akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#define F 999999999

struct Tree
{
  int key; //key
  int p; //parent
  int l; //left
  int r; //right 
};

struct Tree A[250];

int main()
{
  int N;
  int i;
  
  scanf("%d",&N);
  N++;

  for(i=1;i<N;i++)
    {
      A[i].key = A[i].p = A[i].l = A[i].r = F;
    }
  scanf("%d",&A[1].key);
  for(i=2;i<N;i++)
    {
      scanf("%d",&A[i].key);
      if(i%2==1)
	{
	  A[i].p=A[i/2].key;
	  A[i/2].r=A[i].key;
	}
      else if(i%2==0)
	{
	  A[i].p=A[i/2].key;
	  A[i/2].l=A[i].key;
	}
	
    }

  for(i=1;i<N;i++)
    {
      if(i==1)
	printf("node 1: key = %d, left key = %d, right key = %d, \n",A[i].key,A[i].l,A[i].r);
      else if(A[i].l!=F && A[i].r!=F)
	printf("node %d: key = %d, parent key = %d, left key = %d, right key = %d, \n",i,A[i].key,A[i].p,A[i].l,A[i].r);
      else if(A[i].l==F) 
	printf("node %d: key = %d, parent key = %d, \n",i,A[i].key,A[i].p);
      else if(A[i].r==F)
	printf("node %d: key = %d, parent key = %d, left key = %d, \n",i,A[i].key,A[i].p,A[i].l);
    }



  return 0;
  
}



Measured memory_bytes: 2052
#include <cassert>
#include <algorithm>
#include <array>
#include <bitset>
#include <cctype>
#include <cstdint>
#include <cmath>
#include <complex>
#include <chrono>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>
#include <random>
#include <memory>
#include <utility>
#include <limits>
 
#define rep(i, a, b) for (long long i = (a); (i) < (b); (i)++)
#define all(i) i.begin(), i.end()
#define debug(...) std::cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)

void debug_out(){std::cerr<<std::endl;}

template<typename Head,typename... Tail>
void debug_out(Head h,Tail... t){
  std::cerr<<" "<<h;
  debug_out(t...);
}
 
template <typename T1, typename T2>
std::ostream& operator<<(std::ostream& os, std::pair<T1, T2> pa) {
  return os << pa.first << " " << pa.second;
}
 
template <typename T>
std::ostream& operator<<(std::ostream& os, std::vector<T> vec) {
  for (int i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
  return os;
}
 
template<typename T1,typename T2>
inline bool chmax(T1& a,T2 b){return a<b && (a=b,true);}
 
template<typename T1,typename T2>
inline bool chmin(T1& a,T2 b){return a>b && (a=b,true);}
 
long long pow_mod(long long a, long long b, long long mod=-1) {
  if(b==0)return 1;
  if ((a == 0)||(mod!=-1&&(a+mod)%mod==0))return 0;
  long long x = 1;
  while (b > 0) {
    if (b & 1)x = (mod!=-1)?(x * a) % mod:x*a;
    a = (mod!=-1)?(a * a) % mod:a*a;
    b >>= 1;
  }
  return x;
}

//const long long MOD = 998244353;
const long long MOD = 1e9 + 7;

using ll = long long;
using P=std::pair<long long,long long>;

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

  ll n,m;
  std::cin>>n>>m;

  std::cout<<n*(n-1)/2+m*(m-1)/2<<"\n";

  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
int main() {
	std::vector<int> a;
	std::vector<int> b;
	while (true) {
		int i, o;
		std::cin >> i >> o;
		if (i == 0 && o == 0) {
			break;
		}
		a.push_back(std::min(i, o));
		b.push_back(std::max(i, o));
	}
	for (int x = 0; x < a.size(); ++x) {
		std::cout << a[x] << " " << b[x] << std::endl;
	}
}

Measured memory_bytes: 1240
#####segfunc#####
def segfunc(x, y):
    return min(x,y)
#################

#####ide_ele#####
ide_ele = float("inf")
#################

class SegTree:
    """
    init(init_val, ide_ele): 配列init_valで初期化 O(N)
    update(k, x): k番目の値をxに更新 O(logN)
    query(l, r): 区間[l, r)をsegfuncしたものを返す O(logN)
    """
    def __init__(self, n, segfunc, ide_ele):
        """
        init_val: 配列の初期値
        segfunc: 区間にしたい操作
        ide_ele: 単位元
        n: 要素数
        num: n以上の最小の2のべき乗
        tree: セグメント木(1-index)
        """
        self.segfunc = segfunc
        self.ide_ele = ide_ele
        self.num = 1 << (n - 1).bit_length()
        self.tree = [ide_ele] * 2 * self.num
        # 配列の値を葉にセット
        # 構築していく

    def update(self, k, x):
        """
        k番目の値をxに更新
        k: index(0-index)
        x: update value
        """
        k += self.num
        self.tree[k] = x
        while k > 1:
            self.tree[k >> 1] = self.segfunc(self.tree[k], self.tree[k ^ 1])
            k >>= 1

    def query(self, l, r):
        """
        [l, r)のsegfuncしたものを得る
        l: index(0-index)
        r: index(0-index)
        """
        res = self.ide_ele

        l += self.num
        r += self.num
        while l < r:
            if l & 1:
                res = self.segfunc(res, self.tree[l])
                l += 1
            if r & 1:
                res = self.segfunc(res, self.tree[r - 1])
            l >>= 1
            r >>= 1
        return res

import bisect,random

N,E,T=map(int,input().split())
x=list(map(int,input().split()))
x=[0]+x
X=[2*x[i] for i in range(N+1)]



dp=[0 for i in range(N+1)]
dp[N]=abs(E-x[N])

seg1=SegTree(N+1,segfunc,ide_ele)
seg3=SegTree(N+1,segfunc,ide_ele)
seg1.update(N,E-x[N]+x[N])
seg3.update(N,E-x[N]+3*x[N])

for i in range(N-1,-1,-1):
    id=bisect.bisect_right(X,T+2*x[i+1])
    test,test2=10**20,10**20
    if id>i+1:
        #test1=min(dp[j]+x[j] for j in range(i+1,id))+T
        test1=seg1.query(i+1,id)+T
    if N+1>id:
        #test2=min(3*x[j]+dp[j] for j in range(id,N+1))-2*x[i+1]
        test2=seg3.query(id,N+1)-2*x[i+1]
    dp[i]=min(test1,test2)-x[i]
    seg1.update(i,dp[i]+x[i])
    seg3.update(i,dp[i]+3*x[i])
    #dp[i]=min(max(T,2*x[j]-2*x[i+1])+dp[j]+x[j] for j in range(i+1,N+1))-x[i]

print(dp[0])


Measured memory_bytes: 124272
#include<iostream>
#include<algorithm>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
int n,a,b;
int q[10000],l[100],head,tail,last,best,ans;
int cantop[100],can[100][100];
bool vis[100];
void DFS(int x,int len){
	if(len>best){last=x;best=len;}
	vis[x]=true;
	for(int i=0;i<cantop[x];i++){
		if(!vis[can[x][i]]){
			DFS(can[x][i],len+1);
			vis[can[x][i]]=false;
		}
	}
}
int main(){
	int n;
	while(true){
	cin>>n;
	if(!n)break;
	rep(i,100)cantop[i]=false;
	rep(i,n){
		cin>>a>>b;
		a--,b--;
		can[a][cantop[a]]=b,can[b][cantop[b]]=a;
		cantop[a]++,cantop[b]++;
	}
	rep(i,100)vis[i]=false;
	ans=0;
	for(int i=0;i<100;i++){
		best=0;
		DFS(i,1);
		rep(i,100)vis[i]=false;
		best=0;
		DFS(last,1);
		ans=max(ans,best);
	}
	cout<<ans<<endl;
	}
	return 0;
}

Measured memory_bytes: 3124
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define FOR(i,a,b) for(int i=(a); i<=(b); i++)
#define rep(i,n) for(int i = 0; i < (n); i++)
#define chmin(a,b) if((a)>(b)) (a)=(b);
#define chmax(a,b) if((a)<(b)) (a)=(b);
#define vi vector<int>
#define pii pair<int,int>
#define all(v) (v).begin(),(v).end()
#define allr(v) (v).rbegin(),(v).rend()
#define pb push_back
#define pf push_front
int gcd(int a,int b){/*a>=0,b>=0,￢(a=b=0)*/
  while(min(a,b)>0){if(a<b)swap(a,b);a%=b;}return max(a,b);
}
int dx[]={1,0,-1,0,1,-1,-1,1};
int dy[]={0,1,0,-1,1,1,-1,-1};
const int MOD = 1e9+7;
const int INF = 1e18+10;

/*----------------------------------------------*/


signed main(){
  int a,v,b,w,t;
  cin>>a>>v>>b>>w>>t;
  int ch=abs(w-v)*t;
  if(abs(a-b)<=ch&&v>w){
    cout<<"YES"<<endl;
  }else{
    cout<<"NO"<<endl;
  }
  return 0;
}


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


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

Measured memory_bytes: 256
// g++ -std=c++11 -o2 -Wall ABC097C.cpp -o ./out/ABC097C.out
// ./out/ABC097C.out

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

#define all(c) (c).begin(), (c).end()
#define iter(c) __typeof((c).begin())
#define present(c, e) ((c).find((e)) != (c).end())
#define cpresent(c, e) (find(all(c), (e)) != (c).end())
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define tr(c, i) for (iter(c) != (c).begin(); i != (c).end(); ++i)
#define pb push_back
#define mp make_pair

typedef long long ll;


int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  string s;
  int k;
  cin >> s >> k;
  int n = s.size();
  set<string> ss;
  for (int l = 1; l <= 5; ++l) {
    for (int j = 0; j <= n - l; ++j) {
      ss.insert(s.substr(j, l));
    }
  }
  string ans;
  for (auto sss : ss) {
    --k;
    if (k <= 0) {
      ans = sss;
      break;
    }
  }
  cout << ans << "\n";
  return 0;
}


Measured memory_bytes: 1664
#include<stdio.h>
#include<stdlib.h>
#define N 10000
#define NIL NULL
struct node{
  struct node *left;
  struct node *right;
  struct node *parent;
  int key;
};

typedef struct node * Node;
Node root;

void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;
  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;
  
  while(x != NIL){
    y = x;
    if(z->key < x->key)
      x = x->left;
    else{
      x = x->right;
    }
  }
  z->parent = y; 
    if(y==NIL){
      root=z;
    }
    else if(z->key < y -> key){
      y->left = z;
    }
    else{
      y->right =z;
    }
}
void inorder(Node u){
  if(u != NIL){
    inorder(u->left);
    printf(" ");
    printf("%d",u->key);
    inorder(u->right);
  }
 
}
void preorder(Node u){ 
    if (u != NIL) {
      printf(" ");
      printf("%d",u->key); 
      preorder(u->left);
      preorder(u->right);
    
    }
}
Node IterativeTreeSearch(Node x,int k){
  if(x == NIL || k == x -> key) return x;
  if(k < x -> key) return IterativeTreeSearch(x -> left, k);
  else return IterativeTreeSearch(x -> right, k);

 
}

int main(){
  int i,n,m,x;
  char str[10];
  scanf("%d",&m);
  for(i=0;i<m;i++){
    scanf("%s",str);
    if(str[0]=='f'){
      scanf("%d", &x);
      Node t = IterativeTreeSearch(root, x);
      if ( t != NIL ){ 
	printf("yes\n");
      }
      else {
	printf("no\n");
      }
    }
    else if(str[0]=='i'){  
      scanf("%d",&n);
      insert(n);
    }
    
    else if(str[0]=='p'){
      
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    }
  }
return 0;
}

Measured memory_bytes: 19364
#include "bits/stdc++.h"

using namespace std;

#define  f first
#define  lgn 25
#define  endl '\n'
#define  sc second
#define  N (int)2e5+5
#define  sz(x) x.size()
#define  ll long long int
#define  ld long double
#define  vi vector<int>
#define  vl vector<ll>
#define  vs vector<string>
#define  vc vector<char>
#define  mii map<int,int>
#define  mll map<ll,ll>
#define  pii pair<int,int>
#define  pll pair<ll,ll>
#define  vpll vector<pll>
#define  vpii vector<pii>
#define  test(x) while(x--)
#define  pb push_back
#define  eb emplace_back
#define  pq priority_queue
#define  mod 1000000007
#define  fo(i,a,n) for(int i=a;i<n;i++)
#define  rfo(i,n,a) for(int i=n;i>=a;i--)
#define  mst(a,v,n) fo(i,0,n) a[i]=v
#define  all(x) sort(begin(x),end(x))
#define  allr(x) sort(rbegin(x),rend(x))
#define  rev(x) reverse(begin(x),end(x))
#define  db(x) cout<<#x <<" : "<< x <<endl;
#define  tie ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define time() cerr << "Time : " << (double)clock() / (double)CLOCKS_PER_SEC << "s\n"

const int inf = 0x3f3f3f3f;
const ll INF = 0x3f3f3f3f3f3f3f3f;

ll n;
void go()
{
	cin>>n;
	ll ans=0;
	if(n&1) ans=n*(n+1)/2;
	else ans=(n/2)*(n+1);
	ans-=n;
	cout<<ans<<endl;
}

int32_t main()
{
	tie; int t=1; 
	// cin>>t;
	test(t) go();
}

Measured memory_bytes: 256
a = gets.to_i
b = gets.to_i
c = gets.to_i
x = gets.to_i

ans = 0

(0..a).each do |i|
  (0..b).each do |j|
    (0..c).each do |k|
      ans += 1 if x == 500 * i + 100 * j + 50 * k
    end
  end
end

puts ans


Measured memory_bytes: 1788
{-# LANGUAGE ScopedTypeVariables #-}
import qualified Data.IntMap as IM
import Data.Ord
import Data.List

main = do
  [numMonsters, available] <- map read . words <$> getLine
  enemies :: [Int] <- map read . words <$> getLine
  let enemies' = sortBy (comparing negate) enemies
  print $ sum $ drop available enemies'

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

int main(){
    int H ,W;
    while(1){
    cin >> H >>W;
    if(H == 0 && W == 0 ) break;
    for(int i = 0;i < H; i++){
        for(int j = 0; j < W; j++){
            if(i == 0 || i == H-1 || j == 0| j == W-1 ){
                cout << "#";
            }else{
                cout << ".";
            }
        }cout << endl;
        }
        cout << endl;
    }
    return 0;
}


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

using namespace std;

int main()
{
    int arr[3];
    for(int i=0;i<3;i++)
    {
        cin>>arr[i];
    }
    sort(arr,arr+3);
    if(arr[0]==5 && arr[1]==5 && arr[2]==7)
    {
        cout<<"YES"<<endl;
    }
    else
    {
        cout<<"NO"<<endl;
    }
}

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

//#define HOST
#ifdef HOST
#include"data_structure.h"
#include"common_algorithm.h"
#endif

ll inf = 1e9+7;

ll modularInverse(ll x, ll y, ll m)
{
    vector<ll> dp(x+1, 1);
    for (int i = 2; i <= x; i++)
        dp[i] = dp[m % i] *
               (m - m / i) % m;

    return (dp[x]*y)%m;
}


int main() {
    ll n, k, d;
    cin >> n;
    vector<ll> a(5,0);
    for(int i = 0; i < 5; i++)
    {
        cin >> a.at(i);
    }
    sort(a.begin(), a.end());
    ll sum = 5;
    if(n%a.at(0))
    {
        sum += n/a.at(0);
    }
    else
    {
        sum += n/a.at(0)-1;
    }
    cout << sum;

    return 0;
}


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

typedef long long ll;
typedef long double ld;

#define n1		      "\n"
#define B                     begin()
#define E                     end()
#define F                     first
#define S                     second
#define pb                    push_back
#define pf                    push_front
#define popb                  pop_back()
#define popf                  pop_front()

const int BIG=1e5+55;
const int BIGG=1e9+7;
const ll BIGGE=1e12+55;
const double SML=(1e-7);

using namespace std;

    int n;

int main()
{
    ios::sync_with_stdio(false); cin.tie(NULL);
    cout.tie(NULL);
    bool go = 1;
    cin >>n;
    for (int i=0; i<n; i++) {
        int x;
        cin >>x;
        if (x % 2 == 0) {
            if (x % 3 != 0 && x % 5 != 0) {
                go = 0;
            }
        }
    }
    if (go)
        cout <<"APPROVED";
    else
        cout <<"DENIED";



    return 0;
}


Measured memory_bytes: 256
// ABC144B - 81

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

typedef unsigned long long int ull;
typedef long long int ll;

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

	for (int i = 1; i <= 9; i++) {
		for (int j = 1; j <= 9; j++) {
			if (i * j == N) {
				cout << "Yes" << endl;
				return 0;
			}
		}
	}

	cout << "No" << endl;

	return 0;
}


Measured memory_bytes: 256
package main

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

func main() {
	sc := NewScanner()
	N := sc.NextInt()
	mp := map[string]bool{}

	for i := 0; i < N; i++ {
		mp[sc.Next()] = true
	}
	fmt.Println(len(mp))

}

type Scanner struct {
	r   *bufio.Reader
	buf []byte
	p   int
}

func NewScanner() *Scanner {
	rdr := bufio.NewReaderSize(os.Stdin, 1000)
	return &Scanner{r: rdr}
}
func (s *Scanner) Next() string {
	s.pre()
	start := s.p
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			break
		}
	}
	result := string(s.buf[start:s.p])
	s.p++
	return result
}
func (s *Scanner) NextLine() string {
	s.pre()
	start := s.p
	s.p = len(s.buf)
	return string(s.buf[start:])
}
func (s *Scanner) NextInt() int {
	v, _ := strconv.Atoi(s.Next())
	return v
}
func (s *Scanner) NextInt64() int64 {
	v, _ := strconv.ParseInt(s.Next(), 10, 64)
	return v
}

func (s *Scanner) NextFloat() float64 {
	v, _ := strconv.ParseFloat(s.Next(), 64)
	return v
}

func (s *Scanner) NextIntArray() []int {
	s.pre()
	start := s.p
	result := []int{}
	for ; s.p < len(s.buf)+1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 0)
			result = append(result, int(v))
			start = s.p + 1
		}
	}

	return result
}
func (s *Scanner) NextInt64Array() []int64 {
	s.pre()
	start := s.p
	result := []int64{}
	for ; s.p < len(s.buf)+1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 64)
			result = append(result, v)
			start = s.p + 1
		}
	}
	return result
}

func (s *Scanner) NextMap() map[int]bool {
	s.pre()
	start := s.p
	mp := map[int]bool{}
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			v, _ := strconv.Atoi(string(s.buf[start:s.p]))
			mp[v] = true
			start = s.p + 1
		}
	}
	v, _ := strconv.Atoi(string(s.buf[start:s.p]))
	mp[v] = true

	return mp
}

func (s *Scanner) pre() {
	if s.p >= len(s.buf) {
		s.readLine()
		s.p = 0
	}
}
func (s *Scanner) readLine() {
	s.buf = make([]byte, 0)
	for {
		l, p, e := s.r.ReadLine()
		if e != nil {
			panic(e)
		}
		s.buf = append(s.buf, l...)
		if !p {
			break
		}
	}
}


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

int main(){
  string s;
  cin >> s;
  int n = s.size();
  int ans = 0;
  for(int i = 0; i < n / 2; i++){
    if(s[i] != s[n-1-i]) ans++;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3632
#include<stdio.h>
#define N 8

int row[N],col[N],dpos[2*N-1],dneg[2*N-1];
int ary[N][N];

void print(){
  int i,j;
  for(i=0;i<N;i++){
    for(j=0;j<N;j++){
      if(ary[i][j]){
	if(row[i]!=j)return;
      }
    }
  }
  for(i=0;i<N;i++){
    for(j=0;j<N;j++){
      if(row[i]==j)printf("Q");
      else printf(".");
    }
    printf("\n");
  }
}

void set(int n){
  int i;
  if(n==N){
    print();
    return;
  }
  for(i=0;i<N;i++){
    if(col[i]==1 || dpos[n+i]==1 || dneg[n-i+N-1]==1)continue;
    row[n]=i;
    col[i]=dpos[n+i]=dneg[n-i+N-1]=1;
    set(n+1);
    row[n]=col[i]=dpos[n+i]=dneg[n-i+N-1]=-1;
  }
}

int main(){
  int i,j,k,x,y;
  for(i=0;i<N;i++){
    row[i]=-1,col[i]=-1;
  }
  for(i=0;i<N;i++){
    dpos[i]=-1;dneg[i]=-1;
  }
  for(i=0;i<N;i++){
    for(j=0;j<N;j++){
      ary[i][j]=0;
    }
  }
  scanf("%d",&k);
  for(i=0;i<k;i++){
    scanf("%d%d",&y,&x);
    ary[y][x]=1;
  }
  set(0);
  return 0;
      
}



Measured memory_bytes: 2088
#include <iostream>
#include <map>
using namespace std;
int main(){
  char T;
  map<char,int> M;
  for(int i = 2; i < 10; ++i) M['0'+i] = i;
  M['T'] = 10;
  M['J'] = 11;
  M['Q'] = 12;
  M['K'] = 13;
  M['A'] = 14;
  while(cin >> T, T != '#'){
    string C[4][13];
    for(int i = 0; i < 4; ++i)
      for(int j = 0; j < 13; ++j)
        cin >> C[i][j];
    int score[] = {0,0};
    int t = 0;
    for(int i = 0; i < 13; ++i){
      bool f = false;
      int t_ = t, m = M[C[t][i][0]];
      char s = C[t][i][1];
      for(int j = 0; j < 4; ++j){
        int j_ = (t + j)%4;
        if(f){
          if(M[C[j_][i][0]] > m && C[j_][i][1] == T){
            t_ = j_;
            m = M[C[t_][i][0]];
          }
        }else{
          if(C[j_][i][1] == T){
            t_ = j_;
            m = M[C[j_][i][0]];
            f = true;
          }else if(M[C[j_][i][0]] > m &&  C[j_][i][1] == s){
            t_ = j_;
            m = M[C[j_][i][0]];
          }
        }
      }
      t = t_;
      ++score[t%2];
    }
    if(score[0] > score[1]) cout << "NS " << score[0] - 6 << endl;
    else cout << "EW " << score[1] - 6 << endl;
  }
  return 0;
}



Measured memory_bytes: 2996
#include <iostream>

using namespace std;

int main(){
    int A, B, C, X;
    cin >> A >> B >> C >> X;
    
    int gA = 500, gB = 100, gC = 50;
    int nesA = X/gA,   res = X%gA;
    int nesB = res/gB; res = res%gB;
    int nesC = res/gC;
    
    int ans = 0;
    if (nesC > C){ ans = 0; }
    else{
	for (int i=0; i<=A; i++){
	    for (int j=0; j<=B; j++){
		for (int k=0; k<=C; k++){
		    int amount = i*500 + j*100 + k*50;
		    if (amount == X) ans++;
		}
	    }
	}
    }
    cout << ans << endl;
    
    return 0;
}


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

int main() {
  vector<int> a(5);
  rep(i,5){
  cin >> a.at(i);
  }
  rep(i,5){
    if(a.at(i)==0){
      cout << i+1 <<endl;
    }
  }  
}

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


ll calc(ll h)
{
	if(h==1)
		return 1;
	if(h==2)
		return 3;
	ll num=h/2;
	return (2*calc(num)+1);
	
}

int main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    ll h,n,cnt=0,ans=0,i,num;
    cin>>h;
    n=calc(h);
   	cout<<n<<endl;
	
	
	
   		
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef long double ld;
ll n, m;
//ld ;
//string s;

int main() {
    cin >> n >> m;
    ll good[n];
    ll h[n];
    for(ll i=0;i<n;i++){
        cin >> h[i];
        good[i] = 1;
    }
    for(ll i=0;i<m;i++){
        ll l,r;
        cin >> l >> r;
        if(h[l-1]<=h[r-1]){
            good[l-1] = 0;
        }
        if(h[l-1]>=h[r-1]){
            good[r-1] = 0;
        }
    }
    ll count = 0;
    for(ll i=0;i<n;i++){
        count += good[i];
    }
    cout << count << endl;
    return 0;
}


Measured memory_bytes: 5184
# coding: utf-8
import sys
from bisect import bisect_left, bisect_right, insort
sys.setrecursionlimit(10 ** 7)

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

N = ir()
A = [0] + lr()  # 1-indexed
graph = [[] for _ in range(N+1)]  # 1-indexed
for _ in range(N-1):
    a, b = lr()
    graph[a].append(b)
    graph[b].append(a)

answer = [0] * (N+1)  # 1-indexed
INF = 10 ** 10
parent = [-1] * (N+1)

def dfs(n):
    """arrはLISのリスト、answerのリストを更新してから子にarrを渡す"""
    i = bisect_left(dp, INF)
    answer[n] = i
    for c in graph[n]:
        if c == parent[n]:
            continue
        parent[c] = n
        i = bisect_left(dp, A[c])
        old = dp[i]
        dp[i] = A[c]
        dfs(c)
        dp[i] = old

dp = [INF] * (N+1)
dp[0] = A[1]
dfs(1)
for a in answer[1:]:
    print(a)


Measured memory_bytes: 352076
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using VI = vector<int>;
using VL = vector<ll>;
template<class T> using PQ = priority_queue<T, vector<T>, greater<T>>;
#define FOR(i,a,n) for(int (i)=(a);(i)<(n);++(i))
#define eFOR(i,a,n) for(int (i)=(a);(i)<=(n);++(i))
#define rFOR(i,a,n) for(int (i)=(n)-1;(i)>=(a);--(i))
#define erFOR(i,a,n) for(int (i)=(n);(i)>=(a);--(i))
#define each(i, a) for(auto &i : a)
#define SORT(i) sort((i).begin(),(i).end())
#define rSORT(i,a) sort((i).begin(),(i).end(),(a))
#define all(i) (i).begin(),(i).end()
#define out(y,x) ((y) < 0 || h <= (y) || (x) < 0 || w <= (x))
#define line cout << "------------------------\n" 
#define ENDL(i,n) ((i) == (n) - 1 ? "\n" : " ")
#define stop system("pause") //comment out this on AOJ.
constexpr ll INF = 1000000000;
constexpr ll LLINF = 1LL << 60;
constexpr ll mod = 1000000007;
constexpr ll MOD = 998244353;
constexpr ld eps = 1e-10; //1e-9?
constexpr ld pi = 3.1415926535897932;
template<class T>inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; }return false; }
template<class T>inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; }return false; }
inline void init() { cin.tie(nullptr); cout.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); }
template<class T>inline istream& operator>>(istream& is, vector<T>& v) { for (auto& elemnt : v)is >> elemnt; return is; }
template<class T, class U>inline istream& operator>>(istream& is, pair<T, U>& p) { is >> p.first >> p.second; return is; }
template<class T>inline vector<T> vec(size_t a) { return vector<T>(a); }
template<class T>inline vector<T> defvec(T def, size_t a) { return vector<T>(a, def); }
template<class T, class... Ts>inline auto vec(size_t a, Ts... ts) { return vector<decltype(vec<T>(ts...))>(a, vec<T>(ts...)); }
template<class T, class... Ts>inline auto defvec(T def, size_t a, Ts... ts) { return vector<decltype(defvec<T>(def, ts...))>(a, defvec<T>(def, ts...)); }

int main() {
    init();

    ll n, k; cin >> n >> k;
    VL a(n); cin >> a;

    ll sum = 0;
    each(i, a)sum += i;
    VL divs;
    for (ll i = 1; i * i <= sum; ++i) {
        if (sum % i == 0) {
            divs.push_back(i);
            if (i * i != sum)divs.push_back(sum / i);
        }
    }

    ll ans = 0;
    each(num, divs) {
        VL u(n), d(n);
        FOR(i, 0, n) {
            u[i] = num - a[i] % num;
            d[i] = a[i] % num;
        }

        SORT(u), SORT(d);
        bool uok = false, dok = false;
        ll U = 0, D = 0, L = 0, R = 0;
        FOR(i, 0, n) {
            L += num - d[i];
            R += d[i];
        }
        FOR(i, 0, n) {
            L -= num - d[i];
            D += d[i];
            dok |= max(D, L) <= k && D == L;
        }
        if (uok || dok)chmax(ans, num);
    }

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

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
int n,k,sum,a[200005];
int main() {
	ios::sync_with_stdio(false);
	cin >> n >> k;
	for(int i = 1; i <= n; i++) {
		cin >> a[0];
		a[a[0]]++;
	}
	sort(a + 1,a + n + 1);
	for(int i = n - k + 1; i <= n; i++)
		sum += a[i];
	cout << n - sum;
	return 0;
}

Measured memory_bytes: 1024
import re
sd = input()
ts =  input()

def f():
    cand = []
    for i in range(len(sd) - len(ts) + 1):
        p = sd[i:i + len(ts)]
        pat = re.compile(p.replace('?', '.'))
        if re.match(pat, ts):
            cand.append((sd[:i] + ts + sd[i+len(ts):]).replace('?', 'a'))
    return sorted(cand)[0] if cand else 'UNRESTORABLE'
print(f())

Measured memory_bytes: 3188
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int Num = scan.nextInt();
		int[] temoti = new int[Num]; // 手持ちのトランプ
		for (int i = 0; i < Num; i++) {
			temoti[i] = scan.nextInt();
		}
		insertionSort(temoti, Num);
	}

	/**
	 * 挿入ソート
	 * 
	 * @param cardArray
	 *            ソート対象のカードリスト
	 * @param Num
	 *            ソート対象のカードの枚数
	 */
	public static void insertionSort(int[] cardArray, int Num) {
		for (int i = 0; i < Num; i++) {
			int selectedCard = cardArray[i]; // 1枚トランプを取り出す
			int j = i - 1;
			// 取り出した一枚より前の方に持っていたトランプと比較
			while (j >= 0 && cardArray[j] > selectedCard) {
				cardArray[j + 1] = cardArray[j];
				j--;
			}
			// 取り出した一枚が比較しているトランプより大きければ、取り出した一枚のj+1番目に挿入する。
			cardArray[j + 1] = selectedCard;
			for (int k = 0; k < Num; k++) {
				if (k == Num - 1) {
					System.out.print(cardArray[k]);// 最後の一枚の場合には空白をつけない
				} else {
					System.out.print(cardArray[k] + " ");
				}
			}
			System.out.println("");
		}

	}
}



Measured memory_bytes: 32820
#include<cstdio>
#include<algorithm>
#include<iostream>
#define N 200005
using namespace std;
int n,q,m;
long long Q,V[N],ans[N],a[N];
void CL(long long x,long long v)
{
	int P;
	P=lower_bound(a+1,a+m+1,x)-a-1;
	if (x<=a[1])
	{
		ans[1]+=v;
		ans[x+1]-=v;
		return;
	}
	V[P]+=v*(x/a[P]);
	CL(x%a[P],v);
}
int main()
{
	scanf("%d%d",&n,&q);
	m++;
	a[m]=n;
	for (int i=1;i<=q;i++)
	{
		scanf("%lld",&Q);
		while (Q<=a[m])
			m--;
		a[++m]=Q;
	}
	V[m]=1;
	for (int i=m;i>1;i--)
	{
		V[i-1]+=V[i]*(a[i]/a[i-1]);
		CL(a[i]%a[i-1],V[i]);
	}
	ans[0]=0;
	ans[1]+=V[1];
	ans[a[1]+1]-=V[1];
	for (int i=1;i<=n;i++)
	{
		ans[i]+=ans[i-1];
		printf("%lld\n",ans[i]);
	}
	return 0;
}

Measured memory_bytes: 6100
import sys, os, math, bisect, itertools, collections, heapq, queue, copy, array

# from scipy.sparse.csgraph import csgraph_from_dense, floyd_warshall
# from decimal import Decimal
# from collections import defaultdict, deque

sys.setrecursionlimit(10000000)

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: (x * y) // math.gcd(x, y)

MOD = 10 ** 9 + 7
MAX = float('inf')


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    R, G, B = il()
    K = ii()

    for k in range(K):
        if B <= G:
            B *= 2
        elif G <= R:
            G *= 2

        if B > G > R:
            print('Yes')
            exit()
    else:
        print('No')


if __name__ == '__main__':
    main()


Measured memory_bytes: 9888
// In His Name

#include <bits/stdc++.h>

#define pb push_back
#define F first
#define S second
#define gcd __gcd
#define int long long
#define ull unsigned long long

using namespace std;

typedef pair <int, int> pii;

const int MAX_H = 3e3 + 10 , MOD = 1e9 + 7;
int dp[MAX_H][MAX_H];

main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	string s, t;
	cin >> s >> t;
	if (s[0] == t[0]){
		dp[0][0] = 1;
	}
	for (int i = 1 ; i < s.size() ; i++){
		if (s[i] == t[0]){
			dp[i][0] = 1;
		}
		else {
			dp[i][0] = dp[i - 1][0];
		}
	}
	for (int i = 1 ; i < t.size() ; i++){
		if (s[0] == t[i]){
			dp[0][i] = 1;
		}
		else {
			dp[0][i] = dp[0][i - 1];
		}
	}
	for (int i = 1 ; i < s.size() ; i++){
		for (int j = 1 ; j < t.size() ; j++){
			if (s[i] == t[j]){
				dp[i][j] = dp[i - 1][j - 1] + 1;
			}
			else {
				dp[i][j] = max (dp[i - 1][j] , dp[i][j - 1]);
			}
		}
	}
	string ans;
	int i = s.size() - 1;
	int j = t.size() - 1;
	while (i >= 0 && j >= 0){
		if (s[i] == t[j]){
			ans += s[i];
			i--;
			j--;
			continue;
		}
		if (i == 0){
			j--;
			continue;
		}
		if (j == 0){
			i--;
			continue;
		}
		if (dp[i - 1][j] > dp[i][j - 1]){
			i--;
			continue;
		}
		j--;
	}
	reverse (ans.begin() , ans.end());
	cout << ans;
}

Measured memory_bytes: 70912
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<deque>
#include<cmath>
#include<map>
#include<cstring>

using namespace std;
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LLINF = 1LL<<60;
#define P pair<int, int>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define print(x) cout << (x) << endl

class mint {
    long long x;
public:
    mint(long long x=0) : x((x%MOD+MOD)%MOD) {}
    mint operator-() const {
      return mint(-x);
    }
    mint& operator+=(const mint& a) {
        if ((x += a.x) >= MOD) x -= MOD;
        return *this;
    }
    mint& operator-=(const mint& a) {
        if ((x += MOD-a.x) >= MOD) x -= MOD;
        return *this;
    }
    mint& operator*=(const  mint& a) {
        (x *= a.x) %= MOD;
        return *this;
    }
    mint operator+(const mint& a) const {
        mint res(*this);
        return res+=a;
    }
    mint operator-(const mint& a) const {
        mint res(*this);
        return res-=a;
    }
    mint operator*(const mint& a) const {
        mint res(*this);
        return res*=a;
    }
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }
    // for prime MOD
    mint inv() const {
        return pow(MOD-2);
    }
    mint& operator/=(const mint& a) {
        return (*this) *= a.inv();
    }
    mint operator/(const mint& a) const {
        mint res(*this);
        return res/=a;
    }

    friend ostream& operator<<(ostream& os, const mint& m){
        os << m.x;
        return os;
    }
};
/* -- template -- */

int main() {
    int N, M; cin >> N >> M;
    priority_queue<int>Q;
    int A[N]; rep(i, N) cin >> A[i], Q.push(A[i]);
    while(M > 0) {
        int q = Q.top();Q.pop();
        q /= 2;
        Q.push(q);
        --M;
    }
    ll ans = 0;
    rep(i, N)
        ans += Q.top(), Q.pop();
    cout << ans << endl;
}


Measured memory_bytes: 1148
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn =5005;
ll dp[maxn][maxn],n,mod;
ll c[maxn];
int main()
{
    cin>>n>>mod;
    for(int i=2;i<=n;i++)
    {
        c[i]=(i<=(n>>1)+1?i-1:n-i+2);
    }
    // dp[i][j]=dp[i][j-c[i]]+dp[i-1][j]
   for(int i=0;i<=n;i++)
    dp[i][0]=1;
    for(int i=2;i<=n;i++)
    for(int j=0;j<=n;j++)
    {
        if(j>=c[i])dp[i][j]=(dp[i][j-c[i]]+dp[i-1][j]+mod)%mod;
        else dp[i][j]=dp[i-1][j];
    }
    ll ans=0;
    for(int i=0;i<n;i++)
    ans=(ans+(n-i)*dp[n][i]%mod)%mod;
    cout<<ans;
}

Measured memory_bytes: 195712
S=list(input())
ans="Yes"
n=S.count("N")
e=S.count("E")
w=S.count("W")
s=S.count("S")
if n>0 and s>0:
  if e>0 and w>0:
    pass
  elif e==0 and w==0:
    pass
  else:
    ans="No"
elif n==0 and s==0:
  if e>0 and w>0:
    pass
  elif e==0 and w==0:
    pass
  else:
    ans="No"
elif e>0 and w>0:
  if n>0 and s>0:
    pass
  elif n==0 and s==0:
    pass
  else:
    ans="No"
elif e==0 and w==0:
  if n>0 and s>0:
    pass
  elif n==0 and s==0:
    pass
  else:
    ans="No"
else:
  ans="No"
print(ans)

Measured memory_bytes: 3064
// https://atcoder.jp/contests/abc134/tasks/abc134_d
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <string>
#include <algorithm>
#include <numeric>
#include <map>
#include <unordered_map>
#include <stack>
#include <queue>
#include <set>
#include <unordered_set>
#include <bitset>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
#define REP(i, n) for(size_t i = 0; i < (n); ++i)

int main()
{
    int N;
    cin >> N;
    vector<int> a(N + 1);
    for (int i = 1; i <= N; ++i) cin >> a[i];
    int M = 0;
    vector<int> b(N + 1, 0);
    for (int i = N; i >= 1; --i)
    {
        int sum = 0;
        for (int k = i + i; k <= N; k += i)
        {
            if (k <= N && 1 == b[k])
            {
                sum += 1;
            }
        }
        if ((1 + sum) % 2 == a[i])
        {
            b[i] = 1;
            ++M;
        }
        else
        {
            b[i] = 0;
        }
        
    }
    printf("%d\n", M);
    for (int i = 1; i <= N; ++i)
    {
        if (b[i] == 1)
        {
            printf("%d", i);
            if (i != N) printf(" ");
        }
    }
    printf("\n");
    return 0;
}


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

map<long long, long long> mapa;
long long n,R,a[200010];

int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(0);
    cin>>n;
    for (int i=1;i<=n;i++){
        cin>>a[i];
        if (mapa.find(i-a[i])==mapa.end()) mapa[i-a[i]]=1;
        else mapa[i-a[i]]++;
    }
    for (int i=1;i<=n;i++){
        R+=mapa[a[i]+i];
    }
    cout<<R<<'\n';
}


Measured memory_bytes: 27924
#include <math.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define PI acos(-1)
typedef unsigned long long int ull;
typedef long double ld;
 
int main(void) {
  int   scan;
 
  ull    answer;
  ull    n;
  ull    *a;
  ull    MOD;
  ull    sums;
  answer = 0;
  MOD = 1000000007;
  sums = 0;
  scan = scanf("%llu", &n);
  a = (ull *)malloc(sizeof(ull) * n);
  for (ull i = 0; i < n; i++) {
    scan = scanf("%llu", &a[i]);
  }
  
  for (ull i = 0; i < n; i++) {
    sums = sums + a[i];
  }
 
  for (ull i = 0; i < n - 1; i++) {
    sums = sums - a[i];
    answer = (answer + a[i] * (sums % MOD)) % MOD;
  }
 
  printf("%llu", answer);
 
  return (0);
}
 


Measured memory_bytes: 3248
use std::io;

fn main() {
    let n: i32 = {
        let mut n = String::new();
        io::stdin().read_line(&mut n).unwrap();
        n.trim_right().to_owned().trim().parse().unwrap()
    };
    {
        let mut w: Vec<String> = vec![];
        let mut s1 = String::new();
        io::stdin().read_line(&mut s1).unwrap();
        w.push(s1.trim_right().to_owned());
        s1 = s1.trim_right().to_owned();
        for _ in 1..n {
            let mut s2 = String::new();
            io::stdin().read_line(&mut s2).unwrap();
            s2 = s2.trim_right().to_owned();
            if w.contains(&s2) {
                print!("No");
                return;
            }
            w.push(s2.trim_right().to_owned());
            if !s2.starts_with(s1.chars().last().unwrap()) {
                print!("No");
                return;
            }
            s1 = s2;
        }
    }
    print!("Yes");
}


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

int main(void){
	string s; cin >> s;
	string ans;
	rep(i, s.size()){
		if(s[i] == '0') ans += '0';
		else if(s[i] == '1') ans += '1';
		else{
			if(!ans.empty()) ans.pop_back();//空文字でなければ
		}
	}
	cout << ans << endl;
	return 0;
}

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

#define rep(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
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; }

#ifdef LOCAL
    #define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
    #define eprintf(...) do{}while(0)
#endif

struct Ap {
	ll x, y;
};

void flipy(vector<Ap> &a){
	rep( i, SZ(a) ){
		a[i].y = -a[i].y;
	}
}
void flipx(vector<Ap> &a){
	rep( i, SZ(a) ){
		a[i].x = -a[i].x;
	}
}


ll test( vector<Ap> &ay, vector<Ap> &ax, ll dy, ll dx ){
	if ( dy == -1 ){
		flipy(ay);
		flipy(ax);
	}
	if ( dx == -1 ){
		flipx(ay);
		flipx(ax);
	}
	
	// ap.x+ap.yが同じなら衝突の可能性がある
	map<ll,pair<vector<ll>,vector<ll>>> m;
	rep( i, SZ(ay) ){
		Ap &ap = ay[i];
		m[ap.x+ap.y].first.push_back(ap.x);
	}
	rep( i, SZ(ax) ){
		Ap &ap = ax[i];
		m[ap.x+ap.y].second.push_back(ap.x);
	}
	
	ll t = LLONG_MAX;
	for ( auto e : m ){
		auto &vy = e.second.first;
		auto &vx = e.second.second;
		sort(ALL(vy));
		sort(ALL(vx));
		
		// x方向の飛行機があれば、それ以降のy方向の飛行機が衝突する
		int iy = 0;
		rep(ix,SZ(vx)){
			while ( iy < SZ(vy) && vy[iy] < vx[ix] )
				iy++;
			if ( iy == SZ(vy) )
				break;
			chmin( t, (vy[iy] - vx[ix])*10 );
		}
	}
	
	if ( dy == -1 ){
		flipy(ay);
		flipy(ax);
	}
	if ( dx == -1 ){
		flipx(ay);
		flipx(ax);
	}
	return t;
}

void flip_xy(vector<Ap> &a){
	rep( i, SZ(a) ){
		swap( a[i].x, a[i].y );
	}
}


ll testy( vector<Ap> &au, vector<Ap> &ad, bool is_flip_xy ){
	if ( is_flip_xy ){
		flip_xy(au);
		flip_xy(ad);
	}
	
	map<ll,pair<vector<ll>,vector<ll>>> m;
	rep( i, SZ(au) ){
		Ap &ap = au[i];
		m[ap.x].first.push_back(ap.y);
	}
	rep( i, SZ(ad) ){
		Ap &ap = ad[i];
		m[ap.x].second.push_back(ap.y);
	}
	
	ll t = LLONG_MAX;
	for ( auto e : m ){
		auto &vu = e.second.first;
		auto &vd = e.second.second;
		sort(ALL(vu));
		sort(ALL(vd));
		
		// 上方向の飛行機があれば、それ以降の下方向の飛行機が衝突する
		int id = 0;
		rep(iu,SZ(vu)){
			while ( id < SZ(vd) && vd[id] < vu[iu] )
				id++;
			if ( id == SZ(vd) )
				break;
			chmin( t, (vd[id] - vu[iu])*5 );
		}
	}
	
	if ( is_flip_xy ){
		flip_xy(au);
		flip_xy(ad);
	}
	return t;
}



int main(){
	ll n;
	cin >> n;
	
	vector<Ap> apu, apr, apd, apl;
	apu.reserve(n);
	apr.reserve(n);
	apd.reserve(n);
	apl.reserve(n);
	
	rep(i,n){
		ll x, y;
		char u;
		cin >> x >> y >> u;
		if ( u == 'U' ) apu.push_back({x,y});
		if ( u == 'R' ) apr.push_back({x,y});
		if ( u == 'D' ) apd.push_back({x,y});
		if ( u == 'L' ) apl.push_back({x,y});
	}
	
	ll t = LLONG_MAX;
	
	chmin( t, testy( apu, apd, false ) );
	chmin( t, testy( apr, apl, true ) );
	
	chmin( t, test( apu, apr,  1,  1 ) );
	chmin( t, test( apu, apl,  1, -1 ) );
	chmin( t, test( apd, apr, -1,  1 ) );
	chmin( t, test( apd, apl, -1, -1 ) );
	
	if ( t == LLONG_MAX )
		cout << "SAFE" << endl;
	else
		cout << t << endl;
	
	return 0;
}




Measured memory_bytes: 31224
#include<iostream>

using namespace std;

int main(){
    int prob,part;
    int proN = 0;

    cin>>part>>prob;

    int que[part][prob];
    int res[part];

    for(int i=0;i<part;i++){
        res[i] = 0;
        for(int j=0;j<prob;j++){
            cin>>que[i][j];
            if(que[i][j]==1) res[i]++;
        }
    }

    if(part == 1) cout<<res[0]<<endl;
    else{
        for(int i=0;i<part;i++){
            if(proN < res[i]) proN = res[i];
        }
        cout<<proN<<endl;
    }

    return 0;
}


Measured memory_bytes: 3092
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long ll;
#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--)

int main() {
  int a, b;
  cin >> a >> b;
  
  int ans = 0;
  int count = 1;
  while (count < b) {
    count += a - 1;
    ans += 1;
  }
  
  cout << ans << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int ans = 0;
		for (int i = 0; i < n; i++) {
			ans += sc.nextInt();
		}
		sc.close();

		ans -= n;
		System.out.println(ans);
	}
}


Measured memory_bytes: 26224
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define outl(x) cout << (x) << '\n'
using namespace std;
typedef long long ll;

constexpr int MX = 101010;
constexpr int MOD = (int)1e9 + 7;

int f[MX];

inline ll sqr(ll n)
{
    return n * n;
}

inline int modPow(int n, int p)
{
    if (p <= 0) return 1;
    ll ret = sqr(modPow(n, p/2)) % MOD;
    if (p & 1) (ret *= n) %= MOD;
    return ret;
}

void preCalc()
{
    f[0] = 1;
    for (ll i = 1; i < MX; ++i) {
        f[i] = i * f[i-1]  % MOD;
        //finv[i] = modPow(f[i], MOD-2);
    }
    return;
}

inline int combi(int n, int k)
{
    if (k < 0 || n < k) return 0;
    return 1LL * f[n] * modPow(f[k],MOD-2) % MOD * modPow(f[n-k], MOD-2) % MOD;
}

int main()
{
    int N, l, r;
    int pos[MX];

    preCalc();
    memset(pos, -1, sizeof(pos));

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

    cin >> N;
    ++N;
    rep(i, N) {
        int a; cin >> a;
        if (~pos[a]) l = pos[a], r = i;
        else pos[a] = i;
    }

    for (int i =1; i <= N; ++i) {
        outl( (combi(N, i) - combi(N-1-r+l, i-1) + MOD) % MOD );
    }
}


Measured memory_bytes: 2048
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  	int n, slv = 0;
  	scanf("%d", &n);
  	n--;
  	int v[n];
  	for(int i = 0; i < n; i++) scanf("%d", &v[i]);
  	for(int i = 0; i < n - 1; i++) slv += min(v[i],v[i+1]);
  	slv += v[0];
  	slv += v[n - 1];
 	cout << slv << endl;
	return 0;
}

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

int main() {
  int A,B,C,D;
  cin >> A >> B >> C >> D;
  int L = A + B;
  int R = C + D;
  if (L < R) {
    cout << "Right" << endl;
  }
  if (L == R) {
    cout << "Balanced" << endl;
  }
  if (L > R) {
    cout << "Left" << endl;
  }
}

Measured memory_bytes: 256
import math

n = int(input())
town = [[0, 0]] * n
ans = 0
keiro = 0
keiro_count = 0

for i in range(n):
  x, y = map(int, input().split(' '))
  town[i] = [x, y]
# print(n)
# print(town)

for i in range(n):
  for j in range(i+1, n):
    town1 = town[i]
    town2 = town[j]
    x = (town2[0] - town1[0]) ** 2
    y = (town2[1] - town1[1]) ** 2
    d = math.sqrt( x + y )
    # print(d)
    keiro += (d * 2) * (n - 1)
    keiro_count += 2

# print('======================')
# print(keiro)
# print(keiro_count)

ans = keiro / keiro_count
print(round(ans, 10))

Measured memory_bytes: 38384
n, a, b, c = map(int,input().split())
l = [int(input()) for i in range(n)]
INF = 10 ** 9

def dfs(i, x, y, z):
    if i == n:
        cand = abs(a - x) + abs(b - y) + abs(c - z) - 30 if min(x, y, z) > 0 else INF
        return cand

    temp0 = dfs(i + 1, x + l[i], y, z) + 10
    temp1 = dfs(i + 1, x, y + l[i], z) + 10
    temp2 = dfs(i + 1, x, y, z + l[i]) + 10
    temp3 = dfs(i + 1, x, y, z)
    return min(temp0, temp1, temp2, temp3)

ans = dfs(0,0,0,0)
print(ans)

Measured memory_bytes: 3064
module abc129.abc129_c;

import std.algorithm;
import std.container;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;


void main() {
  const MOD = 1000000007;
  auto nm = readln.chomp.split.to!(int[]);
  auto n = nm[0];
  auto m = nm[1];
  
  auto a = make!(RedBlackTree!int);
  iota(m).each!(_ => a.insert(readln.chomp.to!int));

  int[int] dp = [
    0: 1,
    1: 1 in a ? 0 : 1,
  ];

  foreach (k; 2..(n + 1))
    dp[k] = k in a ? 0 : (dp[k - 1] + dp[k - 2]) % MOD;
  
  dp[n].writeln;
}


Measured memory_bytes: 11644
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,b,a) for(int i=b;i>=a;i--)
#define fori(a) for(auto i : a )
#define all(a) begin(a), end(a)
#define set(a,b) memset(a,b,sizeof(a))
#define sz(a) a.size()
#define pi 3.14159
#define ll long long
#define ull unsigned long long
#define pb push_back
#define PF push_front //deque
#define mp make_pair
#define pq priority_queue
#define mod 1000000007
#define f first
#define s second
#define pii pair< int, int >
#define vi vector<int>
#define vpii vector<pii>
#define debug(v) for(auto i:v) cout<<i<<" ";
#define tc int t; cin >> t; while(t--)

using namespace std;
string repeat(string s, int n) {
    string s1 = "";
    for (int i=0; i<n;i++)
        s1+=s;
    return s1;
}
string getString(char x) {
    string s(1, x);
    return s;
}

void optimizeIO(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}
int gcd(int a, int b){
    if (a == 0)  return b;
    return gcd(b % a, a);
}
void  solve(){
  int n,m,y,p;
  cin>>n>>m;
  vector<vector<pii>> v(n,vector<pii>());
  rep(i,0,m){
    cin>>p>>y;
    v[p-1].pb({y,i});
  }
  string ans[m];
  rep(i,0,n) sort(all(v[i]));
  rep(i,0,n){
    int idx=i+1;
    string s=to_string(idx);
    while(s.length()!=6) s="0"+s;
    // cout<<s<<endl;
    // cout<<v[i].size()<<endl;
    rep(j,0,v[i].size()){
      int idx1=j+1;
      // cout<<idx1<<endl;
      string h=to_string(idx1);
      while(h.length()!=6) h="0"+h;
      // cout<<h<<endl;
      ans[v[i][j].s]=s+h;
    }
  }
  rep(i,0,m) cout<<ans[i]<<endl;
}
int main(){
    optimizeIO();
    // tc
    { solve();
    }
}


Measured memory_bytes: 11856
local ior = io.input()
local h, w = ior:read("*n", "*n", "*l")
local map = {}
for i = 1, h * w do map[i] = 0 end
local str = ""

local function getidx(wid, hgt)
  return (hgt - 1) * w + wid
end

local tasks = {}
local tasknum = 0
local done = 0

for i = 1, h do
  str = ior:read()
  for j = 1, w do
    local idx = getidx(j, i)
    if(str:sub(j, j) == ".") then
      map[idx] = 3000
    else
      table.insert(tasks, idx)
      tasknum = tasknum + 1
    end
  end
end

local function walk(src, dst)
  if(map[src] + 1 < map[dst]) then
    map[dst] = map[src] + 1
    table.insert(tasks, dst)
    tasknum = tasknum + 1
  end
end

while(done < tasknum) do
  done = done + 1
  local curidx = tasks[done]
  if(w < curidx) then walk(curidx, curidx - w) end
  if(curidx <= w * (h - 1)) then walk(curidx, curidx + w) end
  if(w ~= 1 and curidx % w ~= 0) then walk(curidx, curidx + 1) end
  if(w ~= 1 and curidx % w ~= 1) then walk(curidx, curidx - 1) end
end
local max = 0
local mma = math.max
for i = 1, h * w do
  max = mma(max, map[i])
end
print(max)


Measured memory_bytes: 17660
#include <bits/stdc++.h>
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define pb push_back
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) FOR(i, 0, n)
#define ll long long
using namespace std;

const ll P = 1000000007;
int gcd(int a, int b) { return b != 0 ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }

int main()
{
  cout << fixed << setprecision(10);
  string N;
  cin >> N;
  N.at(5) = ' ';
  N.at(13) = ' ';
  cout << N << endl;
  return 0;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <math.h>
#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <algorithm>
#include <numeric>
#include <stdio.h>
#include <vector>
#include <map>
#include <queue>

using namespace std;
typedef long long ll;

#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)

int main() {

    ll N;
    string S;
    cin >> N >> S;
    ll out = 0;
    rep(i,1000){
        string str = to_string(i);
        if(str.size()==1) str = "00" + str;
        else if(str.size()==2) str = "0" +str;
        ll cnt = 0;
        rep(j,N){
            if(S[j]==str[cnt]){
                cnt++;
                if(cnt==3){
                    out++;
                    break;
                }
            }
        }
    }
    cout << out << endl;
    return 0;
}


Measured memory_bytes: 3716