akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>
#include<cstring>
#include<vector>
#include<cmath>
#include<queue>
#include<stack>
using namespace std;
#define INT(x) int x; scanf("%d",&x)
#define LL(x) ll x; scanf("%lld",&x)
#define INPUT(x) cin >> x
#define REP1(x,n) for(int x = 0; x < n; x++)
#define REP2(x,s,e) for(int x = s; x <= e; x++)
#define RREP1(x,n) for(int x = n-1; x >= 0; x--)
#define RREP2(x,s,e) for(int x = s; x >= e; x--)
#define BR printf("\n")
#define INF_INT 2147483647
#define INF_LL 9223372036854775807

typedef long long ll;

int main(){
    ll N,M;
    cin >> N >> M;
    ll l = (N-2)*(M-2);
    if ((N == 1 || M == 1) && !(N == 1 && M == 1)){
        if(N == 1){
            cout << M-2 << endl;
        }else{
            cout << N-2 << endl;
        }
    }else if(N == 1 && M == 1){
        cout << 1 << endl;
    }else{
        cout << (N-2)*(M-2) << endl;
    }
    return 0;
}

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

int main() {
  int A, B, C;
  cin >> A >> B >> C;
  if (A == B and B == C and C == A) {
      cout << "No";
  }
  else if (A != B and B != C and C != A) {
      cout << "No";
  }
  else {
      cout << "Yes";
  }
}

Measured memory_bytes: 3584
#include <bits/stdc++.h>
using namespace std;
const int N = 60;
int a[N * 2], dp[N][N * 2][N * 2]; const int mod = 1e9 + 7;
inline void Inc(int &x, int y) {x += y, x -= x >= mod ? mod : 0;}
int main() {
	int n, res = 0; scanf("%d", &n);
	for (int i = 1; i <= 2 * n - 1; i++) scanf("%d", &a[i]);
	sort(a + 1, a + 2 * n), dp[n][1][0] = 1;
	for (int i = n - 1; i >= 1; i--) {
		int tl = a[i] != a[i + 1], tr = a[2 * n - i - 1] != a[2 * n - i];
		for (int j = 0; j <= 2 * n - 1; j++)
			for (int k = 0; j + k <= 2 * n - 1; k++) if (dp[i + 1][j][k]) {
				for (int t = 1; t <= tl + j; t++) 
					Inc(dp[i][j + tl - (t - 1)][k + tr + (t != 1)], dp[i + 1][j][k]);
				for (int t = 1; t <= tr + k; t++)
					Inc(dp[i][j + tl + 1][k + tr - t], dp[i + 1][j][k]);
			}
	}
	for (int i = 0; i <= 2 * n - 1; i++)
		for (int j = 0; i + j <= 2 * n - 1; j++) Inc(res, dp[1][i][j]);
	printf("%d\n", res);
}

Measured memory_bytes: 1536
#include<iostream>
#include<vector>
using namespace std;
int main(){
    int n;
    cin >> n;
    string target,board;
    int ans = 0;
    cin >> target;
    for(int i = 0;i < n;i++){
        cin >> board;
        bool s = false;
        for(int j = 0;j < board.size();j++){
            if(s == true)break;
            if(board[j] == target[0]){
                for(int l = 1;j + l < board.size();l++){
                    if(s == true)break;
                    if(board[j + l] == target[1]){
                        //cout << "-";
                        for(int m = 2;m < target.size();m++){
                            if(board.size() > j  + m * l){
                                //cout << "+";
                                if(board[j + m * l] == target[m]){
                                    //cout << "*";
                                    if(m == target.size() - 1){
                                        ans ++ ;
                                        s = true;

                                    }
                                    continue;
                                }
                                break;
                                                        
                            }
                        }
                    }
                }
            }
        }
    }
    cout << ans <<endl;
}


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

using namespace std;

using ll = long long;

int main() {
  ll n;
  cin >> n;
  ll mi = 1e9;
  for (int i = 0; i < 10; ++i) {
    ll c = n % 1000;
    mi = min(mi, llabs((ll)753 - c));
    n /= 10;
  }
  cout << mi << endl;
}

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

int main()
{
  int N;
  cin >> N;
  vector<int> vec(N);
  for(int i=0;i<N;i++){
    cin >> vec.at(i);
  }

  // 出力
  int n = 0;
  int max = 0;

  for (int i = 0; i < N-1; i++){
    if (vec[i] >= vec[i+1]){
      n++;
    }else {
      n = 0;
    }
    if (n > max){
	  max = n;
    }    
  }
  cout << max << endl;
  
  return 0;
}



Measured memory_bytes: 640
#include <iostream>
#include <math.h>
#define MAX_N 100000
using namespace std;
int n,m=0,r;
double d,w,h,minl; 
int main(){
	while(1){
		cin >> d>> w>> h;
		if(d==0 && w==0 && h==0)break;

		minl=MAX_N;
		if(sqrt(d*d+w*w)<minl)minl=sqrt(d*d+w*w);
		if(sqrt(h*h+w*w)<minl)minl=sqrt(h*h+w*w);
		if(sqrt(d*d+h*h)<minl)minl=sqrt(d*d+h*h);
		cin >> n;
		m=n;
		while(n--){
			cin >> r;
			if(2*r>minl){
				cout << "OK"<<endl;
			}else{
				cout << "NA"<<endl;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 3104
#include <iostream>
#include <math.h>
#include <algorithm>
#include <functional>
#include <vector>
#include <typeinfo>
#include <climits>
#include <ctype.h>
#include <string>
#include <stack>
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, n) for (int i = a; i < n; i++)
#define REP(i, n) for(int i = 0; i < n; i++)
struct omt{omt(){ios::sync_with_stdio(false);cin.tie(0);}}star;

int main(){
    string s;
    cin >> s;
    int A[26] = {};

    int f = 0;
    REP(i, s.size()){
        int c = s[i] - 97;
        A[c]++;
        if(A[c] > 1){
            f = 1;
            break; 
        }
    }

    if(f == 0) cout << "yes" << endl;
    else cout << "no" << endl;

    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int N=sc.nextInt();
		sc.close();
		if(N<1000) {
			System.out.println("ABC");
		}
		else {
			System.out.println("ABD");
		}
	}
}


Measured memory_bytes: 21844
#include <stdio.h>

int main(void){
	int n,a[10001]={0},min=1000001,max=-1000001;
	long long int total=0;
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		scanf("%d",&a[i]);
		if(min>a[i])min=a[i];
		if(max<a[i])max=a[i];
		total+=a[i];
	}
	printf("%d %d %lld\n",min,max,total);
	return 0;
}


Measured memory_bytes: 2100
//{{{
#include <bits/stdc++.h>
using namespace std;
#define rep(...) repN((__VA_ARGS__,rep3,rep2,loop,~))(__VA_ARGS__)
#define loop(n) rep2(_loop_,n)
#define rep2(i,n) rep3(i,0,n)
#define rep3(i,begin,end) for(int i=(int)(begin),i##_end=(int)(end);i<i##_end;++i)
#define repN(a) repX a
#define repX(a0,a1,a2,x,...) x
#define foreach(x,a) for(auto &x:a)
typedef long long ll;
const ll MOD = 1e9+7;
//}}}

ll x[100];
ll sumNum[100][2501] = {0};
int main(){
  int N, A;
  cin >> N >> A;

  rep(i, N){
    cin >> x[i];
  }
  rep(n, N){
    for(int i = n; i >= 1; i--){
      for(int j = 2500; j >= 0; j--){
        if(sumNum[i][j]){
          sumNum[i + 1][j + x[n]] += sumNum[i][j];
        }
      }
    }
    sumNum[1][x[n]]++;
  }

  ll ans = 0;
  rep(n, 1, N + 1){
    ans += sumNum[n][n * A];
  }
  cout << ans << endl;
  return 0;
} 


Measured memory_bytes: 640
#!/usr/bin/env python
# coding: utf-8

# In[42]:


N,K = map(int, input().split())
A = list(map(int, input().split()))


# In[44]:


ans1 = 0
ans2 = 0
for i,a in enumerate(A):
    for j,a_ in enumerate(A):
        if i > j:
            if a > a_:
                ans2 += 1
        if i < j:
            if a > a_:
                ans1 += 1
                ans2 += 1
print((ans1*K + ans2*(K*(K-1)//2))%(10**9+7))


# In[ ]:






Measured memory_bytes: 3188
def main():
    n = int(input())
    k = int(input())
    x = int(input())
    y = int(input())

    ans = 0
    for i in range(1, n + 1):
        if i <= k:
            ans += x
        else:
            ans += y
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
/* “Whether you think you can or you think you can’t, you’re right” - Henry Ford */

#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define all(x) x.begin(), x.end()
#define F first
#define S second
#define pb push_back
#define pl pair<ll, ll>
#define vl vector<ll>
#define vi vector<int>
#define endl '\n'

template <typename T, typename TT>
ostream &operator<<(ostream &os, const pair<T, TT> &t) {
    return os << t.first << " " << t.second;
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &t) {
    for (auto &i : t) os << i << " ";
    return os;
}
template <typename T>
istream &operator>>(istream &is, vector<T> &v) {
    for (T &t : v) is >> t;
    return is;
}
template <typename T1, typename T2>
istream &operator>>(istream &is, vector<pair<T1, T2>> &v) {
    for (pair<T1, T2> &t : v) is >> t.first >> t.second;
    return is;
}

const ll mod = 1e9 + 7;
const ll N = 1e6 + 5;
bitset<N> vis;

void solve() {
    ll n; cin >> n;
    vl v(n); cin >> v;
    multiset<ll> s(all(v));
    ll g = v[0];
    for(int i = 1; i < n; i++) g = __gcd(g, v[i]);
    bool f = 0;
    for(int i = 2; i < N; i++) {
        if(!vis[i]) {
            ll c = 0;
            for(int j = i; j < N; j += i) {
                vis[j] = 1;
                c += s.count(j);
            }
            if(c > 1) {
                f = 1;
                break;
            }
        }
    }
    if(!f) {
        cout << "pairwise coprime" << endl;
        return;
    }
    if(g == 1) {
        cout << "setwise coprime" << endl;
        return;
    }
    cout << "not coprime" << endl;
}

int main()
{
    fast;
    ll t = 1;
    // cin >> t;
    while (t--) {
        solve();
    }
    return 0;
}


Measured memory_bytes: 58028
using static System.Math;
using System;

public class hello
{
    public static void Main()
    {
        string[] line = Console.ReadLine().Trim().Split(' ');
        var a = int.Parse(line[0]);
        var b = int.Parse(line[1]);
        var x = int.Parse(line[2]);
        var ans = int.MaxValue;
        for (int i = 0; i <= (x + 999) / 1000; i++)
            for (int j = 0; j <= (x + 499) / 500; j++)
                if (i * 1000 + j * 500 >= x) { ans = Min(ans, i * a + j * b); ; break; }
        Console.WriteLine(ans);
    }
}




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

    #define FOR(i,a,b) for (int i = (a); i < (b); i++)
    #define rep(i,n) FOR(i,0,n)
    #define RFOR(i,b,a) for (int i = (b)-1; i >= (a); i--)
    #define ITER(it,a) for (__typeof(a.begin()) it = a.begin(); it != a.end(); it++)
    #define FILL(a,value) memset(a, value, sizeof(a))

    #define SZ(a) (int)a.size()
    #define ALL(a) a.begin(), a.end()
    #define PB push_back
    #define MP make_pair
    #define SC second
    #define FS first

    typedef long long LL;
    typedef vector<int> VI;
    typedef vector<LL>VL;
    typedef vector <bool >VB;
    typedef vector<vector<int>>WI;
    typedef vector<vector<LL>>WL;
    typedef pair<int, int> PII;
    typedef pair<double, double> PDD;

    const double PI = acos(-1.0);
    const int INF = 1000 * 1000 * 1000 + 7;
    const LL LINF = LL(1e12);
    const int MAS = int(1e5 * 3 + 1);
    const double EPS = 1e-7;
    const LL MAX = 4294967296;
    const LL MOD =LL(1e9+7);



    LL dp[MAS] ;
    int a[MAS] ;
    int b[MAS];
    int c[MAS];
    int main()
    {
      int n;
      cin >> n;
      rep(i,n)
      {
          cin >> a[i] ;
      }
      rep(i,n)
      {
          cin >> b[i];
      }
      rep(i,n-1)
      {
          cin >> c[i] ;
      }
      LL sum = 0;
      sum+=b[a[0]-1];
      int lst = a[0];
      FOR(i,1,n)
      {
          sum+=b[a[i]-1];
          if(lst == a[i]-1)
          {
              sum+=c[a[i]-2];
          }
          lst = a[i];
      }
      cout << sum ;

    }


Measured memory_bytes: 2304
H,W,K=map(int,input().split())
m = []
A = 0
for _ in range(H):
  m.append([v for v in input()])
for h in range(2**H):
  for w in range(2**W):
    ans = 0
    for h2 in range(H):
      for w2 in range(W):
        if h>>h2&1 and w>>w2&1 and m[h2][w2]=='#':
          ans += 1
    #print(h,w,ans)
    if ans == K:
      A += 1
print(A)
      
    

Measured memory_bytes: 9192
#include<iostream>
#include<algorithm>
#include<map>
#include<vector>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
ll inf = 1000000007;

int dx[8] = { 1,-1,0,0,-1,-1,1,1 };
int dy[8] = { 0,0,1,-1,-1,1,-1,1 };
int main() {
	int h, w;
	cin >> h >> w;
	char mine[55][55];
	int dist[55][55];
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			cin >> mine[i][j];
		}
	}
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			dist[i][j] = inf;
		}
	}
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			int count = 0;
			if (mine[i][j] == '.') {
				int nowx = j;
				int nowy = i;
				for (int k = 0; k < 8; k++) {
					int newx = nowx + dx[k];
					int newy = nowy + dy[k];
					if (newx >= 0 && newx < w && newy >= 0 && newy < h&&mine[newy][newx]=='#') {
						count++;
					}
				}
				dist[nowy][nowx] = count;
			}
		}
	}
	
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			if (j % w == 0) {
				cout << endl;
			}
			
				if (dist[i][j] == inf) {
					cout << "#";
				}
				else {
					cout << dist[i][j];
				}
			
		}
	}
	return 0;
}



Measured memory_bytes: 256
#include <stdio.h>
 
void maxHeap(int *, int, int);
 
main(){
  int i, n;
  int t[500001];
 
  scanf("%d", &n);
 
  for(i = 1;i <= n;i++) scanf("%d", &t[i]);
 
  for(i = n/2;i > 0;i--) maxHeap(t, i, n);
 
 
  for(i = 1;i <= n;i++) printf(" %d", t[i]);
 
  printf("\n");
  return 0; 
}
void maxHeap(int *t, int i, int n){
  int l, r, large, c;
 
  if( i*2+1 < n + 1) r = i*2+1;
  else r = i;
  if( i*2 < n + 1) l = i*2;
  else l = i;
 
  if(l <= n && t[l] > t[i]) large = l;
  else large = i;
 
  if(r <= n && t[r] > t[large])large = r;
 
  if(large != i){
    c = t[i];
    t[i] = t[large];
    t[large] = c;
    maxHeap(t, large, n);
  }
}

Measured memory_bytes: 2552
def double(x, y):
    global count

    for _ in range(7):
        if x < y:
            break

        y *= 2
        count += 1

    return y


def main():
    a, b, c = map(int, input().split())
    k = int(input())

    b = double(a, b)
    c = double(b, c)

    if count <= k:
        print("Yes")
    else:
        print("No")


if __name__ == "__main__":
    count = 0
    main()


Measured memory_bytes: 9184
#include<stdio.h>

int breakblocks(int a[], int N, int i, int x)
{
  int j=x;
  while(a[j-1]!=i && j<=N){j++;}
  return j;
}

int main()
{
  int N;
  scanf("%d",&N);
  int a[200001];
  for(int i=0;i<N;i++){
    scanf("%d",&a[i]);
  }
  
  int count=0,temp=1;
  
  for(int i=1;i<=N;i++)
  {
    temp = breakblocks(a,N,i,temp);
    if(temp>=N+1){
      if(i==1){count=-1; break;}
      if(i!=1){count=N-i+1; break;}
    }
    count = 0;
  }
  
  printf("%d",count);
  
}


Measured memory_bytes: 896
#include <bits/stdc++.h>
#pragma GCC optimize("O3")

#define fi first
#define se second
#define em emplace
#define eb emplace_back
#define mp make_pair
#define pi pair<int,int>
#define vi vector<int>
#define vpi vector<pair<int,int>>
#define vll vector<ll>
#define vpll vector<pair<ll,ll>>
#define endl '\n'

#define si(v) int((v).size())
#define all(v) (v).begin(), (v).end()
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i) 
#define rep2(i, n, m) for (ll i = n; i <= (ll)(m); ++i)
#define rep3(i, n, m) for (ll i = n; i >= (ll)(m); --i)

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

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

constexpr ll MOD = 1000000007;

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

  int n, k; cin >> n >> k;
  set<char> hate;

  rep(i, k) {
    int x; cin >> x;
    hate.em(x);
  }

  while (true) {
    string s = to_string(n);

    bool ok = true;
    rep(i, si(s)) if (hate.count(s[i] - '0')) ok = false;

    if (ok) break;
    ++n;
  }

  cout << n << endl;

  return (0);
}


Measured memory_bytes: 3712
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
const double eps=1e-6;
struct tea{
    long long x;
    double y;
    bool operator < (const tea& b) const{
        return ((long long)(2.0/y)*x)<(b.x*(long long)(2.0/b.y));
    }
} t[4];
int main()
{
    int q,h,s,d,n;
    cin>>q>>h>>s>>d>>n;
    t[0].x=q;t[0].y=0.25;
    t[1].x=h;t[1].y=0.5;
    t[2].x=s;t[2].y=1;
    t[3].x=d;t[3].y=2;
    sort(t,t+4);
    double nn=n;
    long long ans=0;
    for(int i=0;i<4&&nn>eps;i++){
        long long xx=t[i%4].x;
        double yy=t[i%4].y;
        long long gg=nn/yy;
        double ggg=gg;
        ans+=gg*xx;
        nn-=ggg*yy;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
// #include {{{
#include <iostream>
#include <cassert>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <ctime>
#include <queue>
#include <set>
#include <map>
#include <stack>
#include <string>
#include <bitset>
#include <vector>
#include <complex>
#include <algorithm>
using namespace std;
// }}}
// #define {{{
typedef long long ll;
typedef double db;
typedef pair<int,int> pii;
typedef vector<int> vi;
#define de(x) cout << #x << "=" << x << endl
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define per(i,a,b) for(int i=(b)-1;i>=(a);--i)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define fi first
#define se second
// }}}

const int N = 4040;
int n , K;
int sum[2][N][N];

int query(int c,int x,int y) {
  --x;--y;
  int xx = x + K;
  int yy = y + K;
  int res = sum[c][xx][yy];
  if(x >= 0 && y >= 0)
    res += sum[c][x][y];
  if(x >= 0)
    res -= sum[c][x][yy];
  if(y >= 0)
    res -= sum[c][xx][y];
  return res;
}

int main(){
  scanf("%d%d",&n,&K);
  int x,y;
  char c[10];
  int KK = K + K;
  rep(i,0,n) {
    scanf("%d%d%s",&x,&y,c);
    x %= KK;
    y %= KK;
    sum[c[0]=='B'][x][y]++;
  }
  rep(t,0,2) rep(i,0,KK) rep(j,0,KK)
    sum[t][i+KK][j] = sum[t][i][j+KK] = sum[t][i+KK][j+KK] = sum[t][i][j];
  int KKK = KK + K;
  rep(t,0,2) rep(i,0,KKK) rep(j,0,KKK) {
    if(i) sum[t][i][j] += sum[t][i-1][j];
    if(j) sum[t][i][j] += sum[t][i][j-1];
    if(i && j) sum[t][i][j] -= sum[t][i-1][j-1];
  }
  int ans = 0;
  rep(c,0,2) rep(i,0,K) rep(j,0,K) {
    int cnt = query(c , i , j) + query(c , i + K , j + K)
      + query(c ^ 1 , i + K , j) + query(c ^ 1 , i , j + K);
    ans = max(ans , cnt);
  }
  printf("%d\n",ans);
  return 0;
}


Measured memory_bytes: 127232
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
)

func main() {
	n, k := readI(), readI()
	if k >= n {
		fmt.Println(0)
		return
	}

	h := make([]int, n)
	for i := 0; i < n; i++ {
		h[i] = readI()
	}

	sort.Sort(sort.Reverse(sort.IntSlice(h)))
	ans := 0
	for i := k; i < n; i++ {
		ans += h[i]
	}
	fmt.Println(ans)
}

/*-----------Input utils-----------*/

var sc = bufio.NewScanner(os.Stdin)

func init() {
	if len(os.Args) >= 2 {
		if os.Args[1] == "debug" {
			debug()
		}
	}
	const buf = 200100
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, buf), buf)
}

func debug() {
	testFile, err := os.Open("./test/sample-1.in")
	if err != nil {
		fmt.Fprintln(os.Stderr, "There is no testfile.")
		os.Exit(1)
	}
	sc = bufio.NewScanner(testFile)
}

func readS() string {
	sc.Scan()
	return sc.Text()
}

func readR() []rune {
	return []rune(readS())
}

func readI() int {
	i, _ := strconv.Atoi(readS())
	return i
}

func readF() float64 {
	f, _ := strconv.ParseFloat(readS(), 64)
	return f
}


Measured memory_bytes: 6136
#include <bits/stdc++.h>
#define REP(i,s,e) for(int i=(s); i<(e);i++)
#define rep(i,n) REP(i,0,n)
#define rep1(i,n) REP(i,1,n)
#define repe(i,n) for(auto &&i:n)
#define all(v) (v).begin(),(v).end()
#define decimal fixed<<setprecision(20)
#define fastcin() cin.tie(0);ios::sync_with_stdio(false)
using namespace std;
using LL = long long;
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; }
const int INF = 1e9;
const LL LLINF = 1e16;

struct BipartiteMatching {
    using Graph = vector<vector<int>>;
    Graph G;
    vector<int> match, alive, used;
    int timestamp;

    BipartiteMatching(int n) : G(n), alive(n, 1), used(n, 0), match(n, -1), timestamp(0) {}

    void add_edge(int u, int v) {
        G[u].push_back(v);
        G[v].push_back(u);
    }

    int dfs(int idx) {
        used[idx] = timestamp;
        for(auto &&to : G[idx]) {
            int w = match[to];
            if(alive[to] == 0) continue;
            if(w < 0 || (used[w] != timestamp && dfs(w))) {
                match[idx] = to;
                match[to] = idx;
                return 1;
            }
        }
        return 0;
    }

    int bipartite_matching() {
        int res = 0;
        for(int i = 0; i < G.size(); i++) {
            if(alive[i] == 0) continue;
            if(match[i] == -1) {
                ++timestamp;
                res += dfs(i);
            }
        }
        return res;
    }

     void output() {
        for(int i = 0; i < G.size(); i++) {
            if(i < match[i]) {
                cout << i << "-" << match[i] << endl;
            }
        }
    }
};

int main(){
    int x, y, e;
    cin >> x >> y >> e;
    BipartiteMatching BM(x+y);
    rep(i, e){
        int u, v;
        cin >> u >> v;
        BM.add_edge(u, x+v);
    }
    cout << BM.bipartite_matching() << endl;
}




Measured memory_bytes: 3292
N, M = list(map(int, input().split()))
A = list(map(lambda x: int(x),input().split()))

cnt = [0 for _ in range(N)]
for i in range(N):
  a = A[i]
  while a%2 == 0:
    a = a // 2
    cnt[i] += 1

if max(cnt) > min(cnt):
  print(0)
  exit(0)
C = max(cnt)

A = list(map(lambda x: x // pow(2,C), A))
def gcd(a,b):
  if a<b:
    a,b = b,a
  while a%b > 0:
    a,b = b,a%b
  return b

def lcm(a,b):
  return a*b//gcd(a,b)

x = A[0]
for a in A[1:]:
  x = lcm(x,a)
x = x * pow(2,C-1)

print((M // x + 1) // 2)

Measured memory_bytes: 97668
// Winners don't quit and Quitters don't win
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vii vector<int>
#define vll vector<ll>
#define mod 998244353
#define MAX 100005
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    string s;
    cin>>s;
    if(s[2]==s[3] && s[4]==s[5]){
    	cout<<"Yes";
	}
	else{
		cout<<"No";
	}
    
}

Measured memory_bytes: 256
s = input()
ans = False
if s[0] == s[1] :
  if s[0] != s[2] and s[2] == s[3] :
    ans = True
elif s[0] == s[2] :
  if s[0] != s[1] and s[1] == s[3] :
    ans = True
elif s[0] == s[3] :
  if s[0] != s[1] and s[1] == s[2] :
    ans = True
if ans :
  print('Yes')
else:
  print('No')

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

int main()
{
   string s;
   cin >> s;
   string ans = "";
   int sum = 0;
   int target = 0;
   bool plus = true;

   rep(i, 1 << s.size()-1){
      ans = "";
      sum = 0;
      plus = true;
      target = s[0] - '0';
      rep(j, s.size()-1)
      {
         ans += s[j];
         //cout << target << " "<< plus << endl;
         if(plus) sum += target;
         else sum -= target;
         if(i >> j&1)
         {
            //+
            ans += '+';
            plus = true;
         }
         else
         {
            //-
            ans +='-';
            plus = false;
         }
         target = s[j+1] - '0';
      }
      ans += s[s.size()-1];
      if(plus) sum += target;
      else sum -= target;
     // cout << sum << " " << ans<< endl;
      if(sum == 7) break;     
   }
   ans += "=7";
   cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
typedef long long ll;
const int inf=0x3f3f3f3f;
int a[200010],l[100010],r[100010];
ll merge(int a[],int left,int mid,int right){
	ll cnt=0;
	int n1=mid-left;
	int n2=right-mid;
	for(int i=0;i<n1;++i) l[i]=a[left+i];
	for(int i=0;i<n2;++i) r[i]=a[mid+i];
	int k=0,j=0;
	l[n1]=r[n2]=inf;
	for(int i=left;i<right;++i){
		if(l[k]<=r[j]) a[i]=l[k++];
		else{
			a[i]=r[j++];
			cnt+=n1-k;
		}
	}
	return cnt;
}
ll mergesort(int a[],int left,int right){
	if(left+1<right){
		int mid=(left+right)/2;
		ll t1=mergesort(a,left,mid);
		ll t2=mergesort(a,mid,right);
		ll t3=merge(a,left,mid,right);
		return t1+t2+t3;
	}else{
		return 0;
	}
}
int main(){
	int n;
	cin>>n;
	for(int i=0;i<n;++i){
		cin>>a[i];
	}
	cout<<mergesort(a,0,n)<<endl;
	return 0;
}


Measured memory_bytes: 4656
#include <bits/stdc++.h>
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ll long long int
#define pb push_back
#define fi first
#define se second
#define ld long double
#define vi vector<vector<ll> >
using namespace std;
const int MOD=1000000007;
const int MOD2=998244353;
const ll MAX=9187201950435737471;
const int N=100005;
const int INF=1e9+7;
const long double PI=acos(-1);



void solve(int T){
    ll n,a,b;
    cin>>n>>a>>b;
    if(n*a<b){
        cout<<n*a<<"\n";
        return;
    }
    cout<<b<<"\n";
}

int main() {
    fastio

    int T=1;
    //cin>>T;
    for(int i=1;i<=T;i++){
        solve(i);
        //if(i<T)cout<<"\n";
    }
    return 0;
}


Measured memory_bytes: 3648
#include <iostream>
#include <string>
#include <sstream>
#include <list>
#include <stack>
#include <queue>
#include <algorithm>
#include <utility>
#include <vector>
#include <map>
#include <cstring>
#include <cstdio>
#include <cmath>

using namespace std;

int main()
{
    int N;
    int data[251];
    cin>>N;
    for(int i=1;i<=N;i++){
        cin>>data[i];
    }
    for(int i=1;i<=N;i++){
        cout<<"node "<<i<<": key = "<<data[i];
        if(i/2){
            cout<<", parent key = "<<data[i/2];
        }
        if(i*2<=N){
            cout<<", left key = "<<data[i*2];
        }
        if(i*2+1<=N){
            cout<<", right key = "<<data[i*2+1];
        }
        cout<<", "<<endl;
    }
}

Measured memory_bytes: 1160
parseInt(x) = parse(Int, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)

function main()
	n,m,k = readline() |> split |> parseMap
	f = 0
	for i in 0:n
		for j in 0:m
			if (n-i)*(m-j)+i*j == k
				f = 1
				break
			end
		end
	end
	println(f==1?"Yes":"No")
end
main()

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

int main() {
int a,b,m;
cin >> a >>b>>m;
long long ans=0;
long long tmp=pow(10,11);
long long aa[a],bb[b];
for(int i=0;i<a;i++){
    cin >> aa[i];
}
for(int i=0;i<b;i++){
    cin >> bb[i];
}
int x[m],y[m],z[m];
for(int i=0;i<m;i++){
cin >> x[i] >> y[i] >> z[i];
}

for(int  i=0;i<m;i++){
    if((aa[x[i]-1]+bb[y[i]-1]-z[i])<tmp){
    tmp=(aa[x[i]-1]+bb[y[i]-1]-z[i]);}
}
sort(aa,aa+a);
sort(bb,bb+b);
if(aa[0]+bb[0]<tmp)tmp=aa[0]+bb[0];
cout << tmp;
}


Measured memory_bytes: 3072
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstring>
using namespace std;
int map[55];
int main()
{
	int n,m;
	memset(map,0,sizeof(map));
	cin>>n>>m;
	while(m--)
	{
		int a,b;
		cin>>a>>b;
		map[a]++;
		map[b]++;
	}
	for(int i=1; i<=n; i++)
		cout<<map[i]<<endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Comparator;
import java.util.Scanner;

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

        ArrayList<Integer> list = new ArrayList<>(num);
        while (sc.hasNext()) {
            list.add(sc.nextInt());
        }

        list.sort(Comparator.reverseOrder());
        long sum = 0;
        for (int i = 1; i < num; i++) {
            sum += list.get(i/2);
        }
        System.out.print(sum);
    }
}


Measured memory_bytes: 63308
#include <bits/stdc++.h>
using namespace std;
#define all(a) a.begin(), a.end()

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

    string s;
    cin >> s;
    int n = s.length();
    string a = s.substr(0,(n-1)/2);
    string b = s.substr((n + 1) / 2, (n - 1) / 2);

    if(a != b) {
        cout << "No" << "\n";
        return 0;
    }
    reverse(all(a));
    if(a == b)
        cout << "Yes" << "\n";
    else
        cout << "No" << "\n";
    return 0;
}


Measured memory_bytes: 3616
import java.util.*;
 
public class Main {
	
	public static final int A = 0;
	public static final int B = 1;
	
    public static void main( String args[] ) {
        Scanner scan = new Scanner( System.in );

		String str		= scan.next();
		int orderNum	= scan.nextInt();
		
		
		for( int i = 0; i < orderNum; i++ ) {
			int	strLength	= str.length();
			
			int[] option	= new int[2];
			String order	= scan.next();
			int A			= scan.nextInt();
			int B			= scan.nextInt();
	
			if ( order.equals( "print" ) ) {
				System.out.println( str.substring( A, B+1 ) );
				
			} else if ( order.equals( "reverse" ) ) {
				StringBuffer strBuf = new StringBuffer( str.substring( A, B+1 ) );
				String temp			= strBuf.reverse().toString();
				str					= str.substring( 0, A ) + temp + str.substring( B+1, strLength );
				
			} else if ( order.equals( "replace" ) ) {
				String replaceStr	= scan.next();
				str					= str.substring( 0, A ) + replaceStr + str.substring( B+1, strLength );
				
			}
			
		}

	}
	
	
	
}

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

int main(void) {
	string S,T;
	cin>>S>>T;
	
	reverse(S.begin(),S.end());
	reverse(T.begin(),T.end());
	
	int N=S.size();
	int n=T.size();
	
	for(int i=0;i<N;i++){
	    for(int j=0;j<n;j++){
	        if(S[i]=='?'){
	            for(int w=0;w<n;w++){
	                if(S[i+w]!='?')break;
	                if(w==n-1){
	                    S.replace(i,n,T);
	                    for(int x=0;x<N;x++){
	                        if(S[x]=='?')S[x]='a';
	                    }
	                    reverse(S.begin(),S.end());
	                    cout<<S<<endl;
	                    return 0;	                    
	                }
	            }
	        }
	        
	        if(S[i]==T[j]&&i>=j){
	            int m=0;
	            for(int k=i-j;k<i-j+n;k++){
	                if(S[k]!=T[m]&&S[k]!='?')break;
	                m++;
	                
	                if(k==i-j+n-1){
	                    S.replace(i-j,n,T);
	                    for(int u=0;u<N;u++){
	                        if(S[u]=='?')S[u]='a';
	                    }
	                    reverse(S.begin(),S.end());
	                    cout<<S<<endl;
	                    return 0;
	                }
	            }
	            
	        }    
	    }
	}
	
	cout<<"UNRESTORABLE"<<endl;
	
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
int main(){
  string str1;
  int JOI,IOI;
  while(cin >> str1){
    JOI=0,IOI=0;
    for(int i=2;i<str1.size();i++){
      if(str1[i]=='I'){
	if(str1[i-1]=='O'){
	  if(str1[i-2]=='J')JOI++;
	  if(str1[i-2]=='I')IOI++;
	}
      }
    }
    cout << JOI << endl;
    cout << IOI << endl;
  }
  return 0;
}

Measured memory_bytes: 1200
using System;
using System.Collections.Generic;
using System.Linq;

static class Program
{
    static void Main()
    {
        var q =
            from n in RepeatInfinite<Func<string>>( Console.ReadLine )
                .Select( x => int.Parse( x() ) )
                .TakeWhile( x => x > 0 )
            select Enumerable.Repeat<Func<string>>( Console.ReadLine, n )
                .Select( x => int.Parse( x() ) )
                .Aggregate(
                    new { sum = 0, max = -100000 },
                    (x, y) => {
                        var sum = x.sum < 0 || x.sum + y < 0
                            ? y
                            : x.sum + y;
                        return new { sum, max = Math.Max( x.max, sum ) };
                    },
                    x => x.max );
        q.ToList().ForEach( Console.WriteLine );
    }

    static IEnumerable<TSource> RepeatInfinite<TSource>(TSource source)
    {
        while ( true )
            yield return source;
    }
}

Measured memory_bytes: 6072
#include <bits/stdc++.h>
#define rep(i, n) for (lli i = 0; i < (n); i++)
#define rrep(i, n) for (lli i = (n)-1; i >= 0; i--)
#define vall(x) (x).begin(), (x).end()
using namespace std;
using lli = long long int;
void YESNO(bool), YesNo(bool);
template <class T1, class T2> bool chmin(T1 &l, const T2 &r);
template <class T1, class T2> bool chmax(T1 &l, const T2 &r);
template <class T1, class T2> void vadd(vector<T1> &v, T2 x);

#define int long long int

signed main() {
  int N;
  cin >> N;
  vector<int> a(N);
  rep(i, N) cin >> a[i];
  map<lli, lli> m1, m2;
  lli ret = 0;
  rep(i, N) {
    ret += m2[a[i] - i];
    m2[-a[i] - i]++;
  }
  cout << ret << endl;
  return 0;
}

// -- lib
void YESNO(bool b) { cout << (b ? "YES" : "NO") << endl; }
void YesNo(bool b) { cout << (b ? "Yes" : "No") << endl; }

template <class T1, class T2> bool chmin(T1 &l, const T2 &r) {
  return (l > r) ? (l = r, true) : false;
}

template <class T1, class T2> bool chmax(T1 &l, const T2 &r) {
  return (l < r) ? (l = r, true) : false;
}

template <class T1, class T2> void vadd(vector<T1> &v, T2 x) {
  for (auto &s : v)
    s += T2(x);
}


Measured memory_bytes: 27332
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
const int inf=1e9+7;
const ll mod=1e9+7;

int main() {
    int N;
    cin>>N;
    vector<int> D(N);
    for(int i=0;i<N;++i){
        cin>>D[i];
    }
    sort(D.begin(), D.end());
    int l=24, r=0;
    int ans = 24;
    for(int i=0;i<N;++i){
        if(i%2==0){
            if(ans > D[i] - r) ans = D[i] - r;
            r = D[i];
        }
        else{
            if(ans > l - (24-D[i])) ans = l - (24 - D[i]);
            l = 24 - D[i];
        }
        if(ans > l - r) ans = l - r;
    }
    cout<<ans<<endl;
}



Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] p = new int[n];
        for (int i = 0; i < n; i++) {
            p[i] = sc.nextInt();
        }
        sc.close();

        int ans = 0;
        for (int i = 0; i < n - 2; i++) {
            if (p[i] < p[i + 1] && p[i + 1] < p[i + 2]) {
                ans++;
            } else if (p[i] > p[i + 1] && p[i + 1] > p[i + 2]) {
                ans++;
            }
        }
        System.out.println(ans);
    }

}


Measured memory_bytes: 25172
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		try (Scanner scanner = new Scanner(System.in)) {
			int n = scanner.nextInt();
			int[] a = new int[n];
			int[] b = new int[n];
			int[] c = new int[n - 1];

			for (int i = 0; i < n; i++) {
				a[i] = scanner.nextInt();
				a[i]--;
			}
			for (int i = 0; i < n; i++) {
				b[i] = scanner.nextInt();
			}
			for (int i = 0; i < n - 1; i++) {
				c[i] = scanner.nextInt();
			}

			int ans = 0;
			for (int i = 0; i < n; i++) {
				ans += b[a[i]];
				if (i > 0 && a[i] == a[i - 1] + 1) {
					ans += c[a[i - 1]];
				}
			}

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


Measured memory_bytes: 21844
import java.util.Scanner;

public class Main{
	String str[][] = {
		{" "},
		{"'", ",", ".", "!", "?"},
		{"a", "b", "c", "A", "B", "C"},
		{"d", "e", "f", "D", "E", "F"},
		{"g", "h", "i", "G", "H", "I"},
		{"j", "k", "l", "J", "K", "L"},
		{"m", "n", "o", "M", "N", "O"},
		{"p", "q", "r", "s", "P", "Q", "R", "S"},
		{"t", "u", "v", "T", "U", "V"},
		{"w", "x", "y", "z", "W", "X", "Y", "Z"}
	};
	public Main(){
		Scanner sc = new Scanner(System.in);
		
		while(sc.hasNext()){
			String st = sc.next();
			int n = st.length();
			
			for(int i = 0; i < n;){
				String s = st.substring(i, i+1);
				int t = Integer.parseInt(s);
				int c = 0;
				int l = str[t].length;
				i++;
				if(s.equals("0")){
					for(; i <= n-1 && s.equals(st.substring(i, i+1)); i++, c++){
						System.out.print(" ");
					}
				} else {
					for(; i <= n-1 && s.equals(st.substring(i, i+1)); i++, c++);
					System.out.print(str[t][c%l]);
				}
			}
			System.out.println();
		}
	}
	public static void main(String[] args){
		new Main();
	}
}

Measured memory_bytes: 12000
#include <bits/stdc++.h>
#define r(i,n) for(int i = 0; i<n; i++)
using namespace std;
 
int main() {
  int a, b, c, d;
  cin >> a >> b >> c >>d;
  if((a+b)<(c+d))cout << "Right" << endl;
  else if((a+b)>(c+d))cout << "Left" << endl;
  else cout << "Balanced" << endl;
}


Measured memory_bytes: 256
#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-1;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define INF 999999999
typedef pair<ll, ll> LP;

ll min(ll a, ll b){
	if (a<b) return a;
	else return b;
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	string s;
	cin >> s;
	ll ans = 0;
	if (s.size() == 0){cout << 0 << endl; return 0;}
	if (s.size() == 1){
		if (s[0] == s[1]){cout << 1 << endl; return 0;}
		else {cout << 0 << endl; return 0;}
	}
	ll o_cnt_0 = 0;
	ll e_cnt_0 = 0;
	ll o_cnt_1 = 0;
	ll e_cnt_1 = 0;
	for (auto i = 0; i < s.size(); i++){
		if (i%2 == 0){
			if (s[i] == '0'){o_cnt_0++;}
			else {o_cnt_1++;}
		} else {
			if (s[i] == '0'){e_cnt_0++;}
			else {e_cnt_1++;}
		}
	}
	cout << min(o_cnt_0+e_cnt_1, o_cnt_1+e_cnt_0) << endl;
}

Measured memory_bytes: 512
#include <iostream>
#include <cstdio>
#include <string>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <cmath>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
const long long INF = 1e9 + 7;
using namespace std;
typedef long long ll;
map<int, int> mp;
int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	int a, b;
	cin >> a >> b;
	if ((a > 0 && b > 0) || ((a < 0 && b < 0) && (abs(a - b) % 2 == 1))) {
		cout << "Positive\n";
	}
	else if ((a < 0 && b > 0) || (a > 0 && b < 0)) {
		cout << "Zero\n";
	}
	else {
		cout << "Negative\n";
	}
	return 0;
}

Measured memory_bytes: 256
# coding:utf-8

# 0101~ か 1010~のどちらの列が最適かを判定
# 0:0101~ , 1:1010~
def getOptimumPattern(tiles):
	n = len(tiles)
	zero = [ "0" if i%2 == 0 else "1" for i in range(n)]
	one = [ "1" if i%2 == 0 else "0" for i in range(n)]
	zero_count = 0
	one_count = 0
	for l,z in zip(tiles,zero):
		if l != z:
			zero_count = zero_count + 1

	for l,o in zip(tiles,one):
		if l != o:
			one_count = one_count + 1

	if zero_count <= one_count:
		return zero_count
	else:
		return one_count

tiles= list(input())
result = getOptimumPattern(tiles)
print(result)


Measured memory_bytes: 5544
#include<bits/stdc++.h>
using namespace std;
 
typedef unsigned int ui;
#define rep(i,l,r) for(int i=l;i<=r;++i)
const int N=2000+5,A=4e6+5;
int cnt[A];
ui a[1<<17];int mx;
bool Count(int x)
{
	return a[x/32]&(1<<(x&31));
}
void move(int x)
{
	int u=mx/32;mx+=x;
	int du=x/32,di=x&31;
	if(!di)
	{
		for(int i=u;i>=0;--i)a[i+du]|=a[i];
		return ;
	}
	for(int i=u;i>=0;--i)
	{
		a[i+du+1]|=a[i]>>32-di;
		a[i+du]|=a[i]<<di;
	}
}
 
int main()
{
	//freopen("will.in","r",stdin);freopen("will.out","w",stdout);
	int n;
	cin>>n;
mx=0;a[0]=1;
	rep(i,1,n)
	{
		int x;
		scanf("%d",&x);
		move(x);
	}
	
	int tot=0;
	rep(i,1,mx)
	if(Count(i))++tot;
	tot=(tot+1)/2;
	rep(i,1,mx)
	if(Count(i))
	{
		if(!--tot)
		{
			cout<<i;
			exit(0);
		}
	}
}

Measured memory_bytes: 768
def main():
    import sys
    import math
    N=int(sys.stdin.readline())
    T=[]
    for i in range(N):
        x,l=map(int,sys.stdin.readline().split())
        s=max(x-l,0)
        e=x+l
        T.append((s,e))
    T.sort(key=lambda x:x[1])
    now=0
    count=0
    for s,e in T:
        if s<now:
            continue
        else:
            count+=1
            now=e
    print(count)
main()

Measured memory_bytes: 52572
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int i=0; i<(int)(n); i++)
using P =  pair<int, int>;
using T = tuple<int, int ,int>;

// const int MAX_M = 1e5;
// const int MAX_V = 1e9;
// int N, M;
// int a[MAX_N], b[MAX_N];

int main(){
    int k;
    string s;
    cin >> k >> s;

    if(s.size() <= k){
        cout << s << endl;
        return 0;
    }
    cout << s.substr(0,k) << "..." << endl;

    return 0;
}

Measured memory_bytes: 3628
#include <iostream>
#include <numeric>
#include <algorithm>
#include <vector>

using namespace std;

int main() {
  int n, input;

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

    vector<int> scores;
    for (int i = 0; i < n; i++) {
      cin >> input;
      scores.push_back(input);
    }

    cout << (accumulate(scores.begin(), scores.end(), 0) - *max_element(scores.begin(), scores.end()) - *min_element(scores.begin(), scores.end())) / (n - 2) << endl;
  }

  return 0;
}

Measured memory_bytes: 1216
count = 0
n = int(input())
A = [int(input()) for _ in range(n)]

def insertionSort(A, n, g):
    global count
    for i in range(g, n):
        v = A[i]
        j = i - g
        while j >= 0 and A[j] > v:
            A[j + g] = A[j]
            j = j - g
            count += 1
        A[j + g] = v

def shelSort(A, n):
    count = 0
    g = []
    h = 1
    while h <= n:
        g.append(h)
        h += h * 3 + 1
    g.reverse()
    m = len(g)
    print(m)
    print(' '.join([str(x) for x in g]))
    for i in range(m):
        insertionSort(A, n, g[i])

shelSort(A, n)
print(count)
for v in A:
    print(v)



Measured memory_bytes: 45516
#include<iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<iomanip>
#include<vector>
#include<fstream>
#include <stdio.h>
#include <string.h>
#include<queue>
using namespace std;
 
void winter_is_coming()
{
	std::ios_base::sync_with_stdio(0);
	cin.tie(NULL); cout.tie(NULL );
}
 
int main()
{
    //freopen(".in", "r", stdin); //fclose (stdout);
	winter_is_coming();
  
	int n,x,y,t2,dis=0,dis2,t=0;
	bool in=true;
	cin>>n;
	for(int i=0;i<n;i++)
	{
		cin>>t2>>x>>y;
		dis2=x+y;
		if(dis2-dis>t2-t) in=false;
		if(t2-t>(dis2-dis) && ((t2-t)-(dis2-dis))%2==1) in=false;
		t=t2,dis=dis2;
	}
 if(in)  cout<<"Yes\n";
 else    cout<<"No\n";
   // system("pause");
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep0(i,n) for(ll (i) = 0; (i) < (n); ++(i))
#define rrep0(i,n) for(ll (i) = (n) - 1; (i) >= 0; --(i))
#define rep1(i,n) for(ll (i) = 1; (i) < (n); ++(i))
#define rrep1(i,n) for(ll (i) = (n) - 1; (i) >= 1; --(i))
#define nfor(i,a,b) for(ll (i) = (a); (i) < (b); ++(i))
#define ll long long
#define mod (1000000007)
#define YES cout << "YES" << endl;
#define Yes cout << "Yes" << endl;
#define yes cout << "yes" << endl;
#define NO cout << "NO" << endl;
#define No cout << "No" << endl;
#define no cout << "no" << endl;
#define all(x) (x).begin(),(x).end()

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

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

ll fac(ll n){
    ll t = 1;
    rep1(i, n + 1)t *= i;
    return t;
}

int main()
{
    int n,ans = 0;
    bool a = false;
    cin >> n;
    vector<int> s(n);
    rep0(i, n){
        cin >> s[i];
        ans += s[i];
        if (s[i] % 10 != 0) {
            a = true;
        }
    }
    if (!a) {
        cout << 0 << endl;
        return 0;
    }
    sort(all(s));
    for (int i = 0; ;++i ) {
        if (ans % 10 != 0) {
            cout << ans << endl;
            return 0;
        }else if(s[i] % 10 != 0){
            ans -= s[i];
        }
    }
    return 0;
}


Measured memory_bytes: 256
N=int(input())
F=[list(map(int,input().split())) for i in range(N)]
P=[list(map(int,input().split())) for i in range(N)]

reward_list=[]
for i in range(1023):
    k=i+1
    t=[]
    c=[0 for j in range(N)]
    while(1):
        t.append(k%2)
        k=k//2
        if(k==0):
            length=len(t)
            if(length<10):
                for i in range(10-length):
                    t.append(0)
            break
    reward=0
    for j in range(N):
        for f in range(10):
            c[j]+=F[j][f]*t[f]
        reward+=P[j][c[j]]
    reward_list.append(reward)
print(max(reward_list))


Measured memory_bytes: 3064
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<utility>
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
const ll INF = mod * mod;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef vector<int> vec;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define stop char nyaa;cin>>nyaa;

bool isnum(char t) {
	if ('0' <= t && t <= '9')return true;
	return false;
}
ll ppow(ll x, ll n) {
	ll ret = 1;
	rep(i, n) {
		ret *= x;
	}
	return ret;
}
bool calc(ll x, vector<ll> &c) {
	ll ret = 0;
	rep(i, 6) {
		ll t = ppow(x, i);
		ret += c[i] * t;
	}
	return ret==0;
}
void solve() {
	string s; cin >> s;
	int m = s.length();
	vector<ll> c(6);
	ll pre = 1;
	rep(i, m) {
		if (s[i] == 'x') {
			c.push_back(pre);
			if (i + 1 < m&&s[i + 1] == '^') {
				char t = s[i + 2];
				int z = t - '0';
				c[z] = pre; i += 2;
			}
			else {
				c[1] = pre;
			}
			pre = 1;
		}
		else if (s[i] == '-') {
			pre *= -1;
		}
		else if ('0' <= s[i] && s[i] <= '9') {
			int le = i;
			while (i + 1 < m&&isnum(s[i + 1]))i++;
			string t = s.substr(le, i - le + 1);
			int z = stoi(t);
			pre *= z;
		}
	}
	c[0] = pre;
	int n = 0;
	rep1(i, 5) {
		if (c[i] > 0)n = i;
	}
	int tmp = 0;
	vector<int> ans;
	rep1(i, 2000) {
		if (calc(i,c)) {
			tmp++; ans.push_back(i);
		}
		if (calc(-i, c)) {
			tmp++; ans.push_back(-i);
		}
		if (tmp == n)break;
	}
	sort(ans.begin(), ans.end(), greater<int>());
	rep(i, ans.size()) {
		cout << "(x";
		if (ans[i] < 0) {
			cout << '+';
		}
		else {
			cout << '-';
		}
		string t = to_string(abs(ans[i]));
		cout << t << ')';
	}
	cout << endl;
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	solve();
	//stop
		return 0;
}


Measured memory_bytes: 3268
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const ll mod= 1e9+7;
const ll INF= 1e18L+5;

void sub_self(ll& a, ll b){
	a -=b;
	if(a<0){
		a += mod;
	}
}

int main() {
	ll n,k;
	cin >> n >> k;
	ll a[n];
	ll dp[k+1] = {0};
	dp[0]=1;
		
	for(ll i=0; i<n; i++){
		cin >> a[i];
		ll temp[k+1] = {0};
	
		for(ll used = k; used>=0; used--){
			ll l = used+1;
			ll r = used+min(a[i],k-used);
			if(l<=r){
				temp[l] = (temp[l]%mod+dp[used]%mod)%mod;
				if(r<k)
					sub_self(temp[r+1],dp[used]);
			}
			// for(ll j=l; j<=r && j<=k; j++){
			// 	dp[j] = (dp[used]+dp[j])%mod;
			// }
		}
		ll sum = 0;
		for(ll j=0;j<=k; j++){
			// temp[j] = j==0 ? temp[j] : (temp[j]+temp[j-1])%mod;
			// dp[j] = (dp[j]+temp[j])%mod;
			sum = (sum%mod + temp[j]%mod)%mod;
			dp[j] = (dp[j]%mod+sum)%mod;
		}
	}
	cout<<dp[k]<<endl;
}

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

using namespace std;

struct Node {
  char data;
  Node *next;
  Node *prev;
  Node(char data) : data(data), next(nullptr), prev(nullptr) {}
};

struct LinkedList {
  Node *top;
  Node *last;

  LinkedList() : top(nullptr), last(nullptr) {}

  void reset(char ch) {
    Node *node = new Node(ch);
    top = last = node;
  }

  void append(char ch) {
    if (top == nullptr) {
      reset(ch);
      return;
    }

    Node *node = new Node(ch);
    Node *old_last = last;
    last = node;
    old_last->next = node;
    last->prev = old_last;
  }

  void prepend(char ch) {
    if (top == nullptr) {
      reset(ch);
      return;
    }
    
    Node *node = new Node(ch);
    Node *old_top = top;
    top = node;
    top->next = old_top;
    old_top->prev = node;
  }
};

int main(int argc, const char *argv[])
{
  string s;
  int q;
  cin >> s >> q;

  Node* top, *last;
  LinkedList list;
  for (int i = 0; i < s.size(); i++) {
    list.prepend(s[i]);
  }
  
  bool reversed = false;
  for (int i = 0; i < q; i++) {
    int ti;
    cin >> ti;
    if (ti == 1) {
      reversed = !reversed;
    } else {
      int fi;
      char ci;
      cin >> fi >> ci;
      
      if ((fi == 1 && !reversed) || (fi != 1 && reversed)) {
        list.append(ci);
      } else {
        list.prepend(ci);
      }
    }
  }

  Node *cur = reversed ? list.top : list.last;
  while(cur != nullptr) {
    cout << cur->data;
    if (!reversed) {
      cur = cur->prev;
    } else {
      cur = cur->next;
    }
  }

  cout << "\n";

  return 0;
}

Measured memory_bytes: 9984