akhauriyash/Code-Regression huggingface dataset:
object Main {
  def main(args: Array[String]) {
    val factors = scala.io.StdIn.readLine().split(" ").map{_.toInt}
    val x_difference = factors(2) - factors(0)
    val y_difference = factors(3) - factors(1)
    val x_3 = factors(2) - y_difference
    val y_3 = factors(3) + x_difference
    val x_4 = x_3 - x_difference
    val y_4 = y_3 - y_difference

    println(x_3.toString + " " + y_3.toString + " " + x_4.toString + " " + y_4.toString)
  }
}


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

const double EPS = 1e-10;
const ll INF = 100000000;
const ll MOD = 1000000007;

int a, b, c, x;
int dp[100000];

int main(){
    int ans = 0;
    cin >> a >> b >> c >> x;
    for (int i = 0; i <= a; i++) {
        for (int j = 0; j <= b; j++) {
            for (int k = 0; k <= c; k++) {
                if (x == i*500+j*100+k*50) ans++;
            }
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
N, X = map(int, input().split())
As = [1]
Ps = [1]
for i in range(N):
    As.append(As[i] * 2 + 3)
    Ps.append(Ps[i] * 2 + 1)

def f(n, x):
    if n == 0:
        return 0 if x <= 0 else 1

    med = (As[n] + 1) // 2
    if x < med:
        return f(n - 1, x - 1)
    elif x == med:
        return Ps[n - 1] + 1
    elif x > med:
        return Ps[n - 1] + 1 + f(n - 1, x - med)

answer = f(N, X)
print(answer)

# def make_burger(s, count):
#     # count += 1
#     # print(s)
#     if count == N:
#         return s
#     return make_burger('B' + s + 'P' + s + 'B', count + 1)

# print(make_burger('P', 0))

Measured memory_bytes: 3064
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <time.h>
#include <stack>
#include <array>
#include <list>
#define popcount __builtin_popcount
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const ll MOD=1e9+7;
ll powmod(ll a, ll k){
    ll ap=a, ans=1;
    while(k){
        if(k&1){
            ans*=ap;
            ans%=MOD;
        }
        ap=ap*ap;
        ap%=MOD;
        k>>=1;
    }
    return ans;
}
ll inv(ll a){
    return powmod(a, MOD-2);
}
ll f[200020], invf[200020];
void fac(int n){
    f[0]=1;
    for(ll i=1; i<=n; i++) f[i]=f[i-1]*i%MOD;
    invf[n]=inv(f[n]);
    for(ll i=n-1; i>=0; i--) invf[i]=invf[i+1]*(i+1)%MOD;
}
ll comb(int x, int y){
    if(!(0<=y && y<=x)) return 0;
    return f[x]*invf[y]%MOD*invf[x-y]%MOD;
}
ll dp[2][5050];
ll dp2[2][5050];
ll c[5050];
int main()
{
    int n, a, b;
    cin>>n>>a>>b;
    if(a>b) swap(a, b);
    fac(n+1);
    dp2[0][0]=1;
    for(int i=1; i<=n+2; i++){
        for(int j=a; j<=i; j++){
            if(i-j>=0){
                (dp2[0][i]+=dp2[1][i-j])%=MOD;
            }
        }
        for(int j=1; j<=i; j++){
            if(i-j>=0){
                (dp2[1][i]+=dp2[0][i-j])%=MOD;
            }
        }
    }
    dp[0][0]=1;
    for(int i=1; i<=n+2; i++){
        for(int j=1; j<a; j++){
            if(i-j>=0){
                (dp[0][i]+=dp[1][i-j])%=MOD;
            }
        }
        for(int j=1; j<=b; j++){
            if(i-j>=0){
                if(j==b){
                    if(i-j!=0 && i!=n+2) continue;
                }
                (dp[1][i]+=dp[0][i-j]*dp2[1][j])%=MOD;
            }
        }
    }
    cout<<(powmod(2, n)-dp[1][n+2]+MOD)%MOD<<endl;
    return 0;
}

Measured memory_bytes: 3864
#include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <functional>
#include <numeric>
#include <list>
#include <set>
#include <map>
#include <algorithm>
#include <cmath>
#include <limits>
#include <iomanip>
#include <bitset>
#include <queue>
#include <unordered_set>

using namespace std;
typedef long long ll;

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
#define rep(i, n) for(int i = 0;i < n;i++)
const int INF = 1LL << 30;

int MOD = 1000000007;

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

    int a; string s; cin >> a >> s;

    if(a>=3200){
        cout << s << endl;
    } else {
        cout << "red" << endl;
    }
    

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <string>
 
using namespace std;
 
int main(){
    int H, W;
    cin >> H >> W;
    string s[H];

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

    for (int i = 0; i < H; i++) cin >> s[i];
    for (int i = 0; i < H; i++)
    {
        for (int j = 0; j < W; j++)
        {
            if (s[i][j]=='#') continue;
            
            int num = 0;

            for (int d = 0; d < 8; d++)
            {
                int ni = i + dx[d];
                int nj = j + dy[d];

                if (ni < 0 or H <= ni) continue;
                if (nj < 0 or W <= nj) continue;
                if (s[ni][nj] == '#') num++;
            }
            
            s[i][j] =  num + '0';
        }
        
    }

    for (int i = 0; i < H; i++)
    {
        cout << s[i] << endl;
    }
    
    
}

Measured memory_bytes: 256
#pragma GCC optimize ("O2")
#pragma GCC diagnostic ignored "-Wunused-variable"
#pragma GCC diagnostic ignored "-Wunused-result"
#pragma GCC diagnostic ignored "-Wunused-label"

#define DEBUG 0
#define dd if (DEBUG)

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

#define rep(i, a, b) for (int i = (a); i < (b); ++i)
#define trav(a, A) for (auto & a : A)
#define all(a) (a).begin (), (a).end ()
#define rall(a) (a).rbegin (), (a).rend ()
#define sz(a) (int) (a).size ()
#define szl(a) (int) (a).length ()
#define FASTIO cin.sync_with_stdio (0); cin.tie (0); cin.exceptions (cin.failbit);

typedef long long ll;
typedef pair <int, int> pii;
#define f first
#define s second
#define mp(a, b) make_pair((a), (b))
typedef vector <int> vi;
typedef vector <vi> mi;
typedef vector <ll> vll;
typedef vector <vll> mll;
#define pb(a) push_back ((a))

const ll MOD = 1e+9+7;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const int INFi = 0x3f3f3f3f;
const ll MAXN = 1e+6+7;

// 01:09:20h

int main ()
{
    FASTIO;
    int i, j, n;
    cin >> n;
    vector <double> c (n);
    vector <vector <double> > dp (n + 7, vector <double> (n + 7));
    trav (a, c)
        cin >> a;
    dp[0][0] = 1;
    dp[0][1] = c[0];
    for (i = 1; i < n; i++)
    {
        dp[i][0] = 1;
        for (j = 1; j <= n && dp[i][j - 1] != 0; j++)
        {
            dp[i][j] = c[i]*dp[i - 1][j - 1] + (1 - c[i])*dp[i - 1][j];
        }
    }
    dd trav (v, dp) {
        trav (a, v)
            printf ("% 4.4lf ", a);
        printf ("\n");
    }
    dd cout << endl;
    printf ("%.10lf\n", dp[n - 1][(n + 1)/2]);

    return 0;
}



Measured memory_bytes: 71040
#[allow(unused_imports)]
use std::cmp::{Ordering};

#[allow(unused_imports)]
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};

#[allow(unused_imports)]
use std::io::{stdin, stdout, BufWriter, Write};

#[allow(unused_imports)]
use std::iter::FromIterator;

#[allow(unused_macros)]
macro_rules! min {
    ($x: expr) => ($x);
    ($x: expr, $($z: expr),+) => {{
        std::cmp::min($x, min!($($z),*))
    }}
}

#[allow(unused_macros)]
macro_rules! max {
    ($x: expr) => ($x);
    ($x: expr, $($z: expr),+) => {{
        std::cmp::max($x, max!($($z),*))
    }}
}

#[allow(unused_macros)]
macro_rules! get { 
    ([$t: ty]) => { 
        { 
            let mut line = String::new(); 
            stdin().read_line(&mut line).unwrap(); 
            line.split_whitespace().map(|t|t.parse::<$t>().unwrap()).collect::<Vec<_>>()
        }
    };
    ([$t: ty];$n: expr) => {
        (0..$n).map(|_|get!([$t])).collect::<Vec<_>>()
    };
    ($t: ty) => {
        {
            let mut line = String::new();
            stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t: ty),*) => {
        { 
            let mut line = String::new();
            stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            ($(iter.next().unwrap().parse::<$t>().unwrap(),)*)
        }
    };
    ($t: ty; $n: expr) => {
        (0..$n).map(|_|get!($t)).collect::<Vec<_>>()
    };
    ($($t: ty),*; $n: expr) => {
        (0..$n).map(|_|get!($($t),*)).collect::<Vec<_>>()
    };
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        #[cfg(debug_assertions)]
        writeln!(&mut std::io::stderr(), concat!("[DEBUG] ", $(stringify!($a), "={:?} "),*), $($a),*).unwrap();
    }
}

const BIG_STACK_SIZE: bool = true;

#[allow(dead_code)]
fn main() {
    use std::thread;
    if BIG_STACK_SIZE {
        thread::Builder::new()
            .stack_size(32 * 1024 * 1024)
            .name("solve".into())
            .spawn(solve)
            .unwrap()
            .join()
            .unwrap();
    } else {
        solve();
    }
}

fn solve() {
    let (h,w) = get!(usize, usize);
    let a = get!([isize]; h);
    let b = get!([isize]; h);

    let mut dp = vec![vec![vec![false; 81*(h+w)]; w+1]; h+1];
    dp[1][1][(a[0][0]-b[0][0]).abs() as usize] = true;
    for i in 0..h {
        for j in 0..w {
            let v = (a[i][j] - b[i][j]).abs();
            for val in 0..81*(h+w) {
                let val = val as isize;
                let v1 = min!((val-v).abs() as usize, 81*(h+w)-1);
                let v2 = min!((val+v).abs() as usize, 81*(h+w)-1);
                if dp[i+1][j][v1] 
                | dp[i+1][j][v2]
                | dp[i][j+1][v1]
                | dp[i][j+1][v2] {
                    dp[i+1][j+1][val as usize] = true;
                }
            }
        } 
    }
    for val in 0..81*(h+w) {
        if dp[h][w][val] {
            println!("{}", val);
            return;
        }
    }
}


Measured memory_bytes: 102780
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <cmath>
#include <queue>
#include <numeric>
#include <climits>
#include <iterator>
#include <iomanip>
#include <stack>
#include <set>
#include <cstdio>
#include <bitset>
#include <functional>
#include <tuple>
#include <list>
#include <deque>
using namespace std;
typedef pair<int, int> P;

#define FOR(i, a, n) for (ll i = (ll)a; i<(ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)

typedef long long ll;
typedef vector<int> VI;



struct DICE{
    int men[7];
    DICE(int a, int b, int c, int d, int e, int f){
        men[1]=a; men[2]=b; men[3]=c; men[4]=d; men[5]=e; men[6]=f;
    }
    
    void rotate(char s){
        if(s=='S'){
            
            swap(men[1], men[5]);
            swap(men[5], men[6]);
            swap(men[6], men[2]);
        }
        if(s=='W'){
            swap(men[1], men[3]);
            swap(men[3], men[6]);
            swap(men[4], men[6]);
        }
        if(s=='E'){
            swap(men[4], men[1]);
            swap(men[4], men[6]);
            swap(men[3], men[6]);
        }
        if(s=='N'){
            swap(men[1], men[5]);
            swap(men[1], men[2]);
            swap(men[2], men[6]);
        }
    }
    int get_ans(){
        return men[1];
    }  
};
int main() {
    cin.tie(0);
   	ios::sync_with_stdio(false);
    int a, b, c, d, e, f; cin >> a >> b >> c >> d >> e >> f;
    DICE dd(a, b, c, d, e, f);
    
    string s; cin >> s;
    for(int i=0; i<s.size(); ++i){
        dd.rotate(s[i]);
    }
    
    cout << dd.get_ans() << endl;
    
    
	return 0;
}


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

long long func(long long A, long long B, long long x) {
  return (A * x / B) - A * (x / B);
}

int main(void) {
  long long A, B, N;
  cin >> A >> B >> N;
  long long ans = func(A, B, min(N, B - 1));
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3596
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#include <numeric>
#include <limits>
using namespace std;

int main(){
    int n;
    cin >> n;
    int ans = 0;
    while (n != 0){
        ans += n;
        n--;
    }
    
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define inf 0x3f3f3f3f
const int maxn = 10000+5;
int N,M,dis[maxn],vis[maxn],cost[maxn];
struct edge
{
    int v,d,c;
    edge(int A,int B,int C):v(A),d(B),c(C) {}
};
vector<edge> G[maxn];
queue<int> que;

void spfa()
{
    memset(dis,inf,sizeof(dis));
    memset(vis,0,sizeof(vis));
    memset(cost,inf,sizeof(cost));
    dis[1]=0;
    vis[1]=1;
    cost[1]=0;
    que.push(1);
    while(!que.empty())
    {
        int u = que.front();
        que.pop();
        for(int i=0; i<G[u].size(); ++i)
        {
            edge &e = G[u][i];
            if(dis[e.v] > dis[u] + e.d)
            {
                dis[e.v] = dis[u] + e.d;
                cost[e.v] = e.c;
                if(!vis[e.v])
                {
                    vis[e.v] = 1;
                    que.push(e.v);
                }
            }
            else if(dis[e.v] == dis[u] + e.d && cost[e.v] > e.c)
            {
                cost[e.v] = e.c;
                if(!vis[e.v])
                {
                    vis[e.v] = 1;
                    que.push(e.v);
                }
            }
        }
        vis[u]=0;
    }
    int ans = 0;
    for(int i=1; i<=N; ++i)
        ans+=cost[i];
    cout<<ans<<endl;
}

int main()
{
    while(cin>>N>>M)
    {
        if(N == 0 && M == 0)
            break;
        int u,v,d,c;
        for(int i=1; i<=M; ++i)
        {
            cin>>u>>v>>d>>c;
            G[u].push_back(edge(v,d,c));
            G[v].push_back(edge(u,d,c));
        }
        spfa();
        /// clear
        for(int i=1; i<=N; ++i)
            G[i].clear();
    }
}

Measured memory_bytes: 4848
//love yjl forever
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define fi first
#define se second
const ll INF=4611686018427387904,N=5000+5;
int n;
struct node{
	int x,y;
}a[N];
bool cmp(node x,node y)
{
	return x.x+x.y<y.x+y.y;
}
ll dp[N][N];
int main()
{
/*	freopen("","r",stdin);
	freopen("","w",stdout);*/
	int i,j;
	cin>>n;
	for(i=1;i<=n;i++){
		scanf("%d%d",&a[i].x,&a[i].y);
	}
	sort(a+1,a+n+1,cmp);
	
	for(i=0;i<=n;i++)
		for(j=0;j<=n;j++)
			dp[i][j]=INF;
			
	dp[0][0]=0;
	for(i=1;i<=n;i++)
		for(j=1;j<=i;j++)
		{
			dp[i][j]=dp[i-1][j];
			if(a[i].x>=dp[i-1][j-1])
				dp[i][j]=min(dp[i][j],dp[i-1][j-1]+a[i].y);
		}
	
	for(i=n;i>=0;i--)
		if(dp[n][i]<INF)
		{
			cout<<i;
			return 0;
		}
}

Measured memory_bytes: 195968
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i,n) for (int i = 0; i < (n); ++i)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const ll INF=1LL<<60;
const int inf=1<<30;
const int mod=1e9+7;
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,m;cin >> n >> m;
    int t=1;
    for(int i=m;i>0;i-=2){
        cout << t << " " << t+i << endl;
        t++;
    }
    t=m+2;
    for(int i=m-1;i>0;i-=2){
        cout << t << " " << t+i << endl;
        t++;
    }
}

Measured memory_bytes: 3612
#include<cstdio>
int n,m,a[300011],l,r,sum[2],s;
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)scanf("%d",&a[i]);
	for(int i=1;i<=n;i++)sum[i%2]=sum[i%2]+a[i];
	if((n%2)==1)
	{
		int l=1,r=2000000000;
		while(l<r)
		{
			int mid=(l+r+1)/2;
			s=0;
			for(int i=1;i<=n;i++)
			{
				if((i%2)==1)s=s+a[i];
				else 
				{
					if((s>=mid)&&(s-a[i]<0))s=0;
					else s=s-a[i];
				}
			}
			if(s>=mid)l=mid;
			else r=mid-1; 
		}
		sum[0]=sum[0]+l;
		sum[1]=sum[1]-l;
	}
	if(sum[0]>sum[1])printf("%d %d\n",sum[0],sum[1]);
	else printf("%d %d\n",sum[1],sum[0]);
}

Measured memory_bytes: 1280
n = int(input())
a = list(map(int,input().split()))
x1 = sum([a[h] if h%2==0 else -a[h] for h in range(n)])
print(x1,end = ' ')

for i in range(n-1):
	if i == 0:
		b = a[i]*2 - x1
		print(b,end=' ')
	else:
		print(a[i]*2 - b,end=' ')
		b = a[i]*2 - b

Measured memory_bytes: 14092
#include <iostream>
using namespace std;
int main() {
    int N, M;
    while(cin >> N >> M && !(N == 0 && M == 0)) {
        int cell[N];
        for (int i=0; i<N; ++i) cin >> cell[i];

        int dice[M];
        for (int i=0; i<M; ++i) cin >> dice[i];

        int pos=0;
        int res;
        for (int i=0; i<M; ++i) {
            pos += dice[i];
            if (pos >= N - 1) {
                res = i+1; break;
            }

            pos += cell[pos];
            if (pos >= N - 1) {
                res = i+1; break;
            }
        }

        cout << res << endl;
    }
    return 0;
}

Measured memory_bytes: 1164
A,B,K=map(int,input().split())
s1={i for i in range(A,A+K if A+K<B else B)}
s2={i for i in range(B-K+1 if A<B-K+1 else A,B+1)}
s=s1|s2
for i in sorted(list(s)):
    print(i)

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

#define rep(i, n) for(int i = 0; i<(n); i++)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
typedef long long ll;

const int MOD = 1000000007;

int main() {
    int N, M;
    cin >> N >> M;
    vector<int> A(N), B(N);
    rep(i, N) {
        cin >> A[i] >> B[i];
    }

    map<int, ll> m;
    rep(i, N) {
        m[A[i]] += B[i];
    }

    ll ans = 0;
    for (auto shop: m) {
        ll buy = min((ll) M, shop.second);
        ans += buy * shop.first;
        M -= (int) buy;
    }
    cout << ans << endl;
}

Measured memory_bytes: 7296
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (n); i++)
using namespace std;
using ll = long long;
using P = pair<ll, ll>;

int main(){
    int n, m;
    cin >> n >> m;
    vector<vector<int>> G(n);
    rep(i, m){
        int a, b;
        cin >> a >> b;
        a--; b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    vector<int> v;
    rep(i,n-1)v.push_back(i+1);
    sort(v.begin(), v.end());
    int ans = 0;
    do{
        bool flag = true;
        if(!count(G[0].begin(),G[0].end(),v[0])) flag = false;
        rep(i,n-2){
            if(count(G[v[i]].begin(), G[v[i]].end(), v[i+1]))continue;
            else{
                flag = false;
                break;
            }
        }
        if(flag)ans++;
    }while(next_permutation(v.begin(),v.end()));

    printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <math.h>
#define _GLIBCXX_DEBUG
#define _LIBCPP_DEBUG 0

using namespace std;
#define ll long long
#define rep(i,n) for (int i = 0; i < n; i++)
#define MOD (1000000007)
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int, int>
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

int gcd(int a, int b) {
    if (b == 0) return a;
    else return gcd(b, a % b);
}

const ll INF = 1LL << 60;

int main(){
  int n; cin >> n;
  vi a;
  bool zero = false;//０があるかどうかを計数
  int cnt = 0;//マイナスの数を計数
  rep(i, n){
    int x; cin >> x;
    if(x < 0) cnt++;
    if(x == 0) zero = true;
    a.pb(abs(x));
  }

  sort(all(a));
  ll ans = 0;
  rep(i, n) ans += a[i];
  if(!zero && cnt%2 == 1) ans -= 2*a[0];

  std::cout << ans << '\n';
}


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

public class Main{
    public static void main(String[] args) throws IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        String[] input = br.readLine().split(" ");
        int r = Integer.valueOf(input[0]);
        int c = Integer.valueOf(input[1]);

        int[][] matrix = new int[r+1][c+1];
        
        //input data
        for(int i = 0; i < r; i++){
            String[] line = br.readLine().split(" " , c);
            for(int j = 0; j < c; j++){
                matrix[i][j] = Integer.parseInt(line[j]);
            }
        }

        for(int i = 0; i < r; i++){
            for(int j = 0; j < c; j++){
                matrix[i][c] += matrix[i][j];
            }
        }

        for(int i = 0; i < c+1; i++){
            for(int j = 0; j < r; j++){
                matrix[r][i] += matrix[j][i];
            }
        }
        
        StringBuilder sb = new StringBuilder();
        for(int i = 0; i <= r; i++){
            for(int j = 0; j <= c; j++){
                sb.append(matrix[i][j]);
                if(j != c) sb.append(" ");
            }
            if(i != r)sb.append("\n");
        }
        System.out.println(sb);

    }
}

Measured memory_bytes: 27160
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
typedef long long ll;
const int Max = 1e5 + 5;
int lst[Max], ls[Max];

int main()
{
	int n, m;
	cin >> n;
	ll sum = 0;
	for (int i = 1; i <= n; i++)
	{
		scanf("%d", &lst[i]);
		sum += lst[i];
	}
	cin >> m;
	for (int i = 1; i <= m; i++)
	{
		int a, b;
		cin >> a >> b;
		cout << sum + b - lst[a] << endl;
	}
}

Measured memory_bytes: 3172
#include <iostream>
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <time.h>
#include <stdlib.h>
#include <string>
#include <bitset>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <algorithm>
#include <sstream>
#include <stack>
#include <iomanip>
using namespace std;
#define pb push_back
#define mp make_pair
typedef pair<int,int> pii;
typedef long long ll;
typedef double ld;
typedef vector<int> vi;
#define fi first
#define se second
#define fe first
#define FO(x) {freopen(#x".in","r",stdin);freopen(#x".out","w",stdout);}
#define Edg int M=0,fst[SZ],vb[SZ],nxt[SZ];void ad_de(int a,int b){++M;nxt[M]=fst[a];fst[a]=M;vb[M]=b;}void adde(int a,int b){ad_de(a,b);ad_de(b,a);}
#define Edgc int M=0,fst[SZ],vb[SZ],nxt[SZ],vc[SZ];void ad_de(int a,int b,int c){++M;nxt[M]=fst[a];fst[a]=M;vb[M]=b;vc[M]=c;}void adde(int a,int b,int c){ad_de(a,b,c);ad_de(b,a,c);}
#define es(x,e) (int e=fst[x];e;e=nxt[e])
#define esb(x,e,b) (int e=fst[x],b=vb[e];e;e=nxt[e],b=vb[e])
int n;
queue<pii> q;
multiset<int> adj[233333];
map<pii,int> edg;
template<class T>
void ers(T&x,int g) {x.erase(x.find(g));}
int main()
{
	scanf("%d",&n);
	for(int i=1,a,b;i<=(n-1)*2;++i)
		scanf("%d%d",&a,&b),adj[a].insert(b),
		adj[b].insert(a),++edg[pii(min(a,b),max(a,b))];
	for(auto e:edg) if(e.se>=2) q.push(e.fi);
	int cnt=0;
	while(!q.empty())
	{
		pii x=q.front(); q.pop();
		if(edg[x]<2) continue;
		int a=x.fi,b=x.se;
		if(adj[a].size()<adj[b].size()) swap(a,b);
		edg[x]-=2; ++cnt;
		while(adj[a].find(b)!=adj[a].end())
			ers(adj[a],b);
		for(auto s:adj[b])
		{
			if(s==a) continue;
			int&pp=edg[pii(min(s,a),max(s,a))];
			++pp,--edg[pii(min(s,b),max(s,b))],
			ers(adj[s],b),adj[s].insert(a),adj[a].insert(s);
			if(pp>=2) q.push(pii(min(s,a),max(s,a)));
		}
		adj[b].clear();
	}
	if(cnt+1==n) puts("YES"); else puts("NO");
}


Measured memory_bytes: 46208
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int M = sc.nextInt();
		int L[] = new int[M];
		int R[] = new int[M];

		for (int i = 0; i < M; i++) {
			L[i] = sc.nextInt();
			R[i] = sc.nextInt();
		}

		Arrays.sort(L);
		Arrays.sort(R);

		int r = R[0]-L[M-1]+1;
		if (r<=0) {
			System.out.println(0);
		} else {
		System.out.println(r);
		}
	}
}


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

struct union_find{
    vector<int> par;
    vector<int> rank;
    vector<int> siz;
    union_find(int sz){
        par.resize(sz);
        rank.assign(sz,0);
        siz.assign(sz,1);
        for(int i=0;i<sz;i++) par[i]=i;
    }
    int find(int a){
        if(par[a]==a) return a;
        else return par[a] = find(par[a]);
    }
    void clear(int sz){
        par.resize(sz);
        rank.assign(sz,0);
        siz.assign(sz,1);
        for(int i=0;i<sz;i++) par[i]=i;
    }
    void unite(int a,int b){
        if(find(a)==find(b)) return;
        int root_a,root_b;
        root_a=find(a),root_b=find(b);
        if(rank[root_a]>rank[root_b]){
            par[root_b]=root_a;
            siz[root_a]+=siz[root_b];
        }else if(rank[root_a]<rank[root_b]){
            par[root_a]=root_b;
            siz[root_b]+=siz[root_a];
        }else{
            rank[root_a]++;
            par[root_b]=root_a;
            siz[root_a]+=siz[root_b];
        }
    }
    bool same(int a,int b){return find(a)==find(b);}
    int size(int a){
        return siz[find(a)];
    }
};

int main(){
    int ans=0;
    int n,m;
    cin>>n>>m;
    union_find uf(n);
    vector<pair<int,int>> vp(m,pair<int,int>());
    for(int i=0;i<m;i++){
        cin>>vp[i].first>>vp[i].second;
        vp[i].first--;
        vp[i].second--;
    }
    for(int j=0;j<m;j++){
        uf.clear(n);
        //cout<<uf.par[0]<<endl; //デバック
        for(int i=0;i<m;i++){
            if(i==j) continue;
            uf.unite(vp[i].first,vp[i].second);
        }
        for(ll i=0;i<uf.par.size();i++){
            //cout<<uf.par[i]<<" ";
        }
        cout<<endl;
        if(uf.same(vp[j].first,vp[j].second)==false){
            ans++;
            //cout<<j<<endl; //デバッグ
        }
    }    
    cout << ans << endl;
}


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

int main() {
  int N, Q;
  while (scanf("%d%d", &N, &Q) != EOF && N) {
    int D[110];
    fill(D, D+110, false);
    D[0] = Q-1;
    for (int i=0; i<N; i++) {
      int M;
      scanf("%d", &M);
      for (int j=0; j<M; j++) {
	int date;
	scanf("%d", &date);
	D[date]++;
      }
    }
    int max = 0;
    int maxdate = 0;
    for (int i=0; i<110; i++) {
      if (max < D[i]) {
	max = D[i];
	maxdate = i;
      }
    }
    printf("%d\n", maxdate);
  }  
}

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

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

    int H,W,A,B; cin>>H>>W>>A>>B;
    vector<string> s(H,string(W,'0'));
    for(int i=0;i<B;i++) for(int j=0;j<A;j++){
        s[i][j]='1';
    }
    for(int i=B;i<H;i++) for(int j=A;j<W;j++){
        s[i][j]='1';
    }
    for(int i=0;i<H;i++){
        cout<<s[i]<<endl;
    }
    return 0;
}

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

using VI = vector<int>;
using VVI = vector<VI>;
using PII = pair<int, int>;
using LL = long long;
using VL = vector<LL>;
using VVL = vector<VL>;
using PLL = pair<LL, LL>;
using VS = vector<string>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

#define FF first
#define SS second
template<class S, class T>
istream& operator>>(istream& is, pair<S,T>& p){
  return is >> p.FF >> p.SS;
}
template<class S, class T>
ostream& operator<<(ostream& os, const pair<S,T>& p){
  return os << p.FF << " " << p.SS;
}
template<class T>
void maxi(T& x, T y){
  if(x < y) x = y;
}
template<class T>
void mini(T& x, T y){
  if(x > y) x = y;
}


const double EPS = 1e-10;
const double PI  = acos(-1.0);
const LL MOD = 1e9+7;

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

  string S;
  cin >> S;
  int ans = 0;
  VI cnt(26);
  int N = SZ(S);
  REP(i,N) cnt[S[i]-'a']++;

  REP(i,26) ans += cnt[i] % 2;
  cout << ans/2 << endl;

  return 0;
}

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

using namespace std;

#define optimize() 		ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ll				long long
#define vll				vector<long long>
#define pb				push_back
#define w(x)			int x; cin>>x; while(x--)
#define mp      		make_pair
#define F 				first
#define S 				second
#define mod     		1000000007
#define inf     		1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define endl	  		"\n"
#define sp 				" "
#define ca(x) 			"Case "<<x<<": "
#define all(x) 			x.begin(), x.end()
#define loop(i,a,n)		for (int i = a; i < (n); ++i)
#define rloop(i,a,n)	for (int i = n; i >= (a); --i)
#define in(n)			long long n ; cin >> n;
#define ins(s)			string s; cin >> s;
#define yes				cout << "YES"<<"\n"
#define no				cout << "NO"<<"\n"


int main()
{
	optimize();
	//............. S I D A T I V E  H I P N O T I X .............//

	in(n);
	if (n == 0)cout << 1;
	else cout << 0;

	return 0;
}



Measured memory_bytes: 3636
#include <vector>
#include <list>
#include <map>
#include <climits>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <queue>
#include <random>
#include <cctype>
#include <complex>
#include <regex>
#include <unordered_map>
#include <string>
#include <algorithm>
#include <cctype>
#include <cstdio>
#include <cstdlib>

using namespace std;
int main() {

    long long A, B;
    cin >> A >> B;
    if(A % 2 != B % 2) {
         cout << "IMPOSSIBLE" << endl;
         } else {
         cout << (A + B) / 2 << endl;
         }
     return 0;
     }

     



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

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

    int n=0,i=0;
    while(n<X){
        i++;
        n += i;
    }
    cout << i << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>	// require sort next_permutation count __gcd reverse etc.
#include <cstdlib>	// require abs exit atof atoi 
#include <cstdio>		// require scanf printf
#include <functional>
#include <numeric>	// require accumulate
#include <cmath>		// require fabs
#include <climits>
#include <limits>
#include <cfloat>
#include <iomanip>	// require setw
#include <sstream>	// require stringstream 
#include <cstring>	// require memset
#include <cctype>		// require tolower, toupper
#include <fstream>	// require freopen
#include <ctime>		// require srand
#define rep(i,n) for(int i=0;i<(n);i++)
#define ALL(A) A.begin(), A.end()
#define NIL -1

using namespace std;

struct node{
	int id;
	int d;
};

node v[105];
bool vis[105];
vector<int> g[105];

void bfs (int u )
{
	vis[u] = true;
	v[u].d = 0;
	queue<node> que;
	que.push (v[u] );
	
	while (!que.empty() ){
		node cur = que.front(); que.pop();
		int id = cur.id;
		int d  = cur.d;
		rep (j, g[id].size() ){
			int next = g[id][j];
			if (!vis[next] ){
				vis[next] = true;
				v[next].d = d + 1;
				que.push (v[next] );
			} // end if
		} // end rep
	} // end while				
}

int main()
{
	memset (vis, false, sizeof (vis ) );
	ios_base::sync_with_stdio(0);
	int n; cin >> n;
	rep (i, n+1 ) g[i].clear();
	rep (i, n+1 ) v[i].id = i, v[i].d = NIL;

	rep (i, n ){
		int id; cin >> id;
		int k; cin >> k;
		while (k-- ){
			int v; cin >> v;
			g[id].push_back (v );
		} // end while
	} // end rep

	bfs (1 );

	for (int i = 1; i <= n; i++ ){
		cout << v[i].id << ' ' << v[i].d << endl;
	} // end for
		
	return 0;
}

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

using namespace std;
int main(void){
    // Your code here!
    string s,t,u;
    cin>>s>>t>>u;
    if(s[s.length()-1]==t[0]&&t[t.length()-1]==u[0]){
        cout<<"YES"<<endl;
    }
    else{
        cout<<"NO"<<endl;
    }
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<vector>
#include<functional>
#include<algorithm>
#include<stdlib.h>
#include<string>
#include<cmath>
#include<deque>
#include<set>
using namespace std;
typedef long long ll;
#define rep(i,a,b) for(int i=a;i<b;i++)
#define all(_x) _x.begin(), _x.end()
#define r_sort(_x) sort(_x.begin(), _x.end(), std::greater<int>())
#define INF 1LL << 60
#define MAX 1000000000
int gcd(int a, int b) { return a % b == 0 ? b : gcd(b, a % b); }
int main() {
	int N, m;
	scanf("%d", &N);
	vector<int> A(N);
	rep(i, 0, N)scanf("%d", &A[i]);
	m = A[0];
	rep(i, 1, N)m = min(m, gcd(A[i], m));
	printf("%d\n", m);
	return 0;
}

Measured memory_bytes: 640
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<utility>
#include<map>
#include<set>
#include<queue>
#include<math.h>
using namespace std;
#define N (1000000000+7)
#define INF 1e16
typedef pair<int,int> P;
typedef long long ll;


int main(void){
    string s;
    cin>>s;
    for(int i=1;i<=s.length();i++){
        if(s[i-1]=='U'||s[i-1]=='D')continue;
        if(i%2==1){
            if(s[i-1]!='R'){
                cout<<"No"<<endl;
                return 0;
            }
        }
        else{
            if(s[i-1]!='L'){
                cout<<"No"<<endl;
                return 0;
            }
        }
    }
    cout<<"Yes"<<endl;
    return 0;
}

Measured memory_bytes: 256
import sys
from collections import Counter
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7



def main():
    N = int(readline())
    H = list(map(int, readline().split()))
    count = Counter(H)
    sr_count = sorted(count.items(), key=lambda x:x[0],reverse=True)
    ans = 0
    for kye, value in sr_count:
        if value>=4:
            if ans == 0:
                ans = kye**2
                break
            else:
                ans *= kye
                break
        elif value>=2:
            if ans == 0:
                ans += kye
            else:
                ans *= kye
                break
        else:
            continue
    print(ans)


if __name__ == '__main__':
    main()

Measured memory_bytes: 22196
#include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
#include <string.h>
#include <vector>
using namespace std;
typedef long long ll;

int main(){
    ll A, B, C, D;
    ll turn = 0;
    ll sum = 0;

    cin >> A >> B >> C >> D;

    while(A > 0 && C > 0){
        if(turn == 0){
            C -= B;
            turn = 1;
        }else{
            A -= D;
            turn = 0;
        }
    }

    if(A <= 0){
        cout << "No" << endl;
    }else{
        cout << "Yes" << endl;
    }

    return 0;
}


Measured memory_bytes: 3636
use std::io::*;
use std::str::FromStr;

pub fn read<T: FromStr>() -> T {
  let stdin = stdin();
  let stdin = stdin.lock();
  let token: String = stdin
    .bytes()
    .map(|c| c.expect("failed to read char") as char)
    .skip_while(|c| c.is_whitespace())
    .take_while(|c| !c.is_whitespace())
    .collect();
  token.parse().ok().expect("failed to parse token")
}

fn main() {
  let x = read::<i32>();
  if x == 5 || x == 3 || x == 7 {
    println!("YES")
  }else {
    println!("NO")
  }
  

}



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

int main() {
	int n ;
	cin>>n;
	int arr[n];
	for(int i = 0;i<n;i++){
	    cin>>arr[i];
	}
	
	
	int dp[n];
	memset(dp,0,sizeof(dp));
	
	
	dp[1] = abs(arr[0]-arr[1]);
	
	if(n>2){
	for(int i = 2;i<n;i++){
	    dp[i] = min(dp[i-1]+abs(arr[i]-arr[i-1]),dp[i-2]+abs(arr[i-2]-arr[i]));
	}
	}
	//for(int i = 0;i<n;i++)cout<<dp[i]<<endl;
	cout<<dp[n-1]<<endl;
	return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <climits>

using namespace std;

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

	int n, d;
	cin >> n >> d;
	
	int num = 1 + 2 * d;
	int ans = n / num;
	if (n % num != 0)ans++;

	cout << ans;
}

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

void deTransform(const char op, string& str) {
    switch (op) {
    case 'J':
        str = str.at(str.length() - 1) + str.substr(0, str.length() - 1);
        break;
    case 'C':
        str = str.substr(1, str.length() - 1) + str.at(0);
        break;
    case 'E':
        if (str.length() % 2 == 0) {
            str = str.substr(str.length() / 2, str.length() / 2) + str.substr(0, str.length() / 2);
        } else {
            unsigned int middle = str.length() / 2;
            str = str.substr(middle + 1, middle) + str.at(middle) + str.substr(0, middle);
        }
        break;
    case 'A':
        reverse(str.begin(), str.end());
        break;
    case 'P':
        for (string::iterator it = str.begin(); it != str.end(); it++) {
            if (*it == '0') {
                *it = '9';
            } else if ('0' < *it && *it <= '9') {
                (*it)--;
            }
        }
        break;
    case 'M':
        for (string::iterator it = str.begin(); it != str.end(); it++) {
            if (*it == '9') {
                *it = '0';
            } else if ('0' <= *it && *it < '9') {
                (*it)++;
            }
        }
        break;
    }
}

int main() {
    int n;
    cin >> n;
    while (n--) {
        string messengers, message;
        cin >> messengers >> message;
        for (string::reverse_iterator rit = messengers.rbegin(); rit != messengers.rend(); rit++) {
            deTransform(*rit, message);
        }
        cout << message << endl;
    }
}

Measured memory_bytes: 0
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstdlib>
#include <math.h>
#include <unordered_map>
#include <numeric>
#include <sstream>
#include <functional>
using namespace std;

int main()
{
	int a,p;

	cin >> a >> p;

	p+=a*3;

	if(p == 0){
		cout << 0 << endl;
		return 0;
	}

	cout << (int)p/2 << endl;

	return 0;
}

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

int main() {
	int a,b;
	cin>>a>>b;
	if(a==1){
		a=14;
	}
	if(b==1){
		b=14;
	}
	if(a<b){
		cout<<"Bob"<<endl;
	}
	else if(a>b){
		cout<<"Alice"<<endl;
	}
	else{
		cout<<"Draw"<<endl;
	}
}

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

int main(){
  int i,j,n;
  char esu;
  string s,t;
  cin>>s>>t;
  n=s.length();
  int a[26];
  for(i=0;i<26;i++){
    a[i]=0;
  }
  for(i=0;i<n;i++){
    if(s[i]!=t[i]){
      if(a[t[i]-'a']!=0){
        break;
      }
      esu=s[i];
      for(j=0;j<n;j++){
        if(s[j]==esu){
          s[j]=t[i];
        }else if(s[j]==t[i]){
          s[j]=esu;
        }
      }
      a[t[i]-'a']++;
    }
  }
  if(s==t){
    cout<<"Yes";
  }else{
    cout<<"No";
  }
}

Measured memory_bytes: 776
#include <cstdint>
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>

std::string check(int64_t x, int64_t a, int64_t b)
{
    int64_t day = a - b;
    if (day >= 0) return "delicious";
    if (x + day >= 0) return "safe";
    return "dangerous";
}

int main(void)
{
    int64_t x, a, b;

    std::cin >> x >> a >> b;

    std::cout << check(x, a, b) << std::endl;

    return 0;
}

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

int main(){
    int a, b;
    cin >> a >> b;
    if(a<b){
        for(int i=0; i<b; i++) cout << a;
    }else{
        for(int i=0; i<a; i++) cout << b;
    }
    cout << endl;
}

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

#define pb push_back
#define mp make_pair
#define eb emplace_back
#define all(a) begin(a), end(a)
#define has(a, b) (a.find(b) != a.end())
#define fora(i, n) for(int i = 0; i < n; i++)
#define forb(i, n) for(int i = 1; i <= n; i++)
#define forc(a, b) for(const auto &a : b)
#define ford(i, n) for(int i = n; i >= 0; i--)
#define maxval(t) numeric_limits<t>::max()
#define minval(t) numeric_limits<t>::min()
#define imin(a, b) a = min(a, b)
#define imax(a, b) a = max(a, b)
#define sz(x) (int)(x).size()
#define pvec(v) copy(all(v), ostream_iterator<decltype(v)::value_type>(cout, " "))

#define dbgs(x) #x << " = " << x
#define dbgs2(x, y) dbgs(x) << ", " << dbgs(y)
#define dbgs3(x, y, z) dbgs2(x, y) << ", " << dbgs(z)
#define dbgs4(w, x, y, z) dbgs3(w, x, y) << ", " << dbgs(z)

using ll = long long;
using ld = long double;

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

	int n;
	cin >> n;
	map<ll, int> c;
	set<ll> e;
	fora(i, n) {
		ll v;
		cin >> v;
		++c[v];
		e.insert(v);
	}

	if (sz(e) > 3) {
		cout << "No\n";
		return 0;
	}

	if (sz(e) == 1 && has(e, 0)) {
		cout << "Yes\n";
		return 0;
	}
	if (n % 3 != 0) {
		cout << "No\n";
		return 0;
	}

	forc(a, e) forc(b, e) {
		map<ll, ll> need;
		need[a] += n/3;
		need[b] += n/3;
		need[a ^ b] += n/3;
		bool ok = true;
		forc(o, need) {
			if (c[o.first] != o.second) ok = false;
		}
		if (ok) {
			cout << "Yes\n";
			return 0;
		}
	}
	cout << "No\n";

}


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

const int N = 303;

double dp[N][N][N];

int main() {
    int a = 0, b = 0, c = 0;
    int n;
    cin>>n;

    for (int i=1; i<=n; i++) {
        int x;
        cin>>x;
        if (x == 1) a++;
        if (x == 2) b++;
        if (x == 3) c++;
    }

    for (int k=0; k<N; k++)
        for (int j=0; j<N; j++)
            for (int i=0; i<N; i++) {
                if (i+j+k==0 || i+j+k>n)   continue;

                double ea = i ? dp[i-1][j][k]*i : 0;
                double eb = j ? dp[i+1][j-1][k]*j : 0;
                double ec = k ? dp[i][j+1][k-1]*k : 0;
                dp[i][j][k] = (n+ea+eb+ec)/(i+j+k);
//                cout<<i<<" "<<j<<" "<<k<<" "<<dp[i][j][k]<<endl;
            }
    cout<<setprecision(12)<<dp[a][b][c]<<endl;
}


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

int main(){
    string S;
    cin >> S;

    int size = S.size();
    if(S.at(size-1)=='s'){
        cout << S << "es" << endl;
    }else{
        cout << S << 's' << endl;
    }
}

Measured memory_bytes: 3624
n = int(input())
s = input()

ans = s.count("R") * s.count("G") * s.count("B")

for i in range(n-2):
    si = s[i]
    for j in range(i+1, i+(n-i-1)//2+1):
        sj = s[j]
        k = 2*j-i
        if k < n and s[k] != si and s[k] != sj and si != sj:
            ans -= 1

print(ans)

Measured memory_bytes: 9152
#include <iostream>
#include <cstdio>
#include <string.h>
#include <queue>
#define L 40050
#define ll long long
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
int main()
{
    int n,h=1;
    ll a[100005];
    scanf("%d",&n);
    for(int i=0;i<n;i++)
        scanf("%lld",&a[i]);
    sort(a,a+n);
    int d=0;
    int m;
    for(int i=0;i<n;)
    {
        m=0;
        int j=i;
        while(a[i]==a[j])
        {
            j++;
            m++;
        }
        i+=m;
        if(m%2==1)
            d++;
    }
    printf("%d\n",d);
    return 0;

}

Measured memory_bytes: 1024
/*
 *  Created on: 3 / 5 / 2020
 *  Author:     Eslam Waheed
 */
#include <bits/stdc++.h>
//#include <bits/BIGINT.h>
//#include <bits/Int128.h>
using namespace std;

//#define _CRT_SECURE_NO_WARNINGS
//#define __USE_MINGW_ANSI_STDIO
#define Eslam__Waheed ios_base::sync_with_stdio(false);cout.tie(NULL);cin.tie(NULL);

#define ll   long long
#define ull  unsigned ll
#define dd   double
#define ld   long dd
#define ss   string

#define pb      push_back
#define all(c)  c.begin(), c.end()
#define rall(c) c.rbegin(), c.rend()
#define stp(n)  cout << fixed << setprecision(n);
#define iq(v)   v.resize(unique(v.begin(),v.end())-v.begin())
#define sz(s)   (ll)(s.size())
#define endl    '\n'

#define loop(i,m,n)  for(ll i=m;i<n;i++)

ll gcd(ll a, ll b) { return !b ? abs(a) : gcd(b, a % b); }
ll lcm(ll a, ll b) { return abs(a / gcd(a, b)) * b; }

//const ll mod = 1e9 + 7;
//__int128
/*
 you can ^_^ (•‿•)

( إن الله وملائكته يصلون على النبي يا أيها الذين آمنوا صلوا عليه وسلموا تسليما )
*/
int main()
{
    //stp(0)
    Eslam__Waheed
        ss s; cin >> s;
    if (s == "ARC")
    {
        cout << "ABC";
    }
    else
    {
        cout << "ARC";
    }
}

Measured memory_bytes: 3612
import java.io.*;
class Main{
    public static void main(String[] args)throws IOException{
    	InputStreamReader isr =new InputStreamReader(System.in);
   		BufferedReader br =new BufferedReader(isr);
    	String buf = br.readLine();
    	int x = Integer.parseInt(buf);
    	int y = x*x*x;
        System.out.println(y);
    }
}

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

int primes[1500];
int primescnt;

int isprime(int n){
  int flg=0;
  if (n<2)return 0;
  if (sqrt(n)>=primes[primescnt-1]){
    for (int i=primes[primescnt-1];i<=sqrt(n);i++){
      flg=0;
      for (int j=0;j<primescnt;j++){
	if (i%primes[j]==0){flg=1;break;}
      }
      if (!flg) {
	primes[primescnt]=i;
	primescnt++;
      }
    }
  }
  flg=0;
  for (int j=0;j<primescnt;j++){
    if (primes[j]>sqrt(n))break;
    if (n%primes[j]==0){flg=1;break;}
  }
  return !flg;
}

int main(){
  int a,d,n,pcnt,tret;
  primes[0]=2;
  primes[1]=3;
  primes[2]=5;
  primes[3]=7;
  primes[4]=11;
  primescnt=5;

  while (1){
    cin >> a >> d >> n;
    if (a==0&&d==0&&n==0) break;
    pcnt=0;
    tret=a-d;
    while (pcnt!=n){
      tret+=d;
      pcnt+=isprime(tret);
    }
    cout << tret << endl;
  }
  return 0;
}

Measured memory_bytes: 3052
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#define ff first
#define ss second

string s,t;
int dp[3005][3005];

int main()
{
    cin>>s;
    cin>>t;
    int n=s.size(),m=t.size();
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=m;j++)
        {
            if(s[i-1]==t[j-1]) dp[i][j]=dp[i-1][j-1]+1;
            else dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
        }
    }
    // for(int i=0;i<=n;i++)
    // {
    //     for(int j=0;j<=m;j++)
    //     {
    //         cout<<dp[i][j]<<" ";
    //     }
    //     cout<<endl;
    // }
    // cout<<dp[n][m]<<endl;
    vector<char> v;
    int i=n,j=m;
    while(i>0 && j>0)
    {
        if(s[i-1]==t[j-1])
        { 
            v.pb(s[i-1]);
            i--;j--;
        }
        else
        {
            if(dp[i-1][j] > dp[i][j-1]) i--;
            else j--;
        }
    }
    for(int i=v.size()-1;i>=0;i--) cout<<v[i];
    cout<<endl;
}

Measured memory_bytes: 35456
# -*- coding: utf-8 -*-
"""
Created on Sat Dec 15 22:14:32 2018

@author: doppe
"""
n, h, w = (int(x) for x in input().split())

count = 0
for i in range(0, n):
    y, x = (int(z) for z in input().split())
    if (y >= h and x >= w):
        count += 1

print(count)

Measured memory_bytes: 3060
#include <iostream>
#include <string>
using namespace std;
int main(){
	string s;
	while(getline(cin,s)){
		if(s==".") break;
		int a[200][200],k1=0,k2=0,b=0,c1=0,c2=0,c3=0,c4=0;
		for(int i=0;i<200;i++){
			for(int j=0;j<200;j++){
				a[i][j]=0;
			}
		}
		a[100][100]=1;
		int len=s.size();
		for(int i=0;i<len;i++){
			if(s[i]=='('){
				k1++;
				a[100+k1][100+k2]++;
				c1++;
			}
			else if(s[i]==')'){
				a[100+k1][100+k2]=0;
				k1--;
				if(a[100+k1][100+k2]==0){
					b++;
				}
				c2++;
			}
			else if(s[i]=='['){
				k2++;
				a[100+k1][100+k2]++;
				c3++;
			}
			else if(s[i]==']'){
				a[100+k1][100+k2]=0;
				k2--;
				if(a[100+k1][100+k2]==0){
					b++;
				}
				c4++;
			}
		}
		if(b==0&&c1==c2&&c3==c4){
			cout<<"yes"<<endl;
		}
		else{
			cout<<"no"<<endl;
		}
		string s(200,'a');
	}
    return 0;
}

Measured memory_bytes: 1340
#include <bits/stdc++.h>
typedef long long ll;
#define REP(i,a) for(int i = 0; i < (a); i++)
using namespace std;

int main(){
	ll a,b;
	cin >> a >> b;
	ll res = 0;
	if(a % 2 != 0){
		res = res ^ a;
		a++;
	}
	if(b % 2 == 0){
		res = res ^ b;
		b--;
	}
	if((b - a + 1)/ 2 % 2 == 1) res = res ^ 1;
	cout << res << endl;
}

Measured memory_bytes: 256