akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
 int main(){
	ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
	int n;
	cin>>n;
	int a[n],b[n-1],sum=0;
	for(int i=0;i<n-1;++i)
		cin>>b[i];
	for(int i=1;i<n-1;++i){
		a[i]=min(b[i],b[i-1]);
		sum+=a[i];
	//	cout<<sum<<endl;
	}	
	sum+=b[0]; //cout<<sum<<endl;
	sum+=b[n-2];//cout<<sum<<endl;
	cout<<sum;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <cmath>
#include <queue>
#include <numeric>
#include <climits>
#include <iterator>
#include <iomanip>
#include <stack>
#include <set>
#include <cstdio>
#include <bitset>
#include <functional>
#include <tuple>
using namespace std;
const constexpr int INF = 1e9;
typedef pair<int, int> P;

#define FOR(i, a, n) for (ll i = (ll)a; i<(ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)

typedef long long ll;
typedef vector<int> VI;
const constexpr ll MOD = 1e9 + 7;
const int BITSIZE = 100010;

struct Less {
	bool operator()(const pair<int, int>& x, const pair<int, int>& y) const {
		return x.second < y.second;
	}
};
struct More {
	bool operator()(const pair<int, int>& x, const pair<int, int>& y) const {
		return x.first > y.first;
	}
};
//1-indexed
int bit[100010];

int bit_query(int i) {
	int res = 0;
	for (; i >= 1; i -= i & -i) res = max(res, bit[i]);
	return res;
}

void bit_set(int x, int v) {
	for (; x <= BITSIZE; x += x & -x) {
		bit[x] = max(bit[x], v);
	}
}

int a[45], b[45], c[45];
int dp[45][410][410];
int main() {
	int N, Ma, Mb; cin >> N >> Ma >> Mb;
    REP(i, N){
        cin >> a[i] >> b[i] >> c[i];
    }
    for(int i=0; i<45; ++i){
        for(int j=0; j<410; ++j){
            for(int k=0; k<410; ++k){
                dp[i][j][k] = INF;
            }
        }
    }
    
    dp[N][0][0]=0;
    for(int i=N-1; i>=0; i--){ //i番目を取るかどうかを考える
        for(int j=0; j<410; ++j){
            for(int k=0; k<410; ++k){
                if(j-a[i]>=0&&k-b[i]>=0) dp[i][j][k] = min(dp[i+1][j][k], dp[i+1][j-a[i]][k-b[i]]+c[i]);
                else dp[i][j][k] = dp[i+1][j][k];
            }
        }
    }
    int minV=INF;
    for(int i=1; i<410; ++i){
        minV = min(minV, dp[0][Ma*i][Mb*i]);
    }
    if(minV==INF) cout << -1 << endl;
    else cout << minV << endl;
	return 0;
}

Measured memory_bytes: 29824
import std.stdio, std.format, std.string, std.algorithm;

int[] getMaxMin( int val, int l ) {
  int[] digits = new int[]( l );
  foreach ( i; 0 .. l ) {
	digits[ i ] = val % 10;
	val /= 10;
  }
  int[] ans = new int[]( 2 );
  ans[] = 0;
  sort!"a < b"( digits );
  foreach ( i; 0 .. l ) {
	ans[ 0 ] *= 10;
	ans[ 0 ] += digits[ i ];
  }
  sort!"a > b"( digits );
  foreach ( i; 0 .. l ) {
	ans[ 1 ] *= 10;
	ans[ 1 ] += digits[ i ];
  }
  return ans;
}

int contains( int[] array, int index ) {
  foreach ( i; 0 .. index - 1 ) {
	if ( array[ index - 1 ] == array[ i ] ) {
	  return i;
	}
  }
  return -1;
}

void main()
{
  while ( true ) {
	int a, l;
	string input = readln;
	formattedRead( input, "%d %d\n", &a, &l );
	if ( a == 0 && l == 0 ) break;
	int index = 0;
	int[] array = new int[ 30 ];
	array[ index++ ] = a;
	do {
	  int[] ans = getMaxMin( a, l );
	  // stderr.writeln( ans );
	  a = array[ index++ ] = ans[ 1 ] - ans[ 0 ];
	} while ( contains( array, index ) == -1 );
	int j = contains( array, index );
	writefln( "%d %d %d", j, array[ j ], index - 1 - j );
  }
}

Measured memory_bytes: 1080
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>

using namespace std;
using boost::multiprecision::cpp_int;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<ll,pair<ll, ll>> lpll;
typedef pair<ll, int> pli;
typedef pair<int, int> pii;

const ll INF = LLONG_MAX;
const ll MOD = 1e9+7;

vector<vector<int>> ki;
vector<ll> ans_ready;
vector<ll> ans;
vector<bool> checker;

void add(int i) {
    checker[i] = true;
    ans[i] += ans_ready[i];
    for (auto k: ki[i]) {
        if (checker[k]) continue;
        ans[k] += ans[i];
        add(k);
    }
}

int main() {
    // input, ready
    int N,Q;
    cin >> N >> Q;
    vector<pii> a_b(N+1);
    for (int i=1; i<N;i++) {
        int a,b;
        cin >> a >> b;
        a_b.push_back({a,b});
    }
    sort(a_b.begin(),a_b.end());
    ki.resize(N+1);
    for (int i=0; i<=N; i++) {
        vector<int> tmp;
        ki[i] = tmp;
    }
    for (auto ab: a_b) {
        int a = ab.first;
        int b = ab.second;
        ki[a].push_back(b);
        ki[b].push_back(a);
    }

    ans_ready.resize(N+1,0);
    for (int i=0; i<Q; i++) {
        int p,x;
        cin >> p >> x;
        ans_ready[p]+=x;
    }

    // output
    checker.resize(N+1,false);
    ans.resize(N+1,0);
    add(1);
    for (int i=1; i<=N; i++) cout << ans[i] << " "; cout << endl;

    return 0;
}


Measured memory_bytes: 30564
N, C = map(int, input().split())

xv = [tuple(map(int, input().split())) for i in range(N)]
xv2 = [(C - x, v)for x, v in xv[::-1]]


L = [0]*N
ans = 0
for i, X in enumerate(xv):
    x, v = X
    L[i] = L[i-1] + v
R = [0]*N
for i in range(N):
    L[i] -= xv[i][0]
for i, X in enumerate(xv2):
    x, v = X
    R[i] = R[i-1] + v
for i in range(N):
    R[i] -= xv2[i][0]

LL = [0]*(N+1)
RR = [0]*(N+1)
for i in range(N):
    LL[i+1] = max(LL[i], L[i])
    RR[i+1] = max(RR[i], R[i])

ans = 0
ans = max(ans, LL[-1])
ans = max(ans, RR[-1])
for i in range(N):
    ans = max(ans, LL[N - 1 - i] + R[i] - xv2[i][0])
    ans = max(ans, RR[N - 1 - i] + L[i] - xv[i][0])
print(ans)


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

using namespace std;

#define REP(i,x,y) for (int i=x;i<y;i++)

const int8_t INFC=0x3f;
const int16_t INFS=0x3f3f;
const int32_t INF=0x3f3f3f3f;
const int64_t INFL=0x3f3f3f3f3f3f3f3fLL;

const int MAXN=2e5;
struct UF
{
    int par[MAXN],rk[MAXN];
    void merge(int x,int y)
    {
        int px=find(x),py=find(y);
        if (px==py) return ;
        rk[px]+=rk[py];
        par[py]=px;
    }
    int find(int x)
    {
        return ((x==par[x])?x:(par[x]=find(par[x])));
    }
    void init(int n)
    {
        for (int i=0;i<n;i++) par[i]=i,rk[i]=1;
    }
}uf;
int a[MAXN],b[MAXN];
int main()
{
    ios::sync_with_stdio(0);
    int n,m;
    cin >> n >> m;
    uf.init(n);
    for (int i=0;i<m;i++)
    {
        cin >>a[i]>>b[i];
        a[i]--,b[i]--;
    }
    int64_t res=n;
    res*=n-1;
    res/=2;
    vector<int64_t> ans;
    ans.clear();
    for (int i=m-1;i>=0;i--)
    {
        ans.push_back(res);
        //for (int i=0;i<n;i++)cout << uf.par[i]<<" ";
        //cout << endl;
        if (uf.find(a[i])==uf.find(b[i])) continue ;
        //cout <<a[i]<<":"<< uf.find(a[i])<<" "<<b[i]<<":"<<uf.find(b[i])<< endl;
        res-=uf.rk[uf.find(a[i])]*uf.rk[uf.find(b[i])];
        uf.merge(a[i],b[i]);
    }
    for (int i=m-1;i>=0;i--)
    {
        //if (ans[i]<0) ans[i]=0;
        cout << ans[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 3828
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"
#include "ctime"

using namespace std;

constexpr long long int MOD = 1000000007;
//constexpr int MOD = 1000000007;
//constexpr int MOD = 998244353;
//constexpr long long int MOD = 998244353;
constexpr double EPS = 1e-8;

//int N, M, K, H, W, L, R;
long long int N, M, K, H, W, L, R;

class XorShift {
	unsigned int x, y, z, w, t;
public:
	XorShift() {
		x = 133553533;
		y = 314867339;
		z = 664298413;
		w = 924399937;
		t = 0;
	}
	unsigned int rand() {
		t = x ^ (x << 11);
		x = y;
		y = z;
		z = w;
		w = (w ^ (w >> 19)) ^ (t ^ (t >> 8));
		return w & 0x7fffffff;
	}
};

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

	cin >> N;
	vector<int>v(N);
	vector<int>w(N);
	for (auto&i : v)cin >> i;
	for (auto&i : w)cin >> i;
	auto st = clock();
	vector<int>ans(N);
	for (int i = 0; i < N; i++) {
		ans[i] = v[i] ^ w[0];
	}
	int cnt = 0;
	XorShift xs;
	while (1) {
		cnt++;
		if (cnt % 10) {
			auto t = clock()-st;
			if (t * 1000 / CLOCKS_PER_SEC >= 1600) {
				for (int i = 0; i < N; i++) {
					if (ans[i] != -1)cout << i << " " << ans[i] << endl;
				}
				return 0;
			}
		}
		int c = xs.rand()%N;
		int d = -1;
		for (int i = 0; i < N; i++) {
			if (ans[i] != (w[c] ^ v[(c + i) % N])) {
				ans[i] = -1;
				d = (c + i) % N;
			}
		}
		if (d != -1) {
			for (int i = 0; i < N; i++) {
				if (ans[i] != (v[d] ^ w[(d + N - i) % N]))ans[i] = -1;
			}
		}
		c = xs.rand() % N;
		d = -1;
		for (int i = 0; i < N; i++) {
			if (ans[i] != (v[c] ^ w[(c + N - i) % N])) {
				ans[i] = -1;
				d = (c + N - i) % N;
			}
		}
		if (d != -1) {
			for (int i = 0; i < N; i++) {
				if (ans[i] != (w[d] ^ v[(d + i) % N])) {
					ans[i] = -1;
				}
			}
		}
	}
}


Measured memory_bytes: 5888
#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <iterator>
#include <assert.h>
#pragma warning(disable:4996) 
 
typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF 9223300000000000000
#define INF 2140000000
const long long MOD = 1000000007;
//const long long MOD = 998244353;
using namespace std;

char str0[100005];
char str1[100005];

int main(int argc, char* argv[])
{
    scanf("%s%s", str0, str1);
    
    int len0=strlen(str0);
    int len1=strlen(str1);
    vector<int> s0(len0+1), s1(len1+1);
    int i;
    for(i=0; i<len0; i++) {
        if(str0[i]=='B') s0[i+1]=s0[i]+2;
        else s0[i+1]=s0[i]+1;
    }
    for(i=0; i<len1; i++) {
        if(str1[i]=='B') s1[i+1]=s1[i]+2;
        else s1[i+1]=s1[i]+1;
    }

    int T;
    scanf("%d", &T);
    int t;
    for(t=0; t<T; t++) {
        int a,b,c,d;
        scanf("%d%d%d%d", &a, &b, &c, &d);
        int ans=(s0[b]-s0[a-1]-s1[d]+s1[c-1]+6)%3;
        if(ans==0) {
            printf("YES\n");
        }
        else {
            printf("NO\n");
        }
    }

    return 0;
}


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

using namespace std;

#define REP(a, b, c) for (register int a = b, _n = c; a <= _n; ++a)
#define DREP(a, b, c) for (register int a = b, _n = c; a >= _n; --a)
#define FOR(a, b, c) for (register int a = b, _n = c; a < _n; ++a)
#define DFOR(a, b, c) for (register int a = b, _n = c; a > _n; --a)
#define EREP(a, b) for (register int a = first[b]; a; a = edge[a].nxt)

int a, b, c;

void _main () {
    scanf ("%d%d", &a, &b);
    printf ("%d\n", max(a * b, max(a - b, a + b)));
}

int main () {
#ifdef LOCAL
    freopen("in.txt", "w", stdout);
#endif
    _main();   
    return 0;
}


Measured memory_bytes: 256
N=int(input())
d=[int(input()) for _ in range(N)]
d=list(set(d))
d.sort(reverse=True)
cnt=1
for i in range(len(d)-1):
    if d[i+1]<d[i]:
        cnt+=1
    else:
        print(cnt)
        exit()
print(cnt)

Measured memory_bytes: 3064
#coding:utf-8

N,M=map(int,raw_input().split())
D=[[1145141919]*101 for _ in range(101)]
R=[[1145141919]*101 for _ in range(101)]

A=set()
for i in range(M):
    a,b,c=map(int,raw_input().split())
    D[a][b]=c;D[b][a]=c
    R[a][b]=c;R[b][a]=c
    A.add((min(a,b),max(a,b)))

for i in range(1,N+1):D[i][i]=0


for k in range(1,N+1):
    for i in range(1,N+1):
        for j in range(1,N+1):
            if D[i][j]>D[i][k]+D[k][j]:
                D[i][j]=D[i][k]+D[k][j]    
ans=0
for i in range(1,N+1):
    for j in range(i+1,N+1):
        if R[i][j]==1145141919:continue
        if D[i][j]!=R[i][j]:ans+=1
print(ans)



Measured memory_bytes: 32876
#include <iostream>
#include <vector>
#include<list>
#include <algorithm>
#include <string>
#include <math.h>
#include<map>
#include <utility>

#include<queue>
using namespace std;
#define REP(i,k,n) for(int i=k;i<n;i++)
 
#define INF (1e10)
typedef long long unsigned int ll;
#define SIZE_OF_ARRAY(array) (sizeof(array)/sizeof(array[0]))
#define MOD 1000000007

template<typename T>
int vector_finder(std::vector<T> vec, T number) {
  auto itr = std::find(vec.begin(), vec.end(), number);
  size_t index = std::distance( vec.begin(), itr );
  if (index != vec.size()) { // 発見できたとき
    return 1;
  }
  else { // 発見できなかったとき
    return 0;
  }
}

template<typename T>
T gcd(T a,T b){
	if(b>0){
		return gcd(b, a % b);
	}else{
		return a;
	}
}

template<typename T>
T lcm(T a,T b){
	T g = gcd(a, b);
	return a * b / g;
}

void clear( std::queue<pair<int,int> > &q )
{
   std::queue<pair<int,int> > empty;
   std::swap( q, empty );
}
bool IsPrime(int num)
{
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false; // 偶数はあらかじめ除く

    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            // 素数ではない
            return false;
        }
    }

    // 素数である
    return true;
}
template<typename T>
std::vector<T> enum_div(T n)//nの約数を列挙
{
	std::vector<T> ret;
	for(T i=1 ; i*i<=n ; ++i)
	{
		if(n%i == 0)
		{
			ret.push_back(i);
			if(i!=1 && i*i!=n)
			{
				ret.push_back(n/i);
			}
		}
	}
	return ret;
}

int N,K;


int main()
{
  cin>>N;
  ll A, B;
	ll X[N];
	cin >> A >> B;
	REP(i, 0, N)
	{
		cin >> X[i];
  }

  ll ans = 0;
  REP(i,0,N-1){
    if((X[i+1]-X[i])*A<B){
      ans += (X[i + 1] - X[i]) * A;
    }else{
      ans += B;
    }
  }

  cout << ans << endl;
  



  return 0;
}

Measured memory_bytes: 1024
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

static const double EPS = 1e-8;
static const double PI = 4.0 * atan(1.0);
static const double PI2 = 8.0 * atan(1.0);

#define REP(i,n)	for(int i=0;i<(int)n;++i)
#define ALL(c)		(c).begin(),(c).end()
#define CLEAR(v)	memset(v,0,sizeof(v))
#define MP(a,b)		make_pair((a),(b))
#define ABS(a)		((a)>0?(a):-(a))
#define FOR(i,s,n)	for(int i=s;i<(int)n;++i)

int main(int argc, char **argv) {
	int x;
	cin >> x;
	REP(i, 100000) {
		x -= i + 1;
		if (x <= 0) {
			cout << (i + 1) << endl;
			break;
		}
	}
	return 0;
}


Measured memory_bytes: 256
import math

PN = []
def buildPrimeNumber(N):
	global PN
	for n in range(2, N + 1):
		f = True
		for m in range(2, n):
			if 0 == n % m:
				f = False
				break
		if f:
			PN.append(n)

buildPrimeNumber(1000)

C = dict()
def primeFactorization(N):
	global C
	for pn in PN:
		if N % pn:
			continue
		c = 0
		while 0 == N % pn:
			c += 1
			N //= pn
		C[pn] = c
	if N == 1:
		return
	else:
		C.clear()

N = int(input())
f = math.factorial(N)

primeFactorization(f)

r = 1
for c in C.values():
	r *= (c + 1)
print(r % (10**9 + 7))


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

#define DUMP(x) cerr << #x << "=" << x << endl
#define DUMP2(x, y) cerr<<"("<<#x<<", "<<#y<<") = ("<<x<<", "<<y<<")"<< endl
#define BINARY(x) static_cast<bitset<16> >(x)

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define REP(i,m,n) for (int i=m;i<(int)(n);i++)

#define in_range(x, y, w, h) (0<=(int)(x) && (int)(x)<(int)(w) && 0<=(int)(y) && (int)(y)<(int)(h))
#define ALL(a) (a).begin(),(a).end()

typedef long long ll;
const int INF = 1e9;
typedef pair<int, int> PII;
int dx[4]={0, -1, 1, 0}, dy[4]={-1, 0, 0, 1};

int main()
{
    ios::sync_with_stdio(false);

    int N; cin >> N;
    map<int, int> cnt;

    rep(i, N) {
        int A; cin >> A;
        cnt[A-1]++;
    }

   int even = 0;
   for (auto a : cnt) {
       even += (a.second % 2 == 0);
   }

    cout << cnt.size() - (even % 2)  << endl;
}



Measured memory_bytes: 4992
import java.util.Scanner;
public class Main{
  public static void main(String[] args){
    Scanner sc=new Scanner(System.in);
    int s=sc.nextInt();
    int h=s/3600;
    s=s%3600;
    int m=s/60;
    s=s%60;
    System.out.println(h+":"+m+":"+s);
  }
}


Measured memory_bytes: 26348
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <cassert>

using namespace std;
typedef long long LL;
template <typename F, typename S> std::ostream& operator<<(ostream& os, const pair<F,S>& p) {
    os << "(" << p.first << "," << p.second << ")"; return os; }
template <typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
    os << "["; for(const T& a: v){ os << a << ", "; } os << "]"; return os; }
template <typename K, typename V> ostream& operator<<(ostream& os, const map<K,V>& m) {
    os << "{"; for(const auto& p: m){ os << p.first <<":"<< p.second << ", "; } os << "}"; return os; }

LL check(LL n, LL k){
    while(n >= k){
        if(n % k == 0){
            n = n / k;
        }else{
            n = n % k;
        }
    }
    return n;
}

int main(){
    LL n;
    cin >> n;
    set<LL> ans;
    ans.insert(n);
    for(LL i = 1; i*i <= n; ++i){
        if(i > 1 && n % i == 0){
            LL x = i;
            while(x <= n){
                if(check(n, x) == 1){
                    ans.insert(x);
                }
                x *= i;
            }
        }
        if((n-1) % i == 0){
            ans.insert(i);
            ans.insert((n-1)/i);
        }
    }
    ans.erase(1);
    ans.erase(0);
    //cerr << vector<LL>(ans.begin(), ans.end()) << endl;
    cout << ans.size() << endl;
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
#define SIZE 100015
#define INF 1000000005LL
#define MOD 1000000007

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

int n;
vector<int> G[SIZE];

int dfs(int v){
  vector<int> a;
  for(auto to : G[v]){
    a.push_back(dfs(to));
  }
  int u = 0;
  sort(a.begin(),a.end(),greater<int>());
  rep(i,0,a.size()){
    u = max(u,a[i]+i+1);
  }
  return u;
}

int main(){
  cin >> n;
  rep(i,2,n+1){
    int a;
    cin >> a;
    G[a].push_back(i);
  }
  cout << dfs(1) << endl;

  return 0;
}


Measured memory_bytes: 13568
#include <iostream>
#include <algorithm>
#include <functional>
#include <string>
using namespace std;

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
bool check(string  s){
	if(s[0]!='A')return false;
	int c = 0;
	for(int i = 2;i < s.length()-1;i++){
		if(s[i]=='C')c++;
	}
	if(c!=1)return false;
	int upper = 0;
	REP(i,s.length()){
		if(s[i]>='A' && s[i] <= 'Z')upper++;
	}
	if(upper!=2)return false;
	return true;
}
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);

	int n;
	scanf("%d", &n);
	int cmax = 100 / 4;
	int dmax = 100 / 7;
	for (int i = 0;i<= cmax;i++){
		for (int j = 0;j<= dmax;j++){
			if(i*4+j*7 == n){
				cout << "Yes" << endl;
				return 0;
			}
		}
	}
	cout << "No" << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep2(i, s, n) for (ll i = s; i < (ll)(n); i++)
typedef long long ll;
typedef vector<vector<ll>> vvl;
typedef vector<ll> vl;
typedef vector<vector<char>> vvc;
typedef vector<char> vc;
typedef pair<ll,ll> pll;
ll max(ll x,ll y){
if(x>y)return x;
else return y;
}
ll min(ll x,ll y){
  return x+y-max(x,y);
}


int main() {
  int n,m;
  cin >> n >> m;
  vector<int> a(n);
  int sum=0;
  rep(i,n){
    cin >> a[i];
    sum+=a[i];
  }
  sort(a.rbegin(),a.rend());
  if(4*m*a[m-1]>=sum)cout << "Yes" << endl;
  else cout << "No" << endl;
}


Measured memory_bytes: 256
/*
ID: lalitkumar__
TASK: B
LANG: C++14
*/
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
//	freopen("beads.in","r",stdin);
//	freopen("beads.out","w",stdout);

ll n ;
 cin>>n;
 ll a[n];
 for(int i  = 0;i<n;i++) cin>>a[i];
 ll pre[n];
 pre[0] = a[0];
 for(int i = 1;i<n;i++)
 {
 	pre[i]=pre[i-1]+a[i];
 }
ll ans = INT_MAX;
for(int i =0;i<n;i++)
{
	ans = min(ans,abs(pre[i]-abs(pre[n-1]-pre[i])));
}
cout<<ans<<endl;
}

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

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

    int n, p; cin >> n >> p;
    bool q = false;
    for (int i = 0; i < n; ++i)
    {
        int v; cin >> v;
        q or_eq (v & 1);
    }
    if (not q and p)
	return cout << 0 << '\n', 0;
    if (q) --n;
    long long r = (1ll << n);
    cout << r << '\n';
}
        


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define endl "\n"
#define se second
#define ls( s) (s&(-s))
#define ll long long
#define inf 0x3f3f3f3f
#define fast    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
const int N = 1e5+10;
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
const ll mod =  1e9+7;
int n;
int arr[25][25];
int main()
{  fast
cin>>n;
for(int i=0;i<n;i++)
for(int j=0;j<n;j++)
cin>>arr[i][j];
vector<int> dp(1<<n);
dp[0]=1;
for(int i=0;i<(1<<n)-1;i++)
{
	int x=__builtin_popcount(i);
	for(int j=0;j<n;j++)
	{
		if(arr[x][j]&&!((i>>j)&1)){
				int m=i^(1<<j);
		dp[m]+=dp[i];
		if(dp[m]>=mod)
		dp[m]-=mod;}
		
	}
}
cout<<dp[(1<<n)-1];


}

Measured memory_bytes: 8448
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pll;
typedef long double ld;
const ll N=5e5+5;
const ll MOD=1e9+7;
const ld pi=3.14159265359;
const ll INF=(1LL<<60);
#define REP(i,n) for(ll i=0;i<n;i++)
#define REP1(i,n) for(ll i=1;i<=n;i++)
#define X first
#define Y second
#define pb push_back
#define mp make_pair
#define setp setprecision
#define lwb lower_bound
#define SZ(a) (ll)a.size()

ll n,Q,x,y,ans,ty;
ll seg[4*N],cnt;
char ch;

void insert(ll id,ll l,ll r,ll to,ll g){
	if(r-l==1){seg[id]=(1LL<<g);return;}
	ll mid=(l+r)/2;
	if(to<mid){
		insert(id*2,l,mid,to,g);
	}else{
		insert(id*2+1,mid,r,to,g);
	}
	seg[id]=(seg[id*2]|seg[id*2+1]);
}

ll q(ll id,ll l,ll r,ll ql,ll qr){
	if(l>=qr||r<=ql)return 0;
	if(l>=ql&&r<=qr){return seg[id];}
	ll mid=(l+r)/2;
	return (q(id*2,l,mid,ql,qr)|q(id*2+1,mid,r,ql,qr));
}

int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);
	cin>>n;
	REP(i,n)cin>>ch,insert(1,0,n,i,ch-'a');
	cin>>Q;
	while(Q--){
		cin>>ty;
		if(ty==1){
			cin>>x>>ch;
			insert(1,0,n,x-1,ch-'a');
		}else{
			cin>>x>>y;
			cnt=q(1,0,n,x-1,y);ans=0;
			REP(i,26)if(cnt&(1LL<<i))ans++;
			cout<<ans<<"\n";
		}
	}
	return 0;
}


Measured memory_bytes: 10496
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0;i<n;i++)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOR(i,m,n) for(int i=m;i<n;i++)
#define ALL(a) a.begin(),a.end()
typedef long long ll;
#define INF 1<<30

int H,N;
int A[1500],B[1500];
int memo[20000];

int HP(int K){
    if(K<=0)return 0;
    if(memo[K]!=INF)return memo[K];
    int R = INF;
    REP(i,N){
        int r = B[i]+HP(K-A[i]);
        R = min(R,r);
    }
    memo[K] = R;
    return R;
}

signed main()
{
    cin >> H >> N;
    REP(i,N)cin >> A[i] >> B[i];
    REP(i,20000)memo[i] = INF;
    cout << HP(H) << endl;
    return 0;
}

Measured memory_bytes: 768
#include <stdio.h>
#include <string.h>

void append(char subject[], const char insert[], int pos) {
    char buf[100] = {};
    strncpy(buf, subject, pos); 
    int len = strlen(buf);
    strcpy(buf+len, insert); 
    len += strlen(insert); 
    strcpy(buf+len, subject+pos); 
    strcpy(subject, buf);
}

int main() {
    char string[100];
    scanf("%s",string);
    append(string, " ", 4);
    puts(string);

    return 0;

}


Measured memory_bytes: 128
#include<bits/stdc++.h>
#include <ext/pb_ds/detail/standard_policies.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define fi first
#define se second
#define fastio ios_base::sync_with_stdio(false); cin.tie(0)
#define loop(i, a, b) for(lli i=a; i<b; i++)
#define loopb(i, a, b) for(lli i=a; i>=b; i--)
#define pb push_back
#define umap unordered_map
typedef long long int lli;
typedef pair<lli, lli> pii;
typedef vector<lli> vll;
typedef pair<lli, pii> ppi;
typedef tree<lli, null_type, less<lli>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
// use to avoid collision
struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};
// for pair in unordered_map
struct hash_pair {
    static uint64_t splitmix64(uint64_t x) {
    // http://xorshift.di.unimi.it/splitmix64.c
    x += 0x9e3779b97f4a7c15;
    x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
    x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
    return x ^ (x >> 31);
    }
    template <class T1, class T2>
    size_t operator()(const pair<T1, T2>& p) const{
        auto hash1 = hash<T1>{}(p.first);
        auto hash2 = hash<T2>{}(p.second);
        uint64_t x = hash1 ^ hash2;
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};
lli M = 1e9 + 7;
lli power(lli x, lli y){
    lli res = 1;
    x = x%M ;
    while (y > 0) {
        if (y & 1)
            res = (res*x)%M ;
        y = y>>1;
        x = (x*x)%M;
    }
    return res%M;
}
lli solve(){
    string s;
    cin>>s;
    lli q;
    cin>>q;
    deque<char> dq;
    loop(i, 0, s.length())
        dq.pb(s[i]);
    bool flag = false;
    loop(i, 0, q){
        lli ti;
        cin>>ti;
        if(ti == 1){
            flag = !flag;
        }
        else{
            lli fi;
            char ci;
            cin>>fi>>ci;
            if(fi == 1){ 
                if(flag)
                    dq.pb(ci);
                else{
                    dq.push_front(ci);
                }
            }
            else{
                if(!flag)
                    dq.pb(ci);
                else{
                    dq.push_front(ci);
                }
            }
        }
    }
    string res;
    for(auto it : dq)
        res.pb(it);
    if(flag) 
        reverse(res.begin(), res.end());
    cout<<res<<"\n";
    return 0;
 }
int main(){
    fastio;
    lli t;
    // cin>>t;
    t = 1;
    while(t>0){
        t--;
        solve();
    }
    return 0;
}

Measured memory_bytes: 1368
#include<bits/stdc++.h>
//#include<iostream>
using namespace std;
//type
typedef long long ll;
#define pii pair<int, int>
#define vi vector<int>
//x * y * 1.0 can cause overflow
//constant
#define inf (int)(1e9+7)
#define mod (ll)(1e9+7)
#define INF (ll)(1e18)
#define eps 1e-10
//omission
#define eb emplace_back
#define F first
#define S second
#define SZ(x) ((int)(x).size())
#define all(v) v.begin(), v.end()
#define ios cin.tie(0); ios::sync_with_stdio(false)
#define FIX(a) cout << fixed << setprecision(a)
#define mp make_pair
//manip
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
#define UNIQUE(v) v.erase(unique(v.begin(), v.end(), v.end());
#define fill(x, y) memset(x, y, sizeof(x))
#define ceil(a, b) a / b + !!(a % b)
template<class T> T power_mod(T a, T b) {return b ? power(a * a % inf, b / 2) * (b % 2 ? a : 1) % inf : 1;}
template<class T> T power(T a, T b) {return b ? power(a * a, b / 2) * (b % 2 ? a : 1) : 1;}
#define LB(v, x) (int)(lower_bound(v.begin(), v.end(), x) - v.begin())
#define UB(v, x) (int)(upper_bound(v.begin(), v.end(), x) - v.begin())
template<typename T> T gcd(T a, T b) {if (b == 0) return a; return gcd(b, a % b);}
template<typename T> T lcm(T a, T b) {return a / gcd(max(a, b), min(a, b)) * b;} //先に割る!!
#define outa(a, n) rep(i, n) cout << a[i] << " "; cout << endl
#define out(a) cout << a << endl
#define outv(v) rep(i, SZ(v)) cout << v[i] << " "; cout << endl
#define ina(a, n) rep(i, n) cin >> a[i];
//loop
#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define rep3(i, st, n) for (int i = st; i < n; ++i)
//algorithm
//double pointer, l start, how many adds, can be 0 -> init r = l, sum = 0
//bfs, not x, y, i, j
//not !(i % 2), i % 2 == 0
//minimal required terms
//cast caution
//look constraints always

int main() {
    int n, d; cin >> n >> d;
    int x[n][d];
    rep(i, n) {
        rep(j, d) {
            cin >> x[i][j];
        }
    }
    int cnt = 0;
    rep(i, n - 1) {
        rep3(j, i + 1, n) {
            double ans = 0.0;
            rep(k, d) {
                ans += (x[i][k] - x[j][k]) * (x[i][k] - x[j][k]);
            }
            ans = sqrt(ans);
            if (abs(ans - (int)ans) < eps) {
                cnt++;
            }
        }
    }
    out(cnt);
}


Measured memory_bytes: 256
import java.math.BigDecimal;
import java.util.*;
public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    double x = sc.nextDouble();
    double pi = 3.14;
    BigDecimal ans = new BigDecimal(2*x*pi);
    System.out.println(ans);
  }
}  

Measured memory_bytes: 37628
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define int ll
typedef vector<int> vi;
#define endl '\n'
#define fo(i,a,b) for(int i=a;i<=b;i++)
#define rf(i,a,b) for(int i=a;i>=b;i--) 
#define fast_io ios_base::sync_with_stdio(0);
#define show(x) cout<<x<<endl;
#define pret(x) cout<<x<<endl; return 0;
#define disp(x) cout<<x<<" ";
#define let(x,y) cout<<x<<" "<<y<<endl;
ll MOD=1e9+7;
const int maxn=2e5+5;

bool visited[maxn];
vi v[maxn];
int ans;

void dfs(int id){
	visited[id] = 1;
	ans++;
	for(auto it:v[id]){
		if(visited[it]) continue;
		dfs(it);
	}
}

int32_t main(){
    fast_io;
    int n, m;
    cin >> n >> m;
    for (int i = 0; i < m; ++i)
    {
    	int x, y;
    	cin >> x >> y;
    	v[x].emplace_back(y);
    	v[y].emplace_back(x);
    }
    int value = 0;
    fo(i, 1, n){
    	if(visited[i]) continue;
    	ans = 0;
    	dfs(i);
    	value = max(value, ans);
    }
    show(value);
    return 0;
}

Measured memory_bytes: 21024
#include <iostream>
#include <cstdio>
#include <cstring>
#define N 100005
using namespace std;
typedef long long ll;
const int mod=1e9+7;
int n,a[N],D,IN[N],siz,sum[N],len[N],b[N];
bool inc[N];
ll f[N];
bool vis[N],used[N];
ll calc(ll x){
	return x*(x-1)/2%mod;
}
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++) scanf("%d",&a[i]),IN[a[i]]++;
	for(int i=1;i<=n;i++){
		if(vis[i]) continue;
		int g=i;
		while(!vis[g]) vis[g]=1,g=a[g];
		if(used[g]){
			g=i;
			while(!used[g]) used[g]=1,g=a[g];
			continue;
		}
		int x=a[g];inc[g]=1;b[a[g]]=g;
		while(x!=g) inc[x]=1,b[a[x]]=x,x=a[x];
		g=i;
		while(!used[g]) used[g]=1,g=a[g];
	}
	for(int i=1;i<=n;i++){
		if(inc[i]){if(IN[i]>2) return puts("0"),0;}
		else if(IN[i]>1) return puts("0"),0;
	}
	for(int i=1;i<=n;i++){
		if(!IN[i]){
			int g=i,l=0;
			while(!inc[g]) l++,g=a[g];
			len[g]=l;
		}
	}
	memset(vis,0,sizeof(vis));
	for(int i=1;i<=n;i++){
		if(!vis[i]&&inc[i]){
			int g=i,t=1,L=0;
			if(len[i]) t=0;
			while(!vis[g]){
				if(len[g]) t=0;
				L++;
				vis[g]=1;
				g=a[g];
			}
			if(t) sum[L]++;
		}
	}
	ll ans=1;
	for(int i=1;i<=n;i++){
		ll g=1+(i&1);
		if(i==1) g--;
		f[0]=1;
		for(int p=1;p<=sum[i];p++){
			f[p]=f[p-1]*g;
			if(p>1) f[p]=(f[p]+f[p-2]*(p-1)%mod*i)%mod;
		}
		ans=ans*f[sum[i]]%mod;
	}
	memset(vis,0,sizeof(vis));
	for(int i=1;i<=n;i++){
		if(inc[i]&&len[i]){
			int g=i;
			int x=b[g],L=1;
			while(!len[x]) x=b[x],L++;
			if(len[g]>L) return puts("0"),0;
			if(len[g]<L) ans=ans*2%mod;
			g=a[g];L=1;
			while(g!=i){
				if(!len[g]){
					L++;g=a[g];continue;
				}
				if(len[g]>L) return puts("0"),0;
				if(len[g]<L)
					ans=ans*2%mod;
				L=1;g=a[g];
			}
			g=i;
			while(inc[g]) inc[g]=0,g=a[g];
		}
	}
	printf("%lld",ans);
	return 0;
}

Measured memory_bytes: 2432
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repo(i,n) for(int i = 1; i < (int)(n); i++)
#define pb push_back
#define np next_permutation
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
#define pi acos(-1.0)
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }
//intの最大値2147483647 ≒ 2×10^9
//long longの最大値9223372036854775807 ≒ 9×10^18
//'0'+=16;        で大文字に
//'大文字'+=32;    で小文字に
//s[i]-'0'でchar文字→int数に;
//string s = to_string(int数);
//int n = stoi(string文字列)
//cout << fixed << setprecision (20);   小数点以下2０桁まで
//実行時間制約2秒では２×10^8回くらいまで計算できる


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

  vector<int> p(2*n);
  rep(i,2*n){
  cin>>p[i];
  }
  
  sort(all(p));
  reverse(all(p));
  
  int ans = 0;
  rep(i,2*n){
  if(i%2==1) ans+=p[i];
  }
  
  cout << ans << endl;
  
}


Measured memory_bytes: 256
#include<iostream>
#include<string.h>
#include<string>
#include<stdio.h>
#include<algorithm>
#include<vector>
#include<math.h>
#include<queue>
#include<set>
#include<map>
using namespace std;
typedef long long ll;
#define lowbit(x) (x)&(-x)
#define sqr(x) (x)*(x)
#define rep(i,a,b) for (register int i=a;i<=b;i++)
#define per(i,a,b) for (register int i=a;i>=b;i--)
#define fir first
#define sec second
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define maxd 998244353
#define eps 1e-8
int read()
{
    int x=0,f=1;char ch=getchar();
    while ((ch<'0') || (ch>'9')) {if (ch=='-') f=-1;ch=getchar();}
    while ((ch>='0') && (ch<='9')) {x=x*10+(ch-'0');ch=getchar();}
    return x*f;
}

int main()
{
    int n=read(),k=read();
    if (k==1) {puts("0");return 0;}
    int minp=1,maxp=n-(k-1);
    cout << maxp-minp << endl;
    return 0;
}

Measured memory_bytes: 256
import java.io.*;
import java.math.BigInteger;
import java.util.*;

public class Main
{
    static class Node{
        int b = 0;
        int w = 0;
        List<Integer> child;
    }
    static int subsetSum(int[] arr, int target){
        int n = arr.length;
        int m = target + 1;
        boolean[][] dp = new boolean[n][m];
        for (int i = 0; i < n; i++) {
            if (arr[i] > target) continue;
            dp[i][arr[i]] = true;
        }
        for (int i = 1; i < n; i++) {
            for (int j = 0; j < m; j++) {
                if (dp[i-1][j]){
                    dp[i][j] = true;
                    if (j + arr[i] <= target){
                        dp[i][j+arr[i]] = true;
                    }
                }
            }
        }
        for (int i = m-1; i >= 0;i--) {
            if (dp[n-1][i]){
                return i;
            }
        }
        return 0;
    }

    static Node[] nodes;
    static int[] X;
    public static void main(String[] args) throws FileNotFoundException {
        Scanner sc= new Scanner(System.in);
        int N = sc.nextInt();
        nodes = new Node[N];
        X = new int[N];
        for (int i = 0; i < N; i++) {
            nodes[i] = new Node();
            nodes[i].child = new ArrayList<>();
        }
        for (int i = 1; i < N; i++) {
            int par = sc.nextInt();
            nodes[par - 1].child.add(i);
        }
        for (int i = 0; i < N; i++) {
            X[i] = sc.nextInt();
        }
        System.out.println(recur(0) ? "POSSIBLE": "IMPOSSIBLE");
    }

    public static boolean recur(int nodeIdx){
        Node cur = nodes[nodeIdx];
        if (cur.child == null || cur.child.size() == 0){
            cur.b = 0; cur.w = X[nodeIdx];
            return true;
        }
        for (int i = 0; i < cur.child.size(); i++) {
            if (!recur(cur.child.get(i))) {
                return false;
            }
        }
        int b = 0, w = 0;
        int[] swap = new int[cur.child.size()];
        for (int i = 0; i < cur.child.size(); i++) {
            int black = nodes[cur.child.get(i)].b;
            int white = nodes[cur.child.get(i)].w;
            b += Math.min(white, black);
            w += Math.max(white, black);
            swap[i] = Math.max(white, black) - Math.min(white, black);
        }
        if (b > X[nodeIdx]) {
            return false;
        }
        int sww = subsetSum(swap, X[nodeIdx] - b);
        cur.b = X[nodeIdx];
        cur.w = w - sww;
        return true;
    }

}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define REP(i,n) for(int i=0;i<(n);i++)
#define RREP(i,n) for(int i=(n)-1;i>=0;i--)
#define VSORT(v) sort(v.begin(), v.end())
#define DVSORT(v) sort(v.begin(), v.end(),greater<int>())
#define SORT(v, n) sort(v, v+n)
#define DSORT(v,n) sort(v, v+n,greater<int>())
#define vi vector<int>
#define pb push_back
#define P pair<int,int>


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

const double EPS =1e-9;
const long INF =999999999;
const long MOD =1000000007; //10^9+7
#define PI 3.14159265258979

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

int main(){
	int N,T,arrive[200001],sum=0;
	cin>>N>>T;
	REP(i,N) cin>>arrive[i];

	FOR(i,1,N) sum+=(min(arrive[i]-arrive[i-1],T));

	printf("%d\n",sum+T);
	return 0;
}



Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[4]={1,0,-1,0};
const ll dx[4]={0,-1,0,1};
int main(){
    cin.tie(0);cout.tie(0);
    ios::sync_with_stdio(false);
    ll N;cin>>N;
    cout<<N*(N-1)/2<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <map>

using namespace std;

typedef long long ll;

int main() {
    map<ll,ll> m;
    ll n, *a;
    cin >> n;
    a = new ll[n];
    ll sum = 0;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        sum += a[i];
        m[a[i]]++;
    }

    ll q;   cin >> q;
    ll *s = new ll[q];
    for (int i = 0; i < q; i++) {
        ll b, c;    cin >> b >> c;
        ll tmp = m[b];
        m[b] = 0;
        m[c] += tmp;
        sum += (c-b)*tmp;
        s[i] = sum;
    }

    for (int i = 0; i < q; i++)
        cout << s[i] << endl;

    return 0;
}

Measured memory_bytes: 11104
N = int(input())
S = input()

R = S.count('R')
G = S.count('G')
B = S.count('B')

A = 0
if R == 0 or G == 0 or B == 0 :
    print(A)
else:
    A = R*G*B
    for i in range((N-3)//2 +1):#間の大きさ
        for j in range(N-3-2*i +1):#スタートからずれていく
            if S[j] != S[j+i+1] and S[j+i+1] != S[j+2*i+2] and S[j+2*i+2] != S[j]:
                A -= 1
    print(A)

Measured memory_bytes: 9212
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> lpair;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define rREP(i,m,n) for(ll i = (m); i >= (n); i--)
#define ALL(c) (c).begin(), (c).end()
#define print(x) cout << (x) << endl;
#define printa(x,n) for(ll i = 0; i < n; i++){ cout << (x[i]) << " ";} cout<<endl;
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;cin>>n;
    cout << n*n << endl;
    
    
}




Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <math.h>
#include <string.h>
#include <stdio.h>
#include <string>
#include <cstdlib>
#define rep(i,o,u) for(int i = o;i < u; i++)
typedef long long ll;
using namespace std;   
ll w[100010];
int check(ll p,int n,int k){
	int i = 0;
	rep(j, 0, k){
		ll sum = 0;
		while (sum + w[i] <= p){
			sum += w[i++];
			if (i == n) return n;
		}
	}
	return i;
}
ll solve(int n,int k){
	ll left = 0;
	ll right = 10000 * 100000;
	ll mid;
	while (left + 1 < right){
		mid = (left + right) / 2;
		int v = check(mid, n, k);
		if (v >= n) right = mid;
		else left = mid;
	}
	return right;
}
int main(){
	int n,k;
	cin >> n >> k;
	rep(i, 0, n){ cin >> w[i]; }
	cout << solve(n, k) << endl;
	return 0;
}

Measured memory_bytes: 3876
# 2019/08/08

n=int(input())
s=sorted([int(input()) for _ in range(n)])

sum_s=sum(s)
if sum_s%10:
    print(sum_s)
    exit()

for i in range(n):
    if s[i]%10:
        print(sum_s-s[i])
        exit()
print(0)

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

using ll = long long;
#define rep(i, n) for (long long i = 0; i < (n); ++i)
#define repr(i, a, b) for (auto i = (a); i < (b); ++i)
#define itr(x) for (auto&& v : (x))
#define updatemax(t, v) ((t) = std::max((t), (v)))
#define updatemin(t, v) ((t) = std::min((t), (v)))

#include <boost/operators.hpp>

class modint : private boost::operators<modint>, private boost::equivalent<modint> {
  modint(const long long x, const bool y)
      : x(x) {}

 public:
  static long long M;
  long long x;
  modint(const long long x = 0)
      : x((x % M + M) % M) {}
  modint operator-() const { return modint(x ? M - x : 0, true); }
  modint& operator+=(const modint& b) { return ((x += b.x) >= M ? x -= M : 0), *this; }
  modint& operator++() { return (++x >= M ? x -= M : 0), *this; }
  modint& operator-=(const modint& b) { return ((x -= b.x) < 0 ? x += M : 0), *this; }
  modint& operator--() { return (--x < 0 ? x += M : 0), *this; }
  modint& operator*=(const modint& b) { return x = x * b.x % M, *this; }
  modint& operator/=(const modint& b) { return *this *= b.pow(-1); }
  modint pow(long long b) const {
    long long r = 1, a = x;
    b = (b % (M - 1) + (M - 1)) % (M - 1);
    while (b) {
      if (b & 1) r = r * a % M;
      b = b >> 1;
      a = a * a % M;
    }
    return modint(r, true);
  }
  friend bool operator<(const modint& a, const modint& b) { return a.x < b.x; }
  friend std::istream& operator>>(std::istream& s, modint& a) { return s >> a.x, a = a.x, s; }
  friend std::ostream& operator<<(std::ostream& s, const modint& a) { return s << a.x; }
};
long long modint::M = 1e9 + 7;

int main() {
  ll r1, c1, r2, c2;
  cin >> r1 >> c1 >> r2 >> c2;
  ++r2;
  ++c2;
  modint result(0), temp(1), r1f, c1f, r2f, c2f, r1c1f, r1c2f, r2c1f, r2c2f;
  rep(i, r2 + c2 + 1) {
    if (i == r1) r1f = temp;
    if (i == c1) c1f = temp;
    if (i == r2) r2f = temp;
    if (i == c2) c2f = temp;
    if (i == r1 + c1) r1c1f = temp;
    if (i == r1 + c2) r1c2f = temp;
    if (i == r2 + c1) r2c1f = temp;
    if (i == r2 + c2) r2c2f = temp;
    temp *= i + 1;
  }
  result += r2c2f / (r2f * c2f);
  result -= r2c1f / (r2f * c1f);
  result -= r1c2f / (r1f * c2f);
  result += r1c1f / (r1f * c1f);
  cout << result << endl;
}


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

#define INF 100100100
#define MOD 1000000007

#define FOR(i,n) for(int i=0;i<n;i++)

using namespace std;
using ll = long long;
using ull = unsigned long long ;

struct edge{ll to,cost;};

int main(int argc, char const* argv[]){
   int N;
   cin >> N;
   for(int i=1;i<=9;i++){
      if(N<=111*i){
         cout << 111*i;
         break;
      }
   }
   return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back
#define pp pop_back
#define in insert
#define ff first
#define ss second
#define  show for(int j=0;j<v.size();j++) cout<<v[j]<<" ";
#define ld long double
#define e endl
#define bc __builtin_popcount
#define MOD 1000000007
#define MAXN 200005
#define INT_SIZE 32
#define debug cout<<"we are debugging"<<endl;
#define me(x) memset(x,0,sizeof(x))
ll fast_expo(ll x,ll p)
{if(p==0) return 1;
else if(p%2==0){ ll t=fast_expo(x,p/2)%MOD;return (t*t)%MOD;} else return (x*(fast_expo(x,p-1))%MOD)%MOD;}
const ll MAX = 2000000;
ll fac[MAX], finv[MAX], inv[MAX];
void cmbinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (ll i=2;i<MAX;i++) {
		fac[i] = fac[i-1]*i%MOD;
		inv[i] = MOD-inv[MOD%i]*(MOD/i)%MOD;
		finv[i] = finv[i-1]*inv[i]%MOD;
	}
}
ll cmb(ll n, ll k) {
	if(n<k) return 0;
	if(n<0 || k<0) return 0;
	return fac[n]*(finv[k]*finv[n-k]%MOD)%MOD;
}
int main()
{
     int s;
     cin>>s;
     vector<ll> dp(s+1,0),v;
     for(int i=3;i<=s;i++)
     {
          v.pb(i);
     }
     dp[0]=1;
     for(int i=1;i<=s;i++)
     {
          for(int j=0;j<v.size();j++)
          {
               if(v[j]<=i)
                    {dp[i]+=dp[i-v[j]];
                    dp[i]%=MOD;}
          }
     }
     cout<<dp[s]<<e;
}



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

ans = 0

buf = 99
for i in a :
    i = i - 1
    ans += b[i]
    if buf != 99 and i == buf + 1 :
        ans += c[buf]
    buf = i

print(ans)


Measured memory_bytes: 3060
from collections import deque
s=input()
q=int(input())
flg=True
s1=deque()
s2=deque()
for _ in range(q):
    t=list(input().split())
    if t[0]=='1':
        flg=not flg
    else:
        if t[1]=='1':
            if flg:
                s1.appendleft(t[2])
            else:
                s2.append(t[2])
        else:
            if flg:
                s2.append(t[2])
            else:
                s1.appendleft(t[2])
if flg:
    print(''.join(s1)+s+''.join(s2))
else:
    print(''.join(s2)[::-1]+s[::-1]+''.join(s1)[::-1])

Measured memory_bytes: 6516
// #pragma GCC target("avx2")  // CPU 処理並列化
// #pragma GCC optimize("O3")  // CPU 処理並列化
// #pragma GCC optimize("unroll-loops")  // 条件処理の呼び出しを減らす
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<stack>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#include<stdlib.h>
#include<cassert>
#include<time.h>
#include<bitset>
#include<numeric>
#include<unordered_set>
#include<complex>
using namespace std;
const long long mod=1000000007;
const long long inf=mod*mod;
const long long d2=(mod+1)/2;
const double EPS=1e-10;
const double INF=1e+10;
const double PI=acos(-1.0);
const int C_SIZE = 3100000;
namespace{
	long long fact[C_SIZE];
	long long finv[C_SIZE];
	long long inv[C_SIZE];
	long long Comb(int a,int b){
	 	if(a<b||b<0)return 0;
	 	return fact[a]*finv[b]%mod*finv[a-b]%mod;
	}
	void init_C(int n){
		fact[0]=finv[0]=inv[1]=1;
		for(int i=2;i<n;i++){
			inv[i]=(mod-(mod/i)*inv[mod%i]%mod)%mod;
		}
		for(int i=1;i<n;i++){
			fact[i]=fact[i-1]*i%mod;
			finv[i]=finv[i-1]*inv[i]%mod;
		}
	}
	long long pw(long long a,long long b){
		if(a<0LL)return 0;
		if(b<0LL)return 0;
		long long ret=1;
		while(b){
			if(b%2)ret=ret*a%mod;
			a=a*a%mod;
			b/=2;
		}
		return ret;
	}
	long long pw_mod(long long a,long long b,long long M){
		if(a<0LL)return 0;
		if(b<0LL)return 0;
		long long ret=1;
		while(b){
			if(b%2)ret=ret*a%M;
			a=a*a%M;
			b/=2;
		}
		return ret;
	}
	int pw_mod_int(int a,int b,int M){
		if(a<0)return 0;
		if(b<0)return 0;
		int ret=1;
		while(b){
			if(b%2)ret=(long long)ret*a%M;
			a=(long long)a*a%M;
			b/=2;
		}
		return ret;
	}
	int ABS(int a){return max(a,-a);}
	long long ABS(long long a){return max(a,-a);}
	double ABS(double a){return max(a,-a);}
	int sig(double r) { return (r < -EPS) ? -1 : (r > +EPS) ? +1 : 0; }
}
// ここから編集しろ

int main(){
	int a;scanf("%d",&a);
	for(int i=0;i<51000;i++){
		if(i*108/100==a){
			printf("%d\n",i);return 0;
		}
	}
	printf(":(\n");

}


Measured memory_bytes: 128
#include<map>
#include<iostream>
#include<string>
using namespace std;
int main(){
    int num;
    cin >> num;
     
    map<string,int> dic;
     
    for(int i=0;i<num;i++){
        string process,key;
         
        cin >> process >> key;
         
        if(process[0]=='i'){
            dic[key]=1;
        }else{
            if(dic[key]==0){
                cout << "no" << endl;
            }else{
                cout << "yes" << endl;
            }
        }
    }
}

Measured memory_bytes: 52444