akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <string>
#include <stack>
#include <algorithm>
#include <queue>
#include <cstdlib>
using namespace std;

int main() {
	string S;
	cin >> S;

	if (S == "SUN") {
		cout << 7 << endl;
		return 0;
	}
	
	if (S == "MON") {
		cout << 6 << endl;
		return 0;
	}

	if (S == "TUE") {
		cout << 5 << endl;
		return 0;
	}

	if (S == "WED") {
		cout << 4 << endl;
		return 0;
	}

	if (S == "THU") {
		cout << 3 << endl;
		return 0;
	}
	
	if (S == "FRI") {
		cout << 2 << endl;
		return 0;
	}

	if (S == "SAT") {
		cout << 1 << endl;
		return 0;
	}

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ft first
#define sc second
#define pt(sth) cout << sth << "\n"
#define moca(a, s, b) a=((a)s(b)+MOD)%MOD
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
template<class T>bool chmax(T &a, const T &b) {if(a<b) {a=b; return 1;} return 0;}
template<class T>bool chmin(T &a, const T &b) {if(b<a) {a=b; return 1;} return 0;}
static const ll INF=1e18;
static const ll MAX=101010;
static const ll MOD=1e9+7;


//for(i=0; i<N; i++) cin >> a[i];

class sumSegTree {
public:
  ll n, height;
  vector<ll> data;
  
  sumSegTree(ll _n) {
    n=1;
    height=1;
    while(n<_n) {
      n*=2;
      height++;
    }
    data=vector<ll>(2*n-1);
  }
  
  void add(ll i, ll x) {
    i+=n-1;
    data[i]+=x;
    while(i>0) {
      i=(i-1)/2;
      data[i]+=x;
    }
  }
  
  //[a, b):要求区間，[l, r):対象区間
  ll _sum(ll a, ll b, ll k, ll l, ll r) {
    if(r<=a || b<=l) return 0;
    if(a<=l && r<=b) return data[k];
    else {
      ll s=_sum(a, b, 2*k+1, l, (l+r)/2);
      ll t=_sum(a, b, 2*k+2, (l+r)/2, r);
      return s+t;
    }
  }
  
  ll sum(ll a, ll b) {
    return _sum(a, b, 0, 0, n);
  }
  
};


ll c[MAX*5];
ll pos[MAX*5];

int main(void) {
  ll i, j, k;
  
  ll N, Q;
  cin >> N >> Q;
  for(i=0; i<N; i++) {
    cin >> c[i];
    c[i]--;
  }
  
  vector<pair<pll, ll>> v;
  
  for(i=0; i<Q; i++) {
    ll l, r;
    cin >> l >> r;
    l--; r--;
    v.push_back({{r, l}, i});
  }
  sort(v.begin(), v.end());
  
  for(i=0; i<Q; i++) swap(v[i].ft.ft, v[i].ft.sc);
  
  sumSegTree sst(N);
  
  set<ll> st;
  memset(pos, -1, sizeof(pos));
  
  ll ans[MAX*5];
  for(ll q=0; q<Q; q++) {
    ll l=v[q].ft.ft;
    ll r=v[q].ft.sc;
    
    for(i=(q==0)?0:v[q-1].ft.sc+1; i<=r; i++) {
      if(st.find(c[i])!=st.end()) sst.add(pos[c[i]], -1);
      
      st.insert(c[i]);
      pos[c[i]]=i;
      sst.add(i, 1);
    }
    
    ans[v[q].sc]=sst.sum(l, r+1);
  }
  
  for(i=0; i<Q; i++) pt(ans[i]);
  
}




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

int main()
{
    int n,x;
    for( ; ; ){
    cin >> n >> x;
    if(n==0 && x==0)
    {
        break;
    }
    int ans=0;
    for(int i=1;i<n+1;i++)
    {
        for(int j=i+1;j<n+1;j++)
        {
            for(int k=j+1;k<n+1;k++)
            {
                if(i+j+k==x)
                {
                    ans++;
                }
            }
        }
    }
    cout << ans << endl;
    }
}


Measured memory_bytes: 3096
#include <iostream>
#include<cstdlib>
#include<queue>
#include<set>
#include<vector>
#include<string>
#include<algorithm>
#include<stack>
#include<map>
#include<cstdio>
#include<fstream>
using namespace std;
#define rep(i,a) for(int i=0;i<a;i++)
#define mp make_pair
#define P pair<int,int>
const int MOD=1000000000+7;

int n;
int a[11111];
int ans=0;

int main(){
	cin>>n;
	rep(i,n)cin>>a[i];
	rep(i,n){
		while(a[i]%2==0)ans++,a[i]/=2;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
<?php
$inputNum = getInput();

for ($i = 1; $i <= $inputNum; $i++) {
    if (($i % 3 == 0) || preg_match('/3/', $i)) {
        $conditionMatchedNum[] = $i;
    }
}

echo sprintf(' %s', implode(' ', $conditionMatchedNum)), PHP_EOL;

function getInput()
{
     return trim(fgets(STDIN));
}

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

int main() {
  int n,a,b;
  cin>>n>>a>>b;
  int c1=0,c2=0,c3=0;
  for(int i=0;i<n;i++){
    int x;
    cin>>x;
    if(x<=a)c1++;
    else if(x<=b)c2++;
    else c3++;
  }
  int kotae=min({c1,c2,c3});
  cout<<kotae<<endl;
  return 0;
}

Measured memory_bytes: 3604
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define pi M_PI
#define R cin>>
#define Z class
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define REP(i,m,n) for(int i=(int)(m);i<(int)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
template<Z A>void pr(A a){cout<<a;ln;}
template<Z A,Z B>void pr(A a,B b){cout<<a<<' ';pr(b);}
template<Z A,Z B,Z C>void pr(A a,B b,C c){cout<<a<<' ';pr(b,c);}
template<Z A,Z B,Z C,Z D>void pr(A a,B b,C c,D d){cout<<a<<' ';pr(b,c,d);}
template<Z A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}
const ll MAX=1000000007,MAXL=1LL<<60,dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
typedef pair<int,int> P;

void Main() {
  ll n,t,tt=1;
  while(cin >> n >> t && n) {
    ll s[n];
    rep(i,n) R s[i];
    ll l=s[0]-1,r=MAXL;
    while(l+1<r) {
      ll m=(l+r)/2;
      ll x=1,c=0;
      ll k=0;
      while(1) {
        while(k<n&&x+m>s[k]) k++;
        if(!k) break;
        if(k==n) {
          c++;
          break;
        }
        ll l=lower_bound(s,s+k,x)-s;
        ll y=max(1LL,m-abs(x-s[l]));
        if(l) y=max(y,m-abs(x-s[l-1]));
        c++;
        x+=y;
      }
      /*
      rep(i,n) {
        while(i<n&&s[i]-(x+m)<0) i++;
        if(i==n) {c++;break;}
        ll d=s[i]-(x+m);
        if(!i&&d>=0) {
          c=MAXL;
          break;
        }
        while(d>=0) {
          ll y=max(1LL,m-abs(x-s[i-1]));
          c++;
          x+=y;
          d=s[i]-(x+m);
        }
        while(i<n&&s[i]-(x+m)<0) i++;
        i--;
        c++;
        x+=max(1LL,m-abs(x-s[i]));
      }
      */
      if(c>=t) l=m;
      else r=m;
    }

    /*
    if(tt==50) {
      pr(tt);
      pr(n,t);
      PR(s,n);
    }
    tt++;
    */
    ll x=1,c=0,m=l;
    ll k=0;
    while(1) {
      while(k<n&&x+m>s[k]) k++;
      if(!k) break;
      if(k==n) {
        c++;
        break;
      }
      ll l=lower_bound(s,s+k,x)-s;
      ll y=max(1LL,m-abs(x-s[l]));
      if(l) y=max(y,m-abs(x-s[l-1]));
      c++;
      x+=y;
    }
    /*
    rep(i,n) {
      while(i<n&&s[i]-(x+m)<0) i++;
      if(i==n) {c++;break;}
      ll d=s[i]-(x+m);
      if(!i&&d>=0) {
        c=-1;
        break;
      }
      while(d>=0) {
        ll k=lower_bound(s,s+i,x)-s;
        ll y=max(1LL,m-abs(x-s[k]));
        if(k) y=max(y,m-abs(x-s[k-1]));
        c++;
        x+=y;
        d=s[i]-(x+m);
      }
      while(i<n&&s[i]-(x+m)<0) i++;
      ll k=lower_bound(s,s+i,x)-s;
      i--;
      c++;
      x+=max(1LL,m-abs(x-s[i]));
    }
    */
    if(c<t) pr(-1);
    else pr(m);
  }
}

int main(){ios::sync_with_stdio(0);cin.tie(0);Main();return 0;}


Measured memory_bytes: 3892
#include<iostream>
#include<fstream>
#include<string>
#include<string.h>
using namespace std;

string str;

int main() {
	cin >> str;
	int l = strlen(str.c_str());
	int res = 0;
	char tempc = str[0];

	for (int i = 1; i < l; i++) {
		if (tempc != str[i]) {
			res++;
			tempc = str[i];
		}
	}
	cout << res << endl;
	return 0;
}

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

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

using ll = long long;
using namespace std;

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

    auto lognk = log(n) / log(k);

    cout << (floor(lognk) + 1) << endl;
}


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

#define fs first
#define sc second
#define pb emplace_back
#define mp make_pair
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()

const int32_t inf = 1001001001;
const int64_t infll = 1001001001001001001ll;
const int dx[] = {0, -1, 1, 0, -1, 1, -1, 1}, dy[] = {-1, 0, 0, 1, -1, -1, 1, 1};

template <typename T> using vector2d = vector<vector<T>>;

// clang-format off
template <typename T> void sort(vector<T> &v) { sort(all(v)); }
ostream &operator<<(ostream &os, __int128_t value) { if (ostream::sentry(os)) { __uint128_t tmp = value < 0 ? -value : value; char buffer[64]; char *d = end(buffer); do { --d; *d = "0123456789"[tmp % 10]; tmp /= 10; } while (tmp != 0); if (value < 0) { --d; *d = '-'; } int len = end(buffer) - d; if (os.rdbuf()->sputn(d, len) != len) { os.setstate(ios_base::badbit); }} return os; }
istream &operator>>(istream &is, __int128_t &value) { string in; is >> in; value = 0; for (const char &c : in) { if ('0' <= c && c <= '9') value = 10 * value + (c - '0'); } if (in[0] == '-') value *= -1; return is; }
ostream &operator<<(ostream &os, __uint128_t value) { if (ostream::sentry(os)) { char buffer[64]; char *d = end(buffer); do { --d; *d = "0123456789"[value % 10]; value /= 10; } while (value != 0); int len = end(buffer) - d; if (os.rdbuf()->sputn(d, len) != len) { os.setstate(ios_base::badbit); }} return os; }
istream &operator>>(istream &is, __uint128_t &value) { string in; is >> in; value = 0; for (const char &c : in) { if ('0' <= c && c <= '9') value = 10 * value + (c - '0'); } return is; }
template <typename T> ostream &operator<<(ostream &os, vector<T> &v) { os << v[0]; for (int i = 1; i < v.size(); ++i) os << " " << v[i]; return os; }
template <typename T> istream &operator>>(istream &is, vector<T> &v) { for (T &in : v) is >> in; return is; }
template <typename T1, typename T2> ostream &operator<<(ostream &os, pair<T1, T2> p) { os << p.fs << " " << p.sc; return os; }
template <typename T1, typename T2> istream &operator>>(istream &is, pair<T1, T2> &p) { is >> p.fs >> p.sc; return is; }

struct IoSetup { IoSetup(){ cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(10); cerr << fixed << setprecision(10); } } iosetup;

inline int64_t in() { int64_t x = 0; cin >> x; return x; }
template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }
// clang-format on

signed main(int argc, char *argv[]) {
  int x = in();
  int a = x, b = 0;
  while (a) {
    b += a % 10;
    a /= 10;
  }

  if (x % b) {
    cout << "No" << endl;
  } else {
    cout << "Yes" << endl;
  }
}


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

string rev_str(string &s, int start, int end) {
    string t;
    for(int i=end-1; i>=start; --i) t += s[i];
    return t;
}

int main(void){
    int m;
    map<string, int> hoge;
    cin >> m;
    rep(loop, m) {
        hoge.clear();
        string org, tmp, tmp2;
        cin >> org;
        hoge[org] = 1;
        int len = org.size();
        for(int i=1; i<len; ++i) {
            hoge[org.substr(0, i)+rev_str(org, i, len)] = 1;
            hoge[rev_str(org, 0, i)+org.substr(i, len-i)] = 1;
            hoge[rev_str(org, 0, i)+rev_str(org, i, len)] = 1;
            hoge[org.substr(i, len-i)+org.substr(0, i)] = 1;
            hoge[org.substr(i, len-i)+rev_str(org, 0, i)] = 1;
            hoge[rev_str(org, i, len)+org.substr(0, i)] = 1;
            hoge[rev_str(org, i, len)+rev_str(org, 0, i)] = 1;
        }
        map<string, int>::iterator it = hoge.begin();
        int ans = 0;
        while(it != hoge.end()) {
            ans += (*it).second;
            it++;
        }
        cout << ans << endl;
    }
}

Measured memory_bytes: 1312
#ifndef _TEMPLATE_ROOT
#define _TEMPLATE_ROOT
#include "bits/stdc++.h"
using namespace std;
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define repl(i, a, b) for(ll i = a; i < (b); ++i)
#define repd(i, a, b) for(int i = b; i >= (a); --i)
#define repdl(i, a, b) for(ll i = b; i >= (a); --i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
template<typename H> bool chmin(H& v1, const H v2) { if (v1 > v2) { v1 = v2; return true; } return false; }
template<typename H> bool ihmax(H& v1, const H v2) { if (v1 < v2) { v1 = v2; return true; } return false; }
#endif
#ifndef _TEMPLATE_IO
#define _TEMPLATE_IO

template<typename H> void read(H& head) { cin >> head; }
template<typename H, typename ...T> void read(H& head, T& ...tail) { cin >> head; read(tail...); }
template<typename H> void write(H head) { cout << head << '\n'; }
template<typename H, typename ...T> void write(H head, T ...tail) { cout << head << " "; write(tail...); }
template<typename ...T> void die(T ...tok) { write(tok...); exit(0); }
#endif
#ifndef _TEMPLATE_OPT
#define _TEMPLATE_OPT
#pragma GCC optimize("Ofast")
#pragma GCC target("avx2")
#endif
using namespace std;

int a[500005];

struct Query {
  int l, r, id, ans;
};

// freqcnt
int freq[500005];
int distinct = 0;
void freqadd(int x) { 
//write("FA", x, freq[x], "->", freq[x]+1);
  if (!freq[x]) distinct++; freq[x]++; }
void freqrem(int x) { 
  
//write("FR", x, freq[x], "->", freq[x]-1);
  freq[x]--; if (!freq[x]) distinct--; }
Query query[500005];

int main() {
	cin.tie(0)->sync_with_stdio(0);
	cin.exceptions(cin.failbit);

  int n, q; read(n, q);
  rep(i, 1, n + 1) read(a[i]);
  rep(i, 0, q) read(query[i].l, query[i].r), query[i].id = i;
  
  const int BS = 1000;
  sort(query, query + q, [](const Query& a, const Query& b) {
    if (a.l / BS != b.l / BS) return a.l / BS < b.l / BS;
    else return (a.l / BS % 2 ? a.r < b.r : a.r > b.r);
    });

  // inclusive [cl, cr]
  int cl = 1, cr = 0;
  rep(i, 0, q) {
    int nl = query[i].l, nr = query[i].r;
    while (cl > nl) freqadd(a[--cl]);
    while (cr < nr) freqadd(a[++cr]);
    while (cl < nl) freqrem(a[cl++]);
    while (cr > nr) freqrem(a[cr--]);
    query[i].ans = distinct;
  }

  sort(query, query + q, [](const Query& a, const Query& b) { return a.id < b.id; });
  rep(i, 0, q) write(query[i].ans);
}



Measured memory_bytes: 15504
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		int sum = 0;
		int ave = 0;
		int count = 0;
		while(scan.hasNext()){
			String[] str = (scan.nextLine()).split(",");
			int a = Integer.parseInt(str[0]);
			int b = Integer.parseInt(str[1]);
			count++;
			sum += a*b;
			ave += b;
		}
		System.out.println(sum + "\n" + (int)(((double)ave/count)+0.5));
	}
}

Measured memory_bytes: 17132
#include<iostream>
#include<iomanip>
#include<string>
#include<array>
#include<cmath>
#include<vector>
#include<utility>
#include<algorithm>
using namespace std;


int main() {
	int d;
	cin >> d;
	if (d==25) {
		cout << "Christmas" << endl;
	}
	else if (d==24) {
		cout << "Christmas Eve" << endl;
	}
	else if (d==23) {
		cout << "Christmas Eve Eve" << endl;
	}
	else {
		cout << "Christmas Eve Eve Eve" << endl;
	}
}

Measured memory_bytes: 256
def color(x):
	if x < 400:
		return "grey"
	
	if x < 800:
		return "brown"

	if x < 1200:
		return "green"

	if x < 1600:
		return "cyan"

	if x < 2000:
		return "blue"

	if x < 2400:
		return "yellow"

	if x < 2800:
		return "orange"

	if x < 3200:
		return "red"

	return "x"

colors = ["grey", "brown", "green", "cyan", "blue", "yellow", "orange", "red"]
C = []

n = int(input())

c = 0

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

for a in A:
	if(color(a) == "x"):
		c += 1
	else:
		C.append(color(a))

C = list(set(C))

m = len(C) + c

if(len(C) == 0):
	C.append("x")

print("{} {}".format(len(C), m))

Measured memory_bytes: 3064
//Don't have to see. start------------------------------------------
var read = require('readline').createInterface({
  input: process.stdin, output: process.stdout
});
var obj; var inLine = [];
read.on('line', function(input){inLine.push(input);});
read.on('close', function(){
  obj = init(inLine);
  console.error('\n↑入力 ↓出力');
  Main();
});
function makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}
function nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}
function nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}
function next(){return obj.next();} function hasNext(){return obj.hasNext();}
function init(input){  
  return {
    list : input, index : 0, max : input.length,
    hasNext : function(){return (this.index < this.max);},
    next : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException ‚There is no more input';}}
  };
}
function myout(s){console.log(s);}
function myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}
//param "no" is
//unknown or outlier : return i. 1: parseInt.
//2: split space. 4: split space and parseInt.
//6: split 1 character. 7: split 1 character and parseInt.
//8: join space. 9: join nextline. 0: join no character.
function myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}

//Don't have to see. end------------------------------------------
function Main(){
  var N = nextInt();
  var list = nextIntArray();
  var output = 100000000;
  for(var i = 1; i <= 100; i++){
    var sum = 0;
    for(var j = 0; j < N; j++){
      sum += Math.pow(i - list[j] , 2);
    }
    output = Math.min(output, sum);
  }
  myout(output);
}


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

int main() {
	int a, b;
	string t;
	cin >> a >> b >> t;
	t[b - 1] = t[b - 1] + 32;
	cout << t << endl;
}

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


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef pair<ll,ll> p2;
ll a[200005],vis[200005],tr,ind;
vector<ll> g;
void dfs(ll i){
	vis[i]=1;
	g.push_back(i);
	if(!vis[a[i]])
	dfs(a[i]);
	else
	tr=a[i];
}
void solve(){
	ll n,k;
	cin>>n>>k;
	for(ll i=1;i<=n;i++)
	cin>>a[i];
	dfs(1);
	for(ll i=0;i<ll(g.size());i++)
	if(g[i]==tr)
	ind=i;
	if(k<ll(g.size())){
		cout<<g[k];
		exit(0);
	}
	reverse(g.begin(),g.end());
	k-=ind;
	while(ind>0){
		g.pop_back();
		ind--;
	}
	reverse(g.begin(),g.end());
	cout<<g[k%(ll(g.size()))];
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll qc=1;
    for(ll i=1;i<=qc;i++)
    solve();
}


Measured memory_bytes: 14104
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <numeric>
#include <math.h>


using namespace std;

int main() {
    char c;
    cin >> c;
    if (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u')
        cout << "vowel" << endl;
    else
        cout << "consonant" << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    int k,a,b; cin>>k>>a>>b;
    for(int i=a;i<=b;i++)
    {
        if(i%k==0)
        {
            cout<<"OK";
            return 0;
        }
    }
    cout<<"NG";
}


Measured memory_bytes: 3600
from collections import defaultdict

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

s = defaultdict(list)
for i in range(M):
    tmp = [int(x) for x in input().split()]
    s[i] = set(tmp[1:])
p = [int(x) for x in input().split()]

ans = 0
for i in range(1 << N):
    ptn = set()
    for j in range(N):
        if i & (1 << j):
            ptn.add(j + 1)

    flag = True
    for k in range(M):
        c = len(s[k] & ptn) % 2
        if c != p[k]:
            flag = False
            break

    if flag:
        ans += 1
print(ans)


Measured memory_bytes: 3444
total = 0
count = 0
rows = 0

while True:
    try:
        at,n = map(int, raw_input().split(","))
    except EOFError as e:
        break
    total += at * n
    count += n
    rows += 1

print("%d" % (total,))
print("%d" % (int(count/float(rows) + 0.5),))

Measured memory_bytes: 4252
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<sstream>
#include<cmath>
#include<numeric>
#include<map>
#include<stack>
#include<queue>
#include<list>
#include<set>
#include<cstring>
using namespace std;
long long int mod = 1e9 + 7;
template <class T>
void inputV(vector<T> &x, int n){
  for(int i=0; i<n; i++) cin >> x[i];
}

int main() {
  int h, w; cin >> h >> w;
  int n; cin >> n;
  vector<int> a(n);
  for(int i=0; i<n; i++) cin >> a[i];

  vector< vector<int> > b(h, vector<int>(w, -1));
  int p = 0;
  int tmp = a[0];
  for(int i=0; i<h; i++){
    for(int j=0; j<w; j++){
      if(i%2==0){
        b[i][j] = p+1;
      }else{
        b[i][w-1-j] = p+1;
      }
      tmp--;
      if(tmp == 0){
        p++;
        tmp = a[p];
      }
    }
  }

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

  return 0;
}


Measured memory_bytes: 384
from bisect import bisect_right

s = input()
N = len(s)
t = input()


d = {chr(i + ord('a')): [] for i in range(26)}

for i, c in enumerate(s):
    d[c].append(i + 1)

acc = 0
b = 0
for c in t:
    if len(d[c]) == 0:
        acc = -1
        break
    q = bisect_right(d[c], b)
    a = d[c][q if q != len(d[c]) else 0]
    if a > b:
        acc, b = acc + a - b, a
    else:
        acc, b = acc + N - b + a, a

print(acc)

Measured memory_bytes: 7668
#include <bits/stdc++.h>
using namespace std;
#define  rep(i, n) for(int i = 0; i < n; i++) 
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  INF 1LL << 60
typedef long long int LL;
typedef long long int ll;
#define pll pair<ll, ll>
#define F first
#define S second
const int MOD = 1000000007;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return true; } return false; }
//sort(all(x))とするとソートできるよ
// 10^x は pow(10,(x)) 
// 任意のlogは　対数の底の変換を使う    log(N) / log(任意の底)

int main(){
    int N,K;cin >> N >> K;
    vector<int> h(N);
    rep(i,N)cin >> h[i];
    int dp[N+K];
    rep(i,N+K+1)dp[i] = 1<<30;
    dp[0] = 0;
    rep(i,N){
        rep(j,K){
            if(i+j+1 >= N)continue;
            else chmin(dp[i+j+1],dp[i] + abs(h[i+j+1] - h[i]));
        }
    }
    cout << dp[N-1] << endl;
}



Measured memory_bytes: 1024
package main

import "fmt"

func main() {
	var N, sum int
	fmt.Scan(&N, &sum)
	result := [3]int{-1, -1, -1}

BREAK_LABEL:
	for i := 0; i <= N; i++ {
		for j := 0; j <= N-i; j++ {
			if sum == 10000*i+5000*j+1000*(N-i-j) {
				result[0] = i
				result[1] = j
				result[2] = N - i - j
				break BREAK_LABEL
			}
		}
	}
	fmt.Printf("%d %d %d", result[0], result[1], result[2])
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main()
{
    ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    ll n, x;
    cin >> n >> x;
    vector<ll> a(n);
    for (int i = 0; i < n; i++)
        cin >> a[i];
    ll ans = 0;
    if (a[0] > x)
    {
        ans += a[0] - x;
        a[0] -= a[0] - x;
    }
    
    for (int i = 0; i < n - 1; i++)
    {
        ll sum = a[i] + a[i + 1];
        if (sum > x)
        {
            ans += a[i + 1] - (x - a[i]);
            a[i + 1] = (x - a[i]);
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using P = pair<int, int>;

long double maxvd = 18;
ll maxvl = 1000000000000000000;

int main(){
	int n;
	cin >> n;
	vector<ll> a(n, 0);
	for(int i=0; i<n; i++){
		cin >> a[i];
		if(a[i] == 0){
			cout << 0 << endl;
			return 0;
		}
	}

	long double ansd = 0;
	ll ans = 1;
	for(int i=0; i<n; i++){
		ansd += log10(a[i]);
		if(ansd > maxvd){
			cout << -1 << endl;
			return 0;
		}
		ans *= a[i];
		if(ans > maxvl){
			cout << -1 << endl;
		    return 0;
		}
	}

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


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

int main() {
    const ll MOD = 1e9 + 7;
    int n;
    cin >> n;
    ll a[n];
    rep(i, n) cin >> a[i];

    ll ans = 0;
    rep(bit, 61) {
        int one = 0, zero = 0;
        rep(i, n) {
            if (a[i] >> bit & 1)
                one++;
            else
                zero++;
        }

        ll p = (1ll << bit) % MOD;
        ans += p * one % MOD * zero;
        ans %= MOD;
    }

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


Measured memory_bytes: 2688
#include "bits/stdc++.h"
using namespace std;
     
#define DEBUG(x) cout<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cout<<#v<<":";for(int i=0;i<v.size();i++) cout<<" "<<v[i]; cout<<endl
     
typedef long long ll;
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll, ll>
const int inf = 1000000001;
const ll INF = 1e16;
#define MOD 1000000007
#define mod 1000000009
#define pi 3.14159265358979323846
#define Sp(p) cout<<setprecision(15)<<fixed<<p<<endl;
int dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 };
int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };

#define N 100001
#define K 100001
vi par(N); //親
vi ran(N); //木の深さ
vi num(N);

//n要素で初期化
void init(int n){
	int i;
	for (i = 0; i < n; i++) {
		par[i]=i;
		ran[i]=0;
		num[i] = 1;
	}
}

//木の根を求める
int find(int x){
	if(par[x]==x){
		return x;
	}else{
		return par[x]=find(par[x]);
	}
}

//xとyの属する集合を併合
void unite(int x,int y){
	x=find(x);
	y=find(y);
	int numsum = num[x] + num[y];
	if(x==y){
		return;
	}
	if(ran[x]<ran[y]){
		par[x]=y;
	}else{
		par[y]=x;
		if(ran[x]==ran[y]){
			ran[x]++;
		}
	}
	num[x] = num[y] = numsum;
}

//xとyが同じ集合に属するか否か
bool same(int x,int y){
	return find(x)==find(y);
}


int main() {
  int n, m, i, j;
  cin >> n >> m;
  vi x(n);
  vii module(m, vi());
  for (i = 0; i < n; i++) {
    cin >> x[i];
  }
  sort(x.begin(), x.end());
  for (i = 0; i < n; i++) {
    module[x[i] % m].push_back(x[i]);
  }
  int cnt = 0;
  cnt += module[0].size() / 2;
  int left = 1, right = m - 1;
  // for (i = 0; i < m; i++) {
  //   cout << i << " : ";
  //   for (j = 0; j < module[i].size(); j++) {
  //     cout << module[i][j] << " ";
  //   }
  //   cout << endl;
  // }
  // cout << cnt << endl;
  while (left <= right) {
    if (left == right) {
      cnt += module[left].size() / 2;
      left++; right--;
      continue;
    }
    int m = min(module[left].size(), module[right].size());
    cnt += m;
    int small, big;
    if (module[left].size() >= module[right].size()) {
      small = right;
      big = left;
    }
    else {
      small = left;
      big = right;
    }
    int cnt2 = 0;
    int pre = -1;
    for (i = 0; i < module[big].size(); i++) {
      if (module[big][i] == pre) {
	cnt2++;
	pre = -1;
      }
      else {
	pre = module[big][i];
      }
    }
    cnt += min(cnt2, ((int)module[big].size() - m) / 2);
    left++; right--;
  }
  cout << cnt << endl;
 
  
			   
}


Measured memory_bytes: 7296
use std::collections::BinaryHeap;
use std::io::Read;

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).ok();
    let mut iter = buf.split_whitespace();
    let n = iter.next().unwrap().parse::<usize>().unwrap();
    let m = iter.next().unwrap().parse::<usize>().unwrap();
    let mut h = BinaryHeap::new();
    for _i in 0..n {
        h.push((iter.next().unwrap().parse::<i64>().unwrap(), 1));
    }
    for _i in 0..m {
        let b = iter.next().unwrap().parse::<i64>().unwrap();
        let c = iter.next().unwrap().parse::<i64>().unwrap();
        h.push((c, b));
    }
    let mut res = 0;
    let mut rest = n as i64;
    for _i in 0..n {
        let (b, c) = h.pop().unwrap();
        res += std::cmp::min(rest, c) * b;
        rest = std::cmp::max(0, rest - c);
    }
    println!("{}", res);
}


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

using lint = long long int;
using pint = pair<int, int>;
using plint = pair<lint, lint>;
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((lint)(x).size())
#define POW2(n) (1LL << (n))
#define FOR(i, begin, end) for (int i = (begin), i##_end_ = (end); i < i##_end_; i++)
#define IFOR(i, begin, end) for (int i = (end)-1, i##_begin_ = (begin); i >= i##_begin_; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)
#ifdef LOCAL
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
#define eprintf(...) 42
#endif

int main()
{

    string s;
    cin >> s;

    string t;
    cin >> t;

    lint ans = 0;

    REP(i, 3){
        if (s[i] == t[i]){
            ans += 1;
        }
    }
    
    cout << ans <<"\n";

    return 0;
}

Measured memory_bytes: 256
from collections import Counter
import sys
from random import randint
from time import time
start = time()
sys.setrecursionlimit(1000000000)
input = sys.stdin.readline


def get_sat():
    sat = 0
    when = [-1] * 26
    for i in range(d):
        sat += s[i][t[i]]
        when[t[i]] = i
        for j in range(26):
            sat -= c[j] * (i - when[j])
    return sat


d = int(input())
c = list(map(int, input().split()))
s = [list(map(int, input().split())) for _ in range(d)]
t = [randint(0, 25) for i in range(d)]
ans = get_sat()
while time() - start < 1.8:
    p, q = randint(0, d - 1), randint(0, 25)
    x = t[p]
    t[p] = q
    y=get_sat()
    if ans >= y:
        t[p] = x
    else:
        ans=y
for i in t:
    print(i + 1)


Measured memory_bytes: 80644
#include "bits/stdc++.h"
#define lpa(i,a,b) for(int i=a; i<b; ++i)
#define lp(i,n) lpa(i,0,n)
#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define print_v(v,n) lp(i,n) cout<<v[i]<<' '; cout<<'\n';
using namespace std;
typedef long long ll;
ll f(ll n, ll m){
	return n - n/m;
}
int main(){
	ll a, b,c,d; cin>>a>>b>>c>>d;
	ll lcm = c*d/__gcd(c,d);
	ll ans = f(b,c)-f(a-1,c)+f(b,d)-f(a-1,d)-f(b, lcm)+f(a-1,lcm);
	cout<<ans;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<cmath>
#include<map>
#include<queue>
#include<stack>
#include<algorithm>
#include<functional>

typedef unsigned long long LL;

using namespace std;

int keta(int N) {
	int ret = 1;
	while (true) {
		N = N / 10;
		if (N <= 0) {
			break;
		}
		ret += 1;
	}
	return ret;
}

int main() {
	int N;
	cin >> N;
	int ret = 0;
	for (int i = 1; i <= N; i++) {
		if (keta(i) % 2 != 0) {
			ret++;
		}
	}
	cout << ret << endl;
}



Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<cstdio>
#include<cmath>
#include<deque>
#include<numeric>
#include<queue>
#include<stack>
#include<cstring>
#include<limits>
#include<functional>
#include<unordered_set>
#include<iomanip>
#include<cassert>
#include<regex>
#include<bitset>
#include<complex>
#include<chrono>
#include<random>
#define rep(i,a) for(int i=(int)0;i<(int)a;++i)
#define rrep(i,a) for(int i=(int)a-1;i>=0;--i)
#define REP(i,a,b) for(int i=(int)a;i<(int)b;++i)
#define RREP(i,a,b) for(int i=(int)a-1;i>=b;--i)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(),x.end()
using ll=long long;
constexpr ll mod = 1e9 + 7;
constexpr ll INF = 1LL << 60;

ll gcd(ll n, ll m) {
	ll tmp;
	while (m!=0) {
		tmp = n % m;
		n = m;
		m = tmp;
	}
	return n;
}

ll lcm(ll n, ll m) {
	return abs(n) / gcd(n, m)*abs(m);//gl=xy
}
 
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;
}
 
using namespace std;

bool check[10];
void solve(){
  int n;
  string s;
  cin>>n>>s;
  memset(check,0,sizeof(check));
  int ans=0;
  rep(i,n-2){
    if(check[s[i]-'0'])continue;
    check[s[i]-'0']=true;
    vector<bool>check2(10);
    REP(j,i+1,n-1){
      if(check2[s[j]-'0'])continue;
      check2[s[j]-'0']=true;
      set<int>st;
      REP(k,j+1,n){
        if(!st.count(s[k]-'0'))++ans;
        st.emplace(s[k]-'0');
      }
    }
  }
  cout<<ans;
}

int main(){
	ios::sync_with_stdio(false);
  cin.tie(0);
	cout<<fixed<<setprecision(15);
  solve();
	return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <functional>
using namespace std;
int main(void) {
  int N, P1, P2, Cal1, Cal2[100]; // 1 -> ¶n  2 -> gbsO
  int Ans;
  
  while(cin >> N) {
    cin >> P1 >> P2 >> Cal1;
    for(int i = 0 ; i < N ; i++) {
      cin >> Cal2[i];
    }
    
    sort(Cal2, Cal2+N, greater<int>());
    
    int V = Cal1, P = P1;
    Ans = Cal1 / P1; // ¶nÌêh ½è
    
    for(int i = 0 ; i < N ; i++) {
      V += Cal2[i];
      P += P2;
      Ans = max(Ans, V/P);
    }
    cout << Ans << endl;
  }
  return 0;
}

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

const int INF = 1 << 30;

class BigInteger
{
private:
  static const int DIGIT = 1000;

public:
  int num[DIGIT];

  BigInteger()
  {
    for (int i = 0; i < DIGIT; ++i)
      num[i] = 0;
  }

  BigInteger(const string& s)
  {
    BigInteger();
    for (int i = 0; i < s.size(); ++i)
      num[DIGIT-1-i] = s[s.size()-1-i];
  }

  BigInteger(const BigInteger& b)
  {
    for (int i = 0; i < DIGIT; ++i)
      num[i] = b.num[i];
  }

  BigInteger operator +(const BigInteger& rhs) const
  {
    BigInteger res;
    for (int i = 0; i < DIGIT; ++i)
      res.num[i] = num[i] + rhs.num[i];
    for (int i = DIGIT-1; i > 0; --i) {
      if (res.num[i] >= 10) {
	res.num[i] -= 10;
	++res.num[i-1];
      }
    }
    return res;
  }

  void operator +=(int rhs)
  {
    int index = DIGIT-1;
    while (rhs != 0) {
      num[index--] += rhs % 10;
      rhs /= 10;
    }
    for (int i = DIGIT-1; i > 0; --i) {
      if (num[i] >= 10) {
	num[i] -= 10;
	++num[i-1];
      }
    }
  }

  void operator *=(const int rhs)
  {
    BigInteger tmp(*this);
    for (int i = 0; i < rhs-1; ++i) {
      for (int j = 0; j < DIGIT; ++j)
	num[j] += tmp.num[j];
      for (int j = DIGIT-1; j > 0; --j) {
	if (num[j] >= 10) {
	  num[j] -= 10;
	  ++num[j-1];
	}
      }
    }
  }

  bool operator ==(const BigInteger& rhs) const
  {
    bool eq = true;
    for (int i = 0; i < DIGIT && eq; ++i) {
      if (num[i] != rhs.num[i])
	eq = false;
    }
    return eq;
  }

  void print() const
  {
    bool lz = true;
    for (int i = 0; i < DIGIT; ++i) {
      if (num[i] != 0)
	lz = false;
      if (!lz)
	cout << num[i];
    }
    cout << endl;
  }
};

int main()
{
  string s;
  while (cin >> s) {
    bool found = false;
    for (int i = 0; i <= 9; ++i) {
      int idx = 0, digit = 1;
      bool valid = true;
      const BigInteger ZERO;
      vector<BigInteger> num(3);
      for (unsigned int j = 0; j < s.size(); ++j) {
	if (s[j] == '+' || s[j] == '=') {
	  ++idx;
	  digit = 1;
	  continue;
	}
	num[idx] *= 10;
	if (s[j] == 'X') {
	  if (digit != 1 && i == 0 && num[idx] == ZERO) {
	    valid = false;
	    break;
	  }
	  num[idx] += i;
	} else {
	  num[idx] += (int)(s[j] - '0');
	}
	++digit;
      }
      if (valid && num[0] + num[1] == num[2]) {
	found = true;
	cout << i << endl;
	break;
      }
    }
    if (!found)
      cout << "NA" << endl;
  }
  return 0;
}

Measured memory_bytes: 940
using System;
using System.Linq;
using System.Diagnostics;
using System.Collections.Generic;
using static System.Math;

class P
{
    static void Main()
    {
        long[] abc = Console.ReadLine().Split().Select(long.Parse).ToArray();
        int k = int.Parse(Console.ReadLine()); ;
        long max = abc.Max();
        long pow = max;
        for (int i = 0; i < k; i++)
        {
            pow *= 2;
        }
        Console.WriteLine(abc.Sum() - max + pow);
    }
    
}

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

int main() {
  string s;
  cin >> s;
  
  if(s.at(0) == s.at(1) || s.at(1) == s.at(2) || s.at(2) == s.at(3))
    cout << "Bad" << endl;
  else
    cout << "Good" << endl;
}

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

typedef long long ll;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef vector<vector<vector<ll>>> vvvll;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<vector<vector<bool>>> vvvb;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef vector<vpll> vvpll;
typedef vector<double> vd;
typedef vector<vd> vdd;

#define FOR(i,x,y) for(ll i=(ll)x; i<(ll)y; ++i)
#define REP(i,y) FOR(i, 0, y)
#define RFOR(i,x,y) for(ll i=(ll)x; i>=(ll)y; --i)
#define RREP(i,x) RFOR(i, x, 0)
#define ALL(a) a.begin(), a.end()
#define pb push_back
#define debug_print(x...) cerr << "line " << __LINE__ << " : "; debug_print_in(x);

template <typename First>
void debug_print_in(First first){
  cerr << first << endl;
  return;
}

template <typename First, typename... Rest>
void debug_print_in(First first, Rest... rest){
  cerr << first << " ";
  debug_print_in(rest...);
  return;
}

void IN(void){
  return;
}

template <typename First, typename... Rest>
void IN(First& first, Rest&... rest){
  cin >> first;
  IN(rest...);
  return;
}

template <typename First>
void OUT(First first){
  cout << first << endl;
  return;
}

template <typename First, typename... Rest>
void OUT(First first, Rest... rest){
  cout << first << " ";
  OUT(rest...);
  return;
}

template<class t, class u> void chmax(t&a,u b){if(a<b)a=b;};
template<class t, class u> void chmin(t&a,u b){if(a>b)a=b;};
int popcount(int t){return __builtin_popcount(t);} //GCC
int popcount(ll t){return __builtin_popcountll(t);} //GCC

template <typename T>
void vec_print(vector<T> VEC){
  REP(i, VEC.size()){
    cerr << VEC[i] << " ";
  }
  cerr << endl;
};

template <typename T>
void mat_print(vector<vector<T> > MAT){
  REP(i,MAT.size()){
    REP(j,MAT[i].size()){
      cerr << MAT[i][j] << " ";
    }
    cerr << endl;
  }
};

constexpr int INF = (1<<30);
constexpr ll INFLL = 1LL<<62;
constexpr long double EPS = 1e-12;
constexpr ll MOD = (ll)((1E+9)+7);

int main(){
  cin.tie(0); // cut the cin and cout (default, std::flush is performed after std::cin)
  ios::sync_with_stdio(false); // cut the iostream and stdio (DON'T endl; BUT "\n";)

  ll N, R;
  IN(N,R);
  if(N>=10){
    OUT(R);
  }else{
    R += 100*(10-N);
    OUT(R);
  }

  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String S = sc.next();
		sc.close();
		String a = "Sunny";
		String b = "Cloudy";
		String c = "Rainy";
		if(S.equals(a)) {
			System.out.println(b);
		}else if(S.equals(b)) {
			System.out.println(c);
		}else {
			System.out.println(a);
		}
	}

}

Measured memory_bytes: 21588
use proconio::input;
#[allow(unused_imports)]
use proconio::marker::*;
use rand::prelude::*;
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
#[allow(unused_imports)]
use std::f64::consts::*;
use std::time::*;

#[allow(unused)]
const INF: usize = std::usize::MAX / 4;
#[allow(unused)]
const M: usize = 1000000007;

fn ss(n: usize) -> isize {
    (n * (n + 1) / 2) as isize
}

fn calc_score(t: &Vec<usize>, c: &Vec<isize>, s: &Vec<Vec<isize>>) -> isize {
    let n = c.len();
    let d = t.len();
    let mut last = vec![0; n];
    let mut score = 0;
    for i in 0..d {
        let ti = t[i];
        score += s[i][ti];
        last[ti] = i + 1;
        for j in 0..n {
            score -= c[j] * (i + 1 - last[j]) as isize;
        }
    }
    score
}

fn initial_guess(c: &Vec<isize>, s: &Vec<Vec<isize>>) -> Vec<usize> {
    let n = c.len();
    let d = s.len();
    let mut t = vec![0; d];
    let mut last = vec![0; n];
    for i in 0..d {
        t[i] = (0..n)
            .max_by_key(|&j| {
                s[i][j]
                    - (0..n)
                        .map(|k| c[k] * (i + 1 - last[k]) as isize)
                        .sum::<isize>()
            })
            .unwrap();
        last[t[i]] = i + 1;
    }
    t
}

fn improve(
    t: &mut Vec<usize>,
    score: isize,
    c: &Vec<isize>,
    s: &Vec<Vec<isize>>,
    di: usize,
) -> isize {
    let n = c.len();
    let d = s.len();

    let mut last = vec![0; n];
    for i in 0..di {
        last[t[i]] = i + 1;
    }
    let mut next = vec![d + 1; n];
    for i in (di + 1..d).rev() {
        next[t[i]] = i + 1;
    }

    let f =
        |j| s[di][j] - c[j] * (ss(di - last[j]) + ss(next[j] - di - 2) - ss(next[j] - last[j] - 1));
    let remove_score = f(t[di]);

    t[di] = (0..n).max_by_key(|&j| f(j)).unwrap();
    score + f(t[di]) - remove_score
}

fn main() {
    let start = SystemTime::now();
    let limit = Duration::from_millis(1950);
    let n = 26;
    input! {
        d: usize,
        c: [isize; n],
        s: [[isize; n]; d],
    }
    let mut t = initial_guess(&c, &s);
    let mut rng = thread_rng();
    let mut score = calc_score(&t, &c, &s);
    let mut best_score = score;
    let mut best_t = t.clone();
    eprintln!("{}", score);
    let mut iter = 0;
    loop {
        let prev_score = score;
        for di in 0..d {
            score = improve(&mut t, score, &c, &s, di);
        }
        if prev_score == score {
            if score > best_score {
                eprintln!("{}", score);
                best_score = score;
                best_t = t.clone()
            } else {
                t = best_t.clone();
            }
            let d1 = rng.gen_range(0, d);
            let d2 = rng.gen_range(0, d);
            t.swap(d1, d2);
            score = calc_score(&t, &c, &s);
        }
        iter += 1;
        if start.elapsed().unwrap() >= limit {
            break;
        }
    }
    eprintln!("{}", iter);
    eprintln!("{}", best_score);
    for &ti in &best_t {
        println!("{}", ti + 1);
    }
}


Measured memory_bytes: 2768
#include<iostream>
#include<iomanip>
#include<math.h>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<string>
#include<complex>

#define INF (long long)1000000000
#define MOD 1000000007
#define EPS 1e-8

#define REP(i, m) for(long long i = 0; i < m; ++i)
#define FOR(i, n, m) for(long long i = n; i < m; ++i)
#define ALL(v) v.begin(), v.end()
#define pb push_back

using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef long double ld;

int main() {
	int n;
	cin>>n;
	string s = to_string(n);
	if(s[0]==s[2]) cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
}


Measured memory_bytes: 764
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <utility>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define _GLIBCXX_DEBUG
using namespace std;
typedef long long ll;
typedef pair<int, int> pair;
const int inf = 1000000000; //10^9

int main(){
    int a, b;
    cin >> a >> b;
    int ans = 0;

    for (int i = a; i <= b; i++) {
        int c, d, e, f;
        c = i / 10000; 
        d = i / 1000 % 10;
        e = i / 10 % 10;
        f = i % 10;
        if (c == f&&d == e) ans++; 
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3616
//--------------------------------------------------
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,abm,mmx,avx,avx2,popcnt,fma")
//#pragma GCC optimize("fast-math")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC optimize("Ofast")
//--------------------------------------------------
#include <bits/stdc++.h>
//#include <chrono>
//#include <set>
//#include <map>
//#include <deque>
//#include <cmath>
//#include <queue>
//#include <cassert>
//#include <random>
//#include <bitset>
//#include <iomanip>
//#include <numeric>
//#include <time.h>
//#include <ctime>
//#include <string>
//#include <cstdio>
//#include <vector>
//#include <cstdlib>
//#include <iostream>
//#include <algorithm>
//#include <unordered_map>
//#include <unordered_set>
//#include <fstream>
//#include <stack>
//#include <cstring>
//--------------------------------------------------
#define forn(i, n) for(int i = 0; i < n; i++)
#define forw(i, n) for(int i = n-1; i >= 0; --i)
#define forns(i, n, s) for(int i = s; i < n; i++)
#define x first
#define y second
#define pb push_back
#define mp make_pair
#define all(v) v.begin(),v.end()
#define allr(v) v.rbegin(),v.rend()
//----------------------------------------------------
using namespace std;
//----------------------------------------------------
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int uint;
typedef long double ld;
typedef vector<ll> lnum;
typedef complex<ld> comp;
//----------------------------------------------------
const ll mod = 1e9 + 7, mod2 = 998244353;
const ld eps = 1e-6;
const ll inf = 1e18;
const int base = 1e9;
const ld PI = 3.14159265358979;
//----------------------------------------------------
#define endl '\n';
//----------------------------------------------------
int n;
vector<int> a, b;
//----------------------------------------------------
unsigned int bitcount(ull val) { return __builtin_popcount(val) + __builtin_popcount(val >> 32); }

void local() {
    freopen("test.in", "r", stdin);
}

void remote() {
}

void read() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    cin >> n;
    a.resize(n), b.resize(n);
    forn(i, n) cin >> a[i] >> b[i];
}

int main() {
#ifdef MY_DEBUG
    local();
#else
    remote();
#endif
    read();

    sort(all(a));
    sort(all(b));
    if(n % 2 == 0){
        ld beg = ld(a[n/2]+a[n/2-1])/2.0, end = ld(b[n/2] + b[n/2-1])/2.0;
        cout << ll((end - beg) * 2) + 1 << endl;
    }else{
        cout << b[n/2] - a[n/2] + 1 << endl;
    }

}


Measured memory_bytes: 4764
import numpy as np
import numba
from numba import njit, b1, i4, i8, f8

@njit((i8, i8, i8, i8[:,:]), cache=True)
def solve(R,C,K,item):
  dp = np.zeros((C+1,5), dtype=np.int64)
  for i in range(1,R+1):
    new_dp = np.zeros((C+1,5), dtype=np.int64)
    #上からアイテムを取らずに移動
    new_dp[:,0] = dp[:,-1]
    #上からアイテムを取って移動
    new_dp[1:,1] = np.maximum(new_dp[1:,1],dp[1:,-1]+item[i-1])
    for j in range(1,C+1):
      #横からアイテムを取らずに移動
      new_dp[j] = np.maximum(new_dp[j],new_dp[j-1])
      #横からアイテムを取って移動
      for k in range(1,4):
        new_dp[j,k] = max(new_dp[j,k],new_dp[j-1,k-1]+item[i-1,j-1])
    for k in range(4):
      new_dp[:,-1] = np.maximum(new_dp[:,-1],new_dp[:,k])
    dp = new_dp
  ans = dp[-1,-1]
  return ans

R, C, K = map(int, input().split())
item = np.zeros((R,C), dtype=np.int64)
for i in range(K):
  r,c,v = map(int, input().split())
  item[r-1,c-1] = v
print(solve(R,C,K,item))

Measured memory_bytes: 177436