akhauriyash/Code-Regression huggingface dataset:
# D - Even Relation

# 木なのでノードAB間の辺を辿ればそれがAB間の最短経路となる
# 全ての｢辺｣についてループする

from collections import deque

N = int(input())

edge = [[] for _ in range(N)]

for _ in range(N-1):
    u, v, w = map(int, input().split())
    edge[u-1].append([v-1, w])
    edge[v-1].append([u-1, w])

color = [0] + [-1]*(N-1)
d = deque([0])

while d:
    current_point = d.popleft()
    for current_edge in edge[current_point]:
        if color[current_edge[0]] == -1:
            color[current_edge[0]] = (color[current_point] + current_edge[1]) % 2
            d.append(current_edge[0])

for idx in range(N):
    print(color[idx])

Measured memory_bytes: 45344
X, N = map(int, input().split())
P = list(map(int, input().split()))
Q = [i for i in range(-150, 150)]
P = list(set(Q) - set(P))
P.sort()
dif = 100
for p in P:
    if abs(X-p) < dif:
        dif = abs(X-p)
        ans = p
print(ans)

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

int main()
{
  int x, y;
  set<int> a{1, 3, 5, 7, 8, 10, 12};
  set<int> b{4, 6, 9, 11};
  set<int> c{2};
  cin >> x >> y;
  cout << ((a.count(x) && a.count(y)) || (b.count(x) && b.count(y)) || (c.count(x) && c.count(y)) ? "Yes" : "No") << endl;
}


Measured memory_bytes: 256
import java.util.*;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int A = sc.nextInt();
        int B = sc.nextInt();
        int C = sc.nextInt();
        if (C >= A && C <= B) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
    }
}

Measured memory_bytes: 22612
N, X, Y = [int(s) for s in input().split()]
D = [0] * (N)
for i in range(1, N+1):
    for j in range(i+1, N+1):
        d = min(j - i, abs(j - Y) + abs(i - X) + 1)
        D[d] += 1
for i in range(1, N):
    print(D[i])

Measured memory_bytes: 3444
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
long long mo = 1e9 + 7;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
template<class A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}cout << "\n";}
ld PI=3.14159265358979323846;

ll mpow(ll x, ll n){ //x^n(mod mo) ←普通にpow(x,n)では溢れてしまうため，随時mod計算
    ll ans = 1;
    while(n != 0){
        if(n&1) ans = ans*x % mo;
        x = x*x % mo;
        n = n >> 1;
    }
    return ans;
}
 
const int mod = 1000000007;
class mint {
    long long x;
public:
    mint(long long x=0) : x((x%mod+mod)%mod) {}
    mint operator-() const { 
      return mint(-x);
    }
    mint& operator+=(const mint& a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint& a) {
        if ((x += mod-a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const  mint& a) {
        (x *= a.x) %= mod;
        return *this;
    }
    mint operator+(const mint& a) const {
        mint res(*this);
        return res+=a;
    }
    mint operator-(const mint& a) const {
        mint res(*this);
        return res-=a;
    }
    mint operator*(const mint& a) const {
        mint res(*this);
        return res*=a;
    }
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }
    // for prime mod
    mint inv() const {
        return pow(mod-2);
    }
    mint& operator/=(const mint& a) {
        return (*this) *= a.inv();
    }
    mint operator/(const mint& a) const {
        mint res(*this);
        return res/=a;
    }
 
    friend ostream& operator<<(ostream& os, const mint& m){
        os << m.x;
        return os;
    }
};

int main(){
    ll N;
    cin >> N;
    vector<ll> C(N);
    map<ll,ll> mp;
    vector<mint> dp(N+1);
    rep(i,N){
        cin >> C[i];
    }
    dp[0] = 1;
    rep(i,N){
        if(mp[C[i]] == 0){
            mp[C[i]] = i+1;
            dp[i+1] = dp[i];
            continue;
        }
        if(i+1 - mp[C[i]] >= 2){
            dp[i+1] = dp[i] + dp[mp[C[i]]];
        }else{
            dp[i+1] = dp[i];
        }
        mp[C[i]] = i+1;
    }
    //PR(dp,N+1);
    cout << dp[N] << endl;
}

Measured memory_bytes: 18816
#include<iostream>
#include<cstdio>
#include<vector>
#include<algorithm>
using namespace std;
int main()
{
	int n;
	scanf("%d",&n);
	if(n == 0)
		printf("2\n");
	else if(n == 1)
		printf("1\n");
	else
	{
		long long a,b,c;
		a = 2;
		b = 1;
		int i;
		for(i=2;i<=n;i++)
		{
			c = a+b;
			a = b;
			b = c;
		}
		printf("%lld\n",c);
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;

const int mod = 1000000007;
//const int mod = 998244353;

struct mint {
  ll x;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}


int main()
{
    string c;
    cin >> c;
    int n, w, s, e;
    n = w = s = e = 0;
    rep(i, 0, c.size()){
        if(c[i] == 'N') n++;
        if(c[i] == 'W') w++;
        if(c[i] == 'S') s++;
        if(c[i] == 'E') e++;
    }
    bool flag = true;
    if(n == 0 && s > 0) flag = false;
    if(w == 0 && e > 0) flag = false;
    if(s == 0 && n > 0) flag = false;
    if(e == 0 && w > 0) flag = false;
    if(flag) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 3568
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define FAST_IO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int main(){
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    string str;
    while(cin>>str){
        cout<<str[0]<<(str.length()-2)<<(str[str.length()-1])<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include<cstdio>
const int MAXN = 100000;
const int MOD = 998244353;
char s[3*MAXN + 5];
int fct[3*MAXN + 5], n;
void init() {
	fct[0] = 1;
	for(int i=1;i<=MAXN;i++)
		fct[i] = 1LL*fct[i-1]*i%MOD;
}
int f[5], g[5];
int func(char ch) {
	if( ch == 'R' ) return 0;
	if( ch == 'G' ) return 1;
	if( ch == 'B' ) return 2;
}
int main() {
	init(); scanf("%d", &n);
	scanf("%s", s + 1);
	int ans = fct[n];
	for(int i=1;i<=3*n;i++) {
		int x = func(s[i]);
		if( f[x] )
			ans = 1LL*ans*f[x]%MOD, f[x]--;
		else if( g[(x+2)%3] )
			ans = 1LL*ans*g[(x+2)%3]%MOD, g[(x+2)%3]--, f[(x+1)%3]++;
		else if( g[(x+1)%3] )
			ans = 1LL*ans*g[(x+1)%3]%MOD, g[(x+1)%3]--, f[(x+2)%3]++;
		else g[x]++;
	}
	printf("%d\n", ans);
}

Measured memory_bytes: 896
n = int(input())

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    # divisors.sort()
    return divisors

yakusu = make_divisors(n)
yakusu.sort()

ans = 10

for i in range(len(yakusu)):
    ans = min(ans,max(len(str(yakusu[i])), len(str(n//yakusu[i]))) )
    
print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
 
using namespace std;
typedef long long ll;
typedef pair<ll, ll> p_ll;
 
template<class T>
void debug(T itr1, T itr2) { auto now = itr1; while(now<itr2) { cout << *now << " "; now++; } cout << endl; }
#define repr(i,from,to) for (int i=(int)from; i<(int)to; i++)
#define rep(i,N) repr(i,0,N)
#define per(i,N) for (int i=(int)N-1; i>=0; i--)
 
const ll MOD = pow(10,9)+7;
const ll LLINF = pow(2,61)-1;
const int INF = pow(2,30)-1;
  
 
int main() {
    string X; cin >> X;
    
    int res = X.size();
    int s = 0;
    int t = 0;
    rep(i,X.size()) {
        if (X[i] == 'T') t++;
        if (X[i] == 'S' || i == X.size() - 1) {
            if (t > 0) {
                res -= min(s,t) * 2;
                s -= min(s,t);
                t = 0;
            }
            s++;
        }
        // cout << s << " " << t << endl;
    }

    cout << res << endl;
    return 0;
}

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

int main() {
  int a, b, c, d;
  
  cin >> a >> b >> c >> d;
  
  if (a+b > c+d)
    cout << "Left" << endl;
  else if (a+b == c+d) 
    cout << "Balanced" << endl;
  else
    cout << "Right" << endl;
}

Measured memory_bytes: 256
n = int(input())
a = list(map(int,input().split()))
ans = 0
mod = 10**9+7
s = [0]*n
s[-1] = a[-1]
for i in range(n-2,-1,-1):
    s[i] = (s[i+1]+a[i])%mod
for i in range(n-1):
    ans = (ans + (a[i]*s[i+1]))%mod
print(ans)

Measured memory_bytes: 31584
#include "bits/stdc++.h"
// Begin Header {{{
#define all(x)          (x).begin(), (x).end()
#define rep(i, n)       for (i64 i = 0, i##_limit = (n); i < i##_limit; ++i)
#define reps(i, s, t)   for (i64 i = (s), i##_limit = (t); i <= i##_limit; ++i)
#define repr(i, s, t)   for (i64 i = (s), i##_limit = (t); i >= i##_limit; --i)
#ifndef DBG
#define trace(...)
#endif
using namespace std;
using i64 = int_fast64_t;
using pii = pair<i64, i64>;
template <class T, class U> inline bool chmax(T &a, const U &b) { return b > a && (a = b, true); }
template <class T, class U> inline bool chmin(T &a, const U &b) { return b < a && (a = b, true); }
constexpr int INF  = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;

template <class T>
inline vector<T> make_v(const T &initValue, size_t sz) {
    return vector<T>(sz, initValue);
}

template <class T, class... Args>
inline auto make_v(const T &initValue, size_t sz, Args... args) {
    return vector<decltype(make_v<T>(initValue, args...))>(sz, make_v<T>(initValue, args...));
}

inline void read() {}

template <class Head, class... Tail>
inline void read(Head &head, Tail&... tail) { cin >> head; read(tail...); }

inline void print() { cout << "\n"; }

template <class Head, class... Tail>
inline void print(Head &&head, Tail&&... tail) {
    cout << head;
    if (sizeof...(tail)) cout << ' ';
    print(forward<Tail>(tail)...);
}

template <class T>
inline ostream& operator<< (ostream &out, const vector<T> &vec) {
    static constexpr const char *delim[] = { " ", "" };
    for (const auto &e : vec) out << e << delim[&e == &vec.back()];
    return out;
}
// }}} End Header

int f(int x) {
    int cnt = 0;
    while (x > 0 && x % 100 == 0) {
        ++cnt;
        x /= 100;
    }

    return cnt;
}

signed main() {
    ios_base::sync_with_stdio(false); cin.tie(nullptr);

    int D, N;
    read(D, N);

    int cnt = 0;
    reps(i, 1, 10000000) {
        if (f(i) == D) ++cnt;
        if (cnt == N) {
            print(i);
            return 0;
        }
    }

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define modulo 1000000007
#define mod(mod_x) ((((long long)mod_x+modulo))%modulo)
#define Inf 100000000



int main(){
	
	int N;
	cin>>N;
	
	string S;
	cin>>S;
	
	int ok = 0;
	int ng = N+1;
	
	while(ng-ok>1){
		int mid = (ng+ok)/2;
		map<string,int> mp;
		bool f = false;
		for(int i=0;i<N+1-mid;i++){
			string s = S.substr(i,mid);
			if(mp[s]==0)mp[s]=i+1;
			else{
				if(i+1-mp[s]>=mid){
					f=true;
				}
			}
		}
		if(f)ok=mid;
		else ng=mid;		
	}
	
	cout<<ok<<endl;
	
	return 0;
}


Measured memory_bytes: 6672
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time

sys.setrecursionlimit(10**7)
inf = 10**10
mod = 10**9 + 7


def f():
    s = input()
    if re.match(r'.*C.*F.*', s):
        return 'Yes'
    return 'No'

print(f())


Measured memory_bytes: 6544
#include <stdlib.h>
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;   
}

int main() {
    int n,k;
    cin>>n>>k;
    if(n<=k){
        cout<<n<<endl;
    }
    else{
        cout<<n-1<<endl;
    }
    
}




Measured memory_bytes: 256
# include<bits/stdc++.h>
# define LL long long
using namespace std;
int main()
{
	int a,b,c;
	cin>>a>>b>>c;
	int minn=1e9;
	minn=min(minn,abs(b-a)+abs(b-c));
	minn=min(minn,abs(b-a)+abs(a-c));
	minn=min(minn,abs(c-a)+abs(c-b));
	cout<<minn<<endl;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
  int n,x;
  cin >> n >> x;
  while(n!=0||x!=0){
    int i,j,k;
    int o=0;
    for(i=1;i<=n;i++){
      for(j=i+1;j<=n;j++){
    	for(k=j+1;k<=n;k++){
	      if(i+j+k==x) o++;
     	}
      }
    }

    cout << o << endl;

    cin >> n >> x;
  }


  return 0;
}



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

group_a = {1,3,5,7,8,10,12}
group_b = {4,6,9,11}
group_c = {2}

if (x in group_a and y in group_a) or (x in group_b and y in group_b):
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3060
#include<stdio.h>

int main() {
  int H, W, i, j;

  while (1) {
    scanf("%d %d", &H, &W);

    if (H == 0 && W == 0) {
      return 0;
    }
    
    for (i = 0; i < H; i++) {
      for (j = 0; j < W; j++) {
        if (i % 2 == 0 && j % 2 == 0 || i % 2 == 1 && j % 2 == 1) {
          printf ("#");
        } else {
          printf (".");
        }
      }
      printf ("\n");
    }
    printf ("\n");
  }
  return 0;
}


Measured memory_bytes: 2028
#include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<queue>
#include<deque>
#include<regex>
#include<stack>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
#include<iomanip>

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

typedef int long long ll;
using namespace std;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
const ll MOD = 1e9 + 7;

int main() {
    ll n;
    cin>>n;
    ll sn=0;
    ll nn=n;
    while(nn>=1){
        sn+=nn%10;
        nn/=10;
    }
    if(n%sn==0){cout<<"Yes"<<endl;}else{cout<<"No"
    <<endl;}



    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<queue>

using namespace std;

int main(){
    int N, M; cin >> N >> M;
    vector<int> G[100001];
    for (int i = 0; i < M; i++){
        int x, y, z; cin >> x >> y >> z;
        G[x].push_back(y);
        G[y].push_back(x);
    }

    queue<int> q;

    bool used[N+1];
    fill(used, used + N + 1, false);

    int count = 0;
    for (int i = 1; i <= N; i++){
        if (used[i]) continue;
        q.push(i);
        while(q.size()){
            int x = q.front(); q.pop();
            used[x] = true;
            for (auto& y : G[x]){
                if(!used[y]) q.push(y);
            }
        }
        count++;
    }
    cout << count << endl;
}

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

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

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  REP(i,n)
    cin >> a[i];
  
  int c=0;
  REP(i,n) {
    if (a[i] != i+1) {
      c++;
    }
  }
  string ans = "NO";
  if (c==2 || c==0) ans="YES";
  cout << ans << endl;
}


Measured memory_bytes: 256
-- https://github.com/minoki/my-atcoder-solutions
import Data.Char (isSpace)
import Data.Int (Int64)
import Control.Monad (forM_)
import qualified Data.Vector.Unboxed as U
import qualified Data.ByteString.Char8 as BS
import Data.Array.ST
import Control.Monad.ST

asSTUArray :: ST s (STUArray s i e) -> ST s (STUArray s i e)
asSTUArray = id

main = do
  n <- readLn
  xs <- U.map fromIntegral . U.unfoldrN n (BS.readInt . BS.dropWhile isSpace) <$> BS.getLine
  let result = runST $ do
        arr <- asSTUArray $ newArray ((0,0),(n,n)) 0
        -- arr!(i,j): 左から i 個、右から j 個取り除かれた状態から二人が最適に行動した場合の、 X-Y の値
        -- i+j == n の場合は arr!(i,j) == 0
        forM_ [n-1,n-2..0] $ \k ->
          if even k
          then -- 太郎くん： X-Y を最大化したい
            forM_ [0..k] $ \i -> do
              let j = k - i
              -- i + j == k
              a <- (+ xs U.! i) <$> readArray arr (i+1,j)
              b <- (+ xs U.! (n - j - 1)) <$> readArray arr (i,j+1)
              writeArray arr (i,j) $! max a b
          else -- 次郎くん： X-Y を最小化したい
            forM_ [0..k] $ \i -> do
              let j = k - i
              -- i + j == k
              a <- subtract (xs U.! i) <$> readArray arr (i+1,j)
              b <- subtract (xs U.! (n - j - 1)) <$> readArray arr (i,j+1)
              writeArray arr (i,j) $! min a b
        readArray arr (0,0)
  print (result :: Int64)


Measured memory_bytes: 71676
#pragma GCC optimize(3)
#include<bits/stdc++.h>
#define MAXN 105
#define MAXK 100005
#define INF 1000000000
#define MOD 1000000007
#define F first
#define S second
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int n,k,a[MAXN];
int dp[MAXK];
int main()
{
    scanf("%d%d",&n,&k);
    for(int i=1;i<=n;i++) scanf("%d",&a[i]);
    memset(dp,0,sizeof(dp));
    dp[0]=0;
    for(int i=1;i<=k;i++)
    {
        bool f=false;
        for(int j=1;j<=n;j++)
            if(i>=a[j]&&dp[i-a[j]]==0) f=true;
        if(f) dp[i]=1; else dp[i]=0;
    }
    if(dp[k]) puts("First"); else puts("Second");
    return 0;
}



Measured memory_bytes: 640
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        while (true) {
            int n = scanner.nextInt();
            int s = scanner.nextInt();
            if (n == 0 && s == 0) break;
            int m = 0;
            for (int i = 0; i < Math.pow(2, 10); i++) {
                int sum = 0;
                int l = 0;
                for (int j = 0; j < 10; j++) {
                    if(((i >> j) & 1) == 1) {
                        sum += j;
                        l++;
                    }
                }
                if (sum == s && n == l) m++;
            }
            System.out.println(m);
        }
        scanner.close();
    }
}



Measured memory_bytes: 26612
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

n = int(readline())
s = read().rstrip().decode()
cnt = 0
for i in range(1000):
    num = str(i).zfill(3)
    idx = -1
    for m in num:
        idx = s.find(m, idx + 1)
        if idx == -1:
            break
    else:
        cnt += 1
print(cnt)


Measured memory_bytes: 3060
#include <iostream>
#include <cstring>
#include <stdlib.h>
#include <vector>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <math.h>
#include <string>
#include <map>
#include <cstdlib>
#include <sstream>
#include <bitset>
using namespace std;

typedef long long ll;

int main()
{
    int a,b;
    cin >> a >> b;
    if(a>b) swap(a,b);

    if(b==2) cout << 3 << endl;
    else if(a==2) cout << 1 << endl;
    else cout << 2 << endl;




    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void) {
	int n;
	int p[50];
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		scanf("%d", &p[i]);
	}
	int count = 0;
	for (int j = 1; j < n - 1; j++) {
		if ((p[j] - p[j + 1]) * (p[j] - p[j - 1]) < 0) {
			count++;
		}
	}
	printf("%d", count);

	return 0;
}

Measured memory_bytes: 128
import math
A, B, H, M = map(int, input().split(' '))
deg = abs(H * 30 + 0.5 * M - 6 * M)
if deg > 180:
    deg = 360 - deg
deg = math.radians(deg)
print(math.sqrt((B - A * math.cos(deg)) ** 2 + (A * math.sin(deg)) ** 2))

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

template<size_t N>
size_t rankF2(vector<bitset<N>>& a, long n, long m){ // calculate rank of matrix in F_2
    size_t now(0), ret(0);
    while(now < m && ret < n){
        size_t i(ret);
        for(; i < n; ++i)if(a[i][now])break;
        if(i == n){
            ++now;
            continue;
        }
        size_t j(i + 1);
        for(; j < n; ++j)if(a[j][now])a[j] ^= a[i];
        swap(a[ret], a[i]);
        ++ret;
    }
    return ret;
}

int main(){
    constexpr long m = 998244353;
    auto modpow = [&m](long n){
        long r = 1, p = 2;
        while(n){
            if(n & 1){
                r *= p;
                r %= m;
            }
            p *= p;
            p %= m;
            n >>= 1;
        }
        return r;
    };

    long N, M;
    cin >> N >> M;
    bool f = false;
    if(N > M && (f = true))swap(N, M);

    vector<bitset<300>> a(N);
    if(f)for(int i = 0; i < M; ++i)for(int j = 0, k; j < N; ++j){
        scanf("%d", &k);
        a[j][i] = k > 0;
    }
    else for(auto& i : a)for(int j = 0, k; j < M; ++j){
        scanf("%d", &k);
        i[j] = k > 0;
    }

    auto r = rankF2(a, N, M);
    cout << modpow(N + M - r - 1) * (modpow(r) - 1) % m << endl;
}


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

int main() {
  int n;
  cin >> n;
  int c[26], s[n][26];
  vector<int> last(26, -1);
  for (int i = 0; i < 26; ++i)
    cin >> c[i];
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < 26; ++j)
      cin >> s[i][j];
  for (int i = 0; i < n; ++i) {
    int neg(0), test(-1);
    for (int j = 0; j < 26; ++j) {
      neg -= c[j] * (i - last[j]);
    }
    //cout << neg << 'n' << endl;
    int max_score = -1e9;
    for (int j = 0; j < 26; ++j) {
      int ss = s[i][j] + neg + c[j] * (i - last[j]);
      if (ss > max_score) {
        max_score = ss;
        test = j;
      }
    }
    cout << test + 1 << endl;
    //cout << test + 1 << ' ' << max_score << endl;
    last[test] = i;
  }
  return 0;
}

Measured memory_bytes: 3668
n = int(input())
l = list(map(int, input().split()))

l.sort(reverse=True)
ans = 0
if n < 3:
  ans = 0
else:
  for k in range(0, n-2):
    for j in range(k+1, n-1):
      if l[k]/2 > l[j]:
        break
      if l[k] == l[j]:
        continue
      for i in range(j+1, n):
        if l[k] >= l[j] + l[i] or l[j] == l[i]:
          continue
        else:
          ans += 1
print(ans)

Measured memory_bytes: 67964
import sys,heapq,math
from collections import deque,defaultdict
printn = lambda x: sys.stdout.write(x)
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
DBG = True # and False
def ddprint(x):
  if DBG:
    print(x)

n,d = inm()
x = []
for i in range(n):
    x.append(inl())
ans = 0
for i in range(n-1):
    for j in range(i+1,n):
        q = sum([(x[i][k]-x[j][k])**2 for k in range(d)])
        if (int(math.sqrt(q)))**2 == q:
            ans += 1
print(ans)


Measured memory_bytes: 38256
#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define eb 			emplace_back
#define mp 			make_pair
#define pii         pair<ll,ll>
#define vi          vector<ll>
#define vii         vector<pii>
#define mi          map<ll,ll>
#define mii         map<pii,ll>
#define all(a)      (a).begin(),(a).end()
#define fi          first
#define si          second
#define sz(x)       (ll)x.size()
#define endl        '\n'
#define checkbit(n, b) ((n >> b) & 1)
#define mod        1000000007
#define puts(n)		cout<<n;
#define rep(i,a,b)  for(ll i=a;i<b;i++)
#define setbits(x) __builtin_popcount(x)
#define mset(m,v) memset(m,v,sizeof(m))
using namespace std;
int main(){
	ios_base::sync_with_stdio(false);
        cin.tie(NULL);
        cout.tie(NULL);
        ll a,b;
        cin>>a>>b;
        string s[a];
        rep(i,0,a)
        cin>>s[i];
        ll dp[a][b]={};
        //mset(dp,0);
        rep(i,0,b)
        if(s[0][i]=='.')
        dp[0][i]=1;
        else break;
       
        rep(i,0,a)
        if(s[i][0]=='.')
        dp[i][0]=1;
        else break;
       dp[0][0]=0;
	    rep(i,1,a)
        rep(j,1,b){
		if(s[i][j]=='.')
        dp[i][j]=(dp[i-1][j]+dp[i][j-1])%mod;
        }cout<<
		(dp[a-1][b-1])%mod;
return 0;}


Measured memory_bytes: 9088
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>
#include <queue>
#include <stack>

using namespace std;

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

const ll mod = 1000000007;

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

  string s, t;
  cin >> s >> t;

  string ans = t + s;

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <climits>
#include <cmath>
#include <csignal>
#include <cstdio>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <string>
#include <vector>

using ll = long long;
using namespace std;

int main() {
    ll a = 0, b = 0, c = 0;
    cin >> a >> b >> c;
    if (a%2 == 1 && b%2 == 1 && c%2 == 1) {
        cout << min(a*b, min(a*c, b*c)) << endl;
    }
    else {
        cout << 0 << endl;
    }
    return 0;
}


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

int main() {
    int a, b, c;
    cin >> a >> b >> c;

    int cnt = 0;
    if (a % 2 == b % 2) {
        if (a % 2 != c % 2) {
            a++;
            b++;
            cnt++;
        }
    } else {
        if (a % 2 == c % 2) {
            a++;
            c++;
            cnt++;
        } else {
            b++;
            c++;
            cnt++;
        }
    }

    int max_value = max(max(a, b), c);
    cnt += (max_value - a) / 2 + (max_value - b) / 2 + (max_value - c) / 2;
    cout << cnt << endl;
    return 0;
}

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

int main(){
  map<int, string> m;
  m[1] = "A";
  m[3] = "A";
  m[5] = "A";
  m[7] = "A";
  m[8] = "A";
  m[10] = "A";
  m[12] = "A";
  m[4] = "B";
  m[6] = "B";
  m[9] = "B";
  m[11] = "B";
  m[2] = "C";
  
  int x, y;
  cin >> x >> y;
  
  if (m[x] == m[y]) cout << "Yes" << endl;
  else cout << "No" << endl;
  
  return 0;
  
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <bitset>
#include <cmath>
#include <deque>
#include <functional>
#include <queue>
#include <string>
#include <stack>
#include <unordered_map>
#include <unordered_set>

using namespace std;

using ll          = long long;
using db          = double;
using ld          = long double;
using uint        = unsigned int;
using ull         = unsigned long long;

using pii         = pair<int, int>;
using pll         = pair<ll, ll>;
using tiii        = tuple<int, int, int>;

#define mod7        1000000007
#define mod9        1000000009

#define forall(v)   v.begin(), v.end()
#define prec(x)     setprecision(x) << fixed

/* [💭] [💡] [🎈] */

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

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

    vector<ll> bits(60), a(n);
    ll f = 0;
    for (int i = 0; i < n; i++) {
        ll x;
        cin >> x;
        a[i] = x;

        for (int i = 0; i < 60; i++) {
            if (x & (1ll << i)) bits[i]++;
        }
    }

    for (int i = 59; i >= 0; i--) {
        if ((f ^ (1ll << i)) <= k) {
            if (bits[i] < n - bits[i]) {
                bits[i] = n - bits[i];
                f ^= 1ll << i;
            }
        }
    }

    ll s = 0;
    for (ll x : a) {
        s += f ^ x;
    }

    cout << s;

    return 0;
}

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

#define ll long long
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
int n, k; 
int a[100010];
int main(void) 
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin >> n >> k; 
	int ans=0;
	for (int i=1; i<=n; i++) 
	{
		cin >> a[i]; 
		if (a[i] >= k) 
			ans++; 
	}
	cout << ans << '\n';



	return false; 
}


Measured memory_bytes: 640
#include <iostream>
using namespace std;
const int INF=0x3f3f3f3f;
//vector<int>v[maxn];
//map<int,string>mp[maxn];
//queue<int>q[maxn];
int n,m;
int main()
{
//	int i,j,k,ans=0;
	cin>>n>>m;
	int x,y;
	x=n*2;
	if(x>m)
		cout<<"No"<<endl;
	else
	{
		y=(m-x)/2;
		x=n-y;
		//cout<<x<<y;
		if(x*2+y*4!=m || x<0 || y<0)
			cout<<"No"<<endl;
		else
			cout<<"Yes"<<endl;
	}
	return 0;
}


Measured memory_bytes: 3132
#include<iostream>
#include<string>
#include<vector>
#include<cmath>
#include<cstdlib>
#include<string>
#include<algorithm>
#include<map>
#include<iomanip>
#include<limits>
#include<queue>
#include<set>
#include<cstdio>
#include<cstring>

using namespace std;

int main(){

	int H,W;
	cin >> H >> W;
	string ans = "Yes";

	char a[52][52];

	for(int i = 1;i <= H;i++){
		for(int j = 1;j <=W;j++){
			cin >> a[i][j];
		}
	}

	for(int i = 1;i <= H;i++){
		for(int j = 1;j <= W;j++){
		  if(a[i][j] == '#' && a[i-1][j] != '#' && a[i+1][j] !='#' && a[i][j-1] != '#' && a[i][j+1] != '#'){
			  ans = "No";
			  break;
		  }
		}
	}

	cout << ans << endl;

	return 0;

}


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

#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for (int i = x; i < n; i++)
#define OP(m) cout << m << endl
typedef long long ll;
typedef unsigned long long ull;

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

    double minv = 12;

    for (int i = 1; i <= sqrt(n); i++)
    {
        if (n % i == 0)
        {
            minv = min(minv, log10(n / i) + 1);
        }
    }
    OP((int)minv);
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<vector<vector<ll>>> vvvl;
struct edge{ll to,cost;};
const int inf = 1<<28;
const ll INF = 1LL<<53;
const int COMBMAX = 500005;
const ll MOD = 1e9+7;
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i=0;i<n;++i)
#define repf(i,n) for(int i=0;i<=n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
#define eachdo(v, e) for(const auto& e : v)
#define all(v) (v).begin(), (v).end()
#define lower_index(v, e) (ll)distance(v.begin(), lower_bound((v).begin(), (v).end(), e))
#define upper_index(v, e) (ll)distance(v.begin(), upper_bound((v).begin(), (v).end(), e))
ll mpow(ll a, ll n,ll mod=MOD){ll res=1;while(n>0){if(n&1)res=res*a%mod;a=a*a%mod;n>>=1;}return res;}
template<class T1, class T2> ll bcount(T1 v, T2 a){return upper_index(v,a)-lower_index(v,a);} 
template<class T> bool chmin(T &a, T b){if(a>b){a=b;return true;}return false;}
template<class T> bool chmax(T &a, T b){if(a<b){a=b;return true;}return false;}
template<class T> void debug(T v){rep(i,v.size()) cout<<v[i]<<" ";cout<<endl;}
template<class T> void debug2(T v){rep(i,v.size()){rep(j,v[i].size())cout<<v[i][j]<<" ";cout<<endl;}}
template<class T> void rdv(T &v){rep(i,v.size())cin>>v[i];}
template<class T> void rdvv(T &v){rep(i,v.size()){rep(j,v[i].size())cin>>v[i][j];}}

int main(){
    ll N; cin >> N;
    vl a(N);rdv(a);
    ll ans = 0;
    vector<bool> used(N,false);
    for(ll num = 1LL<<35 ; 1<num ; num>>=1){
        unordered_map<ll,ll> md;// a[i]%num,そのようになる個数
        unordered_multimap<ll,ll> list;// a[i]%num、それを満たすlist
        rep(i,N){
            if (used[i] || num<=a[i]) continue;
            md[a[i] % num]++;
            list.emplace(a[i] % num,i);
        }
        eachdo(md,e){
            if(num/2<e.first) continue;
            if(!md.count(num - e.first)) continue;
            if(e.first!=num - e.first){
                ll tm = min(e.second,md[num - e.first]);
                ans += tm;
                ll cnt = 0;
                auto p = list.equal_range(e.first);
                for(auto it = p.first; it != p.second ; ++it){
                    if (cnt>=tm) break;
                    used[it->second] = true;
                    cnt++;
                }
                cnt = 0;
                auto q = list.equal_range(num - e.first);
                for(auto it = q.first; it != q.second ; ++it){
                    if (cnt>=tm) break;
                    used[it->second] = true;
                    cnt++;
                }
            }else{
                ll tm = e.second/2;
                ans += tm;
                ll cnt = 0;
                auto p = list.equal_range(e.first);
                for(auto it = p.first; it != p.second ; ++it){
                    if (cnt>=tm*2) break;
                    used[it->second] = true;
                    cnt++;
                }
            }
        }
        // rep(i,N) cout << used[i] ? 1 : 0;
        // cout << endl;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 20968
#include <stdio.h>
#include <stdbool.h>

bool hasBingo(int firstRow[3], int secondRow[3], int thirdRow[3])
{
    
    if ((firstRow[0] == true && firstRow[1] == true && firstRow[2] == true)
        || (secondRow[0] == true && secondRow[1] == true && secondRow[2] == true)
        || (thirdRow[0] == true && thirdRow[1] == true && thirdRow[2] == true))
    {
        return true;
    }
    else if ((firstRow[0] == true && secondRow[0] == true && thirdRow[0] == true)
             || (firstRow[1] == true && secondRow[1] == true && thirdRow[1] == true)
             || (firstRow[2] == true && secondRow[2] == true && thirdRow[2] == true))
    {
        return true;
    }
    else if ((firstRow[0] == true && secondRow[1] == true && thirdRow[2] == true)
             || (firstRow[2] == true && secondRow[1] == true && thirdRow[0] == true))
    {
        return true;
    }
    else
    {
        return false;
    }
}

int main()
{
    int inputN, inputB, firstRow[3], secondRow[3], thirdRow[3];
    bool isBingo = false;

    // Create a array for every row in a bingo and fill it with values
    scanf("%d %d %d", &firstRow[0], &firstRow[1], &firstRow[2]);

    scanf("%d %d %d", &secondRow[0], &secondRow[1], &secondRow[2]);

    scanf("%d %d %d", &thirdRow[0], &thirdRow[1], &thirdRow[2]);

    // Check if values in bingo are the same with the input
    // If input value and value in the bingo is the same, then makes it '-1'
    scanf("%d", &inputN);

    for (int i = 0; i < inputN; i++)
    {
        scanf("%d", &inputB);

        for (int j = 0; j < 3; j++)
        {
            if (firstRow[j] == inputB)
            {
                firstRow[j] = true;
            }
            if (secondRow[j] == inputB)
            {
                secondRow[j] = true;
            }
            if (thirdRow[j] == inputB)
            {
                thirdRow[j] = true;
            }
        }

    }
    isBingo = hasBingo(firstRow, secondRow, thirdRow);
    
    if(isBingo == true)
    {
        printf("Yes\n");
    }
    else
    {
        printf("No\n");
    }
        
    return 0;
}


Measured memory_bytes: 128
N=int(input())

a=[0]*60001

for x in range(1,101):
  for y in range(1,101):
    for z in range(1,101):
      n=x*x + y*y + z*z + x*y + y*z + z*x
      a[n]+=1

for i in range(1,N+1):
  print(a[i])


Measured memory_bytes: 9680
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define dl double long
#define rep(i, m, n) for(ll i = (ll)(m); i < (ll)(n); ++i)
#define rrep(i, m, n) for(ll i = (ll)(m); i > (ll)(n); --i)
const ll MOD = 1000000007;
const ll MMOD = 998244353;
const double pi = 3.14159265358979323846;

struct point{
    dl x, y;
};

int main(void){
    int h, m, t;
    dl a, b, hkaku, mkaku, res;
    cin >> a >> b >> h >> m;
    t = h * 60 + m;
    hkaku = (dl)(t %= (12 * 60)) / (12 * 60) * 2 * pi;
    mkaku = (dl)(t %= 60) / 60 * 2 * pi;
    res = sqrt(a*a + b*b - 2 * a * b * cos(hkaku - mkaku));
    cout << fixed << setprecision(10) << res << endl; 
    return 0; 
}

Measured memory_bytes: 4084
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define INF 1e9
#define PI 3.14159265359
#define MOD 1000000007
#define ALL(v) v.begin(),v.end()
#define ALLR(v) v.rbegin(),v.rend()
typedef long long ll;
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
//isPrime
//modpow modinv
//getDigit
int main() {
  cout << fixed << setprecision(10);
  int n;
  cin >> n;
  cout << n/3 << endl;
}


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

using namespace std;
using int64 = long long;

constexpr int DEBUG = 0;

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

  int n;
  cin >> n;
  vector<int> xs(n);
  for (int i = 0; i < n - 1; i++) {
    int p;
    cin >> p;
    p--;
    xs[p]++;
  }
  for (int i = 0; i < n; i++) {
    cout << xs[i] << endl;
  }
}

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

int main() {
  
  int A, B, K; cin >> A >> B >> K; vector<int> vec;
  
  for (int i = 1; i < 101; i++) {
    if (A % i == 0 && B % i == 0) vec.push_back(i);
  }
  
  cout << vec.at(vec.size() - K) << endl;
  
}

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


#define REP(i,n) for (int i = 0; (i) < (n); ++ (i))
#define FOR(i,n) for (int i = 1; (i) <= (n); ++ (i))
#define dump(x)  cout << #x << " = " << (x) << endl;
#define pb push_back
#define int long long
//#define lint long long

const int INF = 1e9;
const int MOD = 1e9+7;
//const lint LINF = 1e18;
const double eps = 0.000000001;//もとの値の10^(-16)まで

using namespace std;

//typedef pair<int, int> P;


int n , k;
int d[14];
int ans;
signed main(){
  cin >> n >> k;
  REP(i,k){
    int t;
    cin >> t;
    d[t] ++;
  }
  for(int i = n;i<20*n;i++){
    string s = to_string(i);
    int fr = 0;
    REP(j,s.size()){
      if(d[s[j]-'0'] == 1) fr = 1;
    }
    if(fr==0){
      ans = i;
      break;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
int main()
{
    string s;
    cin >> s;
    string week="aaaSATFRITHUWEDTUEMONSUN";
    cout<<week.find(s)/3<<endl;
}

Measured memory_bytes: 256
a = gets.chomp
fline = readlines
len = fline.length
i = 0
while i < len
    fline[i] = fline[i].chomp.split(" ")
    i += 1
end
flinekai = fline.map{|item| item[0].to_i }
c = flinekai.max
d = flinekai.index(c)
flinekai2 = fline.map{|item| item[1].to_i }
p c + flinekai2[d]

Measured memory_bytes: 23300
#include<iostream>

using namespace std;
int main()
{
int n,i,temp;
cin>>n;
  int brr[100000];
  for(i=0;i<n;i++)
  {
    cin>>temp;
    brr[temp-1]=i+1;
  }
 for(i=0;i<n;i++)
 {
 cout<<brr[i]<<' ';
 }
 return 0;
}

Measured memory_bytes: 1152
using System;

namespace ConsoleApplicationSample
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] head = Console.ReadLine().Split(' ');
            int row = int.Parse(head[0]);
            int column = int.Parse(head[1]);

            int[,] data = new int[row, column];
            for (int i = 0; i < row; i++)
            {
                string[] body = Console.ReadLine().Split(' ');
                for (int j = 0; j < column; j++)
                {
                    data[i, j] = int.Parse(body[j]);
                }
            }

            int[] columnSum = new int[column];
            for (int i = 0; i < row; i++)
            {
                int rowSum = 0;
                for (int j = 0; j < column; j++)
                {
                    Console.Write("{0} ", data[i, j]);
                    rowSum += data[i, j];
                    columnSum[j] += data[i, j];
                }
                Console.WriteLine(rowSum);
            }

            int total = 0;
            foreach (var item in columnSum)
            {
                Console.Write("{0} ", item);
                total += item;
            }
            Console.WriteLine(total);
        }
    }
}

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

long long f(long long n){
    return n * n * n * n * n;
}

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

    long long x;
    cin >> x;

    for(int i = -500; i <= 500; i++){
        for(int j = -500; j <= 500; j++){
            if(f(i) - f(j) == x){
                cout << i << ' ' << j << endl;
                return 0;
            }
        }
    }

    return 0;
}

Measured memory_bytes: 3640
def main():
    N, M = (int(i) for i in input().split())
    A = [int(i) for i in input().split()]
    bcs = [[int(i) for i in input().split()] for _ in range(M)]
    A.sort()
    bcs.sort(reverse=True,key=lambda c:c[1])

    cards = []
    for b,c in bcs:
        for i in range(b):
            cards.append(c)
            if len(cards) == N:
                break
        if len(cards) == N:
            break

    from itertools import zip_longest
    ans = 0
    for a,card in zip_longest(A,cards,fillvalue=0):
        if a < card:
            ans += card
        else:
            ans += a
    print(ans)

if __name__ == "__main__":
    main()


Measured memory_bytes: 87576
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
import java.util.StringTokenizer;
import java.io.BufferedReader;
import java.util.Comparator;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        MyScanner in = new MyScanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        ABC112D solver = new ABC112D();
        solver.solve(1, in, out);
        out.close();
    }

    static class ABC112D {
        public void solve(int testNumber, MyScanner in, PrintWriter out) {
            long N = in.Int();
            long M = in.Int();

            long m = M;
            List<Long> list = new ArrayList<>();
            for (long i = 1; i <= Math.sqrt(m); i++) {
                if (m % i == 0) {
                    list.add(i);
                    list.add(m / i);
                }
            }
            list.sort(Comparator.naturalOrder());

            long ans = 0;
            for (long i : list) {
                if (M % i == 0 && M >= i * N && (M - i * N) % i == 0) {
                    ans = i;
                }
            }
            out.println(ans);

        }

    }

    static class MyScanner {
        private BufferedReader in;
        private StringTokenizer st;

        public MyScanner(InputStream stream) {
            in = new BufferedReader(new InputStreamReader(stream));
        }

        public String next() {
            while (st == null || !st.hasMoreTokens()) {
                try {
                    String rl = in.readLine();
                    if (rl == null) {
                        return null;
                    }
                    st = new StringTokenizer(rl);
                } catch (IOException e) {
                    return null;
                }
            }
            return st.nextToken();
        }

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

    }
}



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

#define ll long long
const int kmod = 1e9 + 7;

vector<int>par(200006);

vector<int>cap(200006);
int find(int a)
{
    if(par[a] == a)
     return a;

  return par[a] = find(par[a]);
}
int main() {

    
    int n , m;
    cin>>n>>m;
    

    for(int i = 0 ;i<= n ;i++)
     par[i] = i,cap[i] = 1;

    for(int i = 0 ; i<m ;i++)
    {
        int a,b;
        cin>>a>>b;

       int pa = find(a);
       int pb = find(b);


       if(pa != pb)
       {
           par[pa] = pb;

           find(a);

           cap[pb] = cap[pa] + cap[pb] ;
 
           cap[pa] = 0;
       }
    }

    int omax = 0;

    for(int i = 0 ; i<= n ;i++)
    omax = max(omax , cap[i]);

    cout<<omax<<endl;
   
}


Measured memory_bytes: 4688
import java.util.HashSet;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        try (Scanner sc = new Scanner(System.in)) {
            int H = sc.nextInt();
            int W = sc.nextInt();
            int M = sc.nextInt();
            int[] h = new int[M];
            int[] w = new int[M];
            HashSet<Long> set = new HashSet<>();
            for (int i = 0; i < M; i++) {
                h[i] = sc.nextInt() - 1;
                w[i] = sc.nextInt() - 1;
                set.add(v(h[i], w[i]));
            }

            int[] sumH = new int[H];
            int[] sumW = new int[W];
            for (int i = 0; i < M; i++) {
                sumH[h[i]]++;
                sumW[w[i]]++;
            }

            int maxH = 0;
            int maxH2 = 0;
            int maxW = 0;
            int maxW2 = 0;
            for (int h2 = 0; h2 < H; h2++) {
                if (sumH[h2] > maxH) {
                    maxH = sumH[h2];
                    maxH2 = h2;
                }
            }
            for (int w2 = 0; w2 < W; w2++) {
                if (sumW[w2] > maxW) {
                    maxW = sumW[w2];
                    maxW2 = w2;
                }
            }

            int max = 0;
            for (int i = 0; i < M; i++) {
                max = Math.max(max, sumH[h[i]] + sumW[w[i]] - 1);
            }
            for (int h2 = 0; h2 < H; h2++) {
                max = Math.max(max, sumH[h2] + sumW[maxW2] - (set.contains(v(h2, maxW2)) ? 1 : 0));
            }
            for (int w2 = 0; w2 < W; w2++) {
                max = Math.max(max, sumW[w2] + sumH[maxH2] - (set.contains(v(maxH2, w2)) ? 1 : 0));
            }
            System.out.println(max);
        }
    }

    private static long v(int r, int c) {
        return (((long) r) << 32) | c;
    }

}


Measured memory_bytes: 82420
/*
Look at the star
Look at the shine for U
*/
#include<bits/stdc++.h>
#define ll long long
#define PII pair<int,int>
#define sl(x) scanf("%lld",&x)
using namespace std;
const int N = 1e6+5;
const int mod = 1e9+7;
const int INF = 0x3f3f3f3f;
const double PI = acos(-1);
ll inv(ll b){if(b==1)return 1; return (mod-mod/b)*inv(mod%b)%mod;}
ll fpow(ll n,ll k){ll r=1;for(;k;k>>=1){if(k&1)r=r*n%mod;n=n*n%mod;}return r;}
ll vis[N];
int main()
{
    ll i,j,k,n;
    sl(n);
    vis[n] = 1;
    for(i = 2;;i++)
    {
        if(n&1)
            n = 3*n+1;
        else
            n /= 2;
        if(vis[n])
        {
            printf("%lld\n",i);
            return 0;
        }
        vis[n] = 1;
    }
    return 0;
}

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

float ts[102],te[102],vmax[102];
float v[40005];


float f(int j, float x){
  if(x<=ts[j]){
    return vmax[j]+(ts[j]-x);
  }else if(ts[j]<x&&x<=te[j]){
    return vmax[j];
  }else{
    return vmax[j]+(x-te[j]);
  }
}


int main(){
  int N;
  cin>>N;
  ts[0]=0;
  te[0]=0;
  for(int i=1;i<=N;i++){
    int t;
    cin>>t;
    ts[i]=te[i-1];
    te[i]=ts[i]+t;
  //  cout<<"ts["<<i<<"]="<<ts[i]<<endl;
  //  cout<<"te["<<i<<"]="<<te[i]<<endl;
  }
  ts[N+1]=te[N];
  te[N+1]=ts[N+1];
  int T=te[N+1];
  for(int i=1;i<=N;i++){
    cin>>vmax[i];
  }
  vmax[0]=0.0;
  vmax[N+1]=0.0;
  float INF=10000000000000.0;
  fill(v,v+2*T,INF);
  for(int i=0;i<=2*T;i++){
    for(int j=0;j<N+2;j++){
      v[i]=min(v[i],f(j,i/2.0));
    }
    //cout<<"v["<<i<<"]="<<v[i]<<endl;
  }
  float ans=0.0;
  for(int i=1;i<=2*T;i++){
    ans+=0.25*(v[i]+v[i-1]);
  }
  printf("%f\n",ans);
  return 0;
}


Measured memory_bytes: 384