akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
#define INF 1007654321
#define PI 3.14159265358979
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define repp(i, s, e) for(int i = (s); i <= (e); ++i)
#define sz(x) ((int)x.size())
#define all(x) x.begin(), x.end()
#define FAST_IO() ios::sync_with_stdio(0); cin.tie(0)
template<typename T>
ostream& operator<<(ostream &os, const vector<T> &v) { for (auto x : v) os << x << " "; return os << "\n"; }

struct Point {
    ll x, y;
};

void print(int x, int y, int m) {
    if(m <= 0) {
        cout << "\n";
        return;
    }
    if(y + x >= 0 && y - x >= 0) {
        cout << 'U';
        print(x, y - (1LL << (m - 1)), m - 1);
    } else if(y + x >= 0 && y - x < 0) {
        cout << 'R';
        print(x - (1LL << (m - 1)), y, m - 1);
    } else if(y + x < 0 && y - x >= 0) {
        cout << 'L';
        print(x + (1LL << (m - 1)), y, m - 1);
    } else {
        cout << 'D';
        print(x, y + (1LL << (m - 1)), m - 1);
    }
}

int main() {
    FAST_IO();
    int N; cin >> N;
    vector<Point> P(N);
    rep(i, N) cin >> P[i].x >> P[i].y;
    bool hasOdd = false, hasEven = false;
    rep(i, N) {
        if((abs(P[i].x) + abs(P[i].y)) % 2 == 0) hasEven = true;
        else hasOdd = true;
    }
    if(hasOdd && hasEven) {
        cout << "-1\n";
        return 0;
    }
    if(hasEven) {
        rep(i, N) P[i].x -= 1;
    }
    const int m = 32;
    if(hasEven) {
        cout << m + 1 << "\n";
        cout << 1 << " ";
    }
    else cout << m << "\n";
    rep(i, m) {
        cout << (1LL << (m - i - 1)) << " ";
    }
    cout << "\n";
    rep(i, N) {
        if(hasEven) cout << 'R';
        print(P[i].x, P[i].y, m);
    }
}

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

using namespace std;


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

    int n, m;
    cin >> n >> m;

    vector<vector<int>> adj(3 * n);
    for (int i = 0, src, dst; i < m; ++i) {
        cin >> src >> dst;
        --src; --dst;
        for (int j = 0; j < 3; ++j)
            adj[3 * src + j].push_back(3 * dst + ((j + 1) % 3));
    }

    int s, t;
    cin >> s >> t;
    s = 3 * (s - 1); t = 3 * (t - 1);

    vector<int> dist(3 * n, -1);
    queue<int> que;
    dist[s] = 0; que.push(s);

    while (!que.empty()) {
        int cur = que.front(); que.pop();
        for (int dst : adj[cur]) {
            if (dist[dst] == -1 || dist[cur] + 1 < dist[dst]) {
                dist[dst] = dist[cur] + 1;
                que.push(dst);
            }
        }
    }

    if (dist[t] == -1) cout << dist[t] << '\n';
    else cout << dist[t] / 3 << '\n';

    return 0;
}


Measured memory_bytes: 17792
#include <bits/stdc++.h>
using namespace std;
int main(){
    int a,b;
    string s;
    cin >> a >> b >> s;
    if(s[a]!='-'){
        cout << "No" << endl;
        return 0;
    }
    sort(s.begin(),s.end());
    int cnt = 0;
    for(int i = 0; i < s.length(); i++){
        if(s[i]=='-')cnt++;
    }
    if(cnt!=1){
        cout << "No" << endl;
        return 0;
    }
    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 3524
import Data.List
import Data.Maybe
import Control.Monad
import qualified Data.ByteString.Char8 as C

readInt' = fst.fromJust.C.readInt
readLnInt = map readInt'.C.words<$>C.getLine
readCsInt n = concat<$>replicateM n readLnInt

x ? (a,b) = if x then a else b
half = flip div 2
aliq = ((0==).).mod

main = do
 [n] <- readLnInt
 print $ solve n

solve n = n * n * n


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

// #undef DEBUG  // Uncomment this line to forcefully disable debug print.
#if DEBUG
template <typename T>
void debug(T value) {
  std::cerr << value;
}
template <typename T, typename... Ts>
void debug(T value, Ts... args) {
  std::cerr << value << ", ";
  debug(args...);
}
#define dbg(...)                              \
  do {                                        \
    cerr << #__VA_ARGS__ << ": ";             \
    debug(__VA_ARGS__);                       \
    cerr << " (L" << __LINE__ << ")" << endl; \
  } while (0)
#else
#define dbg(...)
#endif

void read_from_cin() {}
template <typename T, typename... Ts>
void read_from_cin(T& value, Ts&... args) {
  std::cin >> value;
  read_from_cin(args...);
}
#define in(type, ...) \
  type __VA_ARGS__;   \
  read_from_cin(__VA_ARGS__);

template <typename T>
void write_to_cout(const T& value) {
  std::cout << value << std::endl;
}
template <typename T, typename... Ts>
void write_to_cout(const T& value, const Ts&... args) {
  std::cout << value << ' ';
  write_to_cout(args...);
}
#define out(...) write_to_cout(__VA_ARGS__);

#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)

using ll = long long;

using namespace std;

int main() {
  in(ll, n);
  vector<ll> x(n), y(n), h(n);
  int I = -1;
  rep(i, n) {
    cin >> x[i] >> y[i] >> h[i];
    if (h[i] > 0) I = i;
  }
  assert(I >= 0);
  rep(cx, 101) rep(cy, 101) {
    ll H = h[I] + abs(x[I] - cx) + abs(y[I] - cy);
    bool ok = true;
    rep(i, n) {
      if (max(H - abs(x[i] - cx) - abs(y[i] - cy), 0LL) != h[i]) ok = false;
    }
    if (ok) {
      out(cx, cy, H);
      return 0;
    }
  }
}


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

using namespace std;

int ans[10001];

int main() {
	for(int a = 1; a <= 100; a++) {
		for(int b = 1; b <= 100; b++) {
			for(int c = 1; c <= 100; c++) {
				int x = a*a + b*b + c*c + a*b + b*c + c*a;
				if(x <= 10000) ans[x]++;
			}
		}
	}
	int n;
	cin >> n;
	for(int i = 0; i < n; i++) cout << ans[i+1] << '\n';
}

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

using namespace std;

long long l, ans, cur;
int n;
vector<long long> va, vb;
long long ta;
int tb, tc;

void check() {
	if (va.size() > 1) {
		tb = min((int)va.size() - 1, (int)vb.size() - 1 + 1);
		tc = min((int)va.size() - 1, (int)vb.size() - 1);
		// printf("%d %d\n", tb, tc);
		cur = va.back() - va[va.size() - 1 - tb];
		// printf("A %lld\n", cur);
		cur += vb.back() - vb[vb.size() - 1 - tc];
		cur *= 2;
		// printf("A %lld\n", cur);
		cur -= va.back() - va[va.size() - 2];
		// printf("A %lld\n", cur);
		ans = max(ans, cur);
	}
	if (vb.size() > 1) {
		tb = min((int)vb.size() - 1, (int)va.size() - 1 + 1);
		tc = min((int)vb.size() - 1, (int)va.size() - 1);
		cur = vb.back() - vb[vb.size() - 1 - tb];
		cur += va.back() - va[va.size() - 1 - tc];
		cur *= 2;
		// printf("B %lld\n", cur);
		cur -= vb.back() - vb[vb.size() - 2];
		// printf("B %lld\n", cur);
		ans = max(ans, cur);
	}
}

int main() {
	scanf("%lld%d", &l, &n);
	va.push_back(0);
	vb.push_back(0);
	while (n--) {
		scanf("%lld", &ta);
		va.push_back(va.back() + ta);
	}
	check();
	while (va.size() > 1) {
		vb.push_back(vb.back() + l - (va.back() - va[va.size() - 2]));
		va.pop_back();
		check();
	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 4848
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
 
int main() {
	cin.tie(0);
    ios::sync_with_stdio(false);

    ll N;
    cin >> N;

    ll sum = 0;

    for(ll i = 1; i <= N; i++) {
        if(i % 3 && i % 5) sum += i;
    }

    cout << sum << endl;
}

Measured memory_bytes: 3636
#include<iostream>
using namespace std;
int main()
{
  string s;
  cin>>s;
  if (s=="SAT")
  {
    cout<<"1";
  }
  else if (s=="SUN")
  {
    cout<<"7";
  }
 else if (s=="MON")
  {
    cout<<"6";
  }
 else  if (s=="TUE")
  {
    cout<<"5";
  }
 else if (s=="WED")
  {
    cout<<"4";
  }
 else if (s=="THU")
  {
    cout<<"3";
  }
else   if (s=="FRI")
  {
    cout<<"2";
  }
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define all(v) v.begin(),v.end()
#define P pair<int,int>
#define len(s) (int)s.size()
#define pb push_back

template<class T> inline bool chmin(T &a, T b){
	if(a>b){a=b;return true;}
	return false;
}
template<class T> inline bool chmax(T &a, T b){
	if(a<b){a=b;return true;}
	return false;
}
constexpr int mod = 1e9+7;
constexpr int inf = 3e18;

int f(int x){
	int ok=0,ng=50;
	while(ng-ok>1){
		int mid=(ok+ng)/2;
		if((1+mid)*mid/2<=x)ok=mid;
		else ng=mid;
	}
	return ok;
}
signed main(){
	int N;
	cin>>N;
	map<int,int>mp;
	for(int i=2;i*i<=N;i++){
		int cnt=0;
		while(N%i==0){
			cnt++;N/=i;
		}
		if(cnt)mp[i]=cnt;
	}
	if(N!=1)mp[N]=1;
	int ans=0;
	for(P p:mp)ans+=f(p.second);
	cout<<ans<<endl;
}


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

int main() {
  int n;
  cin >> n;
  vector<int> in;
  for (int i = 0; i < n; i++) {
    int tmp;
    cin >> tmp;
    in.push_back(tmp);
  }
  int alice = 0, bob = 0;
  sort(in.begin(), in.end());
  reverse(in.begin(), in.end());
  //for (int i = 0; i < n; i++)
    //cout << in[i] << endl;
  for (int i = 0; i < n; i++) {
    if (i % 2 == 0) {
      alice += in[i];
    }
    else {
      bob += in[i];
    }
  }
  cout << alice - bob<<endl;
}


Measured memory_bytes: 3632
S = input()
cntA = 0
cntB = 0
for index,x in enumerate(S):
    if(index%2==0):
        if(x=='1'):
            cntA+=1
        else:
            cntB+=1
    else:
        if(x=='1'):
            cntB+=1
        else:
            cntA+=1
print(min(cntA,cntB))


Measured memory_bytes: 3188
import java.util.Scanner;

//Osenbei
public class Main{

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while(true){
			int r = sc.nextInt();
			int c = sc.nextInt();
			if(r==0&&c==0)break;
			int[][] a = new int[r][c];
			for(int i=0;i<r;i++)for(int j=0;j<c;j++)a[i][j]=sc.nextInt();
			int[] p = new int[c];
			for(int j=0;j<c;j++){
				int e = 0;
				for(int i=0;i<r;i++)e+=a[i][j]<<i;
				p[j] = e;
			}
			int n = 1<<r;
			int max = 0;
			for(int i=0;i<n;i++){
				int t = 0;
				for(int j=0;j<c;j++){
					int e = p[j]^i;
					int bit = 0;
					for(int k=0;k<r;k++)bit+=(e&1<<k)>0?1:0;
					t += Math.max(bit, r-bit);
				}
				max = Math.max(max, t);
			}
			System.out.println(max);
		}
	}
}

Measured memory_bytes: 13000
#include "bits/stdc++.h"
using namespace std;

int main() {
  string S;
  cin >> S;
  vector<int> alph(26,0);
  for(int i=0;i<S.size();i++){
    alph.at(S.at(i) - 'a')++;
  }
  int res = -1;
  for(int i=0;i<26;i++){
    if(alph.at(i) == 0){
      res = i;
      break;
    }
  }
  if(res < 0){
    cout << "None";
  }else{
    cout << ((char)(res + 'a'));
  }
  cout << endl;
  return 0;
}

Measured memory_bytes: 512
#include<iostream>
#include<cstring>

using namespace std;

// http://d.hatena.ne.jp/Nekonyan/20110508 
// Nekonyanツつウツづアツづ個コツーツドツづーツ参ツ考ツづ可つオツづ慊つオツつスツ。

int table[10+1][9698];
int memo[10];

void numnum (int size, int depth, int sum )
{
	if (size + 1 == depth ) {
		table[size][sum]++;
	}else{
		for (int i = 0; i <= 9; ++i ){
			if ( memo[i] == 0 ) {
				memo[i] = 1;
				numnum (size, depth + 1, sum + i*depth );
				memo[i] = 0;
			} // end if
		} // end for
	} // end if
}

int main()
{
	memset(table, 0, sizeof (table ) );

	for (int i = 1; i <= 10; ++i ) {
		memset (memo, 0, sizeof (memo ) );
		numnum (i, 1, 0 );
	} // end for

	int n, s;
	while ( cin >> n >> s ) {
		cout << table[n][s] << endl;
	} // end while

	return 0;
}

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

int main() {
	int i;
	char tap[101];
	int cou = 0;

	cin >> tap;

	i = 0;
	while (tap[i++] != NULL)
		cou++;

	for (i = 1; i <= cou; i++) {
		if (i % 2 == 1) {
			if (tap[i-1] == 'L')
				break;
		}
		if (i % 2 == 0) {
			if (tap[i-1] == 'R')
				break;
		}
	}

	if (i == cou + 1)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;

	return 0;
}

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

using namespace std;

typedef long long ll;
const ll INF = 1LL<<60;

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

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

ll modpow(ll a, ll n, ll mod) {
  ll res = 1;
  while (n > 0) {
    if (n & 1) res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}

ll calc_keta(ll num){

  ll ret = 0;
  while(num > 0){
    num = num / 10;
    ret++;
  }
  return ret;
}

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

  ll N;
  cin >> N;

  ll ans = INF;
  for(ll i = 1; i * i <= N; i++){

    if(N % i == 0){
      ll a = i;
      ll b = N / i;
      chmin(ans, max(calc_keta(a), calc_keta(b)));
    }
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
import numpy as np
mod=10**9+7
N=int(input())
A=np.array(list(map(int, input().split())))
ans=0
for i in range(60):
  b=np.count_nonzero(A>>i&1)
  ans+=(2**i)*b*(N-b)
  ans%=mod
  
print(ans)



Measured memory_bytes: 48804
#include <iostream>
#include <vector>
#include <unordered_map>
#include <map>
#include <cstring>


int main() {
//    freopen("inp.txt", "r", stdin);
//    freopen("out.txt", "w", stdout);
    int H, W;
    constexpr int MOD = static_cast<int>(1e9 + 7);
    std::cin >> H >> W;
    int opt[H][W];
    memset(opt, 0, sizeof opt);
    char grid[H][W];

    for(int i = 0; i < H; i++) {
        std::string x;
        std::cin >> x;
        for(std::string::size_type j = 0; j < x.size(); j++) {
            grid[i][j] = x[j];
        }
    }

    if(grid[H - 1][W - 2] == '.') opt[H - 1][W - 2] = 1;
    if(grid[H - 2][W - 1] == '.') opt[H - 2][W - 1] = 1;

    for(int j = W - 3; j >= 0; --j) {
        if(grid[H - 1][j] == '#') opt[H - 1][j] = 0;
        else opt[H - 1][j] = opt[H - 1][j + 1];
    }

    for(int i = H - 3; i >= 0; --i) {
        if(grid[i][W - 1] == '#') opt[i][W - 1] = 0;
        else opt[i][W - 1] = opt[i + 1][W - 1];
    }

    for(int i = H - 2; i >= 0; --i) {
        for(int j = W - 2; j >= 0; --j) {
            if(grid[i][j] == '#') opt[i][j] = 0;
            else opt[i][j] = (opt[i][j + 1] + opt[i + 1][j]) % MOD;
        }
    }

    std::cout << opt[0][0];

    return 0;
}

Measured memory_bytes: 5120
#include<bits/stdc++.h>
using namespace std;
#define REP(i,m,n) for(int i=(m);i<(n);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll inf=1e9+7;
const ll mod=1e9+7;
int main(){
    string s;cin>>s;
    bool f=1;
    if(s[0]==s[s.size()-1]){
        if(s.size()%2==0)f=1;
        else f=0;
    }else{
        if(s.size()%2==0)f=0;
        else f=1;
    }
    cout<<(f?"First":"Second")<<endl;
}

Measured memory_bytes: 512
#include <stdio.h>

int main(void)
{
	int x, y;
	int a, b;
	int tmp;
	
	while (scanf("%d %d", &x, &y) != EOF){
		a = x;
		b = y;
		while (a % b != 0){
			tmp = a % b;
			a = b;
			b = tmp;
		}
		printf("%d\n", b);
	}
	return (0);
}

Measured memory_bytes: 1024
#include<cstdio>
#include<climits>
#include<algorithm>
using namespace std;

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

int main(){
    int n,ans=0,a[100000],b[1000],x;
    scanf("%d",&n);
    for(int i=0;i<n;i++){
        scanf("%d",&a[i]);
        if(i/1000){
            b[i%1000]=gcd(b[i%1000],a[i]);
        }
        else{
            b[i%1000]=a[i];
        }
    }
    for(int i=0;i<n;i++){
        x=0;
        for(int j=i%1000;j<n;j+=1000){
            if(i/1000!=j/1000){
                if(x){
                    x=gcd(x,a[j]);
                }
                else{
                    x=a[j];
                }
            }
        }
        for(int j=0;j<min(1000,n);j++){
            if(i%1000!=j%1000){
                if(x){
                    x=gcd(x,b[j]);
                }
                else{
                    x=b[j];
                }
            }
        }
        ans=max(x,ans);
    }
    printf("%d\n",ans);
}

Measured memory_bytes: 512
package main

import (
	"fmt"
)

func B(n int, s string) int {
	r := 0
	for i := 0; i < n-2; i++ {
		if s[i:i+3] == "ABC" {
			i += 2
			r++
		}
	}
	return r
}

func main() {
	var n int
	var s string
	// fmt.Scanf("%d %d", &k, &x)
	fmt.Scanf("%d", &n)
	fmt.Scanf("%s", &s)
	r := B(n, s)
	fmt.Printf("%d\n", r)
}


Measured memory_bytes: 512
#include<stdio.h>

int main() {
    int a[101][101], b[101], c[101];
    int i, j, n, m;
    
    //入力
    scanf("%d%d", &n, &m);
    
    for (i=0; i<n; i++) {
        for (j=0; j<m; j++) {
            scanf("%d", &a[i][j]);
        }
    }
    for (j=0; j<m; j++) {
        scanf("%d", &b[j]);
    }
    
    //処理cに入れる
    for (i=0; i<n; i++) {
        c[i] = 0; //全部0にする
        for (j=0; j<m; j++) {
            c[i] = c[i] + a[i][j] * b[j];
        }
    }
    
    //出力
    for (i=0; i<n; i++) {
        printf("%d\n", c[i]);
    }
    
    return 0;
}



Measured memory_bytes: 2108
def f(m, n):
    # m, m+1, ..., n
    res = 0

    t = ((m + 3) // 4) * 4
    for i in range(m, t):
        res ^= i

    t = (n // 4) * 4
    for i in range(t, n + 1):
        res ^= i

    return res


a, b = map(int, input().split())
print(f(a, b))


Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }

int X, Y, Z;

void _main() {
  cin >> X >> Y >> Z;
  X -= 2 * Z + Y;
  cout << (X / (Y + Z) + 1) << "\n";
}

Measured memory_bytes: 256
#include<string>
#include<vector>
#include<cctype>
#include<cmath>
#include<iostream>
#include<map>
using namespace std;

int main(){
    vector<int> evnum;
    int N;
    cin >> N;
    int tmp;
    while(cin>>tmp)
        if(!(tmp%2))
            evnum.push_back(tmp);
        else
            N--;
    for(auto n:evnum){
        if((n%3)&&(n%5)){
            cout << "DENIED" << endl;
            break;
        }
        N--;
    }
    if(N==0)
        cout << "APPROVED" << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int bubbleSort(int A[],int N) {
	int sw = 0;
	bool flag = 1;
	for(int i=0; flag; i++) {
		flag = 0;
		for(int j=N-1; j>=i+1; j--) {
			if(A[j] < A[j-1]) {
				swap(A[j], A[j-1]);
				flag = 1;
				sw++;
			}
		}
	}
	return sw;
}

int main(void) {
	int A[100], N, sw;
	cin >> N;
	for(int i=0;i<N; i++) cin >> A[i];

	sw = bubbleSort(A,N);

	for(int i = 0; i < N; i++) {
		if(i) cout << " ";
		cout << A[i];
	}
	cout << endl;
	cout << sw << endl;
	return 0;
}



Measured memory_bytes: 3112
#include<bits/stdc++.h>
using namespace std;
constexpr int64_t mod=1e9+7;

int main()
{
  int n,k;
  cin>>n>>k;
  string s;
  cin>>s;
  int tmp=1;
  std::vector<int> vec;
  for (int i = 0; i < n-1; ++i)
  {
    if(s[i]!=s[i+1]){
      vec.emplace_back(tmp);
      tmp=1;
    }
    else tmp++;
  }
  vec.emplace_back(tmp);
  int ans=0;
  for(auto&& e: vec) {
    ans+=e-1;
  }
  int size=vec.size();
  for (int i = 0; i < k; ++i)
  {
    if(size==1) break;
    else if(size==2) {
      ans++;
      size--;
      continue;
    }
    else ans+=2;
    size-=2;
  }
  cout<<ans;
}

Measured memory_bytes: 1020
macro_rules! input {
    ($ttype:ty) => {
        {
            let mut input = String::new();
            let _= std::io::stdin().read_line(&mut input);
            input.trim().parse::<$ttype>().unwrap()
        }
    };

    ($($ttype:ty),*) => {
        {
            use std::io::BufRead;
            let mut input = String::new();
            let stdin = std::io::stdin();
            let _ = stdin.lock().read_line(&mut input);
            let mut iter = input.trim().split_whitespace();
            (
                $(iter.next().unwrap().parse::<$ttype>().unwrap(),)*
            )
        }
    };

    ($ttype:ty; $x:expr) => {
        {
            use std::io::BufRead;
            let mut input = String::new();
            let stdin = std::io::stdin();
            let _ = stdin.lock().read_line(&mut input);
            let v: Vec<$ttype> = input
                .trim()
                .split_whitespace()
                .map(|x| x.parse().unwrap())
                .collect();
            v
        }
    };

    ($ttype:ty; $x:expr; $y:expr) => {
        {
            use std::io::BufRead;
            let mut matrix = Vec::with_capacity($y);
            for _ in 0..$y {
                let mut input = String::new();
                let stdin = std::io::stdin();
                let _ = stdin.lock().read_line(&mut input);
                let v: Vec<$ttype> = input
                    .trim()
                    .split_whitespace()
                    .map(|x| x.parse().unwrap())
                    .collect();
                matrix.push(v);
            }
            matrix
        }
    };
}

fn main() {
    let (n, m) = input!(i64, i64);

    if n >= m / 2 {
        println!("{}", m / 2);
    } else {
        println!("{}", n + (m - 2 * n) / 4);
    }
}


Measured memory_bytes: 4352
import java.util.*;

public class Main {
	Scanner sc;
	int N;
	int[][] nodes;
	int[] starts;
	int maxOrder = -1;

	public Main() {
		sc = new Scanner(System.in);
	}
	
	private void calc() {
		N = sc.nextInt();
		nodes = new int[N*N][4];
		starts = new int[N];
		for (int i = 0; i < N; i++) {
			int last = -1;
			for (int j = 0; j < N-1; j++) {
				int a = i;
				int b = sc.nextInt()-1;
				if (a < b) { a = b; b = i; }
				int n = N*a + b;
				if (j == 0) starts[i] = n;
				if (last > -1) {
					if (nodes[last][0] == 0) nodes[last][0] = n;
					else nodes[last][1] = n;
				}
				last = n;
			}
		}
		try {
			for (int i = 0; i < N; i++)
				if (nodes[starts[i]][2] == 0)
					maxOrder = Math.max(maxOrder, setPathLength(starts[i]));
			System.out.println(maxOrder);
		} catch (RuntimeException loop) {
			System.out.println(-1);
		}
	}
	
	int setPathLength(int n) {
		if (nodes[n][2] > 0) return nodes[n][2];
		if (nodes[n][3] > 0) throw new RuntimeException("loop");
		nodes[n][3] = 1;
		
		int max = 1;
		int n1 = nodes[n][0];
		if (n1 > 0) max = Math.max(max, 1+setPathLength(n1));
		int n2 = nodes[n][1];
		if (n2 > 0) max = Math.max(max, 1+setPathLength(n2));
		nodes[n][2] = max;
		return max;
	}

	public static void main(String[] args) {
		new Main().calc();
	}
}

Measured memory_bytes: 167068
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
using namespace std;
using ll = long long;
using P = pair<int,int>;
template <class T> void chmin(T &a, const T &b) noexcept { if (b < a) a = b; }
template <class T> void chmax(T &a, const T &b) noexcept { if (a < b) a = b; }
void debug_out() { cout << "\n"; }
template <class T, class... Args>
void debug_out(const T &x, const Args &... args) { cout << x << " "; debug_out(args...);}
#ifdef _DEBUG
  #define debug(...) debug_out(__VA_ARGS__)
#else
  #define debug(...) 
#endif

const int mod = 1000000007;
// const int mod = 998244353;
struct mint {
  ll x;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }
  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
  bool operator==(const mint rhs) const { return x == rhs.x; }
  bool operator!=(const mint rhs) const { return x != rhs.x; }
  bool operator<(const mint &a) const{ return x<a.x;};
};
istream& operator>>(istream& is, mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

struct combination {
  vector<mint> fact, ifact;
  combination(int n):fact(n+1),ifact(n+1) {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n]*ifact[k]*ifact[n-k];
  }
};

int main() {
  std::cin.tie(nullptr);
  std::ios_base::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);
  int k;
  cin >> k;
  string s;
  cin >> s;
  int n = s.length();
  combination comb(k+n);
  mint ans = 0;
  rep(x,k+1) {
    ans += mint(25).pow(k-x) * mint(26).pow(x) * comb(n+k-x-1, n-1);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 35656
#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<string>
#include<algorithm>
#include<vector> 
#include<limits>
#include<numeric>
#include<type_traits>
#include<math.h>
#include<fstream>
#include<set>
#include<queue>
using namespace std;
typedef long long ll;

const ll MOD = 1e9 + 7; 

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repi(i,a,b) for(int i = (int)(a); i < (int)(b); i++)
#define out(str) cout << str << endl
#define ALL(a) (a).begin(),(a).end()
#define INF_INT (1<<30)
#define INF_LL (1ll<<62)

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

int N;

int main(){
    cin>>N;
    int A[N];
    rep(i,N)cin>>A[i];
    rep(i,N){
        if(A[i]%2==0){
            if(A[i]%3!=0&&A[i]%5!=0){
                out("DENIED");
                return 0;
            }
        }
    }
    out("APPROVED");
    
    
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define Re read()
#define f(i,a,b) for(register int i=a;i<=b;++i)
#define fd(i,a,b) for(register int i=a;i>=b;--i)
using namespace std;
typedef long long ll;
const int N = 1e6;

inline int read(int n=0) {
    register char ch;while(!isdigit(ch=getchar()));
    for(n=ch^48;isdigit(ch=getchar());n=(n<<3)+(n<<1)+(ch^48));return n;
}
ll n,s;
int main() {
	cin>>n;
	int s=sqrt(n)+1;
	while(--s) if(n%s==0){
			cout<<s+n/s-2;
			return 0;
		}
    return 0;
}

Measured memory_bytes: 256
from sys import stdin

n, m = [int(x) for x in stdin.readline().rstrip().split()]
a = [int(x) for x in stdin.readline().rstrip().split()]

lb = -1
ub = 1e+09 + 3
total_money = sum(a)

while ub - lb > 1:
    mid = (lb + ub) // 2
    count = 0
    ac = a[:]
    for i in range(len(ac)):
        while ac[i] > mid:
            if ac[i] == 0:
                break
            ac[i] //= 2
            count += 1
        if count > m:
            break
    if count > m:
        lb = mid
    else:
        ub = mid
        ac.sort(reverse=True)
        if count < m:
            for i in range(m-count):
                if i >= n:
                    break
                ac[i] //= 2
        total_money = sum(ac)


print(total_money)

Measured memory_bytes: 20288
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <bitset>
#include <vector>
#include <complex>
#include <algorithm>
using namespace std;
typedef long long ll;
typedef double db;
typedef pair<int,int> pii;
typedef vector<int> vi;
#define de(x) cout << #x << "=" << x << endl
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define fi first
#define se second
const int N = 501010;
int n , m , u , v , c;
vector<pii> V;
int l[N] , r[N] , Co[N] , vis[N];
ll dis[N];
vector<pii> g[N];
 
int main(){
    scanf("%d%d",&n,&m);
    rep(i,0,m){
        scanf("%d%d%d",&u,&v,&c);
        --u;--v;
        l[i] = u , r[i] = v , Co[i] = c;
        V.pb(mp(u , c));
        V.pb(mp(v , c));
    }
    sort(all(V));V.erase(unique(all(V)) , V.end());
    rep(i,0,m){
        u = lower_bound(all(V) , mp(l[i] , Co[i])) - V.begin();
        v = lower_bound(all(V) , mp(r[i] , Co[i])) - V.begin();
        g[n + u].pb(mp(n + v , 0));
        g[n + v].pb(mp(n + u , 0));
    }
    rep(i,0,sz(V)) g[V[i].fi].pb(mp(n + i , 1)) , g[n + i].pb(mp(V[i].fi , 1)) , dis[i + n] = 1ll<<62;
    rep(i,0,n) dis[i] = 1ll<<62;
    priority_queue<pair<ll,int> > PQ;
    dis[0] = 0;
    PQ.push(mp(0 , 0));
    while(sz(PQ)){
        int c = PQ.top().se;PQ.pop();
        if(!vis[c]){
            vis[c] = true;
            for(auto e : g[c]){
                ll ndis = dis[c] + e.se;
                if(ndis < dis[e.fi]){
                    dis[e.fi] = ndis;
                    PQ.push(mp(-ndis , e.fi));
                }
            }
        }
    }
    if(dis[n-1] == 1ll<<62) puts("-1");
    else printf("%lld\n",dis[n-1] / 2);
    return 0;
}

Measured memory_bytes: 46316
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()

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

  int n = s.size();
  rep(i, n) {
    int t = ('z' - s[i] + 1) % 26;
    if (t <= k) {
      k -= t;
      s[i] = 'a';
    } else {
      continue;
    }
  }
  k %= 26;
  s[n - 1] = (char)(s[n - 1] + k);

  cout << s << endl;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
#define REP(i,n) for(long long i=0;i<(n);i++)
#define REP1(i,n) for(long long i=1;i<=(n);i++)
#define REP2D(i,j,h,w) for(long long i=0;i<(h);i++) for(long long j=0;j<(w);j++)
#define REP2D1(i,j,h,w) for(long long i=1;i<=(h);i++) for(long long j=1;j<=(w);j++)
#define PER(i,n) for(long long i=((n)-1);i>=0;i--)
#define PER1(i,n) for(long long i=(n);i>0;i--)
#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define FORE(i,a,b) for(long long i=(a);i<=(b);i++)
#define ITE(arr) for(auto ite=(arr).begin();ite!=(arr).end();++ite)
#define ALL(a) ((a).begin()),((a).end())
#define RANGE(a) (a),((a)+sizeof(a))
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
#define YNPRT(b) cout<<((b)?"Yes":"No")<<endl
#define ENTER printf("\n")
#define REV(arr) reverse(ALL(arr))
#define PRT(a) cout<<(a)<<endl

#ifdef DEBUG
#define DBPRT(a) cout << "[Debug] - " << #a << " : " << (a) << endl
#define DBSTART if(1){
#define DBEND }
#define PRTLST(arr,num) REP(_i,num) cout<<_i<<" - "<<arr[_i]<<endl;
#define PRTLST2(arr2,d1,d2) REP(_i,d1) REP(_j,d2) cout<<_i<<","<<_j<<" : "<<arr2[_i][_j]<<endl;
#define PRTLST2D(arr2,d1,d2) do{cout<<"L\t";REP(_i,d2) cout<<_i<<"\t"; cout<<endl; REP(_i,d1){cout<<_i<<"\t";REP(_j,d2){cout<<arr2[_i][_j]<<"\t";}cout<<endl;}}while(0);
#else
#define DBPRT(a) if(0){}
#define DBSTART if(0){
#define DBEND }
#define PRTLST(arr,num) if(0){}
#define PRTLST2(arr2,d1,d2) if(0){}
#define PRTLST2D(arr2,d1,d2) if(0){}
#endif

#define TOSUM(arr,sum,n) {sum[0]=arr[0];REP1(i,n-1) sum[i]=sum[i-1]+arr[i];}

#define MIN(target,v1) (target)=min(target,v1)
#define MAX(target,v1) (target)=max(target,v1) 
#define P1 first
#define P2 second
#define PB push_back
#define UB upper_bound
#define LB lower_bound
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const int INF_INT = 2147483647;
const ll INF_LL = 9223372036854775807LL;
const ull INF_ULL = 18446744073709551615Ull;
const ll P = 92540646808111039LL;
const int Move[4][2] = {-1,0,0,1,1,0,0,-1};
const int Move_[8][2] = {-1,0,-1,-1,0,1,1,1,1,0,1,-1,0,-1,-1,-1};
template<typename T1,typename T2>
ostream& operator<<(ostream& os,const pair<T1,T2>& p) {os<<"( "<<p.P1<<" , "<<p.P2<<" )";return os;}
template<typename T>
ostream& operator<<(ostream& os,const vector<T>& v) {ITE(v) os << (ite-v.begin()) << " : " << *ite <<endl;return os;}
template<typename T>
ostream& operator<<(ostream& os,const set<T>& v) {os<<" { ";ITE(v) {os<<*ite;if(ite!=--v.end()){os<<" , ";}} os<<" } ";return os;}
template<typename T1,typename T2>
ostream& operator<<(ostream& os,const map<T1,T2>& m) {ITE(m) {os<<ite->P1<<"\t\t|->\t\t"<<ite->P2<<endl;} return os;}

//---------------------
#define MAXN 100000
//---------------------

ll a,b;

int main(){
	cin >> a >>b;
	ll res = -1;
	REP1(i,2000){
		if( ((i*8)/100) == a && ((i)/10) == b)
			{res = i;break;}
	}
	PRT(res);
	return 0;
}









Measured memory_bytes: 256
#define _USE_MATH_DEFINES

#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <utility>
#include <climits>
#include <vector>
#include <map>
#include <queue>
#include <set>
using namespace std;

#define ll long long
const int MOD = 1000000007;//10^9+7
const string SPACE = " ";

ll powsur(ll a, ll b, ll p) {

	if (b == 0) {

		return 1;

	}
	else if (b % 2 == 0) {

		ll d = powsur(a, b / 2, p);
		return ((d%p)*(d%p)) % p;

	}
	else {

		return ((a%p)*powsur(a, b - 1, p) % p) % p;

	}

}
//pは素数,aのb乗をpで割った余り

ll CMOD(ll n, ll r, ll p) {

	ll a = 1, b = 1, c = 1, re;
	for (int i = 1; i <= n; i++) {

		a *= i;
		a = a%p;

	}
	for (int i = 1; i <= r; i++) {

		b *= i;
		b = b%p;

	}
	for (int i = 1; i <= n - r; i++) {

		c *= i;
		c = c%p;

	}
	b = powsur(b, p - 2, p);
	c = powsur(c, p - 2, p);
	re = ((a%p)*(b%p)) % p;
	re = ((re%p)*c%p) % p;

	return re;

}
//pは素数,(nCr)%p

ll gcd(ll a, ll b) {

	if (a > b) {

		ll tmp = a;
		a = b;
		b = tmp;

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

}
//最大公約数

ll lcm(ll a, ll b) {

	return (a / gcd(a, b))*b;

}
//最小公倍数

ll MAX(ll a, ll b) {

	if (a > b)return a;
	else return b;

}
//MAX

int main() {

	ll A, B, C, X, ans = 0;

	cin >> A >> B >> C >> X;

	for (int i = 0; i <= A; i++) {
		for (int j = 0; j <= B; j++) {
			for (int k = 0; k <= C; k++) {

				if (500 * i + 100 * j + 50 * k == X)ans++;

			}
		}
	}

	cout << ans << endl;

	return 0;
}

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

#define MAX 1000
#define VMAX 10000

int n,A[MAX],s,B[MAX],T[VMAX+1];

int partition(int A[],int p,int r){
  int i,j,x,t;
  x=A[r];
  i=p-1;
  for(j=p;j<r;j++){
    if(A[j]<=x){
      i=i+1;
      t=A[i];
      A[i]=A[j];
      A[j]=t;
    }
  }
  t=A[i+1];
  A[i+1]=A[r];
  A[r]=t;
  return i+1;
}

void quicksort(int A[],int p,int r){
  int q;
  if(p<r){
    q=partition(A,p,r);
    quicksort(A,p,q-1);
    quicksort(A,q+1,r);
  }
}

int solve(){
  int i,S,c,an,ans=0,m,v;
  int V[MAX];

  for(i=0;i<n;i++){
    B[i]=A[i];
    V[i]=0;
  }
  quicksort(B,0,n-1);
  for(i=0;i<n;i++){
    T[B[i]]=i;
  }
  for(i=0;i<n;i++){
    if(V[i])continue;
    c=i;
    S=0;
    m=VMAX;
    an=0;
    while(1){
      V[c]=1;
      an++;
      v=A[c];
      m=fmin(m,v);
      S+=v;
      c=T[v];
      if(V[c])break;
    }
    ans+=fmin(S+(an-2)*m,m+S+(an+1)*s);
  }
  return ans;
}

int main(){
  int i,ans;

  scanf("%d",&n);
  s=VMAX;
  for(i=0;i<n;i++){
    scanf("%d",&A[i]);
    s=fmin(s,A[i]);
  }
  ans=solve();
  printf("%d\n",ans);

  return 0;
}



Measured memory_bytes: 2108
local function q(i)
	print(i)
	io.flush()
	local s=io.read()
	if s=="Vacant" then
		os.exit()
	else
		return s
	end
end

local n=io.read("n","l")
local l=0
local r=n-1
local sl=q(l)
local sr=q(r)
while true do
	local m=(l+r)//2
	local sm=q(m)
	local checker=false
	if l%2==m%2 and sl~=sm then
		checker=true
	end
	if l%2~=m%2 and sl==sm then
		checker=true
	end
	if checker then
		r=m
		sr=sm
	else
		l=m
		sl=sm
	end
end


Measured memory_bytes: 3836
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) for (int i = 0; i < (n); i++)
#define ALL(a) (a).begin(), (a).end()

int main() {
    int D, N;
    cin >> D >> N;
    if (N == 100) N++;
    if (D == 0) cout << N << endl;
    else if (D == 1) cout << N * 100 << endl;
    else cout << N * 10000 << endl;
    return 0;
}

Measured memory_bytes: 764
Num = int(input())
data = list(map(int, input().split()))
judge = 0
for i in range(Num):
    if data[i] % 2 == 0:
        if not((data[i] % 3 == 0) or (data[i] % 5 == 0)):
            print("DENIED")
            judge = 1
            break
if judge == 0:
    print("APPROVED")

Measured memory_bytes: 3060
from fractions import gcd

a, b, c, d = map(int, input().split())
n = b-a+1
lcm = c*d//gcd(c,d)

ac=(a-1)//c
ad=(a-1)//d
alcm=(a-1)//lcm

bc=b//c
bd=b//d
blcm=b//lcm

print(n-((bc-ac)+(bd-ad)-(blcm-alcm)))


Measured memory_bytes: 5076
#include<bits/stdc++.h>
using namespace std;
int main()
{
   long long a,b,i,c=0;
   string s;
    cin>>s;
    for(i=0;i<s.size();i++)
    {
      if(s[i]=='2') c++;
    }
    cout<<c<<endl;


  return 0;
}


Measured memory_bytes: 3596
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <cmath>
#include <ctime>
#include <cassert>
#include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <deque>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <iterator>
#include <functional>
#include <utility>
#include <algorithm>
#include <numeric>
#include <typeinfo>

using namespace std;

#define dump(n) cout<<"# "<<#n<<"="<<(n)<<endl
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,n) repi(i,0,n)
#define iter(c) __typeof((c).begin())
#define foreach(i,c) for(iter(c) i=(c).begin();i!=(c).end();++i)
#define allof(c) (c).begin(),(c).end()
#define mp make_pair

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<string> vs;
typedef pair<int,int> pii;

typedef vector<vvd> vvvd;

double calc(int h,int n,int add,vi& bars,int start)
{
	vi bcount(h+1);
	for(int i=h;i>=0;i--)
		bcount[i]=(bars[i]==-1)+(i==h?0:bcount[i+1]);
	
	vvvd dp(h+1,vvd(n,vd(add+1)));	// [i][j][drawed_line]
	dp[0][start][0]=1;
	repi(i,1,h+1){
		if(bars[i]!=-1){
			dp[i]=dp[i-1];
			swap(dp[i][bars[i]],dp[i][bars[i]+1]);
			continue;
		}
		rep(j,n) rep(k,add){
			double p=1.0/(n-1)*(add-k)/bcount[i];
			if(bcount[i]<(add-k))
				continue;
			if(j>0)
				dp[i][j][k+1]+=dp[i-1][j-1][k]*p;
			if(j<n-1)
				dp[i][j][k+1]+=dp[i-1][j+1][k]*p;
			dp[i][j][k+1]+=dp[i-1][j][k]*p*(n-1-((j>0)+(j<n-1)));
		}
		rep(j,n) rep(k,add+1)
			dp[i][j][k]+=dp[i-1][j][k]*(1-(double)(add-k)/bcount[i]);
	}
	
	double res=0;
	rep(i,n)
		res=max(res,dp[h][i][add]);
	return res;
}

int main()
{
	for(int h,n,p,m,k;cin>>h>>n>>p>>m>>k && h|n|p|m|k;){
		vi bars(h+1,-1);
		rep(i,m){
			int a,b; cin>>a>>b;
			bars[a]=b-1;
		}
		
		reverse(1+allof(bars));
		printf("%.10f\n",calc(h,n,k,bars,p-1));
	}
	
	return 0;
}

Measured memory_bytes: 0
import java.util.Scanner;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] p = new int[N + 1];
        int cnt = 0;
        for (int i = 1; i <= N; i++) {
            p[i] = sc.nextInt();
            if (p[i] != i) {
                cnt++;
            }
        }
        if (cnt < 3) {
            System.out.println("YES");
        } else {
            System.out.println("NO");
        }
    }
}


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

int main()
{
    int n;
    cin >> n;
    vector<int> a(n);
    int sum = 0;
    for(int i = 0; i < n; i++) cin >> a[i];
    sort(a.begin(), a.end());
    for(int i = 0; i < n; i++) {
        int cnt = 1;
        if(a[i] == a[i+1]){
            while(a[i] == a[i+1]){
                cnt++;
                i++;
            }
        }
        sum += cnt%2;
    }
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define ll long long
#define mp make_pair
#define pb push_back
#define INF 0x3f3f3f3f
using namespace std;
int a,b,k,t;
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cin>>a>>b>>k;
	for (int i=min(a,b);i>=1;--i)
	{
		if (a%i==0 && b%i==0) t++;
		if (t==k)
		{
			cout<<i;
			return 0;
		}
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;

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

    vector<int> d(n);
    rep(i, n) {
        cin >> d[i];
    }

    int ans = 0;
    rep(i, n) {
        rep(j, n) {
            if(i == j) {
                continue;
            }
            ans += d[i]*d[j];
        }
    }

    ans /= 2;

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

Measured memory_bytes: 256
#include  <iostream>
#include  <stdio.h>
#include <algorithm>
#include <map>
#include <math.h>

using namespace std;
#include <vector>
#define rep(i,n) for (int i = 0; i < (n) ; i++)
#define INF 1e9
#define llINF 1e18
#define base10_4 10000      //1e4
#define base10_5 100000     //1e5
#define base10_6 1000000    //1e6
#define base10_7 10000000   //1e7
#define base10_8 100000000  //1e8
#define base10_9 1000000000 //1e9
#define MOD      1000000007
#define pb push_back
#define ll long long
#define ull unsigned long long
#define vint vector<int>
#define vll vector<ll>

//#include <stack>
//#include <queue>

string ans_Yes = "Yes"; 
string ans_No = "No"; 
string ans_yes = "yes"; 
string ans_no = "no"; 

ll A;
ll B;
ll C;
ll N;
ll M;
ll K;

ll getPower(ll value,ll shisu,ll mod){
    ll ans = 1;
    ll cnt = shisu;
    while(cnt>0){
        if(cnt%2==1){
            ans = ans * value % mod;
        }
        value = value * value % mod;
        cnt = cnt/2;
    }
    return (ans+MOD)%MOD;
}
ll modDivision(ll warukazu,ll mod=MOD){
    //mod is prime number
    return getPower(warukazu,MOD-2,MOD);
}


ll a,b;
ll c;
int main(){

    
    cin >> N;
    cin >> a;
    cin >> b;

    if(N==2){
        cout << 0 << endl;
    }else{
        ll nca,ncb;

        nca = 1;
        c = 1;
        for( int ni = 1 ; ni <=a ; ni++ ){
            //nca = nca * (N-(ni-1)) * modDivision(ni,MOD);
            //nca = nca + MOD;
            //nca = nca % MOD;
            nca = nca * (N-(ni-1)) % MOD;
            c = c * ni % MOD;
        }
        ncb = nca;
        nca = nca * modDivision(c,MOD) % MOD;

        for( int ni = a+1 ; ni <=b ; ni++ ){
            //ncb = ncb * (N-(ni-1)) * modDivision(ni,MOD);
            //ncb = ncb + MOD;
            //ncb = ncb % MOD;
            ncb = ncb * (N-(ni-1)) % MOD;
            c = c * ni % MOD;
        }
        ncb = ncb * modDivision(c,MOD) % MOD;

        //nca = (nca + MOD) % MOD;
        //ncb = (ncb + MOD) % MOD;

        ll ans=0;
        ans = -1;
        ans = ans + getPower(2,N,MOD);
        //cout << ans << endl;
        //cout << nca << endl;
        //cout << ncb << endl;
        ans = ans - nca;
        ans = ans + MOD;
        ans = ans % MOD;
        ans = ans - ncb;
        ans = ans + MOD;
        ans = ans % MOD;
        cout << ans << endl;
    }
}

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

//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx")

#define endl "\n"
#define fi first
#define se second
#define pb push_back
#define last(s) (s)[int((s).size())-1]
#define prelast(s) (s)[int((s).size())-2]
#define all(a) (a).begin(),(a).end()
#define elif else if
#define left asdasd
#define next zaza
#define prev azaz
#define cclear cout<<flush;
#define x0 kerker
#define time chas
#define y0 lolik
#define kchay ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define files freopen("roads.in", "r", stdin);freopen("roads.out", "w", stdout);
#define ref svyazi
// #define int long long //
#define real nihuya
using namespace std;
//using namespace __gnu_cxx;


using llong = long long;
using ld = long double;
using itn = int;
using ii = pair<int,int>;
using ull = unsigned long long;
using psi = pair<string, int>;
using ll = pair<llong, llong>;

const llong over999 = 1e9;
const ld over999ld = 1e18+1;
const llong md = 1e9+7;
const ld EPS = 1e-2;
const ld Pi = acos(-1);
const ld nich = 0;
const llong mnogo = 300;

/**/

string s;
set<string> all;
int cnt, k;

int32_t main() {
    kchay;
    // files;
    cin >> s;
    cin >> k;
    for(int i = 0; i < s.length(); ++i){
        string now = "";
        for(int j = i; j < min(i + 6, (int)s.length()); ++j){
            now += s[j];
            all.insert(now);
        }
    }
    
    for(auto i : all){
        k--;
        if(!k)return cout << i, 0;
    }
    
    
    return 0;
}

Measured memory_bytes: 2176
#include<iostream>
#include<algorithm>
#include<functional>
#include<cmath>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<map>
using namespace std;
#define ll long long
const int mod = 1000000007;
const ll INF = 1000000000000000000;

int digitsum(int x) {
	int num = 0;
	while (x) {
		num += x % 10;
		x /= 10;
	}
	return num;
}
int main()
{
	int N, A, B;
	cin >> N >> A >> B;
	int ans = 0;
	for (int i = 1; i <= N; i++) {
		if (digitsum(i) >= A && digitsum(i) <= B) ans += i;
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
import java.util.Collections;
import java.util.Map;
import java.util.TreeMap;

public class Main {

	private BufferedReader in = new BufferedReader(new InputStreamReader(
			System.in));

	public static void main(String[] args) {
		Main wordcount = new Main();
		String[] words = wordcount.input();
		Map<String, ArrayList<Integer>> entries = wordcount.count(words);
		wordcount.print(entries);
	}

	/**
	 * 出現位置を保存
	 */
	private Map<String, ArrayList<Integer>> count(String[] entries) {
		Map<String, ArrayList<Integer>> map = new TreeMap<String, ArrayList<Integer>>();
		for (int i = 0; i < entries.length; i += 2) {
			if (entries[i].equals(""))
				continue;
			List<Integer> index;
			if ((index = map.get(entries[i])) == null) {
				ArrayList<Integer> list = new ArrayList<Integer>();
				list.add(Integer.parseInt(entries[i + 1]));
				map.put(entries[i], list);
			} else {
				index.add(Integer.parseInt(entries[i + 1]));
			}
		}
		return map;
	}

	/**
	 * 単語＋改行＋indexで出力
	 */
	private void print(Map<String, ArrayList<Integer>> map) {
		for (String str : map.keySet()) {
			List<Integer> list = map.get(str);
			Collections.sort(list);
			System.out.print(str + "\n" + list.get(0));
			for (int i = 1; i < list.size(); i++) {
				System.out.print(" " + list.get(i));
			}
			System.out.println();
		}
	}

	/**
	 * 標準入力から読み込んだ文字列を空白区切りで分割
	 */
	private String[] input() {
		String str = null;
		try {
			str = in.readLine();
			while (true) {
				String input = in.readLine();
				if (input == null)
					break;
				str = str + " " + input;
			}
		} catch (IOException e) {
			e.printStackTrace();
		}
		if (str == null)
			return new String[0];
		else
			return str.toLowerCase().split("\\s+");
	}
}

Measured memory_bytes: 17244
while 1:
  n,m= map(int, input().split())
  if n==0 and m==0:
    break
  A = list(map(int, input().split()))
  B = []
  for i in range(n):
    for j in range(1+i,n):
      b = A[i]+A[j]
      B.append(b)
  #print(B)

  B = sorted(B, reverse=1)
  #print(B)
  B = [x for x in B if x <= m]
  print(B[0] if len(B) > 0 else "NONE")


Measured memory_bytes: 31844
a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())
l = [10]
if a % 10 > 0:
    l = l + [a % 10]
if b % 10 > 0:
    l = l + [b % 10]
if c % 10 > 0:
    l = l + [c % 10]
if d % 10 > 0:
    l = l + [d % 10]
if e % 10 > 0:
    l = l + [e % 10]
m = min(l)
ma = 10 - m
ls =[]
ls = ls + [-(-a // 10) * 10]
ls = ls + [-(-b // 10) * 10]
ls = ls + [-(-c // 10) * 10]
ls = ls + [-(-d // 10) * 10]
ls = ls + [-(-e // 10) * 10]
s = sum(ls)
print(s -ma)

Measured memory_bytes: 3064