akhauriyash/Code-Regression huggingface dataset:
input_value = input()

n = int(input_value)

numbers = range(1, n + 1)

multiples_of_three = [i for i in numbers if i % 3 == 0]

numbers_with_three = [i for i in numbers if '3' in str(i)]

related_three = multiples_of_three + numbers_with_three

related_three.sort()

sorted_related_three = sorted(set(related_three), key=related_three.index)

multiples_and_with_three_strings = list(map(str, sorted_related_three))

print(' ' + ' '.join(multiples_and_with_three_strings))



Measured memory_bytes: 6548
let () = Scanf.scanf "%d %d %d %d\n" @@ fun n a b c ->
  let ls = Array.init n @@ fun _ -> Scanf.scanf "%d\n" @@ fun l -> l in
  Array.fold_left (fun (candidates : (int * int * int * int) list) l ->
    List.concat @@ List.map (fun (n, a, b, c) ->
      [(n, a, b, c);
       (n + (if 0 < a then 10 else 0), a + l, b, c);
       (n + (if 0 < b then 10 else 0), a, b + l, c);
       (n + (if 0 < c then 10 else 0), a, b, c + l)]) candidates)
  [(0, 0, 0, 0)] ls
  |> List.filter (fun (n, a, b, c) -> 0 < a && 0 < b && 0 < c)
  |> List.map (fun (n, a', b', c') ->
      n + abs (a' - a) + abs (b' - b) + abs (c' - c))
  |> List.fold_left min max_int
  |> Printf.printf "%d\n"

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

int solve(int x,int y,vector< vector<int> > a,int ma)
{
    ma++;
    int bx[4]={1,0,-1,0},by[4]={0,1,0,-1};
    int p=ma;
    for(int i=0;i<4;i++){
        if(a[x+bx[i]][y+by[i]]==1){
            a[x][y]=0;
            ma=max(ma,solve(x+bx[i],y+by[i],a,p));
        }
    }
    return ma;
}

int main()
{
    int n,m;
    for(;;){
        cin >> n >> m;
        if(n==0&&m==0) break;
        vector< vector<int> > a(m+2);
        for(int i=0;i<n+2;i++)
            a[0].push_back(0);
        int in;
        for(int i=1;i<m+1;i++){
            a[i].push_back(0);
            for(int j=1;j<n+1;j++){
                cin >> in;
                a[i].push_back(in);
            }
            a[i].push_back(0);
        }
        for(int i=0;i<n+2;i++)
            a[m+1].push_back(0);
        int p=0;
        for(int i=1;i<m+1;i++)
            for(int j=1;j<n+1;j++){
                int ma=0;
                if(a[i][j]==0) continue;
                p=max(p,solve(i,j,a,ma));
            }
        cout << p << endl;
    }
    return 0;
}



Measured memory_bytes: 3892
// match n men with n women according to certain rules (adj matrix)
// connection at any moment, should depend on the current state (which men and women are left to match)
// state of women: use one/zero to describe each woman, you need n parameters to describe the state of all women/men, then you can do dp
// (2^n)^2 to describe states which is too much
// instead use men sequentially, and only record woman's state; if this way, woman's state can be used to deduce men's state
// 1D DP with 2^n states (bit mask) dont use n parameter, use 1 parameter with n bits 
// DP[i], i is a mask to describe which woman has been matched and which are remaining to match

#include<bits/stdc++.h>;
using namespace std;

int n;
vector<vector<int>> adj;
vector<long long> DP;
const int inf = (int)1e9 + 7;

int popcount(uint32_t m)
{
	int counter = 0;
	while (m != 0)
	{
		if (m & 1)
			counter++;
		m = m >> 1;
	}
	return counter;
}

int main()
{
	cin >> n;
	adj.resize(n);
	for (int i = 0; i < n; i++)
	{
		adj[i].resize(n);
		for (int j = 0; j < n; j++)
			cin >> adj[i][j];
	}

	DP.resize(1 << n, 0); //DP array with 2^n states;
	DP[0] = 1;
	for (int mask = 1; mask < (1 << n); mask++) // go over all states
	{
		// based on mask (availabitity of women) to deduce men's availability (always sequential)
		int a = n - popcount(mask); // first man left, if I match this man, I should reach a state DP[?] that has been calculated before
		for (int b = 0; b < n; b++) // iterate through woman and first available to match with a
		{
			if (adj[a][b] && ((mask >> b) & 1)) //a, b are connected, b is available
			{
				//match should mask bth woman as unavailable, also update counts
				DP[mask] = (DP[mask] + DP[mask & (~(1 << b))])%inf;    //new state, set bth woman as used
			}
		}
	}
	cout << DP[(1<<n)-1] << endl;
}

Measured memory_bytes: 19604
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <iomanip>
#include <stack>
#include <queue>
#include <numeric>
#include <map>
#include <unordered_map>
#include <set>
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define pb push_back
#define mod 1000000007
using ll = long long;
using namespace std;

int main(){
  ll A,B,AB,X,Y;
  cin >> A >> B >> AB >> X >> Y;
  ll ans = 1e18;
  for(ll ab=0;ab<=max(X,Y)*2;ab++){
    ll preans;
    ll a = max((ll)0,X - ab/2);
    ll b = max((ll)0,Y - ab/2);
    preans = A*a+B*b+AB*ab;
    //cout << ab << " " << preans << endl;
    ans = min(ans,preans);
  }
  cout << ans << endl;
  return 0;
}


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

int main () {
  
  long long N, W;
  cin >> N >> W;
  
  vector<long long> weight(N);
  vector<long long> value(N);
  for (long long i = 0; i < N; i++) cin >> weight[i] >> value[i];
  
  vector<vector<long long>> dp(N + 1, vector<long long>(100010, INF));
  
  dp[0][0] = 0;
  
  for (long long i = 0; i < N; i++) {
    for (long long v = 0; v <= 100010; v++) {
      if (v <= value[i]) dp[i + 1][v] = min(dp[i][v], weight[i]);
      else dp[i + 1][v] = min(dp[i][v], dp[i][v - value[i]] + weight[i]);
    }
  }
  
  for (long long v = 0; ; v++) {
    if (dp[N][v] > W) {
      cout << v - 1 << endl;
      break;
    }
  }
  
}

Measured memory_bytes: 80256
n = int(input())
if n %10 == 2 or n %10 == 4 or n %10 == 5 or n %10 == 7 or n %10 == 9:
    print('hon')
elif n %10 == 0 or n %10 == 1 or n %10 == 6 or n %10 == 8:
    print('pon')
else:
    print('bon')

Measured memory_bytes: 9116
#include<bits/stdc++.h>
using namespace std;
int main(){
  string s;
  cin>>s;
  for(int i=0;i<s.size();i+=2)
    if(s[i]!='h'||s[i+1]!='i'){
      cout<<"No"<<endl;
      return 0;
    }
  cout<<"Yes"<<endl;
  return 0;
}

Measured memory_bytes: 256
N = int(input())
S = [input() for i in range(N)]
M = int(input())
T = [input() for _ in range(M)]
S1 = set(S)
result = []

for a in S1:
    if a not in T:
        result.append(S.count(a))
    else:
        if S.count(a) >= T.count(a):
            result.append(S.count(a) - T.count(a))

if not result:
    print(0)
else:
    print(max(result))

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define pii pair<int,int>
using namespace std;
long long mod=1000000007;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    int t=1;//cin>>t;
    while(t--)
    {
        int n;cin>>n;
        int a[n];
        for(int i=0;i<n;i++) cin>>a[i];
        sort(a,a+n);
        if(n==1 || n==2) cout<<0<<endl;
        else
        {
          int ans=0;
          for(int i=0;i<n-2;i++)
          {
              for(int j=i+1;j<n-1;j++)
              {
                  for(int k=j+1;k<n;k++)
                  {
                      if(a[i]+a[j]>a[k] && a[i]!=a[j] && a[j]!=a[k] && a[i]!=a[k]) ans++;
                  }
              }
          }
          cout<<ans<<endl;
        }
    }
    return 0;
}


Measured memory_bytes: 3656
#include <bits/stdc++.h>
#define rep(i,n)    for(long long i = 0; i < (n) ; ++i)
#define orep(i,n)   for(long long i = 1; i <= (n); ++i)   // one rep
#define drep(i,n)   for(long long i = (n)-1; i >= 0; --i) // down rep
#define srep(i,s,t) for(long long i = (s); i < (t); ++i)  // set rep
#define rng(x)  (x).begin(),(x).end()

  // range
#define rrng(a) (a).rbegin(),(a).rend() // reverse range
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define ru(x,y) (((x)+(y)-1)/(y)) // round up
#define fi first
#define se second
#define eb emplace_back
#define fcout cout << fixed << setprecision(15)


using namespace std;
using ll  = long long;
using P   = pair<int,int>;
using vi  = vector<int>;
using vvi = vector<vi>;
using vp  = vector<P>;
using vl  = vector<ll>;

template<typename T> void Yes(T flag) {
  cout << (flag ? "Yes" : "No") << endl;
}

template<typename T> void pv(vector<T> vec) {
  cout << "[";
  for(auto& v : vec) { cout << v << ","; }
  cout << "]" << endl;
}

template<>
void pv(vector<P> vec) {
  cout << "[";
  for(auto& v : vec) {
    cout << "<" << v.fi << ","<< v.se << ">" << ",";
  }
  cout << "]" << endl;
}

template<typename T> void pv2(vector<vector<T>> vec) {
  for(auto& v : vec) pv(v);
}

int main() {
  ll x,y;
  cin >> x >> y;
  ll a=x;
  ll ans = 0;
  while(a<=y) {
    a*=2;
    ans++;
  }
  cout << ans << endl;

  return 0;
}


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

#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
    cerr << *it << " = " << a << endl;
    err(++it, args...);
}

void code() {
    int n,x,y;
    cin>>n>>x>>y;
    int ans=0;
    vector<int> distx(n+1);
    vector<int> disty(n+1);
    vector<vector<int> > adj(n+1, vector<int>(n+1));
    for(int i=1; i<=n; i++) {
        for(int j=1; j<=n; j++) {
            adj[i][j] = min(abs(i-j), min(abs(i-x)+1+abs(j-y), abs(j-x)+1+abs(i-y)));
        }
    }
    vector<int> dist(n);
    for(int i=1; i<=n; i++) {
        for(int j=1; j<=n; j++) {
            dist[adj[i][j]]++;
        }
    }

    for(int i=1; i<n; i++)
        cout << dist[i]/2 << '\n';
}

signed main() {
    std::ios_base::sync_with_stdio(false);
    int t=1;
    // cin>>t;
    for(int i=0; i<t; i++) {
        code();
    }
}


Measured memory_bytes: 19032
# 今日の曜日を表す文字列 S が与えられます。
# Sは SUN,MON,TUE,WED,THU,FRI,SAT のいずれかであり、
# それぞれ日曜日、月曜日、火曜日、水曜日、木曜日、金曜日、土曜日を表します。
# 次の日曜日 (あす以降) が何日後か求めてください。

# 入力: 入力は以下の形式で標準入力から与えられる。
# S
# 出力: 次の日曜日が何日後か出力せよ。

week = input()
if week == 'SAT':
    result = 1
elif week == 'FRI':
    result = 2
elif week == 'THU':
    result = 3
elif week == 'WED':
    result = 4
elif week == 'TUE':
    result = 5
elif week == 'MON':
    result = 6
elif week == 'SUN':
    result = 7

print(result)

Measured memory_bytes: 9004
import java.util.*;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        Integer A[] = new Integer[N];
        for (int i = 0; i < N; ++i) {
            A[i] = sc.nextInt();
        }
        int ans = Integer.MAX_VALUE;
        for (int a : A) {
            int cnt = 0;
            while (a % 2 == 0) {
                ++cnt;
                a /= 2;
            }
            ans = Integer.min(ans, cnt);
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 21844
package main

import (
	"bufio"
	"fmt"
	"io"
	"math"
	"os"
	"strconv"
	"strings"

)

func main() {
	solve(os.Stdin, os.Stdout)
}

type ReaderEx struct {
	baseScanner *bufio.Scanner
	words       []string
	nextWordIdx func() int
	initWordIdx func()
}

func NewScannerEx(stdin io.Reader) *ReaderEx {
	var this ReaderEx
	var idx int
	this.baseScanner = bufio.NewScanner(stdin)
	this.baseScanner.Buffer(make([]byte, 0), 1E+11)
	this.nextWordIdx = func() int {
		cur := idx
		idx++
		return cur
	}
	this.initWordIdx = func() {
		idx = 0
	}
	return &this
}

func (me *ReaderEx) ScanAndSplit() (isScanned bool) {
	isScanned = me.baseScanner.Scan()

	me.words = strings.Fields(me.baseScanner.Text())
	me.initWordIdx()
	return
}

func (me *ReaderEx) Scan() (ok bool) {
	ok = me.baseScanner.Scan()
	return
}
func (me *ReaderEx) getString() string {
	return me.baseScanner.Text()
}

func (me *ReaderEx) getInt() int {
	n, err := strconv.Atoi(me.baseScanner.Text())
	defer func() {
		if err != nil {
			panic(err)
		}
	}()

	return n
}

func (me *ReaderEx) nextBytes() []byte {
	return []byte(me.words[me.nextWordIdx()])
}
func (me *ReaderEx) nextString() string {
	return me.words[me.nextWordIdx()]
}

type StringArray []string

func (me *ReaderEx) nextStringArray() StringArray {
	return me.words[me.nextWordIdx():]
}

func (me StringArray) toStrings() []string {
	return me
}

func (me StringArray) toInts() []int {
	strValues := me.toStrings()
	values := make([]int, len(strValues))
	for i, v := range strValues {
		n, err := strconv.Atoi(v)
		if err != nil {
			panic(err)
		}
		values[i] = n
	}
	return values
}
func (me *ReaderEx) nextInt() int {
	n, err := strconv.Atoi(me.words[me.nextWordIdx()])

	defer func() {
		if err != nil {
			panic(fmt.Sprintf("getInt(%d)", n))
		}
	}()
	return n
}

func pow(x, y, mod int) (ans int) {

	ans = 1
	for bit := 1 << uint(math.Floor(math.Log2(float64(y)))); ; bit >>= 1 {
		if y&bit != 0 {
			ans *= x
			if mod > 0 {
				ans %= mod
			}
		}
		if bit <= 1 {
			return
		}
		ans *= ans
		if mod > 0 {
			ans %= mod
		}
	}
}

type factType struct {
	prime int
	count int
}

func fact(n int) (facts []factType) {

	for i := 2; i*i <= n; i++ {
		if n%i == 0 {
			fa := factType{prime: i}
			for n%fa.prime == 0 {
				n /= fa.prime
				fa.count++
			}
			facts = append(facts, fa)
		}
	}
	if n > 1 {
		facts = append(facts, factType{prime: n, count: 1})
	}
	return facts
}
func dec2bin(n int) (ret []bool) {
	for bit := 1 << uint(math.Floor(math.Log2(float64(n)))); ; bit >>= 1 {
		ret = append(ret, n&bit != 0)

		if bit <= 1 {
			return
		}
	}

}

func abs(v int) int {
	if v < 0 {
		v = -v
	}
	return v
}

type kv struct {
	key   int
	value int
}

func b2i(b bool) (i int) {
	if b {
		i = 1
	} else {
		i = 0
	}
	return
}

func solve(stdin io.Reader, stdout io.Writer) {

	r := NewScannerEx(stdin)
	r.Scan()
	r.getInt()
	r.ScanAndSplit()
	a := r.nextStringArray().toInts()

	ok := b2i(true)
	for _, v := range a {
		ok ^= b2i(v%2 == 1)
	}

	fmt.Fprintln(stdout, []string{"NO", "YES"}[ok])

}



Measured memory_bytes: 5248
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
bool sortbysec(const pair<int,int> &a,
              const pair<int,int> &b)
{
    return (a.second < b.second);
}
int main()
{
    ll n,k;
    cin>>n>>k;
    ll ar[n+1];
    ar[0]=0;
    for(ll i=1;i<=n;++i)
    {
        cin>>ar[i];
    }
    ll dp[n+1];
    ll minm=INT_MAX;
    dp[0]=0;
    dp[1]=0;
    for(ll i=2; i<=n; ++i)
    {
        minm=INT_MAX;
        for(int j=1;j<=k;j++)
        {
            if(i-j>=1)
            {
                if((dp[i-j] + abs(ar[i-j]-ar[i]))<minm)
                {
                    minm = dp[i-j] + abs(ar[i-j]-ar[i]);
                }
             }
            else
                    break;
        }
            dp[i]=minm;
            //cout<<dp[i]<<" ";
    }
    //cout<<endl;
    cout<<dp[n];

    return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define rep(i, N) for (long long i = 0; i < N; i++)
using ll = long long;

void solve(long long A, long long B) { cout << A * B << endl; }

int main() {
    long long A;
    scanf("%lld", &A);
    long long B;
    scanf("%lld", &B);
    solve(A, B);
    return 0;
}


Measured memory_bytes: 3684
#include <cstdio>
#include <algorithm>
#include <set>
using namespace std;

const int N = 100500;

set<pair<int, int>> pts;

set<pair<int, int>> inter;

typedef long long llong;

llong cnt[10];

int main() {
    int h, w, n;
    scanf("%d %d %d", &h, &w, &n);
    for (int i = 0; i < n; i++) {
        int x, y;
        scanf("%d %d", &y, &x);
        pts.insert(make_pair(x, y));
        for (int dx = -1; dx <= 1; dx++) {
            for (int dy = -1; dy <= 1; dy++) {
                inter.insert(make_pair(x + dx, y + dy));
            }
        }
    }
    for (auto pr : inter) {
        int x = pr.first;
        int y = pr.second;
        if (x <= 1 || y <= 1 || x >= w || y >= h)
            continue;
        int c = 0;
        for (int dx = -1; dx <= 1; dx++) {
            for (int dy = -1; dy <= 1; dy++) {
                c += pts.count(make_pair(x + dx, y + dy));
            }
        }
        if (c != 0)
            cnt[c]++;
    }
    cnt[0] = (h - 2) * 1ll * (w - 2) - accumulate(cnt + 1, cnt + 10, 0ll);
    for (int i = 0; i < 10; i++) {
        printf("%lld\n", cnt[i]);
    }
}


Measured memory_bytes: 47104
#require 'prime'
#require 'openssl'
MOD=10**9+7;  cnt=0; sum=0; prev=nil; can=true; h=Hash.new(0)
def gs() gets.chomp end
def gi() gets.chomp.to_i end
def gsmi() gets.chomp.split.map(&:to_i) end

def ar2(s1,s2,de=nil) Array.new(s1){Array.new(s2,de)} end
def ar3(s1,s2,s3,de=nil) Array.new(s1){Array.new(s2){Array.new(s3,de)}} end

def desc(ar) ar.sort!{|x,y| y<=>x} end
def min(a,b) a<=b ? a : b end
def max(a,b) a>=b ? a : b end
def sum(ar) ar.inject(:+).to_i end
def ceil(a,b) (a.to_f/b).ceil end

def C(a,b) b==0||a==b ? 1 : (b=a-b if a/2<b;(a-b+1..a).inject(:*)/(1..b).inject(:*)) end
def rui(ar) s=[0]; ar.size.times{|i| s<<s[-1]+ar[i]}; s end
def rev_rui(ar) s=[0]; ar.size.times.reverse_each{|i| s<<s[-1]+ar[i]}; s end

def puts_yesno(b) puts(b ? 'Yes' : 'No') end
def putsend(s) puts s; exit end
def pu(h) begin; require './../nemi_lib/debug.rb'; puts_val(h); rescue LoadError; end; end
########### ( ˘ω˘ )ｽﾔｧ… ###########
n, m, x = gsmi
c = []
a = []
n.times do |i|
  inp = gsmi
  c << inp.shift
  a << inp
end

prices=[]

0.upto(2**n) do |i|
  # 1001001000 みたいなパターンを作って、1の部分は買う、0は買わない
  price = 0
  skill = Array.new(m, 0)
  n.times do |j|
    if i[j] == 1
      price = price + c[j]
      m.times do |k|
        skill[k] += a[j][k]
      end
    end
  end
  if skill.min >= x
    prices << price
  end
end

if prices.size==0
  puts -1
else
  puts prices.min
end

Measured memory_bytes: 14604
n = gets.to_i
ary = gets.split.map(&:to_i)

cnt1 = 0
cnt2 = 0
cnt4 = 0

ary.each do |a|
  if a % 4 == 0
    cnt4 += 1
  elsif a % 2 == 0
    cnt2 += 1
  else
    cnt1 += 1
  end
end

puts cnt2 % 2 + cnt1 <= cnt4 + 1 ? :Yes: :No

Measured memory_bytes: 8452
#include<stdio.h>

int main(){
  int a,b,c,i,ans = 0;

  scanf("%d %d %d",&a,&b,&c);

  for(i = a; i<=b; ++i){
    if(c % i == 0){
      ++ans;
    }
  }

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



Measured memory_bytes: 2108
#include<iostream>
#include<string>

using namespace std;
int main(){
    int n, l;
    cin >> n >> l;
    int ans;
    if (l >= 0)
        ans = ((l+1)+(l+n-1))*(n-1)/2;
    else if (l+n-1 >= 0)
        ans = (l+(l+n-1))*n/2;
    else
        ans = (l+(l+n-2))*(n-1)/2;
    cout << ans << 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 rep2(i, n) for (int i = 1; i <= (int)(n); i++)

int main(){
  int X, Y;
  cin >> X >> Y;
  cout << X + Y / 2 << endl;
}

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


#define rep(i,a,b) for(ll i=ll(a);i<ll(b);i++)
#define irep(i,a,b) for(ll i=ll(a);i>=ll(b);i--)
#define pb push_back
#define mp make_pair
#define pll pair<ll,ll>
#define endl "\n"
using ll=long long;
using ld=long double;
using namespace std;
const ll mod=1e9+7;
ll GCD(ll a, ll b) { return b ? GCD(b, a%b) : a; }

ll a[220000],b[220000];
map<ll,ll> c;
main(){
    ll n,h,w,ans=0;
    cin>>h>>w>>n;
    ll c=labs(h-w);
    if(h<w)swap(h,w);
    ans=ceil((ld)n/h);
    cout<<ans;
}

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

int main()
{
    int ch[500000];
    char kh[1000000],arr[1000000];
    int a=0,b=0,c,d,e,i=0,j=0,k=0,l=0,tep,temp,m,n,x,y;

    scanf("%d",&a);

    
   printf("%d\n",a+a*a+a*a*a);
        
   

    return 0;
}

Measured memory_bytes: 1708
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
	int n;
	cin>>n;
	int a[n],b[n],c[n];

	for(int i=0;i<n;i++)
		cin>>a[i]>>b[i]>>c[i];

	ll dp[n][3];
	dp[0][0]=a[0];dp[0][1]=b[0];dp[0][2]=c[0];
	for(int i=1;i<n;i++)
	{
		dp[i][0]=a[i]+max(dp[i-1][1],dp[i-1][2]);
		dp[i][1]=b[i]+max(dp[i-1][2],dp[i-1][0]);
		dp[i][2]=c[i]+max(dp[i-1][1],dp[i-1][0]);
	}
	cout<<max(dp[n-1][0],max(dp[n-1][1],dp[n-1][2]));

	

}

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

#define pb push_back
typedef long long int ll;
typedef vector<ll> vl;
typedef map<ll,ll> ii;
typedef map<ll,vl> grp;



int main() {
    ios_base::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
    ll x;cin>>x;
    
    cout<<(x*(x-1))/2;
    return 0;
}
    

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int q,_max;
long long n,m,res;
const int P=1e9+7;
inline int mod(long long x){
	return x>=P?x%P:x;
}
void dfs(long long a,long long b,int val,int ty){
	if(a>n||b>m)	return ;
	if(a>m||a+b>n){
		if(val<_max)	return ;
		if(val>_max)	_max=val,res=0;
		if(a<=m)	res=mod(res+(m-a)/b+1);
		_max=max(_max,val),res=mod(res+(n-a)/b+1);
		return ;
	}
	if(!ty)	dfs(a+b,b,val,1);
	dfs(a+b,a,val+1,ty);
}
void solve(){
	if(n==1&&m==1){
		_max=1,res=1;
		return ;
	}
	dfs(2,1,1,0);
	if(_max==1)	res=(n%P*m%P)%P;
}
int main(){
	scanf("%d",&q);
	while(q--){
		scanf("%lld%lld",&n,&m);
		if(n<m)	swap(n,m);
		_max=res=0,solve();
		printf("%d %lld\n",_max,res);
	}
	return 0;
}


Measured memory_bytes: 3968
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define rep2(i,n) for(int i=0;i<=n;i++)
#define repr(i,a,n) for(int i=a;i<n;i++)
#define all(a) a.begin(),a.end()
#define P pair<long long,long long>
#define double long double
#define INF 1e10
#define MOD 1e9+7
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
using Graph = vector<vector<int>>;
signed main(){
  int a,b,c;
  cin>>a>>b>>c;
  vector<double> d(a),e(a);
  rep(i,a)
    cin>>d[i];
  rep(i,a){
    e[i]=b-0.006*d[i];
  }
  double f=1e9,w;
  rep(i,a){
    if(f>abs(e[i]-c)){
    f=abs(e[i]-c);
      w=i+1;
    }
   
      }
  cout<<w<<endl;
}


Measured memory_bytes: 3680
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
using p = pair<int,int>;
const long long INF = 1ll << 60;

bool IsPrime(int num){
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false; // 偶数はあらかじめ除く
    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2){
      if (num % i == 0){
        // 素数ではない
        return false;
      }
    }
    // 素数である
    return true;
}

int main(){
  int x; cin >> x;
  int ans = 0;

  while(true){
    if(IsPrime(x)) break;
    x++;
  }
  cout << x << endl;

  return 0;
}

Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
using Int = long long;
int PREP = (cin.tie(nullptr), ios::sync_with_stdio(false), cout << fixed << setprecision(9), 0);
//int SEGV = getenv("D") || (exit(system("D= SEGFAULT_SIGNALS=all catchsegv ./prog.exe") >> 8), 0);
int cdiv(int x, int y) {
    return (x + y - 1) / y;
}
string solve(int A, int B, int C, int D) {
    if (A < B) {
        string s = solve(B, A, A + B + 1 - D, A + B + 1 - C);
        reverse(begin(s), end(s));
        for (char &c : s) c ^= 'A' ^ 'B';
        return s;
    }
    int K = cdiv(A, B + 1);
    int ok = 0, ng = A + 1;
    while (ng - ok > 1) {
        int NA = (ok + ng) / 2;
        int NB = max(0, (NA - 1) / K);
        if (B - NB <= (Int)(A - NA + 1) * K) {
            ok = NA;
        } else {
            ng = NA;
        }
    }
    int NA = ok;
    int NB = max(0, (NA - 1) / K);
    string ans;
    for (int i = C - 1; i < D; i++) {
        if (i < NA + NB) {
            ans.push_back(i % (K + 1) != K ? 'A' : 'B');
        } else {
            int j = A + B - 1 - i;
            ans.push_back(j % (K + 1) != K ? 'B' : 'A');
        }
    }
    return ans;
}
int main() {
    int Q; cin >> Q;
    while (Q--) {
        int A, B, C, D; cin >> A >> B >> C >> D;
        cout << solve(A, B, C, D) << '\n';
    }
    return 0;
}

Measured memory_bytes: 3656
#include <bits/stdc++.h>
using namespace std;
//#include <boost/multiprecision/cpp_int.hpp>
//using multiInt = boost::multiprecision::cpp_int;

using ll = long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
template <typename Q_temp>
using smaller_queue = priority_queue<Q_temp, vector<Q_temp>, greater<Q_temp>>;

const ll MOD = (ll)(1e9 + 7);
const int INF = (int)1e9;
const ll LINF = (ll)4e18;
const double PI = acos(-1.0);

#define REP(i, m, n) for (ll i = m; i < (ll)(n); ++i)
#define rep(i, n) REP(i, 0, n)
#define MP make_pair
#define MT make_tuple
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible") << endl
#define possible(n) cout << ((n) ? "possible" : "impossible") << endl
#define Yay(n) cout << ((n) ? "Yay!" : ":(") << endl
#define all(v) v.begin(), v.end()
#define NP(v) next_permutation(all(v))
#define dbg(x) cerr << #x << ":" << x << endl;

vector<int> Dx = {0, 0, -1, 1, -1, 1, -1, 1, 0};
vector<int> Dy = {1, -1, 0, 0, -1, -1, 1, 1, 0};

int main()
{
  int n;
  cin >> n;
  vector<double> a(n);
  rep(i, n) cin >> a[i];
  double ave = accumulate(all(a), 0.0) / (double)n;
  int ans;
  double Min = INF;
  rep(i, n)
  {
    if (abs(a[i] - ave) < Min)
    {
      ans = i;
      Min = abs(a[i] - ave);
    }
  }
  cout << ans << endl;
  return 0;
}


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

int main() {
  
  int N,S,X,count;
  cin >> N >> S;
  count = 0;
  
  for (int a=1; a < 10; a++){
    for (int b=0; b < 10; b++){
       for (int c=0; c < 10; c++){
          X = 10001*a + 1010*b + 100*c;
          if (X>=N&& S>=X) count++;
       }
    }
      
  }
  
  cout << count << endl;
}


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

int main()
{
    long int n;
    cin>>n;
    long int a[n],gcd;
    for(long int i=0;i<n;i++)
    {
        cin>>a[i];
        if(i==0)
        gcd=a[i];
        else
        gcd=__gcd(gcd,a[i]);
    }
    int aa[1000001]={0};
    for(long int i=2;i<1000001;i++)
    {
        if(aa[i]==0)
        {
            long int j=i;
            aa[i]=i;
            while(j<=1000000)
            {
                aa[j]=i;
                j+=i;
            }
        }
    }
    int cnt[1000001]={0};
    bool chk=0;
    for(long int i=0;i<n;i++)
    {
        while(a[i]>1)
        {
            cnt[aa[a[i]]]++;
            if(cnt[aa[a[i]]]>1)
            chk=1;
            long int j=aa[a[i]];
            while(a[i]%j==0)
            {
                a[i]/=j;
            }
        }
    }
    if(gcd==1 && chk==0)
    {
        cout<<"pairwise coprime";
    }
    else if(gcd==1 && chk==1)
    {
        cout<<"setwise coprime";
    }
    else
    {
        cout<<"not coprime";
    }
}

Measured memory_bytes: 19220
from sys import stdin
nii=lambda:map(int,stdin.readline().split())
lnii=lambda:list(map(int,stdin.readline().split()))
from collections import Counter

n=int(input())
l=lnii()

def eratosthenes(lim):
  num=[1 for i in range(lim)]
  for i in set(l):
    if num[i]:
      for j in range(i+i,lim,i):
        num[j]=0
  return num

lim=10**6+5
num=eratosthenes(lim)

count=Counter(l)

ans=0
for i in l:
  if num[i]==1 and count[i]==1:
    ans+=1

print(ans)

Measured memory_bytes: 47568
#include<stdio.h>
int main(void){
  int i,j,num,ku[9][9];
  scanf("%d",&num);
  for(i=0;i<9;i++){
    for(j=0;j<9;j++){
      ku[i][j]=(i+1)*(j+1);
    }
  }
  for(i=0;i<9;i++){
    for(j=0;j<9;j++){
      if(ku[i][j]==num){
        printf("Yes");
        return 0;
      }
    }
  }
  printf("No");
  return 0;
}

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

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

int GCD(int a, int b) { return b ? GCD(b, a%b) : a; }

int main() {
    int N; cin >> N;
    vector<int> a(N);
    for (int i = 0; i < N; ++i) cin >> a[i];

    // 累積 GCD (左と右両方)
    vector<int> left(N+1, 0), right(N+1, 0);
    for (int i = 0; i < N; ++i) left[i+1] = GCD(left[i], a[i]);
    for (int i = N-1; i >= 0; --i) right[i] = GCD(right[i+1], a[i]);
    
    // 集計
    int res = 0;
    for (int i = 0; i < N; ++i) {
        // 左側
        int l = left[i];

        // 右側
        int r = right[i+1];

        // 更新
        chmax(res, GCD(l, r));
    }
    cout << res << endl;
}

Measured memory_bytes: 1408
#include<bits/stdc++.h>
using namespace std;
#define INF (1<<30)
typedef pair< int , int > P;
typedef pair< int , P > Pi;
int m,n,k,d;
vector<int> cal;
struct Edge {
  int to,cost;
  Edge(){}
  Edge(int to,int cost):to(to),cost(cost){};
};
vector< Edge > Graph[110];
int min_cost[110][1<<6];
int Bellman_Ford(){
  int ret = INF;
  fill_n(*min_cost,110*(1<<6),INF);
  min_cost[0][(1<<m)-1] = true;
  queue<Pi> que;
  que.push(Pi(0,P(0,(1<<m)-1)));
  while(!que.empty()){
    Pi p = que.front();
    que.pop();
    //int cost = p.first;
    //int now = p.second.first;
    //int bit = p.second.second;
    if(p.second.first == 1) ret = min(ret,p.first);
    if(min_cost[p.second.first][p.second.second] < p.first) continue;
    for(int i=0;i<Graph[p.second.first].size();i++){
      Edge e = Graph[p.second.first][i];
      int nc = p.first + e.cost*k;
      int bit = p.second.second;
      if(e.to >= 2 && e.to < 2 + m){
	if((bit >> (e.to-2)) & 1){
	  nc -= cal[e.to-2];
	  bit &= ~(1 << (e.to-2));
	} else continue;
      }
      if(nc < min_cost[e.to][bit]){
	que.push(Pi(nc,P(e.to,bit)));
	min_cost[e.to][bit] = nc;
      }
    }
  }
  return ret;
}

int judge(string s){
  if(s == "H") return 0;
  else if(s == "D") return 1;
  else if(s[0] == 'C') return atoi(s.substr(1).c_str())+1;
  else if(s[0] == 'L') return atoi(s.substr(1).c_str())+m+1;
}

int main(){
  while(cin >> m >> n >> k >> d , m){
    cal.resize(m);
    for(int i=0;i<m;i++) cin >> cal[i];
    for(int i=0;i<d;i++){
      string s1,s2; int dis;
      cin >> s1 >> s2 >> dis;
      Graph[judge(s1)].push_back(Edge(judge(s2),dis));
      Graph[judge(s2)].push_back(Edge(judge(s1),dis));
    }
    cout << Bellman_Ford() << endl;
    for(int i=0;i<110;i++) Graph[i].clear();
  }
}

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

typedef long long ll;
typedef long double ld;

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

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

int main(){

    ll A, B, C;

    cin >> A >> B >> C;

    cout << (A + B >= C ? "Yes" : "No") << endl;

    return 0;
}

Measured memory_bytes: 256
n, m = [int(i) for i in input().split()]
#table = [[int(i) for i in input().split()] for m in range(m)]
#light = [int(i) for i in input().split()]
s = input()
list = list(s)

#print(n, m)
#print(table)
#print(light)

list[m-1] = list[m-1].lower()
s = ''.join(list)


print(s)

Measured memory_bytes: 2940
use std;

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn b_minor_change() {
    let s = read::<String>();
    let t = read::<String>();
    let ans = s.chars().zip(t.chars()).filter(|(a,b)| a != b).count();
    println!("{}", ans);
}

fn main() {
    b_minor_change();
}


Measured memory_bytes: 2596
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main(void){
  int n;
  cin >> n;
  int x[n], y[n];
  for(int i = 0; i < n; i++){
    cin >> x[i];
    y[i] = x[i];
  }
  sort(y, y + n);
  int s = n / 2;
  for(int i = 0; i < n; i++){
    if(x[i] <= y[s - 1]) cout << y[s] << endl;
    else cout << y[s - 1] << endl;
  }
  return 0;
}


Measured memory_bytes: 3712
#include <stdio.h>

int main(){
int W,H,x,y,r;

scanf("%d %d %d %d %d", &W, &H, &x, &y, &r);

if ( (x - r) >= 0 && (y - r)>=0 && (x + r)<= W && (y + r)<= H )
printf("Yes\n");
else
printf("No\n");

}


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

int main() {
    int N; cin >> N;
    vector<int> A(N); for (int i=0; i<N; ++i) cin >> A[i];
    int first = *max_element(A.begin(), A.end());
    int flg = 0;
    for (int j=0; j<N; ++j){
        if (A[j] == first) flg += 1;
    }
    int second = 0;
    for (int i=0; i<N; i++){
        if (A[i] != first && A[i] > second) second = A[i];
    }
    for (int i=0; i<N; i++){
        if (A[i] == first && flg == 1){
            cout << second << endl;
        } else {
            cout << first << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 2432
#include <bits/stdc++.h>
using namespace std;
#define Endl endl
typedef long long ll;
const int MAXN = (int)1e3 + 5;
string s;
int main()
{
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	while (cin >> s)
	{
		if (s[0] == s[1] || s[1] == s[2] || s[2] == s[3])
			cout << "Bad" << endl;
		else
			cout << "Good" << endl;
	}
}
/*
3776
8080
1333
0024
*/

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (int)(n); i++)
#define repR(i, n) for(ll i = n; i >= 0; i--)
#define For(i, m, n) for(ll i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
typedef long long ll;
typedef long double ld;
using namespace std;
struct Fast {Fast(){std::cin.tie(0);std::ios::sync_with_stdio(false);}} fast;
template <class T = int> T in(){T x; cin >> x; return (x);}

int main(void){
    ll N, K;
    cin >> N >> K;
    string S;
    cin >> S;
    ll s[S.length()];
    transform(ALL(S), s, [](char c) {return c - '0'; });
    
    ll len = S.length();
    bool flag = false;
    ll k = K;
    ll posTemp = 0;
    ll reverse = 0;
    ll reverseTemp = 0;
    rep(i, len){
        //cout << reverseTemp << endl;
        if(s[i] == 0){
            flag = true;
            if(k == 0){
                if(reverse < reverseTemp){
                    reverse = reverseTemp;
                }
                i = posTemp;
                k = K;
                reverseTemp = -1;
                flag = false;
                
               //// cout << "reverse = " << reverse << endl;
               // cout << "posTemp = " << posTemp << endl;
            }
        } else{
            if(flag == true){
                flag = false;
                if(k == K){
                    posTemp = i - 1;
                }
                k --;
              //  cout << "k=" << k << endl;
            }
        }
        
        reverseTemp ++;
    }
    
    if(reverse < reverseTemp){
        reverse = reverseTemp;
    }
    
    ll result = reverse;
    cout << result << endl;
    return 0;
}


Measured memory_bytes: 1232
S = list(input())
N = len(S)
akiba = ['K','I','H','B','R']
flagA = True
i = 0
ia = 0
flag = True
while i < N:
    if i > 9:
        flag = False
        break
    if S[i] == 'A':
        if not(flagA) or (ia >= 1 and ia <= 2):
            flag = False
            break
        flagA = False
        i += 1
    else:
        flagA = True
        if ia > 4:
            flag = False
            break
        if S[i] == akiba[ia]:
            ia += 1
            i += 1
        else:
            flag = False
            break
if ia < 5:
    flag = False

if flag :
    print('YES')
else:
    print('NO')

    
    
#for i in range(2 ** 4):
    
    
    

 
    
    


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

int main() {
	
	int n, k;
	cin >> n >> k;
	vector<int> x(n);
	rep(i, n){
		int tmp;
		cin >> tmp;
		if(tmp != 0){
			x[i] = tmp;
		}else{
			k--;
			n--;
			i--;
		}
	}
	int zero = lower_bound(all(x), 0) - x.begin();
	int min_neg, max_pos, ans = 1001001001;
	
	for(int left = max(0, zero - k), right = left + k - 1; left <= zero && right < n; left++, right++){
		min_neg = (x[left] > 0) ? 0 : abs(x[left]);
		max_pos = max(0, x[right]);
		ans = min(ans, min(min_neg * 2 + max_pos, min_neg + max_pos * 2));
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 640
#include <stdio.h>

int main(int argc, const char * argv[]) {
    int a,b,c,x,y;
    scanf("%d %d %d",&a,&b,&c);
    y=0;
    for(x=a;x<=b;x++){
        if(c%x==0){
            y++;
        }
    }
    printf("%d\n",y);
    return 0;
}

Measured memory_bytes: 596
import java.util.Scanner;

/**
 *
 * @author cs18097
 */
public class Main {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        int d = sc.nextInt();
        int min,max;
        if(a>c){
            min = a;
        } else {
            min = c;
        }
        if(b < d){
            max = b;
        } else {
            max = d;
        }
        int ans = max-min;
        if(ans < 0)ans = 0;
        System.out.print(ans);
           
    }
    
}


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

using namespace std;

int main(){
  int a[100],N,c=0;
  cin >> N;
  for(int i = 0 ; i < N ; i++){
    cin >> a[i];
  }
  for(int i = N-1 ; i >= 0 ; i--){
    for(int j = 0 ; j < i ; j++){
      if(a[j] > a[j+1]){
        swap(a[j],a[j+1]);
        c++;
      }
    }
  }
  for(int i = 0 ; i < N ; i++){
    printf("%d%c",a[i],i==N-1?'\n':' ');
  }
  cout << c << endl;
  return 0;
}

Measured memory_bytes: 1196
#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
using str = string;
using P = pair<int, int>;
using Pll = pair<ll, ll>;
const double PI = 3.141592653589793238;
const ll mod = 1000000007;
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define REP(i, m, n) for (int i = m; i < (int)n; i++)
#define all(a) (a).begin(), (a).end()
#define allg(a) (a).begin(), (a).end(), greator<>()
#define d20 std::setprecision(20)
#define veci vector<int>
#define vecll vector<long long int>
#define vecb vector<bool>
#define vecd vector<double>
template <typename T>
T lcm(T a, T b)
{
	return a / __gcd(a, b) * b;
}

int main()
{
	int a, b, c;
	cin >> a >> b >> c;
	int k;
	cin >> k;
	for (int i = 0; i < k; i++)
	{
		if (a >= b)
			b *= 2;
		else if (c <= b)
			c *= 2;
	}
	// cout << a << " " << b << " " << c << endl;
	if (a < b && b < c)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 3612
#include <cstdio>
#include <algorithm>

using namespace std;

long long n, m;

int main() {

    scanf("%lld %lld", &n, &m);

    long long l = 0;
    long long r = 1000000000000;

    while (l <= r) {
        long long mid = (l + r) / 2;
        long long tmp = m + 2 * min(0LL, n - mid) - 2 * mid;
        if (tmp < 0) {
            r = mid - 1;
        } else {
            l = mid + 1;
        }
    }

    printf("%lld\n", r);

    return 0;

}


Measured memory_bytes: 128
#include <iostream>
#include <iomanip>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <numeric>

using namespace std;

#define pb push_back
#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL)

typedef long long ll;
typedef long double ld;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;



const int M = 2e5+1;
const int MD=1e9+7;
int mat[15][1500];
int main() {
	fast_cin();
	int h,w,k,ans=MD;
	cin>>h>>w>>k;
	for(int i=0;i<h;i++){
		for(int j=0;j<w;j++){
			char ch;
			cin>>ch;
			mat[i][j]=ch-'0';
		}
	}
	for(int msk=0;msk<1<<h-1;msk++){
		int cn=__builtin_popcount(msk);
		int flag=1;
		vector<int>v[2000];
		for(int j=0;j<w;j++){
			int s=0;
			for(int i=0;i<h;i++){
				s+=mat[i][j];
				if(msk>>i&1){
					v[j].push_back(s);
					s=0;
				}
			}
			v[j].push_back(s);
		}
		for(int j=0;j<w;j++){
			for(auto xx:v[j]){
				if(xx>k){
					flag=0;
					break;
				}
			}
		}
		if(!flag) continue;
		int sz=v[0].size();
		vector<int>u(sz,0);
		for(int j=0;j<w;j++){
			bool sp=0;
			for(int i=0;i<sz;i++){
				if(u[i]+v[j][i]>k){
					cn++;
					sp=1;
					break;
				}
			}
			if(sp){
				for(int i=0;i<sz;i++){
					u[i]=v[j][i];
				}
			}
			else{
				for(int i=0;i<sz;i++){
					u[i]+=v[j][i];
				}
			}
		}
		ans=min(ans,cn);
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 512
import numpy as np

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

a = np.array(a)
b = np.array(b)

after = np.zeros((3,3))
for i in range(N):
    after += a == b[i]
    
bool1 = (np.sum(after, axis=0)==3).sum()
bool2 = (np.sum(after, axis=1)==3).sum()
bool3 = (after[0,0]+after[1,1]+after[2,2])==3
bool4 = (after[0,2]+after[1,1]+after[2,0])==3

if bool1+bool2+bool3+bool4>0:
    ans = 'Yes'
else:
    ans = 'No'
    
print(ans)

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

//#define int long long
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<n;++i)
#define exrep(i, a, b) for(ll i = a; i < b; i++)
#define out(x) cout << x << endl
#define EPS (1e-7)
#define gearup ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<bool> > vvb;
typedef vector<vector<double> > vvd;
typedef vector<vector<string> > vvs;
typedef vector<ll> vl;
typedef vector<vector<ll> > vvl;
typedef vector<vector<vector<ll> > > vvvl;
ll MOD = 1000000007;
const long long L_INF = 1LL << 60;
const int INF = 2147483647; // 2^31-1
const double PI = acos(-1);
//cout<<fixed<<setprecision(10);

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> void debug(T v){rep(i,v.size()) cout<<v[i]<<" ";cout<<endl;}
const ll dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};

signed main(){
    gearup;
    vl p(4);
    rep(i,4)cin>>p[i];
    ll n;cin>>n;
    ll res = n/2 * min(8*p[0],min(4*p[1],min(2*p[2],p[3]))) + (n % 2) * min(4*p[0],min(2*p[1],p[2]));
    out(res);
}

Measured memory_bytes: 256
use std::io::*;
use std::str::FromStr;

pub fn read<t: FromStr>() -> t {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

use std::cmp::max;

fn main() {
    let a: i64 = read();
    let b: i64 = read();

    let c = a + b;
    let d = a - b;
    let e = a * b;

    println!("{}", max(c, max(d, e)));
}


Measured memory_bytes: 4352
////////////////////////// Author
////////////////////////// Nasim Hossain Rabbi
////////////////////////// JU-CSE28
////////////////////////// CF - imnasim3.1415
////////////////////////// UVA - imnasim3.1415
////////////////////////// Mail - imnasim3.1415@gmail.com
#include<bits/stdc++.h>
using namespace std;
#define E end()
#define B begin()
#define sz size()
#define EM empty()
#define fi first
#define se second
#define cl clear()
#define sqr(a) (a*a)
#define mk make_pair
#define po pop()
#define pu push
#define pb push_back
#define pf push_front
#define pob pop_back()
#define pof pop_front()
string en="\n";
string sp=" ";
string t="hello";
string Y="YES\n";
string N="NO\n";
#define rep(i,n) for(i=0;i<n;i++)
#define Rep(i,n) for(i=1;i<=n;i++)
#define per(i,n) for(i=n-1;i>=0;i--)
#define peR(i,n) for(i=n;i>0;i--)
#define mem(a,b) memset(a,b,sizeof(a))
#define all(cont) cont.begin(),cont.end()
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL)
#define pi 3.1415926535897932384626433832795
#define vi vector<long long>
#define vs  vector<string>
#define MX LLONG_MAX
#define MN LLONG_MIN
#define MOD 1000000007
#define vp(vi,x) cin>>x; vi.pb(x);
#define bsearch(a,x) binary_search(all(a),x)
#define LB(a,x) (lower_bound(all(a),x)-a.B)
#define UB(a,x) (upper_bound(all(a),x)-a.B)
typedef long long LL;
typedef long double LD;
typedef unsigned long long ULL;
bool isprm(LL a){if(a==1)return false; for(LL i=2;i*i<=a;i++){if(a%i==0)return false;}return true;}
bool palin(string a){for(int i=0;i<a.sz;i++){if(a.at(i)!=a.at(a.sz-i-1))return 0;} return 1;}
bool isVowel(char ch){ ch=toupper(ch); if(ch=='A'||ch=='U'||ch=='I'||ch=='O'||ch=='E') return true; return false;}
int toInt(string s){int sm;stringstream ss(s);ss>>sm;return sm;}
LL ceil2(LL a,LL b){LL c=a/b; if(a%b)c++; return c; }
LL bpow(LL a,LL b){if(b==0)return 1;LL r=bpow(a,b/2);if(b%2)return r*r*a;else return r*r;}
LL binpow(LL a,LL b){LL r=1;while(b>0){if(b&1)r=r*a;a=a*a;b>>=1;}return r;}
LL binpow(LL a,LL b,LL m){a%=m;LL r=1;while(b>0){if(b&1) r=r*a%m;a=a*a%m; b>>=1;}return r;}
template<typename T>inline T gcd(T a,T b){if(a<0)return gcd(-a,b);if(b<0)return gcd(a,-b);return (b==0)?a:gcd(b,a%b);}
template<typename T>inline T lcm(T a,T b) {if(a<0)return lcm(-a,b);if(b<0)return lcm(a,-b);return a*(b/gcd(a,b));}
int main()
{
//    fast;
    LL i,j,k,n,m,l,s=0,x,y,tc=1,p,q,a,b,c=0;
    bool f=0,ff=0;string st,s1,s2,s3; char ch;
    while(cin>>n>>m)
    {
        a=b=0;
        bool ar[n+5];
        rep(i,n+5)ar[i]=0;
        map<LL,LL>mp;
        while(m--)
        {
            cin>>p>>st;
            if(ar[p])continue;
            if(st=="AC") a++,ar[p]=1;
            else mp[p]++;
        }
        for(auto it=mp.B;it!=mp.E;it++)
        {
            if(ar[it->fi])b+=it->se;
        }
        cout<<a<<sp<<b<<en;
    }
    return 0;
}


Measured memory_bytes: 7552
mask = 0b0
num_list = list(map(int,list(input())))
l = len(num_list)
for i in range(1000):
    
    
    sign_list=[]
    for j in range(l-1):
        if(mask & (1<<j)):
            sign_list += ['+']
        else:
            sign_list += ['-']
    
    nsum=num_list[0]
    for j in range(l-1):
        if(sign_list[j]=='+'):
            nsum += num_list[j+1]
        else:
            nsum -= num_list[j+1]

    if(nsum == 7):
        word = ''
        for j in range(l-1):
            word += (str(num_list[j])+sign_list[j])
        word += (str(num_list[-1]) +'=7')
        print(word)
        break

    if(mask > 0b111):
        break
    mask += 1

Measured memory_bytes: 3064
# -*- coding: utf-8 -*-

import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7

def fft(A, B, L):
    import numpy as np
    from numpy.fft import rfft, irfft

    # FFT
    res = irfft(rfft(A, L) * rfft(B, L), L)
    # 四捨五入して整数に
    res = np.rint(res).astype(np.int64)
    return res

MAX = 10 ** 5
N, M = MAP()
A1 = [0] * (MAX+1)
A2 = [0] * (MAX+1)
for a in LIST():
    A1[a] += 1
    A2[a] += 1

L = 2 ** 18
res = fft(A1, A2, L)

ans = cnt = 0
for a in range(L-1, -1, -1):
    c = res[a]
    if cnt + c <= M:
        cnt += c
        ans += a * c
    else:
        # 同値でMを超える分の調整
        ans += a * (M - cnt)
        break
print(ans)


Measured memory_bytes: 28284
#include<bits/stdc++.h>
using namespace std;
int main(){
	string s;
	int sum=0;
	cin>>s;
	int l=s.size();
	for(int i=0;i<l/2;i++){
		if(s[i]!=s[l-1-i])
		sum++;
	}
	
	cout<<sum;
	
	
	
	
	return 0;
} 

Measured memory_bytes: 256