akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using static System.Math;
public static class P
{
    public static void Main()
    {
        int n = int.Parse(Console.ReadLine());
        var firstGender = GetGender(0);
        var valid = 0;
        var invalid = n - 1;
        while (invalid - valid > 1)
        {
            var mid = (valid + invalid) / 2;
            if (GetGender(mid) == (firstGender ^ mid & 1)) valid = mid;
            else invalid = mid;
        }
        GetGender(invalid);
        throw new Exception();
    }

    static int GetGender(int n)
    {
        Console.WriteLine(n);
        var s = Console.ReadLine();
    
        if (s == "Vacant") Environment.Exit(0);

        if (s == "Male") return 0;
        else return 1;
    }
}


Measured memory_bytes: 13480
import sys
readline = sys.stdin.buffer.readline
def even(n): return 1 if n%2==0 else 0

h,w = map(int,readline().split())
maze = []
for _ in range(h):
	maze.append(readline().rstrip().decode('utf-8'))

dp = [[0]*w for _ in range(h)]
dp[0][0] = 1
for i in range(h):
	for j in range(w):
		if maze[i][j] == "#":
			continue
		if i > 0:
			dp[i][j] += dp[i-1][j]
		if j > 0:
			dp[i][j] += dp[i][j-1]
		dp[i][j]%=10**9+7

print(dp[-1][-1])

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

int main(int argc, char const *argv[]) {
    int n;
    cin >> n;
    vector<long long> a(n), nums(n+1);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        nums[a[i]]++;
    }
    long long ans = 0;
    for (int i = 1; i <= n; i++) ans += nums[i] * (nums[i] - 1) / 2;

    for (int i = 0; i < n; i++) {
        long long new_ans = ans - nums[a[i]] * (nums[a[i]] - 1) / 2 + (nums[a[i]] - 1) * (nums[a[i]] - 2) / 2;
        cout << new_ans << endl;
    }
    return 0;
}


Measured memory_bytes: 6416
#include<stdio.h>
#include<string.h>
int main()
{
  int A,B,C;
  int con5=0,con7=0,con=0;
  
  scanf("%d %d %d",&A,&B,&C);
  
  if(A==5) con5++;
  else if(A==7) con7++;
  else con++;
  if(B==5) con5++;
  else if(B==7) con7++;
  else con++;
  if(C==5) con5++;
  else if(C==7) con7++;
  else con++;
  
  if(con==0&&con5==2&&con7==1)
    printf("YES");
  else printf("NO");
  
  return 0;
}

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

using namespace std;
#define int long long
const int MOD = 1000000007;

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N;
	string S;
	cin >> S;
	N = S.size();
	vector<int> A(N, 0);
	int res = 0;
	int t = 0;
	int cur = 0;
	int tot = 0;
	for (int i = 0; i < N; i++) {
		if (t == 0 && S[i] == '1') {
			A[i] = 1;
			cur++;
			tot++;
			res += cur;
			t = 1;
		} else if (t == 1) {
			A[i] = 1;
			tot++;
			res += cur;
			t = 0;
		}
	}
	int X[2];
	X[0] = 0;
	X[1] = 0;
	//cerr << res << endl;
	for (int i = N - 1; i >= 0; i--) {
		swap(X[0], X[1]);
		if (S[i] == '1') {
			X[0]++;
		}
		if (A[i] == 1) {
			tot--;
		} else {
			cur += X[tot % 2];
			cur -= X[(tot + 1) % 2];
			res += cur;
		}
		
		//cerr << res << endl;
	}

	cout << res << endl;
}

Measured memory_bytes: 5212
import math
N = int(input())
T = []
for i in range(N):
    a = list(map(int, input().split()))
    T.append(a)

mod = 10**9+7

A = {}
c_zero = 0
a_zero = 0
b_zero = 0
for i in range(N):
    if T[i][0] == 0 and T[i][1] == 0:
        c_zero += 1
    elif T[i][0] == 0:
        a_zero += 1
    elif T[i][1] == 0:
        b_zero += 1
    else:
        t = math.gcd(abs(T[i][0]),abs(T[i][1]))
        c = 0
        if T[i][0] < 0:
            T[i][0] *= -1
            c += 1
        if T[i][1] < 0:
            T[i][1] *= -1
            c += 1
        if (T[i][0]//t,T[i][1]//t,c%2) in A:
            A[T[i][0]//t,T[i][1]//t,c%2] += 1
        else:
            A[T[i][0]//t,T[i][1]//t,c%2] = 1

used = {}
for i in A.keys():
    used[i] = 0

ans = 1
for k,v in A.items():
    if used[k] == 0:
        if k[2] == 1:
            p = A.get((k[1],k[0],0),0)
            if p != 0:
                used[(k[1],k[0],0)] = 1
        else:
            p = A.get((k[1],k[0],1),0)
            if p != 0:
                used[(k[1],k[0],1)] = 1
        ans *= ( pow(2,v,mod)+pow(2,p,mod) - 1 )
        ans %= mod

ans *= ( pow(2,a_zero,mod)+pow(2,b_zero,mod) - 1 )
ans += c_zero
ans -= 1
print(ans%mod)

Measured memory_bytes: 167964
#include<iostream>
#include<unordered_map>
#include<vector>
#include<algorithm>
#include<cmath>
#include<string>
#include<queue>
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
typedef long double ld;
#define mp make_pair
#define pb push_back

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

    int len = s.length();

    ll anum=0;
    ll count = 0;
    for(int i = 0; i < len-1; i++){
        if(s[i] == 'A'){
            anum++;
            continue;
        }
        if(s[i] == 'B'){
            if(s[i+1] == 'C'){
                count += anum;
                i++;
                continue;
            }else{
                anum = 0;
            }
        }
        if(s[i] == 'C'){
            anum = 0;
        }
    }
    cout << count << endl;

    return 0;
}

Measured memory_bytes: 640
#include <math.h>
#include <iostream>
#include <vector>
#include <map>
#include <string>
#include <cmath>
#include <iomanip>
#include <algorithm>
#include <sstream>
#include <numeric>
using namespace std;

int main()
{
	string s;
	cin >> s;
	int a[26];
	for (int i = 0; i < (int)s.size(); i++) {
		a[s[i] - 'A']++;
	}
	int cnt = 0;
	for (int i = 0; i < 26; i++) {
		if (a[i] == 2) {
			cnt++;
		}
	}
	if (cnt == 2) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
	return(0);
}





Measured memory_bytes: 256
#include<stdio.h>
int main(){
    char s[100000];
    scanf("%s", &s);
    int sum =0;
    for(int i=0; i<sizeof(s);i++){
        if(s[i+1]!='0'&&s[i+1]!='1'){
            break;
        }
        if(s[i+1]==s[i]){
            sum++;
            if(s[i]=='1')s[i+1]='0';
            else s[i+1]='1';
        }
    }
    printf("%d\n", sum);
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#define N 2000000

using namespace std;

int main(){
  int i, j, n, k=0;
  int A[N], B[N], C[N];

  cin >> n;
  for(i=0;i<n;++i){
    cin >> A[i];
    if(A[i] > k) k = A[i];
  }
  
  for(i=0;i<=k;++i)C[i] = 0;
  for(i=0;i<n;++i)C[A[i]]++;
  for(i=0;i<=k;++i)C[i] += C[i-1];
  for(j=n-1;j>=0;--j){
    B[C[A[j]]-1] = A[j];
    C[A[j]]--;
  }
  
  for(i=0;i<n;++i){
    cout << B[i];
    if(i != n-1)cout << " ";
  }
  cout << "\n";
  return 0;
}



Measured memory_bytes: 18704
#include <cstdio>
#include <string>
#define repi(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,a) repi(i,0,a)
#define all(a) (a).begin(), (a).end()

int N, M;
int A[10];
constexpr int cnt[] = { -1, 2, 5, 5, 4, 5, 6, 3, 7, 6 };
std::string dp[10010];

// 3: [5] 7: [3] 8: [7] 4: [4]

std::string strMax( const std::string &s1, const std::string &s2 )
{
  if( s1.size() > s2.size() )
    return s1;
  else if( s1.size() < s2.size() )
    return s2;
  
  if( s1 > s2 )
    return s1;
  else
    return s2;
}

int main()
{
  scanf( "%d%d", &N, &M );
  rep( i, M )
    scanf( "%d", A+i );

  rep( i, N+1 )
    dp[i] = "*";

  dp[0] = "";

  rep( i, N+1 ) rep( j, M ) if( i-cnt[A[j]] >= 0 && dp[i-cnt[A[j]]] != "*" )
    dp[i] = strMax( dp[i], char(A[j]+'0')+dp[i-cnt[A[j]]] );

  printf( "%s\n", dp[N].c_str() );

  return 0;
}

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

int main() {
  char s;
  cin >> s;
  if (s == 'A')
  {
    cout << "T" << endl;
  }
  else if (s == 'T')
  {
    cout << "A" << endl;
  }
  else if (s == 'G')
  {
    cout << "C" << endl;
  }
  else
  {
    cout << "G" << endl;
  }
}

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

using namespace std;

struct restaurant
{
    string name;
    int score;
    int index;

    restaurant(const string& _name, int _score, int _index) :name(_name), score(_score), index(_index)
    {

    }

    bool operator<(const restaurant& r)
    {
        return name < r.name || name == r.name && score > r.score;
    }
};

int main()
{
    ios::sync_with_stdio(false);
    vector<restaurant> A;
    int n;
    cin >> n;
    A.reserve(n);
    for (int i = 0; i < n; ++i)
    {
        string name;
        int p;
        cin >> name >> p;
        A.push_back(restaurant(name, p, i + 1));
    }
    sort(A.begin(), A.end());
    for (auto& r : A)
    {
        cout << r.index << "\n";
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h> 
#define ll long long int
#define pb push_back

using namespace std; 


int main() 
{
    string s;
    cin>>s;
    int n = s.length();
    
    int j=n-1;
    int ans=0;
    for(int i=0;i<n/2;i++) {
        if(s[i]!=s[j]) {
            ans++;
        }
        j--;
    }
    
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define lper(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9;
const ll INF=4e18;
const ll dy[4]={1,0,-1,0};
const ll dx[4]={0,-1,0,1};
int main(){
    string S,T;cin>>S>>T;
    int a,b;cin>>a>>b;
    string U;cin>>U;
    if(U==S)cout<<a-1<<" "<<b<<endl;
    else cout<<a<<" "<<b-1<<endl;
    return 0;
}

Measured memory_bytes: 764
#include <iostream>
#include <vector>
#include <map>

using namespace std;

int main(){
  long long n, m;
  long long result = 0;
  cin >> n >> m;
  map<long long,long long> a;
  for (int i=0;i<n;i++) {
    long long a_tmp;
    cin >> a_tmp;
    if (a.find(a_tmp) == a.end()) {
      a[a_tmp] = 0;
    }
    a[a_tmp]++;
  }
  for (int i=0;i<m;i++) {
    long long b, c;
    cin >> b >> c;
    if (a.find(c) == a.end()) {
      a[c] = 0;
    }
    a[c] += b;
  }

  for (auto it = a.rbegin();it != a.rend();it++) {
    if (n-it->second <= 0) {
      result += n*it->first; 
      //      cout << it->first << "\t" << it->second << "\t" << result << "\t" << n << endl;
      cout << result << endl;
      return(0);
    }
    result += it->second * it->first;
    //    cout << it->first << "\t" << it->second << "\t" << result << "\t" << n << endl;
    n -= it->second;
  }
  return(0);
}


Measured memory_bytes: 12800
#include <iostream>
#include <stdio.h>
using namespace std;
int main(void){
    // Your code here!
    long long int a,b,c,k,point=0;
    scanf("%lld %lld %lld %lld",&a,&b,&c,&k);
    for(int i=0;i<k;i++){
        if(a>0){
            point++;
            a--;
        }else if(b>0){
            b--;
        }else{
            point--;
        }
    }
    printf("%lld",point);
}


Measured memory_bytes: 3752
#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 repr(i,n) for(int i=(n)-1;0<=i;--i)
#define each(e,v) for(auto&& e:(v))
#define all(v) begin(v),end(v)
#define dump(x) cerr<<#x<<": "<<(x)<<endl
#define INF 100000000
#define IINF 9999999999999;
using vint = std::vector<int>;
using ll = long long;
using vll = std::vector<ll>;
template <class T> void chmin(T& a, const T& b) { a = std::min(a, b); }
template <class T> void chmax(T& a, const T& b) { a = std::max(a, b); }

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

    int N;
    cin >> N;
    if(N < 1200) {
        cout << "ABC" << endl;
    } else if(N < 2800) {
        cout << "ARC" << endl;
    } else {
        cout << "AGC" << endl;
    }

    return 0;
}


Measured memory_bytes: 892
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<string>
using namespace std;//dreamer  eraser
int main(){
    char s[100000+50];
    scanf("%s",s);
    int i ;
    for( i = strlen(s)-1; i > 0 ; i--){
        if(s[i]=='r'){
            if(s[i-1]=='e'&&s[i-2]=='m'&&s[i-3]=='a'&&s[i-4]=='e'&&s[i-5]=='r'&&s[i-6]=='d'&&i - 6 >= 0)
                i = i - 6;
            else
                if(s[i-1]=='e'&&s[i-2]=='s'&&s[i-3]=='a'&&s[i-4]=='r'&&s[i-5]=='e'&&i - 5 >= 0)
                i = i - 5;
            else break;
        }
        else
        if(s[i]=='m'){
            if(s[i-1]=='a'&&s[i-2]=='e'&&s[i-3]=='r'&&s[i-4]=='d'&&i - 4 >= 0)
                i = i - 4;
            else
                break;
        }
        else
        if(s[i]=='e'){
            if(s[i-1]=='s'&&s[i-2]=='a'&&s[i-3]=='r'&&s[i-4]=='e'&&i - 4 >= 0)
                i = i - 4 ;
            else break;
        }
        else break;
    }
    if(i!=-1)
       printf("NO\n");
    else  printf("YES\n");
    return 0;
}


Measured memory_bytes: 384
#include "bits/stdc++.h"
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a),i##_len=(b);i<i##_len;++i)
#define BUGAVOID(x) x
#define rep(...) BUGAVOID(_overload3(__VA_ARGS__,repi,_rep,_rep)(__VA_ARGS__))
#define sz(c) (int)(c.size())
#define all(c) c.begin(),c.end()
#define ms(a,v) memset(a,v,sizeof(a))
#define mp make_pair
#define write(x) cout<<(x)<<endl
using namespace std; typedef long long ll; typedef vector<int> vi; typedef vector<ll> vll;
template<class T>bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; }return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; }return 0; }
constexpr ll pow2(const int n) { return 1ll << n; }
const int INF = 1 << 28; const ll LINF = 1ll << 60;
const int MAX = 1e5 + 5; const int MOD = 1e9 + 7; const double EPS = 1e-6;
const int dy[4] = { 0,1,0,-1 }; const int dx[4] = { 1,0,-1,0 };
struct aaa { aaa() { cin.tie(0); ios::sync_with_stdio(0); }; }aaaa;
// 1. 問題よくよめえええええええええええええええええええええええええ
// 2. intオーバーフロー << * + あたり
// 3. 落ち着け

int N, M;
vector<int> start;
vector<vector<pair<int, int>>> graph; // <to, cost>
vector<int> dist;
vector<bool> visited;
int ans;

int main() {
    cin >> N >> M;
    start.assign(N, 0);
    graph.assign(N, vector<pair<int, int>>());
    rep(i, M) {
        int l, r, d;
        cin >> l >> r >> d;
        l--; r--;
        graph[l].emplace_back(r, d);

        if (d > 0) {
            start[r] = 2; // Rに来たものは始点x=0になれない
        }

        if (start[l] != 2) {
            start[l] = 1;
        }
    }

    ans = 1; // Yes
    dist.assign(N, -1);
    visited.assign(N, false);
    rep(i, N) {
        if (start[i] != 1) continue;
        if (dist[i] == -1) {
            dist[i] = 0;
        }
        vector<pair<int, int>> stack; // <v, cost>
        stack.emplace_back(i, 0);

        while (not stack.empty()) {
            const auto top = stack.back();
            stack.pop_back();
            dist[top.first] = top.second;

            for (const auto& e : graph[top.first]) {
                if (dist[e.first] == -1) {
                    stack.emplace_back(e.first, top.second + e.second);
                    
                    if (start[e.first] == 2) {
                        start[e.first] = 0;
                    }
                }
                else if (top.second + e.second != dist[e.first]) {
                    ans = 0;
                    break;
                }
            }

            if (ans == 0) {
                break;
            }
        }

        if (ans == 0) {
            break;
        }
    }

    bool rExists = false;
    rep(i, N) {
        if (start[i] == 2) rExists = true;
    }
    if (rExists) ans = 0;

    write(ans ? "Yes" : "No");
}

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

int main(){
    int h, w;
    cin >> h >> w;

    int a[h][w];
    int flag[h][w];
    for(int i = 0;  i < h; i++){
        for(int j = 0; j < w; j++){
            cin >> a[i][j];
            flag[i][j] = 0;
        }
    }

    int dx[4] = {1, -1, 0, 0};
    int dy[4] = {0, 0, 1, -1};
    vector<pair<int, int> > ans_1;
    vector<pair<int, int> > ans_2;
    for(int i = 0; i < h; i++){
        for(int j = 0; j < w; j++){
            if(a[i][j] % 2 == 1){
                int che = 0;
                for(int k = 0; k < 4; k++){
                    int x = i + dx[k];
                    int y = j + dy[k];
                    if(x >= 0 && x < h && y >= 0 && y < w){
                        if(a[x][y] % 2 == 1){
                            a[i][j]--;
                            a[x][y]++;
                            ans_1.push_back(make_pair(i, j));
                            ans_2.push_back(make_pair(x, y));
                            che = 1;
                            break;
                        }
                    }
                }

                if(che == 0){
                    for(int k = 0; k < 4; k++){
                        int x = i + dx[k];
                        int y = j + dy[k];
                        if(x >= 0 && x < h && y >= 0 && y < w){
                            if(flag[x][y] == 0){
                                a[i][j]--;
                                a[x][y]++;
                                ans_1.push_back(make_pair(i, j));
                                ans_2.push_back(make_pair(x, y));
                                break;
                            }
                        }
                    }
                }
            }
            flag[i][j] = 1;
        }
    }

    cout << ans_1.size() << endl;
    for(int i = 0; i < ans_1.size(); i++){
        cout << ans_1[i].first + 1 << " " << ans_1[i].second + 1 << " " << ans_2[i].first + 1 << " " << ans_2[i].second + 1 << endl;
    }
}

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

using namespace std;

int64_t N, K;
vector<int64_t> A;
vector<int64_t> B;
vector<int64_t> C;

// Mより小さい積の個数を求める(Mは含まない)
int64_t CountSmaller(int64_t M) {
  int64_t total = 0;
  for (int i = 0; i < N; i++) {
    if (A[i] > 0) {
      int64_t r = (M >= 0) ? ((M + A[i] - 1) / A[i]) : (M / A[i]);
      int64_t K = (int64_t)(lower_bound(A.begin(), A.end(), r) - A.begin());
      total += K;
    } else if (A[i] == 0) {
      int64_t K = (M > 0) ? N : 0;
      total += K;
    } else {
      int64_t a = -A[i];
      int64_t r = (M >= 0) ? ((M + a - 1) / a) : (M / a);
      int64_t K = (int64_t)(lower_bound(B.begin(), B.end(), r) - B.begin());
      total += K;
    }
  }
  int64_t K = (int64_t)(lower_bound(C.begin(), C.end(), M) - C.begin());
  total -= K;
  return total / 2;
}

int main() {
  cin >> N >> K;
  A.resize(N);
  B.resize(N);
  C.resize(N);
  for (int i = 0; i < N; i++) cin >> A[i];
  sort(A.begin(), A.end());
  for (int i = 0; i < N; i++) {
    B[i] = -A[N - 1 - i];
  }
  for (int i = 0; i < N; i++) C[i] = A[i] * A[i];
  sort(C.begin(), C.end());

  int64_t L = numeric_limits<int64_t>::min();
  int64_t R = numeric_limits<int64_t>::max();

  for (int i = 0; i < 200; i++) {
    int64_t M = (L + R) / 2;
    int64_t C = CountSmaller(M);
    if (C < K) {
      L = M;
    } else {
      R = M;
    }
  }
  cout << L << endl;

  return 0;
}


Measured memory_bytes: 4992
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(ll i=0;i<((ll)n);i++)
#define rep1(i,n) for(ll i=1;i<=((ll)n);i++)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define IOS ios_base::sync_with_stdio(0); cin.tie(0)
#define meow(a) cout<<a<<" meow\n";
typedef pair<long long,long long> pii;
typedef vector<pii> vii;
const ll maxn=200005;
const ll MOD=998244353;
double mypow(ll a,ll b){
	double res=1;
	while(b){
		if(b&1) res=res*a;
		a=a*a;

		b>>=1;
	}
	return res;
}
ll t,n,m;
ll num[100005];
struct aaa
{
    string city;
    ll score;
    ll id;
}rest[105];
bool cmp(aaa a,aaa b)
{
    if(a.city==b.city) return a.score>b.score;
    return a.city<b.city;
}
int main()
{
    //IOS;
    //cin>>t;
    ll a,b;
    while(cin>>a>>b)
    {
    cout<<(a*3+b)/2<<"\n";
    }
    return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_N = 20000;
const int MAX_M = 16;
const int MAX_C = 256;

const int INF = 1 << 30;

/* typedef */

/* global variables */

int n, m;
int cs[MAX_M], xs[MAX_N];
int dp[2][MAX_C];

/* subroutines */

inline int diff2(int d) { return d * d; }

/* main */

int main() {
  for (;;) {
    cin >> n >> m;
    if (n == 0) break;

    for (int i = 0; i < m; i++) cin >> cs[i];
    for (int i = 0; i < n; i++) cin >> xs[i];

    int cur = 0, nxt = 1;
    for (int c = 0; c < MAX_C; c++) dp[cur][c] = INF;
    dp[cur][128] = 0;

    for (int i = 0; i < n; i++) {
      for (int c = 0; c < MAX_C; c++) dp[nxt][c] = INF;

      for (int c = 0; c < MAX_C; c++) {
	if (dp[cur][c] < INF)
	  for (int j = 0; j < m; j++) {
	    int nc = c + cs[j];
	    if (nc < 0) nc = 0;
	    else if (nc >= MAX_C) nc = MAX_C - 1;
	    int d2 = diff2(xs[i] - nc);
	    int ndp = dp[cur][c] + d2;
	    if (dp[nxt][nc] > ndp) dp[nxt][nc] = ndp;
	  }
      }

      cur ^= 1;
      nxt ^= 1;
    }

    int min_d = INF;
    for (int c = 0; c < MAX_C; c++)
      if (min_d > dp[cur][c]) min_d = dp[cur][c];
    cout << min_d << endl;
  }

  return 0;
}

Measured memory_bytes: 1240
#include<stdio.h>
int main(void)
{
	int n,m,i,z=0;
		while(1){
		z=0;
		scanf("%d",&n);
		if(n==0) break;
		for(i=0;i<9;i++){
		m=0;
			scanf("%d",&m);
			z+=m;
		}
		n=n-z;
		printf("%d\n",n);
		}
	return 0;
}	

Measured memory_bytes: 2692
#include<stdio.h>
#define N 100001
void partition(int *,int,int);

int main(){
  
  int n;
  int A[100001];
  scanf("%d",&n);
  for(int i=0;i<n;i++) scanf("%d",&A[i]);
  partition(A,0,n);
  return 0;
}

void partition(int A[],int p,int r){
  int x = A[r-1];
  int j,tmp;
  j=p;
  for(int i=p;i<r;i++){
    if(A[i]<=x){
      tmp = A[i];
      A[i] = A[j];
      A[j]=tmp;
      j++;
    }
  }
  for(int i=p;i<r;i++){
    if(i==j-1) printf("[%d]",A[i]);
    else printf("%d",A[i]);
    if(i!=r-1) printf(" ");
  }
  printf("\n");
}
    




Measured memory_bytes: 2964
#include<iostream>
#include<string>
#include <stack>
#include<algorithm>
using namespace std;

int main(){
    string s;
    cin>>s;
    stack<char> st;
    for(int i=0;i<s.length();i++){
        if(i==0)
            st.push(s[i]);
        else{
            if(!st.empty()&&st.top()=='S'&&s[i]=='T'){
                st.pop();
            }
            else{
                st.push(s[i]);
            }
        }
    }
    cout<<st.size();
    return 0;
}



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

#define __STDC_FORMAT_MACROS
#define p64 PRId64

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR (i, 0, n)
#define ALL(f, x, ...)                                                         \
    ([&] (decltype ((x)) ALL) {                                                \
        return (f) (begin (ALL), end (ALL), ##__VA_ARGS__);                    \
    }) (x)

using namespace std;
using ll = int64_t;

int main() {
    string S;
    cin >> S;
    cout << string (S.length(), 'x') << endl;
    return 0;
}


Measured memory_bytes: 256
def expectation(p):
    return 0.5 * sum(p) + 0.5 * len(p)


def main():
    n, k = map(int, input().split())
    p = list(map(int, input().split()))
    max_num = sum(p[0:k])
    max_idx = 0
    lst = [max_num]
    for i in range(1, n-k+1):
        num = lst[i-1] + p[i+k-1] - p[i-1]
        lst.append(num)

        if num >= max_num:
            max_num = num
            max_idx = i
    print(expectation(p[max_idx:max_idx+k]))


if __name__ == "__main__":
    main()


Measured memory_bytes: 71816
#include <iostream>

using namespace std;

int main()
{
    long int n;
    cin>>n;
    long int a[n+1];
    long int minn;

    long int dem=0;
    cin>>a[1];
    minn=a[1];
    for(long int i=2;i<=n;i++)
    {
        cin>>a[i];
        if(a[i]>minn)
        {
            dem++;
        }
        else
        {
            minn=a[i];
        }
    }
    cout<<n-dem;

}


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

using namespace std;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    while(true){
        int a,b;
        cin>>a>>b;
        if(a==0 && b==0) break;
        
        for(int i=0; i<a; i++){
            for(int j=0; j<b; j++){cout<<"#";}
            cout<<"\n";
        }
        cout<<"\n";
    }
    
    
}


Measured memory_bytes: 3136
package main

import "fmt"

func main() {
	var sa, sb, sc string
	fmt.Scan(&sa, &sb, &sc)
	next := sa[0]
	sa = sa[1:len(sa)]
	win := ""
	for {
		if next == 'a' {
			if len(sa) == 0 {
				win = "A"
				break
			}
			next = sa[0]
			sa = sa[1:len(sa)]
		} else if next == 'b' {
			if len(sb) == 0 {
				win = "B"
				break
			}
			next = sb[0]
			sb = sb[1:len(sb)]
		} else {
			if len(sc) == 0 {
				win = "C"
				break
			}
			next = sc[0]
			sc = sc[1:len(sc)]
		}
	}
	fmt.Println(win)
}


Measured memory_bytes: 512
#include<iostream>
#include<algorithm>
#include<string>
#include<map>
#include<vector>
#include<utility>

using namespace std;
typedef long long ll;
void yes(){
cout<<"Yes"<<endl;
}
void no(){
cout<<"No"<<endl;
}
int main(){
ll a[3];
cin>>a[0]>>a[1]>>a[2];
sort(a,a+3);
cout<<a[2]*10+a[1]+a[0];
  return 0;
}



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

const int MAX_N = (int)2e5 + 5;
set<int> S[MAX_N];

int main(){
    ios::sync_with_stdio(false), cin.tie(nullptr);
    int H, W, N, cur = 2;
    cin>>H>>W>>N;
    for(int i=0;i<N;i++){
        int x, y;
        cin>>x>>y;
        S[y].emplace(x);
    }
    for(int i=1;i<=H;i++){
        S[W+1].emplace(i);
    }
    for(int i=1;i<=W;i++){
        S[i].emplace(H+1);
    }

    int ans = *S[1].upper_bound(0);
    for(int i=2;i<=W+1;i++){
        while(cur<ans){
            if(!S[i].count(cur)) break;
            ++cur;
        }
        if(cur==ans){
            cout<<ans-1<<endl;
            return 0;
        }
        ans = min(ans, *S[i].upper_bound(cur++));
    }
}

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

long gcd(long n, long m) {
	if (n == 0)return m;
	if (n < m)swap(n, m);
	return gcd(n % m, m);
}

int main() {
	int ans = 0;
	int N; cin >> N;
	for (int i = 1; i <= N; i+=2) {
		int c = 0;
		for (int j=2; j < i; j++) {
			if (i % j == 0)c++;
		}
		if (c == 6)ans++;
	}
	cout << ans;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

typedef long long ll;

const int LGX = 40;

ll f(ll x) {
    ll r = 0;
    for (int i = LGX - 1; i >= 1; i--) {
        ll t = x % (1ll << (i + 1)) - (1ll << i) + 1;
        if (t >= 0) {
            r += (t % 2) * (1ll << i);
        }
    }
    r += (x + 1) / 2 % 2;
    return r;
}

int main() {
    ll a, b;
    cin >> a >> b;

    cout << (f(a - 1) ^ f(b)) << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include<sstream>
#include<string>
#include<vector>
#include <cmath>
#include <limits>
#include <queue>
#include<algorithm>
#include <map>

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


int main(){
  int k, n;
  cin >> k >> n;
  int a[n];
  rep(i,n) cin >> a[i];
  int res = 0;
  int L[n-1];
  rep(i,n-1){
    if (res < a[i+1]-a[i]) res = a[i+1]-a[i];
  }
  if (res < a[0]+(k-a[n-1])) res = a[0]+(k-a[n-1]);
  cout << k-res << endl;

  return 0;
}

Measured memory_bytes: 1024
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons;

alias MP = Tuple!(int, "i", int, "p");

int[11] PS, CS;

void main()
{
    auto dg = readln.split.to!(int[]);
    auto D = dg[0];
    auto G = dg[1] / 100;

    foreach (i; 1..D+1) {
        auto pc = readln.split.to!(int[]);
        PS[i] = pc[0];
        CS[i] = pc[1] / 100;
    }

    int[3][11][1001] memo;
    int solve(int i, int c, int d) {
        if (i == 0 || i == D+1 || c <= 0) return 0;
        if (memo[c][i][d+1]) return memo[c][i][d+1];

        auto r1 = solve(i + d, c, d);
        int r2;
        if (c >= PS[i]) {
            r2 = PS[i] * i + CS[i] + solve(i + d, c - PS[i], d);
        } else {
            r2 = c * i;
        }
        return memo[c][i][d+1] = max(r1, r2);
    }

    foreach (i; 1..1001) {
        if (solve(1, i, 1) >= G || solve(D, i, -1) >= G) {
            writeln(i);
            return;
        }
    }
}

Measured memory_bytes: 380
#include <bits//stdc++.h>
using namespace std;
int in(void){int x;cin>>x;return x;}
#define rep(i,a,b) for(int i=int(a);i<int(b);i++)
#define ll long long int
long long int dx[4]={1,0,-1,0};
long long int dy[4]={0,1,0,-1};

int main() {
	int x,y,z;
	cin>>x>>y>>z;
	int M,m;
	M=min(y,z);
	if(y+z<=x)m=0;
	else{
		m=y+z-x;
	}
	cout<<M<<' '<<m;
	return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cstdio>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <math.h>
#define REP(i, b, n) for (Int i = b; i < Int(n); i++)
#define rep(i, n) REP(i, 0, n)
using namespace std;
using Int = long long;
Int inf = 1000000000000000001LL;
using vi = vector<Int>;
using vvi = vector<vi>;
using pii = pair<Int,Int>;
using mapis = unordered_map<Int,string>;
using mapii = unordered_map<Int,Int>;

Int GCD(Int a, Int b){
    if(b==0) return a;
    if(a < b) return GCD(b, a);
    unsigned r;
    while ((r=a%b)) {
        a = b;
        b = r;
    }
    return b;
}

Int LCM(Int a, Int b){
    return a*b/GCD(a,b);
}


int main() {
    Int N,K,count=0;
    Int mod=1000000000+7;
    cin >> N >> K;

    vi A = vi(N);

    rep(i,N){
        cin >> A[i];
    }

    rep(i,A.size()){
        Int tmp_count = 0;
        REP(j,i+1,A.size()){
            if(A[i]>A[j]){tmp_count++;}
        }
        count+=(tmp_count*K)%mod;
    }

    if (K>1){
        rep(i,A.size()){
            Int tmp_count = 0;
            REP(j,0,A.size()){
                if(A[i]>A[j]){tmp_count++;}
            }
            int hoge = K*(K-1)/2%mod;
            count+=((tmp_count)*hoge)%mod;
        }


    }


    cout << count%mod << endl;

    return 0;
}

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

#define lli long long int
#define REP(i,s,n) for(int i=s;i<n;i++)
#define MOD 1000000007
#define NUM 2520
#define INF (1LL<<50)
#define DEBUG 0
#define mp(a,b) make_pair(a,b)
#define SORT(V) sort(V.begin(),V.end())
#define PI (3.141592653589794)


void func(long long N, long long K, std::vector<long long> A){
    map<lli,lli> cnt;
    REP(i,0,N)cnt[A[i]]++;

    vector<lli> v;
    for(auto e:cnt)v.push_back(e.second);

    sort(v.begin(),v.end());

    lli ans = 0;
    if(v.size()<=K){
        cout<<0<<endl;
        return;
    }
    REP(i,0,v.size()-K){
        ans += v[i];
    }
    cout<<ans<<endl;
}

int main(){
    // cout << fixed << setprecision(5);

    long long N;
    scanf("%lld",&N);
    long long K;
    scanf("%lld",&K);
    std::vector<long long> A(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&A[i]);
    }
    func(N, K, std::move(A));
    return 0;
}


Measured memory_bytes: 16500
#include <iostream>
#include <string>
#define TABLE_SIZE 16777216

using namespace std;

void makeTable(int table[]){
    table['A'] = 1;
    table['C'] = 2;
    table['G'] = 3;
    table['T'] = 4;
}

int convert(string key, int table[]){
    int sum = 0, d = 1;
    for(int i = 0; i < key.size(); i++){
        sum += table[key[i]] * d;
        d *= 5;
    }
    return sum % TABLE_SIZE;
}

int main(){
    int n;
    int convertTable[128];
    bool checkTable[TABLE_SIZE];
    string order, str;

    cin >> n;
    makeTable(convertTable);
    for(int i = 0; i < n; i++){
        cin >> order >> str;
        if(order[0] == 'i'){
            checkTable[convert(str, convertTable)] = true;
        }
        else{
            if(checkTable[convert(str, convertTable)]){ cout << "yes" << endl; }
            else{ cout << "no" << endl; }
        }
    }
    return 0;
}


Measured memory_bytes: 8324
// #define _CRT_SECURE_NO_WARNINGS
// #define _USE_MATH_DEFINES	// M_PI=3.1415...
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <cmath>
#include <cstdlib>
#include <functional>
#include <locale>
#include <cctype>
#include <sstream>
#include <iomanip>	// 20桁出力 cout << setprecision(20) << double;
#include <queue>
#include <bitset>	// bitset<8> bs1(131uL); // 10000011 bs1[0]は1 01stringからビット集合生成可
#include <numeric>
#include <random>
using namespace std;

typedef long long LL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<LL> VL;
typedef vector<pair<int, int> > VPII;
typedef vector<string> VS;
typedef map<int, int> MAPII;
typedef multimap<int, char, greater<int> > MuMAPIC;
typedef multimap<int, string, greater<int> > MuMIS;
typedef pair<int, int> P;
typedef pair<int, pair<P, P> > PP;

#define INF 999999999999999997;
#define MP make_pair
#define FAST_IO  cin.tie(0); ios::sync_with_stdio(false);
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define FORL(i,a,b) for(LL i=(a);i<(b);i++)
#define FOR_REV(i,a,b) for(int i=(a);i>=(b);i--)
#define foreach_it(type,it,c) for(type::iterator it=c.begin(),c_end=c.end();it!=c_end;++it)
#define FOR_ITR(d) for(auto itr=d.begin(),d_end=d.end();itr!=d_end;++itr)	// C++11
#define O(s) cout<<s<<endl;

#define DUMP_VVI(b) FOR(i,0,b.size()){FOR(j,0,b[i].size())printf("%d ",b[i][j]);puts("");}
#define D_OUT(str,value) if(dbgF){cout<<str<<" : "<<value<<endl;}

template<class T>T IN() { T d; cin >> d; return d; }

LL gcd(LL a, LL b) { return (b > 0) ? gcd(b, a%b) : a; } // 最大公約数（Greatest Common Divisor）
LL lcm(LL a, LL b) { return a / gcd(a, b) * b; } // 最小公倍数（Least Common Multiple）
bool uruu(LL Y) { return (((Y % 4 == 0 && Y % 100 != 0) || Y % 400 == 0) ? true : false); } // うるう年判定

int dx[4] = { 0,1,0,-1 };
int dy[4] = { 1,0,-1,0 };
int dxx[8] = { 0,1,1,1,0,-1,-1,-1 };
int dyy[8] = { 1,1,0,-1,-1,-1,0,1 };

// vector注意
// vec[i][j]の形に入力を入れるとき、vecは初期化してある必要がある.

// ------------------- include, typedef, define END. -------------------

int main() {
	FAST_IO;
	bool dbgF = true; // for D_OUT(str, value)  ... cout<< str <<" : "<< value <<endl;

	LL K, T;
	VL a;
	cin >> K >> T;
	FOR(i, 0, T)
		a.push_back(IN<LL>());

	LL nowi = -1;
	while (1) {
		//debug
		/*FOR(i, 0, T) {
			cout << a[i] << " ";
		}cout << endl;*/

		// 最大値のある場所を求める
		LL maxa = 0;
		LL maxi = -1;
		FOR(i, 0, T) {
			if (nowi != i) {
				if (maxa < a[i]) {
					maxa = a[i];
					maxi = i;
				}
			}
		}
		//終了確認
		if (maxi == -1)break;
		// (前日を除く)最大値を1減らす
		a[maxi]--;
		nowi = maxi;
	}
	O((*max_element(a.begin(), a.end())));

	return 0;
}

Measured memory_bytes: 256
fun main(args : Array<String>) {
    val (h, w) = readLine()!!.split(" ").map { it.toInt() }
    val maze = Array(h){ readLine()!! }

    var maxDistance = 0
    maze.forEachIndexed { y, row ->
        for (x in row.indices) {
            if (row[x] == '.') {
                // start from here
                val max = bfs(maze, x, y, h, w)
                if (max > maxDistance) maxDistance = max
            }
        }
    }

    println(maxDistance)
}

fun bfs(maze: Array<String>, x: Int, y: Int, h: Int, w: Int): Int {
    val done = Array(h){ Array(w){false} }
    val queue = mutableListOf<Pos>()

    queue.add(Pos(x, y, 0))
    done[y][x] = true

    var maxCost = 0

    while(queue.size > 0) {
        val pos = queue.removeAt(0)
        val newCost = pos.cost + 1

        // left
        if (pos.x > 0 && maze[pos.y][pos.x-1] == '.' && !done[pos.y][pos.x-1]) {
            queue.add(Pos(pos.x-1, pos.y, newCost))
            done[pos.y][pos.x-1] = true
            maxCost = Math.max(maxCost, newCost)
        }
        // right
        if (pos.x < w-1 && maze[pos.y][pos.x+1] == '.' && !done[pos.y][pos.x+1]) {
            queue.add(Pos(pos.x+1, pos.y, newCost))
            done[pos.y][pos.x+1] = true
            maxCost = Math.max(maxCost, newCost)
        }
        // top
        if (pos.y > 0 && maze[pos.y-1][pos.x] == '.' && !done[pos.y-1][pos.x]) {
            queue.add(Pos(pos.x, pos.y-1, newCost))
            done[pos.y-1][pos.x] = true
            maxCost = Math.max(maxCost, newCost)
        }
        // bottom
        if (pos.y < h-1 && maze[pos.y+1][pos.x] == '.' && !done[pos.y+1][pos.x]) {
            queue.add(Pos(pos.x, pos.y+1, newCost))
            done[pos.y+1][pos.x] = true
            maxCost = Math.max(maxCost, newCost)
        }
    }

    return maxCost
}

data class Pos(var x: Int, var y: Int, var cost: Int)

Measured memory_bytes: 42752
#include<iostream>
#include<string>
#include<iomanip>
#include<cmath>
#include<vector>
#include<algorithm>

using namespace std;

#define int long long
#define endl "\n"

const long long INF = (long long)1e18;
const long long MOD = 1'000'000'007; 

string yn(bool f){return f?"Yes":"No";}
string YN(bool f){return f?"YES":"NO";}



signed main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cout<<fixed<<setprecision(10);
	
	int H, W;
	int a, b, c, d;
	
	cin>>H>>W;
	
	if(W%3 == 0){
		a = 0;
	} else if(W%3 == 1){
		a = H;
	} else {
		a = H;
	}
	
	if(H%3 == 0){
		b = 0;
	} else if(H%3 == 1){
		b = W;
	} else {
		b = W;
	}
	
	if(W%3 == 1){
		if(H%2 == 0){
			int A, B, C;
			A = (W/3)*H;
			B = (W - W/3)*H/2;
			
			c = abs(A-B);
			
			A = (W/3 + 1)*H;
			B = (W - W/3 - 1)*H/2;
			
			c = min(abs(A-B),c);
			
		} else {
			int A, B, C;
			A = (W/3)*H;
			B = (W - W/3)*H/2;
			C = (W - W/3)*(H-H/2);
			c = max(max(A,B),C) - min(min(A,B),C);
			
			
			A = (W/3+1)*H;
			B = (W - W/3-1)*H/2;
			C = (W - W/3-1)*(H-H/2);
			
			c = min(max(max(A,B),C) - min(min(A,B),C),c);
		}
	} else if(W%3 == 2){
		if(H%2 == 0){
			int A, B, C;
			
			// A = H;
			// B = H/2;
			
			c = H/2;
			
		} else {
			int A, B, C;
			
			A = H * (W/3);
			B = (H/2) * (W-W/3);
			C = (H-H/2) * (W-W/3);
			
			c = max(max(A,B),C) - min(min(A,B),C);
			
			A = H * (W/3+1);
			B = (H/2) * (W-W/3-1);
			C = (H-H/2) * (W-W/3-1);
			
			c = min(max(max(A,B),C) - min(min(A,B),C),c);
			
			A = H * (W/3+2);
			B = (H/2) * (W-W/3-2);
			C = (H-H/2) * (W-W/3-2);
			
			c = min(max(max(A,B),C) - min(min(A,B),C),c);
		}
	}
	
	swap(H,W);
	
	if(W%3 == 1){
		if(H%2 == 0){
			int A, B, C;
			A = (W/3)*H;
			B = (W - W/3)*H/2;
			
			d = abs(A-B);
			
			A = (W/3 + 1)*H;
			B = (W - W/3 - 1)*H/2;
			
			d = min(abs(A-B),d);
			
		} else {
			int A, B, C;
			A = (W/3)*H;
			B = (W - W/3)*H/2;
			C = (W - W/3)*(H-H/2);
			d = max(max(A,B),C) - min(min(A,B),C);
			
			
			A = (W/3+1)*H;
			B = (W - W/3-1)*H/2;
			C = (W - W/3-1)*(H-H/2);
			
			d = min(max(max(A,B),C) - min(min(A,B),C),d);
		}
	} else if(W%3 == 2){
		if(H%2 == 0){
			int A, B, C;
			
			// A = H;
			// B = H/2;
			
			d = H/2;
			
		} else {
			int A, B, C;
			
			A = H * (W/3);
			B = (H/2) * (W-W/3);
			C = (H-H/2) * (W-W/3);
			
			d = max(max(A,B),C) - min(min(A,B),C);
			
			A = H * (W/3+1);
			B = (H/2) * (W-W/3-1);
			C = (H-H/2) * (W-W/3-1);
			
			d = min(max(max(A,B),C) - min(min(A,B),C),d);
			
			A = H * (W/3+2);
			B = (H/2) * (W-W/3-2);
			C = (H-H/2) * (W-W/3-2);
			
			d = min(max(max(A,B),C) - min(min(A,B),C),d);
		}
	}
	
	cout<<min(min(a,b),min(c,d))<<endl;
	
	return 0;
}

Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        try (Scanner in = new Scanner(System.in)) {
            solve(in);
        }
    }

    private static void solve(Scanner in) {
        // n m
        // p1 p2 ... pn
        while (true) {
            int n = in.nextInt(), m = in.nextInt();
            if (n == 0 && m == 0) {
                break;
            }
            int[] p = new int[n];
            for (int i = 0; i < n; i++) {
                p[i] = in.nextInt();
            }
            Arrays.sort(p);
            for (int i = 0; i < p.length / 2; i++) {
                int tmp = p[i];
                p[i] = p[p.length - 1 - i];
                p[p.length - 1 - i] = tmp;
            }
            int sum = 0;
            int i = 0;
            int j = 0;
            while (j < n) {
                if (i == m - 1) {
                    i = 0;
                } else {
                    i++;
                    sum += p[j];
                }
                j++;
            }
            System.out.println(sum);
        }
    }
}

Measured memory_bytes: 59572
typedef long long ll;
#include "bits/stdc++.h"
using namespace std;
int main() {
	int n;
	cin >> n;
	vector<int> v1(n);
	vector<int> v2(0);
	for (int i = 0; i < n; i++)
	{
		cin >> v1[i];
	}
	copy(v1.begin(), v1.end(), back_inserter(v2));
	sort(v2.rbegin(), v2.rend());
	int mx = v2[0];
	int cnt = 0;
	while (mx > 0)
	{
		int mode = 0;
		for (int j = 0; j < n; j++)
		{
			if (v1[j] == mx) {
				v1[j]--;
				if (mode == 0) {
					mode = 1;
				}
				else if(mode == 1){
					mode = 2; //continue
				}
			}
			else if (v1[j] != mx) {
				mode = 0;
			}

			if (mode == 1) cnt++;
		}
		mx--;
	}
	cout << cnt << endl;
}

Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main(void){
  string str;
  cin >> str;
  long count_all, count_w;
  count_all = count_w = 0;
  long score;
  score = 0;
  for ( string::iterator itr=str.begin(); itr != str.end(); ++itr){
    count_all++;
      if( *itr == 'W'){
      count_w++;
      score += (count_all - count_w);
    }
  }
  cout << score << endl;
  return 0;
}

Measured memory_bytes: 640
#include <stdio.h>

int main(void) {
	int a,b, c, i, cou = 0;
	scanf("%d%d%d", &a, &b, &c);
	for(i = a; b >= i; i++){
		if(c%i == 0) cou++;
	}
	printf("%d\n", cou);
	return 0;
}

Measured memory_bytes: 596
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <stdbool.h>
#define LL long long
#define DB double
#define PI 3.14159265358979
#define MOD 1000000007
#define ERR 0.00000000000001
#define NUM 200010

int main(){
    char a[4], b[]="ABC";
    scanf("%s",a);
    if(strcmp(a,b)==0){ printf("ARC"); }
    else{ printf("ABC"); }
    return 0;
}

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

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

    int n;
    cin >> n;
    map<string, int> mp;
    REP(i, n){
        string s;
        cin >> s;
        mp[s]++;
    }

    int m;
    cin >> m;
    REP(i, m){
        string t;
        cin >> t;
        mp[t]--;
    }

    int ans = 0;
    for(auto x : mp){
        ans = max(ans, x.second);
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int a[1010];

int main() {
    while(true) {
        int n; cin >> n;
        if(n == 0) break;
        for(int i=0; i<n; ++i) cin >> a[i];
        sort(a, a + n);
        int sum = 0;
        for(int i=1; i+1<n; ++i) sum += a[i];
        cout << sum / (n - 2) << '\n';
    }
}


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

template<class T> inline bool chmin(T &a, T b) {
  if(a>b) {
    a=b;
    return true;
  }
  return false;
}
template<class T> inline bool chmax(T &a, T b) {
  if(a<b){
    a=b;
    return true;
  }
  return false;
}
const ll LINF = 1LL << 60;
int dx[] = {0,1,0,-1};
int dy[] = {-1,0,1,0};

int main() {
  ll A, B, K; cin >> A >> B >> K;
  ll diff;
  if(A > K){
    cout << A-K << " " << B << endl;
  } else if(B > (K-A)){
    cout << 0 << " " << B-(K-A) << endl;
  } else {
    cout << 0 << " " << 0 << endl;
  }
}


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

int main()
{
    int a,b,c,r;
    cin>>a>>b;
    r=a+b;
    if(a%2==b%2){
             c=r/2;
    cout<<c<<endl;

    }
    else{
   cout<<"IMPOSSIBLE"<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize ("Ofast")
#pragma GCC target ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
 
 
#include <iostream>
#include <iomanip>
#include <sstream>
#include <cstring>
#include <vector>
#include <deque>
#include <queue>
#include <set>
#include <map>
#include <valarray>
#include <iterator>
#include <functional>
#include <limits>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <cassert>
#include <unordered_map>
#include <unordered_set>
#include <stack>
using namespace std;
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
 
typedef int64_t ll;
 #define trace(x) cerr << #x << ": " << x << " " << endl;

#define endl '\n'
#define int ll
ll mod=1e9+7;
ll mod1=1e9+5;
ll power(ll a,ll b)
{
    if(b==0) return 1;
    else if(b%2==0)
        return power((((a%mod)*(a%mod))%mod),b/2)%mod;
    else return ((a%mod)*(power((((a%mod)*(a%mod))%mod),b/2)%mod))%mod;
}


int32_t main()
{
    IOS
    
            
    int n;
    cin>>n;
    cout<<n*n*n;      
 
}

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

int main() {
  int n;
  string s;
  cin >> n >> s;
  int ans = 300000;
  vector<int>w(n);
  vector<int>e(n);
  for(int i = 0;i < n;i++){
    if(s.at(i) == 'W'){
      if(i == 0) w.at(i)++;
      else w.at(i) = w.at(i-1)+1;
      if(i != 0) e.at(i) = e.at(i-1);
    }
    else{
      if(i == 0) e.at(i)++;
      else e.at(i) = e.at(i-1)+1;
      if(i != 0) w.at(i) = w.at(i-1);
    }
  }
  for(int i = 0;i < n;i++){
    int j;
    if(i == 0) j = e.at(n-1)-e.at(i);
    else j = (e.at(n-1)-e.at(i))+(w.at(i-1));
    if(j < ans) ans = j;
  }
  cout << ans << endl;
}


Measured memory_bytes: 3076
#include <bits/stdc++.h>
using namespace std;
int main() {
  int a = 0 , l , N , r;
  cin >> N;
  for(int i = 0 ; i < N ; i++){
    cin >> l >> r;
    a += (r - l + 1);
  }
  cout << a << endl;
}

Measured memory_bytes: 3604
import java.util.Scanner;

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

        if(k > a) {
            k -= a;
            a = 0;
            if(k > b) b = 0;
            else b -= k;
        }
        else a -= k;

        System.out.println(a + " " + b);
    }
}


Measured memory_bytes: 21844
#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll n,c;
void dfs(ll d){
  ll d3=d*10+3,d5=d*10+5,d7=d*10+7;
  if(d3<=n){
    ll dd=d3;
    bool b3=false,b5=false,b7=false;
    while(dd!=0){
      if(dd%10==3) b3=true;
      else if(dd%10==5) b5=true;
      else if(dd%10==7) b7=true;
      dd/=10;
    }
    if(b3&&b5&&b7) c++;
    dfs(d3);
  }
  if(d5<=n){
    ll dd=d5;
    bool b3=false,b5=false,b7=false;
    while(dd!=0){
      if(dd%10==3) b3=true;
      else if(dd%10==5) b5=true;
      else if(dd%10==7) b7=true;
      dd/=10;
    }
    if(b3&&b5&&b7) c++;
    dfs(d5);
  }
  if(d7<=n){
    ll dd=d7;
    bool b3=false,b5=false,b7=false;
    while(dd!=0){
      if(dd%10==3) b3=true;
      else if(dd%10==5) b5=true;
      else if(dd%10==7) b7=true;
      dd/=10;
    }
    if(b3&&b5&&b7) c++;
    dfs(d7);
  }
}
int main(){
  cin>>n;
  c=0;
  dfs(0);
  cout<<c;
}

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

int cmp(string s){
	if(s.find("that",0)!=string::npos) return 1;
	if(s.find("the",0)!=string::npos) return 1;
	if(s.find("this",0)!=string::npos) return 1;
	return 0;
}

int main() {
	string s;
	while(getline(cin,s)){
		for(int h=0;h<26;h++){
			for(unsigned int i=0;i<s.length();i++){
					if(s[i]==0x2e||s[i]==0x20||s[i]==0x0a) continue;
					s[i]+=1;
					if((int)s[i]>0x7a) s[i]=0x61;
			}if(cmp(s)==1) break;
		} cout<<s<<endl;
	}return 0;
}

Measured memory_bytes: 1184