akhauriyash/Code-Regression huggingface dataset:
#include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
#include<tuple>
#include<string>
#include<chrono>
#include<functional>
#include<iterator>
#include<random>
#include<unordered_set>
#include<array>
#include<map>
#include<iomanip>
#include<assert.h>
#include<bitset>
#include<stack>
#include<memory>
using namespace std;
using namespace std::chrono;
typedef long long int llint;
typedef double lldo;
#define mp make_pair
#define mt make_tuple
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define fir first
#define sec second
#define res resize
#define ins insert
#define era erase

/*
cout<<fixed<<setprecision(20);
cin.tie(0);
ios::sync_with_stdio(false);
*/
const llint mod=1000000007;
const llint big=2.19e15+1;
const long double pai=3.141592653589793238462643383279502884197;
const long double eps=1e-15;
template <class T,class U>bool mineq(T& a,U b){if(a>b){a=b;return true;}return false;}
template <class T,class U>bool maxeq(T& a,U b){if(a<b){a=b;return true;}return false;}
llint gcd(llint a,llint b){if(a%b==0){return b;}else return gcd(b,a%b);}
llint lcm(llint a,llint b){if(a==0){return b;}return a/gcd(a,b)*b;}
template<class T> void SO(T& ve){sort(ve.begin(),ve.end());}
template<class T> void REV(T& ve){reverse(ve.begin(),ve.end());}
template<class T>llint LBI(vector<T>&ar,T in){return lower_bound(ar.begin(),ar.end(),in)-ar.begin();}
template<class T>llint UBI(vector<T>&ar,T in){return upper_bound(ar.begin(),ar.end(),in)-ar.begin();}
int main(void){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout<<fixed<<setprecision(20);
	int i,j,n,K;cin>>n>>K;
	vector<llint>dp(K+1);
	vector<llint>ep(K+1);
	dp[0]=1;
	while(n--){
		int a;cin>>a;
		llint g=0;
		
		for(i=0;i<=K;i++){
			g+=dp[i];
			if(i-a-1>=0){g-=dp[i-a-1];g+=mod;}
			g%=mod;
			ep[i]=g;
		}
		swap(dp,ep);
	}
	cout<<dp[K]<<endl;
	return 0;
}


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

int main(){
	int n,m;
	cin >> n >> m;
	vector<int>a(n);
	int ans = 0;
	int sum = 0;
	rep(i,n){
		cin >> a[i];
		sum += a[i];
	}
	rep(i,n){
		if(a[i] >= sum/(4.0*m)){
			ans++;
		}
	}

	if(ans >= m)cout << "Yes\n";
	else cout << "No\n";



	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define r for(int i=0;i<n;i++)
using namespace std;
int main(){
    int a[101],n,ans=0;
    cin>>n;
    r cin>>a[i];
    sort(a,a+n,greater<int>());
    r ans+=(i%2?-a[i]:a[i]);
    cout<<ans;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define ALL(c) (c).begin(),(c).end()
using namespace std;
using ll = long long;
using P = pair<int,int>;
#define chmax(x,y) x = max(x,y)
#define chmin(x,y) x = min(x,y)

const int INF = 1e9 + 10;

int N, M, Q;
int a[55], b[55], c[55], d[55];
int res = 0;
vector<int> v(10);

void dfs(int cur = 0, int last = 1) {
    if (cur == N) {
        int tmp = 0;
        rep(i,Q) if ( v[b[i]] - v[a[i]] == c[i] ) tmp += d[i];
        chmax(res, tmp);
        return;
    }
    for (int i = last; i <= M; ++i) {
        v[cur] = i;
        dfs(cur+1, i);
    }
}
int main() {
    cin >> N >> M >> Q;
    rep(i,Q) {
        cin >> a[i] >> b[i] >> c[i] >> d[i];
        a[i]--, b[i]--;
    }
    dfs();
    cout << res << endl;
}


Measured memory_bytes: 3580
#include<iostream>
#include<string>
#include<vector>
#include<iomanip>
#include<algorithm>
#include<queue>
#include<stack>
#include<list>
#include<map>
#include<deque>
#include<math.h>
using namespace std;
#define ll long long
int main(){
    ll N,A;
    cin >> N;
    ll i;
    ll ans=0;
    ll t=0;
    for(i=0;i<N;i++){
        cin >> A;
        ans+=(A+t)/2;
        if(A!=0)t=(A+t)%2;else t=0;
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
#define LL long long
#define Max 100005
#define Mod 1e9+7
const LL mod=1e9+7;
const LL inf=0x3f3f3f3f;
using namespace std;
int main()
{
	int a,b,c;
	scanf("%d/%d/%d",&a,&b,&c);
	if(a<=2019 && b<=4)
	{
		if(b==4 && c>30)
			printf("TBD\n");
		else
			printf("Heisei\n");
	}
	else
		printf("TBD\n");
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <queue>
#include <map>
#include <iostream>
#include <algorithm>
using namespace std;
int n;
int ans;

int main() {
	cin >> n;
	for(int i = 1; i <= n; i += 2) {
		int cnt = 0;
		for(int j = 1; j <= i; j++) {
			if(i % j == 0 && i / j != j) cnt++;
		}
		if(cnt == 8) ans++;
	}
	cout << ans << endl;
}

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

int main() {
  int N,T,c1,c2,t;
  c2 = 1001;
  cin >> N >> T;
  
  for (int i = 0; i < N ;i++){
    cin >> c1 >> t;
    if (t <= T && c1 < c2){
      c2 = c1;  
    }    
  }
  if (c2 == 1001){
    cout << "TLE" << endl;
  }
  else {
    cout << c2 <<endl;
  }
}

Measured memory_bytes: 256
n = gets.to_i
a = gets.split.map(&:to_i)
q = gets.to_i
hash = Hash.new(0)
a.each do |i|
  hash[i] += 1
end
sum = a.sum
res = []
q.times do
  b,c = gets.split.map(&:to_i)
  tmp = hash[b]
  hash[b] = 0
  hash[c] += tmp
  sum -= b * tmp
  sum += c * tmp
  res << sum
end
puts res



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

#define int long long
#define vi vector <int>
#define endl "\n"
#define vvi vector <vector<int> >
#define vii vector <pair<int,int> >
#define rep(i,a,b) for (int i=a;i<b;i++)
#define repD(i,a,b) for (int i=a;i>=b;i--)
#define speed ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define init(i,k) memset(i,k,sizeof i)
#define pb push_back
#define pii pair <int,int>
#define ff first
#define ss second
#define all(a) a.begin(),a.end()
const int N=1e2+5 , MOD=1e9+7;

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


void solve()
{
    int n,w;
    cin >> n >> w;
    vi wei(n+1), v(n+1);
    int sumv=0;
    rep(i,1,n+1)
    {
    	cin >> wei[i] >> v[i];
    	sumv += v[i];
    }

    vvi dp(n+1,vi(sumv+1,-1));

    rep(i,0,n+1)
    dp[i][0] = 0;

    rep(i,1,n+1)
    {
    	rep(j,1,sumv+1)
    	{
    		if(j-v[i]>=0)
    		{
    			if(dp[i-1][j-v[i]]!=-1 && dp[i-1][j] !=-1)
    				dp[i][j] = min(dp[i-1][j], dp[i-1][j-v[i]]+wei[i]);
    			else if(dp[i-1][j-v[i]]==-1)
    				dp[i][j] = dp[i-1][j];
    			else if(dp[i-1][j]==-1 && dp[i-1][j-v[i]]!=-1)
    				dp[i][j] = dp[i-1][j-v[i]]+wei[i];
    		}
    		else
    			dp[i][j] = dp[i-1][j];
    	}
    }

    int ans=0;
    rep(j,0,sumv+1)
   	{
   		if(dp[n][j]>0 && dp[n][j]<=w)
   			ans = max(ans,j);
   	}
   	cout << ans << endl;
}

signed main()
{
    speed;
    
 //    int t; cin >> t;
 //    rep(tt,1,t+1)
 //    {
	// cout <<"Case #"<<tt<<": ";
	solve();
 //    }
    return 0;
}

Measured memory_bytes: 80256
#include<iostream>
#include<vector>
#include<algorithm>
#include<map>
#include<cstring>
#include<math.h>
#include<bitset>
#include<queue>
#include<set>
#include<iomanip>
#include<math.h>
#include<assert.h>
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr long long int INFLL = 1LL << 60;
constexpr int INF = 1000000007;
const double INFD = 1e100;
const int mod = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

int main(){
  int A,B;
  cin >> A >> B;
  for(int i=1; i<=3; i++){
    if(A != i && B != i){
      cout << i << endl;
      return 0;
    }
  }

  return 0;
}


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

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

    int c[m];
    for(int i=0;i<m;i++)    cin >> c[i];

    int coin[m][n+1];
    for(int i=0;i<m;i++)   coin[i][0] = 0;
    for(int i=1;i<=n;i++)   coin[0][i] = coin[0][i-1]+1;

    for(int i=1;i<m;i++){
        for(int j=0;j<=n;j++){
            if(j<c[i]){
                coin[i][j] = coin[i-1][j];
            }else{
                coin[i][j] = min(coin[i-1][j],coin[i][j-c[i]]+1);
            }
        }
    }

    cout << coin[m-1][n] << endl;

    return 0;
}


Measured memory_bytes: 7028
#include <iostream>

using namespace std;
typedef long long  ll;
#define rep(i,s,n)for(ll i = s;i<n;i++)

int main() {
	int a, b, c; cin >> a >> b >> c;
	int x;
	if (a == b && b == c && c == a) {
		x = 1;
	}
	else if (a != b && b != c && c != a) {
		x = 3;
	}
	else {
		x = 2;
	}
	cout << x << endl;

	return 0;
}

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

using namespace std;

typedef long long ll;
typedef vector<ll> vl;

ll n;
string s;
ll dic[52];
ll undic[128];


int main(){
  for(ll i = 0;i < 26;i++){
    dic[i] = ('a'+i);
    undic[('a'+i)] = i;
  }
  for(ll i = 0;i < 26;i++){
    dic[i+26] = ('A'+i);
    undic[('A'+i)] = i+26;
  }
  while(cin >> n){
    if(n == 0) return 0;
    vl k = vl(n);
    for(ll i = 0;i < n;i++) cin >> k[i];
    cin >> s;
    string ans;
    for(ll i = 0;i < s.size();i++){
      ll idx = undic[s[i]];
      idx = (idx-k[i%k.size()]+52)%52;
      char c = dic[idx];
      ans.push_back(c);
    }
    cout << ans << endl;

  }
}



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

class Restaurant{
public:
	int n;
	string name;
	int p; 
	Restaurant(){}
	Restaurant(int n, string name, int p){
		this->n=n;
		this->name=name;
		this->p=p;
	}	
};

int main(){
	/*input*/
	int n;	cin >> n;
	Restaurant* res = new Restaurant[n];
	for(int i = 0; i < n; i++){
		string name;
		int p;
		cin >> name >> p;
		res[i] = Restaurant(i + 1, name, p);
	}
	/*calculation*/
	for(int i = 0; i < n; i++){
		for(int j = n - 1; j > i;j--){
			if(res[j].name<res[j - 1].name){
				Restaurant temp = res[j - 1];
				res[j - 1] = res[j];
				res[j] = temp;
			}else if(res[j].name==res[j - 1].name){
				if(res[j].p>res[j - 1].p){ 
						Restaurant temp = res[j - 1];
						res[j - 1] = res[j];
						res[j] = temp;
				}
			}
		} 
	}

	/*output*/
	for(int i = 0; i < n; i++){
		cout << res[i].n <<  endl;
	}
	delete[] res;
}


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

int main() {
	string a;

	cin >> a;

	if (a[a.size() - 1] == 's') {
		a += 'e';
		a += 's';
	} else {
		a += 's';
	}

	cout << a << endl;

	return 0;
}

Measured memory_bytes: 3624
//#define __USE_MINGW_ANSI_STDIO 0
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
#define int ll
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef pair<int, int> PII;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define IN(a, b, x) (a<=x&&x<b)
#define MP make_pair
#define PB push_back
#ifdef int
const ll INF = (1LL<<60);
#else
const int INF = (1LL<<30);
#endif
const double PI = 3.14159265359;
const double EPS = 1e-12;
const int MOD = 1000000007;

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }

int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};

int par[105], rnk[105];

void init(int n) { REP(i, n) par[i] = i, rnk[i] = 0; }

int find(int x) {
  if(par[x] == x) return x;
  return par[x] = find(par[x]);
}

void unite(int x, int y) {
  x = find(x), y = find(y);
  if(x == y) return;
  if(rnk[x] < rnk[y]) par[x] = y;
  else {
    par[y] = x;
    if(rnk[x] == rnk[y]) rnk[x]++;
  }
}

bool same(int x, int y) { return find(x) == find(y); }

int a[10000], b[10000], w[10000];
VI e[100010];
signed main(void)
{
  while(true) {
    int n, m;
    cin >> n >> m;
    if(!n) break;
    REP(i, m) {
      cin >> a[i] >> b[i] >> w[i];
      a[i]--, b[i]--;
      e[i] = {w[i], a[i], b[i]};
    }
    sort(e, e+m);

    int ret = INF;
    REP(i, m) {
      // e[i]???????°??????????????????§??????????°???¨?????¨????±???????
      init(n);
      unite(e[i][1], e[i][2]);
      int res = e[i][0];
      FOR(j, i+1, m) {
        if(!same(e[j][1], e[j][2])) {
          unite(e[j][1], e[j][2]);
          // cout << e[j][1] << "," << e[j][2] << endl;
          res = e[j][0];
        }
      }
      bool flag = true;
      REP(j, n-1) if(!same(j, j+1)) flag = false;
      if(flag) chmin(ret, res-e[i][0]);
      // cout << i << " " << e[i][0] << " " << res << " " << ret << endl;
    }
    if(ret == INF) cout << -1 << endl;
    else cout << ret << endl;
  }

  return 0;
}

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

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

int N,bit[110];

int add(int k,int x)
{
    for(;k<=N;k+=k&-k) bit[k]+=x;
}
int getSum(int k)
{
    int ret=0;
    for(;k>0;k-=k&-k) ret+=bit[k];
    return ret;
}

signed main()
{
    cin>>N;
    vector<int> a(N);
    REP(i,N){
        cin>>a[i];
    }
    
    vector<int> b,c; b=c=a;
    sort(ALL(b));
    b.erase(unique(ALL(b)),b.end());
    REP(i,N){
        c[i]=lower_bound(ALL(b),c[i])-b.begin()+1;
    }

    int ans=0;
    REP(i,N){
        ans+=i-getSum(c[i]);
        add(c[i],1);
    }

    sort(ALL(a));
    REP(i,N){
        if(i) cout<<' ';
        cout<<a[i];
    }
    cout<<endl;
    cout<<ans<<endl;

}



Measured memory_bytes: 3152
#include<stdio.h>
#include<stdlib.h>
int main ()
{
  int A,B,C,D;
  scanf("%d",&A);
  scanf("%d",&B);
  scanf("%d",&C);
  D=C-A+B;
  if(D<0)
  {
    D=0;
  }
  printf("%d",D);
}


Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <map>
#include <deque>
#include <string.h>
using namespace std;

#define REP(i,n) for(int i = 0; i < n; i++)
#define ALL(v) v.begin(),v.end()
typedef long long ll;
typedef pair<int,int> pi;
typedef pair<ll,ll> pll;
typedef pair<string,string> pss;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pi> vpi;
typedef vector<ll> vll;
typedef vector<vll> vvll;

double EPS = 1e-9;
int INFi = 1000000005;
long long INFll = 1000000000000000005ll;
double PI = acos(-1);
int dirx[8] = {-1,0,0,1,-1,-1,1,1};
int diry[8] = {0,1,-1,0,-1,1,-1,1};
ll MOD = 1000000007;

ll n, x;

ll ans;
ll dfs(ll a, ll b) {
  if (a % b == 0) return ((a / b) * 2 - 1) * b;
  return dfs(b, a % b) + (a / b) * 2 * b;
}

int main(){
  cin >> n >> x;
  if(n - x > x) cout << n + dfs(n - x, x) << endl;
  else cout << n + dfs(x, n - x) << endl;

  return 0;
}


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

fn main() {
    let mut s = String::new();
    stdin().read_line(&mut s).ok();
    let n: usize = s.trim().parse().unwrap();
    let mut s = String::new();
    stdin().read_line(&mut s).ok();
    let a: Vec<i64> = s.split_whitespace().map(|e| e.parse().unwrap()).collect();
    let ave = (a.iter().sum::<i64>() as f64 / a.len() as f64 + 0.5).floor() as i64;

    let mut ans = 0;

    for &e in &a {
        ans += (ave - e).pow(2);
    }

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


Measured memory_bytes: 4352
package main

import "fmt"

func main() {
	var n, k, g, m, a int
	fmt.Scan(&n, &k)

	for i := 0; i < n; i++ {
		fmt.Scan(&a)
		if i == 0 {
			g = a
			m = a
		}
		g = gcd(g, a)
		m = max(m, a)
	}
	if k%g == 0 && k <= m {
		fmt.Println("POSSIBLE")
	} else {
		fmt.Println("IMPOSSIBLE")
	}
}

func gcd(x, y int) int {
	for y != 0 {
		x %= y
		x, y = y, x
	}
	if x < 0 {
		x *= -1
	}
	return x
}

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


Measured memory_bytes: 5504
#include <iostream>
#include <string>
#include <cstring>
#include <algorithm>
#include <functional>
#include <cmath>
#include <queue>
#include <vector>
#include <climits>
using namespace std;

int main()
{
	unsigned long long X, Y, Z, K;
	cin >> X >> Y >> Z >> K;

	vector<unsigned long long> A(X);
	vector<unsigned long long> B(Y);
	vector<unsigned long long> C(Z);

	for (auto i = 0; i < X; ++i)
	{
		cin >> A[i];
	}

	for (auto i = 0; i < Y; ++i)
	{
		cin >> B[i];
	}

	for (auto i = 0; i < Z; ++i)
	{
		cin >> C[i];
	}

	vector<unsigned long long> sum;
	for (auto i = 0; i < X; ++i)
	{
		for (auto j = 0; j < Y; ++j)
		{
			sum.push_back(A[i] + B[j]);
		}
	}
	sort(sum.begin(), sum.end(), greater<unsigned long long>());

	vector<unsigned long long> result;
	for (auto i = 0; i < Z; ++i)
	{
		for (auto j = 0; j < K && j < sum.size(); ++j)
		{
			result.push_back(C[i] + sum[j]);
		}
	}
	sort(result.begin(), result.end(), greater<unsigned long long>());

	for (auto i = 0; i < K; ++i)
	{
		cout << result[i] << endl;
	}

	return 0;
}

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

int main() {
    int N;
    cin >> N;
    vector<int> h(N);
    for (int i = 0; i < N; i++) {
        cin >> h[i];
    }
    for (int i = N - 1; i >= 1; i--) {
        if (h[i] < h[i - 1] - 1) {
            cout << "No" << endl;
            return 0;
        } else if (h[i] == h[i - 1] - 1) {
            h[i - 1]--;
        }
    }
    cout << "Yes" << endl;
}

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

bool check(string& str)
{
	for (int i = 1; i < str.size(); i++){
		if (str[i] != str[0]) return false;
	}
	return true;
}

int main()
{
	string str;
	while (cin >> str, str != "0"){
		queue<pair<string, int> > que;
		que.push({str, 0});
		set<string> done;
		int res = -1;
		while (!que.empty()){
			pair<string, int> p = que.front(); que.pop();
			//cout << p.first << endl;
			if (check(p.first)){
				res = p.second;
				break;
			}
			if (done.count(p.first)) continue;
			done.insert(p.first);
			
			for (int i = 1; i < p.first.size(); i++){
				if (p.first[i] != p.first[i - 1]){
					int cnt[256] = {0};
					cnt[p.first[i]]++;
					cnt[p.first[i - 1]]++;
					
					string tmp = p.first;
					if (!cnt['r']){
						tmp[i] = tmp[i - 1] = 'r';
					}
					else if (!cnt['g']){
						tmp[i] = tmp[i - 1] = 'g';
					}
					else {
						tmp[i] = tmp[i - 1] = 'b';
					}
					
					que.push({tmp, p.second + 1});
				}
			}
		}
		if (res == -1) puts("NA");
		else printf("%d\n", res);
	}
	
	return 0;
}

Measured memory_bytes: 2940
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long k = sc.nextLong();
        int ans = -1;
        long bd = 1 % k;
        long pred = 7 % k;
        if(pred != 0){
            for (int i = 2; i < 10000000; i++) {
                bd = bd * 10 % k;
                pred = (pred + bd*7)%k;
                if(pred == 0){
                    ans = i;
                    break;
                }
            }
        }else{
            ans = 1;
        }
        System.out.println(ans);
        sc.close();

    }

}


Measured memory_bytes: 35820
#include <stdio.h>
#include <stdlib.h>

void selectionSort(int*, int);

int main() {
  int i, numberOfArray;
  int* sortArray;

  scanf("%d", &numberOfArray);
  sortArray = malloc(sizeof(int) * numberOfArray);
  for(i=0; i<numberOfArray; i++) {
    scanf("%d", sortArray+i);
  }
  selectionSort(sortArray, numberOfArray);
  return 0;
}

void selectionSort(int* sortArray, int numberOfArray) {
  int i,j,minj,storageNumber,count;

  for(i=0; i<numberOfArray; i++) {
    minj= i;
    for(j=i; j<numberOfArray; j++) {
      if( *(sortArray+j)< *(sortArray+minj) ) {
        minj= j;
      }
    }
    if( *(sortArray+i)!= *(sortArray+minj) ) {
      count++;
      storageNumber= *(sortArray+i);
      *(sortArray+i)= *(sortArray+minj);
      *(sortArray+minj)= storageNumber;
    }
  }

  for(i=0; i<numberOfArray; i++) {
    printf("%d", *(sortArray+i));
    if( i!= numberOfArray-1 ) {
      printf(" ");
    }
  }
  printf("\n");
  printf("%d\n", count);
}

Measured memory_bytes: 604
import sys
input = sys.stdin.readline
import numpy as np
def print_ans(N, M, C, br, ar):
    """Test Case
    >>> print_ans(2, 3, -10, [1, 2, 3], [[3, 2, 1], [1, 2, 2]])
    1
    >>> print_ans(5, 2, -4, [-2, 5], [[100, 41], [100, 40], [-3, 0], [-6, -2], [18, -13]])
    2
    >>> print_ans(3, 3, 0, [100, -100, 0], [[0, 100, 100], [100, 100, 100], [-100, 100, 100]])
    0
    """
    br = np.array(br)
    ans = 0
    for a in ar:
        tmp = np.dot(np.array(a), br)
        if tmp + C > 0:
            ans+= 1
    print(ans)

if __name__ == '__main__':
    N, M, C = map(int, input().rstrip().split())
    br = list(map(int, input().rstrip().split()))
    ar = [list(map(int, input().rstrip().split())) for _ in range(N)]
    print_ans(N, M, C, br, ar)


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

// 総数を1000000007（素数）で割った余り
const long long mod = 1e9 + 7;

using ll = long long;
using pii  = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

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

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)

ull gcd(ull a, ull b) { return b ? gcd(b, a % b) : a; }
ull lcm(ull a, ull b) { return a / gcd(a, b) * b; }

int main(){
    int a, b, k;
    cin >> a >> b >> k;
    int ans, count = 0;
    rep1r(i, a) {
        if (a%i==0&&b%i==0) ++count;
        if (count==k) {
            ans = i;
            break;
        }
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    string a,b,c;
    cin >>a>>b;
    c=a+b;
    int num = 0;
    for(int i = 0; i < c.size(); i++)
    {
        num *= 10;
        num += c[i] - '0';
    }
    for(int i=0;i<5000;i++){
        if(i*i==num){cout<<"Yes"<<endl;return 0;}
    }
    cout<<"No"<<endl;
}


Measured memory_bytes: 256
#include <set>
    #include <map>
    #include <list>
    #include <queue>
    #include <stack>
    #include <cmath>
    #include <ctime>
    #include <cstdio>
    #include <vector>
    #include <string>
    #include <bitset>
    #include <cctype>
    #include <cstdlib>
    #include <cstring>
    #include <utility>
    #include <numeric>
    #include <complex>
    #include <sstream>
    #include <fstream>
    #include <iomanip>
    #include <cassert>
    #include <iostream>
    #include <iterator>
    #include <algorithm>
    using namespace std;
    typedef long long ll;
    typedef vector<int> vint;
    typedef pair<int, int> pint;
    #define rep(i, n) REP(i, 0, n)
    #define all(v) v.begin(), v.end()
    #define REP(i, x, n) for(int i = x; i < n; i++)
    #define INF 2e9
signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int a,b,c,d,x,flag=0,count=0;
  string s,s2;
  s="YAKI";
  cin>>s2;
  a=s2.size();
  rep(i,4){
    if(s2[i]!=s[i]){
      flag=1;
      break;
    }
  }
  if(flag==0 && a>=4){
    cout<<"Yes"<<'\n';
  }
  else{
    cout<<"No"<<'\n';
  }
  return(0);
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <algorithm>
const int mod=1e9+7;
using LL=long long;
using std::cout;using std::endl;using std::cin;
using std::vector;using std::string;using std::set;using std::multiset;
using std::pair;using std::map;
using std::min;using std::max;
using std::make_pair;
std::ostream& operator<<(std::ostream& os,std::map<int,int>& obj){for(std::map<int,int>::iterator itr=obj.begin();itr!=obj.end();itr++){os<<itr->first<<"^"<<itr->second<<" ";}return os;}
std::ostream& operator<<(std::ostream& os,std::vector<std::map<int,int>>& obj){for(auto itr=obj.begin();itr!=obj.end();itr++){os<<*itr<<std::endl;}return os;}
std::ostream& operator<<(std::ostream& os,std::vector<int>& obj){for(auto itr=obj.begin();itr!=obj.end();itr++){os<<*itr<<endl;}return os;}

namespace ndifix{
template<class T>void sort(T &v){std::sort(v.begin(),v.end());}
}

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

Measured memory_bytes: 256
/**
 *    author  : 𝒌𝒚𝒐𝒎𝒖𝒌𝒚𝒐𝒎𝒖𝒑𝒖𝒓𝒊𝒏
 *    created : 2019-12-08 20:32:37
**/

#include <iostream>
#include <deque>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <complex>
#include <numeric>
#include <bitset>
#include <cassert>
#include <cctype>
#include <functional>
#include <iomanip>
#include <random>
#include <utility>

using namespace std;

using int64 = long long;
#define debug(_) cerr << #_ << ": " << (_) << '\n'
template<class T> ostream& operator<<(ostream& os, vector<T>& _) { os << '{'; for (T& x : _) { os << x; if (&x != &_.back()) os << ','; } os << '}'; return os; }
template<class T, class U> ostream& operator<<(ostream& os, pair<T, U>& p) { return os << '{' << p.first << " " << p.second << '}'; }

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

  string s; cin >> s;
  int n = s.size();
  int cnt = 0;
  for (int i = 0; i < n / 2; ++i) {
    cnt += s[i] != s[n - 1 - i];
  }
  cout << cnt << endl;

  return 0;
}

Measured memory_bytes: 256
import sys

import math


class Solution(object):
    def __init__(self):
        self.N, self.A, self.B = map(int, sys.stdin.readline().split(' '))
        self.h = []
        for _ in range(self.N):
            self.h.append(int(sys.stdin.readline()))
        self.extra_damage = self.A - self.B

    def solve(self):
        max_h = max(self.h)
        at_most = int(max_h / self.B) + 1
        at_least = int(max_h / self.A) + 1
        result = self.binary_search_lowest_kaisu(at_least, at_most)
        print(result)

    def binary_search_lowest_kaisu(self, low, high):
        if low == high:
            return low
        mid = low + (high - low) // 2
        if self.enough(mid):
            return self.binary_search_lowest_kaisu(low, mid)
        else:
            return self.binary_search_lowest_kaisu(mid + 1, high)

    def enough(self, kaisu):
        hps_remain = []
        for x in self.h:
            hp_remain = x - kaisu * self.B
            if hp_remain > 0:
                hps_remain.append(hp_remain)
        counter = 0
        for hp_remain in hps_remain:
            counter += math.ceil(hp_remain / self.extra_damage)
            if counter > kaisu:
                return False
        return True

Solution().solve()


Measured memory_bytes: 11052
a = int(input())
b = list(map(int, input().split()))
c = [0] * a
d = 0
e = []
for i in range(a, 0, -1):
    d = 0
    for j in range(i, a+1, i):
        d += c[j-1]
    if d % 2 != b[i-1]:
        c[i-1] = 1
        d += 1
        e.append(i)
print(d)
if d == 1:
    print(e[0])
elif d > 1:
    print(" ".join(map(str, e)))


Measured memory_bytes: 19852
var
	a,b,c:longint;
    s:string;
begin
	read(s);
	val(s[1]+s[2]+s[3]+s[4],a);
	val(s[6]+s[7],b);
	val(s[9]+s[10],c);
    a:=a*10000+b*100+c;
    if a<=20190430 then writeln('Heisei')
    else writeln('TBD');
end.

Measured memory_bytes: 128
#include<bits/stdc++.h>
    
using namespace std;
    
#define int long long
#define endl "\n"

template<typename RandomIt>
void ruffleSort(RandomIt first, RandomIt last)
{
    random_device rd;
    mt19937 g(rd());
    shuffle(first, last, g);
    sort(first, last);
}

template<typename Container>
auto outputContainer(const Container & con) 
{
    for(int i = 0; i < con.size(); ++i)
        cout << con[i] << " \n"[i+1==con.size()];
}

template<typename T = int>
auto readVector(const int N) 
{
    vector<T> v(N);
    for(auto & e : v) cin >> e;
    return v;
}


int32_t main() {
    ios_base::sync_with_stdio(false); 
    cin.tie(nullptr);
    
    int n;
    cin >> n;

    vector<int> d1(n);
    vector<int> d2(n);

    for(int i = 0; i < n; ++i) {
        cin >> d1[i];
        cin >> d2[i];
    }

    bool flag = false;
    for(int i = 0; i < n-2; ++i) {
        if(d1[i] == d2[i] and d1[i+1] == d2[i+1] and d1[i+2] == d2[i+2]) {
            flag = true;
            break;
        }
    }

    if(flag) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}


Measured memory_bytes: 3620
#include <iostream>
#include <string>
#include <vector>
#include <algorithm> // sort
#include <map> // pair
#include <queue>
#include<iomanip>
#include <cmath>
#include <set>
#include <unordered_set>

#define ABS(x) ((x)>0?(x):-(x))
#define MIN(x,y) ((x)>(y)?(y):(x))
#define MAX(x,y) ((x)<(y)?(y):(x))

#define SIZE_OF_ARRAY(array) (sizeof(array)/sizeof(array[0]))

#define INF 1000000000

using namespace std;
typedef long long ll;

ll newton(long long int a, long long int  b)
{
	if(a==b)
		return a;
	while(a != 0 && b != 0)
	{
		if(a > b)
		{
			b += a;
			a = b-a;
			b -= a;
		}
		b %= a;
	}
	return a;
}

struct UnionFind {
	vector<int> p;
	UnionFind(int N):p(N)
	{
		for(int i=0; i< N; i++)
		{
			p[i] = i;
		}
	}
	int root(int x)
	{
		if(p[x] == x)
			return x;
		return p[x] = root(p[x]);
	}
	void unite(int x, int y)
	{
		int rx = root(x);
		int ry = root(y);
		if(rx == ry) return;
		p[rx] = ry;
	}
	bool issame(int x, int y)
	{
		int rx = root(x);
		int ry = root(y);
		return rx == ry;
	}
};

//大きな数に対する割り算をするとき、MODを指定することで掛け算の値に変換できる

ll div2mul_calc(ll a, ll b, ll m)
{
	if (b == 0) {
        return 1;
    } else if (b % 2 == 0) {
        ll d = div2mul_calc(a, b / 2, m);
        return (d * d) % m;
    } else {
        return (a * div2mul_calc(a, b - 1, m)) % m;
    }
}
ll div2mul(ll n, ll mod)
{
	return div2mul_calc(n, mod-2, mod);
}

ll twoRow(ll a, ll b, ll mod)
{
	ll ret = 1;
	for(ll i = 1 ;i <= a+b;++i)
	{
		ret *= i;
		ret %= mod;
	}
	for(ll i = 1 ;i <= a;++i)
	{
		ret *= div2mul(i,mod);
		ret %= mod;
	}
	for(ll i = 1 ;i <= b;++i)
	{
		ret *= div2mul(i,mod);
		ret %= mod;
	}
	return ret;
}

struct edge {
    int from; //出発点
    int to;   //到達点
    int cost; //移動コスト
};

vector< ll > divisor(ll n) {
  vector< ll > ret;
  for(ll i = 1; i * i <= n; i++) {
    if(n % i == 0) {
      ret.push_back(i);
      if(i * i != n) ret.push_back(n / i);
    }
  }
  sort(ret.begin(), ret.end());
  return (ret);
}
/*
小数の桁数を指定する
	cout << setprecision(8)<< mp[0]-mx << endl;
*/
	ll mp[40000][10] = {0};
	ll two[40000][100] = {0};
	ll ans[1000] = {0};

int main()
{
	ll i,j,k,a,b,ans=0;
	char c;
	ll N,M,T, X,Y;
	string S;
	cin >> X >> Y;
	cin >> N >> M;
	cin >> i >> j;
	N -= i;
	M -= j;
	N *= X;
	M *= Y;
	if(N == -1*M)
	{
		cout << "infinity" << endl;
		return 0;
	}
	else
	{
		if((N>0)==(N+M>0))
		{
			cout << 0 << endl;
			return 0;
		}
		if(N < 0)
		{
			N *= -1;
			M *= -1;
		}
		M += N;
		M *= -1;
		ans = 1;
		ans += (N/M)*2;
		if(N % M == 0)
			ans -= 1;
		cout << ans << endl;
	}

	return 0;
}




















Measured memory_bytes: 256
import math
import numpy

A,B,H,M = (int(x) for x in input().split())

if (H * 30) - (5.5 * M) >= 0:
    a = (H * 30) - (5.5 * M)
else:
    a = (5.5 * M) - (H * 30)

c = A**2 + B**2 - 2 * A * B * math.cos(math.radians(a))

c = math.sqrt(c)

print(c)

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

int main() {
  int A,B,q,w,e,r,i,j=0;
  cin >> A >> B;
  for(i=A;i<B+1;i++){
    q=i/10000;
    w=(i%10000)/1000;
    e=(i%100)/10;
    r=i%10;
    if(q==r && w==e){
      j++;
    }
  }
  cout << j << endl;
}

Measured memory_bytes: 256
import statistics
import math
import numpy as np

def getNearestValue(numbers, num):
    idx = np.abs(np.asarray(numbers) - num).argmin()
    for i in range(N):
        near_number= numbers[np.argsort(np.abs(np.asarray(numbers) - num))[i]]
        if near_number >= midian_number:
            near_up_number = near_number
            break
        else:
            continue
    for j in range(N):
        near_number= numbers[np.argsort(np.abs(np.asarray(numbers) - num))[j]]
        if near_number <= midian_number:
            near_under_number = near_number
            break
        else:
            continue
    return near_up_number, near_under_number
        
            


N = int(input())
numbers = [list(map(int, input().split()))]
numbers = numbers[0]

midian_number = statistics.median(numbers)

near_up_number, near_under_number = getNearestValue(numbers, midian_number)



aaa = near_up_number - midian_number
bbb = midian_number - near_under_number
print(int(aaa + bbb))


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

using namespace std;

struct UF {
	UF *p;
	long s;
	UF() :p(nullptr), s(1) {}
	UF *Find() {
		if (p == nullptr)
			return this;
		return p = p->Find();
	}
	int Union(UF &n) {
		auto *r = Find(), *nr = n.Find();
		if (r == nr) return 0;
		if (r->s < nr->s) swap(r, nr);
		nr->p = r, r->s += nr->s;
		return 1;
	}
} u[111111];
tuple<int, int, int> e[111111];
vector<int> v[111111];
int c[111111];
void f(int i, int w) {
	if (c[i] == -1) return;
	if (get<0>(e[i]) > w)
		return;
	c[i] = -1;
	for (int j : {get<1>(e[i]), get<2>(e[i])})
		for (int k : v[j])
			f(k, w);
}
int main() {
	int n, m;
	cin >> n >> m;
	for (int i = 0; i < n; i++) {
		int x;
		scanf("%d", &x);
		u[i + 1].s = x;
	}
	for (int i = 0; i < m; i++) {
		int a, b, y;
		scanf("%d%d%d", &a, &b, &y);
		e[i] = tuple<int, int, int>(y, a, b);
	}
	sort(e, e + m);
	for (int i = 0; i < m; i++)
		v[get<1>(e[i])].push_back(i), v[get<2>(e[i])].push_back(i);
	for (int i = 0; i < m; i++) {
		u[get<1>(e[i])].Union(u[get<2>(e[i])]);
		if (u[get<1>(e[i])].Find()->s >= get<0>(e[i]))
			c[i] = 1;
	}
	for (int i = m; i--;)
		if (c[i] == 1) f(i, get<0>(e[i]));
	int r = 0;
	for (int i = 0; i < m; i++)
		if (!c[i]) r++;
	cout << r << endl;
	return 0;
}


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

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x)) //最大値を求める
#define MIN(x) *min_element(ALL(x)) //最小値を求める

int main(){
    int N,K;
    cin >> N >> K;
    vector<int> p(N,0);
    REP(i,N){
        cin >> p[i];
    }
    sort(ALL(p));
    ll ans = 0;
    REP(i,K){
        ans += p[i];
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3592
#include <bits/stdc++.h>
#define pb push_back
#define LL long long
#define x first
#define y second
#define pii pair<int,int>
#define mp make_pair
#define MEM(x) memset(x,0,sizeof(x))
#define pi acos(-1)
using namespace std;	
int main(){
	int r,g,b,n;
	scanf("%d %d %d %d",&r,&g,&b,&n);
	int ans=0;
	for(int i = 0;i<=n;i++){
		for(int j = 0;j<=n;j++){
			int need=n-i*r-j*g;
			if(need>=0&&need%b==0)
				ans++;
		}
	}
	printf("%d\n",ans);
	return 0;
}
/*




*/

Measured memory_bytes: 384
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<string>
#include<stack>
#include<queue>
#include<vector>
#include<algorithm>
#include<iomanip>
typedef long long int ll;
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define REP(i,n) for (unsigned int i=0;i<(n);i++)
#define EREP(i,n) for (int i=1;i<=(n);i++)
#define ALL(a) (a).begin(),(a).end()
//#define EVEL 1

#ifdef EVEL
#define DEB(X) cout << #X << ":" <<X<<" " ;
#define TF(f) f ? cout<<"true  " : cout<<"false ";
#define END cout<<"\n";
#else
#define DEB(X) {}
#define TF(f) {}
#define END {}
#endif
const int MOD =  1000000007 ;
const int INF = 2000000000;


    ll A,B,C,D;
    string S,T;
int main(){
    cin>>A;
    cout<<(A%2==0?A:A*2)<<endl;
    return 0;

}


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

int main() {
 
	int X,N;
 
	cin >> X;
	
	if (X <= 599){
		N = 8;
	}
	else if(X <= 799){
		N = 7;
	}
	else if(X <= 999){
		N = 6;
	}
	else if(X <= 1199){
		N = 5;
	}
	else if(X <= 1399){
		N = 4;
	}
	else if(X <= 1599){
		N = 3;
	}
	else if(X <= 1799){
		N = 2;
	}
	else {
		N = 1;
	}
	
	cout << N << endl;
	
}

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

// #define int long long
#define rep(i, n) for (long long i = (long long)(0); i < (long long)(n); ++i)
#define reps(i, n) for (long long i = (long long)(1); i <= (long long)(n); ++i)
#define rrep(i, n) for (long long i = ((long long)(n)-1); i >= 0; i--)
#define rreps(i, n) for (long long i = ((long long)(n)); i > 0; i--)
#define irep(i, m, n) for (long long i = (long long)(m); i < (long long)(n); ++i)
#define ireps(i, m, n) for (long long i = (long long)(m); i <= (long long)(n); ++i)
#define SORT(v, n) sort(v, v + n);
#define REVERSE(v, n) reverse(v, v+n);
#define vsort(v) sort(v.begin(), v.end());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) long long(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vs = vector<string>;
using vpll = vector<pair<ll, ll>>;
using vtp = vector<tuple<ll,ll,ll>>;
using vb = vector<bool>;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

const ll INF = 1e9;
const ll MOD = 1e9+7;
const ll LINF = 1e18;



signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  string s; cin>>s;
  set<char> se;
  rep(i,3){
    se.insert(s[i]);
  }
  if(se.count('A')&&se.count('B')) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}

Measured memory_bytes: 380
// Undone
#include <bits/stdc++.h>
#define int long long
#define double long double
#define INF 1e18
using namespace std;
signed main() {
  int N; cin >> N;
  vector< pair<string, pair<int,int> > > v(N);
  for (int i = 0; i < N; i++) {
    string s; int p;
    cin>>s>>p;
    v[i] = make_pair(s, make_pair(-p,i+1));
  }
  sort(v.begin(), v.end());
  for (int i = 0; i < N; i++) {
    cout<<v[i].second.second<<endl;
  }
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define MOD 1000000007
#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define REP(i,n)  FOR(i,0,n)
#define ITR(itr,mp) for(auto itr = (mp).begin(); itr != (mp).end(); ++itr)
#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
typedef long long ll;
typedef pair<ll,ll> P;
typedef vector<P> Graph;

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

  ll n,m;
  cin >> n >> m;
  
  if(n*2 >= m) cout << m/2 << endl;
  else cout << n + (m-n*2)/4 << endl;
  

  return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

class Main{
  public static void main(String[] args){
    Scanner scanner = new Scanner(System.in);
    int stay = Integer.parseInt(scanner.next());
    int FIRST_COST_STAY = Integer.parseInt(scanner.next());
    int FIRST_COST = Integer.parseInt(scanner.next());
    int SECOND_COST = Integer.parseInt(scanner.next());
    scanner.close();

    int cost = 0;

    if(stay < FIRST_COST_STAY){
      cost += stay * FIRST_COST;
    }else{
      cost += FIRST_COST_STAY * FIRST_COST + (stay - FIRST_COST_STAY) * SECOND_COST;
    }

    System.out.println(cost);
  }
}


Measured memory_bytes: 23124
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<random>

//使い方がよくわからない
#include<stack>
#include<queue>
#include<bitset>
#include<sstream>

#define rep(i,n) for(int i=0;i<(n);i++) 
#define rep1(i,n) for(int i=1;i<(n);i++)
#define co(x) cout << x << endl
#define cosp(x) cout << x << " "

using namespace std;
using ll = long long;

int main(int argc, const char *argv[]){
    int n;
    string s;
    cin >> n >> s;
    if(n%2==1){co("No");return 0;}
    rep(i,(n/2)){
        if(s[i]!=s[i+n/2]){co("No");return 0;}
    }
    co("Yes");
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <array>
using namespace std;
using ULL = unsigned long long;
using UL = unsigned;
using LL = long long;
#define rep(i, n) for(UL i = 0; i < (n); i++)

struct Problem {

	void Solve() {
		UL N, M; cin >> N >> M;
		vector<UL> F(N + 1);
		rep(i, N) {
			UL f; cin >> f;
			F[i + 1] = F[i] + f;
			F[i + 1] %= M;
		}
		map<UL, UL> Q;
		ULL ans = 0;
		rep(i, N + 1) {
			auto p = Q.find(F[i]);
			if (p == Q.end()) Q[F[i]] = 1;
			else {
				ans += p->second;
				Q[F[i]]++;
			}
		}
		cout << ans << endl;
	}

	Problem();
};
int main() {
	unique_ptr<Problem> p(new Problem());
	p->Solve();
	return 0;
}
Problem::Problem() {
	cout << fixed << setprecision(10);
}


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

public class Main{
	static int[] room = {0,1,2,3,5,7,8,9};
	static void r(int n) {
		if(n>=8) {
			r(n/8);
		}
		System.out.print(room[n%8]);
	}
    public static void main(String[] args) {
        Scanner sc = new Scanner (System.in);
        while(true) {
        	int n = sc.nextInt();
        	if(n == 0)break;
        	r(n);
        	System.out.println();
        }
    }
    
}



Measured memory_bytes: 61644
#include <bits/stdc++.h>
using namespace std;
long long  a[100005];
char s[100005];
int n;
long long dp[100005][3];
int main()
{
    ios::sync_with_stdio(0);
    cin>>n>>a[0];
    for(int i =1;i<n;i++)
        cin>>s[i]>>a[i];
    for(int i =0;i<n;i++)
        for(int j =0;j<3;j++)
          dp[i][j]=-1e15;
    dp[0][0]=a[0];
    for(int i =1;i<n;i++)
    {
        dp[i][1]=dp[i-1][1];
        dp[i][2]=dp[i-1][2];
        dp[i][0]=dp[i-1][0];
      //  cout<<a[i]<<" "<<s[i]<<endl;
     //   cout<<dp[i][0]<<" "<<dp[i][1]<<" "<<dp[i][2]<<endl;
        if(s[i]=='-')
        {
             dp[i][0]-=a[i];
             dp[i][1]+=a[i];
             dp[i][2]-=a[i];
             dp[i][2]=max(dp[i][1],dp[i][2]);
             dp[i][1]=max(dp[i][0],dp[i][1]);
        }
        else
        {
             dp[i][0]+=a[i];
             dp[i][1]-=a[i];
             dp[i][2]+=a[i];
        }
        dp[i][1]=max(dp[i][2],dp[i][1]);
        dp[i][0]=max(dp[i][1],dp[i][0]);
     // cout<<dp[i][0]<<" "<<dp[i][1]<<" "<<dp[i][2]<<endl;
    }
    cout<<dp[n-1][0]<<endl;
}


Measured memory_bytes: 3456
# coding: utf-8
import sys
from functools import lru_cache
sys.setrecursionlimit(10 ** 7)

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

# Nから0にする
T = ir()

@lru_cache(None)
def F(x, A, B, C, D):
    if x == 1:
        return D
    elif x <= 0:
        return INF
    if x&1:
        a = min(F(x//2, A, B, C, D) + D + A, F((x+1)//2, A, B, C, D) + D + A)
    else:
        a = F(x//2, A, B, C, D) + A
    cnt2 = 0
    y = x
    while y%3 != 0:
        y -= 1
        cnt2 += 1
    b = F(y//3, A, B, C, D) + B + cnt2 * D
    if (x+1)%3 == 0:
        t = F((x+1)//3, A, B, C, D) + B + D
        b = min(b, t)
    cnt3 = 0
    y = x
    while y%5 != 0:
        y -= 1
        cnt3 += 1
    c = min(F(y//5, A, B, C, D) + C + cnt3 * D, F((y+5)//5, A, B, C, D) + C + (5-cnt3) * D)
    d = x * D
    ret = min(a, b, c, d)
    return ret

INF = float('inf')
for _ in range(T):
    N, A, B, C, D = lr()
    answer = F(N, A, B, C, D)
    print(answer)


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

#ifdef _PRINTDEBUG
  #include "lib/printdebug.hpp"
#else
  #define printdebug(...) 1
#endif
#define I1000000007 (1000000007)
#define I998244353   (998244353)
#define IINF             (1<<28)
#define LINF           (1LL<<60)
#define ALL(a)         (a).begin(), (a).end()
#define rep(i, n)      REP(i, 0, (n))
#define repc(i, n)     REPC(i, 0, (n))
#define REP(i, n, m)   for (int i = (int)(n); i <  (int)(m); i++)
#define REPC(i, n, m)  for (int i = (int)(n); i <= (int)(m); i++)
#define REPCM(i, n, m) for (int i = (int)(n); i >= (int)(m); i--)
#define yesno(cond)       YESNO((cond), "Yes", "No")
#define YESNO(cond, a, b) cout << ((cond) ? (a) : (b)) << "\n"
template<class T> inline bool chmin(T& a, const T& b) {
  if (a > b) { a = b; return true; } else return false;
}
template<class T> inline bool chmax(T& a, const T& b) {
  if (a < b) { a = b; return true; } else return false;
}

namespace solver {
  using namespace std;
  using ll = long long;

  string S, T, U;
  int A, B;

  void init() {
    cin >> S >> T >> A >> B >> U;
  }

  void solve() {
    if(S == U) {
      cout << A-1 << " " << B << "\n";
    } else {
      cout << A << " " << B-1 << "\n";
    }
  }
}

int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  solver::init();
  solver::solve();
  return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cmath>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<queue>
#include<functional>

using namespace std;

int main()
{
	priority_queue<long long, vector<long long>, greater<long long>> pq;
	int n, m;
	long long sum, lmax = 0;
	int i, j, k;
	vector<long long> jewel;
	long long input;

	scanf("%d %d", &n, &m);

	for (i = 0; i < n; i++)
	{
		scanf("%lld", &input);

		jewel.push_back(input);
	}

	for (i = 1; i <= m && i <= n; i++)
	{
		for (j = 0; j <= i; j++)
		{
			sum = 0;

			for (k = 0; k < j; k++)
			{
				pq.push(jewel[k]);

				sum += jewel[k];
			}

			for (k = 0; k < i - j; k++)
			{
				pq.push(jewel[n-1-k]);

				sum += jewel[n - 1 - k];
			}

			for (k = 0; k < i&&k < m - i; k++)
			{
				if (pq.top() >= 0)
				{
					break;
				}

				sum -= pq.top();

				pq.pop();
			}

			if (sum > lmax)
			{
				lmax = sum;
			}

			while (!pq.empty())
			{
				pq.pop();
			}
		}
	}

	printf("%lld\n", lmax);

	return 0;
}

Measured memory_bytes: 256