akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
using namespace std;

int main(){
    int n;
    cin>>n;
    int p[n];
    for(int i=0;i<n;i++){
        cin>>p[i];
    }
    int m=20000;
    for(int i=0;i<=p[0];i++){
        int q[n];
        for(int  j=0;j<n;j++){
            q[j]=p[j];
        }
        int sum=i;
        q[0]-=i;
        for(int j=0;j<=n-2;j++){
            if(q[j]<=0) continue;
            sum+=q[j]*2;
            q[j+1]-=q[j];
        }

        if(q[n-1]>0){
            sum+=q[n-1];
        }

        m=min(m,sum);
    }
    cout<<m<<endl;
    return 0;
}


Measured memory_bytes: 3132
#include <iostream>
#include <ios>
#include <iomanip>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <utility>
#include <typeinfo>
#include <tuple>
using namespace std;

#define MOD 1000000007
#define INF 1e9+7
#define INF_LONG 1e18
#define rep(i, n) for(int i=0; i<n; ++i)
#define rep1(i, n) for(int i=1; i<=n; ++i)
#define rrep(i, m, n) for(int i=m; i<n; ++i)
#define countof(array) (sizeof(array) / sizeof(array[0]))
typedef long long ll;

#define MAX_N 200000
#define MAX_M 100000
#define MAX_V 100
#define MAX_E 100
#define MAX_Q 100000

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

int ddx[] = {-1, 0, 1, 0, -1, 1, -1, 1};
int ddy[] = {0, -1, 0, 1, 1, 1, -1, -1};

string as = {"ABCDEFGHIJKLMNOPQRSTUVWXYZ"};
string ab = {"abcdefghijklmnopqrstuvwxyz"};

ll gcd(ll x, ll y) {
  if(y==0) return x;
  else return gcd(y, x%y);
}

ll lcm(ll x, ll y) {
  return (x*y)/gcd(x, y);
}

void yes() {
  cout << "Yes" << endl;
}

void no() {
  cout << "No" << endl;
}

void print_array(int array[], int len) {

  for(int i=0; i<len; ++i) {
    cout << array[i] << endl;
  }

}

ll absolute(ll x) {
  return (x<0)? (-1)*x : x;
}

//g++ AtCoder.cpp -o AtCoder
//AtCoder

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



int main() {

  string s;
  cin >> s;

  sort(s.begin(), s.end());

  if(s[0]==s[1]&&s[2]==s[3]&&s[0]!=s[3]) yes();
  else no();

  return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <iostream>
#include <sstream>
#include <functional>
#include <map>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <stack>
#include <deque>
#include <set>
#include <list>
#include <numeric>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> P;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const ll INF = 1LL<<29;
const ll mod = 1e9+7;
#define rep(i,n) for(int (i)=0;(i)<(ll)(n);++(i))
#define repd(i,n,d) for(ll (i)=0;(i)<(ll)(n);(i)+=(d))
#define all(v) (v).begin(), (v).end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))
#define mset(m,v) memset((m),(v),sizeof(m))
#define chmin(X,Y) ((X)>(Y)?X=(Y),true:false)
#define chmax(X,Y) ((X)<(Y)?X=(Y),true:false)
#define fst first
#define snd second
#define UNIQUE(x) (x).erase(unique(all(x)),(x).end())
template<class T> ostream &operator<<(ostream &os, const vector<T> &v){int n=v.size();rep(i,n)os<<v[i]<<(i==n-1?"":" ");return os;}
#define N 100010
vector<int> g[N];
int n;
map<P, ll> e;
ll t[N], w[N];
bool used[N];
ll res;

void dfs(int u){
	used[u] = true;
	t[u] = 1;
	for(auto v: g[u]){
		if(used[v]) continue;
		dfs(v);
		t[u] += t[v];
		chmax(w[u], t[v]);
	}
	chmax(w[u], n-t[u]);
}

void dfs2(int u){
	used[u] = true;
	for(auto v: g[u]){
		if(used[v]) continue;
		res += 2*e[P(u, v)]*min(t[v], n-t[v]);
		dfs2(v);
	}
}

int main(){
	cin>>n;
	rep(i, n-1){
		int a, b, c;
		cin>>a>>b>>c;
		a--; b--;
		g[a].push_back(b);
		g[b].push_back(a);
		e[P(a, b)] = e[P(b, a)] = c;
	}
	dfs(0);
	mset(used, 0);
	dfs2(0);
	int wx = 0;
	rep(i, n) if(w[i]<w[wx]) wx = i;
	rep(i, n){
		if(w[i]==w[wx] && i!=wx){
			res -= e[P(i, wx)];
			cout<<res<<endl;
			return 0;
		}
	}
	ll d = 1e9;
	for(auto v: g[wx]){
		chmin(d, e[P(wx, v)]);
	}
	cout<<res-d<<endl;
	return 0;
}


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

#define pb push_back
#define ll long long
#define maxn 200005
#define fr(i,j,k) for(int i=j;i<k;i++)
#define f(n) fr(i,0,n)
#define f1(n) fr(i,1,n+1)
#define ms(i) memset(i,0,sizeof(i));
#define ms1(i) memset(i,-1,sizeof(i));
#define F first
#define S second
const int mod = 1e9+7;

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int c[4] = {};
    int add;
    cin >> add;
    c[add] = 1;
    cin >> add;
    c[add] = 1;
    f1(3){
        if(!c[i]){
            cout << i << endl;
        }
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define ff first
#define ss second
#define quick                    \
    ios::sync_with_stdio(false); \
    cin.tie(0);
#define time cerr << (0.1 * clock()) / CLOCKS_PER_SEC << endl;
#define mod 1000000007
typedef long long ll;
typedef pair<ll, ll> pl;
#define forn(n) for (ll i = 0; i < ll(n); i++)

void solve() {
    ll d, t, s;
    cin >> d >> t >> s;
    if (((d + s - 1) / s) > t) {
        cout << "No\n";
    } else {
        cout << "Yes\n";
    }
}

int main() {
    quick;
    solve();
    // ll t;
    // cin >> t;
    // while (t--) {
    //     solve();
    // }
}

Measured memory_bytes: 3608
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
typedef long long ll;
typedef pair<int, int> P;
const int INF = 100100100;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
map<P, ll> dis{};
int N;
vector<vector<int>> tunagari(0, vector<int>(0, 0));
vector<ll> Ans(0);
void dfs(int sectionid, int beforeid) {
  for (int i = 0; i<tunagari[sectionid].size(); i++) {
    int a = tunagari[sectionid][i];
    int sec = sectionid;
    if (a == beforeid) continue;
    Ans[a] = Ans[sectionid] + dis[P(sectionid, a)];
    dfs(a, sectionid);
  }
}
int main() {
  cin >> N;
  tunagari.resize(N);
  Ans.resize(N);
  REP(i, N - 1) {
    int a, b, c;
    cin >> a >> b >> c, a--, b--;
    dis[P(a, b)] = c;
    dis[P(b, a)] = c;
    tunagari[a].push_back(b);
    tunagari[b].push_back(a);
  }
  int Q, K;
  cin >> Q >> K, K--;
  Ans[K] = 0;
  dfs(K, -1);
  REP(i, Q) { int x, y;
    cin >> x >> y,x--,y--;
    cout << Ans[x] + Ans[y] << endl;
  }
}

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

int main()
{
	int n,i,j;
	cin >> n;//??´??°????????°
	
	long long a[10000], max = 0,min = 0 ,sum = 0;
	
	for(i=0 ;i<n ;i++){
		cin >> a[i];
	}
	
	max = a[0];
	min = a[0];
	for(j=0 ;j<n ; j++){
		if(max < a[j]){
			max = a[j];}
		if(min > a[j]){
			min = a[j];}
		sum = sum + a[j];
	}
	
	cout << min << " " << max << " " << sum <<endl;
	return 0;
}

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

a,b,h,m=map(int,input().split())
nowh=30*h+(30/60)*m
nowm=6*m

if nowh==nowm:
    print(max(a,b)-min(a,b))
elif nowh==0:
    nowm=min(nowm,360-nowm)
    print((a**2+b**2-2*a*b*math.cos(math.radians(nowm)))**0.5)
elif nowm==0:
    nowh=min(nowh,360-nowh)
    print((a**2+b**2-2*a*b*math.cos(math.radians(nowh)))**0.5)
else:
    now=max(nowh,nowm)-min(nowh,nowm)
    print((a**2+b**2-2*a*b*math.cos(math.radians(now)))**0.5)

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

int main ()
{
    int a,b,c;
    cin>>a;
    b=1;
    for(int i=0;i<7;i++){
        b=b*2;
        if(a<b){
            cout<<b/2<<endl;
            return 0;
        }
    }
}

Measured memory_bytes: 256
void main()
{
    long n = rdElem;
    long[] a = n.rdCol;

    writeln(a.any!"a & 1" ? "first" : "second");
}

enum long mod = 10^^9 + 7;
enum long inf = 1L << 60;

T rdElem(T = long)()
if (!is(T == struct))
{
    return readln.chomp.to!T;
}

alias rdStr = rdElem!string;
alias rdDchar = rdElem!(dchar[]);

T rdElem(T)()
if (is(T == struct))
{
    T result;
    string[] input = rdRow!string;
    assert(T.tupleof.length == input.length);
    foreach (i, ref x; result.tupleof)
    {
        x = input[i].to!(typeof(x));
    }
    return result;
}

T[] rdRow(T = long)()
{
    return readln.split.to!(T[]);
}

T[] rdCol(T = long)(long col)
{
    return iota(col).map!(x => rdElem!T).array;
}

T[][] rdMat(T = long)(long col)
{
    return iota(col).map!(x => rdRow!T).array;
}

void rdVals(T...)(ref T data)
{
    string[] input = rdRow!string;
    assert(data.length == input.length);
    foreach (i, ref x; data)
    {
        x = input[i].to!(typeof(x));
    }
}

void wrMat(T = long)(T[][] mat)
{
    foreach (row; mat)
    {
        foreach (j, compo; row)
        {
            compo.write;
            if (j == row.length - 1) writeln;
            else " ".write;
        }
    }
}

import std.stdio;
import std.string;
import std.array;
import std.conv;
import std.algorithm;
import std.range;
import std.math;
import std.numeric;
import std.traits;
import std.container;
import std.functional;
import std.typecons;
import std.ascii;
import std.uni;

Measured memory_bytes: 4092
#include <bits/stdc++.h>
using namespace std;
#define ll int64_t
#define ALL(a)  (a).begin(),(a).end()
 
const ll mod = 1000000007;
const ll LINF = 1e13;
const ll LLINF = 1e18;
const ll ALPHABET = 26;
 
template <class T>
void Swap(T& r, T& l) {
  T tmp = r;
  r = l;
  l = tmp;
}
 
template<typename T>
istream& operator >> (istream& is, vector<T>& vec) {
  for (T& x : vec) is >> x; //for(int i=0; i<vec.size(); i++) is >> x[i]; とかでもいい
  return is;
}


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

    string s;
    cin >> s;

  ll ans = 0;
  char p[3];
  p[0]='A';
  p[1]='B';
  p[2]='C';

  ll tmp = 0;
    for(auto c : s){
      if (p[tmp] == c){
        if (tmp==2){
          tmp=0;
          ans++;
        }else{
          tmp++;
        }
      }else{
        tmp =0;
        if (p[tmp] == c){
          tmp++;
        }
      }
    }


  cout<< ans<<endl;
}


Measured memory_bytes: 256
#include <iostream> 
#include <bits/stdc++.h>
#include<algorithm>
using namespace std;
int main ()
{
  long long int a,b,k;cin>>a>>b>>k;
  if (a<=k) {
      if (b<=(k-a)) {
          cout<<"0"<<" "<<"0"<<endl;
      }
      else {
          cout<<"0"<<" "<<b-(k-a)<<endl;
      }
  }
  else {
      cout<<a-k<<" "<<b<<endl;
  }




}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007

int main() {
	ll n,k;
	cin>>n>>k;
	string s;
	cin>>s;
	s+='2';
	ll l=0,r=0,cnt=0;
	if(s[r]=='0'){
		cnt++;
		for(ll i=0;i<n;i++){
			r=i;
			if(s[i]=='1'&&s[i+1]=='0'){
				break;
			}
		}
	}
	if(cnt!=k){
	for(ll i=1;i<n;i++){
		if(s[i-1]=='1'&&s[i]=='0'){
			cnt++;
			if(cnt>k){
				break;
			}
		}
		r=i;
	}
	}
	ll ans=r-l+1;
//	cout << ans<<endl;
	for(ll i=0;i<n;i++){
		if(s[i]=='0'&&s[i+1]=='1'){
			l=i+1;
			for(ll j=r+1;j<n;j++){
				r=j;
				if(s[j]=='1'&&s[j+1]=='0'){
					break;
				}
			}
			ans=max(r-l+1,ans);
		//	if(ans==7){
		//		cout << l << r<<endl;
		//	}
		}
	}
	cout <<ans;
	// your code goes here
	return 0;
}

Measured memory_bytes: 512
#pragma GCC optimize("O1")
#pragma GCC optimize("O2")
#pragma GCC optimize("O3")
#include<cstdio>
#define N 20002
#define F for(register int i(1);i<=n;i++)
int n,a[N],b[N];
signed main()
{
	scanf("%d",&n);int t;
	F
		a[i]=i*N,b[i]=(n-i+1)*N;
	F
		scanf("%d",&t),a[t]-=(n-i+1);
	F
		printf("%d ",a[i]);
	puts("");
	F
		printf("%d ",b[i]);
	return puts(""),0;
}

Measured memory_bytes: 640
N, Y = map(int, input().split())

a = 10000
b = 5000
c = 1000

flg_exists = False 

for i in range(N + 1) :
    for j in range(N - i + 1) :
        k = N - i - j
        
        if a * i + b * j + c * k == Y and i + j + k == N :
            print(i, j, k)
            flg_exists = True
            break
    if flg_exists == True :
        break
            
if flg_exists == False :
    print(-1, -1, -1)
            
            

Measured memory_bytes: 3064
/*input
32
29 19 7 10 26 32 27 4 11 20 2 8 16 23 5 14 6 12 17 22 18 30 28 24 15 1 25 3 13 21 19 31 9
*/
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<double,double> pdd;
#define IOS ios_base::sync_with_stdio(0); cin.tie(0)
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define F first
#define S second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define pb push_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#ifdef leowang
#define debug(...) do{\
	fprintf(stderr,"%s - %d : (%s) = ",__PRETTY_FUNCTION__,__LINE__,#__VA_ARGS__);\
	_DO(__VA_ARGS__);\
}while(0)
template<typename I> void _DO(I&&x){cerr<<x<<endl;}
template<typename I,typename...T> void _DO(I&&x,T&&...tail){cerr<<x<<", ";_DO(tail...);}
#else
#define debug(...)
#endif
template<typename T1,typename T2>
ostream& operator<<(ostream& out,pair<T1,T2> P){
	out<<'('<<P.F<<','<<P.S<<')';
	return out;
}
//}}}
const ll maxn=300005;
const ll maxlg=__lg(maxn)+2;
const ll INF64=8000000000000000000LL;
const int INF=0x3f3f3f3f;
const ll MOD=ll(1e9+7);
const double PI=acos(-1);
//const ll p=880301;
//const ll P=31;

ll mypow(ll a,ll b){
	ll res=1LL;
	while(b){
		if(b&1) res=res*a%MOD;
		a=a*a%MOD;
		b>>=1;
	}
	return res;
}

map<int,int> mp;
ll a[maxn];

ll inv(int n){
	if(n==1) return 1;
	return (MOD-MOD/n)*inv(MOD%n)%MOD;
}

int main()
{
	//IOS;
	int n;
	cin>>n;
	n++;
	int t;
	REP(i,n){
		int x;
		cin>>x;
		if(mp.count(x)) t=i-mp[x];
		mp[x]=i;
	}
	t=n-t-1;
	ll ans=1;
	REP(i,n){
		ans=ans*inv(i+1)%MOD;
		ans=ans*(n-i)%MOD;
		//cout<<ans<<'\n';
		a[i]=ans;
	}
	//REP(i,n) cout<<a[i]<<" \n"[i==n-1];
	ans=1;
	REP(i,t+1){
		a[i]-=ans;
		if(a[i]<0) a[i]+=MOD;
		ans=ans*inv(i+1)%MOD;
		ans=ans*(t-i)%MOD;
	}
	REP(i,n) cout<<a[i]<<'\n';


	return 0;
}


Measured memory_bytes: 6656
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.PriorityQueue;
import java.util.Set;


public class Main {

	/**
	 * @param args
	 * @throws IOException 
	 * @throws NumberFormatException 
	 */
	public static void main(String[] args) throws NumberFormatException, IOException {
		// TODO Auto-generated method stub
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		String[] tmpArray = br.readLine().split(" ");
		int n = Integer.parseInt(tmpArray[0]);
		int k = Integer.parseInt(tmpArray[1]);
		
		tmpArray = br.readLine().split(" ");
		
		int[] array = new int[n];
		
		int left = 0;
		int right = 0;
		for(int i = 0; i < n; i++){
			array[i] = Integer.parseInt(tmpArray[i]);
			if(array[i] == 1){
				left = i;
				right = i;
			}
		}
		
		int count = 0;
		while(left > 0){
			count++;
			left -= k - 1;
//			System.out.println("left "+left);
		}
		
		right += (-left);
		
		while(right < n - 1){
			count++;
			right += k - 1;
//			System.out.println("right "+right);
		}
		
		System.out.println(count);
	}
	
}

Measured memory_bytes: 36188
#include<bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int,int> P;
#define TO first
#define COST second
vector<P> G[1111];
int dp[1<<6][1<<6][1111];
struct st{
  int b1,b2,p,d;
  st(){}
  st(int b1,int b2,int p,int d):b1(b1),b2(b2),p(p),d(d){}
  bool operator<(st a)const{
    return d>a.d;
  }
};
signed main(){
  int n,m,k,p;
  cin>>n>>m>>k>>p;
  p--;
  for(int i=0,x,y,w;i<m;i++){
    cin>>x>>y>>w;
    x--;y--;
    G[x].push_back(P(y,w));
    G[y].push_back(P(x,w));
  }
  int s[k],t[k];
  for(int i=0;i<k;i++){
    cin>>s[i]>>t[i];
    s[i]--;
    t[i]--;
  }
  memset(dp,-1,sizeof(dp));
  priority_queue<st> q;
  q.push(st(0,0,p,0));
  dp[0][0][p]=0;
  while(!q.empty()){
    st pp=q.top();q.pop();
    int b1=pp.b1,b2=pp.b2,v=pp.p,d=pp.d;
    if(dp[b1][b2][v]<d) continue;
    for(int i=0;i<(int)G[v].size();i++){
      int u=G[v][i].TO,c=G[v][i].COST;
      int nb1=b1,nb2=b2;
      for(int j=0;j<k;j++){
	if(s[j]==u) nb1|=(1<<j);
	if(((b1>>j)&1)&&(t[j]==u))
	  nb2|=(1<<j);
      }
      if(dp[nb1][nb2][u]<0||dp[nb1][nb2][u]>d+c){
	dp[nb1][nb2][u]=d+c;
	q.push(st(nb1,nb2,u,d+c));
      }
    }
  }
  int ans=-1;
  for(int i=0;i<n;i++){
    if(dp[(1<<k)-1][(1<<k)-1][i]<0) continue;
    if(ans<0||ans>dp[(1<<k)-1][(1<<k)-1][i])
      ans=dp[(1<<k)-1][(1<<k)-1][i];
  }
  if(ans<0) cout<<"Cannot deliver"<<endl;
  else cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 42632
#include<cstdio>

int main(){
  int a,b;
  scanf("%d %d", &a, &b);;
  if(a < b){
    printf("a < b\n");
  }else if(a > b){
    printf("a > b\n");
  }else if(a == b){
    printf("a == b\n");
  }
  return 0;
}

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

int main(void){
  int n;
  cin >> n;
  map<int, int> mp;
  rep(i,n) {
    int a;
    cin >> a;
    if(mp.count(a)) {
      cout << "NO" << endl;
      return 0;
    }else{
      mp[a] = 1;
    }
  }
  cout << "YES" << endl;
  return 0;
}

Measured memory_bytes: 12988
while True:
  N = int(raw_input())
  if N == 0: break
  W,H = map(int, raw_input().split())
  matrix = [[0]*H for _ in xrange(W)]
  for _ in xrange(N):
    x,y = map(int, raw_input().split())
    matrix[x-1][y-1] = 1
  S,T = map(int, raw_input().split())
  maxcount = 0
  for i in xrange(W-S+1):
    for j in xrange(H-T+1):
      count = 0
      for a in xrange(S):
        for b in xrange(T):
          count += matrix[i+a][j+b]
      maxcount = max(maxcount, count)
  print maxcount

Measured memory_bytes: 6524
import sys, string
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = 10**20
def I(): return int(input())
def F(): return float(input())
def S(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LS(): return input().split()

def resolve():
    A, B = LI()
    Str = S()

    is_ok = True
    for i, e in enumerate(Str):
        if i==A:
            if e!='-':
                is_ok = False
        else:
            if not e in string.digits:
                is_ok = False
    
    if is_ok:
        print('Yes')
    else:
        print('No')

    
if __name__ == '__main__':
    resolve()

Measured memory_bytes: 3768
#include<iostream>
#include<algorithm>
#include<climits>
#include<vector>
#include<utility>
#include<cmath>
#include<cstring>
#include<map>
#include<sstream>
 
using namespace std;

long long int X, happy;
int coins[2] = {500,5};
int happines[2] = {1000, 5};

int main(){
  cin>>X;
  happy = 0;
  
  for(int i = 0; i < 2; i++){
    happy += (happines[i] * (X/coins[i]));
    X -= (coins[i] * (X/coins[i]));
  }
  
  
  
  cout<<happy;
}


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

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long int

using namespace __gnu_pbds;

typedef tree<pair<ll,pair<ll,ll> >, null_type, less<pair<ll,pair<ll,ll> > >, rb_tree_tag, tree_order_statistics_node_update>ordered_set;


#define me BOSS
#define bug() cout<<"AIkahne aise"<<endl
#define PI acos(-1)
#define mod 1000000007
/* Precode Start Here *\


power of 2 less than or equal to N

ll largest_power(ll N)
{
    //changing all right side bits to 1.
    N = N (N>>1);
    N = N| (N>>2);
    N = N| (N>>4);
    N = N| (N>>8);


//as now the number is 2 * x-1, where x is required answer, so adding 1 and dividing it by
 2. 
            return (N+1)>>1;

}


     Sieve
void sieve()
{
    for(ll i=3; i<=2000; i+=2)
    {
        for(ll j=i*i; j<=4000000; j+=i)
            A[j]=1;
    }
    v.push_back(2);
    for(ll i=3; i<=4000000; i+=2)
        if(A[i]==0)
            v.push_back(i);
}

     Power Function Modulo P
     
ll modPow(ll a, ll x, ll p) {
    //calculates a^x mod p in logarithmic time.
    long res = 1;
    while(x > 0) {
        if( x % 2 != 0) {
            res = (res * a) % p;
        }
        a = (a * a) % p;
        x /= 2;
    }
    return res;
}


   factorial
   
ll fact(ll n)
{
    ll ans=1;
    for(ll i=1;i<=n;i++)
    {
        ans=(ans*i)%mod;
    }
    return ans;
}
     Calculating nCr using Fermats law Theorem
     
ll modInverse(ll a, ll p) {
    //calculates the modular multiplicative of a mod m.
    //(assuming p is prime).
    return modPow(a, p-2, p);
}


ll modBinomial(ll n, ll k, ll p) {
// calculates C(n,k) mod p (assuming p is prime).

    ll numerator = 1; // n * (n-1) * ... * (n-k+1)
    for (ll i=0; i<k; i++) {
        numerator = (numerator * (n-i) ) % p;
    }

    ll denominator = 1; // k!
    for (ll i=1; i<=k; i++) {
        denominator = (denominator * i) % p;
    }

    // numerator / denominator mod p.
    return ( numerator* modInverse(denominator,p) ) % p;
}
     num of divisor and euler totient 

ll phi[1000001],mark[1000001],divi[1000001];;
void divisorPhi(ll n)
{
    for(int i=1;i<=n;i++)
        phi[i]=i;
    for(int i=2;i<=n;i++)
    {
        if(!mark[i])
        {
            for(int j=i;j<=n;j+=i)
            {
                mark[j]=1;
                phi[j]*=(1-1/(double)i);
            }
        }
    }
    for(ll i=1;i<=n;i++)
    {
        for(ll j=i;j<=n;j+=i)
            divi[j]++;
    }
}




/* Precode Ends */
ll A[5000001],B[5000001];
vector<ll>v;
map<ll,ll>myMap;
set<ll>mySet;
vector<pair<ll,ll> >vp;
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
 
 ll r,c;
 cin>>r>>c;
 if(r==1||c==1)
 {
     cout<<1<<endl;
 }
 else
 {
     ll ans=0;
     ans+=((r+1)/2)*((c+1)/2);
     ans+=(r/2)*(c/2);
     cout<<ans<<endl;
 }
 
return 0;
}



Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		int q = sc.nextInt();
		int[] l = new int[q];
		int[] r = new int[q];
		for (int i = 0; i < q; i++) {
			l[i] = sc.nextInt();
			r[i] = sc.nextInt();
		}

		boolean[] isPrimeNum = new boolean[100001];
		for (int i = 1; i <= 100000; i += 2) {
			isPrimeNum[i] = true;
		}
		isPrimeNum[0] = false;
		isPrimeNum[1] = false;
		isPrimeNum[2] = true;
		for (int i = 3; i * i <= 100000; i += 2) {
			if (isPrimeNum[i] == true) {
				for (int j = i * i; j <= 100000; j += i * 2) {
					isPrimeNum[j] = false;
				}
			}
		}

		int[] numOfLikeNumber = new int[100001];
		numOfLikeNumber[1] = 0;
		numOfLikeNumber[2] = 0;
		numOfLikeNumber[3] = 1;
		for (int i = 4; i <= 100000; i++) {
			numOfLikeNumber[i] = numOfLikeNumber[i - 1];
			if (i % 4 == 1) {
				if (isPrimeNum[i] && isPrimeNum[(i + 1) / 2]) {
					numOfLikeNumber[i]++;
				}
			}
		}

		for (int i = 0; i < q; i++) {
			System.out.println(numOfLikeNumber[r[i]] - numOfLikeNumber[l[i] - 1]);
		}

	}

}


Measured memory_bytes: 91564
#include<bits/stdc++.h>
        #define REP(i,n) for(int i=0;i<n;i++)
        #define LOOP(i,x,n) for(int i=x;i<n;i++)
        #define ALL(v) (v).begin(),(v).end()
        #define PB push_back
        #define MP make_pair
        #define FIR first
        #define UB upper_bound
        #define LB lower_bound
        #define int long long
        using namespace std;
        const int MOD=1000000007;
        const int INF=1000000009;
         
        signed main(){
          string s,t;
          cin>>s>>t;
          if(s.size()<t.size()){
            cout<<"UNRESTORABLE"<<endl;
            return 0;
          }
          vector<string> str;
          REP(i,s.size()-t.size()+1){
            string u=s.substr(i,t.size());
            bool k=true;
            REP(j,u.size()){
              if(u[j]=='?')continue;
              if(u[j]!=t[j]){
                k=false;
                break;
              }
            }
            if(k){
              string v=s;
              int p=0;
              for(int j=i;j<i+t.size();j++){
                v[j]=t[p];
                p++;
              }
              REP(j,v.size())if(v[j]=='?')v[j]='a';
              str.PB(v);
            }
          }
          sort(ALL(str));
          if(!str.empty())cout<<str[0]<<endl;
          else cout<<"UNRESTORABLE"<<endl;
          return 0;
        }

Measured memory_bytes: 256
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on 2019/3/23
Solved on 2019/3/
@author: shinjisu
"""


# ABC 074 C - Sugar Water

def getIntList(): return [int(x) for x in input().split()]
def zeros(n): return [0]*n
def zeros2(n, m): return [zeros(m) for i in range(n)] # obsoleted zeros((n, m))で代替
class Debug():
    def __init__(self):
        self.debug = True
 
    def off(self):
        self.debug = False
 
    def dmp(self, x, cmt=''):
        if self.debug:
            if cmt != '':
                print(cmt, ':  ', end='')
            print(x)
        return x


def prob():
    global E, F
    db = Debug()
    db.off()
    A, B, C, D, E, F = getIntList()
    db.dmp((A, B, C, D, E, F), 'A, B, C, D, E, F')
    a = F // (100 * A)
    b = F // (100 * B)
    c = F // C
    d = F // D
    db.dmp((a, b, c, d), 'a, b, c, d')
    maxConc, maxWater, maxSugar = -1.0, 0, 0
    for i in range(a+1):
        for j in range(b+1):
            water = A*i + B*j
            if water == 0:
                continue
            if water*100 >= F:  # overflow
                break
            for n in range(c+1):
                for m in range(d+1):
                    sugar = C*n + D*m
                    conc = sugar / (sugar+water*100) * 100
                    #db.dmp((maxconc, water, sugar, conc),'maxconc, water, sugar, conc')
                    if sugar/water > E:  # not all melted
                        #db.dmp('not all melted')
                        break
                    if water*100+sugar > F:  # overflow
                        #db.dmp('overflow')
                        break
                    if conc > maxConc:
                        #db.dmp('MAX UPDATED')
                        maxConc, maxWater, maxSugar = conc, water, sugar

    db.dmp((maxConc, maxWater, maxSugar),'max conc, water, sugar')
    return maxWater*100+maxSugar, maxSugar


ans = prob()
for elm in ans:
    print(elm, end=' ')


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

#define REP(i,num) for(int i=0;i<(num);++i)
#define ALL(c) c.begin(),c.end()
#define LOOP(i) while(i--)
#define PRINTALL(c) for(auto& x:c){cout<<x<<' ';}cout<<endl;
#define PAIRCOMP(c,comp) [](const pair<ll,ll>& lhs,const pair<ll,ll>& rhs){return lhs.c comp rhs.c;}

using namespace std;
using ll = long long;

constexpr ll atcoder_mod = 1e9+7;

template<typename T=int>
T in(){T x; cin >> x; return (x);}
template<typename T=int,typename C=vector<T>>
C vecin(int N){C x(N);REP(i,N){x[i]=in<T>();}return move(x);}

void vout(){cout << endl;}
template<typename Head,typename... Tail>
void vout(Head&& h,Tail&&... t){cout << ' ' << h;vout(forward<Tail>(t)...);}
void out(){cout << endl;}
template<typename Head,typename... Tail>
void out(Head&& h,Tail&&... t){cout << h;vout(forward<Tail>(t)...);}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout<<fixed<<setprecision(10);

	int N=in(),K=in();
	map<int,int> C;
	REP(i,N){
		C[in()]++;
	}
	vector<int> V;
	for(auto& x:C){
		V.push_back(x.second);
	}
	sort(ALL(V),greater<int>());

	int M=V.size();
	if(K>=M){
		out(0);
	}
	else{
		int sum=0;
		REP(i,K){
			sum += V[i];
		}
		out(N-sum);
	}
	
	return 0;
}

Measured memory_bytes: 10744
n,m=map(int,input().split())
dp=[0]+[-(2**30) for i in range(n)]
a,b=sorted(list(map(int,input().split())),reverse=True),[0,2,5,5,4,5,6,3,7,6]
for i in range(n):
	for j in range(m):
		if(i+b[a[j]]>n):
			continue
		dp[i+b[a[j]]] = max(dp[i+b[a[j]]],dp[i]+1)
ans = ""
while n:
	for j in range(m):
		if n-b[a[j]]<0:
			continue
		if dp[n-b[a[j]]] == dp[n]-1:
			ans += str(a[j])
			n -= b[a[j]]
			break
print(ans)

Measured memory_bytes: 3440
#include<iostream>
int main(){
  int a=0,b=0,c=0,x=0,cnt=0;
  std::cin>>a>>b>>c>>x;
  for(int i=0;i<=a;i++){
    for(int j=0;j<=b;j++){
        for(int k=0;k<=c;k++){
            if(i*500+j*100+k*50==x)++cnt;
        }
    }
  }
  std::cout<<cnt<<std::endl;

    return 0;
}



Measured memory_bytes: 256
#define M 26
P[M],A[M],B[M];
int R(a){return P[a]==a?a:(P[a]=R(P[a]));}
char s[99];main(k,l,d,x,y){for(;scanf("%d",&l),l;puts(k<M||d>0?"NG":"OK")){
	for(k=0;k<M;k++)A[k]=B[k]=0,P[k]=k;
	for(k=0;k<l;k++)scanf("%s",s),x=*s-97,y=s[strlen(s)-1]-97,A[x]++,B[y]++,P[R(x)]=R(y);
	for(d=k=0;k<M;k++){d+=abs(A[k]-B[k]);if((A[k]|B[k])&&R(*s-97)!=R(k))break;}
}exit(0);}

Measured memory_bytes: 584
#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 drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define eb emplace_back
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
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; }
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;}
int const INF = 1001001001;
ll const MOD = 1000000007;


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

int N;
cin >> N;
vl A(N);
rep(i,N) cin >> A[i];
ll ans = A[0];
rep(i,N-1) {
    ans = gcd(ans,A[i+1]);
}

cout << ans << endl;

return 0;
}

Measured memory_bytes: 1024
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<vector>
#include<functional>
#include<algorithm>
#include<stdlib.h>
#include<string.h>
#include<cmath>
#include<deque>
#include<map>
using namespace std;
typedef long long ll;
#define rep(i,a,b) for(int i=a;i<b;i++)
#define all(_x) _x.begin(), _x.end()
#define r_sort(_x) sort(_x.begin(), _x.end(), std::greater<int>())
#define INF 1LL << 60
#define MAX 1000000000
int main(void) {
	int N, M;
	ll ans = 0, c = 0;
	scanf("%d%d", &N, &M);
	vector<ll> A(N), S(N + 1), R(N + 1);
	rep(i, 0, N)scanf("%lld", &A[i]);
	S[0] = 0;
	rep(i, 1, N + 1)S[i] = S[i - 1] + A[i - 1];
	rep(i, 0, N + 1)R[i] = S[i] % M;
	sort(all(R));
	rep(i, 0, N) {
		if (R[i] != R[i + 1])ans += c * (c + 1) / 2,c = 0;
		else c++;
	}
	ans += c * (c + 1) / 2;
	printf("%lld", ans);
	return 0;
}

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

int main() {
  int h, w, m;
  cin >> h >> w >> m;
  vector<int> hs(h), ws(w);
  set<P> s;
  rep(i,m) {
    // row column
    int r, c;
    cin >> r >> c;
    --r; --c;
    hs[r]++;
    ws[c]++;
    s.emplace(r,c);
  }
  int mh = 0, mw = 0;
  rep(i,h) mh = max(mh, hs[i]);
  rep(j,w) mw = max(mw, ws[j]);
  vector<int> is, js;
  rep(i,h) if (mh == hs[i]) is.push_back(i);
  rep(j,w) if (mw == ws[j]) js.push_back(j);
  int ans = mh+mw;
  for (int i : is) for (int j : js) {
    if (s.count(P(i,j))) continue;
    cout << ans << endl;
    return 0;
  }
  --ans;
  cout << ans << endl;
  return 0;
}

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

int dp[105][4][2];

int main(int argc, char const *argv[])
{
    string s; cin >> s;
    int n = s.size();
    int k; cin >> k;
    dp[0][0][0] = 1;
    rep(i,n)rep(j,4)rep(l,2) {
        int nd = s[i] - '0';
        rep(d,10) {
            int ni = i + 1, nj = j, nl  = l;
            if (d != 0) nj ++;
            if (nj > k) continue;
            if (l == 0)
            {
                if (d > nd) continue;
                if (d < nd) nl = 1;
            }
            dp[ni][nj][nl] += dp[i][j][l];
        }
    }
    cout << dp[n][k][0] + dp[n][k][1] << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi = vector<int>;
using mti = vector<vector<int>>;
using vl = vector<ll>;
using mtl = vector<vector<ll>>;
using pi = pair<int, int>;
using pl = pair<ll, ll>;
#define all(x) x.begin(),x.end()
#define rep(i,j,n) for (int i = j; i < (int)(n); i++)
#define _GLIBCXX_DEBUG
#define n_p(v) next_permutation(v.begin(),v.end())
#define to_ll(b) stoll(b)
#define MOD 1000000007
//name[i][j]-> vvl name(i,vl(j))
//map<int,int>mp

signed main(){
	string s,t; cin>>s>>t;
	sort(all(s));
	sort(all(t));
	reverse(all(t));
	if(s<t) cout<<"Yes";
	else cout<<"No";
	
	return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

string n;
long long int res;

void solve(string s)
{
    for(long long int i = 0; i < s.length(); ++i)
    {
        res += (s[i] - 48);
    }
}
int main()
{
    cin >> n;
    solve(n);
    if(res % 9 == 0)
    {
        cout << "Yes";
    }
    else
    {
        cout << "No";
    }
    return 0;
}


Measured memory_bytes: 3880
N = int(input())
B = list(map(int,input().split()))
A = [0]*N
A[0] = B[0]
A[N-1] = B[N-2]

for i in range(1,N-1):
  if B[i] >= B[i-1]:
    A[i] = B[i-1]
  else:
    A[i] = B[i]
print(sum(A))
         

Measured memory_bytes: 38256
#include <bits/stdc++.h>
    using namespace std;
    typedef long long ll;
    #define endl "\n"
    #define space " "
    #define ll long long int
    #define vl vector<ll>
    #define vvl vector < vll >
    #define pii pair<int,int>
    #define pll pair<ll,ll>
    #define vpl vector < pll >
    #define mod 1000000007
    #define pi 3.1415926535897932384626433
    #define inf 1000000000000000001;
    #define fast ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
    #define all(c) c.begin(),c.end()
    #define mp(x,y) make_pair(x,y) 
    #define mem(a,val) memset(a,val,sizeof(a))
    #define pb push_back
    #define f first
    #define s second
    
    void solve()
    {
        int n; cin>>n;
        int c=0, d=0;
        for(int i=0; i<n; i++){
            int x,y; cin>>x>>y;
            if(x==y) c++;
            else c=0;
            if(c==3) d=1;
        }
        if(d==1) cout<<"Yes";
        else cout<<"No";
    }

    signed main()
    {

    fast;
    #ifndef ONLINE_JUDGE
      freopen("input.txt", "r", stdin);
      freopen("output.txt", "w", stdout);
     #endif

    ll T=1;
    // cin>>T;
    while(T--)
    {
        solve();
    }
    return 0;
    }


Measured memory_bytes: 3648
use std::io::stdin;
use std::collections::HashMap;


fn main() {
    let mut nm = String::new();
    stdin().read_line(&mut nm).unwrap();
    let nm: Vec<usize> = nm.trim().split_whitespace().flat_map(str::parse).collect();
    let (n, m) = (nm[0], nm[1]);

    let mut candies = String::new();
    stdin().read_line(&mut candies).unwrap();
    let candies: Vec<usize> = candies.trim().split_whitespace().flat_map(str::parse).collect();

    println!("{}", solve(n, m, candies));
}

fn solve(n :usize, m: usize, candies: Vec<usize>) -> usize {
    let mut ca = Vec::with_capacity(n + 1);
    ca.push(0);
    candies.into_iter().fold(0, |acc, v|{
        let v = (acc + v) % m;
        ca.push(v);
        v
    });

    let mut res = 0;
    let mut memo: HashMap<usize, usize> = HashMap::new();
    for i in ca.into_iter() {
        if !memo.contains_key(&i) {
            memo.insert(i, 0);
        }
        if let Some(p) = memo.get_mut(&i) {
            res += *p;
            *p += 1;
        }
    }
    res
}


Measured memory_bytes: 11984
#include <bits/stdc++.h>
using namespace std;
struct TT{
    int a;
    char b;
}ko;
void BubbleSort(auto &A,auto n)
{
    for(int i=0;i<n;i++)
        for(int j=n-1;j>i;j--)
            if(A[j].a<A[j-1].a){
                TT C=A[j];A[j]=A[j-1];A[j-1]=C;
            }
}
void SelectionSort(auto &A,auto n)
{
    for(int i=0;i<n;i++)
    {
        int index=i;
        for(int j=i;j<n;j++)
            if(A[j].a<A[index].a)
                index=j;
        ko=A[index];
        A[index]=A[i];
        A[i]=ko;

    }
}
void pri(auto A,auto n)
{
    for(int i=0;i<n;i++){
        if(i!=0)cout<<" ";
        cout<<A[i].b<<A[i].a;
    }
    cout<<endl;
}
bool compute(auto A,auto B,auto n)
{
    for(int i=0;i<n;i++)
        if(A[i].b==B[i].b)
            continue;
        else
            return false;
    return true;
}
int main()
{
    int n;cin>>n;
    vector<TT>A(n),B;
    for(int i=0;i<n;i++){
        cin>>A[i].b>>A[i].a;
        if(i!=n-1)getchar();
    }
    B=A;
    BubbleSort(B,n);
    pri(B,n);
    cout<<"Stable"<<endl;
    SelectionSort(A,n);
    pri(A,n);
    if(compute(A,B,n)){
        cout<<"Stable"<<endl;
    }
    else
        cout<<"Not stable"<<endl;
    return 0;
}



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

#define INF 2147483647

signed main()
{
    int n, a, b, c;
    int dp[100000][3] = {};
    
    cin >> n;
    for(int i=0; i<n ;i++ ){
        cin >> a >> b >> c;

        if(i == 0){
            dp[0][0] = a;
            dp[0][1] = b;
            dp[0][2] = c;
        } else {
            dp[i][0] = max(dp[i-1][1], dp[i-1][2]) + a;
            dp[i][1] = max(dp[i-1][0], dp[i-1][2]) + b;
            dp[i][2] = max(dp[i-1][0], dp[i-1][1]) + c; 
        }
    }

    cout << max( dp[n-1][0] ,max( dp[n-1][1], dp[n-1][2] ) ) << endl;

    return (0);
}

Measured memory_bytes: 4780
/*
Author: Sagar Gupta
E mail: sagar.june97p@gmail.com
*/
#include <bits/stdc++.h>
#define newline ("\n")
#define deb(x) cerr << (#x) << " = " << (x) << '\n'
#define FOR(x, n) for (int x = 0; x < n; x++)
#define PI (3.141592653589)

#define MOD 1000000007
using namespace std;

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

    // Pikachu, I choose you
    int n;
    cin >> n;
    int arr[n];
    for(int i= 0;i<n;i++)
        cin >> arr[i];
    int dp[n+1];
    dp[0] = 0;
    dp[1] = 0;
    dp[2] = abs(arr[1] - arr[0]);
    for(int i = 3;i<=n;i++)
    {
        dp[i] = min(dp[i-1] + abs(arr[i-1] - arr[i-2]), dp[i-2] + abs(arr[i-1] - arr[i-3]));
    }
    cout << dp[n];
    return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define REP(i, n) for(int i = 0; i < n; i++)
using namespace std;

int main() {
    int n; cin >> n;
    double ans = 0;
    REP(i,n){
        double x; 
        string u; cin >> x >> u;
        if(u == "JPY"){
            ans += x;
        }else{
            ans += x*380000.0;
        }
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <unordered_map>
#include <functional>
#include <cstring>
#include <cmath>
#include <ctime>
#include <cstdlib>

using namespace std;
typedef long long llong;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<llong, llong> pll;

int n;
int a[101];
int dp1[101]; // ch
int dp2[101]; // no
int main() {
    scanf("%d", &n);
    for (int i = 1; i <= n; ++i) {
        scanf("%d", a + i);
    }
    for (int i = 1; i <= n; ++i) {
        dp1[i] = min(dp1[i - 1], dp2[i - 1]) + 1;
        dp2[i] = (a[i] == a[i - 1] ? dp1[i - 1] : min(dp1[i - 1], dp2[i - 1]));
    }
    printf("%d\n", min(dp1[n], dp2[n]));
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;

map<int,int> factorize(int x){
  map<int,int> ret;
  int d, q;
  while(x>=4 && x%2==0){ret[2]++; x/=2;}
  d = 3; q = x/d;
  while(q>=d){
    if(x%d==0){ ret[d]++; x=q; }else{ d+=2; }
    q=x/d;
  }
  ret[x]++;
  return ret;
}
int gcd(int a, int b){return (b==0?a:gcd(b,a%b));}

int main(){
  int N;
  cin >> N;
  vector<int> v;
  rep(i,N){
    int a;
    cin >> a;
    v.push_back(a);
  }

  map<int,int> memo;
  bool flg = false;
  for(int i=N-1; i>=0; i--){
    map<int,int> res = factorize(v[i]);
    FOR(it,res){
      if(it->first == 1) continue;
      if(memo.count(it->first) > 0){
        flg = true;
        break;
      }
      memo[it->first]++;
    }
  }
  if(!flg){
    cout << "pairwise coprime" << endl;
    return 0;
  }
  
  int ret = v[0];
  rep(i,N){
    ret = gcd(ret, v[i]);
  }

  if(ret == 1) cout << "setwise coprime" << endl;
  else cout << "not coprime" << endl;
  
  return 0;
}



Measured memory_bytes: 10688
x=int(input())
list=[]
max=0
for i in range(33):
    for j in range(2,11):
        if (i**j)<=1000:    
            list.append(i**j)
for i in range(len(list)):
    if max<list[i] and list[i]<=x:
        max=list[i]
print(max)

Measured memory_bytes: 3060
#include <iostream>
#include <string>
#include <string.h>
#include <vector>
#include <algorithm>
#include <sstream>
#include <set>
#include <map>
#include <queue>
#include <tuple>
#include <functional>

using namespace std;

#define For(i,a,n)	for(int i = a;i < n;i++)
#define rep(i,n)	For(i,0,n)
#define clr(n)		memset(n,0,sizeof n)
#define all(n)		(n).begin(),(n).end()

typedef pair<int, int> P;
typedef tuple<int, int, int> T;
typedef pair<P, P> WP;
typedef long long ll;

const ll INF = 1e9;
int dx[4] = { 0, 1, 0, -1 }, dy[4] = { 1, 0, -1, 0 };
bool cheak(int x, int y, int mx, int my){
	return x >= 0 && y >= 0 && x < mx &&  y < my;
}
struct UnionFind{
	vector<int> data;
	UnionFind(int size) :data(size, -1){}

	bool set(int x, int y){
		x = root(x), y = root(y);
		if (x != y){
			if (data[x] > data[y])swap(x, y);
			data[x] += data[y];
			data[y] = x;
		}
		return x != y;
	}

	bool find(int x, int y){
		return root(x) == root(y);
	}
	int root(int x){
		return data[x] < 0 ? x : data[x] = root(data[x]);
	}
	int size(int x){
		return -data[root(x)];
	}

};

int main()
{
	int n, m;
	while (cin >> n >> m && n){
		map<int, vector<int>> hm;
		hm[0].push_back(0);
		For(i, 1, n + 1){
			int h;
			cin >> h;
			hm[h].push_back(i);
		}
		vector<T> v;
		
		rep(i, m){
			int a, b, c;
			cin >> a >> b >> c;
			v.push_back(T(c, a, b));
		}
		sort(all(v));

		int d[201][201];
		rep(i, 201)rep(j, 201)d[i][j] = (i == j ? 1 : 0);

		vector<vector<int>> tv;
		for (auto target : hm){
			auto t = target.second;
			tv.push_back(t);

			UnionFind uf(n+1);
			rep(i, t.size()){
				For(j, 1, n + 1){
					d[t[i]][j] = 0;
				}
			}
			bool f[201]; clr(f);
			For(i, 1, n + 1){
				f[i] = true;
				queue<int> q;
				q.push(i);
				while (q.size()){
					int now = q.front(); q.pop();
					For(j, 1, n + 1){
						if (d[now][j] && !f[j]){
							f[j] = true;
							q.push(j);
							uf.set(now, j);
						}
					}
				}
			}
			rep(i,v.size()){
				T nx = v[i];
				int c = get<0>(nx), a = get<1>(nx), b = get<2>(nx);
				if (!uf.find(a, b) && d[a][a] && d[b][b]){
					uf.set(a, b);
					d[a][b] = d[b][a] = 1;
				}
			}
			bool ef = false;
			For(j, 1, n + 1){
				if (d[j][j]){
					For(i, 1, n + 1){
						if (!uf.find(j, i) && d[i][i]){
							ef = true;
						}
					}
					break;
				}
			}
			if (ef){
				break;
			}
		}

		int ans = 0;
		UnionFind uf(n + 1);
		for (int j = tv.size() - 1; j >= 1; j--){
			rep(k, tv[j].size()){
				d[tv[j][k]][tv[j][k]] = 1;
			}

			rep(i, v.size()){
				T nx = v[i];
				int c = get<0>(nx), a = get<1>(nx), b = get<2>(nx);
				if (!uf.find(a, b) && d[a][a] && d[b][b]){
					uf.set(a, b);
					d[a][b] = d[b][a] = 1;
					ans += c;
				}
			}
		}


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

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



int main() {
  int n;
  cin >>n;
  ll ans=100000000;
  int a[n];
  rep(i,n){
    cin >> a[i];
  }
  for(int i=-100;i<=100;i++){
    ll sum=0;
    rep(r,n){
      int g=a[r]-i;
      sum+=g*g;
    }
    ans=min(ans,sum);
  }
  cout << ans << endl;
}

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

const int N = 100010;
char s[N], t[N];
int n, m, q, cnts[N][2], cntt[N][2];
void can(int sa, int sb, int ta, int tb) {
	if (sa > ta) swap(tb, sb), swap(ta, sa);
	int mn = min(ta - sa, tb - sb); 
	ta -= mn, tb -= mn;
	puts(abs(tb - sb + ta - sa) % 3 == 0 ? "YES" : "NO");
}
int main() {
    scanf ("%s%s", s + 1, t + 1);
    n = strlen(s + 1);
    m = strlen(t + 1);
    for (int i = 1; i <= n; ++i)
        for (int j = 0; j < 2; ++j)
            cnts[i][j] = cnts[i - 1][j] + (j + 'A' == s[i]);
    for (int i = 1; i <= m; ++i)
        for (int j = 0; j < 2; ++j)
            cntt[i][j] = cntt[i - 1][j] + (j + 'A' == t[i]);
    scanf ("%d", &q);
    while (q--) {
        int a, b, c, d;
        scanf ("%d%d%d%d", &a, &b, &c, &d);
        int sa = cnts[b][0] - cnts[a - 1][0], sb = (b-a+1) - sa;
        int ta = cntt[d][0] - cntt[c - 1][0], tb = (d-c+1) - ta;
        // (sa, sb) -> (ta, tb)
    //    if (sa > ta) swap(ta, sa), swap(tb, sb);'
        can(sa, sb, ta, tb);
    }
    return 0; 
}

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

int main()
{

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

Measured memory_bytes: 3608
// abc133d: Rain Flows into Dams
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;

#define upto(i,s,e,d) for(int i=(s);i<(e);i+=(d))

int main(){
  int n; cin>>n;
  ll even = 0, odd = 0;
  vi d(n);
  upto(i,0,n,1){
    cin>>d[i];
    if(i%2) odd += d[i]; else even += d[i];
  }
  int m0 = even - odd;
  cout<<m0;
  upto(i,0,n-1,1){
    int m1 = d[i]*2 - m0;
    cout<<" "<<m1;
    m0 = m1;
  }
  cout<<endl;
}

Measured memory_bytes: 1664
#include <bits/stdc++.h>
using namespace std;
using pii=pair<int,int>;
using ll=long long;

#define fi first
#define se second
#define pb push_back
#define rep(i,n) for(int i=0; i<(int)(n); i++)

int main() {
	int a,b;
	cin >> a >> b;
	for(int i=1; i<=1009; i++) {
		double id = i * 1.0;
		double ad = id * 0.08;
		int at = ad;
		double bd = id * 0.10;
		int bt = bd;
		if(at == a && bt == b) {
			cout << i << endl;
			return 0;
		}
	}
	cout << -1 << endl;

  return 0;
}


Measured memory_bytes: 256