akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"
#include "ext/pb_ds/assoc_container.hpp"
#include "ext/pb_ds/tree_policy.hpp"

using namespace std;
using namespace __gnu_pbds;


#define ll long long int
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(a) a.begin(),a.end()

typedef tree <ll, null_type, less <ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
// order_of_key(val): returns the number of values less than val
// find_by_order(k): returns an iterator to the kth largest element (0-based)
ll dp[101][100001], mod = 1e9 + 7, pref[100001];
int main(void)
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n, k;
    cin>>n>>k;
    ll a[n + 1], i, j;
    for(i = 1; i <= n; i++) {
    	cin>>a[i];
    }
    dp[0][0] = 1;
    for(i = 1; i <= n; i++) {
    	pref[0] = dp[i-1][0];
    	for(j = 1; j <= k; j++) {
    		pref[j] = pref[j-1] + dp[i-1][j];
    	}
    	for(j = 0; j <= k; j++) {
			ll l = max((ll)0, j - a[i]);
			ll r = j;
			dp[i][j] = pref[r]%mod;
			if(l != 0) {
				dp[i][j] = ((dp[i][j] - pref[l - 1]) % mod + mod)%mod;
			}
    	}
    }
    cout<<dp[n][k]<<"\n";
}

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



int main(){
  int H,W; cin >> H >> W;
  bool board_check[H][W];
  for(int i=0;i<H;i++){for(int j=0;j<W;j++) {board_check[i][j]=true;}}
  string board[H];
  for(int i=0;i<H;i++){cin >> board[i];}
  
  for(int i=0;i<H;i++){
    bool flag = false;
    for(int j=0;j<W;j++){
      flag += (board[i][j]=='#');
    }
    if(!flag){
      for(int j=0;j<W;j++){
        board_check[i][j] = false;
      }
    }
  }
  
  for(int j=0;j<W;j++){
    bool flag = false;
    for(int i=0;i<H;i++){
      flag += (board[i][j]=='#');
    }
    if(!flag){
      for(int i=0;i<H;i++){
        board_check[i][j] = false;
      }
    }
  }
  
  for(int i=0;i<H;i++){
    bool line_f = false;
    for(int j=0;j<W;j++){
      if(board_check[i][j]){
        cout << board[i][j];
        line_f = true;
      }

    }
    if(line_f){
      cout << endl;
    }
  }
  
  
}

Measured memory_bytes: 256
def abc159d_banned_k():
    def cmb(n, r):
        """ nCrの組み合わせ数を返す """
        if n - r < r: r = n - r
        if r == 0: return 1
        if r == 1: return n

        numerator = [n - r + k + 1 for k in range(r)]
        denominator = [k + 1 for k in range(r)]

        for p in range(2,r+1):
            pivot = denominator[p - 1]
            if pivot > 1:
                offset = (n - r) % p
                for k in range(p-1,r,p):
                    numerator[k - offset] /= pivot
                    denominator[k] /= pivot

        result = 1
        for k in range(r):
            if numerator[k] > 1:
                result *= int(numerator[k])

        return result
    n = int(input())
    a = list(map(int, input().split()))
    dict_a = {}
    for item in a:
        if item in dict_a.keys():
            dict_a[item] += 1
        else:
            dict_a[item] = 1
    cnt = 0
    for k in dict_a:
        if dict_a[k] > 1:
            cnt += cmb(dict_a[k],2)
    for item in a:
        if dict_a[item] > 2:
            print(cnt - cmb(dict_a[item],2) + cmb(dict_a[item]-1,2))
        elif dict_a[item] == 2:
            print(cnt - 1)
        else:
            print(cnt)

abc159d_banned_k()

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

using namespace std;

int main(void) {
    int N;
    cin >> N;
    int ans = 0;
    int tmp = 0;
    int h0;
    cin >> h0;
    for(int i=1; i<N; i++) {
        int h1;
        cin >> h1;
        if(h1 <= h0) {
            tmp++;
        } else {
            tmp = 0;
        }
        h0 = h1;
        ans = max(ans, tmp);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
// B - Bitter Alchemy
// https://beta.atcoder.jp/contests/abc095/tasks/abc095_b
//
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <numeric>
using namespace std;


int solve(int X, vector<int> M);


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

    int N, X;
    cin >> N >> X;
    vector<int> M(N);
    for (int i = 0; i < N; ++i)
        cin >> M[i];

    int ans = solve(X, M);
    cout << ans << endl;
}


int solve(int X, vector<int> M) {
    int ans = 0;
    int total = accumulate(M.begin(), M.end(), 0);

    if (X < total)
        return ans;
    ans += M.size();
    X -= total;

    ans += (X / *min_element(M.begin(), M.end()));
    return ans;
}


Measured memory_bytes: 256
//https://atcoder.jp/contests/arc077/tasks/arc077_d

#include<bits/stdc++.h>
const int N = 2e5 + 5;
using namespace std;

string s;
int Z[N], n;
long long l, r, cnt[1000], ch[1000][26], ans[26];

void cal(long long x, int v){
    int cur = 0;
    while (cnt[cur] < x) cur++;
    while (x){
        while (cnt[cur-1] >= x) cur--;
        if (x <= cnt[0]){
            for (int i = 0; i < x; i++) ans[s[i] - 'a'] += v;
            break;
        }
        if (cnt[cur] == x){
            for (int i = 0; i < 26; i++) ans[i] += ch[cur][i] * v;
            x = 0;
        }
        else{
            for (int i = 0; i < 26; i++) ans[i] += ch[cur-1][i] * v;
            x -= cnt[cur-1];
        }
    }
}

int main(){
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    cin >> s >> l >> r; n = s.size();
    for (int i = 1, l = 0, r = 0; i < n; i++){
        if (i <= r) Z[i] = min(r-i+1, Z[i-l]);
        while (i + Z[i] < n && s[Z[i]] == s[i+Z[i]]) Z[i]++;
        if (i + Z[i] - 1 > r) l = i, r = i + Z[i] - 1;
    }
    for (int i = 1; i < n; i++) if (i > n/2 && i + Z[i] == n){
        s.resize(i); n = i; break;
    }
    cnt[0] = n;
    for (int i = 1; i < n; i++) if (i + Z[i] >= n){
        cnt[1] = cnt[0] + i;
        break;
    }
    if (!cnt[1]) cnt[1] = 2 * cnt[0];
    if (cnt[0] % (cnt[1] - cnt[0]) == 0){
        int siz = cnt[1] - cnt[0];
        for (int i = 0; i < siz; i++) ans[s[i] - 'a'] += (r+siz-i-1) / siz - (l-1+siz-i-1) / siz;
        for (int i = 0; i < 26; i++) cout << ans[i] << " ";
        return 0;
    }

    for (int i = 0; i < n; i++) ch[0][s[i] - 'a']++, ch[1][s[i] - 'a']++;
    for (int i = 0; i < (cnt[1] - cnt[0]); i++) ch[1][s[i] - 'a']++;

    for (int i = 2; cnt[i-1] <= r; i++) {
        cnt[i] = cnt[i-1] + cnt[i-2];
        for (int j = 0; j < 26; j++) ch[i][j] = ch[i-1][j] + ch[i-2][j];
    }
    cal(r, 1); cal(l-1, -1);

    for (int i = 0; i < 26; i++) cout << ans[i] << " ";
}


Measured memory_bytes: 1428
#include<stdio.h>
#include<iostream>
#include<cmath>
using namespace std;

int main() {
	int a, b, c, A, B, C, n;
	cin >> n;
	for(int i = 0; i < n; i++) {
		cin >> a >> b >> c;
		A = a*a; B = b*b; C = c*c;
		if(A == B + C || B == A + C || C == A + B) {
			printf("YES\n");
		}else printf("NO\n");
	}

	return 0;
}

Measured memory_bytes: 1116
//#pragma GCC optimize("O3", "unroll-loops")
//#pragma GCC target("avx2")
#include<bits/stdc++.h>

#define FAST ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define FIXED cout << fixed << setprecision(12)
#define RANDOM srand(94385)
#define all(a) a.begin(), a.end()
#define shuffle(a) \
    for (int i = 0; i < sz(a); ++i) \
        swap(a[i], a[rand() % sz(a)]);
#define enter putchar('\n')
#define space putchar(' ')
#define Mem(a, x) memset(a, x, sizeof(a))
using namespace std;

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

void debug_out() { cerr << '\n'; }

template<typename T, typename ...R>
void debug_out(const T &f, const R &...r) {
    cerr << f << " ";
    debug_out(r...);
}

#define debug(...) cerr << "[" << #__VA_ARGS__ << "]: ", debug_out(__VA_ARGS__);

inline ll read() {
    ll x = 0;
    int f = 0;
    char ch = getchar();
    while (ch < '0' || ch > '9') f |= (ch == '-'), ch = getchar();
    while (ch >= '0' && ch <= '9') x = (x << 3) + (x << 1) + ch - '0', ch = getchar();
    return x = f ? -x : x;
}

inline void write(ll x) {
    if (x == 0) {
        putchar('0');
        return;
    }
    if (x < 0) {
        putchar('-');
        x = -x;
    }
    static char s[23];
    int l = 0;
    while (x != 0)s[l++] = x % 10 + 48, x /= 10;
    while (l)putchar(s[--l]);
}

int lowbit(int x) { return x & (-x); }

template<class T>
T big(const T &a1, const T &a2) { return a1 > a2 ? a1 : a2; }

template<typename T, typename ...R>
T big(const T &f, const R &...r) { return big(f, big(r...)); }

template<class T>
T sml(const T &a1, const T &a2) { return a1 < a2 ? a1 : a2; }

template<typename T, typename ...R>
T sml(const T &f, const R &...r) { return sml(f, sml(r...)); }

template<class T, class U>
inline void checkMin(T &x, U y) { if (y < x) x = y; }

template<class T, class U>
inline void checkMax(T &x, U y) { if (y > x) x = y; }

template<class T, class U>
inline bool ifMax(T &x, U y) {
    if (y > x) return x = y, true;
    return false;
}

template<class T, class U>
inline bool ifMin(T &x, U y) {
    if (y < x) return x = y, true;
    return false;
}

const int M = 212345;// 2e5+5
const int inf = 0x3f3f3f3f;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const int mod = 1000000007;// 1e9+7

// HAVE FREE OPEN IN MAIN FUNCTION

int a[M], b[M], c[M];
int n;

void init() {
    n = read();
    for (int i = 1; i <= n; ++i) {
        a[i] = read();
    }
    for (int i = 1; i <= n; ++i) {
        b[i] = read();
    }
    for (int i = 1; i < n; ++i) {
        c[i] = read();
    }
    int ans = 0;
    for (int i = 1; i <= n; ++i) {
        ans += b[a[i]];
        if (a[i + 1] == a[i] + 1)ans += c[a[i]];
    }
    write(ans), enter;

}

void solve() {

}

int main() {
    init();

    solve();

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ldb = long double;
using pa = pair < ll, ll >;
using vec = vector < ll >;
#define pb push_back
#define F  first
#define S  second
#define int ll
#define f(i,x,n) for(ll i=x;i<n;i++) 
#define all(c) c.begin(),c.end()
#define edl "\n"
#define ceils(s,n) (s+n-1)/n
#define str string
#define add insert
#define fast() ios_base::sync_with_stdio(false);cin.tie(NULL)
const int MOD = 1e9 + 7, N = 1e5 + 10;
const ll LINF = LLONG_MAX;
ll a,b,c,sum;
str s,s1,s2;
int32_t main() {
    fast();
    cin >> s1;
    s2=s1;
    reverse(all(s1));
    ll c=0;
    f(i,0,s1.size()){
    	if(s1[i]!=s2[i]){
    		c++;
    	}
    }
    cout<<c/2;

    cerr << "\nTime taken: " << int((clock() * 1000.) / CLOCKS_PER_SEC) << "ms\n";
    return 0;
}
 

Measured memory_bytes: 256
import sys
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt, ceil, floor
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache, reduce
from operator import xor
INF = float("inf")
sys.setrecursionlimit(10**7)

# 4近傍（右, 下, 左, 上）
dy = [0, -1, 0, 1]
dx = [1, 0, -1, 0]


def inside(y: int, x: int, H: int, W: int) -> bool: return 0 <= y < H and 0 <= x < W


def solve(N, l):
    a, b = min(l), max(l)
    if b - a > 1:
        return False
    if a == b:
        if a == N - 1:
            return True
        return N >= (a * 2)

    num_a = l.count(a)

    return num_a < b and num_a + 2 * (b - num_a) <= N


def main():
    N = int(input())
    a_list = list(map(int, input().split()))
    print("Yes" if solve(N, a_list) else "No")

if __name__ == '__main__':
    main()


Measured memory_bytes: 14848
#include <algorithm>
#include <cstdio>
const int MAXN = 505;
int C[MAXN], F[MAXN], S[MAXN];
int N;
 
int main()
{
	scanf("%d", &N);
	for(int i = 1; i < N; ++i)
		scanf("%d%d%d", &C[i], &S[i], &F[i]);
	for(int i = 1; i <= N; ++i)
	{
		int time = 0;
		for(int j = i; j < N; ++j)
		{
			time  = std::max(S[j], time);
			int R = (time-S[j]) % F[j];
			if(R) time += F[j]-R;
			time += C[j];
		}
		printf("%d\n", time);
	}
	return 0;
}

Measured memory_bytes: 128
fun main(args: Array<String>) {
    val s = readLine()!!
    val n = s.length

    if (s == s[0] + "9".repeat(n - 1)) {
        println(s[0] - '0' + 9 * (n - 1))
    } else {
        println(s[0] - '1' + 9 * (n - 1))
    }
}

Measured memory_bytes: 33724
N = int(input())
B = list(map(int, input().split()))
count = {}

for i in B:
  if i in count:
    count[i] += 1
  else:
    count[i] = 1
    
total = 0
for i in count:
  total += count[i]*(count[i]-1)/2
  
for i in range(N):
  k = count[B[i]]
  print(int(total-k+1))

Measured memory_bytes: 25644
#include <iostream>
#include <cmath>
#include <cstring>
#include <string>
#include <algorithm>
#include <cstdio>
#include <vector>
using namespace std;

const int maxn = 105, inf = 0x3f3f3f3f;
int M, N;
int X1[maxn], Y1[maxn], X2[maxn], Z2[maxn];

//计算按x值对多边形切片得到的宽度
double width(int * X, int * Y, int n, double x)
{
    double lb = inf, ub = -inf;
    for (int i=0; i<n; ++i)
    {
        double x1 = X[i], y1 = Y[i], x2 = X[(i + 1) % n], y2 = Y[(i + 1) % n];
        //检查与第i条边是否相交
        if ((x1 - x) * (x2 - x) <= 0 && x1 != x2)
        {
            //计算交点坐标
            double y = y1 + (y2 - y1) * (x - x1) / (x2 - x1);
            lb = min(lb, y);
            ub = max(ub, y);
        }
    }
    return max(0.0, ub - lb);
}

void solve()
{
    //枚举区间的端点
    int min1 = *min_element(X1, X1 + M), max1 = *max_element(X1, X1 + M);
    int min2 = *min_element(X2, X2 + N), max2 = *max_element(X2, X2 + N);
    vector<int> xs;
    for (int i=0; i<M; ++i) xs.push_back(X1[i]);
    for (int i=0; i<N; ++i) xs.push_back(X2[i]);
    sort(xs.begin(), xs.end());
    
    double res = 0;
    for (int i=0; i+1<xs.size(); ++i)
    {
        double a = xs[i], b = xs[i+1], c = (a + b) / 2;
        if (min1 <= c && c <= max1 && min2 <= c && c <= max2)
        {
            //利用Simpson公式求积分
            double fa = width(X1, Y1, M, a) * width(X2, Z2, N, a);
            double fb = width(X1, Y1, M, b) * width(X2, Z2, N, b);
            double fc = width(X1, Y1, M, c) * width(X2, Z2, N, c);
            res += (b - a) / 6 * (fa + 4 * fc + fb);
        }
    }
    printf("%.10f\n", res);
    return;
}

int main()
{
    while (~scanf("%d %d", &M, &N) && (M + N))
    {
        for (int i=0; i<M; ++i) scanf("%d %d", &X1[i], &Y1[i]);
        for (int i=0; i<N; ++i) scanf("%d %d", &X2[i], &Z2[i]);
        solve();
    }
    return 0;
}



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

using namespace std;

typedef long long int ll;

const ll INF=1e9+7;

int main(){
    ll n,weight,N=0;
    cin>>n>>weight;
    ll w[n+1],v[n+1],ans=-1;
    for(ll i=1;i<=n;i++)
        cin>>w[i]>>v[i];
    
    for(int i=1;i<=n;i++)
        N+=v[i];

    ll dp[n+1][N+1];
    for(int i=0;i<=n;i++){
        for(int j=0;j<=N;j++)
            dp[i][j]=INF;
    }
    
   for(int i=1;i<=n;i++){
        for(int j=0;j<=N;j++){
            if(v[i]>j) dp[i][j]=dp[i-1][j];
            else if(v[i]==j) dp[i][j]=min(w[i],dp[i-1][j]);
            else dp[i][j]=min(dp[i-1][j-v[i]]+w[i],dp[i-1][j]);
        }
    }

    for(ll j=N;j>=0;j--){
        if(dp[n][j]<=weight)
            ans=max(ans,j);
    }
    
    cout<<ans<<"\n";
    return 0;
}


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

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

    vector<int> L(10000);
    for(int i = 0; i < N; ++i){
        cin >> L.at(i);
    }

    int cnt = 0;
    int result = 0;

    for(int i = 0; i < N + 1; ++i) {
        if(i == 0) {
            result += 1;
            continue;
        }

        cnt = cnt + L.at(i - 1);
        if(cnt <= X) {
            result += 1;
        }
    }

    cout << result << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner s = new Scanner(System.in);

        final int kuji_num = s.nextInt();
        final Set<String> itemSet = new HashSet<String>();
        for (int i = 0 ; i <= kuji_num ; i++) {
            itemSet.add(s.nextLine());
        }
        System.out.println(itemSet.size() - 1);
  }
}

Measured memory_bytes: 79688
#include <iostream>
#include <stdio.h>
#include<vector>
#include<climits>
#include<algorithm>
#include<bitset>
#include<cmath>
#include<functional>
#include <numeric>
#include <map>
#define FORi(N) for(int i=0;i<N;++i)
#define FORj(N) for(int j=0;j<N;++j)
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
ll gcd(ll m,ll n){
  if(n==0)return abs(m);
  return(gcd(n,m%n));
}
void putYN(bool b){
  if(b){
    cout<<"YES"<<endl;
  }else{
    cout<<"NO"<<endl;
  }
}
vector<ll> dp(vector<ll>& b,ll n){//n以下をとる
  if(b.size()==0)return vector<ll>();
  vector<ll> c ,ret,d;
  for(int i=n-1;i>=0;--i){
    if(b[i]==i+1){
      c=b;
      c.erase(c.begin()+i);
      ret = dp(c,n-1);
      if(ret.size()==1&&ret[0]==-1)break;
      ret.push_back(i+1);
      return ret;
    }
  }
  
   ret = vector<ll>{-1};
  return ret;
}
int main(){
  ll N;
  cin>>N;
  vector<ll> b(N);
  FORi(N){
    cin>>b[i];
  }
  vector<ll> ret = dp(b,N);
  FORi(ret.size()){
    cout<<ret[i]<<endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<queue>
#include<stack>
#include<cassert>
#include<numeric>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
const int INF = 1001001001;
const long long LINF = 1001002003004005006ll;
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; }
typedef long long ll;
typedef pair<int,int> P;

int main(){
  int n,k,c;
  cin >> n >> k >> c;
  string s;
  cin >> s;
  vector<int> fast(n,-1);
  vector<int> slow(n,-1);
  int day = 1;
  rep(i,n){
    if(s[i]=='o'){
      fast[i]=day;
      if(day==k)break;
      day++;
      i+=c;
    }
  }
  for(int i=n-1;i>=0;i--){
    if(s[i]=='o'){
      slow[i]=day;
      day--;
      i-=c;
    }
  }
  rep(i,n){
    if(fast[i]==-1)continue;
    if(fast[i]==slow[i])cout << i+1 << endl;
  }
}

Measured memory_bytes: 5252
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;

typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;

template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const int MOD = 1000000007;
const ll INF = 1e18;
const int MX = 2000000001; //check the limits, dummy

bool is_prime(int x){
 if(x<=1) return false;
 for(int i=2;i*i<=x;i++)
 if(x%i==0) return false;
 return true;
 }
int main() {
	ios_base::sync_with_stdio(0); cin.tie(0);

     int n,k,l,sum=0,res=0;
     cin>>n;
    int p=n;
   while(!is_prime(p))p++;

   cout<<p;
	return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
vector<int> dp;
vector<bool> vis;
vector<vector<int>> edges;

void dfs(int node){
    vis[node] = true;

    for(int i=0;i<edges[node].size();i++){
        if(!vis[edges[node][i]]){
            dfs(edges[node][i]);
        }
        dp[node] = max(dp[node],1+dp[edges[node][i]]);
    }
}
int main(){
    int n,m;
    cin>>n>>m;
    edges.resize(n+1);
    for(int i = 0;i <m;i++){
        int x,y;
        cin>>x>>y;
        edges[x].push_back(y);
    }
    dp.resize(n+1,0);
    vis.resize(n+1,false);
    for(int i = 1;i<=n;i++){
        if(!vis[i]){
            dfs(i);
        }
    }
    int res = 0;
    for(int x:dp){
        res = max(res,x);
    }
    cout<<res;
    return 0;
}

Measured memory_bytes: 8192
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm> 

#define fo(i,j,l) for(int i=j;i<=l;++i)
#define fd(i,j,l) for(int i=j;i>=l;--i)

using namespace std;
typedef long long ll;
const ll N=22e4;

int a,b,c;

char s[N],c1[N],c2[N];
int n,q;
int le[N],ri[N];
int done[N];

char read()
{
	char ch=' ';
	for(;ch<'A'||ch>'Z';ch=getchar());
	return ch;
}

inline int judge(int o)
{
	if(o==0)return 0;
	if(o==n+1)return 2;
	fo(i,1,q)if(c1[i]==s[o]){
		if(c2[i]=='R')++o;
		else --o;
		if(o==0)return 0;
		if(o==n+1)return 2;
	}
	return 1;
}

int main()
{
	cin>>n>>q;
	scanf("%s",s+1);
	fo(i,1,q){
		c1[i]=read(),c2[i]=read();
	}
	int zb=0,yb=n+1;
	while(zb+1<yb){
		int mid=zb+yb>>1;
		if(judge(mid)>0)yb=mid;
		else zb=mid;
	}
	
	int o1=yb;
	if(judge(o1)!=1){
		puts("0"); return 0;
	}
	
	zb=0,yb=n+1;
	while(zb+1<yb){
		int mid=zb+yb>>1;
		if(judge(mid)<2)zb=mid;
		else yb=mid;
	}
	
	int ans=zb-o1+1;
	if(ans<0)ans=0;
	cout<<ans;
}

Measured memory_bytes: 896
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <math.h> // sqrt
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <iomanip> // setprecision
#include <bitset> // bitset
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vb = vector<bool>;
using vll = vector<long long>;
using pii = pair<int, int>;
using psi = pair<string, int>;

int main() {
    int N, M;
    cin >> N >> M;
    vector<vi> data(N + 1);
    for (int i = 0; i < M; i++) {
        int a, b;
        cin >> a >> b;
        data[a].push_back(b);
        data[b].push_back(a);
    }
    vi per(N);
    for (int i = 0; i < N; i++) {
        per[i] = i + 1;
    }
    int ans = 0;
    do {
        if (per[0] != 1) {
            break;
        }
        bool check;
        for (int i = 0; i < N - 1; i++) {
            check = true;
            for (int x : data[per[i]]) {
                if (x == per[i + 1]) {
                    check = false;
                    break;
                }
            }
            if (check) {
                break;
            }
        }
        if (!check) {
            ans++;
        }
    } while(next_permutation(per.begin(), per.end()));
    cout << ans << endl;
}


Measured memory_bytes: 3620
#include<stdio.h>
int main()
{
	int n,a,i,j,c,k,flg;
	scanf("%d",&n);
	flg=0;
	c=0;
	k=0;
	for(i=0;i<n;i++){
		scanf("%d",&a);
		if(a==1)	flg=1;
		else{
			flg=0;
			k=0;
		}
		if(flg==1){
			k++;
			if(c<=k)	c=k;
		}
	}
	printf("%d\n",c+1);
	return 0;
}
	
	
	


Measured memory_bytes: 2128
/*
	Swamy Saranam

	Date	: 28/01/2018 17:26:27
	Author	: Krishna Mohan A M
	Problem	:
	Status	:
*/
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;
typedef pair<int,int>	pii;
typedef pair<ld,ld>	pdd;
typedef vector<int> vi;
typedef vector<ld> vd;
typedef pair<ll,ll> pll;

#define FASTIO                ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define FOR(i,a,b)            for(int i=(a);i<(b);i++)
#define REP(i,n)              FOR(i,0,n)
#define SORT(v)               sort((v).begin(),(v).end())
#define UN(v)                 SORT(v),(v).erase(unique((v).begin(),(v).end()),(v).end())
#define CL(a,b)               memset(a,b,sizeof a)
#define PB                    push_back
#define F                     first
#define S                     second

const int MOD = 1000000007;
const int N = 1e3+5;

int n, dat[2][N];

int main()
{
      FASTIO
      cin>>n;
      REP(i, 2){
            REP(j, n){
                  cin>>dat[i][j];
            }
      }
      REP(i, 2){
            REP(j, n){
                  int tmp = dat[i][j];
                  if(i>0)
                        tmp = max(tmp, dat[i][j]+dat[i-1][j]);
                  if(j>0)
                        tmp = max(tmp, dat[i][j]+dat[i][j-1]);
                  dat[i][j] = tmp;
                  // cout<<dat[i][j]<<" ";
            }
            // cout<<"\n";
      }
      cout<<dat[1][n-1]<<"\n";
      return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	private static long g1(long n, long p) {
		if (n == 0) return 0;
		return n / p + g1(n / p, p);
	}

	private static long g2(long n, long p) {
		if (n % 2 == 1) return 0;
		long a = g1(n / 2, p);
		if (p == 2) a += n / 2;
		return a;
	}

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long n = sc.nextLong();
		System.out.println(Math.min(g2(n, 2), g2(n, 5)));
	}
}


Measured memory_bytes: 21844
N, A, B, C = list(map(int, input().split()))
data = [int(input()) for i in range(N)]

INF = 10**11
def magic(i, a, b, c):
  if i == N:
    return abs(A-a) + abs(B-b) + abs(C-c)-30 if min([a, b, c]) > 0 else INF
  ret0 = magic(i+1, a, b, c)
  ret1 = magic(i+1, a+data[i], b, c)+10
  ret2 = magic(i+1, a, b+data[i], c)+10
  ret3 = magic(i+1, a, b, c+data[i])+10
  return min([ret0, ret1, ret2, ret3])

print(magic(0, 0, 0, 0))

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

int main() {
    int N;
    std::cin >> N;
    std::vector<int> a(N);
    for (auto& e : a) std::cin >> e;

    int M;
    std::cin >> M;
    std::vector<int> b(M);
    for (auto& e : b) std::cin >> e;

    std::cout << (a < b) << std::endl;
}

//g++ -o vector -std=c++14 -Wall -Wextra -pedantic-errors  vector.cc


Measured memory_bytes: 3100
N, K = map(int, input().split())
H = [0] + list(map(int, input().split())) + [0]

# dp[i][j] = minimum operations upto col i (fixed), with j moves remaining
dp = [[float('inf') for i in range(K+1)] for j in range(N+2)]
dp[0] = [0 for i in range(K+1)]

def cost(i, j):
    return max(0, H[j] - H[i])

for i in range(1, N+2):
    for j in range(K+1):
        for d in range(j+1):
            if i-d-1 < 0: break
            dp[i][j] = min(dp[i][j], cost(i-d-1, i) + dp[i-d-1][j-d])
                
print(dp[-1][K])


Measured memory_bytes: 47836
n = int(input())
s = []
cnt = 0
for i in range(n):
    s.append(int(input()))
    if s[i] % 10 == 0:
        cnt += 1

if cnt == n:
    print("0")
    exit(0)

if sum(s) % 10 != 0:
    print(sum(s))
else:
    s.sort()
    for i in range(n):
        if s[i] % 10 != 0:
            print(sum(s)-s[i])
            exit(0)


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

typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<int,P> P1;

#define fr first
#define sc second
#define mp make_pair
#define pb push_back
#define rep(i,x) for(int i=0;i<x;i++)
#define rep1(i,x) for(int i=1;i<=x;i++)
#define rrep(i,x) for(int i=x-1;i>=0;i--)
#define rrep1(i,x) for(int i=x;i>0;i--)
#define sor(v) sort(v.begin(),v.end())
#define rev(s) reverse(s.begin(),s.end())
#define lb(vec,a) lower_bound(vec.begin(),vec.end(),a)
#define ub(vec,a) upper_bound(vec.begin(),vec.end(),a)
#define uniq(vec) vec.erase(unique(vec.begin(),vec.end()),vec.end())
#define mp1(a,b,c) P1(a,P(b,c))

const int INF=1000000000;
const int dir_4[4][2]={{1,0},{0,1},{-1,0},{0,-1}};
const int dir_8[8][2]={{1,0},{1,1},{0,1},{-1,1},{-1,0},{-1,-1},{0,-1},{1,-1}};

int main(){
	int n;
	string s;
	cin >> n >> s;
	
	static int pre[500010];
	pre[0] = 0;
	rep(i,s.size()){
		if(s[i] == '0')pre[i+1] = 0;
		else pre[i+1] = pre[i]+1;
	}
	static int dp[500010];
	dp[0] = 0;
	rep(i,s.size()){
		dp[i+1] = dp[i];
		if(s[i] == '1' && i-pre[i+1]-1 >= 0 && s[i-pre[i+1]-1] == '1'){
			dp[i+1] = max ( dp[i+1] , dp[i-pre[i+1]-1] + pre[i+1] );
		}
		if(s[i] == '1' && i > 0 && s[i-1] == '0'){
			dp[i+1] = max( dp[i+1] , dp[i-1-pre[i-1]] + pre[i-1] );
			dp[i+1] = max( dp[i+1] , dp[i-pre[i-1]] + pre[i-1]-1 );
		}
	}
	cout << dp[n] << endl;
}
	
	/*int ret = 0;
	vector<int> vec;
	int loc = 0;
	while(loc < s.size()){
		while(loc < s.size() && s[loc] == '0')loc ++;
		if(loc >= s.size())break;
		while(1){
			int memo = loc;
			while(loc < s.size() && s[loc] == '1')loc ++;
			vec.pb(loc-memo);
			if(loc+1 >= s.size() || s[loc+1] == '0'){
				rep(i,vec.size()){
					ret += vec[i];
					cout << vec[i] << " ";
				}
				cout << endl;
				ret -= vec.size()-1;
				ret -= min(vec[0],vec[vec.size()-1])-1;
				vec.clear();
				break;
			}
			else loc ++;
		}
	}
	cout << ret << endl;
}*/
	
	/*static int dp[500010][2];
	int cnt = 0;
	int i = 0;
	while(i < n && s[i] == '0')i ++;
	dp[i][0] = 0;
	dp[i][1] = 0;
	for(;i<n;i++){
		if(s[i] == '0'){
			if(i+1 >= n || s[i+1] == '0'){
				int memo = max(dp[i][0],dp[i][1]);
				while(i+1 < n && s[i+1] == '0')i ++;
				dp[i+1][0] = memo;
				dp[i+1][1] = memo;
			}
			else{
				dp[i+2][0] = */


Measured memory_bytes: 4740
#include<iostream>
using namespace std;
int main(){
    int n,x,t;
    while(1){
        cin>>n>>x;
        t=0;
        if (n==0&&x==0) break;
        else{
            for (int a=1;a<=n;a++){
                if (a==n-1) break;
                else for (int b=a+1;b<=n;b++){
                    if (b==n) break;
                    else for (int c=b+1;c<=n;c++){
                        if (a+b+c==x) t+=1; 
                    }
                }
            }
        }
        cout<<t<<endl;
    }
    return 0;
}



Measured memory_bytes: 3088
import sys
def f():
 w=m=0;n,q=map(int,input().split());s=[0]*-~n
 for e in sys.stdin:
  a,v=map(int,e.split());s[a]+=v
  if v<0 and a==w:m=max(s);w=s.index(m)
  elif s[a]>m:w,m=a,s[a]
  elif s[a]==m:w=min(w,a)
  print(w,m)
f()


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

// macro
#define rep(i,n) for(i=0;i<n;i++)
#define ll long long
#define all(v) v.begin(), v.end()

// code starts
#define MOD 1000000007

int main()
{
	ll n,k;cin>>n>>k;
	ll ans=0;
	ans=n*(n+1)*(n+2)/6+k*(k-1)*(k*2-n*3-4)/6+(n-k+2);
	cout<<ans%MOD<<endl;
}


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

#define name ""
#define ini freopen(name".inp","r",stdin); freopen(name".out","w",stdout)
#define foe(it,c) for (__typeof(c.begin()) it = c.begin(); it != c.end(); it++)
#define long long long 
#define db double 
#define pii pair <int, int>
#define pll pair <long, long>
#define all(c) c.begin(), c.end()
#define fastio ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)

const int INF = 1e9+7;
const int MOD = 1e9+7;
const int dx[4] = {0,0,-1,1};
const int dy[4] = {-1,1,0,0};

const int N = 1e5+1;

int n, a[N], val[N], b[N];
long res[N];
vector <int> pos[N];

int main()
{
	fastio;
	cin >> n;
	for (int i = 1; i <= n; i++) cin >> a[i], b[i] = a[i];
	sort(a + 1, a + 1 + n);
	for (int i = 1; i <= n; i++){
		int x = lower_bound(a + 1, a + 1 + n, b[i]) - a;
		val[x] = b[i];
		pos[x].push_back(i);
	}
	int pre = -INF, x = INF;
	long cnt = 0;
	for (int i = n; i >= 0; i--){
		if (i == 0){
			res[x] += cnt * pre;
			break;
		}
		if (pos[i].size() == 0) continue;
		if (pre == -INF){
			x = pos[i][0];
			pre = val[i];
			cnt += pos[i].size();
		}	
		else {
			res[x] += cnt * (pre - val[i]);
			if (pos[i][0] < x) x = pos[i][0];
			cnt += pos[i].size();
			pre = val[i];
		}
	}
	for (int i = 1; i <= n; i++) cout << res[i] << '\n';
	return 0;
}

Measured memory_bytes: 8576
#include <stdio.h>

void add_BIT(int N, int BIT[], int i, int k)
{
	while (i <= N) {
		BIT[i] += k;
		i += (i & -i);
	}
}

long long sum_BIT(int BIT[], int r)
{
	long long sum = 0;
	while (r > 0) {
		sum += BIT[r];
		r -= (r & -r);
	}
	return sum;
}

long long inversion_number(int N, int A[], int B[])
{
	int i, a[100001], BIT[100001] = {};
	long long inv = 0;
	for (i = 1; i <= N; i++) a[A[i]] = i;
	for (i = N; i >= 1; i--) {
		inv += sum_BIT(BIT, a[B[i]]);
		add_BIT(N, BIT, a[B[i]], 1);
	}
	return inv;
}

int main()
{
	char S[200001];
	scanf("%s", S);
	
	int i, j, k, l, m, count[26] = {}, odd = -1;
	for (l = 0; S[l] != 0; l++) count[S[l] - 'a']++;
	for (i = 0; i < 26; i++) {
		if (count[i] % 2 == 1) {
			if (odd != -1) {
				printf("-1\n");
				fflush(stdout);
				return 0;
			} else odd = i;
		}
	}
	
	char T[200001];
	int tmp[26] = {};
	long long ans = 0;
	if (odd == -1) {
		for (i = 0, j = 0, k = l / 2; i < l / 2; i++) {
			if (tmp[S[i] - 'a'] < count[S[i] - 'a'] / 2) {
				tmp[S[i] - 'a']++;
				ans += i - j;
				T[j++] = S[i];
			} else T[k++] = S[i];
		}
		for (i = 0; i < 26; i++) tmp[i] = 0;
		for (i = l - 1, j = l - 1, k = l / 2 - 1; i >= l / 2; i--) {
			if (tmp[S[i] - 'a'] < count[S[i] - 'a'] / 2) {
				tmp[S[i] - 'a']++;
				ans += j - i;
				T[j--] = S[i];
			} else T[k--] = S[i];
		}
		ans += (long long)(j - i) * (j - i);
	} else {
		for (i = 0, j = 0, k = l / 2 + 1; 1; i++) {
			if (tmp[S[i] - 'a'] < (count[S[i] - 'a'] + 1) / 2) {
				tmp[S[i] - 'a']++;
				if (tmp[odd] > count[odd] / 2) break;
				ans += i - j;
				T[j++] = S[i];
			} else T[k++] = S[i];
		}
		m = i - j;
		for (i = 0; i < 26; i++) tmp[i] = 0;
		for (i = l - 1, j = l - 1, k = l / 2 - 1; 1; i--) {
			if (tmp[S[i] - 'a'] < (count[S[i] - 'a'] + 1) / 2) {
				tmp[S[i] - 'a']++;
				if (tmp[odd] > count[odd] / 2) break;
				ans += j - i;
				T[j--] = S[i];
			} else T[k--] = S[i];
		}
		T[l/2] = 'a' + odd;
		ans += (long long)(m + 1) * (j - i + 1) - 1;
	}
	T[l] = 0;
	
	int L[100001], R[100001], first[26] = {}, last[26] = {}, next[100001] = {};
	for (i = 1; i <= l / 2; i++) {
		L[i] = i;
		if (first[T[i-1] - 'a'] == 0) {
			first[T[i-1] - 'a'] = i;
			last[T[i-1] - 'a'] = i;
		} else {
			next[last[T[i-1] - 'a']] = i;
			last[T[i-1] - 'a'] = i;
		}
	}
	for (i = 0; i < 26; i++) last[i] = first[i];
	for (i = 1; i <= l / 2; i++) {
		R[i] = last[T[l-i] - 'a'];
		last[T[l-i] - 'a'] = next[last[T[l-i] - 'a']];
	}
	ans += inversion_number(l / 2, L, R);
	printf("%lld\n", ans);
	fflush(stdout);
	return 0;
}

Measured memory_bytes: 4016
#include <iostream>
#include <vector>
#include <array>
#include <string>
#include <unordered_set>
#include <math.h>

using namespace std;

using ll = long long;
const ll mod = 1e9 + 7;

int main()
{
	unsigned long long x;
	cin >> x;
	int n = 0;
	unsigned long long a = 100;
	while (a < x)
	{
		a += (a / 100);
		n++;
	}
	cout << n;
	return 0;
}

Measured memory_bytes: 3636
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <list>
#include <queue>
#include <deque>
#include <algorithm>
#include <numeric>
#include <utility>
#include <complex>
#include <functional>

using namespace std;

int main() {
    int n, m;
    cin >> n;
    int *p = new int[n];
    for(int i=0; i<n; i++) {
        cin >> p[i];
    }
    cin >> m;
    //int *q = new int[m];
    int q, c=0;
    for(int i=0; i<m; i++) {
        cin >> q;
        for(int j=0; j<n; j++) {
            if(q == p[j]) {
                c++;
                break;
            }
        }
    }
    cout << c << endl;
}


Measured memory_bytes: 3112
#include<iostream>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
#include <iomanip>

#define loop(k) for(int i=0;i<k;i++)
#define looop(k) for(int j=0;j<k;j++)
#define solve(s,c) {int judge{}; loop(n){if(s[i]!=c[i%3]) {judge=-1;break;}}cout<<(judge==-1?-1:m)<<endl;}
#define swap(a,b) a^=b^=a^=b;

using namespace std;

int main(){
    string w;
    cin>>w;
    int l=w.length();
    int count[26]{0};
    loop(l){
        count[w[i]-'a']+=1;
    }
    loop(26){
        if(count[i]%2!=0){
            cout<<"No"<<endl;
            break;
        }else if(i==25){
            cout<<"Yes"<<endl;
        }
    }
    return 0;
}

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

// 小数点以下桁数
// fixed << setprecision(i)

int gcd(int a,int b){return (a%b==0?b:gcd(b, a%b));}
int64_t lcm(int a,int b){return (int64_t)a*b/gcd(a, b);}
int factorial(int a){int b=1;while(a){b*=a--;}return b;} //13以下対応
bool is_prime(int a){if(a<=1)return false;for(int i=2;(int64_t)i*i<=a;i++){if(a%i==0)return false;}return true;}

//順列の全列挙
// vector<int> v(N);
// iota(v.begin(), v.end(), 1);       // v に 1, 2, ... N を設定
// do {
//   for(auto x : v) cout << x << " "; cout << "\n";    // v の要素を表示
// } while( next_permutation(v.begin(), v.end()) ); 

int main()
{
  int64_t h, n = 2, ans = 1;

  cin >> h;
  while (h >= n)
  {
    ans += n;
    n *= 2;
  }
  cout << ans << endl;
}

Measured memory_bytes: 3536
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
const int INF = 1e9;
const double PI = acos(-1.0);
const double EPS = 1e-9;
const int MOD = 1e9 + 7;

ll calc(string s) {
	ll sum = 0;
	ll temp = 0;
	rep(i, s.length()) {
		if(s[i] == ' ') continue;
		if(s[i] == '+') {
			sum += temp;
			temp = 0;
		} else {
			temp *= 10;
			temp += (s[i] - '0');
		}
	}
	sum += temp;
	return sum;
}

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

	string S;
	cin >> S;

	ll sum = 0;
	rep(i, 1 << S.length() - 1) {
		string P(S.length(), ' ');
		int mask = 1;
		rep(j, P.length()) {
			if(mask & i) {
				P[j] = '+';
			}
			mask <<= 1;
		}

		string str;
		rep(j, S.length()) {
			str += S[j];
			str += P[j];
		}

		sum += calc(str);
	}


	cout << sum << '\n';

	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
int main(){
    std::string a,b;
    std::string group = "135781012";
    std::cin >> a >> b;
   if(a == "2" || b=="2")std::cout <<"No";
   else if((group.find(a) != std::string::npos)^ (group.find(b) != std::string::npos)) std::cout <<"No";
   else std::cout<<"Yes";
}

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

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

int main()
{
	for(int h;cin>>h && h;){
		vector<vector<int>> a(h,vector<int>(5));
		rep(i,h) rep(j,5) cin>>a[i][j];
		int res=0;
		for(;;){
			int add=0;
			for(auto& b:a) for(int j=0;j<5;){
				if(b[j]==0){
					j++;
					continue;
				}
				int k=j;
				while(k<5 && b[k]==b[j]) k++;
				if(k-j>=3){
					add+=(k-j)*b[j];
					fill(begin(b)+j,begin(b)+k,0);
				}
				j=k;
			}
			if(add==0) break;
			res+=add;
			rep(i,5) for(int j=h,k=h;k--;)
				if(a[k][i]) swap(a[--j][i],a[k][i]);
		}
		cout<<res<<endl;
	}
}

Measured memory_bytes: 1212
import java.io.*;
import java.util.*;

public class Main {
    private static boolean debug = false;
    private static boolean elapsed = false;

    private void solve(Scanner sc, PrintWriter out) {
        int N = sc.nextInt();
        int[] p = new int[N];
        for (int i = 0; i < N; ++i) {
            p[i] = sc.nextInt() - 1;
        }

        int[] r = new int[N];
        for (int i = 0; i < N; ++i) {
            r[p[i]] = i + 1;
        }
        int[] a = new int[N];
        int[] b = new int[N];
        for (int i = 0; i < N; ++i) {
            a[i] = 30000 * (i + 1);
            b[i] = 30000 * (N - i - 1) + r[i];
        }
//      for (int i = 0; i < N - 1; ++i) {
//          while (a[p[i]] + b[p[i]] >= a[p[i + 1]] + b[p[i + 1]]) {
//              for (int j = p[i + 1]; j < N; ++j) {
//                  ++a[j];
//              }
//              for (int j = p[i + 1]; j >= 0; --j) {
//                  ++b[j];
//              }
//          }
//      }
        for (int i = 0; i < N; ++i) {
            if (i > 0) {
                out.print(" ");
            }
            out.print(a[i]);
        }
        out.println();
        for (int i = 0; i < N; ++i) {
            if (i > 0) {
                out.print(" ");
            }
            out.print(b[i]);
        }
        out.println();
    }
    /*
     * 10^10 > Integer.MAX_VALUE = 2147483647 > 10^9
     * 10^19 > Long.MAX_VALUE = 9223372036854775807L > 10^18
     */
    public static void main(String[] args) {
        long S = System.currentTimeMillis();

        Scanner sc = new Scanner(System.in);
        PrintWriter out = new PrintWriter(System.out);
        new Main().solve(sc, out);
        out.flush();

        long G = System.currentTimeMillis();
        if (elapsed) {
            System.err.println((G - S) + "ms");
        }
    }
}

Measured memory_bytes: 30492
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <functional>
#include <cmath>

using namespace std;

#define int long long
#define pii pair<int, int>

#define fst first
#define scd second
#define PB push_back
#define all(a) a.begin(),a.end()
#define omajinai ios::sync_with_stdio(false);cin.tie(0)
#define rep(i,x) for(int i=0;i<(int)(x);++i)

const int inf = 3e18;
const double eps = 1e-9;

struct RMQ {
	vector<int> dat;
	int n;

	RMQ(int n_) {
		n = 1;

		while (n < n_) n *= 2;
		dat.resize(2 * n, -inf);
	}

	inline void update(int i, int v) {
		i += n - 1;

		dat[i] = v;

		while (i > 0) {
			i = (i - 1) / 2;
			dat[i] = max(dat[i * 2 + 1], dat[i * 2 + 2]);
		}
	}

	inline int query(int a, int b, int k = 0, int l = 0, int r = -1) {
		if (r == -1) r = n;
		if (r <= a || b <= l) return -inf;
		if (a <= l && r <= b) return dat[k];
		
		int vl = query(a, b, k * 2 + 1, l, (l + r) / 2);
		int vr = query(a, b, k * 2 + 2, (l + r) / 2, r);

		return max(vl, vr);
	}
};

vector<pii> treasures;
vector<pii> half1, half2;
int A[15000000];
int B[15000000];

signed main()
{
	omajinai;
	int N, D; cin >> N >> D;

	rep(i, N) {
		int X, Y; cin >> X >> Y;
		treasures.PB(pii(X, Y));
	}

	for (int i = 0, n = N / 2 + N % 2, len = pow(3, n); i < len; ++i) {
		int diff1 = 0, diff2 = 0;

		for (int j = 0, I = i; j < n; ++j) {
			switch (I % 3) {
				case 0:
					break;
				case 1:
					diff1 += treasures[N / 2 + j].fst;
					diff2 -= treasures[N / 2 + j].scd;
					break;
				case 2:
					diff1 -= treasures[N / 2 + j].fst;
					diff2 += treasures[N / 2 + j].scd;
					break;
			}

			I /= 3;
		}

		half2.PB(pii(diff1, diff2));
	}

	RMQ rmq(half2.size());

	sort(all(half2));

	rep(i, half2.size()) {
		A[i] = half2[i].fst;
		B[i] = half2[i].scd;

		rmq.update(i, B[i]);
	}

	int ans = -inf;

	for (int i = 0, n = N / 2, len = pow(3, n); i < len; ++i) {
		int diff1 = 0, diff2 = 0;

		for (int j = 0, I = i; j < n; ++j) {
			switch (I % 3) {
				case 0:
					break;
				case 1:
					diff1 += treasures[j].fst;
					diff2 -= treasures[j].scd;
					break;
				case 2:
					diff1 -= treasures[j].fst;
					diff2 += treasures[j].scd;
					break;
			}

			I /= 3;
		}

		half1.PB(pii(diff1, diff2));
	}

	sort(all(half1), greater<pii>());

	int lidx = 0, ridx = 0;

	rep(i, half1.size()) {
		pii &da = half1[i];

		int lv = min(-D - da.fst, D - da.fst);
		int rv = max(-D - da.fst, D - da.fst);
		
		while (A[lidx] < lv && lidx + 1 < half2.size()) lidx++;
		while ((lidx > ridx) || (A[ridx] <= rv && ridx + 1 < half2.size())) ridx++;
		ridx--;

		if (lidx > ridx) continue;

		ans = max(ans, da.scd + rmq.query(lidx, ridx + 1));
	}

	cout << ans << endl;
}

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

signed main()
{
    int dif = 0;
    string s , t;
    cin >> s >> t;
    
    for(int i=0 ;i<s.size() ;i++ ){
        if( s[i] != t[i] ){
            dif++;
        }
    }
    
    cout << dif << endl;
    
    return (0);
}

Measured memory_bytes: 3856
{-# LANGUAGE Strict #-}

main :: IO ()
main = do
  [a, b] <- map read . words <$> getLine
  putStrLn . maybe "IMPOSSIBLE" show $ solve a b

solve :: Int -> Int -> Maybe Int
solve a b
  | q == 0    = Just p
  | otherwise = Nothing
  where (p, q) = divMod (a + b) 2


Measured memory_bytes: 3836
// https://atcoder.jp/contests/abc141/tasks/abc141_b
#include <bits/stdc++.h>
using namespace std;
using P = pair<int, int>;
using ll = long long;
#define REP(i, n) FOR(i, 0, n)
#define FOR(i, s, n) for (int i = (s), i##_len = (n); i < i##_len; ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    string s;
    cin >> s;
    bool flag = false;
    REP(i, s.size()) {
        if (i % 2 == 0 && s[i] == 'L') {
            flag = true;
        }
        if (i % 2 == 1 && s[i] == 'R') {
            flag = true;
        }
    }
    if (flag)
        cout << "No\n";
    else
        cout << "Yes\n";
    return 0;
}

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

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

   cout << n * 800 - n / 15 * 200 << endl;
}

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

char s[233];

int main(){
	scanf("%s",s+1);
	int L = 1;
	int R = (strlen(s + 1) - 1) / 2;
	bool flag1 = true;
	for(int i = 1; L <= R; ){
		if(s[L] != s[R]){
			flag1 = false;
			break;
		}
		L += i;
		R -= i;
	}
	L = (strlen(s + 1) + 3) / 2;
	R = strlen(s + 1);
	bool flag2 = true;
	for(int i = 1; L <= R; ){
		if(s[L] != s[R]){
			flag2 = false;
			break;
		}
		L += i;
		R -= i;
	}
	bool flag3 = true;
	L = 1;
	R = strlen(s + 1);
	for(int i = 1; L <= R; ){
		if(s[L] != s[R]){
			flag2 = false;
			break;
		}
		L += i;
		R -= i;
	}
	if(flag1 && flag2) printf("Yes\n");
	else printf("No\n");
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
//---------------------------
using namespace std;
//---------------------------
#define REP(i,n) for(int i = 0; i < (n); i++)
#define P(x) cout << (x) << "\n"

#define MOD 1000000007 // 1e9+7
#define PI 3.1415926525
#define ll long long int // 10^18
#define INF 1000000001 // 1e9+1

int dx[4]={1,-1,0,0};
int dy[4]={0,0,1,-1};
//---------------------------
int p[200001],r[200001];

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

  // ifstream in("input.txt");
  // cin.rdbuf(in.rdbuf());

  int n;cin>>n;
  for(int i=1;i<=n;i++){
    cin>>p[i];// 1-n
    r[p[i]]=i;
  }
  int cnt=1,mx=1;
  if(n==1){
    P(0);
    return 0;
  }
  for(int j=1;j<=n-1;j++){
    if(r[j+1]-r[j]>0){
      cnt++;
      mx=max(mx,cnt);
    }
    if(r[j+1]-r[j]<0){
      cnt=1;
    }
  }
  P(n-mx);
  return 0;
}


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

using namespace std;

typedef long long ll;

vector <ll> V;
ll n,l,t,cnt;

ll f(ll k)
{
	ll i, ret = 0;
	
	for(i=0;i<n;i++){
		if(V[i] == k) ret += t;
		else if(V[i] < k) ret += t + (k - V[i] - 1) / l + 1;
		else ret += t - (V[i] - k) / l;
	}
	
	return ret;
}

int main()
{
	ll i,a,b,s,e,mid,k,x;
	
	scanf("%lld%lld%lld",&n,&l,&t);
	
	for(i=0;i<n;i++){
		scanf("%lld%lld",&a,&b);
		if(b == 1) V.push_back(a + t);
		else V.push_back(a - t);
	}
	
	sort(V.begin(), V.end());
	
	s = -l*t, e = n + l*t;
	
	for(;s<=e;){
		mid = s+e >> 1;
		
		if(f(mid) <= n*t) s = mid+1;
		else e = mid-1;
	}
	
	x = (n*t - f(s-1));
	k = ((s-1) % l + l) % l;
	
	for(i=0;i<n;i++){
		V[i] = (V[i] % l + l) % l;
	}
	
	sort(V.begin(), V.end());
	
	for(i=0;i<n;i++){
		if(V[i] == k) break;
	}
	
	for(k=0;k<n;k++){
		printf("%lld\n",V[(i+k+x)%n]);
	}
	
	return 0;
}

Measured memory_bytes: 2164
#include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <functional>
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
#include <cassert>
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2100000000
#define mod 1000000007
#define INF2 1000000000000000000


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int x, y;
    cin >> x >> y;
    int ans = INF;
    int d = abs(abs(x) - abs(y));
    if(x + d == y) {
        ans = min(ans, d);
    }
    if(-x + d == y) {
        ans = min(ans, d + 1);
    }
    if(abs(-x + d) == y) {
        ans = min(ans, d + 2);
    }
    if(x - d == y) {
        ans = min(ans, d + 2);
    }
    if(-(x + d) == y) {
        ans = min(ans, d + 1);
    }
    assert(ans < INF);
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256