akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define M 100000007
#define ff first.first
#define fs first.second;
typedef pair<int,int> P;
typedef pair<P,int> Pi;
int main(void){
	int c,n,m,s,d;
	while(1){
		cin>>c>>n>>m>>s>>d;
		if(n==0)break;
		vector<P> cost[n+1];
		for(int i=0;i<m;i++){
			int a,b,l;
			cin>>a>>b>>l;
			cost[a].push_back(P(b,l)); cost[b].push_back(P(a,l));
		}
		int leng[c+1][n+1];
		priority_queue<Pi> que;
		for(int i=0;i<=c;i++) fill(leng[i],leng[i]+n+1,M);
		for(int i=0;i<=c;i++) leng[i][s]=0;
		que.push(Pi(P(0,0),s));
		while(!que.empty()){
			Pi p=que.top(); que.pop();
			int v=p.second,w=p.fs;
			if(leng[w][v]<p.ff) continue;
			for(int i=0;i<cost[v].size();i++){
				P x=cost[v][i];
				int t=leng[w][v]+x.second;
				if(leng[w][x.first]>t){
					leng[w][x.first]=t;
					que.push(Pi(P(t,w),x.first));
				}
				t-=x.second/2;
				if(w<c&&leng[w+1][x.first]>t){
					leng[w+1][x.first]=t;
					que.push(Pi(P(t,w+1),x.first));
				}
			}
		}
		int mi=M;
		for(int i=0;i<=c;i++) mi=min(mi,leng[i][d]);
		cout<<mi<<endl;
	}
	return 0;
}


Measured memory_bytes: 3116
#include<stdio.h>
#define N 100000

int main(void)
{
  int n,p,r,k,t,a,count[101];
  int queue[1000000],head=0,tail=0;
  int router[101][101],visited[101],i,j,b;
  
  struct mail{
    int s;
    int d;
    int v;
  }packet[N];
  
  for(i=0;i<101;i++)
    {
      for(j=0;j<101;j++)
	{
	  router[i][j]=0;
	}
    }
  
  scanf("%d",&n);
  
  for(i=1;i<=n;i++)
    {
      scanf("%d%d",&r,&k);
      
      for(j=1;j<=k;j++)
	{
	  scanf("%d",&t);
	  router[r][t]=1;
	}
    }
  
  for(i=1;i<=n;i++)
    {
      router[i][i]=0;
    }
  
  /*
  for(i=1;i<=n;i++)
    {
      for(j=1;j<=n;j++)
	{
	  printf("%d",router[i][j]);
	}
      printf("\n");
    }
  */
  scanf("%d",&p);
  
  for(i=1;i<=p;i++)
    {
      scanf("%d%d%d",&packet[i].s,&packet[i].d,&packet[i].v);
    }
  
  for(i=1;i<=p;i++)
    {
      for(b=0;b<101;b++)
	count[b]=0;

      count[packet[i].s]=1;
      queue[tail++]=packet[i].s;
      
      for(b=0;b<=n;b++)
	visited[b]=0;
	    

      visited[packet[i].s]=1;

      while(head!=tail)
	{
	  
	  a=queue[head++];

	  for(j=1;j<=n;j++)
	    {
	      if(router[a][j]==1 && visited[j]==0)
		{
		  queue[tail++]=j;
		  visited[j]=1;
		  count[j]=count[a]+1;	
		} 
	      
	    }

	}
        if(count[packet[i].d]<=packet[i].v && count[packet[i].d]!=0)printf("%d\n",count[packet[i].d]);
	else printf("NA\n");
		  
    }
  return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
#include<string>
#define pii pair<int, int>
#define mp make_pair
#define ll long long
#define ld long double
#define pb push_back
#define S second
#define F first
using namespace std;



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

	int l, d, r;
	cin >> l >> r >> d;
	int ans = 0;
	for (int i = l; i <= r; i++) {
		if (i % d == 0) ans++;
	}

	cout << ans << '\n';

}

Measured memory_bytes: 3604
import sys

S = input()

cnt = 0
for s in S:
    if cnt % 2 == 0:
        if s == 'L':
            print('No')
            sys.exit()
    if cnt % 2 != 0:
        if s == 'R':
            print('No')
            sys.exit()
    cnt += 1

print('Yes')

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

using ll = long long;
using Vi = vector<int>;
using Vl = vector<ll>;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

constexpr int I_INF = numeric_limits<int>::max();
constexpr ll L_INF = numeric_limits<ll>::max();

//==================================

class UnionFind {
    using i64 = std::int64_t;

private:
    std::vector<i64> par;
    std::vector<i64> sz;

public:
    UnionFind(i64 N) : par(N), sz(N, 1) {
        for (i64 i = 0; i < N; ++i) par[i] = i;
    }
    i64 root(i64 x) {
        return par[x] == x ? x : par[x] = root(par[x]);
    }
    bool same(i64 x, i64 y) {
        return root(x) == root(y);
    }
    void unite(i64 x, i64 y) {
        x = root(x);
        y = root(y);
        if (x == y) return;
        if (sz[x] < sz[y]) std::swap(x, y);
        par[y] = x;
        sz[x] += sz[y];
    }
    i64 size(i64 x) {
        return sz[root(x)];
    }
    void reset(i64 N) {
        par.resize(N);
        for (i64 i = 0; i < N; ++i) par[i] = i;
        sz.assign(N, 1);
    }
};

int main() {
#ifdef FASTIO
    cin.tie(0), cout.tie(0);
    ios::sync_with_stdio(false);
#endif
#ifdef FILEINPUT
    ifstream ifs("./in_out/input.txt");
    cin.rdbuf(ifs.rdbuf());
#endif

    ll N, M;
    cin >> N >> M;
    Vl P(N);
    for (ll i = 0; i < N; i++) {
        cin >> P[i];
        --P[i];
    }

    UnionFind uf(N);

    for (ll i = 0; i < M; i++) {
        int x, y;
        cin >> x >> y;
        --x, --y;
        uf.unite(x, y);
    }

    unordered_map<ll, Vl> group;
    for (ll i = 0; i < N; i++) {
        group[uf.root(i)].emplace_back(i);
    }

    ll ans = 0;
    for (const auto& g : group) {
        for (const auto& val : g.second) {
            if (binary_search(g.second.begin(), g.second.end(), P[val])) {
                ++ans;
            }
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 11428
#include <bits/stdc++.h>
using namespace std;
#define ll long long
string s1 , s2;
int dp[3000][3000];
int cal( int i = 0 , int j = 0 )
{
    if( i == s1.size() || j == s2.size() ) return 0;
    return dp[i][j] = ( dp[i][j] != -1 ? dp[i][j] : ( s1[i] == s2[j] ? cal( i+1 , j+1 ) + 1 : max( cal( i+1 , j ) , cal( i , j+1 ) ) ) );
}
void print()
{
    int i = 0 , j = 0;
    while( i < s1.size() && j < s2.size() )
    {
        if( s1[i] == s2[j] )
        {
            cout << s1[i]; ++i,++j;
        }
        else
            {
                if( dp[i+1][j] > dp[i][j+1] )
                    ++i;
                else
                    ++j;
            }
    } 
}
int main()
{
    memset(dp,-1,sizeof dp);
    cin >> s1 >> s2;
    cal();
    print();
    return 0;
}


Measured memory_bytes: 35712
N = int(input())
A, B = map(int, input().split())

a = list(map(int, input().split()))
first = 0
second = 0
third = 0

for x in a:
  if x <= A:
    first += 1
  elif x > B:
    third += 1
  else:
    second += 1

print(min(first, second, third))

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
const long inf = 1e18;
int n;
int h[5000];
int p[5000];
long dp[5001];
int main() {
  cin >> n;
  for (int i = 0; i < n; ++i) cin >> h[i] >> p[i];
  vector<int> ord(n);
  iota(ord.begin(), ord.end(), 0);
  sort(ord.begin(), ord.end(), [](int i , int j) {
    return h[i] + p[i] < h[j] + p[j];
  });
  
  for (int i = 0; i <= n; ++i) dp[i] = inf;
  dp[0] = 0;
  for (int i : ord) {
    for (int k = n; k > 0; --k) {
      if (dp[k - 1] <= h[i]) {
        dp[k] = min(dp[k], dp[k - 1] + p[i]);
      }
    }
  }
  
  int ans;
  for (int k = n; k >= 0; --k) {
    if (dp[k] != inf) {
      ans = k;
      break;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <utility>

class UnionFind{ //連結判定
private:
    std::vector<int> parent; //parent[i] = parent of node i
    std::vector<int> rank;
    std::vector<int> size;
public:
    //constructor
    UnionFind(int N){
        for(int i=0; i<N; i++) parent.push_back(i); //parent = [0,1,..,N-1]
        for(int i=0; i<N; i++) rank.push_back(0); //rank = [0,0,..,0]
        for(int i=0; i<N; i++) size.push_back(1);
    }
    //initialize
    void init(int N){
        parent.clear();
        rank.clear();
        size.clear();
        for(int i=0; i<N; i++) parent.push_back(i); //parent = [0,1,..,N-1]
        for(int i=0; i<N; i++) rank.push_back(0); //rank = [0,0,..,0]
        for(int i=0; i<N; i++) size.push_back(1);
    }
    int root(int a){
        if(parent[a] == a) return a;
        return parent[a] = root(parent[a]); //親が自分自身になるまで再帰を呼び出す & 経路圧縮 
    }
    void unite(int a, int b){
        int rootA = root(a);
        int rootB = root(b);
        if(rootA == rootB) return; //ノードa, bがすでに連結しているとき
        //次数の大きい方を親として連結
        if(rank[rootA] < rank[rootB]){
            size[root(b)] += size[root(a)];
            parent[rootA] = rootB;
        }
        else{
            size[root(a)] += size[root(b)];
            parent[rootB] = rootA;
            if(rank[rootA] == rank[rootB]) rank[rootA]++;
        }
    }
    bool same(int a, int b){
        return root(a) == root(b); //ノードa, bが同じ木に属するかどうか
    }
    int get_size(int a){
        return size[root(a)];
    }
};

int main()
{
    long long N, M;
    std::cin >> N >> M;
    std::vector<std::pair<int, int> > edge;
    edge.resize(M);
    for(int i=0; i<M; i++){
        scanf(" %d %d", &(edge[i].first), &(edge[i].second));
        edge[i].first--;
        edge[i].second--;
    }
    
    /*
    std::vector<std::pair<int, int> > node_pair;
    for(int i=0; i<N-1; i++){
        for(int j=i+1; j<N; j++)
            node_pair.emplace_back(i, j);
    }
    */
    UnionFind uf(N);
    std::vector<int> node;
    for(int i=0; i<N; i++) node.push_back(i);
    std::vector<long long> score;
    score.push_back(N*(N-1)/2);
    //uf.unite(edge[M-1].first, edge[M-1].second);
    /*
    for(int i=1; i<M; i++){
        for(auto &&itr = node_pair.begin(); itr != node_pair.end(); ){
            if(uf.same(itr->first, itr->second)) itr = node_pair.erase(itr);
            else itr++;
        }
        score.push_back(node_pair.size());
        uf.unite(edge[M-1-i].first, edge[M-1-i].second);
    }
    */
    for(int i=1; i<M; i++){
        long long s = score[i-1];
        long long ds = uf.get_size(edge[M-i].first) * uf.get_size(edge[M-i].second);
        bool flag = uf.same(edge[M-i].first, edge[M-i].second);
        if(!flag) s -= ds;
        score.push_back(s);
        uf.unite(edge[M-i].first, edge[M-i].second);
    }

    for(int i=score.size()-1; i>=0; i--)
        printf("%lld\n", score[i]);
}

Measured memory_bytes: 4596
N, M = map(int, input().split())
As = list(map(int, input().split()))
def f(l):
    b, c = l
    return c
cards =[list(map(int, input().split())) for _ in range(M)]
cards.sort(key = f)
cnt = 0
while cards and cnt <= N:
    b, c = cards.pop()
    As += [c]*b
    cnt += b
As.sort(reverse = True)
print(sum(As[:N]))

Measured memory_bytes: 34756
#include<iostream>
#include<vector>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<queue>
#include<deque>
#include<map>
#include<bitset>
using namespace std;

typedef long long ll;
#define rep(i, n) for(int i = 0;i < (n);i++)
#define repr(i, n) for(int i = (n);i >= 0;i--)
#define repf(i, m, n) for(int i = (m);i < (n);i++)
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 dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};
//////////////////////////////////////////////////

// A:1, C:2, G:3, T:4
// dp[桁][3文字前][2文字前][1文字前]
ll dp[110][5][5][5];

int main() {
    int n; cin >> n;
    memset(dp, 0, sizeof(dp));
    dp[0][0][0][0] = 1;

    map<char, int> m;
    m['A'] = 1;
    m['C'] = 2;
    m['G'] = 3;
    m['T'] = 4;

    ll mod = 1e9+7;

    rep(i,n) {
        rep(j,5) rep(k,5) rep(l,5) repf(p,1,5) {
            // *AGT
            if (k == m['A'] && l == m['G'] && p == m['T']) continue;
            // *ATG
            if (k == m['A'] && l == m['T'] && p == m['G']) continue;
            // *GAT
            if (k == m['G'] && l == m['A'] && p == m['T']) continue;
            // A*GT
            if (j == m['A'] && l == m['G'] && p == m['T']) continue;
            // AG*T
            if (j == m['A'] && k == m['G'] && p == m['T']) continue;

            (dp[i+1][k][l][p] += dp[i][j][k][l]) %= mod;
        }
    }

    ll ans = 0;
    repf(i,1,5) repf(j,1,5) repf(k,1,5) {
        (ans += dp[n][i][j][k]) %= mod;
    }
    cout << ans << endl;
    return 0;
}

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

int main(){
  int N, X;
  cin >> N >> X;
  
  vector<int> m(N);
  for(int i=0; i<N; i++) cin >> m.at(i);
  
  int cnt = 0;
  int m_sum = 0;
  for(int a: m){
    m_sum += a;
    cnt++;
  }
  X -= m_sum;
  sort(m.begin(),m.end());
  cnt += X / m.at(0);
  cout << cnt << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define MP(a, b)  make_pair(a, b)

typedef pair<int, int> pii;

int main(){
    int n , m;
    string s = "";
    char c;
    for (int i = 0; i < 3; ++i) {
        for (int j = 0; j < 3; ++j) {
            cin >> c;
            if(i == j)s += c;
        }
    }
    cout << s  << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.*;

class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int L = sc.nextInt();
		int R = sc.nextInt();
		int d = sc.nextInt();
		sc.close();
		int ans = 0;
		for(int i=L;i<=R;++i){
			if(i%d == 0){
				ans++;
			}
		}
		System.out.println(ans);
	}
}


Measured memory_bytes: 35536
#include<bits/stdc++.h>
#define rep(i,n) for(int i = 0;i<n;i++)
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0;}

ll n,m;

bool isok(vector<ll>& a,ll x) {
    ll sum = 0;
    rep(i,n) {
        sum += n - (lower_bound(a.begin(),a.end(),x-a[i]) - a.begin());
    }
    return sum >= m;
}



int main() {
    cin >> n >> m;
    vector<ll>a(n);
    rep(i,n) cin >> a[i];
    vector<ll>s(n+1);
    sort(a.begin(),a.end());
    rep(i,n) {
        s[i+1] = s[i] + a[i];
    }
    ll ok = 0;ll ng = 200010;
    while(ng - ok > 1) {
        ll mid = (ok+ng)/2;
        if(isok(a,mid)) ok = mid;
        else ng = mid;
    }
    // cout << ok << endl;
    ll ans = 0;
    ll cnt = m;
    rep(i,n) {
        ll pos = (lower_bound(a.begin(),a.end(),ok-a[i])-a.begin());
        // cout << pos << endl;
        ans += a[i] * (n- pos);
        ans += s[n] - s[pos];
        cnt -= (n-pos);
    }
    // cout << cnt << endl;
    ans += cnt*ok;
    cout << ans << endl;
}

    




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

#define int long long

const int N = 5e3 + 10;

int n , k , p[N] , w[N] , vis[N] , ans = -1e18 , upd , Rt;
int dpe[N] , siz[N] , sum[N] , cnt;

void dfs(int u){
	if(vis[u]) return;
	vis[u] = true , dpe[u] = cnt;
	siz[cnt]++ , sum[cnt] += w[u] , dfs(p[u]);
}

void Updata(int u , int step){
	if(step == 0) return;
	upd += w[p[u]] , Rt = max(Rt , upd);
	Updata(p[u] , step - 1);
}

signed main(){
	scanf("%lld %lld" , &n , &k);
	for(int i = 1; i <= n; i++) scanf("%lld" , &p[i]);
	for(int i = 1; i <= n; i++) scanf("%lld" , &w[i]);
	for(int i = 1; i <= n; i++) if(!vis[i]) cnt++ , dfs(i);
	for(int i = 1; i <= n; i++){
		int step = k % siz[dpe[i]] , Re = k / siz[dpe[i]];
		if(Re) step += siz[dpe[i]] , Re--;
		upd = 0 , Rt = -1e18 , Updata(i , step);
		ans = max(ans , max(Rt , Rt + sum[dpe[i]] * Re));
	}
	printf("%lld" , ans);
	return 0;
}

Measured memory_bytes: 3956
#include <iostream>
#include <algorithm>
#include <limits>
#include <vector>
#include <map>
#include <cmath>
#include <limits>
#include <iomanip>
#include <queue>
#include <string.h>
#include <bitset>

#define ll long long int
#define ld long double
#define rep(i,n) for(int i = 0;i < n;i++)
#define rep1(i,n) for(int i = 1;i < n;i++)
#define co(x) cout << x << endl
#define cosp(x) cout << x << " "
#define all(x) x.begin(),x.end()
#define allr(x) x.begin(),x.end(),greater<int>()
#define P pair<ll,ll>
#define pb push_back
#define mp make_pair
#define MOD 1000000007
#define INF 1ll << 60
#define PI 3.14159265359

using namespace std;

int main(){
	ll a,b,k;
	cin >> a >> b >> k;
	if(a-k >= 0){
		cout << a-k << " " << b << endl;
	}
	else if(b-(k-a) >= 0){
		cout << 0 << " " << b-(k-a) << endl;
	}
	else{
		cout << 0 << " " << 0 << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <cmath>
#include <climits>
#include <iomanip>
#include <set>
#include <map>
using namespace std;
typedef long long ll;
int main(){
  ll s,c;
  cin >> s >> c;
  ll res = 0;
  if(c / 2 <= s){
    res = c / 2;
  }
  else{
    res += s;
    c -= s * 2;
    res += c / 4;
  }
  cout << res << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using vb=vector<bool>;
using vvb=vector<vb>;
using pii = pair<int,int>;
using pli = pair<ll,int>;
using pll = pair<ll,ll>;
using vpii = vector<pii>;
using vpli = vector<pli>;
using vpll = vector<pll>;

#define rep(i, n) for(int i=0;i<(int)n;i++)
#define rep2(i, s, n) for(int i=(s);i<(int)n;i++)
int INF=1e9+7;

vvi d;
vi r;
int R,ans=INF;
vb used;

void dfs(int sum,int last,int num) {
  if(num==R) {
    ans=min(ans,sum);
    return;
  }
  rep(i,R) {
    if(used[i]) continue;
    used[i]=true;
    if(last==-1) dfs(0,i,1);
    else dfs(sum+d[r[last]][r[i]],i,num+1);
    used[i]=false;
  }
}

int main() {
  int N,M;
  cin >> N >> M >> R;
  r=vi(R);
  rep(i,R) {
    cin >> r[i];
    r[i]--;
  }
  vi A(M),B(M),C(M);
  d=vvi(N,vi(N,INF));
  rep(i,N) d[i][i]=0;
  rep(i,M) {
    cin >> A[i] >> B[i] >> C[i];
    A[i]--;B[i]--;
    d[A[i]][B[i]]=C[i];
    d[B[i]][A[i]]=C[i];
  }
  
  rep(i,N) {
    rep(j,N-1) {
      rep2(k,j+1,N) {
        d[j][k]=min(d[j][k],d[j][i]+d[i][k]);
        d[k][j]=min(d[j][k],d[j][i]+d[i][k]);
      }
    }
  }
  
  used=vb(R);
  dfs(0,-1,0);
  
  cout << ans << endl;
}

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

#define rep(i,x,y) for(int i=(x);i<(y);++i)
#define debug(x) #x << "=" << (x)

#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define show(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define show(x)
#endif

typedef long long int ll;
typedef pair<int,int> pii;
template<typename T> using vec=std::vector<T>;

const int inf=1<<30;
const long long int infll=1LL<<62;
const double eps=1e-9;
const int dx[]={1,0,-1,0},dy[]={0,1,0,-1};

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){
    os << "[";
    for (const auto &v : vec) {
        os << v << ",";
    }
    os << "]";
    return os;
}

void solve(){
    int n,m;
    cin >> n >> m;
    typedef tuple<int,int,int> tup;
    vector<unordered_map<int,vector<tup>>> graph(n);
    rep(i,0,m){
        int p,q,c;
        cin >> p >> q >> c;
        --p;
        --q;
        graph[p][0].push_back(make_tuple(p,c,1));
        graph[p][c].push_back(make_tuple(p,0,0));
        graph[q][0].push_back(make_tuple(q,c,1));
        graph[q][c].push_back(make_tuple(q,0,0));
        graph[p][c].push_back(make_tuple(q,c,0));
        graph[q][c].push_back(make_tuple(p,c,0));
    }

    vector<unordered_map<int,int>> dist(n);
    queue<pii> ques[2];
    int d=0;
    dist[0][0]=0;
    ques[0].push(make_pair(0,0));
    for(;;){
        auto &curr=ques[d%2],&next=ques[(d+1)%2];
        if(curr.empty()) break;
        while(!curr.empty()){
            pii p=curr.front();
            curr.pop();
            int v=p.first,r=p.second;
            if(v==n-1 and r==0){
                cout << d << endl;
                return;
            }
            for(tup &edge:graph[v][r]){
                int v_=get<0>(edge),r_=get<1>(edge),c=get<2>(edge);
                if(dist[v_].find(r_)!=dist[v_].end() and dist[v_][r_]<=d+c) continue;
                dist[v_][r_]=d+c;
                if(c==0) curr.push(make_pair(v_,r_));
                else next.push(make_pair(v_,r_));
            }
        }
        ++d;
    }
    cout << -1 << endl;
}

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


Measured memory_bytes: 81408
#include <bits/stdc++.h>
#include <algorithm>
#include <iostream>
#include <string>
using namespace std;
#define rep(i,n) for (ll i=0;i<(n);i++)
typedef long long ll;
bool aaa[11111111];
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
ll gcd(ll a, ll b) {
  if(a < b) return gcd(b, a);
  unsigned r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}

 
int main() {
  ll n,c,aan,m,w=0,memo=0,sx=0,sy=1,ans=0,gx,gy;
  string ka,ss;
  bool flag=true,flag1=false;
  cin>>n;
  vector<int> yoko(n);
  rep(i,n)cin>>yoko[i];
  sort(yoko.begin(),yoko.end());
  rep(i,n-2){
    rep(j,n-i-1){
      if(yoko[i]==yoko[i+j+1])continue;
      rep(k,n-i-j-2){
        if(yoko[i+j+1]==yoko[i+j+k+2])continue;
        if(yoko[i+j+1]+yoko[i]>yoko[i+j+k+2])memo++;
      }
    }

  }
  cout<<memo<<endl;
}

Measured memory_bytes: 3632
/* ex7_3
  */

#include <stdio.h>
#include <stdlib.h>

int main(void){
    int height, width; //変数の定義
    int i, j;
    char **ptr; //入力の表を記憶する二次元配列
    int *row ,*col;


    scanf("%d%d", &height, &width);

    ptr = (char**)calloc(height, sizeof(char*));
    if(ptr == NULL){
        exit(1);
    }
    for(i = 0; i < height; i++){
        ptr[i] = (char*)calloc(width+1, sizeof(char));
        if(ptr[i] == NULL){
            exit(1);
        }
    }


    for(i=0; i<height; i++){ //入力の表を二次元配列に記憶
        for(j=0; j<width+1; j++){
            scanf("%c", &ptr[i][j]);
        }
    }

    row = (int*)calloc(height, sizeof(int));
    if(row ==NULL){
        exit(1);
    }

    col = (int*)calloc(width, sizeof(int));
    if(col ==NULL){
        exit(1);
    }


    for(i=0; i<height; i++){ //二次元配列を全探索して、#がある行、列を記憶
        for(j=0; j<width+1; j++){
            if (ptr[i][j] == '#'){
                row[i] = 1;
                col[j] = 1;
            }
        }
    }
    for(i=0; i<height; i++){
        if(row[i] == 1){ //i番目の行に#が含まれている
            for(j=0; j<width+1; j++){
                if(col[j] == 1){ //j番目の列にも#が含まれている
                    printf("%c", ptr[i][j]);//出力
                }
            }
            printf("\n"); //一行出力したら改行
        }
    }

    for(i = 0; i < height; i++){
        free(ptr[i]);
    }
    free(ptr);

   
        free(row);
        free(col);
    

    return 0;
}


Measured memory_bytes: 1676
import bisect

_n = input()
ls = list(sorted(map(int, input().strip().split())))
total = 0

for i in range(len(ls) - 2):
    for j in range(i + 1, len(ls) - 1):
        a = ls[i]
        b = ls[j]
        left = j + 1
        num = bisect.bisect_left(ls, a + b) - left
        total += num

print(total)




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

int main(void){
  while(1){
    int H;
    int stone[10][5]; /* stone[???][?¨?] */

    int score = 0;

    cin >> H;
    if(H == 0){return 0;}

    for(int i = 0 ; i < H ; i++){
      for(int j = 0 ; j < 5 ; j++){
        cin >> stone[i][j];
      }
    }

    /* ?¶?????????¨??????????????? */
    bool flg = true;
    while(flg == true){

      flg = false;
      for(int i = 0 ; i < H ; i++ ){
        for(int j = 0 ; j < 3 ; j++){
          int count = 1;
          int tempcolor = stone[i][j];

          for(int k = 1 ; k + j < 5 ; k++){
            if(stone[i][j+k] == tempcolor && tempcolor != -1 && tempcolor != 0){
              count++;
            }else{
              break;
            }
          }

          if(count >= 3){
            score += tempcolor * count;

            for(int k = 0 ; k < count ; k++){
              stone[i][j+k] = -1;
              flg = true;
            }
          }

        }
      }

      /* ?¶??????????????????¨??? */


      for(int i = H-1 ; i >= 0 ; i-- ){
        for(int j = 0 ; j < 5 ; j++){
          while(stone[i][j] == -1){
            for(int k = i ; k > 0 ; k--){
              stone[k][j] = stone[k-1][j];
            }
           stone[0][j] = 0;
          }
        }
      }
    }
    cout << score << endl;
  }
}

Measured memory_bytes: 3068
class UnionFindTree():
    def __init__(self, n):
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return
        
        # 常にxの要素数＞yの要素数とする
        if self.parents[x] > self.parents[y]:
            x, y = y, x
            
        # self.parents[x] に　yの要素数を追加してから併合
        self.parents[x] += self.parents[y]
        self.parents[y] = x
  
N, M = map(int, input().split())
uft = UnionFindTree(N)
for m in range(M):
  a, b = map(lambda x: int(x)-1, input().split())
  uft.union(a, b)
  
print(-min(uft.parents))

Measured memory_bytes: 14800
#include <stdio.h>
#include <iostream>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <math.h>
#include <algorithm>
using namespace std;
#define ll long long
const double EPS = 1e-10;
const ll MOD = 7+(1e+9);

int main (){
  ll n;
  cin>>n;
  vector<ll>v(5,0);
  ll m=0;
  for(ll i=0;i<5;i++){
    cin>>v[i];
    if(v[m]>v[i]){
      m=i;
    }
  }
  ll ans=4+n/v[m]+(n%v[m]!=0?1:0);
  cout<<ans<<endl;
}


Measured memory_bytes: 256
import java.util.*;
import java.io.*;
import java.lang.reflect.Array;
import java.math.BigInteger;

import static java.lang.Math.*;
import static java.util.Arrays.*;
import static java.util.Collections.*;
 
public class Main{
    static long mod=1000000007;
//    static int dx[]={-1,0,1,0};
//    static int dy[]={0,-1,0,1};

    public  static void main(String[] args)   throws Exception, IOException{        
        Reader sc = new Reader(System.in);
        PrintWriter out=new PrintWriter(System.out);

        int n=sc.nextInt();
        P p[]=new P[n];

        for (int i = 0; i < p.length; i++) {
        	String s=sc.nextString();
        	p[i]=new P(i+1, sc.nextInt(),s);
        }
        sort(p);
        for (int i = 0; i < p.length; i++) {
            out.println(p[i].id);
		}
//        out.println();
        out.flush();
    }
    



    static boolean validpos(int x,int y,int r, int c){
        return x<r && 0<=x && y<c && 0<=y;
    }

    static void db(Object... os){
        System.err.println(Arrays.deepToString(os));
    }  
}

//class P {
//    int id, d;
//    P(int  id, int d) {
//        this.id=id;
//        this.d=d;
//    }
//}

class P implements Comparable<P>{
	int v,id;
	String s;
	P(int id, int v, String s) {
	  this.id=id;
	  this.v=v;
	  this.s=s;
	}
	public int compareTo(P p){			
	 if(s.equals(p.s)) {
		 return -v+p.v;
	 }
	  return s.compareTo(p.s);
	}
}

class Reader
{ 
    private BufferedReader x;
    private StringTokenizer st;
    
    public Reader(InputStream in)
    {
        x = new BufferedReader(new InputStreamReader(in));
        st = null;
    }
    public String nextString() throws IOException
    {
        while( st==null || !st.hasMoreTokens() )
            st = new StringTokenizer(x.readLine());
        return st.nextToken();
    }
    public int nextInt() throws IOException
    {
        return Integer.parseInt(nextString());
    }
    public int[] nextIntArray(int size) throws IOException{
    	int r[] = new int[size];
    	for (int i = 0; i < size; i++) {
			r[i] = this.nextInt(); 
		}
    	return r;
    }
    public long[] nextLongArray(int size) throws IOException{
    	long r[] = new long[size];
    	for (int i = 0; i < size; i++) {
			r[i] = this.nextLong(); 
		}
    	return r;
    }
    public long nextLong() throws IOException
    {
        return Long.parseLong(nextString());
    }
    public double nextDouble() throws IOException
    {
        return Double.parseDouble(nextString());
    }
}


Measured memory_bytes: 22996
#include<bits/stdc++.h>
using namespace std;
#define reg register
#define ll long long
inline ll read()
{
	ll x=0,w=0;char ch=getchar();
	while(!isdigit(ch))w|=ch=='-',ch=getchar();
	while(isdigit(ch))x=(x<<3)+(x<<1)+(ch^48),ch=getchar();
	return w?-x:x;
}
ll n,m,ans=1e15;
ll a[100005],b[100005];
int main()
{
    n=read(),m=read();reg int i;
    for(i=1;i<=n;++i)a[i]=read();
    for(i=2;i<=n;++i)
    {
        if(a[i]<a[i-1])
        {
            b[a[i-1]+2]--;b[1]+=a[i],b[2]-=a[i];b[2]--;b[a[i]+2]++;b[a[i]+1]+=m-a[i-1]+a[i];b[a[i]+2]-=m-a[i-1]+a[i];
        }
        else
        {
            b[1]+=a[i]-a[i-1],b[2]-=a[i]-a[i-1];b[a[i-1]+2]--;b[a[i]+2]++;b[a[i]+1]+=a[i]-a[i-1];b[a[i]+2]-=a[i]-a[i-1];
        }
    }
    for(i=1;i<=m;++i)b[i]+=b[i-1];for(i=1;i<=m;++i)b[i]+=b[i-1];
    for(i=1;i<=m;++i)ans=min(ans,b[i]);cout<<ans<<"\n";
	return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <vector>
#include <functional>
#include <limits>

template <class Data, class Operator>
class LazySegmentTree {
    using DataMerger = std::function<Data(Data, Data)>;
    using OperatorMerger = std::function<Operator(Operator, Operator)>;
    using Applier = std::function<Data(Data, Operator, int)>;

public:
    int length;
    std::vector<Data> dat;
    std::vector<Operator> ope;
    Data dat_id;
    Operator ope_id;
    DataMerger datm;
    OperatorMerger opem;
    Applier app;

    explicit LazySegmentTree(int N, Data dat_id, Operator ope_id, DataMerger datm, OperatorMerger opem, Applier app)
        : length(1), dat_id(dat_id), ope_id(ope_id), datm(datm), opem(opem), app(app) {
        while (length < N) length *= 2;
        dat.assign(length * 2, dat_id);
        ope.assign(length * 2, ope_id);
    }

    void eval(int nidx, int len) {
        if (ope[nidx] == ope_id) return;
        // 子に作用素を伝播
        if (nidx * 2 + 1 < length * 2) {
            ope[nidx * 2] = opem(ope[nidx * 2], ope[nidx]);
            ope[nidx * 2 + 1] = opem(ope[nidx * 2 + 1], ope[nidx]);
        }
        // 値に作用素を反映
        dat[nidx] = app(dat[nidx], ope[nidx], len);
        ope[nidx] = ope_id;
    }

    // half-open interval [ql, qr)
    Data update(int ql, int qr, Operator e) { return update(ql, qr, e, 1, 0, length); }
    Data update(int ql, int qr, Operator e, int nidx, int nl, int nr) {
        eval(nidx, nr - nl);
        if (nr <= ql || qr <= nl) return dat[nidx];
        if (ql <= nl && nr <= qr) {
            ope[nidx] = opem(ope[nidx], e);
            return app(dat[nidx], ope[nidx], nr - nl);
        }
        // 子を再帰的に更新
        Data vl = update(ql, qr, e, nidx * 2, nl, (nl + nr) / 2);
        Data vr = update(ql, qr, e, nidx * 2 + 1, (nl + nr) / 2, nr);
        // 子の更新後から値を更新
        return dat[nidx] = datm(vl, vr);
    }

    // half-open interval [ql, qr)
    Data query(int ql, int qr) { return query(ql, qr, 1, 0, length); }
    Data query(int ql, int qr, int nidx, int nl, int nr) {
        eval(nidx, nr - nl);
        if (nr <= ql || qr <= nl) return dat_id;
        if (ql <= nl && nr <= qr) return dat[nidx];
        Data vl = query(ql, qr, nidx * 2, nl, (nl + nr) / 2);
        Data vr = query(ql, qr, nidx * 2 + 1, (nl + nr) / 2, nr);
        return datm(vl, vr);
    }
};

const int INF = std::numeric_limits<int>::max();

int main() {
    int N, Q;
    std::cin >> N >> Q;
    LazySegmentTree<int, int> seg(N, INF, 0,
                                  [](int a, int b) { return std::min(a, b); },
                                  [](int e, int f) { return e + f; },
                                  [](int a, int e, int k) { return a + e; });
    seg.update(0, N, -INF);

    for (int q = 0; q < Q; ++q) {
        int k;
        std::cin >> k;
        if (k == 0) {
            int l, r, x;
            std::cin >> l >> r >> x;
            seg.update(l, r + 1, x);
        } else {
            int l, r;
            std::cin >> l >> r;
            std::cout << seg.query(l, r + 1) << std::endl;
        }
    }
    return 0;
}



Measured memory_bytes: 4940
use std::collections::HashMap;

fn main() {
    proconio::input! {
        h: i64,
        w: i64,
        n: usize,
        black: [(i64, i64); n]
    }
    let mut cnt = HashMap::new();
    for &p in &black {
        for dx in -1..=1 {
            if p.0+dx <= 1 || h <= p.0+dx { continue }
            for dy in -1..=1 {
                if p.1+dy <= 1 || w <= p.1+dy { continue }
                let pt = (p.0+dx, p.1+dy);
                if let Some(c) = cnt.get(&pt) {
                    cnt.insert(pt, c+1);
                } else {
                    cnt.insert(pt, 1);
                }
            }
        }
    }
    let mut res = vec![0; 10];
    res[0] = (h-2)*(w-2);
    for (_, &value) in &cnt {
        res[0] -= 1;
        res[value as usize] += 1;
    }
    for &t in &res { println!("{}", t) }
}


Measured memory_bytes: 43860
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0;i<n;i++)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOR(i,m,n) for(int i=m;i<n;i++)
#define ALL(a) a.begin(),a.end()
int main()
{
    int K,X;
    cin >> K >> X;
    if(500*K >= X)cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

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

using namespace std;

int main(){
int N,K; cin >> N >> K;
  long double ans = 0.0;
  for(int i = 1; i <= N; i++){
   //まず初めに出たサイコロの目
    int cnt = 0; int c = i;
    while( c < K){ c *= 2; cnt++;}
    //cnt　は何回コインの表が出る必要があったのかを記録
    // ans に 2の - cnt乗をたす
  
    ans += 1 / pow( 2.0, cnt);
  }
  
  cout << fixed << setprecision(10) << ans/ N << endl; return 0;}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
template<class T> using vc = vector<T>;
template<class T> using vvc = vector<vector<T>>;

#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define repr(i, n) for (ll i = (n)-1; i >= 0; i--)
#define repe(i, l, r) for (ll i = (l); i < (r); i++)
#define reper(i, l, r) for (ll i = (r)-1; i >= (l); i--)
#define repa(i,n) for (auto& i: n)

template<class T> inline bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> inline bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
void init() {cin.tie(0);ios::sync_with_stdio(false);cout << fixed << setprecision(15);}

#ifdef DEBUG
template <class T, class N> void verr(const T& a, const N& n) { rep(i, n) cerr << a[i] << " "; cerr << "\n" << flush; }
ll dbgt = 1; void err() { cerr << "passed " << dbgt++ << "\n" << flush; }
template<class H, class... T> void err(H&& h,T&&... t){ cerr<< h << (sizeof...(t)?" ":"\n") << flush; if(sizeof...(t)>0) err(forward<T>(t)...); }
#endif

const ll INF = 5e18;
const ld EPS = 1e-11;
const ld PI = acos(-1.0L);
const ll MOD = 1e9 + 7;
// const ll MOD = 998244353;
//--------------------------------------------------------------------------------//

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

    ll ans = 0;
    ans += min(A, K);
    K -= A;
    K -= B;
    if (K > 0) ans -= K;

    cout << ans << endl;
}

Measured memory_bytes: 3640
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.List;
import java.util.Map;
import java.util.Scanner;
import java.util.HashMap;
import java.util.ArrayList;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main
{
    public static void main(String[] args)
    {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskG solver = new TaskG();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskG
    {
        public void solve(int testNumber, Scanner in, PrintWriter out)
        {
            int N = in.nextInt(); // nodes
            int E = in.nextInt(); // edges
            Map<Integer, List<Integer>> graph = new HashMap<>();
            populateGraph(graph, in, E);
            int longestPath = getLongestPathFrom(graph);
            out.print(longestPath);
        }

        private int getLongestPathFrom(Map<Integer, List<Integer>> graph)
        {
            Map<Integer, Integer> memo = new HashMap<>();
            int longestPath = -1;
            for (int node : graph.keySet())
            {
                longestPath = Math.max(longestPath, getLongestPathFrom(node, graph, memo));
            }
            return longestPath;
        }

        private int getLongestPathFrom(int node, Map<Integer, List<Integer>> graph, Map<Integer, Integer> memo)
        {
            if (memo.containsKey(node)) return memo.get(node);

            List<Integer> neighbours = graph.get(node);
            int longestPath = 0;
            for (int n : neighbours)
            {
                if (!memo.containsKey(n))
                    longestPath = Math.max(longestPath, 1 + getLongestPathFrom(n, graph, memo));
                else
                    longestPath = Math.max(longestPath, 1 + memo.get(n));
            }
            memo.put(node, longestPath);
            return longestPath;
        }

        private void populateGraph(Map<Integer, List<Integer>> graph, Scanner in, int e)
        {
            for (int i = 0; i < e; i++)
            {
                int startNode = in.nextInt();
                int endNode = in.nextInt();
                List<Integer> neighbours = graph.getOrDefault(startNode, new ArrayList<>());
                neighbours.add(endNode);
                graph.put(startNode, neighbours);
                if (!graph.containsKey(endNode))
                {
                    graph.put(endNode, new ArrayList<>());
                }
            }
        }

    }
}



Measured memory_bytes: 115848
#include<bits/stdc++.h>
//ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
//clock_t start=clock();clock_t end=clock();cout<<(double)(end-start)/CLOCKS_PER_SEC<<endl;
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int ui;
typedef pair<int,int> pii;
typedef pair<pii,int> ppii;
typedef pair<int,pii> pipi;
typedef pair<ll,ll> pll;
typedef pair<pll,ll> ppll;
typedef pair<ll,pll> plpl;
typedef tuple<ll,ll,ll> tl;
ll mod=1000000007;
ll mod2=998244353;
ll mod3=1000003;
ll mod4=998244853;
ll mod5=1000000009;
ll inf=1LL<<60;
double pi=3.141592653589793238462643383279L;
double eps=1e-10;
#define rep(i,m,n) for(ll i=m;i<n;i++)
#define rrep(i,n,m) for(ll i=n;i>=m;i--)
#define srep(itr,st) for(auto itr=st.begin();itr!=st.end();itr++)
#define Max(a,b) a=max(a,b)
#define Min(a,b) a=min(a,b)
int dh[4]={1,-1,0,0};
int dw[4]={0,0,1,-1};
int ddh[8]={-1,-1,-1,0,0,1,1,1};
int ddw[8]={-1,0,1,-1,1,-1,0,1};
ll gcd(ll a,ll b){
    if(a<b)swap(a,b);
    if(b==0)return a;
    if(a%b==0)return b;
    return gcd(b,a%b);
}
ll Pow(ll n,ll k){
    ll ret=1;
    ll now=n;
    while(k>0){
        if(k&1)ret*=now;
        now*=now;
        k/=2;
    }
    return ret;
}
ll beki(ll n,ll k,ll md){
  ll ret=1;
  ll now=n;
  while(k>0){
    if(k%2==1){
      ret*=now;
      ret%=md;
    }
    now*=now;
    now%=md;
    k/=2;
  }
  return ret;
}
ll gyaku(ll n,ll md){
  return beki(n,md-2,md);
}

int main(){
    ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int n;cin>>n;
    int m;cin>>m;
    int s[m],c[m];
    rep(i,0,m)cin>>s[i]>>c[i];
    int ue=Pow(10,n);
    int si=ue/10;
    if(n==1)si=0;
    rep(i,si,ue){
        int a[n];
        int now=i;
        int l=0;
        rrep(j,n-1,0){
            a[j]=now%10;
            now/=10;
        }
        while(l<n&&a[l]==0)l++;
        if(l==n)l--;
        int cc=0;
        rep(j,0,m){
            if(s[j]<=l){
                cc=1;
                break;
            }
            if(a[s[j]-1]!=c[j]){
                cc=1;
                break;
            }
        }
        if(cc==0){
            cout<<i<<endl;
            return 0;
        }
    }
    cout<<-1<<endl;
}







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

int main(void)
{
  int i, j, k, n, result = 0;
  int l[105];
  
  scanf("%d", &n);
  
  for( i = 0; i < n; i++ ){
      scanf("%d", &l[i]);
  }
  
  for( i = 0; i < n; i++ ){
    for( j = i+1; j < n; j++ ){
       for( k = j+1; k < n; k++ ){
           if( l[i] == l[j] ||  l[i] == l[k] || l[k] == l[j]  ){
               continue;
           }
           if( l[i]+l[j] > l[k] && l[j]+l[k] > l[i] && l[k]+l[i] > l[j] ){
               result++;
               //printf("%d %d %d\n", i, j, k);
           }
       }
    }
  }
  
  printf("%d\n", result);
  return 0;
}

Measured memory_bytes: 1728
import sys

lines = sys.stdin.readlines()
for l in lines:
    nums = list(map(int, l.split()))
    A = [nums[0], nums[1], nums[3], nums[4]]
    B = [nums[2], nums[5]]
    detA = A[0]*A[3] - A[1]*A[2]
    inA = [A[3], -A[1], -A[2], A[0]]
    solutions = [n/detA+0.0 for n in [inA[0]*B[0] + inA[1]*B[1], inA[2]*B[0] + inA[3]*B[1]]]
    print("%.3f %.3f" % (solutions[0], solutions[1]))

Measured memory_bytes: 7592
//#include <bits/stdc++.h>
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
//#include "boost/multiprecision/cpp_int.hpp"
//typedef boost::multiprecision::cpp_int LL;
typedef long double dd;
#define i_7 (ll)(1E9+7)
//#define i_7 998244353
#define i_5 i_7-2

ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
typedef pair<ll,ll> l_l;
typedef pair<dd,dd> d_d;
ll inf=(ll)1E16;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);
void Min(ll &pos,ll val){pos=min(pos,val);}
void Add(ll &pos,ll val){pos=mod(pos+val);}
dd EPS=1E-9;
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define fi first
#define se second
#define endl "\n"
#define SORT(v) sort(v.begin(),v.end())
#define ERASE(v) v.erase(unique(v.begin(),v.end()),v.end())
#define POSL(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define POSU(v,x) (upper_bound(v.begin(),v.end(),x)-v.begin())
//template<class T>void max(T a,T b){if(a<b)return b;else return a;}
//template<class T>void min(T a,T b){if(a>b)return b;else return a;}
//template<class T>bool Max(T&a, T b){if(a < b){a = b;return 1;}return 0;}
//template<class T>bool Min(T&a, T b){if(a > b){a = b;return 1;}return 0;}

//////////////////////////

#define N 2005*2005
int main(){fastio
    ll n;cin>>n;
    ll a[n];rep(i,0,n-1)cin>>a[i];
    //bitset<N>dp[n+1];
    bitset<N>dp[2];
    dp[0][0]=1;
    rep(i,1,n){
        dp[i&1]=dp[(i-1)&1]|(dp[(i-1)&1]<<a[i-1]);
    }
    ll sum=0;rep(i,0,n-1)sum+=a[i];
    rep(j,(sum+1)/2,sum){
        if(dp[n&1][j]){cout<<j;return 0;}
    }
    
    return 0;
}


Measured memory_bytes: 2688
#!/usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import sys, random, itertools, math
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
sqrt = math.sqrt
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float, input().split()))
def LI_(): return list(map(lambda x: int(x)-1, input().split()))
def II(): return int(input())
def IF(): return float(input())
def S(): return input().rstrip()
def LS(): return S().split()
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float("INF")

#solve
def solve():
    n = II()
    p = IR(n)
    print(sum(p) - max(p) // 2)
    return


#main
if __name__ == '__main__':
    solve()


Measured memory_bytes: 39024
#include<bits/stdc++.h>
using namespace std;
#define ll long long int 

int main(){
 ll i,j,k;
  ll a,b,c,d;
  cin>>a>>b>>c>>d;
  a-=1;
  ll c1=a/c+a/d;
  c1-=(a/((c*d)/__gcd(c,d)));

  ll c2=b/c+b/d;
  c2-=(b/((c*d)/__gcd(c,d)));
  c2-=c1;
  ll len=b-a;
 // cout<<len<<" "<<c2<<"\n";
  len-=c2;
  cout<<len<<"\n";
}

Measured memory_bytes: 256
from numpy import *
n,M=map(int,input().split())
l=n*3+1
d=zeros((l,n*5),int64)
d[0][0]=1
for i in range(1,l):j,k=i-1,i-2;d[i]=(d[i-3]*k*j+roll(d[k],-1)*j+roll(d[j],1))%M
print(d[-1][:l].sum()%M)

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

using namespace std;

int main()
{
    long n,a,b,res;
    cin>>n>>a>>b;
    if(a>b)
    {
        cout<<0<<endl;
    }
    else if(n==1 && a<b)
    {
        cout<<0<<endl;
    }
    else
    {
        res=((a+b*(n-1))-(a*(n-1)+b)+1);
        cout<<res<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
def solve(n, meetables):
    mets = [set() for _ in range(n)]

    for d, meetable in enumerate(meetables[1:]):
        today = meetable.copy()
        for i in meetable:
            today.update(mets[i])
            mets[i] = today
        if len(today) == n:
            return d + 1
    return -1


while True:
    n = int(input())
    if not n:
        break

    meetables = [set() for _ in range(31)]

    for i in range(n):
        for d in map(int, input().split()[1:]):
            meetables[d].add(i)

    print(solve(n, meetables))

Measured memory_bytes: 7808
#include <bits/stdc++.h>
using namespace std;
// type alias
typedef long long LL;
typedef pair<int,int> II;
typedef tuple<int,int,int> III;
typedef vector<int> VI;
typedef vector<string> VS;
typedef unordered_map<int,int> MAPII;
typedef unordered_set<int> SETI;
template<class T> using VV=vector<vector<T>>;
// minmax
template<class T> inline T SMIN(T& a, const T b) { return a=(a>b)?b:a; }
template<class T> inline T SMAX(T& a, const T b) { return a=(a<b)?b:a; }
// repetition
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)
#define REPE(i,n)  for(int i=0;i<=(n);++i)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  for(int i=0;i<(n);++i)
#define FORR(x,arr) for(auto& x:arr)
#define SZ(a) int((a).size())
// collection
#define ALL(c) (c).begin(),(c).end()
// DP
#define MINUS(dp) memset(dp, -1, sizeof(dp))
#define ZERO(dp) memset(dp, 0, sizeof(dp))
// stdout
#define println(args...) fprintf(stdout, ##args),putchar('\n');
// debug cerr
template<class Iter> void __kumaerrc(Iter begin, Iter end) { for(; begin!=end; ++begin) { cerr<<*begin<<','; } cerr<<endl; }
void __kumaerr(istream_iterator<string> it) { (void)it; cerr<<endl; }
template<typename T, typename... Args> void __kumaerr(istream_iterator<string> it, T a, Args... args) { cerr<<*it<<"="<<a<<", ",__kumaerr(++it, args...); }
template<typename S, typename T> std::ostream& operator<<(std::ostream& _os, const std::pair<S,T>& _p) { return _os<<"{"<<_p.first<<','<<_p.second<<"}"; }
#define __KUMATRACE__ true
#ifdef __KUMATRACE__
#define dump(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); __kumaerr(_it, args); }
#define dumpc(ar) { cerr<<#ar<<": "; FORR(x,(ar)) { cerr << x << ','; } cerr << endl; }
#define dumpC(beg,end) { cerr<<"~"<<#end<<": "; __kumaerrc(beg,end); }
#else
#define dump(args...)
#define dumpc(ar)
#define dumpC(beg,end)
#endif

// $ cp-batch RainFlowsIntoDams | diff RainFlowsIntoDams.out -
// $ g++ -std=c++14 -Wall -O2 -D_GLIBCXX_DEBUG -fsanitize=address RainFlowsIntoDams.cpp && ./a.out

/*
 
 7/7/2019
 
 5:28-
 
 */

const int MAX_N=1e6+1;
LL A[MAX_N];
int N;

void solve() {
  vector<LL> res(N);
  REP(i,N) {
    int sign=i%2?-1:1;
    res[0]+=A[i]*sign;
  }
  REP(i,N-1) res[i+1]=2LL*A[i]-res[i];
  REP(i,N) printf("%lld ", res[i]);
  println("");
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout<<setprecision(12)<<fixed;
  
  cin>>N;
  REP(i,N) cin>>A[i];
  solve();
  
  return 0;
}


Measured memory_bytes: 2944
#include <bits/stdc++.h>
#define rep(i,n) for(int i=1;i<=n;++i)
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl
using namespace std;

int main(){
  string str;
  cin >> str;
  if (str.at(0)==str.at(1) && str.at(1)==str.at(2) && str.at(0)==str.at(2)) Yes;
  else if(str.at(1)==str.at(2) && str.at(2)==str.at(3) && str.at(1)==str.at(3)) Yes;
  else No;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <map>
#include <unordered_map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <math.h>
#include <sstream>
#include <numeric>
#include <string>
#include <cassert>
#include <bitset>

using namespace std;
typedef long long ll;

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


Measured memory_bytes: 1024