akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
int main() {
  int memo, A, B, C, D;
  cin >> memo;
  A = memo / 1000;
  B = (memo % 1000) / 100;
  C = (memo % 100) / 10;
  D = memo % 10;
  for (int tmp = 0; tmp < (1 << 3); tmp++) {
    bitset<3> s(tmp);
    int memo2 = A;
    if (s.test(0)) {
      memo2 += B;
    }
    else {
      memo2 -= B;
    }
    if (s.test(1)) {
      memo2 += C;
    }
    else {
      memo2 -= C;
    }
    if (s.test(2)) {
      memo2 += D;
    }
    else {
      memo2 -= D;
    }
    if (memo2 == 7) {
      cout << A;  
      if (s.test(0)) {
        cout << "+";
      }
      else {
        cout << "-";
      }
      cout << B;  
      if (s.test(1)) {
        cout << "+";
      }
      else {
        cout << "-";
      }
      cout << C;  
      if (s.test(2)) {
        cout << "+";
      }
      else {
        cout << "-";
      }
      cout << D << "=7" << endl;
      break;
    }
  }
}

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

long long N, A[87];
long long dp[87];

int main() {
	cin >> N;
	for (int i = 1; i <= N; i++) cin >> A[i];

	dp[1] = 1000;
	for (int i = 2; i <= N; i++) {
		dp[i] = dp[i - 1];
		for (int j = 1; j <= i - 1; j++) {
			long long V = dp[j] / A[j];
			long long W = dp[j] + (A[i] - A[j]) * V;
			dp[i] = max(dp[i], W);
		}
	}
	cout << dp[N] << endl;
	return 0;
}

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

#define mp make_pair
#define pb push_back

#define int int64_t
#define ld long double

const int MOD = 1e9+7;
const int N = 1e6+5;

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

	string s;
	cin>>s;
	if(s[1]=='B')
	s[1]='R';
	else
	s[1]='B';
	cout<<s;	

	return 0;
}

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

#define rep(i,n) for(int i=0; i<(n); i++)
#define reps(i,x,n) for(int i=x; i<(n); i++)
#define rrep(i,n) for(int i=(n)-1; i>=0; i--)
#define all(X) (X).begin(),(X).end()
#define X first
#define Y second
#define pb push_back
#define eb emplace_back

using namespace std;
typedef long long int ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

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

template<class A, size_t N, class T> void Fill(A (&a)[N], const T &v){ fill( (T*)a, (T*)(a+N), v ); }

const ll INF = 1e9+7;


int main(){
	//ios_base::sync_with_stdio(0);
	string S;
	int ans = INF;

	cin >> S;

	bool f = true;
	rep(i,S.length()-1){
		if( S[i] != S[i+1] ) f = false;
	}
	if(f) ans = 0;

	for(char c='a'; c<='z'; c++){
		string t = S;
		int cnt = 0;
		while(true){
			cnt++;
			bool f = true;
			rep(i,t.length()-1){
				if( t[i] == c || t[i+1] == c ){
					t[i] = c;
				}else{
					f = false;
				}
			}
			t.pop_back();
			if(f) break;
		}
		chmin(ans, cnt);
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int max(int a,int b,int c)
{
    if(a>=b&&a>=c)
        return a;
    else if(b>=c)
        return b;
    else
        return c;
}
void testcase()
{
    int n;
    scanf("%d",&n);
    int a[n+2],b[n+2],c[n+2];
    int dp[n+3][3];
    for(int i=0;i<n;i++)
    {
        scanf("%d %d %d",&a[i],&b[i],&c[i]);
    }
    for(int i=0;i<n;i++)
    {
        if(i==0)
        {
            dp[0][0]=a[0];
            dp[0][1]=b[0];
            dp[0][2]=c[0];
        }
        else
        {
            dp[i][0]=a[i]+max(dp[i-1][1],dp[i-1][2],-1);
            dp[i][1]=b[i]+max(dp[i-1][0],dp[i-1][2],-1);
            dp[i][2]=c[i]+max(dp[i-1][0],dp[i-1][1],-1);
        }
    }
    printf("%d",max(dp[n-1][0],dp[n-1][1],dp[n-1][2]));
}
int main()
{
    testcase();
    return 0;
}


Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;

long long quick_pow(long long a, long long b){
	long long ans = 1;
	while (b){
		if (b & 1){
			ans = (ans * a) % MOD;
		}
		a = (a * a) % MOD;
		b /= 2;
	}
	return ans;
}

int main(){
	ios::sync_with_stdio(0);
	cout << setprecision(10) << fixed;
	long long n, k;
	cin >> n >> k;
	vector<long long> d(k + 1, 0);
	long long ans = 0;
	for (int i = k; i >= 1; --i){
		long long f = k / i;
		long long temp = (quick_pow(f, n) % MOD) % MOD;
		long long extra = 0;
		for (int j = i + i; j <= k; j += i){
			extra = (extra + d[j]) % MOD;
		}
		d[i] = (temp - extra + MOD) % MOD;
	}
	for (int i = 1; i <= k; ++i){
		ans = (ans + i % MOD * d[i] % MOD) % MOD;
	}
	cout << ans;
	return 0;
}



Measured memory_bytes: 3984
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <sstream>
#include <set>
#include <map>
#include <iostream>
#include <utility>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <unordered_set>
#include <unordered_map>
#include <limits.h>
#include <cstring>
#include <tuple>
#include <cassert>
#include <numeric>
using namespace std;
// type alias
typedef long long LL;
typedef vector < int > VI;
typedef unordered_map < int, int > MAPII;
typedef unordered_set < int > SETI;
typedef pair< int , int > II;
typedef tuple< int, int, int > III;
// repetition
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)
#define REPE(i,n)  for(int i=0;i<=(n);++i)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  for(int i=0;i<(n);++i)
#define FORR(x,arr) for(auto& x:arr)
#define SZ(a) int((a).size())
// DP
#define MINUS(dp) memset(dp, -1, sizeof(dp))
#define ZERO(dp) memset(dp, 0, sizeof(dp))
// minmax
#define SMAX(a,b) a = max(a,b)
#define SMIN(a,b) a = min(a,b)
// debug cerr
#define TRACE true
#define dump(x) if(TRACE) { cerr << #x << " = " << (x) << endl; }
#define dump2(x,y) if(TRACE) { cerr << #x << " = " << (x) << ", " << #y << " = " << (y) << endl; }
#define dump3(x,y,z) if(TRACE) { cerr << #x << " = " << (x) << ", " << #y << " = " << (y) << ", " << #z << " = " << (z) << endl; }
#define dump4(x,y,z,a) if(TRACE) { cerr << #x << " = " << (x) << ", " << #y << " = " << (y) << ", " << #z << " = " << (z) << ", " << #a << " = " << (a) << endl; }
#define dumpAR(ar) if(TRACE) { FORR(x,(ar)) { cerr << x << ','; } cerr << endl; }

/*
 
 7/31/2018
 
 25:10-
 
 */

// $ g++ -std=c++14 -Wall -O2 -D_GLIBCXX_DEBUG x.cpp && ./a.out
//const int MAX_N=100+1;
LL w0,W;
vector<LL> WS[4];
vector<LL> cum[4];
int N;
LL solve() {
  REP(i,4) {
    sort(WS[i].rbegin(),WS[i].rend());
    int M=SZ(WS[i]);
    cum[i].resize(M+1,0);
    REP(j,M) cum[i][j+1]=cum[i][j]+WS[i][j];
  }
  
  LL res=0;
  REPE(a,N)if(a<SZ(cum[0])) {
    REPE(b,N-a)if(b<SZ(cum[1])) {
      REPE(c,N-a-b)if(c<SZ(cum[2])) {
        REPE(d,N-a-b-c)if(d<SZ(cum[3])) {
          LL wtot=w0*a+(w0+1)*b+(w0+2)*c+(w0+3)*d;
          if(wtot>W) continue;
          SMAX(res,cum[0][a]+cum[1][b]+cum[2][c]+cum[3][d]);
        }
      }
    }
  }
  return res;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  
  cin>>N>>W;
  LL v0;
  cin>>w0>>v0;
  WS[0].push_back(v0);
  REP(i,N-1) {
    LL w,v;
    cin>>w>>v;
    WS[w-w0].push_back(v);
  }
  cout<<solve()<<endl;
  
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>

using namespace std;

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

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

	auto b = a;
	sort(b.begin(), b.end(), greater<int>());

	if (b[0] == b[1]) {
		for (int i = 0; i < n; i++) {
			cout << b[0] << endl;
		}
	} else {
		for (int i = 0; i < n; i++) {
			if (a[i] == b[0]) {
				cout << b[1] << endl;
			} else {
				cout << b[0] << endl;
			}
		}
	}

	return 0;
}


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

ll gcd(ll x, ll y) {
	return y ? gcd(y, x%y): x;
}
ll low(ll x, ll y) {
	return y/gcd(x, y) * x;
}
int main() {
	int n;
	cin >> n;
	ll x = 1, y;
	while(n--) {
		cin >> y;
		x = low(x, y);
	}
	cout << x << endl;
	return 0;
}

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

int n, m, r;
int memo[205][205] = {0};
vector<int> ls;

int solve();

int main() {
  cin >> n >> m >> r;
  for(int i = 0; i < r; ++i) {
    int x;
    cin >> x;
    --x;
    ls.push_back(x);
  }
  for(int i = 0; i < n; ++i)
    for(int j = 0; j < n; ++j)
      if(i != j) memo[i][j] = 200000000;
  for(int i = 0; i < m; ++i) {
    int a, b, c;
    cin >> a >> b >> c;
    --a, --b;
    memo[a][b] = memo[b][a] = c;
  }
  for(int k = 0; k < n; ++k)
    for(int i = 0; i < n; ++i)
      for(int j = 0; j < n; ++j)
        memo[i][j] =
            min(memo[i][j], memo[i][k] + memo[k][j]);
  cout << solve() << endl;
  return 0;
}

int solve() {
  int ans = 2000000000;
  sort(ls.begin(), ls.end());
  do {
    int now = 0;
    for(int i = 0; i < r - 1; ++i)
      now += memo[ls[i]][ls[i + 1]];
    ans = min(now, ans);
  } while(next_permutation(ls.begin(), ls.end()));
  return ans;
}

Measured memory_bytes: 384
S = input()
Q = int(input())
front = ""
flag = 1
for i in range(Q):
    q =  [ i for i in input().split(' ')]
    if q[0] == '1':
        flag = flag * -1
    else:
        if flag == 1: 
            if q[1] == '1':
                front+=q[2]
            else:
                S += q[2]
        else:
            if q[1] == '1':
                S +=q[2]
            else:
                front+= q[2]
            
if flag ==1:
    print(front[::-1] + S)
else:
    print(S[::-1] + front)

Measured memory_bytes: 4476
#include <stdio.h>
#include <string.h>
#include <math.h>
#define rep(i,l,n) for(i=l;i<n;i++)
int g(int x,int y){
	int c;
	if(x<y){
		c=x;
		x=y;
		y=c;
	}
	if(y==0){
		return x;
	}else{
		return g(x%y,y);
	}
}

int main(void){
	int A,B,a,b,G,L;
	while(scanf("%d %d",&A,&B)!=EOF){
		G=g(A,B);
		a=A/G;
		b=B/G;
		L=a*b*G;
		printf("%d %d\n",G,L);
	}
	
	return 0;
}

Measured memory_bytes: 596
#include<stdio.h>
long long max(int start,int fin,long long *s){
  if(start==fin)
    return s[start];
  long long a=max(start,(start+fin)/2,s);
  long long b=max((start+fin)/2+1,fin,s);
  if(a<b)
    return b;
  else
    return a;
}

int main(){
  long long i,n,people[6];
  scanf("%lld",&n);
  for(i=0;i<5;i++){
    scanf("%lld",&people[i]);
    if(n%people[i]!=0)
      people[i]=n/people[i]+1;
    else
      people[i]=n/people[i];
  }
  printf("%lld\n",max(0,4,people)+4);
  return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <iomanip>
#include <cctype>
#include <cstdlib>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#include <cmath>
#define rep(i, n) for(int i = 0; i < n; ++i)
using namespace std;

int comp(const void* a, const void* b){
	return *(int*)a - *(int*)b;
}

int main() {
	int n, t, a, h[1020], temp, ans, cnt;
	cin >> n >> t >> a;
	rep(i, n){
		cin >> h[i];
		temp = t * 1000 - h[i] * 6;
		if(i == 0){
			ans = abs(temp-a*1000);
			cnt = i+1;
		}else{
			if(ans > abs(temp-a*1000)){
				cnt = i+1;
				ans = abs(temp-a*1000);
			}
		}
	}
	cout << cnt << endl;	
}

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


int main()
{
    long long n,t,i,sum;
    cin>>n>>t;
    long long a[n+2];
    for(i=0;i<n;i++)
    {
        cin>>a[i];
    }
    sum=t;
    for(i=0;i+1<n;i++)
    {
        if((a[i+1]-a[i])>=t)
        {
            sum+=t;
        }
        else
        {
            sum+=(a[i+1]-a[i]);
        }

    }
    cout<<sum<<endl;
    return 0;
}


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

#define REP(i, m, n) for (int i = (m); i < (int)(n); i++)
#define REPS(i, m, n) for (int i = (m); i <= (int)(n); i++)
#define rep(i, n) REP(i, 0, n)
#define reps(i, n) for (int i = 0; i <= (int)(n); i++)
#define rrep(i, x) for (int i = ((int)(x)-1); i >= 0; i--)
#define rreps(i, x) for (int i = (int)(x); i >= 0; i--)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define pb push_back
#define fi first
#define se second
typedef long long ll;
typedef pair<int, int> P;
const int inf = INT_MAX;
const ll INF = 1LL << 60;
const ll mod = 1e9 + 7;
const double EPS = 1e-10;
const double PI = acos(-1.0);
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val) { fill( (T*)array, (T*)(array+N), val ); }
template <class T1, class T2, class Pred = std::less<T2> >
struct sort_pair_second {
    bool operator()(const std::pair<T1,T2>&left, const std::pair<T1,T2>&right) {
        Pred p;
        return p(left.second, right.second);
    }
};

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

    ll A, B, C, K;
    cin >> A >> B >> C >> K;
    ll cnt = 0;
    rep(i, A) {
      if (!K) break;
      K--;
      cnt++;
    }
    rep(i, B) {
      if (!K) break;
      K--;
    }
    rep(i, C) {
      if (!K) break;
      K--;
      cnt--;
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 3644
/*
	author: parv2809
*/

#include<bits/stdc++.h>
#define int long long int
#define mod 1000000007
#define inf 1e18
#define fo(i,y,n,inc)	for(int i=y;i<n+y;i+=inc)
#define cin(t) int t;cin>>t
#define w(t) while(t--)
#define nl cout<<endl;
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define ft(i) (i&(-1*i))
#define arrIn(arr,size)		for(int i=0;i<size;i++){cin>>arr[i];}
#define arrOut(arr,size,seperater)	for(int i=0;i<size;i++){cout<<arr[i]<<seperater;}
using namespace std;

int max(int a, int b) {
	if (a > b)
		return a;
	return b;
}

int min(int a, int b) {
	if (a < b)
		return a;
	return b;
}

int powmd(int a, int b) {
	if (b == 1)	return a;
	if (b == 0)	return 1;

	int half = powmd(a, b / 2);
	int ans = half * half;
	ans %= mod;
	if (b & 1) {
		ans *= a;
	}
	ans %= mod;
	return ans;
}

void fastIO() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);
}

int fact[200005];
int inv[200005];
int H, W;

int inverse(int n) {
	return powmd(n, mod - 2);
}

void pre_process() {

	fact[0] = 1;
	inv[0] = 1;

	for (int i = 1; i <= 200000; i++) {
		fact[i] = (fact[i - 1] * i) % mod;
		inv[i] = inverse(fact[i]);
	}
}

int ways_between_points(pair<int, int>& a, pair<int, int>& b) {
	int right = b.second - a.second;
	int down = b.first - a.first;
	if (right >= 0 and down >= 0) {
		int ways = (((fact[right + down] * inv[right]) % mod) * inv[down]) % mod;
		return ways;
	}
	return 0;
}

int solve(vector<pii>& obstacles) {

	pair<int, int> first(1, 1);
	pair<int, int> last(H, W);

	int total_ways = ways_between_points(first, last);

	vector<int> paths_from_obstacles;
	paths_from_obstacles.push_back(ways_between_points(first, obstacles[0]));

	for (int i = 1; i < obstacles.size(); i++) {
		int ways = ways_between_points(first, obstacles[i]);
		for (int j = i - 1; j >= 0; j--) {
			ways -= (paths_from_obstacles[j] * ways_between_points(obstacles[j], obstacles[i])) % mod % mod;
			ways += mod;
			ways %= mod;
		}
		paths_from_obstacles.push_back(ways);
	}

	for (int i = 0; i < paths_from_obstacles.size(); i++) {
		total_ways -= (paths_from_obstacles[i] * ways_between_points(obstacles[i], last)) % mod;
		total_ways += mod;
		total_ways %= mod;
	}

	return total_ways;
}

bool custom_compare(pii& a, pii& b) {
	return (a.first + a.second) < (b.first + b.second);
}

int32_t main() {

	fastIO();
	int t = 1;
	w(t) {
		pre_process();
		int n;
		cin >> H >> W >> n;

		vector<pii> obstacles(n);

		for (int i = 0; i < n; i++) {
			cin >> obstacles[i].first >> obstacles[i].second;
		}

		sort(obstacles.begin(), obstacles.end(), custom_compare);

		cout << solve(obstacles) << endl;
	}

	return 0;
}

// cout << "Case #" << i << ": " << answer << endl;

Measured memory_bytes: 6892
package main

import "fmt"

func main() {
  var N int
  fmt.Scan(&N)
  var n float64
  n = float64(N%2)
  if n == 0 {
    n = float64(N)
    fmt.Println((n/2)/n)
  } else {
    n = float64(N)
    fmt.Println(((n-1)/2)/n + 1/n)
  }
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)x.size()
#define D(x) cerr << #x << " = " << (x) << '\n'
using ll = long long;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	int k;
	string s;
	cin >> k >> s;
	for(int i = 0; i < min(k, sz(s)); ++ i) cout << s[i];
	if(sz(s) > k) cout << "...";
	cout << '\n';
}


Measured memory_bytes: 3632
n=int(input())
S=input()
count1=0
m=0
for i in range(1,n):
    x=S[:i]
    y=S[i:]
    x1=list(x)
    x2=set(x1)
    for i in x2:
        if y.count(i)>=1:
            count1+=1
    m=max(count1,m)
    count1=0
    x=""
    y=""
    x1=[]
    x2=[]
print(m)


Measured memory_bytes: 3064
#ABC120B_KthCommonDivisor.rb
a,b,k = gets.split.map(&:to_i)
ar = []
a,b = b,a if a > b

(1..a).each do |n|
  if a%n==0 && b%n==0
    ar << n
  end
end

puts ar[ar.size-k]


Measured memory_bytes: 1788
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <functional>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>

using namespace std;

#define pi 3.141592653589793)
#define mod 1000000007

int N, F[101][11];
long long P[101][11];
bool flag[10];
int cnt[101];
long long ans = -99999999999999999;


void dfs(int i) {
	if (i == 10) {
		int flagCnt = 0;
		for (int s = 0; s < N; s++) cnt[s] = 0;
		for (int j = 0; j < 10; j++) {
			if (flag[j]) {
				for (int k = 0; k < N; k++) {
					if(F[k][j]==1)
						cnt[k]++;
				}
			}
			else {
				flagCnt++;
			}
		}
		if (flagCnt == 10) return;
		long long tmp = 0;
		for (int k = 0; k < N; k++) {
			tmp += P[k][cnt[k]];
		}
		ans = max(tmp, ans);
		return;
	}

	flag[i] = true;
	dfs(i + 1);
	flag[i] = false;
	dfs(i + 1);
}

void solve() {
	cin >> N;
	for (int i = 0; i < N; i++)
		for (int j = 0; j < 10; j++)
			cin >> F[i][j];
	for (int i = 0; i < N; i++)
		for (int j = 0; j <= 10; j++)
			cin >> P[i][j];
	dfs(0);
	cout << ans << endl;
}

int main() {
	solve();
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		final Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		long time = 0L;
		long[] num = new long[n];
		long[] baisu = new long[n];
		for(int i = 0; i < n; i++) {
			num[i] = sc.nextLong();
			baisu[i] = sc.nextLong();
		}
		for(int i = n-1; i >= 0; i--) {
			long p = baisu[i]-(num[i]+time)%baisu[i];
			if(p!=baisu[i]) time+=p;
		}
		System.out.println(time);
	}
}

Measured memory_bytes: 89668
#include "bits/stdc++.h"
using namespace std;
typedef long long int lint;
typedef pair<lint, lint> plint;
typedef pair<double long, double long> pld;
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((lint)(x).size())
#define POW2(n) (1LL << (n))
#define FOR(i, begin, end) for(lint i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(lint 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)
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; }
template<typename T1, typename T2> pair<T1, T2> operator+(const pair<T1, T2>& l, const pair<T1, T2>& r) { return make_pair(l.first + r.first, l.second + r.second); }
template<typename T1, typename T2> pair<T1, T2> operator-(const pair<T1, T2>& l, const pair<T1, T2>& r) { return make_pair(l.first - r.first, l.second - r.second); }
const lint MOD = 1e9 + 7, INF = 1e18;

lint N;
lint dp[200][200];
bool visited[200];
set<lint> st0, st1;

int main() {
	cin.tie(0); ios_base::sync_with_stdio(false);
	lint X, Y;
	cin >> X >> Y;
	if (X * 2 <= Y && Y <= X * 4 && Y%2 == 0) {
		cout << "Yes";
	}
	else {
		cout << "No";
	}
}


Measured memory_bytes: 3652
#include<stdio.h>
#include<stdlib.h>
#define min(a,b) ((a)<(b)?(a):(b))

long long abss(long long a){
		if(a<0)return -a;
		return a;
}

int compare_int(const void *a,const void *b){
		return *(long long*)a-*(long long*)b;
}

int main(){
		int n,i;
		long long a[100000],ans[2];ans[1]=-1000000000000;
		scanf("%d",&n);
		for(i=0;i<n;i++)scanf("%lld",&a[i]);
		qsort(a,n,sizeof(long long),compare_int);
		ans[0]=a[n-1];
		for(i=0;i<n-1;i++){
				long long tmp=min(a[i],-a[i]+ans[0]);
				long long ant=min(ans[1],-ans[1]+ans[0]);
				if(abss(tmp-ans[0]/2)<abss(ant-ans[0]/2))ans[1]=a[i];
		}
		printf("%lld %lld\n",ans[0],ans[1]);
		return 0;
}


Measured memory_bytes: 1788
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#define N 302
#define ckmax(x,y) x = x > y ? x : y

using namespace std;

int n, m;
int a[N][N], b[N][N], f[N][N][N], g[N][N][N], h[2][N][N][N];
char s[N][N];

int find(int ,int ,int ,int);
int get(int ,int ,int ,int);

int main(){
	scanf("%d%d", &n, &m);
	memset(f, -1, sizeof f);
	for(int i = 1; i <= n; ++i)
		scanf("%s", s[i] + 1);
	for(int i = 1; i <= n; ++i)
		for(int j = m; j; --j)
			a[i][j] = (s[i][j] == s[i][j + 1] ? a[i][j + 1] : 0) + 1;
	for(int j = 1; j <= m; ++j)
		for(int i = n; i; --i)
			b[i][j] = (s[i][j] == s[i + 1][j] ? b[i + 1][j] : 0) + 1;
	for(int i = 1; i <= n; ++i)
		for(int j = 1; j <= m; ++j){
			f[i][j][j] = b[i][j];
			for(int k = j + 1; k <= m; ++k)
				f[i][j][k] = min(f[i][j][k - 1], s[i][k] == s[i][k - 1] ? b[i][k] : 0);
		}
	for(int j = 1; j <= m; ++j)
		for(int i = 1; i <= n; ++i){
			g[j][i][i] = a[i][j];
			for(int k = i + 1; k <= n; ++k)
				g[j][i][k] = min(g[j][i][k - 1], s[k][j] == s[k - 1][j] ? a[k][j] : 0);
		}
	int ans = 0;
	while(f[1][1][m] < n){
		++ans;
		for(int i = 1; i <= n; ++i)
			for(int j = 1; j <= m; ++j)
				for(int k = j; k <= m; ++k){
					f[i][j][k] += f[i + f[i][j][k]][j][k];
					if(f[i][j][k]) ckmax(h[0][j][i][i + f[i][j][k] - 1], k - j + 1);
				}
		for(int j = 1; j <= m; ++j)
			for(int i = 1; i <= n; ++i)
				for(int k = i; k <= n; ++k){
					g[j][i][k] += g[j + g[j][i][k]][i][k];
					if(g[j][i][k]) ckmax(h[1][i][j][j + g[j][i][k] - 1], k - i + 1);
				}
		for(int i = 1; i <= n; ++i)
			for(int j = 1; j <= m; ++j)
				for(int k = m; k >= j; --k)
					ckmax(f[i][j][k], max(f[i][j][k + 1], h[1][i][j][k]));
		for(int j = 1; j <= m; ++j)
			for(int i = 1; i <= n; ++i)
				for(int k = n; k >= i; --k)
					ckmax(g[j][i][k], max(g[j][i][k + 1], h[0][j][i][k]));
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 311424
#include<bits/stdc++.h>
#define ull unsigned long long
#define pi acos(-1)
using namespace std;
typedef long long ll;
const ll inf = 0x3f3f3f3f;
const ll maxn = 1e7+5;
const ll mod = 1e9+7;

int main(){
	int n,cnt=0;
	string s;
	cin>>n>>s;
	for(int i=0;i<n-2;i++){
		if(s[i]=='A'&&s[i+1]=='B'&&s[i+2]=='C') cnt++;
	} 
	cout<<cnt<<'\n';
	return 0;
}


Measured memory_bytes: 3616
/*
confirm 0LL and 1LL
confirm cornercases such as 0
confirm times of cin < 10^6
*/
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll, ll>;
using Pld = pair<ld, ld>;
using Vec = vector<ll>;
using VecP = vector<P>;
using VecB = vector<bool>;
using VecC = vector<char>;
using VecD = vector<ld>;
using VecS = vector<string>;
using Graph = vector<VecP>;
template <typename T>
using Vec1 = vector<T>;
template <typename T>
using Vec2 = vector<Vec1<T> >;
#define REP(i, m, n) for(ll (i) = (m); (i) < (n); ++(i))
#define REPN(i, m, n) for(ll (i) = (m); (i) <= (n); ++(i))
#define REPR(i, m, n) for(ll (i) = (m)-1; (i) >= (n); --(i))
#define REPNR(i, m, n) for(ll (i) = (m); (i) >= (n); --(i))
#define rep(i, n) REP(i, 0, n)
#define repn(i, n) REPN(i, 1, n)
#define repr(i, n) REPR(i, n, 0)
#define repnr(i, n) REPNR(i, n, 1)
#define all(s) (s).begin(), (s).end()
#define pb push_back
#define fs first
#define sc second
template <typename T>
bool chmax(T &a, const T b){if(a < b){a = b; return true;} return false;}
template <typename T>
bool chmin(T &a, const T b){if(a > b){a = b; return true;} return false;}
template <typename T>
ll pow2(const T n){return (1LL << n);}
template <typename T>
void cosp(const T n){cout << n << ' ';}
void co(void){cout << '\n';}
template <typename T>
void co(const T n){cout << n << '\n';}
template <typename T1, typename T2>
void co(pair<T1, T2> p){cout << p.fs << ' ' << p.sc << '\n';}
template <typename T>
void co(const Vec1<T> &v){for(T i : v) cosp(i); co();}
template <typename T>
void co(initializer_list<T> v){for(T i : v) cosp(i); co();}
template <typename T>
void ce(const T n){cerr << n << endl;}
void sonic(){ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);}
void setp(const ll n){cout << fixed << setprecision(n);}
constexpr ll INF = 1e9+1;
constexpr ll LINF = 1e18+1;
constexpr ll MOD = 1e9+7;
//constexpr ll MOD = 998244353;
constexpr ld PI = acos(-1);
constexpr ld EPS = 1e-11;

int main(void){
	ll k, n;
	cin >> k >> n;
	Vec a(n);
	rep(i, n) cin >> a[i];

	ll max = 0;
	rep(i, n - 1) chmax(max, a[i + 1] - a[i]);
	chmax(max, a[0] + k - a[n - 1]);
	co(k - max);

	return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;

const long double PI = acos(-1);
const long double EPS = 0.0000000001;

int main() {
  double a, b, x;
  cin >> a >> b >> x;
  double s = x / a;
  double rad;
  if (s >= a * b - s) {
    double h = (a * b - s) * 2 / a;
    rad = atan2(h, a);

  } else {
    double w = s * 2 / b;
    rad = atan2(b, w);
  }
  double PI = acos(-1);
  double deg = rad / 2 / PI * 360;
  printf("%.10f\n", deg);
  return 0;
}


Measured memory_bytes: 512
#include<iostream>
#include<cstdio>
#include<string>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<cctype>
#include<vector>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<utility>
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int,int> ii;
typedef pair<ll,ll> lii;
typedef vector<ii> vii;
#define ms(obj, val) memset(obj, val, sizeof(obj))
#define FOR(i, c, n) for(int i=c; i<n; i++)
#define ROF(i, c, n) for(int i=c; i>n; i--)
#define ri(x) scanf("%d", &x)
#define rii(x,y) scanf("%d %d", &x,&y)
#define riii(x,y,z) scanf("%d %d %d", &x, &y, &z)
#define lri(x) scanf("%lld",&x)
#define lrii(x,y) scanf("%lld %lld",&x,&y)
#define lriii(x,y,z) scanf("%lld %lld %lld",&x,&y,&z)
#define  F first
#define  S second
#define pb push_back
void fastIO() {std::ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);}
//////////////////////////////////////////////////////////////////////////////////////

int n,x,a[105];

int main(){
	rii(n,x); FOR(i,0,n) ri(a[i]);
	sort(a,a+n); int ans=0;
	for(int i=0; i<n && x; i++){
		if(x-a[i]<0) break;
		if(i==n-1 && x-a[i]>0) break;
		ans++; x-=a[i];
	}
	printf("%d\n",ans);
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#include<functional>
using namespace std;
#define ll long long int
#define ld long double
using namespace __gnu_pbds;
typedef tree<ll,null_type,less<ll>,rb_tree_tag,
tree_order_statistics_node_update> in_set;
#define rep(n) for(ll i=0;i<(n);i++)
#define jrep(n) for(ll j=0;j<(n);j++)
#define krep(n) for(ll k=0;k<(n);k++)
#define all(a) (a).begin(), (a).end()
#define dpp(a) cout<<(a).first<<" "<<(a).second<<endl;
#define append push_back
#define mod 2000007
#define ff first
#define ss second
#define ffast ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define fast ios::sync_with_stdio(0);
ll pw(ll x,ll y,ll p=mod){ll r=1; x=x%p;while(y>0){ if(y&1)r=(r*x)%p;
y=y>>1;x=(x*x)%p;} return r; } 

void solve(ll ts){
    string s1,s2; cin>>s1>>s2; ll n1=s1.size(),n2=s2.size();
    ll mx=0;
    rep(n2) if(s1[i]!=s2[i]) mx++;
    for(ll i=0;i<n1-n2;i++){
        ll tot=0;
        for(ll j=0;j<n2;j++){
            if(s1[i+j]!=s2[j]) tot++;
        } mx=min(mx,tot);
    } cout<<mx<<endl;
}
 
int main(){
    ffast
    ll t=1;
//    cin>>t;
    rep(t) solve(i+1);
}
 
 
// *p.find_by_order(n) : nth value (0 indexed)
// p.order_of_key(7): index of 7 (0 indexed)


Measured memory_bytes: 3652
#include <iostream>
#include <cstdio>
#include <vector>
#include <string>
#include <queue>

using namespace std;
#define pii pair<int, int>
#define tii tuple<int, int, int>

int dy[4] = {-1, 0, 1, 0};
int dx[4] = { 0, 1, 0,-1};
queue<pii> que;

int main(void){
    int h, w;
    cin >> h >> w;
    vector<string> s(h);
    for (int i = 0; i < h; i++) cin >> s[i];
    vector<vector<int> > g(h, vector<int>(w, 1e9));
    
    int py, px, hy, hx;
    for (int i = 0; i < h; i++) for (int j = 0; j < w; j++) 
        if (s[i][j] == '$') que.push(make_pair(i,j)), g[i][j] = 0;
        else if (s[i][j] == '@') py = i, px = j;
        else if (s[i][j] == '%') hy = i, hx = j;
        else if (s[i][j] == '#') g[i][j] = -1;
        
    while (!que.empty()) {
        pii p = que.front(); que.pop();
        int ty = p.first, tx = p.second, node = g[ty][tx];
        for (int i = 0; i < 4; i++) {
            int ny = ty + dy[i];
            int nx = tx + dx[i];
            if (ny < 0 || ny >= h || nx < 0 || nx >= w || g[ny][nx] == -1) continue;
            if (g[ny][nx] > node+1) {
                g[ny][nx] = node+1;
                que.push(make_pair(ny,nx));
            }
        }
    }
    int sol = g[hy][hx];
    
    g[py][px] = 0;
    que.push(make_pair(py,px));
    while (!que.empty()) {
        pii p = que.front(); que.pop();
        int ty = p.first, tx = p.second, node = g[ty][tx];
        for (int i = 0; i < 4; i++) {
            int ny = ty + dy[i];
            int nx = tx + dx[i];
            if (ny < 0 || ny >= h || nx < 0 || nx >= w || g[ny][nx] == -1) continue;
            if (g[ny][nx] > node+1) {
                g[ny][nx] = node+1;
                que.push(make_pair(ny,nx));
            }
        }
    }
    if (sol == g[hy][hx]) cout << "No" << endl;
    else cout << "Yes" << endl;
}

Measured memory_bytes: 3532
#include <iostream>
#include <cstdio>
#include <fstream>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <deque>
#include <vector>
#include <queue>
#include <string>
#include <cstring>
#include <map>
#include <stack>
#include <set>
#include <sstream>
#define IOS ios_base::sync_with_stdio(0); cin.tie(0);
#define mod 1000000007
#define eps 1e-6
#define ll long long
#define INF 0x3f3f3f3f
#define MEM(x,y) memset(x,y,sizeof(x))
#define pb push_back
#define mk make_pair
#define pi pair<int, int>
#define rep(i, a, b) for (int i = (a); i <= (b); ++i)
#define per(i,a,b) for(int i=a;i>=(b);--i)
using namespace std;
int dt[][2]= {{1,0},{-1,0},{0,1},{0,-1},{0,0}};
//typedef pair<int, int> P;
//priority_queue<int, vector<int>, greater<int> > q;
int main()
{
   IOS;
   ll a,b,n;
   cin >> a >> b >> n;
   cout<<a*min(b-1,n)/b;
}


Measured memory_bytes: 3520
#include<stdio.h>
int main(void){
	int top[3];
	int a[10];
	int i;
		for(i=0;i<10;i++){
			scanf("%d",&a[i]);
		}
		for(i=0;i<10;i++){
			if(top[0]<a[i]){
				top[2]=top[1];
				top[1]=top[0];
				top[0]=a[i];
			}
			else if(top[1]<a[i]){
				top[2]=top[1];
				top[1]=a[i];
			}
			else if(top[2]<a[i]){
				top[2]=a[i];
			}
		}
		printf("%d\n",top[0]);
		printf("%d\n",top[1]);
		printf("%d\n",top[2]);
	return(0);
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
const int N=100001;
long long x[N];
int main()
{
    long long ans=0;
    long long n,A,B;
    cin>>n>>A>>B;
    for(register int i=1;i<=n;++i)
        cin>>x[i];
    for(register int i=2;i<=n;++i)
        if((x[i]-x[i-1])*A>B)
            ans+=B;
        else
            ans+=(long long)(x[i]-x[i-1])*A;
    return cout<<ans,0;
}

Measured memory_bytes: 1024
N,K = map(int,input().split())
A_s = list(map(int,input().split()))
minus = [-x for x in A_s if x < 0]
plus = [x for x in A_s if x >= 0]
minus.sort()
plus.sort()

def cnt(x):
    ans = 0
    if x < 0:
        r = 0
        x = -x
        for num in minus[::-1]:
            while r < len(plus) and plus[r] * num < x:
                r += 1
            ans += len(plus) - r
        return ans
        
    r = 0
    for num in minus[::-1]:
        if num * num <= x: ans -= 1
        while r < len(minus) and minus[r] * num <= x:
            r += 1
        ans += r
    r = 0
    for num in plus[::-1]:
        if num * num <= x: ans -= 1
        while r < len(plus) and plus[r] * num <= x:
            r += 1
        ans += r
    ans //= 2
    ans += len(minus) * len(plus)
    return ans


top = 2 * (10**18) + 2
bottom = 0

while top - bottom > 1:
    mid = (top + bottom) // 2
    if cnt(mid-10**18-1) < K:
        bottom = mid
    else:
        top = mid
print(int(top-10**18-1))

Measured memory_bytes: 119428
#include <bits/stdc++.h>
#include <unordered_set>
using namespace std;
#define ll long long
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define repeat(i,s,n) for(int (i)=s; (i)<(n); (i)++)
#define revrep(i,n) for(int (i)=(n)-1;i>=0; i--)

ll gcd(ll x,ll y) { return y ? gcd(y,x%y) : x; }

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout<<setprecision(std::numeric_limits<float>::max_digits10);
  int n;
  cin>>n;
  vector<ll> a(n);
  rep(i,n)cin>>a[i];
  ll ans=a[0];
  rep(i,n) {
    ans=gcd(ans,a[i]);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define llu unsigned long long
#define ld double
#define llu unsigned long long
#define rep(i,x,y)  for(ll i=x;i<y;++i)
#define For(i,x,y)  for(ll i=x;i<=y;++i)
#define FOr(i,x,y)  for(ll i=x;i>=y;--i)
#define pi acos(-1)
#define mk make_pair<ll,ll>
#define pa pair<ll,ll>
#define lf else if
#define min(x,y)    ((x)<(y)?(x):(y))
#define sqr(x)      ((x)*(x))
#define abs(x)      ((x)>0?(x):-(x))
#define Mul(x,y)    (x=(x)*(y)%mod)
#define Add(x,y)    (x=(x+(y))%mod)
#define E(x)        return writeln(x),0
#define p(x)        printf("~%d~\n",x)
#define pp(x,y)     printf("~~%d %d~~\n",x,y)
#define ppp(x,y,z)  printf("~~~%d %d %d~~~\n",x,y,z)
#define pppp(x,y,z,a)  printf("~~~%d %d %d %d~~~\n",x,y,z,a)
#define f_in(x)     freopen(x".in","r",stdin)
#define f_out(x)    freopen(x".out","w",stdout)
#define open(x)     f_in(x),f_out(x)
#define fi first
#define se second
typedef complex<double> E;
namespace SHENZHEBEI{
#ifdef LOCAL
    struct _{_(){freopen("cf.in","r",stdin);}}_;
#endif
#define NEG 1
    inline char gc(){   return getchar();   }
#if NEG
    inline ll read(){    ll x=0,f=1; char ch=gc();   for (;!isdigit(ch);ch=gc()) if (ch=='-') f=-1;  for (;isdigit(ch);ch=gc())  x=x*10-48+ch;   return x*f; }
    inline void write(ll x){    if (x<0) putchar('-'),x=-x;  if (x>=10)   write(x/10);    putchar(x%10+'0');  }
#else
    inline ll read(){    ll x=0; char ch=gc();   for (;!isdigit(ch);ch=gc());    for (;isdigit(ch);ch=gc())  x=x*10-48+ch;   return x;   }
    inline void write(ll x){    if (x>=10)   write(x/10);    putchar(x%10+'0');  }
#endif
    inline char readchar(){ char ch=gc();   for(;isspace(ch);ch=gc());  return ch;  }
    inline ll readstr(char *s){ char ch=gc();   int cur=0;  for(;isspace(ch);ch=gc());      for(;!isspace(ch);ch=gc())  s[cur++]=ch;    s[cur]='\0';    return cur; }
    inline void writeln(ll x){  write(x);   puts("");   }
    inline ld getreal(){    static ld lbc;  scanf("%lf",&lbc);  return lbc; }
}using namespace SHENZHEBEI;
const ll N=1000000;
void Min(ll &x,ll y){x=x<y?x:y;}
ll n,k;
int main(){
	n=read(),k=read();
	ll res=1,ans=0;
	for(;res<n;){
		++ans;res+=k-1;
	}writeln(ans);
}

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

int main() {
  ll N, A, B;
  cin >> N >> A >> B;
  ll ans = N/(A+B) * A;
  ans += min(N-(N/(A+B))*(A+B), A);
  cout << ans << endl;
}


Measured memory_bytes: 3624
#include <string>
#include <cstring>
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;

typedef vector<pair<int,int> >vpii;
char m[99][99];

char dfs(int i, int j, vpii&v){
	if(m[i][j]=='B')return 1;
	if(m[i][j]=='W')return 2;
	if(m[i][j]=='X')return 0;
	int ret=0;
	v.push_back(make_pair(i,j));
	if(find(v.begin(),v.end(),make_pair(i-1,j))==v.end())ret|=dfs(i-1,j,v);
	if(find(v.begin(),v.end(),make_pair(i+1,j))==v.end())ret|=dfs(i+1,j,v);
	if(find(v.begin(),v.end(),make_pair(i,j-1))==v.end())ret|=dfs(i,j-1,v);
	if(find(v.begin(),v.end(),make_pair(i,j+1))==v.end())ret|=dfs(i,j+1,v);
	return ret;
}

main(){
	int w,h,i,j,k,r,s;
	for(;scanf("%d%d",&w,&h),w;printf("%d %d\n",r,s)){
		for(memset(m,'X',sizeof(m)),r=s=0,i=1;i<=h;i++)scanf("%s",m[i]+1),m[i][w+1]='X';
		for(i=1;i<=h;i++)for(j=1;j<=w;j++)if(m[i][j]=='.'){
			vpii v;
			char x=dfs(i,j,v);
			for(k=0;k<v.size();k++)
				m[v[k].first][v[k].second]=x;
		}
		for(i=1;i<=h;i++)for(j=1;j<=w;j++)
			if(m[i][j]==1)r++;
			else if(m[i][j]==2)s++;
	}
}

Measured memory_bytes: 0
#include<iostream>
using namespace std;
main(){int n,p;while(cin>>n>>p&&n&&p){int num=0,p2=p,a[50]={};while(a[(num-1)%n]!=p){if(p2)p2--,a[num%n]++;else p2=a[num%n],a[num%n]=0;num++;}cout<<(num-1)%n<<endl;}}

Measured memory_bytes: 1160
using System;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;
using System.Text;
using static System.Console;
using static System.Math;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var n = ReadInt();
            var a = ReadInts();
            for (int i = 0; i < n; i++)
            {
                if (a[i] % 2 == 0)
                {
                    if (a[i] % 3 != 0 && a[i] % 5 != 0)
                    {
                        WriteLine("DENIED");
                        return;
                    }
                }
            }
            WriteLine("APPROVED");
        }
        private static string Read() { return ReadLine(); }
        private static string[] Reads() { return (Read().Split()); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }
    }
}


Measured memory_bytes: 11220
// 2014/07/18 Tazoe

#include <iostream>
using namespace std;

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

	int A[100][100];
	for(int i=0; i<n; i++){
		for(int j=0; j<m; j++){
			cin >> A[i][j];
		}
	}

	int b[100];
	for(int i=0; i<m; i++){
		cin >> b[i];
	}

	int c[100];
	for(int i=0; i<n; i++){
		c[i] = 0;

		for(int j=0; j<m; j++){
			c[i] += (A[i][j]*b[j]);
		}
	}

	for(int i=0; i<n; i++){
		cout << c[i] << endl;
	}

	return 0;
}

Measured memory_bytes: 1200
iN = int(input())
aX = [int(_) for _ in input().split()]
aXs = sorted(aX)

iMu  = iN//2
iMd  = iN//2 -1

iMuV = aXs[iMu]
iMdV = aXs[iMd]

if iMuV == iMdV:
    print("\n".join([str(iMuV)]*iN))
else:
    print("\n".join(map(str,map(lambda x: iMuV if x < iMuV else iMdV ,aX))))


Measured memory_bytes: 29808
#pragma GCC optimize("Ofast", "unroll-loops")

#include <bits/stdc++.h>

using namespace std;

#define ll long long

int depth(int i) {
	if (i == 1) return 1;
	return 1 + depth(i / 2);
}

int N;
vector<int> V, W;

void input(void) {
	cin >> N;
	V.resize(N); W.resize(N);
	for (int i = 0; i < N; ++i)
		cin >> V[i] >> W[i];
}

vector<vector<int>> dp;

void dfs(int s, vector<int>& res, int dep) {
	if (s > N) return;
	if (dep > 9) return;
	dp[s] = res;
	for (int w = 0; w <= 100000; ++w) 
		if (w >= W[s - 1])
			dp[s][w] = max(dp[s][w], res[w - W[s - 1]] + V[s - 1]);
	dfs(s * 2, dp[s], dep + 1);
	dfs(s * 2 + 1, dp[s], dep + 1);
}

void build(void) {
	dp.resize(N + 1);
	vector<int> dp(100001, 0);
	dfs(1, dp, 1);
}

vector<pair<int, int>> all_find(int st, int gl, int L) {
	vector<pair<int, int>> res(1, {0, 0});
	while (st > gl) {
		int v = V[st - 1], w = W[st - 1];
		vector<pair<int, int>> tmp = res;
		for (auto p : res) {
			if (p.first + w > L) continue;
			tmp.emplace_back(p.first + w, p.second + v);
		}
		res = tmp;
		st /= 2;
	}
	return res;
}

void solve(int x, int L) {
	if (depth(x) <= 9) {
		cout << dp[x][L] << endl;
		return;
	}
	int _x = x;
	while (depth(_x) > 9) _x /= 2;
	auto tmp = all_find(x, _x, L);
	int res = 0;
	for (auto p : tmp) 
		if (p.first <= L)
			res = max(res, p.second + dp[_x][L - p.first]);
	cout << res << endl;
}

int main(void) {
	input();
	build();
	int Q; cin >> Q;
	while (Q--) {
		int v, L; cin >> v >> L;
		solve(v, L);
	}
	return 0;
}

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

int main(){
	int a,b;
	string s;
	cin >> a >> b >> s;
	int len = s.size();
	rep(i,len){
		if(i == a){
			if(s[i] != '-'){
				cout << "No" << endl;
				return 0;
			}
		}else{
			if(s[i] != '0' && s[i] != '1' && s[i] != '2' &&s[i] != '3' &&s[i] != '4' &&s[i] != '5' &&s[i] != '6' &&s[i] != '7' &&s[i] != '8' &&s[i] != '9'){
				cout << "No" << endl;
				return 0;
			}
		}
	}
	cout << "Yes" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define modulo 1000000007
#define mod(mod_x) ((((long long)mod_x+modulo))%modulo)
#define Inf 10000000


int main(){

	int N;
	cin>>N;
	
	int a = 1;
	while(a*2<=N)a*=2;
	
	cout<<a<<endl;
	
    return 0;
}



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

typedef long long ll;
typedef unsigned long long ull;

#define SIZE_OF_ARRAY(array) (sizeof(array)/sizeof(array[0]))
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define AA(i) cout<<i<<endl;
#define AS(i) cout<<i<<" ";

const int INF = 1001001001;

using namespace std;


int main() {

    ll s, a, b;
    cin >> s >> a >> b;

    ll ans = 0;
    ans += (s / (a + b)) * a;
    
    ll aaa = s % (a + b);
    if (aaa > a) aaa = a;
    ans += aaa;

    AA(ans);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long int ll;
typedef long double ld;
using namespace std;
const long long int INF = 1e18;
const long long int MOD = 1e9+7;

typedef pair<ll, ll> pairs;
typedef vector<pairs> p;

struct edge{
    ll to, cost;
};


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

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

ll keta(ll N){
    int tmp{};
    while( N > 0 ){
        tmp += ( N % 10 );
        N /= 10;
    }
    N = tmp;
    return N;
}

// 素数
vector<bool> IsPrime;
void sieve(size_t max){
    if(max+1 > IsPrime.size()){
        IsPrime.resize(max+1,true);
    } 
    IsPrime[0] = false;
    IsPrime[1] = false;

    for(size_t i=2; i*i<=max; ++i){
        if(IsPrime[i]){
            for(size_t j=2; i*j<=max; ++j){
                IsPrime[i*j] = false;
            }
        }
    }
}

// べき乗の余り
ll modpow(ll a, ll n){
    ll res = 1;
    while(n){
        if(n & 1){
            res = res * a % MOD;
        }
        a = a * a % MOD;
        n = n >> 1;
    }
    return res;
}

// コンビネーション
ll MAXN = 2e5+10;
vector<ll> inv(MAXN);
ll nCk(ll n, ll k) {
	ll res = 1;
	for(ll i = 1; i <= k; i++) {
		res = res*(n-i+1) % MOD;
	}
 
	for(ll i = 1; i <= k; i++) {
		res = res*inv[i] % MOD;
	}
	return res;
}

// 回文
bool kai(string S){
    bool flag = true;
    for(ll i=0;i<S.size()/2;++i){
        if(S[i] != S[S.size()-i-1]){
            flag = false;
            break;
        }
    }
    return flag;
}
// ---------------------------------------------

int main(){
    string s;
    cin>>s;
    ll sum = 0;
    for(ll i=0;i<s.size();++i){
        sum += s[i]-'0';
        sum %= 9;
    }
    if(sum % 9 == 0){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }
}

Measured memory_bytes: 5224
"use strict";

function main(arg) {
    arg = arg.split("\n")[0].split(" ").map(n=>parseInt(n));
    const N = arg[0];
    const A = arg[1];
    const B = arg[2];
    
    console.log(A * N < B ? A * N : B);
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 11468
#include <iostream>
#include <vector>
#include <map> 
#include <algorithm>
#include <cstring>
#define ll long long 
using namespace std; 

void solve(){
  int N, W; 
  cin >> N >> W; 
  ll ws[N], vals[N]; 
  for(int i=0; i<N; i++){
    cin >> ws[i] >> vals[i]; 
  }
  ll dp[N][W+1]; 
  for(int i=0; i<=W ; i++){
    if(ws[N-1] > i){
      dp[N-1][i] = 0; 
    }else{
      dp[N-1][i] = vals[N-1]; 
    }
  } 

  for(int i=N-2; i>=0; i--){
    for(int j=0 ; j<=W; j++){
      if(ws[i] > j){
        dp[i][j] = dp[i+1][j]; 
      }
      else{
        dp[i][j] = max(vals[i] + dp[i+1][j-ws[i]], dp[i+1][j]); 
      }
    }   
  }
  // for(int i=0; i<N; i++){
  //   for(int j=0; j<=W; j++){
  //     cout << dp[i][j] << " "; 
  //   }
  //   cout << "\n"; 
  // }
  cout << dp[0][W] << "\n"; 
}

int main(){
  int t=1; 
  // cin>>t; 
  while(t--){
    solve(); 
  }
 return 0;
}

Measured memory_bytes: 81220
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define inf 1001001001
#define mod 1000000007
#define mod2 998244353
#define pi acos(-1)
#define all(x) (x).begin(),(x).end()
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; }

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  cout << setprecision(15) << fixed;

  int N, K;
  cin >> N >> K;
  vector<int> p(N);
  rep(i, N) {
    cin >> p[i];
  }
  sort(all(p));
  int ans = 0;
  for (int i = 0; i < K; i++) {
    ans += p[i];
  }
  cout << ans << endl;
}


Measured memory_bytes: 3696
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<unordered_map>
#include<set>
#include<unordered_set>
#include<numeric>
#include<algorithm>
#include<tuple>
#include<cmath>

typedef unsigned long long ull;
typedef long long ll;

ll DENOM = 1000000000LL + 7LL;
using namespace std;

int main(){
    int x, n;
    cin >> x >> n;
    vector<int> p(102,1);
    for (int i=0; i<n; ++i){
        int x;
        cin >> x;
        p[x] = 0;
    }
    int s = 999;
    int j = 0;
    for (int i=0; i<102; ++i){
        if (p[i] ==0) continue;
        int st = abs(x - i);
        if(st >= s) break;
        j = i;
        s = st;
    }
    cout << j << endl;
    return 0;
}

Measured memory_bytes: 3160
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
int main()
{
  string S;
  cin >> S;
  int a = 0, b = 0;
  REP(i, S.size()) {
    if (S[i] == '0') {
      a++;
    } else {
      b++;
    }
  }
  cout << min(a, b)*2 << endl;

  
  return 0;
}

Measured memory_bytes: 512
#include<iostream>
#include<map>
using namespace std;
void swap(int &a,int &b){
  int tmp=a;
  a=b;
  b=tmp;
}
void sort(int &a,int &b,int &c){
  if(a>b) swap(a,b);
  if(b>c) swap(b,c);
  if(a>b) swap(a,b);
}
int main(){
  int N;
  cin>>N;
  int p[N][3];
  for(int i=0;i<N;i++){
    for(int j=0;j<3;j++){
      cin>>p[i][j];
    }
  }
  for(int i=0;i<N;i++){
    sort(p[i][0],p[i][1],p[i][2]);
  }
  map<int,bool> memo;
  int cnt=0;
  for(int i=0;i<N;i++){
    int k;
    k=(p[i][0]-1)*1000000+(p[i][1]-1)*1000+(p[i][2]-1);
    if(memo.find(k)!=memo.end())  cnt++;else memo[k]=true;
  }
  cout<<cnt<<endl;
  return 0;
}



Measured memory_bytes: 3160
fun main(args: Array<String>) {
    val input = readLine()!!.trim().split(" ").filterNot(String::isBlank).map(String::toInt)
    val r = input[0]
    val d = input[1]
    val xi = IntArray(11) {
        0
    }
    xi[0] = input[2]
    for (i in 0 until xi.lastIndex) {
        xi[i + 1] = r * xi[i] - d
    }
    println(xi.drop(1).joinToString("\n"))
}

Measured memory_bytes: 35980
#include <bits/stdc++.h>
using namespace std;
int gcd(int n, int m) {
    if(n < m) {
        return gcd(m, n);
    }
    int a;
    while((a = n % m)) {
        n = m;
        m = a;
    }
    return m;
}
 
int main() {
    int n;
    cin >> n;
    int sum = 0;
    for(int i = 1; i <= n; i++) {
        for(int j = 1; j <= n; j++) {
            for(int k = 1; k <= n; k++) {
                sum += gcd(i, gcd(j, k));
            }
        }
    }
 
    cout << sum <<endl;
}

Measured memory_bytes: 3632