akhauriyash/Code-Regression huggingface dataset:
using System;
using System.IO;
using System.Linq;
using System.Collections.Generic;
using System.Text;

public class Program
{

    public void Proc()
    {

        string inpt = Reader.ReadLine();

        int ans = inpt.Count(a => a == '+') - inpt.Count(a => a != '+');
        Console.WriteLine(ans);



    }




    public class Reader
    {
        static StringReader sr;
        public static bool IsDebug = false;
        public static string ReadLine()
        {
            if (IsDebug)
            {
                if (sr == null)
                {
                    sr = new StringReader(InputText.Trim());
                }
                return sr.ReadLine();
            }
            else
            {
                return Console.ReadLine();
            }
        }
        private static string InputText = @"


+-++




";
    }

    public static void Main(string[] args)
    {
#if DEBUG
        Reader.IsDebug = true;
#endif
        Program prg = new Program();
        prg.Proc();
    }
}


Measured memory_bytes: 13268
#include <cstdio>
#include <cstring>
#include <vector>
#include <iostream>
#include <algorithm>

using namespace std;

#define LL long long

const int maxN = 1e7 + 2;
const int mod = 998244353;
int fac[maxN + 2], ifac[maxN + 2], pw2[maxN + 2];
int qpow(int a, int b)
{
    int ans = 1;
    for (; b; b >>= 1, a = 1ll * a * a % mod)
        if (b & 1)
            ans = 1ll * ans * a % mod;
    return ans;
}
inline void Inc(int &x)
{
    x < 0 ? x += mod : 0;
}
void init(int N = 1e7)
{
    fac[0] = 1;
    for (int i = 1; i <= N; ++i)
        fac[i] = (LL) fac[i - 1] * i % mod;
    ifac[N] = qpow(fac[N], mod - 2);
    for (int i = N - 1; i >= 0; --i)
        ifac[i] = (LL) ifac[i + 1] * (i + 1) % mod;
    pw2[0] = 1;
    for (int i = 1; i <= N; ++i)
        pw2[i] = pw2[i - 1] * 2ll % mod;
}
int C(int n, int m)
{
    if (n < m)
        return 0;
    return (LL) fac[n] * ifac[m] % mod * ifac[n - m] % mod;
}
int main()
{
    int n;
    scanf("%d",&n);
    init();
    int ans = qpow(3, n);
    for (int i = n / 2 + 1; i <= n; ++i)
        Inc(ans -= 2ll * C(n, i) * pw2[n - i] % mod);
    printf("%d\n", ans);
    return 0;
}


Measured memory_bytes: 117376
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<queue>
#include<map>
#include<deque>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
typedef long long ll;
typedef pair<int,int> P;

const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

int main(){
    int n,k;
    cin >> n >> k;
    string s;
    cin >> s;
    vector<int> nums;
    int now=1;
    int cnt=0;
    for(int i=0;i<n;i++){
        if(s[i]==(char)('0'+now)){
            cnt++;
        }else{
            nums.push_back(cnt);
            now = 1-now;
            cnt = 1;
        }
    }
    if(cnt!=0) nums.push_back(cnt);
    if(nums.size()%2==0) nums.push_back(0);

    int left=0;
    int right=0;
    int ans=0;
    int add = 2*k+1;
    int sum=0;

    for(int i=0;i<nums.size();i+=2){

        int nextleft = i;
        int nextright = min(i+add,(int)nums.size());

        while(left<nextleft){
            sum -= nums[left];
            left++;
        }
        while(right<nextright){
            sum += nums[right];
            right++;
        }

        ans = max(ans,sum);
    }

    cout << ans << endl;

}

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

public class Main {
    public static void main(String[] args) throws NumberFormatException, IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(br.readLine());
        String[] input = br.readLine().split(" ");

        int[] A = new int[n];
        int chageBox = 0;
        int count = 0;

//      n????????´??°?????????A???????´?
        for (int i = 0; i < n; i++){
            A[i] = Integer.parseInt(input[i]);
        }

        for(int i = 0; i < n - 1; i++){
            for(int j = n - 1; j > i; j--){
                if(A[j] < A[j-1]){
                    chageBox = A[j-1];
                    A[j-1] = A[j];
                    A[j] = chageBox;
                    count++;
                }
            }
        }
        for(int i = 0; i < n; i++){
            if(i == 0){
                System.out.print(A[i]);
            }else{
                System.out.print(" " + A[i]);
            }
        }
        System.out.println();
        System.out.println(count);
    }
}

Measured memory_bytes: 24200
MAXN = 10**6
sieve = [0]*2 + [1]*MAXN
n = 2
while n*n <= MAXN:
    if sieve[n]:
        for i in range(2*n,MAXN+1,n):
            sieve[i] = 0
    n += 1

while True:
    a,d,n = map(int,input().split())
    if n == 0: break
    cnt = 0
    for i in range(a,MAXN+1,d):
        if sieve[i]:
            cnt += 1
            if cnt == n:
                print(i)
                break

Measured memory_bytes: 20888
package main

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

//Util
func nextStr() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func maxInt(a, b int) int {
	if a > b {
		return a
	} else {
		return b
	}
}

func minInt(a, b int) int {
	if a > b {
		return b
	} else {
		return a
	}
}

func absInt(a int) int {
	if a >= 0 {
		return a
	} else {
		return -a
	}
}

func absFloat64(a float64) float64 {
	if a >= 0 {
		return a
	} else {
		return -a
	}
}

func maxFloat64(a, b float64) float64 {
	if a > b {
		return a
	} else {
		return b
	}
}

func minFloat64(a, b float64) float64 {
	if a > b {
		return b
	} else {
		return a
	}
}

func str2Int(s string) int {
	n, _ := strconv.Atoi(s)
	return n
}

func reverse(s string) string {
	runes := []rune(s)
	for i, j := 0, len(runes)-1; i < j; i, j = i+1, j-1 {
		runes[i], runes[j] = runes[j], runes[i]
	}
	return string(runes)
}

func powInt(p, q int) int {
	return int(math.Pow(float64(p), float64(q)))
}

func isPrime(x int) bool {
	if x == 1 {
		return false
	}
	if x == 2 {
		return true
	}
	if x%2 == 0 {
		return false
	}

	b := true
	rootx := int(math.Sqrt(float64(x)))
	i := 3
	for i <= rootx {
		if x%i == 0 {
			b = false
			break
		}
		i += 2
	}
	return b
}

func PrimeFactors(n int) (pfs []int) {
	// Get the number of 2s that divide n
	for n%2 == 0 {
		pfs = append(pfs, 2)
		n = n / 2
	}

	// n must be odd at this point. so we can skip one element
	// (note i = i + 2)
	for i := 3; i*i <= n; i = i + 2 {
		// while i divides n, append i and divide n
		for n%i == 0 {
			pfs = append(pfs, i)
			n = n / i
		}
	}

	// This condition is to handle the case when n is a prime number
	// greater than 2
	if n > 2 {
		pfs = append(pfs, n)
	}

	return
}

func sumInts(x []int) int {

	total := 0
	for _, v := range x {
		total += v
	}

	return total
}

//Main
const (
	initialBufSize = 10000
	maxBufSize     = 1000000
	mod            = 1e9 + 7
)

var (
	sc *bufio.Scanner = func() *bufio.Scanner {
		sc := bufio.NewScanner(os.Stdin)
		buf := make([]byte, initialBufSize)
		sc.Buffer(buf, maxBufSize)
		return sc
	}()
)

var N, K int

func main() {
	sc.Split(bufio.ScanWords)

	N, K = nextInt(), nextInt()
	a := make([]int, N)
	for i := 0; i < N; i++ {
		a[i] = nextInt()
	}

	sort.Ints(a)
	ans := 0
	for i := 0; i < K; i++ {
		ans += a[i]
	}

	fmt.Println(ans)
}


Measured memory_bytes: 1780
#include <cstdio>
#include <cstring>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>
#include <cmath>
#include <map>
#include <string>
#include <iostream>
#include <iomanip>

using namespace std;

typedef long long int ll;
typedef unsigned long long int ull;

#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)

#define TRACE

#ifdef TRACE
#define trace1(x)                cerr << #x << ": " << x << endl;
#define trace2(x, y)             cerr << #x << ": " << x << " | " << #y << ": " << y << endl;
#define trace3(x, y, z)          cerr << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": " << z << endl;
#define trace4(a, b, c, d)       cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << endl;
#define trace5(a, b, c, d, e)    cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl;
#define trace6(a, b, c, d, e, f) cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << " | " << #f << ": " << f << endl;

#else

#define trace1(x)
#define trace2(x, y)
#define trace3(x, y, z)
#define trace4(a, b, c, d)
#define trace5(a, b, c, d, e)
#define trace6(a, b, c, d, e, f)

#endif

const int INF=1e9;
const ll INFF=1e17;
const double EPS=1e-9;
const ll MOD=1e9+7;
ll n,a,b,c,d,curr=0;
bool check(ll p,ll q){return abs(p-q)>=c && abs(p-q)<=d;}
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cin >> n >> a >> b >> c >> d;
	REP(i,n)if((c*(n-1-i)-d*i)<=(b-a) && (b-a)<=(-c*i+(n-1-i)*d)){cout << "YES" << '\n';return 0;}
	cout << "NO" << '\n';
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
typedef long long ll;
using namespace std;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n,k;
    cin>>n>>k;
    vector<ll> v(n);
    ll sum=0;
    for(int i=0;i<n;i++){
        cin>>v[i];
        sum+=v[i];
    }
    set<ll> s;
    for(ll i=1LL;i*i<=sum;i++){
        if(sum%i==0){
            s.insert(i);
            s.insert(sum/i);
        }
    }
    ll d[n];
    ll suma,sumi;
    set<ll>::iterator itr=s.end();
    itr--;
    for(;;itr--){
        suma=0,sumi=0;
        vector<ll> a=v;
        for(int i=0;i<n;i++){
            a[i]%=*itr;
        }
        sort(be(a));
        for(int i=0;i<n;i++){
            if(a[i])d[i]=*itr-a[i];
            else d[i]=0;
            suma+=d[i];
        }
        for(int i=0;i<=n;i++){
            if(sumi==suma && sumi<=k){
                cout << *itr<<endl;
                return 0;
            }
            if(i!=n){
                sumi+=a[i];
                suma-=d[i];
            }
        }
        if(itr==s.begin())break;
    }

    return 0;
}


Measured memory_bytes: 384
A,B=map(int,input().split())
min_a=int(A//0.08)
max_a=int((A+1)//0.08)
min_b=B/0.1
max_b=(B+1)/0.1

sum=0
list=[ ]
for i in range(min_a+1,max_a):
    if min_b <= i < max_b:
        sum += 1
        list.append(i)
if sum==0:
    print(-1)
else:
    print(min(list))

Measured memory_bytes: 3064
#define _CRT_SECURE_NO_WARNINGS
#pragma _attribute_((optimize("-O2")))

#include <iostream>
#include <queue>
#include <stack>
#include <cstdio>
#include <vector>
#include <map>
#include <list>
#include <set>
#include <cstdio>
#include <bitset>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <string>
#include <sstream>
#include <time.h>
#include <iomanip>

//#define Local

using namespace std;

int main()

{

	ios::sync_with_stdio(false);
	cin.tie(0);
	//freopen("input1.txt", "r", stdin);
	//freopen("output1.txt", "w", stdout);

	int k;
	while(cin>>k)
	{
		vector<int> al(k);
		int mi = 200, ma = -200;
		for (int a = 0; a < k; a++)
			cin >> al[a];
		long long res=100000000;
		for (int a = -1 * max(abs(ma), abs(ma)); a <= 2 * max(abs(ma), abs(mi)); a++)
		{
			long long tmp = 0;
			for (int b = 0; b < k; b++)
				tmp += (a - al[b])*(a - al[b]);
			res = min(res, tmp);
		}
		cout << res << endl;
	}

#ifdef Local
	cout << "time: " << (long long)clock() * 1000 / CLOCKS_PER_SEC << " ms" << endl;
#endif
	return 0;
}

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

int main(){
  string S,T;
  cin >> S >> T;
  int count=0;
  for(int i=0;i<S.size();i++){
    if(S.at(i)!=T.at(i)){
      count++;
    }
  }
  cout << count << endl;
}

Measured memory_bytes: 3900
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <math.h>
#include <cstdlib>
#include <cmath>

using namespace std;

int main(){
  int X,A,B;
  cin >> X >> A >> B;
  if(0>=B-A) cout << "delicious" << endl;
  else if(X>=B-A)  cout << "safe" << endl;
  else  cout << "dangerous" << endl;

  return 0;
}


Measured memory_bytes: 256
def factor(n):
    i = 2
    r = []
    while i * i <= n:
        if n % i == 0:
            c = 0
            while n % i == 0:
                c += 1
                n //= i
            r.append((i, c))
        i += 1
    if n > 1:
        r.append((n, 1))
    return r

def main():
    N = int(input())
    r = 0
    for p, e in factor(N):
        i = 1
        while e >= i:
            r += 1
            e -= i
            i += 1
    return r

print(main())


Measured memory_bytes: 9208
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <math.h>
#include <assert.h>
#include <vector>

using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
static const double EPS = 1e-9;
static const double PI = acos(-1.0);

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, s, n) for (int i = (s); i < (int)(n); i++)
#define FOREQ(i, s, n) for (int i = (s); i <= (int)(n); i++)
#define FORIT(it, c) for (__typeof((c).begin())it = (c).begin(); it != (c).end(); it++)
#define MEMSET(v, h) memset((v), h, sizeof(v))

int n;
double E;
double plate[300000];

inline double Get(int index) {
  return plate[index + n];
}

inline double Merge(double x, double y, int w) {
  return min(y, (w * x + y) / (w + 1));
}

double MergeAll(int dir) {
  double left = Get(-dir * n);
  int w = 1;
  int index = -dir * n + dir;
  while (index != 0) {
    left = Merge(left, Get(index), w);
    //cout << index << " " << left << " " << w << endl;
    assert(left >= -EPS);
    w++;
    index += dir;
  }
  return left;
}

int main() {
  while (scanf("%d %lf", &n, &E) > 0) {
    REP(i, 2 * n + 1) {
      scanf("%lf", &plate[i]);
    }
    double left = MergeAll(1);
    double right = MergeAll(-1);
    double ans = max(E / Get(0), E * (n + 1) / (n * (left + right) + Get(0)));
    printf("%.8f\n", ans);
  }
}

Measured memory_bytes: 0
def main():
    N, M = map(int, input().split())
    L = []
    R = []
    for m in range(M):
        l, r = map(int, input().split())
        L.append(l)
        R.append(r)
    print(max((min(R)-max(L)+1), 0))


if __name__ == '__main__':
    main()


Measured memory_bytes: 11012
#### import ####
import sys
import math
from collections import defaultdict

#### 設定 ####
sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

#### 定数 ####
mod = 10**9 + 7

#### 読み込み ####
def I(): return int(input())
def II(): return map(int, input().split())
def III(): return list(map(int, input().split()))
def Line(N):
    read_all = [tuple(map(int, input().split())) for _ in range(N)]
    return map(list,zip(*read_all))

#################

#x以上で最小のyの倍数
def min_mult(x,y):
    if x%y==0:
        return x
    else:
        return x + (y-x%y)

N = I()
C,S,F = Line(N-1)

ans = []

for i in range(N-1):
    temp = S[i]+C[i]
    for j in range(i+1,N-1):
        temp = min_mult(max(temp,S[j]),F[j]) + C[j]
    ans.append(temp)

ans.append(0)
for i in range(N):
    print(ans[i])

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


int main() {
  int n;
  string s;
  cin >> n >> s;
  rep(i,s.size()){
    s.at(i) = (s.at(i)-'A'+n)%26+'A';
    cout << s.at(i);
  }
  cout << endl;
}

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

#define each(i, c) for (auto& i : c)
#define unless(cond) if (!(cond))

using namespace std;

typedef long long int lli;
typedef unsigned long long ull;
typedef complex<double> point;

template<typename P, typename Q> ostream& operator << (ostream& os, pair<P, Q> p) { os << "(" << p.first << "," << p.second << ")"; return os; }
template<typename P, typename Q> istream& operator >> (istream& is, pair<P, Q>& p) { is >> p.first >> p.second; return is; }
template<typename T> ostream& operator << (ostream& os, vector<T> v) { os << "("; each (i, v) os << i << ","; os << ")"; return os; }
template<typename T> istream& operator >> (istream& is, vector<T>& v) { each (i, v) is >> i; return is; }

template<typename T> inline T setmax(T& a, T b) { return a = std::max(a, b); }
template<typename T> inline T setmin(T& a, T b) { return a = std::min(a, b); }

int main(int argc, char *argv[])
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);

  int n;
  while (cin >> n) {
    int x[n][3];
    for (int i = 0; i < n; ++i) {
      cin >> x[i][0] >> x[i][1] >> x[i][2];
    }

    const int N = 1e5 + 5;
    int dp[N][3];
    fill(&dp[0][0], &dp[N - 1][3 - 1] + 1, 0);

    for (int i = 0; i < n; ++i) {
      for (int j = 0; j < 3; ++j) {
        for (int k = 0; k < 3; ++k) {
          if (j == k) continue;
          setmax(dp[i + 1][k], dp[i][j] + x[i][k]);
        }
      }
    }

    cout << max({dp[n][0], dp[n][1], dp[n][2]}) << endl;
  }
  
  return 0;
}


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

using namespace std;

// Header files, namespaces,
// macros as defined above
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>


#define f first
//#define s second
#define db long double
#define pb push_back
#define sz(c) (c).size()
#define all(c) (c).begin(),(c).end()

typedef long long ll;
typedef pair <int , int> ii;
typedef pair <ii , int> iii;
typedef vector <int> vi;
typedef vector <ii> vii;
typedef vector <vi> vvi;
typedef vector <vii> vvii;

const ll mod = 998244353;
const int MAX = 1e5+5;
const db eps = 1e-13;

bool mk[MAX];
int dp[MAX];

vvi g;

int dfs_dp( int node ) {

    mk[node] = true;
    int mx = 0;
    for( int nw : g[node] ) {

        if( !mk[nw] )
            mx = max( dfs_dp(nw) , mx );
        else
            mx = max( dp[nw] , mx );
    }

    return dp[node] = mx+1;
}



int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
    cout<<setprecision(0)<<fixed;
    int ans = 0;
    int n , m;cin>>n>>m;
    vi v;
    g = vvi(n+1,v);
    while(m--) {

        int a, b;
        cin>>a>>b;
        g[a].pb(b);

    }

    for( int i = 1; i <= n ; i++ )
        if( !mk[i] )
            ans = max( ans , dfs_dp(i) );

    cout<<ans-1<<"\n";

}


Measured memory_bytes: 8320
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<map>
#include<stack>
#include<queue>
#include<algorithm>
#include<set>
#include<vector>
#include<cmath>
#define lmid l,m,rt<<1
#define rmid m+1,r,rt<<1|1
#define LL long long
#define rl r-l+1
using namespace std;
int main()
{
     int n,k;
     scanf("%d%d",&n,&k);
     int sum=0;
     for(int i=0;i<n;i++)
     {
          int a;
          scanf("%d",&a);
          a=min(a,abs(k-a));
          sum+=2*a;
     }
     cout<<sum<<endl;
     return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
template<class T>
void dmp(T a){
	rep(i,a.size()) cout << a[i] << " ";
	cout << endl;
}
template<class T>
bool chmax(T&a, T b){
	if(a < b){
		a = b;
		return 1;
	}
	return 0;
}
template<class T>
bool chmin(T&a, T b){
	if(a > b){
		a = b;
		return 1;
	}
	return 0;
}
template<class T>
void g(T &a){
	cin >> a;
}
template<class T>
void o(T a){
	cout << a << '\n';
}
#define all(x) x.begin(),x.end()
int n;
const ll mod = 998244353;
ll dp[200005];
int go[200005];
struct RMQ{
	#define s (1<<19)
	int seg[s];
	void update(int k,int a){
		k+=s/2-1; seg[k]=a;
		while(k>0){
			k=(k-1)/2;
			seg[k]=max(seg[k*2+1],seg[k*2+2]);
		}
	}
	int query(int a,int b,int k,int l,int r){
		if(r<a || b<l) return 0;
		if(a<=l && r<=b) return seg[k];
		else{
			int vl=query(a,b,k*2+1,l,(l+r)/2);
			int vr=query(a,b,k*2+2,(l+r)/2+1,r);
			return max(vl,vr);
		}
	}
}rmq;
int main(){
	g(n);
	vector<P>vec(n);
	rep(i,n){
		g(vec[i].fi); g(vec[i].sc);
	}
	SORT(vec);
	dp[n] = 1;
	for(int i=n-1;i>=0;i--){
		int a = POSL(vec,mp(vec[i].fi+vec[i].sc,-1));
		int x = rmq.query(i+1, a-1, 0, 0, s/2-1);
		x = max(x,a);
		dp[i] = dp[i+1] + dp[x];
		if(dp[i] >= mod) dp[i] -= mod;
		rmq.update(i,x);
	}
	cout << dp[0] << endl;
}

Measured memory_bytes: 5760
#include <stdio.h>
#include <string.h>

int main() {
	char string[1000][32], str[32];
	int i=0, md=0, sd=0, c=0, strn[1000];
	unsigned int mlen;

	while(scanf("%s",&str)!=EOF) {
		
		for(i=0;i<=c;i++) {
			if (strcmp(string[i], str)==0) {
				strn[i]++;
				if (strn[i]>strn[sd]) sd=i;
				break;
			}
			if (i==c) {
				strncpy( string[c+1], str, strlen(str) );
				if ( mlen<strlen(string[c+1]) ) {
					md = c+1;
					mlen = strlen(string[c+1]);
				}
				strn[c+1]=1;
				c++;
			}
		}
	}
	printf("%s %s\n",string[sd],string[md]);
	return 0;
}

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

int main(){
    int n, k;
    while(cin >> n >> k, n+k){
        vector<string> v(n), res;
        for(int i = 0; i < n; i++)  cin >> v[i];
        for(int i = 0; i < 1<<n; i++){
            vector<string> c;
            for(int j = 0; j < n; j++){
                if((i>>j)&1)    c.push_back(v[j]);
            }
            if(c.size() != k)   continue;
            sort(c.begin(), c.end());
            do{
                string t = "";
                for(int j = 0; j < k; j++)  t += c[j];
                res.push_back(t);
            }while(next_permutation(c.begin(), c.end()));
        }
        sort(res.begin(), res.end());
        res.erase(unique(res.begin(),res.end()),res.end());
        cout << res.size() << endl;
    }
    return 0;
}


Measured memory_bytes: 3296
program main
  implicit none
  integer :: n, i, j, d, res, sd
  integer, allocatable :: x(:, :)
  read (*, *) n, d
  allocate (x(n, d))
  do i = 1, n
    read (*, *) x(i, :)
  end do

  res = 0
  do i = 1, n
    do j = i + 1, n
      sd = sdist(x(i, :), x(j, :))
      if (is_squared(sd)) res = res + 1
    end do
  end do

  write (*, "(i0)") res

  contains

  pure integer function sdist(x1, x2)
    integer, intent(in) :: x1(d), x2(d)
    sdist = sum((x1 - x2) ** 2)
  end function sdist

  pure logical function is_squared(k)
    integer, intent(in) :: k
    is_squared = (k == nint(sqrt(dble(k))) ** 2)
  end function is_squared
end program main


Measured memory_bytes: 512
/**
 * Problem: AtCoder Regular Contest 103.  
 * Author:  hkxadpall.
 * Date:    2018-09-29. 
 * Upload:  AtCoder. 
 */
#include <math.h>
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <string.h>
#include <vector>
#include <queue> 
#include <map>
#include <set>

//using std::min;
using std::max;
using std::sort;
//using std::cin;
//using std::cout;
using std::cerr;
//using std::clog;
using std::endl;
using std::vector;

#define DEBUG_ERR 2
#define DEBUG_ON 1
#define DEBUG_OFF 0

#define DEBUG_TAG DEBUG_OFF

#define passing fprintf(stderr, "passing line [%d] in function %s.\n", __LINE__, __FUNCTION__)
#define debug(x) cerr << "[debug] " << #x << " = " << x << endl 

template <typename _TpInt> inline _TpInt read()       
{
    register _TpInt flag = 1; register char c = getchar();
    while ((c > '9' || c < '0') && c != '-') c = getchar();
    if (c == '-') flag = -1, c = getchar(); register _TpInt init = (c & 15);
    while ((c = getchar()) <= '9' && c >= '0') init = (init * 10) + (c & 15);
    return init * flag;
}

template <typename _TpInt> inline void write(_TpInt x)
{
    if (x < 0) { putchar('-'); write<_TpInt>(~x + 1); } 
    else { if (x > 9) write<_TpInt>(x / 10); putchar(x % 10 + '0'); } 
}

#define Max_N 100007 // = Max_M
#define log_N 16 // = log_M
#define log_N_SizeArray (log_N + 3) 

int n, m, a[Max_N] = {0}, b[Max_N] = {0};

int main() 
{
	n = read<int>();
	for (int i = 1; i <= n; i++) { 
		if (i & 1) {
			a[read<int>()]++;
		} else {
			b[read<int>()]++;
		}
	}	
//	int n2 = n >> 1;
	int maxa = 0, maxb = 0;
	int p1a, p1b, p2a, p2b;
	int m2a, m2b;
	for (int i = 1; i <= 100000; i++) { 
		if (a[i] > maxa) {
			m2a = maxa;
			maxa = a[i];
			p2a = p1a;
			p1a = i;
		} else if (a[i] > m2a){
			m2a = a[i];
			p2a = i;
		}
	}	
	for (int i = 1; i <= 100000; i++) { 
		if (b[i] > maxb) {
			m2b = maxb;
			maxb = b[i];
			p2b = p1b;
			p1b = i;
		} else if (b[i] > m2b){
			m2b = b[i];
			p2b = i;
		}
	}	
	if (p1a == p1b) {
		int cga, cgb;
		cga = maxa - m2a;
		cgb = maxb - m2b;
		if (cga < cgb) {
			write(n - m2a - maxb);
		} else {
			write(n - maxa - m2b);
		}
	} else {
		write(n - maxa - maxb);
	}
    return 0;
}

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

int dcount(int number, int count){
  while(number%2 == 0){
    number /= 2;
    count++;
  }
  return count;
}

int main(){
  
  int N; cin>>N;
  vector<int> a(N);
  int answer = 0;
  for(int i=0; i<a.size(); i++){
    cin>>a.at(i);
    answer = dcount(a.at(i), answer);
  }
  
  cout<<answer<<endl;
}


Measured memory_bytes: 256
#include<cstdio>
using namespace std;
int main(void)
{
	int n;
	bool kari = 0;
	int a[10] = {1,2,4,8,16,32,64,128,256,512};
	while(scanf("%d",&n) != EOF)
	{
		bool flag[10] = {0};
		for(int i = 9;i >= 0;i--)
		{
			if(a[i] <= n)
			{
				n -= a[i];
				flag[i] = 1;
			}
		}
		for(int i = 0;i < 10;i++)
		{
			if(flag[i] == 1)
			{
				printf("%d",a[i]);
				for(int j = i+1;j < 10;j++)
				{
					if(flag[j] == 1) kari = 1;
				}
				if(kari == 1) printf(" ");
				else printf("\n");
				kari = 0;
			}
		}
	}
	
	return 0;
}

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

ll minCostDP(ll h[], ll n){
  ll dp[n+1];
  dp[0] = 0;
  dp[1] = abs(h[1]-h[0]);
  for(ll i=2; i<n; i++){
    dp[i] = min(dp[i-1] + abs(h[i]-h[i-1]), dp[i-2] + abs(h[i]-h[i-2]) );
  }
  return dp[n-1];
    
}
int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  ll n;
  cin>>n;
  ll h[n];
  for(ll i=0; i<n; i++){
  	cin>>h[i];
  }
  ll ans = minCostDP(h,n);
  cout<<ans<<"\n";
  return 0;
}


Measured memory_bytes: 5184
#include <iostream>
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>

using namespace std;
#define REP(i,n) FOR(i,0,n)
#define FOR(i,a,b) for(long long i=(a),i##Len_=(b);i<i##Len_;i++)
typedef long long ll;
static const ll MOD = 1000000007;


//arc090
//いつのタイミングで、下に行くか



int main()
{
    ll N;

    cin >> N;

    ll dp[N+1][2] = {};
    ll a[N+1][2] = {};


    REP(i,N)
    {
        cin >> a[i][0];
    }
    REP(i,N)
    {
        cin >> a[i][1];
    }

    dp[0][0] = a[0][0];

    if(N == 1)
    {
        cout << a[0][0] + a[0][1] << endl;
        return 0;
    }

    for(ll i = 0; i < N-1 ; ++i)
    {
        dp[i][1] = max(dp[i][1], dp[i][0] + a[i][1]);
        for(ll j = 0; j <=1; ++j)
        {
            dp[i+1][j] = max(dp[i+1][j], dp[i][j] + a[i+1][j]);
        }
    }

    cout << dp[N-1][1] << endl;

}



Measured memory_bytes: 256
N,M = list(map(int,input().split()))
from collections import deque
A = [[] for i in range(N)]
line_list = []
ans = 0
for i in range(M):
    B,C = map(int,input().split())
    B -=1
    C -=1
    A[B].append(C)
    A[C].append(B)
    line_list.append([B,C])
for i in range(M):#一辺ずつ
    B = 0
    C = line_list[i]
    start = C[0]
    end = C[1]
    que = deque(A[start])
    que.remove(end)
    after = deque([start])
    while que != deque([]):
        now = que.popleft()
        after.append(now)
        for j in A[now]:
            if j in after:
                continue
            if j in que:
                continue
            que.appendleft(j)
        if end in que:
            B = 1
            break
    if B != 1:
        ans += 1
print(ans)

Measured memory_bytes: 3316
// #include <bits/stdc++.h>
#include<climits>
#include<cmath>
#include<cstdio>
#include<deque>
#include<map>
#include<set>
#include<vector>
#include<iostream>
#include<sstream>
#include<algorithm>
#include<numeric>
#include<string>
#include<tuple>
#include<queue>
using namespace std;
// #include <boost/multiprecision/cpp_int.hpp>
// using namespace boost::multiprecision;
#define BEGIN ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define END return EXIT_SUCCESS
#define rep(I,N) for(auto I=0;I<(N);++I)
#define up(I,A,B) for(auto I=(A);I<=(B);++I)
#define dw(I,A,B) for(auto I=(A);I>=(B);--I)
#define all(C) (C).begin(),(C).end()
#define rall(C) (C).rbegin(),(C).rend()
#define ft first
#define sd second
#define mp make_pair
#define mt make_tuple
#define pf push_front
#define pb push_back
#define pt pop_front
#define pk pop_back
#define lb lower_bound
#define ub upper_bound
#define rs resize
template<class T>inline bool chmax(T& a,T b){if(a<b){a=b;return true;}return false;}
template<class T>inline bool chmin(T& a,T b){if(a>b){a=b;return true;}return false;}
template<class T>inline void                                      in(T &p){cin>>p;}
template<class T1,class T2>inline void                            in(T1 &p1,T2 &p2){cin>>p1>>p2;}
template<class T1,class T2,class T3>inline void                   in(T1 &p1,T2 &p2,T3 &p3){cin>>p1>>p2>>p3;}
template<class T1,class T2,class T3,class T4>inline void          in(T1 &p1,T2 &p2,T3 &p3,T4 &p4){cin>>p1>>p2>>p3>>p4;}
template<class T1,class T2,class T3,class T4,class T5>inline void in(T1 &p1,T2 &p2,T3 &p3,T4 &p4,T5 &p5){cin>>p1>>p2>>p3>>p4>>p5;}
template<class T>inline void                             out(T p){cout<<p<<endl;}
template<class T1,class T2>inline void                   out(T1 p1,T2 p2){cout<<p1<<" "<<p2<<endl;}
template<class T1,class T2,class T3>inline void          out(T1 p1,T2 p2,T3 p3){cout<<p1<<" "<<p2<<" "<<p3<<endl;}
template<class T1,class T2,class T3,class T4>inline void out(T1 p1,T2 p2,T3 p3,T4 p4){cout<<p1<<" "<<p2<<" "<<p3<<" "<<p4<<endl;}
long N,P;
string S;
vector<pair<string,long>>vv;
set<string>v;
map<long,long>m;
inline void solve(void){
  in(N);
  rep(i,N){
    in(S,P);
    v.insert(S);
    vv.pb(mp(S,P));
    m[P]=i+1;
  }
  for(auto e:v){
    vector<long>tmp;
    for(auto u:vv)if(e==u.ft)tmp.pb(u.sd);
    sort(rall(tmp));
    for(auto u:tmp)out(m[u]);
  }
}
int main(int argc,char**argv){
  BEGIN;
  solve();
  END;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mp make_pair
#define pb push_back
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)

int main(){

  int a,b;
  cin >> a >> b;
  if((a+b)%2==0){
    cout << (a+b)/2 << endl;
  }
  else cout << "IMPOSSIBLE" << endl;
  
  return 0;

}


Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#define LL long long
#define mod 1000000007
#define maxn 200010
using namespace std;
LL fact[maxn],inv[maxn];
int n,head[maxn],cnt,sz[maxn];
LL pre[maxn],ans[maxn],tp[maxn];
struct node{
	int to,next;
}e[maxn<<1];
void add_edge(int u,int v){
	cnt++,e[cnt].to=v,e[cnt].next=head[u],head[u]=cnt;
}
LL quick_pow(LL a,LL b){
	LL ans=1;
	while(b){
		if(b&1)ans=ans*a%mod;
		a=a*a%mod;
		b>>=1;
	}
	return ans;
}
void init(){
	int i,u,v;
	scanf("%d",&n);
	for(i=1;i<n;i++){
		scanf("%d%d",&u,&v);
		add_edge(u,v),add_edge(v,u);
	}
	fact[0]=1;
	for(i=1;i<=n;i++)fact[i]=fact[i-1]*i%mod;
	inv[n]=quick_pow(fact[n],mod-2);
	for(i=n-1;i>=0;i--)inv[i]=inv[i+1]*(i+1)%mod;
}
LL C(int a,int b){
	return fact[a]*inv[a-b]%mod*inv[b]%mod;
}
void dfs1(int u,int fa){
	int b,v;
	sz[u]=1,pre[u]=1;
	for(b=head[u];b;b=e[b].next){
		v=e[b].to;
		if(v==fa)continue;
		dfs1(v,u);
		sz[u]+=sz[v];
		pre[u]=pre[v]*pre[u]%mod*C(sz[u]-1,sz[v])%mod;
	}
}
void dfs2(int u,int fa){
	int b,v;
	ans[u]=tp[u]*pre[u]%mod*C(n-1,n-sz[u])%mod;
	for(b=head[u];b;b=e[b].next){
		v=e[b].to;
		if(v==fa)continue;
		tp[v]=ans[u]*quick_pow(pre[v]*C(n-1,sz[v])%mod,mod-2)%mod;
		dfs2(v,u);
	}
}
int main(){
	init();
	dfs1(1,0);
	tp[1]=1;
	dfs2(1,0);
	for(int i=1;i<=n;i++)printf("%lld\n",ans[i]);
	return 0;
}

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

int N, a[100004];

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

	cin >> N;
	for (int i=0; i<N; i++) {
		int x, y;
		cin >> x >> y;
		a[i] = x == y;
	}

	int ans = 0;
	for (int i=0; i+2<N; i++) {
		ans |= a[i] and a[i+1] and a[i+2];
	}

	cout << (ans ? "Yes" : "No") << '\n';
}

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

int main(){

  int n,i,A;
  cin>>n;
  int a[n];
  for(i=0; i<n; i++){
    a[i]=0;
  }

  for(i=0; i<n-1; i++){
    cin>>A;
    a[A]=a[A]+1;
  }

  for(i=1; i<n; i++){
    printf("%d\n",a[i]);
  }
printf("0\n");
  return 0;
}

Measured memory_bytes: 4508
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.*;

public class Main {

    static int N;
    static String[] S;

    public static void main(String[] args) {
        FastScanner sc = new FastScanner(System.in);
        N = sc.nextInt();
        S = new String[N];
        for (int i = 0; i < N; i++) {
            S[i] = sc.next();
        }
        System.out.println( solve() );
    }

    static long solve() {
        int[] cnt = new int[5];
        for (int i = 0; i < N; i++) {
            String s = S[i];
            switch (s.charAt(0)) {
                case 'M':
                    cnt[0]++;
                    continue;
                case 'A':
                    cnt[1]++;
                    continue;
                case 'R':
                    cnt[2]++;
                    continue;
                case 'C':
                    cnt[3]++;
                    continue;
                case 'H':
                    cnt[4]++;
                    continue;
            }
        }

        return cmb(cnt, 0, 1, 2) + cmb(cnt, 0, 1, 3) + cmb(cnt, 0, 1, 4)
                + cmb(cnt, 0, 2, 3) + cmb(cnt, 0, 2, 4) + cmb(cnt, 0, 3, 4)
                + cmb(cnt, 1, 2, 3) + cmb(cnt, 1, 2, 4) + cmb(cnt, 1, 3, 4)
                + cmb(cnt, 2, 3, 4);
    }

    static long cmb(int[] cnt, int a, int b, int c) {
        return (long)cnt[a] * cnt[b] * cnt[c];
    }

    @SuppressWarnings("unused")
    static class FastScanner {

        private BufferedReader reader;
        private StringTokenizer tokenizer;

        FastScanner(InputStream in) {
            reader = new BufferedReader(new InputStreamReader(in));
            tokenizer = null;
        }

        String next() {
            if (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        String nextLine() {
            if (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    return reader.readLine();
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }

            return tokenizer.nextToken("\n");
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        int[] nextIntArray(int n) {
            int[] a = new int[n];
            for (int i = 0; i < n; i++)
                a[i] = nextInt();
            return a;
        }

        long[] nextLongArray(int n) {
            long[] a = new long[n];
            for (int i = 0; i < n; i++)
                a[i] = nextLong();
            return a;
        }
    }
}



Measured memory_bytes: 34452
#include<iostream>
#include<iomanip>
#include<string>
#include<vector>
#include<algorithm>
#include<utility>
#include<set>
#include<map>
#include<queue>
#include<math.h>
using namespace std ;
using ll = long long ;
using vi = vector<int> ;
using vii = vector<vi> ;
using pii = pair<ll,ll> ;

int main(){
	set<ll> s ;
	ll a,b,c ;
	cin >> a >> b >> c ;
	s.insert(a) ;
	s.insert(b) ;
	s.insert(c) ;
	if(s.size()==2) cout << "Yes" << endl ;
	else cout << "No" << endl ;
}

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

int main() {
	int N;
	long long C;
	cin >> N >> C;
	vector <long long >X(N);
	vector <long long >Y(N);
	vector<long long>V(N);
	vector<long long>W(N);
	for (int i = 0; i < N; ++i) {
		cin >> X[i] >> V[i];
		Y[N - 1 - i] = C - X[i];
		W[N - 1 - i] = V[i];
	}
	vector<long long>R(N);
	vector<long long>L(N);
	vector<long long>Vsum(N);
	vector<long long>Wsum(N);
	//左先用
	{
		long long memo = 0;
		for (int i = 0; i < N; ++i) {
			if (0 != i) {
				Vsum[i] = Vsum[i - 1] + V[i];
			}
			else {
				Vsum[i] = V[i];
			}
			memo = max(memo, Vsum[i] - X[i]);
			R[i] = memo;
		}
	}
	//右先用
	{
		long long memo = 0;
		for (int i = 0; i < N; ++i) {
			if (0 != i) {
				Wsum[i] = Wsum[i - 1] + W[i];
			}
			else {
				Wsum[i] = W[i];
			}
			memo = max(memo, Wsum[i] - Y[i]);
			L[i] = memo;
		}
	}
	long long ans = 0;
	ans = max(ans, R[N - 1]);
	ans = max(ans, L[N - 1]);
	for (int i = 1; i < N; ++i) {
		if (0 == i) {
			ans = max(ans, Wsum[N - 1 - i] - 2 * Y[N - 1 - i]);
		}
		else {
			ans = max(ans, Wsum[N - 1 - i] - 2 * Y[N - 1 - i] + R[i - 1]);
		}
	}
	for (int i = 1; i < N; ++i) {
		if (0 == i) {
			ans = max(ans, Vsum[N - 1 - i] - 2 * X[N - 1 - i]);
		}
		else {
			ans = max(ans, Vsum[N - 1 - i] - 2 * X[N - 1 - i] + L[i - 1]);
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 9600
function main(input) {
    input=input.split(" ");
    var a=parseInt(input[0],10);
    var b=parseInt(input[1],10);
    var x=parseInt(input[2],10);

  if(a+b>=x & a<=x){
      console.log("YES");}
      else{
          console.log("NO");
      }
  }
  main(require('fs').readFileSync('/dev/stdin', 'utf8'));

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

int main() {
  int kazu,size;
  cin >> kazu >> size;
  vector<string> kekka(kazu);
  for(int i=0;i<kazu;i++) {
    cin >> kekka.at(i);
  }
  sort(kekka.begin(),kekka.end());
  for(int i=0;i<kazu;i++) {
    cout << kekka.at(i);
  }
}

Measured memory_bytes: 3636
n = int(input())
a = list(map(int, input().split()))

l = [0 for i in range(n+1)]
r = [0 for i in range(n+1)]
for i in range(1, n+1):
  l[i] = l[i-1] + a[i-1]
  r[-(i+1)] = r[-i] + a[-i]

ans = 10e+12
for i in range(1, n):
  ans = min(ans, abs(l[i] - r[i]))
print(ans)

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

//#define int long long

typedef pair<int,int>pint;
typedef vector<int>vint;
typedef vector<pint>vpint;
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
template<class T,class U>void chmin(T &t,U f){if(t>f)t=f;}
template<class T,class U>void chmax(T &t,U f){if(t<f)t=f;}

namespace SA{
    const int MAX=1000000;
    int N,K;
    int tmp[MAX+1],rank[MAX+1];
    bool compare_sa(int i,int j){
        if(rank[i]!=rank[j])return rank[i]<rank[j];
        else{
            int ri=(i+K<=N)?rank[i+K]:-1;
            int rj=(j+K<=N)?rank[j+K]:-1;
            return ri<rj;
        }
    }

    vector<int> construct_sa(string S){
        N=S.size();
        vector<int>sa(N+1);
        for(int i=0;i<=N;i++)sa[i]=i;
        for(int i=0;i<=N;i++){
            rank[i]=i==N?-1:S[i];
        }

        for(K=1;K<=N;K*=2){
            sort(sa.begin(),sa.end(),compare_sa);
            tmp[sa[0]]=0;
            for(int i=1;i<=N;i++){
                tmp[sa[i]]=tmp[sa[i-1]]+(compare_sa(sa[i-1],sa[i])?1:0);
            }
            for(int i=0;i<=N;i++)rank[i]=tmp[i];
        }
        return sa;
    }
}


bool exist(string &S,vint &sa,string &T){
    int a=0,b=S.size();
    while(b-a>1){
        int c=(a+b)/2;
        if(S.substr(sa[c],S.size()-sa[c])<T)a=c;
        else b=c;
    }
    return S.substr(sa[b],min(S.size()-sa[b],T.size()))==T;
}

bool contain(string &S,vint &sa,string &T){
    int a=0,b=S.size();
    while(b-a>1){
        int c=(a+b)/2;
        if(S.compare(sa[c],T.size(),T)<0)a=c;
        else b=c;
    }
    return S.compare(sa[b],T.size(),T)==0;
}

signed main(){
    string S;
    vint sa;
    int Q;
    cin>>S;
    sa=SA::construct_sa(S);
    cin>>Q;

    while(Q--){
        string T;cin>>T;
        if(contain(S,sa,T))cout<<1<<endl;
        else cout<<0<<endl;
    }
    return 0;
}

Measured memory_bytes: 18736
#include <iostream>
#include <array>
#include <algorithm>
#include <vector>
#include <bitset>
#include <set>
#include <unordered_set>
#include <cmath>
#include <complex>
#include <deque>
#include <iterator>
#include <numeric>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <limits>
#include <iomanip>
#include <functional>
#include <cassert>
using namespace std;

using ll=long long;
template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
using vll = V<ll>;
using vvll = V<vll>;
#define ALL(v) v.begin(),v.end()
template < class T > inline bool chmax(T& a, T b) {if (a < b) { a=b; return true; } return false; }
template < class T > inline bool chmin(T& a, T b) {if (a > b) { a=b; return true; } return false; }
#define DEBUG_VLL(vec) for(int sz=0;sz<int(vec.size());sz++) std::cerr<<vec[sz]<<(sz==vec.size()-1?'\n':' ');

const long long MOD = 1000000007;
const long long HIGHINF = (long long)1e18;
const int INF = (int)1e9;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    vll a(n);
    for (int i = 0; i < n; i++) cin >> a[i];
    if (a[0] != 0) {
        cout << -1 << '\n';
    } else {
        ll ans = 0;
        for (int i = 1; i < n; i++) {
            if (a[i] > a[i - 1] + 1) {
                cout << -1 << '\n';
                return 0;
            } else {
                if (a[i] == a[i - 1] + 1) ans++;
                else ans += a[i];
            }
        }
        cout << ans << '\n';
    }
    return 0;
}


Measured memory_bytes: 4784
#include <algorithm>
#include <array>
#include <assert.h>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;
typedef long long ll;
typedef long double ld;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define sz(x) ((int)(x).size())
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<ld> vld;
typedef vector<vector<int>> vvi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<vector<ld>> vvd;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;

const ll MOD = 1e9 + 7;
void add(ll& x, ll y) { x += y; if (x >= MOD) x -= MOD; }
void take(ll& x, ll y) { x -= y; if (x < 0) x += MOD; }

ll sum(ll a, ll b) { add(a, b); return a; }
ll sub(ll a, ll b) { take(a, b); return a; }
ll mul(ll x, ll y) { return (x * y) % MOD; }

int main() {
    cout << setprecision(30);
    ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);

    ll n, k;
    cin >> n >> k;
    vl x(n);
    for (int i = 0; i < n; ++i) {
        cin >> x[i];
    }
    ll ans = 0;

    ll diff = 0;
    ll same = 0;
    for (int i = 0; i < n; ++i) {
        for (int j = i + 1; j < n; ++j) {
            if (x[i] != x[j]) ++diff;
            if (x[j] < x[i]) ++same;
        }
    }
    add(ans, mul(same, k));
    add(ans, mul(diff, (k * (k - 1) / 2 % MOD)));

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
ll triangles(ll arr[], ll n)  
{
    ll count = 0;
    for (ll i = 0; i < n - 2; ++i)  
    { 
        ll k = i + 2;
        for (ll j = i + 1; j < n; ++j)  
        {  
            while (k < n && arr[i] + arr[j] > arr[k])  
            ++k;
            if(k > j)  
            count += k - j - 1;  
        }  
    }  
    return count;  
}  
int main()
{
	ll a,b,i,j,k,m,n,t;
	cin>>n;
	ll ar[n];
	ll f[2001]={0};
	for(i=0;i<n;i++)
	{
		cin>>ar[i];
		f[ar[i]]++;
	}
	ll ans=0;
	sort(ar,ar+n);
	
	cout<<triangles(ar,n);
}

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

using namespace std;

int main() {

   string str;
   cin >> str;

   while (str != "-") {
      int m;
      cin >> m;

      for (int i = 0; i < m; ++i) {
         int h;
         cin >> h;

         str = str.substr(h) + str.substr(0, h);
      }

      cout << str << endl;

      cin >> str;
   }

   return 0;

}

Measured memory_bytes: 3108
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
const int iinf = 1 << 28;
const long long llinf = 1ll << 60;
const double PI = 3.14159265;

int main() {
    int a, b; char sa, sb;
    cin>>a>>b;
    sa = a + '0'; sb = b + '0';
    string fa = "", fb = "";
    for (int i = 0; i < a; ++i) fa += sb;
    for (int i = 0; i < b; ++i) fb += sa;
    if (fa < fb) cout << fa;
    else cout << fb;

    return 0;
}


Measured memory_bytes: 256
N = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))

ans = 0

for i in range(N):
  if A[i] >= B[i]:
    ans += B[i]
  else:
    ans += min(A[i]+A[i+1],B[i])
    A[i+1] = max(0,A[i+1]-(B[i]-A[i]))
    
print(ans)

Measured memory_bytes: 24256
def smaller(x, y):
	if x < y: return x
	return y

lst = [1]
x = 6
while x <= 100000:
	lst.append(x)
	x *= 6
x = 9
while x <= 100000:
	lst.append(x)
	x *= 9
lst.sort()

N = int(input())
dp = []
for i in range(0, N+1):
	dp.append(100001)
dp[0] = 0
for i in range(0, N):
	for j in range(0, len(lst)):
		if i + lst[j] > N:
			break
		dp[i+lst[j]] = smaller(dp[i+lst[j]], dp[i]+1)
print(dp[N])

Measured memory_bytes: 45040
#include <bits/stdc++.h>
using namespace std;
int main() 
{
	int a,b[100],c[100];
	cin>>a;
	int x=0;
	for(int i=0;i<a;i++)
	{
		cin>>b[i];
		c[i]=b[i];
	}
	sort(c,c+a);
	for(int i=0;i<a;i++)
	{
		if(b[i]!=c[i])x++;
	}
	if(x>2)cout<<"NO";
	else cout<<"YES";
	return 0; 
}

Measured memory_bytes: 256
#include <stdio.h>
int main(void) {
    int i,j;
    char board[8][8];
    for (i=0; i<8; i++) scanf("%s\n",board[i]);
    printf("90\n");
    for (i=0; i<8; i++) {
        for (j=0; j<8; j++) printf("%c",board[7-j][i]);
        printf("\n");
    }
    printf("180\n");
    for (i=0; i<8; i++) {
        for (j=0; j<8; j++) printf("%c",board[7-i][7-j]);
        printf("\n");
    }
    printf("270\n");
    for (i=0; i<8; i++) {
        for (j=0; j<8; j++) printf("%c",board[j][7-i]);
        printf("\n");
    }
    return 0;
}

Measured memory_bytes: 524
#include <iostream>
#include <bitset>
using namespace std;
#define MAXN 11
#define MAXM 10001
int n,m;
bitset<MAXM> A[MAXN];

bool input()
{
    cin>>n>>m;
    if(!n&&!m)return false;
    int tmp;
    for(int i=0;i<n;i++){
        for(int j=0;j<m;j++){
            cin>>tmp;
            A[i][j] = tmp;
        }
    }
    return true;
}

int res;
void dfs(int id)
{
    if(id==n){
        int cnt = 0;
        for(int j=0;j<m;j++){
            int tmp=0;
            for(int i=0;i<n;i++){
                if(A[i][j]==0)tmp++;
            }
            tmp = max(tmp, n-tmp);
            cnt += tmp;
        }
        res = max(res, cnt);
        return;
    }
    dfs(id+1);
    A[id].flip();
    dfs(id+1);
    A[id].flip();
}

int main()
{
    while(input()){
        res = 0;
        dfs(0);
        cout<<res<<endl;
    }
    return 0;
}



Measured memory_bytes: 3052