akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
//#include "testlib.h"
#define ff first
#define ss second
#define all(v) v.begin(),v.end()
#define int long long
#define ll long long
#define M 1000000007
#define MM 998244353
#define inputarr(a,n) for(int i=0;i<n;++i) cin>>a[i]
#define GCD(m,n) __gcd(m,n)
#define LCM(m,n) m*(n/GCD(m,n))
#define mii  map<ll ,ll >
#define msi  map<string,ll >
#define rep(a,b)    for(ll i=a;i<b;i++)
#define rep0(n)    for(ll i=0;i<n;i++)
#define repi(i,a,b) for(ll i=a;i<b;i++)
#define pb push_back
#define vi vector<ll>
#define vs vector<string>
#define ppb pop_back
#define endl '\n'
#define asdf ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define r0 return 0;
#define FORD(i, a, b) for (int i = (int) (a); i >= (int) (b); --i)
#define inputoutput freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);
#define Set(a, s) (a, s, sizeof (a))
#define FOR repi
#define vii vector<pii>
#define pii pair<int,int>
#define REVERSE(v) reverse(all(v))
#define trav(a, x) for(auto& a : x)
#define display(x) trav(a,x) cout<<a<<" ";cout<<endl
#define debug cerr<<"bhau"<<endl
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    std::cerr << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');std::cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
template<typename T, typename U> static inline void amin(T &x, U y) 
{ 
    if (y < x) 
        x = y; 
}
template<typename T, typename U> static inline void amax(T &x, U y) 
{ 
    if (x < y) 
        x = y; 
}
 
ll max(ll a, ll b) { return (a > b)? a : b;}
int min(int a, int b) { return (a < b)? a : b;} 


int solve(){
    int n,x,t;cin>>n>>x>>t;
    int z=n/x;
    if(n%x) z++;
    cout<<z*t<<endl;



    return 0;
}
signed main(){
    asdf
    int t=1;
    // cin>>t;
    while(t--){
        solve();
    }
    return 0;
}


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

int main()
{
    char a, b;
    cin >> a >> b;
    if(a == 'H'){
        cout << b << endl;
    }
    else{
        switch(b){
            case 'H':
                cout << 'D' << endl;
                break;
            case 'D':
                cout << 'H' << endl;
                break;
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define dunk(a) cout << (a) << endl
using namespace std;
typedef long long ll;

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

    dunk((n+1)/2);
}

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

int main() {
  int N, M, P, SumA=0, SumW=0;
  string S;
  cin >> N >> M;
  vector<int> W(N), A(N);
  rep(i, M){
    cin >> P >> S;
    if(S=="WA" && A.at(P-1)==0) W.at(P-1)++;
    else if(S=="AC") A.at(P-1)=1;
  }
  rep(i, N) SumA+=A.at(i);
  rep(i, N) if(A.at(i)==1) SumW+=W.at(i);
  cout << SumA << " " << SumW << endl;
}

Measured memory_bytes: 1024
import std.stdio, std.string, std.conv;
import std.algorithm, std.array, std.range;
auto solve(string S_) {
    immutable N=S_.chomp.to!int();
    immutable A=readln.chomp();
    immutable B=readln.chomp();
    immutable C=readln.chomp();
    int k=0;
    foreach(i;0..N) {
        if(A[i]!=B[i]) {
            ++k;
            if(A[i]!=C[i] && B[i]!=C[i]) ++k;
        }
        else if(B[i]!=C[i]) {
            ++k;
        }
    }
    return k;
}
void main(){ for(string s; (s=readln.chomp()).length;) writeln(solve(s)); }

Measured memory_bytes: 256
#include <stdio.h>

int main(void){
  int N;
  scanf("%d",&N);

  if(N == 1){
    printf("0\n");
    return 0;
  }

  int C[N],F[N];
  long S[N];

  for(int i = 0;i < N-1;i++){
    scanf("%d%ld%d",&C[i],&S[i],&F[i]);
  }

  for(int i = 0;i < N-1;i++){
    long time = S[i]+C[i];
    for(int j = i+1;j < N-1;j++){
      if(time < S[j]){
        time = S[j];
      }else if(time%F[j] != 0){
        time = time+F[j]-(time%F[j]);
      }
      time += C[j];
    }
    printf("%ld\n",time);
  }

  printf("0\n");
  return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#ifdef _WIN32
#include "debug.hpp"
#endif
using namespace std;

#define rep(i, N)  for(int i = 0; i < (N); i++)
#define reps(i, N) for(int i = 1; i <= (N); i++)
#define repr(i, N) for(int i = (N) - 1; i >= 0; i--)
#define pub push_back

template<typename T> 
void chmax(T &a, T b){ a = max(a, b); };
template<typename T> 
void chmin(T &a, T b){ a = min(a, b); };

typedef long long ll;
typedef pair<int, int> P;
const int INF = 100000000;
const ll LINF = 10000000000000000;
const int MOD = 1000000007;
const int dx[9] = { 0, 1,  0, -1, 1,  1, -1, -1, 0};
const int dy[9] = { 1, 0, -1,  0, 1, -1, -1,  1, 0};
//--------------------------------------//
int N;
int D[51];

int b[24];
void solve(){
	sort(D, D + N);
	rep(i, N){
		if(i % 2)
			b[D[i]]++;
		else
			b[(24 - D[i]) % 24]++;
	}
	//da(b, 24);
	int ans = INF;
	int c = INF;
	rep(i, 24){
		if(b[i] > 1){
			cout << 0 << endl;
			return;
		}
		else if(b[i]){
			chmin(ans, c);
			c = 1;
		}
		else
			c++;
	}
	cout << ans << endl;
}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cin >> N;
	rep(i, N) {
		cin >> D[i];
	}
	N++;
	solve();
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main () {
  long N, M;
  cin >> N >> M;
  long ans = 0;
  if(N >= 2)ans += N * (N - 1) / 2;
  if(M >= 2)ans += M * (M - 1) / 2;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>

struct {
  auto &operator>>(int &x) {
    char c;
    do
      c = std::cin.rdbuf()->sbumpc();
    while (!isdigit(c));
    for (x = 0; isdigit(c); c = std::cin.rdbuf()->sbumpc())
      x = x * 10 + (c ^ 48);
    return *this;
  }
} io;

const int MAX_N = 100000;
const int MOD = 1e9 + 7;

struct Edge {
  int v, next;
} e[MAX_N * 2 + 3];

struct I {
  int v;

  operator int() { return v; }

  I operator+(const I &rhs) {
    return {v + rhs.v >= MOD ? v + rhs.v - MOD : v + rhs.v};
  }

  I operator*(const I &rhs) {
    return {static_cast<int>(static_cast<long long>(v) * rhs.v % MOD)};
  }
};

int g[MAX_N + 1], cnt;
I f[MAX_N + 1][2];
bool vis[MAX_N + 1];

inline void addEdge(int u, int v) {
  e[++cnt] = {v, g[u]};
  g[u] = cnt;
}

void dfs(int u) {
  vis[u] = true;
  I t[2]{1, 1};
  for (int i = g[u], v; i; i = e[i].next) {
    v = e[i].v;
    if (!vis[v]) {
      dfs(v);
      t[0] = t[0] * f[v][1];
      t[1] = t[1] * (f[v][0] + f[v][1]);
    }
  }
  f[u][0] = t[0];
  f[u][1] = t[1];
}

int main() {
  int n;
  io >> n;
  for (int i = 1, u, v; i < n; ++i) {
    io >> u >> v;
    addEdge(u, v);
    addEdge(v, u);
  }
  dfs(1);
  std::cout << f[1][0] + f[1][1];
  return 0;
}

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

int alphabet_pos(char c) {
  if ('A'<=c && c<='Z') return (c-'A'+1);
}

int main() {
  int N;
  string S;
  cin >> N >> S;
  // アルファベット順
  vector<char> alpha = {'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P',
                        'Q','R','S','T','U','V','W','X','Y','Z'};
  for (int i=0; i<S.size(); i++) {
    int order = alphabet_pos(S.at(i));
    if(order+N > 26) S.at(i) = alpha.at(order+N-27);
    else S.at(i) = alpha.at(order+N-1);
  }
  cout << S << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <utility>
#include <map>
#include <string>
#include <math.h>
using namespace std;
typedef long long ll;


int main() {

    int N;
    cin >> N;
    if(N/100==7){
        cout << "Yes" << endl;
        return 0;
    }else if((N%100)/10==7){
        cout << "Yes" <<endl;
        return 0;
    }else if((N%10)==7){
        cout << "Yes" <<endl;
        return 0;
    }else{
        cout << "No" <<endl;
    }
    return 0;
}

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

using ll = long long;
#define REP(i,n) for(int i=0; i < (n); ++i)
#define REPR(i,n) for(int i=(n); i >= 0; --i)
#define FOR(i, m, n) for(int i = (m); i < (n); ++i)

#define INF 1e9


int main(){
  int N, M;
  cin >> N >> M;
  if(N==M){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
package main

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

var (
	sc       = bufio.NewScanner(os.Stdin)
	grid     []string
	h, w     int
	maxUp    [gridSize][gridSize]int
	maxDown  [gridSize][gridSize]int
	maxLeft  [gridSize][gridSize]int
	maxRight [gridSize][gridSize]int
)

const gridSize = 2020

func init() {
	// sc.Split(bufio.ScanWords)
}

func input() int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return i
}

func calcMaxDown() { //j..left, i..up,
	var cnt int
	for j := 0; j < w; j++ {
		for i := h - 1; i >= 0; i-- {
			if grid[i][j] == '#' {
				cnt = 0
				continue
			}

			maxDown[i][j] = cnt
			cnt += 1
		}
		cnt = 0
	}
}

func calcMaxUp() { //j..left, i..down
	var cnt int
	for j := 0; j < w; j++ {
		for i := 0; i < h; i++ {
			if grid[i][j] == '#' {
				cnt = 0
				continue
			}

			maxUp[i][j] = cnt
			cnt += 1
		}
		cnt = 0
	}
}

func calcMaxLeft() { //j..right, i..down
	var cnt int
	for i := 0; i < h; i++ {
		for j := w - 1; j >= 0; j-- {
			if grid[i][j] == '#' {
				cnt = 0
				continue
			}

			maxLeft[i][j] = cnt
			cnt += 1
		}
		cnt = 0
	}
}

func calcMaxRight() { //j..left, i..down
	var cnt int
	for i := 0; i < h; i++ {
		for j := 0; j < w; j++ {
			if grid[i][j] == '#' {
				cnt = 0
				continue
			}

			maxRight[i][j] = cnt
			cnt += 1
		}
		cnt = 0
	}
}

func main() {
	fmt.Scan(&h, &w)
	for i := 0; i < h; i++ {
		sc.Scan()
		grid = append(grid, sc.Text())
	}

	calcMaxDown()
	calcMaxUp()
	calcMaxLeft()
	calcMaxRight()

	// for i := 0; i < h; i++ {
	// 	fmt.Println(maxDown[i])
	// }
	//
	// for i := 0; i < h; i++ {
	// 	fmt.Println(maxUp[i])
	// }
	//
	// for i := 0; i < h; i++ {
	// 	fmt.Println(maxLeft[i])
	// }
	//
	// for i := 0; i < h; i++ {
	// 	fmt.Println(maxRight[i])
	// }

	ans := 0

	for i := 0; i < h; i++ {
		for j := 0; j < w; j++ {
			if grid[i][j] == '#' {
				continue
			}
			tmp := 1 + maxDown[i][j] + maxUp[i][j] + maxLeft[i][j] + maxRight[i][j]
			if ans < tmp {
				ans = tmp
			}
		}
	}
	fmt.Println(ans)
}


Measured memory_bytes: 132496
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
using namespace std;
//typedef __int64 LL;
typedef vector<int> ivec;
typedef vector<string> svec;

const int MOD=1000000007;

int main(){
	string s;
	cin>>s;
	
	bool flag=true;
	
	for(int i=0;i<s.size();i++)
	{
		if(i%2==0 && s[i]=='L'){flag=false;break;}
		else if(i%2==1 && s[i]=='R'){flag=false;break;} 
	}
	if(flag)cout<<"Yes"<<"\n";
	else cout<<"No"<<"\n";
	return 0;
}

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

int main(void) {
	char buffer[2][256], *src, *dest, *tmp;
	int m, i, h, l;
	while (scanf("%255s", buffer[0]) == 1 && strcmp(buffer[0], "-") != 0) {
		src = buffer[0];
		dest = buffer[1];
		l = strlen(src);
		dest[l] = '\0';
		if (scanf("%d", &m) != 1) return 1;
		for (i = 0; i < m; i++) {
			if (scanf("%d", &h) != 1) return 1;
			memcpy(dest + l - h, src, h);
			memcpy(dest, src + h, l - h);
			tmp = src;
			src = dest;
			dest = tmp;
		}
		puts(src);
	}
	return 0;
}



Measured memory_bytes: 2068
#include <bits/stdc++.h>
using namespace std;typedef long long ll;typedef vector<ll> vl;typedef vector<vl> vvl;typedef pair<ll,ll> pl;typedef vector<pl> vp;const ll INF=1001001001;const ll LINF=1001001001001001001;const ll D4[]={0,1,0,-1,0};const ll D8[]={0,1,1,0,-1,-1,1,-1,0};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;}
#define fore(i,a,b) for(ll i=(ll)(a);i<=(ll)(b);++i)
#define rep(i,n) fore(i,0,(n)-1)
#define all(x) (x).begin(),(x).end()

template< typename T >
struct edge {
  int src, to;
  T cost;

  edge(int to, T cost) : src(-1), to(to), cost(cost) {}

  edge(int src, int to, T cost) : src(src), to(to), cost(cost) {}

  edge &operator=(const int &x) {
    to = x;
    return *this;
  }

  operator int() const { return to; }
};

template< typename T >
using Edges = vector< edge< T > >;
template< typename T >
using WeightedGraph = vector< Edges< T > >;
using UnWeightedGraph = vector< vector< int > >;
template< typename T >
using Matrix = vector< vector< T > >;
void solve(long long H, long long W, std::vector<std::string> s){
    WeightedGraph<ll> g(H*W);
    rep(i,H)rep(j,W){
        if(i<H-1)g[i*W+j].emplace_back((i+1)*W+j,(s[i][j]==s[i+1][j]?0:1));
        if(j<W-1)g[i*W+j].emplace_back(i*W+j+1,(s[i][j]==s[i][j+1]?0:1));
    }
    vl d(H*W,LINF);
    d[0]=0;
    priority_queue<pl,vp,greater<>> q;
    q.emplace(0,0);
    while(q.size()){
        ll to,cost;
        tie(cost,to)=q.top();q.pop();
        if(cost>d[to])continue;
        for(auto &e:g[to]){
            if(d[e.to]<=d[to]+e.cost)continue;
            d[e.to]=d[to]+e.cost;
            q.emplace(d[e.to],e.to);
        }
    }

    ll ans=(d[H*W-1]+1)/2;
    if(s[H-1][W-1]=='#'&&s[0][0]=='#')ans++;
    cout<<ans<<endl;
}

int main(){
    long long H;
    scanf("%lld",&H);
    long long W;
    scanf("%lld",&W);
    std::vector<std::string> s(W);
    for(int i = 0 ; i < W ; i++){
        std::cin >> s[i];
    }
    solve(H, W, std::move(s));
}


Measured memory_bytes: 1024
#include <iostream>
using namespace std;
int main(){
	int n,k;
	cin>>n>>k;
	bool dp[k+1]={0};
	int a[n];
	for (int i = 0; i < n; i++	)
	{
		cin>>a[i];
	}
	for (int i = 0; i <=k; ++i)
	{
		for (int j = 0; j<n; ++j)
		{
			if (i>=a[j] && !dp[i-a[j]])
			{
				dp[i]=1;
			}
		}
	}
	if(dp[k])cout<<"First";
	else cout<<"Second";
	return 0;
}


Measured memory_bytes: 384
n=int(input())
w=list(map(int,input().split()))

diff = [0]*(n-1)

for ii in range(1,n):
    s1 = sum(w[:ii])
    s2 = sum(w[ii:])
    diff[ii-1] = abs(s1-s2)
    
print(min(diff))


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define repl(i,x,n) for(long long i=(long long)(x);i<(long long)(n);i++)
#define rep(i,x,n) for(long i=long(x);i<long(n);i++)
int main() 
{
    //ifstream cin("input.in");
    //ofstream cout("output.out");
    ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    long n,a,b;
    cin>>n>>a>>b;
    b-=a;
    b--;
    //cout<<b<<"\n";
    if(b&1)
        cout<<"Alice";
    else
        cout<<"Borys";
}   

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

int main() {
  int a, b;
  cin >> a >> b;
  int ans = 0;
  if(a > b){
    ans += a;
    ans += max(a - 1, b);
  }
  else{
    ans += b;
    ans += max(a, b - 1);
  }
  cout << ans;
  return 0;
}

Measured memory_bytes: 256
import numpy as np 
H, W = map(int, input().split())
S = np.array([list(input()) for _ in range(H)]) == '.'
 

up = np.zeros((H, W), dtype=int)
down = np.zeros((H, W), dtype=int)
left = np.zeros((H, W), dtype=int)
right = np.zeros((H, W), dtype=int)
 
for i in range(H):
    up[i] = (up[i-1] + 1) * S[i]
    down[-i-1] = (down[-i] + 1) * S[-i-1]
    
for i in range(W):
    left[:, i] = (left[:, i-1] + 1) * S[:, i]
    right[:, -i-1] = (right[:, -i] + 1) * S[:, -i-1]

print(np.max(up+down+left+right) - 3)

Measured memory_bytes: 219816
n, q = map(int, input().split())
ki = [0] * (n + 1)
for i in range(n - 1):
    a, b = map(int, input().split())
    ki[b] = a
# print("ki=",ki)

c = [0] * (n + 1)
for i in range(q):
    p, x = map(int, input().split())
    c[p] += x
# print("c=",c)

for i in range(1, n + 1):
    c[i] += c[ki[i]]
# print(c)

print(" ".join(map(str, c[1:])))

Measured memory_bytes: 36896
// This file is a "Hello, world!" in C++ language by GCC for wandbox.
#include <bits/stdc++.h>
using namespace std;
using int64 = long long;

int main() {
  int N;
  cin >> N;
  vector<int64> A(N);
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }
  sort(A.begin(), A.end());
  int64 sub = 0;
  int64 add = 0;
  int64 ans = 0;
  if (N % 2 == 0) {
    for (int i = 0; i < (N - 1) / 2; i++) {
      sub += A[i] * 2;
    }
    sub += A[(N - 1) / 2];
    for (int i = N - 1; i > N - 1 - (N - 1) / 2; i--) {
      add += A[i] * 2;
    }
    add += A[N - 1 - (N - 1) / 2];
    ans = add - sub;
  } else {
    for (int i = 0; i < (N - 1) / 2; i++) {
      sub += A[i] * 2;
    }
    for (int i = N - 1; i > N - 1 - (N - 1) / 2; i--) {
      add += A[i] * 2;
    }
    int64 sub1 = sub + A[(N - 1) / 2] - A[(N - 1) / 2 - 1];
    int64 add1 = add + A[N - 1 - (N - 1) / 2] - A[N - (N - 1) / 2];
    // cout << add << ' ' << sub << ' ' << add1 << ' ' << sub1 << ' ' << endl;
    ans = max(add1 - sub, add - sub1);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 4036
#define  _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES

#pragma comment (linker, "/STACK:526000000")

#include "bits/stdc++.h"

using namespace std;
typedef string::const_iterator State;
#define eps 1e-8L
#define MAX_MOD 1000000007LL
#define GYAKU 500000004LL
#define MOD 998244353LL
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef long double ld;
#define REP(a,b) for(long long (a) = 0;(a) < (b);++(a))
#define ALL(x) (x).begin(),(x).end()
#define int ll
int costs(int now) {
    for (int i = 0; i < 62; ++i) {
        if (now < (1 << i)) {
            return i + 1;
        }
    }
}

int secret_d = 10;
int n;

int interact(int a) {
    int ans = 0;
    cout << "? " << a << endl;
    if (true) {
        int r = 1;
        for (int i = 0; i < 60; ++i) {
            if ((secret_d & (1LL << i))) {
                ans += costs(r) * costs(a);
                r = r * a % n;                
            }
            ans += costs(a) * costs(a);
            a = a * a % n;
        }
    }
    else {
        cin >> ans;
    }
    return ans;
}

void init() {
    iostream::sync_with_stdio(false);
    cout << fixed << setprecision(20);
}

long double comb(int a, int b) {
    ld ans = 1;
    for (int q = 0; q < b; ++q) {
        ans *= (ld)(a - q);
        ans /= (ld)(q + 1);
    }
    return ans;
}
int cnts[400000];
void solve(){
    int n, m;
    cin >> n >> m;
    REP(i, n) {
        int a;
        cin >> a;
        cnts[a]++;
    }
    int ans = 0;
    for (int q = 0; q < m; ++q) {
        if ((q + q) % m == 0) {
            int cnt = 0;
            for (int j = 0; j * m + q <= 1e5; ++j) {
                cnt += cnts[j * m + q];
                cnts[j * m + q] = 0;
            }
            ans += cnt / 2;
            continue;
        }
        int l = 0;
        int r = 0;
        int left_l = 0;
        int left_r = 0;
        for (int j = 0; j * m + q <= 1e5; ++j) {
            l += cnts[j * m + q] / 2;
            left_l += cnts[j * m + q] % 2;
            cnts[j * m + q] = 0;
        }
        q = m - q;
        for (int j = 0; j * m + q <= 1e5; ++j) {
            r += cnts[j * m + q] / 2;
            left_r += cnts[j * m + q] % 2;
            cnts[j * m + q] = 0;
        }
        q = m - q;
        ans += l + r;
        int hoge = min(left_l, left_r);
        ans += hoge;
        left_l -= hoge;
        left_r -= hoge;
        if (left_l > 0) {
            int hoge = min(left_l, r * 2);
            ans += hoge / 2;
        }
        else {
            int hoge = min(left_r, l * 2);
            ans += hoge / 2;
        }
    }
    cout << ans << endl;
}

#undef int
int main() {
    init();
    solve();
}

Measured memory_bytes: 4424
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Main main = new Main();
        main.solve();
    }
    public void solve() {
        Scanner scan = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        String s = scan.next();
        char[] d = s.toCharArray();
        int len = d.length;
        boolean all_nine = true;
        for (int i = 1; i < len; i++) {
            if (d[i] != '9') {
                all_nine = false;
                break;
            }
        }
        if (all_nine) {
            System.out.println(9 * (len - 1) + (d[0] - '0'));
            return;
        }
        System.out.println(9 * (len - 1) + (d[0] - '0') - 1);
        return;
    }
}


Measured memory_bytes: 21844
// bubble sort alg
// input integer elements, output sorted elements and number of change operations
#include<iostream>
void BubbleSort(int*,int);
int main(){
  int N;
  std::cin >> N;
  int A[N];
  for(int i=0; i<N; i++) std::cin >> A[i];
  BubbleSort(A,N);
  return 0;
}
void BubbleSort(int *B, int N){
  int cnt=0,tmp;
  for(int i=0; i<N-1; i++) for(int j=N-1; j>i; j--) if(B[j] < B[j-1]) tmp = B[j], B[j] = B[j-1], B[j-1] = tmp,cnt++;
  for(int i=0; i<N; i++) std::cout << B[i] << (i < N-1 ? " " : "\n");
  std::cout << cnt << "\n";
}

Measured memory_bytes: 3092
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i, a, b) for (int i = (a); i < (int)(b); ++i)
#define rrep(i, a, b) for (int i = (int)(b) - 1; i >= (int)(a); --i)
#define all(c) c.begin(),c.end()
#define sz(x) ((int)x.size())
using pii = pair<int, int>;
using vvi = vector<vector<int>>;
using vi  = vector<int>;

struct BIT {
    int size;
    int pow2_less;
    vi data;

    BIT(int N) : size(N + 1), data(N + 1, 0) {
        pow2_less = 1;
        while ((pow2_less << 1) <= size) {
            pow2_less <<= 1;
        }
    }

    // 1-indexed
    void add(int idx, int value) {
        while (idx < size) {
            data[idx] += value;
            idx += idx & -idx;
        }
    }

    // 1-indexed
    int sum(int idx) {
        int ret = 0;
        while (idx > 0) {
            ret += data[idx];
            idx -= idx & -idx;
        }
        return ret;
    }

    // sum(x) >= value となる最小のxを返す
    int lower_bound(int value) {
        if (value <= 0) {
            return 0;
        }
        int pos = 0;
        for (int k = pow2_less; k > 0; k >>= 1) {
            if (pos + k < size && data[pos + k] < value) {
                value -= data[pos + k];
                pos += k;
            }
        }
        return pos + 1;
    }
};

signed main() {
    int N, Q;
    cin >> N >> Q;
    BIT bit(N);
    rep(i, 0, Q) {
        int C, X, Y;
        cin >> C >> X >> Y;
        if (C == 0) {
            // add
            bit.add(X, Y);
        } else {
            // sum
            cout << bit.sum(Y) - bit.sum(X - 1) << endl;
        }
    }
}



Measured memory_bytes: 3552
def solve():
    N, T, S = map(int, input().split())
    a = [tuple(map(int, input().split())) for _ in [0]*N]
    dp = [float("-inf")]*(T+1)
    dp[0] = 0

    for fun, mise_time in a:
        for prev_time, from_fun, to_fun in zip(range(T-mise_time, -1, -1), dp[T-mise_time::-1], dp[::-1]):
            new_time = prev_time + mise_time
            new_fun = fun + from_fun
            if prev_time < S < new_time:
                new_time = S + mise_time
                if new_time > T:
                    continue
                to_fun = dp[new_time]
            if new_fun > to_fun:
                dp[new_time] = new_fun

    print(max(dp))


if __name__ == "__main__":
    solve()

Measured memory_bytes: 8452
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1LL<<60;

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

int main(){
    ll H,W; cin >> H >> W;
    vector<vector<ll> > a(H,vector<ll>(W));
    ll sum = 0;
    for(int i=0;i<H;++i){
        for(int j=0;j<W;++j){
            cin >> a[i][j];
            sum += a[i][j];
        }
    }

    ll cur = 0, par = 0;
    vector<pair<ll,ll> > p;
    for(int i=0;i<H;++i){
        for(int j=0;j<W;++j){
            a[i][j] += cur;
            if(a[i][j] % 2){
                cur = 1;
            }else cur = 0;
            if(cur || par){
                for(int k=0;k<cur + par;++k)p.push_back(make_pair(i+1,j+1));
            }
            par = cur;
        }
        ++i;
        if(i >= H)break;
        for(int j=W-1;j>=0;--j){
            a[i][j] += cur;
            if(a[i][j] % 2){
                cur = 1;
            }else cur = 0;
            if(cur || par){
                for(int k=0;k<cur + par;++k)p.push_back(make_pair(i+1,j+1));
            }
            par = cur;
        }
    }
    if(cur) p.pop_back();
    cout << p.size()/2 << endl;

    ll cnt = 0;
    for(auto it : p){
        cnt++;
        if(cnt%2)cout << it.first << " " << it.second;
        else if(cnt%2 == 0) cout << " " << it.first << " " << it.second << endl; 
    }

}

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

public class Main {
	static PrintWriter out;
	static StringBuilder sb;
	static int n, m, k;
	static long mod = 998244353;
	static Boolean[][][] memo;
	static String s;
	static HashMap<Integer, Integer> nums;
	static ArrayList<Integer>[] ad;
	static int inf = 1000000;

	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		out = new PrintWriter(System.out);
if(sc.next().equals("ABC"))
	System.out.println("ARC");
else
	System.out.println("ABC");
		out.flush();
	}

	static class Scanner {
		StringTokenizer st;
		BufferedReader br;

		public Scanner(InputStream system) {
			br = new BufferedReader(new InputStreamReader(system));
		}

		public Scanner(String file) throws Exception {
			br = new BufferedReader(new FileReader(file));
		}

		public String next() throws IOException {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}

		public String nextLine() throws IOException {
			return br.readLine();
		}

		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}

		public double nextDouble() throws IOException {
			return Double.parseDouble(next());
		}

		public char nextChar() throws IOException {
			return next().charAt(0);
		}

		public Long nextLong() throws IOException {
			return Long.parseLong(next());
		}

		public int[] nextArrInt(int n) throws IOException {
			int[] a = new int[n];
			for (int i = 0; i < n; i++)
				a[i] = nextInt();
			return a;
		}

		public long[] nextArrLong(int n) throws IOException {
			long[] a = new long[n];
			for (int i = 0; i < n; i++)
				a[i] = nextLong();
			return a;
		}

		public boolean ready() throws IOException {
			return br.ready();
		}

		public void waitForInput() throws InterruptedException {
			Thread.sleep(3000);
		}
	}
}

Measured memory_bytes: 32564
#include<stdio.h>
int main() {
	int a;
	scanf("%d\n", &a);
	int b[20];
	for (int i = 0; i < a; i++){
		scanf("%d", &b[i]);
	}
	int c = 0;
	for (int i = 1; i < a-1; i++) {
		if (b[i - 1] < b[i] && b[i] <= b[i + 1] || b[i + 1] < b[i] && b[i] <= b[i - 1]) {
			c = c + 1;
		}
	}
	printf("%d", c);
	return 0;
}

Measured memory_bytes: 128
import java.util.*;

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

        Scanner sc = new Scanner(System.in);
        char[] a = sc.next().toCharArray();
        char[] b = sc.next().toCharArray();
        int n = a.length;
        int res = 0;
        for(int i=0; i<n; i++) {
            if(a[i] != b[i]) res++;
        }

        System.out.println(res);

    }

}

Measured memory_bytes: 42100
#include <iostream>
#include <bits/stdc++.h>
#include <algorithm>
#include <vector>
#include <cmath>
#include <string>
#include <unordered_map>
#include <map>
#include <set>
#include <unordered_set>
#include <sstream>
typedef long long ll;
#define F first
#define S second
#define PB push_back
#define MP make_pair

using namespace std;


int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    //for writing to files
    //freopen('input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    int N, K, X, Y;
    cin >> N;
    cin >> K;
    cin >> X;
    cin >> Y;
    K = min(N, K);
    cout << X * K + (N-K) * Y;

    return 0;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
 
import math
import itertools
import sys
import copy
 
# 入力
#A, B, C, D = map(int, input().split())
#L = list(map(int, input().split()))
#S = list(str(input()))
#N = int(input())
A, B, K = map(int, input().split())

if A+B <= K :
  print ("0 0")
  exit()

if A >= K :
  print (str(A-K) + " " + str(B))
  exit()
elif A+B > K :
  print ("0 " + str(B-(K-A)))
  
  



Measured memory_bytes: 38384
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <stack>
#include <numeric>
#include <algorithm>
#include <stdio.h>
#include <bitset>
#include <limits.h>
#include <complex>
#include <deque>
#include <iomanip>
using namespace std;
#define MM 1000000000
#define MOD MM+7
#define pi pair<int32,int32>
#define pl pair<int64,int64>
#define chmax(a,b) (a<b ? a=b:0)
#define chmin(a,b) (a>b ? a=b:0)
#define en cout << endl //セミコロンつけろ
const long double PI = acos(-1);
const long long INF = 1e15;
int dx[8] = {-1,0,1,0,-1,-1,1,1};
int dy[8] = {0,-1,0,1,-1,1,1,-1};
template<typename T>
T GCD(T u,T v){
    return v ? GCD(v,u%v) : u;
}
template<typename T>
T LCM(T x,T y){
    T gc = GCD(x,y);
    return x*y/gc;
}

long long pow_mod(long long n,long long k,long long m){
    if (k == 0){
        return 1;
    } else if (k % 2 == 1){
        return pow_mod(n,k-1,m)*n % m;
    } else {
        long long t = pow_mod(n,k/2,m);
        return t*t % m;
    }
}

set<int> st;
vector<int> v;

void dfs(int a){
    int sz = v.size();
    for(int i = 0; i < sz; i++){
        if (st.find(v[i] + a) == st.end()){
            st.insert(v[i]+a);
            v.push_back(v[i]+a);
        }
    }
    v.push_back(a);
}
int main(){
    for(int i = 1; i <= 9; i++){
        for(int j = 1; j <= 9; j++){
            cout << i << "x" << j << "=" << i*j << endl;
        }
    }
    //en;
}
  




Measured memory_bytes: 3108
n = int(input())
a = []
first = 0
second = 0
for i in range(n):
    temp = int(input())
    a.append(temp)
    if i == 0:
        first = temp
    else:
        if temp >= first:
            second = first
            first = temp
        elif temp >= second:
            second = temp
for i in range(n):
    if a[i] == first:
        print(second)
    else:
        print(first)

Measured memory_bytes: 12512
const stdin = require('fs').readFileSync('/dev/stdin', 'utf8')

const _n = stdin.trim().split('\n')
const n = Number(_n)

const ans = _ => {
  if (n < 4) return 'No'
  for (let i = 0; 4 * i <= n; i++) {
    for (let j = 0; 7 * j <= n; j++) {
      const ab = 4 * i + 7 * j
      if (ab === n) return 'Yes'
    }
  }
  return 'No'
}

console.log(ans())


Measured memory_bytes: 7372
#!/usr/bin/env python3
import collections as cl
import math
import sys


def II():
    return int(sys.stdin.readline())


def MI():
    return map(int, sys.stdin.readline().split())


def LI():
    return list(map(int, sys.stdin.readline().split()))


def main():
    N = II()
    print(math.ceil(N / 2))


main()


Measured memory_bytes: 65100
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
const int INF=1e9,MOD=1e9+7,ohara=1e6+10;
const ll LINF=1e18;
using namespace std;

#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(int i=(a);i<(b);i++)
#define rrrep(i,a,b) for(int i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout<<(x)<<endl
#define doublecout(a) cout<<fixed<<setprecision(15)<<a<<endl;
#define Cerr(x) cerr<<(x)<<endl
#define fi first
#define se second
#define P pair<ll,ll> 
#define m_p make_pair
#define V vector<ll> 

ll n,cnt,ans,a,b,c,d,tmp,tmpp,m,h,w,x,y,sum,pos,k;
ld doua;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
//int dy[]={-1,0,1,-1,1,-1,0,1};
//int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"),s;
bool fl;
struct edge{int to,cost;};

//-------------------------↓↓↓↓↓↓------------------------

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

    cin>>n;
    cnt=1;
    while(1){
        if((cnt+1)*(cnt+1)>n)break;
        cnt++;
    }
    Cout(cnt*cnt);
    return 0;
}


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

using ll = long long int;
using P = std::pair<int, int>;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rag(con) std::begin(con), std::end(con)

int main()
{
    int m, k;

    std::cin >> m >> k;

    int x = 1;

    rep(i, m)
        x *= 2;

    if (k >= x)
        std::cout << -1 << std::endl;
    else if (m == 1)
    {
        if (k == 0)
            std::cout << "0 0 1 1" << std::endl;
        else
        {
            std::cout << -1 << std::endl;
        }
    }
    else
    {
        rep(i, x)
        {
            if (i != k)
                std::cout << i << ' ';
        }
        std::cout << k << ' ';
        for (int i = x - 1; i >= 0; --i)
        {
            if (i != k)
                std::cout << i << ' ';
        }
        std::cout << k << ' ' << std::endl;
    }

    return 0;
}

Measured memory_bytes: 3592
#include <iostream>
#include <string>
#include <vector>
#include <climits>
#include <algorithm>
#include <set>
#include <unordered_map>
#include <queue>
#include <iomanip>
#include <map>

#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define P pair<int, int>
#define ll long long

using namespace std;
int mod = 1000000007;

int N;
vector<P> X;
vector<P> Y;
vector<P> graph[100005];

int main() {

  cin >> N;

  rep(i, N) {
    int x, y;
    cin >> x >> y;
    X.emplace_back(x, i);
    Y.emplace_back(y, i);
  }

  sort(X.begin(), X.end());
  sort(Y.begin(), Y.end());

  rep(i, N-1) {
    int len = X.at(i+1).first - X.at(i).first;
    int u = X.at(i+1).second;
    int v = X.at(i).second;
    graph[u].emplace_back(v, len);
    graph[v].emplace_back(u, len);

    len = Y.at(i+1).first - Y.at(i).first;
    u = Y.at(i+1).second;
    v = Y.at(i).second;
    graph[u].emplace_back(v, len);
    graph[v].emplace_back(u, len);
  }

  ll ans = 0;
  priority_queue<P, vector<P>, greater<>> que;
  vector<bool> used(N);
  que.emplace(0, 0);

  while (!que.empty()) {
    P pair = que.top(); que.pop();
    int u = pair.second;
    if (used.at(u)) continue;
    used.at(u) = true;
    ans += pair.first;
    for (auto e : graph[u]) {
      if (!used.at(e.first)) {
        que.emplace(e.second, e.first);
      }
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 10860
ans = 0
number = set()
def exsearch(s, i, N, A):
    if i == N:
        global ans
        mul = 1
        for i in range(N):
            if s[i] == "0":
                mul *= A[i]

            elif s[i] == "1":
                    mul *= (A[i] - 1)

            elif s[i] == "2":
                    mul *= (A[i] + 1)

        if mul % 2 == 0:
            ans += 1

    else:
        for c in ["0", "1", "2"]:
            exsearch(s + c, i + 1, N, A)

def main():
    N = int(input())
    A = [int(a) for a in input().split()]

    exsearch("", 0, N, A)

    print(ans)

if __name__ == "__main__":
    main()

Measured memory_bytes: 9104
#include<cstring>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<map>
#include<set>
#include<vector>
#include<queue>
using namespace std;
const int N=55;
typedef pair<int,int> P;
struct T{
    int x,y;
}p[N];
int main()
{
    int n,m,x,y,sz[N];
    while(~scanf("%d%d",&n,&m)){
        map<P,int>mp;
        map<int,vector<int> >mv;
        for(int i=0;i<m;i++){
            scanf("%d%d",&x,&y);
            p[i].x=x;
            p[i].y=y;
            mp[P(max(x,y),min(x,y))]=1;
            mv[x].push_back(y);
            mv[y].push_back(x);
        }
        int ans=0;
        for(int i=0;i<m;i++){
            memset(sz,0,sizeof(sz));
            mp[P(max(p[i].x,p[i].y),min(p[i].x,p[i].y))]=0;
            sz[p[i].x]=1;
            queue<int>q;
            q.push(p[i].x);
            while(!q.empty()){
                int now=q.front();
                q.pop();
                for(vector<int>::iterator it=mv[now].begin();it!=mv[now].end();it++){
                    if(!sz[*it]&&mp[P(max(now,*it),min(now,*it))]){
                        sz[*it]=1;
                        q.push(*it);
                    }

                }
            }
            for(int i=1;i<=n;i++)
                if(!sz[i]){
                    ans++;
                    break;
                }
            mp[P(max(p[i].x,p[i].y),min(p[i].x,p[i].y))]=1;
        }
        printf("%d\n",ans);
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
	int a,b;
	cin >> a >> b;
	if(a==1)a=14;
	if(b==1)b=14;
	if(a>b){
		cout << "Alice" << endl;
	}else if(a<b){
		cout << "Bob" << endl;
	}else{
		cout << "Draw" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repk(i, k, n) for (int i = k; i < n; i++)
#define MOD 1e9 + 7
#define INF 1e9
#define PIE 3.14159265358979323

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;
}
template <class T>
T GCD(T a, T b) {
    if (b == 0)
        return a;
    else
        return GCD(b, a % b);
}
template <class T>
inline T LCM(T a, T b) {
    return (a * b) / GCD(a, b);
}

int main() {
    int n, m;
    cin >> n >> m;
    vector<int> ss(m);
    int k, a;
    rep(i, n) {
        cin >> k;
        rep(j, k) {
            cin >> a;
            a--;
            ss[a]++;
        }
    }
    int count = 0;
    rep(i, m) {
        if (ss[i] == n)
            count++;
    }
    cout << count << endl;
}

Measured memory_bytes: 256
import collections
import functools
import math

n = int(input())
l = list(map(int, input().split(" ")))
c = collections.Counter(l)
m ={}
def f(n , r):
    if (n, r) in m:
        return m[(n,r)]
    if (n < r):
        return 0
    tmp = math.factorial(n) // (math.factorial(n-r) * math.factorial(r))
    m[(n, r)] = tmp
    return tmp


total = functools.reduce(lambda x, y : x + f(y, 2), c.values(), 0)

for i in l:
    print(total - f(c.get(i, 0), 2) + f(c.get(i, 0) - 1, 2))

Measured memory_bytes: 120284
#include <bits/stdc++.h>
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
#define x first
#define y second
using namespace std;

const int N = 4007;

int n, k, x, y, pw[N][N], pb[N][N];
char c;

int sw(int i, int j) {
	return pw[i + k][j + k] - pw[i + k][j] - pw[i][j + k] + pw[i][j];
}
int sb(int i, int j) {
	return pb[i + k][j + k] - pb[i + k][j] - pb[i][j + k] + pb[i][j];
}

signed main() {
#ifdef LC
    assert(freopen("input.txt", "r", stdin));
#endif
    ios::sync_with_stdio(0), cin.tie(0);
	
	cin >> n >> k;
	while (n--) {
		cin >> x >> y >> c;
		x %= 2 * k; ++x;
		y %= 2 * k; ++y;
		for (int i = 0; i < 2; ++i) {
			for (int j = 0; j < 2; ++j) {
				if (c == 'W') {
					++pw[x + 2 * i * k][y + 2 * j * k];
				} else {
					++pb[x + 2 * i * k][y + 2 * j * k];
				}
			}
		}
	}
	for (int i = 1; i < N; ++i) {
		for (int j = 1; j < N; ++j) {
			pw[i][j] += pw[i - 1][j] + pw[i][j - 1] - pw[i - 1][j - 1];
			pb[i][j] += pb[i - 1][j] + pb[i][j - 1] - pb[i - 1][j - 1];
		}
	}

	int ans = 0;
	for (int i = 0; i < 2 * k; ++i) {
		for (int j = 0; j < 2 * k; ++j) {
			int cur = sb(i, j) + sb(i + k, j + k) + sw(i + k, j) + sw(i, j + k);
			ans = max(ans, cur);
		}
	}
	cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 125824
H, W, A, B = map(int, input().split())

ans = []

for i in range(B):
    lst = [1]*A + [0] *(W-A)
    print(*lst, sep='')
for i in range(H-B):
    lst = [0]*A + [1] *(W-A)
    print(*lst, sep='')


Measured memory_bytes: 5492
function main(input) {
    var line = input.split(/\r?\n/g);
    var arr = line[0].split(" ");
    const H = arr[0], N = arr[1];
    var A = line[1].split(" ").map(Number);
    var accum = 0;
    for (var i = 0; i < A.length; i++)
        accum += A[i];
    console.log(accum < H ? "No" : "Yes");
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 21192
def INT():
    return int(input())

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

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

from math import gcd

N = INT()
A = LI()
A.sort()
ans = A[0]

all_can_div = True

for i in range(1, N):
    A[i] = gcd(A[i], ans)
    
    if A[i] != ans and all_can_div:
        all_can_div = False

print(ans if all_can_div else min(A))

Measured memory_bytes: 85416
from itertools import product

N, M = map(int, input().split())
X = []
for i in range(N):
    x, y, z = map(int, input().split())
    X.append([x, y, z])

l = (-1, 1)

ans = 0
for i, j, k in product(*([l]*3)):
    xs = [x*i+y*j+z*k for x, y, z in X]
    xs.sort(reverse=True)
    ans = max(ans, sum(xs[:M]))
print(ans)

Measured memory_bytes: 3316
n = int(input())
a = []
m = -1
o = -1
for i in range(n):
    p = int(input())
    m = max(m, p)
    if m != o:
        num=i
    o=m
    a += [p]
anslist=[max(a)]*n
if a.count(max(a)) >= 2:
    for i in range(n):
        print(anslist[i])
else:
    a.pop(num)
    anslist[num] = max(a)
    for i in range(n):
        print(anslist[i])


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

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    
    int h, w, k;
    string s[10];
    int sum[11][1001];

    cin >> h >> w >> k;
    for(int i=0;i<h;++i) cin >> s[i];

    for(int i=0;i<=h;++i) sum[i][0] = 0;
    for(int j=0;j<=w;++j) sum[0][j] = 0;
    for(int i=1;i<=h;++i){
        for(int j=1;j<=w;++j){
            sum[i][j] = sum[i-1][j] + sum[i][j-1] - sum[i-1][j-1] + (s[i-1][j-1] - '0');
        }
    }

    for(int i=0;i<=h;++i){
        for(int j=0;j<=w;++j) cerr << sum[i][j] << " ";
        cerr << endl;
    }

    int ans = h + w - 2;
    for(int ptn=0;ptn<(1<<h-1);++ptn){
        vector<int> sep;
        sep.emplace_back(0);
        for(int i=0;i<h-1;++i){
            if((ptn>>i) & 1) sep.emplace_back(i+1);
        }
        sep.emplace_back(h);

        int cand = sep.size() - 2;
        int left = 0;
        for(int pos=1;pos<=w;++pos){
            vector<int> all, cur;
            for(size_t i=1;i<sep.size();++i){
                all.emplace_back(sum[sep[i]][pos] - sum[sep[i]][left ] - sum[sep[i-1]][pos] + sum[sep[i-1]][left ]);
                cur.emplace_back(sum[sep[i]][pos] - sum[sep[i]][pos-1] - sum[sep[i-1]][pos] + sum[sep[i-1]][pos-1]);
            }
            if(*max_element(cur.begin(), cur.end()) > k){ cand = h * w; break; }
            if(*max_element(all.begin(), all.end()) > k){ ++cand; left = pos-1; }
        }
        ans = min(ans, cand);
    }
    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

const long long INF = 1e18;
int n, m;
long long x;
vector<long long> C(15, 0);
vector< vector<long long> > A(15, vector<long long>(15, 0));

int main() {
    cin >> n >> m >> x;
    for(int i = 0; i < n; ++i) {
        cin >> C.at(i);
        for(int j = 0; j < m; ++j) {
            cin >> A.at(i).at(j);
        }
    }

    long long ansmin = INF;
    for(int bit = 0; bit < (1<<n); ++bit) {
        long long cans = 0;
        vector<long long> AA(m, 0);
        for(int i = 0; i < n; ++i) {
            if(bit&(1<<i)) {
                cans += C.at(i);
                for(int j = 0; j < m; ++j) {
                    AA.at(j) += A.at(i).at(j);
                }
            }
        }

        bool flg = true;
        for(int i = 0; i < m; ++i) {
            if(AA.at(i) < x) {
                flg = false;
                break;
            }
        }
        if(flg) {
            chmin(ansmin, cans);
        }
    }

    if(ansmin == INF) {
        cout << -1 << endl;
    }else {
        cout << ansmin << endl;
    }
}

Measured memory_bytes: 3632
{-# LANGUAGE BangPatterns #-}
import           Control.Exception           (assert)
import           Control.Monad
import           Control.Monad.Primitive
import qualified Control.Monad.ST            as ST
import qualified Data.Array.IO               as IO
import qualified Data.Array.ST               as ST
import qualified Data.Array.Unboxed          as A
import           Data.Bits
import qualified Data.ByteString.Char8       as BS
import           Data.Char
import           Data.Foldable
import           Data.List
import qualified Data.Map.Strict             as Map
import           Data.Maybe
import qualified Data.Sequence               as Seq
import qualified Data.Set                    as Set
import qualified Data.Vector                 as VB
import qualified Data.Vector.Mutable         as VBM
import qualified Data.Vector.Unboxed         as V
import qualified Data.Vector.Unboxed.Mutable as VM
import           Debug.Trace

readInt = fst . fromJust . BS.readInt
readIntList = map readInt . BS.words
getInt = readInt <$> BS.getLine
getIntList = readIntList <$> BS.getLine
getIntVec n = V.unfoldrN n (BS.readInt . BS.dropWhile isSpace) <$> BS.getLine

readInteger = fst . fromJust . BS.readInteger
readIntegerList = map readInteger . BS.words
getInteger = readInteger <$> BS.getLine
getIntegerList = readIntegerList <$> BS.getLine

inf :: Int
inf = 10^18

main = do
  n <- getInt
  s <- BS.getLine

  let solve i j k res | i == 10 = res
                      | k == 10 = solve i (j+1) 0 res
                      | j == 10 = solve (i+1) 0 k res
                      | otherwise = solve i j (k+1) (res + check i j k)

      c x = head (show x)

      check i j k = let x = BS.findIndex (== c i) s
                        s' = case x of
                          Just m  -> BS.drop (m+1) s
                          Nothing -> BS.pack ""
                        y = BS.findIndex (== c j) s'
                        s'' = case y of
                          Just m  -> BS.drop (m+1) s'
                          Nothing -> BS.pack ""
                        z = BS.findIndex (== c k) s''
                    in
                      case z of
                        Just m  -> 1
                        Nothing -> 0

  print $ solve 0 0 0 0


Measured memory_bytes: 3956
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 99999999999999999
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;




int main(){

	int H,W,S,T;

	scanf("%d %d %d %d",&H,&W,&S,&T);

	if((H%2)==0 || (W%2 == 0)){

		printf("Yes\n");

	}else{

		if((S+T)%2 == 1){

			printf("No\n");

		}else{

			printf("Yes\n");
		}
	}

	return 0;
}



Measured memory_bytes: 3168
<?php
class main {
    function run() {
        fscanf(STDIN, "%d", $n);
        $line = trim(fgets(STDIN));
        $p_arr = explode(" ", $line);

        $d = $n + 1;

        $a_arr = array();
        $b_arr = array();
        $r_arr = array();

        foreach ($p_arr as $k => $v) {
            $r_arr[$v] = $k;
        }

        for ($i = 1; $i <= $n; $i++) {
            $a_arr[] = $i * $d;
            $b_arr[] = ($n - $i) * $d + $r_arr[$i] + 1;
        }

        echo implode(" ", $a_arr) . "\n";
        echo implode(" ", $b_arr);
    }
}

$object = new main();
$object->run();


Measured memory_bytes: 16648
h,w=map(int,input().split())

s=[]
s.append("."*(w+2))
for i in range(h):
    s.append("."+input()+".")
s.append("."*(w+2))

#print(s)
k=[]
for i in range(h):
    p=[]
    for j in range(w):
        cnt=0
        if s[i+1][j+1]==".":
            if s[i][j]=="#":
                cnt+=1
            if s[i][j+1]=="#":
                cnt+=1
            if s[i][j+2]=="#":
                cnt+=1
            if s[i+1][j]=="#":
                cnt+=1
            if s[i+1][j+2]=="#":
                cnt+=1
            if s[i+2][j]=="#":
                cnt+=1
            if s[i+2][j+1]=="#":
                cnt+=1
            if s[i+2][j+2]=="#":
                cnt+=1
            p.append(cnt)
        else:
            p.append("#")
    k.append(p)
    
for i in range(h):
    for j in range(w):
        print(k[i][j],end="")
    print()
    
        


Measured memory_bytes: 3572