akhauriyash/Code-Regression huggingface dataset:
#pragma GCC optimize(2)
#include<bits/stdc++.h>
#define ll long long
#define maxn 1000005
#define inf 1e9
#define pb push_back
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define per(i,a,b) for(int i=a;i>=b;i--)
using namespace std;

inline int read()
{
	int x=0,w=1; char c=getchar();
	while(c<'0'||c>'9') {if(c=='-') w=-1; c=getchar();}
	while(c<='9'&&c>='0') {x=(x<<1)+(x<<3)+c-'0'; c=getchar();}
	return w==1?x:-x;
}

ll n,a[maxn],ans;

int main()
{
	n=read(); rep(i,1,n) a[i]=read();
	rep(i,1,n) if(a[i]-a[i-1]>1||a[i]>i-1) return puts("-1"),0;
	rep(i,1,n) if(a[i]-a[i-1]!=1) ans+=a[i]; else ans++; cout<<ans<<endl;
	return 0;
}

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

int main(){

    long long int n,i;
    cin >> n;
    string S[n];

    for(i=0;i<n;i++) {
        cin >> S[i];
        sort(S[i].begin(), S[i].end());
    }

    sort(S, S+n);

    long long int count =0, ans=0;
    for(i=0;i<n-1;i++){
        if(S[i]==S[i+1])
            count++;
        else{
            ans += count*(count+1)/2;
            count = 0;
        }
    }

    if(count!=0)
        ans+= count*(count+1)/2;

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

Measured memory_bytes: 6752
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
using namespace std;

int A, B;
int S[5010];
int T[5010];

int main() {
  cin >> A >> B;
  for (int i=0; i<A; i++) cin >> S[i];
  for (int i=0; i<B; i++) cin >> T[i];

  int ans = 0;
  for (int i=0; i<B; i++) {
    int cnt = 0;
    for (int j=0; j<A && i+cnt<B; j++) {
      if (S[j] == T[i+cnt]) cnt++;
    }
    ans = max(ans, cnt);
  }
  cout << ans << "\n";
  return 0;
}

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

int main(){
  int N,Y;
  cin>>N>>Y;
  
  int x=0,y=0,z;
  int xa,ya,za;
  bool flag =false;
  
  for(x=0;x<=2000;x++){
    for(y=0;y<=2000;y++){
      z=N-x-y;
       if(10000*x+5000*y+1000*z==Y and z>=0){
         flag=true;
         xa=x;
         ya=y;
         za=z;
       }
      
    }
  }
  if(flag){
    cout<<xa<<endl<<ya<<endl<<za<<endl;
  }else{
    cout<<-1<<endl<<-1<<endl<<-1<<endl;
  }
  
}

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

int main(){

    string S, T;
    int res=0;
    cin >> S;
    cin >> T;

    int length = S.length();
    for(int i=0; i<length; i++){
        if(S.at(i) != T.at(i))
            res++;
    }

    cout << res << endl;

}

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

typedef long long ll;

int main(void){
    int n;
    cin >> n;
    vector<vector<int>> array(n, vector<int>(n));
    for(int i=0; i<n; i++){
        for(int j=0; j<n; j++){
            cin >> array[i][j];
        }
    }

    vector<vector<int>> array2(array);

    for(int k=0; k<n; k++){
        for(int i=0; i<n; i++){
            for(int j=0; j<n; j++){
                bool judge = false;
                if(i == k || j == k){
                    continue;
                }
                if(array[i][k] + array[k][j] < array[i][j]){
                    cout << -1 << endl;
                    return 0;
                }else if(array[i][k] + array[k][j] == array[i][j]){
                    array2[i][j] = 0;
                }
            }
        }
    }

    ll ans = 0;

    for(int i=0; i<n; i++){
        for(int j=i; j<n; j++){
            ans += array2[i][j];
        }
    }

    cout << ans << endl;



    return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll A[14][14],C[14];
int main()
{
    ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    ll n,m,x;
    cin>>n>>m>>x;
    for(int i=0;i<n;i++)
    {
        cin>>C[i];
        for(int j=0;j<m;j++)
        {
            cin>>A[i][j];
        }
    }
    ll Ans=1e12;
    for(int i=0;i<=4095;i++)
    {
         string s = bitset<12>(i).to_string();
        ll Cost=0,ul[14];
        memset(ul,0,sizeof(ul));
         for(int j=0;j<s.size();j++)
         {
             if(s[j]=='0')
                continue;
             Cost+=C[j];
             for(int k=0;k<m;k++)
             {
                 ul[k]+=A[j][k];
             }
         }
         bool flag=true;
         for(int j=0;j<m;j++)
         {
             if(ul[j]<x)
                flag=false;
         }
         if(flag==true)
            Ans=min(Ans,Cost);
    }
    if(Ans==1e12)
        cout<<-1<<endl;
    else
    cout<<Ans<<endl;


    return 0;
}


Measured memory_bytes: 3656
from collections import namedtuple, deque

class Person:
    def __init__(self, id, conn, x):
        self.id = id
        self.conn = conn
        self.x = x

def main():
    with open(0) as f:
        N, M = map(int, f.readline().split())
        info = [tuple(map(int, line.split())) for line in f.readlines()]
    people = [Person(i, conn=[], x=None) for i in range(N)]
    for l, r, d in info:
        people[l-1].conn.append((r-1, d))
        people[r-1].conn.append((l-1, -d))
    
    for person in people:
        if person.x is not None:
            continue
        else:
            person.x = person.id
            #bfs
            reserved = deque([person])
            seen = {person.id}
            while len(reserved) > 0:
                current = reserved.popleft()
                for next_person_id, d in current.conn:
                    if people[next_person_id].x is None:
                        people[next_person_id].x = current.x + d
                    else:
                        if people[next_person_id].x != current.x + d:
                            print('No')
                            return None
                    if next_person_id in seen:
                        continue
                    seen.add(next_person_id)
                    reserved.append(people[next_person_id])
    print('Yes')

main()            

Measured memory_bytes: 119860
module Main (main) where

import qualified Data.ByteString.Char8     as C8
import           Data.Maybe

main :: IO ()
main = do
  [n] <- readInts
  print . showAnswer $ solve n

type Input  = (Int)
type Output = Bool

solve :: Input -> Output
solve = f .  show
  where
    f xs = g (init xs) || g (tail xs)
    g [x,y,z] = x == y && x == z

showAnswer :: Output -> Answer
showAnswer = YesNo

-- utils
readInts :: IO [Int]
readInts = map (fst . fromJust . C8.readInt) . C8.words <$> C8.getLine

data Answer
  = YesNo Bool
  | YESNO Bool
  | AB Bool
  | Number Int
  | Compare Ordering

instance Show Answer where
  show (YesNo b)   = if b then "Yes" else "No"
  show (YESNO b)   = if b then "YES" else "NO"
  show (AB b)      = if b then "A"   else "B"
  show (Number i)  = show i
  show (Compare o)
    | o == EQ = "="
    | o == LT = "<"
    | o == GT = ">"

Measured memory_bytes: 380
a = []
for i in range(5):
    tmp = input()
    a.append(int(tmp))
k = int(input())
ans = True
for i in range(len(a)):
    for j in range(i, len(a)):
        if(a[j] - a[i] > k):
            ans = False
if ans:
    print("Yay!")
else:
    print(":(")

Measured memory_bytes: 3064
N = int(input())
a = []
for i in range(N):
    a.append(i+1)
    if a[i] % 15 == 0:
        a[i] = 0
    elif a[i] % 5 == 0:
        a[i] = 0
    elif a[i] % 3 == 0:
        a[i] = 0

print(sum(a))


Measured memory_bytes: 33676
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,b,a) for(int i=b;i>=a;i--)
#define fori(a) for(auto i : a )
#define all(a) begin(a), end(a)
#define set(a,b) memset(a,b,sizeof(a))
#define sz(a) a.size()
#define pi 3.14159
#define ll long long
#define ull unsigned long long
#define pb push_back
#define PF push_front //deque
#define mp make_pair
#define pq priority_queue
#define mod 1000000007
#define f first
#define s second
#define pii pair< int, int >
#define vi vector<int>
#define vpii vector<pii>
#define debug(v) for(auto i:v) cout<<i<<" ";
#define tc int t; cin >> t; while(t--)
using namespace std;
void optimizeIO(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}
int dp[509][509];
int C[509][509];
int recurr(int i,int j){
  if(dp[i][j]!=-1) return dp[i][j];
  if(i==j) {dp[i][j]=C[i][j]; return dp[i][j];}
  // number of line segements b/w i & j = line segement from i to j and line segments b/w i to j-1
  // and line segments b/w i+1 to j - line segments included in both(i to j-1, i+1 to j) range i.e i+1 to j-1
  dp[i][j]=C[i][j]+recurr(i,j-1)+recurr(i+1,j)-recurr(i+1,j-1);
  return dp[i][j];
}
void  solve(){
  int n,m,Q,l,r;
  cin>>n>>m>>Q;
  rep(i,0,m){
    cin>>l>>r;
    C[l][r]++;
  }
  rep(i,1,n+1) rep(j,1,n+1) dp[i][j]=-1;

  recurr(1,n);

  rep(i,0,Q){
    cin>>l>>r;
    cout<<dp[l][r]<<endl;
  }

}
int main(){
    optimizeIO();
    solve();
}


Measured memory_bytes: 5696
time = -1
place = ["a","b","c","d","e","f","g","h","i"]
empty_count={}
for i in place:
	empty_count[i] = 0
count_d = empty_count.copy()	

def reset():
	global d
	global count_d
	d={"a":["a","a","b","d"],"b":["a","e","c","b"],"c":["b","f","c","c"],"d":["a","e","g","d"],"e":["b","d","f","h"],"f":["c","e","i","f"],"g":["d","h","g","g"],"h":["g","e","i","h"],"i":["f","h","i","i"]}
	count_d = empty_count.copy()
	
	
def pre_set(start_place,fix_place):
	global d
	global count_d
	for i in place:
		d[i] = list(("").join(d[i]).replace(fix_place,i))
	count_d[start_place] = 1
	
def repeat(time):
	global count_d
	for i in range (time):
		new_count_d = empty_count.copy()
		old_count_d = count_d.copy()
		for j in place:
			for k in d[j]:
				new_count_d[k] += old_count_d[j]
		count_d = new_count_d.copy() 

while time != 0:
	time = int(raw_input())
	if time == 0:
		break
	else:
		info_pre = raw_input().split()
		info = []
		for i in info_pre:
			info.append(i.lower())
		
	reset()
	pre_set(info[0],info[2])
	repeat(time)
	print (count_d[info[1]])/float((4**time))
	
		
	

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

using namespace std;

#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define FORR(i, a, b) for(int i = (a); i > (b); --i)
#define REP(i, n) for(int i = 0; i < (n); ++i)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOREACH(x, a) for(auto &(x) : (a))
#define VECCIN(x)                                                              \
    for(auto &youso_ : (x)) cin >> youso_
#define mp make_pair
#define bitcnt __builtin_popcount
#define All(a) (a).begin(), (a).end()
template <typename T = long long> inline T IN() {
    T x;
    cin >> x;
    return (x);
}
inline void CIN() {}
template <class Head, class... Tail>
inline void CIN(Head &&head, Tail &&... tail) {
    cin >> head;
    CIN(move(tail)...);
}
#define CINT(...)                                                              \
    int __VA_ARGS__;                                                           \
    CIN(__VA_ARGS__)
#define LCIN(...)                                                              \
    ll __VA_ARGS__;                                                            \
    CIN(__VA_ARGS__)
#define SCIN(...)                                                              \
    string __VA_ARGS__;                                                        \
    CIN(__VA_ARGS__)
#define Yes(a) cout << (a ? "Yes" : "No") << "\n"
#define YES(a) cout << (a ? "YES" : "NO") << "\n"

typedef long long ll;
typedef vector<int> V;
typedef vector<ll> VL;
typedef pair<int, int> P;
typedef pair<ll, ll> PL;
typedef priority_queue<int> PQ;
typedef priority_queue<int, V, greater<int>> PQG;

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

int N;

int main() {
    cin >> N;
    if(N == 3) {
        cout << 2 << " " << 5 << " " << 63 << " "
             << "\n";
        return 0;
    }
    if(N % 2) {
        int table[8] = {6, 2, 4, 3, 9, 8, 10, 12};
        REP(i, N / 8 + 1) {
            if(i == N / 8) {
                REP(j, N % 8) { cout << 12 * i + table[j] << " "; }
                cout << "\n";
                return 0;
            }
            REP(j, 8) { cout << 12 * i + table[j] << " "; }
        }
    } else {
        int table[8] = {2, 4, 3, 9, 8, 10, 6, 12};
        REP(i, N / 8 + 1) {
            if(i == N / 8) {
                REP(j, N % 8) { cout << 12 * i + table[j] << " "; }
                cout << "\n";
                return 0;
            }
            REP(j, 8) { cout << 12 * i + table[j] << " "; }
        }
    }
}

Measured memory_bytes: 384
ary = []
ary << gets.to_i
ary << gets.to_i
ary << gets.to_i
ary << gets.to_i
ary << gets.to_i
k = gets.to_i
m = 0

for j in 0..3
    for i in 1..4
        u = (ary[i].to_i - ary[j].to_i)
        if u > k
            m += 1
        end
    end
end

if m > 0
    puts ":("
else
    puts "Yay!"
end


Measured memory_bytes: 1788
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<cstdio>
#include<sstream>
#include<iomanip>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
using namespace std;
//kaewasuretyuui
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef pair<int,pii> pip;
typedef vector<pip>vip;
const double PI=acos(-1);
const double EPS=1e-8;
const int inf=1e8;
ll MOD1=134832894;
ll MOD2=183489237;
ll x1=52452452;
ll x2=34567343;
vector<ll>hash1,hash2,X1,X2;
int n;
int f(int i){
	set<pair<ll,ll> >se;
	rep(j,n-i){
		ll a1=(hash1[i+j+1]-hash1[j]+MOD1)%MOD1*X1[n-(i+j+1)]%MOD1;
		ll a2=(hash2[i+j+1]-hash2[j]+MOD2)%MOD2*X2[n-(i+j+1)]%MOD2;
		se.insert(pair<ll,ll>(a1,a2));
	}
	return se.size();
}
int main(){
	string s;
	cin>>s;
	n=s.size();
	X1=X2=vector<ll>(n+1);
	X1[0]=X2[0]=1;
	rep(i,n){
		X1[i+1]=(X1[i]*x1)%MOD1;
		X2[i+1]=(X2[i]*x2)%MOD2;
	}
	hash1=hash2=vector<ll>(n+1);
	rep(i,n){
		hash1[i+1]=(s[i]-'a')*X1[i+1];
		hash2[i+1]=(s[i]-'a')*X2[i+1];
	}
	rep(i,n){
		hash1[i+1]=(hash1[i+1]+hash1[i])%MOD1;
		hash2[i+1]=(hash2[i+1]+hash2[i])%MOD2;
	}
//	rep(i,n){
	int l=0,r=n;
	while(r-l>2){
		int h1=l+(r-l)/3,h2=l+(r-l)/3*2;
//		cout<<l<<" "<<h1<<" "<<h2<<" "<<r<<endl;
		int H1=f(h1),H2=f(h2);
//		cout<<H1<<" "<<H2<<endl;
		if(H1>H2)r=h2;
		else l=h1;
	}
	int out=0;
	loop(i,l,r)out=max(out,f(i));
	cout<<out<<endl;
}






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

int main()
{
    int N, H;
    cin >> N >> H;
    vector<pair<int, int>> katana(N);
    rep(i, N)
    {
        int a, b;
        cin >> a >> b;
        katana[i] = make_pair(a, b);
    }
    sort(katana.rbegin(), katana.rend());
    vector<int> throw_attack;
    long long sum_only_throw = 0;
    rep(i, N - 1)
    {
        if (katana[0].first <= katana[i + 1].second)
        {
            sum_only_throw += katana[i + 1].second;
            throw_attack.push_back(katana[i + 1].second);
        }
    }

    sum_only_throw += katana[0].second;

    sort(throw_attack.rbegin(), throw_attack.rend());
    long long ans = 0;
    if (H <= sum_only_throw)
    {
        throw_attack.push_back(katana[0].second);
        sort(throw_attack.rbegin(), throw_attack.rend());

        rep(i, throw_attack.size())
        {
            H -= throw_attack[i];
            ans++;
            if (H <= 0)
                break;
        }
    }
    else
    {
        H -= sum_only_throw;
        ans += throw_attack.size() + 1;
        ans += H / katana[0].first + 1;
        if (H % katana[0].first == 0)
            ans--;
    }

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

Measured memory_bytes: 1660
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		String[] s = new String[n];
		for (int i = 0; i < n; i++) {
			char[] c = sc.next().toCharArray();
			Arrays.sort(c);
			s[i] = String.valueOf(c);
		}
		sc.close();

		Map<String, Integer> map = new HashMap<>();
		for (int i = 0; i < n; i++) {
			addCntMap(map, s[i]);
		}

		long ans = 0;
		for (long val : map.values()) {
			ans += val * (val - 1) / 2;
		}
		System.out.println(ans);
	}

	static void addCntMap(Map<String, Integer> map, String key) {
		if (map.containsKey(key)) {
			map.put(key, map.get(key) + 1);
		} else {
			map.put(key, 1);
		}
	}
}


Measured memory_bytes: 52352
h, w = map(int, input().split())
s = [input() for _ in range(h)]

start = (0, 0)
goal = (h-1, w-1)

dx = [1, 0, -1, 0]
dy = [0, 1, 0, -1]

d = [[0 for i in range(w)] for i in range(h)] # 最小距離

from queue import Queue

q = Queue()

# 初期化
for i in range(h):
    for j in range(w):
        d[i][j] = float('inf')

q.put((0, 0))
d[start[0]][start[1]] = 0

# queueが空になるまでループ
while q.qsize():
    # キューの先頭
    p = q.get()

    # ゴールに到着したら終了
    if p[0] == goal[0] and [1] == goal[1]:
        break

    # 移動
    for i in range(4):
        nx = p[0] + dx[i]
        ny = p[1] + dy[i]
        if 0 <= nx and nx < h and 0 <= ny and ny < w:
            if s[nx][ny] == '.' and d[nx][ny] == float('inf'):

                q.put((nx, ny))
                d[nx][ny] = d[p[0]][p[1]] + 1

dist = d[goal[0]][goal[1]]
if dist == float('inf'):
    print(-1)
else:
    count_w = 0
    for i in range(h):
        for j in range(w):
            if s[i][j] == '.':
                count_w += 1
    print(count_w - dist - 1)


Measured memory_bytes: 45800
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef tree<pair<int,int>, null_type, less<pair<int,int>>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define PI 3.14159265358979323846
using namespace std;
typedef long long ll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef pair<ll, ll> pii;
typedef long double ld;
typedef string st;
const ll MOD = 1e9 + 7 ;
const ll INF=1e14;
ll mpow(ll a,ll b,ll p=MOD){a=a%p;ll res=1;while(b>0){if(b&1)res=(res*a)%p;a=(a*a)%p;b=b>>1;}return res%p;}
const ll N=500020;

int main(){
      ios_base::sync_with_stdio(false);
      cin.tie(NULL);
   
      ll n;
      cin>>n;
      ll a[n];
      forn(i,n) cin>>a[i];
      sort(a,a+n);
      ll s=0;
      forn(i,n-1) s+=a[i];
      if(a[n-1]<s)
      {
        cout<<"Yes\n";
      }
      else cout<<"No\n";
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define For(i,n,k) for(int i=(n);i<(k);i++)
#define ALL(a)  (a).begin(),(a).end()
ll ans=0;
void Main(){
    ll n;cin>>n;
    ll m;cin>>m;
    vector<int> a(n),b(n);
    For(i,0,n) cin>>a[i]>>b[i];
    vector<int> c(m),d(m);
    For(i,0,m) cin>>c[i]>>d[i];
    For(i,0,n){
        int dist=1e9,num=-1;
        For(j,0,m){
            if(dist>abs(a[i]-c[j])+abs(b[i]-d[j])){
                num=j+1;
                dist=abs(a[i]-c[j])+abs(b[i]-d[j]);
            }
        }
        cout<<num<<endl;
    }
}
int main(){
    Main();
    /*
    東方風神録は神が出てくるので当然神ゲー
    */
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long int
#define ld long double
const ll MOD = 998244353;
const ll INF = 1e18;
using namespace std;

ll dp[1 << 20], pre[1 << 20];

main(){    
    #ifdef XOX
        freopen("D:\\V S Code\\cpp\\competitiveProgramming\\Input.txt", "r", stdin);
        freopen("D:\\V S Code\\cpp\\competitiveProgramming\\OPT.txt", "w", stdout);
    #endif

    ios::sync_with_stdio(!cin.tie(NULL));
    
    int n;
    cin >> n;
    memset(dp, 0, sizeof(dp));
    memset(pre, 0, sizeof(pre));

    ll tmp, mask;
    for(int i = 0; i < n; i++){
        for(int j = 0; j < n; j++){
            cin >> tmp;
            mask = (1 << i)|(1 << j);
            dp[mask] += tmp;
        }
    }

    for(int i = 0; i < n; i++){
        for(int mask = 0; mask < (1 << n); mask++){
            if(mask&(1 << i))   dp[mask] += dp[mask^(1 << i)];
        }
    }

    for(int mask = 0; mask < (1 << n); mask++){
        pre[mask] = dp[mask];
        for(int sub = mask; sub; sub = (sub - 1)&mask){
            pre[mask] = max(pre[mask], pre[sub] + dp[mask^sub]);
        }
    }

    cout << pre[(1 << n) - 1] / 2;  

}

Measured memory_bytes: 16768
#!/usr/bin/env python3
import sys

MOD = 1000000007  # type: int


def solve(N: int, C: "List[int]"):
    if N == 1:
        print(2*C[0]%MOD)
        return
    
    start = pow(2,N-1,MOD)
    distance = pow(2,N-2,MOD)

    count = [0]*N
    for i in range(N):
        count[i] = (start+distance*i)%MOD
    answer = 0
    C.sort(reverse=True)
    for i in range(N):
        answer += C[i]*count[i]
        answer%=MOD
    answer*=pow(2,N,MOD)
    answer%=MOD
    print(answer)


    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    C = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, C)

if __name__ == '__main__':
    main()


Measured memory_bytes: 36980
def witness(a, n, t, u):
    x = pow(a, u, n)  # x0 = a^u mod nを計算
    
    for _ in range(0, t):
        y = (x * x) % n

        # 法nの下での1の非自明な平方根が存在するのはnが合成数であるときに限る
        if y == 1 and x != 1 and x != (n - 1):
            return True
        x = y
    return y != 1

def is_probably_prime(n, witnesses):
    t = 1
    u = n >> 1
    while u & 1 == 0:
        t = t + 1
        u >>= 1
    assert(2**t * u == n - 1)

    for a in witnesses:
        if a < n and witness(a, n, t, u):
            return False
    return True

def is_definitely_prime(n):
    if ((not (n & 1)) and n != 2) or (n < 2) or ((n % 3 == 0) and (n != 3)):
        return False
    elif n <= 3:
        return True
    else:
        return is_probably_prime(n, [2, 7, 61])

n = int(input())
answer = 0
for _ in range(0, n):
    m = int(input())
    if is_definitely_prime(m):
        answer = answer + 1
print(answer)


Measured memory_bytes: 5616
#include<bits/stdc++.h>
#define int long long
using namespace std;
constexpr int mod=1e9+7;
int f(int x){
    for(int ans=0;;x%=__builtin_popcount(x),ans++){
        if(x==0)
            return ans;
    }
}
int a[200000],b[200000];
signed main(){
    int n;
    string x;
    cin>>n>>x;
    int popx=count(x.begin(),x.end(),'1');
    if(popx==1){
        if(x.back()=='1'){
            for(int i=0;i<n-1;i++)
                cout<<2<<endl;
            cout<<0<<endl;
        }else{
            for(int i=0;i<n-1;i++)
                cout<<(x[i]=='1'?0:1)<<endl;
            cout<<2<<endl;
        }
      return 0;
    }
    a[n-1]=b[n-1]=1;
    for(int i=n-2;i>=0;i--){
        a[i]=a[i+1]*2%(popx+1);
        b[i]=b[i+1]*2%(popx-1);
    }
    int aa=0,bb=0;
    for(int i=0;i<n;i++){
        if(x[i]=='1'){
            (aa+=a[i])%=popx+1;
            (bb+=b[i])%=popx-1;
        }
    }
    for(int i=0;i<n;i++){
        if(x[i]=='1')
            cout<<f((bb-b[i]+popx-1)%(popx-1))+1<<endl;
        else
            cout<<f((aa+a[i])%(popx+1))+1<<endl;
    }
}


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

using namespace std;

int main(void){

  int n;
  while(cin >> n,n){
    vector<int>v(n);
    for(int i=0;i<n;i++)cin >> v[i];
    sort(v.begin(),v.end());
    int sum=0;
    for(int i=1;i<n-1;i++)sum+=v[i];
    cout << sum/(n-2) << endl;
  }

  return 0;
}

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

int  main(){
  int l,a,b,c,d,k,s;
  cin>>l>>a>>b>>c>>d;
  k=a/c;
  s=b/d;
  if(a%c!=0)k++;
  if(b%d!=0)s++;
  if(k>s)cout<<l-k<<endl;
  else cout<<l-s<<endl;
  return 0;
}

Measured memory_bytes: 1160
#include<bits/stdc++.h>
#define endl '\n'
#define mod 1000000007
#define ll long long
#define trace(x) cerr << #x << " = " << x << endl
using namespace std;

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

    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int t=1; 
    while(t--){
         int n, d;
	 cin>>n>>d;
	 int count =0;
	 ll x, y;
	 for(int i =0 ; i< n;i++){
		 cin>>x>>y;
		   double res= ( double)sqrt((ll)x*x + (ll)y*y);
		 if(res<=(double)d)
			 count++;
	 }
	 cout<<count<<endl;
    }
    return 0;
} 


Measured memory_bytes: 3640
a = [input().split() for _ in range(3)]
n = int(input())
b = [input() for _ in range(n)]

p = []
p += a
p += [list(a_) for a_ in zip(*a)]
p += [[a[x][x] for x in range(3)]]
p += [[a[x][2-x] for x in range(3)]]

for p_ in p:
    for x in p_:
        if x in b:
            continue
        else:
            break
    else:
        print('Yes')
        break
else:
    print('No')


Measured memory_bytes: 3064
#include <iostream>
#include<queue>
#include<stack>
#include<vector>
#include<set>
#include<map>
#include<algorithm>
#include<cstring>
#include<string>
#include<cassert>
#include<cmath>
#include<climits>
#include<iomanip>
#include<bitset>
#include<unordered_map>

using namespace std;

#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define rep(i,j,n) for(ll (i)=(j);(i)<(n);(i)++)
#define FOR(i,c) for(decltype((c).begin())i=(c).begin();i!=(c).end();++i)
#define ll long long
#define ull unsigned long long
#define all(hoge) (hoge).begin(),(hoge).end()
typedef pair<ll, ll> P;
const long long INF = 1LL << 60;
const long long MOD = 1e9 + 7;
typedef vector<ll> Array;
typedef vector<Array> Matrix;


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;
}

//グラフ関連
struct Edge {//グラフ
	ll to, cap, rev;
	Edge(ll _to, ll _cap, ll _rev) {
		to = _to; cap = _cap; rev = _rev;
	}
};
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;

void add_edge(Graph& G, ll from, ll to, ll cap, bool revFlag, ll revCap) {
	G[from].push_back(Edge(to, cap, (ll)G[to].size()));
	if (revFlag)G[to].push_back(Edge(from, revCap, (ll)G[from].size() - 1));
}

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

	ll i, j, k;
	cin >> i >> j >> k;

	if (i + j + k >= 22) {
		cout<<"bust"<<endl;
	}
	else {
		cout << "win" << endl;
	}

	return 0;
}

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

using namespace std;

int main()
{
    int n, x[101];

    cin >> n;

    for (int i = 0; i < n; i++)
    {
        cin >> x[i];
    }

    int stamina, min_stamina;
    min_stamina = 1e6;

    for (int p = 0; p <= 100; p++)
    {
        stamina = 0;
        for (int i = 0; i < n; i++)
        {
            int z = p - x[i];
            stamina = stamina + (z*z);
        }

        min_stamina = min(min_stamina, stamina);
    }

    cout << min_stamina << "\n";

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
    int n, count=0;
    cin>>n;
    while(n)
    {
        int rem=n%10;
        if(rem == 7)
        {
            count++;
        }
        n=n/10;
    }
    if(count == 0)
       cout<<"No";
    else
       cout<<"Yes";
return 0;
}
    

Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define len(v) ll(v.size())
#define fi first
#define se second

template <class T>
void cout_vec(const vector<T> &vec){
  for(auto itr:vec) cout<<itr<<' ';
  cout<<endl;
}

typedef pair<ll,ll> P;
const ll mod=1e9+7;
const ll inf=1e15;

int n,k;
vector<vector<int>> g(4010,vector<int>(4010,0)),cnt(4010,vector<int>(4010,0));

int get(int x1,int y1,int x2,int y2){
  int ret=cnt[x2][y2];
  if(x1>0) ret-=cnt[x1-1][y2];
  if(y1>0) ret-=cnt[x2][y1-1];
  if(x1>0 && y1>0) ret+=cnt[x1-1][y1-1];
  return ret;
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin>>n>>k;
  rep(i,n){
    ll x,y;
    char c;
    cin>>x>>y>>c;
    if(c=='W') y+=k;
    x%=2*k;
    y%=2*k;
    g[x][y]++;
  }
  rep(i,4*k)rep(j,4*k){
    if(i<2*k && j<2*k) continue;
    g[i][j]=g[i%(2*k)][j%(2*k)];
  }
  cnt[0][0]=g[0][0];
  FOR(j,1,4*k) cnt[0][j]=cnt[0][j-1]+g[0][j];
  FOR(i,1,4*k) cnt[i][0]=cnt[i-1][0]+g[i][0];
  FOR(i,1,4*k)FOR(j,1,4*k) cnt[i][j]=cnt[i][j-1]+cnt[i-1][j]-cnt[i-1][j-1]+g[i][j];
  int ans=0;
  rep(i,2*k)rep(j,2*k) ans=max(ans,get(i,j,i+k-1,j+k-1)+get(i+k,j+k,i+2*k-1,j+2*k-1));
  cout<<ans<<endl;
}

Measured memory_bytes: 126208
#include <bits/stdc++.h> <bits/stdc++.h>
using namespace std;
#define int long long
priority_queue<int>q;
signed main(){
	int n,m,i;
	scanf("%lld%lld",&n,&m);
	for (i=1;i<=n;i++){
		int x;
		scanf("%lld",&x);
		q.push(x);
	}
	while(m--){
        int x=q.top();
		q.pop();
		q.push(x/2);
	}
	int ans=0;
	while(q.size()){
		ans+=q.top();
		q.pop();
	}
	printf("%lld\n",ans);
	return 0;
}

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

//nC2
ll choose2(ll n)
{
    return n *(n-1)/2;
}

int main(void) 
{
    string s;
    cin >> s;
    int n = s.size();

    int sep = (n -1)/2;
    string first = s.substr(0, sep);
    string end = s.substr(sep + 1, sep);

    if(first == end)
    {
        cout << "Yes" << endl;
        return 0;
    }
   
    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
import sys
 
def gcd(inta, intb):
    large = max(inta, intb)
    small = min(inta,intb)
    mod = large % small
    if mod ==0:
        return small
    else:
        return gcd(small, mod) 
     
def lcm(inta, intb, intgcd):
    return (inta * intb // intgcd)
 
sets = sys.stdin.readlines()
for line in sets:
    a, b = map(int, line.split())
    c = gcd(a, b)
    print(c, lcm(a, b, c))

Measured memory_bytes: 7624
#include<stdio.h>
int f[44];
void fibonacci(int n) 
{
  int i;
  f[0]=f[1]=1;
  for(i=2; i<=n; i++){
    f[i] = f[i-2] + f[i-1];
  }
}
 
int main() 
{
  int n;
  scanf("%d",&n);
  fibonacci(n);
  printf("%d\n",f[n]);
  return 0;
}

Measured memory_bytes: 596
#include <iostream>
#include <cmath>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <map>
using namespace std;
int f[1<<18],g[1<<18];
int n,m;
int main(){
	scanf("%d",&n);
	for (int i=0;i<(1<<n);i++) scanf("%d",&f[i]);
	for (int i=1;i<=n;i++)
		for (int j=0;j<(1<<n);j++)
			if (j&(1<<i-1)){
				int pre=j-(1<<i-1);
				if (f[j]>=f[pre]) g[j]=max(g[j],f[pre]);
				else {
					g[j]=max(f[j],g[pre]); f[j]=f[pre];
				}
			}
	int now=0;
	for (int i=1;i<(1<<n);i++){
		now=max(now,f[i]+g[i]);
		printf("%d\n",now);
	}
}

Measured memory_bytes: 5120
N = int(input())
H = list(map(int, input().split()))
 
ans = 0
tmp = 0
for i in range(N-1):
	if H[i] >= H[i+1]:
		tmp += 1
	else:
		if ans < tmp:
			ans = tmp
		tmp = 0
if ans < tmp:
	ans = tmp
 
print(ans)

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

int main()
{
    int n;
    cin>>n;
    int arr[n+1],cnt=0;
    for(int i=1;i<=n;i++)
    {
        cin>>arr[i];
        if(i&1 && arr[i]&1)
            cnt++;
    }
    cout<<cnt<<endl;
    return 0;
}


Measured memory_bytes: 3592
#include <cassert>
#include <cstdio>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <numeric>
#include <algorithm>

using namespace std;
using lint = long long;
constexpr int MOD = 1000000007, INF = 1010101010;
constexpr lint LINF = 1LL << 60;

template <class T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
	for (const auto &e : vec) os << e << (&e == &vec.back() ? "\n" : " ");
	return os;
}

#ifdef _DEBUG
template <class T>
void dump(const char* str, T &&h) { cerr << str << " = " << h << "\n"; };
template <class Head, class... Tail>
void dump(const char* str, Head &&h, Tail &&... t) {
	while (*str != ',') cerr << *str++; cerr << " = " << h << "\n";
	dump(str + (*(str + 1) == ' ' ? 2 : 1), t...);
}
#define DMP(...) dump(#__VA_ARGS__, __VA_ARGS__)
#else 
#define DMP(...) ((void)0)
#endif

int main() {

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	char c;
	cin >> c;

	cout << char(c + 1) << "\n";

	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <utility>
#include <vector>
#include <complex>
#include <cmath>
#include <algorithm>
#include <functional>

using namespace std;

static const double EPS=1e-12;
static const double INF=1e24;

using Point=complex<int>;
using Plane=vector<Point>;
using Polygon=vector<Point>;

bool operator<(const Point &a, const Point &b) {
    return real(a)!=real(b)? real(a)<real(b) : imag(a)<imag(b);
}

double cross_prod(const Point &a, const Point &b) {
    return imag(conj(a)*b);
}

double dot_prod(const Point &a, const Point &b) {
    return real(conj(a)*b);
}

enum {
    ONLINE_FRONT=-2,
    CLOCKWISE,
    ON_SEGMENT,
    COUNTER_CLOCKWISE,
    ONLINE_BACK,
};

int ccwise(Point a, Point b, Point c) {
    b -= a; c -= a;

    if (cross_prod(b, c) > 0) {
        return COUNTER_CLOCKWISE;
    } else if (cross_prod(b, c) < 0) {
        return CLOCKWISE;
    } else if (dot_prod(b, c) < 0) {
        return ONLINE_BACK;
    } else if (norm(b) < norm(c)) {
        return ONLINE_FRONT;
    } else {
        return ON_SEGMENT;
    }
}

Polygon convex_hull(Polygon g) {
    size_t V=g.size(), k=0;
    sort(g.begin(), g.end(), [](const Point &x, const Point &y) {
        return imag(x)!=imag(y)? imag(x)<imag(y) : real(x)<real(y);
    });

    Polygon chull(V<<1);
    for (size_t i=0; i<V; chull[k++]=g[i++])
        while (k >= 2) {
            int state=ccwise(chull[k-2], chull[k-1], g[i]);
            if (!(state == CLOCKWISE || state == ON_SEGMENT || state == ONLINE_BACK))
                break;

            --k;
        }

    for (size_t i=V-2, t=k+1; ~i; chull[k++]=g[i--])
        while (k >= t) {
            int state=ccwise(chull[k-2], chull[k-1], g[i]);
            if (!(state == CLOCKWISE || state == ON_SEGMENT || state == ONLINE_BACK))
                break;

            --k;
        }

    chull.resize(k-1);
    return chull;
}

int main() {
    size_t n;
    scanf("%zu", &n);

    Polygon g(n);
    for (size_t i=0; i<n; ++i) {
        int x, y;
        scanf("%d %d", &x, &y);
        g[i] = Point(x, y);
    }

    Polygon h=convex_hull(g);
    printf("%zu\n", h.size());
    for (size_t i=0; i<h.size(); ++i)
        printf("%d %d\n", real(h[i]), imag(h[i]));

    return 0;
}

Measured memory_bytes: 5492
import sys
import itertools


def solve():
    input = sys.stdin.readline
    mod = 10 ** 9 + 7
    wn, wm, r = list(map(int, input().rstrip('\n').split()))
    rl = list(map(int, input().rstrip('\n').split()))
    inf = 10 ** 13
    wl = [[inf] * wn for _ in range(wn)]
    for i in range(wn):
        wl[i][i] = 0

    for i in range(wm):
        wa, wb, wc = list(map(int, input().rstrip('\n').split()))
        wl[wa - 1][wb - 1] = wc
        wl[wb - 1][wa - 1] = wc

    for i in range(wn):
        for j in range(wn):
            for k in range(wn):
                wl[j][k] = min(wl[j][k], wl[j][i] + wl[i][k])
    mt = 10 ** 10
    for v in itertools.permutations(rl):
        t = 0
        for i in range(1, r):
            t += wl[v[i]-1][v[i-1]-1]
        mt = min(mt, t)
    print(mt)


if __name__ == '__main__':
    solve()


Measured memory_bytes: 43356
#include<iostream>
#include<string>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<vector>
#include<functional>
#include<iomanip>
#include<queue>
#include<cassert>
#include<tuple>
#include<set>
#include<map>
#include<list>
#include<bitset>
#include<utility>
#include<numeric>

#define PB push_back
#define all(a)  (a).begin(),(a).end()
#define ALL(v) begin(v), end(v)
#define DWN(a)  (a).begin(),(a).end(), greater<int>()
#define rep(i, m) for (int i = 0; i < m; i++)
#define REP(i, n, m) for (int i = n; i < m; i++)
#define V vector<int>
#define VV vector<V>
#define VVV vector<VV>

using namespace std;

typedef long long ll;
typedef pair<int, int> P;

const int dx[4] = { 1, 0, -1, 0 };
const int dy[4] = { 0, 1, 0, -1 };
const int inf = (int)1e9;
const ll INF = (ll)1e18;
const ll MOD{ (ll)1e9 + 7 };
const long double EPS = 1e-10;

int main() {
	int n;
	cin >> n;
	if (n == 1) {
		cout << "Hello World" << endl;
	}
	else {
		int a, b;
		cin >> a >> b;
		cout << a + b << 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++)

typedef long long ll;

const ll INF = 1LL << 60;
long long dp[100010];
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; }

/*
#define MAX 10000
#define NIL -1
struct Node { int p, l, r; };
struct Node T[MAX];
*/

int main() {
    int n, m;
    ll mod = 1e9 + 7;
    cin >> n >> m;
    vector<int> v(10e5 + 7, true);

    rep(i, m)
    {
        int a;
        cin >> a;
        v[a] = false;
    }

    rep(i, 1e5 + 7) dp[i] = 0;
    dp[0] = 1;

    // 配るDP
    // j<= min(n, i+2) でi+1とi+2の場合を計算する
    for (int i = 0; i < n; i++){
        for (int j = i + 1; j <= min(n, i + 2); j++){
            if(v[j]){
                dp[j] += dp[i];
                dp[j] %= mod;
            }
        }
    }

    cout << dp[n] << endl;

    return 0;
}


Measured memory_bytes: 4992
#include<iostream>
#include<string>
#include<cmath>
#include<cstdlib>
#include<vector>
#include<map>
#include<set>
#include<algorithm>
#include<queue>

using namespace std;

long long MOD = 1000000007;

int n;
long long l;
long long a[100005];

int main(){
  cin>>n>>l;
  for(int i=0;i<n;i++)cin>>a[i];

  int can = -1;
  for(int i=0;i<n-1;i++){
    long long tmp = a[i]+a[i+1];
    if(tmp >= l){
      can = i;
      break;
    }
  }

  if(can == -1){
    cout<<"Impossible"<<endl;
  } else {
    can++;
    cout<<"Possible"<<endl;
    for(int i=1;i<can;i++){
      cout<<i<<endl;
    }
    for(int i=n-1;i>=can;i--){
      cout<<i<<endl;
    }
  }
  return 0;
}

Measured memory_bytes: 1536
#include <iostream>
#include <map>
#include <vector>
#include <algorithm>
#include <string>
#include <queue>
#include<iomanip>

#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define rep(i,n) for(int i=0,i##_len=(n);i<i##_len;++i)
#define reps(i,n) for(int i=1,i##_len=(n);i<=i##_len;++i)
#define rrep(i,n) for(int i=((int)((n)-1));i>=0;--i)
#define rreps(i,n) for(int i=((int)(n));i>0;--i)
#define ALL(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define ZERO(a) memset(a,0,sizeof(a))
#define BIT(n) (1LL<<(n))
#define UNIQUE(v) v.erase(unique(v.begin(),v.end()),v.end());
#ifdef LOCAL
    #define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
    #define eprintf(...) 4545
#endif

typedef long long int lli;
using namespace std;
typedef pair<int, int> ii;
typedef priority_queue<int, vector<int>, greater<int> > heapq;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
#define int long long int
struct aaa{
    aaa(){
        cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(20);
    };
}aaaaaaa;

signed main() {
    int N; cin >> N;
    vector<int> A(N + 1);
    for (auto&& a: A) cin >> a;
    vector<int> B(N);
    for (auto && b: B) cin >> b;

    int ans = 0;
    rep(i, SZ(B)) {
        int attack = min(A[i], B[i]);
        A[i] -= attack;
        B[i] -= attack;
        ans += attack;

        attack = min(A[i + 1], B[i]);
        A[i + 1] -= attack;
        B[i] -= attack;
        ans += attack;
    }

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


Measured memory_bytes: 1792
a,b,c,d = map(int, input().split())

nc = (b//c) - ((a-1)//c)
# print(nc)

nd = (b//d) - ((a-1)//d)
# print(nd)

def gcd(a, b):
    if a < b:
        a,b = b,a
    while (a%b)!=0:
        a,b = b,a%b
    return b

def lcm(a, b):
    return (a*b)//gcd(a, b)

ncd = (b//lcm(c,d)) - ((a-1)//lcm(c,d))
# print(ncd)

u = b - a + 1
# print(u)

ans = u - nc - nd + ncd

print(ans)

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

const int MAX_V = 1000;
ll d[MAX_V][MAX_V];
int V;
bool negative=1;
void warshall_floyd(){
    rep(k, V) rep(i, V) rep(j, V){
        if(d[i][k] != INF && d[k][j] != INF){
            d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
        }
    }
}


int main() {
  cin>>V;
  int e[V][V];
  rep(i,V){
      int a[V];
      rep(j,V){ 
          cin>>a[j];
          d[i][j]=a[j];
          e[i][j]=a[j];
      }
  } 
  


  warshall_floyd();

  bool ok=1;
  rep(i,V){
      rep(j,V){ 
            if(d[i][j]!=e[i][j]) ok=0;
      }
  }

  if(!ok){
      cout<< -1 <<endl;
      return 0;
  } 

ll ans=0;
for(int i=0;i<V-1;i++){
    for(int j=i+1;j<V;j++){
        bool flg=1;
        for(int k=0;k<V;k++){
            if(i!=k&&j!=k&&d[i][j]>=d[i][k]+d[k][j]) flg=0;
        }
        if(flg) ans+=d[i][j];
    }
}

cout<<ans<<endl;

}

Measured memory_bytes: 4224
#include<bits/stdc++.h>
#define U [7<<15]={}
#define G )+((c=A[a]+A[P[a]]+C[a])%k?c:0)-M(
typedef long long L;using namespace std;map<L,L>T U;L P U,E U,Z U,H U,C U,A U,O U,X U,B U,k,n,a,b,c,d;char s U;L M(L f){return f?B[f]+M(f^f&-f):0;}L S(L a,L i){for(a=M(i++G i);i<2e5;i+=i&-i)B[i]+=a;}L D(L f){L d;for(map<L,L>::iterator I=T[f].begin();I!=T[f].end();I++)d=I->first,!Z[d]?P[d]=f,E[d]=E[f]+1,C[d]=I->second,Z[d]=1,D(d),Z[f]+=Z[d],Z[H[f]]<Z[d]?H[f]=d:0:0;}L K(L f){a=X[f];n=X[b];return a-n?M(O[E[a]<E[n]?a=n,n=b,b=f,n:f]G O[a])+K(P[a]):abs(M(O[f])-M(O[b]));}main(){for(cin>>n>>k;++d<n;*Z-=T[a][b]=T[b][a]=c)cin>>a>>b>>c;for(D(a=n=0);n<d;a=H[P[++n]]-n?n:0)for(;!O[a];S(a=H[a],O[a]=++b))X[a]=n;for(cin>>a;cin>>s>>a>>b;S(H[a],O[a]),S(a,O[a]-1))*s&2?cout<<K(a)<<endl,0:A[a]+=b;}

Measured memory_bytes: 38096
#include <iostream>
#include <iomanip>
#include <random>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <numeric>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <sstream>
#include <bitset>
#include <cassert>
#include <fstream>
#include <queue>

#define len(X) ((int)(X).size())

#ifdef __LOCAL
	#define DBG(X) cout << "[DBG] " << #X << "=" << (X) << '\n';
	#define SAY(X) cout << "[SAY] " << (X) << '\n';
#else
	#define DBG(X)
	#define SAY(X)
#endif
 
using namespace std;

using ll = long long int;
using ull = unsigned long long int;
using ld  = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

const int INT_INF = (int)(2e9);
const ll  LL_INF  = (ll)(2e18);

const int NIL = -1;
static mt19937 _g(time(nullptr));

inline ll randint(ll a, ll b) { ll w = (_g() << 31LL) ^ _g(); return a + w % (b - a + 1); }
inline void fast_io() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); };
template<typename T> inline T sign(T x) { return T(x > 0) - T(x < 0); }
template<typename T, typename S> inline ostream& operator<<(ostream& os, const pair<T, S> p) { cout << "[" << p.first << ";" << p.second << "]"; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const vector<T>& v) { for(auto el: v) cout << el << " "; return os; }
template<typename T> inline T fetch() { T ret; cin >> ret; return ret; }
template<typename T> inline vector<T> fetch_vec(int sz) { vector<T> ret(sz); for(auto& elem: ret) cin >> elem; return ret; }

const int MAXN = 40;
string s;
int n;
ll dp[MAXN][MAXN];

void solve() {
	cin >> n; n += n;
	cin >> s;
	ll answ = 0;
	set<string> used;
	for(int msk = 0; msk < (1 << (n/2)); ++msk) {
		string cur(n/2, '%');
		int l = 0, r = n/2;
		int ok = 1;
		for(int i = 0; i < n/2; ++i) {
			if((msk>>i)&1) {
				cur[l++] = s[i];
			} else {
				cur[--r] = s[i];
			}
		}
		if(used.count(cur)) continue;
		used.insert(cur);
		DBG(cur);
		for(int l = 0; l <= n/2; ++l) {
			for(int r = 0; r <= n/2; ++r) {
				dp[l][r] = 0;
			}
		}
		dp[0][n/2] = 1;
		for(int l = 0; l <= n/2; ++l) {
			for(int r = n/2; r >= 0; --r) {
				ll v = dp[l][r];
				int i = l + n/2 - r;
				if(l < n/2 && s[i] == cur[l]) {
					dp[l+1][r] += v;
				}
				if(r > 0 && s[i] == cur[r - 1]) {
					dp[l][r-1] += v;
				}
			}
		}
		/*for(int i = 0; i <= n; ++i) {
			for(int l = 0; l <= n/2; ++l) {
				for(int r = 0; r <= n/2; ++r) {
					cout << i << ' ' << l << ' ' << r << ' ' << dp[i][l][r] << '\n';
				}
			}
		}*/

		DBG(dp[n/2][0]);
		answ += dp[n/2][0];
	}
	cout << answ << '\n';
}

int main() {
	fast_io();
	solve();

	return 0;
}


Measured memory_bytes: 14592
n = int(input())
t = list(map(int, input().split()))
m = int(input())
p = [[]] * m
x = [[]] * m
ans = 0
for i in range(n):
  ans += t[i]
for i in range(m):
  p[i], x[i] = map(int, input().split())
  print(ans - t[p[i]-1] + x[i])

Measured memory_bytes: 9084
#include <iostream>
#include <cmath>
using namespace std;
int main()
{
  // 奇 + 奇 = 偶
  // 偶 + 偶 = 偶
  long N, odd = 0, even = 0, buf;
  cin >> N;
  for (long i = 0; i < N; i++)
  {
    cin >> buf;
    if (buf % 2 == 0)
    {
      even++;
    }
    else
    {
      odd++;
    }
  }
  // 可能な限り偶数にする
  while (odd > 1)
  {
    odd -= 2;
    even++;
  }
  if (odd == 0)
  {
    cout << "YES" << endl;
  }
  else
  {
    cout << "NO" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <array>
#include <algorithm>
#include <limits>
#include <cmath>
#include <numeric>
#include <string>

using namespace std;

using ll = long long int;
using ull = unsigned long long int;
#define rep(i, a, b) for(int i = (a); i < (b); ++i )
#define rrep(i, a, b) for(int i = (a); i > (b); --i )
#define REP(i, a, b) for(int i = (a); i <= (b); ++i )
#define RREP(i, a, b) for(int i = (a); i >= (b); --i )
#define llrep(i, a, b) for(ll i = (a); i < (b); ++i )
#define llrrep(i, a, b) for(ll i = (a); i > (b); --i )
#define llREP(i, a, b) for(ll i = (a); i <= (b); ++i )
#define llRREP(i, a, b) for(ll i = (a); i >= (b); --i )
#define ullrep(i, a, b) for(ull i = (a); i < (b); ++i )
#define ullrrep(i, a, b) for(ull i = (a); i > (b); --i )
#define ullREP(i, a, b) for(ull i = (a); i <= (b); ++i )
#define ullRREP(i, a, b) for(ull i = (a); i >= (b); --i )



int A, B;
int main() {
    cin >> A >> B;
    if(A > 8||B>8) {
        cout << ":(";
    }else{
        cout << "Yay!";
    }
}

Measured memory_bytes: 256
#include <iostream>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;

struct Card {
    char suit;
    int value;
};

int n;
Card c1[101], c2[101];

void bubbleSort(Card x[], int y) {
    int flag = 1;
    while (flag) {
        flag = 0;
        for (int j = y - 1; j > 0; j--) {
            if (x[j].value < x[j - 1].value) {
                swap(x[j], x[j - 1]);
                flag = 1;
            };
        }
    }
}

void selectionSort(Card x[], int y) {
    for (int i = 0; i < y; i++) {
        int minj = i;
        for (int j = i; j < y; j++) {
            if (x[j].value < x[minj].value) {
                minj = j;
            }
        }
        if (x[i].value != x[minj].value) {
            swap(x[i], x[minj]);
        }
    }
}

bool isStable(Card bubble[], Card select[], int x) {
    for (int i = 0; i < x; i++) {
        if (bubble[i].suit != select[i].suit) {
            return false;
        }
    }
    return true;
}

int main() {
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> c1[i].suit >> c1[i].value;
        c2[i] = c1[i];
    }
    bubbleSort(c1, n);
    selectionSort(c2, n);
    bool stable = isStable(c1, c2, n);
    rep(i, n - 1) cout << c1[i].suit << c1[i].value << " ";
    cout << c1[n - 1].suit << c1[n - 1].value << endl << "Stable" << endl;
    rep(i, n - 1) cout << c2[i].suit << c2[i].value << " ";
    cout << c2[n - 1].suit << c2[n - 1].value;
    if (stable) {
        cout << endl << "Stable" << endl;
    } else {
        cout << endl << "Not stable" << endl;
    }
    return 0;
}



Measured memory_bytes: 3096