akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i,m,n) for(ll i = (m); i < (n); i++)
#define all(v) v.begin(), v.end()
#define print(x) cout << (x) << endl
//宣言
int N,cnt1,cnt2,cnt3;
ll x,a1,a2,a3;
bool valid1 = true,valid2 = false;

void solve(){
    if(valid1 && valid2) print("Yes");
    else print("No");
}

int main() {
    a1 = a2 = a3 = -1;
    cnt1 = cnt2 = cnt3 = 0;
    cin >> N;
    rep(i,N){
        cin >> x;
        if(x == a1) cnt1++;
        else if(x == a2) cnt2++;
        else if(x == a3) cnt3++;
        else if(a1 == -1){a1 = x;cnt1++;}
        else if(a2 == -1){a2 = x;cnt2++;}
        else if(a3 == -1){a3 = x;cnt3++;}
        else{valid1 = false;break;}
    }
    if(a2 == -1){
        if((a1^a1) == a1) valid2 = true;
    }else if(a3 == -1){
        if(a1 == 0 && cnt1*2 == cnt2) valid2 = true;
        if(a2 == 0 && cnt2*2 == cnt1) valid2 = true;
    }else if(cnt1 == cnt2 && cnt2 == cnt3){
        if((a1^a2) == a3) valid2 = true;
    }

    solve();
    return 0;
}


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

// region template
#define rep(i, a, b) for (int i = (a); i < (b); ++i)
#define trav(a, x) for (auto &a : x)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;

ll gcd(ll a, ll b) { return __gcd(a, b); }

ll euclid(ll a, ll b, ll &x, ll &y) {
    if (b) { ll d = euclid(b, a % b, y, x);
        return y -= a/b * x, d; }
    return x = 1, y = 0, a;
}

typedef unsigned long long ull;
typedef long double ld;
ull mod_mul(ull a, ull b, ull M) {
    ll ret = a * b - M * ull(ld(a) * ld(b) / ld(M));
    return ret + M * (ret < 0) - M * (ret >= (ll)M);
}
ull mod_pow(ull b, ull e, ull mod) {
    ull ans = 1;
    for (; e; b = mod_mul(b, b, mod), e /= 2)
        if (e & 1) ans = mod_mul(ans, b, mod);
    return ans;
}

const ll mod = 1000000007;
struct Mod {
    ll x;
    Mod(ll xx) : x(xx) {}
    Mod operator+(Mod b) { return Mod((x + b.x) % mod); }
    Mod operator-(Mod b) { return Mod((x - b.x) % mod); }
    Mod operator*(Mod b) { return Mod((x * b.x) % mod); }
    Mod operator/(Mod b) { return *this * invert(b); }
    Mod invert(Mod a) {
        ll x, y, g = euclid(a.x, mod, x, y);
        assert(g == 1); return Mod((x + mod) % mod);
    }
    Mod operator^(ll e) {
        if (!e) return Mod(1);
        Mod r = *this ^ (e / 2); r = r * r;
        return e & 1 ? *this * r : r;
    }
};
// endregion

int main() {
    ll x, y; cin >> x >> y;
    {ll g = __gcd(x, y); x /= g, y /= g;}
    ll ans = 1;
    for (ll i = 2; i * i <= y; i++) {
        if (y % i == 0) {
            ans *= i;
            while (y % i == 0) y /= i;
        }
    }
    ans *= y;
    cout << ans << endl;
}


Measured memory_bytes: 3112
import sys

Line = [int(s) for s in input().split()]

A,B,C,K = Line[0],Line[1],Line[2],Line[3]

ans = 0

if A >= K:
    ans += K
    print(ans)
    sys.exit()
else :
    ans += A
    K -= A

if B >= K:
    print(ans)
    sys.exit()
else :
    K -= B
    print(ans - K)

Measured memory_bytes: 9192
import bisect

n=int(input())
a=[int(x) for x in input().rstrip().split()]
dp=[0 for i in range(10**5)]
q=int(input())

for i in a:
  dp[i-1]+=1

ans=sum(a)
for i in range(q):
  b,c=map(int,input().split())
  ans=ans-(dp[b-1]*b)+(c*dp[b-1])
  dp[c-1]+=dp[b-1]
  dp[b-1]=0
  print(ans)


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

using namespace std;

#define rep(i, x)   for (__typeof(x) i = 0; i < x; i++)
#define mp             make_pair
#define pb             push_back
#define fi             first
#define se             second
#define sz(x)          (int)((x).size())
#define all(x)         (x).begin(), (x).end()
#define sci(x)         int x;       scanf("%d", &x);
#define scii(x, y)     int x, y;    scanf("%d %d", &x, &y);
#define sciii(x, y, z) int x, y, z; scanf("%d %d %d", &x, &y, &z);
#define TC(x)          sci(x); while(x --)
#define eprintf(...)   fprintf(stderr, __VA_ARGS__)
#define debug(x)       { cerr << #x << " = " << x << endl; }
#define repi(i, x)  for (__typeof(x) i = x-1; i >= 0; i --)
#define fore(itr, x)   for (__typeof(x.begin()) itr = x.begin(); itr != x.end(); itr ++)
#define forei(itr, x)  for (__typeof(x.end()) itr = x.end() - 1; itr != x.begin() - 1; itr --)
typedef long long      ll;
typedef pair<int, int> ii;
typedef pair<ii, int>  iii;
typedef vector<int>    vi;
typedef vector<ii>     vii;
typedef vector<iii>    viii;
typedef vector<vector<int> > vvi;
const   int            infi = numeric_limits<int>::max();
const   double         eps = 0;
const   int            ms  = 0;

int main()
{
    ios::sync_with_stdio(false);//endl->"\n"
    cin.tie(0);
    int N, H , W;
    cin >> N >> H >> W;
    vi A(N), B(N);
    int ans = 0;
    rep(i, N){
        cin >> A[i] >> B[i];
    }
    rep(i, N){
        if(A[i] >= H && B[i] >= W)ans++;
    }
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 256
N, M = map(int, input().split())
A = list(map(int, input().split()))
A.sort()
BC = [list(map(int, input().split())) for _ in range(M)]
BC.sort(key=lambda x:x[1], reverse=True)
D = []
for b, c in BC:
    D += [c]*b
    if len(D) >= N:
        break
for i in range(N):
    if i < len(D) and A[i] < D[i]:
        A[i] = D[i]
    else:
        break
print (sum(A))

Measured memory_bytes: 34116
#include <iostream>
#include <string>
#include <sstream>
using namespace std;

string affine(string s, int a, int b) {
    string res = s;
    for(int i=0; i<res.size(); i++) {
        if(res[i]>='a' && res[i]<='z') {
            res[i] = ((res[i]-'a')*a + b)%26 + 'a';
        }
    }
    return res;
}

void solve() {
    string s, w;
    
    getline(cin, s);

    for(int a=1; a<26; a+=2) {
        if(a==13) continue;
        for(int b=0; b<26; b++) {
            w = affine(s, a, b);
            if(w.find("that")!=string::npos || w.find("this")!=string::npos) {
                cout << w << endl;
                return;
            }
        }
    }
}

int main() {
    string s;
    stringstream ss;
    int n;
    getline(cin, s);
    ss << s;
    ss >> n;

    for(int i=0; i<n; i++) {
        solve();
    }
}


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

struct Edge {
  int to, weight;
  Edge(int t, int w) :to(t), weight(w) {}
};

struct Tree {
  vector<vector<Edge>> edges;

  void addEdge(int a, int b) { addEdge(a, b, 1); }
  void addEdge(int a, int b, int w) {
    edges[a].emplace_back(b, w);
  }

  Tree(int N) :edges(N) {}
};

int main() {
  int N; cin >> N;
  Tree G(N);
  rep(i, N - 1) {
    int x, y; cin >> x >> y;
    x--; y--;
    G.addEdge(x, y);
    G.addEdge(y, x);
  }

  int M; cin >> M;
  vector<int> u(M), v(M); 
  rep(i, M) {
    cin >> u[i] >> v[i];
    u[i]--; v[i]--;
  }

  vector<int> rank(N);
  vector<int> parent(N, -2);

  queue<int> q;

  parent[0] = -1;
  rank[0] = 0;
  q.push(0);

  while (!q.empty()) {
    int v = q.front(); q.pop();

    for (Edge e : G.edges[v]) {
      int nv = e.to;
      if (parent[nv] != -2) continue;

      parent[nv] = v;
      rank[nv] = rank[v] + 1;
      q.push(nv);
    }
  }

  vector<long long> X(N);
  vector<set<int>> S(M);

  rep(i, M) {;
    int a = u[i], b = v[i];
    if (rank[a] < rank[b]) swap(a, b);
    while (rank[a] != rank[b]) {
      S[i].insert(a);
      a = parent[a];
    }
    while (a != b) {
      S[i].insert(a);
      S[i].insert(b);
      a = parent[a];
      b = parent[b];
    }
  }

  rep(i, N) {
    for (int j = M - 1; j >= 0; j--) {
      X[i] *= 2;
      if (S[j].count(i) == 1) X[i]++;
    }
  }

  vector<long long> dp(1 << M, 0);
  dp[0] = 1;

  rep(i, N) {
    for (int bit = (1 << M) - 1;  bit >= 0;  bit--) {
      dp[bit | X[i]] += dp[bit];
    }
  }

  cout << dp[(1 << M) - 1] / 2 << endl;
}

Measured memory_bytes: 8448
s=input()
x=len(s)
c=0
for j in range(x-1,0,-1):
    for i in range(1,(x-1)//2+1):
        if  s[0:i]*int(j//i)==s[0:j] and j//i%2==0:
            print(j)
            c+=1
            break
    if c==1:
        break

Measured memory_bytes: 3060
#include <iostream>
#include <vector>

using namespace std;

int main(){
  int N, X;
  cin >> N >> X;
  vector<int> L(N);
  for(int &l:L){
    cin >> l;
  }

  int sum = 0;
  int n = 0;
  for(int l:L){
    sum += l;
    n++;
    if(sum > X){
      sum -= l;
      n--;
      break;
    }
  }

  cout << n+1 << endl;

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<(int)(n); i++)
#define all(v) v.begin(), v.end()
#define allR(v) v.rbegin(), v.rend()
#define PRINT(v) for (auto x : (v)) cout <<x <<" " ; cout <<endl;
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
typedef pair<int,int> Pi;
const ll MOD = 1000000007;
const ll INF = 10000000000000000;
const int inf = 1001001001;
vector<int> x4 = {0, 1, 0, -1}, x8 = {0, 1, 1, 1, 0, -1, -1, -1};
vector<int> y4 = {1, 0, -1, 0}, y8 = {1, 1, 0, -1, -1, -1, 0, 1};
template<class T> inline bool chmin(T& a, T b){if (a>b){a = b; return true;}return false;}
template<class T> inline bool chmax(T& a, T b){if (a<b){a = b; return true;}return false;}
template<class T> inline T powerM(T a,T b){if (b==0) return 1;
T tmp = powerM(a,b/2); if (b%2==0) return tmp*tmp%MOD; else return tmp*tmp%MOD*a%MOD; }
template<class T> inline T power(T a,T b,T m){ if (b==0) return 1;
  T tmp = power(a,b/2,m); if (b%2==0) return tmp*tmp%m; else return tmp*tmp%m*a%m; }
template<class T> inline T gcd(T a, T b){if (b==0) return a; return gcd(b, a%b);}
template<class T> inline T lcm(T a, T b){return a / gcd(a,b) * b;}
// ax+by=gcd(a,b)を解く
template<class T> inline T extgcd(T a,T b,T &x,T &y){if (b==0){x=1; y=0; return a;} T d=extgcd(b,a%b,y,x); y -= a/b*x; return d;}
void hey(){ cout <<"hey" <<endl; }

template<class T> struct edge { int to; T cost;};


int main() {
  double a,b,h,m; cin >>a >>b >>h >>m;
  double longhari = m * 6;
  double shorthari = h * 30 + m * 0.5;
  double angle = abs(longhari - shorthari);
  angle = min(angle, 360 - angle);
  double res = a * a + b * b - 2 * a * b * cos(angle/180*3.1415926535897932384626);
  res = sqrt(res);
  cout <<fixed <<setprecision(12) <<res <<endl;
}


Measured memory_bytes: 4264
#include <bits/stdc++.h>
using namespace std;
#define int                     long long int
#define ld                      long double
#define pb                      push_back
#define MOD                     1000000007
#define inf                     3e18
#define vi                      vector<int>
#define vld                     vector<ld>
#define pii                     pair<int,int>
#define mii                     map<int,int>
#define fi                      first
#define se                      second
#define fastIO                  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define db(...)                 __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) { cerr << " "<< name << " : " << arg1 <<'\n'; }
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
    const char* comma = strchr(names + 1, ',');
    cerr.write(names, comma - names) << " : " << arg1 << " | "; __f(comma + 1, args...);
}

void inp_out()
{
	#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	freopen("debug.txt", "w", stderr);
	#endif
}

int32_t main()
{
	fastIO
	inp_out();
	int n, k; 
	cin >> n; 
	vi a(n); 
	mii mp; 
	int sum = 0; 
	for(int i = 0; i < n;  ++ i)
	{
		cin >> a[i]; 
		mp[a[i]] ++ ; 
		sum += a[i]; 
	}
	cin >> k; 
	while(k -- )
	{
		int x, y; 
		cin >> x >> y; 
		sum -= x * mp[x]; 
		sum += y * mp[x]; 
		mp[y] += mp[x]; 
		mp[x] = 0;
		cout << sum << "\n";  
	}

	return 0;
}

Measured memory_bytes: 9908
while True:
    m, f, r = map(int, input().split())

    if m == -1 and f == -1 and r == -1:
        break

    if m == -1 or f == -1:
        print('F')
    elif m + f >= 80:
        print('A')
    elif 80 > m + f >= 65:
        print('B')
    elif 65 > m + f >= 50 or r >= 50:
        print('C')
    elif 50 > m + f >= 30:
        print('D')
    else:
        print('F')

Measured memory_bytes: 7676
import java.util.*;
public class Main{
    public static void main(String args[]) {
      Scanner in = new Scanner(System.in);
      int n = in.nextInt();
      int arr[][] = new int[n][3];
      int dp[][] = new int[n][3];
      for(int i=0; i<n; i++){
          for(int j=0; j<3; j++){
              arr[i][j] = in.nextInt();
          }
      }
      for(int i=0; i<n; i++){
          for(int j=0; j<3; j++){
              if(i==0){
                  dp[i][j]= arr[i][j];
              }
              else{
                  int max =Integer.MIN_VALUE;
                  if(j==0){
                      max = Math.max(dp[i-1][j+1],dp[i-1][j+2]);
                  }
                  else if(j==1){
                      max = Math.max(dp[i-1][j-1],dp[i-1][j+1]);
                  }
                  else if(j==2){
                      max = Math.max(dp[i-1][j-2],dp[i-1][j-1]);
                  }
                  dp[i][j] = arr[i][j]+max;
                  
                  
              }
          }
      }
      
      int max_res = Integer.MIN_VALUE;
      for(int i=0; i<3; i++){
          max_res = Math.max(dp[n-1][i], max_res);
      }
      System.out.println(max_res);
     
      
    }
}

Measured memory_bytes: 100424
#include <bits/stdc++.h>
#define INF 2000000000
using namespace std;
typedef long long ll;
int read(){
    int f = 1, x = 0;
    char c = getchar();
    while(c < '0' || c > '9'){if(c == '-') f = -f; c = getchar();}
    while(c >= '0' && c <= '9')x = x * 10 + c - '0', c = getchar();
    return f * x; 
}
int n, m;
void init(){
    n = read(), m = read();
}
void solve(){
    int x = (n - 1) >> 1;
    int cur = 1;
    for (int i = 1; i <= m; ++i){
        if (i & 1){
            printf("%d %d\n", x, x + i);
            --x;
        }else {
            printf("%d %d\n", cur, n - i + cur);
            ++cur;
        }
    }
}
int main(){
    init();
    solve();
    return 0;
}

Measured memory_bytes: 3764
#include "bits/stdc++.h"
#include <chrono> 
 
using namespace std;
using namespace std::chrono; 
 
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
 
#define gcd(a,b) __gcd(a,b)
#define vi vector<int>
#define vll vector<ll>
#define vs vector<string>
#define vc vector<char>
#define pb(n) push_back(n)
#define pp pop_back()
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define type(a) typeid(a).name();
#define print(arr) cout << "[" ;for(unsigned int i=0;i<(unsigned int) arr.size();i++){ (i==arr.size()-1)?cout << arr[i]:cout << arr[i] << ",";}cout << "]" << endl
#define Arr(arr,l) cout << "[" ;for(unsigned int i=0;i<(unsigned int) l;i++){ (i==l-1)?cout << arr[i]:cout << arr[i] << ",";}cout << "]" << endl
#define console(arr) cout << "["<<endl; for(ll i=0;i<(ll)arr.size();++i){cout << " [";for(ll j=0;j<(ll)arr[i].size();++j){(j==(int)arr[i].size()-1)?cout << arr[i][j]:cout << arr[i][j] << ",";}cout << "]"<<endl;} cout << "]"<<endl
#define starting() auto start = high_resolution_clock::now()
#define ending() auto stop = high_resolution_clock::now();auto duration = duration_cast<microseconds>(stop - start);cout << endl << endl << "Execution Time : "<<duration.count()/1000 << " ms" << endl
 
template <typename T1,typename T2>
void mapped(map<T1,T2>m){for(auto ite=m.begin();ite!=m.end();++ite){cout << "'" << ite->first << "'"<<" : "<<ite->second <<endl;}}
 
template <typename T1 , typename T2>
void mappedArr(map<T1,vector<T2>>m){for(auto ity=m.begin();ity!=m.end();++ity){cout << "'"<< ity->first <<"'"<<" : "<<"[";
for(int i=0;i<(int)ity->second.size();++i){(i==(int)ity->second.size()-1)?cout << ity->second[i]:cout << ity->second[i] << ",";}cout << "]"<<endl;}}
 
string int_to_string(int x){ stringstream ss; ss << x; string ni = ss.str(); return ni;}
int char_to_int(char c){ int n = (int)c - 48; return n; }
int string_to_int(string x){ int n; stringstream s(x); s >> n; return n; }
char upperCase(char a){int d = (int)a - 97 + 65;char c = (char)d;return c;} 
char lowerCase(char a){int d = (int)a - 65 + 97;char c = (char)d;return c;}  
bool isInt(char a){int d = (int)a - 48;if(d>=0 && d<=9){return true;}return false;}
//string char_to_string(char a){string d = (1,a);return d;}
 
template <typename T1,typename T2>
void ArrPair(vector<pair<T1,T2>>vp){for(int i=0;i<(int)vp.size();++i){
cout << "(" << vp[i].first << "," << vp[i].second << ")"<<endl ;}}
 
const int MOD = 1e9 + 7;
const ll INF = 1e18L + 5;
 
unordered_map<int,int> um;
unordered_set<int> us;
set<int> s;
// v.front() gives the first element of vector 
// v.back()  gives the last element of vector
// insert erase substr

//bool bySecond(pair<int,int> a,pair<int,int> b){
//  return a.second < b.second;
//} 

bool f(vector<ll> a,vector<ll> b){
	return a[1] > b[1];
}

 
 
int main(){
	int n;
	cin >> n;
	string s;
	cin >> s;
	//int x = 'Z';
	//cout << x;
	for(int i=0;i<(int)s.size();++i){
		int x = (int)s[i];
		//cout << x;
		x+=n;
		if(x>90){
			x = x - 90 + 64; 
		}
		char y = (char)x;
		s[i] = y; 
	}      
	cout << s;
}







Measured memory_bytes: 256
//**KEEP IT SHORT AND SIMPLE**
#include <bits/stdc++.h>
#define IO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define FILES freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#define REP(i,a,b) for (int i = a; i < b; i++)
#define NL '\n'
#define F first
#define S second
#define dot(a, b) (conj(a) * (b)).real()
#define cross(a, b) (conj(a)* (b)).imag()
using namespace std;
typedef long long ll;
typedef long double ld;
typedef bool bl;
typedef vector < vector<long long> > vvl;
typedef vector <long long> vll;
typedef pair <long long, long long> pll;
typedef map <long long, long long> mll;
typedef map <long long, bool> mlb;
typedef priority_queue<long long, vector<long long>, greater<long long> > minPq;
typedef tuple<ll, ll, ll> line;
typedef complex<double> point;
const double pi = 2 * acos(0.0);
const int OO = 0x3f3f3f3f;
int main()
{
    IO
    ll x, a;
    cin >> x >> a;
    cout << (x < a ? 0 : 10);
    return 0;
}


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

bool iseven(string& str)
{
	if (str.length() % 2 != 0)return false;
	else
	{
		if (string(str.begin(), str.begin() + str.length() / 2) == string(str.begin() + str.length() / 2, str.end()))
			return true;
		else return false;
	}
}

int main(void)
{
	string str,s;
	cin >> str;
	int len = str.length();
	for (int i = len-1; i >=2; i--)//长度
	{
		for (int j = 0; j + i != len; j++) {
		    s=string(str.begin() + j, str.begin() + j + i);
			if (iseven(s)) {
				cout << i << endl;
				return 0;
			}
		}
	}
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <iterator>
#include <algorithm>
#include <string>
#include <map>
#include <list>
using namespace std;

int main() {
  long long a,b;
  int k;
  cin >> a >> b >> k;

  int count=0;
  for(int j=a; j <= b; ++j){
    // if(j >= a && j <= b){
      if(count < k || count > b-a-k) cout << j << endl;
      count++;
    // }
  }
}



Measured memory_bytes: 3560
import itertools

N = int(input())

say = {i:[] for i in range(1, N+1)}
for i in range(N):
    a = int(input())
    for j in range(a):
        x, y = map(int, input().split())
        say[i+1].append([x, y])

ans_list = list(itertools.product([0, 1], repeat=N))

max_count = 0
for ans in ans_list:
    flag = 0
    for i, an in enumerate(ans):
        if an == 1:
            for s in say[i+1]:
                # print(ans, s)
                if ans[s[0]-1] == s[1]:
                    continue
                else:
                    flag = 1
                    break
        if flag == 1:
            break
    if flag == 0:
        max_count = max(sum(ans), max_count)


print(max_count)

Measured memory_bytes: 47728
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#ifdef tabr
#include "library/debug.cpp"
#else
#define debug(...)
#endif

ll func(ll a, ll b, ll x) {
    return (a * x) / b - (x / b) * a;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll a, b, n;
    cin >> a >> b >> n;
    ll mx = 0;
    ll pos = -1;
    for (ll i = 1; i <= min(n, 2000000LL); i++) {
        ll tmp = func(a, b, i);
        mx = max(mx, tmp);
        if (mx == tmp) pos = i;
    }
    if (b <= n) {
        for (ll i = max(1LL, b - 2000000LL); i <= b; i++) {
            ll tmp = func(a, b, i);
            mx = max(mx, tmp);
            if (mx == tmp) pos = i;
        }
    }
    for (ll i = max(1LL, n - 2000000LL); i <= n; i++) {
        ll tmp = func(a, b, i);
        mx = max(mx, tmp);
        if (mx == tmp) pos = i;
    }
    cout << mx << '\n';
    debug(pos);
    return 0;
}

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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,n,m) for(int i=(int)(n); i<=(int)(m); i++)
#define RFOR(i,n,m) for(int i=(int)(n); i>=(int)(m); i--)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)

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

#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>

#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ins insert

using namespace std;

//-------------------------------------------------
//--Range Set Counter
//-------------------------------------------------
template<typename T>
class RangeSet
{
private:
    ::std::vector<int> v;
    ::std::unordered_map<T, int> Map;
    ::std::vector<::std::vector<int> > data;
    int kind;
public:
    RangeSet(const ::std::vector<T> &v_):v(v_.size()){
        int sz = v_.size(); kind = 0;
        for(int i=0;i<sz;i++){
            T t = v_[i];
            if (Map.count(t)){
                data[Map[t]].push_back(i);
            }else{
                Map[t] = kind++;
                data.push_back(::std::vector<int>());
                data.back().push_back(i);
            }
            v[i] = Map[t];
        }
    }
    //query for all elements
    int query(T x){
        if (!Map.count(x)) return 0;
        return data[Map[x]].size();
    }
    //query for [a, b]
    int query(int a, int b, T x){
        if (a>b) return 0;
        if (!Map.count(x)) return 0;
        int xi = Map[x];
        auto right = ::std::upper_bound(data[xi].begin(),data[xi].end(),b);
        auto left  = ::std::lower_bound(data[xi].begin(),data[xi].end(),a);
        return right-left;
    }
    //search x for [k, tail]
    int find(int k, T x){
        if (!Map.count(x)) return -1;
        int xi = Map[x];
        auto itr = ::std::lower_bound(data[xi].begin(),data[xi].end(),k);
        if (itr!=data[xi].end()){
            return *itr;
        }else{
            return -1;
        }
    }
};

//-------------------------------------------------

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; cin>>n;
    string s; cin>>s;
    vector<char> v(n);
    rep(i,n) v[i]=s[i];
    RangeSet<char> rs(v);
    int ans=0;
    rep(i,n-1){
        int cnt=0;
        rep(j,26)if(rs.query(0,i,char(j+'a')) && rs.query(i+1,n-1,char(j+'a'))) cnt++;
        chmax(ans,cnt);
    }
    cout<<ans<<"\n";
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <numeric>
#include <functional>
#include <vector>
#include <string>

using namespace std;

int main() {

	char f[100];
	int n;
	cin >> n;
	bool g = false;
	bool y = false;
	bool p = false;
	bool w = false;

	for (int i = 0; i < n; ++i) {
		char s;
		cin >> s;
		f[i] = s;
	}

	for (int i = 0; i < n; ++i) {
		if (f[i] == 'G') {
			g = true;
		}
		if (f[i] == 'Y') {
			y = true;
		}
		if (f[i] == 'P') {
			p = true;
		}
		if (f[i] == 'W') {
			w = true;
		}
	}

	if (g && y && p && w) {
		cout << "Four" << endl;
	}
	else {
		cout << "Three" << endl;
	}

	return 0;
}

Measured memory_bytes: 256
import collections


def resolve():
    s = input()
    n = int(input())
    d = collections.deque()
    d.appendleft(s)

    rev = False
    for _ in range(n):
        q = list(input().split())

        if len(q) == 1:
            rev = not rev

        else:
            if q[1] == '1':
                las = False

            else:
                las = True

            if rev:
                las = not las

            if las:
                d.append(q[2])

            else:
                d.appendleft(q[2])

    dstr = ''.join(d)

    if rev:
        print(dstr[::-1])

    else:
        print(dstr)
        
resolve()

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

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

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

        cout << a+ a*a+a*a*a << endl;
}

Measured memory_bytes: 3620
package main

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

var mod uint64 = 998244353

var maxfac uint64 = 200000
var fac []uint64  // n! % mod
var ifac []uint64 // k!^(mod-2) % mod

func initCombination() {
	fac = make([]uint64, maxfac+1)
	ifac = make([]uint64, maxfac+1)
	fac[0] = 1
	ifac[0] = 1
	var i uint64
	for i = 0; i < maxfac; i++ {
		fac[i+1] = fac[i] * (i + 1) % mod
		ifac[i+1] = ifac[i] * powMod(i+1, mod-2) % mod
	}
}
func combination(n, r uint64) uint64 {
	if n == 0 && r == 0 {
		return 1
	}
	if n < r || n < 0 {
		return 0
	}
	return (fac[n] * (ifac[r] * ifac[n-r] % mod) % mod)
}

func powMod(n, m uint64) uint64 {
	var ans uint64 = 1
	for m != 0 {
		if (m % 2) != 0 {
			ans = ans * n % mod
			if m == 1 {
				break
			}
		}
		n = n * n % mod
		m = m / 2
	}
	return ans
}

func main() {
	list := getStdinIntArr64()
	var N uint64 = uint64(list[0])
	var M uint64 = uint64(list[1])
	var K uint64 = uint64(list[2])

	initCombination()

	var ans uint64 = 0
	var k uint64 = 0
	for k = 0; k <= K; k++ {
		var tmp uint64 = 0
		tmp = M * combination(N-1, k) % mod
		tmp = tmp * powMod(M-1, N-1-k) % mod
		ans = (ans + tmp) % mod
	}

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

var sc = bufio.NewReaderSize(os.Stdin, 1024*1024*1)

func getStdin() string {
	return readLine()
}
func getStdinIntArr64() []int64 {
	str := getStdin()
	list := strings.Split(str, " ")
	rtn := make([]int64, len(list))
	for idx, val := range list {
		rtn[idx], _ = strconv.ParseInt(val, 10, 64)
	}
	return rtn
}
func readLine() string {
	buf := make([]byte, 0, 0)
	for {
		l, p, _ := sc.ReadLine()
		buf = append(buf, l...)
		if !p {
			break
		}
	}
	return string(buf)
}


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

long A[100000];

int main(int argc, char const* argv[])
{
    int N;
    cin >> N;
    for (int i = 0; i < N; i++) {
        cin >> A[i];
    }

    int sep[3];
    sep[0] = sep[1] = sep[2] = 0;

    long size[3];
    size[0] = size[1] = size[2] = 0;
    for (int i = 0; i < N; i++) {
        size[2] += A[i];
    }

    long max = size[0];

    while (sep[2] < N) {
        long min = size[0];
        int argmin = 0;
        for (int i = 0; i < 3; i++) {
            if (size[i] <= min) {
                min = size[i];
                argmin = i;
            }
        }

        size[(argmin+1)%3] -= A[sep[(argmin+1)%3]];
        size[argmin] += A[sep[(argmin+1)%3]];
        sep[(argmin+1)%3]++;

        if (max < min) {
            max = min;
        }
    }

    cout << max << endl;

    return 0;
}

Measured memory_bytes: 1940
parseInt(x) = parse(Int, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)


function main()
    mod = 998244353
    n = readline() |> parseInt
    d = readline() |> split |> parseMap
    a = zeros(Int,n)
    for i in 1:n
        a[d[i]+1] += 1
    end
    mx = maximum(d)
    q = a[1]==1&&d[1]==0?1:0
    for i in 2:mx+1
        for j in 1:a[i]
            q = q*a[i-1]%mod
        end
    end
    println(q)
end

main()

Measured memory_bytes: 118408
#pragma GCC optimize("O3")
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
typedef  unsigned long long int ull;
typedef pair<ll,ll> P;
template<class T> using V=vector<T>; 
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
const ll inf=(1e18);
//const ll mod=998244353;
const ll mod=1000000007;
//ios_base::sync_with_stdio(false);
//cin.tie(NULL);
ll gcd(ll a,ll b) {return b ? gcd(b,a%b):a;}
ll lcm(ll c,ll d){return c/gcd(c,d)*d;}
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
int main(){
	int n;
    cin>>n;
    V<ll> d(n);
    for(int i=0;i<n;i++)cin>>d[i];
    ll ans=0;
    sort(all(d));
    for(int i=0;i<n-1;i++){
        for(int j=i+1;j<n;j++){
            ans+=(lower_bound(all(d),d[i]+d[j])-d.begin())-j-1;
        }
    }
    cout<<ans<<"\n";
}

Measured memory_bytes: 256
S = input()

ans = 0

if S == "RRR":
    ans = 3
elif S == "RRS":
    ans = 2
elif S == "RSR":
    ans = 1
elif S == "RSS":
    ans = 1
elif S == "SRR":
    ans = 2
elif S == "SRS":
    ans = 1
elif S == "SSR":
    ans = 1
elif S == "SSS":
    ans = 0

print(ans)

Measured memory_bytes: 9052
"""
愚直に一人一人交通止めに対してシミュレートしていは、絶対に間に合わない。

そこで、「この時間に出発したら"まず最初に"この通行止めで引っかかる」というのを前処理でまとめておく。
これは座標圧縮とセグメント木っぽいものを用いることで実現可能。
"""
N,Q = map(int,input().split())
STX = [list(map(int,input().split())) for _ in range(N)]
D = [int(input()) for _ in range(Q)]
times = set(D+[s-x for s,t,x in STX]+[t-x for s,t,x in STX])
compTimes = {t:i for i,t in enumerate(sorted(times))}

class originalSegTree:
    def __init__(self,n):
        self.end_leaves = 2**n.bit_length()
        self.tree = [float("INF")]*(2*self.end_leaves)
    
    def add(self,left,right,x):
        L = left + self.end_leaves
        R = right + self.end_leaves
        while L < R:
            if L&1:
                self.tree[L] = min(self.tree[L],x)
                L += 1
            if R&1:
                R -= 1
                self.tree[R] = min(self.tree[R],x)
            L >>= 1
            R >>= 1
    
    def merge(self):
        for i in range(1,self.end_leaves):
            self.tree[i*2] = min(self.tree[i],self.tree[i*2])
            self.tree[i*2+1] = min(self.tree[i],self.tree[i*2+1])

seg = originalSegTree(len(compTimes))
for s,t,x in STX:
    a = compTimes[s-x]
    b = compTimes[t-x]
    seg.add(a,b,x)

seg.merge()

for d in D:
    c = compTimes[d]
    ans = seg.tree[c+seg.end_leaves]
    if ans == float("INF"):
        ans = -1
    print(ans)


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

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> vec(n);
  rep(i, n) cin >> vec.at(i);
  int count = 0;
  rep(i, n) {
    if(vec.at(i) >= k) count++;
  }
  cout << count << endl;
}


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

class P
{
    static void Main()
    {
        int k = int.Parse(Console.ReadLine());
        long[] a = Console.ReadLine().Split().Select(long.Parse).ToArray();

        long makablePairMin = 2;
        long makablePairMax = 2;
        for (int i = a.Length - 1; i >= 0; i--)
        {
            long possibleMinWinner = (makablePairMin / a[i] + (makablePairMin % a[i] != 0 ? 1 : 0)) * a[i];
            long possibleMaxWinner = (makablePairMax / a[i]) * a[i];
            if (possibleMaxWinner >= possibleMinWinner)
            {
                makablePairMin = possibleMinWinner;
                makablePairMax = possibleMaxWinner + a[i] - 1;
            }
            else
            {
                Console.WriteLine(-1);
                return;
            }
        }
        Console.WriteLine($"{makablePairMin} {makablePairMax}");
    }
}

Measured memory_bytes: 25308
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = a; i < n; i++)
#define repr(i, a, n) for (int i = n - 1; i >= a; i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }

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

  int n, h;
  cin >> n >> h;
  vector<int> a(n), b(n);
  rep(i, 0, n) cin >> a[i] >> b[i];
  int at = *max_element(a.begin(), a.end());
  sort(b.rbegin(), b.rend());

  int ans = 0;
  rep(i, 0, n) {
    if (b[i] <= at)
      break;
    h -= b[i];
    ans++;
    if (h <= 0) {
      cout << ans << endl;
      return 0;
    }
  }

  ans += (h + at - 1) / at;
  cout << ans << endl;
}


Measured memory_bytes: 1024
#include<stdio.h>
int main(void){
int a,b,c=0;
while(scanf("%d %d", &a, &b) != EOF){
a = a+b;
c = 0;
while(!(a==0)){
c++;
a = a/10;
}
printf("%d\n",c);
}
return 0;
}

Measured memory_bytes: 1676
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;
typedef long long ll;
ll gcd(ll n,ll m){
if(m>n) return gcd(m,n);
return m?gcd(m,n%m):n;
}
int main() {
  ll n,m,l,a=1;
  cin >> n >> m;
  l=gcd(n,m);
  if(l%2==0){
    a++;
    do{
      l/= 2; 
    }while(l%2==0);
  }
  for(ll i=3;l>= i && l!=1;i+=2){
       if(l%i==0){
           a++;
           do{
              l/= i; 
           }while(l%i==0);
       }
       if(i*i>l){
          i=l-2; 
       }
   }
  cout<<a;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;
int main() {
	int m1, d1, m2, d2;
	cin >> m1 >> d1 >> m2 >> d2;

	 
	if (d1 < d2) {
		cout << 0 << endl;
	} else {
		cout << 1 << endl;
	}


	return 0;
}

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

int main(){
  string S, T;
  cin >> S >> T;
  int cnt = 0;
  for(int i = 0; i < 3; i++){
    if(S[i] == T[i]){
      cnt++;
    }
  }
  cout << cnt;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define endl "\n"
#define ll long long 
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

int main()
{
    fast;
    int t=1;
    //cin>>t;
    while(t--)
    {
      int x;
      cin>>x;
      if(x>=30)
      {
        cout<<"Yes"<<endl;
      }
      else
      {
        cout<<"No"<<endl;
      }
    }
}

Measured memory_bytes: 3604
using System;
using System.Collections.Generic;
using System.Linq;
using static Atcoder;
using System.Threading.Tasks;
using System.ComponentModel;

public class Hello
{
    private const long INF = 1000000007;
    public static void Main()
    {
        string S = Console.ReadLine();
        HashSet<char> hs = new HashSet<char>();
        foreach (char c in S) {
            if (!hs.Contains(c)) hs.Add(c);
            else {
                Console.WriteLine("no");
                return;
            }
        }
        Console.WriteLine("yes");
    }
}

public class Atcoder
{
    public static void Swap<T>(ref T a, ref T b)
    {
        var t = a;
        a = b;
        b = t;
    }
    public static long LCM(long a, long b)
    {
        long c = a * b;
        if (a < b) Swap(ref a, ref b);
        long d = a % b;
        while (d != 0)
        {
            a = b;
            b = d;
            d = a % b;
        }
        return c / b;
    }
    public static string StrReverce(string s)
    {
        return new string(s.Reverse().ToArray());
    }
    public static bool IsPrime(int n)
    {
        if (n < 2) return false;
        if (n == 2) return true;
        if (n % 2 == 0) return false;

        //double sqrtNum = Math.Sqrt(n);
        for (int i = 3; i < n; i += 2)
        {
            if (n % i == 0) return false;
        }
        return true;
    }
    public static string[] SpRead(char c)
    {
        return Console.ReadLine().Split(c);
    }
    public static string ToConvertBit(int N, int e)
    {
        string ret = "";
        int r = 0;
        while (N != 0)
        {
            r = N % e;
            ret += r.ToString();
            N -= r;
            N /= e;
        }
        ret = StrReverce(ret);
        return ret;
    }
    public static int IntRead()
    {
        return int.Parse(Console.ReadLine());
    }
    public static long LongRead()
    {
        return long.Parse(Console.ReadLine());
    }
    public static long[] LongLine()
    {
        return Console.ReadLine().Split(' ').Select(long.Parse).ToArray();
    }
    public static int[] IntLine()
    {
        return Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
    }
}


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

#define int long long
#define mod 1000000007

using namespace std;

int dp[1010][1010];

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

    string s[h];

    for(int i=0;i<h;i++)
        cin >> s[i];

    dp[0][0] = 1;

    for(int i=0;i<h;i++)
    {
        for(int j=0;j<w;j++)
        {
            if(j && s[i][j-1] == '.')
                dp[i][j] += dp[i][j-1];

            if(i && s[i-1][j] == '.')
                dp[i][j] += dp[i-1][j];

            dp[i][j] %= mod;
        }
    }

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

Measured memory_bytes: 9216
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
using namespace std;

int main(){
  int n;
  cin >> n;
  int h[n];
  REP(i,n) cin >> h[i];
  int ans = 0;
  int now = 0;
  
  REP(i,n-1){
    if(h[i] < h[i+1]){
      if(ans < now) ans = now;
      now = 0;
    }
    else{
      now += 1;
    }
  }
  if(ans < now) ans = now;
   cout << ans;
   return 0;
}

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

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

    int month = stoi(s.substr(5, 2));

    if (month > 4)
    {
        cout << "TBD" << endl;
    }
    else
    {
        cout << "Heisei" << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;

//公約数列挙
void div(long long a, vector<long long> &n) {
  n.push_back(1);
  for (long long i = 2; i <= sqrt(a); i++)
    if (a % i == 0) n.push_back(i);
  if (n.at(n.size() - 1) == sqrt(a))
    for (long long i = n.size() - 2; i >= 0; i--)
      n.push_back(a / n.at(i));
  else
    for (long long i = n.size() - 1; i >= 0; i--)
      n.push_back(a / n.at(i));
  return;
}

void comdiv(long long a, long long b, vector<long long> &n) {
  if (a > b) swap(a, b);
  vector<long long> m(0);
  div(a, m);
  for (long long i = 0; i < m.size(); i++)
    if (b % m.at(i) == 0) n.push_back(m.at(i));
  return;
}

int main() {
  ll a, b;
  cin >> a >> b;
  vector<ll> n(0);
  comdiv(a, b, n);
  ll x = n.at(n.size() - 1);
  cout << a * b / x << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
using namespace std;
struct aaa{
	int x,y,w;
}a[500001];
int n,m,t1,tot,ans[500001],mx[500001],e[500001],nt[500001],hd[500001];
void dfs(int x,int dep,int w){
	if(mx[x]>=dep)return;
	mx[x]=dep;
	if(!ans[x])ans[x]=w;
	if(!w)return;
	int i;
	for(i=hd[x];i;i=nt[i])dfs(e[i],dep-1,w);
}
void build(int x,int y){
	tot++;
	e[tot]=y;
	nt[tot]=hd[x];hd[x]=tot;
}
int main(){
	int i,x,y;
	scanf("%d%d",&n,&m);
	for(i=1;i<=n;i++)mx[i]=-1;
	for(i=1;i<=m;i++){
		scanf("%d%d",&x,&y);
		build(x,y);build(y,x);
	}
	scanf("%d",&t1);
	for(i=1;i<=t1;i++)
		scanf("%d%d%d",&a[i].x,&a[i].y,&a[i].w);
	for(i=t1;i;i--)dfs(a[i].x,a[i].y,a[i].w);
	for(i=1;i<=n;i++)printf("%d\n",ans[i]);
}

Measured memory_bytes: 11392
import os
import sys
from collections import defaultdict, Counter
from itertools import product, permutations,combinations, accumulate
from operator import itemgetter
from bisect import bisect_left,bisect
from heapq import heappop,heappush,heapify
from math import ceil, floor, sqrt
from copy import deepcopy


def main():
    n = int(input())
    a_list = list(map(int, input().split()))
    ans = 0
    for i in range(len(a_list)):
        if ((i+1)%2 != 0) and (a_list[i]%2 != 0):
            ans += 1

    print(ans)

if __name__ == '__main__':
	main()


Measured memory_bytes: 9544
import java.util.*;
public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int A,B,C,X,Y,sum_price=0;
        ArrayList<Integer> price = new ArrayList<>();
        A=sc.nextInt();
        B=sc.nextInt();
        C=sc.nextInt();
        X=sc.nextInt();
        Y=sc.nextInt();
        int L;
        if(X>Y)L=X;
        else L=Y;
        for(int a=0;a<=L;a++){
            sum_price =0;
            sum_price += C*2*a;
            for(int b=0;b<X-a;b++){
                sum_price += A;
            }
            for(int c=0;c<Y-a;c++){
                sum_price +=B;
            }
            price.add(sum_price);
        }
        System.out.println(Collections.min(price));
    }
}

Measured memory_bytes: 25812
import java.util.*;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int ans = 1;
		for (int i=1; true; i++) {
			if (N < i * i) break;
			ans = i * i;
		}
		System.out.println(ans);
	}
}

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

const int N = 105;
const int M = 1e5 + 5;

long long dp[N][M];
int n, w;
int a[N], b[N];

void read() {
  scanf("%d %d", &n, &w);
  for (int i = 0; i < n; i++) {
    scanf("%d %d", &a[i], &b[i]);
  }
}

long long solve(int pos, int sisa) {
  if (sisa < 0) return 4e18;
  if (pos == n) {
    if (sisa == 0) return 0;
    return 4e18;
  }

  long long &ret = dp[pos][sisa];
  if (ret != -1) return ret;

  ret = min(solve(pos + 1, sisa), a[pos] + solve(pos + 1, sisa - b[pos]));
  return ret;
}

long long work() {
  memset(dp, -1, sizeof dp);
  for (int i = M-1 ; i >= 0 ; i--)
    if (solve(0, i) <= w)
      return i;
  assert(0);
  return -1;
}

int main() {
  read();
  cout << work() << endl;
  return 0;
}

Measured memory_bytes: 82304
#include <bits/stdc++.h>
using namespace std;
const int MaxN=15;
int n,m,ans,e[MaxN][MaxN],c[1<<MaxN],dp[1<<MaxN][MaxN];
int main() {
    scanf("%d%d",&n,&m);
    for (int i=1;i<=m;++i) {
        int u,v,w;
        scanf("%d%d%d",&u,&v,&w);
        u--,v--;
        e[u][v]=e[v][u]=w;
        ans+=w;
    }
    for (int i=0;i<(1<<n);++i) for (int j=0;j<n;++j) for (int k=j+1;k<n;++k) if (i&(1<<j) && i&(1<<k)) c[i]+=e[j][k];
    memset(dp,0xff,sizeof dp);dp[1][0]=0;
    for (int S=0;S<(1<<n);++S) for (int i=0;i<n;++i) if (dp[S][i]!=-1) {
        int SS=((1<<n)-1)^S;
        for (int j=0;j<n;++j) if (SS&(1<<j) && e[i][j]) 
            dp[S|(1<<j)][j]=max(dp[S|(1<<j)][j],dp[S][i]+e[i][j]);
        for (int j=SS;j;j=(j-1)&SS) 
            dp[S|j][i]=max(dp[S|j][i],dp[S][i]+c[j|(1<<i)]);
    }
    ans-=dp[(1<<n)-1][n-1];
    printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 2304
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n;
	cin>>n;
	bool flag = false;
	while(n>0){
		if(n%10==7){
			flag = true;
			break;
		}
		n/=10;
	}
	if(flag)cout<<"Yes\n";
	else cout<<"No\n";
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
typedef long long ll;
#define rep(i,n) for(ll i=0;i<(n);i++)
#define repr(i,n) for(ll i=(n-1);i>=0;i--)
#define pb push_back
#define mp make_pair
#define all(x) x.begin(),x.end()
#define br cout << endl;
using namespace std;
const int INF = 1e9;
const int MOD = 1e9+7;
using Graph = vector<vector<ll>>;
template<class T> inline bool chmin(T &a, T b) { if(a > b){ a = b; return true;} return false;}
template<class T> inline bool chmax(T &a, T b) { if(a < b){ a = b; return true;} return false;}

// 0 false, 1 true 
// stringの数字をint型にしてアスキーコードになったら -48する
// 切り上げ　ceil(a)


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

    ll ans = 0;
    if(n % 2 != 0){
        cout << 0 << endl;
    }else{
        ll tmp = 10;
        while(n >= tmp){
            ans += n / tmp;
            tmp *= 5;
        }
        cout << ans << endl;
    }

}


Measured memory_bytes: 256
#include <stdio.h>

int main()
{
  int n,q,C=0,i,j,L,M,R;
  int S[100000],T[50000];

  scanf("%d",&n);
  for(i=0; i<n; i++){
    scanf("%d",&S[i]);
  }

  scanf("%d",&q);
  for(i=0; i<q; i++){
    scanf("%d",&T[i]);
    L = 0;
    R = n;
    while(L<R){
      M = (L+R)/2;
      if(S[M]<T[i])
        L = M+1;
      if(S[M]==T[i]){
        C++;
        break;
      }
      if(S[M]>T[i])
        R = M;
    }
  }
  printf("%d\n",C);

  return 0;
}


Measured memory_bytes: 2276
s = input()[::-1]
keys = ["dream", "dreamer", "erase", "eraser"]
keys_ = [i[::-1] for i in keys]
i = 0
t = ''

for _ in range(len(s)):
  for key in keys_:
    if s[i:].startswith(key):
      t += key
      i += len(key)
    if t == s:
      print('YES')
      exit()
else:
  print('NO')

Measured memory_bytes: 3316
import java.util.Scanner;
public class Main {
	static int n;
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		n = Integer.parseInt(sc.next());
		System.out.println(dfs("0"));
	}

	public static int dfs(String s){
		if (Long.parseLong(s) > n){
			return 0;
		}

		int ret = 0;
		if (s.contains("3") && s.contains("5") && s.contains("7")){
			ret = 1;
		}
		ret += dfs(s + "3");
		ret += dfs(s + "5");
		ret += dfs(s + "7");
		return ret;
	}
}

Measured memory_bytes: 36436
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#define rep(i, n) for(int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
 
int main() {
    int N, M;
    cin >> N;
    string s[110], t[110];
    rep(i, N) {
        cin >> s[i];
    }
    cin >> M;
    rep(i, M) {
        cin >> t[i];
    }
    int a[N];   //a[i]には、s[i]がs[N]にいくつ含まれているか入る
    int b[N];   //b[i]には、s[i]がt[N]にいくつ含まれているか入る
    int c[N];   //c[i]には、s[i]を言った時の点数が入る
    int ans = 0;    //c[N]の要素の最大値が入る。c[N]の要素が全て負のときは0

    rep(i, N) {
        a[i] = 0;   b[i] = 0;   c[i] = 0;
    }

    rep(i, N) {
        rep(j, N) {
            if(s[i] == s[j]) {
                a[i]++;
            }
        }
    }

    rep(i, N) {
        rep(j, M) {
            if(s[i] == t[j]) {
                b[i]++;
            }
        }
    }

    rep(i, N) {
        c[i] = a[i] - b[i];
    }

    sort(c, c+N);

    if(0 < c[N-1]) {
        ans = c[N-1];
    }
    
    cout << ans;

    cout << endl;
    return 0;
}

Measured memory_bytes: 256