akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>

using namespace std;

int main(void) {
    int64_t N, W;
    cin >> N >> W;
    vector<int64_t> w(N), v(N);
    for(int i=0; i<N; i++) {
        cin >> w[i] >> v[i];
    }

    vector< vector<int64_t> > g(4);
    for(int i=0; i<N; i++) {
        g[w[i]-w[0]].emplace_back(v[i]);
    }
    for(int j=0; j<4; j++) {
        sort(g[j].begin(), g[j].end());
        g[j].emplace_back(0);
        reverse(g[j].begin(), g[j].end());
        partial_sum(g[j].begin(), g[j].end(), g[j].begin());
    }

    int64_t ans = 0;
    for(int i=0; i<g[0].size(); i++) {
        for(int j=0; j<g[1].size(); j++) {
            for(int k=0; k<g[2].size(); k++) {
                for(int l=0; l<g[3].size(); l++) {
                    int64_t weight = w[0] * i + (w[0]+1)*j + (w[0]+2)*k + (w[0]+3)*l;
                    if(weight > W) continue;
                    ans = max(ans, g[0][i] + g[1][j] + g[2][k] + g[3][l]);
                }
            }
        }
    }

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


Measured memory_bytes: 256
/*
　　　　　　 ＿＿
　　　　　／＞　　 フ
　　　　　|   _　 _l  
　 　　　／` ミ＿x ノ   Zzz..
　　 　 /　 　 　 |   コード見ちゃだめ！！
　　　 /　 ヽ　　  ﾉ
　 　 │　　|　|  |   
　／￣|　　 |　|  |
　| (￣ヽ＿_ヽ_)_ _)
　＼二つ
*/

#include <bits/stdc++.h>
using namespace std;
#define SORT(a) sort((a).begin(),(a).end())
#define RSORT(a) reverse((a).begin(),(a).end())
#define REP(i, n) for(int i = 0; i < n; i++)
const int MOD = 1e9+7;
typedef long long ll;



int main(){
    //入力
    int n; cin>>n;
    vector<int>p(n);
    for(int i=0;i<n;i++) cin>>p[i];

    int count=0;

    for(int i=0;i<n-1;i++){
        if(p[i]==i+1) {
            swap(p[i],p[i+1]); 
            count++;
        }
    }
    if(p[n-1]==n) count++;
    cout<<count<<endl;
}

Measured memory_bytes: 640
import java.util.Scanner;
public class Main {
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int x = scan.nextInt();
      int cnt = 0;
      int a = 0;
      if(a<=x){
        cnt++;
      }
      for(int i=0; i<n; i++){
        int l = scan.nextInt();
        a = a+l;
        if(a<=x){
        cnt++;
      }
      }
          System.out.println(cnt);

	}
 
}

Measured memory_bytes: 21332
import math
import itertools
from collections import defaultdict
from collections import Counter
import numpy as np
def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

s=input()
su=[0 for _ in range(len(s))]
su[0]=int(s[-1])
for i in range(1,len(s)):
    ii=len(s)-i-1
    o=int(s[ii])*pow(10,i,2019)
    su[i]=(su[i-1]+o)

    su[i]%=2019
su=su+[0]
a_dic=Counter(su)
ans=0

for i in a_dic.keys():
    if a_dic[i]<2:
        continue
    ans+=combinations_count(a_dic[i],2)

print(ans)

Measured memory_bytes: 35904
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
    int n;
    int[][] fss;
    int[][] pss;

    public static void main(String args[]) {
        new Main().run();
    }

    void run() {
        FastReader sc = new FastReader();
        n = sc.nextInt();
        fss = new int[n][10];
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < 10; j++) {
                fss[i][j] = sc.nextInt();
            }
        }
        pss = new int[n][11];
        for (int i = 0; i < n; i++) {
            for (int j = 0; j <= 10; j++) {
                pss[i][j] = sc.nextInt();
            }
        }
        solve();
    }

    void solve() {
        int[] states = new int[n];
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < 10; j++) {
                states[i] <<= 1;
                states[i] |= fss[i][j];
            }
        }
        int maxProfit = Integer.MIN_VALUE;
        for (int i = 1; i < 1 << 10; i++) {
            int profit = 0;
            for (int j = 0; j < n; j++) {
                int overlap = Integer.bitCount(i & states[j]);
                profit += pss[j][overlap];
            }
            if (maxProfit < profit) {
                maxProfit = profit;
            }
        }
        System.out.println(maxProfit);
    }

    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        public FastReader() {
            br = new BufferedReader(new
                    InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements())
            {
                try
                {
                    st = new StringTokenizer(br.readLine());
                }
                catch (IOException e)
                {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

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

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

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

        String nextLine() {
            String str = "";
            try
            {
                str = br.readLine();
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
            return str;
        }
    }
}


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

using namespace std;

int main() {
	// your code goes here
	int n;
	vector<int> count(4,0);
	cin>>n;
	while(n--){
		string query;
		cin>>query;
		if(query == "AC")
			count[0]++;
		if(query == "WA")
			count[1]++;
		if(query == "TLE")
			count[2]++;
		if(query == "RE")
			count[3]++;
	}
	cout<<"AC x "<<count[0]<<endl;
	cout<<"WA x "<<count[1]<<endl;
	cout<<"TLE x "<<count[2]<<endl;
	cout<<"RE x "<<count[3]<<endl;
	
	return 0;
}

Measured memory_bytes: 3548
import itertools
from collections import deque,defaultdict,Counter
from itertools import accumulate
import bisect
from heapq import heappop,heappush,heapify
import math
from copy import deepcopy
import queue
import numpy as np
# sympy as syp(素因数分解とか)
Mod = 1000000007
fact = [1, 1]
factinv = [1, 1]
inv = [0, 1] 
for i in range(2, 10**5 + 1):
    fact.append((fact[-1] * i) % Mod)
    inv.append((-inv[Mod % i] * (Mod // i)) % Mod)
    factinv.append((factinv[-1] * inv[-1]) % Mod)
    
def cmb(n, r, p):
    if (r < 0) or (n < r):
        return 0
    r = min(r, n - r)
    return fact[n] * factinv[r] * factinv[n - r] % p
    
def sieve_of_eratosthenes(n):
    if not isinstance(n,int):
        raise TypeError("n is not int")
    if n<2:
        raise ValueError("n is not effective")
    prime = [1]*(n+1)
    for i in range(2,int(math.sqrt(n))+1):
        if prime[i] == 1:
            for j in range(2*i,n+1):
                if j%i == 0:
                    prime[j] = 0
    res = []
    for i in range(2,n+1):
        if prime[i] == 1:
            res.append(i)
    return res

 
class UnionFind:
    def __init__(self,n):
        self.parent = [i for i in range(n+1)]
        self.rank = [0 for i in range(n+1)]
    
    def findroot(self,x):
        if x == self.parent[x]:
            return x
        else:
            y = self.parent[x]
            y = self.findroot(self.parent[x])
            return y
    
    def union(self,x,y):
        px = self.findroot(x)
        py = self.findroot(y)
        if px < py:
            self.parent[y] = px
        else:
            self.parent[px] = py
 
    def same_group_or_no(self,x,y):
        return self.findroot(x) == self.findroot(y)

def main():  #startline-------------------------------------------
    n, k = map(int, input().split())
    a=list(map(int, input().split()))
    a.sort()
    ans = 0
    for i in range(n - k + 1):
        t = cmb(n - i - 1, k - 1, Mod)
        ans += (a[n - i - 1] * t % Mod - (a[i] * t % Mod)) % Mod
        
    print(ans%Mod)
if __name__ == "__main__":
    main() #endline===============================================

Measured memory_bytes: 43432
#include<algorithm>
#include<iostream>
#include<cstring>
#include<string>
#include<vector>
#include<cstdio>
#include<cmath>
#include<set>
#include<map>
using namespace std;
typedef long long ll;
const int MAXN=1e5+5;
const ll mod=1e9+7;
int read()
{
    int s=0,f=1;
    char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){s=s*10+ch-'0';ch=getchar();}
    return s*f;
}
int main()
{
    ll n,k;cin>>n>>k;
    ll ans=0;
    for(ll i=k;i<=n+1;i++)ans=(ans+(n-i+1)*i+1)%mod;
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3616
import sys
import math
input = sys.stdin.readline

n, d = map(int, input().split())

x = [[0]*d for _ in range(n)]
for i in range(n):
    temp = list(map(int, input().split()))
    for j in range(d):
        x[i][j] = temp[j]
ans = 0
cnt = 0
for i in range(n):
    for j in range(i+1, n):
        temp = 0
        for k in range(d):
            temp += abs(x[i][k] - x[j][k])**2
        temp = math.sqrt(temp)
        if temp == int(temp):
            cnt += 1
print(cnt)

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


int main() {
    int N, R;
    cin >> N >> R;
    if(N<10) {
        cout << R+(100*(10-N)) << endl;
    }
    else {
        cout << R << endl;
    }


    return 0;
}

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

int main() {
  long long x,k,d,y;
  cin >> x >> k >> d;
  x = abs(x);
  y = x%d;
  if(abs(y-x)/d > k){
    cout << x - k*d << endl;
    return 0;
  }else{
    k = k - x/d; //ここでx = yとなる
    x = y;
    if(k%2==0){
      cout << x << endl;
    }else{
      cout << abs(x - d) << endl;
    }
  }
  return 0;
}

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

using namespace std;

int main(void){
    int H, W;
    cin >> H >> W;

    int a[H][W];
    for(int i = 0; i < H; i++ ) {
        for(int j = 0; j < W; j++ ) {
            cin >> a[i][j];
        }
    }

    int N = 0;
    vector<int> y, x, Y, X;
    for(int i = 0; i < H - 1; i++) {
        for(int j = 0; j < W; j++) {
            if (a[i][j] % 2 == 0) {
                continue;
            }

            a[i+1][j]++;

            N++;
            y.push_back(i);
            x.push_back(j);
            Y.push_back(i+1);
            X.push_back(j);
        }
    }

    for(int j = 0; j < W-1; j++) {
        if (a[H-1][j] % 2 == 0) {
            continue;
        }

        a[H-1][j+1]++;

        N++;
        y.push_back(H-1);
        x.push_back(j);
        Y.push_back(H-1);
        X.push_back(j+1);
    }

    cout << N << endl;
    for(int i = 0; i < N; i++) {
        cout << y[i] + 1 << " " << x[i] + 1 << " " 
             << Y[i] + 1 << " " << X[i] + 1 << endl;
    }

    return 0;
}


Measured memory_bytes: 5220
#include<iostream>
using namespace std;
#define MAX 500000
#define SENTINEL 2000000000

int L[MAX/2+2], R[MAX/2+2];
int cnt;

void merge( int A[], int left, int mid, int right ) {
  int n1 = mid - left;
  int n2 = right - mid;
  for ( int i = 0; i < n1; i++ ) L[i] = A[left + i];
  for ( int i = 0; i < n2; i++ ) R[i] = A[mid + i];
  L[n1] = R[n2] = SENTINEL;
  int i = 0, j = 0;
  for ( int k = left; k < right; k++ ) {
    cnt++;
    if ( L[i] <= R[j] ) {
      A[k] = L[i++];
    } else {
      A[k] = R[j++];
    }
  }
}

void mergeSort( int A[], int left, int right ) {
  if ( left + 1 < right ) {
    int mid = (left + right) / 2;
    mergeSort(A, left, mid);
    mergeSort(A, mid, right);
    merge(A, left, mid, right);
  }
}

int main() {
  int A[MAX], n, i;
  cnt = 0;

  cin >> n;
  for ( i = 0; i < n; i++ ) cin >> A[i];

  mergeSort(A, 0, n);

  for ( i = 0; i < n; i++ ) {
    if ( i ) cout << " ";
    cout << A[i];
  }
  cout << endl;

  cout << cnt << endl;

  return 0;
}


Measured memory_bytes: 6996
#include <bits/stdc++.h>
using namespace std;
int main(){
    int arr[7] = {0, 1, 2, 3, 4, 5};
    int ans = 0;
    for(int i = 1 ; i <= 5; i ++){
        int a; cin >> a;
        if(a != arr[i]) ans = i;
    }
    cout << ans << '\n';

}

Measured memory_bytes: 3596
N, K = map(int, input().split())
sushi_list = []
max_d = [0] * N
for i in range(N):
    t, d = map(int, input().split())
    sushi_list.append((t - 1, d))
    max_d[t - 1] = max(max_d[t - 1], d)

sushi_list.sort(key=lambda x: x[1], reverse=True)
good = []
for i in range(N):
    if max_d[sushi_list[i][0]] == sushi_list[i][1]:
        good.append(True)
        max_d[sushi_list[i][0]] = 0
    else:
        good.append(False)

s = sum([sushi[1] for sushi in sushi_list[:K]])
p = len(set([sushi[0] for sushi in sushi_list[:K]]))
ans = s + p**2
r = K - 1
l = K
while True:
    while r >= 0 and good[r]:
        r -= 1
    while l < N and not good[l]:
        l += 1
    if r < 0 or l >= N:
        break
    s = s - sushi_list[r][1] + sushi_list[l][1]
    p += 1
    ans = max(ans, s + p**2)
    r -= 1
    l += 1

print(ans)


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

#define int long long
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; }

vector<int> graph[100010];

signed main(){
	int n, m;
	cin >> n >> m;

	for(int i = 0;i < m;i++){
		int a, b;
		cin >> a >> b;
		a--; b--;
		graph[a].push_back(b);
		graph[b].push_back(a);
	}

	queue<int> que;
	int ans[100010] = {};
	que.push(0);
	ans[0] = 1719;
	while(!que.empty()){
		int idx = que.front();
		que.pop();
		for(auto e : graph[idx]){
			if(ans[e] == 0){
				ans[e] = idx+1;
				que.push(e);
			}
		}
	}

	cout << "Yes" << endl;
	for(int i = 1;i < n;i++){
		cout << ans[i] << endl;
	}

	return 0;
}


Measured memory_bytes: 12872
/*
    Author - Param Kothari
    Ah shit, here we go again
*/

#include <bits/stdc++.h>
 
using namespace std;

#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define pb push_back
#define mk make_pair
#define debug_vec(x, n) cout << (#x) << ": "; for(int i = 0; i < n; i++) cout << x[i] << (i == n - 1 ? "\n" : " ");

typedef long long ll;
typedef long double ld;

void solve(){
    int w, s;
    cin >> s >> w;
    cout << (w >= s ? "unsafe\n" : "safe\n");
    return;
}
 
int main(){
    IOS;
    int t = 1;
    // cin >> t;
    for(int i = 1; i <= t; i++){
        solve();
    }
    return 0;
}

Measured memory_bytes: 3660
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <tuple>
#include <cmath>
using namespace std;

int main(int argc, const char * argv[]) {
  int n;
  int64_t a, aMax = -999999999, aMin = 999999999;
  
  cin >> n;
  for(int i = 0; i < n; i++){
    cin >> a;
    aMax = max(aMax, a);
    aMin = min(aMin, a);
  }
  cout << aMax - aMin << endl;
  return 0;
}


Measured memory_bytes: 256
public class Main {
	public static void main(String[] args){
		java.util.Scanner scan = new java.util.Scanner(System.in);
		int W = scan.nextInt();
		int H = scan.nextInt();
		int x = scan.nextInt();
		int y = scan.nextInt();
		int r = scan.nextInt();

		if((W >= x + r) && (H >= y + r) && ((x + r) > 0) && (y + r) > 0){
			System.out.println("Yes");
		}else{
			System.out.println("No");
		}


	}

}

Measured memory_bytes: 26292
#include<bits/stdc++.h>
using namespace std;
#define fr first
#define sc second
typedef long long ll;
typedef double ld;
typedef pair<int,int> p2;
typedef pair<p2,int> p3;
typedef vector<ll> vi;
const ll Mod = 7 + 1e9;
const ll INF32 = 5 + 2e9;
const ll INF64 = 1 + 1e18;
const ll MAX = 5+ 4e2;

int N,a[30][30],dp[1<<22 |5];

int Try(int i,int Mask)
{
    if(i == N)
        return 1;
    int &r = dp[Mask];
    if( r != -1 )
        return r;
    r = 0;
    for(int j=0;j<N;j++)
        if( a[i][j] && ~Mask & 1<<j )
        r = ( r + Try(i+1,Mask|1<<j ) )%Mod;
    return r;
}

int main()
{
    cin >> N;
    for(int i=0;i<N;i++)
        for(int j=0;j<N;j++)
        cin >> a[i][j];
    memset(dp,-1,sizeof(dp));
    cout << Try(0,0) << endl;
    return 0;
}


Measured memory_bytes: 16640
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

typedef struct {
	char name[12];
	int price;
} zairyou_t;

int compare(const void* x, const void* y) {
	const zairyou_t* a = (const zairyou_t*)x;
	const zairyou_t* b = (const zairyou_t*)y;
	return strcmp(a->name, b->name);
}

int N;
zairyou_t zairyou[5000];
int M;
int mahou[1000][2];

int get_id(const char* name) {
	int left = 0, right = N - 1;
	while (left <= right) {
		int mid = (left + right) / 2;
		int cmp = strcmp(zairyou[mid].name, name);
		if (cmp == 0) {
			return mid;
		} else if (cmp < 0) {
			left = mid + 1;
		} else {
			right = mid - 1;
		}
	}
	printf("not found: %s\n", name);
	exit(1);
}

int main(void) {
	int i;
	int sinchoku;
	int answer;
	if (scanf("%d", &N) != 1) return 1;
	for (i = 0; i < N; i++) {
		if (scanf("%s%d", zairyou[i].name, &zairyou[i].price) != 2) return 1;
	}
	qsort(zairyou, N, sizeof(*zairyou), compare);
	if (scanf("%d", &M) != 1) return 1;
	for (i = 0; i < M; i++) {
		char s[12], t[12];
		if (scanf("%s%s", s, t) != 2) return 1;
		mahou[i][0] = get_id(s);
		mahou[i][1] = get_id(t);
	}

	/* berumannfoodo hou teki na yatu */
	do {
		sinchoku = 0;
		for (i = 0; i < M; i++) {
			if (zairyou[mahou[i][0]].price > zairyou[mahou[i][1]].price) {
				zairyou[mahou[i][0]].price = zairyou[mahou[i][1]].price;
				sinchoku = 1;
			} else if (zairyou[mahou[i][1]].price > zairyou[mahou[i][0]].price) {
				zairyou[mahou[i][1]].price = zairyou[mahou[i][0]].price;
				sinchoku = 1;
			}
		}
	} while (sinchoku);

	answer = 0;
	for (i = 0; i < N; i++) {
		answer += zairyou[i].price;
	}
	printf("%d\n", answer);

	return 0;
}

Measured memory_bytes: 816
#include <bits/stdc++.h>
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define pb push_back
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) FOR(i, 0, n)
#define ll long long
using namespace std;

const ll P = 1000000007;
const long long INF = 1LL << 60;
int gcd(int a, int b) { return b != 0 ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }

int main()
{
  cout << fixed << setprecision(10);
  ll N,M;
  cin >> N >> M;
  if(N==1||M==1)
  {
    cout << 1 << endl;
    return 0;
  }
  if(N*M%2==0)
  {
    cout << N*M/2 << endl;
  }
  else cout << N*M/2+1 << endl;
  return 0;
}


Measured memory_bytes: 3628
import java.util.*;
 
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int[] a = new int[N];
		for(int i=0;i<N;i++) a[i] = sc.nextInt();
		Arrays.sort(a);
		
		int alice = 0;
		int bob = 0;
		for(int i=0;i<N;i++){
			if(i%2==0) alice += a[N-1-i];
			else bob += a[N-1-i];
		}
		System.out.println((alice-bob));
		return;
	}
}

Measured memory_bytes: 24276
n,m,c = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]

a = [[int(i) for i in input().split()] for _ in range(n)]

ans = 0
for i in a:
    judge = sum([k*v for k,v in zip(i,b)]) + c
    if judge > 0:
        ans += 1
print(ans)

Measured memory_bytes: 3064
#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
#define ld long double
#define pb push_back
#define all(x) (x).begin(), (x).end()
template <typename T> using ord_set = tree <T, null_type, less <T>, rb_tree_tag, tree_order_statistics_node_update>;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());



int main() {
	ios_base::sync_with_stdio(false), cin.tie(NULL);
	#ifdef LOCAL
		freopen("input.txt", "r", stdin);
	#endif
	
	char c;
	cin >> c;
	if (c >= 'a' && c <= 'z') {
		cout << 'a';
	}	else {
		cout << 'A';
	}
}


Measured memory_bytes: 3648
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<set>
#include<map>
#include<queue>
#define REP(i,a) for (int i = 0;i < (a);++i)
#define FOR(i,a,b) for (int i = (a);i < (b); ++i)
#define FORR(i,a,b) for (int i = (a);i >= (b); --i)
#define ALL(obj) (obj).begin(),(obj).end()
#define SORT(list) sort(ALL((list)));
#define MOD 1000000007
using namespace std;
using ll = long long;
int main(){
    ll n;
    cin >> n;
    if(n%2)cout << n*2 << endl;
    else cout << n << endl;
    return 0;
}

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

#define ll long long

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

bool is_palindrome(string s)
{
    ll l = s.length();
    for(ll i = 0;i < l/2;i++)
    {
        if(s[i] != s[l - i - 1])
        return false;
    }
    return true;
}

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  
    int a = 0;
    int b = 0;
    int result = 0;
    cin >> a >> b;

    if ((a-b) % 2 == 0){

        if(a > b){
            result = b + (a -b) / 2;
        }else{
            result = a + (b -a) / 2;
        }

        cout << result << endl;

    }else{
        cout << "IMPOSSIBLE" << endl;
    }

}

Measured memory_bytes: 256
#define _USE_MATH_DEFIMES
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cctype>
#include <climits>
#include <clocale>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <regex>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

const int MOD = 1'000'000'007;
const int INF = 1'000'000'000; //1e9
const int NIL = -1;
const long long LINF = 1'000'000'000'000'000'000; // 1e18
const long double EPS = 1E-10;

template<class T, class S> inline bool chmax(T &a, const S &b){
    if(a < b){
        a = b; return true;
    }
    return false;
}
template<class T, class S> inline bool chmin(T &a, const S &b){
    if(b < a){
        a = b; return true;
    }
    return false;
}










int main(){
    int L, R, d, cnt(0);
    std::cin >> L >> R >> d;
    for(int i(L); i <= R; ++i){
        if(!(i % d)) ++cnt;
    }
    std::cout << cnt << std::endl;
    return 0;
}


Measured memory_bytes: 3632
import sys
input = sys.stdin.readline
X, Y, A, B, C = map(int, input().split())
p = [int(x) for x in input().split()]
q = [int(x) for x in input().split()]
r = [int(x) for x in input().split()]

p.sort(reverse = True)
q.sort(reverse = True)
red = p[:X]
green = q[:Y]
ans = red + green + r
ans.sort(reverse = True)
print(sum(ans[:X+Y]))


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

using namespace std;

typedef long long ll;
const ll INF = 1LL<<60;

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

template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

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

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

  ll N, L;
  cin >> N >> L;
  vector<ll> a(N);
  for(int i = 0; i < N; i++){
    cin >> a[i];
  }

  ll max_ind = 0;
  ll max_len = -1;
  for(int i = 0; i < N-1; i++){
    if(chmax(max_len, a[i]+a[i+1])){
      max_ind = i;
    }
  }

  if(max_len < L){
    cout << "Impossible" << endl;
  }else{
    cout << "Possible" << endl;
    for(int i = 0; i < max_ind; i++){
      cout << (i+1) << endl;
    }
    for(int i = N-2; i >= max_ind; i--){
      cout << (i+1) << endl;
    }
  }



  return 0;
}


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

int main(){
    int a,b;
    cin >> a >> b;
    int ans = 0;
    
    rep(i,2){
        if(a<b)swap(a,b);
        ans += a;
        a--;
    }
    
    cout << ans << endl;
    
    return 0;
}

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

using namespace std;
using ll=long long;

int main()
{
    int n;cin >>n;
    vector<int> dp(n,0);
    int h[n];
    for(int i=0;i<n;i++){
        cin >>h[i];
    }
    dp[0]=0;
    dp[1]=abs(h[1]-h[0]);
    for(int 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]));
    }
    cout << dp[n-1]<< endl;
    return 0;
}


Measured memory_bytes: 1024
import java.util.*;

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

    int n = sc.nextInt();
    int d = sc.nextInt();
    int dd = d * 2 + 1;

    double need = (double)n / dd;

    if(n % dd == 0) {
      System.out.println((int)need);
    } else {
      System.out.println((int)Math.ceil(need));
    }
  }
}


Measured memory_bytes: 22996
#include <iostream>
#include <vector>
#include <array>
#include <list>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <tuple>
#include <bitset>
#include <memory>
#include <cmath>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <numeric>
#include <climits>
#include <cfloat>
#include <cassert>
#include <random>
#include<iostream>
#include<cmath>

int main() {
	constexpr long long int MOD = 1000000007LL;
	int x, y; std::cin >> x >> y;
	if ((x + y) % 3 != 0) {
		std::cout << 0 << '\n';
		return 0;
	}
	const int min = std::min(x, y);
	const int diff = std::max(x, y) - min;
	const int count = (x + y) / 3;
	if (count < diff || (count - diff) % 2 != 0) {
		std::cout << 0 << '\n';
		return 0;
	}
	std::vector<long long int> factorial(1000001, 1), inv(1000001, 1), inverse_factorial(1000001, 1);
	for (auto i = 2; i < factorial.size(); ++i) {
		factorial[i] = i * factorial[i - 1] % MOD;
		inv[i] = (MOD - MOD / i) * inv[MOD % i] % MOD;
		inverse_factorial[i] = inv[i] * inverse_factorial[i - 1] % MOD;
	}
	const long long int result = factorial[count] * inverse_factorial[(count - diff) / 2 + diff] % MOD * inverse_factorial[(count - diff) / 2] % MOD;
	std::cout << result << '\n';
}


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

using namespace std;

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

const char sp = ' ';
const char cmm = ',';
const int MOD = 1000000007;

using ll = long long;

ll mod(ll a, ll b){return (a%b+b)%b;}
ll gcd(ll a, ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b){return a*b/gcd(a,b);}
void Yes(){cout << "Yes" << endl;}
void No(){cout << "No" << endl;}
void Judge(bool b){b?Yes():No();}
void YES(){cout << "YES" << endl;}
void NO(){cout << "NO" << endl;}
void JUDGE(bool b){b?YES():NO();}
ll powMod(ll b, ll e, ll m){ll r=1;while(e>0){if(e&1)r=(r%m)*(b%m)%m;b=(b%m)*(b%m)%m;e>>=1;}return r;}
double distance(ll x1, ll y1, ll x2, ll y2){return sqrt((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2));}

template<typename T>
void ppp(T n){cout << n << endl;}

int main(){

    cin.tie(0);
    ios::sync_with_stdio(false);

    ll H, W;
    cin >> H >> W;

    ll ans = H*W;

    for(ll h = 1LL; h < H; ++h){
        ll a = W*h;

        ll b = (H-h)/2LL*W;
        ll c = (H-h-((H-h)/2LL))*W;

        ll B = W/2LL*(H-h);
        ll C = (H-h)*(W-W/2LL);

        ll res1 = max({a,b,c}) - min({a,b,c});
        ll res2 = max({a,B,C}) - min({a,B,C});
        ans = min({ans, res1, res2});
    }

    for(ll w = 1LL; w < W; ++w){
        ll a = H*w;

        ll b = (W-w)/2LL*H;
        ll c = (W-w-((W-w)/2LL))*H;

        ll B = H/2LL*(W-w);
        ll C = (H-H/2LL)*(W-w);

        ll res1 = max({a,b,c}) - min({a,b,c});
        ll res2 = max({a,B,C}) - min({a,B,C});
        ans = min({ans, res1, res2});
    }
    ppp(ans);

    return 0;
}


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

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

  int h=x/3600;
  int m=(x/60)%60;
  int s=x%60;
  cout << h <<":"<< m <<":"<<s<<endl;
  return 0;
}



   
  



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

int main()
{
	int n, k, a, b;

	cin >> n >> k;
	
	for (int i = 0; i < k; i++){
		cin >> a >> b;
		if (n + 1 - a < a) a = n + 1 - a;
		if (n + 1 - b < b) b = n + 1 - b;

		if (a < b) cout << (a - 1) % 3 + 1 << endl;
		else cout << (b - 1) % 3 + 1 << endl;
	}
	return (0);
}

Measured memory_bytes: 3080
import fractions
import sys
range = xrange
input = raw_input

mod = 10**9+7
MOD = 10**9+7

big = 10**6
modinv = [1]*big
for i in range(2,big):
    modinv[i] = (-(MOD//i)*modinv[MOD%i])%MOD

fac = [1]
for i in range(1,big):
    fac.append(fac[-1]*i%MOD)

invfac = [1]
for i in range(1,big):
    invfac.append(invfac[-1]*modinv[i]%MOD)

def choose(n,k):
    return fac[n]*invfac[k]%MOD*invfac[n-k]%MOD


modinv = lambda x: pow(x,mod-2,mod)

n,a,b,c = [int(x) for x in input().split()]

a *= modinv(100)
b *= modinv(100)
c *= modinv(100)




#def nck(n,k):
#    prod = 1
#    for i in range(1,n+1):
#        prod *= i
#    for i in range(1,k+1):
#        prod //= i
#    for i in range(1,n-k+1):
#        prod //= i
#    return prod

fa = a*modinv(a+b)%MOD
fb = b*modinv(a+b)%MOD

fapow = [1]
for _ in range(100010):
    fapow.append(fapow[-1]*fa%MOD)

fbpow = [1]
for _ in range(100010):
    fbpow.append(fbpow[-1]*fb%MOD)


def dp2(x,y):
    if x==n:
        return fa * dp2(x-1,y)
    elif y==n:
        return fb * dp2(x,y-1)
    elif x == n-1 or y == n-1:
        return choose(x+y,y) * fapow[x] % MOD*fbpow[y]


s = 0
for i in range(n):
    k = (n+i)*modinv(1-c)%MOD
    s = (s + k*dp2(n,i))%MOD
    s = (s + k*dp2(i,n))%MOD
print s
#for i in range(100):
#    A = []
#    for j in range(10):
#        x = dp(i,j)
#        denom = 1
#        while x%1:
#            x *= 2
#            denom *= 2
#        A.append((x,denom))
#    print [A]



Measured memory_bytes: 133220
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(a) (a).begin(),(a).end()
#define ll long long
int main(){
  int A,B,C;
  cin>>A>>B>>C;
  if(C>A&&C<B) cout<<"Yes"<<endl;
  else if(C>B&&C<A) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}



Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstdint>

using namespace std;

static void inputArray(int A[], int num) {
  for (int i = 0; i < num; i++) {
    cin >> A[i];
   }
}

static vector<int> L(100000 + 1);
static vector<int> R(100000 + 1);

static uint64_t inversions = 0;

static inline void merge(int A[], int left, int mid, int right) {
  int n1 = mid - left;
  int n2 = right - mid;

  L.assign(&A[left], &A[left + n1]);
  R.assign(&A[mid], &A[mid + n2]);
  L[n1] = R[n2] = INT32_MAX;

  for (int i = 0, j = 0, k = left; k < right; k++) {
    if (L[i] <= R[j]) {
      A[k] = L[i];
      i++;
    } else {
      A[k] = R[j];
      j++;
      inversions += n1 - i;
    }
  } 
}

static inline void mergeSort(int A[], int left, int right) {
  if (left + 1 < right) {
    int mid = (left + right) / 2;
    mergeSort(A, left, mid);
    mergeSort(A, mid, right);
    merge(A, left, mid, right);
  } 
}

static vector<int> A(200000);

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

  inputArray(&A[0], n);

  mergeSort(&A[0], 0, n);
  
  cout << inversions << endl;
    
  return 0;
}



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

int main()
{
  int d,n;
  cin >> d >> n;
  int num = pow(100,d)*n;
  if(d==0 && n==100) num++;
  if(d==1 && n==100) num+=100*d;
  if(d==2 && n==100) num+=pow(100,d);
  cout << num << endl;
  return 0;
}


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

int main(void) {
	int A, B, C;
	scanf("%d %d %d", &A, &B, &C);
	printf(A == B && B == C ? "Yes\n" : "No\n");
	return 0;
}


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

int main() {
  string A, B, C;
  cin >> A >> B >> C;
  if((A.at(A.size()-1)==B.at(0)) && (B.at(B.size()-1)==C.at(0))){
    cout << "YES" << endl;
  }
  else{
    cout << "NO" << endl;
  }
  
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    string s;
    cin>>s;
    n=s.size();
    int pos=0;
    long long int ans=0;
    while(pos<n)
    {
        int coun1=0;
        while(s[pos]=='<' && pos<n){
            ++pos;
            coun1++;
        }
        int coun2=0;

        while(s[pos]=='>' && pos<n)
        {
            coun2++;
            ++pos;
        }
       // cout<<coun1<<endl;
        //cout<<coun2<<endl;
        int x=min(coun1,coun2);
        int y=max(coun1,coun2);
        ans+= x * (long) (x-1)/2;
        ans+= y * (long)(y+1)/2;

    }
    cout<<ans<<endl;
}


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

int main(){
    double n;
    while(1){
        cin >> n;
        if(n < 0)   break;
        
        double integer;
        n = modf(n, &integer);
      
        int left = round(integer);
        
        if(left > 255){
            cout << "NA" << endl;
            continue;
        }
        
        int resinteger[8] = {};
        for(int i = 7; i >= 0; i--){
            resinteger[i] = left%2;
            left /= 2;
        }
        
        int resfloat[4] = {};
        double now = 0.5;
        for(int i = 0; i < 4; i++){
            if(n >= now){
                resfloat[i] = 1;
                n -= now;
            }
            now /= 2.0;
        }
        
        if(n == 0){
            for(int p : resinteger) cout << p;
            cout << ".";
            for(int p : resfloat)   cout << p;
            cout << endl;
        }else{
            cout << "NA" << endl;
        }
    }
    return 0;
}



Measured memory_bytes: 3312
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;

import java.util.*;

public class Main {
    long MOD = (long) 1e9 + 7;

    InputStream in;
    OutputStream out;

    public Main() {
        this(System.in, System.out);
    }

    public Main(InputStream in, OutputStream out) {
        this.in = in;
        this.out = out;
    }

    void run() {
        Scanner sc = new Scanner(this.in);
        PrintWriter out = new PrintWriter(this.out);

        // write your code
        int H = sc.nextInt(), W = sc.nextInt();
        int n = sc.nextInt();
        int[] cs = new int[n];
        int[][] map = new int[H][W];
        for (int i = 0; i < n; i++) {
            cs[i] = sc.nextInt();
        }

        int cur = 0;
        for (int h = 0; h < H; h++) {
            if (h % 2 == 0) {
                for (int w = 0; w < W; w++) {
                    map[h][w] = cur + 1;
                    cs[cur]--;
                    if (cs[cur] == 0) cur++;
                }
            } else {
                for (int w = W - 1; w >= 0; w--) {
                    map[h][w] = cur + 1;
                    cs[cur]--;
                    if (cs[cur] == 0) cur++;
                }
            }
        }

        for (int h = 0; h < H; h++) {
            for (int w = 0; w < W; w++) {
                out.print((w == 0 ? "" : " ") + map[h][w]);
            }
            out.println();
        }

        out.flush();
    }

    void debug(Object... os) {
        System.err.println(Arrays.deepToString(os));
    }

    public static void main(String[] args) {
        new Main().run();
    }
}

Measured memory_bytes: 32444
from itertools import accumulate
N, K = map(int, input().split())
A = list(map(int, input().split()))
M = sum(A)


ans_candidates = []
for n in range(1, int(M ** 0.5) + 1):
    if M % n == 0:
        ans_candidates.append(n)
        ans_candidates.append(M // n)


ans = 0
for X in ans_candidates:
    alpha = sorted([(a % X) for a in A])
    beta = [X - a for a in alpha]

    alpha = list(accumulate(alpha))
    beta = list(accumulate(beta))

    for i in range(N):
        if alpha[i] > K:
            break

        if alpha[i] == (beta[-1] - beta[i]):
            ans = max(ans, X)
            break

print(ans)


Measured memory_bytes: 42844
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <climits>

#define rep(i, m, n) for(int i=int(m);i<int(n);i++)
#define all(c) begin(c),end(c)

template<typename T1, typename T2>
inline void chmin(T1 &a, T2 b) { if (a > b) a = b; }

template<typename T1, typename T2>
inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }

//改造
typedef long long int ll;
using namespace std;
#define INF (1 << 30) - 1
#define INFl (ll)5e15
#define DEBUG 0 //デバッグする時1にしてね
#define dump(x)  cerr << #x << " = " << (x) << endl
#define MOD 1000000007


//ここから編集する
class Solve {
public:
    void input() {

    }

    void solve() {
        input();

        string s;
        cin >> s;

        for (int i = 0; i < s.size(); ++i) {
            for (int j = i; j <= s.size(); ++j) {
                string tmp;
                //i以前まで使う, jとその後ろを使う
                for (int k = 0; k < i; ++k) {
                    tmp += s[k];
                }
                for (int k = j; k < s.size(); k++) {
                    tmp += s[k];
                }

                if(tmp == "keyence"){
                    cout << "YES" << endl;
                    return;
                }

            }
        }

        cout << "NO" << endl;


    }
};


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

    Solve().solve();


    return 0;
}


Measured memory_bytes: 888
n=parse(Int,readline())
h=split(readline())
X=Any[]
for i=1:n
    X= push!(X , parse(Int,h[i]))
end
s=0
for i=1:n-1
  if X[n-i]<=X[n-i+1]
    s+=1
  elseif X[n-i]==X[n-i+1]+1
    X[n-i]=X[n-i]-1
    s+=1
  else
    break
  end
end

if n==1
  print("Yes")
  elseif s==n-1
  print("Yes")
else
  print("No")
end

Measured memory_bytes: 164648
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#include<queue>
#include<vector>
#include<ctime>
#include<map>
#include<bitset>
#include<set>
#define LL long long
#define mp(x,y) make_pair(x,y)
#define pll pair<long long,long long>
#define pii pair<int,int>
using namespace std;
inline int read()
{
	int f=1,x=0;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}
int stack[20];
template<typename T>inline void write(T x)
{
	if(x<0){putchar('-');x=-x;}
    if(!x){putchar('0');return;}
    int top=0;
    while(x)stack[++top]=x%10,x/=10;
    while(top)putchar(stack[top--]+'0');
}
template<typename T>inline void pr1(T x){write(x);putchar(' ');}
template<typename T>inline void pr2(T x){write(x);putchar('\n');}
const int MAXN=200005;
int a[MAXN],n,K,sta[MAXN],tp;
int mx[25][MAXN],mn[25][MAXN],bin[25],Log[MAXN],ans;
int getmx(int l,int r)
{
	int kk=Log[r-l+1];
	return max(mx[kk][l],mx[kk][r-bin[kk]+1]);
//	return a[mx[kk][l]]>a[mx[kk][r-bin[kk]+1]]?mx[kk][l]:mx[kk][r-bin[kk]+1];
}
int getmn(int l,int r)
{
	int kk=Log[r-l+1];
	return min(mn[kk][l],mn[kk][r-bin[kk]+1]);
}
int main()
{
	bin[0]=1;for(int i=1;i<=20;i++)bin[i]=bin[i-1]<<1;
	for(int i=2;i<MAXN;i++)Log[i]=Log[i>>1]+1;
	n=read();K=read();
	for(int i=1;i<=n;i++)a[i]=read()+1,mx[0][i]=mn[0][i]=a[i];tp=0;
	for(int i=2;i<=n;i++)if(a[i]<a[i-1])sta[++tp]=i;
	for(int i=1;bin[i]<=n;i++)
		for(int x=1;x+bin[i]-1<=n;x++)
			mx[i][x]=max(mx[i-1][x],mx[i-1][x+bin[i-1]]),mn[i][x]=min(mn[i-1][x],mn[i-1][x+bin[i-1]]);
	ans=n-K+1;
	for(int i=1;i+K-1<n;i++)
	{
		int u=getmx(i+1,i+K-1),v=getmn(i+1,i+K-1);
		if(a[i+K]>=u&&a[i]<=v)--ans;
	}bool tf=false;
	for(int i=1,cnt=0;i<=n+1;i++)
	{
		if(a[i]<a[i-1])
		{
			if(cnt>=K){ans-=tf;tf=true;}
			cnt=1;
		}
		else ++cnt;
	}pr2(ans);
	return 0;
}


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

main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    int n; cin>>n;
    vector<int> a(n),b(n);
    for(int i=0; i<n; ++i)
    {
        cin>>a[i];
    }
    for(int i=0; i<n; ++i)
    {
        cin>>b[i];
    }
    vector<int> aa(n*2),bb(n);
    for(int i=0; i<n; ++i)
    {
        bb[i]=b[i]^b[(i+1)%n];
    }
    for(int i=0; i<n*2; ++i)
    {
        int ii=i%n;
        aa[i]=a[ii]^a[(ii+1)%n];
    }
    vector<int> cc(bb);
    cc.resize(bb.size()+aa.size());
    copy(aa.begin(),aa.end(),cc.begin()+bb.size());

    vector<int> pref(cc.size());
    for(int i = 1, j = 0; i < (int)pref.size(); ++i)
    {
        if(pref[i - j] + i < pref[j] + j)
        {
            pref[i] = pref[i - j];
        }
        else
        {
            int k = std::max(0, pref[j] + j - i);
            while(k + i < (int)pref.size() && cc[k] == cc[k + i])
                ++k;
            pref[i] = k;
            j = i;
        }
    }
    pref[0] = cc.size();

    for(int k=0; k<n; ++k)
    {
        if(pref[k+bb.size()]>=bb.size())
        {
            cout << k << " " << (b[0]^a[k]) << "\n";
        }
    }

}

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

#define watch(x) cerr << (#x) << ": " << (x) << endl
#define int long long

const int N = 2000;
int n;
int l[N];

int32_t main() {

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    cin >> n;
    for(int i = 0; i < n; ++i) cin >> l[i];
    sort(l, l+n);

    int ans = 0;
    for(int c = n-1; c >= 2; --c) {
        for(int b = c-1; b >= 1; --b) {
            auto it = upper_bound(l, l+b, l[c]-l[b]);
            ans += (l+b) - it;
        }
    }

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


Measured memory_bytes: 384
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <cassert>
#include <string.h>
//#include <unordered_set>
//#include <unordered_map>
//#include <bits/stdc++.h>

#define MP(A,B) make_pair(A,B)
#define PB(A) push_back(A)
#define SIZE(A) ((int)A.size())
#define LEN(A) ((int)A.length())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define fi first
#define se second

using namespace std;

template<typename T>inline bool upmin(T &x,T y) { return y<x?x=y,1:0; }
template<typename T>inline bool upmax(T &x,T y) { return x<y?x=y,1:0; }

typedef long long ll;
typedef unsigned long long ull;
typedef long double lod;
typedef pair<int,int> PR;
typedef vector<int> VI;

const lod eps=1e-11;
const lod pi=acos(-1);
const int oo=1<<30;
const ll loo=1ll<<62;
const int mods=998244353;
const int MAXN=600005;
const int INF=0x3f3f3f3f;//1061109567
/*--------------------------------------------------------------------*/
inline int read()
{
	int f=1,x=0; char c=getchar();
	while (c<'0'||c>'9') { if (c=='-') f=-1; c=getchar(); }
	while (c>='0'&&c<='9') { x=(x<<3)+(x<<1)+(c^48); c=getchar(); }
	return x*f;
}
int f[1<<18][55];
PR a[MAXN];
int main()
{
	int n=read();
	for (int i=1;i<=n;i++) a[i].fi=read();
	for (int i=1;i<=n;i++) a[i].se=read();
	for (int i=0;i<1<<n;i++)
		for (int j=0;j<=50;j++) f[i][j]=INF; 
	f[0][1]=0;
	for (int i=1;i<1<<n;i++)
	{
		int t=__builtin_popcount(i);
		for (int p=1;p<=n;p++)
		if ((i>>(p-1))&1)
		{
			int j=(abs(t-p)&1)?a[p].se:a[p].fi,num=0;
			for (int k=p+1;k<=n;k++) if ((i>>(k-1))&1) num++;  
			for (int k=1;k<=j;k++) upmin(f[i][j],f[i^(1<<(p-1))][k]+num);
		}
	}
	int ans=INF;
	for (int i=1;i<=50;i++) upmin(ans,f[(1<<n)-1][i]);
	printf("%d\n",ans==INF?-1:ans);
/*
	for (int i=0;i<1<<n;i++)
		for (int j=1;j<=50;j++) cout<<i<<" "<<j<<" "<<f[i][j]<<endl; 
*/
	return 0;
}

Measured memory_bytes: 57216
#include <iostream>
#include <cstdio>

using namespace std;

bool isLeap(int i);

int main()
{
    int a, b;
    bool flag = false;
    while (cin >> a >> b, a || b) {
        bool fl = false;
        if (flag) {
            puts("");
        } else {
            flag = true;
        }
        for (int i = a; i <= b; i++) {
            if (isLeap(i)) {
                fl = true;
                cout << i << '\n';
            }
        }
        if (!fl) {
            puts("NA");
        }
    }
    return 0;
}

bool isLeap(int i)
{
    if (!(i % 400) ) {
        return true;
    } else if (!(i % 100) ) {
        return false;
    } else if (!(i % 4) ) {
        return true;
    } else {
        return false;
    }
}

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

#define FOR( i, m, n )  for( int (i) = (m); (i) < (n); (i)++ )
#define REP( i, n )     FOR( i, 0, n )
#define ALL( a )        (a).begin(), (a).end()             

bool binarySearch( vector<int>& a, int key );

int main( void ) {
	int n; cin >> n;
	vector<int> s( n );
	REP( i, n ) cin >> s[i];

	int q, key, sum = 0; cin >> q;
	REP( i, q ) {
		cin >> key;
		if( binarySearch( s, key ) ) sum++;
	}

	cout << sum << endl;

}

bool binarySearch( vector<int>& a, int key ) {
	int left = 0, right = a.size();
	
	while( left < right ) {
		int mid = ( left + right ) / 2;
		if( a[mid] == key ) return true;
		else if( key < a[mid] ) {
			right = mid;
		} else if( key > a[mid] ) {
			left = mid + 1;
		}
	}
	return false;
}


Measured memory_bytes: 3140
#include <iostream>
#include <cstdlib>
#include <vector>
#include <string>
#include <cstring>

using namespace std;

int main() {
    int n;
    cin >> n;
    
    vector<string> s(n);
    for (int i = 0; i < n; i++) {
        cin >> s[i];
        s[i] += s[i];
    }
    
    vector<string> tmp = s;
    
    s.insert(s.end(), tmp.begin(), tmp.end());
        
    vector<string> t(s.size(), string(2 * n, 0));
    
    for (int i = 0; i < 2 * n; i++) {
        for (int j = 0; j < 2 * n; j++) {
            t[i][j] = s[j][i];       
        }
    }
    
    int ans = 0;
    
    for (int j = 0; j < n; j++) {
        bool ok = true;

        for (int k = 0; k < n; k++) {
            if (memcmp(s[k].c_str() + j, t[j + k].c_str(), n) != 0) {
                ok = false;
                break;
            }
        }

        if (ok) {
            ans++;
        }
    }
    
    cout << ans * n << endl;
}


Measured memory_bytes: 1280
#include <bits/stdc++.h>
typedef long long LL;
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define REP(I, N) for (int I = 0; I < (N); ++I)
#define REPP(I, A, B) for (int I = (A); I < (B); ++I)
#define RI(X) scanf("%d", &(X))
#define RII(X, Y) scanf("%d%d", &(X), &(Y))
#define RIII(X, Y, Z) scanf("%d%d%d", &(X), &(Y), &(Z))
#define DRI(X) int (X); scanf("%d", &X)
#define DRII(X, Y) int X, Y; scanf("%d%d", &X, &Y)
#define DRIII(X, Y, Z) int X, Y, Z; scanf("%d%d%d", &X, &Y, &Z)
#define RS(X) scanf("%s", (X))
#define CASET int ___T, case_n = 1; scanf("%d ", &___T); while (___T-- > 0)
#define MP make_pair
#define PB push_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define PII pair<int,int>
#define VI vector<int>
#define VL vector<long long>
#define VPII vector<pair<int,int> >
#define PLL pair<long long,long long>
#define VPLL vector<pair<long long,long long> >
#define F first
#define S second

using namespace std;



int main(){
	int n;
	RI(n);
	VI a(n);
	REP (i,n) {
		RI(a[i]);
	}
	LL res=0;
	if (a[0]){printf("-1\n"); return 0;}
	
	REPP(i,1,n){
		if (a[i]<=a[i-1]) {res+=a[i];}
		else {
			if (a[i]==a[i-1]+1) {res++;}
			else {
			printf("-1\n"); 
			return 0;
			}
		}
	}
	printf("%lld\n",res);
	return 0;
}


Measured memory_bytes: 1024