akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
const ull mod = 1e9 + 7;
#define REP(i,n) for(int i=0;i<(int)n;++i)

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

template<class S, class T> ostream& operator << (ostream& os, const pair<S, T> v){
  os << "(" << v.first << ", " << v.second << ")"; return os;
}
template<class T> ostream& operator << (ostream& os, const vector<T> v){
  for(int i = 0; i < v.size(); i++){if(i > 0){os << " ";} os << v[i];} return os;
}
template<class T> ostream& operator << (ostream& os, const vector<vector<T>> v){
  for(int i = 0; i < v.size(); i++){if(i > 0){os << endl;} os << v[i];} return os;
}

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

    ll N, K;
    string S;
    cin >> N >> K >> S;
    ll a=0, b=0, c=0;
    REP(i, N-1){
    	if(S[i]==S[i+1]) a++;
    	if(S[i]=='L' && S[i+1]=='R') b++;
    	if(S[i]=='R' && S[i+1]=='L') c++;
    }
    ll dabu = min(b, c);
    ll res = a + 2*min(K, dabu);
    K -= dabu;
    if(K>0) res += K;
    res = min(res, N-1);
    cout << res << endl;
    return 0;
}

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

 int main()
 {
     int n;
     cin >> n;
     int a[100000+5];

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


     }

     for(int i = 0;i < n; i++)
     {
         if(i) cout << " ";
         cout << a[i];
     }

     cout << endl;
     
     return 0;
 }

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

int N;
int A[200];

void input() {
    cin >> N;
    for (int i = 0; i < N; ++i) cin >> A[i];
}

int main() {
    input();
    int cnt = 0;
    bool flg = 1;
    
    while(flg){
        for (int i = 0;i < N;i++){
            if (A[i] % 2 == 0){
                A[i] = A[i] / 2;
            } else {
                flg = 0;
                break;
            }
        }
        if (flg){
            cnt++;
        }
    }
    printf("%d\n", cnt);
    return 0;
}

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

typedef long long ll;
typedef unsigned long long ull;

// O(V^3)
template <typename T>
std::vector<std::vector<T>> WarshallFloyd(const std::vector<std::vector<T>>& g, const std::vector<std::vector<T>>& w){
    auto n = g.size();
    std::vector<std::vector<T>> d(n, std::vector<T>(n, std::numeric_limits<T>::max()));
    for(int i=0; i<g.size(); i++){
        for(int j=0; j<g[i].size(); j++){
            d[i][g[i][j]] = w[i][j];
        }
    }

    for(int k=0; k<n; k++){
        for(int i=0; i<n; i++){
            for(int j=0; j<n; j++){
                if(d[i][k] == std::numeric_limits<T>::max()) continue;
                if(d[k][j] == std::numeric_limits<T>::max()) continue;
                d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
            }
        }
    }
    return d;
}

int main()
{
    ll N, M, L;
    cin >> N >> M >> L;
    ll Ai, Bi, Ci;
    vector<vector<ll>> g(N);
    vector<vector<ll>> w(N);
    for(int i=0;i<M;i++){
        cin >> Ai >> Bi >> Ci;
        Ai--; Bi--;
        g[Ai].push_back(Bi);
        g[Bi].push_back(Ai);
        w[Ai].push_back(Ci);
        w[Bi].push_back(Ci);
    }
    auto d = WarshallFloyd(g, w);
    vector<vector<ll>> g2(N);
    vector<vector<ll>> w2(N);
    for(int i=0; i<N; i++){
        for(int j=0; j<N; j++){
            if(i==j) continue;
            if(d[i][j] > L) continue;

            g2[i].push_back(j);
            w2[i].push_back(1);
        }
    }
    auto d2 = WarshallFloyd(g2, w2);

    int Q;
    cin >> Q;
    ll si, ti;
    vector<ll> res;
    for(int i=0; i<Q; i++){
        cin >> si >> ti;
        si--; ti--;

        if(d2[si][ti] == numeric_limits<ll>::max()) res.push_back(-1);
        else res.push_back(d2[si][ti] - 1);
    }
    for(auto v : res) cout << v << endl;

    return 0;
}


Measured memory_bytes: 9588
use proconio::fastout;
use proconio::input;
#[allow(unused_imports)]
use proconio::marker::*;

#[fastout]
fn main() {
    input! {
        s: Chars,
    }
    let cnt = s.iter().filter(|&&c| c == 'R').count();
    println!("{}", if cnt == 2 && s[1] == 'S' { 1 } else { cnt });
}


Measured memory_bytes: 2144
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <iomanip>
#include <queue>
#include <climits> 
#include <time.h>

int main(void){
    std::string S;
    std::cin >> S;
    for(long i=0; i<3; i++){
        std::cout << S[i];
    }
    std::cout << std::endl;
    return 0;
}

Measured memory_bytes: 3620
h,w = map(int,input().split())

li = [list(input().split()) for _ in range(h)]

for i in range(h):
    for j in range(w):
        if li[i][j] == "snuke":
            s = i + 1
            t = j
            
tmp = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
tmp = list(tmp)

print(tmp[t] + str(s))



Measured memory_bytes: 3060
#ifdef LOCAL
#include <cstdio>
#include <vector>
#include <algorithm>
#include <iostream>
#include <cstring>
#else
#include <bits/stdc++.h>
#endif
using namespace std ;

typedef long long ll ;
#define rep(i , n ) for ( int i =0; i < n ; i++)
#define _sort(arg) sort(begin(arg), end(arg))
#define MOD 1000000007
#define pb push_back
#define DEBUG(x) cout << #x << ": " << x << endl;

int main(){
    ios_base::sync_with_stdio(false); //Fast I/O
    cin.tie(0);
    cout.tie(0);
 
 	int n;
 	char s[100005];
 	bool A[100005];
 	cin >> n >> s;
 	s[n]=s[0];
 	s[n+1]=s[1];
 
 	rep(i, 4){
 		A[0]=i&1;
 		A[1]=(i>>1)&1;
 		for(int i=2;i<n+2;i++){

 			// sheep and x || wolf and o
			if(A[i-1]^(s[i-1]=='o'))
				A[i]=A[i-2]^1;
			else 
				A[i]=A[i-2];
		}
 		if(A[n]==A[0] && A[n+1]==A[1]){
 			rep(i,n){
 				if(A[i])
 					cout << 'S';
 				else
 					cout << "W";
 			}
 			return 0;
 		}
 	}
 
 	cout << -1 << endl;
    
    return 0;
}


Measured memory_bytes: 512
function Main(input) {
	var S = input.split('\n')
	
	console.log(Math.pow(S[0], 2));
}
 
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 7372
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pll pair<ll,ll>
#define ff first
#define ss second
#define se set<ll>
#define vec vector<ll>
#define inf 10000000000000000
bool mark[100005];
vec adj[100005];
ll counter;
vec cnt;
vector<string> forsubs;
ll ans=0;
ll n;
string s;



	

int main()
{    
 

	#ifdef APNA_IO
		freopen("input.txt","r",stdin);
		freopen("output.txt","w",stdout);
	#endif
		    ios_base::sync_with_stdio(false); 
    cin.tie(NULL); 


ll n,k;
cin>>n>>k;
if(k==1)
	cout<<"0"<<endl;
else
cout<<n-k<<endl;

}	


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

int main(){
    
    int N;
    cin >> N;
    
    string ans;
    if ( N < 1200 ) {
        ans = "ABC";
    } else if ( N < 2800 ) {
        ans = "ARC";
    } else {
        ans = "AGC";
    }
    cout << ans << endl;
    
}


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

public class Main {

	public static void main(String[] args) {
		@SuppressWarnings("resource")
		Scanner stdin = new Scanner(System.in);

		int inN = stdin.nextInt();
		int inH = stdin.nextInt();

		int aMax = 0;
		int[] inB = new int[inN];
		for (int i = 0; i < inN; i++) {
			aMax = Math.max(aMax, stdin.nextInt());
			inB[i] = stdin.nextInt();
		}

		int count = 0;
		Arrays.sort(inB);
		for (int i = (inN - 1); (i >= 0) && (inB[i] > aMax); i--) {
			inH -= inB[i];
			count++;

			if (inH <= 0) {
				System.out.println(count);
				return;
			}
		}

		count += inH / aMax;
		if ((inH % aMax) > 0) {
			count++;
		}

		System.out.println(count);
	}

}


Measured memory_bytes: 64996
#include<stdio.h>
#include<string.h>
int min(int a, int b){return a < b ? a : b;}
int main(){
    char s[1005], t[1005];
    scanf("%s%s",s,t);
    int ans = 100000;
    // printf("%d\n",strlen(s));
    for(int i = 0; i <= strlen(s) - strlen(t); i++){
        int m = 0;
        for(int j = 0; j < strlen(t); j++){
            if(t[j] != s[i + j])
                m++;
        }
        // printf("%d\n",m);
        ans = min(ans, m);
    }
    printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 1700
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define Cout(s) cout << s << endl;
using ll = long long;
using P = pair<int, int>;

const ll INF = 1ll << 60;
ll MOD = 1e9 + 7;

int main()
{

    int n, m, c;
    cin >> n >> m >> c;
    vector<int> b(m);
    REP(i, m)
    cin >> b[i];

    vector<vector<int>> a(n, vector<int>(m));
    REP(i, n)
    {
        REP(j, m)
        {
            cin >> a[i][j];
        }
    }

    int ans = 0;

    REP(i, n)
    {
        int score = 0;
        REP(j, m)
        {

            score += a[i][j] * b[j];
        }
        if (score + c > 0)
            ans++;
    }

    Cout(ans);

    return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();

        if (n >= m) {
            System.out.println(0);
            return;
        }
        int[] x = new int[m];
        for (int i = 0; i < m; i++) {
            x[i] = sc.nextInt();
        }
        Arrays.sort(x);

        int[] d1 = new int[m-1];
        int sum = 0;
        for (int i = 0; i < m-1; i++) {
            d1[i] = x[i+1] - x[i];
            sum += d1[i];
        }
        Arrays.sort(d1);
        for (int i = 0; i < n-1; i++) {
            sum -= d1[m-i-2];
        }

        System.out.println(sum);
    }
}


Measured memory_bytes: 50340
package main

import (
	"fmt"
)

func main() {
	var a int
	fmt.Scan(&a)

	nums := make([]int, a)
	for i := range nums {
		fmt.Scan(&nums[i])
	}

	count := 0
	max := nums[0]
	for i := 1; i < a; i++ {
		if nums[i] > max {
			max = nums[i]
		}

		if max-nums[i] > 1 {
			count++
		}
	}
	if count == 0 {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}


Measured memory_bytes: 5504
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>

using namespace std;

long long solve_even(int N, vector<long long> A, vector<long long> B)
{
	sort(A.begin(), A.end());
	sort(B.rbegin(), B.rend());

	return (B[N / 2 - 1] + B[N / 2]) - (A[N / 2 - 1] + A[N / 2]) + 1;

}

long long solve_odd(int N, vector<long long> A,vector<long long> B)
{
	sort(A.begin(), A.end());
	sort(B.rbegin(), B.rend());

	return B[N / 2] - A[N / 2] + 1;
}

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

	if (N % 2 == 0) {
		cout << solve_even(N, A, B) << endl;
	}
	else {
		cout << solve_odd(N, A, B) << endl;
	}
}



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

public class Main {
	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		int p = s.nextInt();
		int q = s.nextInt();
		int r = s.nextInt();
		System.out.println(Main.calc(p, q, r));
	}

	public static int calc(int p, int q, int r) {

		Integer array[]= {p,q,r};
		Arrays.sort(array);
		return array[0]+array[1];
	}

}

Measured memory_bytes: 21844
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <cmath>
#include <climits>
#include <iomanip>
#include <set>
#include <map>
using namespace std;
typedef long long ll;
int main(){
  ll n,l;
  cin >> n >> l;
  vector<string> s(n);
  for(int i = 0;i < n;i++)cin >> s[i];
  sort(s.begin(),s.end());
  string res;
  for(int i = 0;i < n;i++)res += s[i];
  cout << res << endl;
}

Measured memory_bytes: 3676
#include <iostream>
#include <cstdint>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <cassert>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <unordered_set>
#pragma GCC optimize("Ofast")
using namespace std;
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<ll> vll;
typedef vector<pair<int, int>> vpii;
typedef vector<vector<int>> vvi;
typedef vector<vector<char>> vvc;
typedef vector<vector<string>> vvs;
typedef vector<vector<ll>> vvll;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define irep(it, stl) for (auto it = stl.begin(); it != stl.end(); it++)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define mes(a) cout << (a) << endl
#define dmes(a, b) cout << (a) << " " << (b) << endl
#define re0 return 0
#define mp(p, q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define rSort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
#define itn int
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
template <class T>
inline bool chmax(T &a, T b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
inline bool chmin(T &a, T b)
{
    if (a > b)
    {
        a = b;
        return 1;
    }
    return 0;
}
struct io
{
    io()
    {
        ios::sync_with_stdio(false);
        cin.tie(0);
    }
};
const int INF = INT_MAX;
const ll LLINF = 1LL << 60;
const ll MOD = 1000000007;
const double EPS = 1e-19;







int main() {
    ll n, m;
    cin >> n >> m;
    
    vb issafe;
    issafe.assign(n+1, true);
    
    rep(i, m) {
        ll a; 
        cin >> a;
        issafe[a] = false;
    }

    vi dp(n+1, 0);

    dp[0] = 1;
    if (issafe[1]) dp[1] = 1;

  
    for (int i = 2; i <= n; ++i) {
        if (issafe[i-1]) dp[i] += dp[i-1];
        if (issafe[i-2]) dp[i] += dp[i-2];
        dp[i] %= MOD;
    }
  
  
    mes(dp[n]);
}

Measured memory_bytes: 3780
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <string>
#include <vector>
using namespace std;
const int MOD = 1e9 + 7;
int main() {
  int n, k;
  cin >> n >> k;
  long long sumCount = 0;
  for (long long i = k; i <= n + 1; i++) {
    sumCount += ((n - i + 1) * i + 1) % MOD;
    sumCount %= MOD;
  }
  cout << sumCount << endl;
  return 0;
}

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


int N = 200000;


int main()
{
  int n, k, a[N], t[N];
  for ( int i=0; i<N; i++ ) {
    a[i] = 0;
    t[i] = 0;
  }

  cin >> n >> k;
  int idx, n_type=0;
  for ( int i=0; i<n; i++ ) {
    cin >> idx;
    a[idx-1]++;
    if ( t[idx-1] == 0 ) {
      t[idx-1] = 1;
      n_type++;
    }
  }

  sort(a, a+n);

  int cnt = 0;
  if ( n_type-k > 0) {
    int i=0, j=0;
    while ( i < n_type-k ) {
      if ( a[j] == 0 ) {
	j++;
	continue;
      }
      cnt += a[j];
      j++;
      i++;
    }
  }
  cout << cnt << endl;
  
  return 0;
}


Measured memory_bytes: 1792
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
    public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        
		// 1行目個数、2行目の複数の数字を配列に格納
		//   3
		//   1 2 3
		int N = Integer.parseInt(br.readLine());
		String[] ss0 = br.readLine().trim().split(" ", 0);
		Integer[] ii0 = new Integer[N];
		for(int i = 0; i < N; i++){
			ii0[i] = Integer.parseInt(ss0[i]);
		}
		
		//dp(N);
					//入力値確認
					for(int i=0; i < N; i++){
						//dp(ii0[i]);
					}

		long l = 1;
		int outHikisu = 0;
		for(int i = 0; i < N; i++){
			dp(i*2+1 + " > " + ii0[i]);
			
			if ( ((i-outHikisu)*2+1) > ii0[i] ) {
				//アウト
				l = (l * (i+1 - outHikisu)) % 1000000007;
				outHikisu += 1;
				dp("Out " + l + ", outHikisu " + outHikisu);
			} else {
			}
		}
		
		
			dp("--------");
		dp("l=" + l);
		dp("N=" + N);
		dp("outHikisu=" + outHikisu);
		dp("(N - outHikisu)=" + (N - outHikisu));
		for(int i = (N - outHikisu); i > 0; i--){
			l = l * i  % 1000000007;
		}


        System.out.println(l);
        return;
    }
    // Debug.Print
    static void dp(String s) {
		//System.out.println(s);
	}
    static void dp(StringBuilder s) { dp(s.toString()); }
    static void dp(int i) { dp(String.valueOf(i)); }
    static void dp(long i) { dp(String.valueOf(i)); }

}


Measured memory_bytes: 52428
#include <iostream>
#include <string>
#include <sstream>
#include <bitset>
using namespace std;

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

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

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

    long long ans = -(1<<30);
    for(int i = 1; i < 1<<10; i++)
    {
        stringstream ss;
        ss << static_cast<bitset<10>>(i);
        string s = ss.str();
        int A[10];
        for(int j = 9; j >= 0; j--)
        {
            A[j] = s[j] - '0';
        }

        long long sub = 0;
        for(int j = 0; j < N; j++)
        {
            int cnt = 0;
            for(int k = 0; k < 10; k++)
            {
                //if(A[k] == 1 and F[j][k] == 1)
                if((i>>k&1) and F[j][k] == 1)
                {
                    cnt++;
                }
            }
            sub += P[j][cnt];
        }

        ans = max(ans, sub);
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while (sc.hasNext()) {
            String str=sc.nextLine();
            StringBuilder sb = new StringBuilder();
            for (char ch : str.toCharArray()) {
                if (ch=='0' || ch=='1')
                    sb.append(ch);
                else if (ch == 'B') {
                    if (sb.length()!=0)
                        sb.deleteCharAt(sb.length() - 1);
                }
            }
            System.out.println(sb.toString());
        }
    }
}

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

int main() {
  int n;
  cin>>n;
  map<string, int> mp;
  long long ans=0;
  rep(i,n){
    string s;
    cin>>s;
    sort(s.begin(),s.end());
    if(mp[s]>0) ans+=mp[s];
    mp[s]++;
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 11308
n,k = gets.chomp.split(" ").map(&:to_i)

result = 0
(1..n).each do |i|
  # iのときの確率は (1 / n) * (1 / 2)^a
  # aは表が連続で出る回数で i * 2^a >= k を満たす最小のa (a >= 0)
  a = [(Math.log2(k) - Math.log2(i)).ceil, 0].max
  result += 1 / (n * (2 ** a)).to_f
end

puts result


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

using namespace std;
double p[3005];
double dp[3005][3005];
int main() {
    int n;
    cin>>n;
    for (int i = 1; i <= n;i++) {
        cin>>p[i];
    }
    dp[0][0]= 1;

    for (int j = 1; j <=n ; ++j) {
        dp[j][0] = dp[j-1][0]*(1.0-p[j]);
        for (int i = 1; i <=j ; ++i) {
            dp[j][i] = dp[j-1][i-1]*p[j] + dp[j-1][i]*(1.0-p[j]);
        }
    }
    double ans = 0.0;
    for (int k = 0; k <=n ; ++k) {
        if (k > n-k) {
            ans += dp[n][k];
        }
    }
    printf("%.10lf\n", ans);
    return 0;
}

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

int main(void)
{
    int n;
    int freq[7];
    int age;
    int i;
    
    while (1){
        memset(freq, 0, sizeof(freq));
        
        scanf("%d", &n);
        if (n == 0){
            break;
        }
        
        for (i = 0; i < n; i++){
            scanf("%d", &age);
            if (age >= 60){
                age = 60;
            }
            freq[age / 10]++;
        }
        
        for (i = 0; i < 7; i++){
            printf("%d\n", freq[i]);
        }
    }
    return (0);
}

Measured memory_bytes: 408
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String s = scanner.next();
        if (s.charAt(0)=='7'||s.charAt(1)=='7'||s.charAt(2)=='7'){
            System.out.println("Yes");
        }else {
            System.out.println("No");
        }
    }
}

Measured memory_bytes: 35652
#pragma warning(disable:4996)
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize ("-ffloat-store")
#include<bits/stdc++.h>
#define FastIO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define MOD 1000000007
#define INF 1e10
#define ull unsigned long long int
using namespace std;

/* TYPE DEFINITIONS */
typedef     long long int   ll;
typedef     vector<float>      vi;
typedef     pair<ll,ll>     pi;


/* Prime Checker!!! */
bool isPrime(ull n) 
{ 
    if (n <= 1)  return false; 
    if (n <= 3)  return true; 
    if (n%2 == 0 || n%3 == 0) return false; 
  
    for (ull i=5; i*i<=n; i=i+6) 
        if (n%i == 0 || n%(i+2) == 0) 
           return false; 
  
    return true; 
} 

/* MACROS */
#define  all(A)         (A).begin() , (A).end()
#define  rall(A)        (A).rbegin() , (A).rend()
#define  sz(A)          (int)(A).size()
#define  pb             push_back
#define  ppb            pop_back
#define  mp             make_pair
#define  ln(X)          (int)(X).length()
#define  square(X)      ((X)*(X))
#define  cube(X)        ((X)*(X)*(X))
#define  forn(i, n)  for (int i = 0; i < int(n); i++)
#define  forr(i, n)  for (int i = int(n - 1); i >= 0; i--)
#define  fora(i, a, b)  for (int i = int(a); i <= int(b); i++)
#define  forb(i, a, b)  for (int i = int(a); i >= int(b); i--)
#define  fore(it, a)    for(__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)  
void solve()
{    
    int n;
    cin>>n;
    ll sum=0;
    ll mul=1;
    vi v;
    for(int i=0;i<n;i++)
    {
        int input;
        cin>>input;
        v.pb(input);
    }
    sort(all(v));
    while(v.size()>2)
    {
        
        float a=v[0],b=v[1];
        v.erase(v.begin());
        v.erase(v.begin());
        v.pb((float)(a+b)/2);
        //sum=(a+b)/2;
        sort(all(v));
    }
    //for(auto i:v)cout<<i<<" ";
    cout<<(float)(v[0]+v[1])/2<<endl;
}   


int main()
{
    FastIO;
    ll t=1;
    //cin>>t;
    //double start_time = clock();
    while(t--)
    {
        solve();
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
const long long MOD = 1000000007LL;
long long GCD(long long a, long long b){return b == 0 ? a : GCD(b, a % b);}
 
int arr[100001];
 
int main(){
 
    cin.sync_with_stdio(0); cin.tie(0); cout.tie(0);
 
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
 
    int n, c, k;
    cin >> n >> c >> k;
 
    vector<int> t;
    for(int i = 0; i < n; ++i){
        int a;
        cin >> a;
        t.push_back(a);
    }
 
    sort(t.begin(), t.end());
 
    int cur = 0, lowest = 0, cnt = 0;
 
    for(auto i : t){
        if(lowest == 0)
            lowest = i;
        if(lowest + k >= i && cur < c){
            ++cur;
        } else {
            ++cnt;
            cur = 1;
            lowest = i;
        }
    }
 
    if(cur >= 1)
        ++cnt;
 
    cout << cnt;
 
    return 0;
}

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

int main() {
  string s;
  cin >> s;
  
  int l = s.length();
  int sum = 0;
  for (int i = 0; i < l; i++) {
    char c = (i % 2 == 0) ? '1' : '0';
    if (s[i] == c)
      sum++;
  }
  
  cout << min(sum, l - sum) << endl;
  return 0;
}

Measured memory_bytes: 512
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		String n = sc.next();
		int a = Integer.parseInt(n.substring(0, 1));
		int b = Integer.parseInt(n.substring(2));

		System.out.println(a == b ? "Yes" : "No");
	}
}

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

using int32 = int_fast32_t;
using int64 = int_fast64_t;

const int32 INF = 1e9;
const int32 MOD = 1e9+7;
const int64 LLINF = 1e18;

#define YES(n) cout << ((n) ? "YES\n" : "NO\n"  )
#define Yes(n) cout << ((n) ? "Yes\n" : "No\n"  )
#define POSSIBLE cout << ((n) ? "POSSIBLE\n" : "IMPOSSIBLE\n"  )
#define ANS(n) cout << (n) << "\n"
#define REP(i,n) for(int64 i=0;i<(n);++i)
#define FOR(i,a,b) for(int64 i=(a);i<(b);i++)
#define FORR(i,a,b) for(int64 i=(a);i>=(b);i--)
#define ALL(obj) (obj).begin(),(obj).end()
#define pii pair<int32,int32>
#define pll pair<int64,int64>
#define pb(a) push_back(a)
#define mp make_pair

int32 di[4] = {1,0,-1,0};
int32 dj[4] = {0,1,0,-1};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int32 h,w;
    cin >> h >> w;
    vector<string> s(h);
    REP(i,h)cin >> s[i];
    int32 wcnt = 0;
    REP(i,h)REP(j,w)if(s[i][j] == '.')wcnt++;
    vector<vector<int32>> dist(h,vector<int32>(w,INF));
    dist[0][0] = 1;
    queue<pii> que;
    que.emplace(0,0);
    while(!que.empty()){
        int32 ci,cj;
        tie(ci,cj) = que.front();que.pop();
        REP(i,4){
            int32 ni = ci + di[i];
            int32 nj = cj + dj[i];
            if(ni < 0 || h <= ni)continue;
            if(nj < 0 || w <= nj)continue;
            if(s[ni][nj] == '#')continue;
            if(dist[ni][nj] > dist[ci][cj] + 1){
                dist[ni][nj] = dist[ci][cj] + 1;
                que.emplace(ni,nj);
            }
        }
    }
    if(dist[h-1][w-1] == INF){
        ANS(-1);
        return 0;
    }
    ANS(wcnt - dist[h-1][w-1]);
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <math.h>
using namespace std;
int main() {
    int a , b , c , d ;
    cin >> a >> b >> c >> d ;
    if (abs(a-c) <= d) cout << "Yes" ;
    else if (abs(a-b) <= d && abs(b-c) <= d) cout << "Yes";
    else cout << "No" ;
    return 0 ;
}


Measured memory_bytes: 3612
while True:
    m,f,r = map(int,input().split())
    if m == f == r == -1 :
        break
    elif m == -1 or f == -1 :
        print("F")
    elif m + f >= 80 :
        print("A")
    elif m + f >= 65:
        print("B")
    elif m + f >= 50 :
        print("C")
    elif m + f >= 30 :
        if r >= 50:
            print("C")
        else :
            print("D")
    else :
        print("F")

Measured memory_bytes: 7660
#include <functional>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;
const ll MOD = 1000000007LL;

ll five(ll c) {
    return c * c * c * c * c;
}

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

    ll x;
    cin >> x;

    for (ll a = -1000; a <= 1000; a++) {
        for (ll b = -1000; b <= 1000; b++) {
            if (five(a) - five(b) == x) {
                cout << a << ' ' << b << endl;
                return 0;
            }
        }
    }

    return 0;
}

Measured memory_bytes: 3608
import math
a, b, h, m = map(int, input().split())
degree_a = 30*h + m/2 
degree_b = 6*m 
x_a = a*math.sin(math.radians(degree_a))
y_a = a*math.cos(math.radians(degree_a))   
x_b = b*math.sin(math.radians(degree_b))
y_b = b*math.cos(math.radians(degree_b)) 
print(math.sqrt((x_a - x_b)**2 +(y_a - y_b)**2 ))

Measured memory_bytes: 9516
def ints
  gets.split.map(&:to_i)
end

N, Q = ints
S = gets.strip

counts = Array.new(S.length, 0)
1.upto(S.length - 1) do |i|
  ac = 0
  if S[i - 1] == 'A' && S[i] == 'C'
    ac = 1
  end
  counts[i] = counts[i - 1] + ac
end

Q.times do
  l, r = ints
  l -= 1
  r -= 1

  puts counts[r] - counts[l]
end


Measured memory_bytes: 3324
import Data.List

f :: Int->String->[String]
f 0 _ =[]
f n str=(take n str) : (f (n-1) str)

f2 :: Int-> String ->[String]
f2 _ []=[]
f2 k a1@(x:xs)=(f k a1) ++ f2 k xs

main = do
      x<-getLine
      y<-getLine
      let k=read y::Int
      putStrLn $ head $ (group $ sort $ f2 k x) !! (k-1)

Measured memory_bytes: 8572
# coding: utf-8
# Your code here!
s=list(input())
if s.count('N')>0 and s.count('S')>0 and s.count('E')>0 and s.count('W')>0:
    print('Yes')
elif s.count('N')>0 and s.count('S')>0 and s.count('E')==0 and s.count('W')==0:
    print('Yes')
elif s.count('N')==0 and s.count('S')==0 and s.count('E')>0 and s.count('W')>0:
    print('Yes')
else:
    print('No')


Measured memory_bytes: 38384
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N, M, a, b;

  cin >> N >> M;
  vector<int> vec(N);

  for (int i = 0; i < M; i++) {
    cin >> a >> b;
    for (int j = 0; j < N; j++) {
      if (a == j + 1 || b == j + 1) {
        vec.at(j) += 1;
      }
    }
  }
  for (int i = 0; i < N; i++) {
    cout << vec.at(i) << endl;
  }

}

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

using namespace std;

const int N = 100010;

map <int, int> mp;

int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) {
    int x;
    scanf("%d", &x);
    ++mp[x];
  }
  int ans = 0;
  for (auto & e: mp) {
    int val = e.first, times = e.second;
    if (times < val) {
      ans += times;
    } else {
      ans += times - val;
    }
  }
  printf("%d\n", ans);
  return 0;
}

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

typedef long long ll;

int main(){

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

  int D;
  cin>>D;

  vector<ll> c(27);
  for(int i=1;i<=26;++i) cin>>c[i];
  vector<vector<ll>> s(D+1,vector<ll>(27,0));
  for(int i=1;i<=D;++i){
    for(int j=1;j<=26;++j){
      cin>>s[i][j];
    }
  }

  vector<ll> t(D+1,1);
  vector<set<ll>> next(27);
  vector<ll> test(D+1);

  ll ans=0;
  ll val=-1e10;

  for(int cnt=0;cnt<3000;++cnt){

    vector<set<ll>> nest(27);

    for(int i=1;i<=D;++i){
      test[i]=rand()%26;
      ++test[i];
    }

    for(int i=1;i<=D;++i){
      nest[test[i]].insert(i);
    }
    for(int i=1;i<=26;++i){
      nest[i].insert(0);
      nest[i].insert(D+1);
    }

    ll ch=0;
    for(int i=1;i<=D;++i){
      ch += s[i][test[i]];
      for(int j=1;j<=26;++j){
        auto k=nest[j].upper_bound(i);
        --k;
        ll l=*k;
        ch -= c[j]*(i-l);
      }
    }
    if(ch>val){
      val=ch;
      ans=ch;
      for(int i=1;i<=D;++i) t[i]=test[i];
    }
  }

  for(int i=1;i<=D;++i){
    next[t[i]].insert(i);
  }
  for(int i=1;i<=26;++i){
    next[i].insert(0);
    next[i].insert(D+1);
  }

  for(int i=0;i<3000000;++i){

    int d=rand()%D;
    ++d;
    int q=rand()%26;
    ++q;
    ll diff=0;

    //up
    ll l,r;
    auto j=next[q].lower_bound(d);
    r=*j;
    --j;
    l=*j;
    diff += s[d][q]+((r-d)*(d-l))*c[q];

    //down
    next[t[d]].erase(d);
    auto k=next[t[d]].lower_bound(d);
    r=*k;
    --k;
    l=*k;
    diff -= s[d][t[d]]+((r-d)*(d-l))*c[t[d]];

    //update
    if(diff>0){
      next[q].insert(d);
      t[d]=q;
      ans += diff;
    }
    else{
      next[t[d]].insert(d);
    }
  }

  for(int i=1;i<=D;++i) cout<<t[i]<<"\n";

  //cout<<ans<<"\n";

}

Measured memory_bytes: 3808
#include<bits/stdc++.h>
using namespace std;
 
/*
#include <ext/pb_ds/assoc_container.hpp> // Common file 
#include <ext/pb_ds/tree_policy.hpp> 
#include <functional> // for less 
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, 
		   tree_order_statistics_node_update> oset;
*/
 
void __print(int x) {cout << x;}
void __print(long x) {cout << x;}
void __print(long long x) {cout << x;}
void __print(unsigned x) {cout << x;}
void __print(unsigned long x) {cout << x;}
void __print(unsigned long long x) {cout << x;}
void __print(float x) {cout << x;}
void __print(double x) {cout << x;}
void __print(long double x) {cout << x;}
void __print(char x) {cout << '\'' << x << '\'';}
void __print(const char *x) {cout << '\"' << x << '\"';}
void __print(const string &x) {cout << '\"' << x << '\"';}
void __print(bool x) {cout << (x ? "true" : "false");}
 
template<typename T, typename V>
void __print(const pair<T, V> &x) { __print(x.first); cout << ','; __print(x.second); }
template<typename T>
void __print(const T &x) {int f = 0; for (auto &i: x) cout << (f++ ? "," : ""), __print(i); }
void _print() {cout << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cout << ", "; _print(v...);}
 
#ifndef ONLINE_JUDGE
#define d(x...) cout << "[" << #x << "] = ["; _print(x)
#else
#define d(x...)
#endif
 
#define IO            ios::sync_with_stdio(false);cin.tie(0);
//#define clock()       std::chrono::high_resolution_clock::now()
//#define duration(x,y) std::chrono::duration_cast<std::chrono::milliseconds>(y-x).count()
 
#define ll            long long
#define pi            pair<int,int>
#define pii           pair<pi,int>
#define pl            pair<ll,ll>
#define vi            vector<int>
#define vl            vector<ll>
#define vll           vector<vl>
#define vs            vector<string>
#define vb            vector<bool>
#define vii           vector<vector<int>>
#define vpi           vector<pi>
#define vpl           vector<pl>
#define pb            push_back
#define mp            make_pair
#define eb            emplace_back
#define ff            first
#define ss            second
#define fo(i,val,n)   for(int i=val;i<n;i++)
#define rfo(i,val,j)  for(int i=val;i>=j;i--)
#define all(x)        x.begin(),x.end()
#define inf           INT_MAX
#define endl          '\n'
	
const int N=2e5+7;
const int MOD=1e9+7;
//const int MOD=998244353;

int main(){
 	
	IO

	ll n,m;
	cin>>n>>m;

	ll ans = (n * (n-1)) / 2 + (m * (m-1)) / 2;
	cout<<ans;
	return 0;
}


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

#define int long long
#define INF 1e18

signed main() {
    int n; cin >> n;
    int maximum = 0;
    int cnt = 0;
    for(int i = 1; i <= n; i++) {
        int tmp = i;
        int tmpcnt = 0;
        while(tmp % 2 == 0) {
                tmpcnt++;
                tmp /= 2;
        }
        if(max(cnt, tmpcnt) == tmpcnt) {
            cnt = tmpcnt;
            maximum = i;
        }
    }
    cout << maximum << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define all(x) (x).begin(),(x).end()
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; }
typedef long long ll;
const long long INF = 1LL << 60;
typedef pair<int, int> P;
int main()
{
    ll X, K, D;
    cin >> X >> K >> D;

    ll ans;
    X = abs(X);
    ll cnt = X / D;
    if (cnt > K) {
        ans = abs(X - K * D);
    }
    else {
        ans = abs(X - cnt * D);
        K -= cnt;
        if (K % 2) {
            ans = abs(ans - D);
        }
    }

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

Measured memory_bytes: 3636
#include "bits/stdc++.h"
#define in std::cin
#define out std::cout
#define rep(i,N) for(int i=0;i<N;++i)
typedef long long int LL;

LL N, M;

int main()
{
	in >> N >> M;
	std::vector<LL>P(M), Y(M);
	std::vector<std::pair<std::pair<LL, LL>, LL>>cities;
	rep(i, M)
	{
		in >> P[i] >> Y[i];
		cities.push_back(std::make_pair(std::make_pair(Y[i], P[i]), i));
	}

	std::sort(cities.begin(), cities.end());
	std::vector<LL>num(M), cnt(N + 1);
	rep(i, cities.size())
	{
		++cnt[cities[i].first.second];
		num[cities[i].second] = cnt[cities[i].first.second];
	}
	;
	rep(i, M)
	{
		out << std::setfill('0') << std::right << std::setw(6) << P[i];
		out << std::setfill('0') << std::right << std::setw(6) << num[i];
		out << std::endl;
	}
	return 0;
}


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


int main(){
  int n;
  int k;
  cin >>n >>k;
  char a[k];
  rep(i,k)cin >> a[i];
  for(int i=n;i<n*20;i++){
    string g=to_string(i);
    int q=g.size();
    bool e=0;
    rep(t,q){
      rep(tt,k){
        if(a[tt]==g[t]){e=1;break;}
      }
    }
    if(e){continue;}
    cout << i << endl;
    break;
  }
}

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

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

typedef long long LL;
typedef unsigned long long ULL;
typedef unsigned int UI;

using namespace std;

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

    int a, b, h;
    cin >> a >> b >> h;

    cout << (a + b) * h / 2 << endl;

    return 0;
}

Measured memory_bytes: 256
/*
*----------------------------------------------
*   Saurabh Srivastava - SAURASS - andha_koder
*----------------------------------------------
*/
#include<bits/stdc++.h>
using namespace std;
 
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define MOD (ll)(1e9 + 7)
#define vi vector<int>
#define vii vector<vector<int> >
#define vl vector<ll>
#define vll vector<vector<ll> >
#define vc(T, nm) vector<T> nm
#define pb push_back
#define popb pop_back
#define si set<int>
#define sl set<ll>
#define F first
#define S second
#define pii pair<int, int>
#define mp make_pair
#define insert ins
#define ers erase
#define FORA(x, s, e, inc) for(ll x = s; x != e; x += inc)
#define ROFA(x, s, e, inc) for(ll x = s; x != e; x -= inc)
#define FOR(x, s, e) FORA(x, s, e, 1)
#define ROF(x, s, e) ROFA(x, s, e, 1)
#define loop(x, n) FOR(x, 0, n)
#define rd1(t, a) 					t a; cin >> a;
#define rd2(t, a, b) 				rd1(t, a); rd1(t, b); 
#define rd3(t, a, b, c) 			rd2(t, a, b); rd1(t, c);
#define rd4(t, a, b, c, d) 			rd3(t, a, b, c); rd1(t, d);
#define rd5(t, a, b, c, d, e) 		rd4(t, a, b, c, d); rd1(t, e);
#define rd6(t, a, b, c, d, e, f) 	rd5(t, a, b, c, d, e); rd1(t, f);
#define rdA(t, nm, len)				t nm[len]; loop(i, len) {cin >> nm[i];}
#ifdef DEBUG
	#define deb(v) cout << endl << #v << ": " << v << endl
	#define db1(v) cout << endl << #v << ": " << "[ "; for(auto x: v) {cout << x << " ";}; cout << "]" << endl;
	#define db2(v) cout << endl << #v << ": " << endl; for(auto r: v) {cout << "[ "; for(auto x: r) {cout << x << " ";}; cout << "]" << endl;};
	#define dbl cout << "-------------------------------" << endl
#else
	#define deb(v)
	#define db1(v)
	#define db2(v)
	#define dbl
#endif


typedef long long int ll;
typedef long double ld;

ld dist(pair<int, int> a, pair<int, int> b) {
    ll x1 = a.first;
    ll y1 = a.second;
    ll x2 = b.first;
    ll y2 = b.second;

    ll x = abs(x2 - x1);
    ll y = abs(y2 - y1);

    return sqrt(x*x + y*y);
}

int main() {
	
    vector<pair<int, int> > d;
    ll n;
    cin >> n;

    for(int i = 0; i < n; i++) {
        ll x, y;
        cin >> x >> y;
        d.push_back(make_pair(x, y));
    }

    ld s = 0;
    for(int i = 0; i < n -1; i++) {
        for(int j = i + 1; j < n; j++) {
            s += dist(d[i], d[j]);
        }
    }
	
    cout << setprecision(20) << (s * 2) / n;

	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<vector>
#include<map>
#define rg register
using namespace std;
int b[10000],a;
signed main()
{
	int n,m,c;
	cin>>n>>m>>c;
	for(int i=1;i<=m;i++)
	  cin>>b[i];
	int ans=0;
	for(int i=1;i<=n;i++)
	{
		int cans=0;
		for(int j=1;j<=m;j++)
		  cin>>a,cans+=a*b[j];
		cans+=c;
		if(cans>0)
		  ans++;
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <utility>
#include <vector>
#include <algorithm>
#include <queue>
#include <stack>
#include <cmath>
#include <cstring>
#include <map>
#include <unordered_map>
#include <set>
#include <climits>
#include <bitset>

#define ll long long
const ll MOD = 1e9 + 7;
const ll INF = 1 << 29;

bool Warshallfloyd(int n, std::vector<std::vector<ll>>& distanceTable)
{
    for (auto k=0; k<n; k++)
    {
        for (auto i=0; i<n; i++)
        {
            for (auto j=0; j<n; j++)
            {
                // d[i][k] : i から k までの最短距離
                // d[k][j] : k から j までの最短距離
                // 故にd[i][j] : i から j までの最短距離 = d[i][k] + d[k][j]
                auto distanceTo = distanceTable[i][k] + distanceTable[k][j];
                if (distanceTo < distanceTable[i][j])
                    distanceTable[i][j] = distanceTo;
            }
        }
    }

    // 負の閉路があった場合 d[i][i] が負の値になる
    return distanceTable[0][0] < 0;
}

int main()
{
    int H, W;
    std::cin >> H >> W;

    const int Pattern = 10;
    std::vector<std::vector<ll>> distanceTable(Pattern, std::vector<ll>(Pattern, INF));
    for (auto i=0; i<Pattern; ++i)
    {
        for (auto j=0; j<Pattern; ++j)
        {
            ll cost;
            std::cin >> cost;
            distanceTable[i][j] = cost;
        }
    }

    Warshallfloyd(Pattern, distanceTable);

    ll total = 0;
    for (auto i=0; i<H; ++i)
    {
        for (auto j=0; j<W; ++j)
        {
            ll value;
            std::cin >> value;
            if (value == -1)
                continue;

            total += distanceTable[value][1];
        }
    }

    std::cout << total << std::endl;
}


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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long; 
const int MOD = 1000000007;

int main() {
  ll n;cin>>n;
  ll ans=1;
  rep(i,n) ans = (ans * (i+1)) % MOD;
  cout << ans;
}


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

int main(){
  int N;
  cin >> N;
  vector<long long> A(N);
  for(int i=0;i<N;i++)  cin >> A.at(i);

  vector<long long> sum(N+1,0);
  for(int i=0;i<N;i++)  sum.at(i+1)=sum.at(i)+A.at(i);
  long long ans=1e18;
  for(int i=1;i<N;i++){
    if(sum.at(i)*2<sum.at(N)) continue;
    long long tmp=abs((sum.at(N)-sum.at(i))-sum.at(i));
    ans=min(ans,tmp);
  }
  for(int i=1;i<N;i++){
    if(sum.at(i+1)*2<sum.at(N)) continue;
    long long tmp=abs((sum.at(N)-sum.at(i))-sum.at(i));
    ans=min(ans,tmp);
  }
  cout << ans << endl;

  return 0;
}


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

int main(){
  int n;
  cin>>n;
  vector<int>vec(n);
  vector<pair<int,int>> even(100005),odd(100005);
  
  for(int i=0;i<100005;i++){
    even.at(i)={0,i};
    odd.at(i)={0,i};
  }
  
  for(int i=0;i<n;i++){
    int a;
    cin>>a;
    if(i%2==0)
      even.at(a).first++;
    else
      odd.at(a).first++;
  }
  sort(even.begin(),even.end());
  sort(odd.begin(),odd.end());
  reverse(even.begin(),even.end());
  reverse(odd.begin(),odd.end());
  
  if(even.at(0).second!=odd.at(0).second)
    cout<<n-even.at(0).first-odd.at(0).first<<endl;
  else
    cout<<n-max(even.at(0).first+odd.at(1).first,even.at(1).first+odd.at(0).first)<<endl;
}

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

ll gcd(ll a, ll b){
    if(a<b) swap(a,b);
    if(a%b==0) return b;
    return gcd(b,a%b);
}

int main(void){
    ll a,b;
    cin >> a >> b;
    ll p = gcd(a,b);
    ll ans=1;
    ll n=2;
    while(n*n<=p){
        if(p%n==0){
            ans++;
            while(p%n==0)
                p/=n;
        }
        n++;
    }
    if(p>1) ans++;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define all(x) x.begin(),x.end()
#define dbg(x) cout<<#x<<":"<<x<<endl
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<ll,P> PP;

vector<int> g[2222];

void dfs(int cnt[],int used[],int n,int k){
  if(used[n])return;
  cnt[n]=1;
  used[n]=1;
  if(k==0)return;
  for(int i=0;i<g[n].size();i++){
    dfs(cnt,used,g[n][i],k-1);
  }
}

int main(){
  int n,k;
  cin>>n>>k;
  int a[2222],b[2222];
  for(int i=0;i<n-1;i++){
    cin>>a[i]>>b[i];
    a[i]--,b[i]--;
    g[a[i]].pb(b[i]);
    g[b[i]].pb(a[i]);
  }

  int ma=0;
  
  if(k%2){
    for(int i=0;i<n-1;i++){
	 int cnt[2222]={};
	 int used[2222]={};
	 dfs(cnt,used,a[i],k/2);
	 fill_n(used,2222,0);
	 dfs(cnt,used,b[i],k/2);
	 int sum=0;
	 for(int j=0;j<n;j++){
	   sum+=cnt[j];
	 }
	 ma=max(ma,sum);
    }
  }else{
    for(int i=0;i<n;i++){
	 int cnt[2222]={};
	 int used[2222]={};
	 dfs(cnt,used,i,k/2);
	 int sum=0;
	 for(int j=0;j<n;j++){
	   sum+=cnt[j];
	 }
	 ma=max(ma,sum);
    }
  }

  cout<<n-ma<<endl;
  
  return 0;
}


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

using namespace std;

#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x).size()
#define F first
#define S second
#define forn(i, n) for (int i = 0; i < (int)n; i++)
#define pb push_back
#define fastIO ios::sync_with_stdio(0), cin.tie(0)
#define endl '\n'
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
void debug_out() {cerr << endl;}
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {cerr << " " << to_string(H), debug_out(T...);}

int main() {
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
    freopen("in.txt", "r", stdin);
    // freopen("out.txt", "w", stdout);
#else
#define debug(...) 3
    fastIO;
#endif
    string s;
    cin>>s;
    set<char> st;
    st.insert(s[0]);
    st.insert(s[1]);
    st.insert(s[2]);
    if(sz(st)==1)cout<<"No"<<endl;
    else cout<<"Yes"<<endl;
    return 0;
}


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

int main() {
	
	int n, k;
	cin >> n >> k;
	
	vector<int> h(n);
	rep(i, n) cin >> h[i];
	
	int ans = 0;
	
	rep(i, n){
		if(h[i] >= k) ans++;
	}
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define loop(__x, __start, __end) for(int __x = __start; __x < __end; __x++)

vector<ll> divisors(ll n) {
  vector<ll> D;
  for (ll i=1; i*i<=n; i++) {
    if (n%i==0) {
      D.push_back(i);
      if (i*i!=n) D.push_back(n/i);
    }
  }
  return D;
}

int main() {
  ll n; cin >> n;
  auto D = divisors(n);
  int ans = 0;
  for (auto d: D) {
    ll m = n;
    if (d == 1) continue;
    while (m%d==0) m /= d;
    m%=d;
    ans += m == 1;
  }
  ans += divisors(n-1).size()-1;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3732
#include<bits/stdc++.h>
using namespace std;
char mp[23][23];
int cnt[29];
int main()
{
	int Q,n,m; 
		scanf("%d%d",&n,&m);
		bool fail = 0;
		memset(cnt,0,sizeof(cnt));
		for(register int i=1;i<=n;++i) {
			scanf("%s",mp[i]);
			for(register int j=0;j<m;++j)
			cnt[mp[i][j] - 'a'] ++;
		}
		if ((m&1) && (n&1)) {
			int l1 = (n + 1)/2 - 1, l2 = (m + 1)/2 - 1;
			int c1 = l1 + l2,lim = l1 * l2; bool fl = 0;
			for(register int i=0;i<26;++i) {
				if (!cnt[i]) continue;
				int h  = cnt[i] / 4;
				int Y = cnt[i] % 4;
				if (h > lim) {
					h -= lim;
					lim = 0;
					Y += h * 4;
				} else lim -= h;
				if (Y & 1) {
					if (fl) {
						fail = 1;
						break;
					}
					Y --; fl = 1;
				}
				Y /= 2;
				if (c1 >= Y) c1 -= Y;
				else {
					fail = 1;
					break;
				}
			}
		}
		else if ((m&1)||(n&1)) {
			int lim,c = (m&1) ? n : m;
			lim = (n * m - c)/4; c /= 2;
			for(register int i=0;i<26;++i) {
				if (!cnt[i]) continue;
				if (cnt[i]&1) {
					fail = 1;
					break;
				}
				int Y = cnt[i]%4,h = cnt[i]/4;
				if (h > lim) {
					h -= lim;
					lim = 0;
					Y += h * 4;
				} else lim -= h;
				Y /= 2;
				if (c >= Y) c -= Y;
				else {
					fail = 1;
					break;
				}
			}
		}
		else {
			for(register int i=0;i<26;++i) 
			if (cnt[i] % 4 != 0) {
				fail = 1;
				break;
			}
		}
		if (fail) puts("No");
		else puts("Yes");
}

Measured memory_bytes: 256