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

#define for_(i,a,b) for(int i=a;i<b;++i)

int N, M, b[15], p[15], p1[15], p2[15];

int main() {
	cin >> N >> M;
	for_(i,0,N) cin >> b[i];
	for_(i,0,M) cin >> p[i];
	
	int ii = 0, v = 0;
	for_(i,0,M) {
		for_(j,0,p[i]) p1[ii] = v, p2[ii++] = 1 - v;
		v = 1 - v;
	}
	
	int c = 0, c1 = 0, c2 = 0;
	for_(i,0,N) c += b[i], c1 += p1[i], c2 += p2[i];
	bool f1 = c == c1, f2 = c == c2;	
	
	int ans1 = 0, ans2 = 0, j1 = 0, j2 = 0;
	for_(i,0,N) {
		if (b[i]) {
			if (f1) {
				while (!p1[j1]) ++j1;
				ans1 += abs(j1 - i);
			}
			if (f2) {
				while (!p2[j2]) ++j2;
				ans2 += abs(j2 - i);
			}
			++j1, ++j2;
		}
	}
	
	cout << min(f1 ? ans1 : 100, f2 ? ans2 : 100) << endl;
	
	return 0;
}

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

using namespace std;

int n, k, c;
string s;
vector<int> a, b;

int main() {
	cin >> n >> k >> c >> s;
	for (int i=0; i<n && a.size()<k; ++i) {
		if (s[i]=='o') {
			a.push_back(i+1);
			i += c;
		}
	}
	for (int i=n-1; i>=0 && b.size()!=k; --i) {
		if (s[i]=='o') {
			b.push_back(i+1);
			i -= c;
		}
	}
	for (int i=0; i<k; ++i) 
		if (a[i]==b[k-1-i]) 
			cout << a[i] << '\n';		
	return 0;
}


Measured memory_bytes: 3448
import java.util.*;
class Main
{
    public static void main(String[] args)
    {
        Scanner sc = new Scanner(System.in);
        
        int k = sc.nextInt();
        int x = sc.nextInt();
        
        int total = 500*k;
        
        if(total>=x){
            System.out.println("Yes");
        }else{
            System.out.println("No");
        }
    }
}

Measured memory_bytes: 23508
#include<bits/stdc++.h>
typedef  long long int ll;
typedef  long double ld;
#define sync ios_base::sync_with_stdio(false); cin.tie(NULL) 
#define input(arr,n) for(ll i1=0;i1<n;i1++ )cin>>arr[i1]
#define mod 1000000007
#define F first
#define S second 
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize("O3")
//recursions\
#pragma comment(linker, "/stack:200000000")
//loops\
#pragma GCC optimize("unroll-loops")
using namespace __gnu_pbds;
#define ordered_set tree<ll, null_type,less_equal<ll>, rb_tree_tag,tree_order_statistics_node_update>//s.order_of_key(val) *s.find_by_order(ind)
using namespace std;
const int N = 1e6 + 5;
int main()
{
	sync;
	ll h, c, cw, ch, dw, dh;
	cin >> h >> c >> cw >> ch >> dw >> dh;
	cw--;ch--;dw--;dh--;
	string mat[h];
	input(mat, h);
	vector<vector<ll> > dis(h, vector<ll> (c, 1e9));
	dis[cw][ch] = 0;
	deque<pair<ll,ll> > dq;
	dq.push_back({cw, ch});
	while(!dq.empty())
	{
		ll x = dq.front().F, y = dq.front().S;
		dq.pop_front();
		for(ll i = -2; i <= 2; i++)
		{
			for(ll j = -2; j <= 2; j++)
			{
				if(x + i >= 0 && x + i < h && y + j >= 0 && y + j < c)
				{
					if(abs(i) + abs(j) == 1 && mat[x][y] == '.' && mat[x + i][y + j] == '.' && dis[x + i][y + j] > dis[x][y])//neighbour
					{
						dis[x + i][y + j] = dis[x][y];
						dq.push_front({x + i, y + j});
					}
					if(mat[x + i][y + j] == '.' && dis[x + i][y + j] > dis[x][y] + 1)//magic
					{
						dis[x + i][y + j] = dis[x][y] + 1;
						dq.push_back({x + i, y + j});
					}
				}
			}
		}
	}
	cout << (dis[dw][dh] == 1e9 ? -1 : dis[dw][dh]);
}

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

#define repeat(i, n) for (auto i = decltype(n)(); (i) < (n); (i)++)

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

    int n;
    cin >> n;

    vector<int64_t> a(n), b(n);
    repeat (i, n) {
        cin >> a[i];
    }
    repeat (i, n) {
        cin >> b[i];
    }

    int ans = 0;
    vector<int64_t> a2(n), b2(n);

    repeat (i, 30) {
        int64_t mask = (1 << (i + 1)) - 1,
                t = (1 << i);
        repeat (j, n) {
            a2[j] = a[j] & mask;
            b2[j] = b[j] & mask;
        }
        sort(b2.begin(), b2.end());

        int64_t cnt = 0;
        repeat (j, n) {
            cnt += lower_bound(b2.begin(), b2.end(), 2 * t - a2[j]) -
                    lower_bound(b2.begin(), b2.end(), t - a2[j]);

            cnt += lower_bound(b2.begin(), b2.end(), 4 * t - a2[j]) -
                    lower_bound(b2.begin(), b2.end(), 3 * t - a2[j]);
        }

        if (cnt & 1) ans |= (1 << i);
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 6528
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
	ll n, z, w; cin >> n >> z >> w;
	ll a[n + 1];
	for(ll i = 0; i < n; ++i) cin >> a[i + 1];
	if(n == 1){
		cout << abs(a[1] - w) << endl;
		return 0;
	}
	ll dp[n + 1][2];
	dp[n][0] = dp[n][1] = (ll)abs(a[n] - a[n - 1]);
	for(ll i = n - 1; i >= 1; --i){
		dp[i][0] = (ll)abs((i - 1 == 0 ? w : a[i - 1]) - a[n]);
		for(ll j = i + 1; j <= n; ++j) dp[i][0] = max(dp[i][0], dp[j][1]);
		dp[i][1] = (ll)abs((i - 1 == 0 ? z : a[i - 1]) - a[n]);
		for(ll j = i + 1; j <= n; ++j) dp[i][1] = min(dp[i][1], dp[j][0]);
	}
	cout << dp[1][0] << endl;
	return 0;
}

Measured memory_bytes: 256
s = gets.chomp
q = gets.to_i

r = false
s = s.chars
ff = ""
b = ""
q.times do
  q, f, c = gets.chomp.split
  if q.to_i == 1
    r = !r
  elsif f.to_i == 1
    if r
      s.push c
    else
      s.unshift(c)
    end
  else
    if r
      s.unshift(c)
    else
      s.push c
    end
  end
end

s = s.join
print r ? s.reverse : s

Measured memory_bytes: 28412
s=input()

def is_guumoji(s):
    l=len(s)
    h=l//2
    s1=s[:h]
    s2=s[h:]
    if s1==s2: return True
    else: return False

s=s[:-2]
while 1:
    if is_guumoji(s):
        print(len(s))
        break
    else:
        s=s[:-2]

Measured memory_bytes: 38384
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define ll long long
#define ll_MAX LONG_LONG_MAX
#define ll_MIN LONG_LONG_MIN
#define pi pair<int,int>
#define endl "\n"
#define MAXN 100005
#define mod 1000000007
using namespace std;

void solve()
{
    
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	cout.tie(NULL);
    solve();
    ll n;
    cin>>n;
    ll a[n], b[n], c[n];
    for (ll i = 0; i < n; i++)
    {
        /* code */
        cin>>a[i]>>b[i]>>c[i];
    }
    vector< vector<ll> > dp(n, vector<ll>(3, 0));
    dp[0][0] = a[0];
    dp[0][1] = b[0];
    dp[0][2] = c[0];
    for(ll i=1; i<n; i++)
    {
        for(ll j=0; j<3; j++)
        {
            if(j == 0)
            {
                dp[i][0] = max(dp[i-1][1] + a[i], dp[i-1][2] + a[i] ); 
            }
            if(j == 1)
            {
                dp[i][1] = max(dp[i-1][0] + b[i], dp[i-1][2] + b[i] ); 
            }
            if(j == 2)
            {
                dp[i][2] = max(dp[i-1][1] + c[i], dp[i-1][0] + c[i] ); 
            }
        }
    }
    ll ans = max(dp[n-1][0], dp[n-1][1]);
    cout<<max(ans, dp[n-1][2])<<'\n';
}

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

int main() {
  int A,B;
  cin >> A >> B;
  int sum=0;
  for(int i=0;i<2;i++){
    if(A>B){
      sum += A;
      A--;
    }
    else{
      sum += B;
      B--;
    }
  }
  cout << sum << endl;
}


Measured memory_bytes: 256
// Problem : A - Circle Pond
// Contest : AtCoder - AtCoder Beginner Contest 163
// URL : https://atcoder.jp/contests/abc163/tasks/abc163_a
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>
using namespace std;

int32_t main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	
	int n;
	cin >> n;
	double ans = 2*acos(-1)*n;
	cout << fixed << setprecision(15);
	cout << ans << '\n';
				
	return 0;
}


Measured memory_bytes: 3792
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
constexpr ll mod=1000000007;
constexpr ll mod998=998244353;

int N;

int main(){
	cin>>N;
	if(N%10==3)puts("bon");
	else if(N%10==0||N%10==1||N%10==6||N%10==8)puts("pon");
	else puts("hon");
}


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

using namespace std;

#define ll long long
#define ini(arr, val) memset(arr, (val), sizeof(arr))
#define loop(i,n)  for(ll i=0; i<n; i++)
#define loop1(i,n)  for(ll i=1; i<=n; i++)

#define all(a)      (a).begin(),(a).end()
#define dupli(a)     unique(all(a)),(a).end()
#define exist(s,e)  (s.find(e)!=s.end())
#define dbg(x)  cout << #x << " is " << x << endl;
#define pt(x) cout<<x<<"\n"
#define pts(x) cout<<x<<" "

#define mp make_pair
#define pb push_back
#define f first
#define s second


#define inf (int)1e9
#define eps 1e-9
#define PI 3.1415926535897932384626433832795
#define mod 1000000007


#define fast    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define test   int t; cin>>t; while(t--)

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<pii> vpii;
typedef vector<vi> vvi;
typedef map<int,int> mii;
typedef set<int> si;

typedef pair<ll, ll> pll;
typedef vector<ll> vl;
typedef vector<string> vs;
typedef vector<pll> vpll;
typedef vector<vl> vvl;
typedef map<ll,ll> mll;
typedef set<ll> sl;


//////////////////////////////////////////////////////////////////////////////////////////
//                      main starts
//////////////////////////////////////////////////////////////////////////////////////////
int const lmt=1e5+5;



int main(){

 //    #ifndef ONLINE_JUDGE
 //    freopen("../input.txt", "r", stdin);
 //    freopen("../output.txt", "w", stdout);
	// #endif
 //    fast
    
    int n,k;
    cin>>n>>k;
    int a[n];
    loop(i,n) cin>>a[i];
    sort(a,a+n);
    ll sum=0;
    loop(i,k) sum+=a[i];
    pt(sum);

    

}


/*

// 

*/

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
bool pc(int n) {
	if(n < 2) return false;
	if(n <= 3) return true;
	if(!(n%2)) return false;
	if(!(n%3)) return false;
	for(int i=5;i*i<=n;i+= 6) {
		if((!(n%i))||(!(n%(i+2)))) return false;
	}
	return true;
}
int res[100];
int main() {
	int n;
	scanf("%d",&n);
	int ct = 11;
	for(int i=0;i<n;i++) {
		while(!pc(ct)) {ct += 10;}
		res[i] = ct;
		ct += 10;
	}
	for(int i=0;i<n;i++) {
		if(i > 0) {printf(" ");}
		printf("%d",res[i]);
	}
	printf("\n");
}

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

int f(int n){   //再帰関数
    if( n==1 )return 1;
    if( n==2 )return 2;
    if( n==3 )return 4;
    //f(n)=f(n-1)+f(n-2)+f(n-3)
    return f(n-1)+f(n-2)+f(n-3);
}
int main(void){
    int n;
    while(true){
    cin >> n;
    if(n==0)break;
    cout << (f(n)/3650)+1 << endl;
    }
}



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

int main(){
	string s;
	cin>>s;
	bool flag=true;
	for(int i=0;i<4;i++){
		int cnt=0;
		char c=s[i];
		for(int j=0;j<4;j++){
			if(s[i]==s[j])cnt++;
		}
		if(cnt!=2)flag=false;
	}
	if(flag)cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    string S;
    cin >> S;
    for(int i = 0; i < S.size(); i++){
        if(i % 2 == 0){
            cout << S.at(i);
        }
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 3620
/**
 * author:    Ziel(Maksat Sakenuly)
 * created:   28.03.2020 17:52:04
 * judge:     Atcoder
 
 * Solution for problem B
**/

// ~succesfully skatal~

#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")

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

#define fi first
#define se second
#define sz(x) int(x.size())
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin, x.rend()
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define eb emplace_back
#define count1 __builtin_popcountl
#define debug(x) cerr << (#x) << " = " << (x) << "\n"
#define ACCELERATE ios_base::sync_with_stdio(false),cin.tie(nullptr)
#define fre(f) if(fopen(f".in", "r")) freopen(f".in", "r", stdin),freopen(f".out", "w", stdout)

using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;

using ll = long long;
using ull = unsigned long long;
// using big = __int128_t; // -10^38...10^38
using db = double;
using ld = long double;
typedef pair<int,int> ii;
typedef pair<ll,ll> pll;

template <class T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <class T>
using p_queue = priority_queue<T, vector<T>, greater<T>>;
template <class T>
inline void cmin(T &a, T b) { a = min(a, b); }
template <class T>
inline void cmax(T &a, T b) { a = max(a, b); }

const int oo = 0x3f3f3f3f;
const ll N = 1e5 + 123;
const ll MOD = 1e9 + 7;
const ll INF = 1e15 + 9;
const db EPS = 1e-9;
const db PI = acos(-1); // 3.14159265358979323846
const int dx[] = {1, -1, 0, 0, 1, 1, -1, -1};
const int dy[] = {0, 0, 1, -1, 1, -1, -1, 1};

main() {
#ifdef ZVER
	cerr << "Ready\n";
#endif
	fre("");
	ACCELERATE;
	mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
	
	int x;
	cin >> x;
	
	ll ans = 0;
	ans += (x / 500 * 1000);
	x %= 500;
	ans += (x / 5 * 5);
	
	cout << ans;
	
	return 0;
}

// uniform_int_distribution<int>(l, r)(rng) -> random in range [l, r]
// assert(condition) -> if (condition == false) Runtime Error
// order_of_key(x) -> number of elements smaller than x
// *find_by_order(k) -> k-th element in 0-based indexation

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int mod=1e9+7;
typedef long long ll;
int comb(int n,int k)
{
    ll t1=1ll,t2=1ll;
    for(int i=k+1;i<=n;++i) t1=(1ll*i*t1)%mod;
    for(int i=2;i<=n-k;++i) t2=(1ll*i*t2)%mod;
    ll usu=1ll,p=1ll*mod-2;
    while(p)
    {
        if(p&1) usu=(1ll*usu*t2)%mod;
        p=p>>1;
        t2=(t2*t2)%mod;
    }
    ll sol=0;
    sol=t1*usu%mod;
    return sol;
}
char c;
long long s[1003],n;
int main()
{
    ios::sync_with_stdio(false);
    cin>>n;
    for(int i=1;i<=n;++i)
    {
        cin>>c;
        ++s[c];
    }
    long long sol=1ll;
    for(char i='a';i<='z';++i)
    {
        sol=sol*1ll*(s[i]+1)%mod;
    }
    --sol;
    if(sol<0) sol+=mod;
    cout<<sol;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main () {
  // ios::sync_with_stdio(false);
  int n;
  cin >> n;
  vector<int> v(n);
  for(int i = 0; i < n; ++i) cin >> v[i];
  
  if (n <= 2) {
    cout << 1 << endl;
    return 0;
  }
  int ct = 0;
  int dir = 0;
  for(int i = 1; i < n; ++i) {
    if (v[i] > v[i - 1]) {
      if (dir < 0) {
        ct++;
        dir = 0;
      } else dir = 1;
    } else if (v[i] < v[i - 1]){
      if (dir > 0) {
        ct++;
        dir = 0;
      } else dir = -1;
    }
  }
 
  ct++;
  cout << ct << endl;
}

Measured memory_bytes: 640
#include <stdio.h>
int main(void) {
	int n,m,k = 0;
	int a = 0;
	int b = 0;
	unsigned long aSum[200010];
	unsigned long bSum[200010];
	int ai,bi = 0;
	int count = 0;
	
	//For binary search
	int mid = 0;
	int left = 0;
	int right = 0;
	
	aSum[0] = 0;
	bSum[0] = 0;
	
	scanf("%d%d%d",&n,&m,&k);
	for(ai=1;ai<n+1;ai++){
		scanf("%d",&a);
		aSum[ai] = aSum[ai-1] + a;
		//printf("aSum = %d\n",aSum[ai]);
		}
	for(bi=1;bi<m+1;bi++){
		scanf("%d",&b);
		bSum[bi] = bSum[bi-1] + b;
	}
	
	for(ai=0;ai<n+1;ai++){
		left = 0;
		right = m;
		//binary search
		while(left <= right){
			mid = (left + right)/2;
			if(aSum[ai]+bSum[mid] <= k){
				left = mid + 1;
				//読んだ冊数を更新
				if(count < ai + mid){
					count = ai + mid;
				}
			}else{
				right = mid - 1;
			}
		}
	}
	
	printf("%d",count);
	return 0;
}

Measured memory_bytes: 4788
#include <bits/stdc++.h>
#define F first
#define S second
using namespace std;
typedef long long LL;
typedef pair<int, int> pii;
int main() {
    ios_base::sync_with_stdio(false); cin.tie(0);
    int n; cin >> n;
    string s; cin >> s;
    LL cnt[3] = {0};
    for (auto &c : s) {
        if (c == 'R')
            cnt[0]++;
        if (c == 'G')
            cnt[1]++;
        if (c == 'B')
            cnt[2]++;
    }
    LL ans = cnt[0] * cnt[1] * cnt[2];
    for (int i = 0 ; i < n ; i++) {
        for (int d = 1 ; i + 2 * d < n ; d++) {
            if (s[i] != s[i + d] && s[i + d] != s[i + 2 * d] && s[i] != s[i + 2 * d])
                ans--;
        }
    }
    cout << ans << '\n';

}


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

int main(){
	int n, c, k, ans = 0;
	cin >> n >> c >> k;
	int t[n];
	for(int i = 0; i < n; i++) cin >> t[i];
	sort(t, t + n);
	for(int i = 0; i < n;){
		int now = 1, j = i;
		while(j < n && t[j] <= t[i] + k && now <= c){
			now++;
			j++;
		}
		ans++;
		i = j;
	}
	cout << ans << endl;
}

Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <functional>
#include <algorithm>
#include <numeric>
#include <string>
#include <map>
#include <queue>
#include <bitset>
#include <sstream>
using namespace std;
typedef long long ll;

bool Check(ll K, ll p, vector<ll> &A, vector<ll> &F){
        for(int i=0; i<A.size(); i++){
                K -= max((A[i]*F[i] - p+F[i]-1)/F[i], 0LL);
                if(K < 0){
                        return false;
                }
        }
        return true;
}


int main(){
        ll N, K;
        cin >> N >> K;
        vector<ll> A(N), F(N);
        for(int i=0; i<N; i++){
                cin >> A[i];
        }
        for(int i=0; i<N; i++){
                cin >> F[i];
        }
        sort(A.begin(), A.end());
        sort(F.rbegin(), F.rend());

        ll l=-1;
        ll r=1e13;
        while(r-l>1){
                ll point = (l+r)/2;
//              cout << point << endl;
                if(Check(K,point, A, F)) r = point;
                else l = point;
        }
        cout << r;

}

Measured memory_bytes: 3328
a = []
b = []

for i in range(5):
    In = int(input())
    a.append(int(In/10))
    b.append(In%10)

b_notzero = [i for i in b if i != 0]
if len(b_notzero) != 0:
    b_notzero.sort()
    b_min = b_notzero[0]
    print(sum(a) * 10 + (len(b_notzero) - 1) * 10 + b_min)
else:
    b_min = 0
    print(sum(a) * 10)

Measured memory_bytes: 3060
#include<algorithm>
#include<iostream>
#include<math.h>
#include<limits.h>

int D, N;
int T[200];
int A[200], B[200], C[200];
// suit[i][j]: i日目に服jが着れるか
bool suit[200][200];
// dp[i][j]: i日目までで当日に服jを選んだ場合の派手さの差の絶対値の合計
int dp[201][201];

int main()
{
	std::cin >> D >> N;
	for( int i = 0; i < D; i++ )
		std::cin >> T[i];

	for( int j = 0; j < N; j++ )
		std::cin >> A[j] >> B[j] >> C[j];

	for( int i = 0; i < D; i++ )
		for( int j = 0; j < N; j++ )
			suit[i][j] = ( A[j] <= T[i] && T[i] <= B[j] );

	for( int i = 0; i < D; i++ )
		for( int j = 0; j < N; j++ )
			dp[i][j] = INT_MIN;

	// 1日目で着れる服は0
	for( int j = 0; j < N; j++ )
		if( suit[0][j] )
			dp[0][j] = 0;

	// i日目
	for( int i = 0; i < D - 1; i++ )
		// 当日に選んだ服j
		for( int j = 0; j < N; j++ )
			// 前日に選んだ服k
			for( int k = 0; k < N; k++ )
				if( suit[i+1][j] )
					dp[i+1][j] = std::max( dp[i+1][j], dp[i][k] + abs( C[j] - C[k] ) );

	int ans = 0;
	for( int j = 0; j < N; j++ )
		ans = std::max( ans, dp[D-1][j] );

	std::cout << ans << std::endl;

	return 0;
}

Measured memory_bytes: 1360
n=gets.to_i
as=gets.split.map(&:to_i)
bs=gets.split.map(&:to_i)

count = 0
goods = []
rest = 0
n.times do |i|
  a = as[i]
  b = bs[i]
  if a < b
    count += 1
    rest += b - a
  else
    goods << [a,b]
  end
end

goods.sort_by!{|a,b|b-a}

i = 0
loop do
  if rest <= 0
    p count
    exit 0
  elsif goods.length <= i
    p -1
    exit 0
  end

  a,b = goods[i]
  rest -= a-b
  count += 1
  i += 1
end


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

int main(){
    long long N,sum = 0;
    bool Fizz,Buzz;

    cin >> N;

    rep(i,N){
        Fizz = false;
        Buzz = false;
        if(i % 3 == 0){
            Fizz = true;
        }else if(i % 5 == 0){
            Buzz = true;
        }else{
            sum += i;
        }
    }

    cout << sum;
}

Measured memory_bytes: 3624
let n = read_int ()
let s = read_line ()
let _ = Array.(init (n - 2) (fun i -> if s.[i] = 'A' && s.[i + 1] = 'B' && s.[i + 2] = 'C' then 1 else 0) |> fold_left (+) 0) |> Printf.printf "%d\n"

Measured memory_bytes: 2432
#include "bits/stdc++.h"

using namespace std;

using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using vvvll = vector<vector<vector<ll>>>;
using vvvvll = vector<vector<vector<vector<ll>>>>;
using pl4 = pair<ll,ll>;
using str = string;
using vpl4 = vector<pair<ll,ll>>;

#define sz size()
#define be begin()
#define en end()
#define fi first
#define se second
#define pb push_back
#define mp make_pair

#define llin(x) ll (x);cin >>(x);
#define stin(x) str (x);cin >>(x);
#define vllin(x,n) vll (x)(n);FOR(i,0,n-1){cin >>(x)[i];}
#define vllin2(a,b,n) vll (a)(n);vll (b)(n);FOR(i,0,n-1){cin >>(a)[i]>>(b)[i];}
#define vllin3(a,b,c,n) vll (a)(n);vll (b)(n);vll (c)(n);FOR(i,0,n-1){cin >>(a)[i]>>(b)[i]>>(c)[i];}
#define vlling(x,n) (x).assign(n,0);FOR(i,0,n-1){cin >>(x)[i];}
#define vlling2(a,b,n) (a).assign(n,0);(b).assign(n,0);FOR(i,0,n-1){cin >>(a)[i]>>(b)[i];}
#define vlling3(a,b,c,n) (a).assign(n,0);(b).assign(n,0);(c).assign(n,0);FOR(i,0,n-1){cin >>(a)[i]>>(b)[i]>>(c)[i];}
#define vpl4in(x,n) vpl4 (x)((n),mp(0,0));FOR(i,0,n-1){cin >>x[i].fi>>x[i].se;}
#define FOR(i,a,b) for(ll i = a ; i <= b ; i++)
#define rFOR(i,b,a) for(ll i = a; i >= b ; i--)
#define SORT(x) sort(x.be, x.en)
#define rSORT(x) sort(x.rbegin(), x.rend())
#define say(x) cout<<(x);
#define sal(x) cout<<(x)<<endl;
#define says(x) cout<<(x)<<(' ');
#define sas cout<<(' ');
#define sayR(x) cout<<fixed<<setprecision(10)<<(x);
#define salR(x) cout<<fixed<<setprecision(10)<<(x)<<endl;
#define yn(a) cout <<((a)?"yes":"no")<<endl;
#define Yn(a) cout <<((a)?"Yes":"No")<<endl;
#define YN(a) cout <<((a)?"YES":"NO")<<endl;
#define Imp(a) cout <<((a)?"Possible":"Impossible")<<endl;
#define IMP(a) cout <<((a)?"POSSIBLE":"IMPOSSIBLE")<<endl;
#define pow(a,b) ll(pow(a,b))

ll MOD=1000000007;

int main(){
    llin(n);
    llin(m);
    vllin2(a,b,m);
    if(m%2!=0){
        sal(-1)
        return 0;
    }
    vvll c(n+1,vll(0));
    FOR(i,0,m-1){
        c[a[i]].pb(b[i]);
        c[b[i]].pb(a[i]);
    }
    vll e(1,1);
    vll f(n+1,0);
    vll g(n+1,0);
    f[1]=1;
    FOR(i,0,n-1){
        for(auto l:c[e[i]]){
            if(f[l]==0){
                e.pb(l);
                f[l]=e[i];
            }
        }
    }
    FOR(i,0,m-1){
        if(f[a[i]]!=b[i]&&f[b[i]]!=a[i]){
            says(a[i])
            sal(b[i])
            g[a[i]]++;
        }
    }
    rFOR(i,1,n-1){
        if(g[e[i]]%2==0){
            says(f[e[i]])
            sal(e[i])
            g[f[e[i]]]++;
        }else{
            says(e[i])
            sal(f[e[i]])
        }
    }
    return 0;
}


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

#if defined(DEBUG)

#include <unistd.h>
#include <sys/fcntl.h>
#define DLOG(...)        cerr << dbgFormat(__VA_ARGS__) << endl
#define DCALL(func, ...) func(__VA_ARGS__)

template <class... Args>
string dbgFormat(const char* fmt, Args... args) {
  size_t len = snprintf(nullptr, 0, fmt, args...);
  char buf[len + 1];
  snprintf(buf, len + 1, fmt, args...);
  return string(buf);
}

#else  // defined(DEBUG)

#define DLOG(...)
#define DCALL(func, ...)

#endif // defined(DEBUG)
// ----------------------------------------------------------------------

// ----------------------------------------------------------------------
typedef pair<double, int> Pair;

int main(int argc, char *argv[]) {
#if defined(DEBUG)
  // GDB on Cygwin ignores redirection at run command.
  if (argc == 2) dup2(open(argv[1], 0), 0);
#else
  // For performance.  We should not use C-style stdio functions
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
#endif
  cout << setprecision(20);

  ll xs, ys, xt, yt; cin >> xs >> ys >> xt >> yt;
  int N; cin >> N;
  vector<int> X(N+2), Y(N+2), R(N+2);
  X.at(0) = xs; Y.at(0) = ys; R.at(0) = 0;
  X.at(N+1) = xt; Y.at(N+1) = yt; R.at(N+1) = 0;
  for (int i = 1; i <= N; i++) {
    int x, y, r; cin >> x >> y >> r;
    X.at(i) = x; Y.at(i) = y; R.at(i) = r;
  }
  vector<double> eDist(N+2, LLONG_MAX);
  priority_queue<Pair, vector<Pair>, greater<Pair>> que;
  que.emplace(0, 0);
  while (!que.empty()) {
    Pair p = que.top(); que.pop();
    double ed = p.first;
    int i = p.second;
    if (i == N+1) {
      cout << ed << endl;
      return 0;
    }
    if (eDist.at(i) <= ed) continue;
    eDist.at(i) = ed;
    for (int j = 0; j < N+2; j++) {
      if (i == j) continue;
      double xDiff = X.at(j) - X.at(i);
      double yDiff = Y.at(j) - Y.at(i);
      double cd = sqrt(xDiff*xDiff + yDiff*yDiff);
      double thisEd = max(0.0, cd - (R.at(i) + R.at(j)));
      if (ed + thisEd >= eDist.at(j)) continue;
      que.emplace(ed + thisEd, j);
    }
  }
  return 0;
}



Measured memory_bytes: 10608
# -*- coding: utf-8 -*-
import sys
from collections import deque
from collections import defaultdict

N,X,Y=map(int, sys.stdin.readline().split())

al=[ [] for i in range(N+1) ]	#隣接リスト

for i in range(1,N):
    al[i].append(i+1)
    al[i+1].append(i)

al[X].append(Y)
al[Y].append(X)

#カウント
C=defaultdict(lambda: 0)

for start in range(1,N+1):
    #距離
    d=[ float("inf") for _ in range(N+1) ]
    d[start]=0

    #スタートからBFS
    #訪問した頂点
    Visit=[ 0 for _ in range(N+1) ]
    q=deque()
    q.append(start)
    Visit[start]=1

    while q:
        fro=q.popleft()
        for to in al[fro]:
            if Visit[to]==0:
                Visit[to]=1	#訪問済みVisitに1をセットする。4行上のpopleftの直後でVisitをセットすると同じ頂点がqに入り、TLEする
                q.append(to)
                d[to]=min(d[to],d[fro]+1)

    for i in range(start+1,N+1):
        C[d[i]]+=1

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

Measured memory_bytes: 37020
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <tuple>
#include <utility>
#include <vector>
#define ll long long
#define itn int
#define endl '\n'
#define co(ans) cout<<ans<<endl
#define COYE cout<<"YES"<<endl
#define COYe cout<<"Yes"<<endl
#define COye cout<<"yes"<<endl
#define CONO cout<<"NO"<<endl
#define CONo cout<<"No"<<endl
#define COno cout<<"no"<<endl
#define FORE(i,a) for(auto &i:a)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define FFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n)  FFOR(i,1,n)
#define PB push_back
#define MP make_pair
#define ALL(V) (V).begin(),(V).end()
#define SORT(V) sort((V).begin(),(V).end())
#define REVERSE(V) reverse((V).begin(),(V).end())
#define EACH(V,i) for(typeof((V).begin()) i=(V).begin();i!=(V).end();++i)
#define equals(a,b) (fabs((a)-(b))<EPS)
#define INF ((1LL<<62)-(1LL<<31))
#define EPS 1e-10
#define PI 3.141592653589793238
#define MOD 1000000007
#define MMOD 998244353
#define MAX 2010101
using namespace std;
using Edge=pair<ll,ll>;
using Graph=vector<vector<int>>;
inline int toInt(string s){int v;istringstream sin(s);sin>>v;return v;}
template<class T>inline string toString(T x){ostringstream sout;sout<<x;return sout.str();}
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;}
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;
typedef long long LL;
const int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

ll x;int n;
int f(ll x){
	int q=0;
	while (x) q+=x%10,x/=10;
	return q;
}
int main(){
	scanf("%d",&n);x=1;ll la=1;
	printf("1\n");
	for (int i=2;i<=n;i++){
		if (la+x>x*f(la+x)) x*=10;
		printf("%lld\n",la+=x);
	}
	return 0;
}

Measured memory_bytes: 3692
#include <iostream>
#include <algorithm>
#include <vector>
#include <unordered_map>
#include <functional>
#include <map>
#include <string>
using namespace std;
#define INF 1000000000;
#define MOD 1000000007;
typedef long long int ll;
int main(void){
    int r,d;
    vector<ll>x(11,0);
    cin>>r>>d>>x[0];
    for(int i=1;i<11;i++){
        x[i]=r*x[i-1]-d;
        cout<<x[i]<<endl;
    }   
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
const int N=10;

int h,w,k;
int ans;
char c[N][N];

int main(){
	cin>>h>>w>>k;
	for(int i=0;i<h;i++)
		for(int j=0;j<w;j++)
			cin>>c[i][j];
			
	for(int i=0;i<(1<<h);i++)
		for(int j=0;j<(1<<w);j++)
		{	
			int black=0;
			for(int a=0;a<h;a++)
				for(int b=0;b<w;b++)
					if(((i>>a)&1)==0 && ((j>>b)&1)==0 && c[a][b]=='#')
						black++;
			if(black==k) ans++;
		}
	cout<<ans;
	return 0;
}


Measured memory_bytes: 3580
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.StringTokenizer;

import static java.lang.Integer.parseInt;

/**
 * Salary for a Plumber
 */
public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line;
		String[] words;

		while ((line = br.readLine()) != null && !line.isEmpty()) {

			int n = parseInt(line);
			if (n == 0) break;

			long max = 0;
			long len = 0;
			int[] joint = new int[n - 1];

			StringTokenizer st;

			st = new StringTokenizer(br.readLine());
			for (int i = 0; i < n; i++) {
				len += parseInt(st.nextToken());
			}

			st = new StringTokenizer(br.readLine());
			for (int i = 0; i < n - 1; i++) {
				joint[i] = parseInt(st.nextToken());
				len += joint[i];
			}
			Arrays.sort(joint);

			max = len;
			for (int i = 0, j = 2; i < n - 1; i++, j++) {
				len -= joint[i];
				max = Math.max(max, len * j);
			}
			System.out.println(max);
		}
	}
}

Measured memory_bytes: 59756
N=int(input())
t=[0]*(N+1)
x=[0]*(N+1)
y=[0]*(N+1)

for i in range(1,N+1):
  t[i],x[i],y[i] = map(int,input().split())
  
flag=True
for j in range(1,N+1):
  #print(j, abs(x[i]-x[i-1]) + abs(y[i]-y[i-1]), t[i]-t[i-1])
  if abs(x[i]-x[i-1]) + abs(y[i]-y[i-1]) > t[i]-t[i-1]:
    flag=False
    break
  else:
    if (t[i]-t[i-1] - (abs(x[i]-x[i-1]) + abs(y[i]-y[i-1])))%2 != 0:
      flag=False
      break
    
if flag:
  print("Yes")
else:
  print("No")

Measured memory_bytes: 11636
#include<bits/stdc++.h>
using namespace std;
 
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
#define f0(i,a,b) for(int i=a;i<b;i++)
#define f1(i,a,b) for(int i=a;i<=b;i++)
#define f2(i,a,b) for(int i=a;i>b;i--)
#define f3(i,a,b) for(int i=a;i>=b;i--)
#define pb push_back
#define mp make_pair
#define pii pair<int,int>
#define int long long
#define fi first
#define se second
#define mod 1000000007
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);


signed main(){
    fast

    int n,k;cin>>n>>k;
    int a[n+5];
    f0(i,0,n) cin>>a[i];

    int dp[n+5];
    f0(i,0,n) dp[i]=INT_MAX;
    dp[0]=0;
    f0(i,1,n){
        f3(j,i-1,max(0ll,i-k)){
            dp[i]=min(dp[i],dp[j]+abs(a[i]-a[j]));
        }
    }
    cout<<dp[n-1];
}

Measured memory_bytes: 1792
h, w = map(int, input().split())
if h % 3 == 0 or w % 3 == 0:
    print(0)
else:
    min_diff = h * w

    h1 = h // 2
    h2 = h - h1
    for w3 in range(w // 3, w // 3 + 3):
        s = [h * w3, h1 * (w - w3), h2 * (w - w3)]
        min_diff = min(min_diff, max(s) - min(s))

    w1 = w // 2
    w2 = w - w1
    for h3 in range(h // 3, h // 3 + 3):
        s = [w * h3, w1 * (h - h3), w2 * (h - h3)]
        min_diff = min(min_diff, max(s) - min(s))

    h1 = h // 3
    h2 = (h - h1) // 2
    h3 = h - h1 - h2
    s = [w * h1, w * h2, w * h3]
    min_diff = min(min_diff, max(s) - min(s))

    w1 = w // 3
    w2 = (w - w1) // 2
    w3 = w - w1 - w2
    s = [h * w1, h * w2, h * w3]
    min_diff = min(min_diff, max(s) - min(s))

    print(min_diff)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
 
const double pi = 3.141592653589793238462643383279;
 
 
using namespace std;
//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<long long, long long> PLL;
typedef pair<int, PII> TIII;
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;
 
 
//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SQ(a) ((a)*(a))
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
 
 
//repetition
//------------------------------------------
#define FOR(i,s,n) for(int i=s;i<(int)n;++i)
#define REP(i,n) FOR(i,0,n)
#define MOD 1000000007
 
 
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
 
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
const double EPS = 1E-10;
 
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)


//ここから編集

 
ll modPow(ll x, ll n, ll mod = MOD){
    ll res = 1;
    while(n){
        if(n&1) res = (res * x)%mod;
 
        res %= mod;
        x = x * x %mod;
        n >>= 1;
    }
    return res;
}

int arr[110][110];
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);

  int W, H, N;
  cin >> W >> H >> N;

  vector<int> x1,x2,y1,y2;
  REP(i,N){
    int x, y, a;
    cin >> x >> y >> a;

    if(a == 1) x1.push_back(x);
    if(a == 2) x2.push_back(x);
    if(a == 3) y1.push_back(y);
    if(a == 4) y2.push_back(y);
  }

  sort(all(x1));
  sort(all(x2));
  sort(all(y1));
  sort(all(y2));
  
  
  int ans = H*W;
  int lm = 0, rm = W, lm2=0,rm2=H;
  if(x1.size() != 0){
    lm = x1[x1.size()-1];
  }
  if(x2.size() != 0){
    rm = x2[0];
  }
  if(y1.size() != 0){
    lm2 = y1[y1.size()-1];
  }
  if(y2.size() != 0){
    rm2 = y2[0];
  }
  cout << max(0, rm2-lm2) * max(0, rm-lm) << endl;
  return 0;
}

Measured memory_bytes: 3612
n,*a=map(int,open(0).read().split())
#print(a)
sumcount=0
for s in range(n*2-1,-1,-2):
  hidari=a[s-1]+sumcount
#  print(hidari,a[s],sumcount)
  if hidari%a[s]==0:
    continue
  elif hidari%a[s]!=0 and hidari//a[s]==0:
    sumcount+=a[s]-hidari
  elif hidari%a[s]!=0 and hidari//a[s]!=0:
    sumcount+=(hidari//a[s]+1)*a[s]-hidari
print(sumcount)

Measured memory_bytes: 25124
#include<iostream>
#include<string>
#include<vector>
#include<map>

using namespace std;

int main(void){

    int n;  cin >> n;
    bool yorn = true;

    vector<string> word(n);

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

    for(int i = 0;i < n-1;i++){
        if(word[i].back() != word[i+1].front()) yorn = false;
    }

    for(int i = 0;i < n;i++){
        for(int j = i+1;j < n;j++){
            if(word[i] == word[j]) yorn = false;
        }
    }

    cout << (yorn ? "Yes" : "No") << endl;



    return 0;
}

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

R = []

for i in range(n):
    R.append(int(input()))

kouho = set()
diff_max = None

for (i, rt) in enumerate(R):
    if i == 0:
        rt_min = rt
    else:
        if rt < rt_min and not (diff_max is None):
            kouho.add(diff_max)
            diff_max = None
            rt_min = rt
        elif rt < rt_min and diff_max is None:
            rt_min = rt
        elif rt >= rt_min:
            if diff_max is None:
                diff_max = rt - rt_min
            else:
                diff_max = max(diff_max, rt - rt_min)

if not (diff_max is None):
    kouho.add(diff_max)

# print(kouho)

if kouho != set():
    print(max(kouho))
else:
    diff_tonari = {R[i + 1] - R[i] for i in range(n - 1)}
    print(max(diff_tonari))

Measured memory_bytes: 15724
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
using namespace std;

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

    if (s.size() == 1)
    {
        cout << 0 << endl;
        return 0;
    }

    long long int ans = 0;
    int B_num = 0;
    int W_num = 0;
    for (int i = 0; i < s.size(); i++)
    {
        if (s[i] == 'W')
        {
            if (B_num > 0)
            {
                ans += i - W_num;
            }
            W_num++;
        }
        else
        {
            B_num++;
        }
    }

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

Measured memory_bytes: 640
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
from collections import deque

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

DR = [1, -1, 0, 0]
DC = [0, 0, 1, -1]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
     
def main():
    s = S()
    print('x' * len(s))

main()



Measured memory_bytes: 6832
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdint.h> // uint64_t

#define max(a,b) ((a) > (b) ? (a) : (b))
#define min(a,b) ((a) > (b) ? (b) : (a))
#define BUF_SIZE 200

int get_int2(int *a1, uint64_t *a2) {
#ifdef BUF_SIZE
  char line[BUF_SIZE];
  if(!fgets(line, BUF_SIZE, stdin)) return -1;
  sscanf(line, "%d %llu", a1, a2);
#else
#error
#endif
  return 0;
}

// <arr[0]> <arr[1]> .. <arr[size-1]>
int fget_array(char *arr, int size) {
#ifdef BUF_SIZE
    char line[BUF_SIZE];
    char *tmpbuf = line;
    int i;
    if(!fgets(line, BUF_SIZE, stdin)) return -1;
    for(i = 0; i < size; i++) {
        char *tmp = strtok(tmpbuf, " ");
        arr[i] = strtol(tmp, NULL, 10);
        tmpbuf = NULL;
    }
#else
#error
#endif
    return 0;
}

#define POWER_MAX 63
#define NUM_MAX 50
#define DIVISOR 1000000007

void mat_mult(uint64_t a1[NUM_MAX][NUM_MAX], uint64_t a2[NUM_MAX][NUM_MAX], uint64_t b[NUM_MAX][NUM_MAX], int num) {
    int i, j, k;
    for(i = 0; i < num; i++) {
        for(j = 0; j < num; j++) {
            uint64_t res = 0;
            for(k = 0; k < num; k++) {
                res = (res + a1[i][k] * a2[k][j])%DIVISOR;
            }
            b[i][j] = res;
        }
    }
}

void display(uint64_t a[NUM_MAX][NUM_MAX], int num) {
    int i, j;
    for(i = 0; i < num; i++) {
        for(j = 0; j < num; j++) {
            printf("%llu ", a[i][j]);
        }
        putchar('\n');
    }
}

int main(void) {
    int num;
    uint64_t mult;
    get_int2(&num, &mult);
    static uint64_t graph[POWER_MAX][NUM_MAX][NUM_MAX];
    static char arr[BUF_SIZE];
    int i, j, k;
    for(i = 0; i < num; i++) {
        fget_array(arr, num);
        for(j = 0; j < num; j++) {
            graph[0][i][j] = arr[j];
        }
    }

    // power
    int bit;
    for(bit = 1; bit < POWER_MAX; bit++) {
        mat_mult(graph[bit-1], graph[bit-1], graph[bit], num);
    }

    // not in-place
    static uint64_t cum[POWER_MAX+1][NUM_MAX][NUM_MAX];
    int idx = 0;
    for(i = 0; i < num; i++) cum[0][i][i] = 1;

    for(bit = 0; bit < POWER_MAX; bit++) {
        uint64_t mask = (uint64_t)(1ull<<bit);
        if(!(mult & mask)) continue;
        mat_mult(cum[idx], graph[bit], cum[idx+1], num);
        idx++;
    }

    uint64_t ans = 0;
    for(i = 0; i < num; i++) {
        for(j = 0; j < num; j++) {
            ans = (ans + cum[idx][i][j])%DIVISOR;
        }
    }
    printf("%d\n", (int)ans);

    return 0;
}

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

bool table[8][8],sub[8][8];
int point[8];
vector<int> st;

void check(int x,int y){
    int a=1;
    for(int i=0;i<8;i++){
        table[i][y]=true;
        table[x][i]=true;
    }
    for(int i=0;i<8-(max(x,y)-min(x,y));i++){
        if(x-i>=0 && y-i>=0) table[x-i][y-i]=true;
        else{ 
            table[x+a][y+a]=true;
            a++;
        }
    }
    a=1;
    if(x+y<8){
        for(int i=0;i<1+x+y;i++){
        if(x+i>=0 &&x+i<8 &&y-i<8 && y-i>=0) table[x+i][y-i]=true;
        else{
            table[x-a][y+a]=true;
            a++;
        }
        }
    }
    else{
        for(int i=0;i<15-x-y;i++){
        if(x+i>=0 &&x+i<8 &&y-i<8 && y-i>=0) table[x+i][y-i]=true;
        else{
            table[x-a][y+a]=true;
            a++;
        }
        }
    }
    
}

void checkmate(int i,int s){
    int x=-1;
    int t;
    int p;
    bool cc=false;
    for(int j=0;j<st.size();j++){
        if(st[j]==i) cc=true;
    }
    if(cc && i<7) checkmate(i+1,0);
    else if(cc && i==7) return;
    else{
        for(int j=s;j<8;j++){
            if((x<0) && table[i][j]==false){ 
                x=j;
                check(i,x);
                point[i]=x;
            }
        }
        if(x>=0 && i<7)checkmate(i+1,0);
        else if(i==7 && x>=0) return;
        else{
            t=i-1;
            while(!cc){
                cc=true;
                for(int j=0;j<st.size();j++){
                    if(t==st[j]){
                        cc=false;
                        t--;
                    }
                }
            }
            p=point[t];
            point[t]=-1;
    
            for(int a=0;a<8;a++){
                
                for(int b=0;b<8;b++){
                    if(sub[a][b]==true) table[a][b]=true;
                    else table[a][b]=false;
                }
            }
            for(int a=0;a<t;a++) check(a,point[a]);
            checkmate(t,p+1);
        }
    }
}



int main(){
    int k;
    cin>>k;
    int x,y;
    for(int i=0;i<8;i++){
        point[i]=-1;
        for(int j=0;j<8;j++){
            table[i][j]=false;
        }
    }
    for(int i=0;i<k;i++){
        cin>>x>>y;
        check(x,y);
        point[x]=y;
        st.push_back(x);
    }
    
    for(int a=0;a<8;a++){               
                for(int b=0;b<8;b++){
                    if(table[a][b]==true) sub[a][b]=true;
                    else sub[a][b]=false;
                }
            }
    checkmate(0,0);
    for(int i=0;i<8;i++){
        for(int j=0;j<8;j++){
            if(j==point[i]) cout<<"Q";
            else cout<<".";
        }
        cout<<endl;
    }
    
}


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

typedef long long ll;
typedef long double ld;

const int MOD = 1000000007;

int add(int a, int b){
    return (a+b)%MOD;
}

int mul(int a, int b){
    return ((ll)a*b)%MOD;
}

int pw(int a, int b){
    if(b == 0) return 1;
    int res = pw(a, b/2);
    res = mul(res, res);
    if(b%2) res = mul(res, a);
    return res;
}

int inv(int x){
    return pw(x, MOD-2);
}

int dp[5005][5005];

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.precision(10);
    cout << fixed;

    int n;
    cin >> n;
    string s;
    cin >> s;
    int m = s.size();
    dp[0][0] = 1;
    for(int i=1; i<=n; i++){
        dp[i][0] = add(dp[i-1][0], dp[i-1][1]);
        for(int j=1; j<=n+1; j++){
            dp[i][j] = add(mul(2, dp[i-1][j-1]), dp[i-1][j+1]);
        }
    }
    cout << mul(dp[n][m], inv(pw(2, m))) << "\n";
    return 0;
}


Measured memory_bytes: 98048
using System;

namespace AtCoder.Abc
{
    class QuestionC
    {
        public static void Main(string[] args)
        {
            var sw = new System.IO.StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);

            var sp = Console.ReadLine().Split(' ');
            var a = int.Parse(sp[0]);
            var b = int.Parse(sp[1]);
            var h = int.Parse(sp[2]);
            var m = int.Parse(sp[3]);

            var hx = a * Math.Sin(h * Math.PI / 6.0 + m * Math.PI / 360);
            var hy = a * Math.Cos(h * Math.PI / 6.0 + m * Math.PI / 360);
            var mx = b * Math.Sin(m * Math.PI / 30.0);
            var my = b * Math.Cos(m * Math.PI / 30.0);

            var dx = Math.Abs(hx - mx);
            var dy = Math.Abs(hy - my);


            string result = Math.Sqrt(dx * dx + dy * dy).ToString();

            Console.WriteLine(result);

            Console.Out.Flush();
        }
    }
}


Measured memory_bytes: 27864
#include <iostream>
#include <algorithm>
#include <string>

using std::cin;
using std::cout;
using std::endl;

int main() {
  std::string s;

  cin >> s;

  int c_num = 0, small = 0;

  for (int i = 2; i < s.size() - 1; ++i) {
    if (s[i] == 'C') {
      c_num++;
    }
  }

  for (int i = 0; i < s.size(); ++i) {
    if ('a' <= s[i] and s[i] <= 'z') {
      small++;
    }
  }

  cout << (c_num == 1 && (small + c_num + 1 == s.size()) && s[0] == 'A' ? "AC" : "WA") << endl;

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
typedef long long LL;
LL N;
int M;
vector<int>G[100001];
int color[100001];
bool used[100001];

void dfs(int x,int c){
   if(color[x]==-2){
      color[x]=c;
   }else{
      if(color[x]!=c)color[x]=-1;
   }
   if(used[x]==true)return;
   used[x]=true;
   REP(i,G[x].size()){
      dfs(G[x][i],1-c);
   }
   
}

int main(){
    cin>>N>>M;
    REP(i,M){
        int a,b;
        cin>>a>>b;
        a--;b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    REP(i,N){
        color[i]=-2;
        used[i]=false;
    }
    dfs(0,0);
    bool check=false;
    LL one=0;
    LL zero=0;
    REP(i,N){
        if(color[i]==-1)check=true;
        if(color[i]==0)zero++;
        if(color[i]==1)one++;
    }
    if(check){
      cout<<(N*(N-1)/2)-M<<endl;
    }else{
      cout<<zero*one-M<<endl;
    }
    return(0);
}

Measured memory_bytes: 7040
l, c = map(int, input().split())
tbl = [[] for _ in range(l)]
li_sum = [0 for _ in range(c+1)]

for i in range(l):
  a = input()
  tbl[i] = list(map(int, a.split()))
  print(a, end='')
  print(' ', sum(tbl[i]), sep = '')

  for j in range(c):
    li_sum[j] += tbl[i][j]
  li_sum[c] += sum(tbl[i])

print(' '.join(map(str, li_sum)))


Measured memory_bytes: 5680
#include<cstdio>
#include<algorithm>
using namespace std;
#define MIN(a,b) (((a)<(b))?(a):(b))
int n,a[100005],r[100005],cnt[3];
int main(){
	scanf("%d",&n);
	int xb,x2;
	for(xb=0;xb<n;xb++) {
		scanf("%d",a+xb);
		while(a[xb]%2==0){
			r[xb]++;
			a[xb]/=2;
		}
		cnt[MIN(2,r[xb])]++;
	}
	cnt[0]-=cnt[2];
	if(cnt[1]==0){
		if(cnt[0]>1) printf("No"); else printf("Yes");
		return 0;
	}
	if(cnt[0]>0) printf("No"); else printf("Yes");
	return 0;
}

Measured memory_bytes: 896
using System;

namespace Volume10_1000
{
    class Program
    {
        static void Main(string[] args)
        {
            while(true)
            {
                String input = Console.ReadLine();
                if (input == null) break;

                String[] strs = input.Split(' ');

                Console.WriteLine( Convert.ToInt32(strs[0]) + Convert.ToInt32(strs[1]) );
            }
        }
    }
}

Measured memory_bytes: 5708
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,l,r) for(long long i=(l);i<(r);++i)
#define REP(i,n) FOR(i,0,n)
#define REPS(i,n) FOR(i,0,n+1)
#define int long long
#define mp make_pair
#define pb push_back
#define eb emplace_back
const int MOD=1e9+7;
const int INF=1e18;

signed main(){
    int H,W;cin>>H>>W;
    int A[H][W];
    REP(i,H)REP(j,W)cin>>A[i][j];
    int X[H*W];
    int Y[H*W];
    for(int i=0;i<H*W;i++){
        X[i]=i/W;
        if(i/W%2==0) Y[i]=i%W;
        else Y[i]=W-1-i%W;
    }
    int N=0;
    vector<pair<pair<int,int>,pair<int,int>>>ans(H*W);
    REP(i,H*W-1){
        if(A[X[i]][Y[i]]%2==1){
            A[X[i]][Y[i]]--;
            A[X[i+1]][Y[i+1]]++;
            pair<pair<int,int>,pair<int,int>> p=mp(mp(X[i],Y[i]),mp(X[i+1],Y[i+1]));
            ans[N]=p;
            N++;
        }
    }
    ans.resize(N);
    cout<<N<<endl;
    REP(i,N){
        cout<<ans[i].first.first+1<<" "<<ans[i].first.second+1<<" "<<ans[i].second.first+1<<" "<<ans[i].second.second+1<<endl;
    }
}


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

int main() {
	int n, cnt = 0, min = 1001;
	long long x;
	cin >> n >> x;

	vector<int> m;
	m.resize(n);

	for (int i = 0; i < n; i++) {
		cin >> m[i];
		if (min > m[i]) {
			min = m[i];
		}
		cnt += m[i];
	}

	cout << n + ((x - cnt) / min) << endl;

	return 0;
}

Measured memory_bytes: 256