akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
using namespace std;

int dim[100000];

void init() {
  fill(dim, dim+100000, 0);
}

bool hitofude() {
  if ((dim[1]*dim[2]+1)%2) {
    return false;
  }
  for (int i=3; i<100000; i++) {
    if (dim[i]%2) {
      return false;
    }
  }
  return true;
}

int main() {
  int a,b;
  init();
  while (scanf("%d%d", &a, &b)!=EOF) {
    dim[a]++;
    dim[b]++;
    if (a==0 && b==0) {
      if (hitofude()) {
	printf("OK\n");
      } else {
	printf("NG\n");
      }
      init();
    }
  }
}

Measured memory_bytes: 1540
class BITree:
    def __init__(self, n):
        self.size = n
        self.tree = [0] * (n + 1)
 
    def sum(self, i):
        s = 0
        while i > 0:
            s += self.tree[i]
            i -= i & -i
        return s
 
    def add(self, i, x):
        while i <= self.size:
            self.tree[i] += x
            i += i & -i
N,K=map(int,input().split())
a=[int(input()) for i in range(N)]
b=[0 for i in range(N+1)]
for i in range(N):
    b[i+1]=b[i]+a[i]-K
btmp=sorted([(b[i],i) for i in range(N+1)])
c=[-1 for i in range(N+1)]
for i in range(N+1):
    c[btmp[i][1]]=i+1
bit=BITree(N+1)
ans=0
for j in range(N+1):
    ans+=j-bit.sum(c[j])
    bit.add(c[j],1)
print((N*(N+1))//2-ans)

Measured memory_bytes: 52748
package main

import (
	"fmt"
)

func main() {
	var n, a, b int
	fmt.Scan(&n, &a, &b)
	result := 0
	for i := 1; i <= n; i++ {
		k := 0
		for j := i; j != 0; j /= 10 {
			k += j % 10
		}
		if a <= k && k <= b {
			result += i
		}
	}
	fmt.Println(result)
}


Measured memory_bytes: 512
import numpy as np
w, h, n = map(int, input().split())
loc = [input() for _ in range(n) ]

def black(x, y, i):
    if i == 1:
        mtx[:x,] = 0
    elif i == 2:
        mtx[x:,] = 0
    elif i == 3:
        mtx[:, :y] = 0
    elif i == 4:
        mtx[:, y:] = 0

        
mtx = np.ones((w, h), dtype=int)
for l in loc:
    x, y, i = map(int, l.split())
    black(x, y, i)
print(mtx.sum())

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

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

  if (N[0] == N[1] && N[1] == N[2]) cout << "Yes" << endl;
  else if (N[3] == N[1] && N[1] == N[2]) cout << "Yes" << endl;
  else cout << "No" << endl;


  return 0;
}

Measured memory_bytes: 764
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <numeric>
#include <queue>
#include <map> 
#include <set>
#include <string>
#include <functional>
#include <list>
#include <random>
#include <time.h>
#include <iomanip>
#include <assert.h>
#define int long long
#define double long double
#define oku7 1000000007
#define MAXN (int)1e+5 * 2+1
#define LL_MAX 9223372036854775807	//ない環境用
#define LL_HALFMAX 9223372036854775807 / 2	//ない環境用

using namespace std;
std::mt19937 mt((int)time(0));

int dx[4] = { 0, 1, 0, -1 }; // x軸方向への変位
int dy[4] = { 1, 0, -1, 0 }; // y軸方向への変位

vector<int> input;

int kanashimi(vector<int> v, int b) {
	int ret = 0;
	for (int i = 0; i < v.size(); i++) {
		ret += abs(v[i] - b);
	}
	return ret;
}

signed main() {
	int N ,sum = 0, ave = 0;
	cin >> N;
	for (int i = 0; i < N; i++) {
		int tmp;
		cin >> tmp;
		sum += tmp - (i + 1);
		input.push_back(tmp - (i + 1));
	}

	/*for (int i = -1000; i < 2000; i++) {
		cout << i << " : " << kanashimi(input, i) << "\n";
	}*/


	//悲しみの二分探索をする
	int l = -1000000000, r = -l , mid;
	int cnt = 0;
	while (1) {
		//欲しいのは最小値なので最小の時だけbreak;
		cnt++;
		mid = (l + r) / 2;
		int midk = kanashimi(input, mid);
		int midl = kanashimi(input, mid-1);
		int midr = kanashimi(input, mid+1);
		if (midk < midl && midk < midr) break;
		if (cnt > 100) break;
		if (midk > midl) r = mid - 1;
		if (midk > midr) l = mid + 1;


	}
	cout << kanashimi(input, mid)<<"\n";

	/*
	ave = sum / N;
	int cand1 = ave, cand2 = ave + 1, cand3 = ave - 1;
	int ans1 = 0, ans2 = 0 ,ans3 = 0;
	for (int i = 0; i < N; i++) {
		ans1 += abs(input[i] - cand1);
		ans2 += abs(input[i] - cand2);
		ans3 += abs(input[i] - cand3);

	}
	*/

	//cout << min(ans1,min(ans2,ans3)) << "\n";

	return 0;
}

Measured memory_bytes: 3440
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<int, int> P;
template<typename T> inline void chkmin(T &a, const T &b) { a = a < b ? a : b; }
template<typename T> inline void chkmax(T &a, const T &b) { a = a > b ? a : b; }

const int MAXN = 505;
int ans[MAXN][MAXN], tmp[MAXN][MAXN], h, H, w, W, rev;

int main() {
	scanf("%d%d%d%d", &H, &W, &h, &w);
	if (H % h == 0 && W % w == 0) return puts("No"), 0;
	puts("Yes");
	if (W % w == 0) swap(H, W), swap(h, w), rev = true;
	int t = W / w, x = t + 1;
	for (int i = h; i <= H; i += h)
	for (int j = 1; j <= W; j++)
		ans[i][j] = j % w == 0 ? (1 - w) * x - 1 : x;
	if (rev) {
		memcpy(tmp, ans, sizeof(tmp));
		for (int i = 1; i <= H; i++)
		for (int j = 1; j <= W; j++) ans[j][i] = tmp[i][j];
		swap(H, W), swap(h, w);
	}
	for (int i = 1; i <= H; i++, puts(""))
	for (int j = 1; j <= W; j++) printf("%d ", ans[i][j]);
	return 0;
}

Measured memory_bytes: 3328
#include <bits/stdc++.h>
using namespace std;
vector<long long> all(51), p(51);
void calc() {
	all[0] = 1;
	p[0] = 1;
	for(int i = 1; i < 51; i++) {
		all[i] = all[i - 1] * 2 + 3;
		p[i] = p[i - 1] * 2 + 1;
	}
}
long long dfs(long long level, long long dist) {
	if(dist == 0) {
		return 0;
	}
	else if(level == 0) {
		return 1;
	}
	else if(dist == 1) {
		return 0;
	}
	else if(dist == all[level - 1] + 2) {
		return p[level - 1] + 1;
	}
	else if(dist < all[level - 1] + 2) {
		return dfs(level - 1, dist - 1);
	}
	else {
		return p[level - 1] + 1 + dfs(level - 1, dist - all[level - 1] - 2);
	}
}
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);  
	long long n, x;
	cin >> n >> x;
	calc();
	cout << dfs(n, x) << endl;
	return 0;	
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

long long int solve(long long int n)
{
    long long int ans = 0;
    if (n % 2 != 0) {
        return 0;
    }
    
    for (long long int i = 10; i <= n; i *= 5) {
        ans += n / i;
    }

    return ans;
}

int main()
{
    long long int n, ans;
    cin >> n;
    ans = solve(n);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))
a.sort()
x, y = a[0], a[-1]
w, z = a[0], a[-1]
for i in a[1:-1]:
    if i < 0:
        y -= i
    else:
        x -= i
print(y - x)
for i in a[1:-1]:
    if i < 0:
        print(z, i)
        z -= i
    else:
        print(w, i)
        w -= i
print(z, w)

Measured memory_bytes: 20668
import sys
input = sys.stdin.readline

n,m,x = map(int,input().split())
ca = [list(map(int,input().split())) for _ in range(n)]

inf = 10**10
ans = inf
for i in range(2**n):
    und = [0] * m
    cost = 0
    for j in range(n):
        if((i>>j)&1):
            cost += ca[j][0]
            for k in range(m):
                und[k] += ca[j][k+1]
    if(min(und) >= x):
        ans = min(ans,cost)

if(ans==inf):
    print(-1)
else:
    print(ans)

Measured memory_bytes: 68764
#include <iostream>
#include <cstring>
using namespace std;
long long gcd(long long a, long long b) {
    return b == 0 ? a : gcd(b, a % b);
}
long long GCD[205][205], primesize, m = 1e9+7;
long long phi[100005], f[100005], pr[100005];
long long Pow(long long a, long long b){
	long long ans = 1;
	while(b > 0) {
		if(b & 1)
			ans = ans * a % m;
		a = a * a % m;
		b >>= 1;
	}
	return ans;
}
void getlist(long long N) {
    phi[1] = 1;
    long long k, p = 0;
	for(long long i = 2; i <= N; ++i){
		if(!f[i])
            phi[pr[++p] = i] = i - 1;
		for(long long j = 1; j <= p && (k = i * pr[j]) <= N; ++j){
			f[k] = 1;
			if(i % pr[j])
				phi[k] = phi[i] * (pr[j] - 1);
			else{
				phi[k] = phi[i] * pr[j];
				break;
			}
		}
	}
}
int main() {
    long long N, K;
    cin >> N >> K;
    long long sum = 0;
    getlist(K);
    for(long long i = 1; i <= K; i++)
        sum = (sum + (phi[i] * Pow(K / i, N)) % m) % m;
    cout << sum << endl;
  	return 0;
}


Measured memory_bytes: 5228
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>
#include <cstring>
#include <utility>
#include <set>
#include <stack>
#include <climits>
#include <cmath>

#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define rep1(i,n) for(int i=1, i##_len=(n); i<=i##_len; ++i)
#define reps(i,s,n) for(int i=s, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define MEMSET(v, h) memset((v), h, sizeof(v))
typedef long long ll;
const char sp = ' ';
#define MOD 1000000007

using namespace std;

const int MAX = 5100000;

long long fac[MAX], finv[MAX], inv[MAX];
using namespace std;

long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}



// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}


int main(void){
    ll N, K;
    cin>>N>>K;
    COMinit();
    rep1(i, K){
        ll blue;
        blue=(COM(K-1, i-1));
        blue%=MOD;
        ll red=0;
        if(i==1 && N==K) red++;
        if(N-K>=i-1) red+=COM(N-K-1, i-2);
        red%=MOD;
        if(N-K>=i) red+=COM(N-K-1, i-1)*2;
        red%=MOD;
        if(N-K>=i+1) red+=COM(N-K-1, i);
        red%=MOD;
        cout<<(blue*red)%MOD<<endl;
    }
    return 0;
}


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

int main() {
  int D, N, a;
  cin >> D >> N;
  if(D == 0) {
    if(N == 100) {
      cout << "101" << endl;
    }
    else {
      cout << N << endl;
    }
  }
  if(D == 1) {
    if(N == 100) {
      cout << "10100" << endl;
    }
    else {
      cout << N*100 << endl;
    }
  }
  if(D == 2) {
    if(N == 100) {
      cout << "1010000" << endl;
    }
    else {
      cout << N*10000 << endl;
    }
  }
}


Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>

struct Node{
  struct Node *right;
  struct Node *left;
  struct Node *parent;
  int key;
};

typedef struct Node * Node;
#define NIL NULL

Node root;

Node treeMinimum(Node x){
  while(x->left!=NIL)
    x = x->left;
  return x;
}

Node treeMaximum(Node x){
  while(x->right != NIL)
    x = x->right;
  return x;
}

Node treeSearch(Node u, int k){
  while(u!=NIL && k!=u->key){

    if(k < u->key) u=u->left;

    else u = u->right;
  }
  return u;

}

Node treeSuccessor(Node x){
  Node y;
  if(x->right != NIL) return treeMinimum(x->right);
  y = x->parent;
  while(y != NIL && x == y->right){
    x = y;
    y = y->parent;
  }
  return y;

}

void treeDelete(Node z){
  Node y; // node to be deleted
  Node x; // child of y
  if(z->left==NIL || z->right==NIL) y = z;
  else y = treeSuccessor(z);

  if(y->left != NIL) x=y->left;
  else x = y->right;

  if(x!=NIL) x->parent = y->parent;
  if(y->parent==NIL) root = x;
  else if(y == y->parent->left) y->parent->left = x;
  else y->parent->right =x;

  if(y!= z) z->key = y->key;
  free(y);
}

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

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

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

void inorder(Node u){
  if(u == NIL)return;
  inorder(u->left);
  printf(" %d",u->key);
  inorder(u->right);

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

}


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

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

  return 0;
}



Measured memory_bytes: 20592
import java.util.*;

class Main {
  public static void main(String args[]) {
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    int b = sc.nextInt();
    int c = sc.nextInt();
    int k = sc.nextInt();

    int max = Math.max(a, Math.max(b,c));
    int sum = a + b + c + max * (int)Math.pow(2, k) - max;

    System.out.println(sum);
  }
}

Measured memory_bytes: 21844
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<int,int> Pi;
#define rep(i,n) for(ll i=0;i<n;i++)
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define fi first
#define se second
#define endl "\n"

template<typename T> inline bool chmax(T &a, T b){if(a<b){a=b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if(a>b){a=b;return true;}return false;}
template<typename T> ostream& operator<<(ostream& s,const complex<T>& d) {return s<<"("<<d.real()<<", "<<d.imag()<< ")";}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const pair<T1,T2>& d) {return s<<"("<<d.first<<", "<<d.second<<")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& d){int len=d.size();rep(i,len){s<<d[i];if(i<len-1) s<<" ";}return s;}
template<typename T> ostream& operator<<(ostream& s,const vector<vector<T>>& d){int len=d.size();rep(i,len){s<<d[i]<<endl;}return s;}
template<typename T> ostream& operator<<(ostream& s,const set<T>& v){s<<"{ ";for(auto itr=v.begin();itr!=v.end();++itr) {if (itr!=v.begin()) {s<< ", ";}s<<(*itr);}s<<" }";return s;}
template<typename T> ostream& operator<<(ostream& s,const multiset<T>& v){s<<"{ ";for(auto itr=v.begin();itr!=v.end();++itr) {if (itr!=v.begin()) {s<< ", ";}s<<(*itr);}s<<" }";return s;}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const map<T1,T2>& m){s<<"{"<<endl;for(auto itr=m.begin();itr!=m.end();++itr){s<<" "<<(*itr).first<<" : "<<(*itr).second<<endl;}s<<"}"<<endl;return s;}

const ll mod=1'000'000'007;
const ll inf=1'000'000'000'000'000'00;
const int INF=1'000'000'000;
const double EPS=1e-10;
const double PI=acos(-1);

int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    int n;
    cin>>n;
    vector<int> X(n),Y(n);
    rep(i,n){
        int x,y;
        cin>>x>>y;
        X[i]=x+y;
        Y[i]=x-y;
    }
    sort(begin(X),end(X));
    sort(begin(Y),end(Y));
    cout<<max(abs(X[0]-X.back()),abs(Y[0]-Y.back()))<<endl;
}

Measured memory_bytes: 4772
#include <bits/stdc++.h>
using namespace std;
 
using ll = long long;
using db = double;
using pii = pair < int, int >;
using pll = pair < ll, ll >;
const int N = 2e5 + 10;
const ll inf = 1e15 + 42;
#define endl "\n"
const ll mod = 1000000007;
 
void testCase() {
    db r;
    cin >> r;
    db up = 22;
    db down = 7;
    up = 2*up*r;
    up = (up/down);
    cout << fixed << setprecision(15) << up << endl;
}
 
int main() {
    ios_base :: sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    testCase();
    return 0;
}

Measured memory_bytes: 3740
#include <stdio.h>
int main(){
  int n,k,i,j,sum=0;
  int a[1001],tmp;
  scanf("%d %d",&n,&k);
  for(i=0;i<n;i++){
    scanf("%d",&a[i]);
  }
  for (i=0; i<n; ++i) {
    for (j=i+1; j<n; ++j) {
      if (a[i] > a[j]) {
        tmp =  a[i];
        a[i] = a[j];
        a[j] = tmp;
      }
    }
  }
  for(i=0;i<k;i++){
    sum+=a[i];
  }
  printf("%d",sum);
  return 0;
}


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

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

	vector<vector<int>> m(n);
	for (int i = 0; i < n; ++i) {
		m[i].resize(n);
	}

	for (int i = 0; i < n; ++i) {
		int u, k;
		cin >> u >> k;
		for (int j = 0; j < k; ++j) {
			int v;
			cin >> v;
			m[u - 1][v - 1] = 1;
		}
	}

	for (int i = 0; i < n; ++i) {
		for (int j = 0; j < n; ++j) {
			cout << m[i][j];
			if (j != n - 1) cout << ' ';
		}
		cout << endl;
	}
}



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

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

    if(n >= 10)
        cout << r << endl;
    else
        cout << r +100 * (10 -n) << endl;
}

Measured memory_bytes: 256
S = gets.chomp
N = S.length

# 0 evens
ans1 = 0
N.times do |i|
  if (i % 2 == 0 and S[i] == "1") or (i % 2 == 1 and S[i] == "0")
    ans1 += 1
  end
end

# 0 odds
ans2 = 0
N.times do |i|
  if (i % 2 == 0 and S[i] == "0") or (i % 2 == 1 and S[i] == "1")
    ans2 += 1
  end
end

puts [ans1, ans2].min

Measured memory_bytes: 1916
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ProgramingStudying2
{
    class Program
    {

        static void Main(string[] args)
        {
            var s = Console.ReadLine();
            var head = new StringBuilder(200000);
            var tail = new StringBuilder(200000); 

            var q = int.Parse(Console.ReadLine());
            var reverse = -1;

            for(int  i =0; i < q; i++)
            {
                var query = Console.ReadLine().Split();
                if(int.Parse(query[0]) == 1)
                {
                    reverse *= -1;
                }
                if(int.Parse(query[0]) == 2)
                {
                    var f = int.Parse(query[1]);
                    if(f == 1)
                    {
                        if(reverse == -1)
                        {
                            head.Append(query[2]);
                        }
                        if(reverse == 1)
                        {
                            tail.Append(query[2]);
                        }
                    }
                    if(f == 2)
                    {
                        if (reverse == 1)
                        {
                            head.Append(query[2]);
                        }
                        if (reverse == -1)
                        {
                            tail.Append(query[2]);
                        }
                    }
                }
            }
            if (reverse == 1)
            {
                var tailAns = string.Concat(tail.ToString().Reverse());
                var ns = string.Concat(s.Reverse());
                Console.WriteLine(tailAns + ns + head);
            }
            if (reverse == -1)
            {
                var headAns = string.Concat(head.ToString().Reverse());
                Console.WriteLine(headAns + s + tail);
            }
        }
    }
}


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

int main(){
  string s,t,u;
  int a,b;
  
  cin >> s >> t;
  cin >> a >> b;
  cin >> u;
  if(s==u) a-=1;
  else if(t==u) b-=1;
  
  cout << a << ' ' << b <<endl;
}
  

Measured memory_bytes: 256
# Aizu Problem 00168: Kannondou
#
import sys, math, os, bisect

# read input:
PYDEV = os.environ.get('PYDEV')
if PYDEV=="True":
    sys.stdin = open("sample-input.txt", "rt")


p = [1, 1, 2] + [0] * 28
for i in range(3, 31):
    p[i] = sum(p[i-3:])


while True:
    N = int(input())
    if N == 0:
        break
    y = int(p[N] / (10 * 365) + 1)
    print(y)
    

Measured memory_bytes: 7668
nums = list(map(int, input().split()))
cards = {'r':nums[0], 'g':nums[1], 'b':nums[2]}
tN = int(input())

def func_check():
    judge = 0
    if cards['g'] > cards['r']:
        judge += 1
    if cards['b'] > cards['g']:
        judge += 2
    if judge == 0:
        c = 'g'
    elif judge == 1:
        c = 'b'
    elif judge == 2:
        c = 'g'
    elif judge == 3:
        c = 'comp'
    return c

for i in range(tN):
    judge = func_check()
    if judge == 'comp':
        break
    else:
        cards[judge] *= 2
judge = func_check()
if judge == 'comp':
    output = 'Yes'
else:
    output = 'No'
print(output)
        


Measured memory_bytes: 9140
#include <iostream>
#include <fstream>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <vector>
#include <stack>
#include <queue>
#include <complex>
#include <set>
#include <list>
#include <iomanip>
#include <map>
#include <limits.h>
#include <memory.h>


using namespace std;
static const double EPS = 1e-10;
typedef long long ll;
typedef unsigned long long ull;
#define FOR(i,n) for(int i=0;i<(int)n;++i)
#define FORNUM(p, x) for (int num = p; num < (int)(x); ++num)
#define FORI(p, x) for (int i = p; i < (int)(x); ++i)
#define FORJ(p, x) for (int j = p; j < (int)(x); ++j)
#define FORK(p, x) for (int k = p; k < (int)(x); ++k)
#define FORL(p, x) for (int l = p; l < (int)(x); ++l)

typedef vector<double> vec;
typedef vector<vec> mat;



int main() {

	string s;
	cin >> s;
	int n=s.length();
	int pos=n;
	while(pos>0){
		bool flg=false;
		if(pos>=5){
			if("dream"==s.substr(pos-5,5) || "erase"==s.substr(pos-5,5)){
				flg=true;
				pos-=5;
			}
		}
		if(pos>=6){
			if("eraser"==s.substr(pos-6,6)){
				pos-=6;
				flg=true;
			}
		}
		if(pos>=7){
			if("dreamer"==s.substr(pos-7,7)){
				flg=true;
				pos -=7;
			}
		}
		if(flg==false){
			break;
		}
	}
	cout << ((pos==0)?"YES":"NO") << endl;
	return 0;
}




Measured memory_bytes: 512
#!/usr/bin/env python3
import sys


def solve(s: str):
    ret = s[0::2]
    print(ret)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    s = next(tokens)  # type: str
    solve(s)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3316
#include<bits/stdc++.h>
using namespace std;
using ll=long long int;
int main()
{
    int n;
    cin>>n;
    string s;
    cin>>s;
    if(s.length()<=n)
    cout<<s<<endl;
    else
    {
        cout<<s.substr(0,n)+string(3,'.');
    }
    

    
}

Measured memory_bytes: 3640
#include <iostream>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
using namespace std;

void display(vector<int> const &v)
{
    rep(i, v.size())
    {
        if(i > 0) cout << " ";
        cout << v.at(i);
    }
    cout << endl;
}

int selectionSort(vector<int> &v, int const & N)
{
    int sw = 0;
    rep(i, N){
        int minj = i;
        rep2(j, i, N){
            if(v.at(j) < v.at(minj)) minj = j;
        }
        if(minj != i){
            swap(v.at(i), v.at(minj));
            ++sw;
        }
    }
    display(v);
    return sw;
}

int main()
{
    int N;
    cin >> N;
    vector<int> v(N);
    rep(i, N) cin >> v.at(i);
    int sw;

    sw = selectionSort(v, N);
    cout << sw << endl;

    return 0;
}


Measured memory_bytes: 3100
#include <stdio.h>
#include <stdlib.h>
#define MAX 100000

int Partition(char [], int [], int, int);
void Quicksort(char [], int [], int, int);


void Merge(char [], int [],int,int,int);
void Merge_Sort(char [], int [],int,int);


int q;

int main(void){

  int A[MAX + 1];
  char C[MAX + 1];
  char MC[MAX + 1];
  int MN[MAX + 1];

  int i, p, n;
  int count = 0;

  scanf("%d",&n);

  for(i=1;i<=n;i++)
    scanf(" %c %d",&C[i], &A[i]);

  for(i=1;i<=n;i++){
    MC[i] = C[i];
    MN[i] = A[i];
  }


  Merge_Sort(MC,MN,1,n);

  p = 1;
  Quicksort(C, A, p, n);

  for(i = 1; i <= n;i++){
    if(MN[i] == A[i] && MC[i] == C[i])
      count++;
  }

  if(count == n)
    printf("Stable\n");

  else
    printf("Not stable\n");


  for(i=1;i<=n;i++)
    printf("%c %d\n",C[i], A[i]);

  return 0;
}

int Partition(char C[], int A[], int p, int r){

  int i, j;
  char tmpC,x;
  int  tmpN, y;

  x = C[r];
  y = A[r];
  i = p - 1;

  for(j = p;j<r;j++){
    if(A[j] <= y){
      i = i + 1;
      tmpN = A[j];
      tmpC = C[j];
      A[j] = A[i];
      C[j] = C[i];
      A[i] = tmpN;
      C[i] = tmpC;
    }
  }
  
  tmpN = A[i+1];
  tmpC = C[i + 1];
  A[i+1] = A[r];
  C[i+1] = C[r];
  A[r] = tmpN;
  C[r] = tmpC;

  return i+1;
}

void Quicksort(char C[], int A[], int p, int r){


  if(p < r){
    q = Partition(C, A, p, r);
    Quicksort(C, A, p, q-1);
    Quicksort(C, A, q+1, r);
    }
}


//Merge_Sortから送られてきたデータを結合する。
void Merge(char MC[], int MN[],int left,int mid,int right){

    int n1 = mid - left + 1;
    int n2 = right - mid;
    int LN[n1 + 1];
    int RN[n2 + 1];
    int LC[n1 + 1];
    int RC[n2 + 1];
    
    int i,j,k;
    
    for(i = 1;i <= n1;i++){
      LN[i] = MN[left + i - 1];
      LC[i] = MC[left + i - 1];
    }
    
    for(i = 1;i <= n2;i++){
      RN[i] = MN[mid + i];
      RC[i] = MC[mid + i];
    }
    
    LN[n1+1] = 1000000000;
    RN[n2+1] = 1000000000;
    
    i = 1;
    j = 1;
    
    for(k = left;k <= right;k++){
      if(LN[i] <= RN[j]){
	MN[k] = LN[i];
	MC[k] = LC[i++];
      }
      else{
	MN[k] = RN[j];
	MC[k] = RC[j++];
      }
    }
}


//ここで分割できるだけ分割する
void Merge_Sort(char MC[], int MN[],int left,int right){
    int mid;

    // 2つになるまで分割して行く
    if(left < right){
        mid = (left + right)/2;
        Merge_Sort(MC,MN,left,mid);
        Merge_Sort(MC,MN,mid+1,right);
        Merge(MC,MN,left,mid,right);
    }
}

Measured memory_bytes: 2364
word = input()

if word[0] != 'A':
    print("WA")
    exit()

result="AC"
ccount = 0
for i, c in enumerate(word[1:], 1):
    if c.islower():
        continue
    if c == 'C' and i > 1 and i < len(word) - 1:
        ccount += 1
        continue
    result = "WA"
    break
if ccount != 1:
    result = "WA"
print(result)


Measured memory_bytes: 3060
import math
def rotation(x1,y1,x2,y2) :
	rot_rad = math.radians(270)
	
	x3 = (x2-x1) * math.cos(rot_rad) - (y2-y1) * math.sin(rot_rad) + x1
	y3 = (x2-x1) * math.sin(rot_rad) + (y2-y1) * math.cos(rot_rad) + y1
	
	return {"x":x3, "y":y3}

x1,y1,x2,y2 = [int(i) for i in input().split()]
rotated = rotation(x2,y2,x1,y1)
x3 = rotated["x"]
y3 = rotated["y"]
rotated = rotation(x3,y3,x2,y2)
x4 = rotated["x"]
y4 = rotated["y"]

print(str(round(x3)) + " " + str(round(y3)) + " " + str(round(x4)) + " " + str(round(y4)))

Measured memory_bytes: 3064
#include<cstdio>
#include<cstring>
#include<vector>
#include<stack>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<map>
#define maxn 200100
 
using namespace std;
long long a[maxn],b[maxn];
int main()
{
	int n;
	scanf("%d",&n);
	for(int i=0;i<=n;i++)
		scanf("%lld",&a[i]);
	for(int i=0;i<n;i++)
		scanf("%lld",&b[i]);
	long long ans=0;
	ans+=min(a[0],b[0]);
	b[0]=(b[0]>=a[0]?b[0]-a[0]:0);
	for(int i=1;i<=n;i++)
	{
		if(b[i-1])
		{
			ans+=min(b[i-1],a[i]);
			a[i]=(b[i-1]<=a[i]?a[i]-b[i-1]:0);
		}
		if(a[i]&&i!=n)
		{
			ans+=min(a[i],b[i]);
			b[i]=(b[i]>=a[i]?b[i]-a[i]:0);
		}
	}
	printf("%lld\n",ans);
}

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

int main() {
    int n, m;
    cin >> n >> m;
    bitset<30> bs(0);
    for (int i = 0; i < n; ++i) {
        int k;
        cin >> k;
        bitset<30> like(0);
        for (int j = 0; j < k; ++j) {
            int a;
            cin >> a;
            --a;
            if (i == 0) {
                bs.set(a);
            } else {
                like.set(a);
            }
        }
        if (i != 0) {
            bs &= like;
        }
    }
    int ans = 0;
    for (int i = 0; i < 30; ++i) {
        ans += bs.test(i);
    }
    cout << ans << endl;
}


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

int main() {
	int N, M;
	int A[10000] = { 0 };
	long long int sum=0;
	cin >> N >> M;
	for (int i = 0; i < M; i++) {
		cin >> A[i];
		sum += A[i];
	}

	if (sum > N) {
		cout << -1;
	}
	else {
		cout << N - sum;
	}

}

Measured memory_bytes: 3672
n,h = map(int, input().split())
ab = []
for _ in range(n):
    data = list(map(int,input().split()))
    ab.append(data)

ab.sort()
ab.reverse()

max_a = ab[0][0]
max_a_b=ab[0][1]
rest_ab = ab[1:]

throw_dmgs = []
for tmp in rest_ab:
    if tmp[1] > max_a:
        throw_dmgs.append(tmp[1])

if max_a < max_a_b:
    throw_dmgs.append(max_a_b)
throw_dmgs.sort()
throw_dmgs.reverse()

ans=0
for i in range(len(throw_dmgs)):
    ans+=1
    h -= throw_dmgs[i]
    if h <= 0:
        print(ans)
        exit()
import math

swing = math.ceil(h / max_a)
print(ans+swing)

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

using namespace std;

#define pb push_back
#define mk make_pair
#define mod 1000000007
#define ff first
#define ss second

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

ll modpow(ll a, ll b){

    ll ans=1;
    while(b){
        if(b&1){
            ans=(ans*a)%mod;
        }
        a=(a*a)%mod;
        b=b/2;
    }
    return ans;
}

int main(){

    cin.tie(0);
    ios::sync_with_stdio(false);

    int n;
    cin>>n;

    string s1, s2;
    cin>>s1>>s2;

    string ans = "";

    for(int i = 0; i < n; i++) {
        ans += s1[i];
        ans += s2[i];
    }

    cout<<ans<<endl;


}


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

int gcd(int a,int b){
    int t;
    while(b>0){
        t=b;
        b=a%b;
        a=t;
    }
    return a;
}

int lcm(int a,int b){
    return a*b/gcd(a,b);
}

int main(){
    ll b,c,d,e,k,l,m,n,o=0,p,q,r,x,y,z,max1=0;
    string s,t,u;
    
    double ans=0;
    priority_queue<ll> pque;
    cin>>n;
    double a[n];
    for(ll i=0;i<n;i++){
        cin>>a[i];
    }  
    sort(a,a+n);
    for(ll i=0;i<n-1;i++){
        a[i+1]=(a[i]+a[i+1])/2;
    }  
    
    
    cout<<a[n-1]<<setprecision(10)<<endl;
}



Measured memory_bytes: 256
N,Q = map(int,input().split())
s = input()
info = [input().split() for _ in range(Q)]

def biserch(ok,ng,judge):
    while abs(ok-ng) > 1:
        mid = (ok+ng) // 2
        if judge(mid):
            ok = mid
        else:
            ng = mid
    return ok

def left_out(i):
    now = i
    for t, d in info:
        if s[now] == t:
            if d == "L":
                now -= 1
            elif d == "R":
                now += 1
        if now < 0:
            return True
        elif now > N-1:
            return False
    return False

def right_out(i):
    now = i
    for t, d in info:
        if s[now] == t:
            if d == "L":
                now -= 1
            elif d == "R":
                now += 1
        if now > N-1:
            return True
        elif now < 0:
            return False
    return False

left = biserch(ok=-1,ng=N,judge=left_out)
right = biserch(ok=N,ng=-1,judge=right_out)
ans = right - (left + 1)
print(ans)

Measured memory_bytes: 39356
#include <bits/stdc++.h>
#define ll long long
#define MODV 1000000007
#define INF INT_MAX // 2147483647
#define INFLL LLONG_MAX // 9223372036854775807
#define rep(i, n) for(ll i=0, i##_len=(ll)(n); i<i##_len; i++)
#define repf(i, n) for(ll i=1, i##_len=(ll)(n+1); i<i##_len; i++)
#define per(i, n) for(ll i=((ll)(n))-1; i>=0; i--)
#define perf(i, n) for(ll i=((ll)(n)); i>0; i--)
#define all(v) v.begin(), v.end()
#define endl "\n"
#define vi vector<ll>
#define vvi vector<vector<ll>>
#define Yes() cout << "Yes" << endl
#define YES() cout << "YES" << endl
#define No() cout << "No" << endl
#define NO() cout << "NO" << endl
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; }
using namespace std;

// 約数列挙：nの約数を昇順に返す
vector<long long> enumDivisors(long long n){
    vector<long long> ret;
    for(long long i=1; i*i<=n; i++){
        if(n%i == 0){
            ret.push_back(i);
            if(n/i != i) ret.push_back(n/i);
        }
    }
    sort(ret.begin(), ret.end());
    return ret;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(10);
    ll a, b, k; cin >> a >> b >> k;
    auto p = enumDivisors(__gcd(a, b));
    cout << p[p.size()-k] << endl;
}

Measured memory_bytes: 3664
#pragma GCC optimize("O3")
#include <iostream>
#include <cmath>

unsigned long long int ans = 0;

unsigned long long int stair(unsigned long long int& a) {
  unsigned long long int i = 0;
  while (a > i) {
    a -= (i + 1);
    i++;
  }
  return i;
}

int main(int argc, char const* argv[]) {
  unsigned long long int N;
  std::cin >> N;
  unsigned long long int two_pow = 0;
  int tmp2 = 1;
  while (N % 2 == 0) {  // 偶数の素数は2のみ
    two_pow += 1;
    if (two_pow >= tmp2) {
      two_pow -= tmp2;
      tmp2 += 1;
      ans += 1;
    }

    N /= 2;
  }
  unsigned long long int three_pow = 0;
  int tmp3 = 1;
  while (N % 3 == 0) {  // 偶数の素数は2のみ
    three_pow++;
    if (three_pow >= tmp3) {
      three_pow -= tmp3;
      tmp3 += 1;
      ans += 1;
    }
    N /= 3;
  }
unsigned long long i_max = sqrt(N) + 1e6;
  for (unsigned long long int i = 5; i<=i_max && i <= N; i += 2) {
    if ((i % 3) == 0) continue;
    if ((N % i) == 0) {
      unsigned long long int n_pow = 0;  // 指数カウンタクリア
      int tmp = 1;
      do {
        n_pow++;  // 指数カウンタプラス
        if (n_pow >= tmp) {
          n_pow -= tmp;
          tmp += 1;
          ans += 1;
        }
        N /= i;

      } while ((N % i) == 0);
      // ans += stair(n_pow);
    }
  }
  if(N != 1) ans++;
  std::cout << ans << std::endl;
}

Measured memory_bytes: 3676
#include<bits/stdc++.h>
using namespace std;
int main()
{
   long long n,s,k,m,p,q,r,sum=0;
   cin>>n;
   if(n>=500){
    s=(n/500);
   k=s*1000;
   m=s*500;
   p=(n-m);
   q=p/5;
   r=q*5;
   sum=k+r;
   cout<<sum;
   return 0;
   }
    if(n<500)
   {
       s=n/5;
       m=s*5;
   }
   cout<<m;
}


Measured memory_bytes: 256
S = input()
T = input()

ans = 10000

for i in range(len(S)-len(T)+1):
    Tcheck = S[i:len(T)+i]
#    print(Tcheck)

    tmp = 0
    for j in range(len(Tcheck)):
        if(T[j] != Tcheck[j]):
            tmp += 1
    
    ans = min(ans, tmp)

print(ans)

Measured memory_bytes: 9112
#include <iostream>
#include <string>
#include <algorithm>
#include <math.h>
#include <vector>
#include <iomanip>
#include <map>
#include <queue>

using namespace std;

#define fori(x) for (int i = 0; i < x; ++i)
#define forj(x) for (int j = 0; j < x; ++j)

typedef long long ll;

const int INF = 2e9 + 5;
const int alength=100100;

int main() {
	string s;
	cin>>s;
	int ans=0;
	for(int i=0;i<s.length();++i){
		for(int j=0;j<s.length();++j){
			string t=s.substr(i,s.length()-j);
			bool f=true;
			for(int k=0;k<t.length();++k){
				if(t[k]!='A'&&t[k]!='C'&&t[k]!='G'&&t[k]!='T'){
					f=false;
					break;
				}
			}
			if(!f){
				continue;
			}
			ans=max(ans,(int)(t.size()));
		}
	}
	cout<<ans;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rrep(i,n) for(int i=(int)(n-1);i>=0;i--)
#define FOR(i,n,m) for(int i=n;i<=(int)(m);i++)
#define RFOR(i,n,m) for(int i=(int)(n);i>=m;i--)
#define all(x) (x).begin(),(x).end()
#define sz(x) int(x.size())
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;
using namespace std;
vector<int> dy={-1,0,1,0};
vector<int> dx={0,1,0,-1};
template<class T>
vector<T> make_vec(size_t a){
    return vector<T>(a);
}
template<class T, class... Ts>
auto make_vec(size_t a, Ts... ts){
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

int main() {
    int n,m;
    cin>>n>>m;
    vector<vector<int>> d(n,vector<int>(n,INF));
    vector<tuple<int,int,int>> edge;
    rep(i,n) d[i][i]=0;
    rep(i,m) {
        int a,b,c;
        cin>>a>>b>>c;
        a--;b--;
        edge.emplace_back(a,b,c);
        d[a][b]=c;
        d[b][a]=c;
    }
    
    rep(k,n) {
        rep(i,n) {
            rep(j,n) {
                d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
            }
        }
    }
    
    int ans=0;
    for(auto p:edge) {
        int a,b,c;
        tie(a,b,c) = p;
        int flag=false;
        rep(i,n) rep(j,n) {
            if(d[i][j]==d[i][a]+c+d[b][j]) flag=true;
        }
        if(!flag) ans++;
    }
    cout<<ans<<endl;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define f first
#define s second
#define MOD 1000000007
#define PMOD 998244353
#define pb(x) push_back(x)
using namespace std;

typedef long long int ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> plii;
typedef pair<int, pii> piii;
const int INF = 1e9+10;
const ll LINF = 1LL*INF*INF;
const int MAXN = 2e5+10;
const int MAXM = 5e3+10;

priority_queue<int> pq;
vector<vector<int> > graph;
queue<int> que;

int A[MAXN];
char S[MAXN];

int main()
{
    int n,m,k,a,b,x,y,q;
    int sum = 0;
    int cnt = 0;
    int mx = 0;
    int mn = INF;
    int cur = 0, idx = -1;
    int tc;

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    cin>>n>>m;

    for(int i=1;i<(1<<n);i++){
        for(int j=1;j<(1<<m);j++){
            if((i&-i)==(j&-j))S[j] = '1';
            else S[j] = '0';
        }
        cout<<S+1<<"\n";
    }

    return 0;
}


Measured memory_bytes: 1280
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int x,a,b;
    int ans;
    cin >> x >> a >> b;
    ans = x-a;
    while(ans >= 0){
        ans = ans - b;
    }
    cout << ans + b << endl;
    return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0; i<(n); ++i)
using namespace std;
typedef long long ll;
const int INF = 1001001001;

vector<pair<long long, long long> > prime_factorize(long long N) {
    vector<pair<long long, long long> > res;
    for (long long a = 2; a * a <= N; ++a) {
        if (N % a != 0) continue;
        long long ex = 0;

        while (N % a == 0) {
            ++ex;
            N /= a;
        }

        res.push_back({a, ex});
    }

    if (N != 1) res.push_back({N, 1});
    return res;
}

int main() {
    ll N, z=2, ans=0;

    cin >> N;

    const auto &res = prime_factorize(N);

    for(auto p : res) {
        for(int i=1; i<=p.second; i++) {
            ans++;
            p.second -= i;
        }
    }

    cout << ans << endl;

    return 0;
    
}

Measured memory_bytes: 3652
#include<iostream>
#include<vector>

using namespace std;

int main(void) {
	int n, m, cmd;
	vector<int> cards, tmp;
	int i, j;

	cin >> n;
	for(i = 0; i < 2 * n; i++) { cards.push_back(i+1); }
	cin >> m;
	for(i = 0; i < m; i++) {
		cin >> cmd;
		tmp.clear();
		if(cmd == 0) {
			for(j = 0; j < (int)cards.size(); j++) { tmp.push_back(cards[j%2*n+j/2]); }
		} else {
			for(j = cmd; j < (int)cards.size(); j++) { tmp.push_back(cards[j]); }
			for(j = 0; j < cmd; j++) { tmp.push_back(cards[j]); }
		}
		cards = tmp;
	}
	for(i = 0; i < 2 * n; i++) { cout << cards[i] << endl; }

	return 0;
}

Measured memory_bytes: 0
#include<stdio.h>
#include<string.h>

int main(){
	char ss[110];
	int i,j,a,b;
	
	while(~scanf(" %s ",ss)){
		if(ss[0]=='0')break;
		i=1;
		a=0;
		b=0;
		while(1){
			if(ss[i]=='\0')break;
			if(ss[i]=='A')++a;
			if(ss[i]=='B')++b;
			++i;
		}
		if(a>b){
			++a;
		}else{
			++b;
		}
		printf("%d %d\n",a,b);
	}
	return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <algorithm>
using namespace std;
#define int long long

signed main() {
  int rate[9];
  for (int i = 0; i < 9; i++) {
    rate[i] = 400 * i;
  }
  int count[9];
  fill(count, count + 9, 0);
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    int a;
    cin >> a;
    for (int i = 0; i + 1 < 9; i++) {
      if (rate[i] <= a && a < rate[i + 1]) count[i]++;
    }
    if (a >= rate[8]) count[8]++;
  }
  int ans = 0;
  for (int i = 0; i < 8; i++) {
    if (count[i]) ans++;
  }
  cout << max(1LL, ans) << " " << ans + count[8] << endl;
  return 0;
}


Measured memory_bytes: 256
N = int(input().strip())
M = int(input().strip())
Inf = 1001001001
K = [[Inf for j in range(N)] for i in range(N)]
for _ in range(M):
    a,b,c,d = map(int,input().strip().split(","))
    K[a-1][b-1] = c
    K[b-1][a-1] = d
S,G,V,P = map(int,input().strip().split(","))
for k in range(N):
    for i in range(N):
        for j in range(N):
            if K[i][j] > K[i][k] + K[k][j]:
                K[i][j] = K[i][k] + K[k][j]
R = V - P - K[S-1][G-1] - K[G-1][S-1]
print(R)


Measured memory_bytes: 5612
#include <stdio.h>
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <regex>
#include <stack>
#include <queue>
#include <vector>
#include <iomanip>
#include <map>
#define MAX_N 100
#define INF 10000000

using namespace std;

string ALP = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";

int n,m,a,b;
int N[100];
string s,t;

void solve() {
    if(n==7 || n==5 || n==3){
        cout<<"YES"<<endl;
    }
    else cout<<"NO"<<endl;
}

int main() {
	cin>>n;
	solve();
	return 0;
}

Measured memory_bytes: 256
import java.util.*;
class Main {
    public static void main(String[] args) {
	Scanner sc = new Scanner(System.in);
	String s = sc.next();
	int b = 0;
	int r = 0;
	for(int i = 0; i<s.length();i++) {
	    char c = s.charAt(i);
	    if(c=='0') b++;
	    else r++;
	}
	System.out.println((int)Math.min(b,r)*2);
    }
}

Measured memory_bytes: 25684
import numpy as np
N, K = map(int, input().split())
A = np.array(input().split(), dtype=float)

E = (A + 1) * 0.5
cumE = np.zeros(N + 1, dtype=float)
cumE[1:] = E.cumsum(axis=0)

ans = (cumE[K:] - cumE[:-K]).max()
print(ans)


Measured memory_bytes: 32036
#include<iostream>
#include<set>
using namespace std;
int main()
{
    int n,a;
    set<int>f;
    cin>>n;
    for(int i=0;i<n; i++) 
	{
        cin>>a;
        f.insert(a);
    }
    
    cout<<f.size()<<endl;
    return 0;
}

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

int main(){
	cin.tie(0),ios::sync_with_stdio(false);
	int n; cin>>n;
	unordered_map<int,int>m;
	for(int i=0;i<n;++i){
		int a; cin>>a;
		++m[a];
	}
	int sum=0;
	for(auto&i:m)if(i.second!=1)sum+=i.second-1;
	cout<<n-sum-(sum%2)<<"\n"s;
}

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

int main() {
  int n, y;
  cin >> n >> y;
  for (int i = 0; i <= n; i++){
    for (int k = 0; i + k <= n; k++){
      if(1000 * i + 5000 * k + (n - i - k) * 10000 > y) continue;
      if (1000 * i + 5000 * k + (n - i - k) * 10000 == y){
        cout << n - i - k << " " << k << " " << i << endl;
        return 0;
      }
    }
  }
  cout << -1 << " " << -1 << " " << -1 << endl;
}

Measured memory_bytes: 256
//
// Created by Wangzhe on 2019/10/19.
//

//
// Created by Wangzhe on 2019/10/19.
//

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const ll maxn = 1e5 + 10, INF = 1e18;

ll a[1111];

int main() {
    ll sum = 0;
    int n; cin >>n;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        for (int j = 0; j < i; j++) {
            sum += a[i] * a[j];
        }
    }
    cout << sum << endl;

    return 0;
}

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

int main()
{
	#ifndef ONLINE_JUDGE
		freopen("input.txt","r",stdin);
		freopen("output.txt","w",stdout);
	#endif
	
	int x;
	cin >> x;
	if (x>=400 && x<=599){
		cout<<8<<endl;
	}else if(x>=600 && x<=799){
		cout<<7<<endl;
	}else if(x>=800 && x<=999){
		cout<<6<<endl;
	}else if(x>=1000 && x<=1199){
		cout<<5<<endl;
	}else if(x>=1200 && x<=1399){
		cout<<4<<endl;
	}else if(x>=1400 && x<=1599){
		cout<<3<<endl;
	}else if(x>=1600 && x<=1799){
		cout<<2<<endl;
	}else if(x>=1800 && x<=1999){
		cout<<1<<endl;
	}
	
	return 0;
}

Measured memory_bytes: 3628
import sys
A, B, C, K = map(int, input().split())

ans = 0
if K-A > 0:
    K -= A
    ans += A
else:
    print(K)
    sys.exit()
    
if K - B > 0:
    K -= B
else:
    print(ans)
    sys.exit()


ans -= K

print(ans)

Measured memory_bytes: 9180
import java.util.Scanner;
public class Main {
		public static void main(String[] args) {
				Scanner sc = new Scanner(System.in);
				int n = sc.nextInt();
				long p=1;
				for(int i=1;i<=n;i++){
					p=p*i;
					if(p>1000000007){
						p=p%1000000007;
					}
				}
				System.out.println(p);
		}
}

Measured memory_bytes: 21844
#include<bits/stdc++.h>
using namespace std;
struct Ev{
    int pos,df;
}arr[400400];
bool cmp(const Ev a,const Ev b){
    return a.pos<b.pos;
}
int main(){
    int n;
    scanf("%d",&n);
    int u=0;
    for(int i=0;i<n;i++){
        int l,r;
        scanf("%d%d",&l,&r);++r;
        arr[u++]=(Ev){l,1};
        arr[u++]=(Ev){r,-1};
    }
    sort(arr,arr+u,cmp);
    int ans=0,flag=0,pos=0;
    for(int i=0;i<u;i++){
        ans+=flag?(arr[i].pos-pos):0;
        flag+=arr[i].df;
        pos=arr[i].pos;
    }
    printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

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

        int n = sc.nextInt();

        int[] vals = new int[n];
        int[] costs = new int[n];

        for (int i = 0; i < n; i++) {
            vals[i] = sc.nextInt();
        }

        for (int i = 0; i < n; i++) {
            costs[i] = sc.nextInt();
        }

        int tot = 0;

        for (int i = 0; i < n; i++) {
            tot += Math.max(0, vals[i] - costs[i]);
        }

        System.out.println(tot);
    }
}


Measured memory_bytes: 22100
n, k = map(int, input().split())
a = list(map(int, input().split()))

for _ in range(k):
    lst = [0] * n
    for i in range(n):
        num = a[i]
        if i-num >= 0:
            lst[i-num] += 1
        else:
            lst[0] += 1
        if i+num+1 <= n-1:
            lst[i+num+1] -= 1
    mini = lst[0]
    for i in range(1, n):
        lst[i] += lst[i-1]
        mini = min(mini, lst[i])
    a = lst[:]
    if mini == n:
        break
print(' '.join(map(str, a)))

Measured memory_bytes: 172284
#!/usr/bin/env python

class Dice:
    def __init__(self, top, s, e, w, n, bottom):
        self.top    = top
        self.s      = s
        self.e      = e
        self.w      = w
        self.n      = n
        self.bottom = bottom

    def rotate(self, dist):
        if dist == 'N':
            self.top, self.s, self.n, self.bottom = self.s, self.bottom, self.top, self.n 
        elif dist == 'S':
            self.s, self.bottom, self.top, self.n = self.top, self.s, self.n, self.bottom 
        elif dist == 'E':
            self.top, self.e, self.w, self.bottom = self.w, self.top, self.bottom, self.e 
        elif dist == 'W':
            self.w, self.top, self.bottom, self.e = self.top, self.e, self.w, self.bottom 

if __name__ == '__main__':
    num = map(int, raw_input().split())
    dice = Dice(*num)

    for c in raw_input():
        dice.rotate(c)
    print dice.top




Measured memory_bytes: 4688
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int count;
		List<Integer> num = new ArrayList<Integer>();
		count = sc.nextInt();
		for(int i=0; i<count; i++) {
            num.add(sc.nextInt());
		}

		for(int i=count-1; i>=0; i--) {
			System.out.print(num.get(i));
			if(i!=0){
			    System.out.print(' ');
			}
		}
			System.out.println();
	}
}





Measured memory_bytes: 26220
#include<stdio.h>
typedef long long LL;
#define REP(j,k,n) for(LL j=k;j<(LL)n;j++)
#define rep(i,N) REP(i,0,N)
const int MOD=998244353;
inline LL Pow(LL x,LL y){LL z=1;x%=MOD;while(y){if(y&1){z=(z*x)%MOD;}x=(x*x)%MOD;y>>=1;}return z%MOD;}
int main(void)
{
  int A,B,C,D,ans=0,dp[3000]={0};LL sum;
  if(!scanf("%d %d %d %d",&A,&B,&C,&D))return 0;
  dp[A-1]=1;
  rep(i,D-B)
  {
    sum=0;
    rep(j,C)
    {
      sum=(sum*(B+i)%MOD+dp[j])%MOD;
      dp[j]=(j*dp[j]+sum)%MOD;
    }
  }
  rep(i,C)ans=(ans+dp[i]*Pow(D,C-i-1)%MOD)%MOD;
  return printf("%d\n",ans),0;
}

Measured memory_bytes: 1744
#include<bits/stdc++.h>
using namespace std;
long long int n,m,ans;
int main()
{
	scanf("%lld%lld",&n,&m);
	if (n==1 && m==1) 
	{
		printf("1");
		return 0;
	}
	if (n==1)
	{
	    printf("%d",m-2);
		return 0;	
	}
	if (m==1)
	{
		printf("%d",n-2);
		return 0;
	}
	ans+=(n-2)*(m-2);
	printf("%lld",ans);
	return 0;
}

Measured memory_bytes: 256