akhauriyash/Code-Regression huggingface dataset:
import math
from collections import deque

s=input()
l=len(s)
n=int(s)
ans=0

dp=[]
for i in range(0,10):
    dp.append([])
    for j in range(0,10):
        dp[i].append(0)

for i in range(1,n+1):
    st=str(i)
    x=int(st[0])
    y=i%10
    dp[x][y]+=1

for i in range(1,n+1):
    st=str(i)
    x=int(st[0])
    y=i%10
    ans+=dp[y][x]

print(ans)

    


Measured memory_bytes: 40812
/*  ***  In The Name of God ... ***  */
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;

#define all(v) v.begin() , v.end()
#define pb push_back

ll n , a , b;

int main ()
{
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	cin >> n >> a >> b;
	ll MinSum = (n - 1) * a + b;
	ll MaxSum = (n - 1) * b + a;
	cout << max(MaxSum - MinSum + 1 , 0LL) << '\n';
}



Measured memory_bytes: 256
n = int(input())
s = [input() for _ in range(n)]
acn = s.count("AC")
wan = s.count("WA")
tlen = s.count("TLE")
ren = s.count("RE")

print("AC x {}".format(acn))
print("WA x {}".format(wan))
print("TLE x {}".format(tlen))
print("RE x {}".format(ren))


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

using namespace std;

int main()
{
    int a,b;
    cin >> a >> b;
    int a_index = b - a - 1;
    int a_tall = 0;

    for(int i = 0; i < a_index; ++i){
        a_tall += (i+1);
    }
    cout << a_tall - a << endl;
    return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define int long long
using namespace __gnu_pbds;
using namespace std;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
 
signed main()
{
     ios_base::sync_with_stdio(false);
     cin.tie(NULL);  
   
 #ifndef ONLINE_JUDGE
    if(fopen("INPUT.txt","r"))
    {
    freopen ("INPUT.txt" , "r" , stdin);
    freopen ("OUTPUT.txt" , "w" , stdout);
    }
 #endif
 
// -------------------------------------Code starts here---------------------------------------------------------------------     

    int n,m;
    cin>>n>>m;
    int ans=0;
    ans+=((n-1)*n)/2;    
    ans+=((m-1)*m)/2;    
    cout<<ans;

// -------------------------------------Code ends here------------------------------------------------------------------
     clock_t clk;
 	clk = clock();
 
    clk = clock() - clk;
 	cerr << fixed << setprecision(6) << "Time: " << ((double)clk)/CLOCKS_PER_SEC << "\n";
 	return 0;
 }


Measured memory_bytes: 256
# -*- coding: utf-8 -*-


def main():
    """Function."""
    a, b, k = map(int, input().split())

    check = set()
    for i in range(k):
        temp = a + i
        if temp > b:
            pass
        else:
            check.add(temp)
    for i in range(k):
        temp = b - k + i + 1
        if temp < a:
            pass
        else:
            check.add(temp)

    uniq = list(check)
    uniq.sort()
    for i in uniq:
        print(i)


if __name__ == "__main__":
    main()


Measured memory_bytes: 3064
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <set>
#include <map>
#include <queue>
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstring>
#include <cctype>
#include <cassert>
#include <limits>
#include <functional>
#include <iomanip>
#include <complex>
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define rer(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i))
#define reu(i,l,u) for(int (i)=(int)(l);(i)<(int)(u);++(i))
#if defined(_MSC_VER) || __cplusplus > 199711L
#define aut(r,v) auto r = (v)
#else
#define aut(r,v) __typeof(v) r = (v)
#endif
#define each(it,o) for(aut(it, (o).begin()); it != (o).end(); ++ it)
#define all(o) (o).begin(), (o).end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))
#define mset(m,v) memset(m,v,sizeof(m))
#define INF 0x3f3f3f3f3f3f3f3fLL
#define SIZE 100005

using namespace std;
typedef vector<int> vi; typedef pair<int, int> pii; typedef vector<pair<int, int> > vpii; typedef long long ll;
typedef pair<int,ll> pill; typedef pair<ll,int> plli; 
typedef pair<double, int> pdi;
template<typename T, typename U> inline void amin(T &x, U y) { if(y < x) x = y; }
template<typename T, typename U> inline void amax(T &x, U y) { if(x < y) x = y; }
typedef complex<double> P;
long long int MOD = 1000000007;

int main(){
	int A,B,N;
	cin>>N>>A>>B;
	if((B-A)%2==1)cout<<"Borys"<<endl;
	else cout<<"Alice"<<endl;
}


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

#define NL '\n'
#define C char
#define D double
#define F float
#define S string
#define sz(x) x.size()
#define INF LONG_LONG_MAX
#define PI (2.0*acos(0.0))
#define sfi(x) scanf("%d",&x)
#define sfi2(x,y) scanf("%d %d",&x,&y)
#define sfi3(x,y,z) scanf("%d %d %d",&x,&y,&z)
#define sfl(x) scanf("%lld",&x)
#define sfl2(x,y) scanf("%lld %lld",&x,&y)
#define sfl3(x,y,z) scanf("%lld %lld %lld",&x,&y,&z)
#define sfd(x) scanf("%lf",&x);
#define max3(a,b,c) max(a,max(b,c))
#define max4(a,b,c,d) max(max3(a,b,c),d)
#define min3(a,b,c) min(a,min(b,c))
#define min4(a,b,c,d) min(a,min3(b,c,d))
#define mem(ara,val) memset(ara,val,sizeof(ara))
#define READ freopen("input.txt","r",stdin)
#define WRITE freopen("output.txt","w",stdout)
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);

typedef long long LL;
typedef unsigned long long ULL;
typedef long double LD;

/*LL gcd(LL a,LL b)
{
    if(b==0)
        return a;
    else
        return gcd(b,a%b);
}
LL lcm(LL a,LL b)
{
    return a/gcd(a,b)*b;
}*/



int main()
{
    int convertFromCopy, digit, convertTo;
    unsigned int convertFrom;
    string stringDigit, answer;
    cin >> convertFrom;
    cin >> convertTo;

    convertFromCopy = convertFrom;

    while (convertFrom != 0){
        digit = convertFrom % convertTo;

        if (digit < 10)
            stringDigit = '0' + digit;
        else
            stringDigit = digit - 10 + 'A';

        answer = stringDigit + answer;

        convertFrom /= convertTo;
    }

cout<<sz(answer);
    //cout << convertFromCopy << " written in base " << convertTo << " is: " << answer;
    return 0;
}


Measured memory_bytes: 256
using namespace std;

#include<bits/stdc++.h>

typedef long long ll;
typedef pair<int, int> ii;
typedef pair<ll, ll> pll;
typedef vector<ii> vii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<vll> vvll;

#define getBit(x,i) (x&(1<<i))
#define setBit(x,i) (x|(1<<i))
#define mem(A,N) memset(A,N,sizeof(A))
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define mp make_pair
#define rep(i, x, y)  for(int i = x; i < y; ++i)
#define Rep(i, x, y)  for(int i = x; i <= y; ++i)
#define srep(i, x, y) for(int i = x; i > y; --i)
#define sRep(i, x, y) for(int i = x; i >= y; --i)
#define all(v) v.std::begin(),v.std::end()
#define Sort(x) sort(x.begin(), x.end())
#define f1(i,n) for (int i=1; i<=n; i++)
#define f0(i,n) for (int i=0; i<n; i++)
#define sz(x) ((int)(x).size())
#define len(x) ((int)(x).length())
#define fi first
#define se second
#define concatenate(a, b) std::copy(b.begin(), b.end(), std::back_inserter(a));
// #define concatenate(a, b) a.insert(b.end(), b.begin(), b.end());
// std::move(b.begin(), b.end(), std::back_inserter(a)); "Undefined behaviour if a actually is b (which is OK if you know that can never happen - but worth being aware of in general purpose code)"
#define makeUnique(v) v.erase(unique(v.begin(), v.end()), v.end())
#define inRange(x, a, b) (a <= x && x < b)

#define linf 0x7FFFFFFFFFFFFFFF
#define inf 0x7FFFFFFF
#define mod 1000000007
#define eps 1e-9
#define Pi 3.14159265358979323846

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define write(x) cerr << #x << " = " << (x) << ", ";
#define writeI0 cerr << "i = " << 0 << ", ";
#define dumpI0 cerr << "i = " << 0 << endl;
#define printSet(s) for(auto it = s.begin(); it!=s.end(); it++) (it==s.begin())? cout << *it : cout << ' ' << *it; cout << endl;
#define printMap(m) for(auto it = m.begin(); it!=m.end(); it++) (it==m.begin())? cout << '(' << it->first << ", " << it->second << ')' : cout << " (" << it->first << ", " << it->second << ')'; cout << endl;
#define printPairSet(s) for(auto it = s.begin(); it!=s.end(); it++) (it==s.begin())? cout << '(' << it->first << ", " << it->second << ')' : cout << " (" << it->first << ", " << it->second << ')'; cout << endl;
#define printVector(x) for(auto it = x.begin(); it!=x.end(); it++) (it==x.begin())? cout << *it : cout << ' ' << *it; cout << endl;
#define printArray(a,x,y) for(auto it = a+x; it != a+y; it++) (it==a+x)? cout << *it : cout << ' ' << *it; cout << endl;
#define PrintArray(a,x,y) for(auto it = a+x; it != a+y+1; it++) (it==a+x)? cout << *it : cout << ' ' << *it; cout << endl;

// ***************** End Of Template ********************

 int a[55];
// int b[100010];
// int c[100010];
string s;
int n, m, k, q;


int main() {
	ios_base::sync_with_stdio(false); cin.tie(NULL);
	int t1, t2, t3; char c1, c2;

	cin >> n; cin.ignore();
	cin >> s;

	int sol = 0;
	for(int i = 0; i < n; i++) {
		if (i < n-2 && s[i] == 'A' && s[i+1] == 'B' && s[i+2] == 'C') {
			sol++;
		}
	}
	cout << sol;


	return 0;
}

Measured memory_bytes: 384
// AOJ DPL_4_B Coin Combination Problem II
// 2018.5.11 bal4u
 
#include <stdio.h>
#include <stdlib.h>

#if 1
#define gc() getchar_unlocked()
#else
#define gc() getchar()
#endif
 
int in()
{
    int n = 0, c = gc();
    do n = 10*n + (c & 0xf), c = gc(); while (c >= '0');
    return n;
}

long long inLL()
{
    long long n = 0, c = gc();
    do n = 10*n + (c & 0xf), c = gc(); while (c >= '0');
    return n;
}

#define MAX  ((1<<20)+5)

long long a[42]; int w;
long long s1[42][MAX]; int w1[42];
long long s2[42][MAX]; int w2[42];

int binarysearch_upper(long long *a, long long x, int r)
{
	int m, l = 0;

    while (l < r) {
        m = (l+r) >> 1;
		if (a[m] <= x) l = m + 1; else r = m;
    }
	return l;
}

int binarysearch_lower(long long *a, long long x, int r)
{
	int m, l = 0;

    while (l < r) {
        m = (l+r) >> 1;
        if (a[m] < x) l = m + 1; else r = m;
    }
	return l;
}

int cmp(long long *a, long long *b)
{
	if (*a < *b) return -1;
	return (*a != *b);
}

long long combi(int n, int k)
{
	long long ans;

	if (s1[n][k]) return s1[n][k];
	if ((k << 1) > n) k = n-k;
	if (k == 0) ans = 1;
	else if (k == 1) ans = n;
	else ans = combi(n-1, k) + combi(n-1, k-1);
	return s1[n][k] = ans;
}

int main()
{
	int N, K, i, j, k, m1, m2, n, lim;
	long long L, R, x, y, ans;

	N = in(), K = in(), L = inLL(), R = inLL();

	w = 0;
	x = y = inLL(); if (y + K-1 <= R) a[w++] = y;
	for (i = 1; i < N; i++) {
		x = inLL();
		if (x != y) y = 0;
		if (x + K-1 <= R) a[w++] = x;
	}

	// identical a[i]
	if (x == y) {
		if (w >= K && (y = x*K) >= L && y <= R) printf("%lld\n", combi(w, K));
		else puts("0");
		return 0;
	}

	m1 = w / 2, lim = 1 << m1;
	for (i = 0; i < lim; i++) {
		x = 0, n = 0;
		for (j = 0; ; j++) {
			if (j == m1) { s1[n][w1[n]++] = x; break; }
			if ((i >> j) & 1) {
				x += a[j];
				if (++n > K) break;
			}
		}
	}

	m2 = w - m1, lim = 1 << m2;
		for (i = 0; i < lim; i++) {
		x = 0, n = 0;
		for (j = 0; ; j++) {
			if (j == m2) { s2[n][w2[n]++] = x; break; }
			if ((i >> j) & 1) {
				x += a[j+m1];
				if (++n > K) break;
			}
		}
	}

	for (i = 0; i <= K; i++) qsort(s2[i], w2[i], sizeof(long long), cmp);

	ans = 0;
	for (i = 0; i <= K; i++) {
		k = K-i;
		for (j = 0; j < w1[i]; j++) {
			y = R-s1[i][j];
			if (y >= 0) {
				ans += n = binarysearch_upper(s2[k], y, w2[k]);
				x = L-s1[i][j];
				if (x > 0) ans -= binarysearch_lower(s2[k], x, n);
			}
		}
	}
	printf("%lld\n", ans);
	return 0;
}


Measured memory_bytes: 19688
#include <memory.h>
#include <iostream>

#define ll long long
#define N 63
#define mod  1000000007

int dp[N][2][2][2];
ll L, R;
 
int add(int x, int y) {
	int ret = (x + y);
	if (ret >= mod) {
		ret -= mod;
	}
	return ret;
}
int solveDp(int ind, int msb, int xeq, int yeq) {
	if (ind < 0) {
		if (msb) {
			return 1;
		}
		return 0;
	}
	int &ret = dp[ind][msb][xeq][yeq];
	if (ret != -1) {
		return ret;
	}
	ret = 0;
	for (int i = 0; i < 2; ++i) {
		for (int j = 0; j < 2; ++j) {
			if (i > j) {
				continue;
			}
			if (xeq && i == 0 && L&(1LL << ind)) {
				continue;
			}
			if (yeq && j == 1 && (R&(1LL << ind)) == 0)
			{
				continue;
			}
			int nxeq, nyeq;
			nxeq = xeq;
			nyeq = yeq;
			if (xeq && i == 1 && (L&(1LL << ind)) ==0 ) {
				nxeq = 0;
			}
			if (yeq && j == 0 && (R&(1LL << ind))) {
				nyeq = 0;
			}
			if (msb == 0) {
				if (i != j) {
					continue;
				}
				if (i == 1) {
					ret = add(ret, solveDp(ind - 1, 1, nxeq, nyeq));
				}
				else {
					ret = add(ret, solveDp(ind - 1, 0, nxeq, nyeq));
				}
			}
			else {
				ret = add(ret, solveDp(ind - 1, 1, nxeq, nyeq));
			}
		}
	}
	return ret;
}
void solve() {
	scanf("%lld %lld", &L, &R);
	memset(dp, -1, sizeof(dp));
	printf("%d\n", solveDp(N-1, 0, 1, 1));
}
int main()
{
	//freopen("input.txt", "r", stdin);
	solve();
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    int map[3][3];
    int ans[3][3];

    for (int i = 0; i < 3; i++)
    {
        for (int j = 0; j < 3; j++)
        {
            cin >> map[i][j];
            ans[i][j] = 0;
        }
    }
    cin >> n;
    int b[n];
    for (int i = 0; i < n; i++)
    {
        cin >> b[i];
    }
    for (int i = 0; i < 3; i++)
    {
        for (int j = 0; j < 3; j++)
        {
            for (int k = 0; k < n; k++){
                if(map[i][j] == b[k]){
                    ans[i][j] = 1;
                }
            }
        }
    }
    if(ans[0][0]+ans[0][1]+ans[0][2]==3||
       ans[1][0]+ans[1][1]+ans[1][2]==3||
       ans[2][0]+ans[2][1]+ans[2][2]==3||
       ans[0][0]+ans[1][0]+ans[2][0]==3||
       ans[0][1]+ans[1][1]+ans[2][1]==3||
       ans[0][2]+ans[1][2]+ans[2][2]==3||
       ans[0][0]+ans[1][1]+ans[2][2]==3||
       ans[0][2]+ans[1][1]+ans[2][0]==3)
       {
           cout << "Yes" << endl;
       }else{cout << "No" << endl;}
       return 0;

}


Measured memory_bytes: 256
def solve():
    answers = []
    ans = []
    def square(n, rest, limit):
        if rest == 0:
            answers.append(' '.join(map(str, ans)))
        else:
            for i in range(rest, 0, -1):
                if i > limit:
                    continue
                ans.append(i)
                square(n, rest - i, i)
                ans.pop()
    
    import sys
    for n in map(int, sys.stdin.readlines()):
        if n == 0:
            break
        square(n, n, n)
    
    print('\n'.join(answers))

solve()


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

int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  for(int i = 0; i < N; i++) 
    cin >> A.at(i);
  sort(A.begin(), A.end());
  int x = A.size() - 1;
  cout << A.at(x) - A.at(0) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define fi first
#define se second
#define pb push_back
#define rep(i, s, n) for (int i = s; i < n; i++)
#define rrep(i, s, n) for (int i = (n)-1; i >= (s); i--)
#define all(a) a.begin(),a.end()
const long long MOD = 1e9+7, INF = 1e18;
template<class T>inline bool chmax(T&a,T b){if(a<b){a=b;return true;}return false;}
template<class T>inline bool chmin(T&a,T b){if(a>b){a=b;return true;}return false;}



signed main(){
	int N,M,T,P;
	vector<int>ans;
	while(cin>>N>>M>>T>>P,N||M||T||P){
		vector<vector<int>>v(M*30,vector<int>(N*30,0));
		rep(i,0,M)rep(j,0,N)v[i][j]=1;
		pair<int,int>now = {0,0};
		rep(_,0,T){
			int a,b;
			cin>>a>>b;
			if(a==2){
				rep(i,0,b){
					rep(j,0,N*30){
						v[now.fi+b+b-i-1][j]+=v[now.fi+i][j];
					}
				}
				now.fi += b;
			}else{
				rep(i,0,M*30){
					rep(j,0,b){
						v[i][now.se+b+b-j-1]+=v[i][now.se+j];
					}
				}
				now.se += b;
			}
			/*
			cout<<now.fi<<" "<<now.se<<endl;
			rep(i,0,M*2){
				rep(j,0,N*2){
					if(j)cout<<" ";
					cout<<v[i][j];
				}
				cout<<endl;
			}
			*/
		}
		rep(i,0,P){
			int a,b;
			cin>>a>>b;
			ans.push_back(v[now.fi+b][now.se+a]);
		}
		/*
		cout<<now.fi<<" "<<now.se<<endl;
		rep(i,0,M*2){
			rep(j,0,N*2){
				if(j)cout<<" ";
				cout<<v[i][j];
			}
			cout<<endl;
		}
		*/
	}
	for(auto e:ans){
		cout<<e<<endl;
	}
}


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

using namespace std;
constexpr int64_t MOD = 1'000'000'007;

template< typename T >
T mod_pow(T x, T n) {
    T ret = 1;
    while(n > 0) {
        if(n & 1) (ret *= x) %= MOD;
        (x *= x) %= MOD;
        n >>= 1;
    }
    return ret;
}

int main(void) {
    int64_t N;
    cin >> N;
    vector<int> cnt(N);
    for(int i=0; i<N; i++) {
        int A;
        cin >> A;
        cnt[A]++;
    }

    try {
        if(N % 2) {
            if(cnt[0] != 1) throw 1;
            for(int j=2; j<N; j+=2) {
                if(cnt[j] != 2) throw 2;
            }
            cout << mod_pow(2L, N/2) << endl;
        } else {
            for(int j=1; j<N; j+=2) {
                if(cnt[j] != 2) throw 3;
            }
            cout << mod_pow(2L, N/2) << endl;
        }
    } catch (...){
        cout << 0 << endl;
    }
    return 0;
}


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

int main() {
	string x;
	cin >> x;
	int zero=0, one=0;
	for (int i = 0; i < x.length(); i++)
	{
		if (x[i] == '0') zero++;
		else one++;
	}
	
	cout << 2*min(one, zero) << endl;
	
	return 0;
}

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

#define whole(f, x, ...)                                 \
  ([&](decltype((x)) whole) {                            \
    return (f)(begin(whole), end(whole), ##__VA_ARGS__); \
  })(x)

using namespace std;
using ll = long long;

map<int64_t, int> prime_factor(int64_t n) {
  map<int64_t, int> ret;
  for (int64_t i = 2; i * i <= n; i++) {
    while (n % i == 0) {
      ret[i]++;
      n /= i;
    }
  }
  if (n != 1) ret[n] = 1;
  return ret;
}

void solve() {
  ll n;
  cin >> n;

  auto p = prime_factor(n);

  ll res = 0;
  for (auto t : p) {
    int cnt = 1;
    while (t.second >= cnt) {
      t.second -= cnt;
      ++cnt;
    }
    res += cnt - 1;
  }
  cout << res << endl;
}

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);

  solve();
  return 0;
}


Measured memory_bytes: 3652
#include<bits/stdc++.h>
using namespace std;
bool check(int n){
if(n<0)
return false;
if(n==0)
return true;
return check(n-4) || check(n-7);
}
int main(){
int n;
cin>>n;
if(check(n)){
cout<<"Yes";
}
else{
cout<<"No";
}
}


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

int main(){

    int a,b;
    cin >> a >>b;

    if(a+b>=10){
        cout << "error" << endl;
    }else{
        cout << a+b << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define REP2(i, n) for (int i = 1; i <= (int)(n); i++)
#define FOR(i, m, n) for (int i = m; i n; i++)
#define SORT(x) sort(x.begin(), x.end())
#define REVE(x) reverse(x.begin(), x.end())
#define all(x) (x).begin(), (x).end()
struct initon
{
    initon()
    {
        cin.tie(0);
        ios::sync_with_stdio(false);
    };
};
int k=0,n=0, m=0, l=0,a=0, b=0, c=0, d=0,e=0,ans=0,ans2=0,x=0,y=0;
string s,t,S;
signed main() {
    cin >> n >> a >> b;
    ans=n/(a+b)*a;
  int rem=n%(a+b);
   ans+=min(rem,a);
cout<<ans<<endl;
}

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

int main() {
  string S;
  cin >> S;
  int N = S.size();
  S += "0";
  vector<int> num(N);
  int val = 1;
  int nn = 0;
  for (int i=1; i<N+1; i++) {
    if (S[i] == S[i-1]) {
      val++;
    }
    else {
      num[nn] = val;
      val = 1;
      nn++;
    }
  }
  bool w = false;
  int ans = 0;
  for (int i=0; i<nn; i++) {
    if (num[i] %3 == 0) {
      ans += num[i]/3*2;
    }
    if (num[i] %3 == 1) {
      ans += num[i]/3*2+1;
      w = false;
    }
    if (num[i] %3 == 2) {
      ans += num[i]/3*2+1;
      if (w) {
        ans++;
        w = false;
      }
      else {
        w = true;
      }
    }
  }
  cout << ans << endl;
  return 0;
}

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

int ZeroThreeFiveSeven(int i) {
  if (i == 0) return 3;
  else if (i == 3) return 5;
  else if (i == 5) return 7;
  else return 9;
}

void Main()
{
  int N; cin >> N;
  int i[9] = {0,0,0,0,0,0,3,3,3};
  int ztfs[4] = {0,3,5,7};
  int tfs[3] = {3,5,7};
  int cnt = 0;
  for (int i0 : ztfs) {
    i[0] = i0;
    for (int i1 : ztfs) {
      i[1] = i1;
      for (int i2 : ztfs) {
        i[2] = i2;
        for (int i3 : ztfs) {
          i[3] = i3;
          for (int i4 : ztfs) {
            i[4] = i4;
            for (int i5 : ztfs) {
              i[5] = i5;
              for (int i6 : tfs) {
                i[6] = i6;
                for (int i7 : tfs) {
                  i[7] = i7;
                  for (int i8 : tfs) {
                    i[8] = i8;
                    int sum = 0;
                    bool check = true;
                    for (int j = 0; j < 8; j++) {
                      sum += i[j];
                      if (sum > 0 and i[j] == 0) {check = false; break;}
                    }
                    if (!check) continue;
                    int num = 0;
                    set<int> se;
                    for (int j = 0; j < 9; j++) {
                      int multiplier = pow(10, j);
                      num += multiplier * i[8-j];
                      se.insert(i[8-j]);
                    }
                    //cout << num << endl;
                    if (se.find(3) != se.end() and se.find(5) != se.end() and
                        se.find(7) != se.end() and num <= N) cnt++;
                  }
                }
              }
            }
          }
        }
      }
    }
  }
  cout << cnt << endl;
}

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


Measured memory_bytes: 4024
#include<bits/stdc++.h>
using namespace std;
const int maxn=20+10;
const int INF=int(1e9)+10;
#define LL long long
char str[maxn][maxn];
int swaped[maxn];
bool used[maxn];
bool ans;
int n,m;
bool check() {    //判断在这种(n行配对)的情况下，是否可以通过列的转换实现对称 
	memset(used,0,sizeof(used));
	for(int i=0; i<m; i++) {       //枚举任意不相等的两列，在这种(n行配对)的情况下，这两列是否相等 
		if(used[i])                //相等则说明这两列可以通过列变换形成对称 
			continue;
		for(int j=0; j<m; j++) {
			bool vis=true;
			if(i==j||used[j])
				continue;
			for(int k=0; k<n; k++) {
				if(str[k][i]==str[swaped[k]][j])
					continue;
				vis=false;
				break;
			}
			if(vis){
				used[i]=used[j]=true;
				break;
			}
		}
	}
	int cnt=0;
	int pos=-1;
	for(int i=0; i<m; i++)   //计算有多少列没配对 
		if(!used[i]) {
			cnt++;
			pos=i;
		}
	if(cnt>=2||(cnt&&(m%2==0))) //没配对数大于等于2或者（列数为奇数且没配对数等于1） 
		return false;           //的情况都说明这种（n行配对）的情况无法通过列转移实现对称 
	if(cnt==1) {                //对于列数m为奇数的情况，需要特判这一列是否可以形成对称 
		for(int i=0; i<n; i++) {
			if(str[i][pos]!=str[swaped[i]][pos])
				return false;
		}
	}
	return true;
}
void dfs(int u,int falg) {   //dfs枚举出所有的（n行配对）的情况 
	if(u==(n+1)>>1) {      //u==(n+1)/2,说明所有的行已经配对成功，这是一种（n行配对）的情况 
		if(check())       //判断列是否通过转换形成对称 
			ans=true;
		return ;
	}
	if(ans==true)
	return;
	for(int i=u; i<n; i++) {
		if(swaped[i]==-1) {
			for(int j=i+1; j<n; j++) {
				if(swaped[j]==-1) {
					swaped[i]=j;
					swaped[j]=i;
					dfs(u+1,falg);
					swaped[i]=-1;
					swaped[j]=-1;
				}
			}
			if(falg) {     //对于行数n为奇数的情况，有一行是关于没有对称行的 
				swaped[i]=i;
				dfs(u+1,false);
				swaped[i]=-1;
			}
		}
	}
}
void init() {
	memset(swaped,-1,sizeof(swaped));
	ans=false;
}
int main() {
	while(~scanf("%d %d",&n,&m)) {
		init();
		for(int i=0; i<n; i++)
			scanf("%s",str[i]);
		if(n&1)
			dfs(0,true);
		else
			dfs(0,false);
		printf("%s\n",ans?"YES":"NO");
	}
	return 0;
}

Measured memory_bytes: 256
# ２部マッチング
# 最大流
# Ford-Fulkerson
N = int(input())
A = [list(map(int, input().split())) for _ in range(N)]
B = [list(map(int, input().split())) for _ in range(N)]

# -1: source, 2N: sink
edge = {-1: {}, 2 * N: {}}
for i, a in enumerate(A):
    edge[i] = {}
    edge[-1][i] = 1
    for j, b in enumerate(B):
        j += N
        if j not in edge:
            edge[j] = {}
        edge[j][2 * N] = 1
        if a[0] < b[0] and a[1] < b[1]:
            edge[i][j] = 1

visited = [False] * (2 * N + 2)
def find_route(start, goal, bottleneck):
    global visited
    visited[start] = True
    if start == goal:
        return bottleneck
    for to in edge[start]:
        if visited[to] or edge[start][to] <= 0:
            continue
        flow = find_route(to, goal, min(bottleneck, edge[start][to]))
        if flow > 0:
            edge[start][to] = edge[start].get(to, 0) - flow
            edge[to][start] = edge[to].get(start, 0) + flow
            return flow
    return 0

ans = 0
while True:
    visited = [False] * (2 * N + 2)
    flow = find_route(-1, 2 * N, float('inf'))
    if flow == 0:
        break
    ans += flow
print(ans)

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

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

#define rep(i, n) for (int i = 0; i < (int)(n); i++)

typedef long long ll;

const string YES = "Yes";
const string NO = "No";

void solve(std::string S)
{
    if (S[2] == S[3] && S[4] == S[5])
    {
        cout << YES << endl;
    }
    else
    {
        cout << NO << endl;
    }
}

int main()
{
    std::string S;
    std::cin >> S;
    solve(S);
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int g[1000][1000];
string s[1000];
int n,m;
inline bool in(int x,int y){
	return x>=0&&x<n&&y>=0&&y<m;
}
int dx[4] = {1,0,-1,0};
int dy[4] = {0,-1,0,1};
int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cin>>n>>m;
	memset(g,-1,sizeof g);
	for(int i=0;i<n;i++)
		cin>>s[i];
	queue<pair<int,int> > q;
	for(int i=0;i<n;i++)
		for(int j=0;j<m;j++)
			if(s[i][j]=='#')
				g[i][j]=0,q.emplace(i,j);
	while(!q.empty()){
		int x,y; tie(x,y) = q.front();q.pop();
		for(int i=0;i<4;i++){
			int nx=x+dx[i],ny=y+dy[i];
			if(in(nx,ny)&&g[nx][ny]==-1){
				g[nx][ny]=g[x][y]+1;
				q.emplace(nx,ny);
			}
		}
	}
	int ans=0;
	for(int i=0;i<n;i++)
		for(int j=0;j<m;j++)
			ans=max(ans,g[i][j]);
	cout<<ans<<endl;
		
}


Measured memory_bytes: 13456
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
typedef long long lint;
 
int main(void)
{
 
  lint a, b, r, x, tmp;
  cin >> a >> b;
 
  x = a * b;
 
  if(a<b){
    tmp = a;
    a = b;
    b = tmp;
  }
 
  r = a % b;
  while(r!=0){
    a = b;
    b = r;
    r = a % b;
  }
  
  cout << x/b << endl;
}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cassert>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <unordered_map>
#include <set>
#include <map>
#define INCANT cin.tie(0), cout.tie(0), ios::sync_with_stdio(0), cout << fixed << setprecision(20);
#define rep(i,n) for (int i=0; i<n;++i)
#define ALL(a)  (a).begin(),(a).end()
#define PI 3.14159265358979
typedef long long ll;
using namespace std;
const ll MOD = 1e9+7LL;
const int INF = 2e9;
int A,B,C,K;

bool dfs(int a,int b,int c,int k) {
  if (a < b && b < c) return true;
  if (k>0) {
    if (dfs(a*2, b, c, k-1)) return true;
    if (dfs(a, b*2, c, k-1)) return true;
    if (dfs(a, b, c*2, k-1)) return true;
  }
  return false;
}

int main() {
  INCANT;
  cin >> A >> B >> C >> K;

  string ans = dfs(A,B,C,K)?"Yes":"No";
  cout << ans << "\n";
  return 0;
}

Measured memory_bytes: 3612
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
const ll INF = 1LL << 60;
const double PI = 3.141592653589793238;
const double EPS = 1e-10;
int a[100];
int main() {
	int N;
	cin >> N;
	for (int i = 0; i < N; i++) {
		cin >> a[i];
	}
	int ans = 1 << 30;
	for (int X = -100; X <= 100; X++) {
		int cost = 0;
		for (int i = 0; i < N; i++) {
			cost += (a[i] - X)*(a[i] - X);
		}
		ans = min(ans, cost);
	}
	cout << ans << endl;
}


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

int main()
{
	int N;
	cin >> N;
	while (N--)
	{
		int n;
		cin >> n;
		int a[n];
		for (int i=0; i<n; i++)
			cin >> a[i];

		vector<int> b(1,0), c(1,0);
		for (int i=0; i<n-1; i++)
		{
			int tmp = a[i+1]-a[i];
			if (tmp > 0)
				b.push_back(tmp);
			else
				c.push_back(-tmp);
		}

		sort(b.begin(), b.end());
		sort(c.begin(), c.end());

		cout << b.back() << ' ' << c.back() << endl;
	}
}

Measured memory_bytes: 0
use std::io;

fn main() {
	let mut buf = String::new();
	io::stdin().read_line(&mut buf).expect("");
	let mut iter = buf.split_whitespace();
	let a = match iter.next().unwrap().parse() {
		Ok(n) => n,
		Err(_) => panic!(""),
	};
	let b = match iter.next().unwrap().parse() {
		Ok(n) => n,
		Err(_) => panic!(""),
	};
	if a < b {
		for n in 0..b {
			print!("{}", a);
		}
		print!("\n");
	}else if b < a {
		for n in 0..a {
			print!("{}", b);
		}
		print!("\n");
	}else{
		for n in 0..a {
			print!("{}", a);
		}
		print!("\n");
	}
}

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

int main() {
	int x, y;
	cin >> x >> y;
	bool f = false;
	for (int i = 0; i <= x; i++) {
		if (4 * i + 2 * (x - i) == y) {
			f = true;
			
		}
	}
	if (f) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
	return 0;
}

Measured memory_bytes: 3636
n, m = map(int, input().split())
a = list(map(int, input().split()))

a.sort()

pairs = [list(map(int, input().split())) for _ in range(m)]
pairs = sorted(pairs, key=lambda x: x[1])
cnt = 0
ans = 0
while cnt < n:
    if pairs != [] and a[-1] < pairs[-1][1] and cnt+pairs[-1][0] <= n:
        cnt += pairs[-1][0]
        ans += pairs[-1][0]*pairs[-1][1]
        pairs.pop(-1)
    elif pairs != [] and a[-1] < pairs[-1][1] and cnt+pairs[-1][0] > n:
        ans += (n - cnt)*pairs[-1][1]
        cnt += n - cnt
        break
    else:
        cnt+= 1
        ans += a[-1]
        a.pop(-1)

print(ans)
 

Measured memory_bytes: 34292
#include<iostream>
#include<string>
#include<math.h>

using namespace std;

int main(){
    int a,ans=0;
    
    cin>>a;
    
    for(int i=0;i<3;i++){
        int tmp=a;
        for(int j=0;j<i;j++){
            tmp=tmp*a;
        }
        ans=ans+tmp;
    }
    cout<<ans<<"\n";
    return 0;
}

Measured memory_bytes: 3628
n = int(input())
s = input()
high = n//2
low = 1
ans = 0

while low <= high:
    t = set()
    i = (high+low)//2
    for j in range(n-i*2+1):
        t.add(s[j:i+j])
        if s[i+j:j+2*i] in t:
            if ans < i:
                ans = i
                low = i+1
                break
    if ans < i:
        high = i-1
print(ans)

Measured memory_bytes: 141148
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
using namespace std;
int main()
{
	int a,b;
	while(~scanf("%d%d",&a,&b)){
		if(a+b >= 10) printf("error\n");
		else printf("%d\n",a+b);
	}
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <vector>
#include <map>

using namespace std;

//vector<int> field;

int n;
int a;
string answer = "YES";

int main()
{
    cin >> n;
    map<int, int> field{};
    for (int i = 0; i < n; ++i)
    {
        cin >> a;
        if (field[a] == 0){
            field[a] = 1;
        }else{
            answer = "NO";
            break;
        }
    }
    cout << answer << endl;

    return 0;
}

Measured memory_bytes: 9600
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//#include <boost/multiprecision/cpp_ll.hpp>
//typedef boost::multiprecision::cpp_ll ll;
typedef long double dd;
#define i_7 (ll)(1E9+7)
//#define i_7 998244353
#define i_5 i_7-2
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
typedef pair<ll,ll> l_l;
ll inf=(ll)1E16;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);
void Min(ll &pos,ll val){pos=min(pos,val);}
void Add(ll &pos,ll val){pos=mod(pos+val);}
dd EPS=1E-9;
string alp="abcdefghijklmnopqrstuvwxyz";
#define endl "\n"
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);


int main(){
    ll n;cin>>n;
    string s[n];rep(i,0,n-1)cin>>s[i];
    ll c[26];rep(i,0,25)c[i]=inf;
    ll cc[26];
    rep(i,0,n-1){
        rep(j,0,25)cc[j]=0;
        rep(j,0,s[i].size()-1){
            rep(k,0,25){
                if(s[i][j]==alp[k]){
                    cc[k]++;
                }
            }
        }
        rep(j,0,25){
            c[j]=min(c[j],cc[j]);
        }
    }
    rep(i,0,25){
        if(c[i]>0){
            rep(j,0,c[i]-1){
                cout<<alp[i];
            }
        }
    }
    cout<<endl;
    
    return 0;
}






Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstring>
#include <algorithm>
#include <functional>
#include <cmath>
#include <set>
#include <queue>
#include <vector>
#include <climits>
using namespace std;

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

	cout << T / A * B << endl;

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#define N 200005
#define X first
#define H second
using namespace std;

typedef long long ll;
ll n, d, a, sum, ans, s[N];
pair<ll, ll> b[N];
int main()
{
	ll i, j;
	cin >> n >> d >> a;
	for (i = 0; i < n; i++) {
		scanf("%lld %lld", &b[i].X, &b[i].H);
	}
	sort(b, b + n);
	for (i = j = 0; i < n; i++) {
		for (; j < i && b[i].X - b[j].X > 2 * d; j++) sum -= s[j];
		s[i] = max(0LL, (b[i].H + a - 1) / a - sum);
		ans += s[i];
		sum += s[i];
	}
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 4992
// Etavioxy
#include<cstdio>
#include<cctype>
#include<cstring>
#include<algorithm>
#include<cmath>
#define il inline
#define ll long long
#define re register
#define rep(i,s,t) for(re int i=(s);i<=(t);i++)
#define rev_rep(i,s,t) for(re int i=(s);i>=(t);i--)
#define each(i,u) for(int i=head[u];i;i=bow[i].nxt)
#define pt(x) putchar(x)
#define pti(x) printf("%d",x)
#define ptll(x) printf("%lld",x)
#define file(s) freopen(s".in" ,"r",stdin),freopen(s".out","w",stdout)
using namespace std;
il int ci(){
	re char ch;int f=1;
	while(!isdigit(ch=getchar()))f=ch=='-'?-1:1;
	re int x=ch^'0';
	while(isdigit(ch=getchar()))x=(x*10)+(ch^'0');
	return f*x;
}
char s[103];
int main(){
	scanf("%s",s+1);
	int n= strlen(s+1);
	int ans= 0;
	for(int x=1,y=n;x<y;x++,y--){
		if( s[x]!=s[y] ) ans++;
	}
	pti(ans),pt('\n');
	return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <ios> 
#include <vector>
#include <string>
#include <algorithm>
#include <functional>
#include <queue>
#include <set>
#include <cmath>
#include <map>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)

using namespace std;
typedef long long int lli;




int main(){
	int N;
	cin >> N;
	
	int prime[30];
	bool isp[100];
	int p = 0;
	//初期化
	for(int i=0;i<=N;i++)
		isp[i]=true;
	isp[0]=isp[1]=false;
	//2以上で素数ならふるい落とす
	for(int i=2;i<=N;i++){
		if(isp[i]){
			p++;
			prime[p]=i;
			for(int j=2*i;j<=N;j+=i) isp[j]=false;
		}
	}
//	cout << N << "以下の素数は"<<p<<"個です"<<endl;
//	for(int i=1;i<=p;i++) cout << prime[i]<<endl;
	
	int nb[30]={};
	rep1(i,p){
		int q=prime[i];
		int t=N;
		while(t>=1){
			t=t/q;
			nb[i]+=t;
		}
	}
	int ct74=0,ct24=0,ct14=0,ct4=0,ct2=0;
	rep1(i,p){
		if(nb[i]>=74)ct74++;
		if(nb[i]>=24)ct24++;
		if(nb[i]>=14)ct14++;
		if(nb[i]>=4)ct4++;
		if(nb[i]>=2)ct2++;
	}
	int ans1,ans2,ans3,ans4;
	ans1=ct74;
	ans2=ct24*(ct2-1);
	ans3=ct14*(ct4-1);
	ans4=ct4*(ct4-1)*(ct2-2)/2;
	cout<<ans1+ans2+ans3+ans4;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String n = sc.next();
        int len = n.length();
        int a = 0; // 01010101
        int b = 0; // 10101010
        for (int i = 0; i < len; i++) {
            char c = n.charAt(i);
            if (i % 2 == 0) {
                if (c == '1') {
                    a++;
                } else {
                    b++;
                }
            } else {
                if (c == '0') {
                    a++;
                } else {
                    b++;
                }
            }
        }
        System.out.println(Math.min(a, b));
        return;
    }
}


Measured memory_bytes: 24552
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1e9+7;

int main(){

    int N;
    cin >> N;

    ll ans = 1;
    for (int i=1; i<=N; i++){
        ans *= i;
        ans %= INF; 
    }

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

Measured memory_bytes: 3632
#include<stdio.h>
#include<stdlib.h>
struct node
{
    int key;
    struct node *next, *prev;
};

struct node *nil;

void init()
{
    nil=(struct node *)malloc(sizeof(struct node));
    nil->next=nil;
    nil->prev=nil;
}

struct node *listSearch(int keys)
{
    struct node *cur=nil->next;
    while(cur!=nil && cur->key!=keys)
        cur=cur->next;

    return cur;
}

void insert(int keys)
{
    struct node *x=(struct node *)malloc(sizeof(struct node));
    x->key=keys;
    //insert
    x->next=nil->next;
    nil->next->prev=x;
    nil->next=x;
    x->prev=nil;
}

void Delete(struct node *t)
{
    if(t==nil) return;
    t->prev->next=t->next;
    t->next->prev=t->prev;
    free(t);
}

void deleteFirst()
{
    Delete(nil->next);
}

void deleteLast()
{
    Delete(nil->prev);
}

void printList()
{
    struct node *cur=nil->next;
    while(cur->next != nil)
    {
        printf("%d ", cur->key);
        cur=cur->next;
    }
    printf("%d\n", cur->key);
}
int main()
{
    int n, x,i;
    char comm[12];

    scanf("%d", &n);

    init();

    for(i=0; i<n; i++)
    {
        scanf("%s", comm);
        if(comm[0]=='i')
        {
            scanf("%d", &x);
            insert(x);
        }
        if(comm[0]=='d')
        {
            if(comm[6]=='F') deleteFirst();
            else if(comm[6]=='L') deleteLast();
            else
            {
                scanf("%d", &x);
                Delete(listSearch(x));
            }
        }
    }


    printList();

    return 0;
}

Measured memory_bytes: 31788
#include<bits/stdc++.h>
using namespace std;
 
int main(){
  long long n;
  cin >> n;
  vector<int> vec(n);
  for(int i=0; i<n; i++){
    cin >> vec.at(i);
  }
  
  long long count =vec.at(0);
  long long sum = 0;
  for(int i=0; i<n; i++){
    if(count < vec.at(i)){count = vec.at(i);}
    
    sum = sum + (count - vec.at(i));
  }
  cout << sum << endl;
}

Measured memory_bytes: 3972
#include<bits/stdc++.h>
using namespace std;
//二部マッチング
//ライブラリげー

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

#define fst first
#define snd second
#define all(c) ((c).begin()), ((c).end())

const long long INF = (1ll << 50);
struct Dinic {
  typedef long long flow_type;
  struct edge {
    int src, dst;
    flow_type capacity, flow;
    size_t rev;
  };
  int n;
  vector<vector<edge>> adj;
  Dinic(int n) : n(n), adj(n) { }
  void add_edge(int src, int dst, flow_type capacity) {
    adj[src].push_back({src, dst, capacity, 0, adj[dst].size()});
    adj[dst].push_back({dst, src, 0, 0, adj[src].size()-1});
  }
  flow_type max_flow(int s, int t) {
    vector<int> level(n), iter(n);
    function<int(void)> levelize = [&]() { // foward levelize
      level.assign(n, -1); level[s] = 0;
      queue<int> Q; Q.push(s);
      while (!Q.empty()) {
        int u = Q.front(); Q.pop();
        if (u == t) break;
        for (auto &e: adj[u]) {
          if (e.capacity > e.flow && level[e.dst] < 0) {
            Q.push(e.dst);
            level[e.dst] = level[u] + 1;
          }
        }
      }
      return level[t];
    };
    function<flow_type(int, flow_type)> augment = [&](int u, flow_type cur) {
      if (u == t) return cur;
      for (int &i = iter[u]; i < adj[u].size(); ++i) {
        edge &e = adj[u][i], &r = adj[e.dst][e.rev];
        if (e.capacity > e.flow && level[u] < level[e.dst]) {
          flow_type f = augment(e.dst, min(cur, e.capacity - e.flow));
          if (f > 0) {
            e.flow += f;
            r.flow -= f;
            return f;
          }
        }
      }
      return flow_type(0);
    };
    for (int u = 0; u < n; ++u) // initialize
      for (auto &e: adj[u]) e.flow = 0;

    flow_type flow = 0;
    while (levelize() >= 0) {
      fill(all(iter), 0);
      for (flow_type f; (f = augment(s, INF)) > 0; )
        flow += f;
    }
    return flow;
  }
};

int main(){
    
    while(1){

        int m, n; cin >> m >> n;
        if(!n) break;
        vector<int> b(m);
        vector<int> r(n);
        for(int i = 0; i < m; i++) cin >> b[i];
        for(int i = 0; i < n; i++) cin >> r[i];
        
        //0 := start, [1, m] := blue, [m + 1, m + n] := red, m + n + 1 := goal
        Dinic G(n + m + 2);

        for(int i = 1; i <= m; i++) G.add_edge(0, i, 1);
        for(int i = m + 1; i <= m + n; i++) G.add_edge(i, m + n + 1, 1);

        //辺を張る
        for(int i = 0; i < m; i++){
            for(int j = 0; j < n; j++){
                if(gcd(b[i], r[j]) > 1){
                    G.add_edge(i + 1, m + j + 1, 1);    
  
                }
            }
        }

        cout << G.max_flow(0, m + n + 1) << endl;
    }

    return 0;
}


Measured memory_bytes: 13556
#include <stdio.h>
#include <stdlib.h>
#define INFTY 1000000001

int count = 0;
void merge(int A[], int left, int mid, int right){
    int n1 = mid - left;
    int n2 = right - mid;
    int * L = (int *)malloc((n1+1) * sizeof(int));
    int * R = (int *)malloc((n2+1) * sizeof(int));
    for (int i = 0; i < n1; i++){//n1-1 or n1?
        L[i] = A[left+i];
    }
    for (int i = 0; i < n2; i++){
        R[i] = A[mid+i];
    }
    L[n1] = INFTY;
    R[n2] = INFTY;

    int i = 0, j = 0;
    for (int k = left; k < right; k++){//if right=3, cicle=3
        count++;
        if (L[i] <= R[j]){
            A[k] = L[i];
            i++;
        }
        else {
            A[k] = R[j];
            j++;
        }
    }
}

void mergeSort(int A[], int left, int right){
    if (left+1 < right){
        int mid = (left + right)/2;
        mergeSort(A, left, mid);
        mergeSort(A, mid, right);
        merge(A, left, mid, right);
    }
}

int main(){
    int n;
    int S[500001];
    scanf("%d", &n);
    for (int i = 0; i< n; i++){
        scanf ("%d", &S[i]);
    }
    mergeSort(S, 0, n);

    for (int i = 0; i < n; i++){
        if (i == n-1){
            printf("%d\n", S[i]);
            break;
        }
        printf("%d ", S[i]);
    }
    printf("%d\n", count);
    return 0;
}


Measured memory_bytes: 65360
#include <iostream>
#include <algorithm>
#include <array>
#include <cstdint>
#include <functional>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stdlib.h>
#include <string>
#include <utility>
#include <vector>

#define INF 1000000000
#define MOD 1000000007
#define rep(i,a,b) for(uint32 i = (a); i < (b); ++i)
#define bitget(a,b) (((a) >> (b)) & 1)
#define ALL(x) (x).begin(),(x).end()
#define C(x) std::cout << #x << " : " << x << std::endl
#define scanf scanf_s

using int32 = std::int_fast32_t;
using int64 = std::int_fast64_t;
using uint32 = std::uint_fast32_t;
using uint64 = std::uint_fast64_t;



int main(void) {
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);
	std::string s;
	std::cin >> s;
	uint32 ans = 0;
	uint32 r = s.length() / 2;
	uint32 l = s.length() - r - 1;
	char c = s[l];
	if (s[l] != s[r]) {
		std::cout << s.length() / 2 << "\n";
		return 0;
	}
	while (r < s.length()) {
		if (s[l] == c&&s[r] == c) {
			-- l;
			++r;
		}
		else {
			break;
		}
	}
	ans = (s.length() + r - l - 1) / 2;
	std::cout << ans << "\n";
	return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
const int maxn=105;
int a[maxn];
using namespace std;
int main(){
    int n;
    cin>>n;
    for(int i=1;i<=2*n;++i){
        cin>>a[i];
    }
    sort(a+1,a+2*n+1);
    int ans=0;
    for(int i=2*n;i>=2;i-=2){
        ans+=a[i-1];
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end())
#define VRSORT(v) sort(v.rbegin(), v.rend())
#define ll long long
#define pb(a) push_back(a)
#define INF 1000000000
#define LINF 3e18+7
#define MOD 1000000007
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

typedef vector<unsigned int>vec;
typedef vector<vec> mat;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline void add(T &a, T b){a = ((a+b) % MOD + MOD) % MOD;};

const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const double PI = acos(-1.0);
const double EPS = 1e-10;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int K,X;
    cin>>K>>X;
    for(int i=max(X-K+1,-1000000);i<X;i++) cout<<i<<" ";
    for(int i=X;i<X+K && i<1000000;i++) cout<<i<<" ";
    cout<<endl;
}

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

int main(void) {
	int N, K;
	cin >> N >> K;
	if (N % K == 0) {
		cout << 0 << endl;
	}
	else {
		cout << 1 << endl;
	}
}

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

#define mod 1e9+7

typedef long long ll;

int fun1(int n){
	
	int h[n+5],ans[n+5];

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

	ans[0]=0;
	ans[1]=abs(h[1]-h[0]);

	int tmp1,tmp2;

	for(int i=2;i<n;i++){
		
		tmp1=(ans[i-1]+abs(h[i]-h[i-1]));	
		tmp2=(ans[i-2]+abs(h[i]-h[i-2]));
		ans[i]=min(tmp1,tmp2);

		//cout<<i<<" "<<tmp1<<" "<<tmp2<<"\n";
	}

	return ans[n-1];
}

int main()
{
    //freopen("in.txt", "r", stdin);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int n;
    cin>>n;

    cout<<fun1(n);

    return 0;
}

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

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

  if((S.at(2) == S.at(3)) && (S.at(4) == S.at(5))) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
import string

S = input()

abc = [chr(i) for i in range(97, 97+26)]

if len(S) < 26:
    for s in S:
        abc.remove(s)
    add = abc[0]
    print(S + add)
elif S == ''.join(sorted(abc, reverse=True)):
    print(-1)
else:
    N = len(S)
    for i in range(1, N):
        now = S[N-i-1]
        fow = S[N-i:]
        fows = sorted(list(fow))
        for f in fows:
            if now < f:
                now = f
                break
        if now != S[N-i-1]:
            ans = S[:N-i-1] + now
            break
    print(ans)



Measured memory_bytes: 3892
N, H = map(int, input().split())
a = [0] * N
b = [0] * N
for i in range(N):
    a[i], b[i] = map(int, input().split())

A = int(max(a))
B = [i for i in b if i > A]

B.sort(reverse=True)

Sum = 0

for i in range(len(B)):
    H -= B[i]
    Sum += 1
    if H <= 0:
        break

if H > 0:
    Sum += int((H-1)//A)+1


print(Sum)

Measured memory_bytes: 52312
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
const int N=1e3+10,Mod=1e9+7;
#define pb push_back
#define pii pair<int,int>
#define f first
#define s second
int h,w,dp[N][N];
char a[N][N];
int main()
{
  cin>>h>>w;
  for(int i=1;i<=h;i++) for(int j=1;j<=w;j++) cin>>a[i][j];
  dp[1][1]=1;
  for(int i=1;i<=h;i++) for(int j=1;j<=w;j++)
  {
    if(a[i][j]=='#') continue;
    if(a[i-1][j]=='.' && a[i][j-1]!='.') dp[i][j]=dp[i-1][j];
    else if(a[i-1][j]!='.' && a[i][j-1]=='.') dp[i][j]=dp[i][j-1];
    else if(a[i-1][j]=='.' && a[i][j-1]=='.') dp[i][j]=(dp[i-1][j]+dp[i][j-1])%Mod;
  }
  cout<<dp[h][w]<<endl;
  return 0;
}


Measured memory_bytes: 5120