akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <map>

using namespace std;

int main() {
    int N, M;
    int h[1501], w[1501];

    while (true) {
        cin >> N >> M;

        if (!N && !M) { break; }

        for (int i = 0; i < N; i++) { cin >> h[i]; }
        for (int i = 0; i < M; i++) { cin >> w[i]; }

        map<int, int> mp;

        for (int i = 0; i < N; i++) {
            int tmp = 0;
            for (int j = i; j < N; j++) {
                tmp += h[j];
                if (mp.find(tmp) == mp.end()) {
                    mp[tmp] = 1;
                } else {
                    mp[tmp]++;
                }
            }
        }

        int ans = 0;

        for (int i = 0; i < M; i++) {
            int tmp = 0;
            for (int j = i; j < M; j++) {
                tmp += w[j];
                if (mp.find(tmp) != mp.end()) { ans += mp[tmp]; }
            }
        }
        cout << ans << endl;
    }
    return 0;
}



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

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

	int n, r;
	cin >> n >> r;
	int ans;
	if(n >= 10) {
		ans = r;
	}else {
		ans = r + (10 - n) * 100;
	}
	cout << ans << endl; 
}

Measured memory_bytes: 256
#define	_USE_MATH_DEFINES
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <vector>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cfloat>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <string>
#include <set>
#include <complex>
#define  rep(i,n) for(int i=0;i<(n);i++)
#define  REP(i,n) for(int i=1;i<(n);i++)
#define  rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define  VI	vector<int>
#define	 VS vector<string>
#define  all(a) (a).begin(),(a).end()
#define  debug(x) cout<<#x<<": "<<x<<endl

using namespace std;
int main(){
	
	rep(i,1000){
		string s;
		bool f=false;
		cin>>s;
		rep(j,s.size()-1){
			if(s[j]=='A'){
				if(s[j+1]!='B'&&s[j+1]!='D'){
					f=true;
					break;
				}
			}
			else if(s[j]=='B'){
				if(s[j+1]!='A'&&s[j+1]!='C'&&s[j+1]!='E'){
					f=true;
					break;
				}
			}
				else if(s[j]=='C'){
				if(s[j+1]!='B'&&s[j+1]!='F'){
					f=true;
					break;
				}
				}
				else if(s[j]=='D'){
				if(s[j+1]!='A'&&s[j+1]!='E'&&s[j+1]!='G'){
					f=true;
					break;
				}
				}
				else if(s[j]=='E'){
				if(s[j+1]!='B'&&s[j+1]!='D'&&s[j+1]!='F'&&s[j+1]!='H'){
					f=true;
					break;
				}
				}
				else if(s[j]=='F'){
				if(s[j+1]!='C'&&s[j+1]!='E'&&s[j+1]!='I'){
					f=true;
					break;
				}
				}
				else if(s[j]=='G'){
				if(s[j+1]!='D'&&s[j+1]!='H'){
					f=true;
					break;
				}
				}
				else if(s[j]=='H'){
				if(s[j+1]!='E'&&s[j+1]!='G'&&s[j+1]!='I'){
					f=true;
					break;
				}
				}
				else if(s[j]=='I'){
				if(s[j+1]!='H'&&s[j+1]!='F'){
					f=true;
					break;
				}
			}
				
		}
		if(!f)
		cout<<s<<endl;
	}
}

Measured memory_bytes: 1184
#include <bits/stdc++.h>
#pragma GCC optimize ("O3")
#define int long long
using namespace std;

const int INF = 1e9;

int knappsack(int budget, vector<pair<int, int>> items) { //{weight, value}
    int n = items.size();
    vector <vector<int>> dp(n + 1, vector <int> (budget + 1));
    
    for(int i = 1; i <= n; i++) {
        int w = items[i - 1].first;
        for(int j = 0; j <= budget; j++) {
            if(w <= j) {
                dp[i][j] = max(items[i - 1].second + dp[i - 1][j - w], dp[i - 1][j]);
            }
            else {
                dp[i][j] = dp[i - 1][j];
            }
        }
    }
    
    return dp[n][budget];
}

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

    int n, budget;
    cin >> n >> budget;
    vector <pair<int, int>> items(n);
    for(auto &x : items) {
        int w, v;
        cin >> w >> v;
        x = {w, v};
    }

    cout << knappsack(budget, items) << "\n";
}

Measured memory_bytes: 83032
#include <algorithm>
#include <bitset>
#include <cassert>
#include <chrono>
#include <climits>
#include <cmath>
#include <complex>
#include <cstring>
#include <deque>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <cstdint>
using namespace std;
typedef long long ll;
#define MP make_pair
#define PB push_back
#define inf 1000000007
#define mod 1000000007
#define rep(i,n) for(int i = 0; i < (int)(n); ++i)

int main(){
    int a,b,c,d;
    cin >> a >> b >> c >> d;
    if(b>d){
        cout << 1 << endl;
    }else{
        cout << 0 << endl;
    }
    return 0;
}

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

using namespace std;

typedef long long lld;

lld arr[4];
lld cost[4];
lld N;

int main(){
    for(int i=0; i<4; i++)
        cin >> arr[i];

    cin >> N;

    cost[0] = N * 4 * arr[0];
    cost[1] = N * 2 * arr[1];
    cost[2] = N * 1 * arr[2];
    cost[3] = N / 2 * arr[3];

    if( N % 2 == 1 ){
        lld a = arr[0] * 4;
        lld b = arr[1] * 2;
        lld c = arr[2];

        cost[3] += min(a, min(b, c));
    }

    cout << min( min(cost[0], cost[1]), min(cost[2], cost[3]) );
}

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

int main() {
  int N, b = 10000000;
  cin >> N;
  for ( int i = 0; i < N; i++) {
    int a, j = 0;
    cin >> a;
    for (; a % 2 == 0; j++) {
      a = a / 2;
    }
    if (j < b) b = j;
  }
  cout << b << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define in(s) ll s; cin>>s
#define pr(r) cout<<r<<endl
#define prr(m,n) cout<<m<<" "<<n<<endl
#define prarr(a,i,n) fab(j,i,n) cout<<a[j]<<" "
#define wh(t) ll t; cin>>t; while(t--)
#define sz(u) u.size()
#define all(v) v.begin(),v.end()
#define arr(a,n) vl a(n + 1, 0); fab(i,0,n) cin>>a[i]
#define prs(u) cout<<u<<" "
#define fab(i,a,b) for(ll i=a;i<b;i++)
#define fba(i,b,a) for(ll i=b;i>=a;i--)
#define sup ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define endl "\n"
#define ll long long int
#define vl vector<ll>
#define vpl vector<pair<ll,ll>>
#define pl pair<ll,ll>
#define pll pair<ll,pl>
#define vvl vector<vl>
#define mxe(x,n) *max_element(x,x+n)
#define mne(x,n) *min_element(x,x+n)
#define mp make_pair
#define pb push_back
#define fs first
#define sd second
#define fr front()
#define bk back()
#define rr return
const ll N =(ll)3e5;
const ll inf =(ll)1e18 + 7;
const ll mod =(ll)1e9 + 7;
const ll MX = (ll)1e9 + 7;
const ll MAX = (ll)1e12 + 7;
 
bool rsort1(const pair<ll,ll> &a,const pair<ll,ll> &b) { return (a.first > b.first);}
bool rsort2(const pair<ll,ll> &a,const pair<ll,ll> &b) { return (a.second>b.second);}
bool sort2(const pair<ll,ll> &a,const pair<ll,ll> &b){ return (a.second < b.second);}

void add(ll &x, ll y){
    x = ((x % mod) + (y % mod)) % mod;
}

void mul(ll &x, ll y){
    x = ((x % mod) * (y % mod)) % mod;
}
 
bool isPrime(ll p)
{
    for(ll i = 2;i * i <= p; i++)
        if(p % i == 0)
            rr false;
    rr true;
}
 
void sieve(ll n,vl &v)
{
    v.pb(2);
    bool prime[n + 1];
    memset(prime, true, sizeof(prime));
    for(ll i = 3;i * i <= n; i += 2)
        if(prime[i])
            for(ll j = i; j * i <= n; j += 2)
                prime[j * i] = false;
        
    for(ll i = 3; i <= n; i += 2)
        if(prime[i])
            v.pb(i);
}

ll phi(ll n)
{
    ll result = n;
    for(ll p = 2; p * p <= n; p++)
    {
        if(n % p == 0)
        {
            while(n % p == 0)
                n /= p;
            result -= result/p;
        }
    }

    if(n > 1)
        result -= result/n;
    return result;
}

ll nCr(ll n, ll k) 
{ 
    vl C(k + 1, 0); 
    ll i, j; 
    C[0] = 1; 
    for (i = 1; i <= n; i++) { 
        for (j = min(i, k); j > 0; j--) { 
            add(C[j], C[j - 1]); 
        } 
    }
    return C[k] % mod; 
}

string s;
ll dp[105][3][2];
ll last, n;

ll magic(ll pos, ll k, ll prev) {
    if(k == n)
        return 1;
    if(pos == last)
        return 0;
    ll &res = dp[pos][k][prev];
    if(res != -1) {
        return res;
    }
    else {
        ll digit = s[pos] - '0';
        res = magic(pos + 1, k, prev || digit > 0);
        if(prev) {
            res += magic(pos + 1, k + 1, 1) * 9;
        }
        else if(digit) {
            res += magic(pos + 1, k + 1, 1) * (digit - 1) + magic(pos + 1, k + 1, 0);
        }
        return res;
    }
}

int main()
{
	sup;
    
    cin >> s;
    cin >> n;
    ll ans = 0;
    last = s.size();
    memset(dp, -1, sizeof(dp));
    ans = magic(0, 0, 0);
    pr(ans);
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String args[]){
	  	Scanner scanner = new Scanner(System.in);
		int i = 0;
		int a;
		int b;
 		
		while(true){
			a = scanner.nextInt();
			b = scanner.nextInt();
			
			if(a == 0)
				if(b == 0)
					break;
			
			if(a <= b)
			    System.out.println(a + " " + b);
			else
			    System.out.println(b + " " + a);
        }
		scanner.close();
    }
}


Measured memory_bytes: 35884
S = input()[::-1]
ans = 0
dp = [0] * 2019
dp[0] = 1
val = ''
m = 0
x_10 = 1
for s in S:
    m = (m + int(s) * x_10) % 2019
    dp[m] += 1
    x_10 = (x_10 * 10) % 2019
for i in dp:
    ans += i * (i-1) // 2
print(ans)


Measured memory_bytes: 9392
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
#include<sstream>
using namespace std;
typedef  long long int lint;
typedef pair<int, int> P;
typedef pair<lint, lint> LLP;
typedef pair<char, char>CP;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define sort(v) sort((v).begin(), (v).end())
#define reverse(v) reverse((v).begin(), (v).end())
#define upper(v,hoge) upper_bound(v.begin(),v.end(),hoge)
#define lower(v,hoge) lower_bound(v.begin(),v.end(),hoge)
#define llower(v,hoge) *lower_bound(v.begin(), v.end(), hoge)
#define lupper(v,hoge) *upper_bound(v.begin(), v.end(), hoge)

const lint MOD = pow(10, 9) + 7;

lint gcd(lint a, lint b) {
	//aとbの最大公約数を返す
	if (a < b)swap(a, b);
	if (a % b == 0)return b;
	return gcd(a % b, b);
}

lint lcm(lint a, lint b) {
	//aとbの最小公倍数を返す
	return a / gcd(a, b) * b;
}

/*
vector<char>al(26);
al = {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
vector<char>AL(26);
AL = {'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
vector<char>NUM(10);
	NUM = { '0','1','2' ,'3' ,'4' ,'5' ,'6' ,'7' ,'8' ,'9' };
*/


int main() {
	int s;
	cin >> s;
	vector<int>cnt(1000000);
	int ans = 0;
	while (1) {
		cnt[s-1]++;
		if (cnt[s - 1] == 2) {
			cout << ans+1 << endl;
			return 0;
		}
		if (s % 2 == 0) {
			s /= 2;
		}
		else {
			s = 3 * s + 1;
		}
		ans++;
	}
}


Measured memory_bytes: 4096
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define rep2(i,n) for(int i=0;i<=n;i++)
#define repr(i,a,n) for(int i=a;i<n;i++)
#define all(a) a.begin(),a.end()
#define P pair<long long,long long>
#define uni(e) e.erase(unique(e.begin(),e.end()),e.end())
#define double long double
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
int INF=1e10;
int MOD=1e9+7;
struct Union{
  vector<int> par;
  Union(int n){
	par= vector<int>(n, -1);
  }
  int find(int x){
    if(par[x]<0)
      return x;
    else
      return par[x]=find(par[x]);
  }
  bool same(int a,int b){
    return find(a)==find(b);
  }
  int Size(int a){
    return -par[find(a)];
  }
  void unite(int a,int b){
    a=find(a);
    b=find(b);
    if(a==b)
      return;
    if(Size(b)>Size(a))
      swap<int>(a,b);
    par[a]+=par[b];
    par[b]=a;
  }
  int much(int a){
  vector<int> e(a);
  rep(i,a)
  e[i]=find(i);
  sort(all(e)); 
  e.erase(unique(all(e)),e.end());
  return e.size();
  }
};
signed main(){
int a,b;
cin>>a>>b;
 int c[b][3];
rep(i,b)rep(j,3)
cin>>c[i][j];
Union d(a);
rep(i,b)
  d.unite(c[i][0]-1,c[i][1]-1);
  cout<<d.much(a)<<endl;
}

Measured memory_bytes: 4224
#include <bits/stdc++.h> 
using namespace std;
 
struct Node {
    int name;
    int pen;
    int ac;
    vector<int> wa;
    Node(int n, int P) : name(n), pen(0), ac(0), wa(P, 0) { }

    void accept(int i, int t) {
        ac++;
        pen += wa[i] * 20 + t;
    }
 
    void wrong(int i) {
        wa[i]++;
    }
 
    bool operator <(const Node & n) const {
        if(ac != n.ac) return ac > n.ac;
        if(pen != n.pen) return pen < n.pen;
        return name > n.name;
    }
 
    bool same(const Node & n) const {
        return ac == n.ac && pen == n.pen;
    }
};
 
int main() {
    int M,T,P,R; 
    while(1){
        cin>>M>>T>>P>>R;
        if(M ==0 && T == 0 && P == 0 && R == 0) break;
        vector<Node> vec;
        for(int i = 0; i < T; i++) vec.push_back(Node(i+1, P));
        for(int i = 0; i < R; i++) {
            int m, t, p, j; cin >> m >> t >> p >> j;
            t--;
            p--;
            if(j == 0) {
                vec[t].accept(p, m);
            }
            else {
                vec[t].wrong(p);
            }
        }
        sort(vec.begin(), vec.end());
        cout << vec[0].name;
        for(int i = 1; i < (int)vec.size(); i++) {
            if(vec[i - 1].same(vec[i])) cout << "=";
            else cout << ",";
            cout << vec[i].name;
        }
        cout << endl;
    }
}



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

int main() {
	int n, k;
	scanf("%d %d", &n, &k);
	
	int arr[n+5];
	int dp[n+5];
	
	for(int i = 0;  i< n; i++) {
		scanf("%d", &arr[i]);
		dp[i] = 1e9;
	}
	
	dp[0] = 0;
	
	
	for(int i = 0; i < n; i++) {
		for(int j = 1; j <= min(k, i); j++) {
			dp[i] = min(dp[i], dp[i-j]+abs(arr[i-j]-arr[i]));
		}
	}
	
//	for(int i = 0; i < n; i++) {
//		printf("%d ", dp[i]);
//	}
//	printf("\n");
	
	printf("%d\n", dp[n-1]);
}

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

// x座標のmaxmin、y座標のmaxminを更新する

struct kaiga
{
    int num;
    int x;
    int y;
};

int max(int a, int b)
{
    if (a < b)
    {
        return b;
    }
    else
    {
        return a;
    }
}

int min(int a, int b)
{
    if (a < b)
    {
        return a;
    }
    else
    {
        return b;
    }
}

int main(void)
{
    int N, i;
    while (true)
    {
        int x_min = 0, x_max = 0, y_min = 0, y_max = 0;
        scanf("%d", &N);
        if (N == 0)
        {
            return 0;
        }
        int n[N], d[N];
        for (i = 0; i < N - 1; i++)
        {
            scanf("%d %d", &n[i], &d[i]);
        }
        struct kaiga sakuhin[N];
        sakuhin[0].num = 0;
        sakuhin[0].x = 0;
        sakuhin[0].y = 0;
        for (i = 1; i < N; i++)
        {
            sakuhin[i].num = i;
            if (d[i - 1] == 0)
            {
                sakuhin[i].x = sakuhin[n[i - 1]].x - 1;
                sakuhin[i].y = sakuhin[n[i - 1]].y;
            }
            else if (d[i - 1] == 1)
            {
                sakuhin[i].x = sakuhin[n[i - 1]].x;
                sakuhin[i].y = sakuhin[n[i - 1]].y - 1;
            }
            else if (d[i - 1] == 2)
            {
                sakuhin[i].x = sakuhin[n[i - 1]].x + 1;
                sakuhin[i].y = sakuhin[n[i - 1]].y;
            }
            else
            {
                sakuhin[i].x = sakuhin[n[i - 1]].x;
                sakuhin[i].y = sakuhin[n[i - 1]].y + 1;
            }
            x_max = max(x_max, sakuhin[i].x);
            x_min = min(x_min, sakuhin[i].x);
            y_max = max(y_max, sakuhin[i].y);
            y_min = min(y_min, sakuhin[i].y);
        }
        printf("%d %d\n", x_max - x_min + 1, y_max - y_min + 1);
    }
    return 0;
}


Measured memory_bytes: 2108
using System;
using System.Collections.Generic;

class main
{
	static void Main(string[] args)
	{
		int N = Int(Str());

		int AC = 0;
		int WA = 0;
		int TLE = 0;
		int RE = 0;

		string tmp;

		for(int i = 0;i < N; i++)
		{
			tmp = Str();

			if (tmp.Equals("AC"))
			{
				AC++;
			}else if (tmp.Equals("WA"))
			{
				WA++;
			}else if (tmp.Equals("TLE"))
			{
				TLE++;
			}else if (tmp.Equals("RE"))
			{
				RE++;
			}
		}
		Console.WriteLine("AC x " + AC);
		Console.WriteLine("WA x " + WA);
		Console.WriteLine("TLE x " + TLE);
		Console.WriteLine("RE x " + RE);
	}

	static string Str()
	{
		return Console.ReadLine().Trim();
	}
	static string[] StrArr()
	{
		return Console.ReadLine().Trim().Split(' ');
	}
	static int[] IntArr()
	{
		string[] strArr = StrArr();
		int len = strArr.Length;

		int[] intArr = new int[len];
		for(int i = 0;i < len; i++)
		{
			intArr[i] = Int(strArr[i]);
		}

		return intArr;
	}

	static int Int(string Str)
	{
		return int.Parse(Str);
	}
}



Measured memory_bytes: 30688
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,b;
    char c;
    cin>>a>>c>>b;
    switch(c)
    {
        case '+':
            cout<<a+b<<endl;
            break;
        default:
            cout<<a-b<<endl;
            break;
    }
    return 0;
}

Measured memory_bytes: 256
from collections import Counter
N = int(input())
S = input()
ls = [float('inf') for i in range(10)]
for i in range(10):
    if str(i) in S:
        ls[i] = S.index(str(i))
ans = 0
for i in range(10):
    if ls[i] != float('inf') and ls[i]+1 != N and ls[i]+2 != N:
        s = S[ls[i]+1:]
        ls2 = [float('inf') for i in range(10)]
        for j in range(10):
            if str(j) in s:
                ls2[j] = s.index(str(j))
        for j in range(10):
            if ls2[j] != float('inf') and ls2[j]+1 != len(s):
                a = s[ls2[j]+1:]
                d = Counter(a)
                ans += len(d)
print(ans)

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

#define ll long long
#define vecll vector<long long>
#define vec2ll vector<vector<long long>>
#define vecbool vector<bool>
#define vecpairll vector<pair<long long,long long>>
#define forll(s,a,b) for(long long s = a;s < b;s++)
#define forllde(s,a) for(long long s = a;s > 0;s--)


int main()
{
  ll l, r, minv=LLONG_MAX;
  cin >> l >> r;
  vecll a(2019, -1);

  forll(i, 0, min((ll)(2019 * 2), r-l+1)){
	if(a[(l + i) % 2019] == -1)
	  a[(l + i) % 2019] = 1;
	else
	  a[(l + i) % 2019] = 2;
  }
	
  forll(i, 0, 2019){
	if (a[i] == -1)
	  continue;
	forll(j, i, 2019){
	  if (a[j] == -1)
		continue;
	  if (a[j] != 2 && i == j)
		continue;
	  minv = min(minv, (ll)(i * j % 2019));
	}
  }
  cout << minv << endl;
}


Measured memory_bytes: 256
#include "cstdio"
#include "stack"

using namespace std;

int main()
{
    long long int in;
    scanf("%lld", &in);
    stack<char> st;
    while(in > 0)
    {
        st.push((in-1)%26+'a');
        in = (in-1)/26;
    }
    while(!st.empty())
    {
        putchar(st.top());
        st.pop();
    }
    putchar('\n');
    return 0;
}

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



int main(){
	int N=0,Y=0;
	cin>>N>>Y;
	int p,q,r;
	int endflg =0;
	
	if(Y == 10000*N){
		cout<<N<<" "<<0<<" "<<0;
	}else{
		for(int i=0;i<N+1;i++){
			p=i;//1万円札の数

			for(int j=0;j<N-p+1;j++){
				q=j;
				r=N-p-q;
				if(10000*p+5000*q+1000*r==Y){
					
					endflg = 1;
					break;
				}
			}
			if(endflg ==1)break;
		}
	

		if(endflg == 1){
			cout<<p<<" "<<q<<" "<<r;
		}else{
			cout<<-1<<" "<<-1<<" "<<-1;
		}
	}
	
	
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cctype>
#include <cstddef>
#include <vector>

enum {BUF_SIZE=(1<<17)};
char buf[BUF_SIZE|1], *pos, *endbuf;

inline int buffer() {
    size_t len=fread(buf, 1, BUF_SIZE, stdin);
    buf[len] = 0;
    endbuf = buf + len;
    pos = buf;
    return len;
}

inline int rebuffer() {
    ptrdiff_t left=endbuf-pos;
    if (buf+left >= pos)
        return *pos;

    memcpy(buf, pos, left);
    size_t len=fread(buf+left, 1, BUF_SIZE-left, stdin);
    endbuf = buf + (left+=len);
    *endbuf = 0;
    pos = buf;
    return len;
}

inline unsigned scan() {
    unsigned u=0;
    if (pos + 10 >= endbuf)
        rebuffer();

    do {
        u = u*10 + *pos-'0';
    } while (*++pos >= '0');

    ++pos;
    return u;
}

int main() {
    buffer();
    size_t N=scan();
    int M=scan();

    std::vector<int> B(N+1, 1), R(N+1);
    R[1] = 1;

    for (int i=0; i<M; ++i) {
        size_t x=scan(), y=scan();

        ++B[y];
        if (R[x])
            R[y] = 1;

        if (!--B[x])
            R[x] = 0;
    }

    int res=0;
    for (size_t i=1; i<=N; ++i)
        if (R[i])
            ++res;

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


Measured memory_bytes: 1152
#include <bits/stdc++.h>
 
using namespace std;
 
#define rep(i, n) for(int i=0; i<(n); i++)
#define FOR(i, m, n) for(int i=(m);i<(n);i++)
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define SORT(x) sort((x).begin(),(x).end())
#define RSORT(x) sort((x).rbegin(),(x).rend())
#define REVE(x) reverse((x).begin(),(x).end())
#define mp make_pair
#define pb push_back
#define chmax(x,y) x = max(x,y)

 
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<vector<int> > VVI;
typedef pair<int, int> PII;
typedef long long LL;
typedef vector<bool> VB;
typedef vector<LL> VL;
typedef vector<vector<long long>> VVLL;
typedef vector<set<int>> VSI;
const int MOD = 1e9+7;
const int INF = 1e9;
const LL LINF = 1e18;
int gcd(int a, int b)
{
   if (a%b == 0)
   {
       return(b);
   }
   else
   {
       return(gcd(b, a%b));
   }
}

int lcm(int a, int b)
{
   return a * b / gcd(a, b);
}
struct UnionFind {
    VI d;
    UnionFind(int n = 0): d(n,-1) {}
    int find(int x) {
        if(d[x] < 0) return x;
        return d[x] = find(d[x]);
    }
    bool unite(int x,int y) {
        x = find(x); y = find(y);
        if(x == y) return false;
        if(d[x] > d[y]) swap(x,y);
        d[x] += d[y];
        d[y] = x;
        return true;
    }
    bool same(int x,int y) { return find(x) == find(y); }
    int size(int x) { return -d[find(x)]; }
};
int deg[100005];
VI to[100005];

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

mint f(int n) {
    if(n == 0) return 1;
    mint x = f(n/2);
    x *= x;
    if(n%2 == 1) x *= 2;
    return x;
}

mint choose(int n,int a) {
    mint x = 1, y = 1;
    rep(i,a) {
        x *= n-i;
        y *= i+1;
    }
    return x/y;
}

int main() {
  int a,b,c;
  cin >> b >> c >> a;

  cout << a << " " << b << " " << c << endl;

    
}


Measured memory_bytes: 2560
using System;

namespace AtCoder
{
    class Program
    {
        static void Main()
        {
            string s = Console.ReadLine();
            string[] ans = new string[3];
            for (int i = 0; i < 8; i++)
            {
                int sum = int.Parse(s[0].ToString());
                for (int j = 0; j < 3; j++)
                {
                    if ((i >> j & 1) == 1)
                    {
                        sum += int.Parse(s[j + 1].ToString());
                        ans[j] = "+";
                    }
                    else
                    {
                        sum -= int.Parse(s[j + 1].ToString());
                        ans[j] = "-";
                    }
                }
                if (sum == 7) break;
            }
            Console.WriteLine(s[0] + ans[0] + s[1] + ans[1] + s[2] + ans[2] + s[3] + "=7");
        }
    }
}

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

#define rep(i, n) for(int i = 0; i<(n); i++)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
typedef long long ll;

int main() {
    ll N, M;
    cin >> N >> M;
    ll ans = 0;

    ll m = N * 2;
    chmin(m, M);
    ans += m / 2;
    M -= m;
    ans += M / 4;
    cout << ans << endl;
}

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

//#define int long long
#define DBG 1
#define dump(o) if(DBG){cerr<<#o<<" "<<o<<endl;}
#define dumpc(o) if(DBG){cerr<<#o; for(auto &e:(o))cerr<<" "<<e;cerr<<endl;}
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define each(it,c) for(auto it=(c).begin();it!=(c).end();it++)
#define all(c) c.begin(),c.end()
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9 + 7);

signed main() {
	int h, w;
	string s;
	vector<string>v;
	cin >> h >> w;
	rep(i, 0, h) {
		cin >> s;
		v.push_back(s);
		v.push_back(s);
	}
	rep(i, 0, 2 * h)cout << v[i] << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep0(i,n) for(ll (i) = 0; (i) < (n); ++(i))
#define rrep0(i,n) for(ll (i) = (n) - 1; (i) >= 0; --(i))
#define rep1(i,n) for(ll (i) = 1; (i) <= (n); ++(i))
#define rrep1(i,n) for(ll (i) = (n); (i) >= 1; --(i))
#define ll long long
#define mod (1000000007)
#define pf(x) cout << (x) << endl;
#define all(x) (x).begin(),(x).end()

ll gcd(ll a,ll b){
    if(b == 0) return a;
    return gcd(b,a%b);
}

ll lcm(ll a,ll b){
    ll g = gcd(a,b);
    return a / g * b;
}

ll factorial(ll n){
    ll t = 1;
    rep1(i, n)t *= i;
    return t;
}

ll combinations(ll n, ll k) {
    ll r = 1;
    rep1(i, k)r = r * n-- / i;
    return r;
}

int main()
{
    int a,b;
    cin >> a >> b;
    rep0(i, max(a,b))cout << min(a,b);
    return 0;
}


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

typedef long long ll;

int main(){
  string s;
  cin >> s;
  int t=0, u=0;
  for (int i = 0; i < s.size(); i++) {
    if (s.at(i)=='0') t++;
    if (s.at(i)=='1') u++;
  }
  cout << 2*min(t,u) << endl;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n, i, ans;

    cin >> n;
    for(i = 1; i <= n; ++i)
    {
        if(i * (i + 1) / 2 >= n)
            break;
    }
    cout << i;

return 0;
}


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

#define MATHPI acos(-1)

template<class T> void chmax(T &a, T b) {
    if (a < b) a = b;
}
template<class T> void chmin(T &a, T b) {
    if (b < a) a = b;
}

using Mat = vector<vector<ll>>;
using Column = vector<ll>;

int main(int argc, char const *argv[])
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    vector<int> v{1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
    int K;cin>>K;
    cout << v[K-1]<<"\n";

    return 0;
}

Measured memory_bytes: 256
n = gets.to_i
d = n.times.map{gets.split.map(&:to_i)}
ans = false
(n-2).times do |i|
    f = true
    3.times do |j|
        f = false if d[i+j][0] != d[i+j][1]
    end
    ans = true if f
end
puts (ans ? "Yes" : "No")

Measured memory_bytes: 14340
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define REP2(i, a, b) for (int i = (a); i < (int)(b); i++)
typedef vector<int> VI;
typedef vector<VI> VVI;

int Main(int N, string s)
{
    int ans = 1;
    REP2(i, 1, N) if(s[i-1] != s[i]) ans++;
    return ans;
}

int main(void){
    int N;
    cin >> N;
    string S;
    cin >> S;
    cout << Main(N, S) << endl;
    return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define ll long long int
#define yorn(f) cout<<((f)?"Yes":"No")<<endl;
#define YORN(f) cout<<((f)?"YES":"NO")<<endl;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define put(x) cout << x << endl;
#define println(x) cout << x << endl;
using namespace std;
int main()
{
    int n, m, c;
    cin >> n >> m >> c;
    vector<int> b(m);
    rep(i, m) cin >> b[i];
    vector<int> a(m);
    int cnt = 0;
    rep(j, n) {
        rep(i, m) cin >> a[i];
        int v = c;
        rep(i, m) {
            v += a[i] * b[i];
        }
        if (v > 0) {
            cnt++;
        }
    }
    put(cnt)

    return 0;
}

Measured memory_bytes: 3608
gets;
s,*f='? '+?0*200;
200.times{|i|
i.times{|j|
s[i+2]=s[j+2]=?1;
puts s;
s[i+2]=s[j+2]=?0;
f<<" (#{i},#{j})"
}
};$>.flush;
print ?!,*f.select{gets=="1
"}


Measured memory_bytes: 5328
import java.util.*;

public class Main {
  public static void main(String[] args) {
  	Scanner sc = new Scanner(System.in);
    String D_T_S [] = new String[3];
    String line = sc.nextLine();
    
    D_T_S = line.split(" ", 0);
    int D = Integer.parseInt(D_T_S[0]);
    int T = Integer.parseInt(D_T_S[1]);
    int S = Integer.parseInt(D_T_S[2]);
    
    if(D > T * S){
      System.out.println("No");
    }else{
      System.out.println("Yes");
    }
  }
}

Measured memory_bytes: 35668
#include <bits/stdc++.h>
#define ll long long int
using namespace std;

void code()
{
    ll n;
    cin>>n;
    bool flag=0;
    while(n>0)
    {
        if(n%10==7)
            flag=1;
        n/=10;
    }
    if(flag==1)
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;
}

int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    ll t=1;
    // cin>>t;
    while(t--)
    {
        code();
    }
}


Measured memory_bytes: 3652
#pragma target("avx")
#pragma optimize("O3")
#include<bits/stdc++.h>
using ll = int_fast64_t;
using P = std::pair<ll,ll>;
using PP = std::pair<ll,P>;
using V = std::vector<ll>;
template<typename T> using pq = std::priority_queue<T>;
template<typename T> using rpq = std::priority_queue<T, std::vector<T>, std::greater<T>>;

#define REP(i,b,e) for(ll i=b; i<e; i++)
#define ALL(vec) vec.begin(),vec.end()
#define PRINT(vec) printf("[ ");for(auto &i:vec)printf("%ld ",i);puts("]");
#define SCAN(vec) for(auto &i:vec)scanf("%ld",&i)
#define fi first
#define se second

const int MOD = 1e9+7;
const ll INF = 1e18;
int dx[] = {0, 1, 0, -1, 1, 1, -1, -1}, dy[] = {1, 0, -1, 0, 1, -1, -1, 1};

int main(){
	int n, m;
	scanf("%d %d", &n, &m);
	int s[m];
	char c[m];
	REP(i, 0, m){
		scanf("%d %c", &s[i], &c[i]);
		s[i]--;
	}

	REP(i, 0, 1000){
		std::string num = std::to_string(i);
		if(num.size()!=n) continue;

		bool ok = true;
		REP(j, 0, m){
			if(num[s[j]]!=c[j]) ok = false;
		}
		if(ok){
			printf("%ld\n", i);
			return 0;
		}
	}
	puts("-1");
	return 0;
}



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

using namespace std;

typedef long long ll;

const int INF = 1e9;
const ll LLINF = 1e18;
const ll MOD = (ll)1e9 + 7;

int main()
{
  string s; cin >> s;
  int n = s.size();
  bool first = true;
  if (n & 1) {
    first = s[0] != s[n - 1];
  }
  else {
    first = s[0] == s[n - 1];
  }
  printf("%s\n", first ? "First" : "Second");
  return 0;
}


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

int main() {
    
    long long x;
    cin >> x;
    
    if(x%11==0)cout << (x/11)*2 << endl;
    else if(x%11>6)cout << ((x+10)/11)*2 << endl;
    else cout << ((x+10)/11)*2 - 1 << endl;
}

Measured memory_bytes: 256
import java.util.*;
import java.io.*;
public class Main
{
    public static void main(String []args) throws IOException {
    	FastScanner in  = new FastScanner(System.in);
    	PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)), false);
    	solve(in, out);
    	in.close();
    	out.close();
    }
    static long gcd(long a, long b){ return (b==0) ? a : gcd(b, a%b); }
    static int gcd(int a, int b){ return (b==0) ? a : gcd(b, a%b); }
    static class FastScanner{
	BufferedReader reader;
	StringTokenizer st;
	FastScanner(InputStream stream){reader=new BufferedReader(new InputStreamReader(stream));st=null;}
	String next(){while(st == null || !st.hasMoreTokens()){try{String line = reader.readLine();if(line == null){return null;}
	     st = new StringTokenizer(line);}catch (Exception e){throw new RuntimeException();}}return st.nextToken();}
	String nextLine()  {String s=null;try{s=reader.readLine();}catch(IOException e){e.printStackTrace();}return s;}
	int    nextInt()   {return Integer.parseInt(next());}
	long   nextLong()  {return Long.parseLong(next());}
	double nextDouble(){return Double.parseDouble(next());}
	char   nextChar()  {return next().charAt(0);}
	int[]  nextIntArray(int n)         {int[] arr= new int[n];   int i=0;while(i<n){arr[i++]=nextInt();}  return arr;}
	long[] nextLongArray(int n)        {long[]arr= new long[n];  int i=0;while(i<n){arr[i++]=nextLong();} return arr;}
	int[]  nextIntArrayOneBased(int n) {int[] arr= new int[n+1]; int i=1;while(i<=n){arr[i++]=nextInt();} return arr;}
	long[] nextLongArrayOneBased(int n){long[]arr= new long[n+1];int i=1;while(i<=n){arr[i++]=nextLong();}return arr;}
	void   close(){try{reader.close();}catch(IOException e){e.printStackTrace();}}
    }
    
    /********* SOLUTION STARTS HERE ************/
    
    private static void solve(FastScanner in, PrintWriter out){
        int n = in.nextInt();
        int a[] = new int[n];
        int b[] = new int[n];
        for(int i=0;i<n;i++){
            a[i]=in.nextInt();
            b[i]=a[i];
        }
        Arrays.sort(b);
        int cnt=0;
        for(int i=0;i<n;i++) if(a[i]!=b[i]) cnt++;
        out.println(cnt<3?"YES":"NO");
    }
    /************* SOLUTION ENDS HERE **********/
}

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

int ri() {
	int n;
	scanf("%d", &n);
	return n;
}

int main() {
	int n = ri();
	int64_t res = 0;
	for (int i = 0; i < n; i++) res += ri() - i - 1;
	std::cout << res << std::endl;
	return 0;
}




Measured memory_bytes: 3248
#include <iostream>
using namespace std;
int main()
{
	int a, res[3] = {0}, i;
	for (i = 0; i < 10; i++)
	{
		cin >> a;
		if (a > res[0])
			res[2] = res[1], res[1] = res[0], res[0] = a;
		else if (a > res[1])
			res[2] = res[1], res[1] = a;
		else if (a > res[2])
			res[2] = a;
	}
	cout << res[0] << endl << res[1] << endl << res[2] << endl;
}

Measured memory_bytes: 0
S = list(input())
K = int(input())

judge = 0
count = 1
for i in range(len(S)):
  if(count == K):
    judge = 1
    ans = S[i]
    break
    
  if(S[i] == '1'):
    count += 1
  else:
    judge = 1
    ans = S[i]
    break

if((count == len(S))and(judge == 0)):
  ans = '1'
print(ans)

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

int main(){
    int sum = 0,M,N;
    cin >> N >> M;
    vector<int>number_vote(N);
    for(int i=0;i<N;i++){
        cin >> number_vote.at(i);
        sum += number_vote.at(i);
    }
    sort(number_vote.begin(), number_vote.end());
    reverse(number_vote.begin(),number_vote.end());

    bool popular_flg = true;
    int least_number;
    if(sum % (4*M)==0){
        least_number = sum/(4*M);
    }
    else{
        least_number = sum/(4*M)+1;
    }
    for(int i=0;i<M;i++){
        if(number_vote.at(i)<least_number){
            popular_flg = false;
            break;
        }
    }
    if(popular_flg==true){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }


}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
#define fastio() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define pb push_back
#define F first
#define S second
#define nl cout<<"\n"
//cout<<fixed<<setprecision(11);
const ll MOD=1e9+7;
const ll ARR_MAX = 1e5+9;
const ll VAL_MAX = 1e5+1;
const ll INF=1e14;


ll mult(ll x,ll y,ll m=MOD){
    return (x*y)%m;
}

ll expo(ll base,ll n,ll m=MOD){
    ll res=1;
    while(n>0){
        if(n%2){
            res=mult(res,base,m);
            n--;
        }
        base=mult(base,base,m);
        n/=2;
    }
    return res;
}

ll inv_mod(ll x,ll m=MOD){
    return expo(x,m-2,m);
}


ll dvd(ll x,ll y,ll m=MOD){
    ll res=mult(x,inv_mod(y,m),m);
    return res;
}

ll fact[ARR_MAX];

void constr_fact(ll N){
    fact[0]=1;
    for(int i=1;i<=N;i++){
        fact[i]=mult(fact[i-1],i);
    }
}

ll comb(ll n,ll k){
    if(k>n){
        return 0;
    }
    ll ans=fact[n];
    ans=dvd(ans,fact[k]);
    ans=dvd(ans,fact[n-k]);
    return ans;
}


void solve(){
    int n,k;
    cin>>n>>k;
    ll a[n];
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    sort(a,a+n);
    ll ans=0;
    for(int i=0;i<n;i++){
        ans+= mult((comb(i,k-1)-comb(n-i-1,k-1))%MOD,a[i]);
        ans%=MOD;ans+=MOD;
        ans%=MOD;
    }
    cout<<ans,nl;
}

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

Measured memory_bytes: 1792
#include <stdio.h>
#include <map>
#include <tuple>
#include <vector>
using namespace std;

typedef struct {
	int f;         // ノード1
	int s;        // ノード2
	int c;       // 色
} fcs;

fcs out[100000];               // 辺情報
vector<fcs*> nodes[100000];   // ノード情報（辺情報への参照リスト）
int maxCol = 0;              // 何色使ったか記録用

int main() {
	int N;                // ノード数
	scanf("%d", &N) + 1;
	int in1, in2;       // 入力受付用
	for (int i = 0; i < N-1; i++) {
		scanf("%d %d", &in1, &in2) + 1;// 2ノードの入力を受ける
		in1--;
		in2--;

		out[i].f = in1;      // 辺情報を
		out[i].s = in2;     // 作成する
		out[i].c = 0;      // 色の初期値は0
		nodes[in1].push_back(&out[i]); // 辺情報へのポインタを
		nodes[in2].push_back(&out[i]);// 両端のノードに持たせる
	}

	// ノードでループ
	for (int i = 0; i < N; i++) {
		map<int, int> usedC; // 使用済み色リスト

		// 使用済み色リストを作成
		auto itr = nodes[i].begin();
		auto e = nodes[i].end();
		for (; itr != e; itr++) {
			usedC[(*itr)->c] = 1;
		}
		
		int kohoC = 1; // 候補の色

		// ノードの持つ辺情報でループ
		itr = nodes[i].begin();
		for (; itr != e; itr++) {
			// 色付け済みの辺はスキップ
			if ((*itr)->c != 0) continue;

			// 未使用の色を探す
			while (usedC.count(kohoC) != 0) kohoC++;

			// 辺情報の色を更新する
			(*itr)->c = kohoC;
			usedC[kohoC] = 1;
		}

		// いっぱい色を使ったらmaxを更新する
		if (maxCol < kohoC) maxCol = kohoC;
	}

	printf("%d\n", maxCol);
	for (int i = 0; i < N-1; i++) {
		printf("%d\n", out[i].c);
	}

	return 0;
}


Measured memory_bytes: 7928
#include <iostream>
#include <vector>
#include <set>
#include <string>
#include <algorithm>
#include <math.h>
typedef long long ll;
using namespace std;

int main()
{
	int a, b;
	cin >> a >> b;
	for (int i = 0; i < 16; i++)
	{
		if (i % 2 == 0)
		{
			if(a > 0){
				a--;
			}
		}
		else
		{
			if (b > 0) {
				b--;
			}
		}
	}

	if (a > 0 || b > 0) cout << ":(";
	else cout << "Yay!";
}

Measured memory_bytes: 256
// template
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<long long, long long> LP;
#define INF 999999999
#define MOD 1000000007
#define REP(i, n) for(ll i = 0, i##_len = (n); i < i##_len; i++)
#define REP_AB(i, a, b) for (ll i = ll(a); i < ll(b); i++)
#define REP_IN(i, n, x) for (ll i = 0; i < n; i++)in>>x;
#define REP_OUT(i, n, x) for (ll i = 0; i < n; i++)out<<x<<endl;
#define ALL(v) v.begin(), v.end()
#define SORT(v) sort(ALL(v))
#define UNIQUE(v) sort(ALL(v));v.erase(unique(ALL(v)), v.end());
#define SIZE(x) ((ll)(x).size())
#define REVERSE(v) reverse(ALL(v))
// true / false
#define BIN_SEARCH(v, a) binary_search(ALL(v), a)
// index
#define BIN_LEFT(v, a) (lower_bound(ALL(v), a) - v.begin())
#define BIN_RIGHT(v, a) (upper_bound(ALL(v), a) - v.begin())
#define BIN_INSERT(v, a) (v.insert(v.begin() + BIN_LEFT(v, a), a))
#define DEL(v, i) v.erase(v.begin() + i)
#define INSERT(v, i, a) v.insert(v.begin() + i, a)
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return (a / gcd(a, b)) * b;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
#define out cout
#define in cin
#define endl '\n'
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 end
 
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    // ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
    //vector<ll> X(N);
    //string s;
    //in >> s;
    //vector<string> s;
    //s.resize(N);
    ll A,B,N;
    in >> A>>B>>N;

    
    ll ans = 0,tmp=0;
    ll i=0,c=0;
    /*
    for(i=N,c=0;i>0 || c!=100000000 ; i--,c++ ){
        tmp = floor(A*i/B)-A*floor(i/B);
        if(ans<tmp)ans=tmp;
    }
    */
   if(B>N){
       ans=floor(A*N/B)-A*floor(N/B);
   }else{
        ans=floor(A*(B-1)/B)-A*floor((B-1)/B);
   }
    
    
    out << ans << endl; 
    
    
}

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

int main() {
  int a,b,n;
  cin >> a >> b;
  n=0;

  for (int i=a; i<=b; i++){
      if (i%10==i/10000%10 && i/10%10==i/1000%10)
        n++;
    if  (i==b)
      cout << n << endl;
  }
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] arg) {
		Scanner in = new Scanner(System.in);
		char[][] numbers = new char[100][];
		int[] eqVal = new int[100];
		for (int n = in.nextInt(); n > 0; n = in.nextInt()) {
			int m = in.nextInt();
			for (int i = 0; i < n; i++) {
				numbers[i] = in.next().toCharArray();
				eqVal[i] = in.nextInt();
			}
			int val = 0;
			for (int i = 0; i < m; i++) {
				char[] hNum = in.next().toCharArray();
				for (int index = 0; index < n; index++) {
					boolean isMuch = true;
					for (int keta = 0; keta < 8; keta++) {
						if (numbers[index][keta] != '*'
								&& hNum[keta] != numbers[index][keta]) {
							isMuch = false;
							break;
						}
					}
					if (isMuch) {
						val += eqVal[index];
						break;
					}
				}
			}
			System.out.println(val);
		}
	}
}

Measured memory_bytes: 35508
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i=0; i<(int)(n); i++)
#define intt int64_t
#define all(vec) vec.begin(), vec.end()
#define MOD 1000000007

int main() {
    int n;
    scanf("%d", &n);
    vector<int> cost(n);
    rep(i,n) scanf("%d", &cost.at(i));
    sort(all(cost));
    int ans = 0;
    rep(i,n) {
        if (i != n-1) ans += cost.at(i);
        else ans += cost.at(i)/2;
    }
    printf("%d\n", ans);
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void) { 
	int n, i;
	for (i = 0; i < 10000; i++) {
		scanf("%d", &n);
		if (n == 0) {
			break;
		}
		printf("Case %d: %d\n", i + 1, n);
	}
	return 0;
}


Measured memory_bytes: 2016
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;
using namespace std;
struct Fast { Fast(){ std::cin.tie(0); ios::sync_with_stdio(false); } } fast;

template<typename ...Ts>
void show(Ts... ts){
  cout<<"#:";
  auto print=[](auto v){cout<<v<<" ";};
  initializer_list<int>{(void(print(ts)),0)...};
  cout<<endl;
}

string solve(int n, int k, string s){
    vector<string> w;
    
    REP(i,1,k+1){
        rep(j,n-i+1){
            w.push_back(s.substr(j,i));
        }
    }
    sort(all(w));
    unique(all(w));
    return w[k-1];
}

int main(void){
    int k;
    string s,ans;
    cin>>s;
    vector<string> w;
    cin>>k;
    int n=s.size();
    
    if(n<10){
        rep(i,n){
            REP(j,1,n-i+1){
                w.push_back(s.substr(i,j));
            }
        }
        sort(all(w));
        unique(all(w));
        ans=w[k-1];
    }else{
        ans=solve(n,k,s);
    }
    
    cout<<ans;
}



Measured memory_bytes: 1660
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication4
{
    class Program
    {
        static void Main(string[] args)
        {
            String[] xArray = Console.ReadLine().Split(' ');
            int a = int.Parse(xArray[0]);
            int b = int.Parse(xArray[1]);
            int c = int.Parse(xArray[2]);

            if( a < b && b < c )
            {
                Console.WriteLine("Yes");

            }
            else
            {
                Console.WriteLine("No");
            }
        }
    }
}

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

#define int long long

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

#define ln << "\n"
#define sp << " "

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

    int N, K; cin >> N >> K;
    // vector<int> A(N); times(N, i) cin >> A[i];

    cout << (N - 2) / (K-1) + 1 ln;

    return 0;
}



Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define pb push_back
#define pii pair<long long,long long>
#define endl '\n'
#define N 300001
int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int n; cin>>n;
    unordered_map<int,int> mp; int x; int ans=0;
    for(int i=1;i<=n;i++)
    {
        cin>>x;
        if(mp.count(i-x))
        ans+=mp[i-x];
        mp[i+x]++;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 11228
#include <iostream>
#include <vector>
#include <unordered_map>

class UnionFind{ //連結判定
private:
    std::vector<int> parent; //parent[i] = parent of node i
    std::vector<int> rank;
    std::vector<int> size;
public:
    //constructor
    UnionFind(int N){
        for(int i=0; i<N; i++) parent.push_back(i); //parent = [0,1,..,N-1]
        for(int i=0; i<N; i++) rank.push_back(0); //rank = [0,0,..,0]
        for(int i=0; i<N; i++) size.push_back(1);
    }
    //initialize
    void init(int N){
        parent.clear();
        rank.clear();
        size.clear();
        for(int i=0; i<N; i++) parent.push_back(i); //parent = [0,1,..,N-1]
        for(int i=0; i<N; i++) rank.push_back(0); //rank = [0,0,..,0]
        for(int i=0; i<N; i++) size.push_back(1);
    }
    int root(int a){
        if(parent[a] == a) return a;
        return parent[a] = root(parent[a]); //親が自分自身になるまで再帰を呼び出す & 経路圧縮 
    }
    void unite(int a, int b){
        int rootA = root(a);
        int rootB = root(b);
        if(rootA == rootB) return; //ノードa, bがすでに連結しているとき
        //次数の大きい方を親として連結
        if(rank[rootA] < rank[rootB]){
            size[rootB] += size[rootA];
            parent[rootA] = rootB;
        }
        else{
            size[rootA] += size[rootB];
            parent[rootB] = rootA;
            if(rank[rootA] == rank[rootB]) rank[rootA]++;
        }
    }
    bool same(int a, int b){
        return root(a) == root(b); //ノードa, bが同じ木に属するかどうか
    }
    int get_size(int a){
        return size[root(a)];
    }
};

int main()
{
    int N, M;
    scanf(" %d %d", &N, &M);
    std::vector<int> X(M), Y(M), Z(M);
    for(int i=0; i<M; i++) scanf(" %d %d %d", &X[i], &Y[i], &Z[i]);

    UnionFind uf(N);
    for(int i=0; i<M; i++) uf.unite(X[i], Y[i]);
    int cost = 0;
    std::unordered_map<int, int> mp;
    for(int i=0; i<N; i++){
        if(mp.find(uf.root(i)) == mp.end()){
            mp[uf.root(i)]; cost++;
        }
    }
    std::cout << cost << std::endl;
}

Measured memory_bytes: 6672
h,w,a,b = map(int, input().split())
ans=[]
for i in range(h):
    if i<b:
        ans.append([0]*w)
    else:
        ans.append([1]*w)
for i in range(h):
    for j in range(w):
        if j<a:
            ans[i][j] = (ans[i][j] + 1)%2
for a in ans:
    print(*a,sep="")

Measured memory_bytes: 77916