akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
using namespace std;

int n, k, mx, a[55];
vector<int> vt;

void f(int p) {
	int i, s = 0;
	if(p<0) return;
	sort(vt.begin(), vt.end());
	for(i=0; i<vt.size(); i++) {
		if(i<p && vt[i]<0) continue;
		s += vt[i];
	}
	mx = max(mx, s);
}

int main() {
	int i, j, c;
	cin >> n >> k;
	for(i=0; i<n; i++) scanf("%d", &a[i]);
	for(i=0; i<=n; i++) {
		vt.clear();
		for(j=0; j<i; j++) vt.push_back(a[j]);
		f(k - vt.size());
		for(c=0, j=n-1; c<n-i; c++, j--) {
			vt.push_back(a[j]);
			f(k - vt.size());
		}
	}
	cout << mx;
	return 0;
}


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

int main(){
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	ll n,k;
	cin >> n;
	vector<vector<int>> v(n,vector<int>(3));
	for(int i=0;i<n;i++){
		for(int j=0;j<3;j++){
			cin >> v[i][j];
		}
	}
	vector<vector<int>> dp(n,vector<int>(3));
	dp[0][0] = v[0][0]; 
	dp[0][1] = v[0][1]; 
	dp[0][2] = v[0][2];
	for(int i=1;i<n;i++){
		dp[i][0] = v[i][0] + max(dp[i-1][1],dp[i-1][2]);
		dp[i][2] = v[i][2] + max(dp[i-1][1],dp[i-1][0]);
		dp[i][1] = v[i][1] + max(dp[i-1][0],dp[i-1][2]);
	} 
	cout << max({dp[n-1][0],dp[n-1][1],dp[n-1][2]});
	return 0;
}

Measured memory_bytes: 11264
x,y = map(int,input().split())
l = list(map(int,input().split()))

if len(l) == 0 :
    print(x)
    exit()

for i in range(200):
    if not((x - i) in l):
        print(x - i)
        exit()

    elif not((x + i) in l):
        print(x + i)
        exit()


Measured memory_bytes: 9188
#include<bits/stdc++.h>
using namespace std;
#define rep(i,j,n) for(int i=(int)(j);i<(int)(n);i++)
#define REP(i,j,n) for(int i=(int)(j);i<=(int)(n);i++)
#define MOD 1000000007
#define int long long
#define ALL(a) (a).begin(),(a).end()
#define vi vector<int>
#define vii vector<vi>
#define pii pair<int,int>
#define priq priority_queue<int>
#define disup(A,key) distance(A.begin(),upper_bound(ALL(A),(int)(key)))
#define dislow(A,key) distance(A.begin(),lower_bound(ALL(A),(int)(key)))
signed main(){
  int N;
  cin>>N;
  string ans="AGC";
  if(N<1200)
    ans="ABC";
  else if(N<2800)
    ans="ARC";
  cout<<ans;
  }


Measured memory_bytes: 256
package main

import (
	"fmt"
)

func scanNums(len int) (nums []int) {
	var num int
	for i := 0; i < len; i++ {
		fmt.Scan(&num)
		nums = append(nums, num)
	}
	return
}

func gcd(a, b int) int {
	if b == 0 {
		return a
	}
	return gcd(b, a%b)
}

func main() {
	var N int
	fmt.Scan(&N)
	nums := scanNums(N)

	ans := nums[0]
	for i := 1; i < len(nums); i++ {
		ans = gcd(ans, nums[i])
	}

	fmt.Println(ans)
	return
}

Measured memory_bytes: 5504
//Wrong Coding:
//j 1 to i not m
#include<cstdio>
#include<cstdlib>
#include<cstring>
#define llong long long
using namespace std;

const int N = 2000;
const int P = 1e9+7;
llong dp[N+3][N+3];
llong fact[5000003],finv[5000003];
int n,m;

llong quickpow(llong x,llong y)
{
	llong cur = x,ret = 1ll;
	for(int i=0; y; i++)
	{
		if(y&(1ll<<i)) {y-=(1ll<<i); ret = ret*cur%P;}
		cur = cur*cur%P;
	}
	return ret;
}

llong comb(llong x,llong y) {return x<0 || y<0 || x<y ? 0ll : fact[x]*finv[y]%P*finv[x-y]%P;}

int main()
{
	fact[0] = 1ll; for(int i=1; i<=5000000; i++) fact[i] = fact[i-1]*i%P;
	finv[5000000] = quickpow(fact[5000000],P-2); for(int i=5000000-1; i>=0; i--) finv[i] = finv[i+1]*(i+1)%P;
	scanf("%d%d",&n,&m);
	if(m==1) {printf("1"); return 0;}
	dp[0][0] = 1ll;
	for(int i=1; i<=n; i++)
	{
		dp[i][0] = 1ll;
		for(int j=1; j<=i; j++)
		{
			dp[i][j] = dp[i-1][j];
			dp[i][j] += comb((n-i)+(n-(j-1))*(m-1)-1,m-2)*dp[i][j-1]%P;
			dp[i][j] %= P;
		}
	}
	llong ans = dp[n][n]*fact[n]%P;
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 109568
#include <bits/stdc++.h>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

const int B=800;

struct query{
	int l,r;
	int id;
	query(){}
	query(int l1,int r1,int ii){
		l=l1;
		r=r1;
		id=ii;
	}
	bool operator<(const query &q)const{
		if(l/B==q.l/B){
			return r<q.r;
		}
		return l/B<q.l/B;
	}
};

int n,q;
int c[500005];
int cnt[500005];
int cur=0;
int ans[500005];
query qq[500005];

void add(int pos){
	cnt[c[pos]]++;
	if(cnt[c[pos]]==1)cur++;
}

void dec(int pos){
	cnt[c[pos]]--;
	if(cnt[c[pos]]==0)cur--;
}

int main(void){
	scanf("%d%d",&n,&q);
	for(int i=0;i<n;i++){
		scanf("%d",&c[i]);
	}
	for(int i=0;i<q;i++){
		scanf("%d%d",&qq[i].l,&qq[i].r);
		qq[i].l--;
		qq[i].id=i;
	}
	sort(qq,qq+q);
	int l=0,r=0;
	for(int i=0;i<q;i++){
		while(qq[i].l<l){
			l--;
			add(l);
		}
		while(qq[i].r>r){
			add(r);
			r++;
		}
		while(qq[i].l>l){
			dec(l);
			l++;
		}
		while(qq[i].r<r){
			r--;
			dec(r);
		}
		ans[qq[i].id]=cur;
	}
	for(int i=0;i<q;i++){
		printf("%d\n",ans[i]);
	}
	return 0;
}


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

int main() {
  int N;
  cin >> N;
  const ll max = pow(10, 18);

  ll ans = 1;
  rep(i, N) {
    ll a;
    cin >> a;
    if (a == 0) {
      ans = 0;
      break;
    }
    if (ans == -1) continue;
    if (a > max / ans) {
      ans = -1;
      continue;
    }
    ans *= a;
  }

  cout << ans << endl;
}


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

using namespace std;

using ll = long long;

const ll MOD = 1000000007;

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

int main()
{
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    string s;
    cin >> s;
    if (s == "ABC")
    {
        cout << "ARC" << endl;
    }
    else
    {
        cout << "ABC" << endl;
    }
}


Measured memory_bytes: 3652
#pragma GCC optimize("O3")

#include "bits/stdc++.h"
#include "ext/pb_ds/tree_policy.hpp"
#include "ext/pb_ds/assoc_container.hpp"
#include "ext/rope"

using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;

typedef long long ll;
typedef pair<int, int> pii;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define F0R(i, a) for(int i = 0; i < (a); ++i)
#define pb push_back
#define sz size
#define f first
#define s second

template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

struct custom_hash 
{
    static uint64_t splitmix64(uint64_t x) 
    {
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const 
    {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};

int main()
{
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n, a, b, c, d;
    string s;
    cin >> n >> a >> b >> c >> d >> s;
    a--; b--; c--; d--;
    //bounds of region, A and B flip in reg
    vector<pair<pair<int, int>, bool>> regs;
    int stcnt = 0;
    int dtcnt = 0;
    F0R(i, n)
    {
        int stpos = i;
        bool flip = false;
        stcnt = 0; dtcnt = 0;
        while(i < s.sz() && stcnt < 2)
        {
            if(s[i] == '#')
            {
                stcnt++;
                dtcnt = 0;
            }
            if(s[i] == '.')
            {
                dtcnt++;
                stcnt = 0;
            }
            if(dtcnt == 3) flip = true;
            i++;
        }
        regs.pb({{stpos, i - 1}, flip});
        i--;
    }
    bool sTrue = false;
    if(c > d) sTrue = true;
    int al = 0, bl = 0, cl = 0, dl = 0;
    // F0R(i, regs.sz()) cout << regs[i].f.f<< " " << regs[i].f.s << "\n";
    F0R(i, regs.sz())
    {
        if(regs[i].f.f <= a && regs[i].f.s >= a) al = i;
        if(regs[i].f.f <= b && regs[i].f.s >= b) bl = i;
        if(regs[i].f.f <= c && regs[i].f.s >= c) cl = i;
        if(regs[i].f.f <= d && regs[i].f.s >= d) dl = i;
    }
    if(cl != al || bl != dl)
    {
        cout << "No";
        return 0;
    }
    if(sTrue)
    {
        if(!((al == bl) && regs[al].s))
        {
            cout << "No";
            return 0;
        }
        int dt = -1;
        int dcnt = 0; 
        FOR(i, a, min(regs[al].f.s, d + 2))
        {
            if(i >= s.sz()) break;
            if(s[i] == '.') dcnt++;
            if(s[i] == '#') dcnt = 0;
            if(dcnt >= 3) dt = i;
        }
        if(dt == -1 || dt == b)
        {
            cout << "No";
            return 0;
        }
    }
    cout << "Yes";
    return 0;
}

Measured memory_bytes: 592
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <map>
#include <queue>
#include <stack>
#include <vector>
using namespace std;
#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
template<class T> void read(T& x){cin>>x;}
void read(int& x){scanf("%d", &x);}
void read(int64_t& x){scanf("%lld", &x);}
void read(double& x){scanf("%lf", &x);}
template<class T, class U, class... V>
void read(T& x, U& y, V&... z){read(x); read(y, z...);}

int main(){
  int n, q;
  read(n, q);
  string tmpName;
  int tmpTime;
  queue<pair<string, int>> que;
  REP(i, n){
    read(tmpName, tmpTime);
    que.push(make_pair(tmpName, tmpTime));
  }
  pair<string, int> tmp;
  int currentTime = 0;
  while(!que.empty()){
    tmp = que.front(); que.pop();
    if(tmp.second > q){
      currentTime += q;
      tmp.second -= q;
      que.push(tmp);
    } else{
      currentTime += tmp.second;
      cout << tmp.first << " " << currentTime << "\n";
    }
  }
}


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

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

    int c[n],v[n];
    for(int i=0;i<n;i++)
        cin>>v[i];
    for(int i=0;i<n;i++)
        cin>>c[i];

    int max = 0;
    for(int i=0;i<n;i++)
    {
        if(v[i]-c[i]>0)
            max +=v[i]-c[i];
    }

    cout<<max;
}

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

template<typename T>
class Queue {
    T *que;
    T *head, *tail;
    int capacity;
public:
    Queue() {}
    Queue(int capacity):capacity(capacity) {
        que=new T[capacity];
        head=tail=que;
    }
    ~Queue() { delete[] que; }
    void push(T x) { *tail++=x; }
    T front() { return *head; }
    void pop() { head++; }
    size_t size() const { return tail-head; }
    bool empty() const { return head==tail; }
    void clear() { head=tail=que; }
};

int main()
{
    int n; cin>>n;
    vector<vector<int>> g(n);
    for(int i=0; i<n-1; ++i) {
        int a, b; cin>>a>>b;
        --a, --b;
        g[a].push_back(b);
        g[b].push_back(a);
    }

    vector<int> x(n);
    Queue<int> q(n);
    q.push(0); x[0]=1;
    q.push(n-1); x[n-1]=-1;

    while (q.size()) {
        int v=q.front(); q.pop();
        int k=x[v];
        for(int u: g[v]) if (!x[u]) {
            x[u]=k;
            q.push(u);
        }
    }
    int fennec=count(begin(x), end(x), 1);
    int snuke=n-fennec;
    cout<<(fennec>snuke ? "Fennec" : "Snuke")<<endl;
}


Measured memory_bytes: 6528
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define cinf(n,x) for(int i=0;i<(n);i++)cin>>x[i];
#define ft first
#define sc second
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(),(v).end()
#define mod 1000000007
using namespace std;
typedef long long ll;
template<class T> using V=vector<T>;
using Graph = vector<vector<int>>;
using P=pair<ll,ll>;
typedef unsigned long long ull;
typedef long double ldouble;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

const ll INF=1e18;

int main(){
    ll n;
    cin>>n;
    V<ll> a(3*n);
    V<P> b(2*n);
    set<P> s1_used,s2_used,s2_not;
    ll sum1=0,sum2=0;
    rep(i,3*n){
        cin>>a[i];
        if(i>=n){
            b[i-n]=P(a[i],i);
        }else{
            sum1+=a[i];
            s1_used.insert(P(a[i],i));
        }
    }
    sort(all(b));
    rep(i,2*n){
        if(i<n){
            s2_used.insert(b[i]);
            sum2+=b[i].ft;
        }
        else s2_not.insert(b[i]);
    }
    ll ans=sum1-sum2;
    for(ll i=n;i<2*n;i++){
        P p=P(a[i],i);
        if(s2_used.count(p)){
            s2_used.erase(p);
            sum2-=p.ft;
            P pp=*begin(s2_not);
            s2_not.erase(pp);
            s2_used.insert(pp);
            sum2+=pp.ft;
        }else{
            s2_not.erase(p);
        }
        P ppp=*begin(s1_used);
        if(ppp.ft<p.ft){
            s1_used.erase(ppp);
            s1_used.insert(p);
            sum1-=ppp.ft;
            sum1+=p.ft;
        }
        chmax(ans,sum1-sum2);
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 24448
H,W=map(int,input().split())
f=H*W
d=[[0]*f for _ in range(f)]


s=[input() for _  in range(H)]
    
for i in range(H):
    for j in range(W-1): 
        cnt=W*i+j
        d[cnt+1][cnt]=s[i][j]==s[i][j+1]=="."
        d[cnt][cnt+1]=s[i][j]==s[i][j+1]=="."
       
for i in range(H-1):
    for j in range(W): 
        cnt=W*i+j
        d[cnt][cnt+W]=s[i][j]==s[i+1][j]=="."
        d[cnt+W][cnt]=s[i][j]==s[i+1][j]=="."
        
import numpy as np
from scipy.sparse.csgraph import shortest_path, floyd_warshall, dijkstra, bellman_ford, johnson
from scipy.sparse import csr_matrix
csr=np.array(d)


ans=-1
k=shortest_path(csr)
for i in range(f):   
    for q in range(f):
            if k[i][q]>=f+1:k[i][q]=-1

    ans=max(ans,max(k[i]))

print(int(ans))

Measured memory_bytes: 18580
N, K = map(int, input().split())

mod = 10 ** 9 + 7
  
ret = 0
for i in range(K, N + 2) :
  ret += (2 * N - i + 1) * i // 2 - (i - 1) * i // 2 + 1
  ret %= mod
  
print(ret)

Measured memory_bytes: 63588
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>

using namespace std;

bool solve() {
  int c[3][3];
  int a[3], b[3];
  for(int i = 0; i < 3; i++) {
    for(int j = 0; j < 3; j++) {
      cin>>c[i][j];
    }
  }
  for(a[0] = -100; a[0] <= 100; a[0]++) {
    b[0] = c[0][0] - a[0];
    b[1] = c[0][1] - a[0];
    b[2] = c[0][2] - a[0];
    for(a[1] = -100; a[1] <= 100; a[1]++) {
      if(b[0] != c[1][0] - a[1]) continue;
      if(b[1] != c[1][1] - a[1]) continue;
      if(b[2] != c[1][2] - a[1]) continue;
      for(a[2] = -100; a[2] <= 100; a[2]++) {
	if(b[0] != c[2][0] - a[2]) continue;
	if(b[1] != c[2][1] - a[2]) continue;
	if(b[2] != c[2][2] - a[2]) continue;
	return true;
      }
    }
  }
  return false;
}

int main() {
  bool ans = solve();
  if(ans) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 256
a, b = map(int, input().split())


def Base_10_to_n(X, n):
    if (int(X / n)):
        return Base_10_to_n(int(X / n), n) + str(X % n)
    return str(X % n)


a = Base_10_to_n(a, b)
print(len(a))

Measured memory_bytes: 3060
//#include<bits/stdc++.h>
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<string>
#include<numeric>
#include<vector>
#include<set>
#include<map>
#include<unordered_map>
#include<stack>
#include<queue>
#include<list>
using namespace std;

#define INF 100000

int main(){
  long long n;
  cin >> n;
  string s;
  cin >> s;
  long long ch[26];
  for(int i=0;i<26;i++){
    ch[i] = 0;
  }
  for(int i=0;i<n;i++){
    int num = s[i] - 'a';
    ch[num] += 1;
  }
  long long ans = 1;
  for(int i=0;i<26;i++){
    ans *= ch[i]+1;
    ans %= 1000000007;
  }

  cout << (ans-1)%1000000007 << endl;

  return 0;
}


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

int sum[10000];
int main() {

    vector<int> v = {3,5,7,11,13,17,19,23};


    for(int i=0; i<v.size(); i++){
        for(int j=i+1; j<v.size(); j++){
            for(int k=j+1; k<v.size(); k++){
                sum[v[i]*v[j]*v[k]] += 1;
            }
        }
    }
    
    v = {5,7,11};
    
    for(int i=0; i<v.size(); i++){
        sum[27*v[i]] += 1;
    }
    

    for(int i=1; i<300; i++){
        sum[i] += sum[i-1];
    }


    int n;

    cin >> n;

    cout << sum[n] << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ui unsigned int
#define ull unsigned long long
#define db double
#define ld long double
#define pii pair<ll,int>
#define X first
#define Y second
#define mp make_pair
#define pb push_back
#define vi vector<int>
#define vii vector<vi>
#define lb lower_bound
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define per(i,b,a) for(int i=(b);i>=(a);--i)
#define rep0(i,a,b) for(int i=(a);i<(b);++i)
#define fore(i,a) for(int i=0;i<a.size();++i)
#define gc() getchar()
#define ls x<<1,l,m
#define rs x<<1|1,m+1,r
inline int rd()
{
	int x=0;char c=gc();while(!isdigit(c))c=gc();
	while(isdigit(c))x=x*10+c-48,c=gc();return x;
}
const int N=500005,inf=1e9+7;
int n,k,nn,cc,a[N],b[N],d[N],hd[N],t[N],q[N];
priority_queue<int>Q;
struct E{int v,nxt;}e[N*10]; 
inline void add(int u,int v){e[++cc]=(E){v,hd[u]};hd[u]=cc;}
struct seg
{
	int mn[N*4];
	void build(int x,int l,int r){mn[x]=inf;if(l==r)return;int m=l+r>>1;build(ls);build(rs);}
	void upd(int x,int l,int r,int p,int v)
	{
		if(l==r){mn[x]=v;return;}int m=l+r>>1;
		p<=m?upd(ls,p,v):upd(rs,p,v);mn[x]=min(mn[x<<1],mn[x<<1|1]);
	}
	int qry(int x,int l,int r,int tl,int tr)
	{
		if(tl<=l&&r<=tr)return mn[x];int m=l+r>>1;
		return min(tl<=m?qry(ls,tl,tr):inf,tr>m?qry(rs,tl,tr):inf);
	}
}T;
int main()
{
	n=rd();k=rd();
	rep(i,1,n)a[i]=rd(),b[a[i]]=i;
	T.build(1,1,n);
	per(i,n,1)
	{
		int t=T.qry(1,1,n,max(1,b[i]-k+1),b[i]);
		if(t<=n)add(b[i],b[t]),d[b[t]]++;
		t=T.qry(1,1,n,b[i],min(n,b[i]+k-1));
		if(t<=n)add(b[i],b[t]),d[b[t]]++;
		T.upd(1,1,n,b[i],i);
	}
	int cc=0;
	rep(i,1,n)if(!d[i])Q.push(-i);
	while(!Q.empty())
	{
		int x=-Q.top();Q.pop();q[++cc]=x;
		for(int i=hd[x];i;i=e[i].nxt)if(!--d[e[i].v])Q.push(-e[i].v);
	}
	rep(i,1,n)a[q[i]]=i;
	rep(i,1,n)printf("%d\n",a[i]);
	return 0;
} 

Measured memory_bytes: 33664
# include <iostream>
# include <stdint.h>
# include <stdio.h>
# include <math.h>
#include <cstdlib>
# include <algorithm>
# include <string>
using namespace std;


int main(){
    int n;
    double  max =0,sum1=0,sum2 =0,sum3 =0,t;
    int x[1000] ={},y[1000] ={};
    cin >>n;
    for(int i=0;i<n;i++){
        cin >>x[i];
    }
    for(int i=0;i<n;i++){
        cin >>y[i];
    }
    for(int i=0;i<n;i++){
        t = fabs(x[i] - y[i]);
        sum1 += t;
        sum2 += pow(t,2);
        sum3 +=pow(t,3);
        if(t >max) max = t;
    }
    printf("%.7f\n",(double)sum1);
    printf("%.7f\n",pow(sum2,0.5));
    printf("%.7f\n",pow(sum3,0.333333333333333));
    printf("%.7f\n",(double)max);
	return 0;
}



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

int main(){
   int N;
   cin >> N;
   vector<int> x(N);
   for (int i=0; i<N; i++){
      cin >> x.at(i);
   }
   int sum, sum2;
   sum = accumulate(x.begin(), x.end(), 0);
   sum2 = 0;
   for (int i=0; i<N; i++){
      sum2 += pow(x.at(i), 2);
   }

   double ans = sum*1.0/N;
   int ans_c, ans_f;
   ans_c = ceil(ans);
   ans_f = floor(ans);

   //cout << ans_c << " " << ans_f << endl;
   //cout << sum << " " << sum2 << endl;

   if (N*pow(ans_c, 2)-2*ans_c*sum > N*pow(ans_f, 2)-2*ans_f*sum)
      cout << N*pow(ans_f, 2)-2*ans_f*sum+sum2 << endl;
   else
      cout << N*pow(ans_c, 2)-2*ans_c*sum+sum2 << endl;
}



Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <array>
#include <set>
#include <cmath>
#include <string>
#include <queue> 
#include <list>
#include <stack>
#include <unordered_map>
#include <algorithm> 
#include <numeric>  
#include <functional>
#include <cassert>
#include <bitset>
#include <cctype>  
#include <iomanip> 
#include <limits>  
#include <regex>
// std::numeric_limits<int>::max(), min()
// std::setprecision(X)
// std::islower(), std::isupper(), std::tolower, std::toupper
// std::accumulate(m.begin(), m.end(), 0LL);
// std::sort(begin(),end()) // 0, 1, 2, 3 ,4 (default, less);
// std::priority_queue<int, vector<int>, less<int>> que; // 4, 3, 2, 1 (defualt, less) : 
// if ( std::regex_match(S, std::regex("(dream|dreamer|erase|eraser)*")) ) std::cout << "YES" << std::endl;
 
#define rep(i, n) for(int i = 0; i < (int)(n);    i++)
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
typedef long long ll;

ll gcd ( ll a, ll b ) { if ( b == 0 ) return a; else return gcd ( b, a%b ); }
ll lcm ( ll a, ll b ) { return a * b / gcd(a, b); }


int main (void) {
  std::cin.tie(0);  std::ios::sync_with_stdio(false);
  int N, K; std::cin >> N >> K;
  std::vector<bool> D(10, true); rep(i,K) { int d; std::cin >> d; D[d] = false; }

  for(int i=N; i<=10*N; i++) {
    auto S = std::to_string(i);
    bool flag = false;
    for(auto&& s : S) {
      int n = s - '0';
      if ( D[n] == false ) flag = true;
    }
    if ( !flag ) {
      std::cout << i << std::endl;
      return 0;
    }
  }

  return 0;
}


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

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout.precision(12);
    cout.setf(ios_base::fixed, ios_base::floatfield);
    
    int n;
    cin >> n;
    if(n%4==0 || n%4==3){
        int s = n*(n+1)/4;
        int sum = 0;
        int i;
        for(i=1;i<=n;i++){
            sum += i;
            if(sum > s) break;
        }
        int r = sum-s;
        cout << (i-1)*(n-i+1) << endl;
        vector<int> lhs, rhs;
        for(int j=1;j<=n;j++){
            if(j<=i && j!=r) lhs.push_back(j);
            else rhs.push_back(j);
        }
        for(int l:lhs){
            for(int r:rhs){
                cout << l << " " << r << endl;
            }
        }
    }else if(n%4==2){
        cout << n*2 << endl;
        for(int i=1;i<n/2;i++){
            cout << i << " " << i+1 << endl;
            cout << i << " " << n-i << endl;
            cout << n-i+1 << " " << i+1 << endl;
            cout << n-i+1 << " " << n-i << endl;
        }
        cout << n/2 << " " << 1 << endl;
        cout << n/2 << " " << n << endl;
        cout << n/2+1 << " " << 1 << endl;
        cout << n/2+1 << " " << n << endl;        
    }else{
        cout << 2*n-2 << endl;;
        cout << n << " " << 1 << endl;
        cout << n << " " << n-1 << endl;
        for(int i=1;i<n/2;i++){
            cout << i << " " << i+1 << endl;
            cout << i << " " << n-i-1 << endl;
            cout << n-i << " " << i+1 << endl;
            cout << n-i << " " << n-i-1 << endl;            
        }
        cout << n/2 << " " << n << endl;
        cout << n/2+1 << " " << n << endl;
    }
    
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdint>
#include <cassert>
#include <cctype>
#include <algorithm>
#include <vector>
#include <string>

constexpr intmax_t MOD=2011;

intmax_t apply(intmax_t lhs, char op, intmax_t rhs) {
  switch (op) {
  case '+': return (lhs + rhs) % MOD;
  case '-': return ((lhs - rhs) % MOD + MOD) % MOD;
  case '*': return (lhs * rhs) % MOD;
  }
  assert(false);
}

intmax_t modpow(intmax_t base, intmax_t iexp) {
  intmax_t res=1;
  for (intmax_t dbl=base; iexp; iexp>>=1) {
    if (iexp & 1) (res *= dbl) %= MOD;
    (dbl *= dbl) %= MOD;
  }
  return res;
}

intmax_t moddiv(intmax_t num, intmax_t den) {
  intmax_t div=modpow(den, MOD-2);
  return num*div % MOD;
}

intmax_t parse(const std::vector<std::string> &s, size_t &i,
               size_t top, size_t bottom, size_t left, size_t right,
               size_t preced=0, size_t base=-1,
               const std::vector<std::string> &ops={"+-", "*"}) {

  while (base+1 == 0) {
    for (size_t r=top; r<bottom; ++r) {
      if (s[r][i] != '.') {
        base = r;
        break;
      }
    }
    if (base+1 == 0) ++i;
  }
  assert(base+1 != 0);

  if (preced == ops.size()) {
    intmax_t res=114514;
    if (s[base][i] == '(') {
      res = parse(s, i+=2, top, bottom, left, right, 0, base);
      assert(s[base][i] == ')');
      ++i;
    } else if (s[base][i] == '-') {
      if (s[base][i+1] == '-') {
        size_t vl=i, vr=i+1;
        while (s[base][++vr] == '-') {}

        size_t j=vl+1;
        intmax_t numer=parse(s, j, top, base, vl, vr, 0);
        j = vl+1;
        intmax_t denom=parse(s, j, base+1, bottom, vl, vr, 0);
        res = moddiv(numer, denom);
        i = vr;
      } else {
        res = MOD-parse(s, i+=2, top, bottom, left, right, preced, base);
        return res;
      }
    } else if (isdigit(s[base][i])) {
      res = s[base][i]-'0';
      ++i;
    } else {
      assert(false);
    }

    if (i < right && top+1 <= base && isdigit(s[base-1][i])) {
      res = modpow(res, s[base-1][i]-'0');
      ++i;
    }
    ++i;
    return res;
  }

  intmax_t lhs=parse(s, i, top, bottom, left, right, preced+1, base);
  while (i < right) {
    char op=s[base][i];
    if (!std::count(ops[preced].begin(), ops[preced].end(), op)) break;
    intmax_t rhs=parse(s, i+=2, top, bottom, left, right, preced+1, base);
    lhs = apply(lhs, op, rhs);
  }
  return lhs;
}

int testcase_ends() {
  size_t n;
  scanf("%zu", &n);
  if (n == 0) return 1;

  std::vector<std::string> s;
  for (size_t i=0; i<n; ++i) {
    char buf[128];
    scanf("%s", buf);
    s.emplace_back(buf);
  }

  size_t i=0;
  intmax_t res=parse(s, i, 0, s.size(), 0, s[0].length());
  printf("%jd\n", res);
  return 0;
}

int main() {
  while (!testcase_ends()) {}
}



Measured memory_bytes: 2792
#include <iostream>
#include <algorithm>
#include <map>
#include <vector>
#include <string>
#include <functional>
#include <assert.h>
#include <sstream>

using namespace std;

#define rep(i,n) for(int i = 0;i < n;i++)
#define all(a) a.begin(),a.end()

int toInt(string s) {
	stringstream ss;
	ss << s;
	int num;
	ss >> num;
	return num;
}
string toStr(int num) {
	stringstream ss;
	ss << num;
	return ss.str();
}

int main() {

	string a; int size;
	while (cin >> a >> size ) {
		if (a == "0" && size == 0)break;
		vector<string> table;
		
		for (int i = 0; i <= 20; i++) {
			while (a.size() < size) {
				a = "0" + a;
			}
			table.push_back(a);
			sort(all(a));
			int da = toInt(a);
			reverse(all(a));
			int ua = toInt(a);

			int next_a = ua - da;
			a = toStr(next_a);
		}
		[&]() {
			for (int i = 0; i <= 20; i++) {
				for (int j = 0; j < i; j++) {
					if (table[j] == table[i]) {
						cout << j << " " << toInt(table[j]) << " " << i - j << endl;
						return;
					}
				}
			}
		}();

	}

	return 0;
}

Measured memory_bytes: 3124
N = int(input())
L = []
l = []
A = []
ans = 0
for i in range(N):
    a = int(input())
    A.append(a)
    for j in range(a):
        l.append(list(map(int,input().split())))
    L.append(l)
    l = []
for bit in range(1<<N):
    flag = True
    listH = [(bit>>i)&1 for i in range(N)]
    for j in range(N):
        if not listH[j]:
            continue
        for k in range(A[j]):
            x = L[j][k][0]-1
            y = L[j][k][1]
            if listH[x] != y:
                flag = False
    if flag:
        ans = max(ans,sum(listH))
print(ans)

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

public class Main {

    private static int X;
    private static boolean isPrime[];

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

        createPrimeArray();
        
        System.out.println(getNextPrime(X));
    }
    
    private static void createPrimeArray(){
        
        isPrime = new boolean[2*X+1];
        Arrays.fill(isPrime, true);
        isPrime[0] = false;
        isPrime[1] = false;
        
        for(int i = 2; i<isPrime.length; i++) {
            if(!isPrime[i]) {
                continue;
            }
            
            for(int j=2;j*i < isPrime.length; j++) {
                isPrime[j*i] = false;
            }
        }
    }
    
    private static int getNextPrime(int x) {
        
        for(int i=x;i<isPrime.length; i++) {
            if(isPrime[i]) {
                return i;
            }
        }
        
        return -1;
    }

}


Measured memory_bytes: 23380
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 ) *} } ;}
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 ) *} } ;}
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" ) } ;}

fn main() {
   input! {
      n: usize,
      a: [usize; n]
   }
   let mut dp = vec![vec![0usize; n]; n];
   for l in 1..n {
      for i in 0..n - l {
         let mut mn = 1001001001001001;
         for m in i..i + l {
            mn = std::cmp::min(mn, dp[i][m] + dp[m + 1][i + l]);
            dp[i][i + l] += a[m];
         }
         dp[i][i + l] += a[i + l];
         dp[i][i + l] += mn;
      }
   }
   println!("{}", dp[0][n - 1]);
}


Measured memory_bytes: 4352
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int n, a; vector<int>p;
int main() {
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a; p.push_back(a);
	}
	sort(p.begin(), p.end());
	p.erase(unique(p.begin(), p.end()), p.end());
	cout << p.size() << endl;
	return 0;
}

Measured memory_bytes: 256
#!/usr/bin/python3
# -*- coding: utf-8 -*-


N,K,Q = map(int, input().split())
An = [int(input()) for _ in range(Q)]

Pn = [K-Q for _ in range(N)]
for a in An:
  Pn[a-1] += 1
for p in Pn:
  if p > 0:
    print("Yes")
  else:
    print("No")

Measured memory_bytes: 58200
import Data.List
import qualified Data.Vector.Unboxed as VU
import qualified Data.Vector.Unboxed.Mutable as VUM
import qualified Data.ByteString.Char8 as B
import Control.Arrow
import Control.Monad

divisibles :: [Int] -> VU.Vector Int
divisibles nums = VU.create $ do
            vec <- VUM.replicate (m + 1) 0
            forM_ nums $ \factor -> do
                alreadyMulted <- VUM.read vec factor
                VUM.modify vec (+ 1) factor
                when (alreadyMulted < 1) $ do
                forM_ [factor*2, factor*3 .. m] $ \mult -> do
                    VUM.modify vec (+ 1) mult
            return vec
        where
            m = maximum nums + 1

main = do
  let readInt = fmap (second B.tail) . B.readInt
  [n] <- map read . words <$> getLine
  pss <- VU.unfoldrN n readInt <$> B.getLine
  let ps = sort $ VU.toList pss
  let ans = divisibles ps
--   putStrLn $ show ans
  let asnss = filter (\x -> ans VU.! x == 1) $ ps
  putStrLn $ show $ length asnss


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

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

int main() {
  int N, M, K, n = 0, m = 0, mx = 0;
  ll S = 0;
  cin >> N >> M >> K;
  vector<int> a(N), b(M);
  REP(i, N) {
    cin >> a[i];
  }
  REP(i, M) {
    cin >> b[i];
  }
  while(n < N && S + a[n] <= K) {
    S += a[n];
    n++;
  }
  while(m < M && S + b[m] <= K) {
    S += b[m];
    m++;
  }
  mx = n + m;
  while(n >= 0) {
    n--;
    S -= a[n];
    while(m < M && S + b[m] <= K) {
      S += b[m];
      m++;
    }
    if(mx < n + m) mx = n + m;
  }
  cout << mx << endl;
}

Measured memory_bytes: 4840
#include <iostream>
#include <vector>
using namespace std;
int min(int a,int b)
{
	int ans;
	if(a>b){ans=b;}
	else{ans=a;}
	return ans;
}
int main()
{
	int n,h,w,counta=0,countb=0,sum=0;
	cin >> n >> h >> w;
	vector<int> a(n),b(n);
	for(int i=0;i<n;i++){
		cin >> a[i] >> b[i];
		counta=0;
		countb=0;
		while(a[i]-h>=0){
			a[i] -= h;
			counta++;
		}
		while(b[i]-w>=0){
			b[i] -= w;
			countb++;
		}
		sum += min(counta,countb);
	}
	
	cout << sum << endl;
	return 0;
}

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

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define ALL(x) (x).begin(), (x).end()

typedef int64_t ll;
typedef long double ld;

const int INF = 1e9;
const ld EPS = 1e-8;

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

int main(){
  int N;
  cin >> N;
  multiset<ld> st;
  REP(i,N) {
    ld v;
    cin >> v;
    st.insert(v);
  }
  REP(i,N-1) {
    auto itr1 = st.begin();
    ld v1 = *itr1;
    st.erase(itr1);
    auto itr2 = st.begin();
    ld v2 = *itr2;
    st.erase(itr2);
    st.insert((v1 + v2) / 2);
  }

  ld ret = *st.begin();
  cout << fixed << setprecision(10) << ret << endl;

  return 0;
}



Measured memory_bytes: 256
import java.io.FileInputStream;
import java.io.InputStream;
import java.util.HashMap;
import java.util.Scanner;

public class Main {
	static Scanner sc;

	static String S;

	public static void main(String[] args) throws Exception {
		//InputStream in = new FileInputStream("src/input.txt");
		InputStream in = System.in;
		//PrintStream out = new PrintStream("src/output.txt");

		//System.setOut(out);

		sc = new Scanner(in);

		int N = sc.nextInt();
		HashMap<Integer, Integer> map = new HashMap<>();
		int max = -1;

		for(int i = 0; i < N; i++){
			int key = sc.nextInt();
			int value = sc.nextInt();

			map.put(key, value);

			if(key > max){
				max = key;
			}

		}

		System.out.println(max + map.get(max));
	}
}

Measured memory_bytes: 97472
#include <algorithm>
#include <cassert>
#include <cfloat>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>
 
#define FOR(i,k,n) for (int (i)=(k); (i)<(n); ++(i))
#define rep(i,n) FOR(i,0,n)
#define all(v) begin(v), end(v)
#define debug(x) cerr<< #x <<": "<<x<<endl
#define debug2(x,y) cerr<< #x <<": "<< x <<", "<< #y <<": "<< y <<endl
 
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
typedef vector<ll> vll;
typedef vector<vector<ll> > vvll;
typedef deque<bool> db;
template<class T> using vv=vector<vector< T > >;

// cout pair
template<typename T1, typename T2> ostream& operator<<(ostream& s, const pair<T1, T2>& p) {
  s << p.first << " " << p.second << "\n"; return s;
}

// cout vector<pair>
template<typename T1, typename T2> ostream& operator<<(ostream& s, const vector<pair<T1, T2> >& vp) {
  int len = vp.size(); s << "\n";
  for (int i = 0; i < len; ++i) { s << vp[i]; }
    s << "\n"; return s;
}

// cout vector
template<typename T> ostream& operator<<(ostream& s, const vector<T>& v) {
  int len = v.size(); s << "\n";
  for (int i = 0; i < len; ++i) {
    s << v[i]; if (i < len - 1) s << "\t";
  }
  s << "\n"; return s;
}

// cout 2-dimentional vector
template<typename T> ostream& operator<<(ostream& s, const vector< vector<T> >& vv) {
  int len = vv.size();
  for (int i = 0; i < len; ++i) { s << vv[i]; }
  return s;
}

int main() {
  string s;
  cin >> s;
  cout << s.substr(0, s.length() - 8) << endl;
  return 0;
}


Measured memory_bytes: 888
#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 sr(ll a, ll b)
{
	return a > b;
}
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(ll n)
{
	int count = 0;
	while (n > 0)
	{
		n /= 10;
		count++;
	}
	return count;
}
template <class T>
void print(const T &value)
{
	std::cout << value << std::endl;
}

int main()
{
	string s;
	cin >> s;
	int l=s.size();
	string t=s.substr(0,1);
	int cnt=1;
	FOR(i,1,l){
		if(s.substr(i,1)!=t){
			t=s.substr(i,1);
			cnt++;
		}else{
			t=s.substr(i,2);
			i++;
			//cout<<i<<" ";
			if(i!=l){
			  cnt++;
			}
		}
		//cout<<i<<" "<<t<<" "<<cnt<<endl;
	}
	cout<<cnt<<endl;

}


Measured memory_bytes: 640
a, b = list(map(int, input().split()))
ans = 0
if a % 2 == 1:
    ans, a = a, a + 1
c = b - a + 1
if (c // 2) % 2 == 0:
    ans ^= 0
else:
    ans ^= 1
if c % 2 == 1:
    ans ^= b
print(ans)

Measured memory_bytes: 3060
#include <stdio.h>

int parent(int);
int left(int);
int right(int);

int main(){
  int H, i, A[251];

  scanf("%d", &H);

  for(i = 1; i <= H; i++) scanf("%d", &A[i]);

  for(i = 1; i <= H; i++){
    printf("node %d: key = %d, ", i, A[i]);
    if(i != 1) printf("parent key = %d, ", A[parent(i)]);
    if(left(i) <= H) printf("left key = %d, ", A[left(i)]);
    if(right(i) <= H) printf("right key = %d, ", A[right(i)]);
    printf("\n");
  }
  
  return 0;
}

int parent(int i){ return i/2; }

int left(int i){ return i*2; }

int right(int i){ return i*2+1; }

Measured memory_bytes: 600
s = input()
From0 = False
From1 = True
cntF0 = 0
cntF1 = 0
for i in range(len(s)):
    if s[i]!=str(int(From0)):
        cntF0 +=1
    if s[i]!=str(int(From1)):
        cntF1 +=1
    From0 = not(From0)
    From1 = not(From1)
print(min(cntF0,cntF1))

Measured memory_bytes: 3188
#include <iostream>
#include <string>
#include <utility>
#include <stack>
#include <vector>
#include <queue>
#include <algorithm>
#include <map>
#include <climits>
#include <set>
#include <numeric>
#include <iomanip>
#include <cmath>
#include <cstring>
using namespace std;
long long A[100000];
int main(){
  int N;
  cin >> N;
  long long sum_A = 0;
  map <long long, int> map_A;
  for(int i = 0; i < N; i++){
    cin >> A[i];
    sum_A += A[i];
    if(map_A.find(A[i]) != map_A.end()){
      map_A[A[i]] ++;
    } else {
      map_A[A[i]] = 1;
    }
  }

  int Q;
  cin >> Q;
  for(int i = 0; i < Q; i++){
    long long B;
    long long C;
    cin >> B >> C;
    if(map_A.find(B) != map_A.end()){
      int B_num = map_A[B];
      sum_A = sum_A - B * (long long) B_num + C * (long long) B_num;
      map_A.erase(B);
      if(map_A.find(C) != map_A.end()){
        map_A[C] += B_num;
      } else {
        map_A[C] = B_num;
      }
    }
    cout << sum_A << endl;
  }
  return 0;
}


Measured memory_bytes: 8304
//make sure to make new file!
import java.io.*;
import java.util.*;

public class Main{
   
   public static long MOD = 998244353L;
   public static long[] fac;
   
   public static void main(String[] args)throws IOException{
      BufferedReader f = new BufferedReader(new InputStreamReader(System.in));
      PrintWriter out = new PrintWriter(System.out);
      
      StringTokenizer st = new StringTokenizer(f.readLine());
      
      int n = Integer.parseInt(st.nextToken());
      long m = Long.parseLong(st.nextToken());
      int x = Integer.parseInt(st.nextToken());
      
      
      fac = new long[n+5];
      fac[0] = 1L;
      for(int k = 1; k < n+5; k++){
         fac[k] = (fac[k-1]*(long)k + MOD)%MOD;
      }
      
      //add 0
      long answer = (m*exp(m-1,n-1) + MOD)%MOD;
      
      for(int k = 1; k <= x; k++){
         long add = (m*exp(m-1,n-k-1) + MOD)%MOD;
         add = (add * choose(n-1,k) + MOD)%MOD;
         answer = (answer + add + MOD)%MOD;
      }
      
      out.println(answer);
      
      
      
      
      
      
      
      
      
      out.close();
   }
   
   public static long exp(long base, int power){
      if(power == 0) 
         return 1;
      if(power == 1) 
         return (base + MOD) % MOD;
      long ans = exp(base,power/2);
      ans = (ans*ans + MOD) % MOD;
      if(power%2 == 1) ans = (ans*base + MOD) % MOD;
      return (ans + MOD) % MOD;
   }
   
   public static long exp(long base, long power){
      if(power == 0) 
         return 1;
      if(power == 1) 
         return (base + MOD) % MOD;
      long ans = exp(base,power/2);
      ans = (ans*ans + MOD) % MOD;
      if(power%2 == 1) ans = (ans*base + MOD) % MOD;
      return (ans + MOD) % MOD;
   }
   
   public static long modInverse(long n){
      return exp(n,MOD-2);
   }
   
   public static long choose(int n, int r) { 
          
      if (r == 0) 
         return 1; 
      
      long ret = (fac[n]* modInverse(fac[r]) + MOD) % MOD;
      ret = (ret * modInverse(fac[n-r]) + MOD) % MOD;
      return ret;
      
        
   }
      
}

Measured memory_bytes: 35540
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double lf;
typedef pair<int,int> ii;
typedef pair<ii,int> iii;
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(int i=1;i<=n;i++)
#define RST(i,n) memset(i,n,sizeof i)
#define SZ(a) (int)a.size()
#define ALL(a) a.begin(),a.end()
#define X first
#define Y second
#define eb emplace_back
#ifdef cold66
#define debug(...) do{\
    fprintf(stderr,"LINE %d: (%s) = ",__LINE__,#__VA_ARGS__);\
    _do(__VA_ARGS__);\
}while(0)
template<typename T>void _do(T &&_x){cerr<<_x<<endl;}
template<typename T,typename ...S> void _do(T &&_x,S &&..._t){cerr<<_x<<", ";_do(_t...);}
template<typename _a,typename _b> ostream& operator << (ostream &_s,const pair<_a,_b> &_p){return _s<<"("<<_p.X<<","<<_p.Y<<")";}
template<typename It> ostream& _OUTC(ostream &_s,It _ita,It _itb)
{
    _s<<"{";
    for(It _it=_ita;_it!=_itb;_it++)
    {
        _s<<(_it==_ita?"":",")<<*_it;
    }
    _s<<"}";
    return _s;
}
template<typename _a> ostream &operator << (ostream &_s,vector<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a> ostream &operator << (ostream &_s,set<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a,typename _b> ostream &operator << (ostream &_s,map<_a,_b> &_c){return _OUTC(_s,ALL(_c));}
template<typename _t> void pary(_t _a,_t _b){_OUTC(cerr,_a,_b);cerr<<endl;}
#define IOS()
#else
#define debug(...)
#define pary(...)
#define endl '\n'
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0);
#endif // cold66
//}
template<class T> inline bool chkmax(T &a, const T &b) { return b > a ? a = b, true : false; }
template<class T> inline bool chkmin(T &a, const T &b) { return b < a ? a = b, true : false; }

const ll MAXn=1e5+5,MAXlg=__lg(MAXn)+2;
const ll MOD=1000000007;
const ll INF=0x3f3f3f3f;

bool ok[MAXn];
int cnt[MAXn];
int main(){
    	IOS();
    	int n,m;
    	cin >> n >> m;
    	ok[0] = true;
    	REP (i,n) {
        	cnt[i] = 1;
    	}
	REP (i,m) {
		int a,b;
		cin >> a >> b;
		a--, b--;
		if (ok[a]) ok[b] = true;
		cnt[a]--, cnt[b]++;
		if (cnt[a] == 0) ok[a] = false;
	}
	int ans = 0;
	REP (i,n) {
		ans += (int)ok[i];
	}
	cout << ans << endl;
}


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

int main(){
      map<string, int> m;
      m["SUN"] = 0;
      m["MON"] = 1;
      m["TUE"] = 2;
      m["WED"] = 3;
      m["THU"] = 4;
      m["FRI"] = 5;
      m["SAT"] = 6;
      string s;cin >> s;
      cout << 7 - m[s];
}

Measured memory_bytes: 256
#include <cstdio>
#include <climits>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <list>
#include <set>
#include <bitset>
#include <iterator>
#define loop(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) for(long long i = 0; i < (long long)(n); i++)
#define debug(x)  cout << #x << " = " << (x) << endl;

using namespace std;
using LL = long long int;
using ULL = unsigned long long;

int main() {
    int n, q;
    cin >> n >> q;
    string s;
    cin >> s;
    vector<pair<int, int>> v;
    rep(i, q) {
        int l, r;
        cin >> l >> r;
        v.push_back(make_pair(l, r));
    }
    vector<LL> left(n + 1);
    left[0] = 0;
    bool pre = false;
    rep(i, n) {
        if (s[i] == 'A') {
            pre = true;
            left[i + 1] = left[i];
        }
        else if (s[i] == 'C' and pre) {
            left[i + 1] = left[i] + 1;
            pre = false;
        } else {
            left[i + 1] = left[i];
            pre = false;
        }
    }
    // vector<LL> right(n + 1);
    // right[n] = 0;
    // pre = false;
    // for (int i = n - 1; i >= 0; i--) {
    //     if (s[i] == 'C') {
    //         pre = true;
    //         right[i] = right[i + 1];
    //     } else if (s[i] == 'A' and pre) {
    //         right[i] = right[i + 1] + 1;
    //         pre = false;
    //     } else {
    //         right[i] = right[i + 1];
    //         pre = false;
    //     }
    // }
    for (auto &lr : v) {
        int l = lr.first;
        int r = lr.second;
        cout << left[r] - left[l] << endl;
    }
}


Measured memory_bytes: 2612
import java.util.*;

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

    if (a>b) {
		  System.out.println("a > b");
    } else if (a<b) {
      System.out.println("a < b");
    } else {
      System.out.println("a == b");
    }
  }
}


Measured memory_bytes: 26252
program abc162c
      implicit none
      integer::k,a,b,c,x,y,sum0
      interface
         function gcd(a,b)
            implicit none
            integer::gcd
            integer,intent(in)::a,b
         end function gcd
      end interface

         read *,k

         do a=1,k
            do b=1,k
               x=gcd(a,b)
               do c=1,k
                  y=gcd(x,c)
                  sum0=sum0+y
               end do
            end do
         end do

         print *,sum0
         stop

   end program abc162c


   function gcd(a,b)
      implicit none
      integer,intent(in)::a,b
      integer::gcd
      integer::l,m,n

         l=a
         m=b
         n=mod(l,m)
         do while (n/=0)
            l=m
            m=n
            n=mod(l,m)
         end do
         gcd=m
         return
   end function gcd

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

typedef long long ll;

const int vmax=100010;
struct node{ll to,cost;};

vector<node> graph[vmax];

ll dist[vmax],cmax[vmax];

void tree_height(int n){
	function<void(int,int,ll)> dfs=[&dfs](int v,int p,ll c){
		dist[v]=c;
		for(auto &e:graph[v]) if(e.to!=p) dfs(e.to,v,c+e.cost);
	};
	dfs(0,-1,0LL);
	int u=0; rep(i,n) if(dist[i]>dist[u]) u=i;
	dfs(u,-1,0LL);
	int v=0; rep(i,n) if(dist[i]>dist[v]) v=i;
	function<void(int,int,ll,int)> dfs2=[&dfs2](int v,int p,ll c,int s){
		cmax[v]=max(cmax[v],c);
		for(auto &e:graph[v]) if(e.to!=p) dfs2(e.to,v,c+e.cost,s);
	};
	dfs2(u,-1,0LL,u);
	dfs2(v,-1,0LL,v);
}

int main(void){
	int n;
	cin >> n;
	rep(i,n-1){
		int a,b,c;
		cin >> a >> b >> c;
		graph[a].pb({b,c});
		graph[b].pb({a,c});
	}
	tree_height(n);
	rep(i,n) cout << cmax[i] << endl;
	return 0;
}

Measured memory_bytes: 4964