akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
///////////////////////////////////////////
const long long int INF = 1LL<<60;
const long long int Mod = 1000000007;
using ll = long long int; using ci = const int;
using vi = vector<int>;  using Vi = vector<long long int>;
using P = pair<int, int>;  using PLL = pair<ll, ll>;
using matrix = vector<vector<ll>>;
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define rp(i,N) for(ll i = 0; i < (ll)N; i++)
#define repi(i,a,b) for(ll i = ll(a); i < ll(b); ++i)
template<class T>bool chmax(T &former, const T &b) { if (former<b) { former=b; return true; } return false; }
template<class T>bool chmin(T &former, const T &b) { if (b<former) { former=b; return true; } return false; }
template<class T>T sqar(T x){ return x*x; }//sqrt(x)は平方根;
#define Sort(v) std::sort(v.begin(), v.end(), std::greater<decltype(v[0])>()) //降順でVをソート
#define p_queue(v) priority_queue<v, vector<v>, greater<v> >
template<class T> inline void princ(T x){cout<<x<<" ";}; 
template<class T> inline void print(T x){cout<<x<<"\n";};
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
///////////////////////////////////////////////////////////////////////////////////

void solve(){
    int n;
    cin >> n;
    Vi a(n);
    Vi evens;
    rp(i,n){
        cin >> a[i];
        if(i&1) evens.pb(a[i]);
    }
    
    sort(all(a));
    sort(all(evens));
    int ctr=0;
    for(ll i=1; i<n; i+=2){
        auto aite=lower_bound(all(evens),a[i]),
        bite=upper_bound(all(evens),a[i]);
        if(aite==bite) ctr++;
    }
    print(ctr);
   
    return;
}
int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    std::cout<<std::fixed<<std::setprecision(30);
    solve();
    return 0;
}

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

int main(void) {
    int N, K;
    cin >> N >> K;
    map<int, int> cnt;
    for (int i = 0; i < N; ++ i) {
        int a;
        cin >> a;
        ++ cnt[a];
    }
    vector<int> a;
    for (auto &p: cnt) a.push_back(p.second);
    sort(begin(a), end(a));

    int ans = 0;
    for (int i = 0; i < (int)a.size() - K; ++ i) {
        ans += a[i];
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 10748
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repr(i,n) for(int i = (int)(n); i >= 0; i--)
#define all(v) v.begin(),v.end()
typedef long long ll;

int main(){
    ll N;
    cin >> N;
    ll H;
    cin >> H;
    vector<ll> A(N);
    vector<ll> B(N);
    rep(i,N){
        cin >> A[i];
        cin >> B[i];
    }
    sort(all(A));
    sort(all(B));
    ll max_swing = A[N - 1];
    ll count = 0;
    rep(i,N){
        if (H <= 0 || B[N - i - 1] <= max_swing){
            break;
        }
        else{
            count++;
            H -= B[N - 1 - i];
        }
    }
    if (H <= 0) count += 0;
    else if (H % max_swing == 0) count += H / max_swing;
    else count += (H / max_swing + 1);
    cout << count << endl;
}


Measured memory_bytes: 4820
#include<bits/stdc++.h>
using namespace std;
using ll =long long;
#define REP(i,m,n) for(int i=(int)(m);i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define SORT(i) sort((i).begin(),(i).end())
constexpr int INF = 2000000000;
constexpr int mod = 1000000007;

int main() {
	int N; cin >> N;
	vector<ll>h(N);
	rep(i, N)cin >> h[i];
	vector<ll>dp(N, INF);
	dp[0] = 0;
	dp[1] = abs(h[0] - h[1]);
	REP(i, 2, N) {
		int a = dp[i - 1] + abs(h[i - 1] - h[i]);
		int b = dp[i - 2] + abs(h[i - 2] - h[i]);
		dp[i] = min(a, b);
	}
	cout << dp[N - 1] << "\n";

	return 0;
}

Measured memory_bytes: 1792
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vvl = vector<vl>;
const int INF = 1 << 28;
const ll MOD = 1000000007;
template <class T>
bool chmax(T &a, const T &b) {
    return (a < b) ? (a = b, 1) : 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    return (b < a) ? (a = b, 1) : 0;
}

template <typename T = int>
T gcd(T a, T b) {
    if (a < b)
        return gcd(b, a);
    T r;
    while ((r = a % b)) {
        a = b;
        b = r;
    }
    return b;
}
template <typename T = int>
T lcm(T m, T n) {
    if ((0 == m) || (0 == n))
        return 0;
    return ((m / gcd(m, n)) * n);
}

int main() {
    ll a, b, c, d;
    cin >> a >> b >> c >> d;
    ll ret = b - a + 1;

    ll cmax = b / c;
    // if (b % c != 0)
    //     cmax++;
    ll cmin = a / c;
    if (a % c != 0)
        cmin++;
    ll cs = cmax - cmin + 1;

    ll dmax = b / d;
    // if (b % d != 0)
    //     dmax++;
    ll dmin = a / d;
    if (a % d != 0)
        dmin++;
    ll ds = dmax - dmin + 1;

    ll cdlcm = lcm(c, d);
    ll cdmax = b / cdlcm;
    // if (b % d != 0)
    //     dmax++;
    ll cdmin = a / cdlcm;
    if (a % cdlcm != 0)
        cdmin++;
    ll cds = cdmax - cdmin + 1;

    ret -= cs;
    ret -= ds;
    ret += cds;
    cout << ret << "\n";
    return 0;
}

Measured memory_bytes: 256
N, M = map(int, input().split())
shina = list(map(int, input().split()))
shina.sort(reverse=True)
hantei = 0
sou = sum(shina)

for i in range(M):
  if shina[i] < sou / (4 * M):
    hantei += 1

if hantei == 0:
  print('Yes')
else:
  print('No')

Measured memory_bytes: 3060
#include <bits/stdc++.h>
typedef long long ll;
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
using namespace std;
ll mod = 1E9+7;

int main() {
    int N; cin >> N;
    int A[N][N];
    REP(i, N) REP(j, N) {
        cin >> A[i][j];
    }
    int N_2 = 1, p[N+1]; 
    p[0] = 1;
    REP(i, N) {
        N_2 *= 2;
        p[i+1] = N_2;
    }
    ll dp[N_2];
    REP(i, N_2) dp[i] = 0;
    dp[0] = 1;
    REP(i, N) REP(k, N_2){
        if (__builtin_popcount(k) != i+1){
            continue;
        }
        REP(j, N){
            if (A[i][j] == 0 || !(p[j] & k)){
                continue;
            }
            dp[k] += dp[k-p[j]];
            dp[k] %= mod;
        }
    }
    cout << dp[N_2-1] << endl;
}

Measured memory_bytes: 16640
#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<string>
#include<cmath>
#include<vector>
#include<stack>
#include<queue>
#include<time.h>
#include<tuple>
#include<set>
#include<map>
#include<cctype>
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define vint vector<int> 
#define vvint vector<vint>
#define ct(a) cout<<a<<endl
#define tget(a,b) get<a>(b)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const ll INF = 1e18;
const int MOD = 1e9 + 7;

int a,b;
int main(void) {
	cin >> a>>b;
	if (a == 1)a += 13;
	if (b == 1)b += 13;
	if (a > b)ct("Alice");
	else if (a == b)ct("Draw");
	else ct("Bob");
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
#define chmin(a, b) ((a)=min((a), (b)))
#define chmax(a, b) ((a)=max((a), (b)))
#define fs first
#define sc second
#define eb emplace_back
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;

const ll MOD=1e9+7;
const ll INF=1e18;
const double pi=acos(-1);
const double eps=1e-10;

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

int main(){
    int n; cin>>n;
    cout << (n - 2) * 180 << endl;
}

Measured memory_bytes: 764
#pragma region Macros
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i, n) for(int i=(n); i>=0; --i)
#define FOR(i, n, m) for(int i=(m), i##_len=(n); i<i##_len; ++i)
#define EACH(i, v) for(const auto& i : v)
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
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; }
template<class Value>using vec = vector< Value >;
using ll = long long;
using P = pair< long long, long long >;
#define fi first
#define se second
#define el endl
#pragma endregion


void Main();
void solve(long long N);

int main(){
    std::cin.tie(nullptr);
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}

void Main(){
    long long N;
    scanf("%lld",&N);
    solve(N);
}

void solve(long long N){
    switch (N%10)
    {
    case 2:
    case 4:
    case 5: 
    case 7:
    case 9:
        cout << "hon\n";break;
    case 3:
        cout << "bon\n";break;
    default:
        cout << "pon\n";break;
    }
}



Measured memory_bytes: 3768
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define F first
#define S second
#define PB push_back
#define REP(i,a,b) for (int i = a ; i <= b ; i++)
#define REPI(i,a,b) for (int i = a ; i >= b ; i--)
using namespace __gnu_pbds;
using namespace std;

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

const int OO = 1e9+7;
const int MOD = 1e9+7;
const int N = 1e5+7;

int n,m;
vector<int> G[N];
vector<int> children[N];
vector<int> pref[N];
vector<int> suff[N];
ll down[N];
ll up[N];

void dfsdown(int u,int p)
{
    down[u] = 1;

    for(auto v:G[u])
    {
        if (v == p) continue;
        dfsdown(v,u);
        down[u] = (down[u]*(down[v]+1))%m;
        children[u].PB(v);
    }
    int n = children[u].size();
    if (n > 0)
    {
        pref[u].PB(down[children[u][0]]+1);
        REP(i,1,n-1)
        {
            pref[u].PB((pref[u][i-1]*(down[children[u][i]]+1))%m);
        }
        suff[u].PB(down[children[u][n-1]]+1);
        REPI(i,n-2,0)
        {
            suff[u].PB((suff[u].back()*(down[children[u][i]]+1))%m);
        }
        reverse(suff[u].begin(),suff[u].end());
    }
}

void dfsup(int u,int p,int idx)
{
    if (p == -1) up[u] = 1;
    else
    {
        up[u] = up[p];
        if (idx > 0) up[u] = (up[u]*pref[p][idx-1])%m;
        //cout << u << ' ' << pref[p][idx-1] << endl;
        if (idx < suff[p].size()-1) up[u] = (up[u]*suff[p][idx+1])%m;
        up[u]++;
    }
    int i = -1;
    for(auto v:children[u])
    {
        i++;
        dfsup(v,u,i);
    }
}

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    //freopen("teleport.in","r",stdin);
    //freopen("teleport.out","w",stdout);

    cin >> n >> m;
    REP(i,1,n-1)
    {
        int x,y;
        cin >> x >> y;
        G[x].PB(y);
        G[y].PB(x);
    }

    dfsdown(1,-1);
    dfsup(1,-1,-1);

    REP(i,1,n)
    {
        cout << (down[i]*up[i])%m << endl;
        //cout << down[i] << ' ' << up[i] << endl;
    }

    return 0;
}


Measured memory_bytes: 30208
#include<bits/stdc++.h>
#define ALL(c) (c).begin(),(c).end()
#define EACH(i,c) for(auto i=(c).begin();i!=(c).end();++i)
#define REP(i,a,b) for(int i=a;i<(b);++i)
using namespace std;
typedef long long ll;

int main()
{
  ll n;
  cin >> n;
  ll p[20000];
  ll a[20000];
  ll b[20000];
  for(ll i=0;i<n;i++){
    ll tmp;
    cin >> tmp;
    p[i]=tmp-1;
    a[i]=i*n+1;
  }
  ll before=0;
  ll min  = 1000000000;
  for(ll i=0;i<n;i++){
    //   cout << before <<" "<<a[p[i]]<<endl;
    b[p[i]]=before - a[p[i]]+1;
    before = b[p[i]] + a[p[i]];
    if( min > b[p[i]])
          min = b[p[i]];
  }
  //  cout <<"ret"<<endl;
  cout <<a[0];
  for(ll i=1;i<n;i++){
    cout << " "<<a[i];
  }
  cout <<endl;
  cout <<b[0]-min+1;
  for(ll i=1;i<n;i++){
    cout << " "<<b[i]-min+1;
  }
  cout <<endl;
}


Measured memory_bytes: 1024
from math import gcd
from functools import reduce


def gcd_kai(*numbers):
    return reduce(gcd, numbers)


K = int(input())
ans = 1
if K == 1:
    next
else:
    ans += (K - 1) * K * 3
    ans_sub = 0
    for i in range(2, K):
        for j in range(i + 1, K + 1):
            for k in range(i, K + 1):
                ans_sub += gcd_kai(i, j, k)
    ans += ans_sub * 3
    for i in range(2, K + 1):
        ans += i
print(ans)


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

/**
 * Created by hwzheng on 2017/3/27.
 */
public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader Reader = new BufferedReader (new InputStreamReader(System.in));
        int N = Integer.parseInt(Reader.readLine());
        String A[] = Reader.readLine().split(" ",0);
        int[] arr = new int[N];
        for (int i=0; i < N; i++){
            arr[i] = Integer.parseInt(A[i]);
        }
        bubbleSort2(arr,N);
    }

    private static void bubbleSort(int[] arr, int n) {
        boolean flag = true;
        int exCount = 0;
        while (flag){
            flag = false;
            for (int i = n - 1; i > 0; i--){
                if (arr[i] < arr[i-1]){
                    exch(arr,i,i-1);
                    exCount++;
                    flag = true;
                }
            }
        }
        String str = "";
        for (int i = 0; i < arr.length; i++){
            str += arr[i] + " ";
        }
        System.out.println(str.substring(0,str.length()-1));
        System.out.println(exCount);
    }
    
    private static void bubbleSort2(int[] arr, int n){
        int exCount = 0;
        for (int i = 0; i < n; i++){
            for (int j = n-1; j>i; j--){
                if (arr[j] < arr[j-1]){
                    exch(arr,j,j-1);
                    exCount++;
                }
            }
        }
        String str = "";
        for (int i = 0; i < arr.length; i++){
            str += arr[i] + " ";
        }
        System.out.println(str.substring(0,str.length()-1));
        System.out.println(exCount);
    }

    private static void exch(int[] arr, int i, int j){
        int tmp = arr[i];
        arr[i] = arr[j];
        arr[j] = tmp;
    }
}

Measured memory_bytes: 24328
import java.io.BufferedReader;
import java.io.Closeable;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Main {
	
	public static void main(String[] args) throws IOException {
		try(final Scanner sc = new Scanner(System.in)){
			final int N = sc.nextInt();
			final int K = sc.nextInt() - 1;
			final String S = sc.next();
			
			System.out.println(S.substring(0, K) + Character.toLowerCase(S.charAt(K)) + S.substring(K + 1));
		}
	}

	public static class Scanner implements Closeable {
		private BufferedReader br;
		private StringTokenizer tok;

		public Scanner(InputStream is) throws IOException {
			br = new BufferedReader(new InputStreamReader(is));
		}

		private void getLine() throws IOException {
			while(!hasNext()){
				tok = new StringTokenizer(br.readLine());
			}
		}

		private boolean hasNext() {
			return tok != null && tok.hasMoreTokens();
		}

		public String next() throws IOException {
			getLine();
			return tok.nextToken();
		}

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

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

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

		public int[] nextIntArray(int n) throws IOException {
			final int[] ret = new int[n];
			for(int i = 0; i < n; i++){
				ret[i] = this.nextInt();
			}
			return ret;
		}

		public long[] nextLongArray(int n) throws IOException {
			final long[] ret = new long[n];
			for(int i = 0; i < n; i++){
				ret[i] = this.nextLong();
			}
			return ret;
		}

		public void close() throws IOException {
			br.close();
		}
	}
}

Measured memory_bytes: 20820
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;


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

  if((A*100 + B*10 + C)%4 == 0){
    cout << "YES" << endl;
  }else{
    cout << "NO" << endl;
  }
  
  return 0;
}



Measured memory_bytes: 256
#include<stdio.h>
#include<algorithm>
using namespace std;

const int MAX = 1400;

int main() {
	int H, W;
	int tile[MAX][MAX];
	int ans = 0;

	scanf("%d%d", &H, &W);
	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {
			scanf("%d", &tile[i][j]);
		}
	}

	for (int y = 0; y < H; y++) {
		for (int x = 0; x < W; x++) {
			if (tile[y][x] == 1) tile[y][x] = 0;
			else if (x < 1 || y < 1) tile[y][x] = 1;
			else tile[y][x] = min(tile[y - 1][x - 1], min(tile[y - 1][x], tile[y][x - 1])) + 1;
			ans = max(tile[y][x], ans);
		}
	}

	printf("%d\n", ans * ans);
	return 0;
}

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

int main() {
  int N;
  cin >> N;
  vector<ll> A(N);
  ll sum = 0;
  for (int i = 0; i < N; i++) {
    cin >> A[i];
    A[i] %= INF;
    sum += A[i];
    sum %= INF;
  }

  ll ans = 0;
  for (int i = N - 1; i > 0; i--) {
    sum -= A[i];
    sum %= INF;
    if (sum < 0) ans += INF;
    ll temp = sum * A[i];
    temp %= INF;
    ans += temp;
    ans %= INF;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 4840
#include<map>
#include<set>
#include<cmath>
#include<stack>
#include<queue>
#include<deque>
#include<ctime>
#include<vector>
#include<bitset>
#include<string>
#include<cstdio>
#include<numeric>
#include<utility>
#include<sstream>
#include<cstdlib>
#include<iomanip>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<functional>
#include<unordered_map>
#define _USE_MATH_DEFINES
#define inf 999999999999999999
#define rep(i,n,m) for(lli i=(lli)(n);i<(lli)(m);++i)
#define reep(i,n,m) for(int i=(int)(n);i<=(int)(m);++i)
#define per(i,m,n) for(lli i=(int)(m)-1;i>=(int)(n);--i)
#define st(n) sort(n.begin(), n.end())
#define rev(n) reverse(n.begin(),n.end())
#define ou(S) cout << S << endl
#define pb(n) push_back(n)
#define ue(N) N.erase(unique(N.begin(),N.end()),N.end());
#define nou(S) cout << S
#define hou(S) cout << setprecision(30) << S << endl
#define vec(K,L,N,S) vector<L> K(N,S)
#define dv(K,L,N,M,S) vector<vector<L>> K(N,vector<L>(M,S))
#define tv(K,L,N,M,R,S) vector<vector<vector<L>>> K(N,vector<vector<L>>(M,vector<L>(R,S)))
#define pint pair<lli,lli>
#define paf(L,R) pair<L,R>
#define maxx 5100000
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
#define endl "\n"
typedef long long int lli;
typedef unsigned long long int uli;
const uli mod = 1e9 + 7;
using namespace std;
int main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL);

    uli x,sum=0;
    cin >> x;
    sum = x / 500 * 1000;
    x %= 500;
    sum += x / 5 * 5;
    cout << sum << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vin=vector<int>;
using vll=vector<long long>;
using vvin=vector<vector<int>>;
using vvll=vector<vector<long long>>;
using vstr=vector<string>;
using vvstr=vector<vector<string>>;
using vch=vector<char>;
using vvch=vector<vector<char>>;
using vbo=vector<bool>;
using vvbo=vector<vector<bool>>;
using vpii=vector<pair<int,int>>;
using pqsin=priority_queue<int,vector<int>,greater<int>>;
#define mp make_pair
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep2(i,s,n) for(int i=(s);i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define decp(n) cout<<fixed<<setprecision((int)n)
const int inf=1e9+7;
const ll INF=1e18;

int main(){
    int d;cin>>d;
    vin c(26);rep(i,26)cin>>c[i];
    vvin s(d,vin(26));
    rep(i,d)rep(j,26)cin>>s[i][j];
    vin last(26,0);int sum,tmp;ll m;
    vin ans(d);
    rep(i,d){
        m=-INF;
        rep(j,26){
            sum=0;
            sum+=s[i][j];
            rep(k,26){
                if(k==j)continue;
                sum-=c[k]*(i+1-last[k]);
            }
            if((ll)sum>m)tmp=j;
        }
        ans[i]=tmp;
        last[tmp]=i+1;
    }
    rep(i,d)cout<<ans[i]<<endl;
}

Measured memory_bytes: 3684
from bisect import bisect_left,bisect,bisect_right
import sys

icase=0
if icase==0:
    n=int(input())
    a=list(map(int,input().split()))

a.sort()
ii=bisect(a,0)

if ii==n:
    if ii%2==0:
        asum=-sum(a)
    else:    
        asum=-sum(a[0:ii-1])+a[ii-1]
    print(asum)
    sys.exit()

if ii%2==0:
    asum=-sum(a[0:ii])+sum(a[ii:])
else:
    if -a[ii-1]<a[ii]:
        d=a[ii-1]+a[ii]
    else:
        d=-a[ii-1]-a[ii]
    asum=-sum(a[0:ii-1])+d+sum(a[ii+1:])

print(asum)


Measured memory_bytes: 20388
import sys
from fractions import gcd

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

A, B, C, D = lr()

def F(x):
    cnt_C = x // C
    cnt_D = x // D
    cnt_CD = x // (C*D//gcd(C, D))
    return x - cnt_C - cnt_D + cnt_CD

print(F(B) - F(A-1))


Measured memory_bytes: 5072
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <cstring>
#include <vector>
#include <map>
#include <utility>
#include <complex>
#include <stack>
#include <climits>
#include <set>

using namespace std;

double sq(double x){return x*x;}

int main(){
	int a,b,c;
	int s = 0,t = 0;
	while(~scanf("%d,%d,%d",&a,&b,&c)){
		if(a * a + b * b == c * c)
			s++;
		else if( a == b)
			t++;
	}

	printf("%d\n%d\n",s,t);


	return 0;
}

Measured memory_bytes: 0
#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
string s;
long long k;
bool flag;
int main()
{
    cin>>s;
    cin>>k;
    for(int i=0;i<k;i++)
        if(s[i]!='1')
        {
            cout<<s[i];
            return 0;
        }
    cout<<1;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <map>

using namespace std;

bool check(map<int, int> reportsMap, int noses) {
   int maxReport = noses - 1;
   if (noses % 2 == 0) {
      for (int i = 1; i <= maxReport; i+=2) {
         if (reportsMap[i] != 2) { return false; }
      }

   } else {
      if (reportsMap[0] != 1) { return false; }
      for (int i = 2; i <= maxReport; i+=2) {
         if (reportsMap[i] != 2) { return false; }
      }
   }
   return true;
}

int main() {

   int noses;
   cin >> noses;

   map<int, int> reportsMap;
   for (int i = 0; i < noses; i++) {
      int report;
      cin >> report;
      if (reportsMap.count(report)) {
         reportsMap[report] += 1;
      } else {
         reportsMap[report] = 1;
      }
   }

  long long answer = 1;
  for (int j = 0; j < (noses / 2); j++) {
     answer = answer * 2 % 1000000007;
  }

   if (check(reportsMap, noses) == false) {
      answer = 0;
   }

   cout << answer << endl;
}

Measured memory_bytes: 6144
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> PII;
typedef long long LL;
typedef unsigned long long ULL;
template<class T> inline bool amax (T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool amin (T &a, const T &b) { if (a > b) { a = b; return 1; } return 0; }
template<class T> ostream& operator << (ostream &os, const vector<T> &v) { os << "["; for (typename vector<T>::const_iterator it = v.begin(); it != v.end(); it++) { os << (it != v.begin() ? ", " : "") << *it; } os << "]"; return os; }
template<class T> ostream& operator << (ostream &os, const set<T> &s) { os << "["; for (typename set<T>::const_iterator it = s.begin(); it != s.end(); it++) { os << (it != s.begin() ? ", " : "") << *it; } os << "]"; return os; }
template<class Key, class Val> ostream& operator << (ostream &os, const map<Key, Val> &m) { os << "{"; for (typename map<Key, Val>::const_iterator it = m.begin(); it != m.end(); it++) { os << (it != m.begin() ? ", " : "") << it->first << ":" << it->second; } os << "}"; return os; }
template<class T, class S> ostream& operator << (ostream &os, const pair<T, S> &p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
template <class T> istream& operator >> (istream &is, vector<T> &v) { for (size_t i = 0; i < v.size(); i++) is >> v[i]; return is; }
template <class Target, class Source> inline Target lexical_cast (const Source &s) { Target t; stringstream ss; ss << s; ss >> t; return t; }

//> v < ^ (clock wise)
int dx[] = {1,0,-1,0};
int dy[] = {0,1,0,-1};
const int INFI = 1<<28;
const long long int INFL = 1LL<<60;
const double INFD = 1e+300;
const float INFF = 1e+100;
const double EPS = 1e-8;
const long long int MOD = 1000000007;

int solve ();
int main () {
    cout.setf(ios::fixed); cout.precision(10);
    ios_base::sync_with_stdio(false);
    solve();
    return 0;
}

int solve () {
    int n;
    cin >> n;
    int s, l, p;
    int score[1000];
    for (int i = 0; i < 1000; i++) score[i] = -INFI;
    score[0] = 0;
    for (int i = 0; i < n; i++) {
        cin >> s >> l >> p;
        for (int k = 0; k < 1000; k++) {
            for (int j = s; j <= l; j++) {
                if (k+j < 1000) score[k+j] = max(score[k+j], score[k]+p);
            }
        }
    }

    int m;
    cin >> m;
    vector<int> ans(m);
    bool ng = false;
    for (int i = 0; i < m; i++) {
        int w;
        cin >> w;
        ans[i] = score[w];
        ng |= score[w]<0;
    }
    if (ng) cout << -1 << endl;
    else {
        for (int i = 0; i < m; i++) cout << ans[i] << endl;
    }

    return 0;
}

Measured memory_bytes: 1200
a = int(input())
if a < 10:
    print(a)
elif a < 100:
    print(9)
elif a < 1000:
    d = a -99
    print(9 + d)
elif a < 10000:
    print(909)
elif a < 100000:
    d = a - 9999
    print(9+900+d)
elif a == 100000:
    print(90909)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;typedef long long ll;typedef string str;
typedef vector<str> vst;typedef vector<ll> vll;
ll mod = 1000000007, INF = 10000000000000000;
ll gcd(ll a, ll b){if(b==0){return a;}return gcd(b, a%b);}
// for (ll i = 0; i < n; i++) {
// sort(.begin(),.end());
int main(){
  str s;
  cin >> s;
  ll n = s.size();
  vll co(26);
  for (ll i = 0; i < n; i++) {
    ll x = s[i] - 'a';
    co[x]++;
  }
  
  str ans = "Yes";
  for (ll i = 0; i < 26; i++) {
    if (co[i] % 2 == 1) {
      ans = "No";
      break;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
s = raw_input()
count = {}
count['N'] = 0
count['W'] = 0
count['E'] = 0
count['S'] = 0
for c in s:
    count.setdefault(c,0)
    count[c] += 1

ok = True

if(count['N']==0 and count['S']!=0): ok = False
if(count['N']!=0 and count['S']==0): ok = False
if(count['W']==0 and count['E']!=0): ok = False
if(count['W']!=0 and count['E']==0): ok = False

if(ok): print('Yes')
else: print('No')

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

using namespace std;

#define intt long long
#define FAST ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

const int N = 100005;
const double PI = 3.14159265;

int n;
int a[N];

double angle (int x, int y, int z) {
	int vol = x * x * y;
	double ans = 0;
	if (z * 2 < vol) {
		double d = (x * y * y) / (2.0 * z);
		ans = atan(d);
	}
	else {
		z = vol - z;
		double d = (2 * z) / (double)(x * x * x);
		ans = atan(d);
	}
	ans = (ans * 180) / PI;
	return ans;
}

int main() {

	FAST;

	int x, y, z;
	cin >> x >> y >> z;
	cout << setprecision(9) << fixed << angle(x, y, z) << '\n';
	return 0;
}

Measured memory_bytes: 384
N=int(input())
A=list(map(int,input().split()))
B=[0 for i in range(N)]
if N%2==0:
    for i in range(N):
        B[N//2+(i//2+i%2)*((-1)**i)]=A[i]
else:
    for i in range(N):
        B[N//2+(i//2+i%2)*((-1)**(i+1))]=A[i]
for j in range(N):
    print(B[j], end=' ')
print()

Measured memory_bytes: 26020
line = [input() for i in range(2)]

status = [int(x) for x in line[0].split()]
fruits = [int(x) for x in line[1].split()]

status
fruits = sorted(fruits)

i = 1
total = 0
for fruit in fruits:
    i += 1
    total += int(fruit)
    if int(status[1]) < i:
        break
print(total)


Measured memory_bytes: 9264
import java.util.ArrayList;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String sd = sc.next();
		String t = sc.next();
		ArrayList<String> list = new ArrayList<String>();

		int i;
		for (i = 0; i < sd.length() - t.length() + 1; i++) {
			int j;
			for (j = 0; j < t.length(); j++) {
				if (sd.charAt(i + j) != '?' && sd.charAt(i + j) != t.charAt(j)) {
					break;
				}
			}
			if (j >= t.length()) {				
				list.add((sd.substring(0, i) + t + sd.substring(i + t.length())).replace('?', 'a'));
			}
		}
		list.sort(null);
		if (list.size() == 0) {
			System.out.println("UNRESTORABLE");
		} else {
			System.out.println(list.get(0));
		}
	}

}


Measured memory_bytes: 23892
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
ll n,ans;
void yan(ll x,ll t,ll f,ll s){
  if(x>n)return;
  if(t&&f&&s)ans++;
  yan(x*10+3,t+1,f,s);
  yan(x*10+5,t,f+1,s);
  yan(x*10+7,t,f,s+1);
}
int main(){
  cin>>n;
  yan(0,0,0,0);
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <math.h>
#include <string>
#include <vector>
#include <cstdlib>
#include <utility>
#include <map>
#include <set>
#include <ios>
#include <iomanip>
#include <functional>

using namespace std;

int main(){
    long long int x, y;
    cin >> x >> y;
    long long int cnt = 1;
    while(1){
        x *= 2;
        if(x > y){
            break;
        }else{
            cnt++;
        }
    }
    cout << cnt;
}


Measured memory_bytes: 256
import java.util.Scanner;
import java.util.Random;
import java.io.PrintWriter;

public class Main{
    public static Random rand = new Random();
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        PrintWriter out = new PrintWriter(System.out);
        long start = System.currentTimeMillis();
        int D = Integer.parseInt(sc.next());
        int[] C = new int[26];
        int[] L = new int[26];
        for (int i = 0; i < 26; i++){
            C[i] = Integer.parseInt(sc.next());
            L[i] = 0;
        }
        int[][] S = new int[D][26];
        for (int i = 0; i < D; i++){
            for (int j = 0; j < 26; j++){
                S[i][j] = Integer.parseInt(sc.next());
            }
        }
        int[] Ans = new int[D];
        for (int i = 0; i < D; i++){
            Ans[i] = (i % 26) + 1;
        }
        int maxPoint = calcPoint(Ans, S, C, L, D);
        

        while (System.currentTimeMillis() - start < 1850){
            maxPoint = change(Ans, S, C, L, D, maxPoint, 1500 - (System.currentTimeMillis() - start));
        }

        for (int i = 0; i < D; i++){
            out.print(Ans[i]);
            out.print("\n");
        }
        //template
        sc.close();
        out.flush();
    }

    public static int calcPoint(int[] Ans, int[][] S, int[] C, int[] L, int D){
        int point = 0;
        for (int i = 0; i < 26; i++){
            L[i] = 0;
        }
        for (int i = 0; i < D; i++){
            point += S[i][Ans[i] - 1];
            L[Ans[i] - 1] = i + 1;
            for (int j = 0; j < 26; j++){
                point -= C[j] * (i + 1 - L[j]);
            }
        }
        return point;
    }

    public static int change(int[] Ans, int[][] S, int[] C, int[] L, int D, int maxPoint, long t){
        int ci = rand.nextInt(D);
        int before = Ans[ci];
        Ans[ci] = rand.nextInt(26) + 1;
        int newPoint = calcPoint(Ans, S, C, L, D);
        if (newPoint < maxPoint){
            if (rand.nextInt(1900) < t){
                return newPoint;
            }
            else{
                Ans[ci] = before;
            return maxPoint;
            }    
        }
        else{
            return newPoint;
        }
    }
}

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

int main() {
    int a;
    int b;
    int c;

    cin >> a >> b >> c;

    if(a == b){
        if(a != c){
            cout << "Yes" << endl;
        }else{
            cout << "No" << endl;
        }
    }else if(a == c){
        if(a != b){
            cout << "Yes" << endl;
        }else{
            cout << "No" << endl;
        }
    }else if(b == c){
        if(b != a){
            cout << "Yes" << endl;
        }else{
            cout << "No" << endl;
        }
    }else{
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
t = 1
# t = input()
# t = int(t)
def max(a,b):
	if a > b:
		return a
	return b
while t > 0:
	t -= 1
	n,k = map(int,input().strip().split())
	v = list(map(int,input().strip().split()))[0:n]
	# m = {}
	ans = 0
	for i in v:
		if i >= k:
			ans += 1
		# temp = x/i
		# if(x%i != 0):
		# 	temp += 1
		# m[i] += 1
	# ans = 0
	print(ans)
	# rem = 0


Measured memory_bytes: 84596
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> P;
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; }

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n, m;
	cin >> n >> m;
	vector<ll> x(m);
	rep(i,m) cin >> x[i];
	if(n >= m){
		cout << 0 << endl;
		return 0;
	}
	sort(x.begin(), x.end());
	vector<ll> dif(m-1);
	rep(i,m-1){
		dif[i] = x[i+1] - x[i];
	}
	ll ans = 0;
	sort(dif.begin(), dif.end());
	rep(i,max(0,m-n)) ans += dif[i];
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define ll long long
#define INF 1000000005
#define MOD 1000000007
#define EPS 1e-10
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define all(v) (v).begin(),(v).end()

using namespace std;

typedef pair<double,int>P;
typedef complex<double> C;

struct edge
{
    int to;
    double cost;
};

const int MAX_N = 105;

C v[MAX_N];
int r[MAX_N];
vector<edge> G[2*MAX_N];
int n;
double d[2*MAX_N];

namespace std {
  bool operator < (const C& a, const C& b) {
    return real(a) != real(b) ? real(a) < real(b) : imag(a) < imag(b);
  }
}

double cross(const C& a, const C& b) {
  return imag(conj(a)*b);
}
double dot(const C& a, const C& b) {
  return real(conj(a)*b);
}

struct L : public vector<C> {
  L(const C &a, const C &b) {
    push_back(a); push_back(b);
  }
};

int ccw(C a, C b, C c) {
  b -= a; c -= a;
  if (cross(b, c) > 0)   return +1;       // counter clockwise
  if (cross(b, c) < 0)   return -1;       // clockwise
  if (dot(b, c) < 0)     return +2;       // c--a--b on line
  if (norm(b) < norm(c)) return -2;       // a--b--c on line
  return 0;
}

bool intersectLL(const L &l, const L &m) {
  return abs(cross(l[1]-l[0], m[1]-m[0])) > EPS || // non-parallel
         abs(cross(l[1]-l[0], m[0]-l[0])) < EPS;   // same line
}
bool intersectLS(const L &l, const L &s) {
  return cross(l[1]-l[0], s[0]-l[0])*       // s[0] is left of l
         cross(l[1]-l[0], s[1]-l[0]) < EPS; // s[1] is right of l
}
bool intersectLP(const L &l, const C &p) {
  return abs(cross(l[1]-p, l[0]-p)) < EPS;
}
bool intersectSS(const L &s, const L &t) {
  return ccw(s[0],s[1],t[0])*ccw(s[0],s[1],t[1]) <= 0 &&
         ccw(t[0],t[1],s[0])*ccw(t[0],t[1],s[1]) <= 0;
}

L cross_line(C p1,int r1,C p2,int r2)
{
    double d = norm(p2-p1);
    double t = r2*r2 - r1*r1 - d;
    double aa = d,bb = t*(real(p2)-real(p1)),cc = t*t / 4.0 - (imag(p2) - imag(p1))*(imag(p2) - imag(p1))*r1*r1;
    double x1 = (-bb + sqrt(bb*bb - 4*aa*cc))/(2*aa);
    double x2 = (-bb - sqrt(bb*bb - 4*aa*cc))/(2*aa);
    if(x1 > x2){
        swap(x1,x2);
    }
    double y1,y2;
    if(imag(p1) == imag(p2)){
        y1 = -sqrt(r1*r1 - x1*x1);
        y2 = -y1;
    }else{
        y1 = (t+2*(real(p2)-real(p1))*x1)/(-2*(imag(p2)-imag(p1)));
        y2 = (t+2*(real(p2)-real(p1))*x2)/(-2*(imag(p2)-imag(p1)));
    }
    L ln = L(C(x1+real(p1),y1+imag(p1)),C(x2+real(p1),y2+imag(p1)));
    return ln;
}

int main()
{
    int x1,y1,r1,x2,y2,r2;
    cin >> x1 >> y1 >> r1 >> x2 >> y2 >> r2;
    L res = cross_line(C(x1,y1),r1,C(x2,y2),r2);
    printf("%.10f %.10f %.10f %.10f\n",real(res[0]),imag(res[0]),real(res[1]),imag(res[1]));
    return 0;
}

Measured memory_bytes: 3260
#include <bits/stdc++.h> 
using namespace std; 
  
// function to determine the edge colors 
void colorEdges(int ptr, vector<vector<pair<int, int> > >& gra, 
                vector<int>& edgeColors, bool isVisited[]) 
{ 
    queue<int> q; 
    int c = 0; 
  
    set<int> colored; 
  
    // return if isVisited[ptr] is true 
    if (isVisited[ptr]) 
        return; 
  
    // Mark the current node visited 
    isVisited[ptr] = 1; 
  
    // Traverse all edges of current vertex 
    for (int i = 0; i < gra[ptr].size(); i++) { 
        // if already colored, insert it into the set 
        if (edgeColors[gra[ptr][i].second] != -1) 
            colored.insert(edgeColors[gra[ptr][i].second]); 
    } 
  
    for (int i = 0; i < gra[ptr].size(); i++) { 
        // if not visited, inset into the queue 
        if (!isVisited[gra[ptr][i].first]) 
            q.push(gra[ptr][i].first); 
  
        if (edgeColors[gra[ptr][i].second] == -1) { 
            // if col vector -> negative 
            while (colored.find(c) != colored.end()) 
  
                // increment the color 
                c++; 
  
            // copy it in the vector 
            edgeColors[gra[ptr][i].second] = c; 
  
            // then add it to the set 
            colored.insert(c); 
            c++; 
        } 
    } 
  
    // while queue's not empty 
    while (!q.empty()) { 
        int temp = q.front(); 
        q.pop(); 
  
        colorEdges(temp, gra, edgeColors, isVisited); 
    } 
  
    return; 
} 
  
// Driver Function 
int main() 
{ 
    set<int> empty; 
  
    int N; cin >> N;
  
    // declaring vector of vector of pairs, to define Graph 
    vector<vector<pair<int, int> > > gra; 
  
    vector<int> edgeColors; 
  
    bool isVisited[101010] = { 0 }; 
  
    // Enter the Number of Vertices 
    // and the number of edges 
    int ver = N; 
  
    
    int edge = N-1; 
  
    gra.resize(ver); 
    edgeColors.resize(edge, -1); 
  
    // Enter edge & vertices of edge 
    // x--; y--; 
    // Since graph is undirected, push both pairs 
    // (x, y) and (y, x) 
    // graph[x].push_back(make_pair(y, i)); 
    // graph[y].push_back(make_pair(x, i));
  
    int cnt = 0;
  for(int i = 0; i < N-1; i++){
    int a,b; cin >> a >> b; a--; b--;
    gra[a].push_back(make_pair(b,cnt));
    gra[b].push_back(make_pair(a,cnt));
    cnt++;
  }
   
    colorEdges(0, gra, edgeColors, isVisited); 
  
    // printing all the edge colors 
   vector<int> ans; int h = 0;
    for (int i = 0; i < edge; i++){ 
        ans.push_back(edgeColors[i] + 1); h = max(h, edgeColors[i]+1);
    }
  
  cout << h << endl;
  
  for(int i = 0; i < ans.size(); i++){ cout << ans[i] << endl;
                                     }
  
    return 0; 
} 


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

int main() {
  int n;
  cin >> n;
  vector<string>data(1);
  cin >> data[0];
  for(int i = 1;i < n;i++){
    string s;
    cin >> s;
    for(int j = 0;j < data.size();j++){
      if(data[j] == s){
        cout << "No" << endl;
        return 0;
      }
    }
    string pre = data[data.size()-1];
    if(pre[pre.size()-1] != s[0]){
      cout << "No" << endl;
      return 0;
    }
    data.push_back(s);
  }
  cout << "Yes" << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
string ch;
int ans;
int main() {
	cin>>ch;
	for (int i=0;i<ch.size();i++) {
		for (int j=i;j<ch.size();j++) {
			bool flag=false;
			for (int k=i;k<=j;k++) {
				if (ch[k]!='A'&&ch[k]!='C'&&ch[k]!='G'&&ch[k]!='T') {
					flag=true;
					break;
				}
			}
			if (!flag) {
				ans=max(ans,j-i+1);
			}
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {
    int r, g, b;
    cin >> r >> g >> b;
    int gb = g * 10 + b;
    if (gb % 4 == 0)    cout << "YES" << endl;
    else
    {
        cout << "NO" << endl;
    }
    
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<bits/stdc++.h>
using namespace std;
/*---------------------DEBUGGING--------------------------------------------*/
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
/*-------------------------------------------------------------------------------------*/
#define mp make_pair
#define pb push_back
#define ll long long
#define pii pair<int,int>
#define pcc pair<char,char>
#define F first
#define S second
#define int long long
#define pi 3.141592653589793238462643383279502
#define M  998244353
#define rep(i,a,n) for(int i=a;i<n;i++)
#define N 300005
#define vi vector<int>
#define all(v) v.begin(),v.end()

signed main()
{
   ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
   int n;
   cin>>n;
   int a[n];
   map<int,int>m;
   rep(i,0,n){cin>>a[i];m[a[i]]++;}
   int ans=0;
   for(auto it=m.begin();it!=m.end();it++)
   {
       int x=it->S;
       ans+=(x*(x-1))/2;
   }
   for(int i=0;i<n;i++)
   {
       cout<<ans-(m[a[i]]-1)<<endl;
   }

}


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

int dp[100010];
vector <int> adj[100010];

void dfs(int x){
	
	dp[x]=0;
	
	for(int i:adj[x])
	{
		if(dp[i]==-1)
			dfs(i);
		dp[x]=max(dp[i]+1,dp[x]);	
		
	}
}

int main() {
	 int n,m,u,v;
	 cin>>n>>m;
	 fill(dp,dp+n,-1);
	 while(m--){
	 	cin>>u>>v;
	 	u--;v--;
	 	adj[u].push_back(v);
	 }
	 
	 for(int i=0;i<n;i++)
		if(dp[i]==-1) dfs(i);
		
	cout<<*max_element(dp,dp+n);	
	 
	return 0;
}

Measured memory_bytes: 8192
#include <bits/stdc++.h>
using namespace std;
#define sz(x) ((int) (x).size())
typedef long long ll;
typedef pair<int,int> pii;
template<class T> void print(T & x){ cout << x; }
template<class T,class U> void print(pair<T,U> & p){cout << "("; print(p.first); cout << ", "; print(p.second); cout << ")"; }
template<class T> void print(vector<T> & v) {
  cout << "{";
  if (sz(v)) print(v[0]);
  for (int i = 1; i < sz(v); i++) cout << ", ", print(v[i]);
  cout << "}\n";
}

int T, N;
vector<ll> A;
string S;

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cin >> T;
  while(T--){
    cin >> N;
    A.resize(N);
    for(int i=0; i<N; i++){
      cin >> A[i];
    }
    cin >> S;
    bool pos = true;
    for(int i=N-1; i>=0; i--){
      if(S[i] == '0'){
        for(int k=0; k<i; k++){
          A[k] = min(A[k], A[k]^A[i]);
        }
      }
      else{
        if(A[i])
          pos = false;
      }
    }
    cout << (pos ? 0 : 1) << "\n";
  }
}


Measured memory_bytes: 3664
#include <iostream>
#include <stdio.h>
#include <utility>
#include <algorithm>
#include <functional>
#include <string.h>
#include <set>
using namespace std;
typedef long long ll;
int st[31][1<<16],dp[31][1<<16];
int count(int num){
	int res=0;
	for(int i=0;i<16;i++)if((num>>i)&1)res++;
	return res;
}
int main()
{
	int n,c;
	while(cin>>n>>c&&n){
		memset(st,0,sizeof(st));
		memset(dp,-1,sizeof(dp));
		int light[31]={},push[31]={},tmp;
		for(int i=0;i<n;i++){
			for(int j=0;j<16;j++){
				cin>>tmp;
				light[i]*=2;
				light[i]+=tmp;
			}
			light[i]=light[i]&((1<<16)-1);
			//printf("light[%d]:%d\n",i,light[i]);
		}
		for(int i=0;i<c;i++){
			for(int j=0;j<16;j++){
				cin>>tmp;
				push[i]*=2;
				push[i]+=tmp;
			}
			for(int j=0;j<(1<<16);j++){
				st[i][j]=count(push[i]&j);
			}
			push[i]=push[i]&((1<<16)-1);
			//printf("push[%d]:%d\n",i,push[i]);
		}
		dp[0][0]=0;
		for(int i=0;i<n;i++){
			for(int j=0;j<(1<<16);j++){
				if(dp[i][j]<0)continue;
				int nx=j|light[i];
				//dp[i+1][nx]=max(dp[i+1][nx],dp[i][j]);
				for(int k=0;k<c;k++){
					int tx=(nx&~push[k]);
					dp[i+1][tx]=max(dp[i+1][tx],dp[i][j]+st[k][nx]);
				}
			}
		}
		int ans=0;
		for(int i=0;i<(1<<16);i++)ans=max(ans,dp[n][i]);
		printf("%d\n",ans);
	}
    return 0;
}

Measured memory_bytes: 17024
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <queue>
using namespace std;

int main(){
	int n,a,b;
	int count[100001]={};
	vector<int> v[100001];
	cin >> n;
	for(int i=0;i<n-1;i++){
		cin >> a >> b;
		count[a]+=1;
		count[b]+=1;
		v[a].push_back(b);
		v[b].push_back(a);
	}
	queue<int>q;
	for(int i=1;i<=n;i++){
		if(count[i]==1){
			q.push(i);
		}
	}
	int x,y;
	int black=0;
	int flag[100001]={};
	while(!q.empty()){
		x = q.front();
		if(flag[x]==1){
			q.pop();
			continue;
		}
		flag[x]=1;
		black+=1;
		q.pop();
		y = 0;
		for(int i=0;i<v[x].size();i++){
			if(flag[v[x][i]]==0){
				y = v[x][i];
				flag[y]=1;
				for(int i=0;i<v[y].size();i++){
					if(flag[v[y][i]]==0){
						count[v[y][i]]-=1;
						if(count[v[y][i]]==1){
							q.push(v[y][i]);
						}
					}
				}
			}
		}
	}
	for(int i=1;i<=n;i++){
		if(flag[i]==0)black+=1;
	}
	if(black>n/2)cout << "First" <<endl;
	else cout <<"Second" << endl;
	return 0;
}

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

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

using namespace std;

int func(int a, int b, int c) {
  if (a % 2 != 0 || b % 2 != 0 || c % 2 != 0) {
    return 0;
  }

  if (a == b && b == c) {
    return -1;
  }

  return func((a + b) / 2, (a + c) / 2, (b + c) / 2) + 1;
}

int main() {
  int a, b, c;
  std::cin >> a >> b >> c;

  std::cout << func(a, b, c) << std::endl;
  return 0;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
#include <numeric>
#define rep(i,n) for (int i = 0; i < n; ++i)
#define rep1(i,n) for (int i = 1; i <= n; ++i)
template<typename T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
const long long MOD = 1e9+7;
#define precout(val) cout << std::fixed << std::setprecision(20) << val;
const string alphabet = "abcdefghijklmnopqrstuvwxyz";
const int dy[4] = { 0, 1, 0, -1 };
const int dx[4] = { 1, 0, -1, 0 };

ll dp[55][2];
ll val[55];

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

  ll n,p; cin >> n >> p;
  rep(i, n) cin >> val[i];
  dp[0][0] = 1;
  rep(i, n) {
    rep(t, 2) {
      dp[i + 1][(t+val[i])%2] += dp[i][t];
      dp[i + 1][t] += dp[i][t];
    }
  }
  cout << dp[n][p] << endl;
}


Measured memory_bytes: 256