akhauriyash/Code-Regression huggingface dataset:
/*input
100000 99999
*/
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define watch(x) cout << (#x) << " is " << (x) << endl
#define debug cout << "hi" << endl
 
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
 
const int MOD = 1e9 + 7;
 
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll a, b; cin >> a >> b;
    cout << (a * b)/__gcd(a, b);
 
    return 0;
}

Measured memory_bytes: 256
import networkx as nx

n,m=map(int,input().split())
board=[input() for _ in range(n)]
k=0
for i in range(n):
  for j in range(m):
    if board[i][j]=='o':
      k+=1
INF=10**9
g=nx.DiGraph()
g.add_node(0,demand=k)
for i in range(n):
  for j in range(m):
    if board[i][j]=='#':
      continue
    if board[i][j]=='o':
      g.add_node((i,j),demand=-1)
      g.add_edge((i,j),0,capacity=1,weight=0)
    elif board[i][j]=='.':
      g.add_node((i,j),demand=0)
      g.add_edge((i,j),0,capacity=1,weight=0)
    if i+1<n and board[i+1][j]!='#':
      g.add_edge((i,j),(i+1,j),weight=-1,capacity=INF)
    if j+1<m and board[i][j+1]!='#':
      g.add_edge((i,j),(i,j+1),weight=-1,capacity=INF)
flow=nx.min_cost_flow(g)
result=sum(v*g[k1][k2]['weight'] for k1,dc in flow.items() for k2,v in dc.items())
print(-result)

Measured memory_bytes: 60416
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <limits.h>
#define swap(type,a,b) do{type t=a;a=b;b=t;}while(0);
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))
#define ll long long
#define INF 100000000
#define FOR(i,a,n) for(i=(a);i<(n);i++)
int comp(const void* a,const void* b){
	return *(int*)a-*(int*)b;
}
void fill(int a[],int b,int c){
	int i;
	FOR(i,0,b) a[i]=c;
	return;
}
int main(void)
{
	ll n,m,a,b,c,d;
	scanf("%lld%lld%lld%lld%lld",&n,&a,&b,&c,&d);
	FOR(m,0,n){
		if(c*(n-1-m)-d*m<=b-a&&b-a<=d*(n-1-m)-c*m){
			puts("YES");
			return 0;
		}
	}
	puts("NO");
	return 0;
}

Measured memory_bytes: 128
#include <stdio.h>

int s2i(int s) {
	switch (s) {
		case 'S': return 0;
		case 'H': return 1;
		case 'C': return 2;
		case 'D': return 3;
		default: return 4;
	}
}

int i2s(int i) {
	if (i < 0 || 3 < i) return '?';
	return "SHCD"[i];
}

int main(void) {
	char aru[5][14] = {{0}};
	int asumi_kana, kitamura_eri;
	if (scanf("%d", &asumi_kana) != 1) return 1;
	for (kitamura_eri = 0; kitamura_eri < asumi_kana; kitamura_eri++) {
		char hayami_saori[4];
		int hanazawa_kana;
		if (scanf("%1s%d", hayami_saori, &hanazawa_kana) != 2) return 1;
		if (hanazawa_kana < 1 || 13 < hanazawa_kana) return 1;
		aru[s2i(hayami_saori[0])][hanazawa_kana] = 1;
	}
	for (asumi_kana = 0; asumi_kana < 4; asumi_kana++) {
		for (kitamura_eri = 1; kitamura_eri <= 13; kitamura_eri++) {
			if (!aru[asumi_kana][kitamura_eri]) {
				printf("%c %d\n", i2s(asumi_kana), kitamura_eri);
			}
		}
	}
	return 0;
}



Measured memory_bytes: 2120
#include<iostream>
#include<string>
#include<stdio.h>
using namespace std;
int main(){
  int n;
  double  a;
  std::cin >> n;
  double sum=0;
  for (int i = 0; i < n; i++) {
    std::cin >> a;
    sum+=(1/a);
  }
  printf("%6f\n",1/sum);



  return 0;
}


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

const int N = 100005;
const int mod = 1e9+7;

int n, cnt[N];

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

	cin >> n;
	for (int i = 0; i < n; ++i) {
		int x;
		cin >> x;
		++cnt[x];
	}
	int result = 1;
	for (int i = n - 1; i >= 0; i -= 2) {
		if (!i) {
			if (cnt[i] != 1) result = 0; 
		} else {
			if (cnt[i] != 2) result = 0; else result = (2 * result) % mod;
		}
	}
	cout << result << endl;
	return 0;
}

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

int main()
{
  int N;
  cin >> N;
  if (N == 0) {
    cout << 2 << endl;
  } else if (N == 1) {
    cout << 1 << endl;
  } else {
    long int jucas = 2;
    long int kucas = 1;
    long int lucas;
    for (int i = 2; i <= N; i++) {
      lucas = jucas + kucas;
      jucas = kucas;
      kucas = lucas;
    }
    cout << lucas << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main()
{
	int a[200],i,n,flag=1,sum;
	scanf("%d",&n);
	for(i=0;i<n;i++)
	{
		scanf("%d",&a[i]); 
	}
	for(sum=0;flag;)
	{
 	for(i=0;i<n;i++)
	{
		if(a[i]%2)
		{
			flag=0;
			break;
		}
		a[i]/=2;
 	}
 	if(i==n)sum++;
	}
	printf("%d\n",sum);
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
int main()
{
  string str[3] = {"Sunny", "Cloudy", "Rainy"};
  string s;
  cin >> s;

  for (int i = 0; i < 3; i++) {
    if (str[i] == s) {
      cout << str[(i+1)%3] << endl;
    }
  }

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
constexpr int64_t mod=1e9+7;

int main()
{
  int n;
  cin>>n;
  std::vector<int64_t> a(n),vec;
  for (int i = 0; i < n; ++i)
  {
    cin>>a[i];
  }
  a.insert(a.begin(),0L);
  a.emplace_back(0L);
  int64_t sum=0;
  for (int i = 0; i < n+1; ++i)
  {
    sum+=abs(a[i+1]-a[i]);
  }
  
  for (int i = 0; i < n; ++i)
  {
    cout<<sum-abs(a[i+1]-a[i])-abs(a[i+2]-a[i+1])+abs(a[i+2]-a[i])<<endl;
  }
}

Measured memory_bytes: 2032
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
using namespace std;
#define MOD @
#define ADD(X,Y) ((X) = ((X) + (Y)%MOD) % MOD)
typedef long long i64; typedef vector<int> ivec; typedef vector<string> svec;

i64 A, V, B, W, T;

int main()
{
	scanf("%lld%lld%lld%lld%lld", &A, &V, &B, &W, &T);

	i64 d = A - B;
	if (d < 0) d = -d;

	if (V <= W) {
		puts("NO");
		return 0;
	}
	if ((V - W) * T >= d) {
		puts("YES");
	} else {
		puts("NO");
	}
	return 0;
}


Measured memory_bytes: 3168
// A - November 30
#include <bits/stdc++.h>

using namespace std;

int main(int argc, char *argv[])
{
	int m1, d1, m2, d2;
	cin >> m1 >> d1 >> m2 >> d2;
	cout << (m1 != m2 ? 1 : 0) << endl;

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <string>
#include <vector>

typedef long long ll;

std::vector<std::string> split(const std::string &s, char sep){
	std::vector<std::string> out;
	std::stringstream ss(s);
	std::string temp;
	while (std::getline(ss, temp, sep)) {
		out.push_back(temp);
	}
	return out;
}

template <typename T>
void print(const std::vector<T> &x){
	for(int i=0;i<x.size();++i){
		if(i==0) std::cout << x[i];
		else std::cout << " " << x[i];
	}
	std::cout << std::endl;
}

template <typename T>
class Stack{
	std::vector<T> vec;
};

using namespace std;

ll pop(vector<ll> &x){
	ll result = x.back();
	x.pop_back();
	return result;
}

void operate(const string &s, vector<ll> &x){
	if(s == "+"){
		x.push_back(pop(x) + pop(x));
	}
	else if(s == "*"){
		x.push_back(pop(x) * pop(x));
	}
	else if(s == "-"){
		ll temp1 = pop(x);
		ll temp2 = pop(x);
		x.push_back(temp2 - temp1);
	}
	else {
		x.push_back(stoll(s));
	}
}

int main(){
	// input
	string s;
	getline(cin, s);	
	vector<string> x = split(s, ' ');
	
	// operation 
	vector<ll> stack;
	for(int i=0; i<x.size(); ++i){
		operate(x[i],stack); 
	}
	print(stack);
	return 0;
}
	



Measured memory_bytes: 3196
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

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

    int tmp = 1;
    for(int i=0; i<n-1; i++){
        tmp *= k-1;
    }

    cout << tmp * k << endl;

    return 0;
}


Measured memory_bytes: 256
# AOJ 0033

N = int(input())
for i in range(N):
    balls = list(map(int, input().split()))
    b = 0
    c = 0
    for ball in balls:
        if b < ball:
            b = ball
        elif c < ball:
            c = ball
        else:
            print('NO')
            break
    else:
        print('YES')



Measured memory_bytes: 5588
def main():
    N = input()
    n = int(N)

    max_l = len(N) + 1

    s = set()

    def search(i, n, f3, f5, f7):
        if f3 and f5 and f7:
            s.add(n)
        if i < 0:
            return

        i -= 1
        search(i, n * 10 + 3, True, f5, f7)
        search(i, n * 10 + 5, f3, True, f7)
        search(i, n * 10 + 7, f3, f5, True)

    search(max_l, 0, False, False, False)

    count = 0
    for v in s:
        if v <= n:
            count += 1

    print(count)


main()


Measured memory_bytes: 22120
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using static System.Console;
using static System.Math;

namespace Atcoder
{
    class Program
    {
        static StreamWriter sw = new StreamWriter(OpenStandardOutput()) { AutoFlush = false };
        static void Main(string[] args)
        {
            try
            {
                SetOut(sw);
                Solve.Answer();
                Out.Flush();
            }
            catch (Exception ex)
            {
                WriteLine(ex.ToString());
            }
        }
    }

    public class Solve
    {
        public static void Answer()
        {
            var n = IO.RInt;
            var m = 0;
            var a = 0;
            var r = 0;
            var c = 0;
            var h = 0;
            for (int i = 0; i < n; i++)
            {
                var s = ReadLine();
                if (s[0] == 'M') m++;
                if (s[0] == 'A') a++;
                if (s[0] == 'R') r++;
                if (s[0] == 'C') c++;
                if (s[0] == 'H') h++;
            }
            var march = new int[] { m, a, r, c, h };

            long ans = 0;
            for (int bit = 0; bit < (1 << 5); bit++)
            {
                bool[] array = new bool[5];
                for (int i = 0; i < 5; i++)
                {
                    var tmp = ((bit >> i) & 1) == 1;
                    array[i] = tmp;
                }

                if (array.Where(x => x).Count() != 3) continue;

                long tmpcnt = 1;
                for (int i = 0; i < 5; i++)
                {
                    if (array[i]) tmpcnt *= march[i];
                }
                ans += tmpcnt;
            }
            WriteLine(ans);
        }
    }

    public class IO
    {
        #region Input
        public static int RInt => int.Parse(ReadLine());
        public static long RLong => long.Parse(ReadLine());
        public static double RDouble => double.Parse(ReadLine());

        public static string[] RSString => ReadLine().Split();
        public static int[] RSInt => ReadLine().Split().Select(s => int.Parse(s)).ToArray();
        public static long[] RSLong => ReadLine().Split().Select(s => long.Parse(s)).ToArray();
        public static double[] RSDouble => ReadLine().Split().Select(s => double.Parse(s)).ToArray();
        #endregion

        #region Output
        public static void OutJoinSpace<T>(IEnumerable<T> list) => WriteLine(string.Join(" ", list));
        public static void WriteLineYes_or_No(bool flag) => WriteLine(flag ? "Yes" : "No");
        public static void WriteLineYES_or_NO(bool flag) => WriteLine(flag ? "YES" : "NO");
        #endregion
    }

    public class Mod
    {
        #region
        private readonly static long M = 1000000007;

        public static long Add(long a, long b) => (a * b) % M;
        public static long Sub(long a, long b) => (a - b) % M >= 0 ? (a - b) % M : (a - b) % M + M;
        public static long Multi(long a, long b) => (a * b) % M;
        #endregion
    }
}

Measured memory_bytes: 31748
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define fastio ios_base::sync_with_stdio(false); cin.tie(0)
#define loop(i, a, b) for(lli i=a; i<b; i++)
#define loopb(i, a, b) for(lli i=a; i>=b; i--)
#define pb push_back
#define umap unordered_map
typedef long long int lli;
typedef pair<lli, lli> pii;
typedef vector<lli> vll;
// use to avoid collision
struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }
 
    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};
// for pair in unordered_map
struct hash_pair {
    static uint64_t splitmix64(uint64_t x) {
    // http://xorshift.di.unimi.it/splitmix64.c
    x += 0x9e3779b97f4a7c15;
    x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
    x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
    return x ^ (x >> 31);
	}
    template <class T1, class T2>
    size_t operator()(const pair<T1, T2>& p) const{
        auto hash1 = hash<T1>{}(p.first);
        auto hash2 = hash<T2>{}(p.second);
        uint64_t x = hash1 ^ hash2;
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};
lli M = 1e9 + 7;
lli power(lli x, lli y){
    lli res = 1;
    x = x;
    while (y > 0) {
        if (y & 1)
            res = (res*x);
        y = y>>1;
        x = (x*x);
    }
    return res;
}
lli n, d, a;
vector<vll> S;
lli solve(){
	cin>>n>>d>>a;
	S.clear();
	loop(i, 0, n){
		lli t1, t2;
		cin>>t1>>t2;
		S.pb({t1, t2});
	}
	sort(S.begin(), S.end(), [](const vll& v1, const vll& v2){
		return v1[0] < v2[0];
	});
	lli ans = 0;
	lli temp = ceil((double)S[0][1] / (double)a);
	vector<lli> dq(n+2, 0);
	ans += temp;
	vll A(n+1);
	loop(i, 0, n)
		A[i] = S[i][0];
	A[n] = 1e15;
	dq[0] += temp;
	lli pos = lower_bound(A.begin(), A.end(), S[0][0]+2*d) - A.begin();
	if(pos != n){
		if(A[pos] == S[0][0] + 2*d)
			pos++;
		dq[pos] -= temp;
	}
	// cout<<pos<<"\n";
	loop(i, 1, n){
		lli h = ceil((double)S[i][1] / (double)a);
		dq[i] += dq[i-1];
		// cout<<h<<"\n";
		if(h > dq[i]){
			lli tmp2 = (h-dq[i]);
			lli pos = lower_bound(A.begin(), A.end(), S[i][0]+2*d) - A.begin();
			if(pos != n){
				if(A[pos] == S[i][0] + 2*d)
					pos++;
				dq[pos] -= (h-dq[i]);
			}
			ans += h-dq[i];
			dq[i] += tmp2;
		}
	}
	cout<<ans<<"\n";
	return 0;
}
int main(){
	// fastio;
	lli t;
	// cin>>t;
	t = 1;
	while(t>0){
		t--;
		solve();
	}
}

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

int main()
{
	int n, h[20];
	cin >> n;
	for (int i = 0; i < n; i ++)
		cin >> h[i];
	int ans = 1;
	int max = h[0];
	for (int i = 1; i < n; i ++)
	{
		if (h[i] >= max)
		{
			ans ++;
			max = h[i];
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define _CRT_SECURE_NO_WARNINGS
#define int long long
unordered_map<int,unordered_map<int,int> > adj,adjr;
vector<bool> v;
vector<int> dist;
bool poss;
void dfs(int loc)
{
	if(!poss) return;
	if(v[loc]) return;
	v[loc] = 1;
	for(auto &i:adjr[loc])
	{
		if(!poss) return;
		if(!v[i.first])
		{
			dist[i.first] = dist[loc] - i.second;
			dfs(i.first);
		}
		else
		{
			if((dist[i.first] + i.second) != dist[loc])
			{
				poss = 0;
				return;
			}
		}
	}
	for(auto &i:adj[loc])
	{
		if(!poss) return;
		if(!v[i.first])
		{
			dist[i.first] = dist[loc] + i.second;
			dfs(i.first);
		}
		else
		{
			if((dist[i.first] - i.second) != dist[loc])
			{
				poss = 0;
				return;
			}
		}	
	}
}
int32_t main()
{
    ios::sync_with_stdio(false);cin.tie(0);
    int n,m,x,y,z;
    cin>>n>>m;
    if(m == 0)
    {
    	cout<<"Yes";
    	return 0;
    }
    poss = 1;
    v.assign(n+1,0);
    dist.assign(n+1,0);
    vector<bool> vis(n+1,1);
    for(int i=0;i<m;i++)
    {
    	cin>>x>>y>>z;
    	adj[x][y] = z;
    	adjr[y][x] = z;
    	vis[y] = 1;
    }
    int idx = 0;
    for(int i=1;i<=n;i++)
    {
    	if(vis[i])
    	{
    		idx = i;
    		break;
    	}
    }
    if(idx == 0)
    	cout<<"No";
    else
    {
    	dfs(idx);
    	for(int i=1;i<=n;i++)
    	{
    		if(!v[i])
    			dfs(i);
    	}
    	if(poss)
    		cout<<"Yes";
    	else
    		cout<<"No";
    }
}

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

int main() {
    //int a, b, c, d, e; cin >> a >> b >> c >> d >> e;
    int a[10];
    for (int i=0; i<5; i++) {
        cin >> a[i];
    }
    
    int val = 10; 
    int sum = 0;
    for (int i=0; i<5; i++) {
        if (a[i] % 10 == 0) {
            sum += a[i];
        }

        else sum += (a[i]/10+1) * 10;
        if ((a[i] % 10) <= val && a[i] % 10 != 0) {
            val = a[i] % 10;
        }
    }
    
    cout << sum - 10 + val << endl;

    return 0;
}




Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main()
{
    string S;
    cin >> S;
    if(S=="AAA"||S=="BBB"){
        puts("No");
    }else{
        puts("Yes");
    }
}

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

const int MAX_V = 100010;
typedef int Capacity;
typedef int Cost;
const int inf = 1 << 28;

struct Edge {
	int dst;
	Capacity cap, cap_orig;
	Cost cost;
	int revEdge; bool isRev;
	Edge(int dst, Capacity cap, Cost cost, int revEdge, bool isRev)
		:dst(dst), cap(cap), cap_orig(cap), cost(cost), revEdge(revEdge), isRev(isRev) {
	}
};


struct PrimalDual {
	int n;
	vector<vector<Edge> > g;
	vector<int> top;
	PrimalDual(int n_) : n(n_), g(vector<vector<Edge> >(n_)) {}
	void add_edge(int src, int dst, Capacity cap, Cost cost) { // ?????????
		g[src].push_back(Edge{ dst, cap, cost, (int)g[dst].size(), false });
		g[dst].push_back(Edge{ src, 0, -cost, (int)g[src].size() - 1, true });
	}
	Cost solve(int s, int t, int f) {
		Cost res = 0;
		static Cost h[MAX_V], dist[MAX_V];
		static int prevv[MAX_V], preve[MAX_V];

		fill(h, h + n, 0);
		if(top.size()) {
			assert(top.size() == n);
			for(int i = 0; i < n; i++) {
				int v = top[i];
				for(int i = 0; i < g[v].size(); i++) {
					Edge& e = g[v][i];
					if(e.cap == 0) continue;
					int u = e.dst;
					h[u] = min(h[u], h[v] + e.cost);
				}
			}
		}

		while(f > 0) {
			typedef pair<Cost, int> pcv;
			priority_queue<pcv, vector<pcv>, greater<pcv> > q;
			for(int i = 0; i < n; i++) {
				dist[i] = inf;
			}
			dist[s] = 0;
			q.push(pcv(0, s));
			while(q.size()) {
				pcv p = q.top(); q.pop();
				int v = p.second;
				if(dist[v] < p.first) continue;
				for(int i = 0; i < g[v].size(); i++) {
					Edge &e = g[v][i];
					if(e.cap > 0 && dist[e.dst] > dist[v] + e.cost + h[v] - h[e.dst]) {
						dist[e.dst] = dist[v] + e.cost + h[v] - h[e.dst];
						prevv[e.dst] = v;
						preve[e.dst] = i;
						q.push(pcv(dist[e.dst], e.dst));
					}
				}
			}
			if(dist[t] == inf) {
				return -1;
			}
			for(int v = 0; v < n; v++) {
				h[v] += dist[v];
			}
			// s-t ????????????????????£??????????????????
			int d = f;
			for(int v = t; v != s; v = prevv[v]) {
				d = min(d, g[prevv[v]][preve[v]].cap);
			}
			f -= d;
			res += d * h[t];
			for(int v = t; v != s; v = prevv[v]) {
				Edge &e = g[prevv[v]][preve[v]];
				e.cap -= d;
				g[v][e.revEdge].cap += d;
			}
		}
		return res;
	}
	// ??????????????????=???????????????-?????¨??????????????¨???
	void view() {
		for(int i = 0; i < g.size(); i++) {
			for(int j = 0; j < g[i].size(); j++) {
				if(!g[i][j].isRev) {
					Edge& e = g[i][j];
					printf("%3d->%3d (flow:%d)\n", i, e.dst, e.cap_orig - e.cap);
				}
			}
		}
	}
};

int bm[12];
int bw[12];

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

	int M, W;
	while(cin >> M >> W, M + W) {
		PrimalDual pd(M + W + 2);
		int S = M + W, T = S + 1;

		for(int i = 0; i < M; i++) {
			cin >> bm[i];
			pd.add_edge(S, i, 1, 0);
		}
		for(int i = 0; i < W; i++) {
			cin >> bw[i];
			pd.add_edge(M + i, T, 1, 0);
		}

		for(int i = 0; i < M; i++) {
			for(int j = 0; j < W; j++) {
				int a = abs(bm[i] - bw[j]);
				int cost = a * (a - 30) * (a - 30);
				pd.add_edge(i, M + j, 1, -cost);
			}
		}

		cout << -pd.solve(S, T, min(M, W)) << endl;
	}
}

Measured memory_bytes: 3156
#include <bits/stdc++.h>
#define MOD 1000000007
#define MAKS 1000000000000000LL

using namespace std;

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

int ar[101010];
bool red[101010];

int main()
{
    ios::sync_with_stdio(false);
    int n,m;
    cin>>n>>m;
    for(int ctr1=0;ctr1<n;ctr1++)
        ar[ctr1]=1;
    red[0]=true;
    int a,b;
    for(int ctr1=0;ctr1<m;ctr1++){
        cin>>a>>b,a--,b--;
        if(red[a]){
            if(ar[a]==1)
                red[a]=false;
            red[b]=true;
        }
        ar[a]--,ar[b]++;
    }
    int rez=0;
    for(int ctr1=0;ctr1<n;ctr1++)
        rez+=red[ctr1];
    cout<<rez<<"\n";
}


Measured memory_bytes: 768
# -*- coding: utf-8 -*-
import sys
from bisect import bisect_left,bisect_right
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
input=lambda: sys.stdin.readline().rstrip()
YesNo=lambda b: bool([print('Yes')] if b else print('No'))
YESNO=lambda b: bool([print('YES')] if b else print('NO'))
int1=lambda x:int(x)-1

def main():
    N=int(input())
    a=list(map(int,input().split()))
    edge=[[] for _ in range(N)]
    for _ in range(N-1):
        x,y=map(int1,input().split())
        edge[x].append(y)
        edge[y].append(x)
    stack=[(0,1)]
    used=[False]*N
    ans=[0]*N
    dp=[INF]*(N+1)
    dp[0]=0
    dpdp=[]
    prev_l=1
    def dfs(v,l):
        used[v]=True
        index=bisect_right(dp,a[v]-1,hi=l)
        dpdp=(index,dp[index])
        dp[index]=a[v]
        ans[v]=bisect_left(dp,INF,hi=l+1)-1
        for nv in edge[v]:
            if not used[nv]:
                i,x=dfs(nv,l+1)
                dp[i]=x
        return dpdp
    dfs(0,1)
    for a in ans:
        print(a)

if __name__ == '__main__':
    main()


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

using namespace std;
bool check(int arr[], int j, int n) {
    for (int i=j+1; j<n; j++) {
        if (arr[i-1] < arr[i])
            continue;
        else
        {
            return false;
        }
    }
    return true;
}

int main() {
    int n;
    scanf("%d", &n);
    if (n < 2) {
        cout << "YES" << endl;
        return 0;
    }
    vector<int> arr(n);
    vector<int> toCheck(n);
    for (int i=0; i<n; i++) {
        scanf("%d", &arr[i]);
        toCheck[i] = arr[i];
    }
    sort(arr.begin(), arr.end());
    int t = 0;
    for (int i=0; i<n; i++) {
        if (toCheck[i] != arr[i])
            t++;
    }
    if (t == 2 || t ==0)
        cout << "YES" << endl;
    else
        cout << "NO" << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while (true) {
            int height = sc.nextInt();
            int width = sc.nextInt();
            if(height == 0 && width ==0){
                break;
            }
            for(int i = 0; i < height; i++){
                for(int j = 0; j < width; j++){
                    if((i == 0 || i == height - 1) || (j == 0 || j == width - 1)){
                        System.out.print("#");
                    }else{
                        System.out.print(".");
                    }
                }
                System.out.print("\n");
            }
            System.out.print("\n");
        }
    }
}


Measured memory_bytes: 36440
from collections import deque
def solve(S, Q):
    S = deque(S)
    flg = 0
    for _ in range(Q):
        que = input().split()
        if len(que) == 1:
            flg += 1
        else:
            if flg % 2 == 0:
                if que[1] == '1':
                    S.extendleft(que[2])
                elif que[1] == '2':
                    S.extend(que[2])
            elif flg % 2 == 1:
                if que[1] == '1':                 
                    S.extend(que[2])
                elif que[1] == '2':                
                    S.extendleft(que[2])
    S = ''.join(S)
    if flg % 2 == 1:
        S = S[::-1]
    print(S)

def main():
    S = input()
    Q = int(input())
    solve(S, Q)

if __name__ == "__main__":
    main()

Measured memory_bytes: 8564
# Good Distance

# libraries
import numpy as np
from itertools import combinations

# input
N, D = map(int, input().split())
X = np.zeros(shape = (N, D))

for i in range(N):
    X[i] = np.array(list(map(int, input().split())))

# solve
def calc_distance(y,z):
    return np.sqrt(np.sum((y - z)**2))

res = 0

for y, z in combinations(X, r = 2):
    distance = calc_distance(y, z)
    if distance - int(distance) == 0:
        res += 1

# output
print(res)

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

map<string,int> memo;
int main(){
	lint N,max=0;
	cin>>N;
	rep(i,N){
		string s;
		cin>>s;
		memo[s]+=1;
	}
	for(auto it=memo.begin();it!=memo.end();it++){
		if(max<(*it).second)max=(*it).second;
	}
	for(auto it=memo.begin();it!=memo.end();it++){
		if(max==(*it).second)cout<<(*it).first<<endl;
	}
}



Measured memory_bytes: 25216
#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>

using namespace std;

int main() {
  int x,a,b;
  cin >> x >> a >> b;
  if(abs(a - x) > abs(b - x)) {
    cout << "B" << endl;
  } else {
    cout << "A" << endl;
  }
}


Measured memory_bytes: 256
a,b,c=map(int,input().split())
x=c//(7*a+b)
r=c-(7*a+b)*x
t=r//a
if c%(7*a+b)!=0:
    if r>=7*a:
        print(7*x+7)    
    else:
        if r%a!=0:
            print(7*x+t+1)
        else:
            print(7*x+t)
else:
    print(7*x)


Measured memory_bytes: 5596
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
	char x,y;
	cin>>x>>y;
	if(x>y)
		printf(">\n");
		else if(x<y)
			printf("<\n");
			else 
				printf("=\n");
}

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

#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)

#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=int(a)-1;i>=int(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)

#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
#define popcount(n) (__builtin_popcountll(n))

template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}

using namespace std;
using ll=long long;

const int inf=1<<29;
map<string,int> conv;
int v[10],p[10];
int l[10],x[10],y[10];
int r[10][10],q[10][10];


signed main(void){
	int n,m,w,t;
	cin >> n >> m >> w >> t;

	rep(i,m){
		string s;
		cin >> s >> v[i] >> p[i];
		conv[s]=i;
	}

	rep(i,n){
		cin >> l[i] >> x[i] >> y[i];
		rep(j,l[i]){
			string s;
			cin >> s >> q[i][j];
			r[i][j]=conv[s];
		}
	}

	ll value[1<<7],weight[1<<7];

	{
		ll tsp[1<<7][7];
		rep(i,1<<n)rep(j,n) tsp[i][j]=inf;
		rep(i,n) tsp[bit(i)][i]=abs(x[i])+abs(y[i]);
		rep(mask,1,1<<n)rep(i,n)if(mask&bit(i)){
			rep(j,n){
				if(mask&bit(j)) continue;
				chmin(tsp[mask|bit(j)][j],tsp[mask][i]+abs(x[j]-x[i])+abs(y[j]-y[i]));
			}
		}
		rep(mask,1<<n) weight[mask]=inf;
		rep(mask,1,1<<n)rep(i,n) if(mask&bit(i)) chmin(weight[mask],tsp[mask][i]+abs(x[i])+abs(y[i]));
	}

	{
		ll dp[10010];
		rep(mask,1,1<<n){
			int profit[10];
			clr(profit,0);
			rep(i,n) if(mask&bit(i)) rep(j,l[i]) chmax(profit[r[i][j]],p[r[i][j]]-q[i][j]);
			clr(dp,0);
			rep(i,m){
				if(profit[i]==0) continue;
				rep(j,w+1) if(j+v[i]<=w) chmax(dp[j+v[i]],dp[j]+profit[i]);
			}
			value[mask]=0;
			rep(j,w+1) chmax(value[mask],dp[j]);
		}
	}

	{
		ll dp[10010];
		clr(dp,0);

		rep(i,t+1){
			if(i-1>=0) chmax(dp[i],dp[i-1]);
	 		rep(mask,1,1<<n) if(i+weight[mask]<=t) chmax(dp[i+weight[mask]],dp[i]+value[mask]);
	 	}

	 	cout << dp[t] << endl;
	}
	return 0;
}

Measured memory_bytes: 3276
a,b,c=map(int,input().split())
la=list(range(1,a,1))
lb=list(range(1,b+1,1))


lx=(set(la)^set(lb))
#print(lx)
n=0
for i in lx:
    #if c%i!=0:
        
    if c%i==0:
        n+=1
print(n)
    


Measured memory_bytes: 7768
#![allow(unused_imports)]
use itertools::Itertools;
use num_traits::clamp;
use ordered_float::OrderedFloat;
use proconio::{fastout, input, marker::*};
use std::cmp::*;
use std::collections::*;
use superslice::*;

#[fastout()]
fn main() {
    input! {
        n: usize, k: usize,
        mut a: [i64; n],
    }
    let m = 1000000007i64;
    let mod_product = |acc: i64, &value: &i64| {
        (acc * value).rem_euclid(m)
    };

    if k == n || k % 2 == 1 && a.iter().all(|v| *v <= 0) {
        a.sort_by_key(|v| -*v);
        let ans = a.iter().take(k).fold(1, mod_product);
        println!("{}", ans);
        return;
    }

    a.sort_by_key(|v| Reverse(v.abs()));
    let mut plus = Vec::new();
    let mut minus = Vec::new();
    for i in 0..n {
        if a[i] >= 0 {
            plus.push(a[i]);
        } else {
            minus.push(a[i]);
        }
    }

    let mut ppos = 0;
    let mut mpos = 0;
    let mut vals = Vec::new();
    let mut retry = false;
    while vals.len() < k {
        if vals.len() < k - 1 && ppos + 1< plus.len() && mpos + 1 < minus.len() {
            if plus[ppos] * plus[ppos+1] < minus[mpos] * minus[mpos+1] {
                vals.push(minus[mpos]);
                vals.push(minus[mpos+1]);
                mpos += 2;
            } else {
                vals.push(plus[ppos]);
                vals.push(plus[ppos+1]);
                ppos += 2;
            }
        } else if vals.len() < k - 1 && mpos + 1 < minus.len() {
            vals.push(minus[mpos]);
            vals.push(minus[mpos+1]);
            mpos += 2;
        } else if ppos < plus.len() {
            vals.push(plus[ppos]);
            ppos += 1;
        } else {
            retry = true;
            break;
        }
    }
    let ans = if !retry {
        vals.iter().fold(1, mod_product)
    } else {
        assert!(k % 2 == 1);
        a.sort_by_key(|v| v.abs());
        a.iter().take(k).fold(1, mod_product)
    };
    println!("{}", ans);
}


Measured memory_bytes: 9772
n = int(input())
a = []
a.append(1)
for i in range(n):
	x = int(input())
	a.append(x)
y = 0
check = True
for i in range(n+1):
	y = a[y]
	if a[y] == 2:
		print(i+1)
		check = False
		break
if check:
	print('-1')

Measured memory_bytes: 7084
#include <iostream>

using namespace std;
using ll = long long;
using ld = long double;

#define ALL(x) begin(x), end(x)
#define REP(i, n) for (size_t i = 0, i##_len = (n); i < i##_len; ++i)

void solve(ll N, ll A, ll B) {
  int ans{};
  for (auto i = 1; i <= N; ++i) {
    int sum = [](int x) {
      int ret{};
      while (x) {
        ret += x % 10;
        x /= 10;
      }
      return ret;
    }(i);
    if (A <= sum && sum <= B) ans += i;
  }
  cout << ans << endl;
}

int main() {
  ll N;
  cin >> N;
  ll A;
  cin >> A;
  ll B;
  cin >> B;
  solve(N, A, B);
  return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;

class Program{
  static void Main(){
    string[] input = Console.ReadLine().Split(' ');
    int N = int.Parse(input[0]);
    int M = int.Parse(input[1]);
    
    int W = (int)Math.Pow(2, N);
    int[,] DP = new int[M+1, W+1];
    
    // dp (縦)
    for (int i = 1; i <= M; i++){
      string[] ab = Console.ReadLine().Split(' ');
      int a = int.Parse(ab[0]);
      int b = int.Parse(ab[1]);
      string[] c = Console.ReadLine().Split(' ');
      
      // cを数値に変換
      int c_num = 0;
      for (int k = 0; k < b; k++){
        c_num += (int)Math.Pow(2, int.Parse(c[k]) - 1);
      }
      
      // dp (横)
      for (int j = 0; j < W; j++){
        if(j != 0 && DP[i-1, j] == 0)
          continue;
        
        if(DP[i, j] != 0)
          DP[i, j] = Math.Min(DP[i, j], DP[i-1, j]);
        else
          DP[i, j] = DP[i-1, j];
        
        // d := 状態 j と 鍵 i から得られる状態
        int d = NewStatus(c_num, j);
        int tmp;
        if(DP[i-1, d] != 0)
          tmp = Math.Min(DP[i-1, d], DP[i-1, j] + a);
        else
          tmp = DP[i-1, j] + a;
        
        if(DP[i, d] != 0)
          DP[i, d] = Math.Min(DP[i, d], tmp);
        else
          DP[i, d] = tmp;
      }  
    }
    
    int ans;
    if (DP[M, W-1] == 0)
      ans = -1;
    else
      ans = DP[M, W-1];
    
    Console.WriteLine(ans);
  }
  
  static int NewStatus(int sta1, int sta2){
    return sta1 | sta2;
  }
}


Measured memory_bytes: 24800
#![allow(non_snake_case,unused_variables)]
use std::io::{self, BufRead};
use std::str;

fn main() {
    let stdin = io::stdin();
    let mut s = String::new();
    let _ = stdin.read_line(&mut s);
    let vec: Vec<i64> = s.split_whitespace().map(|v| str::parse::<i64>(v).unwrap()).collect();

    let N = vec[0];
    let A = vec[1];
    let B = vec[2];

    let mut s = String::new();
    let _ = stdin.read_line(&mut s);
    let xs: Vec<i64> = s.split_whitespace().map(|v| str::parse::<i64>(v).unwrap()).collect();

    let mut total = 0;
    for i in 0..xs.len() - 1 {
        let w = (xs[i + 1] - xs[i]) * A;
        let cost = if w < B { w } else { B };
        total += cost;
    }

    println!("{}", total);
}


Measured memory_bytes: 2684
#include <bits/stdc++.h>
#define rep(i, a, n) for(int (i) = (int)(a);(i) < (int)(n);++(i))
#define repe(i, a, n) for(int (i) = (int)(a);(i) <= (int)(n);++(i))
#define repif(i, a, x) for(int (i) = (int)(a);(x);++(i))
#define repr(i, a, n) for(int (i) = ((int)(a)-1);(i) >= (int)(n);--(i))
#define reper(i, a, n) for(int (i) = (int)(a);(i) >= (int)(n);--(i))
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define SIZE(x) ((int)(x).size())
#define ALL(x) (x).begin(), (x).end()
#define RNG(x, a, n) &((x)[a]), &((x)[n])
#define ADD(a, b) ((((a+MOD)%MOD)+((b+MOD)%MOD))%MOD)
#define MUL(a, b) ((((a)%MOD)*((b)%MOD))%MOD)
#define CEIL(x) ((int)ceil(((double)x)))
#define POW(x, y) ((int)pow(x, y))
#define UNIQUE(x) (x).erase(unique(ALL((x))), (x).end())
#define YES cout << "YES" << endl
#define NO cout << "NO" << endl
#define Yes cout << "Yes" << endl
#define No cout << "No" << endl
#define yes cout << "yes" << endl;
#define no cout << "no" << endl;
#define fcout cout << fixed << setprecision(10)
#define pb push_back
#define pf push_front
#define mp make_pair
#define mt make_tuple
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define PI 3.1415926535897
#define EPS (1e-10)
#define INF INT_MAX
#define INFLL LLONG_MAX
#define MOD 1000000007
using llint = long long;
using VI = std::vector<int>;
using PII = std::pair<int, int>;
using SI = std::set<int>;
using MII = std::map<int, int>;
using TIII = std::tuple<int, int, int>;
using MCI = std::map<char, int>;
using VPII = std::vector<PII>;
using namespace std;


signed main(){
	int X;
	cin >> X;

	if(X == 3 || X == 5 || X == 7) YES;
	else NO;

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  string s;
  cin>>s;
  long l=s.length(),pat=l*(l-1)/2+1,res=0,c;
  map<int,int> m;
  for(int i=0;i<l;++i)m[s[i]]++;
  for(auto itr=m.begin();itr!=m.end();itr++){
    c=(*itr).second;
    res+=c*(c-1)/2;
  }
  cout<<pat-res<<endl;
  return 0;
}

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

#define endl '\n'
#define ll long long

using namespace std;

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);

	int n, m, a, sum = 0;
	cin >> n >> m;

	for (int i = 0; i < m; i++)
	{
		cin >> a;
		sum += a;
	}

	if (sum > n) cout << -1;
	else cout << n - sum << endl;

	return 0;
}

Measured memory_bytes: 3652
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <bits/stdc++.h>
#include<queue>
#include <numeric>
using namespace std;
 
//conversion
//------------------------------------------
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();}
 
//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}
 template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
 
//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
 
//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define fore(i,a) for(auto &i:a)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
 
//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))
 
//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
 



int main(){
    long long H,N;
    cin >> H >> N;
    LL A[N];
    LL sum=0;
    REP(i,N) cin >> A[i];
    REP(i,N) sum+=A[i];
    if(sum>=H){
        cout << "Yes";
    }
    else{
        cout << "No";
    }
    }

Measured memory_bytes: 1024
#include<iostream>
#include<iomanip>
//#include<cstdio>
#include<vector>
#include<map>
#include<queue>
#include<algorithm>
#include<cmath>
#include<cassert>
using namespace std;
typedef long long ll;
const int Nmax = 50;
int N, A, X[Nmax];
ll dp[Nmax+1][Nmax+1][Nmax*Nmax+1];

int main(){
	cin >> N >> A;
	for(int i=0; i<N; i++) cin >> X[i];

	dp[0][0][0] = 1;
	for(int i=0; i<N; i++){
		for(int j=0; j<=N; j++){
			for(int x=0; x<=N*A; x++){
				dp[i+1][j][x] = dp[i][j][x];
				if(j>0 && x>=X[i]) dp[i+1][j][x] += dp[i][j-1][x-X[i]];
			}
		}
	}

	ll ans = 0;
	for(int j=1; j<=N; j++){
		//cout << j << " " << A*j << " " << dp[N][j][A*j] << endl;
		ans += dp[N][j][A*j];
	}
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 50048
#include <iostream>
#include <queue>
#define NMAX 100000

using namespace std;

class process{
  public:
    string name;
    int time;
};

int main()
{
  int i;
  int n;
  int qtime;
  int sumtime = 0;
  process p;
  queue<process> q;


  /* ??\?????¨??? */
  cin >> n;
  cin >> qtime;
  for(i = 0 ; i < n ; i++)
  {
    cin >> p.name;
    cin >> p.time;
    q.push(p);
  }

  /* ????????¨??? */
  while(!q.empty())
  {
    p = q.front();
    q.pop();
    if(p.time > qtime)
    {
      p.time -= qtime;
      q.push(p);
      sumtime += qtime;
    }
    else 
    {
      sumtime += p.time;
      cout << p.name << " " << sumtime << endl;
    }
  }

}

Measured memory_bytes: 4404
s = input()

if s.count(s[0]) == 4:
    print('No')
elif s[0] == s[1] and s[2] == s[3]:
    print('Yes')
elif s[0] == s[2] and s[1] == s[3]:
    print('Yes')
elif s[0] == s[3] and s[1] == s[2]:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3060
n, m = map(int, input().split())
k_a = [ list(map(int, input().split())) for _ in range(n) ]

ans = {}
for a in k_a:
    for i in a[1:]:
        if i in ans.keys():
            ans[i] += 1
        else:
            ans[i] = 1
print(sum([ 1 for i,v in ans.items() if v == n ]))

Measured memory_bytes: 9164
using System;
class Program{
	static void Main(){
		int s=int.Parse(Console.ReadLine());

		long[] h=new long[40];
		long[] h2=new long[40];
		for(int i=0;i<40;i++){
			h[i]=(long)Math.Pow(2,i)*((i&1)*-2+1);
			h2[i]=h[i]+(i>1?h2[i-2]:0);
		}

		long p=0,ans=0,stk=0;
		int q=0;
		if(s<0){
			for(int i=1;i<40;i+=2){if(s>=h2[i]){q=i;break;}}
			ans|=(long)Math.Pow(2,q);
			p+=h[q];
			stk=h2[q];

			while(q>0){
				q--;
				if((q&1)==0){if(s>=stk+((long)Math.Pow(2,q))){ans|=(long)Math.Pow(2,q);p+=h[q];stk+=((long)Math.Pow(2,q));}}
				else{
					if(s<stk+((long)Math.Pow(2,q))){ans|=(long)Math.Pow(2,q);p+=h[q];}
					else{stk+=((long)Math.Pow(2,q));}
				}
			}
		}
		else if(s>0){
			for(int i=0;i<40;i+=2){if(s<=h2[i]){q=i;break;}}
			ans|=(long)Math.Pow(2,q);
			p+=h[q];
			stk=h2[q];

			while(q>0){
				q--;
				if((q&1)==0){
					if(s>stk-((long)Math.Pow(2,q))){ans|=(long)Math.Pow(2,q);p+=h[q];}
					else{stk-=((long)Math.Pow(2,q));}
				}
				else{if(s<=stk-((long)Math.Pow(2,q))){ans|=(long)Math.Pow(2,q);p+=h[q];stk-=((long)Math.Pow(2,q));}}
			}
		}
		Console.WriteLine("{0}",Convert.ToString(ans,2));
	}
}

Measured memory_bytes: 13268
import java.util.*;
 
public class Main {
    public static int[] pre, in, post;
    public static int position, count;
 
    public static void reconstruct(int left, int right) {
        if (left >= right) return;
        int root = pre[position++];
        int middle = 0;
        while (in[middle] != root) middle++;
        reconstruct(left, middle);
        reconstruct(middle + 1, right);
        post[count++] = root;
    }
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        pre = new int[n];
        in = new int[n];
        post = new int[n];
        for (int i = 0; i < n; i++) pre[i] = scanner.nextInt();
        for (int i = 0; i < n; i++) in[i] = scanner.nextInt();
        position = 0;
        count = 0;
        reconstruct(0, n);
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < n; i++) {
            sb.append(post[i]);
            sb.append(i != n - 1 ? " " : "\n");
        }
        System.out.print(sb);
    }
}

Measured memory_bytes: 26404
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(br.readLine());
		String[] sa = br.readLine().split(" ");
		int[] a = new int[n];
		for (int i = 0; i < n; i++) {
			a[i] = Integer.parseInt(sa[i]);
		}
		br.close();

		int mod = 1000000007;
		long ans = 1;
		int cnt = 0;
		for (int i = 0; i < n; i++) {
			cnt++;
			if (a[i] < 2 * cnt - 1) {
				ans *= cnt;
				ans %= mod;
				cnt--;
			}
		}
		for (int i = 1; i <= cnt; i++) {
			ans *= i;
			ans %= mod;
		}
		System.out.println(ans);
	}
}


Measured memory_bytes: 38432
import java.util.*;

public class Main{
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int X = sc.nextInt();
    int A = sc.nextInt();
    int B = sc.nextInt();
    X -= A;
    while (X >= B) {
      X -= B;
    }
      System.out.println(X);
  }
}

Measured memory_bytes: 22868
fun main(){
    val n = readLine()!!.split(" ").map { it.toInt() }[0]
    val k = readLine()!!.split(" ")[0].toCharArray()
    val rIndex = mutableListOf<Int>()
    val gIndex = mutableListOf<Int>()
    val bIndex = mutableListOf<Int>()
    for (i in 0 until n){
        if (k[i] == 'R'){
            rIndex.add(i)
        } else if (k[i] == 'G'){
            gIndex.add(i)
        } else {
            bIndex.add(i)
        }
    }
    val r = rIndex.size
    val g = gIndex.size
    val b = bIndex.size
    var ans:Long = r.toLong() * g * b
    for (i in 0 until n){
        for (j in 1 until n){
            if (i + j > k.size - 1 || i - j < 0){
                break
            }
            if (k[i] == 'R'){
                if (k[i + j] == 'G' && k[i - j] == 'B'){
                    ans -= 1
                } else if (k[i + j] == 'B' && k[i - j] == 'G'){
                    ans -= 1
                }
            } else if (k[i] == 'G'){
                if (k[i + j] == 'R' && k[i - j] == 'B'){
                    ans -= 1
                } else if (k[i + j] == 'B' && k[i - j] == 'R'){
                    ans -= 1
                }
            } else {
                if (k[i + j] == 'G' && k[i - j] == 'R'){
                    ans -= 1
                } else if (k[i + j] == 'R' && k[i - j] == 'G'){
                    ans -= 1
                }
            }
        }
    }
    println(ans)
}


Measured memory_bytes: 38360
import java.util.*;

public class Main{
  public static void main(String[] args)
  {
    Scanner sc=new Scanner(System.in);
    int n=sc.nextInt();
    int cnt=0;
    String ans="No";
    for(int i=0;i<n;i++)
    {
      int x=sc.nextInt();
      int y=sc.nextInt();
      if(x==y)
      {
        cnt++;
        if(cnt==3)
        ans="Yes";
      }
      else
      {
        cnt=0;
      }
    }
    System.out.println(ans);
  }
}


Measured memory_bytes: 36072
#include <iostream>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#include <functional>

using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> P;
typedef vector<P> vpl;
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(ll i=(a); i<(b); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const int inf = 1<<30;
const ll linf = 1LL<<62;
const int mod = 1e9+7;
const int MAX = 5100000;
const int V = 100005;
ll dy[8] = {1,0,-1,0,1,-1,1,-1};
ll dx[8] = {0,1,0,-1,1,-1,-1,1};
const double pi = acos(-1);
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
template<typename T1,typename T2> inline void print2(T1 a, T2 b){cout << a << " " << b << endl;}
#define INT_MAX 1e9+7
vector<ll> fac(MAX), finv(MAX), inv(MAX);

int main(){
    ll n,m; cin >> n >> m;
    vector<vpl> G(n);
    rep(i,m){
        ll a,b,c; cin >> a >> b >> c; a--; b--;
        G[a].emplace_back(b,c);
        G[b].emplace_back(a,-c);
    }
    set<ll> se;
    rep(i,n) se.insert(i);
    vl x(n,inf);
    while(!se.empty()){
        ll s = *se.begin(); se.erase(s);
        if(x[s] != inf) continue;
        if(G[s].empty()) continue;
        queue<ll> q;
        q.push(s);
        x[s] = 0;
        while(!q.empty()){
            ll u = q.front(); q.pop();
            for(auto v : G[u]){
                if(x[v.first]==inf){
                    x[v.first] = x[u] + v.second;
                    q.push(v.first);
                }
                else{
                    if(x[v.first] != x[u] + v.second){
                        puts("No");
                        return 0;
                    }
                }
            }
        }
    }
    puts("Yes");
}


Measured memory_bytes: 137728