akhauriyash/Code-Regression huggingface dataset:
import sys
input = sys.stdin.readline
H, W, K = map(int, input().split())
B = [list(map(int, input()[:-1])) for _ in [0]*H]


def calc(S):
    gain = 0
    for line in S:
        gain += clear(line)
    remove(S)
    return gain


def clear(line):
    gain = 0
    cnt = 0
    pre = line[0]
    for i, c in enumerate(line):
        if pre == c:
            cnt += 1
        else:
            if cnt >= K:
                gain += line[i-1]*cnt
                for k in range(i-cnt, i):
                    line[k] = 0
            cnt = 1
        pre = c

    if cnt >= K:
        gain += line[-1]*cnt
        for k in range(W-cnt, W):
            line[k] = 0
    return gain


def remove(S):
    for w in range(W):
        i = H-1
        for h in range(H-1, -1, -1):
            if S[h][w]:
                S[i][w] = S[h][w]
                i -= 1
        for i in range(i+1):
            S[i][w] = 0


def remove_sq(S, i, j):
    for h in range(i, 0, -1):
        S[h][j] = S[h-1][j]
    S[0][j] = 0


ans = 0
for i in range(H):
    for j in range(W):
        S = [b.copy() for b in B]
        remove_sq(S, i, j)
        score = 0
        p = 1
        while True:
            gain = calc(S)
            if gain == 0:
                break
            score += p * gain
            p *= 2
        if ans < score:
            ans = score
print(ans)


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

int main()
{
ll a,b,c,d;
cin>>a>>b>>c>>d;

ll x,y,p,q;

x=a*c;
y=a*d;
p=b*c;
q=b*d;

cout<<max(max(max(x,y),p),q);


    return 0;
}


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

using namespace std;

int main(){

    ll n;
    cin>>n;

    std::map<ll, ll> mp;
    ll sum = 0;
    for (ll i = 0; i < n; i++) {
        ll p;
        cin>>p;

        mp[p]++;
        sum += p;
    }

    ll q;
    std::cin >> q;
    for (ll i = 0; i < q; i++) {
        /* code */
        ll a, b;
        cin>>a>>b;

        sum += (b-a)*mp[a];
        mp[b] += mp[a];
        mp[a] = 0;
        cout<<sum<<endl;
    }
    return 0;
}


Measured memory_bytes: 9464
/**
*	  Name: Ajay
*	  Institute: IIITH 
*/

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <deque>
#include <vector>
#include <cstdlib>
#include <iomanip>
#include <cmath>
#include <queue>
#include <map>
#include <set>
#include <ctime>
#include <string.h>
#define ll long long
#define inf 0x7fffffff
#define mod 1000000007
#define pb push_back
#define ppi pair<int,int>
#define vi vector<int>
#define vvi vector<vector<int>>
#define vii vector<ppi>
#define vll vector<ll>
#define mp make_pair
#define fi first
#define se second
using namespace std;

void fastio()
{
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
}
void input()
{
  #ifndef ONLINE_JUDGE
  freopen("input.txt","r",stdin);
  freopen("output.txt","w",stdout);
  #endif
}

int main()
{      
  fastio();
  int k;
  cin>>k;
  queue<pair<ll,ll>> que;
  for(int i=1;i<=9;i++)
  	que.push({i,i});
  int cnt=0;
  ll ans;
  while(!que.empty())
  {
  	
  	pair<ll,ll> cur=que.front();
  	que.pop();
  	cnt++;
  	if(cnt==k){
  		ans=cur.fi;
  		break;
  	}
	int d=cur.se;
	//cout<<"current d:"<<d<<endl;
	for(int j=d-1;j<=d+1;j++){
		if(j>=0 && j<=9){
			que.push({cur.fi*10+j,j});
		}
	}
  }
  cout<<ans;
  return 0;
}

Measured memory_bytes: 3456
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
using namespace std;

int main()
{
    int a, b;
    cin >> a >> b;

    if(a <= b)
        cout << a << endl;
    else
        cout << (a-1) << endl;

    return 0;
}


Measured memory_bytes: 764
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0,i##_max=(N);i<i##_max;++i)
#define repp(i,l,r) for(int i=(l),i##_max=(r);i<i##_max;++i)
#define per(i,N) for(int i=(N)-1;i>=0;--i)
#define perr(i,l,r) for(int i=r-1,i##_min(l);i>=i##_min;--i)
#define all(arr) (arr).begin(), (arr).end()
#define SP << " " <<
#define SPF << " "
#define SPEEDUP cin.tie(0);ios::sync_with_stdio(false);
#define MAX_I INT_MAX //1e9
#define MIN_I INT_MIN //-1e9
#define MAX_UI UINT_MAX //1e9
#define MAX_LL LLONG_MAX //1e18
#define MIN_LL LLONG_MIN //-1e18
#define MAX_ULL ULLONG_MAX //1e19
  typedef long long ll;
  typedef pair<int,int> PII;
  typedef pair<char,char> PCC;
  typedef pair<ll,ll> PLL;
  typedef pair<char,int> PCI;
  typedef pair<int,char> PIC;
  typedef pair<ll,int> PLI;
  typedef pair<int,ll> PIL; 
  typedef pair<ll,char> PLC; 
  typedef pair<char,ll> PCL; 

inline void YesNo(bool b){ cout << (b?"Yes" : "No") << endl;}
inline void YESNO(bool b){ cout << (b?"YES" : "NO") << endl;}
inline void Yay(bool b){ cout << (b?"Yay!" : ":(") << endl;}

//素因数分解O(root n)
vector<PLL> prime_factor(ll n){
  vector<PLL> v;
  for(ll i=2; i<=sqrt(n); ++i){
    ll num=0;
    while(n%i==0){
      num++;
      n/=i;
    }
    if(num!=0) v.push_back(PLL(i,num));
  }
  if(n!=1) v.push_back(PLL(n,1));
  return v;
}

int main(void){
  SPEEDUP
  cout << setprecision(15);
  ll N,P;cin >> N >> P;
  vector<PLL> pf = prime_factor(P);
  ll ans = 1ll;
  for(const PLL p : pf){
    ll n = p.second/N;
    if(n==0)continue;
    rep(i,n) ans *= p.first;
  }
  cout << ans << endl;
  return 0;
}


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

int cnt[100003];


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

	int max_cnt = 0;
	for (int i = 0; i <= 100002; i++) cnt[i] = 0;

	for (int i = 1; i <= N; i++) {
		int a;
		cin >> a;
		// a-1からa+1の範囲だが配列要素にマイナスが入らないように+1スライドさせる
		for (int X = a; X <= a+2; X++) {
			cnt[X]++;
			if (max_cnt < cnt[X]) max_cnt = cnt[X];
		}
	}
	cout << max_cnt << endl;

	return 0;
}


Measured memory_bytes: 640
//https://outline.hatenadiary.jp/entry/2019/12/17/021530
//勉強させて頂いた記事

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> pll;


const ll LongINF=1e13+7;
const int INF=1e9+7;
const int dx[]={0,1,0,-1};
const int dy[]={1,0,-1,0};

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, class Y>T GCD(T a, Y b){if(a<b){int c=a;a=b;b=c;}if (a % b == 0){return b;}return GCD(b, a % b);}
void clear(queue<pair<int, int>> &q){queue<pair<int, int>> empty;swap(q, empty);} //queueの中身の型は適時変更を忘れない

#define REP(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define rv reverse
#define ALL(a) (a).begin(),(a).end()

//記事から、XORは桁上がりのない加算！
//上記のことから、一つの桁だけを考えて処理すれば良いことがわかる
//他の桁に影響を及ぼさないため。
//d桁目で、0である数字の個数と、1である数字の個数の積に2**dを掛けたものの総和が解である。
//bit演算大切

int main(){
    int N;
    cin>>N;
    vector<ll> A(N);
    rep(i,N)cin>>A[i];

    ll res=0;
    rep(d,60){
        ll n0=0,n1=0;
        rep(i,N){
            if((A[i]>>d)&1)++n1;
            else ++n0;
        }
        ll tmp=(1LL<<d)%INF;//調べるbitの場所のフラグ

        ll n=n0*n1%INF;
        tmp=tmp*n%INF;
        res=(res+tmp)%INF;
    }

    cout<<res<<endl;


    return 0;
}

//a=97,z=122

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

using std::cout;
using std::cin;
using std::endl;

int main() {
	int n;
	cin >> n;
	long long sum = 0;
	for (int i = 1; i <= n; i++)
	{
		if (i % 3 != 0 && i % 5 != 0)
		{
			sum += i;
		}
	}
	cout << sum << endl;
}

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

#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for (int i = x; i < n; i++)
#define OP(m) cout << m << endl
typedef long long ll;
typedef unsigned long long ull;

int main()
{
    int n, m;
    cin >> n >> m;
    int p[n][n];
    rep(i, n) rep(j, n) p[i][j] = 0;
    rep(i, m)
    {
        int a, b;
        cin >> a >> b;
        a--, b--;
        p[a][b] = 1;
        p[b][a] = 1;
    }

    vector<int> v(n);
    iota(ALL(v), 0);
    int cnt = 0;
    do
    {
        if (v[0] == 0)
        {
            bool flag = 0;
            rep(i, n - 1)
            {
                if (p[v[i]][v[i + 1]] == 0)
                    flag = 1;
            }
            if (!flag)
                cnt++;
        }
    } while (next_permutation(ALL(v)));

    OP(cnt);

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
typedef long long int llint;
int main() {
	char s[3][150];
	cin >> s[0];
	cin >> s[1];
	cin >> s[2];
	cout << s[0][0] << s[1][0] << s[2][0] << endl;
	return 0;
}

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

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
//const ll mod = 1000000007;
string S[405];
int h, w;

struct UnionFind {
    vector<int> par;
    vector<int> rank;
    vector<ll> Size;
    UnionFind(int n = 1) {
        init(n);
    }

    void init(int n = 1) {
        par.resize(n + 1); rank.resize(n + 1); Size.resize(n + 1);
        for (int i = 0; i <= n; ++i) {
            par[i] = i, rank[i] = 0, Size[i] = 0;
        }
        for(int i = 0; i < h; i++){
            for(int j = 0; j < w; j++){
                if(S[i][j] == '.') {
                    Size[i * 400 + j] = 1;
                }
            }
        }
    }

    int root(int x) {
        if (par[x] == x) {
            return x;
        }
        else {
            int r = root(par[x]);
            return par[x] = r;
        }
    }

    bool issame(int x, int y) {
        return root(x) == root(y);
    }

    bool merge(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (rank[x] < rank[y]) swap(x, y);
        if (rank[x] == rank[y]) ++rank[x];
        par[y] = x;
        Size[x] += Size[y];
        return true;
    }

    ll size(int x){
        return Size[root(x)];
    }
};

int main() {
    //cout.precision(10);
    cin >> h >> w;
    for(int i = 0; i < h; i++){
        cin >> S[i];
    }
    UnionFind uni(200000);
    int di[4] = {-1, 1, 0, 0};
    int dj[4] = {0, 0, 1, -1};
    for(int i = 0; i < h; i++){
        for(int j = 0; j < w; j++){
            int now = i * 400 + j;
            for(int k = 0; k < 4; k++){
                int newi = i + di[k];
                int newj = j + dj[k];
                if((newi < 0) || (newi >= h) || (newj < 0) || (newj >= w)) continue;
                if(S[i][j] != S[newi][newj]) uni.merge(i * 400 + j, newi * 400 + newj);
            }
        }
    }
    ll ans = 0;
    for(int i = 0; i < h; i++){
        for(int j = 0; j < w; j++){
            if(S[i][j] == '.') continue;
            /*
            cout << i << " " << j << " " << uni.size(i * 400 + j) << endl;
                for(int k = 0; k < h; k++){
                    for(int l = 0; l < w; l++){
                        if(S[k][l] == '#') continue;
                        if(uni.issame(i * 400 + j, k * 400 + l)) {
                            cout << k << " " << l << endl;
                        }
                    }
                }
            */
            ans += (ll)uni.size(i * 400 + j);
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3584
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000

int cnt[100010];
int cnt1[100010];
int cnt2[100010];
int X[100010];
typedef pair<int, int> P;
int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, M;
    cin >> N >> M;
    int ans = 0;
    rep(i, N) cin >> X[i];
    rep(i, N) cnt[X[i]]++;
    //REP(i, 1, 100000) if(cnt[i] != 0) cout << i << " " << cnt[i] << endl;
    REP(i, 0, 100000) {
        if (cnt[i] % 2) {
            cnt1[i % M]++;
            cnt[i]--;
        }
        cnt2[i % M] += cnt[i];
    }
    //REP(i, 0, M - 1) cout << i << ": "<< cnt1[i] << " " << cnt2[i] << endl;
    rep(i, M + 1) {
        int num1 = i;
        int num2 = M - i;
        while (cnt1[num1] - cnt1[num2] >= 2 && cnt2[num2] >= 2) {
            cnt1[num2] += 2;
            cnt2[num2] -= 2;
        }
    }
    //REP(i, 0, M - 1) cout << i << ": "<< cnt1[i] << " " << cnt2[i] << endl;
    rep(i, M/2 + 1) {
        if ((i * 2) % M == 0) {
            ans += (cnt1[i] + cnt2[i]) / 2;
        } else {
            ans += min(cnt1[i], cnt1[M - i]) + cnt2[i]/2 + cnt2[(M - i) % M]/2;
        }
        //cout << i << " " << ans << endl;
    }
    cout << ans << endl;

    return 0;
}


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

#define thegamebegins   ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define fileio          freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#define int             long long
#define float           long double
#define test            int T; cin>>T; for(int i=1; i<=T; ++i)
#define in(a,n)         for(int i=0; i<(n); ++i)  cin>>a[i]
#define r0              return 0
#define E               "\n"
#define S               " "
#define elif            else if 
#define M               1000000007
#define fi(i,x,y)       for(int i=(x); i<(y); ++i)
#define fb(i,x,y)       for(int i=(x); i>=(y); --i)
#define fa(i,s)         for(auto i:(s))
#define fp(i,s)         for(auto i=(s).begin(); i!=(s).end(); ++i)
#define pf(i,s)         for(auto i=(s).rbegin(); i!=(s).rend(); ++i)
#define all(s)          (s).begin(), (s).end()
#define rev(s)          (s).rbegin(), (s).rend()
#define sz(s)           (int)(s).size()
#define vi              vector <int>
#define vpii            vector <pair <int,int> >
#define mii             map <int,int>
#define pii             pair <int,int>
#define seti            set <int>
#define setd            set <int,greater <int> >
#define sortd(a,n)      sort(a, a+n, greater<int>())
#define pb              push_back
#define fr              first
#define sc              second
#define lb              lower_bound
#define ub              upper_bound
#define er              equal_range
 
const int INF = 0x3f3f3f3f;

signed main()
{
    thegamebegins

    int n;	cin>>n;
    vi v(n);
    fi(i,1,n)
    {
    	int x;	cin>>x;
    	++v[x-1];
    }
    fa(i,v)	cout<<i<<E;
    r0;
}


Measured memory_bytes: 4780
#include<iostream>
#include<algorithm>
#include<vector>
#include<numeric>
#include<string>
#include<cmath>
#include<set>
#include<queue>
#include<deque>
#include<bitset>
#include<iomanip>
#include<cctype>
#include<map>
#include<cstring>
#include<bitset>
#include<cassert>

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

using namespace std;
using ll = long long int;

const int inf = 1001001000;
const long long int Inf = 1001001001001001000;



void print(vector<vector<int>> a){
	for (int i = 0; i < a.size(); i++)
	{
		for (int j=0;j<a[i].size();j++){
			cout << a[i][j] << " ";
		}
		cout << endl;
	}
}

void print(vector<vector<long long int>> a){
	for (int i=0;i<a.size();i++){
		for (int j=0;j<a[i].size();j++){
			cout << a[i][j] << " ";
		}
		cout << endl;
	}
}

void print(vector<int> a){
    int n = a.size();
    for (int j=0;j<n;j++) {
        if (j != n-1) cout << a[j] << " ";
        else cout << a[j] << endl;
    }
}

void print(vector<long long int> a){
    int n = a.size();
    for (int j=0;j<n;j++) {
        if (j != n-1) cout << a[j] << " ";
        else cout << a[j] << endl;
    }
}

void print(set<int> a){
	for (auto x:a)
		cout << x << " ";
	cout << endl;
}

int main()
{
	int x1=0, y1=0, x2, y2, n;
	cin >> x2 >> y2 >> n;
	rep(i,n){
		int x, y, a;
		cin >> x >> y >> a;
		if(a == 1){ 
			if (x1 < x)
				x1 = x;
		} else if (a == 2){ 
			if (x2 > x)
				x2 = x;
		} else if (a == 3){ 
			if (y1 < y)
				y1 = y;
		} else { 
			if (y2 > y)
				y2 = y;
		}
	}
	if(x1 > x2 || y1 > y2){ 
		puts("0");
		return 0;
	}
	cout << (x2 - x1) * (y2 - y1) << endl;


	return 0;
}

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

int main() {
    ll N, M, K;
    cin >> N >> M >> K;
    vector<ll> A(N);
    vector<ll> B(M);
    rep(i,N) {
        cin >> A[i];
        if (i != 0) A[i] += A[i - 1];
    }
    rep(i,M) {
        cin >> B[i];
        if (i != 0) B[i] += B[i - 1];
    }

    auto it = upper_bound(B.begin(), B.end(), K);
    size_t pos = distance(B.begin(), it);
    ll maxi = pos;
    for (int i = 0; i < N; i++) {
        if (K - A[i] >= 0) {
            auto it = upper_bound(B.begin(), B.end(), K - A[i]);
            size_t pos = distance(B.begin(), it);
            ll ans = i + 1 + pos;
            if (ans > maxi) maxi = ans;
        }
    }
    cout << maxi << endl;
    return 0;
}


Measured memory_bytes: 6408
#include<iostream>
#include<algorithm>
#include<utility>
#include<vector>
#include<cmath>
using namespace std;

typedef pair<int, int> P;
typedef long long ll;
const int INF = 100000000;

ll gcd( ll a, ll b ){//最大公約数
    ll tmp;
    if( a < b ) { tmp = a; a = b; b = tmp; }
    if( b < 1 ) return -1;

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

ll lcm(ll a, ll b){//最小公倍数
    return a * b / gcd(a, b);
}


//入力

int main(){

    string s, t;
    cin >> s >> t;

    cout << t + s << endl;

    return 0;
}

Measured memory_bytes: 256
require 'pp'

# 入力値を文字列で返却する
def gets_s()
  gets.chomp
end

# 入力値を文字の配列で返却する
def gets_nsp_list()
  gets.chomp.split("")
end

S = gets_s
s_list = S.chars

if S.size == 1
  puts "YES"
elsif S.size == 2
  if S == "aa" || S == "bb" || S == "cc"
    puts "NO"
  else
    puts "YES"
  end
elsif S.size == 3
  if S.chars.sort.join == "abc"
    puts "YES"
  else
    puts "NO"
  end
else
  s_count_hash = s_list.group_by(&:itself).map{|k,v| [k, v.count] }.to_h
  counts = s_count_hash.values
  if counts.size < 3
    puts "NO"
    exit
  end
  min = counts.min
  counts.each do |c|
    if c - min > 1
      puts "NO"
      exit
    end
  end
  puts "YES"
end


Measured memory_bytes: 8188
import java.util.Scanner;

class Main {

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

		long n = sc.nextLong();
		int a = sc.nextInt();
		int b = sc.nextInt();
		long c = sc.nextInt();
		long d = sc.nextInt();

		long m = n - 1;
		long sub = b - a;

		long min = 0;
		long max = 0;
		for(int i = 0; i < m; i++){
			min = - i * d + (m - i) * c;
			max = - i * c + (m - i) * d;
			if(min <= sub && sub <= max){
				System.out.print("YES");
				return;
			}
			min += 2 * d;
			max += 2 * c;
		}
		System.out.print("NO");
	}
}


Measured memory_bytes: 23636
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Net.Mail;

namespace Contest
{
    class Scanner
    {
        private string[] line = new string[0];
        private int index = 0;
        public string Next()
        {
            if (line.Length <= index)
            {
                line = Console.ReadLine().Split(' ');
                index = 0;
            }
            var res = line[index];
            index++;
            return res;
        }
        public int NextInt()
        {
            return int.Parse(Next());
        }
        public long NextLong()
        {
            return long.Parse(Next());
        }
        public string[] Array()
        {
            line = Console.ReadLine().Split(' ');
            index = line.Length;
            return line;
        }
        public int[] IntArray()
        {
            var array = Array();
            var result = new int[array.Length];
            for (int i = 0; i < array.Length; i++)
            {
                result[i] = int.Parse(array[i]);
            }

            return result;
        }
        public long[] LongArray()
        {
            var array = Array();
            var result = new long[array.Length];
            for (int i = 0; i < array.Length; i++)
            {
                result[i] = long.Parse(array[i]);
            }

            return result;
        }
    }


    class Program
    {
        private int N;
        private long[] A;
        private int MaxRight = 0;
        private void Scan()
        {
            var sc = new Scanner();
            N = sc.NextInt();
            A = sc.LongArray();
        }

        public void Solve()
        {
            Scan();
            long cnt = 0;
            int left = 0;
            int right = 0;
            long xor = 0;
            for (right = 0; right < N; right++)
            {
                if ((xor & A[right]) == 0)
                {
                    xor ^= A[right];
                }
                else
                {
                    cnt += Count(left, right);
                    while (left <= right)
                    {
                        xor ^= A[left];
                        left++;
                        if ((xor & A[right]) == 0)
                        {
                            break;
                        }
                    }

                    xor ^= A[right];
                }
            }
            cnt += Count(left, right);
            Console.WriteLine(cnt);
        }

        private long Count(int left, int right)
        {
            //right -= 1;
            int a = MaxRight - left;
            int b = right - MaxRight;
            long res = 0;
            res += (long)a * b;
            res += (long)b * (b + 1) / 2;
            //Console.WriteLine($"{a} {b}");
            //Console.WriteLine($"{left} {MaxRight} {right} {res}");

            MaxRight = right;
            return res;
        }

        static void Main() => new Program().Solve();
    }
}

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

const int MAXN = 100005;
int A[MAXN], B[MAXN], C[MAXN];
int n;

int main()
{
	scanf("%d", &n);
	for (int i = 1; i <= n; i++) scanf("%d", &A[i]);
	for (int i = 1; i <= n; i++) scanf("%d", &B[i]);
	for (int i = 1; i <= n; i++) scanf("%d", &C[i]);
	sort(A+1, A+n+1);
	sort(C+1, C+n+1);
	sort(B+1, B+n+1);
	int j = 0, k = 0;
	long long ans = 0;
	for (int i = 1; i <= n; i++) {
		while (j < n && A[j+1] < B[i]) j++;
		while (k < n && C[k+1] <= B[i]) k++;
		ans += (long long)j*(n-k);
	}
	cout << ans << endl;
	return 0;
}


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

#include <boost/multiprecision/cpp_int.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>
using namespace boost::multiprecision;

using bint = cpp_int;
using bdec = cpp_dec_float_100;
// using bdec = number<cpp_dec_float<10000>>;

int main() {
  bint N;
  cin >> N;
  cout << ((N % 9) ? "No" : "Yes") << "\n";
}

Measured memory_bytes: 3752
while True:
    z = True
    a = int(input())
    if a == 0:
        break
    for i in range(12):
        b,c = map(int,input().split())
        a -= b-c
        if a <= 0 and z:
            print(i+1)
            z = False
    if a > 0:
        print("NA")


Measured memory_bytes: 5612
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n; cin>>n;
    string s1,s2; cin>>s1>>s2;
    int i=1;
    long sum=3;
    if(s1[0]!=s2[0]){
        i++;
        sum*=2;
    }
    while(i<n){
        bool jud=(s1[i-1]==s2[i-1]);
        if(s1[i]!=s2[i]){
            if(jud)
                sum*=2;
            else
                sum*=3;
            i+=2;
        }
        else{
            if(jud)
                sum*=2;
            i++;
        }
        sum%=(int)(1e9+7);
    }
    cout<<sum;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
 
int main() {
    ll n, a, b;
    ll count=0, count1=0, count2=0;
    cin >> n >> a >> b;
    
    if (a%2==0 && b%2==0) {
        count=(b-a)/2;
        cout << count;
    }
    else if (a%2==1 && b%2==1) {
        count=(b-a)/2;
        cout << count;
    }
    else {
        count = min(a-1, n-b) + 1 + (b-a)/2;
        cout << count;
    }
    
    return 0;
}

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

using namespace std;

typedef long long LL;
LL n;
LL arr[110000];
LL d[110000];
LL cnt = 0;
LL sum = 0;
LL res;

int main() {
    scanf("%lld", &n);
    for(LL i = 1; i <= n; i++) {
        scanf("%lld", &arr[i]);
        sum += arr[i];
    }
    arr[1+n] = arr[1];
    cnt = (n*(n+1))/2;
    bool isok = 1;
    if(sum % cnt == 0) {
        LL loop = sum / cnt;
        for(LL i = 1; i <= n; i++) {
            d[i] = arr[i+1] - arr[i];
            if(d[i] > loop) isok = 0;
            if((loop - d[i]) % n == 0) {
                res += (loop-d[i])/n;
            } else
                isok = 0;
        }
      //  cout<<res<<" "<<loop<<" debug "<<endl;
        if(res != loop) isok = 0;
    } else
        isok = 0;
    printf("%s", isok?"YES":"NO");
    return 0;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
#define mp(a,b) make_pair(a,b)
#define pb push_back
#define ppb pop_back
using namespace std;
typedef long long int ll;
char mat[21][21];
int find(int s1,int e1,int s2,int e2,int h,int w){
	queue< pair<int,int> >q;
	q.push(mp(s1,e1));
	bool visited[21][21];
	int dist[21][21];
	for(int i=0;i<h;i++){
		for(int j=0;j<w;j++){
			
				dist[i][j]=INT_MAX;
			
		}
	}
	dist[s1][e1]=0;
	for(int i=0;i<21;i++)
		for(int j=0;j<21;j++)
			visited[i][j]=false;
	while(!q.empty()){
		pair<int,int>p=q.front();
		q.pop();
		if(visited[p.first][p.second]){
			continue;
		}
		visited[p.first][p.second]=true;
		if(p.first==s2&&p.second==e2){
			return dist[s2][e2];
		}
		if(p.second-1>=0&&!visited[p.first][p.second-1]&&mat[p.first][p.second-1]!='#'){
			dist[p.first][p.second-1]=min(dist[p.first][p.second]+1,dist[p.first][p.second-1]);
			q.push(mp(p.first,p.second-1));
		}
		if(p.second+1<w&&!visited[p.first][p.second+1]&&mat[p.first][p.second+1]!='#'){
			dist[p.first][p.second+1]=min(dist[p.first][p.second]+1,dist[p.first][p.second+1]);
			q.push(mp(p.first,p.second+1));
		}
		if(p.first-1>=0&&!visited[p.first-1][p.second]&&mat[p.first-1][p.second]!='#'){
			dist[p.first-1][p.second]=min(dist[p.first][p.second]+1,dist[p.first-1][p.second]);
			q.push(mp(p.first-1,p.second));
		}
		if(p.first+1<h&&!visited[p.first+1][p.second]&&mat[p.first+1][p.second]!='#'){
			dist[p.first+1][p.second]=min(dist[p.first][p.second]+1,dist[p.first+1][p.second]);
			q.push(mp(p.first+1,p.second));
		}
	}
}
int  main(){
	ll h,w;
	cin>>h>>w;
	
	for(int i=0;i<h;i++){
		for(int j=0;j<w;j++){
			cin>>mat[i][j];
		}
	}
	int ans=0;
	for(int x1=0;x1<h;x1++){
		for(int y1=0;y1<w;y1++){
			for(int x2=0;x2<h;x2++){
				for(int y2=0;y2<w;y2++){
					if(mat[x1][y1]=='.'&&mat[x2][y2]=='.')
						// cout<<find(x1,y1,x2,y2,h,w)<<" "<<x1<<" "<<y1<<" "<<x2<<" "<<y2<<endl;
						ans=max(ans,find(x1,y1,x2,y2,h,w));
				}
			}
		}
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {

	public static int mode(int[]a) {
		int count = 1;
		int maxcount = 1;
		int mode = a[0];
		for(int i = 1; i < a.length; i++) {
			if(a[i] == a[i-1]) {
				count += 1;
				if(count >= maxcount) {
					mode = a[i];
					maxcount = count;
				}
			}
			else
				count = 1;
		}
		return mode;
	}
	public static int mode2(int[]a, int mode) {
		int count = 1;
		int maxcount = 1;
		int mode2;
		if(a[0] != mode) mode2 = a[0];
		else mode2 = 0;
		for(int i = 1; i < a.length; i++) {
			if(a[i] == mode) continue;
			if(a[i] == a[i-1]) {
				count += 1;
				if(count >= maxcount) {
					mode2 = a[i];
					maxcount = count;
				}
			}
			else {
				count = 1;
				if(mode2 == 0)
					mode2 = a[i];
			}
		}
		return mode2;
	}
	public static int count(int[]a, int x) {
		int count = 0;
		for(int i = 0; i < a.length; i++) {
			if(a[i] == x)
				count += 1;	
		}
		return count;
	}
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] vodd = new int[n/2];
		int[] veven = new int[n/2];
		for(int i = 0; i < n/2; i++) {
			vodd[i] = sc.nextInt();
			veven[i] = sc.nextInt();
		}
		Arrays.sort(vodd);
		Arrays.sort(veven);
		int modevodd = mode(vodd);
		int modeveven = mode(veven);
		int modenumvodd = count(vodd, modevodd);
		int modenumveven = count(veven, modeveven);
		if(modevodd != modeveven)
			System.out.println(n - modenumvodd - modenumveven);
		else
			System.out.println(Math.min(n - modenumvodd - count(veven, mode2(veven, modeveven)),n - count(vodd, mode2(vodd, modevodd)) - modenumveven));
	}

}


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

using namespace std;

int main(){
	int S;
	cin >> S;
	int h = S/3600;
	int m = (S-(h*3600))/60;
	int s = S%60;
	cout << h << ":" << m << ":" << s << endl;
	return 0;
}

Measured memory_bytes: 1168
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <queue>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;

int main()
{
    int H, W, N;
    cin >> H >> W >> N;
    int sr, sc;
    cin >> sr >> sc;
    string S, T;
    cin >> S >> T;

    int cU = 0;
    int cD = 0;
    int cL = 0;
    int cR = 0;
    int Umax = 0;
    int Dmax = 0;
    int Lmax = 0;
    int Rmax = 0;
    for(size_t i=0; i<N; i++){
        if(S[i]=='U'                 ){ cU++; Umax=max(Umax, cU);}
        if(T[i]=='D' && sr-1-cU < H-1){ cU--;}
        if(S[i]=='D'                 ){ cD++; Dmax=max(Dmax, cD);}
        if(T[i]=='U' && sr-1+cD > 0  ){ cD--;}
        if(S[i]=='L'                 ){ cL++; Lmax=max(Lmax, cL);}
        if(T[i]=='R' && sc-1-cL < W-1){ cL--;}
        if(S[i]=='R'                 ){ cR++; Rmax=max(Rmax, cR);}
        if(T[i]=='L' && sc-1+cR > 0  ){ cR--;}
    }
    if(
        sr -1 - Umax <  0
     || sr -1 + Dmax >= H
     || sc -1 - Lmax < 0
     || sc -1 + Rmax >= W
    ) cout<<"NO"<<endl;
    else cout<<"YES"<<endl;


    return 0;
}


Measured memory_bytes: 776
#include <iostream>
#include <typeinfo>

using namespace std;

#define FOR(i, a, b) for(int i=a;i<b;i++)
#define rep(i, n)  FOR(i,0,n)

int main() {
    int N;
    cin >> N;
    int CSF[N-1][3];
    int time;
    rep(i, N - 1) {
        cin >> CSF[i][0] >> CSF[i][1] >> CSF[i][2];
    }
    rep(i, N - 1) {
        time = 0;
        FOR(j, i, N - 1) {
            int a = (int) (time + CSF[j][2] - 1 / CSF[j][2]);
            time = max(CSF[j][1], CSF[j][2] * (int) ((time + CSF[j][2] - 1 )/ CSF[j][2]))+CSF[j][0];
        }
        cout << time << endl;
    }
    cout << 0 << endl;
    return 0;
}

Measured memory_bytes: 256
import sys
from collections import deque
import numpy as np

def main():
    n = int(sys.stdin.readline().rstrip())
    ab = np.array(sys.stdin.read().split(), dtype=np.int64).reshape(-1, 2)

    G = [[] for _ in range(n + 1)]
    for a, b in ab:
        G[a].append(b)
        G[b].append(a)
    
    parent = np.zeros(n + 1, dtype=np.int64)
    color = np.zeros(n + 1, dtype=np.int64) # color of the edge(parent[y], y)

    q = deque([1]) # root = 1
    while q:
        x = q.popleft()
        ng = color[x]
        c = 1
        for y in G[x]:
            if y == parent[x]:
                continue
            parent[y] = x
            if c == ng:
                c += 1
            color[y] = c
            q.append(y)
            c += 1

    print(np.amax(color))

    for a, b in ab:
        if a == parent[b]:
            print(color[b])
        else:
            print(color[a])
            
if __name__ == '__main__':
    main()

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

int main() {
    vector<int> A = {1, 3, 5, 7, 8, 10, 12};
    vector<int> B = {4, 6, 9, 11};

    int x, y;
    cin >> x >> y;
    for(int i = 0; i < A.size(); i++){
        for(int j = 0; j < 7; j++){
            if (x == A.at(i) && y == A.at(j)){
                cout << "Yes" << endl;
                goto finish;
            }
        }
    }
    for(int i = 0; i < B.size(); i++){
        for(int j = 0; j < B.size(); j++){
            if(x == B.at(i) && y == B.at(j)){
                cout << "Yes" << endl;
                goto finish;
            }
        }
    }
    cout << "No" << endl;

    finish: return 0;
}

Measured memory_bytes: 256
N, M, K = map(int, input().split())

ans = False
for n in range(0, N + 1):
    for m in range(0, M + 1):
        res = m * N + n * M - 2 * n * m
        if res == K:
            ans = True
            break

if ans:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 40684
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        
        int a = sc.nextInt();
        int b = sc.nextInt();
        
        if (a < b){
            System.out.println("a < b");
        }else if (a > b){
            System.out.println("a > b");
        }else if (a == b){
            System.out.println("a == b");
        }
        
    }
}



Measured memory_bytes: 26172
import sys
input = sys.stdin.readline


def readstr():
    return input().strip()


def readint():
    return int(input())


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


def readstrs():
    return input().split()


def main():
    N = readint()
    d = sorted(list(readnums()))
    print(d[N // 2] - d[N // 2 - 1])


if __name__ == "__main__":
    main()


Measured memory_bytes: 14300
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i, n) for(ll i=0; i<ll(n); i++)
#define REPR(i, n) for(ll i=n-1; i>=0; i--)
#define FOR(i, m, n) for(ll i=m; i<ll(n); i++)
#define ALL(v) v.begin(), v.end()
#define SIZE(x) ll(x.size()) 
using P = pair<int, int>;
const int INF = 2e9;

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n; string s;
  cin >> n >> s;
  int cnt = 1;
  char c = s[0];
  FOR(i,1,n){
    if(c!=s[i]){
      cnt++;
      c = s[i];
    }
  }
  cout << cnt << endl;
  return 0;
}


Measured memory_bytes: 3752
#include <bits/stdc++.h>
# define ll int64_t
#define rep(i,n) for(ll i=0;i<n;i++)
#define rrep(i,n) for(ll i=1;i<=n;i++)
# define ALL(x) (x).begin(), (x).end()
# define SZ(x) ((int)(x).size())
# define pb push_back
# define mod 1000000007

using namespace std;

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

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

int main(){
    string s,m="";
    cin>>s;
    
    rep(i,s.size()){
        if(s.at(i)=='0') m.append("0");
        if(s.at(i)=='1') m.append("1");
        if(s.at(i)=='B') if(m.size()>=1) m.pop_back();
    }
    cout<<m<<endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		int k = in.nextInt();
		int[] s;
		while (n != 0 && k != 0) {
			s = new int[k];
			for (int i = 0; i < k; i++) {
				s[i] = in.nextInt();
			}
			boolean isYes = true;
			for (int i = 0; i < n; i++) {
				for (int j = 0; j < k; j++) {
					s[j] -= in.nextInt();
					if (isYes) {
						isYes = s[j] >= 0;
					}
				}
			}
			System.out.println(isYes ? "Yes" : "No");
			n = in.nextInt();
			k = in.nextInt();
		}
	}
}

Measured memory_bytes: 12000
import java.util.Scanner;

public class Main {

	/**
	 * それぞれの購入地点から得られる最大利ざやを求め、 最も利益の大きい値を出力する
	 * 
	 * @param args
	 */
	public static void main(String args[]) {
		Scanner scan = new Scanner(System.in);
		int num = scan.nextInt();
		int[] value = new int[num];
		for (int i = 0; i < num; i++) {
			value[i] = scan.nextInt();
		}

		System.out.println(ExchangeMax(value));

		scan.close();
	}

	/**
	 * 為替の最小値と最大値を見つけ、その差を最大利ざやとする。
	 * 
	 * @param value
	 *            為替レート
	 * @return 最大利ざや
	 */
	static int ExchangeMax(int[] value) {
		int max = Integer.MIN_VALUE;
		int min = value[0];
		for (int i = 1; i < value.length; i++) {
			max = Math.max(max, value[i] - min);
			min = Math.min(min, value[i]);
		}
		return max;
	}

}



Measured memory_bytes: 102268
import sys
sys.setrecursionlimit(10**7)
INTMAX = 9223372036854775807
INTMIN = -9223372036854775808
MOD = 1000000007
def POW(x, y): return pow(x, y, MOD)
def INV(x, m=MOD): return pow(x, m - 2, m)
def DIV(x, y, m=MOD): return (x * INV(y, m)) % m
def LI(): return [int(x) for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LS(): return input().split()
def II(): return int(sys.stdin.readline())
def SI(): return input()

S = input()
X,Y=LI()

while S and S[0] == 'F':
    S = S[1:]
    X -= 1

isX = True
cur = 0
xs = []
ys = []
for i in range(len(S)):
    if S[i] == 'T':
        if cur:
            if isX:
                xs.append(cur)
            else:
                ys.append(cur)
        isX = not isX
        cur = 0
    elif S[i] == 'F':
        cur += 1

if cur:
    if isX:
        xs.append(cur)
    else:
        ys.append(cur)

X=abs(X)
Y=abs(Y)
xs.sort()
ys.sort()
xss = [0]
yss = [0]
for i in xs:
    xss.append(xss[-1]+i)
for i in ys:
    yss.append(yss[-1]+i)

memo1 = {}
def dp1(x, i):
    if abs(x) > xss[i+1]: return False
    if i < 0: return x == 0
    if (x, i) in memo1: return memo1[(x,i)]
    res = dp1(x - xs[i], i-1) or dp1(x + xs[i], i-1)
    memo1[(x,i)] = res
    return res

memo2 = {}
def dp2(x, i):
    if abs(x) > yss[i+1]: return False
    if i < 0: return x == 0
    if (x, i) in memo2: return memo2[(x,i)]
    res = dp2(x - ys[i], i-1) or dp2(x + ys[i], i-1)
    memo2[(x,i)] = res
    return res


# print(xs, ys)
print('Yes' if dp1(X, len(xs)-1) and dp2(Y, len(ys)-1) else 'No')


Measured memory_bytes: 119132
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
#define all(x)     		(x).begin(),(x).end()
#define ub    			upper_bound
#define lb 				lower_bound
#define int 			long long
#define endl			'\n'
#define ff              first
#define ss              second
#define ull		unsigned long long
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define si 				set<int>		
#define mii             map<int,int>
#define umii			unordered_map<int ,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define rep(i,a,n)		for(int i=a;i<n;++i)
#define repd(i,a,n)		for(int i=a;i>n;--i)
#define setbits(x)      __builtin_popcountll(x)
#define zerobits(x)      __builtin_ctzll(x)
#define Mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
#define deb(x)			cout<<#x <<"="<<x<<endl;
#define deb2(x,y)		cout<<#x<<"="<<x<<"  "<<#y<<"="<<y<<endl;
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
int Pow(int a,int b){int res=1;while(b>0){if(b&1)res*=a;a*=a;b/=2;}return res;}
int MPow(int a,int  b){int res=1;while(b>0){if(b&1)res=(res*a)%Mod;a=(a*a)%Mod;b/=2;}return res%Mod;}
int log(int x){return 64-__builtin_clzll(x)-1;}



void c_p_p()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
	//freopen("in.txt", "r", stdin);
	//freopen("out.txt", "w", stdout);
#endif
}
struct Node
{
	int a,b,c,d;
	
};
const int Max=1e5+1;
int Dp[Max];
int Frog(int A[], int i, int n)
{
	if(i==n || i==n-1)
		return abs(A[i]-A[n]);
	if(Dp[i]==-1)
	{
		return Dp[i]=min(abs(A[i]-A[i+1])+Frog(A,i+1,n),abs(A[i]-A[i+2])+Frog(A,i+2,n));

	}
	return Dp[i];

}

int32_t main()
{
	c_p_p();
	memset(Dp,-1,sizeof(Dp));
	int n;
	cin>>n;
	int A[n+1];
	rep(i,1,n+1)
	cin>>A[i];
	cout<<Frog(A,1,n);
	return 0;
}
	

Measured memory_bytes: 9136
#include<iostream>
#include<string>
#include<cmath>
#include<vector>
#include<stack>
#include<queue>
#include<algorithm>
#include<complex>
using namespace std ;
typedef vector<int> vi ;
typedef vector<vi> vvi ;
typedef vector<string> vs ;
typedef pair<int, int> pii; 
typedef long long ll ;

#define loop(i,a,b) for(int i = a ; i < b ; i ++)
#define rep(i,a) loop(i,0,a)
#define all(a) (a).begin(),(a).end()
int main(void){
  double r,l;
    vi re(4,0);
    vi le(4,0);
    while(cin>>r>>l){
    if(r>=1.1)re[0]++;
    else if(r>=0.6)re[1]++;
    else if(r>=0.2)re[2]++;
    else if(r>=0)re[3]++;

    if(l>=1.1)le[0]++;
    else if(l>=0.6)le[1]++;
    else if(l>=0.2)le[2]++;
    else if(l>=0)le[3]++;


  }
  
  rep(i,4)
    cout<<re[i]<<" "<<le[i]<<endl;

}

Measured memory_bytes: 1220
h, w, a, b = map(int, input().split())
s = [[0] * w for _ in range(h)]
for i in range(h):
    for j in range(w):
        if (i < b and j < a) or (b <= i and a <= j):
            s[i][j] = 1
for t in s:
    print("".join(map(str, t)))

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

int main(){
  
  int n, m, k, a[20], b[20], ma=0;

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

  if(k==1){
    for(int i=0;i<n;i++){
      if(m<b[i]) ma=max(ma, a[i]*m); 
      else ma=max(ma, a[i]*b[i]+(m-b[i]));
    }
  }else if(k==2){
    for(int i=0;i<n;i++){
      int sum1=0, x;
      if(m<b[i]){
	sum1+=a[i]*m;
	x=m-m;
      }else{
	sum1+=a[i]*b[i];
	x=m-b[i];
      }
      for(int j=0;j<n;j++){
	int sum2=sum1;
	if(i==j) continue;
	if(x<b[j]){
	  sum2+=a[j]*x;
	  ma=max(ma, sum2);
	}else{
	  sum2+=a[j]*b[j];
	  ma=max(ma, sum2+(x-b[j]));
	}
      }
    }
  }else if(k==3){
    for(int i=0;i<n;i++){
      int sum1=0, x;
      if(m<b[i]){
	sum1+=a[i]*m;
	x=m-m;
      }else{
	sum1+=a[i]*b[i];
	x=m-b[i];
      }
      for(int j=0;j<n;j++){
	int sum2=sum1, y;
	if(x<b[j]){
	  sum2+=a[j]*x;
	  y=x-x;
	}else{
	  sum2+=a[j]*b[j];
	  y=x-b[j];
	}
	for(int l=0;l<n;l++){
	  int sum3=sum2;
	  if(i==j||i==l||j==l) continue;
	  if(y<b[l]){
	    sum3+=a[l]*y;
	    ma=max(ma, sum3);
	  }else{
	    sum3+=a[l]*b[l];
	    ma=max(ma, sum3+(y-b[l]));
	  }
	}
      }
    }
  }
    
  cout<<ma<<endl; 
  
  
  return 0;
}

Measured memory_bytes: 3104
def BinarySearch(S, key):
    left = 0
    right = n
    while left < right:
        mid = int((left + right) / 2)
        if S[mid] == key:
            return 1
        elif S[mid] < key:
            left = mid+1
        else:
            right = mid
    
    return 0

n = int(input())
S = list(map(int, input().split()))
q = int(input())
T = list(map(int, input().split()))

cnt = 0

for i in range(q):
    key = T[i]
    cnt += BinarySearch(S,key) 

print(cnt)



Measured memory_bytes: 16716
#include<stdio.h>

int A[2000],q,n;

int solve(int i,int m){
  if(m == 0){
    return 1;
  }else if(m < 0 || i > n){
    return 0;
  }

  if(solve(i + 1, m) == 1){
    return 1;
  }
  if(solve(i + 1, m - A[i]) == 1){
    return 1;
  }
}

int main(){
  int i,S[2000];

  scanf("%d",&n);

  for(i=0; i<n; i++){
    scanf("%d",&A[i]);
  }

  scanf("%d",&q);
  for(i=0; i<q; i++){
    scanf("%d",&S[i]);
  }

  for(i=0; i<q; i++){
    if(solve(0,S[i])==1 ){
      printf("yes\n");
    }else{
      printf("no\n");
    }
  }
  return 0;
}



Measured memory_bytes: 2100
#include<iostream>
#include<algorithm>
#include <cassert>
#include<string>
#include<vector>
#include <utility>
#include <math.h>
#include<cmath>
#define INF 1000000009;
using namespace std;
int gcd(int a, int b) {
	while (a % b != 0) {
		int c = 0;
		c = a % b;
		a = b;
		b = c;
	}
	return  b;
}
vector<int> SWITCH[11];
int main() {
	int n = 0;
	cin >> n;
	int much[200005] = { 0 };
	for (int i = 0; i < n; i++) {
		cin >> much[i];
	}
	int maxi = -2000000000;
	int minn = much[0];
	for (int i = 1; i < n; i++) {
		maxi = max(maxi, much[i] - minn);
		minn = min(minn, much[i]);
		//cout << maxi << endl;
	}
	cout << maxi << endl;
	return 0;
}



Measured memory_bytes: 3896
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int[] sums = new int[100001];
        for (int i = 2; i < sums.length; i++) {
            sums[i] = sums[i - 1];
            int count = 0;
            for (int j = 2; j <= Math.sqrt(i) && count < 2; j++) {
                if (i % j == 0) {
                    count++;
                }
            }
            if (count >= 2) {
                sums[i]++;
            }
        }
        int q = sc.nextInt();
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < q; i++) {
            sb.append(sums[sc.nextInt()]).append("\n");
        }
        System.out.print(sb);
    }
}



Measured memory_bytes: 69512
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <stack>
#include <queue>
//ranker
using namespace std;

#define REPS(i, a, n) for (int i = (a); i < (n); ++i)
#define REP(i, n) REPS(i, 0, n)
#define RREP(i, n) REPS(i, 1, n + 1)
#define DEPS(i, a, n) for (int i = (a); i >= n; --i)
#define DEP(i, n) DEPS(i, n, 0)

using ll = long long;
using ull = unsigned long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using pii = pair<int, int>;
using pis = pair<int, string>;
using psi = pair<string, int>;
using D = double;


//複数のソート
void sort2vectors(vector<int> &av, vector<int> &bv)
{
        int n = av.size();
        vector<int> p(n), av2(n), bv2(n);
        iota(p.begin(), p.end(), 0);
        sort(p.begin(), p.end(), [&](int a, int b) { return av[a] < av[b]; });
        for (int i = 0; i < n; i++) {
                av2[i] = av[p[i]];
                bv2[i] = bv[p[i]];
        }
        av = av2;
        bv = bv2;
}

//最大公約数
int gcd(int a, int b)
{
    int c;
    if (a < b) {
        a+=b; b=a-b; a-=b;
    }
    while (b != 0) {
        c = a % b;
        a = b;
        b = c;
    }
    return a;
}

//最小公倍数
int lcm(int x, int y)
{
    return (x * y / gcd(x, y));
}

int isPrime(int x){
  int i;
  if(x < 2) return 0;
  else if(x == 2) return 1;
  if( x%2 == 0) return 0;
  for(i = 3; i*i <= 2; i += 2){
    if(x%i == 0) return 0;
  }
  return 1;
}


const int pmax = 10000000;
bool isPrime_table[pmax];
//constがないと配列宣言できない

void eratos(void){
  int i, j;
  double sqrtmax=sqrt(pmax);

  REP(k, pmax) isPrime_table[k] = true; /* Initialization */

  /* Sieve process  */
  isPrime_table[0] = false;
  isPrime_table[1] = false;
          /* 0 and 1 are not prime. */
  for (i=2; i <= sqrtmax; i++){
    if (isPrime_table[i]==true){   /* i is prime. */
      for (j=i; i*j<pmax; j++){
        isPrime_table[i*j] = false; /* multiples of i are not prime. */
      }
    }
  }
}

//漸化式敵に記述も可能
//abs(dx[i]+dy[j])==1で四方
int dx[3]={-1, 0, 1};
int dy[3]={-1, 0, 1};
int W0, H0;
int  masu0[100][100]={0};
int cnt0;

int dfs(int a, int b){
  masu0[a][b] = 2;
  REP(i, 3)REP(j, 3){
    a = a+dx[i];
    b = b+dy[j];
    if(masu0[a][b]== 1 && a >= 0 && a < W0 && b >= 0 && b < H0){
    dfs(a, b);
  }
  }
  return 1;
}

//文字列取り出し　str.substr(i, 5)
//文字数字変換 stoi, stod とto_string
//初期化memset
//複数配列のソート
//dp
const string abet("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ");
const long long int MOD = 1000000007;

int main(void){

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

  vector <string> vs;
  string s;
  int N, L;
  cin >> N >> L;
  REP(i, N){
    cin >> s;
    vs.push_back(s);
  }
  sort(vs.begin(), vs.end());
  REP(i, N-1) cout << vs[i];
  cout << vs[N-1] << endl;
  return 0;
}


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

int main() {
  int N;
  cin >> N;
  int ans=0;
  int mp;
  rep(i,N){
    int p;
    cin >>p;
    if(i==0){
      mp=p;
      ans++;
      continue;
    }
    mp = min(mp,p);
    if(mp==p) ans++;
  }
  cout << ans;
}



Measured memory_bytes: 256