akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
 
int main() {
  string S;
  cin >> S;
  int n;
  bool f = false;
  n = S.size();
  int i = 0;
  while(i < n){
    if((i % 2) == 0){
      if(S.at(i) == 'L'){
        f = true;
        break;
      }
    } else {
      if(S.at(i) == 'R'){
        f = true;
        break;
      }
    }
    i++;
  }
  if(f == true){
    cout << "No" << endl;
  } else {
    cout << "Yes" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
mod = 10**9+7

import sys
input = sys.stdin.buffer.readline

def main():

    n, k = map(int, input().split())
    A = list(map(int, input().split()))

    PZ = []
    N = []
    for a in A:
        if a >= 0:
            PZ.append(a)
        else:
            N.append(a)

    flag = True
    if len(PZ) > 0:
        if n == k:
            if len(N)%2 != 0:
                flag = False
    else:
        if k%2 != 0:
            flag = False

    if flag:
        if k%2 == 0:
            PZ.sort(reverse=True)
            N.sort()
            s = len(PZ)
            t = len(N)
            C = []
            for i in range(s//2):
                C.append(PZ[2*i]*PZ[2*i+1])
            for i in range(t//2):
                C.append(N[2*i]*N[2*i+1])
            C.sort(reverse=True)
            ans = 1
            for i in range(k//2):
                ans *= C[i]
                ans %= mod
        else:
            PZ.sort()
            ans = PZ.pop()
            PZ.reverse()
            N.sort()
            s = len(PZ)
            t = len(N)
            C = []
            for i in range(s//2):
                C.append(PZ[2*i]*PZ[2*i+1])
            for i in range(t//2):
                C.append(N[2*i]*N[2*i+1])
            C.sort(reverse=True)
            for i in range(k//2):
                ans *= C[i]
                ans %= mod
    else:
        ABS = [abs(a) for a in A]
        ABS.sort()
        ans = 1
        for i in range(k):
            ans *= ABS[i]
            ans %= mod
        ans *= -1
        ans %= mod
    print(ans)

if __name__ == '__main__':
    main()


Measured memory_bytes: 27944
#include "bits/stdc++.h"
using namespace std;
///////////////////////////////////////////
const long long int INF = 1LL<<60;
const long long int Mod = 1000000007;
using ll = long long int; using ci = const int;
using vi = vector<int>;  using Vi = vector<long long int>;
using P = pair<int, int>;  using PLL = pair<ll, ll>;
using matrix = vector<vector<ll>>;
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define rep(i,N) for(ll i = 0; i < (ll)N; i++)
#define repi(i,a,b) for(ll i = ll(a); i < ll(b); ++i)
template<class T>bool chmax(T &former, const T &b) { if (former<b) { former=b; return true; } return false; }
template<class T>bool chmin(T &former, const T &b) { if (b<former) { former=b; return true; } return false; }
template<class T>T sqar(T x){ return x*x; }//sqrt(x)は平方根;
#define Sort(v) std::sort(v.begin(), v.end(), std::greater<decltype(v[0])>()) //降順でVをソート
#define p_queue(v) priority_queue<v, vector<v>, greater<v> >
template<class T> inline void princ(T x){cout<<x<<" ";}; 
template<class T> inline void print(T x){cout<<x<<"\n";};
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
///////////////////////////////////////////////////////////////////////////////////

ll n;
Vi a;

bool ck(ll num){
	ll div = n+1;
	ll sum = 0;
	rep(i,n){
		ll tp = a[i]+num-n;
		if(tp<0)continue;
		ll tmp = tp/div;
		tmp++;
		sum += tmp;
	}
	return num>=sum;
}

int main(){
	cin.tie(0);ios::sync_with_stdio(false);
	std::cout<<std::fixed<<std::setprecision(30);
	cin>>n;
	a.resize(n);
	rep(i,n){
		cin>>a[i];
	}
	ll mid, ok = INF, ng = -1;
	while(abs(ok-ng)>1){
		mid = (ok+ng)/2;
		if(ck(mid))ok = mid;
		else ng = mid;
	}//midではなくokを使わないとバグる!
	//print(ok);
	ll mi = ok-n*n;
	chmax(mi,0LL);
	repi(i,mi,ok+1){
		if(ck(i)){
			print(i);
			break;
		}
	}
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main()
{
	int i,k;
	char a[100][100],b[100];
	for(i=0;i<3;i++)
	{
		for(k=0;k<3;k++)
		{
			scanf("%c",&a[i][k]);
		}	
		getchar();
	}	
	printf("%c%c%c",a[0][0],a[1][1],a[2][2]);
	return 0;
 } 

Measured memory_bytes: 128
#include <iostream>
#include <fstream>
#include <string>
#include <stdio.h>

using namespace std;

typedef struct {
    int s[100];
    int top;
} mystack_t;

void my_push(mystack_t *t, int x){
    t->top += 1;
    t->s[t->top] = x;
}

int my_pop(mystack_t *t){
    int ans = t->s[t->top];
    t->top -= 1;
    return ans;
}

int main(){

    mystack_t t;
    mystack_t *pt = &t;
    string s;
    int a,b,ans;

    while(cin >> s){
        if(s == "+"){
            a = my_pop(pt);
            b = my_pop(pt);
            ans = b+a;
            my_push(pt,ans);
        }else if(s == "-"){
            a = my_pop(pt);
            b = my_pop(pt);
            ans = b-a;
            my_push(pt,ans);
        }else if(s == "*"){
            a = my_pop(pt);
            b = my_pop(pt);
            ans = b*a;
            my_push(pt,ans);

        }else{
            sscanf(s.c_str(),"%d",&ans);
            my_push(pt,ans);
        }
    }
    cout << pt->s[pt->top] << endl;
    return 0;
}



Measured memory_bytes: 3252
#include <iostream>
#include <math.h>
#include <vector>
#include <stack>
#include <cstdio>
#include <string>
#include <bitset>
#include <list>
#include <set>
#include <algorithm>
#include <numeric>
#include <unordered_map>

using namespace std;
//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

//int N;
//int C;
//int D[1001][1001];
//int c[31][31];
//int val[3][31];
//
//int getVal() {
//	for (int i = 2; i <= 2 * N; i += 3) {
//		sum=0;
//
//	}
//}
//
//
//int main() {
//	int N;
//	cin >>N >>C;
//	for (int i = 1; i <= C; i++) {
//		for (int j = 1; j <= C; j++) {
//			cin >> D[i][j];
//		}
//	}
//	for (int i = 1; i <= C; i++) {
//		for (int j = 1; j <= C; j++) {
//			cin >> c[i][j];
//		}
//	}
//	getVal();
//}

#include <iostream>
#include <math.h>
#include <vector>
#include <stack>
#include <cstdio>
#include <string>
#include <bitset>
#include <list>
#include <set>
#include <algorithm>
#include <numeric>
#include <unordered_map>

using namespace std;
//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

int get2factor(int n) {
	int x=0;
	while (n % 2 == 0) {
		n /= 2;
		x++;
	}
	return x;
}

int main() {
	int N,x;
	vector<int> f;
	cin>> N;
	for (int i = 0; i < N; i++) {
		cin >> x;
		f.push_back(get2factor(x));
	}
	cout << accumulate(f.begin(), f.end(),0);

	return 0;
}



Measured memory_bytes: 384
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
 
using namespace std;
typedef long long ll;
 
const ll MOD = 1000000007;
 
ll fact[100005];
 
int N, K;
ll A[100005];
 
void init_fact() {
    ll f = 1;
    fact[0] = 1;
    for (int i = 1; i <= 100004; i ++) {
        f = (f * i) % MOD;
        fact[i] = f;
    }
}
 
void extgcd(ll a, ll b, ll *x, ll *y) {
    ll xx, yy;
    if (b == 0) {
        *x = 1;
        *y = 0;
    } else {
        ll q = a / b;
        ll r = a % b;
        extgcd(b, r, &xx, &yy);
        *x = yy;
        *y = xx - q * yy;
    }
}
 
ll inv(ll a) {
    ll x, y;
    extgcd(a, MOD, &x, &y);
    return (x + MOD) % MOD;
}
 
ll combination(int n, int r) {
    return (fact[n] * inv(fact[r]) % MOD * inv(fact[n - r]) % MOD)%MOD;
}
 
int main() {
    init_fact();
    cin >> N >> K;
    rep(i, N) cin >> A[i];
    sort(A, A + N);
    ll ans = 0;
    for (int i = K - 1; i < N; i ++) {
        ll c = combination(i, K - 1);
        ans = (ans + c * A[i] % MOD) % MOD;
    }
    for (int i = 0; i <= N - K; i ++) {
        ll c = combination(N - 1 - i, K - 1);
        ans = (ans + MOD - (c%MOD * A[i]%MOD) % MOD) % MOD;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
#define ll long long
	
signed main(){
	ll n, i, j, w;
	cin >> n >> w;
	vector<pair<ll,ll>> v(n);
	for( i = 0 ; i < n ; i++ ){
		cin >> v[i].first >> v[i].second;
	}

	sort(v.begin(),v.end());

	vector<ll> dp(w+1,0);
	for( i = 1 ; i <= n ; i++ ){
		for( j = w ; j >= v[i-1].first ; j-- ){
			dp[j] = max( dp[j] , dp[ j-v[i-1].first ] + v[i-1].second );
		}
	}
	cout << dp[w] << endl;
	return 0;
}

Measured memory_bytes: 1024
import java.util.*;

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

        String S = sc.next();
        char[] cs = new char[S.length()];
        int count = 0;

        for (int i=0; i<S.length(); i++) {
            cs[i] = S.charAt(i);
        }

        for (int i=1; i<S.length(); i++) {
            if (cs[i-1] == cs[i]) {
                count++;
                cs[i] = reverse(cs[i]);
            }
        }
        System.out.println(count);
    }

    static public char reverse(char c) {
        if (c == '0') {
            return '1';
        } else {
            return '0';
        }
    }
}


Measured memory_bytes: 26612
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "debug.h"
#else
#define dump(...)
#endif
#define endl "\n"
#define ll long long
#define int ll
#define BUF 1e5
#define INF 1 << 30
#define vi vector<int>
#define vvi vector<vector<int>>
#define all(a) (a).begin(), (a).end()
#define bit(n) (1LL << (n))
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
constexpr ll mod = 1e9 + 7;
ll A, B, C, D, G, H, N, M, L, K, P, Q, R, W, X, Y, Z;
string S, T;
ll ans = 0;

template <typename T>
istream &operator>>(istream &is, vector<T> &vec) {
    for (T &x : vec)
        is >> x;
    return is;
}

signed main() {
    cin >> N >> M;
    vector<pair<int, int>> ab(N);
    for (int i = 0; i < N; i++) {
        cin >> ab[i].first >> ab[i].second;
    }
    sort(all(ab));
    priority_queue<int> pq;
    int j = 0;
    for (int i = 1; i <= M; i++) {
        while (ab[j].first == i) {
            pq.push(ab[j].second);
            j++;
        }
        if (!pq.empty()) {
            ans += pq.top();
            pq.pop();
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 2936
#include<iostream>
#include<algorithm>
using namespace std;
int x[2000000];

void prime(int p) {
	x[2] = 1;
	for (int i = 3; i < p; i += 2) {
		for (int j = 3; j * j <= i; j += 2) {
			if (i%j == 0) { goto E; }
		}
		x[i] = 1;
	E:;
	}
}

int n, m, c, sum;

int main() {
	prime(1000000);
	while (true) {
		sum = 0;
		cin >> n;
		if (n == 0) { break; }
		for (int i = 0; i < n; i++) {
			cin >> m >> c;
			for (int j = max(0, m - c); j <= min(1000000, m + c); j++) {
				sum += x[j];
			}
			sum -= 1;
		}
		cout << sum << endl;
	}
}

Measured memory_bytes: 7016
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i <(n) ; ++i)
using namespace std;
using ll = long long;
void self_max(int &a,int b){
	a = max(a,b);
}
std::vector<string> v = {"Sunny", "Cloudy","Rainy","Sunny"};
int main() {
	string str; cin >> str;

	rep(i,3){
		if(v[i] == str) cout << v[i+1] << endl;
	}

	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
    int i, j, k;
    scanf("%d", &i);
    scanf("%d", &j);
    scanf("%d", &k);

    if ((i + j + k) > 21)
    {
        printf("bust\n");
    }
    else
    {
        printf("win\n");
    }

    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std; // スペル注意
#define rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define pb push_back 
// make_pair など各自で

int main(){
	string S;
	int N;
	cin >> S;
	N = S.size();
	string L ="";
	     for (int i = 0; i < N; i++)
        {
            if (S[i] != 'x')
            {
                L += S[i];
            }
        }
                int M = L.size();
        //WriteLine(L);
        for (int i = 0; i < M / 2; i++)
        {
            if (L[i] != L[M - 1 - i])
            {
                cout << (-1) << endl;
                return 0;
            }
        }
        
        if (M == 0)
        {
            cout << 0 << endl;
        }
        else if (M % 2 == 1)
        {
            int cnt = 0;
            //var A = new int[M / 2 + 1];
            //var B = new int[M / 2 + 1];
            int A[M / 2+ 1] ={0};
            int B[M /2 + 1]= {0};
            for (int i = 0; i < N; i++)
            {
                if (S[i] != 'x')
                {
                    cnt++;
                }
                else
                {
                    if (cnt <= M / 2)
                    {
                        A[M / 2 - cnt]++;
                    }
                    else
                    {
                        B[cnt - M / 2 - 1]++;
                    }
                }


            }
            long sum = 0;
            //WriteLine(string.Join(" ", A));
            //WriteLine(string.Join(" ", B));
            for (int i = 0; i < M / 2 + 1; i++)
            {
                sum += abs(A[i] - B[i]);
            }
            cout << sum << endl;


        }
        else
        {
            int cnt = 0;
            //var A = new int[M / 2];
            //var B = new int[M / 2];
           int A[M / 2] ={0};
            int B[M /2] ={0};
            for (int i = 0; i < N; i++)
            {
                if (S[i] != 'x')
                {
                    cnt++;
                }
                else
                {
                    if (cnt <= M / 2 - 1)
                    {
                        A[M / 2 - cnt - 1]++;
                    }
                    else if(cnt >= M / 2 + 1)
                    {
                        B[cnt - M / 2 - 1]++;
                    }
                }


            }
            long sum = 0;
            //WriteLine(string.Join(" ", A));
            //WriteLine(string.Join(" ", B));
            for (int i = 0; i < M / 2; i++)
            {
                sum += abs(A[i] - B[i]);
            }
            cout << sum << endl;
        }
	return 0;
}

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

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	string s, t; cin >> s >> t;
	sort(s.begin(),s.end());
	sort(t.rbegin(),t.rend());
	cout << ( (s < t) ? "Yes" : "No") << "\n";	
	return 0;
}


Measured memory_bytes: 3656
package main

import "fmt"

func main() {
	var n int
	fmt.Scan(&n)

	var sum float32
	for i := 0; i < n; i++ {
		var a float32
		fmt.Scan(&a)

		sum += 1.0 / a
	}
	fmt.Println(1.0 / sum)
}


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

const int MAXN = 300010;

int A[MAXN];
int cnt[MAXN];
vector<int> vi[MAXN], ve[MAXN];

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

	cin >> N;
	for(int i = 0; i < N; i++) cin >> A[i];

	for(int i = 0; i < N; i++) cnt[A[i] - 1]++;
	sort(cnt, cnt + N);
	int sum = cnt[0];
	cnt[N] = N + 2;
	for(int i = 1; i <= N; i++) {
		int x = N - i;
		for(int y = 0; y < cnt[i] - 1; y++) {
			//printf("x = %d, y = %d, K = [%d, %d], sum = %d\n", x, y, min(sum / (y + 1) + x + 1, N + 1), y ? min(N + 1, sum / y + x + 1) : (N + 1), sum);
			vi[min(sum / (y + 1) + x + 1, N + 1)].push_back(y);
			ve[y ? min(N + 1, sum / y + x + 1) : (N + 1)].push_back(y);
		}
		sum += cnt[i];
	}
	multiset<int> s;
	for(int i = 1; i <= N; i++) {
		s.insert(N / i);
		for(auto a : vi[i]) s.insert(a);
		for(auto a : ve[i]) s.erase(s.find(a));
		cout << *s.begin() << "\n";
	}
	return 0;
}


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

using ll = long long;
using ull = unsigned long long;
using ld = long double;

#define forn(i, a, n) for (int i = a; i < n; ++i)
#define ford(i, a, n) for (int i = n - 1; i >= a; --i)
#define fore(i, a, n) for (int i = a; i <= n; ++i)
#define all(a) (a).begin(), (a).end()
#define fs first
#define sn second
#define trace(a)\
	for (auto i : a) cerr << i << ' ';\
	cerr << '\n'
#define eb emplace_back

#ifndef M_PI
const ld M_PI = acos(-1.0);
#endif

const ld eps = 1e-9;
const int INF = 2000000000;
const ll LINF = 1ll * INF * INF;
const ll MOD = 1000000007;

bool ok (int t, int b) {
    return t >= 0 && t < b;
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
    ll h, w;
    map<pair<ll, ll>, int> cnt;
    int n;
    cin >> h >> w >> n;
    while(n--) {
        int x, y;
        cin >> x >> y;
        --x, --y;
        forn(i, 0, 3) forn(j, 0, 3) {
            if (ok(x + i, h) && ok(x + i - 2, h) && ok(y + j, w) && ok(y + j - 2, w))
                cnt[{x + i, y + j}]++;
        }
    }
    vector<ll> ans(10);
    for (auto p : cnt) ans[p.second]++;
    ans[0] = 1ll * (h - 2) * (w - 2);
    forn(i, 1, 10) ans[0] -= ans[i];
    forn(i, 0, 10) cout << ans[i] << '\n';
}


Measured memory_bytes: 56448
import System.Exit
import Control.Applicative

judge :: Int -> Int -> Int -> String
judge x y z
    | x == -1 || y == -1 = "F"
    | x + y >= 80        = "A"
    | x + y >= 65        = "B"
    | x + y >= 50        = "C"
    | x + y <  30        = "F"
    | z >= 50            = "C"
    | otherwise          = "D"

main = do
    [x, y, z] <- map (read :: String -> Int) . words <$> getLine
    if x == -1 && y == -1 && z == -1 then exitSuccess
    else putStrLn $ judge x y z
    main


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

using namespace std;
using ll = long long;

int main()
{
    ll N,M;
    while(cin >> N >> M){
        if(N == 0)return 0;
        vector<pair<ll, ll>> v;
        for(int i = 0;i < N;i++){
            ll a,b;cin >> a >> b;
            v.push_back({b, a});
        }
        sort(v.begin(), v.end(), greater<pair<ll, ll>>());
        for(int i = 0;i < N;i++){
            if(v[i].second >= M){
                v[i].second -= M;
                M = 0;
            }else{
                M -= v[i].second;
                v[i].second = 0;
            }
        }
        ll ans = 0;
        for(int i = 0;i < N;i++)ans += v[i].first * v[i].second;
        cout<<ans<<endl;
    }
}



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

int main() {
  int n;
  cin >> n;
  vector<long> a(n), s(n + 1);
  for (int i = 0; i < n; i++) {
    cin >> a.at(i);
    s.at(i + 1) = s.at(i) + a.at(i);
  }
  long ans = s.at(n);
  for (int i = 0; i < n; i++) {
    ans = min(ans, abs(2 * s.at(i) - s.at(n)));
  }
  cout << ans << endl;
}


Measured memory_bytes: 3328
#include<iostream>
#include<algorithm>
using namespace std;
int a[200000];
int main()
{
  int n;
  cin >> n;
  for (int i = 0; i < n; ++i)
    cin >> a[i];
  sort(a, a + n);
  reverse(a, a + n);
  long long ans = 0;
  for (int i = 1; i < n; ++i)
    ans += a[i >> 1];
  cout << ans;
  return 0;
}

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

int main() {
  int n,m;
  cin >> n>>m;
  
  int l[n+1][2] = {0};
  int p;
  string s;
  
  
  for(int i = 0;i < m;i++){
    cin >> p >> s;
    if(s == "AC" &&  l[p][0] == 0){
      l[p][0] +=1; 
    }else if(s == "WA" && l[p][0] == 0){
      l[p][1] += 1;
    }
  }
  int a,w;
  a = 0;
  w = 0;
  for(int i = 1;i < n+1;i++){
    a += l[i][0];
    if(l[i][0] > 0){
      w += l[i][1];
    }
    
    //cout << a << " " << w << endl;
  }
  
  cout << a << " " << w << endl;
 }

Measured memory_bytes: 4368
#include <bits/stdc++.h>
#define ll long long

using namespace std;

const int N = 77;
const int md = (int) 1e9 + 7;

ll dp[N];

int main() {
	int n;
	string s[2];
	cin >> n >> s[0] >> s[1];
	vector <int> v;
	for (int i = 0; i < n; i++) {
		if (s[0][i] == s[1][i]) v.push_back(1);
		else v.push_back(2), i++;
	}
	dp[0] = 6;
	if (v[0] == 1) dp[0] = 3;
	for (int i = 1; i < v.size(); i++) {
		if (v[i] == 1 && v[i - 1] == 1) dp[i] = 2 * dp[i - 1] % md;
		if (v[i] == 1 && v[i - 1] == 2) dp[i] = dp[i - 1];
		if (v[i] == 2 && v[i - 1] == 1) dp[i] = 2 * dp[i - 1] % md;
		if (v[i] == 2 && v[i - 1] == 2) dp[i] = 3 * dp[i - 1] % md;
	}
	cout << dp[(int) v.size() - 1] << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
  char s[4];
  int count=0;
  cin>>s;
  for(int i=0;i<strlen(s);i++)
  {
    if(s[i]=='+')
    count++;
    else if(s[i]=='-')
    count--;
  }
  cout<<count<<endl;
}

Measured memory_bytes: 3572
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
using namespace std;
using ll = long long;
ll gcd(ll a, ll b) { return (b == 0)? a : gcd(b,a%b);}

int main() 
{
    int n;
    cin >> n;
    ll ans = 1;
    rep(i,n) {
        int a;
        cin >> a;
        if (i==0) ans = a;
        else ans = gcd(ans, a);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#define MAX_N 9791
inline int max(int a, int b){return (a>b)? a:b;}
inline int min(int a, int b){return (a<b)? a:b;}

using namespace std;
int main(void){
    int x;
    cin >> x;
    long long x_fifth_power[MAX_N];
    for(int i=0;i<MAX_N;i++){
        long long t = (long long)i;
        x_fifth_power[i]=t*t*t*t*t;
    }
    int i,j;
    bool found=false;
    for(i=0;i<MAX_N;i++){
        for(j=i+1;j<MAX_N;j++){
            long long lhs = x_fifth_power[j] - x_fifth_power[i];
            if(lhs==x){
                found=true;
                break;
            }
        }
        if(found) break;
    }
    if(found){
        cout << j << " " << i << endl;
        return 0;
    }
    for(i=0;i<MAX_N;i++){
        for(j=i+1;j<MAX_N;j++){
            long long lhs = x_fifth_power[j] + x_fifth_power[i];
            if(lhs==x){
                found=true;
                break;
            }
        }
        if(found) break;
    }
    cout << j << " " << -i << endl;
    return 0;
}

Measured memory_bytes: 3712
<?php

$inputs = explode(' ',trim(fgets(STDIN)));
$boundInputs = explode(' ',trim(fgets(STDIN)));

$total = 0;
$count = 1;

foreach($boundInputs as $bound){

    $total += $bound;

    if($total > $inputs[1]){
        break;
    }

    $count++;

}

print $count;

Measured memory_bytes: 4728
def solve():
    while 1:
        try:
            A, B = list(map(int, input().split(" ")))
            S = list(input())
            if S[A] != "-":
                print("No")
                raise EndLoop

            for a in S[:A]:
                if not 48 <= ord(a) <= 57:
                    print("No")
                    raise EndLoop

            for b in S[A + 1:]:
                if not 48 <= ord(b) <= 57:
                    print("No")
                    raise EndLoop

            print("Yes")
            break

        except:
            break


solve()

Measured memory_bytes: 3060
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define ALL(x) (x).begin(), (x).end()
typedef long long ll;

int main(){
  int n;
  cin >> n;
  int ans = 0;
  for (int i = n; i > 0; i--){
    string str = to_string(i);
    if (str.size() % 2 == 1){
      ans++;
    }
  }
  cout << ans << "\n";
}


Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<stdlib.h>
#include<algorithm>
#include<vector>
#include<string.h>
#include<math.h>
#include<map>
#include<iomanip>
#include<queue>

using namespace std;

const long long inf = 1e9 + 7;

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

	vector<long long> dp(W + 1 , 0);
	
	for(int i = 0; i < n; i++){
		int w , v;
		cin >> w >> v;
		for(int j = W; j >= 0; j--){
			if(j - w >= 0)
				dp[j] = max(dp[j] , dp[j - w] + v);
		}
	}
	
	long long ans = 0;
	for(int i = 0; i <= W; i++){
		//cout << i << " : " << dp[i] << endl;
		ans = max(ans , dp[i]);
	}

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

Measured memory_bytes: 3984
N, Y = tuple(map(int, input().split(' ')))
result = "-1 -1 -1"
for i in range(0, N + 1):
    # x + y = N - i , 10000x + 5000y = Y - 1000i
    # x = [ (Y - 1000i) / 5000 ] - (N - i)
    # y = 2 * (N - i) - [ (Y - 1000i) / 5000 ]
    t = (Y - 1000 * i) % 5000

    if t == 0:
        x = int(((Y - 1000 * i) / 5000) - (N - i))
        y = int((N - i) - x)

        if x >= 0 and y >= 0:
            result = "{0} {1} {2}".format(x, y, i)
            break

print(result)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define ll long long int 
#define double /*long*/ double
#define endl '\n'
#define vll vector<ll>
#define pll pair<ll,ll>
#define vpll vector<pll>
#define vppll vector<pair<pll,pll>>
#define mp make_pair
#define pb push_back
#define mapll map<ll,ll>
#define fir first
#define sec second
#define _cin ios_base::sync_with_stdio(0);  cin.tie(0);
#define fo(i,b) for(i=0;i<b;i++)
#define repa(i,a,b) for(i=a;i<b;i++)
#define repb(i,a,b) for(i=a;i>=b;i--)
#define all(x) (x).begin(), (x).end()
#define s(v) v.size()
const long long int MAX = (ll)(1e18+1);
const long long int MIN = (ll)(-1e18-1);
const long long int mod = (ll)(1e9+7);
using namespace std;

ll max(ll a,ll b,ll c) {return max(max(a, b), c);}
ll min(ll a,ll b,ll c) { return min(min(a, b), c);}
ll max(ll a,ll b) {return (a>b) ? a : b;}
ll min(ll a,ll b) {return (a<b) ? a : b;}
ll power(ll a, ll n) {ll p = 1;while (n > 0) {if(n%2) {p = p * a;} n >>= 1; a *= a;} return p;}
ll power_mod(ll a, ll n, ll mod_){ ll p=1; while(n){ if(n%2){ p=(p*a)%mod_;} n/=2; a=(a*a)%mod_;} return p%mod_;}
                                                 /*Code Begins*/
vll ans , dp;

void rec(ll i , ll score , vll& not_taken , ll msk , ll group) {
    if(i==s(not_taken)){
        ans[msk] = max(ans[msk] , score + dp[group]);
        return;
    }
    rec(i+1 , score , not_taken , msk , group);
    rec(i+1 , score , not_taken , msk ^ (1LL<<not_taken[i]) , group ^ (1LL<<not_taken[i]));
}

int main(){

    _cin;
    // cout << setprecision(15);
    ll mn = MAX, mx = MIN;
    ll n, t, m, k, i, j,  sum=0,  prev, flag=0, cnt=0;
    ll x=0, y=0, fx, tot=0, l , r;
    int TC=1;
    // cin >> TC;
while(TC--){
    cin >> n;
    int a[n][n];
    fo(i,n) fo(j,n) cin >> a[i][j];
    dp.resize(1LL<<n , 0);
    for(ll msk =0; msk < 1LL<<n; msk++){
        dp[msk]=0;
        fo(i,n){
            if(!(msk & 1LL<<i)) continue;
            repa(j,i+1,n){
                if(msk & 1LL<<j) dp[msk] += a[i][j];
            }
        }
    }
    // cout << dp[(1LL<<n) - 1] << endl;
    ans.resize(1LL<<n,0);
    for(ll msk=0; msk < 1LL<<n; msk++){
        // for(ll msk2=0; msk2< 1LL<<n; msk2++){
        //     if((msk2 & msk) == 0LL){
        //         dp[msk2|msk] = max(dp[msk2|msk] , dp[msk2] + dp[msk]);
        //     }
        // }
        vll not_taken;
        fo(i,n) {
            if(!(msk & 1LL<<i)) not_taken.pb(i);
        }
        rec(0,ans[msk] , not_taken , msk , 0);
    }
    cout << ans[(1LL<<n) - 1];
    


    
}
    return 0;
}


Measured memory_bytes: 1280
#include <algorithm>
#include <queue>
#include <iostream>
#include <string>
#include <set>
#include <map>
#include <ios>     // std::left, std::right
#include <iomanip> 
#define REP(i,n) for(ll i = 0; i < (ll)n; i++)
#define INF 1000000000000000
using namespace std;
typedef long long ll;
typedef double db;
typedef string str;
typedef pair<ll,ll> p;

int main(){
    ll n;cin>>n;
    vector<ll> v(n,0);
    REP(i,n) cin>>v[i];
    vector<int> vleft(100001,0);
    vector<int> vright(100001,0);
    REP(i,n){
        if(i%2==0){
            vleft[v[i]] = vleft[v[i]]+1;
        }else{
            vright[v[i]] = vright[v[i]]+1;
        }
    }
    vector<p> vpleft,vpright;//(count,number)
    REP(i,100001){
        vpleft.push_back(make_pair(vleft[i],i));
        vpright.push_back(make_pair(vright[i],i));
    }
    sort(vpleft.begin(),vpleft.end());
    sort(vpright.begin(),vpright.end());
    ll ans;
    if(vpright[100000].second != vpleft[100000].second){
        ans = n - vpright[100000].first - vpleft[100000].first;
    }else{
        ans = n - vpright[100000].first - vpleft[100001-2].first;
        ans = min(ans, n - vpright[100001-2].first - vpleft[100000].first);
    }
    cout<< ans<<endl;
}

Measured memory_bytes: 6124
// ********* Assalamualaikum****** IN the name of my Almighty****:):)***

#include<bits/stdc++.h>

using namespace std;

#define suni ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)

#define endl "\n"

#define f(i,a,b) for(int i=a;i< b;i++)

#define ff(i,a,b) for(int i= a;i>=b;i--)

#define T int t; cin >>t; while(t--)

#define vi  vector<int>

#define vll vector<long long>

#define vs vector<string>

#define vp vector<pair

#define pii pair<int,int>

#define pb push_back

#define mk make_pair

#define b(a) a.begin(),a.end()

#define rb(a) a.rbegin(),a.rend()

#define I  int

#define ll long long

#define st string

#define C char

#define mn int main()

#define fa(u,v) for(auto u:v)

mn

{

    suni;

    I n;

    cin>>n;

    if(n>=30) puts("Yes");

    else puts("No");

}

//*******Happy Coding*******???******

Measured memory_bytes: 3624
//no one wants to die,yet death is the destination we all share 
// don't think you are,know you are!!

#include<bits/stdc++.h>
using namespace std;
 
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define ll long long 
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define rep(i,n) for(i=0;i<n;i++)
#define forn(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define for1(i, n) for (ll i = 1; i <= (ll)(n); ++i)
#define ford(i, n) for (ll i = (ll)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (ll i = (ll)(a); i <= (ll)(b); ++i)
#define fora(it,x) for(auto it:x)
#define PI 3.14159265
#define sync ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define endl "\n"
 
typedef pair<ll, ll> pii;
typedef vector<ll> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long i64;
typedef vector<i64> vi64;
typedef vector<vi64> vvi64;
typedef pair<i64, i64> pi64;
typedef long double ld;
 
template<class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }

ll a[2*100002];
int main(){
	ll n,ans=0;
	cin>>n;
	forn(i,n) cin>>a[i];
	forn(i,n-1){
		ll te=max(a[i]-a[i+1],(ll)0);
		ans+=te;
		a[i+1]+=te;
	}
	cout<<ans;
}

Measured memory_bytes: 5180
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, j, n) for (ll i = j; i < n; i++)
#define all(x) (x).begin(),(x).end()
#define INF (1000000000)
#define MOD (1000000007)
#define MAX (100000)
#define pii pair<int, int>

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

class XY{
public:
  ll x, y;
  XY() {x = y = 0;}
  XY(ll u, ll v) {x = u; y = v;}
};

template<typename T1, typename T2>
void chmin(T1 &a, T2 b) {if(a > b) a = b;}
template<typename T1, typename T2>
void chmax(T1 &a, T2 b) {if(a < b) a = b;}

template<typename T1, typename T2>
T1 mypow(T1 a, T2 n){
  if(n == 0) return 1;
  if(n == 1) return a;
  if(n % 2) return a * mypow(a, n - 1);
  T1 tmp = mypow(a, n / 2);
  return tmp * tmp;
}

template<typename T>
int BS(vector<T> V, int left, int right, T key){
  int mid = (left + right) / 2;
  if(V[mid] <= key) left = mid;
  else right = mid;
  if(right - mid == 1) return left;
  else return BS(V, left, right, key);
}

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

void Main(){
  int N; cin >> N;
  vector<int> A(N);
  rep(i, 0, N) cin >> A[i];
  sort(all(A));
  int a1 = A[N - 1];
  int a2 = A[0];
  rep(i, 0, N - 1){
    if(abs(A[i] * 2 - a1) < abs(a2 * 2 - a1)) a2 = A[i];
  }
  cout << a1 << " " << a2;
}

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

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

  Main();
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod=1e9+7;
ll fac[200005];
ll qpow(ll a,ll b){
	ll ans=1;
	while(b){
		if(b&1)
			ans=ans*a%mod;
		a=a*a%mod;
		b>>=1;
	}
	return ans;
}
ll inv(ll a){//mod为素数
	return qpow(a,mod-2);
}
ll C(ll n,ll m){
	return fac[n]*inv(fac[m])%mod*inv(fac[n-m])%mod;
}
int main(){
	ll n,a,b,c;
	scanf("%lld%lld%lld%lld",&n,&a,&b,&c);
	fac[0]=1;
	for(ll i=1;i<2*n;i++)
		fac[i]=(fac[i-1]*i)%mod;
	ll tmpa,tmpb,tmpc;
	tmpa=a*inv(a+b)%mod;
	tmpb=b*inv(a+b)%mod;
	tmpc=100*inv(100-c)%mod;	
	ll ans=0;
	for(ll i=0;i<n;i++){
		ll y=tmpc*(n+i)%mod*C(n+i-1,i)%mod;
		ll p=(qpow(tmpa,n)*qpow(tmpb,i)%mod+qpow(tmpa,i)*qpow(tmpb,n)%mod)%mod;
		ans=ans+p*y%mod;
		ans%=mod;
	}
	printf("%lld",ans);	
} 

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
typedef long long ll;
typedef pair<int, int> pii;
int main() {
    int n; cin >> n;
    vector<vector<pii>> f(n);
    rep(i, n){
        int a; cin >> a;
        rep(j ,a){
            pii p; cin >> p.first >> p.second;
            p.first--;
            f.at(i).push_back(make_pair(p.first, p.second));
        }
    }
    int count = 0;
    for(int bit = 0; bit < (1 << n);bit++){
        vector<bool> h(n);
        bool flag = true;
        int temp = 0;
        for(int i = 0; i < n; i++){
            if(bit >> i & 1) h.at(i) = 1;
        }
        for(int j = 0; j < n; j++){
            if(h.at(j) == 1){
                for(int k = 0; k < f.at(j).size(); k++){
                    if(f.at(j).at(k).second != h.at(f.at(j).at(k).first)) flag = false;
                }
            }
        }
        if(flag) rep(x, n){
            temp += h.at(x);
        }
        count = max(count, temp);
    }
    cout << count << endl;
    return 0;
}


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

int main() {
	int l[20];
	for (int i = 0; i < 10; i++)
		cin >> l[i];
	sort(l, l+10);
	cout << l[9] << endl << l[8] << endl << l[7] << endl;
	char c;
	cin >> c;
}

Measured memory_bytes: 3092
#include<iostream>
#include<string>
using namespace std;
typedef long long ll;
int main(){
  ll h,w,l;
  ll i,j,k;
  ll dp[200][200][4]={{{}}};
  string st[200];
  char c[]={'E','S','W','N'};
  ll rx,ry,rd;
  ll ax[]={1,0,-1,0};
  ll ay[]={0,1,0,-1};
  bool f;
  ll s;
  while(cin>>h>>w>>l,h||w||l){
    for(i=0;i<=h+1;i++) st[i]="";
    for(i=0;i<w+2;i++) st[0]+="#";
    for(i=1;i<=h;i++) {
      cin >> st[i];
      st[i]="#"+st[i]+"#";
    }
    for(i=0;i<w+2;i++) st[h+1]+="#";
    rx=0;ry=0;rd=0;
    for(i=1;i<=h;i++){
      for(j=1;j<=w;j++){
	for(k=0;k<4;k++){
	  if(st[i][j]==c[k]){
	    st[i][j]='.';
	    ry=i;rx=j;rd=k;
	  }
	}
      }
    }
    fill(dp[0][0],dp[104][104],-1);
    f = true;
    for(i=1;i<=l;i++){
      while(st[ry+ay[rd]][rx+ax[rd]]=='#'){
	rd=(rd+1)%4;
      }
      if(st[ry+ay[rd]][rx+ax[rd]]=='.'){
	rx+=ax[rd];ry+=ay[rd];
      }
      if(dp[ry][rx][rd]==-1){
	dp[ry][rx][rd]=i;
      }else if(f){
	s = i - dp[ry][rx][rd];
	l=i+(l-i)%s;
	f=false;
      }
    }
    cout << ry << ' ' << rx << ' ' << c[rd] << endl;
  }
  return 0;
}

Measured memory_bytes: 2496
#include <stdio.h>
#define MAX 105

int queue[100000],g[MAX][MAX],head=0,tail=0,cost[MAX];
void enqueue(int);
int dequeue(void);
void bfs();

int main(){
  int n,i,j,u,k;
  scanf("%d",&n);
  for(i=1;i<=n;i++){
    cost[i]=-1;
    scanf("%d%d",&u,&k);
    for(j=1;j<=k;j++){
      scanf("%d",&g[u][j]);
    }
    g[u][j]=-1;
  }
  bfs();
  for(i=1;i<=n;i++) printf("%d %d\n",i,cost[i]);
  return 0;
}
void enqueue(int id){
  queue[tail]=id;
  tail++;
}
int dequeue(){
  if(head==tail) return -1;
  return queue[head++];
}
void bfs(){
  int id,i;
  enqueue(1); cost[1]=0;
  while((id=dequeue())!=-1){
    for(i=1;g[id][i]!=-1;i++){
	if(cost[g[id][i]]==-1){
	  cost[g[id][i]]=cost[id]+1;
	  enqueue(g[id][i]);
	}
    }
  }
}



Measured memory_bytes: 2072
N = int(input())
S = [""] * N
for i in range(N):
    S[i] = input()

M = int(input())
T = [""] * M
for i in range(M):
    T[i] = input()

S = {s: S.count(s) for s in S}
T = {t: T.count(t) for t in T}

ans = 0
for s in S:
    adv = S[s] - T.get(s, 0)
    ans = max(ans, adv)
print(ans)


Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

int main(int argc, char const *argv[]) {
  int n;
  string s;
  cin >> n;
  cin >> s;
  int ans = 0;
  for (size_t i = 1; i < n; i++) {
    int cnt = 0;
    vector<char> svec = {};
    for (size_t j = 0; j < i; j++) svec.emplace_back(s[j]);
    sort(svec.begin(), svec.end());
    svec.erase(unique(svec.begin(), svec.end()), svec.end());
    for (size_t j = 0; j < svec.size(); j++) {
      if (s.substr(i,n-i).find(svec[j]) != string::npos) cnt++;
    }
    if (cnt >= ans) ans = cnt;
  }
  cout << ans << endl;
  return 0;
}


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

int main(){
  int A,B,a,n,x1,x2,x3,x4;
  int count=0;
  cin>>A>>B;
  n=B-A+1;
  a=A;
  for(int i=0;i<n;i++){
    x4=a%10;
    a=a/10;
    x3=a%10;
    a=a/100;
    x2=a%10;
    a=a/10;
    x1=a%10;
    if(!(x1-x4||x2-x3)){
      count+=1;
    }
    a=A+i+1;
  }
  cout<<count<<endl;
}
    


Measured memory_bytes: 764
#include <bits/stdc++.h>
#define pi 3.14159
using namespace std;

int main()
 {
 	long long int n,i,k,j,ans;
 	cin>>n;
 	if(n<=1)
 		ans=2;
 	else if(n==2)
 		ans=2;
 	else
 	{
	 
 	for(i=n;i<=pow(10,6);i++)
 		{
 			k=0;
 			for(j=2;j<=n/2;j++)
 				{
 					if(i%j==0)
					 	k++;	
				 }
			if(k==0)
			{
				ans=i;
				break;
			}
			
		 }
	}
		cout<<ans<<endl;
 }

Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
long long m=1e9+7;
long long fact[1000001],inv[1000001];

long long modRecursive(long long a,long long b,long long c)
{
	if(b == 0) return 1;
	if(b%2 ==0) return modRecursive((a*a)%c,b/2,c);
	else return ((a%c)*(modRecursive((a*a)%c,b/2,c)))%c;
}

int main()
{
	int n,x=0;
	cin>>n;
	int a[n];
	for(int i=0; i<n; i++)
		cin>>a[i];
	int b[51];
	for(int i=0; i<n; i++)
		b[a[i]]=i+1;
	for(int i=1; i<=n; i++)
		if(b[i]!=i) x++;
	if(x==0 || x==2) cout<<"YES\n";
	else cout<<"NO\n";
    return 0;
}


Measured memory_bytes: 256
def main():
  n = int(input())
  a = [int(x) for x in input().split()]
  ls = [[0,int(x)+1] for x in range(n)]
  for i in range(n):
    ls[i][0] = a[i]
  ls = sorted(ls,key = lambda x:x[0])
  for i in range(n):
    print(ls[i][1],end=" ")
  print("\n")

if __name__ == "__main__":
	main()

Measured memory_bytes: 69164
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i < (n); i++)
#define ALL(a) a.begin(), a.end()
#define RALL(a) a.rbegin(), a.rend()
using namespace std;
using ll = long long;
const ll MOD = 1000000007;
const ll INF = MOD * MOD;
const int inf = (1<<29);

int main() {

    int sx, sy, tx, ty;
    cin >> sx >> sy >> tx >> ty;

    int sax = tx - sx;
    int say = ty - sy;

    // 1
    cout << string(say, 'U') << string(sax, 'R');
    // 2
    cout << string(say, 'D') << string(sax, 'L');
    // 3
    cout << 'L' << string(say + 1, 'U') << string(sax + 1, 'R') << 'D';
    // 4
    cout << 'R' << string(say + 1, 'D') << string(sax + 1, 'L') << 'U';

    cout << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<vector>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<time.h>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double EPS=1e-10;
using namespace std;
typedef long long ll;
typedef vector<int> vi;
#define MAX 10000000
bool sosu[MAX];
int main(){
	memset(sosu,true,MAX);
	for(int i=4;i<MAX;i+=2)sosu[i]=false;
	for(int i=3;i<MAX;i+=2)
	for(int j=3*i;j<MAX;j+=2*i)sosu[j]=false;
	int n,b;
	while(cin>>n>>b,n||b){
		vector<int>in(n);
		rep(i,n)cin>>in[i];
		vector<bool>h(b+10);
		h[0]=true;
		rep(i,n){
			rep(j,b-in[i]+1)if(h[j])h[j+in[i]]=true;
		}
		for(int i=b;i>=0;i--){
			if(!i)cout<<"NA"<<endl;
			else if(sosu[i]&&h[i]){
				cout<<i<<endl;
				break;
			}
		}
	}
}

Measured memory_bytes: 11092
from fractions import gcd
from functools import reduce

lcm = lambda a, b: a * b // gcd(a, b)

N, M, *A = map(int, open(0).read().split())

Y = reduce(lcm, A)

if any((Y // a) % 2 == 0 for a in A):
    print(0)
    quit()

print((1 + M // (Y // 2)) // 2)

Measured memory_bytes: 16144
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		sc.close();
		
		if(n<10) {
			System.out.println(n);
			return;
		}
		if(n<100) {
			System.out.println(9);
			return;
		}
		if(n<1000) {
			System.out.println(n-99+9);
			return;
		}
		if(n<10000) {
			System.out.println(909);
		return;
		}
		if(n<100000) {
			System.out.println(n-9999+909);
			return;
		}
		System.out.println(90909);
	}

}


Measured memory_bytes: 21844
from collections import defaultdict

N = int(input())
S = input()
d = defaultdict(list)
for i in range(N):
    d[int(S[i])].append(i)

ans = 0
for i in range(11):
    for j in range(11):
        if d[i] and d[j]:
            left = d[i][0]
            right = d[j][-1]
            if(left+1 < right):
                for k in range(11):
                    for elem in d[k]:
                        if left < elem < right:
                            ans += 1
                            break


print(ans)




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

typedef long long ll;
//const int INF = 2e9;
//const ll INF = 9e18;


int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int N;
    cin >> N;
    vector<int> x(N), y(N);
    for (int i=0;i<N;i++) cin >> x[i] >> y[i];
    int ans = N;
    for (int i=0;i<N;i++){
        for (int j=0;j<N;j++){
            if (x[i] == x[j] && y[i] == y[j]) continue;
            int cnt = N;
            int p = x[j] - x[i];
            int q = y[j] - y[i];
            for (int k=0;k<N;k++){
                for (int l=0;l<N;l++){
                    if (x[l]-x[k] == p && y[l]-y[k]==q) cnt--;
                }
            }
            ans = min(ans,cnt);
        }
    }
    cout << ans << "\n";
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<sstream>
#include<cmath>
#include<numeric>
#include<map>
#include<stack>
#include<queue>
#include<list>
#include<set>
#include<cstring>
using namespace std;

int main() {

  int n; cin >> n;
  vector<int> l(n);
  for(int i=0; i<n; i++) cin >> l[i];
  int m = *max_element(l.begin(), l.end());
  int s = accumulate(l.begin(), l.end(), -m);
  if(m < s) cout << "Yes" << endl;
  else cout << "No" << endl;

  return 0;
}



///


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

int main() {
  int H,W;
  cin >> H >> W;
  
  vector<string> A(H);
  vector<char> B(1,'#');
  
  for(int i=0;i<(W+2);i++){
     cout<<B[0];
  }
  cout<<endl;
  for(int i=0;i<H;i++){
     cin>>A[i];
    cout<<'#'<<A[i]<<'#'<<endl;
  }
  for(int i=0;i<(W+2);i++){
     cout<<B[0];
  }
  cout<<endl;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC_146
{
    class Program
    {
        static void Main(string[] args)
        {
            String S = Console.ReadLine();
            int day = 0;

            switch (S)
            {
                case "SUN":
                    day = 7;
                    break;
                case "MON":
                    day = 6;
                    break;
                case "TUE":
                    day = 5;
                    break;
                case "WED":
                    day = 4;
                    break;
                case "THU":
                    day = 3;
                    break;
                case "FRI":
                    day = 2;
                    break;
                case "SAT":
                    day = 1;
                    break;

            }

            Console.WriteLine(day);
        }
    }
}


Measured memory_bytes: 13268
#define _GLIBCXX_DEBUG

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

constexpr ll INF = 1e16;

#define rep(i, N) for(ll i=0; i<N; ++i)

ll max(ll a, ll b) {return a < b ? b : a; }
ll min(ll a, ll b) {return a > b ? b : a; }
double maxf(double a, double b) { return a < b ? b : a; }

int main() {
  int k, n;
  cin>>k>>n;
  ll a[n];
  for(int i = 0; i < n; i++) cin>>a[i];

  int num = k - a[n-1] + a[0];

  for(int i = 0; i < n-1; i++){
    num = max(num, a[i+1] - a[i]);
  }

  cout<<k - num<<endl;

  return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<vector>
#include<stdio.h>
#include<cstring>
#include<math.h>
#include<map>
#include<bitset>
#include<iomanip>
#include<queue>
#include<functional>
#include<stack>
#include<tuple>
#include<cassert>
using namespace std;

#define rep(i, n) for (long long i = 0; i < (long long)(n); ++i)
using P = pair<long long, long long>;

template <typename T>
vector<T> compress(vector<T> &C1, vector<T> &C2) {
    vector<T> vals;
    long long K = (long long)C1.size();
    for (long long i = 0; i < K; i++) {
        for (T d = 0; d < 1; d++) {  // その位置と、一つ隣を確保(隣を確保しないと空白が埋まってしまうことがある)
            T tc1 = C1[i] + d;
            T tc2 = C2[i] + d;
            vals.push_back(tc1);
            vals.push_back(tc2);
        }
    }
    // ソート
    sort(vals.begin(), vals.end());
    // 隣り合う重複を削除(unique), 末端のゴミを削除(erase)
    vals.erase(unique(vals.begin(), vals.end()), vals.end());
    for (long long i = 0; i < K; i++) {
        C1[i] = lower_bound(vals.begin(), vals.end(), C1[i]) - vals.begin();
        C2[i] = lower_bound(vals.begin(), vals.end(), C2[i]) - vals.begin();
    }
    return vals;
}

long long a[4000][4000] = {0};

int main() {
  long long N;
  cin >> N;
  vector<long long> x1, x2;
  vector<long long> y1, y2;
  rep(i, N) {
    long long p, q, r, s;
    cin >> p >> q >> r >> s;
    x1.push_back(p);
    y1.push_back(q);
    x2.push_back(r);
    y2.push_back(s);
  }
  vector<long long> x;
  vector<long long> y;
  x = compress(x1, x2);
  y = compress(y1, y2);

  // rep(i, N) {
  //   for(long long p = x1[i]; p < x2[i]; p++) {
  //     for(long long q = y1[i]; q < y2[i]; q++) {
  //       a[p][q] += 1;
  //     }
  //   }
  // }
  rep(i, N) {
    a[x1[i]][y1[i]] += 1;
    a[x1[i]][y2[i]] += -1;
    a[x2[i]][y1[i]] += -1;
    a[x2[i]][y2[i]] += 1;  
  }
  long long ans = 0;
  rep(i, x.size()) {
    rep(j, y.size()-1) {
      a[i][j+1] += a[i][j];
    }
  }
  rep(i, x.size()-1) {
    rep(j, y.size()) {
      a[i+1][j] += a[i][j];
    }
  }
  rep(i, x.size()-1) {
    rep(j, y.size()-1) {
      if(a[i][j] > 0) {
        ans += (x[i+1]-x[i]) * (y[j+1]-y[j]);
      }
      // cout << a[i][j] << " ";
    }
    // cout << endl;
  }
  
  cout << ans << endl;
  // rep(i, x1.size()) {
  //   cout << x1[i] << " "; 
  // }
  // cout << endl;
  // rep(i, y1.size()) {
  //   cout << y1[i] << " "; 
  // }
  // cout << endl;
  // rep(i, x2.size()) {
  //   cout << x2[i] << " "; 
  // }
  // cout << endl;
  // rep(i, y2.size()) {
  //   cout << y2[i] << " "; 
  // }
  // cout << endl;
  return 0;
}


Measured memory_bytes: 128264
A,B,M=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
l=[[int(i) for i in input().split()] for j in range(M)]
m=min(a)+min(b)
for x in l:
    m=min(m,a[x[0]-1]+b[x[1]-1]-x[2])
print(m)

Measured memory_bytes: 32556