akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
 
using namespace std;

const int N = 3005;

int dp[N][N];

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

    string s, t;
    cin >> s >> t;
    int n = (int) s.size(), m = (int) t.size();
    for (int i = 0; i <= n; i++) {
        for (int j = 0; j <= m; j++) {
            if (i == 0 || j == 0) continue;
            if (s[i - 1] == t[j - 1]) dp[i][j] = dp[i - 1][j - 1] + 1;
            else dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]); 
        }
    }
    int x = n, y = m;
    string ans = "";
    while (x > 0 && y > 0) {
        if (s[x - 1] == t[y - 1]) {
            ans += s[x - 1];
            x--, y--;
        }
        else if (dp[x - 1][y] > dp[x][y - 1]) x--;
        else y--;
    }
    reverse(ans.begin(), ans.end());
    cout << ans << '\n';
}

Measured memory_bytes: 38844
#include<iostream>
#include<algorithm>
using lint=int64_t;
using namespace std;

int main()
{
	int N;
	int a[100010]{};

	cin >> N;
	for(int i=0;i<N;i++)
		cin >> a[i];
	
	int A=a[0];
	for(int i=1;i<N;i++)
		A=A xor a[i];
	
	if(A==0)cout << "Yes";
	else cout << "No";
	cout << endl;
	return 0;
}



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

int main()
{
  int n;cin>>n;
  int a[n],b[n];
  for(int i=0;i<n;i++) cin>>a[i];
  for(int i=0;i<n;i++) cin>>b[i];
  int ans(0);
  
  for(int i=0;i<n;i++)
    if(a[i]>b[i]) ans+=(a[i]-b[i]);
  
  cout<<ans;
}

Measured memory_bytes: 256
#include <iostream>

int main() {
  int a, b, result;
  char op;
  while (true) {
    std::cin >> a >> op >> b;
    switch (op) {
    case '+':
      result = a + b;
      break;
    case '-':
      result = a - b;
      break;
    case '/':
      result = a / b;
      break;
    case '*':
      result = a * b;
      break;
    default:
      return 0;
    }
    std::cout << result << std::endl;
  }
}



Measured memory_bytes: 3088
#include<bits/stdc++.h>
using namespace std;
#define S second
//#define int long long
typedef long long ll;
#define sqr(x) ((x)*(x))
#define pb push_back
const int N=1000002,M=998244353;
int pw(int x,int y){int z=1;for(;y;y>>=1,x=1ll*x*x%M)if(y&1)z=1ll*z*x%M;return z;}
void inc(int &x,int y){x+=y;if(x>=M)x-=M;}void dec(int &x,int y){x-=y;if(x<0)x+=M;}
void Max(int &x,int y){if(y>x)x=y;}void Min(int &x,int y){if(y<x)x=y;}
int tot,x,y,n,i,m,le[N],l,now,z,ans[302][302],Q;
int dis[302],h[N];
struct node{int to,ne,w;}e[N];
void add(int x,int y,int z){e[++tot]=(node){y,h[x],z},h[x]=tot;}
priority_queue<pair<int,pair<int,int> > >q;
void spfa(int s){
	q.push({0,{0,s}});
	memset(dis,63,sizeof(dis));
	dis[s]=0,le[s]=0;
	while (!q.empty()){
		int u=q.top().S.S;q.pop();
		for (int i=h[u],v;i;i=e[i].ne)
			if (le[u]<e[i].w){
				if (e[i].w<=l){
					if (dis[v=e[i].to]>dis[u]+1 || dis[v]==dis[u]+1 && le[v]<l-e[i].w)
					dis[v=e[i].to]=dis[u]+1,le[v]=l-e[i].w,
					q.push({-dis[v],{le[v],v}});
				}
			}else{
				if (dis[u]<dis[v=e[i].to] || dis[u]==dis[v] && le[v]<le[u]-e[i].w)
				dis[v]=dis[u],le[v]=le[u]-e[i].w,q.push({-dis[v],{le[v],v}});
			}
	}
	for (int i=1;i<=n;i++) ans[now][i]=dis[i]>1e9?-1:dis[i]-1;
}
signed main(){
	scanf("%d%d%d",&n,&m,&l);
	for (i=1;i<=m;i++) scanf("%d%d%d",&x,&y,&z),add(x,y,z),add(y,x,z);
	for (i=1;i<=n;i++) now=i,spfa(i);
	scanf("%d",&Q);
	for (;Q--;){
		scanf("%d%d",&x,&y);
		printf("%d\n",ans[x][y]);
	}
}

Measured memory_bytes: 5632
import java.util.Scanner;

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

			int n = sc.nextInt();
			
			long sum = 0;
			for(int i = 1 ; i <= n ; i++ ) {
				if ( i % 3 != 0 && i % 5 != 0 ) {
					sum+=i;
				}
			}
			System.out.println(sum);
			
		}
	}

}

Measured memory_bytes: 35760
#include <stdio.h>
 
#define min(a,b) (a < b ? a : b)
#define max(a,b) (a < b ? b : a)
#define INF 2e9
 
int main(){
  int N,i,res = -INF,x,y = INF;
  scanf("%d",&N);
  for(i = 0 ; i < N ; i++){
    scanf("%d",&x);
    res = max(res,x-y);
    y = min(x,y);
  }
  printf("%d\n",res);
  return 0;
}


Measured memory_bytes: 2112
n = int(input())
S = list(map(int,input().split()))
q = int(input())
T = list(map(int,input().split()))

def find(key,l,r):
    m = int(l+(r-l)/2)
    #print(str(key) + " " + str(l) + " " + str(m) + " " + str(r))
    if key == S[m]:
        return True
    elif r-l <= 1:
        return False
    elif key < S[m]:
        return find(key,l,m)
    elif key > S[m]:
        return find(key,m+1,r)

cnt = 0
for x in T:
    if find(x,0,n) is True:
        cnt += 1
    
print(cnt)


Measured memory_bytes: 16708
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <string>
#include <functional>
#include <set>
#define DB cerr<<"D"<<endl
#define pb push_back
using namespace std; using ll=long long; using ld=long double; const int INF=1e9; const ll LINF=1e18; const double dINF = 1e18; const ld ldINF = 1e18; const double EPS = 1e-6;
template<typename T, typename U, typename O> void caut(T a, U b, O c){cout<<"("<<a<<","<<b<<","<<c<<") ";} template<typename T, typename U> void caut(T a, U b){cout<<"("<<a<<","<<b<<") ";} template<typename T> void caut(T a){cout<<"("<<a<<") ";}
using P=pair<ll,ll>;
const ll M = 1e9+7;
void add(ll& x, ll y) {x+=y; x%=M;}
void chmax(ll& x, ll y) {if (x<y) x=y;}

int main() {
  int n,k; cin>>n>>k;
  int a[n]; for(int i=0;i<n;i++) cin>>a[i];

  int t = 0;

  for(int i=0;i<k;i++) {
    bool end = true;
    for(int j=0;j<n;j++) {
      if (a[j] != n) {end = false; break;}
    }
    if (end) break;
    int sm[n]={};

    for(int j=0;j<n;j++) {
      int lf = max(0, j - a[j]);
      int ri = j + a[j] + 1;
      sm[lf]++;
      if (ri < n) sm[ri]--;
    }

    for(int j=1;j<n;j++){
      sm[j] += sm[j-1];
    }
    copy(sm,sm+n,a);
    t++;
  }
  
  for(int i=0;i<n;i++) {
    cout<<a[i]<<" ";
  } cout<<endl;
}

Measured memory_bytes: 5124
class Dictionary:
    def __init__(self):
        self.elements = set()
    def insert(self, x):
        self.elements.add(x)
    def find(self, y):
        if y in self.elements:
            print('yes')
        else:
            print('no')

import sys

n = int(sys.stdin.readline())

simple_dict = Dictionary()

for i in range(n):
    operation = sys.stdin.readline()
    if operation[0] == 'i':
        simple_dict.insert(operation[7:])
    else:
        simple_dict.find(operation[5:])

Measured memory_bytes: 33636
#include <bits/stdc++.h>
using namespace std;
#include <atcoder/all>
using namespace atcoder;
#define ll long long
#define ld long double
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,(n)-1,0)
#define all(v) v.begin(), v.end()
#define endk '\n'
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;
const ll mod2 = 998244353;
const ld eps = 1e-10;
template<typename T1, typename T2> inline void chmin(T1 &a, T2 b){if(a>b) a=b;}
template<typename T1, typename T2> inline void chmax(T1 &a, T2 b){if(a<b) a=b;}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, m; cin >> n >> m;
  vector<int> A(m), B(m);
  dsu uf(n);
  int ans = n-1;
  rep(i, m) {
    cin >> A[i] >> B[i];
    A[i]--; B[i]--;
    if(!uf.same(A[i], B[i])) ans--;
    uf.merge(A[i], B[i]);
  }
  cout << ans << endk;
  return 0;
}


Measured memory_bytes: 4552
#include "bits/stdc++.h"

using namespace std;
using ll = long long;
const double pi = acos(-1);
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
	REP(i, v.size()) { if (i)os << " "; os << v[i]; }return os;
}
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) {
	REP(i, v.size()) { if (i)os << endl; os << v[i]; }return os;
}

const ll INF = 1LL << 60;
ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;

#define int long long

inline void my_io() {

	std::ios::sync_with_stdio(false);

	std::cin.tie(0);

	cout << fixed << setprecision(10);

}

signed main() {
	ll n;
	ll ans;

	cin >> n;

	vector<ll> v(n, 0);

	REP(i, n) {
		cin >> v[i];
	}

	sort(v.begin(), v.end(), greater<ll>());

	ans = v[0] / 2;

	FOR(i, 1, n) {
		ans += v[i];
	}

	cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.*;
import static java.lang.Math.abs;

class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt(); //配列の要素数
        int[] A = new int[N]; //入力された値の配列
        int[] B = new int[N]; //上記の配列の絶対値をとった配列
        boolean jud = true;
        int w = 0;
        long ans = 0;         //答え
        //入力
        for(int i = 0;i < N;i++){
            A[i] = sc.nextInt();
            B[i] = abs(A[i]);
        }

        Arrays.sort(A);
        Arrays.sort(B);

        //絶対値の一番小さい値と配列の一番後ろを交換
        while(jud == true){
            if(B[0] == A[w]){
                A[w] = A[N-1];
                A[N-1] = B[0];
                jud = false;
            }else if(B[0] == A[w]*(-1)){
                A[w] = A[N-1];
                A[N-1] = B[0] *(-1);
                jud = false;
            }
            w++;
        }

        //負の値を見つけ-1を乗算
        for(int i = 0;i < N-1;i++){
            if(A[i] < 0){
                A[i] = A[i] * (-1);
                A[i+1] = A[i+1] * (-1);
            }
        }

        //配列の和を計算
        for(int i = 0;i < N;i++){
            ans += A[i];
        }
        //出力
        System.out.println(ans);
    }
}

Measured memory_bytes: 50328
#include <cstdio>
#include <algorithm>
#define rep(i,n) for(int i=0;i<n;i++)
int main(){
    int a[5];
    rep(i, 5) scanf("%d", a + i);
    rep(i, 5) rep(j, 5) if(a[i] > a[j]) std::swap(a[i], a[j]);
    rep(i, 5) printf("%d%c", a[i], i == 4 ? '\n' : ' ');
    return 0;
}

Measured memory_bytes: 1024
import java.text.*;
import java.util.*;

public class Main {
    public static void main(String[] args) {

        Locale.setDefault(Locale.JAPAN);
        Scanner sc = new Scanner(System.in);
        String a = sc.next();//A

        try {
            // 日付1を「A」に設定
            Date date1 = DateFormat.getDateInstance().parse(a);
            // 日付2を「2019/4/30」に設定
            Date date2 = DateFormat.getDateInstance().parse("2019/04/30");

            // 2つの日付を比較し、結果によってメッセージを変えます
            int diff = date1.compareTo(date2);
            if (diff > 0) {
                System.out.println("TBD");
            } else {
                System.out.println("Heisei");
            }

        } catch (ParseException e) {
            e.printStackTrace();
        }
    }
}


Measured memory_bytes: 22096
#include<iostream>
#include<string>
using namespace std;

int main(void){
    int count = 0;
    string s, keyence = "keyence";
    cin >> s;
    int len = s.size();
    int i = 0;
    while(s[i] == keyence[i++]){
        count++;
        if(count == 7){
            cout << "YES" << endl;
            return 0;
        }
    }
    i = 0;
    while(s[len-1-i] == keyence[6-i]){
        i++;
        count++;
        if(count == 7){
            cout << "YES" << endl;
            return 0;
        }
    }
    cout << "NO" << endl;
    return 0;
}

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

vector<pair<int, int>> graph[100005];
bool visited[100005];
int coord[100005];
int cmx, cmn;
bool feasible;

void dfs(int ni, int pos) {
  if (visited[ni]) return;
  visited[ni] = true;
  coord[ni] = pos;
  cmx = max(cmx, pos);
  cmn = min(cmn, pos);
  for (auto x : graph[ni]) {
    if (visited[x.first]) {
      if (coord[x.first] - pos != x.second) {
        feasible = false;
      }
    } else {
      dfs(x.first, pos + x.second);
    }
    if (!feasible) break;
  }
}

int main() {
  int n, m;
  cin >> n >> m;
  for (int mi = 0; mi < m; mi++) {
    int l, r, d;
    cin >> l >> r >> d;
    graph[l].push_back({r, d});
    graph[r].push_back({l, -d});
  }
  feasible = true;
  for (int ni = 0; ni < n; ni++) {
    if (!visited[ni]) {
      cmx = 0;
      cmn = 0;
      dfs(ni, 0);
      if (cmx - cmn > 1000000000) feasible = false;
    }
  }
  if (feasible) {
    cout << "Yes\n";
  } else {
    cout << "No\n";
  }
  return 0;
}


Measured memory_bytes: 11136
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		String s = sc.nextLine();
		String t = sc.nextLine();

		sc.close();


		if (s.equals(t.substring(0, t.length()-1)) &&
				t.matches(s + "[a-z]")) {
				//t.substring(t.length(), t.length()).matches("[a-z]")) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}

	}

}

Measured memory_bytes: 26948
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#define debug(x) cerr << #x << " = " << x << endl;


#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 100010


int main(){
  int n;
  ll a[SIZE];

  scanf("%d",&n);
  for(int i=0;i<n;i++) scanf("%lld",a+i);

  ll t = 0;
  ll ans = 0;
  
  for(int i=0;i<n;i++){
    ll q = (a[i]-1)/(t+1);
    a[i] = a[i]-q*(t+1);

    if(q >= 1){
      a[i] = 1;
    }

    t = max(t,a[i]);
    
    ans += q;
  }

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


Measured memory_bytes: 1024
#include <iostream>

using namespace std;

int N;
int nums[200];

int main(){
  	cin >> N;
	for(int i=0; i<N; i++) cin >> nums[i];  
  	
  	int breakFlag = 0;
  	int count = 0;
  	while(true){
    	for(int i=0; i<N; ++i){
      		if(nums[i]%2 == 0){
              nums[i] /= 2; 
              
            }else{
              breakFlag++;
              break;
            }
    	}
      
      	if(breakFlag > 0){
          break;
        }
        count++;
    }
	cout << count;            
}

Measured memory_bytes: 256
import java.io.*;
import java.util.ArrayList;
import java.util.Stack;

class Main {
    public static void main (String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        
        String input = br.readLine();
        Stack<Integer> stack = new Stack<Integer>();
        ArrayList<int[]> puddles = new ArrayList<int[]>();

        for (int i = 0; i < input.length(); i++) {
            if (input.charAt(i) == '\\') {
                stack.push(i);
            } else if (input.charAt(i) == '/' && !stack.empty()) {
                puddles.add(new int[] {stack.pop(), i});
            }
        }

        ArrayList<Integer> areas = new ArrayList<Integer>();
        int area;
        int totalArea = 0;
        for (int i = 0; i < input.length(); i++) {
            for (int[] puddle: puddles) {
                if (puddle[0] == i) {
                    area = puddle[1] - puddle[0] + calcArea(puddle[0] + 1, puddle[1] - 1, puddles);
                    areas.add(area);
                    totalArea += area;
                    i = puddle[1] + 1;
                }
            }
        }

        StringBuilder sb = new StringBuilder();
        sb.append(totalArea).append("\n").append(areas.size());
        if (areas.size() > 0) {
            sb.append(" ").append(areas.remove(0));
            for (int a: areas) {
                sb.append(" ").append(a);
            }
        }

        System.out.println(sb.toString());
    }

    public static int calcArea(int first, int last, ArrayList<int[]> puddles) {
        int area = 0;
        for (int i = first; i < last; i++) {
            for (int[] puddle: puddles) {
                if (puddle[0] == i) {
                    area += puddle[1] - puddle[0] + calcArea(puddle[0] + 1, puddle[1] - 1, puddles);
                    i = puddle[1] + 1;
                }
            }
        }
        return area;
    }
}

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

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

    cin >> a;

    if(a % 10 == 7 || a % 100 /10 ==7 || a / 100==7){
        cout << "Yes";
    }else{
        cout << "No";
    }

}


Measured memory_bytes: 3652
#include<bits/stdc++.h>
#define MAXN 200005
#define INF 1000000000
#define MOD 1000000007
#define F first
#define S second
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int n,ans[MAXN];
string str;
int mod1[MAXN],mod2[MAXN];
int main()
{
    scanf("%d",&n);
    for(int i=1;i<=200000;i++)
    {
        int cnt=__builtin_popcount(i);
        ans[i]=ans[i%cnt]+1;
    }
    cin>>str;
    int cnt=0;
    for(int i=0;i<n;i++) if(str[i]=='1') cnt++;
    mod1[0]=1;
    for(int i=1;i<=200000;i++) mod1[i]=2LL*mod1[i-1]%(cnt+1);
    if(cnt>1)
    {
        mod2[0]=1;
        for(int i=1;i<=200000;i++) mod2[i]=2LL*mod2[i-1]%(cnt-1);
    }
    int res1=0,res2=0;
    for(int i=0;i<n;i++)
    {
        res1=(2LL*res1+(str[i]-'0'))%(cnt+1);
        if(cnt>1) res2=(2LL*res2+(str[i]-'0'))%(cnt-1);
    }
    for(int i=0;i<n;i++)
    {
        if(str[i]=='0')
        {
            int tmp=(res1+mod1[n-i-1])%(cnt+1);
            printf("%d\n",ans[tmp]+1);
        }
        else
        {
            if(cnt==1) puts("0");
            else
            {
                int tmp=(res2-mod2[n-i-1])%(cnt-1);
                if(tmp<0) tmp+=cnt-1;
                printf("%d\n",ans[tmp]+1);
            }
        }
        
    }
    return 0;
}

Measured memory_bytes: 6256
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <cmath>
using namespace std;

string s;
int cnt[3];

signed main()
{
	int i;
	
	cin >> s;
	for (i = 0; i < s.length(); i++) {
		cnt[s[i] - 'a']++;
	}
	
	int maxi = 0;
	for (i = 0; i < 3; i++) {
		maxi = max(maxi, cnt[i]);
	}
	
	int jyogen = (s.length() + 2) / 3;
	
	if (maxi <= jyogen) { cout << "YES" << endl; }
	else { cout << "NO" << endl; }
	return 0;
}

Measured memory_bytes: 512
import java.util.Scanner;

public class Main{
	static long mod = (long)10e9+7;
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int[] V = new int[N];
		int[] C = new int[N];
		for(int i = 0; i < N; i++) V[i] = sc.nextInt();
		for(int i = 0; i < N; i++) C[i] = sc.nextInt();

		int ans = 0;
		for(int i = 0; i < N; i++) {
			ans += Math.max(0, V[i] - C[i]);
		}
		System.out.println(ans);
	}
}

Measured memory_bytes: 23636
def main():
    n = int(input())
    l = [list(map(int,input().split())) for _ in range(n)]

    for i in range(101):
        for j in range(101):
            k = 0
            while True:
                if l[k][2] == 0:
                    k += 1
                else:break
            h = l[k][2] + abs(l[k][0] - i) + abs(l[k][1] - j)
            flag = 0
            for sl in l:
                if max(h - abs(sl[0] - i) - abs(sl[1] - j),0) == sl[2]:
                    flag += 1
                else: break
            if flag == n:
                return [i,j,h]
    
    return False

print(" ".join(map(str,main())))

Measured memory_bytes: 41200
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll,ll>;
using vl = vector<ll>;
using Map = map<ll,ll>;
using T = tuple<ll,ll,ll>;
using vvl = vector<vector<ll>>;
#define all(v) v.begin(), v.end()
#define prt(v) cout<<v<<"\n";
#define fi(v) get<0>(v)
#define se(v) get<1>(v)
#define th(v) get<2>(v)
#define endl "\n"
template <typename T> bool chmax(T &a, const T &b){if (a<b){a=b;return 1;}return 0;}
template <typename T> bool chmin(T &a, const T &b){if (a>b){a=b;return 1;}return 0;}
const ll INF=1LL<<60;
const ll MOD=1000000007;


signed main(void){
    cin.tie(0);cout.tie(0);ios::sync_with_stdio(false);
    ll N;
    cin >> N;
    ll W;
    cin >> W;
    vector<ll> w(N,0);
    vector<ll> v(N,0);
    for(ll i=0;i<N;++i)cin>>w[i]>>v[i];
    vector<ll> a(0);
    vector<ll> b(0);
    vector<ll> c(0);
    vector<ll> d(0);
    for(ll i=0;i<N;++i){
        if(w[i]==w[0])a.emplace_back(v[i]);
        else if(w[i]==w[0]+1)b.emplace_back(v[i]);
        else if(w[i]==w[0]+2)c.emplace_back(v[i]);
        else if(w[i]==w[0]+3)d.emplace_back(v[i]);
    }
    sort(a.rbegin(), a.rend());
    sort(b.rbegin(), b.rend());
    sort(c.rbegin(), c.rend());
    sort(d.rbegin(), d.rend());
    ll A=a.size(),B=b.size(),C=c.size(),D=d.size();
    vector<ll> sua(A+1,0);
    vector<ll> sub(B+1,0);
    vector<ll> suc(C+1,0);
    vector<ll> sud(D+1,0);
    for(ll i=1;i<=A;++i)sua[i]=sua[i-1]+a[i-1];
    for(ll i=1;i<=B;++i)sub[i]=sub[i-1]+b[i-1];
    for(ll i=1;i<=C;++i)suc[i]=suc[i-1]+c[i-1];
    for(ll i=1;i<=D;++i)sud[i]=sud[i-1]+d[i-1];

    ll ans=0;
    for(ll i=0;i<=N&&i<=A;++i){
        for(ll j=0;j<=N-i&&j<=B;++j){
            for(ll k=0;k<=N-i-j&&k<=C;++k){
                for(ll l=0;l<=N-i-j-k&&l<=D;++l){
                    if(w[0]*i+(w[0]+1)*j+(w[0]+2)*k+(w[0]+3)*l>W)continue;
                    chmax(ans,sua[i]+sub[j]+suc[k]+sud[l]);
                }
            }
        }
    }
    prt(ans)

    return 0;
}


Measured memory_bytes: 256
/*This is the solution from Ling2Feng1, no matter AC or not.*/
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<cstdio>
#include<string>
#include<vector>
#include<math.h>
#include<time.h>
#include<utility>
#include<cstdlib>
#include<sstream>
#include<cstring>
#include<stdio.h>
#include<iomanip>
#include<iostream>
#include<algorithm>
using namespace std;
string s;
int main(){
	cin>>s;
	for(int i=0;i<s.size()-1;i++){
		if(s[i]=='A'&&s[i+1]=='C'){
			cout<<"Yes"<<endl;
			return 0;
		} 
	}
	cout<<"No"<<endl;
	return 0;
}

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

template <typename T> T gcd(T x, T y) {
  if (y == 0)
    return x;
  return gcd(y, x % y);
}

template <typename T> T lcm(T x, T y) {
  if (x == 0 || y == 0)
    return 0;
  return x / gcd(x, y) * y;
}

int ctoi(char c) {
  if (c >= '0' && c <= '9') {
    return c - '0';
  }
  return 0;
}

vector<int> p;
vector<int> r;

void init(int n) {
  p.reserve(n);
  r.reserve(n);
  for (int i = 0; i < n; i++) {
    p[i] = i;
    r[i] = 0;
  }
}

int root(int x) { return p[x] == x ? x : p[x] = root(p[x]); }

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

void unite(int x, int y) {
  x = root(x);
  y = root(y);
  if (x == y)
    return;

  if (r[x] < r[y])
    p[x] = y;
  else {
    p[y] = x;
    if (r[x] == r[y])
      r[x]++;
  }
}

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

  cout << setprecision(10) << (1 + (d != 0)) * (m - 1) * (n - d) / n / n
       << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<stack>
#include<algorithm>
#include<limits.h>
#include<string>
#include<math.h>
#include<map>
#include<deque>
#include<unordered_map>
using namespace std;

int main(){
	int N, W;
	long long int sum = 0;
	int ans = 0;
	cin>>N>>W;
    int value[N+1];
    int weight[N+1];
    for(int i=1;i<=N;i++){
    	cin>>weight[i];
    	cin>>value[i];
    	sum+=value[i];
    }
    long long int dp[100001][N+1];
    dp[0][0] = 0;
    for(int i=1;i<=100000;i++)
    	for(int j=0;j<=N;j++)
    		dp[i][j]=W+1;

    for(int i=1;i<=sum;i++){
    	for(int j=1;j<=N;j++){
    		dp[i][j] = dp[i][j-1];
    		if(value[j]<=i){
    			dp[i][j] = min(dp[i][j], dp[i-value[j]][j-1]+weight[j] );
    		}
    		if(dp[i][j]<=W)
    			ans = max(ans,i);
    	}
    }	
    cout<< ans;	
}









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

typedef long long ll;
const int INF = 1e9;
const ll LINF = 1e18;
const int mod = 1e9+7;

#define pi pair<int,int>
#define pl pair<lld,lld>

#define dump(x) cout << #x << " = " << (x) << endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define SANKOU(n,a,b) cout << ((n) ? (#a) : (#b) ) << endl

#define mem0(x) memset(x,0,sizeof(x))
#define fillnum(x,n) fill(begin(x),end(x),n)
#define asort(x) sort(x.begin(),x.end())
#define dsort(x,t) sort(x.begin(),x.end(),greater<t>())
#define vuniq(x) x.erase(unique(x.begin(), x.end()), x.end())

#define pb(a) push_back(a)
#define mp(a,b) make_pair(a,b)

int main() {
    ll N,A,B;
    cin >> N >> A >> B;
    ll cnt[3];
    mem0(cnt);
    for (int i = 0; i < N; i++) {
        ll P; cin >> P;
        if(B+1 <= P){
            cnt[2]++;
        } else if(P >= A+1 && P <= B){
            cnt[1]++;
        } else {
            cnt[0]++;
        }
    }
    cout << min(min(cnt[0],cnt[1]),cnt[2]) << endl;
}

Measured memory_bytes: 3568
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream>

using namespace std;

int n;
int k;
const int maxn = 2e5 + 5;
int a[maxn];
long long sum[maxn];
long long tmp[maxn];
int id[maxn];
int c[maxn];

void add(int x){
    for(int i = x;i < maxn;i += i & -i) c[i] += 1;
}

int Sum(int x){
    int ret = 0;
    for(int i = x;i > 0;i -= i & -i) ret += c[i];
    return ret;
}


int main(){
    while(cin >> n){
        memset(c,0,sizeof(c));
        cin >> k;
        sum[0] = 0;
        for(int i = 1;i <= n;i++){
            scanf("%d",a + i);
            a[i] -= k;
            sum[i] = sum[i - 1] + a[i];
            tmp[i] = sum[i];
        }
        tmp[n + 1] = 0;
        sort(tmp + 1,tmp + n + 2);
        int tot = unique(tmp + 1,tmp + 2 + n) - tmp - 1;
        //cout << tot << endl;
        for(int i = 0;i <= n;i++){
            id[i] = lower_bound(tmp + 1, tmp + 1 + tot, sum[i]) - tmp;
        }
//        for(int i = 0;i <= n;i++){
//           // cout << a[i] << endl;
//            cout << sum[i] << endl;
//            //cout << id[i] << endl;
//        }
        long long ans = 0;
        for(int i = 1;i <= n;i++){
            add(id[i - 1]);
            ans += Sum(id[i]);
        }
        cout << ans << endl;
    }
    
    return 0;
}

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

ARR = []
for i in range(N):
    ARR.append([int(s) for s in input().split(" ")])

CRR = []
for i in range(N):
    CRR.append([int(s) for s in input().split(" ")])


def calculate(n, arr, crr):

    reds = sorted(arr,key=lambda x:-x[1])
    blues = sorted(crr,key=lambda x:x[0])
    counts = 0

    for i,bl in enumerate(blues):
        for j,rd in enumerate(reds):

            if (rd[0] < bl[0]) and (rd[1] < bl[1]):
                counts = counts + 1
                reds[j][1] = 1000
                reds[j][0] = 1000
                break
    print(counts)

calculate(N, ARR, CRR)


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

int main()
{
	int n, tmp, cnt = 0;
	int a[51];
	cin >> n;
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
	}

	for (int i = 1; i <= n; i++) {
		if (i != a[i] && cnt ==0) {
			tmp = i;
			cnt++;
		}
		else if (i != a[i] && cnt == 1) {
			swap(a[i], a[tmp]);
			cnt++;
		}
		else if (cnt > 2) {
			cout << "NO" << endl;
			return 0;
		}
	}

	for (int i = 1; i <= n; i++) {
		if (i != a[i]) {
			cout << "NO" << endl;
			return 0;
		}
	}
	cout << "YES" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#define rep(i, n) for (int i = (int)(0); i < (int)(n); ++i)
#define reps(i, n) for (int i = (int)(1); i <= (int)(n); ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; i--)
#define irep(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define ireps(i, m, n) for (int i = (int)(m); i <= (int)(n); ++i)
#define FOR(e, c) for (auto &e : c)
#define SORT(v, n) sort(v, v + n);
#define vsort(v) sort(v.begin(), v.end());
#define rvisort(v) sort(v.begin(), v.end(), greater<int>());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
// #define int long long
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
 
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using ul = unsigned long;
 
const int MOD = 1e9+7;
const int INF = 1e9;
const ll LINF = 1e18;
 
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
 
int GCD(int a, int b) { return b ? GCD(b, a%b) : a; }
int LCM(int a, int b) { return a * b / GCD(a, b); }
 
 
signed main()
{
  ll n;cin>>n;
  ll ans=LINF;
  for(ll i=1; i*i<=n; i++){
    if(n%i==0){
      ll a=n/i;
      ll tmp=i-1+a-1;
      chmin(ans,tmp);
    }
  }
  cout<<ans<<endl;
}

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

#include <vector>
#include <cctype>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <string>

using namespace std;


int main()
{
    long long N;

    cin >> N;

    int cou = 0;

   
    long long num2=N;
    string ans="";
    while (N) {
        char s = (N-1)% 26 +'a';
        ans = ans + s;

        N = (N-1) / 26;
    }
        
    reverse(ans.begin(), ans.end());

    cout << ans<<endl;

    return 0;
}

Measured memory_bytes: 3600
import sys

n, *a = map(int, sys.stdin.read().split())

def main():
    c4 = c2 = 0
    for x in a:
        if not x % 4: c4 += 1
        elif not x % 2: c2 += 1
    ans = 'Yes' if c4 >= n // 2 or c4 * 2 + c2 >= n else 'No'
    print(ans)

if __name__ ==  '__main__':
    main()

Measured memory_bytes: 14052
import sys,bisect

input=sys.stdin.readline

N=int(input())
robot=[]
for i in range(N):
    X,L=map(int,input().split())
    robot.append((X+L,L))

robot.sort()
pos=[robot[i][0] for i in range(N)]
arm=[-1]*N
for i in range(0,N):
    index=bisect.bisect_right(pos,robot[i][0]-2*robot[i][1])
    arm[i]=index-1

dp=[0]*N
dp[0]=1
Max=[0]*N
Max[0]=1
for i in range(1,N):
    if arm[i]==-1:
        dp[i]=1
    else:
        dp[i]=1+Max[arm[i]]
    Max[i]=max(dp[i],Max[i-1])

print(max(dp))

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

using namespace std;

using int64 = long long;
const int mod = 998244353;

const int64 infll = (1LL << 62) - 1;
const int inf = (1 << 30) - 1;

struct IoSetup {
  IoSetup() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    cerr << fixed << setprecision(10);
  }
} iosetup;


template< typename T1, typename T2 >
ostream &operator<<(ostream &os, const pair< T1, T2 > &p) {
  os << p.first << " " << p.second;
  return os;
}

template< typename T1, typename T2 >
istream &operator>>(istream &is, pair< T1, T2 > &p) {
  is >> p.first >> p.second;
  return is;
}

template< typename T >
ostream &operator<<(ostream &os, const vector< T > &v) {
  for(int i = 0; i < (int) v.size(); i++) {
    os << v[i] << (i + 1 != v.size() ? " " : "");
  }
  return os;
}

template< typename T >
istream &operator>>(istream &is, vector< T > &v) {
  for(T &in : v) is >> in;
  return is;
}

template< typename T1, typename T2 >
inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }

template< typename T1, typename T2 >
inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

template< typename T = int64 >
vector< T > make_v(size_t a) {
  return vector< T >(a);
}

template< typename T, typename... Ts >
auto make_v(size_t a, Ts... ts) {
  return vector< decltype(make_v< T >(ts...)) >(a, make_v< T >(ts...));
}

template< typename T, typename V >
typename enable_if< is_class< T >::value == 0 >::type fill_v(T &t, const V &v) {
  t = v;
}

template< typename T, typename V >
typename enable_if< is_class< T >::value != 0 >::type fill_v(T &t, const V &v) {
  for(auto &e : t) fill_v(e, v);
}

template< typename F >
struct FixPoint : F {
  FixPoint(F &&f) : F(forward< F >(f)) {}

  template< typename... Args >
  decltype(auto) operator()(Args &&... args) const {
    return F::operator()(*this, forward< Args >(args)...);
  }
};

template< typename F >
inline decltype(auto) MFP(F &&f) {
  return FixPoint< F >{forward< F >(f)};
}


template< typename T, typename Compare = greater< T > >
vector< T > knapsack(const vector< int > &w, const vector< T > &v, const int &W, const T &NG, const Compare &comp = Compare()) {
  const int N = (int) w.size();
  vector< T > dp(W + 1, NG);
  dp[0] = T();
  for(int i = 0; i < N; i++) {
    for(int j = w[i]; j <= W; j++) {
      if(dp[j - w[i]] != NG) {
        if(comp(dp[j - w[i]] + v[i], dp[j])) {
          dp[j] = dp[j - w[i]] + v[i];
        }
      }
    }
  }
  return dp;
}


int main() {
  int N, W;
  cin >> N >> W;
  vector< int > v(N), w(N);
  for(int i = 0; i < N; i++) cin >> v[i] >> w[i];
  auto ret = knapsack(w, v, W, -1);
  cout << *max_element(begin(ret), end(ret)) << endl;
}



Measured memory_bytes: 3252
#include<iostream>
#include<stdlib.h>
#include<cstring>
using namespace std;

int main(){
     int map[20][20]={};
     int H,W,h,w,sum;
     cin >> H >> W;
     cin >> h >> w;
     sum = 0;
     for(int i = 0; i < H; i++){
          for(int j = 0; j < W; j++){
               map[i][j] = 1;
          }
     }
     for(int i = 0; i < h; i++){
          for(int j = 0; j < W; j++){
               map[i][j] = 0;
          }
     }
     for(int j = 0; j < w; j++){
          for(int i = 0; i < H; i++){
               map[i][j] = 0;
          }
     }
     for(int i = 0; i < H; i++){
          for(int j = 0; j < W; j++){
               sum += map[i][j];
          }
     }
     cout << sum << endl;
     return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i,s,e) for(int (i) = (s);(i) <= (e);(i)++)

int main() {
    int ans = 0;
    int n;
    cin >> n;
    rep(i,1,n){
        int a;
        cin >> a;
        bool b = false;
        for(int i = 2;i * i <= a;i++){
            b |= a % i ==0;
        }
        if(!b) ans++;
    }
    cout << ans << endl;
}



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

using namespace std;

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
template<class T> inline T sqr(T x) {return x*x;}

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;

#define all(a)  (a).begin(),(a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define pb push_back
#define mp make_pair
#define each(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define exist(s,e) ((s).find(e)!=(s).end())
#define range(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  range(i,0,n)
#define clr(a,b) memset((a), (b) ,sizeof(a))
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

const double eps = 1e-10;
const double pi  = acos(-1.0);
const ll INF =1LL << 62;
const int inf =1 << 29;

const vi add = {1, 2, 1, 1, 2, 2, 1, 1, 1, 2, 2, 3, 3};
const vi sub = {1, 1, 2, 1, 2, 1, 2, 2, 3, 1, 3, 1, 2};
const vi mul = {1, 1, 1, 2, 1, 2, 2, 3, 2, 3, 1, 2, 1};

string formula;

ll parse(int b, int e, int ord){
    vector<ll> v;
    vector<char> op;

    range(i, b, e){
        if(formula.at(i) == '('){
            int next_b = i + 1, cnt = 1;
            while(cnt){
                if(formula[++i] == '(') cnt++;
                else if(formula[i] == ')') cnt--;
            }
            v.pb(parse(next_b, i, ord));
        }
        else if(isdigit(formula.at(i))){
            ll value = 0;
            while(i < e && isdigit(formula.at(i))){
                value = 10 * value + formula.at(i++) - '0';
            }
            v.pb(value);

            i--;
        }
        else{
            op.pb(formula.at(i));
        }
    }
  
    if(v.size() == 0) return 0;

    range(i, 1, 4){
        rep(j, op.size()){
            bool operated = false;

            if(op[j] == '+' && add[ord] == i){
                v[j] = v[j] + v[j + 1];
                operated = true;
            }
            else if(op[j] == '-' && sub[ord] == i){
                v[j] = v[j] - v[j + 1];
                operated = true;
            }
            else if(op[j] == '*' && mul[ord] == i){
                v[j] = v[j] * v[j + 1];
                operated = true;
            }

            if(operated){
                v.erase(v.begin() + j + 1);
                op.erase(op.begin() + j);
                j--;
            }
        }
    }

    return v[0];
}

int main(void){
    for(; cin >> formula;){
        ll res = parse(0, formula.size(), 0);

        range(i, 1, add.size()){
            res = max(res, parse(0, formula.size(), i));
        }

        cout << res << endl;
    }

	return 0;
}

Measured memory_bytes: 1212
N,Y=map(int,input().split(" "))

x=-1
y=-1
z=-1
bp=0

for i in range(N+1):
    for j in range(N+1-i):
        if Y==9000*i+4000*j+1000*N:
            x=i
            y=j
            z=N-i-j
            bp=1
            break
    if bp==1:
        break
        
print("{} {} {}".format(x,y,z))

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

int main() {
  int N;
  cin >> N;
  
  vector<int> count(N,0);
  
  int max;
  for (int i=0; i<N; i++){
    if (i*i > N){
      max = i-1;
      break;
    }
  }
  if(N==1){
    max=1;
  }
  
  // これでmax求まった
  
  int value;
  
  for (int i=1; i<=max; i++){
    for (int j=1; j<=max; j++){
      if (i*i + j*j + i*j + i + j + 1 > N) break;
      for (int k=1; k<=max; k++){
        value = i*i + j*j + k*k + i*j + j*k + k*i;
        if (value > N) break;
        count.at(value-1)++;
      }
    }
  }
  
  for (int i=0; i<N; i++){
    cout << count.at(i) << endl;
  }
  
  
}


Measured memory_bytes: 3636
#include <iostream>

using namespace std;

int main()
{
    int setN = 1;
    while(1)
    {
        int a;
        cin >> a;
        if(a == 0)
        {
            break;
        }

        cout << "Case " << setN << ": " << a << endl;
        setN++;
    }

    return 0;
}

Measured memory_bytes: 1160
import sys
imput = sys.stdin.readline

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

money = 1000

for i in range(N-1):
  if a[i+1] > a[i]:
    k = money//a[i]
    money += a[i+1]*k - a[i]*k
    
print(money)

Measured memory_bytes: 61896
#include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<queue>
#include<deque>
#include<regex>
#include<stack>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
#include<iomanip>

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

typedef int long long ll;
using namespace std;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
const ll MOD = 1e9 + 7;

int main() {
    string s;
cin>>s;
int n=s.size()-1;

ll ans=0;
for(int i=0;i<(1<<n);i++){
    int nn=i;
    ll pre=0,next=(int)(s[0]-'0');
    ll kari=0;
   // cout<<next<<" ";
    for(int l=0;l<n;l++){
        if(((nn>>l)&1)){//cout<<1;
            kari+=next;
            next=s[l+1]-'0';
            //cout<<s[l+1]<<" ";
            //cout<<next<<"1a";
        }else{
            //cout<<0;
            next=next*10+(s[l+1]-'0');
           // cout<<next<<"0a";
        }
    }
   // cout<<endl;
    //cout<<kari<<" "<<next<<" ";
    kari+=next;
    //cout<<kari<<endl;
    ans+=kari;

}

cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
from itertools import*
from math import*
from collections import*
from heapq import*
from bisect import bisect_left,bisect_right
from copy import deepcopy
inf = float("inf")
mod = 10**9+7
from functools import reduce
import sys
sys.setrecursionlimit(10**7)

N,K = map(int,input().split())
if N*(N-1)//2-K<N-1:
    print(-1)
    exit()
else:
    print(N*(N-1)//2-K)
    edge=[[1]*(N) for i in range(N)]
    for i in range(N):
        edge[i][i]=0
    for i in range(N-1):
        for j in range(i+1,N-1):
            if K>0:
                edge[i][j]=0
                K -=1
    for i in range(N)[::-1]:
        for j in range(0,i):
            edge[i][j]=0
    for i in range(N):
        for j in range(N):
            if edge[i][j]:
                print(i+1,j+1)

Measured memory_bytes: 43248
#include<stdio.h>

int main() {

  int num, i, score[100], max, min, sum, ave;

  while(1) {
    max = 0;
    min = 1000;
    sum = 0;
    scanf("%d", &num);

    if(num == 0) break;

    for(i = 0; i < num; i++) {
      scanf("%d", &score[i]);

      sum += score[i];
      if(score[i] > max) max = score[i];
      if(score[i] < min) min = score[i];
    }

    sum = sum - min - max;
    ave = sum / (num - 2);

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

    for(i = 0; i < num; i++) {
      score[i] = 0;
    }
    
  }
}



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

int main(void){
  int n;
  cin >> n;
  vector<int> A(n);
  vector<int> B(n);
  vector<int> C(n);
  for(int i = 0; i < n; i++){
    cin >> A[i];
  }
  for(int i = 0; i < n; i++){
    cin >> B[i];
  }
  for(int i = 0; i < n-1; i++){
    cin >> C[i];
  }

  int satisfaction = 0;
  int eaten = -1;
  for(int i = 0; i < n; i++){
    satisfaction += B[A[i]-1];
    if(A[i] - eaten == 1) satisfaction += C[eaten-1];
    eaten = A[i];
  }

  cout << satisfaction << endl;
  return 0;
}


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

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

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

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

void solve() {
    int n;
    cin >> n;
    vector<int> h(n);
    for (int i=0; i<n; i++) {
        cin >> h.at(i);
    }
    vector<ll> dp(n);
    dp.at(0) = 0;
    dp.at(1) = abs(h.at(0) - h.at(1));
    for (int i=2; i<n; i++) {
        dp.at(i) = min(dp.at(i-2) + abs(h.at(i) - h.at(i-2)), dp.at(i-1) + abs(h.at(i) - h.at(i-1)));
    }
    cout << dp.back() << "\n";
}

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

    solve();

    return 0;
}


Measured memory_bytes: 1408
#include<iostream>
#include<string.h>
using namespace std;
int kingaku(void);
int saitan(void);
#define WHITE 0
#define GLAY 1
#define BLACK 2
#define INF 9999
int n;	//	??????????????±?????°
int m;	//	?§??????°
int p;	//	????????°
int q;	//	??°?????°
int minv;
int cost[101][101];
int Time[101][101];
int dd[101];
int main()
{
	int a,b,c,t,k,r;
	while(1){
		memset(cost,INF,sizeof(cost));
		memset(Time,INF,sizeof(Time));
		cin >> n >> m;
		if(n == 0 && m == 0) break;
		for(int i=0;i<n;i++){
			cin >> a >> b >> c >>t;
			cost[a][b] = cost[b][a] = c;
			Time[a][b] = Time[b][a] = t;
		}
		cin >> k;
		for(int i=0;i<k;i++){
			cin >> p >> q >> r;
			if(r == 0)
				cout << kingaku() << endl;
			else if(r == 1)
				cout << saitan() << endl;
			//for(int i=1;i<=m;i++)
			//	cout << i << " " << dd[i] << endl;
		}
	}
	return 0;
}

int kingaku()
{
	int u;
	int color[101];
	memset(dd,INF,sizeof(dd));
	memset(color,WHITE,sizeof(color));
	dd[p] = 0;
	color[p] = GLAY;
	while(1){
		u = -1;
		minv = INF;
		for(int i=1;i<=m;i++){
			if(minv > dd[i] && color[i] != BLACK){
				minv = dd[i];
				u = i;
			}
		}
		if(u==-1) break;
		color[u] = BLACK;
		for(int i=1;i<=m;i++){
			if(cost[u][i] != INF && color[i] != BLACK){
				if(dd[i] > dd[u] + cost[u][i])	//
					     //1?§?     1?§???¨??\?????????????§?
					dd[i] = dd[u] + cost[u][i];
			}
		}
	}
	return dd[q];
}

int saitan()
{
	int u;
	int color[101];
	memset(dd,INF,sizeof(dd));
	memset(color,WHITE,sizeof(color));
	dd[p] = 0;
	color[p] = GLAY;
	while(1){
		u = -1;
		minv = INF;
		for(int i=1;i<=m;i++){
			if(minv > dd[i] && color[i] != BLACK){
				minv = dd[i];
				u = i;
			}
		}
		if(u==-1) break;
		color[u] = BLACK;
		for(int i=1;i<=m;i++){
			if(Time[u][i] != INF && color[i] != BLACK){
				if(dd[i] > dd[u] + Time[u][i])
					dd[i] = dd[u] + Time[u][i];
			}
		}
	}
	return dd[q];
}

Measured memory_bytes: 1248
import sys
from collections import deque
import math

input = sys.stdin.readline


def solve():
    n = int(input())
    A = map(int, input().split())
    count = [0 for _ in range(n)]
    for a in A:
        count[a-1] += 1
    return '\n'.join(map(str, count))


if __name__ == '__main__':
    answer = solve()
    print(answer)


Measured memory_bytes: 27256
#!/usr/bin/env python

from collections import deque
import itertools as it
import sys

sys.setrecursionlimit(1000000)

N, M, L = map(int, raw_input().split())

def fact(n):
    if n <= 1:
        return 1
    return fact(n - 1) * n
MC = []
for i in range(M + 1):
    MC.append(fact(M) / fact(i) / fact(M - i))

p_lst = []
P_val = []
P_sum = []

for i in range(N):
    P, T, V = map(int, raw_input().split())
    p_lst.append((T, V))
    PP = []
    for k in range(M + 1):
        PP.append(float(MC[k] * (P ** k) * ((100 - P) ** (M - k))) / 100 ** M)
    P_val.append(list(PP))
    for k in range(M, 0, -1):
        PP[k - 1] += PP[k]
    P_sum.append(PP)

def comp(p1, p2, k1, k2):
    T1, V1 = p1
    T2, V2 = p2
    return L * (V2 - V1) < V1 * V2 * (k2 * T2 - k1 * T1)

for i in range(N):
    ans = 0
    index_lst = [0 for j in range(N)]
    for k1 in range(M + 1):
        ret = P_val[i][k1]
        for j in range(N):
            if i == j:
                continue
            flag = True
            while True:
                k2 = index_lst[j]
                if k2 > M:
                    ret *= 0
                    break
                if comp(p_lst[i], p_lst[j], k1, k2):
                    ret *= P_sum[j][k2]
                    break
                index_lst[j] += 1
        ans += ret
    print '%.10f' % ans



Measured memory_bytes: 5180
#include <cstdio>
#include <cstring>

int main() {
  int W, H, x, y;
  scanf("%d %d %d %d", &W, &H, &x, &y);

  printf("%.16f", 0.5*H*W);

  char s[100000];
  memset(s, '0', sizeof s);
  for (int i = 0; i < 1000; ++i)
    fwrite(s, 1, sizeof s, stdout);

  putchar(' ');
  puts((x+x == W && y+y == H)? "1": "0");
}


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

#ifdef _DEBUG
#define dout cout
#define debug() if (true)
#define dvout(v) vout(v)
#else
#define dout if (false) cout
#define debug() if (false)
#define dvout(v) if(false) vout(v)
#endif

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define all(x) (x).begin(), (x).end()
#define vout(v)           \
	for (auto &i : v)     \
	{                     \
		cout << i << " "; \
	}                     \
	cout << "\n"; //配列出力
#define vec(v, n) vector<int> v(n, 0);
#define vecll(v, n) vector<ll> v(n, 0);
#define vecvec(v,n,m) vector<vector<int>> v(n, vector<int>(m));
#define vin(v)        \
	for (auto &i : v) \
		cin >> i; //配列入力

#define mod (int)(1e9+7)
typedef long long ll;
typedef unsigned long long ull;
#define next asdnext
#define prev asdprev
#define _n "\n"
#define _n2 "\n\n"
#define _t "\t"

//#define _TEST
void Main()
{
	int N;
	cin>>N;
	vec(a,N);
	vin(a);
	int cnt=0;
	rep(i,N){
		if((i+1)%2 && a[i]%2)cnt++;
	}
	cout<<cnt<<_n;
}


void Test();
int main()
{
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << std::fixed << std::setprecision(15);
#ifndef _TEST
	Main();
#else
	Test();
#endif
	return 0;
}

#ifdef _TEST
void Test(){
	cout<<"test"<<_n;
}
#endif


Measured memory_bytes: 3652