akhauriyash/Code-Regression huggingface dataset:
def chmax(a, b) a > b ? a : b end

N = gets.strip.to_i
A1 = gets.strip.split.map(&:to_i)
A2 = gets.strip.split.map(&:to_i)

# 累積和の初期化
s1 = Array.new(N + 1) {0}
s2 = Array.new(N + 1) {0}

N.times do |i|
  s1[i + 1] = A1[i] + s1[i]
  s2[i + 1] = A2[i] + s2[i]
end

res = 0
(1..N).each do |i|
  res = chmax((s1[i] - s1[0]) + (s2[N] - s2[i - 1]), res)
end

puts res


Measured memory_bytes: 1788
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <map>

using namespace std;

string s;
int N;
vector<pair<string, int> > vp[11];

int main()
{
    cin >> N;
    vp[1].push_back(make_pair("a", 1));
    for(int i = 2; i <= N; i++)
    {
        for(int j = 0;j < vp[i-1].size(); j++)
        {
            string f = vp[i-1][j].first;
            int s = vp[i-1][j].second;
            for(char k = 0;k < s+1; k++)
            {
                char c ='a'+k;
                string newstr = f + c;
                int ni = max((int)k+1, s);
                vp[i].push_back(make_pair(newstr, ni));
            }
        }
    }
    for(int i = 0;i < vp[N].size();i++)
    {
        cout << vp[N][i].first << endl;
    }

    return 0;
}

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

using namespace std;

#define ll long long
#define pii pair<int,int>

int main()
{
        string s;
        cin>>s;
        if(s[s.length()-1] == 's')
        {
            s += "es";
        }
        else
        {
            s += 's';
        }
        cout<<s<<endl;
}

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

int main()
{
  int N;
  cin >> N;
  vector<int> h(N);
  rep(i,N) cin >> h[i];
  int ans = 0;
  int count =0;
  rep(i,N-1){
    if (h[i]<h[i+1]){
      count=0;
    }else{
      count++;
    };
    ans = max(ans,count);
  }
  cout << ans << endl;
}

Measured memory_bytes: 640
n = gets.to_i
t = gets.split().map(&:to_i)
m = gets.to_i
i = 0
while i < m
  p, x = gets.split().map(&:to_i)
  s = 0
  j = 0
  t.each do |a|
    if p-1 != j
      s += a
    else
      s += x
    end
    j = j + 1
  end
  puts s
  i = i + 1
end


Measured memory_bytes: 1788
h, w, k = map(int, input().split())
s = [input() for _ in range(h)]

INF = 10 ** 20
ans = INF
for div in range(1 << (h - 1)):
    id = []
    g = 0
    for i in range(h):
        id.append(g)
        if div >> i & 1:
            g += 1
    g += 1

    c = [[0 for _ in range(w)] for _ in range(g)]
    for i in range(h):
    	for j in range(w):
            c[id[i]][j] += (s[i][j] == "1")

    tmp_ans = g - 1
    now = [0] * g

    def add(j):
        for i in range(g):
            now[i] += c[i][j]
        for i in range(g):
            if now[i] > k:
                return False
        return True

    for j in range(w):
        if not add(j):
            tmp_ans += 1
            now = [0] * g
            if not add(j):
                tmp_ans = INF
                break

    # impossible = 0
    # for j in range(w):
    #     if impossible:
    #         tmp_ans = INF
    #         break
    #     for i in range(g):
    #         if c[i][j] > k:
    #             impossible = 1
    #             break
    #         now[i] += c[i][j]
    #         if now[i] > k:
    #             now = [c[gi][j] for gi in range(g)]
    #             tmp_ans += 1
    #             continue

    ans = min(ans, tmp_ans)

print(ans)

Measured memory_bytes: 52956
#include<bits/stdc++.h>
using namespace std;
template<class T>
using mp = pair<T,T>;
template<class T>
using vec = vector<T>;
using ll = long long;
int main(){
    int N, K;
    cin >> N >> K;
    vec<ll>a;
    for(int i = 0;i < N;i++){
        ll x;
        cin >> x;
        a.push_back(x);
    }
    ll ans =99999999999999;
    if(N == 1){
        cout << a[0] << "\n";
        return 0;
    }
    for(int i = 0,_i=N-K+1;i < _i;i++){
        ll tmp;
        if(a[i]*a[i+K-1] >= 0){
            tmp = max(abs(a[i]), abs(a[i+K-1]));
        }
        else{
            ll minun = abs(a[i]);
            ll plusle = a[i+K-1];
            tmp = minun+plusle+min(minun, plusle);
        }
        ans = min(tmp, ans);
    }
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 1400
#include<iostream>
#include<cctype>
#include<string>
using namespace std;

int main(int argc, char const *argv[])
{
    string str,str1,str2;
    int a=0, b=0, n;

    cin >> str;
    cin >> n;
    for (int i = 0; i < n; ++i)
    {
        cin >> str1;
        cin >> a >> b;
        if(str1 == "print"){
            str2 = str.substr(a,b-a+1);
            cout << str2 << endl;
        }
        if(str1 == "reverse"){
            str2 = str.substr(a,b-a+1);
            for (int i = 0; i < str2.size(); ++i)
            {
                str[a+i] = str2[str2.size()-i-1];
            }
        }
        if(str1 == "replace"){
            cin >> str2;
            for (int i = 0; i < str2.size(); ++i)
            {
                str[a+i] = str2[i];
            }
        }
    }

    return 0;
}

Measured memory_bytes: 1224
#include <iostream>
#include <string>
#include <algorithm>
#include <utility>
#include <iomanip>
#include <functional>
#include <queue>
#include <stack>
#include <map>
#include <vector>
#include <cmath>
#include <cctype>
#include <cstdio>
#define ll long long
#define INF 1e+18
#define MOD 1000000007
using namespace std;



int main(){
    double r1,r2;
    cin >> r1 >> r2;
    
    cout<<fixed<<setprecision(6)<<(r1*r2)/(r1+r2)<<endl;
    return 0;
}


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

int main()
{
	int n;
	cin >> n;
	vector<int> a(n);
	int input;
	int bound = 0;
	for (int i = 0; i < n; i++) {
		cin >> input;
		a.at(i) = input;
		bound += input;
	}
	sort(a.begin(), a.end());
	int max = *max_element(a.begin(), a.end());

	int q;
	cin >> q;
	int m;
	for (int i = 0; i < q; i++) {
		cin >> m;

		string ans = "no";

		if (m > bound) cout << ans << endl;
		else if (m == bound) cout << "yes" << endl;
		else {
			// small vector
			vector<int> v;
			if (m <= max) {
				for (int k = 0; k < n; k++) {
					if (a.at(k) < m) v.push_back(a.at(k));
					else if (a.at(k) == m) {
						ans = "yes";
						cout << ans << endl;
						break;
					}
				}
			}
			else v = a;
			int len = v.size();
			sort(v.begin(), v.end(), greater<int>());

			//for each input m...
			if (ans == "no") {
				for (int bit = 0; bit < (1 << len); bit++) {
					int sum = 0;
					for (int j = 0; j < len; j++) {
						if (bit & (1 << j)) sum += v.at(j);
					}
					if (sum == m) {
						ans = "yes";
						break;
					}
				}
				cout << ans << endl;
			}
		}
	}
	
	return 0;

}



Measured memory_bytes: 3224
import java.io.InputStream;
import java.io.PrintStream;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class Main {

  public static void main(String[] args) {
    resolve(System.in, System.out);
  }

  static void resolve(InputStream is, PrintStream pw) {
    Scanner sc = new Scanner(is);
    Set<String> oddExpectation = new HashSet<>(Arrays.asList("R", "U", "D"));
    Set<String> evenExpectation = new HashSet<>(Arrays.asList("L", "U", "D"));
    String s = sc.next();
    char[] sArray = s.toCharArray();
    boolean isYes = true;
    for (int i = 0; i < sArray.length; i++) {
      String c = String.valueOf(sArray[i]);
      if ((i + 1) % 2 == 0) {
        if (!evenExpectation.contains(c)) {
          isYes = false;
          break;
        }
      } else {
        if (!oddExpectation.contains(c)) {
          isYes = false;
          break;
        }
      }
    }
    pw.println(isYes ? "Yes" : "No");
  }
}


Measured memory_bytes: 23508
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<map>
#define ll long long
#define pii pair<int,int>
using namespace std;
map<pii,int> mp;
int read()
{
	char ch=getchar();int f=0,x=1;
	while(ch<'0'||ch>'9'){if(ch=='-') x=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){f=(f<<1)+(f<<3)+ch-'0';ch=getchar();}
	return f*x;
}
int n,m,a[200005],b[200005],c[200005];
ll f[200005][3],ans;bool vis[200005];
int g[200005],h[200005];
const int mod=998244353;
ll quick_mod(ll x,ll y)
{
	ll ret=1;
	while(y)
	{
		if(y&1LL) ret=ret*x%mod;
		x=x*x%mod;
		y>>=1;
	}
	return ret;
}
void mo(ll &x)
{
	if(x>=mod) x-=mod;
}
int main()
{
	n=read();m=read();
	memset(g,-1,sizeof(g));
	memset(h,-1,sizeof(h));
	for(int i=1;i<=m;i++)
	{
		a[i]=read();b[i]=read();c[i]=read();
		mp[pii(a[i],b[i])]=i;
	}
	int cou=0;
	for(int i=1;i<=m;i++)
	{
		if(!vis[i])
		{
			if(a[i]==b[i])
			{
				c[i]=c[i];
				//vis[i]=1;
			}
			else if(mp[pii(b[i],a[i])])
			{
				int num=mp[pii(b[i],a[i])];
				vis[num]=1;
				c[i]=(c[i]+c[num])%2;
			}
			else
			{
				vis[i]=1;
			}
			if(a[i]!=b[i]) cou++;
			//else
			//{
				if(abs(a[i]-b[i])>=3&&!vis[i]&&c[i]!=0)
				{
					puts("0");
					return 0;
				}
			//}
		}
	}
	
	ans=quick_mod(2,1LL*n*(n-1)/2-cou);
	for(int i=1;i<=m;i++)
	{
		if(!vis[i])
		{
			if(a[i]<b[i]) swap(a[i],b[i]);
			if(a[i]==b[i])
			{
				if(g[a[i]]!=-1&&g[a[i]]!=c[i])
				{
					puts("0");
					return 0;
				}
				g[a[i]]=c[i];
				
			}
			else if(a[i]-b[i]==2)
			{
				if(g[a[i]-1]!=-1&&g[a[i]-1]!=c[i])
				{
					puts("0");
					return 0;
				}g[a[i]-1]=c[i];
				
			}
			else if(a[i]-b[i]==1)
			{
				if(h[a[i]]!=-1&&h[a[i]]!=c[i])
				{
					puts("0");
					return 0;
				}
				h[a[i]]=c[i];
			}
		}
	}
	f[0][0]=1;
	for(int i=1;i<=n;i++)
	{
		if(g[i]!=1)
		{
			if(h[i]!=1) mo(f[i][0]+=f[i-1][0]);
			if(h[i]!=0) mo(f[i][0]+=f[i-1][1]);
		}
		if(g[i]!=0)
		{
			if(h[i]!=1) mo(f[i][1]+=f[i-1][1]);
			if(h[i]!=0) mo(f[i][1]+=f[i-1][0]);
		}
		//cout<<f[i][0]<<" "<<f[i][1]<<endl;
	}
	cout<<1LL*ans*(f[n][0]+f[n][1])%mod;
}

Measured memory_bytes: 14592
import sys
from numba import njit

readline = sys.stdin.readline
readall = sys.stdin.read
ns = lambda: readline().rstrip()
ni = lambda: int(readline().rstrip())
nm = lambda: map(int, readline().split())
nl = lambda: list(map(int, readline().split()))
prn = lambda x: print(*x, sep='\n')

@njit(cache=True)
def solve(n, k, a):
    if k == 0:
        return a
    b = [0]*n
    for _ in range(k):
        for i in range(n):
            if i > a[i]:
                b[i-a[i]] += 1
            else:
                b[0] += 1
            if i + a[i] + 1 < n:
                b[i + a[i] + 1] -= 1
        for i in range(n-1):
            b[i+1] += b[i]
            a[i] = 0
        a[-1] = 0
        b, a = a, b
        if min(a) >= n:
            break
    return a

solve(0, 0, [0, 1, 2])
n, k = nm()
a = nl()
print(*solve(n, k, a))

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

int main(){

long long  n;cin >> n;
long long count =0,ans=0;
while(n>0){
    count++;
    n=n/2;

}
ans = pow(2,count)-1;
cout << ans  << endl;

return 0;
}





Measured memory_bytes: 256
package main

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

func main() {
	N, M := ReadInt(), ReadInt()
	gridA := make([]string, N)
	gridB := make([]string, M)
	for i := 0; i < N; i++ {
		gridA[i] = ReadString()
	}
	for i := 0; i < M; i++ {
		gridB[i] = ReadString()
	}

	for top := 0; top <= N-M; top++ {
		for left := 0; left <= N-M; left++ {
			ok := true
			for y := 0; ok && y < M; y++ {
				for x := 0; ok && x < M; x++ {
					if gridA[top+y][left+x] != gridB[y][x] {
						ok = false
					}
				}
			}
			if ok {
				fmt.Println("Yes")
				return
			}
		}
	}
	fmt.Println("No")
}

var reader = bufio.NewReader(os.Stdin)

func Scan(a ...interface{}) {
	if _, err := fmt.Fscan(reader, a...); err != nil {
		panic(err)
	}
}
func ReadInt() (i int)       { Scan(&i); return }
func ReadString() (s string) { Scan(&s); return }


Measured memory_bytes: 1848
open Batteries
let n = Scanf.scanf "%d" (fun x -> x)
let a = List.init n (fun _ -> Scanf.scanf " %d" (fun x -> x))
let () =
  let four = a |> List.filter (fun x -> x mod 4 = 0) |> List.length in
  let two = a |> List.filter (fun x -> x mod 4 <> 0 && x mod 2 = 0) |> List.length in
  let one = n - four - two in
  let res = if two = 0 then four >= one-1 else four >= one in
  print_endline (if res then "Yes" else "No")

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

namespace AtCoder.Abc
{
    public class QuestionA
    {
        public static void Main(string[] args)
        {

            // 整数の入力
            long a = long.Parse(Console.ReadLine());


            Console.WriteLine(a + Math.Pow(a, 2) + Math.Pow(a, 3));

            Console.Out.Flush();
        }
    }
}


Measured memory_bytes: 27696
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<vector>
#include<list>
#include<functional>
#include<algorithm>
#include<string>
#include<cmath>
#include<complex>
#include<set>
#include<map>
#include<stack>
#include<queue>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) for(int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;



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

	string S;
	cin >> S;
	int N = S.size();
	string keyence = "keyence";
	string res = "NO";

	for (int i = 0;i <= 7;i++) {
		if (S.substr(0, i) == keyence.substr(0, i) && S.substr(N - 7 + i) == keyence.substr(i)) {
			res = "YES";
		}
	}
	cout << res << "\n";

	return 0;
}

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

int main(){
    int n,k,m=0,d=0;
    string s;
    cin>>n>>k>>s;
    for(int i=0;i<n-1;i++){
        if(s[i]==s[i+1]) m++;
        else d++;
    }
    for(int i=0;i<k;i++){
        if(d == 1) {
            m += d;
            break;
        }
        else if(d == 2){
            m += d;
            break;
        } 
        else if(d == 0){
            break;
        }
        else {
            m += 2;
            d -= 2;
        }
    }
    cout<<m<<endl;


    return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
const long long INF = 1LL << 60;
const int mod = 1e9 + 7;

const int m = 2019;

int main()
{
    int a, b, c;
    cin >> a >> b >> c;
    if (a > b)
    {
        int x = a;
        a = b;
        b = x;
    }
    if (b > c)
    {
        int x = b;
        b = c;
        c = x;
    }
    if (a > b)
    {
        int x = a;
        a = b;
        b = x;
    }

    cout << a << " " << b << " " << c << endl;
    ;

    return 0;
}


Measured memory_bytes: 3100
(* O(1) *)
let div_ceil a b = if a mod b = 0 then a / b else a / b + 1

(* O(|ts|) *)
let solve n ts = div_ceil n (List.fold_left min max_int ts) + List.length ts - 1

let _ = Scanf.scanf "%d %d %d %d %d %d" (fun n a b c d e ->
  solve n [a; b; c; d; e] |> string_of_int |> print_string)

Measured memory_bytes: 384
s=input()
dic={}
cur=0
power=0
for i in range(0,len(s)+1):
  s_int=len(s)-i-1
  if cur in dic:
    dic[cur]+=1
  else:
    dic[cur]=1
  try:
    num=int(s[s_int])
    cur+=num*pow(10,power,2019)
    cur%=2019
    power+=1
  except IndexError:
    break

res=0
for i in range(len(dic)):
  t=dic.popitem()
  cc=t[1]
  res+=cc*(cc-1)//2
print(res)


Measured memory_bytes: 9344
#include <bits/stdc++.h>
using namespace std;
#define inf 999999999
#define loop(i, a, b) for (int i = (a), i##len = (b); i < i##len; ++i)
#define rep(i, n) loop(i, 0, n)
#define lin long long

lin n;
lin a[200001];

int main(void)
{
    lin s = 0;

    cin >> n;
    rep(i,n)
    {
        cin >> a[i];
        a[i] -= i;
        s += a[i];
    }

    sort(a, a + n);

    lin b = a[0];
    lin res = 0;

    rep(i,n)
    {
        res += abs(a[i] - b);
    }

    lin c = res;
    rep(i, n-1)
    {
        //cout << c << endl;
        lin diff = a[i+1]-a[i];
        c = res + (i + 1) * diff - (n - i - 1) * diff;
        res = min(c, res);
    }

    cout << res << endl;

    return 0;
}


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

int ptod[101]{};
int vertices_num;
std::vector<int> dest[101];
std::vector<int> visited_list;
void search();

int main()
{
	int vertex_tmp, dest_num, dest_tmp;

	std::cin >> vertices_num;
	for (int i = 1; i <= vertices_num; ++i)
	{
		std::cin >> vertex_tmp >> dest_num;
		for (int j = 0; j < dest_num; ++j)
		{
			std::cin >> dest_tmp;
			dest[vertex_tmp].push_back(dest_tmp);
		}
	}

	search();

	for (int i = 1; i <= vertices_num; ++i)
		std::cout << i << " " << ptod[i] << std::endl;

	return 0;
}

void search()
{
	int pre_size{ 0 };
	visited_list.push_back(1);
	bool visited[101]{ false, true };
	for (int i = 1; pre_size != visited_list.size(); ++i)
	{
		int now_size = visited_list.size();
		for (int j = pre_size; j < now_size; ++j)
			for (auto e : dest[visited_list[j]])
				if (!visited[e])
				{
					visited[e] = true;
					visited_list.push_back(e);
					ptod[e] = i;
				}
		pre_size = now_size;
	}
	for (int i = 1; i <= vertices_num; ++i)
		if (!visited[i])
			ptod[i] = -1;
	return;
}


Measured memory_bytes: 3152
#include <bits/stdc++.h>
using namespace std;
int uni[100000]; 
int root(int a)
{
	if (uni[a] < 0) return a;
	return uni[a] = root(uni[a]);
}

bool connect(int a, int b)
{
	a = root(a);
	b = root(b);
	if (a == b) return false;
	if (uni[a] > uni[b])
	{
		a ^= b;
		b ^= a;
		a ^= b;
	}
	uni[a] = uni[a] + uni[b];
	uni[b] = a;
	return true;
}

bool isConnect(int a, int b)
{
	return root(a) == root(b);
}

int size(int a)
{
	return -uni[root(a)];
}

signed main(void)
{
	int x, y;
	cin >> x >> y;
	uni[1] = -7;
	uni[2] = -1;
	uni[3] = 1;
	uni[4] = -4;
	uni[5] = 1;
	uni[6] = 4;
	uni[7] = 1;
	uni[8] = 1;
	uni[9] = 4;
	uni[10] = 1;
	uni[11] = 4;
	uni[12] = 1;
	if (isConnect(x, y))
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
	return 0;
}


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

int n, m, v, p;
int A[100000];
long long int S[100000];

int main(){
  scanf("%d%d%d%d", &n, &m, &v, &p);
  for(int i = 0; i < n; i++) scanf("%d",A+i);
  std::sort(A, A+n);
  for(int i = 1; i < n; i++) S[i] = S[i-1] + A[i];

  int lb, ub;
  lb = -1;
  ub = n-p;
  while(ub - lb > 1){
    int mid = (lb + ub) / 2;
    if((long long) A[mid] + m < A[n-p] || (long long) m * (v - (mid+1) - (p-1)) + (S[n-p] - S[mid]) > (long long) (n-p - mid) * (A[mid] + m)) lb = mid;
    else ub = mid;
  }

  printf("%d\n", n-ub);


  return 0;
}


Measured memory_bytes: 1280
#include <cstdio>
#include <cstring>

#define S 21
#define L 28
#define N 51
#define M 1000000007

char s[N][S];
int f[N][N][S][L], n;

int solve(int l, int r, int p, int c)
{
    if (~f[l][r][p][c])
        return f[l][r][p][c];
    if (l >= r)
        return 1;
    if (c == L - 1)
        return 0;
    if (p == S - 1)
        return f[l][r][p][c] = l + 1 == r;

    int a = 0;

    for (int m = l; m <= r; m++)
    {
        a = (a + 1LL * solve(l, m, p + 1, 0) * solve(m, r, p, c + 1) % M) % M;
        if (m == r || (s[m][p] < L - 1 && s[m][p] != c) || (s[m][p] == L - 1 && !c))
            break;
    }

    return f[l][r][p][c] = a;
}

int main()
{
    scanf("%d", &n);
    memset(f, -1, sizeof f);

    for (int i = 0; i < n; i++)
    {
        scanf("%21s", s[i]);

        for (int j = 0; j < S; j++)
        {
            if (s[i][j] == '?') s[i][j] = L - 1;
            else if (s[i][j]) s[i][j] -= 'a' - 1;
        }
    }

    printf("%d\n", solve(0, n, 0, 0));
    return 0;
}



Measured memory_bytes: 8712
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define fr(i,j,k) for(int i=j;i<k;i++)
#define f(n) fr(i,0,n)
#define f1(n) fr(i,1,n+1)
#define pb push_back
#define F first
#define S second
#define all(x) x.begin(), x.end()
const int maxn = 2e5 + 5;
const int mod = 998244353;
int b[maxn];
vector<ll>d;
int getID(ll x) {
    return lower_bound(all(d),x)-d.begin() + 1;
}
void update(int x) {
    while(x < maxn) {
        b[x]++;
        x += x & (-x);
    }
}
int sum(int x) {
    int ret = 0;
    while(x) {
        ret += b[x];
        x -= x & (-x);
    }
    return ret;
}
int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n, k;
    cin >> n >> k;
    vector<ll>pre{0};
    f(n) {
        ll x;
        cin >> x;
        pre.pb(pre.back() + x - k);
    }
    d = pre;
    sort(all(d));
    d.erase(unique(all(d)),d.end());
    ll ans = 0;
    update(getID(0));
    for (int i = 1 ; i < pre.size() ; i++) {
        int tar = getID(pre[i]+1) - 1;
        ans += sum(tar);
        update(getID(pre[i])); 
    }
    cout << ans << '\n';
}

Measured memory_bytes: 4336
#include<iostream>
#include<vector>
#include<algorithm>
#include<cctype>
#include<utility>
#include<string>
#include<cstring>
#include<cmath>
#include <numeric>
#include<queue>
#include<climits>
#include<cstdio>


#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
//#define INF ((LLONG_MAX) / (2))
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;
typedef long long int ll;
typedef pair<ll,int> LL_IP;
#define INF 1e9+7
#define N_MAX 1001


int n,m,b,c;
int arr[N_MAX];
int cost[N_MAX];

int main(){

    string s;
    cin >> s;
    int tmp = s.length();
    if(tmp == 2){
        cout << s << endl;
    }else{
        reverse(s.begin(),s.end());
        cout << s << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,x,y) for (int i=(x);i<=(y);i++)
#define ll long long
#define inf 1000000001
using namespace std;
ll read(){
	char ch=getchar();ll x=0;int op=1;
	for (;!isdigit(ch);ch=getchar()) if (ch=='-') op=-1;
	for (;isdigit(ch);ch=getchar()) x=(x<<1)+(x<<3)+ch-'0';
	return x*op;
}
#define N 100005
int n,m,cnt,head[N],a[N],b[N],fa[N],id[N],vis[N];ll s1[N],s2[N];
struct edge{int to,nxt;}e[N<<1];
void adde(int x,int y){e[++cnt].to=y;e[cnt].nxt=head[x];head[x]=cnt;}
void ins(int x,int y){adde(x,y);adde(y,x);}
const bool cmp(const int x,const int y){return a[x]<a[y];}
int getfa(int x){return x==fa[x]?x:fa[x]=getfa(fa[x]);}
int main(){
	n=read(),m=read();
	rep (i,1,n){a[i]=read(),b[i]=read();a[i]=max(a[i]-b[i],0);}
	rep (i,1,m){int x=read(),y=read();ins(x,y);}
	rep (i,1,n) fa[i]=id[i]=i,s1[i]=a[i],s2[i]=b[i];
	sort(&id[1],&id[n+1],cmp);
	rep (i,1,n){
		int x=id[i];vis[x]=1;
		for (int j=head[x],y;j;j=e[j].nxt){
			y=e[j].to;if (!vis[y]) continue;
			int fx=getfa(x),fy=getfa(y);
			if (fx!=fy){
				fa[fy]=fx;s2[fx]+=s2[fy];
				s1[fx]=min(s1[fx],s1[fy]+max(0ll,a[x]-s1[fy]-s2[fy]));
			}
		}
	}
	int x=getfa(1);
	cout<<s1[x]+s2[x]<<'\n';
	return 0;
}

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

// begin fast read template by CYJian (source: https://www.luogu.com.cn/paste/i11c3ppx)

namespace io {
	const int __SIZE = (1 << 21) + 1;
	char ibuf[__SIZE], *iS, *iT, obuf[__SIZE], *oS = obuf, *oT = oS + __SIZE - 1, __c, qu[55]; int __f, qr, _eof;
	#define Gc() (iS == iT ? (iT = (iS = ibuf) + fread (ibuf, 1, __SIZE, stdin), (iS == iT ? EOF : *iS ++)) : *iS ++)
	inline void flush () { fwrite (obuf, 1, oS - obuf, stdout), oS = obuf; }
	inline void gc (char &x) { x = Gc(); }
	inline void pc (char x) { *oS ++ = x; if (oS == oT) flush (); }
	inline void pstr (const char *s) { int __len = strlen(s); for (__f = 0; __f < __len; ++__f) pc (s[__f]); }
	inline void gstr (char *s) { for(__c = Gc(); __c < 32 || __c > 126 || __c == ' ';)  __c = Gc();
		for(; __c > 31 && __c < 127 && __c != ' '; ++s, __c = Gc()) *s = __c; *s = 0; }
	template <class I> inline bool gi (I &x) { _eof = 0;
		for (__f = 1, __c = Gc(); (__c < '0' || __c > '9') && !_eof; __c = Gc()) { if (__c == '-') __f = -1; _eof |= __c == EOF; }
		for (x = 0; __c <= '9' && __c >= '0' && !_eof; __c = Gc()) x = x * 10 + (__c & 15), _eof |= __c == EOF; x *= __f; return !_eof; }
	template <class I> inline void print (I x) { if (!x) pc ('0'); if (x < 0) pc ('-'), x = -x;
		while (x) qu[++ qr] = x % 10 + '0',  x /= 10; while (qr) pc (qu[qr --]); }
	struct Flusher_ {~Flusher_(){flush();}}io_flusher_;
} using io::pc; using io::gc; using io::pstr; using io::gstr; using io::gi; using io::print;

// end fast read template by CYJian

#define iter(i, a, b) for(int i=(a); i<(b); i++)
#define rep(i, a) iter(i, 0, a)
#define rep1(i, a) iter(i, 1, (a)+1)
#define log(a) cerr<<"\033[32m[DEBUG] "<<#a<<'='<<(a)<<" @ line "<<__LINE__<<"\033[0m"<<endl
#define all(a) a.begin(), a.end()
#define fi first
#define se second
#define pb push_back
#define mp make_pair
 
using ll=long long;
using pii=pair<int, int>;
//#define int ll
const int MOD = 1000000007;

map<int, int> t;

signed main() {
    ios_base::sync_with_stdio(false); cin.tie(0);
    ll ans = 0;
	int N; gi(N);
	rep1(i, N) {
		int k; gi(k);
		ans += t[i-k];
		t[i+k]++;
	}
	print(ans);
}


Measured memory_bytes: 22276
#include<bits/stdc++.h>
using namespace std;using ll=long long;using vi=vector<int>;using vvi=vector<vi>;using vl=vector<ll>;using vvl=vector<vl>;using P=pair<int,int>;using PL=pair<ll,ll>;using vp=vector<P>;using vpl=vector<PL>;
template<typename T>constexpr auto inf=numeric_limits<T>::max()/2;constexpr int INF=inf<int>,MOD=1000000007;constexpr ll LINF=inf<ll>;
#define _ol3(_1,_2,_3,name,...)name
#define _rep(i,n)_repi(i,0,n)
#define _repi(i,a,b)for(int i=a,i##_l=(b);i<i##_l;++i)
#define REP(...)_ol3(__VA_ARGS__,_repi,_rep,)(__VA_ARGS__)
#define REPR(i,n)for(int i=n-1;i>=0;--i)
#define REPA(i,v)REP(i,(v).size())
#define all(v)(v).begin(),(v).end()
#define rall(v)(v).rbegin(),(v).rend()
#define bit(n)(1ll<<(n))
#define F first
#define S second
#define endl '\n'
#define cho(n,a,b)cout<<((n)?a:b)<<endl
void YES(int n){cho(n,"YES","NO");}void Yes(int n){cho(n,"Yes","No");}void Poss(int n){cho(n,"Possible","Impossible");}
void _print(ostream&){}template<class T,class...U>void _print(ostream&s,const T&t,const U&...u){s<<t<<(sizeof...(u)?' ':'\n');_print(s,u...);}
template<class...T>void print(const T&...t){_print(cout,t...);}template<class...T>void dprint(const T&...t){_print(cerr,t...);}
#ifndef LOCAL
struct osd{template<class T>osd&operator<<(const T&t){return*this;}};osd cer_;
#define dprint(...)
#define cerr cer_
#endif
template<class T>bool chmax(T&a,const T&b){bool x=a<b;x?a=b:b;return x;}template<class T>bool chmin(T&a,const T&b){bool x=a>b;x?a=b:b;return x;}
template<class T,class U>ostream&operator<<(ostream&o,const pair<T,U>&p){return o<<p.F<<' '<<p.S;}
template<class T,class U>istream&operator>>(istream&i,pair<T,U>&p){return i>>p.F>>p.S;}
template<class T>class iterable{static false_type c(string v);template<class U>static auto c(U v)->decltype(all(v),true_type());static false_type c(...);public:const static bool value=decltype(c(declval<T>()))::value;};
template<class T,enable_if_t<iterable<T>::value,int> =0>ostream&operator<<(ostream&o,const T&v){for(auto&&i:v)o<<i<<' ';return o;}
template<class T>istream&operator>>(istream&i,vector<T>&v){for(T&j:v)i>>j;return i;}
template<class T>vector<T>&operator<<(vector<T>&v,const T&t){v.push_back(t);return v;}
template<class T>set<T>&operator<<(set<T>&v,const T&t){v.insert(t);return v;}
template<class T>multiset<T>&operator<<(multiset<T>&v,const T&t){v.insert(t);return v;}
template<class T,enable_if_t<is_integral<T>::value,int> =0>T mod(T a, T b){if(a>0)return a%b;return b-(-a%b);}
template<class T,enable_if_t<is_floating_point<T>::value,int> =0>T mod(T a, T b){if(a>0)return a%b;return b-fmod(-a,b);}

int solve(){
    int n;
    cin>>n;
    int a=n*100/108;
    if(a*108/100==n)return a;
    --a;
    if(a*108/100==n)return a;
    a+=2;
    if(a*108/100==n)return a;
    return -1;
}

int main(){
    cin.tie(0);ios::sync_with_stdio(0);
    cout<<setprecision(10);
    int r=solve();
    if(r<0)print(":(");
    else print(r);
}


Measured memory_bytes: 256
#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;
typedef long long ll;

int main()
{

    string S;
    cin >> S;
    sort(all(S));
    
    map<char,int> M;
    rep(i,int(S.length())) M[S[i]]++;
    vector<pair<int,char>> A;
    for(auto p : M) A.push_back({p.second,p.first});
    sort(all(A));
    reverse(all(A));
    if(A.size() < 2){
        if(A[0].first == 1) cout << "YES" << endl;
        else {
            cout << "NO" << endl;
        }
        return 0;
    }
    
    char a = A[0].second;
    A[0].first--;
    char b = A[1].second;
    A[1].first--;
    //cout << a << b << endl;
    
    rep(i,int(S.length())-2){
        bool f = false;;
        for (int j = 0; j < int(A.size()); j++) {
            pair<int, char> p = A[j];
            if(p.first == 0) continue;
            if(a != p.second && b != p.second){
                a = b;
                b = p.second;
                //cout << p.second << endl;
                A[j].first--;
                f = true;
                break;
            }
        }
        if(!f){
            cout << "NO" << endl;
            return 0;
        }
    }

    cout << "YES" << endl;

    
    return 0;
}



Measured memory_bytes: 512
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <tuple>
#include <cstring>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for(int i=0; i<n; i++)
#define reps(i, s, e) for(int i=s; i<e; i++)
#define repr(i, n) for(int i=n-1; i>=0; i--)
#define reprs(i, s, e) for(int i=e-1; i>=s; i--)

int main(){

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

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

    int cnt1 = 0;
    int vmin = 0;

    rep(i, n){
        if(s[i] == '('){
            cnt1++;
        }
        else{
            cnt1--;
            vmin = min(vmin, cnt1);
        }
    }

    string shead = "";
    rep(i, -vmin){
        shead += '(';
    }
    s = shead + s;

    n = s.size();
    int cnt2 = 0;
    vmin = 0;
    repr(i, n){
        if(s[i] == ')'){
            cnt2++;
        }
        else{
            cnt2--;
            vmin = min(vmin, cnt2);
        }
    }
    // cout << vmin << endl;

    string stail = "";
    rep(i, -vmin){
        stail += ')';
    }
    s = s + stail;

    cout << s << endl;


    return 0;
}

Measured memory_bytes: 256
//AtCoder 
#include <bits/stdc++.h>
using namespace std;
using ll=int64_t;
int main() {
    ll N; cin>>N;
    vector<ll> dn(N);
    for(auto&& d:dn){
        cin>>d;
    }
    sort(dn.begin(),dn.end());
    ll n2=N/2;
    ll ans= dn[n2]-dn[n2-1];
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define L long long
#define pb push_back
using namespace std;
int n,x,y,f[200010][25],h[200010],g[200010];
vector<int> a[200010],b[200010];
inline void dfs(int i)
{
	int j;
	for(j=1;j<=20;j++)
	  f[i][j]=f[f[i][j-1]][j-1];
	for(j=0;j<b[i].size();j++)
	  if(b[i][j]!=f[i][0])
	    {
		 f[b[i][j]][0]=i;
		 h[b[i][j]]=h[i]+1;
		 dfs(b[i][j]);
		}
}
inline bool check(int x,int y)
{
	return x==y || f[x][0]==y || f[y][0]==x;
}
inline int dis(int x,int y)
{
	int a=x,b=y,k;
	if(h[a]<h[b])
	  swap(a,b);
	if(h[a]>h[b])
	  for(k=20;k>=0;k--)
	    if(h[a]-(1<<k)>=h[b])
	      a=f[a][k];
	if(a==b)
	  return abs(h[x]-h[y]);
	for(k=20;k>=0;k--)
	  if(f[a][k]!=f[b][k])
	    a=f[a][k],b=f[b][k];
	return h[x]+h[y]-h[a]-h[b]+2;
}
inline int walk(int y,int x)
{
	int a=x,b=y,k;
	if(h[a]<h[b])
	  {
	   for(k=20;k>=0;k--)
	     if(h[b]-(1<<k)>h[a])
	       b=f[b][k];
	   if(f[b][0]==a)
	     return b;
	  }
	return f[x][0];
}
inline int dfs(int x,int y)
{
	if(g[x])
	  return 0;
	g[x]=1;
	int i,j,k=dis(x,y)*2;
	for(i=0;i<a[x].size();i++)
	  {
	   if(dis(x,a[x][i])>=3)
	     return -1;
	   if(!check(a[x][i],y))
	     {
	      j=dfs(a[x][i],walk(a[x][i],y));
		  if(j==-1)
		    return -1;
		  k=max(k,j+2);
		 }
	  }
	return k;
}
int main()
{
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	int i,j,k;
	scanf("%d%d%d",&n,&x,&y);
	for(i=1;i<n;i++)
	  {
	   scanf("%d%d",&j,&k);
	   a[j].pb(k);
	   a[k].pb(j);
	  }
	for(i=1;i<n;i++)
	  {
	   scanf("%d%d",&j,&k);
	   b[j].pb(k);
	   b[k].pb(j);
	  }
	dfs(1);
	printf("%d\n",dfs(x,y));
	return 0;
}


Measured memory_bytes: 52096
def i():
    return int(input())
def i2():
    return map(int,input().split())
def s():
    return str(input())
def l():
    return list(input())
def intl():
    return list(int(k) for k in input().split())

n,m,c=i2()
b=intl()
a = [intl() for _ in range(n)]
d=0
flag=0
for i in range(n):
	for j in range(m):
		d+=a[i][j]*b[j]
		#print(d,'j')
	if d>-c:
		flag+=1
	d=0
	#print(d,'i')
	#print(-c)
	#print(flag)
print(flag)

Measured memory_bytes: 3064
n , m = map(int,input().split())
x = []
for _ in range(m):
    y = list(map(int,input().split()))
    x.append(y)
p = list(map(int,input().split()))
ans = 0

for i in range(2**n):
    flg = True
    for j in range(m):
        count = 0
        for k in range(1,x[j][0]+1):
            
            if (i>>(x[j][k]-1)&1):
                count += 1
        if count%2 == p[j]:
            continue
        else:
            flg=False
            break
    if flg:
        ans += 1

print(ans)



Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main(){
	ll array[4][4];
	ll brray[4][4];
	ll drray[4][4];

	for(ll i=1;i<=3;i++){
		for(ll j=1;j<=3;j++){
			cin>>array[i][j];
			drray[i][j]=0;
		}
	}
	ll m;
	cin>>m;
	ll crray[m+1];
	for(ll k=1;k<=m;k++){
		cin>>crray[k];
		for(ll p=1;p<=3;p++){
			for(ll q=1;q<=3;q++){
				if(array[p][q]==crray[k]){
					 drray[p][q]=1;
				}
			}
		}
	}
	ll cnt=0;
	for(ll i=1;i<=3;i++){
		if(drray[1][i] ==1 && drray[2][i]==1 && drray[3][i]){
			cnt++;
			break;
		}
		else if(drray[i][1] ==1 && drray[i][2]==1 && drray[i][3]){
			cnt++;
			break;
		}
	}
	if(drray[1][1]==1 && drray[2][2]&&drray[3][3]){
		cnt++;
	}
	if(drray[3][1]==1 && drray[2][2]&&drray[1][3]){
		cnt++;
	}
	if(cnt>0){
		cout<<"Yes"<<endl;
	}else
	cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 256
#ifdef _MSC_VER
#define _CRT_SECURE_NO_WARNINGS
#endif
 
#include <thread>
#include <unordered_set>
#include <vector>
#include <memory.h>
#include <list>
#include <map>
#include <unordered_map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <string>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <stdio.h>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <random>
#include <string>
#include <cassert>


#define getcx _getchar_nolock

using namespace std;
 
namespace std
{
	string to_string(string const& s) { return '"' + s + '"'; }
	string to_string(char c) { return string(1, c); }
	string to_string(const char* s) { return to_string((string)s); }
	string to_string(bool b) { return (b ? "true" : "false"); }
 
	template <class T1, class T2>
	string to_string(pair<T1, T2> p) { return "(" + to_string(p.first) + ", " + to_string(p.second) + ")"; }
 
	template <class T>
	string to_string(T c)
	{
		string s = "[";
		for (auto vvv : c) { s += to_string(vvv) + ","; }
		s += "]";
		return s;
	}
 
	void debug_impl() { cerr << endl; };
 
	template <typename T1, typename... T2>
	void debug_impl(T1 a, T2 ... b)
	{
		cerr << " " << to_string(a);
		debug_impl(b...);
	}
}
 
template <typename T>
struct reversion_wrapper
{
	T& iterable;
};
 
template <typename T>
auto begin(reversion_wrapper<T> w) { return std::rbegin(w.iterable); }
 
template <typename T>
auto end(reversion_wrapper<T> w) { return std::rend(w.iterable); }
 
template <typename T>
reversion_wrapper<T> reverse(T&& iterable) { return { iterable }; }
 
 
#ifdef __ASD__
#define dbg(...) cerr << "[" << #__VA_ARGS__ << "]: ", debug_impl(__VA_ARGS__)
//#define endl "\n"
#else
#define dbg(...) ;
//#define endl "\n"
#endif
 
#define lng long long

int main()
{
#ifdef __ASD__
	auto start_t = chrono::steady_clock::now();
	freopen("input.txt", "r", stdin);
	//freopen("nul", "w", stderr);
	//freopen("output.txt", "w",  stdout);
#else
	ios_base::sync_with_stdio(false);
#endif

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


	set<int> s;

	lng res = 0;

	for (int i = n - 1; i >= 0; i--)
	{
		int idx = inv[i];
		lng l1 = -1;
		lng l2 = -1;
		lng r1 = -1;
		lng r2 = -1;

		auto it = s.lower_bound(idx);
		if (it != s.end())
		{
			r1 = *it;
			it++;
			if (it != s.end())
			{
				r2 = *it;
			}
			it--;
		}

		if (it != s.begin())
		{
			it--;
			l2 = *it;
			if (it != s.begin())
			{
				it--;
				l1 = *it;
			}
		}

		if (l2!=-1)
		{
			res += (i+1) * (l2-l1)*( (r1==-1?n:r1)-idx );
		}

		if (r1!=-1)
		{
			res += (i+1) * (idx-l2)*((r2==-1?n:r2)-r1);
		}

		s.insert(idx);
	}

	cout << res << endl;
	
#ifdef __ASD__
	auto finish_t = chrono::steady_clock::now();
	cerr << "Elapsed " << chrono::duration_cast<chrono::milliseconds>(finish_t - start_t).count() << " ms" << endl;
#endif
	return 0;
}


Measured memory_bytes: 5760
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#include <numeric>
typedef long long Int;
#define rep(i,a,b) for(Int i=a;i<b;++i)
#define rrep(i,a,b) for(Int i=a;i>=b;--i)
using namespace std;

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

    int N; cin >> N;
    int res = 0;
    rep(i, 1, N+1) res += i;
    cout << res << endl;
}


Measured memory_bytes: 256
using System;
using System.Linq;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            int n, k;
            ReadInt2(out n, out k);

            var sushis = (from _ in Enumerable.Repeat(0, n)
                          let cols = Console.ReadLine().Split().ToArray()
                          let s = new { Type = int.Parse(cols[0]), Deliciousness = long.Parse(cols[1]) }
                          orderby s.Deliciousness descending
                          select s).ToArray();

            var maxValues = (from s in sushis
                             group s by s.Type into g
                             select new { Type = g.Key, MaxValue = g.Max(x => x.Deliciousness) })
                             .ToDictionary(x => x.Type, x => x.MaxValue);

            bool[] isMax = new bool[sushis.Length];
            for (int i = 0; i < sushis.Length; i++)
            {
                var sushi = sushis[i];
                if (sushi.Deliciousness == maxValues[sushi.Type])
                {
                    isMax[i] = true;
                    maxValues[sushi.Type] = -1;
                }
            }

            long sum = sushis.Take(k).Sum(s => s.Deliciousness);
            long numKind = sushis.Take(k).Select(s => s.Type).Distinct().Count();
            long ans = sum + numKind * numKind;

            int removing = k - 1, adding = k;
            while (true)
            {
                while (removing >= 0 && isMax[removing])
                {
                    removing--;
                }

                while (adding < n && !isMax[adding])
                {
                    adding++;
                }

                if (removing < 0 || adding >= n)
                {
                    break;
                }

                sum = sum - sushis[removing].Deliciousness + sushis[adding].Deliciousness;
                numKind++;
                ans = Math.Max(ans, sum + numKind * numKind);
                removing--;
                adding++;
            }

            Console.WriteLine(ans);
        }

        static void ReadInt2(out int first, out int second)
        {
            var array = Console.ReadLine().Split().Select(s => int.Parse(s)).ToArray();
            first = array[0];
            second = array[1];
        }
    }
}

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

int gcd(int a, int b);
int main()
{
	int k, sum=0;
	cin >> k;
	rep(i, k){
		rep(j, k){
			rep(l, k){
				sum += gcd(gcd(i+1, j+1), l+1);
			}
		}
	}
	cout << sum << endl;
}

int gcd(int a,int b){
	    if(a<b)swap(a,b);
		    if(a%b==0)return b;
			    return gcd(a%b,b);
}



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

int main(){
	long n;
	cin >> n;
	//n = 6;
	long max = -1000000000;
	vector<long> R(n);
	for (long i = 0; i < n; i++){
		cin >> R[i];
	}
	long Rmin = R[0];
	/*
	R[0] = 5;
	R[1] = 3;
	R[2] = 1;
	R[3] = 3;
	R[4] = 4;
	R[5] = 3;
	*/
	for (long i = 1; i < n; i++){
		if (R[i] - Rmin > max) max = R[i] - Rmin;
		if (R[i] < Rmin) Rmin = R[i];
	}
	cout << max << endl;
	return 0;
}

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

int main() {
    int n;

    while (~scanf("%d", &n)) {
        bool *cand = (bool *)malloc((n + 1) * sizeof(bool));
        memset(cand, false, sizeof(bool) * (n + 1));
        int i = 2;
        while (i < n) {
            if (cand[i] == true) {
                i++;
                continue;
            }
            int m = 2;
            while (i * m <= n) {
                cand[i * m] = true;
                m++;
            }
            i++;
        }
        int cnt = 0;
        //skip 0 and 1
        for (int k = 2; k < n + 1; k++) {
            if (cand[k] == false) {
                cnt++;
            }
        }
        printf("%d\n", cnt);
    }
    return 0;
}



Measured memory_bytes: 16120
#include <stdio.h>

int main(void)
{
  int s1;
  int h,m,s;
  scanf("%d",&s1);
  h=s1/3600;
  m=s1%3600/60;
  s=s1%3600%60;
  printf("%d:%d:%d\n",h,m,s);
  return 0;
}

Measured memory_bytes: 592
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
template<typename T> bool chmax(T &a,T b){if(a<b){a=b;return true;}return false;}
template<typename T> bool chmin(T &a,T b){if(a>b){a=b;return true;}return false;}
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(vec) vec.begin(),vec.end()
typedef long long ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
typedef tuple<ll,ll,ll> tlll;
typedef tuple<int,int,int> tiii;
const ll mod=1e9+7;
const int inf=1<<30;

int main(){
  int n; cin >> n;
  ll ans=0;
  rep(i,n+1){
    if(i%3!=0&&i%5!=0){
      ans+=i;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    int a[n],ans,sum=0;
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
    }
    sort(a,a+n);
    for(int i=0;i<n-1;i++)
    {
        sum=sum+a[i];
    }
    ans=sum+a[n-1]/2;
    cout<<ans<<endl;

}


Measured memory_bytes: 3624
n,m=map(int,input().split())
a=[list(map(int,input().split())) for _ in range(n)]
b=[list(map(int,input().split())) for _ in range(m)]
for i in range(n):
    ans=-1
    num=10**10
    for j in range(m):
        cnt=abs(a[i][0]-b[j][0])+abs(a[i][1]-b[j][1])
        if cnt<num:
            ans=j+1
            num=cnt
    print(ans)


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

using ll = long long;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define ddrep(i, n) for (int i = n; i > 0; --i)
#define srep(i, s, t) for (int i = s; i < t; ++i)
#define ssrep(i, s, t) for (int i = s; i <= t; ++i)

#define rng(a) a.begin(), a.end()
#define rrng(a) a.rbegin(), a.rend()
#define pb push_back
#define eb emplace_back
#define fi first
#define se second

#define chmax(x, y) (x = max(x, y))
#define chmin(x, y) (x = min(x, y))

using pi = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using ld = long double;

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << "(" << p.first << "," << p.second << ")";
  return os;
}

template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
  os << "{";
  rep(i, (int)v.size()) {
    if (i)
      os << ",";
    os << v[i];
  }
  os << "}";
  return os;
}

template <typename T, size_t S> void printArray(const T (&array)[S]) {
  for (auto val : array)
    std::cout << val << ", ";
  std::cout << "\n";
}

const int mod = 1e9 + 7;
const int inf = 1e9 + 5;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << std::setprecision(10);

  int n; std::cin >> n;
  std::cout << n / 3 << "\n";
}


Measured memory_bytes: 256
import math
n,d = map(int,input().split())
grid = [list(map(int,input().split())) for i in range(n)]
dis = 0
count = 0
che = 0
for i in range(n):
    for j in range(i+1,n):
        for k in range(d):
            dis +=(grid[i][k]-grid[j][k])**2
        che = int(math.sqrt(dis))
        if che ** 2 == dis:
            count+=1
        dis = 0
print(count)

Measured memory_bytes: 3064
#author : dokueki

import sys
INT_MAX = sys.maxsize
INT_MIN = -(sys.maxsize)
sys.setrecursionlimit(10**7)
mod = 1000000007


def IOE():
    sys.stdin = open("input.txt", "r")
    sys.stdout = open("output.txt", "w")


def main():
    s = input()
    print("Yes" if "7" in s else "No")


if __name__ == "__main__":
    try:
        IOE()
    except:
        pass
    main()


Measured memory_bytes: 9016
#include<bits/stdc++.h>
using namespace std;
const int MAXH=20000+5;
const int MAXN=1000+5;
int H,n,a[MAXN],b[MAXN],f[MAXH],ans=1<<30;
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	memset(f,0x3f,sizeof(f));
	f[0]=0;
	cin>>H>>n;
	for(int i=1;i<=n;i++)
		cin>>a[i]>>b[i];
	for(int i=1;i<=20000;i++)
		for(int j=1;j<=n;j++)
			if(i-a[j]>=0)
				f[i]=min(f[i],f[i-a[j]]+b[j]);
	for(int i=H;i<=20000;i++)
		ans=min(ans,f[i]);
	cout<<ans;
	return 0;
}

Measured memory_bytes: 384
#include<iostream>
#include<vector>
#include<algorithm>
#include<cctype>
#include<utility>
#include<string>
#include<cmath>
#include<cstring>
#include<queue>
#include<map>
#include<queue>

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 1000000007
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;
typedef long long int ll;
ll dx[4] = {1,0,0,-1};
ll dy[4] = {0,1,-1,0};

#define ARRAY_MAX 1005

int main(){

    int n,a,b;
    cin >> n >> a >> b;
    string s;
    cin >> s;

    int a_num = 1,b_num = 1;//順位
    int a_cnt = 0,b_cnt = 0;

    REP(i,s.length()){

        if(s[i] == 'c'){
            cout << "No" << endl;
            continue;
        }

        if(s[i] == 'a'){
            if(a_cnt+b_cnt < a+b){
                cout << "Yes" << endl;
                a_cnt++;
                a_num++;
            }else{
                cout << "No" << endl;
            }
        }else if(s[i] == 'b'){
            if(a_cnt+b_cnt < a+b && b_num <= b){
                cout << "Yes" << endl;
                b_cnt++;
                b_num++;
            }else{
                cout << "No" << endl;
            }
        }
        //cout << i << " " << a_cnt << " " << b_cnt << endl;
    }

    return 0;
}

Measured memory_bytes: 896
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<iostream>
#include<queue>
#include<vector>
using namespace std;
#define MAX 120

int h[MAX];


int main(){
  int n,count=0;
  bool hantei=false;
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>h[i];
  }
  for(int i=0;i<100;i++){
    hantei=0;
    for(int j=0;j<n;j++){
      if(h[j]!=0){
        h[j]--;
        if(hantei==0){
          hantei=1;
          count++;
        }
      }else{
        hantei=0;
      }
    }
  }
  cout<<count<<endl;
}


Measured memory_bytes: 256
N,M = map(int,input().split())
A = list(map(int,input().split()))
A.sort(reverse=True)
ans = 0
x = sum(A)
for i in range(M):
    if A[i] >= x/(4*M):
        #print(i)
        ans += 1
#print(ans)
if ans == M:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 60868