akhauriyash/Code-Regression huggingface dataset:
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int, int> pi;
#define debug(x) cerr << #x << ": " << x << endl
#define debug2(x, y) debug(x), debug(y)
#define repn(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define rep(i, a) for(int i = 0; i < (int)(a); i++)
#define all(v) v.begin(), v.end() 
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define sq(x) ((x) * (x))

template<class T> T gcd(T a, T b){ return ((b == 0) ? a : gcd(b, a % b)); }

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	//freopen("input.in", "r", stdin);
	//freopen("output.out", "w", stdout);
	ll lon, squ, tri, lle, lri, zri, zle;
	cin >> lon >> squ >> tri >> lle >> lri >> zri >> zle;
	ll tot1 = squ * 2;
	tot1 += 4 * (lle / 2);
	tot1 += 4 * (lri / 2);
	tot1 += (lon / 2) * 4;
	if((lon & 1) && (lle & 1) && (lri & 1)) tot1 += 6;
	ll tot2 = squ * 2;
	if(lon && lle && lri) tot2 += 6, lon--, lle--, lri--;
	tot2 += 4 * (lle / 2);
	tot2 += 4 * (lri / 2);
	tot2 += (lon / 2) * 4;
	ll tot = squ * 2;
	ll mn = min({lon, lle, lri});
	tot += mn * 6;
	lon -= mn;
	lri -= mn;
	lle -= mn;
	tot += (lon / 2) * 4;
	tot += (lle / 2) * 4;
	tot += (lri / 2) * 4;
	cout << max({tot1 / 2, tot / 2, tot2 / 2}) << endl;
	return 0;
}
/*
Things to look out for:
	- Integer overflows
	- Array bounds
	- Special cases
Be careful!
*/


Measured memory_bytes: 3640
a = list(map(int, input().split()))
for i in range(a[0]+1):
    for j in range(a[0]-i+1):
        b = 10000*i + 5000*j + 1000*(a[0]-(i+j))
        if b == a[1]:
            print(i, end=" ")
            print(j, end=" ")
            print(a[0]-(i+j))
            exit()
print(-1, end=" ")
print(-1, end=" ")
print(-1)

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

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    
    int N; string S; int Q;
    cin >> N >> S >> Q;
    
    unordered_map<char, set<int>> mp;
    for (int i = 0; i < S.size(); ++i) {
        mp[S[i]].insert(i);    
    }
    
    while (Q--) {
        int q; cin >> q;
        switch(q) {
            case 1:
                int i; char c; cin >> i >> c; --i;
                mp[S[i]].erase(i);
                S[i] = c;
                mp[c].insert(i);
                break;
            case 2:
                int b, e; cin >> b >> e; b--, e--;
                int cnt = 0;
                for (char k = 'a'; k <= 'z'; ++k) {
                    if (mp.find(k) != mp.end()) {
                        const set<int>& st = mp[k];
                        auto it1 = st.lower_bound(b);
                        if (it1 != st.end() && *it1 <= e) cnt++;
                    }
                }
                cout << cnt << endl;
                break;
        }
    }
}


Measured memory_bytes: 24376
//author: Harsh :)
#include <bits/stdc++.h>
using ll = long long;
using ld = long double;
#define F first
#define S second
const ll mod = 1e9 + 7;
const ll INF = 922337203685477;
#define pb push_back
#define deb(x) cout << '>' << #x << ':' << x << endl;
#define fastio ios_base::sync_with_stdio(false); cin.tie(0);
#define maxN 100007
using namespace std;
int main(){
  fastio;
  ll n=0;
  cin>>n;
  map<ll,ll>mp;
  ll ar[n];
  ll sum=0;
  for(ll i=0;i<n;++i){
    cin>>ar[i];
    mp[ar[i]]++;
    sum+=ar[i];
  }
  ll q=0;
  cin>>q;
  while(q--){
    ll x=0,y=0;
    cin>>x>>y;
    ll c = mp[x];
    mp[x] = 0;
    mp[y] += c;
    sum-= x*c;
    sum+= y*c;
    cout<<sum<<"\n";
  }
  return 0;

}


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

using ll = long long;
using Vi = vector<int>;
using Vl = vector<ll>;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

constexpr int I_INF = numeric_limits<int>::max();
constexpr ll L_INF = numeric_limits<ll>::max();

//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

void solve() {
    // 入力
    int D;
    cin >> D;
    int c[26];
    for (ll i = 0; i < 26; i++) {
        cin >> c[i];
    }
    int s[365][26];
    for (ll i = 0; i < D; i++) {
        for (ll j = 0; j < 26; j++) {
            cin >> s[i][j];
        }
    }
    int t[365];
    for (ll i = 0; i < D; i++) {
        cin >> t[i];
        --t[i];
    }

    set<int> used[26];  // コンテストが行われた日を格納
    for (ll i = 0; i < 26; i++) {
        // 番兵
        used[i].emplace(-1);
        used[i].emplace(D);
    }
    for (ll i = 0; i < D; i++) {
        used[t[i]].emplace(i);
    }

    // 得点計算
    int last[26] = {};
    int ans = 0;
    for (ll i = 0; i < D; i++) {
        ans += s[i][t[i]];
        last[t[i]] = i + 1;
        for (ll j = 0; j < 26; j++) {
            ans -= c[j] * (i + 1 - last[j]);
        }
    }

    int M;
    cin >> M;
    while (M--) {
        int d, q;
        cin >> d >> q;
        --d, --q;
        auto itr1 = used[t[d]].find(d);            // 前
        auto itr2 = prev(used[q].lower_bound(d));  // 後
        int pre1 = *prev(itr1);
        int nxt1 = *next(itr1);
        int pre2 = *itr2;
        int nxt2 = *next(itr2);

        ans += s[d][q] - s[d][t[d]];
        ans -= c[t[d]] * (d - pre1) * (nxt1 - d);
        ans += c[q] * (d - pre2) * (nxt2 - d);

        used[t[d]].erase(itr1);
        used[q].emplace(d);
        t[d] = q;

        cout << ans << "\n";
    }
}

//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

int main() {
#ifdef FASTIO
    cin.tie(0), cout.tie(0);
    ios::sync_with_stdio(false);
#endif
#ifdef FILEINPUT
    ifstream ifs("./in_out/input.txt");
    cin.rdbuf(ifs.rdbuf());
#endif
#ifdef FILEOUTPUT
    ofstream ofs("./in_out/output.txt");
    cout.rdbuf(ofs.rdbuf());
#endif
    solve();
    cout << flush;
    return 0;
}

Measured memory_bytes: 3616
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
class Main{
  public static void main(String[] args) throws IOException {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    int n = Integer.parseInt(br.readLine());
    System.out.println(n >= 30 ? "Yes" : "No");
  }
}

Measured memory_bytes: 32508
#include<algorithm>
#include<vector>
#include<list>
#include<iostream>
#include<utility>
#include<string>
#include<set>
#include<queue>
#include<stack>
#include<iterator>
#include<map>
#include<limits>
#include<iomanip>
#include<ctime>
#include<cmath>
 
const int INF=2147483647;
const long long MOD=1e9+7;
 
using namespace std;




int main(){
    
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    
    int a,b,c;
    cin>>a>>b>>c;
    if(c>=a && c<=b) cout<<"Yes";
    else cout<<"No";
   
    
    
    
    return 0;
    
    
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n, cnt = 0;
		n = sc.nextInt();
		char[] key;
		char[][] word = new char[n][];
		key = sc.next().toCharArray();
		for (int i = 0; i < n; i++) {
			word[i] = sc.next().toCharArray();
Word:		for(int k = 0;k < word[i].length;k++){
				//System.out.println("1??????????????¢?????????");
				//System.out.println( key[0] +" " +word[i][k]);
				for(int l = k+1;l < word[i].length;l++){
					if(key[0] != word[i][k])break;
					//System.out.println("2??????????????¢?????????");
					//System.out.println( key[1] +" " +word[i][l]);
					for(int m = l + (l-k);m < word[i].length;m += (l-k)){
						if(key[1] != word[i][l])break;
						//System.out.println(((m-k)/(l-k))+"??????????????¢?????????");
						//System.out.println(l-k);
						//System.out.println( i +" "+ (m));
						//System.out.println( key[(m-k)/(l-k)] +" "/*+word[i][m]*/);
						if(key[(m-k)/(l-k)] != word[i][m])break;
						if((m-k)/(l-k) == key.length-1){
							cnt++;
							//System.out.println( "number " + i);
							break Word;
						}
					}
				}
			}
		}
		System.out.println(cnt);
	}
}

Measured memory_bytes: 27484
import sys
def Prime(x):
  for i in range(2, x):
    if(x%i==0):
      return False
  return True

if (__name__=='__main__'):
  X = int(input())
  i = 0
  while True:
    if Prime(X+i):
      print(X+i)
      sys.exit()
    i += 1

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

int main(){
	long long int K, A, B;
	cin >> K >> A >> B;
	
	long long int ans=K+1, tmp=0;

	if(K<A || B-A<=2)	ans =  K+1;
	
	else{
		if((K-(A-1))%2==0){
			tmp = A+(B-A)*((K-(A-1))/2);
		}
		else{
			//tmp = A+(B-A)*((K-(A-1))/2)+1;		//解答見てから変えたもの
			//tmp = A+(B-A)*(((K-1)-(A-1))/2)+1;	//自分の最終的な解答
			tmp = A + (B-A)*((K-(A-1))/2) + 1;		//ぷに
		}
		ans = max(ans,tmp);
	}
	
	cout << ans << endl;
	
	return 0;
}


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

int n;

int main(){
	int max,m,n,money,H,y,tanri,hukuri,tesuu,okane,risi;
	double ritu;
	cin >> m;
	for(int i=0;i<m;i++){
		cin >> money;
		cin >> y;
		cin >> n;
		max=0;
		for(int j=0;j<n;j++){
			risi=0;
			okane=money;
			cin >> H >> ritu >> tesuu;
			if(H==0){ //tanri
				for(int k=0;k<y;k++){
					risi+=okane*ritu;
					okane-=tesuu;
				}
				okane+=risi;
			} else { // hukuri
				for(int k=0;k<y;k++){
					risi=okane*ritu;
					okane+=risi;
					okane-=tesuu;
				}
			}
			if(max<=okane){
				max=okane;
			}
		}
		cout << max << endl;
	}

	return 0;
}

Measured memory_bytes: 1232
def divisor(n):
    cnt = 0
    for i in range(1, n + 1):
        if n % i == 0:
           cnt += 1
        
    return cnt

n = int(input())

ans = 0
for i in range(1, n + 1, 2):
    if divisor(i) == 8:
        ans += 1
        
print(ans)

Measured memory_bytes: 9208
import java.io.*;
public class Main{
    public static void main(String[] args) throws IOException{
        BufferedReader bf = 
            new BufferedReader(new InputStreamReader(System.in));
        String color = bf.readLine();
        int num1 = 0,
            num2 = 0;
        for(int i = 0; i < color.length(); i++){
            if(i%2 ==  Character.getNumericValue(color.charAt(i))){
                num1++;
            }
            else{
                num2++;
            }
        }
        System.out.println(Math.min(num1, num2));
    }
}

Measured memory_bytes: 24020
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <map>

using namespace std;

int N,K;

int main(){
	cin>>N>>K;
	int d[K+1],A[K+1][N+1];
	int su[N+1];
	int sum=0;
	for(int i=1;i<=N;i++){
		su[i]=1;
	}

	for(int i=1;i<=K;i++){
		cin>>d[i];
		for(int j=1;j<=d[i];j++){
			cin>>A[i][j];
		}
	}
	for(int i=1;i<=K;i++){
		for(int j=1;j<=d[i];j++){
			su[A[i][j]]=0;
		}
	}
	for(int i=1;i<=N;i++){
		sum+=su[i];
	}
	cout<<sum<<endl;

}




Measured memory_bytes: 3636
#define _CRT_SECURE_NO_WARNINGS

#include <stdio.h>
#include <algorithm>
#include <iostream>
#include <map>
#include <set>
#include <bitset>
#include <string>
#include <vector>
#include <queue>
#include <functional>
#include <math.h>
#include <string.h>

using std::endl;
using std::string;

#define ll long long int
#define LEP(a, n) for(ll a = 0; a < n; ++a)
#define INF 123456789012345
#define OUT std::cout
#define IN std::cin
#define itn int
#define fro for
#define sdt std

ll H, W;
ll data[1234][1234];

ll counter;
string str[1234567];
int main()
{
	IN >> H >> W;

	LEP(a, H)
	{
		LEP(b, W)
		{
			IN >> data[a][b];
		}
	}


	LEP(a, H)
	{
		if (a % 2 == 0)
		{
			// 左から右
			LEP(b, W - 1)
			{
				if (data[a][b] % 2 != 0)
				{
					data[a][b + 1]++;
					str[counter] = std::to_string(a + 1) + " " + std::to_string(b + 1) + " " + std::to_string(a + 1) + " " + std::to_string(b + 1 + 1);
					counter++;
				}
			}
			if (a < H - 1 && data[a][W - 1] % 2 != 0)
			{
				data[a + 1][W - 1]++;
				str[counter] = std::to_string(a + 1) + " " + std::to_string(W - 1 + 1) + " " + std::to_string(a + 1 + 1) + " " + std::to_string(W - 1 + 1);
				counter++;
			}
		}
		else
		{
			// 右から左
			for(int b = W - 1; 0 < b; --b)
			{
				if (data[a][b] % 2 != 0)
				{
					data[a][b - 1]++;
					str[counter] = std::to_string(a + 1) + " " + std::to_string(b + 1) + " " + std::to_string(a + 1) + " " + std::to_string(b - 1 + 1);
					counter++;
				}
			}
			if (a < H - 1 && data[a][0] % 2 != 0)
			{
				data[a + 1][0]++;
				str[counter] = std::to_string(a + 1) + " " + std::to_string(0 + 1) + " " + std::to_string(a + 1 + 1) + " " + std::to_string(0 + 1);
				counter++;
			}
		}
	}

	OUT << counter << endl;
	for (int a = 0; a < counter; ++a)
	{
		OUT << str[a] << endl;
	}

	return 0;
}

Measured memory_bytes: 26240
package main

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

func main() {
	sc := NewScanner()

	k := sc.ReadInt()

	q := make([]int64, 9, 400000)
	for i := range q {
		q[i] = int64(i + 1)
	}

	cnt := 0
	for {
		n := q[0]
		cnt++
		if cnt >= k {
			fmt.Println(n)
			return
		}
		q = q[1:]

		base := n * 10
		mostRight := n % 10
		if mostRight > 0 {
			q = append(q, base+mostRight-1)
		}
		{
			q = append(q, base+mostRight)
		}
		if mostRight < 9 {
			q = append(q, base+mostRight+1)
		}
	}
}

// util
// *   intmath

func Abs(x int) int {
	if x >= 0 {
		return x
	}
	return -x
}

func Min(values ...int) int {
	if len(values) == 0 {
		panic("no values")
	}
	min := values[0]
	for _, v := range values {
		if v < min {
			min = v
		}
	}
	return min
}

func Max(values ...int) int {
	if len(values) == 0 {
		panic("no values")
	}
	max := values[0]
	for _, v := range values {
		if v > max {
			max = v
		}
	}
	return max
}

func Pow(base int, exponent uint) int {
	answer := 1
	for i := uint(0); i < exponent; i++ {
		answer *= base
	}
	return answer
}

func Abs64(x int64) int64 {
	if x >= 0 {
		return x
	}
	return -x
}

func Min64(values ...int64) int64 {
	if len(values) == 0 {
		panic("no values")
	}
	min := values[0]
	for _, v := range values {
		if v < min {
			min = v
		}
	}
	return min
}

func Max64(values ...int64) int64 {
	if len(values) == 0 {
		panic("no values")
	}
	max := values[0]
	for _, v := range values {
		if v > max {
			max = v
		}
	}
	return max
}

func Pow64(base int64, exponent uint) int64 {
	answer := int64(1)
	for i := uint(0); i < exponent; i++ {
		answer *= base
	}
	return answer
}

// *   io

type Scanner struct {
	bufScanner *bufio.Scanner
}

func NewScanner() *Scanner {
	bufSc := bufio.NewScanner(os.Stdin)
	bufSc.Split(bufio.ScanWords)
	return &Scanner{bufSc}
}

func (sc *Scanner) ReadString() string {
	bufSc := sc.bufScanner
	bufSc.Scan()
	return bufSc.Text()
}

func (sc *Scanner) ReadInt() int {
	bufSc := sc.bufScanner
	bufSc.Scan()
	text := bufSc.Text()

	num, err := strconv.Atoi(text)
	if err != nil {
		panic(err)
	}
	return num
}


Measured memory_bytes: 4352
#D幅優先探索
from collections import deque
h, w = list(map(int,input().split()))

def bfs(que,c):
    while que:
        c += 1
        qq = que
        que = deque([])
        while qq:
            x, y = qq.popleft()
            field[x][y] = "#"
            for i in range(4):
                nx = x + dx[i]
                ny = y + dy[i]
        
                if 0 <= nx <= h-1 and 0 <= ny <= w-1 and field[nx][ny] == ".":
                    if (nx,ny) not in que:
                        que.append((nx,ny))
            
    return c-1
            
A = [list(input()) for _ in range(h)]



dx = [1,0,-1,0]
dy = [0,1,0,-1]
que = deque([]) 
ans = []

for p in range(h):
    for q in range(w):
        if A[p][q] == ".":
            field = [k[:] for k in A]
            
            que.append((p,q))
            ans.append(bfs(que,0))
print(max(ans))

Measured memory_bytes: 45660
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
 int n,m;
 cin >> n >> m;
 vector<int> a(n+2);
 for(int i=0;i<m;i++){
  int l,r;
  cin >> l >> r;
  r++;
  a[l]+=1;
  a[r]-=1;
 }
 for(int i=1;i<n+2;i++){
  a[i]+=a[i-1];
 }
 int ans=0;
 for(int i=1;i<n+2;i++){
  if(a[i]==m) ans++;
 }
 cout<<ans<<endl;
 return 0;
}

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

int n, m, a, b;

int main() {
  cin >> n >> m;
  vector<int> h(n);
  vector<vector<int>> connection(n);
  rep (i, n) {
    cin >> h[i];
  }
  rep (i, m) {
    cin >> a >> b;
    connection.at(a-1).push_back(b-1);
    connection.at(b-1).push_back(a-1);
  }
  int ans = 0;
  rep (i, n) {
    bool max_height = true;
    rep (j, connection.at(i).size()) {
      if (h[connection.at(i).at(j)] >= h.at(i)) {
        max_height = false;
      }
    }
    if (max_height) ans++;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 8724
#pragma region
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <map>
#include <queue>
#include <stack>
#include <set>
#include <list>
#include <iomanip>
#include <cstdint>
#include <cstdlib>

using namespace std;
typedef long long ll;
//#define rep(i, s, e) for (int(i) = (s); (i) < (e); ++(i))
#define rep(i, e) for (int(i) = 0; (i) < (e); ++(i))
#define rrep(i, s) for (int(i) = (s) - 1; (i) >= 0; --(i))
#define all(x) x.begin(),x.end()
#pragma endregion


int main()
{
	int x, y, a, b, c; cin >> x >> y >> a >> b >> c;
	vector<ll> p(a), q(b), r(c);
	rep(i, a)cin >> p[i];
	rep(i, b)cin >> q[i];
	rep(i, c)cin >> r[i];
	sort(all(p), greater<ll>());
	sort(all(q), greater<ll>());
	sort(all(r), greater<ll>());
	ll res = 0;
	priority_queue<ll, vector<ll>, greater<ll> > que;
	rep(i, x)
	{
		res += p[i];
		que.push(p[i]);
	}
	rep(i, y)
	{
		res += q[i];
		que.push(q[i]);
	}
	rep(i, c)
	{
		if (que.empty())break;
		ll x = que.top();
		if (x < r[i])
		{
			que.pop();
			que.push(r[i]);
			res -= x;
			res += r[i];
		}
		else break;
	}
	cout << res << endl;
}

Measured memory_bytes: 4724
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        
        int n = Integer.parseInt(sc.next());
        Map<Integer, Integer> map = new HashMap<>();
        int a = 0;
        for(int i=0; i<n; i++) {
            a =Integer.parseInt(sc.next());
            if(map.containsKey(a)) map.put(a, map.get(a)+1);
            else map.put(a, 1);
        }
        
        if(map.size() % 2 == 0) {
            System.out.println(map.size()-1);
        }else {
            System.out.println(map.size());
        }
        
     }
}

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

template<class T>
class SqrtDecomposition {
private:
    int N, K;
    const int cap = 512;
    vector<T> data, bucket;
public:
    SqrtDecomposition(int n);
    void add(int x, T y);
    T query(int x, int y);
};

template<class T>
inline SqrtDecomposition<T>::SqrtDecomposition(int n) : N(n) {
    K = (N + cap - 1) / cap;
    data.assign(K * cap, 0);
    bucket.assign(K, 0);
}

template<class T>
inline void SqrtDecomposition<T>::add(int x, T y) {
    int k = x / cap;
    data[x] += y;
    bucket[k] = 0;
    for(int i = k * cap; i < (k + 1) * cap; ++i) {
        bucket[k] += data[i];
    }
}

template<class T>
inline T SqrtDecomposition<T>::query(int x, int y) {
    T sum = 0;
    for(int k = 0; k < K; ++k) {
        int l = k * cap, r = (k + 1) * cap;
        if(r <= x || y <= l) continue;
        if(x <= l && r <= y) {
            sum += bucket[k];
        } else {
            for(int i = max(x, l); i < min(y, r); ++i) {
                sum += data[i];
            }
        }
    }
    return sum;
}

void solve() {
    int N, Q;
    cin >> N >> Q;
    SqrtDecomposition<int> sq(N);
    while(Q--) {
        int c, x, y;
        cin >> c >> x >> y;
        if(c) cout << sq.query(x, y + 1) << '\n';
        else sq.add(x, y);
    }
}

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



Measured memory_bytes: 3356
#include<bits/stdc++.h>
using namespace std;
#define gc getchar_unlocked
#define fo(i,n) for(int i=0;i<n;i++)
#define ll long long
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, sizeof(x))
#define sortall(x) sort(all(x))
#define PI 3.1415926535897932384626
typedef map<ll, ll>    mp;
typedef pair<int, int>    pii;
typedef vector<ll>        vi;
typedef vector<pii>        vpii;
typedef vector<vi>        vvi;

int main() {
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
int m = 1000000007;
	int n;
	cin >> n;
	vi a(n);
	fo(i, n)cin >> a[i];
ll sum=0,sum1=0;
//vi temp;
for(int i=0;i<n;i++){
	sum1 +=a[i];
	sum1%=m;
}

for(int i=0;i<a.size();i++){
sum1-=a[i];
   if (sum1 < 0) sum1 += m;
sum+=a[i]*sum1;
sum%=m;
}
cout<<sum<<endl;
return 0;
}

Measured memory_bytes: 4768
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>

using namespace std;
typedef pair<int, int> P;

void solve()
{
	int N;
	cin >> N;
	vector<int> L(2 * N);
	for (int i = 0; i < 2 * N; ++i)
	{
		cin >> L[i];
	}
	sort(L.begin(), L.end());
	int ans = 0;
	for (int i = 0; i < 2 * N; i += 2)
	{
		ans += L[i];
	}
	cout << ans << endl;
}

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

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

using namespace std;

string X[] = { "dream","dreamer","erase","eraser" };
string S;

bool check( int j ) {
	if( j == S.size() ) {
		return true;
	}
	for( size_t i = 0; i < 4; i++ ) {
		if( S.substr( j, X[i].size() ) == X[i] && check( j + X[i].size() ) ) {
			return true;
		}
	}
	return false;
}

int main() {
	cin >> S;
	cout << (check( 0 ) ? "YES" : "NO") << endl;
}

Measured memory_bytes: 3072
#include <iostream>
#include <string>
#include <vector>
#include <stdio.h>
#include <algorithm>
#define _USE_MATH_DEFINES
#include <cmath>
#include <numeric>
#include <iomanip>
#include <deque>
#include <tuple>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <cstdint>
#include <unordered_map>
#include <sstream>
#include <boost/multiprecision/cpp_int.hpp>

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define pb push_back
#define pf push_front

namespace mp = boost::multiprecision;
using cpp_int = mp::cpp_int;
using ll = long long;
using namespace std;
	
ll M = 1000000007;

typedef pair<int, int> P;

bool ps1(const P &element1, const P &element2)
{ //first昇順
	return element1.first < element2.first;
}
bool ps2(const P &element1, const P &element2)
{ //first降順
	return element1.first > element2.first;
}
bool ps3(const P &element1, const P &element2)
{ //second昇順
	return element1.second < element2.second;
}
bool ps4(const P &element1, const P &element2)
{ //second降順
	return element1.second > element2.second;
}
int digits(int n)
{
	int count = 0;
	while (n > 0)
	{
		n /= 10;
		count++;
	}
	return count;
}
ll combination(ll n, ll r)
{
	if (r * 2 > n)
		r = n - r;
	ll dividend = 1;
	ll divisor = 1;
	for (ll i = 1; i <= r; ++i)
	{
		dividend *= (n - i + 1);
		divisor *= i;
	}
	return dividend / divisor;
}
int GCD(int x, int y)
{
	return x ? GCD(y % x, x) : y;
}
vector<int> divisor(int n)
{
	vector<int> value;
	FOR(i, 1, pow(n, 0.5) + 1)
	{
		if (i <= sqrt(n))
		{
			if (n % i == 0)
			{
				value.push_back(i);
				if (i * i != n)
				{
					value.push_back(n / i);
				}
			}
		}
	}
	return value;
}
int main()
{
	string s;
	cin>>s;
	string ri="CODEFESTIVAL2016";
	int n=16;
	int cnt=0;
	rep(i,n){
		if(s[i]!=ri[i]){
			cnt++;
		}
	}
	cout<<cnt<<endl;
}

Measured memory_bytes: 256
#include<map>
#include<iostream>
#include<deque>
#include<algorithm>
#include<string>
#include<cctype>
#include<iomanip>
#include<vector>
#include<queue>
#include<math.h>
#include<bitset>
#include<random>
 
using namespace std;
#define REP(i,b,e) for(ll i=(ll)b;i<(ll)e;i++)
#define rep0(i,n) REP(i,0ll,n)
#define rep1(i,n) REP(i,1ll,n+1)
 
#define shosu setprecision(17)
 
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<char,P> Q;
//ll longinf=1ll<<60;
int inf=1<<29;
ll longinf=(1ll<<60);

string maximum(string s,string t){
      if(s.size()>t.size()) return s;
      else if(t.size()>s.size()) return t;
      else{
            if(s>=t) return s;
            else return t;
      }
}

int main(){
      cin.tie(0);
      ios::sync_with_stdio(false);
      ll a,b;
      ll q;
      cin>>a>>b>>q;
      ll s[a+2],t[b+2],x[q];
      rep1(i,a) cin>>s[i];
      rep1(j,b) cin>>t[j];
      rep0(k,q) cin>>x[k];
      s[a+1]=longinf;
      t[b+1]=longinf;
      s[0]=-longinf;
      t[0]=-longinf;
      sort(s,s+a+2);
      sort(t,t+b+2);
      rep0(k,q){
            int zin=lower_bound(s,s+a+2,x[k])-s;
            int tr=lower_bound(t,t+b+2,x[k])-t;
            zin--,tr--;
            //cout<<s[zin]<<" "<<t[tr]<<" "<<x[k]<<endl;
            ll ans=longinf;
            ll migi=max(s[zin+1],t[tr+1])-x[k];
            ll hdr=x[k]-min(s[zin],t[tr]);
            ll mghd=min(s[zin+1]-x[k],x[k]-t[tr])+(s[zin+1]-t[tr]);
            ll hdmg=min(t[tr+1]-x[k],x[k]-s[zin])+(t[tr+1]-s[zin]);
            ans=min({migi,hdr,hdmg,mghd});
            cout<<ans<<endl;
      }
      return 0;
}

Measured memory_bytes: 3712
#include<cstdio>
#include<cstring>
#include<functional>
#include<algorithm>
#include<vector>
#include<iostream>
using namespace std;
int main(void)
{
	int i,a,sum;
	sum=0;
	for(i=0;i<10;i++) {
		cin >> a;
		sum+=a;
	}
	cout << sum << endl;
	exit(0);
}

Measured memory_bytes: 1160
fun main(args: Array<String>) {
    val w = readLine().orEmpty()
    var result = "Yes"

    var inStr = mutableMapOf<Char, Int>()

    w.forEach{
        if(inStr[it] == null) {
            inStr[it] = 1
        }else{
            inStr[it] = inStr[it]!!.plus(1)
        }
    }
    run loop@{
        inStr.forEach {
            if(it.value % 2 != 0){
                result = "No"
                return@loop
            }
        }
    }

    println(result)

}


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

typedef long long ll;
const ll MOD=1000000007;

ll n,a,b;
ll x[5002];
void x_init(){
	ll dp[5005][2]={};
	dp[1][0]=1;
	dp[1][1]=0;
	for(int i=1;i<=a;i++){
		dp[i+1][0]+=dp[i][0];
		if(dp[i+1][0]>=MOD)dp[i+1][0]-=MOD;
		if(i+b<=a){
			dp[i+b][1]+=dp[i][0];
			if(dp[i+b][1]>=MOD)dp[i+b][1]-=MOD;
		}
		dp[i+1][0]+=dp[i][1];
		if(dp[i+1][0]>=MOD)dp[i+1][0]-=MOD;
		dp[i+1][1]+=dp[i][1];
		if(dp[i+1][1]>=MOD)dp[i+1][1]-=MOD;
	}
	for(int i=1;i<=a;i++){
		x[i]=dp[i][0];
		//cout<<i<<":"<<x[i]<<endl;
	}
}

int main(){
	cin>>n>>a>>b;
	if(a<b)swap(a,b);
	x_init();
	
	ll dp[5002][2]={};
	for(int i=1;i<=a-1;i++){
		dp[i][0]=x[i+1];
	}
	for(int i=1;i<=b-1;i++){
		dp[i][1]=1;
	}
	for(int i=1;i<=n-1;i++){
		for(int j=1;j<=b-1;j++){
			if(i+j<=n){
				dp[i+j][1]+=dp[i][0];
				if(dp[i+j][1]>=MOD)dp[i+j][1]-=MOD;
			}
		}
		for(int j=1;j<=a-1;j++){
			if(i+j<n){
				dp[i+j][0]+=dp[i][1]*x[j];
				dp[i+j][0]%=MOD;
			}
			else if(i+j==n){
				dp[i+j][0]+=dp[i][1]*x[j+1];
				dp[i+j][0]%=MOD;
			}
		}
	}
	ll ret=1;
	for(int i=0;i<n;i++){
		ret*=2;
		ret%=MOD;
	}
	ret+=MOD-dp[n][0];
	ret+=MOD-dp[n][1];
	cout<<ret%MOD<<endl;
	//cout<<(dp[n][0]+dp[n][1])%MOD<<endl;
}



Measured memory_bytes: 3800
n = int(input())
masu = []
for i in range(n):
    s, p = input().split()
    masu.append([s,int(p),i+1])
masu.sort(key = lambda x: x[1],reverse = True)
masu.sort(key = lambda x: x[0],reverse = False)
for i in range(n):
    print(masu[i][2])

Measured memory_bytes: 3060
#include<cstdio>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<algorithm>
using namespace std;
#define MAXN 100005
#define MO 1000000007
#define PII pair<int,int>
#define LL long long
int n,m,du[MAXN],cnt,st,ed;
int Adj[MAXN],V[MAXN*2],nxt[MAXN*2],c;
bool vis[MAXN];
void AddEdge(int u,int v)
{
	c++;V[c]=v,nxt[c]=Adj[u];Adj[u]=c;
}
int dfs(int u,int p)
{
	vis[u]=1;
	if(u==ed) return 0;
	int ret=0;
	for(int i=Adj[u];i;i=nxt[i])
	{
		int v=V[i];
		if(v==p) continue;
		if(v==st) ret++;
		else if(!vis[v])
			ret+=dfs(v,u);
	}
	return ret;
}
void check()
{
	for(int i=1;i<=n;i++)
		if(du[i]>2)
		{
			if(du[i]==6)
			{
				printf("Yes\n");
				return;
			}
			if(!st) st=i;
			else ed=i;
		}
	if(dfs(st,0)) printf("Yes\n");
	else printf("No\n");
}
int main()
{
	scanf("%d%d",&n,&m);
	for(int i=1,u,v;i<=m;i++)
	{
		scanf("%d%d",&u,&v);
		AddEdge(u,v);
		AddEdge(v,u);
		du[u]++,du[v]++;
	}
	for(int i=1;i<=n;i++)
	{
		if((du[i]&1)||du[i]==0)
		{
			printf("No\n");
			return 0;
		}
		cnt+=(du[i]-2)/2;
	}
	if(cnt>2) printf("Yes\n");
	else if(cnt==2)
	{
		check();
	}
	else printf("No\n");
}

Measured memory_bytes: 3712
#include <iostream>
#include <vector>
#include <algorithm>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;

ll ex[100002];
ll ex_rev[100002];

ll my_pow(ll a, ll b) {
	if(b==1) return a;
	ll h = my_pow(a,b/2);
	h = (h*h)%MOD;
	if(b%2==1) h = (h*a)%MOD;
	return h;
}

ll combination(int n, int m) {
	ll num;
	num = ex[n];
	num = (num*ex_rev[m])%MOD;
	num = (num*ex_rev[n-m])%MOD;
	return num;
}

void init_ex(int n) {
	ex[0] = 1;
	ex_rev[0] = 1;
	for(int i = 1; i <= n; i++) {
		ex[i] = (ex[i-1]*i)%MOD;
		ex_rev[i] = my_pow(ex[i],MOD-2LL);
	}
}

int main() {
	int n;
	cin >> n;
	init_ex(n+1);
	vector<int> hist(n+1);
	vector<int> input(n+1);
	for(int i = 0; i < n+1; i++) {
		cin >> input[i];
		hist[input[i]]++;
	}
	int t;
	for(int i = 1; i <= n; i++) {
		if(hist[i]>1) {
			t = i;
			break;
		}
	}
	int a=-1,b;
	for(int i = 0; i < n+1; i++) {
		if(input[i]==t) {
			if(a==-1) a=i;
			else {
				b=i;
				break;
			}
		}
	}
	vector<ll> ans(n+2);
	for(int i = 1; i <= n+1; i++) {
		ans[i] = combination(n+1,i);
	}
	int l = a+(n-b)+1;
	for(int i = 0; i < l; i++) {
		ans[i+1] -= combination(l-1,i);
		ans[i+1] += MOD;
		ans[i+1] %= MOD;
	}
	for(int i = 1; i <= n+1; i++) {
		cout << ans[i] << endl;
	}
	return 0;
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define mp make_pair
#define pii pair<int,int>
#define pb push_back
const int maxn = 1e5 + 5;
ll a[maxn];
int main()
{
    ios::sync_with_stdio(false);
    ll n , x;  cin >> n >> x;
    for (int i = 1 ; i <= n ; i++) cin >> a[i];
    ll ans = 0;
    for (int i = 1 ; i < n ; i++) {
        if (a[i] + a[i + 1] > x){
            ll v = ((a[i] + a[i + 1]) - x);
            ans += v;
            a[i + 1] -= v;
            if (a[i + 1] <= 0) {
                a[i] -= a[i + 1];
                a[i + 1] = 0;
            }
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 4396
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using PII = pair<int, int>;
using VI = vector<int>;

int main() {
#ifdef LOCAL_EXEC
	freopen("sample.in", "r", stdin);
//	freopen("sample.out", "w", stdout);
#else
  ios_base::sync_with_stdio(false); cin.tie(NULL);
#endif

  int n; cin >> n;
  ll ans = 0;
  ll max_size = 0;
  for (int i = 1; i <= n; i++) {
    ll ai; cin >> ai;
    if (ai > max_size + 1) {
      ans += (ai - 1) / (1 + max_size);
      ai = 1;
    }
    max_size = max(max_size, ai);
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
struct Fast {
    Fast() {
        cin.tie(0);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(20);
    }
} fast;

int main() {
    long a, b, n, ans = 0;
    cin >> n;
    vector<int> as(n);
    for (int i = 0; i < n; i++) {
        cin >> as[i];
    }
    sort(as.begin(), as.end());
    for (int i = 0; i < n; i++) {
        for (int j = i + 1; j < n; j++) {
            int ok = j, ng = n;
            while (abs(ok - ng) > 1) {
                int mid = (ok + ng) / 2;
                // check mid
                if (as[mid] < as[i] + as[j]) {
                    ok = mid;
                } else {
                    ng = mid;
                }
            }
            // cout << i << " " << j << " " << ok << endl;
            ans += ok - j;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
using System;
class range{
    public static void Main(){
        String[] str = Console.ReadLine().Split(' ');
        int a = int.Parse(str[0]);
        int b = int.Parse(str[1]);
        int c = int.Parse(str[2]);
        if(a < b && b < c)
            Console.WriteLine("Yes");
        else
            Console.WriteLine("No");
    }
}


Measured memory_bytes: 17980
/*
AuThOr GaRyMr
*/
#include<bits/stdc++.h>
#define rb(a,b,c) for(int a=b;a<=c;++a)
#define rl(a,b,c) for(int a=b;a>=c;--a)
#define LL long long
#define IT iterator
#define PB push_back
#define II(a,b) make_pair(a,b)
#define FIR first
#define SEC second
#define FREO freopen("check.out","w",stdout)
#define rep(a,b) for(int a=0;a<b;++a)
#define KEEP while(1)
#define SRAND mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#define random(a) rng()%a
#define ALL(a) a.begin(),a.end()
#define POB pop_back
#define ff fflush(stdout)
#define fastio ios::sync_with_stdio(false)
using namespace std;
const int INF=0x3f3f3f3f;
typedef pair<int,int> mp;
typedef pair<mp,mp> superpair;
int n;
string s;
LL res=1;
LL cnt[8];
const int MOD=998244353;
void update(LL & __){
	__+=MOD;
	__%=MOD;
}
int main(){
	fastio;
	cin>>n>>s;
	n+=n+n;
	map<char,int> M;
	M['R']=0;
	M['G']=1;
	M['B']=2;
	rep(i,n){
		int Key=M[s[i]];
		if(cnt[7-(1<<Key)]){
			res*=cnt[7-(1<<Key)];
			update(res);
			cnt[7-(1<<Key)]--;
			update(cnt[7-(1<<Key)]);
		}
		else{
			int ok=0;
			rep(j,3){
				if(j!=Key){
					if(cnt[1<<j]){
						ok=1;
						res*=cnt[1<<j];
						update(res);
						cnt[(1<<j)+(1<<Key)]++;
						cnt[1<<j]--;
						update(cnt[(1<<j)+(1<<Key)]);
						update(cnt[1<<j]);
					}
				}
			}
			if(!ok){
				cnt[1<<Key]++;
				update(cnt[1<<Key]);
			}
		}
	}
	res%=MOD;
	rb(i,1,n/3)
		res*=i,res%=MOD;
	cout<<res<<endl;
	return 0;
}


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

typedef complex<double> P;

int main(){
	int n;
	map<int,int> p;
	int mx = 0;
	while( cin >> n){
		mx = max(mx,++p[n]);
	}
	for(auto i : p )
		if( mx == i.second ) cout << i.first << endl;
	
			
			
}

Measured memory_bytes: 3080
#include <iostream>
#include <vector>
#include <string>
#include <sstream>
#include <algorithm>
#include <map>
#include <set>
#include <cstdio>
#include <cmath>
#define rep(i,l,n) for(lint i=l;i<n;i++)
#define rer(i,l,n) for(lint i=l;i<=n;i++)
#define all(a) a.begin(),a.end()
#define o(a) cout<<a<<endl
#define pb(a) push_back(a)
#define mk(a,b) make_pair(a,b)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef vector<int> vi;
typedef vector<lint> vli;
typedef vector<vi> vvi;
typedef pair<int,int> pii;

int prime[1000000]; 
bool is_prime[1000001];

void sieve(int n){ 
	int p=0;
	for(int i=0;i<=n;i++) is_prime[i]=true;
	is_prime[0]=is_prime[1]=false;
	for(int i=2;i<=n;i++){
		if(is_prime[i]){
			prime[p++]=i;
			for(int j=2*i;j<=n;j+=i) is_prime[j]=false;
		}
	}
	return;
}

int main(){
	int n;
	sieve(1000000);
	while(cin>>n){
		if(n==0) break;
		int res=0;
		rep(i,2,n/2+1){
			if(is_prime[i] && is_prime[n-i]) res++;
		}
		o(res);
	}
}

Measured memory_bytes: 2444
/*
ID: sabertooth
LANG:C++11
TASK: hamming
*/
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
bool _check(int n,int pos)
{
	return (n & (1<<pos));
}
int _set(int n,int pos)
{
	return n=n|(1<<pos);
}
/*no of prime in range
1e9=50847534
1e8=5761455
1e7=664579
1e6=78498
1e5=9592*/
const int N=1e6;
int isprime[N/32+2];
int prime[78498+3];
int prmsz;
void seive()
{
    prmsz=0;
	prime[prmsz++]=2;
	for(int i=3;i*i<=N;i+=2)
	{
		if(!_check(isprime[i/32],i%32))
		for(int j=i*i;j<=N;j+=i+i)
		{
			isprime[j/32]=_set(isprime[j/32],j%32);
		}
	}
	for(int i=3;i<=N;i+=2)
	{
		if(!_check(isprime[i/32],i%32))
			prime[prmsz++]=i;
	}
	return;
}

int main()
{
   seive();
   int n;
   scanf("%d",&n);
   int j=0;
   for(int i=0;i<prmsz and j<n;i++)
   {
       if(prime[i]%5==1)
       {
           j++;
           cout<<prime[i]<<" ";
       }
   }
   cout<<endl;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
typedef  long long ll;
const int N=55,M=22;
const ll inf=1e18;

int n,len[N];
ll f[N][M][2],c[N],ans=inf;
char s[N][M];

ll dp(int id,int pos,int d) {//id????,pos???,d???(??)
    if(pos>len[id]) return 0;
    if(~f[id][pos][d]) return f[id][pos][d];
    ll &v=f[id][pos][d];
     v=inf;
	bool flag=1;
	if(!d){ for(int j=pos,k=len[id];j<k;j++,k--) if(s[id][j]!=s[id][k]) {flag=0; break;} } 
	else{ for(int j=pos,k=1;j>k;j--,k++) if(s[id][j]!=s[id][k]) {flag=0; break;} } 
	if(flag) return v=0;
    for(int i=1,j,k;i<=n;i++) {//???????????
        flag=1;
        if(!d) {
            for(j=pos,k=len[i];j<=len[id]&&k>=1;j++,k--)
                if(s[id][j]!=s[i][k]) {flag=0; break;}
            if(flag) {
                if(k<1) v=min(v,c[i]+dp(id,j,0));
                else v=min(v,c[i]+dp(i,k,1));
            }
        }
        else {
            for(j=pos,k=1;j>=1&&k<=len[i];j--,k++)
                if(s[id][j]!=s[i][k]) {flag=0; break;}
            if(flag) {
                if(j<1) v=min(v,c[i]+dp(i,k,0));
                else v=min(v,c[i]+dp(id,j,1));
            }
        }
    }
    return v;
}

int main() {
    scanf("%d",&n); memset(f,-1,sizeof(f));
    for(int i=1;i<=n;i++) scanf("%s",s[i]+1),scanf("%lld",&c[i]),len[i]=strlen(s[i]+1);
    for(int i=1;i<=n;i++) 
		ans=min(ans,c[i]+dp(i,1,0));
    printf("%lld\n",ans==inf?-1:ans);return 0;
}



Measured memory_bytes: 3832
function main(input) {
    const reverse = (s) => {
        return s.split('').reverse().join('');
    };

    const WORDS = ['dream', 'dreamer', 'erase', 'eraser'].map(reverse);
    const S = reverse(input.split('\n')[0]);

    var index = 0;

    while(true) {
        var w = WORDS.find((w) => S.startsWith(w, index));
        if (!w) break;
        index += w.length;
    }

    if (S.length === index) {
        console.log('YES');
    } else {
        console.log('NO');
    }
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 36076
n, m, r = gets.split.map &:to_i
g = Array.new(n) { [] }
m.times do
  s, t, w = gets.split.map(&:to_i)
  g[s] << [t, w]
end
d = Array.new n, Float::INFINITY
d[r] = 0
(n-1).times do
  g.each_with_index do |es, s|
    es.each do |t, w|
      d[t] = [d[t], d[s] + w].min
    end
  end
end
nc = g.each_with_index.any? do |es, s|
  es.any? do |t, w|
    d[s] + w < d[t]
  end
end
if nc
  puts 'NEGATIVE CYCLE'
else
  d.each do |w|
    puts w == Float::INFINITY ? 'INF' : w
  end
end

Measured memory_bytes: 8896
def getlist():
	return list(map(int, input().split()))

W, H = getlist()
E = []

for i in range(W):
	p = int(input())
	E.append([p, "W"])
for i in range(H):
	q = int(input())
	E.append([q, "H"])
E = sorted(E)

N = H + W
h = H + 1
w = W + 1
ans = 0
for i in range(N):
	if E[i][1] == "W":
		ans += E[i][0] * h
		w -= 1
	else:
		ans += E[i][0] * w
		h -= 1

print(ans)

Measured memory_bytes: 84568
#include <bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
#define R(i,c,n) for(int i=c;i<n;i++)
#define DEBUG(x) cerr << #x << ": " << x << endl;
#define DUMP(a) REP(d,a.size()){cout<<a[d];if(d!=a.size()-1)cout<<" ";else cout<<endl;}
#define ALL(v) v.begin(),v.end()
#define UNIQUE(v)  sort(ALL(v));v.erase(unique(ALL(v)),v.end());
#define pb push_back
using namespace std;
const int dx[] = {1, -1, 0, 0};
const int dy[] = {0, 0, -1, 1};
const double PI = 3.14159265358979323846;

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  double n,h,w;
  cin >> n >> h >> w;
  cout << (n-h+1)*(n-w+1) << endl;
  return 0;
}

Measured memory_bytes: 256
cmdvar=input()
in_plited=cmdvar.split()

r=int(in_plited[0])
D=int(in_plited[1])
x_2000=int(in_plited[2])

i=0
while i<10:
    x_2000=r*x_2000-D
    ans=x_2000
    print(ans)
    i=i+1

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

int partition(vector<int> &arr, int p, int r)
{
  int x = arr[r];
  int i = p-1;
  for (int j = p; j < r; j++) {
    if (arr[j] <= x) {
      i++;
      swap(arr[i], arr[j]);
    }
  }
  swap(arr[i+1], arr[r]);
  return i+1;
}

int main()
{
  int n; cin >> n;
  vector<int> arr = vector<int>(n);
  for (int i = 0; i < n; i++)
    cin >> arr[i];
  int r = n-1;
  int ret = partition(arr, 0, r);
  for (int i = 0; i < n; i++) {
    if (i == ret)
      cout << "[" << arr[i] << "]";
    else
      cout << arr[i];
    cout << (i==n-1?'\n':' ');
  }
  return EXIT_SUCCESS;
}



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

bool query = 0;
struct line{
    long long m ,b;
    mutable function <const line*()> succ;
    bool operator<(const line&rhs) const{
        if(!query)
            return m < rhs.m;
        const line *s = succ();
        return s ? (b-s->b) < rhs.m*(s->m-m) : 0;
    }
};
struct hull:multiset<line>{
    bool bad(iterator y){
        auto z = next(y);
        if(y == begin()){
            if(z == end())
                return 0;
            return (y->m==z->m) && (y->b<=z->b);
        }
        auto x = prev(y);
        if(z == end())
            return (y->m==x->m) && (y->b<=x->b);
        return (1.0)*(x->b-y->b)*(z->m-y->m) >= (1.0)*(y->b-z->b)*(y->m-x->m);
    }
    void add(long long m ,long long b){
        auto it = insert({-m ,-b});
        it -> succ = [=]{ return next(it)==end() ? 0:&*next(it); };
        if(bad(it)){
            erase(it);
            return;
        }
        while(next(it) != end() && bad(next(it))) erase(next(it));
        while(it != begin()     && bad(prev(it))) erase(prev(it));
    }
    long long eval(long long x){
        query = 1;
        auto l = *lower_bound({x,0});
        query = 0;
        return -(l.m*x+l.b);
    }
};

#define MAX_N 200005

int n;
long long c ,s[MAX_N];
hull h;

int main()
{
    scanf("%d%lld",&n,&c);
    for(int i=0; i<n; i++)
        scanf("%lld",&s[i]);

    vector <long long> dp(n);
    h.add(-2*s[0] ,s[0]*s[0]);
    for(int i=1; i<n; i++){
        dp[i] = s[i]*s[i]+c+h.eval(s[i]);
        h.add(-2*s[i] ,s[i]*s[i]+dp[i]);
    }
    printf("%lld\n",dp[n-1]);
}


Measured memory_bytes: 22144
#include<iostream>
#include<vector>
using namespace std;
int main(){

  int N;
  cin>>N;
  vector<int>P(N);
  for(int i=0;i<=N-1;i++){
  
    cin>>P[i];
  }
  int min=P[0];
  int ans=1;
  for(int i=1;i<=N-1;i++){
  
    if(min>=P[i]){
    
      ans++;
      min=P[i];
    }
  }
  cout<<ans;
}

Measured memory_bytes: 3964
#include <iostream>
#include <algorithm>
#include <functional>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <bitset>
#include <unordered_set>
 
using namespace std;
 
typedef long long ll;
typedef pair<ll, ll> P;
static const int INF = 1000010000;
static const int NIL = -1;
static const int MOD = 1000000007;
 
#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define REP(i, n) for(int i = 0; i < (n); ++i)
#define SORT(v) sort(v.begin(), v.end());
#define RSORT(v) sort(v.begin(), v.end(), greater<int>);
#define pb push_back
#define mp make_pair
#define np next_permutation
#define pq priority_queue
 
int gcd(int a, int b) { int c; while (b != 0) { c = a%b; a = b; b = c; }return a; }
int lcm(int a, int b) { int c = gcd(a, b); a /= c; return a*b; }
int nCr(int a, int b) { int i, r = 1; for (i = 1; i <= b; i++) { r *= (a + 1 - i); r /= i; }return r; }
int pow(int a, int b) { int i, r = 1; for (i = 1; i <= b; i++) { r *= a; }return r; }
long long llpow(long long a, long long b) { long long i, r = 1; for (i = 1; i <= b; i++) { r *= a; }return r; }
long long llgcd(long long a, long long b) { long long c; while (b != 0) { c = a%b; a = b; b = c; }return a; }
long long lllcm(long long a, long long b) { long long c = llgcd(a, b); a /= c; return a*b; }
long long llnCr(long long a, long long b) { long long i, r = 1; for (i = 1; i <= b; i++) { r *= (a + 1 - i); r /= i; }return r; }
 
//int dx4[4] = {0,1,0,-1}, dy4[4] = {-1,0,1,0};
//int dx5[5] = {-1,0,0,0,1}, dy5[5] = {0,-1,0,1,0};
//int dx8[8] = {-1,0,1,1,1,0,-1,-1}, dy8[8] = {1,1,1,0,-1,-1,-1,0};
//int dx9[9] = {-1,0,1,1,1,0,-1,-1,0}, dy9[9] = {1,1,1,0,-1,-1,-1,0,0};

struct edge{
    int to, cost;
};

int main(){
    int n;
    cin >> n;
    int a[2][100];
    int sum[2]; sum[0] = sum[1] = 0;
    REP(i, 2) REP(j, n){
        cin >> a[i][j];
    }
    int ans = 0;
    REP(i, n){
        int s = 0;
        REP(j, i + 1){
            s += a[0][j];
        }
        FOR(j, i, n){
            s += a[1][j];
        }
        ans = max(s, ans);
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
n = int(input())
s = []
suit = ["S",'H',"C","D"]
for i in range(n):
    a,b = input().split()
    b = int(b)
    if a == "S":
        s.append(b)
    elif a == "H":
        s.append(b+13)
    elif a == "C":
        s.append(b+26)
    elif a == "D":   
        s.append(b+39)    

for i in range(1,53):
    if not (i in s):
        print(suit[(i-1)//13], (i-1)%13+1)



Measured memory_bytes: 5596
#include <stdio.h>
int main(){
    int n,a;
    scanf("%d %d\n", &n, &a);

    int l = a;
    int r = a+n-1;

    int x;
    if(r<=0) x = r;
    else if(l>=0) x =l;
    else x = 0;

    int answer=(r+l)*(r-l+1)/2-x;

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

}




Measured memory_bytes: 1732
A = int(input())
B = int(input())
C = int(input())
X = int(input())

count = 0
for a in range(0, A + 1):
    for b in range(0, B + 1):
        for c in range(0, C + 1):
            if X == (500 * a) + (100 * b) + (50 * c):
                count += 1
            else:
                pass

print(count)


Measured memory_bytes: 3060
/*~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=
*$* WRITER:kakitamasziru/OxOmisosiru *$*
~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=*/
#ifdef LOCAL_JUDGE
#define _GLIBCXX_DEBUG //FOR THE DEBUG! COMMENT OUT THIS WHEN SUBMITTING!
#endif
/* I REALLY HOPE MY WISH REACH YOU , ATCODER'S ONLINE JUDGE */
#define WOULD
#define YOU
#define PLEASE
#define ACCEPT
#define MY
#define SUBMISSION
/* I REALLY HOPE MY WISH REACH YOU , ATCODER'S ONLINE JUDGE */
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <iomanip>
#include <limits>//setprecision
//#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <unordered_set> //unordered_set
#include <stack> // stack
#include <deque> // deque
#include <math.h>//pow,,,
#include <cmath>//abs,,,
#include <bitset> // bitset
//It is so troublesome that I include bits/stdc++.h !
using namespace std;

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 long long INF = 100100100100;
const long long MOD = 1000000007;
typedef pair<int,int> P;

//Solve N^M. This, mod_pow use Iterative Square Method.
long long mod_pow(long long N, long long M) {
    if (M == 0) return 1;
    long long res = mod_pow((N * N) % MOD, M / 2);
    //最下位ビット(*N)が1の時は単独でNをかける
    if (M & 1) res = (res * N) % MOD;

    return res %= MOD;
}

long long gcd(long long a, long long b) {
    if (b == 0) return a;
    else return gcd(b, a % b);
}
long long lcm(long long a, long long b) {
    return a * b / gcd(a, b);
}
//桁和がiになる数の個数を表す配列res
vector<int> res(1145141,0);

int main() {
    string S;cin >> S;
    int N,M;
    N = (S.at(0)-'0')*10+S.at(1)-'0';
    M = (S.at(2)-'0')*10+S.at(3)-'0';
    if((N > 12 || N == 0) && (M > 12 || M == 0)){
        cout << "NA" << endl;
    }
    else if((N <= 12 && N != 0) && (M > 12 || M == 0)){
        cout << "MMYY" << endl;
    }
    else if((N > 12 || N == 0) && (M <= 12 || M != 0)){
        cout << "YYMM" << endl;
    }
    else{
        cout << "AMBIGUOUS" << endl;
    }
}

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

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

        Arrays.sort(a);
        int mx = -1;
        int mx2 = -1;
        for (int i = 0; i < n - 1; i++) {
            if (a[i] == a[i + 1]) {
                i++;
                mx2 = mx;
                mx = a[i];
            }
        }

        if (mx2 == -1) {
            System.out.println(0);
        } else {
            long area = mx;
            area *= mx2;
            System.out.println(area);
        }
    }
}

Measured memory_bytes: 50780