akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<ll>;
#define ci(n,a)   vi a(n); rep(i,(n)) cin>>a[i];
#define rep(i,n)  for(ll i = 0; i < (n); ++i)
#define red(i,n)  for(ll i = (n)-1; i >= 0; --i)
#define all(a)    begin(a),end(a)
#define pb(a)     push_back(a)
#define mp(a,b)   make_pair(a,b)
#define yn(a)     cout << ( (a)?"Yes\n":"No\n" )
inline ll gcd(ll a,ll b) { return b?gcd(b,a%b):a; }
ll INF = 1e9+7, LINF = 1e18;

vi c;
bool F=0;

void a()
{
    if(c.size()==0||F) {F=1;return;}
    red(i,c.size()) if(c[i]==i+1) {
        c.erase(begin(c)+i);
        a();
        c.insert(begin(c)+i,i+1);
        if(F) {cout<<i+1<<endl;return;}
        break;
        
    }
    return ;
}

int main(int argc,char* argv[])
{
    ll n,x;
    cin>>n;
    rep(i,n){cin>>x;c.pb(x);}
    a();
    if(!F) cout<<-1<<endl;
    return 0;
}


Measured memory_bytes: 256
import qualified Data.ByteString.Char8 as BC
import Data.Maybe (fromJust)
import Data.List
import Data.Ord

readIntLines :: IO [Int]
readIntLines = map (fst . fromJust . BC.readInt) . BC.lines <$> BC.getContents

solve :: [Int] -> [Int] -> [Int]
solve [] _ = []
solve (a:as) list@[s1, s2] = res : solve as list
  where res = if a /= s1 then s1 else s2

main :: IO ()
main = do
  getLine
  as <- readIntLines
  let list = take 2 $ sortOn Down as
  mapM_ print $ solve as list

Measured memory_bytes: 44796
#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <string.h>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>
#include <numeric>
#include <iomanip>

// output
#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
// utility
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<int(n);++i)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
template<class T> inline T chmax(T & a, const T b) { return a = (a < b) ? b : a; }
template<class T> inline T chmin(T& a, const T b) { return a = (a > b) ? b : a; }

// type/const
#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const int MOD = 1000000007;
/* const int MOD = 998244353; */
const int INF = 1e18;
const double PI = acos(-1);

using namespace std;
struct INIT { 
  INIT(){cin.tie(0); ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
}}INIT;


signed main() {
  int N, K; 
  cin >> N >> K;

  vector<int> L, R;
  REP(i, N){
    int A;
    cin >> A;
    if(A >= 0) R.emplace_back(A);
    else L.emplace_back(-A);
  }
  if(L.size() != 0) reverse(ALL(L));

  int ans = INF;
  if(R.size() >= K) chmin(ans, R[K-1]);
  if(L.size() >= K) chmin(ans, L[K-1]);

  FOR(i, 1, K){
    int j = K-i;
    if(R.size() < i) continue;
    if(L.size() < j) continue;
    int MIN = min(R[i-1], L[j-1]);
    int MAX = max(R[i-1], L[j-1]);
    chmin(ans, MIN*2+MAX);
  }

  cout << ans << "\n";

  return 0;
}

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

int main(){
    int N;
    cin >> N;
    set<vector<int>> st[11];
    st[1].insert({0});
    for(int k=1; k<10; k++){
        for(auto& v : st[k]){
            int mx = *max_element(v.begin(), v.end());
            for(int a=0; a<=mx+1; a++){
                auto v2 = v;
                v2.push_back(a);
                st[k+1].insert(v2);
            }
        }
    }
    for(auto& v : st[N]){
        for(int a : v) cout << char('a'+a);
        cout << endl;
    }
    return 0;
}


Measured memory_bytes: 18432
def orderN(N,L,ices):
    upPeak = L - ices[0]
    downPeak = L - ices[0]
    peaks = []
    for i in xrange(len(ices)):
        if i < N-1:
            if ices[i] < ices[i+1]:
                peaks.append(downPeak)
                downPeak = L - ices[i+1]
                upPeak += L - ices[i+1]
            else:
                peaks.append(upPeak)
                upPeak = L - ices[i+1]
                downPeak += L - ices[i+1]
        else:
            peaks.append(upPeak)
            peaks.append(downPeak)
    print(max(peaks))

N,L = map(int,raw_input().strip().split())
ices = [int(raw_input().strip()) for _ in xrange(N)]

orderN(N,L,ices)

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

int main() {
	int H[10010], W[10010];
	int n = 0;

	while (1) {
		cin >> H[n] >> W[n];
		if (!H[n] && !W[n]) break;
		n++;
	}

	for (int i = 0; i < n; ++i) {
		for (int h = 0; h < H[i]; ++h) {
			for (int w = 0; w < W[i]; ++w) cout << "#";
			cout << endl;
		}
		cout << endl;
	}
}


Measured memory_bytes: 3084
#include<bits/stdc++.h>
using namespace std;
#define sz(a) int((a).size())
#define int long long
#define Int int32_t
#define all(c) c.begin(), c.end()
#define FAST ios_base::sync_with_stdio(false) , cin.tie(NULL);
#define pii pair< int , int >
#define pb push_back
#define F first
#define S second
#define endl "\n"
#define present(c,x) ((c).find(x) != (c).end())
#define cpresent(c,x) (find(all(c),x) != (c).end())
#define bitcnt(n) __builtin_popcountll(n)
#define setpre(n) cout << fixed << setprecision(n)
#define tr(c) for(auto x : c )cout << x << " ";
#define ol(c , s , e ) for(int pos=s; pos<e ; pos++) cout << c[pos] << " ";
#define inf 1e18;
#define PI acos(-1)
const int M = 1000000007;
const int N=2e5+5;
//#define local
#ifdef local
template<typename... T >
void bug(T... __VA_ARGS__) {
    ((cerr << __VA_ARGS__ << " ") , ...);
}
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", bug(__VA_ARGS__) , cerr << endl;
#endif



void solve() {

    int a, b , c ,d;
    cin >> a >> b >> c >> d;
    int i = 0;
    while(1)
    {
        if(i==0)
        {
            if(c - b <=0){
                cout << "Yes\n";
                return;
            }
            else{
                c-=b;
            }
        }
        else{
            if(a -d <=0){
                cout <<"No\n";
                return ;
            }
            else{
                a-=d;
            }
        }
        i = (i==0 ? 1 : 0);
    }
}


signed main()
{
    FAST;
    //TODO:  check test cases are there or not?
    int tc=1;
//    cin >> tc;
    for(int t = 1 ; t <= tc ; t++)
    {
        solve();
    }
}

Measured memory_bytes: 3652
#include<iostream>
#include<string>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<tuple>
#include<vector>
#include<map>
#include<numeric>
#include<limits>
#include<type_traits>
using namespace std;

int main(void){
  int n[4];
  for(int i = 0; i < 4; i++){
    cin >> n[i];
  }
  sort(n, n+4);
  bool ans;
  if(n[0] == 1 && n[1] == 4 && n[2] == 7 && n[3] == 9){
    ans = true;
  }
  else ans = false;
  if(ans){cout << "YES" << endl;}
  else{cout << "NO" << endl;}
  return 0;
}


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

int main() {
    int N, M, i, total = 0, tmp;
    cin >> N >> M;
    for(i = 0; i < M; i++) {
        cin >> tmp;
        total += tmp;
    }
    if(N - total < 0) cout << -1;
    else cout << N - total;
}

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

ll MOD = 1e9 + 7;

ll powMod(ll x, ll y) {
  if (y == 0) return 1;
  if (y == 1) return x;
  ll temp = powMod(x, y / 2);
  temp = (temp * temp) % MOD;
  if (y % 2) return (x * temp) % MOD;
  else return temp;
}

ll inv(ll a) {
  return powMod(a, MOD - 2);
}

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

  ll N; cin >> N;
  ll A; cin >> A;
  ll B; cin >> B;

  ll TOTAL = powMod(2, N) - 1;
  ll r0 = 1, r1 = 1;
  for (ll i = 0; i < A; i++) {
    r0 = (r0 * (N - i) % MOD) * inv(i + 1) % MOD;
  }
  for (ll i = 0; i < B; i++) {
    r1 = (r1 * (N - i) % MOD) * inv(i + 1) % MOD;
  }
  ll ans = (TOTAL - r0 - r1 + 2 * MOD) % MOD;
  cout << ans << '\n';
  return 0;
}

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

int main()
{
	int n;
	while (cin >> n, n)
	{
		int i = 0;
		int ans = 0;
		while (true)
		{
			i++;
			if (i >= n) break;

			int j = 0;
			int sum = i;
			while (true)
			{
				j++;
				sum += i + j;
				if (sum > n) break;
				if (sum == n) ans++;
			}
		}

		cout << ans << endl;
	}

	return 0;
}

Measured memory_bytes: 1160
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

template<class T> inline T sqr(T x) {return x*x;}

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef unsigned long long ULL;

#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

const double EPS = 1e-10;
const double PI  = acos(-1.0);

#define CLR(a) memset((a), 0 ,sizeof(a))

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

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

int main() {
  string s;
  
  cin >> s;
  REP(i, s.size()) printf("%c", (s[i]+10)%26+'A');
  cout << endl;  
}

Measured memory_bytes: 1176
#include<stdio.h>
int main()
{
int x;
int y;
int z;
while(1)
{
 scanf("%d %d",&x,&y);
 if(x==0&&y==0)
 {
   break;
 }
 if(x>y)
 {
  z=x;
  x=y;
  y=z;
 }
 printf("%d %d\n",x,y);
 
}
return 0;
 
}

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

using ll = long long;

int main() {
    int n; cin >> n;
    vector<ll> d(n), c(n);
    for(int i = 0; i < n; ++i) {
        cin >> d[i] >> c[i];
    }

    vector<vector<ll>> nxt(10, vector<ll>(10)), cnt(10, vector<ll>(10, 1));
    for(int i = 0; i <= 9; ++i) {
        for(int pre = 0; pre <= 9; ++pre) {
            int cur = i + pre;
            if(cur >= 10) {
                cur = (cur % 10) + 1;
                cnt[i][pre] += 1;
            }
            nxt[i][pre] = cur;
        }
    }

    ll pre = 0, ans = -1;
    for(int i = 0; i < n; ++i) {
        vector<ll> t(10, -1);
        ll idx = 0;
        vector<ll> sum = {0};
        while(t[pre] == -1 && c[i]-- > 0) {
            t[pre] = idx++;
            ans += cnt[d[i]][pre];
            pre = nxt[d[i]][pre];
            sum.push_back(sum.back() + cnt[d[i]][pre]);
        }
        const ll cycle_len = idx - t[pre];
        if(c[i] <= 0) continue;
        ans += (sum.back() - sum[t[pre]]) * (c[i] / cycle_len);
        c[i] %= cycle_len;
        while(c[i]-- > 0) {
            ans += cnt[d[i]][pre];
            pre = nxt[d[i]][pre];
        }
    }

    cout << ans << endl;
}


Measured memory_bytes: 3328
/*
    Author - Param Kothari
    Ah shit, here we go again
*/

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

#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define pb push_back
#define mk make_pair

typedef long long ll;
typedef long double ld;

void solve(){
    string s;
    cin >> s;
    int n = (int)s.size();
    for(int i = 0; i < n; i++){
        if(s[i] == '?') s[i] = 'D';
    }
    cout << s << "\n";
    return;
}

int main(){
    IOS;
    int t = 1;
    // cin >> t;
    for(int i = 1; i <= t; i++){
        solve();
    }
    return 0;
}

Measured memory_bytes: 3744
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <cmath>
#include <iomanip>
#include <cassert>
#include <bitset>
using namespace std;

typedef pair<int, int> P;
typedef pair<int, P> P2;
#define rep(i, n) for (int i=0; i<(n); i++)
#define all(c) (c).begin(), (c).end()
#define uniq(c) c.erase(unique(all(c)), (c).end())
#define index(xs, x) (int)(lower_bound(all(xs), x) - xs.begin())
#define _1 first
#define _2 second
#define pb push_back
#define INF 1145141919
#define MOD 1000000007

int N, M, Q;
int U[4000], R[4000];
int find(int x) {
  if (U[x] == x) return x;
  return U[x] = find(U[x]);
}
void unite(int x, int y) {
  x = find(x), y = find(y);
  if (x == y) return;
  if (R[x] < R[y]) swap(x, y);
  U[y] = x;
  R[x] += R[y];
}
bool same(int x, int y) {
  return find(x) == find(y);
}

vector<P> G[4000];
int par[4000], dep[4000];
int pare[4000];
void dfs(int x, int p, int r, int pe) {
  par[x] = p;
  pare[x] = pe;
  dep[x] = r;
  for (P pp : G[x]) if (pp._1 != p) dfs(pp._1, x, r+1, pp._2);
}

signed main() {
  ios::sync_with_stdio(false); cin.tie(0);
  cin >> N >> M;
  vector<P2> edges;
  rep(i, M) {
    int a, b, c;
    cin >> a >> b >> c;
    a--, b--;
    edges.pb(P2(c, P(a, b)));
  }
  rep(i, N) U[i] = i, R[i] = 1;
  sort(all(edges));
  long long sum = 0;
  for (P2 p : edges) {
    int c = p._1, a = p._2._1, b = p._2._2;
    if (!same(a, b)) {
      G[a].pb(P(b, c));
      G[b].pb(P(a, c));
      unite(a, b);
      sum += c;
    }
  }
  dfs(0, -1, 0, 0);
  cin >> Q;
  rep(i, Q) {
    int s, t;
    cin >> s >> t;
    s--, t--;
    int m = 0;
    if (dep[s] < dep[t]) swap(s, t);
    while (dep[s] > dep[t]) {
      m = max(m, pare[s]), s = par[s];
    }
    while (s != t) {
      m = max(m, pare[s]), s = par[s];
      m = max(m, pare[t]), t = par[t];
    }
    cout << sum-m << "\n";
  }
  return 0;
}


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

void swap(char *a, char *b){
	char temp[101];
	strcpy(temp, a);
	strcpy(a, b);
	strcpy(b, temp);
}

void quickSort(char array[][101], int left, int right){
	char pivot[101] = {0};

	if(right - left <= 1)
		return;

	int pivotIdx = (left + right) / 2;
	strcpy(pivot, array[pivotIdx]);
	swap(array[pivotIdx], array[right-1]);

	int i = left;
	for(int j=left; j < right - 1; j++) {
		if(strcmp(array[j], pivot) < 0) {
			swap(array[i++], array[j]);
		}
	}
	swap(array[i], array[right-1]);

	quickSort(array, left, i);
	quickSort(array, i + 1, right);
}

int main(void){
	int n, l;
	char str[100][101] = {{0}};

	scanf("%d%d", &n, &l);
	for(int i=0; i < n; i++) {
		scanf("%s", &str[i]);
		if(strlen(str[i]) != l)
			return 1;
	}

	quickSort(str, 0, n);

	for(int i=0; i < n; i++) {
		printf("%s", str[i]);
	}

	return 0;
}


Measured memory_bytes: 128
<?php /*atcoder.php*/

$at = new Atcoder();
$at->main();
unset($at);

class Atcoder{
	private function lineIn(){
		$buf = fgets(STDIN);
		return $this->killNewLine($buf);
	}
	private function arrayIn(){
		$buf = explode(" ", fgets(STDIN));
		return $this->killNewLine($buf);
	}
	private function killNewLine($buf = null){
		$buf = str_replace("\r\n", "", $buf);
		$buf = str_replace("\n", "", $buf);
		$buf = str_replace("\r", "", $buf);
		return $buf;
	}

	public function main(){
		$n = $this->lineIn();
		$s = array();

		for($i = 0; $i < $n; $i++){
			$s[] = $this->arrayIn();
		}

		$exBTC = (380000);
		
		$ans = 0;

		for($i = 0; $i < $n; $i++){
			switch ($s[$i][1]){
				case ("JPY"):
					$ans += $s[$i][0];
				break;
				case ("BTC"):
					$ans += ($s[$i][0] * $exBTC);
				break;
				default:
				break;
			}
		}

		echo $ans . "\n";

	}
}
?>


Measured memory_bytes: 4728
#include <iostream>
#include <vector>

using namespace std;

int cnt = 0;
vector<int> g;

void insertion_sort(vector<int> &arr, int num, int g) {
    for (int i = g; i < num; i++) {
        int v = arr[i];
        int j = i - g;
        while (j >= 0 && arr[j] > v) {
            arr[j + g] = arr[j];
            j = j - g;
            cnt++;
        }
        arr[j + g] = v;
    }
}

void shell_sort(vector<int> &arr, int num) {
    for (int h = 1; ;) {
        if (h > num) {
            break;
        }
        g.push_back(h);
        h = 3 * h + 1;
    }
    for (int i = g.size() - 1; i >= 0; i--) {
        insertion_sort(arr, num, g[i]);
    }
}

int main() {

    int num;
    cin >> num;

    vector<int> arr(num);
    for (int i = 0; i < num; i++) {
        cin >> arr[i];
    }

    shell_sort(arr, num);

    cout << g.size() << endl;
    for (int i = g.size() - 1; i >= 0; i--) {
        cout << g[i];
        if (i != 0) {
            cout << " ";
        } else {
            cout << endl;
        }
    }
    cout << cnt;
    cout << endl;
    for (int i = 0; i < num; i++) {
        cout << arr[i];
        cout << endl;
    }

    return 0;
}



Measured memory_bytes: 6692
#include<iostream>
using namespace std;
int main(void){

  //入力
  int N, T, A;
  cin >> N >> T >> A;
  
  int H[N];
  float a[N];
  float min = 1000000000;
  for(int i = 0; i < N; i++){
    cin >> H[i];
    float sa = A - (T - H[i] * 0.006);
    //差がマイナスだったらマイナスをかける
    if(sa < 0){
      sa = -sa;
    }
    a[i] = sa;
    if(a[i] < min){
      min = a[i];
    }
  }
  
  int ans;
  for(ans = 0; ans < N; ans++){
    if(min == a[ans]){
      break;
    }
  }
  
  cout << ans + 1 << endl;

  return 0;
}

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

int main() {
  int n;
  cin >> n;
  int sum = 0;
  vector<int> vec(n);
  rep(i,n) {
    cin >> vec.at(i);
    sum += vec.at(i);
  }
  int a = sum*sum;
  int s = 0;
  rep(i,n) {
    s +=vec.at(i)*vec.at(i);
  }
  cout << (a-s)/2 <<endl;
}

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

#define rep(i, n) for (int i = 0; i < int(n); i++)
#define rrep(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define reps(i, n) for (int i = 1; i <= int(n); i++)
#define rreps(i, n) for (int i = int(n); i >= 1; i--)
#define repc(i, n) for (int i = 0; i <= int(n); i++)
#define rrepc(i, n) for (int i = int(n); i >= 0; i--)
#define repi(i, a, b) for (int i = int(a); i < int(b); i++)
#define repic(i, a, b) for (int i = int(a); i <= int(b); i++)
#define each(x, y) for (auto &x : y)
#define all(a) (a).begin(), (a).end()
#define bit32(x) (1 << (x))
#define bit64(x) (1ll << (x))

using namespace std;

using i64 = long long;
using f80 = long double;
using vi32 = vector<int>;
using vi64 = vector<i64>;
using vf80 = vector<f80>;
using vstr = vector<string>;

inline void yes() { cout << "Yes" << endl; exit(0); }
inline void no() { cout << "No" << endl; exit(0); }
inline i64 gcd(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); if (a % b == 0) return b; return gcd(b, a % b); }
inline i64 lcm(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); return a / gcd(a, b) * b; }
template <typename T> class pqasc : public priority_queue<T, vector<T>, greater<T>> {};
template <typename T> class pqdesc : public priority_queue<T, vector<T>, less<T>> {};
template <typename T> inline void amax(T &x, T y) { x = max(x, y); }
template <typename T> inline void amin(T &x, T y) { x = min(x, y); }
template <typename T> inline T exp(T x, i64 n, T e = 1) { T r = e; while (n > 0) { if (n & 1) r *= x; x *= x; n >>= 1; } return r; }
template <typename T> istream& operator>>(istream &is, vector<T> &v) { each(x, v) is >> x; return is; }
template <typename T> ostream& operator<<(ostream &os, vector<T> &v) { rep(i, v.size()) { if (i) os << ' '; os << v[i]; } return os; }
void solve(); int main() { ios::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(16); solve(); return 0; }

const int INF = 1e9;

void solve() {
  int N, M;
  cin >> N >> M;
  vector<vi32> sg(N + 1);
  vector<vi32> rg(N + 1);
  vi32 deg(N + 1);
  rep(i, N + M - 1) {
    int u, v;
    cin >> u >> v;
    sg[u].emplace_back(v);    
    rg[v].emplace_back(u);
    deg[v]++;
  }
  vi32 dag;
  {
    vi32 seen(N + 1);
    auto dfs = [&](auto dfs, int u) -> void {
      seen[u] = 1;
      each(v, sg[u]) if (!seen[v]) {
        dfs(dfs, v);
      }
      dag.emplace_back(u);
    };
    reps(i, N) if (!seen[i]) dfs(dfs, i);
    reverse(all(dag));
  }
  vi32 mp(N + 1);
  rep(i, N) {
    mp[dag[i]] = i;
  }
  vi32 ans(N + 1);
  rep(i, N) {
    int u = dag[i];
    pair<int, int> ma(0, 0);
    each(p, rg[u]) amax(ma, make_pair(mp[p], p));
    ans[u] = ma.second;
  }
  reps(i, N) cout << ans[i] << endl;
}


Measured memory_bytes: 15604
import collections

n, k = map(int, input().split())
a = list(map(int, input().split()))

counter = collections.Counter(a)
counter_sorted = sorted(counter.items(), key=lambda x: x[1], reverse=True)
ans = n
for i in range(min(k, len(counter_sorted))):
    ans -= counter_sorted[i][1]
print(ans)

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

int N, A[100005];

int main() {
	scanf("%d", &N);
	for (int i = 0; i < N; i++) scanf("%d", &A[i]);
	long long ans1 = 0, cur = 0;
	for (int i = 0; i < N; i++) {
		if ((cur + A[i] > 0 && i % 2 == 0) || (cur + A[i] < 0 && i % 2 == 1)) {
			cur += A[i];
			continue;
		}
		cur += A[i];
		if (i % 2 == 0) ans1 += abs(cur - 1);
		else ans1 += abs(cur + 1);
		if (i % 2 == 0) cur = 1;
		else cur = -1;
	}
	cur = 0;
	long long ans2 = 0;
	for (int i = 0; i < N; i++) {
		if ((cur + A[i] > 0 && i % 2 == 1) || (cur + A[i] < 0 && i % 2 == 0)) {
			cur += A[i];
			continue;
		}
		cur += A[i];
		if (i % 2 == 1) ans2 += abs(cur - 1);
		else ans2 += abs(cur + 1);
		if (i % 2 == 1) cur = 1;
		else cur = -1;
	}
	printf("%lld\n", min(ans1, ans2));
}


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

using namespace std;

#define LL long long
#define DD double
#define Pb push_back
#define Bp pop_back
#define Pf push_front
#define Fp pop_front
#define Ub upper_bound
#define Lb lower_bound
#define In insert
#define All(x) x.begin(), x.end()
#define mem(a, b) memset(a, b, sizeof(a))
#define fast ios_base::sync_with_stdio(0);cin.tie(0)
#define X first
#define Y second
#define mx1 10
#define mx2 110
#define mx3 1010
#define mx4 10010
#define mx5 100010
#define mx6 1000010

typedef vector<LL> Vl;
typedef vector<DD> Vd;
typedef vector<bool> Vb;
typedef vector<Vl> VVl;
typedef pair<LL, LL> Pll;
typedef pair<DD, DD> Pdd;
typedef vector<Pll> Vpl;
typedef vector<Pdd> Vpd;
typedef queue<LL> Ql;
typedef stack<LL> Sl;
typedef deque<LL> Dl;

LL _set(LL N, LL pos) {return N = N | (1 << pos);}
LL _reset(LL N, LL pos) {return N = N & ~(1 << pos);}
bool _check(LL N, LL pos) {return (bool)(N & (1 << pos));}
bool _upper(char a) {return a >= 'A' && a <= 'Z';}
bool _lower(char a) {return a >= 'a' && a <= 'z';}
bool _digit(char a) {return a >= '0' && a <= '9';}

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

///**************************DONE****************************///

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

    cout << n * n * n << '\n';
    return 0;
}


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

int main() {
  ll N, M;
  cin >> N >> M;
  if (N==1 && M==1) {
    cout << 1 << endl;
    return 0;
  }
  if (N==1 || M==1) {
    if (N==2 || M==2) {
      cout << 0 << endl;
    }
    else {
      cout << max(N, M) - 2 << endl;
    }
  }
  else {
    cout << (N-2)*(M-2) << endl;
  }
}


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

struct init_ { init_(){ cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(10); } } init_;

template<class C> using iodef_rng_t = typename enable_if<decltype(declval<C>().begin(), true_type{})::value && !is_same<C, string>::value>::type;
template<class C, class = iodef_rng_t<C>> istream& operator>>(istream& in, C& c) { for (auto& v : c) { in >> v; } return in; }
template<class C, class = iodef_rng_t<C>> ostream& operator<<(ostream& out, const C& c) { int i = 0; for (const auto& v : c) { if (i++) { out << ' '; } out << v; } return out; }
template<size_t N, class T, class R> using when_last = typename enable_if<N == tuple_size<remove_reference_t<T>>::value - 1, R>::type;
template<size_t N, class T, class R> using when_init = typename enable_if<N != tuple_size<remove_reference_t<T>>::value - 1, R>::type;
template<size_t N = 0, class T> auto operator>>(istream& in, T&& t) -> when_last<N, T, istream&> { return in >> get<N>(t); }
template<size_t N = 0, class T> auto operator>>(istream& in, T&& t) -> when_init<N, T, istream&> { return operator>><N + 1>(in >> get<N>(t), forward<T>(t)); }
template<size_t N = 0, class T> auto operator<<(ostream& out, const T& t) -> when_last<N, T, ostream&> { return out << get<N>(t); }
template<size_t N = 0, class T> auto operator<<(ostream& out, const T& t) -> when_init<N, T, ostream&> { return operator<<<N + 1>(out << get<N>(t) << ' ', t); }

#ifdef LOCAL
template<class T> void trace_(const char* s, const T& v) { cerr << s << "=" << v; }
template<class T, class... Ts> void trace_(const char* s, const T& v, const Ts&... vs) { for (; *s != ','; ++s) { cerr << *s; } cerr << "=" << v << ","; trace_(++s, vs...); }
#define TRACE(...) (cerr << "\033[2m\033[33m", trace_(#__VA_ARGS__, __VA_ARGS__), cerr << "\033[0m\n")
#else
#define TRACE(...)
#endif

int main() {
    int n;
    cin >> n;
    vector<int64_t> a(n);
    cin >> a;
    auto cnt = [&](int pos) {
        int64_t cnt_a = 0, sum_a = 0;
        for (int i = 0; i < n; i++) {
            sum_a += a[i];
            if (i % 2 == pos) {
                if (sum_a <= 0) {
                    cnt_a += 1 - sum_a;
                    sum_a = 1;
                }
            } else {
                if (sum_a >= 0) {
                    cnt_a += sum_a + 1;
                    sum_a = -1;
                }
            }
        }
        return cnt_a;
    };
    cout << min(cnt(0), cnt(1)) << '\n';
}


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

int main () {
int n;
cin>>n;
vector<int>p(n);
int cnt =0;
int crntmin =1e9;

  for (int i=0;i<n;i++){
    cin>>p.at(i);
  }
  for (int i=0;i<n;i++){
    crntmin = min(crntmin,p.at(i));
    if(crntmin == p.at(i)){
      cnt++;
    }
  }
cout<<cnt<<endl;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define loop(start,i,end) for(i = start; i <= end; i++)
#define debug(x) cout << #x << " : " << x << "\n"
#define inf 1000000005
#define ll long long
#define type long long
#define mod 2019
#define nmax 200005
using namespace std;

ifstream in("multiple2.in");
ofstream out("multiple2.out");

//void debug_m(type x[nmax][nmax], type n , type m, string nume){ll i,j; cout << nume << " : \n";;for (i = 1; i <= n; i++) {for (j = 1; j <= m; j++) cout << x[i][j] << " ";cout << "\n";}cout << "\n";}
void debug_a(type x[nmax], type n , string nume){type i;cout << nume << " : ";for (i = 1; i <= n; i++)cout << x[i] << " ";cout << "\n";}
void debug_v(vector<type> &v , string name){cout << name << " : ";for (auto k : v) cout << k << " ";cout << "\n";}

string s;
ll a[nmax],n,v[nmax],f[nmax];
int main()
{ll i,put10,sol = 0;
    cin >> s;
 //   cout << "s : " << s << "\n";
    for (i = 0; i < s.size(); i++) a[i + 1] = s[i] - '0';
    n = s.size();

  //  debug_a(a , n , "a_original");

    put10 = 1;
    for (i = n; i >= 1; i--) {
        a[i] = a[i] * put10 % mod;
        put10 = put10 * 10 % mod;
    }

    for (i = 1; i <= n; i++)
        v[i] = ( a[i] + v[i - 1] ) % mod;

   // debug_a(a , n , "a_nou");
   // debug_a(v , n , "v");

    for (i = 1; i <= n; i++){
        f[v[i]]++;
    }

    f[0]++;

    for (i = 0; i < mod; i++)
        if (f[i] > 0) {
            sol = sol + f[i] * (f[i] - 1) / 2;
            f[i] = 0;
        }
    cout << sol << "\n";
}



Measured memory_bytes: 6788
#include <iostream>
#include <vector>
#include <map>
#include <queue>
#include <string>
#include <algorithm>
#include <cmath>
#include <climits>
#include <fstream>
#include <cstdlib>
#include <cstdio>
#define REP(i, n) for(long long int i=0; i<(n); i++)
#define FOR(i, a, n) for(long long int i=(a); i<(n); i++)
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<char> vc;

int main(){
    int N;cin>>N;
    vi v(N);
    REP(i, N){
        cin >> v[i];
    }

    sort(v.begin(), v.end());
    double ans = 0;
    REP(i, N){
        if(i == N-1 || i == N-2){
            ans += v[N-i-1]/pow(2, N-1);
        }else{
            ans += v[N-i-1]/pow(2, N-(N-i-1));
        }
    }

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

Measured memory_bytes: 384
import java.util.*;

public class Main {

	/**
	 * @param args
	 */
	Scanner sc = new Scanner(System.in);
	StringTokenizer st;
	
	long gcd(long a, long b) {
		if (b == 0) return a;
		return gcd(b, a % b);
	}
	
	
	void run() {
		long a, b;
		while (sc.hasNextLine()) {
			st = new StringTokenizer(sc.nextLine());
			a = Integer.parseInt(st.nextToken());
			b = Integer.parseInt(st.nextToken());
			System.out.printf("%d %d\n", gcd(a,b), a*b/gcd(a,b));
		}
	}
	
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		new Main().run();
	}

}

Measured memory_bytes: 17212
import java.util.*;

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

    int a=sc.nextInt();
    int b=sc.nextInt();
    int c=sc.nextInt();
    int d=a-b;
    int n=c-d;
    if(n<0)
    {
      n=0;
    }
    System.out.print(n);

  }
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
#define REP(i, s, n) for (int i = s; i < n; ++i)
#define rep(i, n) REP(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())
#define IINF INT_MAX
#define LLINF LLONG_MAX
#define DEBUG true
// sort(a.begin(), a.end(), std::greater<int>());

/*
std::vector<std::string> split(const std::string &input, char delimiter)
{
    std::istringstream stream(input);

    std::string field;
    std::vector<std::string> result;
    while (std::getline(stream, field, delimiter))
    {
        result.push_back(field);
    }
    return result;
}
*/

int main()
{
    int a;
    cin>>a;
    set<char> m;
    rep(i,a){
        char b;
        cin>>b;
        m.insert(b);
    }
    if(m.size()==3){
        cout<<"Three"<<endl;
    }
    if(m.size()==4){
        cout<<"Four"<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt(), M = sc.nextInt(), C = sc.nextInt();
		int B[] = new int[M];
		int A[][] = new int[N][M];
		int AB[] = new int[N];
		for(int x=0; x<M; x++)B[x] = sc.nextInt();
		for(int y=0; y<N; y++) {
			for(int z=0; z<M; z++) {
				A[y][z] = sc.nextInt();
				AB[y] += A[y][z]*B[z];
			}			
		}
		int count = 0;
		for(int i=0; i<N; i++)if(AB[i]+C > 0)count++;
		System.out.println(count);
		sc.close();
	}

}

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

using namespace std;

typedef long long ll;

const ll p = 1e9 + 7;
const ll inv = 500000004;

int main() {
  ios::sync_with_stdio(false); cin.tie(NULL);
  ll n, k; cin >> n >> k;
  vector<ll> a(n);
  for (int i = 0; i < n; i++) cin >> a[i];
  ll ans = 0;
  for (int i = 0; i < n; i++) {
    ll cnt1 = 0, cnt2 = 0;
    for (int j = i + 1; j < n; j++) if (a[i] > a[j]) ++cnt1;
    for (int j = 0; j < n; j++) if (a[i] > a[j]) ++cnt2;
    ans += k * cnt1 % p + k * (k - 1) % p * cnt2 % p * inv % p;
    ans %= p;
  }
  cout << ans << endl;
  return 0;
}



Measured memory_bytes: 256
n,x=map(int,input().split())
a=list(map(int,input().split()))
b=a[0]
ans=0
for i in range(1,n):
  if b>x:
    ans+=b-x
    b=x
  if a[i]+b>x:
    ans+=b-x+a[i]
    a[i]=x-b
  b=a[i]
print(ans)

Measured memory_bytes: 85652
#include<stdio.h>

int main ()
{
	int n,i;
	scanf("%d", &n);
	i=1;
	while(i<=n)
	{
		if (i%10==3||i%3==0||i/10%10==3||i/10/10%10==3||i/10/10/10%10==3)
		printf(" %d",i);
		i++;
	}
	printf("\n");
	return 0;
}


Measured memory_bytes: 2748
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;

namespace MyProject
{
    class Program
    {
        static void Main(string[] args)
        {
#if Local
            var sw = new Stopwatch();
            sw.Start();
            Console.SetIn(new StreamReader("input.in"));
#endif

            var solver = new Solver();
            solver.Solve();
#if Local
            Console.WriteLine($"{sw.ElapsedMilliseconds}ms");
#endif
        }
    }

    class Solver
    {
        public void Solve()
        {
            var N = int.Parse(Console.ReadLine());
            var A = Console.ReadLine().Split().Select(elem => int.Parse(elem)).ToArray();

            var max = A.Max();
            var check = new bool[max + 1];
            var exist = new bool[max + 1];
            foreach (var i in Enumerable.Range(0, N))
            {
                if (check[A[i]])
                {
                    continue;
                }

                if (exist[A[i]])
                {
                    check[A[i]] = true;
                    continue;
                }
                else
                {
                    exist[A[i]] = true;
                }

                for (var j = 2 * A[i]; j <= max; j += A[i])
                {
                    check[j] = true;
                }
            }

            Console.WriteLine(A.Count(elem => check[elem] == false));
        }
    }
}


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

int main()
{
    int n;
    scanf("%d",&n);
    int num[n];
    int count=0;
    for(int i=0; i<n; i++){
      scanf("%d",&num[i]);
      if(num[i]%2==0){
        count++;
        if(num[i]%4==0)count++;
      }
    }
    if(n%2==1){
      if(count>=(n-1))printf("Yes\n");
      else printf("No\n");
    }else{
      if(count>=n)printf("Yes\n");
      else printf("No\n");
    }
    return 0;
}


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

using namespace std;

#define rep(i, n) for(int i = 0; i < n; i++)
typedef long long ll;
template<typename T> bool chmax(T &a, T b) {if(a <= b){a = b; return true;}return false;}
template<typename T> bool chmin(T &a, T b) {if(a >= b){a = b; return true;}return false;}


int main(void){
    ll sum = 0;
    string s;
    cin >> s;
    for(int bit = 0; bit < (1<<s.length() - 1); bit++){
        int before = 0;
        for(int i = 0; i < s.length() - 1; i++){
            if(bit&(1<<i)){
                sum += stoll(s.substr(before, i + 1 - before));
                before = i + 1;
            }
        }
        sum += stoll(s.substr(before, s.length() - before));
    }
    cout << sum << endl;
}

Measured memory_bytes: 256
<?php
    $lineNum = fgets(STDIN);

    $resultCount = 0;
    for ($i = 0; $i < $lineNum; $i++) {
        $val = (int)fgets(STDIN);
        if (isPrime($val)) {
            $resultCount++;
        }
    }

    echo $resultCount . PHP_EOL;

    function isPrime($num) {
        switch ($num) {
        case 1:
            return false;
        case 2:
            return true;
        }
        
        if ($num % 2 == 0) {
            return false;
        }

        $i = 0;
        for ($i = 2; $i * $i <= $num; $i++) {
            if ($num % $i == 0) {
                return false;
            }
        }
        return true;
    }


Measured memory_bytes: 9252
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
# define mod 1000000007
# define INF (1 << 29)
# define MAX_N 1000010
/* ACはうれCすぎてうれD */

vector<ll> divisor(ll n){
    vector<ll> res;
    for(ll i = 1; i * i <= n; i++){
        if(n % i == 0){
            res.push_back(i);
            if(i != n / i) res.push_back(n / i);
        }
    }
    return res;
}

ll GetDigit(ll num){
    ll digit=0;
    while(num!=0){
        num /= 10;
        digit++;
    }
    return digit;
}

ll F(ll a, ll b){
    ll dig_a = GetDigit(a);
    ll dig_b = GetDigit(b);
    if(dig_a > dig_b) return dig_a;
    else return dig_b; 
}

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

    vector<ll> div = divisor(n);

    ll ans = 11;
    for(int i=0; i<div.size(); i++){
        ll A = div[i];
        ll B = n / A;
        ll tmp_ans = F(A, B);
        if(tmp_ans < ans){
            ans = tmp_ans;
        }
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 256
n = int(input())
sortedlist = [int(i) for i in input().split()]
anslist = []

longest = 0
ans = 0

for i in range(n+1):
  if i==0:
    longest += abs(sortedlist[0]-0)
  elif i==n:
    longest += abs(0-sortedlist[n-1])
  else:
    longest += abs(sortedlist[i]-sortedlist[i-1])

    
for i in range(n):
  if i==0:
    ans = longest - abs(sortedlist[0]) - abs(sortedlist[1]-sortedlist[0]) + abs(sortedlist[1])
  elif i==n-1:
    ans = longest - abs(sortedlist[n-1]) - abs(sortedlist[n-1]-sortedlist[n-2]) + abs(sortedlist[n-2])
  else:
    ans = longest - abs(sortedlist[i]-sortedlist[i-1])-abs(sortedlist[i+1]-sortedlist[i]) + abs(sortedlist[i+1]-sortedlist[i-1])
  print(ans)
  

Measured memory_bytes: 13792
def add_point(string):
    global ans
    if string=="r":
        ans+=p
    elif string=="s":
        ans+=r
    else:
        ans+=s

n,k=map(int,input().split())
r,s,p=map(int,input().split())
S=list(input())

ans=0

for i in range(n):
    if i<k:
        add_point(S[i])
    else:
        if S[i]==S[i-k]:
            if i+k<n and S[i]==S[i+k]:
                S[i]="a"
            continue
        add_point(S[i])
print(ans)

Measured memory_bytes: 4084
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
int main()
{
  int N;
  cin >> N;
  ll A[N + 10], B[N + 10];
  ll sum = 0;
  ll x = 0;
  int cnt = 0;
  for (int i = 0; i < N; i++)
  {
    cin >> A[i];
    sum += A[i];
  }
  for (int i = 0; i < N; i++)
  {
    cin >> B[i];
  }
  for (int i = 0; i < N; i++)
  {
    if (A[i] < B[i])
    {
      cnt++;
      ll y = B[i] - A[i];
      x += (B[i] - A[i]);
      A[i] += y;
    }
  }
  ll C[N];
  for (int i = 0; i < N; i++)
  {
    C[i] = A[i] - B[i];
  }
  sort(C, C + N);
  reverse(C, C + N);
  for (int i = 0; i < N; i++)
  {
    if (x <= 0)
    {
      break;
    }
    x -= C[i];
    cnt++;
  }
  if(x>0){cout<<-1<<endl; return 0;}
  cout << cnt << endl;
}

Measured memory_bytes: 2560
n = input().split(' ')

if n[0] != n[1] != n[2] != n[0]:
    print(3)
elif n[0] == n[1] != n[2] != n[0]:
    print(2)
elif n[0] != n[1] == n[2] != n[0]:
    print(2)
elif n[2] == n[0] != n[1] != n[0]:
    print(2)
else:
    print(1)

Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <vector>
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
using namespace std;
typedef long long ll;
int main()
{
  ll n;cin >> n;
  ll res = 0;
  res += (n / 500) * 1000;
  n = n % 500;
  res += (n / 5) * 5;
  cout << res << "\n";
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 

using namespace std;
using namespace __gnu_pbds; 
  
#define ll long long
#define X first
#define Y second
#define all(x) x.begin(), x.end()
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 

#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
	enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
	ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
	*this << "[";
	for (auto it = d.b; it != d.e; ++it)
		*this << ", " + 2 * (it == d.b) << *it;
	ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

const int mod = (int)1e9 + 7;
const int MX = (int)1e5 + 10;

void add_self(int &x, int y){x += y; if(x >= mod) x -= mod;}
void sub_self(int &x, int y){x -= y; if(x < 0) x += mod;}
void mul(int &x, int y){x = x * 1LL * y % mod;}


int main(){

	cin.tie(0); cout.tie(0);
	ios_base::sync_with_stdio(0);

	int m1, d1, m2, d2;
	cin >> m1 >> d1 >> m2 >> d2;

	cout << (m1 != m2) << endl;

	
	return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<iostream>
#include<queue>
#include<vector>
#include <bitset>
#include <cmath>
#include <limits>
#include <iostream>
#include <map>
#include<tuple>
using namespace std;
#define INF 1LL<<62
#define MAX 100000
#define MOD 1000000007
typedef long long ll;
typedef pair<int,int> P;
//typedef pair<pair<int,int>,int> p;
#define bit(n,k) ((n>>k)&1) /*nのk bit目*/
#define rad_to_deg(rad) (((rad)/2/M_PI)*360)
struct edge{ll to,cost,val;};
template<class T,class U>bool chmin(T&a,const U&b){if(a<=b)return false;a=b;return true;}
template<class T,class U>bool chmax(T&a,const U&b){if(a>=b)return false;a=b;return true;}
//__builtin_popcount(S);
//C.erase(unique(C.begin(),C.end()),C.end());

bool dp[110000];

int main(){
    int N,K;
    cin>>N>>K;
    vector<int> a(N);
    for(int i=0;i<N;i++) cin>>a[i];
    dp[0]=false;
    for(int i=1;i<=K;i++){
        bool flag=false;
        for(auto j:a){
            if(i-j<0) continue;
            if(dp[i-j]==false) flag=true;
        }
        if(flag) dp[i]=true;
    }
    if(dp[K]) cout<<"First"<<endl;
    else cout<<"Second"<<endl;
}


Measured memory_bytes: 384
#include "bits/stdc++.h"
using namespace std;

/* macro */
#define rep(i,a,b) for(int i=a;i<b;i++)
#define revrep(i,a,b) for(int i = a; i > b; i--)
#define int long long
#define exist(s,e) ((s).find(e)!=(s).end())
#define all(v) (v).begin(), (v).end()
#define each(s,itr) for(auto (itr) = s.begin(); (itr) != s.end(); (itr)++)
#define sum(v) accumulate(all(v), (0LL))
#define isin(a, b, c) (b <= a && a <= c)
#define println cout << "\n";
#define sz(v) (int)v.size()
#define bin(x) static_cast<bitset<16> >(x)


/* alias */
template<class T> using vec = vector<T>;
typedef vector<int> vi;
typedef pair<int, int> pi;
typedef tuple<int, int, int> ti;
typedef map<int, int> mi;
typedef set<int> si;


/* constant */
const int inf = 1LL << 62;
const int mod = 1e9 + 7;
const int dx[8]={1,0,-1,0,-1,1,-1,1};
const int dy[8]={0,1,0,-1,-1,-1,1,1};
const string alphabet = "abcdefghijklmnopqrstuvwxyz";

/* io_method */
int input(){int tmp;cin >> tmp;return tmp;}
string raw_input(){string tmp;cin >> tmp;return tmp;}
template<class T> void printx(T n){cout << n;}
template<class T, class U> void printx(pair<T, U> p){cout << "(" << p.first << "," << p.second << ")";}
template<class T, class U, class V> void printx(tuple<T, U, V> t){cout << "{" << get<0>(t) << "," << get<1>(t) <<"," << get<2>(t) << "}" << endl;}
template<class T> void printx(vector<T> v){cout << "{";rep(i,0,v.size()){printx(v[i]);if(i != v.size()-1)printx(",");}cout << "}";}
template<class T> void print(T n){printx(n);cout << endl;}
template<class T> void print(set<T> s){cout << "{";each(s, e){if(e != s.begin()) printx(",");printx(*e);}cout << "}" << endl;}
template<class T, class U> void print(map<T, U> mp){cout << "{";each(mp, e){cout << "(" << e -> first << "," << e -> second << ")";}cout << "}" << endl;}
template<class T> void printans(vec<T> v){rep(i,0,sz(v)){cout << v[i] << (i == sz(v) - 1 ? "" : " ");}cout << endl;}


/* general_method */
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; }
template<class T>T cut(T &a, int l, int r){return T(a.begin()+l, a.begin()+r);}


/* math_method */
int ceil(int a, int b){return a / b + (a % b > 0);}


/* main */

string s;
void in(){
  cin >> s;
}

void solve(){

  int ans = inf;
  int n = sz(s);
  int cnt = 0;
  rep(i,0,n){
    if(i % 2 == 0) cnt += s[i] == '0';
    else cnt += s[i] == '1';
  }

  chmin(ans, cnt);

  cnt = 0;

  rep(i,0,n){
    if(i % 2 == 1) cnt += s[i] == '0';
    else cnt += s[i] == '1';
  }

  chmin(ans, cnt);

  print(ans);


}

signed main(){

    cin.tie(0);
    ios::sync_with_stdio(false);
    in();
    solve();
    
}

Measured memory_bytes: 512
#!/usr/bin/env python3
k,q = map(int,input().split())
d = list(map(int,input().split()))
for _ in range(q):
    n,x,m = map(int,input().split())
    e = list(map(lambda x:(x-1)%m+1,d))
    s = sum(e)*((n-1)//k) + sum(e[:(n-1)%k])
    tmp = (s+x)//m - x//m
    print(n-1-tmp)

    
    


Measured memory_bytes: 67420
#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>

using namespace std;


struct Line {
    int length;
    int direction;

    Line(int _l, int _d) : length(_l), direction(_d) {}

    bool operator==(const Line& l) const {
        return length == l.length && direction == l.direction;
    }

    bool operator!=(const Line& l) const {
        return !(*this == l);
    }
};

struct Point {
    int x;
    int y;
    Point(int _x, int _y) : x(_x), y(_y) {}
};

using PolygonalLine = pair<vector<Line>, vector<Line>>;

PolygonalLine
converter(vector<Point> points) {
    vector<Line> lines, lines_back;
    for(int i = 0; i < points.size() - 1; ++i) {
        int dx = points[i+1].x - points[i].x;
        int dy = points[i+1].y - points[i].y;
        if(dx == 0) {
            if(dy > 0)      lines.emplace_back(dy, 1);
            else if(dy < 0) lines.emplace_back(-dy, 3);
        } else if(dy == 0) {
            if(dx > 0)      lines.emplace_back(dx, 0);
            else if(dx < 0) lines.emplace_back(-dx, 2);
        }
    }
    int rotate;
    rotate = 4 - lines[0].direction;
    for(int i = 0; i < lines.size(); i++) {
        lines[i].direction = (lines[i].direction + rotate) % 4;
    }
    for(int i = points.size() - 1; i > 0; --i) {
        int dx = points[i-1].x - points[i].x;
        int dy = points[i-1].y - points[i].y;
        if(dx == 0) {
            if(dy > 0)      lines_back.emplace_back(dy, 1);
            else if(dy < 0) lines_back.emplace_back(-dy, 3);
        } else if(dy == 0) {
            if(dx > 0)      lines_back.emplace_back(dx, 0);
            else if(dx < 0) lines_back.emplace_back(-dx, 2);
        }
    }
    rotate = 4 - lines_back[0].direction;
    for(int i = 0; i < lines_back.size(); i++) {
        lines_back[i].direction = (lines_back[i].direction + rotate) % 4;
    }
    return make_pair(lines, lines_back);
}

int main() {
    while(true) {
        int n; cin >> n;
        if(n == 0) break;
        vector<PolygonalLine> plines;
        for(int i = 0; i <= n; ++i) {
            int m; cin >> m;
            vector<Point> points;
            for(int j = 0; j < m; ++j) {
                int x, y;
                cin >> x >> y;
                points.emplace_back(x, y);
            }
            plines.emplace_back(converter(points));
        }
        for(int i = 1; i <= n; ++i) {
            if(
                (plines[0].first == plines[i].first && plines[0].second == plines[i].second)
                || (plines[0].second == plines[i].first && plines[0].first == plines[i].second)
            )
            cout << i << endl;
        }
        cout << "+++++" << endl;
    }
}
// [Problem] Polygonal Line Search
// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=1136&lang=jp



Measured memory_bytes: 3104
N,K = (int(x) for x in input().split())
A_arr = [int(x) for x in input().split()]

def xxor(X):
    ans = 0
    for A in A_arr:
        ans += X ^ A
    return ans

mi_arr = [0]*40
xxor_0 = xxor(0)
for i in range(40):
    x = 1 << i
    if xxor_0 < xxor(x):
        mi_arr[i] = 1

x_max = xxor(K)
K_i_max = [0]*40
for i in range(40):
    K_i = (K >> i) % 2
    if K_i == 0:
        continue

    mi_k_arr = [x for x in mi_arr]
    mi_k_arr[i] = 0
    for j in range(i+1, 40):
        K_j = (K >> j) % 2
        mi_k_arr[j] = K_j
    xi_max = 0
    for i in reversed(range(40)):
        xi_max = xi_max << 1
        xi_max += mi_k_arr[i]

    x_max = max(x_max, xxor(xi_max))

print(x_max)


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

int main()
{
    int A, B;
    cin >> A >> B;

    int cnt = 0;
    for (int i = A; i <= B; i++)
    {
        int a, b, c, d;
        a = i / 10000;
        b = (i / 1000) % 10;
        c = (i % 100) / 10;
        d = i % 10;
        if (a == d && b == c)
        {
            cnt++;
        }
    }

    cout << cnt;
}

Measured memory_bytes: 3564