akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define Nmax 51
#define ll long long

using namespace std;

const long long INF=1e18l+2;
const ll MOD = 1e9+7;

ifstream f("1.in");

ll a[Nmax][Nmax];
ll r[Nmax][Nmax];
ll r_[Nmax][Nmax];

int main()
{
    ll n, k;
    cin >> n >> k;
    for (int i = 1; i <= n; i++)
    {
        r[i][i]=1;
        for (int j = 1; j <= n; j++)
            cin >> a[i][j];
    }

    while(k)
    {
        if(k&1)
        {
            for (int i = 1; i <= n; i++)
                for (int j = 1; j <= n; j++)
                {
                    r_[i][j]=0;
                    for (int k = 1; k <= n; k++)
                        (r_[i][j] += r[i][k]*a[k][j]) %= MOD;

                }
            for (int i = 1; i <= n; i++)
                for (int j = 1; j <= n; j++)
                     r[i][j] = r_[i][j];
        }

        for (int i = 1; i <= n; i++)
            for (int j = 1; j <= n; j++)
            {
                r_[i][j]=0;
                for (int k = 1; k <= n; k++)
                 (r_[i][j] += a[i][k]*a[k][j]) %= MOD;

            }
        for (int i = 1; i <= n; i++)
            for (int j = 1; j <= n; j++)
                a[i][j]=r_[i][j];

        k >>= 1;
    }

    ll s=0;
    for (int i = 1; i <= n; i++)
    {
        for (int j = 1; j <= n; j++)
            s=(s+r[i][j])%MOD;
    }
    cout << s;

    return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#define N 505
#include<queue>
using namespace std;
int n;
bool b[N*N];
int dis[N*N];
int que[N*N], ql, qr;
void bfs(int x){
	que[ql=qr=1]=x;
	while(ql<=qr){
		int u = que[ql++];
		int i=u/n, j=u%n;
		if(i>0 && dis[u-n]>dis[u]+b[u]) dis[u-n]=dis[u]+b[u], que[++qr] = u-n;
		if(j>0 && dis[u-1]>dis[u]+b[u]) dis[u-1]=dis[u]+b[u], que[++qr] = u-1;
		if(i<n-1 && dis[u+n]>dis[u]+b[u]) dis[u+n]=dis[u]+b[u], que[++qr] = u+n;
		if(j<n-1 && dis[u+1]>dis[u]+b[u]) dis[u+1]=dis[u]+b[u], que[++qr] = u+1;
	}
}
int main(){
	scanf("%d", &n);
	for(int x=0; x<n*n; ++x){
		b[x] = true;
		int i=x/n, j=x%n;
		dis[x] = min(min(i, j), min(n-i-1, n-j-1));
	}
	int ans=0, x;
	for(int r=1; r<=n*n; ++r){
		scanf("%d", &x);
		--x;
		ans+=dis[x];
		b[x] = false;
		//printf("%d ", dis[x]);
		bfs(x);
	}
	printf("%d", ans);
	return 0;
}

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

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

  if (m % 2 == 0) {
    for (int i = 0; i < m; i++) {
      if (i < m / 2) {
        cout << 1 + i << " " << m - i << endl;
      }
      else {
        cout << m + 1 + i - m / 2 << " " << 2 * m + 1 - i + m / 2 << endl;
      }
    }
  }
  else {
    for (int i = 0; i < m; i++) {
      if (i < (m+1) / 2) {
        cout << 1 + i << " " << m + 1 - i << endl;
      }
      else {
        cout << m + 2 + i - (m+1)/2 << " " << 2 * m + 1 - i + (m+1)/2 << endl;
      }
    }
  }

  return 0;
}

Measured memory_bytes: 3644
# coding: utf-8
# Your code here!
def kaibun(s):
    n = len(s)
    if n%2==0:
        s1 = s[:n//2]
        s2 = s[n//2:]
    else:
        s1 = s[:(n-1)//2]
        s2 = s[((n-1)//2)+1:]
    
    m = len(s1)
    for i in range(m):
        if s1[i]!=s2[m-i-1]:
            return False
    return True
    
S = input()
N = len(S)
S1 = S[:(N-1)//2]
S2 = S[(N+3)//2-1:]

b1 = kaibun(S)
b2 = kaibun(S1)
b3 = kaibun(S2)

if b1 and b2 and b3:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3064
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <functional>
#include <utility>
#include <tuple>
#include <cctype>
#include <bitset>
#include <complex>
#include <cmath>
#include <array>
#include <numeric>
using namespace std;
#define INF 0x3f3f3f3f
#define INFLL 0x3f3f3f3f3f3f3f3fLL
//#define MOD 998244353
#define MOD 1000000007
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pint;
typedef pair<ll,ll> pll;
typedef tuple<int,int,int> tint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<ull> vull;
typedef vector<pint> vpint;
int dx[8]={0,0,-1,1,1,1,-1,-1};
int dy[8]={-1,1,0,0,1,-1,1,-1};
const int SIZE=85;
//↑templete
bool isPrime(int a){
	for(int i=2;i*i<=a;i++)
		if(a%i==0)
			return 0;
	return 1;
}
signed main(){
	int X;
	cin>>X;
	for(int i=X;1;i++)
		if(isPrime(i)){
			cout<<i<<endl;
			return 0;
		}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <string>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <math.h>
#include <vector>
#include <algorithm>
#include <queue>
#include <stack>
#include <climits>
#include <bitset>
#include <list>
#include <map>
#include <set>

using namespace std;

typedef unsigned long long ull;
typedef long long ll;

int main(){
	string s;
	bool b=true;
	cin >> s;
	for(int i=0; i<3; i++){
		if(s[i]==s[i+1]) b=false;
	}
	if(b) cout << "Good" << endl;
	else cout << "Bad" << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
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; }
int main(){
    int n;
    cin>>n;
    vector<int>l(n),r(n);
    for(int i=0;i<n;i++)cin>>l.at(i);
    for(int i=0;i<n;i++)cin>>r.at(i);
    for(int i=1;i<n;i++)l.at(i)+=l.at(i-1);
    for(int i=n-1;i>=1;i--)r.at(i-1)+=r.at(i);
    int ans=0;
    for(int i=0;i<n;i++)chmax(ans,l.at(i)+r.at(i));
    cout<<ans<<endl;
    
}

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

#define fi first
#define se second
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb(s) push_back(s)
#define mp(a,b) make_pair(a,b)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define maxch(x,y) x=max(x,y)
#define minch(x,y) x=min(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt(x) bitset<32>(x).count()

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<P, int> PPI;
typedef pair<ll, ll> PL;
typedef pair<P, ll> PPL;

#define INF INT_MAX/3

#define MAX_N 1000

ll n;
ll a[111111];

ll allsum=0,sum;

int main(){
	cin.sync_with_stdio(false);
	cin>>n;
	sum=(n+1)*n/2;
	rep(i,n){
		cin>>a[i];
		allsum+=a[i];
	}
	if(allsum%sum!=0){
		cout<<"NO"<<endl;
		return 0;
	}
	ll k=allsum/sum;
	rep(i,n){
		ll d=a[(i+1)%n]-a[i];
		if((k-d)%n!=0){
			cout<<"NO"<<endl;
			return 0;
		}
		if((k-d)/n<0||(k-d)/n>k){
			cout<<"NO"<<endl;
			return 0;
		}
	}
	cout<<"YES"<<endl;
	return 0;
}


Measured memory_bytes: 1152
#include<bits/stdc++.h>
using namespace std;
const int N=1e4+5;
int a[N],b[N];
int main()
{
    int n;
    cin>>n;
    for(int i=0; i<n; i++)
        cin>>a[i];
    long long s=0;
    for(int i=0; i<n; i++)
        cin>>b[i];
    for(int i=0; i<n; i++)
    {
        if(a[i]>b[i])
            s-=a[i]-b[i];
        else s+=(b[i]-a[i])/2;
    }
    if(s>=0)
        printf("Yes\n");
    else printf("No\n");
    //cout<<s<<endl;
    return 0;
}


Measured memory_bytes: 384
#include <stdio.h>

int max(int a,int b){
  if(a > b){
    return a;
  }
  return b;
}

int min(int a,int b){
  if(a < b){
    return a;
  }
  return b;
}

int main(void){
  int W,H,N;
  scanf("%d%d%d",&W,&H,&N);

  int xmax = W,xmin = 0;
  int ymax = H,ymin = 0;
  int x,y,a;
  for(int i = 0;i < N;i++){
    scanf("%d%d%d",&x,&y,&a);
    switch(a){
      case 1:
        xmin = max(xmin,x);
        break;
      case 2:
        xmax = min(xmax,x);
        break;
      case 3:
        ymin = max(ymin,y);
        break;
      case 4:
        ymax = min(ymax,y);
        break;
    }
  }

  printf("%d\n",max(0,(xmax-xmin))*max(0,(ymax-ymin)));

  return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <cstdio>
using namespace std;
const int N = 1e5+10 ; 
int n,l,t,x[N],w[N],y[N] ; long long c ; 
int main(){
//	freopen("in.txt","r",stdin) ; 
	cin >> n >> l >> t ;
	for(int i = 1 ; i <= n ; i++) scanf("%d%d",&x[i],&w[i]) ;
	for(int i = 1 ; i <= n ; i++){
		int r ;
		if(w[i] == 2) w[i] = -1 ;
		r = x[i]+w[i]*t ;
		if(r > 0) (c += r/l)%=n ;
		else if(r < 0) (c += (r+1)/l-1)%=n ;
		y[i] = (r%l+l)%l ; 
	}
	sort(y+1,y+n+1) ; 
	c = (c%n+n)%n ;
	for(int i = c+1 ; i <= n ; i++) printf("%d\n",y[i]) ;
	for(int i = 1 ; i <= c ; i++) printf("%d\n",y[i]) ; 
	return 0; 
}


Measured memory_bytes: 4416
#include <cstdio>
#include <algorithm>
#include <set>

using namespace std;

int n,m;
int map[501][501];

main(){
  fill((int*)map, (int*)(map+sizeof(map)/sizeof(*map)), 0);

  scanf("%d%d", &n, &m);

  if(n==0 && m == 0) return 0;

  int a,b;
  while(m--){
    scanf("%d%d", &a, &b);
    map[a][b] = 1;
    map[b][a] = 1;
  }

  set<int> s;
  for(int i=0;i<501;i++){
    if(map[1][i]){
      s.insert(i);
      for(int j=0;j<501;j++){
	if(map[i][j]){
	  s.insert(j);
	}
      }
    }
  }

  if(s.size())  printf("%d\n", (int)s.size()-1);
  else puts("0");

  main();
}

Measured memory_bytes: 0
#include <iostream>

#define SIZE 100
#define INF  100000

typedef long long ll;

ll n;
ll a[SIZE];
ll total, avg, avg1;
ll ans, ans1;

ll solve() {
    avg  = total / n;
    avg1 = (total / n) + 1;
    for (ll i=0; i<n; ++i) {
        ans  += (avg  - a[i]) * (avg  - a[i]);
        ans1 += (avg1 - a[i]) * (avg1 - a[i]);
    }
    return std::min(ans, ans1);
}

int main() {
    std::cin >> n;
    for (ll i=0; i<n; ++i) {
        std::cin >> a[i];
        total += a[i];
    }
    std::cout << solve() << std::endl;
    return 0;
}

Measured memory_bytes: 256
n,m = map(int,input().split())
dum = [[] for i in range(n)]
for i in range(m):
    a,b = map(int,input().split())
    dum[a-1].append(b-1)
for i in dum[0]:
    if dum[i].count(n-1) >= 1:
        print("POSSIBLE")
        exit()
print("IMPOSSIBLE")

Measured memory_bytes: 29068
#include <stdio.h>
#include <math.h>
int main(){
  int a,b,c,s,ans;
  scanf("%d%d%d",&a,&b,&c);
 s = (a+b+c)/2;
  ans =sqrt(s*(s-a)*(s-b)*(s-c));
  printf("%d\n",ans);
}

Measured memory_bytes: 128
#include<stdio.h>

int bl[10];

int solve(int b,int c,int i){
  if(i==9) return 1;
  if(b<bl[i+1]&&solve(bl[i+1],c,i+1))
    return 1;
  if(c<bl[i+1]&&solve(b,bl[i+1],i+1))
    return 1;
  return 0;
}
int main(){
  int i,n;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d %d %d %d %d %d %d %d %d %d",
	  bl,bl+1,bl+2,bl+3,bl+4,bl+5,bl+6,bl+7,bl+8,bl+9);
    printf("%s\n",solve(bl[0],0,1)?"YES":"NO");
  }
  return 0;
}

Measured memory_bytes: 0
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.IO.Compression;
using System.Linq;
using System.Text;

namespace Atcoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var NK = Console.ReadLine().Split().Select(long.Parse).ToArray();
            var zan = NK[0] % NK[1];
            var ret = Math.Min(zan, Math.Abs(zan - NK[1]));
            if (NK[1] == 1)
            {
                Console.WriteLine("0");
                return;
            }
            
            Console.WriteLine(ret);
        }
    }
}

Measured memory_bytes: 11348
#include <iostream>
#include <string>
#include <cstring>
#include <fstream>
#include <cmath>
#include <iomanip>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <map>
#include <deque>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <list>
#include <unordered_map>

using namespace std;
struct Node{
    long long num,pre,year;
    bool operator<(const Node &right) const {
        return pre == right.pre ? year < right.year : pre < right.pre;
    }

};
bool asc1( const Node& left, const Node& right ) {
    return left.pre == right.pre ? left.year < right.year : left.pre < right.pre;
}
bool asc2( const Node& left, const Node& right ) {
    return left.num < right.num;
}

int main() {
    

    long long n,m;
    cin >> n >> m;
    static const long long M = m;
    Node prob[M];
    for (long i=0;i<m;i++){
        Node x;
        long long p,y;
        cin >> p >> y;
        x.num = i+1;
        x.pre = p;
        x.year = y;
        prob[i] = x;
    }
    sort(prob,prob+M,asc1);
    long order = 1;
    for (long i=0;i<m;i++){
        if(i==0){
            prob[i].year = order;
        }else{
            if(prob[i-1].pre == prob[i].pre){
                order++;
            }else{
                order = 1;
            }
            prob[i].year = order;
        }
    }
    sort(prob,prob+M,asc2);
    for (long i=0;i<m;i++){
        cout << setfill('0') << right << setw(6) << prob[i].pre;
        cout << setfill('0') << right << setw(6) << prob[i].year;
        cout << endl;
    }
}

Measured memory_bytes: 3840
#include <iostream>
#include <vector>
#include <iomanip>
#include <cmath>
using namespace  std;

struct StPnt
{
  double m_nx;
  double m_ny;

  StPnt() :
    m_nx(0), m_ny(0)
  { }
  StPnt(double nx, double ny) :
    m_nx(nx), m_ny(ny)
  { }

  ~StPnt() { }
};

void fnInput(int &rnRcSiz)
{
  cin >> rnRcSiz;
}

void fnKochCrv( const StPnt &cnroPnt1, const StPnt &cnroPnt2, vector<StPnt> &rvoRtnPnt)
{
  const double PI = 3.141592;

  StPnt aoPnt[5];
  aoPnt[0] = cnroPnt1;
  aoPnt[1].m_nx = (2 * cnroPnt1.m_nx + cnroPnt2.m_nx) / 3;
  aoPnt[1].m_ny = (2 * cnroPnt1.m_ny + cnroPnt2.m_ny) / 3;
  aoPnt[3].m_nx = (cnroPnt1.m_nx + 2 * cnroPnt2.m_nx) / 3;
  aoPnt[3].m_ny = (cnroPnt1.m_ny + 2 * cnroPnt2.m_ny) / 3;

  double nRad = 60 * PI / 180; 
  aoPnt[2].m_nx = (aoPnt[3].m_nx - aoPnt[1].m_nx) * cos(nRad) - (aoPnt[3].m_ny - aoPnt[1].m_ny) * sin(nRad);
  aoPnt[2].m_nx += aoPnt[1].m_nx;
  aoPnt[2].m_ny = (aoPnt[3].m_nx - aoPnt[1].m_nx) * sin(nRad) + (aoPnt[3].m_ny - aoPnt[1].m_ny) * cos(nRad);
  aoPnt[2].m_ny += aoPnt[1].m_ny;

  aoPnt[4] = cnroPnt2;

  for (int i = 0; i < 5; i++)
    rvoRtnPnt.push_back(aoPnt[i]);
}

void fnKochCtl(int nRcSiz, vector<vector<StPnt>> &rvvoPnt)
{
  StPnt oPntB(0.0, 0.0);
  StPnt oPntE(100.0, 0.0);

  rvvoPnt.resize(7);
  rvvoPnt[0].clear();
  rvvoPnt[0].push_back(oPntB);
  rvvoPnt[0].push_back(oPntE);

  for (int nRc = 0; nRc < nRcSiz; nRc++)
  {
    rvvoPnt[nRc + 1].clear();
    rvvoPnt[nRc + 1].push_back(oPntB);
    for (int i = 0; i < rvvoPnt[nRc].size() - 1; i++)
    {
      StPnt oPnt1 = rvvoPnt[nRc][i];
      StPnt oPnt2 = rvvoPnt[nRc][i + 1];
      vector<StPnt> voRtnPnt;

      fnKochCrv(oPnt1, oPnt2, voRtnPnt);
      for (int j = 1; j < 5; j++)
        rvvoPnt[nRc + 1].push_back(voRtnPnt[j]);
    }
  }
}

void fnResult(int nRcSiz, const vector<vector<StPnt>> &cnrvvoPnt)
{
  for (int i = 0; i < cnrvvoPnt[nRcSiz].size(); i++)
    cout << cnrvvoPnt[nRcSiz][i].m_nx << " " << cnrvvoPnt[nRcSiz][i].m_ny << endl;
}

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(8);

  int nRcSiz;
  vector<vector<StPnt>> vvoPnt;

  fnInput(nRcSiz);
  fnKochCtl(nRcSiz, vvoPnt);

  fnResult(nRcSiz, vvoPnt);

  return 0;
}

Measured memory_bytes: 1392
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(), (x).end()
using namespace std;
using str = string;
using ll = long long;
using vi = vector<int>;
using vii = vector<vi>;

int main() {
    str S;
    cin >> S;
    int N = S.size();

    ll ans = 0;
    for(int bit = 0; bit < (1 << N); bit++) {
        ll st = 0;
        for(int i = 0; i < N; i++) {
            if(bit & (1 << i)) {
                st = st*10 + (S[i]-'0');
            }
            else {
            ans += st;
            st = 0;
            }
        }
        ans += st;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3604
using System;
using System.Linq;

namespace ITP1_6_A
{
    class Program
    {
        static void Main(string[] args)
        {
            byte n = byte.Parse(Console.ReadLine());
            if (0 < n && n <= 100)
            {
                int[] data = new int[n];
                data = Console.ReadLine().Split(' ').Select(x => Convert.ToInt32(x)).ToArray();
                for (int i = n - 1; i >= 0; i--)
                {
                    Console.Write(data[i]);
                    if (i != 0) Console.Write(" ");
                }                
                Console.WriteLine();                    
            }           
        }
    }
}

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

int MAX_N=262144*2;
vector<int64_t> seg(MAX_N*2-1);
int64_t qu(int a,int b,int k,int l, int r){
  if(r<=a||b<=l){
    return 0;
  }
  else if(a<=l&&r<=b){
    return seg[k];
  }
  else{
    int64_t X=qu(a,b,k*2+1,l,(l+r)/2);
    int64_t Y=qu(a,b,k*2+2,(l+r)/2,r);
    return X+Y;
  }
}
void pu(int64_t a,int b){
  int D=MAX_N-1+b;
  while(D>0){
    seg[D]+=a;
    D--;
    D/=2;
  }
  seg[0]+=a;
}
int main() {
  int N,Q;
  cin>>N>>Q;
  for(int i=0;i<N;i++){
    int64_t a;
    cin>>a;
    pu(a,i);
  }
  for(int i=0;i<Q;i++){
    int64_t a,b,c;
    cin>>a>>b>>c;
    if(a){
      cout<<qu(b,c,0,0,MAX_N)<<endl;
    }
    else{
      pu(c,b);
    }
  }
}

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

int main() {
	long long n;
	vector<long long> da(5);
	cin >> n;
	for (int i = 0;i < 5;i++) {
		cin >> da[i];
	}
	long long m = 1000000000000001;
	for (int i = 0;i < 5;i++) {
		m = min(m, da[i]);
	}
	//cout << m << endl;
	cout << (m + n - 1) / m + 4 << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cassert>
#include <iostream>
#include <iomanip>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <bitset>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> Pll;
typedef pair<int, int> Pii;

const ll MOD = 1000000007;
const long double EPS = 1e-10;
const int dyx[4][2] = {
    { 0, 1}, {-1, 0}, {0,-1}, {1, 0}
};

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

    bool increased = false, decreased = false;
    int ans = 1;
    for(int i=1;i<n;++i) {
        if(a[i-1] < a[i]) {
            increased = true;
        } else if(a[i-1] > a[i]) {
            decreased = true;
        }

        if(increased && decreased) {
            ++ans;
            increased = false;
            decreased = false;
        }
    }

    cout << ans << endl;
}


Measured memory_bytes: 640
#include"iostream"
#include"cmath"
#include"vector"
#include"algorithm"
#include"list"
#include"set"
#include"unordered_set"
#include"map"
#include"unordered_map"
#include"string"
#include"cstring"
#include"iomanip"
using namespace std;
typedef long long ll;
ll a[450],c[4];
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n,w;cin>>n>>w;
    ll bas,v;cin>>bas>>v;
    a[0]=v;c[0]++;
    for(int i=0;i<n-1;++i)
    {
        ll x,y;cin>>x>>y;
        x-=bas;
        a[x*100+c[x]]=y;
        c[x]++;
    }
    sort(a,a+c[0],greater<ll>());sort(a+100,a+100+c[1],greater<ll>());
    sort(a+200,a+200+c[2],greater<ll>());sort(a+300,a+300+c[3],greater<ll>());
    int sa=0,sb=0,sd=0,se=0;
    ll ans=0;
    for(int a1=0;a1<=c[0];++a1)
    {
        if(a1!=0)sa+=a[a1-1];
        sb=0;
        for(int b=0;b<=c[1];++b)
        {
            if(b!=0)sb+=a[100+b-1];
            sd=0;
            for(int d=0;d<=c[2];++d)
            {
                if(d!=0)sd+=a[200+d-1];
                se=0;
                for(int e=0;e<=c[3];++e)
                {
                    if(e!=0)se+=a[300+e-1];
                    ll sum=sa+sb+sd+se;
                    ll s2=bas*(a1)+(bas+1)*(b)+(bas+2)*(d)+(bas+3)*(e);
                    if(s2<=w)
                        ans=max(ans,sum);
                }
            }
        }
    }
    cout<<ans<<'\n';
}





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

namespace ConsoleApp2
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine(Console.ReadLine().Split(' ').Select(w => int.Parse(w)).Aggregate((n, m) => (n == 2 || m == 2 ? 0 : ((n == 4 || n == 6 || n == 9 || n == 11) ? ((m == 4 || m == 6 || m == 9 || m == 11) ? 1 : 0) : ((m == 4 || m == 6 || m == 9 || m == 11) ? 0 : 1)))) == 0 ? "No" : "Yes");
        }
    }
}


Measured memory_bytes: 11348
# ABC 127 c
n, m = [int(el) for el in input().split(' ')]
max_l = 0
min_r = n
for i in range(m):
    l, r = [int(el) for el in input().split(' ')]
    max_l = max(max_l, l)
    min_r = min(min_r, r)

print(max(min_r - max_l + 1, 0))


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

using namespace std;

int main() {
  int N;
  cin >> N;
  int a[N + 1];
  for (int i = 1; i <= N; i++) {
    cin >> a[i];
  }

  bool visited[N + 1] = { false };
  int i = 1;
  int cnt = 1;
  bool ok = false;

  while(!visited[i]) {
    visited[i] = true;
    if (a[i] == 2) {
      ok = true;
      break;
    }
    i = a[i];
    cnt++;
  }

  if (ok) {
    cout << cnt << endl;
  } else {
    cout << -1 << endl;
  }

  return 0;
}

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

using namespace std;

/**
 *  Name: Chris M. Perez
 *  University: Interamerican University Metro Campus
 *
**/

#define endl '\n'
#define MOD 10e9
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define gcd(x , y) __gcd(x , y)
#define all(x) (x).begin() , (x).end()
#define forn(i , a , b) for(int i=(a);i<(b);i++)
#define forrange(j , a , b) for(int j=(a);j<=(b);j++)
#define nestedforn(i , a , b , j , c , d) for(int i=(a);i<=(b);i++) for(int j=(c);j<=(d);j++)
#define sort_all(x) sort(all(x))
#define zeros_at_beginning(x) __builtin_clz(x)
#define zeros_at_end(x) __builtin_ctz(x)
#define ones(x) __builtin_popcount(x)
#define parity_even_or_odd_ones __builtin_parity(x)

typedef vector<int> vi;
typedef pair<int , int> pii;
typedef tuple<int , int , int> tiii;
typedef vector<pii> vpii;
typedef vector<tiii> vtiii;
typedef unsigned int ui;
typedef unsigned long long ull;
typedef long long ll;
typedef long long int lli;

             
inline int input(){
  int n;
  scanf("%d" , &n);
  return n;
}

int f(int n){
  return 111 * ((n - 1) / 111 + 1);
}

int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.precision(10);
  cout << fixed;

#ifdef LOCAL_DEFINE
  freopen("input.txt" , "rt" , stdin);
#endif

  int n; cin >> n;
  cout << f(n) << endl; 
  
     
#ifdef LOCAL_DEFINE
  cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif  
  return 0;
}

Measured memory_bytes: 256
// タイム: 
// mainは一番下(端的に)

// 場合分けは悪手だということに試行錯誤しながら気づいた
// intでoverflowしててこづった

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


int64_t calcNum (int64_t a, int64_t b, int64_t c, int64_t d)
{
    int64_t ac, ad, bc, bd;
    ac = a * c;
    ad = a * d;
    bc = b * c;
    bd = b * d;
    return max(max(max(ac, ad), bc), bd);
}


int main() {
    int64_t a,b,c,d;
    cin >> a >> b >> c >> d;
    int64_t result = calcNum(a, b, c, d);
    cout << result << endl; 
}


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

@SuppressWarnings("resource")
public static void main(String[] args) {
	Scanner sc =new Scanner(System.in);
	int N=sc.nextInt();
	while(N>0) {
		if(N%10==7) {
			System.out.println("Yes");
			System.exit(0);
		}
		N/=10;
	}
	System.out.println("No");
}
}

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

#define int long long
using ll = long long;
using ull = unsigned long long;
#define repi(n) for (long long i = 0; i < (n); ++i)
#define repj(n) for (long long j = 0; j < (n); ++j)
#define repk(n) for (long long k = 0; k < (n); ++k)
#define rep(i, a, b) for (auto i = (a); i < (b); ++i)
#define itr(itr) for (auto&& v : (itr))
#define updatemax(t, v) (t = std::max(t, (v)))
#define updatemin(t, v) (t = std::min(t, (v)))

ll a[200100];
signed main() {
  int n;
  ll k;
  cin >> n >> k;
  repi(n) cin >> a[i];
  vector<ll> positive, zero, negative;
  repi(n)(a[i] > 0 ? positive : a[i] == 0 ? zero : negative).push_back(a[i]);
  sort(positive.begin(), positive.end());
  sort(negative.begin(), negative.end());
  auto num = [&](ll x) {  // x以下の積の数
    ll result = 0;
    if (x < 0) {
      itr(negative) result += positive.end() - partition_point(positive.begin(), positive.end(), [&](ll y) { return v * y > x; });
    } else {
      result += negative.size() * positive.size();
    }
    if (x >= 0) {
      result += zero.size() * (zero.size() - 1) / 2 + zero.size() * (positive.size() + negative.size());
    }
    if (x > 0) {
      for (auto i = negative.begin(); i != negative.end(); ++i) {
        result += i - partition_point(negative.begin(), i, [&](ll y) { return (*i) * y > x; });
      }
      for (auto i = positive.begin(); i != positive.end(); ++i) {
        result += partition_point(positive.begin(), i, [&](ll y) { return (*i) * y <= x; }) - positive.begin();
      }
    }
    return result;
  };
  ll _pm = positive.empty() ? 1 : positive[positive.size() - 1];
  ll _nm = negative.empty() ? -1 : negative[0];
  ll low = _pm * _nm - 1, high = max(_pm * _pm, _nm * _nm) + 1;
  while (high - low > 1) {
    ll middle = (high + low) / 2;
    (num(middle) >= k ? high : low) = middle;
  }
  cout << high << endl;
}


Measured memory_bytes: 6956
//#include "bits/stdc++.h"

#define _USE_MATH_DEFINES
#include<cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <deque>
#include <algorithm>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <iterator>
#include<iomanip>

using namespace std;

#define rep(i,a,b) for(int i=(a), i##_len=(b);i<i##_len;i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)

#define int ll
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair

//typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<int, double> pid;
typedef pair<double, int> pdi;
typedef pair<double, double> pdd;
typedef vector< vector<int> > mat;

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

const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;

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

	int N;
	bool ok = true;
	cin >> N;
	int t, x, y;
	int pt = 0, px = 0, py = 0;
	rep(i, 0, N)
	{
		cin >> t >> x >> y;
		int dt = (t - pt) - abs(px - x) - abs(py - y);
		if (dt < 0 || dt % 2 == 1)
		{
			ok = false;
		}
		pt = t, px = x, py = y;
	}

	if (ok)
	{
		cout << "Yes" << endl;
	}
	else
	{
		cout << "No" << endl;
	}

	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void){
	int a,b,c,tmp;
	scanf("%d %d %d",&a,&b,&c);
	if(a<c){
		tmp = c;
		c = a;
		a = tmp;
	}
	if(a<b){
		tmp = b;
		b = a;
		a = tmp;
	}
	if(b<c){
		tmp = b;
		b = c;
		c = tmp;
	}
	if((b-c)%2==0) printf("%d\n",a-(b+c)/2);
	else         printf("%d\n",a-(b+c-3)/2);
	return 0;
}

Measured memory_bytes: 128
(N, K), A = [[*map(int, line.split())] for line in open(0)]

kiseki = [0] * N
now = 0
for i in range(N):
    kiseki[i] = now
    now = A[now] - 1

p = kiseki.index(now)
ans = p + (K - p) % (N - p) if p < K else K
print(kiseki[ans] + 1)


Measured memory_bytes: 33604
#include<cstdio>
#include<cstring>
#include<iostream>
#include<ctype.h>
using namespace std;
char s[200];
int ans;
int main(){
    cin>>s;
    for(int i = 0 ; i < strlen(s) ; ++ i) s[i] = tolower(s[i]);
    for(int i = 0 ; i < strlen(s) / 2 ; ++ i) {
        if(s[i] != s[strlen(s) - i - 1]) ++ ans;
    }
    printf("%d" ,ans);
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define F first
#define S second

using namespace std;
typedef pair<int,int> P;

const int MOD=998244353;
int INF=100100100100100;
int dp[3010][3010];
signed main(){
  int a,b,c,d;
  cin>>a>>b>>c>>d;
  dp[a][b]=1;
  for(int i=a;i<=c;i++){
    for(int j=b;j<=d;j++){
      if(i>a)(dp[i][j]+=dp[i-1][j]*j)%=MOD;
      if(j>b)(dp[i][j]+=dp[i][j-1]*i)%=MOD;
      if(i>a && j>b)(dp[i][j]+=MOD-(dp[i-1][j-1]*(i-1)*(j-1))%MOD)%=MOD;
    }
  }
  cout<<dp[c][d]<<endl;
      return 0;
}


Measured memory_bytes: 73956
#include <bits/stdc++.h>
using namespace std;
int main() {
	int N;
  cin >>N;
  int A[N];
  for(int i=0;i<=N-1;i++){
  	cin >>A[i];
  }
   bool flag=1;
  int count=0;
  
  for(int i=0;flag;i++){
  	flag=0;
    for(int j=N-1;j>=0;j--){
    	if(A[j]<A[j-1]){
		swap(A[j],A[j-1]);
        count++;
        flag=1;}
    }
  }
  for(int i=0;i<=N-1;i++){
  	if(i==N-1){cout <<A[i];}
   	else{cout<<A[i]<<' ';}
  } 
  cout<<endl<<count<<endl;
}


Measured memory_bytes: 3104
S = input()

d = dict()

for i in range(26):
    alphabet = chr(ord('a') + i)
    d[alphabet] = []

for idx in range(len(S)):
    d[S[idx]].append(idx)

ans = len(S)

for i in range(26):
    alphabet = chr(ord('a') + i)
    if len(d[alphabet]) != 0:
        max_op = 0
        for idx in range(len(d[alphabet])):
            if idx != 0:
                max_op = max(max_op, d[alphabet][idx] - d[alphabet][idx-1] - 1)
            else:
                max_op = max(max_op, d[alphabet][idx])
        max_op = max(max_op, len(S) - d[alphabet][-1] - 1)
        ans = min(ans, max_op)

print(ans)

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

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


#define rep(i,n) for(ll (i)=0; (i)<(ll)(n); (i)++)
#define frep(i,m,n) for(ll (i)=(m); (i)<=(ll)(n); (i)++)
#define rrep(i,n) for(ll (i)=(n)-1; (i)>-1; (i)--)
#define frrep(i,m,n) for(ll (i)=(n); (i)>(ll)(m); (i)--)
#define ALL(x) (x).begin(), (x).end()

const ll INF = 100100100100100100;
const ll MOD = 1000000007;

// get abs
ll my_abs(ll a);
// a^n
ll a_n(ll a, ll n);
// get gcd
ll my_gcd(ll a, ll b);
// a^(-1) % MOD 
ll inv(ll a);
// (a+b+c)%MOD
ll madd(ll a, ll b, ll c);
// (a-b)%MOD
ll msub(ll a, ll b);
// (a*b*c)%MOD
ll mtime(ll a, ll b, ll c);


int main() {
    ll n; cin >> n;
    string c; cin >> c;
    ll ans = 0;
    rep(i, n) {
        if(c[i] == 'W') {
            while(i < n-1) {
                if(c[n-1] == 'R') {
                    ans++;
                    n--;
                    break;
                }
                n--;
            }
        }
    }

    cout << ans << endl;
    return 0;
}

ll my_abs(ll a) {
    if(a >= 0) return a;
    else return -1 *a;
}

ll a_n(ll a, ll n) { 
    if(n == 0) return 1;
    
    ll ret = a, count = 1;
    while(count * 2 < n) {
        ret *= ret;
        count *= 2;
    }
    if(count == n) return ret;
    else return (ret * a_n(a, n-count));
}

ll my_gcd(ll a, ll b) {
    if(b == 0) return a;
    return my_gcd(b, a%b);
}

ll inv(ll a) {
    return a_n(a, MOD-2);
}

ll madd(ll a, ll b, ll c) {
    ll ret = (a+b) % MOD;
    return (ret+c) % MOD;
}

ll msub(ll a, ll b) {
    if(a < b) return (a-b+MOD) % MOD;
    else return (a-b) % MOD;
}

ll mtime(ll a, ll b, ll c) {
    ll ret = (a*b) % MOD;
    return (ret*c) % MOD;
}


Measured memory_bytes: 3728
#include <bits/stdc++.h>
#define rep(i,n) for (long long i = 0; i < (n); ++i)
const int INF = 2147483647;//int max
const int MOD = 1000000007;
using namespace std;
using ll = long long;
using P = pair<int,int>;


int main() {
    ll n;
    string s;
    cin >> n >> s;
    unordered_map<char,int> um;
    rep(i,n){
        um[s[i]]++;
    }
    ll ans = 1;
    for(auto au : um){
        ans *= au.second+1;
        ans%=MOD;
    }
    cout << ans%MOD-1 << endl;
    return 0;
}
/*
やっほい！
　　　　　　　やほほい！
　　　　+　　 　*
　　　 ∧∧　　. ∧∞∧　*
*　ヽ(=´ω｀)人(´ω｀*)ﾉ
　.～（ O x.） （ 　 O)～　+
。*　 　∪　　　　∪
*/

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define IOS ios_base::sync_with_stdio(false); cin.tie(0);
#define pb push_back
#define PI acos(-1)
#define EPS 1e-5
#define sz(v) ((int)(v).size())
#define all(v) v.begin(),v.end()
#define forn(i, n) for(ll i=0;i<(ll)n;i++)
#define fi first
#define se second
 

int main() {
	int n, k;
	cin >> n >> k;
	vector<int> cnt(n);
	for(int i = 0; i < k; i++) {
		int d;
		cin >> d;
		forn(j, d) {
			int x;
			cin >> x;
			cnt[x-1]++;
		}
	}
	int r = count(all(cnt), 0);
	cout << r << endl;
	return 0;
}



Measured memory_bytes: 3624
#include <stdio.h>

typedef struct {
	int key, id;
} data;

typedef struct {
	data obj[200001];
	int size;
} max_heap;

void push(data x, max_heap* h)
{
	int i = ++(h->size), j = i >> 1;
	data tmp;
	h->obj[i] = x;
	while (j > 0) {
		if (h->obj[i].key > h->obj[j].key) {
			tmp = h->obj[j];
			h->obj[j] = h->obj[i];
			h->obj[i] = tmp;
			i = j;
			j >>= 1;
		} else break;
	}
}

data pop(max_heap* h)
{
	int i = 1, j = 2;
	data output = h->obj[1], tmp;
	h->obj[1] = h->obj[(h->size)--];
	while (j <= h->size) {
		if (j < h->size && h->obj[j^1].key > h->obj[j].key) j ^= 1;
		if (h->obj[j].key > h->obj[i].key) {
			tmp = h->obj[j];
			h->obj[j] = h->obj[i];
			h->obj[i] = tmp;
			i = j;
			j <<= 1;
		} else break;
	}
	return output;
}

int main()
{
	int i, N, K;
	data d;
	max_heap h;
	h.size = 0;
	scanf("%d %d", &N, &K);
	for (i = 1; i <= N; i++) {
		scanf("%d", &(d.key));
		push(d, &h);
	}
	
	long long ans = 0;
	while (h.size > 0) {
		d = pop(&h);
		if (K > 0) K--;
		else ans += d.key;
	}
	printf("%lld\n", ans);
	fflush(stdout);
	return 0;
}

Measured memory_bytes: 3272
#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
typedef long long ll;
ll strtoint(string str);
int main(){
	fast;
	ll t,n; cin>>t;
	set<string> ss;
 	while(t--){
		string s; 
		cin>>s;
		ss.insert(s);
	}
	cout<<(ll)ss.size()<<'\n';
	return 0;
}
ll strtoint(string str){
	ll x=0;
	stringstream ss;
	ss<<str;
	ss>>x;
	return x;
}

Measured memory_bytes: 19224
s = input()
n = len(s)
tmp = 0
ans = 'Yes'
flag = True

while(tmp < n):
  if(tmp%2 == 0):
    if(s[tmp] == 'R' or s[tmp] == 'U' or s[tmp] == 'D'):
      pass
    else:
      flag = False
      break
  else:
    if(s[tmp] == 'L' or s[tmp] == 'U' or s[tmp] == 'D'):
      pass
    else:
      flag = False
      break
  if flag == False:
    ans = 'No'
    break
  tmp += 1
if flag == False:
  print("No")
else:
  print("Yes")
  
   
      
    

Measured memory_bytes: 3064
import collections

N, X, Y = list(map(int, input().split()))
dists = [
        min(abs(j-i), abs(X-1-i)+1+abs(Y-1-j), abs(Y-1-i)+1+abs(X-1-j))
        for i in range(N-1) for j in range(i+1, N)
    ]
c = collections.Counter(dists)
for K in range(1,N):
    print(c[K])

Measured memory_bytes: 116692
function Main(input) {

  input = input.split("\n");
  rowcol = input[0].split(" ");
  fill = input[1].split(" ");
  h = rowcol[0];
  w = rowcol[1];
  fillH = fill[0];
  fillW = fill[1];
  if(h == fillH || w == fillW) {
    console.log(0);
  } else {
    wcel = h * w - (w * fillH + ((h - fillH) * fillW));
    console.log(wcel);
  }
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 7372
import sys
import collections

def main():

    input = sys.stdin.readline

    N = int(input())

    c = collections.Counter(prime_factorize(N))

    ans = 0

    for value in c.values():
        j = 1
        for i in range(2,1000000):
            j += i

            if value < j:
                ans += (i - 1)
                break


    print(ans)

def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

if __name__ == "__main__":
    main()

Measured memory_bytes: 9464
a = list(map(int,input().split()))
if a[2] < a[0]: a = [a[2], a[3], a[0],a[1]]

if a[2] < a[1]:
	if a[3] < a[1]:
		print(a[3]-a[2])
	else:
		print(a[1]-a[2])
else:
	print(0)

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

int main()
{
    int h, w, k;
    cin >> h >> w >> k;

    vector<vector<int>> s(h, vector<int>(w));
    vector<int> num(w, 0);
    for (int i = 0; i < h; i++)
    {
        for (int j = 0; j < w; j++)
        {
            char c;
            cin >> c;

            if (c != '.') 
            {
                s[i][j] = 1;
                num[j]++;
            } else {
                s[i][j] = 0;
            }
        
        }
    }

    int label = 1;
    vector<vector<int>> a(h, vector<int>(w, 0));
    for (int i = 0; i < w; i++)
    {
        if (num[i] != 0)
        {
            int cnt = 0;
            for (int j = 0; j < h; j++)
            {
                a[j][i] = label;
                if (s[j][i] == 1) 
                {
                    cnt++;
                    if (cnt != num[i]) label++;
                }
            }

            // if (s[h - 1][i] == 1) label--;
            label++;
        }
    }

    for (int i = 0; i < w - 1; i++)
    {
        if (num[i] == 0) 
        {
            int id = -1;
            //右のをコピー
            for (int j = i + 1; j < w; j++) {
                if (num[j] != 0) 
                {
                    id = j;
                    break;
                }
            }

            if (id != -1) {
                for (int j = 0; j < h; j++) {
                    a[j][i] = a[j][id];
                }
            }
        }
    }

    
    for (int i = 1; i < w; i++)
    {
        if (num[i] == 0) 
        {
            int id = -1;
            for (int j = i - 1; j >= 0; j--) {
                if (num[j] != 0)
                {
                    id = j;
                    break;
                }
            }

            if (id != -1) {
                for (int j = 0; j < h; j++) {
                    a[j][i] = a[j][id];
                }
            }
        }
    }

    for (int i = 0; i < h; i++)
    {
        for (int j = 0; j < w; j++)
        {
            cout << a[i][j] << (j + 1 != w ? " " : "\n");
        }
    }
    

    return 0;
}

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

#define dump(x) cout << (x) << '\n'
#define Int int64_t
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()

Int INF = 1e18;
int inf = 1e9;
Int mod = 1e9+7;

typedef struct {
    bool L, R;
} p_t;

int n;
int dp[1<<15][20];
int sub[15][15];
string s[20];

int rec(int x, int y) {
    if (dp[x][y] < inf) return dp[x][y];
    x -= (1<<y);
    for (int i = 0; i < n; i++) {
        if (x & (1<<i)) {
            dp[x + (1<<y)][y] = min(dp[x + (1<<y)][y], rec(x, i) + (int)s[y].length() - sub[i][y]);
        }
    }
    return dp[x + (1<<y)][y];
}

int main() {
    vector<int> res;
    while (cin >> n and n) {
        for (int i = 0; i < n; i++) {
            cin >> s[i];
        }
        bool cov[20] = {};
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                int i_len = s[i].length();
                int j_len = s[j].length();
                if (i_len <= j_len) continue;
                for (int k = 0; k < i_len - j_len; k++) {
                    if (s[i].substr(k, j_len) == s[j]) {
                        cov[j] = true;
                    }
                }          
            }
        }
        int cnt = 0;
        for (int i = 0; i < n; i++) {
            if (not cov[i]) {
                s[cnt] = s[i];
                cnt++;
            }
        }
        n = cnt;
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                int i_len = s[i].length();
                int j_len = s[j].length();
                int cnt = 0;
                for (int k = 0; k < min(i_len, j_len); k++) {
                    if (s[i].substr(i_len - 1 - k) == s[j].substr(0, k + 1)) {
                        cnt = k + 1;
                    }
                }
                sub[i][j] = cnt;
            }
        }
        for (int i = 0; i < (1<<n); i++) {
            for (int j = 0; j < n; j++) {
                dp[i][j] = inf;
            }
        }
        for (int i = 0; i < n; i++) {
            dp[1<<i][i] = s[i].length();
        }
        int mi = inf;
        for (int i = 0; i < n; i++) {
            mi = min(mi, rec((1<<n) - 1, i));
        }
        res.push_back(mi);
    }
    for (int i = 0; i < (int)res.size(); i++) {
        dump(res[i]);
    }
    return 0;
}



Measured memory_bytes: 4440
import math
def ma(): return map(int,input().split())

a,b=ma()
a_over=(a + 1)/0.08-0.0001
a_under=(a)/0.08
b_over=(b + 1)/0.1-0.0001
b_under= b/0.1

c_over = min(a_over,b_over)
c_under = max(a_under, b_under)

if math.floor(c_over)>=math.ceil(c_under):
    print(math.ceil(c_under))
else:
    print(-1)


Measured memory_bytes: 3060
#include <stdio.h>

int main(){
  int i, j, k;
  int num[5];
  for(i = 0; i < 5;i++){
    scanf("%d", &num[i]);
  }
  for(j = 4; j>=1;j--){
    for(i = 0;i < j; i++){
      if(num[i] < num[i+1]){
	k = num[i];
	num[i] = num[i+1];
	num[i+1] = k;
      }
    }
  }
  printf("%d %d %d %d %d\n", num[0], num[1], num[2], num[3], num[4]);
  return 0;
}

Measured memory_bytes: 596
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <cmath>
#include <algorithm>
#include <map>
#include <cassert>
#define rep(i, a, b) for (int i = (a), _ = (b); i <= _; ++ i)
#define per(i, a, b) for (int i = (a), _ = (b); i >= _; -- i)
#define For(i, a, b) for (int i = (a), _ = (b); i < _; ++ i)
#define ri rd<int>
#define rl rd<LL>
typedef long long LL;
using namespace std;
const int maxN = 1e5 + 7;
const int maxM = 5e6 + 7;
const int V = 5e6;
const int Lim = 2200;

template<class T> inline T rd() {
	bool f = 1; char c = getchar(); for (; !isdigit(c); c = getchar()) if (c == '-') f = 0;
	T x = 0; for (; isdigit(c); c = getchar()) x = x * 10 + c - 48; return f ? x : -x;
}

int n, m;
LL a[maxN];
LL b[maxN], c[maxN];
LL pri[maxM], mnp[maxM], cnt; bool ntpri[maxM];
map<LL, LL> mp, cont, sqr;

void seive() {
	ntpri[1] = 1, cnt = 0;
	rep (i, 2, V) {
		if (!ntpri[i]) {
			pri[++cnt] = i;
			mnp[i] = i;
			sqr[1LL * i * i] = i;
		}
		rep (j, 1, cnt) {
			if (1LL * i * pri[j] > V) break;
			int t = i * pri[j];
			ntpri[t] = 1;
			if (i % pri[j] == 0) {
				mnp[t] = mnp[i];
				break;
			}
			else mnp[t] = pri[j];
		}
	}
}

void gao(LL x) {
	++ m; b[m] = c[m] = 1;
	rep (i, 1, cnt) {
		if (pri[i] > Lim) break;
		LL p = pri[i], cc = 0;
		while (x % p == 0) ++ cc, x /= p;
		cc %= 3;
		if (cc == 0) continue;
		rep (j, 1, cc) b[m] *= p;
		rep (j, 1, 3 - cc) c[m] *= p;
	}
	if (sqr[x]) b[m] *= x, c[m] *= sqr[x];
	else b[m] *= x, c[m] *= x * x;
}

int main() {

	n = ri();
	rep (i, 1, n) a[i] = rl();
	seive();
	rep (i, 1, n) gao(a[i]);
	rep (i, 1, n) ++ cont[b[i]];
	rep (i, 1, n) if (b[i] > c[i]) swap(b[i], c[i]);
	rep (i, 1, n) mp[b[i]] = c[i];

	int res = 0;
	for (map<LL, LL> :: iterator it = mp.begin(); it != mp.end(); ++ it) {
		if (it->first == it->second) ++ res;
		else res += max(cont[it->first], cont[it->second]);
	}
	printf("%d\n", res);

	return 0;
}


Measured memory_bytes: 96256
#include <bits/stdc++.h>
using namespace std;
#define int long long
template<typename T>
void fin(T a){
  cout<<a<<endl;
  exit(0);
}
template<typename T>
void chmin(T &a,T b){
  if(a>b)a=b;
}
template<typename T>
void chmax(T &a,T b){
  if(a<b)a=b;
}

signed main(){
  int n,m;cin>>n>>m;
  cout<<n*(n-1)/2+m*(m-1)/2<<endl;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.PriorityQueue;
import java.util.Random;
import java.util.StringTokenizer;
import java.util.TreeMap;
 
public class Main {
	
	public static void main(String[] args) {
		FastReader scan = new FastReader();
		PrintWriter out = new PrintWriter(System.out);
		Task solver = new Task();
		int t = 1;
		while(t-->0) solver.solve(1, scan, out);
		out.close();
	}
	
	static class Task {
		public void solve(int testNumber, FastReader scan, PrintWriter out) {
			int n = 1 << scan.nextInt();
			int max = 0;
			TreeMap<Integer, Integer> t = new TreeMap<>();
			PriorityQueue<Integer> q = new PriorityQueue<>();
			for(int i = 0; i < n; i++) {
				int a = scan.nextInt();
				max = Math.max(max, a);
				add(t, a);
			}
			remove(t, max);
			q.add(max);
			while(q.size() != n) {
				ArrayList<Integer> res = new ArrayList<>();
				for(int i : q) {
					Integer g = t.lowerKey(i);
					if(g == null) {
						out.println("No");
						return;
					}
					remove(t, g);
					res.add(g);
				}
				for(int i : res) q.add(i);
			}
			out.println("Yes");
		}
		
		static void remove(TreeMap<Integer, Integer> t, int x) {
			int g = t.get(x);
			if(g == 1) t.remove(x);
			else t.put(x, g-1);
		}
		
		static void add(TreeMap<Integer, Integer> t, int x) {
			t.put(x, t.getOrDefault(x, 0)+1);
		}
		
	}
	
	static void shuffle(int[] a) {
		Random get = new Random();
		for(int i = 0; i < a.length; i++) {
			int r = get.nextInt(a.length);
			int temp = a[i];
			a[i] = a[r];
			a[r] = temp;
		}
	}
	
	static void shuffle(long[] a) {
		Random get = new Random();
		for(int i = 0; i < a.length; i++) {
			int r = get.nextInt(a.length);
			long temp = a[i];
			a[i] = a[r];
			a[r] = temp;
		}
	}
	
 
	static class FastReader {
		BufferedReader br;
		StringTokenizer st;
 
		public FastReader() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}
		public FastReader(String s) throws FileNotFoundException {
			br = new BufferedReader(new FileReader(new File(s)));
		}
 
		String next() {
			while (st == null || !st.hasMoreElements()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
			return st.nextToken();
		}
 
		int nextInt() {
			return Integer.parseInt(next());
		}
 
		long nextLong() {
			return Long.parseLong(next());
		}
 
		double nextDouble() {
			return Double.parseDouble(next());
		}
 
		String nextLine() {
			String str = "";
			try {
				str = br.readLine();
			} catch (IOException e) {
				e.printStackTrace();
			}
			return str;
		}
	}
 
}

Measured memory_bytes: 88612
#include <stdio.h>

 int main(void){
 int A, B;
 scanf("%d%d", &A, &B); // 入力からA, B を受け取る

 int result = 6 - A - B; // 6-A-B を計算し，変数result に格納する
 printf("%d\n", result); // 出力

 return 0;
 }


Measured memory_bytes: 128
#   ==========     //\\       //||     ||====//||
#       ||        //  \\        ||     ||   // ||
#       ||       //====\\       ||     ||  //  ||
#       ||      //      \\      ||     || //   ||
#   ========== //        \\  ========  ||//====|| 
#  code

def solve():
    MOD = 998244353
    n, k = map(int, input().split())
    segments = []
    for i in range(k):
        l, r = map(int, input().split())
        segments.append([l, r])
    
    dp = [0] * (n)
    dp[0] = 1
    pdp = [1] * (n)
    for i in range(1 , n):
        pdp[i] = pdp[i - 1] + dp[i]
    
    for j in range(n):
        for i in range(k):
            if j <= segments[i][1] and j >= segments[i][0]:
                dp[j] += pdp[j - segments[i][0]]
            elif j > segments[i][1]:
                dp[j] += pdp[j - segments[i][0]] - pdp[j - segments[i][1] - 1]
            dp[j] %= MOD
            # print(i, dp[j])
            if j > 0:
                pdp[j] = pdp[j - 1] + dp[j]
            else:
                pdp[j] = dp[j]
            pdp[j] %= MOD
    print(dp[n - 1])
    return

def main():
    t = 1
    # t = int(input())
    for _ in range(t):
        solve()

if __name__ == "__main__":
    main()

Measured memory_bytes: 24660
#include <iostream>
#include <vector>
#include <bitset>
#include <algorithm>

int main() {
    long long n, sum = 0, t;
    std::cin >> n;
    std::bitset<4000001> dp(1);
    for (int i = 0ll; i < n; i++) {
        std::cin >> t;
        sum += t;
        dp = dp | (dp << t);
    }

    for (auto i = sum / 2 + (sum % 2); ; i++) {
        if (dp[i]) {
            std::cout << i << std::endl;
            break;
        }
    }

    return 0;
}

Measured memory_bytes: 2176