akhauriyash/Code-Regression huggingface dataset:
l=list(map(int,input().split()))
participant=list(input())
passnum=l[1]+l[2]
b=0
for i in range(l[0]):
    if participant[i]=='a' and passnum>0:
        participant[i]='Yes'
        passnum-=1
    elif participant[i]=='b' and passnum>0 and b<l[2]:
            participant[i]='Yes'
            passnum-=1
            b+=1
    elif passnum==0:
        break
for i in range(l[0]):
    if participant[i]!='Yes':
        participant[i]='No'
for i in range(l[0]):
    print(participant[i])

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

int main() {
  string a,b;
  string kekka  = "No";
  int sum;
  
  cin >> a >> b;
  sum = stoi(a + b);
  
  for(int i = 1; i <= 1000; i++){
    if(sum == i * i) kekka = "Yes";
  }
  
  cout << kekka;
}


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

typedef long long ll;
ll MOD = 1000000007;

int main()
{
    int N, D, cnt = 0, ans = 0;
    cin >> N >> D;
    int X[11][11];
    vector <int> b;

    for (int i = 0; i < N; i++) {
        for (int j = 0; j < D; j++) {
            cin >> X[i][j];
        }
    }

    while (1) {
        if (cnt*cnt > 100000) break;
        b.push_back(cnt*cnt);
        cnt++;
    }


    for (int i = 0; i < N; i++) {
        for (int j = i+1; j < N; j++) {
            cnt = 0;
            for (int k = 0; k < D; k++) {
                int x = X[i][k] - X[j][k];
                cnt += x * x;
            }
            for (int l = 0; l < b.size(); l++) {
                if (cnt == b[l]) {
                    ans++;
                    break;
                }
            }
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define watch(x) cout << (#x) << " is " << (x) << endl
#define endl "\n"
typedef long long ll;
using namespace std;
int static fast = [](){
  ios::sync_with_stdio(false);
  cin.tie(0); cout.tie(0); return 0;
}();
// freopen("input.txt", "r", stdin);

int main() {
    int x;
  	cin >> x;
  	if (x >= 30) {
    	cout << "Yes" << endl;
    } else {
    	cout << "No" << endl;
    }
    return 0;
}


Measured memory_bytes: 3616
try:
    from fractions import gcd
except:
    from math import gcd
N = int(input())
A = list(map(int, input().split()))


def gcd_custom(a, b):
    if a == 0 or b == 0:
        return max(a, b)
    return gcd(a, b)


def get(n, change_dict):
    if n < 0 or N <= n:
        return 0
    if n in change_dict:
        return
    else:
        return A[n]


gcd_left = [0]  # i番目以下の最大公約数
gcd_tmp_val = 0
for i in range(N):
    gcd_tmp_val = gcd_custom(gcd_tmp_val, A[i])
    gcd_left.append(gcd_tmp_val)

gcd_right_reversed = [0]  # 右からi番目==(N-1-i)番目 の最大公約数
gcd_tmp_val = 0
for i in range(N - 1, -1, -1):
    gcd_tmp_val = gcd_custom(gcd_tmp_val, A[i])
    gcd_right_reversed.append(gcd_tmp_val)

ans = 1
for i in range(N):
    ans = max(ans,
              gcd_custom(gcd_left[i], gcd_right_reversed[N - 1 - i])
              )
print(ans)

Measured memory_bytes: 16124
#include <iostream>
using namespace std;
int main(void){
    char x;
    cin >> x;
    if(x=='T'){
        cout << "A" << endl;
    }else if(x=='A'){
        cout << "T" << endl;
    }else if(x=='C'){
        cout << "G" << endl;
    }else{
        cout << "C" << endl;
    }
}


Measured memory_bytes: 256
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <fstream>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <stack>
#include <vector>
using namespace std;
typedef long long ll;
int main(){
  int h,w,a,b;
  cin >> h >> w >> a >> b;
  
  vector<vector<int>> ans(h,vector<int>(w));

  for(int i = 0;i < h;i++){
    for(int j = 0;j < w;j++){
      if(i <= b-1){
        if(j <= a-1)ans[i][j] = 0;
        else ans[i][j] = 1;
      }
      else{
        if(j <= a-1)ans[i][j] = 1;
        else ans[i][j] = 0;
      }
    }
  }

  for(int i = 0;i < h;i++){
    for(int j = 0;j < w;j++){
      cout << ans[i][j];
    }
    cout << endl;
  }
}

Measured memory_bytes: 5120
import sys 
try:
	sys.stdin = open('Input.txt', 'r') 
	sys.stdout = open('Output.txt', 'w')
except:
	pass

input = sys.stdin.readline

def Buy(books,threshold):
	if len(books) == 0:
		for k in threshold:
			if k<x:
				return float('inf')
		else:
			return 0
			
	thresholdnew = threshold[:]
	for k in range(m):
		thresholdnew[k] += books[0][k+1]
	return min(Buy(books[1:],threshold),books[0][0]+Buy(books[1:],thresholdnew))

n,m,x = map(int,input().split())
books = []

for i in range(n):
	l = list(map(int,input().split()))
	books.append(l)
	threshold = [0]*m

ans = Buy(books,threshold)

if ans != float('inf'):
	print(ans)
else:
	print(-1)

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

using namespace std;

const int N = 1e4 + 3;
const int ma[] = { 0, 2, 5, 5, 4, 5, 6, 3, 7, 6 };
int f[N], a[10], m, n, trace[N];

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin >> n >> m;
	for (int i = 1; i <= m; ++i)
		cin >> a[i];
	sort(a + 1, a + 1 + m);
	f[0] = 0;
	for (int s = 1; s <= n; ++s) {
		f[s] = -1;
		for (int i = 1; i <= m; ++i)
			if (s - ma[a[i]] >= 0 && f[s - ma[a[i]]] >= 0) {
				if (f[s] <= f[s - ma[a[i]]] + 1) {
					f[s] = f[s - ma[a[i]]] + 1;
					trace[s] = a[i];
				}
			}
	}
	assert(f[n] > 0);
	string ans = "";
	while (n) {
		ans += to_string(trace[n]);
		n = n - ma[trace[n]];
	}
	printf("%s", ans.c_str());
	return 0;
}


Measured memory_bytes: 384
#include <stdio.h>
#include <iostream>
#include <string>
#include <stdlib.h>
#include<time.h>
#include<cmath>
#include<vector>
using namespace std;

int main(void)
{
	int n,x=0;
	string s;

	cin >> n >> s;

	int max=x;
	for (int i = 0; i < n; i++) {
		if (s[i] == 'I') {
			x++;
		}
		else if(s[i]=='D'){
			x--;
		}

		if (max < x) {
			max = x;
		}
	}

	cout << max;


	cout << endl;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long
#define all(aaa) aaa.begin(), aaa.end()

const int N = 1e5 + 5;
int a[N], b[N];

bool solve_slow(int banned, vector<int> &ans, vector<int> v) {
    sort(all(v));

    do {
        if (v[0] == banned)
            continue;

        bool ok = true;
        for (int i = 0; i + 1 < v.size(); i++) {
            if (a[v[i]] == v[i + 1]) {
                ok = false;
                break;
            }
        }
        if (ok) {
            ans.insert(ans.end(), all(v));
            return true;
        }

    } while (next_permutation(all(v)));

    return false;
}

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

    int n;
    cin >> n;

    set<pair<int, int>> st_p;
    set<int> st;

    for (int i = 0; i < n; i++) {
        st.insert(i);
    }

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

    for (int i = 0; i < n; i++) {
        st_p.insert({b[i], i});
    }

    vector<int> ans;
    int banned = -1;

    for (int i = 0; i + 3 < n; i++) {
        if (st_p.rbegin()->first == n - i - 1) {
            ans.push_back(st_p.rbegin()->second);
            st_p.erase(prev(st_p.end()));
            st.erase(ans.back());
        }
        else {
            auto it = st.begin();
            while (banned == *it)
                it++;
            ans.push_back(*it);
            st.erase(it);
        }
        banned = a[ans.back()];
        st_p.erase({b[a[ans.back()]], a[ans.back()]});
        b[a[ans.back()]]--;
        st_p.insert({b[a[ans.back()]], a[ans.back()]});
    }

    vector<int> v;

    for (const int &x : st) {
        v.push_back(x);
    }

    if (solve_slow(banned, ans, v)) {
        for (const int &x : ans) {
            cout << x + 1 << " ";
        }
    }
    else {
        cout << "-1";
    }

    return 0;
}

Measured memory_bytes: 11008
using static System.Math;
using System;

public class Hello
{
    public static void Main()
    {
        var n = int.Parse(Console.ReadLine().Trim());
        string[] line = Console.ReadLine().Trim().Split(' ');
        var a = Array.ConvertAll(line, int.Parse);
        var ans = getAns(a, n);
        Console.WriteLine(ans);
    }
    static long getAns (int[] a, int n)
    {
        var dp = new long[n];
        dp[1] = Abs(a[1] - a[0]);
        for (int i = 2; i < n; i++)
        {
            var w1 = dp[i - 1] + Abs(a[i] - a[i - 1]);
            var w2 = dp[i - 2] + Abs(a[i] - a[i - 2]);
            dp[i] = Min(w1, w2);
        }
        return dp[n - 1];
    }
}

Measured memory_bytes: 17248
require 'pp'
$DEBUG ? define_method(:dpp){|e|pp e} : define_method(:dpp){|e|}
# sumの追加
class Array
  define_method(:sum){self.inject(:+).to_i} unless method_defined?(:sum)
end

# 入力値を数値で返却する
def gets_i()
  gets.chomp.to_i
end
a, b, c, d, e = gets_i, gets_i, gets_i, gets_i, gets_i

a2, b2, c2, d2, e2 = [a, b, c, d, e].map{|i|
  # i.ceil(-1)
  if i % 10 != 0
    i + (10 - i % 10)
  else
    i
  end
}
dpp [a2, b2, c2, d2, e2]

max_diff = [a2-a, b2-b, c2-c, d2-d, e2-e].max

puts [a2, b2, c2, d2, e2].sum - max_diff

Measured memory_bytes: 2172
#include<cmath>
#include<iostream>
#include<algorithm>
#include <string>
#include <stdexcept>
using namespace std; 
int main(){
  char t[4];
 long long int a,b[120],c=0,d[120],e[120]; 
 	cin >>a;
  for(int i=0;i<a;i++){
   	cin >>b[i];
  }
    for(int i=0;i<a;i++){
   	cin >>d[i];
      e[i]=b[i]-d[i];
  }
    for(int i=0;i<a;i++){
  if(e[i]>0)c+=e[i];
  }
  cout <<c;
}

Measured memory_bytes: 256
package main

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

var sc = bufio.NewScanner(os.Stdin)
var dp [100020]int

func main() {
	scanInit()

	n := nextInt()
	h := make([]int, n)
	for i := 0; i < n; i++ {
		h[i] = nextInt()
	}

	dp[0] = 0
	dp[1] = abs(h[1] - h[0])
	for i := 2; i < n; i++ {
		hop := dp[i-1] + abs(h[i]-h[i-1])
		step := dp[i-2] + abs(h[i]-h[i-2])
		dp[i] = min(hop, step)
	}

	fmt.Println(dp[n-1])

}
func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}
func min(a, b int) int {
	if a > b {
		return b
	}
	return a
}

// ---- readfunc
func scanInit() {
	const cap = 200 * 1024 // default=64*1024
	var buf = make([]byte, cap)
	sc.Buffer(buf, cap)
	sc.Split(bufio.ScanWords)
	return
}
func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}
func nextStr() string {
	sc.Scan()
	return sc.Text()
}


Measured memory_bytes: 3964
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <list>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <bitset>
#include <random>
#include <complex>
#include <assert.h>

using namespace std;
typedef long long ll;
#define endl '\n'

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

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

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

	int N, K; cin >> N >> K;
	vector<int> v(N);
	for (int i = 0; i < N; i++) {
		cin >> v[i];
	}

	sort(v.begin(), v.end());

	int ans = 0;
	for (int i = 0; i < K; i++) {
		ans += v[i];
	}

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

Measured memory_bytes: 3156
#include<iostream>
#include<string>
#include<algorithm>

int main(){

    int N;std::cin >> N ;
    int A[200010];
    for(int i = 1; i <= N;i++){
        std::cin >> A[i];

    }
    
    int max = 0,semiMax = 0,maxNum = 0,semiMaxNum = 0;
    for(int i = 1; i <= N; i++){
        if(max < A[i]){
            semiMax = max;

            max = A[i];
            maxNum = i;
        }else if(semiMax < A[i]){
            semiMax = A[i];
        }
    }

    for(int i = 1; i <= N;i++){
        if(i == maxNum) std::cout << semiMax << std::endl;
        else std::cout << max << std::endl;
    }
}

Measured memory_bytes: 2432
#include<stdio.h>

int main(void){
  int a, i;
  int b = 0;
  
  scanf("%d", &a);
  
  for(i = 0; i <= a; i++){
    if((0 < i) && (i < 10)){
      b++;
    }
    else if((99 < i) && (i < 1000)){
      b++;
    }
    if((9999 < i) && (i < 100000)){
      b++;
    }
  }
  
  printf("%d\n", b);
  
  return 0;
}

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

typedef long long int ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pair<int, int> > vii;
#define rrep(i, m, n) for(int (i)=(m); (i)<(n);  (i)++)
#define erep(i, m, n) for(int (i)=(m); (i)<=(n); (i)++)
#define  rep(i, n)    for(int (i)=0; (i)<(n);  (i)++)
#define rrev(i, m, n) for(int (i)=(n)-1; (i)>=(m); (i)--)
#define erev(i, m, n) for(int (i)=(n); (i)>=(m); (i)--)
#define  rev(i, n)    for(int (i)=(n)-1; (i)>=0; (i)--)
#define vrep(i, c)    for(__typeof((c).begin())i=(c).begin(); i!=(c).end(); i++)
#define  ALL(v)       (v).begin(), (v).end()
#define mp            make_pair
#define pb            push_back
template<class T, class S> inline bool minup(T& m, S x){ return m>(T)x ? (m=(T)x, true) : false; }
template<class T, class S> inline bool maxup(T& m, S x){ return m<(T)x ? (m=(T)x, true) : false; }

const int    INF = 1000000000;
const ll     MOD = 1000000007LL;
const double EPS = 1E-12;

template<typename T> ostream& operator <<(ostream& r, const vector<T> t){vrep(v,t)r<<*v<<(v+1==t.end()?"":" ");return r;}
template<typename T> ostream& operator <<(ostream& r, const pair<vector<T>, int> p){int n=p.second;minup(n,p.first.size());rep(i,n-1)r<<p.first[i]<<' ';r<<p.first[n-1];return r;}
template<typename T> ostream& operator <<(ostream& r, const pair<T*, int> p){int n=p.second-1;rep(i,n)r<<p.first[i]<<' ';return r<<p.first[n];}
template<typename T, size_t S> ostream& operator <<(ostream& r, const T (&a)[S]){rep(i,S-1)r<<a[i]<<' ';return r<<a[S-1];}


int a[3];
int n;
string s;
int tmp;

int main()
{
  while((cin >> n) && n){
    rep(i, 3) a[i] = i + 1;
    int res = 1;
    rep(i, n){
      cin >> s;
      if(s == "North"){
        tmp = a[0];
        a[0] = a[1];
        a[1] = 7 - tmp;
      }
      else if(s == "East"){
        tmp = a[2];
        a[2] = a[0];
        a[0] = 7 - tmp;
      }
      else if(s == "West"){
        tmp = a[0];
        a[0] = a[2];
        a[2] = 7 - tmp;
      }
      else if(s == "South"){
        tmp = a[1];
        a[1] = a[0];
        a[0] = 7 - tmp;
      }
      else if(s == "Right"){
        tmp = a[1];
        a[1] = a[2];
        a[2] = 7 - tmp;
      }
      else if(s == "Left"){
        tmp = a[2];
        a[2] = a[1];
        a[1] = 7 - tmp;
      }
      res += a[0];
      //cout << a << endl;
   }
    cout << res << endl;
  }
  return 0;
}

Measured memory_bytes: 1208
from collections import Counter

n = int(input())
v = [int(vi) for vi in input().split()]

a = sorted(Counter(v[ ::2]).items(), key=lambda x: -x[1])
b = sorted(Counter(v[1::2]).items(), key=lambda x: -x[1])
def w(arr, index):
  arr = arr[index:] + arr[0:index]
  return sum(c for _, c in arr[1:])

if a[0][0] == b[0][0]:
  if len(a) == len(b) == 1:
    print(n // 2)
  else:
    print(min(w(a, 0) + w(b, 1), w(a, 1) + w(b, 0)))
else:
  print(w(a, 0) + w(b, 0))


Measured memory_bytes: 20692
#include<bits/stdc++.h>
using namespace std;
inline void rd(int &x){
  int k, m=0;
  x=0;
  for(;;){
    k = getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
inline void rd(double &x){
  scanf("%lf",&x);
}
inline int rd(char c[]){
  int i, sz=0;
  for(;;){
    i = getchar_unlocked();
    if(i!=' '&&i!='\n'&&i!='\r'&&i!='\t'&&i!=EOF){
      break;
    }
  }
  c[sz++] = i;
  for(;;){
    i = getchar_unlocked();
    if(i==' '||i=='\n'||i=='\r'||i=='\t'||i==EOF){
      break;
    }
    c[sz++] = i;
  }
  c[sz]='\0';
  return sz;
}
inline void wt_L(char a){
  putchar_unlocked(a);
}
inline void wt_L(double x){
  printf("%.15f",x);
}
int N;
double X;
char U[5];
int main(){
  double res=0;
  int Lj4PdHRW;
  rd(N);
  for(Lj4PdHRW=0;Lj4PdHRW<N;Lj4PdHRW++){
    rd(X);
    rd(U);
    if(U[0]=='J'){
      res += X;
    }
    else{
      res += 380000*X;
    }
  }
  wt_L(res);
  wt_L('\n');
  return 0;
}
// cLay varsion 20190715-1

// --- original code ---
// int N; double X; char U[5];
// {
//   double res = 0;
//   rd(N);
//   rep(N){
//     rd(X,U);
//     if(U[0]=='J') res += X;
//     else          res += 380000X;
//   }
//   wt(res);
// }


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

int H,W;

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

bool seen[51][51];
int board[51][51];

  void dfs(int h, int w) {
  seen[h][w] = true; 
  
  for (int dir = 0; dir < 8; ++dir) {
    int nw = w + dx[dir];
    int nh = h + dy[dir];  
    if (nw < 0 || nw >= W || nh < 0 || nh >= H) continue;
    if (seen[nh][nw]) continue; 
    if (board[nh][nw] == 1) dfs(nh,nw);
  }
} 

int main() {  
  cin >> W >> H;
  while (W >= 1 || H >= 1) {
    int ans =0;
    for (int i =0; i<H; i++) {
      for (int j =0; j<W; j++) {
        int tmp; cin >> tmp;
        board[i][j] = tmp;
      }
    }
    
    for (int i =0; i<H; i++) {
      for (int j =0; j<W; j++) {
        seen[i][j] = false;
      }
    }
  
    for (int i =0; i<H; i++) {
      for (int j =0; j<W; j++) {
        if (seen[i][j] == true || board[i][j] == 0) continue;
        dfs(i,j);
        ans++;
      }
    } 
    cout << ans << endl; 
    cin >> W >> H;
    for (int i =0; i<H; i++) {
      for (int j =0; j<W; j++) {
        board[i][j] = 0;
      }
    }
  }
}


Measured memory_bytes: 3216
import java.util.*;

public class Main {    
    
   public static void main(String[] args){
       
    Scanner sc = new Scanner(System.in);
    
    String A = sc.next();
    
    if(A.charAt(0) == 'a' || A.charAt(0) == 'i' || A.charAt(0) == 'u' || A.charAt(0) == 'e' || A.charAt(0) == 'o'){
        System.out.println("vowel");
    }else{
        System.out.println("consonant");        
    }
    
  }
}

Measured memory_bytes: 21844
#include<stdio.h>
int main()
{
	int n;
	int a[100010]={0};
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);
	}
	int j=0;
	int i=1;
	for(;;)
	{
		j++;
		int temp;
		if(a[i]==0)
		{
			printf("-1");
			return 0;
		}
		if(a[i]==2)
		break;
		temp=a[i];
		a[i]=0;
		i=temp;
		
	}
	printf("%d",j);
	return 0;
}

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

int main(){
    string S,K;
    cin >> S;
    for(int bit=0;bit< (1<<(S.size()-1));bit++){
        K = S[0];
        for(int i=0;i<S.size()-1;i++){
            if(bit & 1<<i) K+='+';
            else K+='-';
            K += S[i+1];
        }
        int answer = K[0] - '0';
        for(int i=1;i<K.size();i=i+2){
            if(K[i]=='+') answer += (K[i+1] - '0');
            else if(K[i]=='-') answer -= (K[i+1] - '0');
        }
        if(answer==7){
            cout << K << "=7" << endl;
            break;
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll ans;
const int maxn=100005;
int n,m,i,j,t,k,s,head[maxn],N,poi,cnt[5],edgnt,col[maxn];
struct Edge
{
	int nxt,aim,len;
}edge[maxn*2];
inline void add_edge(int x,int y,int z)
{
	edge[++N]=(Edge){head[x],y,z};
	head[x]=N;
}
bool dfs(int x)
{
	bool ret=1;++poi;
	cnt[col[x]]++;
	for (int i=head[x];i;i=edge[i].nxt)
	{
		edgnt+=(edge[i].len==1);
		int des=edge[i].aim;
		if (col[des]!=-1)
		{
			if (col[des]==(col[x]+edge[i].len+3)%3) continue;
			ret=0;continue;
		}
		col[des]=(col[x]+edge[i].len+3)%3;
		if (!dfs(des)) ret=0;
	}
	return ret;
}
void work(int x)
{
	poi=0;col[x]=0;edgnt=0;
	cnt[0]=cnt[1]=cnt[2]=0;
	if (!dfs(x))
	{
		ans+=1ll*poi*poi;
		return;
	}
	if (cnt[0]&&cnt[1]&&cnt[2])
	 ans+=1ll*cnt[0]*cnt[1]+1ll*cnt[0]*cnt[2]+1ll*cnt[1]*cnt[2];
	else ans+=1ll*edgnt;
}
int main()
{
	scanf("%d%d",&n,&m);
	for (i=1;i<=m;++i)
	{
		scanf("%d%d",&t,&k);
		add_edge(t,k,1);add_edge(k,t,-1);
	}
	memset(col,-1,sizeof(col));
	ans=0;
	for (i=1;i<=n;++i) if (col[i]==-1)
	{
		work(i);
	}
	printf("%lld\n",ans);
	return 0;
}

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

//#define int long long
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<n;++i)
#define exrep(i, a, b) for(ll i = a; i < b; i++)
#define out(x) cout << x << endl
#define EPS (1e-7)
#define gearup ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<bool> > vvb;
typedef vector<vector<double> > vvd;
typedef vector<vector<string> > vvs;
typedef vector<ll> vl;
typedef vector<vector<ll> > vvl;
typedef vector<vector<vector<ll> > > vvvl;
ll MOD = 1000000007;
const long long L_INF = 1LL << 60;
const int INF = 2147483647; // 2^31-1
const double PI = acos(-1);
//cout<<fixed<<setprecision(10);

template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
template<class T> void debug(T v){rep(i,v.size()) cout<<v[i]<<" ";cout<<endl;}
const ll dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};

signed main()
{   
    gearup;
    string s;cin >> s;
    int n = s.size();
    vvl dp(n+10,vl(13,0));
    dp[0][0] = 1;
    rep(i,n){
        rep(j,13){
            if(s[i] == '?'){
                rep(k,10){
                    int num = (10*j+k)%13;
                    dp[i+1][num] += dp[i][j];
                    dp[i+1][num] %= MOD;
                }
            }
            else{
                int d = s[i] - '0';
                int num = (10*j+d)%13;
                dp[i+1][num] += dp[i][j];
                dp[i+1][num] %= MOD;
            }
        }
    }
    out(dp[n][5]);
}


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

#define rep(i,n) for(int i=0;i<n;i++)
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define each(it,v) for(auto &it : v)
#define all(v) (v).begin(),(v).end()
#define mod 1e9+7

using namespace std;
using vi = vector<int>;
using vl = vector<long>;
using P = pair<int,int>;

main()
{
        int n; cin>>n;
        string s=to_string(n);
        int sum=0;
        each(it,s)sum+=it-'0';
        if(n%sum==0)cout<<"Yes"<<endl;
        else cout<<"No"<<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<math.h>
#include<string.h>
#include<vector>
#include<algorithm>
#include<iomanip>
using namespace std;

int main(){
	string s;
	cin >> s;
	string t="FESTIVAL";
	for(int i=0;i<s.size()-t.size();i++){
		cout << s[i];
	}
	cout << endl;
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
  string s;
  getline(cin,s);
  for(int i=0; i<s.size(); i++){
    if(i+4>=s.size()) continue;
    if(s[i] == 'a' && s[i+1] == 'p' && s[i+2] == 'p' && s[i+3] == 'l' && s[i+4] == 'e'){
      s[i] = 'p'; s[i+1] = 'e'; s[i+2] = 'a'; s[i+3] = 'c'; s[i+4] = 'h';
    }
    else if(s[i] == 'p' && s[i+1] == 'e' && s[i+2] == 'a' && s[i+3] == 'c' && s[i+4] == 'h'){
      s[i] = 'a'; s[i+1] = 'p'; s[i+2] = 'p'; s[i+3] = 'l'; s[i+4] = 'e';
    }
  }
  cout <<s<<endl;
  return 0;
}

Measured memory_bytes: 1172
#include <bits/stdc++.h>
#include <algorithm>
using namespace std;
int main(){
	int N; cin >> N; 
	int L[2010] = {}; 
	for(int i = 0; i < N; i++) cin >> L[i]; 
	L[N] = 114514; 
	sort(L, L+N+1); 
	long long int ans = 0; 
	for(int i = 0; i < N-1; i++){
		for(int j = i+1; j < N; j++){
			int index = lower_bound(L, L+N+1, L[i] + L[j]) - L; 
			ans += (long long) index - j - 1; 
		}
	}
	cout << ans << endl; 
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,k,ans=1e8;cin>>n>>k;
  for(int i=0;i<n;i++){
    int x=1,j=0;
    for(;j<i;j++){
      x*=2;
    }
    for(;j<n;j++){
      x+=k;
    }
    ans=min(ans,x);
  }
  for(int i=0;i<n;i++){
    int x=1,j=0;
    for(;j<i;j++){
      x+=k;
    }
    for(;j<n;j++){
      x*=2;
    }
    ans=min(ans,x);
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(ll i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(ll i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(ll i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) ((ll)(x).size())
#define len(x) ((ll)(x).length())
#define endl "\n"

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    // ifstream in("input.txt");
    // cin.rdbuf(in.rdbuf());
    string s, t;
    cin >> s >> t;
    ll ans = 0;
    rep(i, 3) {
        if (s[i] == t[i]) ans++;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<string>
#include<map>
#include<set>
#include<tuple>
#include<cmath>
#include<iomanip>


using namespace std;
typedef long long ll;
typedef vector<ll> v;
typedef vector<vector<ll>> vv;


#define MOD 1000000007
#define INF 1001001001
#define MIN -1001001001
#define rep(i,k,N) for(int i=k;i<N;i++)
#define MP make_pair
#define MT make_tuple //tie,make_tuple は別物
#define PB push_back
#define PF push_front
#define all(x) (x).begin(),(x).end()


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

ll gcd(ll x,ll y){
    while(y > 0){
        ll tmp = y;
        y = x % y;
        x = tmp;
    }
    return x;
}

ll lcm(ll x, ll y){
    return x / gcd(x,y) * y;
}
ll PowMod(ll N,ll P,ll M){
    ll ans = 1;
    while(P >= 1){
        if(P % 2)ans = ans * N % M;
        N = N*N %M;
        P /= 2;
    }
    ans %= M;
    return ans;
}

int main(){
    map<pair<ll,ll>,ll> m;
    ll N;
    cin>>N;
    v A(N),B(N);
    vector<pair<ll,ll>> d;
    map<pair<ll,ll>,bool> ok;
    ll zeros = 0,a0 = 0,b0 = 0;

    rep(i,0,N){
        cin>>A[i]>>B[i];
        if(A[i] == 0 && B[i] == 0){
            zeros++;
            continue;
        }
        else if(A[i] == 0){
            a0++;
            continue;
        }
        else if(B[i] == 0){
            b0++;
            continue;
        }

        ll x = gcd(abs(A[i]),abs(B[i]));
        A[i] /=x;
        B[i] /=x;
        if(A[i]<0){
            A[i] *= -1;
            B[i] *= -1;
        }
        //cout<<A[i] <<" "<<B[i]<<endl;
        m[MP(A[i],B[i])]++;
        d.PB(MP(A[i],B[i]));
    }
    ll ans = 1;
        for(pair<ll,ll> now : d){
            pair<ll,ll> now2;
            if(now.second < 0){
                now2 = MP(now.second * -1, now.first);
            }
            else{
                now2 = MP(now.second, now.first*-1);
            }
            if(ok[now] == false){
                ok[now] = true;
                ok[now2] = true;
                ans *= (PowMod(2,m[now],MOD)+PowMod(2,m[now2],MOD)-1);
                ans %=MOD;
                //cout<<now.first<<" "<<now.second<<" ";
                //cout<<m[now]<<" "<<m[now2]<<endl;
            }
        }
    ans*= (PowMod(2,a0,MOD)+PowMod(2,b0,MOD)-1);
    if(zeros > 0)ans +=zeros;
    ans--;
    ans%=MOD;
    while(ans < 0)ans += MOD;
    cout<<ans;
    return 0;
}

Measured memory_bytes: 59304
#include <iostream>
#include <fstream>
#include <string>
#include <cmath>
#include <vector>
#include <algorithm>
#include <functional>
#include <cstdio>
#include <cstdlib>
#include <iomanip>
#include <cctype>
#include <bits/stdc++.h>
#include <queue>

using namespace std;
// for loop
#define F(i, L, R) for(long i = L; i < R; i++)
#define FE(i, L, R) for(long i = L; i <= R; i++)
// for (reversed)
#define FR(i, L, R) for(long i = L; i > R; i--)
#define FRE(i, L, R) for(long i = L; i >= R; i--)

// data types
#define Int long
#define ul unsigned long
#define ll long long
#define ull unsigned long long
#define ui unsigned int
#define us unsigned shoft

// vectors
typedef vector<int> vi;
typedef vector<long> vl;
typedef vector<long long> vll;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int, int> ii;
#define ALL(c) (c).begin(),(c).end()
#define last(vec) vec.size()-1
#define lastEle(vec) vec[last(vec)]
#define pb push_back
#define InputV(a, n) F(i,0,n){long l; cin >> l; a.pb(l);}

// debug
#define DBG(vari) cerr<<#vari<<" = "<<(vari)<<endl;
#define printA(a, L, R) FE(i, L, R) cout << a[i] << (i==R?'\n':' ')
#define printAF(a, L) printA(a, 0, L-1)
#define printV(a) printA(a, 0, a.size()-1)

// utils
#define char2int(c) (c-'0')
#define bit(x, i) (x&(1<<i))
#define space ' '
#define PI 3.14159265358979323


#define TST 0

int main() {
#if TST==1
    ifstream in ("input.txt");
    cin.rdbuf(in.rdbuf());
#endif
    ull n;
    cin >> n;
    string ans = "";
    while(n > 0){
        if(n%26 == 0){
            ans = 'z' + ans;
            n = n-26;
            n = n/26;
            continue;
        }else{
            char nextchar = 'a' + (n%26 - 1);
            ans = nextchar + ans;
        }
        n = n - n%26;
        n = n/26;
    }
    cout << ans << endl;

#if TST==1

#endif
}



Measured memory_bytes: 3632
n = int(input())
dic = []
for i in range(n):
    inp = input().split()
    dic.append([inp[0], 100-int(inp[1]), i+1])
    temp = ''
    for j in range(10):
        try:
            temp += str(ord(dic[i][0][j])-80)
        except:
            temp += '00'
    dic[i][0] = int(temp)
dic = sorted(dic)
for i in range(n):
    print(dic[i][2])

Measured memory_bytes: 3064
import sys
input = sys.stdin.readline
'''
n, m = map(int, input().split())
n = int(input())
A = list(map(int, input().split()))
for test in range(int(input())):
'''
inf = 100000000000000000  # 1e17

s = input().strip()
if s[2] == s[3] and s[4] == s[5]:
    print("Yes")
else:
    print("No")


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

//Compiler version g++ 6.3.0

int main()
{
    int k,num_pairs; 
    cin>> k;
    if(k%2==0){
    num_pairs =(k/2)*(k/2);
    }else{
    num_pairs =((k-1)/2)*(((k-1)/2)+1);
    }
    
    cout << num_pairs ;
    return 0; 
}

Measured memory_bytes: 3600
// D.

#include <iostream>
#include <sstream>
#include <algorithm>
#include <vector>

using namespace std;

typedef long long LL;

int main(int argc, char* argv[]) {
#ifdef _MSC_VER
	while (true)
#endif
	{
		LL h = -1, ans = 0, d = 1;
		cin >> h;
		if (h < 0) return 0;
		while (h > 1) {
			ans += d;
			h /= 2;
			d *= 2;
		}
		ans += d;
		cout << ans << endl;
	}
	return 0;
}


Measured memory_bytes: 256
// Aizu 2272: Cicada
// 2017.9.22 bal4u@uu

#include <stdio.h>
#define min(a,b) ((a)<=(b)?(a):(b))

char map[52][52];
int dp[52][52];

int main()
{
	int h, w, r, c;

	scanf("%d%d", &h, &w);
	for (r = 0; r < h; r++) scanf("%s", map[r]);
	dp[0][0] = map[0][0]-'0';
	for (c = 1; c < w; c++) dp[0][c] = dp[0][c-1] + (map[0][c]-'0');
	for (r = 1; r < h; r++) dp[r][0] = dp[r-1][0] + (map[r][0]-'0');
	for (r = 1; r < h; r++) for (c = 1; c < w; c++) 
		dp[r][c] = min(dp[r-1][c], dp[r][c-1]) + (map[r][c]-'0');
	printf("%d\n", dp[h-1][w-1]);
	return 0;
}

Measured memory_bytes: 1812
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner kb = new Scanner(System.in);
		double l = kb.nextDouble();
//		double k1 = 1;
//		double k2 = 1;
//		double k3 = l-2;
//		double sum = k1 * k2 * k3;
//		// System.out.println(sum);
//		while (k1 <= l/3+1) {
//			k2 = k1;
//			k3 = l - k1 - k2;
//			while (k2 <= k3) {
//				double sum2 = k1 * k2 * k3;
//				if (sum < sum2)
//					sum = sum2;
//				k2 += 1;
//				k3 -= 1;
//			}
//			k1 += 1;
//		}
//		System.out.println(sum);
		double m = l/3;
		double n =l/3;
		l=l-m-n;
		System.out.println(l*m*n);
		kb.close();

	}
}


Measured memory_bytes: 23252
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <iostream>
#include <sstream>
#include <functional>
#include <map>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <stack>
#include <deque>
#include <set>
#include <list>
#include <numeric>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> P;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const ll INF = 1LL<<29;
const ll mod = 1e9+7;
#define rep(i,n) for(int (i)=0;(i)<(ll)(n);++(i))
#define repd(i,n,d) for(ll (i)=0;(i)<(ll)(n);(i)+=(d))
#define all(v) (v).begin(), (v).end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))
#define mset(m,v) memset((m),(v),sizeof(m))
#define chmin(X,Y) ((X)>(Y)?X=(Y),true:false)
#define chmax(X,Y) ((X)<(Y)?X=(Y),true:false)
#define fst first
#define snd second
#define UNIQUE(x) (x).erase(unique(all(x)),(x).end())
template<class T> ostream &operator<<(ostream &os, const vector<T> &v){int n=v.size();rep(i,n)os<<v[i]<<(i==n-1?"":" ");return os;}

int main(){
	ll a[3];
	cin>>a[0]>>a[1]>>a[2];
	sort(a, a+3);
	ll res = 0;
	while(true){
		int b[3] = {};
		bool br = false;
		rep(i, 3) if(a[i]%2) br = true;
		if(br) break;
		res++;
		rep(i, 3) b[i] = (a[(i+1)%3]+a[(i+2)%3])/2;
		sort(b, b+3);
		bool f = false;
		rep(i, 3) if(a[i]!=b[i]) f = true;
		if(!f){
			res = -1;
			break;
		}
		//rep(i, 3) cerr<<a[i]<<" "; cerr<<endl;
		//rep(i, 3) cerr<<b[i]<<" "; cerr<<endl;
		rep(i, 3) a[i] = b[i];
	}
	cout<<res<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); i++)
#define repd(i,a,b) for (int i = (a); i < (b); i++)
#define INF LLONG_MAX
typedef long long ll;
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; }

int main(void)
{
  int N;
	cin >> N;
	string S;
	cin >> S;
	string A = S.substr(0, N/2);
	string B = S.substr(N/2, N);
	if(A==B) cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC094C
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = int.Parse(Console.ReadLine());
            var Xi = Console.ReadLine().Split().Select(int.Parse).ToArray();

            var Yi = Xi.OrderBy(x => x).ToArray();
            int center_min = Yi[N / 2 - 1];
            int center_max = Yi[N / 2];

            for (int i = 0; i < N; i++)
            {
                if (center_min == center_max) Console.WriteLine(center_min);
                else if (Xi[i] <= center_min) Console.WriteLine(center_max);
                else if (Xi[i] >= center_max) Console.WriteLine(center_min);
            }

            Console.ReadKey();
        }
    }
}


Measured memory_bytes: 41104
import java.util.Scanner;

public class Main{
	public static char[] s;
	public static void main(String[] args){
		Scanner in = new Scanner(System.in);
		while(true){
			s = in.next().toCharArray();
			if(s[0] == '.') break;
			idx = 0;
			char[] res = cipher().toCharArray();
			for(int i=0; i<res.length; i++){
				if(res[i] == '?') res[i] = 'A';
			}
			System.out.println(String.valueOf(res));
		}
	}
	
	public static int idx;
	public static String cipher(){
		if(idx == s.length || s[idx] == ']') return "";
		String next;
		String res = "";
		while((next = string()).length() > 0){
			res += next;
		}
		return res;
	}
	
	public static String string(){
		if(idx == s.length || s[idx] == ']') return "";
		if(s[idx] == '['){
			idx++;
			char[] tmp = cipher().toCharArray();
			char[] tmp2 = new char[tmp.length];
			for(int i=0; i<tmp.length; i++){
				tmp2[i] = tmp[tmp.length-1-i];
			}
			idx++;
			return String.valueOf(tmp2);
		}
		return letter()+"";
	}
	
	public static char letter(){
		if(s[idx] == '+'){
			idx++;
			char res = letter();
			return res=='?' ? res : (char)((res+1-'A')%26+'A');
		}else if(s[idx] == '-'){
			idx++;
			char res = letter();
			return res=='?' ? res : (char)((res-1+26-'A')%26+'A');
		}
		return s[idx++];
	}
}

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

int main(){
	string s;
  cin>>s;
  int a[2]={0};
  for(int i=0;i<s.length();i++){
  	a[s[i]-'A']++;
  }
  if(a[0] && a[1])
    cout<<"Yes"<<endl;
  else
    cout<<"No"<<endl;

    return 0;
}

Measured memory_bytes: 256
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines

def main():
    N = int(readline())
    S = readline().strip()

    ans = 0
    for p in range(1000):
        pattern = str(p).zfill(3)
        key = 0
        cnt = 0
        for n in pattern:
            for i in range(key,N):
                if S[i] == n:
                    key = i+1
                    cnt += 1
                    break
        if cnt == 3:
            ans += 1
    
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 41060
/*
* Created by: WeirdBugsButOkay
*/

#include <bits/stdc++.h>

#define int long long
#define ld long double
#define ff first
#define ss second

using namespace std;

const int MAX = 1e7 + 1;
int factor[MAX];

void generatePrimeFactors() 
{ 
    factor[1] = 1; 
  
    // Initializes all the positions with their value. 
    for (int i = 2; i < MAX; i++) 
        factor[i] = i; 
  
    // Initializes all multiples of 2 with 2 
    for (int i = 4; i < MAX; i += 2) 
        factor[i] = 2; 
  
    // A modified version of Sieve of Eratosthenes to 
    // store the smallest prime factor that divides 
    // every number. 
    for (int i = 3; i * i < MAX; i++) { 
        // check if it has no prime factor. 
        if (factor[i] == i) { 
            // Initializes of j starting from i*i 
            for (int j = i * i; j < MAX; j += i) { 
                // if it has no prime factor before, then 
                // stores the smallest prime divisor 
                if (factor[j] == j) 
                    factor[j] = i; 
            } 
        } 
    } 
} 
  
// function to calculate number of factors 
int calculateNoOFactors(int n) 
{ 
    if (n == 1) 
        return 1; 
  
    int ans = 1; 
  
    // stores the smallest prime number 
    // that divides n 
    int dup = factor[n]; 
  
    // stores the count of number of times 
    // a prime number divides n. 
    int c = 1; 
  
    // reduces to the next number after prime 
    // factorization of n 
    int j = n / factor[n]; 
  
    // false when prime factorization is done 
    while (j != 1) { 
        // if the same prime number is dividing n, 
        // then we increase the count 
        if (factor[j] == dup) 
            c += 1; 
  
        /* if its a new prime factor that is factorizing n,  
           then we again set c=1 and change dup to the new  
           prime factor, and apply the formula explained  
           above. */
        else { 
            dup = factor[j]; 
            ans = ans * (c + 1); 
            c = 1; 
        } 
  
        // prime factorizes a number 
        j = j / factor[j]; 
    } 
  
    // for the last prime factor 
    ans = ans * (c + 1); 
  
    return ans; 
} 

void solve()
{
    int n;
    cin >> n;
    generatePrimeFactors();
    int ans = 0;
    for(int i = 1; i <= n; i++)
        ans += i * calculateNoOFactors(i);
    cout << ans << endl;
}

signed main()
{
    int q = 1;
    //scanf("%d", &q);
    for(int i = 1; i <= q; i++)
    {
        solve();
    }
    return 0;
}

Measured memory_bytes: 81728
using System;
using System.Linq;

namespace AtCoder.Contests.Abc176
{
    public class MultipleOf9
    {
        public static void Main()
        {
            string input = Console.ReadLine();

            if (String.IsNullOrEmpty(input)) { return; }

            int sum = input.Select(x => Int32.Parse(x.ToString())).Sum();

            Console.WriteLine((sum % 9 == 0) ? "Yes" : "No");
        }
    }
}


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

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

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

typedef long long ll;

void solve(long long N, std::vector<long long> x, std::vector<long long> y)
{
    double S = 0;
    int count = 0;
    vector<int> a(N);
    rep(i, N) { a[i] = i; }

    do
    {
        count++;
        double tmp = 0;
        for (int i = 1; i < N; i++)
        {
            ll x0 = x[a[i - 1]];
            ll y0 = y[a[i - 1]];
            ll x1 = x[a[i]];
            ll y1 = y[a[i]];
            tmp += sqrt(pow((x0 - x1), 2) + pow((y0 - y1), 2));
        }
        S += tmp;
    } while (next_permutation(a.begin(), a.end()));
    printf("%.10lf\n", S / count);
}

int main()
{
    long long N;
    scanf("%lld", &N);
    std::vector<long long> x(N);
    std::vector<long long> y(N);
    for (int i = 0; i < N; i++)
    {
        scanf("%lld", &x[i]);
        scanf("%lld", &y[i]);
    }
    solve(N, std::move(x), std::move(y));
    return 0;
}


Measured memory_bytes: 256
//#include <iostream>
//#include <algorithm>
//#include <vector>
//using namespace std;
//
//int nCnt=0;
//
//
//void insertionSort(int nIn[],int nNum,int nG)
//{
//	int nMin=0;
//	int j=0;
//	for(int i=nG;i<=nNum-1;++i)
//	{
//		nMin=nIn[i];
//		j=i-nG;
//		while(j>=0 && nIn[j]>nMin)
//		{
//			nIn[j+nG]=nIn[j];
//			j-=nG;
//			nCnt++;
//		}
//		nIn[j+nG]=nMin;
//	}
//}
//
//
//void shellsort(int nIn[],int nNum,vector<int>& vecG)
//{
//	for(int i=1;i<=nNum;)
//	{
//		vecG.push_back(i);
//		i=i*3+1;
//	}
//	cout<<vecG.size()<<endl;
//	for(int i=vecG.size()-1;i>=0;i--)
//	{
//		cout<<vecG[i];
//		if (i!=0)
//		{
//			cout<<" ";
//		}
//	}
//	cout<<endl;
//	for(int i=vecG.size()-1;i>=0;--i)
//	{
//		insertionSort(nIn,nNum,vecG[i]);
//	}
//	cout<<nCnt<<endl;
//}
//
//
//int main()
//{
//	int nNum=0;
//	cin>>nNum;
//	int nIn[100]={0};
//	for(int i=0;i<nNum;++i)
//	{
//		cin>>nIn[i];
//	}
//	vector<int> vecG;
//	shellsort(nIn,nNum,vecG);
//	for(int i=0;i< nNum;++i)
//	{
//		cout<<nIn[i]<<endl;
//	}
//	system("pause");
//	return 0;
//}

#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;

int nCnt=0;

void insertionSort(int nIn[],int nNum,int nG)
{
	int nMin=0;
	int j=0;
	for(int i=nG;i<=nNum-1;++i)
	{
		nMin=nIn[i];
		j=i-nG;
		while(j>=0 && nIn[j]>nMin)
		{
			nIn[j+nG]=nIn[j];
			j-=nG;
			nCnt++;
		}
		nIn[j+nG]=nMin;
	}
}

void shellsort(int nIn[],int nNum,vector<int>& vecG)
{
	for(int i=1;i<=nNum;)
	{
		vecG.push_back(i);
		i=i*3+1;
	}
	cout<<vecG.size()<<endl;
	for(int i=vecG.size()-1;i>=0;i--)
	{
		cout<<vecG[i];
		if (i!=0)
		{
			cout<<" ";
		}
	}
	cout<<endl;
	for(int i=vecG.size()-1;i>=0;--i)
	{
		insertionSort(nIn,nNum,vecG[i]);
	}
	cout<<nCnt<<endl;
}

int main()
{
	int nNum=0;
	cin>>nNum;
	int nIn[1000000]={0};
	for(int i=0;i<nNum;++i)
	{
		cin>>nIn[i];
	}
	vector<int> vecG;
	shellsort(nIn,nNum,vecG);
	for(int i=0;i< nNum;++i)
	{
		cout<<nIn[i]<<endl;
	}
	return 0;
}


Measured memory_bytes: 7060
#include <cstdlib>
#include <algorithm>
#include <iostream>
#include <vector>


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

  int n;
  std::cin >> n;
  std::vector<int> as(n);
  for (auto&& a : as) {
    std::cin >> a;
  }
  auto mm = std::minmax_element(std::cbegin(as), std::cend(as));
  std::cout << (*mm.second - *mm.first) << std::endl;

  return EXIT_SUCCESS;
}


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

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define ALL(x) (x).begin(), (x).end()

typedef long long ll;
typedef long double ld;

const int INF = 1e9;
const ld EPS = 1e-8;

int main(){
  int R, G;
  cin >> R >> G;
  int ret = 2 * G - R;
  cout << ret << endl;
  return 0;
}



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

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


Measured memory_bytes: 3132
#include <iostream>
#include <cmath>

using namespace std;

typedef long long ll;

ll calc(ll a) {
	ll ans = 0;

	//i桁目の1の個数の偶奇を判定
	for (int i = 0; i < 41; i++) {
		ll loop = 1LL << (i + 1);
		ll cnt = ((a+1) / loop) * (loop / 2); //周期内の1の個数

		//周期に満たない部分の１の個数
		cnt += max(0LL,(a+1) % loop - loop / 2);

		if (cnt % 2 == 1) ans += 1LL << i;
	}
	return ans;
}

int main() {
	ll A, B;

	cin >> A >> B;

	ll ans = calc(B) ^ calc(A - 1);
	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 < n; ++i)
#define stl_rep(itr, x) for (auto itr = x.begin(); itr != x.end(); ++itr)
#define stl_repr(itr, x) for (auto itr = x.rbegin(); itr != x.rend(); ++itr)
#define all(x) x.begin(), x.end()
#define allr(x) x.rbegin(), x.rend()

using llong = long long int;

const static int MOD = 1000000000 + 7;
const static int inf = INT_MAX / 2;
const static llong INF = 1LL << 31;
const static int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

int main (int argc, char *argv[]) {
    cin.tie(0);
    ios::sync_with_stdio(false);

    int n;
    cin >> n;
    vector<llong> A(n + 1), B(n);
    rep(i, n + 1) cin >> A[i];
    rep(i, n) cin >> B[i];

    llong ans = 0;
    rep(i, n) {
        ans += min(A[i], B[i]);
        if (B[i] > A[i]) {
            llong tmp = A[i + 1];
            ans += abs(max(0LL, A[i + 1] - (B[i] - A[i])) - A[i + 1]);
            A[i + 1] = max(0LL, A[i + 1] - (B[i] - A[i]));
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1792
//include for verify
#include<map>
#include<set>
#include<ctime>
#include<cstdlib>
#include<cassert>
#include<iostream>
#include<climits>
using namespace std;
 
const int N = (1<<20);//number of element
const int M = 2*N;//required memory 
const int MAX_VALUE=INT_MAX;//maximum possible value;
int segt[M];//init with MAX_VALUE
int inp[N];
 
void update(int value,int pos,int n){
  int index=n-1+pos;
  segt[index]=value;//[pos,pos]
  while(index>0){
    index=(index-1)/2;
    segt[index]=segt[index*2+1]+segt[index*2+2];
  }
}
 
//children of now
//left now*2+1
//right now*2+2
//find[ql,qr] from [l,r] (definition of l and r is different from ant books)
int query(const int l,const int r,const int index,int q){
  if (l == r && segt[index] == q){
    return l;
  }
  int left=index*2+1,right=index*2+2;
  int midr=(l+r)/2,midl=midr+1;
  if (q <= segt[left])return query(l,midr,left,q);
  else if (q > segt[left])return query(midl,r,right,q-segt[left]);
  assert(false);
}
//end of library
 
void init(int n){
  for(int i=0;i<n;i++)segt[i]=0;
  for(int i=0;i<n;i++)update(0,i,n);
}

void del(int n,int i,map<int,int> &M){
  int pos=query(0,n-1,0,i);
  update(0,pos,n);
  M.erase(inp[pos]);
}

void insert(int n,int i,const int lim,map<int,int> &M){
  update(1,i,n);
  if (segt[0] == lim+1)del(n,1,M);
}

int getn(int n){
  for(int i=0;;i++)if ((1<<i) > n)return (1<<i);
}

main(){
  int q,lim;
  while(cin>>q>>lim){
    if (q == 0 && lim == 0)break;
    int p=0;
    map<int,int> M;
    int n=getn(q);
    init(n);
    for(int i=0;i<q;i++){
      int inq,x;
      cin>>inq>>x;
      if (inq == 0){
	if (M.find(x) != M.end()){
	  assert(false);
	  cout <<"Error 0" << endl;
	}else {
	  M[x]=p;
	  inp[p]=x;
	  insert(n,p,lim,M);
	  p++;
	}
      }else if (inq == 1){
	if (x > (int)M.size()){
	  assert(false);
	  cout <<"Error 1" << endl;
	}else {
	  del(n,x,M);
	}
      }else if (inq == 2){
	if (x > (int)M.size()){
	  assert(false);
	  cout <<"Error 2" << endl;
	}else {
	  int index=query(0,n-1,0,x);
	  cout << inp[index] << endl;
	}
      }else if (inq == 3){
	if (M.find(x) == M.end()){
	  assert(false);
	  cout <<"Error 3" << endl;
	}else {
	  int pos=M[x];
	  M.erase(x);
	  update(0,pos,n);
	}
      }else assert(false);
    }
    cout<<"end" << endl;
  }
  return 0;
}

Measured memory_bytes: 8620
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, s, n) for (int i = (s); i < (int)(n); i++)
#define INF 100000000

using namespace std;

int main() {
   vector<int> v(3); 
   rep(i,3)
   cin >> v[i];
   sort(v.begin(),v.end()); 
   if(v[0]==5&&v[1]==5&&v[2]==7)
   cout << "YES" << endl;
   else 
   cout << "NO" << endl;
}

Measured memory_bytes: 256