akhauriyash/Code-Regression huggingface dataset:
import sys

sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    n, m = map(int, input().split())
    A = sorted(list(map(int, input().split())))
    query = sorted([list(map(int, input().split())) for _ in range(m)], key=lambda x: x[1], reverse=True)

    B = []
    for i in range(m):
        b, c = query[i]
        while b and len(B) != n:
            B.append(c)
            b -= 1
    B.sort(reverse=True)

    for i in range(len(B)):
        if A[i] < B[i]:
            A[i] = B[i]
    print(sum(A))


if __name__ == '__main__':
    resolve()


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

using namespace std;
typedef long long ll;

int cmp(int a,int b){
    return a<b;
}

int main(){
    int n,k;cin>>n>>k;
    int niz[n];
    for(auto &a:niz)
        cin>>a;
    sort(niz,niz+n,cmp);
    ll rj=0;
    for(int i=0;i<k;i++){
        rj+=niz[i];
    }
    cout <<rj<<endl;
}


Measured memory_bytes: 3652
//BISMILLAHIR RAHMANIR RAHIM
//SOTO MEAW
//SOTO SONDESH
#include<bits/stdc++.h>

#define ls ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ll long long
#define __ <<" "<<
#define loop(m,n) for(m=0;m<n;m++)
#define rloop(m,n) for(m=n-1;m>=0;m--)
#define case(z) "Case " << z++ << ": "
#define yes cout << "YES" << endl
#define no cout << "NO" << endl
#define newline cout<<endl
#define quit return 0

using namespace std;

bool isprime(int n)
{
    for (int i = 2; i <= n/2; i++)
    {
        if (n % i == 0)
            return false;
    }
    return true;
}

void showmyDS(set<int> ds)
{
    set<int> ::iterator it;
    for (it=ds.begin();it!=ds.end();it++)
    {
        cout << *it << endl ;
    }
    cout << endl;
}
int main()
{
    ls
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    //int t,l=1;cin>>t;while(l>0){
        int n;
        cin>>n;
        int num,k,i,j,l,r;
        int c[10][10]={0};
        for(i=1;i<=n;i++)
        {
            r=i%10;
            num=i;
            while(num!=0)
            {
                k=num%10;
                num/=10;
            }
            l=k;
            c[l][r]++;
        }
        ll int total = 0;
        loop(i,10){
            loop(j,10){
                total+=(c[i][j]*c[j][i]);
            }
        }
        cout<<total;
        newline;
    //t--;}

    quit;
}


Measured memory_bytes: 3656
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef vector<ll> vl;
typedef vector<string> vs;
typedef vector<char> vc;
typedef queue<ll> ql;
typedef deque<ll> dql;
typedef priority_queue<ll, vl/*, greater<ll>*/> pql; //降順(/*昇順*/)
typedef set<ll> sl;
#define rep(i, n) for(ll i = 0; i < ll(n); ++i)
#define rep2(i, n) for(ll i = 1; i <= ll(n); ++i)
//#define rep(i, k, n) for(ll i = k-1; i < ll(n); ++i)
//#define rep2(i, k, n) for(ll i = k; i <= ll(n); ++i)
#define all(v) (v).begin(), (v).end()
bool chmin(ll &a, ll b) {if(b < a) {a = b; return 1;} return 0;}
bool chmax(ll &a, ll b) {if(b > a) {a = b; return 1;} return 0;}
const ll INF = 1LL << 60;
const ll MOD = 1e9 + 7;
//const ll MOD = 998244353;
const ll MAX = 1e9;
const char newl = '\n';
ll num=1, ans=0, cnt=0, sum=0;

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

  ll a, b, n;
  cin >> a >> b >> n;
  if(b-1<=n) {
    cout << a*(b-1)/b << newl;
  }else {
    cout << a*n/b << newl;
  }
  return 0;
}

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

#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<=(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define Eunique(v) v.erase(unique(all(v)),v.end())
#define Eback(s) s.erase(s.end()-1,s.end())
#define rev(v) reverse(all(v))
#define minvec(v) *min_element(all(v))
#define maxvec(v) *max_element(all(v))
#define sumvec(v) accumulate(all(v),0LL)
#define mapmin(v) v.rbegin()->first
#define mapmax(v) v.begin()->first
#define pb push_back
#define pf push_front
#define m_p make_pair
#define DOUBLE fixed << setprecision(15)
#define OK cerr<<"OK\n"
#define OK1 cerr<<"OK1\n"
#define OK2 cerr<<"OK2\n"
#define SIZE(s) (int)s.size()
#define INF ((1LL<<62)-(1LL<<31))
#define zero(x,n) setw(x) << setfill('0') << n
#define endl '\n'

typedef long long ll;

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<long long> vll;
typedef vector<vll> vvll;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<string> vs;

typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
typedef vector<pair<int,int>> vpii;
typedef vector<pair<ll,ll>> vpll;

const double pi = acos(-1.0);
const ll mod=1000000007;
const ll mod2=998244353;

template<class A, class B>
ostream& operator<<(ostream& ost, const pair<A, B>&p) {
	ost << "{" << p.first << ", " << p.second << "} ";
	return ost;
}

template<class T>
ostream& operator<<(ostream& ost, const vector<T>&v) {
	ost << "{";
	for (int i = 0; i<(int)v.size(); i++) {
		if (i)ost << " ";
		ost << v[i];
	}
	ost << "} \n";
	return ost;
}

template<class A, class B>
ostream& operator<<(ostream& ost, const map<A, B>&v) {
	ost << "{";
	for (auto p:v) {
		ost << "{" << p.first << ", " << p.second << "} ";
	}
	ost << "} ";
	return ost;
}

template<class T>
inline bool chmax(T& a, T b){if(a<b){a=b;return true;} return false;}

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

void YES(bool b) {cout << ((b)?"YES\n":"NO\n");}
void Yes(bool b) {cout << ((b)?"Yes\n":"No\n");}
void yes(bool b) {cout << ((b)?"yes\n":"no\n");}
void Yay(bool b) {cout << ((b)?"Yay!\n":":(\n");}

ll powmod(ll a,ll b){ll c=1; while(b>0){ if(b&1){ c=a*c%mod; } a=a*a%mod; b>>=1; } return c;}
ll gcd(ll x, ll y) {return __gcd(x,y);}
ll lcm(ll x, ll y) {return x/__gcd(x,y)*y;}

int main()
{
	ll n,ans=0;
	cin >> n;
	vll a(n+1);
	map<ll,ll> m;
	m[0]++;
	rep(i,n){
		cin >> a[i+1];
		a[i+1]+=a[i];
		ans+=m[a[i+1]];
		m[a[i+1]]++;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 14336
#include <stdio.h>
int main()
{
	for(int i=1;i<=9;i++)
	{
		for(int j=1;j<=9;j++)		
		{
			int x=i*j;
			printf("%dx%d=%d\n",i,j,x);
		}
	}	
	return 0;
}



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

using namespace std;
#define taskname "A"
#define pb	push_back
#define mp  make_pair

typedef long double ld;
typedef long long ll;
typedef pair<int,int> ii;
const int maxn = 2500 + 5;
const int mod = 1e9 + 7;
int n , a[maxn];

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	if(fopen(taskname".INP","r")){
        freopen(taskname".INP", "r",stdin) ,
        freopen(taskname".OUT", "w",stdout);
	}
    cin >> n;
    for(int i = 1  ; i <= n ; ++i){
        cin >> a[i];
    }
    int res = 1e9;
    for(int i = 1 ; i <= 100 ; ++i){
        int ans = 0;
        for(int j = 1 ; j <= n  ; ++j){
            ans += (a[j] - i) * (a[j] - i);
        }
        res=  min(res,ans);
    }
    cout << res;
}



Measured memory_bytes: 256
#include <iostream>
#include <array>
#include <numeric>
#include <algorithm>
#include <cstdint>

int main()
{
	std::uint16_t num;
	while (std::cin >> num) {
		typedef std::array<std::uint16_t, 13> CardArray;
		CardArray cards;
		cards.fill(0);
		++cards[num - 1];
		for (std::size_t i = 0; i < 4; ++i) {
			char comma;
			std::cin >> comma >> num;
			++cards[num - 1];
		}

		CardArray::iterator i;
		if (std::find(cards.begin(), cards.end(), 4) != cards.end()) {
			std::cout << "four card" << std::endl;
		}
		else if (std::find(cards.begin(), cards.end(), 3) != cards.end()) {
			if (std::find(cards.begin(), cards.end(), 2) != cards.end()) {
				std::cout << "full house" << std::endl;
			}
			else {
				std::cout << "three card" << std::endl;
			}
		}
		else if ((i = std::find(cards.begin(), cards.end(), 2)) != cards.end()) {
			if (std::find(i + 1, cards.end(), 2) != cards.end()) {
				std::cout << "two pair" << std::endl;
			}
			else {
				std::cout << "one pair" << std::endl;
			}
		}
		else {
			if (cards[0] == 1 and std::accumulate(cards.begin() + 9, cards.end(), 0u) == 4u) {
				std::cout << "straight" << std::endl;
			}
			else {
				i = std::find(cards.begin(), cards.end(), 1);
				if (std::accumulate(i, i + 5, 0u) == 5u) {
					std::cout << "straight" << std::endl;
				}
				else {
					std::cout << "null" << std::endl;
				}
			}
		}
	}
	return 0;
}

Measured memory_bytes: 1156
h,w=map(int,input().split())
dp=[[0]*(w+1)]
table=str.maketrans('10','01')
for i in range(h):
    dp+=[[0]+list(map(int,input().translate(table).split()))]

P=[-1,-1,0]
Q=[-1,0,-1]
ans=0
for i in range(1,h+1):
    for j in range(1,w+1):
        if dp[i][j]==0:continue
        dp[i][j]=1+min(dp[i-1][j-1],dp[i-1][j],dp[i][j-1])
        ans=max(ans,dp[i][j])
print(ans*ans)


Measured memory_bytes: 43864
#include <iostream>
#include <algorithm>
#include <functional>
#include <cmath>
#include <string>
#include <vector>
#include <queue>

using namespace std;

struct UnionFind {
  vector<int> v;
  UnionFind(int n): v(n, -1) {};
  
  int root(int x) {
    if (v[x] < 0) return x;
    return v[x] = root(v[x]);
  }

  bool unite(int x, int y) {
    x = root(x); y = root(y);
    if (x == y) return false;
    if (v[x] > v[y]) swap(v[x], v[y]);
    v[x] += v[y];
    v[y] = x;
    return true;
  }

  bool same(int x, int y) {
    return root(x) == root(y);
  }

  int size(int x) {
    return -v[root(x)];
  }
};

int cnt[100005];
vector<int> to[100005];

int main() {
  int n, m, k;
  cin >> n >> m >> k;
  UnionFind uf = UnionFind(n);
  
  for (int i = 0; i < m; ++i) {
    int a, b;
    cin >> a >> b;
    --a; --b;
    cnt[a]++;
    cnt[b]++;
    uf.unite(a, b);
  }

  for (int i = 0; i < k; ++i) {
    int c, d;
    cin >> c >> d;
    --c; --d;
    to[c].push_back(d);
    to[d].push_back(c);
  }

  for (int i = 0; i < n; ++i) {
    int ans = uf.size(i) - 1 - cnt[i];
    for (auto u : to[i]) {
      if (uf.same(u, i)) ans--;
    }
    string divider = i == n-1 ? "\n" : " ";
    cout << ans << divider;
  }


  return 0;
}

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

namespace abc060_a
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] str = Console.ReadLine().Split(' ');
            if (str[0].Substring(str[0].Length - 1) == str[1].Substring(0, 1) && str[1].Substring(str[1].Length - 1) == str[2].Substring(0, 1))
            {
                Console.WriteLine("YES");
            }
            else
            {
                Console.WriteLine("NO");
            }
        }
    }
}


Measured memory_bytes: 13140
/******Old_school_@15******/
#include<bits/stdc++.h>
using namespace std;
#define lld               long long int
#define ld                long double
#define pb                push_back
#define ppb               pop_back hellooitsme1
#define mp                make_pair
#define F                 first
#define S                 second
#define nl                '\n'
#define all(c)            (c).begin(),(c).end()
#define rall(c)           (c).rbegin(),(c).rend()
#define sz(c)             (c).size()
#define tr(x,a)           for(auto &a : x)
#define psnt(x,a)         (x).find(a)!=(x).end()
#define vpsnt(x,a)        find(all(x),a)!=(x).end()
#define lexichar(x,y)     lexicographical_compare(x,x+strlen(x),y,y+strlen(y)) //modify the ranges
#define lexistr(x,y)      lexicographical_compare(x.begin(),x.end(),y.begin(),y.end()) 
#define MOD               1000000007
#define pi                3.1415926536
#define tod               1
#define itr(i,a,b)        for(lld i=a;i<=b;i++)
#define itrn(i,a,b)       for(lld i=a;i>=b;i--)
#define iot(n)            for(lld i=0;i<n;i++)
#define pls(n,arr)        lld arr[n]; iot(n)  cin>>arr[i];
#define bye               fflush(stdout)

typedef pair<lld,lld>     pii;
typedef pair<string,lld>  psi;
template <typename T>
bool mycomp(T x,T y){ 
   return (x==y);  //give your condition here
}
bool paircomp(const pair<lld,lld> &x,const pair<lld,lld> &y){ 
return x.second<y.second;
}

int main(){
       ios_base::sync_with_stdio(false);
             cin.tie(0);
            cout.tie(0);
      lld t=1; //cin>>t;  
      while(t--){
          lld x; cin>>x;
          if(x>=30)  cout<<"Yes";
          else  cout<<"No\n";
      }
}


Measured memory_bytes: 3644
#include <bits/stdc++.h>
using namespace std;
typedef long long int lli;
typedef pair<int,int> pii;
typedef pair<lli,lli> pll;
template<typename T>
int sz(const T &a){return (int)a.size();}

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

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

using namespace std;

#define int long long
#define rep(i,n) for(int i = 0; i < (n); i++)
#define INF ((long long)1e18)
#define MOD ((int)1e9+7)
#define endl "\n"

#define yn(f) ((f)?"Black":"White")
#define YN(f) ((f)?"YES":"NO")

#define MAX 9


int p, n, m;
		
int check(int board[MAX][MAX][MAX], int con[MAX][MAX], int col){
	int res = 0;
	
	for(int i = 0; i < n; i++){
		for(int j = 0; j < n; j++){
			for(int k = 0; k < con[i][j]; k++){
				int count = 0;
				if(board[k][i][j] != col) continue;
				
				for(int o = 1; o < 27; o++){
					int a = o%3, b = (o/3)%3, c = (o/9)%3;
					bool flag = true;
					
					if(a==2) a = -1;if(b==2) b = -1;if(c==2) c = -1;
					
					for(int l = 0; l < m; l++){
						
						if(i+l*b >= n || j+l*c >= n  || i+l*b < 0 || j+l*c < 0 || k+l*a < 0 || k+l*a >= con[i+l*b][j+l*c]){
							flag = false;
							break;
						}
						if(board[k+l*a][i+l*b][j+l*c] != col){
							flag = false;
							break;
						}
					}
					if(flag) return true;
					if(flag) count++;
				}
				res += count;
			}
		}
	}
	
	return res;
}
signed main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout<<fixed<<setprecision(10);
	
	while(true){
		int board[MAX][MAX][MAX] = {};
		int con[MAX][MAX] = {};
		int x, y;
		bool flag = true;
		int ans = 0, win = 0;
		
		cin>>n>>m>>p;
		
		if(!n && !m && !p) break;
		
		for(int i = 0; i < p; i++){
			cin>>x>>y;
			
			x--, y--;
			
			board[con[y][x]++][y][x] = flag + 1;
			
			if(!ans){
				if(check(board, con, flag+1)) ans = i+1;
				win = flag;
			}
			
			flag = !flag;
		}
		
		if(!ans) cout<<"Draw"<<endl;
		else cout<<yn(win)<<" "<<ans<<endl;
	}
	
	
	return 0;
}


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

using namespace std;
typedef long long ll;

// #define DEBUG

const int INTMAX = 2 * 1e9 + 10;
const int NMAX = 2 * 1e3;

bool check[NMAX];

int dfs(int s, int t, int f, vector<pair<int, int>> edge[], vector<int> *used)
{
    int d = 0;
    check[s] = true;
    if (s == t)
    {
        used->push_back(t);
        return f;
    }

    for (auto next : edge[s])
    {
        if (check[next.first] == false && next.second > 0)
            d = dfs(next.first, t, min(next.second, f), edge, used);
        if (d > 0)
        {
            used->push_back(s);
            return d;
        }
        // DFSが終点まで行くと正の値dが帰ってくるので、辺の容量の調整をして終了
    }
    return 0; //そうでなければ何もしない
}

int main()
{

#ifdef DEBUG
    cout << "DEBUG MODE" << endl;
    ifstream in("input.txt"); //for debug
    cin.rdbuf(in.rdbuf());    //for debug
#endif

    int n, x, y, m, s, t, c, a, b, f, ans;
    cin >> x >> y >> m;
    n = x + y + 2;
    vector<pair<int, int>> edge[n];
    vector<int> used;

    f = 1, ans = 0;
    for (int i = 1; i <= x; i++)
    {
        edge[0].push_back(make_pair(i, 1));
        edge[i].push_back(make_pair(0, 0));   
    }
    for (int i = x + 1; i <= y + x; i++)
    {
        edge[i].push_back(make_pair(y+x+1, 1));
        edge[y+x+1].push_back(make_pair(i, 0));   
    }
    for (int i = 0; i < m; i++)
    {
        cin >> s >> t;
        s++;
        t += x+1;
        edge[s].push_back(make_pair(t, 1));
        edge[t].push_back(make_pair(s, 0));
    }

    while (f > 0)
    {
        for (int i = 0; i < n; i++)
            check[i] = false;

        f = dfs(0, n - 1, INTMAX, edge, &used);
        a = -1, b = -1;
        for (auto i : used)
        {
            a = b;
            b = i;

            if (a >= 0 && b >= 0)
            {
                for (auto j = edge[a].begin(); j != edge[a].end(); j++)
                {
                    if (j->first == b)
                    {
                        j->second += f;
                        break;
                    }
                }
                for (auto j = edge[b].begin(); j != edge[b].end(); j++)
                {
                    if (j->first == a)
                    {
                        j->second -= f;
                        break;
                    }
                }
            }
        }
        ans += f;
        used.clear();
    }
    cout << ans << endl;

    return 0;
}

// getline(cin,s);
// a = strtok(s, ",");  ","で分解
// for (int i = 0; i < n; i++)


Measured memory_bytes: 3244
while True:
    h,w=map(int,input().split())
    if h==0 and w==0:
        break
    for i in range(h):
        for j in range(w):
            if i==0 or j==0 or i==h-1 or j==w-1:
                print("#",end="")
            else :
                print(".",end="")
        print("")
    
    print("")


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

int main(){
	int n;
	cin >> n;
	pair <int ,int> dp[n];
	for (int i=0;i<n;i++){cin >> dp[i].first >>dp[i].second;}
		int k=0;
		for (int i=0;i<n-2;i++)
		{
			if (dp[i].first==dp[i].second && dp[i+1].first==dp[i+1].second && dp[i+2].first==dp[i+2].second)
				{
					cout << "Yes";
					k=1;
					break;
			}
		}
	if (k==0) cout << "No";
}


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

int main(){
  int a,b,n,c1,c2;
  while(1){
    cin >> a >> b;
    if(a==0 && b==0) break;
    int mp[1111][1111]={0};
    cin >> n;
    for(int i=0;i<n;i++){
      cin >> c1 >> c2;
      mp[c1][c2] = -1;
    }
    mp[1][1] = 1;
    for(int i=1;i<=a;i++){
      for(int j=1;j<=b;j++){
	if(mp[i][j] == -1){
	  mp[i][j] = 0;
	}
	else if(i != 1 || j != 1){
	  mp[i][j] = mp[i-1][j] + mp[i][j-1];
	} 
      }
    }
    cout << mp[a][b] << endl;
  }
}

Measured memory_bytes: 5988
Value = [int(input()) for _ in range(5)]
amari = list()
for i in range(5):
  if(Value[i]%10 == 0):
    amari.append(10)
  else:
    amari.append(Value[i]%10)
min_amari = [i for i in range(5) if(min(amari)==amari[i])]

ans = 0
for i in range(5):
  if(i == min_amari[0]):
    ans += 0
  else:
    ans += (Value[i] + 10-amari[i])
ans += Value[min_amari[0]]
print(ans)

Measured memory_bytes: 9144
import Control.Monad
import Data.Maybe
import qualified Data.ByteString.Char8 as BS
import Data.List

readInt = fst . fromJust . BS.readInt
readIntList = map readInt . BS.words
getInt = readInt <$> BS.getLine
getIntList = readIntList <$> BS.getLine

main = do
    n <- getInt
    as <- getIntList
    let o | odd n  = (== sort as) . (0 :) $ concatMap (replicate 2) (take (n `div` 2) [2,4..])
          | even n = (== sort as) $ concatMap (replicate 2) (take (n `div` 2) [1,3..])
    print $ if o then powerMod 2 (n `div` 2) else 0

moduloN = 10 ^ 9 + 7

modN = flip mod moduloN

mulMod x y = modN $ x * y

powerMod x 0 = 1
powerMod x y
    | even y = mulMod t t
    | otherwise = mulMod x $ mulMod t t
    where
        t = powerMod x $ div y 2

Measured memory_bytes: 16764
#include <iostream>
#include <stdio.h>
using namespace std;

int insertionSort(int A[], int N, int count){
    int flag = 1;
    while(flag == 1){
        flag = 0;
        for(int j = N - 1; j >= 1; j--){
            if(A[j] < A[j-1]){
                int a = A[j];
                A[j] = A[j-1];
                A[j-1] = a;
                flag = 1;
                count++;
            }
        }
    }
    return count;
}

int main(){
    int N;
    cin >> N;
    int A[N];
    for(int i = 0; i < N; i++){
        cin >> A[i];
    }
    
    int count = 0;
    int ans = insertionSort(A, N, count);
    for(int i = 0; i < N; i++){
        if(i > 0) cout << " ";
        cout << A[i];
    }
    cout << endl;
    cout << ans << endl;
    
    return 0;
}


Measured memory_bytes: 3084
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0;i<(n);i++)
#define rep2(i,a,n) for(int i=a;i<n;i++)
#define been(ix) (ix).begin(),(ix).end()
using namespace std;
typedef long long ll; 
typedef vector<int> vi;
typedef vector<long long> vl;
const ll INFL = 1e18;
const int INF = 1001001001; 
typedef pair<int,int> P;
#define foreach(ix,i) for(auto& (ix) : (i))
typedef long double ld;
const int mod =1000000007;
const double PI = acos(-1);
int main(){
	int n;cin>>n;
	ll a[n];
	rep(i,n){
		cin>>a[i];
		if(a[i]==0){
			cout<<0<<endl;
			return 0;
		}
	}
	ll ans =1;
	ll m = 1000000000000000000;
	rep(i,n){
		if(ans>m/a[i]){
			cout<<-1<<endl;
			return 0;
		}
		ans*=a[i];
		
	}
cout<<ans<<endl;
}

Measured memory_bytes: 4376
#include <set>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>
using namespace std;
typedef long long ll;
typedef vector<int> vint;
typedef pair<int, int> pint;
typedef vector<long long> vlong;
#define vpush(a,x) a.push_back(x);
#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++)
#define INF 2e9
int fact(int n){
    int m;
  if (n == 0)
      return 1;
  m = fact(n - 1);    
  return n * m;       
}
signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n,r;
  cin>>n;
  cout<<pow(n,2.0)<<'\n';
  return(0);
}

Measured memory_bytes: 256
package main

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

var sc, wr = bufio.NewScanner(os.Stdin), bufio.NewWriter(os.Stdout)

func scanString() string   { sc.Scan(); return sc.Text() }
func scanRunes() []rune    { return []rune(scanString()) }
func scanInt() int         { a, _ := strconv.Atoi(scanString()); return a }
func scanInt64() int64     { a, _ := strconv.ParseInt(scanString(), 10, 64); return a }
func scanFloat64() float64 { a, _ := strconv.ParseFloat(scanString(), 64); return a }

func scanInts(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = scanInt()
	}
	return res
}

func debug(a ...interface{}) { fmt.Fprintln(os.Stderr, a...) }

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}
func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

//•*¨*•.¸¸♪main•*¨*•.¸¸♪(　-ω-)ノ　(　・ω・)
func main() {
	defer wr.Flush()
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 10000), 1001001)

	n := scanInt()
	u := scanInt() - 1
	v := scanInt() - 1
	g := make([][]int, n)
	for i := 0; i < n-1; i++ {
		a, b := scanInt()-1, scanInt()-1
		g[a] = append(g[a], b)
		g[b] = append(g[b], a)
	}

	var dfs func(to, c int, arr []int)
	dfs = func(v, c int, arr []int) {
		for _, to := range g[v] {
			if arr[to] != -1 {
				continue
			}
			arr[to] = c
			dfs(to, c+1, arr)
		}
	}

	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = -1
	}
	a[v] = 0
	dfs(v, 1, a)

	ans := 0
	var dfs2 func(v, p, c int)
	dfs2 = func(v, p, c int) {
		for _, to := range g[v] {
			if to == p || a[to] < c {
				continue
			}
			if a[to] == c {
				ans = max(ans, a[to])
			} else {
				ans = max(ans, a[to]-1)
				dfs2(to, v, c+1)
			}
		}
	}

	ans = a[u] - 1
	dfs2(u, u, 1)

	fmt.Fprintln(wr, ans)

}


Measured memory_bytes: 34688
#include <iostream>
#include <string>

using namespace std;

int main() {
	int H, W, K;
	scanf("%d%d%d", &H, &W, &K);
	string m[H];
	for (int i = 0; i < H; i++) {
		cin >> m[i];
	}
	int count = 0;
	for (int b = 0; b < 1 << (H + W); b++) {
		int black = 0;
		for (int i = 0; i < H * W; i++) {
			if (b >> (i / W) & 1 && b >> (H + i % W) & 1) {
				if (m[i / W][i % W] == '#') {
					if (++black > K) {
						break;
					}
				}
			}
		}
		if (black == K) {
			count++;
		}
	}
	printf("%d\n", count);
	return 0;
}


Measured memory_bytes: 3736
#include <algorithm>
#include <bitset>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

typedef long long ll;

#define rep(i, a, b) for (ll i = a; i < (ll)b; ++i)
#define INF 10e12
#define MAX 51000
#define all(x) (x).begin(), (x).end()
#define MX(x) *max_element(all(x))
#define MN(x) *min_element(all(x))

using namespace std;

const long long MOD = 1e9 + 7;

int main(void)
{
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    ll n;
    cin >> n;
    vector<int> v(n), c(n);
    rep(i, 0, n) cin >> v[i];
    rep(i, 0, n) cin >> c[i];
    int ans = 0;
    rep(i, 0, 1 << n)
    {
        vector<int> temp;
        int diff = 0;
        rep(j, 0, n) if (i >> j & 1) temp.push_back(j);
        for (auto j : temp)
        {
            diff += v[j] - c[j];
        }
        ans = max(ans, diff);
    }
    cout << ans << endl;
}


Measured memory_bytes: 3660
#include <bits/stdc++.h>
    #define rep(i,a,b) for(int i=(a);i<(b);i++)
    #define per(i,a,b) for(int i=(a);i>(b);i--)
    #define pb push_back
    #define ff first
    #define ss second
    #define endl '\n'

    typedef long long ll;
    using namespace std;



    int main(){
        int n;
        cin>>n;
        if(n==1) {cout<<0; return 0;}
        else cout<<1;

    return 0;
    }


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

using namespace std;
const int maxN=1e5+100;

vector<int> g[maxN],topol;
int n,m;
bool mark[maxN];

void input()
{
  cin>>n>>m;
  for(int i=1;i<=m;i++)
    {
      int k1,k2;
      cin>>k1>>k2;
      g[k1+1].push_back(k2+1);
    }
}

void dfs(int v)
{
  mark[v]=true;
  for(int i=0;i<g[v].size();i++)
    if(!mark[g[v][i]])
      dfs(g[v][i]);
  topol.push_back(v);
}
void show()
{
  for(int i=0;i<topol.size();i++)
    cout<<topol[i]-1<<"\n";
}
int main()
{
  input();
  for(int i=1;i<=n;i++)
    if(!mark[i])
      dfs(i);
  reverse(topol.begin(),topol.end());
  show();  
  return 0;
}

Measured memory_bytes: 4076
#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(i=a;i<b;i++)
#define re(i,a,b) for(int i=a;i<=b;i++)
#define fr(i,n) for(int i=0;i<n;i++)
#define ll long long
#define mod 1000000007
#define pb(x) push_back(x)
#define mp map<ll,ll>
#define lcm(a,b) (a*b)/(__gcd(a,b))
#define vi vector<ll>
#define start int t; cin>>t; while(t--)
#define dumb ios_base::sync_with_stdio(false);cin.tie(NULL);
vector<ll> g[1000000];
ll vis[10000000]={0};
void dfs(ll i)
{
    vis[i]=1;
    for(auto x: g[i])
    {
        if(vis[x]==0)
        dfs(x);
    }

}
int main()
{
dumb
ll i,j,k,l,n,p,q,c=0,d=0,sum=0,flag=0,min1=999999999999,max1=-999999999999,x,y,m,u,v;
string s;
cin>>n>>m;
fr(i,n)
vis[i]=0;
while(m--)
{
    cin>>u>>v;
    g[u].pb(v);
    g[v].pb(u);
}
for(i=1;i<=n;i++)
{
    if(vis[i]==0)
    dfs(i),c++;
}
cout<<c-1<<endl;
}


Measured memory_bytes: 32176
#include<cstdio>
#include<iostream>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<list>
#include<map>
#include<algorithm>

using namespace std;

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

    int sn = 0;
    int ntmp = n;

    while (ntmp > 0) {
        sn += ntmp % 10;
        ntmp /= 10;
    }

    if (n % sn == 0) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }

    return 0;
}


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

using namespace std;

using VI = vector<int>;
using VVI = vector<VI>;
using VB = vector<bool>;
using VVB = vector<VB>;
using VD = vector<double>;
using VVD = vector<VD>;
using VS = vector<string>;
using PII = pair<int, int>;
using VPII = vector<PII>;
using VL = vector<long long>;
using VVL = vector<VL>;

#define sz(var) (int)var.size()
#define REP(var, start, end) for(int var = start; var < (int)end; ++var)
#define REPC(var, start, end) for(int var = start; var <= (int)end; ++var)
#define CLEAR(var, with) memset(var, with, sizeof(var))
#define ALL(x) x.begin(), x.end()
#define LL long long
#define ULL unsigned long long
#define TIME cerr << "Time elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms" << endl;
#define DBG(x) cerr << x << endl;

/*
	
*/
bool isOk(string& s)
{
	return s[0] == s[sz(s) - 1];
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
	//freopen("tmp.in", "r", stdin);
	//freopen("tmp.out", "w", stderr);
#endif
	string s;
	cin >> s;

	cout << (isOk(s) ? "Yes" : "No") << endl;

	return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define mod 1000000007
#define all(c) begin(c),end(c)
template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
using ll = long long;
using vi = vector<int>; using vs = vector<string>;
int dd[] = { 0, 1, 0, -1, 0 }; //→↓←↑

void solve()
{
	int M, MIN, MAX;
	while (cin >> M >> MIN >> MAX, M)
	{
		vector<int> A(M);
		for (int i = 0; i < M; i++) {
			cin >> A[i];
		}
		sort(A.begin(), A.end());
		reverse(A.begin(), A.end());
		int gap = -1;
		int ans = -1;
		for (int i = MIN - 1; i < MAX; i++)
		{
			if (gap <= A[i] - A[i + 1])
			{
				gap = A[i] - A[i + 1];
				ans = i + 1;
			}
		}
		cout << ans << endl;
	}
}

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


Measured memory_bytes: 3056
#include<stdio.h>
#include<stdlib.h>

int main(void){
	int h,w,i,j;
	
	while(scanf("%d %d", &h, &w),h || w){
		for(i=0; i<h; i++){
			for(j=0; j<w; j++){
				if(i==0 || i==h-1 || j==0 || j==w-1){
					printf("#");
				}else{
					printf(".");
				}
			}
			printf("\n");
		}
		printf("\n");
	}
	
	return 0;
}

Measured memory_bytes: 572
#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;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
int main(){
    cout << fixed << setprecision(10);
    int n;
    cin >> n;
    vector<int> v(n,0);
    map<int,int> mii;
    rep(i,n){
        cin >> v[i];
        mii[v[i]]++;
    }
    if(mii.size() > 3){
        cout << "No" << endl;
        return 0;
    }
    if(mii.size() == 3){
        if(n%3 == 0){
            bool ok = 1;
            int now = 0;
            for(auto u : mii){
                if(u.second != n/3) ok = 0;
                now ^= u.first;
            }
            //cout << now << endl;
            if(ok && now == 0) cout << "Yes" << endl;
            else cout << "No" << endl;
            return 0;
        }else{
            cout << "No" << endl;
            return 0;
        }
    }
    if(mii.size()  == 2){
        bool ok = 1;
        for(auto u : mii){
            if((u.second != n/3 && u.second != 2*n/3)) ok = 0;
            if(u.second == n/3 && u.first != 0) ok = 0;
            //if(u.second == 2*n/3 && u.first == 0) ok = 0;
        }
        if(ok) cout << "Yes" << endl;
        else cout << "No" << endl;
        return 0;
    }
    if(mii.size() == 1){
        bool ok = 1;
        for(auto u : mii){
            if(u.first != 0) ok = 0;
        }
        if(ok) cout << "Yes" << endl;
        else cout << "No" << endl;
        return 0;
    }
    return 0;
}

Measured memory_bytes: 7200
import java.util.Scanner;
 public class Main {
public static void main(String[] args) {
Scanner sc =  new Scanner(System.in);
	int k=sc.nextInt();
	int s=sc.nextInt();
	int ans=0,i,j;
	for(i=0;i<=k;i++){
		for(j=0;j<=k;j++){
			if(i+j<= s && s-(i + j)<= k){
			ans++;
	}
	}
	}
	System.out.println(ans);
}
}

Measured memory_bytes: 23124
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
using namespace std;

//
#define int long long
#define pb(x) push_back(x)
#define m0(x) memset((x), 0, sizeof(x))
#define mm(x) memset((x), -1, sizeof(x))

//container
#define ALL(x) (x).begin(), (x).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define EACH(i, c) for (typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define EXIST(s, e) ((s).find(e) != (s).end())
#define UNIQUE(v) (v).erase(unique((v).begin(), (v).end()), (v).end());
#define PERM(c) \
  sort(ALL(c)); \
  for (bool c##p = 1; c##p; c##p = next_permutation(ALL(c)))

// debug
#define GET_VAR_NAME(variable) #variable
#define test(x) cout << GET_VAR_NAME(x) << " = " << x << endl;

// bit_macro
#define bit(n) (1LL << (n))
#define bitset(a, b) (a) |= (1 << (b))
#define bitunset(a, b) (a) &= ~(1 << (b))
#define bitcheck(a, b) ((((a) >> (b)) & 1) == 1)
#define bitcount(a) __builtin_popcountll((a))

//typedef
typedef long long lint;
typedef unsigned long long ull;
typedef complex<long double> Complex;
typedef pair<int, int> P;
typedef tuple<int, int, int> TP;
typedef vector<int> vec;
typedef vector<vec> mat;

//constant
const int INF = (int)1e18;
const int MOD = (int)1e9 + 7;
const double PI = (double)acos(-1);
const double EPS = (double)1e-10;
const int dx[] = {-1, 0, 0, 1, 0, -1, -1, 1, 1};
const int dy[] = {0, -1, 1, 0, 0, 1, -1, 1, -1};

//
template <typename T>
void chmax(T &a, T b) { a = max(a, b); }
template <typename T>
void chmin(T &a, T b) { a = min(a, b); }
//
inline int toInt(string s) {
  int v;
  istringstream sin(s);
  sin >> v;
  return v;
}
template <class T>
inline string toString(T x) {
  ostringstream sout;
  sout << x;
  return sout.str();
}

//
struct Accelerate_Cin {
  Accelerate_Cin() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout << fixed << setprecision(20);
  };
};

struct edge {
  int to, cost;
};

int n, m, s, t, V = 101000;
const int MAX_V = 101010;

struct Dijkstra {
  int d[MAX_V];
  vector<edge> G[MAX_V];

  void dijkstra(int s) {
    // priority_queueは小さい順に取り出す。
    priority_queue<P, vector<P>, greater<P>> que;
    fill(d, d + V, INF);
    d[s] = 0;
    que.push(P(0, s));

    while (!que.empty()) {
      P p = que.top();
      que.pop();
      int v = p.second;
      if (d[v] < p.first)
        continue;
      for (int i = 0; i < G[v].size(); i++) {
        edge e = G[v][i];
        if (d[e.to] > d[v] + e.cost) {
          d[e.to] = d[v] + e.cost;
          que.push(P(d[e.to], e.to));
        }
      }
    }
  }
};

Dijkstra de, ds;

signed main() {
  cin >> n >> m >> s >> t;
  n--, s--, t--;
  for (int i = 0; i < m; i++) {
    int u, v, a, b;
    cin >> u >> v >> a >> b;
    u--, v--;
    de.G[u].push_back({v, a});
    de.G[v].push_back({u, a});
    ds.G[u].push_back({v, b});
    ds.G[v].push_back({u, b});
  }

  de.dijkstra(s);
  ds.dijkstra(t);

  vec tmp;
  int mx = -INF;
  for (int i = n; i >= 0; i--) {
    mx = max(mx, (int)1e15 - de.d[i] - ds.d[i]);
    tmp.push_back(mx);
  }

  reverse(ALL(tmp));

  for (auto x : tmp) cout << x << endl;
  return 0;
}


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

int main() {
    int n,sum=0;
    cin>>n;
    vector<int> v(n),c(n);

    rep(i,n) cin>>v.at(i);
    rep(i,n) cin>>c.at(i);
    rep(i,n) {
        if (v.at(i)>c.at(i)) {
            sum+=v.at(i);
            sum-=c.at(i);
        }
    }
    cout<<sum<<endl;
}

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

int main()
{
    int a;
    cin>>a;
    int b;
    cin>>b;
    if(a>=0 && a<=100)
    {

        if(b<=1000 && b%2==0)
        {
            if (a>=13)
            {
                cout<<b;
            }
            else if(6<=a && a<=12)
            {
               float y = 0.5;
               b=y*b;
                    cout<<b;
            }
            else if (a<=5)
                cout<<"0";
        }
    }


    return 0;
}

Measured memory_bytes: 256
extern crate core;

use std::fmt;
use std::i32::{MAX};
use std::cmp::{Ordering, min, max };
use std::ops::{Add, Sub, Mul, Div, Neg, Index, IndexMut, SubAssign, Range};
use std::collections::{BTreeMap, VecDeque, BinaryHeap, BTreeSet, HashMap};
use std::fmt::{Display, Formatter, Error};
use std::str::Chars;

fn show<T: Display>(vec: &Vec<T>) {
    if vec.is_empty() {
        println!("[]");
    }else {
        print!("[{}", vec[0]);
        for i in 1 .. vec.len() {
            print!(", {}", vec[i]);
        }
        println!("]");
    }
}
fn show2<T: Display>(vec: &Vec<Vec<T>>) {
    if vec.is_empty() {
        println!("[]");
    }else {
        for l in vec {
            show(l);
        }
    }
}
macro_rules! read_lines{
    ($count: expr; $delimiter: expr; $ty: ty) => {{
        let line_count = $count;
        let mut vec: Vec<Vec<$ty>> = Vec::with_capacity(line_count);
        for _ in 0 .. line_count {
            vec.push(read_line!($delimiter; $ty));
        }
        vec
    }};
    ($count: expr; $ty: ty) => {{
        let line_count = $count;
        let mut vec: Vec<$ty> = Vec::with_capacity(line_count);
        for _ in 0 .. line_count {
            vec.push(read_value!());
        }
        vec
    }}
}
macro_rules! read_line{
    () => {{
        let mut line = String::new();
        std::io::stdin().read_line(&mut line).ok();
        line
    }};
    (delimiter: ' ') => {
        read_line!().split_whitespace().map(|x|x.to_string()).collect::<Vec<_>>()
    };
    (delimiter: $p:expr) => {
        read_line!().split($p).map(|x|x.to_string()).collect::<Vec<_>>()
    };
    (' ') => {
        read_line!(delimiter: ' ')
    };
    ($delimiter:expr) => {
        read_line!(delimiter: $delimiter)
    };
    (' '; $ty:ty) => {
        read_line!().split_whitespace().map(|x|x.parse::<$ty>().ok().unwrap()).collect::<Vec<$ty>>()
    };
    ($delimiter:expr; $ty:ty) => {
        read_line!($delimiter).into_iter().map(|x|x.parse::<$ty>().ok().unwrap()).collect::<Vec<$ty>>()
    };
}
macro_rules! read_value{
    () => {
        read_line!().trim().parse().ok().unwrap()
    }
}
macro_rules! let_all {
    ($($n:ident:$t:ty),*) => {
        let line = read_line!(delimiter: ' ');
        let mut iter = line.iter();
        $(let $n:$t = iter.next().unwrap().parse().ok().unwrap();)*
    };
}

macro_rules! let_mut_all {
    ($($n:ident:$t:ty),*) => {
        let line = read_line!(delimiter: ' ');
        let mut iter = line.iter();
        $(let mut $n:$t = iter.next().unwrap().parse().ok().unwrap();)*
    };
}
fn main() {
    loop {
        let_all!(n: i32, m: usize); if n == 0 && m == 0 {break;}
        if read_line!(' '; i32).contains(&1i32) {
            println!("0.0000000000");
        } else {
            println!("{:.10}", n as f64 / 2f64);
        }
    }
}



Measured memory_bytes: 5056
#[allow(unused_imports)]
use proconio::{
    fastout, input,
    marker::{Bytes, Chars, Isize1, Usize1},
};

#[allow(unused_macros)]
macro_rules! echo {
    ($($e:expr),+) => ( { $(println!("{}", $e))+ } );
}

fn dfs(
    idx: usize,
    cs: &Vec<Vec<usize>>,
    mut skills: Vec<usize>,
    c: usize,
    mut c_min: usize,
    n: usize,
    x: usize,
) -> isize {
    if idx >= n {
        if skills.iter().all(|&s| s >= x) {
            c_min = std::cmp::min(c, c_min);
            return c_min.clone() as isize;
        } else {
            return -1;
        }
    }

    let a = dfs(idx + 1, cs, skills.clone(), c, c_min, n, x);

    let c = c + cs[idx][0];
    for (i, s) in skills.iter_mut().enumerate() {
        *s += cs[idx][i + 1];
    }

    let b = dfs(idx + 1, cs, skills.clone(), c, c_min, n, x);

    if a != -1 && b != -1 {
        return std::cmp::min(a, b);
    } else if a == -1 && b == -1 {
        return -1;
    } else {
        // 片方だけ -1
        return std::cmp::max(a, b);
    }
}

fn main() {
    input! {
        n: usize,
        m: usize,
        x: usize,
        cs: [[usize; m + 1]; n],
    }

    let ans = dfs(0, &cs, vec![0; m], 0, std::usize::MAX, n, x);

    echo!(ans);
}


Measured memory_bytes: 2152
from collections import defaultdict

n = int(input())
a = map(int, input().split())

dd = defaultdict(int)
s = 0
for i in a:
    s += i
    dd[i] = dd[i] + 1

q = int(input())
for i in range(q):
    bi, ci = map(int, input().split())
    if bi in dd:
        dd[ci] = dd[ci] + dd[bi]
        s = s - bi * dd[bi] + ci * dd[bi]
    dd[bi] = 0
    print(s)

Measured memory_bytes: 22052
#include<stdio.h>
#include<ctype.h>

int main(){

	int i;
	char s[500];

	while(scanf("%500[^\n]%*[^\n]",s)!=EOF){
		getchar();
		i=0;
		while(s[i]!='\0'){
			if(islower(s[i])) s[i]=s[i]-32;
			i++;

		}
		 printf("%s\n",s);


	}


	return 0;

}

Measured memory_bytes: 528
#include <cstdio>

int main(){
    int a,b,k;
    scanf("%d %d %d",&a,&b,&k);
    if(b - a >= k * 2){
        for(int i = a; i <= a + k - 1; i++){
            printf("%d\n",i);
        }
        for(int i = b - k + 1; i <= b; i++){
            printf("%d\n",i);
        }
    }else{
        for(int i = a; i <= b; i++){
            printf("%d\n",i);
        }
    }

    return 0;
}

Measured memory_bytes: 128
# import bisect
# import heapq
# from copy import deepcopy
# from collections import deque
# from collections import Counter
# from itertools import accumulate
# from itertools import permutations
# import numpy as np
# import math
# mod = 10**9 + 7

# n = int(input())

# s = deque(input())
s = input()

# a, b = map(int, input().split())
# a = list(map(int, input().split()))

count = 0
for i in range(len(s) // 2):
    count += 1 if s[i] != s[len(s)-1-i] else 0

print(count)

Measured memory_bytes: 2940
#include<iostream>
using namespace std;
int main(){
  int a,c,e;
  char b,d;
  cin>>a>>b>>c>>d>>e;
  if(a==2019&&c<4){
    cout<<"Heisei"<<endl;
  }
   else if(a==2019&&c==4&&e<=30){
    cout<<"Heisei"<<endl;
  }
  else if(a<2019){
    cout<<"Heisei"<<endl;
  }
  else{
    cout<<"TBD"<<endl;
  }
}


Measured memory_bytes: 256
# include <bits/stdc++.h>
# define sz(x) (int)((x).size())
# define F first
# define S second
# define pb push_back
# define ub upper_bound
# define lb lower_bound
# define all(x) x.begin(), x.end()
# define pqueue priority_queue
# define mset multiset
# define umap unordered_map
# define Speed() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
# define rep(i,n) for(int i=0;i<n;++i)
# define forn(i,n) for(int i=1;i<=n;++i)
# define lr(i,l,r) for(int i=l;(l>r?i>=r:i<=r);(l>r?--i:++i))

using namespace std;

template<class T> void umin(T &a,T b){a=min(a,b);}
template<class T> void umax(T &a,T b){a=max(a,b);}

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

const int dx[]={1,0,-1,0,-1,-1,1,1},dy[]={0,1,0,-1,-1,1,-1,1}; 
const int mod = 1e9+7;
const ll N = 1e5+4;

int n,m;
pqueue<int,vector<int>,greater<int>>a;

void solve(){
	cin>>n>>m;
	rep(i,n){
		int x;
		cin>>x;
		a.push(x);
	}
	vector<pii>v;
	rep(i,m){
		int x,y;
		cin>>x>>y;
		v.pb({y,x});
	}
	sort(all(v));
	reverse(all(v));
	int x=n,i=0;
	while(x--){
		if(v[i].S==0){
			if(i==n-1)break;
			i++;
		}
		if(v[i].F<=a.top()){
			break;
		}
		a.pop();
		a.push(v[i].F);
		--v[i].S;
	}
	ll ans=0;
	while(!a.empty()){
		ans+=a.top();
		a.pop();
	}
	cout<<ans;
}

int main(){
	Speed();
	int T=1; 
	//cin>>T;	
	while(T--)
		solve();
	return 0;
}

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

int main(){
  string s;
  cin >> s;
  deque<char> q;
  for( char c : s) q.push_back(c);
  bool flip = false;
  ull Q;
  cin >> Q;
  for(ull i=0;i<Q;i++){
    int t;
    cin >> t;
    if( t == 1 ){
      flip = !flip;
      continue;
    }
    int f;
    char c;
    cin >> f >> c;
    if( flip ) f = 3-f;
    if( f == 1 ){
      q.push_front(c);
    }else{
      q.push_back(c);
    }
  }
 
  if(flip) reverse(q.begin(),q.end());
  string ans;
  for(char c : q ) ans += c;
  cout << ans << endl;
      
  return 0;
}


Measured memory_bytes: 1412
#include<bits/stdc++.h>
#define M 10005
using namespace std;
int fac[M];
void sieve()
{
	fac[0]=fac[1]=1;
	int i,j;
	for(i=2;i*i<M;i++)
	{
        if(!fac[i])
		{
			for(j=i*i;j<M;j+=i)
				if(!fac[j])
				{
					fac[j]=1;
					
				}	
		}
	}

}
int main()
{
	sieve();
	
	int n;
	while(cin>>n)
	{
		int i,ans=0;
		
		
		for(i=1;i<=(n+1/2);i++)
		{
			if(!fac[i]&&!fac[n-i+1])
				ans++;
		}
		printf("%d\n",ans);
	}
	
	return 0;
}

Measured memory_bytes: 3076
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define all(x) (x).begin(),(x).end()
using namespace std;
const int INF=1145141919,MOD=1e9+7;
const long long LINF=1145141919810364364;

const int VMAX=100010;
int n;
bool used[VMAX];
int dist[VMAX][2];
vector<int> edge[VMAX];

void dfs(int from,int who){
	used[from]=1;
	for(auto i:edge[from]){
		if(!used[i]){
			dist[i][who]=dist[from][who]+1;
			dfs(i,who);
		}
	}
	return;
}

int main(){
	cin>>n;
	rep(i,n){
		int a,b; cin>>a>>b;
		edge[a].push_back(b);
		edge[b].push_back(a);
	}
	dfs(1,0);
	rep(i,VMAX) used[i]=0;
	dfs(n,1);
	int fen=0,snu=0;
	for(int i=1;i<=n;i++){
		// cout<<dist[i][0]<<" "<<dist[i][1]<<endl;
		if(dist[i][0]<=dist[i][1]) fen++;
		else snu++;
	}
	cout<<(fen>snu?"Fennec":"Snuke")<<endl;
    return 0;
}


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

for i in range(n):
    if a[i] < 0:
        a[i] = 0
    tmp = b[i] - a[i]
    if tmp <= 0:
        s += b[i]
    else:
        s += a[i]
        if a[i] >= 0:
            s += min(a[i+1],tmp)
            a[i+1] -= tmp
        else:
            a[i+1] -= b[i]
            s += b[i]
            
print(s)

Measured memory_bytes: 18624
#include <bits/stdc++.h>
#define int long long
#define f first
#define s second
using namespace std;
int32_t main(){
    ios::sync_with_stdio(0),cin.tie(0);
    int n,ok=1;
    cin >> n;
    int a[n];
    for(int i=0;i<n;i++)
    	cin >> a[i];
    a[0]--;
    for(int i=1;i<n;i++){
    	if(a[i]<a[i-1])ok=0;
    	else if(a[i]>a[i-1])a[i]--;
    }
    if(ok)cout << "Yes";
    else cout << "No";
}

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

#ifdef LOCAL
#include "debug.h"
#else
#define DEBUG(...)
#endif

template <class T, class Op = multiplies<T>>
constexpr T power(T a, long long n, Op op = Op(), T e = {1}) {
  assert(n >= 0);
  while (n) {
    if (n & 1) e = op(e, a);
    if (n >>= 1) a = op(a, a);
  }
  return e;
}

template <unsigned M> struct modular {
  using m = modular;
  static constexpr unsigned mod = M;
  unsigned v;
  modular(long long x = 0) : v((x %= mod) < 0 ? x + mod : x) {}
  m operator-() const { return m() -= *this; }
  m& operator+=(m b) { if ((int)(v += b.v - mod) < 0) v += mod; return *this; }
  m& operator-=(m b) { if ((int)(v -= b.v) < 0) v += mod; return *this; }
  m& operator*=(m b) { v = (uint64_t)v * b.v % mod; return *this; }
  m& operator/=(m b) { return *this *= power(b, mod - 2); }
  friend m operator+(m a, m b) { return a += b; }
  friend m operator-(m a, m b) { return a -= b; }
  friend m operator*(m a, m b) { return a *= b; }
  friend m operator/(m a, m b) { return a /= b; }
  friend bool operator==(m a, m b) { return a.v == b.v; }
};

using mint = modular<power(10, 9) + 7>;

vector<mint> fact, inv_fact, minv;
void prepare(int n) {
  fact.resize(n + 1), inv_fact.resize(n + 1), minv.resize(n + 1);
  for (int i = 0; i <= n; ++i) fact[i] = i ? fact[i - 1] * i : 1;
  inv_fact[n] = power(fact[n], mint::mod - 2);
  for (int i = n; i--; ) inv_fact[i] = (i + 1) * inv_fact[i + 1];
  for (int i = 1; i <= n; ++i) minv[i] = inv_fact[i] * fact[i - 1];
}
mint binom(int n, int k) {
  if (k < 0 or k > n) return 0;
  return fact[n] * inv_fact[k] * inv_fact[n - k];
}
template <> mint& mint::operator/=(mint b) {
  return *this *= b.v < minv.size() ? minv[b.v] : power(b, mod - 2);
}

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  prepare(n + m);
  mint res;
  for (int k = 0; k <= n; ++k) {
    res += power(-1, k) * binom(n, k) * binom(m, k) * fact[k] * power(binom(m - k, n - k) * fact[n - k], 2);
  }
  cout << res.v << '\n';
}


Measured memory_bytes: 14964