akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <cmath>
#include <algorithm>
#include <functional>
#include <stack>
#include <numeric>
typedef long long ll;
using namespace std;
const int MOD = (int)1e9 + 7;
const ll INF = (ll)1e18 + 7;
//#define int long long
#define all(vec) vec.begin(), vec.end()
#define dbg(x) cerr << #x << " = " << (x) << endl
#define yn(b) cout << ((b) ? "Yes" : "No") << endl
#define YN(b) cout << ((b) ? "YES" : "NO") << endl
#define isEven(t) t % 2 == 0

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

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

	string S;
	bool heisei = true;
	cin >> S;
	int tmp;
	tmp = (S[0] - '0') * 1000 + (S[1] - '0') * 100 + (S[2] - '0') * 10 + S[3] - '0';
	
	if(tmp>2019){
		cout << "TBD" << endl;
		return 0;
	}
	if(tmp<2019){
		cout << "Heisei" << endl;
		return 0;
	}
	tmp = (S[5] - '0') * 10 + S[6] - '0';
	if(tmp>4){
		cout << "TBD" << endl;
		return 0;
	}
	if(tmp<4){
		cout << "Heisei" << endl;
		return 0;
	}
	tmp = (S[8] - '0') * 10 + S[9] - '0';
	if(tmp>30){
		cout << "TBD" << endl;
		return 0;
	}
	if(tmp<=30){
		cout << "Heisei" << endl;
		return 0;
	}

	return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC098A
{
    class Program
    {
        private static int max, a, b;

        static void Main(string[] args)
        {
            int a, b, x;
            // 整数A,Bの入力
            var word = Console.ReadLine().Split(' ');

            a = int.Parse(word[0]);
            b = int.Parse(word[1]);

            //最大値xを求める
        
            x = a + b;

            if (x < a - b) x = a - b;
            if (x < a * b) x = a * b;

            Console.WriteLine(x);

            Console.ReadKey();
        }
    }
}


Measured memory_bytes: 11092
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
using System.Text.RegularExpressions;
using System.Globalization;
using System.Diagnostics;
using static System.Console;
//using System.Numerics;
//using static System.Math;

class Program
{
    static void Main()
    {
        //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
        new Program().solve();
        Out.Flush();
    }
    Scanner cin = new Scanner();
    readonly int[] dd = { 0, 1, 0, -1, 0 }; //→↓←↑
    readonly int mod = 1000000007;


    void solve()
    {
        var S = cin.next;
        int N = S.Length;

        if (N % 2 == 0)
        {
            int ok = N / 2;
            var basis = S[N / 2];
            for (int i = 0; i < N / 2; i++)
            {
                if (S[N / 2 + i] == S[N / 2 - i - 1] && basis == S[N / 2 - i - 1])
                {
                    ok++;
                }
                else
                {
                    WriteLine(ok);
                    return;
                }
            }
            WriteLine(ok);
        }
        else
        {
            int ok = N / 2 + 1;
            var basis = S[N / 2];
            for (int i = 0; i < N / 2; i++)
            {
                if (S[N / 2 + i + 1] == S[N / 2 - i - 1] && basis == S[N / 2 + i + 1])
                {
                    ok++;
                }
                else
                {
                    WriteLine(ok);
                    return;
                }
            }
            WriteLine(ok);
        }
    }

}

class Scanner
{
    string[] s; int i;
    char[] cs = new char[] { ' ' };
    public Scanner() { s = new string[0]; i = 0; }
    public string[] scan { get { return ReadLine().Split(); } }
    public int[] scanint { get { return Array.ConvertAll(scan, int.Parse); } }
    public long[] scanlong { get { return Array.ConvertAll(scan, long.Parse); } }
    public double[] scandouble { get { return Array.ConvertAll(scan, double.Parse); } }
    public string next
    {
        get
        {
            if (i < s.Length) return s[i++];
            string st = ReadLine();
            while (st == "") st = ReadLine();
            s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
            i = 0;
            return next;
        }
    }
    public int nextint { get { return int.Parse(next); } }
    public long nextlong { get { return long.Parse(next); } }
    public double nextdouble { get { return double.Parse(next); } }
}

Measured memory_bytes: 13236
#include<bits/stdc++.h>
using namespace std;
int main() {
	int a[4][4],b;
	cin>>a[1][1]>>a[1][2]>>a[2][2];
	b=a[2][2]*3;
	a[1][3]=b-a[1][1]-a[1][2];
	a[3][1]=b-a[1][3]-a[2][2];
	a[3][3]=b-a[1][1]-a[2][2];
	a[2][1]=b-a[1][1]-a[3][1];
	a[2][3]=b-a[2][1]-a[2][2];
	a[3][2]=b-a[1][2]-a[2][2];
	for(int i=1; i<=3; i++) {
		for(int j=1; j<=3; j++) {
			cout<<a[i][j]<<" ";
		}
		cout<<endl;
	}
}

Measured memory_bytes: 384
let readInt _ = stdin.ReadLine() |> int

Array.concat [

               [| 1 .. () |> readInt |]
               |> Array.map (fun _ -> (stdin.ReadLine(), 1))
               [| 1 .. () |> readInt |]
               |> Array.map (fun _ -> (stdin.ReadLine(), -1)) ]
|> Array.groupBy fst
|> Array.map (fun (_, arr) -> arr |> Array.sumBy snd)
|> Array.max
|> fun x -> if x < 0 then 0 else x
|> printfn "%d"


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

const char dest[]="CODEFESTIVAL2016";
char ch[200];

void solve()
{
    int ans=0;
    for(int i=0;ch[i];i++)
    {
        if(ch[i]!=dest[i])ans++;
    }
    printf("%d\n",ans);
}

int main()
{
    while(scanf("%s",ch)!=EOF)solve();
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <math.h>
#include <cassert>
#define rep(i,n) for(int i = 0; i < n; ++i )
using namespace std;
using ll = long long;
using P = pair<int,int>;

int main() {
  int a,b,c,d;
  cin >> a >> b >> c >> d;
  cout << min(a,b)+min(c,d) << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int x,y;
  cin >> x >> y;
  int k,t;
  int m=0;
  int n=0;
  for(int k=0; k<51; k++){
    for(int t=0; t<51; t++){
      m = 2*k+4*t;
      n = k+t;
      if(m == y && n ==x){
        cout << "Yes" << endl;
        return 0;
      }
    }
  }
  cout << "No" << endl;
}


Measured memory_bytes: 3572
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n) ;i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define sz(x) ((int)(x).size())
using ll=long long;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define MOD  1000000007
const ll INF=1e18;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b){ a = b; return 1; } return 0; }



int main(int argc, char const *argv[]) {
  int n;
  cin >> n;
  vector<ll> a(n);
  rep(i,n) cin >> a[i];
  ll res=a[0];
  for(int i=1; i<n; i++){
    res=res^a[i];
  }
  if(res==0) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <set>
#include <vector>
#include <algorithm>
#include <bitset>
#define ll long long
using namespace std;

int main(){

 //    https://atcoder.jp/contests/abc105/tasks/abc105_d

  // 累積和とって　同じmodでコンビネーション //全てのMODを取る必要性はなく配列ないでの初見MODを逐次処理すれば良い（処理し終わったらvec.eraseで消していく　この際にcnt++ しといてのちに組み合わせ計算をし　ans+=cnt ですね　もちcnt=0に初期化　ほいでvectorがなくなったら終わり）
// 便宜上累積和配列に０突っ込んどく


ll N;ll M;cin>>N>>M;
//vector <int> box(M);
vector <ll> A(0);
A.push_back(0);
for(ll i = 0; i < N; i++)
{
  ll a;cin>>a;
  A.push_back(a%M);
}

ll ans =0;

//累積和
for(ll i=0;i<A.size();i++){
 
  if(i==0) {}//continue;
  else {A[i]=A[i] + A[i-1];A[i]=A[i]%M;}
 /// cout<<A[i]<<" ";
}
//cout<<endl;
sort(A.begin(),A.end());
ll cnt =0;
for(ll i=0;i<A.size();i++){
  if(i==0) {
    cnt++;
    continue;
  }

  if(A[i] != A[i-1]){
    ans += cnt*(cnt-1)/2;
    cnt=0;
    cnt++;
    continue;
  }

  if(i==A.size()-1) {
    cnt++;
    ans += cnt*(cnt-1)/2;
  }

  cnt++;


}


/*
for(ll i=0;i<A.size();i++){
  ll index = A[i];
  box[index] = box[index] +1;
}

for(ll i=0;i<M;i++){
  ll cnt = box[i];
  ans += cnt*(cnt-1)/2;
}
*/


// バケット法に書き換える

 



cout<<ans<<endl;


return 0;
}


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



int main() {

  int h,w;
  cin>>h>>w;
  int v[10][10];
//  int V[10][10];
  rep(i,10)rep(j,10)v[i][j]=INF;
  rep(i,10)rep(j,10)cin>>v[i][j];
  rep(i,10)rep(j,10)rep(k,10){
    v[j][k]=min(v[j][k],v[j][i]+v[i][k]);
  //cout<<v[i][j]<<'i'<<i<<'j'<<j<<'k'<<k<<endl;
  }
  int ans=0;
  rep(i,h)rep(j,w){
    int a1;cin>>a1;
    if (a1==-1)continue;
    ans+=v[a1][1];
  //  cout<<i<<' '<<j<<' '<<ans<<endl;
  }

cout<<ans;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
typedef long long ll;
using namespace std;
void solve()
{
	ll x;
	cin>>x;
	ll ben=100;
	int cnt=0;
	for (;;)
	{
		if (ben>=x)
			break;
		ben*=(1.01);
		cnt++;
	}
	cout<<cnt<<endl;
}
int main() 
{
	ios::sync_with_stdio(false);
	solve();
	return 0;
}

Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
#define fi first
#define se second
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define pf push_front
#define eb emplace_back
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define SZ(x) (int)(x).size()
#define ft front()
#define bk back()
#define endl '\n'
#define FOR(a, b, c) for (auto(a) = (b); (a) < (c); ++(a))
#define ROF(a, b, c) for (auto(a) = (b); (a) > (c); --(a))
#define F0R(a, b) FOR ((a), 0, (b))
#define R0F(a, b) ROF ((a), (b), -1)
#define CEIL(a, b) ((a) + (b)-1) / (b)
#define SET(a, b) memset((a), (b), sizeof(a))
template <class t>
bool ckmin(t& a, const t& b) {
    return a > b ? a = b, true : false;
}
template <class t>
bool ckmax(t& a, const t& b) {
    return a < b ? a = b, true : false;
}
#ifndef DEBUG
#define DEBUG 0
#endif
#define dout \
    if (DEBUG) std::cerr
#define dvar(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
template <class a, class b>
ostream& operator<<(ostream& o, const pair<a, b>& p);
template <class T>
struct IsC {
    template <class C>
    static char test(typename C::const_iterator*);
    template <class C>
    static int test(...);
    static const bool value = sizeof(test<T>(0)) == sizeof(char);
};
template <>
struct IsC<string> {
    static const bool value = false;
};
template <class C>
typename enable_if<IsC<C>::value, ostream&>::type operator<<(ostream& o,
                                                             const C& c) {
    o << '[';
    for (auto it = c.begin(); it != c.end();)
        o << *it << (++it != c.end() ? ", " : "");
    return o << ']';
}
template <class a, class b>
ostream& operator<<(ostream& o, const pair<a, b>& p) {
    return o << '(' << p.fi << ", " << p.se << ')';
}

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

    int n, m;
    cin >> n >> m;
    vvi adj_out(n), adj_in(n);
    vi out(n);
    F0R (i, m) {
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        adj_out[a].pb(b);
        adj_in[b].pb(a);
        ++out[a];
    }
    queue<int> q;
    F0R (i, n)
        if (!out[i]) q.push(i);

    vi toposort;

    while (!q.empty()) {
        int v = q.ft;
        toposort.pb(v);
        q.pop();
        for (int u : adj_in[v])
            if (0 == --out[u]) q.push(u);
    }
    dout << dvar(toposort) << endl;
    vi dp(n);
    for (int i : toposort) {
        for (int u : adj_out[i]) ckmax(dp[i], 1 + dp[u]);
    }
    dout << dvar(dp) << endl;
    cout << *max_element(ALL(dp)) << endl;
    return 0;
}


Measured memory_bytes: 12540
#include<bits/stdc++.h>
using namespace std;
#define first ff
#define second ss
#define ll long long int
int main()
{
    string s,t;
    cin>>s>>t;
    ll match=0,not_match=0;
    for(int i=0;i<s.size();i++){
      if(s[i]!=t[i]) not_match++;


    }

       cout<<not_match;


}


Measured memory_bytes: 3896
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <sstream>
#include <set>
#include <map>
#include <vector>
#include <list>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <stack>
#include <queue>
#include <bitset>     //UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic
#include <cassert>
#include <iomanip>        //do setprecision
#include <ctime>
#include <complex>
using namespace std;

#define FOR(i,b,e) for(int i=(b);i<(e);++i)
#define FORQ(i,b,e) for(int i=(b);i<=(e);++i)
#define FORD(i,b,e) for(int i=(b)-1;i>=(e);--i)
#define REP(x, n) for(int x = 0; x < (n); ++x)

#define ST first
#define ND second
#define PB push_back
#define PF push_front
#define MP make_pair
#define LL long long
#define ULL unsigned LL
#define LD long double
#define pii pair<int,int>
#define pll pair<LL,LL>
#define vi vector<int>
#define vii vector<vi>

const double pi = 3.14159265358979323846264;
const int mod=1000000007;

int main(){
	int k;
    int x;
    cin>>k>>x;
    if(500*k>=x){
        cout<<"Yes";
    }else{
        cout<<"No";
    }

}


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <utility>
#include <cstdio>
#include <iomanip>
#include <cmath>
#include <string>
#include <stack>
#include <queue>
#include <map>
#include <stdlib.h>
#include <set>
typedef long long ll;
using namespace std;

int main() {
	string s1,s2;
	cin>>s1>>s2;
	if(s1.substr(0,1)==s2.substr(2,1)&&s1.substr(1,1)==s2.substr(1,1)&&s1.substr(2,1)==s2.substr(0,1)){
		cout<<"YES"<<endl;
	}else{
		cout<<"NO"<<endl;
	}

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
typedef long long ll;
#define ALL(v) v.begin(), v.end()
#define vmax(v) *max_element(ALL(v))
#define vmin(v) *min_element(ALL(v))
#define chmax(x, a) x = max(x, a)
#define chmin(x, a) x = min(x, a)

int main() {
    ll N; cin >> N;
    vector<ll> A(N);
    vector<int> cnt(1e6+1);
    for (ll i = 0; i < N; i++) {
        cin >> A[i];
        cnt[A[i]]++;
    }
    if (N == 1) {
        cout << 1 << endl;
        return 0;
    }
    sort(ALL(A));
    if (A[0] == A[N-1]) {
        cout << 0 << endl;
        return 0;
    }
    vector<ll> ans = {A[0]};
    int d = 0;
    if (cnt[A[0]] > 1) d++;
    for (ll i = 1; i < N; i++) {
        bool flag = true;
        ll j = 1;
        while (flag && j*j <= A[i] && j <= ans[ans.size()-1]) {
            if (A[i]%j) j++;
            else {
                if (binary_search(ALL(ans), j) || binary_search(ALL(ans), A[i]/j)) {
                    flag = false;
                    break;
                }
                j++;
            }
        }
        if (flag) {
            ans.push_back(A[i]);
            if (cnt[A[i]] > 1) d++;
        }
    }
    cout << ans.size() - d << endl;
}


Measured memory_bytes: 10644
#include <iostream>
#include <algorithm>
#include <set>
#include <map>

using namespace std;

int N;
long long int T;
long long int A[100005];

int  COUNT(long long int k) {
	int ret = 0;
	for (int i = 1; i <= N; i++) {
		if (A[i] == k) { ret++; }
	}
	return ret;
}

long long int M[100005], m[100005];

set<pair<long long int, long long int> > S;

map<long long int, int> C;

int main(void) {

	cin >> N >> T;

	long long int tmp;
	for (int i = 1; i <= N; i++) {
		cin >> tmp; A[i] = tmp;
	}

	M[N] = A[N];
	for (int i = N-1; i >= 1; i--) {
		M[i] = max(M[i + 1], A[i]);
	}

	m[1] = A[1];
	for (int i = 2; i <= N; i++) {
		m[i] = min(m[i - 1], A[i]);
	}

	long long int SUB = -1;

	for (int i = 1; i <= N; i++) {
		SUB = max(SUB, M[i] - m[i]);
	}

	for (int i = 1; i <= N; i++) {
		if (M[i] - m[i] == SUB) { S.insert(pair<long long int, long long int>(M[i], m[i])); }
	}

	for (int i = 1; i <= N; i++) {
		C[A[i]]++;
	}

	long long int ans = 0;
	for (auto it = S.begin(); it != S.end(); it++) {
		long long int a = (*it).first; 
		long long int b = (*it).second;
		ans += min(C[a], C[b]);
	}
	cout << ans << endl;
	//system("pause");
	return 0;
}

Measured memory_bytes: 11904
def get_input_row():
  return [int(i) for i in input().split(" ")]
     
inp = get_input_row()
N = inp[0]
M = inp[1]
item_dict = {}
num = 0
for i in range(N):
  a, b = get_input_row()
  if a in item_dict:
    item_dict[a] += b
  else:
    item_dict[a] = b

sorted_list = [k for k in item_dict.keys()]
sorted_list.sort()
money = 0
for price in sorted_list:
  if M > item_dict[price]:
    M -= item_dict[price]
    money += price * item_dict[price]
  else:
    money += price * M
    break
print(money)

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

int main() {
  int K,N;
  cin >> K >> N;
  vector<int> A(N);
  int sum = 0,gap=0;
  rep(i,N) cin >> A.at(i);
  sort(A.begin(),A.end());
  rep(i,N){
    if(i==N-1){
      int di = A.at(0)+K-A.at(i);
      sum += di;
      gap=max(gap,di);
    }
    else{
      int di = A.at(i+1)-A.at(i);
      sum += di;
      gap=max(gap,di);
    }
  }
  cout << sum-gap << endl;
  return 0;
}

Measured memory_bytes: 1024
#include<stdio.h>
#define ll long long 
int main(){
    int n,k=1;
    scanf("%d",&n);
    ll a[n+1],b[n+1];
    for(int i=1;i<=n;i++)
        scanf("%lld",&a[i]);
    ll c[n];
    for(int i=1;i<n-1;i+=2){
        c[k]=a[i]-a[i+1];
        k++;
    }
    c[k]=a[n];
    ll sum=0;
    for(int i=1;i<=k;i++)
        sum+=c[i];
    b[1]=sum;
    for(int i=1;i<=n;i++){
        if(i!=n)
            b[i+1]=a[i]-b[i]+a[i];
        else
            b[n]=a[n]-b[1]+a[n];
    }
    for(int i=1;i<=n;i++)
        printf("%lld ",b[i]);
    printf("\n");
    return 0;
}

Measured memory_bytes: 3200
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a,N;
  string result  = "APPROVED";
  cin >> N;
  for(int i =0;i <= N;i++){
  	cin >> a;
    if(a % 2 == 0){
    	if(a % 3 == 0 | a % 5 == 0){
        }else{
        	result = "DENIED";
        }
    }
  }
  cout << result << endl;
}

Measured memory_bytes: 256
use std::io;

fn main() {
    let mut line = String::new();
    io::stdin().read_line(&mut line).unwrap();
    let iter = line.split_whitespace();
    let vec: Vec<i32> = iter
        .map(|word| word.to_string().parse::<i32>().unwrap())
        .collect();
    let w = vec[0];
    let h = vec[1];
    let x = vec[2];
    let y = vec[3];
    let r = vec[4];
    let mut ans = if r <= y && y <= (h - r) { "Yes" } else { "No" };
    ans = if r <= x && x <= (w - r) && ans == "Yes" {
        "Yes"
    } else {
        "No"
    };

    println!("{}", ans);
}



Measured memory_bytes: 1052
import java.util.*;
public class Main {
	static Scanner in = new Scanner(System.in);
	public static void main(String[] args) {
		while(true){
			int N = in.nextInt();
			int A = in.nextInt();
			int B = in.nextInt();
			int C = in.nextInt();
			int X = in.nextInt();
			int[] Y = new int[N];
			if(N == A && A == B && B == C && C == X && X == 0) break;
			for(int i = 0; i < N; i++){
				Y[i] = in.nextInt();
			}
			int cnt = 0;
			int idx = 0;
			while(true){
				if(X == Y[idx]){
					idx++;
				}
				if(Y.length == idx) break;
				X = (A * X + B) % C;
				cnt++;
				if(cnt > 10000){
					cnt = -1;
					break;
				}
			}
			System.out.println(cnt);
		}
	}

}

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

using namespace std;

#define int long long

int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int a, b;
    cin >> a >> b;
    for (int i = 0; i < 1000000; ++i)
    {
        int t = i / 10;
        int y = i * 8 / 100;
        if (t == b && y == a)
        {
            cout << i << endl;
            return 0;
        }
    }
    cout << -1 << endl;
    return 0;
}


Measured memory_bytes: 256
n = gets.chomp.to_i
a = gets.chomp.split.map(&:to_i)

count = Hash.new(0)
a.each do |elem|
  count[elem] += 1
end

sum = 0
count.each_value do |v|
  sum += (v*(v-1)) / 2
end

a.each do |e|
  v_e = count[e]
  if v_e == 1
    p sum
    next
  end
  p sum - (v_e*(v_e-1)/2 - (v_e-1)*(v_e-2)/2)
end


Measured memory_bytes: 39044
#include <iostream>
#include <vector>
#include <algorithm> // sort
#include <map> // pair
#include <numeric> // accumulate(begin,end,初期値)
#include <string>
#include <cstdio>
#include <queue>
#include <stack>
#include <set>
#include <cmath>

typedef long long ll;
using namespace std;

#define FALSE printf("false\n");
#define TRUE printf("true\n");
#define all(x) (x).begin(),(x).end()
#define print(x) cout<<x<<endl
#define rep(i,n) for(int i = 0;i < ((int)(n));++i)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define SUM(vec) accumulate(all(vec),0)
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define test(a) cout<<#a<<':'<<a<<endl

const ll INF = 1e9+7;

// 各桁の和
template<typename T>inline T digit(T num){T sum = 0;while(num){sum+=num%10;num/=10;}return sum;}
template<typename T>inline T gcd(T a,T b){if(b == 0)return a;return gcd(b,a%b);}
template<typename T>inline T lcm(T a, T b){T g = gcd(a,b);return a/g*b;}
template<typename T>inline T power(T a,T b){T tmp=1;rep(i,b){tmp*=a;}return tmp;}


class tree{
public:
  tree* par;
  vector<tree*> chi;
  int cnt;
};

int cnt(int a,int b){
  int count = -1;
  while(a){
    a /= b;
    ++count;
  }
  return count;
}


int main() {
  cin.tie(0); ios::sync_with_stdio(0);
  string s;cin>>s;
  string key = "keyence";
  vector<string> tmp(1,"");
  
  bool ans = false;
  rep(i,8){
    string str = s.substr(0,7-i) + s.substr(s.size() - i,s.size());
    ans |= str == key;
  }
  string put;
  if(ans) put = "YES"; else put = "NO";
  print(put);
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n, k;
    cin >> n >> k;
    using ll = long long;
    vector<ll> h(n);
    for(int i = 0; i < n; i++)
    {
        cin >> h[i];
    }
    sort(h.begin(), h.end());

    ll ans = 10000000009;
    for(int i = 0; i < n-k+1 ; i++)
    {
        ans = min(ans, h[i+k-1] - h[i]);
    }
    cout << ans << endl;
}



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

ll vac(ll i,ll j,vector<vector<ll>> &dp,vector<vector<ll>> &v,ll n)
{
  if(i>=n)
    return 0;
  if(dp[i][j]!=-1)
    return dp[i][j];
  ll l,r;
  l=v[i][j]+vac(i+1,(j+1)%3,dp,v,n);
  r=v[i][j]+vac(i+1,(j+2)%3,dp,v,n);
  dp[i][j]=max(l,r);
  return dp[i][j];
}

int main()
{
  ll n,i,j,tmp;
  cin>>n;
  vector<vector<ll>> v(n,vector<ll>(3,0));
  for(i=0;i<n;i++)
  {
    for(j=0;j<3;j++)
    {
        cin>>tmp;
        v[i][j]=tmp;
    }
  }
  ll a,b,c;
  vector<vector<ll>> dp(n,vector<ll>(3,-1));
  a=vac(0,0,dp,v,n);
  vector<vector<ll>> dp2(n,vector<ll>(3,-1));
  b=vac(0,1,dp2,v,n);
  vector<vector<ll>> dp3(n,vector<ll>(3,-1));
  c=vac(0,2,dp3,v,n);
  cout<<max(a,max(b,c))<<"\n";
  return 0;
}

Measured memory_bytes: 34400
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <unordered_set>
#include <unordered_map>
#include <numeric>
#include <ctime>
#include <bitset>
#include <complex>
#include <random>

using namespace std;

const int INF = 1e9 + 239;

int n, m;
vector<vector<int>> a;
vector<vector<int>> dp;

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

	cin >> n >> m;
	a.resize(n, vector<int> (m));
	dp.resize(n, vector<int> (m, INF));
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < m; j++) {
			char c;
			cin >> c;
			a[i][j] = (c == '#');
		}
	}
	dp[0][0] = a[0][0];
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < m; j++) {
			if (i + 1 < n) {
				int w = 0;
				if (a[i][j] == 0 && a[i + 1][j] == 1) w = 1;
				dp[i + 1][j] = min(dp[i + 1][j], dp[i][j] + w); 
			}
			if (j + 1 < m) {
				int w = 0;
				if (a[i][j] == 0 && a[i][j + 1] == 1) w = 1;
				dp[i][j + 1] = min(dp[i][j + 1], dp[i][j] + w);
			}
		}
	}
	cout << dp[n - 1][m - 1] << endl;
} 

Measured memory_bytes: 384
#include <math.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(void) {
  int i, j, k;
  long X;
  long A, B;
  long a, b;
  long ans = 0;
  scanf("%ld", &X);
  for (j = 0; j < 1000; j++) {
    A = j * j * j * j * j;
    for (i = 0; i < 1000; i++) {
      B = i * i * i * i * i;
      if ((A - B) == X) {
        printf("%d %d", j ,i);
        return 0;
      }
      B *= (-1);
      if ((A - B) == X) {
        printf("%d %d", j, i * (-1));
        return 0;
      }
    }
    A *= (-1);
    for (i = 0; i < 1000; i++) {
      B = i * i * i * i * i;
      if ((A - B) == X) {
        printf("%d %d", j*(-1), i);
        return 0;
      }
      B *= (-1);
      if ((A - B) == X) {
        printf("%d %d", j*(-1), i * (-1));
        return 0;
      }
    }
  }
  return 0;
}


Measured memory_bytes: 2124
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
typedef vector<ll> vl;
typedef vector<vector<ll> > vvl;
#define REP(var, a, b) for (int var = (a); var < (b); var++)
#define rep(var, n) for (int var = 0; var < (n); ++var)
#define ALL(c) (c).begin(), (c).end()
#define rALL(c) (c).rbegin(), (c).rend()
ll MOD = 1000000007;

int main() {
  //
  ll a, b;
  cin >> a >> b;
  if ((a - b) & 1) {
    cout << "IMPOSSIBLE" << endl;
  } else {
    cout << abs(a - b) / 2 + min(a, b) << endl;
  }
  return 0;
}


Measured memory_bytes: 888
#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;

/*int min(int a, int b) {
	if (a < b) return a;
	else return b;
}

int gcd(int x, int y) {
	int d = min(x, y);
	for (int i = d; i > 0; i--) {
		if (x % i == 0 && y % i == 0) {
			cout << i << endl;
			return i;
		}
	}
}*/

int gcd(int x, int y){
    if(x < y) swap(x, y);
    while(y > 0){
        int r = x % y;
        x = y;
        y = r;
    }
    cout << x << endl;
    return x;
}

int main() {
	int x, y;
	cin >> x >> y;
	gcd(x, y);

	return 0;
}


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

int main() {
  int A, B, C, K;
  cin >> A >> B >> C >> K;
  
  int n = 0;
  if (A < B && B < C) {
    cout << "Yes" << endl;
  } 
  else if (A < B) {
    while (B >= C) {
      C *= 2;
      n++;
    }
    if (n > K) {
      cout << "No" << endl;
    }
    else {
      cout << "Yes" << endl;
    }
  }
  else {
    while (A >= B) {
      B *= 2;
      n++;
    }
    while (B >= C) {
      C *= 2;
      n++;
    }
    if (n > K) {
      cout << "No" << endl;
    }
    else {
      cout << "Yes" << endl;
    }
  }
}

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

int N, t;
vector<int> A;

int main(){
    cin >> N;
    REP(i,N){
        cin >> t;
        A.push_back(t);
    }

    int c = 0;
    int flag = 1;
    while(flag){
        flag = 0;
        for(int j = N-1; j >= 1; j--){
            if(A[j] < A[j-1]){
                swap(A[j],A[j-1]);
                c++;
                flag = 1;
            }
        }
    }

    REP(i,N-1) cout << A[i] << " "; cout << A[N-1] << endl;
    cout << c << endl;
    return 0;
}

Measured memory_bytes: 3116
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define REP(a,b) for(int a=0;a<(b);++a)
#define REP1(i,n) for(int i=1;i<=(n);++i)
#define debug(x) cerr<<#x<<": "<<x<<'\n'
#define all(x) (x).begin(),(x).end()
#define YES() printf("YES\n")
#define NO() printf("NO\n")
#define isYES(x) printf("%s\n",(x) ? "YES" : "NO")
#define Yes() printf("Yes\n")
#define No() printf("No\n")
#define isYes(x) printf("%s\n",(x) ? "Yes" : "No")
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair
#define INF (1<<29)
#define Sp(p) cout<<setprecision(25)<< fixed<<p<<endl
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
#define X first
#define Y second
#define pie 3.14159265358979323846
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;


template<class T=int>
T in(){T x;cin>>x;return (x);}
template<class T>
void print(T& x){cout<<x<<'\n';}

const int MOD =(int)1e9+7;
const int mod =(int)1e9+7;
const int MAX =510000;
ll fac[MAX],finv[MAX],inv[MAX];
void COMint(){
    fac[0]=fac[1]=1;
    finv[0]=finv[1]=1;
    inv[1]=1;
    for(int i=2;i<MAX;i++){
        fac[i]=fac[i-1]*i%MOD;
        inv[i]=MOD-inv[MOD%i]*(MOD/i)%MOD;
        finv[i]=finv[i-1]*inv[i]%MOD;
    }
}
ll COM(int n,int k){
    if(n<k) return 0;
    if(n<0||k<0)return 0;
    return fac[n]*(finv[k]*finv[n-k]%MOD)%MOD;
}
ll gcd(ll a,ll b){
    if(b==0)return a;
    if(a>b){
        swap(a,b);
    }
    return gcd(a,b%a);
}
ll lcm(ll a,ll b){
    ll g;g=gcd(a,b);
    return a*b/g;
}
bool compare_by_b(pair<int, int> a, pair<int, int> b) {
    if(a.second != b.second){
        return a.second < b.second;
    }else{
        return a.first < b.first;
    }
}

bool compare_by_a(pair<int, int> a, pair<int, int> b) {
    if(a.first != b.first){
        return a.first < b.first;
    }else{
        return a.second < b.second;
    }
}
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;
}

ll RS(ll N,ll P,ll M){
    if(P==0){
        return 1;
    }else{
        if(P%2==0){
            ll t=RS(N,P/2,M);
            return t*t%M;
        }else{
            return N*RS(N,P-1,M)%M;
        }
    }
}
bool greater_pair(pair<ll,ll> a,pair<ll,ll> b){
    if(a.first!=b.first){
        return a.first>b.first;
    }else{
        return a.second>b.second;
    }
}
int main() {
    ios::sync_with_stdio(false);
    int X=in();
    int Y=in();
    Y/=2;
    cout<<X+Y<<endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    static int gcd(int x, int y) {
        if (x < y) {
            int t = x;
            x = y;
            y = t;
        }

        if (x % y == 0) {
            return y;
        }

        return gcd(x % y, y);
    }

    public static void main(String[] args) {
        Scanner std = new Scanner(System.in);
        int n = std.nextInt();
        int x = std.nextInt();
        int[] xs = new int[n];
        for (int i = 0; i < n; i++) {
            xs[i] = Math.abs(std.nextInt() - x);
        }
        int ans = 1;
        for (int i = 0; i < n; i++) {
            if (xs[i] == 0) {
                continue;
            }
            if (ans == 1) {
                ans = xs[i];
            } else {
                ans = gcd(xs[i], ans);
            }
        }

        System.out.println(ans);
    }
}


Measured memory_bytes: 47800
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <typeinfo>
#include <numeric>
#include <functional>
#include <unordered_map>
#include <bitset>
#include <stack>
#include <assert.h>
#include <unordered_set>
#include <random>


using namespace std;
using ll = long long;
using ull = unsigned long long;

const ll INF = 1e18;
const ll MOD = 1e9 + 7;

#define REP(i, n) for(ll i = 0; i < n; i++)

















int main(){
    ll x, y, z;
    cin >> x >> y >> z;
    swap(x, y);
    swap(x, z);
    cout << x << " " << y << " " << z << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){    
	long long a,b;
	cin>>a>>b;
    if(a>0)cout<<"Positive"<<endl;
    else if(a==0||(a<0&&b>0))cout<<"Zero"<<endl;
    else if((abs(b)-abs(a))%2!=0)cout<<"Positive"<<endl;
    else cout<<"Negative"<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<math.h>
#include<algorithm>
#include<string>
#include<vector>
#include<map>
#include<unordered_map>
#include<set>
#include<unordered_set>
#include<stack>
#include<climits>
using namespace std;
#define ll long long int
#define gc getchar_unlocked
#define fo(i,n) for(i=0; i<n; i++)
#define Fo(i,k,n) for(i=k; k<n?i<n:i>n; k<n?i+=1:i-=1)
#define deb(x) cout << #x << "=" << x <<"\n"
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y <<"\n"
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define sortall(x) sort(x.begin(), x.end())
#define clr(x) memset(x, 0, sizeof(x))
#define tr(it,a) for(auto it = a.begin; it != a.end; it++)
#define PI 3.1415926535897932384626
typedef vector<ll> vl;
typedef map<ll, ll> ml;
typedef pair<ll, ll> pl;
typedef vector<pl> vpl;
typedef vector<vl> vvl;
int main() {
	ios_base::sync_with_stdio(false); cin.tie(NULL);   
    int X;
    cin>>X;
    if(X>=400 && X<=599)
        cout<<"8";
    else if(X>=600 && X<=799)
        cout<<"7";
    else if(X>=800 && X<=999)
        cout<<"6";
    else if(X>=1000 && X<=1199)
        cout<<"5";
    else if(X>=1200 && X<=1399)
        cout<<"4";
    else if(X>=1400 && X<=1599)
        cout<<"3";
    else if(X>=1600 && X<=1799)
        cout<<"2";
    else if(X>=1800 && X<=1999)
        cout<<"1";

	return 0;
}




Measured memory_bytes: 3648
#include <stdio.h>

int main() {
	int r, D;
	int xs = 0;
	int i;
	int total;
	int year;

	scanf("%d %d %d", &r, &D,&xs);
	year = xs;

	for (i = 1; i <= 10; i++) {
		total = (r*year) - D;
		printf("%d\n", total);
		year = total;

	}
	return 0;

}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <numeric>
#include <cstdint>
#include <iomanip>
using ll = long long;
#define fast_io(); std::ios_base::sync_with_stdio(0); std::cin.tie(0); std::cout.tie(0);

int main(){
    fast_io();

    int N, K; std::cin >> N >> K;
    std::vector<int> A;
    for(int i=0; i<N; i++){
        int b; std::cin >> b; A.push_back(b);
    }

    for(int k=0; k<K; k++){
        std::vector<int> B(N,0);
        for(int i=0; i<N; i++){
            int l=std::max(0,i-A[i]), r=std::min(N-1,i+A[i]);
            B[l]++;
            if(r+1<N) B[r+1]--;
        }
        for(int i=1; i<N; i++) B[i] += B[i-1];
        if(A == B){
            break;
        }else{
            A = B;
        }
    }

    for(int i=0; i<N; i++){
        std::cout << A[i] << " ";
    }
    return 0;
}


Measured memory_bytes: 4804
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <fstream>
#include <sstream>
#include <math.h>
#include <queue>
#include <stack>
#include <math.h>

using namespace std;


void print_array(int h, int w, bool array[111][111]){
    for(int i=1; i<=h; i++){
        for(int j=1; j<=w; j++){
            cout<<array[i][j];
        }cout<<endl;
    }cout<<endl;
}


bool property_distribution(int orchard[111][111], bool cheack_flag[111][111], int now_h, int now_w, int fluit_num){
    if(orchard[now_h][now_w]!=fluit_num)return 0;
    else{
        if(cheack_flag[now_h][now_w]==1)return 1;
        else {
            cheack_flag[now_h][now_w]=1;
            return
            property_distribution(orchard, cheack_flag, now_h+1, now_w, fluit_num)+
            property_distribution(orchard, cheack_flag, now_h-1, now_w, fluit_num)+
            property_distribution(orchard, cheack_flag, now_h, now_w+1, fluit_num)+
            property_distribution(orchard, cheack_flag, now_h, now_w-1, fluit_num);
        }
    }
    
}


int main(){
    //入力作業
    int H,W;
    while(cin>>H>>W){
        if(!H&&!W)break;
        
        int orchard[111][111]={0};
        
        for(int i=1; i<=H; i++){
            for(int j=1; j<=W; j++){
                char input;
                cin>>input;
                if(input=='#'){
                    orchard[i][j]=1;
                }else if(input=='*'){
                    orchard[i][j]=2;
                }else if(input=='@'){
                    orchard[i][j]=3;
                }
            }
        }
        
        
        //入力終了
        //処理開始
        bool cheack_flag[111][111]={0};
        int ans=0;
        for(int i=1; i<=H; i++){
            for(int j=1; j<=W; j++){
                if(cheack_flag[i][j]==0&&orchard[i][j]!=0){
                    property_distribution(orchard, cheack_flag, i, j, orchard[i][j]);
                    ans++;
                    
                    /////
                    //print_array(10, 10, cheack_flag);
                    /////
                }
            }
        }
        cout<<ans<<endl;
    }

}

Measured memory_bytes: 1848
#include <iostream>
using namespace std;
int main(int argc, char* argv[])
{
	int A,B,C,K;
	cin>>A>>B>>C;
	cin>>K;
	while (K>0){
		if (A>=B){
			B*=2;
			K--;
			continue;
		}
		C*=2;
		K--;
	}
	if (A<B && B<C){
		cout<<"Yes"<<endl;
	}else{
		cout<<"No"<<endl;
	}
	return 0;
}

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

map<long, long> prime_factor(long N) {
  map<long, long> res;
  for (long i = 2; i * i <= N; i++) {
    while (N % i == 0) {
      res[i]++;
      N /= i;
    }
  }
  if (N != 1) {
    res[N] = 1;
  }
  return res;
}

int main() {

  long long N;
  cin >> N;

  map<long, long> mp = prime_factor(N);

  long long ans = 0;

  for (auto x : mp) {
    long long count = 1;
    long long v = x.second;
    bool flg = true;
    while (flg) {
      v -= count;
      if (v < count + 1) {
        ans += count;
        flg = false;
      }
      count++;
    }
  }

  cout << ans << endl;

}

Measured memory_bytes: 3600
/*实现栈的功能*/
#include<iostream>
#include<cstdio>
using namespace std;

// 实现栈的功能

// top是指向栈顶的指针， s是实现栈结构的数组
int top, S[1000];

// 将x压入栈的操作
void push(int x) {
    // top加1之后将元素插入到top所指的位置
    S[++top] = x;
}

// 将栈顶元素返回并删除
int pop() {
    top--;
    return S[top + 1];
}

// 字符转数字
int CharToInt(char s[]) {
    int ans = 0, i = 0;
    while (s[i] != '\0') {
        ans = ans * 10 + s[i] - '0';
        i++;
    }
    return ans;
}
int main() {
    char s[1000];
    int a, b;
    // 清空栈
    top = 0; 
    while(scanf("%s",s)!=EOF){
            if (s[0] == '+') {
                b = pop();a = pop();
                push(a + b);
            }else if (s[0] == '-') {
                b = pop(); a = pop();
                push(a - b);
            }else if (s[0] == '*') {
                b = pop(); a = pop();
                push(a * b);
            }else {
                push(CharToInt(s));
            }
    }
    printf("%d\n",pop());

    return 0;
}


Measured memory_bytes: 3204
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.Scanner;
public class Main {
    public static void main(String[] args){

    Scanner sc = new Scanner(System.in);
        String S = sc.next();
        char[]ss = S.toCharArray();
        ArrayList<Integer>ans  = new ArrayList<>();

        int cou = 0;
        for(int i=0; i<S.length(); i++) {
        if(ss[i]=='A' || ss[i]=='C' || ss[i]=='G' || ss[i]=='T') {
        	cou++;
        }else {
        	ans.add(cou);
                cou = 0;
        }
        }
        if(ans.size() == 0) {
        	System.out.println(Math.max(cou,0));
        }else {
            Collections.sort(ans, Comparator.reverseOrder());
            System.out.println(Math.max(cou,ans.get(0)));
        }
    }
}



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

int main(){
  int n;
  cin >> n;
  using vt = vector<tuple<string, int, int>>;
  using vvt = vector<vt>;
  vt p(n);
  
  string a;
  int b;
  rep(i, n) {
    cin >> a >> b;
    p.at(i) = make_tuple(a, b*-1, i+1);
  }
  sort(p.begin(), p.end());

  rep(i, n) {
    cout << get<2>(p.at(i))  << endl;
  }
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
#define repeat(i,n) for (int i = 0; i < (n); ++i)
#define MAX_W 10
#define MAX_D 10
int main() {
    while (true) {
        int W, D; cin >> W >> D;
        if (W == 0 or D == 0) break;
        static int HW[MAX_W], HD[MAX_D];
        repeat (w,W) cin >> HW[w];
        repeat (d,D) cin >> HD[d];
        sort(HW,HW+W);
        sort(HD,HD+D);
        int result = 0;
        {
            int w = 0, d = 0;
            while (w < W and d < D) {
                if (HW[w] < HD[d]) {
                    result += HW[w]; ++ w;
                } else if (HW[w] > HD[d]) {
                    result += HD[d]; ++ d;
                } else {
                    result += HW[w]; ++ w; ++ d;
                }
            }
            while (w < W) { result += HW[w]; ++ w; }
            while (d < D) { result += HD[d]; ++ d; }
        }
        cout << result << endl;
    }
    return 0;
}

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

#define F first
#define S second
#define MP make_pair
#define pb push_back
#define all(a) a.begin(), a.end()
#define lcm(a, b) (a)/__gcd((a),(b))*(b)
#define CEIL(a, b) (a)/(b)+(((a)%(b))?1:0)
#define endl '\n'

using namespace std;

typedef long long LL;
typedef pair<int, int> P;
typedef pair<LL, LL> LP;

static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1000000007;
static const int SIZE = 200005;

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

vector<int> Div(int n) {
    vector<int> ret;
    for(int i = 1; i * i <= n; ++i) {
        if(n % i == 0) {
            ret.pb(i);

            if(i * i != n) ret.pb(n / i);
        }
    }
    sort(all(ret));
    return ret;
}

bool bfs();

int mp[55][55];
int dist[55][55];
int h, w;

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

    cin >> h >> w;
    for(int i = 1; i <= h; ++i) {
        for(int j = 1; j <= w; ++j) {
            char c;
            cin >> c;
            if(c == '.') mp[i][j] = 1;

        }
    }

    bool f = bfs();
    if(!f) {
        cout << -1 << endl;
        return 0;

    }

    set<int> st;
    int c = 0;
    for(int i = 1; i <= h; ++i) {
        for(int j = 1; j <= w; ++j) {
            if(mp[i][j] == 0) continue;

            if(dist[h][w] < dist[i][j]) {
                ++c;

            } else {
                int s = st.size();
                st.insert(dist[i][j]);
                if(s == st.size()) {
                    ++c;
                }
            }
        }
    }
    cout << c << endl;
    return 0;
}

bool bfs() {
    queue<pair<P, int>> q;
    q.push(MP(MP(1, 1), 0));

    for(int i = 1; i <= h; ++i) {
        for(int j = 1; j <= w; ++j) {
            dist[i][j] = INF;

        }
    }

    dist[1][1] = 0;
    while(!q.empty()) {
        pair<P, int> p = q.front();
        q.pop();

        for(int i = 0; i < 4; ++i) {
            int xx, yy;
            yy = p.F.F + dy[i];
            xx = p.F.S + dx[i];
            if(mp[yy][xx] == 0) {
                continue;

            }
            
            if(dist[p.F.F][p.F.S] + 1 < dist[yy][xx]) {
                dist[yy][xx] = dist[p.F.F][p.F.S] + 1;
                q.push(MP(MP(yy, xx), dist[yy][xx]));

            }
        }
    }

    if(dist[h][w] == INF) return false;
    return true;
}


Measured memory_bytes: 256
import sys
stdin = sys.stdin
sys.setrecursionlimit(10**9)
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

a,b,m = na()

aa = na()
bb = na()

ans = min(aa)+min(bb)

for i in range(m):
    x,y,c = na()
    ans = min(ans,aa[x-1]+bb[y-1]-c)

print(ans)

Measured memory_bytes: 18616
n, q = [int(x) for x in input().split()]

s = input()

arr = [0 for _ in range(len(s)+1)]

for i in range(len(s)-1):
	if s[i] == 'A' and s[i+1] == 'C':
		arr[i+2] += 1

for i in range(1, len(arr)):
	arr[i] = arr[i-1] + arr[i]

for _ in range(q):
	a, b = [int(x) for x in input().split()]
	print(str(arr[b]-arr[a]))

Measured memory_bytes: 7692
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define repr(i, n) REPR(i, n, 0)
#define REPR(i, s, e) for(int i=(int)(s-1); i>=(int)(e); i--)
#define pb push_back
#define all(r) r.begin(),r.end()
#define rall(r) r.rbegin(),r.rend()
#define fi first
#define se second

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

const ll INF = 1e9;
const ll MOD = 1e9 + 7;
double EPS = 1e-8;

template<typename T> T chmax(T& a, const T& b){return a = (a > b ? a : b);}
template<typename T> T chmin(T& a, const T& b){return a = (a < b ? a : b);}

int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    vector<vector<int>> x(n), y(n);
    rep(i, n) {
        cin >> a[i];
        x[i].resize(a[i]);
        y[i].resize(a[i]);
        rep(j, a[i]) {
            cin >> x[i][j] >> y[i][j];
            x[i][j]--;
        }
    }
    int ans = 0;
    rep(mask, 1<<n) {
        bool f = true;
        rep(i, n) {
            rep(j, a[i]) {
                bool a = mask&(1<<i);
                bool b = mask&(1<<x[i][j]);
                bool c = y[i][j];
                if(!a) continue;
                f &= ((a^b)^c);
            }
        }
        if(f) chmax(ans, __builtin_popcount(mask));
    }
    cout << ans << endl;
    return 0;
}

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


int main(){
  int n, m;
  cin >> n >> m;
  
  if(n==1){
    cout << m << endl;
    return 0;
  }
  
  for(int div = (int)m/n; div > 0; div--){
    if(m % div == 0){
      cout << div << endl;
      return 0;
    }
  }
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
	int n,debt = 100000;
	cin >>n;
	for(int i=0; i<n; i++){
		debt *=1.05;
		int k = debt/1000*1000;
		if(debt != k){debt = k+1000;}
	}
	cout <<debt<<endl;
	return 0;
}

Measured memory_bytes: 0