akhauriyash/Code-Regression huggingface dataset:
import sys
input = sys.stdin.readline

N, M, K = map(int, input().split())
friends_table = [[] for i in range(N)]
for _ in range(M):
    a, b = map(int, input().split())
    friends_table[a-1] += [b-1]
    friends_table[b-1] += [a-1]

group_list = [i for i in range(N)]
friends_candidate = [[] for i in range(N)]

for i in range(N):
    # すでにDFS済み
    if i != group_list[i]:
        continue
    next_stack = [i]
    friend = [i]
    while next_stack:
        u = next_stack.pop(-1)
        for v in friends_table[u]:
            # 訪問済み
            if i == group_list[v]:
                continue
            friend += [v]
            group_list[v] = i
            next_stack += [v]
    for f in friend:
        friends_candidate[f] = friend

blocks_table = [[] for i in range(N)]
for _ in range(K):
    a, b = map(int, input().split())
    if group_list[a-1] == group_list[b-1]:
        blocks_table[a-1] += [b-1]
        blocks_table[b-1] += [a-1]

for i in range(N):
    print(len(friends_candidate[i]) - len(friends_table[i]) - len(blocks_table[i])-1)

Measured memory_bytes: 51884
#include <algorithm>
#include <bitset>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

typedef long long ll;

#define rep(i, n) for (ll i = 0; i < (ll)n; ++i)
#define INF 10e12
#define MOD 1000000000 + 7
#define MAX 51000
#define all(x) (x).begin(), (x).end()
#define MX(x) *max_element(all(x))
#define MN(x) *min_element(all(x))

using namespace std;

int main(void)
{
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    char a;
    cin >> a;
    rep(i, 26)
    {
        if (a == 'a' + i)
            cout << 'a' << endl;
    }
    rep(i, 26)
    {
        if (a == 'A' + i)
            cout << 'A' << endl;
    }
}

Measured memory_bytes: 3648
#include <bits/stdc++.h>
#define REP(i, a, n) for(ll i=a; i<n; i++)
#define RREP(i, a, n) for(ll i=n-1; i>=a; i--)
typedef long long ll;
const ll mod =1e9+7;
const ll inf =1e18;
using namespace std;

ll a, b, k;
int main() {
    cin>>a>>b>>k;

    vector<ll> diva, divb;
    set<ll> st;
    REP(i, 1, a+1){
        if(a%i==0) diva.emplace_back(i);
    }
    REP(i, 1, b+1){
        if(b%i==0) divb.emplace_back(i);
    }

    REP(i, 0, diva.size()){
        REP(j, 0, divb.size()){
            if(diva[i]==divb[j]){
                st.insert(diva[i]);
            }
        }
    }

    ll cnt=st.size();
    for(auto itr : st){
        if(cnt==k){
            cout<<itr<<endl;
            break;
        }
        cnt--;
    }

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
 
/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
    sizeは(int)とキャストしよう
    ごちゃごちゃ場合分けを考える前に全探索は考えましたか？
*/
 
const ll mod = 1e9+7;

void chmod(ll &M){
    if(M >= mod) M %= mod;
    else if(M < 0){
        M += (abs(M)/mod + 1)*mod;
        M %= mod;
    }
}

ll modpow(ll x, ll n){
    if(n == 0) return 1;

    ll res = modpow(x, n/2);
    if(n%2 == 0) return res*res%mod;
    else return res*res%mod*x%mod;
}

ll power(ll x, ll n){
    if(n == 0) return 1;

    ll res = power(x, n/2);
    if(n%2 == 0) return res*res;
    else return res*res*x;
}

int getl(int i, int N) { return i==0? N-1:i-1; };
int getr(int i, int N) { return i==N-1? 0:i+1; };

/* <--------------------------------------------> */

typedef tuple<ll, ll, ll> T;
// get<K>(tuple型の変数)


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

    int n, k; cin >> n >> k;
    vector<ll> a(n+1);
    for(int i=1; i<=n; ++i) cin >> a[i];

    vector<vector<ll>> dp(110, vector<ll>(100005, 0));
    vector<ll> cum(100005, 0);
    dp[0][0] = 1;
    for(int i=1; i<=n; ++i){
        cum[0] = 0;
        for(int j=1; j<=k+1; ++j) cum[j] = (cum[j-1]+dp[i-1][j-1])%mod;
        // cum[j] = dp[i-1][0]+...+dp[i-1][j-1]
        for(int j=0; j<=k; ++j) dp[i][j] = (cum[j+1]-cum[max(0LL, j-a[i])]+mod)%mod;
    }

    cout << dp[n][k] << endl;

    return 0;
}

Measured memory_bytes: 87296
#include <bits/stdc++.h>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

int n, m;

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

Measured memory_bytes: 256
#include <stdio.h>

int main()
{
	int H, W, N, sr, sc;
	char S[200001], T[200001];
	scanf("%d %d %d", &H, &W, &N);
	scanf("%d %d", &sr, &sc);
	scanf("%s", S);
	scanf("%s", T);
	
	int i, l = 0, r = W + 1, t = 0, b = H + 1;
	for (i = N - 1; i >= 0; i--) {
		if (T[i] == 'R' && l > 0) l--;
		else if (T[i] == 'L' && r < W + 1) r++;
		else if (T[i] == 'D' && t > 0) t--;
		else if (T[i] == 'U' && b < H + 1) b++;
		if (S[i] == 'L') l++;
		else if (S[i] == 'R') r--;
		else if (S[i] == 'U') t++;
		else if (S[i] == 'D') b--;
		if (r == l + 1 || b == t + 1) break;
	}
	
	if (sc <= l || sc >= r || sr <= t || sr >= b) printf("NO\n");
	else printf("YES\n");
	fflush(stdout);
	return 0;
}

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

int main()
{
	long long a[101][101],b[101][101];
	long long c[101][101];
	memset(a,0,sizeof(a));
	memset(b,0,sizeof(b));
	memset(c,0,sizeof(c));
	int n,m,l;
	cin >> n >> m >> l;

	rep(i,n)
	{
		rep(j,m)
		{
			cin >> a[i][j];
		}
	}

	rep(i,m)
	{
		rep(j,l)
		{
			cin >> b[i][j];
		}
	}

	rep(i,n)
	{
		rep(j,l)
		{
			rep(k,m)
			{
				c[i][j] += a[i][k] * b[k][j];

			}
		}
	}

	rep(i,n)
	{
		rep(j,l)
		{
			if(j == 0)
			{
				cout << c[i][j];
			}
			else 
			{
				cout << " " << c[i][j];
			}
		}
		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 1412
#include<bits/stdc++.h>
using namespace std;
#define lson now<<1
#define rson now<<1|1
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
typedef long long ll;
typedef pair<int, int> pii;
const int mod=1e9+7;
const double eps = 1e-10;
const double pi=acos(-1.0);
const int maxn=2e5+10;
const ll inf=0x3f3f3f3f;
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    int n;
    cin>>n;
    map<int,int> m;
    for(int i=1,x;i<=n;i++){
        cin>>x;
        if(m[x]){cout<<"NO"<<endl;return 0;}
        m[x]++;
    }
    cout<<"YES"<<endl;
}



Measured memory_bytes: 9600
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) begin(v),end(v)
#define fi first
#define se second
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
using ll = long long;
using pii = pair<int, int>;
constexpr ll INF = 1ll<<30;
constexpr ll longINF = 1ll<<60;
constexpr ll MOD = 1000000007;
constexpr bool debug = 0;
//---------------------------------//

template<int M>
struct ModInt {
public:
	using value_type = long long;
	
	ModInt(value_type val = 0) : val(val < 0 ? (M - (-val % M)) % M : val % M) {}
	
	explicit operator bool() const noexcept { return val; }
	bool operator ==(const ModInt & rhs) const noexcept { return val == rhs.val; }
	bool operator !=(const ModInt & rhs) const noexcept { return !(*this == rhs); }
	ModInt operator +() const noexcept { return ModInt(*this); }
	ModInt operator -() const noexcept { return ModInt(0) -= *this; }
	ModInt operator +(const ModInt & rhs) const noexcept { return ModInt(*this) += rhs; }
	ModInt operator -(const ModInt & rhs) const noexcept { return ModInt(*this) -= rhs; }
	ModInt operator *(const ModInt & rhs) const noexcept { return ModInt(*this) *= rhs; }
	ModInt operator /(const ModInt & rhs) const noexcept { return ModInt(*this) /= rhs; }
	
	ModInt & operator +=(const ModInt & rhs) noexcept {
		val += rhs.val;
		if (val >= M) val -= M;
		return *this;
	}
	ModInt & operator -=(const ModInt & rhs) noexcept {
		if (val < rhs.val) val += M;
		val -= rhs.val;
		return *this;
	}
	ModInt & operator *=(const ModInt & rhs) noexcept {
		val = val * rhs.val % M;
		return *this;
	}
	ModInt & operator /=(const ModInt & rhs) noexcept {
		*this *= rhs.inverse();
		return *this;
	}
	
	ModInt pow(value_type n) const {
		ModInt res = 1, x = val;
		if (n < 0) { x = x.inverse(); n = -n; }
		while (n) { if (n & 1) res *= x; x *= x; n >>= 1; }
		return res;
	}
	
	ModInt inverse() const {
		long long a = val, a1 = 1, a2 = 0, b = M, b1 = 0, b2 = 1;
		while (b > 0) {
			value_type q = a / b, r = a % b;
			value_type nb1 = a1 - q * b1, nb2 = a2 - q * b2;
			a = b; b = r;
			a1 = b1; b1 = nb1;
			a2 = b2; b2 = nb2;
		}
		assert(a == 1);
		return a1;
	}
	
	const value_type & get() const noexcept { return val; }
	static decltype(M) get_mod() noexcept { return M; }
	
	friend std::ostream & operator <<(std::ostream & os, const ModInt & rhs) { return os << rhs.val; }
	friend std::istream & operator >>(std::istream & is, ModInt & rhs) {
		value_type x;
		is >> x;
		rhs = ModInt(x);
		return is;
	}
private:
	value_type val;
};
using mint = ModInt<MOD>;

int main() {
	int N, X;
	cin >> N >> X;
	vector<int> S(N);
	REP(i, N) scanf("%d", &S[i]);
	sort(ALL(S));
	
	vector<vector<mint>> dp(N + 1, vector<mint>(X + 1));
	REP(i, X + 1) dp[0][i] = i;
	
	FOR(i, 1, N + 1) {
		REP(j, X + 1) {
			dp[i][j] = dp[i - 1][j] * (i - 1);
			dp[i][j] += dp[i - 1][j % S[i - 1]];
		}
	}
	
	cout << dp[N][X] << endl;
	return 0;
}


Measured memory_bytes: 158592
x, y = map(int, input().split())

prise = {3: 100000, 2: 200000, 1: 300000}
ans = 0
if x in (1, 2, 3):
    ans += prise[x]
if y in (1, 2, 3):
    ans += prise[y]

print(ans + 400000 if x == y == 1 else ans)

Measured memory_bytes: 3060
N = int(input())
Ts = [int(input()) for i in range(N)]
 
# 最大公約数
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a
 
# 最大公倍数
def lcm(a, b):
    return a * b // gcd (a, b)
 
def solve(Ts):
    if len(Ts) == 1:
        print(Ts[0])
    
    else:
        Ts_temp = []
        for i in range(len(Ts)-1):
            Ts_temp.append(lcm(Ts[i], Ts[i+1]))
        solve(Ts_temp)
 
solve(Ts)

Measured memory_bytes: 3264
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const static ll INF = 1e9;


int main(){
    string S; cin >> S;
    for(int i = 2; i < S.size(); i+=2){
        string S_ = S.substr(0, S.size()-i);
        string S1 = S_.substr(0, S_.size()/2);
        string S2 = S_.substr(S_.size()/2);
        //cout << S_ << " " << S1 << " " << S2 << endl;

        if(S1 == S2){
            cout << S_.size() << endl;
            return 0;
        }
    }

}

Measured memory_bytes: 256
#include <stdio.h>
int main() {
	int m[6];
	int i, j, I, N;
	double f;
	scanf("%d", &N);
	for(I = 0; I < 6; ++ I) m[I] = 0;
	for(I = 0; I < N; ++ I) {
		scanf("%lf", &f);
		if(f < 165.0) {
			m[0] ++;
		} else if(f < 170) {
			m[1] ++;
		} else if(f < 175) {
			m[2] ++;
		} else if(f < 180) {
			m[3] ++;
		} else if(f < 185) {
			m[4] ++;
		} else {
			m[5] ++;
		}
	}
	for(i = 0; i < 6; ++ i) {
		printf("%d:", i + 1);
		for(j = 0; j < m[i]; ++ j) printf("*");
		printf("\n");
	}
	return 0;
}

Measured memory_bytes: 640
#include <stdio.h>
#include <math.h>

int main(void) {

  long n;
  scanf("%ld", &n);
  long a[n];
  for (long i = 0; i < n; i++) {
    scanf("%ld", &a[i]);
  }
  long mod = pow(10,9)+7;
  long sum[n];
  sum[0] = a[0];
  for (long i = 1; i < n; i++) {
    sum[i] = sum[i-1]+a[i];
    sum[i] %= mod;
  }
  long ans = 0;
  for (long i = 1; i < n; i++) {
    ans += sum[i-1]*a[i];
    ans %= mod;
  }
  printf("%ld\n", ans);

  return 0;
}

Measured memory_bytes: 4856
package main

import (
    "fmt"
)

func main() {
    var n, m, x, y int
    fmt.Scan(&n, &m, &x, &y)

    maxX := -101
    for i := 0; i < n; i++ {
        var t int
        fmt.Scan(&t)
        if t > maxX {
            maxX = t
        }
    }
    minY := 101
    for i := 0; i < m; i++ {
        var t int
        fmt.Scan(&t)
        if t < minY {
            minY = t
        }
    }

    var ok bool
    for i := x + 1; i <= y; i++ {
        if maxX < i && i <= minY {
            ok = true
        }
    }
    if ok {
        fmt.Println("No War")
    } else {
        fmt.Println("War")
    }

}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
using ll = long long;
using pii = pair<int, int>;
constexpr ll INF = 1ll<<30;
constexpr ll longINF = 1ll<<60;
constexpr ll MOD = 1000000007;
constexpr bool debug = 0;
//---------------------------------//

int main() {
	int N;
	cin >> N;
	
	vector<int> L(N);
	REP(i, N) scanf("%d", L.begin() + i);
	sort(ALL(L));
	
	ll ans = 0;
	REP(i, N) FOR(j, i + 1, N) {
		int p1 = upper_bound(ALL(L), L[j] - L[i]) - L.begin();
		int p2 = lower_bound(ALL(L), L[i] + L[j]) - L.begin();
		chmax(p1, j + 1);
		chmax(p2, j + 1);
		
		ans += p2 - p1;
	}
	
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
//Optimisations
#pragma GCC target ("avx2")
#pragma GCC optimization ("unroll-loops")
#pragma GCC optimize("O2")
//shortcuts for functions
#define pb push_back
#define mp make_pair
#define ff first 
#define ss second
#define all(v) v.begin(),v.end()
#define prec(n) fixed<<setprecision(n)
#define n_l '\n'
// make it python 
#define gcd __gcd
#define append push_back
#define str to_string
// utility functions shortcuts
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define sswap(a,b) {a=a^b;b=a^b;a=a^b;}
#define swap(a,b) {auto temp=a; a=b; b=temp;}
#define init(dp) memset(dp,-1,sizeof(dp));
#define set0(dp) memset(dp,0,sizeof(dp));
#define bits(x) __builtin_popcount(x)
#define SORT(v) sort(all(v))
#define endl "\n"
#define forr(i,n) for(ll i=0;i<n;i++)
// declaration shortcuts
typedef long long int ll;
#define int ll
// Constants
constexpr int dx[] = {-1, 0, 1, 0, 1, 1, -1, -1};
constexpr int dy[] = {0, -1, 0, 1, 1, -1, 1, -1};
constexpr ll INF = 1999999999999999997; 
constexpr int inf= INT_MAX;
constexpr int MAXSIZE = int(1e6)+5;
constexpr auto PI  = 3.14159265358979323846L;
constexpr auto oo  = numeric_limits<int>::max() / 2 - 2;
constexpr auto eps = 1e-6;
constexpr auto mod = 1000000007;
constexpr auto MOD = 1000000007;
constexpr auto MOD9 = 1000000009;
constexpr auto maxn = 100006;
//void IOfile(){
//freopen(file_name, reade_mode, stdin);
//freopen(file_name, write_mode, stdout);
//}
void fastio(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
}
int32_t main(){
	fastio();
	int n,m;
	cin>>n>>m;
	int s = 0 ;
	forr(i,m){
		int x;
		cin>>x;
		s+=x;
	}
	if(s>n) cout<<"-1";
	else cout<<n-s;
}

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

namespace CSharp_practice
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            string s = Console.ReadLine();

            for (int i = 0; i < s.Length; i++)
            {
                int x = s[i] - 'A';
                x = (x + n) % 26;
                Console.Write((char)('A' + x));
            }
            Console.WriteLine();
        }
    }
}


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

using namespace std;

char s[1005], t[1005];

int main(){
    cin>>s+1>>t+1;
    int n=strlen(s+1);
    int m=strlen(t+1);

    int res=0x3f3f3f3f;
    for(int i=1;i+m-1<=n;++i){
        int cnt=0;
        for(int j=1;j<=m;++j){
            if(s[i+j-1]!=t[j]){
                ++cnt;
            }
        }
        res=min(res,cnt);
    }

    cout<<res;

    return 0;
}


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

int main()
{
  int n;cin>>n;
  vector<int> a(3*n);
  int i;
  for(i=0;i<3*n;i++)cin>>a.at(i);
  long long ans=0;
  sort(a.begin(),a.end());
  reverse(a.begin(),a.end());
  for(i=1;i<2*n;i+=2)ans+=a.at(i);
  cout<<ans<<endl;
}


Measured memory_bytes: 1536
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using u64 = unsigned long long;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

int main() {
    int M = 1000000;
    int n;
    cin >> n;
    vector<int> a(M+1);
    int g = 0;
    for (int i = 0; i < n; ++i) {
        int x;
        scanf("%d", &x);
        a[x]++;
        g = __gcd(g, x);
    }
    int ok = 1;
    for (int i = 2; i <= M; ++i) {
        int cnt = 0;
        for (int j = i; j <= M; j += i) {
            cnt += a[j];
        }
        if(cnt >= 2){
            ok = 0;
        }
    }
    if(ok) puts("pairwise coprime");
    else if(g == 1) puts("setwise coprime");
    else puts("not coprime");
    return 0;
}

Measured memory_bytes: 7168
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
inf = 10**17
mod = 10**9 + 7

L=input().rstrip().split(" ")
a=L[0]
b=L[1]
c=L[2]
if a[-1]==b[0] and b[-1]==c[0]:
    print("YES")
else:
    print("NO")

Measured memory_bytes: 3436
n,m = map(int,input().split())
bulb = []
for i in range(m):
    bulb.append(list(map(int,input().split()))[1:])
p = list(map(int,input().split()))
# print(bulb)
# print(p)
cond = [bin(i)[2:].zfill(n) for i in range(2**n)]
# print(cond)
ans = 0
for i in range(2**n):
    cond_sw = cond[i]
    flag = True
    for j in range(m):
        tar_bulb = bulb[j]
        cnt = 0
        for k in range(len(bulb[j])):
            if cond_sw[tar_bulb[k]-1] == "1":
                cnt += 1
        if cnt % 2 != p[j]:
            flag = False
    if flag:
        ans += 1
print(ans)





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

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

    int westE = 0, westW = 0, eastE = 0, eastW = 0;
    //初期値
    char nowChar = s[0];
    for(int i=1; i<n; i++){
        if(s[i] == 'E') eastE++;
        else eastW++;
    }
    int ans = westW + eastE;
    
    for(int i=1; i<n; i++){
        if(nowChar == 'E') westE++;
        else westW++;

        nowChar = s[i]; 
        
        if(s[i] == 'E') eastE--;
        else eastW++;

        ans = min(ans, westW + eastE);
    }

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

Measured memory_bytes: 900
import random

def gcd(a,b):
        if b == 0:
                return a
        else:
                return gcd(b , a%b) 
def is_prime(q,k=50):
    q = abs(q)
    if q == 2: return True
    if q < 2 or q&1 == 0: return False

    d = (q-1)>>1
    while d&1 == 0:
        d >>= 1

    for i in range(k):
        a = random.randint(1,q-1)
        t = d
        y = pow(a,t,q)
        while t != q-1 and y != 1 and y != q-1:
            y = pow(y,2,q)
            t <<= 1
        if y != q-1 and t&1 == 0:
            return False
    return True

a, b = map(int,input().split())

c = 1
m = gcd(a,b)

i = 1
while i * i <=m:
        if a%i == 0 and b%i == 0:
                if is_prime(i):
                        c+=1
                if is_prime(m//i):
                        c+=1
        i+=1
print(c)

Measured memory_bytes: 4464
//
// Created by kashi on 27-07-2020.
//
#include<bits/stdc++.h>
using namespace std;
#define mp make_pair
#define pb push_back
#define ll long long
#define ff first
#define ss second
#define Endl endl
#define int long long
int gcd(int a,int b){
    return b?gcd(b,a%b):a;
}
bool cmps(pair<int,int>p1,pair<int,int>p2) {
    return p1.ss<p2.ss;
}
int lcm(int a, int b){
    return (a*b)/gcd(a, b);
}

int32_t main() {
    int x,k,d;
    cin>>x>>k>>d;
    x=abs(x);
    if (x/d<k){
        k-=x/d;
        x=x%d;
        if(k%2==0)
            cout<<x<<endl;
        else
            cout<<abs(x-d)<<Endl;
    }
    else  {
        x -= k * d;
        cout << x << endl;
    }
    return 0;
}


Measured memory_bytes: 3640
#include<cstdio>
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<cstdlib>
#include<bitset>
#include<utility>
#include<sstream>
#include<iomanip>
#include<ctime>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<functional>

using namespace std;
typedef long long ll;
#define MP make_pair

int main(void) {
    int n,r;

    cin>>n>>r;

    if(n>=10)cout<<r<<"\n";
    else cout<<r+100*(10-n)<<"\n";
    
    
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll          long long int
#define uu          first
#define vv          second
#define pii         pair<int,int>
#define pll         pair<ll,ll>
#define fastio      ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
using namespace std;
const int INF = 1e9;
const ll MOD = 1e9 + 7;

const int N = 1e6 + 6;

int main()  {
    fastio;
    int n;
    string s;
    cin>>n>>s;

    int frm = -1 , to = -1;

    for(int i =0 ; i < n ; i++ ) {
        frm = i;
        if(s[i] =='W') break;
    }
    for(int i = n-1 ; i >=0 ; i--) {
        to = i;
        if(s[i] == 'R') break;
    }
    if(frm == -1|| to ==-1 || frm >to) {
        cout<<0<<'\n';
        return 0;
    }

    int r = 0 , w = 0;
    for(int i = frm ; i <=to ; i++ ) {
        if(s[i] == 'R') r++;
        else w++;
    }
    int ans = min(w, r);

    // cout<<w<< " "<<r<<'\n';

    int cnt = 0;

    for(int i =0 , j = to ; i <w ; i++, j-- ) {
        if(s[j] == 'R')cnt++;
    }
    // cout<<cnt<<'\n';

    cout<<min(ans, cnt)<<'\n';
    return 0;
}

Measured memory_bytes: 3732
#include <algorithm>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
// const int INF = (1 << 30) - 1;
// const ll LL_INF = (1LL << 62) - 1;
// const ll MOD = 1e9 + 7;

int N, K;
vector<int> pi;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> N >> K;
  pi.resize(N);
  for (int i = 0; i < N; i++) {
    int tmp;
    cin >> tmp;
    pi[i] = tmp;
  }

  vector<double> cum(N + 1, 0);
  for (int i = 0; i < N; i++) {
    cum[i + 1] = cum[i];
    cum[i + 1] += (double)(pi[i] * (pi[i] + 1) / 2) / (double)(pi[i]);
  }
  double ans = 0;
  for (int i = K; i <= N; i++) {
    ans = max(ans, cum[i] - cum[i - K]);
  }

  cout << fixed << setprecision(12) << ans << endl;
  return 0;
}


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

int main(){
  int n;
  cin >> n;
  int nc=n;
  int f=0;
  for(int i=0; i<=8; i++){
    f += n%10;
    n /= 10;
  }
  if((nc/f)*f==nc)cout << "Yes";
  else cout << "No";
  return 0;
}


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

int main()
{
	long n,a,b,c,d,e,minv;
	cin>>n>>a>>b>>c>>d>>e;;
	
	minv=min(a,min(b,min(c,min(d,e))));
	
	cout<<((n%minv==0)? n/minv+4:n/minv+5)<<endl;
	
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{

#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	long a, b;
	cin >> a >> b;
	if (b >= a)
		cout << "unsafe\n";
	else
		cout << "safe\n";
	return 0;
}


Measured memory_bytes: 3632
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <string>
#include <sstream>
#define ll long long int
#define rep(i,x,y) for(int i=x;i<y;i++)
#define rel(i,x,y) for(int i=x-1;i>=y;i--)
#define all(x) x.begin(),x.end()
 
using namespace std;

int main (){
    ll A[5],N;
	ll ans=0,min=1000000000000001;
	
	cin >> N; 
    
    rep(i,0,5){
        cin >> A[i];
    }

    rep(i,0,5){
        if(min>A[i]){
            min = A[i];
        }
    }

    ans = (N/min) + 4;

    if(N%min!=0){
        ans++;
    }

    cout << ans << endl;
}


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

#define ll long long

using namespace std;

ll INF = (ll) 1e20;
int iINF = (int) 1e20;
ll mod = (ll) 1e9 + 7;

mt19937 gen(chrono::steady_clock::now().time_since_epoch().count());

signed main() {
    ll n;
    cin >> n;
    vector <ll> a(n);
    for(int i = 0; i < n; cin >> a[i++]);
    sort(a.rbegin(), a.rend());
    multiset <pair <ll, pair <ll, ll>>> st;
    ll ans = a[0];
    if(n == 2) {
        cout << ans;
        return 0;
    }
    ans += a[1];
    st.insert({min(a[0], a[1]), {a[0], a[1]}});
    st.insert({min(a[0], a[2]), {a[0], a[2]}});
    st.insert({min(a[2], a[1]), {a[2], a[1]}});
    for(int i = 3; i < n; ++i) {
        auto it = st.end();
        --it;
        ans += (*it).first;
        ll c = (*it).second.first;
        ll b = (*it).second.second;
        st.erase(it);
        st.insert({min(a[i], b), {a[i], b}});
        st.insert({min(a[i], c), {a[i], c}});
    }
    cout << ans;
}

Measured memory_bytes: 17240
import sys
input = sys.stdin.readline
from collections import defaultdict
n = int(input())
abd = [list(map(int,input().split())) for i in range(n-1)]
if n == 2:
  print(abd[0][2])
  exit()
graph = [[] for i in range(n+1)]
deg = [0 for i in range(n+1)]
for a,b,d in abd:
  graph[a].append((b,d))
  graph[b].append((a,d))
  deg[a] += 1
  deg[b] += 1
stack = []
root = 0
dp = [[] for i in range(n+1)]
sm = [1 for i in range(n+1)]
mx = [0 for i in range(n+1)]
for i in range(1,n+1):
  if deg[i] == 1:
    stack.append(i)
  elif root == 0:
    root = i
    deg[i] += 1
ans = 0
flg = 0
while stack:
  x = stack.pop()
  if dp[x]:
    sm[x] += sum(dp[x])
  if sm[x]*2 == n:
    flg = 1
  for y,d in graph[x]:
    if deg[y] > 1:
      dp[y].append(sm[x])
      if sm[x] == n-sm[x]:
        ans += (sm[x]*2-1)*d
      else:
        ans += min(sm[x],n-sm[x])*2*d
      deg[y] -= 1
      if deg[y] == 1:
        stack.append(y)
dmn = 10**18
if not flg:
  for a,b,d in abd:
    for v in (a,b):
      if not mx[v]:
        if dp[v]:
          mx[v] = max(max(dp[v]),n-1-sm[v])
        else:
          mx[v] = n-2
    if min(mx[a],mx[b])*2 < n:
      dmn = min(dmn,d)
  ans -= dmn
print(ans)

Measured memory_bytes: 95836
from collections import Counter

N = int(input())
A = [int(i) for i in input().split()]
c = Counter(A)

flg = 0
if N % 2:
    if c[0] != 1:
        flg = 1
    else:
        for i in range(2, N, 2):
            if c[i] != 2:
                flg = 1
                break
else:
    for i in range(1, N, 2):
        if c[i] != 2:
            flg = 1
            break

if flg:
    ans = 0
else:
    ans = 2 ** (N//2) % (10**9+7)

print(ans)


Measured memory_bytes: 14820
#include<stdio.h>

int  truer(int N);
int main(){
  int N;
  scanf("%d",&N);
  if(truer(N)){
    printf("Yes\n");
  }
  else
    printf("No\n");
  return 0;
  
  
}

int truer(int N){
  for(int i= 1;i<10;i++)
    {
      if(N/i<10 && N%i==0)
	return 1;
    }
  return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
    int n;
    float s=0,x;
    cin >> n;
    for (int i=1;i<=n;i++)
    {
        cin >> x;
        s=s+(1/x);
    }
    cout << fixed << setprecision(5) << 1/s;
}

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

typedef long long ll;
typedef pair<int, int> pii;
#define FOR(i, n) for(int (i)=0; (i)<(n); (i)++)
#define FOR1(i, n) for(int (i)=1; (i)<=(n); (i)++)
#define FORI(i, n) for(int (i)=n-1; (i)>=0; (i)--)

ll cnt(ll n, ll p){
    ll rez = 0;
    while ( p <= n){
        rez += n/p;
        n /= p;
    }
    return rez;
}

int main(int argc, char** argv) {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cout << setprecision(15);
    if (argc == 2 && atoi(argv[1]) == 123456789) {
        freopen("d:\\code\\cpp\\contests\\stdin", "r", stdin);
        //freopen("d:\\code\\cpp\\contests\\stdout", "w", stdout);
    }

    ll n;
    cin >> n;
    if (n < 5) {
        cout << 0 << endl;
        return 0;
    }

    if (n%2){
        cout << 0 << endl;
    }
    else{
        ll cnt2 = cnt(n/2, 2) + n/2;
        ll cnt5 = cnt(n/2, 5);
        cout << min(cnt2, cnt5) << endl;
    }

    if (argc == 2 && atoi(argv[1]) == 123456789)        cerr << clock()*1.0/CLOCKS_PER_SEC << " sec\n";
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define dunk(a) cout << (a) << endl
#define rall(a) (a).rbegin(),(a).rend()
const int INF = 2e9;
using namespace std;
using Graph = vector<vector<int>>;
typedef pair<int,int> P;
typedef long long ll;

int main(){
    string s; cin >> s;
    int ans = 1002003004;

    rep(i,s.size()-2){
        int jud = 100* (s[i] - '0') + 10* (s[i+1] - '0') + (s[i+2] - '0');
        ans = min(ans,abs(jud - 753));
    }

    dunk(ans);

}

Measured memory_bytes: 256
import java.util.*;
class Main {
	public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        String[] s = new String[n];
        Set<String> set = new HashSet<>();
        for(int i =0;i<n;i++){
            s[i] = sc.next();
            set.add(s[i]);
        }
        int m = sc.nextInt();
        String[] t = new String[m];
        for(int i = 0;i<m;i++)t[i] = sc.next();
        int ans = 0;
        for(String e :set){
            int tmp = 0;
            for(int i = 0;i<n;i++)if(e.equals(s[i]))tmp++;
            for(int i = 0;i<m;i++)if(e.equals(t[i]))tmp--;
            if(tmp>ans) ans = tmp;
        }
        System.out.println(ans);
    }
}


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

#define Q int t; scanf("%d", &t); for(int q=1; q<=t; q++)
typedef long long int lli;
typedef pair<lli, lli> pi;



int main()
{
    string s;
    cin >> s;
    int n = s.size();
    int a[n] = {0};
    for(int i=0; i<n; ){
        int r=0, l=0, ir, il;
        while(s[i] == 'R'){
            ir = i++;
            r++;
        }
        il = i;
        while(i<n && s[i] == 'L'){
            l++;
            i++;
        }
        if((l+r)%2){
            if(r%2){
                a[ir] = (l+r)/2 + 1;
                a[il] = (l+r)/2;
            }
            else{
                a[il] = (l+r)/2 + 1;
                a[ir] = (l+r)/2;
            }
        }
        else{
            a[ir] = (l+r)/2;
            a[il] = (l+r)/2;
        }
    }
    for(auto x: a){
        cout << x << " ";
    }
    printf("\n");

    return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
///Welcome to Nasif's Code
#define bug printf("bug\n");
#define bug2(var) cout<<#var<<" "<<var<<endl;
#define co(q) cout<<q<<endl;
#define all(q) (q).begin(),(q).end()
typedef long long int ll;
typedef unsigned long long int ull;
const int MOD = (int)1e9+7;
const int MAX = 1e6;
#define pi acos(-1)
#define inf 1000000000000000LL
#define FastRead    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int f;
void recur(int n)
{
    if(n==0)
        f=1;
    if(n<=0)
        return ;

    recur(n-4);
    recur(n-7);
}
int main()
{
    FastRead
    //freopen("output.txt", "w", stdout);
    int n;
    cin>>n;
  recur(n);
    if(f)
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;


    return 0;
}


Measured memory_bytes: 3648
# -*- coding: utf-8 -*-
"""
Created on Sat Mar 30 22:26:37 2019

@author: Owner
"""

MOD = 1000000007

def inv(x):
    return pow(x, MOD - 2, MOD)

B, W = map(int, input().split())
fct = [1] * (B + W + 1)
for i in range(B + W):
    fct[i + 1] = (fct[i] * (i + 1)) % MOD

def c(n, k):
    return (fct[n] * inv(fct[k]) * inv(fct[n - k])) % MOD

#p[i]: 黒B回白i回の確率
#q[i]: 黒i回白W回の確率
p = [0] * W
p[0] = inv(pow(2, B, MOD))
for i in range(W - 1):
    p[i + 1] = (p[i] + c(B + i, i + 1) * inv(pow(2, B + i, MOD)) * inv(2)) % MOD
q = [0] * B
q[0] = inv(pow(2, W, MOD))
for i in range(B - 1):
    q[i + 1] = (q[i] + c(W + i, i + 1) * inv(pow(2, W + i, MOD)) * inv(2)) % MOD
for i in range(B + W):
    if i < min(B, W):
        print(inv(2))
        continue
    if i >= max(B, W):
        print((q[i - W] + (1 - p[i - B] - q[i - W] + MOD) * inv(2)) % MOD)
        continue
    if B < W:
        print(((1 - p[i - B] + MOD) * inv(2)) % MOD)
    else:
        print((q[i - W] + (1 - q[i - W] + MOD) * inv(2)) % MOD)

Measured memory_bytes: 74520
#include<iostream>
#include<stdio.h>
//#include<stack>

using namespace std;

int top(int *num){
    while(*num){
        num++;
    }
    return *(num-1);
}

void pop(int *num){
    while(*num){
        num++;
    }
    *(num-1)='\0';
}

bool empty(int *num){
    int i;
    for(i=0; *num!='\0'; i++)
        num++;
    if(i==0)    return true;
    else    return false;
}

void push(int *num, int n){
    while(*num) num++;
    *num=n;
}

int main(){
    //stack<int> st;
    int num[1024]={};
    char c[1024];
    //fgets(c, 1024, stdin);
    fgets(c,2000,stdin);
    int s=0;
    bool flag=false;
    for(int i=0; c[i]!='\0'; i++){
        if(c[i]>='0' && c[i]<='9'){
            flag=true;
            s=10*s+(c[i]-'0');
        }
        else{
            if(flag){
               push(num, s);
               s=0;
               flag=false;
            }
            if(c[i]=='+'){
                int a=top(num);
                pop(num);
                int b=top(num);
                pop(num);
                push(num,a+b);
            }
            else if(c[i]=='-'){
                int a=top(num);
                pop(num);
                int b=top(num);
                pop(num);
                push(num,b-a);
            }
            else if(c[i]=='*'){
                int a=top(num);
                pop(num);
                int b=top(num);
                pop(num);
                push(num, a*b);
            }
        }
    }
    cout<<top(num)<<endl;
       
    //cout<<endl;
    return 0;
}




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

using namespace std;

const int MAX_N = 50, INDEX = 1;
const int MAX_LENGTH = 50, INF = MAX_LENGTH + 1;
const int ALPHA = 26;

int n, countersOfChars[ALPHA], minCountersOfChars[ALPHA];

string s[MAX_N + INDEX], ans;

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

    cin >> n;

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

    for (int i = 0; i < ALPHA; i++) {
        minCountersOfChars[i] = INF;
    }

    for (int i = 1; i <= n; i++) {
        for (int j = 0; j < ALPHA; j++) {
            countersOfChars[j] = 0;
        }

        for (int j = 0; j < s[i].length(); j++) {
            countersOfChars[s[i][j] - 'a']++;
        }

        for (int j = 0; j < ALPHA; j++) {
            minCountersOfChars[j] = min(minCountersOfChars[j], countersOfChars[j]);
        }
    }

    for (int i = 0; i < ALPHA; i++) {
        for (int j = 0; j < minCountersOfChars[i]; j++) {
            ans += i + 'a';
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
/*
    Author: isaf27 (Ivan Safonov)
*/

#pragma GCC optimize("O3")
#include <bits/stdc++.h>

using namespace std;

//defines
typedef long long ll;
typedef long double ld;
#define TIME clock() * 1.0 / CLOCKS_PER_SEC
#define fastIO ios_base::sync_with_stdio(0)
#define nul point(0, 0)
#define str_to_int(stroka) atoi(stroka.c_str())
#define str_to_ll(stroka) atoll(stroka.c_str())
#define str_to_double(stroka) atof(stroka.c_str())
#define what_is(x) cerr << #x << " is " << x << endl
#define solve_system int number; cin >> number; for (int i = 0; i < number; i++) solve()
#define solve_system_scanf int number; scanf("%d", &number); for (int i = 0; i < number; i++) solve()

//permanent constants
const ld pi = 3.141592653589793238462643383279;
const ld log23 = 1.58496250072115618145373894394781;
const ld eps = 1e-8;
const ll INF = 1e18 + 239;
const ll prost = 239;
const int two = 2;
const int th = 3;
const ll MOD = 1e9 + 7;
const ll MOD2 = MOD * MOD;
const int BIG = 1e9 + 239;
const int alf = 26;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, 1, 0, -1};
const int dxo[8] = {-1, -1, -1, 0, 1, 1, 1, 0};
const int dyo[8] = {-1, 0, 1, 1, 1, 0, -1, -1};
const int dig = 10;
const string str_alf = "abcdefghijklmnopqrstuvwxyz";
const string str_alf_big = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
const int day[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
const int digarr[10] = {6, 2, 5, 5, 4, 5, 6, 3, 7, 6};
const int bt = 31;
const int fr = 4;

//easy functions
template< typename T >
inline T gcd(T a, T b) { return a ? gcd(b % a, a) : b; }
template< typename T >
inline T lcm(T a, T b) { return (a / gcd(a, b)) * b; }
inline bool is_down(char x) { return ('a' <= x && x <= 'z'); }
inline bool is_upper(char x) { return ('A' <= x && x <= 'Z'); }
inline bool is_digit(char x) { return ('0' <= x && x <= '9'); }
ll power(ll a, int k)
{
    if (k == 0) return 1;
    ll t = power(a, k >> 1);
    t = (t * t) % MOD;
    if (k & 1) t = (t * a) % MOD;
    return t;
}

//random
mt19937 rnd(239);

//constants
const int M = 2 * 1e5 + 239;
const int N = 2 * 1e3 + 239;
const int L = 20;
const int T = (1 << 20);
const int B = trunc(sqrt(M)) + 1;
const int X = 210;

ll func(ll a, ll b)
{
    if (a == b) return a;
    if (a > b) return (2 * b * ((a - 1) / b) + func(a - ((a - 1) / b) * b, b));
    return (2 * a * ((b - 1) / a) + func(a, b - a * ((b - 1) / a)));
}

ll n, x;

int main()
{
    #ifdef ONPC
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    fastIO;
    cin >> n >> x;
    cout << (n + func(n - x, x));
    return 0;
}


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

int main()
{
  string s, t, u;
  int a, b;
  cin >> s >> t;
  cin >> a >> b;
  cin >> u;

  if (s == u)
    a--;
  else
    b--;

  cout << a << " " << b << endl;
}

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

using namespace std;
typedef long long ll;

#define REP(i,n) for(int i=0;i<n;++i)
#define SORT(name) sort(name.begin(), name.end())
#define ZERO(p) memset(p, 0, sizeof(p))
#define MINUS(p) memset(p, -1, sizeof(p))

#define MOD 1000000007
#define INF 1000000000
#define MAX_N 100010

int N;
vector<ll> A;

int main()
{
    cin >> N;
    REP(i, N) {
        ll tmp;
        cin >> tmp;
        A.push_back(tmp);
    }
    sort(A.begin(), A.end(), greater<ll>());
    ll prev = -1;
    ll first = -1;
    ll second = -1;
    REP(i, N) {
        if(prev == A[i]) {
            if(first == -1) {
                first = A[i];
            }
            else if(second == -1) {
                second = A[i];
                break;
            }
            prev = -1;
        } else {
            prev = A[i];
        }
    }
    if(first == -1 || second == -1) {
        printf("0\n");
        return 0;
    }
    printf("%lld\n", first * second);

    return 0;
}


Measured memory_bytes: 1400
#include <iostream>
#include <vector>
#include <cstdio>
#include <algorithm>
#include <set>
#include <map>
#include <cassert>
#include <numeric>
#include <string>
#include <cstring>
#include <cmath>
using namespace std;

#ifdef LOCAL
	#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
	#define eprintf(...) 42
#endif

typedef long long int int64;


const int MOD = (int) 1e9 + 7;
void sadd(int &a, int b)
{
    a += b;
    if (a >= MOD) a -= MOD;
}
int add(int a, int b)
{
    sadd(a, b);
    return a;
}
void ssub(int &a, int b)
{
    a -= b;
    if (a < 0) a += MOD;
}
int sub(int a, int b)
{
    ssub(a, b);
    return a;
}
int mul(int a, int b)
{
    return (a * 1LL * b) % MOD;
}

const int N = (int) 2e5 + 100;
int a[N];
int dp[N];
int nxt[N];

int main(int,  char **)
{
#ifdef LOCAL
	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);
#endif

    int n;
    scanf("%d", &n);
    for (int i = 0; i < n; i++)
        scanf("%d", &a[i]);

    dp[n] = 1;
    for (int i = n - 1; i >= 0; i--)
    {
        int c = a[i];
        dp[i] = dp[i + 1];
        if (nxt[c] != 0 && nxt[c] != i + 1)
            sadd(dp[i], dp[nxt[c]]);
        nxt[c] = i;
    }
    printf("%d\n", dp[0]);

	return 0;
}




Measured memory_bytes: 2560
while True:
    n, x = map(int, input().split())
    if n + x == 0:
        break
    
    way = 0
    for i in range(1, x//3 + 1):
        for j in range(i+1, (x-i)//2 + 1):
            if x-i-j <= n and (x-i-j) != j:
                way += 1
                
    print(way)


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

using namespace std;
#define DBG(x)                         \
    (void)(cout << "L" << __LINE__     \
                << ": " << #x << " = " \
                << (x) << '\n')
typedef long long ll;
const int INF = 0x3f3f3f3f;
const int maxn = 110000;
int main()
{
    //检查有没有特判0,有没有越界限.
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setiosflags(ios::fixed) << setprecision(12);
    int n;
    cin >> n;
    int mn = INF;
    int cnt = 0;
    for (int i = 1; i <= n; i++)
    {
        int x;
        cin >> x;
        if (mn >= x)
        {
            cnt++;
            mn = min(x, mn);
        }
    }
    cout << cnt << "\n";
    return 0;
}

Measured memory_bytes: 256
import itertools
import math

N = int(input())
n_s = list(range(1, N + 1))
ans = 0
for l in itertools.product(n_s, n_s, n_s):
    a, b, c = sorted(l)
    ans += math.gcd(c, math.gcd(b, a))

print(ans)

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

using namespace std;

typedef long long ll;

const ll inf = 1e9 + 7;

int main(){
  ll H,W; cin >> H >> W;
  vector<vector<char>> S(H+1, vector<char>(W+1));
  
 for(ll i = 1; i <= H; i++){
   for(ll j = 1; j <= W; j++){
     cin >> S[i][j];}} 
  
  vector<vector<ll>> dp(H + 1,vector<ll>(W + 1,0));
  
  dp[1][1] = 1; //dp[H][W]を出力したい 1-indexed
  
  for(ll i = 1; i <= H; i++){
    for(ll  j = 1; j <= W; j++){
      if(S[i][j] == '#'){continue;}//防がれていたら、0のまま
      else{ ll c = dp[i-1][j] + dp[i][j-1] ;
        dp[i][j] =  (max( dp[i][j], c )) % inf; } }}
    
    cout << dp[H][W] % inf << endl; return 0;}
      
      

Measured memory_bytes: 9088
N, X, Y = map(int, input().split())
count = [0 for i in range(N)]
dist = [[-1 for j in range(N)] for i in range(N)]
for i in range(N):
    for j in range(i + 1, N):
        dist[i][j] = min(abs(j - i), abs(X - 1 - i) + 1 + abs(Y - 1 - j))
for i in range(N):
    for j in range(i + 1, N):
        count[dist[i][j]] += 1
for i in range(1, N):
    print(count[i])

Measured memory_bytes: 84088
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        n: usize,
        a: [i64; n],
        b: [i64; n],
    }

    if a.iter().sum::<i64>() < b.iter().sum() {
        println!("-1");
        return;
    }

    let mut diff = (0..n).map(|i| a[i] - b[i]).collect::<Vec<_>>();
    diff.sort();

    let mut l = 0;
    let mut r = n - 1;
    let mut amari = 0;
    let mut ans = 0;

    while diff[l] < 0 {
        amari += diff[l];
        l += 1;
        ans += 1;
        while amari < 0 {
            amari += diff[r];
            r -= 1;
            ans += 1;
        }
    }

    println!("{}", ans);
}


Measured memory_bytes: 6396
import heapq

def main():
    A, B, C, D, E, F = map(int, input().split())
    dp = {0: 0}
    mt, ms = 100 * A, 0
    for i in range(1, F + 1):
        s = -1
        if i - 100 * A in dp:
            s = max(s, dp[i - 100 * A])
        if i - 100 * B in dp:
            s = max(s, dp[i - 100 * B])
        if i - C in dp:
            if dp[i - C] + C <= E * (i - C - dp[i - C]) // 100:
                s = max(s, dp[i - C] + C)
        if i - D in dp:
            if dp[i - D] + D <= E * (i - D - dp[i - D]) // 100:
                s = max(s, dp[i - D] + D)
        if s >= 0:
            if 100 * s * mt > 100 * ms * i:
                mt, ms = i, s
            dp[i] = s
    return mt, ms 

print(*main())


Measured memory_bytes: 3316
#include<bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define REP1(i,n) for(int i=1;i<=(int)(n);i++)
#define RREP(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define FOR(i,a,b) for(int i=a;i<b;i++)
typedef long long ll;

int main(){
  int c ;
  cin >> c;
  if(c%1000==0)cout << 0 << endl;
  else cout << 1000-(c%1000) << endl;
}


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

typedef long long ll;
#define pii pair<int , int>
#define _FastIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define MAXX 200005

int n;
int a[MAXX];
int b[MAXX];

int main()
{
    _FastIO;

    cin >> n;
    for(int i = 1; i <= n; i++){
        cin >> a[i];
        b[a[i]] = i;
    }
    int m = n;
    int ans = 0;
    for(int i = 1; i <= n; i++){
        m = min(m , b[i]);
        if(m == b[i])
            ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1792
import math

# 素数判定関数
def isPrime(num):
    # 2未満の数字は素数ではない
    if num < 2: return False
    # 2は素数
    elif num == 2: return True
    # 偶数は素数ではない
    elif num % 2 == 0: return False

    # 3 ~ numまでループし、途中で割り切れる数があるか検索
    # 途中で割り切れる場合は素数ではない
    for i in range(3, math.floor(math.sqrt(num))+1, 2):
        if num % i == 0:
            return False

    # 素数
    return True

X = int(input())

for i in range(100000):
    if isPrime(X + i):
        print(X+i)
        break


Measured memory_bytes: 3060
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <queue>

#define INF 100000000

using namespace std;

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

    return 0;
}

Measured memory_bytes: 256