akhauriyash/Code-Regression huggingface dataset:
#pragma GCC optimize(2)
#pragma GCC optimize(3)
#pragma GCC optimize("Ofast")
#pragma GCC optimize("inline")
#pragma GCC optimize("-fgcse")
#pragma GCC optimize("-fgcse-lm")
#pragma GCC optimize("-fipa-sra")
#pragma GCC optimize("-ftree-pre")
#pragma GCC optimize("-ftree-vrp")
#pragma GCC optimize("-fpeephole2")
#pragma GCC optimize("-ffast-math")
#pragma GCC optimize("-fsched-spec")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("-falign-jumps")
#pragma GCC optimize("-falign-loops")
#pragma GCC optimize("-falign-labels")
#pragma GCC optimize("-fdevirtualize")
#pragma GCC optimize("-fcaller-saves")
#pragma GCC optimize("-fcrossjumping")
#pragma GCC optimize("-fthread-jumps")
#pragma GCC optimize("-funroll-loops")
#pragma GCC optimize("-fwhole-program")
#pragma GCC optimize("-freorder-blocks")
#pragma GCC optimize("-fschedule-insns")
#pragma GCC optimize("inline-functions")
#pragma GCC optimize("-ftree-tail-merge")
#pragma GCC optimize("-fschedule-insns2")
#pragma GCC optimize("-fstrict-aliasing")
#pragma GCC optimize("-fstrict-overflow")
#pragma GCC optimize("-falign-functions")
#pragma GCC optimize("-fcse-skip-blocks")
#pragma GCC optimize("-fcse-follow-jumps")
#pragma GCC optimize("-fsched-interblock")
#pragma GCC optimize("-fpartial-inlining")
#pragma GCC optimize("no-stack-protector")
#pragma GCC optimize("-freorder-functions")
#pragma GCC optimize("-findirect-inlining")
#pragma GCC optimize("-fhoist-adjacent-loads")
#pragma GCC optimize("-frerun-cse-after-loop")
#pragma GCC optimize("inline-small-functions")
#pragma GCC optimize("-finline-small-functions")
#pragma GCC optimize("-ftree-switch-conversion")
#pragma GCC optimize("-foptimize-sibling-calls")
#pragma GCC optimize("-fexpensive-optimizations")
#pragma GCC optimize("-funsafe-loop-optimizations")
#pragma GCC optimize("inline-functions-called-once")
#pragma GCC optimize("-fdelete-null-pointer-checks")

#include <map>
#include <list>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#define endl '\n'
#define fast ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
using namespace std;
char s,c;
int ans;
int main()
{
    cin>>s;
    while (scanf("%c", &c) == 1)
    {
        if (c!='B'&&c!='W')
           break;
        if (c!=s)
        {
            ans++;
            s=c;
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 384
def main():
    n = int(input())
    d = list(map(int, input().split()))

    sort_d = sorted(d)

    median_index = int(n/2)

    median_d = sort_d[median_index]
    median_d_minus1 = sort_d[median_index-1]

    answer = median_d - median_d_minus1
    print(answer)


if __name__ == '__main__':
    main()

Measured memory_bytes: 85232
/// Containers Start
#include <algorithm>
#include <bitset>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
/// C Header Files
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <math.h>
#include <stdio.h>
/// Containers End

using namespace std;

/// Math Start
#define PI acos(-1.0)
#define Pi 3.141592653589793
#define EPS (1e-7)
#define INF (0x3f3f3f3f)
/// Math End

/// Extra Start
#define nn '\n'
#define pb push_back
#define ull unsigned long long
#define ll long long
#define MOD 1000000007
#define sz(a) int((a).size())
#define space " "
#define All(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
/// Extra End

#define rep(i, n) for (int i = 0; i < n; i++)
#define Cini(a)                                                                \
    int a;                                                                     \
    cin >> a;
#define Cinii(a, b)                                                            \
    int a, b;                                                                  \
    cin >> a >> b;
#define Ciniii(a, b, c)                                                        \
    int a, b, c;                                                               \
    cin >> a >> b >> c;
#define Cins(s)                                                                \
    string s;                                                                  \
    cin >> s;
#define Cinss(s1, s2)                                                          \
    string s1, s2;                                                             \
    cin >> s1 >> s2;
#define Cinc(c)                                                                \
    char c;                                                                    \
    cin >> c;
/// Functions End

/// Graph Start
struct edge {
    int from, to;
    long long cost;
};
/// Graph End

/// Debug Start
#define deb(x) cout << #x << ": " << x << endl
#define deb2(x, y) cout << #x << ": " << x << '\t' << #y << ": " << y << endl;
#define deb3(x, y, z)                                                          \
    cout << #x << ": " << x << '\t' << #y << ": " << y << '\t' << #z << ": "   \
         << z << endl;
/// Debug End

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

/**>>>>>>>>>>>>>>>>>>> END <<<<<<<<<<<<<<<<<<**/

/// template


signed main(void) {
    cin.sync_with_stdio(false);
    cin.tie(0);
    unordered_map<int,int> m;
    rep(i,4) m[i+1] = 0;
    rep(i,3){
        int a,b;
        cin >> a >> b;
        m[a]++;
        m[b]++;
    }
    int count1 = 0,count2 = 0;
    for(auto i:m){
        if(i.second==1) count1++;
        if(i.second==2) count2++;
    }
    if(count1==2 && count2==2) cout <<"YES" << nn;
    else cout  << "NO" << nn;

    return 0;
}

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

rate=[0]*9
over=0

for i in a:
  for j in range(1,9):
    if 400*(j-1) <= i < 400*j:
      rate[j]=1
      break
    elif i >= 3200:
      over+=1
      break

ansmin = rate.count(1)
ansmax = rate.count(1)
if ansmin == 0:
  ansmin=1

if over > 0:
  ansmax += over
    
#print(rate,over)
print(ansmin, ansmax)

Measured memory_bytes: 9140
#include <iostream>


int A[2][100];

int main(int argc, char** argv) {
    int n;
    std::cin >> n;
    for (int i = 0; i < 2; i++) {
        for (int j = 0; j < n; j++) {
            std::cin >> A[i][j];
        }
    }

    int sum = 0;
    int turn_i = n - 1;
    for (int i = 0; i < n; i++) sum += A[0][i];
    sum += A[1][n - 1];

    int loss_sum = 0;
    for (int i = n - 2; i > -1; i--) {
        loss_sum += A[1][i] - A[0][i + 1];
        if (loss_sum > 0) {
            sum += loss_sum;
            loss_sum = 0;
        }
    }
    std::cout << sum << std::endl;
}

Measured memory_bytes: 256
#include <bitset>
#include <cstdint>
#include <iostream>
#include <vector>

using namespace std;

constexpr int64_t divider = 1000000007;
  
int main() {
  int64_t N, M;
  cin >> N >> M;
  bitset<1000001> steps;
  for (int m = 0; m < M; ++m) {
    int s;
    cin >> s;
    steps.set(s);
    if (steps.test(s - 1)) {
      cout << 0 << endl;
      return 0;
    }
  }
  vector<int64_t> pat(N+1);
  pat[0] = 1;
  for (size_t i = 0; i <= N; ++i) {
    if (!steps.test(i+1)) {
      pat[i+1] = (pat[i+1] + pat[i]) % divider;
    }
    if (!steps.test(i+2)) {
      pat[i+2] = (pat[i+2] + pat[i]) % divider;
    }
  }
  
  cout << pat[N] << endl;
  
  return 0;
}


Measured memory_bytes: 3964
# 入力
import sys
stdin = sys.stdin

def li(): return [int(x) for x in stdin.readline().split()]
def li_(): return [int(x)-1 for x in stdin.readline().split()]
def lf(): return [float(x) for x in stdin.readline().split()]
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(ns())
def nf(): return float(ns())

n = ni()
s = lc()

res = 0
ans = 0
for c in s:
    if c == "I":
        res += 1
        
        if res > ans:
            ans = res
            
    elif c == "D":
        res -= 1
        
print(ans)

Measured memory_bytes: 3064
from collections import deque
import sys, copy, itertools,heapq
input = sys.stdin.readline

n = int(input())
count = 0

for i in range(1,n+1):
  a = n // i
  if n % i == 0:
    a -= 1
    
  count += a
  #print(a)

print(count)

Measured memory_bytes: 68152
#include<bits/stdc++.h>
using namespace std;
#define ALL(v) (v).begin(),(v).end()
#define REP(i,p,n) for(int i=p;i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define SZ(x) ((int)(x).size())
#define debug(x) cerr << #x << ": " << x << '\n'
#define INF 999999999
typedef long long int Int;
typedef pair<int,int> P;
using ll = long long;
using VI = vector<int>;

int main(){
  string a,b,c;cin >> a >> b >> c;
  sort(a.begin(),a.end());
  sort(b.begin(),b.end());
  sort(c.begin(),c.end());

  int flag = 0;
  bool ef = false;
  while(!(a.empty()&&b.empty()&&c.empty())){
    if(flag==0){
        if(a.empty()) break;
        flag = a.back()-'a';
        a.pop_back();

    }
    if(flag==1){
        if(b.empty()) break;
        flag = b.back()-'a';
        b.pop_back();
    }
    if(flag==2){
        if(c.empty()) break;
        flag = c.back()-'a';
        c.pop_back();
    }
  }
  cout <<  char(flag+'A') << endl;
}


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

using namespace std;

map <long long, int> A;

int main(){
	int N;
	scanf("%d", &N);
	bool val = false;
	long long aux;
	for (int i = 0; i < N; i++) {
		scanf("%d", &aux);
		if (A[aux] >= 1) {
			val = true;
		}
		A[aux]++;
	}
	if (val) {
		printf("NO\n");
	} else {
		printf("YES\n");
	}
}

Measured memory_bytes: 12800
n, l = map(int, input().split())

aji = (l + l+n-1)*(n/2)

if l >= 0 :
    ans = aji - l
elif l < 0 and l+n <= 0 :
    ans = aji - (l+n-1)
else :
    ans = aji

print(int(ans))


Measured memory_bytes: 2940
import scala.io.StdIn._
object Main extends App {
  val sr = new StdinReader
  val n, m, q = sr.nextInt

  val arr = Array.ofDim[Int](n + 1, n + 1)
  (1 to m).foreach{i =>
    val l, r = sr.nextInt
    arr(l)(r) += 1
  }

  for {
    l <- (1 to n)
    r <- (1 to n)
  } {
    arr(l)(r) += arr(l - 1)(r) + arr(l)(r - 1) - arr(l - 1)(r - 1)
  }

  val ans = Array.ofDim[Int](n + 1, n + 1)
  for {
    l <- (1 to n)
    r <- (1 to n)
  } {
    ans(l)(r) = arr(r)(r) - arr(l - 1)(r) - arr(r)(l - 1) + arr(l - 1)(l - 1)
  }

  val w = new java.io.PrintWriter(System.out)
  (1 to q).foreach{i =>
    val l, r = sr.nextInt
    w.println(ans(l)(r))
  }
  w.flush()
}




class StdinReader {
  val is = System.in
  val buffer = new Array[Byte](1024 * 1024)
  var size = 0
  var pos = 0

  private def readByte: Byte = {
    if (pos >= size) {
      pos = 0;
      size = is.read(buffer);
    }
    if (size < 0) -1
    else {
      val ret = buffer(pos)
      pos += 1
      ret
    }
  }

  // support single byte char only
  def next: String = {
    @scala.annotation.tailrec
    def r(sb: StringBuilder, reading: Boolean): String = {
      readByte match {
        case b if ('!' <= b && b <= '~') => r(sb.append(b.asInstanceOf[Char]), true)
        case _ => if (reading) sb.toString else r(sb, false)
      }
    }
    r(new StringBuilder, false)
  }

  def nextInt: Int = {
    @scala.annotation.tailrec
    def r(i: Int, reading: Boolean): Int = {
      readByte match {
        case '-' => r(i * -1, true)
        case b if '0' <= b && b <= '9' => r(i * 10 + (b - '0'), true)
        case _ => if (reading) i else r(i, false)
      }
    }
    r(0, false)
  }
}

Measured memory_bytes: 40400
// AOJ 2026: Divisor is the Conqueror
// 2017.11.03 bal4u@uu

#include <stdio.h>
#include <string.h>
#include <time.h>

#define HASHSIZ 100019
long long hash[HASHSIZ+2], *hashend = hash + HASHSIZ;

int insert(long long n)
{
	long long *p = hash + n % HASHSIZ;
	while (*p) {
		if (*p == n) return 1;
		if (++p == hashend) p = hash;
	}
	*p = n;
	return 0;
}

int c[15];
int ans[54];
char f[14][365];		// 364=(13+1)*13/2*4

int rec(int j, int k)
{
	int i;
	long long s;

	if (!j) return 1;
	for (s = 0, i = 1; i <= 13; i++) s = (s<<2)+s + c[i];
	if (insert(s)) return 0;

	for (i = 1; i <= 13; i++) {
		if (!c[i]) continue;
		if (f[i][k-i]) {
			c[i]--, ans[j] = i;
			if (rec(j-1, k-i)) return 1;
			c[i]++;
		}
	}
	return 0;
}

int main()
{
	int n, i, v, s;
//	clock_t start, end;

//	start = clock();
	memset(f[1], 1, sizeof(f[1]));
	for (i = 2; i <= 13; i++) {
		f[i][0] = 1;
		for (v = i; v < 365; v += i) f[i][v] = 1;
	}

	while (scanf("%d", &n) && n > 0) {
		if (n == 1) { scanf("%d", &v); printf("%d\n", v); continue; }

		memset(c, 0, sizeof(c));
		for (s = 0, i = 0; i < n; i++) {
			scanf("%d", &v);
			s += v, c[v]++;
		}
		memset(hash, 0, sizeof(hash));
		if (rec(n, s)) {
			printf("%d", ans[1]);
			for (i = 2; i <= n; i++) printf(" %d", ans[i]);
			putchar('\n');
		} else puts("No");
	}
//	end = clock();
//	printf("time %lf\n", (double)(end-start)/CLOCKS_PER_SEC);
	return 0;
}

Measured memory_bytes: 2512
#include <stdio.h>
#include <limits.h>
 
#define INFTY INT_MAX
#define N 500000
 
int count = 0;
 
void merge(int A[], int left, int mid, int right){
    int i, j, k;
    int L[N], R[N];
    int L_elements = mid - left;
    int R_elements = right - mid;
 
    for(i=0; i<L_elements; i++)
        L[i] = A[left + i];
    L[i] = INFTY;
 
    for(i=0; i<R_elements; i++)
        R[i] = A[mid + i];
    R[i] = INFTY;
 
 
    i = j = k = 0;
    for(k=left; k<right; k++){
        if( L[i] <= R[j] )
            A[k] = L[i++];
        else
            A[k] = R[j++];
    }
    count += i + j;
}   
 
void mergeSort(int A[], int left, int right){
    int mid;
    if( left+1 < right ){
        mid = ( left + 1 + right) / 2;
        mergeSort(A, left, mid);
        mergeSort(A, mid, right);
        merge(A, left, mid, right);
    }
}
 
int main(void){
    int A[N], n, i;
 
    scanf("%d", &n);
    for(i=0; i<n; i++)
        scanf("%d", &A[i]);
 
    mergeSort(A, 0, n);
 
    for(i=0; i<n-1; i++)
        printf("%d ", A[i]);
    printf("%d\n%d\n", A[i], count);
 
    return 0;
}



Measured memory_bytes: 5612
#include "bits/stdc++.h"
#pragma GCC optimize "03"
using namespace std;

#define int long long int
#define pb push_back
#define pii pair<int,int>
#define fi first
#define se second
#define rep(i,a,b) for (int i = a; i < b; ++i)
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#ifndef LOCAL
#define endl '\n'
#endif
#define dbg(...)    cerr << "> "; ZZ(#__VA_ARGS__,__VA_ARGS__);
template <typename Arg1> void ZZ(const char* val1, Arg1&& arg1) { cerr << val1 << ": " << arg1 << endl; }
template <typename Arg1, typename... Args> void ZZ(const char* vals, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(vals + 1, ',');
    std::cerr.write(vals, comma - vals) << ": " << arg1<<" , ";
    ZZ(comma+1, args...);
}

const int inf = INT_MAX;
const int MOD = 1e9 + 7;
const int N = 2e5 + 5;



signed main(){
    IOS;
    #ifdef LOCAL
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
    
    string s;
    cin >> s;
    int k;
    cin >> k;
    for (int i = 0; i < s.length(); i++) {
    	if (s[i] == 'a') continue;
    	if ('z' + 1 - s[i] <= k) {
    		k -= ('z' + 1 - s[i]);
    		s[i] = 'a';
    	}
    }
    int len = s.length();
    k %= 26;
    while (k--) {
    	s[len-1]++;
    	if (s[len-1] > 'z')
    		s[len-1] = 'a';
    }
    cout << s << endl;
    return 0;
}

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

int main() {
    string S; int K; cin >> S >> K;
    int ichinum = 0;
    for (int i = 0; i < S.size(); ++i) {
        if (S[i] == '1') ++ichinum;
        else break;
    }
    if (ichinum >= K) cout << 1 << endl;
    else cout << S[ichinum] << endl;
}


Measured memory_bytes: 256
object Main {
  def main(args: Array[String]): Unit = {
    import scala.io.StdIn.readLine
    val _ = readLine
    val datA = readLine.split(" ").map(_.toInt)

    val dirinit    = 0
    val dirunknown = 1
    val dirinc = 2
    val dirdec = 3
    def searchCutPoint(result: Int, dir: Int, border: Int, ls: List[Int]): Int = (dir, border, ls) match {
      case (_, _, Nil) => result + 1
      case (dir, _, ls) if (dir == dirinit) => searchCutPoint(result, dirunknown, ls.head, ls.tail)
      case (dir, border, ls) if (dir == dirunknown) => {
        if     (border == ls.head) searchCutPoint(result, dirunknown, ls.head, ls.tail)
        else if(border >  ls.head) searchCutPoint(result, dirdec, ls.head, ls.tail)
        else                       searchCutPoint(result, dirinc, ls.head, ls.tail)
      }
      case (dir, border, ls) if (dir == dirinc) => {
        if (border <= ls.head) searchCutPoint(result,     dirinc,     ls.head, ls.tail)
        else                   searchCutPoint(result + 1, dirunknown, ls.head, ls.tail)
      }
      case (dir, border, ls) if (dir == dirdec) => {
        if (border >= ls.head) searchCutPoint(result,     dirdec,     ls.head, ls.tail)
        else                   searchCutPoint(result + 1, dirunknown, ls.head, ls.tail)
      }
    }
    val ans = searchCutPoint(0, dirinit, 0, datA.toList)
    println(ans)
  }
}


Measured memory_bytes: 42336
#include <bits/stdc++.h>
using namespace std;
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define per(i,b) gnr(i,0,b)
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
#define IDX(vec, element_iter) distance((vec).begin(), element_iter)
#define pb push_back
#define mp make_pair
#define INF9 1000000000 //10^9
#define MOD 1000000007 //10^9+7
#define fi first
#define sc second
using ll=long long;
using pii=pair<ll,ll>;
using vi=vector<int>;
using vll=vector<ll>;

map<int,int> int_counter(vi vec) {
    map<int,int> counter;
    for(auto v:vec) {
        counter[v]++;
    }
    return counter;
}

int main() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout<<fixed<<setprecision(20);

    int n;cin >> n;
    vi a(n);
    rep(i,n) cin >> a[i];
    sort(ALL(a));
    map<int,int> counter = int_counter(a);
    int lower = a[0],upper=a[n-1]+1;
    int ans = 0;
    rng(x,lower,upper){ 
        ans = max(counter[x-1]+counter[x]+counter[x+1],ans);
    }
  
    cout << ans << endl;;
    return 0;
}

Measured memory_bytes: 5368
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>

using namespace std;
using ll = long long;

int main() {
  string s;
  cin >> s;
  s = '0' + s;
  string t(s);
  reverse(t.begin(), t.end());
  if (s != t || s[1] == '0') {
    cout << -1 << endl;
    return 0;
  }
  int k = 2;
  cout << "1 2" << '\n';
  for (int i = 2; i < s.size() - 1; i++) {
    cout << k << ' ' << i + 1 << '\n';
    if (s[i] == '1') {
      k = i + 1;
    }
  }
}


Measured memory_bytes: 1660
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from pprint import pprint
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(10000)


def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(H, W, N, AB):
    c = Counter()

    ij = list(product([-1, 0, 1], repeat=2))
    for a, b in AB:
        for i, j in ij:
            c[(a+i, b+j)] += 1

    ans = Counter()
    for (i, j), v in c.items():
        if 2 <= i < H and 2 <= j < W:
            ans[v] += 1

    ans[0] = (H-2) * (W-2) - sum(ans.values())
    for i in range(10):
        print(ans[i])


def main():
    H, W, N = read_int_n()
    AB = [read_int_n() for _ in range(N)]

    slv(H, W, N, AB)


if __name__ == '__main__':
    main()


Measured memory_bytes: 163404
#include<bits/stdc++.h>
using namespace std;
#define int long long int
int32_t main() {

	int n;
	cin >> n;
	int total = 0;
	int f = n / 500;
	int r = n % 500;
	total = 1000 * f;
	r = r / 5;
	total += r * 5;
	cout << total << "\n";

}


Measured memory_bytes: 256
N=int(input())
a=list(map(int,input().split()))
a_=sorted(a,key=lambda x:-x)
ans=0
from collections import Counter
c=Counter(a_)
for i in a_:
    if c[i]==0:
        continue
    c[i]-=1
    m=1<<i.bit_length()
    j=m-i
    if j in c and c[j]>0:
        ans+=1
        c[j]-=1
print(ans)

Measured memory_bytes: 35560
int N[]={ 6,10,18,14,  2,13,22,11,  3, 5,21,19,  1,17,23, 7,  0, 9,20,15,  4,12,16, 8};
int E[]={15, 7,11,19,  8, 3,14,23, 16, 0, 6,22,  4, 2,18,20, 12, 1,10,21,  9, 5,13,17};
int W[]={ 9,17,13, 5, 12,21,10, 1,  4,20,18, 2, 16,22, 6, 0,  8,23,14, 3, 15,19,11, 7};
int S[]={16,12, 4, 8, 20, 9, 0,15, 23,17, 1, 7, 21, 5, 3,19, 22,13, 2,11, 18,10, 6,14};
n,a,d;
char s[9];
int main()
{
for(;;)
{
scanf("%d",&n);
if(!n)
break;
a=1;
d=0;
for(;n--;)
{
scanf("%s",s);
d=
(*s-78?0:N[d])+
(*s-69?0:E[d])+
(*s-87?0:W[d])+
(*s-83?0:S[d])+
(*s-82?0:d&28|d%4+1&3)+
(*s-76?0:d&28|d%4-1&3);
a+=d/4+1;
}
printf("%d\n",a);
}
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const double pi = acos(-1);
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
REP(i,v.size()){if(i)os<<" ";os<<v[i];}return os;}
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) {
REP(i,v.size()){if(i)os<<endl;os<<v[i];}return os;}
int main() {
 double A,B;
 cin >> A >> B ;
 double C = A*B / (A+B) ;
 cout << fixed << setprecision(6);
 cout << C << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <limits.h>

struct edge_t {
	int from;
	int to;
	int c;
};

typedef struct edge_t Edge;

int main(void) {
	int num,i,k,from,to,c,update;
  int nedge = 0;
	int dis[10000];
	Edge *edges, *p;

	edges = malloc(sizeof(Edge)*500000);

	scanf("%d", &num);

	for (i=0; i<num; i++) {
		scanf("%d %d", &from, &k);

		while (k--) {

			scanf("%d %d", &to, &c);

			p = &edges[nedge++];
			p->from = from;
			p->to = to;
			p->c = c;
		}

		dis[i] = INT_MAX;
	}
	dis[0] = 0;

	update = 1;
	while (update) {
		update = 0;
		for (i = 0; i < nedge; i++) {
			from = edges[i].from;
			to = edges[i].to;
			c = edges[i].c;
			if (dis[from] < INT_MAX && dis[to] > c + dis[from]) {
				dis[to] = c + dis[from];
				update = 1;
			}
		}
	}

	for (i = 0; i < num; i++) {
		printf("%d %d\n", i, dis[i]);
	}

  return 0;
}



Measured memory_bytes: 7612
main(){double a,b,c,d,x=57.2958;for(;scanf("%lf%lf%lf%lf",&a,&b,&c,&d),b>-1;printf("%.0f\n",6378.1*acos(sin(a)*sin(c)+cos(a)*cos(c)*cos((b-d)))))a/=x,b/=x,c/=x,d/=x;exit(0);}

Measured memory_bytes: 724
// {{{ by shik
#include <bits/stdc++.h>
#pragma GCC diagnostic ignored "-Wunused-result"
#pragma GCC diagnostic ignored "-Wunused-function"
#define SZ(x) ((int)(x).size())
#define ALL(x) begin(x), end(x)
#define REP(i, n) for (int i = 0; i < int(n); i++)
#define REP1(i, a, b) for (int i = (a); i <= int(b); i++)
#define MP make_pair
#define PB push_back
using namespace std;
typedef int64_t LL;
typedef pair<int, int> PII;
typedef vector<int> VI;

namespace { namespace shik {

template<class T> void _R(T &x) { cin >> x; }
void _R(int &x) { scanf("%d", &x); }
void _R(int64_t &x) { scanf("%" SCNd64, &x); }
void _R(double &x) { scanf("%lf", &x); }
void _R(char &x) { scanf(" %c", &x); }
void _R(char *x) { scanf("%s", x); }
void R() {}
template<class T, class... U> void R(T &head, U &... tail) { _R(head); R(tail...); }

template<class T> void _W(const T &x) { cout << x; }
void _W(const int &x) { printf("%d", x); }
void _W(const int64_t &x) { printf("%" PRId64, x); }
void _W(const double &x) { printf("%.16f", x); }
void _W(const char &x) { putchar(x); }
void _W(const char *x) { printf("%s", x); }
template<class T> void _W(const vector<T> &x) { for (auto i = x.begin(); i != x.end(); _W(*i++)) if (i != x.cbegin()) putchar(' '); }
void W() {}
template<class T, class... U> void W(const T &head, const U &... tail) { _W(head); putchar(sizeof...(tail) ? ' ' : '\n'); W(tail...); }

#ifdef SHIK
#include "dump.hpp"
#else
#define dump(...)
#endif

template<class T, class F = less<T>> void sort_uniq(vector<T> &v, F f = F()) { sort(begin(v), end(v), f); v.resize(unique(begin(v), end(v)) - begin(v)); }
template<class T> inline T bit(T x, int i) { return (x >> i) & 1; }
template<class T> inline bool chkmax(T &a, const T &b) { return b > a ? a = b, true : false; }
template<class T> inline bool chkmin(T &a, const T &b) { return b < a ? a = b, true : false; }
template<class T> using MaxHeap = priority_queue<T>;
template<class T> using MinHeap = priority_queue<T, vector<T>, greater<T>>;

// }}}

const int N=3010;
int n,na,nb,a[N],b[N];
char s[2*N];
string dp[N];

void main() {
    R(n,s);
    REP(i,2*n) {
        if ( s[i]=='a' ) a[na++]=i;
        else b[nb++]=i;
    }
    assert(na==n && nb==n);
    for ( int i=n-1; i>=0; i-- ) {
        dp[i]=dp[i+1];
        if ( a[i]<b[i] ) {
            int j=i+1;
            while ( j<n && min(a[j],b[j])<b[i] ) j++;
            chkmax(dp[i],"ab"s+dp[j]);
        } else {
            int mx=max(a[i],b[i]);
            int j=i;
            vector<pair<int,char>> v;
            while ( j<n && min(a[j],b[j])<=mx ) {
                v.PB({a[j],'a'});
                v.PB({b[j],'b'});
                chkmax(mx,max(a[j],b[j]));
                j++;
            }
            sort(ALL(v));
            string z;
            for ( auto &k:v ) z.push_back(k.second);
            chkmax(dp[i],z+dp[j]);
        }
        dump(i,dp[i]);
    }
    W(dp[0]);
}

// {{{ main
}}
int main() { shik::main(); return 0; }
// }}}


Measured memory_bytes: 15616
primes = [false, false]
2.upto(10000){|x|
    prime = true
    2.upto(Math.sqrt(x)){|d| 
        if x % d == 0
            prime = false
            break
        end
    }
    primes[x] = prime
}

while line = gets
    n = line.to_i
    sum = 0
    1.upto(n){|i| sum += 1 if primes[i] && primes[n - i + 1]}
    puts sum
end



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

int main() {
	// your code goes here
	int a,b;
	cin>>a>>b;
	if(a==b){
		cout<<"a == b"<<endl;
	}else{
		if(a>b){
			cout<<"a > b"<<endl;
		}else{
			cout<<"a < b"<<endl;
		}
	}
	return 0;
}

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, n) for(int i=0; i<int(n); i++)
#define RNG(i, f, t) for(int i=int(f); i<=int(t); i++)
#define REV(i, f, t) for(int i=int(f); i>=int(t); --i)
#define ALL(v) (v).begin(), (v).end()
bool RELAXED = false;
template<int,typename T> struct MINMAX{ T val; MINMAX(T val) : val(val) {} };
template<typename T> MINMAX<1,T> MAX(T val) { return MINMAX<1,T>(val); };
template<typename T> MINMAX<2,T> MIN(T val) { return MINMAX<2,T>(val); };
template<typename T, typename U> inline T& operator|=(T &lhs, MINMAX<1,U> rhs) { return lhs = (rhs.val > lhs ? (RELAXED=true,rhs.val) : (RELAXED=false,lhs)); }
template<typename T, typename U> inline T& operator|=(T &lhs, MINMAX<2,U> rhs) { return lhs = (rhs.val < lhs ? (RELAXED=true,rhs.val) : (RELAXED=false,lhs)); }
template<typename T> inline vector<T> readVector(int n) { vector<T> vec(n); FOR(i,n) cin>>vec[i]; return vec; }
template<typename T> void PRINT(T container, bool withSize) { if(withSize) cout<<container.size()<<endl; for(auto it : container) cout<<it<<" "; cout<<endl; }
template<typename T> void EXIT(T answer) { cout<<answer<<endl; exit(0); }
template<typename T> using min_heap = priority_queue<T, vector<T>, greater<T> >;
typedef signed long long int ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<pii> vpii;
typedef vector<pll> vpll;


bool cmp(pii a, pii b) {
    return a.first + a.second < b.first + b.second;
}

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

    int n; cin>>n;
    vpii a(n);
    FOR(i,n)
        cin>>a[i].first>>a[i].second;

    sort(ALL(a), cmp);

    ll ans=0;
    vl dp(100005, 1e18);
    dp[0] = -1e18;

    FOR(i,n) {
        int l=0, r=i;
        while(l<=r) {
            int mid = l+r>>1;
            if(dp[mid] <= a[i].first-a[i].second)
            {
                l = mid+1;
            } else {
                r = mid-1;
            }
        }
        int best=l-1;
        dp[best+1] |= MIN( a[i].first+a[i].second );
        ans |= MAX(best+1);
    }

    cout<<ans<<endl;

    return 0;
}



Measured memory_bytes: 1792
from collections import deque

S=input()
Q=int(input())

R=0
S=deque(S)

for i in range(Q):
    temp=list(input().split())
    if int(temp[0])==1:
        R+=1
    elif int(temp[0])==2:
        F=int(temp[1])
        c=temp[2]
        if F==1:
            if R%2==0:
                S.appendleft(c)
            else:
                S.append(c)
        elif F==2:
            if R%2==0:
                S.append(c)
            else:
                S.appendleft(c)

if R%2==1:
    S=list(S)
    ans=S[-1::-1]
    ans=map(str,ans)
else:
    ans=map(str,S)

print("".join(ans))





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

unsigned gaps[] = {1,8,23,77,281,1073,4193,16577,65921,262913};
// generated from pow(4,i)+3*pow(2,i-1)+1 (prefixed with 1)

unsigned insertion_sort(unsigned a[], unsigned n, unsigned gap = 1){
  unsigned count = 0;
  for(unsigned i = gap; i < n; i++){
    unsigned v = a[i];
    int j = i - gap;
    while(j >= 0 && a[j] > v){
      a[j+gap] = a[j];
      j -= gap;
      count++;
    }
    a[j+gap] = v;
  }
  return count;
}

void shell_sort(unsigned a[], unsigned n){
  unsigned gap_num = 0;
  while(gaps[++gap_num] < n);
  gap_num--;

  unsigned count = 0;
  for(int i=gap_num;i>=0;i--) count += insertion_sort(a,n,gaps[i]);

  std::cout << (gap_num+1) << '\n';

  for(int i=gap_num;i;i--) std::cout << gaps[i] << ' ';
  std::cout << gaps[0] << '\n';

  std::cout << count << '\n';
}

int main(){
  std::ios::sync_with_stdio(false);
  unsigned n;
  std::cin >> n;
  std::vector<unsigned> a(n);
  for(unsigned i = 0; i < n; i++) std::cin >> a[i];
  shell_sort(a.data(),n);
  for(auto &v : a) std::cout << v << '\n';
}

Measured memory_bytes: 4888
/**
 * C - Snack
 * https://atcoder.jp/contests/abc148/tasks/abc148_c
 **/
#include <iostream>

using namespace std;

long gcd(long a, long b) {
    int r = a%b;
    while(r != 0) {
        a = b;
        b = r;
        r = a%b;
    }
    return b;
}

int main () {

    long A, B;
    cin >> A >> B;
    if(A > B) {
        cout << A * B / gcd(A, B) << endl;
    } else {
        cout << A * B / gcd(B, A) << endl;
    }

    return 0;
}

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

int main(){
	int N, i;
	scanf("%d", &N);
	vector<int> P(N), Q(N);
	for(i = 0; i < N; i++){
		scanf("%d", &P[i]);
	}
	for(i = 0; i < N; i++){
		scanf("%d", &Q[i]);
	}
	int ans = 0;
	do{
		ans++;
	}while(next_permutation(P.begin(), P.end()));
	do{
		ans--;
	}while(next_permutation(Q.begin(), Q.end()));
	printf("%d\n", abs(ans));
	return 0;
}

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

#define rep(i,s,n) for (int i = (int)s; i < (int)n; i++)
#define ll long long
#define pb push_back
#define All(x) x.begin(), x.end()
#define Range(x, i, j) x.begin() + i, x.begin() + j
#define lbidx(x, y) lower_bound(x.begin(), x.end(), y) - x.begin()
#define ubidx(x, y) upper_bound(x.begin(), x.end(), y) - x.begin()
#define BiSearchRangeNum(x, y, z) lower_bound(x.begin(), x.end(), z) - lower_bound(x.begin(), x.end(), y)turn idx;
static const int INF = 1e9+7;

// 対象のvectorの [s, e)の範囲でのLIS
int solve(vector<int> &x, int s, int e) {
  int INFTY = 1e9+7;
  vector<int> ret(e - s, INFTY);
  ret[0] = -x[s];
  int size = 1;
  for (int i = s + 1; i < e; i++) {
    int tmp = -x[i];
    if (ret[size - 1] <= tmp) {
      ret[size++] = tmp;
    } else {
      *upper_bound(ret.begin(), ret.end(), tmp) = tmp;
    }
  }
  return size;
};

int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  rep(i, 0, N) {
    cin >> A[i];
  }

  int ans = solve(A, 0, A.size());
  cout << ans << endl;
};


Measured memory_bytes: 1024
#define ll				long long
#define MOD				1000000007

#include <float.h>
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>

FILE *in, *ans;
int tno;

int out(const char *s) {
#ifdef TEST
	char buf[8192];
	fgets(buf, sizeof(buf), ans);
	if (strcmp(buf, s)) {
		printf("err\n");
	}
#else
	printf(s);
#endif
	return 0;
}

int outi(int i) {
	char s[128];
	sprintf(s, "%d\n", i);
	out(s);
	return 0;
}

int outd(double d) {
	char s[128];
	sprintf(s, "%.10lf\n", d);
	out(s);
	return 0;
}

int outll(ll l) {
	char s[128];
	sprintf(s, "%lld\n", l);
	out(s);
	return 0;
}

int geti() {
	int i;
	fscanf(in, "%d", &i);
	return i;
}

ll getll() {
	ll l;
	fscanf(in, "%lld", &l);
	return l;
}

int getstr(char *s) {
	fscanf(in, "%s", s);
	return 0;
}

int getmin(int val1, int val2) {
	if (val1 < val2) {
		return val1;
	}
	else {
		return val2;
	}
}

int getmax(int val1, int val2) {
	if (val1 > val2) {
		return val1;
	}
	else {
		return val2;
	}
}

typedef struct data {
	char c;
	int cnt;
} data;

int datas[100];
int dcnt;

int fnc2() {
	int i;
	int dcnt = geti();
	int l = 0;
	for (i = 0; i < dcnt; i++) {
		datas[i] = geti();
		l += datas[i];
	}
	int min = l;
	int r = 0;
	for (i = 0; i < dcnt; i++) {
		l -= datas[i];
		r += datas[i];
		int d = abs(l - r);
		min = getmin(min, d);
	}

	return min;
}

int fnc1() {
	int ret = fnc2();
	outi(ret);
	return 0;
}

int main() {

#ifdef TEST
	for (tno = TEST_SNO; tno <= TEST_ENO; tno++) {
		char str[128];
		sprintf(str, "test%d.txt", tno);
		in = fopen(str, "r");
		sprintf(str, "ans%d.txt", tno);
		ans = fopen(str, "r");
		fnc1();
		fclose(in);
		fclose(ans);
	}
	printf("end\n");
#else
	in = stdin;
	fnc1();
#endif

	return 0;
}


Measured memory_bytes: 128
/*
　　　　 ∧＿∧　にっぽんちゃちゃちゃ
　／＼（　・∀・）／ヽ
（ ●　と　　　つ　● ）　にっぽんちゃちゃちゃ
　＼/⊂、 ノ　　＼ノ
　　　　　し'
*/
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define repone(i,n) for(int i=1;i<(int)(n);++i)
#define repo(i,o,n) for(int i=o;i<(int)(n);++i)
#define Rep(j,n) for(int j=0;j<(int)(n);++j)
#define Repo(j,o,n) for(int j=o;j<(int)(n);++j)
#define Repone(j,n) for(int j=1;j<(int)(n);++j)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define int long long
#define MOD 1000000007
#define INF 9223372036854775807

signed main(){
int x=0,y=0,z=0,w=0;
int a=0,b=0;
std::vector<int> v1(2),v2(2);
std::cin >> v1[0]>>v1[1];
std::cin >> v2[0]>>v2[1];
std::cin >> x>>y>>z>>w;
if(v1[0]!=0)a+=v1[0]*x+v1[0]/10*z;
if(v1[1]!=0)a+=v1[1]*y+v1[1]/20*w;
if(v2[0]!=0)b+=v2[0]*x+v2[0]/10*z;
if(v2[1]!=0)b+=v2[1]*y+v2[1]/20*w;
if(a==b)std::cout << "even"<<'\n';
else if(a>b)std::cout << "hiroshi" << '\n';
else std::cout << "kenjiro" << '\n';
}




Measured memory_bytes: 3088
from math import*
M=10**9+7
n=int(input())
s=input()
if s[0]==s[-1]=='W':
  print(0)
  exit()
l=a=1
r=f=0
for b,c in zip(s,s[1:]):
  if b==c:
    f^=1
  if f:
    a*=l-r
    a%=M
    r+=1
  else:
    l+=1
print(a*factorial(n)%M*(l==r))

Measured memory_bytes: 4452
#include<iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int main(){
    int N;
    cin >> N;
    int a[N];
    int M = -1000, m = 1000;
    for(int i=0;i<N;i++){
      cin >> a[i];
      m = min(m, a[i]);
      M = max(M, a[i]);
    }

    int ans = 10000000;
    for(int l=m;l<=M;l++){
      int sum = 0;
      for(int i=0;i<N;i++) sum += (a[i]-l)*(a[i]-l);

      ans = min(ans, sum);
    }
    cout << ans <<endl;
  
    return 0;
}


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

class Program
{
    const string Yes = "Yes";
    const string No = "No";
    const long Mod = 1000000007;
    static void Main(string[] args) {
#if DEBUG
        MyDebugger.Test(process, "../TextFile1.txt");
        //MyDebugger.Test(process, "../TextFile2.txt");
        //MyDebugger.MakeTestCase("../TextFile2.txt");
#else
        object ret = process(new StreamReader(Console.OpenStandardInput()));
        Console.WriteLine(ret);
#endif
    }

    static object process(TextReader input) {
        var n = int.Parse(input.ReadLine());

        var x = n/2;

        if (n % 2 != 0) x++;

        return (double)x / (double)n;
    }
}

Measured memory_bytes: 11092
//Achen
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<vector>
#include<cstdio>
#include<queue>
#include<cmath>
#include<set>
#include<map>
#define For(i,a,b) for(int i=(a);i<=(b);i++)
#define Rep(i,a,b) for(int i=(a);i>=(b);i--)
const int N=1e5+7;
typedef long long LL; 
typedef double db;
using namespace std;
int n,a[N],fl1,fl2,sum;

template<typename T> void read(T &x) {
    char ch=getchar(); x=0; T f=1;
    while(ch!='-'&&(ch<'0'||ch>'9')) ch=getchar();
    if(ch=='-') f=-1,ch=getchar();
    for(;ch>='0'&&ch<='9';ch=getchar()) x=x*10+ch-'0'; x*=f;
}

bool cmp(const int &A,const int &B) {
	return A>B;
}

//#define DEBUG
int main() {
#ifdef DEBUG
	freopen("1.in","r",stdin);
	//freopen(".out","w",stdout);
#endif
	read(n);
	For(i,1,n) read(a[i]);
	sort(a+1,a+n+1,cmp);
	For(i,1,n) {
		if(a[i+1]<i+1) {
			i--;
			int j=i; while(a[j+1]>i) j++;
			if(((a[i+1]-i)&1)&&((j-i)&1)) puts("Second");
			else puts("First"); 
			break;
		}
	}
    return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const  ll INF = 1e18;
const  ll MOD = 1e9 + 7;
#define all(v) v.begin(), v.end()
#define repi(i,n,init) for(ll i=init;i<(n);i++)
#define repd(i,n,init) for(ll i=(n);i>=init;i--)
#define repm(i,m) for(auto i=m.begin();i!=m.end();i++)

int main()
{
    string C;
    cin >> C;
    cout << (char)((int)(C.at(0))+1) << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <stdbool.h>

struct stack {
        size_t size;
        int in;
        int data[1];
};

static bool
isfull(struct stack *st)
{
        if (st->in >= st->size - 1)
                return true;

        return false;
}

static bool
isempty(struct stack *st)
{
        if (st->in == 0)
                return true;

        return false;
}

static int
push(struct stack *st, int x)
{
        if (isfull(st))
                return -1;

        st->data[st->in++] = x;

        return 0;
}

static int
pop(struct stack *st, int *x)
{
        if (isempty(st))
                return -1;

        st->in--;
        *x = st->data[st->in];

        return 0;
}

int
main(void)
{
        struct stack *st = malloc(sizeof(struct stack) + sizeof(int) * 200);
        st->in = 0;
        st->size = 200;

        char s[100];
        while (scanf("%s", s) != EOF) {
                int tmp;
                if (!ispunct(s[0])) {
                        tmp = strtol(s, NULL, 10);
                } else {
                        int x;
                        int y;
                        pop(st, &y);
                        pop(st, &x);
                        switch (s[0]) {
                        case '+':
                                tmp = x + y;
                                break;
                        case '-':
                                tmp = x - y;
                                break;
                        case '*':
                        default:
                                tmp = x * y;
                                break;
                        }
                }
                push(st, tmp);
        }

        int ans;
        pop(st, &ans);
        printf("%d\n", ans);

        return 0;
}




Measured memory_bytes: 2100
package main

import (
	"bufio"
	_ "container/heap"
	"fmt"
	"os"
	_ "sort"
	"strconv"
)

// I/O
type Scanner struct {
	sc *bufio.Scanner
}

func NewScanner() *Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024), int(1e+9))
	return &Scanner{sc}
}

func (s *Scanner) nextStr() string {
	s.sc.Scan()
	return s.sc.Text()
}

func (s *Scanner) nextInt() int {
	i, e := strconv.Atoi(s.nextStr())
	if e != nil {
		panic(e)
	}
	return i
}

func (s *Scanner) nextFloat() float64 {
	f, e := strconv.ParseFloat(s.nextStr(), 64)
	if e != nil {
		panic(e)
	}
	return f
}

func (s *Scanner) nextRuneSlice() []rune {
	return []rune(s.nextStr())
}

func (s *Scanner) nextIntSlice(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextInt()
	}
	return res
}

func (s *Scanner) nextFloatSlice(n int) []float64 {
	res := make([]float64, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextFloat()
	}
	return res
}

// Arithmetic
func max(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m < i {
			m = i
		}
	}
	return m
}

func min(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m > i {
			m = i
		}
	}
	return m
}

func abs(x int) int {
	if x > 0 {
		return x
	}
	return -x
}

func pow(x, y int) int {
	res := 1
	for i := 0; i < y; i++ {
		res *= x
	}
	return res
}

func ceil(a, b int) int {
	if a%b == 0 {
		return a / b
	} else {
		return a/b + 1
	}
}

func gcd(a, b int) int {
	if b == 0 {
		return a
	}
	return gcd(b, a%b)
}

func lcm(a, b int) int {
	return a / gcd(a, b) * b
}

// Sort
type RuneSlice []rune

func (a RuneSlice) Len() int           { return len(a) }
func (a RuneSlice) Less(i, j int) bool { return a[i] < a[j] }
func (a RuneSlice) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }

// Main
const MOD = int(1e+9) + 7
const INF = 1 << 60

func main() {
	sc := NewScanner()
	wtr := bufio.NewWriter(os.Stdout)
	defer wtr.Flush()
	S := sc.nextStr()
	l := len(S)
	ans := ""
	for i := 0; i < l; i++ {
		ans += "x"
	}

	fmt.Fprintln(wtr, ans)
}


Measured memory_bytes: 640
/*
  Motto - try hard to become an expert
*/
#include <bits/stdc++.h>
#include <map>
#include <algorithm>
#include <vector>
#include <string.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <chrono>
#include <thread>
#include <iomanip>
 
//define
#define rep(i,n)    for(int i=0;i<n;i++)
#define repu(i,k,n) for(int i=k;i<=n;i++)
#define repd(i,k,n) for(int i=k;i>=n;i--)
#define se second
#define fi first
#define pb push_back
#define mp make_pair
#define INF (int)INT_MAX
#define all(v)  v.begin(), v.end()
#define endl "\n"
 
//typedef
typedef long long int ll;
typedef long double ld;
typedef std::pair<int, int> pii;
typedef std::vector<int> vi;
typedef std::vector< pii > vii;
typedef std::vector< ll > vll;
typedef std::vector< std::pair < pii, int > > vpp;
 
const int N = 3*1e5 +5 ;
const long long MOD = 1e9 + 7;
const long long inf = 1e18;
 
using namespace std;
 

ll modpow(ll x,ll n){
    ll res=1;
    while(n>0){
        if(n&1) res=res*x%MOD;
        x=x*x%MOD;
        n>>=1;
    }
    return res;
}
 
ll modFact(ll n, ll p) 
{ 
    if (n >= p) 
        return 0; 
  
    ll result = 1; 
    for (ll i = 1; i <= n; i++) 
        result = (result * i) % p; 
  
    return result;  
} 
 
bool isPrime(int x)
{
    if(x%2==0)
        return 0;
    for(int i=3;i<=sqrt(x);i+=2)
    {
        if(x%i==0)
            return 0;
    }
    return 1;
}
 
ll binomialCoeff(ll n, ll k) 
{ 
	ll C[n + 1][k + 1]; 
	ll i, j; 


	for (i = 0; i <= n; i++) 
	{ 
		for (j = 0; j <= min(i, k); j++) 
		{ 
			
			if (j == 0 || j == i) 
				C[i][j] = 1; 

			else
				C[i][j] = (C[i - 1][j - 1] + 
										C[i - 1][j])%MOD; 
		} 
	} 

	return C[n][k]; 
}
bool compare(const string &a , const string&b){
	
}
 
void solve()
{
    ll n , w ; 
    cin>>n>>w ;
    ll weight[n]  , value[n];
    rep(i ,n)cin>>weight[i]>>value[i] ;
    ll dp[w+1][n+1] ;
    repu(i , 0 , w){
    	dp[i][0] = 0 ;
    }
    repu(i  , 0 , n){
    	dp[0][i] = 0 ;
    }
    repu(i  , 1 , w){
    	repu(j , 1 , n){
    		dp[i][j] = dp[i][j-1] ;
    		if(i - weight[j-1]>=0){
    			dp[i][j] = max(dp[i][j] , dp[i-weight[j-1]][j-1]+value[j-1]) ;
    		}
    	}
    }
    cout<<dp[w][n]<<endl;
}
 
int main() {
    #ifndef ONLINE_JUDGE
        // for getting input from input.txt
        freopen("input.txt", "r", stdin);
        // for writing output to output.txt
        freopen("output.txt", "w", stdout);
    #endif
    
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    int t = 1;
    //cin>>t;
    while(t--)
    {
        solve();
    } 
    cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
}

Measured memory_bytes: 82544
#include<iostream>
#include<algorithm>
using namespace std;
long long lj;
long long a,b,n;
int main()
{
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>a>>b;
		lj+=b-a+1;
	}
	cout<<lj;
	return 0;
}

Measured memory_bytes: 256
#template
from collections import Counter
def inputlist(): return [int(j) for j in input().split()]
#template
a,b = inputlist()
if a*b <= 0:
    print("Zero")
    exit()
if a > 0 and b > 0:
    print("Positive")
    exit()
if a < 0 and b < 0:
    d = abs(a) - abs(b) + 1
    if d % 2 == 0:
        print("Positive")
    if d % 2 == 1:
        print("Negative")

Measured memory_bytes: 3316
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using System.Diagnostics;

class Myon
{
    public Myon() { }
    public static int Main()
    {
        new Myon().calc();
        return 0;
    }

    Scanner cin;


    void calc()
    {
        cin = new Scanner();
        int N = cin.nextInt();
        long A = cin.nextInt();
        long B = cin.nextInt();
        int[] p = cin.ArrayInt(N);


        long MAX = long.MaxValue / 4;

        long[] dp = new long[N + 1];
        for (int i = 0; i < N + 1; i++)
        {
            dp[i] = MAX;
        }
        dp[0] = 0;

        for (int i = 0; i < N; i++)
        {
            long[] nextDP = new long[N + 1];
            for (int j = 0; j < N + 1; j++)
            {
                nextDP[j] = MAX;
            }

            for (int j = 0; j < N + 1; j++)
            {
                if (j < p[i])
                {
                    nextDP[p[i]] = Math.Min(nextDP[p[i]], dp[j]);
                    nextDP[j] = Math.Min(nextDP[j], dp[j] + A);


                }
                else
                {
                    nextDP[j] = Math.Min(nextDP[j], dp[j] + B);
                }
            }

            dp = nextDP;
        }


        Console.WriteLine(dp.Min());
    }

    


}



class Scanner
{
    string[] s;
    int i;

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

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

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

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

    public long nextLong()
    {
        return long.Parse(next());
    }

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

    public double nextDouble()
    {
        return double.Parse(next());
    }


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


Measured memory_bytes: 30408