akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define ll long long int 
int main()
{
    ll n;
    cin >> n;
    vector<ll> arr(n);
    vector<ll> pref(n);
    for(ll i=0;i<n;i++)
    {
        cin >> arr[i];
    }
    ll sum=0;
    for(ll i=n-1;i>=0;i--)
    {
        sum+=arr[i];
        pref[i]=sum;
    }
    ll ans=0;
    ll p=1000000007;
    for(ll i=0;i<n;i++)
    {
        ans+=((pref[i]-arr[i])%p *(arr[i]))%p;
        ans%=p;

    }
    cout << (ans%p);
}


Measured memory_bytes: 6420
// 

#include <iostream>
#include <cmath>
#include <vector>
#include <algorithm>
#include <unordered_map>
#include <ios>
#include <iomanip>
#include <string>
#include <numeric>

using namespace std;
int K, X;
int main() {
    cin >> K >> X;

    for (int i = X - K + 1; i < K + X; i++) {
        if (i == K + X - 1) {
            cout << i << endl;
        } else {
            cout << i << " ";
        }
        
    }

    return 0;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-

# input
N = int(input())
V = list(map(int, input().split()))
C = list(map(int, input().split()))

# solve
ans = 0
for i in range(N):
    diff = V[i] - C[i]
    if diff > 0:
        ans += diff

# output
print(ans)


Measured memory_bytes: 3060
#include <stdio.h>
#define WIDTH_MAX 10
#define HEIGHT_MAX 30

char amida[HEIGHT_MAX][WIDTH_MAX + 1];
int height, width, goal, start;

int check()
{
    int x, y;

    for(y = 0, x = start; y < height; y++)
    {
        if(x < width && amida[y][x] == '1')
            x++;
        else if(x > 0 && amida[y][x - 1] == '1')
            x--;
    }

    return x == goal;
}

int main(void)
{
    int x, y;

  next:

    while(scanf("%d", &width), width)
    {
        scanf("%d %d %d%*c", &start, &goal, &height);
        start--, goal--;       /* start and goal are given 1-origin */

        for(y = 0; y < height; y++)
            gets(amida[y]);

        if(check())
        {
            puts("0");
            goto next;
        }

        for(y = 0; y < height; y++)
            for(x = 0; x < width; x++)
                if(amida[y][x] != '1'
                   && (x == 0 || amida[y][x - 1] != '1')
                   && (x == width - 1 || amida[y][x + 1] != '1'))
                {
                    amida[y][x] = '1';
                    if(check())
                    {
                        /* bias to make it 1-origin */
                        printf("%d %d\n", y + 1, x + 1);
                        goto next;
                    }
                    amida[y][x] = '0';
                }

        puts("1");
    }

    return 0;
}

Measured memory_bytes: 612
#include<bits/stdc++.h>
using namespace std;
#define LL long long
#define C(n,m) ((LL)fac[n]*ifac[m]%mo*ifac[(n)-(m)]%mo)

const int maxn=2010;
const int mo=1e9+7;
const int N=4000000;

int n,k,dp[maxn][maxn];
int fac[maxn*maxn],ifac[maxn*maxn];

int power(int x,int k)
{
	int res=1;
	while (k)
	{
		if (k&1) res=(LL)res*x%mo;
		x=(LL)x*x%mo;
		k>>=1;
	}
	return res;
}

int main()
{
#ifdef h10
	freopen("F.in","r",stdin);
	freopen("F.out","w",stdout);
#endif
	int i,j;
	fac[0]=1;
	for (i=1;i<=N;i++)
		fac[i]=(LL)fac[i-1]*i%mo;
	ifac[N]=power(fac[N],mo-2);
	for (i=N;i>=1;i--)
		ifac[i-1]=(LL)ifac[i]*i%mo;
	scanf("%d%d",&n,&k);
	if (k==1) {puts("1"); return 0;}
	dp[0][0]=1;
	for (i=0;i<=n;i++)
	for (j=0;j<=n;j++)
		if (dp[i][j])
		{
			(dp[i+1][j]+=dp[i][j])%=mo;
			if (i>j)
				(dp[i][j+1]+=(LL)dp[i][j]*C((n-j)*k-i+j-1,k-2)%mo)%=mo;
		}
	printf("%lld\n",(LL)dp[n][n]*fac[n]%mo);
}


Measured memory_bytes: 47488
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,k,n) for(int i = (k); i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) begin(a),end(a)
#define MS(m,v) memset(m,v,sizeof(m))
#define D10  fixed<<setprecision(3)
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int, int> P;
typedef complex<double> Point;
typedef long long ll;
const int INF = 114514810;
const int MOD = 1000000007;
const double EPS = 1e-8;
const double PI = acos(-1.0);
struct edge
{
	int from, to;
	double cost;
	bool operator < (const edge& e) const { return cost < e.cost; }
	bool operator >(const edge& e) const { return cost > e.cost; }
};
///*************************************************************************************///
///*************************************************************************************///
///*************************************************************************************///

struct a
{
	double x, y, z, r;
};
vector<a> v;
int par[105];
vector<edge> es;

int find(int x)
{
	if (par[x] == x) return x;
	else return par[x] = find(par[x]);
}

void unite(int x, int y)
{
	x = find(x); y = find(y);
	if (x == y) return;
	par[y] = x;
}

bool same(int x, int y)
{
	return find(x) == find(y);
}

void init_UFT(int n)
{
	REP(i, n)
	{
		par[i] = i;
	}
}



int main()
{
	int n;
	while (cin >> n, n)
	{
		v.clear();
		REP(i, n)
		{
			double x, y, z, r;
			cin >> x >> y >> z >> r;
			v.push_back(a{ x, y, z, r });
		}
		es.clear();
		init_UFT(n);
		REP(i, n)FOR(j, i + 1, n)
		{
			double dif = sqrt(pow((v[i].x - v[j].x), 2) + pow((v[i].y - v[j].y), 2) + pow((v[i].z - v[j].z), 2)) - v[i].r - v[j].r;
			if (dif > 0)
			{
				es.push_back(edge{ i, j, dif });
			}
			else
			{
				unite(i, j);
			}
		}

		sort(ALL(es));
		double sum = 0;
		REP(i, es.size())
		{
			if (!same(par[es[i].from], par[es[i].to]))
			{
				unite(es[i].from, es[i].to);
				sum += es[i].cost;
			}
		}
		cout << D10 << sum << endl;
	}
	return 0;
}

Measured memory_bytes: 1448
#include <cstdio>
#include <bits/stdc++.h>
#include <algorithm>
#include <iostream>
#include <string>
#include <cmath>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#define rep(i,n) for (int i=0;i<n;i++)
using ll = long long;
using namespace std;

void solve(){

}
int main (){
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    int ans=10000000;
    rep(i,n){
        int sum1=0,sum2=0;
        rep(j,i+1){
            sum1+=a[j];
        }
        for(int k=i+1;k<n;k++){
            sum2+=a[k];
        }
        ans=min(ans,abs(sum2-sum1));
    }
    cout << ans;

    return 0;
}

Measured memory_bytes: 256
#line 2 "../../library/template.hpp"
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pl = pair<ll, ll>;
using vl = vector<ll>;
#define rep(i, n) for(ll i = 0; i < (ll)n; i++)
#define rep3(i, l, r) for(ll i = l; i < (ll)r; i++)
#define per(i, n) for(ll i = (ll)n-1; i >= 0; i--)
#define per3(i, l, r) for(ll i = (ll)r-1; i >= (ll)l; i--)
#define all(v) begin(v), end(v)
template<class T, class U> inline void cmax(T& a, U b) { if (a < b) a = b; }
template<class T, class U> inline void cmin(T& a, U b) { if (a > b) a = b; }
constexpr char el = '\n';
template<class T, class U> ostream &operator<<(ostream &os, const pair<T, U>& p) { os << p.first << " " << p.second; return os; }
template<class T, class U> istream &operator>>(istream &is, pair<T, U> &p) { is >> p.first >> p.second; return is; }
template<class T> ostream &operator<<(ostream &os, const vector< T > &v) { rep(i, v.size()) os << v[i] << (i + 1 != v.size() ? " " : ""); return os; }
template<class T> istream &operator>>(istream &is, vector< T > &v) { for(T &in : v) is >> in; return is; }
struct IoSetup {
  IoSetup() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); cerr << fixed << setprecision(15); }
} io_setup;
#line 2 "a2.cpp"

int main() {
  string s, t, u;
  ll a, b;
  cin >> s >> t >> a >> b >> u;

  if (s == u) {
    a--;
  } else {
    b--;
  }

  cout << a << " " << b << el;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
    string s;
    cin>>s;
    int n=s.size();
    int i;
    int ans=0;
    int j,k;
    for(i=0;i<n;i++)
    {
        for(j=i;j<n;j++)
        {
            int flag=0;
            string r=s.substr(i,j-i+1);
            for(k=0;k<r.size();k++)
            {
                if(r[k]!='A'&&r[k]!='T'&&r[k]!='G'&&r[k]!='C')
                {
                    flag=1;
                }
            }
            if(flag==0)
            {
                ans=max(ans,j-i+1);
            }
        }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <cstdio>

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

using namespace std;

int main(){
	int p[]={6000,4000,3000,2000};
	rep(_,4){
		int a,b; scanf("%d%d",&a,&b);
		printf("%d\n",p[a-1]*b);
	}
	return 0;
}

Measured memory_bytes: 1028
import sys
#import numpy as np
import math
#from fractions import Fraction
#import itertools
from collections import deque
#import heapq
from fractions  import gcd

input=sys.stdin.readline
n,a,b=map(int,input().split())
v=list(map(int,input().split()))
v.sort(reverse=True)
ans=sum(v[:a])/a
print(ans)
res=0
r1=r2=0
def comb(n,r):
    return math.factorial(n)//(math.factorial(n-r)*math.factorial(r))

if v[a-1]==v[0]:
    for i in v:
        if i==v[0]:
            r2+=1
    for j in range(a,b+1):
        if j>r2:
            break
        res+=comb(r2,j)
    print(res)
else:   
    f=False
    first=0
    for i in range(n):
        if v[i]==v[a-1]:
            r1+=1
            if not f:
                first=i
            f=True
        elif v[i]<v[a-1]:
            break
    numa=a-first
    res+=comb(r1,numa)
    print(res)

Measured memory_bytes: 64364
#include <stdio.h>

int main(){

  int a[2];
  int k;
  int i,j;
  int max,tmp;
  int N;
  scanf("%d %d %d",&a[0],&a[1],&a[2]);
  scanf("%d",&k);

  max = 0;
  N = 0;

  if(a[max] < a[1]) max = 1;
  if(a[max] < a[2]) max = 2;

  tmp = a[max];

  for(i=0;i<3;i++){
    if(i == max){
      for(j=0;j<k;j++){
        tmp = tmp*2;
      }
    }
    else{
      N = N + a[i];
    }
  }
  N = N + tmp;

  printf("%d",N);

  return 0;
}

Measured memory_bytes: 128
#include <algorithm>
#include <iostream>
#include <string>
#include <random>
#include <cassert>
#include <cstring>
#include <chrono>

using namespace std;

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

  vector<vector<int>> components;

  int l = 1;
  int r = n - n % 2;
  while (l < r) {
    components.push_back({l, r});
    l++;
    r--;
  }

  if (n % 2 == 1) {
    components.push_back({n});
  }

  vector<pair<int, int>> result;
  for (int i = 0; i < components.size(); ++i) {
    if (i == components.size() -1 && components.size() == 2) continue;
    auto c1 = components[i];
    auto c2 = components[(i + 1) % components.size()];
    for (int u : c1) for (int v : c2) {
      result.push_back({u, v});
    }
  }
  cout << result.size() << endl;
  for (auto p : result) {
    cout << p.first << " " << p.second << endl;
  }

  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int s = sc.nextInt();
        int h = s/3600;
        int m = (s%3600)/60;
        s = (s%3600)%60;
        System.out.println(h+":"+m+":"+s);
    }
}


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

long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

ll gcd(ll a,ll b){
  while(b!=0){
    a%=b;
    swap(a,b);
  }
  return a;
}

ll kaizyou(ll N){
  ll num=1;
  for(ll i=1;i<=N;i++){
  num*=i;
  }
  return num;
}

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

ll mod=1e9+7;

int main(){
  string S;
  cin >> S;
  int Q;
  cin >> Q;
  int num=0;
  rep(i,Q){
    int a;
    cin >> a;
    if(a==1){
      num++;
    }
    if(a==2){
      if(num%2==0){
      int f;
      string c;
      cin >> f >> c;
      if(f==1){
        S.insert(0,c);
      }
      if(f==2){
        S+=c;
      }
      }
      else{
        int f;
      string c;
      cin >> f >> c;
      if(f==2){
        S.insert(0,c);
      }
      if(f==1){
        S+=c;
      }
      }
    }
  }
  if(num%2==1){
    reverse(S.begin(),S.end());
  }
  cout << S << endl;
}
      
  
  
  

Measured memory_bytes: 900
#include <bits/stdc++.h>
#define LOOP(n) for (int _i = 0; _i < (n); _i++)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define RREP(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, r, n) for (int i = (r); i < (n); ++i)
#define ALL(obj) begin(obj), end(obj)
using namespace std;
using ll = long long;
const int INF = 1000100100;

template <class T>
bool chmin(T &a, const T &b) {
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}

int V, E;
int G[20][20];  // グラフ
int dp[50000][20];

int rec(int S, int v) {  // メモ化再帰
    if (S == 0) {
        if (v == 0) {
            return 0;
        } else {
            return INF;
        }
    }
    if ((S & (1 << v)) == 0) {
        return INF;
    }

    int &ret = dp[S][v];
    if (ret != 0) return ret;

    ret = INF;
    REP(u, V) { chmin(ret, rec(S ^ (1 << v), u) + G[u][v]); }
    return ret;
}

int main() {
    cin >> V >> E;

    // グラフの初期化
    REP(i, 20) {
        REP(j, 20) { G[i][j] = INF; }
    }
    REP(i, E) {
        int s, t, d;
        cin >> s >> t >> d;
        G[s][t] = d;
    }

    int ans = rec((1 << V) - 1, 0);

    if (ans != INF) {
        cout << ans << endl;
    } else {
        cout << -1 << endl;
    }

    return 0;
}



Measured memory_bytes: 5644
#include<stdio.h>
#include<math.h>
#include<string.h>

int main()
{
	int N, K;
	scanf("%d %d", &N, &K);
	
	int d[K];
	int r;
	int t;
	int C[N];
	int M[N];
	
	for(r=0; r<N; r++) M[r] = 0;
	
	for(r=0; r<K; r++){
		scanf("%d", &d[r]);
		for(t=0; t<d[r]; t++){
			scanf("%d", &C[t]);
			M[C[t]-1] = 1;
		}
	}
	
	t = 0;
	
	for(r=0; r<N; r++){
		if(M[r]==0) t++;
	}
	
	printf("%d", t);		
	
	return 0;
	
}


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

#define lint long long
#define P pair<int, int>
#define LLP pair<long long, long long>
#define REP(i, x, n) for(int i = (x), i##_len = (int)(n) ; i < i##_len ; ++i)
#define rep(i, n) for(int i = 0, i##_len = (int)(n) ; i < i##_len ; ++i)
#define reps(i, n) for(int i = 1, i##_len = (int)(n) ; i <= i##_len ; ++i)
#define rrep(i, n) for(int i = (int)(n) - 1 ; i >= 0 ; --i)
#define rreps(i, n) for(int i = (int)(n) ; i > 0 ; --i)
#define SORT(x) sort((x).begin(), (x).end())
#define SORT_INV(x) sort((x).rbegin(), (x).rend())

const int IINF = (1 << 30) - 1;
const long long LLINF = 1LL << 61;
const long long MOD = 1000000007LL;
const int dx4[] = {1, 0, -1, 0}, dy4[] = {0, 1, 0, -1};
const int dx8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dy8[] = {0, -1, -1, -1, 0, 1, 1, 1};
const double EPS = 1e-8;

template<typename T>
bool chmax(T &_a, T _b){
    if(_a < _b){
        _a = _b;
        return true;
    }else{
        return false;
    }
}

void dfs(int v, int depth, vector<int> &cost, const vector< vector<int> > &g){
    cost[v] = depth;
    for(auto e : g[v]){
        if(cost[e] > depth + 1){
            dfs(e, depth + 1, cost, g);
        }
    }
    return;
}

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

    int n;
    cin >> n;

    vector< vector<int> > g(n);
    rep(i, n - 1){
        int a, b;
        cin >> a >> b;
        --a;
        --b;
        g[a].emplace_back(b);
        g[b].emplace_back(a);
    }

    vector<int> cost(n, IINF);
    dfs(0, 0, cost, g);

    int ma = 0, md = 0;
    rep(i, n){
        if(chmax(ma, cost[i])){
            md = i;
        }
    }

    fill(cost.begin(), cost.end(), IINF);
    dfs(md, 0, cost, g);

    rep(i, n){
        chmax(ma, cost[i]);
    }

    if(ma % 3 == 1){
        cout << "Second" << endl;
    }else{
        cout << "First" << endl;
    }

    return 0;
}

Measured memory_bytes: 21376
#include <bits/stdc++.h>
using namespace std;
 
#define fo(i,n) for(i=0;i<n;i++)
#define Fo(i,k,n) for(i=k;i<n;i++)
#define ll long long
 
#define pi pair < ll , ll >
#define pb push_back
#define mp make_pair
#define F first
#define S second
 
#define fastIO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
 
#define debug(x) cout<<#x<<" :: "<<x<<"\n";
#define debug2(x,y) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\n";
#define debug3(x,y,z) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\t"<<#z<<" :: "<<z<<"\n";
using namespace std;

const ll mod = 1e9+7;

void solve() {
    ll s, w;
    cin>>s>>w;
    if(w>=s)cout<<"unsafe";
    else cout<<"safe";
}

int main()
{
    fastIO;ll t=1;
    // cin>>t;
    while(t--)solve();
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main() {
    int n;
    cin >> n;
    int a[n];
    for(int i=0;i<n;++i) cin >> a[i];
    int cnt=0;
    int res=10000000;
    for(int i=0;i<n;++i) {
      res=min(res,a[i]);
      if(a[i]<=res) ++cnt;
    }
    cout << cnt << endl;
}



Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=1e5+10;
int a[110];
int main()
{
    int n;
    scanf("%d",&n);
    int sum=0;
    for(int i=0;i<n;i++)
    {
        scanf("%d",&a[i]);
        sum+=a[i];
    }
    double aver=sum*1.0/n;
    int res;
    double flag=1e9;
    for(int i=0;i<n;i++)
    {
        if(abs(aver-a[i])<flag)
        {
            flag=abs(aver-a[i]);
            res=i;
        }
    }
    printf("%d\n",res);
}


Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Scanner;
import java.util.TreeMap;

public class Main {

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

        // キー集合のID、バリュー鍵の値段
        Map<Integer, Integer> keyInfo = new TreeMap<>();
        for (int i = 0; i < m; i++) {
            int price = sc.nextInt();
            int keyNum = sc.nextInt();
            int keyInfoID = 0;
            for (int j = 0; j < keyNum; j++) {
                int openNo = sc.nextInt();
                openNo--; // 1-indexed;
                keyInfoID |= 1 << openNo;
            }

            // 集合が被った場合はコストが安い方を採用する
            if (price < keyInfo.getOrDefault(keyInfoID, Integer.MAX_VALUE)) {
                keyInfo.put(keyInfoID, price);
            }
        }

        // DP用意と初期化
        int[] dp = new int[1 << n]; // 2^n;
        Arrays.fill(dp, 1001001001);
        dp[0] = 0;

        for (int s = 0; s < 1 << n; s++) {
            for (Entry<Integer, Integer> ent : keyInfo.entrySet()) {
                int t = s | ent.getKey();
                int cost = dp[s] + ent.getValue();
                dp[t] = Math.min(cost, dp[t]);
            }
        }

        // 組み合わせが存在しない場合は-1
        int ans = dp[(1 << n) - 1];
        if (ans == 1001001001) {
            System.out.println(-1);
        } else {
            System.out.println(ans);
        }
    }
}


Measured memory_bytes: 36720
#include<iostream>
using namespace std;
int sum(int x){
 	int ret = 0;
  	while(x){
     	ret += x % 10;
       	x /= 10;
    }
  	return ret;
}
int main(){
 	int n, a, b; cin >> n >> a >> b;
  	int ans = 0;
  	for(int i = 1; i <= n; ++i){
		int x = sum(i);
      	if(x <= b && x >= a) ans += i; 
    }
  	cout << ans << endl;
  	return 0;
}

Measured memory_bytes: 256
use std::cmp::*;
use std::collections::BTreeSet;
use std::io::*;
use std::str::FromStr;
//portable utility
#[allow(dead_code)]
fn switch<T>(flag: bool, true_value: T, false_value: T) -> T {
    if flag {
        true_value
    } else {
        false_value
    }
}
#[allow(dead_code)]
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}
#[allow(dead_code)]
fn read_string() -> Vec<char> {
    read::<String>().chars().collect()
}
#[allow(dead_code)]
fn read_vector<T: FromStr>(number: i32) -> Vec<T> {
    (0..number).map(|_| read()).collect()
}
fn main() {
    let number: i64 = read();
    let sum: i64 = (1..=number)
        .into_iter()
        .filter(|&n| n % 5 != 0 && n % 3 != 0)
        .sum();
    println!("{}", sum);
}


Measured memory_bytes: 2136
N = int(input())
S = input()

R_cnt = S.count("R")
G_cnt = S.count("G")
B_cnt = S.count("B")
cnt = 0
for i in range(N):
    for j in range(i+1, N):
        if S[i] != S[j] and ((2*j - i) < N):
            if S[2*j - i] != S[i] and S[2*j - i] != S[j]:
                cnt += 1

print(R_cnt*G_cnt*B_cnt-cnt)

Measured memory_bytes: 9208
#include <algorithm>
#include <functional>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <bitset>
#include <climits>

#define all(c) (c).begin(), (c).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define pb(e) push_back(e)
#define mp(a, b) make_pair(a, b)
#define fr first
#define sc second

const int INF=100000000;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
using namespace std;
typedef pair<int ,int > P;
typedef long long ll;

struct RollingHash {
    typedef long long int_type;
    typedef pair<int_type,int_type> hash_type;

    int_type base1;
    int_type base2;
    int_type mod1;
    int_type mod2;
    vector<int_type> hash1;
    vector<int_type> hash2;
    vector<int_type> pow1;
    vector<int_type> pow2;

    RollingHash() : base1(1009), base2(1007), mod1(1000000007), mod2(1000000009) {}

    void init(const string &s) {
        int n = s.size();

        hash1.assign(n+1,0);
        hash2.assign(n+1,0);
        pow1.assign(n+1,1);
        pow2.assign(n+1,1);

        for(int i=0;i<n;i++) {
            hash1[i+1] = (hash1[i]+s[i]) * base1 % mod1;
            hash2[i+1] = (hash2[i]+s[i]) * base2 % mod2;
            pow1[i+1] = pow1[i] * base1 % mod1;
            pow2[i+1] = pow2[i] * base2 % mod2;
        }
    }

    hash_type get(int l,int r) {
        int_type t1 = ((hash1[r] - hash1[l] * pow1[r-l]) % mod1 + mod1) % mod1;
        int_type t2 = ((hash2[r] - hash2[l] * pow2[r-l]) % mod2 + mod2) % mod2;
        return make_pair(t1, t2);
    }

    RollingHash::hash_type concat(hash_type h1, hash_type h2, int h2_len) {
        return make_pair((h1.fr*pow1[h2_len]+h2.fr)%mod1, (h1.sc*pow2[h2_len]+h2.sc)%mod2);
    }

};

int n;
set<RollingHash::hash_type> S;

int main() {
    ios::sync_with_stdio(false);
    cin>>n;
    RollingHash rh;
    while(n--) {
        string q,s;
        cin>>q>>s;
        rh.init(s);
        RollingHash::hash_type hash = rh.get(0,s.size());
        if(q=="insert") {
            S.insert(hash);
        }
        else {
            if(S.count(hash)) cout<<"yes"<<endl;
            else cout<<"no"<<endl;
        }
    }
    return 0;
}

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

vector<int> graph[100];
int start[100],endt[100];
int cnt;

void dfs(int num){
	start[num] = ++cnt;
	for(int i = 0;i < graph[num].size();i++){
		if(graph[num][i] != num && !start[graph[num][i]] && !endt[graph[num][i]]) dfs(graph[num][i]);
	}
	endt[num] = ++cnt;
}

int main(){
	int n;
	cin >> n;
	for(int i = 0;i < n;i++){
		int now,m;
		cin >> now >> m;
		for(int j = 0;j < m;j++){
			int t;
			cin >> t;
			graph[now - 1].push_back(t - 1);
		}
	}
	dfs(0);
	for(int i = 0;i < n;i++){
		if(!endt[i]) dfs(i);
	}
	for(int i = 0;i < n;i++){
		cout << i + 1 << " " << start[i] << " " << endt[i] << endl;
	}
	return 0;
}

Measured memory_bytes: 3120
#include<iostream>
#include<algorithm>
#include<functional>
#include<cmath>
#include<string>
#include<vector>
using namespace std;
const int mod = 1000000007;
#define ll long long

int main()
{
	string S, T;
	cin >> S >> T;
	bool f = true;
	string ans;
	for (int i = 0; i < S.size() - T.size() + 1; i++) {
		string tmp = S;
		f = true;
		for (int j = 0; j < T.size(); j++) {
			if (S[i + j] == '?' || S[i + j] == T[j]) {
				tmp[i + j] = T[j];
			}
			else {
				f = false;
				break;
			}
		}
		if (f) {
			for (int j = 0; j < tmp.size(); j++) {
				if (tmp[j] == '?') tmp[j] = 'a';
			}
			if (ans.empty() || tmp < ans) {
				ans = tmp;
			}
		}
	}
	if (ans.empty()) {
		cout << "UNRESTORABLE" << endl;
	}
	else {
		cout << ans << endl;
	}
}

Measured memory_bytes: 256
#include <stdio.h>
#include <algorithm>
#include <vector>
using namespace std;
int main(void) {
	int n, l; scanf("%d %d", &n, &l);
	int orig = n * (2 * l + n - 1) / 2;
	int b = l + (n - 1);
	int a = l;
	if (a <= 0 && 0 <= b) return !printf("%d\n", orig);
	else if (b < 0) return !printf("%d\n", orig - b);
	else return !printf("%d\n", orig - a);
}

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

using namespace std;

typedef long long ll;
typedef vector<ll> vl;
typedef long double ld;
typedef vector<ld> vd;
typedef bool bl;
typedef vector<bl> vb;
typedef unordered_map<ll,unordered_map<ll,ll>> graph;

const ll e5 = 1 << 20;
const ll mod = 1000000007;
const ll e3 = 1 << 13;
const ll INF = 1ll << 60;

ll n,k;

ll factorial(ll n,ll mod = mod){
  static ll dp[100000];
  if(dp[n]) return dp[n];
  if(n == 0) return dp[n] = 1;
  return dp[n] = (n*factorial(n-1))%mod;
}

ll powl(ll x,ll r,ll mod = mod){
  ll ret = 1;
  for(;r != 0;r >>= 1){
    if(r&1 != 0) ret *= x,ret %= mod;
    x *= x,x %= mod;
  }
  return ret;
}

ll inverse(ll x,ll mod = mod){
  return powl(x,mod-2,mod);
}

ll combination(ll n,ll m,ll mod = mod){
  if(n < m) return 0;
  return (((factorial(n)*inverse(factorial(m)))%mod)*inverse(factorial(n-m)))%mod;
}

int main(){
  cin >> n >> k;
  for(ll i = 1;i <= k;i++){
    cout << ((combination((n-k)+1,i)*combination(k-1,i-1))%mod) << endl;
  }

}


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

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

  int ans = 0;
  char pre = 0;
  for(int i=0;i<n;i++){
    if(pre == 'x' && str[i] == 'x') break;
    ans++;
    pre = str[i];
  }
  cout<<ans<<endl;
  
}

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

int p[10] = {0, 0, 0, 0, 0, 0, 1, 1, 1, 2};
int q[10] = {1, 1, 1, 2, 2, 3, 2, 2, 3, 3};
int r[10] = {2, 3, 4, 3, 4, 4, 3, 4, 4, 4};

int main () {
  int n;
  scanf("%d",&n);
  vector<ll> x(5);
  rep(i, n) {
    string s;
    cin >> s;
    if (s[0]=='M') x[0]++;
    if (s[0]=='A') x[1]++;
    if (s[0]=='R') x[2]++;
    if (s[0]=='C') x[3]++;
    if (s[0]=='H') x[4]++;
  }
  ll ans = 0;
  rep(i, 10) ans += x[p[i]]*x[q[i]]*x[r[i]];
  printf("%lld\n", ans);
}


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

int main(){
	int N, K, i, j, k;
	K = 38;
	N = K * (K - 1) + 1;
	int **A = (int **)malloc(sizeof(int *) * (K - 1));
	for(i = 0; i < K - 1; i++){
		A[i] = (int *)malloc(sizeof(int) * K);
		for(j = 0; j < K; j++){
			A[i][j] = K * i + j + 1;
		}
	}
	printf("%d %d\n", N, K);
	for(j = 0; j < K; j++){
		for(i = 0; i < K - 1; i++){
			printf("%d ", A[i][j]);
		}
		printf("%d\n", N);
	}
	for(k = 0; k < K - 1; k++){
		for(i = 0; i < K - 1; i++){
			for(j = 1; j < K; j++){
				printf("%d ", A[(i + k * j) % (K - 1)][j]);
			}
			printf("%d\n", A[k][0]);
		}
	}
	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define LL long long 
#define LLU long long unsigned
#define rarr(arr, n) for(int aab = 0; aab < n; aab++){cin >> arr[aab];}
#define parr(arr, n) for(int aab = 0; aab < n; aab++){cout << arr[aab] << " ";}
#define pb push_back
#define f first
#define s second
#define all(x) x.begin(), x.end()
#define debug(x) cout << #x << " = " << x << "\n";

#define freopen freopen("in.txt", "r", stdin);freopen("out.txt", "w", stdout);ios_base::sync_with_stdio(0);cin.tie(0);

int main(){
	int a, b;
	cin >> a >> b;
	cout << a * b;
} 

Measured memory_bytes: 3676
#include <iostream>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <sstream>
#include <limits.h>
#include <stdio.h>
using namespace std;
 
int main()
{
    std::string s,t;
    cin >>s>>t;
    
    int sizes = s.size();
    int sizet = t.size();
    int minswap = sizes;
    for(int i=0; i<sizes-sizet+1; i++){
        int cnt = 0;
        
        for(int j=0; j<sizet; j++){
            //cout << s[i+j] << ":" << t[j] << endl;
            if(s[i+j] == t[j]){
               
            }else{
                cnt++;
            }
        }
        //cout << "--- " << cnt << endl;
        if(minswap > cnt ) minswap = cnt;
    }

    cout << minswap << endl;
    

    return 0;
}

Measured memory_bytes: 3620
N,M,K=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
a_s=[0]
b_s=[0]
for i in range(N):
  if a_s[i]+a[i]>K:
    break
  a_s.append(a[i]+a_s[i])
for i in range(M):
  if b_s[i]+b[i]>K:
    break
  b_s.append(b[i]+b_s[i])
bn=len(b_s)-1
ans=0
for i in range(len(a_s)):
  while a_s[i]+b_s[bn]>K:
    bn-=1
  ans=max(ans,i+bn)
  
print(ans)

Measured memory_bytes: 40748
a = int(input())
b = int(input())
c = int(input())
x = int(input())

ans = 0
for i_a in range(a + 1):
  for j_b in range(b + 1):
    for k_c in range(c + 1):
      sum = 500 * i_a + 100 * j_b + 50 * k_c
      if sum == x:
        ans += 1

print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define ALL(v) (v).begin(), (v).end()

using namespace std;
using ll = long long;

int main()
{
  string S; cin >> S;
  string E = "AKIHABARA";

  if (E != S and S.size() >= E.size()) {
    cout << "NO" << endl;
    return 0;
  }

  for (int i = 0; i < E.size(); ++i) {
    // printf("%s %d %d\n", S.c_str(), i, S.size());
    // cout << "E[i]: " << E[i] << endl;
    if ((i < S.size() and S[i] != E[i]) or (i == S.size())) {
      if (E[i] == 'A') S.insert(i, "A");

    } else if (i < S.size() and S[i] == E[i]) {
      continue;
    } else {
      break;
    }
  }

  if (S != E) {
    cout << "NO" << endl;
  } else {
    cout << "YES" << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long int
using namespace std;
int main()
{
    ll q;
    cin>>q;
    ll ans=0;
    ll cnt=0;
    multiset<ll> s;
    set<ll> ::iterator it;
    ll count=0;
    ll k=0;
    map<ll,ll>mm;

    ll x;
    while (q--)
    {
        ll z;
        cin>>z;
        if(z==1)
        {
            ll a,b;
            cin>>a>>b;
            count++;
            s.insert(a);
            ans+=b;
            if(count==1)
            {
                it=s.begin();
                x=*it;
            }
            else
            {
                ll zz=x;
                if (count%2==0 && a<x)
                {
                    x=*(--it);
                    ans+=abs(zz-x);
                }
                else if(count%2==1 && a>=x)
                {
                    x=*(++it);
                }
                ans+=abs(a-x);
            }

        }

        else
        {
            if (count==0)
                cout<<0<<endl;
            else
            cout<<x<<" "<<ans<<endl;
        }
    }
}

Measured memory_bytes: 9600
package main

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

var sc = bufio.NewScanner(os.Stdin)

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return i
}

func nextFloat64() float64 {
	f, _ := strconv.ParseFloat(next(), 64)
	return f
}

func nextInts(n int) []int {
	slice := make([]int, n)
	for i := 0; i < n; i++ {
		slice[i] = nextInt()
	}
	return slice
}

func main() {
	sc.Split(bufio.ScanWords)
	a, b := nextInt(), nextInt()
	fmt.Println((a - 1) * (b - 1))
}


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

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

typedef long long ll;
typedef long long int64;

int main() {
  int a,p;
  cin >> a >> p;
  cout << floor((a * 3 + p)/2) << endl;

  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#define min(a,b)((a) < (b) ? (a) : (b))

int gcd(int, int);

int main(){
  int i,j;

  scanf("%d%d",&i,&j);

  if(i >= j){
    printf("%d\n",gcd(j,i % j));
  }

  if(i < j){
    printf("%d\n",gcd(i,j % i));
  }
      
  return 0;
}

int gcd(int a, int b){
  int n,d;
  
  n = min(a,b);
  
  for(d = n; d >= 1; d--){
    if(a % d == 0 && b % d == 0){
      return d;
    }   
  }
  return a;

}



Measured memory_bytes: 2144
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <sstream>
#include <algorithm>
#include <deque>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <list>
#include <cstdio>
#include <iostream>
#include <cmath>
#include <climits>
#include <bitset>
#include <functional>
#include <numeric>
#include <ctime>
#include <cassert>
#include <cstring>
#include <fstream>
#include <iomanip>

using namespace std;

#define FOR(i, a, b) for(int (i)=(a);(i)<(b);(i)++)
#define IFOR(i, a, b) for(int (i)=(a);(i)<=(b);(i)++)
#define RFOR(i, a, b) for(int (i)=(a);(i)>=(b);(i)--)
#define REP(i, n) FOR((i), 0, (n))

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

int main() {
    int n;
    cin >> n;
    vector<ll> a(n);

    REP(i, n){
        cin >> a[i];
    }
    sort(a.begin(), a.end());

    ll ans = 1;
    double ans2 = 1.0;
    REP(i, n){
        ans2 *= a[i];
        if(ans2 > 1e18){
            cout << -1 << endl;
            return 0;
        }
        ans *= a[i];

    }
    if(ans > 1000000000000000000LL){
        cout << -1 << endl;
        return 0;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3672
n = int(input())
a_lst = [int(elem) for elem in input().split()]
b_lst = [int(elem) for elem in input().split()]

res = 0
for i in range(n+1):
  if i == 0:
    res += min(a_lst[i], b_lst[i])
    if b_lst[i] > a_lst[i]:
      b_lst[i] -= a_lst[i]
    else:
      b_lst[i] = 0
  elif i == n:
    res += min(a_lst[i], b_lst[i-1])
    if b_lst[i-1] > a_lst[i]:
      b_lst[i-1] -= a_lst[i]
    else:
      b_lst[i-1] = 0    
  else:
    res += min((b_lst[i-1] + b_lst[i]), a_lst[i])
    if b_lst[i-1] > a_lst[i]:
      b_lst[i-1] -= a_lst[i]
    elif b_lst[i] > (a_lst[i] - b_lst[i-1]):
      b_lst[i] -= (a_lst[i] - b_lst[i-1])
      b_lst[i-1] = 0
    else:
      b_lst[i] = 0
print(res)

Measured memory_bytes: 18624
loop do
    l = gets.chomp
    break if l == ?0
    h = {?A => 0, ?B => 0}
    l.split("").each_cons(2) do |c1, c2|
        h[c1 == c2 ? c1 : c2] += 1
    end
    h[?A] > h[?B] ? h[?A] += 1 : h[?B] += 1
    puts h.values * ' '
end



Measured memory_bytes: 6856
n=gets.strip.split.map(&:to_i)

ans=[-1,-1,-1]
(0..n[0]).each do |i|
    (0..n[0]-i).each do |j|
            k=n[0]-i-j
            if 10000*i+5000*j+1000*k==n[1]
                ans[0]=i
                ans[1]=j
                ans[2]=k
                break
            
        end
    end
end

puts ans.join(' ')

Measured memory_bytes: 14392
n = int(input())
have_8_divisors = 0

for i in range(1, n + 1):

    # 偶数の時はスキップ
    if i % 2 == 0:
        continue
    cnt = 0
    for j in range(1, i + 1):
        if i % j == 0:
            cnt += 1

    result = cnt == 8
    if result:
        have_8_divisors += 1

print(have_8_divisors)

Measured memory_bytes: 9100
#include<iostream>
#include<map>
#include<cmath>
#include<vector>
#define MAX 30000
using namespace std;
vector<int> prime;
bool isntprime[30001];
typedef pair<int,int> P;
typedef pair<P,int> Pi;

bool isTriangle(int a,int b,int c)
{
  if(a >= b+c || b >= a+c || c >= a+b)
    return false;
  return true;
}

int main()
{
 
  isntprime[0] = isntprime[1] = true;
  int j;
  for(int i=2;i<= MAX;i++)if(!isntprime[i])for(prime.push_back(i),j=i*i;j<=MAX;j+=i)isntprime[j] = true;
 
  int T;
  while(cin >> T,T)
    {
      int cnt = 0;
      for(int i=0;i<prime.size() && prime[i] < T;i++)
	for(int j=i;j<prime.size() && prime[i]+prime[j] < T;j++)  
	  if(T-(prime[i]+prime[j]) >= prime[j] && !isntprime[T-(prime[i]+prime[j])] && isTriangle(prime[i],prime[j],T-(prime[i]+prime[j])))
	    cnt++;
	    
      cout << cnt << endl;
    }
  return 0;
}

Measured memory_bytes: 1276
#include<bits/stdc++.h>
#include<unordered_set>
#include<unordered_map>
using namespace std;
#define REP(i,m,n) for(int i=(m);i<(n);i++)
#define rep(i,n) REP(i,0,n)
#include<bits/stdc++.h>
#include<unordered_set>
#include<unordered_map>
using namespace std;
#define REP(i,m,n) for(int i=(m);i<(n);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define all(a) a.begin(),a.end()
#define rall(c) (c).rbegin(),(c).rend()
#define mp make_pair
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll inf=1e9+7;
const ll mod=998244353;
int main(){
    ll n;cin>>n;
    if(n%2){
        cout<<0<<endl;
        return 0;
    }
    ll cnt=0;
    n/=2;
    while(n){
        cnt+=n/5;
        n/=5;
    }
    cout<<cnt<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    char a[10];
    cin>>a;
    if(a[0]==a[1] && a[1]==a[2])
    {
        cout<<"No"<<endl;
    }
    else
    {
        cout<<"Yes"<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>

using namespace std ;

int n ;

int main ()
{
	int i ;
	int x ;
	int res=0;
	scanf("%d",&n);
	for ( i=1 ; i<=n ; i++ ) scanf("%d",&x),res+=x-1;
	printf("%d",res);
	return 0 ;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <utility>
#include <cmath>
#include <random>
#include <vector>
#include <tuple>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <string>
#include <algorithm>
using namespace std;

#define rep(i,n) for(int i = 0; i<n; ++i)
#define REP(i,n) for(int i = 1; i<=n; ++i)
#define all(x) begin(perm),end(perm)
#define showall(obj) for(auto x:obj)cout<<x<<' ';
typedef long long ll;
typedef pair<int,int> ip;
typedef pair<ll,ll> lp;
typedef vector<int> vint;
typedef vector<ll> vll;
const int inf = 100100100;
const ll INF = 1LL<<60;
const int MOD = (int)1e9 + 7;

int main(){
    int n; cin>>n;
    vint w(n); rep(i,n)cin>>w[i];
    vint s(n+1,0); rep(i,n)s[i+1] = s[i]+w[i];

    int ans = inf;
    int m= s[n];
    REP(i,n){
        ans = min(ans, abs(m-2*s[i]));
    }
    cout<<ans<<endl; return 0;
}

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

int main() {
 int N;
  cin >> N;
  vector<int> color(N);
  vector<int> kazu(8, 0);
  for(int i = 0; i < N; i++){
    cin >> color.at(i);
  }
  int count = 0;
  bool freedom = true;
  for(int i = 0; i < N; i++){
    if(color.at(i) < 3200){
      freedom = false;
    }
  }
for(int i = 0; i < N; i++){
  if( color.at(i) > 0 && color.at(i) < 400){
    if(kazu.at(0) == 0){
      kazu.at(0) = 1;
    }
  }
  if( color.at(i) >= 400 && color.at(i) < 800){
    if(kazu.at(1) == 0){
      kazu.at(1) = 1;
    }
  }
  if( color.at(i) >= 800 && color.at(i) < 1200){
    if(kazu.at(2) == 0){
      kazu.at(2) = 1;
    }
  }
  if( color.at(i) >= 1200 && color.at(i) < 1600){
    if(kazu.at(3) == 0){
      kazu.at(3) = 1;
    }
  }
  if( color.at(i) >= 1600 && color.at(i) < 2000){
    if(kazu.at(4) == 0){
      kazu.at(4) = 1;
    }
  }
  if( color.at(i) >= 2000 && color.at(i) < 2400){
    if(kazu.at(5) == 0){
      kazu.at(5) = 1;
    }
  }
  if( color.at(i) >= 2400 && color.at(i) < 2800){
    if(kazu.at(6) == 0){
      kazu.at(6) = 1;
    }
  }
  if( color.at(i) >= 2800 && color.at(i) < 3200){
    if(kazu.at(7) == 0){
      kazu.at(7) = 1;
    }
  }
  if(color.at(i) >= 3200 ){
    count++;
  }
}
if(freedom){
    cout << 1 <<" ";
    if(color.size() < 9){
    cout << color.size() << endl;
    }
    else{
      cout << 8 << endl;
    }
}
 else{
  cout << kazu.at(0) + kazu.at(1) + kazu.at(2) + kazu.at(3) + kazu.at(4) + kazu.at(5) + kazu.at(6) + kazu.at(7) << " ";
   cout << kazu.at(0) + kazu.at(1) + kazu.at(2) + kazu.at(3) + kazu.at(4) + kazu.at(5) + kazu.at(6) + kazu.at(7) + count << endl;
 }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x, n) for(int i = x; i <= n; i++)
#define rep3(i, x, n) for(int i = x; i >= n; i--)
#define elif else if
#define sp(x) fixed << setprecision(x)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const int inf = (1<<30)-1;
const ll INF = (1LL<<60)-1;
const ld EPS = 1e-10;
template<typename T> bool chmax(T &x, const T &y) {return (x < y)? (x = y, true) : false;};
template<typename T> bool chmin(T &x, const T &y) {return (x > y)? (x = y, true) : false;};

int main(){
    int N;
    cin >> N;
    vector<ll> L, R;
    rep(i, N){
        ll l, r;
        cin >> l >> r;
        L.pb(l), R.pb(r);
    }
    sort(all(L), greater<ll>());
    sort(all(R));
    int i = 0;
    ll sum = 0;
    while(i < N && L[i] > R[i]) sum += L[i]-R[i], i++;
    ll ans = sum;
    if(i > 0){
        chmax(ans, sum-L[i-1]);
        chmax(ans, sum+R[i-1]);
    }
    if(2*i < N){
        chmax(ans, sum+L[i]);
        chmax(ans, sum-R[i]);
    }
    cout << 2*ans << endl;
}

Measured memory_bytes: 2036
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		List<Integer> list = new ArrayList<>();
		for (int i = 0; i < n; i++) {
			list.add(sc.nextInt());
		}
		int q = sc.nextInt();
		for (int i = 0; i < q; i++) {
			int b = sc.nextInt();
			int m = sc.nextInt();
			int e = sc.nextInt();
			List<Integer> list2 = new ArrayList<>();
			for (int j = 0; j < b; j++) {
				list2.add(list.get(j));
			}
			for (int j = m; j < e; j++) {
				list2.add(list.get(j));
			}
			for (int j = b; j < m; j++) {
				list2.add(list.get(j));
			}
			for (int j = e; j < list.size(); j++) {
				list2.add(list.get(j));
			}
			list = list2;
		}
		StringBuilder sb = new StringBuilder();
		for (int num : list) {
			sb.append(num + " ");
		}
		String str = sb.toString();
		str = str.substring(0, str.length() - 1);
		System.out.println(str);
	}
}



Measured memory_bytes: 53644
K, N = map(int, input().split())
A = list(map(int, input().split()))

dis = (K-A[-1]) + A[0]
for i in range(len(A)-1):
    if A[i+1] - A[i] > dis:
        dis = A[i+1] - A[i]
print(K-dis)

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

def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

n=I()
ds=LI()
#print(ds)
D=sum(ds)
def sqr(x):
    return x*x
dds=list(map(sqr, ds))
#print(dds)
sigma=sum(dds)
ans=(D*D-sigma)/2
print(int(ans))

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define rep(i,n) for (int (i) = 0; (i) < (n); i++)
#define ll long long
using namespace std;
 
int main() {
	ll N;
	cin>>N;

	vector < ll > A(N);
	for (ll i = 0; i < N; i++) {
		cin >> A[i];
	}

	sort(A.begin(), A.end());

	ll ans = 1;
	for (ll i = 0; i < N; i++) {
		if (A[i] == 0) {
			cout << 0 << endl;
			return 0;
		}
		if (A[i] <= 1000000000000000000 /ans) {
			ans *= A[i];
		} else {
			cout << -1 << endl;
			return 0;
		}

	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 4052
import sys
sys.setrecursionlimit(1000000000)
from collections import Counter
def key(x, y):
    return str(x)+str(y)
def main2():
    # TLE
    N, X, Y = map(int, input().split())
    X -= 1
    Y -= 1

    M = {}
    for i in range(N):
        for j in range(i, N):
            M[key(i, j)] = j - i
    
    def helper(x, y, from_cost):
        if 0 <= x <= N-1 and 0 <= y <= N-1:
            if M[key(x,y)] > from_cost+1:
                M[key(x,y)] = from_cost + 1
                cost = from_cost + 1

                helper(x-1,y, cost)
                helper(x+1,y, cost)
                helper(x,y-1, cost)
                helper(x,y+1, cost)
        
    helper(X, Y, 0)

    cost_list = Counter(list(M.values()))
    for k in range(N-1):
        print(cost_list[k+1])

from collections import deque
INF = 1e10


def main3():
    # official TLE
    N, X, Y = map(int, input().split())
    X -= 1
    Y -= 1
    ans = [0 for _ in range(N)]
    for sv in range(N):
        dist = [INF for _ in range(N)]
        q = deque([])

        def push(v, d):
            if dist[v] != INF: return
            dist[v] = d
            q.append(v)

        push(sv, 0)

        while q:
            sv = q.popleft()
            d = dist[sv]
            if sv > 0:
                push(sv-1, d+1)
            if sv < N-1:
                push(sv+1, d+1)
            if sv == X:
                push(Y, d+1)
            if sv == Y:
                push(X, d+1)

        for d in dist:
            ans[d] += 1
    
    for k in range(1, N):
        print(ans[k] // 2)

def main():
    N, X, Y = map(int, input().split())
    X -= 1
    Y -= 1
    dist = [0 for _ in range(N)]
    for i in range(N-1):
        for j in range(i+1, N):
            d = min(abs(X-i)+1+abs(j-Y), abs(i-j), abs(Y-i)+1+abs(j-Y))
            dist[d] += 1
    
    for k in range(1, N):
        print(dist[k])
 

main()

Measured memory_bytes: 3820
#include<iostream>
#include<vector>
#include <algorithm>
#include <string>
#include <utility>
#include <set>
#include <map>
#include<cmath>
#include <queue>
#include <numeric>

using lli = long long int;
int inf = 1000000007;
using namespace std;

int N;

int main()
{
	cin >> N;
	vector<int> A(N);
	for (int i = 0; i < N; i++)cin >> A[i];

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

		if (set.lower_bound(A[i]) != set.begin()) {
			auto num = prev(set.lower_bound(A[i]));
			set.erase(num);
		}
		set.insert(A[i]);
	}
	cout << set.size() << endl;
	return 0;
}

Measured memory_bytes: 5376
#include<bits/stdc++.h>
#define mod 1000000007
using namespace std;
typedef long long ll;
string s;
ll num[26];
ll n;
int main()
{
    while(cin>>n>>s)
    {
        memset(num,0,sizeof(num));
        for(int i=0;i<s.size();i++)
        {
            num[s[i]-'a']++;
        }
        ll ans=1;
        for(int i=0;i<26;i++)
        {
            ans=(ans*(num[i]+1))%mod;
        }
        ans--;
        cout<<ans<<"\n";
    }
}

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

int main()
{
    int a,b,k,arr[101],i,j=1;
    cin>>a>>b>>k;
    int mini=min(a,b);
    for(i=mini;i>=1;i--){
        if(a%i==0 && b%i==0){
            arr[j++]=i;
        }
    }
    for(j=1; ;j++){
            if(j==k){
                cout<<arr[j];
                break;
            }
    }
    return 0;
}


Measured memory_bytes: 3620