akhauriyash/Code-Regression huggingface dataset:
#include <string>
#include <stack>
#include <stdlib.h>
#include <iostream>
#include <queue>
#include <utility>
using namespace std;


#if 0
queue<pair<string, int>>はダメです。queue<pair<string, int> >の中の’’は必要です。
#endif
pair<string, int> process;
queue<pair<string, int> > Q;
int main()
{
	int j = 0, times = 0;
    int n, q;
	cin >> n >> q;
	for (int i = 0; i<n; i++)
	{
		cin >> process.first >> process.second;
		Q.push(process);
	}
	while (!Q.empty()) {
		process = Q.front(); Q.pop();
		if (process.second > q) {
			process.second -= q;
			times += q;
			Q.push(process);
		}
		else {
			times += process.second;
			cout << process.first << " " << times << endl;
		}
	}
	return 0;
}


Measured memory_bytes: 6240
#include <iostream>
#include <cstring>
#include<vector>
#include <algorithm>
#include<cstdlib>
#include<set>
#include<math.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define rep(i,n) for(ll i=0;i<n;i++)

int main()
{
	int n;
	cin >> n;
	vector<double> a(n);
	for(int i=0;i<n;i++) cin >> a[i];
	vector<double> b(n);
	for(int i=0;i<n;i++) b[i] = 1 / a[i];
	double p, q;
	p = 0;
	for(int i=0;i<n;i++) p += b[i];
	q=1/p;
	cout << q << "\n";


	return 0;
}

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

int main(){
  int N = 5;
  int X[N]; 
  for (int i = 0; i < N; ++i) cin >> X[i];
  int k;
  cin >> k;
  
  int i, j, d, flag;
  flag = 0;
  for(i=0; i<N; ++i){
    for(j=i+1; j<N; ++j){
      d = X[i] - X[j];
      if(d*d > k*k){
        flag = 1;
        break;
      }
    }
  }
  if(flag==1) cout << ":(" << endl;
  else cout << "Yay!" << endl;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef complex<double> P;
typedef pair<double, int> PI;
typedef long long LL;
static const int COUNTER_CLOCKWISE = 1;
static const int CLOCKWISE = -1;
static const int ONLINE_BACK = 2;
static const int ONLINE_FRONT = -2;
static const int ON_SEGMENT = 0;
const double EPS = 1e-10;
double cross(P a, P b) {
	return a.real()*b.imag() - a.imag()*b.real();
}
double dot(P a, P b) {
	return a.real()*b.real() + a.imag()*b.imag();
}
int ccw(P p0, P p1, P p2) {
	P a = p1 - p0;
	P b = p2 - p0;
	if (cross(a, b) > EPS) return COUNTER_CLOCKWISE;
	if (cross(a, b) < -EPS) return CLOCKWISE;
	if (dot(a, b) < -EPS) return ONLINE_BACK;
	if (abs(a) < abs(b)) return ONLINE_FRONT;
	return ON_SEGMENT;
}
bool intersect(P p1, P p2, P p3, P p4) {
	return (ccw(p1, p2, p3)*ccw(p1, p2, p4) <= 0 &&
		ccw(p3, p4, p1)*ccw(p3, p4, p2) <= 0);
}
vector<PI> G[1000];
double dist[1000];
int XA[1000], YA[1000];
int XB[1000], YB[1000];
int main() {
	int NA, NB;
	cin >> NA >> NB;
	for (int i = 0; i < NA; i++) {
		cin >> XA[i] >> YA[i];
	}
	for (int i = 0; i < NB; i++) {
		cin >> XB[i] >> YB[i];
	}
	double ans = 1e10;
	if (!intersect(P(XA[0], YA[0]), P(XA[1], YA[1]), P(XB[0], YB[0]), P(XB[1], YB[1]))) {
		ans = min(ans, abs(P(XA[0], YA[0]) - P(XA[1], YA[1])) + abs(P(XB[0], YB[0]) - P(XB[1], YB[1])));
	}
	for (int i = 0; i < NB; i++) {
		for (int j = 0; j < NB; j++) {
			if (i == j) continue;
			if (intersect(P(XA[0], YA[0]), P(XA[1], YA[1]), P(XB[i], YB[i]), P(XB[j], YB[j]))) continue;
			G[i].emplace_back(abs(P(XB[i], YB[i]) - P(XB[j], YB[j])), j);
		}
	}
	fill(dist, dist + NB, 1e10);
	dist[0] = 0;
	priority_queue<PI, vector<PI>, greater<PI>> Q;
	Q.push(PI(0, 0));
	while (!Q.empty()) {
		PI p = Q.top(); Q.pop();
		if (dist[p.second] < p.first) continue;
		for (PI e : G[p.second]) {
			double cost = p.first + e.first;
			if (dist[e.second] > cost) {
				dist[e.second] = cost;
				Q.push(PI(cost, e.second));
			}
		}
	}
	if (dist[1] < 1e10)
		ans = min(ans, abs(P(XA[0], YA[0]) - P(XA[1], YA[1])) + dist[1]);
	for (int i = 0; i < NB; i++) G[i].clear();
	for (int i = 0; i < NA; i++) {
		for (int j = 0; j < NA; j++) {
			if (i == j) continue;
			if (intersect(P(XA[i], YA[i]), P(XA[j], YA[j]), P(XB[0], YB[0]), P(XB[1], YB[1]))) continue;
			G[i].emplace_back(abs(P(XA[i], YA[i]) - P(XA[j], YA[j])), j);
		}
	}
	fill(dist, dist + NA, 1e10);
	dist[0] = 0;
	Q.push(PI(0, 0));
	while (!Q.empty()) {
		PI p = Q.top(); Q.pop();
		if (dist[p.second] < p.first) continue;
		for (PI e : G[p.second]) {
			double cost = p.first + e.first;
			if (dist[e.second] > cost) {
				dist[e.second] = cost;
				Q.push(PI(cost, e.second));
			}
		}
	}
	if (dist[1] < 1e10)
		ans = min(ans, abs(P(XB[0], YB[0]) - P(XB[1], YB[1])) + dist[1]);
	if (ans == 1e10) {
		cout << -1 << endl;
	}
	else {
		printf("%.15lf\n", ans);
	}
}


Measured memory_bytes: 20092
#include<iostream>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;

int n;
int a[5][5];
int s[5];
int dy[] = {-1,0,1,0}, dx[] = {0,1,0,-1};

int check(void){
  int res = 0;
  for(int d=1;;d++){
    bool dis[5][5] = {0},f = false;
    rep(i,5)rep(j,5){
      if(a[i][j] == 0)continue;
      
      rep(k,2){
	int sy = i, sx = j;
	int c = 0;
	while(sy>=0 && sx>=0 && sy<=4 && sx<=4 && a[sy][sx] == a[i][j]){
	  c++; sy += dy[k]; sx += dx[k];
	}
	if(c<3)continue;
	
	f = true;
	sy = i; sx = j;
	while(sy>=0 && sx>=0 && sy<=4 && sx<=4 && a[sy][sx] == a[i][j]){
	  dis[sy][sx] = true;
	  sy += dy[k]; sx += dx[k];
	}
      }
    }
    if(!f)return res;

    rep(i,5)rep(j,5){
      if(dis[i][j]){
	res += d*s[a[i][j]-1];
	a[i][j] = 0;
      }
    }
    
    rep(i,5){
      for(int j=4;j>=0;j--){
	if(a[j][i] != 0){
	  for(int k=1;k<=4-j;k++){
	    if(a[j+k][i]==0)swap(a[j+k][i],a[j+k-1][i]);
	  }
	}
      }
    }
  }
}

int move(int y,int x,int d){
  int tmp[5][5];
  rep(i,5)rep(j,5)tmp[i][j] = a[i][j];
  int res = check();
  rep(i,5)rep(j,5)a[i][j] = tmp[i][j];
  if(d==n)return res;

  rep(k,4){
    int sy = y+dy[k], sx = x+dx[k];
    if(sy<0 || sy>4 || sx<0 || sx>4)continue;
    swap(a[y][x],a[sy][sx]);
    res = max(res,move(sy,sx,d+1));
    swap(a[y][x],a[sy][sx]);
  }
  return res;
}     

int solve(){
  int res = 0;
  rep(i,5)rep(j,5)res = max(res,move(i,j,0));
  return res;
}

int main(){
  while(cin >> n,n>=0){
    rep(i,5)rep(j,5)cin >> a[i][j];
    rep(i,5)cin >> s[i];
    cout << solve() << endl;
  }
}

Measured memory_bytes: 1164
#include <stdio.h>

int main(){
	int N,flag = 0;
	int i = 1;
	scanf("%d",&N);
	//１番Nに近い2のn乗を求める
	while(i<=N){
		i *= 2;
	}
	i /= 2;//やりすぎたので修正
	//上で求めたやつからスタートして、上から調べていく
	for(;i>1;i/=2){
		for(int j=N;j>0;j--){
			if(j%i==0){
				flag=1;
				break;
			}
		}
		if(flag == 1)
			break;
	}
	printf("%d",i);
}

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

#define Q int t; scanf("%d", &t); for(int q=1; q<=t; q++)
typedef long long int lli;
typedef pair<int, int> pi;

#define N 100010
vector<int> adj[N];
vector<int> we[N];
vector<int> col(N);
bool vis[N];

void dfs(int x, int co)
{
    vis[x] = true;
    col[x] = co;
    for(int i=0; i<adj[x].size(); i++){
        int y = adj[x][i];
        if(vis[y] == false){
            int ff = we[x][i]%2 != 0;
            dfs(y, (co+ff)%2);
        }
    }
}

int main()
{
    int n;
    cin >> n;
    int nn = n;
    while(--n){
        int u, v, w;
        cin >> u >> v >> w;
        adj[u].push_back(v);
        adj[v].push_back(u);
        we[v].push_back(w);
        we[u].push_back(w);
    }
    dfs(1, 0);
    for(int i=1; i<=nn; i++){
        cout << col[i] << "\n";
    }

    return 0;
}


Measured memory_bytes: 13696
#include "stdio.h"
#include <vector>
#include <string>
#include <iostream>
#include <algorithm>

using namespace std;

class Puzzle
{
public:
	vector<int> S;
	vector<int> T;

	void input()
	{
		int N, Q;
		int buf;

		cin >> N;
		for (int ni = 0; ni < N; ni++) {
			cin >> buf;
			S.push_back(buf);
		}
		cin >> Q;
		for (int ni = 0; ni < Q; ni++) {
			cin >> buf;
			T.push_back(buf);
		}

		sort(S.begin(), S.end());
		sort(T.begin(), T.end());

	}

	void play()
	{
		int cnt = 0;
		for (int ti = 0; ti < T.size(); ti++) {
			for (int si = 0; si < S.size(); si++) {
				if (S[si] == T[ti]) {
					cnt++;
					break;
				}
				if (S[si] > T[ti]) break;
			}
		}

		printf("%d\n", cnt);
	}
};


int main()
{
	Puzzle puz;

	puz.input();
	puz.play();

    return 0;
}




Measured memory_bytes: 3296
n = int(input())
if n < 105:
    print(0)
else:
    x = 0
    for i in range(105, n + 1):
        if i % 2 == 1:
            c = 0
            for j in range(1, i + 1):
                if i % j == 0:
                    c += 1
            if c == 8:
                x += 1
    print(x)

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

class Dice
{
private:
  int number[6], size, temporary;
  string order;

public:
  void SetData()
  {
    for(int i = 0; i < 6; i++)
    {
      cin >> number[i];
    }
    cin >> order;
    size = order.size();
  }

  void Rotation(int b, int c, int d)
  {
    b--;
    c--;
    d--;

    temporary = number[0];
    number[0] = number[d];
    number[d] = number[c];
    number[c] = number[b];
    number[b] = temporary;
  }

  void OrderHandle(int a)
  {
    if(order[a] == 'E')
    {
      Rotation(3, 6, 4);
    }
    if(order[a] == 'N')
    {
      Rotation(5, 6, 2);
    }
    if(order[a] == 'S')
    {
      Rotation(2, 6, 5);
    }
    if(order[a] == 'W')
    {
      Rotation(4, 6, 3);
    }
  }

  int Conclusion()
  {
    for(int i = 0; i < size; i++)
    {
      OrderHandle(i);
    }

    return number[0];
  }
};

int main()
{
  Dice dice;

  dice.SetData();

  cout << dice.Conclusion() << endl;

  return 0;
}


Measured memory_bytes: 3184
import java.util.*;

public class Main{
    public static void main(String[] args){
        Scanner scan = new java.util.Scanner(System.in);
        int k = scan.nextInt();
        int x = scan.nextInt();
        if(500 * k >= x){
            System.out.println("Yes");
        }else{
            System.out.println("No");
        }
    }
}

Measured memory_bytes: 21972
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<int(N);++i)
#define rep1(i,N) for(int i=1;i<int(N);++i)
#define all(a) (a).begin(),(a).end()		//sort(all(vi S)) sort(all(string S))

typedef long long ll;
typedef vector<int> vi;
typedef set<int> seti;
typedef vector<string> vs;

const int MOD = 1e9+7;
const int INF = 1e9;

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

Measured memory_bytes: 256
Module Module1

    Sub Main()
        'let
        Dim N As Long = Console.ReadLine()
        Dim A() As String = Console.ReadLine().Split()

        'var
        Dim ans As Long = Long.MaxValue

        For i As Long = 0 To N - 1
            'var
            Dim cnt As Long = 0
            Dim j As Long = CLng(A(i))

            While j Mod 2 = 0
                cnt += 1
                j \= 2
            End While

            ans = Math.Min(ans, cnt)
        Next

        Console.WriteLine(ans)

    End Sub

End Module

Measured memory_bytes: 11220
import java.util.*;
public class Main {
	static Scanner s = new Scanner(System.in);
	public static void main(String __[]){
		solve(s.next());
	}
	private static final void solve(String s) {
		int count=0;
		for(int i=1;i<s.length();i++)
			if(s.charAt(i)!=s.charAt(i-1))
				count++;
		System.out.println(count);
	}
}


Measured memory_bytes: 24356
N = int(input())
okodukais = [[elem for elem in input().split()] for _ in range(N)]
BTC_TO_YEN = 380000.
summed_otoshidama = 0
for x, u in okodukais:
    if u == "JPY":
        summed_otoshidama += float(x)
    else:
        summed_otoshidama += BTC_TO_YEN * float(x)
print(summed_otoshidama)


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

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

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

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

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

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

ll ngcd(vector<ll> a) {
  ll res = a[0];
  for(ll i=1; i<a.size() && res!=1; i++) res = gcd(a[i], res);
  return res;
}
ll nlcm(vector<ll> a){
  ll res = a[0];
  for(ll i=1; i<a.size(); i++) res = lcm(a[i], res);
  return res;
}
bool is_prime(ll n) {
  if(n < 2) return false;
  for (ll i = 2; i * i <= n; i++) if (n % i == 0) return false;
  return true;
}
ll digsum(ll n) {
  ll res=0;
  while(n) res += n%10, n /= 10;
  return res;
}
ll digcnt(ll n){
  ll res=0;
  while(n) res++, n /= 10;
  return res;
}
vector<ll> divisor(ll n) {
  vector<ll> res;
  for (ll i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      res.push_back(i);
      if (i != n / i) res.push_back(n / i);
    }
  }
  sort(res.begin(), res.end());
  return res;
}
map<ll, ll> prime_factor(ll n) {
  map<ll, ll> res;
  for (ll i = 2; i * i <= n; i++) {
    while (n % i == 0) ++res[i], n /= i;
  }
  if (n != 1) res[n] = 1;
  return res;
}

signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  ll a,b,c; cin>>a>>b>>c;
  ll x=gcd(a,b);
  if(c%x==0) cout<<"YES"<<endl;
  else cout<<"NO"<<endl;
}

Measured memory_bytes: 256
#include "iostream"
#include "math.h"
#include "algorithm"
#include "string"
#include "vector"
#include "cmath"
#include "numeric"
using namespace std;

int main() {
	int n;
	cin >> n;
	int a[200005] = {};
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
	}
	long ans = 0;
	int searchNum = 1;
	for (int i = 1; i <= n; i++) {
		if (a[i] == searchNum) {
			searchNum++;
		}
	}
	if (searchNum == 1) {
		ans = -1;
	}
	else {
		ans = n - (searchNum - 1);
	}
	cout << ans << endl;
}

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

int main(){
    int N;cin>>N;
    int cnt=0;
    vector<int> A(N,0);
    REP(i,N){
        int a;cin>>a;
        if(a%2==0&&(a%3==0||a%5==0))cnt++;
        if(a%2!=0)cnt++;
    }
    if(cnt==N)cout<<"APPROVED"<<endl;
    else cout<<"DENIED"<<endl;
}

Measured memory_bytes: 256
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <deque>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <utility>
#include <iostream>
#include <algorithm>
#include <functional>

using namespace std;

#define INF (1 << 30)
#define INFL (1LL << 62)
#define MOD7 1000000007
#define MOD9 1000000009
#define EPS 1e-10

#define ll long long
#define ull unsigned long long
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pul pair<ull, ull>
#define all(a) (a).begin(), (a).end()
#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);--i)
#define REP(i,n) for (int i=0;i<(n);++i)
#define RREP(i,n) for (int i=(n)-1;i>=0;--i)

void YES() { cout << "YES" << endl; }
void NO() { cout << "NO" << endl; }
void Yes() { cout << "Yes" << endl; }
void No() { cout << "No" << endl; }
void yes() { cout << "yes" << endl; }
void no() { cout << "no" << endl; }
void Taka() { cout << "Takahashi" << endl; }
void Aoki() { cout << "Aoki" << endl; }
void digit(int d) { cout << fixed << setprecision(d); }
void IOup() { cin.tie(0); ios::sync_with_stdio(false); }

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

	int ans = 0;
	for (int i = 1; i <= 100; ++i) {
		int cnt = 0;
		for (int j = 0; j < n; ++j)
			if (a[j] >= i)
				cnt++;
		if (cnt >= i)
			ans = i;
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 3088
//
// Created by HSK on 2017. 10. 14..
//

#include <bits/stdc++.h>
using namespace std;

const int MAX_N = 51;
int N, M;
int disc[MAX_N + 1], d;
vector<vector<int>> vt;
vector<pair<int, int>> res;

int dfs(int here, int par) {
  disc[here] = ++d;
  int ret = disc[here];
  for (int there : vt[here]) {
    if (there == par) {
      continue;
    }
    if (!disc[there]) {
      int df = dfs(there, here);
      if (df > disc[here]) {
        res.push_back({min(here, there), max(here, there)});
      }
      ret = min(ret, df);
    } else
      ret = min(ret, disc[there]);
  }
  return ret;
}

int main() {
  cin >> N >> M;
  vt.resize(N + 1);
  for (int i = 0; i < M; i++) {
    int u, v;
    cin >> u >> v;
    vt[u].push_back(v);
    vt[v].push_back(u);
  }

  for (int i = 0; i < N; i++) {
    if (!disc[i]) {
      dfs(i, 0);
    }
  }
  cout << res.size();
  return 0;
}

Measured memory_bytes: 256
/// 6:46 pm 30/08/20
/// Author: t_bone_289 (An Immature Programmer.... I'm still developing !!)

#include<bits/stdc++.h>

using namespace std;
#define endl '\n'
typedef long long ll;

class DSU {
private:
    vector<ll> parent;
    vector<ll> size;
public:
    explicit DSU(ll n) {
        parent = vector<ll>(n);
        size = vector<ll>(n, 1);
        for (int i = 0; i < n; i++) {
            parent[i] = i;
        }
    }

    ll findSet(ll node) {
        if (node == parent[node]) {
            return node;
        }
        parent[node] = findSet(parent[node]);
        return parent[node];
    }

    bool isSameSet(ll node1, ll node2) {
        return (findSet(node1) == findSet(node2));
    }

    void unionSets(ll node1, ll node2) {
        node1 = findSet(node1);
        node2 = findSet(node2);
        if (node1 != node2) {
            if (size[node1] < size[node2]) {
                swap(node1, node2);
            }
            parent[node2] = node1;
            size[node1] += size[node2];
        }
    }

};

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    ll n, q;
    cin >> n >> q;
    DSU dsu(n);
    while (q--) {
        ll t, u, v;
        cin >> t >> u >> v;
        if (!t) {
            dsu.unionSets(u, v);
        } else {
            cout << dsu.isSameSet(u, v) << endl;
        }
    }
    return 0;
}

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

const int N_MAX = 110;
const int V_MAX = 100010;
long long dp[N_MAX][V_MAX]; // dp[i][j] i番目まで選んだ品物のうち、価値がjを超えるもののうち、最小の重さ

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

    int n, w;
    cin >> n >> w;

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

    for(int i = 0; i < N_MAX; i++){
        for(int j = 0; j < V_MAX; j++){
            dp[i][j] = 1e18;
        }
    }

    dp[0][0] = 0;

    for(int i = 0; i < n; i++){
        for(int j = 0; j < V_MAX; j++){
            if(j - V[i] >= 0){
                dp[i + 1][j] = min(dp[i + 1][j], dp[i][j - V[i]] + W[i]);
            }
            dp[i + 1][j] = min(dp[i + 1][j], dp[i][j]);
        }
    }

    int ans = 0;
    for(int i = 0; i < V_MAX; i++){
        if(dp[n][i] <= w){
            ans = i;
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 86272
#include <stdio.h>
#include <string.h>

int main(void) {
  int N;
  scanf("%d", &N);
  int H[N];
  for (int i = 0; i < N; i++) {
    scanf("%d", H+i);
  }
  int pointer=N-1;
  int max=0;
  while (pointer>=0) {
    int current_max=0;
    for (int i = pointer; i >=0 ; i--) {
      if (H[i]>H[i-1]) {
        pointer = i-1;
        break;
      }
      current_max++;
    }
    if (current_max>max) {
      max = current_max;
    }
  }
  printf("%d\n", max);
  return 0;
}



Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
void factorization(long long n,map<long long ,long long>& mp){
    for(long long i=2;i*i<=n;i++){
        while(n%i==0){
            mp[i]++;
            n /= i;
        }
     }
     if(!(n == 1)) mp[n]++;
}
int main() {
    ll n,p;
    cin >> n >> p;
    map<ll, ll> mp;
    factorization(p, mp);
    ll ans = 1;
    for (auto i : mp) ans *= pow(i.first, (i.second / n));
    cout << ans << endl;
}


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

class P
{
public:
	string str;
	int money;

	void strin()
	{
		char c;
		for(int i = 0; i < 8; i++){
			cin >> c;
			if(c >= '0' && c <= '9')
				str += c;
		}
		cin >> money;
		
	}
	int comp(string xstr)
	{
		for(int i = 0; i < str.size(); i++){
			if(xstr[xstr.size()-str.size()+i] != str[i])
				return 0;
		}
		return money;
	}
};

int n,m;

void solve()
{
	vector<P> model(n),mine(m);

	for(int i = 0; i < n; i++){
		model[i].strin();
//		cout << model[i].str << endl;
	}

	for(int i = 0; i < m; i++)
		cin >> mine[i].str;

	long ans = 0;
	for(int i = 0; i < m; i++){
		for(int j = 0; j < n; j++)
			ans += model[j].comp(mine[i].str);
	}
	cout << ans << endl;
		
}	

int main(void)
{

	while(cin >> n >> m , n | m)
		solve();

	return 0;
}

Measured memory_bytes: 1280
from itertools import combinations
N, A, B, C = map(int, input().split())
l = list(map(int, (input() for _ in range(N))))
z = [A, B, C]

def f(i, x, acc):
    if i == 0:
        return acc
    return min(
        f(
            i - 1,
            list(set(x) - set(t)),
            acc + abs(z[3 - i] - sum(l[j] for j in t)) + 10 * (n - 1)
        )
        for n in range(1, len(x) - i + 2)
        for t in combinations(x, n)
    )


ans = f(3, list(range(N)), 0)
print(ans)


Measured memory_bytes: 3064
import collections

h, w = map(int, input().split())
s = [input() for _ in range(h)]
r = [[1, 0], [-1, 0], [0, 1], [0, -1]]


def bfs(i, j):
    global h, w, r
    f = [-1 for _ in range(h * w)]
    que = [[] for _ in range(h * w)]
    que[0].append([i, j])
    for k in range(h * w):
        if que[k]:
            res = k
            for i, j in que[k]:
                f[i * w + j] = k
                for sr in r:
                    ti = i + sr[0]
                    tj = j + sr[1]
                    if ti >= 0 and tj >= 0 and ti < h and tj < w:
                        if s[ti][tj] == ".":
                            if f[ti * w + tj] == -1:
                                que[k + 1].append([ti, tj])
    return res


fl = 0
for i in range(h):
    if "#" in s[i]:
        fl = 1
        break
if fl == 0:
    print(h + w - 2)
else:
    res = 0
    for i in range(h):
        for j in range(w):
            if s[i][j] == ".":
                res = max(res, bfs(i, j))
    print(res)


Measured memory_bytes: 45932
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin >> n;
    int a[n];
    for (int i = 0;i<n;i++){
        scanf("%d",&a[i]);
        // cout << a[i];
        }
    sort(a,a+n);
    // cout << a[-1] << endl;
    // for (auto e: a){
    //     cout << e << endl;
    // }
    
    
    int alice = 0;
    int bob = 0;
    for (auto j = n-1; j>=0; j--) {
        if (j % 2 == 0) { alice += a[j]; 
        }
        else { bob += a[j]; }
    }
    
    
    cout << abs(alice - bob) << endl;
    
    // cout << n;
    // if (n % 500 <= a) {cout << "Yes";}
    // else {cout << "No";}
    return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize("O3")
#include<bits/stdc++.h>
#define rc(x) return cout<<x<<endl,0
#define pb push_back
#define in insert
#define er erase
#define fr first
#define sc second
using namespace std;
typedef long long ll;
const long long llnrm=LLONG_MAX;
const int nrm=INT_MAX;
const int nrn=INT_MIN;
const int nmax=1e5+5;
const int mod=1e9+7;
const int lim=1e8;
ll n,ans,mx=nrn,x,y;
int main()
{
    ios_base::sync_with_stdio(false);cin.tie(0);cerr.tie(0);cout.tie(0);
    //freopen("solution.in","r",stdin);
	//freopen("solution.out","w",stdout);
    cin>>x>>y;
    while(x<=y)
    {
        ans++;
        x<<=1;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
)

func out(x ...interface{}) {
	fmt.Println(x...)
}

var sc = bufio.NewScanner(os.Stdin)

func getInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func getString() string {
	sc.Scan()
	return sc.Text()
}

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

func main() {
	sc.Split(bufio.ScanWords)

	N, K := getInt(), getInt()
	a := make([]int, N)
	for i := 0; i < N; i++ {
		a[i] = getInt()
	}

	sort.Ints(a)

	sum := 0
	ans := N
	for i := len(a) - 1; i >= 0; i-- {
		if a[i]+sum < K {
			sum += a[i]
		} else {
			ans = min(ans, i)
		}
	}
	out(ans)
}


Measured memory_bytes: 768
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> V;
#define rep(i,e) for(ll i=0;i<e;i++ )
typedef pair<ll,ll> P;
const ll mod = 1e9+7;
const ll INF = INT64_MAX;


ll i;

long long ruijou(long long x, long long y){
    if(y==0) return 1;
    else if(y%2==0) return ruijou(x*x%mod,y/2);
    else return x*ruijou(x,y-1)%mod;
}

int main(){
    ll N;
    cin>>N;
    V A(N);
    rep(i,N)cin>>A.at(i);
    map<ll,ll> sos;
    rep(i,N){
        ll ka=A.at(i);
        for(ll j=2;j*j<=A.at(i);j++){
            ll cnt=0;
            while(ka%j==0){
                ka/=j;
                cnt++;
            }
            if(cnt){
                if(sos.count(j))sos[j]=max(sos[j],cnt);
                else sos[j]=cnt;
            }
        }
        if(ka!=1){
            if(sos.count(ka))sos[ka]=max(sos[ka],1LL);
            else sos[ka]=1;
        }
    }
    ll lcm=1;
    for(auto itr=sos.begin();itr!=sos.end();itr++){
        ll x=itr->first;
        ll y=itr->second;
        lcm=lcm*ruijou(x,y)%mod;
    }
    ll ans=0;
    rep(i,N){
        ans=(ans+(lcm*(ruijou(A.at(i),mod-2)%mod)))%mod;
    }
    
    cout<<ans<<endl;


}


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

int main(){
  int n,i,j,mini,tmp,count,swapped;
  scanf("%d",&n);
  int a[n];
  for(i=0; i<n; i++){
    scanf("%d",&a[i]);
  }
  swapped =0;
  count = 0;
  for(i=0; i<n; i++){
    mini = i;
    for(j=i; j<n; j++){
      if(a[mini]>a[j]){
        mini = j;
        swapped = 1;
      }
    }
      tmp = a[i];
      a[i] = a[mini];
      a[mini] = tmp;
      count += swapped;
      swapped = 0;
  }

  for(i=0; i<n; i++){
    printf("%d",a[i]);
    if(i!=n-1){
      printf(" ");
    }else{
      printf("\n");
    }
  }

  printf("%d\n",count);
  return 0;
}

Measured memory_bytes: 3208
#include<cstdio>

unsigned int grundy(unsigned int x, unsigned int k) {
	unsigned int q = x / k;
	unsigned int r = x % k;
	if(r == 0) {
		return q;
	} else {
		return grundy(x - ((r+q) / (q+1)) * (q+1), k);
	}
}

int main() {
	int n;
	scanf("%d", &n);
	unsigned int g = 0;
	for(int i=0;i<n;i++) {
		unsigned int a, k;
		scanf("%u %u", &a, &k);
		g ^= grundy(a, k);
	}
	printf("%s\n", g != 0 ? "Takahashi" : "Aoki");
	return 0;
}


Measured memory_bytes: 128
fn solve() {
    let (n, mut k): (usize, usize) = (read::<usize>(), read::<usize>());
    let mut query: Vec<(usize, usize)> = vec![];
    for i in 0..n {
        let (a, b): (usize, usize) = (read::<usize>(), read::<usize>());
        query.push((a, b));
    }
    query.sort();
    let mut cur = 0;
    while let Some(v) = k.checked_sub(query[cur].1) {
        if v == 0 {
            break;
        }
        k = v;
        cur += 1;
    }
    println!("{}", query[cur].0);
}

fn main() {
    let stack_size = 104_857_600;
    let thd = std::thread::Builder::new().stack_size(stack_size);
    thd.spawn(|| solve()).unwrap().join().unwrap();
}

// =========
#[allow(unused_imports)]
use std::cmp::{max, min, Reverse};
#[allow(unused_imports)]
use std::collections::{BinaryHeap, HashMap, HashSet};
#[allow(unused_imports)]
use std::process::exit;

#[allow(dead_code)]
const MOD: usize = 1000000007;

fn read<T: std::str::FromStr>() -> T {
    use std::io::Read;
    let stdin = std::io::stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

// =========


Measured memory_bytes: 3240
//  main.cpp
//  CppTest

#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
using namespace std;

int main(int argc, const char * argv[]) {
    // input from txt （提出時にこの箇所は削除すること）
    std::ifstream in("input.txt");
    std::cin.rdbuf(in.rdbuf());
    
    // cinを高速にするためのおまじない
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    /////////////////////
    // Write code below /
    /////////////////////

    int N,A=0,B=0;
    cin>>N;
    vector<int>a(N);
    for(int i=0;i<N;i++){
        cin>>a.at(i);
    }
    sort(a.begin(),a.end());
    reverse(a.begin(),a.end());
    for(int i=0;i<N;i++){
        if(i%2==0){
            A+=a.at(i);
        }
        else if(i%2==1){
            B+=a.at(i);
        }
    }
    cout<<A-B<<endl;
    
    
    
    
    
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main()
{
	int x, y[100000]={}, i=0, count;

	while(scanf("%d",&x) != EOF){
		while(x>39){
			x-=39;
		}
		y[i]=x;
		i++;
	}

	count=i;

	for (i = 0; i < count; ++i)
	{
		if(y[i]>9)
			printf("3C%d\n", y[i]);
		else
			printf("3C0%d\n", y[i]);

	}
	return 0;
}

Measured memory_bytes: 992
<?php
	while (true) {
		$n = trim(fgets(STDIN));
		list($h, $w) = explode(" ", $n);

		if ($h == 0 && $w == 0) break;

		for ($i = 0; $i < $h; $i++) {
			for ($j = 0; $j < $w; $j++) {
				if ($i > 0 && $i < $h-1 &&
					$j > 0 && $j < $w-1) {
					print ".";
				} else {
					print "#";
				}
			}
			print "\n";
		}

		print "\n";
	}

Measured memory_bytes: 6580
#include <iostream>
#include <numeric>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;
int main(){
  int a,b;
  int ans=0;
  cin>>a>>b;
  string num,front,back;
  for(int i=a;i<=b;i++){
    num=to_string(i);
    if(num.size()%2==0){
      front=num.substr(0,(num.size())/2);
      back=num.substr((num.size())/2,(num.size())/2);
      reverse(back.begin(),back.end());
      if(front==back)ans++;
    }else{
      front=num.substr(0,(num.size())/2);
      back=num.substr(((num.size())/2)+1,(num.size())/2);
      reverse(back.begin(),back.end());
      if(front==back)ans++;
    }
  }
  cout<<ans<<endl;
}


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

typedef long long ll;
const int MAXN=1e5+5;
const int MOD=1e9+7;
const ll INF=2e18;

ll n,A,B;
ll a[MAXN],f[MAXN],s[MAXN];

ll getsum(int l,int r){
    if(l>r) return 0;
    if(!l) return s[r];
    return ((s[r]-s[l-1])%MOD+MOD)%MOD;
}

int main(){

    scanf("%lld%lld%lld",&n,&A,&B);
    if(A<B) swap(A,B);
    for(int i=1;i<=n;i++) scanf("%lld",&a[i]);
    a[0]=-INF,a[n+1]=INF;
    f[0]=s[0]=1;
    int l=0,r=0;
    for(int i=1;i<=n+1;i++){
        while(r+1<i&&a[i]-a[r+1]>=A) r++;
        if(i>=2&&a[i-1]-a[i-2]<B) l=i-2;
        if(a[i]-a[i-1]>=A) f[i]=f[i-1];
        f[i]=(f[i]+getsum(l,min(i-2,r)))%MOD;
        s[i]=s[i-1];
        if(a[i+1]-a[i-1]>=B) s[i]=(f[i]+s[i])%MOD;
    }
    printf("%lld",f[n+1]);

    fclose(stdin);
    fclose(stdout);
}


Measured memory_bytes: 2560
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <utility>
#include <string>
#include <stack>
#include <regex>
#include <numeric>
#include <queue>
#include <set>
 
#define REP(i, n) for (int i = 0; i < n; i++)
#define ALL(v) (v).begin(), (v).end()
 
using namespace std;
 
typedef long long ll;

int main(int argc, char const *argv[])
{
  ll n,a,b,c,d;
  cin >> n >> a >> b >> c >> d;
  string s;
  a--;b--;c--;d--;
  cin >> s;
  ll i = b;
  int num = 0;
  bool ans = true;
  while (i < d)
  {
    i++;
    if (s[i] == '#') num++;
    else num = 0;
    if (num == 2) {
      ans = false;
      break;
    }
  }
  if (!ans) {
    cout << "No" << endl;
    return 0;
  }
  i = a;
  num = 0;
  while (i < c) {
    i++;
    if (s[i] == '#') num++;
    else num = 0;
    if (num == 2) {
      ans = false;
      break;
    }
  }
  if (!ans) {
    cout << "No" << endl;
    return 0;
  }
  if (c > d) {
    ll cnt = 0;
    ans = false;
    ll hoge = min(d+1,(ll)s.size()-1);
    for (ll i = b-1; i <= hoge; i++) {
      if (s[i] == '.') cnt++;
      else cnt = 0;
      if (cnt == 3) {
        ans = true;
        break;
      }
    }
  }
  if (!ans) {
    cout << "No" << endl;
    return 0;
  }
  cout << "Yes" << endl;
  return 0;
};


Measured memory_bytes: 640
# 数字複数
N,M,X,Y = map(int, input().split())

# スペース区切りの整数N個の入力
x = [int(N) for N in input().split()]
y = [int(M) for M in input().split()]

x.append(X)
y.append(Y)

#print('---')
#print(max(x),min(y))

if max(x) < min(y):
    print('No War')
else:
    print('War')    



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

int main(){
    int x,a,b;
    cin>>x;
    bool fin=false;
    for(int i=1;;i++){
        for(int j=-i;j<=i;j++){
            int ch=pow(i,5)-pow(j,5);
            if(ch==x){
                a=i;
                b=j;
                fin=true;
                break;
            }
        }
        if(fin){
            break;
        }
    }
    cout<<a<<' '<<b<<endl;
}

Measured memory_bytes: 4100
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.util.InputMismatchException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskA solver = new TaskA();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskA {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int a = in.nextInt();
            int b = in.nextInt();
            int c = in.nextInt();
            for (int i = 0; i < 1000000; i++) {
                if (a % 2 == 1 || b % 2 == 1 || c % 2 == 1) {
                    out.println(i);
                    return;
                }
                int newa = b / 2 + c / 2;
                int newb = c / 2 + a / 2;
                int newc = a / 2 + b / 2;

                a = newa;
                b = newb;
                c = newc;
            }
            out.println(-1);
        }

    }

    static class InputReader {
        BufferedReader in;
        StringTokenizer tok;

        public String nextString() {
            while (!tok.hasMoreTokens()) {
                try {
                    tok = new StringTokenizer(in.readLine(), " ");
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
            }
            return tok.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(nextString());
        }

        public InputReader(InputStream inputStream) {
            in = new BufferedReader(new InputStreamReader(inputStream));
            tok = new StringTokenizer("");
        }

    }
}



Measured memory_bytes: 23376
#pragma region include
#include <iostream>
#include <iomanip>
#include <stdio.h>

#include <sstream>
#include <algorithm>
#include <iterator>
#include <cmath>
#include <complex>

#include <string>
#include <cstring>
#include <vector>
#include <tuple>
#include <bitset>

#include <queue>
#include <set>
#include <map>
#include <stack>
#include <list>

#include <fstream>
#include <random>
//#include <time.h>
//#include <intrin.h>
#include <ctime>
#pragma endregion //#include
/////////
#define REP(i, x, n) for(int i = x; i < n; ++i)
#define rep(i,n) REP(i,0,n)
#define ALL(X) X.begin(), X.end()
/////////
#pragma region typedef
typedef long long LL;
typedef long double LD;
typedef unsigned long long ULL;
typedef std::pair<LL,LL> PLL;//
typedef std::pair<int,int> PII;//
#pragma endregion //typedef
////定数
const int INF = (int)1e9;
const LL MOD = (LL)1e9+7;
const LL LINF = (LL)4e18+20;
const LD PI = acos(-1.0);
const double EPS = 1e-9;
/////////
using namespace::std;

void solve(){
	int N,X;
	cin >> N;
	X=1;
	while((X<<1)<=N){
		X<<=1;
	}
	cout << X << endl;
}
#pragma region main
signed main(void){
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	std::cout << std::fixed;//小数を10進数表示
	cout << setprecision(16);//小数点以下の桁数を指定//coutとcerrで別	

	solve();
}
#pragma endregion //main()

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string.h>
#include <stack>
#include <queue>
#include <algorithm>
#include <climits>
#include <cmath>
#include <map>
#include <set>
#include <assert.h>
#include <numeric>
#define REP(i,n) for(ll i=0;i<(n);i++)
#define MOD 1000000007
#define int long long
#ifdef int
const long long INF = LLONG_MAX / 10;
#else
const int INF = 1010101010;
#endif
using namespace std;
typedef long long ll;
typedef vector<vector<ll> > mat;
typedef pair<int, int> P;
//typedef pair<double, double> P;
const int dx[9] = {-1, 0, 0, 1, -1, -1, 1, 1, 0};
const int dy[9] = {0, -1, 1, 0, -1, 1, -1, 1, 0};

string N;
 
signed main()
{
  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  cin >> N;

  int ans1 = (N[0] - '0' - 1) + (9 * (N.length() - 1));
  int ans2 = 0;
  REP(i,N.length()) ans2 += N[i] - '0';

  cout << max(ans1, ans2) << endl;
}

Measured memory_bytes: 256
//
//  main.cpp
//  Test
//
//  Created by Nag on 2017/08/18.
//  Copyright ?? 2017??´ Nag. All rights reserved.
//

#include <iostream>
#include <algorithm>
#include <iomanip>
#include <cmath>
#include <vector>
#include <sstream>
#include <string>
#include <cstdio>

using namespace std;

int main(void) {
    int n, x;
    int i, j, k;
    int cnt = 0;
    
    cin >> n >> x;
    
    while( !(n==0 && x==0) ) {
        cnt = 0;
        
        for(i=1; i<=n-2; i++) {
            for(j=i+1; j<=n-1; j++) {
                for(k=j+1; k<=n; k++) {
                    int sum = i + j + k;
                    //cout << i << " " << j << " " << k << " : " << sum << endl;
                    if( sum==x ) cnt++;
                }
            }
        }
        
        cout << cnt << endl;
        
        cin >> n >> x;
    }
    
    return 0;
}

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

namespace ConsoleApp15
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.ReadLine(); //読み飛ばし

            string line = Console.ReadLine();

            int[] nums = line.Split(' ').Select(c => int.Parse(c)).ToArray();

            int count = 0;
            for (int i = 1; i < nums.Length - 1; i++)
            {
                if (Math.Min(nums[i],Math.Min(nums[i-1],nums[i+1])) != nums[i] && Math.Max(nums[i], Math.Max(nums[i - 1], nums[i + 1])) != nums[i] )
                {
                    count++;
                }
            }

            Console.WriteLine(count);
        }
    }
}


Measured memory_bytes: 13268
#include <iostream>
#include <string>

using namespace std;

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

	for (int i = 0; i<5; i++) {
		cout << s[i];

	}

	cout << " ";

	for (int i = 6; i < 13; i++) {
		cout << s[i];
	}

	cout << " ";
	
	for (int i = 14; i < 19; i++) {
		cout << s[i];
	}
	
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(){
  int k,n;
  int i,j,max=0;
  scanf("%d",&k);
  scanf("%d",&n);
  int d[n];
  int tr_d=0,y,start;
  
  for(i=0;i<n;i++){
    scanf("%d",&d[i]);
  }
 
  for(i=0;i<n;i++){
    j = i-1;
    if(j<0) j+=n;
    y = d[i]-d[j];
    if(y<0) y*=-1;
    if(y>(k/2)) y = k-y;
    
    if(max<y)
      max = y;
  }
  tr_d = k-max;
  printf("%d",tr_d);
  return 0;
}

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

const int Maxn = 100005;
const int Maxm = 13;
const int mod = 1000000007;

char str[Maxn];
int slen;
int dp[Maxn][Maxm];

int main()
{
    scanf("%s", str); slen = strlen(str);
    dp[0][0] = 1;
    for (int i = 0; i < slen; i++)
        for (int j = 0; j < Maxm; j++) if (dp[i][j])
            for (int d = 0; d < 10; d++) if (str[i] == '?' || str[i] - '0' == d) {
                int nj = (10 * j + d) % Maxm;
                dp[i + 1][nj] = (dp[i + 1][nj] + dp[i][j]) % mod;
            }
    printf("%d\n", dp[slen][5]);
    return 0;
}


Measured memory_bytes: 5376
#include<bits/stdc++.h>
#include<bits/stdc++.h>
#include <vector>
#define ll long long int
#define ve vector<int>
#define vell vector<ll>
#define pb push_back
#define mod 998244353
using namespace std;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int s,w;cin>>s>>w;
if(w>=s)
{
	cout<<"unsafe";
}
else
{
	cout<<"safe";
}


}
 

Measured memory_bytes: 3612
#include <bits/stdc++.h>
using namespace std;
 
int main() {
int n,l;
  cin>>n>>l;
  vector<int> a(n);
     for (int i = 0; i < n; i++) {
    a[i] =l+i;
  }
  int s=0;
     for (int i = 0; i < n; i++) {
    s +=a[i];
     }
  int ans =10000000;
     for (int i = 0; i < n; i++) {
   int t = s -a[i];
       if(abs(t-s)<abs(ans-s)){
         ans = t;
       }
     }
  cout<<ans<<endl;
  }

Measured memory_bytes: 256
using System;

class Program
{
    static void Main(string[] args)
    {
        int[,] z = new int[50,3000];
        int[] y = new int[50];
        int x = 0;
        while (true)
        {
            string[] u = Console.ReadLine().Split(' ');
            int a = int.Parse(u[0]), b = int.Parse(u[1]);
            if (a == 0 && b == 0)
                break;
            int d = 0;
            for (int i = a; i <= b;)
            {
                if (i % 4 == 0)
                {
                    if (i % 100 == 0)
                    {
                        if (i % 400 == 0)
                        {
                            z[x,d] = i;
                            d++;
                        }
                        goto stop;
                    }
                    z[x,d] = i;
                    d++;
                    stop:;
                    i += 4;
                    goto rt;
                }
                i++;
                rt:;
            }
            if (d == 0)
            {
                z[x,d] = -100;
                d++;
            }
            y[x] = d;
            x++;
        }
        for (int i = 0; i < x; i++)
        {
            if (i != 0)
            {
                Console.WriteLine();
            }
            for (int j = 0; j < y[i]; j++)
            {        
                if (z[i,j] == -100)
                    Console.WriteLine("NA");
                else
                    Console.WriteLine(z[i,j]);
            }
        }
    }
}

Measured memory_bytes: 9544
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <cstring>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <random>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>
#include <limits>
using namespace std;
using ll = long long;
#define fst first
#define snd second

/* clang-format off */
template <class T, size_t D> struct _vec { using type = vector<typename _vec<T, D - 1>::type>; };
template <class T> struct _vec<T, 0> { using type = T; };
template <class T, size_t D> using vec = typename _vec<T, D>::type;
template <class T> vector<T> make_v(size_t size, const T& init) { return vector<T>(size, init); }
template <class... Ts> auto make_v(size_t size, Ts... rest) { return vector<decltype(make_v(rest...))>(size, make_v(rest...)); }
template <class T> inline void chmin(T &a, const T& b) { if (b < a) a = b; }
template <class T> inline void chmax(T &a, const T& b) { if (b > a) a = b; }
/* clang-format on */

using ull = unsigned long long;

const ull MASK30 = (1ull << 30) - 1;
const ull MASK31 = (1ull << 31) - 1;
const ull MOD = (1ull << 61) - 1;
const ull POSITIVIZER = MOD * 3;

ull mul(ull a, ull b) {
    ull au = a >> 31;
    ull ad = a & MASK31;
    ull bu = b >> 31;
    ull bd = b & MASK31;
    ull mid = ad * bu + au * bd;
    ull midu = mid >> 30;
    ull midd = mid & MASK30;
    return au * bu * 2 + midu + (midd << 31) + ad * bd;
}

ull calc_mod(ull val) {
    val = (val & MOD) + (val >> 61);
    if (val > MOD) val -= MOD;
    return val;
}

ull power(ull base, int N) {
  ull res = 1;
  for (int i = 0; i < N; i++) res = calc_mod(mul(res, base));
  return res;
}

ull calc_hash(const vector<int>& a, ull base) {
  ull hash = 0;
  for (int x : a) {
    hash = calc_mod(mul(hash, base) + x);
  }
  return hash;
}

int main() {
#ifdef DEBUG
  ifstream ifs("in.txt");
  cin.rdbuf(ifs.rdbuf());
#endif
  int N;
  while (cin >> N) {
    vector<int> a(N), b(N);
    for (int& x : a) cin >> x;
    for (int& x : b) cin >> x;
    vector<int> a2(N), b2(N);
    for (int i = 0; i < N; i++) a2[i] = (a[i] ^ a[(i + 1) % N]) + 1;
    for (int i = 0; i < N; i++) b2[i] = (b[i] ^ b[(i + 1) % N]) + 1;
    random_device seed_gen;
    default_random_engine engine(seed_gen());
    uniform_int_distribution<ull> dist(1ull << 30, 1ull << 59);
    ull base = dist(engine);
    ull pw = power(base, N);
    ull hash = calc_hash(a2, base), target = calc_hash(b2, base);
    for (int k = 0; k < N; k++) {
      if (hash == target) {
        cout << k << " " << (a[k] ^ b[0]) << endl;
      }
      hash = calc_mod(mul(hash, base));
      hash = calc_mod(hash + POSITIVIZER - mul(pw, a2[k]));
      hash = calc_mod(hash + a2[k]);
    }
  }
  return 0;
}


Measured memory_bytes: 6528
#include <iostream>
#include <algorithm>
#include <utility>
#include <queue>

using namespace std;

typedef pair<int,int> Pa;
int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};

int func(int a[91][91], bool vis[91][91], int s, int t, int h, int w, int c)
{
	int u = c;
	
	for(int i = 0; i < 4; i++){
		int y = s+dy[i], x = t+dx[i];
		if(0 <= y && y < h && 0 <= x && x < w){
			if(a[y][x] == 1 && vis[y][x]){
				vis[s][t] = false;
				u = max(u, func(a, vis, y, x, h, w, c+1));
				vis[s][t] = true;
			}
		}
	}
	
	return u;
}

int main()
{
	int a[91][91], w, h, t;
	bool vis[91][91];
	queue<Pa> que;
	
	while(1){
		cin >> w >> h;
		if(w == 0 && h == 0){
			break;
		}
		for(int i = 0; i < h; i++){
			for(int j = 0; j < w; j++){
				cin >> a[i][j];
				if(a[i][j] == 1){
					que.push(Pa(i,j));
				}
			}
		}
		
		t = 0;
		while(!que.empty()){
			Pa p = que.front();
			que.pop();
			fill(&vis[0][0], &vis[h][w], true);
			t = max(t, func(a, vis, p.first, p.second, h, w, 1));
		}
		cout << t << endl;
	}
	
	return 0;
}

Measured memory_bytes: 0
N=int(input())
a=list(map(int,input().split()))
mp={}
cnt=0
for it in a:
    if it in mp:
        cnt+=1
    else :
        mp[it]=1
N-=cnt
while cnt>=3:
    cnt=cnt//3+cnt%3
print(max(N-int(cnt==1),1))


Measured memory_bytes: 18272
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <iostream>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <fstream>
#include <numeric>
#include <iomanip>
#include <bitset>
#include <list>
#include <stdexcept>
#include <functional>
#include <utility>
#include <ctime>
#include <random>
#include <cassert>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
#define MEM(a,b) memset((a),(b),sizeof(a))
const LL INF = 1e9 + 7;
const int N = 2e5 + 10;

int main()
{
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	int a, b, x;
	cin >> a >> b >> x;
	if (x >= a && x <= a + b) puts("YES");
	else puts("NO");
	return 0;
}


Measured memory_bytes: 256