akhauriyash/Code-Regression huggingface dataset:
#!/usr/bin/python3
# -*- coding: utf-8 -*-
from decimal import *


N = int(input())
nmove_x = [10**9, -10**9] ##[min,max]
nmove_y = [10**9, -10**9] ##[min,max]
move = {"U":[10**9, -10**9], "D":[10**9, -10**9], "R":[10**9, -10**9], "L":[10**9, -10**9]}

for _ in range(N):
  x,y,d = map(str, input().split())
  x,y = [int(x),int(y)]
  if d in "UD":
    move[d] = [min([move[d][0],y]),max([move[d][1],y])]
    nmove_x = [min([nmove_x[0],x]),max([nmove_x[1],x])]
  else:
    move[d] = [min([move[d][0],x]),max([move[d][1],x])]
    nmove_y = [min([nmove_y[0],y]),max([nmove_y[1],y])]


def get_bb(t):
  x_mx = max([move["R"][1]+t,move["L"][1]-t,nmove_x[1]])
  x_mn = min([move["R"][0]+t,move["L"][0]-t,nmove_x[0]])
  y_mx = max([move["U"][1]+t,move["D"][1]-t,nmove_y[1]])
  y_mn = min([move["U"][0]+t,move["D"][0]-t,nmove_y[0]])
  return ((x_mx-x_mn)*(y_mx-y_mn))


## にぶたん！
l,r = [Decimal("0"),Decimal("10000000000")]
for _ in range(500):
  m = Decimal(l+r)/2
  if get_bb(m-Decimal("0.00000001")) < get_bb(m+Decimal("0.00000001")):
    r = m
  else:
    l = m
print(get_bb(m))

Measured memory_bytes: 117976
#include <algorithm>
#include <array>
#include <vector>
#include <iostream>
#include <fstream>
#include <string>
#include <cmath>
#include <functional>
#include <queue>

//AtCoderC++.cpp

using namespace std;

void Show(vector<vector<int>> Ns) {
	for (int i = 0; i < Ns.size(); i++) {
		for (int j = 0; j < Ns[i].size(); j++) {
			cout << Ns[i][j] << endl;
		}
	}
}


int main() {
	int x1, y1, x2, y2;
	cin >> x1 >> y1 >> x2 >> y2;
	int	dx = x2 - x1;
	int dy = y2 - y1;
	int x3 = x2 - dy;
	int y3 = y2 + dx;
	int x4 = x1 - dy;
	int y4 = y1 + dx;
	cout << x3 << " " << y3 << " " << x4 << " " << y4 << endl;
}

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

int main() {
	// freopen("input.txt", "r", stdin);
	// freopen("output.txt", "w", stdout);
	int n, m;
	cin >> n >> m;
	string s[n];
	for(int i = 0; i < n; ++i) {
		cin >> s[i];
	}
	long dp[n][m];
	memset(dp, 0, sizeof dp);
	for(int i = 0; i < n; ++i) {
		for(int j = 0; j < m; ++j) {
			if(s[i][j] == '#') continue;
			if(i == 0) {
				if(j == 0) dp[i][j] = 1;
				else dp[i][j] = dp[i][j - 1];
			}
			else if(j == 0) {
				dp[i][j] = dp[i - 1][j];
			}
			else {
				dp[i][j] = (dp[i - 1][j] + dp[i][j - 1])%(long)1000000007;
			}
		}
	}
	cout<<dp[n - 1][m - 1];
}

Measured memory_bytes: 13360
def main():
	k, *a = map(int, open(0).read().split())
	m = M = 2
	for x in a[::-1]:
		M -= M % x
		if m > M:
			print(-1)
			exit()
		m += -m % x
		M += x - 1
	print(m, M)

if __name__=="__main__":
	main()


Measured memory_bytes: 14092
#include <iostream>
using namespace std;
 
int main()
{
	int N, Y;
	cin >> N >> Y;
 
	int yen = Y;
	int x = yen / 10000; 
	yen -= 10000 * x;
 
	int y = yen / 5000;
	yen -= 5000 * y;
 
	int z = yen / 1000;
	int n = x + y + z;
 
	while ((N - n >= 9) && (x > 0)) {
		x--;
		z += 10;
		n += 9;
	}
 
	while ((N - n >= 4) && (y > 0)) {
		y--;
		z += 5;
		n += 4;
	}
 
	while ((N - n >= 1) && (x > 0)) {
		x--;
		y += 2;
		n++;
	}
 
	if (n == N) cout << x << ' ' << y << ' ' << z << endl;
	else cout << "-1 -1 -1" << endl;
 
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define repi(i,m,n) for(int i = m;i < n;i++)
#define drep(i,n,m) for(int i = n;i >= m;i--)
#define rep(i,n)repi(i,0,n)
#define rrep(i,n) repi(i,1,n+1)
typedef pair<int,int> P;
typedef pair<int, P> PP;
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(), v.rend()
#define fi first
#define se second
const int inf = 1e9;
int mod = 1e9+7;

int dy[] = {-1, 0, 0, 1}, dx[] = {0, -1, 1, 0};
char str[100][100], a[100][100], used[100][100];

class Dijkstra{
public:
	vector<vector<P> > G;
	vector<int> d;
	
	void init(int n){
		d.resize(n);
		G.resize(n);
	}
	void add_edge(int s, int t, int cost){
		G[s].push_back(P(t, cost));
	}
	
	void dijkstra(int s){
		priority_queue<P, vector<P>, greater<P> > q;
		fill(d.begin(), d.end(), inf);
		d[s] = 0;
		q.push(P(0, s));
		
		while(!q.empty()){
			P p = q.top();q.pop();
			int v = p.second;
			if(d[p.second] < p.first)continue;
			
			for(int i = 0;i < G[v].size();i++){
				int to = G[v][i].first;
				int cost = G[v][i].second;
				
				if(d[to] > d[v]+cost){
					d[to] = d[v]+cost;
					q.push(P(d[to], to));
				}
			}
		}
	}
};

Dijkstra d;
void dfs(int y, int x, char c){
	if(a[y][x] == '#' || a[y][x] == '.')return ;
	if(c != a[y][x] && 'A' <= a[y][x] && a[y][x] <= 'Z'){
		d.add_edge(c-'A', a[y][x]-'A', 1);
		d.add_edge(a[y][x]-'A', c-'A', 1);
		c = a[y][x];
	}
	if(used[y][x])return ;
	used[y][x] = 1;
	rep(i,4){
		int yy = y+dy[i],xx = x+dx[i];
		if(a[y][x] == 'o' && !dy[i] && a[yy][xx] == '|')continue;
		if(a[y][x] == 'o' && !dx[i] && a[yy][xx] == '-')continue;
		if(a[y][x] == '|' && !dy[i])continue;
		if(a[y][x] == '-' && !dx[i])continue;
		dfs(y+dy[i],x+dx[i], c);
	}
}

signed main(){
	d.init(100);
	int h, w;
	char s, t;
	fill((char*)a, (char*)(a+100), '#');
	scanf("%lld%lld",&h, &w);
	scanf(" %c %c", &s, &t);
	rep(i,h)scanf("%s", str[i]);
	rrep(i,h)rrep(j,w)a[i][j] = str[i-1][j-1];
	
	rrep(y,h)rrep(x,w){
		if('A' <= a[y][x] && a[y][x] <= 'Z' && used[y][x] == 0){
			repi(i,-1,2)repi(j,-1,2){
				int yy = y+i, xx = x+j;
				//a[yy][xx] = a[y][x];
				used[yy][xx] = 1;
				if(i*j == -1 || i*j == 1)a[yy][xx] = '.';
			}
		}
	}
	
	rrep(i,h)rrep(j,w){
		fill((int*)used, (int*)(used+100), 0);
		if('A' <= a[i][j] && a[i][j] <= 'Z' && used[i][j] == 0){
			dfs(i, j, a[i][j]);
			//printf("*%c\n", a[i][j]);
		}
	}
	d.dijkstra(s-'A');
	printf("%lld\n", d.d[t-'A']);
	/*int x = 'B'-'A';
	rep(i,d.G[x].size()){
		int y = d.G[x][i].fi;
	}*/
	/*rrep(i,h){
		rrep(j,w)printf("%c", a[i][j]);
		printf("\n");
	}*/
	return 0;
}



Measured memory_bytes: 3292
#include <iostream>
#include <string>
using namespace std;
int main(void){
    int x,a,b;
    cin>>x>>a>>b;
    if(x-a<0){
        a=(x-a)*-1;
    }else{
        a=x-a;
    }
    if(x-b<0){
        b=(x-b)*-1;
    }else{
        b=x-b;
    }
    if(a<b){
        cout<<"A"<<endl;
    }else{
        cout<<"B"<<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);
    int n = sc.nextInt();
    int x = sc.nextInt();
    int lastA = sc.nextInt();
    long count = 0;
    for (int i = 1; i < n; i++) {
      int a = sc.nextInt();
      if (lastA + a <= x) {
        lastA = a;
        continue;
      }
      count += lastA + a - x;
      lastA = x - lastA;
      if (lastA < 0) {
        lastA = 0;
      }
    }
    sc.close();

    System.out.println(count);
  }
}

Measured memory_bytes: 50236
#include<bits/stdc++.h>
using namespace std;
const int maxn = 1505;
struct lpl{int x[5];}ini[maxn];
int n, c[5];
map<lpl, long long> mp;
long long ans;

inline bool operator < (lpl A, lpl B){
	if(A.x[1] == B.x[1]){
		if(A.x[2] == B.x[2]){
			if(A.x[3] == B.x[3]) return A.x[4] < B.x[4];
			else return A.x[3] < B.x[3];	
		}
		else return A.x[2] < B.x[2];	
	}
	else return A.x[1] < B.x[1];
}

inline lpl move(lpl A){
	lpl ret;
	ret.x[1] = A.x[2];
	ret.x[2] = A.x[3];
	ret.x[3] = A.x[4];
	ret.x[4] = A.x[1];
	return ret;
}

inline void ins(lpl A, long long val){
	for(int i = 1; i <= 4; ++i){
		A = move(A); mp[A] += val; 
	}
}

inline void putit(){
	scanf("%d", &n);  lpl lin;
	for(int i = 1; i <= n; ++i){
		for(int j = 1; j <= 4; ++j) scanf("%d", &ini[i].x[j]); 
		ins(ini[i], 1);
	}
}

inline void calc(int a, int b){
	lpl A = ini[a], B = ini[b];
	for(int p = 1; p <= 4; ++p){
		B = move(B);
		lpl up, down, qian, hou;
		up.x[1] = A.x[2]; up.x[2] = A.x[1]; up.x[3] = B.x[1]; up.x[4] = B.x[4];
		down.x[1] = A.x[3]; down.x[2] = A.x[2]; down.x[3] = B.x[4]; down.x[4] = B.x[3];
		qian.x[1] = A.x[4]; qian.x[2] = A.x[3]; qian.x[3] = B.x[3]; qian.x[4] = B.x[2];
		hou.x[1] = A.x[1]; hou.x[2] = A.x[4]; hou.x[3] = B.x[2]; hou.x[4] = B.x[1];		
		if(!mp[up] || !mp[down] || !mp[qian] || !mp[hou]) continue;
		long long ret = 1;
		ret *= mp[up]; ins(up, -1);
		ret *= mp[down]; ins(down, -1);
		ret *= mp[qian]; ins(qian, -1);
		ret *= mp[hou]; ans += ret;
		ins(up, 1); ins(down, 1); ins(qian, 1);
	}
}

inline void workk(){
	for(int i = 1; i <= n; ++i){
		ins(ini[i], -1);
		for(int j = i + 1; j <= n; ++j){
			ins(ini[j], -1); calc(i, j); ins(ini[j], 1);
		}
		ins(ini[i], 1);
	}
	cout << ans / 3;
}

int main()
{
	putit();
	workk();
	return 0;
}

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

int main()
{
    int a,b,c,d,e,f,g;
    cin >> a;
    cin>> b;
    cin >> c;
    d=(a-b);
    e=(d/c);
    f=(e*c);
    g=(d-f);
    cout << g<< endl;
    return 0;
}

Measured memory_bytes: 3600
# your code goes here
#15frame  
H,W=(int(i) for i in input().split())
while H!=0 or W!=0:
    S=""
    for i in range(W):
        S+="#"
    print(S)
    for i in range(H-2):
        S="#"
        for i in range(W-2):
            S+="."
        S+="#"
        print(S)
    S=""
    for i in range(W):
        S+="#"
    print(S,end="")
    H,W=(int(i) for i in input().split())
  #  if H!=0 or W!=0:
    print("\n")

Measured memory_bytes: 7668
#include <iostream>
#include <string>
#include <map>
#include <set>
#include <vector>
#include <algorithm>
#include <iomanip>

using namespace std;

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

  int sum = 0, max = 0;
  for (int i = 0; i < N; ++i)
  {
    int p;
    cin >> p;

    if (max < p) max = p;
    sum += p;
  }

  cout << sum + max / 2 - max << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <complex>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <numeric>
#include <cstring>
#include <ctime>
#include <cstdlib>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <cmath>
#include <bitset>
#include <cassert>
#include <queue>
#include <stack>
#include <deque>
#include <random>
#include <iomanip>
typedef long long int ll;
typedef long double ld;
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
const ll MOD=1000000007;
const ll MAX_N=500010;
const ll INF=999999999999;

int main(){
    ll n;
    cin>>n;
    vector<ll> a(n+1);
    a[0]=0;
    for(ll i=0;i<n;i++){
        ll x;
        cin>>x;
        a[i+1]=a[i]+x;
    }
    ll ans=INF;
    for(ll itr=2;itr<=n-2;itr++){
        auto left=lower_bound(a.begin(),a.begin()+itr+1,a[itr]/2);
        ll p=*left;
        ll p_=*(left-1);
        ll q=a[itr]-*left;
        ll q_=a[itr]-*(left-1);
        if(abs(p_-q_)<abs(p-q)){
            p=p_;
            q=q_;
        }
        auto right=lower_bound(a.begin()+itr+1,a.end(),a[itr]+(a[n]-a[itr])/2);
        ll s=*right-a[itr];
        ll s_=*(right-1)-a[itr];
        ll t=a[n]-*right;
        ll t_=a[n]-*(right-1);
        if(abs(s_-t_)<abs(s-t)){
            s=s_;
            t=t_;
        }
        //cout<<"itr="<<itr<<" "<<p<<" "<<q<<" "<<s<<" "<<t<<endl;
        ans=min(ans,max(max(p,q),max(s,t))-min(min(p,q),min(s,t)));
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 1792
#include <iostream>
#include <iomanip>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <utility>
#include <string>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <numeric>

using namespace std;

typedef uint64_t u64;
typedef int64_t s64;
typedef uint32_t u32;
typedef int32_t s32;
typedef vector<s32> vs32;
typedef vector<u32> vu32;
typedef vector<s64> vs64;
typedef vector<u64> vu64;

const double PI=3.14159265358979323846;

#define MAX(x, y) ((x) < (y) ? (y) : (x))
#define MIN(x, y) ((x) > (y) ? (y) : (x))

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

#define CEIL(x, y) (((x) + (y) - 1) / (y))
#define MOD 1000000007ULL

#define IN(l, r, x) ((l) <= (x) && (x) < (r))


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

    int n;
    cin >> n;
    vs64 s(n + 1, 0);
    s64 a;
    rep (i, n)
    {
        cin >> a;
        s[i + 1] = s[i] + a;
    }

    s64 ans = 1e18;
    for (int m = 2; m <= n - 2; ++m)
    {
        s64 pq = s[m];
        s64 rs = s[n] - s[m];
        auto lm = upper_bound(s.begin(), s.begin() + m + 1, pq / 2);
        auto rm = upper_bound(s.begin() + m + 1, s.end(), rs / 2 + s[m]);
        s64 pqrs[8] = {*(lm - 1), pq - *(lm - 1), *lm, pq - *lm,
                        *(rm - 1) - s[m], s[n] - *(rm - 1), *rm - s[m], s[n] - *rm};
        rep (i, 2)
        {
            rep (j, 2)
            {
                s64 large = 0, small = 1e18;
                large = MAX(large, pqrs[i * 2]);
                large = MAX(large, pqrs[i * 2 + 1]);
                large = MAX(large, pqrs[4 + j * 2]);
                large = MAX(large, pqrs[4 + j * 2 + 1]);
                small = MIN(small, pqrs[i * 2]);
                small = MIN(small, pqrs[i * 2 + 1]);
                small = MIN(small, pqrs[4 + j * 2]);
                small = MIN(small, pqrs[4 + j * 2 + 1]);
                ans = MIN(ans, large - small);
            }
        }
    }

    cout << ans << "\n";
    return 0;
}



Measured memory_bytes: 1792
// Author : Sarthak Kapoor
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
#define rep(i,n) for(int i=0;i<n;++i)
#define repa(i,a,n) for(int i=a;i<n;++i)
#define repr(i,n) for(int i=n-1;i>=0;--i)
#define repba(i,b,a) for(int i=b;i>=a;--i)
#define repab(i,a,b) for(int i=a;i<b;++i)
#define ll long long
#define ull unsigned long long
#define vi vector<int>
#define msi map<string,int>
#define mii map<int,int>
#define viip vector<pair<int,pair<int,int> > > 
#define mp make_pair
#define vip vector<pair<int,int> >
#define pb push_back 
#define po pop_back
#define fi first
#define sec second
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define s(v) v.size()
ll mod = 1000000007;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());//use rng()%n for numbers in range [0,n-1]
ll gcd(ll a,ll b){
	if(b==0)return a;
	return gcd(b,a%b);
}
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);

	int n;
	cin>>n;
	vector<ll> a(n+1);
	rep(i,n+1)cin>>a[i];
	vector<ll> b(n);
	rep(i,n)cin>>b[i];
	ll mon = 0;
	if(a[0] > b[0]){
		a[0] -= b[0];
		mon += b[0];
		b[0] = 0;
	}
	else{
		b[0] -= a[0];
		mon += a[0];
		a[0] = 0;
	}
	repa(i,1,n+1){
		if(b[i-1] > a[i]){
			mon += a[i];
			b[i-i] -= a[i];
			a[i] = 0;
		} 
		else{
			mon += b[i-1];
			a[i] -= b[i-1];
			b[i-1] = 0;
		}
		if(i < n && b[i] > a[i]){
			mon += a[i];
			b[i] -= a[i];
			a[i] = 0;
		}
		else if(i < n){
			mon += b[i];
			a[i] -= b[i];
			b[i] = 0;
		}
	}	
	cout<<mon;
	return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#include <algorithm>
using namespace std;
int main(){
string S; 
int x, y; 
cin >> S >> x >> y; 
S = S + 'T'; 
int X[4010] = {}; 
int Y[4010] = {}; 
int count1 = 0, count2 = 0; 
for(int i = 0; i < S.size(); i++){
	if(S.at(i) == 'F'){
		count1 ++;
	}
	else if(S.at(i) == 'T'){
		if(count2 % 2 == 0){
			X[count2 / 2] = count1;
		}
		else if(count2 % 2 == 1){
			Y[count2 / 2] = count1; 
		}
		count2 ++;
		count1 = 0; 
	}
}
bool dp1[16010][4010] = {}; 
dp1[0][0] = 1;
for(int j = 1; j <= count2 / 2; j++){
	for(int i = 0; i <= 8000; i++){
		dp1[i][j] = (dp1[i+X[j]][j-1] | dp1[abs(i-X[j])][j-1]); 	
	}
}
bool dp2[16010][4010] = {}; 
dp2[0][0] = 1;
for(int j = 1; j <= count2 / 2 + 1; j++){
	for(int i = 0; i <= 8000; i++){
		dp2[i][j] = (dp2[i+Y[j-1]][j-1] | dp2[abs(i-Y[j-1])][j-1]); 	
	}
}
if(dp1[abs(x-X[0])][count2 / 2] == 1 && dp2[abs(y)][count2 / 2 + 1] == 1){
	cout << "Yes" << endl; 
}
else{
	cout << "No" << endl; 
}
}

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

class Solve {
private:
	using vi = std::vector<int>;
	using vvi = std::vector<vi>;

	using vb = std::vector<bool>;
	using vvb = std::vector<vb>;
public:
	bool is_last_query{};
	Solve()
	{
		int m, n;
		scanf("%d%d", &m, &n);
		if (m == 0)
		{
			is_last_query = true;
			return;
		}
		vvi number(1100, vi(1100, -1));
		int place[2]{550, 550}, begin[2]{550, 550};
		int dir[4][2]{{1, 0}, {0, -1}, {-1, 0}, {0, 1}}, now_dir{};
		number[place[0]][place[1]] = 1;
		place[0] += dir[now_dir][0];
		place[1] += dir[now_dir][1];
		for (int i{2}; i <= m; i++)
		{
			if (i == n)
			{
				begin[0] = place[0];
				begin[1] = place[1];
			}
			number[place[0]][place[1]] = i;
			if (number[place[0] + dir[(now_dir + 1) % 4][0]][place[1] + dir[(now_dir + 1) % 4][1]] < 0)
				now_dir = (now_dir + 1) % 4;
			place[0] += dir[now_dir][0];
			place[1] += dir[now_dir][1];
		}

		vb isPrime(m + 1, true);
		isPrime[1] = false;
		for (int i{2}; i <= m; i++)
		{
			if (!isPrime[i]) continue;
			for (int j{2 * i}; j <= m; j += i)
				isPrime[j] = false;
		}

		vvb visited(1100, vb(1100));

		std::queue<std::pair<int, int>> que;
		que.push({begin[0], begin[1]});

		vvi maxTable(1100, vi(1100, 0));
		std::pair<int, int> max;
		while (!que.empty())
		{
			auto now{que.front()};
			que.pop();
			if (visited[now.first][now.second] || number[now.first][now.second] < 0) continue;
			visited[now.first][now.second] = true;
			auto& now_max{maxTable[now.first][now.second]};
			for (int i{now.first - 1}; i <= now.first + 1; i++)
				now_max = std::max(now_max, maxTable[i][now.second - 1]);
			if (isPrime[number[now.first][now.second]])
			{
				now_max++;
				max = std::max(max, {now_max, number[now.first][now.second]});
			}
			for (int i{now.first - 1}; i <= now.first + 1; i++)
				que.push({i, now.second + 1});
		}
		printf("%d %d\n", max.first, max.second);
	}
};

int main()
{
	while (!Solve().is_last_query);

	return 0;
}


Measured memory_bytes: 12916
using System;
using System.IO;
using System.Linq;

class Program
{
    static void Solve()
    {
        var inputs = ReadInts();

        Console.WriteLine((inputs[2] / inputs[0]) * inputs[1]);
    }

    static void Main(string[] args)
    {
        var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
        Console.SetOut(sw);
        Solve();
        Console.Out.Flush();
    }

    public static string Read() { return Console.ReadLine(); }
    public static int ReadInt() { return int.Parse(Read()); }
    public static long ReadLong() { return long.Parse(Read()); }
    public static double ReadDouble() { return double.Parse(Read()); }

    public static string[] Reads() { return Console.ReadLine().Split(' '); }
    public static int[] ReadInts() { return Reads().Select(_ => int.Parse(_)).ToArray(); }
    public static long[] ReadLongs() { return Reads().Select(_ => long.Parse(_)).ToArray(); }
    public static double[] ReadDoubles() { return Reads().Select(_ => double.Parse(_)).ToArray(); }
}

Measured memory_bytes: 13396
while str = STDIN.gets
  n = str.split(" ")
  a = n[0].to_i
  b = n[1].to_i

  if a == 0 && b == 0
    break
  else
    for h in 0..a-1 do
      for w in 0..b-1 do
        if h % 2 == 0 && w % 2 == 0
          print "#"
        elsif h % 2 == 0 && w % 2 != 0
          print "."
        elsif h % 2 != 0 && w % 2 == 0
          print "."
        else
          print "#"
        end
      end
       print "\n"
  end
  print "\n"
  end
end



Measured memory_bytes: 6872
#include <bits/stdc++.h>
#include<string>
using namespace std;
int main(){
    long long int a,b=0;
    string s;
    cin >> s;
    a=s.size();
    for(int i=0;i<a;i++){
        b++;
    }
    if(s[b-1]=='s'){
        cout << s << "es";
    }else{
        cout << s << "s";
    }
    return 0;
}

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

const long long INF = 1LL << 60;
const int MAX_V = 100100;

int main() {
    long long N, W; cin >> N >> W;
    vector<long long> w(N), v(N);
    for(int i = 0; i < N; ++i) cin >> w[i] >> v[i];
    
    vector<vector<long long>> dp(N+1, vector<long long>(MAX_V, INF));
    dp[0][0] = 0;
    for(int i = 0; i < N; ++i) {
        for(int sum_v = 0; sum_v < MAX_V; ++sum_v) {
            if(sum_v - v[i] >= 0) {
                dp[i+1][sum_v] = min(dp[i+1][sum_v], dp[i][sum_v - v[i]] + w[i]);
            }
            
            dp[i+1][sum_v] = min(dp[i+1][sum_v], dp[i][sum_v]);
        }
    }
    
    long long res = 0;
    for(int sum_v = 0; sum_v < MAX_V; ++sum_v) {
        if(dp[N][sum_v] <= W) res = sum_v;
    }
    cout << res << endl;
}


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

int main(){
    string a,b,c;
    cin>>a>>b>>c;
    if((a.back()==b.front())&&(b.back()==c.front())){
        cout<<"YES"<<"\n";
    }else{
        cout<<"NO"<<"\n";
    }
}

Measured memory_bytes: 256
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;

struct UFTree(T)
{
    struct Node
    {
        T parent;
        T rank = 1;
    }

    ///
    T min_size, max_size;

    ///
    this(T n)
    {
        nodes.length = n;
        sizes.length = n;
        foreach (i, ref node; nodes) {
            node = Node(i.to!T);
            sizes[i] = 1;
        }

        min_sizes.length = n + 1;
        min_sizes[1] = n;
        min_size = 1;
        max_size = 1;
    }

    ///
    bool unite(T a, T b)
    {
        a = root(a);
        b = root(b);

        if (a == b) return false;

        auto a_size = sizes[a];
        auto b_size = sizes[b];
        --min_sizes[a_size];
        --min_sizes[b_size];
        ++min_sizes[a_size + b_size];
        foreach (nxt_size; min(a_size, b_size)..min_sizes.length) if (min_sizes[nxt_size] != 0) {
            min_size = nxt_size.to!T;
            break;
        }
        max_size = max(max_size, a_size + b_size);

        if (nodes[a].rank < nodes[b].rank) {
            sizes[a] += sizes[b];
            nodes[b].parent = a;
        } else {
            sizes[b] += sizes[a];
            nodes[a].parent = b;
            if (nodes[a].rank == nodes[b].rank) ++nodes[b].rank;
        }

        return true;
    }

    ///
    bool is_same(T a, T b)
    {
        return root(a) == root(b);
    }

    ///
    T size(T i)
    {
        return sizes[root(i)];
    }

private:
    Node[] nodes;
    T[] sizes;
    T[] min_sizes;

    T root(T i)
    {
        if (nodes[i].parent == i) return i;

        return nodes[i].parent = root(nodes[i].parent);
    }
}

///
UFTree!T uftree(T)(T n)
{
    return UFTree!T(n);
}

void main()
{
    auto nm = readln.split.to!(long[]);
    auto N = nm[0];
    auto M = nm[1];
    long[] as, bs, rs;

    foreach (_; 0..M) {
        auto ab = readln.split.to!(long[]);
        as ~= ab[0]-1;
        bs ~= ab[1]-1;
    }

    rs ~= N * (N-1) / 2;
    auto uft = uftree(N);

    foreach (i; 0..M) {
        auto a = as[M-i-1];
        auto b = bs[M-i-1];
        rs ~= rs[i] - (uft.is_same(a, b) ? 0 : uft.size(a) * uft.size(b));
        uft.unite(a, b);
    }
    rs.reverse();
    rs = rs[1..$];
    writeln(rs.to!(string[]).join("\n"));
}

Measured memory_bytes: 14332
#include <iostream>
#include <algorithm>
#include <cstring>

using namespace std;

int p,n[6],m[6]={1,5,10,50,100,500};
int change[1000000];

int cntchange(int arg){
    if(change[arg] != -1) return change[arg];
    int origin = arg, ret = 0, tmp;
    for(int i=5;i>=0;--i){
        tmp = arg / m[i];
        arg -= tmp * m[i];
        ret += tmp;
    }
    return change[origin] = ret; 
}

int possible(int arg){
    int ret=0, tmp;
    for(int i=5;i>=0;--i){
        tmp = arg / m[i];
        tmp = min(tmp, n[i]);
        arg -= tmp * m[i];
        ret += tmp;
    }

    return arg==0?ret:-1;
}

int main(){
    int sum;
    memset(change, -1, sizeof(change));
    while(cin >> p && p){
        int ub = 0;
        for(int i=0;i<6;++i){
            cin >> n[i];
            ub += n[i] * m[i];
        }

        int ret = 1 << 20;
        for(int i=p;i<=ub;++i){
            int pay;
            pay = possible(i);
            if(pay != -1){
                ret = min(ret, pay+cntchange(i-p));
            }
        }
        cout << ret << endl;
    }
}

Measured memory_bytes: 0
/**
 *    author:  tourist
 *    created: 09.12.2019 15:16:41       
**/
#include <bits/stdc++.h>

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<int> p(n);
  p[0] = -1;
  for (int i = 1; i < n; i++) {
    cin >> p[i];
  }
  vector<int> d(n);
  for (int i = 1; i < n; i++) {
    d[i] = d[p[i]] + 1;
  }
  vector<vector<int>> is_parent(n, vector<int>(n));
  for (int i = 0; i < n; i++) {
    int x = i;
    while (x >= 0) {
      is_parent[x][i] = 1;
      x = p[x];
    }
  }
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  vector<int> ret;
  while (true) {
    int to = 0;
    for (int i = 1; i < n; i++) {
      if (is_parent[a[0]][i] && (!is_parent[a[i]][i] || d[a[i]] < d[a[0]])) {
        if (d[i] > d[to]) {
          to = i;
        }
      }
    }
    if (to == 0) {
      break;
    }
    ret.push_back(to);
    int v = to;
    while (v > 0) {
      swap(a[0], a[v]);
      v = p[v];
    }
  }
  assert(ret.size() <= 10000);
  cout << ret.size() << '\n';
  for (int x : ret) {
    cout << x << '\n';
  }
  return 0;
}


Measured memory_bytes: 18048
n = int(input())
h = list(map(int, input().split()))

for i in range(n-1,1,-1):
    dif = h[i] - h[i-1]
    if(dif == -1):
        h[i-1] -= 1
    elif(dif < -1):
        print('No')
        exit()

print('Yes')


Measured memory_bytes: 63984
n,m,q = map(int,input().split())
a = [0]*q
b = [0]*q
c = [0]*q
d = [0]*q
for i in range(q):
    a[i], b[i], c[i], d[i] = map(int, input().split())
    a[i] -= 1 # インデックス補正
    b[i] -= 1 
    
def score(A):
    x = 0
    for ai,bi,ci,di in zip(a,b,c,d):
        if A[bi] - A[ai] == ci:
            x += di
    return x

def dfs(A):
    # 終端条件 --- 3 重ループまで回したら処理して打ち切り
    if len(A) == n:
        #print(A)
        return score(A)
    res = 0
    # 単調増加するように制限
    pre = A[-1] if len(A) > 0 else 0 
    for v in range(pre, m):
        A.append(v) # 次のノードへの遷移
        res = max(res,dfs(A))      # 再帰呼出し
        A.pop()     # 一回元に戻す (これが結構ポイント appendする前の状態に戻している)
    return res

print(dfs([]))

Measured memory_bytes: 9196
#include <bits/stdc++.h>
using namespace std;
int main(){
	int A, B, C; cin >> A >> B >> C; 
	cout << A << " " << B << " " << -A-B+3*C << "\n"; 
	cout << -2*A-B+4*C << " " << C << " " << 2*A+B-2*C << "\n"; 
	cout << A+B-C << " " << -B+2*C << " " << -A+2*C << "\n"; 
}

Measured memory_bytes: 3580
//-- In the name of ALLAH --
// We're nothing and you're everything.
// Ya Ali!
#include<bits/stdc++.h>
using namespace std;


#define      pai              acos(-1)
#define      ff               first
#define      ss               second
#define      ll               long long
#define      pb               push_back
#define      mp               make_pair
#define      pll              pair<ll,ll>
#define      sz(a)            (ll)a.size()
#define      endl             "\n"
#define      gcd(a, b)        __gcd(a, b)
#define      lcm(a, b)        ((a)*((b)/gcd(a,b))
#define      all(vec)         vec.begin(),vec.end()
#define      ms(a, b)         memset(a,b,sizeof(a))
#define      TEST_CASE(t)     for(int zz=1;zz<=t;zz++)
#define      PRINT_CASE       printf("Case %d: ",zz)
#define      fii              freopen("input.txt","r",stdin);
#define      foo              freopen("output.txt","w",stdout);
#define      FAST             ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);

const ll mod = 1e9+7;
const ll mxn = 1e5+7;

int  main()
{
    ll i,j,k,a,b,c,d,n,m,t,x,y,z,u,v;
    cin>>n;
    cout<<(1-n)<<endl;
    return 0;
}


Measured memory_bytes: 3616
#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);
    int r;
    cin >> r;
    cout << fixed << setprecision(3);
    cout << M_PI * r * 2 << endl;
    
    return 0;
}



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

int main(){
  int n;
  cin >> n;
  vector<int> arr(n);
  for (int i = 0; i < n; i++){
    cin >> arr.at(i);
  }
  int count = 0, tmp = 0;
  for (int x: arr){
    if ((tmp + 1) == x){
      tmp += 1;
      count += 1;
    }
  }
  if (tmp == 0)
    cout << -1 << endl;
  else
    cout << n - count << endl;  
}


Measured memory_bytes: 1152
package main

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

func getScanner(fp *os.File) *bufio.Scanner {
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 500001), 500000)
	return scanner
}

func getNextString(scanner *bufio.Scanner) string {
	scanner.Scan()
	return scanner.Text()
}

func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}

func main() {
	fp := os.Stdin
	if len(os.Args) > 1 {
		fp, _ = os.Open(os.Args[1])
	}

	scanner := getScanner(fp)
	writer := bufio.NewWriter(os.Stdout)

	x := getNextInt(scanner)

	ans := "NO"
	for i := 3; i <= 7; i += 2 {
		if i == x {
			ans = "YES"
			break
		}
	}
	fmt.Fprintln(writer, ans)
	writer.Flush()
}


Measured memory_bytes: 640
import java.util.*;
 
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    String s = sc.next();
    String m[] = s.split("");
    int ans = 0;
    for (int i = 0; i < s.length(); i++){
      if (m[i].equals("+")){
        ans++;
      }else{
        ans--;
      }
    }
    System.out.println(ans);
  }
}

Measured memory_bytes: 35596
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<unordered_map>
#include<bitset>
#include<iomanip>
#include<list>
#include<deque>
using namespace std;
//#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define END {}
#endif
typedef long long ll;
#define int ll
#define uset unordered_set
#define umap unordered_map
typedef std::pair<int,int> P;
struct edge{int to,cost;};
const int INF=100000000000000000;
const int INF2=9223372036854775807;
const int MOD=1000000007;
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define min(X,Y) (((int)(X)<(int)(Y))?(X):(Y))
#define max(X,Y) (((int)(X)>(int)(Y))?(X):(Y))
#define MAX(X,Y) (*max_element(X,Y))
#define MIN(X,Y) (*min_element(X,Y))
#define NP(X,Y) next_permutation(X,Y)
#define setp(X,Y) cout<<fixed<<setprecision(X)<<Y<<endl
int ceil2(int a,int b){if(a%b==0){return a/b;}else{return a/b+1;}}
int pow2(int a,int b){int r=1;for(int i=1;i<=b;i++){r*=a;}return r;}
int Log2(int a){int t=0;while(1){if(a==0||a==1){break;}a/=2;t++;}return t;}

int N;

signed main(){
	cin>>N;
	for(int i=1;i<=9;i++){
		if(N%i==0){
			if(1<=N/i&&N/i<=9){
				cout<<"Yes"<<endl;
				return 0;
			}
		}
	}
	cout<<"No"<<endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

typedef long long ll;
typedef pair<int,int> ii;
typedef tree<ii,null_type,less<ii>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;

int main() {
	cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
	int N,M; cin>>N>>M;
	vector<int> A(N);
	int cut=0;
	for (int i=0; i<N; i++)
		cin>>A[i], cut+=A[i];
	int ret=0;
	for (int i=0; i<N; i++) {
		if(A[i]*M*4<cut)
			continue;
		ret++;
	}
	cout<<(ret>=M?"Yes":"No")<<"\n";
	return 0;
}

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

int main(){
  int N,M,X;
  cin >> N >> M >> X;
  vector<int> C(N);
  vector<vector<int>> A(N,vector<int>(M,0));
  for(int i = 0;i < N; i++){
    cin >> C.at(i);
    for(int j = 0; j < M; j++) cin >> A.at(i).at(j);
  }
  int ans = 2000000;
  for(int tmp = 0; tmp < (1 << 12); tmp++){
    bitset<12> s(tmp);
    vector<int> v(M,0);
    bool ok = true;
    int mon = 0;
    for(int i = 0; i < s.size(); i++){
      if(!s.test(i)) continue;
      if(i > N - 1) continue;
      mon += C.at(i);
      for(int j = 0; j < M;j++){
        v.at(j) += A.at(i).at(j);
      }
    }
    for(int j = 0; j < M; j++) if(v.at(j) < X) ok = false;
    if(ok &&  mon < ans){
      ans = mon;
    }
  }
  if(ans == 2000000) cout << -1 << endl;
  else cout << ans << endl;
}

Measured memory_bytes: 3620
#include <iostream>

int main() {
    while (true) {
        int n, x;
        std::cin >> n >> x;

        if (n == 0 && x == 0) break;

        int result = 0;
        for (int a = 1; a <= n - 2; a++) {
            if (a >= x / 3) break;
            for (int b = a+1; b <= n - 1; b++) {
                int c = x - a - b;
                if (c <= b) break;
                if (c <= n) result += 1;
            }
        }
        std::cout << result << std::endl;
    }
}


Measured memory_bytes: 3080
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,l,r) for(long long i=(l);i<(r);++i)
#define REP(i,n) FOR(i,0,n)
#define REPS(i,n) FOR(i,1,n+1)
#define int long long
#define pb push_back
#define eb emplace_back
#define mp make_pair
const int MOD=1e9+7;
const int INF=1e15;

signed main(){
    int N;cin>>N;
    if(N<1200)cout<<"ABC"<<endl;
    if(N>=1200&&N<2800)cout<<"ARC"<<endl;
    if(N>=2800)cout<<"AGC"<<endl;
}


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

// 型定義
typedef long long ll;
typedef pair<ll, ll> P;

// forループ
#define REP(i,n) for(ll i=0; i<(ll)(n); ++i)

// 定数宣言
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

// グラフ表現
using Graph = vector<vector<int>>;

// グラフの辺表現
using Edge = map<pair<int,int>,int>;

// n次元配列の初期化。第２引数の型のサイズごとに初期化していく。
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

// 最大公約数
ll gcd(ll a,ll b){
   if (a%b == 0) return(b);
   else return(gcd(b, a%b));
}

// 最小公倍数
ll lcm(ll a, ll b){
    return a*b/gcd(a, b);
}

int main()
{
    cout << fixed << setprecision(15);
    ll N, X;
    cin >> N >> X;

    ll minx=INF;
    REP(i, N){
        ll m;
        cin >> m;
        X -= m;
        minx = min(minx, m);
    }
    
    cout << ll(X/minx) + N << endl;
    return 0;
}

Measured memory_bytes: 256
import sys
import itertools

# import numpy as np

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

A, B, C, X, Y = map(int, readline().split())
ans = 0
if A + B > 2 * C:
    if X > Y:
        ans += Y * C * 2
        ans += (X - Y) * A
    else:
        ans += X * C * 2
        ans += (Y - X) * B
else:
    ans += A * X + B * Y
print(min(ans, C * 2 * max(X, Y)))


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

map<long long, int> prime_factorize(long long n) {
	map<long long, int> ret;
	for (long long i = 2; i * i <= n; i++) {
		while (n % i == 0) {
			ret[i]++;
			n /= i;
		}
	}
	if (n != 1)
		ret[n] = 1;
	return ret;
}

long long gcd(long long a, long long b) {
	if (a < b)
		swap(a, b);
	if (a % b == 0) {
		return b;
	} else {
		return gcd(b, a % b);
	}
}

int main() {
	long long a, b;
	long long ans = 0;
	cin >> a >> b;
	long long g = gcd(a, b);
	auto D = prime_factorize(g);
	cout << D.size() + 1 << endl;
	return 0;
}


Measured memory_bytes: 256
n = int(input())
ans = 0
for i in range(1,n+1):
  if i % 3 == 0 and i % 5 == 0:
    a = 0
  elif i % 3 == 0:
    a = 0 
  elif i % 5 == 0:
    a = 0
  else:
    ans += i
print(ans)


Measured memory_bytes: 9168
import sys
import math
from collections import defaultdict, deque, Counter
from copy import deepcopy
from bisect import bisect, bisect_right, bisect_left
from heapq import heapify, heappop, heappush
    
input = sys.stdin.readline
def RD(): return input().rstrip()
def F(): return float(input().rstrip())
def I(): return int(input().rstrip())
def MI(): return map(int, input().split())
def MF(): return map(float,input().split())
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float,input().split()))
def Init(H, W, num): return [[num for i in range(W)] for j in range(H)]


def main():
    H, W = MI()
    D = defaultdict(int)
    
    cost = [LI() for i in range(10)]
    
    for i in range(H):
        temp = LI()
        for j in temp:
            if j != -1:
                D[j]+=1

    for i in range(10):
        for j in range(10):
            for k in range(10):
                cost[j][k] = min(cost[j][k], cost[j][i]+cost[i][k])
                
    ans = 0
    
    for key, num in D.items():
        ans += cost[key][1]*num
        
    print(ans)

    
if __name__ == "__main__":
    main()

Measured memory_bytes: 74752
#include<bits/stdc++.h>
//#define int long long
using namespace std;
const int Mo=998244353;
inline int read()
{
	char c=getchar();int x=0;bool f=0;
	while(c<'0'||c>'9') {if(c=='-') f=1;c=getchar();}
	while(c>='0'&&c<='9') {x=(x<<1)+(x<<3)+(c^48);c=getchar();}
	if(f) x=-x;
	return x;
}
inline void write(int x)
{
	if(x<0) putchar('-'),x=-x;
	if(x>=10) write(x/10);
	putchar(x%10+'0');
}
int a[200001];
signed main()
{
	int n=read(),tip=0,num=0;
	for(int i=1;i<=n;i++)
	a[i]=read();
	for(int i=1;i<=n;i++)
	if(a[i]==tip+1) tip++;
	else num++;
	if(num<n) write(num);
	else cout<<-1<<endl;
	return 0;
}

Measured memory_bytes: 1024
package main

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

func main() {
	var (
		s string
		k int
	)
	fmt.Scan(&s, &k)

	wr := bufio.NewWriter(os.Stdout)
	for i := range s {
		d := int(s[i] - 'a')
		if i == len(s)-1 {
			wr.WriteString(string('a' + (d+k)%26))
			break
		}

		if d > 0 && 26-d <= k {
			wr.WriteString("a")
			k -= 26 - d
		} else {
			wr.WriteString(string(s[i]))
		}
	}
	wr.WriteString("\n")
	wr.Flush()
}


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

using namespace std;

int main  ()
{

 int a;
 int b;

 cin >> a;
 cin >> b;

 if((a+b)%2==1)
 {
  cout << (a+b)/2+1 << endl;
 }

 else 
 {
  cout << (a+b)/2 << endl;
 }

 return 0;

}


Measured memory_bytes: 256
program ABC149C
    implicit none
    integer(8)::n,i,Flag
    read*,n
    do
        Flag = 1
        do i = 2,n-1
            if (mod(n,i) == 0) then
                Flag = 0
            end if
        end do
        if (Flag == 1) then
            print*,n
            stop
        else
            n = n + 1
        end if
    end do
end program ABC149C

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

using namespace std;

typedef long long ll;
typedef long double ld;

const int N = 305;
int n;
ld dp[N][N][N];
bool mark[N][N][N];

ld solve(int a, int b, int c)
{
    if((a < 0 || b < 0 || c < 0) || (a + b + c == 0))
        return 0;
    ld &ans = dp[a][b][c];
    if(mark[a][b][c])
        return ans;
    mark[a][b][c] = 1;
    ans = 1;
    ans += ((ld)a / n) * solve(a - 1, b, c);
    ans += ((ld)b / n) * solve(a + 1, b - 1, c);
    ans += ((ld)c / n) * solve(a, b + 1, c - 1);
    ans /= (1 - (ld)(n - a - b - c) / n);
    return ans;
}

int main()
{
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    cin >> n;
    int a = 0, b = 0, c = 0;
    for(int i = 0; i < n; i++)
    {
        int x;
        cin >> x;
        if(x == 1)
            a++;
        else if(x == 2)
            b++;
        else
            c++;
    }
    cout << fixed << setprecision(12) << solve(a, b, c);
}


Measured memory_bytes: 431616
#include <iostream>
#include <string>
using namespace std;
int main(){
      string s;
      while(getline(cin,s)){
            for(int i=0;i<25;i++){
                  if(s.find("the")!=-1||s.find("this")!=-1||s.find("that")!=-1)break;
                  else for(int j=0;j<s.size();j++)if(s[j]>='a'&&s[j]<='z')s[j]!='z'?s[j]++:s[j]='a';
            }
            cout<<s<<endl;
      }
}

Measured memory_bytes: 1176
#pragma region Template
#include <bits/stdc++.h>
using namespace std;
struct ios_accelerate { ios_accelerate() { ios::sync_with_stdio(false); cin.tie(nullptr); } } CALL;

#define REP(i, n) for(int i = 0; i < n; i++)
#define RNG(i, a, b) for(int i = a; i < b; i++)
#define RBF(i, v) for(auto& i : v)
#define ALL(x) x.begin(), x.end()

using LL = long long;
using UL = unsigned long;
using ULL = unsigned long long;
template<typename T> using V = vector<T>;
template<typename T> using VV = vector<vector<T>>;
template<typename T> using P = pair<T, T>;
template<typename T> using VP = vector<pair<T, T>>;

const double PI = 3.141592653589793;
const int MOD = 1000000007;
const LL INF64 = INT64_MAX >> 1;
const int INF = INT_MAX >> 1;

template<typename T> inline void upsort(vector<T>& x) { sort(x.begin(), x.end()); }
template<typename T> inline void downsort(vector<T>& x) { sort(x.begin(), x.end(), greater<T>()); }
template<typename T> inline void col(T x) { cout << x << '\n'; }
template<> inline void col(double x) { cout << fixed << setprecision(12) << x << '\n'; }
#pragma endregion

signed main()
{
	int h1, m1, h2, m2, k;
	cin >> h1 >> m1 >> h2 >> m2 >> k;

	int begin = h1 * 60 + m1, end = h2 * 60 + m2;
	col(end - k - begin);
	return 0;
}


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

using namespace std;

typedef long long ll;

constexpr int M = 1000 * 1000 * 1000 + 7;

int a[200];

int main() {
    std::ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    cin >> n;
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    int ans = 0;
    for (int i = 1; i + 1 < n; ++i) {
        int x[3] = {a[i - 1], a[i], a[i + 1]};
        sort(x, x + 3);
        ans += x[1] == a[i];
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
const int mod = 1e9 + 7;
//const int mod = 998244353;
const ll infll = (1LL << 62) - 1;
const int inf = (1 << 30) - 1;
void YesNo(bool j){cout << (j ? "Yes" : "No") << endl; return;}
void yesno(bool j){cout << (j ? "yes" : "no") << endl; return;}
template<class Head> void pt(Head&& head){cout << head << endl; return;}



int main() {
  bool ok=true;
  string s;
  cin >> s;
  if(s=="AAA" || s=="BBB") ok=false;
  YesNo(ok);
  return 0;
}


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

int main(){
	int n,m;
	cin>>n>>m;
	vector<string> a(n);
	vector<string> b(m);
	
	for(int i = 0;i<n;i++)cin>>a[i];
	for(int i = 0;i<m;i++)cin>>b[i];
	
	int ans=1;
	for(int i = 0;i<n-m+1;i++){
		for(int l = 0;l<n-m+1;l++){
			ans=1;
			for(int j = 0;j<m;j++){
				for(int k = 0;k<m;k++){
					if(a[i+j][l+k]!=b[j][k]){
						ans=0;
					}
				}
			}
				if(ans==1){
				cout<<"Yes"<<endl;
				return 0;
			}
		}
	}
	cout<<"No"<<endl;
	return 0;
} 

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
typedef pair<int,int > pp;
typedef long long ll;
 
#define sz(x) (int)x.size() 
int const N=3e5+10,oo=1e9;
ll const OO=2e18;
double const eps=1e-8,PI=acos(-1);
int mod=oo+7;

struct circle{
    int x,y,r;
    circle(){};
    circle(int x,int y,int r):x(x),y(y),r(r){}
};

int n;
int a,b,c,d;
circle all[1001];
priority_queue<pair<double,int > > q;
double cost[1001];
bool vis[1001];
double dist(pp a,pp b){
    return sqrt((a.first-b.first)*1LL*(a.first-b.first)+
        (a.second-b.second)*1LL*(a.second-b.second));
}
double distc(int i,int j){
    double dd=dist({all[i].x,all[i].y},{all[j].x,all[j].y});
    dd+=-all[i].r-all[j].r;
    if(dd<0)dd=0;
    return dd;
}
int main(){
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin>>a>>b>>c>>d;
  cin>>n;
  for(int i=0;i<n;i++){
      cost[i]=OO;
      int x,y,r;
      cin>>x>>y>>r;
      all[i]=circle(x,y,r);
  }
  double mn=dist({a,b},{c,d});
  for(int i=0;i<n;i++){
      double dd=dist({a,b},{all[i].x,all[i].y});
      if(dd<=all[i].r){
          q.push({0,i});
          cost[i]=0;
      }else {
          dd-=all[i].r;
          q.push({-dd,i});
          cost[i]=dd;
      }
  }
  while(!q.empty()){
      auto cur=q.top();q.pop();
      double d=-cur.first;
      int idx=cur.second;
      if(vis[idx])continue;
      vis[idx]=1;
      for(int i=0;i<n;i++){
          if(i==idx)continue;
          double need=distc(idx,i);
          if(!vis[i]&&cost[i]>need+d){
              cost[i]=need+d;
              q.push({-cost[i],i});
          }
      }
  }
  for(int i=0;i<n;i++)mn=min(mn,max(0.0,dist({c,d},{all[i].x,all[i].y})-all[i].r)+cost[i]);
  cout<<fixed<<setprecision(10)<<mn<<'\n';
  return 0;
}


Measured memory_bytes: 6256
import java.io.*;
import java.lang.reflect.Array;
import java.util.*;

/*
><BY MOHAMMAD OMAR><GOOGLE, HERE I COME><
*/
public class Main {

    public static void main(String[] args) throws IOException {
        Scanner sc = new Scanner(System.in);
        PrintWriter pw = new PrintWriter(System.out);
        int T = sc.nextInt();
        int ans = (T % 1000 == 0) ? 0 : (1000 - T % 1000);
        pw.println(ans);
        pw.close();
    }

    static class Scanner {
        StringTokenizer st;
        BufferedReader br;

        public Scanner(InputStream s) {
            br = new BufferedReader(new InputStreamReader(s));
        }

        public String next() throws IOException {
            while (st == null || !st.hasMoreTokens())
                st = new StringTokenizer(br.readLine());
            return st.nextToken();
        }

        public int nextInt() throws IOException {
            return Integer.parseInt(next());
        }

        public long nextLong() throws IOException {
            return Long.parseLong(next());
        }

        public String nextLine() throws IOException {
            return br.readLine();
        }

        public boolean ready() throws IOException {
            return br.ready();
        }

        public double nextDouble(String x) {

            StringBuilder sb = new StringBuilder("0");
            double res = 0, f = 1;
            boolean dec = false, neg = false;
            int start = 0;
            if (x.charAt(0) == '-') {
                neg = true;
                start++;
            }
            for (int i = start; i < x.length(); i++)
                if (x.charAt(i) == '.') {
                    res = Long.parseLong(sb.toString());
                    sb = new StringBuilder("0");
                    dec = true;
                } else {
                    sb.append(x.charAt(i));
                    if (dec)
                        f *= 10;
                }
            res += Long.parseLong(sb.toString()) / f;
            return res * (neg ? -1 : 1);
        }


    }
}


Measured memory_bytes: 25444
#include <bits/stdc++.h>
using intl = long long;
using itnl = long long;
using itn = int;
using ld = long double;
using namespace std;
#define rep(i, n) for(intl i = 0; i < (intl)(n); i++)
#define rrep(i, n) for(intl i = (intl)(n); i >= 0; i--)
#define repi(i, a, b) for(intl i = (intl)(a); i < (intl)(b); i++)
#define rrepi(i, a, b) for(intl i = (intl)(a); i >= (intl)(b); i--)
#define max(a, b) ((a) > (b) ? (a) : (b))
#define min(a, b) ((a) < (b) ? (a) : (b))
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))
#define m1(x) memset(x,1,sizeof(x))
#define fill(x,y) memset(x,y,sizeof(x))
#define alength(a) (sizeof(a) / sizeof(a[0]))
#define cin(i, a) rep(i, alength(a))cin >> a[i]
#define ccin(i, j, a) rep(i, alength(a))rep(j, alength(a[i]))cin >> a[i][j]
#define debug(x) cout << #x << ":" << x << endl
#define rdebug(i,x) rep(i, alength(x))cout << #x << "[" << i << "]:" << x[i] << endl
#define sqrt sqrtl
#define itn int
#define double ld
#define pb push_back
#define mp make_pair
const intl INF = 1e9;
const intl MOD = 1e9+7;
const ld eps = 1.0e-14;//-9
void fp(bool f){cout << (f ? "Yes" : "No") << endl;}
void fp(bool f, string s, string t){cout << (f ? s : t) << endl;}
intl kai(intl k){
    intl a = 1;
    for(int i = 2; i <= k; i++){
        a *= i;
    }
    return a;
}
intl gcd(intl a, intl b){
    if(!b)return a;
    return gcd(b, a % b);
}
intl lcm(intl a,intl b){
    return a / gcd(a, b) * b;
}
intl digit10(intl a){
    intl b = 0;
    do{
        a /= 10;
        b++;
    }while(a);
    return b;
}
signed main(){
    cout << fixed << setprecision(10);
    intl n;
    cin >> n;
    intl a,b;
    cin >> a >> b;
    intl cnt = 0;
    rep(i,n + 1){
        intl c = 0;
        intl i0 = i;
        rep(j,digit10(i)){
            c += i0 % 10;
            i0 /= 10;
        }
        cnt += i * ((a <= c)&&(c <= b));
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 256