akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <utility>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <queue>
#include <map>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1<<30; 
const int MOD = 1e9 + 7;
const int dy[] = {1, 0, -1, 0};
const int dx[] = {0, 1, 0, -1};
const int MAX_N = 200010;
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, k; cin >> n >> k;
    map<int, int> mp;
    for(int i = 0; i < n; i++)
    {
        int x; cin >> x;
        mp[x]++;
    }
    int ans = 0;
    vector<P> v;
    for (auto itr : mp)
    {
        v.push_back(P(itr.second, itr.first));
    }
    sort(v.begin(), v.end());
    int cnt = v.size() - k;
    for(int i = 0; i < v.size(); i++)
    {
        if(cnt <= 0) break;
        ans += v[i].first;
        cnt--;
    }
    cout << ans << "\n";
    return 0;
}



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

#define ll long long

typedef pair<int,int>P;

int main(){
	ll h,w,n;
	cin>>h>>w>>n;
	ll ans[10]={};
	ans[0]=(h-2)*(w-2);
	set<P>s[10];
	for(int i=0;i<n;i++){
		int x,y;
		
		cin>>x>>y;
		swap(y,x);
		for(int dx=-2;dx<=0;dx++){
			for(int dy=-2;dy<=0;dy++){
				if(x+dx<1 || y+dy<1 || x+dx>w-2 || y+dy>h-2)continue;
				P p(x+dx,y+dy);
				for(int j=8;j>=0;j--){
					if(j==0){
						ans[0]--;
						ans[1]++;
						s[1].insert(p);
						break;
					}
					if(s[j].find(p)!=s[j].end()){
						s[j].erase(p);
						s[j+1].insert(p);
						ans[j]--;
						ans[j+1]++;
						break;
					}
				}
			}
		}
	}
	for(int i=0;i<10;i++){
		cout<<ans[i]<<endl;
	}
	
	
	return 0;
}


Measured memory_bytes: 42368
#include <cstdio>
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <string>
#include <cstring>
#include <sstream>
#include <algorithm>
#include <functional>
#include <queue>
#include <stack>
#include <cmath>
#include <iomanip>
#include <list>
#include <tuple>
#include <bitset>
#include <ciso646>
#include <cassert>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> T;
typedef vector<ll> vec;

inline bool check(ll x, ll y, ll xMax, ll yMax) { return x >= 0 && y >= 0 && xMax > x && yMax > y; }
inline int toint(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string tostring(T x) { ostringstream sout; sout << x; return sout.str(); }
template<class T> inline T sqr(T x) { return x*x; }
template<class T> inline T mypow(T x, ll n) { T res = 1; while (n > 0) { if (n & 1)res = res * x;	x = x * x;	n >>= 1; }return res; }
inline ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
inline ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

#define For(i,a,b)	for(ll (i) = (a);i < (b);(i)++)
#define rep(i,n)	For(i,0,n)
#define rFor(i,a,b)	for(ll (i) = (a-1);i >= (b);(i)--)
#define rrep(i,n)	rFor(i,n,0)
#define each(i,n)	for(auto &i : n)
#define clr(a)		memset((a), 0 ,sizeof(a))
#define mclr(a)		memset((a), -1 ,sizeof(a))
#define all(a)		(a).begin(),(a).end()
#define sz(a)		(sizeof(a))
#define tostr(a)	tostring(a)
#define dump(val) 	cerr << #val " = " << val << endl;
#define Fill(a,v)	fill((int*)a,(int*)(a+(sz(a)/sz(*(a)))),v)

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

const ll mod = 1e9 + 7;
const ll INF = 1e17 + 9;

#define int ll
#define double ld

signed main() {
	cin.tie(0);
	ios_base::sync_with_stdio(false);

	int n, a, b;
	cin >> n >> a >> b;
	vector<int> t(n);
	for (int i = 0; i < n; i++) {
		cin >> t[i];
	}
	sort(all(t));
	int ans = 0;
	rep(i, n) {
		if (t[i] < a || t[i] >= b) {
			ans++;
		}
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define meow(args...) fprintf(stderr, args)
typedef unsigned u32;
typedef long long s64;
typedef unsigned long long u64;
template<class T1, class T2> inline bool cmin(T1 &a, const T2 &b) {return b<a?(a=b, true):false;}
template<class T1, class T2> inline bool cmax(T1 &a, const T2 &b) {return a<b?(a=b, true):false;}
template<class Type> Type read() {
	Type a;
	bool b;
	unsigned char c;
	while(c=getchar()-48, (c>9)&(c!=253));
	for(a=(b=c==253)?0:c; (c=getchar()-48)<=9; a=a*10+c);
	return b?-a:a;
}
int (*rd)()=read<int>;
//const u32 P=;
//inline u32 &inc(u32 &a, u32 b) {return (a+=b)<P?a:(a-=P);}
//inline u32 &dec(u32 &a, u32 b) {return (a-=b)&0x80000000?(a+=P):a;}
//inline u32 sum(u32 a, u32 b) {return (a+=b)<P?a:a-P;}
//inline u32 dif(u32 a, u32 b) {return (a-=b)&0x80000000?a+P:a;}
//u64 power(u64 a, int b) {
//	u64 ans=1;
//	for(; b; a=a*a%P, b/=2) if(b&1) ans=ans*a%P;
//	return ans;
//}
const int N=1e5;
int n, s, x[N], pos[N];
s64 p[N];
int main() {
	n=rd(), s=rd();
	for(int i=0; i<n; ++i) x[i]=rd(), p[i]=rd();
	int l=0, r=n-1, tot=n;
	while(x[l]<s&&x[r]>s)
		if(p[l]<p[r]) {
			pos[--tot]=x[l];
			p[r]+=p[l++];
		} else {
			pos[--tot]=x[r];
			p[l]+=p[r--];
		}
	if(x[l]>=s) {
		while(r>=l) pos[--tot]=x[r--];
	} else {
		while(l<=r) pos[--tot]=x[l++];
	}
	s64 ans=0;
	for(int i=0; i<n; ++i) {
		ans+=abs(pos[i]-s);
		s=pos[i];
	}
	printf("%lld\n", ans);
	return 0;
}


Measured memory_bytes: 1792
import java.util.*;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int N = sc.nextInt();
		int[] a = new int[N];
		for(int i=0; i<N; i++)
			a[i] = sc.nextInt();
		
		int ans = 0;
		int last = 0;
		for(int i=0; i<N; i++) {
			int num=0;
			while(1<<(num+1)<=a[i])
				num++;
			int additional = 1<<num<a[i] ? 1 : 0;
			if(last<=num) {
				ans += num+additional-last;
				last = num+additional;
			} else {
				last = num;
			}
		}
		
		System.out.println(ans);
		
		sc.close();
	}
}


Measured memory_bytes: 51528
#include <iostream>
#include <cmath>

using namespace std;

int main() {
    int N, R;
    cin >> N;
    int A = N, B = 0, C = 0;
    for (int i = 0; i < N; i++) {
        cin >> R;
        B -= R;
        C += R * R;
    }
    B *= 2;
    float temp = (float)((-1) * B) / (2 * A);
    int X;
    if (temp - (int)temp < 0.5) {
        X = temp;
    }
    else {
        X = temp + 1;
    }
    int Y = A * X * X + B * X + C;
    while (X < 0 || Y < 0) {
        X++;
        Y = A * X * X + B * X + C;
    }
    cout << Y;
    return 0;
}

Measured memory_bytes: 256
using System;
using System.Linq;
using static System.Console;
class Z { static void Main() => new K(); }
class K
{
	long g, L;
	public K()
	{
		var I = ReadLine().Split().Select(long.Parse).ToArray();
		var N = I[0];
		L = I[1];
		var root = new object[2];
		for (var i = 0; i < N; i++)
		{
			var s = ReadLine();
			var n = root;
			for (var j = 0; j < s.Length; j++)
			{
				var x = s[j] - '0';
				n = (object[])(n[x] = n[x] ?? new object[2]);
			}
		}
		DFS(root, 0);
		WriteLine(g != 0 ? "Alice" : "Bob");
	}
	void DFS(object[] n, int d)
	{
		if (C(n[0]) + C(n[1]) == 1) g ^= F(L - d);
		foreach (var c in n) if (c != null) DFS((object[])c, d + 1);
	}
	long F(long n)
	{
		var c = 1L;
		while (n % 2 == 0) { c <<= 1; n >>= 1; }
		return c;
	}
	int C(object o) => o == null ? 0 : 1;
}


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

int main(){
 string S,T;
 T="ABC";
 int N;
 int tot=0;
 cin>>N>>S;
 for(int i=0;i<N;i++){
     if(S[i]==T[0]&&S[i+1]==T[1]&&S[i+2]==T[2]){
         tot++;
     }
 }
 if(N>=3&&N<=50&&S.length()==N){
     cout<<tot;
 }
   return 0;
   
}

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

void solve(std::istream &ist, std::ostream &ost)
{
    /* ------- 宣言と入力 ------- */

    int K;

    ist >> K;

    /* ------- 計算 ------- */

    long long num;

    queue<long long> que;

    for (int i = 1; i <= 9; i++)
    {
        que.push(i);
    }

    for (int i = 0; i < K; i++)
    {
        num = que.front();
        que.pop();

        if (num % 10 != 0)
        {
            que.push(10 * num + num % 10 - 1);
        }

        que.push(10 * num + num % 10);

        if (num % 10 != 9)
        {
            que.push(10 * num + num % 10 + 1);
        }
    }

    ost << num << endl;
}

#ifndef WOMAIN
int main()
{
    solve(std::cin, std::cout);
    return 0;
}
#endif


Measured memory_bytes: 1792
#include <cstdio>
#include <vector>
#include <algorithm>

#define all(v) (v).begin(), (v).end()
using namespace std;

int main()
{
    int no_of_skewers;
    scanf("%d", &no_of_skewers);

    vector <int> length(2*no_of_skewers);
    for(int i = 0; i < 2*no_of_skewers; i++)
        scanf("%d", &length[i]);

    sort(all(length));

    int sum = 0;
    for(int i = 2*no_of_skewers - 2; i >= 0; i-= 2)
        sum += length[i];

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


Measured memory_bytes: 256
N, A, B = list(map(int, input().split()))
ans=0
if (B-A)%2 == 0:
  ans = (B-A)//2
else:
  if N-B <= A-1:
    ans += N-B
    A += N-B+1
    ans += (N-A)//2 + 1
  else:
    ans += A-1
    B -= A-1+1
    ans += (B-1)//2 + 1
print(ans)

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

bool check(vector<int> a, vector<int> b, int N) {
    for (int i = 0; i < N; i++) {
        if (a[i] != b[i]) return false;
    }
    return true;
}

int main() {
    int N; cin >> N;
    vector<int> P(N), Q(N), perm(N);
    for (int i = 0; i < N; i++) cin >> P[i];
    for (int i = 0; i < N; i++) cin >> Q[i];
    for (int i = 0; i < N; i++) perm[i] = i + 1;
    int p_idx = -1, q_idx = -1;
    int counter = 0;
    do {
        counter++;
        if (p_idx == -1) {
            if (check(P, perm, N)) {
                p_idx = counter;
            }
        }
        if (q_idx == -1) {
            if (check(Q, perm, N)) {
                q_idx = counter;
            }
        }
    } while (next_permutation(perm.begin(), perm.end()) && (p_idx == -1 || q_idx == -1));
    cout << abs(p_idx - q_idx);
}

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

using namespace std;
#define lint long long
#define P pair<int, int>

int main() {
    int H, W;
    cin >> H >> W;
    
    char a[H][W];
    
    for(int i = 0; i < H; ++i){
        for(int j = 0; j < W; ++j){
            cin >> a[i][j];
        }
    }
    
    vector<int> r,c;
    
    for(int i = 0; i < H; ++i){
        for(int j = 0; j < W; ++j){
            if(a[i][j] == '#'){
                r.push_back(i);
                break;
            }
        }
    }
    
    for(int i = 0; i < W; ++i){
        for(int j = 0; j < H; ++j){
            if(a[j][i] == '#'){
                c.push_back(i);
                break;
            }
        }
    }
    
    for(int i = 0; i < r.size(); ++i){
        for(int j = 0; j < c.size(); ++j){
            cout << a[r[i]][c[j]];
        }
        cout << endl;
    }
}


Measured memory_bytes: 256
#include <cmath>
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <map>
#include <list>
#include <time.h>
#include <math.h>
#include <random>
#include <deque>
#include <queue>
#include <cassert>
#include <unordered_map>
#include <iomanip>

using namespace std;

const int N = 50 + 7;

long long dp[N][2];

int main()
{
#ifdef ONPC
    freopen("a.in", "r", stdin);
#endif
    dp[0][0] = 1;
    int n, p;
    scanf("%d%d", &n, &p);
    for (int i = 0; i < n; i++)
    {
        int x;
        scanf("%d", &x);
        dp[i + 1][0] += dp[i][0];
        dp[i + 1][1] += dp[i][1];
        if (x % 2)
        {
            dp[i + 1][1] += dp[i][0];
            dp[i + 1][0] += dp[i][1];
        }
        else
        {
            dp[i + 1][0] += dp[i][0];
            dp[i + 1][1] += dp[i][1];
        }
    }
    cout << dp[n][p] << endl;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {

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

        String s = scanner.next();
        String t = scanner.next();

        int sum = 0;
        for (int i = 0; i < s.length(); i++) {
            char sc = s.charAt(i);
            char tc = t.charAt(i);
            if (sc != tc) {
                sum++;
            }
        }

        System.out.println(sum);

    }

}

Measured memory_bytes: 41404
N = int(input()) # number of coins
tmp = [float(i) for i in input().split()]
dp = [0 for i in range(N+1)] # 0 - N heads
dp[0] = 1
# initialize
for i in range(N):
  k = tmp[i]
  # when the very first coin comes we need to verify update format
  # 1 head or 1 tails
  # j is the number of heads which goes from 0 - N
  for j in range(i+1, -1, -1):
    dp[j] = dp[j-1] * k + dp[j] * (1-k)
ans = 0
for i in range(N+1):
  tails = N-i
  if tails < i:
    ans += dp[i]
print("%s" % ans)

Measured memory_bytes: 41948
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N, A, B;
  cin >> N >> A >> B ;
  int p1, p2;
  p1 = N * A, p2 = B;
  
  if (p1 < p2){
    cout << p1 << endl;
  }
  else {
    cout << p2 << endl;
  }


}

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

int main() {
  
  map<int, pair<int, int>> Map;
  
  for (int i = 0; i < 3; i++) {
    for (int j = 0; j < 3; j++) {
      int x;
      cin >> x;
      pair<int, int> p;
      p = make_pair(i,j);
      Map[x] = p;
    }
  }
  bool A[3][3];
  
  for (int i = 0; i < 3; i++) {
    for (int j = 0; j < 3; j++) {
      A[i][j] = false;
    }
  }
  
  int N;
  cin >> N;
  
  for (int i = 0; i < N; i++) {
    int b;
    cin >> b;
    
    if (Map.find(b) != Map.end()) {
      A[Map[b].first][Map[b].second] = true;
    } 
  }
  

  // 横
  for (int i = 0; i < 3; i++) {
    if (A[i][0] && A[i][1] && A[i][2]) {
      cout << "Yes" << endl;
      return 0;
    }
  }
  // たて
  for (int i = 0; i < 3; i++) {
    if (A[0][i] && A[1][i] && A[2][i]) {
      cout << "Yes" << endl;
      return 0;
    }
  }
  // ななめ
  if ((A[0][0] && A[1][1] && A[2][2]) || (A[2][0] && A[1][1] && A[0][2])) {
    cout << "Yes" << endl;
    return 0;
  }
  
  cout << "No" << endl;
    
    
  
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const long long INF = 1LL << 60;

int main() {
    int N;
    cin >> N;
    vector<int> A(N+2);
    A[0] = 0;
    A[N+1] = 0;
    for(int i=1; i<=N; i++) cin >> A[i];
    int total_cost = 0;

    for(int i=0; i<=N; i++) {
        total_cost += abs(A[i]-A[i+1]);
    }
    
    for(int i=1; i<=N; i++) {
        int c = total_cost - abs(A[i]-A[i-1]) - abs(A[i]-A[i+1]) + abs(A[i-1] - A[i+1]);
        cout << c << endl;
    }
}

Measured memory_bytes: 3756
#include<bits/stdc++.h>
using namespace std;
    int main()
    {
        typedef long long ll;
        ll x,sum[200009],n,ans,minn;
        scanf("%lld",&n);
        sum[0]=0;
        ll i=1;
        for(i=1;i<=n;i++)
        {
            scanf("%lld",&x);
            sum[i]=sum[i-1]+x;
        }
        ans=sum[n];
        minn=abs(2*sum[1]-sum[n]);
        for(i=2;i<=n-1;i++)
        {
            minn=min(minn,abs(2*sum[i]-sum[n]));
        }
        printf("%lld\n",minn);
        return 0;
    }

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

#define vint vector<int>
#define vvint vector<vint>
#define sint stack<int>
#define qint queue<int>
#define rep(i, n) for(int i=0;i<(int)(n);i++) // 繰り返し処理
#define all(x) (x).begin(),(x).end() // 全体 こんな感じで使う→sort(all(a));
#define ct(a) cout << a << endl
#define iceil(a,b) (a+(b-1))/b //int ceil : 繰り上げの割り算 通常のceilではceil((7.0/2.0))のようにしなければならなかった。
vint CinLine(int N){vint v(N);for(int i=0;i<N;i++){cin >> v.at(i);}return v;}//cin line 連続でvectorに格納
void CoutLine(vint v){for(int i=0;i<v.size()-1;i++){cout<<v.at(i)<<" ";}cout << v.at(v.size()-1)<<endl;}
// str.substr(開始位置, 取り出す長さ);

int main() {
    int x,y;
    bool isOK = false;
    cin >> x >> y;
    for(int t = 0 ; t <= x ; t++){
        for(int k = (x-t) ; k+t <= x ; k++) {
            //cout << t << " " << k << endl;
            if((t*2 + k*4 == y) || (t*4 + k*2 == y)){
                isOK = true;
                break;
            }
        }
        if(isOK){
            break;
        }
    }
    if(isOK) ct("Yes");
    else ct("No");
}

Measured memory_bytes: 3628
package main

import (
	"fmt"
	"io"
	"os"
)

func answer(reader io.Reader, writer io.Writer) {
	var n int
	fmt.Fscan(reader, &n)
	a := make([]int, n)
	m := uint64(1000000000 + 1)
	s := uint64(0)
	c := 0
	for i := 0; i < n; i++ {
		fmt.Fscan(reader, &a[i])
		v := a[i]
		if v < 0 {
			v = -v
			c++
		}
		if uint64(v) < m {
			m = uint64(v)
		}
		s += uint64(v)
	}
	if c%2 == 0 {
		_, _ = fmt.Fprintf(writer, "%d", s)
	} else {
		_, _ = fmt.Fprintf(writer, "%d", s-m-m)
	}
}

func main() {
	answer(os.Stdin, os.Stdout)
}


Measured memory_bytes: 7296
import java.math.BigInteger;
import java.util.Scanner;

public class Main {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		Scanner cin = new Scanner(System.in);
		while(cin.hasNext()){
			String str=cin.next();
			String s1 = str.substring(0, str.indexOf('+'));
			String s2 = str.substring(str.indexOf('+')+1, str.indexOf('='));
			String s3 = str.substring(str.indexOf('=')+1);
			int output=-1;
			for(int i = 0; i < 10;i++){
				String r1= s1.replace('X',(char)( i+'0'));
				String r2= s2.replace('X',(char)( i+'0'));
				String r3= s3.replace('X',(char)( i+'0'));
				if(r1.charAt(0)=='0'&&r1.length()!=1){
					continue;
				}
				if(r2.charAt(0)=='0'&&r2.length()!=1){
					continue;
				}
				if(r3.charAt(0)=='0'&&r3.length()!=1){
					continue;
				}
				BigInteger a = new BigInteger(r1);
				BigInteger b = new BigInteger(r2);
				BigInteger c = new BigInteger(r3);
				if(a.add(b).equals(c)){
					output=i;
					break;
				}/*
				int x = Integer.parseInt(r1);
				int y = Integer.parseInt(r2);
				int z = Integer.parseInt(r3);
				if(x+y==z){
					output=i;
				}*/
			}
			if(output==-1){
				System.out.println("NA");
			}
			else{
				System.out.println(output);
			}
		}

	}

}

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

int main(){
  ll mod = 1e9+7;
  ll n;
  cin >> n;
  vector<ll> a(n);
  for(ll i=0; i<n; i++) cin >> a[i];
  
  ll one = 1;
  vector<ll> c(61, 0);
  vector<ll> d(61, 0);
  for(ll i=0; i<n; i++){
  	for(ll j=0; j<61; j++){
      if((a[i] >> j) & one){
        c[j]++;
      }else{
      	d[j]++;
      }
    }
  }
  
  ll ans = 0;
  for(ll j=0; j<61; j++){
  	ans += (((c[j]*d[j]) % mod) * ((one << j) % mod)) % mod;
    ans %= mod;
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 2560
#include<bits/stdc++.h>
using namespace std;
int main(){
	long long int a,b,n,i,j,x,y,z,mid;
	cin>>a>>b>>n;
	i=1;j=min(b,n);
	while(i<(j-1)){
		mid=(i+j)/2;
		x=floor((a*mid)/b)-a*floor(mid/b);
		y=floor((a*(mid-1))/b)-a*floor((mid-1)/b);
		z=floor((a*(mid+1))/b)-a*floor((mid+1)/b);
		if(x<y&&x<z){
			if(y>z)
			j=mid-1;
			else 
			i=mid+1;
		}
		else if(x<y)
		j=mid;
		else if(x<z)
		i=mid;
		else {
			i=mid;
		}
	}
	x=floor((a*i)/b)-a*floor(i/b);
	y=floor((a*j)/b)-a*floor(j/b);
	cout<<max(x,y)<<endl;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define int long long
#define mod (int)(1e9+7)
#define inf (int)(3e18)
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define P pair<int,int>
#define PiP pair<int,pair<int,int>>
#define PP pair<P,P>
#define all(v) v.begin(),v.end()
#define mkp make_pair
#define mkt make_tuple
#define prique(T) priority_queue<T,vector<T>,greater<T>>
#define vecunique(vec) sort(vec.begin(), vec.end());decltype(vec)::iterator result = std::unique(vec.begin(), vec.end());vec.erase(result, vec.end())
using namespace std;
template<class T> inline void chmax(T& a, T b) { a = max(a, b); }
template<class T> inline void chmin(T& a, T b) { a = min(a, b); }

bool prime(int x) {
	for (int i = 2; i * i <= x; i++) {
		if (x % i == 0)return false;
	}
	return x > 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x / gcd(x, y) * y;
}
int kai(int x, int y) {
	int res = 1;
	for (int i = x - y + 1; i <= x; i++) {
		res *= i; res %= mod;
	}
	return res;
}
int mod_pow(int x, int y, int m) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % m;
		}
		x = x * x % m;
		y >>= 1;
	}
	return res;
}
int comb(int x, int y) {
	if (y > x)return 0;
	return kai(x, y) * mod_pow(kai(y, y), mod - 2, mod) % mod;
}
int get_rand(int MIN, int MAX) {
	random_device rnd;
	mt19937_64 mt64(rnd());
	uniform_int_distribution<int>engine(MIN, MAX);
	return engine(mt64);
}
/*--------Library Zone!--------*/


signed main() {
	int m, d; cin >> m >> d;
	int cnt = 0;
	for (int i = 1; i <= m; i++) {
		for (int j = 1; j <= d; j++) {
			if (j % 10 <= 1)continue;
			if (j / 10 <= 1)continue;
			if ((j / 10) * (j % 10) == i) {
				cnt++;
			}
		}
	}
	cout << cnt << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int a[55];
int main()
{
    int n;scanf("%d",&n);
    for(int i=1;i<=n;i++)
        scanf("%d",&a[i]);
    int ans=0;
    for(int i=2;i<n;i++)
    {
        if(a[i-1]<a[i]&&a[i]<a[i+1])
            ans++;
        if(a[i-1]>a[i]&&a[i]>a[i+1])
            ans++;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define boost ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define int long long
#define M 1000000007
#define eb emplace_back
#define watch(x) cout << (#x) <<" is "<< x <<"\n";


using namespace std;
//const int N = 1e6;

int32_t main(){
  boost;
  int tc = 1; //cin >> tc;
  while(tc--)
  {
    int n; cin >> n;
    int arr[n], sum = 0;
    map<int, int>mp;
    for(int i=0; i<n; i++)
    {
      cin >> arr[i]; 
      sum += arr[i];
      mp[arr[i]]++;   
    }
    int q; cin >> q;
    while(q--)
    {
      int b, c; cin >> b >> c;
      sum -= (mp[b] * b);
      sum += (mp[b] * c);
      mp[c] += mp[b];
      mp[b] = 0;
      cout << sum <<"\n";
    }
  }
}



Measured memory_bytes: 10232
#include <iostream>

using std::cin;
using std::cout;
using std::endl;

int main() {
  int w, h, n, s;
  // 長方形を作るx座標の左端、右端を表す（xp[0]: 右, xp[1]: 左）
  int xp[2];
  // 長方形を作るy座標の上端、下端を表す（yp[0]: 上, yp[1]: 下）
  int yp[2];
  cin >> w >> h >> n;

  // 初期位置をセット
  xp[0] = w;
  xp[1] = 0;
  yp[0] = h;
  yp[1] = 0;

  for (int i = 0; i < n; i++) {
    int x, y, a;
    cin >> x >> y >> a;

    if (a == 1 && xp[1] < x) {
      xp[1] = x;
    } else if (a == 2 && xp[0] > x) {
      xp[0] = x;
    } else if (a == 3 && yp[1] < y) {
      yp[1] = y;
    } else if(a == 4 && yp[0] > y){
      yp[0] = y;
    }
  }

  if ((xp[0] - xp[1]) <= 0 || (yp[0] - yp[1] <= 0)) {
    cout << 0 << endl;
  } else {
    s = (xp[0] - xp[1]) * (yp[0] - yp[1]);
    cout << s << endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
///////////////////////////////////////////
const long long int INF = 1LL<<60;
const long long int Mod = 1000000007;
using ll = long long int; using ci = const int;
using vi = vector<int>;  using Vi = vector<long long int>;
using P = pair<int, int>;  using PLL = pair<ll, ll>;
using matrix = vector<vector<ll>>;
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define rp(i,N) for(ll i = 0; i < (ll)N; i++)
#define repi(i,a,b) for(ll i = ll(a); i < ll(b); ++i)
template<class T>bool chmax(T &former, const T &b) { if (former<b) { former=b; return true; } return false; }
template<class T>bool chmin(T &former, const T &b) { if (b<former) { former=b; return true; } return false; }
template<class T>T sqar(T x){ return x*x; }//sqrt(x)は平方根;
#define Sort(v) std::sort(v.begin(), v.end(), std::greater<decltype(v[0])>()) //降順でVをソート
#define p_queue(v) priority_queue<v, vector<v>, greater<v> >
template<class T> inline void princ(T x){cout<<x<<" ";}; 
template<class T> inline void print(T x){cout<<x<<"\n";};
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
///////////////////////////////////////////////////////////////////////////////////

void solve(){
    int x,n;
    cin >> x >> n;
    vi p(n);
    set<int> se;
    rp(i,n) {
        cin >> p.at(i);
        se.insert(p[i]);
    }
    int gap=10000;
    int ans;
    for(ll i=105;i>=-1;i--){
        if(se.count(i)) continue;
        if(gap>=abs(i-x)) {
            ans=i;
            gap=abs(i-x);
        }
    }
    print(ans);
    return;
}
int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    std::cout<<std::fixed<<std::setprecision(30);
    solve();
    return 0;
}

Measured memory_bytes: 3648
#計算量 max(N ** 2, C ** 3)
N, C = map(int, input().split())
D = [0] * C
for i in range(C):
  D[i] = list(map(int, input().split()))
grid = [0] * N
for i in range(N):
  grid[i] = list(map(int, input().split()))
  
#print(D, grid) 
grid3 = [[0] * C for i in range(3)]
#grid[i][j]:3で割って余りが i のマスで、色がjであるマスの個数
for i in range(N):
  for j in range(N):
    nn = (i + j) % 3
    color = grid[i][j] - 1
    grid3[nn][color] += 1
#print(grid3)  

score = [[0] * C for i in range(3)]
#score[i][j]:3で割って余りが i のマスを、色jにするときの違和感
#3 * C * C
for j in range(C):
  for i in range(3):
    for k in range(C): 
      score[i][j] += grid3[i][k] * D[k][j]
#print(score)            
ans = 10 ** 10  
for i in range(C):
  for j in range(C):
    if i != j:
      for k in range(C):
        if (i != k) and (j != k):
          now = score[0][i] + score[1][j] + score[2][k]
          ans = min(ans, now)
print(ans)      





Measured memory_bytes: 11652
#include<algorithm>
#include<stdio.h>
#include<stdlib.h>
#include<queue>
#include<stack>

using namespace std;

int main(void) {
	int A = 0, B = 0, X = 0;
	scanf("%d%d%d", &A, &B, &X);
	if (A + B >= X && A <= X)
		printf("YES\n");
	else
		printf("NO\n");
	return 0;
}

Measured memory_bytes: 128
package main

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

const mod = 1000000007

// 1MB
const ioBufferSize = 1 * 1024 * 1024
var sc = func() *bufio.Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Buffer(make([]byte, ioBufferSize), ioBufferSize)
	sc.Split(bufio.ScanWords)
	return sc
}()

func next() string {
	sc.Scan()
	return sc.Text()
}

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

func main() {
	a, b := nextInt(), nextInt()
	num, _ := strconv.Atoi(fmt.Sprintf("%d%d", a, b))

	for i := 1; i <= 1000; i++ {
		if i*i == num {
			fmt.Println("Yes")
			return
		}
	}

	fmt.Println("No")
}

Measured memory_bytes: 640
n, m = list(map(int, input().split()))
a = []
b = []
data = []
for i in range(n):
    data.append(list(map(int, input().split())))
data.sort()
sum = 0
money = 0
index = 0
while sum + data[index][1]< m:
    sum += data[index][1]
    money += data[index][0] * data[index][1]
    del data[index]
money += (m - sum) * data[index][0]
print(money)

Measured memory_bytes: 27756
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
  int N; cin  >> N;
  ll ans=0;
  vector<pair<ll,ll>> A(N);
  for(int i=0;i<N;i++){
    ll a; cin >> a;
    A[i].first=i+1+a;
    A[i].second=i+1-a;
  }
  vector<int> B(N+1,0);
  for(int i=N-1;i>=0;i--){
    if(A[i].first<=N){
      ans+=B[A[i].first];
    }
    if(A[i].second>=0){
      B[A[i].second]++;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 7224
import sys
from itertools import combinations, permutations, product, combinations_with_replacement, accumulate
from heapq import heapify, heappop, heappush, heappushpop
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict, deque
from math import sqrt, log, floor, ceil, factorial, cos, sin, pi #, gcd
from fractions import gcd
from operator import mul
from functools import reduce
sys.setrecursionlimit(10**8)
input = sys.stdin.readline
INF = float('inf')
LINF = 2**63-1
NIL = -LINF
MOD = 10**9+7
MGN = 4
def AST(exp: bool, msg: str = ""): assert exp, msg
def TAST(exp: bool, msg = ""):
    if exp is False: print("TAssertionError:", msg)
    while exp is False:
        pass
def EPR(msg = ""): print(msg, file=sys.stderr)
def II(): return int(input())
def IF(): return float(input())
def IS(): return input().replace('\n', '')
def ILCI(n: int): return [II() for _ in range(n)]
def ILCF(n: int): return [IF() for _ in range(n)]
def ILI(): return list(map(int, input().split()))
def ILLI(n: int): return [[int(j) for j in input().split()] for i in range(n)]
def ILF(): return list(map(float, input().split()))
def ILLF(n: int): return [[float(j) for j in input().split()] for i in range(n)]
def LTOS(lst: list, sep: str = ' '): return sep.join(map(str, lst))
def DEC(lst: list): return list(map(lambda x: x-1, lst))
def INC(lst: list): return list(map(lambda x: x+1, lst))


def main():
    N, K = ILI()

    ans = 0.0
    for i in range(1,N+1):
        scr = i  # 現在のスコア
        pb = 1.0  # 現在のスコアとなる確率
        win = True  # 勝ち続けているか
        while True:
            if K <= scr:  # 勝ち
                EPR(scr)
                break
            elif 0 < scr < K:
                scr *= 2
                pb *= 0.5
            else:  # 負け
                scr = 0
                win = False
                break
        if win:
            ans += pb / N

    print("{:.12}".format(ans))


if __name__ == '__main__':
    main()


Measured memory_bytes: 5548
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<vector>
#include<queue>
#include<map>
#include<tuple>
#define rep(index,num) for(int index=0;index<num;index++)
#define rep1(index,num) for(int index=1;index<=num;index++)
#define scan(argument) cin>>argument
#define prin(argument) cout<<argument<<endl
#define kaigyo cout<<endl
#define eps 1e-15
#define mp(a1,a2) make_pair(a1,a2)
#define YMAX 250001
typedef long long ll;
using namespace std;
typedef pair<ll,ll> pll;
typedef pair<int,int> pint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<pint> vpint;
typedef vector<pll> vpll;
ll INFl=1e+18+1;
int INF=1e+9+1;
int main(){
	string S;
	scan(S);
	if(S[0]=='Y'&&S[1]=='A'&&S[2]=='K'&&S[3]=='I'){
		prin("Yes");
	}
	else{
		prin("No");
	}
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const long long INF = 1LL << 60;

int main(){
    int H, W, K;
    cin >> H >> W >> K;
    string board[H], t;

    for(int i=0; i<H; i++) {
        for(int j=0; j<W; j++) {
            cin >> board[i][j];
        }
    }
    int ans = 0;

    for(int is=0; is<1<<H; is++) {
        for(int js=0; js<1<<W; js++) {
            int count=0;
            for(int i=0; i<H; i++) {
                for(int j=0; j<W; j++) {
                    if(is>>i&1) continue;
                    if(js>>j&1) continue;
                    if(board[i][j] == '#') count++;
                }
            }
            if(count == K) ans++;
        }
    }
    cout << ans << endl;
}

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

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

typedef long long ll;
const int MOD = 1000000007;
ll a_n(ll a, ll n);

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i, n) cin >> a.at(i);
    
    map<int, int> lcm;
    rep(i, n) {
        map<int, int> prime = {}; // a[i]の素因数
        int temp = a.at(i);
        while ((temp%2) == 0) {
            temp /= 2;
            if(prime.count(2)) prime.at(2)++;
            else prime[2] = 1;
        }
        for(int j = 3; j*j <= temp; j+=2) {
            while((temp%j) == 0) {
                temp /= j;
                if(prime.count(j)) prime.at(j)++;
                else prime[j] = 1;
            }
        }
        if(temp != 1) prime[temp]  = 1;
        // primeの全キーをlcmと比較
        for(pair<int, int> p: prime) {
            int key = p.first;
            int value = p.second;
            if(lcm.count(key) && (lcm.at(key) < value)) lcm.at(key) = value;
            if(!(lcm.count(key))) lcm[key] = value;
        }
    }

    ll ans = 0;
    rep(i, n) ans = (ans + a_n(a.at(i), MOD-2));
    for(pair<int, int> p: lcm) {
        int key = p.first;
        int value = p.second;
        rep(i, value) ans = (ans * key)%MOD;
    }

    cout << ans << endl;

    return 0;
}

ll a_n(ll a, ll n) { 
    ll ret = a, count = 1;
    int num = 1;
    vector<ll> memory(100);
    memory.at(0) = a;

    while(count * 2 < n) {
        ret = (ret * ret)%MOD;
        count *= 2;
        memory.at(num) = ret;
        num++;
    }
    if(count == n) return ret;
    else {
        bitset<100> bit = bitset<100>(n-count);
        rep(i, 100) {
            if(bit.test(i)) ret = (ret * memory.at(i))%MOD;
        }
        return ret;
    }    
}


Measured memory_bytes: 768
N = int(input())
jobs = []
for i in range(N):
    jobs.append(list(map(int, input().split())))
sortedjobs = list(sorted(jobs, key = lambda x: x[1]))
tott = 0
flag = False
for A, B in sortedjobs:
    tott += A
    if tott > B:
        flag = True
if flag:
    print("No")
else:
    print("Yes")

Measured memory_bytes: 55196
#include<bits/stdc++.h>
using namespace std;
const int N=1e5;

char s[10];
int a[N];
int flag[N];
int main()
{
    int n,m;
    scanf("%d%d",&n,&m);
    int ans1=0,ans2=0;
    for(int i=0;i<m;++i){
        int x;
        scanf("%d%s",&x,s);
        if(s[0]=='W'){
            if(flag[x]==0)
                ++a[x];
        }
        else{
            if(flag[x]==0){
                flag[x]=1;
                ++ans1;
                ans2+=a[x];
            }
        }
    }
    printf("%d %d",ans1,ans2);
	return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
string to_string(const string& s) {
	return '"' + s + '"';
}
string to_string(const bool b) {
	return (b ? "true" : "false");
}
string to_string(const char* s) {
	return to_string((string)s);
}
string to_string(const char c) {
	string s = "'";
	s += c;
	s += "'";
	return s;
}
template<class T, class U>
string to_string(const pair<T, U>& p) {
	string s = "(";
	s += to_string(p.first);
	s += ", ";
	s += to_string(p.second);
	s += ")";
	return s;
}
template<class T>
string to_string(const T& a) {
	bool first = true;
	string s = "{";
	for (const auto& x : a) {
		if(!first){
			s += ", ";
		}
		first = false;
		s += to_string(x);
	}
	s += "}";
	return s;
}
void debug_out() {cerr << '\n';}
template<class Head, class... Tail>
void debug_out(Head head, Tail... tail) {
	cerr << ' ' << to_string(head);
	debug_out(tail...);
}
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "] = ", debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif
using ll = long long;
using ld = long double;
const int mod = 1e9 + 7;
const int inf = 1e9 + 100;
const ll inf64 = 7e18l;
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout << fixed << setprecision(20);
	int n, m;
	cin >> n >> m;
	vector<vector<char>> a(n, vector<char>(m));
	vector<int> row(n), col(m);
	for (int i = 0; i < n; ++i) {
		for (int j = 0; j < m; ++j) {
			cin >> a[i][j];
			if (a[i][j] == '#') {
				row[i] = col[j] = 1;
			}
		}
	}
	for (int i = 0; i < n; ++i) {
		if (row[i]) {
			for (int j = 0; j < m; ++j) {
				if (col[j]) {
					cout << a[i][j];
				}
			}
			cout << '\n';
		}
	}
	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
	int a,b,c,d,e,f,ans;
	scanf("%d %d %d %d %d %d",&a,&b,&c,&d,&e,&f);
	ans=(a+(b*5)+(c*10)+(d*50)+(e*100)+(f*500))/1000;
	if(ans>=1){
		printf("1\n");
	}
	else if(1>ans){
		printf("0\n");
	}
	return 0;
}


Measured memory_bytes: 2112
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

import numpy as np

MOD = 10 ** 9 + 7

N = int(readline())
A = np.array(read().split(),np.int64)

A.sort()
x = (A * np.arange(N+1,1,-1) % MOD).sum() % MOD
x *= pow(2, N+N-2, MOD); x %= MOD
print(x)

Measured memory_bytes: 25240
#include <iostream>
#include <vector>

using namespace std;

int main(){
    vector<vector<int>> c;
    c.resize(3);
    for(int i = 0; i < 3; i++){
        c[i].resize(3);
    }

    for(int i = 0; i < 3; i++){
        for(int j = 0; j < 3; j++){
            cin >> c[i][j];
        }
    }

    bool isOK = true;
    vector<int> temp = {0, 0, 0};

    for(int i = 1; i < 3; i++){
        for(int j = 0; j < 3; j++){
            temp[j] = c[i][j] - c[0][j];
        }
        if(!((temp[0] == temp[1]) and (temp[0] == temp[2]))) isOK = false;
    }

    for(int j = 1; j < 3; j++){
        for(int i = 0; i < 3; i++){
            temp[i] = c[i][j] - c[i][0];
        }
        if(!((temp[0] == temp[1]) and (temp[0] == temp[2]))) isOK = false;
    }

    if(isOK) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}



        

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

int main() {
  string s;
  cin>>s;
  int ans=0;
  for(int i=1; i<s.size(); i++){
    if(s[i]==s[i-1]&&s[i]=='0') {
      s[i]='1';
      ans++;
    }
    if(s[i]==s[i-1]&&s[i]=='1') {
      s[i]='0';
      ans++;
    }
  }
  cout<<ans;
}

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

typedef long long LL;
typedef pair<int, int> PII;
typedef vector<int> VI;
#define MP make_pair
#define PB push_back
#define X first
#define Y second

#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define RFOR(i, b, a) for(int i = (b) - 1; i >= (a); --i)
#define ALL(a) a.begin(), a.end()
#define SZ(a) (int)((a).size())
#define FILL(a, value) memset(a, value, sizeof(a))
#define debug(a) cout << #a << " = " << a << endl;

const double PI = acos(-1.0);
const LL INF = 1e9 + 47;
const LL LINF = INF * INF;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int main()
{
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	
	int n, k;
	cin >> n >> k;
	VI a(n);
	int N= n;
	FOR(i, 0, N) cin>> a[i];
	int ans = 0;
	FOR(i, 0, N) ans += a[i] >= k;
	cout << ans;
	return 0;
}



Measured memory_bytes: 640
#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>
#include <set>
#include <queue>
#include <stack>
#include <utility>
#include <tuple>
#include <map>
#include <ctime>
#include <cstdlib>
#include <random>
using namespace std;

const double pi = acos(-1);
#define nyan cout << "(=^•ω•^=)" << endl;
#define int long long
#define rep(i, n) for(int i = 0; i < n; i++)
#define loop while(true)

int n;
int k;
int h[300000];
int ans;

signed main(){
	cin >> n >> k;
	if(k >= n){
		cout << 0 << endl;
		return 0;
	}
	for(int i = 0; i < n; i++)cin >> h[i];
	sort(h, h + n);
	for(int i = 0; i < n - k; i++)ans += h[i];
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1792
////////////////////////
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
namespace my {
char itoc(int i) { return i + '0'; }
int ctoi(char c) { return c - '0'; }
ll gcd(ll a, ll b) {
  a = abs(a);
  b = abs(b);
  if (a < b) swap(a, b);
  while (b != 0) {
    a %= b;
    swap(a, b);
  }
  return a;
}
ll lcm(ll a, ll b) { return a * b / my::gcd(a, b); }
}  // namespace my
////////////////////////

int main() {
  int n;
  cin >> n;
  vector<ll> a;
  for (int i = 0; i <= n; i++) {
    int tmp;
    cin >> tmp;
    a.push_back(tmp);
  }

  vector<ll> node(n + 1);
  ll tmp = 0;
  for (int i = n; i >= 0; i--) {
    tmp += a.at(i);
    node.at(i) = tmp;
  }

  //
  ll ans = 0;
  for (int i = 0; i <= n; i++) {
    if (i == 0) {
      node.at(0) = min(node.at(0) - a.at(0), 1 - a.at(0));
      if (node.at(0) < 0) {
        ans = -1;
        break;
      }
      ans += node.at(0) + a.at(i);
      continue;
    }

    node.at(i) = min(node.at(i) - a.at(i), node.at(i - 1) * 2 - a.at(i));
    if (node.at(i) < 0) {
      ans = -1;
      break;
    }
    ans += node.at(i) + a.at(i);
  }

  cout << ans << endl;
}

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

int main() {
    int n, a;
    cin >> n;
    deque<int> dq;
    for(int i = 0; i < n; ++i) {
        cin >> a;
        if(i&1) dq.push_front(a);
        else dq.push_back(a);
    }

    if(n&1) reverse(dq.begin(), dq.end());
    for_each(dq.begin(), dq.end(), [](int x) {
        cout << x << ' ';
    });
    cout << '\n';

    return 0;
}


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

using namespace std;

typedef pair<int, int> P;

map<int, int> dat;
int N;
int a, d;
int M;
int K;

int at(int i){
  if(dat.count(i)){
    return dat[i];
  }
  return dat[i] = a + d * i;
}

void write(int i, int j){
  at(i);
  at(j);
  dat[i] = dat[j];
}

void swap(int i, int j){
  at(i);
  at(j);
  int tmp = dat[i];
  dat[i] = dat[j];
  dat[j] = tmp;
}

int main(){
  cin >> N;
  cin >> a >> d;
  cin >> M;
  for(int i = 0; i < M; ++i){
    int x, y, z;
    cin >> x >> y >> z;
      --y;
      --z;
    if(x == 0){
      swap(y, z);
    }else{
      write(y, z);
    }
  }
  cin >> K;
  --K;
  cout << at(K) << endl;
}

Measured memory_bytes: 1200
#include<iostream>
#include<vector>
#include<algorithm>
#include<stdlib.h>
#include<time.h>
#include<math.h>
#include<stdio.h>
#include<string>
#include<set>
#include<iomanip>
#include<numeric>
#include<map>
#include<limits>

using namespace std;

int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int t, num, k,n,x,y;
cin >> n>>k;
num = 0;
vector<int> a(n);
for (int i = 0; i < n; i++)
{
	cin >> x >> y;
	if (pow(x, 2) + pow(y, 2) <= pow(k, 2)) {
		num++;
	}
}
cout << num;
return 0;
}


Measured memory_bytes: 3980
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

int main(void){
    
    int n, T, min = 1001;
    int c[100];
    int t[100];

    cin >> n >> T;

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

    for(int i = 0; i < n; i++){
        if(T >= t[i]){
            if(min > c[i]){
                min = c[i];
            }
        }
    }

    if(min == 1001){
        cout << "TLE" << endl;
    }
    else{
        cout << min << endl;
    }
    
    return 0;
}

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

int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    int a,b,m;
    cin>>a>>b>>m;
    int ref[a],mic[b];
    for (int i=0;i<a;++i){
        cin>>ref[i];
    }
    for (int i=0;i<b;++i){
        cin>>mic[i];
    }
    int mini = INT_MAX;
    for(int i=0;i<m;++i){
        int x,y,c;
        cin>>x>>y>>c;
        mini = min(mini,ref[x-1]+mic[y-1]-c);
    }
    sort(ref,ref+a);
    sort(mic,mic+b);
    cout<<min(mini,ref[0]+mic[0]);
    
}

Measured memory_bytes: 1024
#include <cstdio>
long long n, a, x, d[55][5005];
int C=2500;
int main() {
	int i, j;
	scanf("%lld%lld", &n, &a);
	d[0][C] = 1;
	for(i=1; i<=n; i++) {
		scanf("%lld", &x);
		x -= a;
		for(j=0; j<=2*C; j++) {
			d[i][j] += d[i-1][j];
			d[i][j+x] += d[i-1][j];
		}
	}
	printf("%lld", d[n][C]-1);
}

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

#ifdef LOCAL
#define debug(var) cerr << (#var) << " = " << (var) << endl;
#else
#define debug(var)
#endif

void init() {
  ios_base::sync_with_stdio(0);
  cin.tie(0); cout.tie(0);
}

const int N = 123;

int a[N];

void solve() {
  int k, t; scanf("%d%d", &k, &t);
  for (int i = 0; i < t; ++i) scanf("%d", a+i);
  if (t == 1) {
    printf("%d", a[0]-1);
    return;
  } 
  sort(a, a+t);
  int spare = 1;
  int prev = 0;
  for (int i = 0; i < t-1; ++i) {
    if (i && a[i] == a[i-1]) continue;
    spare += (a[i]-prev)*(t-i-2);
    a[t-1] -= (a[i]-prev);
    prev = a[i];
  }
  printf("%d", max(a[t-1]-spare, 0));
}

int main() {
  init();
  int t = 1; //scanf("%d", &t);
  while (t--) {
    solve();
  }
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
    int a,b,c,d;
    cin >> a >> b >> c ;
    if ( a > b ){
        d = a;
        a = b;
        b = d;
    }
    if ( b > c ){
        d = b;
        b = c;
        c = d;
    }
    if ( a > b ){
        d = a;
        a = b;
        b = d;
    }
    cout << a << " " << b << " " << c << endl;
}

Measured memory_bytes: 1168
#include<bits/stdc++.h>
    #define nikal ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
    using namespace std;
    int main()
    {
        nikal;
        int n,m;
        long long c=0,k=0;
        cin>>n>>m;
        int i,a[n];
        float p;
        for(i=0;i<n;i++)
        {
            cin>>a[i];
            c+=a[i];
        }
        p=(float)c/(4*m);
        for(i=0;i<n;i++)
        {
            if(a[i]>=p)
                k++;
        }
        if(k>=m)
            cout<<"Yes";
        else
            cout<<"No";
    }


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <vector>
#include <set>
#include <numeric>

using namespace std;

int main(){
   int n;
   cin>>n;
   int a[110];
   for(int i=0;i<n;i++)cin>>a[i];
   int ans=0;
   for(int i=1;i<n;i++){
      if(a[i]==a[i-1]){
         ans++;
         a[i]=10000-a[i];
      }
   }
   cout<<ans<<endl;
}

Measured memory_bytes: 256
from itertools import permutations as pm

def main():
    n = int(input())
    s = input()

    red = [0 for i in range(n+1)]
    green = [0 for i in range(n+1)]
    blue = [0 for i in range(n+1)]

    for i in range(2,n+1):
        if s[i-2]=='R':
            red[i] = red[i-1] + 1
        else:
            red[i] = red[i-1]
        if s[i-2]=='G':
            green[i] = green[i-1] + 1
        else:
            green[i] = green[i-1]
        if s[i-2]=='B':
            blue[i] = blue[i-1] + 1
        else:
            blue[i] = blue[i-1]
    # red[n] = red[n-1]
    # green[n] = green[n-1]
    # blue[n] = blue[n-1]

    # print(red)
    # print(blue)
    # print(green)


    ans = 0
    for i in range(1,n+1):
        for j in range(i+2,n+1):

            if s[i-1]+s[j-1] == "RB" or s[i-1]+s[j-1] =="BR":
                ans += green[j] - green[i+1]
                if (j-i)%2==0 and s[(j-i)//2+i-1] == "G":
                    ans -= 1
            elif s[i-1]+s[j-1] == "RG" or s[i-1]+s[j-1] =="GR":
                ans += blue[j] - blue[i+1]
                if (j-i)%2==0 and s[(j-i)//2+i-1] == "B":
                    ans -= 1
            elif s[i-1]+s[j-1] == "BG" or s[i-1]+s[j-1] =="GB":
                ans += red[j] - red[i+1]
                if (j-i)%2==0 and s[(j-i)//2+i-1] == "R":
                    ans -= 1

    print(ans)

if __name__== "__main__":
    main()

Measured memory_bytes: 69260
#include <bits/stdc++.h>
using namespace std;
#define rep0(i, n) for (long long i = 0; i < (long long)(n); i++)
#define rep1(i,n) for(long long i=1;i<=(long long)(n);i++)
#define all(v) v.begin(),v.end()
#define Sort(v) sort(all(v))
#define Reverse(v) reverse(all(v))
#define Rsort(v) sort(all(v),greater)
#define pub(v) push_back(v)
#define pob(v) pop_back(v)
typedef long long ll;
typedef vector<ll> vel;
typedef vector<vector<ll>> vel2d;
typedef string str;
typedef pair<ll,ll> pal;
typedef vector<str> ves;
typedef vector<char> vech;



int main() {
    ll N,M;cin>>N>>M;
    vel2d G(N);
    vel ans(N,-1);
    vel dist(N,-1);dist[0]=0;
    queue<ll> que; que.push(0);
    rep0(i,M){
        ll a,b;cin>>a>>b;
        G[a-1].pub(b-1); G[b-1].pub(a-1);
    }

    //BFS

    while(!que.empty()){
        ll v=que.front();
        que.pop();

        for(ll i:G[v]){
            if(dist[i]!=-1)continue;

            que.push(i);
            dist[i]=dist[v]+1;
            ans[i]=v;
            //cout<<ans[i]<<endl;
            //cout<<que.front()<<endl;
        }
    }
    rep0(i,N){if(i!=0&&ans[i]==-1){cout<<"No"<<endl;return 0;}}
    rep0(i,N){
        if(i==0){cout<<"Yes"<<endl;continue;}
        cout<<ans[i]+1<<endl;
    }
}


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

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

    int n, a;
    cin >> n >> a;
    int position = 0;
    int result = 0;
    for(int i = 0; i < n; i++){
        int val;
        cin >> val;
        //cout << position << "... " << a << endl;
        if(position <= a){
            result++;
        }
        position += val;
    }
    //cout << position << "... " << a << endl;
    if(position <= a){
            result++;
    }
    cout << result;
    return 0;
}



Measured memory_bytes: 256