akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long int lld;

int dp[111][111];
string arr[111];
int main(void){
	for(int e=0;e<111;e++) for(int p=0;p<111;p++) dp[e][p] = 1e9;
	int n,m;
	scanf("%d%d",&n,&m);
	for(int e=0;e<n;e++) cin >> arr[e];
	if(arr[0][0]=='#') dp[0][0] = 1;
	else dp[0][0] = 0;
	for(int e=0;e<n;e++){
		for(int p=0;p<m;p++){
			if(e==0&&p==0) continue;
			if(arr[e][p]=='.'){
				if(e) dp[e][p] = min(dp[e][p],dp[e-1][p]);
				if(p) dp[e][p] = min(dp[e][p],dp[e][p-1]);
			}else{
				if(e) dp[e][p] = min(dp[e][p],dp[e-1][p]+1);
				if(p) dp[e][p] = min(dp[e][p],dp[e][p-1]+1);
				for(int q=e;q>=0;q--){
					if(arr[q][p]=='.') break;
					for(int r=p;r>=0;r--){
						if(arr[q][r]=='.') break;
						dp[e][p] = min(dp[e][p],dp[q][r]);
					}
				}
			}
		}
	}
	printf("%d",dp[n-1][m-1]);
	return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,x,y) for(ll i=x;i<=y;i++)
#define imin INT_MIN
#define imax INT_MAX
int mod =1e9+7;

int main(){
	cin.tie(NULL);
    ios_base::sync_with_stdio();
    int tem; cin>>tem;
    if(tem>= 30){
        cout<<"Yes";
    }else{
        cout<<"No";
    }
	return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define lli long long int
#define pb push_back
using namespace std;

const lli MAX = 2e5+9;

int main(void)
{
	lli n, ans = 0;
	cin >> n;
	lli a[MAX], count[MAX], hash[MAX];
	
	for(lli i = 0; i <= MAX; i++)
	{
		count[i] = 0;
		hash[i] = -1;
	}

	vector <lli> v;
	for(lli i = 0; i < n; i++)
	{
		cin >> a[i];
		count[a[i]]++;
//		cout << "count[" << a[i] << "] = " << count[a[i]] << endl;
		if(hash[a[i]] == -1)
		{
			hash[a[i]] = 0;
			v.pb(a[i]);
		}
	}
	for(lli i = 0; i < v.size(); i++)
	{
		ans += (count[v[i]]*(count[v[i]] - 1))/2;
//		cout << "v[" << i << "] = " << v[i] << endl;
		// cout << "ans = " << ans << endl;
	}
	for(lli i = 0; i < n; i++)
	{
		lli c = count[a[i]];
//		cout << c << endl;
		ans -= (c - 1);
		cout << ans << endl;
		ans += (c - 1);
	}




	return 0;
}

Measured memory_bytes: 7412
#include<stdio.h>

int main()
{
    int a,b,c,k,x,max,sum;

    scanf(" %d %d %d %d",&a,&b,&c,&k);

    max=a;
    if(max<b){
        max=b;
    }
    if(max<c){
        max=c;
    }

    for(x=0;x<k;x++){
        max*=2;
    }
    sum=a+b+max;
    if(sum>a+c+max){
        sum=a+c+max;
    }
    if(sum>b+c+max){
        sum=b+c+max;
    }
    printf("%d",sum);

    return 0;
}


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

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    ll n;
    cin>>n;
    ll ans=0,k=100;
    while(k<n){
        k+=k/100;
        ans++;
    }
    cout<<ans<<endl;
    return 0;
}



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


/* エイリアス */
#define ll long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vpi vector<pii>
#define vpll vector<pll>
#define endl '\n'

#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define em emplace


/* 関数マクロ */
#define rep(i, n) for (ll i = 0; i < n; ++i)
#define rep2(i, n, m) for (ll i = n; i <= m; ++i)
#define rep3(i, n, m) for (ll i = n; i >= m; --i)
#define all(v) v.begin(), v.end()
#define si(v) int(v.size())
#define UNIQUE(v) sort(all(v)), v.erase(unique(all(v)),v.end())


/* 定数 */
const ll mod = 1e9 + 7;
const ll infll = (1LL << 62) - 1;
const ll inf = (1LL << 30) - 1;


/* その他 */
template<class S, class T> inline bool chmax(S &a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class S, class T> inline bool chmin(S &a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T> using pq = priority_queue<T>;
template<class T> using pqg = priority_queue<T, vector<T>, greater<T>>;


signed main()
{
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cout << fixed << setprecision(15);

  int n, k; cin >> n >> k;
  map<int,int> mp;

  rep(i, n) {
    int a; cin >> a;
    ++mp[a];
  }

  vi v;
  for (auto e : mp) v.eb(e.se);

  sort(all(v));
  int sum = 0;

  rep(i, si(v)-k) sum += v[i];

  cout << sum << endl;
}

Measured memory_bytes: 13524
local function getgcd(x, y)
  while 0 < x do
    x, y = y % x, x
  end
  return y
end
local n = io.read("*n")
local a = {}
for i = 1, n do
  a[i] = io.read("*n")
end
local left = {a[1]}
for i = 2, n - 1 do
  left[i] = getgcd(left[i - 1], a[i])
end
local right = {a[n]}
for i = n - 1, 2, -1 do
  right[n - i + 1] = getgcd(right[n - i], a[i])
end
local mmi, mma = math.min, math.max
local ret = mma(left[n - 1], right[n - 1])
for i = 1, n - 2 do
  local cand = getgcd(left[i], right[n - 1 - i])
  ret = mma(ret, cand)
end
print(ret)


Measured memory_bytes: 6520
#include <bits/stdc++.h>
using namespace std;
const int M= 200005;
string s;
int main()
{
	getline(cin,s);
	int temp =1;
	for(int i=0;i<s.length()-1;i++){
		if(s[i+1] != s[i]){
			temp++;
			continue;
		}
		else{
			if(i==s.length()-3){
				temp++;
				break;				
			}
			if(i==s.length()-2){
				break;
			}
			temp=temp+2;
			i=i+2;
		}
	}
	cout << temp<<endl;
}

Measured memory_bytes: 640
s = input()
t = input()

rev_s = ""
flag = 0

for i in range(len(t)):
    t = t[-1] + t[:len(t)-1]
    # print(t)

    if s == t:
        flag  = 1
        break
    else:
        flag  = 0

if flag == 1:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 9052
#include<bits/stdc++.h>
#define fi first
#define se second
#define lc (x<<1)
#define rc (x<<1|1)
#define gc getchar()//(p1==p2&&(p2=(p1=buf)+fread(buf,1,size,stdin),p1==p2)?EOF:*p1++)
#define mk make_pair
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pb push_back
#define IT iterator
#define vi vector<int>
#define TP template<class o>
#define SZ(a) ((int)a.size())
#define all(a) a.begin(),a.end()
using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
const int N=2e5+10,size=1<<20,mod=998244353,inf=2e9;

//char buf[size],*p1=buf,*p2=buf;
template<class o> void qr(o &x) {
    char c=gc; x=0; int f=1;
    while(!isdigit(c)){if(c=='-')f=-1; c=gc;}
    while(isdigit(c)) x=x*10+c-'0',c=gc;
    x*=f;
}
template<class o> void qw(o x) {
    if(x/10) qw(x/10);
    putchar(x%10+'0');
}
template<class o> void pr1(o x) {
    if(x<0)x=-x,putchar('-');
    qw(x); putchar(' ');
}
template<class o> void pr2(o x) {
    if(x<0)x=-x,putchar('-');
    qw(x); putchar('\n');
}

int n,a[N];

ll power(ll a,ll b=mod-2) {
	ll c=1;
	while(b) {
		if(b&1) c=c*a%mod;
		b /= 2; a=a*a%mod;
	}
	return c;
}

int main() {
//	qr(n);
//	for(int i=1;i<=n;i++) qr(a[i]);
	ll a,b,c,d,ans=-1e18;
	qr(a);qr(b); qr(c); qr(d);
	ans=max(ans,a*c);
	ans=max(ans,a*d);
	ans=max(ans,b*c);
	ans=max(ans,b*d);
	if(a<0&&0<b) ans=max(ans,0LL);
	if(c<0&&0<d) ans=max(ans,0LL);
	pr2(ans);
	return 0;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
#include <assert.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define PB push_back
#define MP make_pair
#define MOD 1000000007LL
#define endl "\n"
const ll UNDEF = -1;
const ll INF=1e18;
template<typename T> inline bool chkmax(T &aa, T bb) { return aa < bb ? aa = bb, true : false; }
template<typename T> inline bool chkmin(T &aa, T bb) { return aa > bb ? aa = bb, true : false; }
ll mod_pow(ll a, ll n) {
	ll ret = 1; ll p = a % MOD; while (n) { if (n & 1) ret = ret * p % MOD; p = p * p % MOD; n >>= 1; } return ret; 
}
inline ll mod_inv(ll a) {
	return mod_pow(a,MOD-2);
}
const ll mn=5e5+4;
const ll mnd2=mn/2;
const ll p=101;
ll ht[mn];
ll deninv[mn];
ll ppow[mn];
ll ppowinv[mn];
inline ll add(ll x, ll y) {return (x+y+MOD)%MOD;}
inline ll mul(ll x, ll y) {return (x*y)%MOD;}
inline ll gethash(ll x, ll y) {
	return mul(add(ht[y],-ht[x]),ppowinv[x]);;
}
inline ll geom(ll n, ll len) {
	ll num=add(1,-ppow[len*n]);
	return mul(num,deninv[len]);
}
inline ll powup(ll small, ll num, ll len) {
	return mul(small,geom(num,len));
}
bool isgood(ll x, ll y, ll d) {
	ll k=y-x;
	ll actual=gethash(x,y);
	{
		//printf("k:%lld d:%lld\n",k,d);
		//if(d==k) continue;
		ll small=gethash(x,x+d);
		ll num=k/d;
		ll len=d;
		ll big=powup(small, num, len);
		if (big==actual) {
			return false;
		}
	}
	return true;
}
ll vans[mn];
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	{
		ll t=1;
		for (ll x=0;x<mn;x++) {
			ppow[x]=t;
			deninv[x]=mod_inv(add(1,-t));
			ppowinv[x]=mod_inv(t);
			t=(t*p)%MOD;
		}
	}
	string s; cin>>s;
	ll n=s.length();
	ll h=0;
	ht[0]=h;
	ll m=1;
	for (ll x=0;x<n;x++) {
		h+=((s[x]-'a'+1)*m);
		h%=MOD;
		//printf("x:%lld h:%lld\n",x+1,h);
		ht[x+1]=h;
		m=(m*p)%MOD;
	}
	bool same=true;
	for (ll x=1;x<n;x++) {
		if (s[x]!=s[0]) same=false;
	}
	if (same) {
		printf("%lld\n1\n",n);
	}
	else {
		for (ll x=1;x<=n;x++) vans[x]=1;
		for (ll d=1;d<=n/2;d++) {
			for (ll y=d*2;y<=n;y+=d) {
				if (!isgood(0,y,d)) vans[y]=0;
				if (y<n&&!isgood(n-y,n,d)) vans[n-y]=0;
			}
		}
		if (vans[n]) {
			printf("1\n1\n");
		}
		else {
			ll ans=0;
			for (ll x=1;x<n;x++) {
				ans+=vans[x];
			}
			printf("2\n%lld\n",ans);
		}
	}
}

Measured memory_bytes: 20380
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#define For(i,j,k) for(int i=j;i<=k;i++)
#define Dow(i,j,k) for(int i=j;i>=k;i--)
#define LL long long
using namespace std;
inline int read() {
	int x = 0,f = 1;
	char ch = getchar();
	while(ch<'0'||ch>'9') { if(ch=='-') f = -1; ch = getchar(); }
	while(ch>='0'&&ch<='9') { x = x *10+ch-48 ; ch = getchar(); }
	return x * f ;
}

const int N = 1e5+11;
int n,m;
int a[N];
LL p[N*2];
LL all,ans;

int main() {
	n=read(); m=read();
	all = 0;
	For(i, 0, n-1) a[i]=read(); 
	For(i, 1, n-1) {
		int l = a[i-1], r = a[i];
		if(l>r) r+=m;
		all+= r-l;
		if( r-l>1 ) {
			p[l+2] += 1;
			p[r+1] -= r-(l+2)+1 +1;
			p[r+2] += r-(l+2)+1;
		}
	}
	For(i, 1, 2*m) p[i]+=p[i-1];
	For(i, 1, 2*m) p[i]+=p[i-1];
	For(i, 1, m) ans=max(ans,p[i]+p[i+m]);
	printf("%lld\n",all-ans);
	return 0;
}

Measured memory_bytes: 2176
N=int(input())
a=list(map(int,input().split()))

color=[0 for i in range(8)]
free=0

for rate in a:
    if(rate<=399):
        color[0]+=1
    elif(rate<=799):
        color[1]+=1
    elif(rate<=1199):
        color[7]+=1
    elif(rate<=1599):
        color[2]+=1
    elif(rate<=1999):
        color[3]+=1
    elif(rate<=2399):
        color[4]+=1
    elif(rate<=2799):
        color[5]+=1
    elif(rate<=3199):
        color[6]+=1
    else:
        free+=1

if(free == N ):
    print(1,free)
else:
    ans=len([i for i in color if i != 0])
    print(ans,ans+free)




Measured memory_bytes: 3064
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<iostream>
#include<string>
#include<stack>
#include<queue>
#include<vector>
#include<map>
#include<set>
#include<algorithm>
#include<numeric>

#define rep(n) for(int i=0;i<n;i++)
#define repp(j, n) for(int j=0;j<n;j++)
#define reppp(i, m, n) for(int i=m;i<=n;i++)
#define all(c) c.begin(), c.end()
#define rall(c) c.rbegin(), c.rend()
#define pb(x) push_back(x)
#define eb(x,y) emplace_back(x,y)
#define MOD 1000000007
#define MAX 1000000001
#define INF 1410065408
#define EPS 1e-9
#define DEBUG 0
#define ll long long
#define Pll pair<ll, ll>
#define Pii pair<int, int>
#define Pdd pair<double, double>
 
using namespace std;
struct edge{int from, to; ll cost;};

signed main(){
    ios::sync_with_stdio(false); cin.tie(0);
    vector< Pdd > v;
    double n, tmp, second = 0.25;
    rep(4){
        cin >> tmp;
        v.pb(Pdd(tmp * (2.0/second), second));
        second *= 2;
    }
    cin >> n;

    sort(all(v));
    ll ans = 0;
    rep(4){
        Pdd p = v[i];
        double price = p.first * (p.second/2.0);
        ll tmp = n / p.second;
        n -= (double)tmp * p.second;
        ans += (ll)price * tmp;
        if(n == 0) break;
    }
    cout << ans;
}


Measured memory_bytes: 256
from bisect import bisect_right

s = input()
t = input()

table = {}
for i in range(len(s)):
    if s[i] in table:
        table[s[i]].append(i)
    else:
        table[s[i]] = [i]

dup = 0
prev = -1
for i in range(len(t)):
    if t[i] not in table:
        print(-1)
        exit()

    ind_list = table[t[i]]
    if prev < ind_list[-1]:
        temp = bisect_right(ind_list, prev)
        prev = ind_list[temp]
        continue
    else:
        dup += 1
        prev = ind_list[0]

print(dup * len(s) + prev + 1)


Measured memory_bytes: 46192
//あなたは、X 円を持ってケーキとドーナツを買いに出かけました。

//あなたはまずケーキ屋で 1 個 A 円のケーキを 1 個買いました。 次に、ドーナツ屋で 1 個 B 円のドーナツをできるだけたくさん買いました。

//これらの買い物のあと手元に残っている金額は何円ですか。

import java.util.Scanner;

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

    int A , B , X ;   //1≤A,B≤1,000
                      //A+B≤X≤10,000
                      //X,A,B は整数である

    X = stdIn.nextInt();

    A = stdIn.nextInt();

    B = stdIn.nextInt();

    X = X - A;
    for (; X >= B ; ) {
      X = X - B;
    }
    System.out.println(X);
  }
}


Measured memory_bytes: 23764
import java.util.*;
import java.io.*;

public class Main {
	static long mod = 1_000_000_007; 
	public static long fact(long n ) {
		long t = 1; 
		for(int i = 1; i<=n; i++) {
			t *= i; 
			t = t%mod; 
		}
		return t; 
	}
	public static void main (String[] args) {
	   InputReader in = new InputReader(System.in);
	   int d = in.readInt();
	   int m = in.readInt();
	   if(Math.abs(d-m) > 1) {
		   System.out.println(0);  
		   return; 
	   }
	   long ans = (fact(d) * fact(m))% mod;
	   if(d == m) {
		   ans = 2*ans; 
		   System.out.println(ans%mod);
	   }
	   else System.out.println(ans);
	}
}

class InputReader {

	private InputStream stream;
	private byte[] buf = new byte[1024];
	private int curChar;
	private int numChars;
	private SpaceCharFilter filter;

	public InputReader(InputStream stream) {
		this.stream = stream;
	}

	public int read() {
		if (numChars == -1)
			throw new InputMismatchException();
		if (curChar >= numChars) {
			curChar = 0;
			try {
				numChars = stream.read(buf);
			} catch (IOException e) {
				throw new InputMismatchException();
			}
			if (numChars <= 0)
				return -1;
		}
		return buf[curChar++];
	}

	public int readInt() {
		int c = read();
		while (isSpaceChar(c))
			c = read();
		int sgn = 1;
		if (c == '-') {
			sgn = -1;
			c = read();
		}
		int res = 0;
		do {
			if (c < '0' || c > '9')
				throw new InputMismatchException();
			res *= 10;
			res += c - '0';
			c = read();
		} while (!isSpaceChar(c));
		return res * sgn;
	}

	public String readString() {
		int c = read();
		while (isSpaceChar(c))
			c = read();
		StringBuilder res = new StringBuilder();
		do {
			res.appendCodePoint(c);
			c = read();
		} while (!isSpaceChar(c));
		return res.toString();
	}

	public long readLong() {
		int c = read();
		while (isSpaceChar(c)) {
			c = read();
		}
		int sgn = 1;
		if (c == '-') {
			sgn = -1;
			c = read();
		}
		long res = 0;
		do {
			if (c < '0' || c > '9') {
				throw new InputMismatchException();
			}
			res *= 10;
			res += c - '0';
			c = read();
		} while (!isSpaceChar(c));
		return res * sgn;
	}
	
	public boolean isSpaceChar(int c) {
		if (filter != null)
			return filter.isSpaceChar(c);
		return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
	}

	public String next() {
		return readString();
	}

	public interface SpaceCharFilter {
		public boolean isSpaceChar(int ch);
	}
}


Measured memory_bytes: 21332
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int N = 1e6 + 5, INF = 0x3f3f3f3f;
inline int read() {
	int x = 0, f = 0; char ch = 0;
	while (!isdigit(ch)) f |= ch == '-', ch = getchar();
	while (isdigit(ch)) x = (x << 3) + (x << 1) + (ch ^ 48), ch = getchar();
	return f ? -x : x;
}
int head[N], tot = 0;
struct edge {
	int to, nxt;
}e[N];
int f[N], g[N], pre[N], suf[N], p[N], ans[N], m;
int n, x, y;
inline void addedge(int x, int y) {
    e[++tot].to = y, e[tot].nxt = head[x], head[x] = tot;
}
void dfs(int x, int fa) {
    int cnt = 0;
    f[x]++;
    for (int i = head[x]; i; i = e[i].nxt) {
    	int y = e[i].to;
    	if (y != fa) {
    		dfs(y, x); f[x] = f[x] * f[y] % m;
    	}
    }
    for (int i = head[x]; i; i = e[i].nxt) {
    	int y = e[i].to;
        if (y != fa) p[++cnt] = y;
    }
    f[x]++, f[x] %= m;
    pre[0] = suf[cnt + 1] = 1;
    for (int i = 1; i <= cnt; i++) pre[i] = pre[i - 1] * f[p[i]] % m;
    for (int i = cnt; i >= 1; i--) suf[i] = suf[i + 1] * f[p[i]] % m;
    for (int i = 1; i <= cnt; i++) g[p[i]] = pre[i - 1] * suf[i + 1] % m;
}
void dfs2(int x, int fa) {
    if (x == 1) ans[x] = 1;
    else ans[x] = (g[x] * ans[fa] + 1) % m;
    for (int i = head[x]; i; i = e[i].nxt) {
    	int y = e[i].to;
    	if (y != fa) dfs2(y, x);
    }
}
signed main() {
    n = read(), m = read();
    for (int i = 1; i < n; i++) {
    	int x = read(), y = read();
        addedge(x, y), addedge(y, x);
    }
    dfs(1, 0); dfs2(1, 0);
    for (int i = 1; i <= n; i++) printf("%lld\n", ans[i] * (m + f[i] - 1) % m);
    return 0;
}

Measured memory_bytes: 24576
num_s, *D,  = [s.split() for s in open(0)]
num_s = int(num_s[0])
dic = {}

for d in D:
    if d[0] == "insert":
        dic[d[1]] = 1
    else:
        if d[1] in dic:
            print("yes")
        else:
            print("no")


Measured memory_bytes: 308396
package main

import (
	"fmt"
)

func main() {
	var aa string
	fmt.Scanf("%s", &aa)
	length := len(aa)
	count := 0
	for ii := 0; ii < length/2; ii++ {
		if aa[ii] != aa[length-1-ii] {
			count++
		}
	}
	fmt.Printf("%d\n", count)
}


Measured memory_bytes: 512
#include<stdio.h>
#include<algorithm>
#include<iostream>
#include<queue>
#include<cmath>
#include<string.h>
#include<set>
#include<map>
#define LL long long
#define pr pair<int,int>
#define fr first
#define sc second
//#define mp make_pair
using namespace std;
LL read( ){LL sum=0;char c=getchar( );bool f=0;while(c<'0' || c>'9') {if(c=='-') f=1;c=getchar( );}while(c>='0' && c<='9') {sum=sum*10+c-'0';c=getchar( );}if(f) return -sum;return sum;}
void read(int &sum){sum=0;char c=getchar( );bool f=0;while(c<'0' || c>'9') {if(c=='-') f=1;c=getchar( );}while(c>='0' && c<='9') {sum=sum*10+c-'0';c=getchar( );}if(f) sum=-sum;}
void read(LL &sum){sum=0;char c=getchar( );bool f=0;while(c<'0' || c>'9') {if(c=='-') f=1;c=getchar( );}while(c>='0' && c<='9') {sum=sum*10+c-'0';c=getchar( );}if(f) sum=-sum;}
const int N=200005;
int n,pos[N],ans[N],l[N],r[N],L[N],R[N];
struct ex{int x,y,id;}S[N];
bool operator < (ex a,ex b) {return a.x<b.x;}
vector<int>E[N];
bool ed[N];
int cnt;
vector<int>G;
void dfs(int x)
{
  if(ed[x]) return;
  ed[x]=1;
  cnt++;G.push_back(x);
  for(auto &y:E[x]) dfs(y);
}
int main( )
{
  int i,j;
  read(n);
  for(i=1;i<=n;i++) read(S[i].x),read(S[i].y),S[i].id=i;
  sort(S+1,S+n+1);
  for(i=1;i<=n;i++) pos[S[i].y]=i;
  set<int>SA;
  int mn = n+1;
  for(i=1;i<=n;i++)
    {
      SA.insert(S[i].y);
      set<int>::iterator it=SA.find(S[i].y);
      if(it==SA.begin( )) j=S[i].y;
      else j=*(--it);
      l[i] = pos[j];
      mn = min(mn,S[i].y);
      L[i] = pos[mn];
    }
  SA.clear( );
  int mx = 0;
  for(i=n;i>=1;i--)
    {
      SA.insert(S[i].y);
      set<int>::iterator it=SA.find(S[i].y);
      it++;
      if(it==SA.end( )) j=S[i].y;
      else j=*it;
      r[i] = pos[j];
      mx = max(mx,S[i].y);
      R[i] = pos[mx];
    }
  for(i=1;i<=n;i++)
    {
      E[i].push_back(l[i]);
      E[l[i]].push_back(i);
      E[i].push_back(r[i]);
      E[r[i]].push_back(i);

      E[i].push_back(L[i]);
      E[L[i]].push_back(i);
      E[i].push_back(R[i]);
      E[R[i]].push_back(i);
    }
  for(i=1;i<=n;i++)
    {
      if(ed[i]) continue;
      cnt=0;G.clear( );dfs(i);
      for(auto &y:G) ans[S[y].id]=cnt;
    }
  for(i=1;i<=n;i++)
    printf("%d\n",ans[i]);
  return 0;
}


Measured memory_bytes: 39524
#include<bits/stdc++.h>
using namespace std;
int main() {
	long long a,b,x,i,j;
	cin>>a>>b>>x;
	if(a%x==0) {
		i=a/x;
	} else {
		i=a/x+1;
	}
	j=b/x;
	cout<<j-i+1<<"\n";
	return 0;
}

Measured memory_bytes: 256
open Scanf
open Printf

let rec scan_list = function
  | 1 -> scanf "%d" (fun k -> [k])
  | n -> scanf "%d " (fun k -> k :: scan_list (n-1))

let rec gcd a b = if b = 0
  then a
  else gcd b (a mod b)

let lcm a b = a * (b / (gcd a b))

let f a m = List.fold_left ( + ) 0 (List.map (fun x -> m mod x) a)

let rec search lst m s n = if s = n
  then m
  else search lst (max m (f lst n)) s (n-1)

let () = let lst = scanf "%d\n" scan_list in
  (* printf "%d\n" (search lst 0 (List.fold_left min 1000000 lst) (List.fold_left lcm 1 lst)) *)
  (* printf "%d\n" (f lst (List.fold_left lcm 1 lst - 1)) *)
  printf "%d\n" (List.fold_left ( + ) 0 lst - List.length lst)

Measured memory_bytes: 1536
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cctype>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define MOD 1000000007
#define rep(i,n) for(i=0;i<(n);i++)
#define loop(i,a,n) for(i=a;i<(n);i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int,int> pii;

int main(void) {
    int i,j;
    int n, w;
    while(cin >> n >> w, n){
        int a[15] = {};
        int k = 0;// max index
        rep(i,n){
            int v;
            cin >> v;
            a[v/w]++;
            k = max(k, v/w);
        }
        k++;
        int ma = 0;
        rep(i,k){
            ma = max(ma, a[i]);
        }
        double ans = 0.01;
        rep(i,k){
            ans += (1.*a[i]/ma)*(k-i-1)/(k-1);
        }
        cout << shosu(10) << ans << endl;
    }
}



Measured memory_bytes: 3160
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define f(i, x, n) for(int i = x; i < (int)(n); ++i)

ll x[100000];

int main(){
	int n;
	scanf("%d", &n);
	f(i, 0, n)scanf("%lld", x + i);
	sort(x, x + n);
	f(i, 1, n)x[i] += x[i - 1];
	int i = n - 2;
	while (i >= 0 && x[i] << 1 >= x[i + 1] - x[i])--i;
	printf("%d\n", n - 1 - i);
}


Measured memory_bytes: 1024
n=int(input())
a=list(map(int,input().split()))
now=0
p=a[0]
cnt=1
for i in range(n):
	if a[i]>p:
		if now=="-":
			cnt+=1
			now=0
		else:
			now="+"
	elif a[i]<p:
		if now=="+":
			cnt+=1
			now=0
		else:
			now="-"
	p=a[i]
print(cnt)


Measured memory_bytes: 14252
A = int(input())
l = []
for i in range(A):
    A = input().split()
    B = int(A[1])
    A = A[0]
    l.append([A,B])
l_after = list(l)
l_after.sort(key=lambda x:(x[0],-x[1]))
for i in l_after:
    print(l.index(i)+1)

Measured memory_bytes: 3060
#include<iostream>
#define MAX 100
#define NOW 110
#include<cstring>
#include<algorithm>
#include<vector>
using namespace std;
typedef long long int ll;
//typedef int ll;
vector<ll> vec;
ll dp[MAX][NOW];
ll n;
ll func(ll sum,ll now){
	if(sum<0||sum>20)
		return 0;
	
	if(dp[sum][now]!=-1)
		return dp[sum][now];
	if(now==n-1){
		if(vec[n-1]==sum)
			return 1;
		else
			return 0;
	}
	ll ret=0;
	ret+=func(sum-vec[now],now+1);
	ret+=func(sum+vec[now],now+1);
	return (dp[sum][now]=ret);
}
int main(){
	cin>>n;
	
	memset(dp,-1,sizeof(dp));
	//fill(dp,dp,-1);
	/*for(int i=0;i<MAX;i++){
		for(int j=0;j<NOW;j++)
			dp[i][j]=-1;
	}*/
	for(ll i=0;i<n;i++){
		ll x;
		cin>>x;
		vec.push_back(x);
	}
	cout<<func(vec[0],1)<<endl;
	return 0;
}

Measured memory_bytes: 0
#include<iostream>
#include <math.h>
#include <cstdio>

using namespace std;

int main(){
	double a, b, C, c, S, L, h;
	cin >> a >> b >> C;
	
	c = sqrt(pow(a, 2.0) + pow(b, 2.0) - 2.0 * a * b * cos(C * (M_PI / 180.0)));
	L = a + b + c;
	S = a * b * sin(C * (M_PI / 180.0)) / 2.0;
	h = b * sin(C * (M_PI / 180.0));
	
	printf("%.8f\n%.8f\n%.8f\n", S, L, h);
	
	return 0;
}

Measured memory_bytes: 3468
//              +-- -- --++-- +-In the name of ALLAH-+ --++-- -- --+              \\

#include <bits/stdc++.h>

#define int ll

#define F first
#define S second
#define _sz(x) (int)x.size()

using namespace std ;
using ll = long long ;
using ld = long double ;
using pii = pair <int , int> ;

const int N = 1e5 + 20 ;
int n , m , a[N] , b[N] , c[N] , sec[N] ;
vector <int> tmp[N] , g[N] ;

int par[N] ;

inline bool byC (int i , int j) { return c[i] < c[j] ; }

int root (int v) { return par[v] < 0 ? v : par[v] = root(par[v]) ; }

inline void merge (int u , int v) { // c[u] >= c[v]
	if ((u = root(u)) == (v = root(v))) return ;

	g[u].push_back(v) ;
	par[v] = u ;
}

ll sum[N] , res[N] ;

void dfs (int v) {
	ll mx = 0 ;

	sum[v] = b[v] ;

	for (int u : g[v]) {
		dfs(u) ;

		sum[v] += sum[u] ;
		mx = max(mx , sum[u] - max(0ll , res[u] - c[v])) ;
	}

	res[v] = sum[v] + c[v] - mx ;
}

int32_t main(){
	ios::sync_with_stdio(false) , cin.tie(0) , cout.tie(0) ;

	cin >> n >> m ;

	for (int i = 0 ; i < n ; i ++) {
		cin >> a[i] >> b[i] ;
		a[i] = max(a[i] , b[i]) ;
		
		c[i] = a[i] - b[i] ;
	}

	iota(sec , sec + n , 0) ;
	sort(sec , sec + n , byC) ;

	for (int i = 0 , u , v ; i < m ; i ++) {
		cin >> u >> v ;
		u -- , v -- ;

		tmp[u].push_back(v) ;
		tmp[v].push_back(u) ;
	}

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

	for (int i = 0 ; i < n ; i ++) {
		int v = sec[i] ;
		for (int u : tmp[v])
			if (c[u] <= c[v]) merge(v , u) ;	
	}

	int root = sec[n - 1] ;
	dfs(root) ;

	cout << res[root] << '\n' ;
}


Measured memory_bytes: 20472
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int inf = 1e9 + 7;
const ll longinf = 1LL << 60;
const ll mod = 1e9 + 7;

int main() {
    ll N, K;
    cin >> N >> K;
    vector<ll> v;
    v.push_back(N);
    if(N % K == 0) v.push_back(0);
    v.push_back(N % K);
    v.push_back(abs((N % K) - K));
    sort(v.begin(), v.end());
    cout << v[0];
    return 0;
}

Measured memory_bytes: 256
def solve():
	A, B = list(map(int, input().split()))
	S = input()
	if len(S) != (A+B+1) or S[A] != "-" or not S[:A].isdigit() or not S[A+1:].isdigit():
		print("No")
		return
	else:
		print("Yes")
	
solve()

Measured memory_bytes: 2940
import collections


def main():
    n = int(input())
    word_list = [input() for _ in range(n)]
    
    c = collections.Counter(word_list)
    max_freq = max(c.values())
    most_freq_word = sorted([i for i in c if c[i] == max_freq])
    print('\n'.join(most_freq_word))


if __name__ == '__main__':
    main()

Measured memory_bytes: 116296
package main

import (
	"bufio"
	"fmt"
	"os"
	"reflect"
	"strconv"
)

const (
	maxBufSize = 1024 * 1024
)

var (
	sc = func() *bufio.Scanner {
		sc := bufio.NewScanner(os.Stdin)
		buf := make([]byte, 1)
		sc.Buffer(buf, maxBufSize)
		sc.Split(bufio.ScanWords)
		return sc
	}()
	out = bufio.NewWriter(os.Stdout)
)

const mod int64 = 5
const yes = "YES"
const no = "NO"

func solve(a int64, b int64, c int64) bool {
	for i := int64(1); i <= int64(100); i ++ {
		if (a * i) % b == c {
			return true
		}
	}
	return false
}

func main() {
	defer out.Flush()

	a := nextInt()
	b := nextInt()
	c := nextInt()
	if solve(a, b, c) {
		fmt.Fprintln(out, yes)
	} else {
		fmt.Fprintln(out, no)
	}
}

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextStringAsBytes() []byte {
	sc.Scan()
	return []byte(sc.Text())
}

func nextInt() int64 {
	a, _ := strconv.ParseInt(next(), 10, 64)
	return a
}

func nextFloat() float64 {
	a, _ := strconv.ParseFloat(next(), 64)
	return a
}

func nextInts(n int64) []int64 {
	ret := make([]int64, n)
	for i := int64(0); i < n; i++ {
		ret[i] = nextInt()
	}
	return ret
}

func nextFloats(n int64) []float64 {
	ret := make([]float64, n)
	for i := int64(0); i < n; i++ {
		ret[i] = nextFloat()
	}
	return ret
}
func nextStrings(n int64) []string {
	ret := make([]string, n)
	for i := int64(0); i < n; i++ {
		ret[i] = next()
	}
	return ret
}

func containStr(arr []string, target string) bool {
	for _, v := range arr {
		if v == target {
			return true
		}
	}
	return false
}

func PrintOut(src interface{}, joinner string) {
	switch reflect.TypeOf(src).Kind() {
	case reflect.Slice:
		s := reflect.ValueOf(src)
		for idx := 0; idx < s.Len(); idx++ {
			fmt.Fprintf(out, "%v", s.Index(idx))
			if idx < s.Len()-1 {
				fmt.Fprintf(out, "%s", joinner)
			} else {
				fmt.Fprintln(out)
			}
		}
	default:
		fmt.Fprintln(out, "orz")
	}
}

// mapからkeysとvaluesを返す
func splitKeyValue(m map[interface{}]interface{}) (keys, values []interface{}) {
	switch reflect.TypeOf(m).Kind() {
	case reflect.Map:
		s := reflect.ValueOf(m)
		for _, v := range s.MapKeys() {
			keys = append(keys, v)
			values = append(values, s.MapIndex(v))
		}
	default:
		fmt.Fprintln(out, "orz")
	}
	return
}


Measured memory_bytes: 1776
#include<bits/stdc++.h>
using namespace std;
 
#define ll long long
#define P pair<int,int>
#define rep(i,n) for(int i = 0; i < (n); i++)
#define asort(x) sort(x.begin(),x.end())
 
int main() {
    int a,b,h,m;
    double ans,rad,hd,md,deg;
    cin>>a>>b>>h>>m;
    hd = h * 360.0/12.0 + m * 30.0/60.0;
    md = m * 360.0/60.0;
    if(md > hd) {
        deg = md - hd;
    } else {
        deg = hd - md;
    }
    rad = deg * M_PI/180.0;
    ans = sqrt(a*a + b*b - 2*a*b*cos(rad));
    printf("%.20f", ans);
    return 0;
}

Measured memory_bytes: 4180
K, N = [int(e) for e in input().split()]
A = [int(e) for e in input().split()]

between_distances = []
for i, a in enumerate(A):
    if i == 0: continue
    old_a = A[i-1]
    between_distances.append(a - old_a)
between_distances.append(K - A[-1] + A[0])

print(sum(between_distances) - max(between_distances))


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

int main(void){
    int N;
    int a[101] = {};
    int result[101] = {};
    int i;
    cin >> N;
    for(i = 0; i < N; i++){
        cin >> a[i]; 
    }
    int size = N;
    while(size > 0){
        for(i = size - 1 ; i >= 0; i--){
            if(a[i] == i + 1){
                result[size-1] = (i+1);
                for(;i<N; i++){
                    a[i] = a[i+1];
                }
                break;
            }
            if(i == 0){
                cout << -1;
                return 0;
            }
        }
        size--;
    }
    for(i = 0; i < N; i++){
        cout << result[i] << endl;
    }
}


void dumpArray(int array[] , int size){
    for(int i = 0; i < size; i++){
        cout << array[i] << " ";
    }
    cout << endl;
}


/*<?php
$n = trim(fgets(STDIN));
$array = explode(" ", trim(fgets(STDIN)));
 
for($i = 0; $i < $n; $i++){
    for($j = count($array) - 1; $j >= 0 ; $j--){
        if($array[$j] == $j + 1){
            unset($array[$j]);
            $array = array_values($array);
            $stack[] = ($j + 1);
            break;
        }
        if($j == 0){
            echo -1;
            exit;
        }
    }
}
echo implode("\n", array_reverse($stack));
*/

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, N) for (int i = 0; i < (int)N; i++)
#define all(a) (a).begin(), (a).end()

int H, W;
vector<vector<int>> s;

vector<vector<int>> moves = {{1,0}, {0,1}, {-1, 0}, {0,-1}};

bool paintable(int i, int j) {
  s[i][j] = 0;
  bool res = false;
  for(auto d: moves) {
    int ni = i + d[0], nj = j + d[1];
    if(ni >= 0 && ni < H && nj >= 0 && nj < W && s[ni][nj]) {
      res = true;
      paintable(ni, nj);
    }
  }
  return res;
}

int main () {
  cin >> H >> W;
  s.resize(H, vector<int>(W));

  rep(i,H)rep(j,W) {
    char c;
    cin >> c;
    s[i][j] = (c == '#') ;
  }


  rep(i,H)rep(j,W) {
    if(s[i][j] && !paintable(i,j)) {
      cout << "No" << endl;
      return 0;
    }
  }

  cout << "Yes" << endl;
  return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <complex>
#include <utility>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <tuple>
#include <cmath>
#include <bitset>
#include <cctype>
#include <set>
#include <map>
#include <unordered_map>
#include <numeric>
#include <functional>
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(ll i=ll(a);i<ll(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define PRINT(V) cout << V << "\n"
#define SORT(V) sort((V).begin(),(V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())
using namespace std;
using ll = long long;
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; }
inline void Yes(bool condition){ if(condition) PRINT("Yes"); else PRINT("No"); }
template<class itr> void cins(itr first,itr last){
    for (auto i = first;i != last;i++){
        cin >> (*i);
    }
}
template<class itr> void array_output(itr start,itr goal){
    string ans = "",k = " ";
    for (auto i = start;i != goal;i++) ans += to_string(*i)+k;
    if (!ans.empty()) ans.pop_back();
    PRINT(ans);
}
ll gcd(ll a, ll b) {
    return a ? gcd(b%a,a) : b;
}
const ll INF = 1e15;
const ll MOD = 1000000007;
const ll MOD2 = 998244353;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> tri;
typedef pair<double,double> point;
const ll MAX = 30000;
constexpr ll nx[8] = {1,0,-1,0,1,-1,1,-1};
constexpr ll ny[8] = {0,1,0,-1,1,1,-1,-1};
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n,m = 1000,k = 0,ans = 1000;
    cin >> n;
    vector<ll> a(n);
    cins(all(a));
    rep(i,n-1){
        if (a[i] < a[i+1]){
            k += m/a[i];
            m %= a[i];
            m += k*a[i+1];
            k = 0;
            chmax(ans,m);
        }
        else if (a[i+1] < a[i]){
            m += k*a[i];
            k = 0;
            k += m/a[i+1];
            m %= a[i+1];
            chmax(ans,m);
        }
    }
    PRINT(ans);
}


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

typedef long long ll;
ll n, m, mx, g, a[105];
bool v[105];
void f(ll p, ll q) {
	ll i, sz =0;
	bool t[105], u[105];
	for (i = 1; i <= n; i++) t[i] = v[i];
	if (p > n / 2) {
		mx = max(mx, q + g);
		return;
	}
	if (v[p]) {
		f(p + 1, q);
		return;
	}
	if (a[p] > 0) {
		f(p + 1, q + a[p]);
	} else {
		f(p + 1, q + a[p]);
//		for (i = p; i <= n; i += p) {
//			if (!v[i]) {
//				v[i] = 1;
//				u[sz++] = i;
//			}
//		}
		for (i = p; i <= n; i += p) {
			if (!v[i] && i > n / 2 && a[i] > 0) q -= a[i];
			v[i] = 1;
		}
		f(p + 1, q);
//		for (i =0; i < sz; i++) v[u[i]] = 0;
		for (i = 1; i <= n; i++) v[i] = t[i];
	}
}
int main()
{
	ll i;
	cin >> n;
	for (i = 1; i <= n; i++) {
		scanf ("%lld", &a[i]);
	}
	for (i = n / 2 + 1; i <= n; i++) if (a[i] > 0) g += a[i];
	f(1, 0);
	cout << mx;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <string.h>
#include <cstring>
#include <stdio.h>
#define lowbit(x) x&(-x)

using namespace std;
const int maxn=110;
typedef long long ll;
int a[maxn];

int main(){
    ios::sync_with_stdio(0);
    int n,d,x;
    cin>>n>>d>>x;
    ll  m=0;
    memset(a,0,sizeof(a));
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    int tmp=0;
    for(int i=0;i<n;i++){
        tmp=a[i];
        if(tmp<d) {
            tmp+=1;
            m+=2;
        }
        else {
                ++m;
                continue;
            }
        while(tmp<d){
             tmp+=a[i];
             if(tmp<=d)
               ++m;
             else break;
        }
    }
    cout<<m+x<<endl;
   return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rrep(i, n) for (int i = (n - 1); i >= 0; i--)
#define ALL(v) v.begin(), v.end()
using namespace std;
using P = pair<int, int>;
typedef long long ll;

int main() {
  string s;
  cin >> s;
  int n = s.size();
  ll num = 0;
  rep(i, n){
    num += s[i] - '0';
  }
  if(num % 9 == 0){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
}

Measured memory_bytes: 3700
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, srt, end) for (long long i = (srt); i < (long long)(end); i++)
#define VL vector<ll>
#define VS vector<string>
#define VB vector<bool>
#define VP vector<pair<ll,ll>>
#define VVL vector<vector<ll>>
#define VVP vector<vector<pair<ll,ll>>>
#define PL pair<ll,ll>
#define ALL(v) (v).begin(), (v).end()
ll d1[4] = {1, -1, 0, 0};
ll d2[4] = {0, 0, 1, -1};

int main(){
    ll N;
    cin >> N;
    vector<ll> a(N+10, 1);
    rep(i, 2, N+1){
        for(ll j = i; j <= N; j += i){
            a[j]++;
        }
    }
    ll ans = 0;
    rep(i, 1, N+1) ans += i * a[i];
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 81340
import sys
## io ##
def IS(): return sys.stdin.readline().rstrip()
def II(): return int(IS())
def MII(): return list(map(int, IS().split()))
def MIIZ(): return list(map(lambda x: x-1, MII()))
## dp ##
def DD2(d1,d2,init=0): return [[init]*d2 for _ in range(d1)]
def DD3(d1,d2,d3,init=0): return [DD2(d2,d3,init) for _ in range(d1)]
## math ##
def divc(x,y) -> int: return -(-x//y)
def divf(x,y) -> int: return x//y
def gcd(x,y):
    while y: x,y = y,x%y
    return x
def lcm(x,y): return x*y//gcd(x,y)
def enumerate_divs(n):
    """Return a tuple list of divisor of n"""
    return [(i,n//i) for i in range(1,int(n**0.5)+1) if n%i==0]
def get_primes(n=10**3):
    """Return a list of prime numbers n or less"""
    is_prime = [True]*(n+1)
    is_prime[0] = is_prime[1] = False
    for i in range(2, int(n**0.5)+1):
        if not is_prime[i]: continue
        for j in range(i*2, n+1, i): is_prime[j] = False
    return [i for i in range(n+1) if is_prime[i]]
def prime_factor(n):
    """Return a list of prime factorization numbers of n"""
    res = []
    for i in range(2,int(n**0.5)+1):
        while n%i==0: res.append(i); n //= i
    if n != 1: res.append(n)
    return res
## const ##
MOD=10**9+7
## libs ##
import itertools as it
import functools as ft
from collections import deque, Counter
from heapq import heapify, heappop, heappush
from bisect import bisect_left
#======================================================#
def main():
    n, m = MII()
    divs = enumerate_divs(m)
    ans = []
    h = m/n
    for i,j in divs:
        if i <= h:
            ans.append(i)
        if j <= h:
            ans.append(j)
    print(max(ans))


if __name__ == '__main__':
    main()

Measured memory_bytes: 3828
#include <bits/stdc++.h>
#define ll long long
#define REV(v) reverse(v.begin(), v.end());
#define REP(i, n) for (ll i = 0; i < n; i++)
#define REPR(i, n) for (ll i = n; i >= 0; i--)
#define FOR(i, start, stop) for (ll i = start; i < stop; i++)
#define FORR(i, start, stop) for (ll i = start; i > stop; i--)
#define SORT(v, n) sort(v, v + n);
#define SORTR(v, n) sort(v, v + n,greater<ll>());
#define VSORT(v) sort(v.begin(), v.end());
#define VSORTR(v) sort(v.begin(), v.end(),greater<ll>());
#define REMOVE(v,n) remove(vector<ll> v,v+v.size(),ll n)
#define ERASE(v,n) v.erase(v.begin()+n);
#define ull unsigned long long
#define pb(a) push_back(a)
#define INF 999999999
#define V(v,i,j) vector(v.begin() + i, v.begin() + j)
#define INSERT(va,vb) va.insert(va.end(), vb.begin(), vb.end())
using namespace std;
typedef vector<ll> vll;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;
int dy[] = {0, 0, 1, -1};
int dx[] = {1, -1, 0, 0};
const int MOD = 1000000007;
void chmin(int &a, int b) { if (a > b) a = b; }

//vector< vector<int> > v (size1, vector<int>(size2) );

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

    ll n;
    cin>>n;
    vector<ll> b(n);
    ll a;
    FOR(i,0,n){
        if(i==0)cin>>b[i];
        else{
            cin>>a;
            b[i]=a+b[i-1];
        }
    }

    //-+-+...
    ll ans_mi=0;
    ll d_mi=0;
    FOR(i,0,n){
        if(i%2==0){
            if(b[i]+d_mi>=0){
                ans_mi+=b[i]+d_mi+1;
                d_mi-=b[i]+d_mi+1;
            }
        }else{
            if(b[i]+d_mi<=0){
                ans_mi+=1-b[i]-d_mi;
                d_mi+=1-b[i]-d_mi;
            }
        }
    }
    

    //+-+-...
    ll ans_pl=0;
    ll d_pl=0;
    FOR(i,0,n){
        if(i%2==0){
            if(b[i]+d_pl<=0){
                ans_pl+=1-b[i]-d_pl;
                d_pl+=1-b[i]-d_pl;
            }
        }else{
            if(b[i]+d_pl>=0){
                ans_pl+=b[i]+d_pl+1;
                d_pl-=b[i]+d_pl+1;
            }
        }
    }

    cout<<min(ans_mi,ans_pl)<<endl;
    //cout<<ans_mi<<ans_pl<<endl;

    return 0;
    
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define de_x(x) cout<<"debug_val: "<<x<<endl;
#define de_ve(x) for(auto it: x) cout<<it<<" ";
#define rep(i,a,n) for (int i=a;i<n;i++)
#define _rep(i,a,n) for (int i=a;i<=n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
typedef long long ll;
typedef vector<int> VI;
typedef pair<int,int> PII;
typedef double db;
std::mt19937 mrand(random_device{}());
int rnd(int x) { return mrand() % x ; }
const ll mod=1e7;
ll ksm(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
int _,n,m;
/***********************/
void run(){
}
int main(){
//    for(scanf("%d",&_);_;_--) run();
    vector<int> g(9);
    for(auto &it : g ) cin>> it;
    cin>>n;
    rep(i,0,n){
        cin>>m;
        for(auto &it:g) if(it == m ) it =0;
    }
    if(!(g[0]+g[3]+g[6]) || !(g[1]+g[4]+g[7]) || !(g[2]+g[5]+g[8] )
     ||!(g[0]+g[1]+g[2]) || !(g[3]+g[4]+g[5]) || !(g[6]+g[7]+g[8] )
     ||!(g[0]+g[4]+g[8]) || !(g[2]+g[4]+g[6])) m =1;
    cout<<((m==1)?"Yes":"No")<<endl;
    return 0;
}

Measured memory_bytes: 256
use proconio::input;

fn main() {
    input!(n: usize, m: usize, k: u64, a: [u64; n], b: [u64; m]);

    let ans = (0..=n)
        .scan((m, b.iter().sum::<u64>()), |(j, time), i| {
            while *time > k && *j > 0 {
                *j -= 1;
                *time -= b[*j];
            }
            let ret = if *time > k { None } else { Some(i + *j) };
            if i < n {
                *time += a[i];
            }
            ret
        })
        .max()
        .unwrap_or(0);

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


Measured memory_bytes: 9324
#include<cstdio>
#include<algorithm>
using namespace std;

int main() {
	#ifdef LOACL
	freopen("in.txt","r",stdin);
	freopen("out.txt","w",stdout);
	#endif
	int N,T;
	int ans=1e9;
	scanf("%d %d",&N,&T);
	for(int i=1;i<=N;i++) {
		int cos,t;
		scanf("%d %d",&cos,&t);
		if(t<=T)ans=min(ans,cos);
	}
	if(ans==1e9)puts("TLE");
	else printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 128
def mws5(lookup, hs):
    ans = 0
    for i in range(len(hs)):
        h = hs[i]
        ans += lookup[i+h]
    print(ans)

if __name__ == "__main__":
    import sys
    from collections import defaultdict as DD
    lookup = DD(int)  
    n = int(input())
    hs = [int(_) for _ in input().split()]
    for i, h in enumerate(hs):
        lookup[i-h] += 1
    mws5(lookup, hs)


Measured memory_bytes: 61672
use proconio::input;
#[allow(unused_mut)]
fn main() {
    input! {
        n: usize,
        p: [usize; n]
    }
    let mut res = 0;
    let mut mini = p[0];
    for i in 0..n {
        if p[i] <= mini {
            res += 1;
            mini = p[i];
        }
    }
    println!("{}", res);
}


Measured memory_bytes: 4724
#include <iostream>
#include <fstream>
#include <vector>
#include <set>
#include <map>
#include <bitset>
#include <algorithm>
#include <iomanip>
#include <cmath>
#include <ctime>
#include <functional>
#include <unordered_set>
#include <unordered_map>
#include <string>
#include <queue>
#include <deque>
#include <stack>
#include <complex>
#include <cassert>
#include <random>
#include <cstring>
#include <numeric>
#define ll long long
#define ld long double
#define null NULL
#define all(a) a.begin(), a.end()
#define forn(i, n) for (int i = 0; i < n; ++i)
#define sz(a) (int)a.size()
#define lson l , m , rt << 1
#define rson m + 1 , r , rt << 1 | 1
template<class T> int gmax(T &a, T b) { if (b > a) { a = b; return 1; } return 0; }
template<class T> int gmin(T &a, T b) { if (b < a) { a = b; return 1; } return 0; }

using namespace std;

const int N = 1e5 + 5;
char seq[N];
int main() {
    int N, K;
    while(~scanf("%d %d", &N, &K)) {
        scanf("%s",seq);
        vector<pair<int, int> > feet;
        pair<int, int> unit = make_pair(-1, -1);
        for(int i = 0, len = strlen(seq); i < len; ++i) {
            if(seq[i] == '0') {
                if(unit.first == -1) unit.first = i;
                unit.second = i;
            } else {
                if(unit.first != -1) feet.push_back(unit);
                unit = make_pair(-1, -1);
            }
        }
        if(unit.first != -1) feet.push_back(unit);

        int result = -1;
        for(int i = 0, len = max(1, (int)feet.size() - K + 1) ; i < len; ++i) {
            int start = i;
            int end = min((int)feet.size() - 1, i + K - 1);
            int from = (start == 0) ? -1 : feet[start - 1].second;
            int to = (end == feet.size() - 1) ? (N - 1) : (feet[end + 1].first - 1);
            result = max(result, to - from);
        }
        printf("%d\n", result);
    }
    return 0;
}

Measured memory_bytes: 1020
typedef long long ll;
#include <bits/stdc++.h>
using namespace std;
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

int main() {
    ll n,m;
    std::cin >> n>>m;
    ll m_count[30];
    Fill(m_count,0);
    
    for (int i = 0; i < n; i++) {
        ll tmp_k;
        std::cin >> tmp_k;
        for (int j = 0; j < tmp_k; j++) {
            ll tmp_m;
            std::cin >> tmp_m;
            m_count[tmp_m-1]++;
        }
    }
    ll result = 0;
    for (int i = 0; i < m; i++) {
        if(m_count[i] == n){
            result++;
        }
    }
    std::cout << result << std::endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>

using namespace std;

const int MAXN = 510;
int uN,vN;
int g[MAXN][MAXN];
int linker[MAXN];
bool used[MAXN];

bool dfs(int u)
{
    for(int v = 0; v < vN;v++)
    if(g[u][v] && !used[v])
    {
        used[v] = true;
        if(linker[v] == -1 || dfs(linker[v]))
        {
            linker[v] = u;
            return true;
        }
    }
    return false;
}

int hungary()
{
    int res = 0;
    memset(linker,-1,sizeof(linker));
    for(int u = 0;u < uN;u++)
    {
        memset(used,false,sizeof(used));
        if(dfs(u))res++;
    }
    return res;
}

int main()
{
    int n;
    int a[110],b[110],c[110],d[110];
    while(scanf("%d",&n)!=EOF){
        uN=vN=n;
        for(int i=0;i<n;i++){
            scanf("%d%d",&a[i],&b[i]);
        }
        for(int i=0;i<n;i++){
            scanf("%d%d",&c[i],&d[i]);
        }
        memset(g,0,sizeof(g));
        for(int i=0;i<n;i++){
            for(int j=0;j<n;j++){
                if(a[i]<c[j]&&b[i]<d[j]){
                    g[i][j]=1;
                }
            }
        }
        printf("%d\n",hungary());
    }
    return 0;
}


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

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

  vector<int> a(N);
  rep(i, N) cin >> a[i];

  int num_4n = 0, num_2n = 0, num_odd = 0;
  rep(i, N) {
    if (a[i] % 4 == 0)
      num_4n++;
    else if (a[i] % 2 == 0)
      num_2n++;
    else
      num_odd++;
  }

  bool ans = true;

  if (num_4n + 1 < (num_2n % 2) + num_odd)
    ans = false;

  if (ans)
    puts("Yes");
  else
    puts("No");
}

Measured memory_bytes: 640