akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<queue>
#include<vector>
using namespace std;
long long int a[100000], b[100000];
long long int sima[100001];
long long int fuben[100001];
long long int group[100001];
vector<int> graph[100001];
int main() {

	long long int n, m;
	cin >> n >> m;
	int i,j,k;
	for (i = 0; i < m; i++) {
		cin >> a[i] >> b[i];

	}
	for (i = 0; i < n; i++) {
		sima[i + 1] = i + 1;
		group[i + 1] = 1;
	}
	//各島のグループを設定した．
	//
	long long int counter = n * (n - 1) / 2;
	fuben[m] = n * (n - 1) / 2;
	queue<int> conection;
	for (i = m - 1; i >= 0; i--) {
		//橋を一本ずつ落としていく問題から，橋を一本ずつつなげていく問題に変える。

		if (sima[a[i]] == sima[b[i]]) {
			//このとき不便さは変わらず
			fuben[i] = fuben[i + 1];
			//cout << fuben[i] << endl;
		}
		else {
			//大きい方の島に統合
			fuben[i] = fuben[i + 1] - group[sima[a[i]]] * group[sima[b[i]]];
			//cout << fuben[i] << endl;
			if (group[sima[a[i]]] > group[sima[b[i]]]) {

 				//b[i]からたどれるすべての島をsima[a[i]]にする．
				group[sima[a[i]]] = group[sima[a[i]]] + group[sima[b[i]]];
				group[sima[b[i]]] = 0;
				sima[b[i]] = sima[a[i]];
				conection.push(b[i]);
				while (conection.size()) {
					j = conection.front(); conection.pop();
					for (k = 0; k < graph[j].size(); k++) {
						if (sima[graph[j][k]] != sima[a[i]]) {
							sima[graph[j][k]] = sima[a[i]];
							conection.push(graph[j][k]);
						}
					}
				}

				
				//cout << sima[a[i]] << ' ' << group[sima[a[i]]] << endl;
				
				
			}
			else {

				//a[i]からたどれるすべての島をsima[b[i]]にする．
				group[sima[b[i]]] = group[sima[b[i]]] + group[sima[a[i]]];

				group[sima[a[i]]] = 0;
				sima[a[i]] = sima[b[i]];
				conection.push(a[i]);
				while (conection.size()) {
					j = conection.front(); conection.pop();
					for (k = 0; k < graph[j].size(); k++) {
						if (sima[graph[j][k]] != sima[b[i]]) {
							sima[graph[j][k]] = sima[b[i]];
							conection.push(graph[j][k]);
						}
					}
				}

				//cout << sima[b[i]] << ' ' << group[sima[b[i]]] << endl;
				

			}
			//cout << endl;
			//for (j = 1; j <= n; j++) {
			//	cout << j << ' ' << sima[j] << endl;
			//}cout << endl;
			//for (j = 1; j <= n; j++) {
			//	cout << j << ' ' << group[j] << endl;
			//}
		}
		graph[a[i]].push_back(b[i]);
		graph[b[i]].push_back(a[i]);
		//a[i]とb[i]を接続

	}
	for (i = 1; i <= m; i++) {
		cout << fuben[i]  << endl;
	}
	return 0;

}

Measured memory_bytes: 13064
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <string>
using namespace std;
const int N = 1e4 + 5;
char s[N];

int main()
{
    int n;
    char str[2];
    scanf("%d", &n);
    scanf("%c", &str);
    scanf("%s", s);
    int len = strlen(s);
    for(int i = 0; i < len; i ++ ){
        int a = s[i] - 'A';
        a = (a + n) % 26;
        printf("%c", 'A' + a);
    }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
//ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
//clock_t start=clock();clock_t end=clock();cout<<(double)(end-start)/CLOCKS_PER_SEC<<endl;
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int ui;
typedef pair<int,int> pii;
typedef pair<pii,int> ppii;
typedef pair<int,pii> pipi;
typedef pair<ll,ll> pll;
typedef pair<pll,ll> ppll;
typedef pair<ll,pll> plpl;
typedef pair<pii,pii> pippi;
typedef tuple<ll,ll,ll> tl;
typedef pair<double,double> pdd;
typedef vector<vector<ll>> mat;
ll mod=1000000007;
ll mod2=998244353;
ll mod3=1000003;
ll mod4=998244853;
ll mod5=1000000009;
ll inf=1LL<<61;
int iinf=1<<30;
double pi=3.14159265358979323846;
double pi2=pi/2.0;
double eps=1e-8;
#define rep(i,m,n) for(ll i=m;i<n;i++)
#define rrep(i,n,m) for(ll i=n;i>=m;i--)
#define srep(itr,st) for(auto itr=st.begin();itr!=st.end();itr++)
#define mrep(itr,mp) for(auto& itr:mp)
#define Max(a,b) a=max(a,b)
#define Min(a,b) a=min(a,b)
//#define endl "\n"
int dh[4]={1,0,-1,0};
int dw[4]={0,1,0,-1};
int ddh[8]={-1,-1,-1,0,0,1,1,1};
int ddw[8]={-1,0,1,-1,1,-1,0,1};
struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};
#define umh unordered_map<int,int,custom_hash>
ll gcd(ll a,ll b){
    if(a<0)a=-a;
    if(b<0)b=-b;
    if(a<b)swap(a,b);
    if(b==0)return a;
    if(a%b==0)return b;
    return gcd(b,a%b);
}
ll lcm(ll a,ll b){
    ll c=gcd(a,b);
    return a*b/c;
}
ll Pow(ll n,ll k){
    if(k<0)return 0;
    ll ret=1;
    ll now=n;
    while(k>0){
        if(k&1)ret*=now;
        now*=now;
        k/=2;
    }
    return ret;
}
ll beki(ll n,ll k,ll md){
  ll ret=1;
  ll now=n;
    now%=md;
  while(k>0){
    if(k%2==1){
      ret*=now;
      ret%=md;
    }
    now*=now;
    now%=md;
    k/=2;
  }
  return ret;
}
ll gyaku(ll n,ll md){
  return beki(n,md-2,md);
}
ll popcount(ll n){
    ll ret=0;
    ll u=n;
    while(u>0){
        ret+=u%2;
        u/=2;
        
    }
    return ret;
}

int main(){
    ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int x;cin>>x;
    if(x>=30)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}


Measured memory_bytes: 3648
#include <iostream>
#include <algorithm>
#include <bitset>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <complex>
#include <deque>
#include <valarray>
#include <unordered_map>
#include <unordered_set>
#include <array>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <chrono>
#include <random>
#include <numeric>
using namespace std;
using ll = long long;
using ld = long double;
using str = string;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<vs> vvs;
typedef vector<vc> vvc;
typedef vector<vb> vvb;
using P = pair<ll,ll>;
#define REP(i, n) for (ll i = 0; i < (int)(n); i++)
#define RREP(i, n) for (ll i = (int)(n)-1; i > -1 ; i--)
#define IN(T, x) T x;cin >> x;
#define AIN(T, a, n) vector<T> a(n);REP(i, n){cin >> a[i];}
#define A2IN(T1, a, T2, b, n) vector<T1> a(n);vector<T2> b(n);REP(i, n){cin >> a[i] >> b[i];}
#define ALL(a) (a).begin(),(a).end()
#define SORT(a) sort(ALL(a))
#define RSORT(a) SORT(a);reverse(ALL(a))
#define pb push_back
#define mp make_pair
#define PF first
#define PS second
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a,const T &b){if(b<a){a=b;return 1;}return 0;}
template<typename A, size_t N, typename T>void Fill(A (&array)[N], const T &val){fill( (T*)array, (T*)(array+N), val );}
#define OUT(x) cout << x << endl;
#define OUTD(x) cout << fixed << x << endl;
#define BOUT(b) if(b){OUT("Yes");}else{OUT("No");}
const ll MOD = 1000000007;
const ll INF = 10e9;
#define PI 3.14159265369;
ll dx[4] = {1,-1,0,0};
ll dy[4] = {0,0,1,-1};
ll ddx[8] = {1,1,1,-1,-1,-1,0,0};
ll ddy[8] = {0,1,-1,0,1,-1,1,-1};

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  IN(str,S);
  ll a = 1;
  ll count1 = 0, count2 = 0;
  REP(i,S.size()){
    if(a){
      if(S.at(i) == '1'){
        count1++;
      }
      a = 0;
    }else{
      if(S.at(i) == '0'){
        count1++;
      }
      a = 1;
    }
  }
  a = 0;
  REP(i,S.size()){
    if(a){
      if(S.at(i) == '1'){
        count2++;
      }
      a = 0;
    }else{
      if(S.at(i) == '0'){
        count2++;
      }
      a = 1;
    }
  }
  OUT(min(count1,count2));
}

Measured memory_bytes: 512
N, T = map(int, input().split())
ans_c, ans = 1000, 0
for _ in range(N):
    c, t = map(int, input().split())
    
    if t <= T:
        ans += 1
        if ans_c >= c:
            ans_c = c
if ans != 0:
    ans = ans_c
else:
    ans = 'TLE'
print(ans)

Measured memory_bytes: 3060
def main():
    import sys,math
    input = sys.stdin.readline

    n = int(input())
    a = list(map(int,input().split()))

    res = 0
    judge = True
    for e in a:
        if e >= n:
            judge = False
            break
    if judge:
        print(res)
        return
    
    x = 0
    while True:
        if a[x] <= n-1:
            x += 1
            if x == n:
                x = 0
            continue

        p = (a[x]//n)
        a[x] -= p*n
        res += p

        judge = True
        for i in range(n):
            if i == x:
                continue
            a[i] += p
            if a[i] >= n:
                judge = False
        if judge:
            print(res)
            return
        
        x += 1
        if x == n:
            x = 0

if __name__ == '__main__':
    main()

Measured memory_bytes: 40304
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <fstream>
#include <sstream>
#include <math.h>
#include <map>
using namespace std;
long L,R;

int main()
{
	int A,B;
	cin >> A >> B;
	cout << (A-1)*(B-1) << endl;

}

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

#define rep(i, n) for(int i = 0; i < (n); i++)
#define repp(i, l, r) for(int i = (l); i < (r); i++)
#define per(i, n) for(int i = ((n)-1); i >= 0; i--)
#define perr(i, l, r) for(int i = ((r)-1); i >= (l); i--)
#define all(x) (x).begin(),(x).end()
#define MOD 1000000007
#define IINF 1000000000
#define LINF 1000000000000000000
#define SP <<" "<<
#define CYES cout<<"Yes"<<endl
#define CNO cout<<"No"<<endl
#define CCYES cout<<"Yay!"<<endl
#define CCNO cout<<":("<<endl
#define CFS cin.tie(0);ios::sync_with_stdio(false)

typedef long long LL;
typedef long double LD;

int main(){
  int n;
  cin >> n;
  if(n==1){
    cout << 1 << endl;
    return 0;
  }
  vector<int> x(n),y(n);
  set<pair<int,int>> st;
  rep(i,n){
    cin >> x[i] >> y[i];
    st.insert({x[i],y[i]});
  }
  int ans=100;
  rep(i,n){
    rep(j,n){
      if(i==j) continue;
      int p = x[i]-x[j];
      int q = y[i]-y[j];
      int tmp=0;
      rep(k,n){
        if(st.find({x[k]-p,y[k]-q})==st.end()) tmp++;
      }
      ans=min(ans,tmp);
    }
  }
  cout << ans << endl;
  return 0;
}


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

int main()
{

    int A, B;
    cin >> A >> B;
    if (A % 3 == 0 || B % 3 == 0 || (A + B) % 3 == 0)
    {
        cout << "Possible";
    }
    else
    {
        cout << "Impossible";
    }
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>

int a[500000];
long long s1[500000], s2[500000];
int main() {
	int n;
	scanf("%d", &n);
	for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
	for (int i = 1; i <= n; i++) s1[i] = s1[i-1] + a[i], s2[i] = s2[i-1] ^ a[i];
	
	long long ans = 0;
	for (int i = 1; i <= n; i++) {
		int l = i, r = n;
		while (l < r) {
			int m = (l+r+1)/2;
			if (s1[m]-s1[i-1]==(s2[m]^s2[i-1])) l = m; else r = m - 1;
		}
		ans = ans + l - i + 1;
	}
	printf("%lld\n", ans);
	return 0;
} 

Measured memory_bytes: 8320
module Main where

import           Data.List

toInt :: String -> Int
toInt s = read s :: Int

strToIntList :: String -> [Int]
strToIntList = map toInt . words

main :: IO ()
main = do
  l1 <- getLine
  l2 <- getLine
  let (_ : k : _) = strToIntList l1
  let ps          = scanl (+) 0 $ strToIntList l2
  print . maximum . map (\x -> fromIntegral (k+x)/2) $ diff k ps

diff diffNum = zipWith subtract <$> id <*> drop diffNum

Measured memory_bytes: 81276
#include<stdio.h>

int main(void){
  int n, i, flag = 0, a[200], count = 0;
  scanf("%d", &n);
  for(i = 0; i < n; i++){
    scanf("%d", &a[i]);
  }
  for(;;){  
    for(i = 0; i < n; i++){
      if(a[i] % 2 != 0) flag = 1;
    }
    if(flag == 1) break;
    for(i = 0; i < n; i++){
      a[i] /= 2;
    }
    count++;
  }
  printf("%d", count);
  return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
	int n, m, x, cost_left = 0, cost_right = 0;
  	cin >> n >> m >> x;
  	for (int i = 0; i < m; i++){
    	int g; cin >> g;
      	if (g < x){
        	cost_left++;
        } else {
        	cost_right++;
        }
    }
  	cout << min(cost_left, cost_right);
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		int number;
		double height, weight;

		while (sc.hasNext()) {
			String str[] = sc.next().split(",");
			number = Integer.valueOf(str[0]);
			weight = Double.valueOf(str[1]);
			height = Double.valueOf(str[2]);
			double bmi = weight / height / height;
			if (25.0 <= bmi) {
				System.out.println(number);
			}
		}
	}
}

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

int main(){
    int n;
    cin >> n;
    int count = 0;
    for(int i = 1; i <= n; i++){
        for(int j = 1; j <= n; j++){
            if(i != j){
                if(i % 2 == 0 && j % 2 != 0){
                    count++;
                }
            }
        }
    }
    cout << count << endl;
    return 0;
}

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

using namespace std;

int main(){
  int N,K,X,Y;
  cin >> N >> K >> X >> Y;
  if(N>K) cout << K*X + (N-K)*Y << endl;
  else  cout << N*X << endl;

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n,m,f[100001];
long long cot[100001];
long long ans[100001];
struct node
{
    int x,y;
}a[100001];
int getf(int x)
{
    return f[x]==x?x:f[x]=getf(f[x]);
}
int main()
{
    scanf("%d%d",&n,&m);
    for(int i=1;i<=n;i++) f[i]=i,cot[i]=1,ans[m]+=i;
    ans[m]-=n;
    for(int i=1;i<=m;i++)
        scanf("%d%d",&a[i].x,&a[i].y);
    long long t=ans[m];
    for(int i=m;i>1;i--)
    {
        int fx=getf(a[i].x),fy=getf(a[i].y);
        if(fx!=fy) t-=cot[fx]*cot[fy],cot[fx]+=cot[fy],f[fy]=f[fx];
        ans[i-1]=t;
    }
    for(int i=1;i<=m;i++)
        printf("%lld\n",ans[i]);
}


Measured memory_bytes: 4096
package main

import (
	"bufio"
	"os"
	"strconv"
	"strings"
	"fmt"
)

var scanner = bufio.NewScanner(os.Stdin)
var (
	dat = [5000][5]int{}
	m = [5]int{}
)

func main() {
	for scanner.Scan() {
		for i := range dat {
			for j := range dat[i] {
				dat[i][j] = 0
			}
		}
		for i := range m {
			m[i] = 0
		}
		n, _ := strconv.Atoi(scanner.Text())
		if n == 0 {
			break
		}
		count := 0
		for i := 0; i < n; i++ {
			scanner.Scan()
			buf := strings.Split(scanner.Text(), " ")
			d, _ := strconv.Atoi(buf[0])
			p, _ := strconv.Atoi(buf[1])
			q, _ := strconv.Atoi(buf[2])
			q--
			count += p
			if d == 2 {
				for j := 0; j < p; j++ {
					dat[m[q]][q] = 1
					ok := true
					for k := 0; k < 5; k++ {
						if dat[m[q]][k] == 0 {
							ok = false
						}
					}
					if ok {
						for k := 0; k < 5; k++ {
							dat[m[q]][k] = 0
							for l := m[q]; l < 4999; l++ {
								dat[l][k] = dat[l+1][k]
							}
							for l := 4999; l >= 0; l-- {
								if dat[l][k] != 0 {
									m[k] = l+1
									break
								}
								if l == 0 {
									m[k] = 0
								}
							}
						}
						count -= 5
					} else {
						m[q]++
					}
				}
			} else {
				h := 0
				for i := 0; i < p; i++ {
					h = max(h, m[i+q])
				}
				for i := 0; i < p; i++ {
					dat[h][i+q] = 1
				}
				for i := 0; i < p; i++ {
					m[i+q] = h+1
				}
				ok := true
				for j := 0; j < 5; j++ {
					if dat[h][j] == 0 {
						ok = false
					}
				}
				if ok {
					for j := 0; j < 5; j++ {
						dat[h][j] = 0
						for k := h; k < 4999; k++ {
							dat[k][j]=dat[k+1][j]
						}
						for k := 4999; k>= 0; k-- {
							if dat[k][j] != 0 {
								m[j]=k+1
								break
							}
							if k == 0 {
								m[j] = 0
							}
						}
					}
					count -= 5
				}
			}
		}
		fmt.Println(count)
	}
}

func max(a, b int) int {
	if a < b {
		return b
	}
	return a
}


Measured memory_bytes: 1376
#include <cstdio>
#include <iostream>
#include <string>
using namespace std;


int main(){
	string a;
	int b[26] = {};
	while(cin>>a){
		for(int i = 0;i < 1200;i++){
			if(a[i] == 'a'||a[i] == 'A')b[0]++;
			else if(a[i] == 'b'||a[i] == 'B')b[1]++;
			else if(a[i] == 'c'||a[i] == 'C')b[2]++;
			else if(a[i] == 'd'||a[i] == 'D')b[3]++;
			else if(a[i] == 'e'||a[i] == 'E')b[4]++;
			else if(a[i] == 'f'||a[i] == 'F')b[5]++;
			else if(a[i] == 'g'||a[i] == 'G')b[6]++;
			else if(a[i] == 'h'||a[i] == 'H')b[7]++;
			else if(a[i] == 'i'||a[i] == 'I')b[8]++;
			else if(a[i] == 'j'||a[i] == 'J')b[9]++;
			else if(a[i] == 'k'||a[i] == 'K')b[10]++;
			else if(a[i] == 'l'||a[i] == 'L')b[11]++;
			else if(a[i] == 'm'||a[i] == 'M')b[12]++;
			else if(a[i] == 'n'||a[i] == 'N')b[13]++;
			else if(a[i] == 'o'||a[i] == 'O')b[14]++;
			else if(a[i] == 'p'||a[i] == 'P')b[15]++;
			else if(a[i] == 'q'||a[i] == 'Q')b[16]++;
			else if(a[i] == 'r'||a[i] == 'R')b[17]++;
			else if(a[i] == 's'||a[i] == 'S')b[18]++;
			else if(a[i] == 't'||a[i] == 'T')b[19]++;
			else if(a[i] == 'u'||a[i] == 'U')b[20]++;
			else if(a[i] == 'v'||a[i] == 'V')b[21]++;
			else if(a[i] == 'w'||a[i] == 'W')b[22]++;
			else if(a[i] == 'x'||a[i] == 'X')b[23]++;
			else if(a[i] == 'y'||a[i] == 'Y')b[24]++;
			else if(a[i] == 'z'||a[i] == 'Z')b[25]++;
			else if(!a[i])break;
		}
	}
	
		cout << "a : " << b[0] << "\n";
		cout << "b : " << b[1] << "\n";
		cout << "c : " << b[2] << "\n";
		cout << "d : " << b[3] << "\n";
		cout << "e : " << b[4] << "\n";
		cout << "f : " << b[5] << "\n";
		cout << "g : " << b[6] << "\n";
		cout << "h : " << b[7] << "\n";
		cout << "i : " << b[8] << "\n";
		cout << "j : " << b[9] << "\n";
		cout << "k : " << b[10] << "\n";
		cout << "l : " << b[11] << "\n";
		cout << "m : " << b[12] << "\n";
		cout << "n : " << b[13] << "\n";
		cout << "o : " << b[14] << "\n";
		cout << "p : " << b[15] << "\n";
		cout << "q : " << b[16] << "\n";
		cout << "r : " << b[17] << "\n";
		cout << "s : " << b[18] << "\n";
		cout << "t : " << b[19] << "\n";
		cout << "u : " << b[20] << "\n";
		cout << "v : " << b[21] << "\n";
		cout << "w : " << b[22] << "\n";
		cout << "x : " << b[23] << "\n";
		cout << "y : " << b[24] << "\n";
		cout << "z : " << b[25] << "\n";
	
	return 0;
}

Measured memory_bytes: 3148
#include <bits/stdc++.h>
#define ll long long
#define maxn 1000005 /*rem*/
#define mod 998244353
#define db double
#define vi vector<int>
#define pb push_back
#define mp make_pair
#define pi pair<int, int>
#define fi first
#define se second
using namespace std;
ll ksm(ll a, ll b) {
   if (!b) return 1;
   ll ns = ksm(a, b >> 1);
   ns = ns * ns % mod;
   if (b & 1) ns = ns * a % mod;
   return ns;
}
ll bk[maxn]; 
vi dv[maxn];
ll f[maxn];
ll w[maxn];
int main() {
	for (int i = 1; i < maxn; i++)
		for (int j = 1; j * i < maxn; j++)
			dv[i * j].pb(i);
	for (int i = 1; i < maxn; i++)
		bk[i] = ksm(i, mod - 2);
	for (int i = 1; i < maxn; i++) {
		f[i] = (bk[i] - f[i]) % mod;
		for (int j = 2; j * i < maxn; j++)
			f[i * j] = (f[i * j] + f[i]) % mod;
	}
	int n;
	cin >> n;
	ll ans = 0;
	for (int i = 1; i <= n; i++) {
		int a;
		scanf("%d", &a);
		for (int j = 0; j < dv[a].size(); j++) {
			int nr = dv[a][j];
			ans += 1ll * w[nr] * a % mod * f[nr]; 
			ans %= mod;
			w[nr] = (w[nr] + a) % mod;
		}
	}
	ans %= mod;
	if (ans < 0) ans += mod;
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 138240
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define lowbit(a) ((a) & -(a))
#define clean(a, b) memset(a, b, sizeof(a))
const int mod = 1e9 + 7;
const int inf = 0x3f3f3f3f;
const int maxn = 2e5 + 9;
 
int _;

//========================================================================
int main()
{
    string s,t;
    cin>>s>>t;
    int l=s.size(),ans=0;
    for(int i=0;i<l;i++)
    {
        if(s[i]!=t[i]) ans++;
    }
    printf("%d\n",ans);
    return 0;
}


Measured memory_bytes: 3836
#![allow(unused_imports)]
#![allow(non_snake_case)]
use std::cmp::*;
use std::collections::*;
use std::ops::Bound::*;
use itertools::Itertools;
use num_traits::clamp;
use ordered_float::OrderedFloat;
use proconio::{input, marker::*, fastout};
use superslice::*;

#[fastout]
fn main() {
    input! {
        n: usize, q: usize,
        a: [usize; n],
        query: [(usize, usize, usize); q]
    }

    let mut bit = BIT::new(n);
    for (i, a) in (0..).zip(a) {
        bit.add(i + 1, a);
    }

    for (command, x, y) in query {
        match command {
            0 => bit.add(x + 1, y),
            1 => {
                let res = bit.sum(y) - bit.sum(x);
                println!("{}", res);
            }
            _ => unreachable!()
        }
    }
}

#[allow(dead_code)]
/// Binary Indexed Tree of usize
pub struct BIT {
    buf: Vec<usize>,
}
#[allow(dead_code)]
impl BIT {
    pub fn new(n: usize) -> BIT {
        BIT {
            buf: vec![0; n + 1],
        }
    }
    pub fn sum(&self, i: usize) -> usize {
        let mut i = i;
        let mut s = 0;
        while i > 0 {
            s += self.buf[i];
            i &= i - 1;
        }
        s
    }
    pub fn add(&mut self, i: usize, x: usize) {
        let mut i = i as i64;
        while i < self.buf.len() as i64 {
            self.buf[i as usize] += x;
            i += i & -i;
        }
    }
}

Measured memory_bytes: 34904
#include <iostream>
#include <climits>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#include <tuple>
#include <queue>
#include <deque>
#include <unordered_set>
#include <unordered_map>

using namespace std;
typedef long long ll;

int main(void) {
  ll N, T; cin >> N >> T;
  vector<ll> vT(N);
  for (int i = 0; i < N; i++) { cin >> vT[i]; }

  ll total = T;
  for (int i = 0; i < N - 1; i++) {
    total += min(T, vT[i + 1] - vT[i]);
  }
  cout << total << endl;
}


Measured memory_bytes: 1792
#include <iostream>
#include <vector>
#include <set>

using namespace std;

class path {
	public:
		int cap;
		int dest;
		int flow;
		path(int cap_,int dest_) {
			cap = cap_;
			dest = dest_;
			flow = 0;
		}

};

int cap[100][100],flow[100][100],fsum,goal,vert;
bool visited[100];

int dfs(int cur,int minf) {
	if(cur == goal) {
		fsum += minf;
		return minf;
	}
	for(int i = 1;i < vert;i++) {
		if(!visited[i] && cap[cur][i] > flow[cur][i]) {
			visited[i] = true;
			int ret = dfs(i,min(minf,cap[cur][i]-flow[cur][i]));
			if(ret != 0) {
				flow[cur][i] += ret;
				return ret;
			}
		}
		if(!visited[i] && flow[i][cur] > 0) {
			visited[i] = true;
			int ret = dfs(i,min(minf,flow[i][cur]));
			if(ret != 0) {
				flow[i][cur] -= ret;
				return ret;
			}
		}
	}
	return 0;
}

int main() {
	int V,E;
	int u,v,c;
	cin >> V >> E;
	goal = V-1;
	vert = V;
	for(int i = 0;i < E;i++) {
		cin >> u >> v >> c;
		cap[u][v] = c;
	}
	int ret = 0;
	while(ret = dfs(0,10000)) {
		for(int i = 0;i < 100;i++) visited[i] = false;
	}
	cout << fsum << endl;
}



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

#define ll long long

int main()
{
    int t;
    int c[100008];
    memset(c,0,sizeof(c));
    c[1] = 1;
    for (int i = 2;i <= 100007; i++) {
        if (c[i] == 0) {
            for (int j = 2; i*j <= 100007; j++) {
                c[i*j] = 1;
            }
            //cout << i << " ";
        }
    }
    cin >> t;
    for(int i = t ;i <= 100007; i++) {
        if (c[i] == 0) {
            cout << i;
            break;
        }
    }
    //cout << t;
    return 0;
}


Measured memory_bytes: 640
N = gets.to_i
s = gets.chomp.split('')
gets

#tate:T yoko:Y
pat = []
while s.length > 0 do
    if s.length > 1 && s[0] == s[1]
        pat.push('Y')
        s.shift
        s.shift
    else
        pat.push('T')
        s.shift
    end
end

MOD = 1000000007

if pat.shift == 'T'
    ans = 3
    prev = 'T'
else
    ans = 6
    prev = 'Y'
end

while pat.length > 0 do
    s = pat.shift
    if s == 'T' && prev == 'T'
        ans *= 2
    elsif s == 'T' && prev == 'Y'
        # 1
    elsif s == 'Y' && prev == 'T'
        ans *= 2
    else
        ans *= 3
    end
    prev = s
    ans %= MOD
end

puts ans


Measured memory_bytes: 1788
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define GET_ARRAY_SIZE(a)   (sizeof(a)/sizeof(a[0]))
#define LL long long
int main(){
    LL n,chk_n;
    cin >> n;
    chk_n = n%10;

    switch (chk_n){
    case 2: case 4: case 5: case 7: case 9:
        cout << "hon" << endl;
        break;
    case 0: case 1: case 6: case 8:
        cout << "pon" << endl;
        break;
    case 3:
        cout << "bon" << endl;
    default:
        break;
    }

    return 0;
}

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

int main(){
    int K,X;
    std::cin>>K>>X;
    std::string s = "";
    for(int i = K - 1; i >= 0-(K-1); i--){
        s+= std::to_string(X - i)+" ";
    }
    std::cout << s.substr(0,s.length()-1) << std::endl;
}

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

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

    int x, n;
    cin >> x >> n;
    set<int> st;
    for(int i = 0; i < n; i++){
        int a;
        cin >> a;
        st.insert(a);
    }

    int ans = 0;
    int diff = 9999;
    for(int i = 0; i <= 101; i++){
        if(st.count(i)) continue;
        if(abs(x - i) < diff){
            diff = abs(x - i);
            ans = i;
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3608
#include<bits/stdc++.h>
#define llu unsigned long long
#define ll long long
#define INF 0x3f3f3f3f
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n"
#define to_lower(s) transform(s.begin(), s.end(), s.begin(), ::tolower);
#define to_upper(s) transform(s.begin(), s.end(), s.begin(), ::toupper);

using namespace std;

// scan vector
template <typename T> 
inline istream &operator>>(istream &in, vector<T> &a) {
    for(auto &x : a) in >> x;
    return in;
}
// print vector
template <typename T> 
inline ostream &operator<<(ostream &out, vector<T> &a) {
    for(auto &x : a) out << x <<" ";
    return out;
}
// scan pair
template <typename T, typename U> 
inline istream &operator>>(istream &in, pair<T,U> &a) {
    in >> a.first >> a.second; 
    return in;
}
int n;
double dp[305][305][305];

double solve(int a, int b, int c)
{
    if(a<0 || b<0 || c<0)
        return 0;
    if(a==0 && b==0 && c==0)
        return dp[a][b][c]=0;
    if(dp[a][b][c]!=-1)
        return dp[a][b][c];
    double p_waste=(double)(n-(a+b+c))/(double)(a+b+c);
    dp[a][b][c]=p_waste;
    // dp[a][b][c]=p_waste/(1-p_waste);
    
    dp[a][b][c]+=(double)a*((solve(a-1,b,c)+1)/(double)(a+b+c));
    dp[a][b][c]+=(double)b*((solve(a+1,b-1,c)+1)/(double)(a+b+c));
    dp[a][b][c]+=(double)c*((solve(a,b+1,c-1)+1)/(double)(a+b+c));

    return dp[a][b][c];
}

int main()    
{
    #ifdef SANS
        freopen("ongoingin.txt","r",stdin);
        freopen("ongoingout.txt","w",stdout);
    #endif
    fast
    int t=1;
    // cin>>t;
    while(t--)
    {
        cin>>n;
        int one=0,two=0,three=0;
        vector<int> sushi(n);
        for(int i=0; i<305; i++){
            for(int j=0; j<305; j++){
                for(int k=0; k<305; k++)
                    dp[i][j][k]=-1;
            }
        }
        for(int i=0; i<n; i++)
        {
            cin>>sushi[i];
            if(sushi[i]==1)
                one++;
            else if(sushi[i]==2)
                two++;
            else
                three++;
        }
        cout<<setprecision(9)<<fixed;
        cout<<(solve(one,two,three));
    }
    #ifdef SANS
        cout<<"\nTime Elapsed:"<<1.0*clock()/CLOCKS_PER_SEC <<"sec\n";
    #endif
}

Measured memory_bytes: 225488
#include <bits/stdc++.h>
using namespace std;
using ll  = long long;
using vl  = vector<ll>;
using vvl = vector<vl>;

#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rng(i,a,b) for(int i = (a); i < (b); ++i)
#define all(a) (a).begin(), (a).end()
const string RGB = "RGB";

int main() {
    int N; cin >> N;
    string S; cin >> S;
    vvl sum(3, vl(N+1, 0));
    rep(c,3) rep(i,N) {
        sum[c][i+1] = (S[i] == RGB[c]);
        sum[c][i+1] += sum[c][i];
    }
    ll ans = 0;
    rep(i,N-2) rng(j,i+1,N-1) {
        vl rgb(3); iota(all(rgb), 0);
        do {
            if (S[i] != RGB[rgb[0]] or S[j] != RGB[rgb[1]]) continue;
            ans += sum[rgb[2]][N] - sum [rgb[2]][j+1];
        } while (next_permutation(all(rgb)));
    }
    rep(i,N-2) rng(len,1,N) {
        if (i+2*len > N) continue;
        vl rgb(3); iota(all(rgb), 0);
        do {
            if (S[i]==RGB[rgb[0]] and S[i+len]==RGB[rgb[1]] and S[i+2*len]==RGB[rgb[2]]) ans--;
        } while (next_permutation(all(rgb)));
    }
    cout << ans << endl;
    return 0;
}


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

int main(int argc, char **argv)
{
   ios_base::sync_with_stdio(false);
   cin.tie(NULL);

#ifdef LOCAL_DEFINE
   freopen("in.txt", "r", stdin);
#endif

   int n;
   cin >> n;
   for (int i = 0; 4 * i <= n; ++i)
   {
      for (int j = 0; 7 * j <= n; ++j) {
         if (4 * i + 7 * j == n)
         {
            cout << "Yes\n";
            return 0;
         }
      }
   }

   cout << "No\n";
   return 0;
}

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

using namespace std;
typedef long long ll;

#define MOD (long long)(1e9+7)
#define REP(i,n) for(ll i = 0; i < n; i++)
#define REP1(i,n) for(ll i = 1; i <= n; i++)

int main(void)
{
  ll n; cin >> n;
  set<string> ss;
  REP(i, n) {
    string s1;
    cin >> s1;
    ss.insert(s1);
  }
  cout << ss.size() << endl;

}


Measured memory_bytes: 19176
while True:
    S=0
    a,b=map(int,input().split())
    if a==0 and b==0:
        break
    for i in range(a):
        X=a-i
        for j in range(X-1):
            Y=(X-1)-j
            for k in range(X-2):
                Z=(X-2)-k-j
                if X>0 and Y>0 and Z>0:
                    A=X+Y+Z
                    if A==b:
                        S=S+1
                    
    print(S)


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

using namespace std;

int N, M;
vector<pair<int, int> > times;
int main(){
	cin >> N >> M;
	for(int i = 1; i <= N; i++){
		times.push_back({i, 0});
	}

	for(int j = 1; j <= M; j++){
		int a,b;
		cin >> a;
		times[a - 1].second = j;
	}

	sort(times.begin(), times.end(), [](const pair<int, int>& a, const pair<int, int> &b)->bool{
		if(a.second != b.second) return b.second < a.second;
		else return a.first < b.first;
	});

	for(auto pp : times){
		cout << pp.first << endl;
	}
}

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

#define ll long long
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define REP(i, x) for (int i = 0; i < (int)(x); i++)
#define REPS(i, x) for (int i = 1; i <= (int)(x); i++)
#define RREP(i, x) for (int i = ((int)(x)-1); i >= 0; i--)
#define RREPS(i, x) for (int i = ((int)(x)); i > 0; i--)
#define INF 2147483647
#define LLINF 9223372036854775807LL
#define vi vector<int>
#define vvi vector<vector<int>>
#define vvvi vector<vector<vector<int>>>
#define pi pair<int, int>
#define ALL(a) (a).begin(), (a).end()
#define BIT(n) (1LL << (n))

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

ll yabaimod(ll x,ll y){
    ll z=1;
    for(ll i=0;i<y;i++){
        z=z*x%1000000007;
    }
    return z;
}
int main(){
ll N; cin>>N;
ll ans=yabaimod(10,N)+yabaimod(8,N)-yabaimod(9,N)-yabaimod(9,N);
ans=ans%1000000007;
ans=(ans+1000000007)%1000000007;
cout<<ans<<endl;
}

Measured memory_bytes: 3672
import java.util.Scanner;

class Main
{
    public static int parent(int i)
    {
	return i / 2;
    }

    public static int left(int i)
    {
	return i * 2;
    }

    public static int right(int i)
    {
	return 2 * i + 1;
    }

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

	int N = In.nextInt();

	int[]A = new int[10001];

	for(int i = 1; i <= N; i++)
	    {
		A[i] = In.nextInt();
	    }

	for(int i = 1; i <= N; i++)
	    {
		System.out.print("node " + i + ": key = " + A[i] + ", ");

		if(parent(i) >= 1) System.out.print("parent key = " + A[parent(i)] + ", ");
		if(left(i) <= N) System.out.print("left key = " + A[left(i)] + ", ");
		if(right(i) <= N) System.out.print("right key = " + A[right(i)] + ", ");

		System.out.println();
	    }
    }
}

Measured memory_bytes: 27416
#include<cstdio>
#include<cstring>
#include<cmath>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<queue>

using namespace std;

using ll=long long;
using vi=vector<int>;
using vvi=vector<vi>;
using pii=pair<int,int>;
using vll=vector<ll>;
using vvll=vector<vll>;
using vpii=vector<pii>;

#define PI 3.1415926535897932384626433832795


ll e_sum(vll&e, int k, int n)
{
	if(n<1) return 0;
	ll ret=e[k]*((n-1)/k);
	ret+=e[(n-1)%k];
	return ret;
}


void dump(vll&v, const char *pre="")
{
	printf("%s", pre);
	for(auto m:v) printf("%lld ", m);
	printf("\n");
}


int solve(int n, int x, int m, vi&d, int k)
{
	vll e(k+1), z(k+1), c(k+1);

	for(int i=0;i<k;i++)
	{
		e[i+1]=e[i]+d[i]%m;
		z[i+1]=z[i]+(d[i]%m==0);
		c[i+1]=c[i]+e[i+1]/m;
		e[i+1]%=m;
	}

	static bool is_first=true;
	if(0)
	{
		is_first=false;
	dump(e, "e=");
	dump(z, "z=");
	dump(c, "c=");
	}

	ll s=x%m+e_sum(e, k, n);
	ll ret=n-1-s/m;
	ret-=e_sum(c, k, n);
	ret-=e_sum(z, k, n);

//	printf("n=%d  s=%lld  cn=%lld  zn=%lld\n", n, s, e_sum(c, k, n), e_sum(z, k, n));

	return ret;
}


int main(void)
{
	int k, q;
	while(scanf("%d%d", &k, &q)==2)
	{
		vi d(k);
		for(auto&m:d) scanf("%d", &m);

		vi n(q), x(q), m(q);
		for(int i=0;i<q;i++)
		{
			scanf("%d%d%d", &n[i], &x[i], &m[i]);
		}

		for(int i=0;i<q;i++)
		{
			printf("%d\n", solve(n[i], x[i], m[i], d, k));
		}
	}
	return 0;
}


Measured memory_bytes: 512
import java.io.IOException;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws IOException {

		new Main().run();
	}

	private void run() throws IOException {
		Scanner scanner = new Scanner(System.in);
		while (scanner.hasNext()) {
			a = scanner.next();
			b = scanner.next();
			int p1 = a.length();
			int p2 = 0;
			int ans = 0;
			while (p1 != 0 || p2 != b.length()) {
				if (p1 != 0)
					p1--;
				else
					p2++;
				ans = Math.max(ans, slove(p1, p2));
			}
			System.out.println(ans);
		}

	}

	private int slove(int p1, int p2) {
		int res = 0;
		int tmp = 0;
		int leng = Math.min(a.length() - p1, b.length() - p2);
		for (int i = 0; i < leng; i++) {
			if (a.charAt(i + p1) == b.charAt(i + p2))
				tmp++;
			else {
				res = Math.max(res, tmp);
				tmp = 0;
			}
		}
		return Math.max(res, tmp);
	}

	String a;
	String b;
}

Measured memory_bytes: 21280
n,k = gets.split.map(&:to_i)
h = []
n.times do
  h << gets.to_i
end
h.sort!
min = h[-1]
((n - k) + 1).times do |i|
  arr = h[i,k]
  diff = arr[-1] - arr[0]
  min = diff if diff < min
end
puts min

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

const int maxn=110;
int n;
int a[maxn];
int p,q;
int ans;

void solve(){
	int Max=0, k=0;
	for(int i=1;i<=n;i++){
		if(abs(a[i])>Max){
			Max=abs(a[i]); k=i;
		}
	}
	if(a[k]<0){
		for(int i=1;i<=n;i++) if(a[i]>=0) ans++;
		printf("%d\n", ans+n-1);
		for(int i=1;i<=n;i++) if(a[i]>=0) printf("%d %d\n", k, i);
		for(int i=n;i>1;i--) printf("%d %d\n", i, i-1);
	}else{
		for(int i=1;i<=n;i++) if(a[i]<0) ans++;
		printf("%d\n", ans+n-1);
		for(int i=1;i<=n;i++) if(a[i]<0) printf("%d %d\n", k, i);
		for(int i=1;i<n;i++) printf("%d %d\n", i, i+1);
	}
}

int main(){

	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		scanf("%d",&a[i]);
		if(a[i]>=0) p++; else q++;
	}
	int flag=1;
	for(int i=2;i<=n;i++) if(a[i]<a[i-1]){ flag=0; break; }
	if(flag){ puts("0"); return 0; }
	if(p==n){
		printf("%d\n", n-1);
		for(int i=1;i<n;i++) printf("%d %d\n", i, i+1);
	}else if(q==n){
		printf("%d\n", n-1);
		for(int i=n;i>1;i--) printf("%d %d\n", i, i-1);
	}else solve();
	return 0;
}

Measured memory_bytes: 256
use v5.18; # strict say state
use warnings;
use List::Util qw(reduce first max min sum0);

chomp (my ($n, $x, $y) = split / /, <STDIN>);
my @ans;
for my $i (1..$n) {
  for my $j ($i..$n) {
    my $d = $j - $i;
    my $s = abs($i - $x) + 1 + abs($j - $y);
    $ans[min($d, $s)]++;
  }
}
for my $i (1..$n-1) {
  say $ans[$i] + 0;
}

Measured memory_bytes: 896
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <unordered_map>
using namespace std;

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

template<class T> vector<T> make_vec(size_t a) { return vector<T>(a); }
template<class T, class... Ts> auto make_vec(size_t a, Ts... ts) {
  return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
template<class T, class V>
typename enable_if<is_class<T>::value == 0>::type fill(T &t, const V &v) {
    t = v;
}
template<class T, class V>
typename enable_if<is_class<T>::value != 0>::type fill(T &t, const V &v){
    for (auto &e : t) fill(e, v);
}

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }

#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
template<class T> ostream& operator << (ostream &s, set<T> P)
{ EACH(it, P) { s << "<" << *it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }

int N;
vector<long long> s;


int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    while (cin >> N) {
        s.resize(N);
        for (int i = 0; i < N; ++i) cin >> s[i];

        long long res = 0;
        for (int p = 1; p <= N-1; ++p) {
            if ((N-1) % p == 0) {
                long long tmp = 0;
                long long cur = 0;
                int i = 0, j = N-1;
                for (; i < j; i += p, j -= p) {
                    cur += s[i] + s[j];
                    chmax(tmp, cur);
                    
                    //cout << p << ": " << make_pair(i, j) << ":: " << cur << endl;
                }
                chmax(res, tmp);
            }
            else {
                long long tmp = 0;
                long long cur = 0;
                int i = 0, j = N-1;
                for (; i < N-1 && j > p; i += p, j -= p) {
                    cur += s[i] + s[j];
                    chmax(tmp, cur);
                    
                    //cout << p << ": " << make_pair(i, j) << ":: " << cur << endl;
                }
                chmax(res, tmp);
            }
        }
        cout << res << endl;
    }
}


















Measured memory_bytes: 1024
def main():
    from bisect import bisect_left

    N = int(input())
    s = input()

    Rs = []
    Gs = []
    Bs = []
    for i, c in enumerate(s):
        if c == 'R':
            Rs.append(i)
        elif c == 'G':
            Gs.append(i)
        else:
            Bs.append(i)

    s += 'Z' * 4000

    ans = 0
    for mid in Rs:
        for g in Gs:
            if g >= mid: break
            ans += len(Bs) - bisect_left(Bs, mid) - (1 if s[mid * 2 - g] == 'B' else 0)
        for b in Bs:
            if b >= mid: break
            ans += len(Gs) - bisect_left(Gs, mid) - (1 if s[mid * 2 - b] == 'G' else 0)
    for mid in Gs:
        for r in Rs:
            if r >= mid: break
            ans += len(Bs) - bisect_left(Bs, mid) - (1 if s[mid * 2 - r] == 'B' else 0)
        for b in Bs:
            if b >= mid: break
            ans += len(Rs) - bisect_left(Rs, mid) - (1 if s[mid * 2 - b] == 'R' else 0)
    for mid in Bs:
        for r in Rs:
            if r >= mid: break
            ans += len(Gs) - bisect_left(Gs, mid) - (1 if s[mid * 2 - r] == 'G' else 0)
        for g in Gs:
            if g >= mid: break
            ans += len(Rs) - bisect_left(Rs, mid) - (1 if s[mid * 2 - g] == 'R' else 0)
    print(ans)


if __name__ == '__main__':
    main()

# import sys
#
# sys.setrecursionlimit(10 ** 7)
#
# input = sys.stdin.readline
# rstrip()
# int(input())
# map(int, input().split())


Measured memory_bytes: 70808
#include "bits/stdc++.h"
#define MAXN 100009
#define INF 1000000007
#define mp(x,y) make_pair(x,y)
#define all(v) v.begin(),v.end()
#define pb(x) push_back(x)
#define wr cout<<"----------------"<<endl;
#define ppb() pop_back()
#define tr(ii,c) for(__typeof((c).begin()) ii=(c).begin();ii!=(c).end();ii++)
#define ff first
#define ss second
#define my_little_dodge 46
#define debug(x)  cerr<< #x <<" = "<< x<<endl;
using namespace std;

typedef long long ll;
typedef pair<int,int> PII;
template<class T>bool umin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
template<class T>bool umax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
int cnt[MAXN];
int main(){
    //~ freopen("file.in", "r", stdin);
    int n;
    scanf("%d",&n);
    while(n--){
		int x;
		scanf("%d",&x);
		cnt[x]++;
	}int ans=cnt[0]+cnt[1];
	for(int i=1;i<MAXN-3;i++)
		umax(ans,cnt[i-1]+cnt[i]+cnt[i+1]);
	printf("%d\n",ans);	
	return 0;
}


Measured memory_bytes: 640
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC066A
{
    class Program
    {
        static void Main(string[] args)
        {
            int a, b, c, r;
            string[] word = Console.ReadLine().Split(' '); 
            a = int.Parse(word[0]);
            b = int.Parse(word[1]);
            c = int.Parse(word[2]);
            int ab = a + b;
            int ac = a + c;
            int bc = b + c;


            if (ab < ac && ab < bc)
                r = ab;
            else if (ac < ab && ac < bc)
                r = ac;
            else
                r = bc;
            Console.WriteLine(r);


            
             
        }
    }
}


Measured memory_bytes: 27500
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
#define rep(i,n) for(int i=0;i<n;++i)


//vector<vector<int>> z(n,vector<int>(2));

int main(){
  vector<vector<int>> a(3,vector<int>(3));
  vector<vector<int>> t(3,vector<int>(3));
  rep(i,3)rep(j,3){
    cin>>a[i][j];
  }
  int n;
  cin>>n;
  rep(i,n){
    int b;
    cin>>b;
    rep(j,3)rep(k,3){
      if (b==a[j][k]){
        t[j][k]=1;
      }
    }

  }
//  cout<<t[0][1]<<'n';
string ans="No";
  rep(i,3){
    if ((t[i][0]+t[i][1]+t[i][2])==3)ans="Yes";
  }
  rep(i,3){
    if ((t[0][i]+t[1][i]+t[2][i])==3)ans="Yes";
  }
  if ((t[0][0]+t[1][1]+t[2][2])==3)ans="Yes";
  if ((t[2][0]+t[1][1]+t[0][2])==3)ans="Yes";
  cout<<ans;

}


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

using namespace std;

int n;
int data[100];
long long dp[21][101];

main(){

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

    for(int i=0;i<22;i++){
      for(int j=0;j<n;j++){
	dp[i][j]=0;
      }
    }
    dp[data[0]][0]++;
    for(int i=1;i<n;i++){
      for(int j=0;j<22;j++){
	if(dp[j][i-1]!=0){
	  int tmp;
	  tmp=j+data[i];
	  if(0<=tmp && tmp<=20){
	    dp[tmp][i]+=dp[j][i-1];
	  }
	  tmp=j-data[i];
	  if(0<=tmp && tmp<=20){
	    dp[tmp][i]+=dp[j][i-1];
	  }
	}
      }
    }
    

    cout << dp[data[n-1]][n-2] << endl;
  }
  return 0;
}

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

using namespace std;

const int N = 2e5 + 5;
long long m, n, a[N];

main() {
  ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
  int x, y, z;
  cin >> x >> y >> z;
  cout << z << ' ' << x << ' ' << y;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>

using namespace std;

#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define REP(i,N) for(long long i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define fi first
#define se second

#define PI acos(-1.0)
#define INF 1000000007
#define MAX_N 5001
#define EPS 1e-10

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<string, ll> PS;
typedef vector<ll> V;

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>

using namespace std;

#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define REP(i,N) for(long long i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define fi first
#define se second

#define PI acos(-1.0)
#define INF 1000000007

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<double, double> PD;
typedef pair<string, ll> PS;
typedef vector<ll> V;

string f[10];

int main(){
	while (cin >> f[0]){
		FOR(i, 1, 8){
			cin >> f[i];
		}
		REP(i, 8){
			REP(j, 8){
				if (f[i][j] == '1'){
					if (i+3<8&&f[i + 3][j] == '1'){
						cout << 'B' << endl;
					}
					if (j+3<8&&f[i][j + 3] == '1'){
						cout << 'C' << endl;
					}
					if (i + 2 < 8 && j - 1 >= 0 && f[i + 2][j - 1] == '1'){
						cout << 'D' << endl;
					}
					if (i + 2 < 8 && j + 1 < 8 && f[i + 2][j + 1] == '1'){
						cout << 'F' << endl;
					}
					if (i + 1 < 8 && j + 1 < 8 &&
						f[i + 1][j] == '1'&&f[i][j + 1] == '1'&&f[i + 1][j + 1] == '1'){
						cout << 'A' << endl;
					}
					if (i + 1 < 8 && j + 2 < 8 && f[i + 1][j + 2] == '1'){
						cout << 'E' << endl;
					}
					if (i + 1 < 8 && j - 1 >= 0 && j + 1 < 8 &&
						f[i + 1][j - 1] == '1'&&f[i][j + 1] == '1'){
						cout << 'G' << endl;
					}
					break;
				}
			}
		}
	}
}

Measured memory_bytes: 1176
import java.util.*;
import java.io.*;
import static java.lang.Math.*;

public class Main {
    public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		
		// 入力
		int n = sc.nextInt();
		
		// 計算
		long result = 0;
		long t = 0;
		long a = 0;
		for(int i = 0; i < n; i++){
		    long nt = sc.nextLong();
		    long na = sc.nextLong();
		    long tempt = nt;
		    long tempa = na;
		    long l = 0;
		    long r = 1000000000000000000L/max(nt, na);
		    while(r-l > 1){
		        long c = (l+r)/2;
		        tempt = nt*c;
		        tempa = na*c;
		        if(t > tempt || a > tempa){
		            l = c;
		        }else{
		            r = c;
		        }
		    }
		    t = nt*r;
		    a = na*r;
		}
		result = t + a;
		
		// 出力
		System.out.println(result);
	}
	
	public static class Scanner {
		private BufferedReader br; private StringTokenizer tok;
		public Scanner(InputStream is) throws IOException { br = new BufferedReader(new InputStreamReader(is));}
		private void getLine() throws IOException { while(!hasNext()) tok = new StringTokenizer(br.readLine());}
		private boolean hasNext() { return tok != null && tok.hasMoreTokens();}
		public String next() throws IOException { getLine(); return tok.nextToken();}
		public int nextInt() throws IOException { return Integer.parseInt(next());}
		public long nextLong() throws IOException { return Long.parseLong(next());}
		public double nextDouble() throws IOException { return Double.parseDouble(next());}
	}
}


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


int main(){
  ll n,k,b;
  b = 0;
  cin >> n >> k;
  vector<ll> H(n);
  rep(i,n) cin >> H[i];
  sort(H.begin(),H.end());
  rep(i,n-k) b += H[i];
  cout << b << endl;  
  return 0;
}


Measured memory_bytes: 1792