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

int main()
{
    string s;
    int ans = 0;
    cin >> s;
    if (s[0] == '+')
    {
        ans++;
    }
    else
    {
        ans--;
    }
    if (s[1] == '+')
    {
        ans++;
    }
    else
    {
        ans--;
    }
    if (s[2] == '+')
    {
        ans++;
    }
    else
    {
        ans--;
    }
    if (s[3] == '+')
    {
        ans++;
    }
    else
    {
        ans--;
    }
    cout << ans;
}

Measured memory_bytes: 384
#include <iostream>
#include<algorithm>
#include<stack>
#include<vector>
#include <cmath>
using namespace std;
const long long N = 105;
long long M = 1000000007;

int main() {
	int a, b, c;
	cin >> a >> b >> c;
	if (a == 7 || b == 7 || c == 7) {
		if (a == 5 && b == 5 || a == 5 && c == 5 || b == 5 && c == 5) {
			cout << "YES";
		}
		else cout << "NO";
	}
	else cout << "NO";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> pi;
typedef pair<ll, ll> pll;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;

#define imx INT_MAX
#define imn INT_MIN
#define llmx LLONG_MAX
#define llmn LLONG_MIN
#define INF         100000000000000000
#define PI          3.1415926535897932384626433832795l



#define fi first
#define se second
#define pb push_back
#define f_s(a) sort(a.begin(), a.end())
#define b_s(a) sort(a.rbegin(), a.rend())
#define p(a) cout<<a<<"\n"


// ll mod = 1000000007;
// #define l(i, )
// #define rl(i, a, b) for(int i = a; i < b; i++)






// struct mycomp {
//     bool operator() (const pair<int,int> &a, const pair<int,int> &b) const{
//         if (a.second-a.first != b.second-b.first)
//         return (a.second-a.first > b.second-b.first);
//         return a.first < b.first;
//     }
// };



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


ll extended_gcd(ll a, ll b, ll& x, ll& y)
{
	if(b==0)
	{
		x=1;
		y=0;
		return a;
	}
	ll x1, y1;
	ll d = extended_gcd(b, a%b, x1, y1);
	x=y1;
	y=x1-y1*(a/b);
	return d;
}

////////////////////SIEVE OF ERATOSTHENES//////////////////////
vector<int> sieveoferatosthenes(int n)
{
	vector<bool> prime(n+1, true);
	for(int i = 2; i <= sqrt(n); i++)
	{
		if(prime[i])
		{
			for(int j = i*i; j<=n; j+=i)
			{
				prime[j]=false;
			}
		}
	}	
	vector<int> all_primes;
	for(int i = 2; i <=n; i++)
	{
		if(prime[i]) all_primes.pb(i);
	}
	return all_primes;
}

////////////////////BINARY EXPONENTIATION///////////////////////
ll bin_exp(ll a, ll b, ll mod)
{
	ll ans = 1;
	while(b)
	{
		if(b%2)
		{
			b--;
			ans = (ans%mod*a%mod)%mod;
		}
		b/=2;
		a = (a%mod*a%mod)%mod;
	}
	return ans;
}


///////////////////////////BFS//////////////////////////////////
void bfs(vector<int>& distance, vector<int> a[], vector<bool>& visited, int u, vector<int>& parent)
{
	visited[u]=true;
	parent[u]=-1;
	distance[u]=0;
	queue<int> q;

	q.push(u); 
    while (!q.empty()) { 
  
        int f = q.front(); 
        q.pop(); 
  		for(int i =0; i < a[f].size(); i++)
  		{
  			if(visited[a[f][i]]==false)
  			{
  				distance[a[f][i]]=distance[f]+1;
  				parent[a[f][i]]=f;
  				visited[a[f][i]]=true;
  				q.push(a[f][i]);
  			}
  		}
    } 

}

void solve()
{

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

	// #ifndef ONLINE_JUDGE
	// freopen("input.txt", "r", stdin);
	// freopen("output.txt", "w", stdout);
	// #endif
	ll n;
	cin>>n;
	ll x = 0;
	vll a(n);
	for(int i = 0; i < n; i++)
	{
		cin>>a[i];
		x = a[i]^x;
	}
	for(int i = 0; i < n; i++)
	{
		cout<<(a[i]^x)<<" ";
	}
	cout<<endl;
	
	return 0;
}

Measured memory_bytes: 4788
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
const int mx=1e3+3;
int dp[mx][mx],n,m,mod=1e9+7;
//char c[mx][mx];
string c[mx];
ll solve (int i,int j)
{
if(i==n||j==m||c[i][j]=='#')
    return 0;
if(i==n-1&&j==m-1)
    return 1;
if(dp[i][j]!=-1)
   return dp[i][j];

 return dp[i][j]=(solve(i+1,j)%mod+solve(i,j+1)%mod)%mod;

}


int main()
{
memset(dp,-1,sizeof dp);
cin>>n>>m;
int i,j;
for(i=0;i<n;i++)
    cin>>c[i];
//   for(j=0;j<m;j++)
//    scanf("%c",&c[i][j]);
cout<<solve(0,0)<<endl;

return 0;
}


Measured memory_bytes: 5376
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>

using namespace std;

const int MAXN = 50000;

long long p[MAXN], a[MAXN], b[MAXN];

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

    for (int i = 0; i < n; i++) {
        a[p[i] - 1] = (p[i] - 1) * MAXN + i + 1;
        b[p[i] - 1] = (n - p[i]) * MAXN + i + 1;
    }

    for (int i = 0; i < n; i++)
        cout << a[i] << " ";
    cout << endl;
    for (int i = 0; i < n; i++)
        cout << b[i] << " ";

    return 0;
}

Measured memory_bytes: 1152
# https://atcoder.jp/contests/keyence2019/tasks/keyence2019_c

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

# check already can pass
need_prepare = 0
need_change = 0
prepare_margin = 0
for a, b in zip(A, B):
    if a < b:
        need_prepare += b - a
        need_change += 1
    else:
        prepare_margin += a - b

if need_prepare == 0:
    print(0)
    exit(0)

# check impossibility
if prepare_margin < need_prepare:
    print(-1)
    exit(0)

# find
margins = []
for i in range(len(A)):
    margins.append((A[i] - B[i], i))

# print(margins)
margins = sorted(margins, reverse=True)
# print(margins)
# print(need_prepare)

for i in range(len(margins)):
    need_prepare -= margins[i][0]
    need_change += 1
    if need_prepare <= 0:
        break

print(need_change)

Measured memory_bytes: 25780
// 21:57 - 22:02
#include<bits/stdc++.h>
using namespace std;

#define fi first
#define se second
#define lch (o << 1)
#define rch (o << 1 | 1)

typedef double db;
typedef long long ll;
typedef unsigned int ui;
typedef pair<int,int> pint;

const int N = 50 + 5;
const int INF = 0x3f3f3f3f;
const ll INF_LL = 0x3f3f3f3f3f3f3f3f;

ll s[N];

int main(){
	ios::sync_with_stdio(0);

	int n; cin >> n;
	for(int i=1; i<=n; i++)
		cin >> s[i];
	
	ll ans = 0;
	bool f = 1;
	while(f){
		f = 0;
		for(int i=1; i<=n; i++){
			if(s[i] >= n){
				f = 1;
				ll d = (s[i] - (n - 1) + n - 1) / n;
				s[i] -= d * n;
				for(int j=1; j<=n; j++)
					if(i != j) s[j] += d;
				ans += d;
			}
		}
		if(!f) break;
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(ll i = 0; i < (n); ++i)
#define repA(i, a, n) for(int  i = a; i <= (n); ++i)
#define all(x) x.begin(), x.end()
#define sz(x) (int) (x).size()
#define fill(a) memset(a, 0, sizeof(a))
#define fst first
#define snd second
#define mp make_pair
#define pb push_back
#define endl '\n'
#define init(n) int n;cin>>n;int a[n];rep(i,n)cin>>a[i];
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<long long int> vll;
typedef vector<pii> vii;
ll p=1000000007;
const int N=100005;
ll n,k;
vector<vector<ll> > mul(vector<vector<ll> > &a,vector<vector<ll> > &b){
    vector<vector<ll> > res(n,vector<ll> (n,0));
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            for(int k=0;k<n;k++){
                res[i][j]+=((a[i][k])*(b[k][j]))%p;
                res[i][j]%=p;
            }
        }
    }
    return res;
}
int main() {
    // #ifndef ONLINE_JUDGE
    // freopen("input.txt", "r", stdin);   
    // freopen("output.txt", "w", stdout);
    // #endif
    cin.sync_with_stdio(0); cin.tie(0);
    cin.exceptions(cin.failbit);
    cin>>n>>k;
    vector<vector<ll> > a(n,vector<ll> (n));
    rep(i,n)rep(j,n)cin>>a[i][j];
    vector<vector<ll> > res(n,vector<ll> (n,0));
    rep(i,n)res[i][i]=1;
    while(k>0){
        if(k&1){
            res=mul(res,a);
        }
        k=k/2;
        a=mul(a,a);
    }
    ll ans=0;
    rep(i,n){
        rep(j,n){
            ans+=res[i][j];
            // cout<<res[i][j]<<endl;
            ans%=p;
        }
    }
    cout<<ans;
    return 0;
}

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

#define maxn 301
#define inf 1e18
typedef long long ll;

ll n, m, l, d[maxn][maxn];
void floyd(){
  for(int k = 1; k <= n; k++){
    for(int i = 1; i <= n; i++){
      for(int j = 1; j <= n; j++){
        d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
      }
    }
  }
}

int main(){
  
  cin.sync_with_stdio(0), cin.tie(0);
  //~ freopen("in", "r", stdin);
  
  cin>>n>>m>>l;
  for(int i = 0; i <= n; i++){
    for(int j = 0; j <= n; j++)
      d[i][j] = inf;
    d[i][i] = 0;
  }
      
  while(m--){
    int u, v, c;
    cin>>u>>v>>c;
    d[u][v] = d[v][u] = c;  
  }
  
  floyd();
  for(int i = 1; i <= n; i++){
    for(int j = 1; j <= n; j++){
      if(d[i][j] > l) d[i][j] = inf;
      else d[i][j] = 1;   
    }
    d[i][i] = 0;
  }
  floyd();
  
  int q;
  cin>>q;
  
  while(q--){
    int u, v;
    cin>>u>>v;
    if(d[u][v] > n) cout<<-1<<endl;
    else cout<<d[u][v]-1<<endl;
  }
}


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

#define int long long
#define SEGVAL (262144)

typedef pair < int , int > Pi;

struct Data {
  int l, c, r, val;
};

struct Segtree {
  
  Pi data[800005];

  Segtree() {
    fill_n(data, 800005, Pi(8101919, 364364));
  }

  void add(int k, Pi x) {
    int now = k + SEGVAL - 1;
    data[now] = x;
    while(now != 0) {
      now = (now - 1) / 2;
      data[now] = min(data[now * 2 + 1], data[now * 2 + 2]);
    }
  }

  Pi query(int a, int b, int k, int l, int r) {
    if(b < l || r < a) return (Pi(8101919, 364364));
    if(l <= a && b <= r) return (data[k]);
    return (min(query(a, (a + b) / 2, k * 2 + 1, l, r), query((a + b) / 2 + 1, b, k * 2 + 2, l, r)));
  }
}; 

int a[200005];
queue < Data > que;
Segtree tree;

main()
{
  int n, nn = SEGVAL;
  int ans = 0;

  
  cin >> n;
  
  for(int i = 0; i < n; i++) {
    cin >> a[i];
    tree.add(i, Pi(a[i], i));
    if(a[i] == 1) que.push( (Data) { 0, i, n - 1, 1 } );
  }
  
  
  while(!que.empty()) {
    Data d = que.front(); que.pop();
    int l = d.l, c = d.c, r = d.r, val = d.val;
    
    ans += (c - l + 1) * (r - c + 1) * val;

    if(c > l) {
      Pi data = tree.query(0, nn - 1, 0, l, c - 1);
      que.push( (Data) { l, data.second, c - 1, data.first } );
    }

    if(c < r) {
      Pi data = tree.query(0, nn - 1, 0, c + 1, r);
      que.push( (Data) { c + 1, data.second, r, data.first } );
    }
  }

  cout << ans << endl;

  return (0);
}


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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define CHMIN(a,b) a=min((a),(b))
#define CHMAX(a,b) a=max((a),(b))

// mod
const ll MOD = 1000000007ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

// floating
typedef double Real;
const Real EPS = 1e-11;
#define EQ0(x) (abs(x)<EPS)
#define EQ(a,b) (abs(a-b)<EPS)
typedef complex<Real> P;

int main(){
  int n,a,b;
  cin>>n>>a>>b;
  printf("%d %d\n",min(a,b),max(0,a+b-n));
  return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
typedef long long ll;
inline int Get() {
	char ch;
	int Num, Sign = 0;
	while ((ch = getchar()) < '0' || ch > '9')
		if (ch == '-') Sign ^= 1;
	Num = ch - '0';
	while ((ch = getchar()) >= '0' && ch <= '9')
		Num = (Num << 3) + (Num << 1) + ch - '0';
	return Sign ? -Num : Num;
}
const int N = 1e5 + 5;
int n, m, a[N];
ll sum[N], pre[N], suf[N], ans;
int main() {
	n = Get(), m = Get();
	for (int i = 1; i <= n; ++i) a[i] = Get();
	for (int i = 1; i <= n; ++i) sum[i] = sum[i - 1] + a[i];
	for (int i = 1; i <= n; ++i) pre[i] = pre[i - 1] + (a[i] > 0 ? a[i] : 0);
	for (int i = n; i >= 1; --i) suf[i] = suf[i + 1] + (a[i] > 0 ? a[i] : 0);
	
	ll res = 0;
	for (int i = 1; i + m - 1 <= n; ++i) 
		res = sum[i + m - 1] - sum[i - 1], ans = std :: max(ans, pre[i - 1] + suf[i + m] + (res > 0 ? res : 0));
	printf("%lld\n", ans);
}

Measured memory_bytes: 2944
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Main {

	public static void main(String args[]) {
		FastScanner cin = new FastScanner();
		PrintWriter cout = new PrintWriter(System.out);
		solve(cin, cout);
		cout.flush();
	}

	private static void solve(FastScanner cin, PrintWriter cout) {
		int n = cin.nextInt();
		int[] s = new int[n];
		for (int i = 0; i < n; i++)
			s[i] = cin.nextInt();

		// n = 1..100
		// s[i] = 1..100
		int[] sum = new int[100 * 100 + 1];
		int len = sum.length;
		sum[0] = 1;
		for (int j = 0; j < n; j++) {
			for (int i = len - 1; i >= 0; i--) {
				if (sum[i] != 1)
					continue;
				sum[i + s[j]] = 1;
			}
		}
		int ans = 0;
		for (int i = len - 1; i >= 0; i--)
			if (sum[i] == 1 && i % 10 != 0) {
				ans = i;
				break;
			}
		cout.println(ans);
	}

	/**
	 * How to read input in Java — tutorial <br />
	 * By Flatfoot<br />
	 * http://codeforces.com/blog/entry/7018
	 */
	static class FastScanner {
		private BufferedReader br;
		private StringTokenizer st;

		FastScanner() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		String next() {
			while (st == null || !st.hasMoreElements())
				try {
					st = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					throw new IllegalStateException(e);
				}
			return st.nextToken();
		}

		double nextDouble() {
			return Double.parseDouble(next());
		}

		int nextInt() {
			return Integer.parseInt(next());
		}

		String nextLine() {
			String str = "";
			try {
				str = br.readLine();
			} catch (IOException e) {
				throw new IllegalStateException(e);
			}
			return str;
		}

		long nextLong() {
			return Long.parseLong(next());
		}
	}

}


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

int cnt[1000000];
int main() {
	int n; scanf("%d", &n);
	rep(i, n) {
		int a, b; scanf("%d%d", &a, &b);
		cnt[a + b]++;
	}
	rep(i, 1000000 - 1) {
		cnt[i + 1] += cnt[i] / 2;
		if (cnt[i] & 1)printf("%d 0\n", i);
	}
}

Measured memory_bytes: 7140
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
using ll = long long;

struct BIT {
    BIT(int n) : b(n + 1), n(n) {}
    void add(int i, int v) {
        for (int k = i + 1; k <= n; k += k & -k) b[k] += v;
    }
    int sum(int k) {
        int s = 0;
        for (; k > 0; k -= k & -k) s += b[k];
        return s;
    }
    int lower_bound(int s) {
        if (s <= 0) return 0;
        int x = 0, w = 1;
        while (w << 1 <= n) w <<= 1;
        do {
            int k = x + w;
            if (k <= n && b[k] < s) {
                s -= b[k];
                x += w;
            }
        } while (w >>= 1);
        return x + 1;
    }
    vector<int> b;
    int n;
};

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

    int n;
    cin >> n;

    int m = 1 << n;

    vector<int> s(m);
    for (int i = 0; i < m; i++) {
        cin >> s[i];
    }
    sort(s.begin(), s.end());

    int k = -1, p = -1;
    for (int i = 0; i < m; i++) {
        if (s[i] != p) k++;
        p = s[i];
        s[i] = k;
    }
    k++;

    BIT bt(k);
    for (int i = 0; i < m - 1; i++) {
        bt.add(s[i], 1);
    }

    vector<int> c(m);
    c[0] = s.back();
    for (int l = 1; l < m; l <<= 1) {
        for (int i = 0; i < l; i++) {
            int s = bt.sum(c[i]);
            if (s == 0) {
                cout << "No" << endl;
                exit(0);
            }
            int j = bt.lower_bound(s) - 1;
            bt.add(j, -1);
            c[l + i] = j;
        }
    }

    cout << "Yes" << endl;

    return 0;
}

Measured memory_bytes: 3328
#include <iostream>
#include <string>
#include <sstream>
#include <iomanip> 
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <functional>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <bitset>

using namespace std;



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

	long long n, i, j, k, ans, s, ct;
	cin >> n;
	vector<long long> a(n);
	for (i = 0; i < n; i++) cin >> a[i];

	ct = 0; s = 0;
	for (i = 0; i < n; i++) {
		s += a[i];

		if (i % 2 == 0) {
			if (s < 1) {
				ct += abs(s - 1);
				s = 1;
			}
		}
		else {
			if (s > -1) {
				ct += abs(s + 1);
				s = -1;
			}
		}
	}
	ans = ct;

	ct = 0; s = 0;
	for (i = 0; i < n; i++) {
		s += a[i];

		if (i % 2 == 1) {
			if (s < 1) {
				ct += abs(s - 1);
				s = 1;
			}
		}
		else {
			if (s > -1) {
				ct += abs(s + 1);
				s = -1;
			}
		}
	}
	ans = min(ans, ct);
	cout << ans << "\n";



	return 0;
}


Measured memory_bytes: 1152
#include<bits/stdc++.h>
 
typedef long long int lli;
typedef unsigned long long int ulli;
typedef long double ldb;
 
#define pb push_back
#define popb pop_back
#define popf pop_front
#define pf push_front
#define si size()
#define mp make_pair 
#define mt make_tuple
#define F first
#define S second
#define lb lower_bound
#define ub upper_bound

#define ask(i,m,n) for(lli i=m;i<n;i++)
#define anket ios::sync_with_stdio(0), cin.tie(0),cout.tie(0)
 
#define endl "\n"
#define o0(a) cout<<a<<" "
#define o1(a) cout<<a<<"\n"
#define o2(a,b) cout<<a<<" "<<b<<"\n"
#define o3(a,b,c) cout<<a<<" "<<b<<" "<<c<<"\n"
#define o4(a,b,c,d) cout<<a<<" "<<b<<" "<<c<<" "<<d<<"\n"
using namespace std;

#define prime1 1000000007
#define prime2 998244353

lli modadd(lli n,lli m , lli mod){
    lli sum = ((n+m)%mod+mod)%mod;
    return sum;
}

lli modsub(lli n,lli m,lli mod){
    lli diff = ((n-m+mod)%mod+mod)%mod;
    return diff;
}

lli modpro(lli n,lli m, lli mod){
    lli pro = ((n*m)%mod+mod)%mod;
    return pro;
}

lli powmod(lli x,lli y,lli mod){
    x %= mod;
    y %= mod;
    lli res = 1;
    while (y > 0) {
        if (y & 1)
            res = modpro(res , x,mod);
        y = y >> 1;
        x = modpro(x , x,mod);
    }
    return res;
}

lli moddiv(lli n,lli m,lli mod){
    //return n/m mod (mod) or n*(m)^-1 mod (mod)
    lli a = powmod(m,mod-2,mod);
    //this is because of fermats thm i.e. a^-1 = a^p-2 mod(p) check
    //multiplying p on both sides
    lli res = modpro(a,n,mod);
    return res;
}

vector<lli> prefix_function(string s) {
    lli n = (lli)s.length();
    vector<lli> pi(n);
    for (lli i = 1; i < n; i++) {
        lli j = pi[i-1];
        while (j > 0 && s[i] != s[j])
            j = pi[j-1];
        if (s[i] == s[j])
            j++;
        pi[i] = j;
    }
    return pi;
}


int main() {
	anket;
	lli n;
	cin>>n;
	lli a[n];
	ask(j,0,n){
	    cin>>a[j];
	}
	lli b = n/2;
	lli c[n];
	lli d[n];
	if(n %2==0){
	    c[0] = a[0];
	    c[1] = a[1];
	    d[0] = 0;
	    d[1] = 1;
	    ask(i,2,n){
	        c[i] = a[i] + c[i-2];
	        i++;
	        c[i] = max(a[i]+c[i-3],a[i] + c[i-2]);
	    }
	    lli ans = max(c[n-1],c[n-2]);
	    o1(ans);
	    return 0;
	}
	else{
	    c[0] = a[0];
	    c[1] = a[1];
	    ask(i,2,n-1){
	        c[i] = a[i] + c[i-2];
	        i++;
	        c[i] = max(a[i]+c[i-3],a[i] + c[i-2]);
	    }
	    d[n-1] = a[n-1];
	    d[n-2] = a[n-2];
	    for(lli j=n-3;j>=1;j--){
	        d[j] = a[j] + d[j+2];
	        j--;
	        d[j] = max(a[j] + d[j+2] , a[j] + d[j+3]);
	    }
	    lli ans = max(c[n-2],c[n-3]);
	    ans = max(ans, d[1]);
	    ans = max(ans, d[2]);
	    for(lli i=0;i+3 < n;i++){
	        ans = max(ans, c[i]+d[i+3]);
	        if(i+4<n && i %2==0){
	            ans = max(ans , c[i] + d[i+4]);
	        };
	        
	    }
	    o1(ans);
	}
	return 0;
}




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

const int N = 8e3 + 5;
int s[3][N];
char a[N];
int n;

signed main() {
	cin >> n >> (a + 1);
	for (register int i = 1; i <= n; i++) {
		s[0][i] = s[0][i - 1];
		s[1][i] = s[1][i - 1];
		s[2][i] = s[2][i - 1];
		switch(a[i]) {
			case 'R':
				s[0][i]++; break;
			case 'G':
				s[1][i]++; break;
			case 'B':
				s[2][i]++; break;
		}
	}
	long long ans = 0;
	for (register int i = 1; i <= n; i++)
		for (register int j = i + 1; j <= n; j++) {
			if (a[i] == a[j]) continue;
			
			if (a[i] != 'R' && a[j] != 'R') {
				ans += s[0][n] - s[0][j];
				if (a[j + (j - i)] == 'R') ans--;
			}
			if (a[i] != 'G' && a[j] != 'G') {
				ans += s[1][n] - s[1][j];
				if (a[j + (j - i)] == 'G') ans--;
			}
			if (a[i] != 'B' && a[j] != 'B') {
				ans += s[2][n] - s[2][j];
				if (a[j + (j - i)] == 'B') ans--;
			}
		}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3660
import heapq as hq
n,m = map(int,input().split())
ab = []
for i in range(n):
    a,b = map(int,input().split())
    ab.append((a,-b))
ab.sort() #日が短い順に
ans = 0
idx = 0
q = []
for i in range(1,m+1):
    while idx<n and ab[idx][0] ==i:
        a,mb = ab[idx]
        hq.heappush(q,mb)
        idx+=1
    if q!=[]:
        ans += -1*hq.heappop(q)

print(ans)


Measured memory_bytes: 67928
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAXSIZE 100

char buf[MAXSIZE];
int bufsh[MAXSIZE];


int main(int argc, const char * argv[]) {
    int n;
    int sum=0;
    scanf("%d",&n);
    int i;
    int k;
    for(i=0;i<n;i++){
        scanf("%d",&k);
        bufsh[i]=k;
    }
    int a,b;
    for(a=0;a<n-1;a++){
        for(b=a+1;b<n;b++){
            sum+=bufsh[a]*bufsh[b];
        }
    }
    
    // insert code here...
    printf("%d",sum);
    return 0;
}


Measured memory_bytes: 128
n = int(input())

keta = len(str(n))

ans = 0

cnt = keta // 2
for i in range(cnt):
    ans += 9 * 10 ** (i*2)
    

if keta % 2 == 0:
    print(ans)
else:
    print(ans + n - 10 ** (keta-1) + 1)

Measured memory_bytes: 2940
items = {}
recipes = {}


def reset():
    items.clear()
    recipes.clear()


def algorithm():
    while True:
        reset()

        for _ in range(int(input())):
            item, price = input().split()
            items[item] = int(price)

        if len(items) == 0:
            break

        for _ in range(int(input())):
            recipe = input().split()
            recipes[recipe[0]] = recipe[2:]

        for _ in range(len(recipes)):
            for k, v in recipes.items():
                total = 0
                for i in range(len(v)):
                    total += items[v[i]]
                items[k] = items[k] if items[k] < total else total

        print(items[input()])


def main():
    algorithm()


if __name__ == '__main__':
    main()

Measured memory_bytes: 7748
## preprocessing
f = {0:1}
mod = 10**9 + 7
for i in range(1,3000):
    f[i] = i * f[i-1] % mod

def c(n, r):
    if n<r:
        return 1
    num = f[n]
    den = (f[r] * f[n-r]) % mod
    return (num * pow(den, mod-2, mod)) % mod

def solve(n):
    k = 1
    ans = 0
    while n - 2*k - 1 >= k-1:
        ans = (ans + c(n-2*k-1, k-1)) % mod
        k+=1

    return ans
    
    
s = int(input())

print(solve(s))


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

using namespace std;

int main(int argc, const char *argv[]) {
  int n, k;
  cin >> n >> k;
  vector<int> vd(k);
  for (int i = 0; i < k; ++i) {
    cin >> vd[i];
  }

  sort(vd.begin(), vd.end());

  auto check = [&](int m) {
    string s = to_string(m);
    bool ok = true;
    for (int i = 0; i < s.size(); i++) {
      int d = s[i] - '0';
      bool ex = binary_search(vd.begin(), vd.end(), d);
      if (ex) {
        ok = false;
        break;
      }
    }

    return ok;
  };

  int i = n, ans;
  while (true) {
    if (check(i)) {
      ans = i;
      break;
    }

    i++;
  }

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

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

typedef long long ll;
const ll INF = 1e9, MOD = 1e9 + 7;
const double EPS = 1e-9, PI = 3.141592653589793;
#define Cin(x) cin >> x
#define Cin2(x,y) cin >> x >> y
#define Cin3(x,y,z) cin >> x >> y >> z
#define Cin4(w,x,y,z) cin >> w >> x >> y >> z
#define Cout(x) cout << x << "\n"
#define Cout2(x,y) cout << x << y << "\n"
#define Cout3(x,y,z) cout << x << y << z << "\n"
#define Cout4(w,x,y,z) cout << w << x << y << z << "\n"
#define Kaigyou cout << "\n"
#define REP(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
#define REPR(i,a,b) for(ll i=b;i>=a;i--)
#define repr(i,n) REPR(i,0,n)
#define Size(n) (n).size()
#define All(v) (v).begin(), (v).end()

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

    string sa,sb,sc;
    Cin3(sa,sb,sc);
    ll size1,size2,size3,ini,flag=1;
    size1 = Size(sa);
    size2 = Size(sb);
    size3 = Size(sc);
    while(1){
        if(flag == 1){
            if(size1 > 0){
                ini = sa[0];
                sa.erase(sa.begin());
                size1--;
                if(ini=='a') flag = 1;
                if(ini=='b') flag = 2;
                if(ini=='c') flag = 3;
                
            }else{
                Cout('A');
                break;
            }
        }
        if(flag == 2){
            if(size2 > 0){
                ini = sb[0];
                sb.erase(sb.begin());
                size2--;
                if(ini=='a') flag = 1;
                if(ini=='b') flag = 2;
                if(ini=='c') flag = 3;
                
            }else{
                Cout('B');
                break;
            }
        }
        if(flag == 3){
            if(size3 > 0){
                ini = sc[0];
                sc.erase(sc.begin());
                size3--;
                if(ini=='a') flag = 1;
                if(ini=='b') flag = 2;
                if(ini=='c') flag = 3;
                
            }else{
                Cout('C');
                break;
            }
        }
    }
    return 0;
}

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

int main(void){
	int w, n, a, b;
	int i, j, tmp;
	int lot[31];
	char str[5];
	char *num_a, *num_b;
	
	scanf("%d %d", &w, &n);
	
	for (i = 0; i <w; i++) lot[i] = i+1;
	
	for (i = 0; i < n; i++){
		scanf("%s", str);
		
		num_a = strtok(str, ",");
		num_b = strtok(NULL, ",");
		
		a = atoi(num_a);
		b = atoi(num_b);
		
		tmp = lot[a-1];
		lot[a-1] = lot[b-1];
		lot[b-1] = tmp;
	}
	
	for (i = 0; i < w; i++) printf("%d\n", lot[i]);
		
	return 0;
}

Measured memory_bytes: 592
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <math.h>
#include <iomanip>
#include <bitset>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <utility>
#include <set>
#include <queue>
using namespace std;
typedef long long int ll;
typedef long double ld;
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;
typedef pair<ll,ll> pairs;
vector<pairs> p;
bool pairCompare(const pair<double,ll>& firstElof, const pair<double,ll>& secondElof){
    return firstElof.first < secondElof.first;
}
bool pairCompareSecond(const pair<double,ll>& firstElof, const pair<double,ll>& secondElof){
    return firstElof.second < secondElof.second;
}
#define MAX_N 100100
#define MOD 1000000007
bool x[MAX_N];
ll num[MAX_N];
ll fibl[MAX_N]={0};
// 四方向への移動ベクトル
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

ll fib(ll a){
    if (fibl[a]!=0)return fibl[a];
    if (a==0){
        return 0;
    }else if (a==1){
        return 1;
    }
    return fibl[a]=fib(a-1)+fib(a-2);
}
 
ll eratosthenes(ll n) {
    int p = 0;
    for (ll i=0; i<=n; ++i) x[i] = true;
    x[0] = x[1] = false;
    for(int i=2; i<=n; ++i) {
        if(x[i]) {
            p++;
            for(int j=2*i; j<=n; j+=i) x[j] = false;
        }
        
        num[i] = p;
    }
    return p;
}
 
ll gcd(ll a,ll b){
    if (a%b==0)return(b);
    else return(gcd(b,a%b));
}
 
ll keta(ll N){
    int tmp{};
    while( N > 0 ){
        tmp += ( N % 10 );
        N /= 10;
    }
    N = tmp;
    return N;
}


int main(){
    ll n,ans=0;
    string s;
    cin >> n >> s;
    vector<ll> r;
    vector<ll> g;
    vector<ll> b;
    for (ll i=0;i<n;i++){
        if (s[i]=='R'){
            r.push_back(i);
        }else if (s[i]=='G'){
            g.push_back(i);
        }else if (s[i]=='B'){
            b.push_back(i);
        }
    }
    for (ll i=0;i<r.size();i++){
        for (ll j=0;j<g.size();j++){
            if (r[i]<g[j]){
                if (g[j]+(g[j]-r[i])<n and s[g[j]+(g[j]-r[i])]=='B'){
                    ans--;
                }
                if (r[i]-(g[j]-r[i])>=0 and s[r[i]-(g[j]-r[i])]=='B'){
                    ans--;
                }
                if ((g[j]-r[i])%2==0 and s[r[i]+(g[j]-r[i])/2]=='B'){
                    ans--;
                }
                ans+=b.size();
            }else{
                if (r[i]+(r[i]-g[j])<n and s[r[i]+(r[i]-g[j])]=='B'){
                    ans--;
                }
                if (g[j]-(r[i]-g[j])>=0 and s[g[j]-(r[i]-g[j])]=='B'){
                    ans--;
                }
                if ((r[i]-g[j])%2==0 and s[g[j]+(r[i]-g[j])/2]=='B'){
                    ans--;
                }
                ans+=b.size();
            }
        }
    }
    cout << ans << endl;
    return 0;
}


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

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

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int N=2e5+5;
typedef pair<int,int>pii;
typedef long long ll;
ll a[N],f1[N],f2[N],ans=1ll<<60;
int n,i,b[N],c[N];
inline void work(ll*f){
	vector<pii>v;v={pii(1,N)};
	for(i=2;i<=n;++i)if(a[i-1]>=a[i]){
		int x=0;
		for(;a[i]<<(x+1)*2<=a[i-1];++x);
		f[i]=f[i-1];
		if(x)v.push_back(pii(i,x));
	}else{
		int x=0,y;
		for(;a[i-1]<<x*2<a[i];++x);
		f[i]=f[i-1];
		for(;x;){
			y=v.size()==1?x:min(v.back().second,x);
			f[i]+=(i-v.back().first)*y;
			x-=y;if(v.size()>1)v.back().second-=y;if(!v.back().second)v.pop_back();
		}
	}
}
int main(){
	scanf("%d",&n);
	if(n==1)return puts("0"),0;
	for(i=1;i<=n;++i)scanf("%lld",a+i);
	work(f1);reverse(a+1,a+n+1);work(f2);reverse(f2+1,f2+n+1);
	for(i=0;i<=n;++i)ans=min(ans,i+f1[i]*2+f2[i+1]*2);
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 4992
#include <iostream>
#include <bits/stdc++.h>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <deque>
using namespace std;

int main()
{
    int x,y;
    cin>>x>>y;

    if(((y-(2*x))%2)==0 && (y-(2*x))>=0)
    {
        if(((y-(2*x))/2)<=x)
        {
            cout<<"Yes";
        }
        else
        {
            cout<<"No";
        }
    }
    else
    {
        cout<<"No";
    }    
}



Measured memory_bytes: 3564
x,y = map(int,input().split())
li = list(map(int,input().split()))
from collections import deque
l = []
for i in range(len(li)):
    l.append((1+ li[i])/2)
from itertools import accumulate
a = list(accumulate(l))
M = a[y-1]
for i in range(len(a)-y):
    m = a[i+y] - a[i]
    if m > M:
        M = m
print(M)

Measured memory_bytes: 25060
#include <stdio.h>

#define PRIME_MAX (1<<15)

char prime[PRIME_MAX];

/* ?´???°??????????????? */
void make_prime(){
    int i,j;
    for(i=0;i<PRIME_MAX;i++)prime[i]=1;
    prime[0]=0;
    prime[1]=0;
    for(i=2;i<PRIME_MAX;i++){
        if(prime[i]){
            for(j=2*i;j<PRIME_MAX;j+=i){
                prime[j]=0;
            }
        }
    }
    
}

int main(){
    int i,n,cnt;

    make_prime();

    while(scanf("%d",&n)&&n){
        /* i??¨n-i????????????????´???°???????????????????????° */
        cnt=0;
        for(i=2;i<=n/2;i++){
            if(prime[i]&&prime[n-i])cnt++;
        }
        printf("%d\n",cnt);
    }

    return 0;
}

Measured memory_bytes: 632
#include <iostream>

int combinations_of_sum_of_4_integers(int n);

int main(int argc, char** argv) {
	int n;

	while(std::cin >> n) {
		std::cout << combinations_of_sum_of_4_integers(n) << std::endl;
	}
}

int combinations_of_sum_of_4_integers(int n) {
	int i, j, k, l, result;
	result = 0;
	if(n > 36) {
		return 0;
	}
	for(i = 0; i <= 9; i++) {
		for(j = 0; j <= 9; j++) {
			for(k = 0; k <= 9; k++) {
				for(l = 0; l <= 9; l++) {
					if (i + j + k + l == n) {
						result += 1; 
					}
				}
			}
		}
	}
	return result;
}


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

int main()
{
	int a[100000],i,j=0,k=0,l=0,b;
	cin >> b;
	for (i = 0; i < b; i++)
	{
		cin >> a[i];
	}
	for (i = 0; i < b; i++)
	{
		if (a[i] % 4 == 0)
		{
			j ++;
		}
		else if (a[i] % 2 == 0)
		{
			k=1;
		}
		else
		{
			l++;
		}
	}
	if (k+l-j<=1)
	{
		cout << "Yes\n";
	}
	else
	{
		cout << "No\n";
	}
	return 0;
}

Measured memory_bytes: 640
#include<iostream>
    //#include <bits/stdc++.h>
    #include<vector>
    #include<algorithm>
    #include<string>
    #include<math.h>
    #include<sstream>
    #include<set>
    #include<map>
    using namespace std;
    #define INF 10000000;
    #define rep(i,n)for(int i=0;(i)<(int)(n);i++)
    #define REP(i,a,b)for(int i=(int)(a);(i)<=(int)(b);i++)
    #define VEC(type, c, n) std::vector<type> c(n);for(auto& i:c)std::cin>>i;
    #define vec(type,n) vector<type>(n)
    #define vvec(m,n) vector<vector<int>> (int(m),vector<int>(n))

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

      
      REP(i,0,n){
        REP(j,0,n-i){
          int k = n-i-j;
          if(10000*i + 5000*j + 1000*k == y){
            cout << i <<" "<< j <<" "<< k;
            return 0;
        }
      }
      

    }
      string s = "-1";
      cout << s <<" "<< s <<" "<< s <<endl;
      
    }

    


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

#define fi first
#define se second
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb(s) push_back(s)
#define mp(a,b) make_pair(a,b)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define maxch(x,y) x=max(x,y)
#define minch(x,y) x=min(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt(x) bitset<32>(x).count()

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<P, int> PPI;
typedef pair<ll, ll> PL;
typedef pair<P, ll> PPL;

#define INF INT_MAX/3

#define MAX_N 1000

int n;
int x[33],y[33];
int q;

int main(){
	cin.sync_with_stdio(false);
	while(1){
		cin>>n;
		if(n==0)break;
		rep(i,n)cin>>x[i]>>y[i];
		cin>>q;
		int rx=10,ry=10;
		int res=0;
		rep(i,q){
			char dir; int dist;
			cin>>dir>>dist;
			int dx=0,dy=0;
			if(dir=='N'){
				dy=1;
			}else if(dir=='E'){
				dx=1;
			}else if(dir=='W'){
				dx=-1;
			}else{
				dy=-1;
			}
			while(dist--){
				rep(j,n){
					if(rx==x[j]&&ry==y[j]){
						res++;
						x[j]=y[j]=-1;
					}
				}
				rx+=dx; ry+=dy;
			}
			rep(j,n){
				if(rx==x[j]&&ry==y[j]){
					res++;
					x[j]=y[j]=-1;
				}
			}
		}
		if(res==n)cout<<"Yes"<<endl;
		else cout<<"No"<<endl;
	}
	return 0;
}

Measured memory_bytes: 3036
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<stack>
#include<queue>
#include<vector>
#include<cmath>
#include<utility>
#define ll long long int
#define ld long double
#define INF 1000000000
#define EPS 0.0000000001
#define rep(i,n) for(i=0;i<n;i++)
using namespace std;
typedef pair<int, int> P;

string str;

int main()
{
  int x,y,size;
  int paper[15][15]={};
  while(scanf("%d,%d,%d",&x,&y,&size)!=EOF){

    x+=2;
    y+=2;

    paper[y][x]++;
    paper[y+1][x]++;
    paper[y-1][x]++;
    paper[y][x-1]++;
    paper[y][x+1]++;

    if(size>1){

      paper[y-1][x-1]++;
      paper[y-1][x+1]++;
      paper[y+1][x-1]++;
      paper[y+1][x+1]++;

      if(size==3){

	paper[y][x-2]++;
	paper[y][x+2]++;
	paper[y-2][x]++;
	paper[y+2][x]++;

      }
    }
  }
  int white=0;
  int m=0;
  int i,j;

  for(i=2;i<12;i++)
    for(j=2;j<12;j++){
    if(paper[i][j]==0)white++;
    m=max(m,paper[i][j]);
  }
  cout<<white<<endl;
  cout<<m<<endl;
}

Measured memory_bytes: 1212
n = int(input())
c = 0

def dfs(s):
    if int(s) > n:
        return
    # print(s)
    if '3' in s and '5' in s and '7' in s:
        global c
        c += 1
    
    dfs(s+'3')
    dfs(s+'5')
    dfs(s+'7')

dfs('0')
print(c)


Measured memory_bytes: 2940
#include<stdio.h>
#define N 1000000
int node(int);
struct node{
  int prant;
  int left;
  int right;
};
struct node tree[N];
int child[N],depth[N];
int n;
int getd(int);
void print(int);
int main()
{
  int m,a,i,j;

  scanf("%d",&n);

  for(i=0; i<n; i++){
    tree[i].prant=-1;
    tree[i].left=-1;
    tree[i].right=-1;
  }

  for(i=0; i<n; i++){
    scanf("%d %d",&a,&m);
    for(j=0; j<m; j++){
      scanf("%d",&child[j]);
      
      tree[child[j]].prant=a;

      if(j==0) tree[a].left=child[0];
      else tree[child[j-1]].right=child[j];
    }
  }

  for(i=0; i<n; i++){
    depth[i]=getd(i);
  }

  for(i=0; i<n;i++) print(i);

  return 0;
}

int getd(int x)
{
  int d=0;
  while(tree[x].prant>=0){
    x=tree[x].prant;
    d++;
  }
  return d;
}

void print(int x)
{
  int i,cnt=0;

  printf("node %d: parent = %d, depth = %d, ",x,tree[x].prant,depth[x]);

  if(tree[x].prant==-1) printf("root, [");
  else if(tree[x].left==-1) printf("leaf, [");
  else printf("internal node, [");

  x=tree[x].left;
  while(x!=-1){
    if(cnt==0) printf("%d",x);
    else printf(", %d",x);

    x=tree[x].right;
    cnt++;
  }
  printf("]\n");
}

Measured memory_bytes: 9192
#include <bits/stdc++.h>
#define ALL(v) (v).begin(), (v).end()
#define pb push_back
#define REP(i,n) for(int i=0; i<(n); i++)
#define REP2(i,x,n) for(int i=x; i<(n); i++)
using namespace std;
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
template<class T>using numr=std::numeric_limits<T>;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const int INF = 1e9;
const int MOD = 1000000007;
const int MOD2 = 998244353;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll n, k;
    cin >> n >> k;
    ll ans = n%k;
    if(abs(ans-k) < ans) cout << abs(ans - k) << endl;
    else cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <array>
#include <set>
#include <cmath>
#include <string>
#include <sstream>
#include <queue> 
#include <list>
#include <stack>
#include <unordered_map>
#include <algorithm> 
#include <numeric>  
#include <functional>
#include <cassert>
#include <bitset>
#include <cctype>  
#include <iomanip> 
#include <limits>  
#include <regex>
// std::numeric_limits<int>::max(), min()
// std::setprecision(X)
// std::islower(), std::isupper(), std::tolower, std::toupper
// std::accumulate(m.begin(), m.end(), 0LL);
// std::sort(begin(),end()) // 0, 1, 2, 3 ,4 (default, less);
// std::priority_queue<int, vector<int>, less<int>> que; // 4, 3, 2, 1 (defualt, less) : 
// if ( std::regex_match(S, std::regex("(dream|dreamer|erase|eraser)*")) ) std::cout << "YES" << std::endl;

#define rep(i,n)  for(int i = 0; i < (int)(n);    i++)
#define sz(x)     ((int)(x).size())
#define all(x)    (x).begin(),(x).end()

using ll = long long;

ll gcd ( ll a, ll b ) { if ( b == 0 ) return a; else return gcd ( b, a%b ); }
ll lcm ( ll a, ll b ) { return a * b / gcd(a, b); }

int main (void) {
  std::cin.tie(0);  std::ios::sync_with_stdio(false);
  int N; std::cin >> N;
  std::vector<ll> A(N), S(N+1, 0);

  rep(i, N) {
    std::cin >> A[i];
    S[A[i]]++;
  }

  ll total = 0;
  for(int i=1; i<=N; i++) total += (S[i] * (S[i]-1))/2;

  rep(i,N) {
    ll ans = total - (S[A[i]] * (S[A[i]]-1))/2 + ((S[A[i]]-1) * (S[A[i]]-2))/2;
    std::cout << ans << std::endl;
  }


  return 0;
}


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

typedef long long ll;

double A, B, H, M;

int main() {
  cin >> A >> B >> H >> M;
  complex<double> a = polar(A, (H * 60. + M) / (12. * 60.) * 2. * M_PI),
                  b = polar(B, M / 60. * 2. * M_PI);
  cout << setprecision(12) << abs(a - b) << endl;
  return 0;
}


Measured memory_bytes: 4128
#include <vector>
#include <iostream>
#include <cmath>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <fstream>
#include <unistd.h>
#include <string>
#include <numeric>
#include <queue>
#include <deque>
#include <sstream>
#include <iomanip>
#include <set>
#include <stack>
#include <cassert>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vvl> vvvl;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<vvb> vvvb;
typedef vector<vvvb> vvvvb;
typedef vector<string> vs;
typedef vector<vector<string>> vvs;
typedef vector<char> vc;
typedef vector<vector<char>> vvc;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<vvd> vvvd;
typedef pair<int, int> P;
typedef pair<ll, ll> PL;
typedef vector<P> vp;
typedef vector<PL> vpl;
typedef vector<vector<P>> vvp;
typedef vector<vector<PL>> vvpl;
const int INF = 1001001001;
const ll LINF = 1e16;
const double pi = 3.1415926535897932;
const string endstr = "\n";
#define FOR(i, a, b) for(ll i = (a); i < b; i++)
#define REP(i, n) for(ll i = 0; i < n; i++)
#define FORMAP(it, m) for(auto it = m.begin(); it != m.end(); it++)
#define ff first
#define ss second
#define pb push_back

template <typename T>
T gcd(T a, T b) {
    return (a == 0) ? b : gcd(b%a, a);
}
template <typename T>
T lcm(T a, T b) {
    return a / gcd(a, b) * b;
}

bool p_comp_fs(const PL p1, const PL p2){ return p1.first < p2.first;};
bool p_comp_fg(const PL p1, const PL p2){ return p1.first > p2.first;};
bool p_comp_ss(const PL p1, const PL p2){ return p1.second < p2.second;};
bool p_comp_sg(const PL p1, const PL p2){ return p1.second > p2.second;};
template <typename T>
vector<T> uniquen(vector<T> vec){
    vec.erase(unique(vec.begin(), vec.end()), vec.end());
    return vec;
}


int main(){
    ll N, K; cin >> N >> K;
    vl a(N); REP(i, N) cin >> a[i];
    vl sum(N+1, 0); REP(i, N) sum[i+1] = sum[i] + a[i];
    vl sump(N+1, 0); REP(i, N) sump[i+1] = sump[i] + max(a[i], 0ll);
    
    ll ans = 0;
    REP(i, N-K+1){
        ll tmp = max(sum[i+K]-sum[i], 0ll);
        tmp += sump[i] + sump[N] - sump[i+K];
        ans = max(ans, tmp);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 2560
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define VSORT(v) sort(v.begin(), v.end())
#define VRSORT(v) sort(v.rbegin(), v.rend())
#define ll long long
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;
typedef vector<unsigned int>vec;
typedef vector<vec> mat;
typedef vector<vector<int>> Graph;

const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const int INF = 1000000000;
const ll LINF = 1000000000000000000;//1e18
const ll  MOD = 1000000007;
const double PI = acos(-1.0);
const double EPS = 1e-10;

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; }
template<class T> inline void add(T &a, T b){a = ((a+b) % MOD + MOD) % MOD;};


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string S;
    cin >> S;
    if(S[0] == 'S') cout << "Cloudy" << endl;
    else if(S[0] == 'C') cout << "Rainy" << endl;
    else cout << "Sunny" << endl;
}


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

int main(){
  char s[3];
  cin>>s;
  int ramen=700;
  for(int i=0;i<3;i++){
    if(s[i]=='o'){
	    ramen+=100;
		}
	}
  cout<<ramen<<endl;
  return 0;
  }
  

Measured memory_bytes: 256
#include <stdio.h>

int main(void){
	
	char line[105]; int n;
	scanf("%d %s", &n, line);
	
	int red = 0, blue = 0;
	for(int i=0; i<n; i++){
		if(line[i] == 'R') red++;
		else blue++;
	} 
	if(red>blue) printf("Yes");
	else printf("No");
	
	return 0;
}

Measured memory_bytes: 128
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians#, log2
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy, copy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
import numpy as np

N = INT()
A = LIST()
A = Counter(A)

ans = 1
for k in sorted(A, reverse=True):
	if A[k] >= 4:
		if ans == 1:
			ans = k**2
			break
		else:
			ans *= k
			break
	elif A[k] >= 2:
		if ans == 1:
			ans *= k
		else:
			ans *= k
			break
else:
	ans = 0
print(ans)

Measured memory_bytes: 28188