akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define N 200000 + 5
#define ls (p << 1)
#define rs (p << 1 | 1)
#define mid (l + r >> 1)
#define int long long
#define inf 1000000000000000
#define rep(i, l, r) for(int i = l; i <= r; ++i)
struct tree{
    int min1, min2, tag;
}t[N << 2];
int n, q, a, b, x, last; 
int read(){
    char c; int x = 0, f = 1;
    c = getchar();
    while(c > '9' || c < '0'){ if(c == '-') f = -1; c = getchar();}
    while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
    return x * f;
}
void up(int p){
    t[p].min1 = min(t[ls].min1, t[rs].min1);
    t[p].min2 = min(t[ls].min2, t[rs].min2);
}
void lazy(int p, int k){
    t[p].min1 += k, t[p].min2 += k;
    t[p].tag += k;
}
void down(int p){
    if(!t[p].tag) return;
    lazy(ls, t[p].tag), lazy(rs, t[p].tag);
    t[p].tag = 0;
}
void build(int p, int l, int r){
    if(l == r){ t[p].min1 = t[p].min2 = inf; return;}
    build(ls, l, mid), build(rs, mid + 1, r);
    up(p);
}
void update(int p, int l, int r, int x, int y, int k){
    if(l >= x && r <= y){ t[p].min1 = k - l, t[p].min2 = k + l; return;}
    down(p);
    if(mid >= x) update(ls, l, mid, x, y, k);
    if(mid < y) update(rs, mid + 1, r, x, y, k);
    up(p);
}
int query1(int p, int l, int r, int x, int y){
    if(x > y) return inf;
    if(l >= x && r <= y) return t[p].min1;
    down(p);
    int ans = inf;
    if(mid >= x) ans = min(ans, query1(ls, l, mid, x, y));
    if(mid < y) ans = min(ans, query1(rs, mid + 1, r, x, y));
    return ans;
}
int query2(int p, int l, int r, int x, int y){
    if(x > y) return inf;
    if(l >= x && r <= y) return t[p].min2;
    down(p);
    int ans = inf;
    if(mid >= x) ans = min(ans, query2(ls, l, mid, x, y));
    if(mid < y) ans = min(ans, query2(rs, mid + 1, r, x, y));
    return ans;
}
int query(int p, int l, int r){
    if(l == r) return t[p].min1 + l;
    down(p);
    return min(query(ls, l, mid), query(rs, mid + 1, r));
}
signed main(){
    n = read(), q = read(), a = read(), b = read();
    build(1, 1, n);
    last = a, update(1, 1, n, b, b, 0);
    rep(i, 1, q){
        x = read();
        int M1 = query1(1, 1, n, 1, x), M2 = query2(1, 1, n, x + 1, n);
        lazy(1, abs(x - last)), update(1, 1, n, last, last, min(M1 + x, M2 - x));
        last = x;
    }
    printf("%lld", query(1, 1, n));
    return 0;
}

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

using ll=long long;
using Graph=vector<vector<int>>;
int main(){
    int n;
    cin>>n;
    Graph g(n);
    vector<ll> A(n);
    for(int i=0;i<n;i++) cin>>A[i];
    for(int i=0;i<n-1;i++){
        int a,b;
        cin>>a>>b;
        a--,b--;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    if(n==2){
        cout<<(A[0]==A[1] ? "YES" : "NO")<<endl;
        return 0;
    }
    vector<ll> dp(n);
    function<ll(int,int)> dfs=[&](int v,int pre){
        int cntC=0;
        ll ma=0;
        ll sum=0;
        for(int i=0;i<g[v].size();i++){
            if(g[v][i]!=pre){
                auto ret=dfs(g[v][i],v);
                sum+=ret;
                ma=max(ma,ret);
                cntC++;
            }
        }
        if(cntC==0) return dp[v]=A[v];
        ll p=sum-A[v];
        if(sum-ma<ma){
            if(p>sum-ma){
                return dp[v]=-1;
            }
        }
        if(p<0) return dp[v]=-1;
        return dp[v]=2*A[v]-sum;
    };
    int root=0;
    for(int i=0;i<n;i++){
        if(g[i].size()>=2){
            root=i;
            break;
        }
    }
    ll val=dfs(root,-1);
    auto isNeg=[](ll x){return x<0;};
    if(val==0 && none_of(dp.begin(),dp.end(),isNeg)){
        cout<<"YES"<<endl;
    }
    else{
        cout<<"NO"<<endl;
    }
    return 0;
}

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

int cnt[201010];
int cnt2[201010];

signed main(void){ 
  
  int n,k,c; cin >> n >> k >> c;
  string s; cin >> s;
  
  int pos = 0; int work = 0; int num = 0;
  
  while( pos < n && work < k ){
    
    if( s[pos] == 'o' && (num >= c  || work == 0)){
      
      work++;
      num = 0;
      cnt[pos] = work;
    }
    else{
      if(work){ num++;}
    }
    
    pos++;
  }
  
  reverse(s.begin(),s.end());
  
  pos = 0; work = 0; num = 0;
  
  while( pos < n && work < k ){
    
    if( s[pos] == 'o'  && (num >= c  || work == 0 )){ 
      num = 0;
      work++;
      cnt2[n-pos-1] = k-work+1;
    }
    else{
      if(work){num++; }
    }
    pos++;
  }
  
  for(int i = 0; i < n; i++){ 
    if( cnt[i] == cnt2[i] && cnt[i] != 0 ){ 
      cout << i+1 << endl;
    }
  }
  
  return 0;
}

Measured memory_bytes: 4996
#include<bits/stdc++.h>
using namespace std;
#define NitroBoost \
        ios_base::sync_with_stdio(false); \
        cin.tie(NULL);
#define ll long long
#define fori(i,l,n) for(int i=l;i<n;i++)
#define ford(i,n,l) for(int i=n;i>l;i--)
#define All(i,x) for(auto i=x.begin();i!=x.end();++i)
#define gcd(a,b) __gcd((a),(b))
#define lcm(a,b) (((a)*(b))/gcd((a),(b)))
#define test int t;cin>>t;while(t--)
#define pb(i) push_back(i)
#define watch(x) cout<<(#x)<<"="<<(x)<<"\n"
#define str(n) to_string(n)
#define fi first
#define sec second
#define prec(n) fixed<<setprecision(n)
#define mp make_pair
const double pi=3.141592653589793;
const int MOD=1e9+7;
ll power(ll x, ll y, ll m) 
{
     ll res = 1;x %= m;
    while (y > 0) {
        if (y & 1)
        res = (res*x) % m;
        y>>=1;
        x = (x*x) % m;
    }
    return res%m;
}
ll look[1000][1000];
ll dp(char a[][1000],int r, int c){
	if(r==1 && c==1)
	return 1;
	if(look[r-1][c-1]!=-1)
	return look[r-1][c-1]%MOD;
	if(a[r-1][c-1]=='#')
	return 0;
	if(r==1)
	return look[r-1][c-1]=dp(a,r,c-1)%MOD;
	if(c==1)
	return look[r-1][c-1]=dp(a,r-1,c)%MOD;
	return look[r-1][c-1]=(dp(a,r-1,c)%MOD+dp(a,r,c-1)%MOD)%MOD;
}
void solve(){
    int h,w;	
	cin>>h>>w;
	char a[h][1000];
	fori(i,0,h){
		fori(j,0,w)
		cin>>a[i][j];
	}
	fori(i,0,1000)
	{
		fori(j,0,1000)
		look[i][j]=-1;
	}
	cout<<dp(a,h,w)<<"\n";
}
int main(){  
    NitroBoost
    //freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);
    //test
    {
        solve();
    }
    return 0;
}

Measured memory_bytes: 12524
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<math.h>
#define rep(i, a) for(int i = 0; i < a; i++)
using namespace std;

int main(){
	int h, w;
	while(1){
		cin >> h >> w;
		if(h == 0 && w == 0) break;
		rep(i, h){
			rep(i, w){
				cout << "#";
			}
		cout << endl;
		}
	cout << endl;
	}

}

Measured memory_bytes: 1152
#include<stdio.h>
int main(void){
  int N,i,count=0;
  scanf("%d",&N);
  int p[N];
  for(i=0;i<N;i++){
    scanf("%d",&p[i]);
  }
  for(i=0;i<N;i++){
    if((i+1)!=p[i]){
      count++;
    }
  }
  if(count==0 ||count==2){
    printf("YES");
  }
  else{
    printf("NO");
  }
  return 0;
}

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

using namespace std;

#define ll long long

int main()
{
	ll N, W;
	cin >> N >> W;
	ll w[N], v[N], vmax=0;
	for(ll i = 0; i < N; i++)
	{
		cin >> w[i] >> v[i];
		vmax += v[i];
	}
	ll ans[N][vmax+1];
	ans[0][0] = 0;
	for(int i = 1; i < vmax+1; i++)
	{
		if(i<v[0])
			ans[0][i] = 1000000000;
		else if(i == v[0])
			ans[0][i] = w[0];
		else
			ans[0][i] = 1000000000;
	}
	for(int i = 1; i < N; i++)
	{
		for(int j = 0; j < vmax+1; j++)
		{
			if(j-v[i] < 0)
				ans[i][j] = ans[i-1][j];

			else
				ans[i][j] = min(ans[i-1][j], ans[i-1][j-v[i]]+w[i]);
		}
	}
	for(int i = vmax; i >= 0; i--)
		if(ans[N-1][i] <= W)
		{
			cout << i;
			break;
		}
}

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

int main() {
    int N;
    long long int Y;
    cin >> N >> Y;
    bool judge = false;
    for(int yen10000 = 0; yen10000 <= N; yen10000++) {
        for(int yen5000 = 0; yen5000 <= N - yen10000; yen5000++) {
            int yen1000 = N - yen10000 - yen5000;
            int sum = 10000*yen10000 + 5000*yen5000 + 1000*yen1000;
            if(sum == Y) {
                judge = true;
                cout << yen10000 << " " << yen5000 << " " << yen1000 << endl;
                return 0;
            }
        }
    }
    cout << -1 << " " << -1 << " " << -1 << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <iomanip>

using namespace std;

int main(void){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  long double ans = 0;
  long double pie = 3.141592653589793238;
  int a;
  cin >> a;
  
  ans = a * 2;
  ans = ans * pie;
  
  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 3820
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1e16;

template <typename T>
struct Graph {
    int V, E;
    struct Edge {
        int from, to;
        T cost;
    };
    vector<vector<Edge>> edge;
    vector<vector<T>> dist;
    vector<Edge> es;

    Graph(int V, int E) : V(V), E(E) {
        edge.assign(V, vector<Edge>(0));
        dist.assign(V, vector<T>(0));
    }

    void add_edge(int from, int to, T cost, bool is_direct) {
        edge[from].push_back({from, to, cost});
        es.push_back({from, to, cost});
        if (!is_direct) {
            edge[to].push_back({to, from, cost});
            es.push_back({to, from, cost});
            E++;
        }
        E++;
    }
    typedef pair<T, int> P;  // (first,second) := (最短距離,頂点番号)
    // 頂点rからの最小距離
    void dijkstra(int r = 0) {
        dist[r].assign(V, INF);

        priority_queue<P, vector<P>, greater<P>> que;
        que.push(P(0, r));
        dist[r][r] = 0;

        while (que.size()) {
            P p = que.top();
            que.pop();
            int v = p.second;
            if (dist[r][v] < p.first) continue;
            for (int i = 0; i < edge[v].size(); i++) {
                Edge e = edge[v][i];
                if (dist[r][v] + e.cost < dist[r][e.to]) {
                    dist[r][e.to] = dist[r][v] + e.cost;
                    que.push(P(dist[r][e.to], e.to));
                }
            }
        }
    }
};

int main() {
    int N, M, S;
    cin >> N >> M >> S;
    Graph<ll> g((50 * (N - 1) + 1) * N, 0);

    auto f = [&](int v, ll x) {
        if (x >= 50 * (N - 1)) x = 50 * (N - 1);
        return x * N + v;
    };
    for (int i = 0; i < M; i++) {
        int u, v;
        ll a, b;
        cin >> u >> v >> a >> b;
        u--, v--;
        for (ll x = a; x <= 50 * (N - 1); x++) {
            g.add_edge(f(u, x), f(v, x - a), b, true);
            g.add_edge(f(v, x), f(u, x - a), b, true);
        }
    }
    for (int i = 0; i < N; i++) {
        ll c, d;
        cin >> c >> d;
        for (ll x = 0; x < 50 * (N - 1); x++) {
            g.add_edge(f(i, x), f(i, x + c), d, true);
        }
    }
    int r = f(0, S);
    g.dijkstra(r);
    for (int i = 1; i < N; i++) {
        ll ans = INF;
        for (ll x = 0; x <= 50 * (N - 1); x++) ans = min(ans, g.dist[r][f(i, x)]);
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 38440
#include<iostream>
#include<algorithm>
#include<vector>
#include<math.h>
#include<string.h>
#include<queue>
using namespace std;
typedef long long ll;
typedef pair<int, int>P;
int n;
int v[20], c[20];
int ans = 0;
void dfs(int i, int x, int y) {
	if (i == n) {
		ans = max(ans, x - y);
		return;
	}
	dfs(i + 1, x + v[i], y + c[i]);
	dfs(i + 1, x, y);
}

int main() {
	 cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> v[i];
	}
	for (int i = 0; i < n; i++) {
		cin >> c[i];
	}
	dfs(0, 0, 0);
	cout << ans << endl;
	return 0;
}

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

int main() {
	int n;
	string a;
	cin >> n >> a;
	int count = 0;
	int left = 0;
	int	right = n-1;
	while (right > left) {
		if (a.substr(left, 1) == "W" && a.substr(right, 1) == "R") {
			count++;
			right--;
			left++;
			continue;
		}
		if (a.substr(right, 1) == "W") {
			right--;
		}
		if (a.substr(left, 1) == "R") {
			left++;
		}
	}
	cout << count;
	return 0;
}

Measured memory_bytes: 3768
#include<stdio.h>
#include<string.h>
#include<stdlib.h>

int search(char *text,char *key)
{
  int m,n,i;
  char *p;
  m=strlen(text);n=strlen(key);
  for(p=text;p<=text+m-n;p++){
    if(strncmp(p,key,n)==0)
      return 1;
  }
  return -1;

}

int main(void)
{
  char str[80];
  int i,j,k;
  while(fgets(str,sizeof(char)*80,stdin)){
    while(1){  
      for(i=0;i<strlen(str);i++)
	if(isalnum(str[i])){
	  if(str[i]=='z')
	    str[i]='a';
	  else
	    str[i]=str[i]+1;
	}
      if(search(str,"the")==1 ||search(str,"this")==1||search(str,"that")==1){
	printf("%s",str);
	break;
      }
    }

  }
 

  return 0;
}

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

int main(){
	int n;
	long tmp;
	vector<long> a;
	cin>>n;

	for(int i=0; i<n; i++){
		cin>> tmp;
		a.push_back(tmp);
	}

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

	long cand[2];
	cand[0]= 0;
	cand[1]= 0;

	tmp= a.at(0);

	for(int i=1; i<n; i++){
		if(tmp== a.at(i)){
			if(cand[0]== 0){
				cand[0]= a.at(i);
				tmp=0;
			}else if(cand[1]== 0){
				cand[1]= a.at(i);
				break;
			}
		}else{
			tmp= a.at(i);
		}
	}


	cout<< cand[0]*cand[1]<<endl;

	return 0;
}

Measured memory_bytes: 1400
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// 秒単位の時間 Sが与えられるので、h:m:sの形式へ変換して出力してください。
		Scanner sc = new Scanner(System.in);
		int S = sc.nextInt();
		
		int h = S / 3600;
		int m = (S % 3600) / 60;
		int s = S % 60;
		
		System.out.println(h + ":" + m + ":" + s);

	}

}



Measured memory_bytes: 26412
#include<bits/stdc++.h>
#define int long long

using namespace std;
//int arr[1000001];

int32_t main(){

int n;
cin>>n;
int Max = 0;
int arr[n];
map<int , int>m;
for(int i=0; i<n; i++){
	cin>>arr[i];
	m[arr[i]]++;
	if(arr[i]>Max)Max =  arr[i];
}
int cnt=0;
bool arr2[Max+1];
///cout<<"max = "<<Max<<endl;
memset(arr2, false, sizeof(arr2));
for(int i=0; i<n; i++){
	for(int j=arr[i]*2; j<=Max; j+=arr[i])
		arr2[j]  = true;
}
for(int i=0; i<n; i++){
	if(arr2[arr[i]]==false && m[arr[i]]==1)cnt++;
}
///for(int i=1; i<=Max; i++)cout<<arr2[i]<<" ";

cout<<cnt<<endl;

return 0;
}

Measured memory_bytes: 18604
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp7
{
	class Program
	{
		static void Main(string[] args)
		{
			var str = Console.ReadLine().Split(' ');
			var a = double.Parse(str[0]); //辺aの長さ
			var b = double.Parse(str[1]); //辺bの長さ
			var c = double.Parse(str[2]); //辺a,bの内角

			double s; //面積
			double l; //周の長さ
			double h = 0; //aが底辺の場合の三角形の高さ
			double d; //a,b以外の辺
			
			double d2 =(a * a) + (b * b) - 2 * a * b * Math.Cos(c * (Math.PI / 180));
			d = Math.Sqrt(d2);
			h = b * Math.Sin(c * (Math.PI / 180));
			
			l = a + b + d;
			s = a * h / 2;

			Console.WriteLine(s);
			Console.WriteLine(l);
			Console.WriteLine(h);


		}
	}
}



Measured memory_bytes: 15944
#include<stdio.h>

int main(void){
  int n,r,p,c,i,j,card[52],temp[52];
  
  while(scanf("%d %d",&n,&r),n,r){
    for(i=0;i<51;i++)card[i]=i;

    for(i=0;i<r;i++){
      scanf("%d %d",&p,&c);
      
      for(j=0;j<c;j++){
	temp[n-j]=card[n-p+1-j];
      }

      for(j=1;j<=p-1;j++){
	card[n-(p-1)-c+j]=card[n-(p-1)+j];
      }

       for(j=0;j<c;j++){
	 card[n-j]=temp[n-j];
      }
    }
    printf("%d\n",card[n]);
  }


  return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
int n,a[200004],b[200004];
int main(){
	cin>>n;
	for(int i=1;i<=n;i++)cin>>a[i]>>b[i];
	sort(a+1,a+1+n);sort(b+1,b+1+n);
	if(n%2==1)cout<<b[(n+1)/2]-a[(n+1)/2]+1;
	if(n%2==0){
		cout<<(b[n/2+1]+b[n/2])-(a[n/2+1]+a[n/2])+1;
	}
}


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

using namespace std;

int main()
{
    int i,j,k,n,m,x,y,z;
    cin>>n>>x;
    int a[n+1];
    int b[n+1];
    for(i=0;i<n;i++)
    {
        cin>>a[i];
    }
    b[0]=0;
    for(i=1;i<=n;i++)
    {
        b[i]=b[i-1]+a[i-1];
    }
    y=0;
    for(i=0;i<=n;i++)
    {
        if(b[i]<=x)
        {
            y++;
        }
    }
    cout<<y<<endl;

}


Measured memory_bytes: 256
/*** author: yuji9511 ***/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> lpair;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i = (m); i < (n); i++)
#define rrep(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define print2(x,y) cout << (x) << " " << (y) << endl;
#define printa(x,n) for(ll i = 0; i < n; i++){ cout << (x[i]) << " \n"[i==n-1];};
vector<ll> tree[10010];
ll val[10010] = {};
ll idx = 0;
ll c[10010];
void dfs(ll cur, ll par){
    val[cur] = c[idx];
    idx++;
    for(auto &e: tree[cur]){
        if(e == par) continue;
        dfs(e, cur);
    }
}
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N;
    cin >> N;
    ll a[10010], b[10010];
    
    rep(i,0,N-1){
        cin >> a[i] >> b[i];
        a[i]--; b[i]--;
        tree[a[i]].push_back(b[i]);
        tree[b[i]].push_back(a[i]);
    }
    rep(i,0,N) cin >> c[i];
    sort(c, c+N, greater<ll>());
    ll ans = 0;
    rep(i,1,N) ans += c[i];
    dfs(0, -1);
    print(ans);
    printa(val, N);




    
}

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

using namespace std;
#define all(a)a.begin(),a.end()
using ll=long long;
const int INF = 1<<30;
const ll INFll =1LL<<62;
const int mod =(1e9)+7;
using P = pair<ll,ll>;

int main(){
    double a,b,h,m;
    cin >>a>>b>>h>>m;
    double pi=3.14159265358979;
    ll time=60*h+m;
    double min=(double)(time%60)*2*pi/60;
    double ho=(double)time*2*pi/(60*12);
    double rad=abs(min-ho);
    double ans=sqrt(a*a+b*b-2*a*b*cos(rad));
    cout <<setprecision(20)<<ans <<endl;
    return 0;
}



Measured memory_bytes: 4224
function main()
	isp=[true for _=1:10^5]
	isp[1]=false
	for i=2:10^5
		if isp[i]
			for j=2:fld(10^5,i)
				isp[i*j]=false
			end
		end
	end
	ok=[N%2==1&&isp[N]&&isp[(N+1)>>1] for N=1:10^5]
	sum=Int[0]
	for i=1:10^5
		push!(sum,sum[end]+ok[i])
	end
	readline()
	for s=readlines()
		l,r=map(x->parse(Int,x),split(s))
		println(sum[r+1]-sum[l])
	end
end
main()


Measured memory_bytes: 153544
def gcd(a, b)
  if b > a
    gcd(b, a)
  elsif b == 0
    a
  else
    gcd(b, a % b)
  end
end

n = gets.to_i
a = gets.split.map(&:to_i)

p a.reduce { |x, y| gcd(x, y) }


Measured memory_bytes: 8452
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
const ll mod998 = 998244353;
const ll intmax = 2147483647;
const ll llmax = 9223372036854775807;
const char sp = ' ';

ll N;

int main() {
	cin >> N;
	if (N & 1)cout << 0 << endl;
	else {
		ll c = 0;
		N /= 2;
		while (N) {
			N /= 5;
			c += N;
		}
		cout << c << endl;
	}
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M, X;
  cin >> N >> M >> X;
  vector<int> vec(M);
  int count = 0;
  for(int i = 0; i < M; i++) {
    cin >> vec.at(i);
    if(vec.at(i) < X) {
      count++;
    }
  }
  if(count < M - count) {
    cout << count << endl;
  }
  else {
    cout << M - count << endl;
  }
}

Measured memory_bytes: 3620
from scipy.sparse import*;(n,m),*d=[map(int,o.split())for o in open(0)];*w,a=zip(*[(i,j+n-1,1)for i,(_,*d)in enumerate(d)for j in d]);print("YNEOS"[1in csgraph.connected_components(csr_matrix((a,w),[n+m]*2))[1][:n]::2])

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

using namespace std;

#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)((x).size()))

typedef pair<int, int> PII;
typedef vector<int> VI;
typedef long long int64;
typedef unsigned int uint;
typedef unsigned long long uint64;

#define gi(x) ((x) = F())
#define gii(x, y) (gi(x), gi(y))
#define giii(x, y, z) (gii(x, y), gi(z))

int F()
{
	char ch;
	int x, a;
	while (ch = getchar(), (ch < '0' || ch > '9') && ch != '-');
	if (ch == '-') ch = getchar(), a = -1;
	else a = 1;
	x = ch - '0';
	while (ch = getchar(), ch >= '0' && ch <= '9')
		x = (x << 1) + (x << 3) + ch - '0';
	return a * x;
}

const int N = 20010;

int n, p[N], a[N], b[N];

int main()
{
	gi(n);
	for (int i = 1; i <= n; ++i) gi(p[i]);
	for (int i = 1; i <= n; ++i) a[i] = a[i - 1] + 20000;
	for (int i = n; i; --i) b[i] = b[i + 1] + 20000;
	for (int i = 1; i <= n; ++i) a[p[i]] += i, b[p[i]] += i;
	for (int i = 1; i <= n; ++i) printf("%d ", a[i]); puts("");
	for (int i = 1; i <= n; ++i) printf("%d ", b[i]); puts("");
	return 0;
}

Measured memory_bytes: 896
#include<iostream>
#include<algorithm>
#include<vector>

using namespace std;

int main() {
	long long int N, max = 0, TMP;
	vector<long long int> a;

	cin >> N;
	for (int i = 0; i < (3 * N); i++) {
		cin >> TMP;
		a.push_back(TMP);
	}
	sort(a.rbegin(), a.rend());

	for (int i = 0; i < N; i++) {
		max += a[i * 2 + 1];
	}
	cout << max << endl;

	return 0;
}

Measured memory_bytes: 6000
Module Program
  Sub Main
    Dim s = GetInts()
    Dim a=s(0)-1,b=s(1)-1
    Dim ans=a*b
    Console.WriteLine(ans)
  End Sub
  
  '/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
  Function Gets() As String()
    Gets = Console.ReadLine().Split(" "c)
  End Function
  Function GetInts() As Integer()
    Dim s = Gets(), r(UBound(s)) As Integer
    For i As Integer=0 To UBound(s): r(i)=s(i): Next i
    GetInts = r
  End Function
End Module

Measured memory_bytes: 20304
#include <cassert>
#include <cstdio>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <numeric>
#include <algorithm>

using namespace std;
using lint = long long;
constexpr int MOD = 1000000007, INF = 1010101010;
constexpr lint LINF = 1LL << 60;

template <class T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
	for (const auto &e : vec) os << e << (&e == &vec.back() ? "\n" : " ");
	return os;
}

#ifdef _DEBUG
template <class T>
void dump(const char* str, T &&h) { cerr << str << " = " << h << "\n"; };
template <class Head, class... Tail>
void dump(const char* str, Head &&h, Tail &&... t) {
	while (*str != ',') cerr << *str++; cerr << " = " << h << "\n";
	dump(str + (*(str + 1) == ' ' ? 2 : 1), t...);
}
#define DMP(...) dump(#__VA_ARGS__, __VA_ARGS__)
#else 
#define DMP(...) ((void)0)
#endif

lint gcd(lint a, lint b) { return b ? gcd(b, a%b) : a; }

int main() {

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	lint a, b;
	cin >> a >> b;

	cout << a * b / gcd(a,b) << "\n";

	return 0;
}

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

#define rep(i, u) for (int i = 0; i < u; i++)

using ll = long long;
using ull = unsigned long long;

int main() {
  string s;
  getline(cin, s);
  rep(i, (int)s.size()) {
    if (!islower(s[i])) s[i] = tolower(s[i]);
    else s[i] = toupper(s[i]);
  }
  cout << s << endl;
  return 0;
}



Measured memory_bytes: 3180
#include <stdio.h>
int x,y;
int i;
main(){
   
   while(1){
   scanf("%d%d",&x,&y);
  
   if(x>y){
   i=x;
   x=y;
   y=i;
   }
  
   if(x==0&&y==0){
    break;
   }
   
   else{
    printf("%d %d\n",x,y);
   }
  }
  return 0;
}

Measured memory_bytes: 600
N = gets.to_i
A = [0] + gets.split(' ').map(&:to_i) + [0]
sum = 0
(N + 1).times do |i|
  sum += (A[i + 1] - A[i]).abs
end
(1..N).each do |i|
  puts sum - (A[i + 1] - A[i]).abs - (A[i] - A[i - 1]).abs + (A[i + 1] - A[i - 1]).abs
end

Measured memory_bytes: 12548
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n) ; ++i)
#define FOR(i,a,b) for(int i = (a); i < (b); ++i)
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define emb emplace_back
#define fcout cout << fixed << setprecision(15)

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

template<typename T> void pv(vector<T> vec) {
  cout << "[";
  for(auto& v : vec) { cout << v << ","; }
  cout << "]" << endl;
}

template<>
void pv(vector<P> vec) {
  cout << "[";
  for(auto& v : vec) {
    cout << "<" << v.fi << ","<< v.se << ">" << ",";
  }
  cout << "]" << endl;
}

ll gcd(ll a, ll b) { return b ? gcd(b,a%b) : a; }

int main() {
  ll n,k;
  cin >> n >> k;

  if(n <= k) cout << min(abs(n-k),n) << endl;
  else cout << min(n % k,abs((n%k)-k)) << endl;

  return 0;
}


Measured memory_bytes: 256
from numpy import inf
n, m, x =map(int, input().split())
a = list(map(int, input().split()))
ans=inf
if x<a[0] or a[m-1]<x:
    print(0)
    exit()
for i in range(m-1):
    if a[i]<x<a[i+1]:
        ans=min(ans,min(i+1,m-i-1))
print(ans)

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

int main() {
  int a, b;
  cin >> a; cin >> b;
  for (int i = 13; i <= 1009; i++) {
    if (floor(i*0.08) == a && floor(i*0.1) == b) {
      cout << i << endl;
      return 0;
    }
  }
  cout << -1 << endl;
  return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("O3")

#include <bits/stdc++.h>

using namespace std;

#define n_l '\n'
#define dbg(...) cout << "[" << #__VA_ARGS__ << "]: "; cout << to_string(__VA_ARGS__) << endl
template <typename T, size_t N> int SIZE(const T (&t)[N]){ return N; } template<typename T> int SIZE(const T &t){ return t.size(); } string to_string(const string s, int x1=0, int x2=1e9){ return '"' + ((x1 < s.size()) ? s.substr(x1, x2-x1+1) : "") + '"'; } string to_string(const char* s) { return to_string((string) s); } string to_string(const bool b) { return (b ? "true" : "false"); } string to_string(const char c){ return string({c}); } template<size_t N> string to_string(const bitset<N> &b, int x1=0, int x2=1e9){ string t = ""; for(int __iii__ = min(x1,SIZE(b)),  __jjj__ = min(x2, SIZE(b)-1); __iii__ <= __jjj__; ++__iii__){ t += b[__iii__] + '0'; } return '"' + t + '"'; } template <typename A, typename... C> string to_string(const A (&v), int x1=0, int x2=1e9, C... coords); int l_v_l_v_l = 0, t_a_b_s = 0; template <typename A, typename B> string to_string(const pair<A, B> &p) { l_v_l_v_l++; string res = "(" + to_string(p.first) + ", " + to_string(p.second) + ")"; l_v_l_v_l--; return res; } template <typename A, typename... C> string to_string(const A (&v), int x1, int x2, C... coords) { int rnk = rank<A>::value; string tab(t_a_b_s, ' '); string res = ""; bool first = true; if(l_v_l_v_l == 0) res += n_l; res += tab + "["; x1 = min(x1, SIZE(v)), x2 = min(x2, SIZE(v)); auto l = begin(v); advance(l, x1); auto r = l; advance(r, (x2-x1) + (x2 < SIZE(v))); for (auto e = l; e != r; e = next(e)) { if (!first) { res += ", "; } first = false; l_v_l_v_l++; if(e != l){ if(rnk > 1) { res += n_l; t_a_b_s = l_v_l_v_l; }; } else{ t_a_b_s = 0; } res += to_string(*e, coords...); l_v_l_v_l--; } res += "]"; if(l_v_l_v_l == 0) res += n_l; return res; } void dbgm(){;} template<typename Heads, typename... Tails> void dbgm(Heads H, Tails... T){ cout << to_string(H) << " | "; dbgm(T...); }
#define dbgm(...) cout << "[" << #__VA_ARGS__ << "]: "; dbgm(__VA_ARGS__); cout << endl

#define REP(i,a,b) for(int i=(a);i<(b);i++)
#define PER(i,a,b) for(int i=(a);i>(b);i++)
#define SZ(a) int((a).size())
#define ALL(a) (a).begin(), (a).end()
#define MS(s, n) memset(s, n, sizeof(s))
#define IN(t, x) (t.find(x) != t.end())
#define PB push_back
#define MP make_pair
#define VI vector<int>

typedef vector<pair<int, int>> VPII;
typedef pair<int, int> PII;
typedef long long ll;
typedef unsigned long long ull;
const int MOD = (int) 1e9 + 7;//


int main() {
    int n;
    cin >> n;
    vector<pair<int, int>> C(n);
//    vector<int> B(n);
    int a, b;
    for (int i = 0; i < n; i++) {
//        cin >> A[i] >> B[i];
        cin >> a >> b;
        C[i] = MP(b, a);
    }
    sort(ALL(C));
    int cur = 0;
    for (int i = 0; i < n; i++) {
        if (cur + C[i].second > C[i].first) {
            cout << "No\n";
            return 0;
        }
        cur += C[i].second;
    }
    cout << "Yes\n";
    return 0;
}

Measured memory_bytes: 1792
def calculation(time_array):
    first_values = [i % 10 if i % 10 != 0 else i for i in time_array]
    minlocation = first_values.index(min(first_values))
    last_order = time_array.pop(minlocation)
    order_time = [i if i % 10 == 0 else int(i /10) * 10 + 10 for i in time_array]
    return sum(order_time) + last_order

if __name__ == "__main__":
    receipe_time = [int(input()) for i in range(5)]
    # receipe_time = [23, 60, 78, 42, 89]
    print(calculation(receipe_time))


Measured memory_bytes: 3060
#include <iostream>
#include <cmath>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <algorithm>

typedef long long ll;

using namespace std;

int main() {
    ll N, A, B;
    cin >> N >> A >> B;
    ll n = N / (A + B);
    ll mod = N % (A + B);
    ll count  = n * A;
    count += mod < A ? mod : A;
    cout << count << endl;
    return 0;
}



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

public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader input =new BufferedReader (new InputStreamReader (System.in));
		String strn = input.readLine( );
		int n = Integer.parseInt(strn);
		int[] list = new int[n+1];
		Arrays.fill(list, 0);
		long answer = 1;
		int x = 0;

		for(int i=1; i<n+1; i++){
			x = i;
			for(int j=1; j<i+1; j++){
				while((x)%(j) == 0){
					list[j] = list[j]+1;
					x = x / (j);
					if(j==1){
						break;
					}
				}
			}
		}

		for(int i=2; i<n+1; i++){
			answer = answer * (list[i]+1);
			answer = answer % (int)(Math.pow(10, 9)+7);
		}

		System.out.println(answer);
	}

}



Measured memory_bytes: 21460
n,k = list(map(int,input().split()))
sunuke = [i for i in range(1,n+1)]

while k > 0:
    d = int(input())
    a = list(map(int,input().split()))
    for i in range(len(a)):
        if a[i] in sunuke:
            sunuke.remove(a[i])
    k -= 1

print(len(sunuke))


Measured memory_bytes: 9048
#pragma warning(disable:4786)
#pragma warning(disable:4996)
#include<list>
#include<bitset>
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<set>
#include<map>
#include<functional>
#include<string>
#include<cstring>
#include<cstdlib>
#include<queue>
#include<utility>
#include<fstream>
#include<sstream>
#include<cmath>
#include<stack>
#include<assert.h>
using namespace std;

#define MEM(a, b) memset(a, (b), sizeof(a))
#define CLR(a) memset(a, 0, sizeof(a))
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define ABS(X) ( (X) > 0 ? (X) : ( -(X) ) )
#define S(X) ( (X) * (X) )
#define SZ(V) (int )V.size()
#define FORN(i, n) for(i = 0; i < n; i++)
#define FORAB(i, a, b) for(i = a; i <= b; i++)
#define ALL(V) V.begin(), V.end()
#define IN(A, B, C)  ((B) <= (A) && (A) <= (C))

typedef pair<int,int> PII;
typedef pair<double, double> PDD;
typedef vector<int> VI;
typedef vector<PII > VP;

#define AIN(A, B, C) assert(IN(A, B, C))

//typedef int LL;
typedef long long int LL;
//typedef __int64 LL;

int n, m;
VI V[4 * 100005];
VI Z[100005];

void build(int at, int l, int r) {
	for (int i = l; i <= r; i++) {
		for (int j : Z[i]) {
			V[at].push_back(j);
		}
	}
	sort(V[at].begin(), V[at].end());
	if (l == r) {
		return;
	}
	int m = (l + r) / 2;
	build(at * 2, l, m);
	build(at * 2 + 1, m + 1, r);
}

int solve(const VI& V, int L, int R) {
	int id = upper_bound(ALL(V), R - 1) - V.begin();
	return V.size() - id;
}

int query(int at, int l, int r, int L, int R) {
	if (R < l || r < L) return 0;
	if (L <= l &&  r <= R) {
		return solve(V[at], L, R);
	}
	int m = (l + r) / 2;
	int a = query(at * 2, l, m, L, R);
	int b = query(at * 2 + 1, m + 1, r, L, R);
	return a + b;
}

int main()
{
	scanf("%d %d", &n, &m);
	for (int i = 1; i <= n; i++) {
		int l, r;
		scanf("%d %d", &l, &r);
		Z[l].push_back(r);
	}
	build(1, 1, m);
	for (int i = 1; i <= m; i++) {
		int ans = 0;
		for (int j = i; j <= m; j += i) {
			int prev = j - i;
			ans += query(1, 1, m, prev + 1, j);
		}
		printf("%d\n", ans);
	}
	return 0;
}


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

namespace AtTest.ABC_128
{
    class D
    {
        static void Main(string[] args)
        {
            Method(args);
        }

        static void Method(string[] args)
        {
            int[] nk = ReadInts();
            int[] vs = ReadInts();
            int n = nk[0];
            int k = nk[1];

            int res = int.MinValue;
            for (int l = 0; l <= n; l++)
            {
                for (int r = 0; r + l <= n&&r+l<=k; r++)
                {
                    List<int> list = new List<int>();
                    for (int i = 0; i < l; i++) list.Add(vs[i]);
                    for (int i = n - 1; i > n - 1 - r; i--) list.Add(vs[i]);

                    list.Sort();
                    int remain = k - r - l;
                    for (int i = 0; i < remain && 0 < list.Count; i++) {
                        if (list[0] < 0) list.RemoveAt(0);
                    }
                    int temp = 0;
                    for (int i =0; i < list.Count; i++) temp += list[i];
                    res = Max(res, temp);
                }
            }
            WriteLine(res);
        }

        private static string Read() { return ReadLine(); }
        private static char[] ReadChars() { return Array.ConvertAll(Read().Split(), a => a[0]); }
        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: 13268
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
 
 
 
int main(){
int D, T, S, A;

scanf("%d%d%d",&D,&T,&S);

A = (S*T) - D;

if(A>=0){printf("Yes");}

else{printf("No");}





return 0;
 
 
 
}

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

main(){
  int n,q;
  cin>>n;
  vector<int>v(n+1);
  r(i,n)cin>>v[i];
  v[n]=1e9+7;
  cin>>q;
  while(q--){
    int a;
    cin>>a;
    int b=lower_bound(v.begin(),v.end(),a)-v.begin();
    cout<<b<<endl;
  }
}


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

ws = [['a']]
for level in range(1, n):
    ws.append([])
    for front_w in ws[level - 1]:
        max_c = max(front_w)
        ws[level] += ([front_w + chr(c) for c in range(ord('a'), ord(max_c) + 2)])

print('\n'.join(ws[-1]))


Measured memory_bytes: 17000
import java.io.BufferedInputStream;
import java.util.Scanner;

public class Main {

	// 14:02-
	public static void main(String[] args) {
		Scanner sc = new Scanner(new BufferedInputStream(System.in));
		int n = sc.nextInt();
		int t = sc.nextInt();
		long sum = 0L;
		long until = 0L;
		for (int i = 0; i < n; i++) {
			int x = sc.nextInt();
			sum -= Math.max(until - x, 0);
			sum += t;
			until = x + t;
		}
		System.out.println(sum);
	}
}


Measured memory_bytes: 60712
#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <complex>
#include <tuple>

#define FAST ios_base::sync_with_stdio(false); cin.tie(0)
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
// #define repr(i, a, b) for(int i=int(a); i>=int(b); i--)
#define reps(i,n) for(int i=1;i<=int(n);++i)
#define repr(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define reprs(i,x) for(int i=((int)(x));i>0;i--)
#define iceil(x,y) (x+y-1)/y
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define all(x) (x).begin(),(x).end()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() )
#define LF "\n"

template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
typedef pair<int, PII> PP;

ll n,k;
ll vec[200001] = {};

int main(){
	FAST;

	cin >> n >> k;
	ll all=0;
	rep(i,n) {
		ll r;
		cin >> r;
 		vec[r]++;
		all+=1;
	}

	sort(vec, vec+200001, std::greater<ll>());

	ll tmp=0;
	rep(i,k) {
		tmp += vec[i];
	}
	cout << all - tmp << LF;

	return 0;
}

Measured memory_bytes: 1792
st[200001],cur,N,r;
main(a){
	for(scanf("%d",&N);N--;){
		scanf("%d",&a);
		for(;st[cur]>a;cur--)r++;
		if(st[cur]<a)st[++cur]=a;
	}
	printf("%d\n",r+cur);
	exit(0);
}

Measured memory_bytes: 1372
#include<cstdio>
#define ll long long
#define mod 1000000007ll
struct Edge{
    int to,nex;
}edge[3000010];
int c[200010],head[200010],pos[200010],cnt[200010],tot;
ll w[200010],fac[200010],rfac[200010],min[200010];
bool v[200010];
ll pow(ll a,ll b){
    ll ans=1,base=a;
    while(b){
        if(b&1)ans=(ans*base)%mod;
        base=(base*base)%mod;
        b>>=1;
    }
    return ans;
}
ll C(ll n,ll k){
    return(((fac[n]*rfac[n-k])%mod)*rfac[k])%mod;
}
void add(int a,int b){
    tot++;
    edge[tot].to=b;
    edge[tot].nex=head[a];
    head[a]=tot;
}
void dfs(int x){
    v[x]=1;
    for(int i=head[x];i;i=edge[i].nex){
        if(!v[edge[i].to])dfs(edge[i].to);
    }
}
int main(){
    int n,i,fir,sec=0;
    ll X,Y,min1,min2,tot,ans;
    scanf("%d%lld%lld",&n,&X,&Y);
    fac[0]=1;
    for(i=1;i<=n;i++){
        scanf("%d%lld",c+i,w+i);
        fac[i]=(i*fac[i-1])%mod;
        min[i]=2147483647;
    }
    rfac[n]=pow(fac[n],mod-2);
    for(i=n;i>0;i--)rfac[i-1]=(i*rfac[i])%mod;
    for(i=1;i<=n;i++){
        if(w[i]<min[c[i]]){
            min[c[i]]=w[i];
            pos[c[i]]=i;
        }
    }
    for(i=1;i<=n;i++){
        if(i!=pos[c[i]]&&w[i]+min[c[i]]<=X){
            add(i,pos[c[i]]);
            add(pos[c[i]],i);
        }
    }
    min1=min2=2147483647;
    for(i=1;i<=n;i++){
        if(w[i]<min1){
            min1=w[i];
            fir=i;
        }
    }
    for(i=1;i<=n;i++){
        if(w[i]<=min2&&c[i]!=c[fir]){
            min2=w[i];
            sec=i;
        }
    }
    for(i=1;i<=n;i++){
        if(i==fir)continue;
        if(c[i]!=c[fir]&&w[i]+w[fir]<=Y){
            add(i,fir);
            add(fir,i);
        }
        if(sec&&c[i]!=c[sec]&&w[i]+w[sec]<=Y){
            add(i,sec);
            add(sec,i);
        }
    }
    dfs(fir);
    tot=0;
    for(i=1;i<=n;i++){
        if(v[i]){
            tot++;
            cnt[c[i]]++;
        }
    }
    ans=1;
    for(i=1;i<=n;i++){
        if(cnt[i]){
            ans=(ans*C(tot,cnt[i]))%mod;
            tot-=cnt[i];
        }
    }
    printf("%lld",ans);
}

Measured memory_bytes: 16640
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N, K ,M;
  cin >> N >> K;
  M=1;
  int A, B;
  for (int i=0;i<N;i++){
    A=M*2;
    B=M+K;
    if(A<=B){
      M=A;
    }
    if(A>B){
      M=B;
    }
  }
  cout << M << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    int b = sc.nextInt();

    if (b % a == 0) {
      System.out.println(a + b);
    }else {
      System.out.println(b-a);
    }
  }
}

Measured memory_bytes: 21716
#include <bits/stdc++.h>
using namespace std;
int main () {
  vector<int> agroup{1,3,5,7,8,10,12}, bgroup{2};
  int x, y;
  cin >> x >> y;
  for(int a: agroup){
    if(a == x) x = 21;
    if(a == y) y = 21;
  }
  for(int a: bgroup){
    if(a == x) x = 22;
    if(a == y) y = 22;
  }
  if(x < 20) x = 23;
  if(y < 20) y = 23;
  if(x == y)cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
using vll = V<ll>;
using vvll = V<vll>;
#define rep(i, k, n) for (ll i=k; i<(ll)n; ++i)
#define REP(i, n) rep(i, 0, n)

const ll MOD = (ll)1e9 + 7;
const ll HIGHINF = (ll)1e18;

ll n;
vll a(2000000);

int main() {
  cin >> n;
  REP(i, n) cin >> a.at(i);
  vll count(10001, 0);
  REP(i, n) {
    count.at(a.at(i))++;
  }
  rep(i, 1, count.size()) {
    count.at(i) += count.at(i-1);
  }
  vll b(n);
  for (ll i=n-1; i>=0; i--) {
    b.at(count.at(a.at(i))-1) = a.at(i);
    count.at(a.at(i))--;
  }
  REP(i, n) {
    cout << b.at(i);
    if (i != n-1) cout << ' ';
  }
  cout << endl;
  return 0;
}



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

int main()
{
	int n, k; cin >> n >> k;
	int h[n], cnt = 0;
	for (int i = 0; i < n; i++) {
		cin >> h[i];
		if (h[i] >= k) cnt++;
	}
	
	cout << cnt << endl;

	return 0;
}

Measured memory_bytes: 640
import collections
n = int(input())
x = input()

num_of_one = x.count("1")

#xの中に1が1つもない時
if num_of_one == 0:
    for i in range(n):
        print(1)
#xの中に1が1つの時(1を取り除くと0個になる)
elif num_of_one == 1:
    for i in range(n):
        if x[i] == "1":
            print(0)
        else:
            #1が2個なので偶数なら余り0
            if x[-1] == "0" and i != n-1:
                print(1)
            #奇数なら1回1を経由
            else:
                print(2)
else:
    dic = collections.defaultdict(int)
    #0からnまでの回数を予め求めて辞書に格納
    for i in range(n):
        tmp_p = i

        cnt = 0
        while tmp_p:
            tmp_p %= bin(tmp_p).count("1")
            cnt += 1
        dic[i] = cnt


    #2冪を num_of_one ± 1 で割った余りの配列を用意しておく
    bi_mod_p = [1 % (num_of_one+1)]
    bi_mod_m = [1 % (num_of_one-1)]
    for i in range(1,n):
        bi_mod_p.append((bi_mod_p[-1] * 2) % (num_of_one+1))
        bi_mod_m.append((bi_mod_m[-1] * 2) % (num_of_one-1))

    #xと逆順なので合わせる
    bi_mod_p.reverse()
    bi_mod_m.reverse()

    #xの10進表記を num_of_one ± 1 で割った余りを用意する
    sum_p = 0
    sum_m = 0
    for i in range(n):
        if x[i] == "1":
            sum_p += bi_mod_p[i]
            sum_p %= (num_of_one+1)
            sum_m += bi_mod_m[i]
            sum_m %= (num_of_one-1)
    tmp = 0
    for i in range(n):
        # 0 -> 1 の変化。1が増えるのでpの方を使う
        if x[i] == "0":
            tmp = sum_p + bi_mod_p[i]
            tmp %= (num_of_one+1)

        # 1 -> 0 の変化。1が減るのでmの方を使う
        else:
            tmp = sum_m - bi_mod_m[i]
            if tmp < 0:
                tmp += (num_of_one-1)
            tmp %= (num_of_one-1)
        print(dic[tmp]+1)


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

visit = [-1]*(N+1)
history = []
v, cnt = 1, 0
while visit[v] == -1:
  visit[v] = cnt
  history.append(v)
  v = A[v-1]
  cnt += 1
period = cnt - visit[v]
l = visit[v]

if K < l:
  print(history[K])
else:
  K -= l
  K %= period
  print(history[l+K])

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

#define ll long long int
#define ld long double
#define reps(i,f,n) for(int i=f;i<n;i++)
#define rep(i,n) reps(i,0,n)
#define m1 cout<<"move1"<<endl
#define m2 cout<<"move2"<<endl
#define m3 cout<<"move3"<<endl
#define m4 cout<<"move4"<<endl


int main(){
  ll N;
  char v[5];
  ll sum =0;

  cin>>N;

  rep(i,N){
    scanf("%s",v);
    // cout<<v<<endl;

    if(v[0] == 'A') sum++;
    if(v[0] == 'U') sum--;
    if( sum < 0){
      cout<<"NO"<<endl;
      return 0;
    }
    //cout<<'#'<<sum<<endl;
  }
  if( sum == 0){
    cout<<"YES"<<endl;
  }
  else{
    cout<<"NO"<<endl;
  }
  return 0;
}

      

Measured memory_bytes: 3160
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <cstring>
#include <vector>
#include <iostream>
#include <queue>
#include <unordered_map>
#include <cmath>
#include <queue>
#include <string>
#include <random>
#include <stack>
#include <set>
#include <unordered_set>

#define bug(x) cout<<"zdongdebug: "<<x<<endl;
#define bug2(x, y) cout<<"zdongdebug: "<<x<<" "<<y<<endl;
using namespace std;
typedef long long ll;
const int maxn = 200005;
const int maxxx = 1000000009;

struct ST{
  int l,r,val;
}st[maxn * 3 * 4];
void build(int id, int l, int r) {
  st[id].l=l,st[id].r=r,st[id].val=maxxx;
  if(l==r){
    return;
  }
  int m=(l+r)>>1;
  build(id<<1,l,m);
  build(id<<1|1,m+1,r);
}
void down(int id){
  st[id<<1].val=min(st[id<<1].val,st[id].val);
  st[id<<1|1].val=min(st[id<<1|1].val,st[id].val);
  st[id].val=maxxx;
}
void update(int id,int l,int r,int val){
  if(st[id].l==l&&st[id].r==r){
    st[id].val=min(st[id].val,val);
    return;
  }
  down(id);
  int m = (st[id].l+st[id].r)>>1;
  if(r<=m)update(id<<1,l,r,val);
  else if(l>m)update(id<<1|1,l,r,val);
  else {
    update(id<<1,l,m,val);
    update(id<<1|1,m+1,r,val);
  }
}
int query(int id,int pos){
  if(st[id].l==st[id].r)return st[id].val;
  down(id);
  int m = (st[id].l+st[id].r)>>1;
  if(pos<=m)return query(id<<1,pos);
  return query(id<<1|1,pos);
}

int n,m;
int s[maxn],t[maxn],x[maxn],q[maxn];
int main() {
#ifdef suiyuan2009
  freopen("/Users/suiyuan2009/CLionProjects/icpc/input.txt", "r", stdin);
#endif
  cin>>n>>m;
  vector<int>v;
  for(int i=0;i<n;i++){
    cin>>s[i]>>t[i]>>x[i];
    v.push_back(s[i]-x[i]);
    v.push_back(t[i]-1-x[i]);
  }
  for(int i=0;i<m;i++){
    cin>>q[i];
    v.push_back(q[i]);
  }
  sort(v.begin(),v.end());
  v.erase(unique(v.begin(),v.end()),v.end());
  int sz = v.size();
  build(1,1,sz);
  for(int i=0;i<n;i++){
    int l = lower_bound(v.begin(),v.end(),s[i]-x[i])-v.begin()+1;
    int r = lower_bound(v.begin(),v.end(),t[i]-1-x[i])-v.begin()+1;
    update(1,l,r,x[i]);
  }
  for(int i=0;i<m;i++){
    int pos = lower_bound(v.begin(),v.end(),q[i])-v.begin()+1;
    int tt = query(1,pos);
    if(tt==maxxx)cout<<-1<<endl;
    else cout<<tt<<endl;
  }
  return 0;
}

Measured memory_bytes: 33644
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define mp make_pair
#define pb push_back
#define scanVec(vec , n) for(int i = 0; i < n ; i++){ cin>>vec[i];}
#define printVec(vec , n) for(int i = 0; i < n ; i++){ cout<<vec[i]<<" ";}
#define S second
#define F first
const int  MOD = 1e9 + 7;
const int M = 55;
struct matrix
{
  long m[M][M];
  matrix(){
    memset(m,0,sizeof(m));
  }
};
matrix Multiply(matrix a,matrix b,int n){
  matrix c;
  for(int i = 1;i <= n;i++)
    for(int j = 1;j <= n;j++)
      for(int k = 1;k <= n;k++)
        c.m[i][j] = (c.m[i][j] + a.m[i][k] * b.m[k][j]) %MOD;
  return c;
}
matrix Expo(long x,matrix b,int n){
  matrix r;//if(x<0)assert(0);
  for(int i=1;i<=n;i++)r.m[i][i]=1;
  while(x){
    if( x & 1)r = Multiply(r,b,n);
    b=Multiply(b,b,n);x/=2;
  }
  return r;
}


//  a d f j k  l  ;
int main(){
    ios::sync_with_stdio(0);  cin.tie(0);
    int n;
    long k;
    cin>>n>>k;
    matrix b;
    for(int i = 1;i <= n;i++){
        for(int j = 1;j <= n;j++){
            cin>>b.m[i][j];
        }
    }
    b = Expo(k,b,n);long ans=0;
    for(int i=1;i<=n;i++){
        for(int j=1;j<=n;j++){
            ans = (ans + b.m[i][j])%MOD;
        }
    }
    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 512
#include <cstdio>
#include <cmath>
#include <iostream>
#include <queue>
using namespace std;

int main() {
    int n, i;
    priority_queue<int> que;
    cin >> n;
    for (i = 2; i <= 10; i++){
        for (int j = 1; pow(j, i)<= n; j++) {
           que.push(pow(j, i)); 
        }
    }
    cout << que.top()<< endl;
    return 0;
}


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

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

int main(){
  string s;
  cin>>s;
  int a=s.length();
  rep(i,a){
    cout<<"x"<<flush;
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define sd(x) scanf("%lld",&x)
#define slld(x) scanf("%lld",&x)
#define ss(x) scanf("%s",x)
#define mod 1000000007
#define bitcount __builtin_popcountll
#define ll long long
#define pb push_back
#define pi pair<ll,ll>
#define pii pair<pi,ll>
#define mp make_pair
vector<ll>v;
int main()
{
	ll i,j,k;
	ll n;
	sd(n);
	for(i=1;i<=n;i++)
	{
		sd(j);
		v.pb(j);
	}
	reverse(v.begin(), v.end());
	if(v[0]!=2)
	{
		printf("-1\n");
		return 0;
	}
	ll mini=2,maxi=3;
	for(i=1;i<v.size();i++)
	{
		mini=(mini/v[i])*v[i] + (mini%v[i] == 0 ? 0 : 1 )*v[i];
		maxi=(maxi/v[i])*v[i] + v[i]-1;
		// prllf("%d %d\n",mini,maxi );
	}
	if(mini>maxi)
		printf("-1\n");
	else
		printf("%lld %lld\n", mini,maxi);
	return 0;
}

Measured memory_bytes: 1528