akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <iomanip>
#include <sstream>
#include <vector>
#include <string>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <functional>
#include <iterator>
#include <limits>
#include <numeric>
#include <utility>
#include <cmath>
#include <cassert>
#include <cstdio>

using namespace std;
using namespace placeholders;

using LL = long long;
using ULL = unsigned long long;
using VI = vector< int >;
using VVI = vector< vector< int > >;
using VS = vector< string >;
using SS = stringstream;
using PII = pair< int, int >;
using VPII = vector< pair< int, int > >;
template < typename T = int > using VT = vector< T >;
template < typename T = int > using VVT = vector< vector< T > >;
template < typename T = int > using LIM = numeric_limits< T >;

template < typename T > inline istream& operator>>( istream &s, vector< T > &v ){ for ( T &t : v ) { s >> t; } return s; }
template < typename T > inline ostream& operator<<( ostream &s, const vector< T > &v ){ for ( int i = 0; i < int( v.size() ); ++i ){ s << ( " " + !i ) << v[i]; } return s; }
template < typename T > inline T fromString( const string &s ) { T res; istringstream iss( s ); iss >> res; return res; }
template < typename T > inline string toString( const T &a ) { ostringstream oss; oss << a; return oss.str(); }

#define REP2( i, n ) REP3( i, 0, n )
#define REP3( i, m, n ) for ( int i = ( int )( m ); i < ( int )( n ); ++i )
#define GET_REP( a, b, c, F, ... ) F
#define REP( ... ) GET_REP( __VA_ARGS__, REP3, REP2 )( __VA_ARGS__ )
#define FOR( e, c ) for ( auto &&e : c )
#define ALL( c ) begin( c ), end( c )
#define AALL( a, t ) ( t* )a, ( t* )a + sizeof( a ) / sizeof( t )
#define DRANGE( c, p ) ( c ).begin(), ( c ).begin() + ( p ), ( c ).end()

#define SZ( v ) ( (int)( v ).size() )
#define EXIST( c, e ) ( ( c ).find( e ) != ( c ).end() )

template < typename T > inline bool chmin( T &a, const T &b ){ if ( b < a ) { a = b; return true; } return false; }
template < typename T > inline bool chmax( T &a, const T &b ){ if ( a < b ) { a = b; return true; } return false; }

#define PB push_back
#define EM emplace
#define EB emplace_back
#define BI back_inserter

#define MP make_pair
#define fst first
#define snd second

#define DUMP( x ) cerr << #x << " = " << ( x ) << endl

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

	string S;
	cin >> S;

	int depth = 0, res = 0;
	FOR( c, S )
	{
		if ( c == 'S' )
		{
			++depth;
		}
		else
		{
			--depth;
			if ( depth < 0 )
			{
				++res;
				depth = 0;
			}
		}
	}

	cout << res + depth << endl;

	return 0;
}


Measured memory_bytes: 720
#include <bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep1(i,n) for(ll i=1;i<=n;i++)
#define repk(i,m,n) for(ll i=m;i<n;i++)
#define IOS ios::sync_with_stdio(false);cin.tie(0);
#define F first
#define S second
typedef long long ll;
typedef long double ld;
using namespace std;
const int MOD1=1e9+7;
const int MOD2=998244353;
const int INF=2*1e9;
int main()
{
    string s;
    cin>>s;
    if(s[2]==s[3]&&s[4]==s[5]) cout<<"Yes";
    else cout<<"No";
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cassert>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
using namespace std;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
typedef long long ll;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
int main()
{
	while(1)
	{
		int n;
		cin >> n;
		if(n == 0) return 0;
		int cnt[10]={};
		for(int i=0;i<n;i++)
		{
			int a;
			cin >> a;
			cnt[a]++;
		}
		for(int i=0;i<10;i++)
		{
			if(cnt[i] == 0) puts("-");
			else
			{
				for(int j=0;j<cnt[i];j++)
				{
					printf("*");
				}
				puts("");
			}
		}
	}
}

Measured memory_bytes: 1116
n = int(input())
a = list(map(int, input().split()))

Alice = []
Bob = []
for i in range(n):
    if i % 2 == 0: 
        Alice.append(max(a))
    else:
        Bob.append(max(a))
    a.remove(max(a))

print(sum(Alice)-sum(Bob))


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

list<int> *adjList;

int dfs(int v,vector<int> &dp)
{
    if(dp[v]!=-1)
        return dp[v];

    int ans=0;
    for(auto i=adjList[v].begin();i!=adjList[v].end();i++)
        ans=max(ans,dfs(*i,dp)+1);
    return dp[v]=ans;
}

int main()
{
    int V,E;
    cin>>V>>E;
    adjList=new list<int>[V+1];
    int u,v;
    for(int i=0;i<E;i++)
    {
        cin>>u>>v;
        adjList[u].push_back(v);
    }
    vector<int> dp(V+1,-1);
     int Max=INT_MIN;
    for(int i=1;i<=V;i++)
    {
        Max=max(dfs(i,dp),Max);
    }

    cout<<Max;
    return 0;
}


Measured memory_bytes: 7424
#include <bits/stdc++.h>
#define watch(x) cout << (#x) << " is " << (x) << endl
#define eps 1e-9

typedef long long ll;

using namespace std;

const ll inf = 1e18;
const ll mod = 1e9+7;
const int N = 1e5+5;

int main()

{
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

    int n, cnt = 0, tmp = 1;
    bool f = 0;

    cin >> n;

    int arr[n];

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

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

        if (arr[i] == tmp) {

            tmp++;
            cnt++;
            f = 1;
        }
    }

    if (f) cout << n-cnt;
    else cout << -1;

    return 0;
}


Measured memory_bytes: 1024
h,w,c,max;
int D(x,y,c,n,M)int *M;{
	int r=1;
	M[x+(w+2)*y]=n;
	if(M[x-1+(w+2)*y]==c)r+=D(x-1,y,c,n,M);
	if(M[x+1+(w+2)*y]==c)r+=D(x+1,y,c,n,M);
	if(M[x+(w+2)*(y-1)]==c)r+=D(x,y-1,c,n,M);
	if(M[x+(w+2)*(y+1)]==c)r+=D(x,y+1,c,n,M);
	return r;
}
int E(d,M)int *M;{
	if(d==4){
		if(M[1+w+2]==c)return;
		int *m=malloc(400);
		memcpy(m,M,400);
		D(1,1,m[1+w+2],c,m);
		int k=D(1,1,m[1+w+2],-1,m);
		if(max<k)max=k;
		free(m);
		return;
	}else{
	int *m=malloc(400);
	int i=1,I,J;
	for(;i<7;i++){
		if(M[1+w+2]==i)continue;
		
		memcpy(m,M,400);
		D(1,1,m[1+w+2],i,m);
		E(d+1,m);
		
	}
	free(m);
	}
}
a[100];
main(i,j){
	for(;scanf("%d%d%d",&h,&w,&c),c;printf("%d\n",max)){
		memset(a,0,400);
		for(j=1;j<h+1;j++)for(i=1;i<w+1;i++)scanf("%d",a+i+(w+2)*j);
		E(max=0,a);
	}
}

Measured memory_bytes: 600
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define int ll
#define REP(i, n) FOR(i, 0, n)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define UM unordered_map
#define ALL(a) (a).begin(), (a).end()
typedef vector<ll> vi;
typedef vector<vector<ll>> vvi;
typedef pair<ll, ll> pii;
const ll INF = 1LL << 58;
const ll MOD = 1000000007;
typedef vector<pii> vpii;
template <class T>
inline bool chmax(T &a, T b)
{
    if (a < b)
    {
        a = b;
        return true;
    }
    return false;
}
template <class T>
inline bool chmin(T &a, T b)
{
    if (a > b)
    {
        a = b;
        return true;
    }
    return false;
}

signed main()
{
    int N;
    cin >> N;
    vector<pair<string, int>> vp;

    REP(i, N)
    {
        string name;
        int s;
        cin >> name >> s;
        vp.push_back(make_pair(name, s));
    }
    string X;
    int ans = 0;
    cin >> X;
    bool flg = false;
    REP(i, N)
    {
        if (flg)
            ans += vp.at(i).second;
        string name = vp.at(i).first;
        if (name == X)
            flg = true;
    }
    cout << ans << endl;

    // system("pause");
    return 0;
}

Measured memory_bytes: 256
#![allow(non_snake_case)]

use std::io::{stdin, Read};
use std::str::FromStr;
fn read_option<T: FromStr>() -> Option<T> {
    let stdin = 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()
}
fn read<T: FromStr>() -> T {
    let opt = read_option();
    opt.expect("failed to parse token")
}

fn main() {
    let n: usize = read();
    let vec: Vec<i32> = (0..n).map(|_| read()).collect();
    let mut unique = vec![vec[0]];
    for v in vec.windows(2) {
        if v[0] != v[1] {
            unique.push(v[1]);
        }
    }
    let mut ans = 0;
    let mut seq = vec![];
    for v in unique {
        if seq.is_empty() {
            seq.push(v);
            ans += 1;
            continue;
        }
        if seq.len() == 1 {
            seq.push(v);
            continue;
        }
        let (a, b, x) = (seq[seq.len() - 2], seq[seq.len() - 1], v);
        if (a > b && b > x) || (a < b && b < x) {
            seq.push(x);
        } else {
            seq = vec![x];
            ans += 1;
        }
    }
    println!("{}", ans);
}


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

using namespace std;

#define all(x) x.begin(), x.end()
#define sz(x) (int) x.size()
#define pb push_back
#define endl '\n'
#define snd second
#define fst first
#define fastio cin.tie(NULL),cout.sync_with_stdio(true)

typedef long long int ll;
typedef unsigned long long int ull;
typedef vector <int> vi;
typedef pair <ll,int> ii;
typedef pair <ii,int> iii;

const int mod = 1e9 + 7;
const int N = 100005;

/*
	se n>=k
	|(n-k)| = (n-k)
	=>||(n-k)| - k| = (n - 2*k) .... min = lower bound , upper bound de (n,k)

	else se n < k
	|(n-k)| = (k-n)
	=>||(n-k)| - k| = |-n| = n ... min = min(k-n, n)
*/

void solve(){
	ll n,k;
	cin >> n >> k;
	if(n >= k){
		cout << min(abs(n-k * (n/k)),abs(n-k * (n/k+1))) << endl;
	}else{
		cout << min(n, k-n) << endl;
	}
}

int main(){
	fastio;
	int t = 1;
	//cin >> t;
	while(t--)
		solve();
	return 0;
}


Measured memory_bytes: 3596
#include <iostream>
#include <vector>
#include <queue>
#include <cmath>
#include <algorithm>

#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define INF 999999999
using namespace std;

int main() {
  int n,num = 0;
  cin >> n;
  int p[n];
  for (int i = 0; i < n; i++) {
    cin >> p[i];
  }
  SORT(p,n);
  for (int i = 0; i < n-1; i++) {
    num += p[i];
  }
  num += p[n-1]/2;
  cout << num << endl;
}


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

#define rep(i, n) REP(i, 0, n)
#define REP(i, k, n) for(auto i = k; i != n; i++)
#define rrep(i, n) RREP(i, n, 0)
#define RREP(i, n, k) for(auto i = n; i != k; i--)
#define all(x, r) (x), (x)+(r)
#define ALL(x) (x).begin(), (x).end()
#define debug(x) cerr << #x << " " << x << endl
#define exst(x, data) (data).find(x) != (data).end()
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
#define np next_permutation
#define b32 bitset<32>

using ll = long long;
using Pii = pair<int,int>;
using Tiii = tuple<int, int, int>;
template<class T>using V = vector<T>;

class UnionFind {
private:
    vector<int> pare, rk;

    void init(int n){
        rep(i, n){
            pare[i] = i;
            rk[i] = i;
        }
    }

public:
    UnionFind(int n) {
        pare = vector<int>(n);
        rk = vector<int>(n);
        init(n);
    }

    int find(int x){
        if (x == pare[x])
            return x;
        return pare[x] = find(pare[x]); // 経路圧縮
    }

    void unite(int x,int y){
        x = find(x);
        y = find(y);
        if(x == y) // すでに結合済
            return;

        // rkの低い方をrkの高い方に併合
        if(rk[x] < rk[y])
            pare[x] = y;
        else
            pare[y] = x;
        if(rk[x] == rk[y])
            rk[x]++;
    }

    bool same(int x,int y){
        return find(x) == find(y);
    }
};

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

    int N, M; cin >> N >> M;
    V<int> p = V<int>(N+1); REP(i,1,N+1) cin >> p[i];
    UnionFind uf = UnionFind(N+1);
    rep(i,M) {
        int x, y; cin >> x >> y;
        uf.unite(p[x],p[y]);
    }

    int ans = 0;
    REP(i,1,N+1) {
        if(uf.same(i,p[i])) ans++;
    }
    cout << ans << endl;
    return 0;
}


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

ll gcd(ll x, ll y);
int fac(ll n, vector<int> num);

const int INF = 1001001001;

//mint�p�̒萔 (10��9��)
const int mod = 1000000007;

struct mint {
    ll x; // typedef long long ll;
    mint(ll x = 0) :x((x% mod + mod) % mod) {}
    mint operator-() const { return mint(-x); }
    mint& operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += mod - a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this; }
    mint operator+(const mint a) const { return mint(*this) += a; }
    mint operator-(const mint a) const { return mint(*this) -= a; }
    mint operator*(const mint a) const { return mint(*this) *= a; }
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t >> 1);
        a *= a;
        if (t & 1) a *= *this;
        return a;
    }

    // for prime mod
    mint inv() const { return pow(mod - 2); }
    mint& operator/=(const mint a) { return *this *= a.inv(); }
    mint operator/(const mint a) const { return mint(*this) /= a; }
};
istream& operator>>(istream & is, const mint & a) { return is >> a.x; }
ostream& operator<<(ostream & os, const mint & a) { return os << a.x; }

int main() {
    string s;
    cin >> s;
    int ans = 0;
    int x = 1, tot = 0;
    reverse(s.begin(), s.end());
    vector<int> cnt(2019);
    rep(i, s.size()) {
        cnt[tot]++;
        tot += (s[i]-'0')*x;
        tot %= 2019;
        ans += cnt[tot];
        x = x * 10 % 2019;
    }

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

/*���C�u�����ő����*/
//���[�O���b�h�̌ݏ��@
ll gcd(ll x, ll y) {
    ll num[3];
    num[0] = (x > y) ? x : y;
    num[1] = (x <= y) ? x : y;
    num[2] = num[0] % num[1];

    while (num[2]) {
        num[0] = num[1];
        num[1] = num[2];
        num[2] = num[0] % num[1];
    }

    return num[1];
}

/*�f��������*/
//���색�C�u����
int fac(ll n, vector<int> num) {
    ll kazu = n;
    for (int i = 2; i <= sqrt(n); i++) {
        while (1) {
            if (kazu % i != 0) break;

            kazu /= i;
            num[i]++;
        }
    }
    if (kazu == n && n != 1) return 1;
    int ans = 0;
    if (kazu != 1) ans++;
    for (int i = 2; i <= sqrt(n); i++) {
        for (int j = 1; j <= num[i]; j++) {
            num[i] -= j;
            ans++;
        }
    }
    return ans;
}

Measured memory_bytes: 3708
eval"N,*T="+`dd`.split*?,
T<<0
z=1
N.times{|i|a,b=T[N+i,2]
z=z*[[[a,t=T[i]].min,0,-1[a-t]][s=T[i-1]<=>t],0,(s%3-1)[t-a]][b<=>a]%(10**9+7)}
p z

Measured memory_bytes: 58064
#include<stdio.h>
#include<stdlib.h>
#include<math.h>

typedef long long int int64;

#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))
#define ABS(a) ((a)>(0)?(a):-(a))

typedef struct sequence{
  char s[6];
} seq;

int cmp(const void *a,const void *b){
  char *p=((seq *)a)->s;
  char *q=((seq *)b)->s;
  int i=0;
  while(p[i]!='\0' && q[i]!='\0'){
    if(p[i]!=q[i]) return (int)(p[i]-q[i]);
    i++;
  }
  if(p[i]=='\0' && q[i]=='\0') return 0;
  return p[i]=='\0'?-1:1;
}

void run(void){
  char s[5001];
  scanf("%s",s);
  int len=0;
  while(s[len]!='\0') len++;
  int k;
  scanf("%d",&k);
  seq *array=(seq *)malloc(sizeof(seq)*5*len);
  int alen=0;
  int i;
  for(i=1;i<=k;i++){
    int j;
    for(j=0;j+i-1<len;j++){
      int l;
      for(l=0;l<i;l++){
	array[alen].s[l]=s[j+l];
      }
      array[alen].s[l]='\0';
      alen++;
    }
  }
  qsort(array,alen,sizeof(seq),cmp);
  int cnt=0;
  i=0;
  seq t;
  while(cnt<k){
    t=array[i];
    cnt++;
    while(i<alen && cmp(&array[i],&t)==0) i++;
  }
  printf("%s\n",t.s);
  return;
}

int main(void){
  run();
  return 0;
}


Measured memory_bytes: 508
import java.io.*;

public class Main{
    public static void main(String[]args)throws IOException{
        BufferedReader br = new BufferedReader( new InputStreamReader(System.in));
        String s = br.readLine();
        String[] str = s.split(" ");
        int x = Integer.parseInt(str[0]);
        int y = Integer.parseInt(str[1]);
        System.out.println(x * y +" "+ 2 *(x + y));
    }
}

Measured memory_bytes: 24288
#include<stdio.h>
#include<string.h>
#include<math.h>
int main(void)
{
	int a,s[200],d,f=0,g=0,h=0,j,i;
	scanf("%d",&a);
	for(i=0;i<a;i++){
		scanf("%d",&s[i]);
		f+=s[i];
	}
	for(i=0;i<a;i++){
		if(s[i]%10!=0){
			h=1;
			break;
		}
	}
	if(h==0) f=0;
	if(h==1){
		for(i=0;i<a;i++){
			for(j=i+1;j<a;j++){
				if(s[i]<s[j]){
					d=s[i];
					s[i]=s[j];
					s[j]=d;
				}
			}
		}
		g=f%10;
		if(g==0){
			for(i=a-1;i>=0;i--){
				if(s[i]%10!=0){
					f-=s[i];
					break;
				}
			}
		}
	}
	printf("%d\n",f);
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repo(i,n) for(int i = 1; i < (int)(n); i++)
#define pb push_back
#define mp make_pair
#define np next_permutation
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
#define pi acos(-1.0)
const ll INF = 1LL<<61;
template<class T>bool chmax(T &a, const T &b) { 
  if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) {
  if (b<a) { a=b; return 1; } return 0; }
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }
ll jou(ll N, ll P){if(P==0) return 1;
  if(P%2==0){ll t = jou(N, P/2);return t*t % mod;
  }return (N * jou(N, P-1)) % mod;}  //jou(n,mod-2)で逆元
//intの最大値2147483647 ≒ 2×10^9
//long longの最大値9223372036854775807 ≒ 9×10^18
//'大文字'+=32;    で小文字に
//  cout << fixed << setprecision (20);   小数点以下2０桁まで
//実行時間制約2秒では２×10^8回くらいまで計算できる




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

  vector<ll> p(n);
  rep(i,n){
    cin>>p[i];
  }

  vector<ll> q(n);
  q[0]=p[0];
  repo(i,n){
    q[i]=gcd(q[i-1],p[i]);
  }

  vector<ll> r(n);
  r[n-1]=p[n-1];
  for(int i=n-2;i>=0;i--){
    r[i]=gcd(r[i+1],p[i]);
  }

  ll ans=max(q[n-2],r[1]);
  repo(i,n-1){
    chmax(ans,gcd(q[i-1],r[i+1]));
  }


  cout << ans << endl;
}


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

using namespace std;

int N, M, A, B;

int main ()
{
//freopen ("input", "r", stdin);
//freopen ("output", "w", stdout);

scanf ("%d %d %d %d", &N, &M, &B, &A);
for (int i=1; i<=N; i++, printf ("\n"))
    for (int j=1; j<=M; j++)
        printf ("%d", (i <= A) ^ (j <= B));
return 0;
}


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

using namespace std;

using ll = long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using vi = vector<int>;
using vl = vector<ll>;

using _loop_int = int;
#define REP(i,n) for(_loop_int i=0; i<(_loop_int)(n); i++)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a); i<(_loop_int)(b); i++)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1; i>=(_loop_int)(a); i--)

#define CHMIN(a,b) (a)=min((a),(b))
#define CHMAX(a,b) (a)=max((a),(b))
#define ALL(v) (v).begin(),(v).end()

#define DEBUG(x) cerr<<#x<<": "<<(x)<<endl
#define DEBUG_VEC(v) cerr<<#v<<": ";REP(__i,(v).size())cerr<<((v)[__i])<<", ";cerr<<endl

const ll MOD = 1000000007ll;

int n;
int a[125252];
set<int> indeg[125252];
int ans[125252];

int main(){
    scanf("%d",&n);
    REP(i,n)scanf("%d",a+i),a[i]--;
    REP(i,n)indeg[a[i]].insert(i);
    set<pii> S;
    REP(i,n)S.insert(pii(indeg[i].size(), i));
    set<int> rest;
    REP(i,n)rest.insert(i);
    int ban = -1;

    int it = 0;
    REP(i,n){
        if(rest.size() < 8){
            it = i;
            break;
        }
        int cand = -1;
        if(S.rbegin()->first == n-i-1){
            // must choose
            cand = S.rbegin()->second;
        }else if(*rest.begin() != ban){
            // can choose
            cand = *rest.begin();
        }else if(rest.size()>1){
            // next
            auto it = rest.begin();
            it++;
            cand = *it;
        }else{
            puts("-1"); return 0;
        }
        ans[i] = cand;
        ban = a[cand];
        rest.erase(cand);
        S.erase(pii(indeg[cand].size(), cand));
        if(rest.count(ban)){
            S.erase(pii(indeg[ban].size(), ban));
            indeg[ban].erase(cand);
            S.insert(pii(indeg[ban].size(), ban));
        }
    }
    vi v;
    for(int x : rest){
        v.push_back(x);
    }

    do{
        FOR(i,it,n)ans[i] = v[i-it];
        bool ook = true;
        REP(i,n-1)if(ans[i+1] == a[ans[i]]){
            ook = false;
        }
        if(ook){
            break;
        }
    }while(next_permutation(ALL(v)));

    bool ook = true;
    REP(i,n-1)if(ans[i+1] == a[ans[i]]){
        ook = false;
    }
    if(!ook){
        puts("-1"); return 0;
    }
    REP(i,n)printf("%d%c",ans[i]+1," \n"[i==n-1]);
    return 0;
}


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

using namespace std;

int main()
{
	string s;
	cin >> s;
	if (s == "AAA")
	{
		cout << "No" << endl;
	}
	else if (s == "BBB")
	{
		cout << "No" << endl;
	}
	else
	{
		cout << "Yes" << endl;
	}
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<utility>
#include<memory>
 
#define ALL(g) (g).begin(),(g).end()
#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define INF 1<<25
#define pb push_back
 
typedef long long ll;
 
using namespace std;

void init(int par[],int rank[],int N){
  rep(i,N){
    par[i]=i;
    rank[i]=0;
  }
  return ;
}

int find(int par[],int x){
  if(par[x]==x) return x;
  else return par[x]=find(par,par[x]);
}

void unite(int par[],int rank[],int x,int y){
  x=find(par,x);
  y=find(par,y);
  if(x==y)  return ;
  if(rank[x]<rank[y]){
    par[x]=y;
  }else{
    par[y]=x;
    if(rank[x]==rank[y])  ++rank[x];
  }
  return ;
}

bool same(int par[],int x,int y){
  if(par[x]==par[y])  return true;
  else  return false;
}

int main(){
  int N,K,L;
  cin >> N >> K >> L ;
  int p[K+1],q[K+1],r[L+1],s[L+1];
  int par1[N+1],rank1[N+1],par2[N+1],rank2[N+1];
  init(par1,rank1,N);
  init(par2,rank2,N);
  int a,b;
  rep(i,K){
    cin >> a >> b ;
    unite(par1,rank1,a-1,b-1);
  }
  rep(i,L){
    cin >> a >> b ;
    unite(par2,rank2,a-1,b-1);
  }
  map<pair<int,int>,int> mp;
  rep(i,N){
    a=find(par1,i);
    b=find(par2,i);
    if(mp.find({a,b})!=mp.end()){
      mp[{a,b}]++;
    }else{
      mp[{a,b}]=1;
    }
  }
  rep(i,N)  cout << mp[{find(par1,i),find(par2,i)}] << " ";
  cout << endl;
  return 0;
}

Measured memory_bytes: 15104
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>

std::vector<int64_t> makeFib()
{
	int64_t f0 = 0, f1 = 1, f2;

	std::vector<int64_t> fib;
	fib.reserve(100000);

	fib.push_back(0);
	for (int i = 0; i <= 100000; i++) {
		fib.emplace_back(f1);
		f2 = (f1 + f0) % 1000000007l;

		f0 = f1;
		f1 = f2;
	}

	return fib;
}

int main()
{
	int N, M;
	std::cin >> N;
	std::cin >> M;
	std::vector<int> nums;
	for (int i = 0; i < M; i++)
	{
		int num;
		std::cin >> num;
		nums.push_back(num);
	}
	std::vector<int64_t> fibs = makeFib();

	int64_t result = 1;
	int prev = -1;
	for (int num : nums)
	{
		int space = num - prev - 1;
		result = (result * fibs[space]) % 1000000007l;
		prev = num;
	}
	int space = (N + 1) - prev - 1;
	result = (result * fibs[space]) % 1000000007l;

	std::cout << result % 1000000007l;
}

Measured memory_bytes: 2296
import jdk.nashorn.internal.ir.BaseNode;

import java.io.*;
import java.util.*;

class Main {

	public static void main(String[] args) throws Exception {
		final Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int M = sc.nextInt();

		long[] d = new long[N];
		Arrays.fill(d, Long.MAX_VALUE);
		d[0] = 0;

		int[] a = new int[M];
		int[] b = new int[M];
		long[] c = new long[M];
		for (int i = 0; i < M; i++) {
			a[i] = sc.nextInt() - 1;
			b[i] = sc.nextInt() - 1;
			c[i] = sc.nextLong() * -1;
		}

		int count = 0;
		while (true) {
			boolean hasUpdate = false;
			for (int i = 0; i < M; i++) {
				if (d[a[i]] != Long.MAX_VALUE && d[b[i]] > d[a[i]] + c[i]) {
					d[b[i]] = d[a[i]] + c[i];
					hasUpdate = true;
				}
			}
			if (!hasUpdate) {
				System.out.println(-1L * d[N - 1]);
				return;
			}
			if (++count >= N) break;


		}
		long answer = -1L * d[N - 1];
		boolean[] isNegativeClosed = new boolean[N];
		for (int k = 0; k < N; k++) {
			for (int i = 0; i < M; i++) {
				if (d[a[i]] != Long.MAX_VALUE && d[b[i]] > d[a[i]] + c[i]) {
					d[b[i]] = d[a[i]] + c[i];
					isNegativeClosed[b[i]] = true;
				}
				if (isNegativeClosed[a[i]]) isNegativeClosed[b[i]] = true;
			}
		}

		if (isNegativeClosed[N - 1]) {
			System.out.println("inf");
		} else {
			System.out.println(answer);
		}
	}
}


Measured memory_bytes: 28288
# Here your code !
n,m,k=gets.split(' ').map(&:to_i)


(m+1).times{|a|
    
    (n+1).times{|b|
        if k==(a*n+b*m-2*a*b)
            print("Yes")
            exit
        end
    }
    
}

print("No")


Measured memory_bytes: 3836
#include<bits/stdc++.h>
#define rep(k,i,n) for(long long i=k;i<n;++i)
using namespace std;
typedef long long ll;
int main(void){
    // Your code here!
    int N;
    cin>>N;
    rep(1,i,10){
        rep(i,j,10){
            if(i*j==N){
                cout<<"Yes"<<endl;
                return 0;
            }
        }
    }
    cout<<"No"<<endl;
}


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

#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
#define LL long long
#define pii pair <int,int>
#define fi first
#define se second
#define pb push_back
#define mpr make_pair

using namespace std;

const LL MOD=1e9+7;

LL n;
queue <LL> q;
vector <LL> v;

int main()
{
	cin>>n;
	repn(i,9) q.push(i);
	while(!q.empty())
	{
		LL p=q.front();
		q.pop();
		v.pb(p);
		if(v.size()==n) break; 
		if(p%10-1>=0) q.push(p*10+p%10-1);
		q.push(p*10+p%10);
		if(p%10+1<10) q.push(p*10+p%10+1);
	}
	cout<<v[n-1]<<endl;
	return 0;
}

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

# AtCoder Beginner Contest
# Problem B

if __name__ == '__main__':
    a, b, x = list(map(int, input().split()))

    # See:
    # https://atcoder.jp/img/arc064/editorial.pdf
    fb = (b // x) + 1
    fa = ((a - 1) // x) + 1

    if a == 0:
        print(fb)
    else:
        print(fb - fa)


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

using namespace std;
const auto MOD = (long long) 1e9 + 7;

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

    long long a[1000] = {};
    for (int i = 2; i <= n; ++i) {
        int t = i;
        for (int p = 2; p <= t; ++p) {
            while (t % p == 0) {
                a[p]++;
                t /= p;
            }
        }
    }

    long long ans = 1;
    for (auto x:a) {
        ans = ans * (x + 1) % MOD;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <map>
#include <set>

#define MAX_INT 2147483647
#define PI 3.141592653589793238462643383279502884L

#define long long long int

using std::vector;
using std::map;
using std::set;
using std::string;
using std::pair;
using std::cin;
using std::cout;

// @author: pashka

int main() {
    std::ios::sync_with_stdio(false);

    int n, k;
    cin >> n >> k;

    vector<int> a(n);
    vector<int> b(n);

    for (int i = 0; i < n; i++) {
        cin >> a[i] >> b[i];
    }

    k++;
    long res = 0;
    while (k > 0) {
        k--;
        long s = 0;
        for (int i = 0; i < n; i++) {
            if ((a[i] & k) == a[i]) {
                s += b[i];
            }
        }
        k = k & (k + 1);
        res = std::max(res, s);
    }

    cout << res << "\n";

    return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<iomanip>
using namespace std;
int x_x(int x,int n){
  if(x>=n) x = 0;
  if(x<0) x = n - 1;
  return x;
}
int y_y(int y,int n){
  if(y>=n) y = 0;
  return y;
}  
int main(){
  int n;
  while(cin>>n){
    if(n==0) break;
    int magic[n][n];
    for(int i=0;i<n;i++){
      for(int j=0;j<n;j++) magic[j][i] = 0;
    }
    magic[n/2][n/2+1] = 1;
    int x = n / 2;
    int y = n / 2 + 1;
    int count = 1;
    //cout << x << ' ' << y << endl;
    while(count!=n*n){
      count++;
      x = x_x(x+1,n);
      y = y_y(y+1,n);
      /*if(x+1>=n) x = 0;
      else x++;
      if(y+1>=n) y = 0;
      else y++;*/
      //cout << x << ' ' << y << endl;
      while(magic[x][y]!=0){
	x = x_x(x-1,n);
	y = y_y(y+1,n);
	/*if(x-1<0) x = n - 1;
	else x--;
	if(y+1>=n) y = 0;
	else y++;*/
      } 
      magic[x][y] = count;
    }
    for(int i=0;i<n;i++){
      for(int j=0;j<n;j++){
	cout << setw(4) << magic[j][i];
      }
      cout << endl;
    }
  }
  return 0;
} 

Measured memory_bytes: 1176
n = int(input())
d = {}

for a in range(1, n+1):
    a = str(a)
    f, l = a[0], a[-1]
    if '0' in [f, l]:
        continue
    if (f, l) in d:
        d[(f, l)] += 1
    else:
        d[(f, l)] = 1

ans = 0
for b in range(1, n+1):
    b = str(b)
    f, l = b[-1], b[0]
    if (f, l) in d:
        ans += d[(f, l)]
print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,n-1,0)
#define REPL(i,m,n) for(ll i=(ll)(m); i<(ll)(n); i++)
#define repl(i,n) REPL(i,0,n)
#define all(v) v.begin(), v.end()
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;

vector<ll> A, F;
bool test(int n, ll k, ll t) {
  ll need = 0;
  rep(i, n)
    need += max(0LL, (F[i] * A[i] - t + F[i] - 1) / F[i]);
  return need <= k;
}

ll binary_search(int n, ll k, ll m) {
  ll l = 0, r = m+1;
  while(r - l > 1) {
    ll mid = (l + r) / 2;
    if(test(n, k, m-mid))
      l = mid;
    else
      r = mid;
  }
  return m-l;
}

int main() {
  int N; ll K;
  cin >> N >> K;
  A = vector<ll>(N);
  F = vector<ll>(N);
  rep(i, N) cin >> A[i];
  rep(i, N) cin >> F[i];
  sort(all(A));
  sort(all(F), greater<ll>());
  ll M = 0;
  rep(i, N) M = max(M, A[i] * F[i]);
  cout << binary_search(N, K, M) << endl;
  return 0;
}



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

//#include <atcoder/all>

using namespace std;
// using namespace atcoder;
using ll = long long;

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

  vector<int> dcnt(n - 1, 0);  // D = i となる頂点の個数
  int mxd = 0;
  for (int i = 0; i < n; i++) {
    int d;
    cin >> d;

    if (i == 0 && d != 0) {
      // 頂点1は距離0のみ
      cout << 0 << endl;
      return 0;
    }

    if (i != 0 && d == 0) {
      // 頂点2~は距離1~のみ
      cout << 0 << endl;
      return 0;
    }

    mxd = max(d, mxd);
    dcnt[d]++;
  }

  dcnt[0] = 1;
  ll ans = 1;
  for (int i = 1; i <= mxd; i++) {
    for (int j = 0; j < dcnt[i]; j++) {
      // D = i なる頂点ひとつ (j) に対して
      // D = i-1 となる頂点の個数 dcnt[i-1] だけ親がある
      ans *= dcnt[i - 1];
      ans %= 998244353;
    }
  }

  cout << ans << endl;
}

Measured memory_bytes: 3644
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include <fstream>
#include <time.h>
#include <iterator>


#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v,n) reverse(v,v+n);
#define VREVERSE(v) reverse(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)
#define m0(x) memset(x,0,sizeof(x))
#define print(x) cout<<x<<endl;
#define pe(x) cout<<x<<" ";
#define lb(v,n) lower_bound(v.begin(), v.end(), n);
#define ub(v,n) upper_bound(v.begin(), v.end(), n);
#define int long long
#define all(x) (x).begin(), (x).end()

using namespace std;

const int MOD = (ll)1000000000 + 7;
const ll INF = 1e17;
const double pi = acos(-1);
const double EPS = 1e-10;
typedef pair<int, int>P;


signed main() {
	int A, P; cin >> A >> P;
	P += A * 3;
	print(P / 2);
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
ABCD = str, input()
ABCD_list = list(ABCD[1])
A = int(ABCD_list[0])
B = int(ABCD_list[1])
C = int(ABCD_list[2])
D = int(ABCD_list[3])
if A+B+C+D == 7:
    print(str(A)+"+"+str(B)+"+"+str(C)+"+"+str(D)+"=7")
elif A-B+C+D == 7:
    print(str(A)+"-"+str(B)+"+"+str(C)+"+"+str(D)+"=7")
elif A+B-C+D == 7:
    print(str(A)+"+"+str(B)+"-"+str(C)+"+"+str(D)+"=7")
elif A-B-C+D == 7:
    print(str(A)+"-"+str(B)+"-"+str(C)+"+"+str(D)+"=7")
elif A+B+C-D == 7:
    print(str(A)+"+"+str(B)+"+"+str(C)+"-"+str(D)+"=7")
elif A-B+C-D == 7:
    print(str(A)+"-"+str(B)+"+"+str(C)+"-"+str(D)+"=7")
elif A+B-C-D == 7:
    print(str(A)+"+"+str(B)+"-"+str(C)+"-"+str(D)+"=7")
elif A-B-C-D == 7:
    print(str(A)+"-"+str(B)+"-"+str(C)+"-"+str(D)+"=7")


Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define N 100010
#define ll long long
#define mod (1000000000+7)
#define Fast ios_base::sync_with_stdio(false); cin.tie(NULL);

using namespace std;

int main()
{
    Fast
    int n,k; cin>>n>>k;
    int a[n] , T[n];
    for(int i=0;i<n;i++)
        cin>>a[i];
    T[0] = 0; T[1] = abs(a[0] - a[1]);
    for(int i=2;i<n;i++)
    {
        int y = INT_MAX; int u = k;
        for(int j=i-1;u>0&&j>=0;j--)
        {
            u--;
            int x = T[j] + abs(a[i] - a[j]);
            //cout<<"i="<<i<<" "<<"X="<<x<<" "<<"Y="<<y<<endl;
            //cout<<min(x,y)<<endl;
            T[i] = min(x , y);
            y = min(x , y);
        }
    }
    /*for(int i=0;i<n;i++)
        cout<<T[i]<<" ";
    cout<<endl;*/
    cout<<T[n-1]<<endl;
}
/*int x = a[i]; int y = a[i-1]; int z = a[i-2];
        int a = T[i-1] + abs(x - y);
        int b = T[i-2] + abs(x - z);
        T[i] = min(a , b);*/


Measured memory_bytes: 4356
N = int(input())
A, B = map(int, input().split())
p = list(map(int, input().split()))
a, b, c = 0, 0, 0
for i in p:
    if i <= A: a += 1
    elif i <= B: b += 1
    else: c += 1
print(min(a, b, c))


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

using namespace std;
#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++)
typedef long long ll;
using Graph = vector<vector<int>>;
typedef long long ll;
typedef pair<int, int> P;

const int MOD = 1000000007;
const int INF_32 = 1LL << 30;
const int64_t INF_64 = 1LL << 60;

int n, m, q;
ll ans = 0;
vector<ll> A;
vector<ll> a;
vector<ll> b;
vector<ll> c;
vector<ll> d;

void dfs(int i)
{
    if (i == n) {
        ll sum = 0;
        for (int j = 0; j < q; j++) {
            if (A.at(b.at(j) - 1) - A.at(a.at(j) - 1) == c.at(j)) {
                sum += d.at(j);
            }
        }
        ans = max(ans, sum);
        return;
    }
    for (int x = A.at(i - 1); x <= m; x++) {
        A.at(i) = x;
        dfs(i + 1);
    }
}
int main()
{
    cin >> n >> m >> q;
    A.resize(n);
    for (int j = 0; j < q; j++) {
        ll inp_a, inp_b, inp_c, inp_d;
        cin >> inp_a >> inp_b >> inp_c >> inp_d;
        a.push_back(inp_a);
        b.push_back(inp_b);
        c.push_back(inp_c);
        d.push_back(inp_d);
    }
    A.at(0) = 1;
    dfs(1);
    cout << ans << endl;
}

Measured memory_bytes: 3648
#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>;
#define chmax(x,y) x = max(x,y)
#define chmin(x,y) x = min(x,y)

const int INF = 1e9 + 10;

int N;
int pos[2][2020];
int L[2][2020][2020];
int dp[2020][2020];

int main() {
    string s;
    int x;
    cin >> N;
    rep(i,2*N) {
		cin>>s>>x;
		pos[s=="W"][x-1]=i;
	}
    rep(i,2) {
		rep(x,N) {
			for(int y=x+1;y<N;y++) if(pos[i][y]<pos[i][x]) L[i][x][N]++;
			for(int y=N-1;y>=0;y--) L[i][x][y]=L[i][x][y+1]+(pos[i^1][y]<pos[i][x]);
		}
	}
    rep(x,N+2) rep(y,N+2) dp[x][y]=1<<25;
    dp[0][0] = 0;
    rep(x,N+1) rep(y,N+1) {
		if(x<N) chmin(dp[x+1][y],dp[x][y]+L[0][x][y]);
		if(y<N) chmin(dp[x][y+1],dp[x][y]+L[1][y][x]);
	}
    cout << dp[N][N] << endl;
    return 0;
}

Measured memory_bytes: 50960
// 2013/07/08 Tazoe

#include <iostream>
#include <string>
#include <stack>
using namespace std;

int main()
{
	while(true){
		string S;
		getline(cin, S);

		if(S==".")
			break;

		stack<char> stk;

		bool flg = true;

		for(int i=0; i<S.size(); i++){
			if(S[i]=='(' || S[i]=='['){
				stk.push(S[i]);
			}
			else if(S[i]==')'){
				if(!stk.empty() && stk.top()=='('){
					stk.pop();
				}
				else{
					flg = false;
				}
			}
			else if(S[i]==']'){
				if(!stk.empty() && stk.top()=='['){
					stk.pop();
				}
				else{
					flg = false;
				}
			}

			if(!flg)
				break;
		}

		if(flg && stk.empty()){
			cout << "yes" << endl;
		}
		else{
			cout << "no" << endl;
		}
	}

	return 0;
}

Measured memory_bytes: 1184
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

# 参考: https://atcoder.jp/contests/abc140/submissions/7402925
# できるだけ大きいスライムを貪欲に生んでいく
# 自力コードはTLEのためmaspyさんのコードを参考にした

import array
from bisect import *
from collections import *
import fractions
import heapq
from itertools import *
import math
import random
import re
import string
import sys


def solve(N, S):
    S = sorted(S)
    used = [S[-1]]
    unused = S[:-1]
    for _ in range(N):
        next_used = []
        next_unused = []
        for p in used[::-1]:
            while unused:
                x = unused.pop()
                if x < p:
                    next_used.append(x)
                    break
                else:
                    next_unused.append(x)
                    continue
        used += next_used
        used.sort()
        unused = unused + next_unused[::-1]
    
    return len(used) == (2**N)


N = int(input())
S = list(map(int, input().split()))
print("Yes" if solve(N, S) else "No")


Measured memory_bytes: 37020
from collections import Counter

def main():
    s = list(map(int,input()[::-1]))

    t = []
    m = 0
    for i,s_i in enumerate(s):
        m = m+s_i*pow(10,i,2019)
        t.append(m%2019)
    
    c = Counter(t)
    ans = c[0]
    for i in c.values():

        ans += i*(i-1)//2
    print(ans)

if __name__ == "__main__":
    main()

Measured memory_bytes: 87084
#include<bits/stdc++.h>
#define ll long double
using namespace std;
int main()
{
	ll a,b,c;
	cin>>a>>b>>c;
	long double eps = 1.0E-14;
 
	if(sqrt(a)+sqrt(b)+eps<sqrt(c))
    {
      cout<<"Yes"<<endl;
    }
  else{
   cout<<"No"<<endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int x,happy = 0;cin >> x;
    while(x)
    {
        if(x >= 500)
        {
            x -= 500;
            happy += 1000;
        }
        else if(x >= 100)
        {
            x -= 100;
            happy += 100;
        }
        else if(x >= 10)
        {
            x -= 10;
            happy += 10;
        }
        else if(x >= 5)
        {
            x -= 5;
            happy += 5;
        }
        else x = 0;
    }
    cout << happy << endl;
    return 0;
}


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

#define ll long long
#define vll vector<ll>
#define vvll vector<vll>
#define rep(i, n) for(i = 0; i < n; i++)

int main(){
    int N;
    vector<double> As(200000);

    int i, j;
    vvll count(19, vll(19, 0));
    vvll csum(19, vll(19, 0));

    cin >> N;
    As.resize(N);
    rep (i, N) {
        cin >> As[i];
        ll bigA = (ll)(As[i] * 1e9 + 0.5);
        int two = 0, five = 0;
        while (bigA % 2 == 0) {
            two++;
            bigA /= 2;
        }
        while (bigA % 5 == 0) {
            five++;
            bigA /= 5;
        }
        count[min(18, two)][min(18, five)]++;
    }

    for (i = 18; i >= 0; i--) {
        for (j = 18; j >= 0; j--) {
            csum[i][j] = count[i][j];
        }
    }
    for (i = 18; i >= 0; i--) {
        for (j = 17; j >= 0; j--) {
            csum[i][j] += csum[i][j+1];
        }
    }
    for (i = 17; i >= 0; i--) {
        for (j = 18; j >= 0; j--) {
            csum[i][j] += csum[i+1][j];
        }
    }
    ll ans = 0;
    for (i = 18; i >= 0; i--) {
        for (j = 18; j >= 0; j--) {
            ans += count[i][j] * csum[18 - i][18 - j];
            if (i >= 9 and j >= 9) {
                ans -= count[i][j];
            }
            // cout << count[i][j] << ' ';
        }
        // cout << '\n';
    }

    cout << ans / 2 << '\n';

    return 0;
}

Measured memory_bytes: 4656
while True:
	data = [int(x) for x in input().split()]
	if data == [0, 0, 0, 0]:
		break
	matrix = [[1 for x in range(data[0])] for y in range(data[1])]
	#print('Matrix :', len(matrix), len(matrix[0]))
	n = data[2] + data[3]
	command = list()
	while n > 0:
		command.append([int(x) for x in input().split()])
		n -= 1
	flipping = [command[x] for x in range(data[2])]
	holing = [command[x] for x in range(data[2], len(command))]
	for c, b in flipping:
		matrixtemp = list()
		if c == 1:
			#print('\tFlipping l-r\t:', b, ' Blocks')
			matrixtemp = [[matrix[y][x] for x in range(b)] for y in range(len(matrix))]
			for n in range(len(matrixtemp)):
				matrixtemp[n] = matrixtemp[n][::-1]
			for n in range(len(matrix)):
				matrix[n] = matrix[n][b:]
			if len(matrixtemp[0]) > len(matrix[0]):
				for y in range(len(matrix)):
					for x in range(len(matrix[n])):
						matrixtemp[y][x] += matrix[y][x]
				matrix = matrixtemp
			else:
				for y in range(len(matrix)):
					for x in range(b):
						matrix[y][x] += matrixtemp[y][x]
		else:
			#print('\tFlipping d-u\t:', b, ' Blocks')
			matrixtemp = matrix[-b:]
			matrixtemp = matrixtemp[::-1]
			matrix = matrix[:-b]
			if len(matrixtemp) > len(matrix):
				for y in range(-len(matrix), 0, 1):
					for x in range(len(matrixtemp[0])):
						matrixtemp[y][x] += matrix[y][x]
				matrix = matrixtemp
			else:
				for y in range(-b, 0, 1):
					for x in range(len(matrixtemp[0])):
						matrix[y][x] += matrixtemp[y][x]
		#print('\t',matrix)
	for x, y in holing:
		print(matrix[len(matrix) - y - 1][x])


Measured memory_bytes: 5640
d, g = map(int, input().split())
pc = [list(map(int, input().split())) for i in range(d)]
ans = float("inf")
# 解いていない問題の配点をrestとして保持しておく。
# iは解いた問題の種類(配点/100)
# countは解いた問題の数
def dfs(i,sum,count,rest):
    # global変数としてansを引継ぎ
    global ans
    if i == d:
        # 合計がgoalを超えていなければrestに残っている問題の中で最大の得点の問題を解いていく。
        if sum < g:
            use = max(rest)
            n = min(pc[use-1][0], -(-(g-sum)//(use*100)))
            count += n
            sum += n*use * 100
            
        # 合計値が与えられた得点を超えていたら，最小の問題数を答える。
        if sum >= g:
            ans = min(ans, count)
            
    else:
        # 総合スコア，解いた問題数，まだ解いていない問題を更新する。
        # i得点の問題を解かないで次に進める場合
        dfs(i + 1, sum, count, rest)
        # i得点の問題を解いて先に進める場合，得点と問題数を加え，restからその得点要素を消去
        dfs(i + 1, sum + pc[i][0] * (i+1) * 100 + pc[i][1], count + pc[i][0], rest - {i+1})


dfs(0,0,0,set(range(1,d + 1)))

# 関数内で定義したグローバル変数を出力する
print(ans)

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

using namespace std;

#define EACH(i,a) for (auto& i : a)
#define FOR(i,a,b) for(int i=(int)a;i<(int)b;++i)
#define RFOR(i,a,b) for(int i=(int)b-1;i>=(int)a;--i)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(a) (a).begin(),(a).end()
#define debug(x) cerr << #x << ":" << x << endl;
#define OK(ok) cout << (ok ? "Yes" : "No") << endl;
typedef long long ll;

void CINT(){}
template <class Head,class... Tail>
void CINT(Head&& head,Tail&&... tail) {
  cin >> head; CINT(move(tail)...);
}
#define CIN(...) int __VA_ARGS__;CINT(__VA_ARGS__)
#define LCIN(...) ll __VA_ARGS__;CINT(__VA_ARGS__)
#define SCIN(...) string __VA_ARGS__;CINT(__VA_ARGS__)

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

int N;
int a[MAX_N];

int f(int x)
{
  int res = 0;
  while(x % 2 == 0) {
    x /= 2;
    res++;
  }
  return res;
}

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

  cin >> N;
  ll ans = 0;
  REP(i, N) {
    cin >> a[i];
    ans += f(a[i]);
  }

  cout << ans  << endl;

  return 0;
}



Measured memory_bytes: 256
#include <stdio.h>
#define N 100000
int binarySearch(int[],int,int);
int main(){
  int x,i,y,b,S[N],count=0;
  scanf("%d",&x);
  for(i=0;i<x;i++){
    scanf("%d",&S[i]);
   
  }
  scanf("%d",&y);
  for(i=0;i<y;i++){
    scanf("%d",&b);
    if(binarySearch(S,x,b)== 1)count++;
    
  }
  printf("%d\n",count);
  return 0;
}
int binarySearch(int A[],int n,int b){
  int left=0,right=n,mid;
  while(left<right){
    mid=(left + right)/2;
    if(A[mid]==b)return 1;
    else if(b< A[mid])right =mid;
    else left=mid +1;
  }
  return 0;
}



Measured memory_bytes: 2108
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;
using System.IO;
using System.Threading.Tasks;

namespace AtCoder
{
    class Program
    {
        private static string Read() { return Console.ReadLine(); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }

        private static int Solve(int N, int W, int[] A)
        {
            int x = Math.Abs(A[N - 1] - W);
            int y = (N == 1) ? 0 : Math.Abs(A[N - 1] - A[N - 2]);
            return Math.Max(x, y);
        }
        static void Main(string[] args)
        {
            int[] values = ReadInts();
            int[] A = ReadInts();
            Console.WriteLine(Solve(values[0], values[2], A));
        }
    }
}


Measured memory_bytes: 11220
#include<iostream>
using namespace std;
int main(){
	int W,H,x,y,r;
	cin>>W>>H>>x>>y>>r;
	if(x-r>=0&&x+r<=W&&y-r>=0&&y+r<=H) {
		cout<<"Yes"<<endl;
	}else{
		cout<<"No"<<endl;
		}
}

Measured memory_bytes: 1160
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;

class Main{
    public static void main(String[] args) throws IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        
        String[] input = br.readLine().split(" ");

        System.out.println((Integer.parseInt(input[0]) + Integer.parseInt(input[1])) / 2);
    }
} 



Measured memory_bytes: 24476
#include <bits/stdc++.h> 
using namespace std;
#define rep(i, N) for(int i=0; i<N; i++)
typedef long long ll;
#define dump(x) cerr<<#x<<"="<<x<<endl
using P = pair<int, int>;

int main() {
    int n; cin >> n;
    vector<vector<int>> a(2, vector<int>(n,0));
    for(int i=0; i<2; i++){
        rep(j, n) cin >> a.at(i).at(j);
    }

    vector<int> sum0(n+1, 0);
    vector<int> sum1(n+1, 0);
    rep(i, n){
        sum0.at(i+1) = sum0.at(i) + a.at(0).at(i); 
        sum1.at(i+1) = sum1.at(i) + a.at(1).at(i); 
    }

    int sum = 0;
    for(int i=1; i<=n; i++){
        sum = max(sum0.at(i)+sum1.at(n)-sum1.at(i-1), sum);
    }

    cout << sum << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define f first
#define s second

int main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    ll mod = 1e9+7;
    int n;
    cin>>n;
    ll a[n];
    ll sum = 0;
    for(int i=0;i<n;i++){
    	cin>>a[i];
    	sum+=a[i];
    	sum%=mod;
	}
	
	ll ans=0;
 	for(int i=0;i<n;i++){
 		sum=(sum+mod-a[i])%mod;
 		ans=(ans+(a[i]*sum)%mod)%mod;
	 }
	 
	cout<<ans;
	return 0;
}

Measured memory_bytes: 5204
#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 10;
int cnt[N], n;
int a[N], ans[N];

int main() {
	cin>>n;for(int i = 1; i <= n; i++) {
		int t; scanf("%d", &t);
		cnt[t]++;
	}
	for(int i = 1; i <= n; i++) if (cnt[i]) {
		a[++a[0]] = cnt[i];
	}
	sort(a + 1, a + 1 + a[0]);
	int sum = 0;
	for(int cs = 1, j = 0; cs <= n; cs++) {
		while(j < a[0] && a[j + 1] < cs){
			j++;
			sum += a[j];
		}
		int t = sum / cs + a[0] - j;
		ans[t] = max(ans[t], cs);
	}
	for(int i = n; i; i--) ans[i] = max(ans[i + 1], ans[i]);
	for(int i = 1; i <= n; i++) printf("%d\n", ans[i]);
}

Measured memory_bytes: 4224