akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstring>
#include <string>    
#include <vector>
#include <queue>
#include <map>
#include <algorithm>
#include <cmath>
using namespace std;
typedef long long ll;
ll n, q;
string str;
char t[200008], d[200008];

bool isfalll(ll at){
	for(ll j = 1; j <= q; j++){
		if(str[at-1] == t[j]){
			if(d[j] == 'L'){at--;}
			else{at++;}
		}
		if(at == 0){return true;}
	}
	return false;
}

bool isfallr(ll at){
	for(ll j = 1; j <= q; j++){
		if(str[at-1] == t[j]){
			if(d[j] == 'L'){at--;}
			else{at++;}
		}
		if(at == n+1){return true;}
	}
	return false;
}

int main(){
	cin >> n >> q >> str;
	for(ll i = 1; i <= q; i++){cin >> t[i] >> d[i];}
	
	ll ngl = 0;
	ll okl = n+1;
	while(okl-ngl > 1){
		ll mid  = (okl+ngl)/2;
		if(isfalll(mid)){ngl = mid;}
		else{okl = mid;}
	}
	
	ll ngr = n+1;
	ll okr = 0;
	while(ngr-okr > 1){
		ll mid  = (okr+ngr)/2;
		if(isfallr(mid)){ngr = mid;}
		else{okr = mid;}
	}
	//cout << ngl << ngr << endl;
	cout << max(ngr-ngl-1, 0LL) << endl;
	return 0;
}

Measured memory_bytes: 900
#include <bits/stdc++.h>
using namespace std;
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
typedef pair<int, int> Pint;
typedef pair<int64_t, int64_t> Pll;

int main() {
    int64_t N, len, ans = 0;
    cin >> N;
    vector<int64_t> A(N);
    for (int i = 0; i < N; i++) {
        cin >> A.at(i);
        if (i != 0) {
            A.at(i) = A.at(i) + A.at(i - 1);
        }
    }
    len = A.at(N - 1);
    for (int i = 0; i < N; i++) {
        if (A.at(i) * 2 >= len) {
            if (i == 0) {
                ans = A.at(i) * 2 - len;
                cout << ans << endl;
                return 0;
            }
            ans = min(A.at(i) * 2 - len, len - 2 * A.at(i - 1));
            cout << ans << endl;
            return 0;
        }
    }
    cout << len - 2 * A.at(N - 1) << endl;
    

}


Measured memory_bytes: 1792
package main

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

func getScanner(fp *os.File) *bufio.Scanner {
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 1000005), 1000005)
	return scanner
}
func getNextString(scanner *bufio.Scanner) string {
	scanner.Scan()
	return scanner.Text()
}
func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}
func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}
func getNextUint64(scanner *bufio.Scanner) uint64 {
	i, _ := strconv.ParseUint(getNextString(scanner), 10, 64)
	return i
}
func getNextFloat64(scanner *bufio.Scanner) float64 {
	i, _ := strconv.ParseFloat(getNextString(scanner), 64)
	return i
}
func main() {
	fp := os.Stdin
	wfp := os.Stdout
	cnt := 0
	if os.Getenv("MASPY") == "ますピ" {
		fp, _ = os.Open(os.Getenv("BEET_THE_HARMONY_OF_PERFECT"))
		cnt = 2
	}
	if os.Getenv("MASPYPY") == "ますピッピ" {
		wfp, _ = os.Create(os.Getenv("NGTKANA_IS_GENIUS10"))
	}
	scanner := getScanner(fp)
	writer := bufio.NewWriter(wfp)
	solve(scanner, writer)
	for i := 0; i < cnt; i++ {
		fmt.Fprintln(writer, "-----------------------------------")
		solve(scanner, writer)
	}
	writer.Flush()
}
func solve(scanner *bufio.Scanner, writer *bufio.Writer) {
	n := getNextInt(scanner)
	aa := make([]int, n)
	bb := make([]int, n)

	for i := 0; i < n; i++ {
		aa[i] = getNextInt(scanner)
		bb[i] = getNextInt(scanner)
	}
	sort.Ints(aa)
	sort.Ints(bb)
	if n%2 == 0 {
		fmt.Fprintln(writer, bb[n/2]+bb[n/2-1]-(aa[n/2]+aa[n/2-1])+1)
	} else {
		fmt.Fprintln(writer, bb[n/2]-aa[n/2]+1)
	}
}


Measured memory_bytes: 10472
#include<stdio.h>
int main()
{
  int a,b;
  char s[11],t[11];
  scanf("%s %s",s,t);
  scanf("%d %d",&a,&b);
  char x[10];
  scanf("%s",x);
  if(s[0]==x[0]){
    a--;
  }
  else{
    b--;
  }
  printf("%d %d\n",a,b);
  return 0;
}

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

int main() {
  std::ios::sync_with_stdio(false);
  cin.tie(0); cout.tie(0);
  string S;
  cin>>S;
  sort(S.begin(),S.end());
  cout<<(S=="abc"?"Yes":"No")<<endl;
  return 0;
}

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

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	double	n, t, a;
	cin >> n >> t >> a;

	/* vector<double>	V(n); */
	int	ans;
	double	dif;
	dif = DBL_MAX;
	rep(i, n)
	{
		double	h;
		cin >> h;
		double	tempt;
		tempt = t - h * 0.006;
		if (abs(tempt - a) < dif)
		{
			ans = i + 1;
			dif = abs(tempt - a);
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
package main

import (
	"fmt"
)

func main() {
	var N int
	fmt.Scanf("%d", &N)
	A := make([]int64, N)
	var cnt int64
	var res int64
	var mina int64 = 1145141919
	for i := 0; i < N; i++ {
		fmt.Scanf("%d", &A[i])
		res += abs(A[i])
		if mina > abs(A[i]) {
			mina = abs(A[i])
		}
		if A[i] < 0 {
			cnt++
		}
	}
	if cnt%2 == 1 {
		res -= 2 * abs(mina)
	}
	fmt.Println(res)
}

func min(x, y int64) int64 {
	if x < y {
		return x
	} else {
		return y
	}
}

func abs(x int64) int64 {
	if x < 0 {
		return -x
	} else {
		return x
	}
}


Measured memory_bytes: 6656
from math import sqrt


N, M = map(int, input().split())

ans = 1
for i in range(1, int(sqrt(M)) + 1):
    if M % i == 0:
        j = M // i
        if M / N >= j:
            ans = max(ans, j)
        elif M / N >= i:
            ans = max(ans, i)

print(ans)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
 
#ifndef LOCAL_
#define fprintf if( false ) fprintf
#endif // LOCAL_
#define dump() fprintf(stderr, "#%s.%d\n", __func__, __LINE__);
#define dumpl(x1) fprintf(stderr, "#%s.%d (%s) = (%ld)\n", __func__, __LINE__, #x1, x1);
#define dumpll(x1, x2) fprintf(stderr, "#%s.%d (%s, %s) = (%ld, %ld)\n", __func__, __LINE__, #x1, #x2, x1, x2);
#define dumplll(x1, x2, x3) fprintf(stderr, "#%s.%d (%s, %s, %s) = (%ld, %ld, %ld)\n", __func__, __LINE__, #x1, #x2, #x3, x1, x2, x3);
#define dumpd(x1) fprintf(stderr, "#%s.%d (%s) = (%lf)\n", __func__, __LINE__, #x1, x1);
#define dumpdd(x1, x2) fprintf(stderr, "#%s.%d (%s, %s) = (%lf, %lf)\n", __func__, __LINE__, #x1, #x2, x1, x2);
#define loop for(;;)
 
struct S002 {
  int n;
  S002& operator > (long& x) {
    n = x;
    return *this;
  }
  S002& operator > (long&& x) {
    n = x;
    return *this;
  }
  S002& operator >= (long& x) {
    if( scanf("%ld", &x) <= 0 ) exit(0);
    return *this;
  }
  S002& operator >= (double& x) {
    if( scanf("%lf", &x) <= 0 ) exit(0);
    return *this;
  }
  S002& operator >= (std::string& s) {
    if( not (std::cin >> s) ) exit(0);
    return *this;
  }
  template<typename a>
  S002& operator >= (std::vector<a>& v) {
    v.resize(n);
    for(long i = 0; i < n; ++i) {
      *this >= v[i];
    }
    return *this;
  }
  template<typename a, std::size_t s>
  S002& operator >= (std::array<a, s>& x) {
    for(long i = 0; i < (long)s; ++i) {
      *this >= x[i];
    }
    return *this;
  }
};


struct Solver {
  long n;
  std::vector<long> xs;
  Solver() {
    S002 reader;
    reader >= n >n>= xs;
  }
  long f(long begin) {
    dumpl(begin);
    if( n - begin <= 2 ) {
      return 1;
    }
    long state;
    if( xs[begin] == xs[begin+1] ) state = 0;
    if( xs[begin] <  xs[begin+1] ) state = 1;
    if( xs[begin] >  xs[begin+1] ) state = -1;
    for(long i = begin+2; i < n; ++i) {
      if( xs[i-1] < xs[i] ) {
        if( state == -1 ) {
          return 1 + f(i);
        }
        state = 1;
      }
      if( xs[i-1] > xs[i] ) {
        if( state == 1 ) {
          return 1 + f(i);
          // res += 1;
        }
        state = -1;
      }
    }
    return 1;
  }
  void solve() {
    long res = f(0);
    // if( n <= 2 ) {
    //   printf("1\n");
    //   return;
    // }
    // long state;
    // if( xs[0] == xs[1] ) state = 0;
    // if( xs[0] <  xs[1] ) state = 1;
    // if( xs[0] >  xs[1] ) state = -1;
    // long res = 1;
    // for(long i = 2; i < n; ++i) {
    //   if( xs[i-1] < xs[i] ) {
    //     if( state == -1 ) {
    //       res += 1;
    //     }
    //     state = 1;
    //   }
    //   if( xs[i-1] > xs[i] ) {
    //     if( state == 1 ) {
    //       res += 1;
    //     }
    //     state = -1;
    //   }
    // }
    printf("%ld\n", res);
  }    
  ~Solver() { fprintf(stderr, "--end--\n"); }
};
 

int main() {
  loop std::unique_ptr<Solver>(new Solver())->solve();
  return 0;
}

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

using vi = vector<int>; using vvi = vector<vi>; using vvvi = vector<vvi>;
using ll = long long int;
using vll = vector<ll>; using vvll = vector<vll>; using vvvll = vector<vvll>;
using vd = vector<double>; using vvd = vector<vd>; using vvvd = vector<vvd>;
using P = pair<int, int>;
using Pll = pair<ll, ll>;
using cdouble = complex<double>;

const double INFD = numeric_limits<double>::infinity();
const double PI = 3.14159265358979323846;
#define Loop(i, n) for(int i = 0; i < (int)(n); i++)
#define Loop1(i, n) for(int i = 1; i <= (int)(n); i++)
#define Loopr(i, n) for(int i = (int)(n) - 1; i >= 0; i--)
#define Loopr1(i, n) for(int i = (int)(n); i >= 1; i--)
#define Foreach(buf, container) for(auto buf : container)
#define Loopdiag(i, j, h, w, sum) for(int i = ((sum) >= (h) ? (h) - 1 : (sum)), j = (sum) - i; i >= 0 && j < (w); i--, j++)
#define Loopdiagr(i, j, h, w, sum) for(int j = ((sum) >= (w) ? (w) - 1 : (sum)), i = (sum) - j; j >= 0 && i < (h); j--, i++)
#define Loopdiagsym(i, j, h, w, gap) for (int i = ((gap) >= 0 ? (gap) : 0), j = i - (gap); i < (h) && j < (w); i++, j++)
#define Loopdiagsymr(i, j, h, w, gap) for (int i = ((gap) > (h) - (w) - 1 ? (h) - 1 : (w) - 1 + (gap)), j = i - (gap); i >= 0 && j >= 0; i--, j--)
#define Loopitr(itr, container) for(auto itr = container.begin(); itr != container.end(); itr++)
#define printv(vector) Loop(ex_i, vector.size()) { cout << vector[ex_i] << " "; } cout << endl;
#define printmx(matrix) Loop(ex_i, matrix.size()) { Loop(ex_j, matrix[ex_i].size()) { cout << matrix[ex_i][ex_j] << " "; } cout << endl; }
#define quickio() ios::sync_with_stdio(false); cin.tie(0);
#define bitmanip(m,val) static_cast<bitset<(int)m>>(val)
#define Comp(type_t) bool operator<(const type_t &another) const
#define fst first
#define snd second
bool nearlyeq(double x, double y) { return abs(x - y) < 1e-9; }
bool inrange(int x, int t) { return x >= 0 && x < t; }
bool inrange(vi xs, int t) { Foreach(x, xs) if (!(x >= 0 && x < t)) return false; return true; }
ll rndf(double x) { return (ll)(x + (x >= 0 ? 0.5 : -0.5)); }
ll floorsqrt(ll x) { ll m = (ll)sqrt((double)x); return m + (m * m <= x ? 0 : -1); }
ll ceilsqrt(ll x) { ll m = (ll)sqrt((double)x); return m + (x <= m * m ? 0 : 1); }
ll rnddiv(ll a, ll b) { return (a / b + (a % b * 2 >= b ? 1 : 0)); }
ll ceildiv(ll a, ll b) { return (a / b + (a % b == 0 ? 0 : 1)); }
ll gcd(ll m, ll n) { if (n == 0) return m; else return gcd(n, m % n); }
ll lcm(ll m, ll n) { return m * n / gcd(m, n); }

/*******************************************************/

int main() {
	ll n, x; cin >> n >> x;
	ll ans = n;
	ll a = x, b = n - x;
	if (a > b) swap(a, b);
	while (true) {
		if (b % a == 0) {
			ans += ((b / a) * 2 - 1) * a;
			break;
		}
		else {
			ans += (b / a) * 2 * a;
			b %= a;
			swap(a, b);
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
int main (){
    std::cin.tie(0); 
	std::ios::sync_with_stdio(false);
    int N;std::cin>>N;
    std::vector<int> a(N,0);
    int x=0;
    for (int i=0;i<N;++i){
        std::cin>>a[i];
        x ^= a[i];
    }

    for (auto i : a) {
        std::cout<<(i^x) << " ";
    }
    
    return 0;
}

Measured memory_bytes: 3984
#include <bits/stdc++.h>
using namespace std;
using cpx = complex<double>;
using namespace std::literals;
using Int = long long;
using Double = long double;
#ifdef __GNUG__
#define _GLIBCXX_DEBUG
#endif
#define rep(i, n) for (int i = 0, i##_len = (int)(n); i < i##_len; i++)
#define reps(i, n) for (int i = 1, i##_len = (int)(n); i <= i##_len; i++)
#define ALL(v) (v).begin(), (v).end()
#define SZ(x) ((int)(x).size())
#define LEN(x) ((int)(x).length())
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());
#define MP make_pair
#define MT make_tuple
#define PB push_back
#define F first
#define S second
#define perm(c)   \
    sort(ALL(c)); \
    for (bool c##p = 1; c##p; c##p = next_permutation(ALL(c)))
vector<Int> IntsIn(int n) {
    auto v = vector<Int>(0);
    for (int i = 0; i < n; i++) {
        Int a;
        cin >> a;
        v.push_back(a);
    }
    return v;
}
template <typename T>
void Puts(T x) {
    cout << x << endl;
}
void setPrecision(int num = 20) {
    std::cout << std::fixed << std::setprecision(num);
}
template <typename T>
T Max(T a) {
    return a;
}
template <typename T, typename... Args>
T Max(T a, Args... args) {
    return std::max(Max(args...), a);
}
template <typename T>
T Min(T a) {
    return a;
}
template <typename T, typename... Args>
T Min(T a, Args... args) {
    return std::min(Min(args...), a);
}
template <typename T>
bool vector_contains(std::vector<T> vec, T value) {
    return (std::distance(vec.begin(), std::find(vec.begin(), vec.end(), value)) != vec.size());
}
template <typename T>
long indexOf(std::vector<T> &vec, const T &value) {
    auto result = std::distance(vec.begin(), std::find(vec.begin(), vec.end(), value));
    return ((long)result == (long)vec.size()) ? -1 : result;
}
template <typename T>
void removeAt(std::vector<T> &vec, unsigned int index) {
    vec.erase(vec.begin() + index);
}
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &value) {
    std::fill((T *)array, (T *)(array + N), value);
}
template <typename T>
struct countMap {
    map<T, Int> dict;
    countMap() {
        dict = map<T, Int>();
    }
    Int operator[](T key) {
        if (dict.find(key) != dict.end()) {
            return dict[key];
        } else {
            return 0;
        }
    }
    // key に対応する値があれば1増加させる，なければキーを新設して1をセット
    void incremntFor(T key) {
        if (dict.find(key) != dict.end()) {
            dict[key]++;
        } else {
            dict.emplace(key, 1);
        }
    }
    // for (auto &p: dict) でループできるように
    auto begin() const {
        return dict.begin();
    }
    auto end() const {
        return dict.end();
    }
};
int main() {
    Int n;
    cin >> n;
    if (n % 2 == 1) {
        puts("0");
    } else {
        Int ans = 0;
        while (n > 0) {
            ans += n / 10;
            n /= 5;
        }
        Puts(ans);
    }
}


Measured memory_bytes: 256
#define _USE_MAT_DEFINES
#include<iostream>
#include <iomanip>
#include<stdio.h>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include <queue>
#include <utility>
#include <map>
#include <set>
#include <stack>
#include <deque>
#include <numeric>
#include <functional>
using namespace std;

int main() {

    int N, ans = 0, sum = 0;
    cin >> N;
    vector<int>s(N + 1);
    s[0] = 0;
    for (int i = 1; i <= N; i++) {
        cin >> s[i];
        sum += s[i];
    }

    for (int i = 0; i <= N; i++) {
        int score = sum - s[i];
        if (score % 10 != 0)ans = max(ans, score);
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

public class AtCoderA
{
    static void Main()
    {
        var sc = new Scanner();

        int n = sc.NextInt();
        int[] a = sc.IntArray();

        int answer = int.MaxValue;

        for (int i = -100; i <= 100; i++)
        {
            int tmpAnswer = a.Select(num => (i - num) * (i - num)).Sum();
            answer = Math.Min(answer, tmpAnswer);
        }

        Console.WriteLine(answer);
    }

    class Scanner
    {
        private string[] _line;
        private int _index;
        private const char Separator = ' ';

        public Scanner()
        {
            _line = new string[0];
            _index = 0;
        }

        public string Next()
        {
            while (_index >= _line.Length)
            {
                _line = Console.ReadLine().Split(Separator);
                _index = 0;
            }

            return _line[_index++];
        }

        public int NextInt() => int.Parse(Next());
        public long NextLong() => long.Parse(Next());
        public double NextDouble() => double.Parse(Next());
        public decimal NextDecimal() => decimal.Parse(Next());
        public char NextChar() => Next()[0];
        public char[] NextCharArray() => Next().ToCharArray();

        public string[] Array()
        {
            _line = Console.ReadLine().Split(Separator);
            _index = _line.Length;
            return _line;
        }

        public int[] IntArray() => Array().Select(int.Parse).ToArray();
        public long[] LongArray() => Array().Select(long.Parse).ToArray();
        public double[] DoubleArray() => Array().Select(double.Parse).ToArray();
        public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray();
    }
}

Measured memory_bytes: 13396
#include <bits/stdc++.h>
using namespace std;
int main(){
    long a; cin >> a;
    vector<int> v(a);
    for(int i=0;i<a-1;i++){
        int b; cin >> b;
        v[b-1]++;
    }
    for(auto x:v)cout << x << endl;
}

Measured memory_bytes: 3996
#include<stdio.h>
#include<vector>
using namespace std;
#pragma GCC optimize("O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define rep(i,N) for(int i=0;i<(int)N;i++)
const int L=128,C=62;
vector<int> s[C*4+3],apr[C+3];int diff;
static inline int decode(int x){return x<=26?64+x:(x<=52?96-26+x:48+x-52-1);}
static inline int ask(int u,int i,int j)
{
  int len=diff;
  printf("? ");rep(k,s[u].size()){len--;putchar(decode(s[u][k]));}len--;putchar(decode(s[u<<1][i]));
  rep(k,s[u<<1|1].size()-j){len--;putchar(decode(s[u<<1|1][k+j]));}puts("");fflush(stdout);
  int res;if(scanf("%d",&res)!=0)return res==len;else return -1;
}
static inline void solve(int u,int le,int ri)
{
  if(le==ri){s[u]=apr[le];return;}
  int mid=(le+ri)>>1;
  solve(u<<1,le,mid);solve(u<<1|1,mid+1,ri);
  for(int i=0,j=0;i<(int)s[u<<1].size()||j<(int)s[u<<1|1].size();)
  {
    if(i<(int)s[u<<1].size()&&(j==(int)s[u<<1|1].size()||ask(u,i,j))){s[u].push_back(s[u<<1][i]); i++;}
    else{s[u].push_back(s[u<<1|1][j]);j++;}
  }
}
int main(void)
{
  rep(i,C)
  {
    printf("? ");rep(j,L){putchar(decode(i+1));}puts("");fflush(stdout);
    int res;if(!scanf("%d",&res))return -1;
    rep(j,L-res)apr[i+1].push_back(i+1);
    diff+=apr[i+1].size();
  }
  solve(1,1,C);
  printf("! ");rep(i,s[1].size())putchar(decode(s[1][i]));puts("");fflush(stdout);
  return 0;
}

Measured memory_bytes: 3740
N = int(input())
h = list(map(int, input().split()))

nums = [h[0]]

for i in range(N-1):
    if h[i+1] > h[i]:
        nums.append(nums[i] + (h[i+1] - h[i]))
    else:
        nums.append(nums[i])

print(nums[-1])


Measured memory_bytes: 2940
while 1:
    n,m= list(map(int,input().split(' ')))
    if n == m ==0:break
    D = []
    for _ in range(n):
        d_i,p_i = list(map(int,input().split(' ')))
        D.append((d_i,p_i))
    D = sorted(D,key = lambda x:x[1],reverse = True)
    while m > 0:
        if len(D) ==0:break
        temp = D.pop(0)
        if temp[0] > m:
            temp = (temp[0] - m,temp[1])
            m=0
            D.append(temp)
        else: 
            m -= temp[0]      
    ans = 0
    for i in D:
        ans += i[0]*i[1]
    print(ans)


Measured memory_bytes: 6820
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<long long, long long>;
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007LL;
constexpr long long INF = 1001001001LL;
constexpr long long LINF = 1e18 + 10;
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define rept(i, j, n) for(int i=(j); i<(n); i++)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }


int main(){ 
    int n, W; cin >> n >> W;
    vector<vector<ll>> values(4); //w, w+1, w+2, w+3;
    ll weight;
    rep(i, n){
        ll w, v; cin >> w >> v;
        if(i==0){
            weight = w;
            values[0].push_back(v); 
        }else{
            int index = w - weight;
            values[index].push_back(v);
        }
    }
    rep(i, 4) sort(all(values[i]), greater<ll>());

    vector<vector<ll>> S(4);
    rep(i, 4){
        S[i].push_back(0);
        rep(j, values[i].size()){
            S[i].push_back(S[i][j] + values[i][j]);
        }
    }

    ll res = 0;
    rep(a, S[0].size()){
        rep(b, S[1].size()){
            rep(c, S[2].size()){
                rep(d, S[3].size()){
                    ll sum_v = S[0][a] + S[1][b] + S[2][c] + S[3][d]; 
                    ll sum_w = a*weight + b*(weight+1) + c*(weight+2) + d*(weight+3);
                    if(sum_w <=W)chmax(res, sum_v);
                }
            }
        }
    }
    cout << res << ln;
}


Measured memory_bytes: 3552
#include <map>
#include <vector>
#include <cstdio>
using namespace std;
int main(){
	int n=0,N,i,j,k,c;
	scanf("%d",&N);
	vector<map<int,int> >dist(N);
	vector<bool>used(N);
	vector<int>cost(N);
	for(;n<N;n++){
		cost[n]=999999;
		for(scanf("%d%d",&i,&k);k--;dist[i][j]=c)scanf("%d%d",&j,&c);
	}
	for(cost[0]=0;;){ //dijkstra
		int m=999999;
		for(i=0;i<N;i++)if(!used[i]&&m>cost[i])m=cost[i];
		if(m==999999)break;
		for(j=0;j<N;j++)if(m==cost[j]){
			map<int,int>::iterator it=dist[j].begin();
			for(used[j]=1;it!=dist[j].end();it++)if(cost[it->first]>it->second+cost[j])cost[it->first]=it->second+cost[j];
		}
	}
	for(i=0;i<n;i++)printf("%d %d\n",i,cost[i]);
}

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

int main(){
  string s ;
  cin >> s ;
  int ss = s.size();
  int ans =0;
  int count =0;
  
  for(int i=0;i<ss;i++){
    if(s[i]=='A'||s[i]=='G'||s[i]=='C'||s[i]=='T'){
      count++;
      ans = max(count,ans);
    }
    else count =0;
  }
  
  cout << ans << endl;
}



Measured memory_bytes: 3628
#include <iostream>
#include <cstdio>

using namespace std;

int n, x, y;
int a[4005];
int d[4005][4005];

int abs(int p) {return (p > 0) ? p : -p;}

int f(int p, int q)
{
    if(p >= n + 1 || q >= n + 1) return abs(a[p] - a[q]);
    if(d[p][q] != 0) return d[p][q];
    if(p > q)
    {
//        int mn = 2e9;
//        for(int i = p + 1; i < n + 2; i++)
//        {
//            mn = min(mn, f(p, i));
//        }
        return d[p][q] = max(f(p + 1, q), f(p, p + 1));
    }
    else
    {
//        int mx = 0;
//        for(int i = q + 1; i < n + 2; i++)
//        {
//            mx = max(mx, f(i, q));
//        }
        return d[p][q] = min(f(p, q + 1), f(q + 1, q));
    }
}

int main()
{
    scanf("%d%d%d", &n, &a[1], &a[0]);
    for(int i = 2; i < n + 2; i++)
    {
        scanf("%d", &a[i]);
    }
    if(n == 1) printf("%d", abs(a[2] - a[0]));
    else printf("%d", f(1, 0));
    return 0;
}


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

int main() {

	long long int a, v, b, w, t;

	cin >> a >> v >> b >> w >> t;

	long long int a2, b2, d;

	if (a == b) {
		cout << "YES";
		return 0;
	}
	else if (b > a) {
		if(b+w*t-a-v*t>0)cout << "NO";
		else cout << "YES";
		return 0;
	}
	else {
		if (a - v * t > b - w * t)cout << "NO";
		else cout << "YES";
		return 0;
	}
	

	return 0;
}

Measured memory_bytes: 3104
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <set>
#include <map>
#include <queue>
using namespace std;
#define rep(i,n) for(int i = 0;i<n;i++)
const long long MOD = 1000000007LL;
const string alpha = "abcdefghijklmnopqrstuvwxyz";
int main(){
    int n;
    cin >> n;
    long long a[n];
    rep(i,n){
        cin >> a[i];
    }
    sort(a,a+n);
    cout << a[n-1] - a[0] << endl;
}

Measured memory_bytes: 256
require 'pp'
$DEBUG ? define_method(:dpp){|e|pp e} : define_method(:dpp){|e|}

# 入力値を文字の配列で返却する
def gets_nsp_list()
  gets.chomp.split("")
end

slist = gets_nsp_list

puts [slist.count("0"), slist.count("1")].min * 2

Measured memory_bytes: 19712
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#define FOR(n) for(int i=0;i<n;i++)
#define FORJ(n) for(int j=0;j<n;j++)
#define PRN(n) printf("%d\n",n)
#define PRF(n) printf("%lf\n",n)
#define PRL(n) printf("%lld\n",n)
#define PRS(s) printf("%s\n",s)
#define PRC(c) printf("%c",c)
#define mod 1000000007
typedef long long int ll;
ll dp[100001];
int u(const void *a, const void *b){
    return *(ll*)a-*(ll*)b;
}
int d(const void *a, const void *b){
    return *(ll*)b-*(ll*)a;
}
int min(int a,int b){
  if(a>b)return b;
  return a;
}
int max(int a,int b){
  if(a>b)return a;
  return b;
}
int gcd(int a,int b){
  if(!b)return a;
  return gcd(b,a%b);
}
int main(void) {
  int c,n;
  scanf("%d %d",&c,&n);
  PRN(c*n);
  return 0;
}


Measured memory_bytes: 2136
for e in iter(input,'0 0'):
 N,M=map(int,e.split())
 S=[int(input())for _ in[0]*N]
 p=b=1
 for i in range(M):
  d=int(input())
  p+=d
  if N<=p:
   if b:print(-~i);b=0
   continue
  p+=S[~-p]
  if(N<=p)*b:print(-~i);b=0


Measured memory_bytes: 5636
n, z, w = map(int, input().split())
a = input().split()
a = [int(m) for m in a]
if n == 1:
    print(abs(a[n - 1] - w))
else:
    print(max(abs(a[n - 1] - w), abs(a[n - 1] - a[n - 2])))

Measured memory_bytes: 3188
import java.util.*;

public class Main {
	public static void main(String[] args) {
	 Scanner sc = new Scanner(System.in);
     int a = sc.nextInt();
     int b = sc.nextInt();
     int h = sc.nextInt();
      
      int ans = (a + b) * h / 2;
      System.out.print(ans);
      
	}
}


Measured memory_bytes: 35464
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<math.h>
#include<queue>
#include<deque>
#include<stack>
#include<cstdio>
#include<utility>
#include<set>
#include<list>
#include<cmath>
#include<stdio.h>
#include<string.h>
#include<iomanip>
#include<cstdio>
#include<cstdlib>
#include<cstring>
using namespace std;
#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)
#define REP(i, n) FOR(i, 0, n - 1)
#define NREP(i, n) FOR(i, 1, n)
using ll = long long;
using pii = pair<int, int>;
using piii = pair<pii, pii>;
const ll dx[4] = { 0, -1, 1, 0 };
const ll dy[4] = { -1, 0, 0, 1 };
const int INF = 1e9 + 7;
int gcd(int x, int y) {
	if (x < y)swap(x, y);
	if (y == 0)return x;
	return gcd(y, x%y);
}
void mul(ll a, ll b) {
	a = a * b % INF;
}
///////////////////////////////////////

int main() {
	int N, M;
	int A[100100], B[100100];
	cin >> N >> M;
	vector<vector<int>>key(100100, vector<int>());
	for (int i = 0; i < N; ++i) {
		cin >> A[i] >> B[i];
		key[A[i]].push_back(B[i]);
	}
	ll ans = 0;
	priority_queue<pii>que;
	for (int i = 1; i <= M; ++i) {
		for (int a : key[i]) {
			que.push({ a,i });
		}
		if (que.empty())continue;
		ans += que.top().first;
		que.pop();
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 6400
N, M = map(int, input().split())
A = list(map(int, input().split()))
BC = []
for _ in range(M):
    BC.append(tuple(map(int,input().split())))

BC.sort(key=lambda x: x[1], reverse=True)

cnt = 0
for i in range(M):
    if N - cnt < BC[i][0]:
        for _ in range(N-cnt):
            A.append(BC[i][1])
        break
    else:
        cnt += BC[i][0]
        for _ in range(BC[i][0]):
            A.append(BC[i][1])

A.sort(reverse=True)

print(sum(A[:N]))


Measured memory_bytes: 23784
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def SI(): return sys.stdin.readline()[:-1]

def main():
    mn=10**10
    n=II()
    aa=LI()
    ans=0
    for a in aa:
        if a<mn:ans+=1
        mn=min(a,mn)
    print(ans)
main()

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

using namespace std;
typedef long long ll;

int main(){
    ll n;
    cin>>n;
    int hap = 0;
    while(n >= 500){
        hap+=1000;
        n -= 500;
    }
    while(n >= 5){
        hap+=5;
        n-=5;
    }
    cout<<hap<<"\n";
}

Measured memory_bytes: 256
import java.util.Scanner;

//Champernowne Constant
public class Main{

	long DIGIT_LIMIT = 1000000000000000000L;
	long MAX_NUMBER = 59477124183006535L;
	long[] endK;
	long[] ten;
	
	void init(){
		endK = new long[20];
		endK[0] = 0;
		long num = 9;
		for(int k=1;k<=17;k++,num*=10){
			endK[k] = endK[k-1]+k*num;
		}
		endK[18] = DIGIT_LIMIT;
		endK[0] = -1;
		ten = new long[20];
		ten[0] = 0;
		ten[1] = 10;
		for(int k=2;k<=17;k++)ten[k]=ten[k-1]*10;
	}
	
	int at(long x){
		long L=0, R=0;
		int k;
		for(k=17;k>=0;k--)if(endK[k] < x){
			L = ten[k];
			R = k==17?MAX_NUMBER:ten[k+1];
			break;
		}
		for(;;){
			long m = (R+L)/2;
			long p = endK[k]+1+(k+1)*(m-ten[k]);
			if(p<=x&&x<p+k+1){
				String s = m+"";
				for(int i=0;i<s.length();i++)if(p+i==x)return s.charAt(i)-'0';
			}
			else if(x < p)R=m;
			else L=m;
		}
	}
	
	void run(){
		init();
		Scanner sc = new Scanner(System.in);
		for(;;){
			int N = sc.nextInt(), K = sc.nextInt();
			if((N|K)==0)break;
			for(int i=0;i<K;i++)System.out.print(at(N+i));
			System.out.println();
		}
	}
	
	public static void main(String[] args) {
		new Main().run();
	}
}

Measured memory_bytes: 12000
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,ans=0;
	char s[100],t[3];
	cin>>n>>s;
	for(int i=0;i<n;i++)
	{
		strncpy(t,s+i,3);
		if(strcmp(t,"ABC")==0)
		ans++;
	}
	cout<<ans<<endl;
 } 

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

using namespace std;
int n;
int t[100001],x[100001],y[100001];

int main() {
  cin >> n;

  for(int i = 0; i < n; i++) cin >> t[i] >> x[i] >> y[i];

  int nx = 0;
  int ny = 0;
  int tmp = 0;
  for(int i = 0; i < n; i++) {
    tmp += abs(x[i] - nx) + abs(y[i] - ny);
    if(tmp % 2 == 1) {
      if(t[i] % 2 == 1 && t[i] >= tmp) {
	tmp = t[i];
	nx = x[i];
	ny = y[i];
      }
      else {
	cout << "No" << endl;
	return 0;
      }
    }
    else {
      if(t[i] % 2 == 0 && t[i] >= tmp) {
	tmp = t[i];
	nx = x[i];
	ny = y[i];
      }
      else {
	cout << "No" << endl;
	return 0;
      }
    }
  }
  cout << "Yes" << endl;
}



Measured memory_bytes: 1408
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <cmath>
#include <climits>
#include <math.h>
#include <bitset>

#define X first
#define Y second
#define vsort(v) sort(v.begin(), v.end())
#define vrev(v) reverse(v.begin(), v.end())
#define P pair

// stoi(s): string to int
// stod(s): string to double

// INT_MAX
// INT_MIN
// LLONG_MAX
// LLONG_MIN
// DBL_MIN
// DBL_MAX
// LDBL_MIN
// LDBL_MAX

// A-Z: 65~90
// a-z: 97~122
// |a-z| = 26

// 2進数変換
// string s = bitset<20>(x).to_string();

using namespace std;
using ll = long long;

int main(int argc, const char *argv[])
{
    int a, b, ans = 0;
    cin >> a >> b;
    for (int i = 0; i < 2; i++)
    {
        if (a > b)
        {
            ans += a;
            a--;
        }
        else
        {
            ans += b;
            b--;
        }
    }
    cout << ans << endl;
}


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

using namespace std;

int main() {
    int N, K;
    cin >> N >> K;

    int loop = 50;
    long long a[loop+1];
    a[0] = 1;
    a[1] = 2;
    for (int i = 2; i <= loop; i++) {
        a[i] = a[i-1] * 2;
    }

    double ans;
    double temp = 1.0 / (double)N;
    // if (N > K-1) {
    //     ans = ((double)N-(double)(K-1)) / (double)N;
    //     double aa = 1.0 - ans;
    //     int t = 1;
    //     for (int i = N-K-1; i >= 1; i--) {
    //         for (int j = t; j <= loop; j++) {
    //             // cout << "i * a[j]: " << i << " * " << a[j] << endl;
    //             if (i * a[j] >= K) {
    //                 // cout << "temp / a[j]: " << temp << " / " << a[j] << endl;
    //                 // cout << "     " << temp / a[j] << endl;
    //                 ans += aa * temp / a[j];
    //                 t = j;
    //                 break;
    //             }
    //         }
    //     }
    // } else {
        ans = 0.0;
        int t = 0;
        for (int i = N; i >= 1; i--) {
            for (int j = t; j <= loop; j++) {
                // cout << "i * a[j]: " << i << " * " << a[j] << endl;
                if (i * a[j] >= K) {
                    // cout << "temp / a[j]: " << temp << " / " << a[j] << endl;
                    // cout << "     " << temp / a[j] << endl;
                    ans += temp / a[j];
                    t = j;
                    break;
                }
            }
        }
    // }

    cout << setprecision(20) << ans << endl;
    
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <limits>
#include <vector>
#include <cstdio>
#include <bits/stdc++.h>
#include <set>
#include <map>
#include <stdio.h>
using namespace std;
using ll =int long long;
map <int ,int> mpa,mpb;

int main (void){
  int  N;
  cin >>  N;
  int x[N];
  int p[N];
  int sum=0;
  for(int i=0;i<N;i++){
    cin >> x[i];
    p[i]=x[i];
    sum=sum+x[i];
  }
  sort(p,p+N);
  int ave=sum/N;
  int c=N/2;
  for(int i=0;i<N;i++){
    if(p[c-1]<x[i]){
      cout << p[c-1] << endl;
    }
    else{
      cout << p[c] << endl;
    }
  }
}

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

#define int long long
#define rep(i,a,n) for(int i = a; i < n; i++)
#define pb push_back
#define eb emplace_back
#define dump(x) cout << #x << " = " << (x) << endl
#define chk() cout << "now" << endl;
#define ALL(x) (x).begin(),(x).end()
#define SORT(c) sort((c).begin(), (c).end())
#define SORTG(c) sort((c).begin(), (c).end(), greater<int>());
#define fi first
#define se second
#define INF (1e9)

typedef pair<int,int> P;
typedef vector<int> vi;


vector<int> divisors(int n) {
    vector<int> res;
    for(int i = 1; i*i <= n; ++i) {
        if(n % i != 0) continue;
        res.push_back(i);
        if(n/i == i) continue;
    }
    return res;
}


int L,R;

signed main() {

    cin>>L>>R;

    int a=L%2019;
    int b=R%2019;

    int ans=0;
    if(L+2019<=R) {
        ans=0;
    }else if(L+2019>R and a<b) {
        int m=a*b;
        rep(i,a,b) {
            rep(j,i+1,b+1) {
                int n=i*j%2019;
                if(n<m) m=n;
            }
        }
        ans=m;
    }else if(L+2019>R and a>=b) {

        ans=0;

    }

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








Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <functional>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#include <fstream>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> P;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<P> vp;
#define rep(i,a,n) for(ll i = (a);i < (n);i++)
#define per(i,a,n) for(ll i = (a);i > (n);i--)
#define lep(i,a,n) for(ll i = (a);i <= (n);i++)
#define pel(i,a,n) for(ll i = (a);i >= (n);i--)
#define clr(a,b) memset((a),(b),sizeof(a))
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define sz size()
#define endl "\n"
#define print(X) cout << (X) << "\n"
// // #define input(X) getline(cin,X)
static const ll  INF = 1e9+7;
static const ll INFL = 1e18+7;
ll n,m,l, p;
string s,t;
ll d[200010],e[200010],dp[101][100001];
char field[202][202];

ll w[101], v[101];

int main(){
    cin >> n >> m;
    rep(i,0,n)cin >> w[i] >> v[i];

    clr(dp, 0);

    rep(i,0,n){
        lep(j,0,m){
            if(j < w[i])dp[i+1][j] = dp[i][j];
            else dp[i+1][j] = max(dp[i][j], dp[i][j-w[i]]+v[i]);
        }
    }
    
    print(dp[n][m]);
    return 0;
}


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


typedef long long i64;

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

	i64 e9 = 1000000000;
	i64 ax = e9, by = s / e9, ay = 0, bx = 0;
	s %= e9;
	if (s > 0) {
		by++, s = e9 - s;
		ay = 1, bx = s;
	}

	cout << "0 0 " << ax << ' ' << ay << ' ' << bx << ' ' << by << '\n';

	return 0;
}

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

int prime(int x){
    int ans = 0;
    for(int i=1; i*i<=x; i++){
        if(x%i == 0) ans += 2;
        if(i*i == x) ans -= 1;
    }
    return ans;
}

int main() {
    int n; cin >> n;
    int data = 0;
    loop(i,1,n+1){
        if(i%2 == 1 && prime(i) == 8) data++;
    }
    cout << data << endl;
}

Measured memory_bytes: 256
package main

import (
	"fmt"
	"strings"
)

func allOfWhich(ss []string, a, b, c string) bool {
	match := 0
	for _, s := range ss {
		if s == a {
			match++
		} else if s == b {
			match++
		} else if s == c {
			match++
		} else {
			break
		}
	}
	if match == len(ss) {
		return true
	}
	return false
}

func isEven(n int) bool {
	if n%2 == 0 {
		return true
	}
	return false
}

func isRhymable(strings []string) bool {
	var evens []string
	var odds []string

	for i, s := range strings {
		if isEven(i + 1) {
			evens = append(evens, s)
		} else {
			odds = append(odds, s)
		}
	}

	if allOfWhich(evens, "L", "U", "D") {
		if allOfWhich(odds, "R", "U", "D") {
			return true
		}
	}
	return false
}

func main() {
	var tmp string
	fmt.Scan(&tmp)
	s := strings.Split(tmp, "")

	if isRhymable(s) {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}


Measured memory_bytes: 640
/*
 Copyright (c) 2019 ... All rights reserved.
 ...
*/
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>

#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
typedef long long ll;

using namespace std;


int inputValue(){
    int a;
    cin >> a;
    return a;
};

void inputArray(int * p, int a){
    rep(i, a){
        cin >> p[i];
    }
};

void inputVector(vector<int> * p, int a){
    rep(i, a){
        int input;
        cin >> input;
        p -> push_back(input);
    }
}

template <typename T>
void output(T a, int precision) {
    if(precision > 0){
        cout << setprecision(precision)  << a << "\n";
    }
    else{
        cout << a << "\n";
    }
}

int main(int argc, const char * argv[]) {

    // source code
    int r, D, x_start;
    int x[10];
    cin >> r >> D >> x_start;

    for(int i = 0; i < 10; i++){
        if(i == 0){
            x[i] = r * x_start - D;
        }else{
            x[i] = r * x[i - 1] - D;
        }
        cout << x[i] << endl;
    }

    return 0;

}

Measured memory_bytes: 888
#include<iostream>

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

  int taro_points = 0, hanako_points = 0;
  for(int i = 0; i < n; i++){
    std::string taro;
    std::string hanako;
    std::cin >> taro;
    std::cin >> hanako;
    
    if(taro > hanako){
      taro_points += 3;
    }else if(taro < hanako){
      hanako_points += 3;
    }else{
      taro_points += 1;
      hanako_points += 1;
    }
  }

  std::cout << taro_points << " " << hanako_points << std::endl;

  return 0;
}



Measured memory_bytes: 3104
n = int(input())

ans = []
def dfs(x):
    if len(x) == n:
        ans.append(x)
        return
    for i in range(max(x)+1):
        y = x.copy()
        y.append(i+1)
        dfs(y)
dfs([1])
#print(ans)

for ai in ans:
    print(''.join(map(lambda x: chr(ord('a') + x - 1), ai)))

#r = ['a','b','c','d','e','f','g','h','i','j']
#for ai in ans:
#    print(''.join(map(lambda x: str(r[x-1]), ai)))




Measured memory_bytes: 28968
def sRaw():
    return input().rstrip("\r")


def iRaw():
    return int(input())


def ssRaw():
    return input().split()


def isRaw():
    return list(map(int, ssRaw()))

INF = 1 << 29

DIV = (10**9) + 7

def mod_inv_prime(a, mod=DIV):
    return pow(a, mod-2, mod)

def mod_inv(a, b):
    r = a
    w = b
    u = 1
    v = 0
    while w != 0:
        t = r//w
        r -= t*w
        r, w = w, r
        u -= t*v
        u, v = v, u
    return (u % b+b) % b


def CONV_TBL(max,mod=DIV):
    fac,finv,inv = [0]*max, [0]*max, [0]*max
    fac[0]=fac[1]=1
    finv[0]=finv[1]=1
    inv[1]=1
    for i in range(2,max):
        fac[i] = fac[i-1]*i % mod
        inv[i] = mod -inv[mod%i] * (mod//i)%mod
        finv[i] = finv[i-1]*inv[i]%mod
    class CONV:
        def __init__(self):
            pass
        def ncr(self,n,k):
            if(n<k):
                return 0
            if(n<0 or k<0 ):
                return 0
            return fac[n]*(finv[k]*finv[n-k]%mod)%mod
    return CONV()



def main():
    N,M =isRaw()
    return "Yes" if N==M else "No"


if __name__ == "__main__":
    print(main())


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

using namespace std;

typedef long long ll;

int main() 
{
    int n, q;
    ll x, y, z;
    scanf("%d %d", &n, &q);
    
    vector<priority_queue<ll> > p(n);
    
    for(int i = 0; i < q; i++)
    {
        scanf("%lld %lld", &x, &y);
        
        if(x == 0)
        {
            scanf("%lld", &z);
            p[y].push(z);
        }
        else if(x == 1)
        {
            if(p[y].size() > 0)
            {
                printf("%lld\n", p[y].top());
            }
        }
        else if(x == 2)
        {
            if(p[y].size() > 0)
            {
                p[y].pop();
            }
        }
    }
    
    return 0;
}


Measured memory_bytes: 5284
#include <iostream>

struct edge{
  int from,to;
  long long cost;
};
constexpr long long inf=99999999999999999;

int n,m;
edge es[2005];
long long d[1005];
int main(){
  std::cin>>n>>m;
  for(int i=0;i<m;++i){
    int a,b;
    long long c;
    std::cin>>a>>b>>c;
    es[i].from=a-1;
    es[i].to=b-1;
    es[i].cost=c*-1;
  }
  
  for(int i=0;i<n;++i)
    d[i]=inf;
  d[0]=0;
  for(int loop=0;loop<n-1;++loop){
    for(int i=0;i<m;++i){
      auto e=es[i];
      if(e.from!=inf&&d[e.to]>d[e.from]+e.cost){
        d[e.to]=d[e.from]+e.cost;
      }
    }
  }
  
  auto ans=-d[n-1];
  
  bool ne[1005];
  for(int i=0;i<n;++i)
    ne[i]=false;
  
  for(int loop=0;loop<n;++loop)
    for(int i=0;i<m;++i){
      auto e=es[i];
      if(e.from==inf)
        continue;
      
      if(d[e.to]>d[e.from]+e.cost){
        d[e.to]=d[e.from]+e.cost;
        ne[e.to]=true;
      }
      
      if(ne[e.from])
        ne[e.to]=true;
    }
  
  if(ne[n-1])
    std::cout<<"inf"<<std::endl;
  else
    std::cout<<ans<<std::endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <functional>
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000
#define int long long

int sum[31][31];
int D[31][31];
int c[510][510];
int cnt[3][31];
signed main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, C;
    cin >> N >> C;
    rep(i, C) {
        rep(j, C) {
            cin >> D[i][j];
        }
    }
    rep(i, N) {
        rep(j, N) {
            cin >> c[i][j];
            c[i][j]--;
        }
    }
    rep(i, N) {
        rep(j, N) {
            cnt[(i + j) % 3][c[i][j]]++;
        }
    }
    int ans = INF;
    rep(i, C) {
        rep(j, C) {
            if(i == j) continue;
            rep(k, C){
                if(i == k || j == k) continue;
                int tmp = 0;
                for(int a = 0; a < C; a++) {
                    tmp += cnt[0][a] * D[a][i];
                    tmp += cnt[1][a] * D[a][j];
                    tmp += cnt[2][a] * D[a][k];
                }
                //cout << i << " " << j << " " << k << " " << tmp << endl;
                ans = min(ans, tmp);
            }
        }
    }
    cout << ans << endl;




    return 0;
}


Measured memory_bytes: 5580
n = int(input())
a = [int(num) for num in input().split()]
b = [a[i] + i for i in range(n)]
c = [a[i] - i for i in range(n)]
dic = {}
dic[b[0]] = 1
ans = 0
for i in range(1,n):
    if -c[i] in dic.keys():
        ans += dic[-c[i]]
    if b[i] in dic.keys():
        dic[b[i]] += 1
    else:
        dic[b[i]] = 1
        
print(ans)

Measured memory_bytes: 138436
#!/usr/bin/env ruby

require 'set'

class Hash
  def push(key, value)
    self[key] = [] if self[key] == nil
    self[key].push(value)
  end
end

class Array
  def lower_bound(value)
    left = -1;
    right = self.length;
    while left + 1 < right
      mid = left + (right - left) / 2;
      if self[mid] >= value
        right = mid
      else
        left = mid
      end
    end
    right
  end

  def unique
    res = [self.first]
    each_cons(2) do |a, b|
      if a != b
        res.push(b)
      end
    end
    res
  end
end

def get_ints
  gets.chomp.split.map(&:to_i)
end

def get_ints_minus_one
  get_ints.map { |x| x - 1 }
end

def get_int
  gets.chomp.to_i
end

N, K = get_ints
S = gets.chomp

k = K-1
puts S[0...k] + S[k].downcase + S[(k+1)..]


Measured memory_bytes: 14348
import java.util.*;
import java.io.*;

public class Main{
  public static void main(String[] args){
    Scanner scanner = new Scanner(System.in);
    int n = scanner.nextInt();
    int m = scanner.nextInt();
    int l = scanner.nextInt();
    int[][] A = new int[n][m];
    int[][] B = new int[m][l];
    long[][] C = new long[n][l];

      for(int i=0;i<n;i++){
        for(int j=0;j<m;j++){
          A[i][j] = scanner.nextInt();
        }
      }

      for(int i=0;i<m;i++){
        for(int j=0;j<l;j++){
          B[i][j] = scanner.nextInt();
        }
      }

      for(int i=0;i<n;i++){
        for(int j=0;j<l;j++){
          C[i][j] = 0;
          for(int k=0;k<m;k++){
            C[i][j] = C[i][j] + (long)A[i][k]*B[k][j];
          }
        }
      }

      for(int i=0;i<n;i++){
        for(int j=0;j<l;j++){
          if(j==l-1){
            System.out.println(C[i][j]);
          }else{
            System.out.print(C[i][j] + " ");
          }
        }
      }

    }
}


Measured memory_bytes: 53744
#include<stdio.h>
#include<algorithm>
#include<functional>
#include<cmath>
using namespace std;
long long  mod = 1000000007;
int main()
{
	int N, D;
	scanf("%d%d", &N, &D);
	int an;
	if (N % (2 * D + 1) != 0) {
		an = N / (2 * D + 1) + 1;
	}
	else {
		an = N / (2 * D + 1);
	}
	printf("%d", an);
	return 0;
}

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

#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cerr << name << " : " << arg1 << std::endl;
}
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...);
}
#else
#define trace(...)
#endif

#define LL long long

const LL MX = 1e18;

int main() {
	LL n, inp[100005];
	cin >> n;
	for(int i=0;i<n;i++) {
		cin >> inp[i];
	}

	for(int i=0;i<n;i++) {
		if(inp[i] == 0) {
			cout << 0 << endl;
			return 0;
		}
	}

	LL ans = 1;
	for(int i=0;i<n;i++) {
		if(inp[i] > MX / ans) {
			cout << -1 << endl;
			return 0;
		}
		ans = ans * inp[i];
	}
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 4404
import string
from collections import defaultdict
S = input()
n = len(S)

# １こ飛ばし文字列
s1 = S[::2]
s2 = S[1::2]

n1 = len(s1)
n2 = len(s2)

ans = 0
for i in range(1,n):
    if S[i] == S[i-1]:
       print("{} {}".format(i, i+1))
       exit()

ans = 0
for i in range(1,n1):
    if s1[i] == s1[i-1]:
       print("{} {}".format(2*i-1, 2*i+1))
       exit()

ans = 0
for i in range(1,n2):
    if s2[i] == s2[i-1]:
       print("{} {}".format(2*(i), 2*(i+1)))
       exit()

print("-1 -1")

Measured memory_bytes: 3832