akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <boost/foreach.hpp>
using namespace std;
#define pi 2*asin(1.0)
#define MAX 10000000
#define MOD 1000000007
#define _GLIBCXX_DEBUG
 
vector<long> fac(MAX);
vector<long> finv(MAX);
vector<long> inv(MAX);
vector<long> Primelist;
//template functions
/////////////////////////
void Prinit(){
long PR=10000001;
vector<long> P(PR,0);
for(long i=2;i*i<PR;i++){
    if(P.at(i)==0){
        long j=i;
      j+=i;
        while(j<PR){
            P.at(j)=1;
             j+=i;         
        }
    }
}

for(long i=2;i*i<PR;i++){//Primelist.size()=446
    if(P.at(i)==0){
        Primelist.push_back(i);
    }
}
}

void Cominit(){
  fac.at(0)=fac.at(1)=1;
  finv.at(0)=finv.at(1)=1;
  inv.at(1)=1;
  for(long i=2;i<MAX;i++){
      fac.at(i)=(fac.at(i-1)*i)%MOD;
      inv.at(i)=MOD-inv.at(MOD%i)*(MOD/i)%MOD;
      finv.at(i)=finv.at(i-1)*inv.at(i)%MOD;
  }
}

long facComb(long N,long M){// nCm%
if(N<M) return 0;
if(N<0||M<0) return 0;
return fac.at(N)*(finv.at(M)*finv.at(N-M)%MOD)%MOD;
}

long Comb(long N,long M){// nCm
long ans=1;
for(long i=N;i>N-M;i--){
    ans=ans*i;
}
for(long i=M;i>0;i--){
    ans=ans/i;
}
return ans;
}

long Perm(long N,long M){// nPm
long ans=1;
for(long i=N;i>N-M;i--){
    ans=ans*i;
}
return ans;
}

long GCM(long A,long B){
            long W,r;
    if(A<B){

        W=B;
        B=A;
        A=W;
    }
    while(A%B!=0){
        r=A%B;
        A=B;
        B=r;
    }
    return B;
}
long LCM(long A,long B){
    return (A*B)/GCM(A,B);
}

long upDiv(long a,long b){
  return (a+b-1)/b;
}

long strtolong(string str){
istringstream ss;
ss=istringstream(str);
long num;
ss>>num;
return num;
}

long chartolong(char ch){
long num;
num=ch-'0';
return num;
}

string longtostr(long N){
    string str;
    str=to_string(N);
    return str;
}









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


//Answer


int main() {

long A,B,C,D;
cin>>A>>B>>C>>D;
if(C>=0){
    if(B>=0){
        cout<<B*D<<endl;;
    }else{
        cout<<B*C<<endl;
    }
}else if(D>=0){
    if(A*C>B*D){
        cout<<A*C<<endl;
    }else{
        cout<<B*D<<endl;
    }
}else{
    if(A>=0){
        cout<<A*D<<endl;
    }else{
        cout<<A*C<<endl;
    }
}

}





Measured memory_bytes: 237480
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {

    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        BReversi solver = new BReversi();
        solver.solve(1, in, out);
        out.close();
    }

    static class BReversi {

        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            int[] a = new int[n];
            for (int i = 0; i < n; i++) {
                a[i] = in.nextInt();
            }
            int[] last = new int[(int) 2e5 + 1];
            Arrays.fill(last, -1);
            long[] dp = new long[n];
            dp[0] = 1;
            last[a[0]] = 0;
            long MOD = (int) 1e9 + 7;
            for (int i = 1; i < n; i++) {
                int l = last[a[i]];
                dp[i] = dp[i - 1];
                if (l != -1 && l != i - 1) {
                    dp[i] = (dp[i] + dp[l]) % MOD;
                }
                last[a[i]] = i;
            }
            out.println(dp[n - 1]);
        }
    }

    static class InputReader {

        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }
    }
}



Measured memory_bytes: 46156
#include <iostream>
#include <vector>
#include <cmath>
#include <iomanip>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)

int main() {
    long long n,ans=0;
    cin>>n;
    vector<long long> len(n),num(5001);
    rep(i,n)cin>>len[i];
    rep(i,n){
        rep(j,len[i]){
            num[j]++;
        }
    }
    int num1,num2,self;
    rep(i,n){
        rep(j,n){
            if(j>i){
                self=2;
                num1=num[len[i]+len[j]-1];
                num2=num[abs(len[i]-len[j])];
                if(min(len[i],len[j])<=abs(len[i]-len[j]))self=1;
                ans+=(num2-num1-self);
                //cout<<num2<<" "<<num1<<endl; //kesu
            }
        }
    }
    
    ans/=3;
    cout<<ans;
	return 0;
}


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

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: 256
from collections import defaultdict 
import sys
import heapq
sys.setrecursionlimit(10**8)

def Find(x):	#xの根を返す
	global table

	if table[x] == x:
		return x
	else:
		table[x] = Find(table[x])	#親の更新(根を直接親にして参照距離を短く)
		return table[x]

def Union(x,y):	#xとyを繋げる
	x = Find(x)	
	y = Find(y)
	
	if x == y:
		return
	
	if rank[x] > rank[y]:
		table[y] = x
	else:
		table[x] = y
		if rank[x] == rank[y]:
			rank[y] += 1

def Check(x,y):
	if Find(x) == Find(y):
		return True
	else:
		return False



#N:頂点数 E:辺数 
N,E = map(int,input().split())

#Union-Find
table = [i for i in range(N)]	#木の親 table[x] == x なら根	
rank  = [1 for i in range(N)]	#木の長さ

# 優先度付きキューの作成
q = []
heapq.heapify(q)

#rout辞書
rout = defaultdict(set)
for i in range(E):
	a,b,w = list(map(int,input().split()))
	rout[a].add(b)
	rout[b].add(a)
	heapq.heappush(q,[w,a,b])

weight = 0
	
while q:
	w,a,b = heapq.heappop(q)
	
	if not Check(a,b):
		weight += w
		Union(a,b)
		
print(weight)


Measured memory_bytes: 42172
#include <iostream>
#include <vector>
using namespace std;
int main(void){
    int n, x, tmp, count=1, sum=0;
    cin>>n>>x;
    for(int i=0; i<n; i++){
        cin>>tmp;
        sum+=tmp;
        if(sum<=x)
            count++;
    }
    cout<<count<<endl;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    long N = sc.nextLong();
    long A = sc.nextLong();
    long B = sc.nextLong();
    long sum = 0;
    
    sum = (N / (A + B)) * A;
    
    if(N %(A+B) > A) {
      sum = sum + A;
    } else {
      sum = sum + N % (A+B);
    }
    System.out.println(sum);
  }
}

Measured memory_bytes: 22996
#include<bits/stdc++.h>
using namespace std;
typedef pair< double, double > Pi;
typedef pair< double, Pi > Pii;

int main() {
  int N, M;
  cin >> N >> M;
  vector< Pii > data(N);
  for(int i = 0; i < N; i++) {
    cin >> data[i].first >> data[i].second.first >> data[i].second.second;
  }
  double best = 0;
  for(int i = 0; i < 1 << N; i++) {
    if(__builtin_popcount(i) != M) continue;
    vector< double > needA, needB, needC;
    for(int j = 0; j < N; j++) {
      if((i >> j) & 1){
        needA.push_back(data[j].first);
        needB.push_back(data[j].second.first);
        needC.push_back(data[j].second.second);
      }
    }
    double ret = 0;
    for(int j = 0; j < M; j++) {
      for(int k = j + 1; k < M; k++) {
        ret += pow(abs(needA[j] - needA[k]), 2) + pow(abs(needB[j] - needB[k]), 2) + pow(abs(needC[j] - needC[k]), 2);
      }
    }
    best = max(best, ret);
  }
  cout << fixed << setprecision(10) << best << endl;
}

Measured memory_bytes: 1324
k = int(input())
a = list(map(int,input().split()))
ansmax = 2
ansmin = 2

for i in reversed(range(k)):
    if ansmax - ansmin < a[i] and (ansmin%a[i])*(ansmax%a[i]) != 0 and (ansmax%a[i]) >= (ansmin%a[i]):
        print(-1)
        exit()
    ansmin = -(-ansmin//a[i])*a[i]
    ansmax = (ansmax//a[i])*a[i] + a[i] - 1
print(str(ansmin) + " " + str(ansmax))


Measured memory_bytes: 85096
#include <bits/stdc++.h>
using namespace std;
int a, b, c, d, e, f, g, h, i;
int main() {
    cin >> a >> b >> e;
    c = 3 * e - a - b;
    h = 2 * e - b;
    f = 2 * a - h;
    i = 3 * e - c - f;
    d = 2 * e - f;
    g = 3 * e - h - i;
    printf("%d %d %d\n%d %d %d\n%d %d %d", a, b, c, d, e, f, g, h, i);
    return 0;
}

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

typedef long long ll;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define each(itr,c) for(__typeof(c.begin()) itr=c.begin(); itr!=c.end(); ++itr)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second

int main()
{
    int n;
    scanf(" %d", &n);
    vector<int> t(n),a(n);
    rep(i,n) scanf(" %d %d", &t[i], &a[i]);

    ll x=t[0], y=a[0];
    for(int i=1; i<n; ++i)
    {
        ll p=x/t[i], q=y/a[i];
        if(x%t[i]!=0) ++p;
        if(y%a[i]!=0) ++q;

        ll k=max(p,q);
        x=k*t[i];
        y=k*a[i];
    }
    cout << x+y << endl;
    return 0;
}


Measured memory_bytes: 256
package main

import "fmt"

func main() {
	var n int
	fmt.Scan(&n)
	a := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&a[i])
	}
	b := make(map[int]int)
	result := true
	for _, v := range a {
		b[v] += 1
		if b[v] >= 2 {
			result = false
			break
		}
	}
	if result {
		fmt.Println("YES")
	} else {
		fmt.Println("NO")
	}
}


Measured memory_bytes: 13952
dict = {"I":1, "V":5, "X":10, "L":50, "C":100, "D":500, "M":1000}

while True:
    try:
        roman = raw_input()
        sum = 0
        for i in range(len(roman)):
            sum += dict[roman[i]]
        sum -= 2*roman.count("IV")
        sum -= 2*roman.count("IX")
        sum -= 20*roman.count("XL")
        sum -= 20*roman.count("XC")
        sum -= 200*roman.count("CD")
        sum -= 200*roman.count("CM")
        print sum
    except:
        break

Measured memory_bytes: 4228
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main() {
	int n,W;
	cin>>n>>W;
	vector<int> w(n),v(n);
	for(int i=0;i<n;i++)cin>>w[i]>>v[i];
	
	vector<vector<ll>>dp(n,vector<ll> (W+1,0));
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<=W;j++)
		{
			dp[i][j]=max(i>0?dp[i-1][j]:0,dp[i][j]);
			if(w[i]<=j)dp[i][j]=max(dp[i][j],1LL*v[i]+ (i>0? dp[i-1][j-w[i]] : 0) );
		}
	}
	cout<<dp[n-1][W]<<endl;
	
}

Measured memory_bytes: 82264
//WrittenBiDP
//grid

#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>

#define MOD 1000000007	

using namespace std;

typedef long long ll;
typedef vector <bool> vb;
typedef vector <ll> vi;
typedef vector <vi> vvi;
typedef vector <vb> vvb;

vvb field;
vvi ans;

int main() {
	//ifstream In("input.txt");
	//ofstream Out("output.txt");

	int h, w;

	cin >> h >> w;

	field.resize(h);
	for (int i = 0; i < h; i++) {
		field[i].resize(w);
	}

	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			char c;
			cin >> c;
			if (c == '#') field[i][j] = false;
			else field[i][j] = true;
		}
	}
	ans.resize(h);
	for (int i = 0; i < h; i++) {
		ans[i].assign(w, 0);
	}

	for (int i = 0; i < w; i++) {
		if (field[0][i]) ans[0][i] = 1;
		else break;
	}
	for (int i = 0; i < h; i++) {
		if (field[i][0]) ans[i][0] = 1;
		else break;
	}

	for (int i = 1; i < h; i++) {
		for (int j = 1; j < w; j++) {
			if (field[i][j]) ans[i][j] = (ans[i - 1][j] + ans[i][j - 1]) % MOD;
		}
	}

	cout << ans[h - 1][w - 1];

	return 0;
}

Measured memory_bytes: 8320
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  char N[4];
  cin>>N;
  if (N[0]==N[1]){
    if(N[1]==N[2]){cout<<"Yes"<<endl;}else{cout<<"No"<<endl;}
  }else if(N[1]==N[2]){
    if(N[2]==N[3]){cout<<"Yes"<<endl;}else{cout<<"No"<<endl;}
  }else{cout<<"No"<<endl;}
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

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

        int N = sc.nextInt();
        long count = 0;

        for (int i = 1; i < N; i++) {
            count += i;
        }

        System.out.println(count);
    }
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
#define io ios_base::sync_with_stdio(0);cin.tie(0);
#define mod 1000000007
#define pi 2*acos(0)
#define ll long long
#define ii pair<int,int>
#define vi vector<int>
using namespace std;



int main()
{

	io;
	
	int n; cin >> n;

	
	
	vector<ll> sum,v;
	ll s = 0;
	for (int i = 0; i < n; i++)
	{
		ll x; cin >> x;
		s =(s+x)%mod;
		v.push_back(x);
		sum.push_back(s);
	}

	ll ans = 0;
	for (int i = 0; i < n-1; i++) {

		ll a = s - sum[i];
		if (a < 0)	a += mod;

		ans += v[i] * a;
		ans %= mod;

		//ans = (ans + (v[i]*(s-sum[i]))%mod ) % mod;

	}

	cout << ans;
	
}



Measured memory_bytes: 6676
#include <iostream>
#include <vector>
#include <cmath>
#include <string>
#include <set>
#include <algorithm>
#include <map>

using namespace std;

int main(){
    int a, b, k;
    cin >> a >> b >> k;
    int cnt = 0;
    int i = 100;
    while(cnt != k){
        if(a % i == 0 && b % i == 0) cnt++;
        i--;
    }
    cout << i + 1 << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define mod 1000000007
using namespace std;
ll ksm(ll a,ll b)
{
	ll mul=1;
	while(b)
	{
		if(b%2==1)mul=(mul*a)%mod;
		a=(a*a)%mod;
		b/=2;
	}
	return mul;
}
ll n,m,f[5005][5005];
string s;
int main()
{
	cin>>n;
	cin>>s;
	m=s.size();
	f[0][0]=1;
	for(int i=0;i<=n;i++)
	{
		for(int j=0;j<=i;j++)
		{
			f[i+1][j+1]+=2*f[i][j];
			f[i+1][j+1]%=mod;
			f[i+1][max(j-1,0)]+=f[i][j];
			f[i+1][max(j-1,0)]%=mod;
		}
	}
	ll ans=ksm(ksm(2,m),mod-2)*f[n][m]%mod;
	cout<<ans;
	return 0;
}
	

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

using ll = long long;
#define FOR(i, m, n) for (int i = (m); i < (n); i++)
#define FORR(i, m, n) for (int i = (m); i >= (n); i--)
#define REP(i, n) FOR(i, 0, (n))
#define REPR(i, n) FORR(i, (n) - 1, 0)
#define REP1(i, n) FOR(i, 1, (n) + 1)
#define ALL(c) (c).begin(), (c).end()
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;}
const int MOD = 1000000007;
const int INF = 1000000001;

ll gcd(ll m, ll n) {
    return n != 0 ? gcd(n, m % n) : m;
}

vector<ll> divisors(ll n) {
    vector<ll> v;
    for (ll i = 1; i * i <= n; i++) {
        if (n % i == 0) {
            v.push_back(i);
            if (i * i != n) {
                v.push_back(n / i);
            }
        }
    }
    return v;
}

map<ll, ll> prime_factorization(ll n) {
    map<ll, ll> m;
    ll x = n;
    ll d = 2;
    while (x > 1 && d * d <= n) {
        if (x % d == 0) {
            m[d]++;
            x /= d;
        } else {
            d++;
        }
    }
    if (x != 1) m[x]++;
    return m;
}

int main() {
    ll a, b;
    cin >> a >> b;
    ll g = gcd(a, b);
    map<ll, ll> f = prime_factorization(g);
    cout << f.size() + 1 << endl;
}


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

void solve () {
    int n, m;
    cin >> n >> m;
    vector<bool> ac(n);
    vector<int> wa(n);
    for (int i = 0; i < m; i++) {
        int x; string s;
        cin >> x >> s;
        x--;
        if(s == "WA" && ac[x] == 0) {
            wa[x]++;
        }
        if (s == "AC") {
            ac[x] = 1;
        }
    }
    int a = 0, b = 0;
    for (int i = 0; i < n; i++) {
        if (ac[i]) {
            a++;
            b+= wa[i];
        }
    }
    cout << a << " " << b;

}

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


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

// {U}{INT,LONG,LLONG}_{MAX,MIN}
#define INF         INT_MAX/3
#define LLINF       LLONG_MAX/3
#define MOD         (1000000007LL)
#define MODA(a, b)  a=((a)+(b))%MOD
#define MODP(a, b)  a=((a)*(b))%MOD
#define inc(i, l, r)   for(int i=(l);i<(r);i++)
#define dec(i, l, r)   for(int i=(r)-1;i>=(l);i--)
#define pb          push_back
#define se          second
#define fi          first
#define mset(a, b)  memset(a, b, sizeof(a))

using LL  = long long;
using G   = vector<vector<int>>;

int di[] = {0, -1, 0, 1};
int dj[] = {1, 0, -1, 0};
// }}}

int main() {
    cin.tie(0);ios::sync_with_stdio(false);
    int n;cin >> n;
    vector<int> a(n);
    for(int i=0;i<n;i++){
        cin >> a[i];
    }
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            if(i == j) continue;
            int d = abs(a[i]-a[j]);
            if(d%(n-1) == 0){
                cout << a[i] << " " << a[j] << endl;
                return 0;
            }
        }
    }
    return 0;
}



Measured memory_bytes: 3228
import math
time_list=[]

for _ in range(5):
    time_list.append(int(input()))
# print(1, time_list)

time_list2=[]
for x in time_list:
    m = x % 10
    if m!=0:
        time_list2.append(x+(10-m))
    else:
        time_list2.append(x)
# print("2", time_list2)

mod_list = []
for x in time_list:
    m = x % 10
    if m!=0:
        mod_list.append(m)
    else:
        mod_list.append(10)
min_ = min(mod_list)
# print(mod_list)



print(sum(time_list2)-(10-min_))

Measured memory_bytes: 3064
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
int n=0;//???? 
long long tme=0;//???? 
struct build{
    long long T1,T2;
}z[200010];
bool cmp(build a,build b){
    return a.T2<b.T2;
}
struct dui{
    int a[150010];
    int c;
    void makedui(int i){
        int j;
        while(i/2>=1){
            j=i/2;
            if(a[j]<a[i]){
                c=a[j];
                a[j]=a[i];
                a[i]=c;
                i=j;
            }
            else break;
        }
    }
    void redui(int i){
        int j;
        while(i*2<=n){
            j=i*2;
            if(a[j]<a[j+1]&&j+1<=n)j++;
            if(a[j]>a[i]){
                c=a[j];
                a[j]=a[i];
                a[i]=c;
                i=j;
            }
            else break;
        }
    }
}q;
void yxj(int p)//??????? 
{
    if(q.a[1]>z[p].T1){
        tme-=q.a[1];
        tme+=z[p].T1;
        q.a[1]=z[p].T1;
        q.redui(1);
    }
}
int main(){
    int k;
    scanf("%d",&k);
    for(int i=1;i<=k;i++){
        scanf("%lld%lld",&z[i].T1,&z[i].T2);
    }
    sort(z+1,z+1+k,cmp);
    for(int i=1;i<=k;i++){
        if(tme+z[i].T1<=z[i].T2)//????lalala,?????...????? 
        {
            q.a[++n]=z[i].T1;
            tme+=z[i].T1;
            q.makedui(n);
        }
        else yxj(i);
    }
    if(n==k)puts("Yes");
    else puts("No");
    return 0;
}

Measured memory_bytes: 3968
#include <bits/stdc++.h>
using namespace std;
# define fastio std::ios_base::sync_with_stdio(false)
# define ll long long int
# define endl "\n"

int main() {
    fastio;
    ll n;
  cin>>n;
  if(n==1)
    cout<<"Hello World"<<endl;
  else
  {
    ll x,y;
    cin>>x>>y;
    cout<<x+y<<endl;
  }
    
	return 0;
}


Measured memory_bytes: 256
A = list(list(map(int, input().split())) for _ in range(3))
b = [int(input()) for _ in range(int(input()))]

for a in A:
    for i, x in enumerate(a):
        if x in b:
            a[i] = "o"

# 横
for a in A:
    if len(set(a)) == 1:
        print("Yes")
        exit()

# 縦
T = []
for i in range(3):
    temp = []
    for j in range(3):
        temp.append(A[j][i])
    T.append(temp)

for t in T:
    if len(set(t)) == 1:
        print("Yes")
        exit()

# 斜
if A[0][0] == A[1][1] == A[2][2] or A[0][2] == A[1][1] == A[2][0]:
    print("Yes")
    exit()

print("No")

Measured memory_bytes: 3064
import java.awt.geom.*;
import java.util.*;

public class Main {
	ArrayList<ArrayList<Integer>> pass;
	boolean [] used;
	int [] match;
	
	private int gcd(int a, int b){
		if(b == 0){
			return a;
		}
		else{
			return gcd(b, a%b);
		}
	}
	
	private boolean dfs(int v){
		used[v] = true;
		for(int i =0; i < pass.get(v).size(); i++){
			int u = pass.get(v).get(i);
			int w = match[u];
			if(w < 0 || !used[w] && dfs(w)){
				match[v] = u;
				match[u] = v;
				return true;
			}
		}
		return false;
	}

	private void doit() {
		Scanner sc = new Scanner(System.in);
		while(true){
			int m = sc.nextInt();
			int n = sc.nextInt();
			if(m ==0 && n == 0) break;
			int [] mdata = new int[m];
			int [] ndata = new int[n];
			used = new boolean[m + n];
			match = new int[m + n];
			
			for(int i =0; i < m; i++){
				mdata[i] = sc.nextInt();
			}
			for(int i =0; i < n; i++){
				ndata[i] = sc.nextInt();
			}
			pass = new ArrayList<ArrayList<Integer>>();
			for(int i =0; i  < m + n; i++){
				pass.add(new ArrayList<Integer>());
			}
			for(int i=0; i < m; i++){
				for(int j =0; j < n; j++){
					int  result = gcd(mdata[i], ndata[j]);
					if(result > 1){
						pass.get(i).add(m + j);
						pass.get(j + m).add(i);
					}
				}
			}
			
			int ans = 0;
			Arrays.fill(match, -1);
			for(int i=0; i < n + m; i++){
				if(match[i] < 0){
					Arrays.fill(used, false);
					if(dfs(i)){
						ans++;
					}
				}
			}
			//System.out.print("ANS= ");
			System.out.println(ans);
			
			//DEBUG
//			for(int i =0; i < m; i++){
//				ArrayList<Integer> al = pass.get(i);
//				for(int j=0; j < al.size(); j++){
//					System.out.print(al.get(j));
//				}
//				System.out.println();
//			}
//			for(int i =0; i < match.length; i++){
//				System.out.println(match[i]);
//			}
			
		}
		
	}

	public static void main(String[] args) {
		Main obj = new Main();
		obj.doit();
	}
}

Measured memory_bytes: 20000
#include <bits/stdc++.h>
#define rep(i,n)for(long long i=0;i<(long long)(n);++i)
#define all(a) a.begin(), a.end()
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
 
const ll MOD=1e9+7;
const ll INF=1e18;
const int MAX=510000;
const double pi=acos(-1);
int dx[8] = {1,0,-1,0,1,1,-1,-1};
int dy[8] = {0,1,0,-1,-1,1,1,-1};
// int d[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};
long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false); 
  
  int n;
  ll k;
  cin >> n >> k;
  vector<ll>a(n);
  rep(i,n) cin >> a[i];
  ll ng = 0,  ok = 1e9;
  while(abs(ng-ok)>1){
    int cnt = 0;
    ll m=(ng+ok)/2;
    rep(i,n){
      if(a[i]<=m)continue;
      if(a[i]%m==0)cnt+=a[i]/m-1;
      else cnt+=a[i]/m;
    }
    if(cnt>k){
      ng=m;
    }
    else ok = m;
  }
  cout << ok << endl;
      
  
  return 0;
}


Measured memory_bytes: 4764
#include <cstdio>
#include <algorithm>
#include <limits>
#define rep(i,a) for(int i=0;i<(a);++i)

constexpr int INF = std::numeric_limits<int>::max() >> 2;

int H, W;
int d[10][10];

int main()
{
	scanf("%d%d", &H, &W);
	
	std::fill((int*)d, (int*)(d + 10), INF);

	rep(i, 10)
		d[i][i] = 0;
	
	rep(i, 10) rep(j, 10)
	{
		int c;
		scanf("%d", &c);

		d[i][j] = c;
	}

	rep(k, 10) rep(i, 10) rep(j, 10)
		d[i][j] = std::min(d[i][j], d[i][k] + d[k][j]);

	int ans = 0;
	rep(i, H) rep(j, W)
	{
		int A;
		scanf("%d", &A);

		if (A != -1)
			ans += d[A][1];
	}

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

	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
 
#define rep(i,n) for(long long int (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(long long int i=(a);i<(b);i++)
#define rrrep(i,a,b) for(long long int i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define pb(q) push_back(q)
#define Size(n) (n).size()
#define Cout(x) cout<<(x)<<endl
 
typedef long long ll;
 
using namespace std;
 
const int INF = 1e9,MOD = 1e9 + 7,ohara = 1e6;
const ll LINF = 1e18;
long long int n,cnt=0,ans=0,a,b,c,d,cmp,cmpp,m,h,w,x,y,sum=0,pos,prime_cnt[ohara],f[ohara],fr[ohara];
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
string alph("abcdefghijklmnopqrstuvwxyz"),s;
bool fl;
struct edge{int to,cost;};
vector<pair<ll,ll>> prime;
//-------------------------↓↓↓↓↓↓------------------------
 
void Factorization(ll nn){
       for(ll i=2;nn!=1;i++){
           if(nn%i)continue;
           prime.push_back({i,0});
           while(nn%i==0){
             prime.back().second++;
             nn/=i;
           }
      }
}
 
ll mod_pow(ll xx,ll nn,ll mod){
  ll ret=1;
  while(nn>0){
    if(nn&1)ret=ret*xx%mod;
    xx=xx*xx%mod;
    nn>>=1;
  }
  return ret;
}
 
ll ncr(ll nn,ll r){
  if(nn<r)return 0;
  return f[nn]*fr[r]%MOD*fr[nn-r]%MOD;
}
 
void init(ll nn){
  f[0]=1;
  rrep(i,1,nn+3){
    f[i]=f[i-1]*i%MOD;
  }
  fr[nn+2]=mod_pow(f[nn+2],MOD-2,MOD);
  rrrep(i,nn+1,0){
    fr[i]=fr[i+1]*(i+1)%MOD;
  }
}
 
int main(void){
  
       cin.tie(0);
    ios::sync_with_stdio(false);
      
      cin>>n>>m;
      init(n+sqrt(m)+3);
      Factorization(m);
      ans=1;
      for(auto v : prime){
        (ans*=ncr(v.second+n-1,v.second))%=MOD;
      }
      Cout(ans%MOD);
    
       
return 0;
}

Measured memory_bytes: 5376
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vi;
typedef pair<ll,ll> pi;
typedef vector<pi> vpi;
typedef double dl;
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define MOD 1e9+7
#define lb lower_bound
#define ub upper_bound
#define dst distance
#define INF 1000000000
#define ALL(x) x.begin(), x.end()
#define SZ(x) (int)x.size()
#define MAXN 300100

ll N;
deque<ll> D;
vi res;
ll a;
vi B;

int main(){
	cin>>N;
	for (ll i=0;i<N;++i){cin>>a;D.pb(a);B.pb(a);}
	while (SZ(D) && D[0] <= 0){
		res.pb(1);
		D.pop_front();
	}
	if (SZ(D) == 0){
		int t = max_element(ALL(B)) - B.begin();
		cout<<*max_element(ALL(B))<<'\n';
		cout<<N-1<<'\n';
		for (int i=0;i<t;++i)cout<<"1\n";
		for (int i=t+1;i<N;++i)cout<<N-i+1<<'\n';
		return 0;
	}
	ll oddsum = 0;
	ll evensum = 0;

	for (ll i=0;i<SZ(D);++i){
		if(D[i]>0){
			if (i%2==1)oddsum+=D[i];
			else evensum+=D[i];
		}
	}
	// cout<<oddsum<<' '<<evensum<<'\n';
	cout<<max({oddsum,evensum})<<'\n';

	int par = SZ(D)%2;
	if (oddsum > evensum)par = 1-par;

	while (SZ(D) && (SZ(D)%2 != par || D[0] < 0)){
		D.pop_front();
		res.pb(1);
	}

	ll t = D[0];
	D.pop_front();
	while (SZ(D) > 1){
		if (D[1] > 0){
			res.pb(2);
			t += D[1];
			// cout<<"Adding "<<D[1]<<' '<<t<<'\n';
			D.pop_front();
			D.pop_front();
		}else{
			if (SZ(D) == 2){
				res.pb(3);
				res.pb(2);
				D.clear();
				break;
			}
			res.pb(3);
			D.pop_front();
			D.pop_front();
		}
	}
	if (SZ(D))res.pb(2);
	cout<<SZ(res)<<'\n';
	for (auto i:res)cout<<i<<'\n';

	assert(t==max(oddsum,evensum));
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
int n,a[100010],b[100010];
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);
		if(a[i]<=n) b[a[i]]++;
	}
	int all=0;
	for(int i=1;i<=n;i++)
		if(b[i]!=0)
		{
			if(b[i]<i) continue;
			else all+=i; 
		}
	printf("%d",n-all);
	return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#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 INF 2e9
#define MOD 1000000007
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
using P = pair<ll,ll>;

int main()
{
  int N;
  cin >> N;
  vector<P> A(N);
  vector<P> B(N);
  REP(i,N){
    cin >> A[i].first >> A[i].second;
    B[i].first=A[i].second;
    B[i].second=A[i].first;
  }
  sort(ALL(A));
  sort(ALL(B));
  
  if(N%2==0){
    cout << (B[N/2].first+B[N/2-1].first)-(A[N/2].first+A[N/2-1].first)+1 << endl;
  }else{
    cout << B[N/2].first-A[N/2].first+1 << endl;
  }
}

Measured memory_bytes: 9532
import sys
input=sys.stdin.readline
def fun(n,w):
 cos=[0]*(w+1)
 for i in range(n):
  w1,v1=map(int,input().split())
  for j in range(w,w1-1,-1):
   f=cos[j-w1]+v1
   if(cos[j]<f):
    cos[j]=f
 print(cos[-1])
n,w=map(int,input().split())
fun(n,w)
  


Measured memory_bytes: 7668
s = int(input())
m = 1000000007

if s >= 3:
    dp = [0] * (s+1)
    dp[3] = 1

    for i in range(4, s+1):
        dp[i] = (sum(dp[:i-3+1]) + 1)%m

    print(dp[s]%m)
else:
    print(0)

Measured memory_bytes: 9184
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<string>
#include<cmath>
#include<utility>
#define rep(i,rept) for (ll i = 0; i < rept; i++)
typedef long long ll;
int main() {
	std::string s;
	bool ac = true;
	int count_c = 0;
	int memo_place = 0;
	std::cin >> s;
	if (s[0] != 'A') {
		ac = false;
	}
	rep(i, s.length()) {
		if (s[i] == 'C') {
			count_c++;
			memo_place = i;
		}
	}
	if (count_c > 1 || count_c == 0) {
		ac = false;
	}
	if (memo_place<2 || memo_place > s.length() - 2) {
		ac = false;
	}
	for (int i = 1; i < s.length(); i++) {
		if (s[i] >= 'A'&&s[i] <= 'Z') {
			if (s[i] != 'C') {
				ac = false;
			}
		}
	}
	if (ac == true) {
		std::cout << "AC" << std::endl;
	}
	else {
		std::cout << "WA" << std::endl;
	}
	return 0;
}

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

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

using namespace std;

int main()
{
	ll a, b, c, x, y;
	cin>>a>>b>>c>>x>>y;
	if (a+b<=c*2){
		cout << a*x+b*y << endl;
	}else{
		ll ans=min(x,y)*c*2;
		if(x>y){
			if (2*c<a){
				ans+=2*c*(max(x,y)-min(x,y));
			}else{
				ans+=a*(max(x,y)-min(x,y));
			}
		}else{
			if (2*c<b){
				ans+=2*c*(max(x,y)-min(x,y));
			}else{
				ans+=b*(max(x,y)-min(x,y));
			}
		}
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<cmath>
#include<string>
#include<algorithm>
#include<map>
#include<utility>
#include<cstdio>
#include<bits/stdc++.h>

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

typedef pair<ll,ll> Pair;

int main(){

ll X,Y;
bool flg = false;
cin >> X >> Y;

for(ll i = 0;i <= X;++i){

    if((2 * i) +( 4 * ( X - i ) ) == Y) flg = true;

}

cout << (flg ? "Yes" : "No") << endl;

return 0;

}


Measured memory_bytes: 3628
#include <iostream>
#include <iomanip>
#include <vector>
#include <utility>
#include <map>
#include <algorithm>
#include <queue>
#include <cmath>
#include <numeric>
#include <set>

using namespace std;
struct aaa{aaa(){cin.tie(nullptr); ios::sync_with_stdio(false); cout<<fixed<<setprecision(20);};}aaa;
template <class T>ostream &operator<<(ostream &o,const vector<T>&v){o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}
#define debug(v) {cerr<<"\033[1;36m[debug]\033[m "<<#v<<" : "<<v<<endl;}

using int64 = long long;

const int MOD = 1000000007;
class mint {
    using int64 = long long;
private:
    int64 x;
public:
    mint(const int64 x1=0) { x = x1%MOD; };

    mint& operator++(int n) { x+=1; return *this; };
    mint& operator--(int n) { x-=1; return *this; };
    mint& operator=(int64 n) { x=n%MOD; return *this; };
    mint& operator--() {x-=1; return *this; };
    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) { return (*this) *= a.inv();}
    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 operator/(const mint a) const { mint res(*this); return res/=a; }
    mint inv() const { return pow(MOD-2);}
    friend ostream& operator<<(ostream &os, const mint a) noexcept { return os << a.x; }
    constexpr bool operator == (const mint& r) const noexcept { return this->x == r.x; }
    constexpr bool operator != (const mint& r) const noexcept { return this->x != r.x; }
    mint pow(long long t) const {
        if (!t) return mint(1);
        mint a = pow(t>>1);
        a*=a;
        if(t&1) a*= *this;
        return a;
    }
};

struct combination {
    vector<mint> fact, ifact;

    // コンストラクタ
    combination(int n):fact(n+1),ifact(n+1) {
        fact[0] = mint(1);
        for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*mint(i);
        ifact[n] = fact[n].inv();
        for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*mint(i);
    }

    mint nCr(int n, int r) {
        if (r < 0 || r > n) return 1;
        return fact[n]*ifact[r]*ifact[n-r];
    }
    mint nPr(int n, int r) {
        if (r < 0 || r > n) return 0;
        return fact[n]*ifact[n-r];
    }
} comb(100005);

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

    if (s<3) {
        cout << 0 << endl;
        return 0;
    }

    mint ans = 1;
    for (int i=2; i*3<=s; i++) {
        ans += comb.nCr(s - i*3 + i - 1, s-i*3);
    }
    cout << ans << endl;
}

Measured memory_bytes: 4168
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
 
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
 
using namespace std;
using namespace __gnu_pbds;
 
typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;
 
typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;
 
typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;
 
template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;
 
#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)
 
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
 
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
const int MOD = 1000000007;
const ll INF = 1e18;
const int MX = 100001; //check the limits, dummy
 
int main() {
	ios_base::sync_with_stdio(0); cin.tie(0);    
	
    int N; cin >> N;

    F0R(i, N) {
        int cur; cin >> cur;
        if (cur % 2 == 0 && (cur % 3 && cur % 5)) {
            cout << "DENIED" << endl; return 0;
        }
    }
    cout << "APPROVED" << endl;
	
	return 0;
}
 
// read the question correctly (ll vs int)
// template by bqi343



Measured memory_bytes: 256
#include <stdio.h>

int main(void){
   
    int a,b,c;
    
    scanf( "%d %d %d",&a,&b,&c );
    
    if( c >= a && c <= b){
        printf("Yes");
    }
    else printf("No");
    
    
    
    
    
    return 0;
}

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

using namespace std;
const long long MOD=1e9+7;

int main(){
  long long n, t[100009], a[100009], check[100009];
  cin >> n;
  for(int i=0;i<n;i++)cin >> t[i];
  for(int i=0;i<n;i++)cin >> a[i];
  if(n==1 && t[0] != a[0]){
    cout << 0 << endl;
    return 0;
  }
  memset(check, -1, sizeof(check));
  check[0] = t[0];
  check[n-1] = a[n-1];
  for(int i=1;i<n;i++){
    if(t[i]!=t[i-1]){
      check[i]=t[i];
      if(check[i]>a[i]){
        cout << 0 << endl;
        return 0;
      }
    }
  }
  for(int i=n-2;i>=0;i--){
    if(a[i]!=a[i+1]){
      check[i]=a[i];
      if(check[i]>t[i]){
        cout << 0 << endl;
        return 0;
      }
    }
  }
  long long ans=1LL;
  for(int i=0;i<n;i++){
    if(check[i]==-1){
      ans = (ans * min(t[i] , a[i]))%MOD;
    }
  }
  cout << ans << endl;
}



Measured memory_bytes: 5908
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner ob=new Scanner(System.in);
        int n=ob.nextInt();
        int k=ob.nextInt();
        int a[]=new int[n];
        for(int i=0;i<n;i++){
            a[i]=ob.nextInt();
        }
        int min=0;
        int arr[]=new int[n];
        arr[0]=0;
        arr[1]=Math.abs(a[1]-a[0]);
        for(int i=2;i<a.length;i++){
            min=Integer.MAX_VALUE;
            for(int j=1;j<=k;j++){
                if(i-j>=0){
                    min=Math.min(arr[i-j]+Math.abs(a[i]-a[i-j]),min);
                    //System.out.println(min+" "+i+" "+j);
                }
            }
            arr[i]=min;
        }
        System.out.println(arr[n-1]);
        ob.close();
    }
}

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

int main(){
    string S;
    int a = 0;
    int b = 0;
    cin >> S;
    for(int i = 0;i < S.size();i++){
        if(S.at(i) == '0') a++;
        if(S.at(i) == '1') b++;
    }
    cout << 2 * min(a,b) << endl;
}

Measured memory_bytes: 512
/*
___ is a raging sadist.
*/

//Destroy all WA at test 2

#include <bits/stdc++.h>
#define fastio()                  \
    ios_base::sync_with_stdio(0); \
    cin.tie(0);                   \
    cout.tie(0)
#define pb push_back
#define show(x) cout << (#x) << " : " << x << endl;
#define ll long long
#define ld long double
#define pow power
#define mp make_pair
#define ff first
#define ss second
#define pii pair<ll, ll>
#define sq(x) ((x) * (x))
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define For(i,a,b) for(int (i)=(a);(i) < (b); ++(i))
#define endl "\n"
#define PI 3.14159265
const ll MOD = 1000 * 1000 * 1000 + 7;
const ll MOD1 = 998244353;
const ll INF     = 1ll*1000*1000*1000*1000*1000*1000 + 7; 
using namespace std;

ll power(ll x, ll y) 
{ 
   ll res = 1;      
  
   
    while (y > 0) 
    { 
       
        if (y & 1) 
            res = (long long)(res*x); 
  

        y = y>>1; 

        if (x<=100000000)
        x = (long long)(x*x);

        //cout<<x<<'\n'; 
    } 
    return res; 
} 






int main()
{

#ifndef ONLINE_JUDGE    
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
#endif

fastio();

ll n,k;
cin>>n>>k;

ll a[n];
For(i,0,n)
cin>>a[i];

sort(a,a+n);

ll sum=0;

for(int i=0;i<k;i++)
sum+=a[i];

cout<<sum;

return 0;
}

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

namespace ARC068_D___Card_Eater
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = int.Parse(Console.ReadLine());
            var cards = new Dictionary<int, int>();
            var A = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
            foreach (int c in A)
            {
                if (!cards.ContainsKey(c)) cards.Add(c, 1); else cards[c]++;
            }

            int surplus = cards.Values.Sum(n => n - 1);
            if (surplus % 2 == 1) surplus++;
            Console.WriteLine(N - surplus);
        }
    }
}


Measured memory_bytes: 22240
#include <iostream>
#include <algorithm>

using namespace std;

typedef long long ll;

int main()
{
    ll n;
    ll a,b = 1,c;
    cin >> n;

    for (int i = 0; i < n; i ++ )
    {
        cin >> a;
        c = __gcd(a,b);
        b = a/c*b;
    }
    cout << b << endl;
    return 0;
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#pragma warning(disable:4996)
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <functional>
#include <stack>
#include <queue>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <list>
#include <set>
#include <ctime>
using namespace std;
typedef long long ll;

const int INF = 100000000;
const int MAX_N = 100000;


int main(int argc, char *args[]) {
	int N;
	int H[100000];
	cin >> N;
	for (int i = 0; i < N; i++) {
		cin >> H[i];
	}
	int ans = 0;
	int now = 0;

	while(true) {
		int counter = 0;
		for (now; now < N - 1; now++) {
			if (H[now] >= H[now + 1]) {
				counter++;
			}
			else {
				break;
			}
		}
		if (ans < counter) {
			ans = counter;
		}
		if (now == N - 1) {
			break;
		}
		now++;
	}
	cout << ans << endl;
}

Measured memory_bytes: 640
//
//  ROIGold.cpp
//  Main calisma
//
//  Created by Rakhman on 05/02/2019.
//  Copyright © 2019 Rakhman. All rights reserved.
//

#include <cstring>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <queue>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cassert>
#include <iterator>

#define ios ios_base::sync_with_stdio(0), cout.tie(0), cin.tie(0);
#define S second
#define F first
#define pb push_back
#define nl '\n'
#define NL cout << '\n';
#define EX exit(0)
#define all(s) s.begin(), s.end()
#define no_answer return cout << "NO", 0;
#define FOR(i, start, finish, k) for(int i = start; i <= finish; i += k)

const int MXN = 2e5 + 200;
const long long MNN = 3e3 + 200;
const long long MOD = 1e9 + 7;
const long long INF = 1e13;
const int OO = 1e9 + 500;

typedef long long llong;
typedef unsigned long long ullong;

using namespace std;

int n, dp[MXN];
vector<int> q[MXN];
vector<int> v[MXN];
int dm = 0, pos = 0;

void dfs(int x, int p, int d){
    if(d > dm) dm = d, pos = x;
    for(int i = 0; i < q[x].size(); i++){
        if(q[x][i] != p){
            dfs(q[x][i], x, d + 1);
        }
    }
}

int main() {
    cin >> n;
    for(int i = 1; i < n; i++){
        int u, v;
        cin >> u >> v;
        q[u].pb(v);
        q[v].pb(u);
    }
    dfs(1, 0, 0);
    dfs(pos, 0, 0);
    dm++;
    dp[0] = 0;
    dp[1] = 1;
    dp[2] = 0;
    for(int i = 3; i <= dm; i++){
        dp[i] = !(dp[i - 2] & dp[i - 1]);
    }
    cout << (dp[dm] == 1 ? "First" : "Second");
}


Measured memory_bytes: 29184
// clang-format off
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define stoi stoll
using pii = pair<int,int>;
using vi = vector<int>;
using vvi = vector<vi>;
#define all(c) begin(c), end(c)
#define rall(c) rbegin(c), rend(c)
#define fore(x, c) for(auto &&x : c)
#define rep(i, a, n) for(int i = a, i##len = (int)(n); i < i##len; ++i)
#define rrep(i, a, n) for(int i = (int)(n - 1); i >= a; --i)
#define sz(c) ((int)c.size())
#define contains(c, x) (c.find(x) != end(c))
#define inseg(l, x, r) ((l) <= (x) && (x) < (r))
#define dump(...)
#define pb push_back
#define eb emplace_back
#define _ 0
const signed INF_ = 1001001001; const long long INF = 1001001001001001001LL;
const int DX[9] = {0,1,0,-1,1,1,-1,-1,0}, DY[9] = {-1,0,1,0,-1,1,1,-1,0};
template<class T> ostream& operator<<(ostream &os, const vector<T> &v) {
  for (auto i = begin(v); i != end(v); i++) os<<*i<<(i==end(v)-1?"":" ");return os;}
template<class T> istream& operator>>(istream &is, vector<T> &v) {
  for (auto i = begin(v); i != end(v); i++) is>>*i;return is;}
template<class T,class U> istream& operator>>(istream &is, pair<T,U> &p) {
  is>>p.first>>p.second;return is;}
template<class T, class U> bool chmax(T &a, const U &b){return a<b?a=b,1:0;}
template<class T, class U> bool chmin(T &a, const U &b){return a>b?a=b,1:0;}
template <class T> void psum(T& c) {partial_sum(begin(c), end(c), begin(c));}
template<class T> using heap = priority_queue<T, deque<T>, greater<T>>;
struct before_main_function {
  before_main_function() {
      cin.tie(nullptr); ios::sync_with_stdio(0);
      cout << setprecision(15) << fixed;
  }
} before_main_function;
// clang-format on
//------------------8<------------------------------------8<--------------------

vi divisors(int n) {
  vi ret;
  rep(i, 1, n + 1) {
    if (i * i > n) break;
    if (n % i == 0) {
      if (i >= 2) ret.pb(i);
      if (i != n / i && n / i >= 2) ret.pb(n / i);
    }
  }
  return ret;
}
int f(int n, int k) {
  if (n % k == 0) return f(n / k, k);
  return n % k;
}
signed main() {
  int N;
  cin >> N;
  vi a = divisors(N);
  vi b = divisors(N - 1);

  int ans = sz(b);
  for (int x : a) {
    if (f(N, x) == 1) {
      ans++;
    }
  }
  cout << ans << endl;
  return (0 ^ _ ^ 0);
}



Measured memory_bytes: 384
#include <iostream>
#define INF 1e9

using namespace std;

int abs(int a) {
    if(a < 0) {
        return -a;
    }
    return a;
}

void chmin(int& a, int b) {
    if(a > b) {
        a = b;
    }
    return;
}

int main() {
    int N, K;
    cin >> N;
    cin >> K;
    int h[N];
    for(int i = 0; i< N; i++) cin >> h[i];
    int dp[N];
    dp[0] = 0;
    for(int i = 1; i < N; i++) dp[i] = INF;

    for(int i = 1; i < N; i++) {
        chmin(dp[i], dp[i-1] + abs(h[i] - h[i-1]));
        if(i > 1) {
            for(int j = 2; j <= K; j++) {
                if( (i-j) >= 0 )  {
                    chmin(dp[i], dp[i-j] + abs(h[i] - h[i-j]));
                }
            }
        }
    }

    cout << dp[N-1] << endl;

    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <cmath>

using namespace std;

const int MAXN = 100000 + 100;
const int MAXM = 1000000 + 1000;
const int INF = 0x3f3f3f3f;
const int MAXL = 100 + 10;

namespace myDinic
{
	struct Edge
	{
		int next, to, w;
	}
	e[MAXM];
	int p[MAXN], head[MAXN], l = 2;

	void addE(int a, int b, int c)
	{
		e[l] = (Edge){p[a], b, c};
		p[a] = l++;
	}

	void ins2(int a, int b, int c)
	{
		addE(a, b, c);
		addE(b, a, 0);
	}

	int S, T, N;
	int dis[MAXN];
	queue<int> q;
	int flow = 0;

	bool bfs()
	{
		memset(dis, 0, (N + 2) * sizeof(dis[0]));
		dis[S] = 1, q.push(S);
		while(!q.empty())
		{
			int x = q.front();
			q.pop();
			for(int i = p[x]; i; i = e[i].next)
				if(e[i].w > 0 && !dis[e[i].to])
				{
					int y = e[i].to;
					dis[y] = dis[x] + 1, q.push(y);
				}
		}
		return dis[T];
	}

	int dfs(int x, int s)
	{
		if(x == T)
			return s;
		int ret = 0;
		for(int &i = head[x]; i; i = e[i].next)
			if(e[i].w > 0 && dis[x] + 1 == dis[e[i].to])
			{
				int t = dfs(e[i].to, min(e[i].w, s));
				e[i].w -= t, e[i ^ 1].w += t;
				s -= t, ret += t;
				if(s <= 0)
					break;
			}
		return ret;
	}

	int dinic()
	{
		flow = 0;
		while(bfs())
		{
			memcpy(head, p, (N + 2) * sizeof(p[0]));
			flow += dfs(S, INF);
		}
		return flow;
	}
}

const int dx[] = {-1, 1, 0, 0};
const int dy[] = {0, 0, -1, 1};

int n, m;
char s[MAXL][MAXL];

int get_id(int x, int y, int t)
{
	return 2 * ((x - 1) * m + (y - 1)) + t + 1;
}

void work()
{
	using namespace myDinic;

	for(int i = 1; i <= n; i++)
		for(int j = 1; j <= m; j++)
		{
			if(s[i][j] == 'o')
				ins2(get_id(i, j, 0), get_id(i, j, 1), 1);
			else if(s[i][j] == 'S')
				S = get_id(i, j, 1);
			else if(s[i][j] == 'T')
				T = get_id(i, j, 0);
		}
	N = get_id(n, m, 1);
	for(int i = 1; i <= n; i++)
		for(int j = 1; j <= m; j++)
			ins2(get_id(i, j, 1), N + i, INF), ins2(N + i, get_id(i, j, 0), INF);
	N += n;
	for(int i = 1; i <= n; i++)
		for(int j = 1; j <= m; j++)
			ins2(get_id(i, j, 1), N + j, INF), ins2(N + j, get_id(i, j, 0), INF);
	N += m;

	// cerr << N << endl;
	// cerr << S << ' ' << T << endl;
	// for(int i = 1; i <= N; i++)
	// {
	// 	cerr << i << " : ";
	// 	for(int j = p[i]; j; j = e[j].next)
	// 		cerr << e[j].to << ' ' << e[j].w << " / ";
	// 	cerr << endl;
	// }

	int ans = dinic();
	if(ans >= INF)
		ans = -1;

	cout << ans << endl;
}

int main()
{
	ios::sync_with_stdio(false);
	// freopen("1.in", "r", stdin);
	// freopen("1.out", "w", stdout);

	cin >> n >> m;
	for(int i = 1; i <= n; i++)
		cin >> (s[i] + 1);
	work();

	return 0;
}


Measured memory_bytes: 3584