akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<vector>
#include<map>
#include<queue>
#include<string>
#include<sstream>
#include<cmath>
#include<numeric>
#include<random>
using namespace std;

class Dice{
  public:
    vector<int> n;
    int top;
    int sum = 0;
    Dice(){
      n.resize(6);
      for(int i=0; i<6; i++) n[i] = i+1;
      top = 0;
    }
    void roll(char c){
      int tmp = n[0];
      if( c == 'E' ){
        n[0] = n[3];
        n[3] = n[5];
        n[5] = n[2];
        n[2] = tmp;
      }else if( c == 'W' ){
        n[0] = n[2];
        n[2] = n[5];
        n[5] = n[3];
        n[3] = tmp;
      }else if( c == 'N' ){
        n[0] = n[1];
        n[1] = n[5];
        n[5] = n[4];
        n[4] = tmp;
      }else if( c == 'S' ){
        n[0] = n[4];
        n[4] = n[5];
        n[5] = n[1];
        n[1] = tmp;
      }else if( c == 'R' ){
        tmp = n[4];
        n[4] = n[3];
        n[3] = n[1];
        n[1] = n[2];
        n[2] = tmp;
      }else if( c == 'L' ){
        tmp = n[4];
        n[4] = n[2];
        n[2] = n[1];
        n[1] = n[3];
        n[3] = tmp;
      }
      sum += n[0];
    }
    void input(){
      for(int i=0; i<6; i++) cin >> n[i];
    }

    void output_top(){
      cout << n[top] << endl;
    }
    void output_sum(){
      cout << sum << endl;
    }
};

bool diff_check(Dice d, Dice d2){
  random_device rnd;
  string con = "NSEW";

  int cnt = 0;
  while(true){
    if( cnt >= 1000 ) break;
    d2.roll( con[rnd()%4] );
    if( d.n[0] == d2.n[0] ){
      if( d.n[5] != d2.n[5] ) break;

      for(int i=0; i<4; i++){
        d2.roll('R');
        bool f = true;
        for(int i=1; i<5; i++){
          if( d.n[i] != d2.n[i] ) f = false;
        }
        if( f ){
          return true;;
        }
      }

      break;
    }
    cnt++;
  }
  return false;
}

int main(){
  random_device rnd;
  string con = "NSEW";

  // d.input();

  int n;
  while(cin >> n){
    if( n == 0 ) break;
    Dice d;

    d.sum += d.n[0];

    for(int i=0; i<n; i++){
      string s;
      cin >> s;
      d.roll(s[0]);
    }

    d.output_sum();
  }

  // d.output_top();

  return 0;
}





// EOF

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

public class Main {

	
	public static void main(String[] args) {
		FastScanner in=new FastScanner();
		PrintWriter out=new PrintWriter(System.out);
	//	int t=in.nextInt();
	//	while(t-->0)
		solve(in,out);
		out.close();
	}
    static long gcd(long a,long b){
        if(b==0) return a;
        else return gcd(b,a%b);
    }
    static void solve(FastScanner in,PrintWriter out){
        long a=in.nextLong();
        long b=in.nextLong();
     out.println((a*b)/gcd(a,b));
    }    
	


	static void sort(int[] a) {
		ArrayList<Integer> l=new ArrayList<>();
		for (int i:a) l.add(i);
		Collections.sort(l);
		for (int i=0; i<a.length; i++) a[i]=l.get(i);
	}
	
	static class FastScanner {
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st=new StringTokenizer("");
		String next() {
			while (!st.hasMoreTokens())
				try {
					st=new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			return st.nextToken();
		}
		
		int nextInt() {
			return Integer.parseInt(next());
		}
		int[] readArray(int n) {
			int[] a=new int[n];
			for (int i=0; i<n; i++) a[i]=nextInt();
			return a;
		}
		long nextLong() {
			return Long.parseLong(next());
		}
	}

	
}


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

int main(){
    long long int N, M;
    cin >> N >> M;

    priority_queue<long long int> q;
    for(long long int i = 0, A; i < N; ++i){
        cin >> A;
        q.emplace(A);
    }

    for(long long int i = 0; i < M; ++i){
        auto x = q.top();
        q.pop();
        x >>= 1;
        q.emplace(x);
    }

    long long ans = 0;
    while(!q.empty()){
        ans += q.top();
        q.pop();
    }

    cout << ans << endl;
}

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

def choose2(n):
    if n >= 2:
        return (n * (n - 1)) // 2
    else:
        return 0

count = [0] * (n + 1)
for i in range(n):
    count[a[i]] += 1
total = 0
for i in range(n + 1):
    total += choose2(count[i])
for k in range(n):
    print(total - (choose2(count[a[k]]) - choose2(count[a[k]] - 1)))


Measured memory_bytes: 26268
#include <iostream>
#include <cstdio>
#include <cstdlib>
using namespace std;

int main(){
    int N;
    int A[100010];
    int reduceTime[100010];

    scanf("%d",&N);
    A[0] = 0;
    A[N+1] = 0;
    for(int i = 1; i <= N; i++){
        scanf("%d",&A[i]);
    }

    int cost = 0;

    for(int i = 1; i <= N; i++){
        cost += abs(A[i-1]-A[i]);
        reduceTime[i] = abs(A[i-1]-A[i]) + abs(A[i]-A[i+1]) - abs(A[i-1]-A[i+1]);
//        printf("%d\n",cost);

    }
    cost += abs(A[N]);

//    printf("%d\n",cost);

    for(int i = 1; i <= N; i++){
//        printf("%d ", reduceTime[i]);
        printf("%d\n",cost-reduceTime[i]);
    }

/*
    for(int i = 0; i < N; i++){
        p = 0;
        int cost = 0;
        for(int j = 0; j < N; j++){
            if(i == j) continue;
            cost += abs(p-A[j]);
            p = A[j];
        }
        cost += abs(p);
        printf("%d\n",cost);
    }
*/

    return 0;

}


Measured memory_bytes: 2680
#include <iostream>
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <algorithm>

using namespace std;

int main() {
	
	int x;
	cin >> x;
	if (x == 0) cout << 1;
	else if (x == 1) cout << 0;
	return 0;
}

Measured memory_bytes: 3620
#include<stdio.h>
int main(void)
{
	int n,h[10],s[10],k[10],i,j,temp,flg,cnt;
	while(1){
		flg=0;
		cnt=0;
		scanf("%d",&n);
		if(n==0000)break;
		while(1){
			if(n==6174)break;
			if(n<1000){
				h[0]=0;
			}
			else{
				h[0]=n/1000;
			}
			if(n<100){
				h[1]=0;
			}
			else{
				h[1]=(n%1000)/100;
			}
			if(n<10){
				h[2]=0;
			}
			else{
				h[2]=((n%1000)%100)/10;
			}
			h[3]=(((n%1000)%100)%10)/1;
			if(h[0]==h[1]&&h[0]==h[2]&&h[0]==h[3]){
			flg=1;
			printf("NA\n");
			break;
			}
			cnt++;
//			printf("%d\n",cnt);
			for(i=0;i<4;i++){
				s[i]=h[i];
				k[i]=h[i];
			}
			for(i=0;i<3;i++){
				for(j=i+1;j<4;j++){
					if(s[i]>s[j]){
						temp=s[i];
						s[i]=s[j];
						s[j]=temp;
					}
				}
			}
			for(i=0;i<3;i++){
				for(j=i+1;j<4;j++){
					if(k[i]<k[j]){
						temp=k[i];
						k[i]=k[j];
						k[j]=temp;
					}
				}
			}
			n=(k[0]*1000+k[1]*100+k[2]*10+k[3])-(s[0]*1000+s[1]*100+s[2]*10+s[3]);
		}
		if(flg!=1){
			printf("%d\n",cnt);
		}
	}
	return 0;
}

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

#define x first
#define y second
#define y1 Y1
#define y2 Y2
#define mp make_pair
#define pb push_back

using namespace std;

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

template <typename T> inline int Chkmax (T &a, T b) { return a < b ? a = b, 1 : 0; }
template <typename T> inline int Chkmin (T &a, T b) { return a > b ? a = b, 1 : 0; }
template <typename T> T read ()
{
	T sum = 0, fl = 1; char ch = getchar();
	for (; !isdigit(ch); ch = getchar()) if (ch == '-') fl = -1;
	for (; isdigit(ch); ch = getchar()) sum = (sum << 3) + (sum << 1) + ch - '0';
	return sum * fl;
}

inline void proc_status()
{
	ifstream t ("/proc/self/status");
	cerr << string (istreambuf_iterator <char> (t), istreambuf_iterator <char> ()) <<endl;
}

const int Maxn = 2e5 + 100;

int N;
LL C, H[Maxn], F[Maxn], Q[Maxn];

inline LL Up (int x, int y) { return F[x] + H[x] * H[x] - (F[y] + H[y] * H[y]); }

inline LL Down (int x, int y) { return 2ll * (H[x] - H[y]); }

inline void Solve ()
{
	int f = 1, l = 1;
	Q[1] = 1, F[1] = 0;

	for (int i = 2; i <= N; ++i)
	{
		while (f < l && Up(Q[f + 1], Q[f]) <= H[i] * Down(Q[f + 1], Q[f])) ++f;

		F[i] = F[Q[f]] + (H[i] - H[Q[f]]) * (H[i] - H[Q[f]]) + C;

		while (f < l && Up(i, Q[l]) * Down(Q[l], Q[l - 1]) <= Up(Q[l], Q[l - 1]) * Down(i, Q[l])) --l;
		Q[++l] = i;
	}

	cout<<F[N]<<endl;
}

inline void Input ()
{
	N = read<int>(), C = read<LL>();
	for (int i = 1; i <= N; ++i) H[i] = read<int>();
}

int main()
{
#ifdef hk_cnyali
	freopen("Z.in", "r", stdin);
	freopen("Z.out", "w", stdout);
#endif
	Input();
	Solve();
	return 0;
}

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

int memo[200][200][200];

int func(int a, int b, int c)
{
    if (a>199 || b>199 || c>199) return 1e9;
    if (a==b && b==c) return 0;
    int& res=memo[a][b][c];
    if (~res) return res;
    return res=min({func(a+1, b+1, c)+1, func(a+1, b, c+1)+1, func(a, b+1, c+1)+1,
        func(a+2, b, c)+1, func(a, b+2, c)+1, func(a, b, c+2)+1});
}
int main()
{
    memset(memo, -1, sizeof(memo));
    int a, b, c; cin>>a>>b>>c;
    cout<<func(a, b, c)<<endl;
}


Measured memory_bytes: 31488
import math

N = int(input())
Nlist = [list(map(int, input().split())) for i in range(N)]
total = 0
for i in range(N-1):
    for j in range(i + 1, N):
        total += math.sqrt((Nlist[i][0]-Nlist[j][0])**2 + (Nlist[i][1]-Nlist[j][1])**2)
        
ans = total*2/N
print(ans)

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

int main() {
	long long N, W, w[100], V, v[4][110] = {}, C[4] = {}, MAX = 0;
	cin >> N >> W;
	for (int i = 0; i < N; i++) {
		cin >> w[i] >> V;
		v[w[i] - w[0]][C[w[i] - w[0]] + 1] = V;
		C[w[i] - w[0]]++;
	}
	for (int i = 0; i < 4; i++) {
		sort(v[i] + 1, v[i] + C[i] + 1, greater<long long>());
	}
	for (int i = 0; i < 4; i++) {
		for (int j = 1; j <= C[i]; j++) {
			v[i][j] += v[i][j - 1];
		}
	}
	long long w0 = w[0], w1 = w[0] + 1, w2 = w[0] + 2, w3 = w[0] + 3;
	for (int i = 0; i <= min(W / w3, C[3]); i++) {
		long long W1 = W - w3 * i;
		for (int j = 0; j <= min(W1 / w2, C[2]); j++) {
			long long W2 = W1 - w2 * j;
			for (int k = 0; k <= min(W2 / w1, C[1]); k++) {
				long long W3 = W2 - w1 * k;
				int l = min(W3 / w0, C[0]);
				MAX = max(MAX, v[3][i] + v[2][j] + v[1][k] + v[0][l]);
			}
		}
	}
	cout << MAX;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<int,int> Pi;
#define rep(i,n) for(ll i=0;i<n;i++)
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define fi first
#define se second
#define endl "\n"

template<typename T> inline bool chmax(T &a, T b){if(a<b){a=b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if(a>b){a=b;return true;}return false;}
template<typename T> ostream& operator<<(ostream& s,const complex<T>& d) {return s<<"("<<d.real()<<", "<<d.imag()<< ")";}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const pair<T1,T2>& d) {return s<<"("<<d.first<<", "<<d.second<<")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& d){int len=d.size();rep(i,len){s<<d[i];if(i<len-1) s<<" ";}return s;}
template<typename T> ostream& operator<<(ostream& s,const vector<vector<T>>& d){int len=d.size();rep(i,len){s<<d[i]<<endl;}return s;}
template<typename T> ostream& operator<<(ostream& s,const set<T>& v){s<<"{ ";for(auto itr=v.begin();itr!=v.end();++itr) {if (itr!=v.begin()) {s<< ", ";}s<<(*itr);}s<<" }";return s;}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const map<T1,T2>& m){s<<"{"<<endl;for(auto itr=m.begin();itr!=m.end();++itr){s<<" "<<(*itr).first<<" : "<<(*itr).second<<endl;}s<<"}"<<endl;return s;}

const ll mod=1e9+7;
const ll inf=1e17;
const int INF=1e9;
const double PI=acos(-1);
const double EPS=1e-10;

int main(){
	cin.tie(0);ios::sync_with_stdio(false);
	vector<int> a(3);
	rep(i,3) cin>>a[i];
	sort(begin(a),end(a));
	cout<<a[0]*a[1]/2<<endl;
}

Measured memory_bytes: 256
#pragma GCC optimize("O3")
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
using P=pair<ll,ll>;
template<class T> using V=vector<T>; 
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
const ll inf=(1e18);
//const ll mod=998244353;
const ll mod=1000000007;
ll GCD(ll a,ll b) {return b ? GCD(b,a%b):a;}
ll LCM(ll c,ll d){return c/GCD(c,d)*d;}
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
ll res[25][60][60]={};
int main(){
  int n;
  cin>>n;
  for(int i=0;i<n;i++){
      string s;
      cin>>s;
      ll val=0,cnt=0;
      bool flag=false;
      for(int j=0;j<s.size();j++){
          if(s[j]=='.'){
              flag=true;
              continue;
          }
          if(flag)cnt++;
          val=val*10+ll(s[j]-'0');
      }
      int two=0,five=0;
      while(val%2==0){
          two++;
          val/=2;
      }
      while(val%5==0){
          five++;
          val/=5;
      }
      res[cnt][two][five]++;
  }
  ll ans=0;
  for(int i=0;i<20;i++){
      for(int j=0;j<60;j++){
          for(int k=0;k<60;k++){
              if(res[i][j][k]==0)continue;
              for(int i2=0;i2<20;i2++){
                  for(int j2=0;j2<60;j2++){
                      for(int k2=0;k2<60;k2++){
                          if(i+i2<=min(j+j2,k+k2)){
                              ans+=res[i][j][k]*res[i2][j2][k2];
                              if(i==i2&&j==j2&&k==k2&&res[i][j][k]>0){
                                  ans-=res[i][j][k];
                              }
                          }
                      }
                  }
              }
          }
      }
  }
  ans/=2;
  cout<<ans<<"\n";
}

Measured memory_bytes: 3668
import java.math.BigInteger;
import java.util.*;
import java.io.*;

public class Main {

    public static void main(String[] args) {
        FastReader sc = new FastReader();
        String s = sc.nextLine();
        String t = sc.nextLine();
        if (!t.substring(0, t.length()-1).equals(s)) {
            System.out.println("No");
        } else {
            System.out.println("Yes");
        }
        //x+a*t == y - b * t
        //a*t+b*t == y - x
        //(a+b)*t == y - x
        // a + (a*2(k-1) = n*2/k
        // a+(a+2k-2)=2a+2k-2=n*2/k
    }

    private static int[] prefix_function(String s) {
        int n = s.length();
        int[] res = new int[n];
        for (int i = 1; i < n; i++) {
            int j = res[i-1];
            while (j > 0 && s.charAt(i) != s.charAt(j)) {
                j = res[j-1];
            }
            if (s.charAt(i)==s.charAt(j)) {
                j++;
            }
            res[i] = j;
        }
        return res;
    }

    private static boolean check(String s) {
        char cc = s.charAt(0);
        for (char c : s.toCharArray()) {
            if (c!=cc) return false;
        }
        return true;
    }

    private static int[] isPrime(int num) {
        for (int i = 2; i <= (int)Math.sqrt(num); i++) {
            if (num % i == 0) return new int[]{i, num/i};
        }
        return null;
    }

    private static int sign(long num) {
        if (num < 0) return -1;
        return 1;
    }

    private static class Pair {
        int x;
        int y;
        public Pair(int x, int y) {
            this.x=x;
            this.y=y;
        }
    }




    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        public FastReader() {
            br = new BufferedReader(new
                    InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

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

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }


    }

}

/**
 * 7 3
 * 3 1 5
 * 9 6 5
 *
 * i = 1: 1
 * i = 2: 2
 * i = 3: 3
 *
 *
 * 1 2 3 3 3 3 3
 */


/**
 *
 *  1+1
 **/

Measured memory_bytes: 32496
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
int main(){
  int s;
  cin>>s;
  set<int>st;
  int x=s;
  int cnt=1;
  
  while(st.count(x)==0){
   cnt++;
   st.insert(x);
   if(x%2==0)x/=2;
    else x=3*x+1;
    
  }
  cout<<cnt<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define f first
#define s second
#define pb push_back
#define pii pair<int, int>
#define endl '\n'
#define vi vector<int>
#define vvi vector<vi>
typedef long long ll;
typedef long double ld;
using namespace std;

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

  int n;
  cin >> n;
  vi a(n + 1, 0), b(n);
  for (int i = 1; i < n; i++) {
    cin >> b[i];
  }

  a[n - 1] = a[n] = b[n - 1];
  for (int i = n - 2; i >= 1; i--) {
    if (b[i] < a[i + 1]) {
      a[i] = b[i];
      a[i + 1] = b[i];
    } else {
      a[i] = b[i];
    }
  }

  cout << accumulate(a.begin(), a.end(), 0) << endl;

  return 0;
}

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

//各桁の和を算出する関数
int findSumOfDegits(int n) {
    int sum = 0;

    while(n > 0) {
        sum += (n%10);
        n /= 10;
    }
    return sum;
}

int main() {
    int N, A, B;
    int total = 0; //求める合計値

    cin >> N >> A >> B;

    for(int i=1; i<=N; ++i) {
        int sum = findSumOfDegits(i); //整数iの各桁の和
        if(sum>=A && sum <=B) total += i;
    }
    cout << total << endl;

    return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;

public class Main {
  public static void main(String[] args) throws IOException {
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    String[] str = in.readLine().split(" ");
    int a = Integer.parseInt(str[0]);
    int b = Integer.parseInt(str[1]);
    int c = Integer.parseInt(str[2]);
    int k = Integer.parseInt(str[3]);
    int max = 0;
    
    if(b>=k-a)
      max = Math.min(k,a);
    else
      max = a*1 - (k-a-b);
    System.out.println(max);
  }
}

Measured memory_bytes: 32452
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double lf;
typedef pair<ll,ll> ii;
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(ll i=1;i<=n;i++)
#define RST(i,n) memset(i,n,sizeof i)
#define SZ(a) (int)a.size()
#define ALL(a) a.begin(),a.end()
#define X first
#define Y second
#define mkp make_pair
#define pb push_back
#define eb emplace_back
#define pob pop_back
#ifdef cold66
#define debug(...) do{\
    fprintf(stderr,"%s - %d (%s) = ",__PRETTY_FUNCTION__,__LINE__,#__VA_ARGS__);\
    _do(__VA_ARGS__);\
}while(0)
template<typename T>void _do(T &&_x){cerr<<_x<<endl;}
template<typename T,typename ...S> void _do(T &&_x,S &&..._t){cerr<<_x<<", ";_do(_t...);}
template<typename _a,typename _b> ostream& operator << (ostream &_s,const pair<_a,_b> &_p){return _s<<"("<<_p.X<<","<<_p.Y<<")";}
template<typename It> ostream& _OUTC(ostream &_s,It _ita,It _itb)
{
    _s<<"{";
    for(It _it=_ita;_it!=_itb;_it++)
    {
        _s<<(_it==_ita?"":",")<<*_it;
    }
    _s<<"}";
    return _s;
}
template<typename _a> ostream &operator << (ostream &_s,vector<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a> ostream &operator << (ostream &_s,set<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a,typename _b> ostream &operator << (ostream &_s,map<_a,_b> &_c){return _OUTC(_s,ALL(_c));}
template<typename _t> void pary(_t _a,_t _b){_OUTC(cerr,_a,_b);cerr<<endl;}
#define IOS()
#else
#define debug(...)
#define pary(...)
#define endl '\n'
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0);
#endif // cold66
//}
template<class T> inline bool chkmax(T &a, const T &b) { return b > a ? a = b, true : false; }
template<class T> inline bool chkmin(T &a, const T &b) { return b < a ? a = b, true : false; }
template<class T> using MaxHeap = priority_queue<T>;
template<class T> using MinHeap = priority_queue<T, vector<T>, greater<T>>;

const ll MAXn=1e3+5,MAXlg=__lg(MAXn)+2;
const ll MOD=1000000007;
const ll INF=0x3f3f3f3f;

char b[MAXn][MAXn];
ll dp[MAXn][MAXn];
int main(){
  IOS();
  ll n,m;
  cin >> n >> m;
  REP1 (i,n) REP1 (j,m) cin >> b[i][j];
  dp[1][1] = 1;

  REP1 (i,n) REP1 (j,m) {
    if (b[i][j] == '#') continue;
    if (dp[i][j] == 0) {
      dp[i][j] = (dp[i-1][j]+dp[i][j-1])%MOD;
    }
  }
  cout << dp[n][m] << endl;
}


Measured memory_bytes: 9088
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <tuple>
#include <numeric>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const double pi = acos(-1);

// 素因数分解。計算量はO(√n)
map<ll, ll> primefactor(ll n) {  // (nのi番目の素因数, その素因数の個数)のmapを返す(n = 720 = (2^4)*(3^2)*(5^1)なら{(2, 4), (3, 2), (5, 1)}のように)
    map<ll, ll> res;
    for(ll i = 2; i*i <= n; i++) {
        while(n%i == 0) {
            res[i]++;
            n /= i;
        }
    }
    if(n != 1) {
        res[n] = 1;
    }
    return res;
}

int main() {
    ll n;
    cin >> n;

    map<ll, ll> mp = primefactor(n);

    ll ans = 0;
    for(auto p : mp) {
        for(ll i = 1; ; i++) {
            if(p.second < i) {
                break;
            }
            p.second -= i;
            ans++;
        }
    }
    
    out(ans);
    re0;
}

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

using namespace std;

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

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

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

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

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

const double EPS=1e-11;
#define EQ0(x) (abs((x))<EPS)
#define EQ(a, b) (abs((a)-(b))<EPS)

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n, a[114514];
	cin>>n;
	bool ok=false;
	REP(i, n){
		cin>>a[i];
		if(a[i]&1){
			ok=true;
		}
	}
	cout<<(ok ? "first" : "second")<<'\n';
	return 0;
}


Measured memory_bytes: 640
import java.util.*;class Main{public static void main(String[]a){Scanner s=new Scanner(System.in);List<Integer>h=new ArrayList<Integer>();for(int i=0;i++<10;)h.add(s.nextInt());Collections.sort(h,Collections.reverseOrder());System.out.printf("%d\n%d\n%d\n",h.toArray());}}

Measured memory_bytes: 12000
// by newbiechd
#include <algorithm>
#include <cassert>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <vector>

// DELETE the debugging information!
#define debug(x) std::cerr << #x << " = " << (x) << std::endl

const int N_MAX = 2003;
int dp[N_MAX][N_MAX];

const int mod = 1e9 + 7;
int power(int x, int y) {
  int ret = 1;
  while (y > 0) {
    if ((y & 1) == 1)
      ret = 1ll * x * ret % mod;
    x = 1ll * x * x % mod, y >>= 1;
  }
  return ret;
}

const int M_MAX = 4000003;
int fac[M_MAX], iFac[M_MAX];

int main() {
  int n, k;
  scanf("%d%d", &n, &k);
  if (k == 1) {
    printf("1\n");
    return 0;
  }
  int m = n * k;
  fac[0] = 1;
  for (int i = 1; i <= m; ++i)
    fac[i] = 1ll * i * fac[i - 1] % mod;
  iFac[m] = power(fac[m], mod - 2);
  for (int i = m; i > 0; --i)
    iFac[i - 1] = 1ll * i * iFac[i] % mod;
  
  dp[0][0] = 1;
  for (int i = 1; i <= n; ++i) {
    dp[i][0] = 1ll * fac[i * (k - 1) - 1] * iFac[k - 2] % mod *
      iFac[(i - 1) * (k - 1)] % mod * dp[i - 1][0] % mod;
    for (int j = 1; j <= i; ++j)
      dp[i][j] = (1ll * fac[i * (k - 1) + j - 1] * iFac[k - 2] % mod *
                  iFac[(i - 1) * (k - 1) + j] % mod * dp[i - 1][j] +
                  dp[i][j - 1]) % mod;
  }
  printf("%lld\n", 1ll * dp[n][n] * fac[n] % mod);
  return 0;
}


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

using namespace std;

int main() {
    int n, m;
    cin >> n >> m;

    vector<int> P(m), Y(m);
    for (int i = 0; i < m; ++i) {
        cin >> P[i] >> Y[i];
        --P[i];
    }

    vector<int> vals[n];
    for (int i = 0; i < m; ++i) {
        vals[P[i]].push_back(Y[i]);
    }

    for (int v = 0; v < n; ++v) {
        sort(vals[v].begin(), vals[v].end());
    }

    for (int i = 0; i < m; ++i) {
        int v = P[i];
        printf("%06d", v + 1);

        int id = lower_bound(vals[v].begin(), vals[v].end(), Y[i]) - vals[v].begin();
        printf("%06d\n", id + 1);
    }
    return 0;
}


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

int main() {
  int N;
  cin>>N;
  vector<int> a(N);
  rep(i,n) cin>>a[i];
  int A=0;
  rep(i,N-1) for(int j =i+1; j<N; j+=1) {
      A+=a[i]*a[j];
  }
  cout<<A<<endl;
}


Measured memory_bytes: 256
from collections import deque

S = input()
Q = int(input())

ANS = deque(S)

rev = 0

for _ in range(Q):
    query = input().split(' ')
    if len(query) == 1:
        rev = rev ^ 1
    else:
        f, c = int(query[1]), query[2]
        if (f - 1) ^ rev:
            ANS.append(c)
        else:
            ANS.appendleft(c)

if rev:
    ANS.reverse()

print(''.join(ANS))

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

const vector<string> ss = { "SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"  };

int main()
{
    string s;
    cin >> s;
    cout << 7 - (find(ss.begin(), ss.end(), s) - ss.begin()) << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
#include <deque>
#define N 100005
using namespace std;

int n, m;
bool v[N];
vector<int> a[N];
deque<int> de;

void f(int p, bool q) {
	int i;
	v[p] = 1;
	if (!q) de.push_front(p);
	else if (p != 1) de.push_back(p);
	for (i = 0; i < a[p].size(); i++) if (!v[a[p][i]]) {f(a[p][i], q); break;}
}

int main()
{
	int i, t1, t2;
	cin >> n >> m;
	while (m--) {
		scanf("%d %d", &t1, &t2);
		a[t1].push_back(t2);
		a[t2].push_back(t1);
	}
	f(1, 0);
	f(1, 1);
    cout << de.size() << endl;
    while (!de.empty()) printf("%d ", de.front()), de.pop_front();
    return 0;
}

Measured memory_bytes: 6784
#include "iostream"
#include "algorithm"
#include "string"
#include "vector"
#include "cmath"
using namespace std;
int main(){
	int a, b, c, d;
	cin >> a >> b >> c >> d;
	if (a + b > c + d)cout << "Left";
	else if (a + b == c + d)cout << "Balanced";
	else cout << "Right";
	cout << endl;
	return 0;
}

Measured memory_bytes: 256
// Lets go to the next level
// AIM EXP at CF *__* asap
// Hit A,B,C faster and reach Expert
// Remember you were also a novice when you started,
// hence never be rude to anyone who wants to learn something!Be calm and help everyone.
// Never open the rank list until and unless you are done with solving problems!
/*HACK ME IF YOU CAN!
░░███▒▒░░░░░░░░░░░░░░░░████
░░████▒░░░░░░░░░░░░░░░███▒█
░░██████░░░░░░░░░░░░░███▒▒▒█
░░██▒▒▒▒█▒▒▒▒▒▒▒▒▒▒▒█████▒██
░▒▒▒▒▓▓▓▓▓▓▒▒▒▒▒▓▓▓▓▓▓▒▒▒░██
▒▒▒▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▒▒▒▒█
▒▒▓▓███████▓░▓▓███████▓▒▒▒▒▒▒
▒▒▓▓▓█▓▄▓█▓░░░▓▓█▓▄▓█▓▓▒▒▒▒▒▒
▒▒▓▓▓▓███▓░░░░░▓▓███▓▓▓▒▒▒▒▒▒
▒▒▒▓▓▓▓▓▓████▓▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒
▒▒▒▒▓▓▓▓▓▒██▒▒▒▓▓▓▓▒▒▒▒▒▒▒▒▒▒
▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
░▒▒▒▒▒▒▒▒█████▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
░░▒▒▒▒▒▒█▒▒▒▒▒█▒▒▒▒▒▒▒▒▒▒▒▒▒
░░░░░▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
*/

//Author: kaiyu
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define sz(x) ((long long)(x).size())
#define all(x)  x.begin(),x.end()
#define endl "\n"
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define leastsigbit(x)     __builtin_ffs(x)
#define mod             1e9 + 7
#define vi vector<ll>
#define vvi vector<vector<ll>>
#define pii pair<int,int>
#define vpii vector<pii>
#define tt ll tt;cin >> tt;while(tt--)
#define  fio ios::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
#define D1(x) { cerr << " [" << #x << ": " << x << "]\n"; }
#define D2(x) { cerr << " [" << #x << ": "; for(auto it:x) cerr << it << " "; cerr << "]\n";}
const double PI = acos(-1);
ll power(ll a,ll b,ll m=mod){ ll ans=1; a=a%m;  while(b>0) {  if(b&1)  ans=(1ll*a*ans)%m; b>>=1;a=(1ll*a*a)%m;}return ans;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
ll lcm( ll x, ll y) { return (x*y)/gcd(x,y);}
bool isprime(ll n){if(n < 2) return 0; ll i = 2; while(i*i <= n){if(n%i == 0) return 0; i++;} return 1;}
struct cmp {
    bool operator() (const pair<int,int>& lhs, const pair<int,int>& rhs) const {
        return lhs.ff * rhs.ss < lhs.ss * rhs.ff;
    }
//for map<pii,int>
};

bool cmps(pair<int,int>p1,pair<int,int>p2) {
    return p1.ss > p2.ss;
}

const int MAXN = 2e5+ 10;

#define int long long
void printString(int n)
{
    vector<char> str; // To store result (Excel column name)
    int i = 0; // To store current index in str which is result

    while (n > 0) {
        // Find remainder
        int rem = n % 26;

        // If remainder is 0, then a 'Z' must be there in output
        if (rem == 0) {
            str.pb('z');
            n = (n / 26) - 1;
        }
        else {
            str.pb( (rem - 1) + 'a');
            n = n / 26;
        }
    }

    reverse(all(str));
    for(auto x : str) {
        cout << x;
    }
}
int32_t main() {
    fio
    int n;
    cin >> n;
    printString(n);



    cerr << "[ Time : " << (float)clock() / CLOCKS_PER_SEC << " secs ]" << endl;


}






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

int main(){
    string A, B, C;
    string sA, sB, sC;
    cin >> A >> B >> C;
    sA = A.at(0);
    sB = B.at(0);
    sC = C.at(0);

    cout << sA << sB << sC;
}

Measured memory_bytes: 256
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"

using namespace std;

const long long int MOD = 1000000007;
//const int MOD = 1000000007;
//const int MOD = 998244353;
//const long long int MOD = 998244353;

long long int N, M, K, H, W, L, R;
//int N, M, K, H, W, L, R;


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

	cin >> N;
	multiset<int>s;
	multiset<int>b;
	long long int ss = 0, bb = 0;
	for (int i = 0; i < N; i++) {
		cin >> K;
		if (K == 1) {
			cin >> L >> R;
			M += R;
			if (s.empty() || (!b.empty() && *b.begin() > L)) {
				s.insert(-L);
				ss += L;
			}
			else {
				b.insert(L);
				bb += L;
			}
			if (s.size() == 1 && b.size() == 1) {
				if (*b.begin() < -*s.begin()) {
					int a = -*s.begin(),c = *b.begin();
					swap(ss, bb);
					s.clear();
					b.clear();
					b.insert(a);
					s.insert(-c);
				}
			}
			if (b.size() > s.size()) {
				int box = *b.begin();
				b.erase(b.begin());
				bb -= box;
				ss += box;
				s.insert(-box);
			}
			if (s.size() > (b.size() + 1)) {
				int box = *s.begin();
				box *= -1;
				s.erase(s.begin());
				bb += box;
				ss -= box;
				b.insert(box);
			}
		}
		else {
			//cout << s.size() << " " << b.size() << endl;
			long long int box = -(*s.begin());
			long long int ans = M;
			ans += bb - box * b.size();
			ans += box * s.size();
			ans -= ss;
			cout << box << " " << ans << endl;
		}
	}
}

Measured memory_bytes: 9600
#include <iostream>
#include <unordered_set>

using namespace std;

unordered_set <int> s;
int n,i,a;

int main()
{
    cin>>n;
    bool ok=1;
    for(i=1;i<=n && ok;i++){
        cin>>a;
        if(s.find(a)!=s.end())
            ok=0;
        s.insert(a);
    }
    if(ok)
        cout<<"YES\n";
    else
        cout<<"NO\n";
    return 0;
}


Measured memory_bytes: 8520
def solve(string):
    n, k, s = string.split()
    n, k = map(int, [n, k])
    flip = [0]
    for i, (s0, s1) in enumerate(zip(s, s[1:]), start=1):
        if s0 != s1:
            flip.append(i)
    flip += [n]
    return str(
        max([
            flip[min(len(flip) - 1, i + 2 * k + (i % 2 ^ int(s[0])))] - flip[i]
            for i in range(len(flip))
        ]))


if __name__ == '__main__':
    print(solve('\n'.join([input(), input()])))


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

int main() {
    int N;
    cin >> N;
    vector<long long> A(N);
    vector<long long> B(N);
    for (int i = 0; i < N; i++) cin >> A[i] >> B[i];

    reverse(A.begin(), A.end());
    reverse(B.begin(), B.end());
    long long ans = 0;
    for (int i = 0; i < N; i++) {
        A[i] += ans;
        ans += (A[i] + B[i] - 1) / B[i] * B[i] - A[i];
    }
    cout << ans << endl;
}

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

int main() {
  int w,a,b;
  cin >>w>>a>>b;
  if(a>b){
    if(a-b-w<=0){
      cout<<0<<endl;
    }else{
      cout<<a-b-w<<endl;
    }
  }else{
    if(b-a-w<=0){
      cout<<0<<endl;
    }else{
      cout<<b-a-w<<endl;
    }
  }
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int INF = 0x3f3f3f3f;
const int N = 3e3 + 10;
int n, m;
int A[N], B[N], C[N], D[N], E[N], F[N];
ll ans;
vector<int>xx, yy;
int id(vector<int>&vc, int x) {
	return lower_bound(vc.begin(), vc.end(), x) - vc.begin();
}
int dx[]{ 0,0,-1,1 };
int dy[]{ -1,1,0,0 };
int die[N][N][4];
typedef pair<int, int> pii;
queue<pii>q;
int vis[N][N];
int main() {
	scanf("%d%d", &n, &m);
	xx.push_back(0);
	yy.push_back(0);
	xx.push_back(-INF); xx.push_back(INF);
	yy.push_back(-INF); yy.push_back(INF);
	for (int i = 1; i <= n; i++) {
		scanf("%d%d%d", &A[i], &B[i], &C[i]);
		xx.push_back(A[i]);
		xx.push_back(B[i]);
		yy.push_back(C[i]);
	}
	for (int i = 1; i <= m; i++) {
		scanf("%d%d%d", &D[i], &E[i], &F[i]);
		yy.push_back(E[i]);
		yy.push_back(F[i]);
		xx.push_back(D[i]);
	}
	sort(xx.begin(), xx.end()); xx.erase(unique(xx.begin(), xx.end()), xx.end());
	sort(yy.begin(), yy.end()); yy.erase(unique(yy.begin(), yy.end()), yy.end());
	for (int i = 1; i <= n; i++) {
		A[i] = id(xx, A[i]);
		B[i] = id(xx, B[i]);
		C[i] = id(yy, C[i]);
		for (int j = A[i]; j < B[i]; j++) {
			die[j][C[i]][0] = 1;
			die[j][C[i] - 1][1] = 1;
		}
	}
	for (int i = 1; i <= m; i++) {
		D[i] = id(xx, D[i]);
		E[i] = id(yy, E[i]);
		F[i] = id(yy, F[i]);
		for (int j = E[i]; j < F[i]; j++) {
			die[D[i]][j][2] = 1;
			die[D[i] - 1][j][3] = 1;
		}
	}
	q.push(pii(id(xx, 0), id(yy, 0)));
	while (!q.empty()) {
		int x = q.front().first, y = q.front().second; q.pop();
		if (vis[x][y])continue;
		if (x == 0 || x == (int)xx.size() - 1 || y == 0 || y == (int)yy.size() - 1) {
			puts("INF");
			return 0;
		}
		ans += 1ll * (xx[x + 1] - xx[x])*(yy[y + 1] - yy[y]);
		vis[x][y] = 1;
		for (int i = 0; i < 4; i++) {
			if (die[x][y][i])continue;
			int nx = x + dx[i], ny = y + dy[i];
			q.push(pii(nx, ny));
		}
	}
	printf("%lld\n", ans);
	return 0;
}


Measured memory_bytes: 160552
#include <bits/stdc++.h>
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
using namespace std;

#define REP(i, n) for (int i = 0; i < (n); i++)
#define int long long
#define FOR(i, m, n) for (int i = (m); i < (n); i++)
#define all(x) x.begin(), x.end()
using pii = pair<int, int>;
using ll = long long;
const int INF = 1e9;

template <typename T> struct edge {
    int src, to;
    T cost;

    edge(int to, T cost) : src(-1), to(to), cost(cost) {}

    edge(int src, int to, T cost) : src(src), to(to), cost(cost) {}

    edge &operator=(const int &x) {
        to = x;
        return *this;
    }

    operator int() const { return to; }
};

template <typename T> using Edges = vector<edge<T> >;
template <typename T> using WeightedGraph = vector<Edges<T> >;
using UnWeightedGraph = vector<vector<int> >;

template <typename G> struct StronglyConnectedComponents {
    const G &g;
    UnWeightedGraph gg, rg;
    vector<int> comp, order, used;

    StronglyConnectedComponents(G &g) : g(g), gg(g.size()), rg(g.size()), comp(g.size(), -1), used(g.size()) {
        for (int i = 0; i < g.size(); i++) {
            for (auto e : g[i]) {
                gg[i].emplace_back((int)e);
                rg[(int)e].emplace_back(i);
            }
        }
    }

    int operator[](int k) { return comp[k]; }

    void dfs(int idx) {
        if (used[idx]) return;
        used[idx] = true;
        for (int to : gg[idx]) dfs(to);
        order.push_back(idx);
    }

    void rdfs(int idx, int cnt) {
        if (comp[idx] != -1) return;
        comp[idx] = cnt;
        for (int to : rg[idx]) rdfs(to, cnt);
    }

    void build(UnWeightedGraph &t) {
        for (int i = 0; i < gg.size(); i++) dfs(i);
        reverse(begin(order), end(order));
        int ptr = 0;
        for (int i : order)
            if (comp[i] == -1) rdfs(i, ptr), ptr++;

        t.resize(ptr);
        for (int i = 0; i < g.size(); i++) {
            for (auto &to : g[i]) {
                int x = comp[i], y = comp[to];
                if (x == y) continue;
                t[x].push_back(y);
            }
        }
    }
};
constexpr int MOD = 1e9 + 7;
int dfs(int n, UnWeightedGraph &T) {
    if (T[n].size() == 0) return 2;
    int ret = 1;
    for (auto nxt : T[n]) {
        ret *= dfs(nxt, T);
        ret %= MOD;
    }
    return (ret + 1) % MOD;
}
bool solve() {
    int N, M;
    cin >> N >> M;
    if (N == 0) return false;
    UnWeightedGraph G(N), T;
    REP(i, M) {
        int u, v;
        cin >> u >> v;
        u--, v--;
        G[v].push_back(u);
    }

    StronglyConnectedComponents<UnWeightedGraph> scc(G);
    scc.build(T);
    int K = T.size();
    vector<int> deg(K);
    int root = 0;
    REP(i, K) {
        for (auto nxt : T[i]) {
            deg[nxt]++;
        }
    }
    ll ans = 1;
    vector<int> roots;
    REP(i, K) {
        if (deg[i] == 0) roots.push_back(i);
    }
    for (auto root : roots) {
        ans *= dfs(root, T);
        ans %= MOD;
    }
    cout << ans << endl;
    return true;
}

signed main() {
    solve();
    // while (solve())
    //     ;
}



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

int gcd(int a, int b) {
	if (!b)return a;
	return gcd(b, a%b);
}
int b[500], r[500];
vector<int>E[500];
bool used[1000];
int match[1000];

bool dfs(int u) {
	used[u] = true;
	for (int v : E[u]) {
		int w = match[v];
		if (w == -1 || (!used[w] && dfs(w))) {
			match[u] = v; match[v] = u;
			return true;
		}
	}
	return false;
}
int main() {
	int m, n;
	while (scanf("%d%d", &m, &n), m) {
		rep(i, m)E[i].clear();
		rep(i, m)scanf("%d", &b[i]);
		rep(i, n)scanf("%d", &r[i]);
		rep(i, m)rep(j, n) {
			if (gcd(b[i], r[j]) != 1)E[i].push_back(m + j);
		}
		memset(match, -1, sizeof(match));
		int ans = 0;
		rep(i, m) {
			if (match[i] == -1) {
				memset(used, 0, sizeof(used));
				if (dfs(i))ans++;
			}
		}
		printf("%d\n", ans);
	}
}

Measured memory_bytes: 3912
macro_rules! get {
    ($t:ty) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t:ty),*) => {
        {
            let mut line: String = String::new();
            std::io::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<_>>()
    };
}

fn main() {
    let (a, b) = get!(String, String);
    println!("{}", if a > b { ">" } else if a < b { "<" } else { "=" });
}

Measured memory_bytes: 2152
#include<bits/stdc++.h>
#include <math.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define lper(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9;
const ll INF=4e18;
const ll dy[4]={1,0,-1,0};
const ll dx[4]={0,-1,0,1};
int main() {
 
int N;
  cin >> N;
  vector<int> vec(N);
  rep(i,N) {
cin >> vec.at(i);
  }
bool answer=true;
  int count=0;
  
  rep(i,N) {
 if ((vec.at(i))%2==0) {
   if ((vec.at(i))%3==0) {
    count++;
   }
   if ((vec.at(i))%5==0) {
     count++;
   }
   if (count>0) {
     count=0;
     continue;
   }
else {
  answer=false;
  break;
}
 }
  }
    if(answer) {
      cout <<"APPROVED" << endl;
    }
else {
  cout << "DENIED" << endl;
}
  }
   

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

using namespace std;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  int n, a, b;
  cin >> n >> a >> b;
  vector<int> h(n);
  int m = 0;
  for (auto &e : h) {
    cin >> e;
    m = max(m, e);
  }
  int l = 0, r = m / b + 1;
  int sd = a - b; // selected damage
  while (l + 1 < r) {
    int mid = (l + r) / 2;
    int selected = 0;
    for (int i = 0; i < n; ++i) {
      int rest = h[i] - b * mid;
      if (0 < rest) {
        selected += (rest + sd - 1) / sd;
      }
      if (mid < selected) break;
    }
    if (mid < selected) {
      l = mid;
    } else {
      r = mid;
    }
  }
  cout << r << "\n";
}


Measured memory_bytes: 640
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>

int main(void) {


	char a = 0;

	int i = 0;
	int sum = 0;

	int answer[10000] = { 0 };
	int counter = 0;
	for (i = 0; i < 10000; i++) {
		scanf("%c", &a);


		if (a != 48) { // 0でない
			if (a != 10) {// 改行でない
				sum += (int)(a - 48);
			}
			else {
				
				answer[counter] = sum;
				counter++;
				sum = 0;
			}
		}
		else { //0 である
			scanf("%c", &a);
			if (a == 10) { // 改行である
				if (sum == 0) {
					break;
				}
				else {
					
					answer[counter] = sum;
					counter++;
					sum = 0;
				}
			}
			else {
				sum += (int)(a -48);
			}
			continue;
		}
	}

	int j = 0;
	for (; j < counter; j++) {
		printf("%d\n", answer[j]);
	}


	return 0;
}


Measured memory_bytes: 2056
#include<stdio.h>
int main(){
    int a, b, c, t;
    scanf("%d%d%d", &a, &b, &c);
    if (a > b){t = a; a = b; b = t;}
    if (b > c){t = b; b = c; c = t;}
    if (a > b){t = a; a = b; b = t;}
    printf("%d %d %d\n", a, b, c);
    return 0;
}


Measured memory_bytes: 2148
#include <bits/stdc++.h>
#include <stdlib.h>
using namespace std;
typedef long long ll;

int main() {
  ll n;
  cin>>n;
  ll a[n];
  for(int i=0;i<n;i++) {
    cin>>a[i];
  }
  ll sum=0;
  ll res1=0;
  ll res2=0;
  for(int i=0;i<n;i++){
    if(i%2==0){
      if(sum+a[i]>0){
        sum+=a[i];
      }
      else{
        res1=res1+1-(sum+a[i]);
        sum=1;
      }
    }
    else{
      if(sum+a[i]<0){
        sum+=a[i];
      }
      else{
        res1=res1+(sum+a[i])+1;
        sum=-1;
      }
    }
  }
  sum=0;
  for(int i=0;i<n;i++){
    if(i%2==0){
      if(sum+a[i]<0){
        sum+=a[i];
      }
      else{
        res2=res2+1+sum+a[i];
        sum=-1;
      }
    }
    else{
      if(sum+a[i]>0){
        sum+=a[i];
      }
      else{
        res2=res2+1-sum-a[i];
        sum=1;
      }
    }
  }
  cout<<min(res1,res2)<<endl;
  return 0;
}


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

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rrep(i, n) for(int i = ((int)(n)-1); i >= 0; i--)
#define all(x) (x).begin(),(x).end()

using namespace std;
using ll = long long;

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> P;
 
const int INF = 1e9;
//const ll INF = 1e18;
const double EPS = 1e-10;
const int MOD = 1e9+7;
const double PI = acos(-1.0);

int main()
{
	int n;
	cin >> n;
	vi a(3*n);
	rep(i,3*n) cin >> a[i];
	sort(all(a));
	ll ans = 0;
	for(int i = n; i < n*3; i+=2){
		ans += a[i];
		//cout << a[i] << endl;
	}
	cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1408
using System;
using System.Diagnostics;
using System.IO;
using System.Text;
using System.Linq;
using System.Collections.Generic;

class Program
{
    static void Main(string[] args) {
#if DEBUG
        //MyDebugger.MakeTestCase("../TextFile2.txt");
        MyDebugger.Test(process, "../TextFile1.txt");
#else
        object ret = process(new StreamReader(Console.OpenStandardInput()));
        Console.WriteLine(ret);
#endif
    }

    static object process(TextReader input) {
        var s = input.ReadLine();

        var ch1 = true;
        var ch2 = true;

        for(int i=0; i<s.Length; i++) {
            char c = s[i];
            if(i % 2 == 0) {
                ch1 &= (c == 'R' || c == 'U' || c == 'D');
            } else {
                ch2 &= (c == 'L' || c == 'U' || c == 'D');
            }
        }

        if(ch1 && ch2) {
            return "Yes";
        } else {
            return "No";
        }
    }
}


Measured memory_bytes: 13140
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; ++i)
#define rrep(i,n) for (int i = n-1; i >= 0; i--)
#define rep2(i,s,n) for (int i = s; i < n; ++i)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define tmax(a,b,c) max(a,max(b,c))
#define tmin(a,b,c) min(a,min(b,c))
#define pb push_back
#define eb emplace_back
#define vi vector<int>
#define vvi vector<vector<int>>
#define vl vector<ll>
#define vs vector<string>
#define vc vector<char>
#define vb vector<bool>
#define vp vector<P>
using namespace std;
using ll = long long;
using P = pair<int,int>;
using LP = pair<ll,ll>;
template<class T> istream& operator>>(istream& is,vector<T>& v) { for(T& t:v){is>>t;} return is; }
template<class T> ostream& operator<<(ostream& os,const vector<T>& v) { for(T t:v){os<<t<<" ";} os<<"\n"; return os; }
void Yes(bool b) { cout << (b ? "Yes" : "No") << endl; }
void YES(bool b) { cout << (b ? "YES" : "NO") << endl; }
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 inf = 1001001001;
const ll linf = 1001001001001001001;

vvi tree;
vi sum;

int dfs(int n = 0,int p = -1) {
    for(int i : tree[n]) {
        if(i == p) continue;
        sum[i] += sum[n];
        dfs(i,n);
    }
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr); cout.tie(nullptr);
    int n,q;
    cin >> n >> q;
    tree.resize(n);
    rep(i,n-1) {
        int a,b;
        cin >> a >> b;
        a--; b--;
        tree[a].pb(b);
        tree[b].pb(a);
    }
    sum.resize(n);
    rep(_,q) {
        int p,x;
        cin >> p >> x;
        p--;
        sum[p] += x;
    }
    dfs();
    cout << sum;
}


Measured memory_bytes: 23552