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

long long max(long long a,long long b){
  if(a > b){
    return a;
  }
  return b;
}

long long min(long long a,long long b){
  if(a < b){
    return a;
  }
  return b;
}

int main(void){
  long H,W;
  long long ans;
  long long Sa,Sb,Sc;
  scanf("%ld%ld",&H,&W);

  if(W%3 == 0 || H%3 == 0) ans = 0;
  else ans = min(H,W);

  for(long i = 1;i < H;i++){
    Sa = i*W;
    Sb = (H-i)*(W/2);
    Sc = (H-i)*(W-W/2);

    ans = min(ans,max(Sa,max(Sb,Sc))-min(Sa,min(Sb,Sc)));

    if(i < H-1){
      Sa = i*W;
      Sb = (H-i)/2*W;
      Sc = H*W-Sa-Sb;

      ans = min(ans,max(Sa,max(Sb,Sc))-min(Sa,min(Sb,Sc)));
    }
  }

  long tmp = H;
  H = W;
  W = tmp;

  for(long i = 1;i < H;i++){
    Sa = i*W;
    Sb = (H-i)*(W/2);
    Sc = (H-i)*(W-W/2);

    ans = min(ans,max(Sa,max(Sb,Sc))-min(Sa,min(Sb,Sc)));

    if(i < H-1){
      Sa = i*W;
      Sb = (H-i)/2*W;
      Sc = H*W-Sa-Sb;

      ans = min(ans,max(Sa,max(Sb,Sc))-min(Sa,min(Sb,Sc)));
    }
  }

  printf("%lld\n",ans);
  return 0;
}

Measured memory_bytes: 128
from fractions import gcd

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

a = A[0]
n = 1
while a % 2 == 0:
    n *= 2
    a //= 2

lcm = 1
for a in A:
    if a % n != 0 or a % (2 * n) == 0:
        print(0)
        exit()
    lcm = lcm * a // gcd(lcm, a)
    if lcm // 2 > M:
        print(0)
        exit()

print((M - lcm // 2) // lcm + 1)


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

int main(){
    int x[25565];
    x[0] = 1;
    int i = 1;
    while(x[i-1] != 0){
        cin >> x[i];
        i++;
    }
    i = 1;
    while(x[i] != 0){
        cout << "Case " << i << ": " << x[i] << endl;
        i++;
    }
}

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

int main() {
  long long n, d, x,y,flag=0,sum=0, mod=1e9+7;
  cin>>n>>d;
  vector<vector<int >> zahy(n, vector<int>(d));
  rep(i,n){
    rep(j,d){
    cin>>zahy.at(i).at(j);
    }
  }
    
  
 
  for(int i=0; i<n-1; i++){
    for(int j=i+1 ; j<n;j++){
      for(int k=0; k<d; k++){
        
        x=zahy.at(i).at(k)-zahy.at(j).at(k);
        sum+=x*x;
      }
      for(int k=0; k<160; k++){
        if(sum==k*k)
          flag++;
      }
      sum=0;
    }
  }


        
  
  cout<<flag<<endl;
   
  
  
  
}

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

int main(void)
{
	char str[21] = {"\0"};
	char str_R[21] = {"\0"};
	int i, len;

	scanf("%s", &str);

	len = strlen(str);

	for(i = 0; i < len; ++i)
	{
		str_R[i] = str[len - i - 1];
	}
	printf("%s\n", str_R);

	return 0;
}

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

using namespace std;

int main(){

    int N;
    cin >> N;

    int ans = 0;
    for(int i = 1; i <= N; i+=2){
        int count = 0;
        for(int j = 1; j <= i; j++){
            if(i % j == 0) count ++;
        }
        if(count == 8) ans += 1;
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

//INSERT ABOVE HERE
signed main(){
  Int n,m;
  cin>>n>>m;
  vector<Int> as(m),bs(m),cs(m,0);

  const Int INF = 1e9;
  Int s=1<<n;
  vector<Int> dp(s,INF);
  dp[0]=0;

  for(Int i=0;i<m;i++){
    cin>>as[i]>>bs[i];
    for(Int j=0;j<bs[i];j++){
      Int k;
      cin>>k;
      k--;
      cs[i]|=1<<k;
    }

    vector<Int> nx(s,INF);
    for(Int b=0;b<s;b++){
      chmin(nx[b],dp[b]);
      chmin(nx[b|cs[i]],dp[b]+as[i]);
    }

    swap(dp,nx);
  }

  if(dp[s-1]==INF) dp[s-1]=-1;
  cout<<dp[s-1]<<endl;
  return 0;
}


Measured memory_bytes: 384
n = int(input())
A = [[int(num) for num in input().split()], [int(num) for num in input().split()]]
P = [0] * n

for shita_time in range(0, n):
  point = sum(A[0][:shita_time + 1]) + sum(A[1][shita_time:])
  P[shita_time] = point
print(max(P))

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

using namespace std;
typedef long long ll;
typedef pair<ll, ll> p_ll;

template<class T>
void debug(T itr1, T itr2) { auto now = itr1; while(now<itr2) { cout << *now << " "; now++; } cout << endl; }
#define repr(i,from,to) for (ll i=(ll)from; i<(ll)to; i++)
#define all(vec) vec.begin(), vec.end()
#define rep(i,N) repr(i,0,N)
#define per(i,N) for (int i=(int)N-1; i>=0; i--)

const ll MOD = pow(10,9)+7;
const ll LLINF = pow(2,61)-1;
const int INF = pow(2,30)-1;

vector<ll> fac;
void c_fac(int x=pow(10,6)+10) { fac.resize(x,true); rep(i,x) fac[i] = i ? (fac[i-1]*i)%MOD : 1; }
ll inv(ll a, ll m=MOD) { ll b = m, x = 1, y = 0; while (b!=0) { int d = a/b; a -= b*d; swap(a,b); x -= y*d; swap(x,y); } return (x+m)%m; }
ll nck(ll n, ll k) { return fac[n]*inv(fac[k]*fac[n-k]%MOD)%MOD; }
ll gcd(ll a, ll b) { if (a<b) swap(a,b); return b==0 ? a : gcd(b, a%b); }
ll lcm(ll a, ll b) { return a/gcd(a,b)*b; }


int main() {
  ll N; cin >> N;
  string c; cin >> c;
  ll r[N]; rep(i,N) r[i] = c[i]=='R';
  ll sum[N] = {}; rep(i,N) sum[i] = i==0 ? r[i] : sum[i-1] + r[i];
  ll result = sum[N-1];
  repr(i,1,N) {
    // cout << i+1-sum[i] << " " << sum[N-1]-sum[i] << endl;
    if (i+1-sum[i]>sum[N-1]-sum[i]) break;
    result = min(result, sum[N-1]-sum[i]);
  }
  cout << result << endl;
  // debug(sum,sum+N);
  return 0;
}

Measured memory_bytes: 6844
//#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>
#define MAX_INT 2100000000
using namespace std;
typedef long long int ll;
#ifdef COMPILE_IN_VCPP
#include <windows.h>
HWND GetConsoleHwnd(void)
{
#define MY_BUFSIZE 1024 // Buffer size for console window titles.
	HWND hwndFound;         // This is what is returned to the caller.
	char pszNewWindowTitle[MY_BUFSIZE]; // Contains fabricated// WindowTitle.
	char pszOldWindowTitle[MY_BUFSIZE]; // Contains original// WindowTitle.
	// Fetch current window title.
	GetConsoleTitle(pszOldWindowTitle, MY_BUFSIZE);
	// Format a "unique" NewWindowTitle.
	wsprintf(pszNewWindowTitle, "%d/%d",GetTickCount(),GetCurrentProcessId());
	// Change current window title.
	SetConsoleTitle(pszNewWindowTitle);
	// Ensure window title has been updated.
	Sleep(40);
	// Look for NewWindowTitle.
	hwndFound = FindWindow(NULL, pszNewWindowTitle);
	// Restore original window title.
	SetConsoleTitle(pszOldWindowTitle);
	return(hwndFound);
}
#endif
int main()
{
#ifdef COMPILE_IN_VCPP
	SetWindowPos(GetConsoleHwnd(), HWND_TOPMOST, 0, 0, 0, 0,
		(SWP_NOMOVE | SWP_NOSIZE | SWP_SHOWWINDOW));
#endif
	int n, k;
	cin >> n >> k;
	cout << n - k + 1 << endl;
}


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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repi(i, s, n) for (int i = (s); i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define debug(x) cerr << #x << ": " << x << '\n'

typedef long long int ll;
typedef pair<int, int> P;

const long long INF = 3e18 + 12;
const int inf = 1e9;

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

  int a, b;
  string p;
  cin >> a >> p >> b;

  if (p == "+") {
    cout << a + b << endl;
  } else {
    cout << a - b << endl;
  }

  return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main{
	public static void main(String[] args) {
	Scanner scan=new Scanner(System.in);
	int x,t;
	x=scan.nextInt();
	t=scan.nextInt();
	int ans=x-t;
	if(ans<0)System.out.println(0);
	else System.out.println(ans);
}
}


Measured memory_bytes: 21204
package main

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

func out(x ...interface{}) {
	fmt.Println(x...)
}

var sc = bufio.NewScanner(os.Stdin)

func getInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func getString() string {
	sc.Scan()
	return sc.Text()
}

// min, max, asub, absなど基本関数
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func asub(a, b int) int {
	if a > b {
		return a - b
	}
	return b - a
}

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

func main() {
	sc.Split(bufio.ScanWords)
	sc.Buffer([]byte{}, 1000000)

	N, C := getInt(), getInt()
	T := make([][]int, C)
	for i := 0; i < C; i++ {
		T[i] = make([]int, 100100)
	}
	for i := 0; i < N; i++ {
		s, t, c := getInt(), getInt(), getInt()-1
		T[c][s]++
		T[c][t+1]--
	}

	for c := 0; c < C; c++ {
		for i := 1; i < 100100; i++ {
			T[c][i] += T[c][i-1]
		}
	}

	ans := 0
	for i := 1; i < 100100; i++ {
		cnt := 0
		for c := 0; c < C; c++ {
			if T[c][i] != 0 {
				cnt++
			}
		}
		ans = max(ans, cnt)
	}

	out(ans)
}


Measured memory_bytes: 26240
N, D = map(int, input().split())

A = [list(map(int, input().split())) for i in range(N)]

P = []
for i in range(N):
    for j in range(i+1, N):
        S = 0
        for k in range(D):
            S += (A[i][k] - A[j][k])**2
        P.append(S)

M = int(max(P)**0.5)
ans = 0

for i in range(1, M+1):
    for j in P:
        if i == j**0.5:
            ans += 1
            
print(ans)

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

using namespace std;

const int INF = 0x0ffffff;

template<typename T>
ostream & operator<<(ostream & os, vector<T> & v)
{
    for (auto e : v){
        os << e << " ";
    }
    os << endl;
    return os;
}

template<typename T>
ostream & operator<<(ostream & os, vector<vector<T>> & v)
{
    for (size_t i = 0; i < v.size(); ++i){
        for (auto e : v[i]){
            os << e << " ";
        }
        os << endl;
    }
    return os;
}


int main()
{
    int n;
    cin >> n;
    if (n % 2 == 0) cout << (n/2 - 1) << endl;
    else cout << (n / 2) << endl;

    return 0;
}

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

typedef long long ll;

int N;
ll a[3001], dp[3001][3001], pref[3001];

ll interval(int i, int j)
{
    return pref[j] - pref[i-1];
}

int main()
{
    scanf("%d", &N);
    for (int i = 1; i <= N; i++)
    {
        scanf("%lld", a + i);
        dp[i][i] = a[i];
        pref[i] = pref[i-1] + a[i];
    }
    for (int g = 1; g <= N; g++)
    {
        for (int i = 1; i <= N; i++)
        {
            if (i + g > N) break;
            dp[i][i+g] = max(a[i] + interval(i+1, i+g) - dp[i+1][i+g], a[i+g] + interval(i, i+g-1) - dp[i][i+g-1]);
        }
    }
    printf("%lld\n", 2LL * dp[1][N] - interval(1,N));
    return 0;
}


Measured memory_bytes: 70016
#include<stdio.h>
int main()
{
	int n,m,i,j,t[101],p[101][3],sum = 0,flag = 0,temp;
	scanf("%d",&n);
	for(i = 0;i < n;i++)
	{
		scanf("%d",&t[i]);
	}
	scanf("%d",&m);
	for(i = 0;i < m;i++)
	{
		for(j = 0;j < 2;j++)
		{
			scanf("%d",&p[i][j]);
		}
	}
	for(i = 0;i < m;i++)
	{
		for(j = 0;j < n;j++)
		{
			if(j + 1 == p[i][0])
			{
				sum = sum + p[i][1];
			}
			else
				sum = sum + t[j];
		}
		printf("%d\n",sum);
		sum = 0;
	}
	return 0;
}


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

using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef pair<int, int> PII;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define MOD 1000000007
#define INF (1LL << 25) // 33554432
#define PI 3.14159265359
#define EPS 1e-12
//#define int ll

signed main(void) {
  while (true) {
    vector<pair<double, string>> co;
    int n, p[55], tb[55], ta[55], s[55], m[55];
    string l[55];
    cin >> n;
    if(!n) break;
    REP(i, n) {
      cin >> l[i] >> p[i];
      int a, b, c, d, e, f;
      cin >> a >> b >> c >> d >> e >> f;
      tb[i] = a + b + c;
      ta[i] = d + e;
      cin >> s[i] >> m[i];
      co.push_back(make_pair(
          ((double)s[i]* f * m[i] - p[i]) / (tb[i] + ta[i] * m[i]), l[i]));
    }
    sort(ALL(co), [](const pair<double, string> &a,
                     const pair<double, string> &b) {
      return (a.first == b.first) ? (a.second < b.second) : (a.first > b.first);
    });
    REP(i, n) { cout << co[i].second << endl; }
    cout << "#" << endl;
  }
  return 0;
}

Measured memory_bytes: 3220
#include <bits/stdc++.h>
#include <stdio.h>
#include <math.h>
using namespace std;
using vi = vector<int>;
using vll = vector<long long int>;
using vb = vector<bool>;
using vvi = vector<vector<int>>;
using vvll = vector<vector<long long int>>;
using ll = long long int;
 
const ll M = 1000000007;
 
vector<ll> fac(300001); //n!(mod M)
vector<ll> ifac(300001); //k!^{M-2} (mod M)
//a,bの範囲的にこれだけ配列を用意していけば十分

ll mpow(ll x, ll n){ //x^n(mod M) ←普通にpow(x,n)では溢れてしまうため，随時mod計算
    ll ans = 1;
    while(n != 0){
        if(n&1) ans = ans*x % M;
        x = x*x % M;
        n = n >> 1;
    }
    return ans;
}

ll comb(ll a, ll b){ //aCbをmod計算
    if(a == 0 && b == 0)return 1;
    if(a < b || a < 0)return 0;
    ll tmp = ifac[a-b]* ifac[b] % M;
    return tmp * fac[a] % M;
}

int main(){
    fac[0] = 1;
    ifac[0] = 1;
    for(ll i = 0; i<300000; i++){
        fac[i+1] = fac[i]*(i+1) % M; // n!(mod M)
        ifac[i+1] = ifac[i]*mpow(i+1, M-2) % M; // k!^{M-2} (mod M) ←累乗にmpowを採用
    }
    ll N, K; cin >> N >> K;
    if(N==K){
        for(int i=1; i<K+1; i++){
            if(i==1){
                cout << 1 << endl;
            }
            else{
                cout << 0 << endl;
            }
        }
    }
    else{
    for(int i=1; i<K+1; i++){
        if(N-K<i-1){
            cout << 0 << endl;
        }
        else{
            ll res = 0;
            if(N-K>=i+1){
            res += comb(K-1, i-1)*comb(N-K-1,i);
            res %= M;
            }
            if(i>1){
            res += comb(K-1, i-1)*comb(N-K-1,i-2);
            res %= M;
            }
            if(N-K>=i){
            res += 2*comb(K-1, i-1)*comb(N-K-1,i-1);
            res %= M;
            }
            cout << res << endl;
        }
    }
    }
}

Measured memory_bytes: 4992
N,M = map(int,input().split())
point = []
target = []
ans = []
for i in range(N):
    person = list(map(int,input().split()))
    point.append(person)
for j in range(M):
    goal = list(map(int,input().split()))
    target.append(goal)
for k in point:
    check = []
    for l in target:
        a = 0
        a += abs(k[0]-l[0])+abs(k[1]-l[1])
        check.append(a)
    b = min(check)
    ans.append(check.index(b))
for m in ans:
    print(m+1)

Measured memory_bytes: 67984
N,Q=map(int,input().split())
S=input()
T=[0]
L=[]
R=[]
cnt=0
for i in range(Q):
  l,r=map(int,input().split())
  L.append(l)
  R.append(r)

for i in range(1,N):
  if S[i-1:i+1]=="AC":
    cnt=cnt+1
  T.append(cnt)
for j in range(Q):
  print(T[R[j]-1]-T[L[j]-1])

Measured memory_bytes: 14208
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  
  int N, A, B;
  
  cin >> N >> A;
  
  B = N % 500;

  
  if (B == 0) {
  cout << "Yes" << endl;
  }
  
  else if (A >= 500){
    cout << "Yes" << endl;
  }
  
  else if (B <= A){
   cout << "Yes" << endl;
  }
  
  else {
  cout << "No" << endl;
  }
  
  
    
}

Measured memory_bytes: 256
from bisect import bisect_right as br
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")

def main():
    n=int(input())
    aa=list(map(int, input().split()))
    input()
    qq=list(map(int, input().split()))

    ss=set()
    ss.add(0)
    for a in aa:
        nss=set()
        for s in ss:
            nss.add(s)
            nss.add(s+a)
        ss=nss

    for q in qq:
        if q in ss:
            print("yes")
        else:
            print("no")

main()



Measured memory_bytes: 5692
import java.util.ArrayList;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		String S = sc.next();
		long K = Long.parseLong(sc.next());

		sc.close();

		ArrayList<Integer> charLList = new ArrayList<Integer>();
		char lastChar = '0';
		int charL = 1;
		boolean sameChar = true;
		for (int i = 0; i < S.length(); i++) {
			if (S.charAt(i) == lastChar) {
				charL++;
			} else {
				if(sameChar && i != 0) sameChar = false;
				if (charL >= 2) {
					charLList.add(charL);
				}
				charL = 1;
				lastChar = S.charAt(i);
			}
		}
		if (charL >= 2) {
			charLList.add(charL);
		}

		if(sameChar) {
			System.out.println(S.length() * K / 2);
			return;
		}


		if (S.charAt(0) == S.charAt(S.length() - 1)) {
			long naka = 0L;
			for(int i = 1;i < charLList.size() - 1;i++) {
				naka += charLList.get(i) / 2;
			}
			long tunagi = (charLList.get(0) + charLList.get(charLList.size() - 1)) / 2;
			long tl = charLList.get(0) / 2 + charLList.get(charLList.size() - 1) / 2;
			long ret = tl + naka * K + tunagi * (K - 1);
			System.out.println(ret);
		} else {
			long ret = 0;
			for(int i = 0;i < charLList.size();i++) {
				ret += charLList.get(i) / 2;
			}
			System.out.println(ret * K);

		}


	}
}


Measured memory_bytes: 23124
n= int(input())
a = list(map(int,input().split()))
ans = float("inf")
flag_1 = 0
flag_2 = sum(a)
for i in range(n):
  flag_1 += a[i]
  flag_2 -= a[i]
  ans = min(ans,abs(flag_1-flag_2))
print(ans)

Measured memory_bytes: 88272
function Main(input) {
	var input = input.split(" ");
  	if(input[0] < 1 || input[0] > 9 || input[1] < 1 || input[1] > 9){
    	console.log(-1)
    }else{
		console.log(input[0]*input[1]);
    }
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 7372
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
using P = pair<int, int>;
using PL = pair<lint, lint>;
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
#define ALL(a)  (a).begin(),(a).end()
constexpr int MOD = 1000000007;
constexpr int INF = 2147483647;
void yes(bool expr) {
  cout << (expr ? "Yes" : "No") << "\n";
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    lint N;
    cin >> N;
    vector<int> ans(N);
    FOR(x, 1, 101) FOR(y, 1, 101) FOR(z, 1, 101) {
        int val = x*x + y*y + z*z + x*y + y*z + z*x;
        if(val <= N) ans[val-1]++;
    }
    REP(i, N) cout << ans[i] << "\n";
}

Measured memory_bytes: 3680
#include <stdio.h>
#include <stdlib.h>

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

int
main(int argc, char *argv[])
{
  int n, a[100000];
  scanf("%d", &n);
  for(int i = 0; i < n; i++) scanf("%d", &a[i]);

  qsort(a, n, sizeof(int), asc);

  int i = 0, k, l, ans = 0;
  while(i < n){
    k = a[i]; l = 1;
    while(a[i] == a[i + 1]){
      l++;
      i++;
    }
    if(l >= k) ans += l - k;
    else ans += l;
    i++;
  }

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

  return 0;
}


Measured memory_bytes: 892
#include <iostream>
#include <set>
#include <queue>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <cstring>
#include <climits>
#include <sstream>
#include <iomanip>
#include <map>
#include <stack>
#include <numeric>
#include <functional>

using namespace std;
#define ALL(x)              (x).begin(),(x).end()
#define REP(i, n)           for (int (i) = 0 ; (i) < (ll)(n) ; ++(i))
#define REPN(i, m, n)       for (int (i) = m ; (i) < (ll)(n) ; ++(i))
#define INF                 (int)2e9
#define MOD                 (1000 * 1000 * 1000 + 7)
#define Ceil(x, n)          (((((x))+((n)-1))/n))
#define CeilN(x, n)         (((((x))+((n)-1))/n)*n)
#define FloorN(x, n)        ((x)-(x)%(n))
#define IsOdd(x)            (((x)&0x01UL) == 0x01UL)
#define IsEven(x)           (!IsOdd((x)))
#define M_PI                3.14159265358979323846
typedef long long           ll;
typedef pair<ll, ll>        P;

/*-----------------------------------------------------------------------------
　処理
 -----------------------------------------------------------------------------*/
int main()
{
	ll N, W;
	cin >> N >> W;
	vector<ll> w(N, 0);
	vector<ll> v(N, 0);
	REP(i, N) cin >> w[i] >> v[i];

	ll w1 = w[0];
	vector<vector<ll>> wType(4);
	REP(i, N) {
		wType[w[i] - w1].emplace_back(v[i]);
	};
	REP(i, 4) {
		sort(wType[i].rbegin(), wType[i].rend());
	}
	
	vector<vector<ll>> wSum(4);
	REP(i, 4) {
		wSum[i].emplace_back(0);
		REP(j, wType[i].size()) {
			wSum[i].emplace_back(wType[i][j] + wSum[i][j]);
		}
	}

	ll ans = 0;
	REP(i0, wSum[0].size()) {
		REP(i1, wSum[1].size()) {
			REP(i2, wSum[2].size()) {
				REP(i3, wSum[3].size()) {
					ll totalWeight = i0 * w1 + i1 * (w1 + 1) + i2 * (w1 + 2) + i3 * (w1 + 3);
					if (totalWeight <= W) {
						ll ansOne = wSum[0][i0] + wSum[1][i1] + wSum[2][i2] + wSum[3][i3];
						ans = max(ans, ansOne);
					}
				}
			}
		}
	}

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


Measured memory_bytes: 256
package main

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

func main() {
	log.SetFlags(log.Lshortfile)
	N := nextInt()
	M := nextInt()
	mp := map[int]int{}
	mp[0] = 1
	S := 0
	rtn := 0
	for i := 0; i < N; i++ {
		x := nextInt()
		S += x
		rtn += mp[S%M]
		mp[S%M]++
	}
	fmt.Println(rtn)
}
func Max(a ...int) int {
	r := a[0]
	for i := 0; i < len(a); i++ {
		if r < a[i] {
			r = a[i]
		}
	}
	return r
}
func Min(a ...int) int {
	r := a[0]
	for i := 0; i < len(a); i++ {
		if r > a[i] {
			r = a[i]
		}
	}
	return r
}
func Sum(a []int) (r int) {
	for i := range a {
		r += a[i]
	}
	return r
}
func Abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

type Pair struct {
	a, b int
}

type Pairs []Pair

func (p Pairs) Len() int {
	return len(p)
}
func (p Pairs) Swap(i, j int) {
	p[i], p[j] = p[j], p[i]
}

func (p Pairs) Less(i, j int) bool {
	return p[i].b < p[j].b
}

var nextReader func() string

func init() {
	nextReader = NewScanner()
}

func NewScanner() func() string {
	r := bufio.NewScanner(os.Stdin)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)
	return func() string {
		r.Scan()
		return r.Text()
	}
}
func nextString() string {
	return nextReader()
}
func nextInt64() int64 {
	v, _ := strconv.ParseInt(nextReader(), 10, 64)
	return v
}
func nextInt() int {
	v, _ := strconv.Atoi(nextReader())
	return v
}
func nextInts(n int) []int {
	r := make([]int, n)
	for i := 0; i < n; i++ {
		r[i] = nextInt()
	}
	return r
}
func nextFloat64() float64 {
	f, _ := strconv.ParseFloat(nextReader(), 64)
	return f
}


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

int main() {
   ll n,a,b;
   cin>>n>>a>>b;
   ll p=n*a;
   if(p<=b)
   cout<<p<<endl;
   else
   cout<<b<<endl;
   
	return 0;
}

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

int main(){
    int n,k;
    cin>>n>>k;
    // int arr[k];
    unordered_map<int,int>mp;
    for (int i=1;i<=n;++i){
        mp[i]=1;
    }
    for (int i=0;i<k;++i){
        int temp;
        cin>>temp;
        for (int j=0;j<temp;++j){
            int x;
            cin>>x;
            mp[x]++;
        }
    }
    int count = 0;
    for (auto x : mp){
        if (x.second==1){
            count++;
        }
    }
    cout<<count;
    
}

Measured memory_bytes: 3616
import sys
fastinput=sys.stdin.readline
N=int(input())
a=[int(i) for i in fastinput().split()]
result=[None]*N
if N%2:#odd
    c=(N-1)//2
    for num,i in enumerate(a):
        r=(num+1)//2
        if num==0:
            result[c]=i
        else:
            if num%2:#右半分
                result[c+r]=i
            else:
                result[c-r]=i
else:#even
    for num,i in enumerate(a):
        d=(N-num-1)//2
        if num%2:#左半分
            result[d]=i
        else:
            result[N-1-d]=i
print(" ".join([str(j) for j in result]))
            

Measured memory_bytes: 29620
#include <bits/stdc++.h>
#define ALL(obj) begin(obj), end(obj)
#define debug(x) cerr << #x << ": " << x << '\n'
using namespace std;
template <class T>
vector<T> make_vec(size_t a) {
    return vector<T>(a);
}
template <class T, class... Ts>
auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
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;
}

using ll = long long;
using ull = unsigned long long;
const int INF = 1e9;
// const int MOD = 1e9 + 7;

int main() {
    int N, M;
    cin >> N >> M;
    vector<int> H(N);
    for (int i = 0; i < N; i++) {
        cin >> H.at(i);
    }

    vector<vector<int>> G(N);
    for (int i = 0; i < M; i++) {
        int a, b;
        cin >> a >> b;
        a--, b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }

    int cnt = 0;
    for (int i = 0; i < N; i++) {
        int m = 0;
        for (auto b : G[i]) {
            chmax(m, H[b]);
        }
        if (H[i] > m) cnt++;
    }
    cout << cnt << endl;
}


Measured memory_bytes: 8800
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <cmath>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const ll INF = -1e18;
const int I=2001;
int ip() {int x; cin>>x; return x;}

int main(){
  int k; cin>>k;
  int a[k], b[k]; for(int i=0;i<k;i++) a[i]=ip(), b[i]=ip();
  int p[8]={0,1,2,3,4,5,6,7};
  do {
    bool ok=true;
    for(int i=0;i<k;i++)
      if (p[a[i]]!=b[i]) ok=false;
    if (!ok) continue;
    bool mp[8][8]; fill(mp[0], mp[8], false);
    for(int i=0;i<8&&ok;i++) {
      if (mp[i][p[i]]) ok=false;
      else {
        int x[4]={1,1,-1,-1}, y[4]={1,-1,1,-1};
        for(int j=0;j<4;j++) {
          int sx=i+x[j], sy=p[i]+y[j];
          while(0 <= sx && sx < 8 && 0 <= sy && sy < 8) {
            mp[sx][sy]=true;
            sx+=x[j], sy+=y[j];
          }
        }
      }
    }
    if (ok) {
      for(int i=0;i<8;i++) {
        for(int j=0;j<8;j++) {
          if (p[i] == j) cout<<"Q"; else cout<<".";
        } cout<<endl;
      }
      break;
    }
  } while(next_permutation(p,p+8));
}


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

int Rank[1000005];
int Tmp[1000005];
int kc,len;

bool compare_sa(int i,int j){
  return
    Rank[i]!=Rank[j]?
    Rank[i]<Rank[j]:
    (i+kc<=len?Rank[i+kc]:-1)<(j+kc<=len?Rank[j+kc]:-1);
}

void construct_sa(char* S,int *sa){
  len=strlen(S);
  for(int i=0;i<=len;i++){
    sa[i]=i;
    Rank[i]=i<len?S[i]:-1;
  }
  for(kc=1;kc<=len;kc*=2){
    sort(sa,sa+len+1,compare_sa);
    Tmp[sa[0]]=0;
    for(int i=1;i<=len;i++){
      Tmp[sa[i]]=Tmp[sa[i-1]]+compare_sa(sa[i-1],sa[i]);
    }
    for(int i=0;i<=len;i++)Rank[i]=Tmp[i];
  }
}


int n,m;
char str[1000005];
char t[1000005];
int sa[1000005];

int main(){
  scanf("%s",str);
  n=strlen(str);
  construct_sa(str,sa);
  scanf("%d",&m);
  while(m--){
    scanf("%s",t);
    int k=strlen(t);
    int l=0,r=n+1,m;
    while(l+1<r){
      m=(l+r)/2;
      if(strncmp(str+sa[m],t,k)<=0)l=m;
      else r=m;
    }
    printf("%d\n",(strncmp(str+sa[l],t,k)==0));
  }
  return 0;
}



Measured memory_bytes: 15980
A, B, C, D, E, F = map(int, input().split())
con = 0
sugar_water = 0
sugar = 0
for a in range(31):
    for b in range(31):
        if not a == b == 0 and a*A*100 + b*B*100 <= F:
            for c in range(int((F - a*A*100 + b*B*100) / C) + 1):
                for d in range(int((F - a*A*100 + b*B*100 + c*C) / D) + 1):
                    if 100*(A*a+B*b)+C*c+D*d <= F:
                        if (c*C+d*D)/(100*a*A+100*b*B+c*C+d*D) <= E/(100+E):
                            if con <= 100*((c*C+d*D)/(100*a*A+100*b*B+c*C+d*D)):
                                con = 100*((c*C+d*D)/(100*a*A+100*b*B+c*C+d*D))
                                sugar = c*C+d*D
                                sugar_water = 100*a*A+100*b*B+c*C+d*D
print(sugar_water, sugar)

Measured memory_bytes: 45600
/*
  Vivek Rathi
  CSE 2nd Year
  MNNIT
*/
#include<bits/stdc++.h>
using namespace std;
#define M 1000000007
#define ll long long int
#define pb push_back
#define pf push_front
#define pob pop_back
#define pof pop_front
#define debug1(x) cout<<#x<<" "<<x<<endl;
#define debug2(x,y) cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<endl;
#define debug3(x,y,z) cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<" "<<#z<<" "<<z<<endl;
#define present(c,x) ((c).find(x) != (c).end())
#define null NULL
#define mp make_pair
#define fi first
#define se second
#define boost ios_base::sync_with_stdio(false);cin.tie(NULL);
#define inf 1e18
#define flush fflush(stdout);
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
#define ordered_set tree<ll, null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>
ll modpower(ll a,ll b,ll c)
{
	ll res=1;
	while(b)
	{
		if(b&1LL)
			res=(res*a)%c;
		a=(a*a)%c;
		b>>=1;
	}
	return res;
}
//-------------------------------Template--Above------------------------------------------------


int main()
{
	boost
	ll n;
	cin>>n;
	ll a[n],b[n],cp[n],cp2[n];
	for(ll i=0;i<n;i++)
	{
		cin>>b[i];
		cp2[i]=b[i];
	}
	for(ll i=0;i<n;i++)
	{
		cin>>a[i];
		cp[i]=a[i];
	}
	ll co=0;
	while(true)
	{
		for(ll i=0;i<n;i++)
		{
			if(a[i]>b[i]&&a[(i-1+n)%n]<=a[i]&&a[(i+1)%n]<=a[i])
			{
				ll temp=a[i]/(a[(i-1+n)%n]+a[(i+1)%n]);
				ll temp2=(a[i]-b[i])/(a[(i-1+n)%n]+a[(i+1)%n]);
				a[i]-=min(temp,temp2)*(a[(i-1+n)%n]+a[(i+1)%n]);
				co+=min(temp,temp2);
			}
		}
		ll flag=0,flag2=0;
		for(ll i=0;i<n;i++)
		{
			if(a[i]!=b[i])
				flag=1;
			if(a[i]!=cp[i])
				flag2=1;
			cp[i]=a[i];
		}
		if(flag==0)
			break;
		if(flag2==0)
		{
			cout<<-1<<endl;
			return 0;
		}
	}
	cout<<co<<endl;
	return 0;
}


Measured memory_bytes: 6528
N=int(input())
s=0
A=list(map(int,input().split()))
li=[0]*(2*(10**5)+1)
for i in range(N):
    li[A[i]]+=1
for j in range(N+1):
    s+=li[j]*(li[j]-1)//2
for k in range(N):
    print(s-li[A[k]]+1)


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

#define IOS ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define I insert
#define endl '\n'
#define all(x) x.begin(), x.end()

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template<class T> using oset=tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
 
using vvll = vector< vector<ll> >;
using vll = vector<ll> ;
using vb = vector<bool> ;
using pll = pair<ll, ll> ;

const ll maxs = 1e6+5;
const ll lmaxs = 20;
ll mod = 1e9+7;
ll oo = 1e15;

ll fast(ll x,ll y){
    ll res=1;
    while(y){
        if(y&1)
            res = (res*x)%mod;
        x = (x*x)%mod;
        y >>= 1;
    }
    return res;
}

ll inv(ll n){
    return fast(n,mod-2);
}


void pre(){



}

ll go(ll x){
    if(x==1){
        return 1;
    }else{
        return 1+2*go(x/2);
    }
}

void solve(){

    ll x;
    cin >> x;
    ll ans = go(x);
    cout << ans;

}

int main(){
    // #ifndef ONLINE_JUDGE
    // freopen("input00.txt","r",stdin);
    // #endif
    IOS;
    pre();
    ll T = 1;
    //cin>>T;
    while(T--){
        solve();   
    }
    return 0;
}

Measured memory_bytes: 3596
/*
   ~~~~~~~~~~~~~~~~~~~
   \  |\/| | |\ | |  /
   /  |  | | |/ |_|  \
   ~~~~~~~~~~~~~~~~~~~
*/
#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef vector<ll> lve;
typedef vector<char> cve;
typedef vector<pair<ll,ll> > lvp;
typedef vector<pair<string,int> > svp;

#define endl       '\n'
#define F          first
#define S          second
#define pp         pop_back
#define PI         2*acos(0)
#define pb         push_back
#define mp         make_pair
#define GCD(x,y)   __gcd(x,y)
#define lb         lower_bound
#define up         upper_bound
#define bs         binary_search
#define LCM(x,y)   ((x*y)/GCD(x,y))
#define For(i,j,k) for(i=j;i<k;i++)
#define FOR(i,j,k) for(i=j;i>=k;i--)
#define sp(x)      cout<<fixed<<setprecision(x)

const   long long  inf=1e18;
const   long long  mod=1e9+7;
const   long long  cs=200005;
int main()
{	
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);    cout.tie(NULL);
    
    ll t,n,a,b,c,d,e,i,j,k;
 	cin>>t;
 	vector<string>v;
 	string s;
 	while(t--)
 	{
 		cin>>s;
 		v.pb(s);
 	}
 	a=count(v.begin(),v.end(),"AC");
 	b=count(v.begin(),v.end(),"WA");
 	c=count(v.begin(),v.end(),"TLE");
 	d=count(v.begin(),v.end(),"RE");
 	cout<<"AC x "<<a<<endl;
 	cout<<"WA x "<<b<<endl;
 	cout<<"TLE x "<<c<<endl;
 	cout<<"RE x "<<d<<endl;
 	return 0;
}

Measured memory_bytes: 7384
#define	_USE_MATH_DEFINES
#include <iostream>
#include <iomanip>
#include <cctype>
#include <algorithm>
#include <functional>
#include <vector>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cfloat>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <string>
#include <set>
#include <complex>
#include <utility>
#include <numeric>
#include <bitset>
using namespace std;
const int INF=1<<30;

typedef pair<int,int> P;



int main(){
	
	int t,p,r;
	while(cin>>t>>p>>r,t!=0&&p!=0&&r!=0){
		vector< P > team(t);
		int problem[51][11]={0};
		int a,b,c;
		string s;
		for(int i=0;i<r;i++){
			cin>>a>>b>>c>>s;
			if(s=="WRONG"){
				problem[a][b]++;
			}
			else {
				team[a-1].first++;
				team[a-1].second+=problem[a][b]*1200+c;
			}
		}
		int q=t;
		while(q--){
		int k=0;
		int maxp=-1,maxtime=-1;
		for(int i=0;i<t;i++){
			if(maxp<team[i].first){
				k=i+1;
				maxp=team[i].first;
				maxtime=team[i].second;
			}
			else if(maxp==team[i].first&&maxtime>team[i].second){
				k=i+1;
				maxtime=team[i].second;
				
			}
		}
			cout<<k<<" "<<maxp<<" "<<maxtime<<endl;
			team[k-1].first=-100;
		
	}
	}
	
	

}

Measured memory_bytes: 3144
// ABC 152-C
// 2020.1.19 bal4u

#include <stdio.h>

#define gc() getchar_unlocked()

int in() {   // 非負整数の入力
	int n = 0; int c;
	c = gc();
	do n = 10 * n + (c & 0xf); while ((c = gc()) >= '0');
	return n;
}

int main()
{
	int N, P, mi, ans;
	
	mi = 0x5fffffff, ans = 0;
	N = in();
	while (N--) {
		P = in();
		if (mi > P) mi = P;
		if (mi >= P) ++ans;
	}
	printf("%d\n", ans);
	return 0;
}


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

using namespace std;

int main(){

    cin.tie(0);
    ios::sync_with_stdio(false);

    string s;

    cin >> s;

    if(s[0] == s[2])
        cout << "Yes" << endl;
    else
        cout << "No" << endl;

    return 0;

}


Measured memory_bytes: 256
import sys

S = input()
N = len(S)

if S != S[::-1]:
    print('No')
    sys.exit()

S1 = S[:int((N-1)/2)]
S2 = S[int((N+1)/2):]
if S1 != S1[::-1]:
    print('No')
    sys.exit()
if S2 != S2[::-1]:
    print('No')
    sys.exit()

print('Yes')


Measured memory_bytes: 3064
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		
		Scanner sc = new Scanner(System.in);
		
		int N = sc.nextInt();
		int H = sc.nextInt();
		int W = sc.nextInt();
		
		if(H>N || W>N) {
			throw new RuntimeException("wrong");
		}
		if(H<N && W==N) {
			System.out.println(N-H+1);
		}
		if(H==N && W<N) {
			System.out.println(N-W+1);
		}
		if(H<N && W<N) {
			System.out.println((N-H+1)*(N-W+1));
		}
		if(H==N && W==N) {
			System.out.println(1);
		}
 	}
}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
using ll = long long;
using p = pair<int,int>;
int main(int argc, const char * argv[]) {



    cin.tie(0);
    ios::sync_with_stdio(false);

    int a,b;
    cin>>a>>b;
    if(a+b>=24)cout<<a+b-24<<endl;
    else cout<<a+b<<endl;

    return 0;
}


Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
struct Fast { Fast() { cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20);} } fast;


int main() {
    int s;
    cin >> s;
    if (s / 100 > 12 || s / 100 == 0){
        if (s % 100 > 12 || s % 100 == 0){
            cout << "NA" << endl;
        }else{
            cout << "YYMM" << endl;
        }
    }else if (s % 100 <= 12 && s % 100 > 0){
        cout << "AMBIGUOUS" << endl;
    }else{
        cout << "MMYY" << endl;
    }
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main(){
    int X=0,Y=0,Z=0,N,num;
    cin >> N >> num;
    for(int x=0;x<=N;x++){
        for(int y=0;y<=N-x;y++){
            if(x*10000+y*5000+(N-x-y)*1000==num){
                X=x;
                Y=y;
                Z=N-x-y;
            }
        }
    }
    if(X==0&&Y==0&&Z==0)    cout << "-1 -1 -1\n";
    else    cout << X << " " << Y << " " << Z << endl;
    return 0;
}

Measured memory_bytes: 256
n=int(input())
a=input()
b=input()
c=input()
count=0
for i in range(n):
    if(a[i] == b[i]):
        if(a[i] != c[i]):
            count += 1
        else:
            continue
    elif(a[i]==c[i]):
        if(a[i] != b[i]):
            count+=1
        else:
            continue
    elif(b[i] == c[i]):
        if(b[i] != a[i]):
            count+=1
        else:
            continue
    else:
        count+=2
print(count)

Measured memory_bytes: 3064
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <functional>

using namespace std;
 
#define mod 1000000007
#define FOR(x,to) for(int x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
#define long long long
inline int rei(){int x;cin>>x;return x;}
inline long rel(){long x;cin>>x;return x;}
inline string res(){string x;cin>>x;return x;}
//------------------------------------------------------- 
void Calc(){
	int M = rei();
	int K = rei();
	if((1 << M) <= K){
		cout << -1 << endl;
		return;
	}
	if(M == 1 && K == 1){
		cout << -1 << endl;
		return;
	}
	if(M == 1 && K == 0){
		cout << "0 0 1 1" << endl;
		return;
	}
	int m = (1 << M);
	for(int i=0;i<m;i++){
		if(i != K){
			cout << i << " ";
		}
	}
	cout << K << " ";
	for(int i=m-1;i>=0;i--){
		if(i != K){
			cout << i << " ";
		}
	}
	cout << K << endl;
}
int main(int argc,char** argv){
	ios::sync_with_stdio(false), cin.tie(0);
	cout.tie(0); Calc(); return 0;
}

Measured memory_bytes: 1792
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;
typedef pair<ld, ld> LDP;
int main(){
	bool exiodd = false;
	int n; cin >> n;
	int xorsum = 1;
	rep(i, n) {
		int a; cin >> a;
		xorsum ^= a;
		if (a % 2)exiodd = true;
	}
	if ((!xorsum) || (xorsum == 1 && !exiodd))cout << "Bob" << endl;
	else cout << "Alice" << endl;
	return 0;
}


Measured memory_bytes: 3108
n,k=map(int,input().split())
s=list(input())
ct=0
for i in range(n-1):
  if s[i]=='R' and s[i+1]=='L':
    ct+=1
if s[0]==s[n-1]:
  x=ct
  ct-=min(ct,k)
  ct*=2
  ct+=1
  print(n-ct)
elif s[0]=='L':
  x=ct
  ct-=min(ct,k)
  ct*=2
  if x<k:
    ct+=1
  else:
    ct+=2
  print(n-ct)
else:
  x=ct
  ct-=min(ct,k)
  ct*=2
  if x<=k:
    ct+=1
  print(n-ct)

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

using namespace std;

const long long INF = 1e18;

pair <int, int> a[105];
long long dp[100005];

int main() {
    int n, w;

    scanf("%d%d", &n, &w);

    for (int i = 0; i < n; i++) scanf("%d%d", &a[i].first, &a[i].second);

    dp[0] = 0;
    for (int i = 1; i <= w; i++) dp[i] = -INF;

    for (int i = 0; i < n; i++) {
        for (int j = w; j >= a[i].first; j--) dp[j] = max(dp[j], dp[j - a[i].first] + a[i].second);
    }

    long long res = -INF;

    for (int i = 0; i <= w; i++) res = max(res, dp[i]);

    printf("%lld\n", res);
}


Measured memory_bytes: 1024
import java.util.*;

class Main {
    public static void main (String [] args) {

        Scanner sc = new Scanner(System.in);

        while (true) {
            int n = sc.nextInt();
            if (n == 0) break;

            int a = 0;
            int b = 0;
            int ac, bc;

            for(int x = 0; x < n; x++) {
                ac = sc.nextInt();
                bc = sc.nextInt();
                if (ac > bc) {
                    a += ac + bc;
                } else if (ac < bc) {
                    b += ac + bc;
                } else {
                    a += ac;
                    b += bc;
                }
            }

            System.out.printf("%d %d\n", a, b);
        }

    }
}

Measured memory_bytes: 12000
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define EQ(a,b) (abs((a)-(b))<EPS)
using namespace std;
typedef double D;
const D EPS = 1e-8;

inline D getTime(D dx, D dy, D v, D fpx, D fpy, D fvx, D fvy){
  D px = fpx-dx, py = fpy-dy;
  D a = fvx*fvx + fvy*fvy - v*v;
  D b = 2*fvx*px + 2*fvy*py;
  D c = px*px + py*py;

  if(EQ(a,0)){
    if(EQ(b,0))return EQ(c,0)?0:-1;
    else return (-c/b<-EPS)?-1:-c/b;
  }else{
    D d = b*b - 4*a*c;
    if(d < -EPS)return -1;
    if(EQ(d,0))return (-b/2/a<-EPS)?-1:-b/2/a;
    D t1 = (-b-sqrt(d))/2/a, t2 = (-b+sqrt(d))/2/a;
    if(t1<-EPS)return (t2<-EPS)?-1:t2;
    return t1;
  }
}

int main(){
  int n,m;
  D dx[10], dy[10], v[10], t[10];
  int cnt[10];
  while(scanf("%d%d",&n,&m),n){
    rep(i,n)scanf("%lf%lf%lf",dx+i,dy+i,v+i);

    memset(cnt,0,sizeof(cnt));
    rep(i,m){
      D fpx, fpy, fvx, fvy;
      scanf("%lf%lf%lf%lf",&fpx,&fpy,&fvx,&fvy);
      
      D minT = 1e10;
      int minID = -1;
      rep(i,n){
	t[i] = getTime(dx[i],dy[i],v[i], fpx,fpy,fvx,fvy);
	if(t[i]>-EPS && minT > t[i] + EPS){
	  minT = t[i]; minID = i;
	}
      }

      cnt[minID]++;
      rep(i,n){
	if(t[i]>-EPS){
	  D sx = fpx+fvx*t[i] - dx[i], sy = fpy+fvy*t[i] - dy[i];
	  D absS = sqrt(sx*sx + sy*sy);
	  if(EQ(absS,0))continue;
	  sx /= absS; sy /= absS;
	  dx[i] += sx * v[i] * minT; dy[i] += sy * v[i] * minT;
	}
      }
    }
    rep(i,n)printf("%d%c",cnt[i],i==n-1?'\n':' ');
  }
}

Measured memory_bytes: 1228
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,i,count=0;
    cin>>n;
    int a[n];
    for(i=0;i<n;i++)
    {
        cin>>a[i];
    }
    for(i=1;i+1<n;i++)
    {
        if((a[i-1]<a[i] && a[i+1]>a[i])||(a[i+1]<a[i] && a[i-1]>a[i]) )
        {
            count++;
        }
    }
    cout<<count;

}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    int n, m, f = 0;
    cin >> n;
    m = n;
    while(n > 0){
        f += n % 10;
        n /= 10;
    }
    
    if((m % f) == 0){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}


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

using namespace std;

#define int long long

const int inf = 1e9;

const int maxn = 100 + 100;
const int maxW = 1e5 + 1000;

int w[maxn], v[maxn];

int dp[maxn][maxW];

signed main() {
    
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    
    int n, can;
    cin >> n >> can;
    
    for (int i = 1; i <= n; i++) {
        cin >> w[i] >> v[i];
    }
    
    for (int i = 1; i <= n; i++) {
        for (int j = 0; j <= can; j++) {
            dp[i][j] = dp[i - 1][j];
            if (j >= w[i]) {
                dp[i][j] = max(dp[i][j], dp[i - 1][j - w[i]] + v[i]);
            }
        }
    }
    
    int ans = 0;
    for (int i = 0; i <= can; i++) {
        ans = max(ans, dp[n][i]);
    }
    cout << ans;
    return 0;
}


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

int main(){
    ll n,a,b;
    cin >> n >> a >> b;
    ll s = b-a;
    if(s%2 == 0) cout << s/2 << endl;
    else cout << min(n-b,a-1) + 1 + (s-1)/2 << endl;
}


Measured memory_bytes: 256
// 大小比較

import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int a, b;

    a = sc.nextInt();
    b = sc.nextInt();

    if (a > b) {
      System.out.println("a > b");
    } else if (a < b){
      System.out.println("a < b");
    } else {
      System.out.println("a == b");
    }

    sc.close();
  }
}



Measured memory_bytes: 26208
#include "bits/stdc++.h"

using namespace std;

const int mx = 2e5 + 9;

int ans[mx];
bitset <mx> mark;
vector <int> adj[mx];

void bfs(int s) {
    mark[s] = 1;
    queue <int> q;
    q.push(s);

    while (!q.empty()) {
        auto u = q.front();
        q.pop();
        for (auto v : adj[u]) {
            if (mark[v]) continue;
            mark[v] = 1;
            ans[v] = u;
            q.push(v);
        }
    }
}

int main() {
    int n, m; cin >> n >> m;
    memset(ans, -1, sizeof ans);
    while (m--) {
        int a, b; cin >> a >> b;
        adj[a].push_back(b);
        adj[b].push_back(a);
    }

    bfs(1);
    for (int i = 2; i <= n; i++) {
        if (ans[i] == -1) {
            cout << "No" << endl;
            return 0;
        }
    }

    cout << "Yes" << endl;
    for (int i = 2; i <= n; i++) {
        cout << ans[i] << endl;
    }
}


Measured memory_bytes: 13152
#include <bits/stdc++.h>
using namespace std;
const int MAXN = (int)1e3 + 10;
int dp[2][MAXN],N,best;
int main(){
	scanf("%d",&N);
	for(int i = 1;i<=N;i++){
		scanf("%d",&dp[0][i]);
		dp[0][i] += dp[0][i-1];
	}
	for(int i = 1;i<=N;i++){
		scanf("%d",&dp[1][i]);
		dp[1][i] += dp[1][i-1];
	}
	for(int i = 1;i<=N;i++){
		best = max(best, dp[0][i]+ dp[1][N] - dp[1][i-1] );
	}
	printf("%d\n",best);
	return 0;
}

Measured memory_bytes: 256
# coding: utf-8
# Your code here!

input_S = input()
input_T = input()
# print("S:{}, T:{}".format(input_S, input_T))
# print("T:{},  len:{}".format(input_T[0:len(input_S)], input_S))
if(input_T[0:len(input_S)] == input_S and 0 < len(input_T) - len(input_S)):
    print("Yes")
else:
    print("No")

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


int main() {
  int a, b;
  cin >> a >> b;
  int tmp;
  if (a > b) {
    tmp = a;
    a = b;
    b = tmp;
  }
  if ((b - a) % 2 == 1) {
    cout << "IMPOSSIBLE" << endl;
  } else {
    cout << (b - a) / 2 + a  << endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0;i<n;i++)
using ll = long long;
using P = pair<ll,ll>;
 
int main (){
  ll n;cin>>n;
  vector<ll> v(n);
  map<ll,ll> m;
  rep(i,n){
    cin>>v.at(i);
    m[v.at(i)]++;
  }
  ll sum = 0;
  for (auto i : m){
    sum+=(i.second-1)*i.second/2;
  }
  rep(j,n){
    ll i = v.at(j);
    ll a,b;
    a = (m[i]-1)*m[i]/2;
    b = (m[i]-2)*(m[i]-1)/2;
    cout << sum - a + b << endl;
  }
}

Measured memory_bytes: 11008
import java.util.*;

public class Main{

    int n;
    int[][] ab;

    void solve(){
        Scanner sc = new Scanner(System.in);

        n = sc.nextInt();
        ab = new int[n][2];
        for(int i=0; i<n; i++){
            ab[i][0] = sc.nextInt();
            ab[i][1] = sc.nextInt();
        }

        Arrays.sort(ab, new Comparator<int[]>(){
                public int compare(int[] a, int[] b){
                    return a[1] - b[1];
                }
            });

        PriorityQueue<Integer> q = new PriorityQueue<Integer>();

        int sum = 0;
        for(int i=0; i<n; i++){
            q.add(-ab[i][0]);
            sum += ab[i][0];
            if(sum>ab[i][1]) sum += q.poll();
        }

        System.out.println(q.size());
    }

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

Measured memory_bytes: 12000