akhauriyash/Code-Regression huggingface dataset:
n = list(map(int,input().split()))
x=0
if n[0]*2 < n[1]:
  n[1] -= n[0]*2
  x = n[0] + (n[1]//4)
elif n[0]*2==n[1]:
  x = n[0]
else:
  x = n[1]//2
print(x)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define ll long long
#define PB push_back
#define MP make_pair

#define REP(i, n) for(int i=0;i<(int)(n);++i)
#define FOR(i,l,h) for(int i=(int)(l);i<=(int)(h);++i)
#define FORD(i,h,l) for(int i=(int)(h);i>=(int)(l);--i)

#define max(a,b) a>b?a:b
#define min(a,b) a>b?b:a

ll gcd(ll a, ll b) { return !b ? a : gcd(b, a % b); }
ll lcm(ll a, ll b) { return (a / gcd(a, b)) * b; }

#define dump(x)  cerr << #x << " = " << (x) << endl
#define ALL(t) (t).begin(),(t).end()

using namespace std;


int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll int n;cin>>n;
    std::map<pair<int ,int> , int> mp;
    for (size_t i = 1; i <= n; i++) {
        int x = i;
        int a = i % 10;
        while(x >= 10){
            x = x / 10;
        }
        int b = x;
        mp[{a,b}]++;
    }
    ll int sum =0;
    for (size_t i = 1; i <= n; i++) {
        int x = i;
        int b = i % 10;
        while(x >= 10){
            x = x / 10;
        }
        int a = x;
        sum += mp[{a,b}];
    }

  cout<<sum;
  return 0;
}


Measured memory_bytes: 256
def main():
    N = int(input())
    A = list(map(int,input().split()))
    list.sort(A)
    pre_A = -1
    dp = [True for i in range(A[-1]+1)]
    for i in range(N):
        if pre_A != A[i]:
            for j in range(2,A[-1]+1):
                x = j*A[i]
                if x <= A[-1]:
                    dp[x] = False
                else:
                    break
            pre_A = A[i]
        else:
            dp[A[i]] = False
            
    count = 0
    for i in range(N):
        if dp[A[i]]:
            count += 1
    print(count)
        
if __name__ == '__main__':
    main()

Measured memory_bytes: 32408
#include <iostream>
#include <vector>
using namespace std;
int ab(int x)
{
	if(x<0)
		return -1*x;
	return x;
}
int main()
{
	int n;
	cin>>n;
	vector<int> h;
	h.resize(n+1);
	int i;
	h[0] = -1000000;
	for(i=1;i<=n;i++)
		cin>>h[i];
	vector<int> mincost;
	mincost.resize(n+1);
	mincost[0] = 0;
	mincost[1] = 0;
	for(i=2;i<=n;i++)
	{
		mincost[i] = min(mincost[i-1]+ab(h[i]-h[i-1]),mincost[i-2]+ab(h[i]-h[i-2]));
	}
	cout<<mincost[n]<<endl;
	return 0;
}

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

int main()
{
	int a, b, c;
	
	scanf("%d %d %d", &a, &b, &c);
	
	if (a < b && b < c){
		printf("Yes\n");
	}
	else {
		printf("No\n");
	}
	
	return (0);
}

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

int main (){
    int N;
    long long tmp;
    string ans = "YES";
    vector<long long> A;
 
    cin >> N;
    for(int i=0;i<N;++i) {
        cin >> tmp;
        A.push_back(tmp);
    } 

    sort(A.begin(),A.end());

    long long prev = long(1e10)+1;
    for(int i=0;i<N;++i){
        if (prev == A[i]){
            ans = "NO";
            break;
        }else
        {
            prev = A[i];
        }
    }

    cout << ans << endl;

}

Measured memory_bytes: 2420
/*
██████╗  ███████╗  
██╔══██╗ ██╔════╝ 
██████╔╝ ███████╗ 
██╔══██╗ ╚════██║  
██║  ██║ ███████║      
╚═╝  ╚═╝ ╚══════╝                                                                                                             
*/

#include<bits/stdc++.h>
using namespace std;
 
#define ll long long int
#define rep(i,n) for(int i=0;i<n;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define haha(j,a,n) for(int j=a;j<n;j++)
#define Max(x,y,z) max(x,max(y,z))
#define Min(x,y,z) min(x,min(y,z))
#define endl "\n"
#define bc(v) v.begin(),v.end()
#define vl vector<ll>
#define vi vector<int>
#define why 1000000007
#define NUM 100005
#define F first
#define S second
#define bhar(a) rep(i,a.size()) cin>>a[i];
#define show(a) rep(i,a.size()) cout<<a[i]<<" ";
#define sott(a) sort(bc(a))
#define mp(a,b) make_pair(a,b)
#define pb push_back
#define mapp map<ll,ll>
#define dkac cout<<fixed<<setprecision(15);
#define ios ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define yeah(n) while(n--)
ll gcd(int a, int b){if(b==0) return a; else return gcd(b,a%b);}
ll bitfun(ll x){
    return (x&(-x));
}
void solve(){
    ll n,w; cin>>n>>w;
    ll wt[n],val[n];
    for(ll i=0;i<n;i++) cin>>wt[i]>>val[i];
    ll dp[n+1][w+1];
    for(ll i=0;i<=n;i++)
        for(ll j=0;j<=w;j++){
            if(i==0 || j==0) dp[i][j]=0;
            else if(j>=wt[i-1]) dp[i][j] = max(dp[i-1][j],val[i-1] + dp[i-1][j-wt[i-1]]);
            else dp[i][j] = dp[i-1][j];
        }
    cout<< dp[n][w];
}
int main(){
    ios
    int t=1; 
    //cin>>t;
    yeah(t){
        solve();
    }
}

Measured memory_bytes: 79232
import sys
input = sys.stdin.readline
N, Q = map(int, input().split())

class SegTree:
  def segfunc(self, x, y):
    return min(x, y)
  def __init__(self, n, ide_ele, init_val):
    #####単位元######
    self.ide_ele = ide_ele
    #num:n以上の最小の2のべき乗
    self.num = 2 ** (n - 1).bit_length()
    self.seg = [self.ide_ele] * 2 * self.num
    #set_val
    for i in range(n):
      self.seg[i + self.num - 1] = init_val[i]    
    #built
    for i in range(self.num - 2, -1, -1) :
      self.seg[i] = self.segfunc(self.seg[2 * i + 1], self.seg[2 * i + 2]) 
  def update(self, k, x):
    k += self.num - 1
    self.seg[k] = x
    while k + 1:
      k = (k - 1) // 2
      self.seg[k] = self.segfunc(self.seg[k * 2 + 1], self.seg[k * 2 + 2]) 
  def query(self, p, q):
    if q <= p:
      return self.ide_ele
    p += self.num - 1
    q += self.num - 2
    res = self.ide_ele
    while q - p > 1:
      if p & 1 == 0:
        res = self.segfunc(res, self.seg[p])
      if q & 1 == 1:
        res = self.segfunc(res, self.seg[q])
        q -= 1
      p = p // 2
      q = (q - 1) // 2
    if p == q:
      res = self.segfunc(res, self.seg[p])
    else:
      res = self.segfunc(self.segfunc(res, self.seg[p]), self.seg[q])
    return res

lseg = SegTree(N, N, [N] * N)
useg = SegTree(N, N, [N] * N)
res = (N - 2) * (N - 2)
for _ in range(Q):
  q, x = map(int, input().split())
  x -= 1
  if q == 1:
    u = useg.query(x, N)
    res -= u - 2
    l = lseg.query(u - 1, u)
    lseg.update(u - 1, min(l, x + 1))
    #print(res, u, "u", x)
  else:
    l = lseg.query(x, N)
    res -= l - 2
    u = useg.query(l - 1, l)
    useg.update(l - 1, min(u, x + 1))
    #print(res, l, "l", x)
print(res)

Measured memory_bytes: 97252
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <iostream>
#include <algorithm>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#define LL long long
#define Max +5

using namespace std;

LL Map[Max][Max],N,M,I,J,A,B,C,K,Ans=1;

int main()
{
	scanf("%lld%lld",&N,&K);
	for(I=1;I<=N;I++)
	{
		if(Ans*2>Ans+K) Ans+=K;
		else Ans*=2;
	}
	printf("%lld",Ans);
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <queue>
#include <vector>
#include <list>
#include <cmath>


using namespace std;

long long int a[300005];
priority_queue<long long int, vector<long long int>, greater<long long int>> pf;
priority_queue<long long int> ps;
long long int sum_f, sum_s;
long long int dif_f[100005];
long long int dif_s[100005];
int main()
{
	int N;
	long long int max;
	sum_f = sum_s = 0;
	max = -(long long int)pow(10, 17);


	cin >> N;

	for (int i = 0; i < N * 3; i++)
	{
		cin >> a[i];
		if (i < N)
		{
			pf.push(a[i]);
			sum_f += a[i];
		}
		else if (2 * N <= i)
		{
			ps.push(a[i]);
			sum_s += a[i];
		}
	}

	dif_f[0] = sum_f;
	dif_s[N] = sum_s;

	for (int i = N; i < 2 * N; i++)
	{
		if (a[i] > pf.top())
		{
			pf.push(a[i]);
			sum_f += a[i];
			sum_f -= pf.top();
			pf.pop();
		}
		dif_f[i - N + 1] = sum_f;
	}

	for (int i = 2 * N - 1; i > N - 1; i--)
	{
		if (a[i] < ps.top())
		{
			ps.push(a[i]);
			sum_s += a[i];
			sum_s -= ps.top();
			ps.pop();
		}
		dif_s[i - N] = sum_s;
	}

	for (int i = 0; i <= N; i++)
	{
		if (max < dif_f[i] - dif_s[i])
			max = dif_f[i] - dif_s[i];
	}

	cout << max << endl;

	return 0;
}

Measured memory_bytes: 5876
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <math.h>
#include <assert.h>
#include <vector>
#include <map>

using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
static const double EPS = 1e-9;
static const double PI = acos(-1.0);

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, s, n) for (int i = (s); i < (int)(n); i++)
#define FOREQ(i, s, n) for (int i = (s); i <= (int)(n); i++)
#define FORIT(it, c) for (__typeof((c).begin())it = (c).begin(); it != (c).end(); it++)
#define MEMSET(v, h) memset((v), h, sizeof(v))


struct FenwickTree {
  static const int SIZE = 500000;
  int tree[SIZE + 10];
  FenwickTree() { memset(tree, 0, sizeof(tree)); }
  void add(int index, int value) {
    for (index += 3; index < SIZE + 1; index += (index & -index)) {
      tree[index] += value;
    }
  }
  int sum(int index) {
    int ret = 0;
    for (index += 3; index > 0; index -= (index & -index)) {
      ret += tree[index];
    }
    return ret;
  }
};

int q, lim;
int seq[500000];
map<int, int> mapto;
FenwickTree ftree;

int FindIndex(int index) {
  int left = 0;
  int right = 410000;
  while (left != right) {
    int mid = (left + right) / 2;
    if (ftree.sum(mid) >= index) {
      right = mid;
    } else {
      left = mid + 1;
    }
  }
  return left;
}

int main() {
  while (scanf("%d %d", &q, &lim), q|lim) {
    ftree = FenwickTree();
    mapto.clear();
    int head = 0;
    REP(i, q) {
      int type, x;
      scanf("%d %d", &type, &x);
      if (type == 0) {
        mapto[x] = head;
        ftree.add(head, 1);
        if (ftree.sum(head) > lim) {
          int index = FindIndex(1);
          //cout << "Delete:" << index << endl;
          assert(ftree.sum(index) - ftree.sum(index - 1) == 1);
          ftree.add(index, -1);
        }
        seq[head++] = x;
      } else if (type == 1) {
        int index = FindIndex(x);
        ftree.add(index, -1);
      } else if (type == 2) {
        int index = FindIndex(x);
        printf("%d\n", seq[index]);
      } else if (type == 3) {
        int index = mapto[x];
        ftree.add(index, -1);
      }
    }
    puts("end");
  }
}

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

namespace Atcoder
{
    class Atcoderrrrrrr
    {
        static void Main(string[] args)
        {
          string[] s = Console.ReadLine().Split(' ');
          string ans = "NO";
          if(s[1].StartsWith(s[0].Substring(s[0].Length-1,1))){
              if(s[2].StartsWith(s[1].Substring(s[1].Length-1,1))){
                ans = "YES";
              }
          }
          Console.WriteLine(ans);
        }
    }
}


Measured memory_bytes: 13280
#include <stdio.h>

void opera(void);

int main(void)
{
	int n;
	int i;
	
	
	scanf("%d", &n);
	
	for (i = 0; i < n; i++){
		
		opera();
	}
	
	return (0);
}
void opera(void)
{
	char train[64];
	char str[1024];
	int  i , j = 0;
	int  place = 31;
	
	
	scanf("%s", str);
		
	for (i = 0; i < 64; i++){
		train[i] = ' ';
	}
	
	while (str[j] != '\0'){
		if (str[j] == '-' && str[j + 1] == '>'){
			place++;
			j++;
		}
		else if (str[j] == '<' && str[j + 1] == '-'){
			place--;
			j++;
		}
		else if (str[j] >= 'a' && str[j] <= 'z'){
			train[place] = str[j];
		}
		j++;
	
	}
	for (j = 0; j < 64; j++){
		if (train[j] != ' '){
			printf("%c", train[j]);
		}
	}
	puts("");
}

Measured memory_bytes: 588
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int N;
    double b, ave, sum = 0, min = 1000000;
    cin >> N;
    int k = N;
    vector<int> a(N);
    for (int i = 0; i < N; i++)
    {
        cin >> a[i];
    }
    for (int i = 0; i < N; i++)
    {
        sum += a[i];
    }
    ave = sum / N;
    for (int i = N - 1; i >= 0; i--)
    {
        b = ave - a[i];
        if (b < 0)
        {
            b *= (-1);
        }
        if (b <= min && i < k)
        {

            min = b;
            k = i;
        }
    }
    cout << k << endl;
}

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


int main(){
    int a,b;
    cin >> a>> b;
    if(a%3==0||b%3==0||(a+b)%3==0)cout << "Possible" << endl;
    else cout << "Impossible" << endl;
    
    return 0;
    
}

Measured memory_bytes: 256
from collections import deque
H, W = map(int, input().split())
S = [input() for _ in range(H)]
def bfs(s, t):
    dist = [[None] * W for _ in range(H)]
    que = deque([(s, t)])
    dist[s][t] = 0
    while que:
        u, v = que.popleft()
        d = dist[u][v]
        G = []
        if u > 0 and S[u-1][v] == ".":
            G.append((u-1, v))
        if u < H - 1 and S[u+1][v] == ".":
            G.append((u+1, v))
        if v > 0 and S[u][v-1] == ".":
            G.append((u, v-1))
        if v < W - 1 and S[u][v+1] == ".":
            G.append((u, v+1))
        for w, x in G:
            if dist[w][x] is None:
                dist[w][x] = d + 1
                que.append((w, x))
    return max(d if d is not None else 0 for di in dist for d in di)

print(max(bfs(i, j) for i in range(H) for j in range(W) if S[i][j] == "."))

Measured memory_bytes: 3316
def resolve():
    W, H, M = map(int, input().split())
    x = []
    y = []
    a = []
    a1 = [0]
    a2 = [W]
    a3 = [0]
    a4 = [H]
    for i in range(M):
        X, Y, A = map(int, input().split())
        x.append(X)
        y.append(Y)
        a.append(A)
    for j in range(M):
        if a[j] == 1:
            a1.append(x[j])
        elif a[j] == 2:
            a2.append(x[j])
        elif a[j] == 3:
            a3.append(y[j])
        else:
            a4.append(y[j])
    print((max(min(a4)-max(a3), 0))*(max(min(a2)-max(a1), 0)))
resolve()

Measured memory_bytes: 9140
#include <iostream>

using namespace std;

int main(){
  int n;
  cin >> n;
  int a[n],b[n],ret=0;
  int i;
  for(i=0;i<n;i++){
    cin >> a[i];
  }
  for(i=0;i<n;i++){
    cin >> b[i];
  }
  for(i=0;i<n;i++){
    if(a[i]-b[i]>0)ret+=a[i]-b[i];
  }
  cout << ret << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define mat vector<vector<int> >
const int inf = 0x7f7f7f7f;

int vis[(int)2e7], dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

int index(mat m) {
    int res = 0;
    for (int i = 0; i < 2; i++) {
        for (int j = 0; j < 4; j++) res += (1 << (3 * (i * 4 + j))) * m[i][j];
    }
    return res;
}

int main() {
    mat a(2);
    vector<int> x(4);
    a[0] = a[1] = x;
    memset(vis, 127, sizeof(vis));

    for (int i = 0; i < 2; i++) {
        for (int j = 0; j < 4; j++) a[i][j] = i * 4 + j;
    }

    vis[index(a)] = 0;

    queue<mat> que;
    que.push(a);

    while (!que.empty()) {
        mat top = que.front();
        que.pop();
        for (int i = 0; i < 2; i++) {
            for (int j = 0; j < 4; j++) {
                if (top[i][j] == 0) {
                    for (int k = 0; k < 4; k++) {
                        int nx = i + dx[k], ny = j + dy[k];
                        if (nx >= 0 && nx < 2 && ny >= 0 && ny < 4) {
                            mat tmp = top;
                            swap(tmp[nx][ny], tmp[i][j]);
                            if (vis[index(tmp)] == inf) {
                                que.push(tmp);
                                vis[index(tmp)] = vis[index(top)] + 1;
                            }
                        }
                    }
                    break;
                }
            }
        }
    }

    while (scanf("%d", &a[0][0]) != EOF) {
        for (int i = 1; i < 4; i++) scanf("%d", &a[0][i]);
        for (int i = 0; i < 4; i++) scanf("%d", &a[1][i]);
        int res = vis[index(a)];
        printf("%d\n", res == inf ? -1 : res);
    }
}


Measured memory_bytes: 81608
s =input()
t = input()
len_s = len(s)
len_t = len(t)
ans = 10**10
for i in range(len_s-len_t+1):
    cnt = 0
    for j in range(len_t):
        if s[i+j]!=t[j]:
            cnt+=1
    ans = min(cnt,ans)
print(ans)
    

Measured memory_bytes: 67536
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<math.h>
using namespace std;
typedef long long ll;
typedef vector<int> VI;
#define REP(i,n) for(int i=0;i<n;i++)
#define eREP(i,n) for(int i=0;i<=n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define eFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define rSORT(c) sort((c).rbegin(),(c).rend())
#define LB(x,a) lower_bound((x).begin(),(x).end(),(a))
#define UB(x,a) upper_bound((x).begin(),(x).end(),(a))
#define INF 1000000000
#define LLINF 9223372036854775807
#define mod 1000000007
//vector<vector<int> > dp;
//vector<vector<vector<int> > > vvvi;
//dp=vector<vector<int> >(N, vector<int>(M,0));
//vector<pair<int,int> > v;
//v.push_back(make_pair(x,y));

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

	string S;
	cin>>S;
	int A[26]={0};
	string B="abcdefghijklmnopqrstuvwxyz";
	string C="zyxwvutsrqponmlkjihgfedcba";
	if(S==C){
		cout<<-1<<endl;
		return 0;
	}
	int ans=0;
	if(S.size()==26){
		for(int i=25;i>=0;i--){
			//oo=min(oo,S[i]-'a');
			if(S[i]>S[i-1]){
				ans=i;
				break;
			}
			
			
		}
		//cout<<ans<<endl;
		REP(i,ans)A[S[i]-'a']++;
		char oo;
		REP(i,26){
			if(A[i]==0 && B[i]>S[ans-1]){
				oo=B[i];
				break;
			}
		}
		//cout<<S[ans-1]<<endl;
		REP(i,ans-1)cout<<S[i];
		cout<<oo<<endl;
		return 0;
	}
	
	REP(i,S.size())
		A[S[i]-'a']++;
	//REP(i,26)cout<<S[i]-'a'<<endl;
	FOR(i,0,26){
		if(A[i]==0){
			cout<<S<<B[i]<<endl;
			return 0;
		}
	}
		
	return 0;
}

Measured memory_bytes: 256
using System;
using System.Linq;
using System.Collections.Generic;

namespace Aojx
{
    class MainClass
    {
        public static void Main(string[] args)
        {
            string s;
            while ((s = Console.ReadLine()) != "0")
            {
                int n = int.Parse(s);
                int c = 0;

                while (n != 1)
                {
                    c++;
                    if (n % 2 == 0)
                    {
                        n /= 2;
                    }
                    else
                    {
                        n = n * 3 + 1;
                    }
                }

                Console.WriteLine(c);
            }
        }
    }
}

Measured memory_bytes: 5600
#include<bits/stdc++.h>
#include<cmath>
#define pb push_back
#define ld long double
#define mp make_pair
#define vl vector<ll> 
#define ll long long int
#define pl pair<ll, ll>
#define min3(a, b, c) min(a, min(b, c))
#define max3(a, b, c) max(a, max(b, c))
#define forr(i, n) for(ll i=0; i<n; i++) 
#define forr1(i, n) for(ll i=1; i<=n; i++)
using namespace std;
const ld PI =2*acos(0.0);
const ll MOD = 1e9+7;
const ll NUM = 1e3+10;
void solve()
{
    ll a,b, hour, minutes;
    cin>>a>>b>>hour>>minutes;
    ll tim=(hour*60)+minutes;
    ld sho=tim*(360.00)/(60*12.00);
    ld smin=(360.0/60.0)*minutes;
    ld anglediff=min(abs(smin-sho), 360-(abs(smin-sho)));
    anglediff=(PI*anglediff)/180.0;
    ld ans=(a*a)+(b*b)-(2*a*b*cos(anglediff));
    ans=sqrt(ans);
    std::cout<<std::setprecision(20)<<ans;
}
int main()
{
    ll test=1;
    //cin>>test;
    while(test--)
        solve();
}

Measured memory_bytes: 4144
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time, copy,bisect
from operator import itemgetter

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

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces

import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time, copy
from operator import itemgetter

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

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces

N, M = na()
MAX = M // N
ans = 1

def make_divisors(n):
    lower_divisors , upper_divisors = [], []
    i = 1
    while i*i <= n:
        if n % i == 0:
            lower_divisors.append(i)
            if i != n // i:
                upper_divisors.append(n//i)
        i += 1
    return lower_divisors + upper_divisors[::-1]

if M % N == 0:
    print(M // N)
else:
    tmp = make_divisors(M)
    print(tmp[max(bisect.bisect_left(tmp, MAX) - 1, 0)])

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
#define REP(i, n) for(int i=0; i<n; i++)
#define REPi(i, a, b) for(int i=int(a); i<int(b); i++)
#define MEMS(a,b) memset(a,b,sizeof(a))
#define mp make_pair
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const ll MOD = 1e9+7;

int main(){
    ll N;
    cin >> N;
    map<ll, ll> A;
    REP(i,N){
        ll a;
       cin >> a; 
       A[a]++;
    }

    ll ans = 0;
    for(auto&& p : A){
        ll val = p.first;
        ll n = p.second;
        ans += val * n;
    }

    ll Q;
    cin >> Q;
    REP(q,Q){
        ll b, c;
        cin >> b >> c;

        ll n = A[b];

        A[c] += n;
        A[b] = 0;

        ans += c * n;
        ans -= b * n;

        cout << ans << endl;
    }


    return 0;
}


Measured memory_bytes: 9496
#include <iostream>
#include <cstdlib>
#include <algorithm>

using namespace std;

#define uint unsigned int

long long A[200000];
int main(){
    uint N;
    cin >> N;
    long long a;
    long long b;
    for(int i=0; i<N; i++){
        cin >> a;
        A[i] = a - (i+1);
        //cout << A[i] << " ";
    }
    sort(A, A+N);
    b = A[N/2];

    long long sum = 0;
    for(long long i = 0; i < N; i++){
        sum += abs(A[i] - b);
    }

    cout << sum<< endl;
    return 0;
}


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

using namespace std;

using int64 = long long;

/*
int dp[100];

int grundy(int sz)
{
  if(dp[sz]) return (dp[sz]);
  set< int > st;
  for(int i = 0; i <= sz; i++) { // i = 3 のとき 0, 1, 2
    int nim = 0;
    for(int j = sz - i; j < sz; j++) {
      nim ^= grundy(j);
    }
    st.emplace(nim);
  }

  int ret = 0;
  while(st.count(ret)) ++ret;
  return (dp[sz] = ret);
}
*/

struct TrieNode
{
  int nxt[2];

  int exist; // 子ども以下に存在する文字列の数の合計
  vector< int > accept; // その文字列id

  TrieNode() : exist(0)
  {
    memset(nxt, -1, sizeof(nxt));
  }
};

int64 N, L;
map< int64, bool > mp;

struct Trie
{
  vector< TrieNode > nodes;
  int root;

  Trie() : root(0)
  {
    nodes.push_back(TrieNode());
  }

  virtual void direct_action(int node, int id) {}

  virtual void child_action(int node, int child, int id) {}

  void update_direct(int node, int id)
  {
    nodes[node].accept.push_back(id);
    direct_action(node, id);
  }

  void update_child(int node, int child, int id)
  {
    ++nodes[node].exist;
    child_action(node, child, id);
  }

  void add(const string &str, int str_index, int node_index, int id)
  {
    if(str_index == str.size()) {
      update_direct(node_index, id);
    } else {
      const int c = str[str_index] - '0';
      if(nodes[node_index].nxt[c] == -1) {
        nodes[node_index].nxt[c] = (int) nodes.size();
        nodes.push_back(TrieNode());
      }
      add(str, str_index + 1, nodes[node_index].nxt[c], id);
      update_child(node_index, nodes[node_index].nxt[c], id);
    }
  }

  void add(const string &str, int id)
  {
    add(str, 0, 0, id);
  }

  void add(const string &str)
  {
    add(str, nodes[0].exist);
  }

  int size()
  {
    return (nodes[0].exist);
  }

  int nodesize()
  {
    return ((int) nodes.size());
  }

  void dfs(int idx = 0, int dep = 0)
  {
    if(nodes[idx].accept.size()) return;
    for(int i = 0; i < 2; i++) {
      if(nodes[idx].nxt[i] == -1) {
        int64 real = (L - dep);
        for(int j = 0; j < 62; j++) {
          if((real >> j) & 1) {
            mp[j] ^= 1;
            break;
          }
        }

      } else {
        dfs(nodes[idx].nxt[i], dep + 1);
      }
    }
  }
};


int main()
{
  /*
  for(int i = 0; i < 100; i++) {
    cout << grundy(i) << " ";

    int x = i + 1;
    for(int j = 0; j < 30; j++) {
      if((x >> j) & 1) {
        cout << (1 << j) << " ";
        break;
      }
    }
    cout << endl;

  }
   */


  cin >> N >> L;
  Trie trie;
  for(int i = 0; i < N; i++) {
    string S;
    cin >> S;
    trie.add(S);
  }
  trie.dfs();

  for(auto &p : mp) {
    if(p.second) {
      cout << "Alice" << endl;
      return (0);
    }
  }

  cout << "Bob" << endl;
}


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

#define rep(i,n) for(int i=0;i<n;i++)
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define each(it,v) for(auto &it : v)
#define all(v) (v).begin(),(v).end()
#define mod 1e9+7

using namespace std;
using vi = vector<int>;
using vl = vector<long>;
using P = pair<int,int>;

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

        vi v(n);
        each(it,v)cin>>it;

        int cnt=0;
        FOR(i,1,n-1)
        {
                if(v[i-1]==v[i])
                {
                        cnt++;
                        v[i]=100100;
                }
        }
        cout<<cnt<<endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

#define NEW(p,n){p=malloc((n)*sizeof(p[0]));if(p==NULL){printf("not enough memory\n");exit(1);};}
//pの型の変数n個の要素分のメモリを確保し、そのアドレスをpに代入するマクロ

#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define SWAP(type, x, y) do { type tmp = x; x = y; y = tmp; } while (0)

#define MOD 1000000007 

int main(void){
    char S[51];
    char T[51];
    scanf("%s",S);
    scanf("%s",T);

    int s=strlen(S);
    int t=strlen(T);

    int flg1=-1;

    for(int i=s-t;i>=0;i--){
        int flg2=0;
        for(int j=0;j<t;j++){
            if(S[i+j]==T[j] || S[i+j]=='?') flg2=1;
            else{
                flg2=0;
                break;
            }
        }
        if(flg2){
            flg1=i;
            break;
        }
    }

    if(flg1==-1) printf("UNRESTORABLE\n");
    else{
        for(int j=0;j<t;j++) S[flg1+j]=T[j];
        for(int i=0;i<s;i++){
            if(S[i]=='?') S[i]='a';
        }
        printf("%s\n",S);
    }

    return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<cstdio>
#include<string>

using namespace std;

int main()
{
	int number;
	char kanma;
	string blood;
	int blo[4]={0};
	while(cin>>number>>kanma>>blood){
		if(blood=="A") blo[0]++;
		else if(blood=="B")blo[1]++;
		else if(blood=="AB")blo[2]++;
		else blo[3]++;
	}
	for(int i=0;i<4;i++) cout<<blo[i]<<endl;
	return 0;
}

Measured memory_bytes: 1204
#include<iostream>
#include<string>
#include<vector>
#include<stdio.h>
#include<algorithm>
#include<math.h>
#include<numeric>
#include<iomanip>
#include<deque>
#include<tuple>
#include<queue>
#include<stack>
#include<map>
#include<cstdint>
#include<unordered_map>
#include<boost/multiprecision/cpp_int.hpp>

#define rep(i, n) for(int i = 0; i < ( int)(n); i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define vi vector<int>
#define vll vector<ll>
#define all(x) (x).begin(),(x).end()
#define F first
#define S second


namespace mp = boost::multiprecision;

using cpp_int = mp::cpp_int;
using ll = long long;
using namespace std;


int main()
{
	int n, m;
	cin >> n >> m;
	vector<int>imos(n + 1);
	rep(i, m) {
		int l, r;
		cin >> l >> r;
		l--;
		imos[l]++;
		imos[r]--;
	}
	vector<int>sum(n + 1);
	int ans = 0;
	int count = 0;
	rep(i, n + 1) {
		ans += imos[i];
		sum[i] = ans;
		if (ans == m) {
			count++;
		}
	}
	cout << count << endl;
}



Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=(a),i##_end=(b);i<=i##_end;i++)
#define For(i,a,b) for(int i=(a),i##_end=(b);i<i##_end;i++)
#define per(i,a,b) for(int i=(b),i##_st=(a);i>=i##_st;i--)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define dbg(x) cerr<<#x" = "<<x<<endl
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define Es(x,i) for(Edge *i=G[x];i;i=i->nxt)
typedef long long ll;
typedef pair<int,int> pii;
const int inf=~0u>>1,MOD=1e9+7;
inline int rd() {
    int x,c,f=1;while(!isdigit(c=getchar()))f=c!='-';x=c-'0';
    while(isdigit(c=getchar()))x=x*10+c-'0';return f?x:-x;
}
const int N=1e6+11;
int n;
ll f[N],g[N];
int main(){
	cin>>n;f[1]=g[1]=n;
	rep(i,2,n){
		f[i]=f[i-1]+(i>=3?g[i-3]:0)+1ll*(n-1)*(n-1)+n-max(i-1,2)+1;
		g[i]=(g[i-1]+(f[i]%=MOD))%MOD; 
	}
	cout<<f[n]<<endl;
}

Measured memory_bytes: 15872
import scala.io.StdIn._
object Main extends App {


  val n = readInt()
  val nodes = Array.fill(n * n){Nil: List[Int]}
  for (_ ← 0 until 2 * n * n - 2 * n){
    val Array(a, b) = readLine.trim.split(' ').map(_.toInt)
    nodes(a - 1) ::= b - 1
    nodes(b - 1) ::= a - 1
  }
  println(
    makeMap(n, nodes).map{_.map{_ + 1}.mkString(" ")}.mkString("\n")
  )





  def makeMap(n: Int, info: Array[List[Int]]): Array[Array[Int]] = {
    val counts = info.map{_.length}
    val result = Array.fill(n){Array.fill(n){-1}}
    var position = Point(0, 0)
    var dir = Point(1, 0)
    var current = info.indexWhere(_.length == 2)
    for (i ← 0 until n * n) {
      counts(current) = -1
      result(position.y)(position.x) = current
      for (neighbor ← info(current)) {
        counts(neighbor) -= 1
      }
      var nextPosition = position + dir
      if (!result.indices.contains(nextPosition.x) || !result.indices.contains(nextPosition.y) || result(nextPosition.y)(nextPosition.x) >= 0) {
        dir = dir.rotateRight
        nextPosition = position + dir
      }
      if (i != n * n - 1) {
        val minCount = info(current).map(s ⇒ counts(s)).filter(_ >= 0).min
        current = info(current).filter(suspect ⇒ counts(suspect) == minCount && nextPosition.neighbors.filter(neighbor ⇒ result.indices.contains(neighbor.x) && result.indices.contains(neighbor.y) && result(neighbor.y)(neighbor.x) != -1).forall(neighbor ⇒ info(suspect).contains(result(neighbor.y)(neighbor.x)))).minBy(s ⇒ info(s).length)
        position = nextPosition
      }
    }
    result
  }
  case class Point(x: Int, y: Int) {
    def +(other: Point): Point = Point(x + other.x, y + other.y)
    def rotateRight: Point = Point(-y, x)
    def neighbors: List[Point] = List(Point(x + 1, y), Point(x - 1, y), Point(x, y + 1), Point(x, y - 1))
  }
}


Measured memory_bytes: 96552
import java.util.Scanner;

public class Main {

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

		for (int i = 1; ;i++) {
			int x  = stdIn.nextInt();
			
			if (x == 0) break;
			
			System.out.println("Case " + i + ": " + x);
		}
	}
}


Measured memory_bytes: 45028
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define pf push_front
#define eb emplace_back
#define PF pop_front
#define PB pop_back
#define mp make_pair
#define s second
#define f first
#define mt make_tuple
#define foreach(it, a) for(__typeof(a.begin()) it=a.begin(); it!=a.end(); it++)
#define forn(i, a) for(int i=0; i<a; i++)
#define INF 1e9
#define all(x) x.begin(), x.end()
#define MOD 1e9+7 
 
typedef long long ll;
typedef pair<int,int> pi;
typedef pair<pi,int> pii;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef unsigned int uint;
 
const int dx[4]={0, 0, 1, -1};
const int dy[4]={1, -1, 0, 0};
 
int n, m, stx, sty, step[805][805], mx, res=2e9;
char grid[805][805];
queue<int> q;
 
inline bool out(int x, int y)
{
	return x<0||x==n||y<0||y==m;
}
 
void Init()
{
	cin>>n>>m>>mx;
	memset(step, -1, sizeof(step));
	for(int i=0; i<n; i++)
		for(int j=0; j<m; j++)
		{
			cin>>grid[i][j];
			if(grid[i][j]=='S')
				stx=i, sty=j;
		}
		
	q.push(stx), q.push(sty);
	
	step[stx][sty]=0;
	while(!q.empty())
	{
		int x=q.front();	q.pop();
		int y=q.front();	q.pop();
		if(step[x][y]==mx+1)
			break;
		for(int i=0; i<4; i++)
		{
			int xx=x+dx[i], yy=y+dy[i];
			if(!out(xx, yy)&&step[xx][yy]==-1&&grid[xx][yy]!='#')
			{
				step[xx][yy]=step[x][y]+1;
				q.push(xx);
				q.push(yy);
			}
		}
	}
	while(!q.empty())
		q.pop();
	for(int i=0; i<n; i++)
		for(int j=0; j<m; j++)
			if(step[i][j]<=mx&&step[i][j]!=-1)
				q.push(i), q.push(j);
}
 
int main() 
{
	Init();
	while(!q.empty())
	{
		int x=q.front();	q.pop();
		int y=q.front();	q.pop();
		res=min(res, (min(min(n-x-1, x), min(y, m-y-1))+mx-1)/mx);
	}
	printf("%d", res+1);
	return 0;
}

Measured memory_bytes: 8576
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <cstring>
#include <iomanip>
#include <bitset>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <list>
#include <map>

using namespace std;

long long f(long long x) {
  if (x & 1) {
    return (((x + 1) >> 1) & 1);
  } else {
    return (x ^ ((x >> 1) & 1));
  }
}

int main() {
  long long a, b;
  cin >> a >> b;
  cout << (f(b) ^ (a > 0 ? f(a - 1) : 0)) << endl;
  return 0;
}


Measured memory_bytes: 384
import java.io.InputStream;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
		InputStream is = System.in;
		solve(is);
	}

	private static void solve(InputStream is) {
		try (Scanner cin = new Scanner(is)) {
			int m = cin.nextInt();
			int n = cin.nextInt();

			if (m > 8 || n > 8) {
				System.out.println(":(");
			} else {
				System.out.println("Yay!");
			}
		}
	}
}


Measured memory_bytes: 23124
import sys
stdin = sys.stdin
sys.setrecursionlimit(10**6)
 
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

m,k = na()

def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

mod = 10**9+7 #出力の制限
N = 10**3*3
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル

for i in range( 2, N + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )


for i in range(1,k+1):
    if i > m-k+1:
        print(0)
    else:
        t = cmb(k-1,i-1,mod)*cmb(m-k+1,i,mod)%mod
        print(t)

Measured memory_bytes: 41968
#include <bits/stdc++.h>
#define rank tipa_rank
#define pb push_back
#define mp make_pair
#define ll long long
#define ull unsigned long long
#define INF 1000000000
#define EPS 1e-6
#define free tipa_free
#define EPS2 1e-8
using namespace std;
const ll MOD = INF + 7;
using namespace std;
string s;
string ans;
int n , k;
deque<pair<char , int> > v;
bool swapped = false;
int main()
{
	//freopen("output.txt" , "w" , stdout);
	cin >> n >> k;
	cin >> s;
	for(int i = 0; i < s.size(); i++)
	{
		if(v.size() && v.back().first == s[i])
			v.back().second++;
		else
			v.push_back(mp(s[i] , 1));
	}
	if(n == 1)
	{
		cout << char(((s[0] - 'A') ^ (k % 2)) + 'A');
		return 0;
	}
	/*for(int i = 0; i < v.size(); i++)
		cout << v[i].first << " " << v[i].second << endl;
	cout << endl;*/
	int cnt = 0;
	while(k--)
	{

		if(v.front().first == 'A' + swapped)
		{
			v.front().second--;
			if(!v.front().second)
				v.pop_front();
			if(v.front().first == 'B' - swapped)
			{
				v.front().second++;
			}
			else
				v.push_front(mp('B' - swapped , 1));
		}
		else
		{
			//v.pop_front();
			v.front().second--;
			if(!v.front().second)
				v.pop_front();
			swapped = !swapped;
			if(v.back().first == swapped + 'A')
				v.back().second++;
			else
				v.push_back(mp(swapped + 'A' , 1));
		}
		/*cout << swapped << endl;
		for(int i = 0; i < v.size(); i++)
			cout << v[i].first << " " << v[i].second << endl;
		cout << endl;*/
		cnt++;
		if(cnt == 500000)
		{
			break;
		}
	}
	if(k % 2 && k > 0 && n % 2)
	{
		if(v.front().second == 1)
		{
			v.pop_front();
			v.front().second++;
		}
		else
		{
			v.front().second--;
			v.push_front(mp('A' + swapped , 1));
		}
	}

	//cout << v[0].first - 'A' << endl;
	for(int i = 0; i < v.size(); i++)
	{
		if(!swapped)
		{
			for(int j = 0; j < v[i].second; j++)
				cout << v[i].first;
		}
		else
		{
			for(int j = 0; j < v[i].second; j++)
				cout << char(((v[i].first - 'A') ^ 1) + 'A');
		}
	}
}


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

	int a, b, c, d, e;
	cin>>a>>b>>c>>d>>e;
	if(a<40) a=40;
	if(b<40) b=40;
	if(c<40) c=40;
	if(d<40) d=40;
	if(e<40) e=40;

	cout<<(a + b + c + d + e) / 5<<endl;

	return 0;
}



Measured memory_bytes: 3092
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define INF (1<<20)
#define INFLL (1ll<<60)
typedef pair<int, int> P;
typedef pair<int, P> E;
#define MOD (1000000007ll)
#define l_ength size
#define EPS (1e-10)

void add_mod(ll &a, ll b){
	a += b;
	a %= MOD;
}

void mul_mod(ll &a, ll b){
	a *= b;
	a %= MOD;
}

ll ds(ll x,ll b){
	return (x<b)?x:x%b+ds(x/b,b);
}

int main(void){
	ll n,s,b=INFLL,i,q;
	cin >> n >> s;
	if(n < s){
		cout << "-1" << endl;
		return 0;
	}else if(n == s){
		cout << (n+1) << endl;
		return 0;
	}
	for(i=2ll; i*i<=n; ++i){
		if(ds(n,i)==s){
			b = min(b,i);
		}
	}
	for(i=1ll; i*i<=n; ++i){
		if((n-s)%i){
			continue;
		}
		q = (n-s)/i+1;
		if(ds(n,q)==s){
			b = min(b,q);
		}
	}
	cout << ((b==INFLL)?-1:b) << endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>

using namespace std;

int main()
{
	bool a[1000000];
	int n;
	
	fill(a, a+1000000, false);
	a[2] = true;
	for(int i = 3; i < 1000000; i+=2){
		bool f = true;
		for(int j = 3; j*j <= i; j+=2){
			if(i%j == 0){
				f = false;
				break;
			}
		}
		a[i] = f;
	}
	
	while(cin >> n){
		int c = 0;
		for(int i = 2; i <= n; i++){
			if(a[i]){
				c++;
			}
		}
		cout << c << endl;
	}
	
	return 0;
}

Measured memory_bytes: 1840
#include<iostream>
using namespace std;
enum{W=10,H=10};

bool clear(bool field[H][W]){
  bool ok=true;
  for(int i=0;i<H;i++)for(int j=0;j<W;j++)if(field[i][j])ok=false;
  return ok;
}

int main(){
  int n;
  bool field[H][W];
  bool dup[H][W];
  int bit[H];
  cin>>n;
  int t=0;
  while(n-->0){
    for(int i=0;i<H;i++)for(int j=0;j<W;j++)cin>>field[i][j];

    for(bit[0]=0; bit[0] < (1<<10); bit[0]++){
      for(int i=1;i<H;i++)bit[i]=0;
      for(int i=0;i<H;i++)for(int j=0;j<W;j++)dup[i][j]=field[i][j];

      for(int j=0;j<W;j++){
        if(!((bit[0]>>j)&1))continue;
        dup[0][j]^=1;
        dup[1][j]^=1;
        if(j>0)dup[0][j-1]^=1;
        if(j<W-1)dup[0][j+1]^=1;
      }

      for(int i=1;i<H;i++){
        for(int j=0;j<W;j++){
          if(dup[i-1][j]){
            bit[i]^=(1<<j);
            dup[i][j]^=1;
            dup[i-1][j]^=1;
            if(i<H-1)dup[i+1][j]^=1;
            if(j>0)dup[i][j-1]^=1;
            if(j<W-1)dup[i][j+1]^=1;
          }
        }
      }
      if(clear(dup))break;
    }
    for(int i=0;i<H;i++){
      for(int j=0;j<W;j++){
        if(j!=0)cout<<" ";
        if(bit[i]&(1<<j))cout<<"1";
        else cout<<"0";
      }
      cout<<endl;
    }
  }
}

Measured memory_bytes: 1152
#include<iostream>
#include<cstdio>
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-'0';ch=getchar();}
	return x*f;
}
inline void Put(int x){
	if(x==0) putchar('0');
	int num=0;char ch[20];
	if(x<0){x=-x;putchar('-');}
	while(x){ch[++num]=x%10+'0';x/=10;}
	while(num){putchar(ch[num]);num--;}
}
int A,B,C,D,E,F,a,b,c,d,T,S;
int Ans1,Ans2;
int main(){
	A=Read();B=Read();C=Read();D=Read();E=Read();F=Read();
	for(int ia=0;ia*A*100<=F;ia++){
		a=ia*A*100;
		for(int ib=0;ib*B*100+a<=F;ib++){
			b=a+ib*B*100;
			for(int ic=0;ic*C+b<=F&&ic*C<=(ia*A+ib*B)*E;ic++){
				c=b+C*ic;d=C*ic;
				for(int id=0;id*D+c<=F&&d+id*D<=(ia*A+ib*B)*E;id++){
					S=d+id*D;
					T=id*D+c;
					if((Ans1==0||Ans2==0)&&T){Ans2=S;Ans1=T;}
					if(Ans2*T<Ans1*S){Ans2=S;Ans1=T;}
				}
			}
		}
	}
	Put(Ans1);
	putchar(' ');
	Put(Ans2);
	return 0;	
}

Measured memory_bytes: 256
<?php
$N = trim(fgets(STDIN));
$B = explode(' ', trim(fgets(STDIN)));

$A = array();
array_unshift($A, $B[0]);

for ($i = 1; $i < count($B); $i++) {
    if ($B[$i] > $B[$i - 1]) {
        $A[$i] = $B[$i - 1];
    }else {
        $A[$i] = $B[$i];
    }
}
array_push($A, $B[$N - 2]);
echo(array_sum($A));

Measured memory_bytes: 3828
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef vector<int> VI;

template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()

bool check(int num, vector<int> v) {
    while (num > 0) {
        int d = num % 10;
        for (auto e: v) {
            if (d == e) {
                return false;
            }
        }
        num /= 10;
    }
    return true;
}


int main() {
    int n, k;
    cin >> n >> k;
    vector<int> v(k);
    rep (i, k) {
        cin >> v[i];
    }
    --n;
    while (++n) {
        if (check(n, v)) {
            cout << n << endl;
            exit(0);
        }
    }
}

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

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

long long ans = 0;

void rec(int N, int M, int Q, int num, vector<int> tmp, vector<long> &a, vector<long> &b, vector<long> &c, vector<long> &d){

    if(N == 0){
        long long sum = 0;
        for (int i = 0; i < Q;i++){
            if(tmp.at(b.at(i) - 1) - tmp.at(a.at(i) - 1) == c.at(i)){
                sum += d.at(i);
            }
        }
        if(ans < sum){
            ans = sum;
        }
        return;
    }
    for (int i = num; i <= M;i++){
        vector<int> _tmp = tmp;
        _tmp.push_back(i);
        rec(N - 1, M, Q, i, _tmp, a, b, c, d);
    }
}

int main()
{
    int N, M, Q;
    cin >> N >> M >> Q;
    vector<long> a(Q), b(Q), c(Q), d(Q);
    rep(i, Q){
        cin >> a.at(i) >> b.at(i) >> c.at(i) >> d.at(i);
    }
    vector<int> tmp;
    rec(N, M, Q, 1, tmp, a, b, c, d);
    cout << ans << endl;
}



Measured memory_bytes: 3616
def read():
    N, D = map(int, input().split(' '))
    ps = []
    for _ in range(N):
        x, y = map(int, input().split(' '))
        ps.append((x, y))
    return N, D, ps


def fun(N, D, ps):
    ans = 0
    for n in range(N):
        x, y = ps[n]
        d = x*x + y*y
        if d <= D*D:
            ans += 1
    return ans


if __name__ == '__main__':
    N, D, ps = read()
    print(fun(N, D, ps))


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

p = list(map(float, input().split()))

dp = [[0 for j in range(N+2)] for i in range(N+1)]
dp[0][1] = 1

for i in range(N):
    for j in range(i+2):
        dp[i+1][j+1] = dp[i][j+1] * (1 - p[i]) + dp[i][j] * p[i]

print(sum(dp[N][N + N//-2 + 2:]))


Measured memory_bytes: 261256
#include <iostream>
#include <map>
#include <ctime>
#include <vector>
#include <climits>
#include <algorithm>
#include <random>
#include <cstring>
#include <cstdio>
#include <map>
#include <set>
#include <bitset> 
#include <queue>
#pragma warning(disable:4996);
#define inf 0x3f3f3f3f
#define IOS ios_base::sync_with_stdio(0); cin.tie(0);
#define rep(i, a, n) for(register int i = a; i <= n; ++ i)
#define per(i, a, n) for(register int i = n; i >= a; -- i)
//#define ONLINE_JUDGE
using namespace std;
typedef long long ll;
const int mod=1e9+7;
template<typename T>void write(T x)
{
    if(x<0)
    {
        putchar('-');
        x=-x;
    }
    if(x>9)
    {
        write(x/10);
    }
    putchar(x%10+'0');
}
 
template<typename T> void read(T &x)
{
    x = 0;char ch = getchar();ll f = 1;
    while(!isdigit(ch)){if(ch == '-')f*=-1;ch=getchar();}
    while(isdigit(ch)){x = x*10+ch-48;ch=getchar();}x*=f;
}
int gcd(int a,int b){return b==0?a:gcd(b,a%b);}
int lcm(int a,int b){return a/gcd(a,b)*b;};
ll ksm(ll a,ll n){//看是否要mod 
	ll ans=1;
	while(n){
		if(n&1) ans=((ans%mod)*(a%mod))%mod;
		a=((a%mod)*(a%mod))%mod;
		n>>=1;
	}
	return ans%mod;
}
//==============================================================
string str;


int main()
{
	#ifndef ONLINE_JUDGE
	freopen("in.txt","r",stdin);
	freopen("out.txt","w",stdout);
	#endif
	//===========================================================
	cin>>str;
	int l=0,flag=0,ans=0;
	rep(i,0,int(str.length())-1){
		if(str[i]=='R'){
			if(flag==0) flag=1,l=i;
		}
		else{
			if(flag){
				ans=max(ans,i-l);
				flag=0;
			}
		}
	}
	if(flag){
		ans=max(ans,int(str.length())-l);
	}
	write(ans);
	//===========================================================
	return 0;
}

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

using namespace std;
using ll = long long int;

ll n,k,ara[105],mod=1e9+7,dp[105][100005],cum[105][100005];

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    ll i,j;
    cin>>n>>k;

    for(i=1; i<=n; i++) cin>>ara[i];

    for(i=0; i<=k; i++)
    {
        dp[0][i]=0;
    }

    for(i=0; i<=n; i++)
    {
        dp[i][0]=1;
        cum[i][0]=1;
    }

    ll temp=0;

    for(i=0; i<=k; i++)
    {
        temp=((temp%mod)+(dp[0][i]%mod))%mod;
        cum[0][i]=temp;

    }

    for(i=1; i<=n; i++)
    {
        temp=1;
        for(j=1; j<=k; j++)
        {
            ll mn=min(j,ara[i]);
            ll st=j-mn,en=j,sum;
            if(st) sum=((cum[i-1][en]%mod)-(cum[i-1][st-1]%mod))%mod;
            else sum=cum[i-1][en]%mod;
            if(sum<0) sum+=mod;
            dp[i][j]=sum;
            temp=((temp%mod)+(dp[i][j]%mod))%mod;
            cum[i][j]=temp;
        }
    }

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

}


Measured memory_bytes: 160000
#include <bits/stdc++.h>
#define mod 1000000007
#define mod998 998244353
#define sp ' '
#define intmax 2147483647
#define llmax 9223372036854775807
#define mkp make_pair
typedef long long ll;
using namespace std;

int N, x[100000], y[100000], c[100000];
vector<int>v[100000], V[100000];
ll res, uf[100000];

int par(int x) {
	if (uf[x] < 0)return x;
	else return uf[x] = par(uf[x]);
}

void uni(int x, int y) {
	x = par(x);
	y = par(y);
	if (x == y)return;
	if (uf[x] < uf[y]) {
		uf[x] += uf[y];
		uf[y] = x;
	}
	else {
		uf[y] += uf[x];
		uf[x] = y;
	}
}

int main() {
	cin >> N;
	for (int i = 0; i < N; ++i) {
		cin >> x[i] >> y[i];
		--x[i];
		--y[i];
		v[x[i]].push_back(y[i]);
	}
	memset(uf, -1, sizeof uf);
	for (int i = 0; i < 100000; ++i) {
		for (int j : v[i]) {
			uni(v[i].front(), j);
		}
	}
	for (int i = 0; i < N; ++i) {
		V[par(y[i])].push_back(x[i]);
		++c[par(y[i])];
	}
	for (int i = 0; i < 100000; ++i) {
		if (V[i].size()) {
			sort(V[i].begin(), V[i].end());
			V[i].erase(unique(V[i].begin(), V[i].end()), V[i].end());
			res += ll(V[i].size())*(-uf[i]) - c[i];
		}
	}
	cout << res << endl;
}

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

int a,b,c,sum=0;

int tax(int x,int s){
  return s*(100+x)/100;
}

int solve(){
  sum=0;
  for(int i=1;i<c;i++){
    for(int j=1;j<c;j++){
      if(tax(a,i)+tax(a,j)==c){
        sum=max(tax(b,i)+tax(b,j),sum);
      }
    }
  }
  return sum;
}

int main(){
  while(cin >> a >> b >> c && a>0 && b>0 && c>0){
    cout << solve() << endl;
  }
}



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

namespace ABC096
{
    class Program
    {
        public static void Main(string[] args)
        {
            var input = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
            int a = input[0];
            int b = input[1];
            int x = input[2];
            string result = "NO";

            result = ((a+b) > x && a <= x) ? "YES" : "NO";

            Console.WriteLine(result);

            Console.ReadLine();
        }
    }
}

Measured memory_bytes: 13396