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

int main() {
    int n;
    cin >> n;
    int sum = 0, temp = n;
    while (temp) {
        sum += temp % 10;
        temp /= 10;
    }
    int ans = sum;
    vector< unordered_set<int> > dict(1, unordered_set<int>({0}));
    for (int i = 1; i < sum; i++) {
        unordered_set<int> temp;
        for (const auto& iter : dict[i - 1]) {
            int cur = (iter + 1) % n;
            while (temp.find(cur) == temp.end()) {
                temp.insert(cur);
                cur = cur * 10 % n;
            }
        }
        if (temp.find(0) != temp.end()) { ans = i; break; }
        dict.push_back(temp);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 13988
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define Would
#define you
#define please

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


	int A, B, K;
	cin >> A >> B >> K;

	vector<int> kotae;
	rep1(i, 100) {
		if (A % i == 0 && B % i == 0) kotae.pb(i);
	}

	int size = kotae.size();

	co(kotae[size - K]);
	
	Would you please 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();
        String NS = String.valueOf(N);
        int l = NS.length();
        int S = 0;
        String s = " ";

        for(int i=0; i<l; i++){
            s = String.valueOf(NS.charAt(i));
            S += Integer.parseInt(s);
        }
        if(N%S==0){
            System.out.println("Yes");
        }
        else{
            System.out.println("No");
        }
    }
}

Measured memory_bytes: 21972
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int x,y;
  cin >> x >> y;
  
  if((y > 4*x) || (y < 2*x) ){
     cout << "No" << endl;
     return 0;
  }
  
  
  if((y - 2*x)%2 == 0){
     cout << "Yes" << endl;
  }else{
     cout << "No" << endl; 
  }

}

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

using namespace std;
using ll =long long;
using vi = vector<int>; 
using vvi = vector<vi>; 
using vl = vector<ll>; 
using vvl = vector<vl>; 
using vs = vector<string>;
using vvs = vector<vs>; 
using vc = vector<char>;
using vvc = vector<vc>; 
using vb = vector<bool>;
using vvb = vector<vb>; 

#define rep(i,n) ;for( int i =0; i < n ; i ++)
#define all(a) a.begin(),a.end()
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define f(i,a,b) for(int i=a;i<b;i++)
#define pri(a)  printf("%.14lf\n",a);
#define MOD 1000000007
bool is_int_lround(double x){
  return std::lround(x)==x;
}
ll keta(ll x){
  ll n=0;
  while(x>0){
    x /=10 ;
    n ++;
  }
  return n;
}

ll conbi(int n,int m){
  
  cin>>n>>m;
  vector<ll> a(100);
  a[0] =1;
  for(int i=0;i<14;i++){
    a[i+1]=a[i]*(i+1);
  }
  return a[n] /(a[m] *a[n-m]);
}

long long modpow(long long a, long long n, long long mod) {
    long long res = 1;//繰り返し二乗法
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
ll kaijoMOD(ll x){
  ll z=1;
  if(x==0){
    return 1;
  }
  while(x>0){
    z *=x;
    z %=MOD;
    x--;
  }
  return z;
}
ll yakusu_num(ll n){
  vl yakusu(n+1,1);
  for(ll i=2;i*i<=n;i++){ 
    while(n%i==0){
      n /=i;
      yakusu[i]++;
    }
  }
  if(n!=1)yakusu[n]++;
  ll num=1;
  for(ll i=0;i<=n;i++){
    num*=yakusu[i];
  }
  return num;
}

int H,W;
vs s(50);
vi dv ={-1,0,1,0};vi du={0,-1,0,1};
int cnt=1;
int dfs(int u,int v){
  s[u][v]='.';
  
  rep(i,4){
   
      int nu =u +du[i],nv=v+dv[i];
      if(nu<0||nu>=H||nv<0||nv>=W)continue;
      if(s[nu][nv]=='.')continue;
      cnt ++;
      dfs(nu,nv);
    
  }
  return cnt;

}
int keta_wa(int x){
  int tot=0;
  while(x>0){
    tot +=x%10;
    x/=10;
  }
  return tot;
}

//vc alp ={'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'};
//vc Alp ={'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'};
//cout<<""<<endl;
int main(){
 int x;cin>>x;if(x<1200)cout<<"ABC";else cout<<"ARC";
  
}   





Measured memory_bytes: 256
require 'prime'

ub = 10 ** 5
ary = Array.new(ub + 1, 0)

1.upto(ub) do |i|
    if i.prime? && ((i + 1) / 2).prime?
        ary[i] = ary[i - 1] + 1
    else
        ary[i] = ary[i - 1]
    end
end

gets.to_i.times do 
    l, r = gets.split.map(&:to_i)
    puts ary[r] - ary[l - 1]
end

Measured memory_bytes: 3708
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cassert>
#include <climits>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <fstream>

using namespace std;
#define SZ(x) (int)(x).size()
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REPR(i,n) for(int i=(n)-1;i>=0;i--)
#define ALL(s) (s).begin(), (s).end()
#define so(V) sort(ALL(V))
#define rev(V) reverse(ALL(V))
#define uni(v) v.erase( unique(ALL(v)) , v.end());

typedef long long unsigned int llu;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vb;
const double EPS = 1e-9;
const int MOD = 1e9 + 7;
const int INF = (1 << 29);
const ll LINF = 1e18;
const double PI = acos(-1);

template<typename T>vector<T> make_v(size_t a) { return vector<T>(a); }
template<typename T, typename... Ts>auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...)); }
template<typename T, typename U, typename... V>
typename enable_if<is_same<T, U>::value != 0>::type
fill_v(U& u, const V... v) { u = U(v...); }
template<typename T, typename U, typename... V>
typename enable_if<is_same<T, U>::value == 0>::type
fill_v(U& u, const V... v) { for (auto& e : u) fill_v<T>(e, v...); }
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 (a > b) { a = b; return 1; } return 0; }
int H, W;
vector<vb> Map;
typedef pair<int, int> P;
typedef pair<int, P> PP;
int dx[] = { -1,0,0,1 };
int dy[] = { 0,-1,1,0 };

bool check(int y, int x) {
	if (y < 0 || y >= H)return false;
	if (x < 0 || x >= W)return false;
	return true;
}

int bfs() {
	vector<vb> visited = vector<vb>(H, vb(W));
	queue<PP> Q;
	REP(i, H)REP(j, W)if (Map[i][j]) {
		Q.push(PP(0, P(i, j)));
		visited[i][j] = true;
	}
	int ret = 0;
	while (!Q.empty()) {
		PP pp = Q.front();
		Q.pop();
		P p = pp.second;
		chmax(ret, pp.first);
		REP(i, 4) {
			int y = dy[i] + p.first;
			int x = dx[i] + p.second;
			if (check(y, x)) {
				if (!visited[y][x]) {
					visited[y][x] = true;
					Q.push(PP(pp.first + 1, P(y, x)));
				}
			}
		}
	}
	return ret;
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cin >> H >> W;
	Map = vector<vb>(H, vb(W));
	REP(i, H) {
		REP(j, W) {
			char c;
			cin >> c;
			if (c == '#')Map[i][j] = true;
		}
	}
	cout << bfs() << endl;
	return 0;
}


Measured memory_bytes: 12688
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
#define ll long long
#define dd double
#define MOD1 1000000007
#define MOD2 998244353
#define nl cout<<endl
#define rt ll Q[100005]={0}
#define mp make_pair
#define test() ll t;cin>>t;while(t--)
#define pb push_back
#define ff first    
#define ss second
#define all(v) v.begin(),v.end()
#define s(ar,n) sort(ar,ar+n)
#define rs(ar,n) sort(ar, ar+n, greater<ll>()) 
#define oa(a,n) for(ll i=0;i<n;i++)cout<<a[i]<<" ";nl
#define cn(a,n) for(ll i=0;i<n;i++)cin>>a[i];
#define ov(a,n) for(ll i=n-1;i>=0;i--)cout<<a[i]<<" ";nl
#define ovp(a,n) for(ll i=0;i<n;i++)cout<<a[i].ff<<" "<<a[i].ss<<endl;
#define maxa(ar,N) *max_element(ar,ar+N)
#define mina(ar,N) *min_element(ar,ar+N)
#define fastio() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
typedef pair<ll,ll> pii;
ll powe(ll n,ll m){if(m==0)return 1;ll t=powe(n,m/2);if(m%2==0)return (t*t);return (((t*t))*n);}
ll mpowe(ll n,ll m,ll MOD){if(m==0)return 1;ll t=mpowe(n,m/2,MOD);t%=MOD;if(m%2==0)return (t*t)%MOD;return (((t*t)%MOD)*n)%MOD;}
ll logtwo(ll n){if(n==1)return 0;return logtwo(n/2)+1;}
int gcd(int a, int b) 
{ 
    if (b == 0) 
        return a; 
    return gcd(b, a % b);  
      
}
int main()
{
    fastio();
   
    int n;
    cin>>n;
    string s;
    cin>>s;
    int r[n],g[n],b[n];
    ll sum=0;
    r[n-1]=s[n-1]=='R'?1:0;
    g[n-1]=s[n-1]=='G'?1:0;
    b[n-1]=s[n-1]=='B'?1:0;
    for(int i=n-2;i>=0;i--)
    {
        r[i]= s[i]=='R'?r[i+1]+1:r[i+1];
        g[i]= s[i]=='G'?g[i+1]+1:g[i+1];
        b[i]= s[i]=='B'?b[i+1]+1:b[i+1];
    }
    for(int i=0;i<n;i++)
    {
        for(int j=i+1;j<n;j++)
        {
            if(s[i]!=s[j])
            {
                if(s[i]!='R' && s[j]!='R')
                {
                    sum = sum + r[j];
                    if(j+j-i<n && s[j+j-i]=='R')
                        sum--;
                }
                else if(s[i]!='G' && s[j]!='G')
                {
                    sum = sum + g[j];
                    if(j+j-i<n && s[j+j-i]=='G')
                        sum--;
                }
                else if(s[i]!='B' && s[j]!='B')
                {
                    sum = sum + b[j];
                    if(j+j-i<n && s[j+j-i]=='B')
                        sum--;
                }
            }
        }
    }
    cout<<sum<<endl;
}

Measured memory_bytes: 3672
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<queue>
using namespace std;
int main()
{
	int x;
	cin >> x;
	int ma = 1;
	for (int i = 2; i < x; i++) {
		int a = i*i;
		while (a <= x) {

			ma = max(ma, a);
			a = a * i;
		}
	}
	cout << ma << endl;
    return 0;
}



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

const int MaxV = 100005, MaxN = 105;

int n, W, sum;
int f[MaxV], w[MaxN], v[MaxN];

void upd(int &a, int b) {
	if (a == -1 || b < a) a = b;
}

int main() {
	scanf("%d%d", &n, &W); sum = 0;
	for (int i = 1; i <= n; ++ i) {
		scanf("%d%d", &w[i], &v[i]);
		sum += v[i];
	}
	for (int i = 0; i <= sum; ++ i) f[i] = -1;
	f[0] = 0;
	for (int i = 1; i <= n; ++ i) {
		for (int j = sum; j - v[i] >= 0; -- j) {
			if (f[j - v[i]] != -1) {
				upd(f[j], min(f[j - v[i]] + w[i], W + 1));
			}
		}
	}
	for (int j = sum; j >= 0; -- j) {
		if (f[j] != -1 && f[j] <= W) {
			printf("%d\n", j);
			break;
		}
	}
	return 0;
}


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

int main()
{
  int n;
  cin >> n;
  string a[n];

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

  set<string> data;
  for (int i = 0; i < n; i++)
  {
    data.insert(a[i]);
  }

  cout << data.size() << endl;
}

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

bool G[26][26];
bool f[26];
bool ans;

void dfs(int now, int root){
    // cout << now << endl;
    if(f[now]){
        if(now == root) ans = false;
        return;
    }
    f[now] = true;
    rep(i, 0, 26){
        if(G[now][i]) dfs(i, root);
    }
}

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    while(cin >> n, n){
        vector<string> s(n);
        ans = true;
        rep(i, 0, 26) rep(j, 0, 26) G[i][j] = false;
        rep(i, 0, n){
            cin >> s[i];
        } 
        rep(i, 0, n - 1){
            int lm = min(s[i].size(), s[i + 1].size());
            bool same = true;
            rep(j, 0, lm){
                if(s[i][j] == s[i + 1][j]) continue;
                else{
                    same = false;
                    G[s[i][j] - 'a'][s[i + 1][j] - 'a'] = true;
                    break;
                }
            }
            if(same){
                if(s[i].size() > s[i + 1].size()){
                    ans = false;
                    break;
                }
            }
        }
        rep(i, 0, 26){
            memset(f, false, sizeof(f));
            dfs(i, i);
        }
        if(ans) cout << "yes" << endl;
        else cout << "no" << endl;
    }
}


Measured memory_bytes: 3112
using System.Text;
using System.Linq;
using System;

public class P
{
    public int id { get; set; }
    public int city { get; set; }
    public int no { get; set; }
    public int y { get; set; }
}

public class Hello
{
    public static void Main()
    {
        string[] line = Console.ReadLine().Trim().Split(' ');
        var n = int.Parse(line[0]);
        var m = int.Parse(line[1]);
        var ps = new P[m];
        for (int i = 0; i < m; i++)
        {
            line = Console.ReadLine().Trim().Split(' ');
            var p = int.Parse(line[0]);
            var y = int.Parse(line[1]);
            ps[i] = new P { id = i, city = p, y = y };
        }
        var ps2 = ps.OrderBy(x => x.city).ThenBy(x => x.y).ToArray();
        var pre = ps2[0].city;
        ps2[0].no = 1;
        var pp = 1;
        for (int i = 1; i < m; i++)
        {
            if (pre == ps2[i].city) { ps2[i].no = ++pp; }
            else { ps2[i].no = 1; pp = 1; pre = ps2[i].city; }
        }
        var sb = new StringBuilder();
        foreach (var x in ps2.OrderBy(y => y.id).ToArray())
            sb.Append(string.Format("{0:000000}{1:000000}\n", x.city, x.no));
        Console.Write(sb);
    }
}


Measured memory_bytes: 38708
#include <cstdio>
#include <utility>
#include <unordered_map>
#include <chrono>
using namespace std;
typedef pair<int,int> ii;
int n,k;
int h[305];
struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
    size_t operator()(const pair<int,int> &i)const{
        return ((long long)i.first)|(((long long)i.second)<<32);
    }
};
unordered_map<int,long long, custom_hash> costs[305];
void ins(int i,int j,long long k){
    if (costs[i].count(j)){
        costs[i][j]=min(costs[i][j],k);
    }
    else{
        costs[i][j]=k;
    }
}
int main(){
    scanf("%d%d",&n,&k);
    for (int x=0;x<n;x++) scanf("%d",&h[x]);

    costs[0][0]=0;
    for (int x=0;x<n;x++){
        for (int y=304;y>=0;y--){
            for (auto it=costs[y].begin();it!=costs[y].end();it++){
                if (it->first>h[x]){
                    ins(y+1,h[x],it->second);
                }
                else{
                    ins(y+1,h[x],it->second+h[x]-it->first);
                }
            }
        }
    }

    long long ans=1000000000000000000;
    for (int x=n;x>=n-k;x--){
        for (auto it=costs[x].begin();it!=costs[x].end();it++){
            ans=min(ans,it->second);
        }
    }

    printf("%lld\n",ans);
}


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

#include <set>
#include <iterator>
using namespace std;
using namespace __gnu_pbds;


#define f first
#define s second
#define pb push_back
#define all(x) x.begin(),x.end()

#define ll long long int
#define vi vector<int>
#define vii vector<pair<int,int> >
#define pii pair<int,int>
#define plii pair<pair<ll, int>, int>
#define piii pair<pii, int>
#define viii vector<pair<pii, int> >
#define vl vector<ll>
#define vll vector<pair<ll,ll> >
#define pll pair<ll,ll>
#define pli pair<ll,int>
#define mp make_pair
#define ms(x, v) memset(x, v, sizeof x)
#define pr_vec(v) for(int i=0;i<v.size();i++) cout << v[i] << " " ;

#define f_in(st) freopen(st,"r",stdin)
#define f_out(st) freopen(st,"w",stdout)

#define INF INT_MAX
#define matrix vector<vector<ll> >

#define fr(i, a, b) for(i=a; i<=b; i++)
#define fb(i, a, b) for(i=a; i>=b; i--)
#define ASST(x, l, r) assert( x <= r && x >= l )
#define maxbits 9
#define maxmask (1ll<<maxbits)
typedef tree<pll, null_type, less<pll>, rb_tree_tag,
             tree_order_statistics_node_update>
    new_data_set;
const int  N=100000 +10, M=(ll)1e9+1 ;
 const int mod =998244353 ,sz=5 ;

void work(){
   double n,d;
   cin >> n >> d;
   d=2*d+1;
   cout << ceil(n/d);
}
int main(){
 ios_base::sync_with_stdio(0);
 cin.tie(0);
    ll t;
    // cin >> t;
    t=1;
    while(t--){
            work();
    }
   return 0;

}


Measured memory_bytes: 256
while True:
    Sei = []
    m_si = 0
    n = int(input())
    
    if n == 0:
        break
    for i in range(n):
        sen = input()
        Sei.append(list(sen))
   
    DP = [[0] * n for i in range(n)]
    for j in range(n):
        if Sei[0][j] == ".":
            DP[0][j] = 1
        else:
            DP[0][j] = 0
    for k in range(n):
        if Sei[k][0] == ".":
            DP[k][0] = 1
        else:
            DP[k][0] = 0
    for k in range(1,n):
        for l in range(1,n):
            if Sei[k][l] == ".":
                DP[k][l] = min(DP[k - 1][l],DP[k][l - 1],DP[k -1][l - 1]) + 1
            else:
                DP[k][l] = 0
    for i in range(n):
        if max(DP[i]) > m_si:
            m_si = max(DP[i])
    print(m_si)

Measured memory_bytes: 49700
#include <bits/stdc++.h>
#define N 100001
using namespace std;
typedef long long ll;

int main(){
  int n,q;
  cin>>n>>q;
  char name[N][11];
  int time[N];
  for(int i=0;i<n;i++)scanf("%s %d",name[i],&time[i]);
  
  queue<int> Q;
  for(int i=0;i<n;i++) Q.push(i);
  
  ll sum = 0;
  while(!Q.empty()){
    int i = Q.front();Q.pop();
    int &t = time[i];
    if(t>q) t-=q,sum+=q,Q.push(i);
    else {
      sum+=t;
      printf("%s %lld\n",name[i],sum);
    }
  }
  

  return 0;
}

Measured memory_bytes: 4140
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;

int main() {
    int n;
    cin >> n;
    vector<string> S(n, "");
    for (auto &s: S) cin >> s;
    vector<int> freq_min(26, 100);
    for (auto &s: S){
        vector<int> freq(26, 0);
        for (auto c: s) freq[c - 'a'] += 1;
        for (int i = 0; i != 26; ++i) freq_min[i] = min(freq_min[i], freq[i]);
    }
    for (int i = 0; i != 26; ++i){
        char c = 'a' + i;
        for (int j = 0; j < freq_min[i]; ++j){
            cout << c;
        }
    }
    cout << endl;
    return 0;
}

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

int main(){
  char s[11], t[11];  scanf("%s%s", s, t);
  int a, b;  scanf("%d%d", &a, &b);

  scanf("%s", s);
  if(strcmp(s, t) == 0)
    printf("%d %d\n", a, b-1);
  else
    printf("%d %d\n", a-1, b);
  return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define IO ios_base::sync_with_stdio(false); cin.tie(NULL);

#define endl '\n'
#define D(x) cout << #x << " = " << (x) << endl;

const int mod = 1000 * 1000 * 1000 + 7;

int main() { IO;
  int h, w;
  cin >> h >> w;

  vector<string> grid(h);
  for (auto &row : grid) cin >> row;

  int cnt[h][w];

  for (int i = 0; i < h; ++i) {
    for (int j = 0; j < w; ++j) {
      cnt[i][j] = (i == 0) && (j == 0);

      if (i and grid[i - 1][j] == '.') {
        cnt[i][j] = (cnt[i][j] + cnt[i - 1][j]) % mod;
      }

      if (j and grid[i][j - 1] == '.') {
        cnt[i][j] = (cnt[i][j] + cnt[i][j - 1]) % mod;
      }
    }
  }

  cout << cnt[h - 1][w - 1] << endl;

  return 0;
}


Measured memory_bytes: 5248
#include <iostream>
#include <vector>
#include <algorithm>
#include <climits>
using namespace std;

#define M 1e9 + 7
#define ll unsigned long long

int main()
{
    int h, w;
    cin >> h >> w;

    vector<vector<char>> grid(h + 1, vector<char>(w + 1, 0));
    vector<vector<ll>> dp(h + 1, vector<ll>(w + 1, 0));

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

    int i;
    for (i = 0; i <= h; i++)
    {
        if (grid[0][i] == '.')
            dp[0][i] = 1;
        else
            break;
    }

    int j = 0;
    for (; j <= w; j++)
    {
        if (grid[j][0] == '.')
            dp[j][0] = 1;
        else
            break;
    }

    for (i = 1; i <= h; i++)
    {
        for (j = 1; j <= w; j++)
        {
            if (grid[i][j] == '.')
            {
                dp[i][j] = dp[i - 1][j] + dp[i][j - 1];
                if (dp[i][j] > M)
                {
                    dp[i][j] -= M;
                }
            }
        }
    }

    // for (auto i : dp)
    // {
    //     for (auto j : i)
    //     {
    //         cout << j << " ";
    //     }
    //     cout << endl;
    // }
    cout << dp[h - 1][w - 1];
    return 0;
}

Measured memory_bytes: 11876
import sys, math
sys.setrecursionlimit(5 * 10**5)
input=sys.stdin.readline

N, M = list(map(int, input().split()))
A = list(map(int, input().split()))

groups = [list() for _ in range(31)]

for a in A:
    for i in range(31):
        if a < 2**i:
            groups[i].append(a)
            break

for i in range(30, 0, -1):
    if len(groups[i]) > 0:
        if len(groups[i]) <= M:
            M -= len(groups[i])
            for e in groups[i]:
                groups[i-1].append(e / 2)
            groups[i].clear()
        else:
            groups[i].sort()
            for j in range(len(groups[i])-1, len(groups[i])-1-M, -1):
                groups[i-1].append(groups[i].pop(j) / 2)
            break

ans = 0

for group in groups:
    for e in group:
        ans += math.floor(e)

print(ans)


Measured memory_bytes: 14252
#include<iostream>
#include<math.h>

using namespace std;

int func(int x, int y, int z, int k) {
  if (x >= y && x >= z) {
    return (int)pow(2, k) * x + y + z;
  } else {
    return func(y, z, x, k);
  }
}

int main(void) {
  int a, b, c, k;

  cin >> a;
  cin >> b;
  cin >> c;
  cin >> k;

  cout << func(a, b, c, k) << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG //これつけるとA[N]でもいいらしい
//for文のマクロ
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define big 1000000007
#define all(a) sort((a).begin(),(a).end()) //ソートのマクロ
#define Re(a) reverse((a).begin(),(a).end())
#define YN(a) if(a){cout<<"Yes"<<endl;}else cout<<"No"<<endl;//条件によってYes、Noを出力する
int main(){
    int64_t x;
    cin>>x;
    int64_t ans = 0;
    ans += 1000*(x/500);
    x -= 500*(x/500);
    ans += 5*(x/5);
    cout<<ans<<endl;
}

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

int dp[45];

int _fib(int n) {
    if(n == 0 || n == 1) {
        return 1;
    } else if(dp[n] != 0) {
        return dp[n];
    } 

    dp[n - 1] = _fib(n - 1);
    dp[n - 2] = _fib(n - 2);
    return dp[n] = dp[n - 1] + dp[n - 2];
}

int fib(int n) {
    memset(dp, 0, sizeof(dp));

    return _fib(n);
}

int main(void) {
    int n;

    scanf("%d", &n);

    printf("%d\n", fib(n));

    return 0;
}


Measured memory_bytes: 2084
def solve():
  ans = float('inf')
  H, W = map(int, input().split())
  for h in range(1,H):
    o1 = (H-h)//2*W
    o2 = (H-h)*W-o1
    a = [h*W,o1,o2]
    ans = min(ans,max(a)-min(a))
    o1 = W//2*(H-h)
    o2 = (H-h)*W-o1
    a = [h*W,o1,o2]
    ans = min(ans,max(a)-min(a))
  for w in range(1,W):
    o1 = (W-w)//2*H
    o2 = (W-w)*H-o1
    a = [w*H,o1,o2]
    ans = min(ans,max(a)-min(a))
    o1 = H//2*(W-w)
    o2 = (W-w)*H-o1
    a = [w*H,o1,o2]
    ans = min(ans,max(a)-min(a))
  return ans
print(solve())

Measured memory_bytes: 73612
n = int(input())
num_list = []
count = 1
for i in range(n):
    num_list.append(int(input())-1)
#[2,2,3,1,3]
#1があるindexに行くのが目標
ind = num_list[0]
if ind == 1:
    print(1)
else:
    for i in range(n-1):
        ind = num_list[ind]
        count += 1
        if ind == 1:
            print(count)
            break
if count > n-1:
   print(-1)    




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

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

#define pb push_back
#define rep(i, n) for(int i = 0; i < (n); i++)
#define FOR(i, a, n) for(int i = a; i < (n); i++)
#define mod (ll)(1e9+7)
#define int ll

__attribute__((constructor))
void initial() {
  cin.tie(0);
  ios::sync_with_stdio(false);
}

signed main() {
	ll w, a, b, result;
  cin >> w >> a >> b;
  if (a < b) result = b - (a + w);
  if (a > b) result = a - (b + w);
  if (result < 0) result = 0;
  cout << result << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long  ll;
#define FOR(i,a,n) for(ll i=(ll)a;i<(ll)n;i++)
#define RFOR(i,a,n) for(ll i=(ll)n-1;i >= (ll)a;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,0,n)
#define ALL(v) v.begin(), v.end()
#define bra(first,second) '(' << first << ',' << second << ')'
#define P(a,b) make_pair(a,b);
ll MOD = 1000000007;
//ll INF = 21474836470000000;
ll INF = 1001001001001001001;
long double EPS = 1e-11;
long double PI = 3.141592653589793238;
template<typename T>
void remove(std::vector<T>& vector, unsigned int index){
    vector.erase(vector.begin() + index);
}

using Graph = vector<vector<pair<ll,ll>>>;

int main(){
  ll N;
  cin >> N;
  vector<string> S(N);
  rep(i,N) cin >> S[i];
  sort(ALL(S));
  vector<pair<ll,string>> B;
  B.emplace_back(1,S[0]);
  rep(i,N-1){
    if(S[i] == S[i+1])B.back().first++;
    else B.emplace_back(1,S[i+1]);
  }
  sort(ALL(B));
  reverse(ALL(B));
  set<string> st;
  ll i = 0;
  while(B[0].first == B[i].first){
    st.insert(B[i].second);
    i++;
  }
  for(auto itr = st.begin();itr != st.end();itr++){
    cout << *itr << endl;
  }
}


Measured memory_bytes: 27760
#include <bits/stdc++.h>
#include <string.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i, m, n) for(int i = m; i < n; i++) 
#define mod 1000000007
typedef long long ll;

vector<int> sieve(int a){
    //aまでの素数のテーブルを作成
    //main側では要素数a+1のvectorを作成しておく
    vector<int>X(a+1,1);
    X[0]=0,X[1]=0;
    for(int p=2;p*p<=a;p++){
        if(!X[p])continue;
        for(int i=p*2;i<=a;i+=p)X[i]=0;
    }
    return X;
}
int main(){
    int Q;
    cin>>Q;
    vector<int>l(Q);
    vector<int>r(Q);
    vector<int>X(100001);
    X=sieve(100000);
    int count=0;
    rep(i,Q){
        cin>>l[i]>>r[i];
        }

    vector<int>sum(100001,0);
    int sum2 = 0;
    for(int i=1;i<=100000;i+=2){
        if(X[i]==1&&X[(i+1)/2]==1){
            sum2+=1;
        }
        sum.at(i)=sum2;
        //cout<<i<<" "<<sum[i]<<endl;
    }
    
    rep(i,Q){
        cout<<sum[r[i]]-sum[l[i]-2]<<endl;
    }
    
    


    return 0;
}

Measured memory_bytes: 2168
n = gets.chomp
arr = gets.chomp.split(' ').map(&:to_i)

cnt = 0
loop do 
  is_break = false
  arr.each do |a| 
   is_break = true if a%2!=0
   break if a%2!=0
  end
  break if is_break == true
  arr.map!{|a| a/2}
  cnt += 1
end
puts cnt
  


Measured memory_bytes: 3836
import java.util.Scanner;
 
public class Main {
 
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int h = sc.nextInt();
		int n = sc.nextInt();
 
		for (int i = 0; i < n; i++) {
			h -= sc.nextInt();
		}
		sc.close();
		if (h <= 0) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
	}
}

Measured memory_bytes: 58760
fun main(args: Array<String>) {
    val (N, M) = readLine()!!.split(" ").map{it.toInt()}
    val a = readLine()!!.split(" ").map{it.toLong()}

    val b = a.map {
        var k = it
        var cnt = 0
        while(k % 2 == 0L) {
            cnt++
            k /= 2L
        }

        cnt
    }.sorted()

    if (b.first() != b.last()) {
        println(0)
        return
    }

    var l = 1L

    for (i in a.indices) {
        l = lcm(l, a[i])

        if (l > 2 * M) {
            println(0)
            return
        }
    }

    val m = l / 2

    println(1 + (M - m) / l)
}

tailrec fun gcd(x: Long, y: Long): Long = if (y == 0L) x else gcd(y, x % y)

/**
 * Calculate the least common multiple of `x` and `y`
 */
fun lcm(x: Long, y: Long): Long = x / gcd(x, y) * y



Measured memory_bytes: 70400
#include <bits/stdc++.h>
#ifdef DOC
#define _NTH_ARG(_1, _2, _3, _4, _5, _6, N, ...) N
#define _FE_1(_CALL, x) _CALL(x)
#define _FE_2(_CALL, x, ...) _CALL(x) \
_FE_1(_CALL, __VA_ARGS__)
#define _FE_3(_CALL, x, ...) _CALL(x) \
_FE_2(_CALL, __VA_ARGS__)
#define _FE_4(_CALL, x, ...) _CALL(x) \
_FE_3(_CALL, __VA_ARGS__)
#define _FE_5(_CALL, x, ...) _CALL(x) \
_FE_4(_CALL, __VA_ARGS__)
#define _FE_6(_CALL, x, ...) _CALL(x) \
_FE_5(_CALL, __VA_ARGS__)
#define FOR_EACH_MACRO(MACRO, ...)                                  \
    _NTH_ARG(__VA_ARGS__, _FE_6, _FE_5, _FE_4, _FE_3, _FE_2, _FE_1) \
    (MACRO, __VA_ARGS__)
#define watch(x) cerr << #x " = " << (x) << "; ";
#define debug(...)                       \
    cerr << "Line " << __LINE__ << ": "; \
    FOR_EACH_MACRO(watch, __VA_ARGS__)   \
    cerr << endl
#else
#define debug(...)
#endif

using namespace std;

template <class T1, class T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p)
{
    return os << '{' << p.first << ", " << p.second << '}';
}

template <class T, class = decltype(begin(declval<T>())),
          class = enable_if_t<!is_same<T, string>::value>>
ostream &operator<<(ostream &os, const T &c)
{
    os << '[';
    for (auto it = begin(c); it != end(c); ++it)
        os << (it == begin(c) ? "" : ", ") << *it;
    return os << ']';
}
typedef long long ll;
#define F(i, a, b) for (int i = (a); i <= (b); i++)
#define D(i, a, b) for (int i = (a); i >= (b); i--)
#define R(i, a, b) for (int i = (a); i < (b); i++)
#define N 500000
#define ALL(vt) vt.begin(), vt.end()
#define ALLR(vt) vt.rbegin(), vt.rend()
int solve(){
    int n; cin >> n;
    vector<int> h(n); for(int &k : h) cin >> k;
    vector<int> dp(n, 0);
    if(n == 1) return 0;
    if(n == 2) return h[1] - h[0];
    dp[1] = abs(h[1] - h[0]);    
    R(i, 2, n){        
        dp[i] = min(dp[i-1] + abs(h[i]-h[i-1]), dp[i-2] + abs(h[i] - h[i-2]));        
        // debug(dp[i]);
    }
    return dp[n-1];
}
int main(){
    cout << solve();

}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef vector<int> VI;
typedef long long LL;
typedef pair<int,int> PII;
typedef pair<double,double> PDD;
const int mod=1e9+7;
const double eps=1e-8;
const int inf=0x3f3f3f3f;
const double pi=acos(-1.0);
//LL powmod(LL a,LL b) {LL res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
LL a[15][15];
int main()
{
    string s;
    cin>>s;
    int n=SZ(s);
    for(int i=0;i<n;i++){
        a[i][i]=s[i]-'0';
        for(int j=i+1;j<n;j++)
            a[i][j]=a[i][j-1]*10+s[j]-'0';
    }
    LL ans=0;
    for(int i=0;i<(1<<n-1);i++){
        int p=-1;
        for(int j=0;j<n-1;j++){
            if(i&(1<<j)){
                ans+=a[p+1][j];
                p=j;
            }
        }
        ans+=a[p+1][n-1];
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int k,n;
int main()
{
	scanf("%d",&k);
	if(k==1)
	{
		printf("1\n1");
		return 0;
	}
	n=(k+3)/4*2;
	printf("%d\n",n);
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=n;j++)
		{
			int val=(i+j-1)%n+1;
			if(i%2) printf("%d ",val);
			else printf("%d ",(val<=k-n?val+n:val));
		}
		printf("\n");
	}
	return 0;
} 

Measured memory_bytes: 1152
/*input
20
*/
#include <bits/stdc++.h>
#define pb push_back
#define x first
#define y second
#define all(a) a.begin(), a.end()
#define sz(a) (int)a.size()
#define rd() abs((int)rng())
using namespace std;
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
const int maxn = 2e5 + 100;
const int mod = 1e9 + 7;
mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
int main()
{
	ios_base::sync_with_stdio(false), cin.tie(0);
	int n;
	cin >> n;
	vector<int>ans(n + 1);
	for (int x = 1; x <= 100; x++) {
		for (int y = 1; y <= 100; y++) {
			for (int z = 1; z <= 100; z++) {
				int num = x * x + y * y + z * z + x * y + y * z + x * z;
				if (num <= n) {
					ans[num]++;
				}
			}
		}
	}

	for (int i = 1; i <= n; i++) {
		cout << ans[i] << "\n";
	}
	return 0;
}

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

const int MOD = 1000000007;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define copy(from, to) copy(from.begin(), from.end(), back_inserter(to))
#define sort(a) sort(a.begin(), a.end())
#define reverse(s) reverse(s.begin(), s.end())
#define p(s) cout << (s) << endl

typedef long long ll;
using namespace std;

template<class T>
void load(vector<T> &v, int n) {
  for (int i = 0; i < n; ++i) {
    T t;
    cin >> t;
    v.push_back(t);
  }
}

template<class T>
T max(vector<T> &v) {
  return *max_element(v.begin(), v.end());
}

template<class T>
T min(vector<T> &v) {
  return *min_element(v.begin(), v.end());
}

void py(bool isUpper = false) {
  if (isUpper) {
    p("YES");
  } else {
    p("Yes");
  }
}

void pn(bool isUpper = false) {
  if (isUpper) {
    p("NO");
  } else {
    p("No");
  }
}

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

  vector<int> mod;
  bool flag = false;
  for (int i = 1; ; ++i) {
    for (int e : mod) {
      if ((a * i) % b == e) {
        flag = true;
      }
    }
    if (!flag) {
      mod.push_back((a * i) % b);
    }
    if (flag) {
      break;
    }
  }

  for (int e : mod) {
    if (e == c) {
      py(true);
      return 0;
    }
  }
  pn(true);
}

Measured memory_bytes: 256
# from math import factorial,sqrt,ceil,gcd
# from itertools import permutations as permus
# from collections import deque,Counter
# import re
# from functools import lru_cache # 簡単メモ化 @lru_cache(maxsize=1000)
# from decimal import Decimal, getcontext
# # getcontext().prec = 1000
# # eps = Decimal(10) ** (-100)

# import numpy as np
# import networkx as nx
# from scipy.sparse.csgraph import shortest_path, dijkstra, floyd_warshall, bellman_ford, johnson
# from scipy.sparse import csr_matrix
# from scipy.special import comb

# slist = "abcdefghijklmnopqrstuvwxyz"
A,B,C,X,Y = map(int,input().split())

costA = min(A,C*2)
costB = min(B,C*2)
costAB = min(A+B,C*2,A+costB,costA+B)

numAB = min(X,Y)
numA = max(X-Y,0)
numB = max(Y-X,0)

ans = numA*costA + numB*costB + numAB*costAB

print(ans)
# print(*ans)   # unpackして出力。間にスペースが入る
# for row in board:
#     print(*row,sep="")    #unpackして間にスペース入れずに出力する
# print("{:.10f}".format(ans))
# print("{:0=10d}".format(ans))


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

using namespace std;

#define pb			push_back
#define all(v)			((v).begin()), ((v).end())
#define SZ(v)			((int)((v).size()))
#define clr(v, d)		memset(v, d, sizeof(v))
#define has(c,i) 		((c).find(i) != end(c))
#define hastr(s, c)		((s).find(c) != string::npos)

template <class T>
istream& operator>>(istream& is, vector<T>& v) {
  for (T& x : v)
    is >> x;
  return is;
}

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;

int main() {

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

    double r;
    cin >> r;
    cout << double(2 * 3.14159 * r);

    return 0;
}


Measured memory_bytes: 3780
import sys
from collections import deque
from heapq import heappush,heappop

d = [(0,1),(1,0),(0,-1),(-1,0)]
def bfs():
    dist = [[[float("inf")]*4 for i in range(w)] for j in range(h)]
    dist[0][0][0] = 0
    q = [(0,0,0,0)]
    while q:
        dn,y,x,c = heappop(q)
        for di in range(4):
            c_ = ro[di][c]
            y_ = y+d[c_][0]
            x_ = x+d[c_][1]
            if 0 <= y_ < h and 0 <= x_ < w:
                if dist[y_][x_][c_] > dn+co[y][x][di]:
                    dist[y_][x_][c_] = dn+co[y][x][di]
                    heappush(q,(dist[y_][x_][c_],y_,x_,c_))
    return dist

while 1:
    w,h = map(int, sys.stdin.readline().split())
    if w == 0:
        break
    s = [list(map(int, sys.stdin.readline().split())) for i in range(h)]
    cost = list(map(int, sys.stdin.readline().split()))
    co = [[[cost[i] for i in range(4)] for x in range(w)] for y in range(h)]
    for y in range(h):
        for x in range(w):
            if s[y][x] < 4:
                co[y][x][s[y][x]] = 0
    ro = [[0]*4 for i in range(4)]
    for c in range(4):
        for i in range(4):
            if c == 0:
                ro[c][i] = i
            elif c == 1:
                ro[c][i] = (i+1)%4
            elif c == 2:
                ro[c][i] = (i+2)%4
            else:
                ro[c][i] = (i+3)%4

    dist = bfs()
    print(min(dist[h-1][w-1]))



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

int main(){
  string ans;
  int N,i;
  cin >> N;
  string s,t;
  cin >> s >> t;
  rep(i,N){
    ans += s[i];
    ans += t[i];
  }
  cout << ans;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define vi vector<int>
#define pb push_back
using namespace std;
const int mod=1e9+7;
const int N=1e5+5;
vi v[N];int n,x,y;
ll dp[N][2];
ll dfs(int now,int color,int last)
{
	if(dp[now][color]!=0)return dp[now][color];
	ll resb=1,resw=1;
	if(color==1)resw=0;
	else resb=0;
	for(int i=0;i<v[now].size();i++)
	{
		int to=v[now][i];
		if(last==to)continue;
		resb*=dfs(to,0,now);
		resb%=mod;
		resw*=(dfs(to,0,now)+dfs(to,1,now))%mod;
		resw%=mod;
	}
	return dp[now][color]=(resb+resw)%mod;
}
int main()
{
	cin>>n;
	for(int i=0;i<n-1;i++)
	{
		cin>>x>>y;
		x--,y--;
		v[x].pb(y);
		v[y].pb(x);
	}
	cout<<(dfs(0,0,-1)+dfs(0,1,-1))%mod<<endl;
	return 0;
}

Measured memory_bytes: 17024
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define USE_LLONG_AS_INT
#ifdef USE_LLONG_AS_INT
#define int long long
#define inf (1ll<<60)
#else
#define inf (1<<30)
#endif
#define rep(i,n) for(int i=0;i<(n);i++)
#define Rep(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,a,b) for(int i=(a);i<=(b);i++)
#define rev(i,n) for(int i=(n)-1;i>=0;i--)
#define vi vector<int>
#define vvi vector<vi>
#define vs vector<string>
#define pb push_back
#define eb emplace_back
#define pi pair<int,int>
#define vp vector<pair<int,int>>
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define MEMSET(a) memset(a,0,sizeof(a))
#define Yes(f) cout<<(f?"Yes":"No")<<endl
#define yes(f) cout<<(f?"yes":"no")<<endl
#define YES(f) cout<<(f?"YES":"NO")<<endl
#define SORT(v) sort(all(v))
#define RSORT(v) sort(all(v), greater<int>())

using namespace std;

const int mod=1e9+7;
// const int mod=998244353;
const string sp=" ";

void run();

void init() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout<<fixed<<setprecision(12);
}

signed main(){
    init();
    run();
    return 0;
}

void run(){
    int n;
    cin>>n;
    int ans=0;
    REP(i,1,n){
        int t=n/i;
        ans+=t*(2*i+(t-1)*i)/2;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 3660
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <queue>
#include <algorithm>
#include <utility>
#include <cmath>

#define INF_LL 9000000000000000000
#define INF 2000000000

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

using namespace std;

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

class Union_find{
private:
	vector<int> par;
	vector<int> rank;
	int n;

public:
	Union_find(int a){
		n = a;
		for(int i = 0;i < n;i++){
			par.push_back(i);
			rank.push_back(0);
		}
	}

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

	void unite(int x, int y){
		x = find(x);
		y = find(y);
		if(x == y) return;

		if(rank[x] < rank[y]){
			par[x] = y;
		}else{
			par[y] = x;
			if(rank[x] == rank[y]) rank[x]++;
		}
	}

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

int num[100000];
int pos[100000];
int res;
int n, m;
int x, y;

int main(void){
	int res =1;
	cin >> n >> m;
	fill(num, num+n, 1);
	fill(pos, pos+n, 0);
	pos[0] = 1;
	REP(i, m){
		cin >> x >> y;
		x--; y--;
		num[x]--;
		num[y]++;
		if(pos[x] == 1){
			if(pos[y] == 0){
				pos[y] = 1;
				res++;
			}
			if(num[x] == 0){
				pos[x] = 0;
				res--;
			}
		}
	}
	cout << res << endl;
	return 0;
}


Measured memory_bytes: 1024
using System;
using System.Linq;
using System.Collections.Generic;

class Program
{
    static void Main(string[] args)
    {
        var K = int.Parse(Console.ReadLine());
        var evenCount = 0;
        var oddCount = 0;
        for (int i = 1; i <= K; i++)
        {
            if (i % 2 == 0)
            {
                evenCount++;
            }
            else
            {
                oddCount++;
            }
        }

        var ans = comb(evenCount, 1) * comb(oddCount, 1);
        Console.WriteLine(ans);
    }

    static int comb(int n, int k)
    {
        var child = 1;
        for (int i = n; i >= n - k + 1; i--)
        {
            child *= i;
        }

        var mother = 1;
        for (int i = k; i >= 1; i--)
        {
            mother *= i;
        }

        var ans = child / mother;
        return ans;
    }


}



Measured memory_bytes: 11092
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <complex>
#include <vector>
#include <cmath>

using namespace std;

#define MAXN (14)
#define INF  (1<<29)
#define X    real()
#define Y    imag()

typedef complex<double> P;

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

inline double getDist(P, P);
struct Segment {
  P s, t;
  double d;
  Segment() {}
  Segment(P s, P t) : s(s), t(t) { d = getDist(s, t); }
};

inline double getDist(P a, P b) { return sqrt(Sq(a.X-b.X)+Sq(a.Y-b.Y)); }
inline double getDist(Segment sg) { return sqrt(Sq(sg.s.X-sg.t.X)+Sq(sg.s.Y-sg.t.Y)); }

int n;
double dist[MAXN][2][MAXN][2]; // seg s: 0, t: 1
double dp[1<<MAXN][MAXN][2];
Segment seg[MAXN];

int main() {
  
  int tcase = 1;
  double x1, y1, x2, y2;
  double allseglen;
  
  while(cin >> n, n) {
    
    allseglen = 0.0;
    
    for(int i=0; i<n; i++) {
      cin >> x1 >> y1 >> x2 >> y2;
      seg[i] = Segment(P(x1, y1), P(x2, y2));
      allseglen += seg[i].d;
    }
    
    for(int i=0; i<n; i++) {
      for(int j=0; j<n; j++) {
	
	if(i == j) {
	  for(int ii=0; ii<2; ii++) {
	    for(int jj=0; jj<2; jj++) {
	      if(ii == jj) { dist[i][ii][j][jj] = 0; }
	      else { dist[i][ii][j][jj] = seg[i].d; }
	    }
	  }
	  
	  continue;
	}
	
	dist[i][0][j][0] = getDist(seg[i].s, seg[j].s);
	dist[i][0][j][1] = getDist(seg[i].s, seg[j].t);
	dist[i][1][j][0] = getDist(seg[i].t, seg[j].s);
	dist[i][1][j][1] = getDist(seg[i].t, seg[j].t);
	
      }
    }
        
    for(int i=0; i<(1<<n); i++)
      for(int j=0; j<n; j++)
	for(int k=0; k<2; k++)
	  dp[i][j][k] = INF;
      
    for(int i=0; i<n; i++)
      for(int j=0; j<2; j++)
	dp[(1<<n)-1][i][j] = 0;
    
    for(int S=(1<<n)-1; S >= 0; S--)
      for(int v=0; v<n; v++)
	for(int u=0; u<n; u++)
	  for(int i=0; i<2; i++)
	    for(int j=0; j<2; j++)
	      if(!(S>>u & 1))
		dp[S][v][j] = min(dp[S][v][j], dp[S|1<<u][u][i]+dist[u][(i+1)%2][v][j]);
    
    double ans = INF;
    for(int i=0; i<n; i++)
      for(int j=0; j<2; j++)
	ans = min(ans, dp[0][i][j]);
    
    printf("Case %d: %f\n", tcase++, ans + allseglen);
  }
  
  return 0;
}

Measured memory_bytes: 4828
#include"bits/stdc++.h"
using namespace std;
#define LL long long
#define REP(i, n) for(int (i)=0; (i)<(n); (i)++)
#define PB push_back
#define MP make_pair
#define all(x) x.begin(),x.end()

int N,Q;
string S;
pair<char,char> q[200000];

//左から消えるか
bool isOK_L(int i){
	for(int j=0; j<Q; j++){
		if(S[i] == q[j].first){
			if(q[j].second == 'L') i--;
			else i++;
		}
		if(i < 0) return true;
	}
	return false;
}
int binary_search_L(){
	int ok = -1;
	int ng = N;
	while(ng-ok > 1){
		int m = (ok+ng)/2;
		if(isOK_L(m)) ok = m;
		else ng = m;
	}
	return ok;
}

//右から消えるか
bool isOK_R(int i){
	for(int j=0; j<Q; j++){
		if(S[i] == q[j].first){
			if(q[j].second == 'L') i--;
			else i++;
		}
		if(i >= N) return true;
	}
	return false;
}
int binary_search_R(){
	int ok = N;
	int ng = -1;
	while(ok-ng > 1){
		int m = (ok+ng)/2;
		if(isOK_R(m)) ok = m;
		else ng = m;
	}
	return ok;
}


int main(){
	cin >> N >> Q >> S;
	for(int i=0; i<Q; i++) cin >> q[i].first >> q[i].second;
	int L = binary_search_L();
	int R = binary_search_R();
	int ans = R-L-1;
	if(ans < 0) ans = 0;
	cout << ans << endl;
	return 0;
}



Measured memory_bytes: 1028
#include<stdio.h>

int main() {
  int x, y, temp;

  scanf("%d %d", &x, &y);

  if(x < y) {
    temp = y;
    y = x;
    x = temp;
  }
  
  while((x%y) != 0) {
    temp = y;
    y = x % y;
    x = temp;
  }

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



Measured memory_bytes: 2700
#include "bits/stdc++.h"
using namespace std;
#define MODULO 1000000007
#define PI 3.14159265359
typedef long long int ll;
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(NULL);
	cout.tie(NULL);
	int n;
	cin>>n;
	int ct=0;
	int flag=0;
	while(n--)
	{
		int a,b;
		cin>>a>>b;
		if(a==b)
		ct++;
		else
		ct=0;
		if(ct==3)
		{
			flag=1;
			cout<<"Yes";
			break;
		}
	}
	if(flag==0)
	cout<<"No"<<endl;
    return 0;
}


Measured memory_bytes: 3628
#include<bits/stdc++.h>
#include<cmath>
using namespace std;
#define tez ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);cerr.tie(NULL);
int main(){
    tez;
    long long int a,b,c; cin>>a>>b>>c;
    long long int d = c - a - b;
    if(d > 0 && d * d > 4 * a * b){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define SZ(x) ((int)(x).size())
typedef long long ll;
typedef long double ld;
using namespace std;

int main() {
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    cout.setf(ios::fixed); cout.precision(20);
    char c; cin >> c;
    for (char ch = 'a'; ch <= 'z'; ch++) {
        if (c == ch) {
            cout << 'a';
            exit(0);
        }
        if (c == toupper(ch)) {
            cout << 'A';
            exit(0);
        }
    }
}


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

using namespace std;

int main() {
    int A = 0, B = 0, C = 0;
    cin >> A >> B >> C;

    if (A == B && B != C) {
        cout << "Yes" << endl;
        return 0;
    } else if (B == C && C != A) {
        cout << "Yes" << endl;
        return 0;
    } else if (A == C && C != B) {
        cout << "Yes" << endl;
        return 0;
    } else {
        cout << "No" << endl;
        return 0;
    }
}

Measured memory_bytes: 3624
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <utility>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <limits>
#include <cmath>
#include <cassert>

using namespace std;
using ll = long long;

const int INF = 1<<30;
const int MOD = (int)1e9 + 7;
const int MAX_N = (int)1e5 + 5;
#define debug(x) cout << #x << ": " << x << endl

signed main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll a, b; cin >> a >> b;
    ll k = (a + b) / 2;
    if(abs(a - k) == abs(b - k)) cout << k << endl;
    else cout << "IMPOSSIBLE" << endl;
    return 0;
}



Measured memory_bytes: 256
#include <cstdio>
#include <cmath>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <algorithm>

#ifdef _DEBUG
#define DMP(x) cerr << #x << ": " << x << "\n"
#else
#define DMP(x) ((void)0)
#endif

const int MOD = 1000000007, INF = 1111111111; 
using namespace std;
using lint = long long;

int main() {

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	int N;
	cin >> N;

	vector<lint> A(N), ans(N);
	for (int i = 0; i < N; i++) cin >> A[i];

	for (int i = 0; i < N; i++) {
		ans[0] += (-2 * (i % 2) + 1) * A[i];
	}
	DMP(ans[0]);

	for (int i = 1; i < N; i++) {
		ans[i] = A[i - 1] * 2 - ans[i - 1];
	}

	for (int i = 0; i < N; i++) {
		cout << ans[i] << " ";
	}

	return 0;
}

Measured memory_bytes: 2944
import collections

N = int(input())
S = [input() for _ in range(N)]

c = collections.Counter(S)
value_and_counts = c.most_common()

max_number = value_and_counts[0][1]

value_and_counts.sort()

for i in value_and_counts:
    if max_number == i[1]:
        print(i[0])

Measured memory_bytes: 46900