akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#include <numeric>

using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define erep(i, n) for (ll i = 0; i <= (ll)(n); ++i)
#define FOR(i,a,b) for (ll i = (a); i < (ll)(b); ++i)
#define EFOR(i,a,b) for (ll i = (a); i <= (ll)(b); ++i)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } }


int main() {
    int n; cin >> n;
    string s; cin >> s;
    int ans = 0;
    int pos = 0;
    while(true) {
        auto p = s.find("ABC", pos);
        if (p == string::npos) {
            break;
        } else {
            pos = p+1;
            ans++;
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
using System;

class Program
{
	static int[] a;
	static void Main(string[] args)
	{
		int n = int.Parse(Console.ReadLine());

		a = new int[n];

		string[] str = Console.ReadLine().Split(' ');
		
		for (int i = 0; i < n; i++)
		{
			a[i] = int.Parse(str[i]);
		}

		InsertionSort();
	}


	static void InsertionSort()
	{
		for (int i = 0; i < a.Length; i++)
		{
			int v = a[i];
			int j = i - 1;

			while (j >= 0 && a[j] > v)
			{
				a[j + 1] = a[j];
				j --;
			}

			a[j + 1] = v;

			string output = "";
			for (int k = 0; k < a.Length; k++)
			{
				output += a[k];
				output += (k == a.Length-1) ? "" : " ";
			}

			Console.WriteLine(output);
		}
	}
}


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

typedef vector<int> vec;
typedef vector<vec> mat;

int MOD;

mat mul(mat& A, mat& B) {
	mat C(A.size(), vec(B[0].size()));
	for (int i = 0; i < A.size(); i++) {
		for (int k = 0; k < B.size(); k++) {
			for (int j = 0; j < B[0].size(); j++) {
				C[i][j] = (C[i][j] + A[i][k] * B[k][j]) % MOD;
			}
		}
	}
	return C;
}

mat pow(mat A, int n) {
	mat B(A.size(), vec(A.size()));
	for (int i = 0; i < A.size(); i++) {
		B[i][i] = 1;
	}
	while (n > 0) {
		if (n & 1) B = mul(B, A);
		A = mul(A, A);
		n >>= 1;
	}
	return B;
}

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

	int n, a, b, c, t;
	while (cin >> n >> MOD >> a >> b >> c >> t , n) {
		mat s(n, vec(1, 0));
		for (int i = 0; i < n; i++) {
			cin >> s[i][0];
		}

		mat m(n, vec(n, 0));
		for (int i = 1; i < n; i++) m[i][i - 1] = a;
		for (int i = 0; i < n; i++) m[i][i] = b;
		for (int i = 0; i < n - 1; i++) m[i][i + 1] = c;

		mat pm = pow(m, t);
		mat ans = mul(pm, s);

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

Measured memory_bytes: 3168
max = 0
N, M, Q = gets.chomp.split(" ").map{|i|i.to_i}
a=[]; b=[]; c=[]; d=[]
Q.times do |i|
  a[i], b[i], c[i], d[i] = gets.chomp.split(" ").map{|i|i.to_i}
end

(1..M).to_a.repeated_combination(N) do |arr|
  score = 0
  Q.times do |i|
    if arr[b[i]-1] - arr[a[i]-1] == c[i]
      score += d[i]
    end
  end
  max = [max, score].max
end

puts max

Measured memory_bytes: 14760
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;
namespace io
{
#define SIZ (1 << 21 | 1)
#define gc() (io::iS == io::iT ? (io::iT= (io::iS= io::ibuff) + fread(io::ibuff, 1, SIZ, stdin), (io::iS == io::iT ? EOF : *io::iS++)) : *io::iS++)
#define putc(x) (io::oS == io::oT ? (fwrite(io::obuff, 1, io::oS - io::obuff, stdout), io::oS= io::obuff, (*io::oS++= x)) : *io::oS++= x)
#define exit                                          \
	fwrite(io::obuff, 1, io::oS - io::obuff, stdout); \
	return 0;
	char *iS, *iT, ibuff[SIZ], obuff[SIZ], *oS= obuff, *oT= oS + SIZ - 1, fu[110], c;
	int fr;
	template <class Type>
	inline void read(Type &x)
	{
		x= 0;
		Type y= 1;
		for(c= gc(); (c > '9' || c < '0') && c != '-'; c= gc())
			;
		c == '-' ? y= -1 : x= (c & 15);
		for(c= gc(); c >= '0' && c <= '9'; c= gc()) x= x * 10 + (c & 15);
		x*= y;
	}
	inline void reads(char *x)
	{
		for(c= gc(); c == ' ' || c == '\n'; c= gc())
			;
		for(; c != ' ' && c != '\n' && c != EOF; *x= c, c= gc(), ++x)
			;
	}
	template <class Type>
	inline void print(Type x, char text= '\n')
	{
		if(x < 0) putc('-'), x*= -1;
		if(x == 0) putc('0');
		while(x) fu[++fr]= x % 10 + '0', x/= 10;
		while(fr) putc(fu[fr--]);
		putc(text);
	}
	inline void prints(char *x, char *y= NULL, char text= '\n')
	{
		for(; *x && x != y; ++x) putc(*x);
		putc(text);
	}
}  // namespace io
using io::print;
using io::prints;
using io::read;
using io::reads;
#define N 200001
#define M 4005
#define P 1000000007
int n, a[N], b[N], f[M][M], ans, jc[8005], invjc[8005];
inline int ksm(int a, int b)
{
	int s= 1;
	for(; b; b>>= 1, a= (long long)a * a % P)
		if(b & 1) s= (long long)s * a % P;
	return s;
}
inline int C(int n, int m) { return (long long)jc[n] * invjc[m] % P * invjc[n - m] % P; }
signed main()
{
	read(n);
	for(int i= 1; i <= n; i++) read(a[i]), read(b[i]);
	for(int i= 1; i <= n; i++) f[2000 - a[i]][2000 - b[i]]++;
	for(int i= 0; i <= 4000; i++)
	{
		for(int j= 0; j <= 4000; j++)
		{
			f[i + 1][j]= ((long long)f[i + 1][j] + f[i][j]) % P;
			f[i][j + 1]= ((long long)f[i][j + 1] + f[i][j]) % P;
		}
	}
	for(int i= 1; i <= n; i++) ans= ((long long)ans + f[2000 + a[i]][2000 + b[i]]) % P;
	jc[0]= invjc[0]= 1;
	for(int i= 1; i <= 8000; i++) jc[i]= (long long)jc[i - 1] * i % P, invjc[i]= ksm(jc[i], P - 2);
	for(int i= 1; i <= n; i++)
	{
		ans= ((long long)ans - C(2 * (a[i] + b[i]), 2 * b[i])) % P;
		if(ans < 0) ans+= P;
	}
	ans= (long long)ans * ksm(2, P - 2) % P;
	print(ans);
	exit;
}

Measured memory_bytes: 68480
from heapq import heappop, heappush
n, h = map(int, input().split())
T = []
for i in range(n):
    a, b = map(int, input().split())
    T.append((a, -b))

max_a, min_b_of_max_a = max(T)
min_b_of_max_a = - min_b_of_max_a
T.remove((max_a, -min_b_of_max_a))

H = []
for i in range(n-1):
    a, minus_b = T[i]
    heappush(H, (minus_b, a))

cnt = 0
while h > 0:
    if min_b_of_max_a >= h:
        h -= min_b_of_max_a
        cnt += 1
        break

    if H:
        b, a = heappop(H)
        b = -b
    else:
        break

    if b <= max_a:
        break
    else:
        h -= b
        cnt += 1


if h > 0:
    h -= min_b_of_max_a
    cnt += 1
    if h > 0:
        cnt += (h + max_a-1)//max_a

print(cnt)

    

    

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

int main() {

  int N, M, C;
  cin >> N >> M >> C;
  vector <int> B(M);
  for (int i = 0; i < M; i++) 
      cin >> B.at(i);
  int count = 0;
  for (int i = 0; i < N; i++) {
    int num = 0;
    for (int j = 0; j < M; j++) {
        int F = 0;
        cin >> F;
        num += B.at(j)*F;
    }
    if(num+C>0) count++;
  }

  cout << count << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define endl '\n'
#define int long long int
using namespace std;
#define pii pair <int, int>
#define mii map<int, int>
#define pb push_back
#define deb(x) cout << #x << " " << x << endl
#define deb2(x, y) cout << #x << " " << x << " " << #y << " " << y << endl
#define Loop(s, e, itr) for (int itr = s; itr < e; itr++)
#define loop(n) for(int i = 0; i < n; i++)
#define vin vector<int>
#define w(t) int tc; cin >> tc; for(int t = 1; t <= tc; t++)
#define vec vector
#define mod 1000000007
#define all(x) x.begin(), x.end()

int nodes, edges;

vin adj_list[100005];

vec<bool> vis(100005, false);
int dp[100005];
int dfs(int node, int tab){
    if(dp[node] == -1){
        int ans = 0;
        for(auto i : adj_list[node]) ans = max(ans, dfs(i, tab+1) + 1);
        dp[node] = ans;
    }
    return dp[node];
}

int32_t main(){
    cin >> nodes >> edges;
    int a, b;
    memset(dp, -1, sizeof(dp));
    loop(edges){
        cin >> a >> b;
        adj_list[a].pb(b);
    } 
    int ans = 0;
    for(int i = 1; i < nodes+1; i++) ans = max(ans, dfs(i, 0));
    cout << ans << endl;
}

Measured memory_bytes: 12608
N = int(input())
XY = []
for _ in range(N):
    XY.append([int(i) for i in input().split()])
case_list = [n for n in range(N)]
from itertools import permutations
P = list(permutations(case_list,N))
dist_sum = 0
cnt = 0
for p in P:
    dist = 0
    for i in range(len(p)-1):
        dist += ((XY[p[i+1]][0] - XY[p[i]][0]) ** 2 + (XY[p[i+1]][1] - XY[p[i]][1]) ** 2) ** 0.5
    dist_sum += dist
    cnt += 1
print(dist_sum / cnt)

Measured memory_bytes: 8052
#include<bits/stdc++.h>
using namespace std; 
int main(){ 
int n; int sum=0;  
cin>>n;
vector<int> v(n+1);
for(int i=1;i<=n;i++)cin>>v[i];
for(int i=1;i<=n;i++){for(int  j=i+1;j<=n;j++){sum+=v[j]*v[i]; }}cout<<sum;}


Measured memory_bytes: 3472
#include <iostream>
#include <fstream>
#include <stdio.h>
#include <vector>
#include <string>
#include <math.h>
#include <algorithm>
#include <map>
#include <set>

#define sz(x) ((int)x.size())
#define all(x) (x).begin(), (x).end()
#define pb(x) push_back(x)
#define mp(x, y) make_pair(x, y)

typedef long long int64;

using namespace std;

int sqr(int x) {
    return x * x;
}

double dist(int x1, int y1, int x2, int y2) {
    return sqrt(sqr(x2 - x1) + sqr(y2 - y1));
}

int main() {
	ios_base::sync_with_stdio(0);
	int n;
	cin >> n;
    vector<int> x(n), y(n);
	for (int i = 0; i < n; ++i) {
	    cin >> x[i] >> y[i];
	}
	vector<int> a(n);
	for (int i = 0; i < n; ++i) a[i] = i;
	double sum = 0;
	int cnt = 0;
	while (true) {
	    ++cnt;
		for (int i = 0; i + 1 < n; ++i) {
		    sum += dist(x[a[i]], y[a[i]], x[a[i + 1]], y[a[i + 1]]);
		}
		if (!next_permutation(all(a))) {
		    break;
		}
	}
	cout.precision(10);
	cout << sum / cnt << endl;

    return 0;
}


Measured memory_bytes: 256
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

n = int(readline())
p = list(map(int, readline().split()))
temp = p[0]
lis = p[1:]
ans = 1

for i in lis:
    if (i > temp):
        pass
    else:
        temp = i
        ans += 1

print(ans)


Measured memory_bytes: 27756
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define mod 1000000007
#define f(i,a,b) for(ll i=a;i<b;i++)
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ii pair<ll,ll>
#define vii vector<ii>
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define MAX 1e9

ll modpow(ll base, ll exp, ll modulus) {base %= modulus;ll result = 1;while (exp > 0) {if (exp & 1) result = (result * base) % modulus;base = (base * base) % modulus;exp >>= 1;}return result;}
const ld pi=acos(-1);

int main(){
    IOS;
    ll n;cin>>n;
    ll a[n];f(i,0,n)cin>>a[i];
    ll ans[n];ans[0]=0;
    f(i,1,n){
        if(i==1)ans[i]=abs(a[i]-a[0]);
        else ans[i]=min(ans[i-1]+abs(a[i]-a[i-1]),ans[i-2]+abs(a[i]-a[i-2]));
    }
    cout<<ans[n-1];
    return 0;
}   


Measured memory_bytes: 1792
/*input
4
0 1 0 0
0 0 0 1
1 0 0 0
0 0 1 0


*/ 
#include <iostream>
#include <bits/stdc++.h>
#include <math.h> 
    
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define gc getchar_unlocked
#define fo(i,n) for(ll i=0;i<n;i++)
#define Fo(i,k,n) for(ll i=k;k<n?i<n:i>n;k<n?i+=1:i-=1)
#define int long long
#define si(x)   scanf("%d",&x)
#define sl(x)   scanf("%lld",&x)
#define ss(s)   scanf("%s",s)
#define pi(x)   printf("%d\n",x)
#define pl(x)   printf("%lld\n",x)
#define ps(s)   printf("%s\n",s)
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, sizeof(x))
#define sortall(x) sort(all(x))
#define tr(it, a) for(auto it = a.begin(); it != a.end(); it++)
#define PI 3.1415926535897932384626
#define ms(a,x) memset(a, x, sizeof(a));
#define endl "\n"
typedef pair<int, int>  pii;
typedef vector<int>     vi;
typedef vector<pii>     vpii;
typedef vector<vi>      vvi;
int mpow(int base, int exp); 
void ipgraph(int m);
//void dfs(int u, int par);
const int mod = 1000000007;
const int N = 1000000001;
const int MAX = 1e5+1;


int32_t main() {
    IOS;
	int n;cin>>n;
	int arr[n][n];
	for(int i=0;i<n;i++){
		for(int j=0;j<n;j++){
			cin>>arr[i][j];
		}
	}
	vector<int> dp((1<<n),0);
	dp[0] = 1;
	for(int mask=0;mask<(1<<n);mask++){
		int a = __builtin_popcount(mask);
		for(int b = 0;b<n;b++){
			if(!(mask&(1<<b)) && arr[a][b]){
				int m2 = mask^(1<<b);
				dp[m2] = (dp[m2]+dp[mask])%mod; 
			}
		}
	}
	cout<<dp[(1<<n)-1]<<endl;
	return 0;
}






Measured memory_bytes: 16640
H,W=map(int,input().split())
A=[input() for i in range(H)]
d=[[0]*(W+1) for i in range(H+1)]
d[0][1]=1
m=10**9+7
for i in range(H):
    for j in range(W):
        if A[i][j]=='.':
            d[i+1][j+1]=(d[i][j+1]+d[i+1][j])%m
print(d[-1][-1])

Measured memory_bytes: 43604
#include<iostream>
#include<vector>
#include<string>
#include<cstdio>
#include<cstdlib>

using namespace::std;

int main(){
  int number;
  int i;
  int j;
   char string[300] = {};
  int seq = 0;
  int max = 0;

  cin>>number;

  while(number != 0){
    int matrix[number][number];

  for(i = 0; i < number; i++){
    scanf("%s", string);
    for(j = 0; j < number; j++){
      matrix[i][j] = string[j] - '0';
    }
  }

  for(i = 0; i < number; i++){ // 横
    for(j = 0; j < number; j++){
      if(matrix[i][j] == 1){
        seq++;
      }else{
        seq = 0;
      }
      if(max < seq){
        max = seq;
      }
    }
    seq = 0;
  }
  for(i = 0; i < number; i++){ // たて
    for(j = 0; j < number; j++){
      if(matrix[j][i] == 1){
        seq++;
      }else{
        seq = 0;
      }
      if(max < seq){
        max = seq;
      }
    }
    seq = 0;
  }

  for(i = 0; i < number; i++){
    for(j = 0; j <= i; j++){
      if(matrix[i -j][j] == 1){
        seq++;
      }else{
        seq = 0;
      }
      if(max < seq){
        max = seq;
      }
    }
    seq = 0;
  }

  for(i = 0; i < number - 1; i++){
    for(j = 0; j <= i; j++){
      if(matrix[(number - 1) - (i - j)][(number - 1) - j]){
        seq++;
      }else{
        seq = 0;
      }
      if(max < seq){
        max = seq;
      }
    }
    seq = 0;
  }
  for(i = 0; i < number; i++){
    for(j = 0; j <= i; j++){
      if(matrix[(number - 1) - (i -j)][j] == 1){
        seq++;
      }else{
        seq = 0;
      }
      if(max < seq){
        max = seq;
      }
    }
    seq = 0;
  }
  for(i = 0; i < number - 1; i++){
    for(j = 0; j <= i; j++){
      if(matrix[i -j][(number - 1) - j] == 1){
        seq++;
      }else{
        seq = 0;
      }
      if(max < seq){
        max = seq;
      }
    }
    seq = 0;
  }
  seq = 0;
  printf("%d\n", max);
  max = 0;
  cin>>number;
  }
  return 0;
}

Measured memory_bytes: 1424
#include "bits/stdc++.h"
using namespace std;
#ifdef _DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

#define int long long
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
const double PI = acos(-1);
const double EPS = 1e-9;
template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; }
int gcd(int x, int y) { return y ? gcd(y, x%y) : x; }
signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N, K; cin >> N >> K;
	vector<int> v(N); rep(i, 0, N) { cin >> v[i]; }
	int M = *max_element(all(v));
	if (N == 1) {
		if (v[0] == K)cout << "POSSIBLE" << endl;
		else cout << "IMPOSSIBLE" << endl;
	}
	else {
		if (M < K) {
			cout << "IMPOSSIBLE" << endl;
		}
		else if (M == K)cout << "POSSIBLE" << endl;
		else {
			M = *min_element(all(v));
			bool f(true);
			rep(i, 0, N) {
				if (gcd(M, v[i]) == 1)f = false;
			}
			if (f) {
				sort(all(v));
				bool g(false);
				rep(i, 1, N) {
					if (v[i] >= K&&K%gcd(v[0], v[i]) == 0)g = true;
				}
				if (g)cout << "POSSIBLE" << endl;
				else cout << "IMPOSSIBLE" << endl;
			}
			else cout << "POSSIBLE" << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
 
#define rep(i, n) for (int i = (int)(0); i < (int)(n); ++i)
#define reps(i, n) for (int i = (int)(1); i <= (int)(n); ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; i--)
#define irep(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define ireps(i, m, n) for (int i = (int)(m); i <= (int)(n); ++i)
#define FOR(e, c) for (auto &e : c)
#define SORT(v, n) sort(v, v + n);
#define vsort(v) sort(v.begin(), v.end());
#define rvisort(v) sort(v.begin(), v.end(), greater<int>());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
#define rv(s) reverse(s.begin(),s.end());
 
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using vpii = vector<pii>;
using vs = vector<string>;
using vd = vector<double>;
using ul = unsigned long;
 
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int GCD(int a, int b) { return b ? GCD(b, a%b) : a; }

void printv(vi& v){
  rep(i,v.size()) cout << v[i] << " ";
  cout << endl;
}

int main()
{
  cin.tie( 0 );
  ios::sync_with_stdio( false );
  
  int n;cin>>n;
  vi h(n);
  rep(i,n)cin>>h[i];
  
  int ans=0;
  while(true){
    
    if(*max_element(h.begin(), h.end())==0) break;
    
    int i=0;
    while(i<n){
      if(h[i]==0) i++;
      else {
        ans++;
        while(h[i]>0 && i<n){
          --h[i];
          i++;
        }
      }
    }
  }
  cout(ans);
}

Measured memory_bytes: 256
function main(input) {
	var a = input[0].split(' ');
	var w = parseInt(a[0])
	var h = parseInt(a[1])
	var x = parseInt(a[2])
	var y = parseInt(a[3])
	var r = parseInt(a[4])

	if(((x+r)<=w)&((x-r)>=0)&((y+r)<=h)&((y-r)>=0)){
		console.log("Yes")
	}else{
		console.log("No")
	}
}

var input = '';

process.stdin.resume();
process.stdin.setEncoding('utf8');
process.stdin.on('data', function(chunk) {
  input += chunk;
});
process.stdin.on('end', function() {
  input = input.split('\n');
  main(input);
});

Measured memory_bytes: 7648
#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 N, r(0); std::cin >> N;
    std::string c; std::cin >> c;
    for(int i(0); i < N; ++i){
        if(c[i] == 'R') ++r;
    }
    int ans(0);
    for(int i(0); i < r; ++i){
        if(c[i] == 'W') ++ans;
    }
    std::cout << ans << std::endl;
    return 0;
}


Measured memory_bytes: 3716
from sys import stdin

n,k = [int(x) for x in stdin.readline().rstrip().split()]
li = list(map(int,stdin.readline().rstrip().split()))

def score(li,n,k):
    dp = [-1 for _ in li]
    dp[0] = 0
    if n == 1:
        return 0
    elif n <= k:
        return abs(li[-1]-li[0])
    for i in range(1,n):
        dp[i] = min([dp[j] + abs(li[j] - li[i]) for j in range(max(0, i - k), i)])
    return dp[n-1] 

print(score(li,n,k))

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

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

  std::vector<int> Hs(N);
  for (auto&& H : Hs) std::cin >> H;

  int ans = 0;
  int Hmax = Hs[0];
  for (auto&& H : Hs) {
    if (Hmax <= H) {
      ++ans;
      Hmax = H;
    }
  }
  std::cout << ans << std::endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);

    int n;
    cin >> n;
    vector<int> S(n);
    for (int i=0; i<n; ++i) {
        cin >> S[i];
    }

    int q, T, ans = 0;
    cin >> q;
    for (int i=0; i<q; ++i) {
        cin >> T;
        if (binary_search(S.begin(), S.end(), T)) ans ++;
    }
    cout << ans << endl;
    return 0;
}

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

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

  int N;  std::cin >> N;
  std::vector<int> V(N+1), W(N+1);
  for (int i=1; i<=N; ++i) std::cin >> V[i] >> W[i];

  int Q; std::cin >> Q; std::vector<int> ans(Q);
  for(int q=0; q<Q; q++) {
    int v, L; std::cin >> v >> L;

    using P = std::pair<int,int>;
    std::vector<P> l1, l2;

    auto gen = [&](std::vector<P> &l, int thr) {
      std::vector<P> tmp;
      l.emplace_back(0, 0);
      while (v >= thr) {
        int p1 = 0, p2 = 0;
        while (p1 < (int)l.size() || p2 < (int)l.size()) {
          P nxt;
          if (p1 < (int)l.size() && l[p1].first < l[p2].first + W[v])
            nxt = l[p1++];
          else
            nxt = {l[p2].first + W[v], l[p2++].second + V[v]};
          if (tmp.empty() || tmp.back().second < nxt.second) tmp.push_back(nxt);
        }
        v /= 2;
        l.swap(tmp);
        tmp.clear();
      }
    };

    constexpr int b = 9;
    gen(l1, 1 << b);
    gen(l2, 1);
    int p1 = 0, p2 = 0;
    while (p2 + 1 < (int)l2.size() && l1[p1].first + l2[p2 + 1].first <= L) p2++;
    ans[q] = l1[p1].second + l2[p2].second;
    while (++p1 < (int)l1.size() && l1[p1].first <= L) {
      while (l1[p1].first + l2[p2].first > L) p2--;
      ans[q] = std::max(ans[q], l1[p1].second + l2[p2].second);
    }
  }
  for(auto&& a : ans) std::cout << a << std::endl;
  return 0;
}



Measured memory_bytes: 5544
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
#define mrep(i,j,n) for(int i = j; i < n; i++)
#define reps(i,n) for(int i = 1; i <= n; i++)
#define rrep(i,n) for(int i = n-1; i >= 0; i--)
#define mreps(i,j,n) for(int i = j; i <= n; i++)
#define rreps(i,n) for(int i = n; i >= 1; i--)
#define co(x) cout << x <<endl
#define cs(x) cout << x <<" "
#define el cout << endl
#define sp(x) cout << setprecision(x);
#define cer(x) cerr << x <<endl
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define ERASE(x,val) x.erase(remove(ALL(x), val), x.end())
#define vi vector<int> 
#define vvi vector<vector<int>> 
#define vpii vector<pair<int,int>> 
#define vl vector<ll> 
#define vvl vector<vector<ll>> 
#define vd vector<double> 
#define vvd vector<vector<double>> 
#define vb vector<bool> 
#define vvb vector<vector<bool>>
#define vs vector<string>
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
ll mod = 1e9 + 7;
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; }
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { ll g = gcd(a, b); return a * b / g; }
bool is_prime(ll x) { for (ll i = 2; i * i <= x; i++) { if (x % i == 0)return false; } return true; }


int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	double h, a;
	cin >> h >> a;
	int ans = ceil(h/a);
	co(ans);
	return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
class Program
{
	static void Main(string[] args)
	{
		int N = int.Parse(Console.ReadLine());
		string[] str = Console.ReadLine().Split();
		long[]A = new long[N];
		long[,]D = new long[N,3];
		for(var i=0;i<N;i++){
			A[i] = long.Parse(str[i]);
		}
		D[N-1,0] = A[N-1];
		D[N-2,1] = A[N-2];
		if(N>=3){
			D[N-3,2] = A[N-3];
		}
		for(var i=N-2;i>=0;i--){
			if((N-1-i)%2==0){
				D[i,0] = D[i+2,0] + A[i];
			}
			if((N-2-i)%2==0 && i+2<N){
				D[i,1] = D[i+2,1]+A[i];
				if(i+3<N){
					D[i,1] = Math.Max(D[i,1],D[i+3,0]+A[i]);
				}
			}
			if((N-3-i)%2==0){
				D[i,2] = D[i+2,2]+A[i];
				if(i+3<N){
					D[i,2] = Math.Max(D[i,2],D[i+3,1]+A[i]);
				}
				if(i+4<N){
					D[i,2] = Math.Max(D[i,2],D[i+4,0]+A[i]);
				}
			}
		}
		long ans = 0;
		ans = D[N+1-N/2*2,0];
		ans = Math.Max(ans,D[N-N/2*2,1]);
		if(N-1-N/2*2 >= 0){
			ans = Math.Max(ans,D[N-1-N/2*2,2]);
		}
      for(var h=0;h<3;h++){
		for(var i=0;i<N;i++){
        }
        }
		Console.WriteLine(ans);
	}
}

Measured memory_bytes: 47388
#include<stdio.h>
#include<stdlib.h>

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;
#define NIL NULL

Node root =NIL;

Node treeMinimum(Node x){
  while(x->left!=NIL)x=x->left;
  return x;
}

Node treeSearch(Node x, int k){
  while (x!=NIL && k!=x->key){
    if(k<x->key)x=x->left;
    else x=x->right;

  }
 return x;
}

Node treeSuccessor(Node x){
  Node y;
  if(x->right!=NIL){
    return treeMinimum(x->right);
  }
  y=x->parent;
  while (y !=NIL && x==y->right){
    x=y;
    y=y->parent;
  }
  return y;
}



void treeDelete(Node z){
  Node y; // node to be deleted
  Node x; // child of y
  if(z->left==NIL||z->right==NIL){
    y=z;
  }
  else y=treeSuccessor(z);
  if(y->left!=NIL)x=y->left;
  else x=y->right;
  if(x!=NIL)x->parent=y->parent;
  if(y->parent==NIL)root=x;
  else if(y==y->parent->left)y->parent->left=x;
  else y->parent->right=x; 

  if(y!=z)z->key=y->key;

}



void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;

  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;

  while(x!=NIL){
    y=x;
    if(z->key<x->key)x=x->left;
    else x=x->right;
  }
  z->parent=y;
  if(y==NIL)root=z;
  else if (z->key<y->key)y->left=z;
  else y->right=z;
}

void inorder(Node u){
  if(u!=NIL){
    inorder(u->left);
    printf(" %d",u->key);
    inorder(u->right);
  }
}
void preorder(Node u){
  if(u!=NIL){
    
    printf(" %d",u->key); 
    preorder(u->left);
    preorder(u->right);

  }
}


int main(){
  int n, i, x;
  char com[20];
  scanf("%d", &n);

  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
    if ( com[0] == 'f' ){
      scanf("%d", &x);
      Node t = treeSearch(root, x);
      if ( t != NIL ) printf("yes\n");
      else printf("no\n");
    } else if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    } else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    } else if ( com[0] == 'd' ){
      scanf("%d", &x);
      treeDelete(treeSearch(root, x));
    }
  }

  return 0;
}

Measured memory_bytes: 19364
#include <stdio.h>
  
int main(void){
int number[10000],x,i=0,n;
scanf("%d",&x);
if(x!=0){
	do{
		i++;
		number[i]=x;
		scanf("%d",&x);
	} while(x!=0 && i<=10000);
}
n=i;
for(i=1;i<=n;i++){
printf("Case %d: %d\n",i,number[i]);
}
return 0;
}

Measured memory_bytes: 636
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define MOD 1000000007
#define INF 1000000000000000000

int main(){
  int N;
  cin>>N;
  vector<int> a(N);
  for(int i=0;i<N;i++){
    cin>>a.at(i);
  }
  int ans=0;
  bool flag=false;
  for(int i=0;i<N-1;i++){
    if(a.at(i)==a.at(i+1)){
      if(flag){
        flag=false;
      }else{
        ans++;
        flag=true;
      }
    }else{
      flag=false;
    }
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 384
import sys
sys.setrecursionlimit(1000000)
INF = 10 ** 20

def update_state(state, newx):
  tmp = list(state)
  tmp[newx] = 1
  return tuple(tmp)

def get_co(x, y):
  dc = do = 0
  score = mp[y][x]
  if score < 0:
    dc = -score
  else:
    do = score
  return dc, do

def minimum_cost(x, y, state, ox, goal, dic, w, m):
  if (x, y, state, ox) in dic:
    return dic[(x, y, state, ox)]
  if y == goal:
    return 0
  if ox <= 1:
    return INF
  
  ret = INF
  
  if x >= 1:
    if state[x - 1] == 0:
      dc, do = get_co(x - 1, y)
      ret = min(ret, minimum_cost(x - 1, y, update_state(state, x - 1), min(ox + do - 1, m), goal, dic, w, m) + dc)
    else:
      ret = min(ret, minimum_cost(x - 1, y, state, ox - 1, goal, dic, w, m))
  
  if x < w - 1:
    if state[x + 1] == 0:
      dc, do = get_co(x + 1, y)
      ret = min(ret, minimum_cost(x + 1, y, update_state(state, x + 1), min(ox + do - 1, m), goal, dic, w, m) + dc)
    else:
      ret = min(ret, minimum_cost(x + 1, y, state, ox - 1, goal, dic, w, m))
 
 
  dc, do = get_co(x, y + 1)
  ret = min(ret, minimum_cost(x, y + 1, tuple((1 if i == x else 0 for i in range(w))), min(ox + do - 1, m), goal, dic, w, m) + dc)
  dic[(x, y, state, ox)] = ret
  return ret

while True:
  w, h = map(int, input().split())
  if w == 0:
    break
  f, m, o = map(int, input().split())
  mp = [list(map(int, input().split())) for _ in range(h)]
  if o <= 1:
    print("NA")
    continue
  dic = {}
  ans = INF
  for i in range(w):
    dc, do = get_co(i, 0)
    state = tuple(1 if i == j else 0 for j in range(w))
    ans = min(ans, minimum_cost(i, 0, state, min(o + do - 1, m), h - 1, dic, w, m) + dc)
  if ans > f:
    print("NA")
  else:
    print(ans)


Measured memory_bytes: 13912
N, M = map(int, input().split())
ans = set(range(1, N+1))
l_max = 1
r_min = N

for i in range(M):
    l, r = map(int, input().split())
    l_max = max(l_max, l)
    r_min = min(r_min, r)

print(max(0, r_min - l_max + 1))

Measured memory_bytes: 50660
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<bitset>
#include<deque>
#include<functional>
#include<iterator>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<utility>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
#define a first
#define b second
#define sz(x) (ll)((x).size())
#define pb push_back
#define mp make_pair
#define bg begin()
#define ed end()
#define all(x) (x).bg,(x).ed
#define rep(i,n) for(ll i=0;i<(n);i++)
#define rep1(i,n) for(ll i=1;i<=(n);i++)
#define rrep(i,n) for(ll i=(n)-1;i>=0;i--)
#define rrep1(i,n) for(ll i=(n);i>=1;i--)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
const ll MOD=1000000007;
const ll INF=1000000000000000;
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 maxx(ll x,ll y,ll z){return max(max(x,y),z);}
ll minn(ll x,ll y,ll z){return min(min(x,y),z);}
ll gcd(ll x,ll y){if(x%y==0) return y;else return gcd(y,x%y);}
ll lcm(ll x,ll y){return x*(y/gcd(x,y));}
ll digsz(ll x){if(x==0) return 1;else{ll ans=0;while(x){x/=10;ans++;}return ans;}}
ll digsum(ll x){ll sum=0;while(x){sum+=x%10;x/=10;}return sum;}
vector<ll> pw2(62,1);vector<ll> pw10(19,1);
const ll V=10;//頂点数

ll d[10][10];//d[u][v]は辺e=(u,v)のコスト(存在しない場合はINF、ただしd[i][i]=1とする)

void warshall_floyd(){
    rep(k,V)rep(i,V)rep(j,V){
        d[i][j]=min(d[i][j],d[i][k]+d[k][j]);
    }
}

int main(){
    {rep1(i,61) pw2[i]=2*pw2[i-1];}
    {rep1(i,18) pw10[i]=10*pw10[i-1];}
    
    ll H,W; cin>>H>>W;
    rep(i,10)rep(j,10) cin>>d[i][j];
    
    warshall_floyd();
    
    ll ans=0;
    rep(i,H)rep(j,W){
        ll x; cin>>x;
        if(x!=-1) ans+=d[x][1];
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 3612
#include<bits/stdc++.h>
#define ll long long
#define int long long int
#define MOD 1000000007
#define mkp make_pair
#define maxn 100005
#define pb push_back
#define ff first
#define ss second
#define debug1(a) cout<<a<<endl;
#define debug2(a,b) cout<<a<<' '<<b<<endl;
#define debug3(a,b,c) cout<<a<<' '<<b<<' '<<c<<endl;
#define rep(i,n) for(int i=0;i<n;i++)
#define repl(i,a,b) for(int i=a;i<b;i++)
#define pi pair<int,int>
#define pii pair<int,pi>
#define mp map<int,int>
#define ump unordered_map<int,int>
#define  vi vector<int>
#define st set<int>
#define mst multiset<int>
#define pq priority_queue
#define mpq priority_queue<int,vector<int>,greater<int> >
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define in cin>>
#define out cout<<
using namespace std;
const int infi=1e9+7;
void printVector(vector<int> v){
    for(int i=0;i<(int)v.size();i++)
        cout<<v[i]<<" ";
    out endl;
}

void printArray(int arr[],int n)
{
   for(int i=0;i<n;i++)cout<<arr[i]<<' ';
cout<<endl;
}
 set<pair<int,int>> primeset;
 vi prime_number;
void SieveOfEratosthenes(int n)
{
    bool prime[n+1];
    memset(prime, true, sizeof(prime));

    for (int p=2; p*p<=n; p++)
    {
        if (prime[p] == true)
        {
        for (int i=p*p; i<=n; i += p)
                prime[i] = false;
        }
    }
    for (int p=2; p<=n; p++)
       if (prime[p])
           primeset.insert(mkp(p,1));
}
ll modExp(ll base, ll power) {
    if (power == 0) {
        return 1;
    } else {
        ll cur = modExp(base, power / 2); cur = cur * cur; cur = cur % MOD;
        if (power % 2 == 1) cur = cur * base;
        cur = cur % MOD;
        return cur;
    }
}
//for making unordered_map with pair
struct hash_pair {
    template <class T1, class T2>
    size_t operator()(const pair<T1, T2>& p) const
    {
        auto hash1 = hash<T1>{}(p.first);
        auto hash2 = hash<T2>{}(p.second);
        return hash1 ^ hash2;
    }
};
int32_t main()
{
fastio;
int tt=1;
int t=1;
//in t;
while(t--){
int n,m;cin>>n>>m;
cout<<(n*(n-1)/2 + m*(m-1)/2);
}
    return 0;
}

/*
google kick start
  cout << "Case #" << tt << ": "<<ans<<endl;
*/


Measured memory_bytes: 256
using System;

class Program {
  static void Main(string[] args) {
    string[] str = Console.ReadLine().Split(' ');
    int K = int.Parse(str[0]);
    int S = int.Parse(str[1]);
    int rep = 0;

    for(int a = Math.Max(S - 2 * K, 0); a <= K && a <= S; ++a) {
      rep += Math.Min(K, S - a) - Math.Max(S - a - K, 0) + 1;
    }

    Console.WriteLine(rep);
  }
}


Measured memory_bytes: 11092
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
typedef long long ll;
typedef pair<int, int> P;
const int INF = 100100100;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
struct Edge {
  ll to;
  ll cost;
};
int main() {
  ll N;
  cin >> N;
  string S;
  cin >> S;
  vector<ll> _e(N), _w(N);
  if (S[0] == 'E') {
    _e[0] = 1;
    _w[0] = 0;
  } else {
    _e[0] = 0;
    _w[0] = 1;
  }
  for (int i = 1; i < N; i++) {
    if (S[i] == 'E') {
      _e[i] = _e[i - 1] + 1;
      _w[i] = _w[i - 1];
    } else {
      _e[i] = _e[i - 1];
      _w[i] = _w[i - 1] + 1;
    }
  }
  int ans = INF;
  for (int i = 0; i < N; i++) {
    int num1 = 0;
    if(i!=0){
      num1 = _w[i - 1];
    }
    int num2 = 0;
    if(i!=N-1){
      num2 = _e[N - 1] - _e[i];
    }
    ans = min(ans, num1 + num2);
  }
  cout << ans << endl;
}

Measured memory_bytes: 8232
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
#include <queue>
#include <cstdio>
#include <stack>
using namespace std;
typedef long long ll;


int main(){
    ll a,b,d1=0,d2=0,l,m,n,o=0,q,r,x,y,z,max1=0,ans=0,h,w,j1,a1=0,b1=0;
    string s,t,u;
    cin>>h>>w>>a>>b;
    ll c[w][h]={},p[w]={};
    
    
    
        for(ll i=1;i<=h;i++){
            for(ll j=1;j<=w;j++){
                if(j<=a&&i>b)cout<<1;
                else if(j>a&&i<=b)cout<<1;
                else cout<<0;
            }
            cout<<endl;
        }

    
}
    






Measured memory_bytes: 9088
a, b, c = map(int, input().split())
n = 0
if a == b :
    if c % a == 0 :
        n = n + 1
else :
    i = list(range(a, b+1))
    for x in i :
        if c % x == 0 :
            n = n + 1
print(n)


Measured memory_bytes: 5716
from itertools import accumulate
N=int(input())
A=list(map(int,input().split()))
s=sum(A)
A=A+A
B=[0]+list(accumulate(A[::2]))
C=[0]+list(accumulate(A[1::2]))
ans=[]
k=(N-1)//2
for i in range(1,N+1):
    j=i//2
    if i%2==0:
        ans.append(str(s-2*(B[j+k]-B[j])))
    else:
        ans.append(str(s-2*(C[j+k]-C[j])))
        
print(" ".join(ans))

Measured memory_bytes: 28608
n=int(input())
t,a=map(int,input().split())
h=list(map(int,input().split()))
b=1
c=abs(t-h[0]*0.006-a)
for i in range(n) :
  if(abs(t-h[i]*0.006-a)<c):
    b=i+1
    c=abs(t-h[i]*0.006-a)
  else:
    continue
print(b)


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

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

  if (A >= B && A >= C) {
    int ans = A;
    for (int i = 0; i < K; i++) {
      ans *= 2;
    }
    cout << ans + B + C << endl;
  }
  else if (B >= A && B >= C) {
    int ans = B;
    for (int i = 0; i < K; i++) {
      ans *= 2;
    }
    cout << ans + A + C << endl;
  }
  else {
    int ans = C;
    for (int i = 0; i < K; i++) {
      ans *= 2;
    }
    cout << ans + B + A << endl;
  }
}

Measured memory_bytes: 256
s = input()
K = int(input())
k = []

for i in range(len(s)):
  if s[i] not in k:
    k.append(s[i])
  
if len(s) >= 2:
  for i in range(len(s)-1):
    if s[i] + s[i+1] not in k:
      k.append(s[i] + s[i+1])
    
if len(s) >= 3:
  for i in range(len(s)-2):
    if s[i] + s[i+1] + s[i+2] not in k:
      k.append(s[i] + s[i+1] + s[i+2])
    
if len(s) >= 4:
  for i in range(len(s)-3):
    if s[i] + s[i+1] + s[i+2] + s[i+3] not in k:
      k.append(s[i] + s[i+1] + s[i+2] + s[i+3])
    
if len(s) >= 5:
  for i in range(len(s)-4):
    if s[i] + s[i+1] + s[i+2] +s[i+3] + s[i+4] not in k:
      k.append(s[i] + s[i+1] + s[i+2] +s[i+3] + s[i+4])
    
new = sorted(k)

print(new[K-1])

Measured memory_bytes: 4072
#include <bits/stdc++.h>
using namespace std;
#define ll      long long
#define ld      long double
#define pii     pair<int ,int>
#define pld     pair<ld ,ld>
#define all(v)  v.begin(),v.end()
#define F       first
#define S       second
#define mod     1000000007
#define pb      push_back
#define MP      make_pair
#define mset(x) memset(x, 0, sizeof(x));
#define ios     ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define inf     10000000000000007
const int N=2004;
ll cnt[N],pre[N];
void run(){
    ll n,x,ans=0,i,j;
    cin>>n;
    for(i=1;i<=n;i++)
    {
        cin>>x;
        cnt[x]++;
    }
    for(i=1;i<=2000;i++)
        pre[i]=pre[i-1]+cnt[i];
    for(i=1;i<=1000;i++)
    {
        ans+=(cnt[i]*(cnt[i]-1)*(cnt[i]-2))/6;
        for(j=i+1;j<=1000;j++)
            ans+=(pre[i+j-1]-pre[j])*cnt[i]*cnt[j];

    }
   
    for(i=1;i<=1000;i++)
    {
        x=cnt[i]*(cnt[i]-1)/2;
        ans+=x*(pre[2*i-1]-pre[i]);
        ans+=x*pre[i-1];

    }

    cout<<ans;

}
 
 
void setup(){
    ios;
    //cout << setprecision(20);
    // #ifndef ONLINE_JUDGE
    // freopen("input", "r", stdin);
    // freopen("output", "w", stdout);
    // #endif
}
 
signed main(){
    setup();
    int tests = 1;
    //cin >> tests;
    for(int i = 1; i <= tests; i++) run();
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  string s;
  int n;
  cin>>s>>n;
  for (int i = 0; i < n; ++i)
  {
    string t;
    int a,b;
    cin>>t>>a>>b;
    if(t=="replace")
    {
      string u;
      cin>>u;
      for (int j = 0; j < u.size(); ++j)
      {
        s.at(a+j)=u.at(j);
      }
    }
    else if(t=="reverse")
    {
      string tmp=s;
      for (int j = 0; j < b-a+1; ++j)
      {
        s.at(a+j)=tmp.at(b-j);
      }
    }
    else
    {
      for (int j = 0; j < b-a+1; ++j)
      {
        cout<<s.at(a+j);
      }
      cout<<endl;
    }
  }
}


Measured memory_bytes: 3152
#pragma GCC optimize("O3")
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;

using ll = long long;
using P = pair<int, int>;
using T = tuple<int, int, int>;

template <class T> inline T chmax(T &a, const T b) {return a = (a < b) ? b : a;}
template <class T> inline T chmin(T &a, const T b) {return a = (a > b) ? b : a;}

constexpr int MOD = 1e9 + 7;
constexpr int inf = 1e9;
constexpr long long INF = 1e18;
constexpr double pi = acos(-1);
constexpr double EPS = 1e-10;

int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};


template<typename T>
struct Segtree {
    int n;
    T e;
    vector<T> dat;
    typedef function<T(T a, T b)> Func;
    Func f;
 
    Segtree(int n_input, Func f, T e_input):f(f), e(e_input){
        n = 1;
        while(n < n_input) n <<= 1;
        dat.resize(2*n-1, e);
    }
 
    void update(int k, T a){
        k += n - 1;
        dat[k] = a;
        while(k > 0){
            k = (k - 1)/2;
            dat[k] = f(dat[2*k+1], dat[2*k+2]);
        }
    }
 
    T between(int a, int b){
        return query(a, b+1, 0, 0, n);
    }
 
    T query(int a, int b, int k, int l, int r){
        if(r<=a || b<=l) return e;
        if(a<=l && r<=b) return dat[k];
        T vl = query(a, b, 2*k+1, l, (l+r)/2);
        T vr = query(a, b, 2*k+2, (l+r)/2, r);
        return f(vl, vr);
    }
};

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

    int n; cin>>n;
    string s; cin>>s;

    map<char, ll> s2num;
    ll num = 1;
    for(char ch='a'; ch<='z'; ch++){
        s2num[ch] = num;
        num *= 2;
    }

    vector<ll> tmp(n);
    for(int i=0; i<n; i++){
        char t = s[i];
        ll cur = s2num[t];
        tmp[i] = cur;
    }

    Segtree<int> stOR(n, [](ll a, ll b){ return a|b;}, 0);
    for(int i=0; i<n; i++) stOR.update(i, tmp[i]);

    /*
    for(int i=0; i<n; i++){
        cout << stOR.dat[i] << " ";
    }
    */

    int q; cin>>q;
    while(q--){
        int Q; cin>>Q;
        if(Q == 1){
            int i; cin>>i;
            char c; cin>>c;
            i--;
            int cur = tmp[i];
            stOR.update(i, -cur);
            int nxt = s2num[c];
            tmp[i] = nxt;
            stOR.update(i, nxt);
        }
        else{
            int l, r; cin>>l>>r;
            l--, r--;
            ll sum = stOR.between(l, r);
            int bcnt = __builtin_popcountll(sum);
            cout << bcnt << endl;
        }
    }

    return 0;
}

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

int main() {
	vector<vector<char>> data(3, vector<char>(3));
  for(int i=0;i<3;i++){
    for(int j=0;j<3;j++){
      cin >> data.at(i).at(j);
    }
  }
  
  cout << data.at(0).at(0) << data.at(1).at(1) << data.at(2).at(2) << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;
import java.util.Arrays;
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n=sc.nextInt();
		int m=sc.nextInt();
		int p=sc.nextInt();
		Edge[] edge=new Edge[m];
		for(int i=0; i<m; i++){
			int a=sc.nextInt()-1;
			int b =sc.nextInt()-1;
			int c =sc.nextInt()-p;
			edge[i]=new Edge(a,b,c);
		}
		long[] dist=new long[n];
		Arrays.fill(dist,Long.MIN_VALUE);
		dist[0]=0;
		boolean flag=true;
		int cnt=0;
		long ans=0;
		boolean ax=false;
		while(flag){
			flag=false;
			for(int i = 0; i<m; i++){
				if(dist[edge[i].from]!=Long.MIN_VALUE && dist[edge[i].to]<dist[edge[i].from]+edge[i].cost){
					flag=true;
					long k=dist[edge[i].from]+edge[i].cost;
					if(ax){
						k=Long.MAX_VALUE/10;
					}
					dist[edge[i].to]=k;
				}
			}
			if(cnt==n){
				ans=dist[n-1];
				ax=true;
			}
			if(cnt==2*n){
				if(ans<dist[n-1]){
					System.out.println(-1);
					return;
				}
				break;
			}
			cnt++;
		}
		if(dist[n-1]<0){
			dist[n-1]=0;
		}
		System.out.println(dist[n-1]);
	}
	static class Edge{
		int from;
		int to;
		long cost;
		public Edge(int from,int to,long cost){
			this.from=from;
			this.to=to;
			this.cost=cost;
		}
	}
}


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

const int N = 1e9+7;



void solve(){
  ll n;
  cin>>n;
  vector<ll>v(n);
  for(ll i=0;i<n;i++){
    cin>>v[i];
  }
  vector<ll>prefix(n, 0);
  prefix[n-1] = v[n-1];
  for(ll i=n-2; i>=0;i--){
    prefix[i] = prefix[i+1]+v[i];
    prefix[i] %= N;
  }
  ll ans = 0;
  for(ll i=0;i<n-1;i++){
    ans += (v[i]*prefix[i+1])%N;
    ans %= N;
  }
  cout<<ans;
}
int main(){
  // freopen("input.txt", "r",stdin);
  // freopen("output.txt", "w", stdout);
  ll t;
  // cin>>t;
  t = 1;
  while(t--){
    solve();
  }
}
























/*
  1 2 3 4 5 6 7 8

  6 7 8 1 2 3 4 5


*/


Measured memory_bytes: 6424
// #pragma GCC target("avx,avx2,fma")
// #pragma GCC optimization ("Ofast")
// #pragma GCC optimization ("unroll-loops")
#include <bits/stdc++.h>

using namespace std;
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
// template <typename T>
// using o_set = tree <T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
// #define sfind(i) find_by_order(i)
// #define ord(i) order_of_key(i)
typedef long long ll;
typedef pair<int , int> pii;
typedef pair<ll, ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;
using cd = complex<double>;
const double pi = acos(-1);
#define mod 1000000007
#define rep(i, a, b) for(ll i = a; i < b; i++)
#define repc(i, a, b, c) for (ll i = a; (c > 0 ? i < b : i > b) and c != 0; i += c)
#define vi vector<int>
#define vl vector<ll>
#define _max(vec) (*max_element(all(vec)))
#define _min(vec) (*min_element(all(vec)))
#define fi first
#define si second
#define pb push_back
#define all(name) name.begin(), name.end()
#define ral(name) name.rbegin(), name.rend()
#define fact(n) rep(i, 1, n+1)ft.pb((ft[i-1]*i)%mod)
#define mod_in(a) power(a, mod - 2)
#define ncr(n, r) (n>=r?((ft[n]*mod_in((ft[r]*ft[(n)-(r)])%mod))%mod):0LL)
#define deb(x) cerr << "[" << #x << " " << x << "]" << endl;
#define endl '\n'  //....????
#define int ll
vector<ll> ft(1, 1LL);


/*======================================================================*/
void solve(){
    int n, k, ans;
    cin >> n >> k;
    vi v(n);
    rep(i, 0, n)cin >> v[i], ans = max(ans, v[i]);
    sort(all(v));
    int l = 1, r = 1e9;
    while(l <= r){
        int mid = (l+r)/2;
        int req = 0;
        rep(i, 0, n){
            req += (v[i]/mid) - 1 + (v[i]%mid != 0);
        }
        if(req <= k)ans = mid, r = mid-1;
        else l = mid+1;
    }
    cout << ans;
}
signed main() {
	cin.sync_with_stdio(0); cin.tie(0);
	cin.exceptions(cin.failbit);
    int t = 1;
    //cin >> t;
    while(t--){
        solve();
    }
}

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

using namespace std;

#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)((x).size()))

typedef pair<int, int> PII;
typedef vector<int> VI;
typedef long long int64;
typedef unsigned int uint;
typedef unsigned long long uint64;

#define gi(x) ((x) = F())
#define gii(x, y) (gi(x), gi(y))
#define giii(x, y, z) (gii(x, y), gi(z))

int F()
{
	char ch;
	int x, a;
	while (ch = getchar(), (ch < '0' || ch > '9') && ch != '-');
	if (ch == '-') ch = getchar(), a = -1;
	else a = 1;
	x = ch - '0';
	while (ch = getchar(), ch >= '0' && ch <= '9')
		x = (x << 1) + (x << 3) + ch - '0';
	return a * x;
}

const int N = 1e5 + 10;

int n, l, t;

int x[N], w[N];

int main()
{
	giii(n, l, t);
	long long v = 0;
	for (int i = 1; i <= n; ++i) 
	{
		gii(x[i], w[i]);
		if (w[i] == 1)
		{
			x[i] += t;
			v += x[i] / l;
			x[i] %= l;
		}
		else
		{
			x[i] -= t;
			if (x[i] < 0)
			{
				v += (x[i] - (l - 1)) / l;
			}
			x[i] %= l;
			if (x[i] < 0) x[i] += l; 
		}
	}
	sort(x + 1, x + n + 1);
	v %= n;
	if (v < 0) v += n;
	for (int i = 1; i <= n; ++i)
	{
		int j = i + v;
		if (j > n) j -= n;
		printf("%d\n", x[j]);
	}
	return 0;
} 

Measured memory_bytes: 1920