akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>

using namespace std;

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

    string s; cin >> s;
    int cnt = 0;
    char prev = 0;
    for(auto c : s)
    {
        if(c == prev) prev = -1;
        else if(prev == -1) {++cnt; prev = 0;}
        else {++cnt; prev = c;}
    }

    cout << cnt;
    return 0;
}


Measured memory_bytes: 720
/*alurquiza*/
//
#include <bits/stdc++.h>

using namespace std;

const int SIZE = 18,SIZE2 = 1 << SIZE;
int DP[SIZE2];
int MAX[SIZE2][4];
vector<int> V(SIZE2);

bool comp(const int &a,const int &b){
    if(a == -1)
        return false;
    if(b == -1)
        return true;

    if(V[a] >= V[b])
        return true;
    return false;
}

void join(int mask,int smask){
    MAX[mask][2] = MAX[smask][0];
    MAX[mask][3] = MAX[smask][1];

    int N = 4;
    stable_sort(MAX[mask],MAX[mask] + N);
    N = unique(MAX[mask],MAX[mask] + N) - MAX[mask];

    stable_sort(MAX[mask],MAX[mask] + N,comp);
}

int main()
{
//    ios_base::sync_with_stdio(0);
//    cin.tie(0); cout.tie(0);

//    freopen(".in","r",stdin);
//    freopen("F.out","w",stdout);

    int N;
    cin >> N;

    for(int i = 0;i < (1 << N);i++)
        cin >> V[i];

    for(int mask = 0;mask < (1 << N);mask++){
        MAX[mask][0] = mask;
        MAX[mask][1] = -1;

        for(int i = 0;(1 << i) <= mask;i++){
            if((1 << i) & mask){
                int nmask = mask ^ (1 << i);
                join(mask,nmask);
            }
        }
        if(MAX[mask][1] != -1)
            DP[mask] = V[MAX[mask][1]];
        DP[mask] += V[MAX[mask][0]];
    }

    for(int i = 1;i < (1 << N);i++){
        DP[i] = max(DP[i],DP[i - 1]);
        cout << DP[i] << '\n';
    }

    return 0;
}


Measured memory_bytes: 9216
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N,L;
  cin>>N>>L;
  vector<string>S(N);
  for(int i=0;i<N;i++)cin>>S.at(i);
  sort(S.begin(),S.end());
  for(int i=0;i<N;i++)cout<<S.at(i);
  cout<<endl;
}

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

using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
signed main(){
  int w,h;cin>>w>>h;
  int res=0;
  vector<int> p(w);
  vector<int> q(h);
  rep(i,w){
    cin>>p[i];
    res+=p[i];
  }
  rep(i,h){
    cin>>q[i];
    res+=q[i];
  }
  sort(q.begin(),q.end());
  vector<int> q_sum(h,0);
  q_sum[0]=q[0];
  rep1(i,h-1)q_sum[i]=q_sum[i-1]+q[i];
  rep1(i,w){
    auto it=lower_bound(q.begin(),q.end(),p[i-1]);
    int index=it-q.begin();
    if(index==0){
      res+=h*p[i-1];
      continue;
    }
    res+=q_sum[index-1];
    res+=(h-index)*p[i-1];
    //cout<<"res="<<res<<endl;
    //printf("%lld\n",index);
    /*rep1(j,h){
      //res+=min(p[i-1],q[j-1]);
      //printf("(%lld,%lld)=%lld\n",i,j,min(p[i-1],q[j-1]));
    }*/
  }
  rep(i,h){
    //printf("q[%lld]=%lld\n",i,q_sum[i]);
  }
  cout<<res<<endl;
  return 0;
}


Measured memory_bytes: 2560
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main()
{
    while (true)
    {
        int n;
        cin>>n;
        if (n==0)
            break;
        vector<int> h(n), r(n);
        for (int i=0; i<n; i++)
            cin>>h[i]>>r[i];
        int m;
        cin>>m;
        h.resize(n+m);
        r.resize(n+m);
        for (int i=n; i<n+m; i++)
            cin>>h[i]>>r[i];

        vector<int> c(n+m, 1);
        for (int i=0; i<n+m; i++)
        for (int j=0; j<n+m; j++)
        for (int k=0; k<n+m; k++)
            if (h[k]<h[j] && r[k]<r[j])
                c[j] = max(c[j], c[k]+1);
        cout<<*max_element(c.begin(), c.end())<<endl;
    }
}

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

int  main()
{
	int  n,digit,s=0,tmp;
	
	cin>>n;
	tmp=n;
	
	while(tmp!=0)
	{
	    digit=tmp%10;
	    s+=digit;
	    tmp=tmp/10;
    }
    
    if(n%s==0)
       cout<<"Yes"<<endl;
    else
       cout<<"No"<<endl;
       
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;;
#define ll long long
#define rep(i, n) for(int i = 0;i < n;i++)
#define repr(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define INF 1<<30
#define LINF 1LL<<62
#define all(x) (x).begin(), (x).end()
#define mp make_pair
#define pb push_back
const int MOD = 1000000007;
 
typedef pair<ll, ll> P;
typedef pair<ll, P> PP;

ll mo[6] = {1,10,9,12,3,4};
int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  string s;cin >> s;
  reverse(all(s));
  vector<ll> num(13,0);
  num[0]  = 1;
  rep(i,s.size()){
      vector<ll> tmp(13,0);
      if(s[i]=='?'){
          rep(j,13){
              rep(k,10){
                  ll pr = mo[i%6];
                  ll to = (j+k*pr)%13;
                  tmp[to] += num[j];
              }
          }
      }else{
          ll x = s[i]-'0';
          rep(j,13){
              ll pr = mo[i%6];
              ll to = (j+x*pr)%13;
              tmp[to]+=num[j];
          }
      }
      rep(j,13){
          tmp[j]%=MOD;
      }
      num = tmp;
  }
  cout << num[5] << endl;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF=1e15;

template<typename T>
struct Dijkstra{
    const T inf=numeric_limits<T>::max();
    using P=pair<T,int>;
    int n;
    vector<vector<pair<int,T>>> G;
    vector<T> d;
    Dijkstra(int n):n(n),G(n),d(n){}
    void add_edge(int u,int v,T w){
        G[u].emplace_back(v,w);
    }
    vector<T> build(int s){
        fill(d.begin(),d.end(),inf);
        d[s]=0;
        priority_queue<P,vector<P>,greater<P>> pq;
        pq.emplace(d[s],s);
        while(!pq.empty()){
            P p=pq.top(); pq.pop();
            int v=p.second;
            if (d[v]<p.first) continue;
            for (auto &e:G[v]){
                int u=e.first; T c=e.second;
                if (d[v]+c<d[u]){
                    d[u]=d[v]+c;
                    pq.emplace(d[u],u);
                }
            }
        }
        return d;
    }
};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,m,s,t; cin >> n >> m >> s >> t;
    Dijkstra<ll> Ds(n),Dt(n);
    for (int i=0;i<m;++i){
        int u,v; ll a,b; cin >> u >> v >> a >> b; --u,--v;
        Ds.add_edge(u,v,a); Ds.add_edge(v,u,a);
        Dt.add_edge(u,v,b); Dt.add_edge(v,u,b);
    }
    vector<ll> S=Ds.build(--s),T=Dt.build(--t);
    vector<ll> ans(n+1,INF);
    for (int i=n-1;i>=0;--i){
        ans[i]=min(ans[i+1],S[i]+T[i]);
    }
    for (int i=0;i<n;++i) cout << INF-ans[i] << '\n';
}

Measured memory_bytes: 20552
#include <iostream>
#include <vector>
#include <stack>
#include <queue>
using namespace std;

int main() {

    int n;
    cin >> n;

    string s;

    cin >> s;

    int leftCount = 0;
    int rightCount = 0;

    int count = 0;

    for(int i = 0; i < n; ++i) {

        if(count == 0 && s[i] == ')')
            leftCount++;
        else if(s[i] == '(') {
            count++;
        }
        else if(s[i] == ')') {
            count--;
        }

    }

    rightCount = count;

    for(int i = 0; i < leftCount; ++i)
        cout << "(";
    cout << s;
    for(int i = 0; i < rightCount; ++i)
        cout << ")";
    
    cout << endl;

    return 0;
}

Measured memory_bytes: 3584
use proconio::*;
use std::cmp::max;
use std::collections::BinaryHeap;

#[fastout]
fn main() {
    input! {
        d: usize,
        c: [i64; 26],
        s: [[i64; 26]; d],
    };

    let mut lasts = [-1; 26];
    let mut t = vec![26; d];
    let depth = 17;
    for i in 0..d {
        let mut max_score = -10000000;
        for j in 0..26 {
            let tmp = search(i, j, &c, &s, &mut lasts, depth, d, 0, 7);
            if tmp > max_score {
                max_score = tmp;
                t[i] = j;
            }
        }
        lasts[t[i]] = i as i64;
    }

    for &a in &t {
        println!("{}", a + 1);
    }
}

fn calc_score(i: usize, j: usize, c: &Vec<i64>, s: &Vec<Vec<i64>>, lasts: &mut [i64; 26]) -> i64 {
    let mut res = s[i][j];
    let tmp = lasts[j];
    lasts[j] = i as i64;

    for j in 0..26 {
        let i = i as i64;
        let last = lasts[j];
        res -= c[j] * (i - last);
    }

    lasts[j] = tmp;
    res
}

fn search(
    i: usize,
    t: usize,
    c: &Vec<i64>,
    s: &Vec<Vec<i64>>,
    lasts: &mut [i64; 26],
    depth: usize,
    d: usize,
    cscore: i64,
    l: usize,
) -> i64 {
    if depth == 0 || i == d - 1 {
        return calc_score(i, t, &c, &s, lasts) + cscore;
    }

    let l = max(1, l - 1);
    let mut max_score = -1000000;
    let tmp_last = lasts[t];
    lasts[t] = i as i64;
    let tmp_score = calc_score(i, t, &c, &s, lasts);
    let mut cands = BinaryHeap::new();
    cands.reserve(26);
    for j in 0..26 {
        let tmp_score = calc_score(i + 1, j, &c, &s, lasts);
        cands.push((tmp_score, j));
    }
    let w = if l > 1 { 2 } else { 1 };
    for &(_, j) in cands.iter().take(w) {
        let tmp = search(i + 1, j, &c, &s, lasts, depth - 1, d, cscore + tmp_score, l);

        if tmp > max_score {
            max_score = tmp;
        }
    }

    lasts[t] = tmp_last;
    max_score + cscore
}


Measured memory_bytes: 2328
#include<bits/stdc++.h>
using namespace std;
int main(){
string s;
  cin>>s;
  int arr[26];
  memset(arr,0,sizeof arr);
 for(int i=0;i<s.length();i++){
 arr[s[i]-'A']++;

 }
  int cnt=0;
  for(int i=0;i<26;i++){
  if(arr[i]==0)continue;
//cout<<i<<" "<<arr[i]<<endl;
    if(arr[i]!=2){
    cout<<"No"<<endl;
      return 0;
    }
    cnt++;

  }
  //cout<<cnt<<endl;
if(cnt==2){
cout<<"Yes"<<endl;
}
  else{
    cout<<"No"<<endl;
}
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)
#define rep2(i,a,n) for(int i=(a); i<(n); i++)
#define all(vec) vec.begin(),vec.end()
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;

int main(){
  int X, N, T; cin >> X >> N >> T;
  int ans = (X/N)*T;
  if(X%N != 0) ans += T;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3620
#include<bits/stdc++.h>
#define MOD 1000000007
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3f
#define EPS (1e-10)
#define rep(i,n)for(int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
typedef pair<int, int>P;

char s[60][30], buf[2];
int d[60][30][60][30][2];
struct st {
	int lx, ly, rx, ry, c;
	bool b;
};
bool operator<(const st&a, const st&b) {
	return a.c > b.c;
}
int C(char c) {
	if (isdigit(c))return c - '0';
	return 0;
}
int w, h;
void update(st p, priority_queue<st>&que) {
	for (int k = -2; k <= 2; k++) {
		for (int t = 1; t <= 3 - abs(k); t++) {
			if (p.b) {
				int nx = p.lx + k, ny = p.ly + t;
				if (0 <= nx&&nx < h && 0 <= ny&&ny < w&&s[nx][ny] != 'X') {
					int&u = d[p.lx][p.ly][nx][ny][!p.b];
					int c = p.c + C(s[nx][ny]);
					if (u > c) {
						u = c; que.push({ p.lx,p.ly,nx,ny,u,!p.b });
					}
				}
			}
			else {
				int nx = p.rx + k, ny = p.ry - t;
				if (0 <= nx&&nx < h && 0 <= ny&&ny < w&&s[nx][ny] != 'X') {
					int&u = d[nx][ny][p.rx][p.ry][!p.b];
					int c = p.c + C(s[nx][ny]);
					if (u > c) {
						u = c; que.push({ nx,ny,p.rx,p.ry,u,!p.b });
					}
				}
			}
		}
	}
}
int main() {
	while (scanf("%d%d", &w, &h), w) {
		memset(d, 0x3f, sizeof(d));
		priority_queue<st>que;
		rep(i, h)rep(j, w) {
			scanf("%s", buf); s[i][j] = buf[0];
		}
		rep(j, w) {
			int i = h - 1;
			if (s[i][j] == 'S') {
				update({ i,j,0,0,0,1 }, que); update({ 0,0,i,j,0,0 }, que);
			}
		}
		while (!que.empty()) {
			st p = que.top(); que.pop();
			if (d[p.lx][p.ly][p.rx][p.ry][p.b] != p.c)continue;
			update(p, que);
		}
		int Min = INF;
		rep(i, h)rep(j, w)rep(k, h)rep(t, w)rep(y, 2) {
			if (s[i][j] == 'T' || s[k][t] == 'T')Min = min(Min, d[i][j][k][t][y]);
		}
		if (Min == INF)puts("-1");
		else printf("%d\n", Min);
	}
}

Measured memory_bytes: 28708
let k_n = stdin.ReadLine().Split(' ') |> Array.map int
let mutable a = stdin.ReadLine().Split(' ') |> Array.map int
a <- Array.sort(a)
a <- Array.rev(a)
let mutable ans = 0
for i in [0..k_n.[1]-1]do
ans<-ans+a.[i]
done;;
printfn "%d" ans


Measured memory_bytes: 30124
from itertools import accumulate

n, k = map(int, input().split())
p = [int(x) - 1 for x in input().split()]
c = list(map(int, input().split()))
ans = -(10 ** 18)

for i in range(n):
    pos = i
    scores = []
    while True:
        pos = p[pos]
        scores.append(c[pos])
        if pos == i:
            break
    m = len(scores)
    s = list(accumulate(scores))
    for j in range(min(m, k)):
        x = (k - j - 1) // m
        ans = max(ans, s[j], s[j] + s[-1] * x)

print(ans)

Measured memory_bytes: 103512
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int[] a = new int[5];
        for (int i = 0; i < a.length; i++) {
            a[i] = sc.nextInt();
        }
        int k = sc.nextInt();
        if (a[4] - a[0] > k) {
            System.out.println(":(");
        } else {
            System.out.println("Yay!");
        }
        sc.close();
    }
}

Measured memory_bytes: 23892
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
#define x first
#define y second
#define mp make_pair
#define pb push_back
template <typename TYPE> inline void chkmax(TYPE &x,TYPE y){x<y?x=y:0;}
template <typename TYPE> inline void chkmin(TYPE &x,TYPE y){y<x?x=y:0;}
template <typename TYPE> void readint(TYPE &x)
{
	x=0;int f=1;char c;
	for(c=getchar();!isdigit(c);c=getchar())if(c=='-')f=-1;
	for(;isdigit(c);c=getchar())x=x*10+c-'0';
	x*=f;
}
const int MAXN=105;

int n,m,a[MAXN][MAXN],p[MAXN];
bool G[MAXN][MAXN];
bool vis[MAXN];
int match[MAXN];
bool dfs(int u)
{
    for(int i=0;i<n;i++)
        if(!vis[i] && G[u][i])
        {
            vis[i]=1;
            if(match[i]<0 || dfs(match[i]))
            {
                match[i]=u;
                return 1;
            }
        }
    return 0;
}

int main()
{
	readint(n),readint(m);
	for(int i=0;i<n;++i)
		for(int j=0;j<m;++j)
			readint(a[i][j]),--a[i][j];
	for(int j=m-1;j>=0;--j)
	{
		memset(G,0,sizeof(G));
		for(int i=0;i<n;++i)
			for(int k=0;k<=j;++k)
				G[i][a[i][k]/m]=1;
		memset(match,-1,sizeof(match));
		for(int i=0;i<n;++i)
		{
			memset(vis,0,sizeof(vis));
			assert(dfs(i));
		}
		for(int i=0;i<n;++i)p[match[i]]=i;
		for(int i=0;i<n;++i)
			for(int k=0;k<j;++k)
				if(a[i][k]/m==p[i])
				{
					swap(a[i][k],a[i][j]);
					break;
				}
	}
	for(int i=0;i<n;++i)
	{
		for(int j=0;j<m;++j)
			printf("%d ",a[i][j]+1);
		putchar('\n');
	}
	for(int j=0;j<m;++j)
	{
		for(int i=0;i<n;++i)p[i]=a[i][j];
		sort(p,p+n);
		for(int i=0;i<n;++i)a[i][j]=p[i];
	}
	for(int i=0;i<n;++i)
	{
		for(int j=0;j<m;++j)
			printf("%d ",a[i][j]+1);
		putchar('\n');
	}
	return 0;
}

Measured memory_bytes: 384
# https://atcoder.jp/contests/cf16-final/tasks/codefestival_2016_final_b

n = gets.to_i
res = []
current_sum = 0
1.upto(n) do |i|
  res << i
  current_sum += i
  break if current_sum >= n
end
res.delete(current_sum - n)
puts res

Measured memory_bytes: 1788
#include <bits/stdc++.h>
#define IO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
using namespace std;
int n,m;
priority_queue<int, vector<int>, greater<int> > pq;
vector<pair<int,int> > x;

void solve(){
long long cnt = 0;
while(pq.size()){
    cnt+=pq.top();
    pq.pop();
}
cout<<cnt;
exit(0);
}

int main()
{
    IO;
    cin>>n>>m;
    for(int i=0,a;i<n;i++){
        cin>>a;
        pq.push(a);
    }
    for(int i=0,a,b;i<m;i++){
        cin>>a>>b;
        x.push_back({b,a});
    }
    sort(x.rbegin(),x.rend());
    for(int i=0;i<m;i++){
        int mx = x[i].first;
        int cnt = x[i].second;
        if(pq.top()>=mx) solve();
        while((pq.size() && cnt) && (pq.top()<mx) ){
            pq.pop();
            pq.push(mx);
            cnt--;
        }
    }
    solve();
    return 0;
}


Measured memory_bytes: 1784
#include <iostream>
#include <string>
#include <cstring>
#include <vector>
#include <algorithm>
#include <set>
#include <stack>
#include <deque>
#include <cmath>
#include <map>
using namespace std;
using ll = long long;
#define rep(i, n) for (ll i = 0; i < n; i++)
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

int main() {
    string s;
    cin >> s;
    int n = s.size();
    rep(i, n) {
        for (int j = i; j <= n; j++) {
            string t = s;
            t.erase(t.begin()+i, t.begin()+j);
            if (t == "keyence") {
                cout << "YES\n";
                return 0;
            }
        }
    }
    cout << "NO\n";
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define fi first
#define se second
typedef pair<int,int> P;
#define Mod 1000000007


#define MAX_N 10101

int par[MAX_N];
int urank[MAX_N];

void init(int n){
    for(int i=0;i<n;i++){
        par[i]=i;
        urank[i]=0;
    }
}

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

void unite(int x,int y){
    x=find(x);
    y=find(y);
    if(x==y) return;
    if(urank[x]<urank[y]){
        par[x]=y;
    } else{
        par[y]=x;
        if(urank[x]==urank[y]) urank[x]++;
    }
}

bool same(int x,int y){
    return find(x)==find(y);
}


int main(){
    init(10101);
    int n,q;
    cin>>n>>q;
    int i,j,k;
    int x,y,z;
    for(i=0;i<q;i++){
        cin>>x>>y>>z;
        if(x==0) unite(y,z);
        else {
            if(same(y,z)) cout<<1<<endl;
            else cout<<0<<endl;
        }
    }
    
    return 0;
}


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

// types
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
typedef vector<ll> vll;

// macros
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define FI first
#define SE second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define REP1(i,n) for(int i=1;i<((int)n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define PB push_back
#define EB emplace_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL

// constants
const int inf = 1e9;
const ll linf = 1LL << 50;
const double eps = 1e-10;
const int MOD = 1e9 + 7;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};


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

  ll n,k;
  cin >> n >> k;

  vll a(n), f(n);
  REP(i, n)
    cin >> a[i];

  REP(i, n){
    cin >> f[i];
  }

  sort(a.begin(), a.end());
  sort(f.begin(), f.end(), greater<ll>());

  auto checkX = [&](ll x){
    ll cnt = 0;
    REP(i, n)
      cnt += max(a[i]-x/f[i], 0LL);

    return cnt<=k;
  };


  ll ok=1000000000000;
  ll ng=-1;
  while(abs(ok-ng)>1){
    ll mid = (ok+ng)/2;
    if(checkX(mid))
      ok = mid;
    else
      ng = mid;
  }

  cout << ok << endl;


}


Measured memory_bytes: 3456
#include <bits/stdc++.h>
using namespace std;
int h[200001],a[200001];
long long t[800001];
long long maxquery(int index,int lb,int rb,int lq,int rq)
{
    if((lb==lq&&rb==rq)||lb==rb)
	return t[index];
    int mid=(lb+rb)/2;
    long long maxx=0;
    if(rq<=mid)
	maxx=max(maxx,maxquery(index*2,lb,mid,lq,rq));
    else if(lq>mid)
	maxx=max(maxx,maxquery(index*2+1,mid+1,rb,lq,rq));
    else
    {
	maxx=max(maxx,maxquery(index*2,lb,mid,lq,mid));
	maxx=max(maxx,maxquery(index*2+1,mid+1,rb,mid+1,rq));
    }
    return maxx;
}
void update(int index,int lb,int rb,int ld,long long value)
{
    if(lb==rb&&lb==ld)
    {
	t[index]=max(t[index],value);
	return;
    }
    int mid=(lb+rb)/2;
    if(ld<=mid)
    {
	update(index*2,lb,mid,ld,value);
	t[index]=max(t[index],t[index*2]);
    }
    else
    {
	update(index*2+1,mid+1,rb,ld,value);
	t[index]=max(t[index],t[index*2+1]);
    }
}
int main()
{
    int n,i;
    long long tmp;
    scanf("%d",&n);
    for(i=1;i<=n;i++)
	scanf("%d",&h[i]);
    for(i=1;i<=n;i++)
	scanf("%d",&a[i]);
    for(i=1;i<=n;i++)
     	update(1,1,n,h[i],maxquery(1,1,n,1,h[i]-1)+a[i]);
    printf("%lld",t[1]);
    return 0;
}

Measured memory_bytes: 7936
<?php
list($a,$b)=explode(" ",trim(fgets(STDIN)));
$s=trim(fgets(STDIN));
if($s[$a]!="-"){
  echo "No";
}else{
  $s[$a]=1;
  $i=0;
  while($i<$a+$b+1){
    if($s[$i]=="-"){
      echo "No";
      exit;
    }
    ++$i;
  }
  echo "Yes";
}

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

int N, A[100005], target[100005];
long long B[100005];
long long ans[100005];
pair<int, int> P[100005];
set<int> S1;
stack< pair<int, int> > S;
bool killed[100005];

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

int main() {
	scanf("%d", &N);
	for (int i = 0; i < N; i++) scanf("%d", &A[i]);
	for (int i = 0; i < N; i++) P[i] = make_pair(A[i], i);
	sort(P, P + N, cmp);
	sort(A, A + N);
	long long cur = 0;
	for (int i = 0; i < N; i++) {
		cur += A[i];
		B[i] = cur;
	}
	memset(target, 0, sizeof(target));
	long long ans1 = 0;
	for (int i = 0; i < N;i++) ans1 += A[i];
	S.push(P[N-1]);
	for (int i = N-2; i >= 0; i--) {
		while (!S.empty() && S.top().second > P[i].second) S.pop();
		if (!S.empty()) target[i] = S.top().first;
		else target[i] = 0;
		S.push(P[i]);
	}
	//for (int i = 0; i < N; i++) printf("%d: %d\n", P[i].second, target[i]);
	
	int curmin = 1000000005;
	long long prev = 0;
	for (int i = 0; i < N; i++) {
		if (target[i] >= curmin) continue;
		//printf("targetting %d\n", target[i]);
		curmin = target[i];
		int pos = lower_bound(A, A + N, target[i]) - A;
		long long preans = B[N - 1] - ((pos == 0) ? 0 : B[pos - 1]) - (long long)target[i] * (N - pos);
		//printf("preans: %lld\n", preans);
		ans[P[i].second] = preans - prev;
		prev = preans;
	}
	
	for (int i = 0; i < N; i++) printf("%lld\n", ans[i]);
}


Measured memory_bytes: 4992
fn main() {
    let mut n = String::new();
    std::io::stdin().read_line(&mut n).unwrap();
    let n: u32 = n.trim().parse().unwrap();
    let mut i = 0;
    let mut txy = Vec::new();
    while ( i < n ) {
        let mut input = String::new();
        std::io::stdin().read_line(&mut input).unwrap();
        let tmp: Vec<i32> = input.trim().split_whitespace()
            .map(|x| x.parse().unwrap()).collect();
        txy.push(tmp);
        i += 1;
    }
    let mut flag = 0;
    let mut ans = 0;
    let mut i = 0;
    while ( i < n ) {
        let mut d = 0;
        let mut j = 0;
        if ( i == 0 ) {
            d = txy[i as usize][1].abs() + txy[i as usize][2].abs();
            j = txy[i as usize][0];
        } else {
            d = (txy[i as usize][1] - txy[(i - 1) as usize][1]).abs() + (txy[i as usize][2] - txy[(i - 1) as usize][2]).abs();
            j = txy[i as usize][0] - txy[(i - 1) as usize][0];
        }
        if ( j < d ) {
            flag = 1; 
        }
        if ( j % 2 == 1 ) {
            if ( d % 2 == 1 && flag != 1 ) {
                ans = 1;
            } else {
                flag = 1;
            }
        } else if ( j % 2 == 0 ){
            if ( d % 2 == 0 && flag != 1 ) {
                ans = 1;
            } else {
                flag = 1;
            }
        }
        i += 1;
    }
    if ( ans == 1 && flag != 1 ) {
        println!("Yes");
    } else {
        println!("No");
    }
}

Measured memory_bytes: 9720
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <cassert>
#include <set>
using namespace std;
using ll = long long;
const int INF = 1<<30;
const int MOD = (int)1e9 + 7;
const int MAX_N = (int)1e5 + 5;
#define debug(x) cout << #x << ": " << x << endl
template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2>& p) { os << p.first << " " << p.second; return os; }
template<typename T>
ostream &operator<<(ostream &os, const vector<T> &v) { for(int i = 0; i < (int) v.size(); i++) os << v[i] << (i + 1 != v.size() ? " " : ""); return os; }

template<class Type> class UnionFind
{
    private:
        vector<Type> data;
        int groups;
    public:
        UnionFind(int sz)
        {
            data.assign(sz, -1);
            this->groups = sz;
        }
        bool unite(Type x, Type y)
        {
            x = find(x), y = find(y);
            if (x == y) return (false);
            if (data[x] > data[y]) swap(x, y);
            data[x] += data[y];
            data[y] = x;
            groups--;
            return (true);
        }
        Type find(Type k) {
            if (data[k] < 0) return (k);
            return (data[k] = find(data[k]));
        }
        Type size(Type k) { return (-data[find(k)]); }
        int getGroups() { return this->groups; }
};

void solve()
{
    int n, m, k; cin >> n >> m >> k;
    vector<int> ans(n);
    UnionFind<int> uf(MAX_N);
    vector<pair<int, int>> v;
    for(int i = 0; i < m; i++)
    {
        int a, b; cin >> a >> b;
        a--, b--;
        uf.unite(a, b);
        v.push_back(make_pair(a, b));
    }
    for(int i = 0; i < n; i++)
    {
        ans[i] = uf.size(i) - 1;
    }
    for(int i = 0; i < k; i++)
    {
        int c, d; cin >> c >> d;
        c--, d--;
        if(uf.find(c) == uf.find(d))
        {
            ans[c]--;
            ans[d]--;
        }
    }
    for(int i = 0; i < v.size(); i++)
    {
        ans[v[i].first]--;
        ans[v[i].second]--;
    }
    for(int i = 0; i < n; i++)
    {
        cout << ans[i] << " ";
    }
    cout << endl;
}

signed main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    solve();
    return 0;
}

Measured memory_bytes: 2548
#include<iostream>
#include<vector>
#include<string>
#include<array>
#include<algorithm>
#include<list>
#include<cmath>
#include<iomanip>
#include<queue>
#include<functional>
#include<climits>
#include<iterator>
#include<unordered_set>
#include<unordered_map>
#include<map>
#include<set>
#include<typeinfo>
using namespace std;

const double pi=4*atan(1.0);

constexpr long long mod=static_cast<long long>(1e9+7);

using cWeightEdges=vector<vector<pair<int,int>>>;
using cEdges=vector<vector<int>>;

int main() {
	int N,A,B;
	cin>>N>>A>>B;
	string str;
	cin>>str;

	int a=0;
	int b=0;
	for(const auto& val:str){
		if(val=='a'){
			if(a+b<A+B){
				cout<<"Yes"<<endl;
				++a;
			}
			else{
				cout<<"No"<<endl;
			}
		}
		else if(val=='b'){
			if(a+b<A+B && b<B){
				cout<<"Yes"<<endl;
				++b;
			}
			else{
				cout<<"No"<<endl;
			}
		}
		else{
			cout<<"No"<<endl;
		}
	}

//	system("pause");
	return 0;
}

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

using namespace std;

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

#define F first
#define S second

int main(){
  int a,p;
  scanf("%d %d",&a,&p);
  printf("%d\n",(a*3+p)/2);
  
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
    using namespace std;
    
    
    int main(){
        string s;
        string ss , s2;
        ss = "KIHBR";
        bool flg = true;
        int t = 0;
        cin >> s;
        s2 = "AKIHABARA";
        int t2 = 0;
        if(s.length() > s2.length()){
            cout << "NO" << endl;
            return 0;
        }
        if(s.length() == s2.length()){
            if(s == s2){
                cout << "YES" << endl;
            }else{
                cout << "NO" << endl;
            }
            return 0;
        }
        for(int i = 0; i < s.length() ; i++){
            //cout << s[i] << ":" << ss[t] << endl;
            if(s[i] == ss[t]){
                t += 1;
            }
            if(s[i] != 'A'){
                t2 += 1;
            }
        }
        if(t != 5 || t2 > 5){
            cout << "NO" << endl;
            return 0;
        }
        for(int i = 0; i < s.length() - 1 ; i++){
            if(s[i] == 'A' && s[i+1] == 'A' ){
                flg = false;
            }
            if(s[i] == 'K' && s[i+1] == 'A' ){
                flg = false;
            }
            if(s[i] == 'A' && s[i+1] == 'I' ){
                flg = false;
            }
            if(s[i] == 'I' && s[i+1] == 'A' ){
                flg = false;
            }
            if(s[i] == 'A' && s[i+1] == 'H' ){
                flg = false;
            }
        }
        
        if(flg){
            cout << "YES" << endl;
        }else{
            cout << "NO" << endl;
        }
        
        return 0;
    }

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


int main() {
  int n;
  cin >> n;
  vector<int> a(n), b;
  rep(i, n) cin >> a[i];
  reverse(all(a));
  for (int i = 0; i < n; i += 2) {
    b.push_back(a[i]);
  }
  reverse(all(a));
  for (int i = n%2 ; i < n; i += 2) {
    b.push_back(a[i]);
  }
  rep(i, n) {
    printf("%d ", b[i]);
  }
  cout << endl;
  return 0;
}

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

int main(){
  int N;cin>>N;
  string s;cin>>s;
  //int r=(int)'z';
  for(int i=0;i<s.size();i++){
    if(s[i]+N > 'Z'){
      s[i]+=N-26;
     // cout<<"!";
    }
    else
      s[i]+=N;
  }
  
  cout<<s;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int N = 100005;
long long n,a[N],b[N],c[N],dp[N][4],k;
int main(){
    cin >> n;
    for(int i=1;i<=n;i++){ cin>>a[i]>>b[i]>>c[i]; }
    for(int i=1;i<=n;i++){
    	dp[i][1]=max( dp[i-1][2], dp[i-1][3]) + a[i];
    	dp[i][2]=max( dp[i-1][1], dp[i-1][3]) + b[i];
    	dp[i][3]=max( dp[i-1][1], dp[i-1][2]) + c[i];
	}
	cout<<max(dp[n][1],max(dp[n][2],dp[n][3]))<<'\n';
}   

Measured memory_bytes: 9100
def main():
    n, k = map(int, input().split())
    h = tuple(map(int, input().split()))
    INF = 10 ** 9
    dp = [INF] * n
    dp[0] = 0
    for i in range(n):
        for j in range(1, k + 1):
            i_j = i + j
            if i_j < n:
                x = dp[i] + abs(h[i] - h[i_j])
                if dp[i_j] > x:
                    dp[i_j] = x
    print(dp[-1])


if __name__ == "__main__":
    main()


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

using namespace std;

#define debug(args...) fprintf(stderr,args)
#define pb push_back
#define mp make_pair

const int N = 5e6 + 5;
const int inf = 1791791791;
const int mod = 1e9+7;

typedef long long ll;

int p[N];

int main() {
	int n; scanf("%d", &n);
	for (int i=2;i<=n;i++) {
		int pi = i;
		for (int j=2;pi != 1;j++) {
			while (pi%j == 0) {
				pi /= j;
				p[j]++;
			}
		}
	}
	long long resp = 1;
	for (int i=2;i<=n;i++) {
		resp *= (long long)(p[i] + 1);
		resp %= mod;
	}
	printf("%lld\n", resp);
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
using i64 = long long;

int main() {
    int n;
    std::cin >> n;
    std::vector<int> cnt(n);
    i64 ret = 0;
    for (int i = 0; i < n; i++) {
        int a;
        std::cin >> a;
        if (i >= a) ret += cnt[i - a];
        if (a + i < n) cnt[a + i]++;
    }

    std::cout << ret << std::endl;
}


Measured memory_bytes: 4048
#include <algorithm>
#include <cstdio>
#include <climits>
#include <vector>
using namespace std;

int main() {
    while(true) {
        int n,m,h,k; scanf("%d%d%d%d", &n, &m, &h, &k);
        if(n==0) break;
        static int botpt[1000];
        for(int i = 0; i < n; i++) scanf("%d", botpt+i);
        static pair<int,int> bar[100000];
        for(int i = 0; i < m; i++) {
            int a,b; scanf("%d%d", &a, &b);
            bar[i].first = b;
            bar[i].second = a-1;
        }
        sort(bar, bar+m);
        static int num[1000];
        static int markL[100000], markR[100000];
        for(int i = 0; i < n; i++) num[i]=i;
        for(int i = 0; i < m; i++) {
            int pos = bar[i].second;
            markL[i] = num[pos];
            markR[i] = num[pos+1];
            swap(num[pos], num[pos+1]);
        }
        static int toppt[1000];
        for(int i = 0; i < n; i++) {
            toppt[num[i]] = botpt[i];
        }
        int basesum = 0;
        for(int i = 0; i < k; i++) basesum += toppt[i];
        int min_dif = 0;
        for(int i = 0; i < m; i++) {
            if(markL[i]<k && markR[i]>=k) min_dif=min(min_dif, toppt[markR[i]]-toppt[markL[i]]);
            if(markL[i]>=k && markR[i]<k) min_dif=min(min_dif, toppt[markL[i]]-toppt[markR[i]]);
        }
        printf("%d\n", basesum+min_dif);
    }
    return 0;
}

Measured memory_bytes: 1636
#include <bits/stdc++.h>
#define rep(i,a,b) for(ll i=ll(a);i<ll(b);i++)
#define irep(i,a,b) for(ll i=ll(a);i>=ll(b);i--)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
#define pb push_back
#define mp make_pair
#define F .first
#define S .second 
#define pll pair<ll,ll>
using ll=long long;
using ld=long double;
const ll INF = 1LL<<60;
const ll mod=1e9+7;
using namespace std;
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }

long long modpow(ll a, ll b) {
    ll res=1;
    while (b) {
        if (b&1)res=res*a%mod;
        a=a*a%mod;
        b>>=1;
    }
    return res;
}

int main(){
    ll n,ans=0;
    cin>>n;
    if(n==1)ans=0;
    else{
        ll tmp=n-2;
        ans=(modpow(10,n)+modpow(8,n))%mod;
        ll z=2*modpow(9,n)%mod;
        ans-=z;
    }
    cout<<(mod+ans)%mod;
}



Measured memory_bytes: 3628
def main
  n = gets.chomp.to_i
  digits = n.to_s.length
  sum = 0
  sum += (n - (10**(digits-1)) + 1) if digits % 2 == 1
  d = digits - 1
  while d > 0 do
    if d % 2 == 0
      d -= 1
      next
    end
    sum += (10**d - 10**(d-1))
    d -= 1
  end
  puts sum
end

main if $0 == __FILE__

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

typedef long long i64;
const int NMAX = 200010;

class MinBatch {
    typedef pair <i64, i64> Line;
    static const int N = 1000010;
    Line aint[4 * N], val;
    int poz;

    i64 eval(Line & l, int where) {
        return l.first * where + l.second;
    }

    void update(int nod, int st, int dr) {
        int mij = (st + dr) / 2;
        if (eval(aint[nod], mij) > eval(val, mij))
            swap(val, aint[nod]);
        if (st == dr)
            return;

        if (eval(aint[nod], st) > eval(val, st))
            update(2 * nod, st, (st + dr) / 2);
        else if (eval(aint[nod], dr) > eval(val, dr))
            update(2 * nod + 1, (st + dr) / 2 + 1, dr);
    }

    i64 query(int nod, int st, int dr) {
        if (st > poz || dr < poz)
            return 1e18;
        if (st == dr)
            return eval(aint[nod], poz);
        return min(eval(aint[nod], poz), min(
            query(2 * nod, st, (st + dr) / 2),
            query(2 * nod + 1, (st + dr) / 2 + 1, dr)));
    }

public:

    void Update(Line l) {
        /// dreapta ax + b
        val = l;
        update(1, 0, N);
    }

    i64 Query(i64 x) {
        /// valoarea minima pt un x
        poz = x;
        return query(1, 0, N);
    }

    MinBatch() {
        fill(aint, aint + 4 * N, make_pair(0, (i64)1e18));
    }
} Batch;

/*
    dp[i] = min dp[j] + C + (h[i] - h[j]) ^ 2
    dp[i] = h[i]^2+C + min (-2*h[j]) * h[i] + (h[j]^2+dp[j])

    -> vreau sa fac un batch de minime cu drepte care se adauga, cu pantele din ce in ce mai mici

*/
int main()
{
    int n;
    i64 C;
    scanf("%d%lld", &n, &C);

    i64 dp;
    for (int i = 1; i <= n; i++) {
        int h;
        scanf("%d", &h);
        dp = 0;
        if (i != 1)
            dp = C + 1LL * h * h + Batch.Query(h);

        Batch.Update(make_pair(-2LL * h, 1LL * h * h + dp));
    }

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

    return 0;
}


Measured memory_bytes: 62720
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
import java.util.Map.Entry;

/**
 * https://abc051.contest.atcoder.jp/tasks/abc051_d
 */
public class Main {

	public static void main(String[] args) {
		
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int M = sc.nextInt();
		Node[] nodes = new Node[N];
		for(int i=0; i<N; i++) nodes[i] = new Node(i);
		for(int i=0; i<M; i++){
			Node a = nodes[sc.nextInt()-1];
			Node b = nodes[sc.nextInt()-1];
			int c = sc.nextInt();
			a.neighbor.put(b, c);
			b.neighbor.put(a, c);
		}
		sc.close();
		
		long costs[][] = getAllPairsMinimumCost(nodes, Long.MAX_VALUE);
		long ans = 0;
		for(int i=0; i<N; i++){
			Node n = nodes[i];
			for(Entry<Node, Integer> e: n.neighbor.entrySet()){
				Node nn = e.getKey();
				int c = e.getValue();
				if(costs[n.id][nn.id]<c){
					ans++;
				}
			}
		}
		
		System.out.println(ans/2);

	}
	
	static class Node{
		int id;
		Map<Node,Integer> neighbor = new HashMap<>();
		int status = -1;
		Node(int id){
			this.id = id;
		}
	}
	
	static long[][] getAllPairsMinimumCost(Node[] nodeList, long inf){
		final long[][] costs = new long[nodeList.length][nodeList.length];
		for(int i=0; i<nodeList.length; i++)
			for(int j=0; j<nodeList.length; j++)
				costs[i][j] = i==j ? 0 : inf;
		for(Node node: nodeList)
			for(Entry<Node,Integer> n:node.neighbor.entrySet())
				costs[node.id][n.getKey().id] = n.getValue();
		for(int k=0; k<nodeList.length; k++){
			for(int i=0; i<nodeList.length; i++){
				if(costs[i][k]==inf) continue;
				for(int j=0; j<nodeList.length; j++){
					if(costs[k][j]==inf) continue;
					costs[i][j] = Math.min(costs[i][j], costs[i][k]+costs[k][j]);
				}
			}
		}
		return costs;
	}

}

Measured memory_bytes: 26008
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define ALL(V) (V).begin(), (V).end()
#define ALLR(V) (V).rbegin(), (V).rend()

template <typename T> using V = vector<T>;
template <typename T> using VV = V<V<T>>;
template <typename T, typename U> using P = pair<T, U>;
using ll = int64_t;
using PLL = P<ll, ll>;

template <typename T> const T& var_min(const T &t) { return t; }
template <typename T> const T& var_max(const T &t) { return t; }
template <typename Head, typename... Tail> const Head& var_min(const Head &head, const Tail&... tail) { return min(head, var_min(tail...)); }
template <typename Head, typename... Tail> const Head& var_max(const Head &head, const Tail&... tail) { return max(head, var_max(tail...)); }
template <typename T, typename... Tail> void chmin(T &t, const Tail&... tail) { t = var_min(t, tail...); }
template <typename T, typename... Tail> void chmax(T &t, const Tail&... tail) { t = var_max(t, tail...); }

void init_io() {
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(30);
}

//#define DEBUGGING
#ifdef DEBUGGING
#include "../debug.cpp"
#else
#define DEBUG(...) 0
#endif

const ll MOD = 1e9 + 7;
VV<ll> init_dp(310, V<ll>(310, 0));
VV<PLL> rests(310);

void check(VV<ll> &dp, ll idx) {
    for(const auto &ele : rests[idx]) {
        ll l, x, r = idx;
        tie(l, x) = ele;
        for(ll i1 = 0; i1 <= idx; i1++) {
            for(ll i2 = 0; i2 <= idx; i2++) {
                ll kinds = 1;
                kinds += (l <= i1 && i1 <= r);
                kinds += (l <= i2 && i2 <= r);
                if(kinds != x) dp[i1][i2] = 0;
            }
        }
    }
}

int main() {
    init_io();
    ll N, M;
    cin >> N >> M;
    for(ll i = 0; i < M; i++) {
        ll l, r, x;
        cin >> l >> r >> x;
        if(r - l + 1 < x) {
            cout << 0 << endl;
            return 0;
        }
        rests[r].emplace_back(l, x);
    }

    auto dp = init_dp;
    dp[0][0] = 1;
    for(ll i = 2; i <= N; i++) {
        auto ndp = init_dp;
        for(ll i1 = 0; i1 < i; i1++) {
            for(ll i2 = 0; i2 < i; i2++) {
                if(i1 && i1 == i2) continue;
                (ndp[i1][i2] += dp[i1][i2]) %= MOD;
                (ndp[i2][i - 1] += dp[i1][i2]) %= MOD;
                (ndp[i - 1][i1] += dp[i1][i2]) %= MOD;
            }
        }
        check(ndp, i);
        dp = move(ndp);
#ifdef DEBUGGING
        for(ll j = 0; j <= i; j++) for(ll k = 0; k <= i; k++) {
            auto t = make_pair(PLL(j, k), dp[j][k]);
            DEBUG(t);
        }
        cout << endl;
#endif
    }
    ll ans = 0;
    for(ll i = 0; i < 310; i++) for(ll j = 0; j < 310; j++) (ans += dp[i][j]) %= MOD;
    cout << ans * 3 % MOD << endl;
    return 0;
}


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

int main() {
    int n, m, x, y;
    cin >> n >> m >> x >> y;
    int mx = -1001001001;
    for (int i = 0; i < n; ++i) {
        int p;
        cin >> p;
        mx = max(mx, p);
    }
    int my = 1001001001;
    for (int j = 0; j < m; ++j) {
        int p;
        cin >> p;
        my = min(my, p);
    }
    bool ans = true;
    for (int z = x + 1; z <= y; ++z) {
        if (mx < z && my >= z) {
            ans = false;
            break;
        }
    }
    cout << (ans ? "War" : "No War") << endl;
}


Measured memory_bytes: 256
import java.util.*;
import java.lang.Math.*;
public class Main {
    public static void main(String[] args) {
      Scanner sc = new Scanner(System.in);
      int A = sc.nextInt();
      int B = sc.nextInt();
      int max=-1000000;
      max=Math.max(A+B,A-B);
      max=Math.max(max,A*B);
      System.out.println(max);
   }
}

Measured memory_bytes: 21844
import java.util.*;
     
    public class Main {
        public static void main(String[] args){
            // Your code here!
            Scanner sc = new Scanner(System.in);
            
            int N = sc.nextInt();
            int A = sc.nextInt();
            
            if((N % 500) <= A){
                System.out.println("Yes");
            }else{
                System.out.println("No");
            }
        }
    }


Measured memory_bytes: 27072
#include <cmath>
#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

int main()
{
	for(int n,y;cin>>n>>y;){
		vector<int> bs(n);
		vector<double> vs(n);
		for(int i=0;i<n;i++){
			int r,t; cin>>bs[i]>>r>>t;
			if(t==1)
				vs[i]=1+y*r*0.01;
			else
				vs[i]=pow(1+r*0.01,y);
		}
		int i=max_element(vs.begin(),vs.end())-vs.begin();
		cout<<bs[i]<<endl;
	}
	return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <vector>

using namespace std;

typedef long long ll;
const int INFTY = 1001001001;

int digits(ll b){
    int d = 0;
    while(b != 0){
        b /= 10;
        ++d;
    }
    return d;
}

int main()
{
    ll N;
    cin >> N;
    int ans = INFTY, b;
    for(ll i=1;i*i<=N;++i){
        if(N % i == 0){
            b = digits(N / i);
            ans = min(ans, b);
        }
    }
    cout << ans << endl;
}


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

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

lis = [0] * 41

for i in range(N):
    for j in range(41):
        if A[i] & (2**j) != 0:
            lis[j] += 1


now = 0
ans = 0
#print (lis)

for i in range(41):

    i = 40-i

    if lis[i] >= N / 2:
        ans += (2**i)*lis[i]

    else:
        if now + 2**i <= K:
            now += 2**i
            ans += (2**i) * (N - lis[i])
        else:
            ans += (2**i) * lis[i]

    #print (ans)

print (ans)


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

#define IOS std::cin.tie(0);std::ios_base::sync_with_stdio(false)

#define ll      long long
#define Fi      first
#define Se      second
#define Pb      push_back
#define vi      vector<int>
#define vp      vector<pair<int,int>>
#define vvi     vector<vector<int>>
#define vvp     vector<vector<pair<int,int>>>
using Graph  =  vector<vector<int>>;

#define sz(x) (int)x.size()
#define all(v) v.begin(),v.end()
#define output_s(s) printf("%s\n",(s).c_str())
#define END cout<<"\n"

#define rep(i,n)        for(int i=0;i<(int)(n);i++)
#define Rep(i,n,m)      for(int i=(int)(n);i<(int)(m);i++)
#define RepS(i,n,m)     for(int i=(int)(n);i<=(int)(m);i++)
#define RRepS(i,n,m)    for(int i=(int)(n);i>=(int)(m);i--)
#define SRepS(i,n,m)    for(int i=(int)(n);i*i<=(int)(m);i++)
#define RepA(x)         for(auto &item:(x))

void CINT(){} //@shibh308's template
template<class Head,class... Tail> void CINT(Head&& head,Tail&&... tail){cin>>head; CINT(move(tail)...);}    
#define CIN(...) int __VA_ARGS__;CINT(__VA_ARGS__)
#define LCIN(...) ll __VA_ARGS__;CINT(__VA_ARGS__)
#define SCIN(...) string __VA_ARGS__;CINT(__VA_ARGS__)
#define VCIN(x) for(auto &item:x) cin>>item

void OUT(){}
template<class Head,class...Tail> void OUT(Head&& head,Tail&&...tail){cout<<head<<(sizeof...(tail)?" ":"\n"); OUT(move(tail)...);}
#define COUT(...) OUT(__VA_ARGS__)

template<typename TypeInt>TypeInt GCD(TypeInt a,TypeInt b){return a%b==0?b:GCD(b,a%b);} //最大公約数
template<typename TypeInt>TypeInt LCM(TypeInt a,TypeInt b){return a*b/GCD(a,b);} //最小公倍数
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>bool chmin(T &a,const T &b){if(b<a){a=b;return true;}return false;}
template<class T>bool comp(T a,T b){return abs(a)<abs(b);} //比較関数

void YES(bool f){printf(f?"YES\n":"NO\n");}
void Yes(bool f){printf(f?"Yes\n":"No\n");}
void Possible(bool f){printf(f?"Possible\n":"Impossible\n");}
void POSSIBLE(bool f){printf(f?"POSSIBLE\n":"IMPOSSIBLE\n");}

//----------------------library------------------------//

//const int dx[4]={1,0,-1,0};
//const int dy[4]={0,1,0,-1};
const int dx[8]={1,0,-1,0,1,-1,-1,1};
const int dy[8]={0,1,0,-1,1,1,-1,-1};
const int NMAX = 55;
const int INF = 1e9;
const int MOD = 1e9+7;
bool flag;

//----------------------Global-------------------------//

signed main(){
    CIN(N,K);
    map<int,int>mp;
    RepS(i,1,N)mp[i]=0;
    rep(i,K){
        int d;cin>>d;
        rep(i,d){
            int a;cin>>a;
            mp[a]++;
        }
    }
    int ans=0;
    RepA(mp)if(item.second==0)ans++;
    printf("%d\n",ans);

    return 0;
}

Measured memory_bytes: 3696
/// kazuki08
/*
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define int long long
typedef long long ll;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef vector<pi> vpi;
#define ar array
//#define inf 1000000000
#define mod 1000000007
#define dmp(x) cerr<<"line "<<__LINE__<<" "<<#x<<":"<<x<<endl
#define fs first
#define sc second
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define mt make_tuple
#define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){
    return o<<"("<<p.fs<<","<<p.sc<<")";
}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){
    o<<"{";
    for(const T& v:vc) o<<v<<",";
    o<<"}";
    return o;
}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const int MAXN = 202000;
int n,m,a[MAXN],sum,ans;
map<int,int> mp;

signed main(){
IOS;
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
  
  cin >> n >> m;
  mp[0]++;
  for(int i=1;i<=n;i++){
    cin >> a[i];
    sum+=a[i];
    sum%=m;
    ans+=mp[sum];
    mp[sum]++;
  }
  cout << ans << endl;


return 0;
}
///....


Measured memory_bytes: 4992