akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;


#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define PSET(x,y) fixed<<setprecision(y)<<x
#define pb push_back
#define pii pair<int,int>
#define pf push_front
#define mp make_pair
#define vi vector<int>
#define vip vector<pair<int,int> >
#define ff first
#define ss second
#define int long long
#define mod 1000000007
#define BIG 998244353
#define s(t) scanf("%lld",&t)
#define p(t) printf("%lld\n",t)
#define mii map<int,int>
#define MSET(table,i) memset(table, i, sizeof(table))
#define endl '\n'
#define tc int t;cin>>t;while(t--)
#define pi  3.1415926358
#define bits(x) __builtin_popcountll(x)
#define minimum(a,n) min_element(a,a+n)-a
#define maximum(a,n) max_element(a,a+n)-a
#define pqbig priority_queue<int>
#define pqsmall priority_queue<pii,vector<pii>,greater<pii> >
#define all(v) v.begin(),v.end()
#define sitr set<int>:: iterator
#define spitr set<pii>:: iterator
#define mitr map<int,int>:: iterator

int toint(const string &s) {stringstream ss; ss << s; int x; ss >> x; return x;}
string tostring ( int number ) {stringstream ss; ss << number; return ss.str();}


typedef tree<pii, null_type, less<pii>, rb_tree_tag,
        tree_order_statistics_node_update>
        new_data_set;


#define trace1(x)                cerr<<#x<<": "<<x<<endl
#define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl


int32_t main()
{
	fast;
	string s;cin>>s;
	int ans=0;
	for(int i=0;i<s.size();i++)
		ans+=(s[i]-'0');
	if(ans%9==0)
		cout<<"Yes"<<endl;
	else
		cout<<"No"<<endl;
}


Measured memory_bytes: 3796
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<math.h>
#include<stdlib.h>
#include<string>
#include<iostream>
#include<set>
#include<map>
#include<deque>
using namespace std;
typedef long long ll;
typedef pair<ll, ll>pii;
typedef pair<pii, ll>pi3;
ll mod = 1000000007;
int main()
{
	int n, k, x, y;
	cin >> n >> k >> x >> y;
	cout << x*min(k, n) + y*max(0, n - k) << endl;
	//printf((a < 1200) ? "ABC\n" : "ARC\n");
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define mod 1000000007
#define sp ' '
#define intmax 2147483647
#define llmax 9223372036854775807
#define mkp make_pair
typedef long long ll;
using namespace std;

vector<int>v(5);
int res = intmax;
int main(){
	for (int i = 0; i < 5; ++i) {
		cin >> v[i];
	}
	sort(v.begin(), v.end());
	do {
		int t = 0;
		for (int i = 0; i < 5; ++i) {
			t = ((t - 1) / 10 + 1) * 10;
			t += v[i];
		}
		res = min(res, t);
	} while (next_permutation(v.begin(), v.end()));
	cout << res - 10 << endl;
	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iostream>
#include <ctime>
#include <atcoder/all>
using namespace std;
#define _LL long long
#define rep(i, n) for (_LL i = 0; i < (_LL)(n); i++)
#define vecrep(itr, v) for (auto itr = (v).begin(); itr != (v).end(); itr++)
using namespace atcoder;

int main()
{
    int n, q; cin >> n >> q;
    fenwick_tree<_LL> ft(n);
    rep(i, n) { _LL a; cin >> a; ft.add(i, a); }
    rep(i, q)
    {
        _LL t, q1, q2;
        cin >> t >> q1 >> q2;
        switch(t)
        {
            case 0:
                ft.add(q1, q2);
                break;
            case 1:
                cout << ft.sum(q1, q2) << endl;
                break;
        }
    }
    return 0;    
}

Measured memory_bytes: 8224
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, from, to) for (int i = from; i < (to); ++i)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define pb push_back
using ll = long long;
using vin=vector<int>;
using vll=vector<ll>;
using P = pair<int, int>;
const int inf=1e9+7;
const ll INF=1e18;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }

int main() {
  int n;
  cin>>n;
  cout<<n/3<<endl;
}

Measured memory_bytes: 3632
N,W = map(int,input().split())
w,v = [0]*N , [0]*N
for i in range(N):
  w[i],v[i] = map(int,input().split())
dp = [[0]*(W+1) for _ in range(N+1)]
for k in range(W+1):
  dp[0][k] = 0
for i in range(N):
  for j in range(W+1):
    if j -w[i] <0:
      dp[i+1][j] = dp[i][j]
    else:
      dp[i+1][j] = max(dp[i][j], dp[i][j-w[i]]+v[i])
print(dp[-1][W])

Measured memory_bytes: 120172
from collections import deque

def bfs(): #幅優先探索
  #入力のグラフを初期化
  d = [[float("inf")] * w for i in range(h)] 
  #d == mazeリストの"."を"inf"に変えたリスト
  dx = [-1,0,0,1]
  dy = [0,-1,1,0]
  
  que = deque([])
  que.append((sx,sy))
  d[sx][sy] = 0
  
  while que:
    lead = que.popleft()
    #lead == queを入れるところ
    if lead[0] == gx and lead[1] == gy:
      break
    for i in range(4):
      nx = lead[0] + dx[i]
      ny = lead[1] + dy[i]
      
      if 0<=nx<h and 0<=ny<w and maze[nx][ny]!="#" and d[nx][ny]==float("inf"):
        que.append((nx,ny))
        d[nx][ny] = d[lead[0]][lead[1]] + 1
  return d[gx][gy]

h, w = map(int, input().split())
maze = [list(input()) for i in range(h)]
sx,sy = 0,0
gx,gy = h-1,w-1

w_squares = 0
#最初の白マスの総数をw_squaresへ
for i in range(h):
  for j in range(w):
    if maze[i][j] == ".":
      w_squares += 1 
      
score = bfs() #幅優先探索で最短で通る白マス総数を出力
if 0 < score < float("inf"):
  #ゴールの分も引く
  change_squares = w_squares - score - 1
  print(change_squares)
else:
  print(-1)

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

using namespace std;

#define rep(i, n) for(int i = 0; i < (int)n; ++i)
#define FOR(i, a, b) for(int i = a; i < (int)b; ++i)
#define rrep(i, n) for(int i = ((int)n - 1); i >= 0; --i)

using ll = long long;
using ld = long double;

const ll INF = 1e18;
const int Inf = 1e9;
const double EPS = 1e-9;
const ll MOD = 1e9 + 7;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(0);
	int n;
	cin >> n;
	vector<int> p(n), q(n);
	rep (i, n) {
	  cin >> p[i];
	  q[i] = i + 1;
	}
	int cnt = 0;
	rep (i, n) if (p[i] != q[i]) cnt++;
	cout << (cnt <= 2 ? "YES" : "NO") << endl;
	
    return 0;
}



Measured memory_bytes: 3616
#include<bits/stdc++.h> 
//#define <- プログラムの文字列を置換する
//typedef <- 新しい型に名前を付けるためのキーワード

using namespace std;

#define MAX_N 1

typedef long long ll;

const double PI = 3.141592653589793;
const long long MOD = 1e9 + 7;
const long long INF = 1e15;
const int INF_INT = 1e9;


int main(){
    int a,b;
    cin >> a >> b;
    if(a >= b) cout << a + max(a-1,b) << endl;
    else cout << b + max(a,b-1) << endl;
    return 0;
}

Measured memory_bytes: 256
n, k = map(int, input().split())

MOD = 10**9 + 7

class mint:
    def __init__(self, i):
        self.i = i

    def __add__(self, m):
        t = self.i + (m.i if isinstance(m, mint) else m)
        if t > MOD:
            t -= MOD
        return mint(t)

    def __radd__(self, m):
        t = self.i + (m.i if isinstance(m, mint) else m)
        if t > MOD:
            t -= MOD
        return mint(t)

    def __mul__(self, m):
        return mint(self.i * m.i % MOD)

    def __sub__(self, m):
        t = self.i - m.i
        if t < 0:
            t += MOD
        return mint(t)

    def __pow__(self, m):
        i = self.i
        res = 1
        while(m > 0):
            if m & 1:
                res = res * i % MOD 
            i = i * i % MOD
            m >>= 1
        return mint(res)

    def __truediv__(self, m):
        return mint(self.i * m ** (MOD - 2) % MOD)

    def __repr__(self):
        return repr(self.i)

l = [mint(0) for _ in range(k + 1)]

for x in range(k, 0, -1):
    count = mint(k // x) ** n
    for tx in range(x + x, k + 1, x):
        count -= l[tx]
    l[x] = count

ans = sum(mint(i) * x for i, x in enumerate(l))
print(ans)



Measured memory_bytes: 27200
package main

import (
	"fmt"
	"sort"
)

func main() {
	var n int
	fmt.Scan(&n)
	numbers := make([]int, n)
	for i := range numbers {
		fmt.Scan(&numbers[i])
	}
	sort.Ints(numbers)
	var total int
	for i := range numbers {
		total += numbers[i]
	}
	fmt.Printf("%d %d %d\n", numbers[0], numbers[n-1], total)
}

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

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long int 
#define append push_back
#define mp make_pair
#define endl "\n"
#define MOD 1e9+7 

template <typename T>
void print(T AA[], int nn){for(int ii=0; ii<nn; ii+=1){cout<<AA[ii]<<" ";}cout<<endl;}
template <typename T> inline void print(T nn){ cout << nn << endl;}
/* ----------------------------------------------------------------------------------- */

const int N = 1e5+1;
int A[N][3], cache[N][3], n;

int fn(int i, int prev){
    if(i==n) return 0;
    if(prev != -1 && cache[i][prev] != -1) return cache[i][prev];
    int ans = 0;
    for(int j=0; j<3; j+=1){
        if(j != prev) ans = max(ans, A[i][j]+fn(i+1, j));

    }
  	if(prev!=-1) cache[i][prev] = ans;
    return ans;
}

int32_t main(){

    IOS
    
    memset(cache, -1, sizeof(cache));
    cin >> n;
    for(int i=0; i<n; i+=1) cin >> A[i][0] >> A[i][1] >> A[i][2];
    print(fn(0, -1));
    return 0;
}


Measured memory_bytes: 12800
#include<stdio.h>

int main(void)
{
	int point[4];
	int i;
	int sum[2],max=0;
	
	sum[0]=0;
	sum[1]=0;

	for (i=0;i<2;i++) {
		scanf("%d %d %d %d",&point[0],&point[1],&point[2],&point[3]);
		sum[i]+=point[0]+point[1]+point[2]+point[3];
		if(max < sum[i]) {
			max=sum[i];
		}
	}

	printf("%d\n",max);

	return 0;
}

Measured memory_bytes: 1020
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = Integer.parseInt(sc.next());
		if (n < 6) {
			System.out.println(n);
			return;
		}
		System.out.println(r(n, 0));
	}
	public static int r(int m, int ans) {
		if (m < 6) return ans + m;
		int a = 0;
		int i = 6;
		while (i * 6 <= m)
			i *= 6;
		int j = 9;
		while (j * 9 <= m)
			j *= 9;
		if (m > 8) {
			return Math.min(r(m - i, ans + 1), r(m - j, ans + 1));
		}
		else
			return r(m - i, ans + 1);
	}
}

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

int n,m;
vector<int>G[200010];
vector<int>D(200010,-1);

void solve() 
{
    cin>>n>>m;
    REP(i,m){
        int a,b;cin>>a>>b;
        a--;b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    queue<int>q;
    q.push(0);
    while(!q.empty()){
        int tmp=q.front();q.pop();
        for(auto it:G[tmp]){
            if(D[it]==-1){
                D[it]=tmp;
                q.push(it);
            }
        }
    }
    bool flag=0;
    REP(i,n){
        if(D[i]==-1){
            flag=1;
            break;
        }
    }

    if(flag){
        cout<<"No"<<endl;
    }else{
        cout<<"Yes"<<endl;
        rep(i,1,n)cout<<D[i]+1<<endl;
    }
}

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

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

int main()
{
    int N, M, X, Y;
    cin >> N >> M >> X >> Y;

    vector<int> x(N), y(M);
    for( int i = 0; i < N; ++i )
        cin >> x[i];
    for( int i = 0; i < M; ++i )
        cin >> y[i];

    for( int i = X+1; i < Y+1; ++i ){
        bool ans = true;

        for( int j = 0; j < N; ++j ){
            if( i <= x[j] ){
                ans = false;
                break;
            }
        }

        if( ans ){
            for( int j = 0; j < M; ++j ){
                if( y[j] < i ){
                    ans = false;
                    break;
                }
            }
        }

        if( ans ){
            cout << "No War" << endl;
            return 0;
        }
    }

    cout << "War" << endl;

    return 0;
}


Measured memory_bytes: 256
n=gets.to_i
a=gets.split.map(&:to_i)
n.times do |i|
  if i<n/2
    puts a[n-1-2*i]
  elsif i==n/2
    puts a[0]
  else
    puts a[(i-n/2)*2-n%2] 
  end
end


Measured memory_bytes: 21764
package main

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

var c [][]int

func main() {
  n := NextInt()
  c = make([][]int,n+1)
  for i:=2;i<n+1;i++ {
    m := NextInt()
    c[m] = append(c[m],i)
  }
  fmt.Println(dfs(1)-1)
}

func dfs(v int) int {
  if len(c[v]) == 0 { return 1 }
  var d []int = []int{math.MaxInt32}
  for _,e := range c[v] { d = append(d,dfs(e)) }
  sort.Sort(sort.Reverse(sort.IntSlice(d)))
  var m int
  for i:=1;i<len(d);i++ {
    if m < d[i]+i { m = d[i]+i }
  }
  return m
}

var reader = bufio.NewReaderSize(os.Stdin,1000000)
func NextInt() int {
  var buffer []byte
  for {
    line,isPrefix,err := reader.ReadLine()
    if err != nil { panic(err) }
    buffer = append(buffer,line...)
    if !isPrefix { break }
  }
  n,_ := strconv.Atoi(string(buffer))
  return n
}

Measured memory_bytes: 62464
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <string>
#include <functional>
#include <utility>
#include <queue>
#include <vector>
#include <string>
using namespace std;
typedef long long int ll;
const ll  MOD = 1000000007;


int main(){
  string s;
  cin >> s;
  cout << s.substr(0,4) << " " << s.substr(4) << endl;
}


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

int main(){

int n;
cin>>n;
int d[n],sum=0;
REP(i,n){
    cin>>d[i];
}
for (int i = 0; i < n-1; i++)
{
    /* code */
    for (int j = i+1; j < n; j++)
    {
        /* code */
        sum+=d[i]*d[j];
    }
    
}
cout<<sum<<endl;


}


Measured memory_bytes: 256
#include<iostream>

using namespace std;
int main()
{
    int N,r=0,count=0;
    cin>>N;
    for(int i=1;i<=N;i++){
        if(i%2!=0){
            for(int j=1;j<=i;j++){
                if(i%j==0){
                    r++;
                }
            }
            if(r==8){
                count++;
            }
            r=0;
        }
    }
    cout<<count<<endl;
}

Measured memory_bytes: 256
let to_list str =
  let rec doit i acc =
    if i < 0 then acc
    else doit (i - 1) (String.get str i :: acc)
  in
  doit (String.length str - 1) []

let calc_area lst =
  let rec doit (i, idxs, acc) = function
    | '_' -> (i + 1, idxs, acc)
    | '\\' -> (i + 1, i :: idxs, acc)
    | '/' -> begin
        match idxs with
        | [] -> (i + 1, idxs, acc)
        | j :: js -> (i + 1, js, ((j, i), i - j) :: acc)
      end
    | _ -> exit 1
  in
  let (_, _, acc) = List.fold_left doit (0, [], []) lst in
  acc

let integrale lst =
  let rec doit acc = function
    | [] -> acc
    | [e] -> e :: acc
    | (((j1, i1), area1) as xs) :: ((((j2, i2), area2) :: tl) as ys) ->
        if j1 < j2 && i1 > i2 then doit acc (((j1, i1), area1 + area2) :: tl)
        else doit (xs :: acc) ys
  in
  doit [] lst

let () =
  let areas = integrale (calc_area (to_list (read_line ()))) in
  Printf.printf "%d\n" (List.fold_left (fun acc (_, n) -> acc + n) 0 areas);
  Printf.printf "%d" (List.length areas);
  List.iter (fun (_, n) -> Printf.printf " %d" n) areas;
  print_newline ()

Measured memory_bytes: 5028
import collections

s=input()

s=list(s)

c = collections.Counter(s)

score_sorted = sorted(c.items(), key=lambda x:-x[1])

val = []

for i, j in score_sorted:
    val.append(j)


if len(val) == 2:
    val.append(0)
elif len(val) == 1:
    val.append(0)
    val.append(0)
    
val.sort()

if 0<= val[2]-val[0] <=1:
    print('YES')
else:
    print('NO')

Measured memory_bytes: 49392
import java.util.*;

public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		long n = sc.nextLong();
		int min = Integer.MAX_VALUE;
		for (int i = 1; i <= Math.sqrt(n); i++) {
		    if (n % i == 0) {
		        min = Math.min(min, function(i, n / i));
		    }
		}
		System.out.println(min);
	}
	
	static int function(long a, long b) {
	    return Math.max(getCount(a), getCount(b));
	}
	
	static int getCount(long x) {
	    int ans = 0;
	    while (x > 0) {
	        ans++;
	        x /= 10;
	    }
	    return ans;
	}
}


Measured memory_bytes: 21844
N = int(input())
s = []
t = []

for i in range(N):
    S, T = list(map(str, input().split()))
    s.append(S)
    t.append(int(T))

X = input()

index = s.index(X)
ans = sum(t)
for i in range(index+1):
    ans -= t[i]
print(ans)

Measured memory_bytes: 3064
#![allow(non_snake_case)]
#![allow(unused_imports)]

use proconio::{input, fastout};
use proconio::marker::*;
use whiteread::parse_line;
use std::collections::*;
use num::*;

use itertools::Itertools;
use itertools_num::ItertoolsNum;

#[fastout]
fn main() {
    input!{
        a: isize, b: isize, c: isize,
    }

    let flag = a <= c && c <= b;

    if flag {
        println!("Yes");
    } else {
        println!("No");
    }
    
}


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

int main() {
    int n;
    std::cin >> n;
    std::vector<int> a(n), b(n);
    for (auto &el : a) std::cin >> el;
    for (auto &el : b) std::cin >> el;
    int ret = 0;
    for (int i = 0; i < n; i++) {
        ret += std::max(0, a[i] - b[i]);
    }
    std::cout << ret << std::endl;

    return 0;
}


Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;

public class Main {
 
	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		int a[] = new int[5];
		for (int i = 0; i < 5; i++) {
			a[i] = stdIn.nextInt();
		}
		Arrays.sort(a);
		for(int i=4;-1<i;i--){
			System.out.print(a[i]);
			if(i!=0)
				System.out.print(" ");
			else
				System.out.println();
		}
	}
}

Measured memory_bytes: 17224
using System;

namespace abc177_b
{
  class Program
  {
    static void Main(string[] args)
    {
      var S = Console.ReadLine();
      var T = Console.ReadLine();

      var ans = T.Length;

      for (int i = 0; i <= S.Length - T.Length; i++)
      {
        var c = 0;
        for (int j = 0; j < T.Length; j++)
        {
          if (S[i + j] != T[j]) c++;
        }

        ans = Math.Min(ans, c);
      }

      Console.WriteLine(ans);
    }
  }
}


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

#define ll long long
#define pb push_back
#define vi vector<int>
#define FOR(i, a, b) for(int i = a; i < b; i++)
#define sizeOf(A) (sizeof(A))/(sizeof(A[0]))
#define odd(x) ((x) % (2))
#define fastio ios_base::sync_with_stdio(false), cin.tie(0);
const ll MOD = 1e9 + 7;

int main() {
    fastio;

    int n, k;
    cin >> n >> k;
    int A[n];
    FOR(i, 0, n) {cin >> A[i];}
    sort(A, A + n);
    int sum = 0;
    FOR(i, 0, k) {
        sum += A[n-1-i];
    }
    cout << sum << "\n";
    return 0;
}
	

Measured memory_bytes: 256
A = int(input())
B = int(input())
C = int(input())
X = int(input())

ans = 0
for i in range(A + 1):
    for j in range(B + 1):
        for k in range(C + 1):
            if 500 * i + 100 * j + 50 * k == X :
                ans += 1
print(ans)


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

int main(){
    int h, w;
    cin >> h >> w;
    int n;
    cin >> n;
    queue<int> que;
    int tmp;
    for (int i = 0; i < n; i++) {
        cin >> tmp;
        for (int j = 0; j < tmp; j++) que.push(i+1);
    }

    vector<vector<int>> ans(h, vector<int>(w));
    for (int i = 0; i < h; i++){
        for (int j = 0; j < w; j++){
            int x = que.front(); que.pop();
            if (i % 2) ans[i][w-j-1] = x;
            else ans[i][j] = x;
        }
    }

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

Measured memory_bytes: 384
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <iostream>
using namespace std;
const int maxn=1e6;
const int maxc=1e6;
int a[maxn], cnt[maxc], ans[maxn], belong[maxn];
struct query {
    int l, r, time, id;
} q[maxn];
struct modify {
    int pos, color, last;
} c[maxn];
int cntq, cntc, n, m, size, bnum;
int cmp(query a, query b) {
    return (belong[a.l] ^ belong[b.l]) ? belong[a.l] < belong[b.l] : ((belong[a.r] ^ belong[b.r]) ? belong[a.r] < belong[b.r] : a.time < b.time);
}
#define isdigit(x) ((x) >= '0' && (x) <= '9')
inline int read() {
    int res = 0;
    char c = getchar();
    while(!isdigit(c)) c = getchar();
    while(isdigit(c)) res = (res << 1) + (res << 3) + (c ^ 48), c = getchar();
    return res;
}
int main() {
    n = read();
    char s[maxn];
    scanf("%s",s+1);
	 m = read();
    size = pow(n, 2.0 / 3.0);
    bnum = ceil((double)n / size);
    for(int i = 1; i <= bnum; ++i) 
        for(int j = (i - 1) * size + 1; j <= i * size; ++j) belong[j] = i;
    for(int i = 1; i <= n; ++i) 
        a[i] =s[i]-'a';
    for(int i = 1; i <= m; ++i) {
        int opt;
        scanf("%d",&opt);
        if(opt==2) {
            q[++cntq].l = read();
            q[cntq].r = read();
            q[cntq].time = cntc;
            q[cntq].id = cntq;
        }
        else if(opt==1) {
            c[++cntc].pos = read();
            char cc[2];
            scanf("%s",cc);
            c[cntc].color =cc[0]-'a';
        }
    }
    sort(q + 1, q + cntq + 1, cmp);
    int l = 1, r = 0, time = 0, now = 0;
    for(int i = 1; i <= cntq; ++i) {
        int ql = q[i].l, qr = q[i].r, qt = q[i].time;
        while(l < ql) now -= !--cnt[a[l++]];
        while(l > ql) now += !cnt[a[--l]]++;
        while(r < qr) now += !cnt[a[++r]]++;
        while(r > qr) now -= !--cnt[a[r--]];
        while(time < qt) {
            ++time;
            if(ql <= c[time].pos && c[time].pos <= qr) now -= !--cnt[a[c[time].pos]] - !cnt[c[time].color]++;
            swap(a[c[time].pos], c[time].color);
        }
        while(time > qt) {
            if(ql <= c[time].pos && c[time].pos <= qr) now -= !--cnt[a[c[time].pos]] - !cnt[c[time].color]++;
            swap(a[c[time].pos], c[time].color);
            --time;
        }
        ans[q[i].id] = now;
    }
    for(int i = 1; i <= cntq; ++i) 
        printf("%d\n", ans[i]);
    return 0;
}


Measured memory_bytes: 15104
#include <cstdio>
#include <iostream>
#include <cstring>
#include <string>
#include <cmath>
#include <algorithm>
#include <cstdlib>
#include <utility>
#include <map>
#include <stack>
#include <set>
#include <vector>
#include <queue>
#include <deque>
#define x first
#define y second
#define mp make_pair
#define pb push_back
#define LL long long
#define Pair pair<int,int>
#define LOWBIT(x) x & (-x)
using namespace std;

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

vector<int> v[200048];
int n,e;
int dist[200048];
priority_queue<Pair> q;

void dijkstra()
{
	int i,x,y,dd;
	for (i=1;i<=n;i++) dist[i]=INF;
	dist[1]=0;q.push(mp(0,1));
	while (!q.empty())
	{
		x=q.top().y;dd=-q.top().x;q.pop();
		if (dd>dist[x]) continue;
		for (i=0;i<v[x].size();i++)
		{
			y=v[x][i];
			if (dist[y]>dist[x]+1)
			{
				dist[y]=dist[x]+1;
				q.push(mp(-dist[y],y));
			}
		}
	}
}

int main ()
{
	int i,x,y;
	scanf("%d%d",&n,&e);
	for (i=1;i<=e;i++)
	{
		scanf("%d%d",&x,&y);
		v[x].pb(y);v[y].pb(x);
	}
	dijkstra();
	if (dist[n]<=2) printf("POSSIBLE\n"); else printf("IMPOSSIBLE\n");
	return 0;
}

Measured memory_bytes: 13936
//#pragma comment(linker, "/STACK:102400000,102400000")
#include <fstream>
#include <iostream>
#include <functional>
#include <algorithm>
#include <sstream>
#include <cstring>
#include <vector>
#include <string>
#include <cstdio>
#include <cmath>
#include <queue>
#include <stack>
#include <deque>
#include <ctime>
#include <list>
#include <set>
#include <map>
#include <bitset>
#include <cassert>
#include <unordered_map>
#include <unordered_set>
using namespace std;

typedef long long ll;
#define eps 1e-8
#define LL_INF 0x3fffffffffffffff
#define INF 0x3f3f3f3f
#define mem(a, b) memset(a, b, sizeof(a))
#define pper(i,n,m) for(int i = n;i >= m; i--)
#define repp(i, n, m) for (int i = n; i <= m; i++)
#define rep(i, n, m) for (int i = n; i < m; i++)
#define sa(n) scanf("%d", &(n))
#define mp make_pair
#define ff first
#define ss second
#define pb push_back
#define DE(val) cout<<#val<<": "<<val<<endl;

const int dx4[5] = { 0,-1,0,1,0 };
const int dy4[5] = { 0,0,1,0,-1 };
const int dx8[9] = { 0,-1,0,1,0,1,1,-1,-1 };
const int dy8[9] = { 0,0,1,0,-1,1,-1,1,-1 };
const int maxn = 2e5+10;
const double PI = acos(-1.0);
const ll mod = 1e9 + 7;
ll po(ll a, ll b, ll mod) { ll res = 1; a %= mod; for (; b; b >>= 1) { if (b & 1)res = res*a%mod; a = a*a%mod; }return res; }
ll gcd(ll a, ll b) { if (a == 0) { return b; } else { return gcd(b%a, a); } }
void YES() { puts("YES"); exit(0); }
void Yes() { puts("Yes");}// exit(0); }
void NO() { puts("NO"); exit(0); }
void No() { puts("No");}// exit(0); }
void one() { puts("-1"); exit(0); }

int n;
int val[maxn];
ll fac[maxn],inv[maxn];
ll ans[maxn];

ll C(ll x,ll y)
{
	return fac[x]*inv[y]%mod*inv[x-y]%mod;
}

void init()
{
	fac[0]=1;
	inv[0]=1;
	repp(i,1,200005)
	{
		fac[i]=fac[i-1]*i%mod;
		inv[i]=po(fac[i],mod-2,mod);
	}
}

map<int,int>hax;
void solve()
{
	sa(n);
	n++;
	int st=0,en=n;
	repp(i,1,n)
	{
		sa(val[i]);
		if(hax.count(val[i]))
		{
			st=hax[val[i]];
			en=i;
		}
		hax[val[i]]=i;
	}
	//DE(st)
	//DE(en)
	repp(i,1,n)
	{
		ans[i]=C(n,i);
	}
	ll left = st-1;
	ll right = n-en;
	//DE(left)
	//DE(right)
	repp(i,1,n)
	{
		if(i-1>right+left)
		{
			printf("%lld\n", ans[i]);
			continue;
		}
		ans[i]=ans[i]-C(left+right,i-1);
		ans[i]=(ans[i]%mod+mod)%mod;
		printf("%lld\n",ans[i]);
	}
}

int main()
{
	init();
	solve();
	//system("pause");
	return 0;
}







Measured memory_bytes: 10240
#include<bits/stdc++.h>
using namespace std;
#define MAX 200005

int H,W,N;

int first(int id){
  return(id%2?min(W,id+1):max(1,id-1));
}

int second(int id){
  return (id%2?max(1,id-1):min(W,id+1));
}

int mem[30][MAX];

int func(int k,int id){
  if(k==0)return first(second(id));
  if(mem[k][id])return mem[k][id];
  return mem[k][id]=func(k-1,func(k-1,id));
}

int calc(int h,int id){
  int S=h/2;
  if(h%2)id=first(id);
  for(int i=0;i<20;i++)if(S>>i&1)id=func(i,id);
  return id;
}

int a,b;
vector<int> G[MAX];
int ans[MAX];
int main(){
  
  scanf("%d %d %d",&H,&W,&N);
  

  for(int i=0;i<N;i++){
    scanf("%d %d",&a,&b);
    G[a].push_back(b);
  }
  for(int i=1;i<=W;i++)ans[calc(H,i)]=i;
  for(int i=MAX-1;i;i--){
    for(int j=0;j<(int)G[i].size();j++){
      int k=G[i][j];
      int a=calc(i-1,k),b=calc(i-1,k+1);
      swap(ans[a],ans[b]);
    }
  }
  for(int i=1;i<=W;i++)printf("%d\n",ans[i]);
  return 0;
}

Measured memory_bytes: 25648
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0,i##_len=int(n);i<i##_len;++i)
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
#define All(x) (x).begin(),(x).end()
#define rAll(x) (x).rbegin(),(x).rend()
using namespace std;
using ll = long long;

int main(){
    int N,K;cin>>N>>K;
    int ans=0;
    while(N){
        N/=K;
        ans++;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstring>
using namespace std;
int main()
{
	char x,y;
    cin >> x >> y;
    if (x < y)
    {
    	cout << "<" << endl;
	}
    if (x > y)
    {
		cout << ">" << endl;
	}
    if (x == y)
    {
    	cout << "=" << endl;
	}
     return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const double pi=acos(-1.0);
const double eps=1e-8;
typedef long long ll;
#define equ(a,b) ((fabs((a)-(b)))<(eps))
#define more(a,b) (((a)-(b))>(eps))
#define less(a,b) (((a)-(b))<(-eps))
#define inf 0x3f3f3f3f

int main(){
    ll n;
    ll a[100005],s=1,flag=0,s2=1e18;
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    for(int i=0;i<n;i++){
        if(a[i]==0){
            cout<<0;
            return 0;
        }
    }
    for(int i=0;i<n;i++){
        ll x=s;
        s*=a[i];
        if(s<x||s>s2){
            cout<<-1;
            return 0;
        }
    }
    cout<<s;
    return 0;
}

Measured memory_bytes: 4360
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <map>
using namespace std;
typedef long long ll;
#define rep(i,n) for (int i = 0; i < int(n);i++)

int main(){
   ll a,v,b,w,t;
   cin >> a >> v >> b >> w >> t;
   if (v-w <= 0) {
      cout << "NO" << endl;
   } 
   else{
      if ((abs(a-b) + (v-w) -1)/(v-w) <= t) cout << "YES" << endl;
      else cout << "NO" << endl;
   }

   return 0;
   

}


Measured memory_bytes: 3620
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include<math.h>
#define ll long long
long long min(long long a, long long b){
    if(a < b) return a;
    else return b;
}
long long max(long long a, long long b){
    if(a < b) return b;
    else return a;
}
int main(){
  int n,k;
  scanf("%d",&n);
  char s[101];
  scanf("%s",s);
  k=strlen(s);
  if(n>=k){
    printf("%s",s);
  }
  else{
    for(int i=0;i<n;i++){
      printf("%c",s[i]);
    }
    printf("...");
  }
  return 0;
}

Measured memory_bytes: 1732
main = do
    s <- getLine
    print $ sum (map read (concat (decompose s)))

decompose :: String -> [[String]]
decompose st
    | length st == 1 = [[st]]
    | otherwise = (map ([head st]:) (decompose (tail st))) ++ [((head st):y):ys | (y:ys) <- decompose (tail st) ]

Measured memory_bytes: 4928
#include <iostream>
//#include <iomanip>
#include <string>
//#include <vector>
#include <algorithm>
//#include <utility>
//#include <set>
//#include <map>
//#include <queue>
//#include <deque>
//#include <bitset>
//#include <math.h>
using namespace std ;
using ll = long long ;
//using ld = long double ;
//using vll = vector<ll> ;
//using vvll = vector<vll> ;
//using vc = vector<char> ;
//using vvc = vector<vc> ;
//using vb = vector<bool> ;
//using vvb = vector<vb> ;
//using pll = pair<ll,ll> ;
#define all(v) v.begin(),v.end()
//ll mod = 1000000007 ;
//long double pie = acos(-1) ;
//ll INF = 1000000000000 ;

void yorn(bool a){if(a) cout << "Yes" << endl ; else cout << "No" << endl ;}
//void YorN(bool a){if(a) cout << "YES" << endl ; else cout << "NO" << endl ;}
//ll gcd(long long a,long long b){if(b==0) return a ; return gcd(b,a%b) ;}
//ll lcm(long long a,long long b){return a/gcd(a,b)*b ;}
//ll sa(long long a,long long b){if(a>b) return a-b ; return b-a ;}
//void mysort(vector<long long> &a){sort(a.begin(),a.end()) ;}
//void myrev(vector<long long> &a){reverse(a.begin(),a.end()) ;}
//void fix_cout(){cout << fixed << setprecision(20) ;}

int main(){
	string s,t ;
	cin >> s >> t ;
	sort(all(s)) ;
	sort(all(t)) ;
	reverse(all(t)) ;
	yorn(s<t) ;
}



Measured memory_bytes: 256
from collections import deque
s = deque(list(input()))
q = int(input())
query = [[1, 0, ''] for i in range(q)]
for i in range(q):
    tmp = input().split()
    if tmp[0] == '2':
        query[i][0] = int(tmp[0])
        query[i][1] = int(tmp[1])
        query[i][2] = tmp[2]

dire = 1
for i in range(q):
    if query[i][0] == 1:
        dire *= -1
    else:
        if (2*query[i][1]-3) * dire == 1:
            s.append(query[i][2])
        else:
            s.appendleft(query[i][2])

ans = ''.join(s)
if dire == 1:
    print(ans)
else:
    print(ans[::-1])

Measured memory_bytes: 122668
#!/usr/bin/env python3
import sys, itertools 
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
sys.setrecursionlimit(10**8)
inf = float('inf')
ans = count = 0



a, b, c = map(int, input().split())
for i in itertools.permutations([a, b, c], 3):
    if i[0] == sum(i[1:]) or sum(i[:2]) == i[2]:
        print("Yes")
        exit()

print("No")


Measured memory_bytes: 38256
n, q = map(int, input().split())
l = [[] for i in range(n)]
for i in range(n - 1):
    a, b = map(int, input().split())
    l[a - 1].append(b - 1)
    l[b - 1].append(a - 1)
r = [0] * n
for i in range(q):
    p, x = map(int, input().split())
    r[p - 1] += x
stack = [0]
used = [False] * n    
while stack:
    i = stack.pop()
    used[i] = True
    for to in l[i]:
        if not used[to]:
            stack.append(to)
            r[to] += r[i]
for t_r in r:
    print(t_r) 

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

int main() {
  ll a, b;
  cin >> a >> b;
  if (a * b <= 0) {
    cout << "Zero" << endl;
  } else {
    if (a < 0 && (b - a) % 2 == 0) {
      cout << "Negative" << endl;
    } else {
      cout << "Positive" << endl;
    }
  }
  return 0;
}


Measured memory_bytes: 256
quit() = exit(0)
in_1() = parse(Int, readline())
in_a() = [parse(Int,s) for s in split(readline())]

function main()
  M = 10^9 + 7
  n, a, b = in_a()
  
  num_a, den_a, num_b, den_b = 1, 1, 1, 1
  num, den = 1, 1
  for i in 1:max(a, b)
    num = mod(num * (n-i+1), M)
    den = mod(den * i, M)
    if i == a
      num_a = num
      den_a = den
    end
    if i == b
      num_b = num
      den_b = den
    end
  end
  cmb_n_a = mod(num_a * invmod(den_a, M), M)
  cmb_n_b = mod(num_b * invmod(den_b, M), M)
  
  ans = mod(powermod(2, n, M) - 1 - cmb_n_a - cmb_n_b, M)
  println(ans)
end

isempty(ARGS) && main()


Measured memory_bytes: 151812
import java.util.*;
import java.io.*;
public class Main {

	public static void main(String[] args) {
		Scanner in=new Scanner(System.in);
		PrintWriter out=new PrintWriter(System.out);
		int n=Integer.parseInt(in.next());
		List<Integer> A=new ArrayList<>();
		for(int i=0;i<n;i++)A.add(Integer.parseInt(in.next()));
		int q=Integer.parseInt(in.next());
		
		Comparator<Integer> lower = (x, y) -> x.compareTo(y) >= 0 ? 1 : -1;
		for(int i=0;i<q;i++) {
			int key=Integer.parseInt(in.next());
			int p=~Collections.binarySearch(A, key, lower);
			if(p>=0)out.println(p);
			else out.println(n);
		}
		out.flush();
	}
}


Measured memory_bytes: 93392
import java.io.PrintWriter

fun next() = readLine()!!
fun nextInt() = next().toInt()
fun nextLong() = next().toLong()
fun nextDouble() = next().toDouble()
fun nextList() = next().split(" ")
fun nextIntList() = nextList().map(String::toInt)
fun nextLongList() = nextList().map(String::toLong)
fun nextDoubleList() = nextList().map(String::toDouble)

val pw = PrintWriter(System.out)
fun print(s: Any = "") = pw.print(s)
fun println(s: Any = "") = pw.println(s)

fun <T> Iterable<T>.join(separator: CharSequence = ", ", prefix: CharSequence = "", postfix: CharSequence = "") = joinToString(separator, prefix, postfix)
fun <T> Array<T>.join(separator: CharSequence = ", ", prefix: CharSequence = "", postfix: CharSequence = "") = joinToString(separator, prefix, postfix)

fun main(args: Array<String>) {
    main()
    pw.flush()
}

fun main() {
    val (H, W) = nextIntList()
    val A = Array(H) { nextIntList().toMutableList() }
    val ans = ArrayList<String>()
    for (y in 0 until H) {
        for (x in 0 until W) {
            val xx = if (y % 2 == 0) x else W - 1 - x
            val yy = y
            val nx = if ((y % 2 == 1 && xx == 0) || (y % 2 == 0 && xx == W - 1)) xx else if (y % 2 == 0) xx + 1 else xx - 1
            val ny = if ((y % 2 == 1 && xx == 0) || (y % 2 == 0 && xx == W - 1)) yy + 1 else yy
            if (ny != H && A[yy][xx] % 2 == 1) {
                ans.add("${yy + 1} ${xx + 1} ${ny + 1} ${nx + 1}")
                A[ny][nx]++
            }
        }
    }
    println(ans.size)
    for (s in ans) println(s)
}

Measured memory_bytes: 67204
#include<iostream>
#include<algorithm>
#include<vector>
#include <iomanip>
#include <math.h>
 
using namespace std;
 
int main(){

	int r, c;
  	cin >> r >> c;
  
  	vector<vector<int> >Table(r, vector<int>(c));
  	vector<int> zentai(c+1);
  
  	for(int i=0; i<r; i++){
    	for(int j=0; j<c; j++){
    		cin >> Table.at(i).at(j);
        }
    }
  
  	for(int i=0; i<r; i++){
      	int sum=0;
    	for(int j=0; j<c; j++){
    		cout << Table.at(i).at(j) << " ";
      		sum += Table.at(i).at(j);
          	zentai.at(j) += Table.at(i).at(j);
        }
      	cout << sum <<endl;
    }
  
  	int sougoukei =0;
  	for(int i=0; i<c; i++){
    	cout << zentai.at(i) << " ";
      	sougoukei += zentai.at(i);
    }
  	cout << sougoukei << endl;

  return 0;
}


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

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    cin >> n;
    vi a(n);
    rep(i,0,n) cin >> a[i];
    vector<pair<int,int>> xs;
    rep(i,0,n) xs.emplace_back(a[i],i);
    sort(all(xs));
    vi ans(n);
    vi c(n);
    rep(i,0,n) {
        c[i]=xs[i].second;
    }
    rep(i,0,n/2) {
        ans[c[i]]=xs[n/2].second;
    }
    rep(i,n/2,n) {
        ans[c[i]]=xs[n/2-1].second;
    }
    rep(i,0,n) cout<<a[ans[i]]<<"\n";
}


Measured memory_bytes: 6128
#!/usr/bin/env python3
import sys
from collections.abc import Iterable
from math import *
from itertools import *
from collections import *
from functools import *
from operator import *
try:
    from math import gcd
except Exception:
    from fractions import gcd

MOD = 1000000007  # type: int

def solve(L):
    dp = [[0] * 2 for _ in range(len(L) + 1)]
    dp[0][0] = 1

    for i, c in enumerate(L):
        # a=0, b=0
        if c == '0':
            dp[i+1][0] = dp[i][0]
            dp[i+1][1] = dp[i][1]
        else:
            dp[i+1][1] = (dp[i][0] + dp[i][1])

        # a=1, b=0
        if c == '0':
            dp[i+1][1] += dp[i][1]
        else:
            dp[i+1][0] += dp[i][0]
            dp[i+1][1] += dp[i][1]

        # a=0, b=1
        if c == '0':
            dp[i+1][1] += dp[i][1]
        else:
            dp[i+1][0] += dp[i][0]
            dp[i+1][1] += dp[i][1]

        dp[i+1][0] %= MOD
        dp[i+1][1] %= MOD

    return sum(dp[-1]) % MOD


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    L = next(tokens)  # type: int
    result = solve(L)
    if isinstance(result, Iterable) and not isinstance(result, str):
        result = '\n'.join([str(v) for v in result])
    print(result)

if __name__ == '__main__':
    main()


Measured memory_bytes: 21896
#include<iostream>
#include<vector>
#include<algorithm>
#include<cctype>
#include<utility>
#include<string>
#include<cmath>

#define REP(i,n) for(int i = 0;i < n;i++)
#define LLREP(n) for(long long int  i = 0;i < n;i++)
typedef long long int ll;
using namespace std;
#define MAX_A 100005

 
 
int main() {
    int n, m;
    cin >> n >> m;
    vector<ll> a(n),b(n),c(n);
    
	REP(i, n){
        cin >> a[i] >> b[i] >> c[i];
    }

	ll maxi = 0;
    
    REP(i, 1 << 3){        
        
        vector<ll> tmp(n);
        
		REP(j,n){

            ll tmp_x = 0;
            
            if(i >> 0 & 1){
                tmp_x += a[j];
             }else{
                tmp_x += -a[j];
             }

            if(i >> 1 & 1){
                tmp_x += b[j];
            }else{
                tmp_x += -b[j];
            }
            
            if(i >> 2 & 1){
                tmp_x += c[j];
            }else{
                tmp_x += -c[j];
            }

            tmp[j] = tmp_x;
            
        }
        
		sort(tmp.begin(), tmp.end(),greater<ll>());
		ll sum = 0;
        REP(j, m){
            sum += tmp[j];
        }
        maxi = max(maxi, sum);
        
	}
	cout << maxi << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
const int mod = 1e9 + 7;
//const int mod = 998244353;
const ll infll = (1LL << 62) - 1;
const int inf = (1 << 30) - 1;
void YesNo(bool j){cout << (j ? "Yes" : "No") << endl; return;}
void yesno(bool j){cout << (j ? "yes" : "no") << endl; return;}
template<class Head> void pt(Head&& head){cout << head << endl; return;}


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


Measured memory_bytes: 3680
#include <stdio.h>

int main(void){
	int a[3],i,j;
	scanf("%d %d %d",&a[0],&a[1],&a[2]);
	if(a[0]+a[1]+a[2]!=17){
		printf("NO\n");
	}else{
		for(i=0;i<3;i++){
			if(a[i]==5){
				for(j=0;j<3;j++){
					if(a[j]==7){
						printf("YES\n");
						return 0;
					}
				}
			}
		}
		printf("NO\n");
	}
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define int long long int
#define pb push_back
#define vec vector<int>
#define fo(i, n) for (int i = 0; i < n; i++)
#define foo(i, a, b) for (int i = a; i < b; i++)
#define mp make_pair
#define deb(x) cout << #x << "-->" << x << endl;
#define deb1a(v)                  \
    cout << #v << "--->" << endl; \
    for (auto it : v)             \
    {                             \
        cout << it << " ";        \
    }                             \
    cout << endl;
#define deb2a(v)                  \
    cout << #v << "--->" << endl; \
    for (auto it : v)             \
    {                             \
        for (auto it1 : it)       \
        {                         \
            cout << it1 << " ";   \
        }                         \
        cout << endl;             \
    }
    #define mod 998244353
 
#define fi first
#define se second
int fun(int n,int i){
    if(i==0)
        return 0;
    if(i==1)
        return n;
    else if(i==2)
        return (n * (n - 1)) / 2;
    else if(i==3)
    {
        return (n * (n - 1) * (n - 2)) / 6;
    }
    
}
int power(int i,int j){
    int ans = 1;
    while(j--)
        ans *= i;
    return ans;
}
int solve(string s,int n){
    
    if(s.size()<n)
        return 0;
    if(s.size()==0)
        return 0;
    if(s[0]=='0')
    {
       
        return solve(s.substr(1, s.size() - 1), n );
    }
    if (n == 1)
        return ((s.size()-1)*9+(s[0]-'0'));
    int nn = s.size();
    int ans = 0;
    if((nn-1)>=n)
        ans +=( fun(nn - 1, n)*power(9,n));
    ans += ((s[0] - '0'-1) * fun(nn - 1, n - 1) * power(9, n - 1));
    return ans + solve(s.substr(1, nn - 1), n - 1);
}
int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    string s;
    cin >> s;
    int n;
    cin >> n;
    cout << solve(s, n)<<endl;
   
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define X first
#define Y second
#define PB push_back
#define LL long long
#define pii pair<LL,LL>
#define MEM(x,y) memset(x,y,sizeof(x))
#define bug(x) cout<<"debug "#x" is "<<x<<endl;
#define FIO ios::sync_with_stdio(false);
#define ALL(x) x.begin(),x.end()
#define LOG 20
#define lson(x) ((x)<<1)
#define rson(x) ((x)<<1|1)
const int maxn=2e5;

LL a,b,n;
int main(){
    FIO;
    cin>>n>>a>>b;
    cout<<min(n%(a+b),a)+n/(a+b)*a<<endl;
	return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
using namespace std;
int main()
{
    string a;
    int b,c,d;
    while(cin>>a)
    {
            b=c=d=0;
for(int i=0;i<a.length();i++){
    if(a[i]=='a')
        c=1;
    if(a[i]=='b')
        b=1;
    if(a[i]=='c')
        d=1;
    }
    if(c&&b&&d)
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;
    }
}


Measured memory_bytes: 256
#include "iostream"
#include "vector"
using namespace std;

vector < vector <string> > power_set(int index, vector <string> &elements) {
    if (index == -1) {
        return {{}};
    }
    auto ps = power_set(index - 1, elements);
    vector < vector <string> > add;
    for (auto &i: ps) {
        vector <string> j(i);
        j.push_back(elements[index]);
        add.push_back(j);
    }
    ps.insert(ps.end(), add.begin(), add.end());
    return ps;
}

int main() {
    int h, w, k, ans = 0;
    cin >> h >> w >> k;
    vector < vector <int> > grid(h + 1, vector <int>(w + 1));
    // 1 if black, 0 if white
    for (int i=1; i<=h; i++) {
        for (int j=1; j<=w; j++) {
            char x;
            cin >> x;
            grid[i][j] = x == '#';
        }
    }
    vector <string> elements;
    for (int i=1; i<=h; i++) {
        elements.push_back("r" + to_string(i));
    }
    for (int i=1; i<=w; i++) {
        elements.push_back("c" + to_string(i));
    }
    auto ps = power_set(elements.size() - 1, elements);
    for (vector <string> &s: ps) {
        vector < vector <int> > new_grid(grid);
        for (string &el: s) {
            char type = el[0];
            int index = el[1] - '0';
            if (type == 'r') {
                for (int j=1; j<=w; j++) {
                    new_grid[index][j] = 0;
                }
            }
            else if (type == 'c') {
                for (int i=1; i<=h; i++) {
                    new_grid[i][index] = 0;
                }
            }
        }
        int count = 0;
        for (int i=1; i<=h; i++) {
            for (int j=1; j<=w; j++) {
                count += new_grid[i][j];
            }
        }
        if (count == k) {
            ans += 1;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 4364
#include <stdio.h>

int main(){
  long n, t[5], mini = 1e15;
  scanf("%ld", &n);
  for(int i=0; i<5; i++){
    scanf("%ld", t+i);
    if(t[i] < mini)  mini = t[i];
  }

  long ans = n / mini + (n % mini != 0 ? 1 : 0);

  printf("%ld\n", ans+4);

  return 0;
}


Measured memory_bytes: 1700
#include<stdio.h>

int main(void){
	int x=1,y[100000],z=1,a=0,b=1;
	while(x!=0){
		scanf("%d",&x);
		if(x!=0){
			y[z]=x;
			z++;
		}
	}
	while(y[b]!=0){
		printf("Case %d: %d\n",a+1,y[b]);
		b++;
		a++;
	}
	return 0;
}

Measured memory_bytes: 644
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,n) for(int i = 0; i < n; i++)
#define CloseIo std::ios::sync_with_stdio(false)
const int N = 100000 + 20;
const ll INF = 1e15+200;
int main(){
  std::ios::sync_with_stdio(false);
  ll n;
  cin>>n;
  ll a[7];
  ll min = INF;
  rep(i,5){
    cin>>a[i];
    if(a[i] < min) min = a[i];
  }
  ll sum = ((n-1)/min)+5;
  cout<<sum<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
const int inf = 1e9;
const ll INF = 1e18;
const double pi = 3.14159265358979323846;
#define rep(i,n) for(ll i=0;i<n;i++)

int main(){
	int n;cin>>n;
	int a[n];
	rep(i,n) cin>>a[i];
	sort(a,a+n);
	if(n%2==0){
		rep(i,n-1){
			if(i%2==0&&a[i]==a[i+1]) continue;
			else if(i%2==1&&a[i]+2==a[i+1]) continue;
			else {
				cout<<0<<"\n";
				return 0;
			}
		}
	}
	else{
		rep(i,n-1){
			if(i==0&&a[i]==0) continue;
			else if(i%2==0&&a[i]+2==a[i+1]) continue;
			else if(i%2==1&&a[i]==a[i+1]) continue;
			else {
				cout<<0<<"\n";
				return 0;
			}
		}
	}
	ll ans=1;
	rep(i,n/2){
		ans=ans*2%MOD;
	}
	cout<<ans<<"\n";
}

Measured memory_bytes: 640
# dn 解説の要点は2つ
# 1,各桁のbitは独立に決定できる(一番大事)(解説後半)
# 2,K以下で探すように成約を入れる（解説前半）


N, K = list(map(int, input().split()))
A = list(map(int, input().split()))


ans = 0

for i in range(40, -1, -1):
    # print(ans)
    # 桁の大きい方から探索していく.
    power = 1 << i  # i個桁をシフトさせることでi桁目について考えることができる。
    # まずは1の処理からしていこう
    # i番目のビットに1はいくつあるか
    bit_count_of_1 = sum(1 for a in A if a & power != 0)  # この書き方は頭いい

    # 寄与の分岐
    # 注意すべきはpower>Kのときで、ビットは必ず0なので寄与はその時点で決まる。
    if power > K:
        # print(i)
        ans += power * bit_count_of_1
        # print(ans)
    elif bit_count_of_1 > N - bit_count_of_1:
        # その桁で1のほうが多い場合は最適なXは0を与えたほうがいい。0を与えるのはつまり その桁の大きさ×1の個数
        ans += power * bit_count_of_1
    else:
        ans += power * (N - bit_count_of_1)
        K -= power  # なにげに一番むずかしいポイントはここだった
        #→power==Kかつ ans X_kが1を与えるほうが良いとき、一つ下の桁も問題の条件を満たしているかはわからない。そこでこの演算が必要
        # イメージとしては最上位のビットを削除している。
        # その結果次のiterで一つ下の桁が問題条件（K以下）かを判断することができる。


print(ans)


Measured memory_bytes: 71020