akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;

const int mod = 998244353;
const int Maxn = 2005;

int C[Maxn][Maxn];
int n, k;
int dp0[Maxn], dp1[Maxn];
int dp[Maxn];
int small[Maxn][Maxn];
int big[Maxn][Maxn];

int toPower(int a, int p)
{
    int res = 1;
    while (p) {
        if (p & 1) res = ll(res) * a % mod;
        p >>= 1; a = ll(a) * a % mod;
    }
    return res;
}

int Inv(int a) { return toPower(a, mod - 2); }

int root = 5;
int root_1 = 4404020;
const int root_pw = 1<<12;
int a[root_pw], b[root_pw];

void fft (int a[], bool invert) {
	int n = root_pw;

	for (int i=1, j=0; i<n; ++i) {
		int bit = n >> 1;
		for (; j>=bit; bit>>=1)
			j -= bit;
		j += bit;
		if (i < j)
			swap (a[i], a[j]);
	}

	for (int len=2; len<=n; len<<=1) {
		int wlen = invert ? root_1 : root;
		for (int i=len; i<root_pw; i<<=1)
			wlen = int (wlen * 1ll * wlen % mod);
		for (int i=0; i<n; i+=len) {
			int w = 1;
			for (int j=0; j<len/2; ++j) {
				int u = a[i+j],  v = int (a[i+j+len/2] * 1ll * w % mod);
				a[i+j] = u+v < mod ? u+v : u+v-mod;
				a[i+j+len/2] = u-v >= 0 ? u-v : u-v+mod;
				w = int (w * 1ll * wlen % mod);
			}
		}
	}
	if (invert) {
		int nrev = Inv(n);
		for (int i=0; i<n; ++i)
			a[i] = int (a[i] * 1ll * nrev % mod);
	}
}

void Multiply(int a[], int b[])
{
    fft(a, false); fft(b, false);
    for (int i = 0; i < root_pw; i++)
        a[i] = ll(a[i]) * b[i] % mod;
    fft(a, true);
}

int main()
{
    root = toPower(3, 243712);
    root_1 = Inv(root);
    for (int i = 0; i < Maxn; i++) {
        C[i][0] = C[i][i] = 1;
        for (int j = 1; j < i; j++)
            C[i][j] = (C[i - 1][j - 1] + C[i - 1][j]) % mod;
    }
    scanf("%d %d", &k, &n);
    for (int i = 1; i <= k; i++) {
        dp0[i] = i <= n? C[n - 1][i - 1]: 0;
        dp1[i] = i <= n - 1? C[n - 2][i - 1]: 0;
    }
    small[0][0] = 1; big[0][0] = 1;
    for (int i = 0; i <= k; i++)
        for (int j = 0; j <= k; j++) {
            small[i + 1][j] = (small[i + 1][j] + small[i][j]) % mod;
            small[i + 1][j + 1] = (small[i + 1][j + 1] + small[i][j]) % mod;
            big[i + 1][j] = (big[i + 1][j] + big[i][j]) % mod;
            big[i + 1][j + 1]  = (big[i + 1][j + 1] + 2ll * ll(big[i][j])) % mod;
        }
    for (int i = 2; i <= 2 * k; i++) {
        int simp = 0, pr = 0, spec = 0;
        for (int j = 1; j <= k; j++)
            if (i - j < 1 || i - j > k) simp++;
            else if (j + j == i) spec++;
            else pr++;
        pr /= 2;
        fill(a, a + root_pw, 0);
        fill(b, b + root_pw, 0);
        for (int j = 0; j <= k; j++) {
            a[j] = small[simp][j];
            b[j] = big[pr][j];
        }
        Multiply(a, b);
        int res = 0;
        for (int j = 1; j <= k; j++) {
            res = (res + ll(a[j]) * dp0[j]) % mod;
            if (spec)
                res = (res + ll(a[j - 1]) * dp1[j - 1]) % mod;
        }
        printf("%d\n", res);
    }
    return 0;
}


Measured memory_bytes: 47488
#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <string>
#include <numeric>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <queue>

#define rep(i,n) for(int i=0;i<n;i++)
#define dup(x,y) (((x)+(y)-1)/(y)) // dup * y >= x なる最小のdup.
using namespace std;
typedef long long ll;

int main() {
	ll N;
	cin >> N;
	vector<ll> A(N), B(N);
	rep(i, N) cin >> A[i];
	rep(i, N) cin >> B[i];

	priority_queue<pair<ll, ll>> task; // <B[i], i>;
	rep(i, N) {
		if(A[i] < B[i]) {
			task.push(make_pair(B[i], i));
		}
	}
	
	ll ans = 0;
	while(task.size()>0) {
		ll id = task.top().second;
		task.pop();
		ll s = B[(id+N-1)%N] + B[(id+1)%N];
		if(B[id]-A[id]>=s){
			ll op = (B[id]-A[id])/s;
			ans += op;
			B[id] -= op*s;
			if(A[id]<B[id]) {
				task.push(make_pair(B[id], id));
			}
		} else {
			cout << -1 << endl;
			return 0;
		}
	}
	
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 9456
#include <bits/stdc++.h>
using namespace std;
int INF = 100000000;
int main(){
  while (1){
    int n, m, s, g1, g2;
    cin >> n >> m >> s >> g1 >> g2;
    if (n == 0 && m == 0 && s == 0 && g1 == 0 && g2 == 0){
      break;
    }
    s--;
    g1--;
    g2--;
    vector<vector<int>> d(n, vector<int>(n, INF));
    for (int i = 0; i < n; i++){
      d[i][i] = 0;
    }
    for (int i = 0; i < m; i++){
      int b1, b2, c;
      cin >> b1 >> b2 >> c;
      b1--;
      b2--;
      d[b1][b2] = c;
    }
    for (int i = 0; i < n; i++){
      for (int j = 0; j < n; j++){
        for (int k = 0; k < n; k++){
          d[j][k] = min(d[j][k], d[j][i] + d[i][k]);
        }
      }
    }
    int ans = INF;
    for (int i = 0; i < n; i++){
      ans = min(ans, d[s][i] + d[i][g1] + d[i][g2]);
    }
    cout << ans << endl;
  }
}


Measured memory_bytes: 3024
#include "bits/stdc++.h"

using namespace std;

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

const double PI = 3.1415926535897932384626433832795;

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

int gcd(int x, int y) { return y ? gcd(y, x % y) : abs(x); }
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : abs(x); }
int lcm(int x, int y) { return x / gcd(x, y) * y; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }

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

	int n;
	cin >> n;
	vector<ll> a(3 * n);
	for (int i = 0; i < 3 * n; i++) {
		cin >> a[i];
	}

	vector<ll> front(3 * n + 1); {
		priority_queue<ll, vector<ll>, greater<ll>> que;
		for (int i = 0; i < 3 * n; i++) {
			que.push(a[i]);
			ll b = 0;
			if (que.size() == n + 1) {
				b = que.top(); que.pop();
			}
			front[i + 1] = front[i] + a[i] - b;
		}
	}
	vector<ll> back(3 * n + 1); {
		priority_queue<ll> que;
		for (int i = 3 * n -1; i >= 0; i--) {
			que.push(a[i]);
			ll b = 0;
			if (que.size() == n + 1) {
				b = que.top(); que.pop();
			}
			back[i] = back[i + 1] + a[i] - b;
		}
	}
	ll result = -INT64_MAX;
	for (int i = n; i <= 2 * n; i++) {
		result = max(result, front[i] - back[i]);
	}
	
	cout << result << endl;
	return 0;
}


Measured memory_bytes: 9068
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstring>
#include <map>
#include <queue>
#include <stack>
#include <set>
#include <functional>
#include <sstream>
#include <complex>
#include <climits>
using namespace std;

#define REP(i,a,n) for(int i=(a);i<(int)(n);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define mp make_pair
#define all(x) x.begin(),x.end()
#define EPS 1e-8

/*
one : 18
two : 21
three : 33
full house : 36
four card : 84

*/
int d[5];
int card[15];

bool isstraight(){
	for(int i=1; i<=10; i++){
		if( card[i]==3 && card[i+1]==3 && card[i+2]==3 &&
				card[i+3]==3 && card[i+4]==3 ) return true;
	}
	return false;
}
int main(){
	while(~scanf("%d,%d,%d,%d,%d",d,d+1,d+2,d+3,d+4)){
		rep(i,15)card[i]=1;
		rep(i,5){
			if( d[i]==1 ) card[14]*=3;
			card[d[i]]*=3;
		}
		int sum = 0;
		rep(i,14)if( card[i]>1 )sum+=card[i];
		
		if( isstraight() ){
			puts("straight");
		}else if( sum==18 ){ //one
			puts("one pair");
		}else if( sum==21 ){ //two
			puts("two pair");
		}else if( sum==33 ){ 
			puts("three card");
		}else if( sum==36 ){
			puts("full house");
		}else if( sum==84 ){
			puts("four card");
		}else{
			puts("null");
		}
		
		//rep(i,14)printf("%d ",card[i]); printf("sum:%d\n",sum);
		
	}
	return 0;
}

Measured memory_bytes: 0
#include <iostream>
//#include <iomanip>
//#include <algorithm>
//#include <numeric>
//#include <queue>
//#include <stack>
//#include <math.h>
//#include <vector>
//#include <unordered_map>
#include <string>
//typedef long long LL;
//typedef long double LD;
using namespace std;

//#define MOD 1000000007

int main() {
    int n;
    string s;
    int ans=0;
    cin >> n;
    cin >> s;
    for(int i=0; i<n-2; i++){
        if(s[i]=='A' && s[i+1]=='B' && s[i+2]=='C'){
            ans++;
        }
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
#define pb push_back
#define sz(x) ((int)x.size())

int pref[3005] = {0}, dp[3005][3005] = {0};

int32_t main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    for(int i = 1; i <= n; i++) 
        cin >> pref[i], dp[i][i] = pref[i], pref[i] += pref[i-1];
    for(int i = 2; i <= n; i++)
        for(int j = 1; j+i-1 <= n; j++)
            dp[j][j+i-1] = max(dp[j][j] + pref[j+i-1] - pref[j] - dp[j+1][j+i-1], dp[j+i-1][j+i-1] + pref[j+i-2] - pref[j-1] - dp[j][j+i-2]);
    cout << dp[1][n] - (pref[n] - dp[1][n]) << endl;
}

Measured memory_bytes: 49752
#include<bits/stdc++.h>
#include<vector>
#include<list>
#include<stack>
#include<queue>
#include<algorithm>
using namespace std;


int main(){
    int n,q;
    scanf("%d",&n);
    vector<int> a(n);
    for(auto&e:a){
        scanf("%d",&e);
    }
    scanf("%d",&q);
    vector<int> m(q);
    for(auto&e:m){
        scanf("%d",&e);
    }
    set<int> lst;
    for(int all=0;all< (1<<n);all++){
        int chk=0;
        for(int i=0;i<n;i++){
            if(all>>i & 1){
                chk+=a[i];
            }
        }
        lst.insert(chk);
    }
    for(int i=0;i<q;i++){
        if(lst.find(m[i])!=lst.end()){
            printf("yes\n");
        }else{
            printf("no\n");
        }
    }
    return 0;
}

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

int main()
{
	int N;
	cin >> N;
	int pme = 2;
	int ans = 1;
	
	int array[100010];
	for(int i = 0; i < N; i++){
		cin >> array[i];
	}
	for(int i = 0; i < N - 1; i++){
		if(array[i] > array[i + 1]){
			if(pme == 0){
				ans += 1;
				pme = 2;
			}
			else if(pme == 2){
				pme = 1;
			}
		}
		else if(array[i] < array[i + 1]){
			if(pme == 1){
				ans += 1;
				pme = 2;
			}
			else if(pme == 2){
				pme = 0;
			}
		}
	}
	cout << ans << endl;
}


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

using namespace std;

#define ll long long

int a[100000001];
int mini[100000001];

int main()
{
	int n;
	cin>>n;
	mini[0] = 1e9+7;
	for(int i = 1;i<=n;i++)
	{
		cin>>a[i];
	}
	for(int i = 1;i<=n;i++)
	{
		mini[i] = min(mini[i-1],a[i]);
	}
	int cnt = 0;
	for(int i = 1;i<=n;i++)
	{
		if(mini[i] == a[i])
		{
			cnt++;
		}
	}
	cout<<cnt;
}

Measured memory_bytes: 5120
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(int i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(int i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(int i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define uniq(x) (x).erase(unique((x).begin(), (x).end()), (x).end())

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    ll s;
    cin >> s;
    vector<pair<int, int>> xy(3);
    ll mv = 1e9;
    xy[0] = make_pair(0, 0);
    xy[1] = make_pair(mv, 1);
    
    if (s < mv) {
        xy[2] = make_pair(s, 0);
    }
    else {
        ll y = (s + (mv - 1)) / mv;
        xy[2] = make_pair(y * mv - s, y);
    }
    
    rep(i, 3) {
        printf("%d %d%s", xy[i].first, xy[i].second, (i == 2) ? "\n" : " ");
    }
    
    return 0;
}


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

Bo = [0 for _ in range(n)]
Ans = []

for i in range(n-1, -1, -1):
    tot = sum(Bo[i::i+1])

    if (tot % 2 == A[i]):
        pass
    elif (tot % 2 != A[i]):
        Ans.append(str(i+1))
        Bo[i] += 1
    else:
        pass
if len(Ans) ==0:
    print(0)
else:
    print(len(Ans))
    print(' '.join(Ans))


Measured memory_bytes: 17228
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
inline int read()
{
	int x = 0, f = 1; char c = getchar();
	while (!isdigit(c)) {if (c == '-') f = -1; c = getchar();}
	while (isdigit(c)) {x = x * 10 + c - '0', c = getchar();}
	return x * f;
}

const int mod = 998244353;
const int inv2 = (mod + 1) / 2;
inline int inc(int x, int y) {x += y; return x >= mod ? x - mod : x;}
inline int mul(int x, int y) {return (ll)x * y % mod;}
inline int qpow(int x, int y)
{
	int res = 1;
	for (; y; y >>= 1, x = mul(x, x))
		if (y & 1) res = mul(res, x);
	return res;
}

void fwt(int n, int *a)
{
	for (int i = 1; i < n; i <<= 1)
		for (int j = 0; j < n; j += i << 1)
			for (int k = 0; k < i; k ++)
			{
				int x = a[j + k], y = a[i + j + k];
				a[j + k] = inc(x, y);
				a[i + j + k] = inc(x, mod - y);
			}
}

void ifwt(int n, int *a)
{
	for (int i = 1; i < n; i <<= 1)
		for (int j = 0; j < n; j += i << 1)
			for (int k = 0; k < i; k ++)
			{
				int x = a[j + k], y = a[i + j + k];
				a[j + k] = mul(inc(x, y), inv2);
				a[i + j + k] = mul(inc(x, mod - y), inv2);
			}
}

const int maxn = (1 << 18) + 5;
int n, a[maxn], b[maxn], p[maxn];

int main()
{
	n = read(), n = 1 << n;
	for (int i = 0; i < n; i ++) p[i] = read();
	int s = 0;
	for (int i = 0; i < n; i ++) s = inc(s, p[i]);
	s = qpow(s, mod - 2);
	for (int i = 0; i < n; i ++) p[i] = mul(s, p[i]);
	for (int i = 0; i < n; i ++) a[i] = p[i]; a[0] = inc(a[0], mod - 1);
	for (int i = 0; i < n; i ++) b[i] = mod - 1; b[0] = inc(b[0], n);
	fwt(n, a), fwt(n, b);
	for (int i = 0; i < n; i ++) a[i] = mul(b[i], qpow(a[i], mod - 2));
	ifwt(n, a); int delta = mod - a[0];
	for (int i = 0; i < n; i ++) a[i] = inc(a[i], delta);
	for (int i = 0; i < n; i ++)
		printf("%d\n", a[i]);
	return 0;
}

Measured memory_bytes: 5888
#include<stdio.h>

int main(void){
int a,b,c,d;

scanf("%d %d %d %d",&a,&b,&c,&d);
if(a+b>c+d){
printf("Left");
}else if(c+d>a+b){
printf("Right");
}else{
printf("Balanced");
}

return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int i = 0; i < (n); i++)
#define all(v) v.begin(), v.end()
#define MOD 1000000007
const int INF = 1LL<<30;

int H,W;
char maze[30][310];
int d[30][30];
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
int bfs(int sx,int sy){
    queue<pair<int,int>> que;
    rep(i,H){
        rep(j,W){
            d[i][j]=INF;
        }
    }
 
    int res=0;
    que.push(make_pair(sx,sy)); // (0,0)ã‚¹ã‚¿ãƒ¼ãƒˆ
    d[sx][sy]=0;
    while(!que.empty()){
        pair<int,int> p=que.front();
        que.pop();
        for(int i=0;i<4;i++){
            int nx=p.first+dx[i];
            int ny=p.second+dy[i];
            if(0<=nx && nx<H && 0<=ny && ny<W && maze[nx][ny]!='#' && d[nx][ny]==INF){
                que.push(make_pair(nx,ny));
                d[nx][ny]=d[p.first][p.second]+1;
                res=max(res,d[nx][ny]);
            }
        }
    }
 
    return res;
}

int main(){
    cin>>H>>W;
    rep(i,H){
        rep(j,W){
            cin>>maze[i][j];
        }
    }

    int ans=0;
    rep(i,H){
        rep(j,W){
            if(maze[i][j]=='.') ans=max(ans,bfs(i,j));
        }
    }

    cout<<ans<<endl;
}

Measured memory_bytes: 3600
import qualified Data.ByteString.Char8 as B
import           Data.Char
import           Data.List             as L

main :: IO ()
main = do
  [n, m] <- map read.words <$> getLine
  xs <- L.unfoldr (B.readInt.B.dropWhile isSpace) <$> B.getLine
  print $ solve m xs

solve :: Int -> [Int] -> Int
solve m xs = zeros + sum[ l * (l - 1) `quot` 2| ys<-yss,let l = length ys]
  where
    zeros
        | y == 0 = length ys
        | otherwise = 0
    yss@(ys@(y:_):_) = L.group
        .L.sort
        . scanl1 (\x y -> (x + y) `rem` m)
        $ map (`rem` m) xs

Measured memory_bytes: 13564
#include <stdio.h>
int main()
{
  int imu,orshi,i = 0,tahmid[10000],j,k,l,sum = 0,flag = 0;
  scanf("%d %d",&imu, &orshi);
  while(imu--){
     tahmid[i] = orshi + i;
     if(tahmid[i]==0) flag = 1;
     sum = sum + tahmid[i];
     i++;
  }
  //printf("%d\n",sum);
  if(flag==1) printf("%d\n",sum);
  else if(sum>=0) printf("%d\n",sum-tahmid[0]);
  else printf("%d\n",sum-tahmid[i-1]);
  return 0;
}


Measured memory_bytes: 128
#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

#define MOD 1000000007
#define MOD2 998244353
#define int long long
#define double long double
#define EPS 1e-9
//#define PI 3.14159265358979

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

using namespace std;

template < typename T >
ostream &operator<<(ostream &os, const vector< T > &A) {
	for (int i = 0; i < A.size(); i++)
		os << A[i] << " ";
	os << endl;
	return os;
}
template <>
ostream &operator<<(ostream &os, const vector< vector< int > > &A) {
	int N = A.size();
	int M;
	if (N > 0)
		M = A[0].size();
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < M; j++)
			os << A[i][j] << " ";
		os << endl;
	}
	return os;
}

typedef pair< int, int > pii;
typedef long long ll;

struct edge {
	int from, to, d, c;
	edge(int _from = 0, int _to = 0, int _d = 0, int _c = 0) {
		from = _from;
		to = _to;
		d = _d;
		c = _c;
	}
	bool operator<(const edge &rhs) const {
		return (d == rhs.d) ? (c < rhs.c) : (d < rhs.d);
	}
};
struct aabb {
	int x1, y1, x2, y2;
	aabb(int x1, int y1, int x2, int y2) : x1(x1), y1(y1), x2(x2), y2(y2) {}
};

typedef vector< edge > edges;
typedef vector< edges > graph;
struct flow {
	int to, cap, rev, cost;
	flow(int to = 0, int cap = 0, int rev = 0, int cost = 0) : to(to), cap(cap), rev(rev), cost(cost) {}
};
typedef vector< vector< flow > > flows;

const int di[4] = {0, -1, 0, 1};
const int dj[4] = {-1, 0, 1, 0};
const int ci[5] = {0, 0, -1, 0, 1};
const int cj[5] = {0, -1, 0, 1, 0};
const ll LINF = LLONG_MAX / 2;
const int INF = INT_MAX / 2;
const double PI = acos(-1);

int pow2(int n) { return 1LL << n; }
template < typename T, typename U >
bool chmin(T &x, const U &y) {
	if (x > y) {
		x = y;
		return true;
	}
	return false;
}
template < typename T, typename U >
bool chmax(T &x, const U &y) {
	if (x < y) {
		x = y;
		return true;
	}
	return false;
}

struct initializer {
	initializer() {
		cout << fixed << setprecision(20);
	}
};
initializer _____;

int N, M, K, T, Q, H, W;
signed main() {
	cin >> N;
	int ans = 0;
	for (int i = 1; i <= N; i += 2) {
		int t = i;
		vector< int > d;
		for (int j = 1; j * j <= t; j++) {
			if (t % j == 0) {
				d.push_back(j);
				if (j != t / j)
					d.push_back(t / j);
			}
		}
		if (d.size() == 8)
			ans++;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define PI  3.14159265358979323846

ll gcd(ll a,ll b)
{
    if(a==0)
        return b;
    else
        return gcd(b%a,a);
}
ll fast(ll n,ll a,ll m)
{
    if(n==0)
        return 1;
    else if(n==1)
        return a;
    else
    {
        ll res=fast(n/2,a,m)%m;
        if(n%2==0)
            return (((res%m)*(res%m))%m);
        else
            return (((((res%m)*a)%m)*res)%m);
    }
}
int main()
{
  ll n,i;
  cin>>n;
  ll P[n];
  for(i=0;i<n;i++)
  {
      cin>>P[i];
  }
  ll ans=1,M=P[0];
  for(i=1;i<n;i++)
  {
      if(P[i]<=M)
      {
          ans++;
      }
      M=min(M,P[i]);
  }
  cout<<ans;
}


Measured memory_bytes: 1792
import java.util.Arrays;
import java.util.HashMap;
import java.util.Scanner;

public class Main {
	
	private void solve() {
		Scanner in = new Scanner(System.in);
		int N = in.nextInt();
		HashMap<String, Integer> anagCount = new HashMap<>();
		for(int i=0; i<N; i++) {
			String s = in.next();
			char[] chars = s.toCharArray();
			Arrays.sort(chars);
			String sorted = new String(chars);
			if(anagCount.containsKey(sorted)) {
				anagCount.put(sorted, anagCount.get(sorted)+1);
			}else {
				anagCount.put(sorted, 1);
			}
		}
		
		long ans = 0;
		for (int count : anagCount.values()) {
			ans += ((long)count)*(count-1)/2;
		}
		System.out.println(ans);
	}
	
	public static void main(String[] args) {
		new Main().solve();
	}
}


Measured memory_bytes: 53220
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
#include<stdio.h>
#include <cstdint>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define all(a) a.begin(), a.end()
#define fi first
#define se second
#define RNG(x, a, n) &((x)[a]), &((x)[n])
typedef pair<int, int> PII;
typedef long long ll;
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; }
const int inf = 1e9 + 7;
const ll longinf = 1LL << 60;
const ll mod = 1e9 + 7;

int a, b, c;

int main() {

	cin >> a >> b;

	c = a + b;

	if (c == 3)cout << 3 << endl;
	else if (c == 4)cout << 2 << endl;
	else cout << 1 << endl;

	return 0;
}



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

long long gcd(long long a, long long b)
{
	if (b == 0)
		return a;
	return gcd(b, a % b);

}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	long long sum{};
	long long n; cin >> n;
	for (long long i = 1; i <= n; i++)
		for (long long j = 1; j <= n; j++)
			for (long long k = 1; k <= n; k++)
				sum += gcd(gcd(i, j), k);
	cout << sum;
}

Measured memory_bytes: 3648
from itertools import combinations

H, W, K = map(int, input().split())
Map = [[0] * W for _ in range(H)]
ans = 0
for i in range(H):
    s = input()
    for j in range(W):
        if s[j] == '#':
            Map[i][j] = 1

Columns = []
Rows = []
for i in range(H):
    Columns.append(i)
for i in range(W):
    Rows.append(i)

for i in range(H + 1):
    for j in range(W + 1):
        for c in combinations(Columns, i):
            for r in combinations(Rows, j):
                black = 0
                for y in c:
                    for x in r:
                        if Map[y][x]:
                            black += 1
                if black == K:
                    ans += 1

print(ans)


Measured memory_bytes: 68356
#include <bits/stdc++.h>
//#define int long long
#define rep(i,n) for(int i;i<n;i++)
#define fi first
#define se second
#define INF 100000002
#define MAX 1000002
using namespace std;

int main(){
	int t, ans = 0;
	for(int i = 0;i < 4;i++)scanf("%d", &t), ans += t;
	printf("%d\n%d\n", ans/60, ans%60);
	return 0;
} 

Measured memory_bytes: 3204
#include <bits/stdc++.h>
using namespace std;
using large = long long;
int main() {
    large a, b, n;
    cin >> a >> b >> n;

    // (A*x/B) - A * (x/B);
    // q = x/B
    // r = x%B
    // => x = q * B + r
    // A*x/B = A*q + A*r/B
    // A*(x/B) = A*q
    // ()- A() = A*r/B

    large r_max;
    if (n < b) {
        r_max = n;
    } else {
        r_max = b - 1;
    }

    cout << (a * r_max) / b << "\n";
    return 0;
}


Measured memory_bytes: 3636
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;

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

  int ans = 1000000000;
  for(int i=-100;i<=100;i++){
    int sum = 0;
    for(int j=0;j<N;j++){
      sum += (i - a[j]) * (i - a[j]);
    }
    ans = min(ans,sum);
  }

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int a[200005];
bool cmp(int a,int b)
{
	return a>b;
}
int main()
{
	int n,k;
	cin>>n>>k;
	int sum=0;
	for(int i=1;i<=n;i++)
	{
		int x;
		cin>>x;
		if(!a[x])
			sum++;
		a[x]++;
	}
	sort(a,a+200005,cmp);
	int ans=0;
	int i=k;
	while(a[i]!=0)
	{
		ans+=a[i];
		i++;
	}
	cout<<ans;
	return 0;
 } 

Measured memory_bytes: 1024
#include<iostream>
using namespace std;
int main()
{
    int x=0;
    cin>>x;
    if(x>=400&&599>=x)
        cout<<8;
    else if(x>=600&&799>=x)
        cout<<7;
       else if(x>=800&&999>=x)
        cout<<6;
       else if(x>=1000&&1199>=x)
        cout<<5;
       else if(x>=1200&&1399>=x)
        cout<<4;
       else if(x>=1400&&1599>=x)
        cout<<3;
       else if(x>=1600&&1799>=x)
        cout<<2;
       else if(x>=1800&&1999>=x)
        cout<<1;
}



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

int main() {
  int n, score_t = 0, score_h = 0;
  cin >> n;
  for (int i = 0; i < n; i++) {
    string t, h;
    cin >> t >> h;
    int size = max(t.size(), h.size());
    for (int j = 0; j < size; j++) {
      if (t[j] > h[j]) {
        score_t += 3;
        break;
      } else if (t[j] < h[j]) {
        score_h += 3;
        break;
      }else{
          if(j == size-1){
              score_t += 1;
              score_h += 1;
          }
      }
    }
  }
  cout << score_t << " " << score_h << endl;
  return 0;
}


Measured memory_bytes: 3216
#include <iostream>
#include <algorithm>
#include <vector>

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

  std::vector<int> h(n);
  for(int i=0;i<n;i++)
  {
    std::cin>>h[i];
  }
  std:: vector<long long> dp(n);
  dp[0]=0;
  dp[1]=abs(h[1]-h[0]);
  
  for(int i=2;i<n;i++){
    dp[i]=std::min(dp[i-1]+abs(h[i]-h[i-1]),
                   dp[i-2]+abs(h[i]-h[i-2]))
      ;
  }
  std::cout<<dp[n-1]<<std::endl;
  }

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

#define forn(i,n) for(int i=0;i<n;i++)
#define pb push_back
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vii;
const ll INF=1e18L +7;

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);	
        ll n,w;
        cin>>n>>w;
        const int val=1e5;
        vector<ll> dp(val+1,INF);
        dp[0]=0;
        forn(i,n){
            ll weight,value;
            cin>>weight>>value;
            for(int i=val-value;i>=0;i--){
                dp[i+value]=min(dp[i+value],dp[i]+weight);
            }
        }
        int ans=0;
        for(int i=1;i<=val;i++){
            if(dp[i]<=w)
            ans=max(ans,i);
        }
        cout<<ans<<endl;
}


Measured memory_bytes: 1024
#include<string>
#include<iostream>
#include<algorithm>
#include<set>
#include<math.h>
#include<vector>
#include<sstream>
#include<queue>
#include<functional>
#include<bitset>
#include<cstdio>
#include<iomanip>
#include<map>
#include<unordered_map>
#include<unordered_set>
#include <string.h>
using namespace std;
long long f[100][10];
long long p[100][11];
long long d[10];
long long n;

long long calc() {
	bool flg = true;
	long long s[100] = {};
	for (long long i = 0; i < 10; i++) {
		if (d[i] != 0) {
			flg = false;
			break;
		}
	}
	if (flg) {
		return -1000000000;
	}
	for (int i = 0; i < 10; i++) {
		for (int j = 0; j < n; j++) {
			if (d[i] == 1 && f[j][i] == 1)  s[j]++;
		}
	}
	long long res = 0;
	for (int i = 0; i < n; i++) {
		res+= p[i][s[i]];
	}
	return res;
}
long long solve(long long depth) {
	if (depth == 10) {
		return calc();
	}
	long long l, r;
	d[depth] = 0;
	l = solve(depth + 1);
	d[depth] = 1;
	r = solve(depth + 1);
	return max(l, r);
}
int main() {
	cin >> n;
	for (long long i = 0; i < n; i++) {
		for (long long j = 0; j < 10; j++) {
			cin >> f[i][j];
		}
	}
	for (long long i = 0; i < n; i++) {
		for (long long j = 0; j <= 10; j++) {
			cin >> p[i][j];
		}
	}
	cout << solve(0) << endl;

	return 0;
}

Measured memory_bytes: 384
require 'prime'

n = gets.to_i
if n == 1
  puts '1'
  exit
end
M = 10 ** 9 + 7
h = Hash.new(0)
1.upto(n) do |i|
  i.prime_division.each do |k, v|
    h[k] += v
  end
end
puts h.values.map{|i| (i + 1)}.inject{|u, v| u * v % M}

Measured memory_bytes: 2300
#include<bits/stdc++.h>
using namespace std;
const int maxn = 1e5;
int a[maxn + 5];
int b[maxn + 5];
int main() {
	int n, m, x, y;
	cin >> n >> m >> x >> y;
	int Max1 = -1000, Max2 = 1e6;
	for(int i = 1; i <= n; i++) {
		cin >> a[i];
		Max1 = max(Max1, a[i]);
	}
	for(int i = 1; i <= m; i++) {
		cin >> b[i];
		Max2 = min(Max2, b[i]);
	}
	for(int i = x + 1; i <= y; i++) {
		if(i > Max1 && i <= Max2) {
			cout << "No War" << endl;
			return 0;
		}
	}
	cout <<"War" << endl;
	return 0;
}

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

int main(){
    double n, x, y, ans=0;
    cin >> n;
    vector<pair<double, double>> X(n);
    RAP(i, n){
        cin >> x >> y;
        X[i] = make_pair(x, y);
    }
    RAP(i, n){
        FOR(j, i+1, n){
            ans += pow(pow(X[i].first-X[j].first,2)+pow(X[i].second-X[j].second, 2), 0.5);
        }
    }
    ans = ans*2/n;
    cout << fixed << setprecision(10) << ans << endl;
    return 0;
}


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

int main()
{
    vector<int> v1, v2, v3;
    int n;
    cin >> n;
    while (n--)
    {
        int x;
        cin >> x;
        v1.push_back(x);
    }
    int m;
    cin >> m;
    while (m--)
    {
        int x;
        cin >> x;
        v2.push_back(x);
    }
    set_union(v1.begin(), v1.end(), v2.begin(), v2.end(), back_inserter(v3));
    int i;
    for (i = 0; i < v3.size(); i++)
    {
        cout << v3[i] << endl;
    }
    return 0;
}


Measured memory_bytes: 6452
# -*- coding: utf-8 -*-
import sys 
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

#Union Find
#xの根を求める
def find(x):
    if par[x] < 0:
        return x
    else:
        par[x] = find(par[x])
        return par[x]
#xとyの属する集合の併合
def union(x,y):
    x = find(x)
    y = find(y)
    if x != y:
        #sizeの大きいほうがx
        if par[x] > par[y]:
            x,y = y,x
        par[x] += par[y] #xにyの個数くっつける 
        par[y] = x #yをxにくっつける
        return 

#xとyが同じ集合に属するかの判定
def same(x,y):
    return find(x) == find(y)

#xが属する集合の個数
def size(x):
    return -par[find(x)]

N,Q = map(int,readline().split())
#0-index
par = [-1]*(N+1)
for _ in range(Q):
    x,y = map(int,readline().split())
    union(x,y)

print(-min(par))

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

using namespace std;

const int max_n = 200222, inf = 1000111222;

int n;
char s[max_n];

int main() {
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    scanf("%s", s);
    n = strlen(s);
    long long ans = 0, cnt = 0;
    for (int i = 0; i < n; ++i) {
        if (s[i] == 'B') {
            ++cnt;
        } else {
            ans += cnt;
        }
    }
    printf("%lld\n", ans);
    return 0;
}


Measured memory_bytes: 384
var lines = [];
var B_counter, S, H, W
var readline = require('readline');

var rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout,
});

rl.on('line', function (x) {
    lines.push(x);
});

rl.on('close', function () {
    H = Number(lines[0].split(" ")[0])
    W = Number(lines[0].split(" ")[1])
    lines.shift()

    S = lines.map(i => i.split(""))

    //console.log(S)

    B_counter = 0; var q = []
    for (var i = 0; i < H; i++) {
        for (var j = 0; j < W; j++) {
            if (S[i][j] === "#") { q.push([i, j]); B_counter++; }
        }
    }
    console.log(bfs(q));
});

function bfs(q) {

    var black = 0; var ans = "No";

    while (q.length) {

        var t = q.shift();
        var y = t[0], x = t[1];

        if (0 <= x + 1 && x + 1 < W) { if (S[y][x + 1] === "#") { S[y][x + 1] = "."; black++; q.push([y, x + 1]) } }
        if (0 <= x - 1 && x - 1 < W) { if (S[y][x - 1] === "#") { S[y][x - 1] = "."; black++; q.push([y, x - 1]) } }
        if (0 <= y + 1 && y + 1 < H) { if (S[y + 1][x] === "#") { S[y + 1][x] = "."; black++; q.push([y + 1, x]) } }
        if (0 <= y - 1 && y - 1 < H) { if (S[y - 1][x] === "#") { S[y - 1][x] = "."; black++; q.push([y - 1, x]) } }

    }
    
    if (black === B_counter) { ans = "Yes"; }

    return (ans);
}

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

public class Main {

	public static void main(String args[]) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		String str[] = br.readLine().split(" ");
		String str1 = str[0];
		String str2 = str[1];

		str = br.readLine().split(" ");
		int a = Integer.parseInt(str[0]);
		int b = Integer.parseInt(str[1]);

		String s = br.readLine();

		if (s.equals(str1)) {
			a--;
		} else {
			b--;
		}
		System.out.println(a + " " + b);
	}
}


Measured memory_bytes: 22356
sentinel = 1000000001

def merge(A, left, mid, right):
    """Merge the two sorted partial sequences A[left:mid] and A[mid:right].

    To count the number of inversions,
    make a global declaration for the variable cnt.
    """
    L = A[left:mid]
    n1 = len(L)
    L.append(sentinel)
    R = A[mid:right]
    R.append(sentinel)
    i = 0
    j = 0
    cnt = 0
    for k in range(left, right):
        if L[i] <= R[j]:
            A[k] = L[i]
            i += 1
        else:
            A[k] = R[j]
            j += 1
            cnt += n1 - i
    return cnt

def mergeSort(A, left, right):
    if left + 1 < right:
        mid = (left + right) // 2
        cnt1 = mergeSort(A, left, mid)
        cnt2 = mergeSort(A, mid, right)
        cnt3 = merge(A, left, mid, right)
        return cnt1 + cnt2 + cnt3
    else:
        return 0


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

cnt = 0

n_ivs =  mergeSort(S, 0, n)

print(n_ivs)

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

using namespace std;

int n,k;
int a,b,c;

int main(){
	scanf("%d %d\n",&n,&k);
	for(int i=0;i<k;i++){
		scanf("%d %d",&a,&b);
		int m=1000000000;
		m=min(a-1,m);
		m=min(n-a,m);
		m=min(b-1,m);
		m=min(n-b,m);
		if(m%3==0) printf("1\n");
		if(m%3==1) printf("2\n");
		if(m%3==2) printf("3\n");
	}
	return 0;
}

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

#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define ALL(v) (v).begin(), (v).end()
#define p(s) cout<<(s)<<endl
#define p2(s, t) cout << (s) << " " << (t) << endl
#define br() p("")
#define pn(s) cout << (#s) << " " << (s) << endl
#define p_yes() p("Yes")
#define p_no() p("No")

const ll mod = 1e9 + 7;
const ll inf = 1e18;

// 配るDP ver

ll ll_pow(ll a, ll n){
    ll ans = 1;
    FOR(i, 0, n){
        ans *= a;
    }
    return ans;
}

vector<ll> coins;
const int N_MAX = 200010;
ll dp[N_MAX];

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

    // input
    ll N;
    cin >> N;

    FOR(i, 0, N_MAX){
        dp[i] = inf;
    }

    coins.push_back(1);
    FOR(i, 1, 7){
        coins.push_back(ll_pow(6, i));
    }
    FOR(i, 1, 6){
        coins.push_back(ll_pow(9, i));
    }

    dp[0] = 0;
    FOR(i, 0, 100000){
        for(ll c : coins){
            ll num = dp[i] + 1;
            dp[i+c] = min(dp[i+c], num);
        }
    }

    p(dp[N]);
    
    return 0;
}

Measured memory_bytes: 1792
#include <stdio.h>
#include <iostream>
using namespace std;

int shinhou(int x)
{
	if (x < 10)
		return x;
	else
		return x % 10 + shinhou(x / 10);
}

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

	if (N % shinhou(N) == 0)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
}

Measured memory_bytes: 256
main :: IO ()
main = do
    [a, b, c] <- map (read :: String -> Int) . words <$> getLine
    [k] <- map (read :: String -> Int) . words <$> getLine
    let m = maximum [a, b, c]
        s = sum [a, b, c]
    print $ s + m * (2^k - 1)

Measured memory_bytes: 508
import java.util.Scanner;

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

Measured memory_bytes: 17304
// AtCoder Regular Contest 079
// E - Decrease (Judge ver.)

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;


const int MAX_N = 50;
const ll MAX_A = (ll)1e16 + 1000;

int N;
ll a[MAX_N];

ll can(ll k) {
    ll sum = 0;
    for (int i = 0; i < N; i++) {
        sum += (max(a[i] + k - (N - 1), 0LL) + N) / (N + 1);
    }
    return sum <= k;
}

int main() {

    ll sum_a = 0;
    ll ans;

    cin >> N;
    for (int i = 0; i < N; i++) {
        cin >> a[i];
        sum_a += a[i];
    }

    for (ll k = max(sum_a - (N - 1) * N, 0LL); k <= MAX_A * N; k++) {
        if (can(k)) {
            ans = k;
            break;
        }
    }

    cout << ans << endl;

    return 0;

}





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

using namespace std;
typedef long long ll;

int main() {
    string s;
    cin >> s;
    bool yes = false;
    for (auto c : s) {
        if (c == '7') yes = true;
    }
    if (yes) cout << "Yes\n";
    else cout << "No\n";
}


Measured memory_bytes: 3628
import java.util.Scanner;
public class Main
{
	public static void main(String[] args) 
	{
		Scanner in=new Scanner(System.in);
		char c[]=in.next().toCharArray();
		System.out.println(c[0]=='x'&&c[c.length-1]=='x' ? "x":"o");
	}
}

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

using namespace std;
#define int long long
#define all(a) (a).begin(), (a).end()
#define ms(a,v) memset(a, v, sizeof(a))
#define sz(v) ((int)(v).size())
#define mp make_pair
#define pb push_back
#define prev biiiiirl_sai_de_casa_comi_pra_caralho
#define next trapezio_descendente
#define index eh_ele_que_nos_vai_buscar
#define left aqui_eh_37_anos_porra
#define R32 ({i32 x; scanf("%d", &x); x;})
#define RL ({long long x; scanf("%lld", &x); x;})
#define RC ({char x; scanf(" %c", &x); x;})
#define RI RL
#define ff first
#define ss second
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ii> vii;
typedef long long ll;

const int N = 105;
vector<int> a, b;
int H, d2, m;

bool check(int i, int j){
  vector<int> cnt(H-d2+1);

  for(int k = 0; k < m; k++){
    // H+h == b[k]
    int h = b[k]-H;
   // cerr << "bruting " << i << " " << j << " makes h[" << k << "] = " << h << endl;
    if(h < 0 || h > H-d2) return false;
    if((k == i || k == j) && h != H-d2) return false;
    cnt[h]++;
  }

  for(int i = 1; i <= H-d2; i++) if(cnt[i] < 2) return false;
  return true;
}

int32_t main(){
  // handle n = 2
  //
  int n = RI;
  for(int i = 0; i <n; i++) a.pb(RI);
  int mn = *min_element(all(a));

  if(count(all(a), mn) > 2){
    cout << "Impossible" << endl;
    return 0;
  }

  if(n == 2){
    if(mn != 1 || count(all(a), mn) != 2)
      cout << "Impossible" << endl;
    else cout << "Possible" << endl;

    return 0;
  }


  bool ok = false;
  H = mn;
  d2 = count(all(a), mn) == 2;
  for(int x : a) if(x != mn) b.pb(x);

  m = sz(b);

  for(int i = 0; i < m; i++)
    for(int j = i+1; j < m; j++)
      ok |= check(i,j);
  
  if(ok) cout << "Possible" << endl;
  else cout << "Impossible" << endl;
}


Measured memory_bytes: 384
/***
**   AUTHOR::ASHUTOSH MOUDGIL
***/


#include<bits/stdc++.h>
using namespace std;

#define pb push_back
#define mp make_pair
#define IOS ios_base::sync_with_stdio(false); cin.tie(NULL);
#define F first
#define S second
#define int long long
//#define ll long long
#define all(x) x.begin(),x.end()
#define rsort(x) sort(all(x)); reverse(all(x));
#define endl '\n'
#define vi vector<int>
#define vlli vector<long long>
#define pii pair<int,int>
#define mod 1000000007
#define LMAX 1e18
#define deb(x) cout<<#x<<" : "<<x<<endl;
#define PI 3.141592654
#define deb1(x) cout << #x <<"="<< x <<endl;
#define deb2(x,y) cout << #x <<"="<<x<<", "<<#y<<"="<<y <<endl;
#define deb3(x,y,z) cout << #x <<"="<<x<<", "<<#y<<"="<<y <<", "<<#z<<"="<<z<<endl;
#define deb4(x,y,z,a) cout << #x <<"="<<x<<", "<<#y<<"="<<y <<", "<<#z<<"="<<z<< ", "<<#a <<"="<<a << endl;
#define debarr(x) cout << #x<<"::"<<endl;for(int i : x){cout << i <<" ";} cout <<endl;

inline void add(int& a, int b){a = (a+b); if(a>=mod)a-=mod;}
inline void sub(int& a, int b){a = a-b; if(a<0)a+=mod;}
inline void mul(int& a, int b){a = (a*b)%mod;}



void mymain(){
    int n;
    cin >> n;
    int ans=0;
    for(int i=1;i<=n;i++){
        if(i%3!=0 && i%5!=0)
            ans+=i;
    }
    cout << ans <<endl;
}

signed main(){
IOS;
///freopen("input.txt", "r", stdin);
///freopen("output.txt", "w", stdout);
int t=1;
///cin>>t;

for(int tt=0;tt<t;tt++){
   ///cout << "Case #" << tt+1 <<": ";
   mymain();
}
return 0;
}
/*

*/


Measured memory_bytes: 3636
#include "bits/stdc++.h"
using namespace std;

int main() {
   int x;
   cin >> x;
   if(x == 0) {
       puts("0");
   } else if(x % 500 == 0) {
       cout << 2*x << endl;
   } else {
       cout << (x / 500)*1000 + ((x%500)/5)*5 << endl;
   }
}

Measured memory_bytes: 256
S = list(input())

odd = ["R", "U", "D"]
even = ["L", "U", "D"]

for i, s in enumerate(S):
    if i % 2 == 0 and s not in odd:
        print("No")
        break
    if i % 2 == 1 and s not in even:
        print("No")
        break
else:
    print("Yes")


Measured memory_bytes: 2940
#in1 = '125'        #176
#in1 = '9999999999' #12656242944
in1 = input()
len = len(in1)

in_array = [''] * ((len * 2) - 1)
for idx1 in range(len):
    in_array[idx1 * 2] = in1[idx1]

RC = 0
for idx1 in range(2 ** (len - 1)):
    pos = format(idx1, '0' + str(len - 1) + 'b')
    for idx2 in range(len - 1):
        if pos[idx2] == '1':
            in_array[idx2 * 2 + 1] = '+'
        else:
            in_array[idx2 * 2 + 1] = ''
    RC += eval(''.join(in_array))

print(RC)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
#include <math.h>
#define _GLIBCXX_DEBUG
#define _LIBCPP_DEBUG 0

using namespace std;
#define ll long long
#define rep(i,n) for (int i = 0; i < n; i++)
#define MOD (1000000007)
#define vi vector<int>
#define vl vector<ll>
#define vvi vector<vi>
#define pii pair<int, int>
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

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

const ll INF = 1LL << 60;

const int dh[4] = {1,0,-1,0};
const int dw[4] = {0,1,0,-1};

int main(){
  int x,y; cin >> x >> y;
  int ans = 0;
  if(x == 1) ans += 3e5;
  else if(x == 2) ans += 2e5;
  else if(x == 3) ans += 1e5;

  if(y == 1) ans += 3e5;
  else if(y == 2) ans += 2e5;
  else if(y == 3) ans += 1e5;

  if(x == 1 && y == 1) ans += 4e5;

  std::cout << ans << '\n';
}


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

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

int main(){
    int n; cin>>n;
    vector<lp> rob(n);
    rep(i,n){
        ll c, lo;
        cin>>c>>lo;
        rob[i].first = c+lo;
        rob[i].second = c-lo;
    }
    sort(rob.begin(),rob.end());
    int ans = 1;
    ll lim = rob[0].first;
    for(int i = 1; i<n; ++i){
        if(rob[i].second>=lim){
            ans++; lim = rob[i].first;
        }
    }
    cout<<ans<<endl ; return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <algorithm>
#include <deque>
#include <iterator>
#include <list>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <stack>
#include <utility>
#include <vector>
#include <string>
#include <iostream>
using namespace std;
int main() {
	int a,b,c;
	cin >> a;
	if (a % 2== 0 ) {
		b = a / 2;
		cout << b << endl;
	}
else {
		c = (a / 2) + 1;
			cout << c << endl;
}
	return 0;
}

  

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

int main() {
	
	int n; cin >> n;
	vector<pair<int, int>> red;
	for (int i = 0; i < n; i++) {
		int a, b; cin >> a >> b;
		red.push_back({ a,b });
	}
	vector<pair<int, int>> blue;
	for (int i = 0; i < n; i++) {
		int c, d; cin >> c >> d;
		blue.push_back({ c,d });
	}
	sort(blue.begin(), blue.end());

	vector<bool> used(n, false);
	int cnt = 0;
	for (int i = 0; i < n; i++) {
		int bx = blue[i].first;
		int by = blue[i].second;
		int near_y = -1000;
		int near_j = -1;
		for (int j = 0; j < n; j++) {
			if (used[j]) continue;
			int rx = red[j].first;
			int ry = red[j].second;
			if (bx < rx) continue;
			if (by < ry) continue;
			if (near_y < ry) {
				near_j = j;
				near_y = ry;
			}
		}
		if (near_j != -1) {
			cnt++;
			used[near_j] = true;
		}
	}
	cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 3620
#include<bits/stdc++.h>
using namespace std;
#define MP make_pair
const int Maxn=1e5+7;
int n;
pair <int,int> t1[Maxn];
pair <int,int> t0[Maxn];
int main(){
	cin>>n;
	for(int i=0,a;i<n;i++){
		cin>>a;
		if(i%2==0)
			t0[a]=MP(t0[a].first-1,a);
		if(i%2==1)
			t1[a]=MP(t1[a].first-1,a);
	}
	sort(t0,t0+Maxn);
	sort(t1,t1+Maxn);
	if(t1[0].second!=t0[0].second){
		cout<<n/2+t1[0].first+n/2+t0[0].first;
	}
	else{
		int ans=min(n/2+t1[0].first+n/2+t0[1].first,n/2+t1[1].first+n/2+t0[0].first);
			cout<<ans;
	}
}


Measured memory_bytes: 1792
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
using namespace std;
typedef long long int lli;
typedef unsigned long long int ulli;
typedef long double ld;
#define vec(s) vector

#define vvec(s) vector<vector
>
typedef vector<lli> vi;
typedef vector<vi> vvi;
typedef pair<lli,lli> pii;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define Yes(x) cout<<(x?"Yes":"No")<<endl;
#define YES(x) cout<<(x?"YES":"NO")<<endl;
#define out(s) cout<<s<<endl;
#define pb(s) push_back(s);
#define sp " " 
#define INF 10000000000
#define LINF 9000000000000000000
#define all(s) s.begin(),s.end()
void vout(vi v){
    for(lli i=0;i<v.size();i++)
    cout<<v.at(i)<<endl;
}
int main(){
    cout << std::fixed << std::setprecision(10);
    lli n, l;
    cin>>n>>l;
    lli p=0;
    if ((l+n-1)*l<=0) {
        p=0;
    }
    else if(l>0){ 
        p=l;
    }
    else{ 
        p=l+n-1;
    }
    lli ans=n*l-n+((n+1)*n)/2;
    out(ans-p);

}

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

using namespace std;
long long F(long long x)
{
    int cnt=0;
    while(x)
    {
        x/=10;
        cnt++;
    }
    return cnt;
}
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    long long n;
    cin>>n;
    long long sq=sqrt(n),ans=1e18;
    for(long long i=1;i<=sq;i++)
    {
        if(n%i==0)
        {
            ans=min(ans,max(F(i),F(n/i)));
        }
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
/*
 * ALDS1_9_B.cpp
 *
 *  Created on: May 5, 2018
 *      Author: 13743
 */

#include<iostream>
#include<algorithm>

using namespace std;


void maxHeapify(int* H, int n, int i) {
	int l = 2*i;
	int r = 2*i + 1;
	int largest = i;
	if(l <= n && H[l] > H[i]) {
		largest = l;
	}
	if(r <= n && H[r] > H[largest]) {
		largest = r;
	}
	if(largest != i) {
		swap(H[i], H[largest]);
		maxHeapify(H, n, largest);
	}
}

void buildMaxHeap(int* H, int n) {
	for(int i=n/2; i>0; i--) {
		maxHeapify(H, n, i);
	}
}

int main() {
	int n;
	int H[500001];

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

	buildMaxHeap(H, n);

	for(int i=1; i<=n; i++) {
		cout << " " << H[i];
	}
	cout << endl;
}





Measured memory_bytes: 5012
gets
c=0
puts$<.map{|s|a=0
[s.chop.bytes.map{a+=81-_1*2}.min,a]}.sort_by{0<_2 ? -_1:2e9-_2+_1}.map{_2-_1+c-=_2}.max>0||c<0?:No: :Yes

Measured memory_bytes: 103384