akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <random>
#include <chrono>
#include <queue>
#include <ctime>
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
#define fs first
#define sc second
#define INF 1000000000
#define MOD 1000000007
#define EPS 0.00000001


int main(){
    int N, K; cin >> N >> K;
    vector<int> A(N);
    ll sum = 0;
    for(int &a:A){
        cin >> a;
        sum += a;
    }
    
    vector<ll> d;
    for(int i=1; i*i<=sum; i++){
        if(sum%i==0){
            d.push_back(i);
            if(i*i!=sum) d.push_back(sum/i);
        }
    }
    sort(d.begin(), d.end());
    
    ll ans = 0;
    for(int i=0; i<d.size(); i++){
        vector<ll> r;
        ll s  = 0;
        for(int j=0; j<N; j++){
            if(A[j]%d[i]){
                r.push_back(A[j]%d[i]);
                s += A[j]%d[i];
            }
        }
        
        sort(r.begin(), r.end(), greater<ll>());
        ll cnt = s / d[i];
        ll cur = 0;
        for(int j=0; j<cnt; j++){
            cur += d[i] - r[j];
        }
        if(cur <= K) ans = d[i];
    }
    
    cout << ans << endl;
    
    return 0;
}





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

using namespace std;

typedef long long int Int;

bool field[100][100];

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

    for(int i = 50;i < 100;i++) {
        for(int j = 0;j < 100;j++) {
            field[i][j] = true;
        }
    }

    a--,b--;

    cout<<100<<" "<<100<<endl;

    for(int i = 0;i < 50;i += 2) {
        for(int j = 0;j < 100;j += 2) {
            if(b > 0) {
                b--;
                field[i][j] = true;
            }
        }
    }

    for(int i = 51;i < 100;i += 2) {
        for(int j = 0;j < 100;j += 2) {
            if(a > 0) {
                a--;
                field[i][j] = false;
            }
        }
    }

    for(int i = 0;i < 100;i++) {
        for(int j = 0;j < 100;j++) {
            if(field[i][j])
                cout<<"#";
            else
                cout<<".";
        }
        cout<<endl;
    }

    return 0;
}


Measured memory_bytes: 760
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rng(i, a, b) for (int i = int(a); i < int(b); i++)
#define rep(i, b) rng(i, 0, b)
#define gnr(i, a, b) for (int i = int(b) - 1; i >= int(a); i--)
#define per(i, b) gnr(i, 0, b)
#define bg begin()
#define ed end()
#define all(x) x.bg, x.ed
#define vi vector<int>
template <class t, class u>
void chmax(t &a, u b)
{
    if (a < b)
        a = b;
}
template <class t, class u>
void chmin(t &a, u b)
{
    if (b < a)
        a = b;
}

int main()
{
    string s;
    cin >> s;
    vector<ll> n(s.length() + 1, 0);
    for (int i = 0; i < s.length(); i++)
    {
        if (s[i] == '<')
        {
            chmax(n[i + 1], n[i] + 1);
        }
    }
    for (int i = s.length() - 1; i >= 0; i--)
    {
        if (s[i] == '>')
        {
            chmax(n[i], n[i + 1] + 1);
        }
    }

    cout << std::accumulate(all(n), ll(0)) << endl;
    return 0;
}

Measured memory_bytes: 4740
// 簡易競プロテンプレ
#include <bits/stdc++.h>
using namespace std;
int n, m;
int f[8][8];
int a,b;
int main(void){
 cin >> n >> m;
 for(int i=0;i<m;i++){cin >> a >> b; f[a-1][b-1] = f[b-1][a-1] = 1;}
 vector<int> p(n);
 for(int i=0;i<n;i++) p[i] = i;
 int ans = 0;
 do{
  if (p[0]!=0) continue;
  int ok = 1;
  for(int i=0;i+1<n;i++){if (f[p[i]][p[i+1]]==0) ok = 0;}
  if (ok) ans++;
 }while(next_permutation(p.begin(), p.end()));
 cout << ans << endl;
 return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

void proc(int a,int b,int c){
  char r='F';
  if(a==-1||b==-1)r='F';
  else{
    if(a+b>=80)r='A';
	else if(a+b>=65)r='B';
	else if(a+b>=50)r='C';
	else if(a+b>=30){
	  r='D';
	  if(c>=50)r='C';
	}
  }
  printf("%c\n",r);
}

int main(){
  while(true){
    int a,b,c;
    scanf("%d%d%d", &a,&b,&c);
	if(a==-1&&b==-1&&c==-1)break;
	proc(a,b,c);
  }
  return 0;
}

Measured memory_bytes: 1012
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
using namespace std;
typedef long long ll;
typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 1000000007;
typedef long double ld;
const ll INF = mod * mod;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
#define fr first
#define sc second

int n,m,k;
bool used[2001][4001];
ll ans[2001][4001];
ll dfs(int s, int r) {
	if (s < 0)return 0;
	if (used[s][r])return ans[s][r];
	used[s][r] = true;
	if (r == 0) {
		if (s == 0)return ans[s][r] = 1;
		else return ans[s][r] = 0;
	}
	ll ret = 0;
	rep(i, k) {
		ret += dfs(s - i, r - 1);
		if (ret >= mod)ret -= mod;
	}
	return ans[s][r] = ret;
}
void solve() {
	cin >> n >> m >> k;
	ll cnt = 0;
	int d = (n + m - 1) / (k - 1);
	rep(i, d) {
		int r = m - i * (k - 1);
		if (r == 0)break;
		//if (r < i)break;
		cnt += dfs(r, d - i);
		if (cnt >= mod)cnt -= mod;
	}
	cout << cnt << endl;
}
int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	solve();
	//stop
		return 0;
}

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

int main() {

	int n; cin >> n;

	vector<long long> a(n + 1);
	
	long long sum = 0;
	
	for (int i = 1; i <= n; ++i) {
		cin >> a[i];
		sum += a[i];
	}

	vector<long long> x(n + 1, 0);
	
	x[1] += sum;
	for (int i = 1; i <= (n + 1) / 2; i++) {
		x[1] -= 2 * a[2 * i];
	}

	for (int i = n; i >= 2; --i) {

		if (i == n) {
			x[i] = 2 * a[i] - x[1];
		}
		else {
			x[i] = 2 * a[i] - x[i + 1];
		}

	}

	for (int i = 1; i <= n; ++i) {
		cout << x[i] << " ";
	}

	return 0;
}

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

const int SIZE = 10000000;

bool used[SIZE];

int main() {
    int m, n;
    while (cin >> m >> n, m | n) {
        memset(used, false, sizeof(used));
        int life = n;
        for (int i = m; i < SIZE; i++) {
            if (!used[i]) {
                if (life > 0) {
                    life--;
                    for (int j = 1; i * j < SIZE; j++) {
                        used[i * j] = true;
                    }
                } else break;
            }
        }
        for (int i = m; i < SIZE; i++) {
            if (!used[i]) {
                cout << i << endl;
                break;
            }
        }
        /*
        for (int i = m; i < SIZE; i++) {
            if (used[i]) continue;
            if (life > 0) {
                life--;
            } else {
                cout << i << endl;
                break;
            }
        }
        */
    }

    return 0;
}

Measured memory_bytes: 12872
#include<bits/stdc++.h>
#define rep(i,a,b) for (int i=(a); i<=int(b); i++)
#define pb push_back
#define mp make_pair
#define v first
#define w second
using namespace std;
typedef pair<int,int> pii;

const int maxn = 200009, INF = 2e9;
int d[maxn], q[maxn], l, r, a, b, c, n, m, u;
vector<pii> e[maxn];

void bfs(int s) {
	l = r = 0; q[r++] = s; d[s] = 0;
	while (l < r) {
		u = q[l++];
		for (auto k : e[u])
			if (d[k.v] >= INF) {
				d[k.v] = d[u] + k.w;
				q[r++] = k.v;
			}
			else if (d[u] + k.w != d[k.v]) {
				puts("No"); exit(0);
			}
	}
}

int main() {
	scanf("%d%d", &n, &m);
	rep (i, 1, m) {
		scanf("%d%d%d", &a, &b, &c);
		e[a].pb(mp(b, c)); e[b].pb(mp(a, -c));
	}
	memset(d, 0x7f, sizeof d);
	rep (i, 1, n)
		if (d[i] >= INF) bfs(i);
	puts("Yes");
	return 0;
}

Measured memory_bytes: 12672
#include<stdio.h>
int main()
{
	int r,g,b,n;
	int counter=0;
	int i,j,k;
	scanf("%d %d %d %d",&r,&g,&b,&n);
	for(i=0;i<=n/r;i++){
		for(j=0;j<=(n-r*i)/g;j++){
			if((n-r*i-j*g)%b==0){
				counter+=1;
			}
		}
	}
	printf("%d",counter);
}

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

#define MAX 100
#define WHITE 0
#define BLACK 1
#define GRAY 2

int i, j, n, M[MAX][MAX];

void print()
{
    printf("%d\n", prim());
}

int prim()
{
    int u, v, mincost, weight = 0;
    int d[MAX], p[MAX], color[MAX];
    
    for (i = 0; i < n; i++) {
        d[i] = 100000;
        p[i] = -1;
        color[i] = WHITE;
    }
    
    d[0] = 0;
    
    while (1) {
        mincost = 100000;
        u = -1;
        for (i = 0; i < n; i++) {
            if (color[i] != BLACK && d[i] < mincost) {
                mincost = d[i];
                u = i;
            }
        }
        if (u == -1) {
            break;
        }
        color[u] = BLACK;
        
        for(v = 0; v < n; v++) {
            if (color[v] != BLACK && M[u][v] != 100000) {
                if (M[u][v] < d[v]) {
                    d[v] = M[u][v];
                    p[v] = u;
                    color[v] = GRAY;
                }
            }
        }
    }
    
    for (i = 0; i < n; i++) {
        if (p[i] != -1) {
            weight = weight + M[i][p[i]];
        }
    }
    
    return weight;
}

int main()
{
    int e;
    
    scanf("%d", &n);
    for (i = 0; i < n; i++) {
        for (j = 0; j < n; j++) {
            scanf("%d", &e);
            M[i][j] = e;
            if (e == -1) {
                M[i][j] = 100000;
            }
        }
    }
    
    print();
    
    return 0;
}


Measured memory_bytes: 2124
#include<bits/stdc++.h>
using namespace std;
             
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll,ll> Pi;
typedef map<ll,ll> mi;
             
template<class T> T nrem(T x,T y){return ((x%y)+y)%y;}
             
#define For(i,a,n) for(int i=a;i<n;++i)
#define For0(i,n) for(int i=0;i<n;++i)
#define For1(i,n) for(int i=1;i<=n;++i)
#define Forl0(i,n) for(ll i=0;i<n;++i)
#define Forl1(i,n) for(ll i=1;i<=n;++i)
#define fi freopen("input.txt","r",stdin);
#define fo freopen("output.txt","w",stdout);
#define pb push_back
#define mp make_pair
#define endl "\n"
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define cs 200005
#define pi acos(-1)
#define INF (int)INFINITY
void in()
    {
         #ifndef ONLINE_JUDGE
         freopen("input.txt", "r", stdin);
         freopen("output.txt", "w", stdout);
        #endif
    }

vector<int> adj[cs];
int visited[cs];
int level[cs];

void bfs(int s)
{
    queue <int> Q;
    Q.push(s);

    visited[s]=1;
    level[s]=0;
    while(!Q.empty())
    {
        int u=Q.front();
        Q.pop();

        for(int i=0;i<adj[u].size();i++)
            if(visited[adj[u][i]]==0)
        {
            int v=adj[u][i];
            visited[v]=1;
            level[v]=level[u]+1;
            Q.push(v);
        }
    }
}

int main()
{  
    IOS
    in();
    
   int n,m;
   cin>>n>>m;

   For0(i,m)
   {
       int a,b;
       cin>>a>>b;
       adj[a].pb(b);
       adj[b].pb(a);
   }
    
    memset(level,-1,sizeof level);

    bfs(1);
    if(level[n]<=2&&level[n]!=-1)
    cout<<"POSSIBLE"<<endl;
    else cout<<"IMPOSSIBLE"<<endl;
}

Measured memory_bytes: 16708
#include <iostream>
#include <stack>
#include <algorithm>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <functional>
#include <string>
#include <cstdlib>
#include <numeric>
#include <cstdbool>
#include <cstring>
#include <map> 
#include<set>
#include<queue>
#include <iomanip>

typedef long long ll;

#define rep(i,n) for(ll i=0;i<n;i++)
using namespace std;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

const long long INF = 1000000000000000;
const ll inf = -1e18;
typedef pair<ll, ll> P;
ll ma = 1000000000 + 7;
ll mx = 1000003;
ll h,n, w,m; string s;
int dx[4] = { 1, 0, -1, 0 };
int dy[4] = { 0, 1, 0, -1 };
ll gcd(ll x, ll y) {
	if (x % y == 0) return y;
	return gcd(y, x % y);
}
ll lcm(ll a,ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}
void comb(vector<vector <ll> >& v) {
	for (ll i = 0; i < v.size(); i++) {
		v[i][0] = 1;
		v[i][i] = 1;
	}
	for (ll k = 1; k < v.size(); k++) {
		for (int j = 1; j < k; j++) {
			v[k][j] = (v[k - 1][j - 1] + v[k - 1][j])%ma;
		}
	}
}

ll GetDigit(ll num) {
	return log10(num) + 1;
}
ll Combination(int n, int r)
{
	if (n - r < r) r = n - r;
	if (r == 0) return 1;
	if (r == 1) return n;

	vector<ll> numerator(r);
	vector<ll> denominator(r);

	for (int k = 0; k < r; k++)
	{
		numerator[k] = n - r + k + 1;
		denominator[k] = k + 1;
	}

	for (int p = 2; p <= r; p++)
	{
		int pivot = denominator[p - 1];
		if (pivot > 1)
		{
			int offset = (n - r) % p;
			for (int k = p - 1; k < r; k += p)
			{
				numerator[k - offset] /= pivot;
				denominator[k] /= pivot;
			}
		}
	}

	ll result = 1;
	for (int k = 0; k < r; k++)
	{
		if (numerator[k] > 1) result *= numerator[k];
		result %= ma;
	}

	return result;
}
double dis[10][10];
bool flg[10][10];
int main() {
	cin >> n;
	vector<double> x(n);
	vector<double> y(n);
	rep(i, n) {
		cin >> x[i] >> y[i];
	}
	rep(i, n) {
		rep(j, n) {
			dis[i][j] = sqrt((x[i] - x[j]) * (x[i] - x[j]) + (y[i] - y[j]) * (y[i] - y[j]));
			flg[i][j] = false;
		}
	}
	ll pp = 1;ll k = 1;
	for (ll i = n; i >= 1; i--) {
		pp *= i;
		k *= i;
	}
	pp *= (n - 1);
	pp /= Combination(n, 2);
	double res = 0;
	rep(i, n) {
		for (ll j = i + 1; j < n; j++) {
			if (!flg[i][j]) {
				res += dis[i][j];
				flg[i][j] = true;
				flg[j][i] = true;
			}
		}
	}
	res *= pp;
	res /= k;
	cout << setprecision(10) << res << endl;
	
}



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

using namespace std;

int main()
{
	int N;
	long long ans = 0;
	int max_count = 0;

	cin >> N;
	vector<int> A(N);
	vector<int> C(N);

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

		int count = 0;
		while (A[i] != 0 && A[i] % 2 == 0)
		{
			A[i] /= 2;
			count++;
		}

		if (count > max_count)
		{
			max_count = count;
		}
		C[i] = count;
	}

	for (int i = 0; i < N; i++)
	{
		if (C[i] == 0)
		{
			continue;
		}

		ans += C[i];
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 384
n, l = map(int, input().split())
e = l+n-1

if (l * e) < 0:
    print(int(n/2*(l+e)))
else:
    if min(abs(l), abs(e)) == abs(l):
        print(int(n/2*(l+e)) - l)
    else:
        print(int(n/2*(l+e)) - e)


Measured memory_bytes: 2940
#!/usr/bin/env python3

from copy import deepcopy

def dfs(x, adj, visited):
    for y, flag in enumerate(adj[x]):
        if flag and y not in visited:
            visited.add(y)
            dfs(y, adj, visited)

def main():
    n, m = map(int, input().split())
    adj = [[(i == j) for i in range(n)] for j in range(n)]
    edges = set()
    for i in range(m):
        a1, b1 = map(int, input().split())
        a = a1 - 1
        b = b1 - 1
        edges.add((a, b))
        adj[a][b] = True
        adj[b][a] = True

    res = 0
    for e in edges:
        adjc = deepcopy(adj)
        adjc[e[0]][e[1]] = False
        adjc[e[1]][e[0]] = False
        visited = {0}
        dfs(0, adjc, visited)
        if len(visited) < n:
            res += 1
    print(res)

main()


Measured memory_bytes: 3568
#include <bits/stdc++.h>
using namespace std;
#include <iostream>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <algorithm>
int main() {
 int N,K;
  cin>>N>>K;
  N=N+1;
  N=N/2;
  K=N-K;
  if(K<0){
  cout<<"NO"<<endl;
  }else{
  cout<<"YES"<<endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long int
#define mp make_pair
#define pa pair<int,int>
#define ld long double
#define BOOST ios_base::sync_with_stdio(false)
#define pb push_back
using namespace std;
const int MAX=1e5+5;
int dp[MAX];
int main()
{
    int n;
    scanf("%d",&n);
    int tab[n];
    dp[0]=0;
    dp[1]=0;
    for (int i=1;i<=n;i++)
    {
        scanf("%d",&tab[i]);
    }
    tab[0]=-10000000;
    for (int i=2;i<=n;i++)
    {
        dp[i]=min(dp[i-1]+abs(tab[i]-tab[i-1]),dp[i-2]+abs(tab[i]-tab[i-2]));
    }

    printf("%d",dp[n]);

    return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using ll=long long;
using namespace std;
#define rep(i, n) for(ll i=0; i<n; i++)
#define Rep(i, j, n) for(ll i=j; i<n; i++)
#define all(vec) vec.begin(), vec.end()
template<class T> inline bool chmin(T& a, T b) {if(a > b) {a = b; return true;} return false;}
template<class T> inline bool chmax(T& a, T b) {if(a < b) {a = b; return true;} return false;}

int main(){
  string s;
  cin>>s;
  int ans=0;
  rep(i,3)if(s[i]=='R')ans++;
  if(ans==2&&s[1]=='S')ans=1;
  cout<<ans<<endl;
    
    
  return 0;
}


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

/* メモリ食い過ぎ注意 */
#define int long long

typedef long long ll;

/* define const */
const ll INF = (1ll << 60);
const ll MOD = (ll)1e9 + 7;
/* end defineing */

signed main()
{
    double t, x;
    cin >> t >> x;

    cout << t / x;
}


Measured memory_bytes: 256
/*

    author : s@if

*/

#include<bits/stdc++.h>
using namespace std;

#define 		NIL 			-1
#define		 	fi	 		    first
#define 		sec 			second
#define 		MAX 			INT_MAX
#define			INF 			99999999
#define 		ll 			    long long
#define 		PI 			    acos(-1.0)
#define			MOD 			1000000007
#define 		PLL 			pair<ll,ll>
#define 		PII			    pair<int,int>
#define 		ull 			unsigned long long
#define 		For(i,a,b) 		for(int i=a;i<=(int)b;i++)


bool Check(int N , int pos)	{	return (bool) (N & (1<<pos));}
int Set(int N, int pos) {	return N = N | (1<<pos);}

int fx[]={+0,+0,+1,-1,-1,+1,-1,+1};
int fy[]={-1,+1,+0,+0,+1,+1,-1,-1};
int hr[]={-2,-2,-1,+1,+2,+2,-1,+1};
int hc[]={+1,-1,+2,+2,-1,+1,-2,-2};
int dx[]={+1,-1,+0,+0};
int dy[]={+0,+0,+1,-1};

const int MAXN = (int)1e5+9;

ll a[MAXN], b[MAXN];

int main()
{
/*	freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);  */

    ll i,j,k,l,m,n,p,q,x,y,u,v,r,tc,t;

    cin>>n;

    For(i,1,n)
    {
        cin>>a[i];
    }

    ll sum = 0;

    For(i,1,n-1)
    {
        if(i%2==0)
            sum+=a[i];
        else
            sum-=a[i];
    }

    b[1] = (a[n]-sum)/2;

    For(i,2,n)
    {
        b[i] = a[i-1] - b[i-1];
    }

    For(i,1,n)
        cout<<b[i]*2<<" ";
    
    cout<<endl;

    //main();

    return 0;
}

// read the question correctly (is y a vowel? what are the exact constraints?)
// look out for SPECIAL CASES (n=1?) and overflow (ll vs int?)


Measured memory_bytes: 2816
#include <bits/stdc++.h>
using namespace std;
int n,T;
long long w[100010],v[100010],dp[100010];
int main(){
	cin>>n>>T;
	for(int i=1;i<=n;++i){
		cin>>w[i]>>v[i];
	}
	for(int i=1;i<=n;++i){
		for(int j=T;j>=0;--j){
			if(j>=w[i])
			dp[j]=max(dp[j-w[i]]+v[i],dp[j]);
		}
	}
	cout<<dp[T]<<endl;
	return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define int long long
#define pii pair<int,int>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(c) (c).begin(),(c).end()
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
#define MINF(a) memset(a,0x3f,sizeof(a))
#define POW(n) (1LL<<(n))
#define IN(i,a,b) (a <= i && i <= b)
using namespace std;
template <typename T> inline bool CHMIN(T& a,T b) { if(a>b) { a=b; return 1; } return 0; }
template <typename T> inline bool CHMAX(T& a,T b) { if(a<b) { a=b; return 1; } return 0; }
template <typename T> inline void SORT(T& a) { sort(ALL(a)); }
template <typename T> inline void REV(T& a) { reverse(ALL(a)); }
template <typename T> inline void UNI(T& a) { sort(ALL(a)); a.erase(unique(ALL(a)),a.end()); }
const int MOD = 1000000007;
const int INF = 0x3f3f3f3f3f3f3f3f;
const double EPS = 1e-10;
/* ---------------------------------------------------------------------------------------------------- */

int L,R;

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

  cin >> L >> R;
  if (R - L >= 2018) {
    cout << 0 << endl;
    return 0;
  }
  vector<int> v;
  FOR(i,L,R+1) v.push_back(i % 2019);
  int ans = 2019;
  REP(i,v.size()) REP(j,v.size()) if (i < j) {
    CHMIN(ans,v[i]*v[j]%2019);
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<stack>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#include<stdlib.h>
#include<cassert>
#include<time.h>
#include<bitset>
using namespace std;
const long long mod=1000000007;
const long long inf=mod*mod;
const long long d2=(mod+1)/2;
const long double EPS=1e-9;
const long double PI=acos(-1.0);
int ABS(int a){return max(a,-a);}
long long ABS(long long a){return max(a,-a);}
long double ABS(long double a){return max(a,-a);}
vector<pair<int,int> > g[110000];
int col[110000];
int ks=-1;
long long M=0;
long long pos[110000];
bool dame=false;
void dfs(int a,int b,long long c){
	pos[a]=c;
	for(int i=0;i<g[a].size();i++){
	//	if(b==g[a][i].first)continue;
		if(col[g[a][i].first]!=-1){
			if(col[a]==col[g[a][i].first]){
				ks=g[a][i].first;
				M=pos[g[a][i].first]+(g[a][i].second-c);
			}else{
				if(pos[g[a][i].first]!=(g[a][i].second-c))dame=true;
			}
		}else{
			col[g[a][i].first]=1-col[a];
			dfs(g[a][i].first,a,(g[a][i].second-c));
		}
	}
}
int v[110000];
long long val[110000];
void dfs2(int a,int b,long long c){
	val[a]=c;
	v[a]=1;
	for(int i=0;i<g[a].size();i++){
	//	if(b==g[a][i].first)continue;
		if(v[g[a][i].first])continue;
		dfs2(g[a][i].first,a,g[a][i].second-c);
	}
}
int main(){
	int a,b;scanf("%d%d",&a,&b);
	for(int i=0;i<b;i++){
		int p,q,r;
		scanf("%d%d%d",&p,&q,&r);p--;q--;
		g[p].push_back(make_pair(q,r));
		g[q].push_back(make_pair(p,r));
	}
	for(int i=0;i<a;i++)col[i]=-1;
	col[0]=0;
	dfs(0,-1,0LL);
	if(dame){
		printf("0\n");return 0;
	}
	if(ks==-1){
		long long right=inf;
		long long left=1;
		for(int i=0;i<a;i++){
			if(col[i]==0){
				left=max(left,-pos[i]+1);
			}else{
				right=min(right,pos[i]-1);
			}
		}
		printf("%lld\n",max(0LL,right-left+1));
	}else{
		if(ABS(M)%2){
			printf("0\n");return 0;
		}
		long long st=M/2;
	//	printf("%d %lld\n",ks,st);
		dfs2(ks,-1,st);

		for(int i=0;i<a;i++){
			if(val[i]<=0){
				printf("0\n");return 0;
			}
			for(int j=0;j<g[i].size();j++){
				if(val[i]+val[g[i][j].first]!=g[i][j].second){
					printf("0\n");return 0;
				}
			}
		}
		printf("1\n");

	}
}


Measured memory_bytes: 13440
using System;
using System.IO;
using System.Linq;
using System.Collections.Generic;
using System.Text;

public class Program
{

	public void Proc()
	{
        const string fes = "FESTIVAL";
        string inpt = Reader.ReadLine();

        string ans = inpt.Substring(0, inpt.Length - fes.Length);
        Console.WriteLine(ans);
        
    }


    public class Reader
	{
		private static StringReader sr;
		public static bool IsDebug = false;
		public static string ReadLine()
		{
			if (IsDebug)
			{
				if (sr == null)
				{
					sr = new StringReader(InputText.Trim());
				}
				return sr.ReadLine();
			}
			else
			{
				return Console.ReadLine();
			}
		}
		private static string InputText = @"






";
	}

	public static void Main(string[] args)
	{
#if DEBUG
		Reader.IsDebug = true;
#endif
		Program prg = new Program();
		prg.Proc();
	}
}


Measured memory_bytes: 13140
#include <iostream>
#include <string>
#include <sstream>
#include <iomanip> 
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <functional>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <bitset>

using namespace std;


int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	int a, b;
	cin >> a >> b;
	if ((a - b) % 2 == 0) cout << (a + b) / 2 << "\n";
	else cout << "IMPOSSIBLE\n";

	return 0;
}


Measured memory_bytes: 256
n=int(input())
l=list(map(int,input().split()))
flag=1
for i in l:
    if i%2==0:
        if i%3==0 or i%5==0:
            continue
        else:
            flag=0
            break
if flag==0:
    print("DENIED")
else:
    print("APPROVED")


Measured memory_bytes: 2940
/*
      HET PAGHADAR
      DA-IICT
      @HET262
*/
 
#include<bits/stdc++.h>
using namespace std;
typedef long double ld;
typedef long long ll;
typedef vector<ll> vec; 
#define inf LLONG_MAX
#define bp __builtin_popcountll
#define pb push_back
#define ff first
#define ss second
#define P pair<ll,ll>
#define N 1000005
#define mod 1000000007
#define FAST ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

int32_t main()
{
      
      FAST;
      
      ll n,m;
      cin>>n>>m;
      
      if(n==m)
            cout<<"Yes";
      else
            cout<<"No";
      
      
}


Measured memory_bytes: 256
h,w = map(int,input().split())
n = int(input())
A = [int(i) for i in input().split()]
dic = {}
for i in range(n):
    dic[i+1] = A[i]

Map = [0 for i in range(h*w)]
height = 0
width = 0
now = 0
color = list(dic.keys())

color_num = 0
while now < h*w:
    if height%2==0:
        Map[now] = color[color_num]
        dic[color[color_num]] -= 1
        if dic[color[color_num]]==0:
            color_num += 1
        width += 1
        if width==w:
            height += 1
            width = w-1
    else:

        Map[now] = color[color_num]
        dic[color[color_num]] -=1
        if dic[color[color_num]]==0:
            color_num += 1
        width -= 1
        if width==-1:
            height += 1
            width = 0
    now = height*w + width
st = 0

for i in range(h):
    print(*Map[st:st+w])
    st = st+w

Measured memory_bytes: 9940
import sys
n = int(input())
s = list(input())
t = list(input())

if s == t:
    print(n)
    sys.exit()
can = False
for i in range(n):
    if s[i:n] == t[0:(n-i)]:
        can = True
        break
if can:
    print(n + i )
else:
    print(2*n)


Measured memory_bytes: 9176
n = int(input())
a = list(map(int,input().split()))
lcm = 1
for i in range(n):
  big,sml = lcm,a[i]
  while sml != 0:
    big,sml = sml,big%sml
  lcm *= a[i] // big
mod = 10 ** 9 + 7
def inv(x):
  y = 1
  while x != 1:
    y *= mod // x + 1
    x -= mod % x
    y %= mod
  return y
ans = 0
for i in range(n):
  ans += inv(a[i])
  ans %= mod
lcm %= mod
ans *= lcm
ans %= mod
print(ans)

Measured memory_bytes: 4084
#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <map>
#include <queue>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using namespace std;

template<class T>
constexpr T INF = ::numeric_limits<T>::max() / 32 * 15 + 208;

int main() {
    ll n, m;
    string s, t;
    cin >> n >> m >> s >> t;
    ll u = __gcd(n, m);
    for (int i = 0; i < u; ++i) {
        if(s[n/u*i] != t[m/u*i]){
            cout << "-1\n";
            return 0;
        }
    }
    cout << n*m / u << "\n";
    return 0;
}


Measured memory_bytes: 512
import std.stdio;
import std.conv;
import std.array;
import std.string;
import std.algorithm;

void main() {
	string S;
	S = chomp(readln());
	string res = "";
	if(S[0] == '9' || S[1] == '9') {
		res = "Yes";
	}
	else{
		res = "No";
	}
	writeln(res);
}


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

using namespace std;

#define ll long long
#define pb push_back
#define vi vector<int>
#define bn(n) (n).begin(), (n).end()
#define FOR(n) for(int i = 0; i < (int)n; i++)


void solve() {
    int a, b, c;
    cin >> a >> b >> c;
    if (b-a == c-b) {
        cout << "YES\n";
    } else {
        cout << "NO\n";
    }

}

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

    int t = 1, i = 1;
    //cin >> t;
    while(t--) {
        //cout << "Case #" << i << ": ";
        solve();
        //i++;
    }
    return 0;
}


Measured memory_bytes: 3656
#include <iostream>
#include <vector>
#include <algorithm>
#include <stdio.h>

using namespace std;

int N, K;

int main(){
	scanf("%d%d", &N, &K);
	if(N%2==0){
		if(K<=N/2){
			printf("YES");
		}else{
			printf("NO");
		}
	}else{
		if(K<=(N+1)/2){
			printf("YES");
		}else{
			printf("NO");
		}
	}
	return 0;
}

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

int main() {
  // ここにプログラムを追記
  int a,b,c,d;
  cin >> a;
  b=a/100;
  c=a/10-10*b;
  d=a-100*b-10*c;
  cout << (b+c+d)%9 << endl;
}


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

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> left, right;
  for (int i = 0; i < m; i++) {
    int l, r;
    cin >> l >> r;
    left.push_back(l);
    right.push_back(r);
  }

  sort(left.rbegin(), left.rend());
  sort(right.begin(), right.end());

  if (left.at(0) <= right.at(0))
  cout << right.at(0) - left.at(0) + 1 << endl;
  else
  cout << 0 << endl;
}


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

int main(){
	int n;
	cin >> n;
	for(int i = 0; i < n; i++){
		int x = 0;
		int y = 0;
		int dx, dy;
		int max_distance = 0;
		int max_x = 0, max_y = 0;
		while(cin >> dx >> dy){
			if(dx == 0 && dy == 0) break;
			x += dx;
			y += dy;
			if(x * x + y * y > max_distance){
				max_x = x;
				max_y = y;
				max_distance = x * x + y * y;
			}else if(x * x + y * y == max_distance && x > max_x){
				max_x = x;
				max_y = y;
			}
		}
		cout << max_x << " " << max_y << endl;
	}
	return 0;
}

Measured memory_bytes: 0
#define _USE_MATH_DEFINES
#include <iostream>
#include <sstream>
#include <cmath>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>

using namespace std;

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

static const double eps = 10e-6;



int main(){
	int n;
	int* primeTable = new int[100001];
	fill((int*)primeTable,(int*)primeTable+100001,1);

	primeTable[0] = 0;
	primeTable[1] = 0;

	for(int i=2;i*i<=100000;i++){
		if(primeTable[i] != 1) continue;
		for(int j=i+i;j<=100000;j+=i){
			primeTable[j] = 0;
		}
	}

	while(~scanf("%d",&n)){
		if(n==0) break;
		for(int i=n;i-2>=0;i--){
			if(primeTable[i] && primeTable[i-2]){
				printf("%d %d\n",i-2,i);
				break;
			}
		}
	}
}

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

int main(){
  long double n,m,d; cin>>n>>m>>d;
  if(d==0){
    long double ans=1/n;
    ans*=(m-1);
    cout<<setprecision(14)<<ans<<endl;
  }else{
    long double sum=2*(n-d);
    long double ans=sum/(n*n);
    ans*=(m-1);
    cout<<setprecision(14)<<ans<<endl;
  }
}

Measured memory_bytes: 384
import Control.Applicative
import Control.Monad
import Data.IntSet (IntSet)
import qualified Data.IntSet as IS

main :: IO ()
main = do
  n <- readLn
  unless (n == 0) $ do
    solve <$> replicateM n f <*> f >>= print
    main
  where
    f = IS.fromList <$> map read <$> tail <$> words <$> getLine

solve :: [IntSet] -> IntSet -> Int
solve cds lk = let cdd = filter f $ zip cds [1..]
               in case cdd of
                   [(_,i)] -> i
                   _ -> (-1)
  where
    f (x, _) = IS.intersection x lk == lk



Measured memory_bytes: 6592
s = input()
t = input()
max = 10**100
now = t[0]
cnt1 = 0
cnt2 = 0

while True:
	temp = s[:]
	if cnt2 == len(t):
		print(cnt1)
		break
	if max == 0:
		print("-1")
		break
	while True:
		num = temp.find(now)
		if num != -1:
			cnt2+=1
			cnt1+=num+1
			#print("num={0}, temp={1}, cnt1={2}, cnt2={3}".format(num, temp, cnt1, cnt2))
			if cnt2 < len(t):
				now = t[cnt2]
			else:
				break
			temp = temp[num+1:]
			continue
		else:
			if temp == s:
				print("-1")
				exit(0)
			else:
				cnt1+=len(temp)
			break
	max-=1


Measured memory_bytes: 3468
package main

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

var sc = bufio.NewScanner(os.Stdin)

func nextInt() int {
        sc.Scan()
        i, e := strconv.Atoi(sc.Text())
        if e != nil {
                panic(e)
        }
        return i
}

func swap(a, b int) (int, int) {
        return b, a
}

func main() {
        sc.Split(bufio.ScanWords)
        n := nextInt()
        var p []int
        for i := 0; i < n; i++ {
                p = append(p, nextInt())
        }

        ans := 0
        for i := 0; i < n-1; i++ {
                if i+1 == p[i] {
                        ans++
                        p[i], p[i+1] = swap(p[i], p[i+1])
                }
        }
        if p[n-1] == n {
                ans++
        }

        fmt.Printf("%d\n", ans)
}

Measured memory_bytes: 6028
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned ll
#define uint unsigned
#define pii pair<int,int>
#define pll pair<ll,ll>
#define PB push_back
#define fi first
#define se second
#define For(i,j,k) for (int i=(int)(j);i<=(int)(k);i++)
#define Rep(i,j,k) for (int i=(int)(j);i>=(int)(k);i--)
#define CLR(a,v) memset(a,v,sizeof(a));
#define CPY(a,b) memcpy(a,b,sizeof(a));
using namespace std;
const int N=300005;
int n,a[N];
pii q[N];
bool check(int k){
	int top=1,S=a[1];
	q[1]=pii(a[1],1);
	For(i,2,n){
		if (S<a[i]){
			q[++top]=pii(a[i]-S,1);
			S=a[i];
			continue;
		}
		for (;S>a[i];){
			int dif=min(q[top].fi,S-a[i]);
			q[top].fi-=dif; S-=dif;
			if (!q[top].fi) --top;
		}
		for (;top&&q[top].se==k;--top)
			S-=q[top].fi;
		if (!top) return 0;
		if (q[top].fi==1) ++q[top].se;
		else{
			q[++top]=pii(1,0);
			q[top-1].fi--;
			q[top].se=q[top-1].se+1;
		}
		if (S<a[i]){
			q[++top]=pii(a[i]-S,1);
			S=a[i];
		}
	}
	return 1;
}
int main(){
	scanf("%d",&n);
	For(i,1,n) scanf("%d",&a[i]);
	int l=1,r=n,ans=0;
	while (l<=r){
		int mid=(l+r)/2;
		if (check(mid))
			ans=mid,r=mid-1;
		else l=mid+1; 
	} 
	printf("%d\n",ans);
} 

Measured memory_bytes: 2560
#include<bits/stdc++.h>
using namespace std;
//const int N=4e5+10;
#define ll long long
//#define d double
#define F first
#define S second
#define FastIO ios_base::sync_with_stdio(false),cin.tie(0)
#define fix std::fixed<<setprecision(10)
#define M 100000007
#define f(n) for(int i=0;i<n;i++)
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define vi vector<int>
#define pb push_back
#define si set<int>
#define cl(n,m) (ceil(double(n)/double(m)))
#define T() int t; cin>>t; while(t--)

#include <bits/stdc++.h>
using namespace std;

int main()
{
    int n;
    cin>>n;
    double arr[n];
    f(n)cin>>arr[i];

    double sum=0;

    f(n)
    {
        sum+=(1/arr[i]);
    }
    sum=1/sum;
    cout<<fix<<sum<<endl;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define repp(i,l,r,k)for(ll i=(l);i<(r);i+=(k))
#define INF ((1LL<<62)-(1LL<<31))
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))
#define bit(n,m)(((n)>>(m))&1)
int upll(const void*a, const void*b){return*(ll*)a<*(ll*)b?-1:*(ll*)a>*(ll*)b?1:0;}
int downll(const void*a, const void*b){return*(ll*)a<*(ll*)b?1:*(ll*)a>*(ll*)b?-1:0;}
void sortup(ll*a,int n){qsort(a,n,sizeof(ll),upll);}
void sortdown(ll*a,int n){qsort(a,n,sizeof(ll),downll);}
ll pom(ll a,ll n,int m){ll x=1;for(a%=m;n;n/=2)n&1?x=x*a%m:0,a=a*a%m;return x;}
//#define MOD 998244353
#define MOD 1000000007
#define invp(a,p)pom(a,p-2,p)

ll cost[210][210];


//辺の情報を個別に持つタイプ
typedef struct edge{ll s,g;}E;
typedef struct graph{
	int vcnt,ecnt;
	E  e[200010];//適宜変える(ecnt)
	int id[100010];//適宜変える(vcnt)
}G;
G g;

int esort(const void*a,const void*b){
	E*p=(E*)a,*q=(E*)b;
	if((*p).s<(*q).s)return -1;
	if((*p).s>(*q).s)return  1;
	if((*p).g<(*q).g)return -1;
	return 1;
}


void readgraph(){
	//適宜変える
	ll n;
	scanf("%lld",&n);
	ll m=0;
	rep(i,0,n){
		char s[210];
		scanf(" %s",s);
		rep(j,0,n){
			if(s[j]=='1'){
				g.e[m].s=i;
				g.e[m].g=j;
				m++;
				cost[i][j]=1;
			}else{
				cost[i][j]=i==j?0:INF;
			}
		}
	}

	g.vcnt=n;
	g.ecnt=m;
	qsort(g.e,g.ecnt,sizeof(E),esort);

	int p=0;
	rep(i,0,g.vcnt){
		while(p<g.ecnt&&g.e[p].s<i)p++;
		g.id[i]=p;
	}
	g.id[g.vcnt]=g.ecnt;//番兵
}


int co[210];
//dfs
int dfs(int v,int pre,int k){
	if(co[v])return co[v]==k;
	co[v]=k;
	rep(i,g.id[v],g.id[v+1]){
		if(g.e[i].g!=pre){
			if(!dfs(g.e[i].g,v,k^3))return 0;
		}
	}
	return 1;
}


//ワーシャルフロイド
//頂点数（と隣接行列）を引いて全点間最短距離を返す
//O(V^3)
//*
ll dddd[210][210];
void waasharuhuroido(ll n){
	rep(i,0,n)rep(j,0,n)dddd[i][j]=cost[i][j];//辺が無いところはINFにする前処理が必要
	rep(k,0,n)rep(i,0,n)rep(j,0,n)dddd[i][j]=min(dddd[i][j],dddd[i][k]+dddd[k][j]);
}

int main(){
	readgraph();
	if(!dfs(0,-1,1)){
		puts("-1");
		return 0;
	}
	ll n=g.vcnt;
	waasharuhuroido(n);
	ll ans=0;
	rep(i,0,n)rep(j,0,n)if(dddd[i][j]!=INF)ans=max(ans,dddd[i][j]);
	printf("%lld",ans+1);
}

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

int main(void){
	int n,x, count = 0;

	while (true){
		cin >> n >> x;

		if (n == 0 && x == 0) break;

		count = 0;
		for (int i = 1; i < n-1; i++){
			for (int j = i + 1; j < n; j++){
				for (int k = j + 1; k < n+1; k++){
					if (i + j + k == x)
						count++;
				}
			}
		}

		cout << count << "\n";
	}

	return 0;
}

Measured memory_bytes: 1160
#include<cstdio>
#include<cstring>
#include<utility>
#include<set>
using namespace std;
typedef pair<int,int> p;
set<p> map;
long long num[10];
int h,w,n,a,b;
int count(int x,int y)
{
    int num=0;
    for (int i = -1; i <= 1; i++)
    {
        for (int j = -1; j <= 1; j++)
        {
            int nx=x+i,ny=y+j;
            if(0<nx&&nx<=h&&0<ny&&ny<=w)
            {
                if(map.count(p(nx,ny)))
                    num++;
            }
            else
                return 0;
        }
    }
    return num;
}
void check(int x,int y)
{
    for (int i = -1; i <= 1; i++)
    {
        for (int j = -1; j <= 1; j++)
        {
            int temp=count(x+i,y+j);
            if(temp)
            {
                num[temp-1]--;
                num[temp]++;
            }
        }
    }
}
int main()
{
    scanf("%d%d%d",&h,&w,&n);
    num[0]=(long long)(h-2)*(w-2);
    while (n--)
    {
        scanf("%d%d",&a,&b);
        map.insert(p(a,b));
        check(a,b);
    }
    for (int i = 0; i < 9; i++)
        printf("%lld\n",num[i]);
    printf("%lld",num[9]);
}

Measured memory_bytes: 5248
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using V = vector<int>;
using VV = vector<V>;
using VVV = vector<VV>;
using VL = vector<ll>;
using VVL = vector<VL>;
using VVVL = vector<VVL>;
template<class T> using VE = vector<T>;
template<class T> using P = pair<T, T>;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define REP(i,k,n) for(int i=(k);i<(n);i++)
#define all(a) (a).begin(),(a).end()
#define output(x,y) cout << fixed << setprecision(y) << x << endl;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
// const ll MOD = 1e9 + 7;
const ll MOD = 998244353;
ll upper = MOD + MOD;
ll under = -upper;
ll UPPER = MOD * MOD;
ll UNDER = -UPPER;
const long double pi = 3.141592653589793;
int main() {
	ll n, w;
	cin >> n >> w;
	VL w1, w2, w3, w4;
	ll Base;
	rep(i, n) {
		int a, b;
		cin >> a >> b;
		if (i == 0) {
			Base = a;
			w1.push_back(b);
		}
		else {
			if (a - Base == 0) w1.push_back(b);
			if (a - Base == 1) w2.push_back(b);
			if (a - Base == 2) w3.push_back(b);
			if (a - Base == 3) w4.push_back(b);
		}
	}
	ll ans = 0;
	sort(all(w1), greater<ll>()); sort(all(w2), greater<ll>()); sort(all(w3), greater<ll>()); sort(all(w4), greater<ll>());
	w1.insert(w1.begin(), 0); w2.insert(w2.begin(), 0); w3.insert(w3.begin(), 0); w4.insert(w4.begin(), 0);
	rep1(i, w1.size() - 1) w1[i] += w1[i - 1];
	rep1(i, w2.size() - 1) w2[i] += w2[i - 1];
	rep1(i, w3.size() - 1) w3[i] += w3[i - 1];
	rep1(i, w4.size() - 1) w4[i] += w4[i - 1];
	rep(i, w1.size()) rep(j, w2.size()) rep(k, w3.size()) rep(l, w4.size()) {
		ll W = i * Base + j * (Base + 1) + k * (Base + 2) + l * (Base + 3);
		if (W > w) continue;
		ll tmp = w1[i] + w2[j] + w3[k] + w4[l];
		chmax(ans, tmp);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3596
num_inputs = int(input())
array = input().split(' ')
flag = True
count = 0

while flag:
    flag = False
    for i in reversed(range(1, num_inputs)):
        if int(array[i]) < int(array[i - 1]):
            buf = array[i]
            array[i] = array[i - 1]
            array[i - 1] = buf
            count += 1
            flag = True

print(' '.join(array))
print(str(count))


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

#define int long long

int32_t main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	
	int x;
	cin >> x;
	double y = 100;
	for(int i = 1; ; i++) {
		double temp = y*1.01;
		temp = (int)temp;
		if(temp >= x) {
			cout << i << '\n';
			return 0;
		}
		y = temp;
	}
				
	return 0;
}


Measured memory_bytes: 3640
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n)  for(int i=0;i<n;++i)
#define sc1(a)  scanf("%d",&a)
#define sc2(a,b)  scanf("%d %d",&a,&b)
int main(){
    vector <int> d(6);
    vector <int> a(6);
    for(auto&e:d) sc1(e);
    for(auto&e:a) sc1(e);
    char s[8]={'N','W','E','E','E','N','N','N'};
    rep(i,8) {
        int tmp,tmp2;
        if (s[i]=='N') {
            tmp=d[0];
            d[0]=d[1];
            d[1]=d[5];
            d[5]=d[4];
            d[4]=tmp;
        } else if (s[i]=='W') {
            tmp=d[0];
            d[0]=d[2];
            d[2]=d[5];
            d[5]=d[3];
            d[3]=tmp;
        } else if (s[i]=='E') {
            tmp=d[0];
            d[0]=d[3];
            d[3]=d[5];
            d[5]=d[2];
            d[2]=tmp;
        } else {
            tmp=d[0];
            d[0]=d[4];
            d[4]=d[5];
            d[5]=d[1];
            d[1]=tmp;
        }
        rep(j,4) {
            tmp2=d[1];
            d[1]=d[2];
            d[2]=d[4];
            d[4]=d[3];
            d[3]=tmp2;
            int f=1;
            rep(k,6) if (a[k]!=d[k]) f=0;
            if (f) {
                printf("Yes\n");
                return 0;
            }
        }
    }
    printf("No\n");
    return 0;
}



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

string s;
int k;

int main() {
    cin.sync_with_stdio(0); cin.tie(0);
    cin >> s >> k;
    set<string> substrings;
    vector<string> a;
    for (int i = 0; i < (int)s.size(); i++) {
        a.push_back(s.substr(i, s.size() - i));
    }

    sort(a.begin(), a.end());
    for (auto& i : a) {
        for (int j = 1; substrings.size() < k && j <= s.size(); j++) {
            substrings.insert(i.substr(0, j));
        }
    }

    auto it = substrings.begin();
    int num = 1;
    while (num < k) {
        num++;
        it++;
    }
    cout << *it;
}



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

using pii = pair<int, int>;

int main()
{
  int n, m;
  vector<pii> bridges;
  cin >> n >> m;
  int a, b;
  for (int i = 0; i < m; ++i)
  {
    cin >> a >> b;
    bridges.push_back(pii(b - 1, a - 1));
  }
  // end でソート
  sort(bridges.begin(), bridges.end());

  vector<int> bps; // break points
  for (auto bridge : bridges)
  {
    bool needBreak = true;
    for (auto p : bps)
    {
      if (bridge.second < p && p <= bridge.first)
      {
        needBreak = false;
        break;
      }
    }
    // 破壊ポイントにかぶっていない場合は壊す
    if (needBreak)
    {
      bps.push_back(bridge.first);
    }
  }
  cout << bps.size() << endl;
  return 0;
}

Measured memory_bytes: 1400
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include<cstdio>

using namespace std;

#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);i--)
#define pb push_back
#define pf push_front

typedef vector<int> vi;
typedef vector<string> vs;
typedef long long ll;
typedef vector<ll> vll;

ll gcd(ll x, ll y) {
	ll r;
	while ((r = x % y) != 0) {
		x = y;
		y = r;
	}
	return y;
}
ll lcm(ll x, ll y) {
	x /= gcd(x, y);
	y /= gcd(x, y);
	return (x*y);
}

int main()
{
	int w, a, b;
	cin >> w >> a >> b;
	if ((max(a, b) - (min(a, b) + w)) < 0) cout << 0;
	else cout << (max(a, b) - (min(a, b) + w));
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <cmath>
#include <limits>
#include <climits>
#include <utility>
#include <algorithm>
#include <numeric>
#include <sstream>

using namespace std;

using ll = long long;
using ull = unsigned long long;

int main()
{
    string x;
    cin >> x;

    int A = x[0] - '0';
    int B = x[1] - '0';
    int C = x[2] - '0';
    int D = x[3] - '0';

    for (int i = 0; i < 8; ++i) {
        int x = A;
        stringstream ans;
        ans << A;

        if (i & (1 << 0)) {
            x += B;
            ans << "+" << B;
        } else {
            x -= B;
            ans << "-" << B;
        }

        if (i & (1 << 1)) {
            x += C;
            ans << "+" << C;
        } else {
            x -= C;
            ans << "-" << C;
        }

        if (i & (1 << 2)) {
            x += D;
            ans << "+" << D;
        } else {
            x -= D;
            ans << "-" << D;
        }

        ans << "=7";

        if (x == 7) {
            cout << ans.str() << endl;
            return 0;
        }
    }

    cout << A << '+' << B << '+' << C << '+' << D << "=7" << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cstdio>
#define f first
#define s second
 
using namespace std;
 
pair <int, pair <int, int> > q[2000001];
int n, m, a[1000001], ans[2000001];
int st[5*1000001], used[10000001];
int cmp(pair <int, pair <int, int> > a, pair <int, pair <int, int> > b)
{
    if (a.s.f != b.s.f)
        return a.s.f < b.s.f;
    return a.f < b.f;
}
void update(int v, int l, int r, int x, int d)
{
    if (l == r)
    {
        st[v] = d;
        return;
    }
    int mid = (l + r) / 2;
    if (x <= mid)
        update(v * 2, l, mid, x, d);
    else
        update(v * 2 + 1, mid + 1, r, x, d);
    st[v] = st[v * 2] + st[v * 2 + 1];
}
int Find(int v, int A, int B, int l, int r)
{
    if (l > B || r < A)
        return 0;
    if (A == l && B == r)
        return st[v];
    int mid = (A + B) / 2;
    return Find(v * 2, A, mid, l, min(mid, r)) + Find(v * 2 + 1, mid + 1, B, max(mid + 1, l), r);
}
 
int main()
{
    scanf("%d", &n);
    scanf("%d", &m);
    for (int i = 1; i <= n; i++)
        scanf("%d", &a[i]);
    //scanf("%d", &m);
    for (int i = 1; i <= m; i++)
        scanf("%d %d", &q[i].f, &q[i].s.f), q[i].s.s = i;
    sort(q + 1, q + m + 1, cmp);
    int j = 1;
    for (int i = 1; i <= m; i++)
    {
        while(j <= q[i].s.f)
        {
            if (!used[a[j]])
            {
                update(1, 1, n, j, 1);
                used[a[j]] = j;
            }
            else
            {
                update(1, 1, n, used[a[j]], 0);
                update(1, 1, n, j, 1);
                used[a[j]] = j;
            }
            j++;
        }
        ans[q[i].s.s] = Find(1, 1, n, q[i].f, q[i].s.f);
    }
    for (int i = 1; i <= m; i++)
        printf("%d\n", ans[i]);
 
    return 0;
}

Measured memory_bytes: 19628
#include <bits/stdc++.h>
#define debug(x) cerr << #x << ": " << x << '\n';
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = (int)1e9;
const int MOD = (int)1e9 + 7;

int N, M;
vector<int> g[8];

int main(void){
    cin >> N >> M;
    for(int i = 0; i < M; i++){
        int a, b;
        cin >> a >> b;
        g[--a].push_back(--b);
        g[b].push_back(a);
    }

    int ar[8];
    ar[0] = 0;
    for(int i = 1; i < N; i++) ar[i] = i;

    int res = 0;
    do{
        int flag = true;
        for(int i = 0; i < N-1; i++){
            // debug(count(g[ar[i]].begin(), g[ar[i]].end(), ar[i+1]));
            if(count(g[ar[i]].begin(), g[ar[i]].end(), ar[i+1]) == 0) flag = false;
        }

        if(flag) res++;
    }while(next_permutation(ar+1, ar+N));

    cout << res << '\n';

    return 0;
}

Measured memory_bytes: 256