akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <stdlib.h>

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;
#define NIL NULL

Node root;

/*Node treeMinimum(Node x){
  

}

Node treeMaximum(Node x){


}*/

Node treeSearch(Node u, int k){
  if(u == NIL || k == u->key) return u;

  if(k < u->key)return treeSearch(u->left, k);
  else return treeSearch(u->right, k);

  return NIL;
}

/*Node treeSuccessor(Node x){


}

void treeDelete(Node z){
  Node y; // node to be deleted
  Node x; // child of y



  }*/

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

  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;

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

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

   
}

void inorder(Node u){
  int i=0;
  if(u != NIL){
    inorder(u->left);
   
    printf(" %d",u->key);
    
    inorder(u->right);
  }
}

void preorder(Node u){
  int i=0;
 if(u != NIL){
   printf(" ");
   printf("%d",u->key);
   preorder(u->left);
   preorder(u->right);
  }
}



int main(){
  int n, i, x;
  char com[20];
  scanf("%d", &n);

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

  return 0;
}




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

int main() {
	int n, m;
	cin >> n >> m;
	vector<int> a(m);
	for(int i=0;i<m;i++) cin >> a[i];
	vector<int> ans(n,0);
	for(int i=0;i<m;i++) {
		int tar = a[i];
		int cnt = 0;
		for(int j=0;j<n;j++) {
			int b;
			cin >> b;
			if(b == a[i]) {
				ans[j]++;
			}else{
				cnt++;
			}
		}
		ans[tar-1] += cnt;
	}
	for(int i=0;i<n;i++) cout << ans[i] << endl;
}


Measured memory_bytes: 3088
A1,A2,A3=map(int,input().split())
A=[A1,A2,A3]
A.append(A1)
def A_(i):
    if A[i]-A[i+1]>=0:
        return A[i]-A[i+1]
    else:
        return A[i+1]-A[i]
B=[A_(i) for i in range(3)]
B.append(A_(0))
B.append(A_(1))
def sum(j):
    return B[j]+B[j+1]
C=[sum(j) for j in range(3)]
print(min(C))

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

#define rep(i,n) for(int (i)=0;(i)<(n);++(i))
#define FOR(i,a,b) for(int (i)=(a);i<(b);++(i))
#define ALL(obj) (obj).begin(),(obj).end()
#define space <<" "<<
#define ll long long
#define bpm %1000000007

using namespace std;

ll powAns(ll,ll);

int main(){
    int n;
    int a=0;
    ll N=10000000;



    vector<ll> res;
    vector<bool> is_prime( N+1, true);

    for (ll p = 2; p <= N; p++) {
    if (!is_prime[p]) continue;

    for (ll k = p * 2; k <= N; k += p) is_prime[k] = false;

    res.push_back(p);
    }

    while(1<2){
    cin>>n;
    if(n==0)break;
    
    for(int k=distance(res.begin(),upper_bound(res.begin(),res.end(),n)-1);k>0;k--)if(((res[k]-2)==res[k-1])&&((res[k]-6)==res[k-2])&&((res[k]-8)==res[k-3])){
        a=res[k];
        break;
    }
    cout<<a<<endl;
}
}

ll powAns(ll m ,ll n){
    ll res=1;
    while(n>0){
        if(n & 1)res = res*m bpm;

        m=m*m bpm;
        n>>=1;
    }

    return res;
}



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

struct st {
	int from, to, c;
};
vector<st>E;
int d[1000];
int main() {
	int v, e, r; scanf("%d%d%d", &v, &e, &r);
	rep(i, e) {
		int s, t, d; scanf("%d%d%d", &s, &t, &d);
		E.push_back({ s,t,d });
	}
	memset(d, 0x3f, sizeof(d));
	d[r] = 0;
	rep(i, v)rep(j, e) {
		st s = E[j];
		if (d[s.from] != INF&&d[s.to] > d[s.from] + s.c) {
			d[s.to] = d[s.from] + s.c;
			if (i == v - 1) {
				puts("NEGATIVE CYCLE"); return 0;
			}
		}
	}
	rep(i, v) {
		if (d[i] == INF)puts("INF");
		else printf("%d\n", d[i]);
	}
}

Measured memory_bytes: 3272
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    String s = sc.next();
    HashSet<String> hs = new HashSet<String>();
    int orglen = s.length();
    for(int i = 0;i<orglen;i++){
      hs.add(s.substring(i,i+1));
    }
    int aftlen = hs.size();
    if(orglen == aftlen){
      System.out.println("yes");
    }else{
      System.out.println("no");
    }
  }
}


Measured memory_bytes: 22996
#include "bits/stdc++.h"
#include <cassert>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a)  (a).begin(),(a).end()
#define vi vector<int>
#define pb push_back
#define INF 999999999
//#define INF (1LL<<59)

//verified AOJ GRL_1
#define MAX_V 100000
struct edge{int to,cost;};
vector<edge> G[MAX_V];

void dijkstra(int s, vector<int> &d){
    priority_queue< pii,vector<pii>,greater<pii> > que;
    rep( i,d.size() )d[i]=INF;
    d[s] = 0;
    que.push( pii(0,s) );
    
    while( que.size() ){
        pii p=que.top();
        que.pop();
        
        int v=p.second;
        if(d[v]<p.first)continue;
        
        rep(i,G[v].size()){
            edge e=G[v][i];
            if(d[e.to]>d[v]+e.cost){
                d[e.to]=d[v]+e.cost;
                que.push(pii(d[e.to],e.to));
            }
        }
    }
}


int main(){
    int v,e,s;
    cin>>v>>e>>s;
    rep(i,e){
        int a,b,c;
        cin>>a>>b>>c;
        G[a].pb(edge{b,c});
    }
    
    vi d(v);
    dijkstra(s,d);
    
    rep(i,v){
        if(d[i]==INF)cout<<"INF"<<endl;
        else cout<<d[i]<<endl;
    }
}

Measured memory_bytes: 13132
// IN THE NAME OF GOD
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define FORD(i,a,b) for(int i=(a);i>=(b);i--)
#define ll long long unsigned int
#define em emplace_back
#define pb push_back
#define INF 1e9+5
#define MOD 1e9+7
#define print printf
#define in scanf
#define LL long long 
using namespace std;
template<class type>
void displaySingle(type &arr)
{
for(auto i:arr)
cout<<i<<" ";
cout<<endl;
}
template<class type>
void displayDouble(type &arr)
{
for(auto i:arr)
cout<<i.first<<" "<<i.second<<endl;
}
int main()
{
int n,k,i;
in("%d %d",&n,&k);
vector<LL>input(n);
REP(i,n)
in("%lld",&input[i]);
vector<ll>dp(n,INF);
dp[0]=0;
for(int i=0;i<n;i++)
{
for(int j=i+1;j<=i+k && j<input.size();j++)
{
dp[j]=min(dp[j],dp[i]+abs(input[i]-input[j]));
}
}
print("%lld\n",dp[dp.size()-1]);
return 0;
}

Measured memory_bytes: 1792
N=int(input())
a_list=list(map(int,input().split()))
counter=0
for i in range (N):
	if a_list[i]%2==0:
		if a_list[i]%3!=0 and a_list[i]%5!=0:
			counter+=1
if counter==0:
	print("APPROVED")
else:
	print("DENIED")

Measured memory_bytes: 3060
import numpy as np


##get int
first_input = list(map(lambda x:int(x), input().split(" ")))
second_input = list(map(lambda x:int(x), input().split(" ")))

##get float
#first_input = list(map(lambda x:float(x), input().split(" ")))
#second_input = list(map(lambda x:float(x), input().split(" ")))

##get string
#first_input = input().split(" ")

K = first_input[0]
N= first_input[1]

A_list = second_input

A_list.append(K+A_list[0])

dist_list = np.array(A_list)[1:]-np.array(A_list)[:-1]

print(sum(dist_list)-max(dist_list))


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

using namespace std;

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

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

  int q[10000];
  for (int i = 0; i < n; i++) {
    q[i] = p[i];
  }
  sort(q,q+n);

  int count = 0;
  for (int i = 0; i < n; i++) {
    if (q[i] != p[i]) {
      count++;
    }
    if (count > 2) {
      break;
    }
  }

  if(count < 3){
    cout << "YES" << endl;
  }
  else{
    cout << "NO" << endl;
  }

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int inf = 0x3f3f3f3f,oo = inf;
#define IL inline
#define RG register
#define rep(i,a,b) for(RG int i=(a);i<int(b);++i)
#define Rep(i,a,b) for(RG int i=(a);i<=(b);++i)
#define Dep(i,a,b) for(RG int i=(a);i>=(b);--i)
#define pc putchar
#define gc getchar
IL ll read(){
    RG ll x=0;char f=0;RG char c=gc();
    for(;!isdigit(c);c=gc())f|=(c=='-');
    for(;isdigit(c);c=gc())x=(x<<1)+(x<<3)+(c^48);
    return f?-x:x;
}
IL void write(ll x){if(x<0)x=-x,pc('-');if(x>=10)write(x/10);pc(x%10+'0');}
IL void writeln(ll x){write(x);puts("");}
#define rd() read()
#define mem(x,v) memset(x,v,sizeof(x))
const ll N=3000010;
ll n,pre[N],suc[N],answ=1e9;char s[N];
int main(){
	n=read();
	scanf("%s",s+1);
	Rep(i,1,n){
		pre[i]=pre[i-1]+(s[i]=='E');
	}
	Dep(i,n,1)suc[i]=suc[i+1]+(s[i]=='W');
	Rep(i,1,n)	answ=min(answ,(i-1-pre[i-1])+(n-i-suc[i+1]));
	writeln(answ);
}
/*
int main(){
	n = rd();
	Rep(i,1,n){
		a[i] = rd();
		s1[i] = s1[i-1] ^ a[i];
		s2[i] = s2[i-1] + a[i];
	}
	int l = 0;
	for(int r=1;r<=n;r++){
		while(s1[r]-s1[l] != s2[r]-s2[l]) ++l;
		ans += 
	}
}*/

Measured memory_bytes: 10752
#include <bits/stdc++.h>
using namespace std;
typedef long long lint;
#define FOR(i, o, n) for (auto i = (o); (i) < (n); ++(i))
#define REP(i, n) FOR(i, 0, n)
#define REPR(i, n) for (auto i = (n)-1; (i) >= 0; --i)
#define REPI(itr, v) for (auto itr = v.begin(); itr != v.end(); ++itr)
#define REPIR(itr, v) for (auto itr = v.rbegin(); itr != v.rend(); ++itr)
#define fi first
#define se second
#define ll long long
#define V2(name, h, w) vector<vector<int> > name((h), vector<int>(w));
int ctoi(const char c){
  switch(c){
    case '0': return 0;
    case '1': return 1;
    case '2': return 2;
    case '3': return 3;
    case '4': return 4;
    case '5': return 5;
    case '6': return 6;
    case '7': return 7;
    case '8': return 8;
    case '9': return 9;
    default : return -1;
  }
}
int main(){
	char S[100]; cin >> S;
	int dates = ctoi(S[5])*1000 + ctoi(S[6])*100 + ctoi(S[8])*10 + ctoi(S[9]);
	if(dates <= 430) cout << "Heisei" << endl;
	else cout << "TBD" << endl;
}


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

typedef long long ll;

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

    int n; cin >> n;
    ll ans = 0LL;
    for (int i = 1; i <= n; i++) {
        if (i%3 == 0 || i%5 == 0) continue;
        ans += i;
    }

    cout << ans;

    return 0;
}


Measured memory_bytes: 3648
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<iomanip>
#include<string>
#include<cmath>
#include<vector>
#include<set>
#include<queue>
#include<stack>
#include<fstream>
#include<map>
#include<bitset>
#include<unordered_map>
#include<cstring>
#include<cctype>
using namespace std;
#define  ll long long
#define  ull unsigned long long
#define  ul unsigned long
#define all(v) v.begin(),v.end()
#define sz(n) (int)n.size()
#define pb(s) push_back(s);
#define format(n) fixed<<setprecision(n)
#define finl "\n"
#define Mohammed_Atef_Hassan fast();
#define mod 1000000007
#define INF LLONG_MAX
#define PI acos(-1)
#define clr(dp,n) memset(dp,n,sizeof dp)
#define ex(n) return cout<<n<<finl,0;
int dx[] = { 0, 1, 0, -1, 1, 1, -1, -1 };
int dy[] = { 1, 0, -1, 0, 1, -1, 1, -1 };
ll fix_mod(ll x, ll y)
{
	return (y + x % y) % y;
}
void fast() {
	std::ios_base::sync_with_stdio(false);
	cin.tie(nullptr); cout.tie(nullptr);
}
char g[1001][1001]; int n, m;
ll mem[1001][1001];
ll solve(int x, int y)
{
	if (x == n || y == m||g[x][y]=='#')return 0;
	if (x == n - 1 && y == m - 1)return 1;
	ll& ret = mem[x][y];
	if(~ret)return ret;
	 ret = solve(x + 1, y) + solve(x, y + 1);
	 return ret %= 1000000007;
}
int main()
{
	Mohammed_Atef_Hassan
		clr(mem, -1);
		cin >> n >> m;
	for (int i = 0; i < n; i++)
		for (int j = 0; j < m; j++)
			cin >> g[i][j];
	cout << solve(0, 0) << finl;
}

Measured memory_bytes: 9216
n = int(input())
b = list(map(int, input().split()))

ans = [b[0]]

for i in range(n-2):
    if b[i] <= b[i+1]:
        ans.append(b[i])
    else:
        ans.append(b[i+1])

ans.append(b[len(b)-1])

print(sum(ans))

Measured memory_bytes: 9148
import sys

def solve():
    input = sys.stdin.readline
    N, M, V, P = map(int, input().split())
    A = [int(a) for a in input().split()]
    A.sort()
    B = A[N - P]
    low, high = -1, N
    while high - low > 1:
        mid = (low + high) // 2
        if mid >= N - P: high = mid
        elif A[mid] + M < B: low = mid
        else:
            border = A[mid] + M
            room = 0
            for i in range(N - P + 1):
                if i != mid: room += min(M, max(0, border - A[i]))
            if room >= max(0, V - P) * M: high = mid
            else: low = mid
            #print(mid, room)
    print(N - high)

    return 0

if __name__ == "__main__":
    solve()

Measured memory_bytes: 14172
#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <algorithm>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <string>
#include <ctime>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <deque>
#include <cassert>
#include <unordered_map>
#include <bitset>
#include <unordered_set>

using namespace std;

#define pb push_back
#define pp pop_back
#define f first
#define s second
#define mp make_pair
#define sz(a) (int)((a).size())
#ifdef _WIN32
#  define I64 "%I64d"
#else
#  define I64 "%lld"
#endif
#define fname "."

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair < int, int > pi;
typedef pair < int, ull > pu;

const int inf = (int)1e9 + 123;
const ll infl = (ll)1e18 + 123;
const double eps = 1e-9;

const int MAX_N = (int)1e5 + 123;
const int mod = (int)1e9 + 7;

int n, m, q;
char a[2002][2002];

int f[3][2002][2002];

int get(int tp, int x, int y, int x2, int y2) {
    if (x > x2 || y > y2)
        return 0;
    int res = f[tp][x2][y2] - f[tp][x - 1][y2] - f[tp][x2][y - 1] + f[tp][x - 1][y - 1];
    return res;
}

int main() {
#ifdef DEBUG
    freopen("input.txt", "r", stdin);
#endif
    ios_base :: sync_with_stdio(0), cin.tie(0), cout.tie(0);
    cin >> n >> m >> q;
    for (int i = 1; i <= n; i++)
        for (int j = 1; j <= m; j++) {
            cin >> a[i][j];
            f[0][i][j] = f[0][i - 1][j] + f[0][i][j - 1] - f[0][i - 1][j - 1] + (a[i][j] == '1');
            f[1][i][j] = f[1][i - 1][j] + f[1][i][j - 1] - f[1][i - 1][j - 1] + (a[i][j] == '1' && a[i - 1][j] == '1');
            f[2][i][j] = f[2][i - 1][j] + f[2][i][j - 1] - f[2][i - 1][j - 1] + (a[i][j] == '1' && a[i][j - 1] == '1');
        }
    for (int i = 1, x, y, x2, y2; i <= q; i++) {
        cin >> x >> y >> x2 >> y2;
        int res = get(0, x, y, x2, y2) - get(1, x + 1, y, x2, y2) - get(2, x, y + 1, x2, y2);
        printf("%d\n", res);
    }
    return 0;
}


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

using namespace std;

bool used[8];
int roads[201][201];
int visitTowns[8];
int minDist=99999999;

void gen(int (&soFar)[8], int depth, int n)
{
    //generate all permutations
    if (depth == n)
    {
        //calculate distance
        int dist=0;
        for (int i = 0; i < n-1; i++)
        {
            dist += roads[visitTowns[soFar[i]]][visitTowns[soFar[i+1]]];
        }
        minDist = min(minDist, dist);
    } else
    {
        for (int i = 0; i < n; i++)
        {
            if (!used[i])
            {
                soFar[depth] = i;
                used[i]=true;
                gen(soFar, depth+1, n);
                used[i] = false;
            }
        }
    }
}

int main()
{
    for (int i = 0; i < 8; i++)
    {
        used[i] = false;
    }

    int towns, numRoads, n;
    cin >> towns >> numRoads >> n;

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

    for (int i = 1; i <= 200; i++)
    {
        for (int j = 1; j <= 200; j++)
        {
            if (i == j)
            {
                roads[i][j] = 0;
            } else
            {
                roads[i][j] = 99999999;
            }
        }
    }

    for (int i = 0; i < numRoads; i++)
    {
        int from, to, dist;
        cin >> from >> to >> dist;
        //if (roads[from][to] > dist)
        //{
            roads[from][to] = dist;
            roads[to][from] = dist;
        //}
    }

    //floyd-warshall
    for (int k = 1; k <= towns; k++)
    {
        for (int i = 1; i <= towns; i++)
        {
            for (int j = 1; j <= towns; j++)
            {
                roads[i][j] = min(roads[i][j], roads[i][k]+roads[k][j]);
            }
        }
    }

    /*for (int i = 1; i <= towns; i++)
    {
        for (int j = 1; j <= towns; j++)
        {
            cout << roads[i][j] << " ";
        }
        cout << endl;
    }*/

    int x[8];
    gen(x, 0, n);

    cout << minDist << endl;
    return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <cmath>
using namespace std;
int calc(int a,int b,int c){
    return a*10000+b*5000+c*1000;
}
int main(void){
    // Your code here!
    int n;
    cin >> n ;
    int c[n],s[n],f[n];
    for(int i=0;i<n-1;i++){
        cin >> c[i] >> s[i] >> f[i];
    }
    for(int i=0;i<n-1;i++){
        int ans = 0;
        for(int j=i;j<n-1;j++){
            if(s[j]>=ans) ans = s[j];
            else ans = ceil((double)(ans-s[j])/(double)f[j])*f[j] + s[j];
            ans += c[j];
        }
        cout << ans << endl;
    }
    cout << 0 << endl;
}



Measured memory_bytes: 256
n = int(input())
csf = [list(map(int, input().split())) for _ in range(n-1)]

for i in range(n-1):
  t = 0
  for j in range(i, n-1):
    if csf[j][1]>t:
      t+=(csf[j][1]-t)
    if t%csf[j][2]!=0:
      t+=(csf[j][2]-t%csf[j][2])
    t+=csf[j][0]
  print(t)
print(0)

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

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rrep(i, n) for(int i = ((int)(n)-1); i >= 0; i--)
#define all(x) (x).begin(),(x).end()

using namespace std;
using ll = long long;

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> P;
 
const int INF = 1e9;
//const ll INF = 1e18;
const double EPS = 1e-10;
const int MOD = 1e9+7;
const double PI = acos(-1.0);

int main()
{
	int n,m,c;
	cin >> n >> m >> c;
	vi b(m);
	rep(i,m) cin >> b[i];
	int ans = 0;
	for(int i = 0; i < n; i++){
		int sum = c;
		for(int j = 0; j < m; j++){
			int a; cin >> a;
			sum += a*b[j];
		}
		if(sum > 0) ans++;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
fun main(args:Array<String>){
  var s = readLine()!!.toInt()
  var a = s/100
  var b = s%100
  if(b<13 && 0<b){
    if(a<13 && 0<a){
      println("AMBIGUOUS")
    }
    else{
      println("YYMM")
    }
  }
  else{
    if(a<13 && 0<a ){
      println("MMYY")
    }
    else{
      println("NA")
    }
  }
}

Measured memory_bytes: 29944
def coloring():
    line = input()
    words = line.split()
    W = int(words[0])
    H = int(words[1])
    N = int(words[2])

    x = 0
    y = 0
    w = W
    h = H

    grid = []

    for i in range(h):
        for j in range(w):
            grid.append(0)

    for i in range(N):
        s = input()
        ws = s.split()
        x = int(ws[0])
        y = int(ws[1])
        a = int(ws[2])
        if a == 1:
            #rect = x * whole
            for i in range(h):
                for j in range(x):
                    grid[j + w * i] = 1

        if a == 2:
            #rect = (w - x) * whole
            for i in range(h):
                for j in range(x,w):
                    grid[j + w*i] = 1

        if a==3:
            #rect = whole * y
            for i in range(y):
                for j in range(w):
                    grid[j + w * i] = 1
        
        if a == 4:
            #rect = whole * (h - y)
            for i in range(y,h):
                for j in range(w):
                    grid[j + w*i] = 1

        
    print(grid.count(0))


coloring()

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

int main() {

    int N;
    cin >> N;
    vector<int> X(N);
    vector<int> Y(N);
    for(int i=0;i<N;i++){
        cin >> X.at(i) >> Y.at(i);
    }
    double distance;
    int xd, yd;
    double ave = 0;
    double divide = 1.0;
    for(int i=1;i<=N;i++){
        divide *= i;
    }
    double mul = divide / N;
    for(int i=0;i<N;i++){
        for(int j=i+1;j<N;j++){
            xd = X.at(i) - X.at(j);
            yd = Y.at(i) - Y.at(j);
            distance = sqrt(xd*xd + yd*yd);
            ave += distance * mul * 2.0 / divide;
        }
    }
    cout << setprecision(14) << ave;
    return 0;

}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws IOException {
		int n = 0; // ????????????????????°
		String str;
		String num;
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		num = br.readLine(); //????????????????????°??\???
		n = Integer.parseInt(num);
		for(int i = 0 ; i < n; ++i){
			str = br.readLine();
			str = str.replace("Hoshino", "Hoshina");
			System.out.println(str);
		}
	}

}

Measured memory_bytes: 24216
n = int(input())
m1, m1_index = 0, 0
m2, m2_index = 0, 0
for i in range(n):
    a = int(input())
    if a > m1:
        m1 = a
        m1_index = i
    elif a > m2:
        m2 = a
for i in range(n):
    if i != m1_index:
        print(m1)
    else:
        print(m2)

Measured memory_bytes: 4668
#include <cstdio>
#include <queue>

char field[1000][1001];

struct XY
{
  int x;
  int y;
  int g;
};

int main()
{
  int H, W;
  scanf("%d %d", &H, &W);
  
  std::queue<XY> q;
  for (int i = 0; i < H; ++i)
  {
    scanf("%s", field[i]);
    for (char *p = field[i]; *p; ++p)
    {
      if (*p == '#')
      {
        q.push(XY{p - field[i], i, 0});
      }
    }
  }
  
  const int dir[] = {0, 1, 0, -1, 0};
  int ans = 0;
  while (q.size() > 0)
  {
    XY c = q.front();
    q.pop();
    if (ans < c.g)
    {
      ans = c.g;
    }
    for (int i = 0; i < 4; ++i)
    {
      int X = c.x + dir[i + 1];
      int Y = c.y + dir[i];
      if (0 <= X && X < W && 0 <= Y && Y < H && field[Y][X] == '.')
      {
        field[Y][X] = '#';
        q.push(XY{X, Y, c.g + 1});
      }
    }
  }
  printf("%d\n", ans);
  return 0;
}

Measured memory_bytes: 13328
#include <algorithm>
#include <cassert>
#include <iostream>
#include <vector>
using namespace std;

int N, Q;
vector<long long> starts;
vector<long long> D;
vector<long long> fail;

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

    cin >> N;
    starts.resize(N);
    D.resize(N);

    cin >> starts[0];

    for (auto &d : D)
        cin >> d;

    for (int i = 0; i < N - 1; i++)
        starts[i + 1] = min(starts[i], abs(starts[i] - D[i]));

    fail.resize(N + 1);
    fail[N] = 1;

    for (int i = N - 1; i >= 0; i--)
        fail[i] = D[i] < 2 * fail[i + 1] ? D[i] + fail[i + 1] : fail[i + 1];

    cin >> Q;

    for (int q = 0; q < Q; q++) {
        int index;
        cin >> index;
        index--;
        bool answer = starts[index] >= fail[index + 1];
        cout << (answer ? "YES" : "NO") << '\n';
    }
}


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

int main(){
  int N;
  string s;
  cin >> N;
  
  for(int i = 0; i < N; i++){
    cin >> s;
    if(s == "Y"){
      cout << "Four" << endl;
      break;
    }
    else if(i == (N - 1) && s != "Y"){
      cout << "Three" << endl;
    }  
  }
}




Measured memory_bytes: 256
import sys

N = int(sys.stdin.readline())
A = list(map(int, sys.stdin.readline().split()))

sum_rain = sum(A)

# 山0以外の雨の総和
rest = 0
for i in range(1, N, 2):
    rest += A[i] * 2

rains = [0 for _ in range(N)]
rains[0] = sum_rain - rest
for i in range(1, N):
    rains[i] = (A[i-1] - rains[i-1] // 2) * 2

print(*rains)

Measured memory_bytes: 19944
from heapq import *
from collections import deque

intinf = 10 ** 15

def bfs_01(n, graph, start):
    min_distance = [intinf] * n

    deq = deque()
    min_distance[start] = 0
    deq.append(start)

    while deq:
        src = deq.popleft()
        for dst, cost in graph[src]:
            next_d = min_distance[src] + cost
            if min_distance[dst] <= next_d:
                continue

            min_distance[dst] = next_d
            if cost == 0:
                deq.appendleft(dst)
            elif cost == 1:
                deq.append(dst)
            else:
                print('invalid cost in graph')
                raise ValueError

    return min_distance

def dijkstra(n, graph, start):
    min_distance = [intinf] * n

    # min-heap of (distance, vertex)
    heap = []

    heappush(heap, (0, start))
    min_distance[start] = 0

    while heap != []:
        d, src = heappop(heap)
        if min_distance[src] < d:
            continue
        for dst, cost in graph[src]:
            next_d = d + cost
            if next_d < min_distance[dst]:
                min_distance[dst] = next_d
                heappush(heap, (next_d, dst))

    return min_distance

def main():
    K = int(input())

    # (v, c) in graph[u] <=> u -> v with cost = c
    graph = [[] for _ in range(K)]

    for i in range(K):
        graph[i].append(((i+1) % K, 1))
        graph[i].append((i * 10 % K, 0))

    dist = dijkstra(K, graph, 1)
    # dist = bfs_01(K, graph, 1)

    print(dist[0] + 1)

if __name__ == '__main__':
    main()



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

class Cube{
public:
    int face[6];

    Cube(){}

    void roll(char direction) {
        if (direction == 'N') {
            int t = face[0];
            face[0] = face[1];
            face[1] = face[5];
            face[5] = face[4];
            face[4] = t;
        } else if (direction == 'S') {
            int t = face[0];
            face[0] = face[4];
            face[4] = face[5];
            face[5] = face[1];
            face[1] = t;
        } else if (direction == 'E') {
            int t = face[0];
            face[0] = face[3];
            face[3] = face[5];
            face[5] = face[2];
            face[2] = t;
        } else if (direction == 'W') {
            int t = face[0];
            face[0] = face[2];
            face[2] = face[5];
            face[5] = face[3];
            face[3] = t;
        }
    }
};

int main() {
    int default_face[6];
    int n, a, b;

    Cube c;
    for (int i = 0; i < 6; i++) cin >> c.face[i];

    cin >> n;

    for (int i = 0; i < n; i++) {
        cin >> a >> b;

        while (true) {
            if (b == c.face[1]) {
                break;
            } else if (b == c.face[2] || b == c.face[3]) {
                c.roll('W');
            } else {
                c.roll('N');
            }
        }

        while (true) {
            if (a == c.face[0]) {
                break;
            } else {
                c.roll('W');
            }
        }

        cout << c.face[2] << endl;
    }

    return 0;
}



Measured memory_bytes: 3076
open Batteries
module EnumL = Enum.Labels
module ListL = List.Labels
module ArrayL = Array.Labels

let dbg0 x = Printf.eprintf "[debug]%s\n" @@ dump x
let dbg1 x = dbg0 x; x

let id = identity

let (++) n m = List.range n `To m
let (++-) n m = if n >= m then List.range n `Downto m else []
let (++^) n m = if n < m then List.range n `To (pred m) else []

let scan fmt = Scanf.sscanf (read_line ()) fmt

let scan_lines n fmt f =
  if n = 0 then []
  else List.map (fun _ -> scan fmt f) (1 ++ n)

let scan_list sep cnv =
  let line = read_line () in
  (match sep with
   | None -> List.map String.of_char @@ String.to_list line
   | Some sep -> String.split_on_char sep line)
  |> List.map cnv

let scan_array ?sep cnv = Array.of_list @@ scan_list sep cnv

let scan_matrix n m e ?sep conv =
  let arr = Array.make_matrix n m e in
  ListL.iter (0 ++^ n)
    ~f:(fun i -> arr.(i) <- Array.of_list @@ scan_list sep conv);
  arr

let rec powerset e =
  match Enum.get e with
  | None -> Enum.singleton @@ Enum.empty ()
  | Some v ->
    let f = powerset e in
    let g = Enum.clone f in
    EnumL.map f ~f:(fun x -> let y = Enum.clone x in push y v; y)
    |>  Enum.append g

let permutations l =
  let rec aux l =
    let rec interleave x = function
      | [] -> [[x]]
      | (hd::tl) as lst ->
        (x::lst) ::
        (ListL.map ~f:(List.cons hd)  @@ interleave x tl)
    in
    match l with
    | [] -> [[]]
    | hd::tl -> List.concat @@ List.map (interleave hd) @@ aux tl in
  let l = List.sort (List.compare Int.compare) @@ aux @@ List.of_enum l in
  List.enum % ListL.map ~f:List.enum @@ l

let intersection l =
  EnumL.filter ~f:(fun x -> EnumL.exists ~f:((=) x) @@ Enum.clone l)

let zip l m =
  let n = min (List.length l) (List.length m) in
  List.combine (List.take n l) (List.take n m)

let lower_bound n f =
  let rec aux l u =
    if u - l > 1 then
      let m = (l + u) / 2 in
      if f m then aux l m
      else aux m u
    else u in aux (-1) n

let between n x m = n <= x && x < m

let s = scan "%s" id

let map_predi ~init ~f =
  let rec aux n pred = function
    | [] -> []
    | x::rest ->
      let cur = f n pred x in
      cur :: aux (succ n) cur rest
  in aux 0 init

let rec pow_mod n m =
  if m = 0 then 1
  else if m mod 2 = 0 then
    pow_mod (n*n mod 2019) (m/2)
  else
    n * (pow_mod (n*n mod 2019) ((pred m)/ 2)) mod 2019

let count_list l =
  let h = Hashtbl.create 0 in
  ListL.iter l ~f:(fun i ->
      Hashtbl.replace h i @@ succ @@ Hashtbl.find_default h i 0);
  Hashtbl.to_list h

let () =
  let l =
    0::(String.to_list s
        |> List.rev
        |> map_predi ~init:0 ~f:(fun i pred c ->
            let ( * ) n m = n * m mod 2019 in
            let (+) n m = (n + m) mod 2019 in
            let n = Char.code c - Char.code '0' in
            ((n*pow_mod 10 i) + pred))) in
  count_list l
  |> ListL.map ~f:(fun (_, m) -> m*(m-1)/2)
  |> List.sum
  |> Printf.printf "%d\n"


Measured memory_bytes: 29716
#include <stdio.h>
#import <Foundation/Foundation.h>

int main(int argc, const char * argv[]) {
    char T[101];
    char S[101];
    char TS[201];
    scanf("%s", S);
    scanf("%s", T);
     printf("%s", T);
    int i = 0;
    while (T[i] != '\0') {
      TS[i] = T[i];
      i++;
    }
    i = 0;
    while (S[i] != '\0') {
      TS[i] = S[i];
      i++;
    }
    TS[i] = '\0';
    printf("%s", TS);
    return 0;
}

Measured memory_bytes: 128
# util functions

# debug
$debugFlag = ( ARGV[0] != nil )
p "==== DEBUG MODE ====" if $debugFlag

def pd(str)
  p str if $debugFlag
end

# input
inputs = []
lc = 0
while l = $stdin.gets do
  if false
    inputs << l.chomp.split(" ").map(&:to_s)
  else
    inputs << l.chomp.split(" ").map(&:to_i)
  end
  lc += 1
end


# input check
if $debugFlag
  p "--- INPUT (begin) ---"
  inputs.each do |l_i|
    p l_i
  end
  p "--- INPUT (end) ---"
  print "\n"
end

input = inputs[0]

# body
if $debugFlag
end

aa = input[0]
bb = input[1]
cc = input[2]
dd = input[3]

cnt = 0
for i in 0..100 do
  cnt += 1 if aa <= i and i <= bb and cc <= i and i <= dd
end

puts [cnt-1, 0].max


Measured memory_bytes: 3836
#include <cstdio>

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

int main()
{
  int sum = 0;
  for(int i=0;i<6;i++){
    int x;
    scanf("%d", &x);
    sum += x * m[i];
  }

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

Measured memory_bytes: 1028
#include<iostream>
#include<math.h>
#include<vector>
#include<algorithm>
#include<numeric>
#include<map>
#include<queue>
using namespace std;

int main(){
    int N,K,x[100010],ans=pow(10,9);cin>>N>>K;
    for(int i=0;i<N;i++)
        cin>>x[i];
    
    int i=0;
    while(x[i+K-1]<=0){
        ans=min(ans,-x[i]);
        i++;
        if(i==N-K+1)goto lol1;
    }
    while(x[i]<=0){
        int c=x[i+K-1]-x[i]+min(x[i+K-1],-x[i]);
        ans=min(ans,c);
        i++;
        if(i==N-K+1)goto lol2;
    }
    while(true){
        ans=min(ans,x[i+K-1]);
        i++;
        if(i==N-K+1)goto lol3;
    }
    lol1:lol2:lol3:
    cout<<ans<<endl;
    return 0;

}

Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <map>
using namespace std;
typedef long long ll;
#define rep(i,n) for (int i=0;i < (int)(n);i++)

int main(){
  int n;
  cin >> n;
  string s = "";
  while(n != 0){
    int r = n%2;
    if (r < 0) r +=2;
    n = (n-r)/(-2);
    s += (char)('0' + r);
  }
  reverse(s.begin(),s.end());
  if (s == "") s = "0";
  cout << s << endl;
  
}


Measured memory_bytes: 3612
#include <cstdio>
#include <algorithm>
#define N 200010
using namespace std;
typedef long long ll;
ll n, ans, pr[N];
struct st{ll x, y, z;} a[N/2], b[N];

bool cmp1(st p, st q) {return p.x<q.x;}
bool cmp2(st p, st q) {return p.y<q.y;}
bool cmp3(st p, st q) {return p.z<q.z;}
ll f(ll p) {
	if(pr[p]==p) return p;
	return pr[p] = f(pr[p]);
}

int main() {
	ll i, x, y;
	scanf("%lld", &n);
	for(i=1; i<=n; i++) scanf("%lld%lld", &a[i].x, &a[i].y), a[i].z=pr[i]=i;
	sort(a+1, a+n+1, cmp1);
	for(i=1; i<n; i++) b[i] = {a[i].z, a[i+1].z, a[i+1].x-a[i].x};
	sort(a+1, a+n+1, cmp2);
	for(i=1; i<n; i++) b[i+n-1] = {a[i].z, a[i+1].z, a[i+1].y-a[i].y};
	sort(b+1, b+2*n-1, cmp3);
	for(i=1; i<2*n-1; i++) {
		x = f(b[i].x), y = f(b[i].y);
		if(x!=y) ans += b[i].z, pr[y] = x;
	}
	printf("%lld", ans);
	return 0;
}

Measured memory_bytes: 8320
#include <cmath>
#include <iostream>
#include <vector>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <bitset>
#include <algorithm>
#include <functional>
#include <utility>
#include <iomanip>
#define int long long int
#define mod(x) ((x % MOD) + MOD) % MOD
#define rep(i,a,b) for(int i=(a);i<(b);++i)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);--i)

#define ALL(a) (a).begin(),(a).end()
#define SIZE(a) (int)((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl;

using namespace std;

typedef pair<int,int> P;
struct edge {
  int to, cost;
};

const int INF = 1e18;
const int MOD = 1e9+7;

template<typename T> ostream& operator<<(ostream& s, const vector<T>& v) {
  int len = v.size();
  for (int i = 0; i < len; ++i) {
    s << v[i]; if (i < len - 1) s << " ";
  }
  return s;
}

class BIT
{
  private:
    vector<int> bit;
    int len;
  public:
    BIT(int n);
    void add(int i, int x);
    int sum(int i);
};

BIT::BIT(int n) {
  len = n+1;
  bit = vector<int>(len);
}
void BIT::add(int i, int x) {
  i += 1;
  while (i <= len) {
    bit[i] += x;
    i += i & -i;
  }
}
int BIT::sum(int i) {
  i += 1;
  int s = 0;
  while (i > 0) {
    s += bit[i];
    i -= i & -i;
  }
  return s;
}

class BIT_2D
{
  private:
    vector<BIT> bit;
    int len;
  public:
    BIT_2D(int n);
    void add(int i, int j, int x);
    int sum(int i, int j);
};

BIT_2D::BIT_2D(int n) {
  len = n+1;
  bit = vector<BIT>(len, BIT(n));
}
void BIT_2D::add(int i, int j, int x) {
  i += 1;
  while (i <= len) {
    bit[i].add(j, x);
    i += i & -i;
  }
}
int BIT_2D::sum(int i, int j) {
  i += 1;
  int s = 0;
  while (i > 0) {
    s += bit[i].sum(j);
    i -= i & -i;
  }
  return s;
}


signed main()
{
  int N, K;
  cin >> N >> K;
  BIT_2D s(K);
  int x, y; char c;
  int white = 0;
  rep(i, 0, N) {
    cin >> x >> y >> c;
    int l = (x % (2*K) < K) ? 0 : 1;
    int m = (y % (2*K) < K) ? 0 : 1;
    int n = (c == 'B') ? 0 : 1;
    if ((l+m+n) % 2 == 0) {
      s.add(x % K, y % K,  1);
    } else {
      s.add(x % K, y % K, -1);
      white++;
    }
  }

  int ans = -INF;
  rep(i, 0, K) {
    rep(j, 0, K) {
      ans = max(s.sum(K-1, K-1) - s.sum(i, K-1) - s.sum(K-1, j) + 2*s.sum(i, j), ans);
      ans = max(s.sum(i, K-1) + s.sum(K-1, j) - 2*s.sum(i, j), ans);
    }
  }

  cout << ans + white << endl;

  return 0;
}


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

int PrimeNum(int N){
    bool jud = true;
    for (int i=2; i<N; i++){
        if (N%i==0){
            jud = false;
            break;
        }
    }
    if (jud == true) return true;
    else return false;
}

int main(){
    int x;
    cin>>x;
    while(true){
        if (PrimeNum(x)==true){
            cout << x;
            return 0;
        }
        x++;
    }
}

Measured memory_bytes: 3624
from math import sqrt


def distance_calculator(coordinates1, coordinates2, d):
    distance = 0
    for i in range(d):
        distance += (coordinates1[i] - coordinates2[i]) ** 2
    return sqrt(distance)


n, d = map(int, input().split())
points = [[]] * n
for i in range(n):
    points[i] = list(map(int, input().split()))
answer = 0
for i in range(n):
    for j in range(i + 1, n):
        distance = distance_calculator(points[i], points[j], d)
        if int(distance) == distance:
            answer += 1
print(answer)


Measured memory_bytes: 3064
#include<bits/stdc++.h>
 
#define lli long long int
#define endl "\n"
 
using namespace std;
 
typedef long long int LLI;
typedef double DB;
 
void fastio()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
}
 
 
bool comparator(pair<lli,lli> a,pair<lli,lli> b)
{
    if(a.first>b.first)
        return true;
    else if (a.first==b.second)
    {
        if(a.second>=b.second)
            return false;
        return true;
    }
    return false;
}
 
int mods(int x)
{
    if(x>0)
        return x;
    return -x;
}
 
lli gcd(lli a,lli b)
{
    return __gcd(a,b);
}
 
lli lcm(lli x,lli y,lli z)
{
    lli j=gcd(x,y);
    lli k=gcd(y*x/j,z);
    return (((x*y)/j)*z)/k;
} 

int isprime(int n)
{
    for(int i=2;i<=sqrt(n);++i)
    {
        if(n%i==0) return 0;
    }
    return 1;
}

int main()
{
    fastio();
    int n,x; cin>>n>>x; int arr[n]; for(int i=0;i<n;++i) cin>>arr[i];
    sort(arr,arr+n);
    for(int i=0;i<n;++i)
    {
        x-=arr[i]; if(x<0) {cout<<i; return 0;}
        if(i==n-1) 
        { 
            if(x>0) {--i;} 
            cout<<i+1; return 0;
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int l;
int a;
int b;
int c;
int d;
int main(){
	cin >> l;
	cin >> a;
	cin >> b;
	cin >> c;
	cin >> d;
	if (a / c > b / d){
		if (a%c== 0){
			cout << l - a / c << endl;
		}
		else cout << l - a / c - 1 << endl;
	}
	if (a / c < b / d){
		if (b % d== 0){
				cout << l - b / d << endl;
			}
		else cout << l - b / d - 1 << endl;
	}
	if (a / c == b / d){
		if (a%c == 0 || b%d == 0){
			cout << l - a / c << endl;
		}
		else cout << l - a / c - 1 << endl;
	}

	return 0;
}

Measured memory_bytes: 3088
#include <iostream>
#include <vector>
#include <iterator>
#include <algorithm>
#include <string>
#include <map>
#include <list>
using namespace std;

int main() {
  int sx,sy,tx,ty;
  cin >> sx >> sy >> tx >> ty;

  string s;
  for(int i = 0; i < tx - sx; ++i){
    s += 'R';
  }

  for(int i = 0; i < ty - sy; ++i){
    s += 'U';
  }
  
  for(int i = 0; i < tx - sx; ++i){
    s += 'L';
  }
  
  for(int i = 0; i < ty - sy; ++i){
    s += 'D';
  }

  //二巡目
  s += 'D';
  for(int i = 0; i < tx - sx + 1; ++i){
    s += 'R';
  }

  for(int i = 0; i < ty - sy + 1; ++i){
    s += 'U';
  }

  s += 'L';
  s += 'U';
  for(int i = 0; i < tx - sx + 1; ++i){
    s += 'L';
  }
  
  for(int i = 0; i < ty - sy + 1; ++i){
    s += 'D';
  }
  s += 'R';
  cout << s << endl;
}



Measured memory_bytes: 3680
#include <cstdio>
#include <memory.h>
#include <cstring>
#include <vector>
#include <deque>
#include <cstdlib>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cassert>
#include <functional>
#include <iostream>
#include <set>
#include <list>
#include <map>
#include <time.h>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
using namespace std;

typedef long long ll;
typedef unsigned long long llu;
typedef pair<int, int> pii;
typedef pair<int, pii> piii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<int, ll> pil;
typedef pair<string, int> psi;
const ll MOD = 1e9 + 7;
const long double PI = 3.141592653589793238462643383279502884197;

priority_queue<int, vector<int>, greater<int> > pq;
vector<int> v;

int n;
double dp[301][301][301];
int cnt[3];

double go(int a, int b, int c) {
	if (a == 0 && b == 0 && c == 0) return 0;
	if (dp[a][b][c] > -1) return dp[a][b][c];

	// 오퍼레이션 수 구하는거니까.
	double ret = 0; 
	if (a) ret += go(a - 1, b, c) * ((double)a / n);
	if (b) ret += go(a + 1, b - 1, c) * ((double)b / n);
	if (c) ret += go(a, b + 1, c - 1) * ((double)c / n);
	ret += 1;

	ret = ret * ((double)n / (a + b + c));

	return dp[a][b][c] = ret;
}

int main() {
	int t;
	for (int i = 0; i < 301; i++)
		for (int j = 0; j < 301; j++)
			for (int k = 0; k < 301; k++)
				dp[i][j][k] = -2;

	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		scanf("%d", &t);
		cnt[--t]++;
	}

	printf("%.10lf", go(cnt[0], cnt[1], cnt[2]));
}

Measured memory_bytes: 213376
import java.util.Scanner;

class Main
{
	public static void main(String args[])
	{
		Scanner sc = new Scanner(System.in);
		while (true)
		{
			String str = sc.next();
			if (str.charAt(0) == '0') break;
			int a = 0, b = 0;
			int length = str.length();
			for (int i = 1; i < length; i++)
			{
				if (str.charAt(i) == 'A')
					a++;
				else
					b++;
			}
			if (a > b)
				System.out.printf("%d %d\n", a+1, b);
			else
				System.out.printf("%d %d\n", a, b+1);
		}
	}
}

Measured memory_bytes: 12000
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>

using namespace std;

int main() {
	int s = 0;
	int e = 0;
	int n = 0;
	int w = 0;
	int cou = 0;
	string m;

	cin >> m;

	for (int i = 0; i < m.size(); i++) {
		if (m[i] == 'S') {
			s = s + 1;
		}if (m[i] == 'E') {
			e = e + 1;
		}if (m[i] == 'N') {
			n = n + 1;
		}if (m[i] == 'W') {
			w = w + 1;
		}
	}

	if (s>0&&n>0&&e>0&&w>0) {
		cout << "Yes" << endl;
	}else if (s==0&&n==0 && e>0 && w>0) {
		cout << "Yes" << endl;
	}else if (e==0&&w==0&& s>0 && n>0) {
		cout << "Yes" << endl;
	}else {
		cout << "No" << endl;
	}

	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(){

	int i,temp;
	int n;
	int a,b,c;
	
	scanf("%d",&n);
	
	for(i=0;i<n;i++){
		scanf("%d %d %d",&a,&b,&c);
		
		if(a < b){temp=a;a=b;b=temp;}
		if(a < c){temp=a;a=c;c=temp;}
		
		if(a*a == b*b + c*c)
			printf("YES\n");
		else
			printf("NO\n");
	}

	return 0;
}

Measured memory_bytes: 580
###==================================================
### import
#import bisect
#from collections import Counter, deque, defaultdict
#from copy import deepcopy
#from functools import reduce, lru_cache
#from heapq import heappush, heappop
#import itertools
#import math
#import string
import sys
### stdin
def input(): return sys.stdin.readline().rstrip()
def iIn(): return int(input())
def iInM(): return map(int, input().split())
def iInM1(): return map(int1, input().split())
def iInLH(): return list(map(int, input().split()))
def iInLH1(): return list(map(int1, input().split()))
def iInLV(n): return [iIn() for _ in range(n)]
def iInLV1(n): return [iIn()-1 for _ in range(n)]
def iInLD(n): return [iInLH() for _ in range(n)]
def iInLD1(n): return [iInLH1() for _ in range(n)]
def sInLH(): return list(input().split())
def sInLV(n): return [input().rstrip('\n') for _ in range(n)]
def sInLD(n): return [sInLH() for _ in range(n)]
### stdout
def OutH(lst, deli=' '): print(deli.join(map(str, lst)))
def OutV(lst): print('\n'.join(map(str, lst)))
### setting
sys.setrecursionlimit(10 ** 6)
### utils
int1 = lambda x: int(x) - 1
### constants
INF = int(1e9)
MOD = 1000000007
dx = (-1, 0, 1, 0)
dy = (0, -1, 0, 1)
###---------------------------------------------------

N = input()

bool_1 = (N[0] == N[1] and N[1] == N[2])
bool_2 = (N[1] == N[2] and N[2] == N[3])
ans = 'Yes' if (bool_1 or bool_2) else 'No'
print(ans)




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

using ll = long long;
using ull = unsigned long long;
using ld = long double;

#define forn(i, a, n) for (int i = a; i < n; ++i)
#define ford(i, a, n) for (int i = n - 1; i >= a; --i)
#define fore(i, a, n) for (int i = a; i <= n; ++i)
#define all(a) (a).begin(), (a).end()
#define fs first
#define sn second
#define trace(a)\
    for (auto i : a) cerr << i << ' ';\
    cerr << '\n'
#define eb emplace_back

#ifndef M_PI
const ld M_PI = acos(-1.0);
#endif

const ld eps = 1e-9;
const int INF = 2000000000;
const ll LINF = 1ll * INF * INF;
const ll MOD = 1000000007;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    string s;
    cin >> s;
    int n = s.length();
    int ans = INF;
    {
        bool ok = true;
        forn(i, 0, n)
            if (s[i] != s[0])
                ok = false;
        if (ok) ans = 0;
    }
    forn(i, 0, 26) {
        vector<int> a(n);
        forn(j, 0, n) a[j] = (s[j] == 'a' + i);
        int sz = n;
        while (sz) {
            vector<int> b(sz - 1);
            forn(j, 0, sz - 1)
                b[j] = max(a[j], a[j + 1]);
            bool ok = true;
            forn(j, 0, sz - 1)
                if (b[j] == 0)
                    ok = false;
            --sz;
            if (ok) {
                ans = min(ans, n - sz);
                break;
            }
            a = b;
        }
    }
    cout << ans << '\n';
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <algorithm>
 
using namespace std;
 
 
int memo[2][2048][2048];
int M, N;
char s[2048], t[2048];
char st[] = "IO";
 
int getMax(bool sel, int ns, int nt)
{
	if (ns == M && nt == N){
		return (0);
	}
	if (~memo[sel][ns][nt]) return (memo[sel][ns][nt]);
	
	int res = 0;
	//bool flag = false;
	if (ns < M){
		if (s[ns] == st[sel]){
			//flag = true;
			res = max(res, getMax(sel ^ 1, ns + 1, nt) + 1);
		}
	}
	if (nt < N){
		if (t[nt] == st[sel]){
			//flag = true;
			res = max(res, getMax(sel ^ 1, ns, nt + 1) + 1);
		}
	}
	
	return (memo[sel][ns][nt] = res);
}
 
int main()
{
	
	scanf("%d %d", &M, &N);
	scanf("%s", s);
	scanf("%s", t);
	
	memset(memo, -1, sizeof(memo));
	
	int ans = 0;
	for (int i = 0; i <= M; i++){
		for (int j = 0; j <= N; j++){
			if (getMax(0, i, j) & 1){
				ans = max(ans, getMax(0, i, j));
			}
			else {
				ans = max(ans, getMax(0, i, j) - 1);
			}
		}
	}
	
	printf("%d\n", ans); 
	
	return (0);
}

Measured memory_bytes: 34116
import java.util.*;
public class Main {
	public static void main(String[] args){
       Scanner sc = new Scanner(System.in);
      // 取得
	  String s = sc.next();
      if(con1(s) && con2(s) && con3(s)){
        System.out.println("AC");
      }else{
        System.out.println("WA");
      }
    }
    //一つ目の条件
    static boolean con1(String s){
      if(s.charAt(0)=='A'){
        return true;
      }else{
        return false;
      }
    }
    //二つ目の条件
    static boolean con2(String s){
      int count =0;
      String str = s.substring(2,s.length()-1);
      for(int i=0;i<str.length();i++){
        if(str.charAt(i)=='C'){
          count++;
        }
      }
      if(count==1){
        return true;
      }else{
        return false;
      }
    }
    //三つ目の条件
    static boolean con3(String s){
      int count=0;
      for(int i=0;i<s.length();i++){
        if(Character.isUpperCase(s.charAt(i))){
          count++;
        }
      }
      if(count==2){
        return true;
      }else{
        return false;
      }
    }
}

Measured memory_bytes: 35560
#define _USE_MATH_DEFINES
#include<iostream>
#include<cmath>
using namespace std;

int main() {
	double r;
	double area, circumference;
	cin >> r;

	area = r * r * M_PI;
	circumference = 2 * r * M_PI;

	cout.precision(6);
	cout << fixed << area << " " << fixed << circumference << endl;

	return 0;
}


Measured memory_bytes: 3236
# B - Two Colors Card Game
from collections import Counter
n = int(input())
n_dict = {}
for _ in range(n):
    ns = str(input().split())
    if ns not in n_dict.keys():
        n_dict[ns] = 1
    else:
        n_dict[ns] += 1

m = int(input())
m_dict = {}
for _ in range(m):
    ms = str(input().split())
    if ms not in m_dict.keys():
        m_dict[ms] = 1
    else:
        m_dict[ms] += 1

delta = dict(Counter(n_dict) - Counter(m_dict))
if len(delta)>0:
  ans = max(delta.values())
else:
  ans = 0
print(ans)

Measured memory_bytes: 3316