akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define REP(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) REP(i, 0, n)
#define rrep(i, n) for (int i = (int)(n-1); i >= 0; i--)
#define sz(x) int(x.size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define INF 2e9
#define LINF 1e18
template<class T> inline bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T &a, const T &b) { if (a > b) { a = b; return 1; } return 0; }
typedef long long ll;
typedef pair<int, int> P;
 
int main() {
    int a, b, k; cin >> a >> b >> k;
    int cnt = 0;
    rrep(i, min(a, b)+1) {
        if (a%i == 0 && b%i == 0) {
            cnt++;
            if (cnt == k) {
                cout << i << endl;
                return 0;
            }
        }
    }
}

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

#define fi first
#define se second
#define sz(a) (int)(a).size()
#define all(a) (a).begin(), (a).end()
#define reset(a, v) memset((a), v, sizeof(a))

using namespace std;

typedef long long ll;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<ii> vii;

const int N = (int)1e5 + 5;

int x, y, nRed, nGreen, nOther;
int red[N], green[N], other[N];

bool comp(int a, int b) {
	return a > b;
}

int main() {
	scanf("%d %d %d %d %d", &x, &y, &nRed, &nGreen, &nOther);
	for (int i = 0; i < nRed; i++) {
		scanf("%d", &red[i]);
	}
	sort(red, red+nRed, comp);
	for (int i = 0; i < nGreen; i++) {
		scanf("%d", &green[i]);
	}
	sort(green, green+nGreen, comp);
	for (int i = 0; i < nOther; i++) {
		scanf("%d", &other[i]);
	}
	sort(other, other+nOther, comp);
	ll ans = 0;
	priority_queue< int, vector<int>, greater<int> > pq1;
	priority_queue<int> pq2;
	for (int i = 0; i < x; i++) {
		pq1.push(red[i]);
		ans += red[i];
	}
	for (int i = 0; i < y; i++) {
		pq1.push(green[i]);
		ans += green[i];
	}
	for (int i = 0; i < nOther; i++) {
		pq2.push(other[i]);
	}
	while (!pq2.empty()) {
		int tp1 = pq1.top();
		int tp2 = pq2.top();
		if (tp1 >= tp2) {
			break;
		}
		pq1.pop();
		ans -= tp1;
		pq1.push(tp2);
		pq2.pop();
		ans += tp2;
	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 3060
#include <iostream>
#include <bits/stdc++.h>
const long long INF = 1LL<<60;

using namespace std;

int main() {
  int N, W;
  cin >> N >> W;
  vector<int> w(N);
  vector<int> v(N);
  int max_v=0;
  for (int i=0; i<N; i++) {
    cin >> w.at(i) >> v.at(i);
    max_v = max(max_v, v[i]);
  }

  int max_tot_v = max_v * N;
  vector<vector<long long int>> tot_w;
  tot_w.resize(N+1);
  for(int i=0; i<=N; i++) {
    tot_w[i].resize(max_tot_v + 1);
  }

  for (int j=0; j<max_tot_v+1; j++) {
    tot_w[0][j] = INF;
  }

  tot_w[0][0] = 0;

  for (int i=0; i<N; i++) {
    for(int j=0; j<max_tot_v+1; j++) {
      if (v[i] <= j) {
        tot_w[i+1][j] = min(tot_w[i][j], tot_w[i][j-v[i]] + w[i]);
      } else {
        tot_w[i+1][j] = tot_w[i][j];
      }
    }
  }

  int result=0;
  for (int j=max_tot_v; j >=0; j--) {
    if (tot_w[N][j] <= W) {
      result = j;
      break;
    }
  }

  cout << result << endl;

  return 0;
}

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

typedef long long LL;
typedef pair<int, int> PII;
typedef vector<int> VI;
#define MP make_pair
#define PB push_back
#define X first
#define Y second

#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define RFOR(i, b, a) for(LL i = (b) - 1; i >= (a); --i)
#define ITER(it, a) for(__typeof(a.begin()) it = a.begin(); it != a.end(); ++it)
#define ALL(a) a.begin(), a.end()
#define SZ(a) (LL)((a).size())
#define FILL(a, value) memset(a, value, sizeof(a))
#define debug(a) cout << #a << " = " << a << endl;

const double PI = acos(-1.0);
const LL INF = 1000 * 1000 * 1000 + 7;
const LL LINF = (LL)INF * INF;
const int MAX = 100005;
int a[4];
int main()
{
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    //freopen("In.txt" , "r" , stdin);
	cin >> a[0] >> a[1] >> a[2] >> a[3];
	sort(a , a + 4);
	if(a[0] == 1 && a[1] == 4 && a[2] == 7 && a[3] == 9)
		cout << "YES";
	else
		cout << "NO";
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<map>
#include<vector>
#include<algorithm>
#include<cmath>
#include<climits>
#include<ctime>
#include<cstring>
#include<stack>
#include<queue>
#include<sstream>
#include<string>
#include<set>
#include<stdio.h>

#define ALL(v) (v).begin(),(v).end()
#define REP(i,p,n) for(int i=p;i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define DUMP(list) cout << "{ "; for(auto nth : list){ cout << nth << " "; } cout << "}" << endl

using namespace std;

const int MAX_V=16;
const int MAX_E=1001;
const int INF=1<<28;

int G[MAX_V][MAX_V];
int n_num[MAX_V];
int dp[1<<MAX_V];
int max_cost;

int main(){

	int n,e;
	cin >> n >> e;
	fill_n((int *)n_num,sizeof(n_num)/sizeof(int),0);
	fill_n((int *)G,sizeof(G)/sizeof(int),INF);
	vector<int> odd_node;
	max_cost=0;
	rep(i,e){
		int s,t,d;
		cin >> s >> t >> d;
		max_cost+=d;
		d=min(d,G[s][t]);
		G[s][t]=d;
		G[t][s]=d;
		n_num[s]++;
		n_num[t]++;
	}
	
	rep(i,n) if(n_num[i]%2!=0) odd_node.push_back(i);	
	
	for(int k = 0; k < n; ++k)
		for(int i = 0; i < n; ++i)
			for(int j = 0; j < n; ++j) G[i][j] = min(G[i][j], G[i][k] + G[k][j]);


	fill_n((int *)dp,sizeof(dp)/sizeof(int),INF);
	dp[0]=0;
	for(int i=0;i<(1<<odd_node.size());i++){
		rep(j,odd_node.size()){
			if(i & (1<<j)) continue;
			for(int k=j+1;k<odd_node.size();k++){
				if(i & (1<<k)) continue;
				dp[i|(1<<j)|(1<<k)] = min(dp[i|(1<<j)|(1<<k)],dp[i]+G[odd_node[j]][odd_node[k]]);
			}
		}
	}

	cout << max_cost+dp[(1<<odd_node.size())-1] << endl;

	return 0;
}

Measured memory_bytes: 1464
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
const ll INF = LLONG_MAX;

int main()
{
    int n;
    cin >> n;
    vector<pair<pair<string, int>, int>> ans(n);
    for (int i = 0; i < n; i++)
    {
        string s;
        int p;
        cin >> s >> p;
        ans[i] = make_pair(make_pair(s, -p), i + 1);
    }
    sort(ans.begin(), ans.end());
    for (int i = 0; i < n; i++)
    {
        cout << ans[i].second << "\n";
    }
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#include<unordered_map>
#include<queue>
#include<iomanip>
#include<math.h>
#include<bitset>
#include<cassert>
#include<random>
#include<time.h>
#include<functional>
using namespace std;
using ll=long long;
using ld=long double;
using P=pair<ll,ll>;
#define MOD 1000000007LL
#define INF 1000000000LL
#define EPS 1e-10
#define FOR(i,n,m) for(ll i=n;i<(ll)m;i++)
#define REP(i,n) FOR(i,0,n)
#define DUMP(a) REP(d,a.size()){cout<<a[d];if(d!=a.size()-1)cout<<" ";else cout<<endl;}
#define ALL(v) v.begin(),v.end()
#define UNIQUE(v)  sort(ALL(v));v.erase(unique(ALL(v)),v.end());
#define pb push_back

constexpr int MAX_SIZE = 303030;
template <typename T>
class segTree {
public:
	/// op: 演算, ie: 演算の単位元
	segTree(int _n, function<T(T, T)> op, const T ie) : op(op), ie(ie) {
		n = 1;
		while(n < _n) n *= 2;
		for(int i = 0; i < 2 * n - 1; i++) seq[i] = ie;
	}

	// k 番目(0-indexed)の要素を e で更新
	void update(int k, const T e) {
		k += n - 1;
		seq[k] = e;
		while(k > 0) {
			k = (k - 1) / 2;
			seq[k] = op(seq[k * 2 + 1], seq[k * 2 + 2]);
		}
	}

	/// [a, b) 番目(0-indexed)の要素全体の演算結果を返す
	/// k, l, r は、外部から呼び出す際は指定不要
	T query(int a, int b, int k = 0, int l = 0, int r = -1) {
		if(r == -1) r = n;
		if(r <= a || b <= l) return ie;
		if(a <= l && r <= b) return seq[k];
		T vl = query(a, b, k * 2 + 1, l, (l + r) / 2);
		T vr = query(a, b, k * 2 + 2, (l + r) / 2, r);
		return op(vl, vr);
	}

private:
	int n;
	const function<T(T, T)> op; // 演算
	const T ie; // 演算の単位元
	T seq[MAX_SIZE];
};
// [Range Sum Query] op: [] (long long a, long long b) { return a + b; }, ie: 0
// [Range Maximum Query] op: [] (long long a, long long b) { return max(a, b); }, ie: -1e18
// [Range Minimum Query] op: [] (long long a, long long b) { return min(a, b); }, ie: 1e18

/* --------------------------------------- */

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n, q;
	cin >> n >> q;
	segTree<ll> seg(n, [] (ll a, ll b) { return min(a, b); }, (1LL << 31) - 1);
	REP(i, q) {
		int c, x, y;
		cin >> c >> x >> y;
		if(c == 0) {
			seg.update(x, y);
		} else {
			cout << seg.query(x, y + 1) << endl;
		}
	}
	return 0;
}

/* --------------------------------------- */




Measured memory_bytes: 5220
import java.util.Scanner;

public class Main {

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

		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int min = 1000000000;
		int max = -1000000000;

		for(int i = 0; i < n; i++) {

			int r = sc.nextInt();

			if(i == 0) {

				min = r;

			} else {

				max = Math.max(max, r - min);
				min = Math.min(min, r);

			}
		}

		System.out.println(max);

	}

}


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

int main() {
  cout << "Yes" << endl;
  int N,M;
  cin >> N >> M;
  vector<vector<int>> G(N);
  rep(i,M){
    int a,b;
    cin >> a >> b;
    a--;b--;
    G.at(b).push_back(a);
    G.at(a).push_back(b);
  }
  vector<int> dist(N,MOD);
  vector<int> ans(N);
  queue<int> que;
  dist.at(0) = 0;
  que.push(0);
  while(!que.empty()){
    int v = que.front();
    que.pop();
    for(int nv:G.at(v)){
      if(dist.at(nv) != MOD){
      continue;
      }
      dist.at(nv) = dist.at(v) +1;
      ans.at(nv) = v;
      que.push(nv);
    }
  }
  rep(i,N-1){
    cout << ans.at(i+1)+1 << endl;
  }
}
  
    

Measured memory_bytes: 10584
#include <bits/stdc++.h>
#include <algorithm>
using namespace std;
int main() {

int a,b,c[110],d[110],e,f;
   cin >> a;
  for(int i=0;i<a;i++)
    cin >> c[i];
  for(int i=0;i<a;i++){
    d[i] =c[i];
  }
  
  sort(c,c+a);
  f =0;
   
   for(int i=0;i<a;i++){
     if(d[i] != c[i]){
       f++;
     }
   }
     if(f ==0||f==2){
     cout <<"YES" << endl;
     
     return 0;
   }
    else{
  
  cout <<"NO" <<endl;
      return 0;
}
     }

Measured memory_bytes: 256
n=list(input())
n.append("R")
now="R"
count=0
was=0
list=[0 for i in range(len(n)-1)]
for i in range(len(n)):
  if now=="R":
    if now==n[i]:
      count+=1
    else:
      list[i]+=count//2
      if count%2==1:
        list[i-1]+=(count//2)+1
      else:
        list[i-1]+=count//2
      count=1
      now="L"
      was=i-1
  else:
    if now==n[i]:
      count+=1
    else:
      list[was]+=count//2
      if count%2==1:
        list[was+1]+=(count//2)+1
      else:
        list[was+1]+=count//2
      now="R"
      count=1
w=""
for i in list:
  w+=str(i)+" "
print(w)

Measured memory_bytes: 5288
#include <bits/stdc++.h>
using namespace std;
int main(){
    //freopen("input.txt", "r", stdin);
    int len;
    cin >> len;
    vector<int> nums(len + 1);
    for(int i = 0; i < len; i++){
        scanf("%d", &nums[i]);
    }
    if(len == 2) cout << abs(nums[0] - nums[1]) << endl;
    else{
        vector<int> dp(len + 1, 0);
        dp[0] = 0;
        dp[1] = abs(nums[0] - nums[1]);
        for(int i = 2; i < len; i++){
            dp[i] = min((dp[i - 2] + abs(nums[i - 2] - nums[i])), (dp[i - 1] + abs(nums[i - 1] - nums[i])));
        }
        cout << dp[len - 1] << endl;
    }
    return 0;
}


Measured memory_bytes: 4108
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<n; i++)
#define rep1(i, n) for(int i=1; i<=n; i++)
#define repr(i, n) for(int i=n-1; i>=0; i--)
#define repr1(i, n) for(int i=n; i>=1; i--)
#define all(v) v.begin(),v.end()
using ll = long long;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const int INF = 1e9;
const ll LLINF = 1e18;
const ll MOD = 1e9+7;
const double EPS = 1e-10;
const double PI = acos(-1);
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

const int MAX = 100010;
ll fac[MAX], finv[MAX], inv[MAX];

void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++) {
        fac[i] = fac[i-1] * i % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        finv[i] = finv[i-1] * inv[i] % MOD;
    }
}

ll comb(int n, int k) {
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main() {
    int n; cin >> n;
    vector<vector<int>> pos(n+1);
    rep(i, n+1) {
        int a; cin >> a;
        pos[a].push_back(i+1);
    }

    int l, r;
    for (int i = 1; i <= n; i++) {
        if (pos[i].size() == 2) {
            l = pos[i][0];
            r = pos[i][1];
        }
    }

    COMinit();

    for (int k = 1; k <= n+1; k++) {
        if (k == 1) {
            cout << n << endl;
        } else {
            ll res = 0;

            // l も r も選ぶ
            res += comb(n-1, k-2);
            if (res < 0) res += MOD;

            // l も r も選ばない
            res += comb(n-1, k);
            if (res < 0) res += MOD;

            // l と r の片方だけ選ぶ
            res += (2 * comb(n-1, k-1)) % MOD;
            if (res < 0) res += MOD;
            res -= comb(n+l-r, k-1);
            if (res < 0) res += MOD;

            cout << res % MOD << endl;
        }
    }

}


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

int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	ll n;
	cin >> n;
	vector<ll> a(n);
	for (int i = 0; i < n; i++)
		cin >> a[i];
	ll sum = 0;
	ll ma = a[0];
	for (auto x : a)
	{
		if (x < ma)
		{
			sum += (ma - x);
		}
		else if (x > ma)
		{
			ma = x;
		}
	}
	cout << sum;
	return 0;
}


Measured memory_bytes: 4756
#include <bits/stdc++.h>
using namespace std;
int main() {
    int n, m; cin >> n >> m;
    vector<int> w(m, 0), a(m, 0);
    for (int i = 0; i < m; i++) {
        int b; cin >> a[i] >> b;
        for (int j = 0; j < b; j++) {
            int t; cin >> t;
            w[i] |= 1 << (t-1);
        }
    }
    vector<vector<int>> dp(m+1, vector<int>(1 << n, 1e9));
    dp[0][0] = 0;
    for (int i = 0; i < m; i++) {
        for (int j = 0; j < (1 << n); j++) {
            dp[i+1][j] = min(dp[i+1][j], dp[i][j]);
            dp[i+1][j|w[i]] = min(dp[i+1][j|w[i]], dp[i][j] + a[i]);
        }
    }
    if (dp[m].back() != 1e9) cout << dp[m].back() << endl;
    else cout << -1 << endl;
    return 0;
}

Measured memory_bytes: 16384
#include <iostream>
#include <cmath>
#include <boost/multiprecision/cpp_dec_float.hpp>
using namespace std;
namespace mp = boost::multiprecision;

int main()
{
    int A,B,H,M;

    cin>>A>>B>>H>>M;
    mp::cpp_dec_float_50 dis;
    mp::cpp_dec_float_50 pi =3.1415926535897932384;
    pair<mp::cpp_dec_float_50,mp::cpp_dec_float_50>p1;//時間
    pair<mp::cpp_dec_float_50,mp::cpp_dec_float_50>p2;//分速 
  	p2.first=B*cos((90-6*M)*pi/180.0);
    p2.second=B*sin((90-6*M)*pi/180.0);
    p1.first=A*cos((90-30*H-M/2.0)*pi/180.0);
    p1.second=A*sin((90-30*H-M/2.0)*pi/180.0);
    dis=sqrt((p2.second-p1.second)*(p2.second-p1.second)+(p2.first-p1.first)*(p2.first-p1.first));
    cout <<std::setprecision(std::numeric_limits<decltype(dis)>::digits10 + 1) <<dis << endl;
   
}

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

#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)

#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=int(a)-1;i>=int(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)

#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
#define popcount(n) (__builtin_popcountll(n))

using namespace std;

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

using ll=long long;
using R=long double;
const R EPS=1e-9L; // [-1000,1000]->EPS=1e-8 [-10000,10000]->EPS=1e-7
inline int sgn(const R& r){return(r > EPS)-(r < -EPS);}
inline R sq(R x){return sqrt(max(x,0.0L));}

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

// Problem Specific Parameter:

int main(void){
	ll n,k;
	cin >> n >> k;
	n=max(n-2,0LL);

	ll ans=0LL;
	rep(i,2,2+11){
		rep(j,2,7){
			ll cur=9*(7*i+j-7);
			if(cur%11==k) ans++;
		}
	}

	ans*=n/11;
	n%=11;

	rep(i,2,2+n){
		rep(j,2,7){
			ll cur=9*(7*i+j-7);
			if(cur%11==k) ans++;
		}
	}

	cout << ans << endl;
	return 0;
}

// 

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

using namespace std;

#define DATA_MAX 50

void swap( int& a , int& b );

int main(void)
{
	int w, n;
	int a, b;

	int data[DATA_MAX];

	cin >> w;
	cin >> n;

	for( int i = 0 ; i < DATA_MAX ; i++ )
	{
		data[i] = i+1;
	}

	for( int i = 0 ; i < n ; i++ )
	{
		scanf("%d , %d", &a , &b );
		swap( data[a-1] , data[b-1] );
	}
	for( int i = 0 ; i < w ; i++ )
	{
		cout << data[i] << endl;
	}

	return 0;
}

void swap( int& a , int& b )
{
	int temp;

	temp = a;
	a = b;
	b = temp;

	return;
}

Measured memory_bytes: 1240
#include<bits/stdc++.h>
using namespace std;
int n,has[233],
rat[]={0,399,799,1199,1599,1999,2399,2799,3199,-1};
int main(){
	int i,dt=0;
	cin>>n;
	for(i=1;i<=n;i++){
		int x;cin>>x;
		for(int i=1;rat[i]!=-1;i++)
			if(rat[i-1]<x&&x<=rat[i])
				has[i]=1;
		if(x>3199)++dt;
	}
	int x=0;
	for(i=1;i<=20;i++)x+=has[i];
	cout<<max(x,1)<<" "<<x+dt;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <math.h>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <stack>
#include <queue>

using namespace std;
typedef long long ll;
#define rep(i,n) for(ll i=0;i<(ll)n;i++)
#define rep1(i,n) for(ll i=1;i<(ll)n;i++)
#define repf(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define repr(i,a,b) for(ll i=(ll)a-1;i>=(ll)b;i--)
#define Fi first
#define Se second
typedef pair<ll, ll> pll;
const ll MAX = 1005;
const char END = '\n';

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	ll N, K, Ans = 1000000000;
	cin >> N >> K;
	
	vector<ll> h(N);
	rep(i, N)
		cin >> h[i];

	sort(h.begin(), h.end());
	
	rep(i, N - (K - 1)) {
		ll sub = h[i + K - 1] - h[i];
		if (sub < Ans)
			Ans = sub;
	}

	cout << Ans << END;
	return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(V) (V).begin(),(V).end()
#define SORT(V) sort(ALL(V))

vector<string> split(string,string);

//template<typename T>
//void swap(T*,T*);
//char ToUpper (char cX) { return toupper(cX); }

int main()
{
    int N,A;
    cin >> N;
    cin >> A;
    int sum = N % 500;
    if(sum <= A)
        Yes(true);
    else
    {
        Yes(false);
    }
    
}

Measured memory_bytes: 256
#include<cstdio>
char last(char *s){
    if(*s=='\0')return *(s-1);
    else return last(s+1);
}
int main(){
    char s[3][11];
    scanf("%s%s%s",s[0],s[1],s[2]);
    if(last(s[0])==s[1][0] && last(s[1])==s[2][0])printf("YES");
    else printf("NO");
    return 0;
}

Measured memory_bytes: 128
import math
import string
import collections
from collections import Counter


def readints():
    return list(map(int, input().split()))


def nCr(n, r):
    return math.factorial(n)//(math.factorial(n-r)*math.factorial(r))


def has_duplicates2(seq):
    seen = []
    for item in seq:
        if not(item in seen):
            seen.append(item)
    return len(seq) != len(seen)


def divisor(n):
    divisor = []
    for i in range(1, n+1):
        if n % i == 0:
            divisor.append(i)
    return divisor


# coordinates
dx = [-1, -1, -1, 0, 0, 1, 1, 1]
dy = [-1, 0, 1, -1, 1, -1, 0, 1]
W, H, x, y = map(int, input().split())
tmp = 0

if x*2 == W and y*2 == H:
    tmp = (W*H)/2
    print('{:f}'.format(tmp), 1)
    exit()
else:

    print('{:f}'.format((H*W)/2), 0)
    exit()


Measured memory_bytes: 38640
#include <algorithm>
#include <iostream>
#include <list>
#include <queue>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define MAX_N 100
using namespace std;

int main(void) {
  ios::sync_with_stdio(false);
  int N;
  cin >> N;

  list<pair<int, int>> red;
  rep(i, N) {
    int a, b;
    cin >> a >> b;
    red.push_back(make_pair(a, b));
  }
  red.sort();

  list<pair<int, int>> blue;
  rep(i, N) {
    int c, d;
    cin >> c >> d;
    blue.push_back(make_pair(c, d));
  }
  blue.sort();

  int Ans = 0;
  for (auto itr_b = blue.begin(); itr_b != blue.end(); ++itr_b) {
    auto &b = *itr_b;

    int r_y_max = -1;
    auto r_max = red.begin();
    bool flag = false;
    for (auto itr_r = red.begin(); itr_r != red.end(); ++itr_r) {
      auto &r = *itr_r;
      if (b.first <= r.first || b.second <= r.second)
        continue;
      if (r_y_max < r.second) {
        flag = true;
        r_y_max = r.second;
        r_max = itr_r;
      }
    }
    if (flag) {
      red.erase(r_max);
      Ans++;
    }
  }
  cout << Ans << endl;
  return 0;
}

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

using namespace std;

int main(){
    int n;
    cin >> n;
    int array[100];
    bool flag=true;
    int count=0;
    for(int i=0;i<n;i++){
        cin >> array[i];
    }
    while(flag){
        flag=false;
        for(int i=0;i<n-1;i++){
            if(array[i]>array[i+1]){
                int tmp=array[i];
                array[i]=array[i+1];
                array[i+1]=tmp;
                flag=true;
                count++;
            }
        }

    }
    for(int i=0;i<n;i++){
        cout << array[i];
        if(i!=n-1){
            cout << " ";
        }
    }
    cout << endl;
    cout << count << endl;
    return 0;
}


Measured memory_bytes: 3104
#include "bits/stdc++.h"

using namespace std;

using ll = long long;
using ld = long double;
using P = pair<int, int>;
constexpr ld EPS = 1e-12;
constexpr int INF = numeric_limits<int>::max() / 2;
constexpr int MOD = 1e9 + 7;

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

    int N;
    while (cin >> N, N)
    {

        vector<ll> HP(N);
        for (int i = 0; i < N; i++)
        {
            cin >> HP[i];
        }
        int M;
        cin >> M;
        vector<P> single, all;
        for (int i = 0; i < M; i++)
        {
            string name, target;
            int mp, damage;
            cin >> name >> mp >> target >> damage;
            if (target == "All")
                all.push_back(P(mp, damage));
            else
                single.push_back(P(mp, damage));
        }
        // dp1[i] := All で i ダメージ与える最小コスト
        // dp2[i] := Single で i ダメージ与える最小コスト
        vector<ll> dp1(111111, INF), dp2(111111, INF);
        dp1[0] = 0;
        dp2[0] = 0;
        for (int i = 0; i < (int)all.size(); i++)
        {
            int mp = all[i].first, d = all[i].second;
            for (int j = 0; j <= 100000; j++)
            {
                if (j + d > 100000)
                {
                    dp1[100001] = min(dp1[100001], dp1[j] + mp);
                }
                else
                {
                    dp1[j + d] = min(dp1[j + d], dp1[j] + mp);
                }
            }
        }
        for (int i = 0; i < (int)single.size(); i++)
        {
            int mp = single[i].first, d = single[i].second;
            for (int j = 0; j <= 100000; j++)
            {
                if (j + d > 100000)
                {
                    dp2[100001] = min(dp2[100001], dp2[j] + mp);
                }
                else
                {
                    dp2[j + d] = min(dp2[j + d], dp2[j] + mp);
                }
            }
        }
        for (int i = 100000; i >= 0; i--)
        {
            dp1[i] = min(dp1[i], dp1[i + 1]);
            dp2[i] = min(dp2[i], dp2[i + 1]);
            // assert(dp1[i] != INF);
            // assert(dp2[i] != INF);
        }
        ll res = INF;
        for (int i = 0; i <= 100000; i++)
        {
            ll tmp = dp1[i];
            for (int j = 0; j < N; j++)
            {
                if (HP[j] <= i)
                    continue;
                tmp += dp2[HP[j] - i];
            }
            res = min(res, tmp);
        }
        cout << res << endl;
    }
}



Measured memory_bytes: 4808
#include<stdio.h>
#include<string.h>
#define fup(i,a,b) for(int i=a;i<b;++i)
#define fdn(i,a,b) for(int i=a;i>=b;--i)
#define mem(a,b) memset(a,b,sizeof(a))

void Main()
{
    int n;char a[105];
    scanf("%d %s",&n,a);
    int b[103][2],cz[130],cy[130];
    int s,sz,sy;
    fup(x,0,n)
    {
        sz=sy=s=0;
        mem(cz,0);mem(cy,0);
        fdn(i,x,0)++cz[a[i]];
        fup(i,x+1,n)++cy[a[i]];
        fup(i,95,130)
        {
            if(cz[i])++sz;
            if(cy[i])++sy;
            if(cz[i]&&cy[i])++s;
        }
        b[x][0]=sz+sy;
        b[x][1]=s;
    }
    int mx=-1,j=0;
    fup(i,0,n)if(mx<b[i][0])mx=b[i][0],j=i;
    printf("%d",b[j][1]);
}
int main()
{
Main();
return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	int sum = 0;
	int i;
	
	for (i = 0; i < 5; i++){
		int point;
		
		scanf("%d", &point);
		if (point < 40) point = 40;
		sum += point;
	}
	printf("%d\n", sum / 5);
	
	return 0;
}

Measured memory_bytes: 600
#include <bits/stdc++.h>
using namespace std;
template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << "(" << p.first << "," << p.second << ")";
  return os;
}
#ifdef __LOCAL
#define debug(x) cerr << __LINE__ << ": " << #x << " = " << x << endl
#define debugArray(x, n)                                      \
  cerr << __LINE__ << ": " << #x << " = {";                   \
  for (long long hoge = 0; (hoge) < (long long)(n); ++(hoge)) \
    cerr << ((hoge) ? "," : "") << x[hoge];                   \
  cerr << "}" << endl
#else
#define debug(x) (void(0))
#define debugArray(x, n) (void(0))
#endif

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N, K;
  cin >> N >> K;
  int ans = 0;
  for (int i = 0; i < N; i++) {
    int h;
    cin >> h;
    ans += h >= K;
  }
  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 3656
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define forn(i, a, b) for (int i = a; i < b; ++i)
#define SZ(x) int(x.size())
#define pb push_back
#define F first
#define S second
void dbg_out() { cerr << endl; }
template <typename Head, typename... Tail>
void dbg_out(Head H, Tail... T) {
  cerr << ' ' << H;
  dbg_out(T...);
}

int main() {
#ifdef LOCAL
  freopen("g.txt", "r", stdin);
// freopen("g.txt", "w", stdout);
#define dbg(...) cerr << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__)
#else
  ios::sync_with_stdio(0);
  cin.tie(0);
#define endl '\n'
#define dbg(...) 18
#endif
  int n, b, ans = 0;
  cin >> n;
  int a[n];
  for (int i = 0; i < n; i++) cin >> a[i];
  for (int i = 0; i < n; i++) {
    cin >> b;
    if (a[i] > b) ans += (a[i] - b);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3564
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <functional>
#include <vector>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <cassert>
#define InfL 1000000000
#define InfLL 1000000000000000000LL
#define mod 1000000007
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rrep(i,n) for(int (i)=(n-1);(i)>=(0);(i)--)
using namespace std;
typedef long long ll;
typedef double db;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<bool> vb;
typedef vector<db> vd;

int main() {
	int N, K;
	cin >> N >> K;
	vi P(N);
	rep(i, N)
		cin >> P[i];
	vi greater_count(N);
	greater_count[0] = 0; // P[i]>P[i+1]のsum
	rep(i, N - 1)
		greater_count[i + 1] = greater_count[i] + (P[i] > P[i + 1]);
	set<int> P_part;
	rep(i, K)
		P_part.insert(P[i]);
	vb P_part_is_sorted(N - K + 1);
	rep(i, N - K + 1)
		P_part_is_sorted[i] = (greater_count[i + K - 1] == greater_count[i]);
	bool P_part_is_sorted_once = false; // P_partがソート済みである場合が発生したらtrueにして、以後ansに足さない

	int ans = 1;
	if (P_part_is_sorted[0])
		P_part_is_sorted_once = true;
	rep(i, N - K) {
		auto Pmin_it = P_part.begin();
		int Pmin = *Pmin_it;
		P_part.erase(P[i]);
		P_part.insert(P[i + K]);
		auto Pmax_it = P_part.rbegin();
		int Pmax = *Pmax_it;

		if (P_part_is_sorted[i + 1]) {
			ans += !P_part_is_sorted_once;
			P_part_is_sorted_once = true;
		}
		else if (Pmin != P[i] || Pmax != P[i + K])
			ans++;
	}

	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 11136
n = int(input())
S = list(input())

r_cnt, l_cnt = 0, 0

for s in S[::-1]:
    if s == ')':
        r_cnt += 1
    else:
        r_cnt = max(r_cnt-1, 0)

S = ['(']*r_cnt + S

for s in S:
    if s == '(':
        l_cnt += 1
    else:
        l_cnt = max(l_cnt-1, 0)

S = S + [')']*l_cnt

print(*S, sep='')

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define sz(x) (int)(x.size())

signed main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    int n, m;
    cin >> n >> m;
    int ans = 1;
    for (int i = 1; i * i <= m; i++) {
        if (m % i == 0) {
            int j = m / i;
            if (j >= n) {
                ans = max(i , ans);
            }
            if (i >= n) {
                ans = max(ans, j);
            }
        }
    }
    cout << ans << "\n";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define rrep(i,n) for(int i=1;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define maxs(a, b) a = max(a, b)
#define mins(a, b) a = min(a, b)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const ll linf = 1001002003004005006ll;
const int inf = 1001001001;
const int mod = 1000000007;

vector<int> g[100005];
int dist[100005][3];

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n, m;
	cin >> n >> m;
	rep(i, m) {
		int a, b;
		cin >> a >> b;
		a--; b--;
		g[a].emplace_back(b);
	}
	int s, t;
	cin >> s >> t;
	s--; t--;
	memset(dist, -1, sizeof(dist));
	dist[s][0] = 0;
	queue<P> que;
	que.emplace(s, 0);
	while (que.size()) {
		int u = que.front().first;
		int v = que.front().second;
		que.pop();
		for (auto& c : g[u]) {
			int nv = (v + 1) % 3;
			if (dist[c][nv] != -1) continue;
			dist[c][nv] = dist[u][v] + 1;
			que.emplace(c, nv);
		}
	}
	int ans = dist[t][0];
	if (ans == -1) cout << -1 << endl;
	else cout << ans / 3 << endl;
	return 0;
}

Measured memory_bytes: 6912
#include<iostream>
#include<vector>
#include<string>
using namespace std;
int main(void){
int n;
int tanku[]={5,7,5,7,7};
while(1){
cin>>n;
if(n==0)break;
string a;
vector<int> w(n);
for(int i=0;i<n;i++){
	cin>>a;
	w[i]=a.size();
}
int plase;
for(int i=0;i<n;i++){
plase=i;
int sum=0;
int k=0;
bool flag=false;
for(int j=i;j<n;j++){
sum+=w[j];
if(sum>tanku[k])break;
if(sum==tanku[k]){
	k++;
	sum=0;
}
if(k==5){
	flag=true;
	break;
}
}
if(flag){
	cout<<i+1<<endl;
	break;
}
}
}	
return 0;
}

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

using namespace std;

typedef long long ll;
typedef long double ld;

#define mp make_pair
#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define popb pop_back
#define popf pop_front
#define all(v) v.begin(),v.end()

const int maxn = 2e3 + 100;
const ll inf = 2e18, mod = 924844033;

int n, k;
ll dp[maxn][maxn], DP[maxn], NXT[maxn], fact[maxn];
bool mark[maxn];

void PRINT()
{
	for (int i = 0; i <= n; i++)
		cerr << '_' << DP[i];
	cerr << endl;
}

void UPDATE(int cnt)
{
	memset(NXT, 0, sizeof(NXT));
	for (int i = 0; i <= n; i++)
	{
		for (int j = 0; j <= cnt; j++)
			if (i + j <= n)
				NXT[i + j] = (NXT[i + j] + DP[i] * dp[cnt][j] % mod) % mod;
	}
	swap(NXT, DP);
	//PRINT();
}

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

	fact[0] = 1;
	for (int i = 1; i < maxn; i++)
		fact[i] = fact[i - 1] * i % mod;

	DP[0] = 1;
	
	dp[0][0] = dp[1][0] = dp[1][1] = 1;
	for (int i = 2; i < maxn; i++)
	{
		for (int j = 0; j < maxn; j++)
		{
			dp[i][j] = (dp[i][j] + dp[i - 1][j]) % mod;
			if (j)
				dp[i][j] = (dp[i][j] + dp[i - 2][j - 1]) % mod;
		}
	}

	cin >> n >> k;
	for (int i = 0; i < n; i++)
	{
		if (!mark[i])
		{
			mark[i] = true;
			int cnt = 0;
			for (int j = i + k; j < n; j += k)
			{
				cnt++;
				mark[j] = true;
			}
			//cerr << "PATH AT " << i << ' ' << cnt << endl;
			UPDATE(cnt);
			UPDATE(cnt);
		}
	}
	//PRINT();
	ll ans = 0;
	for (int i = 0; i <= n; i++)
	{
		ll sign = (i & 1 ? -1 : 1);
		ans += (DP[i] * fact[n - i] % mod) * sign;
		ans %= mod;
		ans = (ans + mod) % mod;
	}
	cout << ans << endl;
}



Measured memory_bytes: 34688
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int M,H,n,x,y,a,Lx,Rx,Ly,Ry;
    Lx=Ly=0;

    cin>>M>>H>>n;
    Rx=M;
    Ry=H;
    for(int i=0;i<n;i++)
    {
        cin>>x>>y>>a;
        if(a==1)
        {
            if(Lx<x)
                Lx=x;
        }
        else if(a==2)
        {
            if(Rx>x)
                Rx=x;
        }
        else if(a==3)
        {
            if(Ly<y)
                Ly=y;
        }
        else if(a==4){
            if(Ry>y)
            Ry=y;
        }
    }
    if(Rx-Lx<=0 || Ry-Ly<=0)
    {
        cout<<"0\n";
    }
    else {
            int res;
        res=(Rx-Lx)*(Ry-Ly);
        cout<<res<<endl;
    }
}


Measured memory_bytes: 256
# from math import sqrt
# from heapq import heappush, heappop
# from collections import deque


def main():
    N, M = map(int, input().split())

    digit = [-1] * N

    for i in range(M):
        s, c = map(int, input().split())
        s -= 1
        if digit[s] >= 0 and digit[s] != c:
            print(-1)
            exit()
        digit[s] = c

    if N > 1:
        if digit[0] == 0:
            print(-1)
            exit()
        if digit[0] < 0:
            digit[0] = 1

    for i in range(0, N):
        if digit[i] < 0:
            digit[i] = 0

    #    print(digit)
    print("".join(map(str, digit)))


if __name__ == "__main__":
    main()


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



int main(){
    ll n,k;cin>>n>>k;
    ll a[200010],f[200010];
    rep(i,0,n)cin>>a[i];
    rep(i,0,n)cin>>f[i];
    sort(a,a+n);
    sort(f,f+n);
    reverse(f,f+n);
    ll l=-1,r=1e12;
    while(l+1<r){
        ll c=(l+r)/2;
        ll sum=0;
        rep(i,0,n){
            sum+=max(0ll,a[i]-c/f[i]);
        }
        if(sum<=k)r=c;
        else l=c;
    }
    cout<<r<<endl;
}

    









Measured memory_bytes: 3328
#include <iostream>
using namespace std;
int main() {
	int n;
	while(cin>>n) {
		int l[10001];
		l[0] = 2;
		for (int i=1;i<n;i++) {
			l[i]=l[i-1]+i+1;
		}
		cout << l[n-1] << endl;
	}
}

Measured memory_bytes: 0
#include<stdio.h>
#include <stdlib.h>
#include<string.h>
#include<math.h>
#define loop(i, l, r) for(i=l; i<r; i++)/*Instead of function, (for).*/
#define rep(i,r) for(i=0; i<r; i++)
#define Max(a, b) ((a) > (b) ? (a) : (b))
#define Min(a, b) ((a) < (b) ? (a) : (b))
typedef long long int lli;
/*Return Combination ,(nCr)*/
int combi(int n, int r)
{
	if(r==0 || r==n) return 1;
	else return combi(n-1,r) + combi(n-1,r-1);
}
/*Return gcd(a, b)*/
int gcd(int a, int b){
	if(b == 0) return a;
	else return gcd(b, a % b);
}
//qsort�֐��Ɏg��compare�֐�,(long long int, int, double�^)
int compare_lli(const void *a, const void *b)
{
    return *(lli*)a - *(lli*)b;
}
int compare_int(const void *a, const void *b)
{
    return *(int*)a - *(int*)b;
}
int compare_double(const void *a, const void *b)
{
    return *(double*)a - *(double*)b;
}
/*qsort(data, 10, sizeof(int_lli_double), compare_int);*/
/*qsort(�z��, �v�f��, sizeof(�z��̌^), compare_�z��̌^);*/
int chek(int *tmp1, int *tmp2, int n){
	int i;
	for(i=0; i<n; i++){
		if(tmp1[i] != tmp2[i]){
			return 1;
		}
	}
	return 0;
}//2�̔z�񂪈�v���邩�̔���_(return��v��0,�s��v���P)
int Abs(int a){
	if(a>=0) return a;
	else return -1*a;
}
int main(void)
{
	int k;
	int head=1, tail=10;
	scanf("%d", &k);
	lli x, queue[100005];
	for(int i=0; i<10; i++)
		queue[i]=i;
	while(tail <= k){
		x = queue[head++];
		if(x % 10 != 0)
			queue[tail++] = x*10+x%10-1;
		queue[tail++] = x*10+x%10;
		if(x%10 != 9)
			queue[tail++] = x*10+x%10+1;
	}
	printf("%lld", queue[k]);
	return 0;
}

Measured memory_bytes: 896
//#pragma GCC optimize("Ofast","unroll-loops","omit-frame-pointer","inline") //Optimization flags
//#pragma GCC option("arch=native","tune=native","no-zero-upper") //Enable AVX
//#pragma GCC target("avx2")  //Enable AVX
#include<bits/stdc++.h>
using namespace std;

#define all(a) a.begin(),a.end()
#define F first
#define S second
#define pb push_back
#define ll long long
#define vi vector<int>
#define pi pair<int,int>
#define mp make_pair
 
#ifdef LOCAL
#include "debug.h"
#else
#define debug(...) 42
#endif
 
const int mod=1e9+7;
 
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
int mul(int a,int b){
  return ((a)*1ll*(b))%mod;
}
 
void add(int &a,int b){
  a+=b;
  if(a>=mod)a-=mod;
}
 
int sub(int a,int b){
  a-=b;
  if(a<0){
    a+=mod;
  }
  return a;
}
 
int powz(int a,int b){
  int res=1;
  while(b){
    if(b&1){
      res=mul(res,a);
    }
    b/=2;
    a=mul(a,a);
  }
  return res;
}
 
template <typename A, typename B>
istream& operator>>(istream& input,pair<A,B>& x) {
  input>>x.F>>x.S;
  return input;
}
 
template <typename A>
istream& operator>>(istream& input,vector<A>& x) {
  for(auto& i:x)
    input>>i;
  return input;
}
 
template<typename A>
ostream& operator<<(ostream& output,vector<A>& x) {
  for(auto& i:x)
    output<<i<<' ';
  return output;
}
 
const int N=2000002;

struct ST{
  vector<ll>t;
  ST(int n){
    t.resize(4*n);
  }
  void update(int v, int tl, int tr, int l, int r, int add) {
    if (l > r)
      return;
    if (l == tl && r == tr) {
      t[v] += add;
    } else {
      int tm = (tl + tr) / 2;
      update(v*2, tl, tm, l, min(r, tm), add);
      update(v*2+1, tm+1, tr, max(l, tm+1), r, add);
    }
  }

  ll get(int v, int tl, int tr, int pos) {
    if (tl == tr)
      return t[v];
    int tm = (tl + tr) / 2;
    if (pos <= tm)
      return t[v] + get(v*2, tl, tm, pos);
    else
      return t[v] + get(v*2+1, tm+1, tr, pos);
  }

};


void solve(){
  int n,m;
  cin>>n>>m;
  vi a(n);
  cin>>a;
  ST st1(m+1),st2(m+1);
  for(int i=1;i<n;i++){
    if(a[i]==a[i-1]){
      continue;
    }
    int j=i;
    if(a[j-1]<a[j]){
      st1.update(1,1,m,a[j-1]+1,a[j],a[j-1]);
      st2.update(1,1,m,a[j-1]+1,a[j],1);
    }
    if(a[j]<a[j-1]){
      st1.update(1,1,m,a[j-1]+1,m,a[j-1]);
      st2.update(1,1,m,a[j-1]+1,m,1);
      st1.update(1,1,m,1,a[j],a[j-1]-m);
      st2.update(1,1,m,1,a[j],1);
    }
  }
  ll ans=0;
  for(int i=1;i<=m;i++){
    ans=max(ans,st2.get(1,1,m,i)*1ll*(i-1)-st1.get(1,1,m,i));
    debug(i,st2.get(1,1,m,i),st1.get(1,1,m,i),ans);
  }
  debug(ans);
  ans*=-1;
  for(int i=1;i<n;i++){
    int j=i;
    ans+=(a[j]>=a[j-1]?a[j]-a[j-1]:m-a[j-1]+a[j]);
  }
  cout<<ans;
 
  
}  
 
signed main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int tc=1;
  //~cin>>tc;
  for(int _=0;_<tc;_++){
    // cout<<"Case #"<<_+1<<": ";
    solve();
    if(_!=tc-1){
      cout<<'\n';
    }
  }
}


Measured memory_bytes: 6912
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long long ll;
const ll MOD = 1000000007;
#define SortAsc(c) std::sort(c.begin(), c.end())
#define SortDesc(c) std::sort(c.rbegin(), c.rend())
int dx[8] = {0, 1, 0, -1, 1, 1, -1, -1};
int dy[8] = {1, 0, -1, 0, 1, -1, 1, -1};

int main() {
  int K, A, B;
  cin >> K >> A >> B;
  for (int i = A; i <= B; i++) {
    if (i % K == 0) {
      cout << "OK" << endl;
      return 0;
    }
  }
  cout << "NG" << endl;
}

Measured memory_bytes: 3596
#include <bits/stdc++.h>
#include <iostream>
#include <math.h>
using namespace std;
int main() {
    int H, A;
    cin >> H >> A;
    int count = H / A;
    if (H % A != 0) {
        count += 1;
    }

    cout << count << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<cstdio>
#include<climits>
#include<cmath>
#include<cstring>
#include<string>
#include<complex>
#include<map>

#define f first
#define s second
#define mp make_pair

#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define FOR(i,c) for(__typeof((c).begin()) i=(c).begin(); i!=(c).end(); i++)
#define ALL(c) (c).begin(), (c).end()
#define EPS (1e-10)
using namespace std;

typedef unsigned int uint;
typedef long long ll;
typedef complex<double> P;

int main(){
  double x[6];
  double y[6];
  while(2==scanf("%lf,%lf,",&x[1],&y[1])){
    REP(i,3) scanf("%lf,%lf,",&x[i+2],&y[i+2]);
    x[5] = x[1];
    x[0] = x[4];
    y[5] = y[1];
    y[0] = y[4];
    int ans = 0;
    REP(i,4){
      double dx1 = x[i+1] - x[i];
      double dx2 = x[i+2] - x[i+1];
      double dy1 = y[i+1] - y[i];
      double dy2 = y[i+2] - y[i+1];
      if(dx1 * dy2 < dx2 * dy1) ans++;
      else ans--;
    }
    if(ans == 4 || ans == -4) ans = 1;
    else ans = 0;
    puts(ans?"YES":"NO");
  }
  return 0;
}

Measured memory_bytes: 0
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
 
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
 
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

H, W = MAP()
S = [input() for i in range(H)]

dx = [-1, 0, 1, 0]
dy = [0, 1, 0, -1]

for h in range(H):
    for w in range(W):
        if S[h][w] == "#":
            cnt = 0
            for i in range(4):
                if 0 <= h + dy[i] < H and 0 <= w + dx[i] < W:
                    if S[h+dy[i]][w+dx[i]] == "#":
                        cnt += 1
            if cnt == 0:
                print("No")
                exit()
print("Yes")
                

Measured memory_bytes: 5192
package main

import (
	"fmt"
	"math"
)

func main() {
	var N int
	fmt.Scan(&N)

	if N%2 == 0 {
		fmt.Println(0.5)
	} else {
		a := math.Ceil(float64(N)/2.0) / float64(N)
		fmt.Println(a)
	}
}


Measured memory_bytes: 512
s = int(input())
if s<=10**9:
    print(0,0,0,1,s,0)
elif s <10**18:
    b = 10**9-s%(10**9)
    c = 1
    a = 10**9
    d = (s+b)//a
    print(0,0,a,b,c,d)
else:
    print(0,0,10**9,0,0,10**9)

Measured memory_bytes: 38384
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		try (Scanner sc = new Scanner(System.in)) {
			// 整数の入力
			long a = sc.nextLong();
			long b = sc.nextLong();

			StringBuilder sb = new StringBuilder();
			if (a < b) {
				for (int i = 0; i < b; i++) {
					sb.append(a);
				}
			} else {
				for (int i = 0; i < a; i++) {
					sb.append(b);
				}

			}
			System.out.println(sb);
		}
	}

	/**
	 * 最小公倍数
	 */
	static long lcm(long a, long b) {
		long temp;
		long c = a;
		c *= b;
		while ((temp = a % b) != 0) {
			a = b;
			b = temp;
		}
		return c / b;
	}

	/**
	 * 最大公約数
	 */
	static long gcd(long a, long b) {
		long temp;
		while ((temp = a % b) != 0) {
			a = b;
			b = temp;
		}
		return b;
	}
}


Measured memory_bytes: 23892
#include <bits/stdc++.h>
using namespace std; typedef long double ld; typedef long long ll;
typedef unsigned long long ull;
#define MP make_pair
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define FORR(x,arr) for(auto& x:arr)
#define VI vector<int>
#define PII pair<int, int>
#define FI first 
#define SE second
#define ALL(x) (x).begin(), (x).end()
const int INF=1<<30; const ll LINF=1LL<<60 ; const ll MOD=1e9+7 ;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
//-------------------
string s;

int main(){
    cin >> s;
    int ans1=0, ans2=0;
    FOR(i,0,s.size()-1){
        if(i%2==0){
            if(s[i] == '1') ans1 += 1;
        }else{
            if(s[i] == '0') ans1 += 1;
        }
    }
    FOR(i,0,s.size()-1){
        if(i%2==0){
            if(s[i] == '0') ans2 += 1;
        }else{
            if(s[i] == '1') ans2 += 1;
        }
    }
    cout << min(ans1,ans2);
    return 0;
}


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

//Math/ModInt
template<long long mod = 1000000007>
struct modint{
	long long a;

	modint() : a(0){}
	modint(long long t){
		a = t % mod;
		if(a < 0) a += mod;
	}

	operator long long() const{ return a; }

	bool operator==(const modint &x) const{ return a == x.a; }
	bool operator!=(const modint &x) const{ return a != x.a; }

	modint operator-() const{ return modint(a ? (mod - a) : 0); }
	modint operator~() const{ return pow(mod - 2); }

	modint operator+(const modint &x) const{ return modint(*this) += x; }
	modint operator-(const modint &x) const{ return modint(*this) -= x; }
	modint operator*(const modint &x) const{ return modint(*this) *= x; }
	modint operator/(const modint &x) const{ return modint(*this) /= x; }

	modint &operator+=(const modint &x){
		a += x.a;
		if(a >= mod) a -= mod;
		return *this;
	}
	modint &operator-=(const modint &x){
		a -= x.a;
		if(a < 0) a += mod;
		return *this;
	}
	modint &operator*=(const modint &x){
		a = a * x.a % mod;
		return *this;
	}
	modint &operator/=(const modint &x){
		a = a * (~x).a % mod; 
		return *this;
	}

	modint &operator++(){ return (*this) += 1; }
	modint &operator--(){ return (*this) -= 1; }
	modint &operator++(int){
		modint tmp = *this;
		(*this) += 1;
		return tmp;
	}
	modint &operator--(int){
		modint tmp = *this;
		(*this) -= 1;
		return tmp;
	}

	friend ostream &operator<<(ostream &os,const modint &x){
		return os << x.a;
	}
	friend istream &operator>>(istream &is,modint &x){
		long long t;
		is >> t;
		x = modint(t);
		return is;
	}

	modint pow(long long x) const{
		modint ret = 1,tmp = a;
		for(;x;tmp *= tmp,x >>= 1){
			if(x & 1) ret *= tmp;
		}
		return ret;
	}
};

//Math/Combination
template<class T>
struct Combination{
	vector<T> fact,factinv;
	Combination(int n) : fact(n + 1),factinv(n + 1){
		fact[0] = 1;
		for(int i = 1;i <= n;i++) fact[i] = fact[i - 1] * T(i);
		factinv[n] = ~fact[n];
		for(int i = n;i >= 1;i--) factinv[i - 1] = factinv[i] * T(i);
	}
	T nCr(int n,int r){
		if(r < 0 || n < r) return 0;
		return fact[n] * factinv[r] * factinv[n - r];
	}
};

const int MOD = 1000003;

signed main(){
	int q;
	scanf("%d",&q);
	Combination<modint<MOD>> comb(MOD - 1);
	for(int i = 0;i < q;i++){
		int x,d,n;
		scanf("%d %d %d",&x,&d,&n);
		modint<MOD> mx = x,md = d;
		if(!d) printf("%d\n",mx.pow(n));
		else if(n >= MOD) puts("0");
		else printf("%d\n",comb.fact[n] * comb.nCr(-mx / md,n) * (-md).pow(n));
	}
}


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

int main() {
	int x, y;

	while (1) {
		cin >> x >> y;
		if (x == 0 && y == 0) break;
		else if (x <= y) cout << x << " " << y << endl;
		else cout << y << " " << x << endl;
	}
	
	return 0;
}


Measured memory_bytes: 3072
def printField(l):
    h = len(l)
    w = len(l[0])
    for i in range(h):
        for j in range(w):
            print(l[i][j], end='')
        print()


h, w = map(int, input().split())
l = [list(input()) for _ in range(h)]
# print(l)

for i in range(h):
        for j in range(w -1):
            if (l[i][j] != '.' and l[i][j+1] != '.'):
                l[i][j] = '$'
                l[i][j+1] = '$'
# printField(l)
# print('========================')

for j in range(w):
    for i in range(h -1):
        if (l[i][j] != '.' and l[i + 1][j] != '.'):
            l[i][j] = '$'
            l[i + 1][j] = '$'
# printField(l)

flag = False
for sl in l:
    for s in sl:
        if s == '#':
            flag = True
            break
    if flag:
        break

if flag:
    print('No')
else:
    print('Yes')


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

int main(){
	
  int n;
  
  cin >> n;
  
  if(n % 2 == 0){
    cout << 0.5 << endl;
    return 0;
  }
  
  double ans = (double) (n/2 + 1) / n;
    
  cout << ans << endl;
    return 0;
}



Measured memory_bytes: 256