akhauriyash/Code-Regression huggingface dataset:
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstring>
#define ll long long
using namespace std;
int main()
{
   char s[100010];
   int ans=0,i=0;
   while((s[i]=getchar())!='\n')
   {
       if(i>=1)
       {

       if((s[i-1]=='0'&&s[i]=='1')||(s[i-1]=='1'&&s[i]=='0'))
        {
              ans+=2;
              s[i]='\0';
              s[i-1]='\0';
              i-=2;
        }
       }
       i++;
   }
   cout<<ans<<endl;

}


Measured memory_bytes: 384
/*
 * ARC093C.cpp
 *
 *  Created on: May 18, 2018
 *      Author: 13743
 */
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<string>
#include<cstring>
using namespace std;
typedef long long lng;
typedef unsigned long long ulng;

#define pb push_back
#define SZ(a) int((a).size())
#define ALL(a) (a).begin(), (a).end
#define FOR(i,a,b) for(int i=(a); i<=(b); ++i)
#define FORD(i,b,a) for(int i=(b); i>=(a); --i)
#define REP(i,n) FOR(i,0,n-1)
#define UNIQUE(a) a.erase(unique(ALL(a)), a.end())

lng power(lng b, lng e) {lng sol=1; while(e>0) {if(e&1) {sol=sol*b;} e>>=1; b*= b;} return sol;}

int a[100001];

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

	int N;
	cin >> N;
	REP(i, N) {
		cin >> a[i+1];
	}

	int cost = 0;
	FOR(i, 1, N) {
		cost += (a[i]>a[i-1]) ? a[i]-a[i-1] : a[i-1]-a[i];
	}
	cost += (a[N]>0) ? a[N] : -a[N];

	int path = 0;
	FOR(i, 1, N) {
		path = (a[i+1] > a[i-1]) ? a[i+1]-a[i-1] : a[i-1]-a[i+1];
		path -= (a[i+1] > a[i]) ? a[i+1]-a[i] : a[i]-a[i+1];
		path -= (a[i-1] > a[i]) ? a[i-1]-a[i] : a[i]-a[i-1];
		cout << cost + path << "\n";
	}
	cout << flush;
}






Measured memory_bytes: 1664
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < int(n); i++)
using namespace std;
using ll = long long;
const int INF = (1<<30)-1;
const long long LINF = (1LL<<62)-1;
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, 1, 0, -1};
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll x, k, d;
  cin >> x >> k >> d;
  x = abs(x);
  if (x/d > k)
    cout << x-d*k << endl;
  else {
    k -= x/d;
    x %= d;
    if (k%2)
      cout << abs(x-d) << endl;
    else
      cout << x << endl;
  }
  return 0;
}

Measured memory_bytes: 3656
#include<stdio.h>
#include<stdlib.h>
 
struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;
#define NIL NULL
 
Node root;
 
void insert(int k){
  Node y = NIL; // parent of x
  Node x = root;
  Node z;
 
  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;
 
  while(x != NIL)
    {
      y = x;
      if(z->key < x->key) x = x->left;
      else x = x->right;
    }
  z->parent = y;
  if(y == NIL) root = z;
  else if(z->key < y->key) y->left = z;
  else y->right = z; 
}
 
void inorder(Node u){
  if(u != NIL)
    {
      inorder(u->left);
      printf(" %d", u->key);
      inorder(u->right);
    }
}
 
void preorder(Node u){
  if(u != NIL)
    {
      printf(" %d", u->key);
      preorder(u->left);
      preorder(u->right);
    }
} 
 
int main()
{
  int n, i, x;
  char com[20];
  scanf("%d", &n);
   
  for ( i = 0; i < n; i++ )
    {
      scanf("%s", com);
      if ( com[0] == 'i' )
	{
	  scanf("%d", &x);
	  insert(x);
	} 
      else if ( com[0] == 'p' )
	{
	  inorder(root);
	  printf("\n");
	  preorder(root);
	  printf("\n");
	}
    }
   
  return 0;
}

Measured memory_bytes: 24040
#include "bits/stdc++.h"
using namespace std;
#ifdef _DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

//#define int long long
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
const double PI = acos(-1);
const double EPS = 1e-9;
template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; }

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N, W; cin >> N >> W;
	vector<int>v, w;
	rep(i, 0, N) {
		int a, b, c; cin >> a >> b >> c;
		int j(0);
		while (c) {
			int x = min(c, (1 << j++));
			c -= x;
			v.emplace_back(x*a);
			w.emplace_back(x*b);
		}
	}
	vector<int>dp(W + 1, 0);
	rep(i, 0, v.size())rrep(j, w[i], W + 1)
		chmax(dp[j], dp[j - w[i]] + v[i]);
	cout << dp[W] << endl;
	return 0;
}

Measured memory_bytes: 3228
#include <iostream>
#include <string>
#include <vector>
#include <climits>
#include <set>
#include <algorithm>
#include <unordered_map>
#include <queue>
#include <iomanip>
#include <map>
#include <utility>
#include <numeric>
#include <chrono>
#include <ctime>
#include <bitset>

#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define P pair<int, int>
#define debug(x) cerr << #x << ": " << x << ", "
#define debugln(x) cerr << #x << ": " << x << '\n'

using namespace std;
using ll = long long;
const ll mod = 1e9+7;

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

  int a, b, h; cin >> a >> b >> h;
  cout << (a+b)*h/2 << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
 
int LinearSearch(int A[], int n, int key){

  int i = 0;
  A[n] = key;
  while(A[i] != key){
      i++;
  }

  return i != n;
}
 
int main(){

  int i, n, p, key, sum = 0;
  int A[10000];

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

  scanf("%d", &p);
  for (i = 0; i < p; i++){
    scanf("%d", &key);
    if (LinearSearch(A, n, key) == 1){
      sum++;
    }
  }

  printf("%d\n", sum);

return 0;
}

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

int N, K;
int min_ = 1;

int main() {
  scanf("%d%d", &N, &K);
  for(int i = 0;i < N; i++) {
    min_ = min_ * 2 < min_ + K ? min_ * 2 : min_ + K;
  }

  printf("%d\n", min_);
  return 0;
}


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

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

    int dx[8] = {1,1,0,-1,-1,-1,0,1};
    int dy[8] = {0,-1,-1,-1,0,1,1,1};

    for(int j=0;j<h;j++){
        for(int k=0;k<w;k++){
            if(s[j][k] == '#') continue;

            int tmp = 0;
            for(int d=0;d<8;d++){
                int nj = j + dy[d];
                int nk = k + dx[d];
                if(nj<0 || h<=nj) continue;
                if(nk<0 || w<=nk) continue;
                if(s[nj][nk] == '#') tmp++;
            }
            s[j][k] = char(tmp+'0');
        }
    }

    for(int i=0;i<h;i++) cout << s[i] << endl;
    return 0;
}

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

using namespace std;

typedef long long ll;

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

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

const int MIN_X = -1000000;
const int MAX_X = 1000000;

int main(void) {
    int K, X;
    cin >> K >> X;

    int possible_min = max(MIN_X, X - K + 1);
    int possible_max = min(MAX_X, X + K - 1);

    cout << possible_min;
    for (int i = possible_min + 1; i <= possible_max; i++) {
        cout << " " << i;
    }
    cout << endl;
    
    return 0;
}


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

int main(){
  int N, W;
  cin >> N >> W;
  W++;
  
  vector<int> v(N), w(N);
  vector<long> dp(W, 0);
  
  for(int i=0; i<N; i++){
    cin >> w[i] >> v[i];
  }
  
  for(int i=0; i<N; i++){
    for(int s=W-1; s>=0; s--){
      if(s-w[i] < 0){
        continue;
      }
      dp[s] = max(dp[s], dp[s-w[i]] + v[i]);
    }
  }
  
  cout << dp[W-1] << endl;
  return 0;
}

Measured memory_bytes: 1024
import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val s = sc.next()
    for (len in s.length / 2 - 1 downTo 1) {
        val left = s.substring(0 until len)
        val right = s.substring(len until 2*len)
        if (left == right) {
            println(len*2)
            return
        }
    }
}

Measured memory_bytes: 29596
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <deque>
using namespace std;

using VI = vector <int> ;
using VVI = vector <VI> ;

void solve(int depth, int len, char maxc, vector<char>& arr) {
    if (depth == len) {
        for (int i = 0; i < arr.size(); ++i) {
            printf("%c", arr[i]);
        }
        printf("\n");

        return ;
    }

    for (char ch = 'a'; ch <= maxc; ++ch) {
        arr[depth] = ch;
        solve(depth+1, len, max((char)(ch+1), maxc), arr);
    }
}

int main() {

    int N;
    cin >> N;

    vector <char> arr(N);
    solve(0, N, 'a', arr);

    return 0;
}

Measured memory_bytes: 1536
import numpy as np


A,B,H,M = map(int,input().split())


short_x = np.sin((((H*30)+(M*0.5))/180)*np.pi)*A
short_y = np.cos((((H*30)+(M*0.5))/180)*np.pi)*A

long_x = np.sin(((M*6)/180)*np.pi)*B
long_y = np.cos(((M*6)/180)*np.pi)*B

ans = abs(short_x - long_x)**2 + abs(short_y - long_y)**2

ans = np.sqrt(ans)

print(ans)

Measured memory_bytes: 27192
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
using namespace std;
using ll=long long;
constexpr ll mod=1000000007;
constexpr int inf=1000000000;
constexpr ll linf=1000000000000000000;

int main(){
    string s;
    cin>>s;
    if(s=="RRR")cout<<3;
    else if(s=="RRS")cout<<2;
    else if(s=="SRR")cout<<2;
    else if(s=="SSS")cout<<0;
    else cout<<1;
    cout<<endl;
}


Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
#ifdef LOCAL_DEBUG
  #include "LOCAL_DEBUG.hpp"
#endif
#define int long long
const int MOD = 1e9 + 7;

struct Combination{
  const int MOD = 1e9+7;

  vector<int> fact; //　fact[i] = iの階乗
  void init(int n){
    fact.resize(n+1);
    fact[0] = fact[1] = 1;
    for(int i = 2; i <= n; i++){
      fact[i] = i * fact[i-1] % MOD;
    }
  }

  int nCr(int n, int r){ // nCr = n!/r!(n-r)!
    if(n < r) return 0;
    return fact[n] * mod_pow(fact[r]*fact[n-r]%MOD, MOD-2, MOD) % MOD;
  }

  int mod_pow(int n, int p, int MOD){ // a/n ≡ a*n^(p-2) nとpは互いに素
    int r = 1;
    for(; p > 0; p >>= 1){
      if(p & 1LL) r = (r * n) % MOD;
      n = (n * n) % MOD;
    }
    return r; // r = n^p % MOD
  }

}comb;

signed main(){

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

  comb.init(1e5);
  int ans = 0, t = 1;
  for(int i = 0; i < n-1; i++){
    ans = (ans + t * (x[i+1] - x[i])) % MOD;
    t = (t + comb.mod_pow(i+2, MOD-2, MOD)) % MOD;
  }
  cout << ans * comb.fact[n-1] % MOD << endl;

  return 0;
}


Measured memory_bytes: 1792
#include <algorithm>
#include <iomanip>
#include <ios>
#include <iostream>
#include <string>
#include <vector>
using namespace std;

int main()
{
    int a, b;
    cin >> a >> b;
    if (a * b % 2 == 1) {
        cout << "Odd\n";
    } else {
        cout << "Even\n";
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef  long long ll;
using vll=vector<ll>;
using vi=vector<int>;

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

//pow(llpow,modpow)
template<class T> ll llpow(ll x,T n){ll ans=1;if(x==0)ans=0;while(n){if(n&1)ans*=x;x*=x;n>>=1;}return ans;}
long long modpow(long long a, long long n, long long mod) {long long res = 1;while (n > 0) {if (n & 1) res = res * a % mod;a = a * a % mod;n >>= 1;}return res;}
//最大公約数
template<class T> inline T gcd(T x,T y){if(y==0)return x; else {return gcd(y,x%y);}}
//最小公倍数
template<class T> inline T lcm(T x,T y){return x/gcd(x,y)*y;}
//逆元
long long modinv(long long a, long long m) {long long b = m, u = 1, v = 0;while (b) {long long t = a / b;a -= t * b; swap(a, b);u -= t * v; swap(u, v);}u %= m;if (u < 0) u += m;return u;}

#define rep(i,n) for(ll i=0;i<(ll)n;i++)
#define rep2(i, begin_i, end_i) for (ll i = (ll)begin_i; i < (ll)end_i; i++)

int INF = 1<<30;

int n;
int l[8];
int A,B,C;
int dfs(int cur,int a,int b,int c){
    if(cur==n)return (min(min(a,b),c)>0)?abs(a-A)+abs(b-B)+abs(c-C)-30:INF;

    int cos1=dfs(cur+1,a,b,c);
    int cos2=dfs(cur+1,a+l[cur],b,c)+10;
    int cos3=dfs(cur+1,a,b+l[cur],c)+10;
    int cos4=dfs(cur+1,a,b,c+l[cur])+10;

    return min(min(cos1,cos2),min(cos3,cos4));
}

int main( ){
    cin>>n;
    cin>>A>>B>>C;
    rep(i,n)cin>>l[i];
    int ans=dfs(0,0,0,0);
    cout<<ans<<endl;
    return 0;
}




Measured memory_bytes: 256
#include<cstdio>
#define int long long
#define mod 1000000007
#define inv2 500000004
int n,m,a[3010],f[3010][3010],g[3010][3010],A,B,ans;
signed main(){
	scanf("%lld%lld",&n,&m);
	for(int i=1;i<=n;i++)
		scanf("%lld",&a[i]);
	for(int i=1;i<=n;i++)
		for(int j=1;j<=n;j++)
			f[i][j]=a[i]<a[j];
	for(int i=1;i<=m;i++){
		scanf("%lld%lld",&A,&B);
		for(int j=1;j<=n;j++){
			g[A][j]=(f[A][j]+f[B][j])%mod*inv2%mod;
			g[j][A]=(f[j][A]+f[j][B])%mod*inv2%mod;
			g[B][j]=g[A][j];
			g[j][B]=g[j][A];		
		}
		g[A][B]=g[B][A]=(f[A][B]+f[B][A])%mod*inv2%mod;
		for(int j=1;j<=n;j++){
			f[A][j]=g[A][j];
			f[B][j]=g[B][j];
			f[j][A]=g[j][A];
			f[j][B]=g[j][B];			
		}
	}
	for(int i=1;i<=n;i++)
		for(int j=i+1;j<=n;j++)
			(ans+=f[j][i])%=mod;
	for(int i=1;i<=m;i++)
		(ans*=2)%=mod;
	printf("%lld\n",ans);
}

Measured memory_bytes: 141568
#include <bits/stdc++.h>
 
 
 
using namespace std;
 
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<int> VI;
typedef vector<VI > VVi;
typedef vector<string> VS;
typedef vector<LL> VLL;
typedef pair<int,int> PII;
 
const int    INF  = 0x3f3f3f3f;
const LL     INFL = 0x3f3f3f3f3f3f3f3fLL;
const double DINF = 0x3f3f3f3f;
 
int main(){
	ios::sync_with_stdio(false);
    long long x,p,t;
cin>>x;
p=x/11;
if(x<11){
    if(x<=6){
        cout<<1<<endl;
        return 0;
    }
    else{
        cout<<2<<endl;
        return 0;
    }
}
if(x%11==0){
cout<<p*2<<endl;
}
else if(x%11<=6){cout<<p*2+1<<endl;}
else
cout<<p*2+2<<endl;
 
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int k = scanner.nextInt();
        String s = scanner.next();

        if (s.length() <= k) {
            System.out.println(s);
        } else {
            System.out.println(s.substring(0, k) + "...");
        }
    }
}

Measured memory_bytes: 38552
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
//        long startTime = System.currentTimeMillis();
        Scanner scanner = new Scanner(System.in);

        int N = scanner.nextInt();
        int[] H = new int[N];
        for (int i=0;i<N;i++){
            H[i]=scanner.nextInt();
        }
        scanner.close();

        int count = 0;

        int max = 0;

        for(int i=0;i<N;i++){
            if (H[i] >= max){
                max = H[i];
                count++;
            }
        }

        System.out.println(count);

//        System.out.println(System.currentTimeMillis() - startTime);
    }
}


Measured memory_bytes: 21844
a = input()
a = a[:len(a) - 1]
while True:
    if len(a) % 2 != 0:
        a = a[:len(a)-1]
    else:
        b = True
        for i in range(len(a) // 2):
            if a[i] != a[i + len(a) // 2]:
                b = not b
                break
        if b:
            print(len(a))
            exit()
        a = a[:len(a)-1]


Measured memory_bytes: 3060
def main():
    S = input()
    N = len(S)
    M = N//2
    for i in range(M//2+1):
        if S[i] == S[M-1-i] == S[M+1+i] == S[N-1-i]:
            continue
        else:
            print("No")
            return
    print("Yes")


if __name__ == "__main__":
    main()


Measured memory_bytes: 38256
#include <stdio.h>
#include <string.h>

int main(void){
  char S[100],T[100];
  int flag;

  scanf("%s%s",S,T);

  for(int i = 0;i < strlen(T);i++){
    flag = 1;
    for(int j = 0;j < strlen(T);j++){
      if(S[j] != T[(i+j)%strlen(T)]){
        flag = 0;
        break;
      }
    }
    if(flag){
      printf("Yes\n");
      return 0;
    }
  }

  printf("No\n");
  return 0;
}

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

typedef long long   signed int LL;
typedef long long unsigned int LU;

#define incID(i, l, r) for(int i = (l)    ; i <  (r); i++)
#define incII(i, l, r) for(int i = (l)    ; i <= (r); i++)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); i--)
#define decII(i, l, r) for(int i = (r)    ; i >= (l); i--)
#define  inc(i, n) incID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define  dec(i, n) decID(i, 0, n)
#define dec1(i, n) decII(i, 1, n)

#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))

#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define PQ priority_queue

#define  ALL(v)  v.begin(),  v.end()
#define RALL(v) v.rbegin(), v.rend()
#define  FOR(it, v) for(auto it =  v.begin(); it !=  v.end(); ++it)
#define RFOR(it, v) for(auto it = v.rbegin(); it != v.rend(); ++it)

template<typename T> bool   setmin(T & a, T b) { if(b <  a) { a = b; return true; } else { return false; } }
template<typename T> bool   setmax(T & a, T b) { if(b >  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmineq(T & a, T b) { if(b <= a) { a = b; return true; } else { return false; } }
template<typename T> bool setmaxeq(T & a, T b) { if(b >= a) { a = b; return true; } else { return false; } }
template<typename T> T gcd(T a, T b) { return (b == 0 ? a : gcd(b, a % b)); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }

// ---- ----

int n, k;
vector<pair<LL, LL>> vx, vy;

int main() {
	cin >> n >> k;
	inc(i, n) {
		int x, y;
		cin >> x >> y;
		vx.EB(x, y);
		vy.EB(y, x);
	}
	
	sort(ALL(vx));
	sort(ALL(vy));
	
	LL ans = 4e18;
	inc(xh,  vx.size()) {
	inc(xl, xh) {
	inc(yh,  vy.size()) {
	inc(yl, yh) {
		int c = 0;
		inc(i, n) {
			if(inII(vx[i].FI, vx[xl].FI, vx[xh].FI) && inII(vx[i].SE, vy[yl].FI, vy[yh].FI)) { c++; }
		}
		if(c >= k) { setmin(ans, (vx[xl].FI - vx[xh].FI) * (vy[yl].FI - vy[yh].FI)); }
	}
	}
	}
	}
	
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 256
a,b,c,x = Array.new(4){ gets.to_i }

def coin(x, n); 0.step(n*x, x); end

ans = 0
coin(500, a).each do |s|
  coin(100, b).each do |t|
    coin(50, c).each do |u|
      ans += 1 if s + t + u == x
    end
  end
end

puts ans

Measured memory_bytes: 2044
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define repr(i, n) REPR(i, n, 0)
#define REPR(i, s, e) for(int i=(int)(s-1); i>=(int)(e); i--)
#define pb push_back
#define all(r) r.begin(),r.end()
#define rall(r) r.rbegin(),r.rend()
#define fi first
#define se second

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const ll INF = 1e18;
const ll MOD = 1e9 + 7;
const double EPS = 1e-8;

template<typename T> T chmax(T& a, const T& b){return a = (a > b ? a : b);}
template<typename T> T chmin(T& a, const T& b){return a = (a < b ? a : b);}

int main(){
    int N, W;
    cin >> N >> W;
    vi v(N), w(N);
    rep(i, N) cin >> v[i] >> w[i];
    vi cur(W+1, 0);
    rep(i, N) {
        for(int j = 0; j+ w[i] < W+1; ++j) chmax(cur[j+w[i]], cur[j]+v[i]);
    }
    int ans = 0;
    rep(i, W+1) chmax(ans, cur[i]);
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3140
N=int(input())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
C=list(map(int,input().split()))
result=0

for i in range(N):
    result+=B[A[i]-1]
    if i>0:
        if A[i]-A[i-1]==1:
            result+=C[A[i-1]-1]

print(result)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define N 1000005
#define ll long long int 	
#define MP make_pair
#define pb push_back
#define ppb pop_back
#define sp " "
#define endl "\n"
#define fi first
#define se second
#define ii pair<int,int>
#define lli pair<ll,ll>
#define fast cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(false)
#define fast2 freopen ("badhair.gir","r",stdin);freopen ("badhair.cik","w",stdout);
#define mod 1000000007
#define fs(x,y) for(ll i=1;i<=y;i++) cin>>x[i]
#define fo(i,x,y) for(ll i=x;i<=y;i++)
#define INF 1000000000005
#define ull unsigned long long int
using namespace std;

ll n,m,ar[N],sum,t;

ll f(ll x,ll y)
{
	ll z=x-y;
	z*=z;
	return z;
}

int main()
{
	fast;
	cin>>n;
	fs(ar,n);
	ll mn=1e18;
	for(int i=1;i<=100;i++)
	{
		ll top=0;
		fo(j,1,n)
			top+=f(i,ar[j]);
		mn=min(mn,top);
	}
	cout<<mn<<endl;



}



/*     cd onedrive\desktop\kod
cls

Sinav:21-22 aralik
Aciklama: Muhtemelen 25 aralik
*/

Measured memory_bytes: 256
s = list(map(int, input().split()))
N = s[0]
M = s[1]
C = s[2]
B = list(map(int, input().split()))
x = 0
for i in range(N):
  k = C
  A = list(map(int, input().split()))
  for j in range(M):
    k = k + A[j] * B[j]
  if k > 0:
    x = x + 1
  else:
    pass
print(x)  


Measured memory_bytes: 3064
fun main(args: Array<String>) {
    abc124b()
}

fun abc124b() {
    val n = readLine()!!.toInt()
    val hotelList = readLine()!!.split(" ").map { it.toInt() }

    val count = hotelList.filterIndexed { index: Int, hotel: Int ->
        val leftHighestHotel = hotelList.subList(0, index).max() ?: 0
        hotel >= leftHighestHotel
    }.count()

    println(count)
}



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

int a,b,c,d;

int main()
{
    scanf("%d%d%d%d",&a,&b,&c,&d);
    a += b;
    c += d;
    if(a > c)printf("Left\n");
    if(a < c)printf("Right\n");
    if(a == c)printf("Balanced\n");
    return 0;
}


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

int main() {
ios_base::sync_with_stdio(false);cin.tie(NULL);
int n,x;
cin>>n>>x;
vector <int> L(n),B;
for(auto &e:L)cin>>e;
int d=0;
B.emplace_back(d);
for(int i=0;i<n;i++){
    B.emplace_back(L[i]+d);
    d=L[i]+d;
}
//for(auto x:B)cout<<x <<"\n";
int c=0;
for(auto e:B){
    if(e<=x){c++;}
    else{continue;}
}
cout<<c <<"\n";
}

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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

struct UnionFindTree{
    vector<int>par,sz;
    UnionFindTree(int n){
        par.resize(n);
        sz.resize(n);
        for(int i=0;i<n;i++){
            par[i]=i;
            sz[i]=1;
        }
    }
    int find(int x){
        return x==par[x]?x:par[x]=find(par[x]);
    }
    void unite(int x,int y){
        x=find(x);y=find(y);
        if(x==y)return;
        if(sz[x]<sz[y])swap(x,y);
        sz[x]+=sz[y];
        par[y]=x;
    }
    bool areSame(int x,int y){
        return find(x)==find(y);
    }
    int size(int x){
        return sz[find(x)];
    }
};

int N,H;
int A[111111],B[111111],C[111111],D[111111];


int M=500;
int deg[1111];
bool used[1111];

signed main(){
    cin>>N>>H;
    UnionFindTree uf(1111);
    rep(i,N){
        cin>>A[i]>>B[i]>>C[i]>>D[i];

        int u,v;
        if(C[i]==0){
            u=A[i];
        }
        else{
            u=M+C[i];
        }

        if(D[i]==0){
            v=M+B[i];
        }
        else{
            v=D[i];
        }

        uf.unite(u,v);
        used[u]=used[v]=true;
        deg[u]++;
        deg[v]--;

    }



    used[2*M]=true;
    int ei=0,uku=0;
    rep(i,M){
        if(deg[i]<0){
            cout<<"NO"<<endl;
            return 0;
        }
        if(deg[i]>0){
            ei+=deg[i];
            uf.unite(2*M,i);
        }
    }

    for(int i=M;i<2*M;i++){
        if(deg[i]>0){
            cout<<"NO"<<endl;
            return 0;
        }
        if(deg[i]<0){
            uku+=-deg[i];
            uf.unite(2*M,i);
        }
    }

    if(ei!=uku){
        cout<<"NO"<<endl;
        return 0;
    }


    rep(i,1111)rep(j,1111){
        if(!used[i]||!used[j])continue;
        if(!uf.areSame(i,j)){
            cout<<"NO"<<endl;
            return 0;
        }
    }
    cout<<"YES"<<endl;
    return 0;
}


Measured memory_bytes: 3456
import java.io.*;

class Main {
	public static void main(String[] args){
		int a, b, c;
		try{
			BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
			
			String[] line = br.readLine().split(" ");
			a = Integer.parseInt(line[0]);
			b = Integer.parseInt(line[1]);
			c = Integer.parseInt(line[2]);
			
			if(a < b ){
			  if(b < c){
				System.out.println("Yes");
			  } else {
			  	System.out.println("No");
			  	}
			  } else {
				System.out.println("No");
			    }
		} catch(Exception e){
		}
	}
}

Measured memory_bytes: 24268
#include <bits/stdc++.h>
#define int long long int
#define ldouble long double
#define vint vector<int> 
#define for(i,a,n) for(i=a;i<n;i++)
#define INF (int)1000000007

//etprecision()<<

using namespace std;

void fin(int i,int n,vint &a){
    for(i,0,n){
        cin>>a.at(i);
    } 
} 

signed main() {
    int i;
    int N,M;
    cin>>N>>M;
    vint P(M),Y(M);
    vector<vector<int> > group(N,vector<int>(0));
    for(i,0,M){
        cin>>P.at(i)>>Y.at(i);
        group.at(P.at(i)-1).push_back(Y.at(i));  //県ごとに市を追加
    }

    for(i,0,N){
        sort(group.at(i).begin(),group.at(i).end());
    }

    for(i,0,M){
        int p=P.at(i)-1;
        int y=Y.at(i);
        int n=(int)(lower_bound(group.at(p).begin(),group.at(p).end(),y)-group.at(p).begin()+1); //何番目か
        printf("%06lld%06lld\n",p+1,n);        
    }

return 0;
}

Measured memory_bytes: 8576
// Template begins
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <stdio.h>
#include <stack>
#include<queue>
#include <map>
#include <cmath>
#include<cstring>
using namespace std;
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define ll long long
#define endl "\n"
#define lb lower_bound
#define ub upper_bound
#define fo(i,a,b) for(i=a;i<=b;i++)
#define all(v) (v).begin(),(v).end()
#define sort0(v) sort(all(v))
#define lbb(a,b,arr,x) lower_bound(arr+a,arr+b+1,x)-arr
#define ubb(a,b,arr,x) upper_bound(arr+a,arr+b+1,x)-arr
#define freq(a,b,arr,x) upper_bound(arr+a,arr+b+1,x)-lower_bound(arr+a,arr+b+1,x)
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define d0(x) cout<<(x)<<" "
#define d1(x) cout<<(x)<<endl
#define d2(x,y) cout<<(x)<<" "<<(y)<<endl
#define d3(x,y,z) cout<<(x)<<" "<<(y)<<" "<<(z)<<endl
#define d4(a,b,c,d) cout<<(a)<<" "<<(b)<<" "<<(c)<<" "<<(d)<<endl
#define d5(a,b,c,d,e) cout<<(a)<<" "<<(b)<<" "<<(c)<<" "<<(d)<<" "<<(e)<<endl
#define d6(a,b,c,d,e,f) cout<<(a)<<" "<<(b)<<" "<<(c)<<" "<<(d)<<" "<<(e)<<" "<<(f)<<endl
#define max3(a,b,c) max(max((a),(b)),(c))
#define max4(a,b,c,d) max(max((a),(b)),max((c),(d)))
#define ss second
#define ff first
#define pb push_back
#define mp make_pair
#define printp(x) cout << x.ff << " " << x.ss << endl
template<class L, class R> ostream& operator<<(ostream &os, pair<L,R> P) {
    return os << P.first << " " << P.second;
}
template<class T> ostream& operator<<(ostream &os, vector<T> V) {
    for(auto v : V) os << v << "\n ";
    return cout << "";
}
template<class T> ostream& operator<<(ostream &os, set<T> S){
    for(auto s:S) os<<s<<" ";
    return cout << "";
}
const ll mod=998244353;
#define inf 9999999999999

ll inv(ll i){if(i==1) return 1;return (mod-((mod/i)*inv(mod%i))%mod)%mod;}

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

ll pwr(ll a, ll b) {a %= mod; ll res = 1;while (b > 0) {if (b & 1) res = res * a % mod; a = a * a % mod; b >>= 1;}return res;}
//Template ends
vector<vector<int>> adj;
vector<bool> vis;
void dfs(int u){
    vis[u]=1;
    for(auto v:adj[u]){
        if(!vis[v])dfs(v);
    }
}
int main(){
    fio;
    
    int n,m,c=0;
    cin>>n>>m;
    adj.assign(n+1,{});
    vis.assign(n+1,0);
    for(int i=0;i<m;i++){
        int u,v;
        cin>>u>>v;
        adj[u].pb(v);
        adj[v].pb(u);
    }
    for(int i=1;i<=n;i++){
        if(!vis[i]){
            c++;
            dfs(i);
        }
    }
    d1(c-1);
}

Measured memory_bytes: 9276
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=20;
int read(){
    int f=1,g=0;char ch=getchar();
    for (;!isdigit(ch);ch=getchar()) if (ch=='-') f=-1;
    for (;isdigit(ch);ch=getchar()) g=g*10+ch-'0';
    return f*g;
}
int n,a[N];
unordered_map<int,ll> ans[N][N];
ll calc(int l,int r,int fl,int fr){
	if (l>r) return 0;
	if (l==r) return (ll)(fl+fr)*a[l];
	if (ans[l][r].count((fl<<15)+fr)) return ans[l][r][(fl<<15)+fr];
	ll cur=1e18;
	for (int i=l;i<=r;i++)
	cur=min(cur,(ll)(fl+fr)*a[i]+calc(l,i-1,fl,fl+fr)+calc(i+1,r,fl+fr,fr));
	return ans[l][r][(fl<<15)+fr]=cur;
}
int main(){
	n=read();
	for (int i=1;i<=n;i++) a[i]=read();
	printf("%lld\n",calc(2,n-1,1,1)+a[1]+a[n]);
	return 0;
}


Measured memory_bytes: 5760
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using db = double;
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define all(v) (v).begin(), (v).end()
#define siz(v) (ll)(v).size()
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repi(i, x, n) for (ll i = x; i < (ll)(n); i++)
#define lb lower_bound
#define ub upper_bound
typedef pair<int, int> P;
typedef pair<ll, ll> PL;
const ll mod = 1000000007;
const ll INF = 1000000099;
vector<ll> dx = {-1, 1, 0, 0}, dy = {0, 0, -1, 1};
//cin.tie(0);ios::sync_with_stdio(false);

signed main()
{
    int n;
    cin >> n;
    db ans = 0;
    vector<tuple<double, ll, ll>> v(0);
    rep(i, n)
    {
        ll x, y;
        cin >> x >> y;
        if (!x && !y)
        {
            continue;
        }

        tuple<double, ll, ll> a = make_tuple(atan2(x, y), x, y);
        v.pb(a);
    }

    sort(all(v));
    /*rep(i,siz(v)){
        cout<<get<1>(v[i])<<" "<<get<2>(v[i])<<endl;
    }*/

    for (int i = 0; i < siz(v); i++)
    {
        for (int j = i; j < 2*siz(v); j++)
        {
            if(siz(v)<=j-i)continue;

            double x = 0, y = 0;
            for (int k = i; k <= j; k++)
            {
                x += get<1>(v[k%siz(v)]);
                y += get<2>(v[k%siz(v)]);
                //cout<<x<<" "<<y<<endl;
                
            }
            //cout<<i<<" "<<j<<" "<<x*x+y*y<<endl;
            ans = max(ans, x * x + y * y);
        }
    }

    cout << fixed << setprecision(20) << sqrt(ans) << endl;
}


Measured memory_bytes: 384
N, K = map(int, input().split())
D = [int(i) for i in input().split()]
M = N

while True:
  S = str(M)
  flag = 0
  for s in S:
    if int(s) in D:
      M += 1
      break
  else:
    break
print(S)
#N = str(N)
#L = len(N)
#for i in range(L):
#  j = -1-i
#  x = int(N[j])
#  if int(N[j]) in D:
#    while int(N[j]) in D:
      

Measured memory_bytes: 2940
#include <algorithm>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <set>
#include <stdio.h>
#include <string>
#include <utility>
#include <vector>

using namespace std;

int main() {
  int a, b, c;
  cin >> a >> b >> c;
  int ans = 100000;
  for (int i = 0; i <= 100; i++) {
    if (a > i || b > i || c > i)
      continue;
    int aa, bb, cc;
    int score = (i - a) / 2;
    aa = a + (i - a) / 2 * 2;
    score += (i - b) / 2;
    bb = b + (i - b) / 2 * 2;
    score += (i - c) / 2;
    cc = c + (i - c) / 2 * 2;
    if ((i * 3 - aa - bb - cc) % 2 == 1)
      continue;
    score += (i * 3 - aa - bb - cc) / 2;
    ans = min(ans, score);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#define ll long long int
#define mod 1000000007
#define pii pair<int, int>
#define fr(n) for (int i = 0; i < n; i++)
#define fr1(n) for (int i = 1; i <= n; i++)
using namespace std;

int main() {
    ios::sync_with_stdio(false);
    int n, a[100005] = {}, b, y = 0, z = 0;
    cin >> n;
    fr(n) cin >> b, a[b]++;
    fr(100004) {
        if (a[i]) a[i]--;
        if (a[i] % 2) z += a[i] / 2, y++;
        else if (a[i]) z += a[i] / 2;
    }
    if (y % 2) z++;
    z += y / 2;
    cout << n - z * 2;
}

Measured memory_bytes: 640
/*..................................
manojeet24
....................................*/
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define fl(i,a,b) for(int i=a;i<b;i++)
#define flr(i,a,b) for(int i=a;i>b;i--)
#define fast ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
#define endl '\n'
vector<int> adjlist[100005];
bool vis[100005];
int lvl[100005];
int dfs(int node)
{
    vis[node]=true;
    lvl[node]=0;
    int mx=0;
    fl(i,0,adjlist[node].size())
    {
       // lvl[adjlist[node][i]]=max(lvl[adjlist[node][i]],lvl[node]+1);
        if(vis[adjlist[node][i]]==false)
            mx=max(mx,dfs(adjlist[node][i]));
        else
            mx=max(mx,lvl[adjlist[node][i]]);
    }
    return lvl[node]=mx+1;
}
int main()
{
    int n,m;
    cin>>n>>m;
    while(m--)
    {
        int x,y;
        cin>>x>>y;
        adjlist[x].push_back(y);
    }
    fl(i,1,n+1)
    {
        if(!vis[i])
        {
           // cout<<i<<endl;
            dfs(i);
        }
    }
   // fl(i,1,n+1)
     //   cout<<lvl[i]<<" ";
    cout<<*max_element(lvl+1,lvl+n+1)-1;

}



Measured memory_bytes: 8192
// AtCoder Regular Contest 062
// C - AtCoDeerくんと選挙速報 / AtCoDeer and Election Report

#include <cstdio>
#include <algorithm>
using namespace std;

typedef long long int ll;


int N;
ll A, B;

int main() {

  ll a, b, p;

  scanf("%d", &N);
  scanf("%lld%lld", &A, &B);
  for (int i = 1; i < N; i++) {
    scanf("%lld%lld", &a, &b);
    p = max((A + a - 1) / a, (B + b - 1) / b);
    A = a * p;
    B = b * p;
  }

  printf("%lld\n", A + B);

  return 0;

}




Measured memory_bytes: 128
pub mod contest {
    pub mod input {
        use std::io;
        use std::str::FromStr;
        use std::fmt::Debug;

        pub fn read_line<F>() -> F
        where F: FromStr, <F as FromStr>::Err: Debug {
            let mut input = String::new();
            io::stdin().read_line(&mut input).unwrap();
            input.trim().parse().unwrap()
        }

        pub fn read_words<F>() -> Vec<F>
        where F: FromStr, <F as FromStr>::Err: Debug {
            let mut input = String::new();
            io::stdin().read_line(&mut input).unwrap();
            input
                .split_whitespace()
                .map(|i| i.parse().unwrap())
                .collect()
        }

        pub fn read_matrix<F>(num_lines: usize) -> Vec<Vec<F>>
        where F: FromStr, <F as FromStr>::Err: Debug {
            (0..num_lines).map(|_| read_words()).collect()
        }

        // 所有権的な問題で SplitWhitespace を直接持てないので妥協
        // まあ、一行のデータの数なんてそんなに多くないだろうし
        pub struct WordsReader {
            words: Vec<String>,
            cur: usize,
        }

        impl WordsReader {
            pub fn new() -> Self {
                let mut input = String::new();
                io::stdin().read_line(&mut input).unwrap();
                WordsReader {
                    words: input.split_whitespace().map(|i| i.to_owned()).collect(),
                    cur: 0,
                }
            }

            pub fn next<F>(&mut self) -> F
            where F: FromStr, <F as FromStr>::Err: Debug {
                let v: F = self.words[self.cur].parse().unwrap();
                self.cur += 1;
                v
            }
        }
    }
}

fn solve(v: &mut Vec<f64>) -> f64 {
    v.sort_by(|a, b| a.partial_cmp(b).unwrap());
    let mut value = v[0];
    for i in 1..v.len() {
        value = (value + v[i]) / 2.0;
    }
    value
}

#[test]
fn test_solve() {
    assert_eq!(solve(&mut vec![3.0, 4.0]), 3.5);
}


fn main() {
    contest::input::read_line::<usize>();
    let mut v: Vec<f64> = contest::input::read_words();
    println!("{}", solve(&mut v));
}


Measured memory_bytes: 4476
import java.util.*;
public class Main {

    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        int[][] nums=new int[n][2];
        for(int i=0;i<n;i++){
            nums[i][0]=sc.nextInt();
            nums[i][1]=sc.nextInt();
        }
        int[][] dirs=new int[n*n][2];
        for(int i=0;i<n;i++){
            for(int j=0;j<n;j++){
                if(i==j)continue;
                dirs[n*i+j][0]=nums[i][0]-nums[j][0];
                dirs[n*i+j][1]=nums[i][1]-nums[j][1];
            }
        }
        int ans=0;
        int[] tmp=new int[2];
        int tmpa=0;
        for(int i=0;i<dirs.length;i++){
            tmp[0]=dirs[i][0];
            tmp[1]=dirs[i][1];
            if(tmp[0]==0&&tmp[1]==0)continue;
            tmpa=0;
            for(int j=0;j<dirs.length;j++){
                if(tmp[0]==dirs[j][0]&&tmp[1]==dirs[j][1]){
                    tmpa++;
                }
            }
            ans=Math.max(ans,tmpa);
        }
        System.out.println(n-ans);
    }
}

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

int int_len(int n) {
  int s=0;
  while(n!=0) s++, n/=10;
  return s;
}

int int_sum(int n) {
  int m=0,s=0,a=n;
  while(a!=0) s++, a/=10;
  for(int i=s-1;i>=0;i--) m+=n/((int)pow(10,i))-(n/((int)pow(10,i+1)))*10;
  return m;
}


int vec_sum(vector<int> v){
  int n=0;
  for(int i=0;i<v.size();i++) n+=v[i];
  return n;
}
///////////////////////////
int main() {
  int a=0,b=0,c=0,d=0,m=0,n=0,h=0,w=0,count=0,ans=0;
  string s;
  cin>>a>>b>>c>>d;
  n=min(b,d)-max(a,c);
  if(n>0){
    cout<<n<<endl;
  }else{
    cout<<0<<endl;
  }
}
///////////////////////////

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define mp make_pair
#define si(x) int(x.size())
const int mod=1000000007,MAX=200005,INF=1<<30;
vector<ll> wh[MAX][2];

int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int Q;cin>>Q;
    while(Q--){
        int N;cin>>N;
        ll sum=0;
        for(int i=0;i<N;i++){
            wh[i][0].clear();
            wh[i][1].clear();
        }
        
        for(int i=0;i<N;i++){
            int k,l,r;cin>>k>>l>>r;
            k--;
            if(l>r) wh[k][0].push_back(l-r);
            if(l<r) wh[k+1][1].push_back(r-l);
            sum+=min(l,r);
        }
        
        priority_queue<ll> PQ;
        for(int i=N-1;i>=0;i--){
            for(ll a:wh[i][0]) PQ.push(a);
            if(!PQ.empty()){
                sum+=PQ.top();
                PQ.pop();
            }
        }
        while(!PQ.empty()) PQ.pop();
        
        for(int i=0;i<N;i++){
            for(ll a:wh[i][1]) PQ.push(a);
            if(!PQ.empty()){
                sum+=PQ.top();
                PQ.pop();
            }
        }
        
        cout<<sum<<"\n";
    }
}


Measured memory_bytes: 17688
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pint pair<int, int>
#define pll pair<ll, ll>
#define vint vector<int >
#define vll vector<ll >
#define ALL(x) (x).begin(), (x).end()
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i,n) for (int i = 0; i < (n); ++i)
const int INF = 100100100;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    int n;
    cin >> n;
    vint D1(n),D2(n);
    int check = 0;
    int is_yes = 0;
    REP(i,n){
        cin >> D1[i] >> D2[i];
        if(D1[i]==D2[i]){
            check++;
        }else{
            check = 0;
        }
        if(check == 3){
            is_yes = 1;
        }
    }
    if(is_yes){
        cout << "Yes\n";
    }else{
        cout << "No\n";
    }
    return 0;
}

Measured memory_bytes: 3660
#include<stdio.h>
#include<algorithm>
#include<functional>
#include<cmath>
using namespace std;
long long  mod = 1000000007;
int main()
{
	long long K, A, B;
	scanf("%lld%lld%lld", &K, &A, &B);
	if (B - A <= 2) {
		printf("%lld", K + 1);
	}
	else {
		if (A >= K) {
			printf("%lld", K + 1);
		}
		else {
			K -= A - 1;
			K -= 2;
			printf("%lld", B + (B - A) * (K / 2) + (K % 2));
		}
	}
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

using namespace std;

#define rep(i, a, b) for (long long i = a; i < b; i++)
#define rrep(i, a, b) for (int i = a; i <= b; i++)
#define all(a)  begin((a)),end((a))
#define uniq(c) (c).erase(unique(all((c))), end((c)))

int main()
{
    long long N, K, ans = 0ll; cin >> N >> K;
    vector<long long> H(N);
    rep (i, 0ll, N) cin >> H[i];

    sort(H.begin(), H.end(), greater<long long>());
    rep (i, K, N) ans += H[i];

    cout << ans << endl;
}

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

int main(){
	int n, i, j;
	int cards[4][13]={0};
	char suit; //?????????
	int num;
	
	cin >> n;
	
		for(i = 0; i < n; i++){
			cin >> suit >> num;

			if(suit == 'S'){
				cards[0][num - 1]++;
			}else if(suit == 'H'){
				cards[1][num - 1]++;
			}else if(suit == 'C'){
				cards[2][num - 1]++;
			}else{
				cards[3][num - 1]++;
		}
	}

	for(i = 0; i < 4; i++){
		for(j = 0; j < 13; j++){
			if(cards[i][j] == 0){
				if(i == 0){
					cout << 'S' << " " << j + 1 << endl;
				}else if(i == 1){
					cout << 'H' << " " << j + 1 << endl;
				}else if(i == 2){
					cout << 'C' << " " << j + 1 << endl;
				}else{
					cout << 'D' << " " << j + 1 << endl;
				}
			}
		}
	}
 	return 0;
}

Measured memory_bytes: 3076
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, s, n) for (int i = (int)(s); i < (int)(n); i++)
const ll mod = ll(1e9) + 7;
const int INF = int(1e9);
int main()
{
    int N;
    int Q;
    cin >> N >> Q;
    string S;
    cin >> S;
    vector<int> cnt(N);
    reps(i, 1, N)
    {
        if (S[i - 1] == 'A' && S[i] == 'C')
            cnt[i] = cnt[i - 1] + 1;
        else
            cnt[i] = cnt[i - 1];
    }
    vector<int> ans;
    rep(i, Q)
    {
        int l, r;
        cin >> l >> r;
        l--;
        r--;
        ans.push_back(cnt[r] - cnt[l]);
    }
    rep(i, Q) cout << ans[i] << endl;
    return 0;
}


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

int main(){
	int n ; cin >> n ;
	vector<int> a(n) ;
	for(int i=0;i<n;i++) cin >> a.at(i) ;
	int cnt = 0 ;
	int bot = 1 ;
	for(int i=0;i<n;i++){
		if(bot==2){
			cout << cnt << endl ;
			return 0 ;
		}
		cnt++ ;
		bot = a.at(bot-1) ;
	}
	cout << -1 << endl ;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
int a[100 + 5],b[100 + 5];
int main(){
	int n;
	cin >> n;
	for(int i=0;i<n-1;i++){
		cin >> a[i];
	}
	b[0] = a[0];
	for(int i = 1;i<n;i++){
		b[i] = min(a[i],a[i-1]);
	}
	b[n-1] = a[n-2];
	long long sum = 0;
	for(int i=0;i<n;i++){
		sum+=b[i];
	}
	cout << sum << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <queue>
#include <cmath>
#include <map>
#include <iomanip>

using namespace std;
typedef long long  ll;

int main()
{
	ll N;
	cin >> N;
	ll mm1 = 0, mm2 = 0;
	map<ll, ll> m;
	vector<ll> a(N);
	for (ll i = 0; i < N; i++)
	{
		cin >> a[i];
		m[a[i]]++;
		if (m[a[i]] % 2 == 0 && m[a[i]] != 0) {
			if (mm1 < a[i]) {
				mm2 = mm1;
				mm1 = a[i];
			}
			else {
				if (mm2 < a[i]) {
					mm2 = a[i];
				}
			}
		}
	}
	cout << mm2 * mm1 << endl;
	return 0;
}

Measured memory_bytes: 7296
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
//template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
 
/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
*/

int main(){
    int H, W; cin >> H >> W;
    int cnt = 0;
    for(int i=0; i<H; i++){
        for(int j=0; j<W; j++){
            char c; cin >> c;
            if(c == '#') cnt++;
        }
    }

    if(cnt == H+W-1) cout << "Possible" << endl;
    else cout << "Impossible" << endl;
}

Measured memory_bytes: 256
def main():
    N = int(input())
    S = input()
    Q = int(input())
    K = list(map(int, input().split()))
    for k in K:
        d_cnt = 0
        m_cnt = 0
        dm_cnt = 0
        answer = 0
        for i in range(N):
            c = S[i]
            if i-k >= 0:
                prevc = S[i-k]
                if prevc == "D":
                    d_cnt -= 1
                    dm_cnt -= m_cnt
                elif prevc == "M":
                    m_cnt -= 1
            if c == "D":
                d_cnt += 1
            elif c == "M":
                m_cnt += 1
                dm_cnt += d_cnt
            elif c == "C":
                answer += dm_cnt
        print(answer)


if __name__ == "__main__":
    main()


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

int main() {
  int N;
  cin >> N;
  int ans = 111;
  for (int i = 1; i < 10; i++) {
    if (N <= ans * i) {
      cout << ans * i << endl;
      break;
    }
    else if (i == 9) {
      cout << 1111 << endl;
    }
  }
}

Measured memory_bytes: 3608
#include <bits/stdc++.h>
using namespace std;
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
#define ll long long
#define debug(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " = " << a << endl;
	err(++it, args...);
}

ll mod = 1e9+7;

int main(){
    fastio
    string s;
    cin >> s;
    ll sum = 0;
    for(char c : s) sum += (c-'0');
    cout << (sum%9==0 ? "Yes" : "No");
}


Measured memory_bytes: 3740
#include <algorithm>
#include <climits>
#include <complex>
#include <cstring>
#include <iostream>
#include <map>
#include <set>
#include <vector>

// using
using namespace std;

// typedef
typedef long long ll;

// define
#define ALL(c) (c).begin(), (c).end()
#define SORT(c) sort(ALL(c))
#define REVERSE(c) reverse(ALL(c))
#define UNIQ(c) unique(ALL(c))
#define FOR(i, a, b, c) for (int i = (int)(a); i < (int)(b); i += (int)(c))
#define REP(i, n) FOR(i, 0, n, 1)
#define RFOR(i, a, b, c) for (int i = (int)(a); i >= (int)(b); i -= (int)(c))
#define RREP(i, n) RFOR(i, n, 0, 1)

// functions
int ceil(int a, int b) {
    return (a + b - 1) / b;
}
int round(int a, int b) {
    return (a + b / 2) / b;
}
int gcd(int a, int b) {
    return b ? gcd(b, a % b) : a;
}
int lcm(int a, int b) {
    return a * b / gcd(a, b);
}
template <class T> bool amax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template <class T> bool amin(T &a, const T &b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}

// main
int main() {
    string S, res = "";
    REP(i, 3) {
        cin >> S;
        res += S[0] - 'a' + 'A';
    }
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define F first
#define S second

const int mx=1000010;
const ll mod=1e9+7;


int main(){
  int a,b,c;
  cin >> a >> b >> c;
  if(a==b && b==c){
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }

  return 0;
}

Measured memory_bytes: 384