akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <math.h>

using namespace std;

int main(){
	int n;
	double students[1000] = {0},sum,m,div;

	while(true){
		scanf("%d",&n);
		if(n == 0) break;
		div = sum = 0;
		for(int i = 0; i < n; i++){
			scanf("%lf",&students[i]);
			sum += students[i];
		}
		m = sum/n;
		for(int i = 0; i < n;i++){
			div += (students[i] - m)*(students[i] - m);
			students[i] = 0;
		}
		printf("%.8lf\n",sqrt(div/n));
	}
}


Measured memory_bytes: 2716
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>

int main() {
    int a = 0, b = 0, c = 0;
    int k = 0;
    int ans = 0;
    scanf("%d %d %d\n%d", &a, &b, &c, &k);
    if (a >= b) {
        if (a >= c) ans = a * pow(2,k) + b + c;
        else ans = a + b + c*pow(2,k);
    }
    else {
        if (b >= c) ans = a + b * pow(2,k) + c;
        else ans = a + b + c*pow(2,k);
    }
    printf("%d\n", ans);
    return 0;
}


Measured memory_bytes: 128
(let* ((n (read))
    (a (make-array n :initial-element 1))
    (sum 0)
    (ans 0))

    (loop for i below n do
        (progn
            (setf (aref a i) (read))
            (incf sum (aref a i))
            (setf sum (rem sum 1000000007))
        )
    )

    (loop for i below n do
        (progn
            (decf sum (aref a i))
            (if (< sum 0) (incf sum 1000000007))
            (incf ans (* (aref a i) sum))
            (setf ans (rem ans 1000000007))
        )
    )

    (format t "~D~%" ans)
)

Measured memory_bytes: 78580
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> P;
typedef pair<ll, ll> Pll;
using Graph = vector<vector<int>>;
using Graphl = vector<vector<ll>>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define Rep(i, k, n) for (int i = k; i < (int)(n); i++)
#define RRep(i, k, n) for (int i = k; i > (int)(n); i--)
#define FOR(itr, v) for (auto itr = (v).begin(); itr != (v).end(); ++itr)
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define ALL(a)  (a).begin(),(a).end()
#define rALL(a)  (a).rbegin(),(a).rend()
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; }
template<class T> void PrintVector(const vector<T> &vec) {for (auto val : vec) cout << val << " "; cout << endl;}
const long long INF = 1LL << 60;
const long long minusINF = -(1LL << 40);
const int MOD = 1000000007;
const double PI = acos(-1); //3.14~
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

int main()
{
    int n, i; cin >> n >> i;
    cout << n - i + 1 << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define mods 1000000007
#define pb push_back
#define mp make_pair
#define st first
#define nd second
typedef long long int lint;
typedef unsigned long long int ulint;

lint n,w,dp[110][100020]={0},dizi[110][2]={0};

int main(){
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
	lint i,j,k,l;
	cin>>n>>w;
	for(i=1;i<=n;i++) cin>>dizi[i][0]>>dizi[i][1];
	for(j=1;j<=n;j++){
		for(i=0;i<=w;i++){
			if(i>=dizi[j][0]) dp[j][i]=fmax(dp[j-1][i],dp[j-1][i-dizi[j][0]]+dizi[j][1]);
			else dp[j][i]=dp[j-1][i];
		}
	}
	cout<<dp[n][w];
	
	
	return 0;
}

Measured memory_bytes: 79360
#include <bits/stdc++.h>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/integer/common_factor.hpp>
#include <boost/integer/common_factor_rt.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>

using std::string;
using std::vector;
using std::set;
using std::map;
using std::unordered_map;
using std::pair;
using std::cin;
using std::cout;

typedef uintmax_t    ull;
typedef intmax_t     ll;
typedef uint64_t     ul;
typedef uint32_t     ui;
typedef uint8_t      uc;

typedef boost::multiprecision::number<boost::multiprecision::cpp_dec_float<1000>> cpp_dec_float_1000;

constexpr char CRLF = '\n';
constexpr char SPACE = ' ';
constexpr char VECTOR_COUT_SEPARATOR = SPACE;
constexpr ll INF = 1000'000'007;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> std::ostream& operator<< (std::ostream& os, const std::vector<T>& vc) { for(auto it = vc.begin(); it != vc.end(); ++it) { if (std::next(it) == vc.end()) os << *it; else os << *it << VECTOR_COUT_SEPARATOR; } return os; }
template<class T1, class T2> inline std::ostream & operator<< (std::ostream & os, const std::pair<T1, T2> & p) { return os << p.first << ' ' << p.second; }

void solve(void)
{
  ull n,k; cin >> n >> k;

  auto num0 = n / k;
  auto num1 = k % 2 ? 0 : n / (k / 2);
  if(num1) num1 -= num0;

  auto res = num0*num0*num0;
  res += num1*num1*num1;
  cout << res << CRLF;
  return;
}

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

  solve();

  return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#define MOD 1000000007
typedef long long ll;
using namespace std;

int main(){
  ll I,O,T,J,L,S,Z;
  cin>>I>>O>>T>>J>>L>>S>>Z;

  ll ans=O;
  if((I%2+J%2+L%2)>=2){
    if(I>0&&J>0&&L>0){
      ans=ans+3;
      I--;
      J--;
      L--;
    }
  }
  ans=ans+(I/2)*2;
  ans=ans+(L/2)*2;
  ans=ans+(J/2)*2;
  cout<<ans<<endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define chmin(a, b) ((a)=min((a), (b)))
#define chmax(a, b) ((a)=max((a), (b)))
#define fs first
#define sc second
#define eb emplace_back
using namespace std;
 
typedef long long ll;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;
 
const ll MOD=1e9+7;
const ll INF=1e18;
 
int dx[]={1,0,-1,-1,-1,0,1,1};
int dy[]={1,1,1,0,-1,-1,-1,0};

int sum[1010][1010];
int m[1010][1010];

int main(){
    int h,w;

    cin >> h >> w;
    for(int i = 0;i < h;i++){
        char tmp[1010];
        cin >> tmp;
        for(int j = 0;j < w;j++){
            if(tmp[j] == '.'){
                m[i][j] = 0;
                sum[i][j] = 0;
            }else{
                m[i][j] = tmp[j] - '0';
                sum[i][j] = -1;
            }
        }
    }
    queue<P> que;
    int ans = 0;
    for(int i = 0;i < h;i++){
        for(int j = 0;j < w;j++){
            if(sum[i][j] == -1){
                int s = 0;
                for(int k = 0;k < 8;k++){
                    if(sum[i+dx[k]][j+dy[k]] == 0) s++;
                }
                if(s >= m[i][j]){
                    que.push(P(i,j));
                    sum[i][j] = 1;
                    ans = 1;
                }
            }
        }
    }
    while(!que.empty()){
        P q = que.front(); que.pop();
        int x = q.fs,y = q.sc;
        for(int k = 0;k < 8;k++){
            if(sum[x+dx[k]][y+dy[k]] == -1){
                int smax = 0;
                int count = 0;
                int nx = x + dx[k],ny = y + dy[k];
                vector<int> v;
                for(int l = 0;l < 8;l++){
                    if(sum[nx+dx[l]][ny+dy[l]] == -1)continue;
               //     smax = max(smax,sum[nx+dx[k]][ny+dy[k]]);
                    v.push_back(sum[nx+dx[l]][ny+dy[l]]);
                    count++;
                }
                if(count >= m[x+dx[k]][y+dy[k]]){
                    int th = m[x+dx[k]][y+dy[k]];
                    sort(v.begin(),v.end());

                    ans = max(ans,v[th-1]+1);
                    sum[x+dx[k]][y+dy[k]] = v[th-1]+1;
                    que.push(P(x+dx[k],y+dy[k]));
                }
            }
        }
    }
    cout << ans << endl;





}


Measured memory_bytes: 11048
package main

import "fmt"

func main() {
	var n, m int
	fmt.Scan(&n, &m)

	if n == 1 && m == 1 {
		fmt.Println(1)
	} else if n == 1 && m > 1 {
		fmt.Println(m - 2)
	} else if m == 1 && n > 1 {
		fmt.Println(n - 2)
	} else {
		fmt.Println((n - 2) * (m - 2))
	}
}


Measured memory_bytes: 512
import sys
s = list(input())

i = 0
for e in s:
    if i % 2 == 0 and e == 'L':
        print('No')
        sys.exit()
    elif i % 2 == 1 and e == 'R':
        print('No')
        sys.exit()
    i += 1

print('Yes')


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

long long n, a, b;

int main()
{
    cin >> n >> a >> b;
    long long tims = n / (a + b) * a;
    n %= (a + b);
    tims += min(a, n);
    cout << tims << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
 
using namespace std;
 
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define fo(i, n) for(int i = 1; i <= n; ++i)
 
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
 
const int N = 200200;
const int mod = 1e9 + 7;
 
string s;
int n;
int a[N];
inline bool good(int k)
{
	for(int i = 0; i < n; ++i)
		a[i] = s[i] - '0';
	for(int i = 0; i < n; ++i)
		if(a[i] == 1)
			
	for(int i = 0; i < n; ++i)
		if(a[i] != 0)
			return 0;
	return 1;
}
 
int main()
{
	cin >> s;
	n = s.length();
	int k = 0, n1 = n, n0 = n;
	for(int i = 0; i < n; ++i)
		a[i] = s[i] - '0';
	for(int i = 0; i < n; ++i)
		if(a[i]) n1 = min(n1, max(min(i + 1, n - i), max(i, n - i - 1)));
		else     n0 = min(n0, max(min(i + 1, n - i), max(i, n - i - 1)));

	cout << max(n1, n0);
	return 0;            
}

Measured memory_bytes: 896
#include <bits/stdc++.h>
using namespace std;
 
#define MOD (1000000007)
#define f first
#define s second
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define all(x) x.begin(), x.end()
#define print(vec,l,r) for(int i = l; i <= r; i++) cout << vec[i] <<" "; cout << endl;
#define forf(i,a,b) for(int i = (a); i < (b); i++)
#define forr(i,a,b) for(int i = (a); i > (b); i--)
#define input(vec,N) for(int i = 0; i < (N); i++) cin >> vec[i];
typedef long long int ll;
#define ld long double
const int N = 2e5+30;
//https://codeforces.com/problemset/page/2?tags=1700-1700
 
 
void solve(){
   int n,k;
   cin>>n>>k;
   int a[n+3];
   int dp[n+3];
   for(int i=1;i<=n;i++){
     dp[i] = 1e9;
   }
   for(int i=1;i<=n;i++){
     cin>>a[i];
   }
   dp[1]  = 0;
   for(int i=2;i<=n;i++){
     for(int j=1;j<=k;j++){
      if(i-j>=1){
        dp[i] = min(dp[i],dp[i-j]+abs(a[i]-a[i-j]));
      }
     }
   }
   cout<<dp[n]<<'\n';
}
 
 
int main(){
 	ios_base::sync_with_stdio(false);
  cin.tie(NULL);
	int T;
  //cin >> T;
  //cout<<prs.size()<<'\n';
	 T = 1;
  //visited[1]=1;
	while(T--){
		solve();
	}
}

Measured memory_bytes: 4336
MOD = 10 ** 9 + 7

s = $stdin.readline.to_i
res = 0
inv = Array.new(s + 1)
s.times do |i|
  if i == 0
    inv[i + 1] = 1
  else
    inv[i + 1] = (- inv[MOD % (i + 1)] * (MOD / (i + 1))) % MOD
  end
end

(s / 3).times do |t|
  if t == 0
    res += 1
    next
  end
  t += 1

  comb = Array.new(t)
  comb[0] = 1
  
  (t - 1).times do |i|
    comb[i + 1] = comb[i] * (s - 2 * t - 1 - i) * inv[i + 1] % MOD
  end

  res = (res + comb[t - 1]) % MOD
end
puts res

Measured memory_bytes: 14316
import sys
def input():
    return sys.stdin.readline()[:-1]
N,Q=map(int,input().split())
s=input()
t=[input() for i in range(Q)]
def o(x):
    for i in t:
        if s[x]==i[0]:
            if i[2]=="L":
                if x==0:
                    return -1
                x-=1
            else:
                x+=1
                if x==N:
                    return 1
    return 0
l,r=0,N
while l+1<r:
    m=(r-l)//2+l
    if o(m)>=0:
        r=m
    else:
        l=m
a=l
l,r=0,N
while l+1<r:
    m=(r-l)//2+l
    if o(m)>0:
        r=m
    else:
        l=m
print(l-a)

Measured memory_bytes: 57040
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
  
int main() {
  int x=0;
  int a;
  cin >> a;
  int N = a;
  
  while(1){
    x += N % 10;
	N /= 10;
    if (N==0) break; 
  }
  if (a % x == 0) {
    cout << "Yes";
  }else cout << "No";
}

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

int	main(void)
{
  	char	s[101];
  	int		num;
  	int		len;
  	int		i;
  	int		count;
  
  	num = scanf("%s", s);
  	if (num != 1)
      	return (0);
  
  	len = strlen(s);
  
  	count = 0;
  	for (i=0; i<len/2 ; i++)
    {
      	if (s[i] != s[len - i - 1])
          	count++;
    }
  
  	printf("%d", count);
  
  	return (0);
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int i,n,sum=0;
	char a[100];
	cin>>a;
	n=strlen(a);
	for(i=1;i<n-1;i++)
		sum++;
	cout<<a[0]<<sum<<a[n-1];	
 	return 0;
}


Measured memory_bytes: 256
import std.stdio, std.conv, std.functional, std.string;
import std.algorithm, std.array, std.container, std.typecons;
import std.numeric, std.math;
import core.bitop;

string FMT_F = "%.10f";

static string[] s_rd;
T RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
string RDR()() { return readln.chomp; }
T[] ARR(T = long)(in string str, T fix = 0) { auto r = str.split.to!(T[]); r[] += fix; return r; }
size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }

bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
bool minimize(T)(ref T x, T y) { if (x > y) { x = y; return true; } else { return false; } }
bool maximize(T)(ref T x, T y) { if (x < y) { x = y; return true; } else { return false; } }

long mod = 10^^9 + 7;
void moda(ref long x, long y) { x = (x + y) % mod; }
void mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(ref long x, long y) { x = (x * y) % mod; }

void main()
{
	auto N = RD;
	auto M = RD;
	auto C = RD;
	auto B = RDR.ARR;
	auto A = new long[][](N);
	foreach (i; 0..N)
	{
		A[i] = RDR.ARR;
	}

	long ans;
	foreach (ref e; A)
	{
		e[] *= B[];
		if (e.sum + C > 0) ++ans;
	}
	writeln(ans);
	stdout.flush();
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <string>
#include <sstream>
#include <vector>
#include <set>
#define INF 2000000000
using namespace std;



long merge(int *A,int left,int mid,int right){
	int n1 = mid - left;
	int n2 = right - mid;
	int *L = new int[n1+1];
	int *R = new int[n2+1];
	for(int i = 0; i < n1; i++){
		L[i] = A[left + i];
	}

	for(int i = 0; i < n2; i++){
		R[i] = A[mid + i];
	}
	L[n1] = INF;
	R[n2] = INF;
	int i = 0;
	int j = 0;
	long count = 0;
	for(int k = left; k < right; k++){
		if( L[i] <= R[j]){
			A[k] = L[i];
			i++;
		}else{			//L > R の時でかつ、i < n1 - 1 の場合順序の置き換えが発生している
			count += n1 - i;
			A[k] = R[j];
			j++;
		}
	}
	//delete[] L,R;
	return count;
}


long mergeSort(int *A,int left,int right){
	long totalCount = 0;
	if(left + 1 < right){
		int mid = (left + right) / 2;
		totalCount += mergeSort(A,left,mid);
		totalCount += mergeSort(A,mid,right);
		totalCount += merge(A,left,mid,right);
	}
	return totalCount;
}


int main()
{
	int n;
	cin >> n;
	int *A = new int[n];
	for(int i = 0; i < n; i++){
		cin>>A[i];
	}
	long count = 0;
	count = mergeSort(A,0,n);
	cout << count << endl;
	return 0;
}





Measured memory_bytes: 27300
#include <stdio.h>
#include <math.h>

struct Point{ double x,y;};

void koch(int n,Point a,Point b)
{
  if(n==0)return;
  Point s, t, u;
  double th = M_PI * 60.0 / 180.0;

  s.x = (2.0 * a.x + 1.0 * b.x) / 3.0;
  s.y = (2.0 * a.y + 1.0 * b.y) / 3.0;
  t.x = (1.0 * a.x + 2.0 * b.x) / 3.0;
  t.y = (1.0 * a.y + 2.0 * b.y) / 3.0;
  u.x = (t.x - s.x) * cos(th) - (t.y - s.y) * sin(th) + s.x;
  u.y = (t.x - s.x) * sin(th) + (t.y - s.y) * cos(th) + s.y;

  koch(n-1, a, s);
  printf("%.8f %.8f\n", s.x, s.y);
  koch(n-1, s, u);
  printf("%.8f %.8f\n", u.x, u.y);
  koch(n-1, u, t);
  printf("%.8f %.8f\n", t.x, t.y);
  koch(n-1, t, b);
}

int main()
{
  Point a, b;
  int n;

  scanf ("%d", &n);

  a.x = 0;
  a.y = 0;
  b.x = 100;
  b.y = 0;

  printf("%.8f %.8f\n", a.x, a.y);
  koch(n, a, b);
  printf("%.8f %.8f\n", b.x, b.y);

  return 0;
}



Measured memory_bytes: 2732
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
typedef  long long ll;
typedef  vector<int> vi;
typedef  pair<int,int> ii;
typedef  pair<int,string> pis;
double   pi=3.1415926535898;
#define speed      ios::sync_with_stdio(false);cin.tie(NULL); cout.tie(NULL);
#define lp(i,n)    for(int i=0;i<int(n);i++)
#define ff(i,a,b)  for(int i=a;i<=int(b);++i)
#define fr(i,a,b)  for(int i=a;i>=int(b);i--)
#define ms(x,a)    memset(x,a,sizeof(x))
#define all(x)     (x).begin(),(x).end()
#define sz(x)      int(x.size())
#define pb         push_back
#define r0         return 0;
#define CC         continue;
#define bb(x)      cerr<< x <<endl;
#define F          first
#define S          second       //  __builtin_popcount;
//freopen("input.txt","r",stdin),freopen("output.txt","w",stdout);
string ys = "YES\n";
string no = "NO\n" ;
const double EPS = 1e-9;
const int inf = 1<<30;
const ll M  = 1e9+7 ;
//const int N = 100100;
//////////////////////    Hi    ^_^  hack me if you can :P

int n,k,t;

int main()
{
    speed;
    string s;
    cin >> s;
    bool f = 1;
    for (auto x :s ){
    if (f) cout << x;
    f = !f;
    }

    return 0;
}

Measured memory_bytes: 592
import java.util.Scanner;
public class Main {
	public static void main(String[] args){
		Scanner scan=new Scanner(System.in);
		int x,y;
		while(true){
			x=scan.nextInt();
			y=scan.nextInt();
			if(x==0&&y==0) break;
			if(x<y){
				System.out.printf("%d %d\n",x,y);
			}else{
				System.out.printf("%d %d\n",y,x);
			}
		}
	}
}

Measured memory_bytes: 33440
#include<stdio.h>
int main(void){
  char x,y;
  int a=1,b=0,c=0;
  int w=0;

  while(scanf("%c,%c",&x,&y) != EOF){
    if(x == 'A' && y =='B' || y == 'A' && x =='B'){
      w=a;a=b;b=w;}
    else if(x == 'A' && y == 'C' || y == 'A' && x == 'C'){
      w=a;a=c;c=w;}
    else if(x == 'B' && y == 'C' || y == 'B' && x == 'C'){
      w=b;b=c;c=w;}
    
  }
  if(a==1)printf("A\n");
  else if(b == 1)printf("B\n");
  else printf("C\n");
  return 0;
}

//#526082

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

int main(){
    int n,a,b,max,min;
    cin >> n >> a >> b;
    
    if(a>b){
        max = b;
    }else{
        max = a;
    }
    
    if(n > a+b){
        min = 0;
    }else{
        min = a+b-n;
    }
    cout << max << " " << min << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<n;i++)
int main(){
    int flag=1;
    string s;
    map<char,int> mp;
    cin >> s;
    rep(i,s.length()){
        mp[s[i]]++;
    }
    if(mp.count('E')!=mp.count('W'))flag=0;
    if(mp.count('N')!=mp.count('S'))flag=0;
    if(flag)cout << "Yes" << endl;
    else cout << "No" << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <unordered_map>
#include <unordered_set>
using namespace std;
#define endl '\n'
#define PI acos(-1)
typedef long long ll;
//  Table is the complete reverse of dp
//  Always think of the pattern (LCM, GCD)
//  Be careful of unsigned
//  double epsilon = FLT_EPSILON;
//	Think of a solution that gets TLE and optimize it
int n, *x;
ll **dp[2];
int main()
{
    cin.tie(nullptr); cout.tie(nullptr); ios_base::sync_with_stdio(false);
    cin >> n;
    x = new int[n];
    dp[0] = new ll *[n];
    dp[1] = new ll *[n];
    for(int i = 0; i < n; i++)
    {
    	cin >> x[i];
    	dp[0][i] = new ll[n];
    	dp[1][i] = new ll[n];
    	dp[0][i][i] = x[i];
    	dp[1][i][i] = -x[i];
    }
    for(int sz = 1; sz < n; sz++)
    	for(int i = 0; i + sz < n; i++)
    	{
			dp[0][i][i + sz] = max(x[i] + dp[1][i + 1][i + sz], x[i + sz] + dp[1][i][i + sz - 1]);
			dp[1][i][i + sz] = min(-x[i] + dp[0][i + 1][i + sz], -x[i + sz] + dp[0][i][i + sz - 1]);
    	}
    cout << dp[0][0][n - 1];
}


Measured memory_bytes: 92672
#include <set>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctype.h>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>

using namespace std;

#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i, n) REP(i, 0, n)
#define lengthof(x) (sizeof(x) / sizeof(*(x)))
#define FILL(ptr, value) FILL_((ptr), sizeof(ptr)/sizeof(value), (value))
template <typename T>
void FILL_(void * ptr, size_t size, T value){
  std::fill((T*)ptr, (T*)ptr+size, value);
}
//4方向ベクトル→↑←↓
int dx[] ={1,0,-1,0};
int dy[] ={0,-1,0,1};
string str;
int main()
{
  while(cin>>str){
    int ans = 0;
    map<char,int> fig;
    fig['I'] = 1;
    fig['V'] = 5;
    fig['X'] = 10;
    fig['L'] = 50;
    fig['C'] = 100;
    fig['D'] = 500;
    fig['M'] = 1000;
    for(int i = 0;i < str.length();i++){
      if(fig[str[i]] >=fig[str[i+1]]){
	ans +=fig[str[i]];
      }else{
	ans -=fig[str[i]];
      }
    }
    cout <<ans<<endl;
  }	
  return 0;
}

Measured memory_bytes: 1188
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int main(void){
    int n,d,x,a,ans=0;
    cin>>n>>d>>x;
    for(int i=0;i<n;i++){
        cin>>a;
        ans+=(d-1)/a+1;
    }
    cout<<ans+x;
    return 0;
}


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


int main() {
	int n,cnt=0;cin>>n;
	vector<int> p,q;
	rep(i,n){
		int k;cin>>k;
		p.push_back(k);
	}
	q=p;
	sort(p.begin(),p.end());
	rep(i,n){
		if(p.at(i)!=q.at(i))cnt++;
	}
	if(cnt==2||cnt==0){
		cout<<"YES"<<endl;
	}else{
		cout<<"NO"<<endl;
	}
	return 0;
}


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

using namespace std;

char s[100005];
int pos[100001];
int len;
int cou[100001];

int main()
{
    scanf("%s",s + 1);
    len = strlen(s + 1);
    for(int i = 1;i <= len;i++)
        cou[i] = 1;
    for(int i = 1;i <= len;i++)
    {
        int j = i;
        if(s[i] == s[i - 1] && i != 1)
            pos[i] = pos[i - 1];
        else
        {
            if(s[j] == 'R')
            {
                while(s[j] == s[j + 1])
                    j++;
            }
            else
            {
                while(s[j] == s[j - 1])
                    j--;
            }
            pos[i] = j;
        }
    }
    for(int i = 1;i <= len ;i++)
    {
        int t = 0;
        int j = i;
        cou[i]--;
        while(1)
        {
            if(s[j] == 'R')
            {
                if(s[j + 1] == 'L')
                {
                    if(t % 2 == 1)
                    {
                        cou[j]++;
                        break;
                    }
                    else
                    {
                        cou[j + 1]++;
                        break;
                    }
                }
                else
                {
                    j = pos[j];
                    t += abs(pos[j] - i) + 1;
                }
            }
            else
            {
                if(s[j - 1] == 'R')
                {
                    if(t % 2 == 1)
                    {
                        cou[j]++;
                        break;
                    }
                    else
                    {
                        cou[j - 1]++;
                        break;
                    }
                }
                else
                {
                    j = pos[j];
                    t += i - pos[j] + 1;
                }
            }
        }
    }
    for(int i = 1;i < len;i++)
        printf("%d ",cou[i]);
    printf("%d\n",cou[len]);
    return 0;
}


Measured memory_bytes: 1280
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC target("avx")
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int (i)=0;i<(n);i++)
#define rrep(i,n) for(int (i)=1;i<=(n);i++)
#define REP(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define MOD 1000000007
#define INF 1e18
#define int long long
#define endl "\n"
#define yorn(f) puts((f)?"Yes":"No")
#define YORN(f) puts((f)?"YES":"NO")
typedef long long ll;
typedef pair<int, int> P;
int gcd(int a,int b){return b?gcd(b,a%b):a;};
int lcm(int a,int b){return a/gcd(a,b)*b;};
int mod(int a,int b){return (a+b-1)/b;};
template<typename A, size_t N, typename T>
void Fill(A(&array)[N],const T &val){std::fill((T*)array,(T*)(array+N),val);}
template<class T>inline bool chmax(T& a,T b){if(a<b){a=b;return true;}return false;};
template<class T>inline bool chmin(T& a,T b){if(a>b){a=b;return true;}return false;};



signed main() {
	cin.tie(0);
	cout.tie(0);
	ios::sync_with_stdio(false);
	//cout << fixed << setprecision(15);
	
	int n, d;
	cin >> n >> d;
	int ans = 0;
	rep(i, n) {
		int x, y;
		cin >> x >> y;
		if(x * x + y * y <= d * d) ans++;
	}
	cout << ans << endl;
	return 0;
}

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

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
const ll mod = 1000000007;
ll inv[1000000];
ll FactorialInv[1000000];
ll Factorial[1000000];
ll beki(ll a, ll b){
    if(b == 0){
        return 1;
    }
    ll ans = beki(a, b / 2);
    ans = ans * ans % mod;
    if(b % 2 == 1){
        ans = ans * a % mod;
    }
    return ans;
}
void init_combination(){
    inv[1] = 1;
    FactorialInv[1] = 1;
    Factorial[1] = 1;
    for(int i = 2; i < 1000000; i++){
        inv[i] = beki(i, mod - 2);
        Factorial[i] = Factorial[i - 1] * i % mod;
        FactorialInv[i] = FactorialInv[i - 1] * inv[i] % mod;
    }
}
ll combination(ll a, ll b){
    if((a == b) || (b == 0)){
        return 1;
    }
    ll ans = Factorial[a] * FactorialInv[b] % mod;
    ans = ans * FactorialInv[a - b] % mod;
    return ans;
}

struct SegmentTree {
private:
    int n;
    vector<ll> node;
 
public:
    /*SegmentTree() {
        int sz = 100500;
        n = 1; while(n < sz) n *= 2;
        node.resize(2*n-1, 0);
    }*/
    SegmentTree(vector<ll> v) {
        int sz = v.size();
        n = 1; while(n < sz) n *= 2;
        node.resize(2*n-1, INF);
        for(int i=0; i<sz; i++) node[i+n-1] = v[i];
        for(int i=n-2; i>=0; i--) node[i] = min(node[2*i+1], node[2*i+2]);
    }
 
    void update(int x, ll val) {
        x += (n - 1);
        node[x] = val;
        while(x > 0) {
            x = (x - 1) / 2;
            node[x] = (node[2*x+1] + node[2*x+2]) % mod;
        }
    }
    // hannkaikukann 
    int getsum(int a, int b, int k=0, int l=0, int r=-1) {
        if(r < 0) r = n;
        if(r <= a || b <= l) return 0;
        if(a <= l && r <= b) return node[k];
 
        int vl = getsum(a, b, 2*k+1, l, (l+r)/2);
        int vr = getsum(a, b, 2*k+2, (l+r)/2, r);
        return (vl + vr) % mod;
    }
};

int main() {
    init_combination();
    vector<ll> v(100500);
    SegmentTree seg(v);
    int n;
    cin >> n;
    ll ans = 0;
    for(int i = 1; i <= n; i++){
        ll in;
        cin >> in;
        seg.update(i, in);
    }
    ll sum[100500];
    sum[0] = 0;
    for(int i = 1; i <= n - 2; i++){
        int L = 1 + i;
        int R = n - i;
        if(R >= L){
            sum[i] = sum[i - 1] + seg.getsum(L, R + 1);
        } else {
            sum[i] = sum[n - 1 - i];
        }
        sum[i] = sum[i] % mod;
        ll add;
        add = sum[i] * Factorial[n] % mod;
        add = add * FactorialInv[i + 2] % mod;
        add = add * Factorial[2] % mod;
        add = add * Factorial[i] % mod;
        ans = (ans + add) % mod;
        //cout << i << " " << sum[i] << endl;
        //cout << add << endl;
    }
    for(int i = 1; i <= n - 1; i++){
        ll add = seg.getsum(1, i + 1) + seg.getsum(n + 1 - i, n + 1);
        add = add * Factorial[n] % mod;
        add = add * inv[i + 1] % mod;
        ans = (ans + add) % mod;
    }
    ll add = Factorial[n] * seg.getsum(1, n + 1) % mod;
    ans = (ans + add) % mod;
    cout << ans << endl;
    return 0;
}


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

const long long mod = 1e9 + 7;

using ll = long long;
using pii  = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)

ull gcd(ull a, ull b) { return b ? gcd(b, a % b) : a; }
ull lcm(ull a, ull b) { return a / gcd(a, b) * b; }

int main(){
    int n;
    cin >> n;
    vi a(n);
    rep(i, n) cin >> a[i];
    RSORT(a);
    ll ans = 0;
    int cnt = n-1;
    rep(i, n) {
        int t = (i>0?2:1);
        rep(j, t) {
            if (cnt > 0) {
                ans += a[i];
                --cnt;
            }
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 4052
using System;

namespace ALDS1_5A_2{
    public class Program{
        public static void Main(string[] args){
            var sr = new StreamReader();
            //---------------------------------
            var N = sr.Next<int>();
            var A = sr.Next<int>(N);
            var Q = sr.Next<int>();
            var M = sr.Next<int>(Q);

            Func<int, int, bool> solve = null;
            solve = (i, x) =>{
                if(x == 0) return true;
                if(i >= N || x < 0) return false;
                return solve(i + 1, x - A[i]) || solve(i + 1, x);
            };

            foreach(var m in M){
                Console.WriteLine(solve(0, m) ? "yes" : "no");
            }
            //---------------------------------
        }
    }

    public class StreamReader{
        private readonly char[] _c = {' '};
        private int _index = -1;
        private string[] _input = new string[0];

        public T Next<T>(){
            if(_index == _input.Length - 1){
                _index = -1;
                while(true){
                    string rl = Console.ReadLine();
                    if(rl == null){
                        if(typeof(T).IsClass) return default(T);
                        return (T)typeof(T).GetField("MinValue").GetValue(null);
                    }
                    if(rl != ""){
                        _input = rl.Split(_c, StringSplitOptions.RemoveEmptyEntries);
                        break;
                    }
                }
            }
            return (T)Convert.ChangeType(_input[++_index], typeof(T), System.Globalization.CultureInfo.InvariantCulture);
        }

        public T[] Next<T>(int x){
            var ret = new T[x];
            for(var i = 0; i < x; ++i) ret[i] = Next<T>();
            return ret;
        }

        public T[][] Next<T>(int y, int x){
            var ret = new T[y][];
            for(var i = 0; i < y; ++i) ret[i] = Next<T>(x);
            return ret;
        }
    }
}

Measured memory_bytes: 10232
import java.util.Scanner;

public class Main{
    public static void main(String []args){
            Scanner sc = new Scanner(System.in);
        int n,x;
        while(true){
            int counter = 0;
            n = sc.nextInt(); x = sc.nextInt();
             if(n == 0 && x == 0){
                break;
            };
            int [] arr1 = new int[n];
            int [] arr2 = new int[n];
            int [] arr3 = new int[n];
            for(int i = 0; i < n; i++){
                arr1[i] = i+1;
                arr2[i] = i+1;
                arr3[i] = i+1;
            }
            
            for(int i = 0; i< n;i++){
                for(int j = i+1; j< n;j++){
                    for (int k = j+1; k < n; k++) {
                        if (x == arr1[i]+ arr2[j] + arr3[k] ) {
                            counter++;
                        }
                    }        
                }
            }
            System.out.println(counter);
            
            
           
        }
        
    }
}


Measured memory_bytes: 27320
#include<stdio.h>

int main()
{
  int n;
  int f[100];
  int i;

  scanf("%d",&n);
  f[0] = 1;
  f[1] = 1;
  for(i=2;i<=n;i++)
    {
      f[i] = f[i-1] + f[i-2];
    }
  printf("%d\n",f[n]);
  return 0;
}

Measured memory_bytes: 596
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll mod = 1000000007;

ll r(ll x, ll y) {
  if (y == 0) return 1;
  else if (y % 2 == 0) return r(x, y/2) * r(x, y/2) % mod;
  else return x * r(x, (y-1)/2) % mod * r(x, (y-1)/2) % mod;
}

int main() {
  string s,t;
  cin >> s >> t;
  cout << t << s <<endl;
}

Measured memory_bytes: 256
def getN():
    return int(input())


def getNM():
    return map(int, input().split())


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

def gcd(n,m):
    if n > m:
        n,m = m,n
    while (m % n != 0):
        temp = n;
        n = m % n;
        m = temp;
    return n;

def lcm(m,n):
    return int(m*n/gcd(m,n))

N,M = getNM()

s = input()
t = input()

lcm = lcm(N,M)
ks, kt = lcm//N, lcm//M
order = {}
flag = 1
i = 0
for alp in s:
    order[ks*i+1] = alp
    i += 1

j= 0
for alp in t:
    num = kt*j+1
    try:
        if order[num] != alp:
            flag = 0
    except:
        pass
    j += 1

if flag:
    print(lcm)
else:
    print("-1")



Measured memory_bytes: 15396
#include <bits/stdc++.h>
using namespace std;
#define long long long
#define read cin >>
#define echo cout <<
#define fin << '\n'

signed main ( ) {

    int n;
    read n;
    vector<int> a(n);
    for ( auto&&i : a ) cin >> i;

    int lookFor = 1;
    for ( int i = 0; i < n; i++ ) {
        if ( a[i] == lookFor ) {
            lookFor++;
        }
    }

    if ( lookFor == 1 ) puts("-1");
    else echo n-lookFor+1 fin;

    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x, n) for(int i = x; i <= n; i++)
#define rep3(i, x, n) for(int i = x; i >= n; i--)
#define elif else if
#define sp(x) fixed << setprecision(x)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
//const ll MOD = 1e9+7;
const ll MOD = 998244353;
const int inf = (1<<30)-1;
const ll INF = (1LL<<60)-1;
const ld EPS = 1e-10;
template<typename T> bool chmax(T &x, const T &y) {return (x < y)? (x = y, true) : false;};
template<typename T> bool chmin(T &x, const T &y) {return (x > y)? (x = y, true) : false;};

template<ll mod> struct Mod_Int{
    ll x;
    Mod_Int() {}
    Mod_Int(ll y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod){}

    Mod_Int &operator += (const Mod_Int &p) {
        x = (x + p.x) % mod;
        return *this;
    }

    Mod_Int &operator -= (const Mod_Int &p) {
        x = (x + mod - p.x) % mod;
        return *this;
    }

    Mod_Int &operator *= (const Mod_Int &p) {
        x = (x * p.x) % mod;
        return *this;
    }

    Mod_Int &operator /= (const Mod_Int &p) {
        *this *= p.inverse();
        return *this;
    }

    Mod_Int operator -() const {return Mod_Int(-x);}

    Mod_Int operator + (const Mod_Int &p) const {return Mod_Int(*this) += p;}

    Mod_Int operator - (const Mod_Int &p) const {return Mod_Int(*this) -= p;}

    Mod_Int operator * (const Mod_Int &p) const {return Mod_Int(*this) *= p;}

    Mod_Int operator / (const Mod_Int &p) const {return Mod_Int(*this) /= p;}

    bool operator == (const Mod_Int &p) const {return x == p.x;}

    bool operator != (const Mod_Int &p) const {return x != p.x;}

    Mod_Int pow(ll n) const{
        Mod_Int now = *this, ret = 1;
        while(n > 0){
            if(n & 1) ret *= now;
            now *= now, n >>= 1;
        }
        return ret;
    }

    Mod_Int inverse() const{
        return pow(mod-2);
    }
};

using mint = Mod_Int<MOD>;
const int MAX_N = 2e6;
mint fac[MAX_N+1];

void init(){
    fac[0] = 1;
    rep2(i, 1, MAX_N){
        fac[i] = fac[i-1]*mint(i);
    }
}

mint comb(mint n, mint k){
    return fac[n.x]/(fac[n.x-k.x]*fac[k.x]);
}

mint perm(mint n, mint k){
    return fac[n.x]/fac[n.x-k.x];
}

int main(){
    int N, M;
    cin >> N >> M;
    init();
    mint ans = 0;
    //奇数の山の個数
    for(int i = M&1; i <= min(N, M); i += 2){
        //残った2の個数
        int j = (3*M-i)/2;
        mint tmp = comb(N-1+j, j);
        tmp -= (mint)i * comb(N-1+j-M, j-M);
        if(j >= M+1) tmp -= (mint)(N-i) * comb(N-1+j-M-1, j-M-1);
        ans += tmp * comb(N, i);
    }
    cout << ans.x << endl;
}

Measured memory_bytes: 15872
#include <iostream>
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
#include <cctype>
#include <string>
#include <map>
#include <set>
#include <math.h>
#include <cmath>
#define ll long long
#define lli long long int

using namespace std;
using P = pair<ll,ll>;

int main(){

  ll N, M;
  cin >> N >> M;
  ll ans = 0;

  vector<P> p(N);
  for (int i = 0; i < N; i++) {
    cin >> p[i].first >> p[i].second;
  }
  sort(p.begin(), p.end());

  for (int i = 0; i < N; i++) {
    if(M < 0) break;

    if(M - p[i].second >= 0){
      ans += p[i].first * p[i].second;
    }else if (M - p[i].second < 0){
      ans += p[i].first * M;
    }
    M = M - p[i].second;

  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 4772
/**
 * Training to the municipal stage of ROI
**/ 
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define forn for(int i=0;i<n;i++)
#define form for(int j=0;j<m;j++)
#define pb push_back
#define mp make_pair
#define s second
#define f first
#define kek cout<<"\n"
#define all(v)        ((v).begin()), ((v).end())
#define pob pop_back()
int main()
{
  // freopen("input.txt", "r", stdin);
  // freopen("output.txt", "w", stdout);
int n;
cin>>n;
int arr[n];
forn cin>>arr[i];
ll ans=0;
forn
{
          for(int j=i+1;j<n;j++)
          {
                    
                    ans+=arr[i]*arr[j];
          }
}
cout<<ans;
return 0;

 
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		sc.close();
		int result = 0;
		for (int i = 0; i <= N; i++) {
			result += i;
		}
		System.out.println(result);
	}
}

Measured memory_bytes: 9812
#include<algorithm>
#include<string>
#include<vector>
#include<cmath>
#include<iostream>
# define ll int64_t
# define rep(i,n) for(ll i=0;i<n;i++)
# define rrep(i,n) for(ll i=1;i<=n;i++)
# define ALL(x) (x).begin(), (x).end()
# define SZ(x) ((int)(x).size())
# define pb push_back
# define mod 1000000007
# define PI 3.141592653589793
# define vec vector
#define dump(x) cerr<<#x<<"="<<x<<endl
using namespace std;

bool compare_by_b(pair<string,ll> a,pair<string,ll> b){
    if(a.second != b.second) return a.second<b.second;
    else return a.first<b.first;
}

bool my_compare(pair<string,ll> a,pair<string,ll> b){
    
    if(a.first != b.first) return a.first<b.first;
    if(a.second != b.second) return a.second>b.second;
    else return true;
}

ll factorial(ll n){
    ll x=1;
    rrep(i,n) (x*=i)%=mod;
    return x;
}

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

ll lcm(ll a,ll b)
{
   return a/gcd(a,b)*b;
}

//累乗だってさ
ll modpow(ll a,ll n,ll mod1) {
    ll res=1;
    while(n>0){
        if(n&1) res=res*a%mod1;
        a = a*a%mod1;
        n >>= 1;
    }
    return res;
}
//逆元だってさ
ll modinv(ll a,ll mod1) {
    return modpow(a, mod1 - 2, mod1);
}

const ll MAX = 510000;
const ll MOD = 1000000007;
 
ll fac[MAX], finv[MAX], inv[MAX];
 
// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (ll i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
 
// 二項係数計算
ll COM(ll n, ll k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    ll n;
    cin>>n;
    vec<pair<string,ll>> b(n),v(n);
    rep(i,n){
        cin>>b[i].first>>b[i].second;
        v[i].first=b[i].first;
        v[i].second=b[i].second;
    }
    sort(ALL(b),my_compare);
    rep(i,n){
        rep(j,n){
            if(b[i]==v[j]) cout<<j+1<<endl;
        }
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iterator>
#include <vector>
#include <cmath>
#include <algorithm>
#include <string>
#include <numeric>
#include <iomanip>
#include <limits>

using namespace std;

int main(){

    int ans=0;

    int a,b;
    cin>>a>>b;

    int max=a+b;

    if(max<a-b){
        max=a-b;
    }
    if(max<a*b){
        max=a*b;
    }

    cout<<max<<endl;
    return 0;
}


Measured memory_bytes: 256
//{{{
#include <bits/stdc++.h>
using namespace std;
#define rep(...) repN((__VA_ARGS__,rep3,rep2,loop,~))(__VA_ARGS__)
#define loop(n) rep2(_loop_,n)
#define rep2(i,n) rep3(i,0,n)
#define rep3(i,begin,end) for(int i=(int)(begin),i##_end=(int)(end);i<i##_end;++i)
#define repN(a) repX a
#define repX(a0,a1,a2,x,...) x
#define foreach(x,a) for(auto &x:a)
typedef long long ll;
const int MOD = 1e9+7;
//}}}

ll gcd(ll a, ll b){return b ? gcd(b, a % b) : a;}
ll lcm(ll a, ll b){return a / gcd(a, b) * b;}

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

  vector<pair<int, int>> v;
  rep(i, N){
    int a, b;
    cin >> a >> b;
    v.emplace_back(a, b);
  }
  sort(v.begin(), v.end());

  int i = 0;
  int ans = 0;
  rep(i, N){
    K -= v[i].second;
    if(K <= 0){
      ans = v[i].first;
      break;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1400
#include<stdio.h>
#include<assert.h>
#include<vector>
#include<string.h>
#include<algorithm>
#include<memory.h>
#include<cmath>
#include<string>
#include<iostream>
#include<set>
#include<unordered_set>
#include<map>
#include<queue>
#include<functional>
#include<list>

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<double, double> pdd;
typedef tuple<int,int,int> t3;

const int MX = 100005;
const int MM = 1000000007;

int D[MX], E[MX];

struct UF{
	map<int,int> L;
	int find(int x){
		return L.find(x) == L.end()? x : L[x] = find(L[x]);
	}
	int merge(int a, int b){
		a = find(a), b = find(b);
		return a == b ? 0 : (L[a] = b, 1);
	}
} uf;

int main()
{
	map<int, int> X, Y;
	int N, g = 0;
	scanf("%d", &N);
	for(int i = 1; i <= N; i++) scanf("%d", D+i), g ^= D[i]; D[N+1] = g;
	g = 0;
	for(int i = 1; i <= N; i++) scanf("%d", E+i), g ^= E[i]; E[N+1] = g;
	N++;

	for(int i = 1; i <= N; i++) X[D[i]] += 1;
	for(int i = 1; i <= N; i++) Y[E[i]] += 1;

	for(auto c : X){
		if( X[c.first] != Y[c.first] ) return !printf("-1\n");
	}

	set<int> L;
	int ans = 0;
	for(int i = 1; i <= N; i++) if( D[i] != E[i] ) ans++, L.insert(D[i]);
	if( L.size() == 0 ) return !printf("0\n");
	ans += L.size();
	for(int i = 1; i <= N; i++){
		ans -= uf.merge(D[i], E[i]);
	}
	if( D[N] != E[N] ) ans-=2;
	else if( D[N] == E[N] && L.find(D[N]) != L.end() ) ans--;
	printf("%d\n", ans);
}


Measured memory_bytes: 22400
#include <bits/stdc++.h>
using namespace std;
int main(){
    unordered_set<string> set;
    int n, as, bs;
    string q, s;
    cin >> n;
    for (int i = 0; i < n; i++){
        cin >> q >> s;
        if (q == "insert"){
            set.insert(s);
        } else if (q == "find"){
            bs = set.size();
            set.insert(s);
            as = set.size();
            if (bs == as){
                cout << "yes" << endl;
            } else {
                cout << "no" << endl;
                set.erase(s);
            }
        }
    }
}


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

using namespace std;

#define countof(a) (sizeof(a)/sizeof(*a))

#define vi vector<int>
#define vvi vector<vector<int> >
#define vpi vector<pi >
#define pi pair<int,int>
#define mp make_pair
#define fi first
#define se second
#define all(n) n.begin(), n.end()

#define FROMTO(var, from, to) for (register int var = (from), var##down = ((int)(to)) < ((int)(from));var##down ? (var >= (int)(to)) : (var <= (int)(to));var##down ? var-- : var++)
#define UPTO(var, from, to)   for (register int var = (from); var <= ((int)to); var++)
#define DOWNTO(var, from, to) for (register int var = (from); var >= ((int)to); var--)
#define FOR(var, to)          UPTO(var, 0, (to)-1)
#define DOWN(var, from)       DOWNTO(var, (from)-1, 0) 

#define INIT(var, val) FOR(i,countof(var)) var[i] = val
#define INPUT(var) FOR(i,countof(var)) cin >> var[i]
#define INPUT1(var) FOR(i,countof(var)) cin >> var[i], var[i]--

#define SORT(v) qsort(v,countof(v),sizeof(*v),int_less)
#define SORTT(v) qsort(v,countof(v),sizeof(*v),int_greater)
#define QSORT(v,b) qsort(v,countof(v),sizeof(*v),b)

#define MOD 1000000007
#define INF ((1 << 30)-1)
#define LINF ((1LL << 62)-1)

typedef uint8_t u8;
typedef uint16_t u16;
typedef uint32_t u32;
typedef uint64_t u64;
typedef int8_t s8;
typedef int16_t s16;
typedef int32_t s32;
typedef int64_t s64;

struct Comb {
    vector<vector<s64> > data;
    Comb(int n) { // O(n^2)
        data = vector<vector<s64> >(n+1,vector<s64>(n+1,1));
        UPTO(i,1,n) {
            FOR(j,i+1) {
                if (!j || j == i) data[i][j] = 1;
                else data[i][j] = data[i-1][j-1] + data[i-1][j];
            }
        }
    }
    
    s64 ncr(int n, int r) {
        return data[n][r];
    }
};

static inline int ri() {
  int a;
  scanf("%d", &a);
  return a;
}

int int_less(const void *a, const void *b) {
  return (*((const int*)a) - *((const int*)b));
}
int int_greater(const void *a, const void *b) {
  return (*((const int*)b) - *((const int*)a));
}

int main() {
	int n = ri();
	int k = ri();
 	int a[n];
	int b[n];
	FOR(i,n) a[i] = ri(), b[i] = ri();
	
	s64 res = 0;
	FOR(i,n) if ((k&a[i]) == a[i]) res += b[i];
	FOR(i,30) {
		if (k&(1<<i)) {
			int kk = k;
			kk&=~(1<<i);
			DOWN(j,i) kk |= (1<<j);
			s64 res_tmp = 0;
			FOR(j,n) {
				if ((kk&a[j]) == a[j]) {
					res_tmp += b[j];
				}
			}
			res = max(res, res_tmp);
		}
	}
	cout << res << endl;
	
    return 0;
}


Measured memory_bytes: 1024
# coding: utf-8
# Your code here!
N,A,B,C,D=map(int,input().split())

if N%A==0 and N%C==0:
    X=(N//A)*B
    Y=(N//C)*D
    
    X,Y=sorted([X,Y])
    print(X)

elif N%A==0 and N%C!=0:
    X=(N//A)*B
    Y=((N//C)+1)*D
    
    X,Y=sorted([X,Y])
    print(X)

elif N%A!=0 and N%C==0:
    X=((N//A)+1)*B
    Y=(N//C)*D
    
    X,Y=sorted([X,Y])
    print(X)

else:
    X=((N//A)+1)*B
    Y=((N//C)+1)*D
    
    X,Y=sorted([X,Y])
    print(X)


Measured memory_bytes: 5612
#include<iostream>
using namespace std;
int main() {
  string x,y;
  cin >> x >> y;
  if(x == y) {
    cout << "=" << endl;
  }else if((x == "A" && y != "A") || (x == "B" && y != "A" && y != "B") || (x == "C" && y != "A" && y != "B" && y != "C") || (x == "D" && y != "A" && y != "B" && y != "C" && y != "D") || (x == "E" && y != "A" && y != "B" && y != "C" && y != "D" && y != "E") || (x == "F" && y != "A" && y != "B" && y != "C" && y != "D" && y != "E" && y != "F")){
    cout << "<" << endl;
  }else{
    cout << ">" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <cmath>
#include <limits>
#include <climits>
#include <utility>
#include <algorithm>
#include <numeric>

using namespace std;

using ll = long long;
using ull = unsigned long long;

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

    map<string, int> m;

    for (int i = 0; i < N; ++i) {
        string s;
        cin >> s;
        m[s]++;
    }

    int max_count = 0;
    for (auto&& p : m) {
        max_count = max(max_count, p.second);
    }

    for (auto&& p : m) {
        if (p.second == max_count) {
            cout << p.first << endl;
        }
    }

    return 0;
}


Measured memory_bytes: 17664