akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;
int main(){
    string s, t;
    cin >> s >> t;
    int S = (int)s.size();
    int T = (int)t.size();
    int INF = 1e9;
    vector<vector<int>> dp(S + 1, vector<int>(T + 1, 0));
    for(int i = 1; i < S + 1; i++){
        for(int j = 1; j < T + 1; j++){
            if(s[i - 1] == t[j - 1]){
                int temp = dp[i][j];
                dp[i][j] = max(dp[i - 1][j - 1] + 1, max(dp[i - 1][j], dp[i][j - 1]));
            }
            else{
                dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
            }
        }
    }
    string ans;
    int cnt = dp[S][T];
    int si = S, sj = T;
    int flag = 0;
    while(cnt != 0){
        if(dp[si][sj] > dp[si][sj - 1]) {
            ans += t[sj - 1];
            cnt--;
            sj--;
            flag = 0;
            continue;
        }
        if(flag == 0){
            if(dp[si][sj] > dp[si - 1][sj]) {
                flag = 1;
                continue;
            }
            si--;
        }
        if(flag == 1){
            sj--;
        }
    }
    reverse(ans.begin(), ans.end());
    cout << ans << endl;
}

Measured memory_bytes: 38552
#include<stdio.h>
#include<string.h>
int main(void)
{

        char a[4];

        char *bt = "BTC";

        char *jp = "JPY";

        double b,s;

        int i,c;

        scanf("%d",&c);

        for(i=0;i<c;i++){

                scanf("%lf%s",&b,a);

                if(strcmp(a,jp)==0){

                        s+=b;
                }

                if(strcmp(a,bt)==0){

                        s+=(380000*b);
                }

        }

        printf("%f\n",s);

        return 0;
}



Measured memory_bytes: 128
// This amazing code is by Eric Sunli Chen.
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <utility>
#include <vector>
using namespace std;
template<typename T> void get_int(T &x)
{
	char t=getchar();
	bool neg=false;
	x=0;
	for(; (t>'9'||t<'0')&&t!='-'; t=getchar());
	if(t=='-')neg=true,t=getchar();
	for(; t<='9'&&t>='0'; t=getchar())x=x*10+t-'0';
	if(neg)x=-x;
}
template<typename T> void print_int(T x)
{
	if(x<0)putchar('-'),x=-x;
	short a[20]= {},sz=0;
	while(x>0)a[sz++]=x%10,x/=10;
	if(sz==0)putchar('0');
	for(int i=sz-1; i>=0; i--)putchar('0'+a[i]);
}
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define get1(a) get_int(a)
#define get2(a,b) get1(a),get1(b)
#define get3(a,b,c) get1(a),get2(b,c)
#define printendl(a) print_int(a),puts("")
typedef long long LL;
typedef unsigned long long uLL;
typedef pair<int,int> pii;
const int inf=233333333;
const LL Linf=1ll<<61;
const double pi=acos(-1.0);

vector<int> g[1111];
int p[1111],n,v[1111],sz[1111],dp[1111];

int mn[1111][5555];

void dfs(int x)
{
	for(int i=0;i<(int)g[x].size();i++)
		dfs(g[x][i]);
	int sz=(int)g[x].size();
	for(int i=0;i<sz;i++)
	{
		for(int j=0;j<=5000;j++)
		{
			mn[i+1][j]=inf;
			if(j>=v[g[x][i]])mn[i+1][j]=min(mn[i+1][j],mn[i][j-v[g[x][i]]]+dp[g[x][i]]);
			if(j>=dp[g[x][i]])mn[i+1][j]=min(mn[i+1][j],mn[i][j-dp[g[x][i]]]+v[g[x][i]]);
		}
	}
	dp[x]=mn[sz][v[x]];
}
int main()
{
	get1(n);
	for(int i=2;i<=n;i++){get1(p[i]);g[p[i]].pb(i);}
	for(int i=1;i<=n;i++)get1(v[i]);
	
	dfs(1);
	if(dp[1]<inf)puts("POSSIBLE");
	else puts("IMPOSSIBLE");
	return 0;
}

Measured memory_bytes: 22784
/*
Rathin Bhargava
IIIT Bangalore

*/
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
#define mt make_tuple
#define mp make_pair
#define pu push_back
#define INF 1000000001
#define MOD 1000000007
#define EPS 1e-6
#define ll long long int
#define ld long double
#define fi first
#define se second
#define all(v) v.begin(),v.end()
#define pr(v) { for(int i=0;i<v.size();i++) { v[i]==INF? cout<<"INF " : cout<<v[i]<<" "; } cout<<endl;}
#define t1(x)                cerr<<#x<<" : "<<x<<endl
#define t2(x, y)             cerr<<#x<<" : "<<x<<" "<<#y<<" : "<<y<<endl
#define t3(x, y, z)          cerr<<#x<<" : " <<x<<" "<<#y<<" : "<<y<<" "<<#z<<" : "<<z<<endl
#define t4(a,b,c,d)          cerr<<#a<<" : "<<a<<" "<<#b<<" : "<<b<<" "<<#c<<" : "<<c<<" "<<#d<<" : "<<d<<endl
#define t5(a,b,c,d,e)          cerr<<#a<<" : "<<a<<" "<<#b<<" : "<<b<<" "<<#c<<" : "<<c<<" "<<#d<<" : "<<d<<" "<<#e<<" : "<<e<<endl
#define t6(a,b,c,d,e,f)          cerr<<#a<<" : "<<a<<" "<<#b<<" : "<<b<<" "<<#c<<" : "<<c<<" "<<#d<<" : "<<d<<" "<<#e<<" : "<<e<<" "<<#f<<" : "<<f<<endl
#define GET_MACRO(_1,_2,_3,_4,_5,_6,NAME,...) NAME
#define t(...) GET_MACRO(__VA_ARGS__,t6,t5, t4, t3, t2, t1)(__VA_ARGS__)
#define _ cerr<<"here"<<endl;
#define __ {ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);}

using namespace std;
template<class A, class B> ostream& operator<<(ostream& out, const pair<A, B> &a){ return out<<"("<<a.first<<", "<<a.second<<")";}
template <int> ostream& operator<<(ostream& os, const vector<int>& v) { os << "["; for (int i = 0; i < v.size(); ++i) { if(v[i]!=INF) os << v[i]; else os << "INF";if (i != v.size() - 1) os << ", "; } os << "]\n"; return os; } 
template <typename T> ostream& operator<<(ostream& os, const vector<T>& v) { os << "["; for (int i = 0; i < v.size(); ++i) { os << v[i]; ;if (i != v.size() - 1) os << ", "; } os << "]\n"; return os; } 

const int N = 2e3+100;
vector<int> adj[N] = {};

int cnt = 0;
void dfs(int u,int p = -1,int level = 0)
{
  // t(u,p);
  if(level<0) return;
  cnt++;
  for(auto v : adj[u]) 
  {
    // t(v,p);
    if(v!=p) dfs(v,u,level-1);
  }
}

int main()
{
  __;
  int n,k;
  cin >> n >> k;
  vector<pair<int,int> > edge;
  for(int i=0;i<n-1;i++)
  {
    int a,b;
    cin >> a >> b;
    a--; b--;
    adj[a].pu(b);
    adj[b].pu(a);
    edge.pu(mp(a,b));
  }

  // k--;

  int min1 = INF;
  if(k%2==0)
  {
    for(int i=0;i<n;i++)
    {
      dfs(i,-1,k/2);
      // t(i,n-cnt);
      min1 = min(min1,n-cnt);
      cnt = 0;
    }
  }
  else
  {
    for(auto p : edge)
    {
      dfs(p.fi,p.se,(k-1)/2);
      // cout << "\n";
      int a = cnt;
      cnt = 0;
      dfs(p.se,p.fi,(k-1)/2);
      a += cnt;
      // t(p,a);
      min1 = min(min1,n-a);
      cnt = 0;
    }
  }

  cout << min1 << endl;
  return 0;
}



Measured memory_bytes: 384
#include<stdio.h>
#include<stdlib.h>
typedef struct node
{
	int value;
    struct node* prev,* next;
}Node;
Node* head;
void Init()
{
    head=(Node*)malloc(sizeof(Node));
    head->next=head;
    head->prev=head;
}

Node* FindNode(int x)
{
	Node*temp=head->next;
	while(temp!=head&&temp->value!=x)
        temp=temp->next;
    return temp;
}
void Insert(int x)
{
	Node*temp=(Node*)malloc(sizeof(Node));
    temp->value=x;
    head->next->prev=temp;
    temp->next=head->next;
    head->next=temp;
    temp->prev=head;
}

void Delete(Node*temp)
{
	if(temp==head)
        return ;
	temp->next->prev=temp->prev;
	temp->prev->next=temp->next;
    free(temp);
}

void DeleteFirst()
{
    Delete(head->next);
}
void DeleteLast()
{
	Delete(head->prev);
}
void PrintList()
{
    Node*temp=head->next;
    int flag=0;
    while(1)
    {
        if(temp==head)
            break;
        else
        {
            if(flag++>0)
                printf(" ");
            printf("%d",temp->value);
            temp=temp->next;
        }
    }
    printf("\n");
}
int main()
{
	int n;
	int i;
	scanf("%d",&n);
	char str[12];
	int x;
	Init();
    /*
	while(n--)
	{
		scanf("%s%d",str,&x);
		if(str[0]=='i'){Insert(x);}
		else if(str[0]=='d'&&str[6]=='F')DeleteFirst();
		else if(str[0]=='d'&&str[6]=='L')DeleteLast();
		else if(str[0]=='d'){Delete(FindNode(x));}
	}
    */

	for(i = 0; i < n; i++) {
        scanf("%s %d", str, &x);
        if (str[0] == 'i') {
            Insert(x);
        }
        else if(str[0] == 'd') {
            if(str[6] == 'F')
                DeleteFirst();
            else if(str[6] == 'L')
                DeleteLast();
            else
                //DeleteValue(x);
                Delete(FindNode(x));
        }
    }
    /*
    Node* temp=head->next;
    while(temp->next!=head)
    {
        printf("%d ",temp->value);
        temp=temp->next;
    }
    printf("%d\n",temp->value);
    */
    PrintList();
	return 0;
}

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

using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t,a,b;
    t = 1;
    while(t--) {
     cin >> a >> b;
     if((a * b) % 2 == 0)
      cout << "Even" << endl;
     else
      cout << "Odd" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>
#include <tuple>
#include <algorithm>
#include <climits>
using namespace std;
using ll = long long;

struct Station{
    int num;
    int silver;
};

int main(){
    int N,M,S;
    cin>>N>>M>>S;
    vector<ll> U,V,A, B, C, D;
    vector<vector<int>> graph(N,vector<int>());
    ll maxa = 0;
    for(int i = 0;i < M;i++){
        int u,v,a,b;
        cin>>u>>v>>a>>b;
        u--;
        v--;
        maxa = max((ll)a,maxa);
        U.push_back(u);
        V.push_back(v);
        A.push_back(a);
        B.push_back(b);
        graph[u].push_back(i);
        graph[v].push_back(i);
    }
    for(int i = 0;i < N;i++){
        int c,d;cin>>c>>d;
        C.push_back(c);
        D.push_back(d);
    }
    ll G = maxa * (N-1);
    G = 2500;
    if(S > G)S = G;
    // for(int i = 0;i < N;i++){
    //     for(int s = 0;s <= 5000;s++)
    //         stats.push_back(Station{i,s});
    // }
    auto comp = [](auto& A, auto& B){
        return get<0>(A) > get<0>(B);
    };
    // cout<<comp(pair<int,Station>{222,Station{0,0}},pair<int,Station>{1,Station{0,0}})<<endl;
    // return 0;
    priority_queue<tuple<ll,ll,ll>, vector<tuple<ll,ll,ll>>, decltype(comp)> q{comp};
    q.push(tuple<ll,ll,ll>(0,0,S));
    // q.push(pair<ll,Station>{10,Station{10,S}});
    // q.push(pair<ll,Station>{40,Station{0,S}});
    // cout<<q.top().first<<endl;
    // return 0;

    vector<vector<ll>> d(N,vector<ll>(G+1,LLONG_MAX));
    vector<ll> d2(N,LLONG_MAX);
    d[0][S] = 0;
    while(q.size() > 0){
        tuple<ll,ll,ll> p = q.top();q.pop();
        ll t = get<0>(p);
        ll num = get<1>(p);
        ll silver = get<2>(p);
        if(d[num][silver] < t)continue;
        // cout<<st.num<<" "<<st.silver<<endl;
        // cout<<p.first<<endl;
        d2[num] = min(d2[num], t);

        if(silver < G){
            ll nextsi = min(G, silver + C[num]);
            ll time = t + D[num];
            if(d[num][nextsi] > time){
                d[num][nextsi] = time;
                q.push(tuple<ll,ll,ll>{time,num,nextsi});
            }
        }

        for(int i = 0;i < graph[num].size();i++){
            int rail = graph[num][i];
            int to = U[rail] == num ? V[rail] : U[rail];
            
            ll time = t + B[rail];
            ll nextsi = silver - A[rail];
            if(nextsi < 0)continue;
            if(d[to][nextsi] > time){
                d[to][nextsi] = time;
                q.push(tuple<ll,ll,ll>{time, to,nextsi});
            }
        }
    }
    for(int i = 1;i < N;i++){
        cout<<d2[i]<<endl;
    }

}

Measured memory_bytes: 7260
#include<algorithm>
#include<cstring>
#include<cctype>
#include<cstdio>
#define rep(i,x,y) for(int i=x; i<=y; ++i)

using namespace std;
int n,a[10];

int main()
{
	scanf("%d",&n);
	rep(i,0,2) a[i]=n%10,n/=10;
	rep(i,0,2) if(a[i]==1) a[i]=9; else if(a[i]==9) a[i]=1;
	printf("%d%d%d\n",a[2],a[1],a[0]);
	return 0;
}

Measured memory_bytes: 128
#include<cstdio>
#include<vector>
#include<queue>
using namespace std;

int main(){
  int n,m;
  vector<int> G[100000];
  queue<int> q;
  int in[100000];
  int rnk[100000];
  scanf("%d %d",&n,&m);
  fill(in,in+n,0);
  fill(rnk,rnk+n,-1);
  for(int i=0;i<m;i++){
    int a,b;
    scanf("%d %d",&a,&b);
    G[a-1].push_back(b-1);
    in[b-1]++;
  }
  for(int i=0;i<n;i++) if(in[i]==0) q.push(i);
  int cnt = 0;
  int flag = 0;
  while(!q.empty()){
    if(q.size()>1) flag = 1;
    int v = q.front(); q.pop();
    rnk[cnt++] = v + 1;
    for(int i=0;i<G[v].size();i++){
      if(--in[G[v][i]]==0) q.push(G[v][i]);
    }
  }
  for(int i=0;i<n;i++) printf("%d\n",rnk[i]);
  printf("%d\n",flag);
  return 0;
}

Measured memory_bytes: 5476
X, N = map(int, input().split())
if N == 0:
    print(X)
    exit()

hukuro = set()
p = [hukuro.add(int(x)) for x in input().split()]
for i in range(120):
    if not X-i in hukuro:
        print(X-i)
        exit()
    elif not X+i in hukuro:
        print(X+i)
        exit()


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

using namespace std;

#define loop(i, n) for(int i = 0;i < int(n);i++)
#define rloop(i, n) for(int i = int(n);i >= 0;i--)
#define range(i, a, b) for(int i = int(a);i <= int(b);i++)
#define SZ(c) int(c.size())
#define ALL(c) c.begin(), c.end()
#define RALL(c) c.rbegin(), c.rend()
#define PI acos(-1)
#define pb push_back
#define mp make_pair
#define fr first
#define sc second
#define sfi1(v) scanf("%d",&v)
#define sfi2(v1, v2) scanf("%d %d",&v1,&v2)
#define sfi3(v1, v2, v3) scanf("%d %d %d",&v1,&v2,&v3)
#define sfll1(v) scanf("%I64d",&v);
#define sfll2(v1, v2) scanf("%I64d %I64d",&v1,&v2)
#define sfll3(v1, v2, v3) scanf("%I64d %I64d %I64d",&v1,&v2,&v3)
#define endl '\n'

typedef vector<int> vi;
typedef vector<pair<int, int> > vii;
typedef long long ll;
typedef pair<int, int> pii;


const int N = 1e5 + 10, LOG_A = 60;
ll basis[LOG_A];

void insertVector(ll mask) {
    for (int i = LOG_A - 1; i >= 0; i--) {
        if ((mask & 1LL << i) == 0) continue;

        if (!basis[i]) {
            basis[i] = mask;
            return;
        }

        mask ^= basis[i];
    }
}

int main() {

#ifndef ONLINE_JUDGE
//    freopen("in.in", "r", stdin);
    //freopen("out.in", "w", stdout);
#endif
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    int n;
    ll all = 0, ans = 0;
    cin >> n;
    vector<ll> v(n);
    for (auto &x : v)cin >> x, all ^= x;
    for (auto &x : v)x &= (~all);
    for (auto &x : v)insertVector(x);
    rloop(i, LOG_A - 1) {
        if (!basis[i])continue;
        if ((ans >> i) & 1)continue;
        ans ^= basis[i];
    }

    cout << ans + ans + all << endl;

    return 0;
}

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

int main()
{
	int k,x;
    cin>>k>>x;
    
    if(500 * k >= x)
    {
        cout<<"Yes"<<endl;
	}
    else
    {
        cout<<"No"<<endl;
    }
	return 0;
}

Measured memory_bytes: 256
#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;
const int mod = 1000000007;
const int INF = 1e18;

signed main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	int n, k;
	cin >> n >> k;
	vector<int> a(n);
	rep(i, 0, n) cin >> a[i];
	vector<int> d;
	rep(i, 0, n){
		int sum = 0;
		rep(j, i, n){
			sum += a[j];
			d.push_back(sum);
		}
	}
	int ans = 0;
	for(int i = 40; i >= 0; i--){
		int cnt = 0;
		rep(j, 0, d.size()){
			if((ans & d[j]) == ans){
				if(d[j] & (1LL << i)){
					cnt++;
				}
			}
		}
		if(cnt >= k){
			ans |= (1LL << i);
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 6128
#include <bits/stdc++.h>
    #define ll long long
    #define sz(a) int((a).size())
    #define fr(i,n) for(int i=0;i<n;i++) 
    #define rf(i,n) for(int i=1;i<=n;i++)
    #define jdb(i,v) for(__typeof(v.begin())i=v.begin(); i!=v.end();i++)
    #define present(c,a) (find(all(c),a) != c.end())
    #define spresent(c,a) (c.find(a)!=c.end())
    #define no(s,c) s.count(c)  
    #define pb push_back 
    #define eb emplace_back
    #define mp make_pair
    #define all(c) (c).begin(),(c).end()
    #define MAX INT_MAX 
    using namespace std;
    #define f first
    #define s second              
    int main()
    {
        ios_base::sync_with_stdio(false);
        cin.tie(NULL);
        int n;
        cin>>n;
        ll ans=0;
        fr(i,n)
        {
            ll a;
            cin>>a;
            ans=__gcd(a,ans);
        }
        cout<<ans<<endl;
        return 0;
    }
       

Measured memory_bytes: 256
#include<stdio.h>
#include<algorithm>
using namespace std;
#define NIL -2000000001
#define MAX 250

int A[MAX];

void printHeap(int n) {
  for ( int i = 0; i < n; i++ ) {
    printf("node %d: key = %d, ", i+1, A[i]);
    if (i+1 != 1) {
      printf("parent key = %d, ", A[(i+1)/2-1]);
    }
    if (A[2*(i+1)-1] != NIL && 2*(i+1)-1 < MAX) {
      printf("left key = %d, ", A[2*(i+1)-1]);
    }
    if (A[2*(i+1)+1-1] != NIL && 2*(i+1)+1-1 < MAX) {
      printf("right key = %d, ", A[2*(i+1)+1-1]);
    }
    printf("\n");
  }
}

int main() {
  for ( int i = 0; i < MAX; i++ ) {
    A[i] = NIL;
  }
	int n;
  scanf("%d", &n);
  for ( int i = 0; i < n; i++ ) {
    scanf("%d", &A[i]);
  }

  printHeap(n);

  return 0;
}



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

int main() {
  string a,b;
  cin >> a >> b;
  if(a == "H" && b == "H"){
    cout << "H" << endl;
  }else if(a == "H" && b == "D"){
    cout << "D" << endl;
  }else if(a == "D" && b == "H") {
    cout << "D" << endl;
  }else if(a == "D" && b == "D") {
    cout << "H" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin>>n;
  string s;
  cin>>s;
  s+=s[0];
  for(int i=0;i<2;i++){
    for(int j=0;j<2;j++){
      string a;
      a+=(i?'S':'W');
      a+=(j?'S':'W');
      for(int k=2;k<=n+1;k++){
	if(s[k-1]=='o'){
	  if(a[k-1]=='S')a+=a[k-2];
	  else a+=(a[k-2]=='W'?'S':'W');
	}else{
	  if(a[k-1]=='S')a+=(a[k-2]=='W'?'S':'W');
	  else a+=a[k-2];
	}
      }
      //cout<<a<<endl;
      if(a[0]==a[n]&&a[1]==a[n+1]){
	for(int i=0;i<n;i++)cout<<a[i];
	cout<<endl;
	return 0;
      }
    }
  }
  cout<<-1<<endl;
  return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <functional>
#include <limits.h>
#include <set>
#include <map>
#include <tuple>
using namespace std;

#include <chrono>

#define ll long long
#define ull unsigned long long
#define rep(i,N) for (ll i=0;i<N;i++)
#define loop(i,N,M) for(ll i=N;i<M;i++)
#define MAX(v) *max_element(v.begin(),v.end())
#define MIN(v) *min_element(v.begin(),v.end())
#define SORTL2S(type,v) sort(v.begin(),v.end(),greater<type>())
#define SORTS2L(type,v) sort(v.begin(),v.end())
#define SORTMF(v,func) sort(v.begin(),v.end(),func)

ll debugFlag = false;
template<typename T> void debug(T&);
template<typename T> void debug(T&, bool);
template<typename T> void debug(vector<T>&);
template<typename T> void debug(vector<T>&, bool);
template<typename T, typename U> void debug(pair<T, U>&);
template<typename T, typename U> void debug(pair<T, U>&, bool);

template<typename T>
void debug(T& obj) {
	debug(obj, true);
}

template<typename T>
void debug(T& obj, bool lnFlag) {
	if (!debugFlag) return;
	cout << obj;
	if (lnFlag) cout << endl;
}

template<typename T>
void debug(vector<T>& obj) {
	debug(obj, true);
}

template<typename T>
void debug(vector<T>& obj, bool lnFlag) {
	if (!debugFlag) return;
	cout << "[";
	rep(i, obj.size()) {
		if (i != 0) cout << ",";
		debug(obj[i], false);
	}
	cout << "]";
	if (lnFlag) cout << endl;
}

template<typename T, typename U>
void debug(pair<T, U>& obj) {
	debug(obj, true);
}

template<typename T, typename U>
void debug(pair<T, U>& obj, bool lnFlag) {
	if (!debugFlag) return;
	cout << "(";
	debug(obj.first, false);
	cout << ",";
	debug(obj.second, false);
	cout << ")";
	if (lnFlag) cout << endl;
}

ll GCD(ll x, ll y) {
	ll tmp;
	if (y > x) {
		tmp = x;
		x = y;
		y = tmp;
	}
	while (x%y != 0) {
		tmp = y;
		y = x % y;
		x = tmp;
	}
	return y;
}

void solve() {

	chrono::system_clock::time_point start, end;
	start = chrono::system_clock::now();

	ll A, B;
	cin >> A >> B;

	map<ll, bool> mp;

	ll num2 = GCD(A, B);

	for (ll i = 2; num2 != 1; i++) {
		if (num2%i == 0) {
			mp[i]=true;
			num2 = num2 / i;
			i--;
		}

		end = chrono::system_clock::now();
		double time = static_cast<double>(chrono::duration_cast<chrono::microseconds>(end - start).count() / 1000.0);
		if (time > 1800) {
			cout << mp.size()+2;
			return;
		}

	}

	cout << mp.size() + 1;

}


int main(int argc, char* argv[]) {
	if (argc == 2 && string(argv[1]) == "debug") debugFlag = true;
	solve();
	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();
    	int cur = 0;
    	long sum = 0;
    	for (int i = 0; i < n; i++) {
    	    int x = sc.nextInt();
    	    if (cur <= x) {
    	        cur = x;
    	    } else {
    	        sum += cur - x;
    	    }
    	}
    	System.out.println(sum);
    }
}



Measured memory_bytes: 58892
#include <stdio.h>

int main(void){
  int n,k;
  int x,y;
  int z=0;
  int d;
  scanf("%d",&n);
  scanf("%d",&k);
  int a[n];
  for(x=0;x<n;x++){
    a[x]=0;
  }
  for(x=0;x<k;x++){
    scanf("%d",&d);
    int A[d];
    for(y=0;y<d;y++){
      scanf("%d",&A[y]);
    }
    for(y=0;y<d;y++){
      a[A[y]-1]++;
    }
  }
  for(x=0;x<n;x++){
    if(a[x]==0){
      z++;
    }
  }
  printf("%d",z);  
  return 0;
}


Measured memory_bytes: 1736
from collections import Counter


def main():
    n = int(input())
    As = list(int(input()) for _ in range(n))
    As_count = Counter(As)
    ans = 0
    for _, count in As_count.items():
        if (count % 2) == 0:
            continue
        ans += 1
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 20744
# coding: utf-8
import numpy as np


def solve(*args: str) -> str:
    n, m, x = map(int, args[0].split())
    inf = 10**12

    C = []
    A = []
    for CA in map(str.split, args[1:]):
        C.append(int(CA[0]))
        A.append(CA[1:])

    A = np.array(A, int)

    ret = inf
    for b in range(2**n):
        S = np.zeros(m, int)
        c = 0
        for i in range(n):
            if (b >> i) & 1 == 1:
                S += A[i]
                c += C[i]
            if all(x <= S):
                ret = min(ret, c)

    return str(ret if ret < inf else -1)


if __name__ == "__main__":
    print(solve(*(open(0).read().splitlines())))


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

int main() {
  int L, R, d;
  cin >> L >> R >> d;
  int Rd, Ld;
  Rd = R / d;
  if (L == 1) {
    Ld = 0;
  }
  else {
    Ld = (L - 1) / d;
  }
  cout << Rd - Ld << endl;
  return 0;
}


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

int main(){
    int n; cin >> n;
    vi a(n);
    ll comfort = 0LL;
    priority_queue<tuple<int,int,int>> cir;
    for(int ix=0;ix<n;ix++) cin >> a.at(ix);
    sort(a.begin(),a.end());
    // tuple (friendry,left,right)
    cir.push(make_tuple(a.at(n-1),a.at(n-1),a.at(n-1)));
    for(int ix=0;ix<n-1;ix++){
        int tmp,l,r;
        tie(tmp,l,r) = cir.top();
        cir.pop();
        comfort += tmp;
        cir.push(make_tuple(min(a.at(n-2-ix),l),l,a.at(n-2-ix)));
        cir.push(make_tuple(min(a.at(n-2-ix),r),a.at(n-2-ix),r));
    }
    cout << comfort << endl;
}

Measured memory_bytes: 7140
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<limits.h>
#include<cmath>
#include<queue>
#include<stack>

#include<stdio.h>
#include<stdlib.h>

#define rep(i,n) for(ll i = 0; i < (ll)n; i++)
#define swap(a,b) a^=b;b^=a;a^=b;
#define chmax(a,b) {if(a < b) a = b;}
#define chmin(a,b) {if(a > b) a = b;}

using namespace std;
typedef long long ll;
const ll INF = 1LL << 60;

int main(void) {
	cin.tie(0);
	ios::sync_with_stdio(false);
	//Program Start	

	int N, K;
	cin >> N >> K;
	vector<int> p(N);
	rep(i, N) {
		cin >> p[i];
	}

	sort(p.begin(), p.end());

	int ans = 0;

	rep(i, K) {
		ans += p[i];
	}


	cout << ans << endl;

EndPoint:;

	//Program End
#ifndef DEBUG
	system("pause");
#endif // !DEBUG

	return 0;
}




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

int main() {
  int L, R;
  cin >> L >> R;

  // naive solution
  // constexpr unsigned long long mod = 2019;
  // int ans = 2019;

  // for (int i = L; i <= R-1; i++) {
  //   for (int j = i+1; j <= R; j++) {
  //     ans = min(ans, (int) ((unsigned long long) (i * j) % mod));
  //   }
  // }

  // cout << ans << endl;

  if (R-L >= 2018) {
    cout << 0 << endl;
    return 0;
  }
  
  constexpr int mod = 2019;
  int ans = 2019;

  L %= mod, R %= mod;

  for (int i = L; i <= R-1; i++) {
    for (int j = i+1; j <= R; j++) {
      ans = min(ans, (i * j) % mod);
    }
  }

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

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

const int INF = 1e+8;
// f[k] := k テ」ツつ津ヲツュツ」テ・ツ崢崚ゥツ敖「テ、ツスツ禿ヲツ閉ーテ」ツ?ョテ・ツ陳古」ツ?ィテ」ツ?療」ツ?ヲティツ。ツィテ」ツ?凖」ツ?淌」ツつ?」ツ?ォテ・ツソツ?ィツヲツ?」ツ?ェテヲツュツ」テ・ツ崢崚ゥツ敖「テ、ツスツ禿ヲツ閉ーテ」ツ?ョテ・ツ?凝ヲツ閉ーテ」ツ?ョテヲツ慊?・ツーツ湘・ツ?、
int f[1000001];
// g[k] := k テ」ツつ津・ツ・ツ?ヲツ閉ーテ」ツ?ョテヲツュツ」テ・ツ崢崚ゥツ敖「テ、ツスツ禿ヲツ閉ーテ」ツ?ョテ・ツ陳古」ツ?ィテ」ツ?療」ツ?ヲティツ。ツィテ」ツ?凖」ツ?淌」ツつ?」ツ?ォテ・ツソツ?ィツヲツ?」ツ?ェテ・ツ・ツ?ヲツ閉ーテ」ツ?ョテヲツュツ」テ・ツ崢崚ゥツ敖「テ、ツスツ禿ヲツ閉ーテ」ツ?ョテ・ツ?凝ヲツ閉ーテ」ツ?ョテヲツ慊?・ツーツ湘・ツ?、
int g[1000001];

int main(){
	fill(f, f + 1000001, INF);
	fill(g, g + 1000001, INF);
	vector<int> a, b;
	for(int i = 0 ; true ; i++ ){
		int k = i * (i + 1) * (i + 2) / 6;
		if( 1e+6 < k ) break;
		
		if( k % 2 == 1 ){
			b.push_back(k);
			g[k] = 1;
		}
		a.push_back(k);
		f[k] = 1;
	}
	for(int i = 0 ; i < 1000001 ; i++ ){
		if( f[i] ){
			for(int j = 0 ; j < a.size() ; j++ ){
				int k = i + a[j];
				if( 1e+6 < k ) break;
				f[k] = min(f[k], f[i] + 1);
			}
		}
		if( g[i] ){
			for(int j = 0 ; j < b.size() ; j++ ){
				int k = i + b[j];
				if( 1e+6 < k ) break;
				g[k] = min(g[k], g[i] + 1);
			}
		}
	}
	
	int N;
	while( cin >> N , N ){
		cout << f[N] << " " << g[N] << endl;
	}
}

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

int main() {
	int a, b, n;
	string op;
	for (int i = 0; i < 10000; i++) {
		cin >> a >> op >> b;
		if (op == "+") {
			n = a + b;	
		}
		else if (op == "-") {
			n = a - b;
		}
		else if (op == "*") {
			n = a * b;	
		}
		else if (op == "/") {
			n = a / b;
		}
		else if (op == "?") {
			break;
		}
		cout << n << endl;
	}
	
	return 0;
}


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

int main(){
    string S,T;
    cin >> S >> T;

    int count=0;
    for(int i=0; i<S.length(); i++){
        if(S[i]!=T[i]) count++;
    }

    cout << count << endl;

    return 0;
}

Measured memory_bytes: 3800
import java.io.*;
import java.util.*;

public class Main {
  private static int solve(int n, int k, int[] ls) {
    Arrays.sort(ls);
    int sum = 0;
    for (int i = 0; i < k; i++) {
      sum += ls[n - 1 - i];
    }
    return sum;
  }
  
  private static void execute(ContestReader reader, PrintWriter out) {
    int n = reader.nextInt();
    int k = reader.nextInt();
    int[] ls = reader.nextInt(n);
    out.println(solve(n, k, ls));
  }
  
  public static void main(String[] args) {
    ContestReader reader = new ContestReader(System.in);
    PrintWriter out = new PrintWriter(System.out);
    execute(reader, out);
    out.flush();
  }
}

class ContestReader {
  private BufferedReader reader;
  private StringTokenizer tokenizer;
  
  ContestReader(InputStream in) {
    reader = new BufferedReader(new InputStreamReader(in));
  }
  
  public String next() {
    while (tokenizer == null || !tokenizer.hasMoreTokens()) {
      try {
        tokenizer = new java.util.StringTokenizer(reader.readLine());
      } catch (Exception e) {
        throw new RuntimeException(e);
      }
    }
    return tokenizer.nextToken();
  }
  
  public int nextInt() {
    return Integer.parseInt(next());
  }
  
  public long nextLong() {
    return Long.parseLong(next());
  }
  
  public double nextDouble() {
    return Double.parseDouble(next());
  }
  
  public String[] next(int n) {
    String[] array = new String[n];
    for (int i = 0; i < n; i++) {
      array[i] = next();
    }
    return array;
  }
  
  public int[] nextInt(int n) {
    int[] array = new int[n];
    for (int i = 0; i < n; i++) {
      array[i] = nextInt();
    }
    return array;
  }
  
  public long[] nextLong(int n) {
    long[] array = new long[n];
    for (int i = 0; i < n; i++) {
      array[i] = nextLong();
    }
    return array;
  }
  
  public double[] nextDouble(int n) {
    double[] array = new double[n];
    for (int i = 0; i < n; i++) {
      array[i] = nextDouble();
    }
    return array;
  }
  
  public char[] nextCharArray() {
    return next().toCharArray();
  }
  
  public int[][] nextInt(int n, int m) {
    int[][] matrix = new int[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        matrix[i][j] = nextInt();
      }
    }
    return matrix;
  }
  
  public long[][] nextLong(int n, int m) {
    long[][] matrix = new long[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        matrix[i][j] = nextLong();
      }
    }
    return matrix;
  }
  
  public double[][] nextDouble(int n, int m) {
    double[][] matrix = new double[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        matrix[i][j] = nextDouble();
      }
    }
    return matrix;
  }
  
  public char[][] nextCharArray(int n) {
    char[][] matrix = new char[n][];
    for (int i = 0; i < n; i++) {
      matrix[i] = next().toCharArray();
    }
    return matrix;
  }
}


Measured memory_bytes: 23380
#include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long LL;
const int N = 1e5 + 5;
LL a[3];
int main(){
  bool flag=false;
  for(int i=0;i<3;++i){
    scanf("%lld",&a[i]);
    if(a[i]%2==0)flag=true;
  }
  if(flag){
    printf("0\n");
    return 0;
  }
  sort(a,a+3);
  printf("%lld\n",a[0]*a[1]);
  return 0;
}

Measured memory_bytes: 128
#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std;

int main() {
  int n;
  scanf("%d", &n);
  int ab = 0, ba = 0, a = 0, b = 0;
  for (int i = 0; i < n; i++) {
    char s[15];
    scanf("%s", s);
    int m = strlen(s);
    if (s[0] == 'B' && s[m - 1] == 'A') {
      ba++;
    } else if (s[0] == 'B') {
      b++;
    } else if (s[m - 1] == 'A') {
      a++;
    }
    for (int i = 0; i < m - 1; i++) {
      if (s[i] == 'A' && s[i + 1] == 'B') {
        ab++;
      }
    }
  }
  int ans = ab;
  if (a == 0 && ba > 0) {
    a++;
    ba--;
  }
  if (a > 0) {
    ans += ba;
  }
  ans += min(a, b);
  printf("%d\n", ans);
  return 0;
}

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

int main(){
    int n; cin >> n;
    vector<ll> a(n); rep(i,n) cin >> a[i];
    int minus = 1;
    ll as = 0;
    rep(i,n-1){
        as += minus*a[i];
        minus *= -1;
    }
    ll x = as + a[n-1];
    cout << x << " ";
    x /= 2;
    rep(i,n-1){
        x = a[i]-x;
        cout << 2*x << " ";
    }
}

Measured memory_bytes: 2048
N = int(input())
Weight = list(map(int, input().split()))

S1 = 0
S2 = 0
diff = 0
min_diff = 255

for T in range(N):
    S1 = 0
    S2 = 0
    for i in range(N):
        if i <= T:
            S1 += Weight[i]
        else:
            S2 += Weight[i]

    diff = abs(S1 - S2)
    if diff < min_diff:
        min_diff = diff

print(min_diff)

Measured memory_bytes: 3064
#include <iostream>

using namespace std;

#define FOR(i,a,n) for(i=a;i<=n;++i)

int main(void){
    int n;
    cin >> n;
    
    long long L[87];
    L[0]=2;
    L[1]=1;
    int i;
    FOR(i,2,n){
        L[i]=L[i-1]+L[i-2];
    }
    
    cout << L[n];
    
    return 0;
    
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
const ll MOD = 1000000007;

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

    vector<int> divs;
    for(int i=1;i<=max(A, B);i++){
        if(A % i == 0 && B % i == 0){
            divs.push_back(i);
        }
    }
    cout << divs[divs.size() - K] << endl;
    return 0;
}

Measured memory_bytes: 256
N = int(input())
P = input().replace(" ","")
Q = input().replace(" ","")

def add_up(string, left):
  string_set = set()
  if len(left) == 0:
    return {string}
  
  for number in left:
    string_set |= add_up(string+str(number), left-{number})
  return string_set

l = sorted(list(add_up("",set([i+1 for i in range(N)]))))
print(abs(l.index(Q)-l.index(P)))


Measured memory_bytes: 58972
#include <iostream>

using namespace std;

int n, a, b;

int calc(int x)
{
	int ret = 0;
	for(;x;x/=10) ret += x % 10;
	return ret;
}

int main(void)
{
	cin >> n >> a >> b;
	
	int ans = 0;
	for(int i = 1; i <= n; i++){
		int x = calc(i);
		if(a <= x && x <= b) ans += i;
	}
	cout << ans << endl;
	return 0;
}

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

int main(){
  long long a, b, p, q, r, t = 1e12; cin >> a >> b;
  rep(i, a){
    p = i * b;
    q = (a-i)/2*b;
    r = (a-(a+i)/2)*b;
    t = min(t, max(p, max(q, r)) - min(p, min(q, r)));
    q = (a-i)*(b/2);
    r = (a-i)*(b-b/2);
    t = min(t, max(p, max(q, r)) - min(p, min(q, r)));
  }
  rep(i, b){
    p = i * a;
    q = (b-i)/2*a;
    r = (b-(b+i)/2)*a;
    t = min(t, max(p, max(q, r)) - min(p, min(q, r)));
    q = (b-i)*(a/2);
    r = (b-i)*(a-a/2);
    t = min(t, max(p, max(q, r)) - min(p, min(q, r)));
  }
  cout << t << "\n";
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

void calculate(vector<int>& a, vector<int>& b, vector<int>& c, vector<int>& d,
	       vector<int>& A, int N, int M, int Q, int index, int prev,
	       int& ans)
{
  if (index > N)
    return;
  int sum = 0;
  for (int i = 0; i < Q; i++){
    if (A[b[i] - 1] - A[a[i] - 1] == c[i])
      sum += d[i];
    ans = max(ans, sum);
  }
  for (int i = prev; i <= M; i++){
    A[index] = i;
    calculate(a, b, c, d, A, N, M, Q, index + 1, i, ans);
  }
}

int main(void)
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N, M, Q, ans = 0;
  cin >> N >> M >> Q;
  vector<int> a(Q), b(Q), c(Q), d(Q), A(N, 0);
  for (int i = 0; i < Q; i++)
    cin >> a[i] >> b[i] >> c[i] >> d[i];
  calculate(a, b, c, d, A, N, M, Q, 0, 1, ans);
  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 3608
import java.util.*;
import java.io.*;
import java.util.stream.Stream;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int N = Integer.parseInt(br.readLine());
        
        League league = new League(N);
        
        for(int i = 0; i < N; i++){
            String[] stdR = br.readLine().split(" ");
            league.A[i] = Stream.of(stdR).mapToInt(Integer::parseInt).map(num -> num - 1).toArray();
        }
        
        league.exec();
    }
}


class League{
    int N;
    int[][] A;
    ArrayDeque<Game> queue;
    ArrayDeque<Game> nextQueue;
    int[] matchOrder;
    boolean[][] done;
    
    public League(int N){
        this.N = N;
        A = new int[N][N-1];
        matchOrder = new int[N];
        done = new boolean[N][N];
    }
    
    public void exec(){
        int ans = 0;
        queue = new ArrayDeque();
        nextQueue = new ArrayDeque();
        
        for(int i = 0; i < N; i++){
            check(i);
        }
        
        while ( !nextQueue.isEmpty() ){
            
            queue = nextQueue;
            nextQueue = new ArrayDeque<Game>();
            ans++;
            
            while( !queue.isEmpty() ) {
                Game game = queue.removeFirst();
                if (done[game.a][game.b] || done[game.b][game.a]) {
                    continue;
                }
                done[game.a][game.b] = true;
                matchOrder[game.a]++;
                matchOrder[game.b]++;
                check(game.a);
                check(game.b);
            }
        }
        
        boolean ok = true;
        for (int i=0; i<N; i++) {
            if (matchOrder[i] != N-1) {
            ok = false;
            break;
            }
        }
        
        System.out.println( ok ? ans : -1);
    }
    
    private void check(int i){
        if (matchOrder[i] >= N - 1) return;
        
        int opponent = A[i][matchOrder[i]];
        
        if (matchOrder[opponent] >= N - 1) return;
        
        if (A[opponent][matchOrder[opponent]] == i ) {
            nextQueue.add(new Game(i, opponent));
        }
    }
}

class Game {
    int a;
    int b;
    
    public Game(int a, int b){
        this.a = a;
        this.b = b;
    }
    
    public String toString(){
        return "a=" + a + " " + "b=" + b;
    }
}

Measured memory_bytes: 96476
#include <cstdio>
#include <cmath>
#include <iostream>
#include <vector>
#include <string>
#include <utility>
#include <algorithm>
#include <queue>
using namespace std;
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define REP(i,n) for(ll i=0;i<n;i++)
#define REPR(i,n) for(ll i=n-1;i>=0;i--)

typedef long long ll;
#define INF 1e18

int main(){
	ll s; cin>>s;
	ll w; cin>>w;
	if(w>=s){
		cout<<"unsafe"<<endl;
	}else{
		cout<<"safe"<<endl;
	}

	return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
int main(){
    int n,k,A[200000],dp[200000];
    cin>>n>>k;
    rep(i,n) cin>>A[i];
    dp[0]=2;
    rep(i,k){
        int z=0;
        rep(j,n) if(dp[i+1-A[j]]!=2) z++;
        if(z==n) dp[i+1]=2;
        else dp[i+1]=1;
    }
    if(dp[k]==1) cout<<"First";
    else cout<<"Second";
}

Measured memory_bytes: 640
/*Function Template*/
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
const int MAX = 510000;
const int MOD = 1e17;
#define rep(i, n) for(ll i = 0; i < (n); i++)
#define Rep(i, n) for(ll i = 1; i < (n); i++)
#define ALL(a)  (a).begin(),(a).end()
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
ll fac[MAX], finv[MAX], inv[MAX];


template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (ll i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }

}
ll Len(ll n) {
  ll s=0;
  while(n!=0) s++, n/=10;
  return s;
}


ll Sint(ll n) {
  ll m=0,s=0,a=n;
  while(a!=0) s++, a/=10;
  for(ll i=s-1;i>=0;i--) m+=n/((ll)pow(10,i))-(n/((ll)pow(10,i+1)))*10;
  return m;
}


ll Svec(vector<ll> v){
  ll n=0;
  for(ll i=0;i<v.size();i++) n+=v[i];
  return n;
}


ll GCD(ll a,ll b) {
  return b ? GCD(b,a%b) : a;
}


ll LCM(ll a,ll b){
  return a/GCD(a,b)*b;
}


ll Factorial(ll n){
  ll m=1;
  while(n>=1) m*=n,n--;
  return m;
}

void runlength(string s,vector<pair<char,ll>> &p){
  ll x=1;
  if(s.size()==1){
    p.push_back(pair<char,ll>(s[0],1));
  }
  for(ll i=0;i<s.size()-1;i++){
    if(s[i]==s[i+1]){
      x++;
      if(i==s.size()-2){
        p.push_back(pair<char,ll>(s[i],x));
      }
    }else{
      p.push_back(pair<char,ll>(s[i],x));
      x=1;
      if(i==s.size()-2){
        p.push_back(pair<char,ll>(s[s.size()-1],x));
      }
    }
  }
}




ll COM(ll n,ll k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

const int MAX_N=100010;
vector<bool> sieve_of_eratosthenes(){
  vector<bool> isPrime(MAX_N+1,true);
  for(int i=2;i<=MAX_N;i++){
    if(isPrime[i]){
      for(int j=2*i;j<=MAX_N;j+=i){
        isPrime[j]=false;
      }
    }
  }
  return isPrime;
}



/*↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓*/
int main() {
  IOS;
  ll n;
  cin>>n;
  vector<ll> v(n);
  rep(i,n) cin>>v[i];
  ll ans=MOD,tmp=v[0],sum=Svec(v)-v[0];
  rep(i,n-1){
    chmin(ans,abs(tmp-sum));
    
    tmp+=v[i+1];
    sum-=v[i+1];
    
  }
  cout<<ans<<endl;
  
  
}


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

typedef long long ll;
typedef unsigned int ui;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<long long> vll;

const int MOD = 1e9 + 7;

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

    int h, w;    
    cin >> h >> w;
    char a;
    vector<vi> dp(h, vi(w));

    for (int i = 0; i < h; ++i) {
        for (int j = 0; j < w; ++j) {
            cin >> a;
            if (a == '.') {
                dp[i][j] = (i > 0 ? dp[i - 1][j] : 0) +
                           (j > 0 ? dp[i][j - 1] : 0);
                if (dp[i][j] >= MOD) {
                    dp[i][j] -= MOD;
                }
                if (i == 0 && j == 0) {
                    dp[i][j] = 1;
                }
            }
            else {
                dp[i][j] = 0;
            }
        }
    }
    cout << dp[h - 1][w - 1] << '\n';

    return 0;
}

Measured memory_bytes: 4224
#define _USE_MATH_DEFINES 
#include<iomanip> 
#include<cmath>  
#include<iostream>
#include<fstream>
#include<vector>
#include<algorithm>
#include<numeric>
#include<bitset>
#include<map>
#include<unordered_map>
#include<set>
#include<unordered_set>
#include<queue>
#include<deque>
#include<stack>
using namespace std;
typedef long long ll;
#define repi(i,a,b) for(ll i = (ll)(a) ; i < (ll)(b) ; i++)
#define repd(i,a,b) for(ll i = (ll)(a) ; i > (ll)(b) ; i--)
#define rd(x) cin >> x
#define wr(x)  cout << x
#define wrln(x) cout << x << endl
const ll MAX_10p5 = 100010;
const ll MAX_10p9 = 1000000010;
const ll MAX_10p18 = 1000000000000000010;
const ll MOD = 1000000007;
const ll m4x[4] = { 1,0,-1,0 };
const ll m4y[4] = { 0,1,0,-1 };
const ll m8x[8] = { 1,1,0,-1,-1,-1,0,1 };
const ll m8y[8] = { 0,1,1,1,0,-1,-1,-1 };
const ll m9x[9] = { 1,1,0,-1,-1,-1,0,1,0 };
const ll m9y[9] = { 0,1,1,1,0,-1,-1,-1,0 };

struct edge {
	ll from, to, cost;
	bool operator<(const edge& right) const {
		return cost < right.cost;
	}
};
struct point {
	ll x, y;
	bool operator<(const point& right) const {
		return x == right.x ? y < right.y : x < right.x;
	}
};

///////////////////////////////////////////////////////////////////////////////////////




int main() {
	string s[3];
	repi(i, 0, 3) rd(s[i]);
	repi(i, 0, 3) {
		char tc;
		tc = (char)((int)(s[i][0] - 'a' + 'A'));
		wr(tc);
	}
	cout << endl;
	return 0;
}


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

int main(){
	
	int n,m;
	cin >> n >> m;
	
	vector<vector<int>> s;
	rep(i,m){
		int k;
		cin >> k;
		vector<int> tmp(k);
		rep(j,k) cin >> tmp[j];
		s.push_back(tmp);
	}
	
	vector<int> p(m);
	rep(i,m) cin >> p[i];
	
	int cnt = 0;
	for(int i = 0; i < (1<<n); i++){
		vector<int> check(m);
		bool allOn = true;
		rep(j,m){
			if(!allOn) break;
			
			rep(k,s[j].size()){
				if(i>>(s[j][k]-1) & 1){ // s[j][k]のスイッチがon
					check[j]++;
				}
			}
			
			if(check[j] % 2 != p[j]) allOn = false;
		}
		if(allOn) cnt++;
	}
	
	cout << cnt << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
int main(){
 
  stack <int> sa;
  string m;
  int cnt=0,result=0,high=0,tmp=0,h[20000],i;
  vector <int> amo;
 
  cin>>m;
  for(i=m.size()-1;i!=-1;i--){
    if(m[i]=='\\') tmp++;
    if(m[i]=='/') tmp--;
    high=max(high,tmp);
    h[i]=high;
  }
 
  for(i=0;i<m.size();i++){
    if(m[i]=='\\'){
      sa.push(i);
    } else if(m[i]=='/' && !sa.empty()) {
      cnt+=i-sa.top();
      sa.pop();
      if(sa.empty()){
        amo.push_back(cnt);
        result+=cnt;
        cnt=0;
      }
    }
    if(i<m.size()-1) if(h[i+1]-h[i]) sa.pop();
  }
  if(amo.empty()) cout<<"0"<<endl<<"0"<<endl;
  else{
    cout<<result<<endl<<amo.size()<<" ";
    for(i=0;i<amo.size()-1;i++) cout<<amo[i]<<" ";
    cout<<amo[amo.size()-1]<<endl;
  }
  return 0;
 
}


Measured memory_bytes: 3312
def Fib(n):
    a, b = 1, 1
    if n == 1:
        return a
    elif n == 2:
        return b
    else:
        for i in range(n-2):
            a, b = b, a + b
        return b
N, M = map(int, input().split())
a = [int(input()) for _ in range(M)]

flag = True
if M == 1:
    print(Fib(a[0])*Fib(N-a[M-1]))
elif M == 0:
    print(Fib(N+1)%1000000007)
else:
    m = Fib(a[0])*Fib(N-a[M-1])
    for i in range(M-1):
        if a[i] + 1 == a[i+1]:
            print(0)
            flag = False
            break
    if flag:
        for j in range(M-1):
            dev = a[j+1]-a[j]-1
            m = m*Fib(dev)%1000000007
        print(m%1000000007)

Measured memory_bytes: 7080
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<utility>
#include<cmath>
#include<climits>
#include<queue>
#include<stack>
#include<numeric>
#include<set>
#include<iomanip>
#include<map>
#include<type_traits>
#include<tuple>
#include<deque>
#include<cassert>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
#define rep(i,N) for(ll (i)=0;(i)<(N);(i)++)
#define chmax(x,y) x=max(x,y)
#define chmin(x,y) x=min(x,y)
const int mod = 1000000007;
const int INF = 1001001001;

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i, n) {
    int t;
    cin >> t;
    t -= i;
    a[i] = t;
  }
  sort(a.begin(), a.end());
  int c = a[n/2];
  ll ans = 0;
  rep(i, n) {
    ans += abs(c - a[i]);
  }
  cout << ans << endl;
}

Measured memory_bytes: 1024
#include "bits/stdc++.h"
 
typedef long long ll;
#define int ll
#define fi first
#define se second
#define SORT(a) sort(a.begin(),a.end())
#define rep(i,n) for(int i = 0;i < (n) ; i++) 
#define REP(i,n) for(int i = 0;i < (n) ; i++) 
#define MP(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define INF LLONG_MAX/2
#define all(x) (x).begin(),(x).end()
#define debug(x) cerr<<#x<<": "<<x<<endl
#define debug_vec(v) cerr<<#v<<":";rep(i,v.size())cerr<<" "<<v[i];cerr<<endl
using namespace std;
int MOD = 998244353;
int n;

signed main(){
    cin >> n;
    vector<string> s(n);
    rep(i,n)cin >> s[i];
    int ans = 0;
    int b = 0,a = 0,ba = 0;

    rep(i,n){
        rep(j,s[i].size()-1){
            if(s[i][j] == 'A' && s[i][j+1] == 'B')ans++;
        }
        if(s[i][0] == 'B' && s[i][s[i].size()-1] == 'A')ba++;
        else if(s[i][0] == 'B')b++;
        else if(s[i][s[i].size()-1] == 'A')a++;
    }
    if(ba == 0){
        ans += min(a,b);
    }else{
        ans += ba-1;
        if(a>0){
            a--;
            ans++;
        }
        if(b>0){
            b--;
            ans++;
        }
        ans += min(a,b);

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

// g++ -std=c++14 code1.cpp
// rm -r -f test;oj dl https://cf17-final-open.contest.atcoder.jp/tasks/cf17_final_a
// rm -r -f test;oj dl http://diverta2019.contest.atcoder.jp/tasks/diverta2019_a

Measured memory_bytes: 768
#include<bits/stdc++.h>
#define ll long long
#define pll pair<ll,ll>
#define pii pair<int,int>
#define rep(i,a,b) for(int i=a;i<=b;++i)
#define per(i,a,b) for(int i=a;i>=b;--i)
#define mem0(x) memset(x,0,sizeof(x))
#define meminf(x) memset(x,0x3f,sizeof(x))
#define VI vector<int>
#define VL vector<ll>
using namespace  std;

double a[200005];
int n,k;

int check(double x){
    ll cnt = 0;
    rep(i,1,n){
        cnt += (ll)(a[i]/x);
        if(fabs(a[i]-(ll)(a[i]/x)*x)<=0.1) {
            --cnt;
        }
    }
    return cnt>k;
}
int main(){
    ios::sync_with_stdio(0);
    cin>>n>>k;

    double l = 1,r= 0;
    rep(i,1,n){
        cin>>a[i];
        r = max(r,a[i]);
    }
    int cnt = 0;
    while(cnt++<100){
        double mid = (l+r)/2;
        if(check(mid)){
            l = mid+0.01;
        }else{
            r = mid;
        }
    }
    cout<<(ll)ceil(l);
}


Measured memory_bytes: 5364