akhauriyash/Code-Regression huggingface dataset:
#include <cstring>
#include <queue>
#include <cstdio>
#include <algorithm>
#include <iostream>
using namespace std;
#define X first
#define Y second
typedef long long LL;
typedef pair<int, int> pii;

const int N = 1e5 + 100;
int dis[N];
priority_queue<pii> Q;
int main() {
    memset(dis, 0x3f, sizeof(dis));
    int n;
    cin >> n;
    dis[1] = 1;
    Q.push(pii(-dis[1], 1));
    while(! Q.empty() ) {
        pii cur = Q.top();
        Q.pop();
        if(-cur.X != dis[cur.Y]) continue;
        if(cur.Y == 0) return printf("%d\n", -cur.X), 0;
        int np = cur.Y * 10 % n;
        if(dis[np] > -cur.X) dis[np] = -cur.X, Q.push(pii(-dis[np], np));
        np = (cur.Y + 1) % n;
        if(dis[np] > -cur.X + 1) dis[np] = -cur.X + 1, Q.push(pii(-dis[np], np));
    }
}


Measured memory_bytes: 1276
#include <iostream>
#include <algorithm>
using namespace std;
int main(){
int N;
cin >> N;
while(N--){
int i[3],c;
int max;
cin >> i[0] >> i[1] >> i[2];
sort(i,i+3);
cout << ((i[0]*i[0]+i[1]*i[1]==i[2]*i[2])?"YES\n":"NO\n");
}}

Measured memory_bytes: 1136
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin >> n;
  char s[1100];
  cin >> s;
  int ans=0;
  for(int i=0;i<n;i++){
    if(s[i]=='A' && s[i+1]=='B' && s[i+2]=='C'){
      ans++;
      i+=2;
    }
  }
  cout << ans;
  return(0);
}

Measured memory_bytes: 256
#define FNAME ""

#include <bits/stdc++.h>

#define hash padjf9srpi
#define y0 sdkfaslhagaklsldk
#define y1 aasdfasdfasdf
#define yn askfhwqriuperikldjk
#define j1 assdgsdgasghsf
#define tm sdfjahlfasfh
#define lr asgasgash
#define pb push_back
#define mp make_pair
#define forn(i, n) for (int i = 0; i < (n); i++)
#define fornr(i, n) for (int i = (n) - 1; i >= 0; i--)
#define forab(i, a, b) for (int i = (a); i < (b); i++)
#define gcd __gcd
#define all(a) (a).begin(), (a).end()
 
#ifdef _WIN32
    #define I64 "%I64d"
#else
    #define I64 "%lld"
#endif

using namespace std;

typedef long long LL;
typedef unsigned long long ULL;
typedef long double LD;
typedef pair <int, int> pii;                                                                                                                                                                                      
typedef vector <int> vi;

template <class T> T sqr(const T &a) {return a * a;}

const int MAXN = 1e5 + 300;

vi pr[MAXN];
int n, k, depth[MAXN], maxDepth[MAXN], a[MAXN];
set<pii> Set;
void dfs(int v) {
    for (int to: pr[v])
        if (to)
            depth[to] = depth[v] + 1, dfs(to);
}

int main()
{
#ifdef LOCAL
    freopen(FNAME".in", "r", stdin);
    freopen(FNAME".out", "w", stdout);
#endif
    scanf("%d%d", &n, &k);
    forn(i, n)
        scanf("%d", &a[i]), a[i]--, pr[a[i]].pb(i);
    dfs(0);
    int ans = 0;
    if (a[0] != 0)
        ans = 1;
    forab(i, 1, n)
        Set.insert(mp(-depth[i], i));
    while (Set.size()) {
        int v = Set.begin()->second;
        Set.erase(Set.begin());
        if (maxDepth[v] == k - 1 && a[v] )
            ans++;
        else
            maxDepth[a[v]] = max(maxDepth[v] + 1, maxDepth[a[v]]);
    }
    printf("%d\n", ans);
}



Measured memory_bytes: 14720
#include<stdio.h>
int main(){
	int i,j,n,a,p;
	char c[15];
	for(i=0;i<9;i++){
		scanf("%s %d %d",c,&a,&p);
		printf("%s %d %d\n",c,a+p,a*200+p*300);
	}
	exit(0);
}

Measured memory_bytes: 0
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <sstream>
#include <string>
#define _repargs(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _repargs(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
//#define inf 2000000007
#define mp make_pair
#define pb push_back
typedef long long ll;
using namespace std;
template <typename T>
inline void output(T a, int p = 0) {
    if(p) cout << fixed << setprecision(p)  << a << "\n";
    else cout << a << "\n";
}
// end of template

const ll inf = 1LL << 63;

struct edge {int to; ll cost; bool use;};
struct node {int pos; ll cost;};
bool operator < (const node &a, const node &b){
    return a.cost > b.cost;
}

vector<ll> dijkstra(vector<vector<edge>> &G, int root){
    vector<ll> ret(G.size(), inf);
    priority_queue<node> pq;
    pq.push({root, 0});
    while (!pq.empty()) {
        node t = pq.top();
        pq.pop();
        
        if (ret[t.pos] == inf) ret[t.pos] = t.cost;
        else continue;
        
        for (edge e : G[t.pos]) {
            pq.push({e.to, t.cost + e.cost});
        }
    }
    return ret;
}


vector<ll> C1, C2, D1, D2;

ll dfs(vector<vector<edge>> &G, vector<ll> &C, vector<ll> &D, int cur, int par = -1) {
    ll ret = 0;
    if(C[cur] >= 0) return C[cur];
    for(edge e: G[cur]){
        if(D[e.to] + e.cost == D[cur]) {
            (ret += dfs(G, C, D, e.to, cur)) %= mod;
        }
    }
    return C[cur] = ret;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    // source code
    int N, M, S, T;
    cin >> N >> M >> S >> T;
    S--, T--;
    vector<vector<edge>> G(N);
    rep(i, M){
        int u, v;
        ll d;
        cin >> u >> v >> d;
        d *= 2;
        u--, v--;
        G[u].pb({v, d, false});
        G[v].pb({u, d, false});
    }
    
    D1 = dijkstra(G, S);
    D2 = dijkstra(G, T);
    ll dist = D1[T];
    ll meet = dist / 2;
    
    C1.assign(N, -1);
    C1[S] = 1;
    dfs(G, C1, D1, T);
    C2.assign(N, -1);
    C2[T] = 1;
    dfs(G, C2, D2, S);
    
    vector<ll> tak, aok;
    rep(i, N){
        if(D1[i] == meet && D2[i] == meet){
            tak.pb(C1[i]), aok.pb(C2[i]);
        }
    }
    
    rep(i, N){
        for(edge e: G[i]){
            if(D1[i] < meet && D2[e.to] < meet && D1[i] + D2[e.to] + e.cost == dist){
                tak.pb(C1[i]);
                aok.pb(C2[e.to]);
            }
        }
    }
    
    ll ans = C1[T] * C1[T] % mod;
    rep(i, tak.size()){
        ll sub = tak[i] * aok[i] % mod;
        (ans -= sub * sub) %= mod;
    }
    (ans += mod) %= mod;
    output(ans);
    
    return 0;
}


Measured memory_bytes: 28172
#include <iostream>
#include <cstdio>
using namespace std;
int f[210000];
int n,x;
int main(void)
{
    scanf("%d",&n);
    for(int i=1;i<=n-1;i++)
    {
        scanf("%d",&x);
        f[x]++;
    }
    for(int i=1;i<=n;i++)
    {
        printf("%d\n",f[i]);
    }
    return 0;
}

Measured memory_bytes: 3836
#include <iostream>
#include <string>
using namespace std;
 
int main(){
int w;
cin >> w;
char a;
int n;
cin >> n;
int b[n];
int d[n];
int c;
c=0;
while(c<n){
cin >> b[c]>>a>>d[c];
c=c+1;}
int e[w];
c=0;
while(c<w){
e[c]=c;
c=c+1;}
int f;
int g;
c=0;
while(c<n){
f=e[b[c]-1];
g=e[d[c]-1];
e[d[c]-1]=f;
e[b[c]-1]=g;
c=c+1;}
c=0;
while(c<w){
cout << e[c]+1 <<endl;
c=c+1;}
 
 
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define REP(i, n) FOR(i, 0, (n))
#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define LAR(a, b) ((a)=max((a),(b)))
#define SML(a, b) ((a)=min((a),(b)))
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pair<int, int>> vpii;
typedef pair<int, int> pii;
#define PB push_back
#define EB emplace_back
#ifdef LOCAL_DEBUG
#define DEBUG(...) printf(__VA_ARGS__)
#else
#define DEBUG(...)
#endif

#define N 112345
ll s[N];

int main(){
	int n; scanf("%d", &n);
	REP(i, n) scanf("%lld", s+i);
	int m = n-1;
	ll ans = 0;
	FOR(i, 1, N){
		int p = i;
		int q = m-i;
		ll tmp = 0;
		while(1){
			if(m%i==0 && q<=p) break;
			if(m%i!=0 && q<i) break;
			tmp += s[p]+s[q];
			LAR(ans, tmp);
			p += i;
			q -= i;
		}
	}
	printf("%lld\n", ans);
}


Measured memory_bytes: 1024
#include <iostream>
#include <iomanip>
#include <string>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#define MOD 1000000007LL
using namespace std;

int main(){
	int w, a, b;
	cin >> w >> a >> b;
	if(abs(a-b) <= w) cout << 0 << endl;
	else cout << abs(a-b) - w << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>
#include <sstream>
#include <iomanip>
#include <set>
using namespace std;
typedef long long int ll;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define yes cout << "yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
#define no cout << "no" << endl

const int INF = 1001001001;
const int mod = 1000000007;
#define PI 3.14159265359;

void P(int x) {cout << x << endl;}
void P(long x) {cout << x << endl;}
void P(double x) {cout << x << endl;}
void P(ll x) {cout << x << endl;}
void P(string x) {cout << x << endl;}
void P(char x) {cout << x << endl;}

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;}

int main() {
  string s;
  cin >> s;
  int flag[3];
  rep (i, 3) {
    flag[i] = 0;
  }
  rep (i, 3) {
    if (s[i] == 'a') flag[0] = 1;
    if (s[i] == 'b') flag[1] = 1;
    if (s[i] == 'c') flag[2] = 1;
  }
  int flagA = 1;
  rep (i, 3) {
    if (flag[i] == 0) flagA = 0;
  }

  if (flagA) Yes;
  else No;
  return 0;
}



Measured memory_bytes: 256
object Main extends App {
  val sc = new java.util.Scanner(System.in)
  val N = sc.nextInt()
  val A1, A2 = List.fill(N)(sc.nextInt())
  println {
    A1.scan(0)(_ + _)
      .tail
      .zip(A2.scan(A2.sum)(_ - _).init)
      .map { case (l, r) => l + r }
      .max
  }
}


Measured memory_bytes: 55708
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);
    int N = scanner.nextInt();
    int K = scanner.nextInt();
    int[] x = new int[N];
    for (int i = 0; i < N; i++) {
      x[i] = scanner.nextInt();
    }
    int min = Integer.MAX_VALUE;
    for (int i = 0; i <= N - K; i++) {
      int j = i + K - 1;
      int d = Math.abs(x[j] - x[i]) + Math.min(Math.abs(x[i]), Math.abs(x[j]));
      if (d < min) min = d;
    }
    System.out.println(min);
  }
}


Measured memory_bytes: 50876
#include<bits/stdc++.h>
#include<iostream>
#include<cmath>
#include<vector>
#include<string>
#include<queue>
#include<set>
#include<map>
#include<algorithm>
#include<functional>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef pair<ull, ull> pullull;
typedef pair<ll, int> plli;
typedef pair<int, pii> pipii;
typedef vector<vector<int> > mati;
typedef vector<vector<double> > matd;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef vector<vector<vector<ll>>> vvvll;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<vector<vector<bool>>> vvvb;

#define FOR(i,x,y) for(ll i=(ll)x; i<(ll)y; ++i)
#define REP(i,y) FOR(i, 0, y)
#define RFOR(i,x,y) for(ll i=(ll)x; i>=(ll)y; --i)
#define RREP(i,x) RFOR(i, x, 0)

template <typename T>
void vec_print(vector<T> VEC){
  REP(i, VEC.size()){
    cout << VEC[i] << " ";
  }
  cout << "\n";
};

template <typename T>
void mat_print(vector<vector<T> > MAT){
  REP(i, MAT.size()){
    REP(j, MAT[i].size()){
      cout << MAT[i][j] << " ";
    }
    cout << "\n";
  }
};

template <typename CLASS1, typename CLASS2>
class HOGE{
  public:
    CLASS1 key;
    CLASS2 value;
    HOGE(void){
      return;
    };
    HOGE(CLASS1 key, CLASS2 value){
      this->key = key;
      this->value = value;
    };
    ~HOGE(void){
      return;
    };

    void print(void){
      cout << "key : " << key << ", value : " << value << "\n";
      return;
    };
    
    bool operator==(const HOGE &obj){
      return (this->value == obj.value);
    };
    bool operator<(const HOGE &obj){
      return (this->value < obj.value);
    };
    bool operator>(const HOGE &obj){
      return (this->value > obj.value);
    };
};

constexpr int INF = (1<<30);
constexpr ll INFLL = 1LL<<62;
constexpr long double EPS = 1e-12;
constexpr ll MOD = (ll)((1E+9)+7);

unordered_map<ll, ll> mp;

ll sequential(ll N){
  if(mp.find(N)!=mp.end()) return mp[N];

  sequential(N/2);
  if(N%2==1) return mp[N] = mp[N/2];

  sequential(N/2-1);
  return mp[N] = mp[N/2] + mp[N/2-1];
};

ll sum(ll N){
  if(N==0) return mp[0];
  if(N==1) return 2*mp[0];
  sequential(N/2);
  if(N%2==0) return (3*sum(N/2-1) + mp[N/2])%MOD;
  return (3*sum(N/2-1) + 2*mp[N/2])%MOD;
}

int main(){
  cin.tie(0); // cut the cin and cout (default, std::flush is performed after std::cin)
  ios::sync_with_stdio(false); // cut the iostream and stdio (DON'T endl; BUT "\n";)

  ll N;
  cin >> N;

  mp[0] = 1;
  cout << sum(N)%MOD << "\n";

  return 0;
}


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

#define N 30000
char dx[N];

typedef struct Roll{
  int insidedx;
  int buff;
} Roll;

int S1[N];
Roll S2[N];

int s1_top = 0;
int s1_pop()
{return S1[--s1_top];}

void s1_push(int x)
{S1[s1_top++] = x;}

int s2_top = 0;

Roll s2_Top()
{return S2[s2_top-1];}

Roll s2_pop()
{return S2[--s2_top];}

void s2_push(int insidedx, int buff)
{
  Roll x;
  x.insidedx = insidedx;
  x.buff = buff;

  S2[s2_top++] = x;
}

int main()
{
  int j,i,sum,b,c;
  scanf("%s", dx);

  sum = 0;
  i = 0;

  while ( (c = dx[i]) != 0 ) {
    if ( c == '\\' ) {
      s1_push(i);
    } else if ( s1_top > 0 && c == '/') {
      j = s1_pop();
      b = i - j;
      sum += b;
      while ( s2_top > 0 && s2_Top().insidedx > j) {
    b += s2_pop().buff;
      }
      s2_push(j, b);
    }
    i++;
  }

  printf("%d\n", sum);
  printf("%d", s2_top);
  for ( i = 0 ; i < s2_top; i++ ) {
    printf(" ");
    printf("%d", S2[i].buff);
  }
  printf("\n");

  return 0;
}

Measured memory_bytes: 648
import sys
from collections import *
import heapq
import math
import bisect
from itertools import permutations,accumulate,combinations,product
from fractions import gcd
def input():
    return sys.stdin.readline()[:-1]
def ruiseki(lst):
    return [0]+list(accumulate(lst))
mod=pow(10,9)+7
al=[chr(ord('a') + i) for i in range(26)]

s=input()
if s[2]==s[3] and s[4]==s[5]:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 65900
#include <stdio.h>
int main(void) {
    int n, k;
    int cnt = 0;
    scanf("%d %d", &n, &k);
    for (int i = 0; 1; i++) {
        if (i + k <= n) {
            cnt++;
        } else {
            break;
        }
    }
    printf("%d\n", cnt);
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;

int inf = 1000000000;

int main() {
    int h, w;
    cin >> h >> w;
    string s[h];
    for (int i = 0; i < h; i++) {
        cin >> s[i];
    }

    int dp[h][w];
    for (int i = 0; i < h; i++) for (int j = 0; j < w; j++) {
        dp[i][j] = inf;
    }

    if (s[0][0] == '#') dp[0][0] = 1;
    else dp[0][0] = 0;
    for (int i = 0; i < h; i++) for (int j = 0; j < w; j++) {
        if (i == 0 && j == 0) continue;
        if (i > 0) {
            if (s[i-1][j] == '.' && s[i][j] == '#') dp[i][j] = min(dp[i][j], dp[i-1][j] + 1);
            else dp[i][j] = min(dp[i][j], dp[i-1][j]);
        }
        if (j > 0) {
            if (s[i][j-1] == '.' && s[i][j] == '#') dp[i][j] = min(dp[i][j], dp[i][j-1] + 1);
            else dp[i][j] = min(dp[i][j], dp[i][j-1]);
        }
    }

    cout << dp[h - 1][w - 1] << endl;
    return 0;
}

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

void solve()
{
	int n, y;
	cin >> n >> y;
	for (int i = 0; i <= n; i++)
	{
		for (int j = 0; i + j <= n; j++)
		{
			if (i * 10000 + j * 5000 + (n - i - j) * 1000 > y) break;
			if (i * 10000 + j * 5000 + (n - i - j) * 1000 == y)
			{
				cout << i << " " << j << " " << n - i - j << "\n";
				return;
			}
		}
	}
	cout << "-1 -1 -1\n";
}

int main()
{
	solve();
}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <stdio.h>
#include <algorithm>
#include <functional>
#include <cstdlib>
#include <stdlib.h>
#include <ctime>
#include <list>
#include <queue>
#include <bitset>
#include <set>
#include <map>
#define INF 10000000
#define I64 long long int
#define rep(i) for(I64 i=0;;++i)
#define repn(i,n) for(I64 i=0;i<(n);++(i))
using namespace std;

typedef pair<string, int> P;

bool coprime(int a, int b){
	int r, temp;
	if(a < b){
		temp = a;
		a = b;
		b = temp;
	}
	do{
		r = a % b;
		a = b;
		b = r;
	}while(r);
	if(a == 1) return true;
	else return false;
}

int main(){
	char t[26];

	int n;
	cin >> n;

	scanf("%*c");

	repn(i, n){
		string input;
		getline(cin, input);
		int len = input.size();

		bool flag = false;
		rep(a){
			if(coprime(26, a+1)){
				repn(b, 26){
					string res = "";
					repn(r, 26){
						t[r] = ((a+1) * r + b) % 26 + 'a';
					}
					repn(j, len){
						if(input[j] == ' ') res += ' ';
						else{
							repn(k, 26){
								if(input[j] == t[k]){
									res += k + 'a';
									break;
								}
							}
						}
					}
					if(res.find("this") != string::npos || res.find("that") != string::npos){
						cout << res << endl;
						flag = true;
						break;
					}
				}
				if(flag) break;
			}
			if(flag) break;
		}
	}
}

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

using namespace std;

int main(){
  long long N, M, value;
  cin>>N;
  vector<int>count(N);
  for(int i = 0; i < N-1; i++){
    cin>>value;
    count[value-1]++;
  }
  for(int i = 0; i < N; i++)
    cout<<count[i]<<' ';
}

Measured memory_bytes: 4056
# = int(input())
# = map(int, input().split())
# = list(map(int, input().split()))
# = list(input())
# = [tuple(map(int, input().split())) for _ in range(n)]

n = int(input())

d = [[0 for _ in range(10)] for _ in range(10)]
for i in range(1, n+1):
    temp = list(str(i))
    h = int(temp[0])
    t = int(temp[-1])
    if t != 0:
        d[h][t] += 1

ans = 0
for i in range(1, 10):
    for j in range(1, 10):
        ans += d[i][j] * d[j][i]

print(ans)

Measured memory_bytes: 40684
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 1e9
#define ALL(v) v.begin(), v.end()

using namespace std;
typedef long long ll;

int main(){
    int h, w;
    cin >> h >> w;
    string grid[100];
    REP(i, h){
        cin >> grid[i];
    }

    vector<int> keeprow(h, 0);
    vector<int> keepcol(w, 0);

    REP(i, h){
        REP(j, w){
            if (grid[i][j] == '#'){
                keeprow[i] = 1;
                keepcol[j] = 1;
            }
        }
    }

    REP(i, h){
        REP(j, w){
            if (keeprow[i] == 1  && keepcol[j] == 1){
                cout << grid[i][j];
            }
        }
        if (keeprow[i] == 1) cout << endl;
    }



}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
#define ordered_set tree<int,null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 
#define ordered_set_pair tree<pair<int,int>,null_type,less<pair<int,int>>, rb_tree_tag,tree_order_statistics_node_update> 
#define ordered_set_mutiset tree<int,null_type,less_equal<int>, rb_tree_tag,tree_order_statistics_node_update>
typedef long long int ll;
typedef long double ld;
typedef unsigned long long int ull;
typedef pair<int,int> pi; 
#define PI 3.1415926535897932384
#define FOR(i,vv,n) for(ll i=vv;i<n;i++)
#define FORR(i,n,vv) for(ll i=n-1;i>=vv;i--)
#define ve vector 
#define maxind(v) (max_element(v.begin(),v.end())-v.begin())
#define minind(v) (min_element(v.begin(),v.end())-v.begin())
#define maxe(v) *max_element(v.begin(),v.end())
#define mine(v) *min_element(v.begin(),v.end())
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define eb emplace_back
#define FAST ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define mp make_pair
#define M 1000000007ll
#define INF 1000000000000000000ll
#define PRECISE cout.precision(18);
#define all(v) v.begin(),v.end()
#define BS(v,n) binary_search(all(v),n)
#define srt(v) sort(v.begin(),v.end())
#define rsrt(v) sort(all(v),greater <ll>())
#define uni(v) v.resize(unique(all(v))-v.begin())
#define F first
#define S second
#define GET(i,p) get<p>(i)


int main(){

	#ifndef ONLINE_JUDGE
    // for getting input from input.txt	
    freopen("input.txt", "r", stdin);
    // for writing output to output.txt
    freopen("output.txt", "w", stdout);
	 #endif

    FAST
	//PRECISE



string s;
cin>>s;
ll ans=0;
ll co=0;
if(s[0]=='R')co++;
if(s[1]=='R')co++;
if(s[2]=='R')co++;
if(co==3)ans=3;
if(co==1)ans=1;
if(co==2&&s[1]=='S')ans=1;
if(co==2&&s[1]=='R')ans=2;
cout<<ans;






return 0;
 }
 

Measured memory_bytes: 3648
#include <iostream>
#include <cstdio>
#include <algorithm>

using namespace std;

#define M 110000

int main(){
  int N, a[M], num=0, i, val=0;
  cin >> N;
  for (i = 0; i < N; i++)
    cin >> a[i];
  sort(a, a+N);
  i = 0;
  while (i < N){
    int p=0, cc = a[i];
    while (i < N && a[i] == cc){
      p ++;
      i++;
    }
    num += p%2;
  }

  cout << num << endl;
  return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
 
#define REP(i,n) for(int (i)=0;(i)<(n);(i)++)      //repeat n times
#define REP2(i,s,n) for(int (i)=(s);(i)<(n);(i)++) //repeat from s to n 
#define REPD(i,n) for(int (i)=(n);(i)>=0;(i)--)    //repeat from n to 0
#define REPD2(i,s,e) for(int (i)=(s);(i)>=(e);(i)--) //repeat from s to e
#define ASIZE(a) (sizeof(a) / sizeof(a[0]))        //array size
#define SORTD(a) sort(a,a+ASIZE(a),greater<int>()) //sort in descending order for array
#define SORTA(a) sort(a,a+ASIZE(a))                //sort in ascending order for array
#define SORTS(a) sort(a.begin(),a.end())           //sort in ascending order for string type
typedef long long LL;
typedef unsigned int UINT;
 
void SCAN(int *a){scanf("%d",a);}                             //scan for type int
void SCAN(int *a,int n){int i;REP(i,n){scanf("%d",&a[i]);}}   //scan for type int array
void SCAN(UINT *a){scanf("%u",a);}                            //scan for type unsigned int
void SCAN(UINT *a,int n){int i;REP(i,n){scanf("%u",&a[i]);}}  //scan for type unsigned int array
void SCAN(LL *a){scanf("%lld",a);}                            //scan for type long long int
void SCAN(LL *a,int n){int i;REP(i,n){scanf("%lld",&a[i]);}}  //scan for type long long int array
void SCAN(char *c){scanf(" %c",c);}                           //scan for type char
void SCAN(char *c,int n){int i;REP(i,n){scanf(" %c",&c[i]);}} //scan for type char array
 
const int MOD = 1000000007;
const int INF = 1000000000;
 
const int DX4[4]= {-1,0,0,1};
const int DY4[4]= {0,-1,1,0};
 
//fill an N-dimensional array with val
template<typename A, size_t N, typename T>
void FILL(A (&array)[N], const T &val){
	fill((T*)array,(T*)(array+N),val);
}
 
int pascalTri(int n,int r){
	int tri[n+1][n+1];
	int i,j;
	REP(i,n+1){REP(j,n+1){tri[i][j]=0;}}
	REP(i,n+1){
		REP(j,n+1){
			if(j>i){break;}
			if(j==0||j==i){tri[i][j]=1;}else{tri[i][j]=(tri[i-1][j-1]%MOD+tri[i-1][j]%MOD)%MOD;}
		}
	}
	return tri[n][r];
}
 
 
int main(){
	// cin.tie(0);
	// ios::sync_with_stdio(false);
	char x,y;
	int i,j;
	
	SCAN(&x);SCAN(&y);

	int tmp_x=(int)x;
	int tmp_y=(int)y;
	if(tmp_x==tmp_y){
		printf("=\n");
	}else if(tmp_x<tmp_y){
		printf("<\n");
	}else{
		printf(">\n");
	}
 
	return 0;
}

Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))

n_neg = sum([1 for i in range(n) if a[i] < 0])
if n_neg%2 == 0:
    ans = sum([abs(aa) for aa in a])
else:
    min_abs = min([abs(aa) for aa in a])
    ans = sum([abs(aa) for aa in a]) - 2*min_abs
print(ans)


Measured memory_bytes: 14332
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int INF = 1e10;
const int MOD = 1e9 + 7;
#define dump(x) cout << #x << " = " << (x) << endl;
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define pb push_back
#define all(v) (v).begin(), (v).end()
#define P pair<int, int>
#define V vector<int>
#define S set<int>
int N, M, a[100010], d[100010];
void solve()
{
}

signed main()
{
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cin >> N >> M;
    FOR(i, 0, M)
    {
        int x;
        cin >> x;
        a[x]++;
    }
    d[1] = 1;
    FOR(i, 2, N + 2)
    {
        if (a[i - 1] == 0) {
            d[i] = d[i - 1] + d[i - 2];
            d[i] %= MOD;
        }
    }
    cout << d[N + 1] << endl;
    solve();
    return 0;
}


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

typedef pair<int, int> ii;
typedef pair<int, ii> iii;
typedef vector<ii> vii;
typedef vector<int> vi;
typedef long long ll;
typedef long double ld;
typedef vector<ll> vll;
typedef pair<ll,ll> lll;

ll MOD = 1000000007;
const ll INF = 1e9+5;
const double eps = 1e-7;
const double PI = acos(-1.0);

#define FOR(i,a,b) for(long long i = (long long)(a); i < (long long)(b); i++)
#define RFOR(i,a,b) for(long long i = (long long)(a); i >= (long long)(b); i--)
#define ull unsigned long long
#define deb(x )     cerr << #x << " = "<< x << endl;
#define endl    "\n"
#define coud(a,d) cout << fixed << showpoint << setprecision(d) << a;
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define fill(x, y) memset(x, y, sizeof(y))
#define all(x) (x).begin(), (x).end()
#define bitcount(x) __builtin_popcount(x)
#define cps CLOCKS_PER_SEC
#define verify(x) if(x >= MOD) x -= MOD;

inline void debug_vi(vi a) {FOR(i, 0, a.size()) cout<<a[i]<<" ";}
inline void debug_vll(vll a) {FOR(i, 0, a.size()) cout<<a[i]<<" ";}
inline void print_case(int tn) {cout<<"Case #"<<tn<<": ";}

template<typename T>
using minpq = priority_queue<T, vector<T>, greater<T>>;

template<typename T>
using maxpq = priority_queue<T>;
/*----------------------------------------------------------------------*/

const int nax = 2e5+5;
ll arr[nax], n;

int main(){
    std::ios::sync_with_stdio(false);cin.tie(NULL); cout.tie(NULL);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    clock_t clk = clock();
    ll res = 0;
    cin>>n>>MOD;
    string s; cin>>s;
    if(MOD == 2 || MOD == 5) {
        FOR(i, 0, n) {
            if((s[i] - '0') % MOD == 0) {
                res += (i + 1);
            }
        }
        cout<<res; return 0;
    }
    ll mult = 1;
    unordered_map<int,int> freq;
    RFOR(i, n - 1, 0) {
        arr[i] = (mult * (s[i] - '0'))%MOD;
        if(i != n - 1) arr[i] += arr[i+1]; 
        arr[i] %= MOD;
        mult *= 10; mult %= MOD;
        freq[arr[i]]++;
        // deb(arr[i]);
    }
    for(auto itr : freq) {
        res += itr.second * 1LL * (itr.second - 1) / 2;
        if(itr.ff == 0) res += itr.ss;
    }
    cout<<res;
    cerr << endl << "Time (in ms): " << double(clock() - clk) * 1000.0 / cps << endl;
    return 0;
}

Measured memory_bytes: 2452
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <queue>
#include <deque>
#include <list>
#include <map>
#include <set>
#include <cmath>
#include <cstring>
#include <string>
#include <bitset>
#include <fstream>
#include <iomanip>

using namespace std;

typedef long long ll;
typedef long double db;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<double,double> pdd;
typedef vector<pii> vii;

#define INF 1000000007ll
#define pb push_back
#define mp make_pair
#define err(x) cout<<#x<<"= "<<x<<endl;
#define rep(i,n) for(int i =0; i< n; i++)
#define ff first
#define ss second
#define cil(a,b) ( ((a)%(b) == 0)?((a)/(b)):((a)/(b)+1) )
#define SIZE 100010

int main(){
	ios::sync_with_stdio(false);
	ll A[4],n,ans=0;
	cin>>A[0]>>A[1]>>A[2]>>A[3];
	cin>>n;
	n*=4;
	if(A[3]<=min(min(8*A[0],4*A[1]),2*A[2])){
		ans+= A[3]*(n/8);
		n%=8;
	}
	if(A[2]<=min(2*A[1],4*A[0])){
	//	cout<<"here"<<' '<< A[2]<<' '<<n/4<<endl;
		ans+= A[2]*(n/4);
		n%=4;
	}
	if(A[1]<=2*A[0]){
		ans+= A[1]*(n/2);
		n%=2;
	}
	ans+= A[0]*n;
	cout<<ans<<endl;

	return 0;
}


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

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

  int64_t a = 2, b = 1, c = 3;
  for (int i = 1; i < n; i++) {
    a = b;
    b = c;
    c = a + b;
  }
  cout << b << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i, l, r) for(ll i = l; i < r; i++)
#define rep(i, N) FOR(i, 0, N)
using namespace std;

typedef long long ll;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<ll> vl;
const ll MOD = round(1e9+7);

int main() {
    string S, T; cin >> S >> T;
    ll ans = 0;
    rep(i,S.size()){
        if(S[i] != T[i]) ans++;
    }

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


Measured memory_bytes: 3872
#include<cstdio>
#include<cmath>
#include<vector>
#include<iostream>
#include<queue>

using namespace std;

#define PII pair<int,int>

queue<PII> Q;

int main(void){
	
	int D;
	char m[16][16];
	
	while(scanf("%d",&D) != EOF){
		
		for(int a = 1; a <= D; a++){
			
			int dx[12] = {-3,-2,-1, 0, 0, 0, 0, 0, 0, 1, 2, 3};
			int dy[12] = { 0, 0, 0, 3, 2, 1,-1,-2,-3, 0, 0, 0};
			int x,y;
			
			for(int i = 1; i < 9; i++){
				scanf("%s",m[i]+1);
			}
			
			scanf("%d %d", &x, &y);
			Q.push(PII(y,x));
			
			while(!Q.empty()){
		//		cout << Q.size() << endl;
				y = Q.front().first;
				x = Q.front().second;
				Q.pop();
				
				if(m[y][x] == '1'){
					m[y][x] = '0';
					for(int i = 0; i < 12; i++){
						if(0 < y+dy[i] && y+dy[i] < 9 && 0 < x+dx[i] && x+dx[i] < 9){
							Q.push(PII(y+dy[i],x+dx[i]));
						}
					}
				}
			}
			
			printf("Data%2d:\n",a);
			for(int i = 1; i < 9
			; i++){
				puts(m[i]+1);
			}
		}
	}
	return 0;
}

Measured memory_bytes: 0
for i in range(50):
    a,b,c = map(int,input().split())
    d = a+b
    if a == b == c == -1:
        exit()
    elif a == -1 or b == -1 or d < 30:
        print("F")
    elif 80 <= d:
        print("A")
    elif 65 <= d < 80:
        print("B")
    elif 50 <= d < 65 or (30 <= d < 50 and 50 <= c):
        print("C")
    elif 30 <= d < 50:
        print("D")
    


Measured memory_bytes: 5592
#include <stdio.h>

int main(void)
{
	int n, i, a[100];
	
	scanf("%d", &n);
	
	for (i = 0; i < n; i++) {
		scanf("%d", &a[i]);
	}
	
	for (i = n - 1; i > 0; i--){
		printf("%d ", a[i]);
	}
	printf("%d\n", a[0]);
	
	return 0;
}

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

#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rep2(i,s,n) for(int i = (s); i < (n); ++i)
#define ll long long
#define ld long double
#define P pair<ll,ll>
#define all(v) v.begin(),v.end()

const ll mod = 1e9+7;
const ll INF = 1e18;
const double pi = acos(-1.0);

int main(void)
{
    ll n; cin>>n;
    map<string,ll> mp;
    rep(i,n){
        string s; cin>>s;
        mp[s]++;
    }
    
    cout<<"AC x "<<mp["AC"]<<endl;
    cout<<"WA x "<<mp["WA"]<<endl;
    cout<<"TLE x "<<mp["TLE"]<<endl;
    cout<<"RE x "<<mp["RE"]<<endl;
    
    return 0;
}

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

int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  int k;
  vector<int> v;
  int tmp;
  while (cin >> tmp) v.push_back(tmp);
  k = v[v.size() - 1];
  v.pop_back();
  
  for (int i = 0; i < v.size() - 1; i++) {
      for (int j = i + 1; j < v.size(); j++) {
          if (abs(v[j] - v[i]) > k) {
              cout << ":(" << endl;
              return 0;
          }
      }
  }
  cout << "Yay!" << endl;
        
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define INCANT cin.tie(0), cout.tie(0), ios::sync_with_stdio(0), cout << fixed << setprecision(20);
#define int long long
const int INF = 1e18, MOD = 998244353;
signed main() {
    int a, b, c;
    cin>>a>>b>>c;
    if (c - a - b < 0) {
        cout<<"No"<<endl; return 0;
    }
    if (4 * a * b < (c - a - b) * (c - a - b)) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}

Measured memory_bytes: 256
n=int(input())
a=list(map(int,input().split()))
m=max(a)
cnt=[0 for _ in range(m+1)]
ans=0
for i in a:
    if cnt[i]>=1:
        cnt[i]+=1
        continue
    for j in range(2*i,m+1,i):
        cnt[j]+=1
    cnt[i]=1
for i in range(n):
    if cnt[a[i]]==1:
        ans+=1
print(ans)

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

#define pb push_back
#define eb emplace_back

typedef long long ll;
typedef unsigned long long ull;

using namespace std;

ll bp(ll a, ll d, ll m) {
    if (d == 0) {
        return 1;
    }
    auto h = bp(a, d / 2, m);
    auto hh = (h * h) % m;
    if (d % 2) {
        hh = (hh * a) % m;
    }
    return hh;
}


void oneCase() {
    int n, m;
    cin >> n >> m;
    vector<int> a(m);
    for (auto& el : a) {
        cin >> el;
    }
    auto t = accumulate(a.begin(), a.end(), 0);
    if (t > n) {
        cout << -1 << "\n";
        return;
    }
    cout <<  n - t<< "\n";
}

int main() {
//    std::ios::sync_with_stdio(false);
//    std::cin.tie(nullptr);

    int t = 1;
//    cin >> t;
    while (t--) {
       oneCase();
    }

    return 0;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   FOR(i,0,n)
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<int,int> pint;

map<int,int> a;
int main(){
    int n,ai;
    cin>>n;
    rep(i,n){
        cin>>ai;
        if(a[ai]==1) a[ai]=0;
        else a[ai]=1;
    }
    int sum=0;
    for(map<int,int>::iterator it=a.begin();it!=a.end();++it) sum+=it->second;
    cout<<sum<<endl; 
    return 0;
}

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

const ll inf = (1 << 30) - 1;
ll dp[1010][1003];
int N, M, Q, l, r;

int main()
{
    cin >> N >> Q;
    string s;
    cin >> s;
    vector<int> a(N + 1);
    for (int i = 1; i < N; i++)
    {
        if (s[i - 1] == 'A' && s[i] == 'C')
            a[i]++;
    }
    for (int i = 0; i < N; i++)
    {
        a[i + 1] += a[i];
    }
    for (int i = 0; i < Q; i++)
    {
        cin >> l >> r;
        l--, r--;
        cout << a[r] - a[l] << endl;
    }
}

Measured memory_bytes: 1408
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e16;

/*
<url:https://abc087.contest.atcoder.jp/tasks/abc087_a>
問題文============================================================
 あなたは、X 円を持ってケーキとドーナツを買いに出かけました。
 
 あなたはまずケーキ屋で 1 個 A 円のケーキを 1 個買いました。
 次に、ドーナツ屋で 1 個 B 円のドーナツをできるだけたくさん買いました。
 
 これらの買い物のあと手元に残っている金額は何円ですか。
=================================================================

解説=============================================================
 やるだけ
 
 ans := (X-A)%B
================================================================
*/
int main(void) {
	cin.tie(0); ios::sync_with_stdio(false);
    ll X,A,B; cin >> X >> A >> B;
    cout << (X-A)%B << endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <math.h>
#include <cstdlib>
#define rep(i,n) for(int i = 0;i<(n);i++);
#define all(a) (a).begin(),(a).end()
using namespace std;
using ld = long double;
using ll = long long;
const ll INF = 100100100100100;
ll cost(vector<ll> n, ll m) {
	ll ans = 0;
	ll big = n.size();
	for (int i = 0; i < big; i++) {
		ans += pow(m - n[i], 2);
	}
	return ans;
}
int main() {
	ll N;
	cin >> N;
	vector<ll> num(N);
	ll avr1 = 0,avr2 = 0;
	for (int i = 0; i < N; i++) {
		cin >> num[i];
		avr1 += num[i];
	}
	avr1 /= N;
	avr2 = avr1 + 1;
	ll cnt = min(cost(num, avr1), cost(num, avr2));
	cout << cnt << endl;
}

Measured memory_bytes: 256
def main():
    n, k = map(int, input().split())

    res = 0
    for b in range(k + 1, n + 1):
        tail = max(0, (n % b) - k + 1)
        body = (b - k) * (n // b)
        res += body + tail - (k == 0)

    print(res)


if __name__ == "__main__":
    main()


Measured memory_bytes: 2940
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#define int long long
#define mod 1000000007
using namespace std;
signed main() {
	int n, h[123456], ans = 0, cnt = 0; cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> h[i];
		if (!i)cnt++;
		else if (h[i] <= h[i - 1])cnt++;
		else {
			ans = max(ans, cnt);
			cnt = 1;
		}
	}
	cout << max(ans, cnt)-1 << endl;
}

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

#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
#define hash dhsjakhd
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef long double ld;

unsigned seed = std::chrono::system_clock::now().time_since_epoch().count();
std::mt19937 eng(seed);
uniform_int_distribution<> DD(0, 1000000000);

ll random(ll r){
    return (ll(DD(eng))*1000000000 + ll(DD(eng)))%r;
}

ll n,m,T,k,q;

const ll big = 1000000007;
const ll big2 = 1000000009;
const ll mod =  998244353;

ll I[100001] = {0};
vl ind;
vl A;
vector<vl> C(100001, vl());

bool comp(ll i, ll j){
    return A[i] < A[j];
}

ll j = 0;

ll solve(ll i, ll par){
    ll temp = 0;
    for(int c1 = 0; c1 < sz(C[i]); c1++){
        ll a = C[i][c1];
        if(a != par){
            temp += solve(a,i);
        }
    }
    if(par != -1){
        temp += A[ind[j]];
    }
    I[i] = ind[j];
    j++;
    return temp;
}

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

    //freopen("input.txt","r",stdin);
   // freopen("autput.txt","w",stdout);

    ll a,b,c,d;

    cin >> n;
    ll root = 0;
    for(int c1 = 0; c1 < n-1; c1++){
        cin >> a >> b;
        a--;
        b--;
        C[a].push_back(b);
        C[b].push_back(a);
        if(sz(C[a]) > 1)root = a;
        if(sz(C[b]) > 1)root = b;
    }

    rep(c1,0,n){
        cin >> a;
        A.push_back(a);
        ind.push_back(c1);
    }
    sort(all(ind),comp);
    ll ans = solve(root,-1);
    cout << ans << "\n";
    for(int c1 = 0; c1 < n; c1++){
        cout << A[I[c1]] << " ";
    }cout << "\n";

    return 0;
}


Measured memory_bytes: 3840
function Main(input) {
	input = input.split("\n");
	tmp = input[0].split(" ");
	var number = input[1].split(" ");
	var answer = 0;
	for(var i=0;i<tmp;i++){
      answer = answer + 1/number[i];
    }
	answer = 1/answer;
	console.log(answer);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 7372
import math
N,M=map(int,input().split())
def combinations_count(n, r):
  return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
ans=0
if N>1:
  ans+=combinations_count(N, 2)
if M>1:
  ans+=combinations_count(M, 2)
print(ans)

Measured memory_bytes: 3188
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<n; i++)
#define PI 3.14159265359
#define INF 1000100100000000000
#define MOD 1000000007
#define all(x) (x).begin(),(x).end()
typedef long long ll;
#define P pair<int, int>
#define PP pair<P,P>
#define T tuple<int,int,int> 
using namespace std;

int main(){
    int n; ll w; cin >> n >> w;
    vector<vector<int> > ob(4);
    ll a,b; cin >> a >> b;
    a--;
    ob[0].push_back(b);
    rep(i,n-1){
        int o; int v; cin >> o >> v;
        ob[o-a-1].push_back(v);
    }
    rep(i,4){
        sort(all(ob[i]));
        reverse(all(ob[i]));
    }

    int ans=0;

    rep(i,ob[0].size()+1){
        rep(j,ob[1].size()+1){
            rep(z,ob[2].size()+1){
                rep(k,ob[3].size()+1){
                    int tmp=0;
                    rep(ii,i) tmp+=ob[0][ii];
                    rep(jj,j) tmp+=ob[1][jj];
                    rep(zz,z) tmp+=ob[2][zz];
                    rep(kk,k) tmp+=ob[3][kk];
                    ll tmpw=(ll)(i*(a+1))+(ll)(j*(a+2))+(ll)(z*(a+3))+(ll)(k*(a+4));
                    if(tmpw<=w) ans=max(ans,tmp);
                }
            }
        }
    }

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



Measured memory_bytes: 3564
#include<iostream>
#include<iomanip>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
#include<cstring>
#include<sstream>
using namespace std;
 
#define P(p) cout<<(p)<<endl
#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define rrep(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define vsort(v) sort(v.begin(), v.end());
#define rvsort(v) sort(v.begin(), v.end(),greater<int>());
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define ret return
#define lb(v,n) lower_bound(v.begin(),v.end(),n)
#define ub(v,n) upper_bound(v.begin(),v.end(),n)
#define mae(v) max_element(v.begin(),v.end())
#define mie(v) min_element(v.begin(),v.end())
#define INF 0x7FFFFFFF
#define mod 1000000007
typedef long long ll;
////////////////////////////////////////////////////////////
const int MAX_V = 100;
vector<vector<ll>> dp(MAX_V,vector<ll>(MAX_V,INF));
//d[[i][j]:i,j間の最短経路
int E,V; //頂点数
vector<vector<ll>> nxt(MAX_V,vector<ll>(MAX_V));
bool root[MAX_V][MAX_V];
void wf(){
	rep(k,0,V){
		rep(i,0,V){
			rep(j,0,V){
				if(dp[i][j] > dp[i][k] + dp[k][j] ){
					dp[i][j] = dp[i][k] + dp[k][j];
					nxt[i][j] = nxt[i][k];
				}
			}
		}
	}
}

void printPath3(int start , int goal ){
	int bef = start;
	for(int cur = start ; cur != goal ; cur = nxt[cur][goal] ){
		//cout << cur << " ";
		root[bef][cur] = 0;
		root[cur][bef] = 0;
		bef = cur;
	}
	//cout << goal << endl;
	root[bef][goal] = 0;
	root[goal][bef] = 0;
}

//入力
void make(){
	rep(i,0,V)
		dp[i][i] = 0;
	
	rep(i,0,E){
		int u,v,c;
		cin>>u>>v>>c;
		u--; v--;
		dp[u][v] = c;
		dp[v][u] = c;
		root[u][v] = 1;
		root[v][u] = 1;
	}
}

int main(){
	cin >> V >> E;
	make();
	
	rep(i,0,V){
		rep(j,0,V){
			nxt[i][j] = j;
		}
	}
	
	wf();
	rep(i,0,V){
		rep(j,0,V){
			printPath3(i,j);
		}
	}
	
	ll sum = 0;
	rep(i,0,V) rep(j,0,V) if(root[i][j]) sum++;
	
	P(sum/2);

	ret 0;
}

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

using namespace std;

int main()
{
  	int a[3][3];
  
  	for(int i=0;i<3;i++)
    {
      	for(int j=0;j<3;j++)
          	cin >> a[i][j];
   	}
  	
  	int q;
  	cin >> q;
  	
  	for(int i=0;i<q;i++)
    {
      	int k;
      	cin >> k;
      	
      	for(int i=0;i<3;i++)
        {
          	for(int j=0;j<3;j++)
            {
              	if(k==a[i][j])
                {
                  a[i][j] = -1;
                }
            }
        }
    }
  	
  bool f1=0;
  	for(int i=0;i<3;i++)
    {
      bool f=1;
      for(int j=0;j<3;j++)
      {
        if(a[i][j]!=-1)
          f=0;
      }
      if(f)
      {
        f1=1;
        break;
      }
    }
  
  	for(int i=0;i<3;i++)
    {
      bool f=1;
      for(int j=0;j<3;j++)
      {
        if(a[j][i]!=-1)
          f=0;
      }
      if(f)
      {
        f1=1;
        break;
      }
    }
  	
  	if(a[0][0]==-1 && a[1][1]==-1 && a[2][2]==-1)
      	f1=1;
 	if(a[2][0]==-1 && a[1][1]==-1 && a[2][0]==-1)
      	f1=1;
  
  	if(f1)
      cout << "Yes" << endl;
 	else
      cout << "No" << endl;
  	
  	return 0;
}

Measured memory_bytes: 256
N, M = map(int, input().split())
switches = []
for i in range(M):
    _, *switch = map(int, input().split())
    switches.append(switch)
condition = [int(x) for x in input().split()]
cnt = 0
for status in range(2 ** N):
    satisfied = False
    for i, switch in enumerate(switches):
        total_status = sum([1 & (status >> (s - 1)) for s in switch])
        if condition[i] != total_status % 2: break
        elif i == len(switches) - 1: satisfied = True
    if satisfied: cnt += 1
print(cnt)

Measured memory_bytes: 3064
'''
条件に合うものを絞り込む
data = [1, 2, 3]
s = [x for x in data if x % 3 == 0]
'''
'''
文字配列を数値に
l_si = ['-10', '0', '100']

l_si_i = [int(s) for s in l_si]
'''
'''
a = [2, 4, 6, 8]
b = [3, 6, 9]

print(list(set(a) | set(b)))  # 和集合
print(list(set(a) & set(b)))  # 積集合
'''
'''
N = int(stdin.readline().rstrip())
A = [int(x) for x in stdin.readline().rstrip().split()]
count = 0
while len([x for x in A if x % 2 == 0]) == N:
    A = list(map(lambda y: y / 2, A))
    count += 1
print(count)
'''
'''
.append(要素)
.extend(要素)
.insert(場所,要素)
del 配列名[場所]
-1で末尾で末尾から一つ前
'''
'''
間に空白追加
' '.join(lis)
'''
'''
copy.copy(配列名)
'''
'''
sort()
sorted(reverse=true)
'''
'''
2分探索
bisect.bisect_left(リスト, 要素)
'''
'''
リスト同士の演算
list(map(lambda x, y: x+y, el2, el3))
'''
'''
配列の初期化
配列名=[a]*n+[b]*m
'''
'''
重複
list(set())
２次元配列
list(map(list, set(map(tuple, addition))))
'''
'''
順列
for el in itertools.permutations(配列のパターン):
'''
'''
Decimal()
'''
# 入力 =stdin.readline().rstrip()
# 分割 = stdin.readline().rstrip().split()




from sys import stdin
from itertools import accumulate, dropwhile, takewhile, groupby
import bisect
import copy
import math
import itertools
from functools import reduce
from operator import mul
def gcd(*numbers):
    return reduce(math.gcd, numbers)


def gcd_list(numbers):
    return reduce(math.gcd, numbers)


def lcm_base(x, y):
    return (x * y) // math.gcd(x, y)


def lcm(*numbers):
    return reduce(lcm_base, numbers, 1)


def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)


def get_unique_list(seq):
    seen = []
    return [x for x in seq if x not in seen and not seen.append(x)]


d = stdin.readline().rstrip().split()
a = d[0]
b = d[1]
ad = a * int(b)
bd = b * int(a)
data = [ad, bd]
data.sort()
print(data[0])


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

// 最小公倍数を求める
int euqlid (int a, int b){
  int temp;
  temp = a % b;
  if(temp == 0)return b;
  return euqlid(b,temp);
}

int main(){
  string s,t,u;
  int a,b;
  cin >> s >> t;
  cin >> a >> b;
  cin >> u;
  if(u == s){
    a--;
  }
  else{
    b--;
  }
  printf("%d %d\n",a,b);
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    long k = sc.nextLong();
    long[] a = new long[n];
    long g = 1;
    for(int i = 0; i < n; i++) {
      a[i] = sc.nextLong();
      if(i == 0) {
        g = a[0];
      } else {
        g = gcd(g, a[i]);
      }
    }
    String ans = "IMPOSSIBLE";
    for(int i = 0; i < n; i++) {
      if(a[i] >= k) {
        if(((a[i] - k) % g) == 0) ans = "POSSIBLE";
      }
    }
    System.out.println(ans);
  }

  public static long gcd(long a, long b) {
    if(b == 0) return a;
    return gcd(b, a % b);
  }
}


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

namespace AtCorder
{
	public class Program
	{
		static void Main(string[] args)
		{
			Scanner cin = new Scanner();
			int n = cin.Int();
			int a = cin.Int();
			int b = cin.Int();

			Console.WriteLine(Math.Min(n * a, b));
		}
	}

	public class Scanner
	{
		string[] s;
		int i;

		char[] cs = new char[] { ' ' };

		public Scanner()
		{
			s = new string[0];
			i = 0;
		}

		public string Next()
		{
			if (i < s.Length) return s[i++];
			string st = Console.ReadLine();
			while (st == "") st = Console.ReadLine();
			s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
			if (s.Length == 0) return Next();
			i = 0;
			return s[i++];
		}

		public int Int()
		{
			return int.Parse(Next());
		}
		public int[] ArrayInt(int N, int add = 0)
		{
			int[] Array = new int[N];
			for (int i = 0; i < N; i++) {
				Array[i] = Int() + add;
			}
			return Array;
		}

		public long Long()
		{
			return long.Parse(Next());
		}

		public long[] ArrayLong(int N, long add = 0)
		{
			long[] Array = new long[N];
			for (int i = 0; i < N; i++) {
				Array[i] = Long() + add;
			}
			return Array;
		}

		public double Double()
		{
			return double.Parse(Next());
		}


		public double[] ArrayDouble(int N, double add = 0)
		{
			double[] Array = new double[N];
			for (int i = 0; i < N; i++) {
				Array[i] = Double() + add;
			}
			return Array;
		}
	}
}


Measured memory_bytes: 13140