akhauriyash/Code-Regression huggingface dataset:
//agrawal117
//chahatagrawal117
#include<bits/stdc++.h>
#define mod 1000000007
#pragma GCC optimize ("O3")
#define endl '\n'
using namespace std;
typedef long long int ll ;
#define MAX 1005
ll dp[10006];
int main()
{
    ll h,n;
    cin>>h>>n;
    vector<pair<ll,ll>> v;
    for(int i=1;i<=n;i++){
        ll a,b;
        cin>>a>>b;
        v.push_back({a,b});
    }
    for(int i=1;i<=h;i++){
        ll mn=INT_MAX;
        for(int j=0;j<n;j++){
            ll val=v[j].first;
            if(i-val<=0){
                mn=min(mn,v[j].second);
            }
            else{
                mn=min(mn,dp[i-val]+v[j].second);
            }
        }
        dp[i]=mn;
    }
    // for(int i=1;i<=h;i++) cout<<dp[i]<<" ";
    // cout<<endl;
    cout<<dp[h]<<endl;
}

Measured memory_bytes: 384
import sys
import math
import heapq
mod=10**9+7
inf=float("inf")
from math import sqrt
from collections import deque
from collections import Counter
from math import ceil
input=lambda: sys.stdin.readline().strip()
sys.setrecursionlimit(11451419)
from decimal import Decimal #floatの高精度ver, 渡すのはstr型で
from functools import lru_cache
#メモ化再帰defの冒頭に毎回 @lru_cache(maxsize=10**10)
#引数にlistはだめ
#######ここまでテンプレ#######
#ソート、"a"+"b"、再帰ならPython3の方がいい
#######ここから天ぷら########
class BIT:
    def __init__(self,n):
        self.n=n
        self.data= [0]*(n+1) #これがBIT
        self.el= [0]*(n+1) #これが元データ
    def sum(self,i):  #iまでの和
        s=0
        while i>0:
            s+=self.data[i]
            i-= i&(-i)
        return s
    def add(self,i,x):  #iにxを足す(x<0)
        self.el[i]+=x
        while i<= self.n:
            self.data[i]+= x
            i+= i&-i
    def get(self,i,j=None):  #iからjまでの和、iだけなら普通の要素iを取得(いる？)
        if j is None:
            return self.el[i]
        return self.sum(j)-self.sum(i)
    

n,q=map(int,input().split())
C=list(map(int,input().split()))
C=[i-1 for i in C]  #球の純粋配置
Q=[]
for i in range(q):
    l,r=map(int,input().split())
    l-=1;r-=1
    Q.append([i,l,r])
Q=sorted(Q, key=lambda x:x[2]) 
ANS=[-1]*q

B=BIT(n)
YOI=[-1]*n #色iの良い球の位置
for i in range(Q[0][2],-1,-1):
    if YOI[C[i]]==-1:
        YOI[C[i]]=i
        B.add(i+1,1)

# 
ANS[Q[0][0]]= B.sum(Q[0][2]+1)- B.sum(Q[0][1])
left=Q[0][1]; right=Q[0][2]
#print(B.data)
# right=-1
for l in Q:
    newleft,newright=l[1],l[2]
    for i in range(newright,right,-1):
        if YOI[C[i]]==-1: #新種の色
            YOI[C[i]]=i
            B.add(i+1, 1)
        elif YOI[C[i]]>i:
            continue
        else:
            B.add(YOI[C[i]]+1, -1)
            YOI[C[i]]=i
            B.add(i+1, 1)
    ANS[l[0]]= B.sum(newright+1)- B.sum(newleft)
    right=newright
    #print(B.data)
for i in ANS:
    print(i)


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

    vl a(n+1);
    rep(i, n+1) {
        cin >> a[i];
    }

    vl b(n);
    rep(i, n) {
        cin >> b[i];
    }

    ll ans = 0;
    rep(i, n) {
        if(b[i] <= a[i]) {
            ans += b[i];
        }
        else if(b[i] < a[i] + a[i+1]) {
            ans += b[i];
            a[i+1] -= (b[i] - a[i]);
        }
        else {
            ans += a[i] + a[i+1];
            a[i+1] = 0;
        }
    }
    
    out(ans);
    re0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pb               push_back
#define sz(c)            (int)c.size()
#define len(c)           (int)c.length()
#define vec              vector
#define int              long long int
#define mp(x,y)          make_pair(x,y)
#define all(c)           c.begin(), c.end()
#define rall(c)          c.rbegin(), c.rend()
#define trav(a,i)        for(auto& i: a)
#define loop(n,i,a)      for(int i=a;i<n;i++)
#define invect(v,n)       for(int i=0;i<n;i++ ){int arb;cin>>arb;v.pb(arb);}
#define inset(s,n)        loop(n,i,0){int aset;cin>>aset;s.insert(aset);}
#define display(c)        trav(c,i) cout<<i<<" ";
#define F                 first
#define S                 second
#define pii               pair<int,int>
#define pp               pop_back
#define endl              "\n"
#define copy(a,b)         copy(all(a),back_inserter(b));
#define intersect(a,b,w)    set_intersection(a.begin(), a.end(),b.begin(), b.end(),back_inserter(w));
#define union(a,b,w)      set_union(a.begin(), a.end(),b.begin(), b.end(),back_inserter(w));
#define diff(a,b,w)       set_difference(a.begin(), a.end(),b.begin(), b.end(),back_inserter(w));
#define symdiff(a,b,w)    set_symmetric_difference(a.begin(), a.end(),b.begin(), b.end(),back_inserter(w));
//int m=10000009;
//int arr[100000];
#define M                   1000000007
#define mm  998244353  
//set<int> st;
signed main()
{
    fast
    int h,w;
    cin>>h>>w;
    int k = h*w;
    if(h==1 || w==1)
    {
        cout<<1;
        return 0;
    }
    if(k%2==0)
    {
        cout<<k/2;
    }
    else
    {
        cout<<k/2+1;
    }
}

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

#define int          long long
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define x           first
#define y           second
#define sz(x)       (int)x.size()
#define endl        '\n'
#define hell        1000000007
#define rep(i,a,b)  for(int i=a;i<b;i++)
using namespace std;

void solve(){
    int a,b,c;
    cin>>a>>b>>c;
    if(c-a-b<0) cout<<"No"<<endl;
    else if(4*a*b<(c-a-b)*(c-a-b)) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t=1;
    // cin>>t;
    while(t--){
        solve();
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
	
	int a , b , c ;
	cin >> a >> b >> c;
	
	int count =0;
	for( int i=a ; i<=b; i++){
		if( c % i ==0) {
			count++;
		}
	}cout<< count << endl;
	 return 0;    
}


Measured memory_bytes: 3120
n = int(input())
a = list(map(int, input().split()))
sum_of_height = 0
max_height = a[0]
for i in range(1, n):
  if max_height > a[i]:
    sum_of_height += (max_height - a[i])
  else:
    max_height = a[i]
print(sum_of_height)

Measured memory_bytes: 32192
//Author - Rahil Malhotra
#include <bits/stdc++.h>
using namespace std;
 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl '\n'
#define int long long
#define double long double

int32_t main()
{
    IOS
    int n;
    cin>>n;
    int arr[n];

    for(int i=0;i<n;i++)
        arr[i]=i+1;
    int brr[n],crr[n];
    for(int i=0;i<n;i++)
        cin>>brr[i];
    for(int i=0;i<n;i++)
        cin>>crr[i];
    int a=0,b=0;
    int ctr=1;
    do
    {
        int f1=0;int f2=0;
        for(int i=0;i<n;i++)
        {
            if(arr[i]!=brr[i])
                f1=1;
            if(arr[i]!=crr[i])
                f2=1;
        }
        if(!f1)
            a=ctr;
        if(!f2)
            b=ctr;
        ctr++;
    }while(next_permutation(arr,arr+n));
    cout<<abs(a-b);
}


Measured memory_bytes: 256
#include <stdio.h>
 
int main(void){
    float w;
    while(scanf("%f" , &w)!=EOF){
        if(w <= 60){
            if(w <= 54){
                if(w <= 48) printf("light fly\n");
                else{
                    if(w <= 51) printf("fly\n");
                    else printf("bantam\n");
                }
            }else{
                if(w <= 57) printf("feather\n");
                else printf("light\n");
            }
        }else{
            if(w <= 75){
                if(w <= 64) printf("light welter\n");
                else{
                    if(w <= 69) printf("welter\n");
                    else printf("light middle\n");
                }
            }else{
                if(w <= 81) printf("middle\n");
                else if(w <= 91) printf("light heavy\n");
                else printf("heavy\n");
            }
        }
    }
    return 0;
}

Measured memory_bytes: 604
#include<bits/stdc++.h>
using namespace std;
int n, v, lg, a[200005];

struct oneside {
	int rb[19][200005], dt[1<<19];
	int solve () {
		int cv = v;
		for(int i=0;i<=lg;i++,cv/=2) {
			int un = 1;
			for(int j=1;j<n;j++) {
				if(a[j+1] - a[j] > cv) {
					for(int k=un;k<=j;k++) rb[i][k] = j;
					un = j+1;
				}
			}
			for(int k=un;k<=n;k++) rb[i][k] = n;
		}
		for(int i=0;i<(1<<lg);i++) {
			for(int j=1;j<=lg;j++) {
				int t = (1<<(j-1));
				if(i & t) continue;
				dt[i|t] = max(dt[i|t], rb[j][min(dt[i]+1, n)]);
			}
		}
	}
} ls, rs;

struct segtree {
	int val[888888], lim;
	void init () {
		for(lim = 1; lim <= n; lim <<= 1);
	}
	void update (int S, int E, int X) {
		S += lim; E += lim;
		while(S<=E) {
			if(S%2 == 1) val[S] += X, S++;
			if(E%2 == 0) val[E] += X, E--;
			S>>=1; E>>=1;
		}
	}
	int query (int P) {
		P += lim;
		int ret = 0;
		while(P) {
			ret += val[P];
			P>>=1;
		}
		return ret;
	}
} seg;

int main()
{
	scanf("%d%d",&n,&v);
	for(int i=1;i<=n;i++) {
		scanf("%d",&a[i]);
	}
	for(int i=v;i;i/=2,lg++);
	ls.solve();
	reverse(a+1, a+1+n);
	for(int i=1;i<=n;i++) a[i] *= -1;
	rs.solve();
	seg.init();
	for(int i=0;i<(1<<lg);i++) {
		int t = ((1<<lg)-1)^i;
		if(ls.dt[i] + 1 > n - rs.dt[t]) {
			for(int j=1;j<=n;j++) puts("Possible");
			return 0;
		}
		else {
			int ss = n - rs.rb[0][min(n, rs.dt[t]+1)] + 1, se = ls.rb[0][min(n, ls.dt[i]+1)];
			if(ss <= se) seg.update(ss, se, 1);
		}
	}
	for(int i=1;i<=n;i++) {
		puts(seg.query(i) ? "Possible" : "Impossible");
	}
}


Measured memory_bytes: 38016
#include <iostream>
#include <math.h>
#include <vector>
using namespace std;

// 最大公約数を算出
long long gcd(long long a, long long b)
{
  if (b == 0)
  {
    return a;
  }
  else
  {
    gcd(b, a % b);
  }
}

// 素数か判定する
int judge_prime(long long target)
{
  if (target <= 3)
  {
    return 1;
  }
  else
  {
    long long max = (long long)((int)(sqrt(target) + 1));
    for (long long i = 2; i <= max; i++)
    {
      if (target % i == 0)
        return 0;
    }
  }
  return 1;
}

long long prime_fac(long long a)
{
  long long ans = 1;
  long long max = (long long)((int)sqrt(a) + 1);
  long long tmp = a;

  // 素数の算出
  for (long long target = 2; target < max; target++)
  {
    if (tmp % target == 0 && judge_prime(target))
    {
      while (tmp % target == 0)
      {
        tmp /= target;
      }
      ans++;
    }
  }

  //割り切った数値が判定しきれていない素数の可能性を考慮
  //ex: 19 => 1*19 だが、上の条件では判定しきれていない
  if (tmp >= max && judge_prime(tmp))
  {
    ans++;
  }

  return ans;
}

int main()
{
  long long A, B;
  cin >> A >> B;

  long long ans = prime_fac(gcd(A, B));
  cout << ans;

  return 0;
}

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

using namespace std;
using ll = long long;
using vl = vector<ll>;
using pll = pair<ll, ll>;

#define rep(i, n) for (ll i = 0, xxx_rep_end = (n); i < xxx_rep_end; ++i)
#define all(x) (x).begin(), (x).end()

template <class T1, class T2>
inline bool chmax(T1 &a, const T2 &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template <class T1, class T2>
inline bool chmin(T1 &a, const T2 &b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}

constexpr ll INF = 0x3f3f3f3f3f3f3f3fLL;
constexpr ll mod = 1000000007;

int main() {
    ll N, K;
    cin >> N >> K;
    vector<ll> A(N);
    rep(i, N) {
        ll num;
        cin >> num;
        --num;
        A[i] = num;
    }

    vector<ll> is_visited(N, -1);
    ll cur = 0;
    for (ll i = 0; i < K; ++i) {
        cur = A[cur];
        if (is_visited[cur] != -1) {
            ll aaa = (K - 1 - i) / (i - is_visited[cur]);
            i += (i - is_visited[cur]) * aaa;
        }
        is_visited[cur] = i;
    }
    cout << cur + 1 << endl;
}

Measured memory_bytes: 6436
def calc_dan(h):
    hh = h
    dan = 0
    while hh > 1:
        hh = hh // 2
        dan += 1
    return dan

def main():
    H = int(input())
    dan = calc_dan(H)
    answer = 1
    for i in range(1, dan + 1):
        answer += (2 ** i)
    print(answer)

main()


Measured memory_bytes: 2940
def main():
    n = int(input())
    a_list = sorted([int(input()) for _ in range(n)])
    maxv = sum(a_list)

    if maxv%10 != 0:
        print(maxv)
    else:
        flag = 1
        for i in range(n):
            if a_list[i]%10 != 0:
                ans = maxv - a_list[i]
                print(ans)
                flag = 0
                break
        if flag: print(0)


if __name__ == "__main__":
    main()

Measured memory_bytes: 3060
h,w = map(int,input().split())
s = [[0]*(w+2)]+[[0]+[(i == "#")*1 for i in list(input())]+[0] for _ in range(h)]+[[0]*(w+2)]

ans = [[0]*w for _ in range(h)]
for i in range(h):
    for j in range(w):
        if s[i+1][j+1] == 1:
            ans[i][j] = "#"
            continue
        ans[i][j] = str(s[i][j+1]+s[i+1][j]+s[i+1][j+2]+s[i+2][j+1]+s[i][j]+s[i+2][j+2]+s[i+2][j]+s[i][j+2])
for l in ans:
    print("".join(l))

Measured memory_bytes: 3188
#include <iostream>
#include <vector>
#include <algorithm>

struct GSB{
    int A;
    int B;

    GSB(int A2, int B2)
    {
        A=A2;
        B=B2;
    }

    bool operator < (const GSB & another) const
    {
        return A < another.A;
    }
};


int main()
{
    long N;
    std::cin >> N;
    std::vector<GSB> GSBS;
    for(long i=0; i<N; i++){
        long temp;
        std::cin >> temp;
        GSBS.push_back(GSB(temp,i+1));
    }
    std::sort(GSBS.begin(),GSBS.end());
    for(long i=0; i<N; i++){
        std::cout << GSBS[i].B << " ";
    }
    std::cout << std::endl;
    return 0;
}

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

int n;
string s;

int main()
{
	ios::sync_with_stdio(false);
	cin >> n >> s;
	if (s.size() <= n) cout << s << endl;
	else
	{
		for (int i = 0; i < n; i++) cout << s[i];
		cout << "...\n";
	}
	return 0;
}


Measured memory_bytes: 3652
#include <stdio.h>
#define MAX 100000
#define SENTINEL 2000000000

struct Card{
	char suit;
	int value;
};

struct Card L[MAX / 2 + 2], R[MAX / 2 + 2];

void merge(struct Card A[], int n, int left, int mid, int right){
	int n1 = mid - left;
	int n2 = right - mid;
	for(int i = 0; i < n1; i++) {L[i] = A[left + i];}
	for(int i = 0; i < n2; i++) {R[i] = A[mid + i];}
	L[n1].value = R[n2].value = SENTINEL;
	int i = 0, j = 0;
	for(int k = left; k < right; k++){
		if(L[i].value <= R[j].value){
			A[k] = L[i++];
		}
		else{
			A[k] = R[j++];
		}
	}
}

void mergeSort(struct Card A[], int n, int left, int right){
	if(left + 1 < right){
		int mid = (left + right) / 2;
		mergeSort(A, n, left, mid);
		mergeSort(A, n, mid, right);
		merge(A, n, left, mid, right);
	}
}

int partition(struct Card A[], int n, int p, int r){
	int i,j;
	struct Card t, x;
	x = A[r];
	i = p-1;
	for(j = p; j < r; j++){
		if(A[j].value <= x.value){
			i++;
			t = A[i];
			A[i] = A[j];
			A[j] = t;
		}
	}
	t = A[i + 1];
	A[i + 1] = A[r];
	A[r] = t;
	return i+1;
}

void quickSort(struct Card A[], int n, int p, int r){
	int q;
	if(p < r){
		q = partition(A,n,p,r);
		quickSort(A,n,p,q-1);
		quickSort(A,n,q+1,r);
	}
}

int main(){
	int n,i,v;
	struct Card A[MAX], B[MAX];
	char S[10];
	int stable = 1;
	
	scanf("%d", &n);
	
	for(i = 0; i < n; i++){
		scanf("%s %d", S, &v);
		A[i].suit = B[i].suit = S[0];
		A[i].value = B[i].value = v;
	}
	
	mergeSort(A,n,0,n);
	quickSort(B,n,0,n-1);
	
	for(i = 0; i < n; i++){
		if(A[i].suit != B[i].suit){stable = 0;}
	}
	
	if(stable == 1){printf("Stable\n");}
	else {printf("Not stable\n");}
	for(i = 0; i < n; i++){
		printf("%c %d\n", B[i].suit, B[i].value);
	}
	
	return 0;
}



Measured memory_bytes: 4076
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
using ll = long long;
using u64 = uint_fast64_t;
using pii = pair<int, int>;
using pll = pair<long long, long long>;
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007;
//constexpr long long MOD = 998244353;
template<class T1, class T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return true;} return false; }
template<class T1, class T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return true;} return false; }
inline int popcount(int x) {return __builtin_popcount(x);}
inline int popcount(long long x) {return __builtin_popcountll(x);}
void print() { cout << "\n"; }
template<class T, class... Args>
void print(const T &x, const Args &... args) {
    cout << x << " ";
    print(args...);
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    int N; cin >> N;
    vector<string> S(N);
    rep(i,N) cin >> S[i];

    int foo = 0;
    rep(i,N) {
        rep(j,N) if (S[i][j]=='#') foo = 1;
    }
    if (!foo) {
        cout << -1 << ln;
        return 0;
    }
    int cntc = N;
    rep(c,N) {
        bool ok = true;
        rep(r,N) if (S[r][c]=='.') ok = false;
        if (ok) cntc--; 
    }
    int ans = 1e9;
    rep(r,N) {
        bool ok = false;
        rep(nr,N) {
            if (S[nr][r]=='#') ok = true;
        }
        int cnt = 0;
        if (!ok) cnt++;
        rep(c,N) {
            if (S[r][c]=='.') cnt++;  
        }
        chmin(ans,cnt+cntc);
    }

    cout << ans << ln;
}

Measured memory_bytes: 512
//
//  main.cpp
//  0118
//
//  Created by 穎川和弘 on 2014/07/16.
//  Copyright (c) 2014年 穎川和弘. All rights reserved.
//

#include <iostream>
using namespace std;

char map[100][101];
int fdx[] = {1, -1, 0, 0};
int fdy[] = {0, 0, -1, 1};
char chr;
int h, w;

void dfs(int x, int y) {
    if(x < 0 || y < 0 || x >= w || y >= h) return;
    if(map[y][x] == '.' || map[y][x] != chr) return;
    map[y][x] = '.';
    for(int r = 0; r < 4; r++) {
        dfs(x + fdx[r], y + fdy[r]);
    }
}

int main(void) {
    cin.tie();
    ios::sync_with_stdio(false);
    
    while(true) {
        cin >> h >> w;
        if(h + w == 0) break;
        
        for(int r = 0; r < h; r++) {
            for(int c = 0; c < w; c++) {
                cin >> map[r][c];
            }
        }
        
        int count = 0;
        while(true) {
            bool flag = false;
            for(int r = 0; r < h; r++) {
                for(int c = 0; c < w; c++) {
                    if(map[r][c] != '.') {
                        flag = true;
                        chr = map[r][c];
                        dfs(c, r);
                        count++;
                    }
                    if(flag) break;
                }
                if(flag) break;
            }
            if(!flag) break;
        }
        cout << count << endl;
    }
    return(0);
}

Measured memory_bytes: 1516
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using u32 = uint32_t;
using vi = vector<int>;    using vvi = vector<vi>;
using vb = vector<bool>;   using vvb = vector<vb>;
using vl = vector<ll>;     using vvl = vector<vl>;
using vd = vector<double>; using vvd = vector<vd>;

#define MAXC(c, x) (c = max(c, x))
#define MINC(c, x) (c = min(c, x))

#define REP(i,n) for(auto i = 0 * (n), i##_len = (n); i < i##_len; ++i)
#define ALL(c) (c).begin(), (c).end()
#define FOR(i,s,n) for(ll i=s, i##_len=(ll)(n); i<i##_len; ++i)
#define TEN(x) ((ll)1e##x)
const ll mod = TEN(9) + 7;

const ll INF = 1e9;

int main() {
	#ifdef INPUT_FROM_FILE
	ifstream cin("sample.in");
	ofstream cout("sample.out");
	#endif
	cin.tie(0);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(50);

	ll n, m; cin >> n >> m;

	cout << ((n - m) * 100 + 1900 * m) * (ll)pow(2, m) << std::endl;

	return 0;
}


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

#define ll long long
#define mod 1000000007
#define pb push_back
#define pi pair<int,int>
#define vi vector<int>
#define vpi vector< pi > 
#define IOS ios_base::sync_with_stdio(false),cin.tie(NULL)
const int N=2003;
int a[N],n;
vpi v;
ll dp[N][N];
ll solv(int i,int l)
{
    if(i>n) return 0;
    if(dp[i][l]!=-1) return dp[i][l];
    ll ans=0;
    int r=l+(n-i);
    ans =1ll*v[i-1].first*abs(v[i-1].second-l)+solv(i+1,l+1);
    ans = max(ans,1ll*v[i-1].first*abs(v[i-1].second-r)+solv(i+1,l));
    dp[i][l]=ans;
    return ans;
}
int main()
{
    cin>>n;

    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=n;j++)
            dp[i][j]=-1;
        cin>>a[i];
        v.pb({a[i],i});
    }
    sort(v.begin(), v.end());
    reverse(v.begin(),v.end());
    cout<<solv(1,1)<<"\n";
    
    return 0;
}

Measured memory_bytes: 35128
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int n; cin>>n;
  vector<string> s(n);
  for(int i=0; i<n; ++i){
    cin>>s[i];
    sort(s[i].begin(), s[i].end());
  }
 
  sort(s.begin(), s.end());
  long long ans=0LL;
 
  long long l=1LL; string ss=s[0];
  for(int i=1; i<n; ++i){
    if(ss==s[i])++l;
    else{ans+=l*(l-1)/2; ss=s[i]; l=1;}
  }
  ans+=l*(l-1)/2;
 
  cout<<ans<<endl;
  
}

Measured memory_bytes: 7296
N=io.read()
S=io.read()
count=0
for i=2,#S do
  if string.sub(S,i,i)=="E" then
    count=count+1
  end
end
k=count
for i=2,#S do
  if string.sub(S,i-1,i-1)=="W" then
    k=k+1
  end
  if string.sub(S,i,i)=="E" then
    k=k-1
  end
  if k<count then
    count=k
  end 
end
print(count)

Measured memory_bytes: 888
#include<cstdio>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<cstring>
using namespace std;

const int N = 500;

int a[N + 2][N + 2], n, m, st[(1 << 22) + 2], st2[(1 << 22) + 2], sum[N + 2], val[N + 2];

int main()
{
	for (; scanf("%d%d", &n, &m) && (n || m); )
	{
		for (int i = 0; i < n; i++)
			for (int j = 0; j < m; j++)
			{
				scanf("%1d", &a[i][j]);
			}
		int ans = 0;
		if (n <= 22)
		{
			for (int k = 1; k < 1 << n; k++)
			{
				for (int i = 0; i < m; i++)
					sum[i] = 0;
				int cnt = 0;
				for (int l = 0; l < n; l++)
					if (k >> l & 1)
					{
						cnt++;
						for (int i = 0; i < m; i++)
							sum[i] ^= a[l][i];
					}
				int ok = 1;
				for (int i = 0; i < m; i++)
					if (sum[i])
						ok = 0;
				if (ok)
					ans = max(ans, cnt);
			}
		}
		else
		{
			for (int i = 0; i < 1 << m; i++)
				st[i] = st2[i] = 0;
			for (int i = 0; i < n; i++)
			{
				val[i] = 0;
				for (int j = 0; j < m; j++)
				{
					val[i] = 2 * val[i] + a[i][j];
				}
			}
			for (int i = 0; i < n; i++)
			{
				if (st[val[i]] > 0)
					ans = max(ans, st[val[i]] + 1);
				for (int j = 0; j < 1 << m; j++)
					st2[j^val[i]] = st[j] > 0 ? st[j] + 1 : 0;
				st2[val[i]] = max(st2[val[i]], 1);
				for (int j = 0; j < 1 << m; j++)
					st[j] = max(st[j], st2[j]);
			}
		}
		printf("%d\n", ans);
	}
}

/*


*/

Measured memory_bytes: 20000
#include <bits/stdc++.h>
#define ll long long int
#define N 100000
#define f(i, a, b) for (ll i = (ll)a; i <= (ll)b; i++)
#define rf(i, a, b) for (ll i = (ll)a; i >= (ll)b; i--)
#define po pop_back
#define pb push_back
#define lb lower_bound
#define fi first
#define se second
#define debug(x) cout << #x << " = " << x << endl
#define ub upper_bound
#define ibs ios_base::sync_with_stdio(false)
#define cti cin.tie(0)
#define all(x) x.begin(), x.end()
#define PI 3.14159265
#define cot cout.tie(0)
#define square(x) x*x
using namespace std;
/**
        * @author :: Sawlani
        *
        */
int main()
{

     ll y;
     cin >> y;

     ll a=(y/500)*1000;

     y-=(y/500)*500;

     ll b=(y/5)*5;

     cout << a+b;
  
     }
    
 

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

using namespace std;
typedef long long ll;
#define int ll

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

const ll LLINF = (1LL<<60);
const int INF = (1LL<<30);
const double DINF = std::numeric_limits<double>::infinity();
const int MOD = 1000000007;
#define MAX_N 100010

signed main()
{
    int N;
    string A, B, C;
    cin >> N >> A >> B >> C;
    int ans = 0;
    REP(i, N) {
        // 出てくる回数が一番多い文字にする
        if(A[i] == B[i] && B[i] == C[i]) {}
        else if(A[i] == B[i] || B[i] == C[i] || A[i] == C[i]) { ans++; }
        else { ans += 2; }
    }
    printf("%lld\n", ans);
    return 0;
}


Measured memory_bytes: 256
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))
def getArray(intn):
    return [int(input()) for i in range(intn)]
def input():
    return sys.stdin.readline().rstrip()

from collections import defaultdict, deque, Counter
from sys import exit
import heapq
import math
import copy
from operator import mul
from functools import reduce
from bisect import bisect_left, bisect_right

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

N, M = getNM()
if N >= M // 2:
    print(M // 2)
else:
    left = M - (2 * N)
    print(N + (left // 4))

Measured memory_bytes: 38256
#include <bits/stdc++.h>
#define rep(i, n) for(int i= 0; i < (n); i++)
using ll= long long int;
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
ll mod= 1e9 + 7;


int main(){
  int n;
  cin >> n;
  ll d[n];
  rep(i,n)cin >> d[i];
  sort(d,d+n);
  ll ans=0;
  for(int a=0;a<n;a++){
    for(int b=a+1;b<n;b++){
      for(int c=b+1;c<n;c++){
        if(d[a]!=d[b] && d[b]!=d[c] && d[a]+d[b]>d[c])ans++;
      }
    }
  }
  cout << ans << endl;
}

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

int main() {
    for (;;) {
        double x, h;
        scanf("%lf%lf", &x, &h);
        if (x == 0 && h == 0) return 0;
        const double y = sqrt(x*x/4+h*h);
        printf("%.6f\n", x*x+2*x*y);
    }
}

Measured memory_bytes: 0
#[macro_export]
macro_rules !read_value {($iter :expr ,($($t :tt ) ,*) ) =>{($(read_value !($iter ,$t ) ) ,*) } ;($iter :expr ,[$t :tt ;$len :expr ] ) =>{(0 ..$len ) .map (|_ |read_value !($iter ,$t ) ) .collect ::<Vec <_ >>() } ;($iter :expr ,{$t :tt =>$f :expr } ) =>{$f (read_value !($iter ,$t ) ) } ;($iter :expr ,chars ) =>{read_value !($iter ,String ) .chars () .collect ::<Vec <char >>() } ;($iter :expr ,usize1 ) =>{read_value !($iter ,usize ) -1 } ;($iter :expr ,$t :ty ) =>{$iter .next () .unwrap () .parse ::<$t >() .unwrap () } ;}
#[macro_export]
macro_rules !input_inner {($iter :expr ) =>{} ;($iter :expr ,) =>{} ;($iter :expr ,mut $var :ident :$t :tt $($r :tt ) *) =>{let mut $var =read_value !($iter ,$t ) ;input_inner !{$iter $($r ) *} } ;($iter :expr ,mut $var :ident $($r :tt ) *) =>{input_inner !{$iter ,mut $var :usize $($r ) *} } ;($iter :expr ,$var :ident :$t :tt $($r :tt ) *) =>{let $var =read_value !($iter ,$t ) ;input_inner !{$iter $($r ) *} } ;($iter :expr ,$var :ident $($r :tt ) *) =>{input_inner !{$iter ,$var :usize $($r ) *} } ;}
#[macro_export]
macro_rules !input {(source =$s :expr ,$($r :tt ) *) =>{let mut iter =$s .split_whitespace () ;input_inner !{iter ,$($r ) *} } ;(iter =$iter :ident ,$($r :tt ) *) =>{let s ={use std ::io ::Read ;let mut s =String ::new () ;std ::io ::stdin () .read_to_string (&mut s ) .unwrap () ;s } ;let mut $iter =s .split_whitespace () ;input_inner !{$iter ,$($r ) *} } ;($($r :tt ) *) =>{let s ={use std ::io ::Read ;let mut s =String ::new () ;std ::io ::stdin () .read_to_string (&mut s ) .unwrap () ;s } ;let mut iter =s .split_whitespace () ;input_inner !{iter ,$($r ) *} } ;}
fn main() {
    #[allow(unused_imports)]
    use std::io::Write as _;
    let __out = std::io::stdout();
    #[allow(unused_mut, unused_variables)]
    let mut __out = std::io::BufWriter::new(__out.lock());
    #[allow(unused_macros)]
    macro_rules !print {($($arg :tt ) *) =>(::std ::write !(__out ,$($arg ) *) .unwrap () ) }
    #[allow(unused_macros)]
    macro_rules !println {($($arg :tt ) *) =>(::std ::writeln !(__out ,$($arg ) *) .unwrap () ) }
    #[allow(unused_macros)]
    macro_rules! echo {
        ($iter :expr ) => {
            echo!($iter, "\n")
        };
        ($iter :expr ,$sep :expr ) => {
            let mut iter = $iter;
            if let Some(item) = iter.next() {
                print!("{}", item);
            }
            for item in iter {
                print!("{}{}", $sep, item);
            }
            println!();
        };
    }
    input!(n, a: [usize; n]);
    let mut b = 0;
    for i in 2..n {
        b ^= a[i];
    }
    let a0 = a[0];
    let a = a[0] + a[1];
    if a < b {
        println!("-1");
        return;
    }
    let c = (a - b) / 2;
    if a % 2 != b % 2 || c > a0 || c & (b ^ c) != c {
        println!("-1");
        return;
    }
    let mut i = 0;
    let mut j = 1 << 60;
    while j > 0 {
        if b & j != 0 && c ^ (i | j) <= a0 {
            i |= j;
        }
        j >>= 1;
    }
    i ^= c;
    if i == 0 {
        println!("{}", -1);
    } else {
        println!("{}", a0 - i);
    }
}


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

int main() {
	int n; cin >> n;
	vector<int>a(n); for (auto&& x : a)cin >> x;
	int cnt4 = 0, cnt2 = 0;
	for (auto&&x:a) {
		if (x >= 4 && x % 4 == 0)cnt4++;
		else if (x >= 2 && x % 2 == 0)cnt2++;
	}
	cnt4 += (cnt2 / 2);
	cout << (cnt4 >= (n / 2) ? "Yes" : "No") << endl;

	return 0;
}

Measured memory_bytes: 640
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <cstring>
#include <deque>
#include <cstdio>
#include <cmath>
#include <complex>
#include <iostream>
#include <iterator>

using namespace std;

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

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;

typedef vector<double> vd;
typedef vector<vd> vvd;

int main()
{
	int seat[17] = {0};
	int answer[100];
	int sit = 0;
	deque<int> que;
	
	for(int i=0; sit<100; ++i){
		rep(j, 17)
			if(seat[j]) --seat[j];
		if(i%5 == 0)
			que.push_back(i/5);
		
		while(!que.empty()){
			int g = que.front();
			int n = g % 5 == 1 ? 5 : 2;
			int pos = search_n(seat, seat+17, n, 0) - seat;
			if(pos == 17)
				break;
			fill_n(seat+pos, n, 17*(g%2) + 3*(g%3) + 19);
			answer[que.front()] = i - g * 5;
			que.pop_front();
			++sit;
		}
	}

	int n;
	while(scanf("%d", &n) != EOF){
		printf("%d\n", answer[n]);
	}

	return 0;
}

Measured memory_bytes: 0
#!/usr/bin/env python3
import sys
from collections import defaultdict

def solve(N: int, X: int, Y: int):
    l = [0] * (N-1)
    for i in range(N):
        for j in range(i+1,N):
            cost = min(j-i,1+abs(Y-j-1)+abs(X-i-1))-1
            l[cost] += 1
    for ll in l:
        print(ll)
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    X = int(next(tokens))  # type: int
    Y = int(next(tokens))  # type: int
    solve(N, X, Y)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3820
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <string>
#include <map>

using namespace std;
int main(int argc, const char * argv[]) {
    
    int p, q, r;
    cin >> p >> q >> r;

    cout << min(p+q, min(q+r, p+r)) << endl;
    return 0;
}

Measured memory_bytes: 256
/*
 * Author - Abhas Jain
 * Code is inside the solve function
 */
 
#include <bits/stdc++.h>
 
#define F first
#define S second
#define all(c) c.begin(), c.end()
#define endl '\n'
#define pb push_back

typedef long long ll;
typedef long double ld;

using namespace std;
mt19937 rang(chrono::high_resolution_clock::now().time_since_epoch().count());
 
const ld PI = 3.141592653589793;
const ll INF = 9223372036854775807ll;
const ll mod = 1e9 + 7;
 
void solve() 
{
	int n;
	cin >> n;
	set<int> done;
	vector<int> a(n);
	vector<int> poss(1e6 + 2, 1);
	for (int i = 0; i < n; ++i) {
		cin >> a[i];
		if (done.find(a[i]) == done.end()) done.insert(a[i]);
		else {
			poss[a[i]] = 0;
		}
	}
	for (int x : done) {
		for (int j = 2; j * x < 1e6 + 2; ++j) {
			poss[x * j] = 0;
		}
	}
	int ans = 0;
	for (int num : a) if (poss[num]) ans++;
	cout << ans << endl;
}
 
int main( )
{   
    ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    srand(chrono::high_resolution_clock::now().time_since_epoch().count());
    solve();
    return 0;
}

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

int main(){
    int  a,b,c;
    cin>>a>>b>>c;
    if(a==b && a==c && b==c || a!=b && a!=c&& b!=c)cout<<"No"<<endl;
    else cout<<"Yes"<<endl;
    return 0;
}


Measured memory_bytes: 256
def enum_divisors(N):
    # 約数列挙
    import math as m
    a = set()
    for i in range(1, int(m.sqrt(N)) + 1):
        if N % i == 0:
            a.add(i)
            a.add(N // i)
    a = list(a)
    a.sort()
    return a


def resolve():
    N = int(input())
    a = enum_divisors(N)
    print(len(str(a[len(a) // 2])))


resolve()


Measured memory_bytes: 3188
/*
********************
Author : MIHIR ARORA
********************
*/
#include <bits/stdc++.h>
using namespace std;
#define fast cin.tie(NULL); cout.tie(NULL); 
#define input int n; scanf("%d",&n); int*arr = new int[n];  for(int i=0;i<n;i++) scanf("%d",&arr[i]);  
#define inputs int n; scanf("%d",&n); char str[n];   cin>>str;   

typedef long long int ll;
const int mod=1e9+7; 
ll add(ll a, ll b)
{
    return (a%mod+b%mod)%mod;
}

ll mul(ll a, ll b)
{
    return ((a%mod)*(b%mod))%mod;
}

ll sub(ll a, ll b)
{
    return ((a%mod) - (b%mod))%mod;
}
ll n;
ll w; 
inline long long int rec(long long int arr[100000][2],long long  int w, long long int idx, long long int** cache)
{
 if(w==0)
     return 0; 
    if(w<0)
        return -1e9; 
    if(idx==n)
        return 0; 
    if(cache[idx][w]!=-1)
        return cache[idx][w]; 
  long long  int a = arr[idx][1] + rec(arr,w-arr[idx][0],idx+1,cache); 
    long long    int b =  rec(arr,w,idx+1,cache);
    
    cache[idx][w]=max(a,b); 
     return max(a,b); 
}
inline void solve()
{

    cin>>n; 
    cin>>w; 
    ll  arr[100000][2]; 
    for(int i=0;i<n;i++)
        for(int j=0;j<2;j++)
            cin>>arr[i][j]; 
  long long   int **cache = new long long int*[n+1]; 
    for(int i=0;i<=n;i++)
        cache[i]=new long long int[w+1]; 
    for(int i=0;i<=n;i++)
        for(int j=0;j<=w;j++)
            cache[i][j]=-1; 

  cout<<  rec(arr,w,0,cache); 
    
}
int main()
{ 
    fast; 

        solve();
 
    
    
}

Measured memory_bytes: 79488
max = 999999
prime_list = [false, false] + [true] * (max - 1)

loop_max = (max**0.5)

(2..loop_max).each do |i|
  next unless prime_list[i]
  limit = ((max.to_f/i.to_f) - i.to_f).truncate
  base = (i*i)
  (0..limit).each do |j|
    prime_list[base + i*j] = false
  end
end

while gets do
  count = 0
  2.upto($_.to_i) { |i| count += 1 if prime_list[i] }
  puts count
end

Measured memory_bytes: 21796
long long t[21][2],a,d;main(b){scanf("%d%d",&a,&b),t[b][a&1]=1;for(;(d%=21)||--a-1&&scanf("%d",&b);t[d++][a&1]=((b>d?0:t[d-b][!(a&1)])+((b<(21-d))?t[b+d][!(a&1)]:0)));scanf("%d",&b);a=!printf("%lld\n",t[b][0]);}

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

#define ll long long

int main() {
	int n;
	cin >> n;
	vector<ll> v(n);
	for(int i = 0;i<n;i++)
		cin >> v[i];
	ll result = 0;
	sort(v.begin(),v.end(),greater<int>());
	result += v[0];
	//cout << v[0] << endl;
	int flag = 0; int runs = 0;
	int i = 1;
	while(runs < n-2) {
		if(flag == 1)
		{
			result += v[i];
			i++;
			flag = 0;
		}
		else
		{
			result += v[i];
			flag = 1;
		}
		runs++;
	}
	cout << result << endl;
	return 0; 
}

Measured memory_bytes: 4848
#include<bits/stdc++.h>
#define ll long long
const ll mod=998244353;
const ll N=2e5+5;
using namespace std;
ll gcd(ll a,ll b) {return b==0?a:gcd(b,a%b);}
ll lcm(ll a,ll b) { return a*b/gcd(a,b);    }
ll qp(ll a,ll b, ll p){ll ans = 1;while(b){if(b&1){ans = (ans*a)%p;--b;}a = (a*a)%p;b >>= 1;}return ans%p;}
ll Inv(ll x){ return qp(x,mod-2,mod);}
ll C(ll n,ll m){if (m>n) return 0;ll ans = 1;for (int i = 1; i <= m; ++i) ans=ans*Inv(i)%mod*(n-i+1)%mod;return ans%mod;}
map<int,int>mp;
int a[N];
int main()
{
    int n,flag=1;
    cin>>n;
    for(int i=0;i<n;i++) {cin>>a[i];if(!mp[a[i]]) mp[a[i]]=1;else flag=0;}
    if(flag) cout<<"YES"<<endl;
    else     cout<<"NO"<<endl;
    return 0;
}


Measured memory_bytes: 10368
A, B, C, D = map(int, input().split())

i = 0
while True:
    if i % 2 == 0:
        C -= B
    else:
        A -= D

    if A <= 0:
        print("No")
        break
    if C <= 0:
        print("Yes")
        break
    i += 1

Measured memory_bytes: 9176
#include <iostream>
#include <cctype>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <utility>
#include <string>
#include <functional>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <iomanip>
#include <bitset>
#include <array>
#define mp make_pair
#define YES cout<<"YES"<<endl
#define Yes cout<<"Yes"<<endl
#define NO cout<<"NO"<<endl
#define No cout<<"No"<<endl
#define rep(i,n) for(ll i=0;i<n;i++)
#define INF (1<<30)
#define LLINF (1LL<<60)
//#define MOD 998244353
#define MOD 1000000007
#define PI 3.14159265358979
using ll = long long;
using namespace std;

int main(){
    string s;
    cin >> s;
    if(s=="RRR")
        cout << "3" << endl;
    else if(s=="SSS")
        cout << "0" << endl;
    else if(s=="RRS"||s=="SRR")
        cout << "2" << endl;
    else
        cout << "1" << endl;
    return 0;
}

Measured memory_bytes: 3584
#include<stdio.h>

int main (void){
  int i,j,n,S[100000],q,T[100000],count=0;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&S[i]);
  }
  scanf("%d",&q);
  for(i=0;i<q;i++){
    scanf("%d",&T[i]);
  }
  for(i=0;i<q;i++){
    for(j=0;j<n;j++){
    if(S[j]==T[i]){
      count++;
      break;
    }
    }
  }
  printf("%d\n",count);
  return 0;
}

Measured memory_bytes: 648
#include <iostream>
#include <numeric>
#include <iomanip>
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)




int main() {
	double L;
	cin >> L;
	cout << fixed << setprecision(10);
	cout << (L * L * L) / 27 << endl;
}

Measured memory_bytes: 256
class Integer
  def divisors
    res = []
    1.upto((self**0.5)) do |i|
      if self % i == 0
        res.push i
        res.push self / i if i != self / i
      end
    end
    res.sort!
    block_given? ? res.each{|t| yield t } : res
  end
end

n, m = gets.to_s.split.map{|t| t.to_i }

m.divisors.reverse_each do |t|
  if m / t >= n && m % t == 0
    puts t
    exit
  end
end

Measured memory_bytes: 1916
#include <stdio.h>

int main()

{

    int a,b,c,num=0;
    scanf("%d %d",&a,&b);
    c = b-a;
    //printf("%d",c);
    
    for(int i=1;c>i;i++)
    {
        num += i;
    
    }
    printf("%d\n",num-a);
    
    return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define MAXSIZE 10000000;

bool comp(const pair<string,int> a, const pair<string,int> b) {
  if (a.first != b.first)
    return a.first < b.first; // 高い順に並べたいので演算子を逆に
  else{
      return a.second > b.second;
  }
}

int Dx[6] = { 0, 0, 1, 1,-1,-1};
int Dy[6] = { 1,-1, 1, 0, 0,-1};

//priority_queue<long long int,vector<long long int>, greater<long long int>> PQ;
//priority_queue<long long int> PQ1;
int main(){
    int X,A;

    cin >>X>>A;

    if(X<A)cout <<0<<endl;
    else cout <<10<<endl;

    return 0;
}

/*Syakutori
while(cin >>b && b)){
      ll t = 1;
      long long int ansS = 1,ansT=0;
      long long int sum = 0;

      for(ll s = 1;s < 50000000;s++){

        while(t <  50000000 && sum+Rsum[t] < b){
          sum += Rsum[t];
          t++;
        }
        if(b == sum+Rsum[t]){
          if(ansT - ansS < t-s){
            ansS = s;
            ansT = t;
          }
          cout <<ansS<<" "<<ansT-ansS + 1<<endl;
          break;
        }
        if(t == s)++t;
        else sum -= Rsum[s];
        }
    }

*/

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

using namespace std;

#define ll long long
#define ld long double

int grundy_(ll n, ll m, int a, int b) {
	if (n > m / 2) {
		if (n % 2 == m % 2)
			return a;
		else
			return b;
	}
	int g1 = grundy_((m / 2) * 2, m, a, b);
	int g2 = grundy_((m / 2) + 1, m, a, b);
	int next_a = 3;
	for (int i = 2; i >= 0; --i)
		if (i != g1 && i != g2)
			next_a = i;
	if (n == (m / 2)) return next_a;
	g1 = grundy_(((m / 2) - 1) * 2, m, a, b);
	int next_b = 3;
	for (int i = 2; i >= 0; --i)
		if (i != g1 && i != next_a)
			next_b = i;
	if (n == (m / 2) - 1) return next_b;
	return grundy_(n, (m / 2), next_a, next_b);
}

int grundy(ll n, ll m) {
	if (n == 2 && m >= 4) {
		int g1 = grundy(3, m);
		int g2 = grundy(4, m);
		for (int i = 0; i < 3; ++i)
			if (i != g1 && i != g2)
				return i;
	}
	if (n == 1 && m >= 2) {
		int g = grundy(2, m);
		for (int i = 0; i < 3; ++i)
			if (i != g)
				return i;
	}
	return grundy_(n, m, 0, 1);
}

signed main() {
	int k; cin >> k;

	int tmp = 0;
	while (k--) {
		ll n, m;
		cin >> n >> m;
		tmp ^= grundy(n, m);
	}

	if (tmp)
		cout << "mo3tthi" << endl;
	else
		cout << "tubuann" << endl;

	return 0;
}


Measured memory_bytes: 3116
n = int(input())
a_li = list(map(int,input().split()))
dum1 = a_li[0::2]
dum2 = a_li[1::2]
if n%2 == 0:
    dum2 = dum2[::-1]
    dum1 = " ".join(map(str,dum1))
    dum2 = " ".join(map(str,dum2))
    print(dum2+" "+dum1)
else:
    dum1 = dum1[::-1]
    dum1 = " ".join(map(str,dum1))
    dum2 = " ".join(map(str,dum2))
    print(dum1+" "+dum2)


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

using namespace std;

#define intt long long
#define FAST ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

int n, k;

int main() {
	
	cin >> n >> k;
	intt ans = 0;
	for (int b = k + 1; b <= n; b ++) {
		int x = n / b, m = n % b;
		if (x > 0) ans += 1LL * x * (b - k);
		if (m >= k) ans += m - k + 1;
	}
	if (!k) ans -= n;
	cout << ans << '\n';
}

Measured memory_bytes: 256
import math
from numba import jit

k = int(input())

@jit
def ans():
    sum = 0
    temp = 0
    for l in range(1,k+1):
        for m in range(1,k+1):
            temp = math.gcd(l,m)
            for n in range(1,k+1):
                sum += math.gcd(temp,n)
    return(sum)
print(ans())

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

int main(){
  int n;
  cin>>n;
  int d[n];
  REP(i,n){
    cin>>d[i];
  }
  int cnt=0;
  REP(i,n){
    for(int j=i+1;j<n;j++){
      cnt+=d[i]*d[j];
    }
  }
  cout<<cnt<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
using namespace std;
int main()
{
    ll a, b, ans = 1, cnt = 0;
    cin >> a >> b;
    while(ans < b)
    {
        ans --;
        ans += a;
        cnt ++;
    }
    cout << cnt;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll int
#define FOr(i,x,y)  for(ll i=x;i>=y;--i)
#define For(i,x,y)	for(ll i=x;i<=y;++i)
using namespace std;
const ll N=4010;
char s1[N],s2[N];
ll L[N],R[N],pre[N],nxt[N],a[N],b[N],now[N],n,dd[N],gg[N],answ=1e9;
bool pd(){
	bool a_has_1=0,b_has_1=0;
	For(i,0,n-1)	a_has_1|=a[i],
					b_has_1|=b[i];
	return a_has_1&&!b_has_1;
}
void Max(ll &x,ll y){	if (y>=x)	x=y;	}
int main(){
//	freopen("flip.in","r",stdin);
//	freopen("flip.out","w",stdout);
	scanf("%s%s",s1,s2);	n=strlen(s1);
	For(i,0,n-1)	a[i]=s1[i]-'0';
	For(i,0,n-1)	b[i]=s2[i]-'0';
	if (pd())	return puts("-1"),0;
	For(i,0,n-1)	L[i]=i-1,R[i]=i+1;	L[0]=n-1;	R[n-1]=0;
	For(i,0,n*2)	pre[i%n]=b[i%n]?i%n:pre[L[i%n]];
	FOr(i,n*2,0)	nxt[i%n]=b[i%n]?i%n:nxt[R[i%n]];
	For(i,0,n-1)	pre[i]=(i-pre[i])<0?(i-pre[i]+n):(i-pre[i]);
	For(i,0,n-1)	nxt[i]=(nxt[i]-i)<0?(nxt[i]-i+n):(nxt[i]-i);
	For(rev,0,n-1){//枚举 向左移动i
		ll ned_right=0,ned_left=0,cost=0;
		For(i,0,n-1)	now[i]=a[(i+rev)%n];
		For(i,0,n-1)	dd[i]=gg[i]=0;
		For(i,0,n-1)	cost+=now[i]!=b[i];
		For(i,0,n-1)	if (now[i]!=b[i]&&nxt[i]>rev&&pre[i])	Max(dd[nxt[i]-rev-1],pre[i]),Max(gg[pre[i]-1],nxt[i]-rev);
		FOr(i,n-1,0){
			Max(dd[i],dd[i+1]);	Max(gg[i],gg[i+1]);
			answ=min(answ,rev+cost+(min(dd[i],gg[i])+i)*2);
		}
	}
	For(rev,0,n-1){//枚举 向右移动i
		ll ned_left=0,ned_right=0,cost=0;
		For(i,0,n-1)	now[i]=a[(i-rev+n*2)%n];
		For(i,0,n-1)	dd[i]=gg[i]=0;
		For(i,0,n-1)	cost+=now[i]!=b[i];
		For(i,0,n-1)	if (now[i]!=b[i]&&pre[i]>rev&&nxt[i])	Max(dd[pre[i]-rev-1],nxt[i]),Max(gg[pre[i]-1],pre[i]-rev);
		FOr(i,n-1,0){
			Max(dd[i],dd[i+1]);	Max(gg[i],gg[i+1]);
			answ=min(answ,rev+cost+(dd[i]+i)*2);
		}
	}printf("%d",answ);
}


Measured memory_bytes: 384
#include <iostream>
using namespace std;
int main(void){
    int num[100][100], sum1[100] = {0}, sum2 = 0, SUM = 0;
    int i, j, r, c;

    scanf("%d %d", &r, &c);
    for(i = 0; i < r; i++){
        for(j = 0; j < c; j++){
            scanf("%d", &num[i][j]);
            sum1[i] += num[i][j];
        }
    }

    for(i = 0; i < r; i++){
        for(j = 0; j < c + 1; j++){
            if(j >= 0 && j < c)
                printf("%d ", num[i][j]);
            if(j == c)
                printf("%d", sum1[i]);
        }
        putchar('\n');
    }
    for(i = 0; i < c; i++){
        for(j = 0; j < r; j++){
            sum2 += num[j][i]; 
        }
        printf("%d ", sum2);
        sum2 = 0;
    }

    for(i = 0; i < r; i++)
        SUM += sum1[i];
    printf("%d\n", SUM);

    return 0;
} 


Measured memory_bytes: 3212
using System;
using System.Collections.Generic;
using System.Text;


namespace ConsoleApplication7
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] s = Console.ReadLine().Split(' ');

            int W = int.Parse(s[0]);
            int H = int.Parse(s[1]);
            int x = int.Parse(s[2]);
            int y = int.Parse(s[3]);
            int r = int.Parse(s[4]);

            int a = x - r;
            int b = x + r;
            int c = y - r;
            int d = y + r;

            if (a >= 0 && b <= W && c >= 0 && d <= H)
            {
                Console.WriteLine("Yes");
            }
            else 
            {
                Console.WriteLine("No");
            }

        }
    }
}

Measured memory_bytes: 5312
import sys


def input():
    return sys.stdin.readline().rstrip('\n')


def calc(X, K, D):
    X = abs(X)
    n = X // D
    if K <= n:
        return abs(X - K * D)
    if (K - n) % 2 == 0:
        return abs(X - n * D)
    else:
        return abs(X - (n + 1) * D)


(X, K, D) = tuple([int(s) for s in input().split()])
print(calc(X, K, D))

Measured memory_bytes: 61868
def main():
    N = int(input())
    T1, A1 = map(int, input().split())
    for _ in range(N-1):
        T2, A2 = map(int, input().split())
        n = max(-(-T1//T2),-(-A1//A2))
        T1,A1 = T2*n,A2*n
    print(T1 + A1)


if __name__ == '__main__':
    main()

Measured memory_bytes: 9124