akhauriyash/Code-Regression huggingface dataset:
def main():
    n,m = map(int,input().split())
    MOD = 10**9 + 7

    fact = [1]
    fact_inv = [1]
    for i in range(m):
        fact.append(fact[-1]*(i+1)%MOD)
    fact_inv = [1] * (m+1)
    fact_inv[m] = pow(fact[m],MOD-2,MOD)
    for i in range(m):
        fact_inv[m-i-1] = fact_inv[m-i] * (m-i) % MOD
    # print(fact_inv)


    ｍPn = fact[m] * pow(fact[m-n],MOD-2,MOD) % MOD

    a = pow(mPn,2,MOD)
    b = 0
    for i in range(1,n+1):
        nCr = fact[n] * fact_inv[i] % MOD * fact_inv[n-i] % MOD
        b += (-1)**(i%2) * nCr * fact[m-i] % MOD * fact_inv[m-n] % MOD
        b %= MOD
    ans = a + b * mPn
    print(ans%MOD)


main()




Measured memory_bytes: 48668
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const int inf = 1000000000;

int main(){
    int a;
    cin >> a;
    cout << a+ a*a +a*a*a << endl;
}

Measured memory_bytes: 3616
#include <stdlib.h> 
#include <stdio.h>
#include <string.h>
#include<iostream>
using namespace std;
int main()
{
	int a[4][11],b[4][11],c[4][11],d[4][11];
	
	int n,k,f,r,v;
	while(cin>>n)//????????????????????????
	{
		memset(a,0,4*11*sizeof(int));//?????¶??§?????°?????????????°±????°?????°±?°´?°¬?????????????°±??????0??????1???????????±???????????¨????°±????????±?°±?\?
	memset(b,0,4*11*sizeof(int));
	memset(c,0,4*11*sizeof(int));
	memset(d,0,4*11*sizeof(int));
		for(int i=1;i<=n;i++)
			{
				cin>>k>>f>>r>>v;
		if(k==1)
			a[f][r]+=v;
		if(k==2)
			b[f][r]+=v;
		if(k==3)
			c[f][r]+=v;
		if(k==4)
			d[f][r]+=v;//+=???=+????????????????????????
		}//???????????¬?????????????????????????????°???
		//??????????????????????????¶?????????continue
		for(int i=1;i<=3;i++)
			{
				for(int j=1;j<=10;j++)
				{
					cout<<" "<<a[i][j];
		if(j==10)
			cout<<endl;
				}
		}
		for(int k=0;k<20;k++)
			{
				cout<<"#";
		if(k==19)
			cout<<endl;
		}

			for(int i=1;i<=3;i++)
			{
				for(int j=1;j<=10;j++)
				{
					cout<<" "<<b[i][j];
		if(j==10)
			cout<<endl;
				}
		}
			for(int k=0;k<20;k++)
			{
				cout<<"#";
		if(k==19)
			cout<<endl;
		}


			for(int i=1;i<=3;i++)
			{
				for(int j=1;j<=10;j++)
				{
					cout<<" "<<c[i][j];
		if(j==10)
			cout<<endl;
				}
		}
			for(int k=0;k<20;k++)
			{
				cout<<"#";
		if(k==19)
			cout<<endl;
		}

			for(int i=1;i<=3;i++)
			{
				for(int j=1;j<=10;j++)
				{
					cout<<" "<<d[i][j];
		if(j==10)
			cout<<endl;
				}
			}
	}
}

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

int main() {
  string s;
  cin >> s;
  
  if(s.at(s.size()-1) == '6') cout << "pon" << endl;
  else  if(s.at(s.size()-1) == '8') cout << "pon" << endl;
  else  if(s.at(s.size()-1) == '1') cout << "pon" << endl;
  else if(s.at(s.size()-1) =='0') cout << "pon" << endl;
  else  if(s.at(s.size()-1) == '3') cout << "bon" << endl;
  else  if(s.at(s.size()-1) == '2') cout << "hon" << endl;
  else  if(s.at(s.size()-1) == '4') cout << "hon" << endl;
  else  if(s.at(s.size()-1) == '5') cout << "hon" << endl;
  else  if(s.at(s.size()-1) == '7') cout << "hon" << endl;
  else  if(s.at(s.size()-1) == '9') cout << "hon" << endl;
  
}



Measured memory_bytes: 3624
import java.util.*;

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

Measured memory_bytes: 35728
import math
from collections import deque
from collections import defaultdict

import itertools as it

#自作関数群
def readInt():
	return int(input())
def readInts():
	return list(map(int, input().split()))
def readChar():
	return input()
def readChars():
	return input().split()
def factorization(n):
	res = []
	if n%2==0:
		res.append(2)
	for i in range(3,math.floor(n//2)+1,2):
		if n%i==0:
			c = 0
			for j in res:
				if i%j==0:
					c=1
			if c==0:
				res.append(i)
	return res
def fact2(n):
	p = factorization(n)
	res = []
	for i in p:
		c=0
		z=n
		while 1:
			if z%i==0:
				c+=1
				z/=i
			else:
				break
		res.append([i,c])
	return res
def fact(n):#階乗
	ans = 1
	m=n
	for _i in range(n-1):
		ans*=m
		m-=1
	return ans
def comb(n,r):#コンビネーション
	if n<r:
		return 0
	l = min(r,n-r)
	m=n
	u=1
	for _i in range(l):
		u*=m
		m-=1
	return u//fact(l)
def combmod(n,r,mod):
	return (fact(n)/fact(n-r)*pow(fact(r),mod-2,mod))%mod
def printQueue(q):
	r=copyQueue(q)
	ans=[0]*r.qsize()
	for i in range(r.qsize()-1,-1,-1):
		ans[i] = r.get()
	print(ans)
class UnionFind():
	def __init__(self, n):
		self.n = n
		self.parents = [-1]*n

	def find(self, x): # root
		if self.parents[x]<0:
			return x
		else:
			self.parents[x] = self.find(self.parents[x])
			return self.parents[x]

	def union(self,x,y):
		x = self.find(x)
		y = self.find(y)

		if x==y:
			return

		if self.parents[x]>self.parents[y]:
			x,y = y,x

		self.parents[x]+=self.parents[y]
		self.parents[y]=x

	def size(self,x):
		return -1*self.parents[self.find(x)]

	def same(self,x,y):
		return self.find(x)==self.find(y)

	def members(self,x): # much time
		root = self.find(x)
		return [i for i in range(self.n) if self.find(i)==root]

	def roots(self):
		return [i for i,x in enumerate(self.parents) if x<0]

	def group_count(self):
		return len(self.roots())

	def all_group_members(self):
		return {r: self.members(r) for r in self.roots()} # 1~n
def bitArr(n):#ビット全探索
	x = 1
	zero = "0"*n
	ans = []
	ans.append([0]*n)
	for i in range(2**n-1):
		ans.append(list(map(lambda x:int(x),list((zero+bin(x)[2:])[-1*n:]))))
		x+=1
	return ans;
def arrsSum(a1,a2):
	for i in range(len(a1)):
		a1[i]+=a2[i]
	return a1
def maxValue(a,b,v):
	v2 = v
	for i in range(v2,-1,-1):
		for j in range(v2//a+1): #j:aの個数
			k = i-a*j
			if k%b==0:
				return i
	return -1
def copyQueue(q):
	nq = queue.Queue()
	n = q.qsize()
	for i in range(n):
		x = q.get()
		q.put(x)
		nq.put(x)
	return nq
def get_sieve_of_eratosthenes(n):
	#data = [2]
	data = [0,0,0]
	for i in range(3,n+1,2):
		data.append(i)
		data.append(0)
	for i in range(len(data)):
		interval = data[i]
		if interval!=0:
			for j in range(i+interval,n-1,interval):
				data[j] = 0
	#ans = [x for x in data if x!=0]
	ans = data[:]
	return ans

n = readInt()
t = readInts()
m = readInt()
px = []
for i in range(m):
	px.append(readInts())
sumTime = sum(t)

for i in range(m):
	print(sumTime-t[px[i][0]-1]+px[i][1])

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

const int MN=100000;

vector<int> e[MN];
int d[MN];


void dfs(int i)
{
  vector<int> ds(e[i].size());
  for(int x=0;x<e[i].size();x++){
    int j=e[i][x];
    dfs(j);
    ds[x]=d[j];
  }
  sort(ds.begin(),ds.end());
  d[i]=0;
  for(int x=0;x<ds.size();x++){
    d[i]=max(d[i],ds[x]+(int)ds.size()-x);
  }
  //printf("%d %d\n",i+1,d[i]);
}

int main()
{
  int n;
  scanf("%d",&n);
  static int a[MN];
  for(int i=1;i<n;i++){
    scanf("%d",a+i);
    a[i]--;
    e[a[i]].push_back(i);
  }
  dfs(0);
  printf("%d\n",d[0]);
  return 0;
}


Measured memory_bytes: 17408
use std::io::stdin;
use std::str::FromStr;
#[allow(dead_code, unused_mut)]
fn read<T: FromStr>() -> T {
    let mut s = String::new();
    stdin().read_line(&mut s).ok();
    s.trim().parse().ok().expect("1")
}
#[allow(dead_code, unused_mut)]
fn read_vec<T: FromStr>() -> Vec<T> {
    read::<String>().split_whitespace()
        .map(|e| e.parse().ok().expect("2"))
        .collect()
}
#[allow(dead_code, unused_mut)]
fn read_two<T: FromStr>() -> (T, T) {
    let mut s = String::new();
    stdin().read_line(&mut s).unwrap();
    let mut x = s.split_whitespace().map(|x| x.parse().ok().unwrap());
    (x.next().unwrap(), x.next().unwrap())
}
#[allow(dead_code, unused_mut)]
fn read_three<T: FromStr>() -> (T, T, T) {
    let mut s = String::new();
    stdin().read_line(&mut s).unwrap();
    let mut x = s.split_whitespace().map(|x| x.parse().ok().unwrap());
    (x.next().unwrap(), x.next().unwrap(), x.next().unwrap())
}
#[allow(dead_code)]
fn remove_whitespace(s: &str) -> String {
    s.chars().filter(|c| !c.is_whitespace()).collect()
}
use std::io::{Write, stdout};
fn main() {
    let n:usize = read();
    let mut a: Vec<i32> = read_vec();
    let mut b: Vec<(usize, i32)> = Vec::new();
    for i in 0..n {
        b.push((i, a[i]));
    }
    b.sort_by(|x, y| x.1.cmp(&y.1));
    //let b: Vec<usize> = b.into_iter().map(|x| x.0 + 1).collect();
    let out = stdout();
    let mut out = out.lock();
    for i in b {
        write!(out, "{} ", i.0 + 1).unwrap();
    }
}

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

int main(){
    int n;
    cin >> n;
    long a[n];
    for(int i =0; i < n; i++){
        cin >> a[i];
    }
    int count = 0;   
    
    for(int i = 0; i < 160; i++){
        bool isOdd = false;
        for(int j = 0; j < n; j++){
            if(a[j] %2 != 0) isOdd = true;
        }
        if(isOdd) break;
        for(int j = 0; j < n; j++){
            a[j] /= 2;
        }
        count++;
    }
    cout << count;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll, ll> Pll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repn(i, n) for (int i = 0; i <= (int)(n); i++)
#define srep(i, l, n) for (int i = l; i < (int)(n); i++)
#define srepn(i, l, n) for (int i = l; i <= (int)(n); i++)
#define pb push_back 
#define debug(var)  do{std::cout << #var << " : ";view(var);}while(0)
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ view(v); } }
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

const int MOD = 1000000007;
const int INF = 1e9;
#define PI 3.14159265369;
int dx[4] = {1,-1,0,0};
int dy[4] = {0,0,1,-1};
int ddx[8] = {1,1,1,-1,-1,-1,0,0};
int ddy[8] = {0,1,-1,0,1,-1,1,-1};


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

	int n, m, q;
	cin >> n >> m >> q;
	int ex[n+1][n+1];
	for(int i = 0; i <= n; i++) {
		for(int j = 0; j <= n; j++) {
			ex[i][j] = 0;
		}
	}
	for(int i = 0; i < m; i++) {
		int a, b;
		cin >> a >> b;
		ex[a][b]++;
	}
	for(int i = 1; i <= n; i++) {
		for(int j = 1; j <= n; j++) {
			ex[i][j] = ex[i][j] + ex[i][j-1];
		}
	}
	for(int i = 1; i <= n; i++) {
		for(int j = 1; j <= n; j++) {
			ex[i][j] = ex[i][j] + ex[i-1][j];
		}
	}

	while(q--) {
		int a, b;
		cin >> a >> b;
		int ans = ex[b][b]-ex[b][a-1]-ex[a-1][b]+ex[a-1][a-1];
		cout << ans << endl;
	}
}

Measured memory_bytes: 1920
#include <iostream>
#include <algorithm>
#include <string>
#include <list>
#include<vector>
#include <sstream>
#include <stdio.h>
#include <valarray>
#include <iomanip>
#include <unordered_set>
#include <set>
using namespace std;

int main(void)
{
	int Tmp = 0;
	for (int i=0;i<5;i++)
	{
		cin >> Tmp;
		if (Tmp==0)
		{
			cout << (i + 1) << endl;
			return 0;
		}
	}

	return 0;
}

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

int main(){

    int N, K;
    cin >> N >> K;
    vector<int> p(N);
    rep (i, N) cin >> p[i];
    sort(p.begin(), p.end());

    int ans = 0;
    rep(i, K) ans += p[i];

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i, n) for(ll i=0; i<(ll)n; i++)
#define REPR(i, n) for(ll i=(ll)n-1; i>=0; i--)
#define FOR(i, m, n) for(ll i=(ll)m; i<(ll)n; i++)
#define FORR(i, m, n) for(ll i=(ll)m-1; i>=(ll)n; i--)
#define ALL(x) (x).begin(), (x).end()
#define ASC(v) sort(ALL(v));
#define DESC(v) sort(ALL(v), greater<int>());
#define UNIQ(a) sort(ALL(a));(a).resize(unique(ALL(a)) - a.begin());
#define PRINTD(x, d) cout << fixed << setprecision(d) << x << "\n";
#define DEBUG(x) cout<<#x<<": "<<x<<"\n"
const double PI = acos(-1);
ll lcm(ll a, ll b) { return a / __gcd(a, b) * b; }
bool isprime(int x){ int i; if(x<2)return 0; else if(x==2) return 1; if(x%2==0) return 0; for(i=3; i*i<=x; i+=2) if(x%i==0) return 0; return 1; }
int digsum(int n) { int r=0; while(n>0) { r+=n%10; n/=10; } return r; }
vector<string> split(string s, char p){vector<string>v;stringstream m(s);string b;while(getline(m,b,p))v.push_back(b);return v;}
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a = b; return 1; } return 0; }
struct nya{ nya(){ cin.tie(0); ios::sync_with_stdio(false); } }nyan;


int main(){
    ll N;
    cin >> N;
    vector<ll> L(N+1);
    L[0] = 2;
    L[1] = 1;
    FOR(i, 2, N+1) L[i] = L[i-1] + L[i-2];
    cout << L[N] << "\n";
}


Measured memory_bytes: 256
k, t = map(int, input().split())
A = list(map(int, input().split()))
A.sort(reverse=True)

C = []
for i in range(t):
    C += [i]*A[i]

from collections import deque
B = deque(C)
L = [-1]*k
for i in range(k):
    if i%2 == 0:
        L[i] = B.popleft()
    else:
        L[i] = B.pop()

ans1 = 0
for i in range(1, k):
    if L[i-1] == L[i]:
        ans1 += 1

B = deque(C)
L = [-1]*k
for i in range(k):
    if i%2 == 0:
        L[i] = B.pop()
    else:
        L[i] = B.popleft()

ans2 = 0
for i in range(1, k):
    if L[i-1] == L[i]:
        ans2 += 1

print(min(ans1, ans2))


Measured memory_bytes: 3572
#include<stdio.h>

int main()
{
    int A,B,C;
    scanf("%d%d%d",&A,&B,&C);
    if((1<=A)&&(A<=10)&&(1<=B)&&(B<=10)&&(1<=C)&&(C<=10))
{
    if(A==5&&B==5&&C==7)
    {
     printf("YES");
    }
    else if(A==5&&B==7&&C==5)
    {
     printf("YES");
    }
    else if(A==7&&B==5&&C==5)
    {
    printf("YES");
    }
    else
    {
    printf("NO");
    }
    }
    return 0;
}
   

Measured memory_bytes: 128
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>

#define rep(i,n) for(int i=0;i<(n);i++)
typedef long long LL;
using namespace std;

int main() {
	LL n, a, b; cin >> n >> a >> b;
	LL c = a + b;
	LL ans = 0;

	if (!a) {
		cout << 0 << endl;
		return 0;
	}
	if (!b) {
		cout << n << endl;
		return 0;
	}
	ans += n / (a + b)*a;
	ans += min(n % (a + b), a);
	
	cout << ans << endl;

	return 0;
}

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

void swap(int &a, int &b){
	int temp;
	temp=a;
	a=b;
	b=temp;
}

int main() {
	int x,y;
	for(int i; i<3000;i++){
		std::cin>> x>>y ;
		if(x==0 && y==0) break;
		if (x>y) swap(x,y);
		std::cout << x<<" "<<y <<std::endl;

	}
	return 0;
}

Measured memory_bytes: 3056
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Scanner;


public class Main {
	public static void main(String[] args) throws IOException{

		Scanner sc = new Scanner(new InputStreamReader(System.in));
		int a = sc.nextInt();
		int x = 0;

		for(int i = 1;i<a+1;i++){
			x = x+i;
		}
        System.out.println(x);
	}
}


Measured memory_bytes: 21588
#include<bits/stdc++.h>
using namespace std;
struct node {
	int x,y;
}a[100005];
bool cmp(node q,node p){
	return (q.x+q.y)>(p.x+p.y);
}
int main(){
	int n;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>a[i].x>>a[i].y;
	}
	sort(a,a+n,cmp);
	long long cnt =0;
	for(int i=0;i<n;i++){
		if(i%2==0){
			cnt+=a[i].x;
		}
		else 
			cnt-=a[i].y;
	}
	cout<<cnt<<endl;
} 

Measured memory_bytes: 1024
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		int a,b=1;
		while(true) {
		 a = sc.nextInt();
		 if(a==0)break;
		 System.out.println("Case " + b++ + ": " + a);

		}


    }

}



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

int n;
int a[212345];
long long S,sum1,sum2;

int main() {
 //   freopen("test.txt","r",stdin);
    cin >> n ;
    for (int i =1 ; i <= n ; i++) cin >> a[i] , S += a[i];
    long long ans = 10e10;
    for (int i =1 ; i < n ; i++) {
        sum1 += a[i];
        sum2 = S - sum1;
        ans = min(ans, abs(sum1 - sum2));
    }
    cout << ans;
}


Measured memory_bytes: 1024
#include "bits/stdc++.h"
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a),i##_len=(b);i<i##_len;++i)
#define BUGAVOID(x) x
#define rep(...) BUGAVOID(_overload3(__VA_ARGS__,repi,_rep,_rep)(__VA_ARGS__))
#define sz(c) (int)(c.size())
#define all(c) c.begin(),c.end()
#define mp make_pair
#define write(x) cout<<(x)<<"\n"
using namespace std; typedef long long ll;
typedef vector<int> vi; typedef vector<ll> vll; template<class T, class U>using vp = vector<pair<T, U>>;
template<class T>using vv = vector<vector<T>>; template<class T, class U>using vvp = vv<pair<T, U>>;
template<class T>vv<T> vvec(size_t n, size_t m, T v) { return vv<T>(n, vector<T>(m, v)); }
template<class T>bool chmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }
template<class T>bool chmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
constexpr int INF = 1 << 28, MAX = 1e5 + 5, MOD = 998244353;
constexpr ll LINF = 1ll << 60; constexpr double EPS = 1e-6;
constexpr int dy[4] = { 0,1,0,-1 }, dx[4] = { 1,0,-1,0 };
struct aaa { aaa() { cin.tie(0); ios::sync_with_stdio(0); }; }aaaa;

int main() {
    int N;
    string S;
    cin >> N >> S;

    int cnt = 0;
    rep(i, N) {
        if (S[i] == '.') cnt++;
    }

    int ans = cnt;
    rep(i, 1, N + 1)  {
        if (S[i - 1] == '.') cnt--;
        else cnt++;

        chmin(ans, cnt);
    }

    write(ans);
}


Measured memory_bytes: 3764
#include <bits/stdc++.h>
using namespace std;
const int N = 3e3+5;

string s, t;
int dp[N][N];

void print(int n, int m)
{
	if (!n || !m) return;
	if (s[n-1] == t[m-1])
	{
		print(n - 1, m - 1);
		cout << s[n-1];
	}
	else
	{
		if (dp[n][m] == dp[n-1][m])	print(n - 1, m);
		else	print(n, m - 1);
	}
}

int main()
{
	cin >> s >> t;
	int n = s.length();
	int m = t.length();
	for (int i = 1; i <= n; i++)
	{
		for (int j = 1; j <= m; j++)
		{
			if (s[i-1] == t[j-1])	dp[i][j] = dp[i-1][j-1] + 1;
			else	dp[i][j] = max(dp[i-1][j], dp[i][j-1]);
		}
	}
	print(n, m);
	return 0;
}

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

int main() {
   int N;
   cin >> N;
   vector<ll> A(N);
   map<ll, ll> AA;
   ll sum = 0;
   for (int i = 0; i < N; i++) {
       cin >> A[i];
       AA[A[i]] += 1;
       sum += A[i];
   }
   int Q;
   cin >> Q;
   vector<ll> B(Q), C(Q);
   for (int i = 0; i < Q; i++) {
       cin >> B[i] >> C[i];
       if (AA.count(B[i])) {
           AA[C[i]] += AA[B[i]];
           sum += (C[i]-B[i])*AA[B[i]];
           AA.erase(B[i]);
       }
       cout << sum << endl;
   }
}

Measured memory_bytes: 9588
#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#include<stack>
#include<algorithm>
#include<cmath>
#include<climits>
#include<string>
#include<set>
#include<numeric>
#include<map>
#include<iostream>
using namespace std;
#define rep(i,n) for(int i = 0;i<((int)(n));i++)
#define reg(i,a,b) for(int i = ((int)(a));i<=((int)(b));i++)
#define irep(i,n) for(int i = ((int)(n)-1);i>=0;i--)
#define ireg(i,a,b) for(int i = ((int)(b));i>=((int)(a));i--)
typedef long long ll;
typedef pair<ll, ll> mp;
ll MOD = 1e9+7;
//LLONG_MIN


int main(void){
	bool is_loop=true;
	ll a,b,c,ans=0;
	cin>>a>>b>>c;
	while(true){
		if(a%2==1 || b%2==1 || c%2==1){
			is_loop=false;
			break;
		}
		if(a==b && b==c){
			break;
		}
		ll x=(a+b)/2,y=(b+c)/2,z=(c+a)/2;
		a=x;
		b=y;
		c=z;
		ans++;
	}
	cout<<(is_loop?-1:ans)<<endl;
	return 0;
}

Measured memory_bytes: 256
// dfmt off
T lread(T=long)(){return readln.chomp.to!T;}T[] lreads(T=long)(long n){return iota(n).map!((_)=>lread!T).array;}
T[] aryread(T=long)(){return readln.split.to!(T[]);}void arywrite(T)(T a){a.map!text.join(' ').writeln;}
void scan(L...)(ref L A){auto l=readln.split;foreach(i,T;L){A[i]=l[i].to!T;}}alias sread=()=>readln.chomp();
void dprint(L...)(lazy L A){debug{auto l=new string[](L.length);static foreach(i,a;A)l[i]=a.text;arywrite(l);}}
static immutable MOD=10^^9+7;alias PQueue(T,alias l="b<a")=BinaryHeap!(Array!T,l);import std, core.bitop;
// dfmt on

void main()
{
    auto S = aryread!string();
    S.map!"a[0]".array().writeln();
}


Measured memory_bytes: 3704
#include<iostream>
using namespace std;
int main()
{
    int n, a[4];
    cin >> n;
    for(int i = 3; i >= 0; i--){
        a[i] = n % 10;
        n /= 10;
    }
    if     (a[0]+a[1]+a[2]+a[3] == 7) printf("%d+%d+%d+%d=7", a[0], a[1], a[2], a[3]);
    else if(a[0]+a[1]+a[2]-a[3] == 7) printf("%d+%d+%d-%d=7", a[0], a[1], a[2], a[3]);
    else if(a[0]+a[1]-a[2]+a[3] == 7) printf("%d+%d-%d+%d=7", a[0], a[1], a[2], a[3]);
    else if(a[0]-a[1]+a[2]+a[3] == 7) printf("%d-%d+%d+%d=7", a[0], a[1], a[2], a[3]);
    else if(a[0]+a[1]-a[2]-a[3] == 7) printf("%d+%d-%d-%d=7", a[0], a[1], a[2], a[3]);
    else if(a[0]-a[1]+a[2]-a[3] == 7) printf("%d-%d+%d-%d=7", a[0], a[1], a[2], a[3]);
    else if(a[0]-a[1]-a[2]+a[3] == 7) printf("%d-%d-%d+%d=7", a[0], a[1], a[2], a[3]);
    else if(a[0]-a[1]-a[2]-a[3] == 7) printf("%d-%d-%d-%d=7", a[0], a[1], a[2], a[3]);
    return 0;
}

Measured memory_bytes: 256
//おまじない
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <utility>
#define INF 1e9+7
#define rep(i,m,n) for(int i=m;i<n;i++)
#define mrep(i,m,n) for(int i=m;i>n;i--)
#define NO cout<<"NO"<<endl;
#define YES cout << "YES"<<endl;
#define No cout << "No"<<endl;
#define Yes cout << "Yes"<<endl;
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;


//(int)'a'は97 (int)'A'は65 (int)'1'は49
//おまじない

int n, m;
int ans = 0;
int pass[8][8] = { 0 };
bool city[8];
int reach = 1;

void cal(int s) {
	if (reach == n) {
		ans++;
		return;
	}
	else {
		rep(i, 0, n) {
			if (pass[s][i] == 1 && !city[i]) {
				city[i] = true;
				reach++;
				cal(i);
				city[i] = false;
				reach--;
			}
		}
	}
	return;
}

int main() {

	cin >> n >> m;
	rep(i, 0, m) {
		int a, b; cin >> a >> b;
		pass[a - 1][b - 1] = pass[b - 1][a - 1] = 1;
	}

	rep(i, 0, n) {
		city[i] = false;
	}
	city[0] = true;
	cal(0);

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;
int odd,mult2,mult4;
int main(){
    int n;
    cin>>n;
    for(int i=1;i<=n;i++){
        int x;
        cin>>x;
        if(x%2 == 1){
            odd++;
        }
        if(x%4 == 2){
            mult2++;
        }
        if(x%4 == 0){
            mult4++;
        }

    }
    if(odd>mult4+1){
        cout<<"No"<<endl;
    }else{
        if(odd==mult4+1 && mult2){
            cout<<"No"<<endl;
            return 0;
        }

        cout<<"Yes"<<endl;
    }

}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define INF (1<<30)
#define INFLL (1ll<<60)
typedef pair<ll, ll> P;
#define MOD (1000000007ll)
#define l_ength size

int main(void){
	int n;
	string s;
	cin >> s;
	n = s.l_ength();
	cout << s[0] << (n-2) << s[n-1] << endl; 
	return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {

	int a, b, c, d;cin >> a >> b >> c >> d;
	int train, bus;
	if (a > b)train = b;
	else train = a;
	if (c > d)bus = d;
	else bus = c;
	cout << train + bus << endl;
	return 0;
}

Measured memory_bytes: 256
use std::io::*;
use std::str::FromStr;

fn main() {
	let n: usize = read();
	let s: String = read();
	let s: Vec<char> = s.chars().collect();
	let mut rgb: (usize, usize, usize) = (0, 0, 0);
	for c in &s {
		match c {
			'R' => rgb.0 += 1,
			'G' => rgb.1 += 1,
			'B' => rgb.2 += 1,
			_ => return (),
		}
	}
	let mut cnt: usize = 0;
	for i in 0..n-2 {
		for j in i+1..n-1 {
			let k = 2*j-i;
			if n <= k { break; }
			if s[i] != s[j] && s[j] != s[k] && s[k] != s[i] {
				cnt += 1;
			}
		}
	}
	let ans = rgb.0 * rgb.1 * rgb.2 - cnt;
	println!("{}", ans);
}

fn read<T: FromStr>() -> T {
	let stdin = stdin();
	let stdin = stdin.lock();
	let token: String = stdin
		.bytes()
		.map(|c| c.expect("failed to read char") as char)
		.skip_while(|c| c.is_whitespace())
		.take_while(|c| !c.is_whitespace())
		.collect();
	token.parse().ok().expect("failed to parse token")
}



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

#define rep(i, n) for(int i = 0; i<(n); i++)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
typedef long long ll;

const int MAX_N = 50;
int N, M;
bool graph[MAX_N][MAX_N];
bool visited[MAX_N];

void dfs(int v) {
    if (visited[v]) return;
    visited[v] = true;
    rep(nv, N) {
        if (!graph[v][nv]) continue;
        dfs(nv);
    }
}

int main() {
    cin >> N >> M;
    vector<int> a(M), b(M);
    rep(i, M) {
        cin >> a[i] >> b[i];
        a[i]--;
        b[i]--;
        graph[a[i]][b[i]] = graph[b[i]][a[i]] = true;
    }

    int ans = 0;
    rep(i, M) {
        graph[a[i]][b[i]] = graph[b[i]][a[i]] = false; // 橋を壊す

        rep(j, N) visited[j] = false;
        dfs(0);
        bool bridge = false;
        rep(j, N) if (!visited[j]) bridge = true;
        if (bridge) ans++;

        graph[a[i]][b[i]] = graph[b[i]][a[i]] = true;// 橋を作る
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;

int main() {
    int N, K;

    cin >> N >> K;

    vector<int> stones(N);

    for (int i = 0; i < stones.size(); i++) {
        cin >> stones[i];
    }

    sort(stones.begin(), stones.end());
    vector<bool> dp(K + 1);

    for (int i = 1; i <= K; i++) {
        for (int j = 0; j < stones.size(); j++) {
            if (stones[j] > i) {
                break;
            }

            if (!dp[i - stones[j]]) {
                dp[i] = true;
                break;
            }
        }
    }

    if (dp[K]) {
        cout << "First" << endl;
    }
    else {
        cout << "Second" << endl;
    }
}

Measured memory_bytes: 3112
#include <stdio.h>
#include <stdlib.h>

int compar(const int *val1,const int *val2){
    return *val1-*val2;
}
int main(void){
    int map[12]={0},i;
    for(i=0;i<12;i++)
        scanf("%d",&map[i]);
    qsort(map,12,sizeof(int),(int(*)(const void *,const void *))compar);
       if(map[0] == map[3] && map[4] == map[7] && map[8] == map[11])
       printf("yes\n");
   else
       printf("no\n");
   return 0;
}

Measured memory_bytes: 584
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll MOD = 1e9+7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i = (m); i <= (n); i++)
#define rrep(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define printa(x,m,n) for(ll i = (m); i <= n; i++){cout << (x[i]) << " ";} cout<<endl;

ll n, m;
string s;

int main(){
	cin.tie(0); ios::sync_with_stdio(false);
	
	ll a, b;
	cin >> n >> a >> b;
	if(a > b){
		ll tmp = a;
		a = b;
		b = tmp;
	}
	
	if((b-a) % 2 == 0){
		print((b-a)/2)
	}
	else{
		ll p = min(a-1, n-b);
		a += p + 1;
		b += p;
		print(p+1+(b-a)/2)
	}
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
int len[50];
int d[5]={5,7,5,7,7};
int main(){
	int n;
	string s;
	while(true){
	cin>>n;
	if(n==0)break;
	for(int i=0;i<n;i++){
		cin>>s;
		len[i]=s.size();
	}
	int ans=100000;
	for(int i=0;i<n;i++){
		int cnt=0;
		int set=0;
		int j=i;
		bool ok=true;
		while(true){
			cnt+=len[j];
			if(cnt==d[set]){
				cnt=0;
				set++;
				if(set==5)break;
			}
			if(cnt>d[set]){
				ok=false;
				break;
			}
			j++;
			if(j==n){
				ok=false;
				break;
			}
		}
		if(ok){
			ans=min(ans,i+1);
		}
	}
	cout<<ans<<endl;
	}
	return 0;
}

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

#define mp make_pair
#define pb push_back
#define FAST_IO ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define FILE_IO(x) freopen((string(x) + ".in").c_str(), "r", stdin); freopen((string(x) + ".out").c_str(), "w", stdout)
#define f first
#define s second
#define x1 x1qwer
#define y1 y1qwer
#define foreach(it, v) for (auto it : v)
#define rep(it, n) for (int it = 0; it < n; ++it)
#define forin(it, l, r) for (int it = l; it < r; ++it)
#define all(x) x.begin(), x.end()

// #define FAST_ALLOCATOR_MEMORY 250000000
 
#ifdef FAST_ALLOCATOR_MEMORY
int allocator_pos = 0;
char allocator_memory[(int)FAST_ALLOCATOR_MEMORY];
inline void * operator new ( size_t n ) {
    char *res = allocator_memory + allocator_pos;
    allocator_pos += n;
    assert(allocator_pos <= (int)FAST_ALLOCATOR_MEMORY);
    return (void *)res;
}
inline void operator delete ( void * ) noexcept { }
//inline void * operator new [] ( size_t ) { assert(0); }
//inline void operator delete [] ( void * ) { assert(0); }
#endif

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const double DINF = numeric_limits<double>::infinity();
const ll MOD = 1e9 + 7;
const double EPS = 1e-7;
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
mt19937 mmtw_(MOD);
uniform_int_distribution<ll> rd_;
ll randomll() { return rd_(mmtw_);}
ll rnd(ll x, ll y) { return rd_(mmtw_) % (y - x + 1) + x; }
template <class T> T fact(T n) { if (n == 1) return 1; return n * fact(n - 1); }
////////////////////////////////////////////////////////////////////////////////////////////////

ll a[3];
int k;

int main() {
    rep(i, 3) {
        cin >> a[i];
    }
    cin >> k;

    sort(a, a + 3);

    rep(i, k) {
        a[2] *= 2;
    }

    cout << a[0] + a[1] + a[2] << endl;
}

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

using namespace std;

int H, W;
int cnt = 0;
string table[100];
map <int, bool> width;
map <int, bool> height;
bool flag;

int main() {
	cin >> H >> W;
	for (int i = 0; i < H; i++) {
		cin >> table[i];
		for (int j = 0; j < W; j++) {
			if (table[i][j] == '#') {
				flag = true;
			}
		}
		if (!flag) {
			height[i] = true;
		}
		flag = false;
	}
	for (int i = 0; i < W; i++) {
		for (int j = 0; j < H; j++) {
			if (table[j][i] == '#') flag = true;
			
		}
		if (!flag) {
			width[i] = true;
		}
		flag = false;
	}
	string s[100];
	for (int i = 0; i < H; i++) {
		if (!height[i]) {
			for (int j = 0; j < W; j++) {
				if (width[j]) continue;
				else {
					s[cnt] += table[i][j];
				}
			}
			cnt++;
		}
	}
	for (int i = 0; i < cnt; i++) {
		cout << s[i] << endl;
	}
	return 0;
}

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

/*BigInteger
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/rational.hpp>
namespace xxx = boost::multiprecision;
using Bint = xxx::cpp_int;
using Real = xxx::number<xxx::cpp_dec_float<1024>>;
*/

#define int long long
#define pb(x) push_back(x)
#define m0(x) memset((x), 0LL, sizeof(x))
#define mm(x) memset((x), -1LL, sizeof(x))

//container
#define ALL(x) (x).begin(), (x).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define EACH(i, c) for (typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define EXIST(s, e) ((s).find(e) != (s).end())
#define UNIQUE(v) (v).erase(unique((v).begin(), (v).end()), (v).end());
#define PERM(c) \
  sort(ALL(c)); \
  for (bool c##p = 1; c##p; c##p = next_permutation(ALL(c)))

// debug
#define GET_VAR_NAME(variable) #variable
#define test(x) cout << GET_VAR_NAME(x) << " = " << x << endl;

// bit_macro
#define Bit(n) (1LL << (n))
#define Bitset(a, b) (a) |= (1LL << (b))
#define Bitunset(a, b) (a) &= ~(1LL << (b))
#define Bitcheck(a, b) ((((a) >> (b)) & 1LL) == 1LL)
#define Bitcount(a) __builtin_popcountll((a))

//typedef
typedef long long lint;
typedef unsigned long long ull;
typedef complex<long double> Complex;
typedef pair<int, int> P;
typedef tuple<int, int, int> TP;
typedef vector<int> vec;
typedef vector<vec> mat;

//constant
constexpr int INF = (int)1e18;
constexpr int MOD = (int)1e9 + 7;
constexpr double PI = (double)acos(-1);
constexpr double EPS = (double)1e-10;
constexpr int dx[] = {-1, 0, 0, 1, 0, -1, -1, 1, 1};
constexpr int dy[] = {0, -1, 1, 0, 0, 1, -1, 1, -1};

//
template <typename T>
void chmax(T &a, T b) { a = max(a, b); }
template <typename T>
void chmin(T &a, T b) { a = min(a, b); }
//
inline int toInt(string s) {
  int v;
  istringstream sin(s);
  sin >> v;
  return v;
}
template <class T>
inline string toString(T x) {
  ostringstream sout;
  sout << x;
  return sout.str();
}

//
struct Accelerate_Cin {
  Accelerate_Cin() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout << fixed << setprecision(20);
  };
} Accelerate_Cin;

signed main() {
  int N, M, K;
  cin >> N >> M >> K;
  for (int i = 0; i <= N; i++) {
    for (int j = 0; j <= M; j++) {
      if (i * j + (N - i) * (M - j) == K) {
        cout << "Yes" << endl;
        return 0;
      }
    }
  }

  cout << "No" << endl;

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define fi first
#define se second
typedef pair<ll,ll> P;
using VP = vector<P>; using VVP = vector<VP>;
using VI = vector<int>; using VVI = vector<VI>; using VVVI = vector<VVI>;
const int inf=1e9+7;
const ll INF=1LL<<61;
const ll mod=1e9+7;

int main(){
  int i,j;
  int h,a;
  cin>>h>>a;
  cout<<(h+a-1)/a<<endl;
    
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define INF 1000000005
#define MOD 1000000007
#define EPS 1e-10
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;--i)
#define srep(i,s,t) for(int i=(int)(s);i<(int)(t);++i)
#define each(a,b) for(auto& (a): (b))
#define all(v) (v).begin(),(v).end()
#define len(v) (int)(v).size()
#define zip(v) sort(all(v)),v.erase(unique(all(v)),v.end())
#define cmx(x,y) x=max(x,y)
#define cmn(x,y) x=min(x,y)
#define fi first
#define se second
#define pb push_back
#define show(x) cout<<#x<<" = "<<(x)<<endl
#define spair(p) cout<<#p<<": "<<p.fi<<" "<<p.se<<endl
#define sar(a,n) cout<<#a<<":";rep(pachico,n)cout<<" "<<a[pachico];cout<<endl
#define svec(v) cout<<#v<<":";rep(pachico,v.size())cout<<" "<<v[pachico];cout<<endl
#define svecp(v) cout<<#v<<":";each(pachico,v)cout<<" {"<<pachico.first<<":"<<pachico.second<<"}";cout<<endl
#define sset(s) cout<<#s<<":";each(pachico,s)cout<<" "<<pachico;cout<<endl
#define smap(m) cout<<#m<<":";each(pachico,m)cout<<" {"<<pachico.first<<":"<<pachico.second<<"}";cout<<endl

using namespace std;

typedef pair<int,int> P;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<double> vd;
typedef vector<P> vp;
typedef vector<string> vs;

const int MAX_N = 100005;

int p[MAX_N];

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    rep(i,n){
        cin >> p[i];
        p[i]--;
    }
    int ans = 0;
    rep(i,n){
        if(p[i] == i){
            if(i != n-1){
                swap(p[i], p[i+1]);
            }
            ans++;
        }
    }
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 640
module Main where

import qualified Data.ByteString.Char8 as BS
import Data.List
import Data.Char
import qualified Data.Map.Strict as M
import Control.Arrow
-- import Debug.Trace

main :: IO ()
main = do
  [a, b] <- unfoldr (BS.readInteger . BS.dropWhile isSpace) <$> BS.getLine
  print . succ . pf $ gcd a b

-- http://qiita.com/myuon_myon/items/ad006568bd187223f494#2-4
primes = 2:3:[x|i<-[1..], j<-[-1,1], let x = 6*i+j, isPrime x] where
  isPrime n = null [i|i<-takeWhile (\x -> x*x <= n) primes, rem n i == 0]

-- | returns [(PrimeFactor, Exponent)]
-- >>> primeFactor 9
-- [(2,0),(3,2)]
primeFactor x = go x primes
  where       
    ub = floor . sqrt $ fromIntegral x
    go x (p:ps) 
      | p <= ub = let (x', e) = gogo x p 0 
        in (p, e) : go x' ps
      | x == 1 = []
      | otherwise = [(x, 1)]
      where
        gogo x p e = case quotRem x p of
          (q, 0) -> gogo q p (e + 1)
          (q, _) -> (x, e)

-- | returns [(PrimeFactor, Exponent)]
-- >>> primeFactor' 9
-- [(3,2)]
primeFactor' x = map (head &&& length) . group $ go x divisor
  where
    go 1 [] = []
    go y [] = [y]
    go y ps'@(p : ps) = case quotRem y p of
      (q, 0) -> p : go q ps'
      (q, _) -> go y ps
    ub = floor . sqrt $ fromIntegral x
    divisor = takeWhile (<= ub) primes

pf x = length . group $ go x divisor
  where
    go 1 [] = []
    go y [] = [y]
    go y ps'@(p : ps) = case quotRem y p of
      (q, 0) -> p : go q ps'
      (q, _) -> go y ps
    ub = floor . sqrt $ fromIntegral x
    divisor = takeWhile (<= ub) primes


Measured memory_bytes: 7932
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        final Scanner scanner = new Scanner(System.in);
        final int r = scanner.nextInt();
        final int d = scanner.nextInt();
        int x = scanner.nextInt();

        for (int i = 0;i<10;i++){
            x = r * x - d;
            System.out.println(x);
        }
    }
}


Measured memory_bytes: 21332
import sys 

N, M = list(map(int, input().split()))
a_list = list()
b_list = list()
c_list = list()

for _ in range(M):
    a, b, c = list(map(int, input().split()))
    a_list.append(a)
    b_list.append(b)
    c_list.append(-c)

inf = sys.maxsize
dist = [inf] * N
dist[0] = 0

for loop in range(N):
    for i in range(M):
        if dist[a_list[i]-1] == inf:
            continue
        if dist[b_list[i]-1] > dist[a_list[i]-1] + c_list[i]:
            dist[b_list[i]-1] = dist[a_list[i]-1] + c_list[i]
            if loop == N - 1 and b_list[i] == N:
                print('inf')
                sys.exit()

print(-dist[N-1])


Measured memory_bytes: 3188
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <fstream>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <stack>
#include <vector>
#include <set>
#include <tuple>
#include <utility>
#include <functional>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;
const int INF = 1000000000;
const int MOD = 1000000007;
int main(){
	int n,m;
	cin >> n >> m;
	int ans = 1;
	for(int i = 1;i * i <= m;i++){
		if(m % i == 0){
			if(i >= n){
				ans = max(m/i,ans);
			}
			if(m/i >= n){
				ans = max(ans,i);
			}
		}
	}
	cout << ans << endl;
}


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 1000000000



int main(){
	
	int N,M;
	cin>>N>>M;
	
	vector<int> WA_sum(N,0);
	
	set<int> AC;
	
	long long A = 0,W = 0;
	
	for(int i=0;i<M;i++){
		int p;
		cin>>p;
		p--;
		string S;
		cin>>S;
		
		if(!AC.count(p)){
			if(S=="WA"){
				WA_sum[p] ++;
			}
			else{
				A ++;
				W += (long long)WA_sum[p];
				AC.insert(p);
			}
		}
	}
	
	cout<<A<<' '<<W<<endl;
	
    return 0;
}


Measured memory_bytes: 5376
#include <iostream>
#include <algorithm>
#include <queue>
#include <set>
#include <cstdlib>

using namespace std;
typedef long long int ll;

bool debug;
#define show(x) if (debug) {cout << "" # x << " = " << x << endl;}
#define rep(x, a, b) for (int x = a; x < b; x++)

const ll big = 1000000007;
bool valid[300][300][300];
ll memo[300][300][300];

ll calc(ll n, ll l, ll d, ll u) {
  if (valid[l][d][u]) {
    return memo[l][d][u];
  }

  int ans = 0;

  if (l == 0) {
    if (d == n)
      ans = 1;
    else
      ans = 0;
  } else {
    if (d + u < n) {
      ans = calc(n, l - 1, d, u + 1) % big;
    }

    ans = (ans + d * calc(n, l - 1, d + u, 0)) % big;
    ans = (ans + u * calc(n, l - 1, d, u)) % big;
  }

  valid[l][d][u] = true;
  return memo[l][d][u] = ans % big;
}

ll fact(ll n) {
  int ans = 1;
  for (ll i = 1; i <= n; i++) {
    ans = (ans * i) % big;
  }
  return ans;
}

int main(int argc, char **argv)
{
  (void)argv; debug = argc > 1;

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

  cout << ((n > m)?0:((fact(n - 1) * calc(n, m, 1, 0)) % big)) << endl;

  return 0;
}


Measured memory_bytes: 120832
use std::io::prelude::*;
use std::str::FromStr;
pub struct Scanner<R: Read>(R);
impl<R: Read> Scanner<R> {
    pub fn new(reader: R) -> Self {
        Self(reader)
    }
    pub fn read<T: FromStr>(&mut self) -> T {
        let token = self
            .0
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| (b as char).is_whitespace())
            .take_while(|&b| !(b as char).is_whitespace())
            .collect::<Vec<u8>>();
        unsafe { std::str::from_utf8_unchecked(token.as_slice()) }
            .parse()
            .ok()
            .expect("Can't parse it.")
    }
    pub fn vec<T: FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}
fn main() {
    let (stdin, stdout) = (std::io::stdin(), std::io::stdout());
    let mut sc = Scanner::new(stdin.lock());
    let mut out = std::io::BufWriter::new(stdout.lock());
    solve(&mut sc, &mut out);
    out.flush().ok().unwrap();
}
fn solve(sc: &mut Scanner<std::io::StdinLock>, out: &mut std::io::BufWriter<std::io::StdoutLock>) {
    let mut s: String = sc.read();

    let patterns = vec!["dream", "dreamer", "erase", "eraser"];
    'again: while s.len() > 0 {
        for &pat in &patterns {
            if s.ends_with(pat) {
                s.split_off(s.len() - pat.len());
                continue 'again;
            }
        }
        println!("NO");
        return;
    }
    println!("YES");
}


Measured memory_bytes: 2272
#include <vector>
#include <string>
#include <iostream>
#include <queue>
#include <climits>
#include <cfloat>
#include <algorithm>
#include <cstdio>
using namespace std;

template<class T>
vector<vector<T> > matrixProduct(const vector<vector<T> >& x, const vector<vector<T> >& y)
{
	int a = x.size();
	int b = x[0].size();
	int c = y[0].size();
	vector<vector<T> > z(a, vector<T>(c, 0));
	for(int i=0; i<a; ++i){
		for(int j=0; j<c; ++j){
			for(int k=0; k<b; ++k){
				z[i][j] += x[i][k] * y[k][j];
			}
		}
	}
	return z;
}

template <class T>
vector<vector<T> > matrixPower(const vector<vector<T> >& x, int k)
{
	int n = x.size();
	vector<vector<T> > y(n, vector<T>(n, 0));
	for(int i=0; i<n; ++i)
		y[i][i] = 1;

	vector<vector<T> > z = x;
	while(k > 0){
		if(k & 1)
			y = matrixProduct(y, z);
		z = matrixProduct(z, z);
		k >>= 1;
	}
	return y;
}

void linearSystem(vector<vector<double> >& mat, vector<double>& x)
{
	int n = mat.size();
	x.resize(n);

	for(int i=0; i<n; ++i){
		for(int j=n; j>=i; --j)
			mat[i][j] /= mat[i][i];
		for(int j=0; j<n; ++j){
			if(j == i)
				continue;
			for(int k=n; k>=i; --k){
				mat[j][k] -= mat[i][k] * mat[j][i];
			}
		}
	}

	for(int i=0; i<n; ++i)
		x[i] = mat[i][n];
}

int main()
{
	int s, n, k;
	cin >> s >> n >> k;
	s = abs(s);
	if(n == 1){
		if(s % k == 0)
			cout << (double)(s / k) << endl;
		else
			cout << -1 << endl;
		return 0;
	}

	vector<double> prob(n*k+1, 0.0);
	prob[0] = 1.0;
	for(int i=0; i<k; ++i){
		vector<double> nextProb(n*k+1, 0.0);
		for(int j=0; j<=n*(k-1); ++j){
			for(int l=1; l<=n; ++l){
				nextProb[j+l] += prob[j] / n;
			}
		}
		prob.swap(nextProb);
	}

	vector<vector<double> > mat(n*k*2-1, vector<double>(n*k*2, 0.0));
	for(int i=0; i<n*k*2-1; ++i){
		mat[i][i] = 1.0;
		if(i == n*k-1){
			continue;
		}
		mat[i][n*k*2-1] = 1.0;
		if(i < n*k-1){
			for(int j=1; j<=n*k; ++j){
				mat[i][i+j] = -prob[j];
			}
		}else{
			for(int j=1; j<=n*k; ++j){
				mat[i][i-j] = -prob[j];
			}
		}
	}
	vector<double> x;
	linearSystem(mat, x);
	x = vector<double>(x.rbegin(), x.rbegin()+n*k);
	if(s < n*k){
		printf("%.10f\n", x[n*k-1-s]);
		return 0;
	}

	vector<vector<double> > y(n*k+1, vector<double>(n*k+1, 0.0));
	y[0][n*k] = 1.0;
	y[n*k][n*k] = 1.0;
	for(int i=0; i<n*k-1; ++i)
		y[i+1][i] = 1.0;
	for(int i=0; i<n*k; ++i)
		y[0][i] = prob[i+1];
	y = matrixPower(y, s-n*k+1);

	double ret = y[0][n*k];
	for(int i=0; i<n*k; ++i)
		ret += y[0][i] * x[i];
	printf("%.10f\n", ret);

	return 0;
}

Measured memory_bytes: 0
#include<iostream>

using namespace std;

int main(){
	int N, i, j, key;
	cin >> N;
	int A[N];
	for(i = 0; i < N; i++)
		cin >> A[i];

	for(i = 0; i < N; i++){
		key = A[i];
		j = i - 1;
		while(j >= 0 && A[j] > key){
			A[j + 1] = A[j];
			j--;
		}
		A[j + 1] = key;
		for(int k = 0; k < N; k++){
		if(k > 0)
			cout << " ";
		cout << A[k];
		}
		cout << endl;
	}

	return 0;
}

Measured memory_bytes: 1160
#include<iostream>
#include<vector>
#include<cstdio>
#include<string>
#include<numeric>
#include<algorithm>
#include<complex>
#include<queue>
#include<stdlib.h>
#include<map>
#include<cmath>
#include<stdio.h>
#include<stdlib.h>
#include<set>

#define ll long long int
#define MOD 1000000007
#define pb push_back
#define ub upper_bound
#define lb lower_bound
#define mp make_pair

using namespace std;

int main(){
    int N,W;
    cin >> N >> W;
    ll dp[W+1][N];
    vector<pair<ll,ll>> vec(N);
    int w,v;
    for(int i=0;i<N;i++){
        cin >> w >> v;
        vec[i]=make_pair(w,v);
    }
    for(int i=0;i<=W;i++){
        for(int j=0;j<N;j++){
            dp[i][j]=0;
        }
    }
    for(int i=0;i<N;i++){
        for(int j=0;j<=W;j++){
            if(j<vec[i].first){
                dp[j][i+1]=dp[j][i];
            }
            else{
                dp[j][i+1]=max(dp[j-vec[i].first][i]+vec[i].second,dp[j][i]);
            }
        }
    }
    cout << dp[W][N] << endl;
    return 0;
}


Measured memory_bytes: 78336
#include <bits/stdc++.h>
     
#define all(A) begin(A), end(A)
#define rall(A) rbegin(A), rend(A)
#define sz(A) int(A.size())
#define pb push_back
#define mp make_pair
     
using namespace std;
     
typedef long long ll;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef vector <int> vi;
typedef vector <ll> vll;
typedef vector <pii> vpii;
typedef vector <pll> vpll;
 
int main () {
  ios::sync_with_stdio(false); cin.tie(0);
  int n;
  cin >> n;
  vi g(n + 1);
  for (int i = 2; i <= n; i++) {
    int j;
    cin >> j;
    g[j]++;
  }
  for (int i = 1; i <= n; i++) cout << g[i] << '\n';
  return (0);
}


Measured memory_bytes: 3960