akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> lpair;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i = (m); i < (n); i++)
#define rrep(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define print2(x,y) cout << (x) << " " << (y) << endl;
#define printa(x,n) for(ll i = 0; i < n; i++){ cout << (x[i]) << " ";} cout<<endl;
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N,Q;
    cin >> N >> Q;
    string S;
    cin >> S;
    char t[200010], d[200010];
    rep(i,0,Q){
        cin >> t[i] >> d[i];
    }
    ll lv = -1, rv = N;
    while(rv - lv > 1){
        ll mid = (rv + lv) / 2;
        ll pos = mid;
        char alpha = S[mid];
        bool ok = true;
        rep(i,0,Q){
            if(t[i] == S[pos]){
                if(d[i] == 'R'){
                    pos++;
                }else{
                    pos--;
                }
                if(pos == -1){
                    ok = false;
                    break;
                }else if(pos == N){
                    break;
                }
            }
        }
        if(ok){
            rv = mid;
        }else{
            lv = mid;
        }

    }
    ll v1 = rv;
    lv = -1, rv = N;
    while(rv - lv > 1){
        ll mid = (rv + lv) / 2;
        ll pos = mid;
        char alpha = S[mid];
        bool ok = true;
        rep(i,0,Q){
            if(t[i] == S[pos]){
                if(d[i] == 'R'){
                    pos++;
                }else{
                    pos--;
                }
                if(pos == N){
                    ok = false;
                    break;
                }else if(pos == -1){
                    break;
                }
            }
        }
        if(ok){
            lv = mid;
        }else{
            rv = mid;
        }

    }
    ll v2 = lv;
    print(v2 - v1 + 1);

    

    
    
}

Measured memory_bytes: 976
#include <bits/stdc++.h>
using namespace std;
int main(void){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout<<fixed<<setprecision(15);

    int d,t,s;
    cin>>d>>t>>s;
    if(s*t >= d){
        cout<<"Yes"<<endl;
        return 0;
    }
    cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 3636
N,K = map(int,input().split())
S = input()

ranlength_l = []
count = 1
if(N==1):
    ranlength_l.append([S[0],1])
else:
    for i in range(1,len(S)):
        if(S[i] != S[i-1]):
            ranlength_l.append([S[i-1],count])
            count = 1
        else:
            count += 1
        if(i==len(S)-1):
            ranlength_l.append([S[len(S)-1],count])

ans = N-len(ranlength_l)
for const in (ranlength_l[1:-1:2]):
    if(K==0):
        break
    ans += 2
    K = K-1

if(K!=0 and len(ranlength_l)!=1):
    ans+=1

print(min([ans,N-1]))




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

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

ll count_number(ll b, ll c, ll d)
{
  ll lcm;
  lcm = c * d / gcd(c,d);
  return b - b/c - b/d + b/lcm;
}

int main()
{
  ll a,b,c,d;
  ll tmp;
  cin >> a >> b >> c >> d;
  tmp = count_number(b,c,d) - count_number(a-1,c,d);
  cout << tmp << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
	std::ios::sync_with_stdio(false);
	long long l,r;
	//while(cin>>l>>r){
		
	cin>>l>>r;
		//printf("%d %d\n",l%2019,r%2019);
		ll mx=2e9,mx1=2e9;
		//for(int i=l;i<=r;i++){
		//	for(int j=i+1;j<=r;j++){
		//		mx=min(mx,(1ll*i*j)%2019);
		//		//printf("%d ",(i*j)%2019);
		//	}
		//}
		ll l1=l%2019,rr=r%2019;
		if(l1>=rr||r-l>=2019){
			for(ll i=l1;i<2019;i++)
				for(ll j=i+1;j<2019;j++)
					mx1=min(mx1,(i*j)%2019);
			for(ll i=0;i<=rr;i++)
				for(ll j=i+1;j<=rr;j++)
					mx1=min(mx1,(i*j)%2019);
		}
		else{
			for(ll i=l1;i<=rr;i++)
				for(ll j=i+1;j<=rr;j++)
					mx1=min(mx1,(1ll*i*j)%2019);
		}
	
		//mx1=l1*rr;
		//if(l==r)
		//	mx1=0;
		//cout<<mx<<" "<<mx1<<"\n";
		cout<<mx1<<"\n";
	//}
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>

int main(){
    
    size_t n;
    long long max = 0, x = 0;
    std::string s;

    std::cin >> n >> s;

    for(size_t i = 0; i < n; i++){
        if(s.at(i) == 'I'){
            x++;
        }else{
            x--;
        }

        max = std::max(max, x);
    }

    std::cout << max << std::endl;
    
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pll pair<ll,ll>
#define ff first
#define ss second
#define se set<ll>
#define vec vector<ll>
#define inf 10000000000000000
bool mark[100005];
vec adj[100005];
ll counter;
vec cnt;
vector<string> forsubs;
ll b;
ll a;
ll u;

void addedge(ll u, ll v)

   {
      adj[u].push_back(v);
      adj[v].push_back(u);
   }

void dfs(ll node)
   {
      //cout<<node<<endl;
      mark[node]=1;
      

      for(auto i:adj[node])
      {  
         if(!mark[i])
            {
               dfs(i);
               u++;
            }

      }        

         
   }



int main()
{    
 

   #ifdef APNA_IO
      freopen("input.txt","r",stdin);
      freopen("output.txt","w",stdout);
   #endif
          ios_base::sync_with_stdio(false); 
    cin.tie(NULL); 

ll h,w;
cin>>h>>w;
ll m2[h+1][w+1];
char m1[h+1][w+1];
ll a=1000000000+7;

for(ll j=0;j<=w;j++)
{
   m2[0][j]=0;
}

for(ll i=0;i<=h;i++)
{
   m2[i][0]=0;
}
m2[1][0]=1;

for(ll i=1;i<=h;i++)
{
   for(ll j=1;j<=w;j++)
   {
      cin>>m1[i][j];
   }
}

for(ll i=1;i<=h;i++)
{
   for(ll j=1;j<=w;j++)
   {
      if(m1[i][j]=='.')
      {
         m2[i][j]=(m2[i][j-1]+m2[i-1][j])%a;
      }
      else
         m2[i][j]=0;
   }
}

cout<<m2[h][w]%a<<endl;

}     





Measured memory_bytes: 11392
#include <stdio.h>
int main(void)
{
  int a,b,c,x[110][110],y[100],i,j;
  scanf("%d",&a);
  for(i=0;i<a;i++){
    scanf("%d%d",&b,&c);
    for(j=0;j<c;j++){
      scanf("%d",&y[j]);
      x[b-1][y[j]-1]=1;
    }
  }
  for(i=0;i<a;i++){
    for(j=0;j<a;j++){
      if(j==0) printf("%d",x[i][j]);
      else printf(" %d",x[i][j]);
    }
    printf("\n");
  }
 
 
  return 0;
 
}

Measured memory_bytes: 1872
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int n=scan.nextInt();
		int a=scan.nextInt();
		int b=scan.nextInt();
		if((n*a)<b) System.out.println(n*a);
		else System.out.println(b);
	}

}


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

using namespace std;

int main()
{
//    freopen("in.txt","r",stdin);

    int a[110];
    int b[110];

    int n;
    cin>>n;
    for(int i=0;i<n;i++)
        scanf("%d",&a[i]);
    for(int i=0;i<n;i++)
        scanf("%d",&b[i]);

    double d1=0;
    for(int i=0;i<n;i++)
        d1+=fabs(a[i]-b[i]);

    double d2=0;
    for(int i=0;i<n;i++)
    {
        int k=fabs(a[i]-b[i]);
        d2+=k*k;
    }
    d2=sqrt(d2);

    double d3=0;
    for(int i=0;i<n;i++)
    {
        int k=fabs(a[i]-b[i]);
        d3+=k*k*k;
    }
    d3=pow(d3,1.0/3);

    double d4=0;
    for(int i=0;i<n;i++)
    {
        d4=max(d4,fabs(a[i]-b[i]));
    }

    printf("%.6lf\n",d1);
    printf("%.6lf\n",d2);
    printf("%.6lf\n",d3);
    printf("%.6lf\n",d4);
}



Measured memory_bytes: 3400
/*  -*- coding: utf-8 -*-
 *
 * b.cc: B: ATCoder
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_N = 10;

/* typedef */

/* global variables */

char s[MAX_N + 4];

/* subroutines */

inline bool atcg(char c) {
  return c == 'A' || c == 'T' || c == 'C' || c == 'G';
}

/* main */

int main() {
  scanf("%s", s);

  int maxl = 0;
  for (int i = 0; s[i];) {
    while (s[i] && ! atcg(s[i])) i++;
    if (! s[i]) break;

    int j = i + 1;
    while (atcg(s[j])) j++;
    int l = j - i;
    if (maxl < l) maxl = l;
    i = j;
  }

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


Measured memory_bytes: 256
# # Make IO faster
# import sys
# input = sys.stdin.readline

# # get single (or) multiple str
# X = input()

# # get single int
# N = int(input())
# # get multiple int (e.g., 2)
# X, Y = map(int, input().split())
# # get multiple int (e.g., 2) for N lines
# XY = [list(map(int, input().split())) for _ in range(N)]

# from IPython import embed; embed(); exit();

# 全部入り
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
import numpy as np
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

N, M = MAP()
ans = [0 for _ in range(N)]
for i in range(M):
    a, b = MAP()
    ans[a - 1] += 1
    ans[b - 1] += 1

for a in ans:
    print(a)


Measured memory_bytes: 27116
/*
これを入れて実行
g++ code.cpp
./a.out
*/

#include <iostream>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <cmath>
#include <math.h>
#include <tuple>
#include <iomanip>

using namespace std;
typedef long long ll;
typedef long double ld;

int dy4[4] = { -1, 0, +1, 0 };
int dx4[4] = { 0, +1, 0, -1 };
int dy8[8] = { -1, -1, 0, 1, 1, 1, 0, -1 };
int dx8[8] = { 0, 1, 1, 1, 0, -1, -1, -1 };

const long long INF = 1LL << 60;
const ll MOD = 1e9 + 7;

bool greaterSecond(const pair<int, int>& f, const pair<int, int>& s){
	return f.second > s.second;
}

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

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

ll nCr(ll n, ll r){
	if (r == 0 || r == n){
		return 1;
	}
	else if (r == 1){
		return n;
	}
	return (nCr(n - 1, r) + nCr(n - 1, r - 1));
}

ll nPr(ll n, ll r){
	r = n - r;
	ll ret = 1;
	for (ll i = n; i >= r + 1; i--) ret *= i;
	return ret;
}

//-----------------------ここから-----------

int main(void){
	int n, k;
	cin >> n >> k;

	int maxi = 0;

	vector<int> a(n);
	for (int i = 0; i < n; i++){
		cin >> a[i];
		maxi = max(maxi, a[i]);
	}

	if (maxi < k){
		cout << "IMPOSSIBLE" << endl;
		return 0;
	}

	if (n == 1){
		if (a[0] == k){
			cout << "POSSIBLE" << endl;
		} else {
			cout << "IMPOSSIBLE" << endl;
		}
		return 0;
	}

	int g = gcd(a[0], a[1]);
	for (int i = 2; i < n; i++){
		g = gcd(g, a[i]);
	}

	if (k % g == 0 && maxi % g == 0){
		cout << "POSSIBLE" << endl;
	} else {
		cout << "IMPOSSIBLE" << endl;
	}

}


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

using namespace std;


int main(){
    int N;
    cin >> N;
    vector<int> a(3*N);
    for(int i=0;i<3*N;i++) cin >> a.at(i);

    sort(a.begin(),a.end(),greater<int>());
    long ans = 0;
    for(int i =0;i < 2*N;i++){

        if(i%2==1) ans+= a[i];

    }

    cout << ans << endl;


    return 0;
}

Measured memory_bytes: 1408
#include <iostream> 
#include <algorithm> 
#include <vector> 
#include <cmath>   
#include <complex> 
#include <queue> 
#include <cstdio> 
using namespace std;
const double EPS = 1e-9; const double PI = acos(-1);    typedef complex<double> P; typedef vector<P> G;    struct L :public vector<P> {     L(const P &a,const P &b){         push_back(a);         push_back(b);     } };    
#define next(P,i) (P[(i+1)%P.size()]) 
#define curr(P,i) (P[(i+0)%P.size()])    
double cross(const P &a,const P &b){     return imag(conj(a)*b); } double dot(const P &a,const P &b){     return real(conj(a)*b); }    int ccw(P a,P b,P c){     b -= a;     c -= a;     if( cross(b,c) > 0 ) return +1;     if( cross(b,c) < 0 ) return -1;     if( dot(b,c) < 0 ) return +2;     if( norm(b) < norm(c) ) return -2;     return 0; }    P crosspoint(const L &l,const L &m){     double A = cross(l[1]-l[0],m[1]-m[0]);     double B = cross(l[1]-l[0],l[1]-m[0]);     if( abs(A) < EPS && abs(B) < EPS) return m[0];     return m[0]+B/A*(m[1]-m[0]); }       G convex_cut(const G &poly,const L &l){     G Q;     for(int i = 0 ; i < poly.size() ; i++){         P A = curr(poly,i) , B = next(poly,i);         if( ccw(l[0],l[1],A)!=-1)Q.push_back(A);         if( ccw(l[0],l[1],A)*ccw(l[0],l[1],B)<0)Q.push_back(crosspoint(L(A,B),l));     }     return Q;             }    L bisector(P a,P b){     P A = (a+b) * P(0.5,0);     return L(A,A+(b-a)*P(0,PI/2)); } G voronoi(G g,vector<P> v,int s){     for(int i = 0 ; i < v.size() ; i++){         if( i != s ){             g = convex_cut(g,bisector(v[s],v[i]));         }     }     return g; }    double Area(const G& poly) {     double A = 0;     for (int i = 0; i < poly.size(); ++i)A += cross(curr(poly, i), next(poly, i));     return abs(A)/2; }                                       
int main(){
    int N,M;
	while(cin >> N >> M && N){
	G area,p;
	for(int i = 0 ; i < N ; i++){
		P po;
		cin >> po.real() >> po.imag();
		area.push_back(po);
	}
	for(int i = 0 ; i < M ; i++){
		P po;
		cin >> po.real() >> po.imag();
		p.push_back(po);
	}
	double ans = 0;
	for(int i = 0 ; i < M ; i++){
		printf("%.10lf\n",Area(voronoi(area,p,i)));
	}
 } 
}

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

typedef pair<int, int> P;
typedef pair<P, P> PP;
int main() {
	int H, W, N = 0;
	static int A[500][500];
	vector<PP> ans;
	cin >> H >> W;
	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {
			cin >> A[i][j];
		}
	}
	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W - 1; j++) {
			if (A[i][j] % 2 == 1) {
				ans.emplace_back(PP(P(i + 1, j + 1), P(i + 1, j + 2)));
				N++;
				A[i][j]--;
				A[i][j + 1]++;
			}
		}
	}
	for (int i = 0; i < H - 1; i++) {
		if (A[i][W - 1] % 2 == 1) {
			ans.emplace_back(PP(P(i + 1, W), P(i + 2, W)));
			N++;
			A[i][W - 1]--;
			A[i + 1][W - 1]++;
		}
	}
	cout << N << endl;
	for (PP pp : ans) {
		cout << pp.first.first << " " << pp.first.second << " " << pp.second.first << " " << pp.second.second << endl;
	}
}

Measured memory_bytes: 5232
#include <bits/stdc++.h>
using namespace std;
const int MAX = 1005;
 
int main()
{
    long long n, m;
    cin >> n >> m;
    long long ans;
    if(n*2 > m)
    {
        ans = m/2;
    }
    else ans = n + (m-n*2)/4;
    cout << ans;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>
#include <fstream>
#include <bitset>
#include <time.h>
#include <tuple>
#include <iomanip>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef complex<double> Point;

#define PI acos(-1.0)
#define EPS 1e-10
const ll INF = 1e12;
const ll MOD = 1e9 + 7;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,N) for(int i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define EQ(a,b) (abs((a)-(b))<EPS)
#define EQV(a,b) ( EQ((a).real(), (b).real()) && EQ((a).imag(), (b).imag()) )
#define fi first
#define se second
#define N_SIZE (1LL << 20)
#define NIL -1

int n;

int main(){
	cin >> n;
	vector<int> vi(n);
	rep(i,n)cin >> vi[i];
	ll s = 0;
	int ub = 0;
	ll ans = 0;
	rep(i,n){
		int lb = i;
		while(ub < n){
			bool ok = true;
			rep(j,20){
				if(((1<<j)&s) && ((1<<j)&vi[ub]))ok = false;
			}
			if(ok){
				ans += (ub-lb+1);
				s += vi[ub];
				ub++;
			}
			else break;
		}
		s -= vi[lb];
	}
	cout << ans << endl;
}

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

using std::cout;
using std::cin;
using std::endl;

int main() {
	int k;
	cin >> k;
	long long sum = 0;
	for (int a = 1; a <= k; a++)
	{
		for (int b = 1; b <= k; b++)
		{
			int n = std::gcd(a, b);
			for (int c = 1; c <= k; c++)
			{
				sum += std::gcd(n, c);
			}
		}
	}
	cout << sum << endl;
}

Measured memory_bytes: 3640
N=int(input())
def sieve(n):
    is_prime = [True for _ in range(n+1)]
    is_prime[0] = False

    for i in range(2, n+1):
        if is_prime[i-1]:
            j = 2 * i
            while j <= n:
                is_prime[j-1] = False
                j += i
    table = [ i for i in range(1, n+1) if is_prime[i-1]]
    return is_prime, table
q,p=sieve(55555)
ans=0
q=[]
for i in p:
    if i%5==1:
        q.append(i)
for i in range(N):
    print(q[i],end=" ")


Measured memory_bytes: 41840
q,h,s,d = map(int, input().split())
n = int(input())

if q*2 < h: h = q*2
if h*2 < s: s = h*2
if s*2 < d: d = s*2

ans = n//2*d
n -= n//2 * 2
ans += n*s
print(ans)

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

int main() {
    int n, ans = 0;
    string s;
    cin >> n >> s;
    for (int i0 = 0; i0 < 10; i0++) {
        for (int i1 = 0; i1 < 10; i1++) {
            for (int i2 = 0; i2 < 10; i2++) {
                int pass[3] = {i0, i1, i2};
                int k = 0;
                for (int i = 0; i < s.size(); i++) {
                    if (s[i] - '0' == pass[k]) k++;
                    if (k == 3) {
                        ans++;
                        break;
                    }
                }
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.*;

class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        String[] direction = {"N","S","W","E"};
        boolean test = true;
        if(s.contains(direction[0])){
            if(!s.contains(direction[1])){
                test = false;
            }
        }
        if(s.contains(direction[1])){
            if(!s.contains(direction[0])){
                test = false;
            }
        }
        if(s.contains(direction[2])){
            if(!s.contains(direction[3])){
                test = false;
            }
        }
        if(s.contains(direction[3])){
            if(!s.contains(direction[2])){
                test = false;
            }
        }
        if(test){
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
    }
}


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


int main() {
    long long x,y,a,b,c;
	
	cin >>x >> y >> a >> b >> c;
	vector<long long> al(a),bl(b),cl(c);
	for(int i=0;i<a;i++) cin >> al[i];
	for(int i=0;i<b;i++) cin >> bl[i];
	for(int i=0;i<c;i++) cin >> cl[i];
	cl.push_back(-1);
	sort(al.begin(),al.end(),greater<long long>());
	sort(bl.begin(),bl.end(),greater<long long>());
	sort(cl.begin(),cl.end(),greater<long long>());
	for(int i=x;i<a;i++)al[i]=-1;
	for(int i=y;i<b;i++)bl[i]=-1;

	long long cnt_a=0,cnt_b=0,cnt=0,sum=0;
	int ai=0,bi=0,ci=0;
	while(cnt < x+y){
		if(al[ai]>=bl[bi] && al[ai]>=cl[ci]){
			sum += al[ai];
			ai++;
		}else if (bl[bi]>=al[ai] && bl[bi]>=cl[ci]){
			sum += bl[bi];
			bi++;
		}else{
			sum += cl[ci];
			ci++;
		}
		cnt++;
	}

	cout << sum << endl;
	// cout << ai << " " << bi << " " << ci << endl;

    return 0;
}



Measured memory_bytes: 3328
#include <bits/stdc++.h>
using namespace std;
int main(){
  int64_t a, b, c, k;
  cin >> a >> b >> c >> k;
  if(k<a+1){
    cout << k << endl;
  }
  if(a<k && k<a+b+1){
    cout << a << endl;
  }
  if(k>a+b){
    cout << 2*a-k+b << endl;
  }
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define trace1(x)                cerr<<#x<<": "<<x<<endl
#define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
#define ll  long long
#define endl '\n'
#define pi 3.14159265
ll p(ll a,ll b)
{
    ll res=1;
    while(b)
    {
        if(b%2!=0)

            res*=a;
        a*=a;
        b/=2;
    }
    return res;
}
int main()
{           
    IOS;
    string s;
    cin>>s;
    string tmp=s.substr(0,4);
    if(tmp>"2019")
    {
    	cout<<"TBD";
    	return 0;
    }
    if(tmp<"2019")
    {
    	cout<<"Heisei";
    	return 0;
    }
    tmp=s.substr(5,2);
    if(tmp>"04")
    {
    	cout<<"TBD";
    	return 0;
    }
    if(tmp<"04")
    {
    	cout<<"Heisei";
    	return 0;
    }
    cout<<"Heisei";
}       

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

#define INF INT_MAX
typedef long long ll;

using namespace std;

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

	if((a < c && c < b) || (b < c && c < a)){
		cout << "Yes" << endl;
	}else{
		cout << "No" << endl;
	}
	
	return 0;
}				

Measured memory_bytes: 256
//#define _CRT_SECURE_NO_WARNINGS
#include "bits/stdc++.h"

#define rep(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define all(x) (x).begin(),(x).end()
#define MOD 1000000007
#define INF (1LL<<60LL)
typedef long long ll;

using namespace std;


int main() {
	ll n, m; cin >> n >> m;
	vector<ll> a(n);
	rep(i, n) cin >> a[i];
	sort(all(a));
	vector<ll> a0 = a;
	vector<pair<int, int>> p(m + 1);
	rep(i, m) {
		int b, c; cin >> b >> c;
		p[i] = { c,b };
	}
	sort(all(p));
	reverse(all(p));
	int j0 = 0;


	rep(i,m){
		int b = p[i].second;
		int c = p[i].first;
		int k = int(lower_bound(all(a0), c) - a0.begin());
		b = max(0,min(b, k - j0));
		rep(j1, b) {
			a[j0+j1] = c;
		}
		j0 = j0 + max(0, b);
	}
	ll ans = 0;
	for (auto au : a) {
		ans += au;
	}
	cout << ans << endl;
}

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

typedef long long LL;
typedef pair<int, int> PII;
typedef vector<int> VI;
#define MP make_pair
#define PB push_back
#define X first
#define Y second

#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define RFOR(i, b, a) for(int i = (b) - 1; i >= (a); --i)
#define ALL(a) a.begin(), a.end()
#define SZ(a) (int)((a).size())
#define FILL(a, value) memset(a, value, sizeof(a))
#define debug(a) cout << #a << " = " << a << endl;

const double PI = acos(-1.0);
const LL INF = 1e9 + 47;
const LL LINF = INF * INF;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

template<typename T> void setmax(T& x, T y) {x = max(x, y);}
template<typename T> void setmin(T& x, T y) {x = min(x, y);}

int main()
{
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	
	int n, m;
	cin >> n >> m;
	
	int max_l = 1, min_r = n;
	while(m--)
	{
		int l, r;
		cin >> l >> r;
		setmax(max_l, l);
		setmin(min_r, r);		
	}
	
	cout << max(0, min_r - max_l + 1);
	
	cerr << "Time elapsed: " << clock() / (double)CLOCKS_PER_SEC << endl;
	return 0;
}



Measured memory_bytes: 256
#!/usr/bin/env python3
#ARC98 D

import sys
import math
import bisect
sys.setrecursionlimit(1000000000)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

n = I()
a = [0] + LI()
b = list(accumulate(a))
l,r,tmp,ans = 0,0,0,n
while r < n:
    if b[r+1] - b[l] == tmp ^ a[r+1]:
        tmp ^= a[r+1]
        ans += r-l
        r += 1
    elif l == r:
        tmp ^= a[l]
        l += 1
        r += 1
    else:
        l += 1
        tmp ^= a[l]
print(ans)


Measured memory_bytes: 23960
# https://drken1215.hatenablog.com/entry/2020/03/23/004100

import collections
import math

N = int(input())
a = list(map(int,input().split()))
a_counter = collections.Counter(a)

res = 0

for v in a_counter: # 全通り
    res += a_counter[v]*(a_counter[v]-1)//2

for v in a:
    befor = a_counter[v]*(a_counter[v]-1)//2
    after = (a_counter[v]-1)*(a_counter[v]-2)//2
    print(res-befor+after)



Measured memory_bytes: 34132
(n, k) = list(map(int, input().split()))
h = [int(input()) for _ in range(n)]
h.sort()
l = 0
k -= 1
minh = 10000000000
for i in range(k, n):
    minh = min(minh, h[i] - h[i - k])
print(minh)

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

using namespace std;

template<typename S, typename T>
ostream& operator<<(ostream& out, const pair<S, T> p) {
    out << "(" << p.first << "," << p.second << ")";
    return out;
}

template<typename T>
ostream& operator<<(ostream& out, const vector<T>& v) {
    for (auto a: v)
        out << a << " ";
    return out;
}

template<typename T>
ostream& operator<<(ostream& out, const set<T>& S) {
    for (auto a: S)
        cout << a << " ";
    return out;
}

template<typename T>
ostream& operator<<(ostream& out, const multiset<T>& S) {
    for (auto a: S)
        cout << a << " ";
    return out;
}

template<typename S, typename T>
ostream& operator<<(ostream& out, const map<S, T>& M) {
    for (auto m: M)
        cout << "(" << m.first << "->" << m.second << ") ";
    return out;
}

template<typename S, typename T>
pair<S, T> operator+(pair<S, T> a, pair<S, T> b) {
    return make_pair(a.first + b.first, a.second + b.second);
}

template<typename S, typename T>
pair<S, T> operator-(pair<S, T> a, pair<S, T> b) {
    return make_pair(a.first - b.first, a.second - b.second);
}

int solve(vector<vector<pair<int,int>>>& A) {
    // cout << "A: " << A << endl;
    int n = A.size();
    vector<int> B;
    int max_val = 0;
    for (int i = 0; i < (1<<n); i++) {
        // cout << "i: " << i << endl;
        B.assign(n, 0);
        for (int j = 0; j < n; j++) {
            if (i & (1<<j)) {
                B[j] = 1;
            }
        }
        // cout << "B: " << B << endl;
        bool ok = true;
        for (int j = 0; j < n; j++) {
            if (B[j]) {
                for (auto &p: A[j]) {
                    if (p.second == 1 && B[p.first] == 0) {
                        ok = false;
                        break;
                    }
                    if (p.second == 0 && B[p.first] == 1) {
                        ok = false;
                        break;
                    }
                }
                if (!ok)
                    break;
            }
        }
        if (ok) {
            int val = __builtin_popcount(i);
            max_val = max(max_val, val);
        }
    }
    return max_val;
}

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int n;
    vector<vector<pair<int,int>>> A;
    cin >> n;
    A.resize(n);
    for (int i = 0; i < n; i++) {
        int m;
        cin >> m;
        A[i].resize(m);
        for (int j = 0; j < m; j++) {
            int a, b;
            cin >> a >> b;
            A[i][j] = {a - 1, b};
        }
    }
    int ans = solve(A);
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }

const ll mod = 1e9 + 7;
ll dp[100003][102][2];

int main() {
    string s;
    int d;
    cin >> s >> d;
    int n = s.length();
    dp[0][0][0] = 1;
    REP(i,n) REP(j,d) REP(f,2){
        int y = s[i] - '0';
        int lim = f ? 9 : y;
        FOR(x,0,lim){
            (dp[i+1][(j+x)%d][f|(x<y)] += dp[i][j][f]) %= mod;
        }
    }
    ll ans = mod - 1;
    REP(f,2) ans = (ans + dp[n][0][f]) % mod;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 16640
H, W, K = map(int, input().split())
mod = 7 + 10**9
No = [1 for i in range(7)] #使用しない辺の取り方
No[1], No[2], No[3], No[4] = 2, 3, 5, 8
No[5], No[6]= 13, 21

if W == 1:
    print(1)
else:
    DP = [[0 for w in range(W)] for h in range(H)]
    DP[0][0], DP[0][1] = No[max(0, W-2)], No[max(0, W-3)]
    for h in range(1, H):
        for w in range(W):
            if w == 0:
                left = 0
                up = DP[h-1][0] * No[max(0, W-2)] % mod
                right = DP[h-1][1] * No[max(0, W-3)] % mod
            elif w == W-1:
                left = DP[h-1][W-2] * No[max(0, W-3)] % mod
                up = DP[h-1][W-1] * No[max(0,W-2)] % mod
                right = 0
            else:
                left = DP[h-1][w-1] * No[max(0, w-2)] * No[max(0, W-w-2)] % mod
                up = DP[h-1][w] * No[max(0, w-1)] * No[max(0, W-w-2)] % mod
                right = DP[h-1][w+1] * No[max(0, w-1)] * No[max(0, W-w-3)] % mod
            DP[h][w] = (left+up+right) % mod
    print(DP[H-1][K-1])



Measured memory_bytes: 3188
// #pragma GCC optimize("O3")
#include<bits/stdc++.h>
using namespace std;
 
#define ll long long
#define pb push_back
#define N 1000000007
#define N2 998244353
#define Nmax 100001
#define INF (ll)1e18
#define pll pair<ll,ll>
#define pii pair<ll,ll>
#define mp make_pair
#define fi first
#define se second
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(ll i=m;i<(n);i++)
#define get(n) ll (n); scanf("%lld",&(n));
#define get2(n,k) ll (n),(k); scanf("%lld%lld",&(n),&(k));
#define get3(n,m,k) ll (n),(m),(k); scanf("%lld%lld%lld",&(n),&(m),&(k));
#define gets(s) string (s); cin >> (s);
#define ALL(c) (c).begin(),(c).end()
#define fill_nums(A,n) vector<ll> A((n)); for(ll i=0;i<n;i++) scanf("%lld",&A[i]);
#define fill_edges(adj,m) for(ll i=0;i<m;i++) {ll a, b; scanf("%lld %lld",&a,&b); adj[a-1].pb(b-1); adj[b-1].pb(a-1);}
#define fill_direct(adj,m) for(ll i=0;i<m;i++) {ll a, b; scanf("%lld %lld",&a,&b); adj[a-1].pb(b-1);}
#define pi 3.1415926535897

int main() {

	get2(r,l);

	string sr="", sl="";
	while(r) {
		sr += (r%2) + '0';
		r /= 2;
	}

	while(l) {
		sl += (l%2) + '0';
		l /= 2;
	}

	ll diff = sl.length()-sr.length();
	while(diff--)
		sr += '0';
	reverse(ALL(sl));
	reverse(ALL(sr));
	// cout<<sr<<" "<<sl<<endl;

	vector<vector<vector<ll>>> dp(2, vector<vector<ll>>(2, vector<ll>(2,0)));
	dp[0][0][0] = 1;

	for(ll i=0;i<sl.length();i++) {
		vector<vector<vector<ll>>> dp2(2, vector<vector<ll>>(2, vector<ll>(2,0)));

		if(sr[i]=='0')
			dp2[0][1][0] = (dp[0][0][0] + dp[0][1][0])%N;

		l = sl[i]-'0';
		r = sr[i]-'0';
		dp2[1][0][0] = ((!(l==0 && r==1) ? dp[1][0][0] : 0) + ((l==1 && r==1) ? dp[0][0][0] : 0))%N;
		dp2[1][0][1] = ((l==0 ? dp[1][0][1] : (2*dp[1][0][1] + (r==0 ? dp[1][0][0] : 0))) + ((l==1 && r==0) ? dp[0][0][0] : 0))%N;
		dp2[1][1][0] = ((r==1 ? dp[1][1][0] : (2*dp[1][1][0] + (l==1 ? dp[1][0][0] : 0))) + (r==1 ? dp[0][1][0] : 0))%N;
		dp2[1][1][1] = (3*dp[1][1][1] + (l==1 ? dp[1][0][1] : 0) + (r==0 ? dp[1][1][0] : 0) + (r==0 ? dp[0][1][0] : 0))%N;

		dp = dp2;
	}

	ll sum = 0;
	for(auto i:dp)
		for(auto j:i)
			for(auto k:j)
				sum = (sum + k)%N;

	printf("%lld\n", sum);

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=1;i<=(n);i++)
using ll=long long;
int main(){
    int n,m;
    cin>>n>>m;
    vector<vector<int>> dat(n+1);
    rep(i,m){
        int a,b;
        cin>>a>>b;
        if(a==1||b==1||a==n||b==n){
            dat[a].push_back(b);
            dat[b].push_back(a);
        }
    }
    for(int p:dat[1]){
        if(dat[p].size()>=2){
            cout<<"POSSIBLE"<<endl;
            return 0;
        }
    }
    cout<<"IMPOSSIBLE"<<endl;
    return 0;
}

Measured memory_bytes: 14936
import java.util.*;

public class Main {
  public static void main(String[] args) {
    new Main().run();
  }

  private void run() {
    while(sc.hasNext()) {
      final int n = sc.nextInt();

      if(n == 0) break;

      int[] as = new int[n];
      for(int i = 0; i < n; i++) as[i] = sc.nextInt();

      long max = -100000;
      long sum = 0;

      for(int i = 0; i < n; i++) {
        sum += as[i];

        if(max < sum) max = sum;
        if(sum <= 0) sum = 0;
      }

      System.out.println(max);
    }
  }

  private final Scanner sc = new Scanner(System.in);
}

Measured memory_bytes: 12000
//ΔARC 081C
#include<iostream>
#include<cstdio>
#include<fstream>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<cmath>
#include<cstring>
#include<cstdlib>
using namespace std;
typedef long long LL;
int a[111111];
int main()
{
	int n,i,x;
	scanf("%d",&n);
	for(i=1;i<=n;i=i+1)
		scanf("%d",a+i);
	sort(a+1,a+n+1);
	x=0;
	for(i=n-1;i>=1;i=i-1){
		if(a[i+1]==a[i]){
			if(x){
				cout<<(LL)a[i]*x<<endl;
				return 0;
			}
			x=a[i];
			i--;
		}
	}
	cout<<0<<endl;
	return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
using namespace std;

int main (){
  int H, N;
  cin >> H >> N;
  int A[N];
  int sum = 0;
  for (int i = 0; i < N; ++i) {
    cin >> A[i];
    sum += A[i];
  }
  if (sum >= H) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}


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

// vector<int> dp(100000, 1e9);

int main()
{
    int X[32] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
    int n;
    cin >> n;
    cout << X[n - 1];
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,l,r) for(int (i)=(l);(i)<(r);(i)++)
#define ll long long
using namespace std;
int main(){
    ll n,a,b;
    cin>>n>>a>>b;
    ll ans=0;
    ans=a*(n/(a+b));
    ans+=((n-(n/(a+b))*(a+b)<a)?(n-(n/(a+b))*(a+b)):(a));
    cout<<ans<<endl;
}

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

using namespace std;
int main(){
    int ab, bc, ca;
    cin >> ab >> bc >> ca;

    float s = (ab + bc + ca) / 2;
    int result = sqrt(s * (s - ab) * (s - bc) * (s - ca));
    cout << result << endl;
}

Measured memory_bytes: 256
#include <iostream>   
                         
using namespace std;  
long x, y;               
                         
int main()               
{                        
  int ans = 0;           
  long a;                
                         
  cin >> x >> y;         
  a = x;                 
                         
  while(a <= y){         
    ans++;               
    a *= 2;              
  }                      
  cout << ans << endl;
                         
  return 0;              
}                        


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

#define int long long
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define rep1(i,n) for(int i=1;i<=(int)(n);++i)
#define rep11(i,n) for(int i=1;i<(int)(n);++i)
#define repo(i,o,n) for(int i=o;i<(int)(n);++i)
#define repm(i,n) for(int i=(int)(n)-1;i>=0;--i)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define sperase(v,n) (v).erase(remove(all(v), n), (v).end())
#define vdelete(v) (v).erase(unique(all(v)), (v).end())
#define pb(n) push_back(n)
#define mp make_pair
#define MOD 1000000007
#define INF LONG_LONG_MAX

struct UnionFind {
#define MAX 100001
    int root[MAX];
    void Init() {rep(i,MAX) root[i] = -1;}
    void unite(int a ,int b) {
        int a_root = find(a),b_root = find(b);
        if (a_root != b_root) {
            if (root[a_root] > root[b_root]) {
                root[a_root] += root[b_root];
                root[b_root] = a_root;
            } else {
                root[b_root] += root[a_root];
                root[a_root] = b_root;
            }
        }
    }
    int find(int a) {
        if (root[a] < 0) return a;
        else {
            root[a] = find(root[a]);
            return root[a];
        }
    }
    int size(int a) {
        int a_root = find(a);
        return -root[a_root];
    }
    /*
     * root : rootの番号
     * unite : 併合
     * find : aのrootを返す
     * size : aのグループの要素数
     * */
};

int n,m,a[100000],x,y,ans;
pair<int,int> memo = mp(0,-1);
UnionFind UF;
priority_queue<int,vector<int>,greater<int>> pq;
map<int,priority_queue<int,vector<int>,greater<int>>> M;

signed main() {
    UF.Init();
    cin >> n >> m;
    if (n-1 == m) {
        cout << 0 << endl;
        return 0;
    }
    rep(i,n) cin >> a[i];
    rep(i,m) {
        cin >> x >> y;
        UF.unite(x,y);
    }
    rep(i,n) M[UF.find(i)].push(a[i]);
    for(auto i : M) {
        ans += i.se.top();
        i.se.pop();
        while(!i.se.empty()) {
            pq.push(i.se.top());
            i.se.pop();
        }
    }
    rep(i,2*(n-m-1)-M.size()) {
        if (pq.empty()) {
            cout << "Impossible" << endl;
            return 0;
        }
        ans += pq.top();
        pq.pop();
    }
    cout << ans << endl;
}



Measured memory_bytes: 12800
#include <iostream>
#define SENTINEL 1000000001
using namespace std;
int comp = 0;

void Merge(int arr[], int left, int mid, int right) {
    int n1 = mid - left;
    int n2 = right - mid;
    int arr1[n1] = {};
    int arr2[n2] = {};
    for (int i = 0; i < n1; i++) {
        arr1[i] = arr[left + i];
    }

    for (int i = 0; i < n2; i++) {
        arr2[i] = arr[mid + i];
    }
    arr1[n1] = SENTINEL;
    arr2[n2] = SENTINEL;
    int i = 0;
    int j = 0;
    for(int k = left; k < right; k++) {
        comp++;
        if (arr1[i] < arr2[j]) {
            arr[k] = arr1[i];
            i++;
        } else {
            arr[k] = arr2[j];
            j++;
        }
    }
}

void MergeSort(int arr[], int left, int right) {
    if (left + 1 < right) {
        int mid = (left + right) / 2;
        MergeSort(arr, left, mid);
        MergeSort(arr, mid, right);
        Merge(arr, left, mid, right);
    }
}

int main() {
    int pickles, i;
    cin >> i;
    int array[i] = {};
    for (int j = 0; j < i; j++) {
        cin >> array[j];
    }
    MergeSort(array, 0, i);
    for (int k = 0; k < i; k++) {
        if (k != i - 1) cout << array[k] << " ";
        else cout << array[k] << endl;
    }
    cout << comp << endl;
}


Measured memory_bytes: 6972
import java.util.*;

class Main{
  public static void main (String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int M = sc.nextInt();
    Integer Array[] = new Integer[N];
    boolean AC[] = new boolean[N];
    for(int i=0;i<N;i++){
      Array[i] = 0;
      AC[i] = false;
    }
    for (int i=0;i<M;i++){
     int p = sc.nextInt();
     String s = sc.next();
     if (s.equals("WA")){
      if (AC[p-1] == false){
        Array[p-1] += 1;
      }
     }else{
       AC[p-1] = true;
     }
    }
    int one = 0;
    int two = 0;
    for (int i=0;i<N;i++){
      if (AC[i]){
        one += 1;
        two += Array[i];
      }
    }
    System.out.print(one);
    System.out.print(" ");
    System.out.print(two);
    
    

  }
}

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

int main()
{
    int N;
    cin >> N;
    vector<int> A(N);
    map<int, long> B{};
    for (int i = 0; i < N; i++)
    {
        cin >> A.at(i);
        B[A.at(i)]++;
    }

    long sum = 0;
    for (pair<int, long> p : B)
    {
        sum += p.second * (p.second - 1) / 2;
    }

    for (int i = 0; i < N; i++)
    {
        cout << sum - B[A.at(i)] + 1 << endl;
    }

    return 0;
}

Measured memory_bytes: 11948
x, n = map(int, input().split())
p = list(map(int, input().split()))
reps = [i for i in range(-1, 102)]
for elem in p:
    reps.remove(elem)
diff = 10 ** 7
ans = -100
for elem in reps[::-1]:
    rep = abs(x - elem)
    if rep <= diff:
        diff = rep
        ans = elem
print(ans)


Measured memory_bytes: 61996
#include <iostream>
#include <algorithm>
#include <math.h>
#include <string.h>

typedef long long ll;
using namespace std;

int main()
{
  string S;
  cin >> S;
  
  int sum = 0;
  
  if(S[0]=='1')sum++;
  if(S[1]=='1')sum++;
  if(S[2]=='1')sum++;

  cout << sum << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define REP(i,a) for(int i=0;i<(a);i++)
#define MOD 1000000007

int main(){
  string s;
  cin>>s;
  ll cnt[26]={}, n=s.length();
  ll ans=n*(n-1)/2+1;
  for(int i=0;i<n;i++) cnt[s[i]-'a']++;
  for(int i=0;i<26;i++){
    ans-=cnt[i]*(cnt[i]-1)/2;
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <cmath>
#include <string>
#include <climits>
#include <iomanip>
#include <algorithm>
#include <queue>
#include <map>
#include <tuple>
#include <iostream>
#include <deque>
#include <array>
#include <set>
#include <functional>

constexpr long long int mod = 1000000007L;
long long int solve(const int current, std::vector<long long int>& memo) {
	if (current > memo.size()) {
		return 0;
	}
	else if (current == memo.size()) {
		return 1;
	}
	else if (memo[current] != -1) {
		return memo[current];
	}
	else {
		return memo[current] = (solve(current + 2, memo) + solve(current + 1, memo)) % mod;
	}
}
int main() {
	int n, m; std::cin >> n >> m;
	std::vector<long long int> memo(n, -1);
	for (auto i = 0; i < m; ++i) {
		int a;  std::cin >> a;
		memo[a] = 0;
	}
	for (int i = n; i >= 0; i -= 1000) {
		solve(i, memo);
	}
	std::cout << solve(0, memo) << std::endl;
};

Measured memory_bytes: 1280
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
typedef long long ll;
const int N=2005;
struct node{
    int u,v,nxt;
}edge[N*2];
int head[N],mcnt;
void add_edge(int u,int v){
    mcnt++;
    edge[mcnt].u=u;
    edge[mcnt].v=v;
    edge[mcnt].nxt=head[u];
    head[u]=mcnt;
}
int n,k;
int du[N];
int deep[N];
void dfs(int u,int fa,int d){
    deep[u]=d;
    for(int i=head[u];i;i=edge[i].nxt){
        int v=edge[i].v;
        if(v==fa)
            continue;
        dfs(v,u,d+1);
    }
}
int main()
{
    //freopen("shorten.in","r",stdin);
    //freopen("shorten.out","w",stdout);
    scanf("%d%d",&n,&k);
    for(int i=1;i<n;i++){
        int u,v;
        scanf("%d%d",&u,&v);
        add_edge(u,v);
        add_edge(v,u);
        du[u]++;
        du[v]++;
    }
    int ans=n;
    if(k&1)
        for(int u=1;u<=n;u++)
            for(int i=head[u];i;i=edge[i].nxt){
                int v=edge[i].v;
                if(v<u)
                    continue ;
                dfs(u,v,0);
                dfs(v,u,0);
                int cnt=0;
                for(int j=1;j<=n;j++)
                    if(deep[j]>k/2)
                        cnt++;
                ans=min(ans,cnt);
            }
    else
        for(int u=1;u<=n;u++){
            dfs(u,0,0);
            int cnt=0;
            for(int j=1;j<=n;j++)
                if(deep[j]>k/2)
                    cnt++;
            ans=min(ans,cnt);
        }
    printf("%d\n",ans);
}


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

typedef vector<int> veci;
typedef pair<int, int> pii;
typedef vector<pii> vecii;
typedef long long ll;
typedef pair<ll, ll> pll;
typedef vector<ll> vecl;
typedef vector<pll> vecll;
#define EPS (1e-9)
#define MOD (1e9 + 7)
#define fi first
#define se second
#define endl '\n'

void solve() {
    int n;
    cin >> n;

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

    ll ans1 = 0;
    int p = 1;
    ll prev = v[n/2];
    int l = 0, r = n - 1;
    while (p < n) {
        if (p % 2) {
            ans1 += abs(prev - v[l]);
            prev = v[l];
            l += 1;
        } else {
            ans1 += abs(prev - v[r]);
            prev = v[r];
            r -= 1;
        }
        p += 1;
    }

    ll ans2 = 0;
    p = 1;
    if (n%2==0) {
        prev = v[(n-1)/2];
    } else {
        prev = v[n/2];
    }
    l = 0, r = n - 1;
    while (p < n) {
        if (p % 2 == 0) {
            ans2 += abs(prev - v[l]);
            prev = v[l];
            l += 1;
        } else {
            ans2 += abs(prev - v[r]);
            prev = v[r];
            r -= 1;
        }
        p += 1;
    }

    cout << max(ans1,ans2) << endl;
}

int main(int argc, char* argv[]) {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
#ifdef LOCAL_TEST
    (void)argc;
    const string strpath = string(argv[0]) + string("-test.in");
    freopen(strpath.c_str(), "r", stdin);
    int tcs;
    cin >> tcs;
    while (tcs-- > 0)
#endif
    solve();
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef int Int;
typedef pair<Int,Int> pii;
typedef pair<Int,double> pid;
typedef pair<double,double> pdd;
typedef pair<Int,pii> pip;
typedef pair<double,Int> pdp;
#define A first
#define B second
#define pb(x) push_back(x)
#define ALL(x) x.begin(),x.end()
#define SZ(x) (x).size()
#define CLR(x) memset(x,0,sizeof x)
#define pdebug() printf("%d\n",__LINE__)
#define Itype(a) typeof(a.begin()) 
#define REP(i,a,b) for(int i = (a);i <= (b);i++)
#define FORO(i,n) REP(i,0,(int)n-1)
#define FORI(i,n) REP(i,1,(int)n)
#define FORIT(i,t) for(Itype(t) i = t.begin();i != t.end();i++)
#define eps 1e-6
#define sqr(x) ((x)*(x))
#define dist(_a,_b) sqrt(sqr(_a.A-_b.A)+sqr(_a.B-_b.B))
#define norm(_a) sqrt(sqr(_a.A)+sqr(_a.B))
template<typename T>void getMin(T &a,T b) { if(a > b) a = b; }
template<typename T>void getMax(T &a,T b) { if(a < b) a = b; }
const int MOD = 1000000007;

struct UF {
    vector<int> p;
    vector<int> sz;
    UF(int size) { init(size); }
    void init(int size){
        p.clear(); p.resize(size);
        sz.clear(); sz.resize(size);
        for(int i = 0;i < size;i++) {
            p[i] = i;
            sz[i] = 1;
        }
    }
    int find(int x) {
        return x == p[x] ? x : p[x] = find(p[x]);
    }
    bool same(int x, int y){ return find(x) == find(y); }
    void unite(int x, int y) {
        x = find(x), y = find(y);
        p[x] = y;
        sz[y] += sz[x];
    }
    int size(int u) {
        return sz[find(u)];
    }
};

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int N, M;
    cin >> N >> M;
    vector<pii> E(M);
    FORO(i, M) {
        cin >> E[i].A >> E[i].B;
        E[i].A--; E[i].B--;
    }
    reverse(ALL(E));
    UF uf(N);
    ll k = (ll) N * (N - 1LL) / 2LL;
    vector<ll> ans(M);
    FORO(i, M) {
        ans[i] = k;
        int a = E[i].A, b = E[i].B;
        if(!uf.same(a, b)) {
            //cout << "i = " << i <<  uf.size(a) << " "<<  uf.size(b) << endl;
            k -= uf.size(a) * uf.size(b);
            uf.unite(a, b);
        }
    }
    reverse(ALL(ans));
    FORO(i, M) cout << ans[i] << endl;
    return 0;
}

Measured memory_bytes: 3712
#include<iostream> 
#include<vector> 
#include<string> 
#include<algorithm> 
using namespace std; 
int main()
{
	string s;
	cin >> s;
	for (char i = 'a'; i <= 'z'; i++)
	{
		int a = 0;
		for (int j = 0; j < s.size();j++)
		{
			if (i==s.at(j))
			{
				a++;
			}
		}
		if (a==0)
		{
			cout << i << endl;
			break;
		} 
		if (i=='z')
		{
			cout << "None" << endl;
			break;
		}
	}
}

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

using namespace std;

long long int LCM(long long int p,long long int q)
{
    long long int m,n;
    m=p;
    n=q;
    while(m!=n)
    {
        if(m>n)
            n=n+q;
        if(m<n)
            m=m+p;
    }
    return m;
}

int main()
{
    long long int a,b,c,d,e,f,g,h,l;
    cin>>a>>b>>c>>d;
    l=LCM(c,d);
    e=b-a+1;
    f=(b/c)-(a/c);
    g=(b/d)-(a/d);
    h=(b/l)-(a/l);
    if(a%c==0)
        f++;
    if(a%d==0)
        g++;
    if(a%l==0)
        h++;
    cout<<(e-f-g+h);
    return 0;
}


Measured memory_bytes: 384