akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <utility>
using namespace std;
#define ll long long

int main () {
  ll n, m;
  cin >> n >> m;
  pair<ll, ll> box[1000000];
  for (ll i = 0; i < n; i++) {
    ll s, ss;
    cin >> s >> ss;
    box[i] = make_pair(s, ss);    
  }  
  sort(box, box + n);
  ll ans = 0;
  ll num = 0;
  for (ll i = 0; i < n; i++) {
    num += box[i].second;
    ans += box[i].second * box[i].first;
    if (num >= m) {
      ans -= box[i].first * (num - m);
      cout << ans << endl;
      return 0;    
    }    
  }
}


Measured memory_bytes: 15872
s=input()

list=[0 for _ in range(len(s) + 1)]

for n in range(0, len(s), 1):
    if '<' == s[n] and list[n] >= list[n + 1]:
        list[n + 1] += list[n] - list[n + 1] + 1

for n in range(len(s) - 1, -1, -1):
    if '>' == s[n] and list[n] <= list[n + 1]:
        list[n] += list[n + 1] - list[n] + 1

print(sum(list))


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

int w, h, m;
string s[20];

void dfs(int i, int j) {
	s[i][j] = '#';
	m++;

	if (i > 0 && s[i - 1][j] == '.')
		dfs(i - 1, j);
	if (i < h - 1 && s[i + 1][j] == '.')
		dfs(i + 1, j);

	if (j > 0 && s[i][j - 1] == '.')
		dfs(i, j - 1);

	if (j < w - 1 && s[i][j + 1] == '.')
		dfs(i, j + 1);
}

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

	while (w > 0 && h > 0) {
		m = 0;

		for (int i = 0; i < h; i++)
			cin >> s[i];

		for (int i = 0; i < h; i++)
			for(int j = 0; j < w; j++)
				if (s[i][j] == '@')
					dfs(i, j);

		cout << m << endl;
		cin >> w >> h;
	}
}



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

#ifdef _DEBUG
#define dout cout
#define debug() if (true)
#define dvout(v) vout(v)
#else
#define dout if (false) cout
#define debug() if (false)
#define dvout(v) if(false) vout(v)
#endif

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define all(x) (x).begin(), (x).end()
#define vout(v)           \
	for (auto &i : v)     \
	{                     \
		cout << i << " "; \
	}                     \
	cout << "\n"; //配列出力
#define vec(v, n) vector<int> v(n, 0);
#define vecll(v, n) vector<ll> v(n, 0);
#define vecvec(v,n,m) vector<vector<int>> v(n, vector<int>(m));
#define vin(v)        \
	for (auto &i : v) \
		cin >> i; //配列入力

#define mod (int)(1e9+7)
typedef long long ll;
typedef unsigned long long ull;
#define next asdnext
#define prev asdprev
#define _n "\n"
#define _n2 "\n\n"
#define _t "\t"

//	LLONG_MAX 9.2*1e18	9223372036854775807LL = (2^63)-1
//	INT_MAX 2.1*1e9 2147483647 = (2^31)-1
//	O(1e8) 1.2sec

void Main()
{
	int N;
	cin>>N;
	vecll(A,N);
	vin(A);

	ll high=0;
	ll ans=0;
	rep(i,N){
		if(A[i]<=high){
			ans += high-A[i];
		}
		else{
			high=A[i];
		}
	}

	cout<<ans<<_n;
}


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


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

int main(int argc, char** argv){
  int n;

  while(cin >> n) {
    bool flg = true;
    set<string> words;
    string first;
    
    cin >> first;
    char prev = first[first.size() - 1];
    
    words.insert(first);

    for (int i = 0; i < n - 1; i++) {
      string s;
      cin >> s;

      if (s[0] != prev) {
	flg = false;	
      }

      if (words.find(s) != words.end()) {
	flg = false;
      }


      words.insert(s);
      prev = s[s.size() - 1];
    }

    if (flg)
      cout << "Yes" << endl;
    else
      cout << "No" << endl;
  }

  return 0;
}


Measured memory_bytes: 256
/*
これを入れて実行
g++ code.cpp
./a.out
 */

#include <iostream>
#include <vector>
#include <string>
#include <queue>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <cmath>
#include <tuple>
#include <iomanip>

using namespace std;
typedef long long ll;
typedef long double ld;

int dy4[4] = {-1, 0, +1, 0};
int dx4[4] = {0, +1, 0, -1};
int dy8[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
int dx8[8] = {0, 1, 1, 1, 0, -1, -1, -1};

const long long INF = 1LL << 60;
const ll MOD = 1e9 + 7;

bool greaterSecond(const pair<int, int>& f, const pair<int, int>& s){
    return f.second > s.second;
}

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

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

ll nCr(ll n, ll r){
    if(r == 0 || r == n){
        return 1;
    } else if(r == 1){
        return n;
    }
    return (nCr(n - 1, r) + nCr(n - 1, r - 1));
}

ll nPr(ll n, ll r){
    r = n - r;
    ll ret = 1;
    for (ll i = n; i >= r + 1; i--) ret *= i;
    return ret;
}

//-----------------------ここから-----------

int main(void){
    string s;
    cin >> s;

    bool ok = true;
    for(int i = s.size() - 1; i >= 6; i--){
        if(s.substr(i - 4, 5) == "dream" || s.substr(i - 4, 5) == "erase"){
            i -= 4;
        } else if(s.substr(i - 6, 7) == "dreamer"){
            i -= 6;
        } else if(s.substr(i - 5, 6) == "eraser"){
            i -= 5;
        } else {
            ok = false;
            break;
        }   
    }

    if(ok){
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }
}

Measured memory_bytes: 512
from sys import exit

def downsearch(X,list):
    if X not in list:
        return X
    else:
        return downsearch(X-1,list)

def upsearch(X,list):
    if X not in list:
        return X
    else:
        return upsearch(X+1,list)


X,N = map(int,input().split())

if N == 0:
    print(X)
    exit(0)

plist = [int(x) for x in input().split()]

d = downsearch(X,plist)
u = upsearch(X,plist)

if abs(X-d) <= abs(X-u):
    print(d)
else:
    print(u)

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

int main(){
  int N;
  cin >> N;
  ll ans = 0;
  rep(i, N){
    if ((i+1) % 3 != 0 && (i+1) % 5 != 0) ans += i + 1;
  }
  cout << ans << endl;
}

Measured memory_bytes: 3596
using System;
class c
{
    static void Main()
    {
        {
            var nk = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
            int n = nk[0], k = nk[1];
            long ans = k;
            for (int i = 1; i < n; i++)ans *= k - 1;
            Console.WriteLine(ans);
        }
    }
}

Measured memory_bytes: 13140
#include <iostream>
#include <numeric>
#include <cmath>
#include <limits>
#include <stdio.h>
#include <iomanip>
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
using namespace std;
using ll = long long;
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)
ll Max(ll(a), ll(b), ll(c)) {
	return max(max(a, b), c);
}
ll Min(ll(a), ll(b), ll(c)) {
	return min(min(a, b), c);
}





int main() {
    ll N;
    cin >> N;
    vector<ll> P(N);
    vector<ll> Q(N);
    vector<ll> R(N);
    rep(i, N) {
        cin >> P.at(i);
    }
    rep(i, N) {
        cin >> Q.at(i);
        R.at(i) = i + 1;
    }
    ll p, q;
    ll k = 0;
    do {
        bool pc = true;
        bool qc = true;
        for (int i = 0; i < N; i++) {

            if (P.at(i) != R.at(i)) {
                pc = false;
            }
            if (Q.at(i) != R.at(i)) {
                qc = false;
            }

        }

        if (pc) p = k;
        if (qc) q = k;
        k++;
    } while (next_permutation(R.begin(), R.end()));
    cout << abs(p - q) << endl;
}


Measured memory_bytes: 3568
N,M,Q = map(int,input().split())
grid = [[0]*(N+1) for i in range(N+1)]

for i in range(M):
    l, r = map(int, input().split())
    grid[l][r] += 1

for i in range(N+1):
    for j in range(N):
        grid[i][j+1] += grid[i][j]
for i in range(N+1):
    for j in range(N):
        grid[j+1][i] += grid[j][i]

for i in range(Q):
    p,q = map(int, input().split())
    ans = grid[q][q] - grid[q][p-1] - grid[p-1][q] + grid[p-1][p-1]
    print(ans)

Measured memory_bytes: 13300
#include <bits/stdc++.h>
#include <stdlib.h>
#include <fstream>
#include <iostream>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll,ll> llP;

ll mod(ll a, ll b){
  ll ret=a%b;
  if(ret<0) ret+=b;
  return ret;
}

ll modpow(ll a,ll b,ll c){
  ll res=1;
  while(b>0){
    if(b&1) res=mod(res*a,c);
    a=mod(a*a,c);
    b>>=1;
  }
  return res;
}

int GCD(int x,int y){
  if(x<y){
    swap(x,y);
  }
  while(x%y!=0){
    int temp=x;
    x=y;
    y=temp%y;
  }
  return y;
}

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

int main() {
  int n;
  cin>>n;
  int ans=0;
  bool cnt=false;
  for(int i=0;i<n;i++){
    int d1,d2;
    cin>>d1>>d2;
    if(d1==d2){
      ans++;
    }
    else ans=0;
    if(ans==3) cnt=true;
  }
  if(cnt) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
  return 0;
}

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

bool compareHeight(int v1, int v2) {
	return v2 < v1;
}

int main() {
	vector<int> HeightVec;
	int iHeight = 0;
	for (int i = 0; i < 10; i++) {
		cin >> iHeight;
		HeightVec.push_back(iHeight);
	}
	
	sort(HeightVec.begin(),HeightVec.end(),compareHeight);
	cout << HeightVec[0] << endl;
	cout << HeightVec[1] << endl;
	cout << HeightVec[2] << endl;

	return 0;
}

Measured memory_bytes: 1216
#include <bits/stdc++.h>
using namespace std;
int main () {
	int N;
	cin >> N;
	std::vector<int> v(N);
	for (int i = 0; i < N; ++i)
	{
		cin >> v[i];
	}
	cout << *max_element(v.begin(), v.end()) - *min_element(v.begin(), v.end()) << endl;

}

Measured memory_bytes: 256
#include<iostream>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
#include<limits>
#include<sstream> 
#include<unordered_map>      

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef int itn;
typedef vector<int> vi;
typedef vector<ll> vl;

const int inf = numeric_limits<int>::max() >> 2;
const ll linf = numeric_limits<ll>::max() >> 2;
const ull ulinf = numeric_limits<ull>::max() >> 2;
const double pi = acos(-1);
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
const int dx8[8]={-1,0,1,-1,1,-1,0,1};
const int dy8[8]={-1,-1,-1,0,0,1,1,1};

#define p_queue(i) priority_queue<i> 
#define rp_queue(i) priority_queue<i, vector<i>, greater<i>> 
#define umap(i,j) unordered_map<i,j>
#define P(p) cout<<(p)<<endl
#define PS(p) cout<<(p)<< " "
#define IN cin >> 
#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define rrep(i,m,n) for(int i = (m-1); i >= (int)(n); i--)
#define inrep(n,a) for(int i = 0; i < (int)(n); i++)cin >> a[i];
#define mod(i) ((i)%(ll)(1e9 + 7))
#define divm(a,b) (mod(a * modpow((ll)b,(ll)(1e9+5))))
#define rsort(a,b,c) sort(a, b, greater<c>())
#define vsort(v) sort(v.begin(), v.end())
#define rvsort(v,c) sort(v.begin(), v.end(), greater<c>()) 
#define ft first
#define sd second
#define pb push_back
#define it insert
#define sz(x) ((int)(x).size())
#define lb(a,n,k) (lower_bound(a,a+n,k) - a) 
#define vlb(a,k)  (lower_bound(a.begin(),a.end(),k) - a.begin())
#define ub(a,n,k) (upper_bound(a,a+n,k) - a) 
#define vub(a,k)  (upper_bound(a.begin(),a.end(),k) - a.begin())
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define ret return

ll modpow(ll i,ll j){ ll tmp=1; while(j){ if(j%2)tmp=mod(tmp*i);i=mod(i*i);j/=2;}return tmp;}
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; }

vector<string> split(const string &str, char sep){
    vector<string> v;
    stringstream ss(str);
    string buffer;
    while( getline(ss, buffer, sep) ) {
        v.push_back(buffer);
    }
    return v;
}

//ll ncr[100][100];
//ll nCr(int n, int r){if(n==r) ret ncr[n][r] = 1; if(r==0) ret ncr[n][r] = 1; if(r==1) ret ncr[n][r] = n;if(ncr[n][r]) ret ncr[n][r]; ret ncr[n][r] = nCr(n-1,r) + nCr(n-1,r-1);}

//ll npr[100][100]={};
//ll nPr(int n,int r){if(npr[n][r])ret npr[n][r];if(r==0)ret npr[n][r] = 1;if(r==1)ret npr[n][r] = n;ret npr[n][r] = n * nPr(n-1,r-1);}

//ll nHr(int n,int r){ret nCr(n+r-1,r);}

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


int main(){

    int n;

    cin >> n;
    vector<double> a(n);
    inrep(n,a);

    vsort(a);
    while(sz(a) > 1){
	a.pb((a[0] + a[1])/2);
	a.erase(a.begin());
	a.erase(a.begin());
	
	vsort(a);
    }

    printf("%.10lf\n",a[0]);
    return  0;
}


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

using namespace std;

int main()
{
    int n;
    cin >> n;
    vector<string> ss(3);
    cin >> ss[0] >> ss[1] >> ss[2];

    int count = 0;
    for (int i = 0; i < n; i++)
    {
        set<char> s;
        s.insert(ss[0][i]);
        s.insert(ss[1][i]);
        s.insert(ss[2][i]);
        count += s.size() - 1;
    }
    cout << count << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <iomanip>
#include <algorithm>
#include <cassert>
#include <queue>
#include <set>
#include <vector>
#include <cmath>
#include <bitset>
#include <functional>
#include <limits>
#include <map>
using namespace std;

typedef long long ll;
#define rep1(i, n) for(ll i = 1; i <=(ll)(n); i++)
#define rep0(i, n) for(ll i = 0; i <=(ll)(n); i++)

ll pow(ll a, ll n) { //compute a^n with o(logn)
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * a;
        a = a * a;
        n >>= 1;
    }
    return res;
}

ll pow(ll a, ll n, ll mod) { //compute a^n (mod mod) with o(logn)
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

const int MAX = 199;
const int MOD = 1000000007;
ll fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int 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 COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

//順列計算
ll PER(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[n - k] % MOD) % MOD;
}

int main(){
    ll n,x,t;
    cin >> n >> x >>t;
    ll total = t*(n/x);
    if(n % x > 0) total += t;
    cout << total << endl;
    return 0;
}

Measured memory_bytes: 3196
N, K = map(int, input().split())
V = list(map(int, input().split()))

def query(l, r):
    if (l+r > K):
        return 0
    rest = K-l-r
    lst = V[:l] + V[N-r:]
    lst.sort()
    return sum([x for i, x in enumerate(lst) if x > 0 or i >= rest])

ans = 0
for l in range(N+1):
    for r in range(N+1-l):
        ans = max(ans, query(l, r))
print(ans)

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

int main() {
  int H,W,N;
  cin >> H;
  cin >> W;
  cin >> N;
  int a;
  int i=0;
  if(H>W){
    a = H;
  }
  else{
    a = W;
  }
  while(true){
    N -= a;
    i++;
    if(N<=0){
      break;
    }
  }
  cout << i << endl;
}


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

int main() {
  string s;
  cin >> s;
  int ci=-1, fi=-1;
  for (int i=0; i<s.size(); i++)
    if (s.at(i) == 'C') {
      ci = i;
      break;
    }
  for (int i=s.size()-1; i>=0; i--)
    if (s.at(i) == 'F') {
      fi = i;
      break;
    }
  if (ci==-1||fi==-1||ci>fi)
    cout << "No" << endl;
  else
    cout << "Yes" << endl;
}

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


int main()
{
	int H, W;
	char s[55][55];
	bool flag = true;

	cin >> H >> W;

	for (int i = 0; i <= W + 1; i++) {
		s[0][i] = '.';
	}

	for (int i = 0; i <= W + 1; i++) {
		s[i][0] = '.';
	}

	for (int i = 1; i <= H; i++) {
		for (int j = 1; j <= W; j++) {
			cin >> s[i][j];
		}
	}

	for (int i = 1; i <= H; i++) {
		for (int j = 1; j <= W; j++) {
			// cout << s[i][j];
			if (s[i][j] == '#') {
				if ((s[i-1][j] == '#') || (s[i][j-1] == '#') || (s[i+1][j] == '#') || (s[i][j+1] == '#')) {
				}
				else {
					flag = false;
				}
			}
		}
		// cout << endl;
	}

	if (flag) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin >> n;
  int t[n];
  int tsum = 0;
  for(int i=0; i<n; i++){
    cin >> t[i];
    tsum += t[i];
  }
  int m;
  cin >> m;
  int p[m],x[m];
  for (int i=0; i<m; i++){
    cin >> p[i] >> x[i];
    cout << tsum-(t[p[i]-1]-x[i]) << endl;
  }
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void){
int a,b;
  scanf("%d %d",&a,&b);
  for(int i=1;i<1009;i++){
    if(i*8/100==a&&i*1/10==b){
      printf("%d",i);
      return 0;
    }
  }
  printf("-1");
  return 0;
}

Measured memory_bytes: 128
from itertools import accumulate
N=int(input())
s=list(accumulate(map(int,input().split())))
ans=10**9
p=0
q=2
for i in range(2,N-1):
    while p<i-1 and abs(s[i-1]-2*s[p+1])<abs(s[i-1]-2*s[p]):
        p+=1
    if q<i:
        q+=1
    while q<N and abs(s[i-1]-2*s[q+1]+s[-1])<abs(s[i-1]-2*s[q]+s[-1]):   
        q+=1
    t=[s[q]-s[i-1],s[-1]-s[q],s[p],s[i-1]-s[p]]
    w=max(t)-min(t)
    ans=min(ans,w) 
print(ans)  

Measured memory_bytes: 25972
import Data.Array.ST (STUArray, runSTUArray, newArray, writeArray, getBounds)
import Data.Array.Unboxed
import Data.Ix (range)
import Control.Monad.ST (ST,runST)
import Control.Monad
import Control.Applicative

type PosXY = (Int,Int)
type Board = UArray PosXY Char
type STBoard s = ST s (STUArray s PosXY Char)

readDigits = map read <$> words <$> getLine :: IO [Int]

mkChessBoard :: Int -> Int -> Board
mkChessBoard w h =
    runSTUArray $ do
        box <- newArray ((1,1),(w,h)) '.' :: STBoard s
        rng <- range <$> getBounds box
        forM_ rng $ \idx@(y,x) -> do
            let c = if even (y+x) then '#' else '.'
            writeArray box idx c
        return box

main :: IO ()
main =
    loop
    where
    loop = do
        [h,w] <- readDigits
        unless (h == 0 && w == 0) $ do
            let box = mkChessBoard w h
            let ((sx,sy), (ex,ey)) = bounds box
            putStrLn $ unlines [[box!(x,y) | x<-[sx..ex]] | y<-[sy..ey]]
            loop

Measured memory_bytes: 5148
#include <iostream>

int main()
{
	char board[3][3];
	while (true) {
		std::cin >> board[0][0];
		if (board[0][0] == '0') break;
		std::cin >> board[0][1] >> board[0][2];
		std::cin >> board[1][0] >> board[1][1] >> board[1][2];
		std::cin >> board[2][0] >> board[2][1] >> board[2][2];
		char c;
		bool isNA = true;
		// vertical
		for (int j=0; j<3; j++) {
			c = board[0][j];
			if (c == '+') continue;
			if (board[1][j] == c && board[2][j] == c) {
				std::cout << c << std::endl;
				isNA = false; break;
			}
		}
		// horizontal
		if (isNA) {
			for (int i=0; i<3; i++) {
				c = board[i][0];
				if (c == '+') continue;
				if (board[i][1] == c && board[i][2] == c) {
					std::cout << c << std::endl;
					isNA = false; break;
				}
			}
		}
		// diagonal
		if (isNA) {
			c = board[1][1];
			if (c != '+') {
				if (board[0][0] == c && c == board[2][2]) {
					std::cout << c << std::endl;
					isNA = false;
				}
				else if (board[2][0] == c && c == board[0][2]) {
					std::cout << c << std::endl;
					isNA = false;
				}
			}
		}
		if (isNA) std::cout << "NA" << std::endl;
	}
	return 0;
}



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

#define SIZE_OF_ARRAY(array) (sizeof(array)/sizeof(array[0]))

int main()
{
  int N, K;
  cin >> N >> K;
  int A[N];
  for(int n=0; n<N; n++)
  {
    cin >> A[n];
  }

  std::sort(A, A+SIZE_OF_ARRAY(A));
  
  int T=0;
  for(int n=0; n<K; n++)
  {
    T = T+A[n];
  }
  cout << T << endl;
}


Measured memory_bytes: 3628
// Bismillahir Rahmanir Rahim. Ya Allah...
#include<bits/stdc++.h>
using namespace std;
typedef long long int  ll;
typedef pair<int,int> PII;
const int mod = 1e9+7,INF = 1e9;
const int mx = 3e5+5;
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin>>n;
    int val = (n+1000-1)/1000;
    int ans = val*1000-n;
    cout<<ans<<endl;
    return 0;
}



Measured memory_bytes: 3560
n = int(input())
p = [int(i) for i in input().split()]
i = 0
ans = 0
while i < n:
    if i < n - 1:
        if p[i] == i + 1:
            p[i], p[i+1] = p[i+1], p[i]
            ans += 1
    elif p[i] == i + 1:
        ans += 1
    i += 1
print(ans)


Measured memory_bytes: 13880
# -*- coding: utf-8 -*-
"""
D - DivRem Number
https://atcoder.jp/contests/diverta2019/tasks/diverta2019_d

"""
import sys


def solve(N):
    def divisor(N):
        divisors = set()
        for i in range(1, int(N**0.5)+1):
            if N % i == 0:
                divisors.add(i)
                divisors.add(N // i)
        return divisors

    ans = 0
    for q in divisor(N):
        if q == 1:
            continue
        a, b = divmod(N, q-1)
        if a == b:
            ans += (q-1)
    return ans


def main(args):
    N = int(input())
    ans = solve(N)
    print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])


Measured memory_bytes: 3828
def Yes():
  print("Yes")
def No():
  print("No")

def gcd(x, y):
  b = max(x, y)
  s = min(x, y)
  r = b % s
  while r != 0:
    b = s
    s = r
    r = b % s
  return s

def lcm(x, y):
  return (x * y) // gcd(x,y)

def main():
  T = int(input())
  AD = [list(map(int, input().split())) for i in range(T)]

  for i in AD:
    A = i[0]
    B = i[1]
    C = i[2]
    D = i[3]
    if A < B:
      No()
      continue
    if B > D:
      No()
      continue
    add = D - B
    d = gcd(B, D)
    
    C += 1
    t = C % d
    k = A % d
    if k == t:
      LD = C
    elif k > t:
      LD = C + k - t
    else:
      LD = C + d - t + k
    if LD < B:
      No()
    else:
      Yes()

main()

Measured memory_bytes: 3188
M, D = map(int, input().split())
count = 0
for i in range(1, M+1):
    for j in range(1, D+1):
        d_s = str(j)
        if len(d_s) == 1 or int(d_s[0]) < 2 or int(d_s[1]) < 2:
            continue
        elif i == int(d_s[0])*int(d_s[1]):
            count += 1
print(count)

Measured memory_bytes: 3060
import sys
n,m = map(int, input().split())

if n==1 and m==1:
    print(1)
    sys.exit()
elif n==1:
    print(m-2)
    sys.exit()
elif m==1:
    print(n-2)
    sys.exit()
else:
    print((n-2)*(m-2))

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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

signed main(){
    int N;cin>>N;
    vint A(N);rep(i,N)cin>>A[i];
    cout<<accumulate(all(A),0ll)-N<<endl;
    return 0;
}


Measured memory_bytes: 256
building = {1:[],2:[],3:[],4:[]}
for b in range(1, 4+1):
    building[b] = [0 for i in range(3*10)]

n = int(input())
for i in range(n):
    b, f, r, v = list(map(int, input().split()))
    building[b][(f-1)*10+(r-1)] += v

for b in range(1, 4+1):
    for i in range(3):
        for j in range(10):
            print(" {0}".format(building[b][(i*10)+j]), end="")
        print()
    if b < 4:
        print("#"*20)

Measured memory_bytes: 7764
from fractions import Fraction

def sroap(x1,y1,x2,y2):
	if x2 - x1 == 0:
		return float("inf")
	else:
		return Fraction(y2 - y1,x2 - x1)
		
N = int(input())
for n in range(N):
	Ax,Ay,Bx,By,Cx,Cy,Dx,Dy = map(lambda x: round(x * 10 ** 5),(map(float,input().split())))
	if sroap(Ax,Ay,Bx,By) == sroap(Cx,Cy,Dx,Dy):
		print("YES")
	else:
		print("NO")

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

int main() {
	long long n,k;
	cin >> n >> k;
	double a[n];
	for(long long i=0;i<n;i++){
		cin >> a[i];
		a[i]=(a[i]+1.0)/2.0;
	}
	double b[n+1];
	b[0]=0;
	for(int i=1;i<=n;i++){
		b[i]=b[i-1]+a[i-1];
	}
	double ans=0.0;
	for(int i=0;i+k<=n;i++){
		ans=max(ans,b[i+k]-b[i]);
	}
	cout << fixed << setprecision(10);
	cout << ans << endl;
}


Measured memory_bytes: 3456
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<cstring>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define rep(i, n) for(int i=0;i<n;++i)
#define rrep(i, n) for(int i=n;i>=0;--i)
const int inf=1e9+7;
const ll mod=1e9+7;
const ll big=1e18;
const double PI=2*asin(1);

int main() {
  int A, B, C, D;
  cin>>A>>B>>C>>D;
  if(A+B>C+D) cout<<"Left"<<endl;
  else if(A+B==C+D) cout<<"Balanced"<<endl;
  else cout<<"Right"<<endl;
}



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

int main()
{
        string S;
        cin >> S;
        map<int, int> m;
        for (int i = 0; i < S.length(); ++i) {
                m[S[i] - 'a']++;
        }
        for (auto i : m) {
                if (i.second != 1) {
                        cout << "no" << endl;
                        exit(0);
                }
        }
        cout << "yes" << endl;



}


Measured memory_bytes: 256
#include<vector>
#include<iostream>
#include<string>
#include<algorithm>
#include<math.h>
#include<map>
#include<functional>
#include<queue>
#include<stack>
#include<string.h>
#define ll long long int
#define MOD 1000000007LL
using namespace std;
int main() {
    ll n,a,b;
    cin>>n>>a>>b;
    ll x[114514]={};
    for(int i=0;i<n;i++){
        cin>>x[i];
    }
    ll ans=0;
    for(int i=0;i<n-1;i++){
        ans+=min(a*(x[i+1]-x[i]),b);
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 1152
#include <iostream>
#include <limits.h>
#include <string>
using namespace std;

int main(void){
    long long x, ans = 0;
    cin >> x;
    ans = (x / 11) * 2;
    if (x % 11 > 6) ans += 2;
    else if (x % 11 != 0) ans++;
    cout << ans << endl;
    return 0;
}



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

using namespace std;
typedef long long ll;

#define MOD (long long)(1e9+7)
#define INF (1LL<<60)
#define rep(i,n) for(ll i = 0; i < (n); i++)
#define rep1(i,n) for(ll i = 1; i <= (n); i++)

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;
}


// 最大公約数
ll gcd(ll a, ll b)
{
  if(b == 0) return a;
  return gcd(b, a % b);
}

// mod m におけるa の逆元
ll modinv(ll a, ll m) {
  ll b = m, u = 1, v = 0;
  while (b) {
    ll t = a / b;
    a -= t * b; swap(a, b);
    u -= t * v; swap(u, v);
  }
  u %= m;
  if (u < 0) u += m;
  return u;
}

// 素因数分解
vector<pair<ll, ll>> prim;
void pf(ll n)
{
  ll s = sqrt(n);
  ll r = 0;
  for(ll i = 2; i <= s; i++) {
    if((n % i) == 0) {
      r = 0;
      do {
	r++;
	n = n / i;
      } while((n % i) == 0);
      prim.push_back({i, r});
    }
  }
  if(n > s) {
    prim.push_back({n, 1});
  }
}

void solve()
{
  ll N; cin >> N;
  vector<ll> x(N), y(N); rep(i, N) cin >> x[i] >> y[i];
  double ans = 0;

  ll r[9]; rep(i, N) r[i] = i;
  ll cr = 0;
  double d = 0;
  do {
    cr ++;
    //    rep(i, N) cerr << r[i] << " "; cerr << endl;
    for(int i = 1; i < N; i++) {
      d += sqrt((x[r[i]] - x[r[i-1]]) * (x[r[i]] - x[r[i-1]]) +
		(y[r[i]] - y[r[i-1]]) * (y[r[i]] - y[r[i-1]]));
    }
    
  }while(next_permutation(r, r+N));
  ans  = d / cr; 
  

  printf("%.10f\n", ans);
}


int main(void)
{
  // ll t; cin >> t; rep(i, t)
  solve();
}


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

int main() {
    ll N, C, K;
    cin >> N >> C >> K;

    ll T[N];
    for(ll i = 0; i < N; i++) {
      cin >> T[i];
    }

    ll id = 0;
    ll cnt = 0;
    sort(T, T + N);
    while (1) {
        ll start = T[id];
        
        cnt++;

        if(start + K < T[id + 1])
          id++;

        for(ll i = 0; i < C && start + K >= T[id]; i++) {
            id++;
            if(id == N) {
              cout << cnt << endl;
              return 0;
            }
        }

        if(id == N) {
          cout << cnt << endl;
          return 0;
        }

    }



}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
  
#define FOR(i,a,b) for( ll i = (a); i < (ll)(b); i++ )
#define REP(i,n) FOR(i,0,n)
#define YYS(x,arr) for(auto& x:arr)
#define ALL(x) (x).begin(),(x).end()
#define SORT(x) sort( (x).begin(),(x).end() )
#define REVERSE(x) reverse( (x).begin(),(x).end() )
#define UNIQUE(x) (x).erase( unique( ALL( (x) ) ) , (x).end() )
#define PW(x) (1LL<<(x))
#define SZ(x) ((ll)(x).size())
#define SHOW(x) cout << #x << " = " << x << endl
 
#define pb emplace_back
#define fi first
#define se second

using namespace std;
 
typedef long double ld;
typedef long long int ll;
typedef pair<int,int> pi;
typedef pair<ll,ll> pl;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<bool> vb;
typedef vector<ld> vd;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<vpl> gr;
typedef vector<vl> ml;
typedef vector<vd> md;
typedef vector<vi> mi;
 
const ll INF = (ll)1e9 + 10;
const ll INFLL = (ll)1e18 + 10;
const ld EPS = 1e-8;
const ll MOD = 1e9+7;

template<class T> T &chmin( T &a , const T &b ){ return a = min(a,b); }
template<class T> T &chmax( T &a , const T &b ){ return a = max(a,b); }
template<class T> inline T sq( T a ){ return a * a; }
ll in(){ ll x; scanf( "%lld" , &x ); return x; }
 
// head

const ll L = 1000000;

ll n, s;

bool check( ll b ){
  ll res = 0;
  ll cur = n;
  while( cur > 0 ){
    res += cur % b;
    cur /= b;
  }
  return res == s;
}

int main(){

  n = in();
  s = in();

  FOR( i , 2 , L ){
    if( check(i) ){
      printf( "%lld\n" , i );
      return 0;
    }
  }

  ll ans = INFLL;
  if( s == n ){
    ans = n + 1;
  }
  
  FOR( i , 1 , L ){
    ll j = s - i;
    if( j < 0 ){
      continue;
    }
    ll k = ( n - j ) / i;
    if( k <= i or k <= j ){
      continue;
    }
    if( k * i + j == n ){
      chmin( ans , k );
    }
  }

  if( ans == INFLL ){
    ans = -1;
  }
  
  printf( "%lld\n" , ans );
  
  return 0;
}


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

using namespace std;

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

typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define CHMIN(a,b) a=min((a),(b))
#define CHMAX(a,b) a=max((a),(b))

// mod
const ll MOD = 1000000007ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

// floating
typedef double Real;
const Real EPS = 1e-11;
#define EQ0(x) (abs(x)<EPS)
#define EQ(a,b) (abs(a-b)<EPS)
typedef complex<Real> P;

int n;
ll t[125];

int main(){
  cin>>n;
  REP(i,n)cin>>t[i];
  ll ans = t[0];
  REP(i,n){
    ans = ans / __gcd(ans,t[i]) * t[i];
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
A,B,C,D=map(int,input().split())
mod=998244353
dpx=[[0 for i in range(D+1)] for j in range(C+1)]
dpy=[[0 for i in range(D+1)] for j in range(C+1)]
dpx[C][D]=1
dpy[C][D]=1
for i in range(D-1,B-1,-1):
    dpx[C][i]=(dpy[C][i+1]*C)%mod
    dpy[C][i]=(dpy[C][i+1]*C)%mod
for j in range(C-1,A-1,-1):
    dpx[j][D]=(dpx[j+1][D]*D)%mod
    dpy[j][D]=(dpx[j+1][D])%mod

for i in range(C-1,A-1,-1):
    for j in range(D-1,B-1,-1):
        dpx[i][j]=((dpx[i+1][j]*j)%mod+(dpy[i][j+1]*i)%mod)%mod
        dpy[i][j]=(dpx[i+1][j]+(dpy[i][j+1]*i)%mod)%mod

print(dpx[A][B])


Measured memory_bytes: 226360
#include<iostream>
#include <cstdio>
#include<cstring>
#include <cstdlib>  
#include<cmath>   
#include <cctype>
#include<string>
#include<set>
#include <iomanip>
#include <map>
#include<algorithm>
#include <functional>
#include<vector>
#include<climits>
#include<stack>
#include<queue>
#include <deque>
#include <climits>
#include <typeinfo>
#include <utility> 
using namespace std;
using ll = long long;
double pi() { return 3.14; }
int sum(int a, int b) { return a + b; }
int mul(int a, int b) { return a * b; }
int main() {

	int N,X;
	cin >> N >> X;
	int d = 0;
	int ans = 1;
	vector<int>l(N);
	for (int i = 0;i < N;i++) {
		cin >> l[i];
		d = d + l[i];
		if (d > X) { break; }
		else { ans++; }
	}
	cout << ans << endl;
	return 0;

}


Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <vector>
#include <set>
#include <map>
#include <sstream>
#include <cstdio>
#include <algorithm>
#include <stack>
#include <queue>
#include <cmath>
#include <iomanip>
#include <fstream>
//#include <bits/stdc++.h>
using namespace std;
typedef  long long ll;
const ll INF = (1 << 30);
const ll inf = (1LL << 50LL);
const int  maxn = 1e5 + 5;
const int MOD = 1e9 + 7;
int n;
ll arr[maxn];
ll dp[3005][3005][3];
ll rek(int levo, int desno, int turn){
    if(levo >= desno){
        if(turn == 0){
            return arr[levo];
        }
        return 0;
    }
    if(dp[levo][desno][turn] != -1){
        return dp[levo][desno][turn];
    }
    ll ret;
    if(turn == 0){
        ret = 0;
        ret = max(ret, rek(levo + 1, desno, 1 ^ turn) + arr[levo]);
        ret = max(ret, rek(levo, desno - 1, 1 ^ turn) + arr[desno]);
    }
    else{
        ret = inf;
        ret = min(ret ,rek(levo + 1, desno, 1 ^ turn));
        ret = min(ret, rek(levo, desno - 1, 1 ^ turn));
    }
    return dp[levo][desno][turn] = ret;
}
int main(int argc, const char * argv[]) {
    ios_base::sync_with_stdio(false);
     cin >> n;
    ll sum = 0;
    for(int i = 0; i < n; i ++){
        cin >> arr[i];
        sum += arr[i];
    }
    memset(dp, -1, sizeof dp);
    ll A = rek(0, n - 1, 0);
    ll B = sum - A;
    cout << A - B << endl;
    return 0;
}


Measured memory_bytes: 212096
# coding: utf-8
# Your code here!
import math

if __name__ == "__main__":
    N, X = list(map(int, input().split()))
    sum_moto = 0

    moto = int(input())
    sum_moto += moto
    min_moto = moto
    for i in range(N-1):
        moto = int(input())
        sum_moto += moto
        if moto < min_moto:
            min_moto = moto
    amari = X - sum_moto
    n = math.floor(amari / min_moto)
    print(N + n)



Measured memory_bytes: 3060
#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;
template <typename T> using vec = vector<T>;
template <typename T> using vvec = vector<vec<T>>;

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

ll pow(ll n,ll m){
    if(m==1) return n;
    if(m&1){
        ll p = pow(n,m-1);
        return p*n%mod;
    }else{
        ll p = pow(n,m/2);
        return p*p%mod;
    }
}


int main(){
    int N;
    cin >> N;
    vector<ll> D(N);
    vector<ll> cnt(N);
    for(int i=0;i<N;i++){
        cin >>D[i];
        cnt[D[i]]++;
    }
    if(cnt[0]>=2 || D[0]!=0){
        cout << 0 << endl;
        return 0;
    }
    mint ans = 1;
    int id = -1;
    for(int i=1;i<N;i++){
//        cerr << i << " " << cnt[i] << " " << cnt[i-1] << endl;
        if(cnt[i]==0){
            id = i;
            break;
        }
        ans *= pow(cnt[i-1],cnt[i]);
    }
    if(id!=-1){
        for(int i=id+1;i<N;i++) if(cnt[i]>=1){
            cout << 0 << endl;
            return 0;
        }
    }
    cout << ans.x << endl;
}

Measured memory_bytes: 1792
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <string>
#include <map>
#include <unordered_map>
#include <queue>
#include <functional>
using namespace std;

typedef long long ll;

int n, k;
int a[100001];

int gcd(int n1, int n2);

int main() {
	cin >> n >> k;
	int m = 0;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		if (m <= a[i]) {
			m = a[i];
		}
	}
	int g = a[0];
	for (int i = 1; i < n; i++) {
		g = gcd(g, a[i]);
	}
	if (k <= m && k%g == 0) cout << "POSSIBLE" << endl;
	else cout << "IMPOSSIBLE" << endl;
	return 0;
}

int gcd(int n1, int n2) {
	if (n1%n2 == 0) return n2;
	return gcd(n2, n1%n2);
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
using vi=vector<int>;
using vvi=vector<vi>;
using vs=vector<string>;
using msi=map<string,int>;
using mii=map<int,int>;
using pii=pair<int,int>;
using vlai=valarray<int>;
using ll=long long;
#define rep(i,n) for(int i=0;i<n;i++)
#define range(i,s,n) for(int i=s;i<n;i++)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define fs first
#define sc second
#define pb push_back
#define eb emplace_back
#define INF 1<<30
constexpr int gcd(int a,int b){return b?gcd(b,a%b):a;}
constexpr int lcm(int a,int b){return a*b/gcd(a,b);}

struct MaxFlow{
    struct edge{
        int to,cap,rev;
        edge(int t, int c, int r):to(t),cap(c),rev(r){}
    };
    vector<vector<edge>> g;
    vector<bool> used;
    MaxFlow(int n){
        g=vector<vector<edge>>(n);
        used=vector<bool>(n);
    }
    void add(int from, int to, int cap){
        g[from].eb(to,cap,g[to].size());
        g[to].eb(from,0,g[from].size()-1);
    }
    int dfs(int v, int t, int f){
        if(v==t) return f;
        used[v]=true;
        rep(i,g[v].size()){
            auto &e=g[v][i];
            if(!used[e.to] && e.cap>0){
                int d=dfs(e.to, t, min(f,e.cap));
                if(d>0){
                    e.cap-=d;
                    g[e.to][e.rev].cap+=d;
                    return d;
                }
            }
        }
        return 0;
    }
    int calcMF(int s, int t){
        int flow=0;
        while(1){
            fill(all(used),false);
            int f=dfs(s,t,INF);
            if(f==0) return flow;
            flow+=f;
        }
    }
};

int main(){
	int m,n;
	while(cin>>m>>n,n){
	    MaxFlow mf(m+n+2);
	    int s=m+n,t=m+n+1;
        vi b(m),r(n);
        rep(i,m){
            cin>>b[i];
            mf.add(s,i,1);
        }
        rep(i,n){
            cin>>r[i];
            mf.add(m+i,t,1);
            rep(j,m){
                if(gcd(b[j],r[i])!=1){
                    mf.add(j,m+i,1);
                }
            }
        }
        cout<<mf.calcMF(s,t)<<endl;
	}
	return 0;
}

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

int main(){
    int N, M;
    int X[100010];
    cin >> N >> M;
    for(int i=0; i<M; i++ ){
        cin >> X[i];
    }

    sort(X, X+M);

    int Y[100010];
    for(int i=0; i < M-1; i++){
        Y[i] =X[i+1]-X[i];
    }

    sort(Y, Y+(M-1));

    int ans =0;

    for(int i=0; i< (M-N); i++){
        ans = ans + Y[i];
    }

    cout << ans << endl;
}

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

int main() {
  set<string> S;
  int N;
  string s;
  cin >> N;
  rep(i, N) {
    cin >> s;
    S.insert(s);
  }
  cout << S.size() << endl;
  return 0;
}




Measured memory_bytes: 19264
/**
 *    author:  otera    
**/
#include<iostream>
#include<string>
#include<cstdio>
#include<cstring>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<deque>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
using namespace std;

//#define int long long
typedef long long ll;
typedef unsigned long long ul;
typedef unsigned int ui;
typedef long double ld;
const int inf=1e9+7;
const ll INF=1LL<<60 ;
const ll mod=1e9+7 ;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<int, int> P;
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
#define fr first
#define sc second
#define all(c) c.begin(),c.end()
#define pb push_back
#define debug(x)  cerr << #x << " = " << (x) << endl;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

void solve() {
	int n, T; cin >> n >> T;
    vector<int> c(n), t(n);
    rep(i, n) {
        cin >> c[i] >> t[i];
    }
    int ans = inf;
    rep(i, n) {
        if(t[i] <= T) {
            chmin(ans, c[i]);
        }
    }
    if(ans == inf) {
        cout << "TLE" << endl;
    } else {
        cout << ans << endl;
    }
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(10);
	//int t; cin >> t; rep(i, t)solve();
	solve();
    return 0;
}

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

int main(){
    int a,b;
    cin >> a >> b;
    
    if(a==1) a = 14;
    if(b==1) b = 14;
    
    if(a>b) cout << "Alice";
    if(a<b) cout << "Bob";
    if(a==b) cout << "Draw";
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <algorithm>
using namespace std;
int main(){
	int M, K; 
	cin >> M >> K; 
	if(M == 1 && K == 1){
		cout << -1 << endl; 
	}
	else if(M == 1 && K == 0){
		cout << 0 << " " << 0 << " " << 1 << " " << 1 << endl; 
	}
	else if(K >= (1 << M)){
		cout << -1 << endl; 
	}
	else{
		for(int i = 0; i < (1 << M); i++){
			if(i == K) continue; 
			cout << i << " "; 
		}
		cout << K << " "; 
		for(int i = ((1 << M) - 1); i >= 0; i--){
			if(i == K) continue; 
			cout << i << " "; 
		}
		cout << K << endl; 
	}
}

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

int main()
{
    string s;
    cin >> s;
    if(s.size()<4)
        cout << "No\n";
        
    else
    {
        string t = "YAKI";
        int flg = 0;
        for(int i=0;i<4;i++)
        {
            if(s[i]!=t[i])
            {
                cout << "No\n";
                flg = 1;
                break;
            }
        }
        if(!flg)
            cout << "Yes\n";
    }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define vi vector<int>
#define vvi vector<vi>
#define vs vector<string>
#define pb push_back
#define P pair<int,int>
#define vp vector<P>
#define PP pair<int,P>
#define vpp vector<PP>
#define fi first
#define se second
#define INF 1e9
#define MOD 1000000007
#define REP(i,n) for(int i=0;i<n;i++)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOR(i,m,n) for(int i=m;i<n;i++)
#define all(x) (x).begin(),(x).end()
int dx[]={-1,0,1,0},dy[]={0,-1,0,1};
int main(){
    int h,w;
    cin>>h>>w;
    vs vec(h);
    REP(i,h){
        cin>>vec[i];
    }
    queue<PP> que;
    que.push(PP(0,P(0,0)));
    vvi d(h,vi(w,INF));
    d[0][0]=0;
    while(que.size()){
        PP p=que.front();que.pop();
        if(d[p.se.fi][p.se.se]<p.fi){
            continue;
        }
        REP(i,4){
            int x=p.se.fi+dx[i];
            int y=p.se.se+dy[i];
            if(x<0||h<=x||y<0||w<=y){
                continue;
            }
            if(vec[x][y]=='#'){
                continue;
            }
            if(d[x][y]>p.fi+1){
                d[x][y]=p.fi+1;
                que.push(PP(d[x][y],P(x,y)));
            }
        }
    }
    if(d[h-1][w-1]==INF){
        cout<<"-1"<<endl;
        return 0;
    }
    int ans=0;
    REP(i,h){
        REP(j,w){
            if(vec[i][j]=='.'){
                ans++;
            }
        }
    }
    ans-=d[h-1][w-1]+1;
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  string bus;
  cin >> bus;
  bool A = false;
  bool B = false;
  for (int i = 0; i < 3; i++){
    if (bus.at(i) == 'A') A = true;
    if (bus.at(i) == 'B') B = true;
  }
  if (A && B) cout << "Yes" << endl;
  else cout << "No" << endl;
}
    

Measured memory_bytes: 256
import java.util.LinkedList;
import java.util.Queue;
import java.util.Scanner;

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

    void solve(Scanner sc) {
        char[] s = sc.next().toCharArray();
        Queue<Character> stack = new LinkedList<>();
        int ans = 0;
        for (char c : s) {
            if (stack.isEmpty()) {
                stack.add(c);
                continue;
            }

            if (stack.peek() != c) {
                ans += 2;
                stack.poll();
            } else {
                stack.add(c);
            }
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 27976
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000
#define int long long

int dp[1010][1010];



signed main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int H, W;
    cin >> H >> W;
    string S[1010];
    rep(i, H) cin >> S[i];
    dp[0][0] = 1;
    rep(i, H) {
        rep(j, W) {
            if (S[i + 1][j] == '.') dp[i + 1][j] = (dp[i + 1][j] + dp[i][j]) % mod;
            if (S[i][j + 1] == '.') dp[i][j + 1] = (dp[i][j + 1] + dp[i][j]) % mod;
        }
    }
    /*
    rep(i, H) {
        rep(j, W) {
            cout << dp[i][j] << " ";
        }
        cout << endl;
    }
    */
    cout << dp[H - 1][W - 1] << endl;

    return 0;
}


Measured memory_bytes: 9216