akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#include<math.h>
int f[100010],n,h[100010];
int fuck(int i)
{
    if(f[i]==-1)
    {
        if(i==n-1)
        return f[i]=0;
        else if(i==n-2)
        return f[i]=fabs(h[n-1]-h[n-2]);
        else
        return f[i]=fmin(fabs(h[i]-h[i+1])+fuck(i+1),fabs(h[i]-h[i+2])+fuck(i+2));
    }
    else 
    return f[i];
}
int main()
{
    int i,ans;
    scanf("%d",&n);
    for(i=0;i<n;i++)
    {
        scanf("%d",&h[i]);
        f[i]=-1;
    }
    ans=fuck(0);
    printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 4096
using System;
using System.Linq;
using System.Collections.Generic;

namespace Aojx
{
    class MainClass
    {
        public static void Main(string[] args)
        {
            string s;
            while ((s = Console.ReadLine()) != null)
            {
                List<int> row = s.Split(',').Select(e => int.Parse(e)).ToList();
                double l = row.GetRange(0, 10).Sum();
                double x = row[10] * l / (row[10] + row[11]);

                int p = 0;
                for (int i = 1; i < 10; i++)
                {
                    p += row[i - 1];
                    if (p < x && x <= p + row[i])
                    {
                        Console.WriteLine(i + 1);
                    }
                }
            }
        }
    }
}

Measured memory_bytes: 5924
#include <bits/stdc++.h>
#define rep(i, to) for (int i = 0; i < (to); i++)
#define rrep(i, to) for (int i = to - 1; i >= 0; i--)
#define repf(i, from, to) for (int i = (from); i < (to); i++)
#define unless(cond) if (!(cond))
using namespace std;
using ll = long long;
template <typename T>
using V = vector<T>;
template <typename T, typename U>
using P = pair<T, U>;

int main() {
  int n, k;
  cin >> n >> k;
  V<int> a;
  a.resize(n);
  rep(i, n) {
    cin >> a[i];
  }

  repf(i, k, n) {
    int prev_first = i - k;
    if(prev_first < 0) {
      continue;
    }

    if(a[prev_first] < a[i]) {
      cout << "Yes" << endl;
    } else {
      cout << "No" << endl;
    }
  }
}


Measured memory_bytes: 4044
#include<stdio.h>

int main(){
	int a,b,d,r;
	double f;
	scanf("%d",&a);
	scanf("%d",&b);
	d= a/b;
	r=a%b;
	f=(double)a/b;
	printf("%d %d %lf\n",d,r,f);
	return 0;
}


Measured memory_bytes: 2108
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;

void main()
{
    auto rdx = readln.split.to!(long[]);
    auto r = rdx[0];
    auto D = rdx[1];
    auto x = rdx[2];
    foreach (_; 0..10) {
        x = r*x-D;
        writeln(x);
    }
}

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

//Compiler version g++ 6.3.0

int main()
{
   int a,b,c;
   cin>>a>>b;
   
   if(2*b>a)
   {
     cout<<"0";
   }
   else
   {
     c=a-2*b;
     cout<<c;
   }
}

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

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
//const ll mod = 1000000007;
int x[300];
int y[300];

int main() {
    //cout.precision(10);
    cin.tie(0);
    ios::sync_with_stdio(false);
    while(true) {
        int n;
        cin >> n;
        if(n == 0) break;
        int xmaxi = 0;
        int xmini = 0;
        int ymaxi = 0;
        int ymini = 0;
        for(int i = 1; i < n; i++) {
            int a, b;
            cin >> a >> b;
            x[i] = x[a];
            y[i] = y[a];
            if(b == 0) {
                x[i]--;
            }
            if(b == 1) y[i]--;
            if(b == 2) x[i]++;
            if(b == 3) y[i]++;
            ymaxi = max(ymaxi, y[i]);
            ymini = min(ymini, y[i]);
            xmaxi = max(xmaxi, x[i]);
            xmini = min(xmini, x[i]);
        }
        cout << (xmaxi - xmini + 1) << " " << ymaxi - ymini + 1 << endl;
    }
    return 0;
}


Measured memory_bytes: 3092
ss = input() + '#'

ss = ss.replace('BC', 'Z')

def func(ts):
    n = len(ts)
    nums = [0]*n
    num = 0
    for i in reversed(range(n)):
        if ts[i] == 'Z':
            num += 1
        nums[i] = num
    ans = 0
    for i, (t, num) in enumerate(zip(ts, nums)):
        if t == 'A':
            ans += num
    return ans

ans = 0
iFr = -1
for i, s in enumerate(ss):
    if s == 'A' or s == 'Z':
        if iFr == -1:
            iFr = i
    else:
        if iFr != -1:
            ans += func(ss[iFr:i])
            iFr = -1

print(ans)


Measured memory_bytes: 6432
#include "bits/stdc++.h"

#define MOD 1000000007
#define rep(i, n) for(ll i=0; i < (n); i++)
#define rrep(i, n) for(ll i=(n)-1; i >=0; i--)
#define ALL(v) v.begin(),v.end()
#define rALL(v) v.rbegin(),v.rend()
#define FOR(i, j, k) for(ll i=j;i<k;i++)
#define DUMP(i, v)for(ll i=0;i<v.size();i++)cerr<<v[i]<<" "

using namespace std;
typedef long long int ll;
typedef vector<ll> llvec;
typedef vector<double> dvec;
typedef pair<ll, ll> P;
typedef long double ld;
struct edge{ll x, c;};

ll mod(ll a, ll mod){
  ll res = a%mod;
  if(res<0)res=res + mod;
  return res;
}

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

ll modinv(ll a, ll mod){
  return modpow(a, mod-2, mod);
}

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

bool is_prime(ll n){
  ll i = 2;
  if(n==1)return false;
  if(n==2)return true;
  bool res = true;
  while(i*i <n){
    if(n%i==0){
      res = false;
    }
    i = i+1;
  }

  //if(i==1)res = false;
  if(n%i==0)res=false;
  return res;
}

struct dijkstra{
  ll N;
  llvec d;
  vector<vector<edge>> e;
  dijkstra(ll n){
    N = n;
    //d = llvec(N, 1e18);
    e = vector<vector<edge>>(N);
  }

  void add_edge(ll from, ll to, ll cost){
    e[from].push_back({to, cost});
  }

  void run(ll start){
    priority_queue<P, vector<P>, greater<P>> que;
    que.push({0, start});
    d = llvec(N, 1e18);
    d[start]=0;
    while(!que.empty()){
      P q = que.top();que.pop();
      ll dc = q.first;
      ll x = q.second;
      if(dc>d[x]){
        continue;
      }else{
        for(auto ip: e[x]){
          if(d[ip.x]<=d[x]+ip.c){
            continue;
          }else{
            d[ip.x]= d[x]+ip.c;
            que.push({d[ip.x], ip.x});
          }
        }
      }
    }
  }
  
};


/**************************************
** A main function starts from here  **
***************************************/
int main(){
  string S, T;
  cin >> S >> T;
  map<ll, llvec> smp, tmp;
  set<ll> sst, tst;
  rep(i, S.size()){
    smp[S[i]-'a'].push_back(i);
    sst.insert(S[i]-'a');
  }
  rep(i, T.size()){
    tmp[T[i]-'a'].push_back(i);
    tst.insert(T[i]-'a');
  }

  
  
  ll cnt=0;
  ll cur=-1;
  rep(i, T.size()){
    ll ind = T[i]-'a';
    auto it = upper_bound(ALL(smp[ind]), cur);
    if(it == smp[ind].end()){
      it = lower_bound(ALL(smp[ind]), -1);
      if(it==smp[ind].end()){
        cout << -1 ;
        return 0;
      }
      cnt +=1;
    }
    cur =*it;
    cerr << T[i] << " " << cur << " " << cnt<< endl;
  }


  cout << cnt * S.size() + cur + 1;
  
  
  return 0;
}


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

#pragma GCC optimize "O3"
#define rep(i,a,n) for(long long i=a; i<n; i++)
typedef long long ll;
typedef pair<int,int> P;
const ll MOD = (int)1e9+7;
const ll INF = MOD*MOD;
const double EPS = 1e-9;
const ll powll = 1LL<<1;

/*
while(!frag && cin >> a >>b, a|b)
*/

int main(void){
    int a,b,c; cin >> a >> b >> c;
    int ans = 0;
    rep(i,a,b+1){
        if(i%c==0)ans++;
    }
    cout << ans <<"\n";
}

Measured memory_bytes: 3564
#include<bits/stdc++.h>
using namespace std;
multiset<int>S;
multiset<int>::iterator it;
int A[100001];
int main() {
	int a,i,w=0;
	cin>>a;
	for(i=1;i<=a;i++)cin>>A[i];
	for(i=a;i;i--){
		it=S.upper_bound(A[i]);
		if(it!=S.end())S.erase(it),w++;
		S.insert(A[i]);
	}
	cout<<a-w;
}

Measured memory_bytes: 5376
open System
let readInt () = stdin.ReadLine() |> int

let A = readInt ();
let B = readInt ();
let C = readInt ();
let X = readInt ();

[ for i in [0..A] do
    for j in [0..B] do
        for k in [0..C] do
           yield i * 500 + j * 100 + 50 * k]
|> Seq.sumBy (fun v -> if v = X then 1 else 0)
|> printfn "%d"


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

def main():
    N = int(input())
    # N = 10
    ok = False
    for i in range(1, 10):
        for j in range(1, 10):
            if i*j == N:
                ok = True
                break
        if ok:
            break
    print("Yes" if ok else "No")


if __name__ == "__main__":
    main()

Measured memory_bytes: 9148
import math
from math import gcd,pi,sqrt
INF = float("inf")

import sys
sys.setrecursionlimit(10**6)
import itertools
from collections import Counter,deque
def i_input(): return int(input())
def i_map(): return map(int, input().split())
def i_list(): return list(i_map())
def i_row(N): return [i_input() for _ in range(N)]
def i_row_list(N): return [i_list() for _ in range(N)]
def s_input(): return input()
def s_map(): return input().split()
def s_list(): return list(s_map())
def s_row(N): return [s_input for _ in range(N)]
def s_row_str(N): return [s_list() for _ in range(N)]
def s_row_list(N): return [list(s_input()) for _ in range(N)]


def main():
    w,h,n = i_map()

    up = h
    right = w
    down = 0
    left = 0

    for i in range(n):
        x,y,a = i_map()
        if a == 1:
            left = max(left,x)
        elif a == 2:
            right = min(right, x)
        elif a == 3:
            down = max(down, y)
        else:
            up = min(up, y)
    print(max((up-down),0)*max((right-left),0))

if __name__=="__main__":
    main()


Measured memory_bytes: 9156
#include <cstdio>
#include <algorithm>

using i8 = std::int8_t;
using u8 = std::uint8_t;
using i16 = std::int16_t;
using u16 = std::uint16_t;
using i32 = std::int32_t;
using u32 = std::uint32_t;
using i64 = std::int64_t;
using u64 = std::uint64_t;
using i128 = __int128_t;
using u128 = __uint128_t;
using isize = std::ptrdiff_t;
using usize = std::size_t;


auto main() -> i32 {
	i32 n;
	i64 ans = 0;
	i64 last = 0;
	scanf("%d", &n);
	for (i32 i = 0; i < n; ++i) {
		i64 a;
		scanf("%ld", &a);
		if (last > a) {
			ans += last - a;
		} else {
			last = a;
		}
	}
	printf("%ld\n", ans);
	return 0;
}


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

#define all(v) v.begin(), v.end()
#define rep(i, n) REP(i, 0, n)
#define REP(i, x, n) for (int i = x; i < n; i++)
#define REPE(i, x, n) for (int i = x; i <= n; i++)
#define OP(x) cout << x << endl;
template<typename T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
template<class T> void chmax(T& a, T b) { if(a > b) a = b; }
template<class T> void chmin(T& a, T b) { if(a < b) b = a; }
typedef long long ll;

int main() {
    int n, m, x, y; cin >> n >> m >> x >> y;
    vector<int> vx(n);
    vector<int> vy(m);
    rep(i, n) cin >> vx[i];
    rep(i, m) cin >> vy[i];
    sort(all(vx));
    sort(all(vy));

    bool flag = false;
    for(int i = vx[n - 1] + 1; i <= vy[0]; i++){
        if(x < i && i <= y){
            flag = true;
            break;
        }else{
            continue;
        }
    }
    if(flag){
        cout << "No War" << endl;
    }else{
        cout << "War" << endl;
    }
}


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

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

const int mod =  1000000007;  //出力は (ans % mod + mod) % mod  (負の剰余を正にする)
const int inf = 1e9;
const long long INF = 1LL << 60;   // INF = 11

int main()
{
    ll a,b,c,d;
    cin >> a >> b >> c >> d;
    ll ans = a*c;
    ans = max(a*c,ans);
    ans = max(b*d,ans);
    ans = max(a*d,ans);
    ans = max(b*c,ans);
    cout << ans << endl;
}

Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
const int MAXn = 55555 + 1;
bool flag[MAXn];
int cnt, n;
int main() {
	ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	cin >> n;
	for (int i = 2; i < MAXn; i++)
		if (!flag[i]) {
			if (i % 10 == 1)
				if (cnt < n) {
					cout << i << ' ';
					cnt++;	
				}
			for (int j = 2 * i; j < MAXn; j+= i)
				flag[j] = true;
		}
}


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

int cal(int x){

  int ans=1;
    for(int i=0;i<3;i++){
        ans*=x;
    }
    return ans;
}

int main(){
  int x;
  cin >>x;
  
  int ans=cal(x);
  cout << ans <<endl;
  
  return 0;
}


Measured memory_bytes: 3100
#ABC140_C
N=int(input())
A=[0]*N
B=[int(i) for i in input().split()]
A[0]=B[0]

for i in range(1,N-1):
    A[i]=min(B[i-1],B[i])
A[N-1]=B[N-2]

print(sum(A))

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

int main(){
    map<int,int> mp;
    int cnt2=0,cnt1=0;
    for(int i = 0;i < 6;i ++){
        int a;
        cin >> a;
        mp[a] ++;
    }
    for(auto ite = mp.begin();ite != mp.end();++ite){
        if(ite->second==1) cnt1 ++;
        else if(ite->second==2) cnt2 ++;
    }
    if(cnt1==2&&cnt2==2) cout << "YES" << endl;
    else cout << "NO" << endl;
    return 0;
}

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

int main() {
  int A,B,C;
  cin >> A >> B >> C;
  
  if ((A == B) && (A == C) ||(A != B) && (B != C) && (C != A)) {
    cout << "No" << endl;
  }
  else {
    cout << "Yes" << endl;
  }
}


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

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

	int a, b, c, d;
	a = N / 1000;
	b = (N - a * 1000) / 100;
	c = (N - a * 1000 - b * 100) / 10;
	d = N - a * 1000 - b * 100 - c * 10;

//	cout << a << b << c << d << endl;

	if ((a == b) && (b == c)) {
		cout << "Yes" << endl;
	}
	else if ((b == c) && (c == d)) {
		cout << "Yes" << endl;
	}
	else {
	cout << "No" << endl;
	}
}

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


int main(){
  int v,e;cin>>v>>e;
  vector<vector<long long>> dist(v,vector<long long>(v,1e12)) ;
  for (int i = 0; i < v; i++) {
    dist[i][i] = 0;
  }
    
  for (int i = 0; i < e; i++) {
    int s,t,d;cin>>s>>t>>d;
    dist[s][t] = d;
  }

  for (int mid = 0; mid < v; mid++)
  for (int frm = 0; frm < v; frm++) 
  for (int des = 0; des < v; des++) 
  {
    dist[frm][des] = min(dist[frm][des],dist[frm][mid] + dist[mid][des]);
  }

  for (int i = 0; i < v; i++) 
  {
    if(dist[i][i] < 0)
    {
      cout<<"NEGATIVE CYCLE"<< endl;
      return 0;
    }
  }

  for (int i = 0; i < v; i++) 
  {
    if(dist[i][0] <= 1e11)cout << dist[i][0];
    else cout << "INF";
  for (int j = 1; j < v; j++) 
  {
    if(dist[i][j] <= 1e11)cout << " " << dist[i][j];
    else cout << " " << "INF";
  }
  cout << endl;
  }
}



Measured memory_bytes: 3240
#pragma region template 2.4
#include <bits/stdc++.h>
using namespace std;
template <typename T>
using pq_asc = priority_queue<T, vector<T>, greater<T>>;
typedef long long ll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef pair<ll, ll> ii;
typedef vector<ii> vii;
typedef vector<string> vs;
#define REP(i, n) for (ll i = 0; i < (n); ++i)
#define REP1(i, n) for (ll i = 1; i <= (n); ++i)
#define FOR(i, a) for (auto &i : a)
#define CH(f, x, y) x = f(x, y)
#define IN(T, x) \
    T x;         \
    cin >> x;
#define AIN(T, a, n) \
    vector<T> a(n);  \
    FOR(i, a)        \
    cin >> i;
#define A2IN(T1, a, T2, b, n) \
    vector<T1> a(n);          \
    vector<T2> b(n);          \
    REP(i, n)                 \
    cin >> a[i] >> b[i];
#define OUT(x) cout << (x) << endl;
#define FOUT(x) cout << fixed << setprecision(15) << (x) << endl;
#define ALL(a) (a).begin(), (a).end()
#define SORT(a) sort(ALL(a))
#define RSORT(a) \
    SORT(a);     \
    reverse(ALL(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define DUMPA(a)          \
    cout << #a << " = {"; \
    JOUT(ALL(a), ", ", cout) << "}" << endl;

template <typename T>
ostream &JOUT(T s, T e, string sep = " ", ostream &os = cout)
{
    if (s != e)
    {
        os << *s;
        ++s;
    }
    while (s != e)
    {
        os << sep << *s;
        ++s;
    }
    return os;
}

ostream &YES(bool cond, string yes = "Yes", string no = "No", ostream &os = cout)
{
    if (cond)
    {
        os << yes << endl;
    }
    else
    {
        os << no << endl;
    }
    return os;
}

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)
{
    os << '[';
    JOUT(ALL(v), ", ", os) << ']';
    return os;
}

const ll INF = 1e18;
const ll MOD = 1e9 + 7;
#pragma endregion template

int main()
{
    IN(ll, N);
    ll M = 1 << N;
    AIN(ll, S, M);
    SORT(S);
    multiset<ll> T, X;
    REP(i, M - 1)
    {
        T.insert(-S[i]);
    }
    X.insert(S[M - 1]);
    REP(i, N)
    {
        multiset<ll> Y(X);
        FOR(x, X)
        {
            auto j = T.upper_bound(-x);
            if (j == T.end())
            {
                OUT("No");
                return 0;
            }
            Y.insert(-(*j));
            T.erase(j);
        }
        X = Y;
    }
    OUT("Yes");
}

Measured memory_bytes: 26880
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int mod = 1e9 + 7;
const int inf = (1 << 30) - 1;
const ll infll = (1LL << 61) - 1;
#define fast() ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)

// dp[i][j] := s[i], t[j]まで見たときの部分列の最長の長さ
int dp[3333][3333];
string s, t;

int main()
{
    cin >> s >> t;
    int N = s.size(), M = t.size();
    s = " " + s, t = " " + t;
    for (int i = 1; i <= N; i++)
    {
        for (int j = 1; j <= M; j++)
        {
            if (s[i] == t[j])
                dp[i][j] = dp[i - 1][j - 1] + 1;
            else
                dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
        }
    }

    string ans = "";
    int length = dp[N][M], i = N, j = M;
    while (length > 0)
    {
        if (s[i] == t[j])
        {
            ans = s[i] + ans;
            i--, j--, length--;
        }
        else if (dp[i][j] == dp[i - 1][j])
            i--;
        else
            j--;
    }

    cout << ans << endl;
}

Measured memory_bytes: 41216
N = int(input())
H = list(map(int, input().split()))
if N == 1:
    print("Yes")
else:
    for i in range(N-2, -1, -1):
        if H[i] > H[i+1]:
            if H[i] > H[i+1]+1:
                print("No")
                break
            H[i] -= 1
    else:
        print("Yes")

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

#define int long long
using namespace std;
#define rep(i, n) for(int i=0;i<(n);++i)
typedef pair<int, int> pii;
const int INF = 1l << 60;


signed main() {
    int H, W;
    cin >> H >> W;
    H = max(H, W);
    int N;
    cin >> N;
    cout << (N + H - 1) / H << endl;
    return 0;
}


Measured memory_bytes: 764
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
//#define int long long

template <class T>
bool INRANGE(T x, T a, T b) { return a <= x && x <= b; }
template <class T>
bool chmax(T &a, const T &b) {if (a < b){ a = b; return 1;} return 0;}
template <class T>
bool chmin(T &a, const T &b) {if (a > b){ a = b; return 1;}return 0;}
template <class T>
void printv(vector<T> v) {for (T t : v) {cout << t << " ";}cout << '\n';}

#define REP(i, n) for (int i = 0; i < (n); ++i)
#define RREP(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define RFOR(i, a, b) for (int i = (a); i >= (b); --i)
#define ALL(v) (v).begin(), (v).end()
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \
                      << " " << __FILE__ << endl;

typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<vi> vvi;
typedef pair<int, int> pii;

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

    int n = s.length();
    vi ans(n,0);

    int i = 0;
    int r = 0;
    int l = 0;
    int p;
    while (i < n)
    {
        if (s[i] == 'R') r++;
        if (s[i] == 'L') l++;

        if (l==1) {
            p = i-1;
        }

        if (s[i] == 'L' and s[i+1] == 'R' or i == n-1) {
            if ((r+l)%2 == 0) {
                ans[p] = (r+l)/2;
                ans[p+1] = (r+l)/2;
            } else {
                if (r%2 == 0) {
                    ans[p] = (r+l)/2;
                    ans[p+1] = (r+l)/2+1;
                } else {
                    ans[p] = (r+l)/2+1;
                    ans[p+1] = (r+l)/2;
                }
            }

            r = 0;
            l = 0;
        }
        i++;
    }
    

  
    for (int i=0; i<n; i++) {
        cout << ans[i];
        if (i != n-1) cout << ' ';
    }

    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define rep2(i, a, n) for(ll i = a; i < (ll)(n); i++)
#define memi cout << endl
#define kono(n) cout << fixed << setprecision(n)
#define all(c) (c).begin(), (c).end()
#define pb push_back
#define hina cout << ' '
#define in(n) cin >> n
#define in2(n, m) cin >> n >> m
#define in3(n, m, l) cin >> n >> m >> l
#define out(n) cout << n
const ll mei = (ll)1e9 + 7;

int main(){
  ll a, b, n, s;
  in3(n, a, b);
  s = n / (a + b);
  n = n - s * (a + b);
  s = s * a;
  s = s + min(n, a);
  out(s);
  memi;
}

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


int main () {
    int a,y,x,W,H,N,z=0;
    cin >> W >> H >> N;

    bool xy[110][110]={0};
    for (int i=0;i<N;i++) {
        cin >> x >> y >> a;
        if (a==1){
            for (int j=0;j<x;j++) {
                for(int k=0;k<H;k++){
                xy[j][k]=1;
        }}}
        else if (a==2){
            for (int j=W-1;j>=x;j--) {
                for(int k=0;k<H;k++){
                xy[j][k]=1;
        }}}
        else if (a==3){
            for (int j=0;j<y;j++) {
                for(int k=0;k<W;k++){
                xy[k][j]=1;
        }}}
        else if (a==4){
            for (int j=H-1;j>=y;j--) {
               for(int k=0;k<W;k++){
                xy[k][j]=1;
        }}}
        
    }
    
    for (int i=0;i<W;i++){
    for (int j=0;j<H;j++){
    if (xy[i][j]==1) z++;
    }
    }
    cout << H*W-z << endl;

    return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;

namespace Atcoder
{
    class Program
    {
        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());
            var input = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();

            int count = 0;
            for (int i = 0; i < N; i++)
            {
                if (input[i] != i + 1)
                {
                    count++;
                }
            }

            Console.WriteLine(count == 0 || count == 2 ? "YES" : "NO");

        }
    }
}

Measured memory_bytes: 13268
#include <iostream>
#include <map>
#include <vector>
#include <algorithm>
#include <bitset>
using ll = long long;
using namespace std;
constexpr ll INF = 1LL << 60;

ll n, r;

int main() {
	cin >> n >> r;
	if (n >= 10) cout << r;
	else cout << r + 100 * (10 - n);
	return 0;
}

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

using namespace std;

#define cerr if(false)cerr
#define what(x) cerr<<#x<<" = "<<x<<endl
 
typedef long long ll;
typedef pair<ll, ll> ii;

const int maxN = 1e5 + 9, maxV = 1e6 + 9, MOD = 1e9 + 7, SQ = 322;

int main(){

	ios_base::sync_with_stdio(false); 
	cin.tie(0);
	cout.tie(0);

	ll x;
	cin >> x;
	for(ll i = 0; i < x; i++){
		ll a = i * i * i * i *i;
		ll res = -1 * (x - a);
		ll mul = 1;
		
		if(res < 0){
			mul = -1;
			res *= -1;
		}

		ll p = pow(res, (1.0/5.0));
		if(p * p * p * p * p == res){
			cout << i << " " << p * mul << endl;
			return 0;
		}else if((p+1) * (p+1) * (p+1) * (p+1) * (p+1) == res){
			cout << i << " " << (p+1) * mul << endl;
			return 0;
		}


	}

	return 0;
}

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

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

using ll = long long;

using namespace std;

void init();
void solve();

int main()
{
	init();
	solve();
}

int N;
vector<ll> v;

void init()
{
	int T;
	cin >> N >> T;
	v.resize(N);
	rep(i, N) cin >> v[i];
}

ll culc_ma()
{
	ll res = 0;
	ll mi = v[0];
	reps(i, 1, N) {
		mi = min(mi, v[i]);
		res = max(res, v[i] - mi);
	}
	return res;
}

void solve()
{
	ll ma = culc_ma();
	multiset<ll> s;
	s.insert(v[0]);
	ll res = 0;
	reps(i, 1, N) {
		res += s.count(v[i] - ma);
		s.insert(v[i]);
	}
	cout << res << endl;
}


Measured memory_bytes: 5760
#include <bits/stdc++.h>
#define ll long long
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end))) // rep(i, 1, 5) --> {1,2,3,4} // rep(i, 5, 1) --> {4,3,2,1} // rep(it, end(v), begin(v)) --> *it

using namespace std;

int main()
{
    ll n;
    cin >> n;
    vector<ll> v(n);
    rep(i, 0, n)
        cin >> v[i];
    ll ans = LLONG_MAX;
    ll res1 = 0, res2 = 0;
    ll som;
    if (v[0] >= 0)
    {
        if (v[0] == 0)
        {
            som = 1;
            res1 = 1;
        }
        else 
            som = v[0];
        rep(i, 1, n)
        {
            som = som + v[i];
            if (i % 2 == 1)
                if (som < 0)
                    continue;
                else
                {
                    res1 += som + 1;
                    som = -1;
                }
            else 
                if (som > 0)
                    continue;
                else 
                {
                    res1 += 1 - som;
                    som = 1;
                }
        }
        res2 = v[0] + 1;
        som = -1;
        rep(i, 1, n)
        {
            som = som + v[i];
            if (i % 2 == 0)
                if (som < 0)
                    continue;
                else
                {
                    res2 += som + 1;
                    som = -1;
                }
            else 
                if (som > 0)
                    continue;
                else 
                {
                    res2 += 1 - som;
                    som = 1;
                }
        }
    }
    if (v[0] == 0)
        ans = min(res1, res2);
    if (v[0] <= 0)
    {
        if (v[0] == 0)
        {
            som = -1;
            res1 = 1;
        }
        else 
            som = v[0];
        rep(i, 1, n)
        {
            som = som + v[i];
            if (i % 2 == 0)
                if (som < 0)
                    continue;
                else
                {
                    res1 += som + 1;
                    som = -1;
                }
            else 
                if (som > 0)
                    continue;
                else 
                {
                    res1 += 1 - som;
                    som = 1;
                }
        }
        res2 = 1 - v[0];
        som = 1;
        rep(i, 1, n)
        {
            som = som + v[i];
            if (i % 2 == 1)
                if (som < 0)
                    continue;
                else
                {
                    res2 += som + 1;
                    som = -1;
                }
            else 
                if (som > 0)
                    continue;
                else 
                {
                    res2 += 1 - som;
                    som = 1;
                }
        }
    }
    if (v[0] == 0)
        cout << min({ans, res1, res2});
    else 
        cout << min(res1, res2);
    return 0;
}

Measured memory_bytes: 1024
x,y,a,b,c=map(int,input().split())
p=list(map(int,input().split()))
q=list(map(int,input().split()))
r=list(map(int,input().split()))

p.sort(reverse=True)
q.sort(reverse=True)
r.sort(reverse=True)

p=p[:x]
q=q[:y]

p.extend(q)
p.extend(r)

p.sort(reverse=True)
print(sum(p[:x+y]))


Measured memory_bytes: 23456
#include<bits/stdc++.h>
#include<cctype>
using namespace std;
#define rep(i,n) for (int i=0;i<(n);i++)
#define reps(i,n) for (int i=1;i<=(n);i++)
#define rrep(i,n) for (int i=(n)-1;i>=0;i--)
#define rreps(i,n) for (int i=(n);i>0;i--)
#define all(v) (v).begin(),(v).end()
#define pi 3.1415926535897932384
#define E9 1000000000
#define eps 1e-4
#define pii pair<int,int>
template<class T> inline bool chmin(T &a, T b) {if (a>b) {a = b; return 1;} return 0;};
template<class T> inline bool chmax(T &a, T b) {if (a<b) {a = b; return 1;} return 0;};
typedef long long int ll;
const long long INF = 1LL << 60;

// ランレングス圧縮(Run Length Encoding)
vector<pair<char,int>> RLE(string S){
  vector<pair<char,int>> p;
  int N = S.size();
  for (int i=0;i<N;i++) {
    if (S[i]==S[i+1]){
      int cnt = 1;
      char c = S[i];
      while (i+1<N && S[i]==S[i+1]) {
        i++;
        cnt++;
      }
      p.push_back({c,cnt});
    }
    else p.push_back({S[i],1});
  }
  return p;
}


int main(){
  int N, K; cin >> N >> K;
  ll ans = 0;
  for (int b=1;b<=N;b++){
    int p = N/b;
    int r = N%b;
    ans += p*max(0,b-K);
    ans += max(0,r-K+1);
  }
  if (K==0) ans -= N;
  cout << ans << endl;

  // cout << fixed << setprecision(10);
  
  return 0;
}


Measured memory_bytes: 3608
#include<bits/stdc++.h>
using namespace std;
struct node{
	int v;
	int son;
	int siz;
	int fa;
	int ch[2];
}a[500007];
int root;
int tot;
void rotat(int x){
	int y=a[x].fa;
	int z=a[y].fa;
	int k=(a[y].ch[1]==x);
	a[z].ch[a[z].ch[1]==y]=x,a[x].fa=z;
	a[a[x].ch[k^1]].fa=y,a[y].ch[k]=a[x].ch[k^1];
	a[y].fa=x,a[x].ch[k^1]=y;
	a[x].son=a[x].siz+a[a[x].ch[0]].son+a[a[x].ch[1]].son;
	a[y].son=a[y].siz+a[a[y].ch[0]].son+a[a[y].ch[1]].son;
}
void splay(int x,int top){
	while(a[x].fa!=top) {
		int y=a[x].fa;
		int z=a[y].fa;
		if(z!=top)
			(a[y].ch[0]==x)^(a[y].ch[0]==y)?rotat(x):rotat(y);
		rotat(x);
	}
	if(!top)
        root=x;
}
void inser(int x){
	int u=root;
	int f=0;
	while(u&&a[u].v!=x)
		f=u,u=a[u].ch[x>a[u].v];
	if(u){
		a[u].siz++;
		splay(u,0);
		return;
	}
	u=++tot;
	if(f)
        a[f].ch[x>a[f].v]=u;
	a[u].fa=f;
	a[u].siz=a[u].son=1;
	a[u].v=x,splay(u,0);
}
void fin(int x){
	int u=root;
	while(a[u].v!=x&&a[u].ch[x>a[u].v])
        u=a[u].ch[x>a[u].v];
	splay(u,0);
}
int nex(int x,int f){
	fin(x);
	if((f&&a[root].v>x)||(!f&&x>a[root].v))
        return root;
	int u=a[root].ch[f];
	while(a[u].ch[f^1])
        u=a[u].ch[f^1];
	return u;
}
void delet(int x){
	int aa=nex(x,0);
	int bb=nex(x,1);
	splay(aa,0),splay(bb,aa);
	int u=a[bb].ch[0];
	if(a[u].siz>1){
        a[u].siz--;
        splay(u,0);
	}
	else
        a[bb].ch[0]=0;
}
int kth(int x){
	int u=root;
	if(a[u].son<x)
        return 0;
	while(1){
		if(x>a[a[u].ch[0]].son+a[u].siz)
			x-=a[a[u].ch[0]].son+a[u].siz,u=a[u].ch[1];
		else if(a[a[u].ch[0]].son>=x)
			u=a[u].ch[0];
		else
            return a[u].v;
	}
}
int main(){
	int n;
	cin>>n;
	int sum=0;
	inser(1e9);
	inser(-1e9);
	for(int i=1;i<=n;++i){
		int x;
		cin>>x;
		int now=a[nex(x,0)].v;
		if(now!=-1e9){
            delet(now);
            inser(x);
		}
		else{
            inser(x);
            sum++;
		}
	}
	cout<<sum;
	return 0;
}


Measured memory_bytes: 4352
//
//  main.cpp
//  1234
//
//  Created by Moha Jain on 14/04/20.
//  Copyright © 2020 Moha Jain. All rights reserved.
//
 
#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<unordered_map>
#include<unordered_set>
#include<queue>
#include<stack>
#include<algorithm>
#include<string>
#include<math.h>
#include <iomanip>
#include <numeric>
#define _USE_MATH_DEFINES
 
using namespace std;
 

 
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    long long int n,sum=0;
    cin>>n;
    vector<long long int>a(n+1);
    
    for(int i=1;i<=n;i=i+1) for(int j=i;j<=n;j=j+i) a[j]++;
    
    for(int i=1;i<=n;i=i+1) sum+=i*a[i];
    cout<<sum<<endl;
}


 


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

vector<int> v[100005];
int ans[100005];

int dfs(int node)
{
	if(!ans[node])
	{
		for(int i: v[node])
		{
			ans[node] = max(ans[node] , dfs(i));
		}
		ans[node]++;
	}
	return ans[node];
}
int main()
{
	int n , m;
	
	cin >> n >> m;
	
	for(int i = 1 ; i<=m ; i++)
	{
		int x , y;
		cin >> x >> y;
		v[x].push_back(y);
	}
	
	int fans = 1;
	
	for(int i = 1 ; i<=n ; i++)
	{
		fans = max(fans , dfs(i));
	}
	
	cout << fans-1;
	
	return 0;
}

Measured memory_bytes: 7424
import itertools
import math
n = int(input())

points = []
for i in range(n):
    x,y = map(int,input().split())
    points.append([x,y])


cs = list(itertools.combinations(points,2))
ans = 0
for a,b in cs:
    c = (a[0]-b[0]) ** 2 + (a[1]-b[1]) ** 2
    ans += math.sqrt(c)

ans = (ans / n) * 2
print(ans)


Measured memory_bytes: 3064
def partition(A, p, r):
    i = p - 1
    for j in range(p, r + 1):
        if A[j] <= A[r]:
            i += 1
            A[i], A[j] = A[j], A[i]

    return i


n = int(raw_input())
A = map(int, raw_input().split())

q = partition(A, 0, n-1);

A = map(str, A)
A[q] = "[" + A[q] + "]"

print " ".join(A)

Measured memory_bytes: 17080
#include <iostream>
#include <string>
#include <map>
#include <set>
#include <algorithm>
using namespace std;
#define MAX 100000

static const int N =100;

int main(){
  int n,p[N+1],m[N+1][N+1];
  cin >> n;
  for(int i=1;i<=n;i++){
    cin >>p[i-1]>>p[i];
  }
  for(int i=1;i<=n;i++)m[i][i]=0;
  
  for(int l=2;l<=n;l++){
    for(int i=1;i<=n-l+1;i++){
      int j=i+l-1;
      m[i][j]=(1<<21);
      for(int k=i;k<=j-1;k++){
        m[i][j]=min(m[i][j],m[i][k]+m[k+1][j]+p[i-1]*p[k]*p[j]);
      }
    }
  }
  cout << m[1][n] << endl;
  return 0;
}


Measured memory_bytes: 3148
#include "bits/stdc++.h"
using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
	*this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define cool ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	#define int  long long int
	#define pb push_back
	#define fe first
	#define lb lower_bound 
	#define ub upper_bound
	#define pii pair<pair<int,int>,pair<int,int> >
	#define se second
	#define endl "\n"
	#define pi pair<int, int>
	#define mi          map<int,int>
	#define mii         map<pi,int>
	#define vi vector<int> 
	#define vvi vector<vi>
	#define bs   binary_search
	#define rep(i,a,b) for(int i=a;i<b;i++)
	#define rep1(i,a,b) for(int i=a;i<=b;i++)	
	#define all(c) (c).begin(),(c).end()
	#define sz(x)       (int)x.size() 
	#define PI 3.14159265358979323846
	
	 const int N =5e5+5;
	
	 int mod= 1e9+7;
	 int dx[4]={0,0,+1,-1};
	 int dy[4]={+1,-1,0,0};  
	 
	 
	int po(int a, int b) {
		a %= mod;
		int res = 1;
		while (b > 0) {
			if (b & 1)
				res = (res * a) % mod;
			a =(a*a) % mod;
			b >>= 1;
		}
		 return res;	
	   }
	     

	 void solve() {	    
		   
		 int a,b,c;
		 cin>>a>>b>>c;
		 set<int> st;
		 st.insert(a);
		 st.insert(b);
		 st.insert(c);
		 if(sz(st)==2) cout<<"Yes\n";
		 else cout<<"No\n";      
		       
	 }
	
int32_t main() {
	cool;
	int t=1;
	//cin>>t;
	while(t--)
	   solve();
	   
	   
	   return 0;	   
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
import sys
X, Y = map(int, input().split())

mod = 10 ** 9 + 7

a = (2 * Y - X) / 3
b = (2 * X - Y) / 3
if a < 0 or b < 0 or (X + Y) % 3 != 0:
    print(0)
    sys.exit()

a = int(a)
b = int(b)
N = a + b
f = [1]
for i in range(1,a+b+1):
    f.append((f[-1] * i) % mod)
ans = f[a+b] * (pow(f[a], mod-2, mod) * pow(f[b], mod-2, mod) % mod) % mod
print(ans)

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

using namespace std;
int main() {
    string s;
    int k;
    cin>>k;
    cin>>s;
    
    if(s.size()<=k){
        cout<<s<<endl;
    }else{
        string a = s.substr(0,k);
        a+="...";
        cout<<a<<endl;
    }
    return 0;
}

Measured memory_bytes: 3612
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>

using namespace std;

string s;
int pos;

int calc(){
  if('0' <= s[pos] && s[pos] <= '9'){
    string tmp;
    for(;'0'<=s[pos]&&s[pos]<='9';pos++) tmp.push_back(s[pos]);
    return (atoi(tmp.c_str()) + 1) / 2;
  }
  vector<int> vec;
  while(pos < s.size() && s[pos] == '['){
    pos++;
    vec.push_back(calc());
    pos++;
  }
  sort(vec.begin(), vec.end());
  int res = 0;
  for(int i=0;i<=(int)vec.size()/2;i++) res += vec[i];
  return res;
}

main(){
  int T;
  cin >> T;
  while(T--){
    cin >> s;
    pos = 0;
    cout << calc() << endl;
  }
}

Measured memory_bytes: 1288
import math

nm = list(map(int, input().split()))
N, M = nm[0], nm[1]
dp = [1145141919810 for i in range(int(math.pow(2, N)))]
dp[0] = 0
for i in range(M):
    c_num = list(map(int, input().split()))
    cost, NUM = c_num[0], c_num[1]
    index = 0
    tmp = list(map(int, input().split()))
    for j in range(len(tmp)):
        index += int(math.pow(2, tmp[j] - 1))
    for j in range(int(math.pow(2, N))):
        dp[j | index] = min(dp[j | index], dp[j] + cost)
if dp[len(dp) - 1] == 1145141919810:
    print(-1)
else:
    print(dp[len(dp) - 1])


Measured memory_bytes: 47448
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
using namespace std;
typedef long long ll;
ll MOD = 1e9+7;
#define rep(i,n) for(int i = 0; i < (n); ++i)
int main() {
    int n;
    cin >> n;
    ll ans = 1;
    rep(i, n) ans = ans * (i + 1)% MOD;
    cout << ans << endl;
    return 0;
}


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

#define MOD 1000000007
#define rep(i, n) for(ll i=0; i < (n); i++)
#define ALL(v) v.begin(),v.end()
#define FOR(i, j, k) for(ll i=j;i<k;i++)
#define DUMP(i, v)for(ll i=0;i<v.size();i++)cout<<v[i]<<" "

using namespace std;
typedef long long int ll;
typedef vector<ll> llvec;
typedef vector<double> dvec;
typedef pair<ll, ll> P;
typedef long double ld;
struct Edge{ll from, to, cost;};
struct node{ll cost, to;
  bool friend operator>(node a, node b){
    return a.cost>b.cost;
  }
};

ll mod(ll a, ll mod){
  ll res = a%mod;
  if(res<0)res=res + mod;
  return res;
}

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

ll modinv(ll a, ll mod){
  return modpow(a, mod-2, mod);
}

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

bool is_prime(ll n){
  ll i = 2;
  if(n==1)return false;
  if(n==2)return true;
  bool res = true;
  while(i*i <n){
    if(n%i==0){
      res = false;
    }
    i = i+1;
  }

  //if(i==1)res = false;
  if(n%i==0)res=false;
  return res;
}


/**************************************
** A main function starts from here  **
***************************************/
int main(){
  string r,g,b;
  cin >> r >> g >> b;
  cout << ((stoi(g+b)%4==0)?"YES":"NO");

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <utility>
#include <limits>

using namespace std;

int N;
size_t MASK;
vector<vector<int>> v;
vector<int> dp;

inline size_t add(size_t res, size_t delta)
{ 
  return (res + delta) % 1000000007;
} 

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

  cin >> N;

  MASK = (1<<N) - 1;

  v = vector<vector<int>>(N, vector<int>(N));
  dp = vector<int>(1<<N, 0);
  auto bc = dp;

  for (int i = 0; i < N; ++i)
  { 
    for (int j = 0; j < N; ++j)
    { 
      cin >> v[i][j];
    }
  }
  dp[MASK] = 1;

  for (int i = 1; i < (1<<N); ++i)
  {
    bc[i] = bc[i & (i-1)] + 1;
  }

  for (int i = N-1; i >= 0; --i)
  {
    for (int mask = 0; mask < MASK; ++mask)
    {   
      if (bc[mask] != i) continue;
      if (dp[mask] > 0) continue;
      size_t res = 0;
      for (int j = 0; j < N; ++j)
      {   
        if (v[i][j] && !(mask & (1<<j)))
        {   
          const size_t new_mask = mask | (1<<j);
          res = add(res, dp[new_mask]);
        }   
      }   
      dp[mask] = res;
    }   
  }

  cout << dp[0];

  return 0;
}

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

using namespace std;

int main() {
  int n, k, c = 0;
  cin >> n >> k;
  
  for (int i = 0; i < n; i++) {
    int t;
    cin >> t;
    if (t >= k) c++;
  }
  
  cout << c << endl;
  return 0;
}

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

using namespace std;


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

	unordered_multiset<int> result;
	//result.resize(M); 
	int count = 0;

	int left = 0;
	int right = 10000000;
	for (int i = 0; i < M; i++)
	{
		int a, b;
		cin >> a >> b;
		left = max(left, a);
		right = min(right, b);
		//for (int j = left; j <= right; j++)
		//{
		//	result.emplace(j);
		//}
	}

	//for (int i = left; i <= right; i++)
	//{

	//	if (result.count(i) >= M)
	//	{
	//		count++;
	//	}
	//}


	if (left <= right)
	{
		cout << right - left + 1 << endl;
	}
	else
	{
		cout << 0 << endl;
	}


	return 0;

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define ld long double
#define pi pair<ll,ll>
#define pii vector<pair<ll,ll> >
#define v vector
#define vi vector<ll>
#define f(a,i,n) for(int i=a;i<n;i++)
#define pb push_back
#define mp make_pair
#define MOD 1000000007
#define MAX 1000001
#define all(x) x.begin(),x.end()
const ll inf=(ll) 1e18;

ll gcd(ll a, ll b) {ll r; while (b) {r = a % b; a = b; b = r;} return a;}
ll lcm(ll a, ll b) {return a / gcd(a, b) * b;}
ll fpow(ll n, ll k, int p = MOD) {ll r = 1; for (; k; k >>= 1) {if (k & 1) r = r * n % p; n = n * n % p;} return r;}
int inv(int a, int p = MOD) {return fpow(a, p - 2, p);}
ll spf[MAX+1];
void sieve()//complexity = approx 3*10^6
{
    f(1,i,MAX) {spf[i]=i;} 
    for(ll i=2;i<MAX;i+=2){spf[i]=2;}
    for(ll i=3;i<MAX;i+=2)
    {
        if(spf[i]==i) //if i is prime mark its multiples with spf as i
        {
            for(ll j=i*i;j<MAX;j+=i)
            {
                spf[j]=min(i,(ll)spf[j]);
            }
        }
    }
}

int main()
{
    ll n, w;
    cin >> n >> w;
    vi items(n), weight(n);
    f(0, i, n) cin >> weight[i] >> items[i];
    v<vi> dp(n + 1, vi(w + 1, 0));
    f(0, i, n + 1) {
        f(0, j, w + 1) {
            if(j == 0 or i == 0)
                dp[i][j] = 0;
            else if(j >= weight[i - 1])
                dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - weight[i - 1]] + items[i - 1]); 
            else 
                dp[i][j] = dp[i - 1][j];
        }
    }
    cout << dp[n][w] << endl;
} 

Measured memory_bytes: 82980
import java.util.Scanner;

	public class Main {

		public static void main(String[] args) {

			Scanner sc = new Scanner(System.in);
			
			int n = sc.nextInt();
			int m = sc.nextInt();
			int[] s = new int[m];
			int[] c = new int[m];
			int[] num = new int[n+1];
			
			for(int i=0;i<m;i++) {
				s[i] = sc.nextInt();
				c[i] = sc.nextInt();
			}
			
			for(int i=0;i<n+1;i++) {
				num[i] = -1;
			}
			
			for(int i=0;i<m;i++) {
				if(n!=1&&s[i]==1&&c[i]==0) {
					System.out.println(-1);
					return;
				}
				if(num[s[i]]==-1){
					num[s[i]] = c[i];
					continue;
				}
				if(num[s[i]]!=c[i]){
					System.out.println(-1);
					return;
				}
				
			}
			
			if(n==1) {
				if(num[1]==-1) {
					System.out.println(0);
					return;
				}
			}else if(num[1]==-1) {
				num[1] = 1;
			}
			
			
			for(int i=2;i<n+1;i++) {
				if(num[i]==-1) {
					num[i]=0;
				}
			}
			
			for(int i=1;i<n+1;i++) {
				System.out.print(num[i]);
			}
			
	    }
				
	}


Measured memory_bytes: 23636
N = int(input())
s_list = {}
out = 0

for i in range(N):
	s_in =''.join(sorted(list(input())))
	if s_in in s_list:
		s_list[s_in]+=1
	else:
		s_list[s_in]=1
    
for val in s_list.values():
  out += int(val*(val-1)/2)
    
print(out)

Measured memory_bytes: 17808
#include <bits/stdc++.h>
using namespace std;
#define REP(i,s,n) for(int i=(int)(s);i<(int)(n);i++)
#define rep(i,n) REP(i, 0, n)
map <int, int> d;//基本状態から状態iへの最短手数
const int dir[4] = {-4, -1, 1, 4};
int encode(int a[8]){
    int res = 0;
    rep(i, 8)
      res |= a[i] << (i * 3);
    return res;
}
void decode(int x, int a[8]){
    rep(i, 8)
      a[i] = (x >> (i * 3)) & 7;
}
void bfs(){
    queue <int> cnd;//condition（遷移する状態）
    cnd.push(16434824);
    d[16434824] = 0;
    while(cnd.size()){
        int sp[8];//作業用
        int bcnd = cnd.front(); cnd.pop();
        decode(bcnd, sp);
        int bz = find(sp, sp + 8, 0) - sp;
        rep(i, 4){
            int nz = bz + dir[i];
            if(nz < 0 || nz >= 8 || bz + nz == 7) continue;
            swap(sp[bz], sp[nz]);
            int ncnd = encode(sp);
            if(d.count(ncnd) == 0){
                d[ncnd] = d[bcnd] + 1;
                cnd.push(ncnd);
            }
            swap(sp[bz], sp[nz]);
        }
    }
}
int main(){
    bfs();
    while(true){
        int a[8];
        rep(i, 8)
          if(scanf("%d", a + i) == EOF)
            return 0;
        printf("%d\n", d[encode(a)]);
    }
}

Measured memory_bytes: 2152
#include <iostream>
#include <vector>
#include <climits>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <string>
#include <bitset>
#include <utility>
#include <numeric>
#include <queue>
#include <stack>

using ll = long long;
using namespace std;

constexpr int MOD = 1e9 + 7;
constexpr ll MOD_LL = ll(1e9) + 7;

int main(void) {
	int n;
	cin >> n;
	
	vector<ll> r(n);
	for(int i = 0; i < n; ++i) {
		cin >> r[i];
	}
	
	ll mini = r[0];
	ll ans = -1e10;
	for(int i = 1; i < n; ++i) {
		ans = max(ans, r[i] - mini);
		mini = min(mini, r[i]);
	}
	
	cout << ans << endl;
	
	return 0;
}



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

int main(){
  int N;
  cin>>N;
  vector<int>d;
  for(int i=0;i<N;i++){
    int x;
    cin>>x;
    d.push_back(x);
  }
  int sum=0;
  for(int i=0;i<N-1;i++){
    for(int j=i+1;j<N;j++){
      sum+=d[i]*d[j];
    }
  }
  cout<<sum<<endl;
  return 0;
}

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

int N;
int A[200005];
long long prefixsum[200005];
map <long long, long long> frequency;
long long ans=0;

int main()
{
    frequency[0]=1;

    cin>>N;

    for (int i=1; i<=N; i++)
    {
        cin>>A[i];
    }

    for (int i=1; i<=N; i++)
    {
        prefixsum[i]=prefixsum[i-1]+A[i];

        ans=ans+frequency[prefixsum[i]];

        frequency[prefixsum[i]]++;
    }

    cout<<ans<<endl;
}

Measured memory_bytes: 15104
#include <cstdio>
#include <cstring>
#include <cmath>
#include <utility>
#include <iostream>
#include <functional>
#include <bitset>
#include <algorithm>
#include <vector>
#include <forward_list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#define rep(i, s, g) for ((i) = (s); (i) < (g); ++(i))
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const ll MOD = 1e9 + 7;
const ll INF = (1ll << 60);

ll power(ll x, ll y)
{
    ll ans = 1;
    while (y)
    {
        if (y & 1)
            ans = (ans * x) % MOD;
        x = (x * x) % MOD;
        y >>= 1;
    }
    return ans;
}

ll comb(ll n, ll k)
{
    ll ans = 1;
    ll i;

    if (n < k || n < 0 || k < 0)
    {
        return 0;
    }

    rep(i, 0, k)
    {
        ans *= n - i;
        ans %= MOD;
        ans *= power(i + 1, MOD - 2);
        ans %= MOD;
    }

    return ans;
}

int main(void)
{
    int n;
    ll ans = 0;

    cin >> n;

    vector<string> s(n);
    map<string, ll> count;
    for (int i = 0; i < n; i++)
    {
        cin >> s[i];
        sort(s[i].begin(), s[i].end());

        count[s[i]]++;
    }

    for (auto x : count)
    {
        ans += x.second * (x.second - 1) / 2;
    }

    cout << ans << endl;
}

Measured memory_bytes: 18176