akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/range/adaptor/reversed.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
typedef boost::multiprecision::cpp_int cppint;
#define PI (acos(-1))
#define REP(i,n) for(cppint (i)=0;(i)<(n);(i)++)

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define dumparr(x) cerr << #x ; for(auto elem: x){cerr << " " << elem;} cerr << endl;
#define dumppairs(x) cerr << #x ; for(auto elem: x){cerr << "(" << elem.first << " " << elem.second << ") ";} cerr << endl;
#define dumpline cerr << "**********************" << endl;
#define dumpwline(x) cerr << "******** " << #x << "=" << (x) << " ********" << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))

cppint koubai(cppint a, cppint b){
    cppint c = min(a, b);
    cppint d = max(a, b);
    while(c*d > 0){
        cppint z1 = max(c, d);
        cppint z2 = min(c, d);
        c = z1%z2;
        d = z2;
    }
    return d;
}

pair <cppint, cppint> normalize(cppint a, cppint b){
    cppint fugo = 1;
    if (a*b < 0){
        fugo = -1;
    }
    if (a*b == 0){
        fugo = 1;
    }
    cppint kbi = koubai(abs(a), abs(b));
    kbi = max(cppint(1), kbi);
    return {abs(a)/kbi * fugo, abs(b)/kbi};
}

cppint d = 1000000007;
int main(void){
    cppint n; cin >> n;
    map <pair<cppint, cppint>, cppint> mp;
    cppint ex = 0;
    REP(i, n){
        cppint a; cppint b; cin >> a >> b;
        auto normalized = normalize(a, b);
        if ((normalized.first == 0) && (normalized.second == 0)){
            ex += 1;
            continue;
        }
        mp[normalized]++;
    }
    n -= ex;
    map<pair<cppint, cppint>, cppint> chofuku;
    for(auto item: mp){
        pair <cppint, cppint> p = item.first;
        cppint num = item.second;
        if (num == 0){
            continue;
        }
        cppint fugo = -1;
        if (p.first >= cppint(0)){
            fugo = 1;
        }
        if (p.first*p.second == 0){
            fugo = -1;
        }
        pair <cppint, cppint> pp;
        pp.first = abs(p.second)*fugo*-1;
        pp.second = abs(p.first);
        cppint num2 = mp[pp];
        if (num2 == 0){
            continue;
        }

        chofuku[{max(num, num2), min(num ,num2)}]++;
    }
    cppint bai = 1;
    for(auto item: chofuku){
        pair<cppint, cppint> p = item.first;
        cppint num = item.second / 2;
        n -= num*(p.first + p.second);
        cppint bai1 = 1;
        REP(_, p.first){
            bai1 *= 2;
            bai1 %= d;
        }
        cppint bai2 = 1;
        REP(_, p.second){
            bai2 *= 2;
            bai2 %= d;
        }
        REP(_, num){
            bai *= (bai1+bai2-1)%d;
            bai %= d;
        }
    }
    REP(i, n){
        bai *= 2;
        bai %= d;
    }
    cout << (bai-1+ex+d)%d << endl;
    return 0;
}

Measured memory_bytes: 59796
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
using namespace std;

const int N=100005;

int n,m,cnt,last[N],dep[N],a[N],fa[N],ans,bz[N][20],bin[20],c[N],tim,dfn[N],mx[N];
struct edge{int to,next;}e[N];

int read()
{
	int x=0,f=1;char ch=getchar();
	while (ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while (ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}

void addedge(int u,int v)
{
	e[++cnt].to=v;e[cnt].next=last[u];last[u]=cnt;
}

void dfs(int x)
{
	dep[x]=dep[fa[x]]+1;dfn[x]=++tim;
	bz[x][0]=fa[x];
	for (int i=1;i<=16;i++) bz[x][i]=bz[bz[x][i-1]][i-1];
	for (int i=last[x];i;i=e[i].next)
		dfs(e[i].to);
	mx[x]=tim;
}

bool cmp(int x,int y)
{
	return dep[x]>dep[y];
}

int get(int x)
{
	for (int i=16;i>=0;i--)
		if ((m-1)&bin[i]) x=bz[x][i];
	return x;
}

void ins(int x,int y)
{
	while (x<=n) c[x]+=y,x+=x&(-x);
}

int find(int x)
{
	int ans=0;
	while (x) ans+=c[x],x-=x&(-x);
	return ans;
}

int main()
{
	bin[0]=1;
	for (int i=1;i<=16;i++) bin[i]=bin[i-1]*2;
	n=read();m=read();
	for (int i=1;i<=n;i++)
	{
		int x=read();
		if (i==1) ans+=x!=1;
		else addedge(x,i),fa[i]=x;
	}
	dfs(1);
	for (int i=1;i<=n;i++) a[i]=i;
	sort(a+1,a+n+1,cmp);
	for (int i=1;i<=n;i++)
	{
		int x=a[i];
		if (dep[x]<=m+1||find(dfn[x])) continue;
		int y=get(x);
		ins(dfn[y],1);ins(mx[y]+1,-1);
		ans++;
	}
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 14720
class NormalInput{
  input: string[];
  pointer: number;
  constructor(raw:string){
    this.input=raw.split(/ |\n/);
    this.pointer=0;
  }
  int = ():number=>{
    const ret= parseInt(this.input[this.pointer], 10);
    this.pointer++;
    return ret;
  }
  str=():string=>{
    const ret= this.input[this.pointer];
    this.pointer++;
    return ret;
  }
  strs=(length:number):string[]=>{
    let ret:string[]=[];
    for(let i=0;i<length;i++){
      ret.push(this.str());
    }
    return ret;
  }
  ints=(length:number):number[]=>{
    let ret:number[]=[];
    for(let i=0;i<length;i++){
      ret.push(this.int());
    }
    return ret;
  }
}
function Main({int,str,strs,ints}:NormalInput) {
  const N=int();
  const A = ints(N);
  const ans = A.every((a)=>{if(a%2!==0)return true;return a%3===0 || a%5===0})
  console.log(ans?"APPROVED":"DENIED")
}

//DO NOT EDIT
Main(new NormalInput(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 11468
#include <iostream>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <cmath>
#include <string>
#include <sstream>
#include <iomanip>
#include <complex>
using namespace std;
 
#define ll long long
#define vvi vector< vector<int> >
#define vi vector<int>
#define All(X) X.begin(),X.end()
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define pb push_back
#define pii pair<int,int>
#define mp make_pair
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
 
int main(){
    int x[100],y[100];
    int n;
    cin >> n;
    REP(i,n) cin >> x[i];
    REP(i,n) cin >> y[i];
    long double sum = 0;
    REP(i,n) sum += abs(x[i]-y[i]);
    cout << sum << endl;
    sum = 0;
    REP(i,n) sum += (x[i]-y[i])*(x[i]-y[i]);
    cout << setprecision(20) << fixed << sqrt(sum) << endl;
    sum = 0;
    REP(i,n) sum += abs((x[i]-y[i])*(x[i]-y[i])*(x[i]-y[i]));
    cout << cbrt(sum) << endl;
    long double ans4 = -9999;
    REP(i,n) ans4 = max(ans4,(long double)abs(x[i]-y[i]));
    cout << ans4 << endl;
}

Measured memory_bytes: 1264
#include <bits/stdc++.h>
  
using namespace std;
  
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define repr(i, n) REPR(i, n, 0)
#define REPR(i, s, e) for(int i=(int)(s-1); i>=(int)(e); i--)
#define pb push_back
#define all(r) r.begin(),r.end()
#define rall(r) r.rbegin(),r.rend()
#define fi first
#define se second
  
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
 
const int INF = 1e9;
const ll MOD = 1e9 + 7;
double EPS = 1e-8;

int main(){
    int a, b;
    cin >> a >> b;
    cout << (a-1) * (b-1) << endl;
    return 0;
}

Measured memory_bytes: 256
// #include C {
#include<cstring>
#include<cassert>
#include<cstdio>
#include<cctype>
#include<cmath>
// }

// #include C++ {
#include<functional>
#include<algorithm>
#include<iostream>
#include<vector>
#include<string>
#include<bitset>
#include<queue>
#include<deque>
#include<stack>
#include<list>
#include<map>
#include<set>
// }

using namespace std;
// #typedef {
typedef long long int64;
typedef pair <int, int> PII;
typedef pair <int64, int64> PLL;
// }

// #parameter{
#ifdef DEBUG_MODE

#define TYPE decltype
#define RF(filename) {freopen((filename), "r", stdin);}
#define WF(filename) {freopen((filename), "w", stdout);}
#define DF(filename) {freopen((filename), "w", stderr);}
#define eprintf printf

#else

#define TYPE __typeof
#define RF(filename) {;}
#define WF(filename) {;}
#define DF(filename) {;}
#define eprintf(...)
#define fprintf(...)

#endif

// #define {
#define SZ(a) ((int)(a).size())
#define X first
#define Y second
#define MP make_pair
#define L(x) ((x)<<1)
#define R(x) ((x)<<1 | 1)
#define max3(x, y, z) (max(max((x), (y)), (z)))
#define min3(x, y, z) (min(min((x), (y)), (z)))
#define BIT(x, i) (((x) >> (i)) & 1)
#define ALL(it) (it).begin(), (it).end()
#define FILL(__space, __val) memset(__space, __val, sizeof(__space))
#define MOVE(__spaceTo, __spaceFrom) memmove(__spaceTo, __spaceFrom, sizeof(__spaceTo))
#define UNIQUE(__vector) sort(ALL(__vector)), __vector.resize(unique(ALL(__vector)) - __vector.begin())
#define FOR(it, c) for( TYPE((c).begin()) it = (c).begin(); it != (c).end(); it++)
/////////////////////////////////////////////////////////////
const double PI = acos(-1.0);
const double EPS = 1e-6;

#define MAX_N 505
#define MAX_M 100005
#define MOD (int)(1e9+7)
#define INF ((1 << 30) - 1)
#define BINF ((1LL << 62) - 1LL)
#define NONE -1
#define NIL 0
// }

/////////////////////////////////////////////////////////////
char mapp[MAX_N][MAX_N];
/////////////////////////////////////////////////////////////
int main() {
	RF("input.txt");
//  WF("output.txt");
	DF("err.txt");

	int H, W;
	scanf("%d %d", &H, &W);
	for (int r = 0; r < H; r++) scanf("%s", mapp[r]);
	for (int r = 0; r < H; r++) for (int c = 0; c < W; c++) if (mapp[r][c] == '.') {
		int cnt = 0;
		for (int ofr = -1; ofr <= 1; ofr++) for (int ofc = -1; ofc <= 1; ofc++) {
			int nr = r + ofr;
			int nc = c + ofc;
			if (nr >= 0 && nr < H && nc >= 0 && nc < W && mapp[nr][nc] == '#')
				cnt++;
		}
		mapp[r][c] = cnt + '0';
	}
	for (int r = 0; r < H; r++) puts(mapp[r]);
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>
#include <string>
#include <algorithm>
#include <utility>
#include <cstring>
#include <cassert>

using namespace std;

#define REP(var, count) for(int var=0; var<count; var++)

const char op[] = "()*/+-=N";


string line;
int cur;
char readchar() {
	return line[cur++];
}
char peek() {
	return line[cur];
}


int digit() {
	return readchar() - '0';
}
int number() {
	int n = digit();
	while ( peek() >= '0' && peek()<='9' ) {
		n = n*10 + digit();
	}
	return n;
}

int expression();
int factor() {
	if ( peek() != '(' ) { return number(); }
	assert( readchar() == '(' );
	int ret = expression();
	assert( readchar() == ')' );
	
	return ret;
}

int term() {
	int ret = factor();
	while( peek() == '*' || peek() == '/' ) {
		char op = readchar();
		int fac = factor();
		
		if ( op == '*' ) { ret *= fac; }
		else { ret /= fac; }
	}
	
	return ret;
}

int expression() {
	int ret = term();
	while( peek() == '+' || peek() == '-' ) {
		char op = readchar();
		int ter = term();
		
		if ( op == '+' ) { ret += ter; }
		else { ret -= ter; }
	}
	
	return ret;
}

int main(void) {
	int N;
	cin >> N;
	while(N--) {
		cin >> line;
		cur = 0;
		
		cout << expression() << endl;
	}

}

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

int main(){
	int n;
	int p[] = {6,8,13,15,20,22,27};
	bool prime[300001] = {};
	vector<int> msn,ps,primes;
	int num = 1;
	for(int i = 0;num <= 300000;i++){
		msn.push_back(num);
		if(num != 1) prime[num] = true;
		if(i % 2) num += 2;
		else num += 5;
	}
	for(int i = 0;i < 7;i++){
		for(int j = 1;j < msn.size();j++){
			if(p[i] * msn[j] >= 550) break;
			prime[p[i] * msn[j]] = false;
		}
	}
	for(int i = 0;i < 550;i++) if(prime[i]) ps.push_back(i);
	for(int i = 0;i < ps.size();i++){
		for(int j = 1;j < msn.size();j++){
			if(ps[i] * msn[j] > 300000) break;
			prime[ps[i] * msn[j]] = false;
		}
	}
	for(int i = 0;i <= 300000;i++) if(prime[i]) primes.push_back(i);
	while(1){
		cin >> n;
		if(n == 1) break;
		vector<int> yaku;
		for(int i = 0;i < primes.size();i++) {
			if(n % primes[i] == 0) yaku.push_back(primes[i]);
		}
		printf("%d:",n);
		for(int i = 0;i < yaku.size();i++) printf(" %d",yaku[i]);
		puts("");
	}
	return 0;
}

Measured memory_bytes: 3720
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
using ld = long double;
const ll ATCODER_AMARI = 1000000007; //10^9 + 7
const ll INF = 10000000000000;

//階乗関数　ATCODER_AMARIに注意
ll factorial(ll k){
  ll sum = 1;
  for(int i = 1 ; i < k + 1; i++) {
    sum *= i;
    //sum = sum % ATCODER_AMARI;
  }
  return sum;
}

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

  if(x >= 30) cout << "Yes" << endl;
  else cout << "No" << endl;
}


Measured memory_bytes: 3524
costs = {}
searching = {}

def init(a, b, c, d):
    my_costs = {}
    my_costs[0] = 0
    frontier = set([0])
    for depth in range(8):
        new_frontier = set()
        for f in frontier:
            for ff, cst in [(f*2, a), (f*3, b), (f*5, c), (f-1, d), (f+1, d)]:
                if ff < 0:
                    continue
                if ff not in my_costs:
                    my_costs[ff] = my_costs[f] + cst
                else:
                    my_costs[ff] = min(my_costs[f] + cst, my_costs[ff])
                new_frontier.add(ff)
        frontier = new_frontier
    for k in range(20):
        costs[k] = my_costs[k]

def solve(n, a, b, c, d):
    if n in costs:
        return costs[n]

    next_step = {}
    for delta in range(-5, 5+1):
        m = n + delta
        for div, div_cost in [(2, a), (3, b), (5, c)]:
            if m % div == 0:
                cst = d * abs(delta) + div_cost
                r = m // div
                if r not in next_step:
                    next_step[r] = cst
                else:
                    next_step[r] = min(next_step[r], cst)

    #print(f'next step for {n} is {list(next_step.keys())}')
    costs_lst = []
    for r in next_step:
        cst = solve(r, a, b, c, d) + next_step[r]
        costs_lst.append(cst)
    costs[n] = min(costs_lst + [n*d])
    return costs[n]

t = int(input())

for casenum in range(1, t+1):
    n, a, b, c, d = map(int, input().split())
    costs = {}
    searching = {}

    init(a, b, c, d)
    answer = solve(n, a, b, c, d)
    #print(f'answer for {n, a, b, c, d} = {answer}')
    print(answer)

Measured memory_bytes: 159936
// "include" {{{
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <deque>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <cstring>
#include <iomanip>
#include <tuple>
// }}}

using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
#define reps(i,n) for(int i=1;i<=(n);++i)
#define all(x) (x).begin(),(x).end()
#define pii pair<int,int> 
#define int long long
#define setout(n,x) setw(n) << setfill(x)
#define Fixed fixed << setprecision(10)
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const long long mod = 1e9+7;

int gcd(int a,int b){ return b ? gcd(b,a % b) : a;}
int lcm(int a,int b){ return a / gcd(a,b) * b;}

signed main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int a,b,c,d;
	cin >> a >> b >> c >> d;
	cout << b - (b / c + b / d - b / lcm(c,d)) - ((a-1) - ((a-1) / c + (a-1) / d - (a-1) / lcm(c,d))) << '\n';
	return 0;	
}


Measured memory_bytes: 256
#include <iostream>
#include <limits>
#include <cstdint>
#include <vector>
#include <string>
#include <math.h>
#include <algorithm>
#include <numeric>
#include <map>
#include <unordered_map>
#include <set>
#include <cstring>
#include <deque>
#include <stack>
#include <queue>
#include <utility> 
#include <iomanip>      // std::setprecision
using namespace std;
typedef long long int l1;
typedef long long unsigned int lu1;
typedef long double ld;
#define FIO std::ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
// #define __gcd(a,b) __algo_gcd(a,b)
#define PI acos(-1.0)
#define pb push_back
// #define SORT(A) sort(A.begin(), A.end());
// #define REVERSE(A) reverse(A.begin(), A.end());
#define PrintArray(arr) for(int i=0;i<(int)arr.size();i++)cout<<arr[i]<<" ";cout<<endl;
#define pii pair<int,int>
#define pll pair<long long int , long long int>
#define puu pair<long long unsigned , long long unsigned>
const int MOD = 1e9+7;

// const int N = 2*(2e5+5);
// vector<int> adj[N];
// vector<int> level(N,0);
// vector<bool> vis(N,0);

l1 dp[200000+5][100+5];
l1 foo(vector<int> &wt, vector<int>& price,int W,int wsum, int s)
{
    if(dp[wsum][s]!=-1)
    {
        return dp[wsum][s];
    }
    if(s<(int)wt.size())
    {
        if(wsum+wt[s]<=W)
        {
            return dp[wsum][s] = max(price[s]+foo(wt,price,W,wsum+wt[s],s+1),0+foo(wt,price,W,wsum,s+1));
        }
        else
        {
            return dp[wsum][s] = max(dp[wsum][s],0+foo(wt,price,W,wsum,s+1));
        }
    }
    else
    {
        return 0;
    }
}

int main()
{
    FIO;
    int t;
    t = 1;
    // cin>>t; 
    // freopen("input.txt","r",stdin);
    // freopen("output.txt","w",stdout);
    for(int tc=0;tc<t;tc++)
    {   
        int n,W;
        cin>>n;
        cin>>W;
        vector<int> wt(n), price(n);
        
        // for(int i1=0;i1<n;i1++) cin>>price[i1];
        // for(int i1=0;i1<n;i1++) cin>>wt[i1];
        for(int i1=0;i1<n;i1++)
        {
            cin>>wt[i1]>>price[i1];
        }
        memset(dp,-1,sizeof(dp));
        cout<<foo(wt,price,W,0,0)<<"\n";
        // foo(wt,price,W,0,0);
    }
    return 0;
}

Measured memory_bytes: 164352
N, M = map(int, input().split())
A = sorted(list(map(int, input().split())))
BC = [None] * M
for i in range(M):
    BC[i] = tuple(map(int, input().split()))
BC.sort(key=lambda tpl: tpl[1], reverse=True)  # sort by C descendant

D = [0] * N
i = 0
j = 0
while i < N and j < M:
    b, c = BC[j]
    for k in range(i, min(i + b, N)):
        D[k] = c
    i += b
    j += 1

for i in range(N):
    A[i] = max(A[i], D[i])

print(sum(A))


Measured memory_bytes: 22492
s = input()
n = len(s)
count = 0
count2 = 0
for i in range(n):
    if i % 2 == 0:
        x = "0"
    else:
        x = "1"
    if s[i] == x:
        count2 += 1
        #print(i, s[i], x, "OK")
    else:
        count += 1
        #print(i, s[i], x)
print(min(count,count2))

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

#define debug(x) cout <<"DEBUG"<<" "<< #x << ":" << x << '\n'

//↓0-originか1-originでn回繰り返し
#define rep(i,n) for(int i = 0; i < ((int)(n)); i++)   //0-indexed昇順
#define rep1(i,n) for(int i = 1; i <= ((int)(n)); i++) //1-indexed昇順
#define rrep(i,n) for(int i = ((int)(n)-1); i >= 0; i--)  //0-indexed降順
#define rrep1(i,n) for(int i = ((int)(n)); i >= 1; i--)   //1-indexed降順
#define all(x) (x).begin(),(x).end()

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vi> vii; //2次元配列
typedef vector<ll> vll;
typedef pair<int, int> PII;

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

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

const ld PI = acos(-1.0L);
const ll infll = (1LL<<62)-1;
const int inf = (1<<30)-1;
const int mod = 1000000007;
//const int mod = 998244353;


/*FUNCs=================================================*/


/*MAIN==================================================*/
signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);   //cin cout 高速化
    //cout << fixed << setprecision(10);

    int h,w; cin >> h >> w;
    
    //locate of obstancles, grid
    vec<vec<char>> grid(h, vec<char>(w));
    vii obs_row(h, vi(1, -1));  // 0 -> -1
    vii obs_col(w, vi(1, -1));  // 0 -> -1
    rep(i,h) {
        rep(j,w) {
            char ch; cin >> ch;
            grid[i][j] = ch;
            if(ch!='#') continue;
            obs_row[i].push_back(j);
            obs_col[j].push_back(i);
        }
    }
    rep(i,h) obs_row[i].push_back(w);
    rep(i,w) obs_col[i].push_back(h);

    int maxi = -1, cnt;
    rep(i,h) {
        rep(j,w) {
            if(grid[i][j]=='#') continue;
            auto up1 = lower_bound(all(obs_row[i]), j);
            auto low1 = up1-1;
            cnt = *up1 - *low1 - 1;
            auto up2 = lower_bound(all(obs_col[j]), i);
            auto low2 = up2-1;
            cnt += (*up2 - *low2) - 1;
            --cnt;
            chmax(maxi, cnt);
        }
    }
    cout << maxi << '\n';
    /*for(auto i : obs_col[5]) debug(i);
    auto i = *(lower_bound(all(obs_col[5]), 2));
    auto j = *(--lower_bound(all(obs_col[5]), 2));
    cout << i << '\n';
    cout << j << '\n';*/
}

Measured memory_bytes: 38400
# coding: utf-8
import sys
from heapq import heapify, heappop, heappush

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

# vertexごとに3つの状態数を持つ
N, M = lr()
graph = [[] for _ in range((N+1)*3)]  # 1-indexed
for _ in range(M):
    a, b = lr()
    a *= 3; b *= 3
    for i in range(3):
        j = i+1 if i < 2 else 0
        graph[a+i].append(b+j)

INF = 10 ** 15

def dijkstra(start):
    dist = [INF] * (N+1) * 3
    dist[start] = 0
    que = [(0, start)]
    while que:
        d, prev = heappop(que)
        if dist[prev] < d:
            continue
        for next in graph[prev]:
            d1 = d + 1
            if dist[next] > d1:
                dist[next] = d1
                heappush(que, (d1, next))
    return dist

S, T = lr()
dist = dijkstra(S*3)
answer = dist[T*3]
if answer == INF:
    answer = -1
else:
    answer //= 3
print(answer)


Measured memory_bytes: 61512
package main

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

var scanner = bufio.NewScanner(os.Stdin)

func scanInt() int {
	scanner.Scan()
	a, err := strconv.Atoi(scanner.Text())
	if err != nil {
		fmt.Println(err)
	}
	return a
}

func main() {
	scanner.Split(bufio.ScanWords)

	h := scanInt()

	l := 0
	r := 40

	for r > l+1 {
		c := (l + r) / 2
		if float64(h) >= math.Pow(2, float64(c)) {
			l = c
		} else {
			r = c
		}
	}
	x := l

	ret := make([]int, x+1)
	ret[0] = 1
	for i := 1; i <= x; i++ {
		ret[i] = ret[i-1]*2 + 1
	}
	fmt.Println(ret[x])
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
const int M=1e5+5;
int n;
vector<int>X[M];
set<int>S[M];
int x[M],y[M],f[M];

int find(int x){
	return x==f[x]?x:f[x]=find(f[x]);
}

int main(){
	scanf("%d",&n);
	if(n<=2) return !puts("0");
	for(int i=1; i<=n; i++){
		scanf("%d %d",&x[i],&y[i]);
		X[x[i]].push_back(y[i]);
	}
	for(int i=1; i<=M-5; i++) f[i]=i;
	for(int i=1; i<=M-5; i++){
		if(!X[i].size()) continue;
		int fa=find(X[i][0]);
		for(int j=1,_j=X[i].size(); j<_j; j++){
			int fb=find(X[i][j]);
			f[fb]=fa;
		}
	}
	for(int i=1; i<=M-5; i++){
		if(!X[i].size()) continue;
		int fa=find(X[i][0]);
		for(int j=0,_j=X[i].size(); j<_j; j++){
			S[fa].insert(X[i][j]);
		}
	}
	long long ans=0;
	for(int i=1; i<=M-5; i++){
		if(!X[i].size()) continue;
		long long fa=find(X[i][0]);
		ans+=1ll*S[fa].size();
	}
	printf("%lld\n",ans-n);
	return 0;
}

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

if K == 1:
    print(1)
    exit()

if N < K:
    P = 0
    for i in range(1, N + 1):
        temp = 1
        while i * (2 ** temp) < K:
            temp += 1
        P += (1 / N) * (1 / 2) ** temp
else:
    P = (N - (K - 1)) / N
    for i in range(1, K):
        temp = 1
        while i * (2 ** temp) < K:
            temp += 1
        P += (1 / N) * (1 / 2) ** temp
print(P)


Measured memory_bytes: 3064
#include<stdio.h>

int main(){
	double a,b,c,d,e,f,x,y,x2,y2;
	double aa=1000,bb=1000;
	int status;
	while(1){
		status=scanf("%lf%lf%lf%lf%lf%lf",&a,&b,&c,&d,&e,&f);
		if (status==EOF){
			break;
		}
		x=(f/e-c/b)/(d/e-a/b);
		y=c/b-a*x/b;
		x2=(b*f-c*e)/(b*d-a*e);
		y2=(c-a*x2)/b;
		
		if (b==0){
			y2=(f-d*x2)/b;
		}
		
		
		
		if (x2<0.0005 && x2>-0.0005){
			x2=0;
		}
		if (y2<0.0005 && y2>-0.0005){
			y2=0;
		}
	//	printf("%.3f %.3f\n",x,y);
	//	printf("%f %f\n",x,y);
		printf("%.3f %.3f\n",x2,y2);
	//	printf("%f %f\n\n\n",x2,y2);
	}
	
	return 0;
}

Measured memory_bytes: 0
A,B,C,X,Y = (int(i) for i in input().split())

if X>=Y:
    bigger = A
else:
    bigger = B


common = max(X,Y) - abs(X-Y)
if (A+B)/2 < C:
    total = A*common + B*common
else:
    total = C*common*2

difference = abs(X-Y)
if bigger < C*2:
    total = total + bigger*difference
else:
    total = total + difference*C*2


print(total)

Measured memory_bytes: 3064
#!/usr/bin/env python3
import sys


def solve(N: int, S: "List[str]"):
    cnt = 0
    
    cnt_ba = 0
    cnt__a = 0
    cnt_b_ = 0

    for s in S:
        cnt += s.count("AB")
        if s[0] == "B" and s[-1] == "A":
            cnt_ba += 1
        elif s[0] == "B":
            cnt_b_ += 1
        elif s[-1] == "A":
            cnt__a += 1

    if cnt_ba > 0:
        cnt += cnt_ba - 1
        if cnt__a > 0:
            cnt += 1
            cnt__a -= 1

        if cnt_b_ > 0:
            cnt += 1
            cnt_b_ -= 1

    cnt += min(cnt__a,cnt_b_)


    print(cnt)



    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    s = [ next(tokens) for _ in range(N) ]  # type: "List[str]"
    solve(N, s)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3700
#include <bits/stdc++.h>
using namespace std;
void __print(int x) {cout << x;}
void __print(long x) {cout << x;}
void __print(long long x) {cout << x;}
void __print(unsigned x) {cout << x;}
void __print(unsigned long x) {cout << x;}
void __print(unsigned long long x) {cout << x;}
void __print(float x) {cout << x;}
void __print(double x) {cout << x;}
void __print(long double x) {cout << x;}
void __print(char x) {cout << '\'' << x << '\'';}
void __print(const char *x) {cout << '\"' << x << '\"';}
void __print(const string &x) {cout << '\"' << x << '\"';}
void __print(bool x) {cout << (x ? "true" : "false");}
template<typename T, typename V>
void __print(const pair<T, V> &x) {cout << '{'; __print(x.first); cout << ','; __print(x.second); cout << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cout << '{'; for (auto &i: x) cout << (f++ ? "," : ""), __print(i); cout << "}";}
void _print() {cout << "\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cout << ", "; _print(v...);}
#define debug(x...) cout << #x << " = "; _print(x)
typedef long long ll; typedef vector<int> vi; typedef vector<ll> vll;
#define rep(i,a,b) for (ll i = (a); i < (b); ++i)
#define per(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define all(x) begin(x), end(x)
#define mp make_pair 
#define pb push_back
#define ff first
#define ss second
#define fast ios_base::sync_with_stdio(NULL);cin.tie(NULL);cout.tie(NULL) 

int solve(){
	int a, b, c, k, ans = 0;
	cin>> a>> b>> c>> k;
	while(k){
		if(a){
			if(a >= k){
				ans += k;
				break;
			}
			else{
				ans += a;
				k -= a, a = 0;
			}
			continue;
		}
		else if(b){
			if(b >= k)
				break;
			else{
				k -= b;
				b = 0;
			}
			continue;
		}
		else{
			ans -= k;
			break;
		}
	}
	cout<< ans;
	return 0;
}
 
int main()
{
	fast;
	int t = 1;
	//cin>> t;
	while(t--){  
		solve();
	}
	return 0;
}
//v.clear(), vis.clear(); vis.resize(n + 1, 0), v.resize(n + 1);
 
/*	inv[1] = 1; // inv is ll
	for(int i=2; i<=mxn; ++i)
		inv[i]=mod-mod/i*inv[mod%i]%mod;*/


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

int main(){
    int n, y;
    cin >> n >> y;
    int A[] = {-1, -1, -1};

    for(int i=0;i<=n;i++){
        for(int j=0;j<=n-i;j++){
            if(0 <= n-i-j && (10000*i + 5000*j + 1000*(n-i-j) == y)){
                A[0] = i;
                A[1] = j;
                A[2] = n-i-j;
                break;
            }
        }
    }

    for(int i=0;i<3;i++){
        cout << A[i] << " ";
    }
    cout << endl;
    return 0;
}

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

using namespace std;

#define int long long

const int DIM = 1e6 + 7;

vector <int> comun;

main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	int a, b;
	cin >> a >> b;
	
	int n = __gcd(a, b);
	
	if(n % 2 == 0)
	{
		comun.push_back(2);
		
		while(n % 2 == 0)
			n /= 2;
	}
	
	for(int i = 3; i * i <= n; i += 2)
		if(n % i == 0)
		{
			comun.push_back(i);
			
			while(n % i == 0)
				n /= i;
		}
	
	if(n != 1)
		comun.push_back(n);
	
	comun.push_back(1);
	
	cout << comun.size();
	
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long int
#define vi vector<ll>
#define vvi vector<vector<ll>>
#define pii pair<ll, ll>
#define pb push_back
#define rep0(i, n) for(ll i = 0;i<n;i++)
#define rep1(i, n) for(ll i = 1;i<n;i++)
#define all(v) v.begin(),v.end()
#define fast                          \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL);
using namespace std;
const int N = 1e5 + 5;
void solve(){
    int n;
    cin >> n;
    vector<ll> arr(n);
    for(int i=0; i<n; i++){
        cin >> arr[i];
    }
    ll sum = 0;
    for(int i=1; i<n; i++){
        if(arr[i]-arr[i-1]<0){
            sum += abs(arr[i]-arr[i-1]);
            arr[i] = arr[i-1];
        }
    }
    cout << sum;
}

int main()
{
    fast;
    solve();
    // int t;
    // cin >> t;
    // while(t--){
    //     solve();
    // }
    return 0;
}


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

int main(){
	int a,b,k; cin>>a>>b>>k;
	vector<int> v;
	int mx=max(a,b);
	for(int i=1; i<=mx; i++){
		if(a%i==0&&b%i==0) v.push_back(i);
	}
	sort(rall(v));
	cout<<v[k-1]<<endl;
}

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

using namespace std;

const long long int MOD = 2019;

int main(){
	#ifdef EVAL
		freopen("input.txt","r",stdin);
		//freopen("output.txt","w",stdout);
	#endif
	long long int A, B;
	cin >> A >> B;
	long long int ans = INT_MAX;
	for(long long int i = A; i <= min(A + MOD,B); i++){
		for(long long int j = B; j >= max(A,B - MOD); j--){
          	if(i == j)continue;
			ans = min(ans,(i % MOD * j % MOD) % MOD);
		}
	}
	cout << ans;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<algorithm>
#define MN 310000
#define ld long double
#define ll long long
#define eps 1e-14
using namespace std;

int read_p,read_ca;
inline int read(){
    read_p=0;read_ca=getchar();
    while(read_ca<'0'||read_ca>'9') read_ca=getchar();
    while(read_ca>='0'&&read_ca<='9') read_p=read_p*10+read_ca-48,read_ca=getchar();
    return read_p;
}
int n,m,x[MN];
long long MMH=0;
int main(){
	register int i;
	n=read();
	for (i=1;i<=3*n;i++) x[i]=read();
	sort(x+1,x+1+3*n);
	for (i=1;i<=n;i++) MMH+=x[3*n-2*i+1];
	printf("%lld\n",MMH);
	return 0;
}

Measured memory_bytes: 1280
import numpy as np
n=int(input())
ans=1
a=input().split()
#print(a)
if '0' in a:
    ans=0
    print(ans)
if ans!=0:
    for i in a:
        ans=ans*int(i)
        if ans>10**18:
            ans=-1
            break
    print(ans)

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

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

using Graph = vector<vector<int>>;

ll calc(ll a, ll b, ll p){//aのb乗をpで割った余り
  if(b == 0) return 1;

  else if(b%2 == 0){
    ll d = calc(a,b/2,p);
    return (d*d)%p;
  }
  else if(b%2 == 1){
    return (a * calc(a,b-1,p))%p;
  }
}

typedef pair<int,int> P;

bool is_prime(int n){//nが素数であるかどうか判定 iで割り切れると素数でない
    if(n == 1) return false;//1は例外
    for(int i = 2;i*i <= n;i++){
        if(n%i == 0) return false;
    }
    
    return true;
}

int main(){
  int N;
  cin >> N;
  string S;
  cin >> S;
  if(N%2) cout << "No" << endl;
  else{
    string T = S.substr(0,N/2);
    string T2 = T;
    string T3 = T + T2;
    //cout << T << endl;
    if(S == T3) cout << "Yes" <<endl;
    else cout << "No" << endl;
  }
 }

Measured memory_bytes: 256
#include <vector>
#include <array>
#include <algorithm>
#include <iostream>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <map>
#include <math.h>
#include <assert.h>
#include <queue>
#include <deque>
#include <iomanip>
#include <numeric>
#include <fstream>

using namespace std;

typedef long long ll;
typedef long double ld;

#define fi first
#define se second

#define mp make_pair
#define pb push_back
#define sz(x) ((int)(x).size())

typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<ld> vld;
typedef vector<vector<int>> vvi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<vector<ld>> vvd;
typedef vector<string> vs;
typedef vector<bool> vb;

typedef pair <int, int> pii;
typedef pair <ll, ll> pll;


int main() {
    cout << setprecision(30);
    ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);

    ll n;
    cin >> n;
    vs ss(n);
    for (int i = 0; i < n; ++i) {
        cin >> ss[i];
        sort(ss[i].begin(), ss[i].end());
    }
    sort(ss.begin(), ss.end());

    ll ans = 0;

    for (ll i = 0; i < n; ++i) {
        ll j = i;
        while (j < n && ss[i] == ss[j]) ++j;
        ans += (j - i) * (j - i - 1) / 2;
        i = j - 1;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 5760
/*
  Author: @yash_31
*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp> 
#include <functional>
#define ll long long int
#define eb emplace_back
#define fatafat ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define MOD 1000000007
#define ft first
#define sd second
#define mkpr make_pair
#define deb(x) std::cout<<#x<<":"<<x<<endl;
#define whole(x) (x).begin(),(x).end()
#define revwhole(x) (x).rbegin(),(x).rend()
#define endl "\n"
#define fbo find_by_order
#define ook order_of_key
#define init0(x) memset(x,0,sizeof(x));

using namespace std; 
using namespace __gnu_pbds;
typedef tree<ll, null_type, less_equal<ll>, rb_tree_tag,tree_order_statistics_node_update> gharKaSet;
 
const int maxlimit=2e5+2;
const ll inf=1e18;
//TTBDC

int main()
{
  fatafat
  int n;cin>>n;
  double p[n+1];
  for(int i=1;i<=n;i++)cin>>p[i];
  double dp[n+1][n+1];
  memset(dp,0,sizeof(dp));
  for(int i=0;i<=n;i++)dp[0][i]=0;
  dp[0][0]=1;
  for(int i=1;i<=n;i++)dp[i][0]=dp[i-1][0]*(1-p[i]);
  for(int i=1;i<=n;i++){
    for(int j=1;j<=n;j++){
      if(i<j)dp[i][j]=0;
      else {
        dp[i][j] = (1-p[i])*dp[i-1][j] + p[i]*dp[i-1][j-1];
      }
    }
  }
  // for(int i=0;i<=n;i++){
  //   for(int j=0;j<=n;j++){
  //     cout<<dp[i][j]<<" ";
  //   }
  //   cout<<endl;
  // }
  double ans=0;
  int nheads=n;
  while(n-nheads<nheads){
    ans+=dp[n][nheads];
    nheads--;
  }
  cout<<setiosflags(ios::fixed | ios::showpoint)<< setprecision(10)<<ans;
  return 0;
}

Measured memory_bytes: 74168
n = int(input())
a = [int(input()) for _ in range(n)]
ans = [0]*n
count = 0
num = a[0]
index = 1
while ans[1] != 1:
    count += 1
    ans[index-1] += 1
    if ans[index-1] >= 2:
        print(-1)
        exit()
    index = num
    num = a[num-1]
print(count-1)

Measured memory_bytes: 13812
#include <bits/stdc++.h>
using namespace std;
int main(){
	//freopen("","r",stdin);
	//freopen("","w",stdout);
	int n;
	cin>>n;
	int a[n+1];
	for(int i=1;i<=n;i++){
		cin>>a[i];
		if(a[i]%2==0){
			if(a[i]%3!=0&&a[i]%5!=0){
				cout<<"DENIED";
				return 0;
			}
		}
	}
	cout<<"APPROVED";
}


Measured memory_bytes: 256
def bubble(a)
    k = 0
    loop do
        new_k = k
        (0..a.size-2).each do |i|
            if a[i] > a[i+1]
                new_k += 1
                a[i], a[i+1] = a[i+1], a[i]
            end
        end
        break if new_k == k
        k = new_k
    end
    k
end

loop do
    n = gets.to_i
    break if n == 0
    a = (1..n).map { gets.to_i }
    p bubble(a)
end

Measured memory_bytes: 8708
#include<iostream>
#include<map>
#include<vector>
#include<algorithm>

using namespace std;

map<int, int> MakePair(int);
int Calculator(int, int, int, int);

int main(){
  int n, m, min, _min;
  map<int, int> data_n, data_m;
  map<int, int>::iterator i, j;

  while(1){
    cin >> n >> m;
    if(n == 0 && m == 0) break;

    data_n = MakePair(n);
    data_m = MakePair(m);

    for(i=data_n.begin(), min=-1; i!=data_n.end(); ++i){
      for(j=data_m.begin(); j!=data_m.end(); ++j){
	_min = Calculator(i->first, i->second, j->first, j->second);
	if(min < 0 || min > _min) min = _min;
      }
    }
    cout << min << endl;
    data_n.clear();
    data_m.clear();
  }
  return 0;
}

map<int, int> MakePair(int n){
  int i, j;
  map<int, int> data;
  if(n == 1){
    data.insert(make_pair(1, 1));
  }else{
    for(i=1, j=n; i<j; ++i){
      if(n % i == 0){
	j = n/i;
	data.insert(make_pair(i, j));
      }
    }
  }
  return data;
}

int Calculator(int a, int b, int c, int d){
  int x, y, z;
  vector<int> data;
  data.push_back(a);
  data.push_back(b);
  data.push_back(c);
  data.push_back(d);
  sort(data.begin(), data.end());
  x = data[1] - data[0];
  y = data[2] - data[1];
  z = data[3] - data[2];
  return x*x + y*y + z*z;
}

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

using ll= long long;
const ll INF=1LL<<60;
const ll MOD=1e9+7;

int main(){
    int N; cin >> N;
    string S; cin >> S;
    int res=0;
    vector<vector<bool>> seen(3, vector<bool>(10, 0));
    for(int i=0; i<S.size()-2; i++){
        if(seen[0][S[i]-'0']) continue;
        for(int j=i+1; j<S.size()-1; j++){
            if(seen[1][S[j]-'0']) continue;
            for(int k=j+1; k<S.size(); k++){
                if(seen[2][S[k]-'0']) continue;
                res++;
                seen[2][S[k]-'0']=true;
            }
            seen[2].assign(10, 0);
            seen[1][S[j]-'0']=true;
        }
        seen[1].assign(10, 0);
        seen[0][S[i]-'0']=true;
    }
    cout << res << endl;
    return 0;
}

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

string s,ss;
int len;

bool check(string s)
{
	int len=s.length();
	
	for (int i=0, j=len-1 ; i<=(len+1)/2 ; i++,j--)
	    if (s[i]!=s[j]) return 0;
	
	return 1;
}

int main()
{
	getline(cin,s);
	
	len=s.length();
	
	ss=s.substr((len+3)/2,len);
	
	//cout<<ss<<endl;
	
	if (check(s) && check(s.substr(0,(len-1)/2)) && check(s.substr((len+3)/2-1,len)))
	{
		printf("Yes");
		
	}
	else
	{
		printf("No");
	}
	
	
	return 0;
}

Measured memory_bytes: 256
s = int(input())
a = []
a.append(s)
#E:f(n)=n/2 O:f(n)=3n+!

i = 0
tmp = 0
while True:
    if a[i]%2==0:
        tmp = a[i]//2
    else:
        tmp = 3*a[i]+1
    i+=1
    if tmp in a:
        print(i+1)
        break
    a.append(tmp)

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

int s[123][123] ;

int main()
{
    #ifdef insomnia
    //freopen("in.txt","r",stdin) ;
    //freopen("out.txt","w",stdout) ;
    #endif // insomnia
    int n , m , k  ;
    while(~scanf("%d %d",&n,&m)){
        scanf("%d",&k) ;
        int tmp ;
        int cnt = 0 ;
        for(int i = 1 ; i <= k ; i ++){
            scanf("%d",&tmp) ;
            for(int j = cnt ; j < cnt + tmp ; j ++){
                s[j/m][j%m] = i ;
            }
            cnt += tmp ;
        }
        for(int i = 0 ; i < n ; i ++){
            if(i%2 == 0){
                for(int j = 0 ; j < m ; j ++)
                    if(j == 0)
                        printf("%d",s[i][j]) ;
                    else
                        printf(" %d",s[i][j]) ;
                printf("\n") ;
            }
            else{
                for(int j = m - 1 ; j >= 0 ; j --)
                    if(j == m - 1)
                        printf("%d",s[i][j]) ;
                    else
                        printf(" %d",s[i][j]) ;
                printf("\n") ;
            }
        }
    }
    return 0 ;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
#define rep(i,n) for(int i=0, i##_len=(int)(n); i<i##_len; i++)
#define reps(i,n) for(int i=1 , i##_len=(int)(n);i<=i##_len;i++)
#define rrep(i,n) for(int i=((int)(n)-1);i>=0;i--)
#define rreps(i,n) for(int i=((int)(n));i>0;i--)
#define repi(i,x) for(auto i=(x).begin(),i##_fin=(x).end();i!=i##_fin;i++)
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define mp make_pair
#define pb push_back
#define solve(a) ((a)?"Yes":"No")
typedef vector<int> Vi;
typedef vector<Vi> VVi;
typedef pair<int , int> Pi;
typedef vector<Pi> VPi;
typedef vector<long long> V;
typedef vector<V> VV;
typedef pair<long long , long long> P;
typedef vector<P> VP;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1;} return 0;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1;} return 0;}
const long long INFLL = 1LL<<60;
const int INF = 1<<30;
const double PI=acos(-1);
int main(){
	string s;
	bool ans=true;
	cin >>s;
	int x,y;
	cin>>x>>y;
	x+=10000;
	y+=10000;
	vector<int>X,Y;
	bool turn =false;
	int cnt=0;
	rep(i,s.size()){
		if(s[i]=='T'){
			if(cnt!=0){
				if(turn){
					Y.push_back(cnt);
				}else{
					X.push_back(cnt);
				}
				cnt=0;
			}
			if(turn){
				turn=false;
			}else{
				turn=true;
			}
		}else
		{
			cnt++;
		}
		
	}
	if (cnt != 0)
	{
		if (turn)
		{
			Y.push_back(cnt);
		}
		else
		{
			X.push_back(cnt);
		}
		cnt = 0;
	}
	if(s[0]=='F' and X.size()!=0){
		x-=X.front();
		X.erase(X.begin());
	}
	//X.push_back(0);
	//Y.push_back(0);
	vector<int>dp(20000,-1);//st:10000
	vector<int> bef(20000, -1); //st:10000
	dp[10000]=1;
	//clog<<"x"<<endl;
	repi(itr,X){
		//clog<<(*itr)<<" ";
		for(int i=0;i<20000;i++){
			if(*itr +i >=20000 or i-*itr  <0 or dp[i]==-1){
				continue;
			}
			chmax(bef[i+*itr],dp[i]+1);
			chmax(bef[i-*itr],dp[i]+1);
		}
		dp=bef;
	}
	if(X.size()!=0){
	ans&=(dp[x]==X.size()+1);}else{
		ans&=(10000==x);
	}
	//clog<<endl<<ans<<endl;
	//clog<<dp[x]<<endl;
	rep(i,20000){
		dp[i]=-1;
		bef[i]=-1;
	}
	dp[10000]=1;
	//clog<<"y"<<endl;
	repi(itr, Y)
	{
	//	clog << (*itr) << " ";
		for (int i = 0; i < 20000; i++)
		{
			if (*itr + i >= 20000 or i - *itr < 0 or dp[i] == -1)
			{
				continue;
			}
			chmax(bef[i + *itr], dp[i] + 1);
			chmax(bef[i - *itr], dp[i] + 1);
		}
		dp = bef;
	}
	//ans &= (dp[y] == Y.size()+1);
	if (Y.size() != 0)
	{
		ans &= (dp[y] == Y.size() + 1);
	}
	else
	{
		ans &= (10000 == y);
	}
	//clog<<endl << ans << endl;
	cout<<solve(ans)<<endl;
}//clog

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

ll gcd(ll a,ll b){
  while(b!=0){
    a%=b;
    swap(a,b);
  }
  return a;
}

int main(){
  int N;
  cin >> N;
  vector<string>s(N);
  vector<int>t(N);
  string X;
  for(int i=0;i<N;i++){
    cin >> s.at(i) >> t.at(i);
  }
  cin >> X;
  int ans=0;
  for(int i=0;i<N;i++){
    ans+=t.at(i);
  }
  for(int i=0;i<N;i++){
    ans-=t.at(i);
    if(s.at(i)==X){
      cout << ans << endl;
      return 0;
    }
  }
}
      
  
  
  

Measured memory_bytes: 256
import sys
import math
from collections import deque
from decimal import Decimal, ROUND_HALF_UP, ROUND_HALF_EVEN
def I(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LI2(N): return [list(map(int, sys.stdin.readline().split())) for i in range(N)]
def S(): return sys.stdin.readline()
def LS(): return sys.stdin.readline().split()
def LS2(N): return [sys.stdin.readline().split() for i in range(N)]
def FILL(i,h,w): return [[i for j in range(w)] for k in range(h)]
def sisha(num,digit): return Decimal(str(num)).quantize(Decimal(digit),rounding=ROUND_HALF_UP)
#'0.01'や'1E1'などで指定、整数に戻すならintをかます
MOD = 1000000007
INF = float("inf")
sys.setrecursionlimit(10**6+10)

input = sys.stdin.readline


N = I()
S = input().rstrip()
R = S.count('R')
G = S.count('G')
B = N-R-G

ans = R*G*B
for i in range(N):
    for j in range(i+1,N):
        if 2*j-i < N and S[i]!=S[j] and S[j]!=S[2*j-i] and S[2*j-i]!=S[i]:
            ans -= 1
print(ans) 


Measured memory_bytes: 89380
#include <bits/stdc++.h>
#ifdef LOCAL_DEBUG
#define DEBUG 1
#define CERR if(DEBUG) cerr
#define MACRO(_1,_2,_3,_4,_5,_6,_7,_8,_9,_10,NAME,...) NAME
#define pr(...) CERR<<MACRO(__VA_ARGS__,pr10,pr9,pr8,pr7,pr6,pr5,pr4,pr3,pr2,pr1)(__VA_ARGS__)<<endl
#define pr1(a) (#a)<<"="<<(a)<<" "
#define pr2(a,b) pr1(a)<<pr1(b)
#define pr3(a,b,c) pr1(a)<<pr2(b,c)
#define pr4(a,b,c,d) pr1(a)<<pr3(b,c,d)
#define pr5(a,b,c,d,e) pr1(a)<<pr4(b,c,d,e)
#define pr6(a,b,c,d,e,f) pr1(a)<<pr5(b,c,d,e,f)
#define pr7(a,b,c,d,e,f,g) pr1(a)<<pr6(b,c,d,e,f,g)
#define pr8(a,b,c,d,e,f,g,h) pr1(a)<<pr7(b,c,d,e,f,g,h)
#define pr9(a,b,c,d,e,f,g,h,i) pr1(a)<<pr8(b,c,d,e,f,g,h,i)
#define pr10(a,b,c,d,e,f,g,h,i,j) pr1(a)<<pr9(b,c,d,e,f,g,h,i,j)
#define prArr(a){CERR<<(#a)<<"={";int i=0;for(auto t:(a))CERR<<(i++?", ":"")<<t;CERR<<"}"<<endl;}
#else
#define DEBUG 0
#define pr(...)
#define prArr(a)
#endif
using namespace std;
using Int = long long;
using _int = int;
using ll = long long;
using Double = long double;
const Int INF = (1LL<<60)+1e9; // ~ 1.15 * 1e18
const Int mod = (1e9)+7;
const Double EPS = 1e-8;
const Double PI = 6.0 * asin((Double)0.5);
using P = pair<Int,Int>;
template<class T> T Max(T &a,T b){return a=max(a,b);}
template<class T> T Min(T &a,T b){return a=min(a,b);}
template<class T1, class T2> ostream& operator<<(ostream& o,pair<T1,T2> p){return o<<"("<<p.first<<","<<p.second<<")";}
template<class T1, class T2, class T3> ostream& operator<<(ostream& o,tuple<T1,T2,T3> t){return o<<"("<<get<0>(t)<<","<<get<1>(t)<<","<<get<2>(t)<<")";}
template<class T1, class T2> istream& operator>>(istream& i,pair<T1,T2> &p){return i>>p.first>>p.second;}
template<class T> ostream& operator<<(ostream& o,vector<T> a){Int i=0;for(T t:a)o<<(i++?" ":"")<<t;return o;}
template<class T> istream& operator>>(istream& i,vector<T> &a){for(T &t:a)i>>t;return i;}
//INSERT ABOVE HERE

Int N;
vector<Int> V;
Int A, B;


Int dfs(Int idx, Int num){
  static Int used[51][51], mem[51][51];
  if(idx == N) return num == 0? 0:-INF;
  if(used[idx][num]++) return mem[idx][num];

  Int a = dfs(idx + 1, num);
  Int b = num? dfs(idx + 1, num - 1) + V[idx]:-INF;
  Int res = max(a, b);
  return mem[idx][num] = res;
}

Int dfs2(Int idx, Int num){
  static Int used[51][51], mem[51][51];
  if(idx == N) return num == 0? 1:0;
  if(used[idx][num]++) return mem[idx][num];

  Int best = dfs(idx, num);
  Int a = dfs(idx + 1, num);
  Int b = num? dfs(idx + 1, num - 1) + V[idx]:-INF;
  Int numA = best == a? dfs2(idx + 1, num):0;
  Int numB = best == b? dfs2(idx + 1, num - 1):0;
  Int res = numA + numB;
  return mem[idx][num] = res;
}

signed main(){
  srand((unsigned)time(NULL));
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  cin>>N>>A>>B;
  V.resize(N);
  cin>>V;

  Double mx = 0;
  for(Int x=A;x<=B;x++){
    Double ave = ((Double)dfs(0, x)) / x;
    Max<Double>(mx, ave);
  }

  Int num = 0;
  for(Int x=A;x<=B;x++){
    Double ave = ((Double)dfs(0, x)) / x;
    Int s = dfs2(0, x);
    if(abs(ave - mx) < 1e-8) num += s;
  }

  cout<<mx<<endl;
  cout<<num<<endl;

  return 0;
}


Measured memory_bytes: 384
#include<iostream>
#include<queue>
#define MAX_N 1000000
typedef long long ll;
ll N, K;
std::priority_queue<ll> que;
int main(){
    std::cin >> N >> K;
    ll atack_cont=0 ;
    for(int i=0; i<N; i++){
       int tmp;
       std::cin >> tmp;
       que.push(tmp);
    }
    while(!que.empty()){
        int p = que.top(); que.pop();
        if(K-- > 0) continue;
        atack_cont+=p;
    }
    std::cout << atack_cont << "\n";
    return 0;
}

Measured memory_bytes: 2420
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();

		String S[] = new String[N];
		ArrayList<String>ans = new ArrayList<String>();

		for (int i=0; i<N; i++){
			S[i] = sc.next();
		}
		Arrays.sort(S);
		int maxCnt=0;
		HashMap<String, Integer>map = new HashMap<String, Integer>();
		for (int i=0; i<N; i++){
			if (map.containsKey(S[i])){
				map.put(S[i], map.get(S[i]) + 1);
			} else {
				map.put(S[i], 1);
			}
			maxCnt = Math.max(maxCnt, map.get(S[i]));
		}
		for (String key : map.keySet()){
			if (map.get(key) == maxCnt){
				ans.add(key);
			}
		}
		Collections.sort(ans);
		for (int i=0; i<ans.size(); i++){
			System.out.println(ans.get(i));
		}
	}
}

Measured memory_bytes: 77660