akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define int LL
using namespace std;
typedef long long LL;
const int MAX_N=100005;
const int Mod=1e9+7;
int n;
int m;
int x[MAX_N];
int y[MAX_N];
int xi[MAX_N];
int yi[MAX_N]; 
int pre[MAX_N];
int sum(int seg[],int nm)
{
	for(int i=1;i<nm;i++)
	{
		pre[i]=pre[i-1]+seg[i];
	}
	int l=1,r=nm-1;
	int res=pre[nm-1];
	int sum=res;
	while(l<nm && r>0)
	{ 
		res+=pre[nm-1]-pre[l]-(pre[nm-1]-pre[r-1]);
		res%=Mod;
		l++;
		r--;
		sum+=res;
		sum%=Mod;
	}
	return sum;
}
signed main()
{
	cin>>n>>m;
	for(int i=1;i<=n;i++)cin>>x[i];
	for(int i=1;i<=m;i++)cin>>y[i];
	for(int i=1;i<n;i++)xi[i]=x[i+1]-x[i];
	for(int i=1;i<m;i++)yi[i]=y[i+1]-y[i];
	cout<<sum(xi,n)*sum(yi,m)%Mod<<endl;

	return 0;
}

Measured memory_bytes: 4096
#include <bits/stdc++.h>
#define LOCAL
using namespace std;
template <typename A, typename B>
ostream& operator <<(ostream& out, const pair<A, B>& a) {
out << "(" << a.first << "," << a.second << ")";
return out;
}
template <typename T, size_t N>
ostream& operator <<(ostream& out, const array<T, N>& a) {
out << "["; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
return out;
}
template <typename T>
ostream& operator <<(ostream& out, const vector<T>& a) {
out << "["; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
return out;
}
template <typename T, class Cmp>
ostream& operator <<(ostream& out, const set<T, Cmp>& a) {
out << "{"; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "}";
return out;
}
template <typename U, typename T, class Cmp>
ostream& operator <<(ostream& out, const map<U, T, Cmp>& a) {
out << "{"; bool first = true;
for (auto& p : a) { out << (first ? "" : ", "); out << p.first << ":" << p.second; first = 0;} out << "}";
return out;
}
#ifdef LOCAL
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
#else
#define trace(...) 42
#endif
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
const char* comma = strchr(names + 1, ',');
cerr.write(names, comma - names) << ": " << arg1 << " |";
__f(comma + 1, args...);
}
#define rep(i,n) for(int i=0; i<(n); i++)
using ll = long long;
#define int long long
using P = pair<int,int>;
//#########################################
void chmax(int &a,int b){
    if(a < b)a = b;
}
signed main(){
    int n,w;cin >> n >> w;
    vector<vector<int>> dp(n+1,vector<int>(w+1,0));
    rep(i,n){
        int a,b;cin >> a >> b;
        rep(j,w+1){
            chmax(dp[i+1][j],dp[i][j]);
            if(j+a < w+1)chmax(dp[i+1][j+a],dp[i][j] + b);
        }
    }
    cout << dp[n][w] << endl;
    return 0;
}

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

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

void put_double(double obj){printf("%.12f\n",obj);};

template < typename T > std::string to_string( const T& n )
{
    std::ostringstream stm ;
    stm << n ;
    return stm.str() ;
}

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; }


int main()
{
    int r,D,x;
    cin >> r >> D >> x;

    rep(i,10)
    {
        x = r*x-D;
        cout << x << endl;
    }
}


Measured memory_bytes: 256
/*Bismillahir Rahmanir Rahim*/


#include<bits/stdc++.h>
#include<cstring>
#include<vector>
#include<map>
#include<set>
#define ll long long int
#define dd double
using namespace std;

int main()
{
   ll t,n,i,j,x,a,b,y;
    cin>>a>>b;
    if(a>b)
    cout<<"safe"<<endl;
    else
    {
       cout<<"unsafe"<<endl;
    }
    

  
   
  

}
//Apna Time Aayega :)

Measured memory_bytes: 3644
#include <iostream>
#include <vector>
#include <algorithm> // sort
#include <map> // pair

#define all(x) (x).begin(),(x).end()
#define FOR(x) for(ll i = 0;i < x;++i)

using namespace std;
typedef long long ll;

int main() {
	int r,D,x;
  cin>>r>>D>>x;
  int tmp = x;
  for(int i = 0;i < 10;i++){
    tmp = r * tmp - D;
    cout<<tmp<<endl;
  }

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <utility>
#include <cstdio>
#include <iomanip>
#include <cmath>
#include <string>
#include <stack>
#include <queue>
#include <map>
#include <stdlib.h>
#include <set>
typedef long long ll;
using namespace std;

int main() {
	string s;
	cin>>s;
	if(s=="a"||s=="i"||s=="u"||s=="e"||s=="o"){
		cout<<"vowel"<<endl;
	}else{
		cout<<"consonant"<<endl;
	}

	return 0;
}



Measured memory_bytes: 256
use proconio::{input, fastout};
use proconio::marker::{Chars};
use proconio::marker::Usize1;
use std::cmp::*;
use std::char;

macro_rules! debug {
      ($($a:expr),*) => {
          eprintln!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}

#[fastout]
fn main() {
    input!{
        s: Chars,
    }

    let mut alphabet: Vec<usize> = vec![0;30];
    for i in 0..s.len() {
        alphabet[s[i] as usize - 'a' as usize] += 1;
    }
    debug!('a' as usize);
    debug!(alphabet);
    for i in 0..26 {
        if alphabet[i]==0 {
            println!("{}", char::from_u32(i as u32 + 'a' as u32).unwrap());
            return;
        }
    }
    println!("None");
}


Measured memory_bytes: 2480
import java.util.Scanner;

public class Main {
public static void main(String[] args) {
	Scanner scn=new Scanner(System.in);
	int []arr=new int [5];
	int ans=0;
	for(int i=0;i<5;i++) {
		arr[i]=scn.nextInt();
		if(arr[i]==0)
			ans=i+1;
	}
	System.out.println(ans);
}
}


Measured memory_bytes: 35704
<?php

fscanf(STDIN,"%s",$numbers);

//1と0の数を数える
$count0 = substr_count($numbers,"0");
$count1 = substr_count($numbers,"1");

if ($count0 > $count1){
    echo $count1 * 2;
}else{
    echo $count0 * 2;
}


Measured memory_bytes: 3828
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0,i##_max=(N);i<i##_max;++i)
#define repp(i,l,r) for(int i=(l),i##_max=(r);i<i##_max;++i)
#define per(i,N) for(int i=(N)-1;i>=0;--i)
#define perr(i,l,r) for(int i=r-1,i##_min(l);i>=i##_min;--i)
#define all(arr) (arr).begin(), (arr).end()
#define SP << " " <<
#define SPF << " "
#define SPEEDUP cin.tie(0);ios::sync_with_stdio(false);
#define MAX_I INT_MAX //1e9
#define MIN_I INT_MIN //-1e9
#define MAX_UI UINT_MAX //1e9
#define MAX_LL LLONG_MAX //1e18
#define MIN_LL LLONG_MIN //-1e18
#define MAX_ULL ULLONG_MAX //1e19
  typedef long long ll;
  typedef pair<int,int> PII;
  typedef pair<char,char> PCC;
  typedef pair<ll,ll> PLL;
  typedef pair<char,int> PCI;
  typedef pair<int,char> PIC;
  typedef pair<ll,int> PLI;
  typedef pair<int,ll> PIL; 
  typedef pair<ll,char> PLC; 
  typedef pair<char,ll> PCL; 

inline void YesNo(bool b){ cout << (b?"Yes" : "No") << endl;}
inline void YESNO(bool b){ cout << (b?"YES" : "NO") << endl;}
inline void Yay(bool b){ cout << (b?"Yay!" : ":(") << endl;}

int main(void){
  SPEEDUP
  cout << setprecision(15);
  int N;cin >> N;
  vector<PLL> range(N);
  vector<ll> left(N);
  vector<ll> right(N);
  rep(i,N){
    cin >> range[i].first >> range[i].second;
    left[i] = range[i].first;
    right[i] = range[i].second;
  }
  sort(all(range));
  sort(all(left));
  sort(all(right));
  if(N%2==1) cout << right[N/2] - left[N/2] + 1 << endl;
  else{
    ll l = left[N/2-1] + left[N/2];
    ll r = right[N/2-1] + right[N/2];
    cout << r - l + 1 << endl;
  }
  return 0;
}


Measured memory_bytes: 9512
a, b, c = map(int, input().split())
k = int(input())
ans = a+b+c
m = -100
if m < a: 
    m = a
if m < b: 
    m = b
if m < c: 
    m = c
ans = ans - m
for i in range(k):
    m = m*2
print(ans + m)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int>ii;
typedef vector<int>vi;
typedef vector<ii>vii;
vector<vii>adjlist;
const int N=1e5+5;
vi all;
vii tmp;
int n,child[N];
long long sum[N],sum1[N],ans[N];
bool  vis[N];
void dfs(int u,int p)
{
    child[u]=1;
    for(ii v:adjlist[u])
    {
        if(not vis[v.first] && v.first!=p){
            dfs(v.first,u);
            child[u]+=child[v.first];
        }
    }
}
int findcen(int u,int p,int sz)
{
    for(ii v:adjlist[u]){
        if(not vis[v.first] && v.first!=p && child[v.first]>sz/2)return findcen(v.first,u,sz);
    }
    return u;
}
void redfs(int u,int p,int dist)
{
    all.push_back(dist);
    for(ii v:adjlist[u]){
        if(not vis[v.first] && v.first!=p){
            redfs(v.first,u,min(dist,v.second));
        }
    }
}
void findans(int u,int p,int dist)
{
    tmp.push_back(ii(dist,u));
    for(ii v:adjlist[u]){
        if(v.first!=p && not vis[v.first]){
            findans(v.first,u,min(dist,v.second));
        }
    }
}
void centroid(int root)
{
    dfs(root,root);
    int cen=findcen(root,root,child[root]);
    vis[cen]=1;
    all.clear();
    for(int i=0;i<adjlist[cen].size();++i){
        int v=adjlist[cen][i].first;
        if(vis[v])continue;
        redfs(v,cen,adjlist[cen][i].second);
    }
    sort(all.begin(),all.end());
    for(int pos=0;pos<all.size();pos++){
        if(pos)sum[pos]=sum[pos-1]+all[pos];
        else sum[pos]=all[pos];
    }
    ans[cen]+=sum[all.size()-1];
    for(int i=0;i<adjlist[cen].size();++i){
        int v=adjlist[cen][i].first;
        int w=adjlist[cen][i].second;
        if(vis[v])continue;
        tmp.clear();
        findans(v,cen,w);
        sort(tmp.begin(),tmp.end());
        for(int j=0;j<tmp.size();j++){
            if(j)sum1[j]=sum1[j-1]+tmp[j].first;
            else sum1[j]=tmp[j].first;
        }
        for(int j=0;j<tmp.size();++j){
            int u=tmp[j].second;
            int len=tmp[j].first;
            int pos1=upper_bound(tmp.begin(),tmp.end(),ii(len,1e9+7))-tmp.begin();
            int pos2=upper_bound(all.begin(),all.end(),len)-all.begin();
            ans[u]+=sum[pos2-1]-sum1[pos1-1];
            ans[u]+=len*(all.size()-pos2+pos1-tmp.size()+1);
        }
    }
    for(int i=0;i<adjlist[cen].size();i++){
        int v=adjlist[cen][i].first;
        if(not vis[v])centroid(v);
    }
}
int main()
{
    scanf("%d",&n);
    adjlist.assign(n+1,vii());
    for(int i=1;i<n;++i){
        int u,v,w;
        scanf("%d%d%d",&u,&v,&w);
        adjlist[u].push_back(ii(v,w));
        adjlist[v].push_back(ii(u,w));
    }
    centroid(1);
    for(int i=1;i<=n;++i)printf("%lld\n",ans[i]);
}


Measured memory_bytes: 16504
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        #[cfg(debug_assertions)]
        writeln!(&mut std::io::stderr(), concat!("[DEBUG] ", $(stringify!($a), "={:?} "),*), $($a),*);
    }
}

#[allow(unused_imports)]
use std::cmp::{min, max};

#[allow(unused_imports)]
use std::io::Write;
const MOD: usize = 1e9 as usize + 7;

fn dfs(edges: &Vec<Vec<usize>>, cur: usize, prev: usize, dp: &mut Vec<Vec<usize>>) {
    let mut white = 1;
    let mut black = 1;
    for &next in edges[cur].iter() {
        if prev != next {
            dfs(edges, next, cur, dp);
            white *= (dp[next][0] + dp[next][1]) % MOD;
            white %= MOD;

            black *= dp[next][0];
            black %= MOD;
        }
    }
    dp[cur][0] = white;
    dp[cur][1] = black;
}


fn main() {
    input!{
      n: usize,
      xys: [(usize,usize); n-1],
    }

    let mut edges = vec![vec![]; n];
    for &(x, y) in xys.iter() {
        edges[x-1].push(y-1);
        edges[y-1].push(x-1);
    }
    let mut dp = vec![vec![0; 2]; n];
    dfs(&edges, 0, n, &mut dp);
    let ans = dp[0][0] + dp[0][1];
    println!("{}", ans%MOD);
}


Measured memory_bytes: 27004
#include <algorithm>
#include <queue>
#include <vector>
#include<bits/stdc++.h>

using namespace std;

constexpr long long INF64 = 1e18;

class Graph {

  struct Edge {
    int src, dst;
    long long weight;
    Edge(int src, int dst, long long weight)
        : src(src), dst(dst), weight(weight) {}

    bool operator<(const Edge &e) const {
        return weight > e.weight;
    }
  };

  std::vector<std::vector<Edge>> g;
  std::vector<long long> dist, prev;

  int flag = -1;

  void Dijkstra(int s) {
    std::priority_queue<Edge> q;
    dist[s] = 0;
    for (q.emplace(-2, s, 0); !q.empty();) {
      Edge e = q.top();
      q.pop();
      if (prev[e.dst] != -1) {
        continue;
      }
      prev[e.dst] = e.src;
      for (auto next_e : g[e.dst]) {
        if (dist[next_e.dst] > next_e.weight + e.weight) {
          dist[next_e.dst] = next_e.weight + e.weight;
          q.emplace(next_e.src, next_e.dst, dist[next_e.dst]);
        }
      }
    }
    flag = s;
  }

public:
  Graph(int n) : g(n), dist(n, INF64), prev(n, -1) {}

  void addEdge(int s, int t, long long cost) {
    g[s].emplace_back(s, t, cost);
    flag = -1;
  }

  long long getCost(int s, int t) {
    if (flag != s) {
      Dijkstra(s);
    }
    return dist[t];
  }

  std::vector<int> getPath(int s, int t) {
    if (flag != s) {
      Dijkstra(s);
    }
    std::vector<int> path;
    for (; t != -2; t = prev[t]) {
      path.push_back(t);
    }
    std::reverse(path.begin(), path.end());
    return path;
  }
};

int main(){
    int n,m,s;
    cin>>n>>m>>s;
    Graph g(n);
    for(int i=0;i<m;++i){
        int from,to;
        long long weight;
        cin>>from>>to;
        cin>>weight;
        g.addEdge(from,to,weight);
    }
    for(int i=0;i<n;++i){
        long long ans=g.getCost(s,i);
        if(ans==INF64)cout<<"INF"<<endl;
        else cout<<ans<<endl;
    }
}
        


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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int H,W,K;
string S[808];
int SY,SX;

int dist[808][808];

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>H>>W>>K;
	FOR(y,H) {
		cin>>S[y];
		FOR(x,W) {
			if(S[y][x]=='S') {
				S[y][x]='.';
				SY=y;
				SX=x;
			}
			dist[y][x]=1<<20;
		}
	}
	
	dist[SY][SX]=0;
	queue<int> Q;
	Q.push(SY*1000+SX);
	while(Q.size()) {
		int cy=Q.front()/1000;
		int cx=Q.front()%1000;
		Q.pop();
		if(dist[cy][cx]==K) continue;
		
		FOR(i,4) {
			int dd[]={1,0,-1,0};
			int ty=cy+dd[i];
			int tx=cx+dd[i^1];
			if(ty<0 || tx<0 || ty>=H || tx>=W) continue;
			if(S[ty][tx]=='#') continue;
			if(dist[ty][tx]>dist[cy][cx]+1) {
				dist[ty][tx]=dist[cy][cx]+1;
				Q.push(ty*1000+tx);
			}
		}
	}
	
	FOR(y,H) FOR(x,W) if(dist[y][x]<=K) {
		dist[y][x]=0;
		Q.push(y*1000+x);
	}
	
	while(Q.size()) {
		int cy=Q.front()/1000;
		int cx=Q.front()%1000;
		Q.pop();
		
		if(cy==0 || cy==H-1 || cx==0 || cx==W-1) {
			_P("%d\n",(dist[cy][cx]+K-1)/K+1);
			return;
		}
		
		FOR(i,4) {
			int dd[]={1,0,-1,0};
			int ty=cy+dd[i];
			int tx=cx+dd[i^1];
			if(ty<0 || tx<0 || ty>=H || tx>=W) continue;
			if(dist[ty][tx]>dist[cy][cx]+1) {
				dist[ty][tx]=dist[cy][cx]+1;
				Q.push(ty*1000+tx);
			}
		}
	}
	
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n';
	FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	solve(); return 0;
}


Measured memory_bytes: 6016
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
vector<vector<int> > map;
int N;
class road {
public:
	int a;
	int b;
	int far;
	road(int c, int d, int e) :a(c), b(d), far(e) {}
};
bool compare(road &a, road &b) {
	return a.far < b.far;
}


bool func(road& a, int num) {
	return a.a != num&&a.b != num;
}

int find(road &ro) {
	int res = (1 << 31) - 1;
	for (int i = 1; i <= N; ++i) {
		if (func(ro, i)) {
			int a = map[i][ro.a];
			int b = map[i][ro.b];
			res = min(res, a + b);
		}
	}
	return res;
}
int main() {
	cin >> N;
	map.resize(N + 1);
	for (int i = 1; i <= N; ++i) {
		map[i].resize(N + 1);
		for (int j = 1; j <= N; ++j) {
			cin >> map[i][j];
		}
	}
	vector<road> list;
	for (int i = 1; i <= N; ++i) {
		for (int j = i + 1; j <= N; ++j) {
			list.push_back(road(i, j, map[i][j]));
		}
	}
	sort(list.begin(), list.end(), compare);
	long long ans = 0;
	for (int i = 0; i < list.size(); ++i) {
		int num = find(list[i]);
		int num2 = map[list[i].a][list[i].b];
		if (num > num2) {
			ans += num2;
		}
		else if (num < num2) {
			ans = -1;
			break;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1532
import java.util.*;
import java.io.*;
import java.lang.reflect.Array;
import java.lang.reflect.Constructor;
import java.util.function.*;
// import lib.util.*;
// import lib.graph.*;
// import lib.io.*;
// import lib.math.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int K = sc.nextInt();
        int Q = sc.nextInt();
        int[] A = new int[N];
        Arrays.fill(A, K - Q);
        StringBuilder res = new StringBuilder();
        for (int i = 0; i < Q; i++) {
            A[sc.nextInt() - 1]++;
        }
        for (int i = 0; i < N; i++) {
            if (A[i] <= 0) {
                System.out.println("No");
            } else {
                System.out.println("Yes");
            }
        }
    }
}

Measured memory_bytes: 59456
#include <iostream>
#include <vector>
#include <stack>
#include <queue>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <numeric>

using namespace std;

#define rep(i, n) for(int i = 0; i < n; i++)
#define repi(i, start, end) for(int i = start; i < end; i++)
#define all(x) (x).begin(), (x).end()
#define debug(x) cout << (x) << endl;
typedef long long ll;
const int MAX = 999999999;

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

    vector<int> nums(n);
    rep(i, n) cin >> nums[i];

    vector<int> cnt_num(100005, 0);
    rep(i, n){
        if(nums[i]-1 >= 0) cnt_num[nums[i]-1] ++;
        cnt_num[nums[i]] ++;
        cnt_num[nums[i]+1] ++;
    }

    int target = max_element(all(cnt_num)) - cnt_num.begin();
    int cnt = 0;
    rep(i, n){
        if(nums[i]-1 <= target && target <= nums[i]+1) cnt ++;
    }

    cout << cnt << endl;
}

Measured memory_bytes: 1024
#include<iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<vector>
#include<map>
#include<stack>
#include<queue>
using namespace std;
#define MAXN 100001
int dp[MAXN*3];
int main(){
	int N;
	cin>>N;
	for(int i=0;i<N*3;++i){
		cin>>dp[i];
	}
	//dp[0]=in[0];dp[1]=in[1];dp[2]=in[2];
	for(int i=3;i<N*3;i++){
		if(i%3==0){
			dp[i]=dp[i]+max(dp[i-2],dp[i-1]);
		}else if(i%3==1){
			dp[i]=dp[i]+max(dp[i-4],dp[i-2]);
		}else{
			dp[i]=dp[i]+max(dp[i-4],dp[i-5]);
		}
	}
	int x;
	if(dp[3*N-1]>=dp[3*N-2]){
		x=dp[3*N-1];
	}else{
		x=dp[3*N-2];
	}
   cout<<(x>dp[3*N-3]?x:dp[3*N-3]);
   return 0;
} 

Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
const int maxp=309;
int vep[maxp];int totp;
void erathos(){
	int n=2000;
	bool bep[n+1];memset(bep,1,sizeof(bep));
	for(int i=2;i*i<=n;++i)
	if(bep[i]){
		for(int j=i*i;j<=n;j+=i)
			bep[j]=0;
	}
	for(int i=2;i<=n;++i)
	if(bep[i])vep[totp++]=i;
}
typedef long long LL;
const LL modu=1e9+7;
int dd[maxp];
LL getans(){
	LL s=1;
	for(int i=0;i<totp;++i){
		if(dd[i]==0)continue;
		for(int j=0;j<dd[i];++j){
			s=s*vep[i]%modu;
		}
	}
	return s;
}
void addon(int x,int f){
	for(int i=0;i<totp;++i){
		if(x==1)break;
		int idx=0;
		while(x%vep[i]==0){
			x/=vep[i];
			idx++;
		}
		dd[i]+=idx*f;
	}
}
void Comb(int n,int r){//comb select r from n
	for(int i=0;i<r;++i){
		addon(i+1,-1);
		addon(n-i,1);
	}
}
void c1(int a,int b){
	Comb(a-1,b-1);
}
LL solve(int n,int k,int i){
	if(n-k+2<i+1)return 0;
	memset(dd,0,sizeof(dd));
	c1(n-k+2,i+1);c1(k,i);
	return getans();
}
int main(){
	erathos();
	int n,k;cin>>n>>k;
	for(int i=1;i<=k;++i)printf("%lld\n",solve(n,k,i));
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
  
int main(){
  int a,b,c,x;
  cin >> a;
  cin >> b;
  cin >> c;
  cin >> x;
  int sum = 0;
  int num;
  if(x % 50 == 0){
    for(int i=0;i<=a;i++){
      if(i * 500 > x)break;
      for(int j=0;j<=b;j++){
        if(i*500+j*100 > x)break;
        num = x - i * 500 - j * 100;
        if(num >= 0 && num / 50 <= c){
          sum++;
        }
      }
    }
    cout << sum;
  }else{
    cout << 0;
  }
}


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <algorithm>
#include <stdlib.h>
#include <vector>
#include <stack>

using namespace std;


int main(){
	int n;

	while(1){
		cin >> n;
		if(n == 0) break;

		int score[n];
		for(int i=0 ; i<n ; i++){
			cin >> score[i];
		}
		sort(score , score+n);
		
		int sum=0;
		for(int i=1 ; i<n-1 ; i++){
			sum += score[i];
		}
		sum = sum / (n-2);

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

Measured memory_bytes: 1176
/*
   وَعَلَى اللَّهِ فَلْيَتَوَكَّلِ الْمُؤْمِنُونَ
*/

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

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

   int a, b ;
   cin >> a >> b ;
   int cn = 0 ;
   while(a){
     a /= b ;
     cn++ ;
   }

   cout << cn ;


}




Measured memory_bytes: 256
#include <bits/stdc++.h>
#define INF 2000000000
using namespace std;
typedef long long ll;
int read(){
    int f = 1, x = 0;
    char c = getchar();
    while(c < '0' || c > '9'){if(c == '-') f = -f; c = getchar();}
    while(c >= '0' && c <= '9')x = x * 10 + c - '0', c = getchar();
    return f * x; 
}
int h, w, a, b;
char s[1005][1005] = {0};
void init(){
    h = read(), w = read(), a = read(), b = read();
}
void solve(){
    for (int i = 0; i < b; ++i)
        for (int j = a; j < w; ++j)
            s[i][j] = 1;
    for (int i = b; i < h; ++i)
        for (int j = 0; j < a; ++j)
            s[i][j] = 1;
    for (int i = 0; i < h; ++i){
        for (int j = 0; j < w; ++j)
            putchar(s[i][j] + '0');
        putchar('\n');
    }
}
int main(){
    init();
    solve();
    return 0;
}

Measured memory_bytes: 2176
import java.io.*;

class Main{
    public static void main(String args[])throws IOException{
      try(BufferedReader br = new BufferedReader(new InputStreamReader(System.in))){
        int H = Integer.parseInt(br.readLine());
        int W = Integer.parseInt(br.readLine());
        int N = Integer.parseInt(br.readLine());

        int max = Math.max(H, W);
        int min = Math.min(H, W);

        int max_count = max;
        int min_count = min;

        int result = 0;

        while(N > 0){
          if(max_count != 0){
            N -= max;
            max_count--;
            result++;
          }else if(min_count != 0){
            N -= min;
            min_count--;
            result++;
          }
        }

        System.out.println(result);
      }
    }
}

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

int main(){
string N; cin>>N;
  if(N.at(0)!='7'&&N.at(1)!='7'&&N.at(2)!='7'){cout<<"No"<<endl;}
  else{cout<<"Yes"<<endl;}
}


Measured memory_bytes: 3628
#include <stdio.h>

int main()
{
	int n;

	scanf("%d", &n);

	int array[n];
	int i;
	for(i=0; i<n ;i++){
		scanf("%d", &array[i]);
	}

	int sum = 0;
	int max = array[0];

	i=0;
	for(i=0; i<n ;i++){
		sum = sum + array[i];
		if ( max < array[i]){
			max = array[i];
		}
	}

	if(
		sum - max > max
	){
		printf("Yes\n");
	} else{
		printf("No\n");
	}

	return 0;
}


Measured memory_bytes: 128
#include <stdio.h>
#include <limits.h>

/** Application main entry point. */
int main (
  int argc,
  char *argv[ ]
  )
{
  int n;

  scanf ( "%d", &n );
  while ( n != 0 )
  {
    int min = INT_MAX;
    int max = INT_MIN;

    while ( n-- )
    {
      int a, b, v, g, d;
      int ptr;

      scanf ( " %d %d %d %d %d", &a, &b, &v, &g, &d );
      ptr = a + b + v + g + d;

      if ( ptr > max )
      {
        max = ptr;
      }
      if ( ptr < min )
      {
        min = ptr;
      }
    }
    printf ( "%d %d\n", max, min );

    scanf ( " %d", &n );
  }

  return ( 0 );
}

Measured memory_bytes: 0
from collections import deque
N, M = map(int, input().split())
broken = [int(input())-1 for i in range(M)] #indexは0からなので、-1
broken = set(broken)

if N == 1:
  print(1)
  exit()

if 0 in broken:
    if 1 in broken:
        stairs=deque([0,0])
    else:
        stairs=deque([0,1])
else:
    if 1 in broken:
        stairs=deque([1,0])
    else:
        stairs=deque([1,2])

for i in range(2,N):
    if i in broken:
        stairs.append(0)
    else:
        stairs.append((stairs[i-1]+stairs[i-2])%(10**9 + 7))
print(stairs[-1])

Measured memory_bytes: 13552
# -*- coding: utf-8 -*-
s=list(input())
n=len(s)
c=0

if n%2 == 0:
  m=int(n/2)
else:
  m=int((n-1)/2)

for i in range(m):
  if s[i] != s[n-(1+i)]:
    c=c+1
    
print(c)

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

int main(){
  int a,b;
  cin >> a >> b;
  int c;
  if(b / 10 > 0 && b / 10 < 10){ 
  c = 100 * a + b;
  }else if(b / 10 == 0) {
    c = 10 * a + b;
  }else{
    c = 1000 * a + b;
  }

  for(int i = 0; i <= c; i++){
    if( c == i * i){ cout << "Yes"; return 0; }
  }

  cout << "No";
return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
typedef long long lint;
using namespace std;

int main()
{
	int N;
	lint a[200010]={};
	lint sum=0;
	lint ans=2e9+10;
	
	cin >> N;
	for(int i=1;i<=N;i++)
	{
		cin >> a[i];
		sum+=a[i];
	}
	for(int i=1;i<N;i++)
	{
		a[i]+=a[i-1];
		ans=min(ans,abs(a[i]-(sum-a[i])));
	}
	cout << ans << endl;
	return 0;
}


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

# AtCoder Beginner Contest
# Problem B
import math


if __name__ == '__main__':
    a, b = map(str, input().split(" "))

    number = int(a + b)
    root_number = math.sqrt(number)

    if abs(number - int(root_number) ** 2) < 10 ** -6:
        print("Yes")
    else:
        print("No")


Measured memory_bytes: 2940
import sys
input = sys.stdin.readline

H, W = map(int, input().split())
F = []
for _ in range(H):
    a = list(input())[:-1]
    F.append(a)

L = [[0]*(W+2) for _ in range(H+2)]
R = [[0]*(W+2) for _ in range(H+2)]
U = [[0]*(W+2) for _ in range(H+2)]
D = [[0]*(W+2) for _ in range(H+2)]

for h in range(1, H+1):
    f = F[h-1]
    l = L[h]
    for w in range(1, W+1):
        l[w] = l[w-1] + 1 if f[w-1] == '.' else 0
        U[h][w] = U[h-1][w] + 1 if f[w-1] == '.' else 0

for h in range(H, 0, -1):
    f = F[h-1]
    r = R[h]
    for w in range(W, 0, -1):
        r[w] = r[w+1] + 1 if f[w-1] == '.' else 0
        D[h][w] = D[h+1][w] + 1 if f[w-1] == '.' else 0

ans = 0
for h in range(1, H+1):
    l, r, u, d = L[h], R[h], U[h], D[h]
    ans = max( ans, max( l[w]+r[w]+u[w]+d[w] for w in range(1, W+1) ))
print(ans-3)

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

int main() {
  int A, B;
  string op;
  cin >> A >> op >> B;
  
  if(op == "+"){
    cout << A + B << endl;
  }
  
  else if(op == "-"){
  	cout << A- B << endl;
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
    string st;
    cin>>st;
    ll i;
    ll x=st.size();
    ll chk=0;
    for(i=0; i<x; i++)
    {
        if(st[i]=='7')
        {
            chk=1;
            break;
        }
    }
    if(chk==1) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}


Measured memory_bytes: 3628
# include <iostream>
# include <vector>
# include <limits>
# include <algorithm>
# include <map>
using namespace std;

int main() {
	map<int, bool> a;
	for (int i = 1; i <= 30; i++) {
		a.insert(map<int, bool>::value_type(i, false));
	}
	int b;
	for (int i = 0; i < 28; i++) {
		cin >> b;
		a[b] = true;
	}
	for (int i = 1; i <= 30; i++) {
		if (a[i] == false) {
			cout << i << endl;
		}
	}
}

Measured memory_bytes: 3104
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		char[] list = sc.next().toCharArray();
		boolean flag = false;
		int max = 0;
		int tmp = 0;
		for(int i = 0; i < list.length; i++) {
			if(list[i] == 'A' || list[i] == 'T' || list[i] == 'C' || list[i] == 'G') {
				if(!flag) {
					flag = true;
					tmp = 0;
				}
				tmp++;
			} else {
				if(flag) {
					flag = false;
					max = Math.max(max, tmp);
				}
			}
		}
		System.out.println(Math.max(max, tmp));
	}

}


Measured memory_bytes: 23252
#include<iostream>
#include<map>
#include<vector>
using namespace std;
typedef long long ll;

int main(){
    int n, k;
    cin >> n >> k;
    vector<ll> v(n+1, 0);
    for(int i = 1; i <= n; i++)  cin >> v[i], v[i] += v[i-1];
    map<ll,int> m;
    m[0] = 1;
    ll ret = 0;
    for(int i = 1; i <= n; i++){
        if(i >= k)   m[(v[i-k]-(i-k))%k]--;
        ret += m[(v[i]-i)%k];  
        m[(v[i]-i)%k]++;
    }
    cout << ret << endl;
    return 0;
}

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

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using WGraph = vector<vector<pair<int, ll>>>;

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

constexpr int dx[4] = {-1, 0, 0, 1}, dy[4] = {0, -1, 1, 0};
constexpr int INF = 1e9;
constexpr int MOD = 1e9 + 7;
constexpr long long LINF = 1e18;
constexpr double EPS = 1e-10;
constexpr double PI = M_PI;

void solve() {
    int n;
    cin >> n;
    vector<ll> a(n);
    for (int i=0; i<n; ++i) {
        cin >> a.at(i);
    }

    sort(a.begin(), a.end());
    vector<ll> two;
    for (int i=0; i<n; ++i) {
        if (i+1 < n && a.at(i) == a.at(i+1)) {
            two.push_back(a.at(i));
            ++i;
        }
    }

    int len = (int)two.size();
    if (len < 2) cout << 0 << '\n';
    else cout << two.at(len-1) * two.at(len-2) << '\n';
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(20);

    solve();

    return 0;
}


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

int main(){
  int i,X,Y;
  cin>>X>>Y;
  int flag=1;
  for(i=0;i<X+1;i++){
    if(2*i+4*(X-i)==Y){
      cout<<"Yes"<<endl;
      flag=0;
      break;
    }
  }
  if(flag)cout<<"No"<<endl;
}

Measured memory_bytes: 3564
# -*- coding: utf-8 -*-
n,m = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(n)]
ab.sort()

res = 0
for i in range(n):
    if m>=ab[i][1]:
        res += ab[i][0]*ab[i][1]
        m -= ab[i][1]
    else:
        res += ab[i][0]*m
        m = 0

    if m==0:
        break

print(res)


Measured memory_bytes: 27756
import java.util.Comparator;
import java.util.Scanner;

public class Main {
    public static void main(String args[]) {
        try (Scanner in = new Scanner(System.in)) {
            int N = in.nextInt();
            int M = in.nextInt();
            int[] A = new int[M];
            for (int i = 0; i < M; i++) {
                A[i] = in.nextInt();
            }

            int[] n = new int[] { 0, 2, 5, 5, 4, 5, 6, 3, 7, 6, };

            int[] B = new int[M];
            for (int i = 0; i < M; i++) {
                B[i] = n[A[i]];
            }

            Comparator<String> comparator = new Comparator<String>() {
                @Override
                public int compare(String o1, String o2) {
                    if (o1 == null) {
                        if (o2 == null) {
                            return 0;
                        } else {
                            return 1;
                        }
                    } else {
                        if (o2 == null) {
                            return -1;
                        } else {
                        }
                    }

                    if (o1.length() > o2.length()) {
                        return -1;
                    }
                    if (o1.length() < o2.length()) {
                        return 1;
                    }
                    return -o1.compareTo(o2);
                }
            };

            String[] dp = new String[N + 1];
            dp[0] = "";
            for (int i = 0; i < dp.length; i++) {
                if (dp[i] == null) {
                    continue;
                }
                for (int j = 0; j < A.length; j++) {
                    if (i + B[j] > N) {
                        continue;
                    }
                    String next1 = A[j] + dp[i];
                    String next2 = dp[i] + A[j];
                    String next = comparator.compare(next1, next2) < 0 ? next1 : next2;
                    String current = dp[i + B[j]];
                    dp[i + B[j]] = comparator.compare(current, next) < 0 ? current : next;
                }
            }

            System.out.println(dp[N]);
        }
    }

}


Measured memory_bytes: 380752
#include <stdio.h>
#define MAX 100000
#define SENTINEL 2000000000

struct Card {
    char suit;
    int value;
};

struct Card L[MAX / 2 + 2], R[MAX / 2 + 2];

void merge(struct Card A[], int n, int left, int mid, int right){
    int i, j, k;
    int n1 = mid -left;
    int n2 = right - mid;
    for (i=0; i<n1; i++) L[i] = A[left + i];
    for (i=0; i<n2; i++) R[i] = A[mid + i];
    L[n1].value = R[n2].value = SENTINEL;
    i = j = 0;
    for (k=left; k<right; k++){
        if (L[i].value <= R[j].value){
            A[k] = L[i++];
        } else{
            A[k] = R[j++];
        }
    }
}

void mergeSort(struct Card A[], int n, int left, int right){
    int mid;
    if (left + 1 < right){
        mid = (left + right) / 2;
        mergeSort(A, n, left, mid);
        mergeSort(A, n, mid, right);
        merge(A, n, left, mid, right);
    }
}

int partition(struct Card A[], int n, int p, int r){
    int i, j;
    struct Card t, x;
    x = A[r];
    i = p - 1;
    for (j=p; j<r; j++){
        if (A[j].value <= x.value) {
            i++;
            t = A[i];
            A[i] = A[j];
            A[j] = t;
        }
    }
    t = A[i+1];
    A[i+1] = A[r];
    A[r] = t;
    return i + 1;
}

void quickSort(struct Card A[], int n, int p, int r){
    int q;
    if (p < r){
        q = partition(A, n, p, r);
        quickSort(A, n, p, q-1);
        quickSort(A, n, q+1, r);
    }
}

int main(){
    int n, i, v;
    struct Card A[MAX], B[MAX];
    char S[10];
    int stable = 1;
    
    scanf("%d", &n);
    
    for (i=0; i<n; i++){
        scanf("%s %d", S, &v);
    A[i].suit = B[i].suit = S[0];
    A[i].value = B[i].value = v;
    }

    mergeSort(A, n, 0, n);
    quickSort(B, n, 0, n-1);

    for (i=0; i<n; i++){
        if (A[i].suit != B[i].suit) stable = 0;
    }

    if (stable == 1) printf("Stable\n");
    else printf("Not stable\n");
    for (i=0; i<n; i++){
        printf("%c %d\n", B[i].suit, B[i].value);
    }

return 0;
}


Measured memory_bytes: 4052
function main(input) {
	// 定義
	input = input.split("\n");
	var a = parseInt(input[0], 10);
	var b = parseInt(input[1], 10);
	var c = parseInt(input[2], 10);
	var d = parseInt(input[3], 10);
	var e = parseInt(input[4], 10);
	var k = parseInt(input[5], 10);
	var ans = "Yay!";
	// 処理
	if (e - a > k) {
		ans = ":(";
	}
	// 出力
	console.log(ans);
}
 main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 7372
#include <iostream>

using namespace std;

int main(void) {
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    if(abs(a-c) <= d) {
        cout << "Yes" << endl;
    } else if(abs(a-b) <= d && abs(b-c) <= d) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String args[]) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        Map<Integer, Integer> map = new HashMap<>();
        for (int i = 0; i < n-1; i++) {
            int val = scanner.nextInt() - 1;
            int count = map.getOrDefault(val, 0);
            map.put(val, ++count);
        }

        for (int i = 0; i < n; i++) {
            System.out.println(map.getOrDefault(i, 0));
        }
    }
}

Measured memory_bytes: 73900
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        try (Scanner sc = new Scanner(System.in)) {
            String s = sc.next();
            int number = 0;
            // 回文の判定
            for (int i = 0, length = s.length(); i < length / 2; ++i) {
                if (s.substring(i, i + 1).equals(s.substring(length - i - 1, length - i))) {
                    continue;
                } else {
                    number++;
                }
            }
            System.out.println(number);
        }
    }

}


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

int main() {
    int n;
    cin >> n;
    pair<int, int> x[n];
    for (int i = 0; i < n; i++) {
        cin >> x[i].first;
        x[i].second = i;
    }
    sort(x, x + n);
    int index[n];
    for (int i = 0; i < n; i++) {
        index[x[i].second] = i;
    }
    for (int i = 0; i < n; i++) {
        if (index[i] < n / 2) {
            cout << x[n / 2].first << ' ';
        } else {
            cout << x[n / 2 - 1].first << ' ';
        }
    }
    return 0;
}

Measured memory_bytes: 4480
#include <bits/stdc++.h>
#define FOR(i, a, b) for(int i = (a);i < (b);++i)
#define FORR(i, b, a) for (int i = (b) - 1;i >= 0;--i)
#define REP(i, n) for(int i = 0;i < (n);++i)
#define REPR(i, n) for(int i = (n) - 1;i >= 0;--i)
#define ITER(itr, v) for(auto itr = v.begin();itr != v.end();++itr)
#define SORT(v) sort(v.begin(), v.end())
#define REV(v) reverse(v.begin(), v.end())
using namespace std;
typedef long long ll;
typedef pair<int, int> P;




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

	int N, M;
	cin >> N >> M;
	vector<P> p(N);
	REP(i, N) {
		cin >> p[i].first >> p[i].second;
	}
	SORT(p);
	priority_queue<int> pq;
	int j = 0;
	int res = 0;
	for (int i = 1;i <= M;++i) {
		while (j < N && p[j].first == i) {
			pq.emplace(p[j].second);
			++j;
		}
		if (!pq.empty()) {
			res += pq.top();
			pq.pop();
		}
	}
	cout << res << endl;

	return 0;
}

Measured memory_bytes: 1660
#if defined(__GNUC__)
#include <bits/stdc++.h>
#define __int32 __int32_t
// __GNUC__
#else
#include "bits/stdc++.h"
#endif
using namespace std;

#define int long long

#define itn __int32
#define REP(i, n) for(itn (i) = 0; (i) < (n); ++(i))
#define REP2(i, x, n) for(itn (i) = x; (i) < (n); ++(i))
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define SORT(x) sort(ALL(x))
#define RSORT(x) sort(ALL(x), greater<decltype(x)::value_type>())
#define RSORT2(x, T) sort(ALL(x), greater<T>())
#define REVERSE(x) reverce(ALL(x))
#define ACM(x, y) accumulate(ALL(x), y)

#define INT_POW(x, y) [](int a, int b) -> int {int c = a; REP(i, b - 1){c *= a;} return c;}(x, y)
#define INT_POWM(x, y, m) [](int a, int b, int m) -> int {int c = a; REP(i, b - 1){c *= a; c %= m;} return c;}(x, y, m)
#define FCT(x) [](int a) -> int {int r = 1; REP(i, a){r *= i;} return r;}(x)

// デバッグ用
#define PUT_LIST(x, y) std::copy(ALL(x), ostream_iterator<decltype(x)::value_type>(cout, y))

const int kMod = 1e9 + 7;

itn main() {
	ios::sync_with_stdio(false);

	int n;
	cin >> n;

	vector<int> a(n);
	vector<int> va(n + 1, 0);

	REP(i, n) {
		cin >> a[i];
		va[a[i]]++;
	}
	
	vector<int> ra(n + 1);

	int all_ptr = 0;

	REP(i, n + 1) {
		ra[i] = va[i] * (va[i] - 1) / 2;
		all_ptr += ra[i];
	}

	REP(i, n) {
		cout << all_ptr - ra[a[i]] + (va[a[i]] - 1) * (va[a[i]] - 2) / 2 << '\n';
	}

	return 0;
}


Measured memory_bytes: 7296
#include <bits/stdc++.h>
using namespace std;
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define lli long long int
#define tc int t;cin>>t;while(t--)
#define all(x) x.begin(),x.end()
#define f first
#define s second
#define pb push_back
#define vi vector<int>
#define vll vector<lli>
#define maxn 1000005
#define mod 1000000007



int main(){
    fastio;
   lli n;
   cin>>n;
   lli a[n];
   for(int i=0;i<n;i++)
   cin>>a[i];
   sort(a,a+n);
   lli sm=a[n-1];
   int rem=n-2;
   for(int i=n-2;i>=0;i--)
   {
       if(rem>=2) rem-=2,sm+=2*a[i];
       else if(rem==1) rem=0,sm+=a[i];
       else break;
   }
   cout<<sm<<"\n";
   return 0;
}



Measured memory_bytes: 5184
#include<bits/stdc++.h>
using namespace std;
long long n,k,cac,j,l;
int main(){
	cin>>n;
	while(n--){
		cac=0;
		cin>>j>>k;
		if(j>k){
			swap(j,k);
		}
		l=sqrtl(j*k-1);
		if(j<=l){
			cac=1;
		}
		if(l*(l+1)<j*k){
			cout<<2*l-cac<<endl;
		}
		else{
			cout<<2*l-cac-1<<endl;
		}
	}
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <deque> 
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cctype> 
using namespace std;

int main(){
    int A, B, C;
    cin >> A >> B >> C;
    if (A==1) {
        cout << "YES" << endl;
        return 0;
    }
    for (int i=1; i<=100; i++) {
        if ((i*A)%B==C) {
            cout << "YES" << endl;
            return 0;
        }
    }
    cout << "NO" << endl;
}

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

data=list(map(int,input().split()))

e=[]
def a(c):
    count=0
    while c%2 == 0:
        c /=2
        count +=1
    return count
for i in data:
    d=a(i)
    e.append(d)
    
print(min(e))

Measured memory_bytes: 3060
# -*- coding: utf-8 -*-
import sys
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
input=lambda: sys.stdin.readline().rstrip()
YesNo=lambda b: bool([print('Yes')] if b else print('No'))
YESNO=lambda b: bool([print('YES')] if b else print('NO'))
int1=lambda x:int(x)-1

def main():
    N,M=map(int,input().split())
    ans=min(M//2,N)
    N-=ans
    M-=ans*2
    ans+=M//4
    print(ans)

if __name__ == '__main__':
    main()


Measured memory_bytes: 38256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,n) for(int i=0;i<n;i++)
#define why(n,x) int n;while(cin >>n,n!=x)
#define iFOR(i,x,n)for(int i=x;i<n;i++)
#define unless(flg) if ( !(flg) )
#define read cin<<
#define echo cout<<
#define fin <<'\n'
#define __ <<" "<<
#define bash push_back
#define alles(x) x.begin(),x.end()
int dx[]={1,0,-1,0,1,1,-1,-1};
int dy[]={0,-1,0,1,-1,1,-1,1};
const int INF=1 << 30;
bool inside(int x,int y,int w,int h){
  return (x>=0 && y>=0 && x<w && y<h);}
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vit;
typedef map<string,int> mstit;
typedef priority_queue<int> pqit;





int main(){
  cin.tie(0), ios::sync_with_stdio(false);
  ll n;
  ll con=0;
  ll now=1;
  cin >>n;

  ll hoge=n/11*2;
  n=n%11;
  if(n>0){
    hoge++;
    n-=6;
  }
  if(n>0){
    hoge++;
    n-=5;
  }
  cout <<hoge fin;
  return 0;
}



Measured memory_bytes: 256
#include<stdio.h>

int main(){
	long int x,y;	//入力される数字
	long int r;		//剰余
	
	//入力
	scanf("%ld %ld",&x,&y);
	
	//yが大きければ入れ替え
	if(x < y){
		int s = x;
		x = y;
		y = s;
	}
	
	//ユークリッドの互除法
	while(y > 0){
		r = x % y;
		x = y;
		y = r;
	}
	
	//出力
	printf("%ld\n",x);
	
	return 0;
}



Measured memory_bytes: 2060
#include<iostream>
#include<vector>

using namespace std;

class DisjointSet {
public:
	vector<int> rank, p;

	DisjointSet(){}
	DisjointSet(int size) {
		rank.resize(size, 0);
		p.resize(size, 0);
		for (int i = 0; i < size; i++)makeSet(i);
	}

	void makeSet(int x) {
		p[x] = x;
		rank[x] = 0;
	}

	bool same(int x, int y) {
		return findSet(x) == findSet(y);
	}

	void unnite(int x, int y) {
		link(findSet(x), findSet(y));
	}

	void link(int x, int y) {
		if (rank[x] > rank[y]) {
			p[y] = x;
		}
		else {
			p[x] = y;
			if (rank[x] == rank[y]) {
				rank[y]++;
			}
		}
	}

	int findSet(int x) {
		if (x != p[x]) {
			p[x] = findSet(p[x]);
		}
		return p[x];
	}
};

int main() {
	int n, a, b, q;
	int t;

	cin >> n >> q;
	DisjointSet ds = DisjointSet(n);

	for (int i = 0; i < q; i++) {
		cin >> t >> a >> b;
		if (t == 0)ds.unnite(a, b);
		else if (t == 1) {
			if (ds.same(a, b))cout << 1 << endl;
			else cout << 0 << endl;
		}
	}

	return 0;
}


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

#define MAXLENGTH 1000

int main(void)
{
  int i,deg=0,count=0;
  char r='R',l='L';
  char st[MAXLENGTH];

  scanf("%s",&st);

  for(i=0;i<strlen(st);i++)
    {
      switch(st[i])
	{
	case 'R':
	  deg+=90;
	  break;
	case 'L':
	  deg-=90;
	  break;
	default:
	  break;
	}
      if(deg==360)
	{
	  count+=1;
	  deg=0;
	}
      else if(deg==-360)
	{
	  deg=0;
	}
    }

    printf("%d\n",count);

}



Measured memory_bytes: 2112
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#define rep(i,n) for(int i=0;i<n;i++)
const long long MOD = 1000000007;
typedef pair<int,int> P;
typedef long long ll;
ll n,m,k,ans;
string s;

int main(){
  int h,w; cin >> h >> w;
  cin >> k;
  string s[h]; rep(i,h) cin >> s[i];
  //まずそれぞれのイチゴのマスに番号をつける
  int num[h][w];
  rep(i,h) rep(j,w) num[i][j] = 0;

  int tmp = 1;
  rep(i,h) rep(j,w){
    if(s[i][j] == '#'){
      num[i][j] = tmp;
      int l = 1;
      while(j+l < w && num[i][j+l] == 0 && s[i][j+l]=='.'){
        num[i][j+l] = num[i][j]; l++;
      }
      l = 1;
      while(j-l >= 0 && num[i][j-l] == 0 && s[i][j-l]=='.'){
        num[i][j-l] = num[i][j]; l++;
      }
      tmp++;
    }
  }
  for(int i = 0; i<h; i++) {
    rep(j,w){
      if(i != n-1 && num[i][j] > 0 && num[i+1][j] == 0){
        int l = 1;
        while(i+l < h && num[i+l][j] == 0) {
          num[i+l][j] = num[i][j]; l++;
        }
      }
      if(i != 0 && num[i][j] > 0 && num[i-1][j] == 0){
        int l = 1;
        while(i-l >= 0 && num[i-l][j] == 0) {
          num[i-l][j] = num[i][j]; l++;
        }
      }
    }
  }
  rep(i,h) {
    rep(j,w){
      cout << num[i][j] << " ";
    }
    cout << "\n";
  }
}

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

#define ll long long
#define mp make_pair
#define pb push_back

#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#define rep(i, n) for (int i = 0; i < (int)(n); ++ i)

const int mxn = 3e5 + 5;
int n, k;

struct SEG {
	static const int sz = 1 << 19;
	int mx[sz << 1];
	void upd(int x, int v) { for (x += sz; x; x >>= 1) mx[x] = max(mx[x], v); }
	int qry(int l, int r) {
		int ans = 0;
		for (l += sz, r += sz; l < r; l >>= 1, r >>= 1) {
			if (l & 1) ans = max(ans, mx[l ++]);
			if (r & 1) ans = max(ans, mx[-- r]);
		}
		return ans;
	}
} seg;

int main() {
	scanf("%d %d", &n, &k);
	rep(i, n) {
		int a;
		scanf("%d", &a);
		seg.upd(a, seg.qry(max(0, a - k), min(mxn, a + k + 1)) + 1);
	}
	printf("%d\n", seg.mx[1]);
	return 0;
}

Measured memory_bytes: 6196