akhauriyash/Code-Regression huggingface dataset:
/*** keep hungry and calm CoolGuang!***/
#pragma GCC optimize(2)
#include <bits/stdc++.h>
#include<stdio.h>
#include<queue>
#include<algorithm>
#include<string.h>
#include<iostream>
#define debug(x) cout<<#x<<":"<<x<<endl;
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pp;
const ll INF=1e16;
const int maxn=2e6+6;
const int mod=1000000007;
const double eps=1e-3;
inline bool read(ll &num)
{char in;bool IsN=false;
in=getchar();if(in==EOF) return false;while(in!='-'&&(in<'0'||in>'9')) in=getchar();if(in=='-'){ IsN=true;num=0;}else num=in-'0';while(in=getchar(),in>='0'&&in<='9'){num*=10,num+=in-'0';}if(IsN) num=-num;return true;}
ll n,m,p;
struct dsu{int pre[maxn];void inint(){for(int i=1;i<=n;i++) pre[i]=i;}int Find(int x){return x==pre[x]?x:pre[x]=Find(pre[x]);}void Merge(int x,int y){int dx=Find(x),dy=Find(y);if(dx!=dy) pre[dx]=dy;}};
ll num[maxn];
int a[maxn];
map<ll,int>mp;
int main()
{
    read(n);read(m);
    mp[n]=1;
    ll ans=INF;
    while(1){
        ll temp=n/m;
        if(temp)ans=min(n-temp*m,ans);
        n=abs(n-(temp+1)*m);
        ans=min(ans,n);
        if(mp[n]) break;
        mp[n]=1;
    }printf("%lld\n",ans);
    return 0;
}
/***
6
0 0 0 0 0 0
0 2 3 1
0 3 4 1
0 1 5 1
1 0 1 0
1 0 2 0
1 0 4 0
***/


Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<string.h>
#include<math.h>
#include<cstring>
using namespace std;
#define INF 10000000
int mini(int a,int b){
	if(a<b){
		return a;
	}else{
		return b;
	}
}
int maxim(int a,int b){
	if(a>b){
		return a;
	}else{
		return b;
	}
}
int saidai(int m/**/,int b/*難易度*/){
	int a=0;
	while(a<=m){
		a+=b;
	}
	a-=b;
	return a;
}
int saishou(int m,int tan,int i,int a[],int b[]){
	int d; 
	d=a[i];
	while(d<=m){
		if(b[tan]==d&&a[tan]<=a[i])return d;
		if(b[tan]<d)return d;
		d+=a[i];
	}
	return 0;
}

int main(){
	while(1){
		int n,m,i,j,a[1001]/*難易度*/,b[1001]/*申請*/,tan,c;
		cin>>n>>m;
		if(n==0&&m==0)break;
		for(i=0;i<1001;i++){a[i]=0;b[i]=0;}
		for(i=0;i<n;i++){
			cin>>a[i];
			if(i==0){
				b[i]=saidai(m,a[i]);
				tan=i;
			}else{
				b[i]=saishou(m,tan,i,a,b);
				if(b[i]==0){
					b[i]=saidai(m,a[i]);
					tan=i;
				}
			}
		}
		c=0;
		for(i=0;i<n;i++){
			if(a[i]==a[tan]&&b[i]==b[tan])c++;
		}
		if(c>=2){tan=n-1;}
		cout<<tan+1<<endl;
	}
    return 0;
}

Measured memory_bytes: 1168
def solve(a, b, c, k):
    point = min(a, k)
    more = k - a
    if more > 0:
        more -= b
    if more > 0:
        point -= more

    print(point)

a, b, c, k = map(int, open(0).read().split())
solve(a, b, c, k)

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

int main()
{
    int n;
    cin>>n;
    int arr[n+5];
    for(int i=0;i<n;i++)cin>>arr[i];
    sort(arr,arr+n);
    int ans=1e8;

    for(int i=arr[0];i<=arr[n-1];i++)
    {
        int k=i;
        int sta=0;
        for(int j=0;j<n;j++)
        {
            sta+=((abs(arr[j]-k))*(abs(arr[j]-k)));
        }
        ans=min(ans,sta);
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
constexpr long long INFL = 1LL << 60;
constexpr int INF = 1e9;

using namespace std;

typedef long long ll;

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

    int ope[3];
    for(int i = 0; i < (1<<3); ++i){
        int res = s[0] - '0';
        for(int j = 0; j < 3; ++j){
            if(i&(1<<j)){
                res += s[j+1] - '0';
                ope[j] = 1;
            } else{
                res -= s[j+1] - '0';
                ope[j] = 2;
            }
        }
        if(res == 7){
            cout << s[0];
            for(int j = 0; j < 3; ++j){
                if(ope[j] == 1)
                    cout << "+" << s[j+1] - '0';
                else
                    cout << "-" << s[j+1] - '0';

            }
            cout << "=7" << endl;
            return 0;
        }
    }

    return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
using ll = long long; using ull = unsigned long long;
#define int ll
using vb = vector<bool>; using vvb = vector<vb>;
using vi = vector<int>; using vvi = vector<vi>;
using vl = vector<ll>; using vvl = vector<vl>;
using pii = pair<int,int>; using pll = pair<ll,ll>;
#define FOR(i,a,b) for(ll i = (a); i < (ll)(b); ++i)
#define REP(i,n) FOR(i,0,n)
#define RFOR(i,a,b) for(ll i = (ll)(b)-1;i >= a;--i)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define eb(val) emplace_back(val)
const double PI = acos(-1);
const double EPS = 1e-10;
const ll MOD = 1e9+7;
void cioacc(){//accelerate cin/cout
  cin.tie(0);
  ios::sync_with_stdio(false);
}
template<typename T>
struct union_find{//rank,経路圧縮で高速化
  vector<T> data;//そのノードがrootであれば-（集合のサイズ）を表し、そうでなければ親ノードidを示す。
  union_find(T size):data(size,-1){}//コンストラクタ,size個のノードを作成し、-1で初期化
  T root(T a){//根を探す,経路圧縮
    return data[a] < 0 ? a : data[a]=root(data[a]);
  }
  bool find(T a,T b){//a,bが同じ集合に属するか調べる
    return root(a) == root(b);
  }
  bool unite(T a,T b){//小さい方の木の根に大きい方の根を上書きする
    a = root(a),b = root(b);
    if(a==b) return false;//根が同じなら終了,uniteが失敗したことを出力
    if(data[a]<data[b]) swap(a,b); //集合サイズの大きい方の根に低い方の根をつける
    data[b] += data[a];//集合サイズを統合
    data[a] = b;//bの親にaをつける
    return true;//unite成功を出力
  }
  T size(T a){//aが属する集合のサイズを出力
    return -data[root(a)];
  }
};

signed main(){
  int n,m;
  cin >> n >> m;
  vi a(m),b(m);
  REP(i,m) cin >> a.at(i) >> b.at(i);
  vl ans(m);
  ans.at(m-1) = n*(n-1)/2;
  union_find<ll> uf(n+1);
  RFOR(i,1,m){
    if(uf.find(a.at(i),b.at(i))){
      ans.at(i-1) = ans.at(i);
      continue;
    }
    ans.at(i-1) = ans.at(i) - uf.size(a.at(i))*uf.size(b.at(i));
    uf.unite(a.at(i),b.at(i));
  }
  for(auto i:ans){
    cout << i << endl;
  }
}



Measured memory_bytes: 4480
import java.util.*;

public class Main {

    public static void main(String[] args) {
        //
        //Euclid e1=new Euclid();//ユークリッドの互除法
        //Compute c1=new Compute();//累積和，
        //変数
        int count = 0;
        boolean sw = false;
        int max = Integer.MIN_VALUE;
        int min = Integer.MAX_VALUE;
        double dMax = Double.MIN_VALUE;
        double dMin = Double.MAX_VALUE;
        int answer = 0;
        //String answer="Yes";
        //StringBuilder answer=new StringBuilder();
        //List<Integer> list = new ArrayList<>();
        //int array[] = new int[];

        //入力
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int X = sc.nextInt();
        int L[] =new int[N];
        for(int i=0;i<N;i++)
        {
            L[i]=sc.nextInt();
        }
        int D=0;
        count++;
        for (int i=0;i<N;i++)
        {
            //System.out.println(D);
            //System.out.println(L[i]);
            int a=D+L[i];
            if(a<=X)
            {
                count++;
            }
            D=a;
            //System.out.println(a);
            //System.out.println("-------------");
        }
        answer=count;
        //出力
        //BigDecimal bd = new BigDecimal(answer);
        //System.out.println(bd.setScale(12,BigDecimal.ROUND_DOWN));
        //System.out.println(String.format("%.0f",answer));
        System.out.println(answer);
    }
}

Measured memory_bytes: 21972
Sx, Sy, Tx, Ty = map(int, input().split())

Dx = Tx - Sx
Dy = Ty - Sy

g1 = ['U'] * Dy + ['R'] * Dx
g = ''.join(g1)

r1 = ['D'] * Dy + ['L'] * Dx
r = ''.join(r1)

print('{}{}LU{}RDRD{}LU'.format(g, r, g, r))


Measured memory_bytes: 3060
#include<iostream>
#define rep(i,n) for(int i=0;i<(n);i++)
#define lrep(i,n) for(long int i=0;i<(n);i++)
using namespace std;
int main(){
	int n;
	cin >>n;
	char c[n+2];
	rep(i,n)cin >>c[i+1];
	c[0]='R';
	c[n+1]='W';
	int right=1,left=n,count=0;
	while(right<left){
		while(c[right]=='R')right++;
		while(c[left]=='W')left--;
		c[right]='R';
		c[left]='W';
		count++;
	}
	count--;
	cout<<count;
	return 0;
}

Measured memory_bytes: 3744
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int N=200050;
int gi(){
    char ch=getchar(); int x=0,q=0;
    while(ch<'0'||ch>'9') q=ch=='-'?1:q,ch=getchar();
    while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
    return q?-x:x;
}
int b[N],a[N],x[N]; ll ans;
int main(){
    int n=gi();
    for (int i=1; i<=n; ++i) a[i]=gi()-i,x[i]=-i;
    if (a[1]!=-1){
	cout<<"-1"; return 0;
    }
    for (int i=1; i<=n; ++i) b[i]=i;
    for (int i=1; i<=n; ++i){
	if (a[i]>=0||a[i]>a[i-1]||-a[i]>i){
	    cout<<"-1"; return 0;
	}
	b[-a[i]]=max(b[-a[i]],i);
    }
    for (int i=1; i<=n; ++i)
	ans+=b[i]-i;
    cout<<ans;
    return 0;
}


Measured memory_bytes: 2688
s = input()[::-1]
d = {'maerd', 'remaerd', 'esare', 'resare'}

cnt = 0
while cnt < len(s):
    if s[cnt:cnt + 5] in d:
        cnt += 5
    elif s[cnt:cnt + 6] in d:
        cnt += 6
    elif s[cnt:cnt + 7] in d:
        cnt += 7
    else:
        print('NO')
        break
else:
    print('YES')


Measured memory_bytes: 9204
#include <iostream>
using namespace std;
int main(void){
    
    string S;
    cin >> S;
    int n = S.size();
    
    if(n == 1){
        cout << "No" << endl;
        return 0;
    }
    
    
    else {
        n /= 2;
        string sub_S = "";
        
        while(n--){
            sub_S += "hi";
        }
        
        if(sub_S == S){
            cout << "Yes" << endl;
        }
        
        else{
            cout << "No" << endl;
        }
    }
    
    
}


Measured memory_bytes: 256
import java.util.*;
 
class Main {
    public static void main(String[] args) {
      
        Scanner sc = new Scanner(System.in);
        int W = sc.nextInt();
        int a = sc.nextInt();
      	int b = sc.nextInt();
        int min = 0;
      
      if(b>=a&&b<=a+W){System.out.print(0);}
      else if(b+W>=a&&b+W<=a+W){System.out.print(0);}
      else{
      	min = Math.abs(a-(b+W));
        min = Math.min(min,Math.abs(b-(a+W)));
        System.out.print(min);
      }

    }
      

}

Measured memory_bytes: 21844
use std::io;
use std::io::BufRead;
use std::io::BufReader;

fn main() {
    let reader = io::stdin();
    let mut reader = BufReader::new(reader.lock());

    let mut s = String::new();
    let _ = reader.read_line(&mut s);
    let v: Vec<u32> = s.split_whitespace().map(|x| x.parse().unwrap()).collect();

    if v[0] % 2 == 1 && v[1] % 2 == 1 {
        println!("{}", "Yes");
    } else {
        println!("{}", "No");
    }
}

Measured memory_bytes: 4352
# -*- coding: utf-8 -*-

s = input().split()
n = int(s[0])
m = int(s[1])
d = int(s[2])

if d==0:
    print(1.0*n*(m-1)/n/n)
else:
    print(2.0*(n-d)*(m-1)/n/n)

Measured memory_bytes: 38384
#include <bits/stdc++.h>
#define INF (1LL<<50)
using namespace std;
typedef long long ll;

int main(){
  int n,m;
  cin>>n>>m;
  vector <ll> s,t,p,P;
  s.resize(n),t.resize(n),p.resize(m+2),P.resize(m+2);
  for(int i=0;i<n;i++) cin>>s[i]>>t[i];
  for(int i=1;i<=m;i++) cin>>p[i];
  P[0]=p[0]=0,p[m+1]=P[m+1]=(INF);
  sort(p.begin(),p.end());
  for(int i=1;i<m+2;i++)P[i]=p[i]-p[i-1];
  for(int i=2;i<m+1;i+=2)P[i]+=P[i-2],P[i+1]+=P[i-1];
  
  ll sum=0; 
  for(int i=0;i<n;i++){
    vector <ll> :: iterator it1=p.begin(),it2=p.end();
    int idx2=upper_bound(it1,it2,s[i])-it1,idx1=idx2-1;
    int idx4=upper_bound(it1,it2,t[i])-it1,idx3=idx4-1;
    int f;

    if(idx2==idx4)sum+=abs(t[i]-s[i]);
    else if(s[i]<t[i]){
      sum+=(p[idx2]-s[i]);
      if(p[idx2]>s[i])idx2++;
      f=idx2%2==idx3%2;
      sum+=P[idx3-f]-P[idx2-1]+f*(t[i]-p[idx3]);
    } 
    else{
      sum+=(s[i]-p[idx1]);
      if(p[idx1]<s[i])idx1--;
      f=idx1%2==idx4%2;
      sum+=P[idx1]-P[idx4-!f]+f*(p[idx4]-t[i]);
    }
  }
  cout <<sum<<endl;
  
  return 0;
}

Measured memory_bytes: 4176
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pi 3.141592653589793238
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define MOD 1000000007
int main(){
	fast;
	string s;
	cin>>s;
	ll cnt=0;
	for(int i=1;i<s.length();i++)
		if(s[i]!=s[i-1])
			cnt++;
	cout<<cnt;
	return 0;
}



Measured memory_bytes: 3764
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;

int main() {
	ll a;
	double b;
	cin >> a >> b;
	ll B = b * 100 + 0.00000001;
	//ll ans = a * b+0.000001;
   //ll B = b;
	cout << a * B/100 << endl;
	return 0;
}


Measured memory_bytes: 3728
#include<cstdio>
#include<vector>
#include<algorithm>
#include<queue>
#include<set>

using namespace std;

using ll=long long;
using vi=vector<int>;
using vvi=vector<vi>;
using pii=pair<int,int>;
using vll=vector<ll>;
using vvll=vector<vll>;
using vpii=vector<pii>;


#define T_INF (1LL<<62)


void min_u(ll&m, ll v)
{
	if(m>v) m=v;
}


struct q_t
{
	ll t, s;
	int p;
	ll flags;
	ll trans_count;
	q_t(int n=0) : t(T_INF), s(-1), p(-1), flags(0), trans_count(-1) {
	}
	bool operator<(const q_t& rhs) const
	{
//		if(t!=rhs.t) return t>rhs.t;
//		return s<rhs.s;
		return t>rhs.t;
	}
};


struct edge_t
{
	int v;
	ll cs, ct;
};


bool min_qu(q_t&m, q_t&v)
{
	if(m.t>v.t) m=v;
	return true;
}


priority_queue<q_t> que;


void push(q_t q)
{
	que.push(q);
}


int pop(q_t& q)
{
	if(que.empty()) return 0;
	q=que.top();
	que.pop();
	return 1;
}


int solve(vector<q_t>&ans, ll s, vector<vector<edge_t> >&e, vector<edge_t>&mt)
{
	int n=ans.size()-1;
	q_t q(n);
	int rest=n;
	vector<set<ll> > mb(n+1);
	vector<vector<ll> > v(n+1);
	ll amax=0;
	for(auto&me:e) for(auto&mme:me) amax=max(amax, mme.cs);
	ll s_max=amax*(n-1);
	for(auto&mv:v) mv.assign(s_max+1, T_INF);

	{
		priority_queue<q_t> t;
		que=t;
	}

	q.t=0;
	q.s=min(s, s_max);
	q.p=1;
	q.trans_count=0;
	q.flags|=1<<1;
	mb[1].insert(q.flags);

	push(q);
	while(pop(q))
	{
		auto&mv=v[q.p];
		if(mv[q.s]<=q.t) continue;
		for(int i=q.s;i>=0 && mv[i]>q.t;i--) mv[i]=q.t;

		if(ans[q.p].t==T_INF)
		{
			rest--;
		}
		min_qu(ans[q.p], q);
		if(rest<=0) break;

		for(auto&me:e[q.p])
		{
			q_t nq=q;
			nq.p=me.v;
			nq.t=q.t+me.ct;
			nq.s=q.s-me.cs;
			if(nq.s>=0)
			{
				push(nq);
			}
		}
		{
			auto&mmt=mt[q.p];
			q_t nq=q;
			nq.t=q.t+mmt.ct;
			nq.s=min(q.s+mmt.cs, s_max);
			push(nq);
		}
	}
	return 1;
}


int main(void)
{
	int n, m, s;

	while(scanf("%d%d%d", &n, &m, &s)==3)
	{
		vector<q_t> ans(n+1, q_t(n));
		vector<vector<edge_t>> e(n+1);
		vector<edge_t> mt(n+1);

		for(int i=0;i<m;i++)
		{
			int u, v, a, b;
			edge_t t;

			scanf("%d%d%d%d", &u, &v, &a, &b);
			t.cs=a;
			t.ct=b;
			t.v=v;
			e[u].push_back(t);
			t.v=u;
			e[v].push_back(t);
		}

		for(int i=1;i<=n;i++)
		{
			int a, b;
			edge_t&t=mt[i];

			scanf("%d%d", &a, &b);
			t.v=i;
			t.cs=a;
			t.ct=b;
		}

		solve(ans, s, e, mt);

		for(int i=2;i<=n;i++)
		{
//			printf("t=%lld  trans_count=%lld\n", ans[i].t, ans[i].trans_count);
			printf("%lld\n", ans[i].t);
		}
	}
	return 0;
}


Measured memory_bytes: 4428
#include <bits/stdc++.h>
//----***やべーやつら***----
using namespace std;
#define int long long

//----***型定義***----
using ll = long long;
using P = pair<int,int>;

//----***Like a Pythonista***----
#define REP(ii,jj,nn) for (ll ii=jj;ii<(nn);ii++)
#define RREP(ii,nn,jj) for (ll ii = nn; jj<ii;ii--)
#define each(i,...) for (auto&& i:__VA_ARGS__)
#define ALL(vec) (vec).begin(),(vec).end()
#define sum(...) accumulate(ALL(__VA_ARGS__),0LL)
#define dsum(...) accumulate(ALL(__VA_ARGS__),0.0)
#define vec(type,name,...) vector<type> name(__VA_ARGS__)
template<class T> inline auto max(const T& a){ return *max_element(ALL(a)); }
template<class T> inline auto min(const T& a){ return *min_element(ALL(a)); }
inline ll gcd(ll a,ll b){if(b == 0) return a;return  gcd(b,a%b);}
inline ll lcm(ll a,ll b){ll g = gcd(a,b);return a / g * b;}

//----***定数***----
#define MOD 1000000007
#define INF 100000000000000000
#define EPS 1e-9
#define PI  acos(-1)
const vector<vector<int>> DXY={{-1,0},{1,0},{0,-1},{0,1}};

//----***パーツ***----
#define fi first
#define se second
#define pb push_back
#define re return
#define br break

//----***入出力***---
void print() { std::cout << "\n"; }
template <class T>void print(const T &x) {std::cout << x<<"\n";}
template <class T, class... Args>void print(const T &x, const Args &... args) {std::cout << x << " ";print(args...);}
#define debug(var)  do{std::cerr << #var << " ↓ "<<"\n";view(var);}while(0);
#define dbg cerr<<"🥺🥺🥺🥺🥺🥺"<<endl;
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ view(v); } }

//----***初期時読み込み***----
struct initial{initial(){cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(15);};}initial_;

signed main(){
  int N;cin>>N;
  string S;cin>>S;
  string ans=S;
  vector<int> left(N,0),right(N,0);
  left[0]=(S.at(0)=='('?1:-1);
  if(left[0]==-1){
    ans='('+ans;
    left[0]=0;
    }
  REP(i,1,N){
    left[i]=left[i-1]+(S.at(i)=='('?1:-1);
    if(left[i]<0){
      ans='('+ans;
      left[i]++;
    }
  }

  right[N-1]=(S.at(N-1)==')'?1:-1);
  if(right[N-1]==-1){
    ans=ans+')';
    right[N-1]=0;
  }
  RREP(i,N-2,-1){
    right[i]=right[i+1]+(S.at(i)==')'?1:-1);
    if(right[i]<0){
      ans=ans+')';
      // print(ans,i);
      right[i]++;
    }
  }
  print(ans);
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <iomanip>
#include <cmath>
#include <stack>
using namespace std;
typedef long long ll;
ll f[5];
int main()
{
    ll n;
    cin >> n;
    for(int i=0;i<5;i++)
        cin >> f[i];
    ll s;
    sort(f,f+5);
    if(n%f[0]!=0)
        cout << n/f[0]+5;
    else
        cout << n/f[0]+4;
    return 0;
}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)

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

SUM=[0]*(N+1)
for i in range(N-1,-1,-1):
    SUM[i]=SUM[i+1]

    if (N-i)%2==1:
        SUM[i]+=A[i]

#print(SUM)

ADICT=dict()

def calc(i,select):
    if ADICT.get((i,select))!=None:
        return ADICT.get((i,select))
    rest=N-i

    if rest==0 or select==0:
        ADICT[(i,select)]=0
        return 0

    if rest%2==1 and rest//2+1==select:
        ADICT[(i,select)]=SUM[i]
        return SUM[i]
    
    elif rest%2==0 and rest//2==select:
        ADICT[(i,select)]=max(calc(i+1,select),A[i]+calc(i+2,select-1))
        return ADICT[(i,select)]

    elif rest%2==1 and rest//2==select:
        ADICT[(i,select)]=max(calc(i+1,select),A[i]+calc(i+2,select-1))
        return ADICT[(i,select)]

print(calc(0,N//2))

    


Measured memory_bytes: 270468
#include <iostream>
#include <algorithm>

using namespace std;

int main() {
	long long int A, B, N;
	cin >> N >> A >> B ;
	if((B - A)%2 == 0) {
	   	cout << (B - A)/2 << endl;
	} else {
		//cout << N - A << " " << B - 1 << endl;
		cout << min(N - B, A - 1) + (B - A + 1)/2  << endl;
	}
}


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

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

Measured memory_bytes: 3724
#include <bits/stdc++.h>
#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define REP(i, n) FOR(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define bit(x) (1L << (x))
using ll = long long;
using namespace std;

int main() {
  string s; cin >> s;
  int n = (int)s.length();

  vector<vector<vector<int>>> dp(n+1, vector<vector<int>>(2, vector<int>(32, 0)));

  function<int(int, int, int)> rec = [&](int k, int tight, int f){
    if(k == n) return (f == 0b1111)? 1: 0;
    if(dp[k][tight][f]) return dp[k][tight][f];

    int x = s[k] - '0';
    int r = tight? x: 9;

    int ret = 0;
    REP(i, r+1){
      int nf = f;
      switch (i){
        case 0: if(f >> 3) continue;
                break;
        case 3: nf |= bit(2);
                nf |= bit(3);
                break;
        case 5: nf |= bit(1);
                nf |= bit(3);
                break;
        case 7: nf |= bit(0);
                nf |= bit(3);
                break;
        default:  continue;
      }

      ret += rec(k+1, tight && i == x, nf);
    }

    return dp[k][tight][f] = ret;
  };
  
  cout << rec(0, 1, 0) << endl;
   
  return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#include<cstring>

using namespace std;
const int maxn=300010;
int ans=0,tot=0,sum[maxn],a[maxn],f[maxn],g[1<<26],n,l,r;
char s[maxn];
void read(int &k){
	k=0; int f=1; char c=getchar();
	while (c<'0'||c>'9')c=='-'&&(f=-1),c=getchar();
	while ('0'<=c&&c<='9')k=k*10+c-'0',c=getchar();
	k*=f;
}
int main(){
	scanf("%s",s+1);
	int n=strlen(s+1);
	for (int i=1;i<=n;i++) sum[i]=sum[i-1]^(1<<(s[i]-'a'));
	memset(f,32,sizeof(f)); memset(g,32,sizeof(g));
	g[0]=0;
	for (int i=1;i<=n;i++){
		f[i]=min(f[i],g[sum[i]]+1);
		for (int j=0;j<26;j++) f[i]=min(f[i],g[sum[i]^(1<<j)]+1);
		g[sum[i]]=min(g[sum[i]],f[i]);
	}
	printf("%d\n",f[n]);
	return 0;
}

Measured memory_bytes: 265088
#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 whole(f, x, ...) ([&](decltype((x)) whole) { return (f)(begin(whole), end(whole), ## __VA_ARGS__); })(x) // decltypeで型取得、引数があればva_argsのところに入れる
using namespace std;
typedef long long ll; // long longをllでかけるようにした
const int INF = 1e9;

int main(void){
    int n; cin >> n;
    bool ans = 0;
    for(int i = 0; i <= n; i += 4){
        for(int j = 0; j <= n - i; j += 7){
            if(i + j == n) ans = 1;
        }
    }
    cout << (ans ? "Yes" : "No") << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int x; cin >> x;
  int kosuu = x/100;
  int hasuu = x % 100;
 // cout << kosuu << " " << hasuu << endl;
  if(hasuu >  5 * kosuu)
    cout << 0;
  else
    cout << 1;
}
        
  


Measured memory_bytes: 3504
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define ALL(x) (x).begin(),(x).end()
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define INF 99999999999
#define PRINT(var) std::cout<<#var"= "<<var<<std::endl

using namespace std;
typedef long long  int ll;

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

ll n,m;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >>n>>m ;
  vector<string> s(n);
  vector<string> t(m);

  REP(i,n) cin >>s[i];
  REP(i,m) cin >>t[i];

  REP(i,n-m+1){
    REP(j,n-m+1){
      REP(k,m){
        if(s[i+k].substr(j,m)!=t[k]) break;

        if(k==m-1){
          cout <<"Yes" <<endl;
          return 0;
        }
      }
    }
  }
  cout <<"No"<<endl;
  return 0;
}

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

int main()
{
	string s;
	cin >> s;
	if (s[0] == '9' || s[1] == '9')
	{
		cout << "Yes" << endl;
	}
	else
	{
		cout << "No" << endl;
	}

	return 0;
}

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

const int maxn = 710;
bitset <maxn> adj[maxn];
int mark[maxn];
int sz = 0, cnt = 0;
int n;
vector <pair <int, int>> vec;
bitset <maxn> knap;

void dfs(int v){
	for (int u = 0; u < n; u++){
		if (u != v && adj[v][u]){
			if (!mark[u]){
				mark[u] = 3 - mark[v];
				if (mark[u] == 1)
					sz ++;
				cnt ++;
				dfs(u);
			}
			else{
				if (mark[v] == mark[u]){
					cout << -1;
					exit(0);
				}
			}
		}
	}
}

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int m;
	cin >> n >> m;
	for (int i = 0; i < m; i++){
		int v, u;
		cin >> v >> u;
		v --;
		u --;
		adj[v][u] = 1;
		adj[u][v] = 1;
	}
	for (int i = 0; i < n; i++)
		adj[i] = ~adj[i];
	for (int i = 0; i < n; i++){
		if (!mark[i]){
			sz = 1;
			cnt = 1;
			mark[i] = 1;
			dfs(i);
			vec.push_back({sz, cnt - sz});
		}
	}
	int k = vec.size();
	knap[0] = 1;
	for (int i = 0; i < k; i++){
		knap = (knap << vec[i].first) | (knap << vec[i].second);
	}
	int x = knap._Find_next((n - 1) / 2);
	cout << (x * (x - 1) + (n - x) * (n - x - 1)) / 2;
}

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

int main() {
    ll n;
    cin >> n;
    vector<ll> nums(n,0);
    for (ll i=0; i<n; i++) cin >> nums[i];
    ll maxim = nums[0];
    ll res = 0;
    for (ll i=1; i<n; i++) {
        res+=max(ll(0),maxim-nums[i]);
        maxim = max(maxim,nums[i]);
    }
    cout << res;
    return 0;
}

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

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

int main() {
	ll a, b, k;
	cin >> a >> b >> k;
	if (a < k) k -= a, a = 0;
	else a -= k, k = 0;
	if (b < k) k -= b, b = 0;
	else b -= k, k = 0;
	cout << a << " " << b << endl;
	return 0;
}

Measured memory_bytes: 3604
import java.io.*;

class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader reader =
            new BufferedReader(new InputStreamReader(System.in));

        String line = reader.readLine();
        int S = Integer.parseInt(line);
        if (S >= 0 && S < 86400) {
            int hour = S / 3600;
            S %= 3600;
            int minute = S / 60;
            int second = S % 60;
            System.out.println(hour + ":" + minute + ":" + second);
        }
    }
}

Measured memory_bytes: 24296
//! ----------------------------------------------
//! Framework <https://github.com/vain0x/procon>
//!
//! See the bottom of file for solution.
//! ----------------------------------------------

#![allow(unused_imports)]
#![allow(non_snake_case)]

use std::cell::RefCell;
use std::cmp::{max, min, Ordering};
use std::collections::*;
use std::fmt::{Debug, Display, Formatter, Write as FmtWrite};
use std::io::{stderr, stdin, BufRead, Write};
use std::mem::{replace, swap};
use std::ops::*;
use std::rc::Rc;

/// Print values to standard error if debug mode.
#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), stderr());
            writeln!(err, "\x1B[33m{}\x1B[0m = {:?}", e, $e).unwrap()
        })*
    };
}

/// Read from standard input and parse each word.
/// - `read!(T, U, ..)` parses a line as a tuple of words.
/// - `read![[T]]` parses a line as an array of words.
/// - `read![..; N]` parses `N` lines, using `read!(..)` repeatedly.
#[allow(unused_macros)]
macro_rules! read {
    ([$t:ty] ; $n:expr) =>
        ((0..$n).map(|_| read!([$t])).collect::<Vec<_>>());
    ($($t:ty),+ ; $n:expr) =>
        ((0..$n).map(|_| read!($($t),+)).collect::<Vec<_>>());
    ([$t:ty]) =>
        (rl().split_whitespace().map(|w| w.parse().unwrap()).collect::<Vec<$t>>());
    ($($t:ty),*) => {{
        let buf = rl();
        let mut w = buf.split_whitespace();
        ($(w.next().unwrap().parse::<$t>().unwrap()),*)
    }};
}

/// Read a line from standard input.
#[allow(dead_code)]
fn rl() -> String {
    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();

    #[allow(deprecated)]
    buf.trim_right().to_owned()
}

// -----------------------------------------------
// Solution
// -----------------------------------------------

fn main() {
    let H = read!(i64);
    let W = read!(i64);
    let N = read!(i64);

    let M = max(H, W);
    println!("{}", (N + M - 1) / M)
}


Measured memory_bytes: 4352
n = int(input())
T,A = (int(x) for x in input().split())
H = [int(x) for x in input().split()]

# T - x * 0.006 = A
# x = (T-A)/0.006
x = (T-A)/0.006
def error(i):
    return abs(H[i]-x)
n = 0
e = error(0)
for i in range(len(H)):
    if error(i) <= e:
        n = i
        e = error(i)

print(n+1)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define ll long long
#define INF 0x3f3f3f3f
#define mem( f, x ) memset( f, x, sizeof( f ) )
#define pii pair<int, int>
#define fi first
#define se second
#define mk(x, y) make_pair( x, y )
#define pk push_back
using namespace std;
const int M = 1e5 + 5;
const int N = 1e5 + 5;
const double PI = acos(-1.0);
ll m, n;

int main( ){
    while( scanf( "%lld %lld", &n, &m ) != EOF ){
        ll sum = 0, x;
        while( m-- ){
            scanf( "%lld", &x );
            sum += x;
        }
        if( sum > n ) printf( "-1\n" );
        else printf( "%lld\n", n - sum );
    }
    return 0;
}


Measured memory_bytes: 3812
#include <cstdio>
#include <vector>

using namespace std;


vector<int> cnt;
vector< vector<int> > e;

void solve(int v, int p) {
    for (int i = 0; i < int(e.at(v).size()); ++i) if (e.at(v).at(i) != p) cnt.at(e.at(v).at(i)) += cnt.at(v), solve(e.at(v).at(i), v);
}

int main() {
    int n, q, a, b, p, x;
    scanf("%d%d", &n, &q);
    cnt.resize(n + 1);
    e.resize(n + 1);
    for (int i = 1; i < n; ++i) {
        scanf("%d%d", &a, &b);
        e.at(a).push_back(b);
        e.at(b).push_back(a);
    }
    for (int i = 0; i < q; ++i) scanf("%d%d", &p, &x), cnt.at(p) += x;
    solve(1, 0);
    for (int i = 1; i <= n; ++i) printf("%d%c", cnt.at(i), i == n ? '\n' : ' ');
    return 0;
}


Measured memory_bytes: 29696
#include "algorithm"
#include "cmath"
#include "iostream"
#include "map"
#include "string"
#include "unordered_map"
#include "vector"

constexpr int MOD           = 1e9 + 7;
constexpr int long long INF = 1e18;
using namespace std;

int long long dp[20000 + 10][256];
int C[16], X[20000 + 10];
int main() {
  int N, M;
  cin >> N >> M;
  while (N != 0 || M != 0) {
    for (auto &i : dp) {
      for (auto &j : i) {
        j = INF;
      }
    }
    for (int i = 0; i < M; i++) {
      cin >> C[i];
    }
    for (int i = 0; i < N; i++) {
      cin >> X[i];
    }
    dp[0][128] = 0;
    for (int i = 0; i < N; i++) {
      for (int j = 0; j < 256; j++) {
        for (int k = 0; k < M; k++) {
          if (j + C[k] < 0) {
            dp[i + 1][0] = min(dp[i + 1][0], dp[i][j] + X[i] * X[i]);
          } else if (j + C[k] > 255) {
            dp[i + 1][255] = min(dp[i + 1][255], dp[i][j] + (X[i] - 255) * (X[i] - 255));
          } else {
            dp[i + 1][j + C[k]] = min(dp[i + 1][j + C[k]], dp[i][j] + (X[i] - (j + C[k])) * (X[i] - (j + C[k])));
          }
        }
      }
    }
    cout << *min_element(dp[N], dp[N] + 256) << endl;
    cin >> N >> M;
  }
}



Measured memory_bytes: 43212
//#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>

using namespace std;

#define FAST       			ios_base :: sync_with_stdio(false); cin.tie(NULL); 
#define endl "\n"

typedef long long int  ll;
typedef unsigned long long int ull;


int main()
{
	FAST;
	int arr[101];
	int n;
	cin >> n;
	for(int i=0 ; i<n ; i++)
		cin >> arr[i];

	sort(arr , arr+n);

	int count = 1;
	for(int i=1 ; i<n ; i++)
	{
		if(arr[i] != arr[i-1])
			count++;
	}

	cout << count;

	return 0;
}

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

#define lint long long
#define P pair<int, int>
#define LLP pair<long long, long long>
#define REP(i, x, n) for(int i = (x), i##_len = (int)(n) ; i < i##_len ; ++i)
#define rep(i, n) for(int i = 0, i##_len = (int)(n) ; i < i##_len ; ++i)
#define repr(i, n) for(int i = (int)(n) - 1 ; i >= 0 ; --i)
#define SORT(x) sort((x).begin(), (x).end())
#define SORT_INV(x) sort((x).rbegin(), (x).rend())

const int IINF = 1e9 + 10;
const long long LLINF = (long long)1e18 + 10;
const long long MOD = (long long)1e9 + 7;
const int dx4[] = {1, 0, -1, 0}, dy4[] = {0, 1, 0, -1};
const int dx8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dy8[] = {0, -1, -1, -1, 0, 1, 1, 1};
const double EPS = 1e-8;

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

    int n;
    cin >> n;

    vector<int> l(n * 2);
    rep(i, n * 2){
        cin >> l[i];
    }
    SORT(l);

    int ans = 0;
    for(int i = 0 ; i < n * 2 ; i += 2){
        ans += l[i];
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<vector<int>> vvi;
typedef vector<vector<string>> vvs;
typedef vector<vector<char>> vvc;
typedef vector<vector<bool>> vvb;
#define v_inputrep(v,n) for(int i=0;i<n;i++){cin >> v.at(i);} //配列vにn個の要素を入力する
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repn(i, n) for (int i = 0; i <= (int)(n); i++)

int main(){
    int n;
    cin >> n;
    vector<long double> t(n), a(n);
    rep(i, n){cin >> t.at(i) >> a.at(i);}
    ll t_tmp;
    ll a_tmp;
    t_tmp = 1;
    a_tmp = 1;
    for(ll i = 0 ; i < n ; i++){
        ll n = max(ceil(t_tmp / t.at(i)), ceil(a_tmp / a.at(i)));
        t_tmp = t.at(i) * n;
        a_tmp = a.at(i) * n;
    }

    cout << t_tmp + a_tmp;
}



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

using namespace std;
typedef long long ll;
typedef pair<ll, ll> p_ll;

template<class T>
void debug(T itr1, T itr2) { auto now = itr1; while(now<itr2) { cout << *now << " "; now++; } cout << endl; }
#define repr(i,from,to) for (int i=(int)from; i<(int)to; i++)
#define rep(i,N) repr(i,0,N)
#define per(i,N) for (int i=(int)N-1; i>=0; i--)

const ll MOD = pow(10,9)+7;
const ll LLINF = pow(2,61)-1;
const int INF = pow(2,30)-1;


int main() {
  string S; cin >> S;
  int l = S.length();
  int a = 0, b = 0, c = 0;
  rep(i,l) {
    if (S[i]=='a') a++;
    else if (S[i]=='b') b++;
    else c++;
  }
  int ma = max(a,max(b,c));
  int mi = min(a,min(b,c));
  string result = (ma-mi<=1) ? "YES" : "NO";
  cout << result << endl;
  return 0;
}

Measured memory_bytes: 512
#include <algorithm>
#include <numeric>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
using ll = long long;

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

  vector<int> *v[3];
  for (auto &p: v) { p = new vector<int>(0); }

  for (auto i = 0; i != n; ++i) {
    switch (str[i]) {
      case 'R':
        v[0]->push_back(i);
        break;
      case 'G':
        v[1]->push_back(i);
        break;
      case 'B':
        v[2]->push_back(i);
        break;
    }
  }

  sort(begin(v),end(v),
       [](auto p1, auto p2){
         return p1->size() < p2->size();
       });
  
  ll cnt = accumulate(begin(v),end(v),1ll,
                      [](auto acc, auto x){
                        return acc * x->size();});
  auto b = cbegin(*v[2]);
  auto e = cend(*v[2]);
  for(auto i: *v[0]) {
    for(auto j: *v[1]) {
      if(binary_search(b,e,2*i-j)) --cnt;
      if(binary_search(b,e,2*j-i)) --cnt;
      if((i+j)%2 == 0 && binary_search(b,e,(i+j)/2)) --cnt;
    }
  }

  cout << cnt << endl;
  for (auto &p: v) { delete p; }
  return 0;
}


Measured memory_bytes: 3640
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <utility>
#include <string>
#include <cmath>

using namespace std;

typedef uint64_t u64;
typedef int64_t s64;
typedef uint32_t u32;
typedef int32_t s32;

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

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

#define CEIL(x, y) (((x) + (y) - 1)/ (y))
#define MOD 1000000007ULL

void print_array(u64 *A, u64 N);
u64 insertionSort(u64 *A, u64 N, u64 g);
u64 shellSort(u64 *A, u64 N);

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

    u64 n;
    u64 *A;

    cin >> n;

    A = new u64[n];

    rep (i, n)
    {
        cin >> A[i];
    }

    u64 ret = shellSort(A, n);

    cout << ret << "\n";
    print_array(A, n);

    delete[] A;

    return 0;
}

void print_array(u64 *A, u64 N)
{
    rep (i, N)
    {
        cout << A[i] << "\n";
    }
}

u64 insertionSort(u64 *A, u64 N, u64 g)
{
    u64 cnt = 0;
    u64 v;
    for (u64 i = g; i < N; ++i)
    {
        v = A[i];
        s64 j = i - g;
        while (j >= 0 && A[j] > v)
        {
            A[j + g] = A[j];;
            j -= g;
            ++cnt;
        }
        A[j + g] = v;
    }

    return cnt;
}

u64 shellSort(u64 *A, u64 N)
{
    u64 cnt = 0;
    vector<u64> G;

    u64 h = 1;
    while (h <= N)
    {
        G.push_back(h);
        h = 3 * h + 1;
    }

    u64 m = G.size();

    for (int i = m - 1; i >= 0; --i)
    {
        cnt += insertionSort(A, N, G[i]);
    }

    cout << m <<"\n";
    for (int i = m - 1; i >= 0; --i)
    {
        if (i != m - 1)
        {
            cout << " ";
        }
        cout << G[i];
    }
    cout << "\n";

    return cnt;
}



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

#define all(cont) cont.begin(), cont.end()
#define rall(cont) cont.end(), cont.begin()
#define mp make_pair
#define pb push_back
#define X first
#define Y second
#define MOD 1000000007

#define trace1(x)                    cout <<#x<<": "<<x<< endl;
#define trace2(x, y)                 cout <<#x<<": "<<x<<" | "<<#y<<": "<<y<< endl;
#define trace3(x, y, z)              cout <<#x<<": "<<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl;
#define trace4(a, b, c, d)           cout <<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl;

typedef long long ll;

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(NULL);
    ll i,j,n,m;
    cin>>n;
    ll a[n];
    vector<ll> v,v1;
    ll cnt=0;
    ll os=0;
    ll cnt1=0;
    ll cnt2=0;
    for(i=0;i<n;i++)
    {
        cin>>a[i];
        if(a[i]<0)
        v.pb(a[i]),cnt++,cnt2-=a[i];
        else if(a[i]==0)
        os++;
        else
        cnt1+=a[i],v1.pb(a[i]);
    }
    sort(all(v));
    sort(all(v1));
    if(os!=0)
    {
        cout<<cnt1+cnt2;
    }
    else
    {
        if(cnt%2==0)
        cout<<cnt1+cnt2;
        else if(cnt1!=0)
        cout<<cnt1+cnt2+max(2*v[v.size()-1],-2*v1[0]);
        else
        cout<<cnt1+cnt2+2*(v[v.size()-1]);
    }
    return 0;
}

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

int main(){
	int N;
	cin >> N;
	for(int i = N; i > 0; i--){
		int num = i;
		while(num % 2 == 0){
			num /= 2;
		}
		if(num == 1){
			N = i;
			break;
		}
	}
	cout << N << endl;
}

Measured memory_bytes: 256
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Linq.Enumerable;
using static System.Math;

class Program
{
    static void Main()
    {
        for(int i = 0; i < 3; i++)
          Write(ReadLine()[i]);
        WriteLine();
    }
}

static class ArrayDeconstructExtensions
{
    public static void Deconstruct<T>(this T[] a, out T i1, out T i2) => (i1, i2) = (a[0], a[1]);
    public static void Deconstruct<T>(this T[] a, out T i1, out T i2, out T i3) => (i1, i2, i3) = (a[0], a[1], a[2]);
    public static void Deconstruct<T>(this T[] a, out T i1, out T i2, out T i3, out T i4) => (i1, i2, i3, i4) = (a[0], a[1], a[2], a[3]);
    public static void Deconstruct<T>(this T[] a, out T i1, out T i2, out T i3, out T i4, out T i5) => (i1, i2, i3, i4, i5) = (a[0], a[1], a[2], a[3], a[4]);
}


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

ll inf=1ll<<60;

int main()
{
	//freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
	ios_base::sync_with_stdio(false); cin.tie(0);
	ll i,j,k,n,m,f,t,p;
	cin>>n>>m;
	vector<vector<int>> g(n);
	vector<ll> s(n);
	vector<bool> v(n);
	fill(s.begin(),s.end(),false);
	for (i=0;i<m;i++){
		cin>>f>>t;
		f--;t--;
		g[f].push_back(t);
		g[t].push_back(f);
	}
	queue<ll> q;
	q.push(0);
	fill(s.begin(),s.end(),inf);
	s[0]=0;
	while (!q.empty()){
		p=q.front();
		q.pop();
		for (i=0;i<g[p].size();i++){
			if (v[g[p][i]]==false){
				s[g[p][i]]=min(s[g[p][i]],s[p]+1);
				q.push(g[p][i]);
			}
		}
		v[p]=true;
	}
	if (s[n-1]==2){
		cout<<"POSSIBLE";
	}
	else {
		cout<<"IMPOSSIBLE";
	}
	return 0;
}

Measured memory_bytes: 14448
//おまじない
//#include <bits/stdc++.h>
#include <stdio.h>
#include <iostream>
#include <math.h>
#include<iomanip>
#include <map>
#include <set>
#include <algorithm>
#include <vector>
#include <string>
#include <utility>
#include <queue>
#define INF 1e9+7
#define rep(i,n) for(int i=0;i<n;i++)
#define all(a) a.begin(),a.end()
#define P pair<int,int>
#define space ' '
#define pll pair<ll,ll>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;

//(int)'a'は97 (int)'A'は65 (int)'1'は49
//おまじない

const int maxn = 100000;

int main(){
    
    int ans = 0;
    int x,y;cin >> x>>y;
    if(x==3)ans+=100000;
    else if(x==2)ans+=200000;
    else if(x==1)ans+=300000;
    if(y==3)ans+=100000;
    else if(y==2)ans+=200000;
    else if(y==1)ans+=300000;
    
    if(x==1&&y==1)ans+=400000;
    
    cout << ans<<endl;
    
    
    return 0;
}


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

#define FOR(i, a, b) for(int i = a; i < b; ++i)
#define REP(i, n) FOR(i, 0, n)
#define _ << " " <<
#define sz(x) ((int) x.size())

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

set<string> s;

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

  string ss; cin >> ss;

  int n = ss.size();
  REP(i, n) {
    FOR(j, 1, 6) {
      if(i + j > n) break;
      s.insert(ss.substr(i, j));
    }
  }

  auto it = s.begin();
  int k; cin >> k;
  REP(i, k - 1) it ++;
  cout << *it << endl;
}


Measured memory_bytes: 1664
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a


def lcm(a, b):
    return a * b // gcd (a, b)


N, M = map(int, input().split())
A = list(map(int, input().split()))
B = [a//2 for a in A]

base = B[0]

is_break = False
for b in B:
  if base % b == 0:
    if (base // b) % 2 == 0:
      is_break = True
      break
    
    continue
  
  new_base = lcm(base, b)
  if (new_base // base) % 2 == 0:
    is_break = True
    break
  
  base = new_base

if is_break:
  ans = 0
else:
  ans = M // base
  if ans%2 == 0:
    ans = ans // 2
  else:
    ans = (ans + 1) // 2


print(ans)

Measured memory_bytes: 14244
#include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <functional>
#include <numeric>
#include <list>
#include <set>
#include <map>
#include <algorithm>
#include <cmath>
#include <limits>
#include <iomanip>
#include <bitset>
#include <queue>

using namespace std;
typedef long long ll;

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
#define rep(i, n) for(int i = 0;i < n;i++)
const long long INF = 1LL << 60;

int MOD = 1000000007;

struct UnionFind {
  vector<int> data;
  UnionFind(int size) : data(size, -1) { }
  bool unionSet(int x, int y) {
    x = root(x); y = root(y);
    if (x != y) {
      if (data[y] < data[x]) swap(x, y);
      data[x] += data[y]; data[y] = x;
    }
    return x != y;
  }
  bool findSet(int x, int y) {
    return root(x) == root(y);
  }
  int root(int x) {
    return data[x] < 0 ? x : data[x] = root(data[x]);
  }
  int size(int x) {
    return -data[root(x)];
  }
};

int main(){
    std::ios_base::sync_with_stdio(false);
    int n; cin >> n;
    std::vector<int> a(n);
    rep(i,n) cin >> a[i];

    int current = a[0]; int ans=0;
    rep(i,n){
      if(current== i+1){
        ans++;
        current = a[i];
      } else{
        if(i!=n-1) current = a[i+1];
      }
    }
    cout << ans << endl;
    
    return 0;
}


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

int main() {
    int n;
    cin>>n;
    priority_queue<int,vector<int>,greater<int>> pq;
    int input;
    double ans=0;
    for (size_t i = 0; i < n; i++)
    {
        cin>>input;
        pq.push(input);
    }
    ans = pq.top();
    pq.pop();
    while(!pq.empty())
    {
        ans = (ans+pq.top())/2.0;
        pq.pop();
        /* code */
    }
    cout<<ans<<endl;
        
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f, N = 2e5 + 5;
int n, x, y;
int a[N], b[N];
inline int read () {
    int tot = 0, f = 1; char c = getchar ();
    while (c < '0' || c > '9') { if (c == '-') f = -1; c = getchar (); }
    while (c >= '0' && c <= '9') { tot = tot * 10 + c - '0'; c = getchar ();}
    return tot * f;
}
signed main () {
    n = read ();
    for (int i = 1; i <= n; i++) {
        x = read (); y = read ();
        a[i] = x - y;
        b[i] = x + y;
    }
    sort (a + 1, a + 1 + n); sort (b + 1, b + 1 + n);
    printf ("%d\n", max (a[n] - a[1], b[n] - b[1]));
    return 0;
}


Measured memory_bytes: 5204
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define numrep(i,n) for(int i=1;i<=n;i++)
#define bitrep(n) for(int bit=0;bit<(1<<n);bit++)
#define ll int64_t
#define all(v) v.begin(), v.end()

const int MOD = 1000000007;

int main() {

ll N; cin >> N ;

vector<ll> A(N);

rep(i,N) cin >> A[i];

deque<int> dq;

rep(i,N){
  if(i%2==0) dq.push_back(A[i]);

  else dq.push_front(A[i]);

}

if(N%2==0){
  rep(i,N){
    cout << dq.front() << ' ';
    dq.pop_front();
  }
}

else{
  rep(i,N){
    cout << dq.back() << ' ';
    dq.pop_back();
  }
}

cout << endl; 

return 0;

}

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

#define tt template<typename T> ostream& operator <<(ostream& os, const
#define tuv template<typename U, typename V> ostream& operator<<(ostream& os, const
tt vector<T>& v)            { os << "["; for(auto & x : v) os << " " << x; os << " ]"; return os; }
tt vector<vector<T> >& m)   { for(auto & x : m) { for(auto & y : x) os << y << " "; os << "\n"; } return os; }
tt set<T>& s)               { os << "{"; for(auto & x : s) os << " " << x; os << " }"; return os; }
tt unordered_set<T>& s)     { os << "{"; for(auto & x : s) os << " " << x; os << " }"; return os; }
tt queue<T>& q)             { queue<T> q2(q); while(!q2.empty()) { os << q2.front() << " "; q2.pop(); } return os; }
tt stack<T>& s)             { stack<T> s2(s); while(!s2.empty()) { os << s2.top() << " "; s2.pop(); } return os; }
tuv pair<U,V>& p)           { os << "(" << p.first << "," << p.second << ")"; return os; }
tuv map<U,V>& m)            { os << "{ "; for(auto & x : m) os << x.first << ":" << x.second << " "; os << "}"; return os; }
tuv unordered_map<U,V>& um) { os << "{ "; for(auto & x : um) os << x.first << ":" << x.second << " "; os << "}"; return os; }


int main(int argc, char * argv[])
{
    std::ios_base::sync_with_stdio(false);    
    std::cin.tie(NULL);

    int N, L;
    std::cin >> N >> L;

    std::vector<string> S(N);
    for(int i = 0; i < N; ++i) std::cin >> S[i];

    std::sort(std::begin(S), std::end(S));

    string res;
    for(auto & x : S) res += x;

    std::cout << res << std::endl;



    return 0;
}


Measured memory_bytes: 256