akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i,n) for(int64_t i=0;i < (int64_t)(n);i++)
using namespace std;

//////全探索したいときに開けよ////////
vector<vector<int>> fspattern;
vector<int> fspattern_draft;
int fspcnt = 0;

void setfspattern_core(int floor,int number,int degree){
  if(floor==degree){
    fspattern.at(fspcnt) = fspattern_draft;
    fspcnt++;
  }else{
    rep(i,number){
      fspattern_draft.at(floor) = i;
      setfspattern_core(floor+1,number,degree);
    }
  }
}

void setfspattern(int number,int degree){
  int64_t array_num = 1;
  rep(i,degree){
    array_num *= number;
  }
  fspattern = vector<vector<int>>(array_num,vector<int>(degree));
  fspattern_draft = vector<int>(degree);
  setfspattern_core(0,number,degree);
}

//////nCrのmodを求めたいときに開けよ/////////
//int64_t univMod = 1000000007;
//int64_t factnum = 100000
//vector<int64_t> modfact(factnum);
//vector<int64_t> modinvfact(factnum);

/*void setmodfact(){
  for(int i=0;i<factnum;i++){
    if(i == 0){
      modfact.at(i) = 1;
    }else{
      modfact.at(i) = (modfact.at(i-1)*i)%univMod;
    }
  }
}

int64_t calcmodpower(int64_t a,int64_t n){
  int64_t res = 1;
  while(n != 0){
    if(n & 1){
      res = (res * a) % univMod;
    }
    a = (a*a) % univMod;
    n = n >> 1;
  }
  return res;
}

int64_t calcinverse(int64_t n){
	return calcmodpower(n,univMod-2);
}

void setmodinvfact(){
  for(int i=0;i<factnum;i++){
    if(i==0){
      modinvfact.at(i) = 1;
    }else{
      modinvfact.at(i) = calcmodpower(modfact.at(i),univMod-2);
    }
  }
}

int64_t calcmodcomb(int64_t n,int64_t r){
  return (((modfact.at(n)*modinvfact.at(r))%univMod)*modinvfact.at(n-r))%univMod;
}

int64_t calcmodpositive(int64_t n){
  return (n + ((abs(n)+univMod-1)/univMod)*univMod)%univMod;
}
  
    */


/*
int64_t calcGCD(int64_t a,int64_t b){
	int64_t p = a;
	int64_t q = b;
	int64_t c = a%b;
	while(c != 0){
		p = q;
		q = c;
		c = p%q;
	}
	return q;
}
*/

int main(){
  string a,s,c;
  cin >> a >> s >> c;
  cout << "A" << s.at(0) << "C" << endl;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <vector>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<ll, int> ll_i;
typedef pair<double, int> d_i;
typedef pair<ll, ll> ll_ll;
typedef pair<double, double> d_d;
struct edge { int u, v; ll w; };

ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-9;

int hoge(vector< vector<int> >& a, int i, int j) {
	return i < a[j].size() ? a[j][i] : 0;
}

int main() {
	for (;;) {
		int n, l; cin >> n >> l;
		if (n == 0) break;
		vector<int> x(n), dx(n);
		for (int i = 0; i < n; i++) {
			char c; cin >> c >> x[i];
			dx[i] = (c == 'L' ? -1 : 1);
		}
		int t;
		for (t = 1; ; t++) {
			vector<int> a(l + 1);
			bool flag = false;
			for (int i = 0; i < n; i++) {
				x[i] += dx[i];
				if (x[i] > 0 && x[i] < l) {
					flag = true;
					a[x[i]]++;
				}
			}
			if (!flag) break;
			for (int i = 0; i < n; i++)
				if (x[i] > 0 && x[i] < l && a[x[i]] >= 2) dx[i] *= -1;
		}
		cout << t << ' ';
		int _i = -1;
		for (int i = 0; i < n; i++)
			if (x[i] == 0) _i = i;
		for (int i = 0; i < n; i++)
			if (x[i] == l && _i == -1) _i = i;
		cout << _i + 1 << endl;
	}
}

Measured memory_bytes: 1200
package main

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

func main() {
    var fp *os.File
    fp = os.Stdin
    reader := bufio.NewReaderSize(fp, 1024)
    line := readLine(reader)
    arr := strings.Split(line, " ")
    N, _ := strconv.Atoi(arr[0])
    K, _ := strconv.Atoi(arr[1])
    var res []float64
    var n, cnt float64
    n = 1 / float64(N)

    for i:= 1; i <= N; i++ {
        cnt = 0
        j := i

        for j < K {
            j = j * 2
            cnt++
        }

        res = append(res, n * math.Pow(0.5, cnt))
    }

    var retval float64

    for _, v := range res {
        retval += v
    }

    fmt.Println(retval)
    //fmt.Printf("%.11f", retval)
    //fmt.Println()
}

func readLine(reader *bufio.Reader) string {
    buf := make([]byte, 0, 1024)

    for {
        l, p, _ := reader.ReadLine()

        buf = append(buf, l...)

        if !p {
            break
        }
    }

    return string(buf)
}

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

//#define int long long
#define DBG 1
#define dump(o) if(DBG){cerr<<#o<<" "<<o<<endl;}
#define dumpc(o) if(DBG){cerr<<#o; for(auto &e:(o))cerr<<" "<<e;cerr<<endl;}
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define each(it,c) for(auto it=(c).begin();it!=(c).end();it++)
#define all(c) c.begin(),c.end()
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9 + 7);

signed main() {
	int n; cin >> n; vector<int>v(n); rep(i, 0, n)cin >> v[i];
	string s; vector<bool>table(1010, false);
	rep(i, 0, n)s += to_string(v[i]); map<string, int>M;
	rep(i, 0, n) {
		for (int j = 1; j <= s.length() - i; j++) {
			M[s.substr(i, j)] = 1;
		}
	}
	string key = "0";
	while (M[key] == 1) {
		key = to_string(stoi(key) + 1);
	}
	cout << key << endl;
	return 0;
}

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

int main() {
    string c;

    cin >> c;

    for(int i=0;i<c.size()-1;i++){
        if(c[i] == 'A' && c[i+1] == 'C'){
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
bool f[10][10000];
int H,W;
void change(int h){
    for(int j=0;j<W;j++){
        f[h][j]=!f[h][j];
    }
}
bool solve(){
    scanf("%d%d",&H,&W);
    if(H==0&&W==0)return false;
    for(int i=0;i<H;i++)
        for(int j=0;j<W;j++)
            scanf("%d",&f[i][j]);

    int ma=0;
    for(int S=0;S<(1<<H);S++){
        for(int i=0;i<H;i++)
            if((S>>i)&1)change(i);

        int sum=0;
        for(int j=0;j<W;j++){
            int cnt=0;
            for(int i=0;i<H;i++){
                if(f[i][j])cnt++;
            }
            sum+=max(cnt,H-cnt);
        }
        ma=max(ma,sum);
        for(int i=0;i<H;i++)
            if((S>>i)&1)change(i);
    }
    printf("%d\n",ma);
    return true;
}
int main(){
    while(solve());
}

Measured memory_bytes: 1284
#include <stdio.h>  
#include <algorithm>  
#include <assert.h>
#include <bitset>
#include <cmath>  
#include <complex>  
#include <deque>  
#include <functional>  
#include <iostream>  
#include <limits.h>  
#include <map>  
#include <math.h>  
#include <queue>  
#include <set>  
#include <stdlib.h>  
#include <string.h>  
#include <string>  
#include <time.h>  
#include <unordered_map>  
#include <unordered_set>  
#include <vector>

using namespace std;

typedef tuple<int, int, int> t3;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair <ll, int> pli;
typedef pair <db, db> pdd;

const db PI = acos(-1);
const db ERR = 1e-12;

const int MX = 100005;

struct UF{
	int t[MX*2];
	int find(int x){
		return t[x] ? t[x] = find(t[x]) : x;
	}
	int merge(int a, int b){
		a = find(a), b = find(b);
		return a == b ? 0 : (t[a] = b, 1);
	}
} uf;

int main()
{
	int A, B, N, M;
	scanf("%d%d", &N, &M);
	for(int i = 1; i <= M; i++){
		scanf("%d%d", &A, &B);
		uf.merge(A*2, B*2+1);
		uf.merge(A*2+1, B*2);
	}
	for(int i = 1; i <= N; i++){
		if( uf.find(i*2) == uf.find(i*2+1) ){
			return !printf("%lld\n", (ll)N*(N-1)/2 - M);
		}
	}
	int a = uf.find(2);
	int x = 0, y = 0;
	for(int i = 1; i <= N; i++){
		if( uf.find(i*2) == a ) x++;
		else y++;
	}
	if( x == 1 || y == 1 ) return !printf("0\n");
	else printf("%lld\n", (ll)x*y - M);
}


Measured memory_bytes: 1024
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
result = 0
before = -1
for i in range(N):
    food = A[i]
    value = B[food - 1]
    result += value
    if food == before + 1:
        result += C[before - 1]
    before = food
print(result)

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <algorithm>
#include <cmath>

using namespace std;

typedef long long ll;

#define forn(i, n) for (int (i) = 0; (i) != (n); (i)++)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define popcount(x) __builtin_popcount(x)
#define popcountll(x) __builtin_popcountll(x)
#define fi first
#define se second

#ifdef LOCAL
#define dbg(x) cerr << __LINE__ << " " << #x << " " << x << endl
#define ln cerr << __LINE__ << endl
#else
#define dbg(x) void(0)
#define ln void(0)
#endif // LOCAL

const int N = 500000;

int n, a[N];
int mx = 0, mn = 0;
vector<pair<int, int> > ops;

signed main()
{
    #ifdef ONLINE_JUDGE
        ios_base::sync_with_stdio(false);
        cin.tie(0);
        cout.tie(0);
    #endif // ONLINE_JUDGE
    cin >> n;
    for (int i = 0; i < n; i++) cin >> a[i];
    for (int i = 0; i < n; i++) mx = max(mx, a[i]);
    for (int i = 0; i < n; i++) mn = min(mn, a[i]);
    if (abs(mx) >= abs(mn))
    {
        int idmx = 0;
        for (int i = 0; i < n; i++) if (a[i] > a[idmx]) idmx = i;
        ops.push_back({idmx + 1, n});
        ops.push_back({idmx + 1, n});
        ops.push_back({n, n});
        for (int i = 0; i < n - 1; i++)
        {
            if (i) ops.push_back({n, i + 1});
            ops.push_back({n, n});
        }
        cout << ops.size() << "\n";
        forn(i, ops.size()) cout << ops[i].fi << " " << ops[i].se << "\n";
    }
    else
    {
        int idmn = 0;
        for (int i = 0; i < n; i++) if (a[i] < a[idmn]) idmn = i;
        ops.push_back({idmn + 1, 1});
        ops.push_back({idmn + 1, 1});
        ops.push_back({1, 1});
        for (int i = n - 1; i > 0; i--)
        {
            if (i < n - 1) ops.push_back({1, i + 1});
            ops.push_back({1, 1});
        }
        cout << ops.size() << "\n";
        forn(i, ops.size()) cout << ops[i].fi << " " << ops[i].se << "\n";
    }
    return 0;
    forn(i, ops.size())
    {
        a[ops[i].se - 1] += a[ops[i].fi - 1];
    }
    forn(i, n) cout << a[i] << " ";
    cout << "\n";
}


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

int s[7];
int check(int a, int b)
{
	int x, y;
	for (int i = 1; i <= 6; i++)
	{
		if (s[i] == a) x = i;
		if (s[i] == b) y = i;
	}
	if (((x == 2) && (y == 1)) || ((x == 6) && (y == 2)) || ((x == 5) && (y == 6)) || ((x == 1) && (y == 5))) cout << s[4] << endl;
	if (((x == 1) && (y == 2)) || ((x == 2) && (y == 6)) || ((x == 6) && (y == 5)) || ((x == 5) && (y == 1))) cout << s[3] << endl;
	if (((x == 3) && (y == 2)) || ((x == 2) && (y == 4)) || ((x == 4) && (y == 5)) || ((x == 5) && (y == 3))) cout << s[6] << endl;
	if (((x == 2) && (y == 3)) || ((x == 4) && (y == 2)) || ((x == 5) && (y == 4)) || ((x == 3) && (y == 5))) cout << s[1] << endl;
	if (((x == 1) && (y == 4)) || ((x == 4) && (y == 6)) || ((x == 6) && (y == 3)) || ((x == 3) && (y == 1))) cout << s[2] << endl;
	if (((x == 4) && (y == 1)) || ((x == 6) && (y == 4)) || ((x == 3) && (y == 6)) || ((x == 1) && (y == 3))) cout << s[5] << endl;
	return 0;
}
int main()
{
	int x, y;
	int n;
	for (int i = 1; i <= 6; i++)
	{
		cin >> s[i];
	}
	cin >> n;
	for (int i = 1; i <= n; i++)
	{
		cin >> x >> y;
		check(x, y);
	}
	return 0;
}



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

int main(void) {
    int n;
    cin >> n;
    
    int a = 0, t;
    t = n;
    while (t != 0) {
        a += t % 10;
        t /= 10;
    }
    
    cout << (n % a == 0 ? "Yes" : "No") << endl;
    
    return 0;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
int nt[N << 1], to[N << 1], head[N], cnt = 0;

void add(int x, int y) {
  to[++cnt] = y;
  nt[cnt] = head[x];
  head[x] = cnt;
}

int f[N], g[N], ans = 0;
void predfs(int u, int fa) {
  int s = 0, pos = 0, tmp = 0, mx = 0;
  for(int i = head[u]; i; i = nt[i]) {
    if(to[i] == fa) continue;
    predfs(to[i], u);
    ans = max(ans, mx + g[to[i]] + 1);
    mx = max(mx, g[to[i]] + 1);
    pos += f[to[i]];
    tmp++;
  }
  g[u] = mx;
  f[u] = pos + (tmp / 2);
  if(u == 1) f[u] += tmp & 1;
  if(!tmp) f[u] = 0;
}

int lmt, flg, up[N], A, B, num, st[N];
multiset<int> S;
multiset<int> :: iterator sit;
void dfs(int u, int fa) {
  if(!flg) return ;
  for(int i = head[u]; i; i = nt[i]) {
    if(to[i] == fa) continue;
    dfs(to[i], u);
  }
//  printf("%d %d\n", u, fa);
  for(int i = head[u]; i; i = nt[i]) {
    if(to[i] == fa) continue;
    if(f[to[i]] + 1 > lmt) {
      flg = 0;
      return ;
    }
//    printf("%d %d num = %d\n", to[i], f[to[i]] + 1, num);
    S.insert(f[to[i]] + 1);
  }
  int top = 0;
  while(S.size() > 1) {
    int pos = *S.rbegin();
    S.erase(S.find(pos));
    if(*S.rbegin() + pos <= lmt) {
      num++;
      int tmp = *S.rbegin();
      S.erase(S.find(tmp));
    } else if(*S.begin() + pos > lmt) {
      st[++top] = pos;
    } else {
      sit = S.upper_bound(lmt - pos);
      sit--;
      num++;
      S.erase(sit);
    }
  }
  if(S.size()) {
    st[++top] = *S.begin();
    S.clear();
  }
  f[u] = 0;
  if(top) {
    sort(st + 1, st + 1 + top);
    f[u] = st[1];
    num += top - 1;
  }
//  if(u == 2) printf("qswl%d\n", f[u]);
  if(!fa && f[u]) num++;
}

bool check(int x) {
  flg = 1;
  lmt = x, num = 0;
  dfs(1, 0);
//  printf("qwq%d %d %d\n", x, num, flg);
  return flg && num <= A;
}

int main() {
  int n;
  scanf("%d", &n);
  for(int i = 2, x, y; i <= n; ++i) {
    scanf("%d%d", &x, &y);
    add(x, y), add(y, x);
  }
  memset(f, 0x3f, sizeof f);
  predfs(1, 0);
  A = f[1];
  int l = 1, r = ans;
  while(l <= r) {
    int mid = (l + r) >> 1;
    if(check(mid)) r = mid - 1, B = mid;
    else l = mid + 1;
  }
//  check(2);
  printf("%d %d\n", A, B);
  return 0;
}

Measured memory_bytes: 9600
#include <bits/stdc++.h>
using namespace std;
using Int = long long;
int PREP = (cin.tie(nullptr), ios::sync_with_stdio(false), cout << fixed << setprecision(9), 0);
//int SEGV = getenv("D") || (exit(system("D= SEGFAULT_SIGNALS=all catchsegv ./prog.exe") >> 8), 0);
int main() {
    int T; cin >> T;
    while (T--) {
        Int N, A, B, C, D; cin >> N >> A >> B >> C >> D;
        map<Int, Int> memo = { {0, 0}, {1, D} };
        auto dfs = [&](auto&& dfs, Int val) -> Int {
            if (memo.count(val)) return memo[val];
            Int ans;
            if (__builtin_mul_overflow(val, D, &ans)) {
                ans = LLONG_MAX;
            }
            if (val % 2 == 0) {
                ans = min(ans, dfs(dfs, val / 2) + A);
            } else {
                ans = min(ans, dfs(dfs, val / 2) + A + D);
                ans = min(ans, dfs(dfs, val / 2 + 1) + A + D);
            }
            if (val % 3 == 0) {
                ans = min(ans, dfs(dfs, val / 3) + B);
            } else if (val % 3 == 1) {
                ans = min(ans, dfs(dfs, val / 3) + B + D);
            } else {
                ans = min(ans, dfs(dfs, val / 3 + 1) + B + D);
            }
            if (val % 5 == 0) {
                ans = min(ans, dfs(dfs, val / 5) + C);
            } else if (val % 5 == 1) {
                ans = min(ans, dfs(dfs, val / 5) + C + D);
            } else if (val % 5 == 2) {
                ans = min(ans, dfs(dfs, val / 5) + C + D + D);
            } else if (val % 5 == 3) {
                ans = min(ans, dfs(dfs, val / 5 + 1) + C + D + D);
            } else {
                ans = min(ans, dfs(dfs, val / 5 + 1) + C + D);
            }
            return memo[val] = ans;
        };
        cout << dfs(dfs, N) << '\n';
    }
    return 0;
}


Measured memory_bytes: 4216
#include <stdio.h>

int main(void)
{
    int n,a,b,c,d;
    scanf("%d",&n);
    a=n/1000%10;
    b=n/100%10;
    c=n/10%10;
    d=n%10;
    if(a+b+c+d==7)printf("%d+%d+%d+%d=7",a,b,c,d);
    else if(a-b+c+d==7)printf("%d-%d+%d+%d=7",a,b,c,d);
    else if(a+b-c+d==7)printf("%d+%d-%d+%d=7",a,b,c,d);
    else if(a+b+c-d==7)printf("%d+%d+%d-%d=7",a,b,c,d);
    else if(a-b-c+d==7)printf("%d-%d-%d+%d=7",a,b,c,d);
    else if(a-b+c-d==7)printf("%d-%d+%d-%d=7",a,b,c,d);
    else if(a+b-c-d==7)printf("%d+%d-%d-%d=7",a,b,c,d);
    else printf("%d-%d-%d-%d=7",a,b,c,d);
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)n; ++i)
#define repi(i, a, b) for (int i = int(a); i < int(b); ++i)
#define repr(i, n) for (int i = (int)n - 1; i >= 0; --i)
#define ALL(a) (a).begin(), (a).end()
const ll mod = 1e9 + 7;

int main() {
  int n, a, b, i = 1;
  cin >> n;
  vector<int> p(n), q(n), ans(n);
  rep(i, n) cin >> p[i];
  rep(i, n) cin >> q[i];
  rep(i, n) ans[i] = i + 1;
  do {
    int count = 0;
    rep(i, n) {
      if (p[i] == ans[i]) count++;
    }
    if (count == n) {
      a = i;
    }
    i++;
  } while (next_permutation(ALL(ans)));
  i = 1;
  do {
    int count = 0;
    rep(i, n) {
      if (q[i] == ans[i]) count++;
    }
    if (count == n) {
      b = i;
    }
    i++;
  } while (next_permutation(ALL(ans)));
  cout << abs(a - b) << endl;
  return 0;
}

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

using namespace std;

int main() {
	int n;
	cin >> n;
	
	int p = n % 10;
	if (p == 2 || p == 4 || p == 5 || p == 7 || p == 9) cout << "hon";
	else if (p == 0 || p == 1 || p == 6 || p == 8) cout << "pon";
	else cout << "bon";
	return 0;
}


Measured memory_bytes: 3584
#include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <functional>
#include <numeric>
#include <list>
#include <set>
#include <map>
#include <algorithm>
#include <cmath>
#include <limits>
#include <iomanip>
#include <bitset>
#include <queue>
#include <unordered_set>
#include <unordered_map>

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;

#define rep(i, n) for(int i = 0;i < n;i++)
const int INF = 1LL << 30;
const int MOD = 1000000007;


int main(){
    std::ios_base::sync_with_stdio(false);
    cin.tie(0);

    int h,n; cin >> h >> n;

    std::vector<int> a(n);
    std::vector<int> b(n); rep(i,n) cin >> a[i] >> b[i];

    std::vector<int> min_mana_to_kill_hp(10000+1, INF);
    min_mana_to_kill_hp[0] = 0;

    rep(i,n){
        rep(j,10000+1){
            if(j-a[i]>=0) min_mana_to_kill_hp[j] = min(min_mana_to_kill_hp[j], min_mana_to_kill_hp[j-a[i]]+b[i]);
        }
    }

    int m = min_mana_to_kill_hp[h];
    
    for(int i=h+1; i<10001; ++i){
        m = min(m, min_mana_to_kill_hp[i]);
    }

    cout << m << endl;


    return 0;
}

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

using ll = long long;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define ddrep(i, n) for (int i = n; i > 0; --i)
#define srep(i, s, t) for (int i = s; i < t; ++i)
#define ssrep(i, s, t) for (int i = s; i <= t; ++i)

#define rng(a) a.begin(), a.end()
#define pb push_back
#define eb emplace_back
#define fi first
#define se second

#define chmax(x, y) (x = max(x, y))
#define chmin(x, y) (x = min(x, y))

using pi = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using ld = long double;

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << "(" << p.first << "," << p.second << ")";
  return os;
}

template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
  os << "{";
  rep(i, (int)v.size()) {
    if (i)
      os << ",";
    os << v[i];
  }
  os << "}";
  return os;
}

template <typename T, size_t S> void printArray(const T (&array)[S]) {
  for (auto val : array)
    std::cout << val << ", ";
  std::cout << "\n";
}

const int mod = 1e9 + 7;
const int inf = 1e9 + 5;

struct Edge {
  int to, c;
};
vector<vector<Edge>> graph;
vector<ll> cost;

void dfs(int d, ll c, int p) {
  cost[d] = c;
  for (auto &edge : graph[d]) {
    if (edge.to == p) continue;
    dfs(edge.to, c+edge.c, d);
  }
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << std::setprecision(10);

  int n; std::cin >> n;
  graph.resize(n);
  cost.resize(n);
  rep(i, n-1) {
    int a, b, c; std::cin >> a >> b >> c;
    a--, b--;
    graph[a].pb({b, c}), graph[b].pb({a, c});
  }
  int q, k; std::cin >> q >> k;
  k--;
  dfs(k, 0, -1);
  rep(i, q) {
    int x, y; std::cin >> x >> y;
    x--, y--;
    std::cout << cost[x] + cost[y] << "\n";
  }
}


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



int main() {
  double a;
  cin >> a;
  double o=0;
  for(int i=1;i<=a;i++){if(i%2==1){o++;}}
  printf("%.12lf\n",o/a);

}

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

#define N 1505

int a[N][N], val[N], n, m;

int b[N >> 1][N >> 1];

using pii = pair <int, int>;

const int mod = 998244353;

bool adj[N][N];
int col[N], tot[N], sum[N], cnt[N];

int C;

void add_edge(int x, int y) {
    adj[x][y] = adj[y][x] = 1;
}

void go(int k) {
    col[k] = C;
    for (int i = 1; i <= m; i ++) if (adj[k][i]) {
            tot[C] ++;
            if (!col[i]) go(i);
        }
}

char s[N][N];

int main() {
    scanf("%d", &n);
    n --;
    for (int i = 1; i <= n; i ++) {
        scanf("%s", s[i] + 1);
        for (int j = 1; j <= n; j ++) {
            if (s[i][j] == '?') a[i][j] = 0;
            else if (s[i][j] == 'o') a[i][j] = 1;
            else a[i][j] = -1;
        }
    }
    for (int x = 0; x <= n + 1; x ++) {
        for (int y = x + 2; y <= n + 1; y += 2) {
            int d = (y - x) >> 1;
            vector <pii> vec;
            vec.push_back(pii(x + d, d));
            vec.push_back(pii(d, x + d));
            vec.push_back(pii(n + 1 - d, n + 1 - x - d));
            vec.push_back(pii(n + 1 - x - d, n + 1 - d));
            int cnt[3] = {0};
            for (auto x : vec) cnt[a[x.first][x.second] + 1] ++;
            if (cnt[0] > 0 && cnt[2] > 0) return puts("0"), 0;
            if (cnt[0] > 0) for (auto x : vec) a[x.first][x.second] = -1;
            if (cnt[2] > 0) for (auto x : vec) a[x.first][x.second] = 1;
        }
    }
    int ans = 1, pw = 0;
    for (int d = 0; d < 2; d ++) {
        int up = (n + 1) >> 1;
        C = 0;
        memset(b, 0, sizeof b);
        memset(adj, 0, sizeof adj);
        memset(col, 0, sizeof col);
        memset(sum, 0, sizeof sum);
        m = 0;
        for (int i = 1; i <= up; i ++) {
            for (int j = i; j <= n + 1 - i; j ++) {
                if ((i + j & 1) == d) {
                    int x = j - i, y = j + i;
                    x = (x + 2) >> 1, y = (y + 2) >> 1;
                    b[x][y] = b[y][x] = a[i][j];
                    m = max({x, y, m});
                }
            }
        }
        if (m & 1) {
            for (int i = 1; i <= m; i ++) {
                val[i] = 0;
                for (int j = 1; j <= m; j ++) if (i != j) {
                        if (b[i][j] == 0) add_edge(i, j);
                        else if (b[i][j] == 1) val[i] ^= 1;
                    }
            }
            for (int i = 1; i <= m; i ++) if (!col[i]) ++ C, tot[C] = 0, cnt[C] = 0, go(i);
            for (int i = 1; i <= m; i ++) cnt[col[i]] ++;
            for (int i = 1; i <= m; i ++) if (val[i]) sum[col[i]] ++;
            for (int i = 1; i <= C; i ++) if (sum[i] & 1) return puts("0"), 0;
            for (int i = 1; i <= C; i ++) pw += tot[i] / 2 - (cnt[i] - 1);
        }
        else {
            for (int i = 1; i <= m; i ++) for (int j = i + 1; j <= m; j ++) if (b[i][j] == 0) pw ++;
        }
    }
    while (pw --) {
        ans <<= 1;
        if (ans >= mod) ans -= mod;
    }
    printf("%d\n", ans);
    return 0;
}


Measured memory_bytes: 19180
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <cmath>
#include <map>
using namespace std;

int N;
vector <int> kekka;
bool vld[10101010];

int main()
{
	cin >> N;
	int sum=0;
	for(int i=1; i<N+1; i++){
		sum += i;
		kekka.push_back(i);
		if(sum==0){
			break;
		}
		else if(sum>N){
			kekka.erase(remove(kekka.begin(), kekka.end(), sum-N), kekka.end());
			break;
		}
	}
	for(int i=0; i<kekka.size(); i++){
		cout << kekka[i] << endl;
	}
	return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
char arr[1010][1010];
long long int dp[1010][1010];
const int mod = 1e9+7;
int main()
{
    int n,i,j,k,x,y,ans=0,curr,last;
    int r,c;
    scanf("%d %d",&r,&c);
    getchar();
    for(i=1;i<=r;i++)
    {
        for(j=1;j<=c;j++)
        {
            scanf("%c",&arr[i][j]);
        }
        getchar();
    }
    dp[1][1] = 1;
    for(i=1;i<=r;i++)
    {
        for(j=1;j<=c;j++)
        {
            if(arr[i][j] == '#')
            {
                dp[i][j] = 0;
                continue;
            }
            dp[i][j] = 0;
            if(i == 1 && j == 1)
                dp[i][j] = 1;
            if(i > 1)
            {
                dp[i][j] = dp[i-1][j];
            }
            if(j > 1)
            {
                dp[i][j] = (dp[i][j] + dp[i][j-1]) % mod;
            }
        }
    }
    printf("%lld\n",dp[r][c] % mod);
    return 0;
}


Measured memory_bytes: 9216
#include <stdio.h>
int main ()
{
    int H,W,i,j;
    
    while(1){
    
     scanf("%d %d", &H, &W);
     if(H == 0 && W == 0) break;
     for(i = 1; i<= H; i++){
        
         for(j = 1; j <= W; j++){
             printf("#");
         }
         printf("\n");
     }
     printf("\n");
    }
     return 0;
}


Measured memory_bytes: 2040
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define FOR(i,a,n) for(int i=(a); i<(n); i++)
#define all(v) v.begin(), v.end()
#define fi first
#define se second
#define sz(x) int(x.size())
using namespace std;
using ll = long long;
using P = pair<int ,int>;
const int INF = 1001001001;
const int MOD = 1000000007;
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 (b<a) {a=b; return 1;} return 0;}

#ifdef _DEBUG
#include "debug.h"
#else
#define debug(...)
#define print(...)
#endif

int main() {
    string s; cin >> s;
    int g = 0, p = 0;
    int n = sz(s);
    int ans = 0;
    rep(i, n) {
        if (i==0) {
            g++;
            if (s[i]=='p') ans--;
            continue;
        }
        if (s[i]=='g') {
            if (g-p>=1) {
                p++;
                ans++;
            } else {
                g++;
            }
        } else {
            if (g-p>=1) {
                p++;
            } else {
                g++;
                ans--;
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int mod = 1000000007;

int main() {
    ios::sync_with_stdio(false);
    int n, m, u, v, z = 0, a[100005] = {}, b[100005] = {0, 1};
    cin >> n >> m;
    for (int i = 1; i <= n; i++) a[i] = 1;
    while (m--) {
        cin >> u >> v;
        a[u]--;
        a[v]++;
        if (b[u]) b[v] = 1;
        if (!a[u]) b[u] = 0;
    }
    for (int i = 1; i <= n; i++) z += b[i];
    cout << z;
}


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

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

    if (s[2] == s[3] && s[4] == s[5])
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 256
//#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <string>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque> 
#include <algorithm>
 
using namespace std;
 
#define     lli                 long long int
#define     ulli                unsigned long long int

#define     ifor(st,lim)        for(int i=st;i<lim;i++)
#define     jfor(stt,llim)      for(int j=stt;j<llim;j++)
#define		Test(tt)			for(int test=1;test<=tt;test++)
#define		For(var,srt,nnd)	for(var=srt;var<nnd;var++)
#define		Rfor(var,srt,nnd)	for(var=srt;var>=nnd;var--)
 
#define     pb                  push_back
#define     mkp                 make_pair
 
#define     pi                  acos(-1)
#define     mod                 100000007
 
#define     Clear(var,val)      memset(var,val,sizeof(var));
#define     len(var)            var.length()
#define     vlen(vect)          (int)vect.size()
#define     line(ss)            getline(cin,ss);

#define		FIO					ios_base::sync_with_stdio(false);cin.tie(NULL)

#define		sclock				int start_s=clock()
#define		eclock				int end_s=clock()
#define		pclock				printf("\nRuntime :: %.2lf\n", (double)(end_s-start_s)/CLOCKS_PER_SEC)
 
/****************************** IO ************************************/
#define		ina(a)				scanf("%d",&a)
#define		inb(a,b)			scanf("%d %d",&a,&b)
#define		inc(a,b,c)			scanf("%d %d %d",&a,&b,&c)
#define		ins(chr)			scanf("%s",s)
#define		inlla(a)			scanf("%lld",&a)
#define		inllb(a,b)			scanf("%lld %lld",&a,&b)
#define		inllc(a,b,c)		scanf("%lld %lld %lld",&a,&b,&c)
 
#define		outa(a)				printf("%d",a)
#define		outlla(a)			printf("%lld",a)

#define		yn(b)				puts(b ? "YES" : "NO") 

#define		outar(ar,ln,c)		for(int i=0;i<ln;i++){printf("%d%c",ar[i],c);}

#define		outCase()			printf("Case %d:",test)
 
#define		blank				printf("\n")
/**********************************************************************/

int main()
{
    FIO;
/******************************* E ************************************/
	
	lli ans=0;
	int eatR,eatG,R,G,C,tmp,cc;
	cin >> eatR >> eatG >> R >> G >> C;
	vector<int> red,green,white; 
	ifor(0,R)
	{
		cin >> tmp;
		red.pb(tmp);
	}
	ifor(0,G)
	{
		cin >> tmp;
		green.pb(tmp);
	}
	ifor(0,C)
	{
		cin >> tmp;
		white.pb(tmp);
	}
	sort(red.rbegin(),red.rend());
	sort(green.rbegin(),green.rend());
	sort(white.rbegin(),white.rend());
	
	cc=0;eatR--;eatG--;
	while(cc<C and eatR>=0 and eatG>=0)
	{
		if(white[cc]>red[eatR] or white[cc]>green[eatG])
		{
			if(red[eatR]>green[eatG]) eatG--;
			else eatR--;
			cc++;
		}
		else break;
	}
	while(cc<C and eatR>=0)
	{
		if(white[cc]>red[eatR])
		{
			eatR--;cc++;
		}
		else break;
	}
	while(cc<C and eatG>=0)
	{
		if(white[cc]>green[eatG])
		{
			eatG--;cc++;
		}
		else break;
	}
	ifor(0,eatR+1) ans+=(lli)red[i];
	ifor(0,eatG+1) ans+=(lli)green[i];
	ifor(0,cc) ans+=(lli)white[i];
	
	cout << ans << endl;
	
	
/**********************************************************************/
    return 0;
}


Measured memory_bytes: 1784
#pragma GCC optimize ("O3")
#pragma GCC target ("avx")
//#include<bits/stdc++.h>
#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

const int cm = 1 << 17;
char cn[cm], * ci = cn + cm, ct;
inline char getcha() {
	if (ci - cn == cm) { fread_unlocked(cn, 1, cm, stdin); ci = cn; }
	return *ci++;
}
inline int getint() {
	int A = 0;
	if (ci - cn + 12 > cm) while ((ct = getcha()) >= '0') A = A * 10 + ct - '0';
	else while ((ct = *ci++) >= '0') A = A * 10 + ct - '0';
	return A;
}
void pakuri_sort(int N, int A[]) {
	const int b = 8;
	int tmp[300001];
	rep(k, 4) {
		int kazu[1 << b] = {}, kazu2[1 << b] = {};
		rep(i, N) kazu[A[i] >> k * b & ((1 << b) - 1)]++;
		rep(i, (1 << b) - 1) kazu[i + 1] += kazu[i];
		for (int i = N - 1; i >= 0; i--) tmp[--kazu[A[i] >> k * b & ((1 << b) - 1)]] = A[i];
		k++;
		rep(i, N) kazu2[tmp[i] >> k * b & ((1 << b) - 1)]++;
		rep(i, (1 << b) - 1) kazu2[i + 1] += kazu2[i];
		for (int i = N - 1; i >= 0; i--) A[--kazu2[tmp[i] >> k * b & ((1 << b) - 1)]] = tmp[i];
	}
}

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


	int N = getint();
	int A[300000];
	rep(i, 3 * N) A[i] = getint();
	pakuri_sort(3 * N, A);

	ll kotae = 0;
	for (int i = N; i < 3 * N; i += 2) kotae += A[i];

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

	Would you please return 0;
}

Measured memory_bytes: 2688
li = [ int(it) for it in input() ]
N = len(li)

s1 = 0
flip = 0
for it in li:
  if it != flip:
    s1+=1
  flip=1-flip
s2 = 0
flip = 1
for it in li:
  if it != flip:
    s2+=1
  flip=1-flip
print ( min (s1,s2) )

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

int main(){
  int a,b,c,k;
  cin >> a >> b >> c >> k;
  
  if (k <= a) cout << k << endl;
  else if (k <= a + b) cout << a << endl;
  else cout << a - (k - (a + b)) << endl;
  return 0;
}


Measured memory_bytes: 3580
f :: [String] -> IO()
f [] = return()
f [a,op,b]
    | op == "+" = print $ read a  + read b
    | op == "-" = print $ read a  - read b
    | op == "*" = print $ read a  * read b
    | op == "/" = print $ read a  `div` read b
    | op == "?" = return()
    
main = getContents >>= mapM_ f . ( map words ) . lines


Measured memory_bytes: 4076
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
int INF = 1000000007;
 
 
int main(){
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
 
  int N;
  cin >> N;
  cout << N*800 - (N/15)*200 << endl;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <math.h>
using namespace std;

int main() {
	int day;
	double a[4];

	scanf("%d", &day);
	for (int i = 0; i < 4; i++) {
		scanf("%lf", &a[i]);
	}

	double temp1, temp2;
	temp1 = ceil(a[0] / a[2]);
	temp2 = ceil(a[1] / a[3]);

	printf("%d\n", day - (int)max(temp1, temp2));

	return 0;
}

Measured memory_bytes: 1064
#include <iostream>
#include <queue>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <algorithm>
#include <cmath>
#include <iomanip>

using namespace std;

#define REP(i,n) for(ll (i) = (0); (i) < (n); ++i)
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define ALL(v) v.begin(),v.end()
#define INF 1100000000
#define LLINF 1000000000000000000LL
#define MOD 1000000007
#define Decimal fixed << setpresicion(20)


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

void prime_factor(ll n, map<ll, ll>& res) {
  for (ll i = 2; i * i <= n; i++) {
    while (n % i == 0) {
      res[i]++;
      n /= i;
    }
  }
  if (n != 1) res[n] = 1;
}

ll mypow(ll a, ll n)
{
  ll ret = 1;
  for (int i = 0; i < n; i++) 
    ret *= a;
  return ret;
}

int main()
{
  ll N, P; cin >> N >> P;
  map<ll, ll> mp;
  prime_factor(P, mp);
  ll ans = 1;
  for (auto e : mp) {
    if (e.SE >= N) ans *= mypow(e.FI,(e.SE/N));
  }
  cout << ans << endl;
  return 0;
}



Measured memory_bytes: 256
n = int(input())
a = list(map(int,input().split()))
from math import log,floor
minc = 1000000
for i in range(n):
    count = 0
    while True:
        if a[i]%2==1:
            break
        else:
            a[i]=a[i]//2
            count+=1
    minc = min(minc,count)

print(minc)

Measured memory_bytes: 38640
#include <bits/stdc++.h>
#include <ext/pb_ds/detail/standard_policies.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define pb push_back
#define F first
#define S second
#define ll long long
#define ull unsigned long long
#define ld long double
#define endl '\n'
#define TIME 1.0*clock()/CLOCKS_PER_SEC
#define pii pair < int , int >
#define Endl '\n'

#pragma GCC optimize("Ofast")

using namespace std;
using namespace __gnu_pbds;

template <typename T> using ordered_set = tree <T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;

mt19937 gen(chrono::system_clock::now().time_since_epoch().count());

const int mod = 1e9 + 7;
const int FFTM = 998244353;

const int SX[4] = {0 , 1 , -1 , 0};
const int SY[4] = {1 , 0 , 0 , -1};
const int rx[8] = {1, -1, 0, 0, 1, 1, -1, -1};
const int ry[8] = {0, 0, 1, -1, 1, -1, 1, -1};
const int kx[8] = {1, 1, -1, -1, 2, 2, -2, -2};
const int ky[8] = {2, -2, 2, -2, 1, -1, 1, -1};

typedef cc_hash_table< int, int, hash<int>, equal_to<int>, direct_mask_range_hashing<int>, hash_standard_resize_policy<hash_exponential_size_policy<>, hash_load_check_resize_trigger<true>, true>> ht;

int32_t main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#else
//    freopen("gotham.in", "r", stdin);
//    freopen("gotham.out", "w", stdout);
#endif
    int l, r, d;
    cin >> l >> r >> d;
    int kol = 0;
    for (int i = l;i <= r; ++i){
        if (i % d == 0)kol++;
    }
    cout << kol << endl;
    return 0;
}


Measured memory_bytes: 3648
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cstdio>
#include<cstring>
#include<map>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(n) rep(i,n)
#define all(n) n.begin(),n.end()

#define N_MAX 100

int n,m;
string NUM[N_MAX];
long R[N_MAX];

string S;
int t,k;


bool is_atari(string s1,string s2){
    for(int i = 0;i < 8;i++){
        if(s1[i] != '*'){
            if(s1[i] != s2[i])return false;
        }
    }
    return true;
}

/*
int getlen(string str){
    int i=0;
    int k=0;
    while(str[k] == '*' && str[k] != '\0')k++;
    while(str[k] != '\0'){
        k++;
        i++;
    }
    return i;
}*/



int main()
{
    long reward;
    string tmp;
    while(cin >> n >> m){
        if(n == 0)break;
        
        REP(n){
            cin >> S >> t;
            NUM[i] = S;
            R[i] = t;
        }

        reward = 0;
        REP(m){
            cin >> S;
            
            rep(j,n){
                if(is_atari(NUM[j],S)){
                    reward += R[j];
                    break;
                }
            }
        }
        cout << reward << endl;

    }      

    return 0;
}

Measured memory_bytes: 1216
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <queue>

const int N = 2e5 + 52;
struct edge {
	int to, next, w;
} e[N << 4];
int n, head[N], cnt;
void ad(int x, int y, int z) { e[++cnt] = {y, x[head], z}, x[head] = cnt; }

std::queue<int> q;
int dis[N];
int main() {
	memset(head, -1, sizeof head);
	memset(dis, 0x3f, sizeof dis), dis[1] = 1;
	scanf("%d", &n);
	for (int i = 1; i < n; i++)
		for (int j = 0; j < 10; j++) ad(i, (10 * i + j) % n, j);
	for (int i = 1; i < 10; i++) q.push(i);
	for (; !q.empty(); q.pop())
		for (int x = q.front(), i = x[head], nx; ~i; i = e[i].next)
			if ((nx = e[i].to)[dis] > x[dis] + e[i].w)
				nx[dis] = x[dis] + e[i].w, q.push(nx);
	printf("%d", 0 [dis]);
}

Measured memory_bytes: 15616
import sys
import numpy as np
from collections import defaultdict
from numba import njit
def input(): return sys.stdin.readline().rstrip()

@njit
def koushin(dp,item):
    dptmp1 = np.copy(dp)
    dptmp2 = np.copy(dp)
    dptmp3 = np.copy(dp)
    for i in range(len(item)):
        dptmp3[item[i][0]:] = np.fmax(dptmp3[item[i][0]:], dptmp2[item[i][0]]+item[i][1])
        dptmp2[item[i][0]:] = np.fmax(dptmp2[item[i][0]:], dptmp1[item[i][0]]+item[i][1])
        dptmp1[item[i][0]:] = np.fmax(dptmp1[item[i][0]:], dp[item[i][0]]+item[i][1])
    return dptmp3

def main():
    R, C, K = map(int, input().split())
    items = defaultdict(list)
    for _ in range(K):
        r, c, v = map(int, input().split())
        items[r-1].append([c-1, v])
    dp = np.zeros(C, dtype=int)
    for RR in range(R):
        if items[RR]==[]:
          continue
        items[RR].sort(key=lambda x: x[0])
        dp=koushin(dp,np.array(items[RR],dtype=int))
    print(dp[-1])


if __name__ == '__main__':
    main()

Measured memory_bytes: 151212
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define N ((ll)301*1000)

struct Ant{
	ll x,y,id;
	char c;
};

bool cmp(Ant x,Ant y){return x.x<y.x;}

ll n,m,t,ans[N],cnt_l;
pair <ll,ll> b[N];
Ant a[N];
ll tmp[N];

int main()
{
	ios_base::sync_with_stdio(0);cin.tie(0);
	cin>>n>>m>>t;
	for(int i=0;i<n;i++)
	{
		int xy ; 
		cin>>a[i].x>>xy;
		if(xy == 1) a[i] . c = 'R' ; else a[i] . c = 'L' ; 
		a[i].id=i;
		a[i].y=a[i].x+(t%m)*(a[i].c=='R'?1:-1);
		if(a[i].y<=0)a[i].y+=m;
		if(a[i].y>m)a[i].y-=m;
		if(a[i].c=='L')cnt_l++;
	}
	sort(a,a+n,cmp);
	ll shift=2*n-2*cnt_l;shift%=n;
	shift*=t/m;shift%=n;t%=m;
	for(int i=0;i<n;i++)tmp[(i+shift)%n]=a[i].id;
	for(int i=0;i<n;i++)a[i].id=tmp[i];
	
	for(int i=0;i<n;i++)b[i]={a[i].y,i};
	sort(b,b+n);
	
	ll hits[2]={};
	for(int q=0;q<2;q++)
		for(int i=0;i<n;i++)
			if(a[i].c!=a[b[q].second].c)
			{
				ll p=b[q].second;
				ll l=a[p].x,r=a[p].y;
				ld pos1=((ld)a[p].x+a[i].x)/2,pos2=pos1+(ld)m/2;
				if(pos2>m)pos2-=m;
				if(l<=r && a[p].c=='R')hits[q]+=(l<pos1 && pos1<r)+(l<pos2 && pos2<r);
				if(l<=r && a[p].c=='L')hits[q]+=(pos1<l || r<pos1)+(pos2<l || r<pos2);
				if(r<l && a[p].c=='L')hits[q]+=(r<pos1 && pos1<l)+(r<pos2 && pos2<l);
				if(r<l && a[p].c=='R')hits[q]+=(pos1<r || l<pos1)+(pos2<r || l<pos2);
			}
	ll id1=(b[0].second+hits[0]*(a[b[0].second].c=='R'?1:-1)+5*n)%n,id2=(b[1].second+hits[1]*(a[b[1].second].c=='R'?1:-1)+5*n)%n;
	for(int i=id1,j=0;j<n;i++,i%=n,j++)
		ans[a[i].id]=b[(j+(b[0].first==b[1].first && (id2+1)%n==id1))%n].first;
	for(int i=0;i<n;i++)cout<<ans[i] % m<<'\n';
	return 0;
}

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

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

  int A[N], ans = 0;
  for (int i = 0; i < N; i++) {
    cin >> A[i];
    if (A[i] % 2 == 1) {
      cout << ans << endl;
      return 0;
    }
  }

  while (true) {
    ans++;
    for (int i = 0; i < N; i++) {
      A[i] /= 2;
      if (A[i] % 2 == 1) {
        cout << ans << endl;
        return 0;
      }
    }
  }
}

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

int main(){
  int N, K;
  cin >> N >> K;
  vector<int> h(N);
  for(int i=0; i<N; i++){
    cin >> h[i];
  }
  int ans=0;
  for(int i=0; i<N; i++){
    if (h[i]>=K) ans++;
  }
  cout << ans <<endl;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define sc(n) scanf("%d",&n)
#define scl(n) scanf("%lld",&n)
#define pr(n) printf("%d",n)
#define prl(n) printf("%lld",n)
#define nl printf("\n")
#define fr(i,n) for(i=1;i<=n;i++)
#define bi(n) __builtin_popcount(n)
#define bil(n) __builtin_popcountll(n)


typedef long long ll;
typedef pair<ll,ll> pii;
const int N = 710;
ll mod = 1e9+7;
ll fmod(ll b,ll exp){
    ll res =1;
    while(exp){if(exp&1ll)res=(res*b)%mod;
    b =(b*b)%mod;exp/=2ll;
    }
    return res;
}
int fl =0;
int bl =0,red=0;
bitset<N> a,b;
int col[N],vis[N];
int A[N][N];
vector<int> adj[N];
vector<pii> v;

void dfs(int i,int k){
    vis[i]=1;
    col[i]=k;
    if(k==0)bl++;
    else red++;
    for(auto ve:adj[i]){
        if(!vis[ve])dfs(ve,1-k);
        else {
            if(col[ve]!=(1-k)){
                fl=1;
            }
        }
    }
}

ll fn(int num){
    ll res = (1ll*num);
    return (res*(res-1))/2ll;
}


int main()
{
    ios_base::sync_with_stdio(false);cin.tie(NULL);
    int t=1,n,i,j;
    int m;
    int u,vi;
    cin>>n>>m;
    fr(i,m){
        cin>>u>>vi;
        A[u][vi]=1;
        A[vi][u]=1;
    }
    fr(i,n){
        fr(j,n)A[i][j]=(1-A[i][j]);
        fr(j,n)if(i-j && A[i][j])adj[i].pb(j);
    }

    fr(i,n)
        if(!vis[i]){
            ll tp1= bl;
            ll tp2 = red;
            dfs(i,0);
            v.pb(mp(bl-tp1,red-tp2));
        }
    if(fl)cout<<"-1\n";
    else{
       
        a.set(0);
        ll mn = 1e18;
        for(auto ve:v){
            b.reset();
            b |= (a<<(ve.f));
            b |= (a<<(ve.s));
            a = b;
        }
        for(int i=0;i<=n;i++)if(a.test(i)){
            mn = min(fn(i)+fn(n-i),mn);
        }
    
        cout<<mn<<"\n";
    }







    
    return 0;
}


Measured memory_bytes: 5120
import sys
from collections import Counter
readline = sys.stdin.readline

def divi(n):
    res = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            res.append(i)
            if i != n // i:
                res.append(n//i)
    return res

MOD = 998244353
N = int(readline())
X = list(map(int, readline().strip()))
D = divi(N)
C = Counter()
for d in D:
    if N//d % 2 == 0:
        continue
    res = 0
    for x in X[:d]:
        res = (2*res)%MOD
        res += x
    res += 1
    xx = X[:d] + [not x for x in X[:d]]
    for i in range(N):
        x1 = X[i]
        x2 = xx[i%(2*d)]
        if x1 == x2:
            continue
        if x1 < x2:
            res -= 1
            break
        break
    C[2*d] = res%MOD

CL = list(C.items())
CL.sort()
K = len(CL)
Kc, Vc = list(map(list, zip(*CL)))
for i in range(K):
    for j in range(i+1, K):
        if Kc[j] % Kc[i] == 0:
            Vc[j] = (Vc[j] - Vc[i])%MOD
ans = 0
for i in range(K):
    ans = (ans + Kc[i]*Vc[i])%MOD
print(ans)

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

int n;
char arr[101];

int main(void){
  cin>>n;
  if(n%2==1){cout<<"No";return 0;}
  cin>>arr;
  for(int i=0;i<n/2;i++)if(arr[i]!=arr[i+n/2]){cout<<"No";return 0;}
  cout<<"Yes";
 return 0; 
}

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

template<typename T> T In() { T v; cin >> v; return v; }

#define P(s) cout<<s<<endl
#define P2(b,y,f) P(((b)?y:f))
#define REP(i,b,e) for(int i=b;i<e;++i)
#define ALL(con) con.begin(), con.end()

struct Pos {
    int x = 0, y = 0;
    int cnt = 1;
    void Right() { ++x; ++cnt; }
    void Down() { ++y; ++cnt; }
};

int main() {
    auto h = In<int>();
    auto w = In<int>();
    vector<string> board(h);
    
    int num = 0;
    for (auto&& row: board) {
        cin >> row;
        num += accumulate(ALL(row), 0, [](int init, char c) {
            return init + (c=='#'?1:0);
        });
    }
    
    Pos p;
    for(;;) {
        auto right = p.x != w-1 && board[p.y][p.x + 1] == '#';
        auto down = p.y != h-1 && board[p.y + 1][p.x] == '#';
        if (right == down) {
            break;
        }
        
        if (right) {
            p.Right();
        }
        if (down) {
            p.Down();
        }
    }

    P2(num == p.cnt, "Possible", "Impossible");
    
    return 0;
}

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

using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using pii = pair<int, int>;

#define INF 1e9
#define MOD 1000000007
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define each(x, v) for (auto& x: (v))
#define all(x) (x).begin(), (x).end()
#define print(x) cout << (x) << endl

void solve();
void in(){} template<class T, class... U> void in(T &t, U &...u){ cin >> t; in(u...); }
int main() { cin.tie(0); ios::sync_with_stdio(0); solve(); }

void solve() {
  int N;
  in(N);
  vi L(N);
  each(x, L) in(x);

  sort(all(L));

  ll ans = 0;
  rep(i, 0, N)
    rep(j, i + 1, N)
      ans += lower_bound(all(L),L[i] + L[j]) - L.begin() - j - 1;

  print(ans);
}


Measured memory_bytes: 256