akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"
#include <unordered_set>

#define _CRT_SECURE_NO_WARNINGS

#define FOR(i, x, n) for(decltype(x) i = (x); i < (n); i++)
#define REP(i, n) for(decltype(n) i = 0; i < (n); i++)
#define RREP(i, n) for (decltype(n) i = (n) - 1; i >= 0; i--)

#define ALL(a) (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
#define DESCSORT(c) sort(c.begin(), c.end(), greater<int>())

using namespace std;

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

using LL = long long int;
using LD = long double;

const int INF = (1 << 30) - 1;
const LL INF64 = ((LL)1 << 62) - 1;
const double PI = 3.1415926535897932384626433832795;

using pii = pair<int, int>;
using pll = pair<LL, LL>;
using pdd = pair<double, double>;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vl = vector<LL>;
using vvl = vector<vl>;
using vvvl = vector<vvl>;
using vd = vector<double>;
using vvd = vector<vd>;
using vs = vector<string>;
using vb = vector<bool>;
using vvb = vector<vb>;

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

	string a, s;
	cin >> a >> s;

	cout << "A";
	cout << s[0];
	cout << "C" << endl;
	return 0;
}

Measured memory_bytes: 256
#include <algorithm>  
#include <iostream>  
#include <sstream>  
#include <string>  
#include <cstring>
#include <vector>  
#include <queue>  
#include <set>  
#include <map>  
#include <cstdio>  
#include <cstdlib>  
#include <cctype>  
#include <cmath>  
#include <list>  
#include <cassert>
#include <ctime>
#include <climits>
using namespace std;  

#define PB push_back  
#define MP make_pair  
#define SZ(v) ((int)(v).size())  
#define FOR(i,a,b) for(int i=(a);i<(b);++i)  
#define REP(i,n) FOR(i,0,n)  
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)  
#define REPE(i,n) FORE(i,0,n)  
#define FORSZ(i,a,v) FOR(i,a,SZ(v))  
#define REPSZ(i,v) REP(i,SZ(v))  
typedef long long ll;
typedef unsigned long long ull;
ll gcd(ll a,ll b) { return b==0?a:gcd(b,a%b); }

const int MAXN=100000;

int n;
int a[MAXN];

bool solve() {
	int mn=a[0],mx=a[0]; REP(i,n) { if(a[i]<mn) mn=a[i]; if(a[i]>mx) mx=a[i]; }
	if(mx-mn>=2) return false;
	if(mx==mn) {
		// all unique
		if(mn==n-1) return true;
		// none unique
		int cmx=n/2;
		if(mn<=cmx) return true;
	} else {
		int nunique=0; REP(i,n) if(a[i]==mn) ++nunique;
		int npaired=n-nunique;
		//printf("mx=%d mn=%d nunique=%d npaired=%d\n",mx,mn,nunique,npaired);
		if(npaired>=2) {
			int cmx=npaired/2;
			if(mn>=nunique&&mx<=nunique+cmx) return true;
		}
	}
	return false;
}

void run() {
	scanf("%d",&n); REP(i,n) scanf("%d",&a[i]);
	printf("%s\n",solve()?"Yes":"No");
}

int main() {
	run();
	return 0;
}


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

using namespace std;

#define for_(i,a,b) for(int i=a;i<b;i++)
#define minit(a,b) memset(a,b,sizeof(a));
#define ALL(a) a.begin(),a.end()

int N, M;
int h[2000], w[2000];

void solve() {
	vector<int> H, W;
	for_(k,0,N) {
		for_(i,0,N-k) {
			int sum = 0;
			for_(j,i,i+k+1) sum += h[j];
			H.push_back(sum);
		}
	}
	for_(k,0,M) {
		for_(i,0,M-k) {
			int sum = 0;
			for_(j,i,i+k+1) sum += w[j];
			W.push_back(sum);
		}
	}
	sort(ALL(H)); sort(ALL(W));
	
	int ans = 0;
	int hsize = (int)H.size();
	for_(i,0,hsize) {
		int hi = H[i];		
		int numh = upper_bound(ALL(H),hi) - lower_bound(ALL(H),hi);
		int numw = upper_bound(ALL(W),hi) - lower_bound(ALL(W),hi);
		ans += numh * numw;
		i += numh - 1;
	}
	
	cout << ans << endl;
}

int main() {
	while (cin >> N >> M, N) {
		for_(i,0,N) cin >> h[i];
		for_(i,0,M) cin >> w[i];
		solve();
	}
	
	return 0;
}

Measured memory_bytes: 21816
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <map>
#include <sstream>
#include <queue>
#include <cstdlib>
#include <algorithm>
#include <iterator>
#include <stack>
#include <list>
using namespace std;
const int INF=1000000000;
typedef long long int lli;
typedef pair<int,int> P;

const int MAX_V=5001;
int cost[MAX_V][MAX_V];
int d[MAX_V];
bool used[MAX_V];
int shortest[MAX_V];

int abs(int x){
	if(x<0) return -x;
	else return x;
}

int main(){
	int V,E,K;
	cin >> V >> E >> K;
	for(int i=1; i<=V; ++i){
		for(int j=1; j<=V; ++j){
			if(i==j) {
				cost[i][j]=0;
			} else {
				cost[i][j]=INF;
			}
		}
	}
	for(int i=0; i<E; ++i){
		int a,b,l;
		cin >> a >> b >> l;
		cost[a][b]=cost[b][a]=l;
	}
	fill(d,d+V+1,INF);
	for(int i=0; i<K; ++i){
		int tmp;
		cin >> tmp;
		d[tmp]=0;
	}
	fill(shortest,shortest+V+1,INF);
	fill(used,used+V+1,false);
	while(true){
		int v=-1;
		for(int u=1; u<=V; ++u){
			if(!used[u]&&(v==-1||d[u]<d[v])) v=u;
		}
		
		if(v==-1) break;
		used[v]=true;
		
		for(int u=1; u<=V; ++u){
			d[u]=min(d[u],d[v]+cost[v][u]);
			if(shortest[u]>d[u]) shortest[u]=d[u];
		}
	}
	
	int ans=-1;
	for(int i=1; i<=V; ++i){
		for(int j=1; j<=V; ++j){
			if(cost[i][j]!=INF){
				int tmp=abs((shortest[j]+shortest[i]+cost[i][j]+1)/2);
				ans=max(ans,tmp);
			}
		}
	}
	cout << ans << "\n";
	return 0;
}

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

int main()
{
   int n, m;
   cin >> n >> m;
   vector<int>a(m);
   vector<int>b(m);
   for(int i = 0; i < m; i++) cin >> a[i] >> b[i];
   vector<int>c(n);
   for(int i = 0; i < m; i++){
      c[a[i]-1] += 1;
      c[b[i]-1] += 1;
   } 
   for(int i = 0; i < n; i++)cout << c[i] << endl;
}



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

using namespace std;

#define REPI(x) for(int i=0;i<x;i++)
#define REPJ(x) for(int j=0;j<x;j++)
#define SCANFD(x) scanf("%d",&x)

int main(){
    int N,M;
    int bufa,bufb;
    int ii,jj;
    vector<int> from,to;
    bool flag = false;

    scanf("%d%d",&N,&M);
    
    for(int i=0;i<M;i++){        
        scanf("%d%d",&bufa,&bufb);
        
        if(bufa == 1 && bufb == N){
            flag = true;
            continue;
        }else if(bufa == 1){
            from.push_back(bufb);            
        }else if(bufb == N){
            to.push_back(bufa);
        }
    }
    if(from.size() > 0 && to.size() > 0){
        sort(from.begin(),from.end());
        sort(to.begin(),to.end());
        
        ii = 0;
        jj = 0;
        
        while(ii < from.size() && jj < from.size()){
            if(from[ii] == to[jj]){
                flag = true;
                break;
            }
            if(from[ii] > to[jj]){
                jj++;
            }else{
                ii++;
            }
        }    
    }
    
    if(flag)
        printf("POSSIBLE\n");
    else
        printf("IMPOSSIBLE\n");
        
    
    return 0;
}


Measured memory_bytes: 1276
#include <iostream>

using namespace std;

int main(void){
	while(true){
		int h, w;
		cin >> h >> w;
		if(h == 0 && w == 0){
			break;
		}
		for(int i = 0;i < h; ++i){
			for(int j = 0;j < w; ++j){
				if(i == 0 || j == 0 || j == w-1 || i == h-1){
					cout << '#';
				} else {
					cout << '.';
				}
			}
			cout << endl;
		}
		cout << endl;
	}

	return 0;
}

Measured memory_bytes: 1156
package main

import (
        "fmt"
)

func main() {
        var a,b,c int
        fmt.Scan(&a)
        fmt.Scan(&b)
        fmt.Scan(&c)

        X := []int{a,b,c}
        for i := 0; i < len(X) ; i++ {
                for j := len(X)-1 ; j > i; j--{
                        if (X[j] < X[j-1]) {
                                var t int
                                t = X[j]
                                X[j] = X[j-1]
                                X[j-1] = t
                        }
                }
        }
        fmt.Println(X[0], X[1], X[2])
}


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

using namespace std;

int main(void) {
    string s;
    cin >> s;
    string t;
    cin >> t;
    int cnt = 0;

    for (int i = 0; i < 3; i++) {
        if (s[i] == t[i]) cnt++;
    }

    cout << cnt << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
    int a,b,c;
    int count=0;
    cin >> a >> b >> c;
    for(int i=a;i<=b;i++){
        if(c%i==0){
            count++;
        }
    }
    cout << count << endl;
}


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

#define all(x)        (x).begin(),(x).end()
#define eb            emplace_back
#define mp            make_pair
#define pb            push_back
#define fi            first
#define se            second
#define sz(x)         ((int)(x).size())
#define rep(x,y,z)    for(int x=y;x<z;x++)
#define per(x,z,y)    for(int x=z-1;x>=y;x--)
#define trav(y,x)     for(auto& y:x)
#define pii           pair<int, int>
#define pll           pair<ll, ll>
#define vi            vector<int>
#define vpi           vector<pii>

int dbg = 0;
#define cri           if(0)
#define shame         cri cerr<<(++dbg)<<"\n\n";

// aaaaaaaaaaaaaaaa
void solve() {
  int a, b, c, k;
  scanf("%d%d%d%d", &a, &b, &c, &k);
  int t = min(a, k);
  int ans = t;
  k -= t;
  t = min(b, k);
  k -= t;
  t = min(c, k);
  ans -= t;
  printf("%d\n", ans);
}

int main() {
  // int _; scanf("%d", &_); while (_--)
  // ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  // int _; cin >> _; while(_--)
  solve();
	return 0;
}


Measured memory_bytes: 3812
{-# OPTIONS_GHC -O #-}

import Data.List
import qualified Data.ByteString.Char8 as B

cmb n k = foldl' (\a i->div (a*(n-i+1)) i) 1 [1..k]

main = do
    (n:a:b:_)<-map read.words<$>getLine::IO[Int]
    vs<-sortBy (flip compare).unfoldr (B.readInt.B.dropWhile(==' '))<$>B.getLine::IO[Int]
    --
    print $ hei a vs
    print $ solve a b vs
--
hei a vs = flip (/) (fromIntegral a) $ fromIntegral $ sum $ take a vs

solve a b vs@(va:_)
    | la >= a = sum $ map (cmb la) [a..lb]
    | otherwise = cmb ld lc
    where
        la = length $ takeWhile(==va) vs
        lb = min la b
        lc = length $ filter(==(vs !! (a-1))) $ take a vs
        ld = length $ filter(==(vs !! (a-1))) vs
         

Measured memory_bytes: 508
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define per(i,a,b) for(int i=a;i>b;i--)
#define repLL(i,a,b) for(LL i=(LL)a;i<(LL)b;i++)
#define perLL(i,a,b) for(LL i=(LL)a;i>(LL)b;i--)
#define debug5(a,b,c,d,e) cerr<<#a<<": "<<a<<" "<<#b<<": "<<b<<" "<<#c<<": "<<c<<" "<<#d<<": "<<d<<" "<<#e<<": "<<e<<endl;
#define debug4(a,b,c,d)  cerr<<#a<<": "<<a<<" "<<#b<<": "<<b<<" "<<#c<<": "<<c<<" "<<#d<<": "<<d<<endl;
#define debug3(a,b,c) cerr<<#a<<": "<<a<<" "<<#b<<": "<<b<<" "<<#c<<": "<<c<<endl;
#define debug2(a,b) cerr<<#a<<": "<<a<<" "<<#b<<": "<<b<<endl;
#define debug(a) cerr<<#a<<": "<<a<<endl;
#define pb push_back
#define mp make_pair
#define SZ(x) ((int)(x).size())
#define ALL(x) x.begin(),x.end()
#define fi first
#define se second
#define _upgrade ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

using namespace std;

typedef long long LL;
typedef pair<int,int> PII;
typedef pair<LL,LL> PLL;
typedef vector<PII> VPII;
typedef vector<PLL> VPLL;
typedef vector<LL> VLL;
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<char> VC;
typedef long double LD;
typedef pair<LD,LD> PLD;
typedef vector<LD> VLD;
typedef vector<PLD> VPLD;

template<typename T>
void dbg(T a)
{
      #ifdef LOCAL
            cerr<<a<<"\n";
      #endif
}

template<typename T, typename ...Arg>
void dbg(T a,Arg ...arg)
{
      #ifdef LOCAL
            cerr<<a<<" ";
            dbg(arg...);
      #endif
}

const int maxn=(1e6)+7;
const int inf=(1e9)+7;
const LL LLinf=(1e18)+7;
const LD eps=1e-9;
const LL mod=1e9+7;

// ***************************** CODE ***************************** //

LL dp[maxn][2];
LL val[maxn][2];

int main()
{
      _upgrade
	int n;
	cin>>n;
	for(int i = 0 ;i < n;i++)
	{
		cin>>val[i][0];
		dp[i][0] = val[i][0];
		dp[i][0] += dp[i - 1][0];
	}
	for(int i = 0 ;i < n;i++)
	{
		cin>>val[i][1];
		if(i > 0)
			dp[i][1] = max(dp[i - 1][1], dp[i][0]) + val[i][1];
		else
			dp[i][1] = dp[i][0] + val[i][1];
	}
	cout<<dp[n - 1][1];
      return 0;
}


Measured memory_bytes: 2304
s = list(map(int, input()))

expected = []

for i in range(len(s)):
    if (i % 2 == 0):
        expected.append(0)
    else:
        expected.append(1)

union = []

for i in range(len(s)):
    union.append((s[i] + expected[i]) % 2)

cnt_0 = union.count(0)
cnt_1 = union.count(1)

print(min(cnt_0, cnt_1))

Measured memory_bytes: 5536
n, m = map(int, input().split())
A = [list(map(int, input().split())) for i in range(m)]

B = [[] for i in range(n + 1)]

for i in range(m):
    B[A[i][0]].append(A[i][1])
    B[A[i][1]].append(A[i][0])

co = 0
ok = 0
while ok == 0:
    ok = 1
    for i in range(1, n + 1):
        if len(B[i]) == 1:
            ok = 0
            k = B[i][0]
            B[i].remove(k)
            B[k].remove(i)
            co += 1

print(co)

Measured memory_bytes: 3064
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;

#define FOR(i,n) for(int i=0;i<n;i++)
#define PRINT(a) cout<<a<<"\n"
 
int main(){

	int x;
	cin>>x;

	cout<<((x<1200)?"ABC":"ARC")<<endl;
	

	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<algorithm>
#include<string>
#include<vector>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
int main(){
  ll a,b,c,ans;cin>>a>>b>>c;
  ans=min(a*b,c);
  cout<<ans<<endl;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define BIT(n) (1LL << (n))
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPB(i, n) for (int i = 0; i < BIT(n); i++)
#define REPS(i, x) for (int i = 1; i <= (int)(x); 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 FORA(i, n) for (auto &&i : n)
#define FORS(i, m, n) for (int i = m; i <= n; i++)
#define DEBUG(x) cerr << #x <<": "<<x<<"\n"
#define ALL(v) v.begin(), v.end()
#define fst first
#define snd second
#define mp make_pair
#define pb push_back
#define epb emplace_back
#define int long long
using namespace std;
template <class T> using vec = std::vector<T>;
template <class T = int> T in(){T x; cin>>x;return(x);}
template <class T > void print(T& x){cout<<x<<"\n";}
typedef long long ll;
const int MOD = 1000000007;
const int INF = 1061109567;
const double EPS = 1e-10;
const double PI  = acos(-1.0);
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
vec< vec< int > > t;
vec< int > cost;
void dfs(int oya) {
  REP(i, (int)(t[oya].size())) {
    int child = t[oya][i];
    cost[child] += cost[oya];
    dfs(child);
  }
}
signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
 int N,Q;
 cin>>N>>Q;
 cost.resize(N);
 cost.assign(N, 0);
 t.resize(N, vec< int >());

 REP(i, N - 1) {
   int a, b;
   cin >> a >> b;
   a--;
   b--;
   t[a].pb(b);
 }
 REP(i,Q){
     int p,q;
     cin>>p>>q;
     p--;
     cost[p]+=q;
 }
 dfs(0);
 REP(i,N){
     cout << cost[i]<<" ";
 }
 cout <<endl;

}

Measured memory_bytes: 21120
import java.util.Scanner;
public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    int b = sc.nextInt();
    if (a < b) {
      System.out.println("a < b");
    } else if (a == b) {
      System.out.println("a == b");
    } else {
      System.out.println("a > b");
    }
  }
}



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

int main() {
  long Q, H, S, D, N;
  cin >> Q >> H >> S >> D >> N;
  long x = min({Q * 4, H * 2, S});
  if (x * 2 <= D) {
    cout << N * x << endl;
    return 0;
  }
  cout << (N / 2) * D + (N % 2) * x << endl;
}

Measured memory_bytes: 256
open System;

let _ = Console.ReadLine()
let s = Console.ReadLine()

[for c in s -> c]
|> List.fold (fun (acc, mmax) c -> let acc = acc + if c = 'I' then 1 else -1
                                   (acc, max acc mmax))
             (0, 0)
|> (fun (acc, mmax) -> mmax)
|> Console.WriteLine

Measured memory_bytes: 13268
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <set>
#include <map>
#include <numeric>
#include <regex>
#include <tuple>
#include<iomanip>
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
#define MOD 1000000007 // 10^9 + 7
#define INF 1000000000 // 10^9
#define LLINF 1LL<<60


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

	int a; cin >> a;
	string s; cin >> s;

	if (a >= 3200) cout << s << endl;
	else cout << "red" << endl;

	return 0;
}

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

void update(vector<long long int> &vec,long long int val,int pos){
    for(pos++;pos<vec.size();pos += (pos&(-pos)))
        vec[pos] = max(vec[pos], val);
}
long long int query(vector<long long int> &vec,int pos){
    long long int val = -1;
    for(pos++;pos;pos -= (pos&(-pos)))
         val = max(vec[pos],val);
    return val;
}
int main(){
    int n;
    cin >> n;
    int h[n+1], a[n+1];
    for(int i=0; i<n;i++)
        cin >> h[i];
    for(int i=0; i<n; i++)
        cin >> a[i];
    vector<long long int> ans(n+2,0);
    for(int i=0; i<n; i++){
        int x = h[i];
        long long int res = query(ans, x-1);
        update(ans, res+a[i], x);
    }
    cout << query(ans, n);
}

Measured memory_bytes: 6408
N = int(input())
x = []
count = 0
for i in range(N):
    D1,D2 = map(int,input().split())
    t = [D1,D2]
    x.append(t)
i = 0
while i <= N-3:
    if i > N-3:
        break
    elif x[i][0] == x[i][1] and x[i+1][0] == x[i+1][1] and x[i+2][0] == x[i+2][1]:
        t = 'Yes'
        break
    else:
        t = 'No'
    i +=1
print(t)

Measured memory_bytes: 9192
#include <bits/stdc++.h>
#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 ll long long
#define INF 999999999
using namespace std;
int main() {
  int N,M;
  std::cin >> N >> M;
  if (N%2) {
    for (int i = 1; i <= M; i++) {
      std::cout << i << " " << N-i+1 << '\n';
    }
  }
  else{
    for (int i = 1; i <= M; i++) {
      if (i <= (double)N/4) {
        std::cout << i << " " <<N-i+1 << '\n';
      }
      else{
        std::cout << i << " " << N-i << '\n';
      }
    }
  }
}


Measured memory_bytes: 3644
import java.util.*;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int N = sc.nextInt();
        int[] a = new int[N];

        for(int i = 0; i < N; ++i) {
            a[i] = sc.nextInt();
        }

        long res = Long.MAX_VALUE;
        for(int t = -100; t <= 100; ++t) {
            long s = 0;
            for(int i = 0; i < N; ++i) {
                s += Math.pow(a[i] - t, 2);
            }
            res = Math.min(s, res);
        }
        System.out.println(res);
    }
}


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

using namespace std;

using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  vector<ll> v(n);
  for (int i = 0; i < n; i++)
    cin >> v[i];
  ll ans = 0;
  for (int i = 0; i < n; i++) {
    ll c;
    cin >> c;
    v[i] -= c;
    ans += max(0LL, v[i]);
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define fi first
#define se second
long long mo = 1000000007;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
typedef pair<ll,Pll> Plp;
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
template<class A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}cout << "\n";}
ld PI=3.14159265358979323846;

template<typename T>
struct BIT {
  int n;
  vector<T> d;
  BIT(int n=0):n(n),d(n+1) {}
  void add(int i, T x=1) {
    for (i++; i <= n; i += i&-i) {
      d[i] += x;
    }
  }
  T sum(int i) {
    T x = 0;
    for (i++; i; i -= i&-i) {
      x += d[i];
    }
    return x;
  }
  T sum(int l, int r) {
    return sum(r-1) - sum(l-1);
  }
};

int main(){
    ll N, Q;
    cin >> N >> Q;
    vector<ll> a(N), l(Q), r(Q), pi(N+1,-1);
    rep(i,N){
        cin >> a[i];
    }
    vector<vector<Pll>> qs(N);
    rep(i,Q){
        cin >> l[i] >> r[i];
        l[i]--;r[i]--;
        qs[l[i]].push_back(Pll(r[i], i));
    }
    vector<vector<ll>> ps(N);
    rep(i,N){
        ll l = pi[a[i]];
        if(l != -1) ps[l].push_back(i);
        pi[a[i]] = i;
    }
    BIT<ll> d(N);
    vector<ll> ans(Q);
    for(ll i=N-1;i>=0;i--){
        for(auto& y:ps[i]) d.add(y,1);
        for(auto& p:qs[i]){
            ans[p.se] = (p.fi - i + 1) - d.sum(p.fi);
        }
    }
    rep(i,Q) cout << ans[i] << endl;
}

Measured memory_bytes: 78744
import java.io.*;
import java.util.Arrays;
import java.util.StringJoiner;
import java.util.StringTokenizer;

public class Main {

    static long K;

    public static void main(String[] args) {
        FastScanner sc = new FastScanner(System.in);
        K = sc.nextLong();

        long[] array = solve();
        StringJoiner j = new StringJoiner(" ");
        for (long each : array) {
            j.add(String.valueOf(each));
        }
        System.out.println( array.length );
        System.out.println( j.toString() );
    }

    static long[] solve() {
        long[] answer = new long[50];

        long d = K / 50;
        int r = (int)(K % 50);

        Arrays.fill(answer, d + 49);

        for (int i = 0; i < r; i++) {
            answer[i] ++;
        }
        for (int i = r; i < 50; i++) {
            answer[i] -= r;
        }
        return answer;
    }

    @SuppressWarnings("unused")
    static class FastScanner {
        private BufferedReader reader;
        private StringTokenizer tokenizer;

        FastScanner(InputStream in) {
            reader = new BufferedReader(new InputStreamReader(in));
            tokenizer = null;
        }

        String next() {
            if (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        String nextLine() {
            if (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    return reader.readLine();
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken("\n");
        }

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

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

        int[] nextIntArray(int n) {
            int[] a = new int[n];
            for (int i = 0; i < n; i++)
                a[i] = nextInt();
            return a;
        }

        long[] nextLongArray(int n) {
            long[] a = new long[n];
            for (int i = 0; i < n; i++)
                a[i] = nextLong();
            return a;
        }
    }
}


Measured memory_bytes: 23124
import sys
N,M=map(int,input().split())
A = list( map(int,input().split()) )
for i in range(N): A[i] = A[i]//2


def GCD(a,b):
    if a % b == 0:
        return b
    return GCD( b, a%b )

# 全Aが2で割り切れる数が等しいか確認
cnt = 1
while A[0]%(1<<cnt) == 0 :
    cnt += 1
for i in range(1,N):
    if (A[i]%(1<<cnt) == 0) or (A[i]%(1<<(cnt-1)) != 0):
        print(0)
        sys.exit()

A.append(1)
a = A[0]
b = A[1]
lcm = a * b // GCD(a,b)
#print(lcm)
if lcm > M:
    print(0)
    sys.exit()
for i in range(2,N):
    a = lcm
    b = A[i]
    lcm = a * b // GCD(a,b)
    if lcm > M:
        print(0)
        sys.exit()
print( (M+lcm) // (lcm*2) )


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

const ll MOD = 1e9+7;
const int INF = (int)1e9+7;

// vector<tuple<long,long>> items; // (value, weight)
// auto item = items[i];
// long v = get<0>(item);
// long w = get<1>(item);
// long v, w;
//   for( int i = 0; i < N; i++ ){
//     cin >> v >> w;
//     items.push_back( make_tuple(v, w) ); // item : (value, weight)
//   }

int main(){
    int N;
    cin >> N;
    int dp[100000][3];
    int a,b,c;
    cin >> a >> b >> c;
    dp[0][0] = a;
    dp[0][1] = b;
    dp[0][2] = c;
    for(int i=1; i<N; i++){
        cin >> a >> b >> c;
        dp[i][0] = max(dp[i-1][1],dp[i-1][2]) + a;
        dp[i][1] = max(dp[i-1][0],dp[i-1][2]) + b;
        dp[i][2] = max(dp[i-1][0],dp[i-1][1]) + c;
    }
    cout << max({dp[N-1][0],dp[N-1][1],dp[N-1][2]});
    return 0;
}


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

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>

using namespace std;

int main(int argc, char* argv[]) {
	int a, b, i;
	scanf("%d %d",&a,&b);
	int c=0;
	for (i=a;i<=b;i++) {
		if (i/10000==i%10&&i/1000%10==i/10%10) c++;
	}
	printf("%d\n",c);
	return 0;
}


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

using namespace std;
using ll = long long;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  int n; cin >> n;
  vector<int> ar(n - 1);
  for(int &x: ar) {
    cin >> x;
  }
  int res = ar[0];
  for(int i = 0; i < n - 2; ++i) {
    res += min(ar[i], ar[i + 1]);
  }
  res += ar.back();
  cout << res << '\n';
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ff first
#define ss second
#define len(x) (int)(x.size())
#define all(x) x.begin(), x.end()
using namespace std;
using ll = long long;
using ii = pair<int, int>;

int main(){
	int n;
	scanf("%d", &n);
	vector<int> vs(n);
	for(auto &x:vs)	
		scanf("%d", &x);
	sort(all(vs));
	ll ans = 0;
	for(int i=0; i<n; ++i){
		for(int j=i+1; j<n; ++j){
			int l = upper_bound(vs.begin()+j+1, vs.end(), abs(vs[i]-vs[j]))-vs.begin();
			int r = lower_bound(vs.begin()+j+1, vs.end(), vs[i]+vs[j])-vs.begin();
			ll value = r-l;
			//cout << vs[i] << " " << vs[j] << " " << l << "-" << r << endl;
			ans += value;
		
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 3716
#include <iostream>
#include <iomanip>
#include <vector>
#include <utility>
#include <map>
#include <algorithm>
#include <queue>
#include <cmath>
#include <numeric>

using namespace std;
struct aaa{aaa(){cin.tie(nullptr); ios::sync_with_stdio(false); cout<<fixed<<setprecision(20);};}aaa;

typedef long long int64;

bool ok(int i, const int& n, vector<bool>& d) {
    if (i < n) return false;
    while(i != 0) {
        if (d[i%10]) return false;
        i /= 10;
    }
    return true;
}

int main() {
    int n,k;
    cin >> n >> k;
    vector<bool> ng(10);
    for (int i=0; i<k; i++) {
        int d; cin>>d;
        ng[d] = true;
    }

    for (int i=1; i<=INT_MAX; i++) {
        if (ok(i,n,ng)) {
            cout << i << endl;
            break;
        }
    }
}

Measured memory_bytes: 256
A,B = map(int, input().split())
S = input()

for i in range(A):
  if S[i] == '-':
    print("No")
    exit(0)

if S[A] != "-":
  print("No")
  exit(0)

for i in range(B):
  if S[A+i+1] == '-':
    print("No")
    exit(0)
    
print("Yes")


Measured memory_bytes: 3060
n, m, p = map(int,input().split())
a = sorted([(int(input()) - p) % n for _ in range(m)])
print(min(a[-1], n - a[0], min([a[i] + n - a[i + 1] + min(a[i], n - a[i + 1]) for i in range(m - 1)])) * 100 if m > 1 else min(a[0], n - a[0]) * 100)


Measured memory_bytes: 6388
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false), cin.tie(0)
#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, a, b) for (int i = a; i < b; i++)
#define ALL(x) (x).begin(), (x).end()
#define dump(x) cout << (x) << endl
#define LMAX 9223372036854775807LL
#define LMIN -9223372036854775807LL
using ll = long long;
template<typename T>
using vec = vector<T>;
using P = pair<ll, ll>;
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
	fill((T *)array, (T *)(array + N), val);
}

const ll INF = 1e16;
const ll MOD = 1e9 + 7;
//int dx[4] = {1,0,-1,0};
//int dy[4] = {0,1,0,-1};
//ll pas[51][52];


signed main(){
	IOS;
	double n, m, d;
	cin >> n >> m >> d;

	double ans = 0;
	if(d){
		ans = 2 * (m - 1) * (n - d)/ (n * n);

	}else{
		ans = (m - 1) / n;
	}
	cout << setprecision(7) << fixed << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,N) for(int i=0; i<N; i++) ;
int main() {
    ll L,R;
    cin>>L>>R;
    if(R-L>=2019){
        cout<<0<<endl;
    }
    else{
    if(L%2019>R%2019){
        L=L%2019;
        R=R%2019+2019;
    }
    else
    {
        L=L%2019;
        R=R%2019;
    }
    ll answer=100000;
    for(int i=L; i<R+1; i++){
        for(int j=L; j<R+1; j++){
            if(i==j){
                continue;
            }
            else if(i*j%2019<answer){
                answer=i*j%2019;
            }
        }
    }
    cout<<answer<<endl;
    }
}


Measured memory_bytes: 3600
nl = lambda: list(map(int, input().split()))
sl = lambda: input().split()
n = lambda: int(input())
s = lambda: input()

N = n()

def ok(S):
    for ng in ['AGC', 'GAC', 'ACG']:
        if S[1:] == ng or S[:3] == ng:
            return False
    if S[0] == 'A' and S[2:] == 'GC':
        return False
    if S[:2] == 'AG' and S[3] == 'C':
        return False
    return True


memo = {}
def find(i, prev):
    if (i, prev) in memo:
        return memo[(i, prev)]

    if i == N:
        return 1

    res = 0
    for c in 'ACGT':
        if ok(prev + c):
           res += find(i+1, prev[1:] + c)

    res %= 1000000007
    memo[(i, prev)] = res
    return res

print(find(0, 'TTT'))





Measured memory_bytes: 52312
#include <iostream>
#include <cstring>
#include <algorithm>
#include <queue>
#include <cstdio>
#include <cstdlib>
using namespace std;

static const int N = 1000;

int lcs(string X, string Y) {

    int C[N+1][N+1];
    int m = X.size();
    int n = Y.size();
    int maxl = 0;

    X = ' ' + X; //X[0]に空白を挿入
    Y = ' ' + Y; //Y[0]に空白を挿入

    for (int i = 0; i <= m; i++) C[i][0] = 0;
    for (int j = 1; j <= n; j++) C[0][j] = 0;
    
    for (int i = 1; i <= m; i++) {
        for (int j = 1; j <= n; j++) {
            if (X[i] == Y[j]) {
                C[i][j] = C[i-1][j-1] + 1;
            } else {
                C[i][j] = max(C[i-1][j], C[i][j-1]);
            }
            maxl = max(maxl, C[i][j]);
        }
    }
    return maxl;
}

int main() {

    int n;
    cin >> n;

    string a, b;

    for(int i = 0; i < n; i++) {
        cin >> a >> b;
        cout << lcs(a, b) << endl;
    }
    return 0;
}


Measured memory_bytes: 7112
N = int(input())
H = list(map(int,input().split()))
def dfs(ans, H):
    if not any(H):
        return ans
    flag = 1
    cnt = 0
    for i in range(N):
        if H[i] != 0:
            H[i] -= 1
            if flag:
                flag = 0
                cnt += 1
        else:
            flag = 1
    return dfs(ans + cnt, H)
print(dfs(0, H))

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

int main() {
  int A, B, C ;
  cin >> A >> B;
  C = A % 500;
  if (B >= C) {
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl; 
  }
  // ここにプログラムを追記
}


Measured memory_bytes: 256
import numpy as np
import math

N, K = [int(i) for i in input().split()]

prob = np.maximum((N - K + 1) / N, 0)
#print(prob)

end = np.minimum(N, K-1)
#print(end)
for i in range(1, end+1):
    ratio = K / i
    num = math.ceil(math.log2(ratio))
    prob += 1 / N * (0.5 ** num)
#    print(prob)

print(prob)

Measured memory_bytes: 13240
package main

import (
    "fmt"
    "math"
)

func main() {
    a := scanInt()
    b := scanInt()
    c := scanInt()
    fmt.Println(int(math.Min(float64(b / a), float64(c))))
}

func scanInt() (num int) {
    fmt.Scan(&num)
    return
}
func scanInts(len int) (nums []int) {
    var num int
    for i := 0; i < len; i++ {
        fmt.Scan(&num)
        nums = append(nums, num)
    }
    return
}
func scanString() (str string) {
    fmt.Scan(&str)
    return
}
func scanStrings(len int) (strs []string) {
    var str string
    for i := 0; i < len; i++ {
        fmt.Scan(&str)
        strs = append(strs, str)
    }
    return
}

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

int main(){
    int a,b,c; cin>>a>>b>>c;
    int k; cin>>k;
    int tmp=k;
    if(b<=a){
        while(b<=a && tmp>0){
           b=b*2;
           tmp--;
       } 
    }
    if(c<=b){
        //cout<<tmp<<endl;
       while(c<=b && tmp>0){
           c=c*2;
           tmp--;
           //cout<<c<<endl;
       } 
    }
    //cout<<c<<endl;
    //cout<<a<<' '<<b<<' '<<c;
    if(a<b && b<c) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}



Measured memory_bytes: 3592
#include <algorithm>
#include <bitset>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

typedef long long ll;

#define rep(i, a, b) for (ll i = a; i < (ll)b; ++i)
#define digit(a) to_string(a).size()
#define INF 10e12
#define MAX 51000
#define all(x) (x).begin(), (x).end()
#define MX(x) *max_element(all(x))
#define MN(x) *min_element(all(x))

using namespace std;

const long long MOD = 1e9 + 7;

int main(void)
{
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    int n, k;
    cin >> n >> k;
    vector<int> a(n);
    rep(i, 0, n) cin >> a[i];
    int ans = 0;
    int pre = find(a.begin(), a.end(), 1) - a.begin();
    int last = n - pre - 1;
    ans = (pre + last + k - 2) / (k - 1);

    cout << ans << endl;
}

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

int main(){
    int n,T;
    cin >> n >> T;
    int c,t;
    int ans_c = 10000;
    for (int i = 0;i < n;i++){
        cin >> c >> t;
        if (t <= T ){
            if(c < ans_c){
                ans_c = c;
            }
        }
    }

    if(ans_c != 10000){
        cout << ans_c << endl;
    }
    else if(ans_c == 10000){
        cout << "TLE" << endl;
    }
}

Measured memory_bytes: 256
n=int(input())
a= list(map(int, input().split()))
# 寿司の皿を乗ってる寿司の数で分ける
x=[0,0,0]
for i in range(n):
    x[a[i]-1]+=1

# dp[k][i][j]:k3個、i2個、j1個の寿司が乗ってる皿の数。そこからの全部0になる回数の期待値
dp=[[[0]*(n+2) for i in range(n+2)] for j in range(n+2)]

for k in range(n+1):
    for i in range(n+1):
        for j in range(n+1):
            v=k+i+j
            if 0<v<=n:
                dp[k][i][j]+=dp[k][i][j-1]*(j/v)+dp[k][i-1][j+1]*(i/v)+dp[k-1][i+1][j]*(k/v)+n/v

print(dp[x[2]][x[1]][x[0]])

Measured memory_bytes: 504072
#include<bits/stdc++.h>
using namespace std;
 
int main()
{
int n;cin>>n;
int a[n];
for(int i=0;i<n;i++)
	cin>>a[i];
int maxsteps=0;
int j=n-1,steps=0;
while(j>=1)
{
	if(a[j]<=a[j-1])
		steps++;
	else{
	maxsteps=max(steps,maxsteps);
	steps=0;
	}
	j--;
	}
maxsteps=max(steps,maxsteps);
cout<<maxsteps;
return 0;
}


Measured memory_bytes: 640
A, B, C, D = input().split()
A = int(A)
B = int(B)
C = int(C)
D = int(D)


def solve(A, B, C, D):
    if A < C:
        if B < C:
            return 0
        elif A <= C and D <= B:
            return (D - C)
        else:
            return (B - C)
    else:
        if D < A:
            return 0
        elif C <= A and B <= D:
            return (B - A)
        else:
            return (D - A)

print(solve(A, B, C, D))


Measured memory_bytes: 3060
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {

	final int MIN_NUMBERS = 1;
	final int MAX_NUMBERS = 5000;
	
	final int MIN_NUM = -100000;
	final int MAX_NUM = 100000;
	
	public static void main(String[] args) throws Exception{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		while(true){
			//項数を取得
			int numbers = Integer.parseInt(br.readLine());
			if(numbers == 0)	break;
			//各項に数字を代入
			int[] n = new int[numbers];
			for(int i = 0; i < numbers; i++){
				n[i] = Integer.parseInt(br.readLine());
			}
			//連続した項の和の最大値を出力
			System.out.println(getMaxSumSequence(n));
		}
	}
	public static long getMaxSumSequence(int[] n){
		long maxSum = n[0];
		for(int source = 0; source < n.length; source++){
			long tmpSum = (long)n[source];
			maxSum = Math.max(maxSum, tmpSum);
			for(int target = source + 1; target < n.length; target++){
				tmpSum += (long)n[target];
				maxSum = Math.max(maxSum, tmpSum);
			}
		}
		return maxSum;
	}
}

Measured memory_bytes: 19976
#include <iostream>
#include <algorithm>
#include <vector>
#include <tuple>
#include <functional>
#include <limits>
using namespace std;

int main(){
    int N;
    cin>>N;
    vector<int64_t> A(N);
    for(auto &a:A) cin>>a;
    function<int64_t(int64_t,int64_t,int64_t,int64_t)> rec = [&](int64_t l, int64_t r, int64_t lx, int64_t rx){
        if(r-l==1) return int64_t(0);
        int64_t ret = numeric_limits<int64_t>::max();
        for(int k=l+1;k<r;k++){
            ret = min(ret, rec(l,k,lx,lx+rx)+rec(k,r,lx+rx,rx)+A[k]*(lx+rx));
        }
        return ret;
    };
    cout<<rec(0,N-1,1,1)+A[0]+A[N-1]<<endl;
    return 0;
}

Measured memory_bytes: 504
import java.util.*;

class Main {
	Scanner sc = new Scanner(System.in);


	public void run() {
		while(true){
			int n=sc.nextInt();
			if(n==0)break;
			int m=sc.nextInt();

			Node[] nodes=new Node[m];
			for(int i=0;i<m;i++){
				String[] str=sc.next().split(",");
				nodes[i]=new Node(Integer.parseInt(str[0]),Integer.parseInt(str[1]),Integer.parseInt(str[2]));
			}
			UnionFind uf=new UnionFind(n);
			Arrays.sort(nodes);
			int res=0;int node=0;
			for(int i=0;i<m;i++){
				if(!uf.find(nodes[i].p1,nodes[i].p2)){
					uf.unite(nodes[i].p1,nodes[i].p2);
					res+= nodes[i].dist;
					node++;
				}
			}
			ln(res/100-node);
		}

	}
	class Node implements Comparable<Node>{
		int p1,p2,dist;

		@Override
		public int compareTo(Node o) {
			return dist-o.dist;
		}
		Node(int a,int b,int c){
			p1=a;p2=b;dist=c;
		}
	}
	public class UnionFind {
	    private int[] id;
	    private int[] sz;
	    private int components;

	    public UnionFind(int N) {
	        id = new int[N];
	        sz = new int[N];
	        components = N;
	        for (int i = 0; i < N; i++) {
	            id[i] = i;
	            sz[i] = 1;
	        }
	    }
	    public int find(int x) {
	        while (x != id[x])
	            x = id[x];
	        return x;
	    }
	    public int components() {
	        return components;
	    }
	    public boolean find(int p, int q) {
	        return find(p) == find(q);
	    }
	    public void unite(int p, int q) {
	        int i = find(p);
	        int j = find(q);
	        if (i == j) return;
	        if   (sz[i] < sz[j]) { id[i] = j; sz[j] += sz[i]; }
	        else                 { id[j] = i; sz[i] += sz[j]; }
	        components--;
	    }
	}

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

	public static void pr(Object o) {
		System.out.print(o);
	}

	public static void ln(Object o) {
		System.out.println(o);
	}

	public static void ln() {
		System.out.println();
	}
}

Measured memory_bytes: 13000
#include <iostream>
#include <string>
#include <algorithm>
#include <stdlib.h>
#include <iomanip>
#include <vector>
#include <bits/stdc++.h>
using namespace std;
//typedef long long unsigned int ll;
typedef long long ll;

int main() {
  ll n, k;
  cin >> n >> k;
  ll D[n];
  for(int i=0;i<n;i++) cin >> D[i];
  
  ll ans = 0;
  for(int a=0;a<=min(k,n);a++){
    for(int b=0;b<=min(k-a,n-a);b++){
      priority_queue< int, vector<int>, greater<int> > que;
      for(int i=0;i<a;i++) que.push(D[i]);
      for(int j=0;j<b;j++) que.push(D[n-1-j]);
      for (int i=0;i<k-a-b;i++){
        if(!que.empty()){
          if(que.top() < 0) que.pop();
        }
      }
      ll ans_tmp = 0;
      //cout << a << b << endl;
      while(!que.empty()) {
        ans_tmp += que.top();
        //cout << que.top();
        que.pop();
      }
      //cout << endl;
      ans = max(ans, ans_tmp);
    }
  }
  cout << ans << endl;
  //cout << dq.front() << endl;
  //dq.pop_front();
  //cout << dq.front() << endl;
  //cout << endl;
}

Measured memory_bytes: 256
#include <stack>
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <cmath>
#include <array>
#include <iomanip>
using namespace std;
int gcd(int a, int b)
{
   if (a%b == 0)
   {
       return(b);
   }
   else
   {
       return(gcd(b, a%b));
   }
}
int main(){
    //std::stack<int> stack;
    int n;
    cin >> n;
    pair <pair<string, int>, int> p[n];
    for(int i = 0; i < n; i++){
        string name;
        int num;
        cin >> name >> num;
        p[i] = make_pair(make_pair(name, num*(-1)), i);
    }
    sort(p, p+n);
    for(int i = 0; i < n; i++){
        cout << p[i].second+1 << endl;
    }
    return 0;
}





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

using namespace std;

int main()
{
//	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);
	long long x, y;
	cin >> x >> y;
	if (y == 0 || x % y == 0)
		cout << -1;
	else
		cout << x;
	return 0;
}

Measured memory_bytes: 256
#if __has_include("D:/dhiraj/Programming/debug.h")
    #include "D:/dhiraj/Programming/debug.h"
#else
    #include <bits/stdc++.h>
    using namespace std;
    #define d(...) 11
    #define cerr if(0) cerr
#endif

// Macro --------------------------------------------------------------------

#define ll                  long long int
#define FOR(i, a, b, s)     for(ll i = (a); ((s)>0 ? i<(b) : i>(b)); i += (s))
#define FOR1(b)             FOR(i, 0, b, 1)
#define FOR2(i, b)          FOR(i, 0, b, 1)
#define FOR3(i, a, b)       FOR(i, a, b, (a) <= (b) ? 1 :-1)
#define FOR4(i, a, b, s)    FOR(i, a, b, s)
#define GET5(a, b, c, d, e, ...) e
#define FORC(...)           GET5(__VA_ARGS__, FOR4, FOR3, FOR2, FOR1)
#define loop(...)           FORC(__VA_ARGS__)(__VA_ARGS__)
#define all(x)              x.begin(),x.end()
#define rall(x)             x.rbegin(),x.rend()
#define endl                '\n'

// Template -----------------------------------------------------------------

// multiple input
template <typename... T> 
inline void inp(T&... args) {
    ((cin>>args), ...);
}
// scan vector
template <typename T> 
inline istream &operator>>(istream &in, vector<T> &a) {
    for(auto &x : a) in >> x;
    return in;
}
// scan pair
template <typename T, typename U> 
inline istream &operator>>(istream &in, pair<T,U> &a) {
    in >> a.first >> a.second; 
    return in;
}

// Solve --------------------------------------------------------------------

void solve(int &T)
{
    ll n, m, k;
    cin>>n>>m>>k;

    vector<string> a(n);
    cin>>a;

    // auto f = [&](ll i, ll j)
    // {
    //     ll cnt = 0;
    //     loop(x,n)
    //     {
    //         loop(y,m)
    //         {
    //             if(x == i or y == j) continue;
    //             else if(a[x][y] == '#') cnt++;
    //         }
    //     }
    //     return (cnt == k);
    // };

    ll ans = 0;
    ll xx = (1ll << n);
    ll yy = (1ll << m);

    loop(i,xx)
    {
        loop(j,yy)
        {
            bitset<10> aa(i), bb(j);
            ll cnt = 0;
            loop(ii,0,n)
            {
                loop(jj,0,m)
                {
                    if(aa[ii] or bb[jj]) continue;
                    else if(a[ii][jj] == '#') cnt++;
                }
            }
            ans += (cnt == k);
        }
    }
    cout<<ans<<endl;
}

// Main ---------------------------------------------------------------------

int main()
{
    #ifdef Dhiraj
        freopen("D:/dhiraj/Programming/i1.txt","r",stdin);
        freopen("D:/dhiraj/Programming/o1.txt","w",stdout);
    #endif

    ios::sync_with_stdio(false);
    cin.tie(0);

    int t = 1;
    for(int i=1; i<=t; i++)
    {
        cerr<<"Case #"<<i<<"\n";
        solve(i);
    }
    return 0;
}

Measured memory_bytes: 3652
#include <iostream>
#include <algorithm>
#include <string>
#define flush fflush(stdout)
using namespace std;
typedef long long ll;


int main(void) {
    int n, i;
    ll ans = 0;

    cin >> n;
    
    for (i = 1; i <= n; i++) {
        if (i % 3 > 0 && i % 5 > 0) {
            ans += i;
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3624
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <cfloat>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iostream>
#include <memory>
#include <string>

#include <algorithm>
#include <complex>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <vector>

using namespace std;

#ifdef _MSC_VER
#define __typeof__ decltype
#endif

#define ITER(c)         __typeof__((c).begin())
#define FOREACH(it, c)  for (ITER(c) it=(c).begin(); it != (c).end(); ++it)
#define RITER(c)        __typeof__((c).rbegin())
#define RFOREACH(it, c) for (RITER(c) it=(c).rbegin(); it != (c).rend(); ++it)
#define REP(i, n)       REPEAT(i, 0, n)
#define REPEAT(i, k, n) for (int i = (k); i < (n); ++i)
#define REVREP(i, n)    for (int i = ((n)-1); i >= 0; --i)
#define FIND(c, n)      std::find((c).begin(), (c).end(), (n));
#define BSEARCH(c, n)   std::binary_search((c).begin(), (c).end(), (n))
#define LLPOW(p1,p2)    ((ll)pow((double)(p1), (int)p2))
#define ESIZEOF(A)      (sizeof(A)/sizeof((A)[0]))
#define MIN(p1,p2)      (((p1)<(p2))?(p1):(p2))
#define MAX(p1,p2)      (((p1)>(p2))?(p1):(p2))
#define CIN_NO_SYNC     do { cin.tie(0); ios_base::sync_with_stdio(false); } while(0)
#define GETSTR(p)       fgets((p), sizeof(p), stdin)
#define CHOMP(p)        do{ char *_q = (p) + strlen(p)-1; if(*_q == '\n' || *_q == '\r') *_q = 0; } while(0)

typedef long long ll;
typedef unsigned long long ull;

#ifdef _DEBUG
#define pf printf
#define pr(n) do { cout << #n " = " << (n) << endl; } while(0)
#else
#define pf(...) /* */
#define pr(...) /* */
#endif

int main(){
    char buf[1024];
    GETSTR(buf);
    CHOMP(buf);
    int n;
    sscanf(buf, "%d", &n);

    REP(i,n){
        GETSTR(buf);
        CHOMP(buf);
        int len = strlen(buf);
        std::sort(buf, buf+len);
        int p1, p2;
        sscanf(buf, "%d", &p1);
        std::sort(buf, buf+len, std::greater<char>());
        sscanf(buf, "%d", &p2);
        printf("%d\n", p2-p1);
    }

    return 0;
}

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

#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n)-1;i>=0;i--)
#define rrep2(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define all(a) (a).begin(),(a).end()

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

const ll inf = 1e15;
ll dp[20001][256];

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

    int N, M;
    while (cin >> N >> M && N) {
        vi C(M);
        rep(i, M) cin >> C[i];
        vi x(N);
        rep(i, N) cin >> x[i];

        rep(i, N + 1) rep(j, 256) dp[i][j] = inf;
        dp[0][128] = 0;
        rep(i, N) {
            rep(j, 256) {
                if (dp[i][j] == inf) continue;
                rep(k, M) {
                    int nxtj = j + C[k];
                    if (nxtj < 0) nxtj = 0;
                    if (nxtj > 255) nxtj = 255;
                    dp[i + 1][nxtj] = min(dp[i + 1][nxtj], dp[i][j] + (x[i] - nxtj) * (x[i] - nxtj));
                }
            }
        }

        ll ans = inf;
        rep(j, 256) ans = min(ans, dp[N][j]);
        cout << ans << endl;

    }
}

Measured memory_bytes: 43224