akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;

using System.Collections;

class Program
{
    static void Main()
    {
        int[] hw = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();

        int H = hw[0];
        int W = hw[1];
        

        char[] data = new char[H * W];

        for(int i = 0; i < H; i++)
        {
            char[] lineData = Console.ReadLine().ToArray();
            lineData.CopyTo(data, i * W);
        }

        var validRows = Enumerable.Range(0, H).Where(y => Enumerable.Range(0, W).Any(x => data[W * y + x] == '#')).ToArray();
        var validCols = Enumerable.Range(0, W).Where(x => Enumerable.Range(0, H).Any(y => data[W * y + x] == '#')).ToArray();

        foreach(var y in validRows)
        {
            foreach(var x in validCols)
            {
                Console.Write(data[y * W + x]);
            }
            Console.WriteLine();
        }


    }
}


static class MathUtil
{
    public static IEnumerable<IEnumerable<int>> GetPermutation(int n)
    {
        if (n == 0)
        {
            yield return Single(0);
            yield break;
        }

        for (int i = 0; i <= n; i++)
        {
            foreach (var x in GetPermutation(n - 1))
            {
                yield return Single(i).Concat(x.Select(itm => itm < i ? itm : itm + 1));
            }
        }
    }

    private static IEnumerable<int> Single(int x)
    {
        yield return x;
    }

    public static IEnumerable<int> EnumeratePrimeNumbers()
    {
        List<int> primes = new List<int>() { 2 };
        yield return 2;

        for (int i = 3; i < int.MaxValue; i++)
        {
            bool isPrime = true;
            int Sqrt = (int)Math.Sqrt(i) + 1;

            foreach (var prime in primes)
            {
                if (prime > Sqrt)
                {
                    break;
                }
                if (i % prime == 0)
                {
                    isPrime = false;
                    break;
                }
            }

            if (isPrime)
            {
                primes.Add(i);
                yield return i;
            }
        }
    }
}


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

int main() {
  int a, b;
  cin >> a >> b;
  int ans = max(a-2*b, 0);
  cout << ans << endl;
  return 0;
}

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

#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define INF 2e9
#define MOD 1000000007
//#define MOD 998244353
#define LINF (long long)4e18
#define jck 3.141592

const double EPS = 1e-10;

using ll = long long;
using Pi = pair<int,int>;
using Pl = pair<ll,ll>;

int main(){
  int n,k; cin >> n >> k;
  vector<int> p(n);
  rep(i,n) cin >> p[i];
  sort(p.begin(),p.end());
  int ans = 0;
  rep(i,k) ans += p[i];
  cout << ans << endl;
}


Measured memory_bytes: 3612
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<(n); ++i)
#define y_n(ans) cout<<(ans?"Yes":"No")<<endl;

int main() {
    int n; cin >> n;
    vector<long long> nums(1e5 + 10);
    long long sum = 0;
    for (int i=0; i<n; ++i) {
        int a; cin >> a;
        sum += a;
        nums[a]++;
    }
    int q; cin >> q;
    vector<long long> ans;
    for (int i=0; i<q; ++i) {
        int b, c; cin >> b >> c;
        nums[c] += nums[b];
        sum += nums[b] * (c - b);
        nums[b] = 0;
        ans.push_back(sum);
    }
    for (auto i: ans) cout << i << endl;
}

Measured memory_bytes: 5012
#include <stdio.h>
int main()
{
    int n, k, q;
    scanf("%d%d%d", &n, &k, &q);
    int tmp;
    int p[n];
    for (int i = 0; i < n; i++)
        p[i]=k;
    for (int i = 0; i < q; i++)
    {
        scanf("%d", &tmp);
        p[tmp-1] += 1;
    }
    for (int i = 0; i < n; i++)
    {
        if(p[i]-q<=0){
            printf("No\n");
        }
        else{
            printf("Yes\n");
        }
    }

}

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

int main(){
int N,K;
 cin>>N>>K;
  
  int ans=1;
  for(int i=0; i<N; i++){
   if(i==0){ans*=K;}
    else{ans*=(K-1);}
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <cstring>
#include <cmath>
#include <cstdio>
#include <unordered_map>
#include <queue>
#include <map>
#include <sstream>
#include <set>
#include <cstdlib>
#include <ctime>
#include <unordered_set>
#include <bitset>
#include <chrono>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
//#pragma GCC optimize(3, "Ofast", "inline")
#define MAX_INF 0x3f3f3f3f
template <class T, class C>
void print(C name, T a)
{
	cout << name << ": " << a << endl;
}
template <class T>
T gcd(T a, T b)
{
	return b ? gcd(b, a % b) : a;
}
template <class T>
T lcm(T a, T b)
{
	return a * b / gcd(a, b);
}
ll pow(ll a, ll b, ll p)
{
	ll ans = 1;
	a %= p;
	while (b)
	{
		if (b & 1)
			ans = ans * a % p;
		a = a * a % p;
		b >>= 1;
	}
	return ans;
}
template <typename _Tp>
void read(_Tp &x)
{
	char ch;
	bool flag = 0;
	x = 0;
	while (ch = getchar(), !isdigit(ch))
		if (ch == '-')
			flag = 1;
	while (isdigit(ch))
		x = x * 10 + ch - '0', ch = getchar();
	if (flag)
		x = -x;
}
template <class T>
void print(T x)
{
	if (x < 0)
	{
		x = -x;
		putchar('-');
	}
	if (x > 9)
		print(x / 10);
	putchar(x % 10 + '0');
}
const ll mod = 998244353;
const ll inf = 1e18;
ll add(ll x, ll t)
{
	x %= mod;
	t %= mod;
	return (x + t) % mod;
}
ll del(ll ans, ll x)
{
	ans %= mod;
	ans += mod;
	x %= mod;
	return (ans - x) % mod;
}
ll mul(ll ans, ll x)
{
	ans %= mod;
	x %= mod;
	return (ans * x) % mod;
}
#define fir(i, a, b) for (int i = a; i <= b; i++)
const int maxn = 3000+ 20, N = 2010, M = 3000 + 10;
int p[maxn];
ll c[maxn];
vector<vector<ll>> sum;
ll a[maxn][maxn];
ll dp[maxn][maxn][4];
int main()
{
	int n,m,k;
	cin>>n>>m>>k;
	fir(j,1,k)
	{
		int x,y;
		ll w;
		scanf("%d%d%lld",&x,&y,&w);
		a[x][y]=w;
	}
	ll ans=0;
	fir(i,1,n)
	fir(j,1,m)
	{
		fir(u,1,3)
		{
			dp[i][j][u]=max(dp[i][j-1][u-1]+a[i][j],max(dp[i][j-1][u],dp[i-1][j][3]+a[i][j]));
			ans=max(ans,dp[i][j][u]);
		}
	}
	cout<<ans<<endl;
}

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

using namespace std;

/* g++ -g -fsanitize=address -lasan -std=c++11 -Dfoo_ */

/* freopen("input.txt", "rt", stdin); */
/* freopen("output.txt", "wt", stdout); */

#define ALL(c)          (c).begin(), (c).end()
#define ALLR(c)         (c).rbegin(), (c).rend()
#define FOR(i,a,b)      for (int i=(a); i < (b); ++i)
#define FORR(i,a,b)     for (int i=(a); i > (b); --i)
#define FOR_ALL(i,c)    for (__typeof((c).begin()) i=(c).begin();   \
                             i != (c).end(); ++i)
#define FOR_ALLR(i,c)   for (__typeof((c).rbegin()) i=(c).rbegin(); \
                             i != (c).rend(); ++i)
#define SZ(array)       (sizeof(array)/sizeof(array[0]))
#define lc(x)           (x<<1)     /* 2*x */
#define rc(x)           (x<<1 | 1) /* 2*x+1 */
#define lowbit(x)       (x & (-x)) /* 0b10100 -> 0b100 */

typedef long long       LL;
typedef map<int,int>    MII;
typedef pair<int,int>   PII;
typedef set<int>        SI;
typedef vector<bool>    VB;
typedef vector<double>  VD;
typedef vector<int>     VI;
typedef vector<string>  VS;

/* check if a key is in container C */
template <class C>
inline bool in_(const typename C::key_type& k, const C& A)
{ return A.find(k) != A.end(); }
inline bool in_(const string& s, const string& S)
{ return S.find(s) != string::npos; }

int main()
{
#ifdef foo_
    freopen("foo", "rt", stdin);
#endif
    int n;
    while (cin >> n) {
        multiset<int> S; int ans = 0;
        FOR(i,0,n) {
            int a; cin >> a;
            if (S.empty()) {
                ans++; S.insert(a);
            }
            else {
                auto i = S.upper_bound(a-1);
                if (i == S.begin())
                    ans++;
                else
                    S.erase(--i);
                S.insert(a);
            }
        }
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 4992
import java.io.BufferedWriter;
import java.util.InputMismatchException;
import java.io.InputStream;
import java.io.OutputStreamWriter;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.Writer;
import java.io.IOException;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 * @author ilyakor
 */
public class Main {
	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		OutputWriter out = new OutputWriter(outputStream);
		TaskA solver = new TaskA();
		solver.solve(1, in, out);
		out.close();
	}
}

class TaskA {
    public void solve(int testNumber, InputReader in, OutputWriter out) {
        int n = in.nextInt();
        int res = Integer.MAX_VALUE;
        for (int i = 1; i <= n - 1; ++i) {
            int cur = sum(i) + sum(n - i);
            if (cur < res)
                res = cur;
        }
        out.printLine(res);
    }

    private int sum(int x) {
        int res = 0;
        while (x > 0) {
            res += x % 10;
            x /= 10;
        }
        return res;
    }
}

class InputReader {
    private InputStream stream;
    private byte[] buffer = new byte[10000];
    private int cur;
    private int count;

    public InputReader(InputStream stream) {
        this.stream = stream;
    }

    public static boolean isSpace(int c) {
        return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
    }

    public int read() {
        if (count == -1) {
            throw new InputMismatchException();
        }
        try {
            if (cur >= count) {
                cur = 0;
                count = stream.read(buffer);
                if (count <= 0)
                    return -1;
            }
        } catch (IOException e) {
            throw new InputMismatchException();
        }
        return buffer[cur++];
    }

    public int readSkipSpace() {
        int c;
        do {
            c = read();
        } while (isSpace(c));
        return c;
    }

    public int nextInt() {
        int sgn = 1;
        int c = readSkipSpace();
        if (c == '-') {
            sgn = -1;
            c = read();
        }
        int res = 0;
        do {
            if (c < '0' || c > '9') {
                throw new InputMismatchException();
            }
            res = res * 10 + c - '0';
            c = read();
        } while (!isSpace(c));
        res *= sgn;
        return res;
    }

}

class OutputWriter {
    private final PrintWriter writer;

    public OutputWriter(OutputStream outputStream) {
        writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
    }

    public void print(Object... objects) {
        for (int i = 0; i < objects.length; i++) {
            if (i != 0) {
                writer.print(' ');
            }
            writer.print(objects[i]);
        }
    }

    public void printLine(Object... objects) {
        print(objects);
        writer.println();
    }

    public void close() {
        writer.close();
    }

}



Measured memory_bytes: 21460
#include <bits/stdc++.h>
#include <vector>
#include <iostream>
#include <map>
#include <cmath>
#include <string>
#include <algorithm>
#include <math.h>
using namespace std;

#define rep(i, o) for (ll i = 0; i < (o);i++)
#define rep_s(i, o) for (int i = 1; i <= (o);i++)
#define REP(i,a,b)for(int i=(int)(a);(i)<(int)(b);i++)
#define NUM 1e5

typedef long long ll;
typedef unsigned long long ull;

ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll lcm(ll c, ll d) { return c / gcd(c, d) * d; }


template<class T>
bool chmax(T &a, const T &b) { if (a < b) { return b; } return a; }

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

int main() {
    ll n; cin >> n;

    vector<ll> a(n); ll ans = 0;
    rep(i, n) {
        cin >> a[i];
        if ((i+1)%2 == 1 && a[i]%2 == 1) ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3628
#include<bits/stdc++.h>
#define rep(i,N) for(int i=0;i<(N);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e12;
const int inf = 1e9;
const int mod = 1e9+7;
typedef long long ll;
typedef pair<ll,int> P;
typedef set<int> S;
int main(){
    cout << fixed << setprecision(10);
    while(1){
        string s;
        cin >> s;
        if(s == "#") break;
        int y,m,d;
        cin >> y >> m >> d;
        if(y > 31){
            cout << "?" << " " << y- 30 << " " << m << " " << d << endl;
        }else if(y == 31){
            if(m >= 5){
                cout << "?" << " " << y - 30 << " " << m << " " << d << endl;
            }else{
                cout << s << " " << y << " " << m << " " << d << endl;
            }
        }else{
            cout << s << " " << y << " " << m << " " << d << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 3144
#include <iostream>

using namespace std;

// L0=2, L1=1, L2=3, L3=4, L4=7,L5=11,L6=18
// Ln={Ln-1}+{Ln-2}={{Ln-2}+{Ln-3}}+{{Ln-3}+{Ln-4}}
// L2=L1+L0
// L3=L2+L1=2L1+L0
// L4=L3+L2=(2L1+L0)+(L1+L0)=3L1+2L0
// L5=L4+L3=(3L1+2L0)+(2L1+L0)=5L1+3L0
// L6=(5L1+3L0)+(3L1+2L0)=8L1+5L0
// Ln=(fib(n)L1+fib(n-1)L0)

// L3-L2=(2L1+L0)-(L1+L0)=L1
// L4-L3=(3L1+2L0)-(2L1+L0)=L1+L0
// L5-L4=(5L1+3L0)-(3L1+2L0)=2L1+L0
// L6-L5=(8, 5)-(5,3)=(3,2)
// Ln - Ln-1 = (fib(n), fib(n-1)) - (fib(n-1), fib(n-2)) = 

// fib(1)=1
// fib(2)=1
// fib(3)=2
// fib(4)=3
// fib(5)=5
// fib(6)=8
// fib(7)=13
// fib(8)=21

//  a=f_n, b=f_n-1

int64_t fib(int N, int64_t* previous_num1)
{
	if (N<=2)
	{
		*previous_num1 = 1;
		return 1;
	}

	int64_t curret_num = 1;
	*previous_num1 = 1;
	int64_t previous_num2 = 1;
	
	for (int n = 2; n < N; n++)
	{
		previous_num2 = *previous_num1;
		*previous_num1 = curret_num;
		curret_num= *previous_num1 + previous_num2;
	}
	return curret_num;
}

int64_t lucas(int n)
{
	// fibの計算を一回のみにするためbを導入

	int64_t a, b;
	a = fib(n, &b);
	return a + 2*b;
}

int main()
{
	int N;
	cin >> N;

	if (N == 1)
	{
		cout << 1 << endl;
		return 0;
	}
	
	cout << lucas(N) << endl;

	return 0;

}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
	long long X,K,D,result = 0;
	cin>>X>>K>>D;
	long long div=abs(X)/D;
	long long mod=abs(X)%D;
	if(K>div){
		K-=div;
		if(K%2==0){
			result=mod;
		}
		else{
			if(D>mod){
				result=D-mod;
			}
			else{
				result=mod-D;
			}
		}
	}
	else if(K<div){
		result=abs(X)-(D*K);
	}
	else{
		result=abs(X)%D;
	}
	cout<<result;
	return 0;
}

Measured memory_bytes: 3620
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;

using ll = long long;
using P = pair<int, int>;

template <class T> inline T chmax(T &a, T &b) {a = max(a, b);}
template <class T> inline T chmin(T &a, T &b) {a = min(a, b);}

constexpr int MOD = 1e9 + 7;
constexpr ll INF = 1e18;
constexpr double pi = acos(-1);
constexpr double EPS = 1e-10;

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

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

    ll n; cin>>n;
    vector<ll> a(n);
    for(int i=0; i<n; i++) cin>>a[i];

    ll ok = 0, ng = 1e10;
    ll mid;
    while(ng - ok > 1){ // [ok, ng)
        mid = (ok + ng) / 2;

        ll rain = mid * 2;
        for(int i=0; i<n; i++){
            ll rest = a[i] - rain / 2;
            rain = rest * 2;
        }

        if(mid * 2 <= rain){
            ok = mid;
        }   
        else{
            ng = mid;
        }
    }

    vector<ll> ans(n);
    ll rain = ok;
    rain *= 2;
    for(int i=0; i<n; i++){
        ans[i] = rain;
        ll rest = a[i] - rain / 2;
        rain = rest * 2;
    }

    for(int i=0; i<n; i++){
        cout << ans[i] << " \n"[i == n-1];
    }
}

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

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = (n) - 1; i >= 0; i--)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (a); i > (b); i--)
#define ALL(a) (a).begin(), (a).end()

int main() {
    ll N, M;
    cin >> N >> M;
    pll AB[N];
    REP(i, N) {
        ll A, B;
        cin >> A >> B;
        AB[i] = {A, B};
    }
    sort(AB, AB + N);
    ll ans = 0;
    REP(i, N) {
        if (M <= 0) break;
        ans += AB[i].first * min(AB[i].second, M);
        M -= AB[i].second;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 5156
import sys
sys.setrecursionlimit(10**6)
readline = sys.stdin.readline
N = int(input())
A = [int(i) for i in readline().split()]

from collections import Counter
c = Counter(A)

for i in range(1,N+1):
  if i in c:
    print(c[i])
  else:
    print(0)


Measured memory_bytes: 35032
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
using namespace std;

ll inf=9223372036854775806;

int main()
{
	//freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
	ios_base::sync_with_stdio(false); cin.tie(0);
	ll h,w,i,j,k;
	bool q,r[100],c[100];
	fill(r,r+100,true);
	fill(c,c+100,true);
	cin>>h>>w;
	char a[h][w];
	for (i=0;i<h;i++){
		cin>>a[i];
	}
	for (i=0;i<h;i++){
		q=true;
		for (j=0;j<w;j++){
			if (a[i][j]=='#'){
				q=false;
			}
		}
		if (q==true){
			r[i]=false;
		}
	}
	for (i=0;i<w;i++){
		q=true;
		for (j=0;j<h;j++){
			if (a[j][i]=='#'){
				q=false;
			}
		}
		if (q==true){
			c[i]=false;
		}
	}
	for (i=0;i<h;i++){
		q=false;
		for (j=0;j<w;j++){
			if (r[i]==true&&c[j]==true){
		    	cout<<a[i][j];
		    	q=true;
		    }
		}
		if (q==true){
			cout<<"\n";
		}
	}
	return 0;
}

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

int main() {
    string s; cin >> s;
    int n = s.length();
    int v = 0;
    for(int i = 0; i < n; i ++) {
        if(s[i]=='o') v++;
    }
    cout << (15-n+v >= 8 ? "YES" : "NO") << endl;
    return 0;
}

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

int main(){
    int N,K;
    string S;
    cin >> N >> K >> S;
    
    if(S.at(K - 1) == 'A') S.at(K - 1) = 'a';
    else if(S.at(K - 1) == 'B') S.at(K - 1) = 'b';
    else S.at(K - 1) = 'c';
    
    cout << S << endl;
    
    
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#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++)
#define pi 3.14159265359
#define all(i) i.begin(),i.end()
using namespace std;
const long long INF=1e9+7;
const string alp="abcdefghijklmnopqrstuvwxyz"; //26
const string ALP="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> T;
//const ll MOD=998244353LL;
//const ll MOD=1777777777LL;


int main() {
  ll N,M;cin>>N>>M;
  ll a[M],b[M];
  vl ans(N,0);
  rep(i,M){
    cin>>a[i]>>b[i];
    a[i]--;
    b[i]--;
    ans[a[i]]++;
    ans[b[i]]++;
  }
  rep(i,N) cout<<ans[i]<<endl;
}

Measured memory_bytes: 3612
#include <iostream>
#include <vector>
#include <map>
#include <utility>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <stack>
#include <queue>

#define REP(i,a,n) for(int i=a;i<n;++i)
#define rep(i,n) REP(i,0,n)
#define vsort(v) sort(v.begin(),v.end())
#define asort(a,n) sort(a, a + n)
#define vi vector<int>
#define vd vector<double>

//ここからAtCoder向けdefine
#define yes cout << "YES" << endl;
#define no cout << "NO" << endl;

using namespace std;

int main(){
    ios::sync_with_stdio(false);
    int x, y, z;

    cin >> x >> y >> z;
    int counter = 0;
    int current = 0;
    current += z;
    while(true){
        current += y;
        current += z;
        //cout << current << endl;
        if(current > x){
            break;
        }else{
            counter++;
        }
    }

    cout << counter << endl;

    return 0;
}

Measured memory_bytes: 256
using System;
class Program
    {
        static void Main(string[] args)
        {
            string[] input1 = Console.ReadLine().Split(' ');
            string[] input2 = Console.ReadLine().Split(' ');
            string[] input3 = Console.ReadLine().Split(' ');
            Console.WriteLine(new Output().Calu(input1,input2,input3).ToString());
        }

        public class Output{
            private const int MOD = 1000000007;
            private long Sum(string[] s, int n){
                long Sum = 0;
                for (int i = 0; i < n; i++) {
                    Sum += long.Parse(s[i]) * (2 * i - n + 1); 
                }
                return Sum % MOD;
            }
            public long Calu(string[] input1, string[] input2, string[] input3)
            {      
                return (Sum(input2, int.Parse(input1[0])) * Sum(input3, int.Parse(input1[1]))) % MOD;
            }
        }
    }

Measured memory_bytes: 33756
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

target = a[0]
ans = 0

for i in range(n):
#    print("\n# i: " + str(i))

    if b[i] > target:
#        print("# Terminate all!")
        ans += target
        res = b[i] - target
        ans += min(res, a[i+1])
        target = a[i+1] - res
        if target < 0:
            target = 0

        # print("# ans: " + str(ans))
        # print("# res: " + str(res))
        # print("# target: " + str(target))
    else:
#        print("# Do my best...")
        ans += b[i]
        target = a[i+1]
#        print("# ans: " + str(ans))

print(ans)


Measured memory_bytes: 81892
#include <iostream>

 using namespace std;

int main()
{
   int i, h, m, s;
   cin >> i;
   h = i / 3600;
   m = (i - h * 3600) / 60;
   s = i % 60;
   cout << h << ":" << m << ":" << s << endl;

   return 0;
}
// comments for human
// 1 min = 60 sec
// 1 hour = 60 min = 3600 sec


Measured memory_bytes: 3084
N=int(input())
A=list(map(int,input().split()))

M=max(A)
check=[0]*(M+1)
#A.sort()
for i in range(N):
    a=A[i]
    if check[a]>1:
        continue
    while a<=M:
        check[a]+=1
        a+=A[i]
ans=0
for i in range(N):
    if check[A[i]]==1:
        ans+=1

print(ans)

Measured memory_bytes: 32220
#include<iostream>
using namespace std;
int main()
{
	while(1){
		int a,b;
		char op;
		cin >> a >> op >> b;
		if(op=='?')break;
		switch(op){
		case '+':
			cout << a+b << endl;
			break;
		case '-':
			cout << a-b << endl;
			break;
		case '*':
			cout << a*b << endl;
			break;
		case '/':
			cout << a/b << endl;
			break;
		}
	}
	return 0;
}

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

using namespace std;


int main(){

// #ifndef ONLINE_JUDGE
//     // for getting input from input.txt
//     freopen("input.txt", "r", stdin);
//     // for writing output to output.txt
//     freopen("output.txt", "w", stdout);
// #endif
    int n;
    int sum;
    cin>>n;
    cin>>sum;
    ll dp[n+1][sum+1];
    vector<int>w(n);
    vector<int>val(n);
    for(int i=0;i<n;i++){
    	cin>>w[i];
    	cin>>val[i];
    }
    for(int i=0;i<=n;i++){
    	for(int j=0;j<=sum;j++){
    		if(i==0||j==0)
    			dp[i][j] = 0;
    		else{
    			if(w[i-1]<=j)
    				dp[i][j] = max(dp[i-1][j],val[i-1]+
    								dp[i-1][j-w[i-1]]);
    			else
    				dp[i][j] = dp[i-1][j];
    			
    		}
    	}
    }
    cout<<dp[n][sum];
}
		


Measured memory_bytes: 82364
#include<iostream>

using namespace std;

int main(){
    int N,Y;
    int aa = -1, bb = -1, cc = -1;
    cin >> N >> Y;
    for (int i = 0; i <= N;i++){
        for (int j = 0; j + i <= N;j++){
            int c = N - (i + j);
            int total = 10000 * i + 5000 * j + 1000 * c;
            if (total == Y)
            {
                aa = i;
                bb = j;
                cc = c;
            }
        }
    }
    cout << aa << " " << bb << " " << cc << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stdlib.h>
#include <math.h>
#include <numeric>

int main() {
	int n;

	std::cin >> n;

	std::string s;

	std::cin >> s;

	int black = 0;
	int white = 0;

	for (size_t i = 0; i < s.length(); i++)
	{
		if (s[i] == '.') {
			white++;
		}
	}

	int min = white;

	for (size_t i = 0; i < s.length(); i++)
	{
		if (s[i] == '#') {
			black++;
		}
		if (s[i] == '.') {
			white--;
		}

		min = std::min(min, white + black);
	}

	std::cout << min << std::endl;
	return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
using ld = long double;
const ll ATCODER_AMARI = 1000000007; //10^9 + 7
const ll INF = 10000000000000;

//階乗関数　ATCODER_AMARIに注意
ll factorial(ll k){
  ll sum = 1;
  for(int i = 1 ; i < k + 1; i++) {
    sum *= i;
    //sum = sum % ATCODER_AMARI;
  }
  return sum;
}

int main() {
  char in2;
  cin >> in2;
  int in = in2;
  //cout << in << endl;
  if(in >= 65 && in <= 90) {
    cout << 'A' << endl;
  }
  else{
    cout << 'a' << endl;
  }
}



Measured memory_bytes: 3632
/// IN THE NAME OF GUITAR
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long int ll;
typedef pair<ll, ll> pll;

#define sz(x)                       (ll) x.size()
#define all(x)                      (x).begin(),(x).end()
#define F                           first
#define S                           second
#define lc                          id << 1
#define rc                          lc | 1

ll Pow(ll a, ll b, ll md, ll ans = 1) {
    for (; b; b >>= 1, a = a * a % md)
        if (b & 1)
            ans = ans * a % md;
    return ans % md;
}
 
const ll MAXN = 1e4 + 20;
const ll INF = 1e18;
const ll MOD = 1e9 + 7;
const ll MAXX = 5e3;
ll dp[MAXN], pd[2][MAXN + 1], X[MAXN], n, ridi = 0;
vector<ll> adj[MAXN];

void DFS(ll v) {
	dp[v] = INF;
	for (ll u : adj[v]) {
		DFS(u);
	}
	for (ll i = 1; i <= X[v]; i++) pd[0][i] = INF;
	pd[0][0] = 0;
	for (ll i = 1; i <= sz(adj[v]); i++) {
		ll u = adj[v][i - 1];
		for (ll j = 0; j <= X[v]; j++) {
			pd[i & 1][j] = INF;
			if (j - dp[u] >= 0) pd[i & 1][j] = min(pd[i & 1][j], pd[1 ^ (i & 1)][j - dp[u]] + X[u]);
			if (j - X[u] >= 0) pd[i & 1][j] = min(pd[i & 1][j], pd[1 ^ (i & 1)][j - X[u]] + dp[u]);
		}
	}
	for (ll i = 0; i <= X[v]; i++) {
		dp[v] = min(dp[v], pd[sz(adj[v]) & 1][i]);
	}
	if (dp[v] >= INF / 10) ridi = 1;
}

int main() {
	scanf("%lld", &n);
	for (ll i = 2; i <= n; i++) {
		ll p; scanf("%lld", &p);
		adj[p].push_back(i);
	}
	for (ll i = 1; i <= n; i++) scanf("%lld", &X[i]);
	DFS(1);
	if (ridi) printf("IMPOSSIBLE\n");
	else printf("POSSIBLE\n");
    return 0;
}
 

Measured memory_bytes: 4072
#include <cstdio>

using namespace std;

int N;
int p[100010];
int main() {
  scanf("%d", &N);
  for(int i=0;i<N;++i)
    scanf("%d", &p[i]);
  int ans=0;
  for(int i=0;i<N;++i) {
    if (p[i]==i+1) {
      if (i!=N-1&& p[i+1]==i+2) {
        ans++;
        i++;
      } else {
        ans++;
      }
    }
  }
  printf("%d\n", ans);
  return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int N; cin >> N;
    for (int i = 0; i < N; i++) {
        int a; cin >> a;
        if (a % 2) {
            cout << "first" << endl;
            return 0;
        }
    }
    cout << "second" << endl;
    return 0;
}

Measured memory_bytes: 256
package main

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

var scanner = bufio.NewScanner(os.Stdin)


func nextInt() int {
	scanner.Scan()
	i, err := strconv.Atoi(scanner.Text())
	if err != nil {
		panic(err)
	}
	return i
}

func getMax(ints ...int) int {
	var max int
	max = ints[0]
	for _, v := range ints {
		if max < v {
			max = v
		}
	}
	return max
}

func getMin(ints ...int) int {
	var min int
	min = ints[0]
	for _, v := range ints {
		if min > v {
			min = v
		}
	}
	return min
}
func main() {
	scanner.Split(bufio.ScanWords)
	a := nextInt()
	b := nextInt()
	c := nextInt()
	fmt.Printf("%d %d\n", getMin(a, b, c), getMax(a, b, c))
}


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

using namespace std;

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

    if(s[0]==s[1]||s[1]==s[2]||s[2]==s[3]){
        cout <<"Bad" <<endl;

    }
    else{
        cout <<"Good" <<endl;
    }

}


Measured memory_bytes: 256
def main():
    N = int(input())
    A = [int(n) for n in input().split()]
    dic = [0]*(N+1)
    for a in A:
        dic[a]+=1
    S = 0
    for i in range(1,N+1):
        S += dic[i] * (dic[i]-1) // 2
    for a in A:
        print(S - dic[a] * (dic[a]-1) // 2 + (dic[a]-1) * (dic[a]-2) // 2)
main()

Measured memory_bytes: 83188
#include <algorithm>
#include <cmath>
#include <climits>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <cassert>
#include <functional>

using namespace std;

#define LOG(...) printf(__VA_ARGS__)
//#define LOG(...)
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define RSORT(c) sort((c).rbegin(),(c).rend())
#define CLR(a) memset((a), 0 ,sizeof(a))

typedef long long ll;
typedef unsigned long long ull;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

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

struct UnionFind {
	vector<int> v;
	UnionFind(int n) : v(n) { for (int i = 0; i < n; i++) v[i] = i; }
	int  find(int x) { return v[x] == x ? x : v[x] = find(v[x]); }
	void unite(int x, int y) { v[find(x)] = find(y); }
};

int main() {
	int w, d;
	while (cin >> w >> d, w) {
		vi vw(w);
		vi vd(d);
		REP(i, w)
			cin >> vw[i];
		REP(i, d)
			cin >> vd[i];
		int ans = 0;
		FOR(i, 1, 21) {
			re:
			REP(j, vw.size()) {
				REP(k, vd.size()) {
					if (vw[j]==vd[k]) {
						ans += vw[j];
						vw.erase(vw.begin() + j);
						vd.erase(vd.begin() + k);
						goto re;
					}
				}
			}
		}
		REP(i, vw.size()) {
			ans += vw[i];
		}
		REP(i,vd.size()) {
			ans += vd[i];
		}
		cout << ans << endl;
	}
}

Measured memory_bytes: 3032
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin() , v.end()
#define REP(i, x, n) for(int i = x; i < n; i++)


int main(){
    int n, k, rel = 1; cin >> n >> k;
    rep(i, n){
        rel = min(rel * 2, rel + k);
    }
    cout << rel << endl;
}

Measured memory_bytes: 256
import Data.List
main :: IO ()
main = do
    n <- read <$> getLine
    xs <- map read . words <$> getLine
    print $ solve xs n
    return ()
solve :: [Int] -> Int -> Int
solve as n = sum . map (abs . subtract c) $ bs
    where   
        bs = sort $ zipWith (\l r -> l - r) as [1..]
        c = bs !! (n `div` 2)

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

using namespace std;

typedef unsigned int ui;
typedef long long ll;
typedef unsigned long long ull;

constexpr int MAXN = 2999;

double dp[MAXN + 2];

int main() {
	int N;
	cin >> N;
	dp[0] = 1;
	for(int i = 0; i < N; i++) {
		double p;
		cin >> p;
		for(int j = i + 1; j >= 0; j--)
			dp[j] = dp[j] * (1 - p) + dp[j - 1] * p;
	}
	double ans = 0;
	for(int i = (N + 1) / 2; i <= N; i++)
		ans += dp[i];
	cout << setprecision(9) << ans << endl;
}


Measured memory_bytes: 256
from collections import Counter

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

C = Counter(A)
C = sorted(C.items())

cc = []
for a, b in C:
    cc.append([a, b])
C = cc

M = len(C)

left = 0
right = M - 1

while True:
    if C[left][1] < 2:
        p_left = left
        for left in range(p_left, M):
            if C[left][1] > 1:
                break

    if C[right][1] < 2:
        p_right = M - right - 1
        for right in range(M):
            if C[M - right - 1][1] > 1:
                break

        right = M - right - 1

    if C[left][1] <= 1 and C[right][1] <= 1:
        break

    if left == right:
        if C[left][1] >= 3:
            C[left][1] -= 2
        else:
            f = 0
            C[left][1] -= 1
            for i in range(left + 1, M):
                if C[i][1] > 0:
                    C[i][1] -= 1
                    f = 1
                    break

            if f == 0:
                for i in range(0, left):
                    if C[i][1] > 0:
                        C[i][1] -= 1

    else:
        C[left][1] -= 1
        C[right][1] -= 1


ans = 0
for a, b in C:
    ans += b

print(ans)


Measured memory_bytes: 29640
#include <bits/stdc++.h>
#define MOD 1000000007
using namespace std;

#define rep(i, a, b) for(int i = (a); i < int(b); ++i)
#define rrep(i, a, b) for(int i = (a) - 1; i >= int(b); --i)
#define trav(it, v) for(typeof((v).begin()) it = (v).begin(); it != (v).end(); ++it)
#define all(v) (v).begin(), (v).end()
#define what_is(x) cerr << #x << " is " << x << endl;

typedef double fl;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;

ll c[200005], w[200005];
ll colorWeight[200005];
ll colorWeight2[200005];
ll colorCount[200005];
ll minWeight;

ll powerMod(ll a, ll x){
	if(x == 0)
		return 1;
	if(x%2)
		return (a*powerMod((a*a)%MOD, x/2))%MOD;
	return (powerMod((a*a)%MOD, x/2));
}

ll inv(ll a){
	return powerMod(a, MOD-2);
}

ll invfac[200005];
ll fac[200005];

int main(){
	invfac[0]=1;
	fac[0]=1;
	rep(i,1,200003){
		fac[i]=(fac[i-1]*i)%MOD;
		invfac[i]=(invfac[i-1]*inv(i))%MOD;
		assert((fac[i]*invfac[i])%MOD == 1);
	}
	ll N, X, Y;
	scanf("%lld%lld%lld", &N, &X, &Y);
	assert(N <= 200000);
	assert(X <= 1000000000);
	assert(Y <= 1000000000);
	rep(i,0,N+1){
		colorWeight[i]=1050000000;
		minWeight = 1050000000;
		assert(colorWeight[i] > X && colorWeight[i] > Y);
	}
	assert(minWeight > X && minWeight > Y);
	int minColor=-1;
	rep(i,0,N){
		scanf("%lld%lld", c+i, w+i);
		assert(c[i] <= N);
		assert(c[i] >= 1);
		assert(w[i] <= 1000000000);
		assert(w[i] >= 1);
		colorWeight[c[i]] = min(colorWeight[c[i]], w[i]);
		if(w[i] < minWeight){
			minWeight = min(minWeight, w[i]);
			minColor = c[i];
		}
	}
	rep(i,0,N+1){
		colorWeight2[i]=colorWeight[i];
	}
	sort(colorWeight2, colorWeight2+(N+1));
	int minWeight2 = colorWeight2[1];
	int movable=0;
	rep(i,0,N){
		int tw = minWeight;
		if(c[i] == minColor)
			tw = minWeight2;
		if(w[i]+colorWeight[c[i]] <= X || w[i]+tw <= Y){
			if(colorWeight[c[i]]+minWeight <= Y){
				++colorCount[c[i]];
				++movable;
			}
		}
	}
	ll ans=fac[movable];
	rep(i,0,N+1){
		if(!colorCount[i])
			continue;
		ans = (ans*invfac[colorCount[i]])%MOD;
	}
	assert(ans >= 0 && ans < MOD);
	sort(colorWeight, colorWeight+(N+1));
	if(colorWeight[0]+colorWeight[1] > Y)
		cout << "1" << endl;
	else
		cout << ans << endl;
}

Measured memory_bytes: 11136
#include <iostream>
#include <algorithm>
using namespace std;
int main(){
  int sum=0;
  int ans=0;
  int a,b,c,x,y;
  cin >> a >> b >>c >>x >> y;
  int n=(a+b)/2;
  int d=min(x,y);
  if(x>y){
    ans+=(x*c*2);
  }
  else{
    ans+=(y*c*2);
  }
if(n>c){
  sum+=(d*c*2);
  x-=d;y-=d;
  sum+=((x*a)+(y*b));
  sum=min(ans,sum);
}
else{
  sum+=(a*x);
  sum+=(b*y);
  sum=min(ans,sum);
}
cout << sum << endl;
}


Measured memory_bytes: 256
//
//  CPlibrary
//
//  Created by Tanmay Singh on 3/03/2020.
// INDIAN INSTITUTE OF TECHNOLOGY (BHU) , VARANASI
//  Copyright © 2020 Tanmay Singh. All rights reserved.
//#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
//#pragma GCC optimization ("unroll-loops")
 
#include <algorithm>
#include <bitset>
#include <cassert>
#include <chrono>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <climits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <ratio>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
 
#define FAST(); ios_base::sync_with_stdio(false);cin.tie(NULL);
#define endl "\n"
#define mod 1000000007
typedef long long int  bigint ;
typedef std::vector< int > vi;
typedef std::vector< long long int > vll;
typedef std::vector< vi > vvi;
 
using namespace std;

int main(){
    FAST() ;
    int N ; cin >> N ;
    bigint arr[100] ;
    arr[0] = 2 ; arr[1] = 1 ;
    for( int i = 2 ; i <= N ; i++ )
        arr[i] = arr[i-1] + arr[i-2] ;
    cout << arr[N] << endl ;
    return 0 ;
}


Measured memory_bytes: 256
#include<queue>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<iostream>
#include<algorithm>
#define ll long long
#define inf 1000000000LL
#define mod 1000000007
using namespace std;
int read()
{
    int x=0,f=1;
    char ch=getchar();
    while(ch<'0'||ch>'9')
    {
        if(ch=='-')f=-1;
        ch=getchar();
    }
    while(ch>='0'&&ch<='9')
    {
        x=x*10+ch-'0';
        ch=getchar();
    }
    return x*f;
}
const int N=305;
ll dp[105][N][105],w[N];
int v[N];
int main()
{
   // while(true)
    {
        int n=read(),V=read();
        for(int i=1;i<=n;i++){
            w[i]=read();v[i]=read();
            if(i>1){
                w[i]=w[i]-w[1];
            }
        }
        memset(dp,0,sizeof(dp));
        int w1=w[1];
        w[1]=0;
        for(int i=1;i<=n;i++){
            for(int j=0;j<=300;j++){
                for(int k=1;k<=n;k++){
                    if(j>=w[i])
                        dp[i][j][k]=max(dp[i-1][j][k],dp[i-1][j-w[i]][k-1]+v[i]);
                    else dp[i][j][k]=dp[i-1][j][k];
                }
            }
        }
        ll ans=0;
        for(ll i=0;i<=300;i++){
            for(ll j=0;j<=n;j++){
                if(j*w1+i<=V){
                    ans=max(ans,dp[n][i][j]);
                }
            }
        }
        printf("%I64d\n",ans);
    }
    return 0;
}


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

#define rep(i,n) for(int i=0;i<(n);++i)
#define reps(i,n) for(int i=1;i<=(n);++i)
#define repr(i,n) for(int i=(n);i>=0;--i)
#define int long long
#define itn int
#define pb push_back
#define m_p make_pair
#define m_t meke_tuple
#define p_p(a,b) pb(m_p(a,b))
#define all(a) a.begin(),a.end()
#define SORT(a) sort(all(a))
#define RSORT(a) sort(all(a));reverse(all(a))
#define UNIQUE(a) a.erase(unique(all(a)),a.end())
#define SZ(a) (ll)(a.size())
#define ENDL cout<<endl
#define debg(a) cout<<#a<<" "<<a<<endl;
#define call(a) for(auto i:a)cout<<i<<" ";cout<<endl
#define show(a) rep(ghf,SZ(a)){rep(kjh,SZ(a[ghf])){cout<<(a[ghf][kjh]<10?" ":"")<<a[ghf][kjh]<<" ";}ENDL;}
#define out(a) cout<<(a)<<endl
#define fi first
#define se second
#define Vec vector
#define P pair
typedef long long ll;
typedef string str;
typedef vector<ll> V;
typedef pair<ll,ll> Pi;
typedef vector<Pi> VP;
const long long INF = 1LL<<60;
const long long MOD = 1e9+7;
int gcd(int a,int b){if(b==0)return a;return gcd(b,a%b);}
int lcm(int a,int b){return a/gcd(a,b)*b;}
int max(int a,int b){if(a>b)return a; return b;}
int min(int a,int b){if(a>b)return b; return a;}
void Yes(){cout<<"Yes"<<endl;}
void No(){cout<<"No"<<endl;}
void YN(bool b){cout<<(b?"Yes":"No")<<endl;}
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>bool chmin(T &a,const T &b){if(a>b){a=b;return true;}return false;}

signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  int n,k;
  cin>>n>>k;
  V t(n),d(n);
  rep(i,n)cin>>t[i]>>d[i],t[i]--;
  VP dt(n);
  rep(i,n)dt[i]=m_p(d[i],t[i]);
  RSORT(dt);
  
  int sum=0;
  set<ll> kinds;
  priority_queue<ll,Vec<ll>,greater<ll>> que;
  rep(i,k){
    sum+=dt[i].fi;
    //debg(dt[i].fi);
    if(kinds.find(dt[i].se)!=kinds.end()){
      que.push(dt[i].fi);
      //cout<<"same"<<endl;
    }
    kinds.insert(dt[i].se);
  }
  int ans=sum+SZ(kinds)*SZ(kinds);
  for(int i=k;i<n;++i){
    if(que.empty())break;
    if(kinds.find(dt[i].se)==kinds.end()){
      //cout<<"updt"<<endl;
      sum-=que.top();
      que.pop();
      sum+=dt[i].fi;
      kinds.insert(dt[i].se);
    }
    ll tmp=sum+SZ(kinds)*SZ(kinds);
    //debg(ans);debg(tmp)
    chmax(ans,tmp);
  }
  out(ans);
  
  
  return 0;
}



Measured memory_bytes: 6780
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using u64 = unsigned long long;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

int main() {
    for (int i = 0; i < 5; ++i) {
        int x;
        cin >> x;
        if(!x) cout << i+1 << "\n";
    }
    return 0;
}

Measured memory_bytes: 3564
#include <bits/stdc++.h>
using namespace std;
 
long NOD(long a, long b){
    while (a != b){
        if (a > b){
            a -= b;
        } else {
            b -= a;
        }
    }
    return a;
}
 
long NOK(long a, long b){
    return abs(a * b)/NOD(a, b);
}
 
int main(){
    long a, b;
    cin >> a >> b;
    cout << NOK(a, b);
    return 0;
}

Measured memory_bytes: 256
n = int(input())
b_list = list(map(int,input().split()))
b_list.append(b_list[-1])
a_list = b_list[:]

for count in range(1, n):
    if a_list[count] > b_list[count - 1]:
        a_list[count] = b_list[count - 1]

print(sum(a_list))


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

int main(void) {
    vector<uint64_t> A(102,0);
    vector<vector<uint64_t>> B(4,vector<uint64_t>(4,0));
    uint64_t N;
    uint64_t a,b;
    string output = "No\n";
    for(int i=1;i<=3;i++) {
        for (int j=1;j<=3;j++) {
            cin >> a;
            A[a]=(i<<2)|j;
        }
    }
    
    cin >> N;
    for(int i=0;i<N;i++) {
        cin >> b;
        if(A[b]) {
            B[(A[b] & 0xC) >> 2][A[b] & 0x3] = 1;
        }
    }

    for(int i=1;i<=3;i++) {
        if(B[i][1] && B[i][2] && B[i][3]) output = "Yes\n";
    }
    for(int i=1;i<=3;i++) {
        if(B[1][i] && B[2][i] && B[3][i]) output = "Yes\n";
    }
    if(B[1][1] && B[2][2] && B[3][3]) output = "Yes\n";
    if(B[3][1] && B[2][2] && B[1][3]) output = "Yes\n";

    cout << output;
    return 0;
}


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

#define watch(x) cerr << (#x) << ": " << (x) << endl

int numABs(string s) {
    int ret = 0;
    int l = s.length();
    for(int i = 1; i < l; ++i) {
        if(s[i] == 'B' && s[i-1] == 'A')
            ret++;
    }
    return ret;
}

int32_t main() {

    int n; cin >> n;
    vector<string> ss(n);
    for(int i = 0; i < n; ++i) cin >> ss[i];

    int ans = 0;
    for(string s : ss) {
        ans += numABs(s);
    }

    int startsB = 0, endsA = 0, both = 0;
    for(string s : ss) {
        if(s[0] == 'B' && s.back() == 'A') both++;
        else if(s[0] == 'B') startsB++;
        else if(s.back() == 'A') endsA++;
    }

    if(both) {
        ans += both-1;
        if(endsA) {
            endsA--;
            ans++;
        }
        if(startsB) {
            startsB--;
            ans++;
        }
    }
    
    ans += min(startsB, endsA);

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


Measured memory_bytes: 768
from sys import stdin

#l = list(map(int, stdin.readline().rstrip().split()))
a,b,c,d,e = map(int, stdin.readline().rstrip().split())
#S = [list(map(int, stdin.readline().rstrip().split())) for _ in range(h)]#hの定義を忘れずに

if a==0:
  print('1')
elif b==0:
  print('2')
elif c==0:
  print('3')
elif d==0:
  print('4')
elif e==0:
  print('5')

Measured memory_bytes: 9056
//Author : pakhandi
//
using namespace std;

#include<bits/stdc++.h>

#define wl(n) while(n--)
#define fl(i,a,b) for(i=a; i<b; i++)
#define rev(i,a,b) for(i=a; i>=b; i--)

#define si(n) scanf("%d", &n)
#define sll(l) scanf("%lld",&l)
#define ss(s) scanf("%s", s)
#define sc(c) scanf("%c", &c)
#define sd(f) scanf("%lf", &f)

#define pi(n) printf("%d\n", n)
#define pll(l) printf("%lld\n", l)
#define ps(s) printf("%s\n", s)
#define pc(c) printf("%c\n", c)
#define pd(f) printf("%lf\n", f)

#define debug(x) cout<<"\n#("<<x<<")#\n"
#define nline printf("\n")

#define mem(a,i) memset(a,i,sizeof(a))

#define MOD 1000000007
#define ll long long int
#define u64 unsigned long long int

#define mclr(strn) strn.clear()
#define ignr cin.ignore()
#define PB push_back
#define SZ size
#define MP make_pair
#define fi first
#define sec second

int main()
{
	int i, j;

	string str1;

	cin>>str1;

	int limit = str1.SZ();

	int l = -1, r = -1;

	fl(i,1,limit)
	{
		if(str1[i] == str1[i - 1])
		{
			l = i - 1;
			r = i;
			break;
		}
	}

	if(l != -1 && r != -1)
	{
		cout<<l + 1<<" "<<r + 1; return 0;
	}


	fl(i,2,limit)
	{
		if(str1[i] == str1[i - 2])
		{
			l = i - 2 + 1;
			r = i + 1;
			break;
		}
	}

	cout<<l<<" "<<r;

	return 0;
}
/*
	Powered by Buggy Plugin
*/


Measured memory_bytes: 512
#[allow(unused_imports)]
use std::char::*;
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;

#[allow(unused_macros)]
macro_rules! debug {($($a:expr),*) => {println!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);}}
#[allow(unused_macros)]
macro_rules! input { ( source = $ s : expr , $ ( $ r : tt ) * ) => { let mut iter = $ s . split_whitespace ( ) ; let mut next = || { iter . next ( ) . unwrap ( ) } ; input_inner ! { next , $ ( $ r ) * } } ; ( $ ( $ r : tt ) * ) => { let stdin = std :: io :: stdin ( ) ; let mut bytes = std :: io :: Read :: bytes ( std :: io :: BufReader :: new ( stdin . lock ( ) ) ) ; let mut next = move || -> String { bytes . by_ref ( ) . map ( | r | r . unwrap ( ) as char ) . skip_while ( | c | c . is_whitespace ( ) ) . take_while ( | c |! c . is_whitespace ( ) ) . collect ( ) } ; input_inner ! { next , $ ( $ r ) * } } ; }
#[allow(unused_macros)]
macro_rules! input_inner { ( $ next : expr ) => { } ; ( $ next : expr , ) => { } ; ( $ next : expr , $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let $ var = read_value ! ( $ next , $ t ) ; input_inner ! { $ next $ ( $ r ) * } } ; }
#[allow(unused_macros)]
macro_rules! read_value { ( $ next : expr , ( $ ( $ t : tt ) ,* ) ) => { ( $ ( read_value ! ( $ next , $ t ) ) ,* ) } ; ( $ next : expr , [ $ t : tt ; $ len : expr ] ) => { ( 0 ..$ len ) . map ( | _ | read_value ! ( $ next , $ t ) ) . collect ::< Vec < _ >> ( ) } ; ( $ next : expr , chars ) => { read_value ! ( $ next , String ) . chars ( ) . collect ::< Vec < char >> ( ) } ; ( $ next : expr , usize1 ) => { read_value ! ( $ next , usize ) - 1 } ; ( $ next : expr , $ t : ty ) => { $ next ( ) . parse ::<$ t > ( ) . expect ( "Parse error" ) } ; }

#[derive(PartialEq, PartialOrd)]
pub struct Total<T>(pub T);
impl<T: PartialEq> Eq for Total<T> {}
impl<T: PartialOrd> Ord for Total<T> { fn cmp(&self, other: &Total<T>) -> std::cmp::Ordering { self.0.partial_cmp(&other.0).unwrap() }}

#[allow(dead_code)]
const MAX:usize = 100006;
#[allow(dead_code)]
const INF_U32:u32 = 1 << 31;
#[allow(dead_code)]
const INF_I32:i32 = 1 << 30;
#[allow(dead_code)]
const INF_U64:u64 = 1 << 63;
#[allow(dead_code)]
const INF_I64:i64 = 1 << 62;

fn func(x:i32) -> i32 {
    if x/10==0 {return x;}
    x%10 + func(x/10)
}

fn main() {
    input!{n:i32,a:i32,b:i32};

    let mut ans:i32 = 0;
    for i in 1..n+1 {
        let sum = func(i as i32);
        if a <= sum && sum <= b {
            ans += i;
        }
    }
    println!("{}", ans);

}

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

int total(int x){
  int sum=0;
  while(x>0){
    sum+= x%10;
    x/=10;
  }
  return sum;
}


int main(){
  int n;
  cin >> n;
  if(n%total(n)==0){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
  
}


Measured memory_bytes: 256