akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#define INF 1000000000
using namespace std;
typedef long long ll;
int main(){
  ll n,a,b,s=0,tmp,e=INF,cnt=0,num,dec;
  cin >> n >> a >> b;
  ll h[n];
  for(ll i=0;i<n;i++){
    cin >> h[i];
  }
  while(e-s>1){
    tmp = (e+s)/2;
    dec = tmp*b;
    cnt = 0;
    for(ll i=0;i<n;i++){
      if(h[i]-dec>0){
        num = h[i] - dec;
        if(num>0) cnt+= (num-1)/(a-b) + 1;
      }
    }
    if(cnt<=tmp){
      e = tmp;
    }else{
      s = tmp;
    }
  }
  cout << e << endl;
}


Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
using namespace std;
typedef pair<int,int> P;

int dp[2][2222][2222];

int main() {
  string s;
  int m;
  cin >> s >> m;
  string s1="UD",s2="LR";
  int ans=0;
  for(int l=0; l<2; l++) {
    for(int r=0; r<2; r++) {
      for(int i=0; i<=s.size(); i++) {
	for(int j=0; j<=m; j++) dp[0][i][j]=dp[1][i][j]=-(1<<29);
      }
      dp[0][0][0]=dp[1][0][0]=0;
      for(int i=0; i<s.size(); i++) {
	for(int j=m; j>=0; j--) {
	  if(s[i]=='U'||s[i]=='D') {
	    dp[1][i+1][j]=dp[1][i][j];
	    int x=1;
	    if(s[i]==s1[(l+j)%2]) x=-1;
	    dp[0][i+1][j]=max(dp[0][i+1][j],dp[0][i][j]+x);
	    if(j<m) dp[0][i+1][j+1]=max(dp[0][i+1][j+1],dp[0][i][j]-x);
	  } else {
	    dp[0][i+1][j]=dp[0][i][j];
	    int x=1;
	    if(s[i]==s2[(r+j)%2]) x=-1;
	    dp[1][i+1][j]=max(dp[1][i+1][j],dp[1][i][j]+x);
	    if(j<m) dp[1][i+1][j+1]=max(dp[1][i+1][j+1],dp[1][i][j]-x);
	  }
	}
      }
      for(int i=0; i<=m; i++) {
	for(int j=0; j<=m; j++) {
	  if(i+j<=m) ans=max(ans,dp[0][s.size()][i]+dp[1][s.size()][j]);
	}
      }
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 37832
S = input()
l = [S[0]]
a = 0
n = len(S)
f = S[0]
for i in range(1, n):
    if f != "L" or S[i] != "R":
        l[a] += S[i]
    else:
        l.append(S[i])
        a += 1
    f = S[i]

#print(l)
for x in l:
    r = x.count("R")
    t = len(x)
    a, b = divmod(t, 2)
    for i in range(r - 1):
        print("0", end=" ")
    if r % 2 == 0:
        print(a, end=" ")
        print(a + b, end=" ")
    else:
        print(a + b, end=" ")
        print(a, end=" ")
    for i in range(t - r - 1):
        print("0", end=" ")


Measured memory_bytes: 12636
//#pragma GCC optimize(3)
#include<iostream>
#include<iomanip>
#include<stack>
#include<queue>
#include<list>
#include<vector>
#include<set> 
#include<map>
#include<string>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<ctime>
#define ll long long
#define db double
#define inf 200009
#define INF (int)1e8 
#define mod (int)(1e9+7)
#define pi acos(-1)
#define rd(n) {n=0;char ch;int f=0;do{ch=getchar();if(ch=='-'){f=1;}}while(ch<'0'||ch>'9');while('0'<=ch&&ch<='9'){n=(n<<1)+(n<<3)+ch-48;ch=getchar();}if(f)n=-n;}
using namespace std;

int a[inf],p[inf];
int n;

bool check(int k){
	for (int i=1;i<=n*2-1;i++){
		p[i]=(a[i]>=k);
	}
	int posl=0,posr=n*2;
	for (int i=n;i>=2;i--){
		if (p[i]==p[i-1]){
			posl=i;
			break;
		}
	}
	for (int i=n;i<n*2-1;i++){
		if (p[i]==p[i+1]){
			posr=i;
			break;
		}
	}
	if (posl==0 && posr==n*2){
		return p[1];
	}
	else if (n-posl>posr-n){
		return p[posr];
	}
	return p[posl];
}

int main(){
	rd(n)
	for (int i=1;i<=n*2-1;i++){
		rd(a[i])
	}
	int l=2,r=n*2-2,ans;
	while (l<=r){
		int mid=(l+r)/2;
		if (check(mid)){
			ans=mid;
			l=mid+1;
		}
		else{
			r=mid-1;
		}
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 1792
#include<functional>
#include<algorithm>
#include<iostream>
#include<utility>
#include<string>
#include<vector>
#include<cmath>
#include<stack>
#include<queue>
#include<deque>
#include<map>
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,x,n) for(int i=x;i<n;i++)
#define pf push_front
#define pb push_back
#define int long long
using namespace std;
const int INF=1000000007;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

signed main(){ 
  string s,t;
  cin>>s;
  cout<<s[0]<<(s.size()-2)<<s[s.size()-1]<<endl;
  return 0;
}




Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#include <bitset>
#include <stack>
#include <queue>
#include <list>
#include <iomanip>
#include <numeric>

using namespace std;
typedef long long ll;
ll mod = 1000000007;
const int INF = 1001001001;

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

template<class Type>
Type gcd(Type x, Type y)
{
	Type r;
	if (x < y) swap(x, y);

	while (0 < y) {
		r = x % y;
		x = y;
		y = r;
	}
	return x;
}

template<class Type>
Type lcm(Type x, Type y)
{
	return x * y / gcd(x, y);
}

template<class Type>
bool is_prime(Type x)
{
	if (x == 2) return true;
	if (x < 2 || x % 2 == 0) return false;

	for (Type i = 3; i <= sqrt(x); i += 2) {
		if (x % i == 0) return false;
	}
	return true;
}

template<class Type>
vector<bool> eratos(Type n)
{
	vector<bool> isPrime(n + 1, true);
	isPrime[0] = isPrime[1] = false;
	for (Type i = 2; i <= n; i++) {
		if (isPrime[i]) {
			Type j = i + i;
			while (j <= n) {
				isPrime[j] = false;
				j = j + i;
			}
		}
	}
	return isPrime;
}

bool binary_search_judge(vector<int> a, int index, int key)
{
	if (key <= a[index]) return true;
	else return false;
}

int binary_search(vector<int> a, int key)
{
	int ng = -1;
	int ok = a.size();
	while (1 < abs(ng - ok)) {
		int mid = (ng + ok) / 2;
		if (binary_search_judge(a, mid, key)) ok = mid;
		else ng = mid;
	}
	return a[ok] == key;
}

int main()
{
	int h, n;
	cin >> h >> n;
	vector<int> a(n), b(n);
	for (int i = 0; i < n; i++) cin >> a[i] >> b[i];

	vector<vector<int>> mp(n, vector<int>(h + 1, INF));
	for (int i = 0; i < n; i++) mp[i][0] = 0;

	for (int i = 0; i < n; i++) {
		for (int j = 0; j < h; j++) {
			int nj = min(j + a[i], h);

			// i番目の魔法を使う場合を調査
			if (0 < i) mp[i][j] = min(mp[i][j], mp[i - 1][j]);  // i行目の情報を更新
			if (mp[i][j] != INF) mp[i][nj] = min(mp[i][nj], mp[i][j] + b[i]);

			// i番目の魔法を使わない場合を調査
			if (0 < i) mp[i][nj] = min(mp[i][nj], mp[i - 1][nj]);
		}
	}
	cout << mp[n - 1][h] << endl;
}

Measured memory_bytes: 39424
N = int(input())
A = list(map(int, input().split()))

cumulative = [0]
A.sort()
for i in range(N):
    cumulative.append(cumulative[i] + A[i])
# print(A)
# print(cumulative)

for i in range(N - 1, 0, -1):
    # print(i)
    if A[i] > cumulative[i] * 2:
        print(N - i)
        break
else:
    print(N)


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

int read() {
    int x = 0, f = 1;
    char c = getchar();
    while (c < '0' || c > '9') {
        if (c == '-') f = -1;
        c = getchar();
    }
    while (c >= '0' && c <= '9') {
        x = x * 10 + c - '0';
        c = getchar();
    }
    return x * f;
}

int main() {
    int h = read(), w = read(), a = read(), b = read();
    for (int i = 1; i <= h - b; ++i) {
        for (int j = 1; j <= w - a; ++j) putchar('1');
        for (int j = 1; j <= a; ++j) putchar('0');
        puts("");
    }
    for (int i = 1; i <= b; ++i) {
        for (int j = 1; j <= w - a; ++j) putchar('0');
        for (int j = 1; j <= a; ++j) putchar('1');
        puts("");
    }
    return 0;
}

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

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

	// "yyyy/mm/dd"
	int year = stoi(S.substr(0, 4));
	int month = stoi(S.substr(5, 2));
	if(year > 2019){
		cout << "TBD" << endl;
	}else if(year == 2019){
		if(month > 4) cout << "TBD" << endl;
		else cout << "Heisei" << endl;
	}else{
		cout << "Heisei" << endl;
	}

	return 0;
}


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

#define int             long long
#define FOR( i, m, n )  for( int (i) = (m); (i) < (n); (i)++ )
#define REP( i, n )     FOR( i, 0, n )
#define REPR( i, m )    for( int (i) = (m); (i) >= 0; (i)-- )
#define REPONE( i, n )  FOR( i, 1, n + 1 )
#define ALL( a )        (a).begin(), (a).end()
#define MP              make_pair

using namespace std;
using P = pair<int, int>;

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( a > b ) { a = b; return 1; } return 0; }

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

signed main(){
    int M, D; cin >> M >> D;

    int cnt = 0;
    FOR( i, 1, M + 1 ){
        FOR( j, 22, D + 1 ){
            int t1 = j % 10;
            int t2 = j / 10;
            if( t1 >= 2 && t2 >= 2 && t1 * t2 == i ){
                cnt++;
            }
        }
    }

    cout << cnt << endl;
}



Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <queue>
#include <string>

using namespace std;

using i32 = int;
using i64 = long long;
using u32 = unsigned;
using u64 = unsigned long long;

using pii = pair<i32, i32>;

#define rep(i, n) for (i32 i = 0; i < (n); ++i)
#define repr(i, n) for (i32 i = ((n)-1); i >= 0; --i)
#define urep(i, n) for (u32 i = 0; i < (n); ++i)
#define urepr(i, n) for (u32 i = ((n)-1); i >= 0 && i < (n); --i)
#define all(v) v.begin(), v.end()

int main()
{
	string s;
	cin >> s;
	sort(s.begin(), s.end());
	if (s[0] == s[1] && s[2] == s[3] && s[0] != s[2]) {
		cout << "Yes" << endl;
	} else {
		cout << "No" << endl;
	}
	return 0;
}


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

using namespace std;

main(void) {
	stack<int> st;
	int x;
	while( cin >> x) {
		if(x != 0) {
			st.push(x);
		} else {
			cout << st.top() << endl;
			st.pop();
		}
	}
}

Measured memory_bytes: 1200
// https://atcoder.jp/contests/abcXXX/tasks/abcXXX_x

#include <bits/stdc++.h>

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

static const ll INF = 1001001001;
static const ll LLINF = 1001001001001001001;
static const ll MOD = (ll)1e9 + 7;
static const double EPS = 1e-9;

#define REP(i, n) for(ll i = 0; i < (n); ++i)
#define RANGE(i, m, n) for(ll i = (m); i <= (n); ++i)
#define RRANGE(i, m, n) for(ll i = (m); i >= (n); --i)
#define POSITIVE(x) (x)=((x) < 0) ? 0 : (x)

ll power(ll x, ll y) {
    ll ret = 1;
    while(y-- > 0) ret *= x;
    return ret;
}

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

ll extgcd(ll a, ll b, ll& x, ll& y) {
    x = 1; y = 0;
    assert(a >= 0);
    assert(b >= 0);
    if (b == 0) return a;
    ll X, Y;
    auto d = extgcd(b, a % b, X, Y);
    x = Y;
    y = X - (a / b) * Y;
    return d;
}

int run(istream& in, ostream& out) {
    ll K, X;
    in >> K >> X;
    out << (500*K >= X ? "Yes" : "No") << endl;
    return 0;
}

int main() {
    return run(cin, cout);
}


Measured memory_bytes: 384
#include <stdio.h>

int main() {
  int rows, columns, n, tempR = 1, tempC = 1;
  scanf("%d %d %d", &rows, &columns, &n);

  int i = 1, j = 1;
  while(tempR < n && i <= rows) {
    tempR = i * columns;
    i++;
  }
  while(tempC < n && j <= columns) {
    tempC = j * rows;
    j++;
  }

  if(i == 1 && j == 1) printf ("1");
  else if(i < j) printf("%d", i - 1);
  else printf("%d", j - 1);
  return 0;
}

Measured memory_bytes: 3228
#include<bits/stdc++.h>
#define fastio ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
using namespace std;
int main()
{
  fastio;
  int n;
  cin>>n;
  int h[n];
  int d[n];
  for(int i=0;i<n;i++)
    cin>>h[i];
  d[0]=0;d[1]=abs(h[1]-h[0]);
  for(int i=2;i<n;i++)
    d[i]=min( d[i-1]+abs(h[i]-h[i-1]) , d[i-2]+abs(h[i]-h[i-2]) );
  cout<<d[n-1];
}
 


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

x = 0
index = 0

for i in range(n-1):
    if x < a[i+1] - a[i]:
        x = a[i+1] - a[i]
        index = i

if x < k-a[-1]+a[0]:
    x = k-a[-1]+a[0]

print(k - x)


Measured memory_bytes: 26444
#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
typedef long long int ll;
#define forn(i,p,n); for(long long i=p;i<n;++i)
#define rofn(i,p,n); for(long long i=p;i>n;--i)
#define pb push_back
#define vi vector
#define ump unordered_map
void solve(){
    ll n;
    cin >> n;
    vi<ll> a(n);
    ll sum= 0;
    ll mod = 1e9+7;
    forn(i,0,n){
        cin >> a[i];
        sum += a[i];
    }
    ll ans = 0;
    forn(i,0,n){
        sum -= a[i];
        ll x = sum%mod;
        ll y = a[i]%mod;
        x = (x*y)%mod;
        ans += (x)%mod;
    }
    cout<<ans%mod;
}
 
int main()
{
    fast;
    //int test;
    //cin >> test;
    //while(test--){
        solve();
    //}
}

Measured memory_bytes: 4740
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
using namespace std;
#define mod 1000000007
#define FOR(x,to) for(int x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
#define long long long
inline int rei(){int x;cin>>x;return x;}
inline long rel(){long x;cin>>x;return x;}
inline string res(){string x;cin>>x;return x;}
namespace Fact{
	long f[1000000];
	long rf[1000000];
	long pow(long N,long K){
		if(K == 0){
			return 1;
		}
		else if(K % 2 == 0){
			long t = pow(N,K/2);
			return t*t%mod;
		}
		else{
			return N*pow(N,K-1)%mod;
		}
	}
	void Fact(int N){
		for(int i=0;i<N+1;i++){
			if(i == 0){
				f[i] = 1;
			}
			else{
				f[i] = (f[i-1]*i)%mod;
			}
		}
		for(int i=N;i>=0;i--){
			if(i == N){
				rf[i] = pow(f[N],mod-2);
			}
			else{
				rf[i] = rf[i+1]*(i+1)%mod;
			}
		}
	}
	long GetFact(int N){
		return f[N];
	}
	long GetPerm(int N,int R){
		return f[N] * rf[N-R] % mod;
	}
	long GetConv(int N,int R){
		return ((f[N]*rf[R])%mod*rf[N-R])%mod;
	}
	long GetRev(int N){
		if(N == 0){
			return 1;
		}
		else{
			return rf[N] * f[N-1] % mod;
		}
	}
}
//------------------------------------------------------- 
long DP[100001*101];
void Calc(){
	int N = rei();
	int K = rei();
	Fact::Fact(500000);
	DP[K] = 1;
	for(int i=0;i<N;i++){
		int a = rei()+1;
		for(int j=0;j<=100000;j++){
			DP[(i+1)*100001+j] = DP[i*100001+j] % mod;
		}
		for(int j=a;j<=100000;j++){
			DP[(i+1)*100001+j-a] += mod - DP[i*100001+j];
		}
	}
	long ans = 0;
	for(int i=0;i<=K;i++){
		ans += DP[N*100001+i]%mod*Fact::GetConv(i+N-1,i)%mod;
	}
	cout << ans % mod << endl;
}
int main(int argc,char** argv){
	ios::sync_with_stdio(false), cin.tie(0);
	cout.tie(0); Calc(); return 0;
}

Measured memory_bytes: 89600
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops") 
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp> 
#define int long long
#define fr(i,a,b) for(int i = a ; i <= b ; ++i)
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) begin(x), end(x)
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x).size()
#define pb push_back
#define fst first
#define snd second
using namespace __gnu_pbds;
using ordered_set =
 tree<int, null_type,less<int>,
 rb_tree_tag,tree_order_statistics_node_update>;
//find_by_order(k):returns iterator to kth element starting from 0
//order_of_key(k):returns count of elements strictly smaller than k
typedef long long ll;typedef pair<int, int> pii;
typedef vector<int> vi;typedef long double ld;
template<class T>
using min_heap = priority_queue<T,vector<T>,greater<T>>; 
template<typename T> T gcd(T a, T b){return(b?__gcd(a,b):a);}
template<typename T> T lcm(T a, T b){return(a*(b/gcd(a,b)));}
template<typename T> 
void remdup(vector<T>& v) {
	sort(all(v)); v.erase(unique(all(v)), v.end());
}
template<typename T> void re(vector<T> &v) {trav(i,v) cin >> i;}
void unsyncIO() { ios_base::sync_with_stdio(0); cin.tie(0); }
#ifdef np
#include "C:\Users\navodit\Desktop\mycodes\pr.h"
#else
#define trace(...)
#endif

#define MOD 1000000007  





void solve(){
	int n;
	cin >> n ;
	int sum = 0 ;
	for(int i = 1 ; i <= n ; ++i){
		fr(j,1,n){
			fr(k,1,n){
				sum+=gcd(i,gcd(k,j));
			}
		}
	}
	cout << sum << endl;
	
}

signed main() {
	unsyncIO();
	int tt =1 ;
	// cin >> tt;
	rep(i,0,tt) solve();













#ifdef np
	cout <<endl<<endl<< "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
	return 0;
}


Measured memory_bytes: 3664
#include<bits/stdc++.h>
#define pb           push_back
#define pii          pair<int,int>
#define vi           vector<int>
#define vpii         vector<pair<int,int>>
#define gph          map<int, vector<int>>
#define mp           make_pair
#define FOR(i, n) for (int i = 0; i <  (int)(n); i++)
#define FOR1(i, n) for (int i = 1; i <= (int)(n); i++)
#define FORD0(i, n) for (int i = (int)n; i >= 0; i--)
#define FORD1(i, n) for (int i = (int)n; i >= 1; i--)
#define FORS(i, n) for(; i < (int)(n); i++)
#define debug(X) { cout << #X << " = " << (X) << endl; }
#define printArr(A,n) { cout << #A << " = "; FOR(i,n) cout << A[i] << ' '; cout << endl; }
using namespace std;
#define int long long int

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

    int n,x, d;cin >> n >> x >> d;
    unordered_map<int, vector<pii>> m;
    if( d == 0){
        if(x == 0){
            cout << 1;
        }else{
            cout << n + 1 <<endl;
        }
        return 0;
    }
    for(int i =0; i <= n; i++){
        int start = (i*(i-1))/2;
        int end = (i*(n - i+1 + n- 2))/2;
        int mid = i*x;
        m[mid % d].pb(mp(mid/d + start, mid/d + end));
    }

    int ans = 0;
    for(auto& temp: m){
        vector<pii>& v= temp.second;
        sort(v.begin(), v.end());
        bool set = false;
        int l, r;
        for(pii range: v){
            if(!set){
                l = range.first;
                r= range.second;
                set =true;
            }else if(range.first > r){
               ans += (r - l  + 1);
              l = range.first;
              r= range.second; 
            }else{
                r = max(r, range.second);
            }
        }
        ans += (r - l + 1);
    }
    cout << ans;


}




Measured memory_bytes: 17864
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()   //reverse
#define strall(v) (v).cbegin(),(v).cend() //const_itterator
using namespace std;
using ll = long long;
using P = pair<int,int>;
using Graph = vector<vector<int>>;
template<class t,class u> void chmax(t&a,u b){if(a<b)a=b;}
template<class t,class u> void chmin(t&a,u b){if(b<a)a=b;}

struct UnionFind {
  vector<int> par;
  UnionFind(int n) : par(n,-1){ }//n個格納確保
  void init(int n) {par.assign(n,-1);} //初期化
  
  int root(int x){//根を探す
    if(par[x] < 0) return x;
    else return par[x] = root(par[x]);//再帰
  } 
  bool issame(int x, int y){
    return root(x) == root(y);//同じ根を持つか
  }
  
  bool merge(int x,int y){
    x = root(x);y = root(y);
    if(x == y) return false;//くっつける必要ない
    if(par[x] > par[y]) swap(x,y);
    par[x] += par[y];
    par[y] = x;
    return true;
  }

  int size(int x){
    return -par[root(x)];
  }
};

int main(){
  int n,m; cin >> n >> m;
  vector<int> x(m),y(m),z(m);
  for(int i=0;i<m;++i) cin >> x[i] >> y[i] >> z[i],--x[i],--y[i];
  UnionFind uf(n);
  for(int i=0;i<m;++i) uf.merge(x[i],y[i]);//node連結
  set<int> se;
  for(int i=0;i<n;++i) se.insert(uf.root(i));
  cout << (int)se.size() << "\n";
  
}

Measured memory_bytes: 6400
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stdlib.h>
#include <cmath>
#include <numeric>
#include <functional>
#include <stack>
#include <iomanip>
#include <map>
#include <cstdio>

int main() {
	long long n;

	std::cin >> n;

	std::vector<long long> v(n);

	bool even = false;

	for (long long i = 0; i < n; i++)
	{
		std::cin >> v[i];
		if (v[i] % 2 == 0) {
			even = true;
		}
	}

	if (even == false) {
		std::cout << 0 << std::endl;
		return 0;
	}

	long long ans = 0;

	for (long long i = 0; i < n; i++)
	{
		while (v[i] % 2 == 0) {
			ans++;
			v[i] /= 2;
		}
	}

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

	return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
# define ll long long
# define int long long
#define gok ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
# define mo 1000000007

 signed main(){
    gok
    int n,m;
    cin>>n>>m;
    map<int,int> mp;
    for(int i=1;i<=5;i++)
        mp[i]=-1;
    bool ch=true;
    for(int i=0;i<m;i++){
        int x,y;
    cin>>x>>y;
    if(mp[x]==-1 || mp[x]==y)
    mp[x] = y;
    else
    {
        ch=false;
    }
    if(x==1 && y==0 && n!=1)
        ch=false;
    if(x>n)
        ch=false;
    }
    if(ch)
    {
        string ss="";
        bool chh=true,ttt=true;;
       for(int i=1;i<=n;i++)
       {

               if(mp[i]==-1){
                 if(i!=1 || n==1)
                ss.push_back('0');
               else
                ss.push_back('1');
               }
               else
               {
                   ss.push_back('0'+mp[i]);
               }
               chh=false;
           }

      // reverse(ss.begin(),ss.end());
       cout<<ss;
    }
    else
        cout<<-1;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
  int n,a,count=0;
  cin>>n;
  for(int i=1;i<=n;i++)
  {
    cin>>a;
    if(i%2==1)
      if(a%2==1)
        count++;
  }
  cout<<count<<endl;
  return 0;
}  

Measured memory_bytes: 3596
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<stdio.h>
#include<utility>//swapでaとbの値を入れ替える
#define rep(i,n) for(int i=0;i<(n);i++)
#define ll long long
#define sort(s) sort(s.begin(),s.end())
#define r(s) reverse(s.begin(),s.end())
using namespace std;

int main() {
	int a, b=0;
	cin >> a;
	for (int i = 1; i < 10; i++) {
		for (int j = 1; j < 10; j++) {
			if (a == i * j)b++;
		}
	}
	if (b > 0)cout << "Yes" << endl;
	else cout << "No" << endl;
	
	return 0;
}


Measured memory_bytes: 256
N, M = map(int,input().split())
A = []
counter = 0
ans = 0
for i in range(N):
    l = input().split()
    l.remove(l[0])
    A = A + l

for k in range(M):
    y = k+1
    counter = A.count(str(y))
    if counter == N:
        ans += 1
print(ans)

Measured memory_bytes: 3064
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#define MOD1 1000000007
#define MOD2 998244353
#define LIMIT1 200002
#define LIMIT2 500002
typedef long long ll;
typedef long double ld;
typedef const void cv;
#define rep(i,n) for(i=0;i<n;i++)
#define max(a,b) ((a)>(b) ? (a) : (b))
#define min(a,b) ((a)<(b) ? (a) : (b))
#define zt(a,b) (max((a),(b))-min((a),(b)))
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll nPr(int n,int r){ll i,result=1;rep(i,r){result*=(ll)(n-i);}return result;}
ll nCr(int n,int r){ll i,result=1;if(n<r) return 0;rep(i,min(r,n-r)){result*=(ll)(n-i);result/=(ll)(i+1);}return result;}
#define fact(n) nPr((int)(n),(int)(n))
#define nHr(n,r) nCr((int)((n)+(r)+1),(int)(r))
#define sankaku(x) (((x)*((x)+1))/2)
int dx[8]={1,0,-1,0,1,-1,-1,1};
int dy[8]={0,1,0,-1,1,1,-1,-1};
int upint(const void *a, const void *b) { return *(int *)a < *(int *)b ? -1 : *(int *)a > *(int *)b ? 1 : 0; }
int downint(const void *a, const void *b) { return *(int *)a < *(int *)b ? 1 : *(int *)a > *(int *)b ? -1 : 0; }
int upchar(const void* left, const void* right) {return strcmp((char *)left,(char *)right);}
int downchar(const void* left, const void* right) {return strcmp((char *)right,(char *)left);}
ll modpow(ll a, ll n, ll mod) {
  ll res = 1;
  while (n > 0) {
    if (n & 1) res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}
void initialize(){
    
}
ll a,b;
ll find(ll x){
  return ((a*x)/b)-a*(x/b);
}
int main(void){
  initialize();
  ll n,m,q,i,j,result=0;
  scanf("%lld %lld %lld",&a,&b,&n);
  
  i = (n/b) * b -1;
  result = find(i);
  result = max(result,find(n));
  
  printf("%lld",result);
  return 0;
}




Measured memory_bytes: 1732
#include<stdio.h>
#include<math.h>
int main(void){
   int sum, sum2, fst, snd, trd, i, n;
   sum = fst = snd = trd = 0;
   for ( i = 0; i < 10; i++ ) {
      scanf("%d", &n);
      if ( fst <= n ) {
         sum = sum + n - trd;
         trd = snd;
         snd = fst;
         fst = n;
      } else if ( snd <= n ) {
         sum = sum + n - trd;
         trd = snd;
         snd = n;
      } else if ( trd <= n ) {
         sum = sum + n - trd;
         trd = n;
      }
   }
   sum2 = fst = snd = trd = 0;
   for ( i = 0; i < 10; i++ ) {
      scanf("%d", &n);
      if ( fst <= n ) {
         sum2 = sum2 + n - trd;
         trd = snd;
         snd = fst;
         fst = n;
      } else if ( snd <= n ) {
         sum2 = sum2 + n - trd;
         trd = snd;
         snd = n;
      } else if ( trd <= n ) {
         sum2 = sum2 + n - trd;
         trd = n;
      }
   }
   printf("%d %d\n", sum, sum2);
   return 0;
}

Measured memory_bytes: 1812
n = int(input())
h = list(map(int,input().split()))

INF = 10 ** 20

dp = [INF]*(n)
dp[0] = 0
dp[1] = abs(h[1]-h[0])
 
for i in range(2,n):
    dp[i] = min(dp[i-1]+abs(h[i]-h[i-1]), dp[i-2]+abs(h[i]-h[i-2]))
 
print(dp[n-1])

Measured memory_bytes: 13928
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define ALL(A) A.begin(), A.end()

using namespace std;

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

int last[26];

vector<int> calcScore(int D, vector<int> c, vector<vector<int>> s, vector<int> t){
	int sat = 0;
	memset(last, 0, sizeof(last));

	vector<int> res; res.clear();
	rep (d, D){
		int j = t[d];
		last[j] = d + 1;
		rep (i, 26){
			sat -= (d + 1 - last[i]) * c[i];
		} // end rep
		sat += s[d][j];
		res.push_back(sat);
	} // end rep
	return res;
}

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int D; cin >> D;
	vector<int> c(26, 0);
	rep (i, 26){
		cin >> c[i];
	} // end rep
	vector<vector<int>> s(D, vector<int>(26, 0));
	rep (i, D){
		rep (j, 26){
			cin >> s[i][j];
		} // end rep
	} // end rep

	vector<int> t(D, 0);
	rep (i, D){
		cin >> t[i];
		t[i]--;
	} // end rep

	vector<int> res = calcScore(D, c, s, t);
	rep (i, (int)res.size()){
		cout << res[i] << endl;
	} // end rep

	return 0;
}


Measured memory_bytes: 3660
S = input()

S_array = [""] * 4

for i in range(len(S)):
    S_array[i] = S[i]

S_array.sort()

if S_array[0] == S_array[1] and S_array[2] == S_array[3] and S_array[0] != S_array[2]:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 38256
import sys

N = int(input()) 

def prime_judge(N):
    if N % 2 == 0 or N % 3 ==0:
        return False
    for i in range(4,N):
        if N % i == 0:
            return False
            break
    if N % 5 == 1 :
        return True
    else: False

a = []
n = 0
p = 2

while True:
    if prime_judge(p):
        if len(a) == N:
            a2 = [str(i) for i in a]
            print(" ".join(a2))
            sys.exit()
        a.append(p)
    p += 1

Measured memory_bytes: 3064
#include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>

std::vector<int> kmp(int n, char *s) {
  std::vector<int> fail(n, -1);
  for (int i = 1, j = -1; i < n; ++i) {
    while (j >= 0 && s[j + 1] != s[i]) j = fail[j];
    fail[i] = s[j + 1] == s[i] ? ++j : j;
  }
  return fail;
}

const int N = 5e5 + 10;

char s[N];

bool valid(int n, int b) {
  int p = n - b;
  return p == n || n % p;
}

int main() {
  scanf("%s", s);
  int n = strlen(s);
  auto u = kmp(n, s);
  if (valid(n, u[n - 1] + 1)) {
    puts("1\n1");
    return 0;
  }
  if (u[n - 1] == n - 2) {
    printf("%d\n1\n", n);
    return 0;
  }
  std::reverse(s, s + n);
  auto v = kmp(n, s);
  int ret = 0;
  for (int i = 0; i + 1 < n; ++i) {
    ret += valid(i + 1, u[i] + 1) && valid(n - 1 - i, v[n - 1 - i - 1] + 1);
  }
  printf("2\n%d\n", ret);
  return 0;
}


Measured memory_bytes: 4608
#include<bits/stdc++.h>
using namespace std;
int n,a;
vector<int>V;
int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>a;
		V.push_back(a);
	}
	sort(V.begin(),V.end());
	int a1=V.back();
	auto a2=lower_bound(V.begin(),V.end(),V.back()/2);
	while(a2==V.end()-1||(abs(V.back()/2-*a2)>abs(V.back()/2-*(a2-1))&&a2>V.begin()))a2--;
	cout<<a1<<' '<<*a2;
	return 0;
}

Measured memory_bytes: 892
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define irep(i, n) for (int i = (n); i >= 0; i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = 1 << 30;
 
int main() {
  ll n, t[110];
  cin >> n;
  rep(i,n) cin >> t[i];
  ll ans = 1;
  rep(i,n) {
    ans = t[i] / __gcd(ans,t[i]) * ans;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3640
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <ctype.h>

#define MAXOP 100
#define NUMBER '0'
#define BUFSIZE 100
#define MAXVAL 100

int sp = 0;
double val[MAXVAL];
int getch(void);
void ungetch(int);
char buf[BUFSIZE];
int bufp =0;
int getop(char []);
void push(double);
double pop(void);

int main()
{
	int type;
	double op2;
	char s[MAXOP];

     while((type = getop(s)) != EOF) {   
		switch (type) {
		case NUMBER:
			push(atof(s));
			break;
		case '+':
			push(pop() + pop());
			break;
		case '*':
			push(pop() * pop());
			break;
		case '-':
			op2 = pop();
			push(pop() - op2);
			break;
		case '\n':
			printf("%g\n", pop());
			break;
		default:
			printf("error: unknown command %s\n", s);
			break;
		}
		if(type == '\n'){
		  break;
		}
	}
	return 0;
}

void push(double f)
{
	if (sp < MAXVAL)
		val[sp++] = f;
	else
		printf("error: stack full, can't push %g\n", f);
}

double pop(void)
{
	if (sp > 0)
		return val[--sp];
	else {
		printf("error: stack empty\n");
		return 0.0;
	}
}

int getop(char s[])
{
	int i, c;

	while ((s[0]= c = getch()) == ' ' || c == '\t')
		;
	s[1] = '\0';
	if (!isdigit(c) && c != '.')
		return c;      
	i = 0;
	if (isdigit(c)) 
		while (isdigit(s[++i] = c = getch()))
			;
	if (c == '.') 
		while (isdigit(s[++i] = c = getch()))
			;
	s[i] = '\0';
	if (c != EOF)
		ungetch(c);
	return NUMBER;
}

int getch(void) 
{
	return (bufp > 0) ? buf[--bufp] : getchar();
}

void ungetch(int c) 
{
	if (bufp >= BUFSIZE)
		printf("ungetch: too many characters\n");
	else
		buf[bufp++] = c;
}



Measured memory_bytes: 2128
#include <iostream>
#include <string>
using namespace std;
using ll = int64_t;

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

  ll total_r = 0;
  for(ll i=0; i<S.size(); i++) {
    if(S[i]=='R') {
      total_r++;
    }
  }

  // Pick some position. All stones to the left must be red; all right must be white
  ll nr = 0;
  ll nw = 0;
  ll ans = n;
  for(ll i=0; i<=n; i++) {
    ll bad_left = nw;
    ll bad_right = total_r - nr;
    //cerr << " i=" << i << " bad_left=" << bad_left << " bad_right=" << bad_right << endl;
    ans = min(ans, max(bad_left, bad_right));
    if(S[i]=='R') {
      nr++;
    } else {
      nw++;
    }
  }
  cout << ans << endl;
}


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

using namespace std;

#define ll  long long
#define ld  double

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

#define pb  emplace_back
#define X   first
#define Y   second

const int   N   = 2e5 + 5;

typedef pair<int,int>   ii;

int a[N];
int t[N];

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

    string S;   cin >> S;
    int n = S.size();

    vector<ii>  vec;
    vector<int> pos[26];

    for(int i = 0 ; i < sz(S) ; ++i)
        pos[S[i] - 'a'].pb(i);

    bool check = 0;

    for(int i = 0 ; i < 26 ; ++i)   if (sz(pos[i]) & 1) {
        if (check)  {   cout << -1; return  0;  }
        else
            check = 1;
    }

    for(int i = 0 ; i < 26 ; ++i)
    for(int j = 0, k = sz(pos[i]) - 1 ; j < k ; ++j, --k)
        vec.pb(pos[i][j],pos[i][k]);
    
    sort(all(vec));

    int lef = 0;
    int rig = n - 1;

    for(ii  e : vec)    {
        a[lef++] = e.X;
        a[rig--] = e.Y;       
    }
    if (check)  {
        for(int i = 0 ; i < 26 ; ++i)   {
            int m = sz(pos[i]);
            if (m & 1)
                a[lef] = pos[i][m / 2];
        }
    }
    ll  ans = 0;

    for(int i = 0 ; i < n ; ++i)    {
        for(int p = a[i] + 1 ; p < N ; p += p & -p)    ans += t[p];
        for(int p = a[i] + 1 ; p > 0 ; p -= p & -p)    t[p]++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 4620
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
#define FOR(I,A,B) for(int I=int(A);I<int(B);++I)
#define FORR(I,A,B) for(int I=int(B-1);I>=int(A);--I)

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	int n;
	cin >> n;
	map<pair<int,P>,int> ma;
	FOR(i,0,n){
		int b,f,r,v;
		cin >> b >> f >> r >> v;
		ma[{b,{f,r}}] += v;
	}
	FOR(b,1,5){
		FOR(f,1,4){
			FOR(r,1,11){
				cout << ' ' << ma[{b,{f,r}}];
			}
			cout << '\n';
		}
		if(b!=4)cout<<"####################\n";
	}
}



Measured memory_bytes: 3144
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

class Main {

    public static void main(String[] args) throws Exception {

        try {

            BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

            String[] inputString = br.readLine().split(" ");
            int carsCount = Integer.parseInt(inputString[0]);
            int fromFrontCarNumber = Integer.parseInt(inputString[1]);

            int fromBackCarNumber = carsCount - fromFrontCarNumber + 1;
            System.out.println(fromBackCarNumber);

        } catch (IOException | NumberFormatException e) {
            e.printStackTrace();
            System.exit(0);
        } catch (final Exception e) {
            e.printStackTrace();
            System.exit(0);
        }
    }
}

Measured memory_bytes: 24916
#include <stdio.h>

int main(void)
{
    int n;
    float x1, y1, x2, y2, x3, y3, x4, y4;
    float ax, ay, bx, by;
    float cross;

    do{
      scanf("%d", &n);
    }while(n >= 100);

    while(n){
      scanf("%f %f %f %f %f %f %f %f", &x1, &y1, &x2, &y2, &x3, &y3, &x4, &y4);

        ax = x1 - x2;
        ay = y1 - y2;
        bx = x3 - x4;
        by = y3 - y4;

        cross = ax * by  - ay * bx;
  
        if(cross == 0)
            printf("YES\n");
        else
            printf("NO\n");
	n--;
    }
    return 0;
}

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

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<int, pii> pipii;
typedef pair<pii, pii> piipii;

#define mp make_pair
#define fi first
#define se second
#define all(a) (a).begin(), (a).end()
#define sz(a) (int)(a).size()
#define eb emplace_back
const int mod = 1e9+7;
ll f[100005];
int main(){
    f[0] = 1;
    for(int i=1;i<=100000;i++) f[i] = f[i-1]*i%mod;
    int a, b;
    scanf("%d%d", &a, &b);   
    if(a < b) swap(a, b);
    if(a-b >= 2) printf("0\n");
    else{
        ll ans;
        if(a-b == 1) ans = f[a]*f[b]%mod;
        else ans = f[a]*f[b]%mod*2%mod;
        printf("%lld\n", ans);
    }
}

Measured memory_bytes: 1152
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
using P = pair<lint, lint>;
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
#define ALL(a)  (a).begin(),(a).end()
constexpr lint MOD = 1000000007;
constexpr int INF = 2147483647;
constexpr double EPS = 1e-6;
void yes(bool expr) {
  cout << (expr ? "Yes" : "No") << "\n";
}


int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int N, A, B;
  cin >> N >> A >> B;
  vector<lint> v(N);
  REP(i, N) cin >> v[i];
  sort(ALL(v), greater<lint>());
  lint sum = 0;
  REP(i, A) sum += v[i];
  double mean = (double)sum/(double)A;
  cout << fixed << setprecision(10) << mean << "\n";

  lint ans = 0;
  lint ncr[51][51];
  REP(i, 51) REP(j, i+1) {
    if(j == 0 || j == i) ncr[i][j] = 1;
    else ncr[i][j] = ncr[i-1][j-1] + ncr[i-1][j]; 
  }
  lint cnt1 = 0;
  REP(i, N) if(v[A-1] == v[i]) cnt1++;
  FOR(k, A, B+1) {
    if(k != A && v[k-1] != v[0]) break;
    lint cnt2 = 0;
    REP(i, k) if(v[A-1] == v[i]) cnt2++;
    ans += ncr[cnt1][cnt2];
  }
  
  cout << ans << "\n";

}

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

using namespace std;
const int N = 1e5+5;
const int MOD = 1e9+7;
vector<int> v[N];
long long dp[2][N];
void dfs(int x, int u)
{
    long long prwhite = 1, prall = 1;
    for (auto it: v[x])
        if (it!=u)
        {
            dfs(it,x);
            prwhite = (prwhite*dp[0][it])%MOD;
            prall = (prall*(dp[1][it]+dp[0][it])%MOD)%MOD;
        }
    dp[0][x] = prall;
    dp[1][x] = prwhite;
}

int main()
{
    int n;
    cin >> n;
    for (int i = 1; i<n; i++)
    {
        int x,y;
        cin >> x >> y;
        v[x].push_back(y);
        v[y].push_back(x);
    }
    dfs(1,0);
    cout << (dp[1][1]+dp[0][1])%MOD;
}


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

int main()
{
    int n,i,j,k,l,cnt=1;
    cin>>n;
    string s;
    cin>>s;
    for(i=1;i<n;i++){
        if(s[i]!=s[i-1])cnt++;
    }
    cout<<cnt<<endl;
    return 0;
}


Measured memory_bytes: 512
#数字の入力
x = input()
N = int(x)

#各桁の数字
a = int(N/1000)
b = int((N-1000*a)/100)
c = int((N-1000*a-100*b)/10)
d = int(N-1000*a-100*b-10*c)

#いい整数かどうかを判定
if 1000>N or N>9999:
    print("No")
elif a==b==c or b==c==d:
  print("Yes")
else:
  print("No")

Measured memory_bytes: 3064
from fractions import gcd


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

gcd_l = [0]
gcd_r = [0]
for i in range(N):
    gcd_l.append(gcd(gcd_l[i], A[i]))
    gcd_r.append(gcd(gcd_r[i], A[-(i+1)]))

gcd_r = gcd_r[::-1]

ans = []
for i in range(N):
    ans.append(gcd(gcd_l[i], gcd_r[i+1]))

print(max(ans))

Measured memory_bytes: 99936
X,Y,Z,K=map(int,input().split())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
C=list(map(int,input().split()))
A.sort()
B.sort()
C.sort()
AB=[]
for a in A:
  for b in B:
    AB.append(-(a+b))
import heapq
heapq.heapify(AB)
ABC=[]
for _ in range(min(K,len(AB))):
  ab=heapq.heappop(AB)
  for c in C:
    heapq.heappush(ABC,ab-c)
for i in range(K):
  print(-heapq.heappop(ABC))
  

Measured memory_bytes: 186108
require "prime"

def divisors(n)
  n.prime_division.inject([1]) do |ary, (p, e)|
    (0..e).map{ |e1| p ** e1 }.product(ary).map{ |a, b| a * b }
  end.sort
end

num = STDIN.gets.chomp.split(" ").map(&:to_i)[0]
array = divisors(num)
if array.size.even?
  puts array[array.size/2-1] + array[array.size/2] - 2
else
  puts array[array.size/2] * 2 - 2
end

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

signed main() {
  int A,B;
  cin >> A >> B;
  if(A<1 || A>9 || B<1 || B>9) {
    puts("-1");
    return 0;
  }
  cout << A*B << endl;

}


Measured memory_bytes: 256
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>

int main(int argc, char **argv)
{
	uint64_t A, B, K;
	scanf("%ld %ld %ld", &A, &B, &K);
	if (A >= K) {
		printf("%ld %ld\n", A-K, B);
		return 0;
	}
	K -= A;
	if (B >= K) {
		printf("0 %ld\n", B-K);
		return 0;
	}
	printf("0 0\n");
	return 0;
}


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

int main(){
    int a, b;
    double t;
    cin >> a >> b >> t;
    t += 0.5;

    int ans = 0;
    for(int i = 0; i <= t; i+=a){
        ans += b;
    }

    cout << ans - b << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>

int main(){
    long int S;
    int min = 1000;
    int base = 753;
    int i, tmp;

    scanf("%ld", &S);

    while(S>100){
        tmp = S % 1000;
        S = S/10;
        if(min > abs(tmp-base)){
            min = abs(tmp-base);
        }
    }

    printf("%d", min);

    return 0;
}

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

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


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


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

    ans = 0
    for x in X:
        ans += min(x, abs(K - x))
    print(ans * 2)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3952
def main():
    from sys import stdin, setrecursionlimit
    #setrecursionlimit(10**9)
    #n = int(stdin.readline()[:-1])   
    r = stdin.readline()[:-1]
    #n = int(stdin.readline()[:-1])   
    #r = [stdin.readline() for i in range(n)]
    #t = [int(stdin.readline()) for i in range(n)]
    #a = r.split()
    a, b, c = r.split()
    #a = list(map(int, r.split()))
    #a,b,c = map(int, r.split())
    #a = [int(s[i]) for i in range(1, n+1)]
    #a = [list(map(int, r.split())) for i in range(1,n+1)]
    #res = 0

    if a[-1] == b[0] and b[-1] == c[0]:
        print('YES')
    else:
        print('NO')

if __name__ == '__main__':
    main()


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

int Merge(int A[], int left, int mid, int right){
   int n1=mid-left;
   int n2=right-mid;
   int i, j, k;
   int L[n1+1], R[n2+1];

   for(i=0; i<n1; i++) L[i]=A[left+i];
   for(i=0; i<n2; i++) R[i]=A[mid+i];
   L[n1]=1000000000;
   R[n2]=1000000000;

   i = j = 0;
   for(k=left; k<right; k++){
      if(L[i]<=R[j]){
         A[k]=L[i];
         i++;
      }else{
         A[k]=R[j];
         j++;
      }
   }
   return right-left;
}

int Merge_Sort(int A[], int left, int right){
   int mid, res=0;
   if(left+1<right){
      mid=(left+right)/2;

      res+=Merge_Sort(A, left, mid);
      res+=Merge_Sort(A, mid, right);
      res+=Merge(A, left, mid, right);

   }
   return res;
}

int main(){
   int i, x, n, S[500000];
   cin >> n;
   for(i=0; i<n; i++) cin >> S[i];

   x=Merge_Sort(S, 0, n);

   for(i=0; i<n; i++){
      if(i) cout << " ";
      cout << S[i];
   }
   cout << endl;
   cout << x << endl;
   return 0;
}


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


int main(void){
  int N, t=0; 
  cin >> N;
  vector<int> v(N);
  for(int i=0;i<N;i++) cin >> v[i];
  for(int i=0;i<N;i++){
    int min=i;
    for(int j=i+1; j<N;j++){
      if(v[min] > v[j]){
        min = j;
      }
    }
    if(v[i] > v[min]){
      swap(v[i], v[min]);
      t++;
    }
  }
  for(int i=0;i<N;i++){
    cout << v[i];
    if(i != N-1)cout << " ";
    else cout << endl;
  }
  cout << t << endl;
  return 0; 
}

Measured memory_bytes: 1196
import collections
n=int(input())
a=list(map(int,input().split()))
mod=10**9+7
a.sort()

if n%2==0:
    if a[0]!=1:
        print(0)
        exit()
    for i in range(n-1):
        if (i%2==0 and a[i]!=a[i+1]) or i%2==1 and (a[i+1]-a[i]!=2):
            print(0)
            exit()
else:
    if a[0]!=0:
        print(0)
        exit()
    for g in range(1,n-1):
        if (g%2==1 and a[g]!=a[g+1]) or g%2==0 and (a[g+1]-a[g]!=2):
            print(0)
            exit()

print(2**(n//2)%mod)

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

int main() {
  int N;
  cin >> N;
  vector<long long int> A(N+1);
  vector<long long int> B(N);
  for (int i = 0; i < N+1; i++){
    cin >> A.at(i);
  }
  for (int i = 0; i < N; i++){
    cin >> B.at(i);
  }
  long long int ans = 0;
  for (int i = 0; i < N; i++){
    if(A.at(i) <= B.at(i)){
      ans += A.at(i);
      B.at(i) -= A.at(i);
      A.at(i) = 0;
    } else {
      ans += B.at(i);
      A.at(i) -= B.at(i);
      B.at(i) = 0;
    }
    if(A.at(i+1) <= B.at(i)){
      ans += A.at(i+1);
      B.at(i) -= A.at(i+1);
      A.at(i+1) = 0;
    } else {
      ans += B.at(i);
      A.at(i+1) -= B.at(i);
      B.at(i) = 0;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1792
from collections import deque
s = deque(input())
n = int(input())
re = 0
st = ''
en = ''
for i in range(n):
    a = list(input().split())
    if a[0]=='1':
        re = 1 if re==0 else 0
    else:
        if a[1]=='1':
            if re==0:
                s.appendleft(a[2])
            else:
                s.append(a[2])
        else:
            if re==0:
                s.append(a[2])
            else:
                s.appendleft(a[2])
if re==1:
    s.reverse()
res = list(s)
print(''.join(res))

Measured memory_bytes: 9076
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

#define mod         1000000007
#define pi          acos(-1.0)
#define eps         1e-9

#define fast       ios::sync_with_stdio(0); cin.tie(0);cout.tie(0)
#define fs          first
#define sc          second
#define pb         push_back
#define sp          printf(" ")
#define nl          '\n'
#define all(a) a.begin(),a.end()
#define itn int

#define set0(a)     memset(a,0,sizeof(a))
#define setneg(a)   memset(a,-1,sizeof(a))
#define setinf(a)   memset(a,126,sizeof(a))

typedef long long LL;
typedef long double LD;
typedef unsigned long long ULL;
typedef pair<int, int> pii;
typedef pair<LL, LL> pll;
typedef pair<double, double> pdd;
typedef vector<int> vi;
typedef vector<LL> vll;
typedef vector<double> vd;


void solve()
{
    int n;
    cin>>n;
    LL arr[n+1];
    for(int i=1;i<=n;i++)
        cin>>arr[i];
    LL dp[n+1];
    dp[1]=0;
    dp[2]=abs(arr[1]-arr[2]);
    for(int i=3;i<=n;i++)
        dp[i]=min(dp[i-1]+abs(arr[i]-arr[i-1]), dp[i-2]+abs(arr[i]-arr[i-2]));
    cout<<dp[n]<<nl;
}
int main()
{   fast;
        solve();
}


Measured memory_bytes: 1792
#include <iostream>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <functional>
using namespace std;
#define int long long

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin>>n;
    int res=0;
    for(int i=0;i<=n;i++){
        if(i%3==0||i%5==0)continue;
        res+=i;
    }
    cout<<res<<endl;
}

Measured memory_bytes: 3652
package main

import "fmt"

func main() {
	var n, x int
	fmt.Scan(&n, &x)

	m := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&m[i])
	}

	ans := 0
	min := 1001
	for _, v := range m {
		if v < min {
			min = v
		}
		ans++
		x -= v
	}

	fmt.Println(ans + x/min)
}


Measured memory_bytes: 512
n=int(input())
S=input()
w_t=S.count("W")
w_c=0
ans=float("inf")
for i in range(n):
  if S[i]=="W":
    t=1
  else:
    t=0
  ans=min(ans,w_c+n-i-1-(w_t-w_c-t))
  if S[i]=="W":
    w_c+=1
print(ans)

Measured memory_bytes: 3700
#include <bits/stdc++.h>
using namespace std;
#define LL long long
#define mp make_pair
#define fi first
#define se second
#define pb push_back

LL N,A,B;

int main(){
	
	cin >> A >> B;
	for ( int i = 1; i <= 10000; i++ ){
		LL a = i * 8 / 100;
		LL b = i * 10 / 100;
		if ( a == A && b == B ){
			printf("%d\n",i);
			return 0;
		}
	}	
	printf("-1\n");
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<utility>
#include<algorithm>
#include<cstdio>
#include<iomanip>
#include<queue>
#include<stack>

#define ll int64_t
#define Rep(i, n) for (ll i = 0; i < n; i++)

using namespace std;

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

    string s;
    cin >> s;
    ll ans = 0;
    Rep (i, 4) {
        if (s[i] == '2') ans++;
    }

    cout << ans << "\n";
}

Measured memory_bytes: 256