akhauriyash/Code-Regression huggingface dataset:
import core.bitop, std.algorithm, std.ascii, std.bigint, std.conv, std.math,
    std.functional, std.numeric, std.range, std.stdio, std.string, std.random,
    std.typecons, std.container;

// dfmt off
T lread(T = long)(){return readln.chomp.to!T();}
T[] aryread(T = long)(){return readln.split.to!(T[])();}
void scan(TList...)(ref TList Args){auto line = readln.split();
foreach (i, T; TList){T val = line[i].to!(T);Args[i] = val;}}
alias sread = () => readln.chomp();enum MOD = 10 ^^ 9 + 7;
// dfmt on

void main()
{
    long N, K;
    scan(N, K);
    auto V = aryread();
    long ans = long.min;
    long M = min(N, K);
    foreach (x; 0 .. M + 1)
        foreach (y; 0 .. M - x + 1)
        {
            auto X = V[0 .. x];
            auto Y = V[N - y .. $];
            long t = X.sum() + Y.sum();
            auto r = chain(X, Y).array;
            r.sort();
            foreach (i; 0 .. K - (x + y))
                if (i < r.length && r[i] < 0)
                {
                    t -= r[i];
                }
                else
                {
                    break;
                }
            ans = ans.max(t);
        }
    writeln(ans);
}


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

int main()
{
    int A, B, C;
    cin >> A >> B >> C;
    ;

    int res = 0;
    for (int i = B - A; i >= 0; i = i - A)
    {
        if (res >= C || i < 0)
        {
            break;
        }
        res++;
    }
    cout << res << endl;
}

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

using namespace std;

int main()
{
    ll n;
    cin>>n;
    ll sum=0;
    ll arr[n];
    ll freq[100001];
    for(ll i=0;i<100001;i++){
        freq[i]=0;
    }
    for(ll i=0;i<n;i++){
        cin>>arr[i];
        freq[arr[i]]++;
        sum+=arr[i];
    }
    ll q;
    cin>>q;
    ll barr[q],carr[q];
    for(ll i=0;i<q;i++){
        cin>>barr[i];
        cin>>carr[i];
    }
    for(ll i=0;i<q;i++){
        sum+=(freq[barr[i]]*(carr[i]-barr[i]));
        cout<<sum<<"\n";
        freq[carr[i]]+=freq[barr[i]];
        freq[barr[i]]=0;
    }

    return 0;
}


Measured memory_bytes: 6752
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  vector<int> h(N);

  for (int i = 0; i < N; i++) cin >> h.at(i);

  int ans = 0;
  while (1) {

    bool F = 1; // 水やりした：0 していない：1
    bool G = 1; // 現在水やり中：0 していない：1

    for (int i = 0; i < N; i++) {
      if (G == 1 && 0 < h.at(i)) {
        // 花の水やりを開始
         F = 0;
         G = 0;
        h.at(i)--;
        ans++;
      } else if (G == 0 && 0 < h.at(i)) {
        h.at(i)--;
      } else if  (h.at(i) == 0) {
        // 花の水やりをやめる
        G = 1;
      }

    }

    // 1回も水をあげていない場合は終了
    if (F) break;
  }

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

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

int main() {
  long long N,keta=0;
  cin >> N;
  N++;
  long long n = N;
  for(int i=0; n>=1; i++){
    if(n/10 == 0){
      keta++;
      break;
    }
    n /= 10;
    keta++;
  }
  cout << (keta-1)*9+n-1 << endl;
}


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

#define MAX_N 100000

using namespace std;

typedef long long lint;

lint poz(lint a)
{
    if(a < 0)
        return (-a);

    return a;
}

int n, m;

int prim[MAX_N + 1];
int fail[MAX_N + 1];

string s;

int main()
{
    cin >> n >> m;
    int cr = 0;
    int pen = 0;
    for(int i = 1; i <= m; i ++)
    {
        int a;
        cin >> a >> s;

        if(s == "AC")
        {
            if(prim[a] == 0)
                prim[a] = i, cr ++;
        }

        if(s == "WA")
        {
            if(prim[a] == 0)
                fail[a] ++;
        }
    }

    for(int i = 1; i <= n; i ++)
    {
        if(prim[i] != 0)
            pen += fail[i];
    }

    cout << cr << " " << pen << "\n";

    return 0;
}


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

int main() {
    int n;
    string s;
    cin >> s;
    if(s == "Sunny"){
        cout << "Cloudy" << endl;
    }
    else if(s == "Cloudy"){
        cout << "Rainy" << endl;
    }
    else {
        cout << "Sunny" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
import math
T = [int(input()) for i in range(5)]
m = [(T[i]+9)%10 for i in range(5)]
idx = m.index(min(m))
d = m[idx]+1
result = sum([math.ceil(T[i]/10)*10 for i in range(5)])
result -= 10 - d
print(result)

Measured memory_bytes: 3064
/* ＵＴＦ－８ */
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <list>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <array>
#include <queue>
#include <stack>
#include <algorithm>
#include <tuple>
#include <numeric>
#include <type_traits>
#include <limits>
#include <stdio.h>

int main()
{
	int N;
	std::vector<int> A;

	std::cin >> N;
	A.resize(N);
	for (auto& a : A) {
		std::cin >> a;
	}

	double sum = 0;
	for (auto a : A) {
		sum += 1.0/a;
	}
	printf("%.20f\n", (1.0/sum));
}


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

#define sws ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define INFINITO 1000000000
#define ll long long
#define vi vector<int>
#define pb push_back
#define pii pair<int, int>
#define mp make_pair
#define ff first
#define ss second
#define vvi vector<vi>
#define all(x) x.begin(), x.end()
#define fo(i, n) for( int i = 0; i < n; i++ )


int main() {

    string s;
    cin >> s;
    set<char> letras;

    for ( auto l : s ) {
        letras.insert(l);
    }

    int x = 0, y = 0;
    if ( letras.find('S') != letras.end() ) y--;
    if ( letras.find('N') != letras.end() ) y++;
    if ( letras.find('W') != letras.end() ) x++;
    if ( letras.find('E') != letras.end() ) x--;

    cout << (x == 0 and y == 0 ? "Yes\n" : "No\n");

    return 0;
}

Measured memory_bytes: 256
/*
    IN THE NAME OF GOD
*/
#include <bits/stdc++.h>

#define loop(n) for(int i=0; i<n; i++)
#define loopB(n) for (int j=0; j<n; j++)
#define TAJIKISTAN ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define in freopen("input.txt", "r" , stdin);
#define out freopen("output.txt", "w", stdout);

#define ll long long
#define ff first
#define ss second

// #pragma GCC optimize("Ofast")
using namespace std;

int* insertX(int arr[], int x, int position) {
    int arraySize = sizeof(arr)/sizeof(arr[0]);
    for (int i=arraySize; i>position; i--) {
        arr[i] = arr[i-1];
    }
    arr[position]=x;
    return arr;
}

int dp[100005];
int height[100005];

void solve() {
    int n;
    cin>>n;
    loop(n) {
        cin>>height[i];
    }
    dp[0]=0;
    dp[1]=abs(height[1]-height[0]);
    for (int i=2; i<n; i++) {
        dp[i] = min((abs(height[i]-height[i-1])+dp[i-1]), (abs(height[i]-height[i-2])+dp[i-2]));
    }
    cout<<dp[n-1];
}

int main()
{
    //in out
    //TAJIKISTAN
    int t=1;
    //cin>>t;
    while (t--) {
        solve();
        cout<<'\n';
    }
    return 0;
}


Measured memory_bytes: 4332
#include<iostream>
#include<stdio.h>
#include<cmath>
using namespace std;
int main(){
	double x,h;

while(1){
	cin>>x;
	cin>>h;


	if(x==0&&h==0){
	break;
	}

	printf("%f\n",x*x+2*x*sqrt(h*h+x*x/4));
}
	return 0;
}


Measured memory_bytes: 3164
#include <iostream>
#include <vector>
#include <string>

using namespace std;

int main(){
    int n, k;
    cin >> n >> k;
    string s;
    cin >> s;
    
    int left = 0, right;

    int count = 0;
    for(right = 1; right < n; right++){
        if(s[right-1] == '0' && s[right] == '1')count++;
        if(count == k) break;
    }
    
    
    for(; right < n ; right++){
        if(right < n-1){
            if(s[right] == '1' && s[right+1] == '0') break;
        }
    }
    //cout << right << endl;
    if(right == n) cout << n << endl;
    else{
        int max = right+1;
        while(right < n-1){
            left++;
            for(; !(s[left-1] == '0' && s[left] == '1'); left++);
            right++;
            for(; !(s[right-1] == '0' && s[right] == '1') && right < n; right++);
            if(right == n) right--;
            //cout << right;
            for(; right < n-1; right++){
                if(s[right] == '1' && s[right+1] == '0') break;
            }
            //if(right == n-1) right--;
            //if(right == n-1 && s[n-1] == '1') cout << right++;
            if(max < (right - left + 1)) max = right - left + 1;
            
            //cout << left << " " << right << endl;
        }
        cout << max << endl;
    }
}

Measured memory_bytes: 512
/*
AOJ - ITP1_9_b
Date: 20181007
Author: Mikoron * ♡mikoiwate_351♡
 */

#define STRMAX 201

#include<stdio.h>
#include<stdlib.h>
#include<string.h>

int main(void) {
        char str[STRMAX], str_buf[STRMAX];
        short i, j, shf_cnt, shf_num, str_num;

        while(1) {
                scanf("%s", str);
                if(!(strcmp(str,"-"))) break;
                str_num = (short)strlen(str);
                scanf("%hd", &shf_cnt);
                for(i = 0; i < shf_cnt; i++) {
                        scanf("%hd", &shf_num);
                        strcpy(str_buf,str);
                        for(j = 0; j < str_num; j++) {
                                if(j < shf_num) str[str_num-shf_num+j] = str_buf[j];
                                else str[j-shf_num] = str_buf[j];
                        }
                }
                printf("%s\n", str);
        }
        return 0;
}



Measured memory_bytes: 2064
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef vector<ll> vl;
typedef pair<ll, ll> PP;
#define rep(i, n) for(ll i = 0; i < ll(n); i++)
#define all(v) v.begin(), v.end()
bool chmin(ll & a, ll  b) { if (b < a) { a = b; return 1; } return 0; }
bool chmax(ll & a, ll b) { if (b > a) { a = b; return 1; } return 0; }
const ll INF = 999999999999999;
const ll MOD = 1000000007;
const ll MAX_N=500010;
ll a, b, c, d, e, f, p, t, x, y, z, q, m, n, r, h, k, w, l, ans;
bool lamda(string S,string T){
    if(S.length()>T.length())return true;
    if(S.length()<T.length())return false;
    if(S>T)return true;
    return false;
}
int main() {
    ll A[9]={2,5,5,4,5,6,3,7,6};
    cin>>n>>m;
    vl ok(9,0);
    rep(i,m){
        cin>>x;
        ok[x-1]=1;
    }

    vector<string> V;
    string S;

    rep(i,n+1){
        if(i==0)V.push_back("");
        else V.push_back("!");
        rep(j,9){
            if(ok[j]==1&&i>=A[j]&&V[i-A[j]]!="!"){
                S=V[i-A[j]];
                char c='1'+j;
                S=S+c;
                if(lamda(S,V[i]))V[i]=S;
            }
        }
    }

    cout<<V[n]<<endl;
}


Measured memory_bytes: 41472
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, n) for(int i = 0; i < (n); i++)
#define MEM(a, x) memset(a, x, sizeof(a))
#define ALL(a) a.begin(), a.end()
#define UNIQUE(a) a.erase(unique(ALL(a)), a.end())
typedef long long ll;

int n, q, k;
vector<pair<int, ll> > g[100005];
ll dis[100005];
bool used[100005];

void setDis(int from) {
	FOR(i, g[from].size()) {
		int to = g[from][i].first;
		if (used[to]) continue;
		dis[to] = dis[from] + g[from][i].second;
		used[to] = true;
		setDis(to);
	}
	return;
}

int main(int argc, char const *argv[]) {
	ios_base::sync_with_stdio(false);
	cin >> n;
	FOR(i, n-1) {
		int a, b;
		ll c;
		cin >> a >> b >> c;
		g[a].push_back(make_pair(b, c));
		g[b].push_back(make_pair(a, c));
	}
	cin >> q >> k;
	used[k] = true;
	setDis(k);
	vector<ll> ans(q);
	FOR(i, q) {
		int x, y;
		cin >> x >> y;
		ans[i] = dis[x] + dis[y];
	}
	// FOR(i, n+1) cout << dis[i] << endl;
	FOR(i, q) cout << ans[i] << endl;
	return 0;
}

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

const ll INF = 1e17;

struct RU {
	using t1 = ll;
	using t2 = ll;
	static t2 id2() { return INF; }
	static t1 op2(const t1& l, const t2& r) { return min(l, r); }
	static t2 op3(const t2& l, const t2& r) { return min(l, r); }
};

template <typename M>
class lazy_segment_tree {
	using T1 = typename M::t1;
	using T2 = typename M::t2;
	const int h, n;
	vector<T1> data;
	vector<T2> lazy;
	void push(int node) {
		if (lazy[node] == M::id2()) return;
		lazy[node << 1] = M::op3(lazy[node << 1], lazy[node]);
		lazy[(node << 1) | 1] = M::op3(lazy[(node << 1) | 1], lazy[node]);
		lazy[node] = M::id2();
	}
public:
	lazy_segment_tree(int n_, T1 v1)
		: h(ceil(log2(n_))), n(1 << h), data(n_, v1), lazy(n << 1, M::id2()) {}
	lazy_segment_tree(const vector<T1>& data_)
		: h(ceil(log2(data_.size()))), n(1 << h), data(data_), lazy(n << 1, M::id2()) {}
	void update(int l, int r, T2 val) {
		l += n, r += n - 1;
		for (int i = h; i > 0; i--) push(l >> i), push(r >> i);
		r++;
		while (l < r) {
			if (l & 1) lazy[l] = M::op3(lazy[l], val), l++;
			if (r & 1) r--, lazy[r] = M::op3(lazy[r], val);
			l >>= 1; r >>= 1;
		}
	}
	T1 find(int p) {
		T1 res = data[p]; p += n;
		while (p) res = M::op2(res, lazy[p]), p >>= 1;
		return res;
	}
};

int main()
{
	int N, M;
	cin >> N >> M;
	vector<int> L(M), R(M), C(M);
	vector<vector<pair<int, ll>>> G(N);
	for (int i = 0; i < M; i++) {
		cin >> L[i] >> R[i] >> C[i]; --L[i];
		G[L[i]].emplace_back(R[i], C[i]);
	}
	lazy_segment_tree<RU> lst(N, INF);
	lst.update(0, 1, 0);
	for (int i = 0; i < N; i++) {
		ll d = lst.find(i);
		for (auto e : G[i]) {
			lst.update(i, e.first, d + e.second);
		}
	}
	ll res = lst.find(N - 1);
	cout << (res == INF ? -1 : res) << endl;
	return 0;
}


Measured memory_bytes: 9600
#include <iostream>
#include <string>
#include <set>
#include <map>
#include <vector>
#include <numeric>
#include <tuple>
#include <cstdio>

using namespace std;

typedef long long ll;


#define rep(i,b) for(ll i=0;i<(b);++i)
#define rep1(i,b) for(ll i=1;i<=(b);++i)
#define vec vector
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl;

int N;
int s[110];

int dp[10010][110];

/*
int rec(int ans, int prob) {
   if (prob > N) {
      return ((ans % 10 == 0) ? 0 : ans);
   } else {
      if (dp[ans][prob] < 0) {
         dp[ans][prob] = max(rec(ans, prob + 1), rec(ans+s[prob], prob+1));
      }
      return dp[ans][prob];
   }
}
*/

int main() {
   cin >> N;
   rep1(i, N) {
      cin >> s[i];
   }
   rep(i, 10010) {
      dp[i][N+1] = ((i % 10 == 0) ? 0 : i);
      /*
      rep(j, N+1) {
         dp[i][j] = -1;
      }
      */
   }
   for (int j=N;j>=0;j--) {
      for (int i=0;i<=10000;i++) {
         if (i+s[j] <= 10000) {
            dp[i][j] = max(dp[i][j+1], dp[i+s[j]][j+1]);
         } else {
            dp[i][j] = dp[i][j+1];
         }
      }
   }
   cout << dp[0][0] << endl;
}


Measured memory_bytes: 4608
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using u64 = unsigned long long;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

int main() {
    int n, k;
    cin >> n >> k;
    vector<int> v(n);
    for (auto &&i : v) scanf("%d", &i);
    for (int i = k; i < n; ++i) {
        if(v[i-k] < v[i]) puts("Yes");
        else puts("No");
    }
    return 0;
}

Measured memory_bytes: 4040
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i,s,e) for(int (i) = (s);(i) <= (e);(i)++)
#define all(x) x.begin(),x.end()

/* include file*/
#include <functional>
#include <vector>
using namespace std;

template <class Monoid>
struct Segment {
  using Func = function<Monoid(Monoid, Monoid)>;

  vector<Monoid> node;
  Monoid ide;
  int n = 1;

  Func bin_f;
  Func update_f;

  Segment(const vector<Monoid>& init, Monoid ide_, Func f_, Func u_f)
    : bin_f(f_), ide(ide_), update_f(u_f) {
      int sz = init.size();
      while (n < sz) n *= 2;
      node.assign(n * 2 - 1, ide);
      for (int i = 0; i < sz; i++) node[i + n - 1] = init[i];
      for (int i = n - 2; i >= 0; i--)
        node[i] = bin_f(node[i * 2 + 1], node[i * 2 + 2]);
    }

  void update(int i, Monoid x) {
    i += n - 1;
    node[i] = update_f(node[i], x);
    while (i) {
      i = (i - 1) / 2;
      node[i] = bin_f(node[i * 2 + 1], node[i * 2 + 2]);
    }
  }

  Monoid get_inter(int a, int b, int k = 0, int l = 0, int r = -1) {
    if (r < 0) r = n;
    if (a <= l && r <= b) return node[k];
    if (r <= a || b <= l) return ide;

    Monoid lm = get_inter(a, b, k * 2 + 1, l, (l + r) / 2);
    Monoid rm = get_inter(a, b, k * 2 + 2, (l + r) / 2, r);
    return bin_f(lm, rm);
  }
};

// http://judge.u-aizu.ac.jp/onlinejudge/review.jsp?rid=2730414#1
// http://judge.u-aizu.ac.jp/onlinejudge/review.jsp?rid=2730425#1

int main(){
  i64 N;
  cin >> N;
  vector<int> a(N);
  rep(i,0,N - 1){
    cin >> a[i];
  }
  i64 ng = 1e9;
  i64 ok = 0;

  while(ng - ok > 1){
    int mid = (ok + ng) / 2;
    Segment<int> seg(vector<int>(202020,0),0,[](int a,int b){return a + b;},[](int a,int b){return a + b;});
    seg.update(101010,1);
    i64 cnt = 0;
    i64 sum = 0;
    for(int i = 0;i < N;i++){
      sum += (a[i] <= mid) ? 1 : -1;
      cnt += seg.get_inter(0,101010 + sum - 1 + 1);
      seg.update(101010 + sum,1);
    }
    if(cnt < (N + 1) * N / 4 + 1) ok = mid;
    else ng = mid;
  }
  cout << ok + 1<< endl;
}


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

#define NREP() for(ll i = 0; i < n; i++)
#define REP(i, n) for(ll i = 0; i < n; i++)
#define ALL(x) (x).begin(),(x).end()
#define MSG(x) cout << x << endl;
#define YN(x) x ? cout << "YES" << endl : cout << "NO" << endl;
#define Yn(x) x ? cout << "Yes" << endl : cout << "No" << endl;
#define yn(x) x ? cout << "yes" << endl : cout << "no" << endl;

using namespace std;
using ll = long long;
const static ll MOD = 1e9 + 7;

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

    vector<pair<ll, ll>> v;
    NREP() {
        ll ta, tb;
        cin >> ta >> tb;
        v.emplace_back(ta, tb);
    }

    sort(ALL(v));

    ll cnt = 0;
    ll idx = 0;
    while (cnt < k && idx < n) {
        cnt += v.at(idx).second;
        idx++;
    }

    MSG(v.at(idx-1).first)
    return 0;
}


Measured memory_bytes: 2420
#include <bits/stdc++.h>
using namespace std;
using pii = pair<int,int>;
using pll = pair<long long, long long>;
const long long INF = 1<<29;

const int MOD = 1000000007;
long long ruizyou(long long m,long long n){
  if(m == 0)return 0;
  if(m == 1)return 1;
  long long ans = 1;
  long long tmp = m;
  for(int i=0;i<=30;i++){
    if(n & (1<<i)){
      ans *= tmp;
      ans %= MOD;
    }
    tmp *= tmp;
    tmp %= MOD;
  }
  return ans;
}
long long kaizyou(long long x){
  if(x == 0)return 1;
  return x * kaizyou(x-1) % MOD;
}
long long comb(long long x,long long y){
  long long bunsi = kaizyou(x);
  long long bunbo = kaizyou(x-y) * kaizyou(y) % MOD;
  return bunsi * ruizyou((int)bunbo,MOD-2) % MOD;
}
struct unionfind{
  vector<int> par;
  vector<int> hukasa;
  unionfind(int n){
    par = vector<int>(n);
    hukasa = vector<int>(n,0);
    for(int i=0;i<n;i++){
      par.at(i) = i;
    }
  }
  int root(int x){
    if(par.at(x) == x)return x;
    return root(par.at(x));
  }
  void unite(int x,int y){
    int rx = root(x);
    int ry = root(y);
    if(rx == ry)return;
    if(hukasa.at(rx) >= hukasa.at(ry)){
      par.at(ry) = rx;
      hukasa.at(rx) = max(hukasa.at(ry) + 1,hukasa.at(rx));
    }
    else{
      par.at(rx) = ry;
    }
  }
  bool same(int x,int y){
    return root(x) == root(y);
  }
};
int ctoi(char a){
  return a - '0';
}
long long gcd(long long a,long long b){
  long long c = max(a,b);
  long long d = min(a,b);
  if(d % c == 0)return c;
  return gcd(c,d%c);
}
long long lcm(long long a,long long b){
  return a * b / gcd(a,b);
}
int main(){
  int n;
  cin >> n;
  vector<int> a(n);
  for(int i=0;i<n;i++){
    cin >> a.at(i);
    a.at(i)--;
  }
  vector<long long> b(n,0);
  for(int i=0;i<n;i++){
    b.at(a.at(i))++;
  }
  long long sum = 0;
  vector<long long> c(n);
  for(int i=0;i<n;i++){
    c.at(i) = b.at(i) * (b.at(i)-1) / 2;
    sum += c.at(i);
  }
  for(int k=0;k<n;k++){
    long long tmp = b.at(a.at(k));
    cout << sum - tmp * (tmp-1)/2 + (tmp-1)*(tmp-2)/2 << endl;
  }
}

Measured memory_bytes: 7200
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<string>
#include<iostream>
#include<cctype>
#include<cstdio>
#include<vector>
#include<stack>
#include<queue>
#include <algorithm>
#include<math.h>
#include<set>
#include<map>
#include <sstream>
#include<iomanip>
#include <ctype.h>

//#include<bits/stdc++.h>




using namespace std;
int main() {
	int n; cin >> n;
	string a;
	cin >> a;
	int x = 0, t = 0;
	for (int i = 1; i < a.size() ; i++) {
		string b = a.substr(0, i);
		string c = a.substr(i, a.size() - i);
		//bool f[100] = {};
		map<char,int>f;
		t = 0;
		
		for(int j=0;j<b.size();j++)
			for (int k = 0; k < c.size(); k++) {
				if (b[j] == c[k]) {
				//	cout << b[j] << "#" << t << endl;
					if (!f[b[j]])t++;

					//	cout << "#";
					f[b[j]] = 1;
			
				}
			}

		x = max(x,t);
	}
	cout << x << endl;
	return 0;
}

Measured memory_bytes: 256
x_s, y_s, x_t, y_t = map(int, input().split())
dist_x, dist_y = x_t - x_s, y_t - y_s

ans = ""
ans += ("R" * dist_x)
ans += ("U" * dist_y)
ans += ("L" * dist_x)
ans += ("D" * dist_y)
ans += "D"
ans += ("R" * (dist_x + 1))
ans += ("U" * (dist_y + 1))
ans += "LU"
ans += ("L" * (dist_x + 1))
ans += ("D" * (dist_y + 1))
ans += "R"

print(ans)

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

int main(){
  long long N, M;
  cin >> N >> M;
  vector<long long> Lighthouse(N);
  for(int i = 0; i < N; i++){
    cin >> Lighthouse.at(i);
  }
  vector<int> Good(N, 1);
  for(int i = 0; i < M; i++){
    int A, B;
    cin >> A >> B;
    if(Lighthouse.at(A - 1) > Lighthouse.at(B - 1)){
      Good.at(B - 1) = 0;
    }
    else if(Lighthouse.at(A - 1) < Lighthouse.at(B - 1)){
      Good.at(A - 1) = 0;
    }
    else if(Lighthouse.at(A - 1) == Lighthouse.at(B - 1)){
      Good.at(A - 1) = 0;
      Good.at(B - 1) = 0;
    }
  }
  int cnt = 0;
  for(int i = 0; i < N; i++){
    cnt += Good.at(i);
  }
  cout << cnt << endl;
}

Measured memory_bytes: 4320
#include <bits/stdc++.h>
using namespace std;
int main(){

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

Measured memory_bytes: 3564
#include<iostream>
#include<map>
using namespace std;
#define N (int)2e5
#define int long
int n;
int a[N], ans[N], b[N], buket[N + 1];
int solved[N];
int nC2[N + 1];
int nCr(int n, int r){
    if(n < r)
        return 0;
    int temp = 1, temp2 = 1;
    for(int i = n; i > n - r; i--){
        temp *= i;
    }
    for(int i = 2; i <= r; i++){
        temp2 *= i;
    }
    return temp / temp2;
}
signed main(){
    cin >> n;
    for(int i = 0; i < n; i++){
        nC2[i] = nCr(i, 2);
    }
    for(int i = 0; i < n; i++){
        cin >> a[i];
        buket[a[i]]++;
    }
    for(int i  = 0; i <= n; i++){
        b[buket[i]]++;
    }
    for(int i  = 0; i < n; i++){
        if(!solved[buket[a[i]]]){
            b[buket[a[i]]]--;
            b[buket[a[i]] - 1]++;
            for(int j = 1; j <= n; j++){
                solved[buket[a[i]]] += b[j] * nC2[j];
            }
            b[buket[a[i]]]++;
            b[buket[a[i]] - 1]--;
        }
        ans[i] = solved[buket[a[i]]];
    }
    for(int i = 0; i < n; i++){
        cout << ans[i] << endl;
    }
    return 0;
}

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

using namespace std;
typedef long long ll;
typedef long double ld;
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i,n) for(int i=n; i>-1; --i)
#define ALL(a) (a).begin(),(a).end()
#define FILL(a,n,x); REP(i,(n)){ (a)[i]=(x); }
#define CINA(a,n); REP(i,(n)){ cin >> (a)[i]; }
#define FILL2(a,n,m,x); REP(i,(n)){ REP(j,(m)){(a)[i][j]=(x);} }
#define CINA2(a,n,m); REP(i,(n)){ REP(j,(m)){cin >> (a)[i][j];} }
#define Liny "Yes\n"
#define Linn "No\n"
#define LINY "YES\n"
#define LINN "NO\n"

//cout << setfill('0') << right << setw(4) << 12; // "0012"
int keta(ll x){ if(x<10){return 1;} else{return keta(x/10) + 1;}}
int keta_wa(ll x){ if(x<10){return x;} else{return keta_wa(x/10) + x%10;} }
int ctoi(char c){ return ( (c>='0' && c<='9')? c - '0': 0 );}
int __stoi(string s){ return atoi(s.c_str()); }
ll sum(ll a[],ll N){ return accumulate(a,a+N,0LL);}
ll gcd(ll a,ll b){if(a<b)swap(a,b); return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){if(a<b){swap(a,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){a=b;} }
template<class T> bool isIn(T a,vector<T> v){ for(T x:v){ if(a==x){return true;}} return false;}
string strReplace(string s,string target, string replacement){
    if (!target.empty()) {
      std::string::size_type pos = 0;
      while ((pos = s.find(target, pos)) != std::string::npos) {
        s.replace(pos, target.length(), replacement);
        pos += replacement.length();
      }
    }
    return s;
}
const ll MOD = 1e9+7;
#define pii pair<int,int>
#define pll pair<ll,ll>
#define MP make_pair

bool DEBUG = 0;

template<class T> void dprint(T s){
  if(DEBUG){ cout << s << "\n"; }
}

const int MAX = 30000000;
ll f[MAX],finv[MAX],inv[MAX];
void COMinit(int N){
    f[0] = 1;
    f[1] = 1;
    finv[0] = 1;
    finv[1] = 1;
    inv[1] = 1;
    for(int i=2;i<=N;++i){
        f[i] = f[i-1]*i %MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD/i) %MOD;
        finv[i] = finv[i-1]*inv[i]%MOD;
    }
}
ll COM(int N, int K){
    if(N<K || N<0 || K <0){ return 0; }
    return f[N]*(finv[K]*finv[N-K]%MOD) %MOD;
}


int main(int argc,char* argv[]){
  if(argc>1 && argv[1][0]=='D'){ DEBUG=1;}
  dprint("start");

  ll N,K; cin>>N>>K;
  vector<ll> a(N); CINA(a,N); sort(ALL(a));
  
  COMinit(N);
  ll sum_max = 0LL;
  ll sum_min = 0LL;
  REP(i,N){
    sum_max += COM(i,K-1)*a[i];
    sum_max %= MOD;
    sum_min += COM(N-i-1,K-1)*a[i];
    sum_min %= MOD;
  }
  ll ans = (sum_max - sum_min+MOD)%MOD;
  cout << ans <<"\n";
  
}

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

vector<long long> A;

void func(string s, int n) {
  A.push_back(stoll(s));
  if (n == 10) return;
  char c = s.back();
  if (c != '0') {
    func(s + (char)(c - 1), n + 1);
  }
  func(s + c, n + 1);
  if (c != '9') {
    func(s + (char)(c + 1), n + 1);
  }
}

int main() {
  int K; cin >> K;
  for (int i = 1; i < 10; i++) func(to_string(i), 1);
  sort(A.begin(), A.end());
  cout << A.at(K-1) << endl;
}

Measured memory_bytes: 2420
#include <stdio.h>
#include <math.h>

int main(void)
{
	double a,b,c;
	double h,S,L;

	scanf("%lf %lf %lf", &a,&b,&c);
	c = (c*M_PI)/180;
	h = b*sin(c);
	S = h*a/2;
	L = a + b + sqrt(a*a + b*b - 2*a*b*cos(c));
	printf("%lf\n", S);
	printf("%lf\n", L);
	printf("%lf\n", h);
	return 0;
}



Measured memory_bytes: 2920
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <string>
#include <set>
#include <cstdint>
#include <numeric>
#define INF 1000000000
#define INF2 100000000000
#define LLINF 1000000000000000
#define MOD 1000000007
using namespace std;
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define LOOP(i,N) for(int i=0;i<N;i++)
#define LOOP1(i,N) for(int i=1;i<=N;i++)
typedef pair<int,int> P;
typedef pair<int,pair<int,int> > PP;
#define int long long

signed main(){
int a,b;
cin >> a>> b;
cout << a*b << endl;
}


Measured memory_bytes: 3632
#include <algorithm>
#include <iostream>
#include <vector>
#include <math.h>
#include <set>
#include <map>
#include <string>
#include <stack>
#include <queue>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <bitset>
#include <complex>
#include <unistd.h>
#include <cassert>
#include <cctype>
#include <random>
#include <time.h>
#define _USE_MATH_DEFINES
#define _GLIBCXX_DEBUG
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> plglg;
typedef pair<double, ll> pdlg;
typedef tuple<int, int, int> tiii;
typedef tuple<ll, ll, ll> tlglglg;
typedef tuple<double, double, double> tddd;
typedef complex<double> xy_t;
typedef vector<ll> vll;
typedef vector< vector<ll> > matrix;
#define REP(i, x, y) for(ll i = (ll)x; i < (ll)y; i++)
#define DREP(i, x, y, d) for(ll i = (ll)x; i < (ll)y; i += (ll)d)
#define PER(i, x, y) for(ll i = (ll)x; i > (ll)y; i--)
#define DPER(i, x, y, d) for(ll i = (ll)x; i > (ll)y; i -= (ll)d)
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
double pi = 3.141592653589793;
ll mod = 1000000007;
int intmax = 2147483647;
int intmin = -2147483648;
ll llmax = 9223372036854775807;
ll llmin = -9223372036854775807;
int iinf = intmax / 8;
ll inf = llmax / 8;
double eps = 1e-12;

struct edge {
    ll to, cost;
};

int V;
vector<edge> G[1000000];
ll d[1000000];
bool ok[1000000];

void addedge(int st, int ed, ll co) {
    edge e;
    e.to = ed;
    e.cost = co;
    G[st].push_back(e);
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N, u, v;
    cin >> N >> u >> v;
    u--;
    v--;
    fill(d, d + N + 5, -1);
    fill(ok, ok + N + 5, false);
    REP(i, 0, N - 1) {
        ll a, b;
        cin >> a >> b;
        addedge(a - 1, b - 1, 1);
        addedge(b - 1, a - 1, 1);
    }
    queue<ll> que;
    d[v] = 0;
    que.push(v);
    while (!que.empty()) {
        ll node = que.front();
        que.pop();
        REP(i, 0, G[node].size()) {
            edge e = G[node][i];
            if (d[e.to] == -1) {
                d[e.to] = d[node] + 1;
                que.push(e.to);
            }
        }
    }
    queue<ll> queb;
    queb.push(u);
    ll ans = d[u];
    ok[u] = true;
    while (!queb.empty()) {
        ll node = queb.front();
        queb.pop();
        REP(i, 0, G[node].size()) {
            edge e = G[node][i];
            if (!ok[e.to] && d[e.to] >= d[u] - d[u] / 2) {
                ans = max(ans, d[e.to]);
                queb.push(e.to);
                ok[e.to] = true;
            }
        }
    }
    cout << ans - 1 << endl;
}


Measured memory_bytes: 30592
#include <iostream>
#include <vector>
using namespace std;
vector<int> a[100005];
vector<int> g[100005];
bool e[100005];
int n,m;

void dfs(int v) {
  e[v] = true;

  for(int i = 0; i < g[v].size(); i++) {
    int u = g[v][i];
    if(!e[u]) dfs(u);
  }
  return;
}

int main() {
  cin >> n >> m;
  for(int i = 0; i < n; i++) {
    int k;
    cin >> k;
    for(int j = 0; j < k; j++) {
      int l;
      cin >> l;
      l--;
      a[l].push_back(i);
    }
  }

  for(int i = 0; i < m; i++) {
    for(int j = 1; j < a[i].size(); j++) {
      g[a[i][0]].push_back(a[i][j]);
      g[a[i][j]].push_back(a[i][0]);
    }
  }

  dfs(0);

  bool ok = true;

  for(int i = 0; i < n; i++)
    if(!e[i]) {
      ok = false;
      break;
    }

  if(ok) cout << "YES" << endl;
  else cout << "NO" << endl;
}
	
  


Measured memory_bytes: 9088
#!/usr/bin/env python3

n = int(input())

harr = [int(i) for i in input().split(' ')]

twojump = 0
onejump = abs(harr[1] - harr[0])
ans = onejump

for i in range(2, n):
    ans = min(abs(harr[i]-harr[i-1])+onejump, abs(harr[i]-harr[i-2])+twojump)
    twojump = onejump
    onejump = ans

print(ans)


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

using namespace std;
using ll = long long int;
constexpr ll M = 1e9 + 7;
inline ll sum_1(const ll n) { return ((n * (n + 1)) / 2) % M; }
inline ll sum_2(const ll n) { return ((n * (n + 1) * (2 * n + 1)) / 6) % M; }
inline ll sum_3(const ll n) { return (((n * (n + 1)) / 2) % M * ((n * (n + 1)) / 2) % M) % M; }
inline ll sum_1(const ll i, const ll j) { return (sum_1(j) - sum_1(i - 1) + M) % M; }
inline ll sum_2(const ll i, const ll j) { return (sum_2(j) - sum_2(i - 1) + M) % M; }
inline ll sum_3(const ll i, const ll j) { return (sum_3(j) - sum_3(i - 1) + M) % M; }

void solve() {
    int n;
    cin >> n;

    vector<pair<ll, ll>> A(n);
    for (int i = 0; i < A.size(); ++i) {
        cin >> A[i].first;
        A[i].second = i;
    }
    sort(A.begin(), A.end(), greater<pair<ll,ll>>());

    /**
     * dp[L][R] = max(dp[L-1][R] + A[i]*|idx-L|, dp[L][R-1] + A[i]*|idx-R|)
     * 0 <= L+R <= n
     */
    vector<vector<ll>> dp(n + 5, vector<ll>(n + 5, 0));

    for (int i = 0; i < n + 5; ++i) {
        dp[i][0] = dp[0][i] = LLONG_MIN;
    }
    dp[1][1] = 0;

    for (int i = 1; i <= n+1; ++i) {
        for (int j = 1; j <= n+1; ++j) {
            int curr_ele = (i - 1) + (j - 1) - 1;
            if (curr_ele < 0 || curr_ele >= n) {
                continue;
            }
            dp[i][j] = max(
                dp[i - 1][j] + A[curr_ele].first * abs(A[curr_ele].second - (i - 2)),
                dp[i][j - 1] + A[curr_ele].first * abs(n - (j - 1) - A[curr_ele].second));
        }
    }

    ll ans = 0;
    for (int i = 1; i <= n + 1; ++i) {
        ans = max(ans, dp[i][n-i+2]);
    }
    cout << ans << endl;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    #ifndef ONLINE_JUDGE
        freopen("in.in", "r", stdin);
        freopen("out.out", "w", stdout);
    #endif

    solve();

    return 0;
}


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

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


Measured memory_bytes: 3088
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//#include <boost/multiprecision/cpp_int.hpp>
//typedef boost::multiprecision::cpp_int ll;
typedef long double dd;
#define i_7 (ll)(1E9+7)
//#define i_7 998244353
#define i_5 i_7-2
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
typedef pair<ll,ll> l_l;
ll inf=(ll)1E16;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);
void Min(ll &pos,ll val){pos=min(pos,val);}
void Add(ll &pos,ll val){pos=mod(pos+val);}
dd EPS=1E-9;
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
////////////////////////////

int main(){
    ll a,b;
    string s;
    cin>>a>>s>>b;
    if(s=="+"){
        cout<<a+b<<endl;
    }else{
        cout<<a-b<<endl;
    }
    
    return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp15
{
    class Class323
    {
        static void Main()
        {
            string S = Console.ReadLine();
            string T = Console.ReadLine();
            int s = S.Length;
            int t = T.Length;
            if (s < t)
            {
                Console.WriteLine("UNRESTORABLE");
                return;
            }
            for(int i = s-t; i >= 0; i--)
            {
                bool frag = true;
                string A = S.Substring(i, t);
                for(int j = 0; j < t; j++)
                {
                    if (A[j] == T[j] || A[j] == '?') continue;
                    else frag = false;
                    break;
                }

                if (frag)
                {
                    string line = S.Substring(0, i);
                    line += T;
                    if (i + t + 1 < s)
                        line += S.Substring(i + t);
                    char[] L = line.ToCharArray();
                    for (int j = 0; j < s; j++)
                        if (L[j] == '?')
                            L[j] = 'a';
                    Console.WriteLine(string.Join("",L));
                    return;
                }
            }
            Console.WriteLine("UNRESTORABLE");
        }
    }
}


Measured memory_bytes: 13268
#include <math.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define PI acos(-1)
typedef unsigned long long int ull;
typedef long long int ll;
typedef long double ld;

int main(void) {
  /* 標準入力フラグ */
  int   scan;

  /* 数入力 */
  ll    answer;
  ll    n;
  ll    k; 
  answer = 0;
  scan = scanf("%lld", &n);
  scan = scanf("%lld", &k);
 
  /* プログラムを書く */

  answer = n * k;










  /* 数回答 */
  printf("%lld", answer);

  return (0);
}


Measured memory_bytes: 1732
n = int(input())

array = []
S = input()
for i in range(len(S)):
    array.append(S[i])

for _ in range(1, n):
    S = input()
    newArray = []
    for i in range(len(S)):
        if S[i] in array:
            newArray.append(S[i])
            array.remove(S[i])

    array = [newArray[i] for i in range(len(newArray))]

array.sort()

for i in array:
    print(i, end='')

print()


Measured memory_bytes: 3064
#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 h,w,k; 
    cin >> h >> w >> k;
    string grid[h];
    rep(i,0,h){
        cin >> grid[i];
    }

    int ans = 0;
    for(int i = 0; i < pow(2,h); i++){
        for(int j = 0; j < pow(2,w); j++){
            int tk = 0;
            for(int a = 0; a < h; a++){
                for(int b = 0; b < w; b++){
                    if((i>>a & 1) && (j>>b & 1) && grid[a][b] == '#'){
                        tk++;
                    }
                }
            }
            if(tk == k){
                ans++;
            }
        }
    }
    cout << ans << "\n";
}

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

#define rep(i, n)  for (int i = 0; i < (int) (n); i++)
#define Rrep(i, n) for (int i = ((int) n - 1); i >= 0; i--)
#define all(x)     (x).begin(), (x).end()
#define SZ(x)      ((int) (x).size())
#define INF 2e15
#define MOD 10e9 + 7

typedef vector <int> vint;
typedef long long    ll;



int main()
{
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);

    int n, k;
    ll  s;

    cin >> n >> k;
    cin >> s;

    vector <ll> seq(n);
    rep(i, k) {
        seq.at(i) = s;
    }
    for (int j = k; j < n; j++) {
        if (s == 1000000000) { seq.at(j) = s - 1; }
        else { seq.at(j) = s + 1; }
    }

    rep(i, n) {
        cout << seq.at(i);
        if (i + 1 != n) { cout << " "; }
    }

    return 0;
}


Measured memory_bytes: 2176
#include<iostream>
#include<cstdio>
#include<cstdlib>

using namespace std;

void input(int*,int);
bool linearSearch(int*,int,int);

int main(void){
    int n,q;
    int a[10000+1],b[500+1];
    int sum=0;
    cin>>n;
    input(a,n);
    
    cin>>q;
    input(b,q);
    
    for(int i=0;i<q;++i){
        if(linearSearch(a,n,b[i])) sum++;
    }
    
    cout<<sum<<endl;
    
    return 0;
}

void input(int* a,int b){
    for(int i=0;i<b;++i){
        cin>>*(a+i);
    }
}

bool linearSearch(int* a, int n, int key){
    a[n] = key;
    for(int i=0;i<n;++i){
        if(a[i]==key) return true;
    }
    return false;
}


Measured memory_bytes: 3108
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <cmath>
#include <iomanip>
#define rep(i, n) for(int i = 0; i < (int)(n); ++i)
using namespace std;
using lint = int64_t;

struct BinaryIndexedTree {
    int length;
    vector<int> node;
    BinaryIndexedTree (int N) : length(N + 1), node(length, 0) {}
    void add(int idx, int val) {
        for (int i = idx; i < length; i += (i & -i)) node[i] += val;
    }
    int getsum(int idx) {
        int ans = 0;
        for (int i = idx; i > 0; i -= (i & -i)) ans += node[i];
        return ans;
    }
};

int main() {
    int N;
    lint K;
    cin >> N >> K;
    vector<lint> a(N);
    rep(i, N) cin >> a[i];
    
    vector<lint> b(N + 1, 0);
    rep(i, N) b[i + 1] = b[i] + a[i];
    rep(i, N + 1) b[i] -= K * i;
    
    vector<pair<lint, int>> c(N + 1);
    rep(i, N + 1) c[i] = pair<lint, int>{b[i], i};
    sort(c.begin(), c.end());
    vector<int> d(N + 1);
    int cnt = 1;
    d[c[0].second] = cnt;
    for (int i = 1; i < N + 1; ++i) {
        if (c[i].first != c[i - 1].first) ++cnt;
        d[c[i].second] = cnt;
    }
    
    BinaryIndexedTree BIT(cnt);
    lint ans = 0;
    rep(i, N + 1) {
        ans += BIT.getsum(d[i]);
        BIT.add(d[i], 1);
    }
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 8064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = (int)1e9 + 7;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
#define REP(i, n) for (int i = 0; i < (n); i++)
#define FOR(i,s,n) for (int i = s; i < (n); i++)
#define ALL(obj) (obj).begin(), (obj).end() //コンテナじゃないと使えない!!
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N,W;
    cin >> N >> W;
    vector<ll> val(N),weight(N);
    REP(i,N){
        cin >> val[i] >> weight[i];
    }
    vector<vector<ll>> dp(N+1,vector<ll>(W+1));
    REP(i,N){
        REP(w,W+1){
            if(w>=weight[i])
                dp[i+1][w] = dp[i][w-weight[i]] + val[i];
            chmax(dp[i+1][w], dp[i][w]);
        }
    }

    ll ans = dp[N][W];
    cout << ans << endl;
}




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

// ----------- define --------------
#define int long long
#define vi vector<int>
#define vc vector<char>
#define ii pair<int,int>
#define fi first
#define sc second
#define all(x) (x).begin(),(x).end()
#define get_bit(x, k) ((x >> k) & 1)
// ---------------------------------

void MAIN() {
  int n; cin >> n;
  int q = 1, d = n;
  for (int i = 1; i <= 5; i++) {
    int t; cin >> t;
    if (t >= n) continue;
    else {
      q = max(q, (n + t - 1) / t);
      d = t;
    }
  }
  cout << q + 4 << '\n';
}

signed main() {
  ios::sync_with_stdio(0); cin.tie(0);
  int T = 1;
  // cin >> T;
  while (T--) MAIN();
}


Measured memory_bytes: 3640
# import math
# x, y = map(int, input().split())
# a = (4 * x - y) / 2
# if a >= 0 and a <= x and a == math.ceil(a):
#     print('Yes')
# else:
#     print('No')


x, n = map(int, input().split())
p = list(map(int, input().split()))
# print(p)
for i in range(1000):
    if x - i not in p:
        print(x - i)
        break
    elif x + i not in p:
        print(x + i)
        break


Measured memory_bytes: 9168
#!/usr/bin/env python3
import sys
from collections import Counter

input = sys.stdin.readline


def S():
    return input().rstrip()


def I():
    return int(input())


def MI():
    return map(int, input().split())


n = I()
sl = [S() for _ in range(n)]

c = Counter(sl)
print("AC x " + str(c["AC"]))
print("WA x " + str(c["WA"]))
print("TLE x " + str(c["TLE"]))
print("RE x " + str(c["RE"]))


Measured memory_bytes: 16620
A, B, C, D, E, F = map(int, input().split())

ab_list = []
for a in range(F//100+1):
    for b in range(F//100+1):
        x = A*a + B*b
        if (0 < 100*x <= F) and (x not in ab_list):
            ab_list.append(x)

cd_list = []
for c in range(F+1):
    for d in range(F+1):
        y = C*c + D*d
        if (y <= F) and (y not in cd_list):
            cd_list.append(y)

max_conc = 0
result = [0, 0]
for i in ab_list:
    for j in cd_list:
        if (100*i + j <= F) and (j <= E*i):
            conc = (100*j) / (100*i + j)
            if conc >= max_conc:
                max_conc = conc
                result = [100*i + j, j]

print(result[0], result[1])

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#include <string>
using namespace std;
using ll=long long;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define inf 1001001001
typedef pair<int,int> P;
#define mod 1000000007


int main(){
    int a,b,s;
    bool flag=true;
    cin >> a >> b;
    rep(i,a+b+1){
        char c;
        cin >> c;
        if(i!=a){
            if(!('0'<=c&&c<='9'))flag=false;
        }
        else {
            if(c!='-') flag=false;
        }
    }
    if(flag) cout << "Yes" << endl;
    else cout <<"No"<<endl;

}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace abc073
{
    class Program
    {
        static void Main(string[] args)
        {
            string str = Console.ReadLine();
            if (str[0] == '9' || str[1] == '9')
            {
                Console.WriteLine("Yes");
            }else
            {
                Console.WriteLine("No");
            }
        }
    }
}


Measured memory_bytes: 11092
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line1 = br.readLine();
		String line2 = br.readLine();
		int counts = Integer.parseInt(line1);
		int[] bossCount = new int[counts];
		String[] bosses = line2.split(" ");
		for(int i = 0; i < counts; i++) {
			bossCount[i] = 0;
		}
		for(int i = 0; i < bosses.length; i++) {
			int index = Integer.parseInt(bosses[i]);
			bossCount[index - 1] += 1;
		}
		for (int i : bossCount) {
			System.out.println(i);
		}
	}
}


Measured memory_bytes: 65336
#include <cmath>
#include <functional>
#include <fstream>
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <map>
#include <list>
#include <time.h>
#include <math.h>
#include <random>
#include <deque>
#include <queue>
#include <cassert>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <bitset>
#include <sstream>
#include <chrono>
#include <cstring>

using namespace std;

typedef long long ll;

#ifdef iq
  mt19937 rnd(228);
#else
  mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());
#endif

int main() {
#ifdef iq
  freopen("a.in", "r", stdin);
#endif
  ios::sync_with_stdio(0);
  cin.tie(0);
  ll a, b, v, w, t;
  cin >> a >> v >> b >> w >> t;
  if (a < b) {
    if (a + t * (ll) v >= b + t * (ll) w) {
      cout << "YES\n";
    } else {
      cout << "NO\n";
    }
  } else {
    if (a - t * (ll) v <= b - t * (ll) w) {
      cout << "YES\n";
    } else {
      cout << "NO\n";
    }
  }
}


Measured memory_bytes: 3652
import java.util.*;
 
class Main{
 
    void solve(){
        Scanner sc = new Scanner(System.in);
 
        while(true){
            int n = sc.nextInt();
            if(n==0) break;
 
            long[][] dp = new long[2][1<<17];
 
            int idx = 0;
            long max = 0;
            for(int i=0; i<n; i++){
                int m = sc.nextInt();
                int L = sc.nextInt();
                int bit = 0;
                for(int j=0; j<m; j++){
                    int s = sc.nextInt()-6;
                    int e = sc.nextInt()-6;
                    for(int k=s+1; k<=e; k++){
                        bit ^= (1<<k);
                    }
                }
                for(int j=0; j<(1<<17); j++){
                    dp[idx][j] = Math.max(dp[idx][j], dp[1-idx][j]);
                    if((j&bit)==bit){
                        dp[idx][j] = Math.max(dp[idx][j], L + dp[1-idx][j^bit]);
                        max = Math.max(max, dp[idx][j]);
                    }
                }
                
                idx = 1-idx;
                Arrays.fill(dp[idx], 0);
            }
 
            System.out.println(max);
        }
    }
 
    public static void main(String[] args){
        new Main().solve();
    }
}

Measured memory_bytes: 64588