akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <string>
using namespace std;

struct node{
	int key;
	node *left, *right, *parent;
};

node *root, *NIL;// 定义全局的根节点

void insert(int k){

	node *x,*y,*z;
	x = root;
	y = NIL;
	z = (node *)malloc(sizeof(node));

	z->key = k;
	z->left = NIL;
	z->right = NIL;

	while(x!=NIL){
		y = x;
		if(k<x->key){
			x = x->left;
		}
		else{
			x = x->right;
		}
	}

	z->parent = y;

	if(y==NIL){
		root = z;
	}
	else{
		if(k < y->key){
			y->left = z;
		}else{
			y->right = z;
	}
	}
	
}

void preorder(node *z){
	if(z==NIL) return;
	cout<<" "<<z->key;
	preorder(z->left);
	preorder(z->right);
}

void inorder(node *z){
	if(z==NIL) return ;
	inorder(z->left);
	cout<<" "<<z->key;
	inorder(z->right);
}

int main(){
	int n, tem;
	string A;
	cin>>n;
	for(int i=0; i<n; i++){
		cin>>A;
		if(A=="insert"){
			cin>>tem;
			insert(tem);
		}
		else{
			inorder(root);
			cout<<endl;
			preorder(root);
			cout<<endl;

		}
	}
	
	return 0;
}





Measured memory_bytes: 26552
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, a, b) for(int i = a; i < b; i++)
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  FastIO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
typedef long long ll;
using P = pair<int,int>;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return true; } return false; }

int f(ll a, ll b, ll div){
    ll qa = a / div;
    ll qb = b / div;
    ll ra = a % div;
    ll rb = b % div;
    if (qa % 2 == 0 && qb % 2 == 0) return 0;
    else if (qa % 2 != 0 && qb % 2 != 0){
        if ((ra + rb) % 2 == 0) return 1;
        else return 0;
    }
    else if (qa % 2 != 0){
        if (ra % 2 != 0) return 1;
        else return 0;
    }
    else if (qb % 2 != 0){
        if (rb % 2 == 0) return 1;
        else return 0;
    }
}

int main(){
    ll a, b;
    cin >> a >> b;
    ll div = 1;
    while(div <= b) div *= 2;
    div /= 2;
    ll ans = 0;
    while(div > 1){
        ans *= 2;
        ans += f(a, b, div);
        div /= 2;
    }
    ans *= 2;
    ll n = b-a+1;
    if (b % 2 != 0 && a % 2 != 0){
        if ((n / 2 + 1) % 2 != 0) ans++;
    } 
    else{
        if ((n/2) % 2 != 0) ans++;
    } 
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3612
n, m = map(int, input().split())
XYZ = []
JKL = []
Seihu = [-1, 1]
for i in range(n):
    x, y, z = map(int, input().split())
    XYZ.append([x,y,z])
    for j in Seihu:
        for k in Seihu:
            for l in Seihu:
                tot = x*j + y*k + z*l
                XYZ[i].append(tot)
for j in Seihu:
    for k in Seihu:
        for l in Seihu:
            JKL.append([j,k,l])

ans = 0
for i in range(8):
    jkl = JKL[i]
    XYZ = sorted(XYZ, key=lambda x:x[i+3], reverse=True)
    score = 0
    for x in range(m):
        score += XYZ[x][i+3]
    ans = max(ans, score)

print(ans)

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

// ----------- define --------------
#define int long long
#define vi vector<int>
#define ii pair<int,int>
#define fi first
#define sc second
#define stoi stoll
#define popcnt __builtin_popcount
#define getBit(x, k) ((x >> k) & 1)
#define all(x) (x).begin(),(x).end()
// ---------------------------------

void Main() {
  int n, m;
  cin >> n >> m;
  int ans = 0;
  for (int i = 1; i * i <= m; i++) {
    if (m % i == 0) {
      if (i >= n) ans = max(ans, m / i);
      if (m / i >= n) ans = max(ans, i);
    }
  }
  cout << ans << '\n';
}

signed main() {
#ifdef _DEBUG
  // freopen("in" , "r", stdin );
  cerr << "- ---- -- ----- <3\n";
#endif
  cin.tie(0)->sync_with_stdio(0);
  int T = 1;
  // cin >> T;
  while (T--) Main();
}


Measured memory_bytes: 3660
#include <iostream>
#include <cstdio>
#include <map>

using namespace std;

map<int, int> used;

void solve(int a, int b, int times) {
	int r = a % b;

	if (used[r]) {
		cout << (a / b) << endl;

		--used[r], ++times;
		for (int i = 0; i < used[r]; ++i) cout << " ";
		for (int i = used[r]; i < times; ++i) cout << "^";
		cout << endl;
	}
	else {
		used[r] = times+2;
		cout << (a / b);
		if (r) solve(r * 10, b, times + 1);
		else cout << endl;
	}
}

int main() {
	int n, m;
	while (scanf("%d %d\n", &n, &m) != EOF) {
		used.clear();
		used[n % m] = 1;
		solve(n * 10, m, 0);
	}
}

Measured memory_bytes: 1220
# わからんだろこれ 降順ソート*昇順ソートからの発想が浮かばず
n, k = map(int, input().split())
a = sorted(list(map(int, input().split())))
b = sorted(list(map(int, input().split())), reverse=True)
l, r = -1, 10**12 + 1  # ちゃんと「取りうることがないもののうち最大値」「取りうることのない最小値」でやる.....

while r - l > 1:
    mid = (r + l) // 2  # 最大値これをめざす
    cur = 0
    for i in range(n):
        if a[i] * b[i] <= mid:
            # Kを使う必要がない
            pass
        else:
            # Kからどんくらい使うか これむずくない？
            cur += a[i] - mid // b[i]
    if cur > k:
        l = mid
    else:
        r = mid
print(r)

Measured memory_bytes: 121036
import java.util.*;
public class Main { 
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        int o=0;
        int n=sc.nextInt();
        int k=sc.nextInt();
      PriorityQueue<Integer> p=new PriorityQueue<>();
      	for(int i=0;i<n;i++){
    		p.offer(sc.nextInt());
		}
        for(int j=0;j<k;j++){
          	o+=p.poll();
    	}
      System.out.println(o);
    }
    
}

Measured memory_bytes: 38848
import java.util.Scanner;
class Main {
    public static void main(String[] args){
        
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        int count = 0;
        
        for(int i = a ; i <= b ; i++){
            if(c % i == 0){
                count++;
            }
        }
        System.out.println(count);
    }
}


Measured memory_bytes: 26268
#include <iostream>

int main()
{
	int a = 0, b = 0;
	double re = 0.0;
	std::cin >> a;
    for(int i = 1; i <= a; i++ )
    {
        b += i % 2;
    }
	re = (double)b / (double)a;
	std::cout << re << std::endl;
	return 0;
}


Measured memory_bytes: 256
# include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10, mod = 1e9 + 7;
int p[N], n, m, ans;  
int find_set(int x){
    return x == p[x] ? x : p[x] = find_set(p[x]);
}
void union_sets(int a, int b){
    a = find_set(a);
    b = find_set(b);
    p[a] = b;
}
int main(){
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    cin >> n >> m;
    for(int i = 1; i <= n; i++)p[i] = i;
    for(int i = 1; i <= m; i++){
        int a, b, c;
        cin >> a >> b >> c;
        union_sets(a, b);
    }
    for(int i = 1; i <= n; i++){
        ans += (i == find_set(i));
    }
    cout << ans << endl;
}


Measured memory_bytes: 1152
import java.util.Scanner;
import java.util.Stack;


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

        while(sc.hasNext()) {
            String str = sc.nextLine();

            if(str.equals(".")) {
                break;
            }

            Stack<Character> stack = new Stack<Character>();
            boolean f = true;
            char tmp_c;
            char[] ary = str.toCharArray();
            for(char c: ary) {
                if(c == '(' || c == '['){
                    stack.push(c);
                }
                else if(c == ')') {
                    if(stack.empty()) {
                        f = false;
                        break;
                    }
                    tmp_c = stack.pop();
                    if(tmp_c != '('){
                        f = false;
                        break;
                    }
                }
                else if(c ==']'){
                    if(stack.empty()) {
                        f = false;
                        break;
                    }
                    tmp_c = stack.pop();
                    if(tmp_c != '[') {
                        f = false;
                        break;
                    }
                }
            }

            String result;
            if(stack.empty() && f) {
                result = "yes";
            } else {
                result = "no";
            }

            System.out.println(result);
        }
    }
}



Measured memory_bytes: 51804
#include<stdio.h>
int main(void)
{
	int a,b,c,max;

	scanf("%d %d %d",&a,&b,&c);


	if(a>b){
		max=a;
		a=b;
		b=max;
	}
	if(b>c){
		max=b;
		b=c;
		c=max;
	}

	if(a>b){
		max=a;
		a=b;
		b=max;
	}

	printf("%d %d %d\n",a,b,c);

	return 0;
}



Measured memory_bytes: 2048
sx, sy, tx, ty = gets.split.map(&:to_i)

ans = ""
ans << "U" * (ty-sy)
ans << "R" * (tx-sx)
ans << "D" * (ty-sy)
ans << "L" * (tx-sx)

ans << "L"
ans << "U" * ((ty-sy)+1)
ans << "R" * ((tx-sx)+1)
ans << "D"
ans << "R"
ans << "D" * ((ty-sy)+1)
ans << "L" * ((tx-sx)+1)
ans << "U"

puts ans


Measured memory_bytes: 1788
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for (int i=0;i<(n);i++)
//#define int long long  
int main(){
    int N;
    int co=1;
    int Ans=0;
    int A[114514]={};
    cin >> N;
    REP(i,N){cin >> A[i];}
    sort(A,A+N);
    REP(i,N){
        if(A[i]==A[i+1]){
            co++;
            if(i==N-1){
                if(co>=A[i]){
                    Ans+=(co-A[i]);
                }else{
                    Ans+=co;
                }
            }
        }else{
            if(co>=A[i]){
                Ans+=(co-A[i]);
            }else{
                Ans+=co;
            }
            co=1;
        }
    }
    cout << Ans <<endl;
	return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
#define rep(i, l, r) for(int i = (l), i##end = (r);i <= i##end;++i)
using std::cin; using std::cout;
const int maxn = 200200;
typedef long long ll;
const int mod = 998244353;
inline ll pow(ll a,int b,int ans = 1) {
	for(;b;b >>= 1,a = a * a % mod) if(b & 1)
		ans = ans * a % mod;
	return ans;
}
int ans = 1;
inline ll inverse(int x){ return pow(x, mod - 2); }
inline int get(std::string s) {
	int x = 0;
	for(char i : s) x = x * 10 + (i & 15);
	return x;
}
inline bool chk(std::string s) {
	cout << "? " << s << std::endl;
	cin >> s;
	return s == "Y";
#ifdef ONLINE_JUDGE
#else
	std::cerr << "debug : ask : " << s << std::endl;
	return get(s) <= ans && s <= std::to_string(ans) || get(s) > ans && s > std::to_string(ans);
#endif
}
inline int getlen() {
	for(int len = 1;len <= 10;++len) {
		if(!chk("1" + std::string(len - 1, '0'))) {
			return len - 1;
		}
	}
	for(int len = 9;len >= 1;--len) {
		if(!chk(std::string(len, '9'))) {
			cout << "! " << 1 << std::string(len, '0') << '\n';
			exit(0);
		}
	}
	cout << "! " << 1 << '\n';
	exit(0);
}
int main() {
	std::ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	int len = getlen();
	std::string s;
	for(int i = 1;i < len;++i) {
		int l = 0, r = 10;
		for(;l + 1 != r;) {
			int mid = l + r >> 1;
			if(chk(s + char(mid + '0'))) {
				l = mid;
			} else {
				r = mid;
			}
		}
		s += char(l + '0');
	}
	for(int i = 8;i >= -1;--i) {
		if(i < 0 || !chk(s + char(i + '0') + char(i + '0'))) {
			cout << "! " << s << i + 1 << '\n';
			return 0;
		}
	}
}


Measured memory_bytes: 624
from sys import stdin

n, m = map(int, raw_input().strip().split())
inp = stdin.readlines()

p = [[0, 0] for i in xrange(n)]
i = 0
for line in inp:
    p[i] = map(int, line.strip().split())
    i += 1

p.sort()

pay = 0
rem = m
for i in xrange(n):
    a, b = p[i]
    tob = min(b, rem)
    rem -= tob
    pay += (a * tob)

    if rem <= 0: break

print pay

    
    


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

int main() {
	int n;
	cin >> n;
	int a[n + 1];
	for (int i = 1; i <= n; i++) {
		int temp;
		cin >> temp;
		a[temp] = i;
	}
	int ans = 0, temp = 1;
	for (int i = 2; i <= n; i++) {
		if (a[i] > a[i - 1]) {
			temp++;
		} else {
			ans = max(ans, temp);
			temp = 1;
		}
	}
	ans = max(ans, temp);
	cout << n - ans << endl;
	return 0;
}

Measured memory_bytes: 1024
numline=input().split(" ")
a=int(numline[0])
b=int(numline[1])

numline=input().split(" ")
numlis=[]
for i in range(a):
    numlis.append(int(numline[i]))

numlis.sort()

result=0
for i in range(b):
    result+=numlis[i]

print(result)

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

vector<pair<int, int> > Team_Data;
int Team_Rank[100];

int main(void){
  int team_id, score;
  while(true){
    scanf("%d,%d", &team_id, &score);
    if(team_id == 0 && score == 0){
      break;
    }
    Team_Data.push_back(pair<int, int>(score, team_id));
  }

  sort(Team_Data.rbegin(), Team_Data.rend());

  Team_Rank[Team_Data[0].second] = 1;
  int nowScore = Team_Data[0].first;
  int nowRank = 1;
  
  for(int i = 1; i < Team_Data.size(); i++){
    if(Team_Data[i].first == nowScore){
      Team_Rank[Team_Data[i].second] = nowRank;
    }else{
      nowRank++;
      nowScore = Team_Data[i].first;
      Team_Rank[Team_Data[i].second] = nowRank;
    }
  }
  
  int ref;
  while(cin >> ref){
    cout << Team_Rank[ref] << endl;
  }
  return 0;
}

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



int main() {
    int N,M,K;
    cin>>N>>M>>K;
    vector<int> checked(N);
    vector<int> group(N);
    vector<vector<int>> frien(N,vector<int>(0));
    
    vector<vector<int>> block(N,vector<int>(0));
    rep(i,M){
        int a,b;
        cin>>a>>b;
        --a;--b;
        frien.at(a).push_back(b);
        frien.at(b).push_back(a);
    }
    rep(i,K){
        int c,d;
        cin>>c>>d;
        --c;--d;
        block.at(c).push_back(d);
        block.at(d).push_back(c);
    }
    
    int num=1;
    rep(i,N){
        if(group[i]!=0){continue;}
        
        //bfs
        queue<int> q;
        q.push(i);
        while(!q.empty()){
            int v=q.front();
            checked.at(v)=1;
            group.at(v)=num;
            q.pop();
            for(auto x:frien.at(v)){
                if(checked.at(x)==0)q.push(x);
            }
        }

        num++;
    }
    vector<int> member(num);
    rep(i,N){
        member[group[i]]++;
    }
    /*
    rep(i,num){
        cout<<member[i]<<" ";
    }
    cout<<endl;

    rep(i,N){
        cout<<group[i]<<" ";
    }
    cout<<endl;*/

    vector<int> B(N);
    rep(i,N){
        for(auto x:block.at(i)){
            if(group[i]==group[x]){B.at(i)++;}
        }
    }

    rep(i,N){
        cout<<member.at(group[i])-1-frien.at(i).size()-B.at(i);
        if(i==N-1){cout<<endl;}
        else{cout<<" ";}
    }
}

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

#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n)-1;i>=0;i--)
#define rrep2(i,a,b) for (int i=(a)-1;i>=b;i--)
#define chmin(a,b) (a)=min((a),(b));
#define chmax(a,b) (a)=max((a),(b));
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define printV(v) cerr<<(#v)<<":";for(auto(x):(v)){cerr<<" "<<(x);}cerr<<endl;
#define printVS(vs) cerr<<(#vs)<<":"<<endl;for(auto(s):(vs)){cerr<<(s)<< endl;}
#define printVV(vv) cerr<<(#vv)<<":"<<endl;for(auto(v):(vv)){for(auto(x):(v)){cerr<<" "<<(x);}cerr<<endl;}
#define printP(p) cerr<<(#p)<<(p).first<<" "<<(p).second<<endl;
#define printVP(vp) cerr<<(#vp)<<":"<<endl;for(auto(p):(vp)){cerr<<(p).first<<" "<<(p).second<<endl;}

inline void output(){ cerr << endl; }
template<typename First, typename... Rest>
inline void output(const First& first, const Rest&... rest) {
    cerr << first << " "; output(rest...);
}

using ll = long long;
using Pii = pair<int, int>;
using TUPLE = tuple<int, int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
const int inf = 1ll << 60;
const int mod = 1e9 + 7;
using Graph = vector<vector<int>>;

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

  int W, n;
  int t = 1;
  while (cin >> W) {
    if (W == 0) return 0;
    cin >> n;
    vi v(n), w(n);
    string s;
    rep(i, n) {
      getline(cin, s, ',');
      v[i] = stoi(s);
      cin >> w[i];
    }

    vvi dp(n+1, vi(W+1, -inf));
    dp[0][0] = 0;
    rep2(i, 1, n + 1) {
      rep(j, W + 1) {
        chmax(dp[i][j], dp[i-1][j]);
        if (j - w[i-1] >= 0) {
          chmax(dp[i][j], dp[i-1][j-w[i-1]] + v[i-1]);
        }
      }
    }

    cout << "Case " << t << ":" << endl;
    int ma_v = *max_element(all(dp[n]));
    int mi_w = inf;
    rep(j, W+1) {
      if (dp[n][j] == ma_v) {
        mi_w = j;
        break;
      }
    }
    cout << ma_v << endl;
    cout << mi_w << endl;

    t++;
  }
}



Measured memory_bytes: 10812
#include "iostream"
#include "string"
using namespace std;

int main(int argc, char const *argv[])
{
	char x[1001];
	int y[1001];
	int sum=0;
	int count=0;
	int i=0;

	while(true)
	{
		sum =0;
		i=0;
		cin >> x;
		// if(strncmp(x, "0", 1001) == 0)
		// {
		// 	break;
		// }

		if(x[0] == 48)
		{
			break;
		}

		while(x[i] != 0)
		{
			sum += x[i] - '0';
			i++;
		}

		cout << sum << endl;

	}

	return 0;
}


Measured memory_bytes: 3056
#[allow(unused_imports)]
use std::cmp::{Ordering};

#[allow(unused_imports)]
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};

#[allow(unused_imports)]
use std::io::{stdin, stdout, BufWriter, Write};

#[allow(unused_imports)]
use std::iter::FromIterator;

#[allow(unused_macros)]
macro_rules! min {
    ($x: expr) => ($x);
    ($x: expr, $($z: expr),+) => {{
        std::cmp::min($x, min!($($z),*))
    }}
}

#[allow(unused_macros)]
macro_rules! max {
    ($x: expr) => ($x);
    ($x: expr, $($z: expr),+) => {{
        std::cmp::max($x, max!($($z),*))
    }}
}

#[allow(unused_macros)]
macro_rules! get { 
    ([$t: ty]) => { 
        { 
            let mut line = String::new(); 
            stdin().read_line(&mut line).unwrap(); 
            line.split_whitespace().map(|t|t.parse::<$t>().unwrap()).collect::<Vec<_>>()
        }
    };
    ([$t: ty];$n: expr) => {
        (0..$n).map(|_|get!([$t])).collect::<Vec<_>>()
    };
    ($t: ty) => {
        {
            let mut line = String::new();
            stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t: ty),*) => {
        { 
            let mut line = String::new();
            stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            ($(iter.next().unwrap().parse::<$t>().unwrap(),)*)
        }
    };
    ($t: ty; $n: expr) => {
        (0..$n).map(|_|get!($t)).collect::<Vec<_>>()
    };
    ($($t: ty),*; $n: expr) => {
        (0..$n).map(|_|get!($($t),*)).collect::<Vec<_>>()
    };
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        #[cfg(debug_assertions)]
        writeln!(&mut std::io::stderr(), concat!("[DEBUG] ", $(stringify!($a), "={:?} "),*), $($a),*).unwrap();
    }
}

const BIG_STACK_SIZE: bool = true;

#[allow(dead_code)]
fn main() {
    use std::thread;
    if BIG_STACK_SIZE {
        thread::Builder::new()
            .stack_size(32 * 1024 * 1024)
            .name("solve".into())
            .spawn(solve)
            .unwrap()
            .join()
            .unwrap();
    } else {
        solve();
    }
}

fn solve() {
    let (n,k) = get!(usize, usize);
    let v = get!([isize]).into_iter().collect::<VecDeque<_>>();

    let mut mx = 0;
    for l in 0..n+1 {
        for r in 0..n+1 {
            if l+r > n || l+r > k {
                break;
            }
            let mut v = v.clone();
            let rest = k-l-r;
            let mut pop = Vec::with_capacity(l+r);
            for i in 0..l {
                pop.push(v.pop_front().unwrap());
            }
            for i in 0..r {
                pop.push(v.pop_back().unwrap());
            }
            pop.sort();
            let mut count = 0;
            for i in 0..min!(pop.len(), rest) {
                if pop[i] < 0 {
                    count += 1;
                } else {
                    break;
                }
            }
            let sum = pop.into_iter().skip(count).sum::<isize>();
            mx = max!(mx, sum);
        }
    }
    println!("{}", mx);
}


Measured memory_bytes: 8572
#include <bits/stdc++.h>
#define INF 2147483647
#define INF_LL 9223372036854775807
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;

int main() {
	int n, m;
	cin >> n >> m;
	cout << (n - 1)*(m - 1) << endl;
	return 0;
}

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

using namespace std;
using ll = long long;


int main()
{
    int n,d, x;
    cin >> n >> d >> x;
    vector<int> a(n);
    vector<int> sum(d + 1);
    
    for(int i = 0; i < n; i++)cin >> a[i];

    for(auto i : a){
        for(int j = 1; j <= d; j += i)sum[j]++;
    }
    cout << accumulate(sum.begin(), sum.end(), 0) + x << endl;

}

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

using ll = long long;
using G = vector<vector<int>>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const ll MOD = 1000000007;

ll GCD(ll x, ll y){
	return y ? GCD(y, x%y) : x;	
}

int main() {
	string s; cin >> s;
	string ans = "Yes";
	for(int i=0;i<s.size();i++){
		if(i%2==0 && s[i]=='L'){
			ans = "No";
			break;
		}
		if(i%2==1 && s[i]=='R'){
			ans = "No";
			break;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
N = int(input())
P = list(map(int,input().split()))
cnt = 0
for i in range(1, N):
  if P[i-1] == i:
    tmp = P[i-1]
    P[i-1] = P[i]
    P[i] = tmp
    cnt += 1
if P[N-1] == N:
  tmp = P[N-1]
  P[N-1] = P[N-2]
  P[N-2] = tmp
  cnt += 1
print(cnt)

Measured memory_bytes: 13880
// ????????????????????°??????: ??£??\?????????

// Library
#include<vector>
#include<queue>
#include<functional>
#include<algorithm>
#include<cassert>
// Type
typedef int Vertex;
typedef int Weight;
struct Edge {
  Vertex from, to;
  Weight weight;
};
bool operator<(const Edge& lhs, const Edge& rhs) {
  if(lhs.weight != rhs.weight) return lhs.weight < rhs.weight;
  if(lhs.from != rhs.from) return lhs.from < rhs.from;
  return lhs.to < rhs.to;
}
bool operator>(const Edge& lhs, const Edge& rhs) {
  if(lhs.weight != rhs.weight) return lhs.weight > rhs.weight;
  if(lhs.from != rhs.from) return lhs.from > rhs.from;
  return lhs.to > rhs.to;
}
// Class
class Graph {
public:
  explicit Graph(int size);
  void add(const Vertex& from, const Vertex& to, const Weight& weight = 1);
  const std::vector<Edge> minimum_spanning_tree() const;
private:
  int size_;
  std::vector<std::vector<Edge>> edge_;
};
// Implement
Graph::Graph(int size) : size_(size), edge_(size) {
}
void Graph::add(const Vertex& from, const Vertex& to, const Weight& weight) {
  edge_.at(from).push_back({from, to, weight});
  edge_.at(to).push_back({to, from, weight});
}
// Minimum Spanning Tree: Prim's algorithm, O(|E| + |V| log |V|)
const std::vector<Edge> Graph::minimum_spanning_tree() const {
  std::vector<Edge> result;
  std::priority_queue<Edge, std::vector<Edge>, std::greater<Edge>> q(std::begin(edge_.front()), std::end(edge_.front()));
  std::vector<bool> visited(size_, false);
  visited.front() = true;
  while(!q.empty()) {
    auto current = q.top();
    q.pop();
    if(visited.at(current.to)) continue;
    visited.at(current.to) = true;
    result.push_back(current);
    for(const auto& e: edge_.at(current.to)) if(!visited[e.to]) q.push(e);
  }
  assert(result.size() == size_ - 1);
  return result;
}

#include<bits/stdc++.h>
using namespace std;
int main() {
  int V, E;
  cin >> V >> E;
  Graph g(V);
  for(int i = 0; i < E; ++i) {
    int s, t, w;
    cin >> s >> t >> w;
    g.add(s, t, w);
  }
  auto mst = g.minimum_spanning_tree();
  cout << accumulate(begin(mst), end(mst), 0, [](int sum, Edge e){return sum + e.weight;}) << endl;
}

Measured memory_bytes: 7292
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <string>
#include <queue>
#include <fstream>
#include <string>
#include <math.h>
#include <set>
#include <string>
#include <bitset>
#include <fstream>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
//typedef pair<ll, P> T;

#define rep(i, n) for (ll i = 0; i < (n); i++)
#define revrep(i, n) for (ll i = (n) - 1; i >= 0; i--)
#define f first
#define s second
#define pb push_back

ll mod = 1000000007;
const ll INF = 100000000000010000;
//const ull B = 998244353;
//ll kai[3010];

//void pres(double A, ll x = 20) { printf("%.20f\n", x); }

vector<ll> dx = { 0, 1, 0, -1, 1, -1, 1, -1, 0};
vector<ll> dy = { 1, 0, -1, 0, 1, 1, -1, -1, 0};

void chmin(double& x, double y) {
	x = min(x, y);
}

void chmax(double& x, double y) {
	x = max(x, y);
}

ll pow_long(ll x, ll y) {
	ll res = 1;
	while (y > 0) {
		if (y % 2 == 1) res *= x;
		x *= x;
		y /= 2;
	}
	return res;
}

void test() {
	cout << "888888888888888888888888" << endl;
}

ll gcd(ll x, ll y) {
	if (y == 0) return x;
	return gcd(y, x % y);
}

ll pow_mod(ll x, ll k) {
	x %= mod;
	ll res = 1;
	while (k > 0) {
		if (k % 2) {
			res *= x; res %= mod;
		}
		x *= x; x %= mod;
		k /= 2;
	}
	return res;
}

ll div_mod(ll x) {
	return pow_mod(x, mod - 2);
}

//コンビネーション
const int MAXcomb = 1000010;
ll fac[MAXcomb], finv[MAXcomb], inv[MAXcomb];
//facはn!,finvは1/n!
//invは逆元
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAXcomb; 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 comb(int n, int k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * finv[k] % mod * finv[n - k] % mod;
}

ll N, K;
vector<P> ans;
ll num;

void solve() {
	cin >> N >> K;
	rep(i, N) if (i != 0) ans.pb(P(i, N));
	num = (N - 1) * (N - 2) / 2;
	if (K > num) {
		cout << -1 << endl;
		return;
	}
	for (ll i = 1; i < N; i++) {
		for (ll j = i + 1; j < N; j++) {
			if (K == num) break;
			ans.pb(P(i, j)); num--;
		}
	}
	cout << ans.size() << endl;
	for (P p: ans) cout << p.f << ' ' << p.s << endl;
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll T = 1;
	//cin >> T;
	rep(i, T) solve();
}


Measured memory_bytes: 512
from sys import stdin

input=stdin.readline

n=int(input())

cost=[0 for i in range(n)]

s=list(map(int,input().split()))
cost[1]=abs(s[1]-s[0])

for i in range(2,n):
    cost[i]=min(cost[i-1]+abs(s[i]-s[i-1]),cost[i-2]+abs(s[i]-s[i-2]))

print(cost[-1])


Measured memory_bytes: 88932
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <functional>
#include <queue>
#include <string>
#include <cstring>
#include <numeric>
#include <cstdlib>
#include <cmath>
using namespace std;

typedef long long ll;

#define INF 10e10
#define REP(i,n) for(int i=0; i<n; i++)
#define REP_R(i,n,m) for(int i=m; i<n; i++)
#define MAX 10000

int N;
int a[MAX];
int ans = 0;

int main() {
  scanf("%d", &N);
  REP(i,N) scanf("%d", &a[i]);

  int i = 1;

  while (i < N) {
    int count = 1;
    while (a[i] == a[i-1]) {
      count++;
      i++;
    }

    if (count > 1) {
      ans += count / 2;
      i--;
    }

    i++;

  }

  cout << ans << endl;
}


Measured memory_bytes: 256
line =gets.split(' ').map(&:to_i)
p = line[0]
r = line[1]
q = line[2]
sai = 300
for i in 0..2 do
  for j in 0..2 do
    aho = line[i]+line[j]
    if i == j then 
      break
    end
    if aho <= sai
      sai = aho
    end
    end
  end
puts sai

Measured memory_bytes: 1788
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
const ll MOD=(ll)1e9+7;

int dp[110][100][310]; //i,j,k i番目まででj個使って，重さの差の和がkの時の最大価値

ll mini(ll a,ll b,ll c){
    return min(a,min(b,c));
}

ll maxi(ll a,ll b,ll c){
    return max(a,max(b,c));
}

int main(){
    ll H,W; cin>>H>>W;
    ll ans=1e18;
    //三型
    if(H%3==0||W%3==0) ans=0;
    else ans=min(H,W);

    //T型
    ll s1,s2,s3;
    for (int i = 1; i < H; ++i) {
        s1=i*W;
        s2=(H-i)*(W/2); s3=(H-i)*W-s2;
        ans=min(ans,maxi(s1,s2,s3)-mini(s1,s2,s3));
    }

    //ト型
    for (int i = 1; i < W; ++i) {
        s1=i*H;
        s2=(W-i)*(H/2); s3=(W-i)*H-s2;
        ans=min(ans,maxi(s1,s2,s3)-mini(s1,s2,s3));
    }

    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <string>
#include <cmath>
#include <map>
#include <vector>
#include <set>
#include <queue>
#include <stack>
using namespace std;
typedef long long ll;



int main()
{
    int n,m;
    while(~scanf("%d%d",&n,&m)) printf("%d\n",n*m-n-m+1);
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
using std::cin;
using std::cout;
using std::endl;

int countTriangles(int *lines, int num_lines)
{
    //int total_triangles = num_lines * (num_lines - 1) * (num_lines - 2) / 6;
    int total_triangles = 0;
    std::sort(lines, lines + num_lines);
    for (int i = 0; i < num_lines - 2; i++)
    {
        for (int j = i + 1; j < num_lines - 1; j++)
        {
            for (int k = j + 1; k < num_lines; k++)
            {
                if (lines[i] + lines[j] > lines[k])
                {
                    total_triangles++;
                }
            }
        }
    }
    return total_triangles;
}

int main()
{
    int N, total_triangles;
    cin >> N;
    int L[N];
    for (int i = 0; i < N; i++)
    {
        cin >> L[i];
    }
    total_triangles = countTriangles(L, N);
    cout << total_triangles << endl;
    return EXIT_SUCCESS;
}

Measured memory_bytes: 256
ni = lambda: int(input())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))

n, m = nm()

a = sorted(nl())

pos = 0

changer = []

for i in range(m):
    b, c = nm()
    changer.append((c, b))

changer = sorted(changer)[::-1]


for i in range(m):

    c = changer[i]
    for j in range(c[1]):
        while pos < n:
            if a[pos] < c[0]:
                a[pos] = c[0]
                break
            pos += 1
    if pos >= n:
        break

print(sum(a))


Measured memory_bytes: 23252
#include<cstdio>
const int MAXN=10+5;
char c[MAXN];int a,b;
int main()
{
	scanf("%d %d",&a,&b);
	scanf("%s",c);
	if(c[a]!='-')
	{
		printf("No");
		return 0;
	}
	for(int i=0;i<a;i++)
		if(!(c[i]>='0' && c[i]<='9'))
		{
			printf("No");
			return 0;
		}
	for(int i=a+1;i<a+b+1;i++)
		if(!(c[i]>='0' && c[i]<='9'))
		{
			printf("No");
			return 0;
		}
	printf("Yes");
	return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define LL long long
#define pa pair<int,int>
const int Maxn=200010;
const int inf=2147483647;
int read()
{
    int x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9')x=(x<<3)+(x<<1)+(ch^48),ch=getchar();
    return x*f;
}
int n,a[Maxn],p[Maxn];
int main()
{
	n=read();
	p[0]=0;
	for(int i=1;i<=n;i++)
	{
		a[i]=read();
		if(!a[i])p[i]=p[i-1];
		else p[i]=i;
	}
	LL ans=n;
	for(int i=1;i<=n;i++)
	{
		int S=a[i],j=i-1;
		while(j)
		{
			if(!a[j])
			{
				ans+=(j-p[j]);
				j=p[j];
			}
			else
			{
				if(S&a[j])break;
				S|=a[j];
				ans++;
				j--;
			}
		}
	}
	printf("%lld",ans);
}


Measured memory_bytes: 1792
import sys
import math
import collections
from collections import deque
#n = int(input())
#a, b = map(int, input().split())
s = input()
#x = list(map(int, input().split()))
q = int(input())
d = deque([])
for i in range(len(s)):
    d.append(s[i])

rev = 1
for i in range(q):
    que = sys.stdin.readline().split()
    if que[0] == "1":
        rev *= -1

    else:
        if rev == 1:
            if que[1] == "1":
                d.appendleft(que[2])
            else:
                d.append(que[2])

        else:
            if que[1] == "1":
                d.append(que[2])
            else:
                d.appendleft(que[2])


if rev == 1:
    for i in range(len(d)):
        print(d.popleft(), end="")
else:
    for i in range(len(d)):
        print(d.pop(), end="")




Measured memory_bytes: 7652
#include<bits/stdc++.h>
using namespace std;
int main(){
    int a,b;
    cin>>a>>b;
    int x=1;
    while(x<=b){
        x*=10;
    }
    int n=a*x+b;
    int m=sqrt(n);
    if(m*m==n){puts("Yes");}
    else{puts("No");}
    return 0;
}
    

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <algorithm>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#include <functional>
#define vv(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define vvi vector<vector<int> >
#define vvl vector<vector<ll> >
#define vll vector<ll>
#define rep(c, a, b) for(ll c=a;c<b;c++)
#define re(c, b) for(ll c=0;c<b;c++)
typedef long long int ll;
typedef long double ld;
using namespace std;

int main(int argc, char const *argv[]) {
  ll a, n, m;std::cin >> n >> m;
  vll dat(m, 0), p(m, 0);

  map<ll, ll> mp;
  re(i, n){
    std::cin >> a;
    dat[a%m]++;
    if(mp.find(a)==mp.end()) mp.emplace(a, 1);
    else (*mp.find(a)).second++;
  }
  for(auto itr = mp.begin();itr!=mp.end();itr++){
    ll num = (*itr).first, k = (*itr).second;
    p[num%m]+=k/2;
  }
  ll ans = 0;
  for(int i=1;i<m/2+(m%2==1?1:0);i++){
    ll k = min(dat[i], dat[m-i]);
    ll a = k + min((dat[i]-k)/2, p[i]) + min((dat[m-i]-k)/2, p[m-i]);
    ll b = 0;
    if(k>0){
      k--;
      b = k + min((dat[i]-k)/2, p[i]) + min((dat[m-i]-k)/2, p[m-i]);
    }
    ans += max(a, b);
  }
  ans += dat[0]/2;
  if(m%2==0) ans += dat[m/2]/2;
  std::cout << ans << '\n';
  return 0;
}


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

using i64 = long long;

int v[300005];

void die(int x = -1) {
    cout << x << '\n';
    exit(0); }

struct Kheap {
    multiset<int> l, r;
    i64 sl, sr;
    int k;

    Kheap(int _k) {
        l.clear(), r.clear();
        k = _k;
        sl = sr = 0LL; }

    void baga(int x) {
        multiset<int>::iterator it;
        l.insert(x);
        sl+= x;

        if (l.size() > k) {
            it = l.end(); --it;
            r.insert(*it);
            sl-= *it;
            sr+= *it;
            l.erase(it); } }

    void scoate(int x) {
        multiset<int>::iterator it;
        it = l.find(x);

        if (it != end(l)) {
            sl-= *it;
            l.erase(it);
            if (!r.empty()) {
                it = r.begin();
                sr-= *it;
                sl+= *it;
                l.insert(*it);
                r.erase(it); }
            return; }

        it = r.find(x);
        if (it != end(r)) {
            sr-= *it;
            r.erase(it); } } };

int main() {
    //freopen("dat.in", "r", stdin);
    ios::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    i64 ant, sa, sb;
    int n;

    cin >> n;
    Kheap l(n), r(n);
    for (int i = 1; i <= n * 3; ++i)
        cin >> v[i];
    for (int i = 1; i <= n; ++i)
        l.baga(-v[i]);
    for (int i = 1; i <= 2 * n; ++i)
        r.baga(v[3 * n - i + 1]);

    ant = (-l.sl) - r.sl;
    for (int i = n + 1; i <= 2 * n; ++i) {
        l.baga(-v[i]);
        r.scoate(v[i]);
        ant = max(ant, (-l.sl) - (r.sl)); }

    cout << ant << '\n';

    return 0; }


Measured memory_bytes: 15488
import java.util.*

fun main(arr:Array<String>) {
    val (n,m) = readLine()!!.split(" ").map { it.toInt() }
    val numList = PriorityQueue<Long>()
    readLine()!!.split(" ").map { it.toLong() * -1 }.forEach { numList.add(it) }
    val rewriteList = (1..m).map { readLine()!!.split(" ").map { it.toLong() } }.sortedByDescending { it[1] }
    var ans = 0L
    var remain = n
    var idx = 0
    while (remain > 0) {
        if(idx >= rewriteList.size || numList.peek() * -1 >= rewriteList[idx][1]) {
            ans += numList.poll() * -1
            remain--
        } else {
            val cnt = Math.min(remain, rewriteList[idx][0].toInt())
            ans += rewriteList[idx][1] * cnt
            idx++
            remain -= cnt
        }
    }

    println(ans)
}



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

#define ONLINE_JUDGE
#define ll long long
#define PI 3.14159265359
#define fore(i, l, r) for(int i = int(l); i < int(r); ++i)
#define pb(a) push_back(a)

//////////// Solution /////////////////////////////////

void solve() {
	int n,k;
	cin >> n >> k;
	string s;
	cin >> s;
	s[k-1] = tolower(s[k-1]);
	cout << s;
}


/////////// End Solution ///////////////////////////////////////

//////// Initialization ////////////////////////////////////

int main() {

	#ifndef ONLINE_JUDGE
	FILE *FIN = freopen("/home/danil/prog/input.txt", "r", stdin);
	clock_t time_start = clock();
	#endif

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

	solve();

	#ifndef ONLINE_JUDGE
	fclose(FIN);
	cerr << "\x1b[031m\n-----------------\nTime=" << (ll)((double)(clock()-time_start) / CLOCKS_PER_SEC * 1000) << "ms\n\x1b[0m";
	#endif

	return 0;
}

//////// End Initialization ///////////////////////////////////////

Measured memory_bytes: 256
using System;

namespace Csharp_ITP1 {
    class ITP1_2_D {
        static void Main() {
            string[] s = Console.ReadLine().Split();
            int W = int.Parse(s[0]);
            int H = int.Parse(s[1]);
            int x = int.Parse(s[2]);
            int y = int.Parse(s[3]);
            int r = int.Parse(s[4]);
            Console.WriteLine
               ((x - r < 0 || W < x + r || y - r < 0 || H < y + r) ? "No" : "Yes");
        }
    }
}


Measured memory_bytes: 18000
#include<iostream>
#include <cstring>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
typedef pair<int,int> pint;
typedef pair<ll,int> pli;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;


int main(){
  ll a, b, c; cin >> a >> b >> c;
  cout << max(a-c, 0LL);
  cout << " ";
  cout << max(b - max(c-a, 0LL), 0LL) << endl;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")

#include <bits/stdc++.h>
using namespace std;

const int M=1000000007;

int main()
{
    int n,k;
    cin>> n >> k;
    int x=n+1,y=2,z=n-2;
    int ans=(k>1)?1:(x+1);
    bool f=true;
    while(y<=n){
        if(f) x=(x+z<M)?(x+z):(x+z-M);
        else x=(x-z<0)?(x-z+M):((x-z<M)?(x-z):(x-z-M));
        if(y>=k) ans=(ans+x<M)?(ans+x):(ans+x-M);
        if(z==1 && f) z-=2;
        if(z<2) f=false;
        z+=f?-2:2,y++;
    }
    cout<< ans <<endl;
    return 0;
}

Measured memory_bytes: 3636
use proconio::{input, fastout};
use proconio::marker::Chars;

#[fastout]
fn main() {
    input!{
        s: Chars,
    }
    let ng = s.iter().enumerate().any(|(i, c)|
        if i & 1 == 1 {
            *c == 'R'
        } else {
            *c == 'L'
        }
    );
    if ng {
         println!("No");
    } else {
         println!("Yes");
    }
}

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

#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,m,n) for(int i=m;i<(n);i++)
#define ALL(v) v.begin(),v.end()

template<typename flow_t>
struct edge {
	int to;
	flow_t cap;
	int rev;
	bool isrev;
	int idx;
	edge(int to, flow_t cap, int rev, bool isrev, int idx) :to(to), cap(cap), rev(rev), isrev(isrev), idx(idx) {}
};

template< typename flow_t >
struct Dinic {
	const flow_t INF;

	vector< vector< edge<flow_t> > > graph;
	vector< int > min_cost, iter;

	Dinic(int V) : INF(numeric_limits< flow_t >::max()), graph(V) {}

	void add_edge(int from, int to, flow_t cap, int idx = -1) {
		graph[from].push_back((edge<flow_t>) { to, cap, (int)graph[to].size(), false, idx });
		graph[to].push_back((edge<flow_t>) { from, 0, (int)graph[from].size() - 1, true, idx });
	}

	bool bfs(int s, int t) {
		min_cost.assign(graph.size(), -1);
		queue< int > que;
		min_cost[s] = 0;
		que.push(s);
		while (!que.empty() && min_cost[t] == -1) {
			int p = que.front();
			que.pop();
			for (auto &e : graph[p]) {
				if (e.cap > 0 && min_cost[e.to] == -1) {
					min_cost[e.to] = min_cost[p] + 1;
					que.push(e.to);
				}
			}
		}
		return min_cost[t] != -1;
	}

	flow_t dfs(int idx, const int t, flow_t flow) {
		if (idx == t) return flow;
		for (int &i = iter[idx]; i < graph[idx].size(); i++) {
			edge<flow_t> &e = graph[idx][i];
			if (e.cap > 0 && min_cost[idx] < min_cost[e.to]) {
				flow_t d = dfs(e.to, t, min(flow, e.cap));
				if (d > 0) {
					e.cap -= d;
					graph[e.to][e.rev].cap += d;
					return d;
				}
			}
		}
		return 0;
	}

	flow_t max_flow(int s, int t) {
		flow_t flow = 0;
		while (bfs(s, t)) {
			iter.assign(graph.size(), 0);
			flow_t f = 0;
			while ((f = dfs(s, t, INF)) > 0) flow += f;
		}
		return flow;
	}

	void output() {
		for (int i = 0; i < graph.size(); i++) {
			for (auto &e : graph[i]) {
				if (e.isrev) continue;
				auto &rev_e = graph[e.to][e.rev];
				cout << i << "->" << e.to << " (flow: " << rev_e.cap << "/" << e.cap + rev_e.cap << ")" << endl;
			}
		}
	}
};
long long gcd(long long x, long long y) {
	long long m = max(x, y), n = min(x, y);
	if (m%n == 0)return n;
	else return gcd(m%n, n);
}

void solve() {
	int N, M; cin >> N >> M;
	if (N == 0)exit(0);
	vector<int>B(N), R(M);
	int s = N + M, t = N + M + 1;
	Dinic<int>g(N + M + 2);
	REP(i, N) {
		cin >> B[i];
		g.add_edge(s, i, 1);
	}
	REP(i, M) {
		cin >> R[i];
		g.add_edge(N + i, t, 1);
	}
	REP(i, N) {
		REP(j, M) {
			if(gcd(B[i],R[j])!=1)g.add_edge(i, N + j, 1);
		}
	}
	cout << g.max_flow(s, t) << endl;
}

//void solve() {
//	int V, E; cin >> V >> E;
//	Dinic<int>g(V);
//	REP(i, E) {
//		int u, v, c; cin >> u >> v >> c;
//		g.add_edge(u, v, c);
//	}
//	cout << g.max_flow(0, V - 1) << endl;
//}

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
    while(true)
	solve();
}


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

#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define endl '\n'
#define fcin ios::sync_with_stdio(false); cin.tie(nullptr);
#define INF 0x3f3f3f3f
#define all(x) x.begin(), x.end()
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

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

template <typename A, typename B>
string to_string(pair<A, B> p){
    return "(" + to_string(p.fi) + ", " + to_string(p.se) + ")";
}

template <typename T>
string to_string(T v){
    string s = "{";
    bool first = true;
    for(const auto & x : v){
        if(!first) s += ", ";
        first = false;
        s += to_string(x);
    }
    return s + "}";
}

void debug_out(){ cerr << endl;}
template <typename First, typename... Next>
void debug_out(First F, Next... N){
    cerr << " " << to_string(F);
    debug_out(N...);
}

#ifdef LOCAL
    #define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
    #define debug(...) 1
#endif

int main(){
    fcin;
    int n;
    cin >> n;
    vector<int> a(n);
    map<int, ll> f;
    for(int i = 0; i < n; i++){
        cin >> a[i];
        f[a[i]]++;
    }
    ll ans = 0;
    for(auto p : f){
        ans += (p.se * (p.se - 1))/2;
    }

    for(int i = 0; i < n; i++){
        ll qt = f[a[i]];
        ll t = ans;
        t -= (qt * (qt-1))/2;
        qt--;
        t += max(0LL, (qt * (qt-1))/2);

        cout << t << endl;
    }
    return 0;
}



Measured memory_bytes: 10368
#include<bits/stdc++.h> 
using  namespace std; 
int  main() { 
  int n; 
cin>>n; 
set<string>st;
for(int i=0;i<n;i++) { 
string s;
cin>>s;
st.insert(s); 
} 
cout<<st.size()<<endl; 
return 0; 
}

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

#define INF 1000000000
#define MOD 1000000007
#define ll long long
#define rep(i,a,b) for(int i = (a); i < (b); i++)
#define bitget(a,b) (((a) >> (b)) & 1)
#define vint vector<int>
#define vvint vector<vector<int>>
#define vsort(x) sort(x.begin(),x.end())

using int64 = uint64_t;

using namespace std;

int main() {
	int l, a, b, c, d;
	cin >> l >> a >> b >> c >> d;
	cout << l - max((a-1) / c + 1, (b-1) / d + 1) << endl;
	return 0;
}

Measured memory_bytes: 3084
#include <bits/stdc++.h>
using namespace std;
int main() {
	int n;
	scanf("%d", &n);
	if (n % 2 == 0) {
		printf("%.10lf\n", 1.0/2);
	} else {
		int t = n / 2 + 1;
		printf("%.10lf\n", t*1.0/n);
	}
	return 0;
}

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

using namespace std;

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

  int sz = s.size(), tz = t.size();
  int p = -1;
  for (int i = 0; i < sz; i++) {
    if (i + tz - 1 >= sz) continue;
    bool yes = true;
    for (int j = 0; j < tz; j++) {
      yes &= !(s[i + j] != '?' && s[i + j] != t[j]);
    }
    if (yes) p = i;
  }

  if (p == -1) {
    cout << "UNRESTORABLE\n";
  } else {
    for (int i = 0; i < sz; i++) {
      if (i >= p && i <= p + tz - 1) {
        s[i] = t[i - p];
      } else if (s[i] == '?') {
        s[i] = 'a';
      }
    }
    cout << s << endl;
  }

  return 0;
}

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

int main() {
  int N, M;
  vector<int> A(M);
  cin >> N >> M;
  for(int i = 0; i < M; i++){
    cin >> A.at(i);
  }
  int sum = 0;
  for(int i = 0; i < M; i++){
    sum += A.at(i);
  }
  
  int answer = N - sum;
  if(answer >= 0){
	cout << answer << endl;
  }
  else cout << -1 << endl;
  
  
}

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

#define rep(i, a, n)  for(int i=a; i<n; i++)
#define per(i, a, n)  for(int i=n-1; i>=a; i--)
#define fill0(n)  setfill('0') << right << setw(n)
#define all(x)  (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define MAX 1000000001;
using namespace std;
typedef long long ll;

int n;
int a,b,c;
int l[20];

ll dfs(int cur, int A, int B, int C){
  if(cur==n+1){
    if(A==0 || B==0 || C==0)return MAX;
    ll ret = abs(a-A)+abs(b-B)+abs(c-C)-30;
    return ret;
  }

  // ll res = MAX;
  ll res0 = dfs(cur+1, A, B, C);
  ll res1 = dfs(cur+1, A+l[cur], B, C)+ 10;
  ll res2 = dfs(cur+1, A, B+l[cur], C)+ 10;
  ll res3 = dfs(cur+1, A, B, C+l[cur])+ 10;

  return min(res0,min(res1,min(res2,res3)));
}

int main(){
  std::cin >> n >> a>>b>>c;
  rep(i,1,n+1)std::cin >> l[i];
  std::cout << dfs(1,0,0,0) << '\n';
  return 0;
}


Measured memory_bytes: 256