akhauriyash/Code-Regression huggingface dataset:
import numpy as np

def eval(x, y, z):
    if(x==y and y==z):
        return 1
    if(x==y):
        return 3
    if(y==z):
        return 3
    return 6


def main():
    N = int(input().rstrip())
    ans = np.zeros(N, dtype=np.int64)

    for x in range(1, 143):
        for y in range(x, 143):
            for z in range(y, 143):
                val = (x+y)**2 + (x+z)**2 + (y+z)**2
                if(val <= 2*N and val%2==0):
                    ans[int(val/2)-1] += eval(x, y, z)

    for a in ans:
      print(a)

if __name__ == "__main__":
    main()


Measured memory_bytes: 27428
/**
 * @author      : Luis Miguel Baez <es.luismiguelbaez@gmail.com>
 * @created     : Wednesday August 19, 2020
 */

#include <bits/stdc++.h>

using namespace std;

#define endl '\n'
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define ms(arr, value) memset(arr, value, sizeof(arr))
#define finally(value) {cout << value << '\n'; return;}
#define ll    int64_t

const int oo = int(1e9);
const ll lloo  = (ll)(1e18);
const int N = int(1001);

const int MOD = int(1e9+7);

template<typename T>
T sub(T a, T b) {
    return ((a-b)%MOD + MOD) % MOD;
}

template<typename T>
T add(T a, T b) {
    return ((a%MOD) + (b%MOD)) % MOD;
}

template<typename T>
T mul(T a, T b) {
    return ((a%MOD) * (b%MOD)) % MOD;
}

template<typename T>
T power(T a, T b) {
    T answer = (T)1;
    while (b > 0) {
        if (b & 1) {
            answer = mul(answer, a);
        }
        a = mul(a, a);
        b >>= 1;
    }
    return answer;
}

template<typename T>
T inverse(T a) {
    a %= MOD;
    if (a < 0) a += MOD;
    T b = MOD, u = 0, v = 1;
    while (a) {
        T t = b / a;
        b -= t * a; swap(a, b);
        u -= t * v; swap(u, v);
    }
    assert(b == 1);
    if (u < 0) u += MOD;
    return u;
}

template<typename T>
T divi(T a, T b) {
    return mul(a ,  inverse(b));
}


class Task {
public:
    int H, W;
    vector<vector<char>> grid;
    int dp[N][N];

    int go(int row, int col) {
        if(row<0 || col <0) return 0;
        if(row==0 && col == 0) return 1;
        if(grid[row][col] == '#') return 0;
        int &ans = dp[row][col];
        if(ans != -1) return ans;
        ans = 0;
        ans = add(ans, go(row-1, col));
        ans = add(ans, go(row, col-1));
        return ans;
    }

    void solveOne(istream &in, ostream &out) {
        in >> H >> W;
        string line;
        grid.clear();
        grid.resize(H, vector<char>(W));

        for(int i = 0; i < H; ++i){
            in >> line;
            for(int j = 0; j < W; ++j){
                grid[i][j] = line[j];
            }
        }
        ms(dp, -1);
        int ans = go(H-1, W-1);
        finally(ans);
    }
    
    void solve(istream &in, ostream &out) {
        int t=1;
        while(t--) solveOne(in, out);
    }
};

auto main() -> int {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    
    Task solver;
    istream &in(cin);
    ostream &out(cout);
    solver.solve(in, out);
    return 0;
}

Measured memory_bytes: 8568
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

struct node{
  int key;
  struct node *next;
  struct node *prev;
};

typedef struct node *NodePointer;
NodePointer nil;


NodePointer listSearch(int key){
  NodePointer cur = nil->next;
  while(cur != nil && cur->key != key){
    cur = cur->next;
  }
  return cur;
}


void init(){
  nil = (NodePointer)malloc(sizeof(NodePointer));
  nil->next = nil;
  nil->prev = nil;
}

void printList(){
  NodePointer cur = nil->next;
  int isf = 0;
  while(1){
    if(cur == nil) break;
    if(isf++ > 0) printf(" ");
    printf("%d", cur->key);
    cur = cur->next;
  }
  printf("\n");
}

void deleteNode(NodePointer t){
  if(t == nil) return;
  t->prev->next = t->next;
  t->next->prev = t->prev;
  free(t);
}

void deleteFirst(){
  deleteNode(nil->next);
}

void deleteLast(){
  deleteNode(nil->prev);
}

void deleteKey(int key){
  deleteNode(listSearch(key));
}

void insert(int key){
  NodePointer x = (NodePointer)malloc(sizeof(NodePointer));
  x->key = key;
  x->next = nil->next;
  nil->next->prev = x;
  nil->next = x;
  x->prev = nil;
}

int main(){
  int key, n, i;
  int size = 0;
  char com[20];
  int np = 0, nd = 0;
  
  scanf("%d", &n);
  init();
  for(i = 0 ; i < n ; i++){
    scanf("%s%d", com, &key);
    if(com[0] == 'i') {
      insert(key);
      np++;
      size++;
    }
    else if(com[0] == 'd'){
      if(strlen(com) > 6){
	if(com[6] == 'F') deleteFirst();
	else if(com[6] == 'L') deleteLast();
      }
      else{
	deleteKey(key);
	nd++;
      }
      size--;
    }
  }

  printList();
}


Measured memory_bytes: 33080
def main():
    K, S = map(int, input().split())
    count = 0
    for a in range(K+1):
        for b in range(K+1):
            c = S - a - b
            if 0 <= c <= K:
                count += 1
    return count
if __name__ == '__main__':
    print(main())

Measured memory_bytes: 2940
from bisect import bisect, bisect_left
 
N=int(input())
L=list(map(int,input().split()))
L.sort()
 
ans = 0
for i in range(N-2):
  a=L[i]
  for k in range(i+1,N-1):
    b=L[k]
    t=bisect_left(L,a+b)
    ans+=t-k-1
print(ans)

Measured memory_bytes: 3188
n,k = map(int,input().split())

sunuke = [0] * n

for i in range(k):
  d = int(input())
  a = list(map(int,input().split()))
  for j in range(d):
    sunuke[a[j]-1]+=1

ans = 0
for i in range(n):
  if sunuke[i] == 0:
    ans += 1

print(ans)

Measured memory_bytes: 9104
N=int(input())
A=input()
B=input()
C=input()
cnt = 0
tmp=''
s = 0
for i in range(N):
    cnt = 0
    tmp = A[i]
    if tmp == B[i] or tmp == C[i] :
        cnt += 1
    if B[i] == C[i]:
        cnt += 1
    elif tmp != B[i] and tmp != C[i]:
        cnt += 2
    if tmp == B[i] and tmp == C[i]:
        cnt = 0
    s += cnt
print(s)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
// iostream is too mainstream
#include <cstdio>
// bitch please
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <cmath>
#include <iomanip>
#include <time.h>
#define dibs reserve
#define OVER9000 1234567890
#define ALL_THE(CAKE,LIE) for(auto LIE =CAKE.begin(); LIE != CAKE.end(); LIE++)
#define tisic 47
#define soclose 1e-8
#define chocolate win
// so much chocolate
#define patkan 9
#define ff first
#define ss second
#define abs(x) (((x) < 0)?-(x):(x))
#define uint unsigned int
#define dbl long double
#define pi 3.14159265358979323846
using namespace std;
// mylittledoge

using cat = long long;

#ifdef DONLINE_JUDGE
	// palindromic tree is better than splay tree!
	#define lld I64d
#endif

int main() {
	cin.sync_with_stdio(0);
	cin.tie(0);
	cout << fixed << setprecision(10);
	int N, M;
	string S;
	cin >> N >> M >> S;
	cat mod = 1000000007;
	vector<int> L;
	for(int i = 0; i < M; i++) if(i == 0 || S[i] != S[i-1]) {
		int l = 0;
		while(i+l < M && S[i+l] == S[i]) l++;
		L.push_back(l);
	}
	M = L.size();

	if(M == 1) {
		vector<cat> cnt(N+1, 0);
		cnt[1] = 1;
		cat pref = 1;
		for(int i = 2; i <= N; i++) {
			cnt[i] = (pref - cnt[i-1]) % mod;
			pref = (pref + cnt[i]) % mod;
		}
		cat ans = 1;
		for(int i = 1; i < N; i++)
			ans = (ans + (i+1) * cnt[N-i]) % mod;
		cout << ans << "\n";
		return 0;
	}
 
	int max_first = N-1;
	if(L[0]%2 == 0) max_first = min(max_first, L[0]+1);
	for(int i = 0; i < M-1; i += 2)
		if(L[i]%2 != 0) max_first = min(max_first, L[i]);
	if(max_first%2 == 0) max_first--;

	vector<cat> cnt(N+1, 0), pref(N+2, 0);
	cnt[1] = pref[2] = 1;
	for(int i = 3; i <= N; i += 2) {
		cnt[i] = (pref[i-1] - pref[max(0, i-max_first-2)]) % mod;
		pref[i+1] = (cnt[i] + pref[i-1]) % mod;
	}

	cat ans = 0;
	for(int i = 1; i <= max_first; i += 2)
		ans = (ans + (i+1) * cnt[N-i]) % mod;
	ans %= mod;
	if(ans < 0) ans += mod;
	cout << ans << "\n";
	return 0;
}

// look at my code
// my code is amazing


Measured memory_bytes: 4040
/*
このコード、と～おれ!
Be accepted!
∧＿∧　
（｡･ω･｡)つ━☆・*。
⊂　　 ノ 　　　・゜+.
　しーＪ　　　°。+ *´¨)
 　　　　　　　　　.· ´¸.·*´¨) ¸.·*¨)
		  　　　　　　　　　　(¸.·´ (¸.·'* ☆
					*/

#include <stdio.h>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstring>
#include <vector>
#include <numeric>
#include <iostream>
#include <random>
#include <map>
#include <unordered_map>
#include <queue>
#include <regex>

#pragma GCC optimize("Ofast")
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define rep1(i, n) for(int i = 1; i <= (n); ++i)
#define rep2(i, n) for(int i = 2; i < (n); ++i)
#define repr(i, n) for(int i = n; i >= 0; --i)
#define reprm(i, n) for(int i = n - 1; i >= 0; --i)
#define printynl(a) printf(a ? "yes\n" : "no\n")
#define printyn(a) printf(a ? "Yes\n" : "No\n")
#define printYN(a) printf(a ? "YES\n" : "NO\n")
#define printin(a) printf(a ? "possible\n" : "inposible\n")
#define printdb(a) printf("%.50lf\n", a)//少数出力
#define printdbd(a) printf("%.16lf\n", a)//少数出力(桁少なめ)
#define prints(s) printf("%s\n", s.c_str())//string出力
#define all(x) (x).begin(), (x).end()
#define allsum(a, b, c) ((a + b) * c / 2)//等差数列の和、初項,末項,項数
#define pb push_back
#define priq priority_queue
#define rpriq priq<int, vector<int>, greater<int>>
#define deg_to_rad(deg) (((deg)/360.0)*2.0*PI)
#define rad_to_deg(rad) (((rad)/2.0/PI)*360.0)
#define Please return
#define AC 0

using ll = long long;

constexpr int INF = 1073741823;
constexpr int MINF = -1073741823;
constexpr ll LINF = ll(4661686018427387903);
constexpr ll MOD = 1000000007;
const double PI = acos(-1);

using namespace std;

void scans(string& str) {
	char c;
	str = "";
	scanf("%c", &c);
	if (c == '\n')scanf("%c", &c);//最初の改行対策
	while (c != '\n' && c != -1) {
		str += c;
		scanf("%c", &c);
	}
}

void scanc(char& str) {
	char c;
	scanf("%c", &c);
	if (c == -1)return;
	while (c == '\n') {
		scanf("%c", &c);
	}
	str = c;
}

double acot(double x) {
	return PI / 2 - atan(x);
}

/*-----------------------------------------ここからコード-----------------------------------------*/


int main() {
	
	int a, b;
	scanf("%d%d", &a, &b);
	if(a == 4 || a == 6 || a == 9 || a == 11)a = 2;
	else if(a == 2)a = 3;
	else a = 1;
	if(b == 4 || b == 6 || b == 9 || b == 11)b = 2;
	else if(b == 2)b = 3;
	else b = 1;
	printyn(a == b);
	
	Please AC;
}


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

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

bool IsPrime(int n) {
    FOR(i, 2, int(sqrt(n))+1) {
        if(n%i==0) return false;
    }
    return true;
}

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

    int cnt=0;
    REP(i, n) {
        int a;
        cin >> a;
        if (IsPrime(a)) cnt++;
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 3064
#include<iostream>

using namespace std;

char grid[105][105];

int main() {
  int a,b;
  cin >> a >> b;
  a--;b--;
  for(int i = 0; i < 100; i++) {
    for(int j = 0; j < 100; j++) {
      if(i < 50) grid[i][j] = '#';
      else grid[i][j] = '.';
    }
  }
  for(int i = 0; i < 49; i+=2) {
    for(int j = 0; j < 100; j+=2) {
      if(a > 0) {
	grid[i][j] = '.';
	a--;
      }
    }
  }
  for(int i = 51; i < 100; i+=2) {
    for(int j = 0; j < 100; j+=2) {
      if(b > 0) {
	grid[i][j] = '#';
	b--;
      }
    }
  }
  cout << "100 100" << endl;
  for(int i = 0; i < 100; i++) {
    for(int j = 0; j < 100; j++) {
      cout << grid[i][j];
    }
    cout << endl;
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#pragma GCC optimization ("unroll-loops")
#pragma GCC optimization ("O2")
#pragma GCC target("popcnt")
#pragma GCC target ("avx2")
using namespace std;
vector<pair<int,int>> graph[100001],edges;
int n,m,deg[100001],ans[100001];

void bfs(int curr){
    map<int,pair<int,int>> from;
    set<int> seen;
    seen.insert(curr);
    queue<int> q;
    for(pair<int,int> i : graph[curr]){
        from[i.first] = {curr,i.second};
        seen.insert(i.first);
        q.push(i.first);
    }
    int found;
    while(q.size()){
        int a = q.front();
        q.pop();
        if(deg[a] == 1){
            found = a;
            break;
        }
        for(pair<int,int> i : graph[a]){
            if(seen.count(i.first)){
                continue;
            }
            seen.insert(i.first);
            from[i.first] = {a,i.second};
            q.push(i.first);
        }
    }
    deg[found] ^= 1;
    deg[curr] ^= 1;
    while(from.find(found) != from.end()){
        pair<int,int> a = from[found];
        ans[a.second] ^= 1;
        found = a.first;
    }
}

bool check(){
    int cnt2[n+1];
    for(int i = 1 ; i <= n ; i += 1){
        cnt2[i] = 0;
    }
    int ok = 0;
    for(int i = 0 ; i < m ; i += 1){
        if(ans[i] == 0){
            cnt2[edges[i].first] += 1;
            if(cnt2[edges[i].first] % 2 == 1){
                ok += 1;
            }else{
                ok -= 1;
            }
        }else{
            cnt2[edges[i].second] += 1;
            if(cnt2[edges[i].second] % 2 == 1){
                ok += 1;
            }else{
                ok -= 1;
            }
        }
    }
    return ok == 0;
}

int main(){
    cin >> n >> m;
    for(int i = 0 ; i < m ; i += 1){
        int a,b;
        cin >> a >> b;
        graph[a].push_back({b,i});
        graph[b].push_back({a,i});
        edges.push_back({a,b});
        deg[a] ^= 1;
    }
    if(m % 2 == 1){
        cout << -1 << endl;
        return 0;
    }
    for(int i = 1 ; i <= n ; i += 1){
        if(deg[i] == 1){
            bfs(i);
        }
    }
    for(int i = 0 ; i < m ; i += 1){
        if(ans[i] == 0){
            cout << edges[i].first << " " << edges[i].second << '\n';
        }else{
            cout << edges[i].second << " " << edges[i].first << '\n';
        }
    }
    // assert(check());
}

Measured memory_bytes: 16628
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int n,k;
    int c=0;
    scanf("%lli%lli",&n,&k);

     if(abs(n%k-k)>n%k)   printf("%lli\n",n%k);
else cout<<abs(n%k-k)<<endl;


    }



Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
int main()
{
   string s;
   cin >> s;
   if("Sunny" == s)
     cout << "Cloudy";
   else if("Cloudy" == s)
     cout << "Rainy";
   else if("Rainy" == s)
     cout << "Sunny";
   return 0;
}

Measured memory_bytes: 764
use std::io;
use std::str::FromStr;

fn input<T:FromStr>() -> T {
    let mut line: String = String::new();
    io::stdin().read_line(&mut line);
    line.trim().parse().ok().unwrap()
}

fn main() {
    let n: u64 = input();
    let f = n % 10;
    if f == 2 || f == 4 || f == 5 || f == 7 || f == 9 {
        println!("hon");
    } else if f == 3 {
        println!("bon");
    } else {
        println!("pon");
    }
}


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

int main(){
  int N,M;
  cin >> N >> M;
  priority_queue<P> q;//firstは数字の大きさ,secondは枚数
  int A[N],B[M],C[M];
  rep(i,N){
    cin >> A[i];
  }
  rep(i,M){
    cin >> B[i] >> C[i];
  }
  rep(i,N) q.push(make_pair(A[i],1));
  rep(i,M) q.push(make_pair(C[i],B[i]));

  ll ans=0;
  rep(i,N){
    auto p = q.top();q.pop();
    ans += p.first;
    if(p.second>1){//1枚使ったので減らす
      p.second--;
      q.push(p);
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3572
#include <algorithm>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define show(x) cout << #x << " = " << (x) << endl;
using namespace std;
using ll = long long;
using pii = pair<int,int>;
int main(){
    int n;
    cin >> n;
    string a,b,c;
    cin >>a >> b >> c;
    int ans = 0;
    rep(i,n){
        if(a[i] == b[i] and b[i] == c[i]){
            ans += 0;
        }else if(a[i] == b[i]){
            ans++;
        }else if(b[i] == c[i]){
            ans++;
        }else if(c[i] == a[i]){
            ans++;
        }else{
            ans+=2;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
// https://beta.atcoder.jp/contests/abc112

#define SUBMIT

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

int main() {
    int n;
    cin >> n;
    if (n == 1) cout << "Hello World" << endl;
    else {
        int a, b;
        cin >> a >> b;
        cout << a + b << endl;
    }
    return 0;
}

Measured memory_bytes: 764
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while(sc.hasNext()) {
			String[] sarr = sc.next().split(",");
			int[] x = new int[13];
			for(int i=0;i<12;i++) {
				x[i] = Integer.valueOf(sarr[i]);
			}
			int v1 = x[10];
			int v2 = x[11];
			for(int i=1;i<10;i++) {
				x[i] += x[i-1];
			}
			for(int i=0;i<10;i++) {
				if (x[9]*v1<=x[i]*(v1+v2)) {
					System.out.println(i+1);
					break;
				}
			}
		}
	}

}

Measured memory_bytes: 17160
#include <stdio.h>

int main(void){
	int a,b,c;

	scanf("%d %d %d",&a,&b,&c);

	if(a<b){
		if(b < c){
			printf("Yes\n");
		}else{
			printf("No\n");
		}
	}else{
		printf("No\n");
	}
}


Measured memory_bytes: 2124
#include<stdio.h>
#include<algorithm>
using namespace std;
int main()
{   int n,l,i,m,a,b,e;
	while(~scanf("%d%d%d",&a,&b,&e))
	{  
	    int c[3];
	    
		c[0]=a;
		c[1]=b;
		c[2]=e;
		sort(c,c+3);
		if(c[0]==5&&c[1]==5&&c[2]==7)
		printf("YES\n");
		else
		printf("NO\n");	
	}
}


Measured memory_bytes: 128
<?php
	fscanf(STDIN, "%s %s", $X, $Y);

	$num1 = 0;
	$num2 = 0;

	switch ($X){
		case "A":
			$num1 = 10;
			break;

		case "B":
			$num1 = 11;
			break;

		case "C":
			$num1 = 12;
			break;

		case "D":
			$num1 = 13;
			break;

		case "E":
			$num1 = 14;
			break;


		case "F":
			$num1 = 15;
			break;

	}

	switch ($Y){
		case "A":
			$num2 = 10;
			break;

		case "B":
			$num2 = 11;
			break;

		case "C":
			$num2 = 12;
			break;

		case "D":
			$num2 = 13;
			break;

		case "E":
			$num2 = 14;
			break;


		case "F":
			$num2 = 15;
			break;

	}

	// 出力
	if ($num1 > $num2){
		echo ">\n";
	} elseif ($num1 < $num2) {
		echo "<\n";
	} elseif ($num1 == $num2) {
		echo "=\n";
	}


?>

Measured memory_bytes: 3828
#include <algorithm>
#include <iostream>
#include <numeric>
#include <vector>

int main() {
    int n;
    std::cin >> n;
    std::vector<int> a(n);
    for (int i = 0; i < n; i++) {
        std::cin >> a[i];
    }

    int min = *std::min_element(a.begin(), a.end());
    int max = *std::max_element(a.begin(), a.end());
    long long sum = std::accumulate(a.begin(), a.end(), 0LL);
    std::cout << min << " " << max << " " << sum << std::endl;
}



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

using namespace std;
using ull = unsigned long long;
using ll = long long;

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

	int x = std::count(s.begin(), s.end(), 'R');

	int y = std::count(s.begin(), s.begin() + x, 'R');
	cout << x-y << endl;
}

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

int main(void){
    ll x, y;
    cin >> x >> y;
    
    ll t = x, ans = 0;
    while (t <= y) {
        ans++;
        t *= 2;
    }
    
    cout << ans << endl;
    
    return 0;
}


Measured memory_bytes: 3632
from sys import stdin, stdout, setrecursionlimit
from collections import deque, defaultdict, Counter
from heapq import heappush, heappop
import math

rl = lambda: stdin.readline()
rll = lambda: stdin.readline().split()
rli = lambda: map(int, stdin.readline().split())
rlf = lambda: map(float, stdin.readline().split())

INF, NINF = float('inf'), float('-inf')

def main():
	n = int(rl())
	f = lambda x, y, z: x**2 + y**2 + z ** 2 + x*y + y*z + z*x
	vals = defaultdict(lambda: 0)
	for x in range(1, 120):
		for y in range(1, 120):
			for z in range(1, 120):
				cand = f(x,y,z)
				if cand > n: break
				vals[cand] += 1
	for i in range(1, n+1):
		print(vals[i])
	stdout.close()

if __name__ == "__main__":
	main()

Measured memory_bytes: 75812
#include <bits/stdc++.h>
using namespace std;
map <string, int> mp = {{"maerd", 1}, {"esare", 1}, {"remaerd", 1}, {"resare", 1}};
int main()
{
    string s, T = "", TT = "", TTT = "";
    cin >> s;
    int len = s.size(), i = 0, flag = 0, idx = 0;
    reverse(s.begin(), s.end());
    while(i < len){
        T = s.substr(i, 5);
        TT = s.substr(i, 6);
        TTT = s.substr(i, 7);

        if(mp[T]){
            flag = 1;
            T = "";
            TT = "";
            TTT = "";
            i += 4;
        }
        else if(mp[TT]){
            flag = 1;
            T = "";
            TT = "";
            TTT = "";
            i += 5;
        }
        else if(mp[TTT]){
            flag = 1;
            T = "";
            TT = "";
            TTT = "";
            i += 6;
        }
        else{
            flag = 0;
            break;
        }
        i++;
    }
    if(flag) cout << "YES" << endl;
    else cout << "NO" << endl;
    return 0;
}


Measured memory_bytes: 512
#define _USE_MATH_DEFINES 
#include<iomanip> 
#include<cmath>  
#include<iostream>
#include<fstream>
#include<vector>
#include<algorithm>
#include<numeric>
#include<bitset>
#include<map>
#include<unordered_map>
#include<set>
#include<unordered_set>
#include<queue>
#include<deque>
#include<stack>
using namespace std;
typedef long long ll;
#define repi(i,a,b) for(ll i = (ll)(a) ; i < (ll)(b) ; i++)
#define repd(i,a,b) for(ll i = (ll)(a) ; i > (ll)(b) ; i--)
#define rd(x) cin >> x
#define wr(x)  cout << x
#define wrln(x) cout << x << endl
const ll MAX_10p5 = 100010;
const ll MAX_10p9 = 1000000010;
const ll MAX_10p18 = 1000000000000000010;
const ll MOD = 1000000007;
const ll m4x[4] = { 1,0,-1,0 };
const ll m4y[4] = { 0,1,0,-1 };
const ll m8x[8] = { 1,1,0,-1,-1,-1,0,1 };
const ll m8y[8] = { 0,1,1,1,0,-1,-1,-1 };
const ll m9x[9] = { 1,1,0,-1,-1,-1,0,1,0 };
const ll m9y[9] = { 0,1,1,1,0,-1,-1,-1,0 };

struct edge {
	ll from, to, cost;
	bool operator<(const edge& right) const {
		return cost < right.cost;
	}
};
struct point {
	ll x, y;
	bool operator<(const point& right) const {
		return x == right.x ? y < right.y : x < right.x;
	}
};

///////////////////////////////////////////////////////////////////////////////////////

ll N, a[MAX_10p5], tempsum[2], ans[2];

int main() {
	rd(N);
	repi(i, 0, N) rd(a[i]);
	repi(k, 0, 2) {
		repi(i, 0, N) {
			tempsum[k] += a[i];
			if ((i % 2) == (k % 2)) {
				if (!(tempsum[k] > 0)) {
					ans[k] += 1 - tempsum[k];
					tempsum[k] = 1;
				}
			}
			else {
				if (!(tempsum[k] < 0)) {
					ans[k] += 1 + tempsum[k];
					tempsum[k] = -1;
				}
			}
		}
	}
	wrln(min(ans[0], ans[1]));
	return 0;
}


Measured memory_bytes: 1024
n, m = gets.split.map(&:to_i)
c = []
if n == 1 && m == 1
  puts 1
elsif n == 1 || m == 1
  puts n * m - 2
elsif n == 2 || m == 2
  puts 0
else
  puts n * m - 2 * n - 2 * m + 4
end


Measured memory_bytes: 1788
#include <bits/stdc++.h>
using namespace std;
 
int N;
int A;
int B;
int main () {
  cin >> N;
  cin >> A;
 
  B=N%500;
  if(B<=A)
  {
    cout << "Yes" << endl;
  }
  else
  {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#define N 500
#define sNA 1<<15
int cmp(const void* a,const void* b){ long long c=*(int*)a,d=*(int*)b; return (c<d)?-1:(c>d); }
int main(void){
    long long total,i,j,a,b,n,k,A[N],d[N],factor[sNA];
    scanf("%lld %lld",&n,&k);
    for(i=0;i<n;i++) scanf("%lld",&A[i]);
    for(i=total=0;i<n;i++) total += A[i];
    for(i=1,j=0;i*i<=total;i++) if(total%i==0) factor[j++] = i;
    for(i=j;i<2*j;i++) factor[i] = total/factor[2*j-1-i];
    b=j*2;
    for(a=b-1;a>=0;a--){
        for(i=0;i<n;i++) d[i] = A[i] - (A[i]/factor[a])*factor[a];
        qsort(d,n,sizeof(long long),cmp);
        for(i=total=0;i<n;i++) total += d[i];
        j=total/factor[a];
        for(i=total=0;i<j;i++) total += factor[a]-d[n-1-i];
        if(total<=k) break;
    }
    printf("%lld\n",factor[a]);
    return 0;
}


Measured memory_bytes: 252
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define f(a, b) for (ll i = a; i <= b; i++)
#define pb push_back
#define pf push_front
#define mp make_pair
using namespace std;
#define N 200005
const ll INF = 1000000000000000001;
const ll MOD = 1000000007;

//vector< vector<ll> > g(N);
//vector< pair<ll, pair< ll, ll > > > g(N);
//ll vis[N] = {0}, par[N] = {0}, child[N] = {0},cnt = 0;


void solve(){
    string s; cin >> s;
    if(s[s.size()-1] == 's') cout << s << "es";
    else cout << s << 's';
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    #ifndef ONLINE_JUDGE
        freopen("input.txt","r",stdin);
        freopen("out.txt","w",stdout);
    #endif
   //ll t;cin >> t;for(ll index=1; index<=t; index++){
        //cout << "Case #" << index << ": " ;
        solve();
   // }
    return 0;
}

Measured memory_bytes: 3648
import java.util.Arrays;
import java.util.Scanner;
import java.util.stream.IntStream;

/**
 * 解説通りに作成したソースコード
 */
public class Main {

	/** 計算する最大値 */
	private static final int N = 100_000;

	public static void main(String[] args) {
		try (Scanner scanner = new Scanner(System.in)) {
			// Nまでの素数を計算する
			boolean[] isPrime = new boolean[N + 1];
			Arrays.fill(isPrime, true);
			isPrime[0] = isPrime[1] = false;
			IntStream.rangeClosed(2, N).forEach(i -> {
				if (isPrime[i]) {
					IntStream.rangeClosed(2, N / i).forEach(j -> isPrime[j * i] = false);
				}
			});
			// 最大値まで2017に似た数を計算する
			int[] count = new int[N];
			count[0] = count[1] = count[2] = 0;
			IntStream.range(3, N).forEach(i -> count[i] = count[i - 1] + (is2017LikeNumber(i, isPrime) ? 1 : 0));
			int q = scanner.nextInt();
			IntStream.range(0, q).map(i -> {
				int l = scanner.nextInt(), r = scanner.nextInt();
				return count[r] - count[l - 1];
			}).forEach(System.out::println);
		}
	}

	/**
	 * 入力数字が2017に似た数であるかどうかを計算
	 * 
	 * @param number  入力数字
	 * @param isPrime indexが素数かどうかの配列
	 * @return 入力数字が2017に似た数であるかどうか
	 */
	private static boolean is2017LikeNumber(int number, boolean[] isPrime) {
		return (1 == (number & 1)) && isPrime[number] && isPrime[(number + 1) / 2];
	}
}


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

#define FOR(i,l,r) for(int i = int(l);i < int(r);i++)
template<typename T> bool chmax(T& a,const T& b){ return a < b ? (a = b,true) : false; }
template<typename T> bool chmin(T& a,const T& b){ return b < a ? (a = b,true) : false; }
typedef long long ll;

int N;
vector<int> A;

int main()
{
	scanf("%d",&N);
	A.assign(N,0);
	FOR(i,0,N){
		scanf("%d",&A [i]);
	}

	int x = 1,y = 1;
	FOR(i,0,N) x *= 3;
	FOR(i,0,N){
		if(A [i] % 2 == 0){
			y *= 2;
		}
	}
	printf("%d\n",x - y);

	return 0;
}


Measured memory_bytes: 256
import java.util.*;
class Main{
	public static void main(String[]z){
		Scanner cin=new Scanner(System.in);
		int y,m,d,Y,M,D;
		while(true){
			y=cin.nextInt();m=cin.nextInt();d=cin.nextInt();Y=cin.nextInt();M=cin.nextInt();D=cin.nextInt();
			if(y==-1)return;
			System.out.println((new GregorianCalendar(Y,M-1,D).getTimeInMillis()-new GregorianCalendar(y,m-1,d).getTimeInMillis())/86400000);
		}
	}
}

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

using namespace std;
typedef long long ll;

#define MOD (long long)(1e9+7)
#define INF (1LL<<60)
#define rep(i,n) for(ll i = 0; i < (n); i++)
#define rep1(i,n) for(ll i = 1; i <= (n); i++)

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


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

// mod m におけるa の逆元
ll modinv(ll a, ll m) {
  ll b = m, u = 1, v = 0;
  while (b) {
    ll t = a / b;
    a -= t * b; swap(a, b);
    u -= t * v; swap(u, v);
  }
  u %= m;
  if (u < 0) u += m;
  return u;
}

// 素因数分解
vector<pair<ll, ll>> prim;
void pf(ll n)
{
  ll s = sqrt(n);
  ll r = 0;
  for(ll i = 2; i <= s; i++) {
    if((n % i) == 0) {
      r = 0;
      do {
	r++;
	n = n / i;
      } while((n % i) == 0);
      prim.push_back({i, r});
    }
  }
  if(n > s) {
    prim.push_back({n, 1});
  }
}

void solve()
{
  // ll N; cin >> N;
  // ll N, K; cin >> N >> K;
  // ll x, y, z; cin >> x >> y >> z;
  // ll a, b, c; cin >> a >> b >> c;
  string s; cin >> s;
  // vector<ll> a(N); rep(i, N) cin >> a[i];
  char ans;
  switch(s[0]) {
  case 'A':
    ans = 'T';
    break;
  case 'T':
    ans = 'A';
    break;
  case 'C':
    ans = 'G';
    break;
  case 'G':
    ans = 'C';
    break;
  }
  // ll ans = 0;
  // bool ok = false;

  cout << ans << endl;
  // cout << (ok?"Yes":"No") << endl;
}


int main(void)
{
  // ll t; cin >> t; rep(i, t)
  solve();
}


Measured memory_bytes: 3688
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using System.Text;
using System.IO;
using static System.Math;
using System.Numerics;
using System.Runtime.InteropServices.ComTypes;
using System.Xml.Schema;
using System.ComponentModel.DataAnnotations;
using System.Security.Cryptography;
using System.Drawing;
using System.Runtime.CompilerServices;
using System.Linq.Expressions;
using System.Xml.XPath;

namespace AtCoder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
            Solve();
            //Out.Flush();
            Read();
        }

        static void Solve()
        {
            var dct = new Dictionary<char, long>();
            foreach (var c in ReadLine())
            {
                if (!dct.ContainsKey(c)) dct[c] = 0;
                ++dct[c];
            }
            if (dct.All(d => d.Value == 2))
                WriteLine("Yes");
            else
                WriteLine("No");
        }

        static long Gcd(long x, long y) => y == 0 ? x : Gcd(y, x % y);
        static long Lcm(long x, long y) => x / Gcd(x, y) * y;

        static long Mod = (long)1e9 + 7;
        static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); }
        static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); }
        static public (T1 a, T2 b) Slice<T1, T2>()
        {
            var t = ReadLine().Split();
            return (
            (T1)Convert.ChangeType(t[0], typeof(T1)),
            (T2)Convert.ChangeType(t[1], typeof(T2)));
        }
        static public (T a, T b) Slice2<T>()
        {
            var t = ReadLine().Split();
            return (
            (T)Convert.ChangeType(t[0], typeof(T)),
            (T)Convert.ChangeType(t[1], typeof(T)));
        }
        static public (T a, T b, T c) Slice3<T>()
        {
            var t = ReadLine().Split();
            return (
            (T)Convert.ChangeType(t[0], typeof(T)),
            (T)Convert.ChangeType(t[1], typeof(T)),
            (T)Convert.ChangeType(t[2], typeof(T)));
        }
        static public (T a, T b, T c, T d) Slice4<T>()
        {
            var t = ReadLine().Split();
            return (
            (T)Convert.ChangeType(t[0], typeof(T)),
            (T)Convert.ChangeType(t[1], typeof(T)),
            (T)Convert.ChangeType(t[2], typeof(T)),
            (T)Convert.ChangeType(t[3], typeof(T)));
        }
    }
}

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

using namespace std;

int main(){
	int n,m;
	cin>>n>>m;
	vector<int> cnt(m+1);
	for(int i=0;i<n;i++){
		int k;
		cin>>k;
		for(int j=0;j<k;j++){
			int x;
			cin>>x;
			cnt[x]++;
		}
	}
	int ans=0;
	for(int i=0;i<=m;i++)
		if(cnt[i]==n)ans++;
	cout<<ans;

}

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

typedef vector< ll > 	vi;
typedef vector< vi > 	vvi;
typedef pair< ll,ll > 	ii;

#define pb 		push_back
#define all(c) 		(c).begin(),(c).end()
#define present(c,x) 	((c).find(x) != (c).end())
#define rep(i,n)        for(ll i=0LL; i<(n); i++)

#define MOD 	1000000007
#define INF 	(int)1e9
#define MEM(a, b) memset(a, (b), sizeof(a))

//Maths functions
ll Digit(ll N){ll res=0;while(N) res++, N/=10;return res;}
ll Gcd(ll a,ll b){ return b?Gcd(b,a%b):abs(a); }


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

	string s, t;
	cin>>s>>t;
	ll m,n;
	cin>>m>>n;
	string st;
	cin>>st;
	if(st==s)
	{
		cout<<m-1<<" "<<n;
	}
	else if(st==t)
	{
		cout<<m<<" "<<n-1;
	}
	else cout<<m<<" "<<n;
	
	return 0;
}

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

#define fastIO \
ios_base::sync_with_stdio(false); cin.tie(NULL);
#define endl "\n"
#define ll long long
#define MOD 1000000007
#define pb push_back
#define ff first
#define ss second
#define mp make_pair

int main(){
	int n;
	cin >> n;
	int a[n];
	for(int i=0;i<n;i++)	cin >> a[i];
	sort(a, a+n);
	double ans = ((double)a[0]+a[1])/2;
	for(int i=2;i<n;i++){
		ans = (ans + a[i])/2;
	}
	cout << fixed << setprecision(9) << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <time.h>
#include <stack>
#include <string>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <cassert>

using namespace std;

const int N = 2005;
const int inf = 1000 * 1000 * 1000;
const int mod = 1000 * 1000 * 1000 + 7;

string s1,s2;
int sum , answ = 10000;
int r[N] , l[N];
pair <int,int> p[N];

int main(){
    cin>>s1>>s2;
    int n = (int)s1.size();
    int z = 0 , k = 0;

    for(int i=0;i<n;i++){
        if(s2[i] == '0')k++;
        if(s1[i] == '1')z++;
    }

    if(k == n){
        if(z > 0)
            cout<<-1<<endl;
        else
            cout<<0<<endl;
        return 0;
    }

    for(int i=0;i<n;i++){
        int x = i;
        while(s2[x] != '1'){
            r[i]++;
            x++;
            x %= n;
        }
        x = i;
        while(s2[x] != '1'){
            l[i]++;
            x--;
            x += n;
            x %= n;
        }
    }

    for(int i=-n+1;i<n;i++){
        vector <int> g[N];
        int sz = 0;
        int ss = 0;
        for(int j=0;j<n;j++){
            int ind = j + i;
            ind += n;
            ind %= n;
            if(s1[j] != s2[ind]){
                ss++;
                if(i < 0){
                    if(l[j] > -i){
                        g[l[j]].push_back(r[j]);
                        sz++;
                    }
                }
                else{
                    if(r[j] > i){
                        g[l[j]].push_back(r[j]);
                        sz++;
                    }
                }
            }
        }
        if(sz > 0){
            int X , Y = 0 , sum = 10000;
            for(int j=n;j>=0;j--){
                if((int)g[j].size() == 0)continue;
                for(int h=0;h<(int)g[j].size();h++){
                    /////////// update answer
                    X = j;
                    if(i < 0)
                        X = max(X , -i);
                    else
                        Y = max(Y , i);
                    if(2 * (X + Y) < sum) sum = 2 * (X + Y);
                    /////////////////////////
                    Y = max(Y , g[j][h]);
                }
            }
            X = 0;
            if(i < 0)
                X = max(X , -i);
            else
                Y = max(Y , i);
            if(2 * (X + Y) < sum) sum = 2 * (X + Y);
            answ = min(answ , sum - abs(i - 0) + ss);
        }
        else
            answ = min(answ , abs(i - 0) + ss);
    }
    cout<<answ<<endl;
    return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <iomanip>
#include <string>
#include <sstream>
#include <algorithm>
#include <map>
#include <bits/stdc++.h>

using namespace std;

#define REP(i,n) FOR(i,0,n)
#define FOR(i,a,b) for(long long i=(a),i##Len_=(b);i<i##Len_;i++)
typedef long long ll;
typedef pair<long long, long long> pll;
static const ll MOD = 1000000007;
static const ll INF = 1000000000000000000LL;

//N M Q
//M本の電車区間
//Qの範囲に収まるM
int main() {

    ll N,M,S;

    cin >> N >> M >> S;

    ll tmp1,tmp2;

    ll LR[N][N] = {};
    REP(i,M)
    {
        cin >> tmp1 >> tmp2;

        --tmp1;--tmp2;
        ++LR[tmp1][tmp2];
    }

    //ソートすることで

    ll ruiseki[N+1][N+1] = {};

    REP(i,N)
    {
        REP(j,N)
        {
            ruiseki[i+1][j+1] = ruiseki[i][j+1] + ruiseki[i+1][j] - ruiseki[i][j] + LR[i][j];
        }
    }

    //vector <pair<pll,ll>> PQ(Q);
    ll P,Q;
    REP(i,S)
    {
        cin >> P >> Q;
        --P;

        ll res = ruiseki[Q][Q] - ruiseki[P][Q] - ruiseki[Q][P] + ruiseki[P][P];

        cout << res << endl;
    }

    return 0;
    
}

Measured memory_bytes: 4864
#include <bits/stdc++.h>
using namespace std;
struct iofix
{
   ios_base::Init i;
   iofix() {
      cin.sync_with_stdio(0);
      cin.tie(0);
      cout.sync_with_stdio(0);
      cout.tie(0);
      cout.precision(10);
      cout << fixed;
   }
} iofix;

void solve(){
  int x; cin >> x;
  if(!x)
     cout << 1;
  else 
     cout << 0;
}

int main(){

   	solve();

#ifndef Time
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
   return 0;
}

Measured memory_bytes: 3844
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

struct State{
    int at;
    ll cost;
    State(int a, ll c) : at(a), cost(c){}
    bool operator>(const State& s) const{
        return cost > s.cost;
    }
};

struct Edge{
    int to;
    ll cost;
    Edge(int t, ll c) : to(t), cost(c){}
};

using Graph = vector<vector<Edge> >;
const ll INF = 1e15;

void dijkstra(int s, const Graph& G, vector<ll>& minc){
    minc.assign(G.size(), INF);
    priority_queue<State, vector<State>, greater<State> > pq;
    pq.emplace(s, 0);
    minc[s] = 0;
    while(!pq.empty()){
        State cur = pq.top();
        pq.pop();
        if(minc[cur.at] < cur.cost) continue;
        for(const Edge& e : G[cur.at]){
            ll cost = cur.cost + e.cost;
            if(minc[e.to] <= cost) continue;
            minc[e.to] = cost;
            pq.emplace(e.to, cost);
        }
    }
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
	int n, m, s, t;
	cin >> n >> m >> s >> t;
	s--; t--;
	Graph g1(n), g2(n);
	rep(i,m){
		int u, v, a, b;
		cin >> u >> v >> a >> b;
		u--; v--;
		g1[u].emplace_back(v, a);
		g1[v].emplace_back(u, a);
		g2[u].emplace_back(v, b);
		g2[v].emplace_back(u, b);
	}
	vector<ll> minc1, minc2;
	dijkstra(s, g1, minc1);
	dijkstra(t, g2, minc2);
	vector<ll> ans(n, INF);
	for(int i = n-1; i >= 0; i--){
		chmin(ans[i], minc1[i] + minc2[i]);
		if(i < n-1) chmin(ans[i], ans[i+1]);
	}
	rep(i,n) cout << INF - ans[i] << endl;
    return 0;
}

Measured memory_bytes: 19016
#include <stdio.h>

int main(void) {
	int a,b,c,d,e,k;
	scanf("%d %d %d %d %d %d", &a, &b, &c, &d, &e, &k);
	printf(e-a<=k?"Yay!\n":":(\n");
	
	return 0;
}

Measured memory_bytes: 128
#include <cstdio>
#include <string>
#include <vector>
#include <map>
using namespace std;
int main() {
	int cnt = 0;
	int n, t;
	scanf("%d", &n);
	map<int, bool> m;
	for (int i = 0;i < n;i++) {
		scanf("%d", &t);
		if (m[t] == false) {
			m[t] = true;
			cnt++;
		} else {
			m[t] = false;
			cnt--;
		}
	}
	printf("%d", cnt);
}

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

int e[200][200];

int calc(int f, int n) {
    vector<int> c(n, -1);
    queue<int> q; q.push(f); c[f] = 1; int ret = 1;
    while (!q.empty()) {
        int curr = q.front(); q.pop();
        for (int i = 0; i < n; i++) {
            if (e[curr][i]) {
                if (c[i] == -1) {
                    c[i] = c[curr] + 1;
                    ret = max(ret, c[i]);
                    q.push(i);
                } else {
                    if (abs(c[i] - c[curr]) != 1) {
                        return -1;
                    }
                }
            }
        }
    }
    return ret;
}

int main() {
    int n; cin >> n;
    for (int i = 0; i < n; i++) {
        string s; cin >> s;
        for (int j = 0; j < n; j++) {
            e[i][j] = s[j] - '0';
        }
    }
    int ans = -1;
    for (int i = 0; i < n; i++) {
        ans = max(ans, calc(i, n));
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 384
### main

loop do
  n = gets.strip.to_i
  k = gets.strip.to_i
  break if (n | k) == 0

  ds = n.times.map{gets.strip.to_i}
  #p ds

  nums = {}

  ds.permutation(k) do |ns|
    nums[ns.join('')] = true
  end

  puts nums.keys.length
end

Measured memory_bytes: 6668
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
#define rep(i,n) for(int i = 0; i < ((int)(n)); i++)   // 0-indexed昇順

int main() {
    ll N; cin >> N;
    vector<ll> A(N), B(N);
    ll fixA = 0, fixB = 0;
    ll WaA = 0, WaB = 0;
    rep(i, N) cin >> A.at(i);
    rep(i, N) {
        cin >> B.at(i);
        WaA += A[i];
        WaB += B[i];
        if (A[i] < B[i]) { // You should check A first cause A can be updated
            ll d = (B[i] - A[i] + 1) / 2;
            fixA += d;
            A[i] += d * 2; // This update works right below here.
        }
        if (A[i] > B[i]) {
            ll d = A[i] - B[i];
            fixB += d;
            B[i] += d;
        }
    }
    if (WaA > WaB) {
        cout << "No" << endl;        
        return 0;
    }

    if (fixA >= fixB) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }

}


Measured memory_bytes: 3768
INF = 10e5
n = int(input())
h = list(map(int,input().split()))
dp = [INF for _ in range(n)]

dp[0] = 0
dp[1] = abs(h[1]-h[0])

for i in range(2,n):
    cost1 = abs(h[i]-h[i-1])
    cost2 = abs(h[i]-h[i-2])
    dp[i] = min(dp[i-1] + cost1, dp[i-2] + cost2)

print(dp[n-1])

Measured memory_bytes: 13980
#include <bits/stdc++.h>
using namespace std;
#define int long long int
float distance(int x1, int y1, int x2, int y2) 
{ 
    // Calculating distance 
    return sqrt(pow(x2 - x1, 2) +  
                pow(y2 - y1, 2) * 1.0); 
} 
int factorial(int n) 
{ 
    // single line to find factorial 
    return (n==1 || n==0) ? 1: n * factorial(n - 1);  
}

signed main()
{
  int n;
  cin>>n;
   double x[n],y[n];

  for(int i=0;i<n;i++)
  {
  	cin>>x[i]>>y[i];
  }
  vector<int> vec(n);
  for(int i=0;i<n;i++)
  	vec[i]=i;
  double sum=0;
  do 
  {
    for(int i=0;i<n-1;i++)
    {
    	sum+=distance(x[vec[i+1]],y[vec[i+1]],x[vec[i]],y[vec[i]]);//linearly caluculating next permutations and summing the distance
    }

  }while(next_permutation(vec.begin(), vec.end()));
  double ans=sum/factorial(n);
  cout<<setprecision(10)<<ans<<endl;


	return 0;

}

Measured memory_bytes: 256
#include<stdio.h>
#include<cstdio>
#include<iostream>
#include<math.h>
#include<algorithm>
#include<string.h>
#include<string>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#define pi 3.14159
#define Inf (int)pow(2., 12.)

using namespace std;
typedef std::pair<int, int> mypair;
queue<mypair> qu;
#define M 1000000
const int dy[4] = {0, 1, 0, -1}, dx[4] = {1, 0, -1, 0};
#define N 123456 
int num = 0;


int main(){
	int a[2*N+1];
	for(int i = 0; i <= 2*N; i++) {
		a[i] = i;
	}
	a[1] = 0;
	for(int i = 2; i*i <= 2*N; i++) {
		if(a[i] != 0) {
			for(int j = 2*i; j <= 2*N; j++) {
				if(j % i == 0) a[j] = 0;
			}
		}
	}
	int n;
	while(1) {
		int count = 0;
		cin >> n;
		if(n == 0) break;
		for(int i = n+1; i <= 2*n; i++) {
			if(a[i] != 0) count++;
		}
		cout << count <<endl;
	}
	
	return 0;
}

Measured memory_bytes: 2164
using System;

public class Program
{ 
  private static void Main()
  {
    int N = int.Parse(Console.ReadLine());
    char[] S = Console.ReadLine().ToCharArray();
    
    int count = 1;
    
    for(int i = 0; i < N - 1; i ++)
    {
      if(S[i] != S[i + 1])
        count++;
    }
    
    Console.WriteLine(count.ToString());
  }
}


Measured memory_bytes: 11488
#include <iostream>//cin/cout/wcin/wcout/left/right/internal/dec/hex/oct/fixed/scientific
#include <string>//stoi/stol/stoul/stoll/stoull/stof/stod/stold/to_string/getline

using namespace std;

int main()
{
    size_t n, m;
    cin >> n >> m;
    string* a = new string[n];
    string* b = new string[m];
    for(size_t i = 0; i < n; ++i) { cin >> a[i]; }
    for(size_t i = 0; i < m; ++i) { cin >> b[i]; }

    bool found;
    for(size_t atop = 0; atop <= n-m; ++atop)
    {
        for(size_t alef = 0; alef <= n-m; ++alef)
        {
            found = true;
            for(size_t btop = 0; btop < m; ++btop)
            {
                for(size_t blef = 0; blef < m; ++blef)
                {
                    if (b[btop][blef] != a[atop+btop][alef+blef]) {found = false; goto nf;}
                }
            }
            nf:
            if (found) goto ff;
        }
    }
    ff:
    cout << (found ? "Yes" : "No") << endl;
    return 0;
}


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

using namespace std;
 
int main() {
    int n; cin>>n;
    long long ans = 0;
    vector<int> a(n+1), b(n);
    for(int i = 0; i < n+1; i++) cin >> a[i];
    for(int i = 0; i < n; i++) cin >> b[i];

    for(int i=0; i<n; i++){
        int left = 0;
        left = min(a[i], b[i]);
        a[i] -= left;
        b[i] -= left;
        ans += left;

        int right = 0;
        right = min(a[i+1], b[i]);
        a[i+1] -= right;
        b[i] -= right;
        ans += right;
    }

    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1024
n, m = map(int, input().split())
h = [int(n) for n in input().split()]
check = [0] * n

for i in range(m):
    a, b = map(int, input().split())
    if h[a-1] < h[b-1]:
        check[a-1] = 1
    elif h[a-1] > h[b-1]:
        check[b-1] = 1
    elif h[a-1] == h[b-1]:
        check[a-1] = 1
        check[b-1] = 1

print(check.count(0))

Measured memory_bytes: 20064
#include <bits/stdc++.h>
#define Rint register int
#define C(n,m) (n<m?0:1ll*fac[n]*invfac[n-m]%mod*invfac[m]%mod)
using namespace std;
int T,n,m,p,k,st[4010],t=0,A,B;
char ans[4010];
int query(int x,int y){
	printf("? %d %d\n",x,y);
	fflush(stdout);
	char a;
	scanf(" %c",&a);
	return a=='Y';
}
int main(){
	scanf("%d%d",&A,&B);
	if(A<=B) return puts("Impossible"),fflush(stdout);
	n=A+B;
	for(int i=0;i<n;i++){
		if(!t) st[++t]=i;
		else{
			int res=query(st[t],i);
			if(!res) t--;
			else st[++t]=i;
		}
	}
	for(int i=0;i<n;i++){
		if(i!=st[t]) ans[i]=query(st[t],i)+'0';
		else ans[i]='1';
	}
	putchar('!'),putchar(' ');puts(ans);
	fflush(stdout);
}


Measured memory_bytes: 3836
#include <stdio.h>

int main(void) {

  long q;
  scanf("%ld", &q);
  long l[q],r[q];
  for (long i = 0; i < q; i++) {
    scanf("%ld %ld", &l[i], &r[i]);
  }
  int prime[200001];
  prime[0] = 0;
  prime[1] = 0;
  for (long i = 2; i < 200001; i++) {
    prime[i] = 1;
  }
  for (long i = 2; i < 200001; i++) {
    if (prime[i] == 1) {
      for (long j = 2; i*j < 200001; j++) {
        prime[i*j] = 0;
      }
    }
  }
  long sum[200001];
  sum[0] = 0;
  for (long i = 1; i < 200001; i++) {
    sum[i] = sum[i-1];
    if (i%2 == 1 && prime[i] == 1 && prime[(i+1)/2] == 1) {
      sum[i]++;
    }
  }
  for (long i = 0; i < q; i++) {
    printf("%ld\n", sum[r[i]]-sum[l[i]-1]);
  }

  return 0;
}

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

#define rep(i,n) for(int i=0 ; i<(n) ; i++)
#define repr(i,n) for(int i=(n) ; i>=0 ; i--)
#define FOR(i,m,n) for(int i=(m) ; i<(n) ; i++)
#define FORR(i,m,n) for(int i=(m) ; i>=(n) ; i--)

typedef long long ll;
typedef unsigned long long ull;

const int INF = 1000000000;

int main(){
   string a,b;cin >> a >> b;
   int c = stoi(a + b);
   int ans = sqrt(c);
   if(ans == sqrt(c)){
      cout << "Yes";
   }else{
      cout << "No";
   }
   return 0;
}

Measured memory_bytes: 256