akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;
int main()
{
	string a,b,c;
	getline(cin,a);
	getline(cin,b);
	sort(b.begin(),b.end());
    reverse(b.begin(),b.end());
    sort(a.begin(),a.end());
    if (a<b) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int check(char x){
    if(x=='M')return 1000;
    else if(x=='D')return 500;
    else if(x=='C')return 100;
    else if(x=='L')return 50;
    else if(x=='X')return 10;
    else if(x=='V')return 5;
    else if(x=='I')return 1;
    else return 0;
}
int main(void){
 
    char str[100]={0};
 
    while(cin>>str){
    int ans=0;
        for(int i=0;sizeof(str);i++){
            if(check(str[i])<check(str[i+1]))ans+=(check(str[i+1])-check(str[i])),i++;
            else if(str[i]==0)break;
            else ans+=check(str[i]);
 
        }
 
        cout<<ans<<endl;
 
        for(int i=0;i<sizeof(str);i++){
            str[i]=0;
        }
    }
    return 0;
}

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

void solve(long long s){
    int count = 0;
    if (s == 1) count = 0;
    else if (s == 2) count = 0;
    else {
        while (s != 4) {
            if (s % 2) s = 3 * s + 1;
            else s /= 2;
            count++;
        }
    }
    cout << count + 4 << '\n';
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    long long s;
    scanf("%lld",&s);
    solve(s);
    return 0;
}


Measured memory_bytes: 256
//  ROAD TO GREEN
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <cmath>
#include <iomanip>

using namespace std;
typedef long long ll;
const ll MAXN = 1e5+2;
vector<bool> used(MAXN,false);
int n,m; int a[MAXN];

int main(){
    long long n; cin >> n;
    n = n*(n-1)/2;
    cout << n << endl;
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <cmath>
#include <utility>
#include <iostream>
#include <functional>
#include <bitset>
#include <algorithm>
#include <vector>
#include <forward_list>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <numeric>
#define ll long long int
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
int mx4[] = {0,1,0,-1};
int my4[] = {1,0,-1,0};


//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
int main(){
    ll a,b,x; cin >> a >> b >> x;
  	if(a == 0) cout << b / x + 1 << endl;
    else cout << b / x - (a-1) / x << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef pair<ll, ll> pll;
#define mod 1000000007
#define all(x) (x).begin(), (x).end()
#define call(x) (x).cbegin(), (x).cend()
#define pb push_back
const double PI = acos(-1);
const long long INF = (1LL << 60);
ll gcd(ll a,ll b){return b ? gcd(b,a%b) : a;}
ll lcm(ll a,ll b){return a / gcd(a,b) * b;}
ll stringcount(string s, char c){return count(s.cbegin(), s.cend(), c);}
bool isInteger(double x){return floor(x) == x;}
ll ceil(const ll a, const ll b){return ((a)+(b)-1)/b;}

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

  ll s, w;
  cin >> s >> w;
  if(w >= s) cout << "unsafe" << endl;
  else cout << "safe" << endl;
  return 0;
}

Measured memory_bytes: 3608
X, Y = map(int, input().split())
P = 10 ** 9 + 7
N = (X+Y) // 3
R = (2 * X - Y) // 3
fact = [1, 1]
factinv = [1, 1]
inv = [0, 1]

for i in range(2, N+1):
    fact.append((fact[-1] * i) % P)
    inv.append((-inv[P % i] * (P//i) % P))
    factinv.append((factinv[-1] * inv[-1] % P))


def cmb_mod(n, r, p):
    if (r < 0) or (n < r):
        return 0
    r = min(r, n-r)
    return fact[n] * factinv[r] * factinv[n-r] % p


if (X+Y) % 3 != 0:
    print(0)
else:
    print(cmb_mod(N, R, P))


Measured memory_bytes: 211284
// abca29c.cpp : Typical Stairs
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007

int calc(vector<int> &v, int i, int n){
	if(i>n) return 0;
	if(i==n) return 1;
	if(v[i]==-2) return 0;
	if(v[i]==-1) v[i] = (calc(v,i+1,n) + calc(v,i+2,n)) % MOD;
	return v[i];
}

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

	vector<int> v(n+1,-1);
	v[n] = 1;
	for(int i=0;i<m;i++){
		int a; cin>>a;
		v[a] = -2;
	}

	int ans = calc(v,0,n);

	cout<< ans <<endl;
}

Measured memory_bytes: 6912
#include <iostream>
#include <cstdio>
#define N 505
using namespace std;

int h, w, c, a[N][N];
bool v[N][N];
int main()
{
	int i, j, t;
	cin >> h >> w;
	for (i = 0; i < h; i++) {
		for (j = 0; j < w; j++) {
			scanf("%d", &t);
			a[i][j] += t;
			if (a[i][j] % 2) {
				if (i == h - 1 && j == w - 1) continue;
				c++;
				a[i][j]--;
				v[i][j] = 1;
				if (i < h - 1) a[i + 1][j]++;
				else if (j < w - 1) a[i][j + 1]++;
			}
		}
	}
	cout << c << endl;
	for (i = 0; i < h - 1; i++) for (j = 0; j < w; j++) if (v[i][j]) printf("%d %d %d %d\n", i + 1, j + 1, i + 2, j + 1);
	for (i = 0; i < w - 1; i++) if (v[h - 1][i]) printf("%d %d %d %d\n", h, i + 1, h, i + 2);
    return 0;
}

Measured memory_bytes: 3328
/*ex4_3
  TKC001*/

#include<stdio.h>
//プロトタイプ宣言
int snow(int west, int east);

int main(void){
     /*west:a
       east:b*/
    int west, east;

    //入力
    scanf("%d%d", &west, &east);

    //出力
    printf("%d", snow(west, east));

    return 0;
}

//関数の定義
int snow(int west, int east){
     /*diff:b-a,eastの塔が西から何番目か
east_height:東側の塔の高さ
       snow:積雪*/
    int diff, east_height;

    diff = east - west;
    east_height = diff*(diff+1) / 2;

    return east_height - east;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#include <ext/rope>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#define int long long
#define pb push_back
#define x first
#define y second
#define mk(a,b) make_pair(a,b)
#define rr return 0
#define sqr(a) ((a)*(a))
#define all(a) (a).begin(), (a).end()
#define sz(a) (int)(a).size()

using namespace std;
using namespace __gnu_cxx;
using namespace __gnu_pbds;

using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

template<class value, class cmp = less<value> >
using ordered_set = tree<value, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>;
template<class value, class cmp = less_equal<value> >
using ordered_multiset = tree<value, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>;
template<class key, class value, class cmp = less<key> >
using ordered_map = tree<key, value, cmp, rb_tree_tag, tree_order_statistics_node_update>;

/// find_by_order()
/// order_of_key()
mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
inline int randll(int l = INT_MIN, int r = INT_MAX) {
    return uniform_int_distribution<int>(l, r)(rng);
}
const int INF = 1e9, MOD = 1e9 + 7; /// think
const ll LINF = 1e18;


const int dx[] = {0, 0, 1, -1}, dy[] = {1, -1, 0, 0};
inline bool inside (int x, int y, int n, int m) {
    return 0 <= x && 0 <= y && x < n && y < m;
}

template<class T> bool umin (T &a, T b) {return a > b ? (a = b, true) : false; }
template<class T> bool umax (T &a, T b) {return a < b ? (a = b, true) : false; }

const int N = 111;
ll dp[N][5][2] = {};

main()
{
    ios::sync_with_stdio(0);
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    string n;
    int k;
    cin >> n >> k;
    dp[0][0][0] = 1;
    for (int i = 0; i < sz(n); i++) {
        int num = n[sz(n) - i - 1] - '0';
        for (int t = 0; t < 4; t++) {
            for (int t1 = 0; t1 < 2; t1++) {
               for (int cur = 0; cur < 10; cur++) {
                    bool k1 = t1;
                    if (cur > num) k1 = 1;
                    else if (cur < num) k1 = 0;
                    dp[i + 1][t + (cur != 0)][k1] += dp[i][t][t1];
               }
            }
        }
    }
//    int N = atoi(n.c_str()), ans = 0;
//    for (int i = 1; i <= N; i++) {
//        int cnt = 0;
//        for (auto c : to_string(i)) {
//            if (c != '0') {
//                ++cnt;
//            }
//        }
//        if (cnt == k) ++ans;
//    }
//    cout << ans << '\n';
    cout << dp[sz(n)][k][0] << '\n';
}


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

using namespace std;

typedef long long ll;
const int MOD = (int) 1e9 + 7;

int add(int a, int b) {
  a += b;
  if (a >= MOD) {
    return a - MOD;
  }
  if (a < 0) {
    return a + MOD;
  }
  return a;
}

int mul(int a, int b) {
  return a * (ll) b % MOD;
}

int pw(int a, int b) {
  int r = 1;
  while (b) {
    if (b & 1) {
      r = mul(r, a);
    }
    a = mul(a, a);
    b /= 2;
  }
  return r;
}

const int N = (int) 1e5 + 7;
int n, k;
vector <int> g[N];
int par[N];
int kids[N];

void build(int nod) {
  for (auto &nou : g[nod]) {
    if (nou != par[nod]) {
      par[nou] = nod;
      kids[nod]++;
      build(nou);
    }
  }
}

int a[N];
bool vis[N];

int ops;
int know[N];

/**int know(int x) {
  int res = (a[x] != -1);
  for (auto &it : g[x]) {
    ops++;
    res += (a[it] != -1);
  }
  cout << "calculated for " << x << "\n";
  return res;
}**/

void dfs_up(int nod) {
  vector <int> path;
  int i = nod;
  while (vis[i] == 0) {
    path.push_back(i);
    vis[i] = 1;
    i = par[i];
  }
  reverse(path.begin(), path.end());
  for (auto &nod : path) {
    int nou = par[nod];
    int cnt = know[nou];
    if (cnt > k) {
      cout << "0\n";
      exit(0);
    }
    a[nod] = k - cnt;
    for (auto &it : g[nod]) {
      know[it]++;
    }
    know[nod]++;
  }
}

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

  cin >> n >> k;
  for (int i = 1; i < n; i++) {
    int a, b;
    cin >> a >> b;
    g[a].push_back(b);
    g[b].push_back(a);
  }

  build(1);
  vis[0] = 1;
  for (int i = 1; i <= n; i++) {
    if (kids[i] == 0 && vis[i] == 0) {
      dfs_up(i);
    }
  }

  int res = 1;
  for (int i = 1; i <= n; i++) {
    res = mul(res, a[i]);
  }
  cout << res << "\n";

  return 0;
}


Measured memory_bytes: 11548
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <functional>
#include <vector>
#include <queue>
#include <deque>
#include <map>
#include <set>
#define nmax_def 110000
#define Cmax_def 2200
#define mod 1000000007
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
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;

void U() {
	cout << 'U';
}
void D() {
	cout << 'D';
}
void R() {
	cout << 'R';
}
void L() {
	cout << 'L';
}

int main() {
	int a, b, c, d;
	cin >> a >> b >> c >> d;
	int X = c - a;
	int Y = d - b;
	rep(i, X)
		R();
	rep(i, Y)
		U();
	rep(i, X)
		L();
	rep(i, Y)
		D();
	D();
	rep(i, X+1)
		R();
	rep(i, Y + 1)
		U();
	L();
	U();
	rep(i, X + 1)
		L();
	rep(i, Y + 1)
		D();
	R();
	cout << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
#define pi 3.14159265358979323846264338327950L
using namespace std;

int main() {
  int N, Y, x=-1, y=-1, z=-1;
  cin >> N >> Y;
  bool finished=false;
  for (int i=0; i<=Y/10000; i++) {
    for (int j=0; j<=Y/5000; j++) {
      if (9000*i+4000*j+1000*N==Y && N-i-j>=0) {
        x=i;
        y=j;
        z=N-i-j;
        finished=true;
        break;
      }
    }
    if (finished) {
      break;
    }
  }
  cout << x << " " << y << " " << z << endl;
}

Measured memory_bytes: 3568
#include <stdio.h>

int main(){
	int r, c;
	int data[101][101];
	int i,t;
	scanf("%d %d", &r, &c);
	for(i = 0;i < r; i++){
		data[i][c] = 0;
		for(t = 0;t < c; t++){
			scanf("%d", &data[i][t]);
			data[i][c] += data[i][t];
		}
	}
	for(t = 0;t <= c;t++){
		data[r][t] = 0;
		for(i = 0;i < r; i++){
			data[r][t] += data[i][t];
		}
	}
	for(i = 0;i <= r; i++){
		for(t = 0;t <= c; t++){
			printf("%d", data[i][t]);
			if(t==c)puts("");
			else printf(" ");
		}
	}

	return 0;
}

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

int main(){
  int R;
  cin >> R;
  if(R<1200){
    cout << "ABC" << endl;
    return 0;
  }
  if(R<2800){
    cout << "ARC" << endl;
    return 0;
  }
  cout << "AGC" << endl;
  return 0;
}

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

int A[2097152], V[2097152];
int num, head;

void init(int n) {
    num = 1;
    while (num < n) num *= 2;
    head = num - 1;
    num *= 2;
    int l = head + n;
    for (int i=0; i<=l; ++i) {
        A[i] = (i < head ? 1 : i - head);
        V[i] = 0;
    }
    for (int i=l+1; i<num; ++i) {
        A[i] = INT_MAX;
        V[i] = -INT_MAX;
    }
}

void update(int a, int v) {
    int k = head + a;
    V[k] += v;
    while (k) {
        k = (k - 1) / 2;
        int l = 2*k+1, r = 2*k+2;
        if (V[l] < V[r] || (V[l] == V[r] && A[l] > A[r])) {
            V[k] = V[r];
            A[k] = A[r];
        } else {
            V[k] = V[l];
            A[k] = A[l];
        }
    }
}

int main() {
    ios::sync_with_stdio(false);
    int n, q;
    cin >> n >> q;
    init(n);
    int a, v;
    for (int i=0; i<q; ++i) {
        cin >> a >> v;
        update(a, v);
        cout << A[0] << " " << V[0] << endl;
    }
    return 0;
}

Measured memory_bytes: 17580
#include <bits/stdc++.h>
#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 INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
int main()
{
 int a,b,c;
 cin>>a>>b;
 c = a+b;
 if(c == 3)
  { cout<< 3 <<endl;}
 else if (c == 4){
  cout<< 2 << endl;}
 else if (c == 5){
 cout << 1 << endl;}   


}

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

using namespace std;

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

template <typename T>
void printv(const vector<T> &v)
{
    int sz = v.size();
    for (int i = 0; i < sz; i++)
    {
        cout << v[i] << " \n"[i == sz - 1];
    }
}

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

    int n;
    cin >> n;
    vector<P> ret;
    int sum;
    if (n % 2)
        sum = n;
    else
        sum = n + 1;
    for (int i = 1; i <= n; i++)
    {
        for (int j = i + 1; j <= n; j++)
        {
            if (i + j != sum)
                ret.push_back(P(i, j));
        }
    }
    cout << ret.size() << endl;
    for (auto p : ret)
    {
        cout << p.first << " " << p.second << endl;
    }
}


Measured memory_bytes: 384
#include <set>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
typedef long long ll ;
#define rep(i, a, b) for (int i = a; i <= b; ++ i)
const int N = 100005 ;
using namespace std ;

set <pair <ll, ll> > S ;
int n, m ; 
ll a[N], f[N] ;

void add(ll x, ll y) {
	std :: set <pair <ll, ll> > :: iterator it = S.lower_bound(make_pair(x, 0)) ;
	if (it == S.end() || (*it).first != x) S.insert(make_pair(x, y)) ; else {
		S.insert(make_pair(x, y + (*it).second)) ;
		S.erase(it) ;
	}
}

int main() {
	scanf("%d%d", &n, &m), ++ m ;
	rep(i, 2, m) {
		scanf("%lld", &a[i]) ;
	}
	a[1] = n ;
	S.insert(make_pair(a[m], 1)) ;
	ll las = a[m] ;
	for (int i = m - 1; i >= 1; -- i) if (a[i] < las) {
		std :: set <pair <ll, ll> > :: iterator it ;
		for ( ; ; ) {
			it = S.lower_bound(make_pair(a[i] + 1, 0)) ;
			if (it == S.end()) break ;
			ll u = (*it).first, v = (*it).second ;
			S.erase(it) ;
			if (u / a[i]) add(a[i], u / a[i] * v) ;
			if (u % a[i]) add(u % a[i], v) ;
		}
		las = a[i] ;
	}
	std :: set <pair <ll, ll> > :: iterator it = S.begin() ;
	for ( ; it != S.end() ; ++ it) f[(*it).first] += (*it).second ;
	for (int i = n - 1; i >= 1; -- i) f[i] += f[i + 1] ;
	rep(i, 1, n) printf("%lld\n", f[i]) ;
	return 0 ; 
}

Measured memory_bytes: 9344
#include <bits/stdc++.h>
#include <algorithm>
#include <math.h>
#include <cstring>

#define test(t) while(t--)
#define fo(i,k,n) for(int i=k;i<n;i++)
#define refl(a,x) for(auto& a:x)
#define MIN(a,b)  (a>b?b:a)
#define ll  long long int
#define MOD 1e9 + 7
#define in  cin>>
#define out cout<<
#define en "\n"
#define sp " "
#define fi first
#define se second
#define fast()  ios_base::sync_with_stdio(false);cin.tie(0);
#define pb push_back
#define lb lower_bound
#define ub upper_bound
//typedef pair<int,int> pai;
//typedef pair<char,int> pac;



/*bool f(int x,int y){

return x>y;
}*/


using namespace std;


void solve()
{ string s;
    in s;
    ll flag=0;
    for(ll i=0;i<s.length();i++){
        if(s[i]=='7'){
         flag=1;
         break;
        }
    }
    if(flag==1)
        out "Yes"<<en;
    else
        out "No"<<en;
}


int main(){ fast()
             //freopen("input.txt","r",stdin);
	         //freopen("output.txt","w",stdout);
             ll t=1;
            //cin>>t;
            test(t){
            solve();
            }

return 0;}


Measured memory_bytes: 3640
#pragma GCC optimize("O3")
//#pragma GCC target("avx2")
//#pragma GCC optimize("unroll-loops")

#include <bits/stdc++.h>

using namespace std;

#ifdef LOCAL
#include <prettyprint.hpp>
#define debug(...)  cerr << "[" << #__VA_ARGS__ << "]: ", d_err(__VA_ARGS__);
#else
#define debug(...) 83;
#endif

void d_err() {
    cerr << endl;
}

template <typename H, typename... T>
void d_err(H h, T... t) {
    cerr << h << " ";
    d_err(t...);
}

template <typename T>
void print(T x) {
    cout << x << "\n";
}

#define ALL(x) (x).begin(), (x).end()
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define REVFOR(i, m, n) for (int i = (n - 1); i >= (m); --i)
#define REP(i, n) FOR(i, 0, n)
#define REVREP(i, n) REVFOR(i, 0, n)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define bcnt __builtin_popcountll

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<ll,ll> Pll;
typedef pair<int,int> Pin;

ll INF = 1e16;
int inf = 1e9;
ll MOD = 1e9+7;

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

    int n;
    cin >> n;

    vector<vi> A(2, vi(n));

    REP(i, 2) REP(j, n) cin >> A[i][j];

    int s = 0;
    REP(i, n) s += A[1][i];

    ll ans = 0, s1 = 0;
    REP(i, n) {
        s1 += A[0][i];
        ll tmp = s + s1;
        ans = max(ans, tmp);
        s -= A[1][i];
    }

    print(ans);
}

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

long int a[10001];

int main(){

  for(long int i=2;i*i<10001;i++){
    if( !a[i] ){
      for(long int j=i+i;j<10001;j+=i) a[j] = 1;
    }
  }

  a[0] = a[1] = 1;

  long int n;

  while(cin >> n, n){

    for(long int i=n;i>4;i--){
      if(a[i] == 0 && a[i-2] == 0){
	cout << i-2 << " " << i << endl;
	break;
      }
    }

  }

}

Measured memory_bytes: 1244
coins = (10,50,100,500)
isfirst = True
while 1:
    cost = int(raw_input())
    if cost == 0: break
    if not isfirst: print
    have = map(int,raw_input().split())

    budget = sum(i*j for i,j in zip(coins,have))
    change = budget-cost

    ret = [0]*4
    for i in reversed(range(4)):
        c = change/coins[i]
        ret[i] = c
        change -= c*coins[i]

    for i in range(4):
        if have[i]-ret[i] <= 0: continue
        print coins[i],have[i]-ret[i]

    isfirst = False

Measured memory_bytes: 4236
s = input()
last = int(s[0])
count = 0

for c in s[1:]:
	c = int(c)
	if(last == c):
		count += 1
		last = (c+1)%2
	else:
		last = c

s = s[::-1]
last = int(s[0])
count2 = 0

for c in s[1:]:
	c = int(c)
	if(last == c):
		count2 += 1
		last = (c+1)%2
	else:
		last = c


print(min(count,count2))

Measured memory_bytes: 3188
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<deque>
#include<stack>
#include<set>
#include<map>
#include<bitset>
#include<string>
#define MOD 1000000007
#define enld endl
typedef long long ll;
using namespace std;

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    int N,K; cin >> N >> K;
    int p[1005];
    for(int i=0;i<N;i++) cin >> p[i];
    sort(p,p+N);
    int ans  = 0;
    for(int i=0;i<K;i++) ans += p[i];
    cout << ans << enld;
    return 0;
}

Measured memory_bytes: 3616
#include"bits/stdc++.h"
#include <ext/pb_ds/assoc_container.hpp> 
using namespace __gnu_pbds; 
using namespace std;

#define double long double
#define int long long
#define pb push_back 
#define Z(c) (int)(c).size()
#define L(c) c[Z(c)-1]
#define F first
#define S second
#define nl "\n"
#define mii map<int,int> 
#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()
#define rep(i,iv,n) for(int (i)=(iv);(i)<(n);++(i))
#define FO fflush(stdout) 
#define D1(x) cerr <<"At line "<<__LINE__<<" "<<#x<<"="<<x<<nl
#define D2(x,y) cerr <<"At line "<<__LINE__<<" "<<#x<<"="<<x<<" "<<#y<<"="<<y<<nl
#define D3(x,y,z) cerr <<"At line "<<__LINE__<<" "<<#x<<"="<<x<<" "<<#y<<"="<<y<<" "<<#z<<"="<<z<<nl
#define tr(it,ct) for(auto &(it) : (ct))
#define pi acos(-1)
#define prt(ct) for(auto &(it) : (ct)) cerr<<it<<" "; cerr<<nl
#define prtp(ct) for(auto &(it) : (ct)) cerr<<it.F<<" "<<it.S<<nl; cerr<<nl

typedef vector< int > vi;
typedef vector< vi > vvi;
typedef pair< int,int > pii;
typedef vector< pii > vp;
typedef tree<int, null_type, less<int>, rb_tree_tag, 
             tree_order_statistics_node_update> baap;

void swap(char &a,char &b)
{ auto tm=a; a=b; b=tm; }
                                   
 
  const int mod=1000000007;
  const int mod2=998244353;
  const int INF=1e16+18;
  const int N=2e5+25;
  const int M=2e4;
  
 
 void fft()           
 { 
   int x; cin>>x;
   int ans=x/500; ans*=1000;
   x=x%500; x=x/5;
   ans+=x*5;
   cout<<ans;
 }

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

   
   
   int tc=1;                         
 //  cin>>tc;

  rep(i,1,tc+1)
  { // cout<<"Case #"<<i<<": ";
   fft();
   if(i<tc)
   cout<<nl;
  }
  
 
 return 0; 
}

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

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

const int N = 1e5 + 15;
int n, l[N], r[N];

inline void process(int lo, int hi, int &cur, ll &ans){
	if(cur < lo){
		ans += lo - cur;
		cur = lo;
	}else if(cur > hi){
		ans += cur - hi;
		cur = hi;
	}
}

inline void rem(map<pair<int, int>, int> &mp, pair<int, int> x){
	mp[x]--; if(!mp[x])mp.erase(x);
}

ll compute(int flg){
	map<pair<int, int>, int> ml, mr;
	for(int i = 0; i < n; i++){
		ml[{l[i], r[i]}]++;
		mr[{r[i], l[i]}]++;
	}
	ll ans = 0;
	int cur = 0;
	for(int i = 0; i < n; i++){
		if(flg){
			int lo = (mr.begin()->first).second;
			int hi = (mr.begin()->first).first;
			rem(mr, {hi, lo});
			rem(ml, {lo, hi});
			process(lo, hi, cur, ans);
		}else{
			int lo = (ml.rbegin()->first).first;
			int hi = (ml.rbegin()->first).second;
			rem(mr, {hi, lo});
			rem(ml, {lo, hi});
			process(lo, hi, cur, ans);
		}
		// cout<<i<<" "<<ml.size()<<" "<<mr.size()<<endl;
		flg ^= 1;
	}
	ans += abs(cur);
	return ans;
}

int main(){
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout<<setprecision(32);

	cin>>n;
	for(int i = 0; i < n; i++){
		cin>>l[i]>>r[i];
	}
	cout<<max(compute(0), compute(1))<<endl;

	return 0;
}

Measured memory_bytes: 16908
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		//StringBuilder s = new StringBuilder();
		String[] s = new String[n];
		int[] countS = new int[n]; //かぶった回数
		for (int i = 0; i < n; i++) {
			String tempS = scan.next();
			if (Arrays.asList(s).contains(tempS)) {
				s[i] = tempS;
				countS[i]++;
			} else {
				s[i] = tempS;
				countS[i]=0;
			}
		}
		//countS[i]内で最大のもののi＝forのi回目で入力したモノ
		int m = scan.nextInt();
		String[] t = new String[m];
		int[] countT = new int[m]; //かぶった回数
		for (int i = 0; i < m; i++) {
			String tempT = scan.next();
			if (Arrays.asList(t).contains(tempT)) {
				t[i] = tempT;
				countT[i]++;
			} else {
				t[i] = tempT;
				countT[i]=0;
			}
		}
		List<String> listS = Arrays.asList(s);
		List<String> listT = Arrays.asList(t);
		//System.out.println(listS);
		//System.out.println(listT);

		int plus[] =new int[n];
		int minus[] = new int[m];
		for(int i=0;i<listS.size();i++) {
			List<String>zanteiS = new ArrayList<>(listS);
			List<String>deleteS = new ArrayList<>();
			deleteS.add(listS.get(i));
			zanteiS.removeAll(deleteS);
			plus[i]=listS.size()-zanteiS.size();
		//	System.out.println(plus[i]);
		}

		for(int i=0;i<listT.size();i++) {
			List<String>zanteiT = new ArrayList<>(listT);
			List<String>deleteT = new ArrayList<>();
			deleteT.add(listT.get(i));
			zanteiT.removeAll(deleteT);
			minus[i]=listT.size()-zanteiT.size();
			//System.out.println(minus[i]);
		}

		int[] count = new int[listS.size()];
		for(int i=0;i<listS.size();i++) {
			count[i] = plus[i];

			for(int l=0;l<listT.size();l++) {
				if(listT.get(l).equals(listS.get(i))) {
					count[i] --;
				}
			}
//System.out.println("count"+count[i]);
		}
int ans =0;
		for(int i=0;i<count.length;i++) {
			ans = Math.max(count[i], ans);
		}
		System.out.println(ans);
		/*
		//plus内の最大値は
		int plusMax =0;
		for(int i=0;i<plus.length;i++) {
			plusMax=Math.max(plusMax, plus[i]);
		}
System.out.println(plusMax);

int minusMin =0;
for(int i=0;i<minus.length;i++) {
	minusMin=Math.min(minusMin, minus[i]);
}
System.out.println(minusMin);

*/

	}

}


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

int main(void) {
  ll N, M, A, B, C;
  cin >> N >> M >> A >> B >> C;
  vector<vector<ll>> E(N);
  REP(i, 0, M) {
    ll U, V;
    cin >> U >> V, U--, V--;
    E[V].push_back(U);
  }

  vector<bool> s(N);
  s[N - 1] = true;

  for (ll ans = 1;; ans++) {
    vector<vector<bool>> dp(101, vector<bool>(N));
    REP(v, 0, N) dp[0][v] = s[v];

    REP(k, 0, 100) {
      REP(v, 0, N) {
        if (dp[k][v]) {
          REP(i, 0, E[v].size()) {
            ll u = E[v][i];
            dp[k + 1][u] = true;
          }
        }
      }
    }

    bool br = true;
    REP(v, 0, N) {
      if (!s[v] && dp[A][v] && dp[B][v] && dp[C][v]) {
        s[v] = true;
        br = false;
        if (v == 0) {
          cout << ans << endl;
          return 0;
        }
      }
    }
    if (br) break;
  }

  cout << "IMPOSSIBLE" << endl;
}


Measured memory_bytes: 3184
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<vector>
#include<queue>
#include<stack>
#include<cmath>
using namespace std;
int main(){
int n,m,t=0;
cin>>n>>m;
t=1;
for(int i=1;i<=n;i++){
	if(t*2>=t+m){
	   t+=m;
	}
	else t*=2;
}
cout<<t;
    return 0;
}


Measured memory_bytes: 256
n, m = map(int, input().split())
dat_d = []
for i in range(n):
    a,b = map(int, input().split())
    dat_d.append((a, b))
dat_d.sort(key=lambda x: x[0])
total = 0
for i in range(m):
    if dat_d[i][1] >= m:
        #print("buy {0} sum {1}-hon".format(dat_d[i][0], m))
        total += dat_d[i][0] * m
        break
    else:
        #print("buy {0} sum {1}-hon".format(dat_d[i][0], dat_d[i][1]))
        total += dat_d[i][1] * dat_d[i][0]
        m -= dat_d[i][1]

print(total)


Measured memory_bytes: 18180
inf = 10**9
n, a, b, c = map(int, input().split())
l = [int(input()) for _ in range(n)]

def dfs(i, a_cur, b_cur, c_cur):
    if i == n:
        return abs(a_cur-a) + abs(b_cur-b) + abs(c_cur-c) - 30 if min(a_cur, b_cur, c_cur) > 0 else inf
    ans0 = dfs(i+1, a_cur+l[i], b_cur, c_cur) + 10
    ans1 = dfs(i+1, a_cur, b_cur+l[i], c_cur) + 10
    ans2 = dfs(i+1, a_cur, b_cur, c_cur+l[i]) + 10
    ans3 = dfs(i+1, a_cur, b_cur, c_cur)
    return min(ans0, ans1, ans2, ans3)

print(dfs(0, 0, 0, 0))

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define pb push_back
#define ff first
#define ss second
using namespace std;
using ll = long long;
using vi = vector<int>;
using pii = pair<int, int>;
const int INF = 0x3f3f3f3f;
int main() {
  ll a, b, k;
  cin >> a >> b >> k;
  k = min(a + b, k);
  ll ans1, ans2;
  ans1 = min(k, a);
  k -= ans1;
  ans2 = min(k, b);
  cout << a - ans1 << ' ' << b - ans2 << endl;
}

Measured memory_bytes: 256
n = int(input())
point = 0
def sitigosan(num,keta):
    global point
    now = keta+num
    if int(now) > n:
        return
    else:
        if "3" in now and "5" in now and "7" in now:
            point += 1
        return sitigosan("3",str(now)),sitigosan("5",str(now)),sitigosan("7",str(now))
sitigosan("","3")
sitigosan("","5")
sitigosan("","7")

print(point)

Measured memory_bytes: 3700
package main

import (
	"fmt"
	"strings"
)

func main() {
	var h, w int

	for {
		fmt.Scan(&h, &w)
		if h == 0 && w == 0 {
			break
		}
		for i := 0; i < h; i++ {
			fmt.Println(strings.Repeat("#", w))
		}
		fmt.Println()
	}
}



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

using namespace std;

char u[55][111];
char d[55][111];

void solve() {
    int a,b;
    cin >> a >> b;
    memset(u, '#', sizeof u);
    memset(d, '.', sizeof d);
    auto nex = [](int& i, int& j){
        if (j < 99) j += 2;
        else {i+=2; j = 1;}
    };
    int i = 1, j = 1;
    a--;
    while (a--) {
        u[i][j] = '.';
        nex(i,j);
    }
    b--;
    i = 2, j = 1;
    while (b--) {
        d[i][j] = '#';
        nex(i,j);
    }
    cout << "100 100\n";
    for (int i = 1; i <= 50; i++) {
        for (int j = 1; j <= 100; j++) {
            cout << u[i][j];
        }cout<<"\n";
    }
    for (int i = 1; i <= 50; i++) {
        for (int j = 1; j <= 100; j++) {
            cout << d[i][j];
        }cout<<"\n";
    }
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    solve();
    cout << endl;
}


Measured memory_bytes: 384
import java.util.Scanner;
public class Main{
 public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int[] a = {0,0,0};
    int i,t,j;
    for ( i = 0; i < 3; i++) {
       a[i] = sc.nextInt();
    }

    for ( i = 0; i < 3; i++) {
       for ( j = i+1; j < 3; j++) {
          if(a[i]>a[j]){
             t = a[i];
             a[i] = a[j];
             a[j] = t;
          }
       }
    }

    System.out.println(a[0]+" "+a[1]+" "+a[2]);

    

  }
}



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

using VS = vector<string>;    using LL = long long;
using VI = vector<int>;       using VVI = vector<VI>;
using PII = pair<int, int>;   using PLL = pair<LL, LL>;
using VL = vector<LL>;        using VVL = vector<VL>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)--)
#define debug(x) cerr << #x << ": " << x << endl
const int INF = 1e9;                          const LL LINF = 1e16;
const LL MOD = 1000000007;                    const double PI = acos(-1.0);
int DX[8] = { 0, 0, 1, -1, 1, 1, -1, -1 };    int DY[8] = { 1, -1, 0, 0, 1, -1, 1, -1 };

/* -----  2018/03/05  Problem: 086_arc_b / Link: https://arc086.contest.atcoder.jp/tasks/arc086_b?lang=en  ----- */
/* ------問題------

すぬけ君は長さ N の数列 a を持っています。a の (1-indexedでの) i 番目の数は ai です。
すぬけ君は以下の操作を何度でも行うことができます。
操作：1 以上 N 以下の整数 x,y を選び、ay に ax を加算する。
すぬけ君はこの操作を 0 回以上 2N 回以下行って a が下記の条件を満たすようにしたいです。そのような操作手順の一例を示してください。 なお、この問題の制約下で、条件を満たすような操作の手順が必ず存在することが証明できます。

条件：a1≤a2≤…≤aN

-----問題ここまで----- */
/* -----解説等-----

N-1回で符号を全部おなじになるように整地する。
その後N-1回で累積和を取れば良い

----解説ここまで---- */

LL N;

LL ans = 0LL;

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

	cin >> N;
	VL a(N);
	FOR(i, 0, N) {
		cin >> a[i];
	}
	LL Min = LINF;
	LL Max = -LINF;
	FOR(i, 0, N) {
		Min = min(Min, a[i]);
		Max = max(Max, a[i]);
	}
	cout << 2 * N - 1 << endl;
	if (abs(Max) > abs(Min)) {
		int pos; // 全部正
		FOR(i, 0, N) {
			if (Max == a[i])pos = i;
		}
		FOR(i, 0, N) {
			cout << pos + 1 << " " << i + 1 << endl;
		}
		FOR(i, 0, N - 1) {
			cout << i + 1 << " " << i + 2 << endl;
		}
	}
	else { //全部負
		int pos;
		FOR(i, 0, N) {
			if (Min == a[i])pos = i;
		}
		FOR(i, 0, N) {
			cout << pos + 1 << " " << i + 1 << endl;
		}
		FORR(i, N - 2, 0 - 1) {
			cout << i + 2 << " " << i + 1 << endl;
		}
	}

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <map>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <set>
#include <vector>
#include <queue>
#include <list>
#include <numeric>

using namespace std;
typedef long long ll;

int gcd(int x, int y) {
  if (x < y) swap(x, y);
  while (y > 0) {
    int r = x % y;
    x = y;
    y = r;
  }
  return x;
}

/*迷路
const int INF = 50;

typedef pair<int,int> P;
char field[52][52];
int d[51][51];
int r,c;
int sx,sy;
int gx,gy;

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

int bfs(){
    queue<P> que;
    for(int i=0;i<r;i++){
        for(int j=0;j<c;j++){
            d[i+1][j+1] = INF;
        }
    }
    que.push(P(sy,sx));
    d[sy][sx]=0;
while(que.size()){
    P p=que.front();
    que.pop();
    if(p.second==gx&&p.first==gy) break;
    for(int i=0;i<4;i++){
        int nx=p.second+dx[i];
        int ny=p.first+dy[i];

        if(1<=nx&&nx<=c&&1<=ny&&ny<=r&&field[ny][nx]!='#'&&d[ny][nx]==INF){
            que.push(P(ny,nx));
            d[ny][nx] = d[p.first][p.second] + 1;
        }
    }
}
return d[gy][gx];
}
*/

int main(){
    int a,b,c;
    cin>>a>>b>>c;
    cout<<min(b/a,c)<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main()
{
      int D;
      scanf("%d",&D);
      if(D==25)
            printf("Christmas\n");
      else if(D==24)
            printf("Christmas Eve\n");
      else if(D==23)
            printf("Christmas Eve Eve\n");
      else if(D==22)
            printf("Christmas Eve Eve Eve\n");
      return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
 
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
 
using namespace __gnu_pbds;
using namespace std;
 
#define count1 __builtin_popcount
#define int long long
#define pb push_back
#define pii pair<int,int>
#define fr(i,n) for(int i=0;i<n;i++)
#define F first
#define S second
#define ccM 1000000007
#define fastio ios_base::sync_with_stdio(false);cin.tie(0)
long double pi = 3.14159265358979323;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
int max(int b,int a){if(b>a)return b;else return a;}
int min(int b,int a){if(b<a)return b;else return a;}
int Abs(int b){return max(b,-b);}
bool sortbysec(const pair<int,int> &a, const pair<int,int> &b){return a.second<b.second;}

int32_t main()
{
	int n;
	cin>>n;
	int s=0;
	int p=1;
	while(p<=n)
	{
		s+=p;
		p*=2;
	}
	s+=p;
	p--;
	cout<<p<<endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <iostream>
#include <queue>
#include <stdio.h>
#include <string>
#include <vector>

#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const double PI = 3.1415926535897932;

/* a と b の最大公約数を返す関数 */
long long GCD(long long a, long long b) {
	if (b == 0) return a;
	else return GCD(b, a % b);
}


int main()
{
	ll n, a, b;
	cin >> n >> a >> b;
	ll r1, r2;

	r1 = n / (a + b) *a;
	r2 = min(n % (a + b), a);

	cout << r1 + r2 << endl;

	return 0;
}

Measured memory_bytes: 3592
#include <algorithm>
#include <cassert>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;

#define rep(i, n) for(ll i = 0; i < n; i++)
#define REP(i, n) for(ll i = 1; i < n + 1; i++)
//cout << std::fixed << std::setprecision(15) << y << endl;


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

    ll A[N];
    ll rainSum = 0;
    rep(i, N){
        cin >> A[i];
        rainSum += A[i];
    }

    ll ans[N];
    ll sum;
    sum = A[0] + A[N - 1];
    for(ll i = 2; i < N - 1; i += 2){
        sum += A[i];
    }
    ans[0] = sum * 2 - rainSum;//cout << "sum: " << sum * 2 << ", rainSum: " << rainSum << endl;
    for(ll i = N - 1; i > 0; i--){
        ans[i] = (A[i] - ans[(i + 1) % N] / 2) * 2;
    }

    rep(i, N){
        if(i != 0){
            cout << " ";
        }
        cout << ans[i];
    }
    cout << endl;

    return 0;
}

Measured memory_bytes: 5168
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
const int N = 2e5 + 5; 
using namespace std; 

int n, fa[N], head[N], cnte, vis[N], cir[N], mex[N];
struct edge { int to, nxt; } e[N << 1]; 

template < typename T >
inline T read()
{
	T x = 0, w = 1; char c = getchar();
	while(c < '0' || c > '9') { if(c == '-') w = -1; c = getchar(); }
	while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
	return x * w; 
}

inline void adde(int u, int v) { e[++cnte] = (edge) { v, head[u] }, head[u] = cnte; }

void dfs(int u)
{
	for(int i = head[u]; i; i = e[i].nxt)
		if(!cir[e[i].to]) dfs(e[i].to);
	for(int i = head[u]; i; i = e[i].nxt)
		if(!cir[e[i].to]) vis[mex[e[i].to]] = 1;
	int x = 0;
	while(vis[x]) x++;
	mex[u] = x;
	for(int i = head[u]; i; i = e[i].nxt)
		if(!cir[e[i].to]) vis[mex[e[i].to]] = 0; 
}

int main()
{
#ifndef ONLINE_JUDGE
	freopen("cpp.in", "r", stdin); 
#endif
	n = read <int> ();
	for(int i = 1; i <= n; i++) fa[i] = read <int> (), adde(fa[i], i);
	int u = 1;
	while(!vis[u]) vis[u] = 1, u = fa[u];
	for(int i = 0; i <= n; i++) vis[i] = 0; 
	while(!cir[u]) cir[u] = 1, u = fa[u];
	int mn = n + 1, mx = 0, cnt = 0;
	for(int i = 1; i <= n; i++)
	{
		if(!cir[i]) continue;
		dfs(i), cnt++;
		mx = max(mx, mex[i]), mn = min(mn, mex[i]); 
	}
	puts((mx == mn) && (cnt & 1) ? "IMPOSSIBLE" : "POSSIBLE"); 
	return 0; 
}


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

#define ll long long
#define ii pair<int, int>
#define vi vector<int>
#define vl vector<ll>
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#define ff first
#define ss second
#define pi 3.14159265
#define oo 1000000007
#define loo 10000000000000007

#define prime 1000000007

#define W(x) cerr << "\033[31m" << #x << " = " << x << "\033[0m" << "\n";
using namespace std;

int mat[4][4], v[3] = {0, 1, 2}, w[3] = {0, 1, 2};

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    for (int i = 0; i < 3; ++i){
        for (int j = 0; j < 3; ++j){
            cin >> mat[i][j];
        }
    }

    do{
        int s = mat[v[0]][w[0]]+mat[v[1]][w[1]]+mat[v[2]][w[2]];
        do{
            if(s != mat[v[0]][w[0]]+mat[v[1]][w[1]]+mat[v[2]][w[2]]){
                cout << "No\n";
                return 0;
            }
        }while(next_permutation(v, v+3));
        v[0] = 0, v[1] = 1, v[2] = 2;
    }while(next_permutation(w, w+3));
    
    cout << "Yes\n";

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<queue>
using namespace std;

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

#define pb push_back
#define fr first
#define sc second

int N;
int p[200010];
int d[200010];
int cnt[200010];
int grundy[200010];
vector<int> to[200010];

void dfs(int v){
	///cout << "dfs(" << v << ") = ";
	if(cnt[v] != d[v]){
		//cout << cnt[v] << " " << d[v] << endl;
		return;
	}
	sort(to[v].begin(),to[v].end());
	to[v].erase(unique(to[v].begin(),to[v].end()),to[v].end());
	grundy[v] = -1;
	for(int i = 0 ; i < to[v].size() ; i ++){
		if(to[v][i] != i){
			grundy[v] = i;
			break;
		}
	}
	if(grundy[v] == -1)grundy[v] = to[v].size();
	to[p[v]].pb(grundy[v]);
	cnt[p[v]] ++;
	//cout << grundy[v] << endl;
	dfs(p[v]);
}

int main(){
	scanf("%d",&N);
	for(int i = 1 ; i <= N ; i ++){
		scanf("%d",&p[i]);
	}
	
	for(int i = 1 ; i <= N ; i ++){
		d[p[i]] ++;
	}
	for(int i = 1 ; i <= N ; i ++){
		if(d[i] == 0){
			dfs(i);
		}
	}
	
	static int cnt_[200010];
	static int grundy_[200010];
	static vector<int> to_[200010];
	for(int i = 1 ; i <= N ; i ++){
		cnt_[i] = cnt[i];
		grundy_[i] = grundy[i];
		to_[i] = to[i];
	}
	
	for(int i = 1 ; i <= N ; i ++){
		if(d[i] != cnt[i]){
			int v = p[i];
			swap(i,v);
			
			int memo = 0;
			sort(to[i].begin(),to[i].end());
			to[i].erase(unique(to[i].begin(),to[i].end()),to[i].end());
			for(int j = 0 ; j <= to[i].size() ; j ++){
				if(j == to[i].size() || to[i][j] != j){
					memo = j;
					to[i].pb(j);
					break;
				}
			}
			//cout << cnt[3] << endl;
			cnt[i] ++;
			dfs(i);
			
			/*cout << i << " " << v <<  endl;
			for(int j = 1 ; j <= N ; j ++){
				printf("%d ",grundy[j]);
			}cout << endl;*/
			
			/*int gr = 0;
			sort(to[i].begin(),to[i].end());
			to[i].erase(unique(to[i].begin(),to[i].end()),to[i].end());
			for(int j = 0 ; j <= to[i].size() ; j ++){
				if(j == to[i].size() || to[i][j] != j){
					gr = j;
					break;
				}
			}*/
			if(memo == grundy[v]){
				puts("POSSIBLE");
				return 0;
			}
			
			for(int j = 1 ; j <= N ; j ++){
				cnt[j] = cnt_[j];
				grundy[j] = grundy_[j];
				to[j] = to_[j];
			}
			cnt[i] ++;
			dfs(i);
			
			/*cout << i << " " << v <<  endl;
			for(int j = 1 ; j <= N ; j ++){
				printf("%d ",grundy[j]);
			}cout << endl;*/
			/*sort(to[i].begin(),to[i].end());
			to[i].erase(unique(to[i].begin(),to[i].end()),to[i].end());
			for(int j = 0 ; j <= to[i].size() ; j ++){
				if(j == to[i].size() || to[i][j] != j){
					gr = j;
					break;
				}
			}*/
			if(memo != grundy[v]){
				puts("POSSIBLE");
				return 0;
			}
			puts("IMPOSSIBLE");
			return 0;
		}
	}
}



Measured memory_bytes: 20480
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
const ll mod = (int) 1e9 + 7;
ll n;
double a[3005];
double dp[3005][3005];
double solve(ll coins, ll heads){
    if(heads == 0){
        return 1;
    }
    if(coins == 0){
        return 0;
    }
    if(dp[coins][heads] != -1){
        return dp[coins][heads];
    }
    return dp[coins][heads] = a[coins] * solve(coins-1, heads-1) + (1 - a[coins]) * solve(coins-1, heads);
}
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>a[i];
    }
    //memset(dp,-1.0,sizeof(dp));
    for(int i=0;i<=n;i++){
        for(int j=0;j<=n;j++){
            dp[i][j] = -1;
        }
    }
    cout<<fixed<<setprecision(10)<<solve(n,((n+1)/2))<<"\n";
}
    
    


Measured memory_bytes: 70912
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <string.h>
#include <limits.h>
#include <math.h>

#include <iostream>
#include <string>
#include <vector>
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstdio>

using namespace std;

const int INF = 1e+8;

typedef struct edge_def {
	int to;
	int cost;
	edge_def(int _to, int _cost) {to = _to; cost = _cost;}
} edge;

typedef pair<int, int> P;

int V, E;
const int MAX_V = 10;
vector<edge> G[MAX_V];	//[i] : fromを表す
int d[MAX_V];

void dijkstra(int s) {
	int i;
	priority_queue<P, vector<P>, greater<P> > q;

	for (i=0; i<V; i++) d[i] = INF;
	d[s] = 0;
	q.push(P(0, s));

	while (q.size()) {
		P p = q.top();
		q.pop();
		int v = p.second;

		if (d[v] < p.first) continue;

		for (i=0; i<(int)G[v].size(); i++) {
			edge e = G[v][i];
			if (d[e.to] > d[v] + e.cost) {
				d[e.to] = d[v] + e.cost;
				q.push(P(d[e.to], e.to));
			}
		}
	}
}

int main() {
	int i, j;
	int total;
	int minT;

	while (1) {
		scanf("%d ", &E);
		if (!E) break;

		for (i=0; i<MAX_V; i++)
			G[i].clear();

		V = 0;
		for (i=0; i<E; i++) {
			int ef, et, ec;
			scanf("%d%d%d ", &(ef), &(et), &(ec));
			G[ef].push_back(edge(et, ec));
			G[et].push_back(edge(ef, ec));
			V = max(V, ef);	
			V = max(V, et);	
		}
		V++;

		total = INF;
		minT = INF;
		for (i=0; i<V; i++) {
			dijkstra(i);

			int sum = 0;
			for (j=0; j<V; j++)
				sum += d[j];

			if (sum < total) {
				total = sum;
				minT = i;
			} else if (sum == total && i < minT)
				minT = i;
		}

		printf("%d %d\n", minT, total);
	}	

	return 0;
}

Measured memory_bytes: 1192
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr ll INF = 1'010'000'000'000'000'017LL;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()

int main() {
    // AtCoder
    // template
    ll a, b, c;
    cin >> a >> b >> c;
    ll fst = a % b;
    if(fst == c) {
        cout << "YES";
        return 0;
    }

    for(size_t i = 2; fst != i * a % b; i++) {
        // cout << i << endl;
        if(i * a % b == c) {
            cout << "YES";
            return 0;
        }
    }
    cout << "NO";
}


Measured memory_bytes: 256
// BEGINNING WITH THE NAME OF ALMIGHTY GOD ALLAH
// AUTHOR:: MOHAMMAD FAISAL
#include<bits/stdc++.h>
using namespace std;
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.flush();
	int a;
    cin >> a;
    cout<<a/3;

	return 0;
	// BYE BYE 
}


Measured memory_bytes: 256
#include <cstdio>
#define rep(i,n) for(int i = 0; i < n; i++)

int n, m;
int ice[90][90];
int dx[4] = {1,0,-1,0}, dy[4] = {0,1,0,-1};
int ans, cnt;

void dfs(int x, int y){
	if(ans < cnt) ans = cnt;
	rep(i,4){
		if(0<=x+dx[i]&&x+dx[i]<m&&0<=y+dy[i]&&y+dy[i]<n&&ice[x+dx[i]][y+dy[i]] == 1){
			cnt++;
			ice[x+dx[i]][y+dy[i]] = 0;
			dfs(x+dx[i],y+dy[i]);
			ice[x+dx[i]][y+dy[i]] = 1;
			cnt--;
		}
	}
}

int main(){
	while(scanf("%d%d", &n, &m),n||m){
		ans = 0;
		rep(i,m) rep(j,n) scanf("%d", &ice[i][j]);
		rep(i,m){
			rep(j,n){
				if(ice[i][j] == 0) continue;
				cnt = 0;
				dfs(i,j);
			}
		}
		printf("%d\n", ans);
	}
}

Measured memory_bytes: 1060
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <locale>
#include <iostream>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define ALL(x) (x).begin(),(x).end()

using namespace std;

using ll = long long;
using ld = long double;

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template <typename T> int len(const T &x) { return x.size(); }

template<typename T>
vector<T> table(int n, T v) { return vector<T>(n, v); }

template <class... Args>
auto table(int n, Args... args) {
  auto val = table(args...);
  return vector<decltype(val)>(n, move(val));
}

struct yes_no : numpunct<char> {
  string_type do_truename()  const { return "YES"; }
  string_type do_falsename() const { return "NO"; }
};

void solve(string s) {
  cout << s.front() << s.size() - 2 << s.back() << endl;
}

int main() {
  locale loc(locale(), new yes_no);
  cout << boolalpha << setprecision(12) << fixed;
  cout.imbue(loc);
	string s;
	cin >> s;
	solve(s);
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main()
{
    int n;
    cin>>n;
    vector <int> a(n);
    for (int i=0;i<n;i++)
    cin>>a[i];
    sort (a.begin(),a.end());
    int j=0;
    while(j<n)
    {
        if (a[j]==a[j+1])
       {cout <<"NO";
        break;} 
        else 
            {if (j+1==n)
            {cout <<"YES";
            break;}
            
            }
            j++;
    } 
} 


Measured memory_bytes: 1024