akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
template <class T>
inline bool chmax(T &a, T b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
inline bool chmin(T &a, T b)
{
    if (a > b)
    {
        a = b;
        return 1;
    }
    return 0;
}
typedef long long int ll;

#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
const double EPS = 1e-7;
const int INF = INT_MAX;
const ll LLINF = INT64_MAX;
const double PI = acos(-1);
const int MOD = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

//-------------------------------------

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<int> a(n);
    map<int, int> mp;
    for (int i = 0; i < n; i++)
    {
        cin >> a[i];
        mp[a[i]]++;
    }
    int cnt = 0;
    for (auto p : mp)
    {
        if (p.second >= 2)
        {
            if (p.second % 2)
            {
                cnt += (p.second - 1);
                mp[p.first] = 1;
            }
            else
            {
                cnt += (p.second - 2);
                mp[p.first] = 2;
            }
        }
    }
    int tmp = 0;
    for(auto p:mp){
        if(p.second >= 2){
            tmp++;
        }
    }
    cnt += ((tmp + 1) / 2) * 2;
    cout << n - cnt << endl;
}

Measured memory_bytes: 5376
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define MAXN 200010
#define MOD 1000000007

int n, a[MAXN], b[MAXN];
ll dp[4010][4010], has[4010][4010], fat[8010], inv_fat[8010];

ll exp(ll a, int p){
	ll resp = 1LL;
	while(p>0){
		if(p%2){
			resp = (resp*a)%MOD;
		}
		a = (a*a)%MOD;
		p/=2;
	}
	return resp;
}

int main(){
	fat[0]=1;
	inv_fat[0]=1;
	for(ll i=1; i<=8010; i++){
		fat[i] = (i*fat[i-1])%MOD;
		inv_fat[i] = exp(fat[i], MOD-2);
	}
	while(scanf("%d", &n)!=EOF){
		memset(dp,  0, sizeof(dp) );
		memset(has, 0, sizeof(has));
		for(int i=0; i<n; i++){
			scanf("%d %d", &a[i], &b[i]);
			a[i] += 2000;
			b[i] += 2000;
			dp[4000-a[i]][4000-b[i]]++;
			has[a[i]][b[i]]++;
		}
		
		ll X=0;
		for(int x=0; x<=4000; x++){
			for(int y=0; y<=4000; y++){
				if(x>0){
					dp[x][y] = (dp[x][y] + dp[x-1][y])%MOD;
				}
				if(y>0){
					dp[x][y] = (dp[x][y] + dp[x][y-1])%MOD;
				}
				X = (X + has[x][y]*dp[x][y])%MOD;
			}
		}
		
		ll same=0;
		for(int i=0; i<n; i++){
			ll nn = (a[i]-(4000-a[i])), mm = (b[i]-(4000-b[i]));
			ll parc = fat[nn+mm];
			parc = (parc*inv_fat[nn])%MOD;
			parc = (parc*inv_fat[mm])%MOD;
			same = (same + parc)%MOD;
		}
		
		ll resp = (X - same + MOD)%MOD;
		resp = (resp*inv_fat[2])%MOD;
		printf("%lld\n", resp);
	}
	return 0;
}


Measured memory_bytes: 253184
#include<bits/stdc++.h>
using namespace std;
#define fori(x) for(int i=0;i<x;i++)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define ll long long int 
#define ld long double
#define ull unsigned long long int
#define pi acos(-1)
#define test() int T,t=1;cin>>T;
typedef vector<int> VI;
typedef pair<int,int> PII;

void solve()
{
   //freopen("input.txt","r",stdin);
	int x;cin>>x;
	if(x>=30) cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
}
int main()
{
	ios_base::sync_with_stdio(false);cin.tie(NULL);

solve();

	return 0;
}

Measured memory_bytes: 3648
import java.util.*;

class Main{
	public static void main(String args[]){
		Scanner s=new Scanner(System.in);
		while(true){
			int a=s.nextInt();
			if(a==0)System.exit(0);
			String [] b=new String[a];
			for(int i=0;i<a;i++){
				b[i]=s.next();
			}
			int [][] dp=new int[a][a];
			int ans=0;
			for(int i=0;i<a;i++){
				for(int j=0;j<a;j++){
					if(b[i].charAt(j)=='*')dp[i][j]=0;
					else{
						
						if(i==0||j==0)dp[i][j]=1;
						else{
							int now=1000;
							now=Math.min(now,Math.min(dp[i-1][j-1],Math.min(dp[i][j-1],dp[i-1][j])));
							dp[i][j]=now+1;
						}
						ans=Math.max(dp[i][j],ans);
					}
				}
			}
			System.out.println(ans);
		}
	}
}

Measured memory_bytes: 15000
#include<bits/stdc++.h>
using namespace std;
#include<map>
#define MEM(var,val) memset(var,(val),sizeof(var))
#define MAX(a,b) ((a) > (b) ? (a) : (b))
#define MIN(a,b) ((a) < (b) ? (a) : (b))
#define nitro   ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long
#define vll vector<ll>
#define pll pair<ll,ll>
#define mp make_pair
#define pb push_back
#define F first
#define S second
vll dp,h;
ll n,k;

ll rec(ll i)
{
    if(i>n)
        return 1000000000;
    if(i==n)
        return dp[i]=0;
        if(dp[i]<1000000000)
            return dp[i];
            else
            for(int j=1;j+i<=n&&j<=k;j++)
                dp[i]=MIN(abs(h[i+j]-h[i])+rec(i+j),dp[i]);
    return dp[i];
}
int main()
{

    cin>>n>>k;
    dp.resize(n+1,1000000000);
     h.resize(n+1);
    for(int i=1;i<n+1;i++)
        cin>>h[i];
    cout<<rec(1);

}


Measured memory_bytes: 8064
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#define N 500000

typedef struct Node{
  int key;
  struct Node *right,*left,*parent;
}Node;

Node *NIL,*root;

Node *find(Node *x,int k){
  while(x!=NIL && k!=x->key){
    if(k<x->key){
      x=x->left;
    }
    else{
      x=x->right;
    }
  }
    return x;
}

void insert(int k){
  struct Node *y=NIL;
  struct Node *x=root;
  struct Node *z;

  z=(Node *)malloc(sizeof(Node));
  z->key=k;
  z->left=NIL;
  z->right=NIL;

  while(x!=NIL){
    y=x;
    if(z->key < x->key){
      x=x->left;
    }
    else {
      x=x->right;
    }
  }

  z->parent=y;
  if(y==NIL){
    root = z;
  }
  else {
    if(z->key < y->key){
      y->left=z;
    }
    else {
      y->right=z;
    }
  }
}

void inorder(struct Node *u){

  if(u==NIL) return;
  inorder(u->left);
  printf(" %d",u->key);
  inorder(u->right);
}

void preorder(struct Node *u){

  if(u==NIL) return;
  printf(" %d",u->key);
  preorder(u->left);
  preorder(u->right);
}


main(){

  int i,n,x,s;
  char com[6];
  Node *t;

  scanf("%d",&n);

  for(i=0;i<n;i++){
    scanf("%s",com);
    if(com[0]=='i'){
      scanf("%d",&x);
      insert(x);
    }
    else if(com[0]=='f'){
      scanf("%d",&s);
      t=find(root,s);
      if(t!=NIL) printf("yes\n");
      else printf("no\n");
    }
    else if(com[0]='p'){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    }
  }
  return 0;
}

Measured memory_bytes: 19364
////////////////////////////////////////////////////////////////////
// This source code is for Visual Studio
////////////////////////////////////////////////////////////////////
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <map>
#include <set>
#include <algorithm>
#include <sstream>
#include <iterator>
#include <stack>
#include <functional>
#include <iomanip>
#include <string>
#include <cstring>
#include <deque>
#include <math.h>
#include <assert.h>

#define	numberof(a)	(sizeof(a) / sizeof(a[0]))
#define	INF32		INT32_MAX
#define	INF64		INT64_MAX
#define Rep(i,n) for(int i = 0; i < (n); ++i )

using namespace std;

typedef vector< vector<int> > MAT;
typedef pair<int, int> PINT;
typedef long long ll;
typedef uint32_t u32;
typedef uint64_t u64;
typedef int32_t s32;
typedef int64_t s64;

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI = acos(-1.0);

bool pair_comp(const pair<ll, ll> & p1, const pair<ll, ll> & p2)
{
	// sort(item.begin(), item.end(), throw_comp)のように使う
	if (p1.first != p2.first) {
		return p1.first < p2.first;
	}
	else {
		return p1.second > p2.second;
	}
}

// main function
int main()
{
	ll N = 0;
	ll ans = 0;

	cin >> N;
	vector<ll> h(N);
	Rep(i, N) {
		cin >> h[i];
	}

	Rep(i, N) {
		ll left, right = 0;
		ll tmp_min = INF32;
		bool start = false;
		for (int j = 0; j < N; ++j) {
			if (h[j] == 0) {
				if (start) {
					break;
				}
				else {
					// before start
				}
			}
			else {
				if (!start)left = j;
				start = true;
				tmp_min = min(tmp_min, h[j]);
			}
			right++;
		}

		// diff left - (right - 1)
		if (start) {
			for (int j = left; j < right; ++j) {
				h[j] -= tmp_min;
			}
			ans += tmp_min;
		}
	}

	cout << ans << endl;

	return 0;
}


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

int main()
{
	double test[4][2] = {0}, eye[2] = {0};

	while (cin >> eye[0] >> eye[1]){
		for (int i = 0; i < 2; i++){
			if (eye[i] >= 1.1){
				test[0][i]++;
			}
			else if (eye[i] >= 0.6){
				test[1][i]++;
			}
			else if(eye[i] >= 0.2){
				test[2][i]++;
			}
			else {
				test[3][i]++;
			}
		}
	}
		for (int i= 0; i < 4; i++){
		cout << test[i][0]	<< " " << test[i][1] << endl;
		}
	
	return(0);
}

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

#define INF_LL (int64)1e18
#define INF (int32)1e9
#define REP(i, n) for(int64 i = 0;i < (n);i++)
#define FOR(i, a, b) for(int64 i = (a);i < (b);i++)
#define all(x) x.begin(),x.end()
#define fs first
#define sc second

using int32 = int_fast32_t;
using uint32 = uint_fast32_t;
using int64 = int_fast64_t;
using uint64 = uint_fast64_t;
using PII = pair<int32, int32>;
using PLL = pair<int64, int64>;

const double eps = 1e-10;

template<typename A, typename B>inline void chmin(A &a, B b){if(a > b) a = b;}
template<typename A, typename B>inline void chmax(A &a, B b){if(a < b) a = b;}

int main(void){
	cin.tie(0);
	ios::sync_with_stdio(false);
	double a, b;
	cin >> a >> b;
	for(double t = 0;t <= 180; t+= 0.5){
		double aa = a+t, bb = b-t;
		if(aa >= 360) aa-=360;
		if(bb < 0) bb += 360;
		if(aa == bb){
			cout << aa << endl;
			return 0;
		}
		aa = a-t; bb = b+t;
		if(aa < 0) aa+=360;
		if(bb >= 360) bb-=360;
		if(aa == bb){
			cout << aa << endl;
			return 0;
		}
	}
}


Measured memory_bytes: 3300
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <numeric>
#include <string>
#include <iostream>
#include <fstream>
#include <algorithm>
#include <assert.h>
#include <ctype.h>
#include <limits.h>
#include <math.h>
#include <cmath>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <time.h>
#include <bitset>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <sstream>

using namespace std;
const double PI = acos(-1.0);
const double EPS = 1e-11;
typedef long long ll;
const ll MOD = 1000000007;
const int N = 100000 + 7;
typedef unsigned long long ull;

//freopen("input.txt","r",stdin);
//freopen("output.txt","w",stdout);
void fast() {
    std::ios_base::sync_with_stdio(0);
    cin.tie(0);
}

/*                What if i lose? only losers think like that. But the answer is you will lose rate.                */

int n, m, k;
vector<vector<char>> grid;

int main() {
#ifndef ONLINE_JUDGE
    freopen("Input.txt", "r", stdin);
    freopen("Output.txt", "w", stdout);
#endif
    fast();

    cin >> n >> m >> k;
    grid.resize(n, vector<char>(m));
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            cin >> grid[i][j];
        }
    }

    int ans = 0;
    for (int maskRow = 0; maskRow < (1 << n); maskRow++) {
        for (int maskCol = 0; maskCol < (1 << m); maskCol++) {
            int blackSq = 0;
            for (int i = 0; i < n; i++) {
                for (int j = 0; j < m; j++) {
                    if (((maskRow >> i) & 1) == 0 && ((maskCol >> j) & 1) == 0 && grid[i][j] == '#')
                        blackSq++;
                }
            }
            if (blackSq == k)
                ans++;
        }
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3656
#include<iostream>
#include<string>
#include<algorithm>
#include<utility>
#include<vector>
#include<map>
#include<functional>

using namespace std;

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

	int a,b,c,d;
	cin >> a >> b >> c >> d;

	if(abs(a-c) <= d || (abs(a-b) <= d && abs(b-c) <= d)) cout << "Yes\n";
	else cout << "No\n";

	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main()
{
    int n;
    scanf("%d", &n);
    int i;
    int d[102];
    for (i = 0; i < n; i++)
        scanf("%d", &d[i]);
    int k;
    for(i=0;i<n-1;i++)
        if (d[i] < d[i + 1])
        {
            k = d[i];
            d[i] = d[i + 1];
            d[i + 1] = k;
            if (i > 0)
                i -= 2;
        }
    int ans = n;
    for (i = 1; i < n; i++)
        if (d[i] == d[i - 1])
            ans--;
    printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 128
/*** author: yuji9511 ***/
#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(ll i = (m); i < (n); i++)
#define rrep(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define print2(x,y) cout << (x) << " " << (y) << endl;
#define printa(x,n) for(ll i = 0; i < n; i++){ cout << (x[i]) << " \n"[i==n-1];};

struct HashData {
	int h1, h2;
	bool operator==(const HashData& rhs) const {
		return h1 == rhs.h1 && h2 == rhs.h2;
	}
	bool operator!=(const HashData& rhs) const { return !(*this == rhs); }
};

class RollingHash {
	template<int B, int M>
	class RollingHashPart {
	private:
		size_t len;
		std::vector<int> pow_b, hash;
	public:
		RollingHashPart() {}
		template<typename T>
		RollingHashPart(const T& s) : len(s.size()), pow_b(s.size() + 1), hash(s.size() + 1) {
			pow_b[0] = 1;
			hash[0] = 0;
			for (int i = 0; i < len; i++) {
				pow_b[i + 1] = (ll)pow_b[i] * B % M;
				hash[i + 1] = ((ll)hash[i] * B + s[i]) % M;
			}
		}
		// [l, r)
		int get(int l, int r) const {
			int res = (hash[r] - (ll)hash[l] * pow_b[r - l]) % M;
			if (res < 0) res += M;
			return res;
		}
	};
public:
	RollingHashPart<1033, 1000000007> rh1;
	RollingHashPart<6037, 999999937> rh2;
 
	RollingHash() {}
	template<typename T> RollingHash(const T & s) : rh1(s), rh2(s) {}
	// [l, r)
	HashData get(int l, int r) const {
		return (HashData){ rh1.get(l, r), rh2.get(l, r) };
	}

	lpair getPair(int l, int r) const {
		return make_pair(rh1.get(l,r) , rh2.get(l, r));
	}
	// [l1, r1), [l2, r2)
	int lcp(const RollingHash & rhs, int l1, int r1, int l2, int r2) const {
		int lb = 0, ub = std::min(r1 - l1, r2 - l2) + 1;
		while (ub - lb > 1) {
			int md = (lb + ub) >> 1;
			(get(l1, l1 + md) == rhs.get(l2, l2 + md) ? lb : ub) = md;
		}
		return lb;
	}
};

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll N,M;
	cin >> N >> M;
	string S;
	cin >> S;
	RollingHash rh(S);
	ll lv = 0, rv = 0;
	ll ans = 0;
	map<lpair, ll> mp;
	rep(i,0,M){
		string q;
		cin >> q;
		if(q == "R++"){
			rv++;
		}else if(q == "R--"){
			rv--;
		}else if(q == "L++"){
			lv++;
		}else{
			lv--;
		}
		lpair d = rh.getPair(lv, rv+1);
		if(mp[d] == 0){
			ans++;
			mp[d]++;
		}
	}
	print(ans);
	
	
}


Measured memory_bytes: 26372
using System;
using System.Linq;
using System.Collections.Generic;
using System.IO;
using static System.Console;

namespace atcorder2
{
    class Program
    {
        public static long Read()
        {
            return long.Parse(ReadLine());
        }

        public static long[] Reads()
        {
            return ReadLine().Split().Select(long.Parse).ToArray();
        }


        public static long gcd(long x,long y)
        {
            if (y < x) gcd(y, x);
            while (y != 0)
            {
                var z = x % y;
                x = y;
                y = z;
            }
            return x;
        }

        public static long C(long n,long k)
        {
            long x=1;
            for (long i = 1; i <=k; i++)
            {
                x *= n - i + 1;
                x /= i;
            }
            return x;
        }
        static void Main(string[] args)
        {
            var sw = new StreamWriter(OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);

            var q = Reads();
            var l = q[0];
            var r = q[1];
            long ans = long.MaxValue;
            if (r - l <= 2019)
            {
                for (long i = l; i <=r; i++)
                {
                    for (long j = i+1; j <=r; j++)
                    {
                        ans = Math.Min(ans, i  * j  % 2019);
                    }
                }
                WriteLine(ans);
            }
            else WriteLine(0);
            

            Console.Out.Flush();
        }
    }
}


Measured memory_bytes: 18856
#include <bits/stdc++.h>
#define loop(n) for (int ngtkana_is_a_genius = 0; ngtkana_is_a_genius < int(n); ngtkana_is_a_genius++)
#define rep(i, begin, end) for (int i = int(begin); (i) < int(end); i++)
#define all(v) v.begin(), v.end()
#define rand(l, r) std::uniform_int_distribution<>(l, r)(mt)
using lint = long long;
auto mt = std::mt19937_64(std::random_device{}());
auto cmn = [](auto& a, auto b){ if (a > b) {a = b; return true;} return false; };
auto cmx = [](auto& a, auto b){ if (a < b) {a = b; return true;} return false; };
void debug_impl() { std::cerr << std::endl; }
template <typename Head, typename... Tail>
void debug_impl(Head head, Tail... tail) { std::cerr << " " << head; debug_impl(tail...); }
#ifndef STOPIT
#define debug(...)\
  do {\
    std::cerr << std::boolalpha << "[" << #__VA_ARGS__ << "]:";\
    debug_impl(__VA_ARGS__);\
    std::cerr << std::noboolalpha;\
  } while (false)
#else
#define debug(...) 0;
#endif

template < typename Container, typename Value = typename Container::value_type, std::enable_if_t<!std::is_same< Container, std::string >::value, std::nullptr_t> = nullptr>
std::istream& operator>> (std::istream& is, Container& v)
  { for (auto & x : v) { is >> x; } return is; }

template < typename Container, typename Value = typename Container::value_type, std::enable_if_t<!std::is_same< Container, std::string >::value, std::nullptr_t> = nullptr >
std::ostream& operator<< (std::ostream& os, Container const& v) {
 os << "{";
  for (auto it = v.begin(); it != v.end(); it++)
    {os << (it != v.begin() ? "," : "") << *it;}
  return os << "}";
}

int main() {
  std::cin.tie(0); std::cin.sync_with_stdio(false);
  int n; std::cin >> n;
  std::vector< lint > d(n), c(n);
  rep(i,0,n) std::cin >> d.at(i) >> c.at(i);
  lint x = std::accumulate(all(c), 0LL);
  lint y = std::inner_product(all(d), c.begin(), 0LL);
  lint ans = x - 1 + (y - 1) / 9;
  std::cout << ans << std::endl;
  return 0;
}

Measured memory_bytes: 3456
from sys import stdin

s = stdin.readline().rstrip()


m = {}

for i in range(len(s)):
    if s[i] in m:
        m[s[i]] += 1
    else:
        m[s[i]] = 1

ans = "Yes"
if len(m) != 2:
    ans = "No"
else:
    l = list(m.values())
    if l[0] != l[1]:
        ans = "No"

print(ans)


Measured memory_bytes: 38256
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M, counter;
  cin >> N >> M;
  vector<int> vec(2*M);
  for(int i=0; i<2*M; i++) cin >> vec.at(i);
  for(int j=1; j<=N; j++){
    counter=0;
    for(int i=0; i<2*M; i++){
      if(vec.at(i)==j) counter++;
    }
    cout << counter << endl;
  }
}

Measured memory_bytes: 256
s=gets.strip!
t=gets.strip!
for i in 0...s.length do
  char=[]
  for j in 0...s.length do
    if i==0 then
      str=s
      break
    else
      char.insert((j+i) % s.length,s[j])
    end
  end
  if char[0]!=nil then
    str=char.join
  end
  if str==t then
    puts "Yes"
    break
  end
  if i==s.length-1 && j==s.length-1 then
    puts "No"
  end
end


Measured memory_bytes: 3836
#include<bits/stdc++.h>
#include<cctype>
using namespace std;
#define rep(i,n) for (int i=0;i<(n);i++)
#define all(v) (v).begin(),(v).end()
typedef long long int ll;
#define pi 3.1415926535897932384
#define E9 1000000000
#define eps 1e-4
#define pii pair<int,int>

int main(){
  int N; cin >> N;
  int A[N]; rep(i,N) cin >> A[i];

  int retval = A[0];
  rep(i,N) retval = __gcd(retval, A[i]);

  cout << retval << endl;

  // cout << fixed << setprecision(10);
  
  return 0;
}



Measured memory_bytes: 4000
def read():
    N, M = map(int, input().split())
    A = map(int, input().split())
    return N, M, A

def solve(N, M, A):
    x = N - sum(A)
    return x if x >= 0 else -1
    

if __name__ == '__main__':
    inputs = read()
    print("{}".format(solve(*inputs)))


Measured memory_bytes: 65788
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
vector<ll>vec;
int main() 
{
    ll k,a,b;
    cin>>k>>a>>b;
    ll f=0;
    for(ll i=a;i<=b;i++)
    {
        if(i%k==0){
            f=1;
            break;
        }
    }
    if(f)
    cout<<"OK"<<endl;
    else
    cout<<"NG"<<endl;
	return 0;
}


Measured memory_bytes: 3644
#include <algorithm>
#include <iostream>
#include <vector>
#include <math.h>
#include <set>
#include <map>
#include <string>
#include <stack>
#include <queue>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <bitset>
#include <complex>
#include <unistd.h>
#include <cassert>
#include <cctype>
#include <random>
#include <time.h>
#define _USE_MATH_DEFINES
#define _GLIBCXX_DEBUG
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> plglg;
typedef pair<double, ll> pdlg;
typedef tuple<int, int, int> tiii;
typedef tuple<ll, ll, ll> tlglglg;
typedef tuple<double, double, double> tddd;
typedef complex<double> xy_t;
typedef vector<ll> vll;
typedef vector< vector<ll> > matrix;
#define REP(i, x, y) for(ll i = (ll)x; i < (ll)y; i++)
#define DREP(i, x, y, d) for(ll i = (ll)x; i < (ll)y; i += (ll)d)
#define PER(i, x, y) for(ll i = (ll)x; i > (ll)y; i--)
#define DPER(i, x, y, d) for(ll i = (ll)x; i > (ll)y; i -= (ll)d)
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
double pi = 3.141592653589793;
ll mod = 1000000007;
int intmax = 2147483647;
int intmin = -2147483648;
ll llmax = 9223372036854775807;
ll llmin = -9223372036854775807;
int iinf = intmax / 8;
ll inf = llmax / 8;
double eps = 1e-12;
void yesno(bool ok, string yes = "Yes", string no = "No") {
    if (ok) {
        cout << yes << endl;
    } else {
        cout << no << endl;
    }
}

ll val[200010];

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N;
    cin >> N;
    ll A[N];
    REP(i, 0, N) {
        ll a;
        cin >> a;
        A[i] = a;
        val[a]++;
    }
    ll ans = 0;
    REP(i, 0, N + 10) {
        ans += val[i] * (val[i] - 1) / 2;
    }
    REP(i, 0, N) {
        ll a = A[i];
        cout << ans - (val[a] - 1) << endl;
    }
}


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

int main(){
  list<int> L;
  int q;
  cin >> q;
  auto it = L.begin();
  int query;
  for(int i = 0; i < q; i++){
    cin >> query;
    if(query == 0){
      int x;
      cin >> x;
      it = L.insert(it, x);
    }else if(query == 1){
      int d;
      cin >> d;
      advance(it, d);
    }else{
      it = L.erase(it);
    }
  }
  for(int i : L){
    cout << i << endl;
  }
  return 0;
}


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

int main() {
    string S;
    cin >> S;
    int N = S.size();
    vector<int> s(N);
    rep(i, N) s[i] = (int)(S[i] - '0');
    long long int sum = 0;
    rep(i, 1<<(N-1)) {
        long long int sum1 = 0;
        long long int temp = s[0];
        rep(j, N-1) {
            int k = (i >> j) %2;
            if(k){
                sum1 += temp;
                temp = s[j+1]; 
            } else {
                temp = temp * 10 + s[j+1];
            }
        }
        sum1 += temp;
        sum += sum1;
    }
    cout << sum << endl;
}


Measured memory_bytes: 256
package main

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

func main() {
	max := int(1e5)
	isPrime, _ := Sieve(1e5)

	c := make([]int, max+1)
	for i := 3; i <= max; i += 2 {
		c[i] = c[i-2]
		if isPrime[i] && isPrime[(i+1)/2] {
			c[i]++
		}
	}

	Q := nextInt()
	for q := 0; q < Q; q++ {
		l, r := nextInt(), nextInt()
		if l%2 == 0 {
			l++
		}
		if r%2 == 0 {
			r--
		}
		var lc int
		if l-2 > 0 {
			lc = c[l-2]
		}
		fmt.Println(c[r] - lc)
	}
}

// Sieve returns isPrime, primes
func Sieve(max int) ([]bool, []int) {
	isPrime := make([]bool, max+1)
	for i := 2; i <= max; i++ {
		isPrime[i] = true
	}
	primes := []int{}
	for i := 2; i <= max; i++ {
		if !isPrime[i] {
			continue
		}
		for j := 2 * i; j <= max; j += i {
			isPrime[j] = false
		}
		primes = append(primes, i)
	}
	return isPrime, primes
}

var sc = bufio.NewScanner(os.Stdin)

func init() {
	sc.Buffer(make([]byte, 256), 1e9)
	sc.Split(bufio.ScanWords)
}

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

func nextInt() int {
	a, _ := strconv.Atoi(next())
	return a
}


Measured memory_bytes: 4736
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <string>
#include <cstring>
#include <cstdint>
#include <vector>
#include <algorithm>
#include <cmath>
#include<iomanip>
#include <sstream>
#include <unordered_map>
using namespace std;
static const long long MOD = 1000000007LL;
typedef long long ll;

int main()
{
	string s;
	cin>>s;
	vector<string> p;
	int ans=0;
	char t;
	t=s[0];
	int l=1;
	for(int i=0;i<s.length();i++)
	{
		if(l==1)
		{
			if(t==s[i+1])
			{
				ans++;
				t=s[i+1];
				l=2;
				i++;
			}
			else
			{
				ans++;
				t=s[i+1];
			}
		}
		else
		{
			l=1;
			ans++;
			t=s[i+1];
		}
	}
	cout<<ans<<endl;

	return 0;
} 

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,W,w,v;
    cin>>n>>W;
    vector<long long>dp(W+1);
    for(int i=0;i<n;i++){
        // cout<<"working;";
        cin>>w>>v;
        for(int k=W-w;k>=0;k--){
            dp[k+w]=max(dp[k+w],v+dp[k]);
        }
    }
    cout<<*max_element(dp.begin(),dp.end());
    return 0;
}




Measured memory_bytes: 1024
N = input()
n = map(int,raw_input().split(' '))
c = 0
for i in range(0,N-1):
	for j in range(1,N-i):
		if n[j-1] > n[j]:
			temp = n[j-1]
			n[j-1] = n[j]
			n[j] = temp
			c += 1
print " ".join(str(i) for i in n)
print c

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

int main() {
  int N, NN, h;
  cin >> N;
  NN=N;
  while (0<NN) {
	h+=NN % 10;
    NN/=10;
  }
  if ( N % h == 0 ) cout << "Yes" << endl;
  else cout << "No" << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int n, m;
vector<vector<int>> g;
int ans = 0;
void dfs(int cur, vector<int> &vis) {
	bool flag = true;
	vector<int> v = vis;
	for(int i = 0; i < n; i++) {
		if(!vis[i]) flag = false;
	}
	if(flag) {
		ans++;
		return;
	}
	for(int i = 0; i < g[cur].size(); i++) {
		int nxt = g[cur][i];
		if(vis[nxt]) continue;
		v[nxt] = true;
		dfs(nxt, v);
		v[nxt] = false;
	}
	return;
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin >> n >> m;
	g.resize(n);
	vector<int> vis(n, 0);
	vis[0] = 1;
	for(int i = 0; i < m; i++) {
		int a, b;
		cin >> a >> b;
		a--; b--;
		g[a].push_back(b);
		g[b].push_back(a);
	}
	dfs(0, vis);
	cout << ans << endl;
	return 0;	
}


Measured memory_bytes: 256
h,w = gets.split.map(&:to_i)
ans = Float::INFINITY

if h % 3 == 0
  puts 0
  exit
elsif w % 3 == 0
  puts 0
  exit
end

h.times do |i|
  rem = h - (i+1)
  a = (i+1) * w
  if w % 2 == 0
    b = (w / 2) * rem
    c = (w / 2) * rem
  else
    b = (w / 2) * rem
    c = (w / 2 + 1) * rem
  end

  tmp = [a,b,c].sort
  ans = [ans, tmp[-1] - tmp[0]].min
end

w.times do |i|
  rem = w - (i+1)
  a = (i+1) * h
  if h % 2 == 0
    b = (h / 2) * rem
    c = (h / 2) * rem
  else
    b = (h / 2) * rem
    c = (h / 2 + 1) * rem
  end

  tmp = [a,b,c].sort
  ans = [ans, tmp[-1] - tmp[0]].min
end

h.times do |i|
  rem = h - (i+1)
  a = (i+1) * w
  if rem % 2 == 0
    b = (rem / 2) * w
    c = (rem / 2) * w
  else
    b = (rem / 2) * w
    c = (rem / 2 + 1) * w
  end

  tmp = [a,b,c].sort
  ans = [ans, tmp[-1] - tmp[0]].min
end

w.times do |i|
  rem = w - (i+1)
  a = (i+1) * h
  if rem % 2 == 0
    b = (rem / 2) * h
    c = (rem / 2) * h
  else
    b = (rem / 2) * h
    c = (rem / 2 + 1) * h
  end

  tmp = [a,b,c].sort
  ans = [ans, tmp[-1] - tmp[0]].min
end

puts ans


Measured memory_bytes: 1788
import java.util.*;
public class Main{
  public static void main(String arg[]){
  Scanner sc=new Scanner(System.in);
    int a=sc.nextInt();
    int b=sc.nextInt();
	int c=0;
	int arr[]={1,100,10000,1000000};
	for(int i=1;;i++){
		if((i%arr[a]==0)&&(i%arr[a+1]!=0))
			c++;
		if(c==b){
			System.out.println(i);
			break;
		}
	}
	
  }
}

Measured memory_bytes: 22100
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
//import java.util.Scanner;
import java.util.StringTokenizer;

public class Main {
	public static void main(String[] args) throws IOException
	{
		BufferedReader br= new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st= new StringTokenizer(br.readLine());
		
		int a= Integer.parseInt(st.nextToken());
		int b= Integer.parseInt(st.nextToken());
		//String inputString=br.readLine();
		//int a = Integer.parseInt ( inputString );
		//int b = Integer.parseInt ( inputString );
		
		//Scanner sc= new Scanner(System.in);
		//int a=sc.nextInt();
		//int b=sc.nextInt();
		if((a*b)%2==0)
			System.out.println("Even");
		else System.out.println("Odd");
	
	}

}

Measured memory_bytes: 21460
import java.util.Scanner;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int d = sc.nextInt();
        int n = sc.nextInt();
        if(n == 100){
            System.out.println(101 * (int)Math.pow(100,d));
        }
        else System.out.println(n * (int)Math.pow(100,d));
    }


}


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

using namespace std;

int main() {
  string s;
  cin >> s;
  int counter = 0;
  for( int i = 0; i < 3; i++ ) {
    if( s[i] == s[i + 1] )
      counter += 1;
    else if( counter < 2 )
      counter = 0;
  }
  if( counter >= 2 )
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    int n, b, f, r, v, i, j, k;
    int cnt[4][3][10];
    for(i = 0; i < 4; i++){
        for(j = 0; j < 3; j++){
            for(k = 0; k < 10; k++){
                cnt[i][j][k] = 0;
            }
        }
    }
    
    cin >> n;
    for(i = 0; i < n; i++){
        cin >> b >> f >> r >> v;
        cnt[b-1][f-1][r-1] += v;
    }
    
    for(i = 0; i < 4; i++){
        for(j = 0; j < 3; j++){
            for(k = 0; k < 10; k++){
                cout << " " << cnt[i][j][k];
                if(k == 9) cout << endl;
            }
        }
        if(i < 3)   cout << "####################" <<endl;
    }
                
    return 0;
}



Measured memory_bytes: 3080
import sys

mod=10**9+7
fib=[1]*10
for i in range(2,10):
  fib[i]=fib[i-1]+fib[i-2]
#print(fib)

H,W,K=map(int,input().split())
if W==1:
  print(1)
  sys.exit()

dp=[[0]*(W+1) for _ in range(H+1)]
dp[0][1]=1

for i in range(1,H+1):
  dp[i][1]=(fib[W-1]*dp[i-1][1]+fib[W-2]*dp[i-1][2])%mod
  dp[i][W]=(fib[W-2]*dp[i-1][W-1]+fib[W-1]*dp[i-1][W])%mod
  for j in range(2,W):
    dp[i][j]=(fib[j-2]*fib[W-j]*dp[i-1][j-1]+fib[j-1]*fib[W-j]*dp[i-1][j]+fib[j-1]*fib[W-j-1]*dp[i-1][j+1])%mod
    
#print(dp)
print(dp[H][K])

Measured memory_bytes: 3188
#include<iostream>
#include<vector>
#include<algorithm>
#include<stack>
using namespace std;

int main(void) {

    int n;
    stack<int> s;
    while(cin >> n){
        if( n == 0 ){
          cout << s.top() << endl;
          s.pop();
        }else{
          s.push( n );
        }
    }
    return 0;
}

Measured memory_bytes: 3056
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < (n); i++)
#define REP1(i, n) for(int i = 1; i <= (n); i++)
#define REPD(i,a,b) for (int i=(a);i<=(b);i++)
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef set<int> si;
typedef vector<si> vsi;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<int, int> pi;
typedef queue<int> qi;
typedef queue<pi> qpi;
typedef pair<ll, ll> pll;
typedef queue<pll> qpll;
typedef vector<pi> vpi;
typedef vector<pll> vpll;
const int mod = 1000000007;
const int INF = 1001001001;
// 小数点　<< fixed << setprecision(0) <<
// sort降順　sort(ALL(),greater<int>());
// 円周率　M_PI
// 文字判定　isupper islower
// 文字変換　
// 順列　do {} while(next_permutation(ALL(X)));
// 最大値　LLONG_MAX
// a内でx以上　auto iter = lower_bound(ALL(a), x);
// a内でxより大きい　auto iter = upper_bound(ALL(a), x);
int dx[8] = {1, 0, -1, 0, 1, 1, -1, -1};
int dy[8] = {0, 1, 0, -1, 1, -1, 1, -1};
struct edge {
    int from; //出発点
    int to;   //到達点
    int cost; //移動コスト
};
typedef struct edge se;
typedef vector<edge> ve;
unsigned Euclidean_gcd(unsigned a, unsigned b) {
  if(a < b) return Euclidean_gcd(b, a);
  unsigned r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}

vpll PrimeFactorization(ll n) {
  vpll res;
  for (ll i=2; i*i<=n; i++) {
    if(n%i!=0) continue;
    ll ex=0;
    while(n%i==0) {
      ex++;
      n/=i;
    }
    res.push_back(pll(i,ex));
  }
  if(n!=1) res.push_back(pll(n,1));
  return res;
}

int main() {
  ll n;
  cin >> n;
  ll i=0;
  while(n>0) {
    i++;
    n-=pow(26,i);
  }
  vll ans(i,0);
  n+=pow(26,i);
  n--;
  REP(j,i) {
    ans[i-1-j]=n%26;
    n/=26;
  }
  REP(j,i) {
    char s='a'+ans[j];
    cout << s;
  }
  cout << endl;
  return 0;
}


Measured memory_bytes: 4100
#include <iostream>
#include <cmath>
#include <iomanip>
using namespace std;
int main(){
  //int sum = 0,
  int x[1000],y[1000],n;
  //double max = 0;
  double p1 = 0,p2 = 0,p3 = 0,p = 0;
  cin>>n;
  for(int i = 0;i < n;i++){
    cin>>x[i];
  }
  for(int i = 0;i < n;i++){
    cin>>y[i];
  }
  for(int i = 0;i < n;i++){
    p1 += abs(x[i]-y[i]);
    if(x[i]-y[i] < 0){
      p2 += pow(((x[i]-y[i])*-1),2.0);
    }else{
      p2 += pow(x[i]-y[i],2.0);
    }
    if(x[i]-y[i] < 0){
      p3 += pow(((x[i]-y[i])*-1),3.0);
    }else{
      p3 += pow((x[i]-y[i]),3.0);
    }
    if(abs(x[i]-y[i])>p){
      p = abs(x[i]-y[i]);
    }
  }
  p2 = sqrt(p2);
  p3 = pow(p3,1.0/3.0);
  cout<<fixed<<setprecision(5)<<p1<<endl;
  cout<<fixed<<setprecision(5)<<p2<<endl;
  cout<<fixed<<setprecision(5)<<p3<<endl;
  cout<<fixed<<setprecision(5)<<p<<endl;
  return 0;
}

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

using namespace std;

typedef long long ll;

int main() {
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    ll n, k, x, y;
    cin >> n >> k >> x >> y;
    ll ans;
    if (n <= k)
        ans = x * n;
    else
        ans = x * k;
    if (n > k)
        ans += (n - k) * y;
    cout << ans;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <stdlib.h>
#include <vector>
#include <algorithm>

using namespace std;

int main(){
	uint16_t N, M;
	int16_t C,*A,*B;
	cin >> N >> M >> C;
	A = new int16_t[M];
	B = new int16_t[M];
	for(uint16_t i = 0;i < M;i++)
		cin >> B[i];
	uint16_t res = 0;
	int32_t tmp = 0;
	for(uint16_t j = 0;j < N;j++){
		tmp = 0;
		for(uint16_t i = 0;i < M;i++){
			cin >> A[i];
			tmp += A[i]*B[i];
		}
		tmp += C;
		if(tmp > 0)
			++res;
	}
	cout << res << endl;

	

	return 0;
}

Measured memory_bytes: 256
n = int(input())
PRE = list(map(int,input().split()))
IN =  list(map(int,input().split()))
post =[]
pos = 0

def rec(l,r):
    global pos
    if l >= r : return
    root = PRE[pos]
    pos += 1
    m = IN.index(root)
    rec(l,m)
    rec(m+1,r)
    post.append(root)

def solve():
    rec(0,len(PRE))
    for i in range(n):
        if i == n-1:
            print(post[i])
        else:
            print(post[i],"",end = "")

solve()


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

int32_t main() {
    
   int a,b,c;
   cin >> a >> b >> c;
   
   if(a==1 or b==1 or c==1) {
       cout << 0 ;
       return 0;
   }
   
   if(a==b and b==c) {
   cout << -1;
   return 0;
   }
   int x=0;
   while((a%2==0) and (b%2==0) and (c%2==0)) {
       x++;
       
       int p=(b/2)+(c/2);
       int q=(a/2)+(c/2);
       int r=(b/2)+(a/2);
       
       a=p,b=q,c=r;
   }
   
   cout << x;
    
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cmath>
#include <functional>
#include <algorithm>
#include <numeric>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <deque>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <boost/range/irange.hpp>
#include <boost/container/static_vector.hpp>
#include <boost/utility/string_ref.hpp>

class input
{
    std::istream& cin;

public:
    input() : cin(std::cin)
    {
        std::cin.tie(nullptr);
        std::ios::sync_with_stdio(false);
    }

    template <class T>
    inline input& operator>>(T& var)
    {
        cin >> var;
        return *this;
    }
    template <class T>
    inline input& operator,(T& var)
    {
        cin >> var;
        return *this;
    }

    template <class T>
    inline T read()
    {
        T var;
        cin >> var;
        return var;
    }

    template <class InputIterator>
    inline void read(InputIterator head, std::size_t n)
    {
        for (std::size_t i = 0; i < n; ++i) {
            cin >> *head;
            ++head;
        }
    }

    template <class T>
    inline std::vector<T> read(std::size_t n)
    {
        std::vector<T> res;
        res.reserve(n);

        for (std::size_t i = 0; i < n; ++i) {
            T tmp;
            cin >> tmp;
            res.emplace_back(tmp);
        }
        return res;
    }

    template <class T, class F>
    inline void online(std::size_t n, F&& f)
    {
        T var;
        for (std::size_t i = 0; i < n; ++i) {
            cin >> var;
            f(var);
        }
    }
};
template <class T, std::size_t n>
std::istream& operator>>(std::istream& in, std::array<T, n>& var)
{
    for (std::size_t i = 0; i < n; ++i) {
        in >> var[i];
    }
    return in;
}

class output
{
    std::ostream& cout;

public:
    class proxy
    {
        std::ostream& cout;

    public:
        proxy() : cout(std::cout) {}
        ~proxy() { cout << '\n'; }
        template <class T>
        proxy& operator,(T&& val)
        {
            cout << ' ' << val;
            return *this;
        }
    };

public:
    output() : cout(std::cout)
    {
        cout << std::fixed << std::setprecision(15);
    }

    template <class T>
    proxy operator<<(T&& val)
    {
        cout << val;
        return {};
    }

    template <class T>
    void print(const T& container)
    {
        bool first = true;
        for (auto&& x : container) {
            if (!first) {
                cout << ' ';
                first = false;
            }
            cout << x;
        }
    }
};

int main()
{
    input in;
    output out;

    auto n = in.read<std::uint64_t>();
    if (n % 2) {
        out << 0;
        return 0;
    }

    uint64_t k = n / 2;
    uint64_t l = 0;

    uint64_t m = 5;
    while (k / m != 0) {
        l += k / m;
        m *= 5;
    }

    out << l;

    return 0;
}


Measured memory_bytes: 256
var GET=(function(){function f(s){return new g(s);}function g(s){this._s=s.trim().split("\n");this._y=0;}g.prototype.a=function(f){var s=this._s, y=this._y, r;if(typeof s[y]==="string")s[y]=s[y].split(" ").reverse();r=s[y].pop();if(!s[y].length)this._y++;return f?r:+r;};g.prototype.l=function(f){var s=this._s[this._y++].split(" ");return f?s:s.map(a=>+a);};g.prototype.m=function(n,f){var r=this._s.slice(this._y,this._y+=n).map(a=>a.split(" "));return f?r:r.map(a=>a.map(a=>+a));};g.prototype.r=function(n,f){var r=this._s.slice(this._y,this._y+=n);return f?r:r.map(a=>+a);};return f;})();
var o=GET(require("fs").readFileSync("/dev/stdin","utf8"));
function xArray(v){var a=arguments,l=a.length,r="Array(a["+--l+"]).fill(0).map(x=>{return "+v+";})";while(--l)r="Array(a["+l+"]).fill(0).map(x=>"+r+")";return eval(r);}
var bellmanFord = (function(){
  var INF = 1e9;
  function f(graph,start){
    return new bellmanFord(graph,start);
  }
  function bellmanFord(graph,start){
    var n = graph.length, n2 = n << 1;
    var dist = this.d = Array(n).fill(INF);
    var node = Array(n);
    node[start] = 1;
    dist[start] = 0;
    for(var i = 0; i < n2; i++){
      for(var v = 0; v < n; v++){
        if(node[v])for(var k = 0; k < graph[v].length; k++){
          var e = graph[v][k];
          if(dist[v] !== INF && dist[e.to] > dist[v] + e.cost){
            if(i >= n-1)dist[e.to] = -INF;
            else{
              node[e.to] = 1;
              dist[e.to] = dist[v] + e.cost;
            }
          }
        }
      }
    }
  }
  bellmanFord.prototype.dist = function(i){
    return this.d[i];
  };
  return f;
})();

console.log(main());
function main(){
  var n = o.a();
  var m = o.a();
  var p = o.a();
  var graph = xArray("[]",n);
  for(var i = 0; i < m; i++){
    var t = o.l(), a = t[0]-1, b = t[1]-1, c = t[2];
    graph[a].push({to:b,cost:p-c});
  }
  var bf = bellmanFord(graph,0);
  if(bf.dist(n-1) === -1e9)return -1;
  if(bf.dist(n-1) >= 0)return 0;
  return -bf.dist(n-1);
}

Measured memory_bytes: 10640
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#include <bits/stdc++.h> 
#define pb emplace_back
#define mp make_pair 
#define st first 
#define nd second 
#define all(v) v.begin(),v.end()
#define umap unordered_map
#define L nd<<1
#define R (L)|1
#define mid ((s + e)>>1)
#define ln '\n'
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
int n;
string s;
int ct[20005][3];
int ch[1000];
ll ans;
char diff(char c1, char c2){
	umap <int, int> m; 
	m[c1]++;
	m[c2]++;
	if(m['B']==0)return 'B';
	if(m['R']==0)return 'R';
	if(m['G']==0)return 'G';
}
int main(){
  ios_base::sync_with_stdio(0);
  cin.tie(nullptr);cout.tie(nullptr);cerr.tie(nullptr);
  ch['R'] = 0;
  ch['G'] = 1;
  ch['B'] = 2;
  cin >> n >> s;	
  for(int i = n - 1; i > 0; i--){
  	ct[i][ch[s[i]]]++;
  	ct[i - 1][0] = ct[i][0];
  	ct[i - 1][1] = ct[i][1];
  	ct[i - 1][2] = ct[i][2];
  }
  ct[0][ch[s[0]]]++;
  for(int i = 0; i < n - 2; i++){
  	for(int j = i + 1; j < n - 1; j++){
  	    if(s[i] == s[j])continue;
  		if(j + (j - i) < n && s[j + (j - i)] == diff(s[i], s[j]))ans--;
  		
  		//cout << (char)diff(s[i], s[j]) << ln;
  		ans += ct[j][ch[(int)diff(s[i], s[j])]];
  	}
  }

  cout << ans;
}

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

int main() {
    int num[] = { 1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51 };
    int k;
    cin >> k;

    cout << num[k - 1] << endl;

    return 0;
}

Measured memory_bytes: 256
import bisect

N,M = map(int,(input().split()))
bridge = [[] for _ in range(N+1)]
for i in range(M):
    a,b = map(int,(input().split()))
    bridge[a].append(b)

# UnionFind
class UnionFind:

    def __init__(self, n):
        self.par =  [-1] * n
        self.rank = [0] * n
    
    def root(self,x):
        if self.par[x] < 0:
            return x
        else:
            self.par[x] = self.root(self.par[x])
            return self.par[x]

    def union(self, x, y):
        x = self.root(x)
        y = self.root(y)

        if x == y:
            return
        else:
            if self.rank[x] <self.rank[y]:
                self.par[y] += self.par[x] # 負+負でsize管理 
                self.par[x] = y
            else:
                self.par[x] += self.par[y]
                self.par[y] = x
                if self.rank[x] == self.rank[y]: # 負+負でsize管理 
                    self.rank[x] += 1
    
    def is_same(self, x, y):
        return self.root(x) == self.root(y)

    def size(self, x):
        return -self.par[self.root(x)]

Tree = UnionFind(N)
ans = 0
for i in range(1,N+1):
    for j in range(len(bridge[i])):
        erase_a = i
        erase_b = bridge[i][j]
        del bridge[i][j]

        for k in range(1,N+1):
            for l in range(len(bridge[k])):
                Tree.union(k-1,bridge[k][l]-1)
        
        if not Tree.is_same(erase_a-1,erase_b-1):
            ans += 1

        bisect.insort_left(bridge[erase_a],erase_b)

        Tree.__init__(N)

print(ans)

Measured memory_bytes: 42352
#include<bits/stdc++.h>
using namespace std;
const long long maxn=20000;
long long n,w,s,v,dp[1111][22222],ans;
pair<long long,pair<long long,long long> > a[1111];
int main()
{
	scanf("%lld",&n);
	for (long long i=1;i<=n;i++)
	{
		scanf("%lld%lld%lld",&w,&s,&v);
		s+=w;
		a[i]=make_pair(s,make_pair(w,v));
	}
	sort(a+1,a+n+1);
	for (long long i=0;i<=n;i++)
	{
		for (long long j=0;j<=maxn;j++)
		dp[i][j]=-1e18;
	}
	dp[0][0]=0;
	for (long long i=1;i<=n;i++)
	{
		for (long long j=0;j<=maxn;j++)
		{
			dp[i][j]=max(dp[i][j],dp[i-1][j]);
			if (j>=a[i].second.first && j<=a[i].first) dp[i][j]=max(dp[i][j],dp[i-1][j-a[i].second.first]+a[i].second.second);
		}
	}
	for (long long i=0;i<=maxn;i++)
	{
		ans=max(ans,dp[n][i]);
	}
	printf("%lld\n",ans);
	return 0;
}

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

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

	vector<ll>s(n);
	s.at(0) = a.at(0);
	for (int i = 1; i < n; i++)s.at(i) = s.at(i - 1) + a.at(i);

	double mid = s.at(n - 1) * 0.5;
	int x = lower_bound(s.begin(), s.end(),mid) - s.begin();
	if (x == s.at(n - 1) * 0.5) {
		cout << 0 << endl;
		return 0;
	}
	double l = mid - s.at(x - 1);
	double r = s.at(x) - mid;
	int ans = min(l, r) * 2;
	cout << ans << endl;
}

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

pair<bool, int> square(string s, int i);

pair<bool, int> rounded(string s, int i){
    pair<bool, int> ret;
    for(;i<s.length();++i){
        if(s[i] == '['){
            ret = square(s, i+1);
            i = ret.second;
            if(ret.first == false)return ret;
        }else if(s[i] == ']'){
            return (pair<bool, int>){false, i};
        }else if(s[i] == ')'){
            return (pair<bool, int>){true, i};
        }else if(s[i] == '('){
            ret = rounded(s, i+1);
            i = ret.second;
            if(ret.first == false)return ret;
        }
    }
    return (pair<bool, int>){false, i};
}

pair<bool, int> square(string s, int i){
    pair<bool, int> ret;
    for(;i<s.length();++i){
        if(s[i] == '('){
            ret = rounded(s, i+1);
            i = ret.second;
            if(ret.first == false)return ret;
        }
        else if(s[i] == ')'){
            return (pair<bool, int>){false, i};
        }else if(s[i] == ']'){
            return (pair<bool, int>){true, i};
        }else if(s[i] == '['){
            ret = square(s, i+1);
            i = ret.second;
            if(ret.first == false)return ret;
        }
    }
    return (pair<bool, int>){false, i};
}

int main(){
    string s;
    while(getline(cin,s), s[0] != '.'){
        bool flag = false;
        pair<bool, int> ret = pair<bool, int>{true, 0};
        for(int i=0;i<s.length();++i){
            if(s[i] == '('){
                ret = rounded(s, i+1);
                if(ret.first == false){
                    flag = true;
                    printf("no\n");
                    break;
                }
                i = ret.second;
            }else if(s[i] == '['){
                ret = square(s, i+1);
                if(ret.first == false){
                    flag = true;
                    printf("no\n");
                    break;
                }
                i = ret.second;
            }else if(s[i] == ')' || s[i] == ']'){
                printf("no\n");
                flag = true;
                break;
            }
        }
        if(flag == false && ret.first == true)printf("yes\n");
        else if(flag == false)printf("no\n");
    }
    return 0;
}


Measured memory_bytes: 3140
using System;
using System.Collections.Generic;
using System.Linq;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            //[summary]A - September 9
            string N = Console.ReadLine();

            if (N.Contains('9'))
            {
                Console.WriteLine("Yes");
            }
            else
            {
                Console.WriteLine("No");
            }
        }
    }
}

Measured memory_bytes: 13268