akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
int main()
{
    int n,i,q,p;
    scanf("%d",&n);
    int a[n],b[n];
    p=0,q=n-1;
    for(i=0;i<n;i++)
    {
        scanf(" %d",&a[i]);
    }
    for(i=q;i>=0;i--)
    {
        if(n%2)
        {
            if(i%2==0)
                b[p++]=a[i];
            else b[q--]=a[i];}
        else { if(i%2)
            b[p++]=a[i];
            else b[q--]=a[i];
        }
    }
    for(i=0;i<n;i++)
    {
        printf("%d ",b[i]);
    }
    return 0;
}


Measured memory_bytes: 3712
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end())
#define VRSORT(v) sort(v.rbegin(), v.rend())//vectorの降順ソート
#define ll long long
#define pb(a) push_back(a)
#define INF 1000000000
#define MOD 1000000007
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

typedef vector<unsigned int>vec;
typedef vector<vec> mat;
typedef tuple<ll, ll, ll> T;

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

const int limit = 50;
int n,m;
int a[limit],b[limit];
bool graph[limit][limit];
bool visited[limit];

void dfs(int v){
    visited[v]=true;
    REP(v2,n){
        if(graph[v][v2]==false)continue;
        if(visited[v2]==true)continue;
        dfs(v2);
    }
}
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin>>n>>m;
    REP(i,m){
        cin>>a[i]>>b[i];
        a[i]--;b[i]--;
        graph[a[i]][b[i]]=graph[b[i]][a[i]]=true;
    }
    int ans=0;
    REP(i,m){
        graph[a[i]][b[i]]=graph[b[i]][a[i]]=false;

        REP(j,n) visited[j]=false;
        dfs(0);
        bool bridge = false;
        REP(j,n) if(visited[j]==false)bridge=true;
        if(bridge) ans+=1;
        graph[a[i]][b[i]]=graph[b[i]][a[i]]=true;
    }
    cout<<ans<<endl;
}

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

using namespace std;

int a[111111];
int n;

int main(){
//	freopen("input.inp", "r", stdin);
	scanf("%d",&n);
	for(int i = 1; i <= n; ++i) scanf("%d",&a[i]);
	sort(a + 1, a + 1 + n);
	int an = 0;
	for(int i = 1; i <= n; ++i){
		int l = i, r = n;
		while (l <= r){
			int md = (l + r) >> 1;
			if (a[md] - a[i] > 2) r = md - 1;
			else l = md + 1;
		}
		an = max(an, l - i);
	}
	printf("%d",an);
	return 0;
}

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

int main() {
	int h, w;
	cin >> h >> w;
	vector<string> s(h);
	vector<vector<int>> ans(h, vector<int>(w));
	rep(i, h) cin >> s[i];
	rep(i, h) rep(j, w) {
		if(s[i][j] == '#') {
			ans[i][j] = -1;
			for(int k = -1; k <= 1; k++) {
				if(k + i < 0 || k + i >= h) continue;
				for(int l = -1; l <= 1; l++) {
					if(k == 0 && l == 0) continue;
					if(l + j < 0 || l + j >= w) continue;
					if(s[i+k][j+l] == '#') continue;
					ans[i+k][j+l]++;
				}
			}
		}
	}
	rep(i, h){
		rep(j, w) {
			if(ans[i][j] == -1) cout << '#';
			else cout << ans[i][j];
		}
		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 256
n = int(input())
s = []*100
for i in range(n):
  s.append(input().split())
ans = 0
for i in range(n):
  if s[i][1] == "JPY":
    ans += float(s[i][0])
  else:
    ans += float(s[i][0])*380000
print(ans)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
int main(){
	int n;
	cin >> n; 
	vector<int> a(n);
	int sum=0;
	for(int i=0; i<n; ++i){
		cin >> a[i];
		sum ^= a[i];
	}

	for(int i=0; i<n; ++i){
		cout << (sum^a[i]) << " ";
	}
	cout << endl;
}

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

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

Measured memory_bytes: 256
#include<bits/stdc++.h>
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
using namespace std;
const int N=2e5+5;
int n,a[N],v[N*5],ans=0,x;
signed main(){
//	freopen(".inp","r",stdin);
//	freopen(".out","w",stdout);
//	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin>>n;
	for(int i=0;i<n;i++) cin>>a[i];
	sort(a,a+n);
	for(int i=0;i<n;i++){
		x=0;
		for(int j=2;j<=sqrt(a[i]);j++){
			if(a[i]%j==0){
				if(v[j]||v[a[i]/j]) x=1;
			}
		}
		if(i>0&&a[i]==a[i-1]) x=1;
		if(i<n-1&&a[i]==a[i+1]) x=1;
		if(v[1]==1) x=1;
		if(!x) ans++;
		v[a[i]]=1;
	}
	cout<<ans;
}


Measured memory_bytes: 8344
def main():
    n = int(input())
    a_lst = list(map(int, input().split()))
    lst1 = []
    lst2 = []

    if n % 2 == 0:
        for i in range(n // 2):
            lst1.append(a_lst[-1 - i * 2])
        for i in range(n // 2):
            lst2.append(a_lst[i * 2])

    else:
        for i in range(n // 2):
            lst1.append(a_lst[-1 - i * 2])
        lst2.append(a_lst[0])
        for i in range(n // 2):
            lst2.append(a_lst[1 + i * 2])

    lst = lst1 + lst2
    ans = ''
    for i in range(n - 1):
        ans += '{} '.format(lst[i])
    ans += '{}'.format(lst[-1])
    print(ans)


if __name__ == '__main__':
    main()

Measured memory_bytes: 30984
N = int(input())

hurui = [True]*(55556)
for i in range(2, int(55555**0.5)+1):
    for j in range(i*2, 55556, i):
        hurui[j] = False
sosu = []
for i in range(2, 55556):
    if i%5 != 1:
        continue
    if hurui[i]:
        sosu.append(i)

print(*sosu[:N])

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

int main() {
    string W, T;
    cin >> W;
    REP(i, W.size()) W[i] = tolower(W[i]);
    int s = 0;
    while (cin >> T, T != "END_OF_TEXT") {
        REP(i, T.size()) T[i] = tolower(T[i]);
        if (T.find(W) != -1 && W.size() == T.size()) s++;}
    cout << s << endl;
}

Measured memory_bytes: 3156
// D - 2017-like Number
#include <bits/stdc++.h>
using namespace std;

vector<bool> primes_create(int n){
	vector<bool> p(n+1, true);
	p[0] = p[1] = false;
	for(int i=2; i*i<=n; ++i)
		if(p[i]) for(int j=i+i; j<=n; j+=i) p[j] = false;
	return p;
}

int main(){
	vector<bool> P = primes_create(100000+1);

	vector<int> C(P.size());//Cumulative sum
	for(int n=3; n<P.size(); ++n)
		C[n] += C[n-1] + (n%2 && P[n] && P[(n+1)/2]);

	int Q; cin>>Q;
	while(Q--){
		int l,r; cin>>l>>r;
		cout<< C[r] - C[l-1] <<endl;
	}
}

Measured memory_bytes: 1024
paths = [list(map(int, input().split())) for _ in range(3)]

link = [[0 for _ in range(4)] for _ in range(4)]
for path in paths:
  link[path[0]-1][path[1]-1] += 1
  link[path[1]-1][path[0]-1] += 1

ans = 'YES'
for i in range(4):
  tmp = 0
  for j in range(4):
    tmp += link[i][j]

  if tmp >= 3:
    ans = 'NO'

print(ans)

Measured memory_bytes: 9120
#include<iostream>
using namespace std;
int main(){
	int n,x[100],y[100],now=1;
	while(cin>>n,n){
		double ans=0,pre;
		for(int i=0;i<n;i++)
		cin>>x[i]>>y[i];
		for(int i=1;i<n-1;i++){
			pre=((y[i+1]-y[0])*(x[i]-x[0])-(x[i+1]-x[0])*(y[i]-y[0]));
			ans+=pre;
		}
		ans=max(ans,-ans);
		printf("%d %.1lf\n",now++,ans/2);
	}
	return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
#define REP(i,st,ed) for(register int i=st,i##end=ed;i<=i##end;++i)
#define DREP(i,st,ed) for(register int i=st,i##end=ed;i>=i##end;--i)
typedef long long ll;
inline int read(){
	int x;
	char c;
	int f=1;
	while((c=getchar())!='-' && (c<'0' || c>'9'));
	if(c=='-') c=getchar(),f=-1;
	x=c^'0';
	while((c=getchar())>='0' && c<='9') x=(x<<1)+(x<<3)+(c^'0');
	return x*f;
}
inline ll readll(){
	ll x;
	char c;
	ll f=1;
	while((c=getchar())!='-' && (c<'0' || c>'9'));
	if(c=='-') c=getchar(),f=-1;
	x=c^'0';
	while((c=getchar())>='0' && c<='9') x=(x<<1ll)+(x<<3ll)+(c^'0');
	return x*f;
}
const int maxn=3e5+10;
int a[maxn];
int main(){
	int n=read(),A=read(),B=read();
	if(1ll*A*B<n  || A+B-1>n || A>n || B>n || A<1 || B<1){
		printf("-1\n");
		return 0;
	}
	int tmp=0,res=n;
	REP(i,res-A+1,res) printf("%d ",i);
	res=res-A;
	int x=0;
	if(res) x=res/(B-1);
	B--;
	while(res){
		int u=res-x+1;
		if(B*x<res) u--;
		REP(i,u,res) printf("%d ",i);
		B--;
		res=u-1;
	}
	return 0;
}


Measured memory_bytes: 2176
import sys
from heapq import heapify, heappop, heappush
from collections import defaultdict

def main():
    finput=lambda :sys.stdin.readline().strip()
    n,a,b=map(int,finput().split())
    h=[int(finput()) for _ in range(n)]
    gs=lambda a,b:a//b+(a%b>0)
    def enough(t):
        s=sum([gs(max(x-t*b,0),a-b) for x in h])
        if s<=t:
            return True
        else:
            return False
    def biser(t,l):
        if l==0:
            return t
        t=t+l//2
        if enough(t):
            return biser(t-l//2,l//2)
        else:
            return biser(t+1,l-l//2)
    l=max(h)//b+1
    t=biser(0,l)
    #while l>0:
    #    t=t+l//2
    #    if enough(t):
    #        t=t-l//2
    #        l=l//2
    #    else:
    #        t+=1
    #        l=l-l//2
    print(t)

if __name__=='__main__':
    main()



Measured memory_bytes: 17096
def two_int():
    N, K = map(int, input().split())
    return N,K

def one_int():
    return int(input())

def one_str():
    return input()

def many_int():
    return list(map(int, input().split()))


n=one_int()

divisors = []
for i in range(int(n**0.5)+1, 0, -1):
    if n % i == 0:
        if i!=1:
            divisors.append((i,n//i,i+n//i -2))
        else:
            divisors.append((i,n//i, n//i -1))

# import math
# nn= int(math.sqrt(n))-1
# ans=[]
# min_ans=10**13
# for i in range(nn,n+1):
#     temp=n/i
#     if temp.is_integer():
#         if (int(temp) + i) < min_ans:
#             ans=[int(n/i),i]
#             min_ans = int(n/i)+i

# divisors

divisors=sorted(divisors,key=lambda x:x[2])[0]

print(divisors[2])

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

// int/long:		-2,147,483,648 - 2,147,483,648 (-2^31 <= int < 2^31)
// long/long long:	-9,223,372,036,854,775,808 - 9,223,372,036,854,775,807 (-2^63 <= long < 2^63)

#define	INF (1<<29)
//536,870,912

// lower_bound(A.begin(), A.end(), N)
// upper_bound(...

// A.erase(unique(A.begin(), A.end()), A.end())

// bit: &/and, |/or, ^/xor, ~/not

// getline(cin, String)

// Graph
// Warshall-Floyd: Distance between each node, N^3
// Dijkstra: Distance from the start node, N^2
// DFS(Depth-First Search)

/*
int	gcd(int A, int B) {
	while (0!=B) {
		A %=B;
		swap(A, B);
	}
	return A;
}
*/

#define	MOD 1000000007

int	main() {
	int N;
	cin >>N;
	vector<vector<int>> A(N, vector<int> (2, 0));
	for (int i=0; i<N; i++)
		cin >>A.at(i).at(0) >>A.at(i).at(1);
	sort(A.begin(), A.end());
	cout <<A.back().at(0)+A.back().at(1) <<endl;
	return 0;
}



Measured memory_bytes: 5760
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp11
{
    class Class33
    {
        static void Main()
        {
            int N = int.Parse(Console.ReadLine());
            var H = Console.ReadLine().Split().Select(int.Parse).ToArray();
            bool B = false;
            int count = 0;
            while (H.Sum() > 0)
            {
                for (int i = 0; i < N; i++)
                {

                    if (H[i] > 0)
                    {
                        H[i] -= 1;
                        if (!B)
                        {
                            count += 1;
                            B = true;
                        }
                    }
                    else
                        B = false;
                }
                B = false;
            }
            Console.WriteLine(count);
        }
    }
}


Measured memory_bytes: 13396
/* ＵＴＦ－８ */
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <deque>
#include <list>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <array>
#include <queue>
#include <stack>
#include <algorithm>
#include <tuple>
#include <numeric>
#include <type_traits>
#include <limits>

#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <string.h>

#define USE_COLORED 1

#ifdef USE_COLORED
static const char stdout_pre[]  = "\033[1m"; // bold black
static const char stderr_pre[]  = "\033[31;1m"; // bold red
static const char stdxxx_post[] = "\033[m";

// 当然ながら GCC(g++)/libstdc++ 依存
#include <ext/stdio_filebuf.h>
using stdio_filebuf = __gnu_cxx::stdio_filebuf<char>;
class colored_stdio_filebuf : public stdio_filebuf {
private:
	const char* const pre_;
	const char* const post_;

public:
	colored_stdio_filebuf(FILE* fp, const char* pre, const char* post) : stdio_filebuf(fp, std::ios_base::out), pre_(pre), post_(post)
	{
	}

protected:
	std::streamsize xsputn(const char* s, std::streamsize count) override
	{
		stdio_filebuf::xsputn(pre_, strlen(pre_));
		auto ret = stdio_filebuf::xsputn(s, count);
		stdio_filebuf::xsputn(post_, strlen(post_));
		return ret;
	}
};
#endif

int main()
{
#ifdef USE_COLORED
	if (getenv("DEBUG")) {
		std::cout.rdbuf(new colored_stdio_filebuf(stdout, stdout_pre, stdxxx_post));
		std::cerr.rdbuf(new colored_stdio_filebuf(stderr, stderr_pre, stdxxx_post));
	} else
#endif
	{
		int fd = open("/dev/null", O_WRONLY);
		dup2(fd, 2);
		close(fd);
	}
	
	int H, W;
	std::vector<std::string> S;
	std::cin >> H >> W;
	S.resize(H);
	for (auto& s : S) {
		std::cin >> s;
	}

	int result = 0;
	for (int x = 0; x < W; ++x) {
		for (int y = 0; y < H; ++y) {
			if (S[y][x] != '.')
				continue;
			auto T = S;
			std::queue<std::tuple<int, int, int>> q; /* x, y, dist */
			T[y][x] = '#';
			q.push(std::tuple<int, int, int>{x, y, 0});
			while (!q.empty()) {
				auto pos = q.front();
				q.pop();
				auto curx = std::get<0>(pos);
				auto cury = std::get<1>(pos);
				auto dist = std::get<2>(pos);
				result = std::max(result, dist);
				if (curx > 0 && T[cury][curx-1] == '.') {
					T[cury][curx-1] = '#';
					q.push(std::tuple<int, int, int>{curx-1,cury,dist+1});
				}
				if (curx < W-1 && T[cury][curx+1] == '.') {
					T[cury][curx+1] = '#';
					q.push(std::tuple<int, int, int>{curx+1,cury,dist+1});
				}
				if (cury > 0 && T[cury-1][curx] == '.') {
					T[cury-1][curx] = '#';
					q.push(std::tuple<int, int, int>{curx,cury-1,dist+1});
				}
				if (cury < H-1 && T[cury+1][curx] == '.') {
					T[cury+1][curx] = '#';
					q.push(std::tuple<int, int, int>{curx,cury+1,dist+1});
				}
			}
		}
	}
	std::cout << result << "\n";
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,a,n) for(int i=a;i<n;i++)
#define repb(i,a,b) for(int i=a;i>=b;i--)
#define all(a) a.begin(),a.end()
#define o(a) cout<<a<<endl
#define int long long
#define fi first
#define se second
using namespace std;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;

string t[10]={
	"* = ****",
	"* =* ***",
	"* =** **",
	"* =*** *",
	"* =**** ",
	" *= ****",
	" *=* ***",
	" *=** **",
	" *=*** *",
	" *=**** "
};

signed main(){
	string s;
	bool f=false;
	while(cin>>s){
		if(f) cout<<endl;
		else f=true;
		string ans[6];
		while(s.size()<5) s='0'+s;
		rep(i,0,s.size()) ans[i]=t[s[i]-'0'];
		rep(i,0,8){
			rep(j,0,5){
				cout<<ans[j][i];
			}
			cout<<endl;
		}
	}
}

Measured memory_bytes: 1184
w, h, n = map(int, input().split())
num_w = 0
num_h = 0

for i in range(n):
  x, y, a = map(int, input().split())
  if a == 1:
    if num_w < x:
      num_w = x
  elif a == 2:
    if w > x:
      w = x
  elif a == 3:
    if num_h < y:
      num_h = y
  else:
    if h > y:
      h = y
      
cnt_w = w-num_w
cnt_h = h-num_h

if cnt_w < 0 or cnt_h < 0:
  print(0)
else:
  print(cnt_w*cnt_h)

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

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)n; ++i)
#define FOR(i, a, b) for (int i = a; i < (int)b; ++i)
#define rrep(i, n) for (int i = ((int)n - 1); i >= 0; --i)

typedef long long ll;
typedef long double ld;

const ll INF = 1e18;
const int Inf = 1e9;
const double EPS = 1e-9;
const int MOD = 1e9 + 7;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(0);
    string s;
    ll k;
    cin >> s >> k;
    ll l = min((ll)s.size(), k);
    rep (i, l) {
        if (s[i] != '1') {
            cout << s[i] << endl;
            return 0;
        }
    }
    cout << 1 << endl;

    return 0;
}



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

int main(){
    int N;
    cin >> N;
    int a[N+10];
    for (int i = 0; i < N; ++i) cin >> a[i];
    sort(a, a + N);
    int dist = a[N-1] - a[0];
    cout << dist << endl;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
using P	  = pair<ll, ll>;
using mat = vector<vector<ll>>;
typedef string::const_iterator State;
class ParseError {};

void IOS() { ios::sync_with_stdio(false), cin.tie(0); }

constexpr ll INF = 1e16;
constexpr ll INM = 114514;
constexpr ll MOD = 1e9 + 7;
constexpr ld EPS = 1e-12;

template <typename T>
void dump(T x) { cout << x << endl; }
void dumpf(ld x, int t) { cout << setprecision(t) << fixed << x << endl; }
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {
	fill((T *)array, (T *)(array + N), val);
}
inline ll mod(ll a, ll b) {
	if (a > 0) return a % b;
	if (a % b == 0) return 0;
	ll x = -a / b + 1;
	a += x * b;
	return a % b;
}
ll powm(ll a, ll b, ll c) {
	if (b == 0)
		return 1;
	else if (b % 2 == 0) {
		ll d = powm(a, b / 2, c);
		return (d * d) % c;
	} else
		return (a * powm(a, b - 1, c)) % c;
}
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
ll dx[4] = {1, 0, -1, 0};
ll dy[4] = {0, 1, 0, -1};

int main() {
	IOS();
	int n;
	cin >> n;
	vector<P> a(n);
	for (int i = 1; i <= n; i++) {
		int x;
		cin >> x;
		a[i - 1] = make_pair(x, i);
	}
	sort(a.begin(), a.end());
	for (int i = 0; i < n; i++) {
		if (i) cout << " ";
		cout << a[i].second;
	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 2432
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <string>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int mod = 1000000007;

int main() {
    ios::sync_with_stdio(false);
    string s;
    ll p[100005] = {1}, a = 0, b = 0, c[100005] = {}, d[100005] = {}, z = 0;
    for (int i = 1; i <= 100002; i++) p[i] = p[i - 1] * 3 % mod;
    cin >> s; s = 'X' + s;
    for (int i = (int)s.length() - 1; i; i--) c[i] = c[i + 1] + (s[i] == 'C'), d[i] = d[i + 1] + (s[i] == '?');
    for (int i = 1; i < s.length(); i++) {
        if (s[i] == 'B' || s[i] == '?') {
            z = (z + (p[b] * a + (b ? p[b - 1] : 0) * b) % mod * ((p[d[i + 1]] * c[i + 1] + (d[i + 1] ? p[d[i + 1] - 1] : 0) * d[i + 1]) % mod)) % mod;
        }
        if (s[i] == 'A') a++;
        if (s[i] == '?') b++;
    }
    cout << z;
}


Measured memory_bytes: 2896
import sys
sys.setrecursionlimit(10**7)
from collections import Counter
class UnionFind():
    def __init__(self,n):
        self.n = n
        self.parents = [-1]*n

    def find(self,x):
        if self.parents[x]<0:
            return x
        else:
            self.parents[x]=self.find(self.parents[x])
            return self.parents[x]
    
    def union(self,x,y):
        x = self.find(x)
        y = self.find(y)
        if x==y:
            return
        if self.parents[x]>self.parents[y]:
            x,y=y,x
        self.parents[x]+=self.parents[y]
        self.parents[y]=x
    #木の深さじゃなくxを含む集合の要素数
    def size(self,x):
        return -self.parents[self.find(x)]

    def same(self,x,y):
        return self.find(x)==self.find(y)

    def members(self,x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i)==root]

    def roots(self):
        return [i for i,x in enumerate(self.parents) if x>0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())
n,k,l=map(int,input().split())
load=UnionFind(n+1)
tetsu=UnionFind(n+1)
for _ in range(k):
    p,q=map(int,input().split())
    load.union(p,q)
for _ in range(l):
    r,s = map(int,input().split())
    tetsu.union(r,s)

count = [(load.find(i),tetsu.find(i)) for i in range(1,n+1)]
# print(count)
C = Counter(count)
ans = []
for i in range(n):
	if count[i][0]<0 or count[i][1]<0:
		ans.append(0)
	else:
		ans.append(C[count[i]])
print(*ans)

Measured memory_bytes: 44392
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
   int n;
   int a,b;
   bool res=false;
   cin>>n;
   vector<pair<int,int> > v;
    for(int i=0; i<n; i++) {
        cin>>a>>b;
        v.push_back({a,b});
    }
    int c=1;
    for(int i=0; i<v.size()-1; i++) {
        if(v[i].first==v[i].second && v[i+1].first==v[i+1].second) {
             c++;
             if(c==3) {
                 res=true;
                 break;
             }
        }else {
            if(c==3) {
                res=true;
                break;
            }
            
            c=1;
        }
    }
    if(res) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
   
   return 0;
}

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

bool win(int low, int high, int player, auto card) {
  if(card[player].empty()) return true;
  bool pass = true;
  if(card[player].count(low-1)) {
    pass = false;
    card[player].erase(low-1);
    if(!win(low-1, high, !player, card)) return true;
    card[player].insert(low-1);
  }
  if(card[player].count(high+1)) {
    pass = false;
    card[player].erase(high+1);
    if(!win(low, high+1, !player, card)) return true;
    card[player].insert(high+1);
  }
  if(pass) return !win(low, high, !player, card);
  return false;
}

int main() {
  int N;
  cin >> N;
  for(auto i = 0; i < N; ++i) {
    vector<set<int>> card(2);
    for(auto j = 1; j <= 13; ++j) if(j != 7) card[1].insert(j);
    for(auto j = 0; j < 6; ++j) {
      int f;
      cin >> f;
      card[0].insert(f);
      card[1].erase(f);
    }
    cout << (win(7, 7, 0, card) ? "yes" : "no") << endl;
  }
}

Measured memory_bytes: 3104
# N = input()
operand = []
for x in raw_input().split():
  if x.isdigit():
    operand.append(int(x))
  else:
    a1 = operand[len(operand)-1]
    operand.pop()
    a2 = operand[len(operand)-1]
    operand.pop()
    if  x == '+' :
      operand.append(a2 + a1)
    elif  x == '-':
      operand.append(a2 - a1)
    elif  x == '*':
      operand.append(a2 * a1)


print operand[0]
  

Measured memory_bytes: 6244
#include <iostream>
#include <iomanip>
#include <cmath>

using namespace std;

int main()
{
  double a, b, c;
  cin >> a >> b >> c;
  c *= M_PI / 180.0;
  double sinC = sin(c);
  double cosC = cos(c);
  double S = 0.5 * a * b * sinC;
  double L = a + b + sqrt(a * a + b * b - 2 * a * b * cosC);
  double h = b * sinC;
  cout << fixed << setprecision(10) << S << endl;
  cout << L << endl;
  cout << h << endl;
  return 0;
}

Measured memory_bytes: 3484
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;

public class Solution
{
    public static void Main()
    {
        var N = int.Parse(Console.ReadLine()) + 1;
        var A = Console.ReadLine().Split(' ').Select(long.Parse).ToArray();

        if (N == 0 && A[0] == 0)
        {
            Console.WriteLine(-1);
            return;
        }

        var max = new long[N + 1];
        max[N] = 0;
        for (int i = N - 1; i >= 0; i--)
        {
            max[i] = max[i + 1] + A[i];
        }

        long count = 0;
        long cur = 1;
        for (int i = 0; i < N; i++)
        {
            if (cur < A[i])
            {
                Console.WriteLine(-1);
                return;
            }

            count += cur;
            var next = Math.Min(max[i + 1], (cur - A[i]) * 2);
            cur = next;
        }

        Console.WriteLine(count);
    }
}

Measured memory_bytes: 38248
import java.util.Scanner;

public class Main {
	public static void main(String[]args) {
		Scanner sc = new Scanner(System.in);
		String b = sc.next();

		if (b.equals("A")) {
			System.out.println("T");
		} else if (b.equals("C")) {
			System.out.println("G");
		} else if (b.equals("G")) {
			System.out.println("C");
		} else {
			System.out.println("A");
		}
	}

}


Measured memory_bytes: 21204
#include<iostream>
#include<algorithm>

using namespace std;
typedef long long Int;

Int dp[105][25], n, ans, num[105];

int main(){
 cin >> n;
 for(int i = 0;i < n - 1;i++)cin >> num[i];
 cin >> ans;
 dp[0][num[0]] = 1;
 for(int i = 1;i < n - 1;i++){
  for(int j = 0;j <= 20;j++){
   if(j - num[i] >= 0)dp[i][j] += dp[i - 1][j - num[i]];
   if(j + num[i] <= 20)dp[i][j] += dp[i - 1][j + num[i]];
  }
 }
 cout << dp[n - 2][ans] << endl;
 return 0;
}

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

const int mod = 1e9 + 7;
const long long INF = 1LL<<60;
//using ll = long long;
//using P = pair<int,int>;

int n;
int M[110][110];
int visited[110];
vector<int> d(110, 0);
vector<int> f(110, 0);
int t;

void dfs(int v){
    
    t++;
    d[v] += t;
    visited[v] = 1;
    
    for (int i = 0; i < n; i++){
        if (M[v][i] == 0) continue;
        
        if(visited[i] == 0) dfs(i);
    }
    
    visited[v] = 2;
    t++;
    f[v] += t;
}

int main(){
    cin >> n;
    t = 0;
    
    for (int i = 0; i < n; i++){
        for (int j = 0; j < n; j++) M[i][j] = 0;
        visited[i] = 0;
    }
    
    for (int i = 0; i < n; i++){
        int u;
        cin >> u;
        u--;
        
        int k;
        cin >> k;
        
        for (int j = 0; j < k; j++){
            int v;
            cin >> v;
            v--;
            
            M[u][v]++;
        }
    }
    
    for (int i = 0; i < n; i++){
        if (visited[i] == 0) dfs(i);
    }
    
    for (int i = 0; i < n; i++){
        cout << i+1 << " " << d[i] << " " << f[i] << endl;
    }
    
    
}


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

int main() {
    int N, K;
    double p;
    double maxE = 0;
    cin>>N>>K;
    vector<double> E(N+1, 0);
    REP(i, 0, N){
        cin>>p;
        E[i+1] = (p+1)/2 + E[i];
    }
    REP(i, 0, N-K+1){
        if(maxE < (E[i+K]-E[i])){
            maxE = E[i+K]-E[i];
        }
    }
    cout.precision(12);
    cout << maxE << endl;
    return 0;   
}

Measured memory_bytes: 1792
import java.util.Scanner;
public class Main{
  public static void main(String[] args){
    Scanner s = new Scanner(System.in);
    int n = s.nextInt();
    int x = s.nextInt();
    for(int i = 0; i < x; i++){
      n = n - s.nextInt();
    }
    if(n < 0){
      System.out.println(-1);
    } else {
    System.out.println(n);
    }
  }
}

Measured memory_bytes: 46276
program sample
	character(len=1) :: a
    
    read(*,*) a
    
    if (a=='S') then
    	write(*,*) 'Cloudy'
    else if (a=='C') then
    	write(*,*) 'Rainy'
    else
    	write(*,*) 'Sunny'
    end if
    stop
end program sample

Measured memory_bytes: 2652
input1=list(map(int,input().split()))
input2=list(map(int, input().split()))

distance=[]
for order,value in enumerate(input2):
    if order==0:
        pass
    else:
        distance.append(value-input2[order-1])
distance.append(input1[0]-sum(distance))

print(input1[0]-max(distance))

Measured memory_bytes: 25804
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
vector<pair<int,int> > g[400010];
int a[200010],w[200010],cnt[20],p[1000010],x,y,z,n,ans;
bool vis[1000010];
void dfs(int p,int fa)
{
	for(auto i:g[p])if(i.first!=fa)a[i.first]=i.second,dfs(i.first,p);
	for(auto i:g[p])if(i.first!=fa)w[p]^=w[i.first];
	a[p]^=w[p];w[p]^=a[p];
}
int main()
{
	scanf("%d",&n);
	for(int i=1;i<n;i++)scanf("%d%d%d",&x,&y,&z),x++,y++,g[x].pb({y,z}),g[y].pb({x,z});
	dfs(1,0);
	for(int i=1;i<=n;i++)++cnt[a[i]];
	for(int i=1;i<16;i++)ans+=cnt[i]/2,cnt[i]&=1;
	for(int i=1;i<16;i++)if(cnt[i])++ans;
	for(int i=1;i<(1<<16);i++)p[i]=-100;
	for(int i=0;i<(1<<15);i++)
	{
		int tp=i,ts=1,now=0;
		for(;tp;tp>>=1,++ts)if(tp&1)now^=ts;
		vis[i]=!now;
	}
	for(int i=1;i<(1<<15);i++)
	if(vis[i])
	{
		p[i]=1;
		for(int j=i;j;j=(j-1)&i)if(vis[j])p[i]=max(p[i],p[j]+p[i^j]);
	}
	int tp=0;
	for(int i=15;i;i--)tp=(tp<<1)|cnt[i];
	printf("%d\n",ans-p[tp]);
	return 0;
}

Measured memory_bytes: 22912
#include<bits/stdc++.h>
#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long
#define vi vector<ll>
#define vvi vector<vi>
#define BITLE(n) (1LL<<((ll)n))
#define SUBS(s,f,t) ((s).substr((f),(t)-(f)))
#define ALL(a) (a).begin(),(a).end()
#define Max(a) (*max_element(ALL(a)))
#define Min(a) (*min_element(ALL(a)))
using namespace std;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll keta = 0;
  ll sum = 1;
  ll plus = 26;
  ll n;cin>>n;
  while(sum<= n){
    sum += plus;
    plus = plus*26;
    keta++;
  }
  sum-=plus/26;
  plus/=26*26;
  string ans = "";
  n-=sum;
  for(int i=0;i<keta;i++){
    ll ho = n/plus;
    n%=plus;
    plus/=26; 
    ans.pb(('a'+ho));
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 3644
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#include <ctype.h>
#include <stdlib.h>
using namespace std;

int main(){
    int A;
    int B;
    cin >> A >> B;

    int ans = A - B * 2;
    if(ans < 0){
        cout << "0" << endl;
    }else{
        cout << ans << endl;
    }
}

Measured memory_bytes: 256
// #pragma GCC optimize("O3", "unroll-loops")
// #pragma GCC target("avx2")

#include <bits/stdc++.h>
using namespace std;

typedef long long int ll;

#define endl '\n'
#define int long long
#define pb push_back
#define pii pair <int, int>
#define ff first
#define ss second
#define point pair <double, double>
#define watch(x) cerr << "\n" << (#x) << " is " << (x) << endl

void __print(int x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "\n[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif

const int mod = 1e9 + 7;
//const int mod = 998244353;

void solve(){
  int n, d, ans = 0, x, y, a, done = 0;
  cin >> n >> d >> a;
  vector <pii> v;
  set <pii> bombed;
  
  for(int i = 1; i <= n; i++){
     cin >> x >> y;
     v.pb({x,y});
  }
  sort(v.begin(), v.end());
  for(auto i : v){
     x = i.ff;
     y = i.ss;
     while(1){
        auto it = bombed.begin();
        if(it == bombed.end()) break;
        if((*it).ff >= x)break;
        done-=((*it).ss);
        bombed.erase(it); 
     }
     y-=(a*done);
     if(y > 0){
        int req = y/a + (y%a != 0);
        ans += req;
        bombed.insert({x+2*d, req});
        done+=req;
     }
  }
  cout << ans << '\n';
}

signed main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
        clock_t t1 = clock();
  int t = 1; //cin >> t;
  while(t--){      
     solve();
  }
        clock_t t2 = clock();
  //cout << "Time-Taken: " << ((t2 - t1) / (double)CLOCKS_PER_SEC) << endl;      
}


Measured memory_bytes: 9580
import java.util.*;

public class Main{
    public static void main(String[] args) {
      Scanner sc = new Scanner(System.in);
      int W=sc.nextInt();
      int H=sc.nextInt();
      int x=sc.nextInt();
      int y=sc.nextInt();

      int cnt=0;

      double S=(double)W*H/2;

      if(x*2==W && y*2==H){
        cnt=1;
      }

      System.out.println(S+" "+cnt);

    }
}


Measured memory_bytes: 21716
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
using pint = pair<int, int>;
using vi = vector<int>;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()

template<typename T> T gcd(T a, T b) { return b ? gcd(b, a%b) : a; }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
template<class T> void corner(bool flg, T hoge) { if (flg) { cout << hoge << endl; exit(0); } }

const int MOD = 1000000007;
const int INF = 1 << 30;

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

    rep(i, N) B[i] = A[i] - 1 - i;

    sort(all(B));

    int b;
    if (N % 2) b = B[N/2];
    else b = (B[(N-1)/2] + B[N/2]) / 2;

    lint res = 0;

    rep(i, N) {
        res += abs(A[i] - (b + 1 + i));
    }
    
    cout << res << endl;
    return 0;
}


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

int N;

int main(){
    cin>>N;
    double sum=0,a;
    for(int i=0;i<N;i++){
        cin>>a;
        sum+=1.0/a;
    }
    sum=1.0/sum;
    cout<<sum<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <math.h>
#define rep(i,l,n) for(i=l;i<n;i++)

int main(void){
	int flag,a[105],i,j,k,n,c;
	
	scanf("%d",&n);
	rep(i,0,n) scanf("%d",&a[i]);
	
	k=0;
	flag=1;
	while(flag){
		flag=0;
		for(j=n-1;j>0;j--){
			if(a[j]<a[j-1]){
				c=a[j-1];
				a[j-1]=a[j];
				a[j]=c;
				flag=1;
				k++;
			}
		}
	}
	rep(i,0,n-1) printf("%d ",a[i]);
	printf("%d\n",a[n-1]);
	printf("%d\n",k);
	return 0;
}

Measured memory_bytes: 600
#include <bits/stdc++.h>
using namespace std;
 
int main() {
string a,b;
int c,d;
string less;
  cin >> a >> b;
  cin >>c >> d;
  cin >> less;
  if( a == less) 
     c-=1;
  if( b == less)
    d-=1;
    cout << c <<" "<< d <<endl;
}

Measured memory_bytes: 256
import math
a,b,h,m = [int(x) for x in input().split()]

choshin = m*6
tanshin = (30*h) + m/2
d = abs(choshin-tanshin)
c = a**2 + b**2 -2*a*b*math.cos(math.radians(d))
print(math.sqrt(c))

Measured memory_bytes: 9428
#include<iostream>
#include<math.h>
using namespace std;
int main()
{
  long long int a,c,i;
  cin>>a;
  for(i=sqrt(a);i>=1;i--)
  {
    if(a%i==0)
    {
      c=i+(a/i)-2;
      cout<<c;
      break;
    }
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define IO ios_base::sync_with_stdio(false); cin.tie(NULL);

#define endl '\n'
#define D(x) cout << #x << " = " << (x) << endl;

string s, t;
vector<vector<int>> dp, path;

int f(int i, int j) {
  if (i < 0 or j < 0) {
    return 0;
  }

  if (dp[i][j] == -1) {
    if (s[i] == t[j]) {
      dp[i][j] = 1 + f(i - 1, j - 1);
      path[i][j] = 0;
    } else {
      int a = f(i - 1, j);
      int b = f(i, j - 1);

      if (a >= b) {
        dp[i][j] = a;
        path[i][j] = 1;
      } else {
        dp[i][j] = b;
        path[i][j] = 2;
      }
    }
  }

  return dp[i][j];
}


int main() { IO;
  cin >> s >> t;

  const int n = s.size();
  const int m = t.size();

  dp.resize(n);
  for (auto &v : dp) {
    v.resize(m);
    fill(v.begin(), v.end(), -1);
  }

  path = dp;

  f(n - 1, m - 1);

  string ans;
  int i = n - 1, j = m - 1;

  while (i >= 0 and j >= 0) {
    if (path[i][j] == 0) {
      ans += s[i];
      i -= 1;
      j -= 1;
    } else if (path[i][j] == 1) {
      i -= 1;
    } else if (path[i][j] == 2) {
      j -= 1;
    } else {
      assert(true);
    }
  }

  reverse(ans.begin(), ans.end());
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 71168
N,M = map(int,input().split())
intervals = []
for _ in range(M):
    a,b = map(int,input().split())
    intervals.append([a,b])
intervals.sort()
ans = [intervals[0]]
for i in range(len(intervals)):
    if ans[-1][1]>intervals[i][0]:
        if ans[-1][1]>intervals[i][1]:
            ans[-1][1]=intervals[i][1]
        ans[-1][0] = intervals[i][0]
    else:
        ans.append(intervals[i])
print(len(ans))

Measured memory_bytes: 20068
#include <iostream>
#include <string>
#include <cctype>
#include <cassert>

using namespace std;

string S;
size_t cur = 0;
int N;
int parse();

char readchar(){
    assert(cur < S.size());
    return S[cur++];
}

char peek(){
    //assert(cur < S.size());
    return S[cur];
}

int digit(){
    assert(isdigit(peek())); 
    int n = readchar() - '0';
    return n;
}

int number(){
    int n = digit();
    while (cur < S.size() && isdigit(peek())) {
        n = n*10 + digit();
    }
    return n;
}


int expression();

int factor(){
    if (peek() != '(') return number();
    cur += 1;
    int n = expression();
    assert(peek() == ')');
    cur += 1;
    return n;
}

int term() {
    int a = factor();
    while (cur < S.size() && (peek() == '*' || peek() == '/')){
        char op = readchar();
        int b = factor();
        if (op == '*') a *= b; else a /= b;
    }
    return a;
}

int expression(){
    int a = term();
    while (cur < S.size() && (peek() == '+' || peek() == '-')){
        char op = readchar();
        int b = term();
        if (op == '+') a += b; else a -= b;
    }
    return a;
}

int parse() { return expression(); }


int main(){
    cin >> N;
    for(int i = 0; i < N; i++){
        cin >> S;
        cur = 0;
        int a = parse();
        cout << a << endl;
    }
}

Measured memory_bytes: 3172
from math import factorial

N, K = [int(_) for _ in input().split()]
# N = 10
MOD = 10 ** 9 + 7

kaijo = [0] * (N + 1)
kaijo[0] = kaijo[1] = 1
for i in range(2, N + 1):
    kaijo[i] = (kaijo[i - 1] * i) % MOD

gyaku = [0] * (N + 1)
gyaku[0] = gyaku[1] = 1

for i in range(2, N + 1):
    # gyaku[i] = (gyaku[i - 1] * pow(i, MOD - 2, MOD)) % MOD
    gyaku[i] = pow(kaijo[i], MOD - 2, MOD)


def calc(n, k):
    return (kaijo[n] * gyaku[n - k] * gyaku[k]) % MOD
    # return factorial(n) // (factorial(n - k) * factorial(k))


def solve():
    for i in range(1, K + 1):
        n = N - K + 1
        k = i
        if k <= n:
            print((calc(n, k) * calc(K - 1, i - 1)) % MOD)
        else:
            print(0)


solve()


Measured memory_bytes: 3444
//
//  ROIGold.cpp
//  Main calisma
//
//  Created by Rakhman on 05/02/2019.
//  Copyright © 2019 Rakhman. All rights reserved.
//

#include <cstring>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <queue>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cassert>
#include <iterator>
#include<unordered_map>

#define ios ios_base::sync_with_stdio(0), cin.tie(0);
#define S second
#define F first
#define pb push_back
#define nl '\n'
#define NL cout << '\n';
#define EX exit(0)
#define all(s) s.begin(), s.end()
#define FOR(i, start, finish, k) for(llong i = start; i <= finish; i += k)

const long long MXN = 1e6 + 100;
const long long MNN = 4444;
const long long MOD = 1e9 + 7;
const long long INF = 1e9;
const long long OO = 1e9 + 1;
const double pi = acos(-1.0);

typedef long long llong;
typedef unsigned long long ullong;

using namespace std;

llong n, b[MXN], sum, mx;

int last[MXN];
int dp[MXN];

int main(){
    ios;
    cin >> n;
    for(int i = 1; i <= n; i++){
        cin >> b[i];
    }
    dp[0] = 1;
    for(int i = 1; i <= n; i++){
        dp[i] = dp[i - 1];
        if(last[b[i]] && last[b[i]] != i - 1) dp[i] = (dp[i] + dp[last[b[i]]]) % MOD;
        last[b[i]] = i;
    }
    cout << dp[n];
    return 0;
}
/*
 
 1 1 - 1
 2 1 - 1
 3 1 - 1
 4 1 - 1
 5 1 - 1
 6 1 - 1
 7 1 - 1
 
 1 2 - 0
 2 2 - 1
 3 2 - 2
 4 2 - 3
 5 2 - 4
 6 2 - 5
 7 2 - 6
 
 1 3 - 1
 2 3 - 1
 3 3 - 1
 4 3 - 3
 5 3 - 6
 6 3 - 10
 7 3 - 15
 8 3 - 21
 9 3 - 28
 10 3 - 36
 
 1 4 - 1
 2 4 - 1
 3 4 - 1
 4 4 - 1
 5 4 - 4
 6 4 - 10
 7 4 - 20
 8 4 - 35
 9 4 - 56
 10 4 - 84
 
 1 5 - 1
 2 5 - 1
 3 5 - 1
 4 5 - 1
 5 5 - 1
 5 5 - 1
 6 5 - 5
 7 5 - 15
 8 5 - 35
 9 5 - 70
 10 5 - 126
 */


Measured memory_bytes: 9216
s=Array.new(1200,0)
n=gets.to_i
n.times do
  b,f,r,v=gets.split.map(&:to_i)
  s[(b-1)*30+(f-1)*10+(r-1)]+=v
end
for b in 0..3
  for f in 0..2
    msg=''
    for r in 0..9
      msg+=' '+s[b*30+f*10+r].to_s
    end
    puts msg
  end
  puts '####################' if b<3
end



Measured memory_bytes: 8924
import java.io.*;
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        PrintWriter out = new PrintWriter(System.out);
        
        final int A = Integer.parseInt(sc.next());
        final int B = Integer.parseInt(sc.next());
        String[] ss = sc.next().split("-");
        
        if (ss.length == 2
                && ss[0].length() == A
                && ss[0].matches("[0-9]+")
                && ss[1].length() == B
                && ss[1].matches("[0-9]+")) {
            out.println("Yes");
        } else {
            out.println("No");
        }
        
        out.flush();
    }
}

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

int main()
{
    char s[4];
    int cout = 0, max = 0;

    scanf("%s", s);

    for (int i = 0; i < 3; i++) {
        if (s[i] == 'R') {
            cout++;
            if (cout > max) {
                max = cout;
            }
        } else if (s[i] == 'S') {
            cout = 0;
        }
    }
    
    
    printf("%d\n", max);
    

    return 0;
}

Measured memory_bytes: 3720
import sys
a=int(input())
b=int(input())
c=int(input())
x=int(input())

#とりあえずコーナケース
if 500*a+100*b+50*c<x:
    print(0)
    sys.exit()
elif 500*a+100*b+50*c==x:
    print(1)
    sys.exit()
elif c==0 and x%100!=0:
    print(0)
    sys.exit()
elif b==0 and c==0 and x%500!=0:
    print(0)
    sys.exit()

#3重ループする
ans=0
for i in range(a+1):
    for j in range(b+1):
        for k in range(c+1):
            if 500*i+100*j+50*k==x:
                ans+=1

print(ans)
       

Measured memory_bytes: 3064
def main():
    S = input()

    word_list = ['dream', 'dreamer', 'erase', 'eraser']

    while len(S) > 0:
        for word in word_list:
            flag = "NO"
            if S[len(S) - len(word):] == word:
                S = S[:len(S) - len(word)]
                flag = "YES"
                break

        if flag == "NO":
            break
    print(flag)

main()

Measured memory_bytes: 3188
#[allow(unused_macros)]
macro_rules! input {
    ( source = $ s : expr , $ ( $ r : tt ) * ) => { let mut iter = $ s . split_whitespace ( ) ; let mut next = || { iter . next ( ) . unwrap ( ) } ; input_inner ! { next , $ ( $ r ) * } };
    ( $ ( $ r : tt ) * ) => { let stdin = std :: io :: stdin ( ) ; let mut bytes = std :: io :: Read :: bytes ( std :: io :: BufReader :: new ( stdin . lock ( ) ) ) ; let mut next = move || -> String { bytes . by_ref ( ) . map ( | r | r . unwrap ( ) as char ) . skip_while ( | c | c . is_whitespace ( ) ) . take_while ( | c |! c . is_whitespace ( ) ) . collect ( ) } ; input_inner ! { next , $ ( $ r ) * } };
}
#[allow(unused_macros)]
macro_rules! input_inner {
    ( $ next : expr ) => { };
    ( $ next : expr , ) => { };
    ( $ next : expr , $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let $ var = read_value ! ( $ next , $ t ) ; input_inner ! { $ next $ ( $ r ) * } };
}
#[allow(unused_macros)]
macro_rules! read_value {
    ( $ next : expr , ( $ ( $ t : tt ) ,* ) ) => { ( $ ( read_value ! ( $ next , $ t ) ) ,* ) };
    ( $ next : expr , [ $ t : tt ; $ len : expr ] ) => { ( 0 ..$ len ) . map ( | _ | read_value ! ( $ next , $ t ) ) . collect ::< Vec < _ >> ( ) };
    ( $ next : expr , chars ) => { read_value ! ( $ next , String ) . chars ( ) . collect ::< Vec < char >> ( ) };
    ( $ next : expr , usize1 ) => { read_value ! ( $ next , usize ) - 1 };
    ( $ next : expr , $ t : ty ) => { $ next ( ) . parse ::<$ t > ( ) . expect ( "Parse error" ) };
}

fn main() {
    input! {
        a: u64, p: u64
    }
    let p2 = a * 3 + p;
    println!("{}", p2 / 2);
}


Measured memory_bytes: 4352
#include <iostream>
#include <string>

using namespace std;

int main()
{
    string s; cin >> s;
    int a = s[0] - '0';
    int b = s[1] - '0';
    int c = s[2] - '0';
    int d = s[3] - '0';
    char op1, op2, op3;

    if (a + b + c + d == 7) { 
        op1 = op2 = op3 = '+';
    } else if (a + b + c - d == 7) {
        op1 = op2 = '+'; op3 = '-';
    } else if (a + b - c - d == 7) {
        op1 = '+'; op2 = op3 = '-';
    } else if (a - b - c - d == 7) {
        op1 = op2 = op3 = '-';
    } else if (a - b + c - d == 7) {
        op1 = op3 = '-'; op2 = '+';
    } else if (a - b + c + d == 7) {
        op1 = '-'; op2 = op3 = '+';
    } else if (a + b - c + d == 7) {
        op1 = op3 = '+'; op2 = '-';
    } else if (a - b - c + d == 7) {
        op1 = op2 = '-'; op3 = '+';
    }

    cout << a << op1 << b << op2 << c << op3 << d << 
        '=' << 7 << endl;

    return 0;
}

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

int main() {
	ll h1, m1, h2, m2, k;
	cin >> h1 >> m1 >> h2 >> m2 >> k;
	ll ho = (h2 - h1) * 60 + (m2 - m1);
	cout << max(ho - k, 0ll);
}


Measured memory_bytes: 3632
//Suplex
#include <cstdio>
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
int n;
long long f[10000];

struct leo{
    int h,p;
}a[10000];

bool cmp(leo a,leo b)
{
    return a.h+a.p<b.h+b.p;
}

inline long long min(long long a,long long b)
{
    return a<b ? a : b;
}

int main()
{
    scanf("%d",&n);
    for(int i=1;i<=n;i++) scanf("%d%d",&a[i].h,&a[i].p);
    sort(a+1,a+1+n,cmp);
    memset(f,0x3f,sizeof(f));
    f[0]=0;
    for(int i=1;i<=n;i++)
        for(int j=i;j;j--)
            if(f[j-1]<=a[i].h) f[j]=min(f[j],f[j-1]+a[i].p);
    for(int i=n;i;i--) if(f[i]<1e18){printf("%d\n",i);break;}
    return 0;
}

Measured memory_bytes: 384
#include <stdio.h>
#define MAX_V 999999

int prime[MAX_V + 1] = {0};
int sum[MAX_V + 1];

int main() {
	int data[30];
	int i, k, n, cnt = 0;
	sum[0] = 0;
	for(i = 2; i <= MAX_V; i++) {
		prime[i] = 1;
	}
	for(i = 2; i * i <= MAX_V; i++) {
		if(prime[i]) {
			for(k = 2 * i; k <= MAX_V; k += i) {
				prime[k] = 0;
			}
		}
	}
	for(i = 0; i <= MAX_V; i++) {
		sum[i + 1] = sum[i] + prime[i];
	}
	while(scanf("%d", &n) != EOF) {
		data[cnt] = n;
		cnt++;
	}
	for(i = 0; i < cnt; i++) {
		printf("%d\n", sum[data[i] + 1]);
	}
	return 0;
}

Measured memory_bytes: 9596