akhauriyash/Code-Regression huggingface dataset:
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.NoSuchElementException;
class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        }else{
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }
    private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
    private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
    public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}
    public String next() {
        if (!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while(isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }
    public long nextLong() {
        if (!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while(true){
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            }else if(b == -1 || !isPrintableChar(b)){
                return minus ? -n : n;
            }else{
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
        return (int) nl;
    }
    public double nextDouble() { return Double.parseDouble(next());}
}
public class Main {
	static FastScanner stdIn=new FastScanner();
	static int N=stdIn.nextInt();
	static int M=stdIn.nextInt();
	static ArrayList<ArrayList<Integer>>G=new ArrayList<ArrayList<Integer>>();
	static boolean visited[]=new boolean[N];
	static int ans=0,num=0;
	public static void main(String[] args) {
		for(int i=0;i<N;i++){
			G.add(new ArrayList<Integer>());
		}
		for(int i=0;i<M;i++){
			int a=stdIn.nextInt()-1;
			int b=stdIn.nextInt()-1;
			ArrayList<Integer> c=new ArrayList<Integer>();
			c=G.get(a);c.add(b);G.set(a,c);
			c=G.get(b);c.add(a);G.set(b,c);
		}
		dfs(0);
		System.out.println(ans);
	}
	static void dfs(int now){
		visited[now]=true;
		num++;
		if(num==N)
			ans++;
		for(int i=0;i<G.get(now).size();i++){
			if(visited[G.get(now).get(i)]==false)
				dfs(G.get(now).get(i));
		}
		visited[now]=false;
		num--;
	}
}


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

#include <iostream>
#include <iomanip>
#include <sstream>
#include <fstream>
#include <stdint.h>
#include <string.h>

//#define _USE_MATH_DEFINES
//#include <math.h>

#include <vector>
#include <list>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <stack>
#include <deque>
#include <string>

#include <algorithm>
#include <functional>
#include <bitset>
#include <functional>
#include <chrono>
#include <random>
#define sqr(x) (x) * (x)

typedef unsigned int u32;
typedef int i32;
typedef unsigned long long int u64;
typedef long long int i64;
typedef uint16_t u16;
typedef int16_t i16;
typedef uint8_t u8;
typedef int8_t i8;

using namespace std;
using namespace std::chrono;

const i64 mod = 1000000007ll;
const i64 smod = 998244353ll;
const i64 inf = 1000000007; // 10000000000000007ll;

const double eps = 1e-8;

const i64 MAXN = 2'000'000 + 6;

i64 n, m;

i64 a[MAXN];

bool isp(string s) {
    string t = s;
    reverse(t.begin(), t.end());
    //cerr << s << " " << t << endl;
    return t == s;
}

int main(int argc, char* argv[]) {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cout.precision(15); cout.setf(ios::fixed);


    string s;
    cin >> s;

    bool R = isp(s) && isp(s.substr(0, s.size() / 2)) && isp(s.substr(s.size() / 2 + 1));
    if (R) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
using namespace std;
int main(){
  int n,a;
  vector<int>v(1,0);
  cin >> n;
  while(n--){
    cin >> a;
    v.push_back(a);
  }
  for(int j=1;j<v.size();j++){
    int key = v[j],i = j - 1;
    while(i > 0 && v[i] > key){
      v[i+1] = v[i];
      i--;
    }
    v[i+1] = key;
    for(int j=1;j<v.size();j++){
      cout << (j==1?"":" ") << v[j];
    }
    cout << endl;
  }
}



Measured memory_bytes: 3168
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

use std::cmp;

fn main() {
    input! {
        N: i64
    }
    let mut ans = usize::max_value();
    for i in 1..(((N as f64).sqrt() as i64) + 1){
        if N % i == 0 {
            ans = cmp::min(ans, (N / i).to_string().len());
        }
    }
    println!("{}", ans);
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
int main() {
  string N;
  cin >> N ;
  if ((N[0] == N[1] && N[1] == N[2]) || (N[1] == N[2] && N[2] == N[3])){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
	string s; cin >> s;
	long long ans = 0, qbc = 0;
	int isbk = 0;
	int len = s.size();
	vector<int> good(len, 0);
	for(int i = len - 2; i >= 0; i--){
		if(s[i] == 'B' && s[i + 1] == 'C') good[i] = good[i + 1] = 1;
		else if(s[i] == 'A') good[i] = 1;
	}
	for(int i = len - 2; i >= 0; i--){
		if(s[i] == 'B' && s[i+1] == 'C') qbc++;
		else if(s[i] == 'A') ans += qbc;
		else if(!good[i]) qbc = 0;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 1412
N, K = map(int, input().split())
p = list(map(int, input().split()))
ansmax = 0
ans = 0
for j in range(K):
  ans += (p[j]+1)/2
if(ansmax < ans):
  ansmax = ans
for i in range(N-K):
  ans =  ans - (p[i]+1)/2 + (p[i+K]+1)/2
  if(ansmax < ans):
    ansmax = ans
print(ansmax)

Measured memory_bytes: 25604
/**
 *    author: gxfireball       
**/
#include <bits/stdc++.h>
#define ll long long
#define endl '\n'
#define MOD 1000000007
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); 
using namespace std;

void solve(){
   ll n,k,sum=0;
   cin >> n >> k;
   for(ll i=k; i<=n+1; ++i){
	   sum += ((n-i+1)*i + 1);
	   sum %= MOD;
   }
   cout << sum << endl;
}

int main(){
    fastio;
    int t;
    t = 1;
    //cin>>t;
    while(t--){
    	solve();
    }
    return 0;
}


Measured memory_bytes: 3608
#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <string>
#include <numeric>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <queue>

#define rep(i,n) for(int i=0;i<n;i++)
#define dup(x,y) (((x)+(y)-1)/(y)) // dup * y >= x なる最小のdup.
using namespace std;
typedef long long ll;
using Graph = vector<vector<int>>;


int main() {
	int N, T;
	cin >> N >> T;
	int c, t;
	cin >> c >> t;
	rep(i, N-1) {
		int tmpc, tmpt;
		cin >> tmpc >> tmpt;
		if(tmpt<=T && tmpc<c) {
			t = tmpt;
			c = tmpc;
		}
	}

	if(t>T) cout << "TLE" << endl;
	else cout << c << endl;

	return 0;
}

Measured memory_bytes: 256
n, m = gets.to_s.split.map(&:to_i)
h = [0] + gets.to_s.split.map(&:to_i)
ans = [0] + [1] * n

m.times do
  a, b = gets.split.map(&:to_i)
  if h[a] < h[b]
    ans[a] = 0
  elsif h[a] > h[b]
    ans[b] = 0
  else
    ans[a] = 0
    ans[b] = 0
  end
end
puts ans.sum


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

using i64 = long long;

map<i64, int> psums;
i64 ant;
int n;

int main() {
#ifdef HOME
	freopen("agc23a.in", "r", stdin);
	freopen("agc23a.out", "w", stdout);
#endif
	ios::sync_with_stdio(false);
	cin.tie(0), cout.tie(0);
	i64 s;
	int t;

	cin >> n;

	s = 0;
	psums[0] = 1;
	for (int i = 0; i < n; ++i) {
		cin >> t;
		s+= t;
		ant+= psums[s];
		psums[s]+= 1; }

	cout << ant << endl;

	return 0; }


Measured memory_bytes: 12800
b=list(input())
N=len(b)
enki=["A","T","G","C"]
curmax=0
for i in range(N):
    for j in range(i,N):
        if all((k in enki) for k in b[i:j+1]):
            curmax=max(curmax,j-i+1)
print(curmax)

Measured memory_bytes: 3060
a=[int(i) for i in input().split()]

for i in range(len(a)):
    for j in range(len(a)):
        if a[i]<a[j]:
            a[i], a[j]=a[j], a[i]

s=0
for i in range(1, len(a)):
    s+=abs(a[i-1]-a[i])

print(s)


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

using ll = long long;
using ull = unsigned long long;

int main(int argc, char const *argv[]) {
    double n,k;
    std::cin >> n >> k;
    // 2^mother2 >= k
    int mother2 = int(log2(k));
    if (log2(k) != double(int(log2(k)))) {
        mother2++;
    }

    double children = 0.0;
    for (int i = 1; i <= min(n, k); i++) {
        int child = int(log2(k/i));
        if (log2(k/i) != double(int(log2(k/i)))) {
            child++;
        }

        children += pow(2,mother2-child);
    }

    for (int i = min(n, k)+1; i <= n; i++) {
        children += pow(2,mother2);
    }

    double ans = children / pow(2,mother2) / n;

    std::cout << std::setprecision(12) << ans << '\n';

    return 0;
}



Measured memory_bytes: 256
from collections import defaultdict
import sys
input = sys.stdin.readline


N = int(input())
# 例外処理
if (N == 1):
    print("First")
    quit()

tree = defaultdict(set)
tree_main = defaultdict(set)
for i in range(N-1):
    a, b = tuple(map(int, input().split()))
    tree[a].add(b)
    tree[b].add(a)
    tree_main[a].add(b)
    tree_main[b].add(a)

def longest_path(tree, from_node=1):
    cnt = 1

    nearest_nodes = list(tree[from_node])
    while len(nearest_nodes) > 0:
        for one_step_node in nearest_nodes:
            for two_step_node in tree[one_step_node]:
                if two_step_node != from_node:
                    tree[two_step_node].remove(one_step_node)
                    tree[two_step_node].add(from_node)
                    tree[from_node].add(two_step_node)
            tree[from_node].remove(one_step_node)
        cnt += 1
        nearest_nodes = list(tree[from_node])

    return one_step_node, cnt


far, _ = longest_path(tree)
_, n = longest_path(tree_main, far)
print("Second" if n % 3 == 2 else "First")


Measured memory_bytes: 235472
#include <iostream>
#include <queue>
#include <string>
#include <algorithm>

using namespace std;

void a(){
    int A, P; cin >> A >> P;

    int p = A*3 + P;
    cout << p/2;

}

void b(){
    int N; cin >> N;
    vector<pair<string,int>> vec(N);
    for(int i = 0; i < N; i++){
        string s; cin >> s;
        int p; cin >> p;

        vec[i] = make_pair(s,-p);
    }
    vector<int> idx(N);
    for(int i = 0; i < N; i++){
        idx[i] = i;
    }

    sort(idx.begin(),
         idx.end(),
         [&vec](int idx1, int idx2){return (vec[idx1] < vec[idx2]);}
    );


    for(int i = 0; i < N; i++){

        cout << idx[i] + 1 << endl;
    }

}

bool is_mem(int bit, int i){

    return bit & (1 <<i);
}

bool is_lamp_on(int bit, const vector<int> &connected, int p){
    int on_switch = 0;
    for(int n: connected){
        if (is_mem(bit, n)) on_switch++;
    }

    return (on_switch%2 == p);

}
void c(){
    int N, M; cin >> N >> M;

    vector<vector<int>> connect(M);
    for(int i = 0; i < M; i++){

        int k; cin >> k;
        for(int j = 0;j<k; j++ ){
            int s_ij; cin >> s_ij; s_ij--;
            connect[i].push_back(s_ij);
        }
    }
    vector<int> p_vec(M);
    for(int i = 0; i < M; i++){
        cin >> p_vec[i];
    }

    int count = 0;
    for(int bit = 0; bit < (1<<N); ++bit){
        bool all_on = true;
        for(int m = 0; m < M; m++){// 全てonになるか？
            if (!is_lamp_on(bit, connect[m], p_vec[m])) {
                all_on = false;
                break;
            }
        }
        if (all_on) count++;
    }

    cout << count;

}
int main(){
    c();
}

Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <stdlib.h>

using namespace std;

int main() {
	int n;
	int *k;

	while (1) {
		cin >> n;
		if (n == 0) {
			break;
		}
		int p = 0;
		int r = 0;
		int q = 0;
		k = (int *)malloc(sizeof(int) * 110000);
		if (k == NULL) {
			exit(0);
		}
		k[0] = 1;
		for (int i = 1; i < 110000; i++) {
			k[i] = 0;
		}
		for (int i = 1; i * i < 110000; i++) {
			if (k[i] == 0) {
				for (int j = 2; j <= 110000/(i+1); j++) {
					k[(i+1)*j-1] = 1;
				}
			}
		}
		while (r < n) {
			if (k[q] == 0) {
				p += (q+1);
				r++;
			}
			q++;
		}
		cout << p << endl;
	}

	return 0;
}

Measured memory_bytes: 20616
#include "bits/stdc++.h"
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define int long long
#define MRE assert(0);
const int inf = 1e17;
const int mod = 998244353;
typedef pair<int, int> P;
typedef pair<int, P> PP;
int a[200006];
signed main() {
	int n; cin >> n;
	rep(i, n)cin >> a[i];
	map<int, int>M;
	rep(i, n)M[a[i]]++;
	int cnt = 0;
	for (auto itr = M.begin(); itr != M.end(); itr++) {
		int x = itr->second;
		cnt += x*(x - 1) / 2;
	}
	rep(i, n) {
		int x = M[a[i]] - 1;
		cout << cnt - x << endl;
	}
}

Measured memory_bytes: 12160
import java.util.Scanner;

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

		long sum = 0;
		for (int i = 1; i <= n; i++) {
			if (i % 3 != 0 && i % 5 != 0) {
				sum += i;
			}
		}

		System.out.println(sum);


		sc.close();
	}
}

Measured memory_bytes: 27240
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define MAX 1000000
#define MOD 1000000007

int main(){
  int N;
  cin>>N;
  vector<ll> A(N);
  ll sum=0;
  for(int i=0;i<N;i++){
    cin>>A.at(i);
    sum+=A.at(i);
  }

  vector<ll> semi_sum(N);
  ll x=0;
  for(int i=1;i<N;i+=2){
    x+=2*A.at(i);
  }
  semi_sum.at(0)=x;
  for(int i=1;i<N;i++){
    x+=2*A.at((2*i-2)%N)-2*A.at((2*i-1)%N);
    semi_sum.at((2*i)%N)=x;
  }
  for(int i=0;i<N;i++){
    cout<<sum-semi_sum.at(i)<<" ";
  }
  cout<<endl;
}


Measured memory_bytes: 2944
#include <stdio.h>

int main(void)
{
	double input;
	double d_num;
	int i_num;
	int i;
	
	while (1){
		scanf("%lf", &input);
		if (input < 0.0) break;
		
		i_num = (int)input;
		d_num = input - (double)i_num;
		
		if (i_num < 256){
			for (i = 0; i < 4; i++){
				int tmp;
				
				d_num *= 2.0;
				tmp = (int)d_num;
				
				if (d_num >= 1.0){
					d_num -= (double)tmp;
				}
			}
			if (d_num != 0.0){
				puts("NA");
				continue;
			}
			
			for (i = 7; i >= 0; i--){
				printf("%d", (i_num >> i) & 1);
			}
			printf(".");
			
			d_num = input - i_num;
			for (i = 0; i < 4; i++){
				int tmp;
				
				d_num *= 2.0;
				tmp = (int)d_num;
				
				printf("%d", tmp);
				
				if (tmp > 0){
					d_num -= (double)tmp;
				}
			}
			puts("");
		}
		
		else puts("NA");
	}
	
	return (0);
}

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

namespace TYC
{
	typedef long long ll;
	const int N = 1e5 + 5;

	int n, m, A[N], B[N], C[N], Fa[N], P[N], Vis[N];
	ll F[N], Sum[N];
	vector<int> E[N], T[N];

	bool cmp(const int a, const int b) { return C[a] < C[b]; }

	int find(const int a) { return a == Fa[a] ? a : Fa[a] = find(Fa[a]); }

	void dfs(const int u)
	{
		Sum[u] = B[u];
		for (int v : T[u])
		{
			dfs(v);
			Sum[u] += Sum[v];
		}
		if (!T[u].size())
			F[u] = C[u] + B[u];
		else 
		{
			F[u] = LLONG_MAX;
			for (int v : T[u])
				F[u] = min(F[u], max(F[v], (ll)C[u]) + Sum[u] - Sum[v]); 
		}
	}

	void work()
	{
		scanf("%d%d", &n, &m);
		for (int i = 1; i <= n; i++)
		{
			scanf("%d%d", &A[i], &B[i]);
			C[i] = max(A[i] - B[i], 0);
			P[i] = Fa[i] = i;
		}
		for (int i = 1, u, v; i <= m; i++)
		{
			scanf("%d%d", &u, &v);
			E[u].push_back(v);
			E[v].push_back(u);
		}
		sort(P + 1, P + 1 + n, cmp);
		for (int i = 1; i <= n; i++)
		{
			int u = P[i], f;
			Vis[u] = 1;
			for (int v : E[u])
				if (Vis[v] && (f = find(v))	!= u)
				{
					Fa[f] = u;
					T[u].push_back(f);
				}
		}
		dfs(P[n]);
		printf("%lld\n", F[P[n]]);
	}
}

int main()
{
	TYC::work();
	return 0;
}

Measured memory_bytes: 18812
import sys
from collections import Counter

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline

in_n = lambda: int(readline())
in_nn = lambda: map(int, readline().split())
in_nl = lambda: list(map(int, readline().split()))
in_na = lambda: map(int, read().split())
in_s = lambda: readline().rstrip().decode('utf-8')


def main():
    N = in_n()
    A = in_nl()
    count = Counter(A)
    nums = list(count.values())

    for i in range(len(nums)):
        if nums[i] >= 3:
            if nums[i] % 2 == 0:
                nums[i] = 2
            else:
                nums[i] = 1

    d = Counter(nums)

    n1, n2 = d[1], d[2]
    ans = n1
    if n2 % 2 == 0:
        ans += n2
    else:
        ans += n2 - 1
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 22340
#include <bits/stdc++.h>
#define FI first
#define SE second
#define VE vector<int>
#define PB push_back
#define PA pair<int,int>
#define MA make_pair
#define ll long long
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ROF(i,a,b) for(int i=b-1;i>=a;i--)
#define YES(i) cout<<(i?"YES":"NO")<<endl
#define Yes(i) cout<<(i?"Yes":"No")<<endl
#define POS(i) cout<<(i?"POSSIBLE":"IMPOSSIBLE")<<endl
#define Pos(i) cout<<(i?"Possible":"Impossible")<<endl
#define co(i) cout<<i<<endl
#define fcout cout<<fixed<<setprecision(10)
#define uni(i) i.erase(unique(i.begin(), i.end()), i.end());
using namespace std;

const int INF=1e9+7;
const int MOD=1e9+7;

int main(){
	string s; cin>>s;
	int w; cin>>w;
	FOR(i,0,s.size()){
		if(i%w==0) cout<<s[i];
	}
}

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

int main(){
    int n,k;
    cin>>n>>k;
    ll ans=0;
    ll a;
    if(k%2==0){
        a=n/(k/2)-n/k;
        ans+=a*a*a;
        a=n/k;
        ans+=a*a*a;
    }
    else{
        a=n/k;
        ans+=a*a*a;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.*;
import java.io.*;
 
class Main{
  public static void main(String[]args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    long result = 1;
    boolean flag = true;
    long num = 1000000000000000000l;
    long[] arr = new long[n];
    
    for(int i = 0; i < n; i++) {
        arr[i] = sc.nextLong();
        if (arr[i] == 0) {
            System.out.println(0);
            System.exit(0);
        }
    }
    Arrays.sort(arr);
    for(int i = 0; i < n; i++) {
      	if(flag) result = result*arr[i];
      	if(result > num || result < 1) flag = false;
    }
    
    if(flag) System.out.println(result);
    else System.out.println(-1);
  }
}

Measured memory_bytes: 61708
#include <bits/stdc++.h>
using namespace std;
const int N=1e5+5;
char s[N];
bool vis[N];
int R,S,P;
int cal(char c) {
	if(c=='r') return P;
	if(c=='s') return R;
	return S;
}
int main() {
	int n,k;
	scanf("%d%d%d%d%d",&n,&k,&R,&S,&P);
	scanf("%s",s+1);
	int ans=0;
	for(int i=1;i<=n;i++) {
		if(i>=k&&s[i]==s[i-k]) {
			if(!vis[i-k]) ans+=cal(s[i]),vis[i]=true;
		}
		else ans+=cal(s[i]),vis[i]=true;
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define X first
#define Y second
#define PB push_back
#define ll long long
#define pii pair<ll,ll>
#define MEM(x,y) memset(x,y,sizeof(x))
#define bug(x) cout<<"debug "#x" is "<<x<<endl;
#define FIO ios::sync_with_stdio(false);
#define ALL(x) x.begin(),x.end()
#define LOG 20
#define lson(x) ((x)<<1)
#define rson(x) ((x)<<1|1)
using namespace std;
#define vi vector<int>
const int maxn = 2e5+7;
const ll mod=998244353;
ll a[maxn],b[maxn],c[maxn];
int main(){
    FIO
    ll n;
    cin>>n;
    cout<<n/500*1000+(n%500)/5*5<<endl;
	return 0;
}


Measured memory_bytes: 256
#![allow(unused_imports)]
#![allow(unused_macros)]
use std::cmp::{max, min};
use std::collections::*;
use std::io::{stdin, Read};

#[allow(unused_macros)]
macro_rules! parse {
    ($it: ident ) => {};
    ($it: ident, ) => {};
    ($it: ident, $var:ident : $t:tt $($r:tt)*) => {
        let $var = parse_val!($it, $t);
        parse!($it $($r)*);
    };
    ($it: ident, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = parse_val!($it, $t);
        parse!($it $($r)*);
    };
    ($it: ident, $var:ident $($r:tt)*) => {
        let $var = parse_val!($it, usize);
        parse!($it $($r)*);
    };
}

#[allow(unused_macros)]
macro_rules! parse_val {
    ($it: ident, [$t:tt; $len:expr]) => {
        (0..$len).map(|_| parse_val!($it, $t)).collect::<Vec<_>>();
    };
    ($it: ident, ($($t: tt),*)) => {
        ($(parse_val!($it, $t)),*)
    };
    ($it: ident, u1) => {
        $it.next().unwrap().parse::<usize>().unwrap() -1
    };
    ($it: ident, $t: ty) => {
        $it.next().unwrap().parse::<$t>().unwrap()
    };
}

#[cfg(debug_assertions)]
macro_rules! debug {
    ($( $args:expr ),*) => { eprintln!( $( $args ),* ); }
}

#[cfg(not(debug_assertions))]
macro_rules! debug {
    ($( $args:expr ),*) => {
        ()
    };
}

fn solve(s: &str) {
    let mut it = s.split_whitespace();
    parse!(it, x: i64);
    if (x >= 30) {
        println!("{}", "Yes");
    } else {
        println!("{}", "No");
    }
}

fn main() {
    let mut s = String::new();
    stdin().read_to_string(&mut s).unwrap();
    solve(&s);
}

#[cfg(test)]
mod tests {
    use super::*;
    #[test]
    fn test_input() {
        let s = "
        ";
        solve(s);
    }
}


Measured memory_bytes: 2132
use std::io;

fn read<T: std::str::FromStr>() -> Vec<T>{
    let mut te = String::new();
    io::stdin().read_line(&mut te).unwrap();
    te.trim().split_whitespace().map(|x| x.parse().ok().unwrap()).collect()
}

fn main() {
    let nums : Vec<i64> = read();
    let small = if nums[2] < nums[3] { nums[2] } else { nums[3] };
    let large = if nums[2] > nums[3] { nums[2] } else { nums[3] };
    let uc = small * large / p(small, large);
    let r = nums[1] - nums[0];
    let smalltotal = (nums[1] / small) - ((nums[0] - 1) / small); 
    let largetotal = (nums[1] / large) - ((nums[0] - 1) / large);
    let uctotal = (nums[1] / uc) - ((nums[0] - 1)/ uc);

    println!("{}", r - (smalltotal + largetotal - uctotal) + 1);
}


fn p(a: i64, b: i64) -> i64{
    let mut max : i64 = b;
    let mut min : i64 = a;
    let mut hold : i64 = 0;
    while max % min != 0 {
        hold = min;
        min = max % hold;
        max = hold;
    }
    min
}

Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-8;
const ll mod=1e9+7;
const int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};

string s;

int main(){
	cin>>s;
	int t=0;
	for(auto i:s) if(i=='x') t++;
	cout<<(t<8?"YES":"NO")<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n-1; i >= 0; i--)
#define ALL(x) x.begin(), x.end()
using ll = long long;
using pii = pair<int, int>;
const int mod = 1e9+7;
const int INF = 1e9;
const int MAX = 1e6;

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;
}

int main() {
    // input
    int n;
    cin >> n;
    // solve
    map<string, int> dic;
    int max_c = 0;
    set<string> ans;
    rep(i, n) {
        string s;
        cin >> s;
        dic[s]++;
        if (chmax(max_c, dic[s])) {
            ans.clear();
            ans.insert(s);
        } else if (dic[s] == max_c) {
            ans.insert(s);
        }
    }
    // output
    for (string s : ans) {
        cout << s << endl;
    }
}

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

using namespace std;

#define debug(n) cerr << #n << ':' << n << endl;
#define dline    cerr << __LINE__ << endl;

using ll = long long;
using ull = unsigned long long;
template<class T, class U> using P = pair<T,U>;
template<class T> using Heap = priority_queue<T>;
template<class T> using heaP = priority_queue<T,vector<T>,greater<T>>;
template<class T,class U> using umap = unordered_map<T,U>;
template<class T> using uset = unordered_set<T>;

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

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

template<class T, size_t N, class U>
void Fill(T (&a)[N], const U&v){
    fill((U*)a,(U*)(a+N),v);
}

template<class T,class U>
istream& operator >> (istream&is, P<T,U>&p){
  is >> p.first >> p.second;
  return is;
}

template<class T>
istream& operator >> (istream&is, vector<T>&v){
  for(auto&e:v){
    is >> e;
  }
  return is;
}

int main(){
  ll n,c; cin >> n >> c;
  vector<ll> dist(n),kcal(n);
  for(int i = 0; i < n; ++i)cin >> dist[i] >> kcal[i];
  vector<ll> fmax(n),bmax(n);
  {
    ll tmp = 0;
    ll calsum = 0;
    for(int i = 0; i < n; ++i){
      calsum += kcal[i];
      tmp = max(tmp,calsum - dist[i]);
      fmax[i] = tmp;
    }
    tmp = 0;
    calsum = 0;
    for(int i = 0; i < n; ++i){
      calsum += kcal[n-i-1];
      tmp = max(tmp,calsum - (c-dist[n-i-1]));
      bmax[n-i-1] = tmp;
    }
  }
  // for(int i = 0; i < n; ++i){
  //   debug(i);
  //   debug(fmax[i]);
  //   debug(bmax[i]);
  // }
  ll ans = 0;
  ll calsum = 0;
  for(int i = 0; i < n; ++i){    
    calsum += kcal[i];
    ans = max({ans,
	       calsum - dist[i],
	       (i<n-1?calsum - dist[i]*2 + bmax[i+1]:0)   });    
  }
  calsum = 0;
  for(int i = 0; i < n; ++i){
    calsum += kcal[n-i-1];
    ans = max({ans,
	       calsum - (c-dist[n-i-1]),
	       (i<n-1?calsum - (c-dist[n-i-1])*2 + fmax[n-i-2]:0)  });
  }
  cout << ans << endl;
}


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

using namespace std;

#define debug(n) cerr << #n << ':' << n << endl;
#define dline    cerr << __LINE__ << endl;

using ll = long long;
template<class T, class U> using P = pair<T,U>;
template<class T> using Heap = priority_queue<T>;
template<class T> using heaP = priority_queue<T,vector<T>,greater<T>>;
template<class T,class U> using umap = unordered_map<T,U>;
template<class T> using uset = unordered_set<T>;

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

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

template<class T, size_t N, class U>
void Fill(T (&a)[N], const U&v){
    fill((U*)a,(U*)(a+N),v);
}

template<class T>
istream& operator >> (istream&is, vector<T>&v){
  for(auto&e:v)is >> e;
  return is;
}

int main(){
  string s; cin >> s;
  for(int i = 0; i < (int)s.size(); ++i){
    if(s[i] == '?')s[i] = 'D';
  }
  cout << s << endl;
  return 0;
}


Measured memory_bytes: 3760
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String {
            bytes
                .by_ref()
                .map(|r| r.unwrap() as char)
                .skip_while(|c| c.is_whitespace())
                .take_while(|c| !c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input!{
        n: usize,
        v: [usize; n]
    }
    let mut tab: Vec<Vec<usize>> = vec![vec![usize::max_value(); n]; n];
    let mut ps: Vec<usize> = v.iter().clone().scan(0, |ac, x| {*ac += *x; Some(*ac)}).collect();
    ps.insert(0, 0);
    for i in 0..n {
        tab[i][i] = 0;
    }
    for d in 1..n {
        for i in 0..n - d {
            tab[i][i + d] = ps[i + d + 1] - ps[i] + (i..i + d).map(|x| tab[i][x] + tab[x + 1][i + d]).min().unwrap();
        }
    }
    println!("{}", tab[0][n - 1]);
}


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

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	string s;cin >> s;
	int cntg=0,cntp=0;
	int p=s.size()/2;
	rep(i,s.size()){
		if(s.at(i)=='g') cntg++;
		else cntp++;
	}
	cout << p-cntp << endl;
}

Measured memory_bytes: 512
# pragma GCC optimize("O3")
# include <bits/stdc++.h>
# define maxn 100005
# define ll long long
# define clock (clock() * 1000.0 / CLOCKS_PER_SEC)
# define rc(s) return cout << s,0
# define _ ios_base::sync_with_stdio(false);cin.tie(0);cerr.tie(0);cout.tie(0);
# define db(x) cerr << #x << " = " << x << '\n'
# define pb push_back
# define mp make_pair
# define sz(x) (int)((x).size())
# define int ll
using namespace std;

int n,m,k;
vector<int>vec;
int x;
int sum;
int a[1000][1000];

int32_t main(){_
    //freopen("input","r",stdin);
	cin >> n >> m;
	cin >> k;
	vec.pb(0);
	for(int i = 1;i <= k;i++)
	{
		cin >> x;
		sum += x;
		vec.pb(sum);
	}
	for(int i = 1;i <= n;i++)
	{
		for(int j = 1;j <= m;j++)
		{
			if(i & 1) a[i][j] = (i - 1) * m + j;
			else a[i][j] = (i - 1) * m + m - j + 1;
		}
	}
	for(int i = 1;i <= n;i++)
	{
		for(int j = 1;j <= m;j++)
		{
			cout << lower_bound(vec.begin(),vec.end(),a[i][j]) - vec.begin() << ' ';
		}
		cout << '\n';
	}
}


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

int main() {
  string S;
  cin >> S;

  bool g = true, k = true;

  for (int i = 0; i < S.size(); i++) {
    if (i % 2 != 0) {
      if (S.at(i) == 'R') {
        g = false;
        break;
      }
    } else {
      if (S.at(i) == 'L') {
        k = false;
        break;
      }
    }
  }
  if (g && k) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
#include <stdio.h>
int main(void){
	int a,b,c;
	scanf("%d%d%d",&a,&b,&c);
	if((a==7 && b==5 && c==5)||(a==5 && b==7 && c==5)||(a==5 && b==5 && c==7))printf("YES");
	else printf("NO");
	
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <numeric>
#include <iomanip>
#include <tuple>

using namespace std;

int main() {
    int n,m;
    cin>>n>>m;
    vector<int> a(m),b(m);
    vector<pair<int,int>> p(m);
    for(int i=0;i<m;i++){
        cin>>a[i]>>b[i];
        a[i]--;b[i]--;
        p[i]=make_pair(b[i],a[i]);
    }
    sort(p.begin(),p.end());
    int ans=1;
    int l=p[0].second;
    int r=p[0].first;
    for(int i=1;i<m;i++){
        if(r<=p[i].second){
            ans++;
            l=p[i].second;
            r=p[i].first;
        }
    }
    cout<<ans<<endl;
}

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

typedef pair <int, int> ii;

int T;
int n;
int k[200005];
ii lr[200005];
vector <int> lrm, lrl;
set <int> mset;
set <int, greater <int> > lset;
long long ans;

bool mcomp(int l, int r) {
	return (lr[l].first - lr[l].second) > (lr[r].first - lr[r].second);
}

bool lcomp(int l, int r) {
	return (lr[l].first - lr[l].second) < (lr[r].first - lr[r].second);
}

int main() {
	scanf("%d", &T);
	while (T--) {
		scanf("%d", &n);
		ans = 0;
		lrm.clear();
		lrl.clear();
		mset.clear();
		lset.clear();
		for (int i = 0; i < n; i++) {
			int l, r; scanf("%d%d%d", &k[i], &l, &r);
			lr[i] = ii(l, r);
			if (l >= r) lrm.push_back(i);
			else lrl.push_back(i);
		}
		sort(lrm.begin(), lrm.end(), mcomp);
		sort(lrl.begin(), lrl.end(), lcomp);
		for (int i = 1; i <= n; i++) {
			mset.insert(i);
			lset.insert(i);
		}
		for (int i : lrm) {
			auto p = mset.upper_bound(k[i]);
			if (p == mset.begin()) {
				ans += lr[i].second;
			} else {
				ans += lr[i].first;
				mset.erase(--p);
			}
		}
		for (int i : lrl) {
			auto p = lset.lower_bound(k[i]);
			if (p == lset.begin()) {
				ans += lr[i].first;
			} else {
				ans += lr[i].second;
				lset.erase(--p);
			}
		}
		printf("%lld\n", ans);
	}
	return 0;
}


Measured memory_bytes: 25152
#include<bits/stdc++.h>
#include <stdio.h>
using namespace std;
#define M1 (ll)1000000007
#define M2 (ll)998244353
#define Pi 3.141592653
#define exp 2.71828
#define ll long long
#define ull unsigned long long
#define pi pair<int,int>
#define pl pair<ll,ll> 
#define vi vector<int>
#define vl vector<ll>
#define di deque<int>
#define dl deque<ll>
#define dii deque<pi>
#define dll deque<pl>
#define vvi vector<vi>
#define vvl vector<vl>
#define vii vector<pi>
#define vll vector<pl>
#define pb push_back
#define pp pop_back
#define pf push_front
#define pt pop_front
#define mp make_pair
#define in insert
#define er erase
#define ff first
#define ss second
#define ub upper_bound
#define lb lower_bound
#define rp(i,a,b) for(int i=a;i<b;i++)
#define rpt(i,a,b,t) for(int i=a;i<b&&t<1;i++)
#define rep(i,n) for(int i = 0 ; i<n ; i++)
#define rept(i,n,t) for(int i = 0 ; i<n&&t<1 ; i++)
#define repr(i,n) for(int i = n-1 ; i>=0 ; i--)
#define reprt(i,n,t) for(int i=n-1;i>=0&&t<1;i--)
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); 
#define SORT(v) sort(v.begin(),v.end())
using namespace std;
bool cmp(pair<int,int> i,pair<int,int> j){
    return i.first<j.first;
}
int main() {
    fast
    string s,t;
    cin>>s>>t;
    int n = s.length();
    int m = t.length();
    int lcs[n+1][m+1];
    for(int i=0;i<n+1;++i) for(int j=0;j<m+1;++j) lcs[i][j]=0;
    for(int i=1;i<n+1;++i){
        for(int j=1;j<m+1;++j){
            if(s[i-1]==t[j-1]) lcs[i][j] = lcs[i-1][j-1]+1;
            else lcs[i][j] = max(lcs[i-1][j],lcs[i][j-1]);
        }
    }
    string result = "";
    int xp=n,yp=m;
    while(result.length()<lcs[n][m]){
        if(s[xp-1]==t[yp-1]) result=s[xp-1]+result,--xp,--yp;
        else{
            if(lcs[xp-1][yp]==lcs[xp][yp]) --xp;
            else --yp;
        }
    }
    cout<<result;
}


Measured memory_bytes: 38872
#include <bits/stdc++.h>
using namespace std;
typedef long long lli;
typedef long double lld;
#define mod 1000000007
#define mod2 998244353
#define fori(n) for (int i = 0; i < n; i++)
#define forj(n) for (int j = 0; j < n; j++)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define fast ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define endl "\n"
#define sortvec(a) sort(a.begin(), a.end())
#define watch(x) cerr << "\n" << (#x) << " is " << (x) << endl
#define cerr if(true)cerr
void print(){cout<<endl;}
template<typename T,typename... Args>
void print(T a, Args... args) {cout<<a<<" ";print(args...);}
lli llipowerp(lli x, lli y, lli p=LLONG_MAX)
{
    lli res = 1;
    x = x % p;
    while (y > 0)
    {
        if (y & 1) res = (res * x) % p;
        y = y >> 1;
        x = (x * x) % p;
    }
    return res;
}
lli binarySearch(vector<int> arr, int l, int r, int x)
{
    if (r >= l)
    {
        lli mid = l + (r - l) / 2;
        if (arr[mid] == x)
            return mid;
        if (arr[mid] > x)
            return binarySearch(arr, l, mid - 1, x);
        return binarySearch(arr, mid + 1, r, x);
    }
    return -1;
}
template <typename T>
inline void printvec(vector<T> inp){
    for(auto it:inp) cout<<it<<" ";
    cout << endl;
}
//---------------------------------------------------------------------------------
vector<int> h;
int k;
int dp[(int)1e5+5];
int fill(int n){
    if(dp[n]!=-1) return dp[n];
    if(n<=1) return 0;
    if(n==2) return abs(h[2]-h[1]);
    int minv=INT32_MAX;
    for(int i=1;i<=min(k,n-1);i++){
        minv=min(minv,fill(n-i)+abs(h[n]-h[n-i]));
    }
    dp[n]=minv;
    return dp[n];
}
int main(){
    int n;
    cin>>n>>k;
    h.resize(n+1);
    fori(n) cin>>h[i+1];
    memset(dp,-1,sizeof(dp));
    cout<<fill(n)<<endl;

}


Measured memory_bytes: 8832
#include <bits/stdc++.h>
#define rep(i,n) for (ll i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
const ll INF=1e18;




int main() {
  ll n;
  cin >> n;
  vector<ll>v(n);
  rep(i,n)cin>>v[i];
  ll ans=-INF;
  for(ll c=1;c<n;c++){
    ll l=0;ll r=n-1;
    ll now=0;
    if((n-1)%c==0){
      while(l<r){
        now+=v[l]+v[r];
        ans=max(ans,now);
        l+=c;
        r-=c;
      }
    }
    else{
      now=0;
      while(r>c){
        now+=v[l]+v[r];
        ans=max(ans,now);
        l+=c;
        r-=c;
      }

    }

  }
  cout<<ans;
}


Measured memory_bytes: 4036
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<utility>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<functional>
#include<math.h>
using namespace std;
#define N (1000000000+7)
#define M (998244353)
#define INF 1e16
typedef long long ll;
typedef pair<ll,ll> P;

bool cmp(const pair<ll,ll> &a,const pair<ll,ll> &b) {
	if(a.second!=b.second)return a.second<b.second;
	else return a.first>b.first;
}


int main(void){
    ll n;
    cin>>n;
    vector<P>p(n);
    for(ll i=0;i<n;i++)cin>>p[i].first>>p[i].second;
    sort(p.begin(),p.end(),cmp);
    //cout<<endl;
    ll now = 0;
    for(ll i=0;i<n;i++){
        now+=p[i].first;
        if(now>p[i].second){
            cout<<"No"<<endl;
            return 0;
        }
    }
    cout<<"Yes"<<endl;
    return 0;
}

Measured memory_bytes: 3456
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
typedef int64_t Int;
typedef pair<Int,Int> p;


int main(){
    int N; cin >> N;
    vector<Int> A(N), B(N);
    rep(i,N){
        cin >> A[i];
        B[i] = A[i]-i;
    }

    map<Int,int> cnt;
    rep1(i,N-1){
        cnt[B[i]]++;
    }
    
    Int ans = 0;
    rep(i,N) ans += cnt[-A[i]-i];
    cout << ans << endl;
}


Measured memory_bytes: 29040
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {

		Scanner s = new Scanner(System.in);

		while (true) {
			int n = s.nextInt();

			if (n == 0)
				break;

			int[] a = new int[n];
			int max = 0;
			int min = 0;
			int sum = 0;
			int ave = 0;

			for (int t = 0; t < n; t++) {
				a[t] = s.nextInt();
			}

			max = a[0];
			min = a[0];

			for (int i = 0; i < n; i++) {
				if (max <= a[i])
					max = a[i];

				if (min >= a[i])
					min = a[i];

				sum += a[i];
			}

			sum = sum - max - min;
			ave = sum / (n - 2);

			System.out.println(ave);
		}
	}
}

Measured memory_bytes: 20940
#include<algorithm>
#include<array>
#include<cmath>
#include<iostream>
#include<iomanip>
#include<iso646.h>
#include<queue>
#include<stack>
#include<string>
#include<vector>

using std::cin;
using std::cout;
using std::endl;
using std::string;
using std::vector;

#define FOR(counter,initial_value,condition) for(int counter = initial_value; counter < condition;counter++)

int digitSum(int n,int digit=8) {
	// digit > 2
	int x = 1;
	FOR(i,0,digit){
		x *= 10;
	}
	int sum = 0;
	FOR(i, 0, digit) {
		sum += n / x;
		n %= x;
		x /= 10;
	}
	sum += n;
	return sum;
}


int main()
{
	int n, m;
	vector<int> A(50);
	cin >> n >> m;
	A.resize(n);
	fill(A.begin(), A.end(), 0);
	int tmp1,tmp2;
	FOR(i, 0, m) {
		cin >> tmp1 >> tmp2;
		A[tmp1 - 1]++;
		A[tmp2 - 1]++;
	}
	FOR(i, 0, n) {
		cout << A[i] << endl;
	}
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.LinkedList;
import java.util.Queue;

public class Main {
  private final static class Process {
    public String name = null;
    public int processTime = 0;

    public Process(String name, int processTime) {
        this.name = name;
        this.processTime = processTime;
    }
}
    public static void main(String args[]) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] firstRow = br.readLine().split("\\s");
        int elementNum = Integer.parseInt(firstRow[0]);
        int quantum = Integer.parseInt(firstRow[1]);
        Queue<Process> que = new LinkedList<Process>();
        for (int i = 0; i < elementNum; i++) {
            String[] stringArray = br.readLine().split("\\s");
            Process process = new Process(stringArray[0],
                    Integer.parseInt(stringArray[1]));
            que.offer(process);
        }
        int resultTime = 0;
        while (que.size() > 0) {
            Process process = que.poll();
            resultTime += quantum;
            if ((process.processTime = process.processTime - quantum) > 0) {
                que.offer(process);
                continue; 
            }
            resultTime += process.processTime;
            System.out.println(process.name + " " + resultTime);
        }

    }
    
}


Measured memory_bytes: 78024
#include<bits/stdc++.h>
#define rep(i, n) for (int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
 
int main(void){
    int n;
    cin>>n;
    ll ans = 0;
    for(int i = 1;i<=n;i++){
        int k = n/i;
        ans += (ll)k * ((ll)k+1LL) / 2LL * i;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3572
from functools import reduce
from operator import mul

def cmb(n,r):
  r = min(r, n-r)
  if r==0: return 1
  if r<0: return 0
  over = reduce(mul, range(n, n-r, -1))
  under = reduce(mul, range(1,r+1))
  return over//under

class UnionFind:
  def __init__(self, n):
    self.par = [i for i in range(n)]
    self.size = [1]*n
    self.rank = [0]*n
  def find(self, x):
    if self.par[x]==x:
      return x
    else:
      self.par[x] = self.find(self.par[x])
      return self.par[x]
  def unit(self, x, y):
    x = self.find(x)
    y = self.find(y)
    if x==y:
      return
    elif self.rank[x]<self.rank[y]:
      self.par[x] = y
      self.size[y] += self.size[x]
      return
    elif self.rank[y]<self.rank[x]:
      self.par[y] = x
      self.size[x] += self.size[y]
    else:
      self.par[y] = x
      self.size[x] += self.size[y]
      self.rank[x] += 1
      
  def same(self, x, y):
    return self.find(x)==self.find(y)
  
  def count(self, x):
    return self.size[x]

N, M = map(int, input().split())
bridge = []
u = UnionFind(N)
m = cmb(N,2)
ans = [m]

for i in range(M):
  A, B = map(int, input().split())
  bridge += [(A,B)]
  
for i in range(M-1,0,-1):
  a, b = bridge[i]
  if u.same(a-1,b-1):
    ans += [m]
    continue
  pa = u.find(a-1)
  pb = u.find(b-1)
  m -= u.count(pa)*u.count(pb)
  ans += [m]
  u.unit(a-1,b-1)

for i in range(M-1,-1,-1):
  print(ans[i])
  

Measured memory_bytes: 25984
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
// const ll MOD = 1000000007;
// const int INF = 2000000000;

ll N, C;
vector<ll> x, v;
vector<ll> x_rev, v_rev;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> N >> C;
  x.resize(N + 1, 0);
  v.resize(N + 1, 0);
  x_rev.resize(N + 1, 0);
  v_rev.resize(N + 1, 0);
  for (int i = 1; i <= N; i++) {
    cin >> x[i] >> v[i];
    x_rev[N - i + 1] = C - x[i];
    v_rev[N - i + 1] = v[i];
  }

  vector<ll> cum_calory(N + 1, 0);
  ll calory = 0;
  for (int i = 1; i <= N; i++) {
    cum_calory[i] = max(cum_calory[i - 1], calory + v[i] - x[i] + x[i - 1]);
    calory += (v[i] - x[i] + x[i - 1]);
  }

  vector<ll> rev_cum_calory(N + 1, 0);
  calory = 0;
  for (int i = 1; i <= N; i++) {
    rev_cum_calory[i] =
        max(rev_cum_calory[i - 1], calory + v_rev[i] - x_rev[i] + x_rev[i - 1]);
    calory += (v_rev[i] - x_rev[i] + x_rev[i - 1]);
  }

  ll ans = 0LL;
  for (int i = 1; i <= N; i++) {
    ans = max(ans, cum_calory[i]);
    ans = max(ans, rev_cum_calory[i]);
    ans = max(ans, cum_calory[i] - x[i] + rev_cum_calory[N - i]);
    ans = max(ans, cum_calory[N - i] - x_rev[i] + rev_cum_calory[i]);
  }

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

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

using namespace std;

int main()
{
  int n, ct = 0;
  cin >> n;
  string ch;
  cin >> ch;
  for(int i = 0; i < n - 2; i++)
  {
    if(ch[i] == 'A' && ch[i + 1] == 'B' && ch[i + 2] == 'C')
       ct++;
  }

  cout << ct << '\n';
  return 0;
}


Measured memory_bytes: 256
import sys

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

cf=[(0, 0)]*n

cf = sorted( [[int(x) for x in sys.stdin.readline().split()] for _ in range(n)] )

dp=[0]*(we+1)

best=0
cnt=1
lim=0

for w,c in cf:
    cnt=cnt+w
    lim=min(cnt, we-w)
    for j in range(lim, -1, -1):
        if dp[j+w]<(dp[j] + c) : dp[j+w]=dp[j] + c

print(max(dp))

Measured memory_bytes: 7736
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
	ll n,res=0;
  	cin>>n;
    ll v[n],c[n];
  for(ll i=0;i<n;i++)
    	cin>>v[i];
 	for(ll i=0;i<n;i++)
      	cin>>c[i];
  for(ll i=0;i<n;i++)
  {
    if(v[i]>c[i])
	res+=(v[i]-c[i]);
  }
  cout<<res;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i = a; i < (b); ++i)
#define rrep(i,a,b) for(int i = b; i --> (a);)
#define all(v) v.begin(),v.end()
#define trav(x,v) for(auto &x : v)
#define sz(v) (int)(v).size()
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	
	int h,w;
	cin >> h >> w;
	int fyra = 0, tva = 0, ett = 0;
	if(h%2==0 && w%2==0){
		fyra = h*w/4;
	} else if(h%2 == 0){
		fyra = h/2 * (w/2);
		tva = h/2;
	} else if(w%2==0){
		fyra = (w/2)*(h/2);
		tva = w/2;
	} else {
		fyra = (h/2)*(w/2);
		tva = (h/2) + (w/2);
		ett = 1;
	}
	vi cnt(26);
	vector<string> s(h);
	trav(t, s) cin >> t;
	trav(t, s) trav(c, t) ++cnt[c-'a'];
	rep(i,0,26){
		while(cnt[i]>=4 && fyra){
			cnt[i]-= 4;
			--fyra;
		}
		while(cnt[i]>=2 && tva){
			cnt[i] -= 2;
			--tva;
		}
		while(cnt[i]>=1 && ett){
			cnt[i]--;
			--ett;
		}
	}
	puts((ett+tva+fyra==0) ? "Yes" : "No");
}

Measured memory_bytes: 256