akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <cstring>

#include <algorithm>

using namespace std;

#define NMAX 300000
#define INF 1000000000

struct Node {
    Node(int _l, int _r)
        : l(_l), r(_r), maxv(0), minv(INF),
          lch(NULL), rch(NULL) {}

    int l, r, maxv, minv;
    Node *lch, *rch;

    void update() {
        maxv = max(lch->maxv, rch->maxv);
        minv = min(lch->minv, rch->minv);
    }
};

Node *build(int l, int r) {
    Node *x = new Node(l, r);
    if (l < r) {
        int m = (l + r) >> 1;
        x->lch = build(l, m);
        x->rch = build(m + 1, r);
    }
    return x;
}

void modify(Node *x, int p, int v) {
    if (x->l == x->r) x->minv = x->maxv = v;
    else {
        int m = (x->l + x->r) >> 1;
        if (p <= m) modify(x->lch, p, v);
        else modify(x->rch, p, v);
        x->update();
    }
}

int query_max(Node *x, int l, int r) {
    if (l <= x->l && x->r <= r) return x->maxv;
    else {
        int ret = 0, m = (x->l + x->r) >> 1;
        if (l <= m) ret = max(query_max(x->lch, l, r), ret);
        if (r > m) ret = max(query_max(x->rch, l, r), ret);
        return ret;
    }
}

int query_min(Node *x, int l, int r) {
    if (l <= x->l && x->r <= r) return x->minv;
    else {
        int ret = INF, m = (x->l + x->r) >> 1;
        if (l <= m) ret = min(query_min(x->lch, l, r), ret);
        if (r > m) ret = min(query_min(x->rch, l, r), ret);
        return ret;
    }
}

static int perm[NMAX + 10], f[NMAX + 10][2];

int main() {
    int n;
    scanf("%d", &n);
    Node *seg = build(1, n), *sl = build(1, n), *sr = build(1, n);
    for (int i = 1; i <= n; i++) {
        scanf("%d", perm + i);
        f[i][0] = perm[i] == i;
        f[i][1] = perm[i] != i;
        if (perm[i] == i) modify(seg, i, i);
        else if (i < perm[i]) modify(sr, i, perm[i]);
        else modify(sl, i, perm[i]);
        if (i > 1) {
            f[i][0] += perm[i - 1] != i - 1 ? f[i - 1][1] : 0;
            f[i][1] += perm[i - 1] == i - 1 ? f[i - 1][0] : 0;
        }
    }
    bool ok = true;
    for (int i = 1; i <= n && ok; i++) {
        ok &= (i & 1) == (perm[i] & 1);
        ok &= perm[i] == i || perm[i] - f[perm[i]][1] < i;
        if (perm[i] > i) {
            ok &= query_max(seg, i, perm[i]) < perm[i];
            ok &= query_min(sr, i, perm[i]) >= perm[i];
        } else if (perm[i] < i) {
            ok &= query_min(seg, perm[i], i) > perm[i];
            ok &= query_max(sl, perm[i], i) <= perm[i];
        }
    }
    puts(ok ? "Yes" : "No");
    return 0;
}


Measured memory_bytes: 88064
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

class Main {
	public static void main(String[] args) {
		InputStreamReader isr = new InputStreamReader(System.in);
		BufferedReader br = new BufferedReader(isr);
		try {
			String[] list = br.readLine().split(" ");
			int count = 0;
			int from = Integer.parseInt(list[0]);
			int to = Integer.parseInt(list[1]);
			int num = Integer.parseInt(list[2]);
			for (; from <= to; from++) {
				if (num % from == 0) {
					count++;
				}
			}
			System.out.println(count);

		} catch (IOException e) {
			e.printStackTrace();
		}
	}
}

Measured memory_bytes: 17048
s = input()
output = []

for n in range(len(s)):
    if s[n] == '1' or s[n] == '0':
        output.append(s[n])
    elif s[n] == 'B' and output != []:
        backspace = len(output)-1
        output = output[:backspace]
print(''.join(output))



Measured memory_bytes: 2940
// 2017-03-13
#include <iostream>
#include <cmath>
using namespace std;

int main() {
	int n, a[1000];
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	bool b[100000] = {};
	for (int i = 0; i < n; i++) {
		if (a[i] == 0) {
			b[0] = true;
			continue;
		}
		int d = 0;
		int m = min(n, i + 5);
		for (int j = i; j < m; j++) {
			d = 10 * d + a[j];
			b[d] = true;
		}
	}
	for (int i = 0; i < 100000; i++) {
		if (!b[i]) {
			cout << i << endl;
			break;
		}
	}
	return 0;
}

Measured memory_bytes: 3196
#include<bits/stdc++.h>
using namespace std;
const int MAXN = 2e5 + 5;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
template <typename T> void chkmax(T &x, T y) {x = max(x, y); }
template <typename T> void chkmin(T &x, T y) {x = min(x, y); } 
template <typename T> void read(T &x) {
	x = 0; int f = 1;
	char c = getchar();
	for (; !isdigit(c); c = getchar()) if (c == '-') f = -f;
	for (; isdigit(c); c = getchar()) x = x * 10 + c - '0';
	x *= f;
}
template <typename T> void write(T x) {
	if (x < 0) x = -x, putchar('-');
	if (x > 9) write(x / 10);
	putchar(x % 10 + '0');
}
template <typename T> void writeln(T x) {
	write(x);
	puts("");
}
int f[MAXN];
int F(int x) {
	if (f[x] == x) return x;
	else return f[x] = F(f[x]);
}
int x[MAXN], y[MAXN], type[MAXN];
int main() {
	int n, q; ll m;
	read(n), read(m), read(q);
	for (int i = 1; i <= n; i++)
		f[i] = i;
	for (int i = 1; i <= q; i++) {
		read(x[i]), read(y[i]), read(type[i]);
		x[i]++, y[i]++;
		if (type[i] == 0) {
			f[F(x[i])] = F(y[i]);
		} else {
			if (m == n - 1) {
				puts("No");
				return 0;
			}
		}
	}
	for (int i = 1; i <= q; i++)
		if (type[i] && F(x[i]) == F(y[i])) {
			puts("No");
			return 0;
		}
	int cnt = 0;
	for (int i = 1; i <= n; i++)
		cnt += F(i) == i;
	if (cnt <= 2) {
		for (int i = 1; i <= q; i++)
			if (type[i]) {
				puts("No");
				return 0;
			}
	}
	ll ans = n - 1 - (cnt - 1);
	ans += 1ll * cnt * (cnt - 1) / 2;
	if (ans >= m) puts("Yes");
	else puts("No");
	return 0;
}

Measured memory_bytes: 1792
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<queue>
#include<map>
#include<stack>
#include<iostream>
#include<algorithm>
#define m(a,b) memset(a,b,sizeof(a));
using namespace std;
const int maxn = 1e5;
const int inf = 1<<30;
typedef long long LL;
int n,m;
int cmp(int x, int y){
	return x > y;
}
int main(){
	scanf("%d %d",&n,&m);
	int num[maxn+5];
	for(int i = 0;i<n;i++)
		scanf("%d",&num[i]);
	LL max = 0;
	int max_i = 0;
	for(int i = 1;i<n;i++){
		if(num[i]+num[i-1]>=max) max = num[i]+num[i-1],max_i = i;
	}
	if(max >= m){
		printf("Possible\n");
		for(int i = 1;i<max_i;i++)
			printf("%d\n",i);
		for(int i = n-1;i>max_i;i--)
			printf("%d\n",i);
		printf("%d\n",max_i);
	}
	else
		printf("Impossible\n");
	return 0;
}

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

int main(){
    int n, k;
    static int p[1000];
    cin >> n >> k;
    for(int i=0;i<n;++i) cin >> p[i];
    sort(p, p+n);

    int ans = 0;
    for(int i=0;i<k;++i) ans += p[i];
    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 3608
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
typedef vector<ll> vl;
typedef vector<int> vi;
typedef vector<char> vec;
typedef vector<bool> veb;
typedef vector<string> ves;
typedef vector<vector<ll>> vvl;
typedef vector<vector<int>> vvi;
typedef vector<vector<char>> vvec;
typedef vector<vector<bool>> vveb;
typedef vector<vector<string>> vves;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<(int)(n);i++)
#define rep2(i,n) for(int i=2;i<(int)(n);i++)
#define repk(i,k,n) for(int i=k;i<(int)(n);i++)
#define rev(v) reverse(v.begin(), v.end())
#define fs first
#define sc second
#define pb push_back
#define pp pop_back
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define maxel(a) *max_element(all(a))
#define minel(a) *min_element(all(a))
#define acc accumulate
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define mod (1000000007)
typedef long long int64;
//const int64 INF = 1LL << 58;
#define dame { puts("-1"); return 0;}
#define YES { cout << "YES" << endl; return 0; }
#define NO { cout << "NO" << endl; return 0; }
#define Yes { cout << "Yes" << endl; return 0; }
#define No { cout << "No" << endl; return 0; }
#define uniq(a) sort(all(a));(a).resize(unique(all(a)) - a.begin());
#define dab(v) for(auto i:v)cout<<i<<' '; cout << endl;
#define vin(v) for (ll i = 0; i < v.size(); ++i) cin >> v[i];
template<class T> bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> bool chmin(T& a, const T& b) { if (a > b) { a = b; return 1; } return 0; }
int dx[] = { 0, 0, -1, 1 };
int dy[] = { 1, -1, 0, 0 };
int gcd(int a, int b) { if (a % b == 0) { return(b); } else { return(gcd(b, a % b)); } }


int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	//cout << fixed << setprecision(15);

	int H1, M1, H2, M2, K;
	cin >> H1 >> M1 >> H2 >> M2 >> K;

	int num = H2 * 60 + M2 - H1 * 60 - M1;
	cout << num - K;


	return 0;
}


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

#define N 1000

int lcs(string x, string y) {
  int i, j, m, n, lcs[N+1][N+1];
  
  m = x.length();
  n = y.length();
  // indexずれを補正
  x = ' ' + x;
  y = ' ' + y;
  
  // 初期値
  for (i = 0; i < m + 1; i++) lcs[i][0] = 0;
  for (j = 0; j < n + 1; j++) lcs[0][j] = 0;
  // 漸化式
  for (i = 1; i <= m; i++) {
    for (j = 1; j <= n; j++) {
      if (x[i] == y[j]) lcs[i][j] = lcs[i-1][j-1] + 1;
      else lcs[i][j] = max(lcs[i-1][j], lcs[i][j-1]);
    }
  }

  return lcs[m][n];
}

int main() {
  int i, q, lcs_arr[N];
  string x, y;

  cin >> q;

  for (i = 0; i < q; i++) {
    cin >> x;
    cin >> y;
    lcs_arr[i] = lcs(x, y);
  }    

  for (i = 0; i < q; i++) cout << lcs_arr[i] << endl;
    
  return 0;
}


Measured memory_bytes: 7080
#include <iostream>
using namespace std;
long long gcd(long long a, long long b){
  if (a%b == 0) return(b);
  else return(gcd(b, a%b));
}

long long lcm(long long a, long long b){
  return a * b / gcd(a, b);
}

int main(){
  long long a,b;
  cin >> a >> b;
  cout << lcm(a,b) << "\n";
  return 0;
}

Measured memory_bytes: 3564
#include<stdio.h>
main(){
  int tmp[31],tmp1;
  int i,w,n,a,b;
  for(i=1;i<=30;i++)tmp[i]=i;
 
  scanf("%d %d",&w,&n);
  for(i=0;i<n;i++){
    scanf("%d,%d",&a,&b);
    tmp1=tmp[a];
    tmp[a]=tmp[b];
    tmp[b]=tmp1;
  }
  for(i=1;i<=w;i++){
  printf("%d\n",tmp[i]);
  }
  return 0;
}


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


using namespace std;

int main()
{
    string s;
    cin>>s;
    char a;
    a=s[0];
    switch(a)
    {
        case 'S' :
        cout<<"Cloudy";
        break;

        case 'C' :
        cout<<"Rainy";
        break;

        case 'R':
        cout<<"Sunny";
        break;
    }
    return 0;
}


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

#define rep(i,n) for(i = 0;i < n;++i)
#define all(v) v.begin(), v.end()
template <typename T> bool chmax(T &a, const T b){if(a < b){a = b;return true;}return false;}
template <typename T> bool chmin(T &a, const T b){if(a > b){a = b;return true;}return false;}
using ll = long long;

int main()
{
    ll i,j;
    ll n,m;
    cin >> n >> m;
    vector<vector<ll>> a(n,vector<ll>(m));
    for(i = 0;i < n;++i){
        rep(j,m){
            cin >> a.at(i).at(j);
            --a.at(i).at(j);
        }
    }
    vector<ll> kazu(m);
    for(i = 0;i < n;++i){
        ++kazu.at(a.at(i).at(0));
    }
    ll ans = 0;
    ll ind;
    for(i = 0;i < m;++i){
        if(chmax(ans, kazu.at(i))) ind = i;
    }

    vector<ll> now(n,0);
    set<ll> mita;
    for(i = 1;i < m;++i){
        mita.insert(ind);
        kazu.at(ind) = 0;

        ll tmp = 0;
        for(j = 0;j < n;++j){
            bool flag = false;
            while(mita.count(a.at(j).at(now.at(j)))){
                flag = true;
                ++now.at(j);
            }
            if(flag) ++kazu.at(a.at(j).at(now.at(j)));
        }
        for(j = 0;j < m;++j){
            if(chmax(tmp, kazu.at(j))) ind = j;
        }
        ans = min(ans, tmp);
    }

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

Measured memory_bytes: 1024
#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);
	rep (i, n) cin >> p[i];
	int res = 0;
	FOR (i, 1, n - 1) {
	  if ((p[i - 1] < p[i] && p[i] < p[i + 1]) || (p[i - 1] > p[i] && p[i] > p[i + 1])) res++;
	}
	cout << res << endl;
    
    return 0;
}



Measured memory_bytes: 3660
#include<stdio.h>
int main()
{
	int a,b;
	scanf("%d %d",&a,&b);
	if(a<=5)
	{
		printf("0\n");
		return 0;
	}
	else if(a<=12)
	{
		printf("%d\n",b/2);
	}
	else
	{
		printf("%d\n",b);
	}
	return 0;
}


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

using namespace std;
using ll = long long;
using pii = pair<int, int>;

struct P {
  int s, w;
  P() {}
  P(int s, int w) : s(s), w(w) {}
  bool operator <= (const P& a) {
    return s <= a.s && w <= a.w;
  }
};

const vector<P> v = {{60, 2}, {80, 5}, {100, 10}, {120, 15}, {140, 20}, {160, 25}};

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  int n;
  while (cin >> n, n) {
    int ans = 0;
    for (int i = 0; i < n; i++) {
      int x, y, h, w;
      cin >> x >> y >> h >> w;
      P p(x + y + h, w);
      for (int j = 0; j < 6; j++) {
        if (p <= v[j]) {
          ans += v[j].s * 10;
          break;
        }
      }
    }
    cout << ans << endl;
  }

  return 0;
}


Measured memory_bytes: 3144
import sys
input = sys.stdin.readline
N=int(input())
L=list(map(int,input().split()))
t=0
ans=0
l=0
r=0
while r<=N-1:
 if t+L[r]==t^L[r]:
  t+=L[r]
  r+=1
 else:
  ans+=(r-l)
  t-=L[l]
  l+=1
ans+=(r-l)*(r-l+1)/2
print(int(ans))

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

#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <unordered_map>
#include <queue>
#include <algorithm>

#include <bits/stdc++.h>
#include <cmath>
#include <limits>

using namespace std;


int getTail(long long v){
	return int (v % 10);
}

int getHead(long long v){
	long long ret = v;
	while(true){
		long long tmp = ret / 10;
		if(tmp == 0){
			return ret;
		}
		ret = tmp;
	}
}

long long lpow(long long base, int e){
	long long ret = 1;
	for(int i=0; i<e; i++){
		ret = ret * base;
	}
	return ret;
}

long long pow10[7] = {1, 10, 100, 1000, 10000, 100000, 1000000};

long long N;

int main(int argc, char* argv[]){
	cin.tie(0);
	ios::sync_with_stdio(false);

	cin >> N;
	long long ans = 0;
	for(int i=1; i<=N; i++){
		if((i % 10) == 0) continue;
		int a = getHead(i);
		int b = getTail(i);
		int next = 1;
		//iのペアが1桁の場合 (i, a) をカウントする
		if(a == b && a <= N){
			ans++;
		}
		//iのペアが2桁以上の場合 2桁から6桁
		for(int j=2; j<=6; j++){
			//long long v = lpow(10, j - 1) * b + a;
			long long v = pow10[j - 1] * b + a;
			if(v > N){
				continue;
			}
			int mid = j - 2;
			for(int k=0; k < pow10[mid] ; k++){
				long long w = v + 10 * k;
				if(w <= N){
					ans++;
				}
			}
		}
	}
	printf("%lld\n", ans);
	return 0;
}



Measured memory_bytes: 3716
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key

typedef long long ll;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef long double ld; 
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
typedef set<int>::iterator sit;
typedef map<int,int>::iterator mit;
typedef vector<int>::iterator vit;

ll x[111111];
ll dp[111111];
int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	ll lmin=ll(1e18); 
	deque<pair<ll,ll> > rmin;
	int n; cin>>n; ll e,t; cin>>e>>t;
	x[0]=0;
	for(int i=1;i<=n;i++)
	{
		cin>>x[i];
	}
	int ptr=1;
	rmin.pb(mp(dp[0]-x[0]+t,1));
	for(int i=1;i<=n;i++)
	{
		while(ptr<=i&&x[i]>=t/2+x[ptr]+1) //this means that we need to remove ptr from the "T - 2(x_i - x_{j+1})" is large part
		{
			if(!rmin.empty()&&rmin.front().se==ptr) rmin.pop_front();
			lmin = min(lmin, dp[ptr-1]-2*x[ptr]-x[ptr-1]);
			ptr++;
		}
		ll best=lmin;
		if(!rmin.empty()) best=min(best,-2*x[i]+rmin.front().fi);
		dp[i]=best+3LL*x[i];
		ll cost = dp[i]-x[i]+t;
		while(!rmin.empty()&&rmin.back().fi>=cost) rmin.pop_back();
		rmin.pb(mp(cost,i+1));
	}
	cout<<dp[n]+e-x[n];
}


Measured memory_bytes: 2560
fun main(args: Array<String>) {
  val n = readLine()!!.toInt()
  val m = sortedMapOf<String, Int>()
  repeat(n) {
    val s = readLine()!!
    if (s !in m) m[s] = 0
    m[s] = m[s]!!+1
  }
  val max = m.entries.map { it.value }.max()!!
  m.entries.filter { it.value == max }.forEach { println(it.key) }
}

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

int digit_number(int target, int digit) {
  return (int)(target / pow(10, digit - 1)) % 10;
}
 
int main() {
  int A, B, counter = 0;
  cin >> A >> B;
  for (int i = A; i <= B; i++) {
    if (digit_number(i, 1) == digit_number(i, 5)
    && digit_number(i, 2) == digit_number(i, 4)) {
      counter++;
    }
  }
  cout << counter << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <queue>
#include <string>
#include <algorithm>
#include <cmath>
#include <climits>
#define REP(i, n) for(int i=0; i<(n); i++)
#define FOR(i, a, n) for(int i=(a); i<(n); i++)
using namespace std;

int main(){
    int N;
    cin >> N;
    vector<int> W(N);
    REP(i, N){
        cin >> W[i];
    }
    int ans = INT_MAX;
    REP(i, N-1){
        int s1, s2;
        s1 = 0;
        s2 = 0;
        REP(j, N){
            if(j <= i){
                s1 += W[j];
            }else{
                s2 += W[j];
            }
        }
        ans = ans < abs(s1-s2) ? ans : abs(s1-s2);
    }

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define REP(i, n) FOR(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define bit(x) (1L << (x))
using ll = long long;
using namespace std;

template<typename T>
vector<T> make_v(size_t a,T b){return vector<T>(a,b);}
 
template<typename... Ts>
auto make_v(size_t a,Ts... ts){
    return vector<decltype(make_v(ts...))>(a,make_v(ts...));
}

int main() {
    int n; cin >> n;
    set<int> s;

    REP(i, n) {
        int d; cin >> d;
        s.insert(d);
    }

    cout << s.size() << endl;

    return 0;
}


Measured memory_bytes: 256
import itertools
N = int(input())
S = [input() for i in range(N)]
U = []
n = [0,0,0,0,0]
result = 0

for i in range(N):
    if S[i][0] == 'M' or S[i][0] == 'A' or S[i][0] == 'R' or S[i][0] == 'C' or S[i][0] == 'H':
        U.append(S[i][0])
    
    if S[i][0] == 'M':
        n[0] += 1
    if S[i][0] == 'A':
        n[1] += 1
    if S[i][0] == 'R':
        n[2] += 1
    if S[i][0] == 'C':
        n[3] += 1
    if S[i][0] == 'H':
        n[4] += 1
        
c = list(itertools.combinations(n,3))

for i in range(10):
    result = result + c[i][0]*c[i][1]*c[i][2]

print(result)

Measured memory_bytes: 10668
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <algorithm>
#include <cassert>
#include <cfloat>
#include <complex>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define repLRE(i, l, r) for (ll i = (l); i <= (r); ++i)
#define rrepLRE(i, l, r) for (ll i = (l); i >= (r); --i)
#define Sort(v) sort(v.begin(), v.end())
#define rSort(v) sort(v.rbegin(), v.rend())
#define Reverse(v) reverse(v.begin(), v.end())
#define Lower_bound(v, x) \
  distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) \
  distance(v.begin(), upper_bound(v.begin(), v.end(), x))

using ll = long long;
using ull = unsigned long long;
using P = pair<ll, ll>;
using T = tuple<ll, ll, ll>;
using vll = vector<ll>;
using vP = vector<P>;
using vT = vector<T>;
using vvll = vector<vector<ll>>;
using vvP = vector<vector<P>>;
using dqll = deque<ll>;

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

/* Macros reg. ends here */

const ll INF = 1LL << 50;

int main() {
  // ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cout << fixed << setprecision(15);

  ll n;
  cin >> n;
  vector<string> mp(n);
  rep(i, n) {
    string s;
    cin >> s;
    mp[i] = s + s;
  }
  ll ans = 0;
  rep(k, n) {
    bool ok = true;
    rep(i, n) {
      rep(j, n) {
        if (mp[i][j+k] != mp[j][i+k]) {
          ok = false;
          break;
        }
      }
      if (!ok) break;
    }
    if (ok) ans++;
  }

  cout << ans * n << endl;

  return 0;
}


Measured memory_bytes: 3796
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int MOD = 1000000007;


signed main() {
 int n,m;
 cin>>n>>m;
 vector<int> hen1[n];
 double cou[n]={};
 int s[m],t[m];
 for(int i=0;i<m;i++){
   cin>>s[i]>>t[i];
   s[i]--;t[i]--;
   hen1[t[i]].push_back(s[i]);
   cou[s[i]]++;
 }
double k[n][n],k2[n][n];
 for(int i=0;i<n;i++){
   fill(k[i],k[i]+n,0);
   fill(k2[i],k2[i]+n,0);
   k[i][i]=0;
   k2[i][i]=1;
   for(int j=i+1;j<n;j++){
     for(int p=0;p<hen1[j].size();p++){
       k[i][j]+=(k[i][hen1[j][p]]+k2[i][hen1[j][p]])/cou[hen1[j][p]];
       k2[i][j]+=k2[i][hen1[j][p]]/cou[hen1[j][p]];
     }
   }
 }
 //cerr<<k[0][n-1];
 double ans=k[0][n-1];
 int u=n+1;
 for(int i=0;i<m;i++){
   if(cou[s[i]]>1){
    
        ans=min(ans,(k[0][n-1]-k[s[i]][n-1]*k2[0][s[i]]+k2[0][s[i]]*(k[s[i]][n-1]*cou[s[i]]-(1.0+k[t[i]][n-1]))/(cou[s[i]]-1)));
   
   }
   
 }
//for(int i=0;i<n;i++){for(int j=i;j<n;j++){
 // cerr<<k[i][j]<<' ';
//}
//cerr<<endl;
//}

cout << std::setprecision(20)<<ans;
}


Measured memory_bytes: 11008
import queue

INF = 10 ** 9

H, W, K = map(int, input().split())
sx, sy, gx, gy = map(int, input().split())

sentinels = [-1] * (W+2)
MAP = [sentinels]
for _ in range(H):
    MAP.append( [-1] + list(map(lambda c: INF if c == '.' else -1, input())) + [-1] )
MAP.append(sentinels)

q = queue.Queue()
q.put((sx, sy))
MAP[sx][sy] = 0
while not q.empty():
    x, y = q.get()
    for d in range(1, K+1):
        if MAP[x+d][y] > MAP[x][y] + 1:
            MAP[x+d][y] = MAP[x][y] + 1
            q.put((x+d, y))
        elif MAP[x+d][y] < MAP[x][y] + 1:
            break
    for d in range(1, K+1):
        if MAP[x-d][y] > MAP[x][y] + 1:
            MAP[x-d][y] = MAP[x][y] + 1
            q.put((x-d, y))
        elif MAP[x-d][y] < MAP[x][y] + 1:
            break
    for d in range(1, K+1):
        if MAP[x][y+d] > MAP[x][y] + 1:
            MAP[x][y+d] = MAP[x][y] + 1
            q.put((x, y+d))
        elif MAP[x][y+d] < MAP[x][y] + 1:
            break
    for d in range(1, K+1):
        if MAP[x][y-d] > MAP[x][y] + 1:
            MAP[x][y-d] = MAP[x][y] + 1
            q.put((x, y-d))
        elif MAP[x][y-d] < MAP[x][y] + 1:
            break

if MAP[gx][gy] == INF:
    print(-1)
else:
    print(MAP[gx][gy])

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

int main() {
    
    // ここから入力
    int n;
    cin >> n;
    
    int c = 1;
    ll ans = 0;
    while(c < n){
        int d = n-c;
        double sqrtNum = sqrt(d);
        sqrtNum += 0.5;
        for (int i = 1; i <= sqrtNum; i++)
        {
            if (d % i == 0)
            {
                if(d/i == i){
                    ans++;
                }
                else{
                    ans += 2;
                }
                
            }
            
        }
        
        c++;
    }
    
    cout << ans << endl;

}


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

set<int> num;

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	int s;
	cin >> s;

	int ans = 1;
	while(num.find(s) == num.end()) {
		num.insert(s);
		if (s&1) s = (3 * s) + 1;
		else s = s/2;
		ans++;
	}

	cout << ans << endl;
}


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

int main() {
  double w, h;
  double pX, pY;
  double tmp1, tmp2;
  double kekka = 0.0000;
  double cnt = 0;
  cin >> w >> h >> pX >> pY;

  kekka = (w * h) / 2.0;
  if ((double)pX == (double)(w / 2) && (double)pY == (double)(h / 2)) cnt++;

  cout << setprecision(18) << kekka;
  cout << " ";
  if (cnt > 0) cout << 1;
  else cout << 0;

}


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

int main()
{
    long long h;
    cin >> h;

    long long minAttack = 0;

    int frag = 1;
    int n = floor(log2(h));
    long long ans = pow(2, n + 1) - 1;
    cout << ans << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    //http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=DSL_3_A
    //http://judge.u-aizu.ac.jp/onlinejudge/review.jsp?rid=2692179#1 -- reference
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int K = in.nextInt();//target
        int a[] = new int[n+1];
        for(int i = 1; i<=n ;i++){
            a[i] = in.nextInt();
        }
        int tag[] = new int[K+1];
        //use two pointer
        int p1 = 0, p2 = 0;
        int min = n+1;//smallest size
        int sum = 0;
        //moving the pointer and check the sum < k
        while(p1<=n){
            //p2 = p1;
            if(sum==K) {
                min = Math.min(min, p2-p1);
                //System.out.println(min);
            }
            //main body
            //move right pointer
            if(sum<K){
                p2++;
                if(p2>n) break;
                if(a[p2] <= K){
                    if(tag[a[p2]]==0) sum++;
                    tag[a[p2]]++;
                }
            }else {
                p1++;
                if(p1>n) break;
                if(a[p1]<=K){
                    tag[a[p1]]--;
                    if(tag[a[p1]]==0) sum--;
                }
            }

        }
        if(min == n+1) System.out.println(0);
        else System.out.println(min);

    }

}



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

int main() {
  int n, a;
  cin >> n >> a;
  
  if (n < 500) {
    
    if (n > a) {
      
      cout << "No" << endl;
      return 0;
      
    }
    
    cout << "Yes" << endl;
    return 0;
  }
  
  if( (n % 500) > a) {
    cout << "No" << endl;
  } else {
    cout << "Yes" << endl;
  }
}


Measured memory_bytes: 3588
#include <iostream>
#include <vector>
using namespace std;
 
const long long INF = 1LL << 60;

template<class T> bool chmin(T& a, T b){
    if(a > b){
        a = b;
        return true;
    }
    return false;
}
 
int main(void){
    int N;
    cin >> N;
 
    vector<long long> h(N+2);
    vector<long long> dp(N+2, INF);
 
    for(int i=0;i<N;i++){
        cin >> h[i];
    }
 
    dp[0] = 0;
 
    for(int i=0;i<N;i++){
        chmin(dp[i+1], dp[i]+abs(h[i]-h[i+1]));
        chmin(dp[i+2], dp[i]+abs(h[i]-h[i+2]));
    }
 
    cout << dp[N-1] << endl;
 
    return 0;
}


Measured memory_bytes: 1792
#include<iostream>
#include<algorithm>
#define REP(i,n) for(int i=0;i<n;i++)
using namespace std;

int main() {
    int S, h, m, s;
    cin >> S;
    h = S/3600;
    m = (S - 3600*h)/60;
    s = S - 3600*h - 60*m;
    
    cout <<  h << ':' << m << ':' << s << endl;
    return 0;
}


Measured memory_bytes: 3096
#include<iostream>
using namespace std;
int main()
{
    int n;
    cin >> n;
    int sum = 0;
    int ntmp = n;
    while(ntmp > 0)
    {
        sum += ntmp%10;
        ntmp /= 10;
    }
    if(n % sum == 0)
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
    return 0;
}

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

check = [0] * (n+10)
flag = 0
cnt = 0
for i in range(n):
    if flag == 0:
        if i+1 == p[i]:
            flag = 1
            cnt += 1
    else:
        if i+1 == p[i]:
            cnt += 1
        else:
            flag = 0
            check[cnt] += 1
            cnt = 0
else:
    check[cnt] += 1

ans = 0
for i in range(len(check)):
    s = i//2 + i%2
    ans += s*check[i]

print(ans)

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

typedef long long ll;
const ll INF = 1e18;
const int BIG = 1e9 + 555;
const int maxN = 1e5 + 9;

int n;
ll pos[maxN];

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

	for(int i = 1; i <= n; i++){
		int x;	cin >> x;
		pos[x] = i;
	}

	multiset<ll> se;
	se.insert(0);
	se.insert(0);
	se.insert(n + 1);
	se.insert(n + 1);
	
	ll ans = 0;

	for(int i = n; i > 0; i--){
		se.insert(pos[i]);
		multiset<ll>::iterator it = se.find(pos[i]);	
		
		it--;
		ll lf0 = *it;
		it--;
		ll lf1 = *it;

		it++;	it++;	it++;
		ll rt0 = *it;
		it++;
		ll rt1 = *it;
		
		//cerr << i << ' ' << pos[i] << ' ' << lf1 << ' ' << lf0 << ' ' << rt0 << ' ' << rt1 << '\n';

		ans += (ll)i * (lf0 - lf1) * (rt0 - pos[i]);
		ans += (ll)i * (pos[i] - lf0) * (rt1 - rt0);
	}
	
	cout << ans << '\n';

	return 0;
}

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

using namespace std;

int main(int argc, char const *argv[]) {
	string str;
	int ret = 700;

	cin >> str;

	for (char s : str){
		if (s == 'o')
			ret += 100;
	}

	cout << ret;

	return 0;
}

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

int main() {
  long long D, G;
  cin >> D >> G;

  vector<int> P(D), C(D);

  for (int i = 0; i < D; i++) {
    cin >> P[i] >> C[i];
  }

  long long ans = 10000;
  for (int tmp = 0; tmp < (1 << D); tmp++) {
    bitset<10> s(tmp);
    long long sum = 0;
    long long count = 0;
    for (int i = 0; i < D; i++) {
      if (s.test(i)) {
        sum += P[i] * 100 * (i + 1) + C[i];
        count += P[i];
      }
    }
    if (sum >= G) {
      ans = min(ans, count);
    } else {
      for (int j = D - 1; j >= 0; j--) {
        if (s.test(j) == false) {
          for (int k = 0; k < P[j]; k++) {
            sum += (j + 1) * 100;
            count++;
            if (sum >= G) {
              ans = min(ans, count);
              break;
            }
          }
        }
      }
    }
  }
  cout << ans << endl;
}

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

int main(void) {
	int n, k, ans = 0;			cin >> n >> k;
	vector<int> x(n);	for (int i = 0; i < n; i++) cin >> x[i];
	for (int i = 0; i < n; i++) {
		ans += 2 * min(x[i], k - x[i]);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <algorithm>
using namespace std;
typedef pair<int,int> pii;
typedef pair<pii,int> piii;
typedef vector<int> vi;
typedef vector<pii> vii;
typedef long long ll;
#define loop(n)      for(int i=0;i<(n);i++)
#define lp(x,s,e)    for(int x=(s);x<(e);x++)
#define lpe(x,s,e)    for(int x=(s);x<=(e);x++)
#define MP make_pair
#define PB push_back
#define all(a)  a.begin(),a.end()
#define clr(x,val) memset((x),(val),sizeof(x))
#define endl '\n'

using namespace std;

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    long long n;
    cin>>n;
    cout<<n*(n+1)/2;
}

Measured memory_bytes: 256
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
using static System.Math;

namespace AtCoder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            new Program().Solve(new ConsoleInput(Console.In, ' '));
        }

        public void Solve(ConsoleInput cin)
        {
            var N = cin.ReadInt;
            var S = cin.Read;
            var chars = S.ToCharArray();
            var ans = true;
            if (N % 2 != 0)
            {
                ans = false;
            }
            else
            {
                for (int i = 0; i < N / 2; i++)
                {
                    if (chars[i] != chars[i + N / 2])
                    {
                        ans = false;
                        break;
                    }
                }
            }
            if (ans)
            {
                Console.WriteLine("Yes");
            }
            else
            {
                Console.WriteLine("No");
            }
        }
    }

    public class ConsoleInput
    {
        private readonly System.IO.TextReader _stream;
        private char _separator = ' ';
        private Queue<string> inputStream;
        public ConsoleInput(System.IO.TextReader stream, char separator = ' ')
        {
            this._separator = separator;
            this._stream = stream;
            inputStream = new Queue<string>();
        }
        public string Read
        {
            get
            {
                if (inputStream.Count != 0) return inputStream.Dequeue();
                string[] tmp = _stream.ReadLine().Split(_separator);
                for (int i = 0; i < tmp.Length; ++i)
                    inputStream.Enqueue(tmp[i]);
                return inputStream.Dequeue();
            }
        }
        public string ReadLine { get { return _stream.ReadLine(); }}
        public int ReadInt { get { return int.Parse(Read); }}
        public long ReadLong { get { return long.Parse(Read); }}
        public double ReadDouble { get { return double.Parse(Read); }}
        public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret;}
        public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret;}
        public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret;}
    }
}


Measured memory_bytes: 11220
require 'prime'

def gcd(a, b)
  x = a % b
  if x == 0
    b
  else
    gcd(b, x)
  end
end

n, m, k = gets.split(' ').map(&:to_i)

a = gcd(n, m)

if k == 1
  puts a
else
  divs = Prime.prime_division(a).map{|n, e|
	  (0..e).map{|i| n ** i }
    }.inject([1]){ |a, b|
      a.product(b).map{|ai, bj| ai * bj }
    }.sort
  puts divs[-k]
end

Measured memory_bytes: 2044
N = int(input())
S = list(input())

# 左端からリーダーにしていく
# リーダーを1つ右隣に移すとき、振り向く合計人数は、リーダーと右隣の人の向きが(W,W)なら+1、(E,E)なら-1、(E,W)or(W,E)なら変化なし
n_turn_list = [S[1:].count("E")] # 左端リーダーのときに振り向く人数

for leader_position in range(N-1): # 右端の1つ左まで
    if S[leader_position+1] == "W" and S[leader_position] == "W":
        n_turn_list.append(n_turn_list[leader_position]+1)
    elif S[leader_position+1] == "E" and S[leader_position] == "E":
        n_turn_list.append(n_turn_list[leader_position]-1)
    else:
        n_turn_list.append(n_turn_list[leader_position])

print(min(n_turn_list))

Measured memory_bytes: 21200
#include <cstdio>
#include <algorithm>
#include <functional>

using namespace std;

int main(void) {
	int array[10];
	for(int i = 0; i < 10; i++)
		scanf("%d", &array[i]);
	sort(array, array + 10, greater<int>());
	for(int i = 0; i < 3; i++)
		printf("%d\n", array[i]);
	return 0;
}

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

using namespace std;

#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,m,n) for(int i=(m);i<(n);i++)
#define int long long

const int MAX=7368791;
bool used[MAX+1];
signed main(){
    while(true){
        int M,N;cin>>M>>N;
        if(M==0&&N==0)return 0;
        fill(used,used+MAX+1,0);
        int cnt=0;
        FOR(i,M,MAX+1){
            if(cnt==N)break;
            if(!used[i]){
                used[i]=true;
                for(int j=2*i;j<=MAX;j+=i){
                    used[j]=true;
                }
                cnt++;
            }
        }
        FOR(i,M,MAX+1){
            if(!used[i]){
                cout<<i<<endl;
                break;
            }
        }
    }
}


Measured memory_bytes: 10316
#include <cstdio>
using namespace std;
#define MAX 100000

void exchange(int *m,int *n){
    int k = *m;
    *m  = *n;
    *n = k;
}


int partition(int A[],int p,int r){
    int x = A[r]; //r为数组A末尾元素的下标，分割时以末尾元素A[r]为基准.
    int i = p-1;
    for (int j=p; j<=r-1; j++) {//<=x的会和前面大于x的元素交换位置
        if (A[j] <= x) {
            ++i;
            exchange(&A[i],&A[j]);
        }
    }
    exchange(&A[i+1],&A[r]);
    for(int k=0; k<r+1; k++) {
        if (k == i + 1) printf("[%d]", A[k]);
        else printf("%d", A[k]);
        if( k!=r) printf(" ");
    }
    printf("\n");
    return 0;

}


int main(){
    int A[MAX],n;
    scanf("%d\n",&n);

    for (int i=0; i<n; i++) scanf("%d",&A[i]);
    partition(A,0,n-1);
    return 0;
}





Measured memory_bytes: 3068
#include<bits/stdc++.h>
#define dd(x) cout<<#x<<" = "<<x<<" "
#define de(x) cout<<#x<<" = "<<x<<"\n"
#define sz(x) int(x.size())
#define All(x) x.begin(),x.end()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef priority_queue<int> BQ;
typedef priority_queue<int,vector<int>,greater<int> > SQ;
const int maxn=3e5+10,mod=1e9+7,INF=0x3f3f3f3f;
vector<int> e[maxn];
int ans[maxn],d[maxn];
int main()
{
	int n,m;
	cin>>n>>m;
	for (int i=1;i<=m;++i){
		int u,v;
		scanf("%d%d",&u,&v);
		e[u].pb(v);
		e[v].pb(u);
	}
	memset(d,INF,sizeof(d));
	queue<int> q;
	q.push(1);
	d[1]=0;
	while (sz(q)){
		int u=q.front();
		q.pop();
		for (auto v:e[u])
			if (d[u]+1<d[v])
				d[v]=d[u]+1,ans[v]=u,q.push(v);
	}
	int ok=1;
	for (int i=2;i<=n;++i)
		if (!ans[i])
			ok=0;
	if (!ok)
		cout<<"No";
	else{
		cout<<"Yes\n";
		for (int i=2;i<=n;++i)
			printf("%d\n",ans[i]);
	}
	return 0;
}


Measured memory_bytes: 16516
#include<iostream>
#include<iomanip>
#include<cstring>
#include<cmath>
#include<cstdio>
#include<queue>
#include<algorithm>
using namespace std;
int read()
{
	char c=getchar();
	int res=0;
	while(c<'0'||c>'9') c=getchar();
	while(c>='0'&&c<='9') res=(res<<1)+(res<<3)+(c^48),c=getchar();
	return res;
}
int n,a[105];
long long dp(int l,int r,int cl,int cr)
{
	if(r-l<=1) return 0;
	long long ans=1e18;
	for(int i=l+1;i<=r-1;i++) ans=min(ans,dp(l,i,cl+cr,cr)+dp(i,r,cl,cr+cl)+1ll*(cl+cr)*a[i]);
	return ans;
}
int main()
{
	n=read();
	for(int i=1;i<=n;i++) a[i]=read();
	printf("%lld\n",dp(1,n,1,1)+a[1]+a[n]);
}

Measured memory_bytes: 3728
#include <iostream>
#include <string>
using namespace std;
int main(void){
  int l;
  cin >> l;
  string s,t;
  cin >> s >> t;
  
  for(int i=0;i<l;i++){
    cout << s[i] << t[i];
  }
  
  cout << endl;
  
  return 0;
}

  
  

Measured memory_bytes: 256
using System;
class p
{
  static void Main()
  {
    string[] input = Console.ReadLine().Split(' ');
    int A = int.Parse(input[0]);
    int B = int.Parse(input[1]);
    int count = 0;
    for (int i = A; i <= B; i++) {
      bool result = true;
      string s = i.ToString();
      int n = s.Length / 2;
      for (int j = 0; j <= n; j++) {
        if (s[j] != s[s.Length - (j + 1)]) {
          result = false;
          break;
        }
      }
      if (result) { count++; }
    }
    Console.WriteLine(count);
  }
}

Measured memory_bytes: 13140
//Himanshu Shukla
#pragma GCC optimize("O2")
#include <bits/stdc++.h>
using namespace std;
#define FASTIO ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0)
//#define file_input
//#define multitest
//#define measure_time
#define ll long long
#define v32 vector<int>
#define v64 vector<ll>
#define s32 set<int>
#define s64 set<ll>
#define graph vector<v32>
#define p32 pair<int, int>
#define p64 pair<ll, ll>
#define sz(v) (ll)(v).size()
#define fi first
#define se second
#define ln '\n'
#define debug(x) cerr << (#x) << ": " << (x) << ln
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
inline ll add(ll a, ll b, ll m) { return (((a % m + b % m) % m + m) % m); }
inline ll mul(ll a, ll b, ll m) { return (((a % m * b % m) % m + m) % m); }
const double EPS = 1e-6;
const ll MOD = 1e9 + 7;
template <typename T, typename U>
ostream &operator<<(ostream &out, const pair<T, U> &p)
{
	out << '[' << p.fi << ", " << p.se << ']';
	return out;
}
template <template <typename, typename...> class ContainerType, typename ValueType, typename... Args>
void print_container(const ContainerType<ValueType, Args...> &c)
{
	cout << "{ ";
	for (const auto &v : c)
		cout << v << ' ';
	cout << '}' << ln;
}

void solve()
{
	int n;
	cin >> n;
	ll sum = 0;
	for (int i = 1; i < n + 1; i++)
	{
		if (i % 3 == 0 || i % 5 == 0)
			continue;
		sum += i;
	}
	cout << sum << ln;
	return;
}

int main()
{
	FASTIO;
#ifdef file_input
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	clock_t start, stop;
	int t = 1;
#ifdef multitest
	cin >> t;
#endif
#ifdef measure_time
	start = clock();
#endif
	for (int tc = 1; tc < t + 1; tc++)
		solve();
#ifdef measure_time
	stop = clock();
	cerr << "Time :" << fixed << setprecision(5) << double(stop - start) / double(CLOCKS_PER_SEC) << "s" << ln;
#endif
	return 0;
}


Measured memory_bytes: 3656
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
using pint = pair<int, int>;
using plint = pair<lint, lint>;
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
template<typename T> istream &operator>>(istream &is, vector<T> &vec){ for (auto &v : vec) is >> v; return is; }
template<typename T> ostream &operator<<(ostream &os, const vector<T> &vec){ os << "["; for (auto v : vec) os << v << ","; os << "]"; return os; }
template<typename T> ostream &operator<<(ostream &os, const deque<T> &vec){ os << "deq["; for (auto v : vec) os << v << ","; os << "]"; return os; }
template<typename T> ostream &operator<<(ostream &os, const set<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const unordered_set<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const multiset<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const unordered_multiset<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &pa){ os << "(" << pa.first << "," << pa.second << ")"; return os; }
template<typename TK, typename TV> ostream &operator<<(ostream &os, const map<TK, TV> &mp){ os << "{"; for (auto v : mp) os << v.first << "=>" << v.second << ","; os << "}"; return os; }
template<typename TK, typename TV> ostream &operator<<(ostream &os, const unordered_map<TK, TV> &mp){ os << "{"; for (auto v : mp) os << v.first << "=>" << v.second << ","; os << "}"; return os; }
template<typename T> void ndarray(vector<T> &vec, int len) { vec.resize(len); }
template<typename T, typename... Args> void ndarray(vector<T> &vec, int len, Args... args) { vec.resize(len); for (auto &v : vec) ndarray(v, args...); }
template<typename T> bool mmax(T &m, const T q) { if (m < q) {m = q; return true;} else return false; }
template<typename T> bool mmin(T &m, const T q) { if (m > q) {m = q; return true;} else return false; }
template<typename T1, typename T2> pair<T1, T2> operator+(const pair<T1, T2> &l, const pair<T1, T2> &r) { return make_pair(l.first + r.first, l.second + r.second); }
template<typename T1, typename T2> pair<T1, T2> operator-(const pair<T1, T2> &l, const pair<T1, T2> &r) { return make_pair(l.first - r.first, l.second - r.second); }
#define dbg(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ") " << __FILE__ << endl;


int main()
{
    lint A;
    cin >> A;
    lint B;
    cin >> B;
    if (B / A * A == B) cout << A + B << endl;
    else cout << B - A << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, begin, end) for(ll i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(ll i=(begin)-1;i>=(end);i--)
#define IREP(i, n) IFOR(i,n,0)
#define SORT(a) sort(a.begin(), a.end())
#define ISORT(a) sort(a.begin(), a.end(),greater<ll>())
#define REVERSE(a) reverse(a.begin(), a.end())
#define debug(x) cout << #x << "=" << x << endl;
#define vdebug(v) cout << #v << "=(" <<; REP(i_debug, v.size()){ cout << v[i_debug] << ","; } cout << ")" << endl;
#define mdebug(m) cout << #m << "=" << endl; REP(i_debug, m.size()){ REP(j_debug, m[i_debug].size()){ cout << m[i_debug][j_debug] << ","; } cout << endl;}
#define Max(a, b) a = max(a, b)
#define Min(a, b) a = min(a, b)

#define ll long long
#define f first
#define s second
#define mp make_pair
#define pb push_back
#define INF 1000000000000000000

using vec = vector<ll>;
using mat = vector<vec>;
using Pii = pair<ll, ll>;
using PiP = pair<ll, Pii>;
using PPi = pair<Pii, ll>;
using bvec = vector<bool>;
using Pvec = vector<Pii>;

ll mod = 1000000007;

int main()
{
	ll N, A, B, C;
	cin >> N >> A >> B >> C;

	vec l(N);
	REP(i, N) {
		cin >> l[i];
	}

	ll ans = INF;

	REP(i, pow(4, N)) {
		ll a = 0, b = 0, c = 0;
		ll tempans = 0;
		REP(j, N) {
			if ((i / (ll)pow(4, j)) % 4 == 1) {
				if (a > 0) tempans += 10;
				a += l[j];
			}
			else if ((i / (ll)pow(4, j)) % 4 == 2) {
				if (b > 0) tempans += 10;
				b += l[j];
			}
			else if ((i / (ll)pow(4, j)) % 4 == 3) {
				if (c > 0) tempans += 10;
				c += l[j];
			}
		}
		if (a == 0 || b == 0 || c == 0) continue;
		tempans += abs(A - a) + abs(B - b) + abs(C - c);

		ans = min(ans, tempans);
	}

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

Measured memory_bytes: 256