akhauriyash/Code-Regression huggingface dataset:
//***Little by little one travels far***
 
#include<bits/stdc++.h>
using namespace std;
 
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define ll long long
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define rep(i,n) for(i=0;i<n;i++)
#define forn(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define for1(i, n) for (ll i = 1; i <= (ll)(n); ++i)
#define ford(i, n) for (ll i = (ll)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (ll i = (ll)(a); i <= (ll)(b); ++i)
#define fora(it,x) for(auto it:x)
#define PI 3.14159265
#define sync ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define endl "\n"
 
typedef pair<ll, ll> pii;
typedef vector<ll> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long i64;
typedef vector<i64> vi64;
typedef vector<vi64> vvi64;
typedef pair<i64, i64> pi64;
typedef long double ld;
 
template<class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }
vector<ll> vec[40322];
ll cn=0;
void fun(set<ll>s,vector<ll> v){
  //for(auto x:v){ cout<<x;}
  //cout<<"\n";
  if(s.size()==0){
    vec[cn++]=v;
    return ;
  }
  set<ll> s1=s;
  for(auto it=s.begin();it!=s.end();it++){
    ll te=*it;
    s1.erase(*it);
    v.pb(te);
    fun(s1,v);
    v.pop_back();
    s1.insert(*it);
  }
}

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

  set<ll> s;
  forn(i,n){
    s.insert(i+1);
  }
  vector<ll> v;
  fun(s,v);

  vector<ll> a(n);
  vector<ll> b(n);
  forn(i,n) cin>>a[i];
  forn(i,n) cin>>b[i];

  ll p1,p2;
  forn(i,cn){
    ll f=0;
    forn(j,n){
      if(vec[i][j]!=a[j]){
        f=1;
        break;
      }
    }
    if(f==0){p1=i;break;}
  }

  forn(i,cn){
    ll f=0;
    forn(j,n){
      if(vec[i][j]!=b[j]){
        f=1;
        break;
      }
    }
    if(f==0){p2=i;break;}
  }

  cout<<abs(p1-p2);
}

Measured memory_bytes: 4352
//Author: Prakhar Asaiya
#include<bits/stdc++.h>
using namespace std;
#define REP(i,a,b) for(ll i=a;i<b;++i)
#define REPN(i,a,b) for(ll i=a;i<=b;++i)
#define db1(x) cout<<#x<<"="<<x<<'\n'
#define db2(x,y) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<'\n'
#define db3(x,y,z) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<","<<#z<<"="<<z<<'\n'
#define ll long long
const int M=1e9+7;
const int INF=1e9+5;

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

  int a,b,c,d;
  cin>>a>>b>>c>>d;
  int x=(a+d-1)/d;
  int y=(b+c-1)/b;
  if(x>=y)
  cout<<"Yes\n";
  else
  cout<<"No\n";
 
  
   return 0;
}


Measured memory_bytes: 3608
// 8クィーン問題
#include<iostream>
#include<cassert>

using namespace std;

#define N 8
#define FREE -1
#define NOT_FREE 1

int row[N], col[N], dpos[2 * N - 1], dneg[2 * N - 1];

bool X[N][N];

// 初期化処理
void initialize()
{
    for(int i = 0; i < N; i++)
    {
        row[i] = FREE;
        col[i] = FREE;
    }

    for(int i = 0; i < 2 * N - 1; i++)
    {
        dpos[i] = FREE;
        dneg[i] = FREE;
    }
}

// 表示用の処理
void printBoard()
{
    for(int i = 0; i < N; i++)
    {
        for(int j = 0; j < N; j++)
        {
            if( X[i][j] )
            {
                if( row[i] != j )
                {
                    // 初期配置に対応しているかを調べる
                    // 題意の並べ方に対応するまで検索を継続する
                    return;
                }
            }
        }
    }

    // 結果の表示をする
    for(int i = 0; i < N; i++)
    {
        for(int j = 0; j < N; j++)
        {
            cout << ( ( row[i] == j ) ? "Q" : ".");
        }

        cout << endl;
    }
}

// 各行について, クィーンを置くことが可能な列を検索する関数
// i : クィーンを置く行のNo.
void recursive(int i)
{
    if( i == N )
    {
        // クィーンの配置に成功
        printBoard();
        return;
    }

    for(int j = 0; j < N; j++)
    {
        // 横方向に検索していく
        if( NOT_FREE == col[j] ||
            NOT_FREE == dpos[i + j] ||
            NOT_FREE == dneg[i - j + N - 1] )
        {
            // (i, j)が他のクィーンに襲撃されている場合は無視
            continue;
        }

        // (i, j)にクィーンを配置する
        // i行目の j の位置にクィーンを配置する
        row[i] = j;
        col[j] = dpos[i + j] = dneg[i - j + N - 1] = NOT_FREE;

        // 次の行を試す
        recursive(i + 1);

        // -------------------------------------------------------
        // 再帰呼び出しをしているので、ここに来た時は, 状態は i の時に戻っている
        // -------------------------------------------------------

        // ----- バックトラックの操作 -----
        // (i, j)に配置されているクィーンを取り除く
        row[i] = col[j] = dpos[i + j] = dneg[i - j + N - 1] = FREE;
    }

    // クィーンの配置に失敗した時にここにくる
}

int main()
{
    initialize();

    for(int i = 0; i < N; i++)
    {
        for(int j = 0; j < N; j++)
        {
            X[i][j] = false;
        }
    }

    int k;

    cin >> k;

    for(int i = 0; i < k; i++)
    {
        int r, c;

        cin >> r >> c;

        // 初期配置を保存する
        X[r][c] = true;
    }

    // 並べ方の検索を開始する
    recursive(0);

    return 0;
}



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

typedef long long ll;
const ll MOD = 1e9+7;
int n;
string s;
ll ans=0;
map<string,ll>mp;

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

    for(int i=1;i<=n;i++){
        cin>>s;
        sort(s.begin(),s.end());
        ans+=mp[s];
        mp[s]++;
    }

    cout<<ans;
    return 0;
}


Measured memory_bytes: 11264
def main():
    S = input()
    N = len(S)
    li = []
    pre = S[0]
    pre_cnt = 1
    l_cnt = 0
    for i in range(1, N):
        if (pre == '<' and S[i] == '>') or (pre == '>' and S[i] == '<'):
            li.append((pre*pre_cnt, l_cnt))
            pre = S[i]
            pre_cnt = 1
            l_cnt += 1
        else:
            pre_cnt += 1
    else:
        li.append((pre*pre_cnt, l_cnt))
    finished = [False] * (len(li)+1)
    li.sort(key=lambda s: len(s[0]), reverse=True)

    ans = 0
    for i in range(len(li)):
        if li[i][0][0] == '<':
            n = len(li[i][0])
            if finished[li[i][1] + 1]:
                n -= 1
            ans += (n*(n+1))//2
        else:
            n = len(li[i][0])
            if finished[li[i][1]]:
                n -= 1
            ans += (n*(n+1))//2
        finished[li[i][1]] = True
        finished[li[i][1] + 1] = True

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 88264
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<string>
#include<vector>
#include<set>
#include<cctype>
using namespace std;
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
const long long INF = 1LL << 60;

int main(void){
	ios::sync_with_stdio(false); cin.tie(0);
	
	int a,b;
	cin>>a>>b;
	if(a<=b)cout<<a<<endl;
	else cout<<a-1<<endl;
	
	
	
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
#include<complex>
using namespace std;

//#define int long long
typedef long long ll;

typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = mod * mod;
typedef pair<int, int>P;
typedef pair<int, bool> sP;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef pair<ll, ll> LP;
typedef vector<ll> vec;
typedef long double ld;
typedef pair<ld, ld> LDP;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef vector<vector<ll>> mat;
typedef vector<ll> vec;

void solve() {
	int n, m, w, t; cin >> n >> m >> w >> t;
	map<string, int> mp;
	vector<int> v(m), p(m);
	rep(i, m) {
		string s; cin >> s;
		mp[s] = i;
		cin >> v[i] >> p[i];
	}
	vector<int> x(n), y(n);
	vector<vector<int>> r(n), q(n);
	rep(i, n) {
		int sz; cin >> sz;
		cin >> x[i] >> y[i];
		r[i].resize(sz); q[i].resize(sz);
		rep(j, sz) {
			string s; cin >> s;
			r[i][j] = mp[s];
			cin >> q[i][j];
		}
	}
	/*vector<vector<int>> dp(n);
	rep(i, n) {
		dp[i].resize(w + 1, -mod);
		dp[i][0] = 0;
		rep(j, r[i].size()) {
			int id = r[i][j];
			int wei = v[id];
			int bene = p[id]-q[i][j];
			rep(k, w + 1) {
				if (k + wei <= w) {
					dp[i][k + wei] = max(dp[i][k + wei], dp[i][k] + bene);
				}
			}
		}
	}*/
	vector<P> vp;
	rep1(i, (1 << n) - 1) {
		vector<int> dp(w + 1, -mod);
		dp[0] = 0;
		vector<int> bene(m, -mod);
		vector<int> e;
		rep(j, n) {
			if (i&(1 << j)) {
				e.push_back(j);
				rep(k, r[j].size()) {
					bene[r[j][k]] = max(bene[r[j][k]], p[r[j][k]]-q[j][k]);
				}
			}
		}
		rep(j, m) {
			rep(k, w + 1) {
				if (k + v[j] <= w) {
					dp[k + v[j]] = max(dp[k+v[j]], dp[k] + bene[j]);
				}
			}
		}
		int ma = 0;
		rep(j, w + 1)ma = max(ma, dp[j]);
		int cost = mod;
		while (1) {
			int sum = 0;
			sum += abs(x[e[0]]) + abs(y[e[0]]);
			sum += abs(x[e.back()]) + abs(y[e.back()]);
			rep(i, (int)e.size() - 1) {
				int dx = abs(x[e[i]] - x[e[i + 1]]);
				int dy = abs(y[e[i]] - y[e[i + 1]]);
				sum += dx + dy;
			}
			cost = min(cost, sum);
			if (!next_permutation(e.begin(), e.end()))break;
		}
		vp.push_back({ ma,cost });
	}
	vector<ll> dp(t+1, -INF);
	dp[0] = 0;
	rep(i, vp.size()) {
		int wei = vp[i].second;
		ll val = vp[i].first;
		rep(j, t + 1) {
			if (j + wei <= t) {
				dp[j + wei] = max(dp[j + wei], dp[j] + val);
			}
		}
	}
	ll ans = -INF;
	rep(i, t + 1)ans = max(ans, dp[i]);
	cout << ans << endl;
}


signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(7);
	//init();
	solve();
	//stop
	return 0;
}




Measured memory_bytes: 3344
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <tuple>
#include <queue>
#include <set>
#include <math.h>
#include <array>
#include <list>
#include <set>
const int MOD=1000000007;
const int INF=1000000000;
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pair<int,int> > vp;
int N;
ll K,ans=0;
ll A[100005];
int main(void)
{
  cin >> N >> K;
  for(int i=0;i<N;i++)
    {
      cin >> A[i];
    }
  for(int d=60;d>=-1;d--)
    {
      if(d!=-1 && !(K&(1LL<<d))) continue;
      ll tmp=0;
      for(int e=60;e>=0;e--)
	{
	  ll mask=1LL<<e;
	  int num=0;
	  for(int i=0;i<N;i++) if(A[i]&mask) num++;
	  if(e>d)
	    {
	      if(K&mask)tmp+=mask*(N-num);
	      else tmp+=mask*num;
	    }
	  else if(e==d)
	    {
	      tmp+=mask*num;
	    }
	  else
	    {
	      tmp+=mask*max(num,N-num);
	    }
	}
      ans=max(ans,tmp);
    }
  cout << ans << endl;
  return 0;
}
//return 0;



Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define F(i,a,b) for(long long i=a;i<=b;i++)
ll  w[1001],v[1001],f[107][100007];
ll n,W,s=0,i=0,j=0;
main()
{
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
cin>>n>>W;
F(i,1,n){   cin>>w[i]>>v[i]; s+=v[i]; }
F(i,1,s)f[0][i]=30000000000;
F(i,1,n)F(j,1,s)
{
   f[i][j]=f[i-1][j];
   if(j>=v[i])f[i][j]=min(f[i][j],f[i-1][j-v[i]]+w[i]);
}
for(i=s;i>=1;i--)
if(f[n][i]<=W){ cout<<i;  break;}
}


Measured memory_bytes: 80128
#!/usr/bin/env python3
#ABC46 D

import sys
import math
import bisect
sys.setrecursionlimit(1000000000)
from heapq import heappush, heappop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7

s = input()
n = len(s)
ans = 0
cnt = 0
for i in range(n):
    if s[i] == 'g':
        if cnt > 0:
            ans += 1
            cnt -= 1
        else:
            cnt += 1
    else:
        if cnt == 0:
            ans -= 1
            cnt += 1
        else:
            cnt -= 1
print(ans)


Measured memory_bytes: 40360
#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <climits>
#include <cmath>
#include <utility>

using namespace std;

const int maxn = 100002;

int n, h[maxn], f[maxn];

int main() {

	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	cin >> n;
	for (int i = 0; i < n; ++i) {
		cin >> h[i];
	}
	
	f[0] = 0;
	f[1] = abs(h[1]-h[0]);
	for (int i = 2; i < n; ++i)
		f[i] = min(f[i-1] + abs(h[i]-h[i-1]), f[i-2] + abs(h[i]-h[i-2]));

	cout << f[n-1] << endl;

	return 0;
}

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

#define MAX 5005

int dp[MAX][MAX], lim, n;
string s;

int solve(int l1, int l2) {
    if (l1 > lim) return 0;
    if (l2 >= n) return 0;

    if (dp[l1][l2] != -1) return dp[l1][l2];

    if (s[l1] != s[l2]) {
        dp[l1][l2] = 0;
        return 0;
    }

    int ret = 0;
    ret = 1 + solve(l1 + 1, l2 + 1);
    return dp[l1][l2] = ret;
}


int main() {
    memset(dp, -1, sizeof(dp));

    cin >> n;
    cin >> s; 

    int ans = 0;

    for (int i = 0; i < n; i++) {
        for (int j = i + 1; j < n; j++) {
            lim = j - 1;
            ans = max(ans, solve(i, j));
        }
    }

    cout << ans;
    return 0;
}

Measured memory_bytes: 98304
#!/usr/bin/ruby
h={2=>[[2,1]],3=>[[3,1]],4=>[[2,2]],5=>[[5,1]],6=>[[2,1],[3,1]],7=>[[7,1]],8=>[[2,3]],9=>[[3,2]],10=>[[2,1],[5,1]],11=>[[11,1]],12=>[[2,2],[3,1]],13=>[[13,1]],14=>[[2,1],[7,1]],15=>[[3,1],[5,1]],16=>[[2,4]],17=>[[17,1]],18=>[[2,1],[3,2]],19=>[[19,1]],20=>[[2,2],[5,1]],21=>[[3,1],[7,1]],22=>[[2,1],[11,1]],23=>[[23,1]],24=>[[2,3],[3,1]],25=>[[5,2]],26=>[[2,1],[13,1]],27=>[[3,3]],28=>[[2,2],[7,1]],29=>[[29,1]],30=>[[2,1],[3,1],[5,1]],31=>[[31,1]],32=>[[2,5]],33=>[[3,1],[11,1]],34=>[[2,1],[17,1]],35=>[[5,1],[7,1]],36=>[[2,2],[3,2]]}
while(l=gets.split)!=["0","0"]	
	n=l[0].to_i;m=l[1].to_i(n)
	p h[n].map{|a,b|
		z=m;r=0
		while z>0 do r+=(z/=a) end
		r/b
	}.min
end

Measured memory_bytes: 2552
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, s, n) for (int i = (s); i < (n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main() {
  int n, k;
  cin >> n >> k;
  int a[n];
  rep(i, n) cin >> a[i];
  sort(a, a + n);
  int ans = 0;
  rep(i, k) ans += a[i];
  cout << ans << endl;
  return 0;
}

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


int main() {
	int n;
	cin >> n;
	vector<int> vec(n);
	for (int i = 0; i < n; i++) cin >> vec[i];
	vector<int> visited(n, 0);

	int current = 0, count = 0;
	while (visited[current] == 0 && vec[current] != 2) {
		count++;
		visited[current] = 1;
		current = vec[current] - 1;
	}

	if (vec[current] == 2) cout << count + 1 << endl;
	else cout << -1 << endl;
	return 0;
	
	
}


Measured memory_bytes: 1024
a,b,t,i,N;
main(){
    long c=0;
    for(scanf("%d",&N);N--;i++){
        scanf("%d",&t);
        a=i&&a<t?a:t;
        b=i&&b>t?b:t;
        c+=t;
    }
    printf("%d %d %ld\n",a,b,c);
}

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

using namespace std;
using ll = long long;

int main()
{
  string N; cin >> N;
  cout << count(ALL(N), '2') << endl;
}

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

#define long long int

const int D = 365;
vector<int> C(26), ans(D, 0);
vector<vector<int>> S(D, vector<int>(26));

void input()
{
    int tmp;
    cin >> tmp;
    rep(i,26) cin >> C[i];
    rep(i,D)rep(j,26) cin >> S[i][j];
    rep(i,D) cin >> ans[i]; rep(i,D) ans[i]--; //B,C問題用
}
void output()
{
    for(auto x : ans)
        cout << x+1 << "\n";
}
void greedy()
{
    vector<int> last(26, -1);
    rep(i,D)
    {
      int cur = 0, pt = -1e9;
      rep(j,26)
      {
        int sum = S[i][j];
        rep(k, 26)
        {
          if(j == k) continue;
          sum -= C[k] * (i - last[k]);
        }
        if(sum > pt)
        {
          cur = j;
          pt = sum;
        }
      }
      ans[i] = cur;
      last[cur] = i;
    }   
}
void solve()
{
  greedy();
}

int main()
{
    input();
    solve();
    output();
    return 0;
}


Measured memory_bytes: 3688
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned ll
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define IOS std::ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define pb push_back
using namespace std;

// DEBUG TEMPLATE
void __print(int x) {cout << x;}
void __print(long x) {cout << x;}
void __print(long long x) {cout << x;}
void __print(unsigned x) {cout << x;}
void __print(unsigned long x) {cout << x;}
void __print(unsigned long long x) {cout << x;}
void __print(float x) {cout << x;}
void __print(double x) {cout << x;}
void __print(long double x) {cout << x;}
void __print(char x) {cout << '\'' << x << '\'';}
void __print(const char *x) {cout << '\"' << x << '\"';}
void __print(const string &x) {cout << '\"' << x << '\"';}
void __print(bool x) {cout << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cout << '{'; __print(x.first); cout << ','; __print(x.second); cout << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cout << '{'; for (auto &i: x) cout << (f++ ? "," : ""), __print(i); cout << "}";}
void _print() {cout << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cout << ", "; _print(v...);}

void OFFLINE(){
    #ifndef ONLINE_JUDGE 
        freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
        #define debug(x...) cout << "[" << #x << "] = ["; _print(x)
        #else
            #define debug(x...)
    #endif
}

const int MOD = 1e9 + 7;

int factors(int n) {

    if(n <= 2) {
        return n;
    }

    int cnt = 0;
    for(int i = 1; i * i <= n; i++) {
        if(n % i == 0){
            cnt += (1 + (i != (n / i)));
        }
    }

    return cnt;
}

int main(){

    IOS;
    OFFLINE();
    //check for corner test cases

    int n;
    cin >> n;

    int cnt = 0;

    for(int i = 1; i < n; i++) {
        cnt += factors(n - i);
    }

    cout << cnt << "\n";

    //check for corner test cases
    return 0;
}

Measured memory_bytes: 3652
import sys
from collections import defaultdict

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

in_n = lambda: int(readline())
in_nn = lambda: map(int, readline().split())
in_s = lambda: readline().rstrip().decode('utf-8')
in_nl = lambda: list(map(int, readline().split()))
in_nl2 = lambda H: [in_nl() for _ in range(H)]
in_map = lambda: [s == ord('.') for s in readline() if s != ord('\n')]
in_map2 = lambda H: [in_map() for _ in range(H)]
in_all = lambda: map(int, read().split())


def main():
    N, M = in_nn()
    A = in_nl()
    total_sum = [0] * (N + 1)

    for i in range(N):
        total_sum[i + 1] = total_sum[i] + A[i]

    for i in range(N + 1):
        total_sum[i] %= M

    d = defaultdict(lambda: 0)
    for i in range(N + 1):
        d[total_sum[i]] += 1

    ans = 0
    for k, v in d.items():
        ans += v * (v - 1) // 2

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 22712
#include <bits/stdc++.h>
//#include <atcoder/all>

typedef unsigned long long ULLONG;
typedef long long LLONG;
static const LLONG MOD_NUM = 998244353; //1000000007

template<class _T> static void get(_T& a) {
	std::cin >> a;
}
template<class _T> static void get(_T& a, _T& b) {
	std::cin >> a >> b;
}
template<class _T> static void get(_T& a, _T& b, _T& c) {
	std::cin >> a >> b >> c;
}
template <class _T> static _T tp_abs(_T a) {
	if (a < (_T)0) {
		a *= (_T)-1;
	}
	return a;
}

static void E();

int main()
{
	E();
	fflush(stdout);
	return 0;
}

static void E()
{
	LLONG N, X, M;
	get(N, X, M);

	std::set<LLONG> nums;
	std::vector<LLONG> ai(1);
	ai[0] = X;
	LLONG sum = X, looped = 0;
	nums.insert(X);
	bool zero = false;
	for (LLONG i = 1; i <= N; i++) {
		LLONG num = (ai[i - 1] * ai[i - 1]) % M;
		if (num == 0) {
			zero = true;
			break;
		}
		if (nums.find(num) == nums.end()) {
			sum += num;
			nums.insert(num);
			ai.push_back(num);
		}
		else {
			looped = num;
			break;
		}
	}

	LLONG ans = 0;
	if (zero) {
		for (int i = 0; i < N && i < ai.size(); i++) {
			ans += ai[i];
		}
	}
	else {
		int loopIdx = 0;
		while (looped != ai[loopIdx]) loopIdx++;
		
		if (N <= (LLONG)ai.size()) {
			for (int i = 0; i < N; i++) {
				ans += ai[i];
			}
		}
		else {
			ans = sum;

			LLONG count = N - (LLONG)ai.size();
			LLONG mul = count / (LLONG)(ai.size() - loopIdx);
			LLONG surp = count % (LLONG)(ai.size() - loopIdx);
			int cnt = ai.size();
			LLONG loopSum = 0;
			for (int i = loopIdx; i < cnt; i++) {
				loopSum += ai[i];
			}
			ans += (loopSum * mul);
			for (int i = 0; i < surp; i++) {
				ans += ai[i + loopIdx];
			}
		}
	}
	printf("%lld\n", ans);
}


Measured memory_bytes: 5988
#include<bits/stdc++.h>
using namespace std;
#define INFTY 1<<20
typedef long long int ll;
const int MOD=1000000007;
using Graph = vector<vector<int>>;
using ipair = pair<ll,ll>;
#define rep(i,n) for (int i = 0; i < (n); ++i)
bool operator< (const ipair a, const ipair b){return a.first < b.first;};
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}

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

  priority_queue<ipair,vector<ipair>,less<ipair>> a;
  rep(i,n){
    ll an;cin>>an;
    a.push(make_pair(an,1));
  }
  rep(i,m){
    ll b,c;cin>>b>>c;
    a.push(make_pair(c,b));
  }
  ll sum=0;
  rep(i,n){
    pair<ll,ll> an = a.top();
    a.pop();
    sum += an.first;
    an.second--;
    if(an.second>0)a.push(an);
  }
  cout<<sum;
  return 0;
}

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

#define MAX 1000001

using namespace std;

void to_sieve(vector<bool>& sieve, vector<int>& num, int N)
{
  int sum = 0, prev;
  for (int i = 0; i < N; i++){
    if (sieve[num[i]] == true){
      if (num[i] == prev){
	sum--;
	prev = 0;
      }
      continue;
    }
    sum++;
    int temp = num[i];
    while (temp < MAX){
      sieve[temp] = true;
      temp += num[i];
    }
    prev = num[i];
  }
  cout << sum << '\n';
}

int main(void)
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N;
  vector<bool> sieve(MAX, false);
  cin >> N;
  vector<int> num(N);
  for (int i = 0; i < N; i++)
    cin >> num[i];
  sort(num.begin(), num.end());
  to_sieve(sieve, num, N);
  return 0;
}


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

def io_generator():
	return input()

#+++++++++++++++++++


def gt(t):
	m=t%10
	if m > 0:
		return t+(10-m),10-m
	return t,0
	
def main(io):
	l =[ int(io()) for _ in range(5)]
	ll=[gt(t) for t in l]
	dd= sum([t[0] for t in ll])
	nn=max([t[1] for t in ll])
	return dd-nn

#++++++++++++++++++++

if __name__ == "__main__":
	io= lambda : io_generator()
	print (main(io))

Measured memory_bytes: 3064
import java.util.*;

public class Main {
    public static void main(final String[] args) {
        Scanner sc = new Scanner(System.in);
        int n =sc.nextInt();
        int[] a = new int[n+2];
        int sum = 0;
        for (int i = 1; i <= n; i++) {
            a[i] = sc.nextInt();
            sum += Math.abs(a[i-1] - a[i]);

        }
        sum += Math.abs(0 - a[n]);

        for (int i = 1; i <= n; i++) {
            int p = check(a[i-1], a[i], a[i-+1]);
            if (p == 1) {
                System.out.println(sum);
            } else {
                int tmp = sum;
                tmp -= (Math.abs(a[i] - a[i-1]) + Math.abs(a[i] - a[i+1]));
                tmp += Math.abs(a[i+1] - a[i-1]);
                System.out.println(tmp);
            }
        }
    }

    private static int check(int prev, int cur, int next) {
        if ((prev <= cur && cur <= next) || (next <= cur && cur <= prev)) {
            return 1;
        }
        if ((cur <= prev && prev <= next) || (next <= prev && prev <= cur)) {
            return 2;
        }
        return 3;
    }
}

Measured memory_bytes: 60236
#include <bits/stdc++.h>
using namespace std;
int main(int argc, char **argv) {
  int S;
  cin >> S;
  int prev = S;
  unordered_set<int> lookup;
  lookup.insert(S);
  for (int i = 2; i <= 1000000; ++i) {
    int a;
    if (prev % 2) {
      a = 3 * prev + 1;
    } else {
      a = prev / 2;
    }
    if (lookup.count(a)) {
      cout << i << endl;
      return 0;
    } else {
      lookup.insert(a);
    }
    prev = a;
  }
  return 0;
}

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

int main(){
    int n;
    cin >> n;
    float arr[n];
    float k =0;
    for(int i=0;i<n;i++)
    {
        cin >> arr[i];
        k = k + (1/arr[i]);
        //cout << k << "s" << endl;
    }
    printf("%f", 1/k);
    //cout << 1.0/float(k) << endl;
}

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

int main() {
	int n;
	while(cin>>n){
		int count=0;
		for(int a=0;a<10;a++){
			for(int b=0;b<10;b++){
				for(int c=0;c<10;c++){
					for(int d=0;d<10;d++){
						if((a+b+c+d)==n){
							count++;
						}
					}
				}
			}
		}
		cout<<count<<endl;
	}
	return 0;
}

Measured memory_bytes: 3092
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
using namespace std;
int a[510][510];
int main()
{
	int k;
	scanf("%d",&k);
	int n=min(k,500);
	printf("%d\n",n);
	int now=0;
	for(int i=0;i<n;i++)
	{
		int pos=0;
		for(int j=0;j<n;j++)
		{
			pos=(i-j+n)%n;
			if((j&1)&&n+i+1<=k)
				a[j][pos]=n+i+1;
			else a[j][pos]=i+1;
		}
	}
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<n;j++)
			printf("%d ",a[i][j]);
		printf("\n");
	}
}

Measured memory_bytes: 2176
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
struct drink {
    long long price;
    long long num;
};
bool comparePrice(struct drink& d1, struct drink& d2) {
    return d1.price < d2.price;
}
int main() {
    long long n, m;
    cin >> n >> m;
    vector<drink> v;
    drink d;
    for (int i=0; i<n; i++) {
        cin >> d.price >> d.num;
        v.push_back(d);
    }
    sort(v.begin(), v.end(), comparePrice);
    long long result = 0;
    auto itr = v.begin();
    while (m > 0) {
        if ((*itr).num < m) {            
            result += (*itr).price * (*itr).num;
            m -= (*itr).num;
        } else {
            result += (*itr).price * m;
            m = 0;
        }
        itr++;
    }
    cout << result << endl;
}

Measured memory_bytes: 5344
#include <iostream>
#include <math.h>

using namespace std;

double degree(int hours, int minutes)
{
	double degrees, A , B;
	
	A = (double)hours*5 + (double)minutes/12;
	B = minutes;
	degrees = abs(A - B) * 6;

	if (degrees > 180)
	{
		degrees = 360 - abs(A - B)*6;
	}

	return degrees;
}

int main()
{
	const double PI = 3.14159265358979323846;

	int A, B, H, M;

	cin >> A >> B >> H >> M;

	double uhel;
	uhel = degree(H, M) / 180 * PI;

	double lenght;
	lenght = sqrt(pow(A, 2) + pow(B, 2) - 2 * (double)A * (double)B * cos(uhel));

	printf("%.11f", lenght);

	return 0;
}

Measured memory_bytes: 4172
#include <iostream>
#include <algorithm>
#include <utility>
#include <map>
#include <vector>
#include <cstring>
#include <climits>
#include <queue>
#include <cmath>
#include <iomanip>
#include <set>
#include <bitset>

using namespace std;

typedef long long LL;
typedef pair<int, int> pii;
typedef pair<int, pii> tmp;
typedef pair<int, tmp> state;

int H, W, K;
int sx, sy, ex, ey;
// U, R, D, L
int dx[4] = {-1, 0, 1, 0};
int dy[4] = {0, 1, 0, -1};
priority_queue<state, vector<state>, greater<state> > pq;

int main() {
  scanf("%d%d%d", &H, &W, &K);
  scanf("%d%d%d%d", &sx, &sy, &ex, &ey);
  sx--; sy--; ex--; ey--;
  vector<vector<char> > mat(H, vector<char>(W, '.'));
  vector<vector<int> > dist(H, vector<int>(W, -1));
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      scanf(" %c", &mat[i][j]);
    }
  }

  dist[sx][sy] = 0;
  pq.push(state(0, tmp(-1, pii(sx, sy))));
  while (pq.size()) {
    int d = pq.top().first;
    int prv = pq.top().second.first;
    int x = pq.top().second.second.first, y = pq.top().second.second.second;
    pq.pop();
    if (d != dist[x][y]) continue;
    if (x == ex && y == ey) {
      break;
    }
    for (int i = 0; i < 4; i++) {
      if ((i%2)== (prv%2) || i == prv) continue;
      for (int k = 1; k <= max(H, W); k++) {
        int nx = x + dx[i] * k, ny = y + dy[i] * k;
        if (nx < 0 || ny < 0 || nx >= H || ny >= W) break;
        if (mat[nx][ny] == '@') break;
        int nd = d + (k + K - 1) / K;
        if (dist[nx][ny] == -1 || dist[nx][ny] > nd) {
          dist[nx][ny] = nd;
          pq.push(state(nd, tmp(i, pii(nx, ny))));
        } 
      }
    }
  }
  printf("%d\n", dist[ex][ey]);
}

Measured memory_bytes: 28484
#include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<queue>
#include<deque>
#include<regex>
#include<stack>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
#include<iomanip>
#define rep(i,n) for(int i=0;i<n;i++)

typedef int long long ll;
using namespace std;
typedef pair<int,int> P;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
const ll MOD=1e9+7;
static const int MAX = 100;
static const int INF = (1<<23);
template<class T> T gcd(T a, T b){return b? gcd(b,a%b) : a;}
template<class T> T lcm(T a,T b){return a / gcd(a,b)*b;}

int main(){

    ll n,x,y;
    cin>>n>>x>>y;
    vector<ll> ans(n+1,0);
    for(int i=1;i<=n;i++){
        for(int j=i+1;j<=n;j++){
            ll t1 = j-i;
            ll t2= abs(x-i)+abs(y-j)+1;
            ll t3 =min(t1,t2);
            //cout<<i<<" "<<j<<" "<<t3<<endl;
            ans[t3]++;
        }
    }
    rep(i,n-1){
        cout<<ans[i+1]<<endl;
    }


return 0;
}


Measured memory_bytes: 256
/**In the name of Allah, the Most Merciful, the Most Merciful.**/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define INF 9223372036854775806
#define pb push_back
#define mp make_pair
#define MOD 1000000007
#define PI 2*acos(0.0)
#define EPS 1e-9
ll max(ll a,ll b) {if(a>b) return a; else return b;}
ll min(ll a,ll b) {if(a<b) return a; else return b;}

int main()
{
    int n;
    cin>>n;
    cout<<(n+n*n+n*n*n)<<endl;

    return 0;
}




Measured memory_bytes: 3636
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0;i < (n);i++)
#define all(v) v.begin(),v.end()
#define dec(n) cout << fixed << setprecision(n);
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using vl = vector<ll>;
using vvl = vector<vl>;

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

ll mod(ll a){
  return (a % 1000000007);
}

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


int main(){
  ll n; cin >> n;
  ll x = n % 10;
  
  if( x==3 ) cout << "bon" << endl;
  else if( x==1 || x==0 || x==6 || x==8 ) cout << "pon" << endl;
  else cout << "hon" << endl;
  
}

Measured memory_bytes: 3628
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds;
using namespace std;
 
#define ff                  first
#define ss                  second
#define endl                "\n"
#define loop(i,s,e)         for(int i=s;i<e;i++)
#define int                 long long
#define vi                  vector<int> 
#define S(v)                sort(v.begin(),v.end())
#define RS(v)               sort(v.rbegin(),v.rend())
#define R(v)                reverse(v.begin(),v.end())
#define mxpq(T)             priority_queue <T>
#define mnpq(T)             priority_queue<T,vector<T>,greater<T>>
#define prv(v)              for(auto &x : v)cout << x << " ";
#define piirv(v)            for(auto &x : v)cout << x.ff << " " << x.ss << endl;
#define prvv(v)             for(auto &x : v)for(auto &y : x.ss)cout << y << " ";
#define mp                  make_pair
#define pii                 pair<int,int>
#define mset(a,f)           memset(a , f , sizeof(a))
#define pb                  push_back
#define inf                 INT_MAX
#define INF                 LLONG_MAX
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> oset;

const int N = 2e6 + 6;
int A[N];
int n;

void solve()
{
	int s,w;
	cin >> s>> w;
	if(w >= s)cout << "unsafe";
	else cout << "safe";
}
 
int32_t main()
{
 
cout<<fixed<<setprecision(16);

ios_base:: sync_with_stdio(false);
cin.tie(NULL); cout.tie(NULL);
 	

 	int t = 1;
 	// cin >> t;
 	while(t--)solve();
  
}

Measured memory_bytes: 3584
/*
   Push yourself, because no one else is going to do it for you.
*/
#include <bits/stdc++.h>
#define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define set_zero(a) memset(a,0,sizeof(a));
#define ll long long int
#define PI 2 * acos(0.0)
#define MAX 1000000000000000000
#define in(a) scanf("%d",&a);
#define out(a) printf("%d",a);
#define INF 1000000 
#define M 1000000007
#define pi 3.14159265 
using namespace std; 
int main(){ 
   fast_io
   ll n;
   cin>>n;
   string s;
   cin>>s;
   if(n >= 3200) cout<<s<<endl;
   else cout<<"red"<<endl;
   return 0;
} 

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

#define ll long long
#define ld long double

#define pii pair<int, int>
#define pci pair<char, int>
#define pcc pair<char, char>

#define vi vector <int>
#define vll vector<long long>
#define vld vector<long double>
#define vb vector<bool>
#define vc vector<char>
#define vs vector<string>

#define vvi vector<vi>
#define vvll vector<vll>
#define vvld vector<vld>
#define vvb vector<vb>
#define vvc vector<vc>
#define vvs vector<vs>

#define vpii vector<pii>
#define vpci vector<pci>
#define vpcc vector<pcc>

#define all(v) (v).begin(), (v).end()
#define allrev(v) (v).rbegin(), (v).rend()
#define allcomp(v) (v).begin(), (v).end(), comp
#define allrevcomp(v) (v).rbegin(), (v).rend(), comp

const int MOD = 1e9 + 7;
const ld pi = 3.1415926535897932384626433832;

#define line cout<<"\n";
#define fast ios_base::sync_with_stdio(false) ; cin.tie(0) ; cout.tie(0);

void printString(ll n)
{
    char str[100]; // To store result (Excel column name)
    ll i = 0; // To store current index in str which is result

    while (n > 0) {
        // Find remainder
        ll rem = n % 26;

        // If remainder is 0, then a 'Z' must be there in output
        if (rem == 0) {
            str[i++] = 'z';
            n = (n / 26) - 1;
        }
        else // If remainder is non-zero
        {
            str[i++] = (rem - 1) + 'a';
            n = n / 26;
        }
    }
    str[i] = '\0';

    // Reverse the string and print result
    reverse(str, str + strlen(str));
    cout << str << endl;

    return;
}

void solve(int test_case){

    ll n;
    cin >> n;

    printString(n);
}

int main(){
    fast
    int test = 1;
    //cin>>test;
    for(int i = 1; i <= test; i++){
        solve(i);
    }
    return 0;
}


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

using namespace std;

#define _ ios_base::sync_with_stdio(0);cin.tie(0);
#define endl '\n'
//#define end endl
//#define endl() end()
#define f first
#define s second
#define pb push_back
#define mp make_pair

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

const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3fll;

int main(){ _
	char end = '\n';

	string s, t;

	cin >> s >> t;
	int i, n=s.size(), m=t.size();

	for (i=0; i<n && i<m; i++)
	{
		if (s[i]!=t[i])
			break;
	}

	if (i==n && n<m)
	{
		cout << "Yes\n";
	}
	else
	{
		cout << "No\n";	
	}

	exit(0);
}


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

using namespace std;

typedef long long ll;


int main (){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll A, B, C, D;
    cin >> A >> B >> C >> D;
    while(A > 0 && C > 0){
        C -= B;
        if(C <= 0){
            cout << "Yes" << endl;
            break;
        }
        A -= D;
        if(A <= 0){
            cout << "No" << endl;
            break;
        }
    }

    return 0;


}

Measured memory_bytes: 3652
#include<iostream>
#include<math.h>
using namespace std;
int main(){
	int n,m,s(0),x;
	cin>>n>>m>>x;
   int a[m] ;
	for(int i=1;i<=m;i++)
	cin>>a[i];
	for(int i=0;i<m;i++){
	if(a[i]<x&&a[i+1]>x){
		s=i;
	}
	}
		x=min(m-s,s);
	cout<<x<<endl;
	
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<cstdlib>
#include<tuple>
#include<iomanip>
#include<map>
#define int long long
using namespace std;

signed main() {
	int N,K;
	cin >> N >> K;
	vector<int> vec(N);
	for(int i = 0;i < N;i++) {
		cin >> vec.at(i);
	}
	int cnt;
	for(int i = 0;i < N;i++) {
		if(vec.at(i) == 1) {
			cnt = i;
		}
	}
	int answer = (N - 1 + K - 2) / (K - 1);
	cout << answer << endl;
}

Measured memory_bytes: 1024
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <queue>
#include <vector>
#include <map>
#include <set>
#include <stack>

using namespace std;

typedef long long LL;
typedef pair<int , int> P2;
typedef pair<pair<int , int> , int> P3;
typedef pair<pair<int , int> , pair<int , int> > P4;
#define Fst first
#define Snd second
#define PB(a) push_back(a)
#define MP(a , b) make_pair((a) , (b))
#define M3P(a , b , c) make_pair(make_pair((a) , (b)) , (c))
#define M4P(a , b , c , d) make_pair(make_pair((a) , (b)) , make_pair((c) , (d)))
#define repp(i,a,b) for(int i = (int)(a) ; i < (int)(b) ; ++i)
#define repm(i,a,b) for(int i = (int)(a) ; i > (int)(b) ; --i)

int N,M;
vector<int> V[100010];
stack<int> S;
queue<int> Q;
bool p[100010];

int main(){
	scanf("%d%d" , &N , &M);
	repp(i,0,M){
		int a,b;
		scanf("%d%d" , &a , &b);
		V[a].PB(b);
		V[b].PB(a);
	}
	int z = 1;
	while(V[z].size() == 0) ++z;
	int x = z;
	p[z] = 1;
	int ans = 1;
	while(1){
		bool b = 1;
		for(auto u : V[x]){
			if(p[u]) continue;
			S.push(u);
			p[u] = 1;
			x = u;
			b = 0;
			++ans;
			break;
		}
		if(b) break;
	}
	x = z;
	while(1){
		bool b = 1;
		for(auto u : V[x]){
			if(p[u]) continue;
			Q.push(u);
			p[u] = 1;
			x = u;
			b = 0;
			++ans;
			break;
		}
		if(b) break;
	}
	printf("%d\n" , ans);
	while(!S.empty()){
		printf("%d " , S.top());
		S.pop();
	}
	printf("%d" , z);
	while(!Q.empty()){
		printf(" %d" , Q.front());
		Q.pop();
	}
	printf("\n");
	return 0;
}


Measured memory_bytes: 6784
#include<bits/stdc++.h>
using namespace std;
int main(){
int64_t A,B,N;
  cin>>A>>B>>N;
  if(B-1<=N)
    cout<<(A*(B-1))/B<<endl;
  else
    cout<<(A*N)/B<<endl;
   return 0;
}

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

using namespace std;

#define all(x) begin(x), end(x)

using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using vi = vector<int>;

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

    int n;
    cin >> n;
    int ans = 0;
    multiset<int> ms;

    for (int i = 0; i < n; ++i) {
        int x;
        cin >> x;
        auto it = ms.lower_bound(x);
        if (it == begin(ms)) {
            ++ans;
            ms.insert(x);
        } else {
            it = prev(it);
            ms.erase(it);
            ms.insert(x);
        }
    }

    cout << ans << '\n';
    
    return 0;
}


Measured memory_bytes: 4992
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<(n); ++i)
#define repr(i, a, b) for (int i=a; i<(b); ++i)
#define reprev(i, n) for (int i=n-1; i>=0; --i)
#define reprrev(i, a, b) for (int i=b-1; i>=(a); --i)
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
    cout << fixed << setprecision(10);
    
    int N; cin >> N;
    ll ans = 0;
    repr(i, 1, N+1) {
        if (i % 5 != 0 && i % 3 != 0) {
            ans += i;
        }
    }
    cout << ans << endl;
    return 0;
}

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

const int MAX=55;

char C[MAX][MAX];
int state[MAX][MAX];
queue<pair<int,int>> Q;

void BFS(int H,int W){
    Q.push(make_pair(0,0));
    state[0][0]=1;
    while(Q.size()){
        int a=Q.front().first;
        int b=Q.front().second;
        if(a!=H-1&&state[a+1][b]==0&&C[a+1][b]=='.'){
            Q.push(make_pair(a+1,b));
            state[a+1][b]=state[a][b]+1;
        }
        if(b!=W-1&&state[a][b+1]==0&&C[a][b+1]=='.'){
            Q.push(make_pair(a,b+1));
            state[a][b+1]=state[a][b]+1;
        }
        if(a!=0&&state[a-1][b]==0&&C[a-1][b]=='.'){
            Q.push(make_pair(a-1,b));
            state[a-1][b]=state[a][b]+1;
        }
        if(b!=0&&state[a][b-1]==0&&C[a][b-1]=='.'){
            Q.push(make_pair(a,b-1));
            state[a][b-1]=state[a][b]+1;
        }
        Q.pop();
    }
}

int main(){
    
    int H,W,cnt=0;cin>>H>>W;
    for(int i=0;i<H;i++){
        for(int j=0;j<W;j++){
            cin>>C[i][j];
            if(C[i][j]=='.') cnt++;
        }
    }
    BFS(H,W);
    if(state[H-1][W-1]==0) cout<<-1<<endl;
    else cout<<cnt-state[H-1][W-1]<<endl;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define all(x) (x).begin(),(x).end()

using namespace std;
using ll = long long;


int main(){
    int p, q, r;
    cin >> p >> q >> r;

    int ans = 100000000;
    ans = min(ans, p + q);
    ans = min(ans, q + r);
    ans = min(ans, r + p);
    cout << ans << endl;
}

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

int linearSearch(int a[],int N,int key){
    int i;
    a[N] = key;
    for(i=0;i<N+1;i++){
        if(a[i]==key)break;
    }
    return i == N ? -1:i;
}

int main(void){
    int i,ns,nt;
    int *S,*T;
    /*?????????????????????*/
    scanf("%d",&ns);
    S = malloc(sizeof(int)*(ns+1));//??????????????????1?????????????¢????
    for(i=0;i<ns;i++)
        scanf("%d",&S[i]);
    scanf("%d",&nt);
    T = malloc(sizeof(int)*nt);
    for(i=0;i<nt;i++)
        scanf("%d",&T[i]);
    /*?????????????????????*/
    
    
    int count = 0;
    for(i=0;i<nt;i++){
        if(linearSearch(S,ns,T[i])!=-1)count++;
    }
    printf("%d\n",count);
    
    return 0;
}

Measured memory_bytes: 1816
n, m = map(int, input().split())
menu = {}

for i in range(n):
  a = list(map(int, input().split()))
  for j in range(1, len(a)):
    if a[j] in menu:
      menu[a[j]] += 1
    else:
      menu[a[j]] = 1

count = 0
for i in menu:
  if menu[i] == n:
    count+=1
print(count)

Measured memory_bytes: 3064
#include<cstdio>
#include<cstdlib>
#include<string>
#include<iostream>
using namespace std;

struct Node {
	int key;
	Node *right, *left, *parent;
};

Node *root, *NIL;

void insert(int k) {
	Node *y = NIL;
	Node *x = root;
	Node *z;
	
	z = (Node *)malloc(sizeof(Node));
	z->key = k;
	z->left = NIL;
	z->right = NIL;
	
	while ( x != NIL ) {
		y = x;
		if ( z->key < x->key ) {
			x = x->left;
		} else {
			x = x->right;
		}
	}
	
	z->parent = y;
	if ( y == NIL ){
		root = z;
	} else {
		if ( z->key < y->key ) {
			y->left = z;
		} else {
			y->right = z;
		}
	}
}

void inorder(Node *u) {
	if ( u == NIL ) return;
	inorder(u->left);
	printf(" %d", u->key);
	inorder(u->right);
}
void preorder(Node *u) {
	if ( u == NIL ) return;
	printf(" %d", u->key);
	preorder(u->left);
	preorder(u->right);
}

int main() {
	int n, i, x;
	string com;
	
	scanf("%d", &n);
	
	for ( i = 0; i < n; i++ ) {
		cin >> com;
		if ( com == "insert" ) {
			scanf("%d", &x);
			insert(x);
		} else if ( com == "print" ) {
			inorder(root);
			printf("\n");
			preorder(root);
			printf("\n");
		}
	}
	
	return 0;
}



Measured memory_bytes: 26732
N = int(input())

MOD = 10 ** 9 + 7

# dp[n][i][j][k]: str[n:n+3]で(i,j,k)となる個数
dp = [[[[0] * 4 for _ in range(4)] for _ in range(4)] for _ in range(N - 2)]

# 初期条件
for i in range(4):
    for j in range(4):
        for k in range(4):
            if i == 0 and j == 1 and k == 2: # ACG
                continue
            if i == 0 and j == 2 and k == 1: # AGC
                continue
            if i == 2 and j == 0 and k == 1: # GAC
                continue
            dp[0][i][j][k] = 1

# 配るDP
for n in range(N - 3):
    for i in range(4):
        for j in range(4):
            for k in range(4):

                # c: 次の文字
                for c in range(4):
                    if j == 0 and k == 1 and c == 2: # ?ACG
                        continue
                    if j == 0 and k == 2 and c == 1: # ?AGC
                        continue
                    if j == 2 and k == 0 and c == 1: # ?GAC
                        continue
                    if i == 0 and k == 2 and c == 1: # A?GC
                        continue
                    if i == 0 and j == 2 and c == 1: # AG?C
                        continue

                    dp[n+1][j][k][c] = (dp[n+1][j][k][c] + dp[n][i][j][k]) % MOD

ans = 0
for i in range(4):
    for j in range(4):
        for k in range(4):
            ans = (ans + dp[-1][i][j][k]) % MOD

print(ans)

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

import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7

N = INT()
S = input()

dp = list2d(N+1, 4, 0)
dp[0][0] = 1
msk = (1<<1000) - 1
for i in range(N):
    a = int(S[i])
    for j in range(4):
        dp[i+1][j] |= dp[i][j]
        if j == 0:
            dp[i+1][j+1] |= dp[i][j]<<a*100
            dp[i+1][j+1] &= msk
        if j == 1:
            dp[i+1][j+1] |= dp[i][j]<<a*10
            dp[i+1][j+1] &= msk
        if j == 2:
            dp[i+1][j+1] |= dp[i][j]<<a
            dp[i+1][j+1] &= msk
ans = 0
S = dp[N][3]
for k in range(1000):
    if S & 1<<k:
        ans += 1
print(ans)


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

int main() {
  vector<char>P(4);
  for(int i=0;i<4;i++){
    cin >> P.at(i);
  }
  sort(P.begin(),P.end());
  if((P.at(0)=='1')&&(P.at(1)=='4')
     &&(P.at(2)=='7')&&(P.at(3)=='9')){
     cout << "YES" << endl;
  }else{
    cout << "NO" << endl;
  }
  
}

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

int main()
{
    int n,x;
    int cnt=0,cnt2=0,cnt4=0;
    cin>>n;
    for(int i=0;i<n;++i)
    {
        cin>>x;
        if(x%4==0)
            cnt4++;
        else if(x%2==0)
            cnt2++;
    }
    cnt=n-cnt2-cnt4;
//    cout<<cnt<<" "<<cnt2<<" "<<cnt4<<endl;
    if(cnt2)
    {
        if(cnt4>=cnt)
            cout<<"Yes"<<endl;
        else
            cout<<"No"<<endl;
    }
    else if(cnt4&&cnt4+1>=cnt)
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;
    return 0;
}


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

int main() {
  string s;
  cin >> s;
  size_t res = 0;
  for (size_t i = 0; i < s.size() - 1; ++i) {
    if (s[i] != s[i + 1]) res++;
  }
  cout << res << endl;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
//#include <iostream>
using namespace std;
 
int main() {
    int H, W;
    cin >> H >> W;

    // input
    string str((H+2)*(W+2), '#');
    for(int n1=1; n1<=H; n1++){
        for(int n2=1; n2<=W; n2++){
            cin >> str.at(n1*(W+2)+n2);
        }
    }
    // output
    for(int n1=0; n1<H+2; n1++){
        for(int n2=0; n2<W+2; n2++){
            cout << str.at(n1*(W+2)+n2);
        }
        cout << endl;
    }
    return 0;
}

Measured memory_bytes: 3604