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


 
int main(){
  string s,t;
  cin >> s >> t;
  int word = s.size();
  
  bool ans = true;
  vector<char>scount(26,'0'),tcount(26,'0');
  for(int i=0; i<word; i++){
    if(scount[s[i]-'a']!='0' && scount[s[i]-'a']!=t[i]) ans = false;
    if(tcount[t[i]-'a']!='0' && tcount[t[i]-'a']!=s[i]) ans = false;
    scount[s[i]-'a']=t[i];
    tcount[t[i]-'a']=s[i];
  }
  
  if(ans) cout << "Yes" << endl;
  else cout << "No" << endl;
  
}

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

int main(){
    constexpr long MOD = 1000000007;
    long N;
    cin >> N;
    long dp{N};
    vector<long> sum(N + 3, (N - 1) * N % MOD);
    sum[0] = 0;
    for(long i = 3; i != N + 3; ++i)sum[i] = (sum[i - 1] - 1 + (dp += sum[i - 3])) % MOD;
    cout << dp % MOD << endl;
    return 0;
}

Measured memory_bytes: 8064
PROGRAM-ID.                      AGC_025_A.
DATA                             DIVISION.
WORKING-STORAGE                  SECTION.
    01 MAX_SM  PIC 9(2) VALUE 99.

    01 N       PIC 9(6).
    01 half    PIC 9(5).
    01 i       PIC 9(5).
    01 a       PIC 9(6).
    01 b       PIC 9(6).
    01 asm     PIC 9(2).
    01 bsm     PIC 9(2).
    01 sm      PIC 9(2).

    01 r       PIC 9(1).

    01 ans     PIC X(2).

    01 ZS      PIC Z(3).
    01 DUMMY   PIC X(1).


PROCEDURE                        DIVISION.
    ACCEPT N.

    DIVIDE 2 INTO N GIVING half.

    MOVE MAX_SM TO sm.

    PERFORM VARYING i FROM 1 BY 1 UNTIL half < i
        MOVE i TO a
        SUBTRACT i FROM N GIVING b
        MOVE ZERO TO asm
        MOVE ZERO TO bsm
        PERFORM UNTIL a <= ZERO
            DIVIDE 10 INTO a GIVING a REMAINDER r
            ADD r TO asm
        END-PERFORM
        PERFORM UNTIL b <= ZERO
            DIVIDE 10 INTO b GIVING b REMAINDER r
            ADD r TO bsm
        END-PERFORM
        ADD asm TO bsm
        IF bsm < sm
            MOVE bsm TO sm
        END-IF
    END-PERFORM.

    MOVE sm TO ZS.

    PERFORM UNANS.

    DISPLAY ans(1:FUNCTION STORED-CHAR-LENGTH(ans)).
    STOP RUN.

UNANS                            SECTION.
    UNSTRING
        ZS DELIMITED BY ALL SPACE
        INTO DUMMY ans
    END-UNSTRING.


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

int main() {

  int a, b, c;
  cin >> a >> b >> c;
  vector<int> v = {a, b, c};
  int Mx, Md, Mn;
  Mx = max(max(a, b), c);
  Mn = min(min(a, b), c);
  Md = a + b + c - Mx -Mn;
  cout << Mn << " " << Md << " " << Mx << endl;

}



Measured memory_bytes: 3084
#include <iostream>
#include <cstdio>

using namespace std;

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

int main() {
	while (true) {
		int n, m, ans = 0, count = 0;
		bool I = false;
		
		cin >> n;
		if (n == 0) break;
		cin >> m;
		
		REP(i, m) {
			int c = getchar();
			if (c == 'I' && !I) { I = true; count++; }
			else if (c == 'O' && I) I = false;
			else {
				if (count > n) ans += count - n;
				if (c == 'I') { I = true; count = 1; }
				else { I = false; count = 0;}
			}
		}
		if (count > n) ans += count - n;
		getchar();
		
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 1160
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll P=998244353;
#define endl "\n"
ll power(ll n,ll k)
{
    ll x=k;
    ll ans=1;
    while(x!=0)
    {
           if(x&1)
           {
               ans=(n*ans)%P;
           }
           n=(n*n)%P;
           x>>=1;
    }
    return ans;
}
vector<ll> adj[1000001];
ll mp[1000001];
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    ll i,j,k,l,m,n,o,p,q,r,s,t;
    cin>>n;
    vector<ll> v1,v2;
    for(i=1;i<=n;i++)
    {
        cin>>j>>k;
        v1.push_back(j);
        v2.push_back(k);
    }
    ll ans=0;
    sort(v1.begin(),v1.end());
    sort(v2.begin(),v2.end());
    if(n%2==1)
    {
        ans=v2[n/2]-v1[n/2]+1;
    }
    else 
    {
        ans=v2[n/2]+v2[n/2-1]-(v1[n/2]+v1[n/2-1])+1;
    }
    cout<<ans<<endl;
    return 0;
}


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

using namespace std;

template< typename T >
struct WeightedGraph
{
  struct edge
  {
    int to;
    T cost;
  };

  vector< vector< edge > > g;

  WeightedGraph() {}

  WeightedGraph(int n) : g(n) {}

  void add_edge(int u, int v, T cost)
  {
    g[u].emplace_back((edge) {v, cost});
  }

  vector< edge > &operator[](int k)
  {
    return g[k];
  }

  size_t size() const
  {
    return g.size();
  }
};

template< typename T >
vector< T > dijkstra(WeightedGraph< T > &g, int s)
{
  const auto INF = numeric_limits< T >::max();
  vector< T > dist;
  dist.assign(g.size(), INF);

  using Pi = pair< T, int >;
  priority_queue< Pi, vector< Pi >, greater< Pi > > que;
  dist[s] = 0;
  que.emplace(dist[s], s);
  while(!que.empty()) {
    T cost;
    int idx;
    tie(cost, idx) = que.top();
    que.pop();
    if(dist[idx] < cost) continue;
    for(auto &e : g[idx]) {
      auto next_cost = cost + e.cost;
      if(dist[e.to] <= next_cost) continue;
      dist[e.to] = next_cost;
      que.emplace(dist[e.to], e.to);
    }
  }
  return dist;
}

int main()
{
  int V, E, S;
  cin >> V >> E >> S;
  WeightedGraph< int > g(V);
  for(int i = 0; i < E; i++) {
    int x, y, z;
    cin >> x >> y >> z;
    g.add_edge(x, y, z);
  }
  auto cost = dijkstra(g, S);
  for(int i = 0; i < V; i++) {
    if(cost[i] == numeric_limits< int >::max()) cout << "INF" << endl;
    else cout << cost[i] << endl;
  }
}


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

int check(string s, int n){
  int i;
  string t;
  rep(i, n){
    t += s[n - i - 1];
  }
  rep(i, n){
    if(s[i] != t[i]){
      return 0;
    }
  }
  return 1;
}

int main(){
  ll N, M, i;
  string S, T, U, ans, t;
  cin >> S;
  rep(i, S.size()){
    if(i <= S.size()/2 - 1){
      T += S[i];
    } else if(i > S.size()/2){
      U += S[i];
    }
  }
  
  if(check(S, S.size()) == 1 && check(T, T.size()) == 1 && check(U, U.size()) == 1){
    ans = "Yes";
  } else {
    ans = "No";
  }
  
  cout << ans << endl;
  return 0;
}

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

using namespace std;

int main(){
	int n, m;
	cin >> n >> m;
	
	int L, R;
	L = 1;
	R = n;
	
	for (int i=0; i<m; ++i){
		int l, r;
		cin >> l >> r;
		
		L = max(l, L);
		R = min(r, R);
	}
	
	if (R >= L){
		cout << R - L + 1 << endl;
	}else{
		cout << 0 << endl;
	}
	
}

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

#define fst(t) std::get<0>(t)
#define snd(t) std::get<1>(t)
#define thd(t) std::get<2>(t)
#define unless(p) if(!(p))
#define until(p) while(!(p))

using ll = std::int64_t;
using P = std::tuple<int,int>;

int D, G;
int p[15], c[15];

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

    std::cin >> D >> G;

    for(int i=1;i<=D;++i){
        std::cin >> p[i] >> c[i];
    }

    int mn = 1001001001;

    for(int _s=0;_s<(1<<D);++_s){
        int s = _s * 2;
        int solved = 0, score = 0;

        for(int i=1;i<=D;++i){
            if(s >> i & 1){
                solved += p[i];
                score += i * 100 * p[i] + c[i];
            }
        }

        for(int i=D;i>=1;--i){
            if(score >= G){
                break;
            }

            if(s >> i & 1){
                continue;
            }

            int x = std::min(p[i], (G - score + 100 * i - 1) / (100 * i));

            solved += x;
            score += 100 * i * x;
        }

        if(score >= G){
            mn = std::min(mn, solved);
        }
    }

    std::cout << mn << std::endl;
}


Measured memory_bytes: 256
#include<iomanip>
#include<limits>
#include<thread>
#include<utility>
#include<iostream>
#include<string>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<stack>
#include<queue>
#include<cmath>
#include<numeric>
#include<cassert>
#include<random>
#include<deque>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
const int error=1e9+7;
#define F first
#define S second
#define MK make_pair






int main(){
    vector<int> a(210000);
    int n,k;
    cin>>n>>k;
    for(int i=0;i<n;i++){
        int b;
        cin>>b;
        a[b]++;
    }
    sort(a.begin(),a.end());
    int count=0;
    for(int i=0;i<a.size()-k;i++){
        count+=a[i];
    }
    cout<<count<<endl;
    
    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define INF 1e9

void increaseHeight(const vector<int> &H, vector<int> & H_c, const int l, const int r, int &count) {
  int min_h = INF;
  for (int i = l; i <= r; i++) {
    int diff = H[i] - H_c[i];
    if(min_h > diff) {
      min_h = diff;
    }
  }
  
  if (min_h != INF) {
    count += min_h;
    for (int i = l; i <= r; i++) {
      H_c[i] += min_h;
    }

    int i, start = l, end;
    for (i = l; i <= r; i++) {
      if (H[i] - H_c[i] == 0) {
	end = i - 1;
	if (end >= start) increaseHeight(H, H_c, start, end, count);
	start = i + 1;
      }
    }
    increaseHeight(H, H_c, start, r, count);
  }
}

int main() {
  int N;
  cin >> N;
  
  vector<int> H, H_c(N, 0);
  H.reserve(N);
  for (int i = 0; i < N; i++) {
    int h;
    cin >> h;
    H.emplace_back(h);
  }
  
  int count = 0;
  increaseHeight(H, H_c, 0, N - 1, count);
  
  cout << count << endl;
  return 0;
}

Measured memory_bytes: 256
use proconio::{input, fastout};

#[fastout]
fn main() {
    input! {
        n: usize,
    }

    let mut f = vec![0usize; n];
    let sqrt_n = (n as f64).sqrt() as usize;

    for x in 1..=sqrt_n {
        for y in 1..=sqrt_n {
            for z in 1..=sqrt_n {
                let ans = x * x + y * y + z * z + x * y + y * z + z * x;
                if ans <= n {
                    f[ans-1] += 1;
                } 
            }
        }
    }

    for i in f.into_iter() {
        println!("{}", i);
    }
}


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

//Lottery
public class Main {

	public static void main(String[] args) {
		boolean[] p = new boolean[1000001];
		int[] s = new int[1000001];
		Arrays.fill(p, true);
		p[0]=p[1]=false;
		for(int i=2;i<1000001;i++){
			s[i] = s[i-1];
			if(p[i]){
				s[i]++;
				for(int j=i*2;j<1000001;j+=i)p[j]=false;
			}
		}
		Scanner sc = new Scanner(System.in);
		while(true){
			int n = sc.nextInt();
			if(n==0)break;
			int prime = 0;
			while(n--!=0){
				int P = sc.nextInt();
				int m = sc.nextInt();
				int l = Math.max(1, P-m);
				int r = Math.min(1000000, P+m);
				int x = s[r]-s[l-1];
				if(x==0)prime--;
				else prime+=x-1;
			}
			System.out.println(prime);
		}
	}
}

Measured memory_bytes: 43144
// 2020 1.22 選択ソート

#include <stdio.h>
#define N 100

int main()
{
    int a,min=0,temp,cnt=0;
    int i,j;
    int array[N];

    scanf("%d",&a);
    for(i=0;i<a;i++)
    {
        scanf("%d",&array[i]);
    }
    for(j=0;j<a;j++)
    {
    min = array[j];
    temp = j;
    //printf("%d\n",min);
    for(i=j;i<a;i++)   //最小値求める
    {
        if(min <= array[i])
        {
          continue;
        }
        else
        {
           min = array[i];
           temp = i; //場所変えるための一時変数
        } 
    }
    //printf("k%d\n",min);
    if(j != temp) cnt++;
    int temp2 = array[j];
    array[j] = min;
    array[temp] = temp2;

    /* for(i=0;i<a;i++)
    {
        printf("%d",array[i]);
        if(i != a-1) printf(" ");
    }
    printf("\n"); */
    }

    for(i=0;i<a;i++)
    {
        printf("%d",array[i]);
        if(i != a-1) printf(" ");
    }
    printf("\n");
    printf("%d\n",cnt);  
    return 0;
}


Measured memory_bytes: 2056
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n;
  cin >> n;
  set<int> s;
  s.insert(n);
  int count = 1;
  while(true)
  {
    if(n%2 == 0)
    {
      n/=2;
    }
    else
      n = 3*n+1;
    count++;
    if(s.find(n) != s.end())
    {
      cout << count;
      return 0;
    }
    s.insert(n);
  }
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(){
	int x,y;
	scanf("%d%d",&x,&y);
	if(x>3&&y>3)
		printf("0\n");
	else
	{if(x==1&&y==1)
			printf("1000000\n");
	else if(x==1&&y==2)
			printf("500000\n");
	else if(x==1&&y==3)
			printf("400000\n");
	else if(x==1&&y>3)
		printf("300000\n");
	else if(x==2&&y==1)
		printf("500000\n");
	else if(x==2&&y==2)
		printf("400000\n");
	else if(x==2&&y==3)
		printf("300000\n");
	else if(x==2&&y>3)
		printf("200000\n");
	else if(x==3&&y==1)
		printf("400000\n");
	else if(x==3&y==2)
		printf("300000\n");
	else if(x==3&&y==3)
		printf("200000\n");
	else if(x==3&&y>3)
		printf("100000\n");
	else if(x>3&&y==1)
		printf("300000\n");
	else if(x>3&&y==2)
		printf("200000\n");
	else if(x>3&&y==3)
		printf("100000\n");
	}
	return 0;
}

Measured memory_bytes: 128
N,M = map(int,input().split())
H = list(map(int,input().split()))

li = set(range(0, N))

for i in range(M):
    a,b = map(int,input().split())
    if H[a-1] < H[b-1]:
        li.discard(a-1)
    elif H[a-1] > H[b-1]:
        li.discard(b-1)
    else:
        li.discard(a-1)
        li.discard(b-1)

#print(li)
print(len(li))

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

using namespace std;

int main()
{
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int n, k;
    cin >> n >> k;
    vector<pair<int, int>> edges;
    for(int i = 2; i <= n; i++)
      edges.push_back({1, i});
    if(((n - 2) * (n - 1)) / 2 < k)
    {
      cout << -1;
      return 0;
    }
    int have = ((n - 1) * (n - 2)) / 2;
    for(int i = 2; i <= n; i++)
    {
      if(have == k)
        break;
      for(int j = i + 1; j <= n; j++)
      {
        if(have == k)
          break;
        edges.push_back({i, j});
        have--;
      }
    }
    cout << edges.size() << '\n';
    for(auto &edg: edges)
      cout << edg.first << ' ' << edg.second << '\n';
    return 0;
}


Measured memory_bytes: 384
#include "bits/stdc++.h"
using namespace std;

typedef long long ll;

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

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

	ll sum=0, ans=0;
	for (int i = 0; i < N; i++) {
		if (A[i] < B[i]) {
			sum += A[i] - B[i];
			ans++;
		}
	}

	if (sum == 0) {
		cout << 0 << endl;
		return 0;
	}

	vector<ll> C;
	for(int i=0; i<N; i++) if(A[i] >= B[i]) C.push_back(A[i]-B[i]);
	sort(C.rbegin(),C.rend());


	for (int i = 0; i < C.size(); i++) {
		sum += C[i];
		ans++;
		if(sum>=0) break;
	}

	if (sum < 0) {
		cout << -1 << endl;
		return 0;
	}

	cout << ans << endl;

}



Measured memory_bytes: 2428
import java.util.*;

public class Main {
public static void main(String[] args) {
		
		Scanner keyboard = new Scanner(System.in); 
		
		int X  = keyboard.nextInt();
		int[] A = new int[X];
		
		for(int i=0; i<X; i++) {
			A[i] = keyboard.nextInt();
		}
		
		Arrays.sort(A);
		
		int ans = 0;
		final int nmax = 1000010;		
		int[] hako = new int[nmax];

		for(int j=0; j<X; j++) {
			if(hako[A[j]] == 0) {
				if(j == X-1 || A[j] != A[j+1]) {
					ans++;
				}
				for(int k=1; k*A[j]<nmax; k++) {
					hako[k*A[j]] = 1;
				}
			}
		}
		
			
		System.out.print(ans);
		keyboard.close();	
	}
}


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

using namespace std;
int main(void){
 int n,k;
 double x,ans=0;
 char s;

 cin>>n;

 for(int i=0; i<n; i++){
  cin>>x>>s>>s>>s;
  if(s=='C')ans+=(380000*x);
  else ans+=x;
 }

 cout<<setprecision(20)<<ans;
 return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define FOR(i,a,n) for(int i=(a); i<(n); i++)
#define all(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9+7;

const int annual = 195;
const int leap = 200;

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

    int n; cin >> n;
    rep(nn, n) {
        int y, m, d; cin >> y >> m >>d;
        int ans = 0;
        FOR(i, y+1, 1000) {
            if (i%3 != 0) ans += annual;
            else ans += leap;
        }
        FOR(i, 1, 11) FOR(j, 1, 21) {
            if ((i<m) || (i==m && j<d)) continue;
            if (y%3!=0 && i%2==0 && j==20) continue;
            ans++;
        }
        cout << ans << endl;
    }
}


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

typedef long long ll;
#define rep(i, n) for(ll i=0; i<n; i++)
#define FOR(i, a, b) for(ll i=a; i<b; i++)
#define sz(v) ll(v.size)


void solve(long long N, std::vector<long long> W){
    ll min = 10000000;
    rep(i, N) {
        ll sum1 = 0;
        ll sum2 = 0;
        rep(j, i) {
            sum1 += W[j];
        }
        FOR(j, i, N) {
            sum2 += W[j];
        }
        if (min > abs(sum1-sum2)) {
            min = abs(sum1-sum2);
        }
    }
    cout << min << endl;
}

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


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

//typedef
//------------------------------------------
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef vector<bool> VB;
typedef vector<PII> VP;


//REPEAT
//------------------------------------------
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define RFOR(i, m, n) for(int i = m;i > n;i--)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,m)  RFOR(i,m,0)

//container util
//------------------------------------------
#define pb(a) push_back(a)
#define fst first
#define snd second
#define SORT(V) sort((V).begin(),(V).end())
#define REV(V) reverse((V).begin(),(V).end())

//constant
//------------------------------------------
const int MOD = 1000000007;
const int INF = 1061109567;
const double EPS = 1e-10;
const double PI  = acos(-1.0);
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

//grobal variable
//------------------------------------------

//def function, class
//------------------------------------------

//main
//------------------------------------------
signed main(){
  int N, M;
  cin >> N >> M;
  VI a(N);//どのスイッチを押すとどの電球が点灯するのかの表を作る

  REP(i, M){//iは電球の名前
    int k;//kは電球iが接続しているスイッチ数
    cin >> k;
    REP(j, k){//繋がっているスイッチをビットの形で取得
      int s;
      cin >> s;
      s--;
      a[s] |= 1<<i; //001 |= 1<<2 -> 001 |= 100 -> 101
      //101はスイッチsが1，3に繋がっていて2に繋がっていない状況
    }
  }

  int p=0;
  REP(i, M){
    int x;
    cin >> x;
    p |= x<<i;
  }

  int ans=0;

  REP(s, 1<<N){//1<<N = 2^N，これでどのスイッチがonなのか全通り試せる
    int t=0; //どの電球がついてるか
    REP(i, N){
      if(s>>i&1) t^=a[i];
      //iビット目が立っていれば(スイッチのi番目がonならば)，
      //t xor a[i](a[i]の表に従って電球が点灯)
    }
    if(t==p) ans++;
  }

  cout << ans << endl;

  return 0;
}


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

int main() {
  int N, K;
  cin >> N >> K;
  vector<int> x(N);
  for (int i = 0; i < N; i++) cin >> x[i];
  int ans = 3 * 1e8 + 1;
  for (int i = 0; i <= N - K; i++) {
    int dis = min(abs(x[i]) + abs(x[i + K - 1] - x[i]), abs(x[i + K - 1]) + abs(x[i + K - 1] - x[i]));
    ans = min(dis, ans);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define int long long
signed main(){
  int n;
  cin>>n;
  int A[n];
  for(int i=0;i<n;i++) cin>>A[i];
  int ans=0;
  for(int i=0;i<n;i++){
    int minj=i;
    for(int j=i;j<n;j++){
      if(A[j]<A[minj]){
	minj=j;
      }
    }
    if(i!=minj){
      swap(A[i],A[minj]);
      ans++;
    }
  }
  for(int i=0;i<n;i++) cout<<A[i]<<" \n"[i==n-1];
  cout<<ans<<endl;
  return 0;
}



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

int main(void) {
    int N,n,i, ret;
    char str[8];
    fgets(str, 8, stdin);

    N = atoi(str);
    if ((N % 2) == 1) {
        n = N - 1;
        ret = N + ((n+1) * (n/2));
    } else {
        n = N;
        ret = ((n + 1) * (n/2));
    }

    printf("%d\n", ret);

    return 0;
}


Measured memory_bytes: 128
S=input()
n=w=s=e=0
for c in S:
    if c=='N':
        n+=1
    elif c=='W':
        w+=1
    elif c=='S':
        s+=1
    elif c=='E':
        e+=1
ok=(n==s==0 or (n>0 and s>0)) and (w==e==0 or (w>0 and e>0))
ans="Yes" if ok else "No"
print(ans)

Measured memory_bytes: 8800
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		int N = sc.nextInt();
		
		double[] V = new double[N];
  		
		double ave = 0;
		int max = 0;
	    int max2 = 0;
		for(int i = 0 ;i<N;i++){
			V[i] = sc.nextInt();
        }
      
      	Arrays.sort(V);
      
      	for(int i = 1 ;i<N;i++){
			if(ave == 0){
              ave = (V[0] + V[1]) / 2;
            }else{
              ave = (ave + V[i]) /2;
            }
        }
 	  
      
		System.out.println(ave);
	}
}

Measured memory_bytes: 23124
import itertools, operator, collections
N = int(input())
A = sorted([int(input()) for _ in range(N)])[::-1]
sA = set(a & -a for a in A)
cumxor = list(itertools.accumulate(A, func=operator.xor))[-1]
cnt = 0
for i in range(30, -1, -1):
    if cumxor & 2**i:
        if 2**i in sA:
            cumxor ^= 2**(i + 1) - 1
            cnt += 1
        else:
            print(-1)
            exit()
print(cnt)


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

using namespace std;

typedef long long ll;
#define int ll
typedef long double ld;

typedef pair<int,int> pii;
#define x first
#define y second

signed main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    string n;
    cin>>n;
    bool ok=false;
    for(char c:n)
        if(c=='7')
            ok=true;
    cout<<(ok?"Yes\n":"No\n");
}


Measured memory_bytes: 3640
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskB solver = new TaskB();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskB {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int N = in.nextInt();
            String[] S = new String[N];
            for (int i = 0; i < N; i++) {
                S[i] = in.next();
            }
            for (int i = 0; i < N; i++) {
                if (S[i].equals("Y")) {
                    out.println("Four");
                    return;
                }
            }
            out.println("Three");
        }

    }
}



Measured memory_bytes: 23764
#include <bits/stdc++.h>
using namespace std;
#define sort(vec) sort(vec.begin(),vec.end())
#define reverse(vec) reverse(vec.begin(),vec.end())
#define unsort(vec); sort(vec);reverse(vec);
#define int long long
long long ans;

int gcd(int x,int y){
	if(y==0) return x;
	else return gcd(y,x%y);
}

int lcm(int x,int y){
	return x/gcd(x,y)*y;
}
 
signed main(){
	int n,sum=0,x=0,mi(100000000000000000);
	cin>>n;
	vector<int>vec(n);
	for(int i=0;i<n;i++){
		cin>>vec[i];
		sum+=vec[i];
	}
	for(int i=0;i<n-1;i++){
		int y;
		x+=vec[i];
		y=sum-x;
		mi=min(mi,abs(x-y));
	}
	cout<<mi<<endl;
}


Measured memory_bytes: 1792
/*
 
@author
_      _          _                 _      _
\\    // /\    | | \  |     |    /\ \\    //     
 \\  // /__\   | |_/  |_____|   /__\ \\  //
  \\// /    \  | | \  |     |  /    \ \\//
   \/ /      \ | |_/  |     | /      \ \/
@ Indian Institute of Technology Bhilai

With practice comes perfection,
with knowledge comes wisdom.
Incorporate wisdom in you, practice will harvest better results.
Always learn from others, your method is good but someone's even better.
Results take time, run for wisdom, for innovation, for getting better.
Points are mere objects, either you solve first or you solve better.
Seek for betterment, for quality, pace is important but cannot outstand
the quality you persist.
Times are bad just as now but it'll improve, this is my passion and I promise 
I won't let it go. I'll build myself again like a fighter gets back up after 
being thrown to the ground.
I'll learn. I bet that. I promise that.
*/
 
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ul;
#define rep(i,n) for(ll i=0; i<n; i++)
#define rep1(i,n) for(ll i=1; i<=n; i++)
#define pb push_back
#define fi first
#define se second
#define all(v) v.begin(), v.end()
#define alla(arr,n) arr, arr+n
#define yes cout<<"YES\n"
#define no cout<<"NO\n"
#define fsync ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
const ll maxx =  1e9+7;

bool compare(const pair<ll,ll> &a, const pair<ll,ll> &b){
    return a.fi>b.fi;
}

ll inline power(ll a, ll b, ll p){
    a %= p;
    ll ans = 1;
    while(b>0){
        if(b & 1)
            ans = (ans*a)%p;
        a = (a*a)%p;
        b >>= 1;
    }
    return ans;
}

ll inv(ll n, ll p){
    return power(n,p-2, p);
}

bool inline isPrime(ll n) { 
    if (n <= 1)  return false; 
    if (n <= 3)  return true; 
    if (n%2 == 0 || n%3 == 0) return false; 
    for (ll i=5; i*i<=n; i=i+6) 
        if (n%i == 0 || n%(i+2) == 0) 
           return false; 
    return true; 
}

template<class T>
void printv(T &v, ll n){
    if(n==-1)
        n = v.size();
    rep(i,n)
        cout << v[i] << " ";
    cout << "\n";
}

void solve(){
    string s;
    cin>>s;
    ll n=s.length();
    for(ll i=n-1; i>=0; i--){
        if(s[i]=='P' || s[i]=='D')
            continue;
        if(i==n-1){
            s[i]='D';
            continue;
        }
        if(s[i+1]=='P')
            s[i]='D';
        else{
            if(i && s[i-1]=='P')
                s[i]='D';
            else
                s[i]='P';
        }
    }
    cout << s << "\n";
}

int main(){
    fsync
    ll test=1;
    // cin >> test;
    while(test--){
        solve();
    }
}

Measured memory_bytes: 3748
#include<bits/stdc++.h>
/* #define int long long */
/* #define double long double */
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define repa(i, s, n) for(int i = s; i < (int)n; i++)
#define MOD 1000000007
using namespace std;
using ll = long long;
typedef vector<int> vi;
typedef pair<int, int> P;
#define rrep(i,a,b) for(int i=a;i>=b;i--)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

signed main(){
    int a, b, c;
    cin >> a >> b >> c;
    bool isOK = false;
    if(a == b && a != c) isOK = true;
    if(b == c && a != b) isOK = true;
    if(c == a && a != b) isOK = true;
    if(isOK) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 3584
def main():
    H,W = map(int,input().split())
    strings = []

    for h in range(H):
        inp = input()
        if not "#" in inp:
            continue
        strings.append(inp)


    #横の行が消えてるかテスト
    #print("")
    #for s in strings:
    #    print(s)

    delete_row = [False] * W
    for i in range(W):
        if all([string[i]=="." for string in strings]):
            delete_row[i] =True


    #filter
    new_strings = []
    for string in strings:
        temp_s = ""
        for i,c in enumerate(string):
            if not delete_row[i]:
                temp_s = temp_s + c
        new_strings.append(temp_s)
    #print()


    for string in new_strings:
        print(string)











if __name__ == '__main__':
    main()


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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i < (int)(n); i++)
using ll = long long;

int main(){
  int n;
  cin>>n;
  vector<ll> a(n),sunuke(n),arrai(n);
  ll sum = 0;
  rep(i,n){
    cin>>a.at(i);
    sum += a.at(i);
  }
  sunuke.at(0) = a.at(0);
  arrai.at(0) = sum - sunuke.at(0);
  ll dif = abs(sunuke.at(0)-arrai.at(0));
  rep1(i,n-1){
    sunuke.at(i) = sunuke.at(i-1)+a.at(i);
    arrai.at(i) = sum - sunuke.at(i);
    dif = min(abs(sunuke.at(i)-arrai.at(i)),dif);
  }
  cout<<dif<<endl;
  
  return 0;
}

Measured memory_bytes: 4992
n = int(input())
data = []
datb = []
res = 0
import math
for _ in range(n):
    a,b = map(int, input().split())
    data.append(a)
    datb.append(b)

for i in range(n-1, -1, -1):
    a,b = data[i], datb[i]
    a += res
    t = math.ceil(a / b)
    t = b * t
    res += t - a
print(res)


Measured memory_bytes: 11852
import java.util.*;
import java.util.Map.Entry;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        long m = sc.nextLong();
        long[] sum = new long[n];
        Map<Long, Long> map = new HashMap<>();
        map.put(0L, 1L);
        for (int i = 0; i < n; i++) {
            long a = sc.nextLong();
            if(i == 0) sum[i] = a % m;
            else sum[i] = (sum[i-1] + a) % m;
            if(!map.containsKey(sum[i])) map.put(sum[i], 1L);
            else map.put(sum[i], map.get(sum[i]) +1);
        }
        long ans = 0L;
        for(Entry<Long, Long> e : map.entrySet()){
            ans += e.getValue() * (e.getValue()-1) / 2;
        }
        System.out.println(ans);
        sc.close();

    }

}


Measured memory_bytes: 63916
#include <iostream>
#include <array>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>

using namespace std;
using ll = long long;

ll N;
vector<vector<ll>> tree;

void input() {
    cin >> N;
    tree.resize(N+1);
    for (ll i = 0; i < N-1; i++) {
        ll a, b;
        cin >> a >> b;
        tree[a].push_back(b);
        tree[b].push_back(a);
    }
}

ll set_length(ll c, ll f, ll s, vector<ll> &lens)  {
    ll res = s;
    lens[c] = s;
    for (auto t : tree[c]) {
        if (t == f)
            continue;
        res = max(res, set_length(t, c, s+1, lens));
    }
    return res;
}

ll tree_size(ll c, ll f, ll s) {
    ll res = s;
    for (auto t : tree[c]) {
        if (t == f)
            continue;
        res = max(res, tree_size(t, c, s+1));
    }
    return res;
}

bool solve() {
    vector<ll> lens(N+1);
    set_length(1, 0, 0, lens);
    ll start = (max_element(lens.begin(), lens.end()) - lens.begin());
    ll len = tree_size(start, 0, 0);
    cerr << len << endl;
    return (len-1)%3 == 0;
}

int main() {
    input();
    cout << (solve() ? "Second" : "First") << endl;
    //    solve();
    
    return 0;
}



Measured memory_bytes: 25216
#include<bits/stdc++.h>
using namespace std;
char s[100005];
int a[100005];
void dfs(int l,int r){
	int flag=0,point=0;
	for(int i=l;i<r;i++){
		if(s[i]=='L'&&s[i+1]=='R'){
			flag=1;
			dfs(l,i);
			dfs(i+1,r);
			return;
		}
		if(s[i]=='R'&&s[i+1]=='L')point=i;
	}
	int x=(point-l+2)/2;
	a[point]+=x;
	a[point+1]+=point-l+1-x;
	int y=(r-point+1)/2;
	a[point+1]+=y;
	a[point]+=r-point-y;
	return;
}
int main(){
	scanf("%s",s+1);
	int len=strlen(s+1);
	dfs(1,len);
	for(int i=1;i<=len;i++)cout<<a[i]<<" ";
		
}


Measured memory_bytes: 896
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <iostream>
#include <math.h>
#include <map>
using namespace std;


#define ARRAYMAX 2*100000
int person[ARRAYMAX];

#define DEBUG

map<int, int> mp;

int main()
{
    int i, j, k, m;

    
    int K;
    cin >> K;

    int A,B;
    cin >> A>>B;

    int OK = 0;
    for (i = A;i <= B;i++)
    {
        if (i % K == 0)
        {
            OK = 1;
            break;
        }

    }

    if (OK == 1)
    {
        printf("OK\n");
    }
    else
    {
        printf("NG\n");

    }


    return 0;
}


Measured memory_bytes: 3624
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <numeric>
#include <tuple>
#include <stack>

#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) x.begin(),x.end()
#define print(s) cout << s << endl
typedef long long ll;
using namespace std;

int ctoi(char c) {
	if (c >= '0' && c <= '9') {
		return c - '0';
	}
	return 0;
}

int main() {
	int n,d,x; cin >> n >> d >> x;
	vector<int> v(n);
	x += n;
	rep(i,n){
		cin >> v[i];
		x += (d-1)/v[i];
	}
	cout << x << endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
  int d;
  
  scanf("%d", &d);
  
  if(d==25) printf("Christmas");
  else if(d==24) printf("Christmas Eve");
  else if(d==23) printf("Christmas Eve Eve");
  else if(d==22) printf("Christmas Eve Eve Eve");
  
  return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <cstdlib>
using namespace std;
int main(){
      string ch;
      int stack[150],top=-1;
      while(cin>>ch){
            switch(ch[0]){
                  case '+':
                        stack[top-1]+=stack[top];
                        top--;
                        break;
                  case '-':
                        stack[top-1]-=stack[top];
                        top--;
                        break;
                  case '*':
                        stack[top-1]*=stack[top];
                        top--;
                        break;
                  case '/':
                        stack[top-1]/=stack[top];
                        top--;
                        break;
                  default:
                        stack[top+1]=atoi(ch.c_str());
                        top++;
            }
      }
      cout<<stack[0]<<endl;
}

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



int main() {
    int n;
    cin>>n;
    
    int k=1,x=0,count=0;
    for(int i=0;i<n;i++){
        cin>>x;
        if(x==k){
            
            k++;
        }
    }
    if(k==1)    cout <<-1 << endl;
    else        cout<<n-k+1<<endl;
    return 0;
}


Measured memory_bytes: 3572
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define strall(v) (v).cbegin(),(v).cend()
using namespace std;
using ll = long long;
using P = pair<int,int>;
using Graph = vector<vector<int>>;
template<class t,class u> void chmax(t&a,u b){if(a<b)a=b;}
template<class t,class u> void chmin(t&a,u b){if(b<a)a=b;}
//const long long INF = 1LL << 60;
 int INF = 500000;
 int MAX = 2050;
 ll mod = 1e9+7;

ll fac[2050];//n!
ll finv[2050];//(r!)^(-1)
ll inv[2050];//(n-r)!^(-1)

void COMinit(){
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for(int i=2;i<MAX;i++){
    fac[i] = fac[i-1] * i %mod;
    inv[i] = mod-inv[mod%i] * (mod/i) % mod;
    finv[i] = finv[i-1] * inv[i] % mod;
  }
}
ll COM(int n,int k){
  if(n<k) return 0;
  if(n < 0 || k < 0) return 0;
  return fac[n] * (finv[k] * finv[n-k]%mod) % mod;
}


int main(){
  int n,k;
  cin >> n >> k;
  ll res[k] = {0};
  
  COMinit();
  rep(i,k){
    int tmp = i+1;
    ll pos = COM(n-k+1,tmp);//赤いボールのどの場所に青を配置するか
    ll num = COM(k-1,i);//青玉の分配
    res[i] = (pos*num)%mod;
  }
  rep(i,k) cout << res[i] << endl; 
}


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


int main() {
  map<string,int> mp;
  int n;
  cin >> n;
  for(int i=0;i<n;i++){
      string s;
      cin >> s;
      mp[s]++;
  }
  int max1 = 0;
  for(const auto& value:mp){
      max1 = max(max1,value.second);
  }
  for(auto it = mp.begin();it !=mp.end();it++){
      if(it->second == max1){
          cout << it->first << endl;
      }
  }
  return 0;
}


Measured memory_bytes: 25216
#include <stdio.h>
#include <algorithm>
using namespace std;
using ll = long long;

int n, m, a[100010];
ll dp[100010], mod = 1e9 + 7;
int main() {
	scanf("%d %d", &n, &m);
	for (int i = 0; i < m; i++) {
		scanf("%d", a + i);
		dp[a[i]] = -2e18;
	}
	dp[0] = 1;
	for (int i = 0; i < n; i++) {
		dp[i] = max(0ll, dp[i]) % mod;
		dp[i + 1] += dp[i];
		dp[i + 2] += dp[i];
	}
	printf("%lld\n", dp[n] % mod);
}

Measured memory_bytes: 1280
#include <bits/stdc++.h>
#include <ext/numeric>
/**
       return NO_PAIN ? NO_GAIN : GAIN;
*/
using namespace std;
using namespace __gnu_cxx;

#define all(v)   v.begin(), v.end()
#define sz(x)    (int) x.size()
#define Unique(x) x.erase(unique(all(x)), x.end())
#define endl "\n"
#define pb push_back
#define F first
#define S second
#define START cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
#define isOdd(n)    (n&1)
#define pow(n, m) power(n, m)
#define numOfDigits(n)  ((n)? (ll)(log10(n))+1 : 1)
#define mem(x, val)    memset(x, val, sizeof(x)) //be careful of value and TLE
#define MOD 1000000007
#define EPS 1e-7

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef vector<int> vi;

vi dig;
int k;
string s;
ll dp[20002][100][2];
/*
dp[i][modOfDigits][f1];
index of digit, sum of digits mod k,
 state that we are smaller than b.
 */

ll solve(int i, int modDig, int smaller){
    if(i==sz(dig))  return !modDig;

    ll &ret = dp[i][modDig][smaller];
    if(~ret) return ret;

    ll cnt = 0, mxDig = 0;
    if(smaller) mxDig = 9;
    else mxDig = dig[i];

    for(int j = 0; j<=mxDig; j++){
        int sum = modDig + j;
        sum %= k;
        int sm = (j < mxDig || smaller);
        cnt += solve(i+1, sum, sm)%MOD;
        cnt %= MOD;
    }
    return ret = cnt%MOD;
}
ll pos(string s){
    dig.clear();
    for(int i = 0; i<sz(s); i++){
        dig.pb(s[i]-'0');
    }
    mem(dp, -1);

    return solve(0, 0, 0);
}
int main()
{
    START
    //freopen("test cases\\in.txt", "r", stdin) ;
    //freopen("test cases\\out.txt", "w", stdout);
    cin>>s>>k;
    ll ans = pos(s) - 1;
    cout<<(ans>=0? ans: ans + MOD);
	return 0;
}


Measured memory_bytes: 32640
import sys
from functools import lru_cache

sys.setrecursionlimit(1000000)

H, N = map(int, input().split())

AB = []
for i in range(N):
  A, B = map(int, input().split())
  AB.append((A, B))

'''
H = 10000
N = 1000
import random
AB = []
for i in range(N):
    A = random.randint(1, 10000)
    B = random.randint(1, 10000)
    AB.append((A, B))
'''




@lru_cache(maxsize=None)
def f(h):
    if h <= 0:
        return 0
    best = float('inf')
    for a, b in AB:
        val = b + f(h - a)
        if val < best:
            best = val
        else:
            break
    return best

AB.sort(key=lambda ab: (ab[0] / ab[1], -ab[0]), reverse=True)
bestA, bestB = AB[0]
threshold = sum(a for a, b in AB)

ans = None
times = (H - threshold) // bestA
if times > 0:
    ans = bestB * times + f(H - bestA * times)
else:
    ans = f(H)

print(ans)

Measured memory_bytes: 30180
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cctype>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <functional>
#include <iomanip>
using namespace std;

string to_string(string s) {
  return '"' + s + '"';
}

string to_string(const char* s) {
  return to_string((string) s);
}

string to_string(bool b) {
  return (b ? "true" : "false");
}

template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}

template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto &x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}

void debug_out() { cerr << endl; }

template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}

#ifndef ONLINE_JUDGE
#define show(...) cerr << "[" << #__VA_ARGS__ << "] :", debug_out(__VA_ARGS__)
#else
#define show(...) 42
#endif


#define f first
#define s second
#define endl "\n"
#define pb push_back
#define  oo 0x3f3f3f3f
#define limit 1000000007
#define two pair<int,int>
#define int long long int
#define mod(x,m) ((x%m+m)%m)
#define all(v) v.begin(),v.end()
#define max3(x,y,z) max(x,max(y,z))
#define min3(x,y,z) min(x,min(y,z))
#define fori(x,n) for(int i = x; i < n; i++)
#define forj(y,m) for(int j = y; j < m; j++)
#define fork(z,p) for(int k = z; k < p; k++)
#define fastio std::ios::sync_with_stdio(false)
#define watch(x) cout << (#x) << " is " << (x) << "\n"
#define input_from_file  freopen("input.txt", "r", stdin);

long double dist(int p1,int p2,vector<two> &p){
  long double d = 0;
  d = (long double)((p[p1].f-p[p2].f)*(p[p1].f-p[p2].f)
                     + (p[p1].s-p[p2].s)*(p[p1].s-p[p2].s));
  d = sqrt(d);
  return d;
}

signed main(){
  //input_from_file;
  int n; cin>>n;
  vector<two> p(n+1);
  fori(1,n+1) cin>>p[i].f>>p[i].s;
  string str = "";
  fori(1,n+1) str += to_string(i);
  long double totald = 0;
  long double cnt = 0;
  do {
    cnt += 1;
    fori(1,n) totald += dist(str[i-1]-'0',str[i]-'0',p);
  } while(next_permutation(all(str)));
  long double avgd = totald/cnt;
  cout<<fixed<<setprecision(10)<<avgd<<endl;
}


Measured memory_bytes: 888
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mp make_pair
#define pb push_back
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)

int main(){
  ll a,b;
  cin >>  a >> b;
  if(a*b<=0)cout << "Zero" << endl;
  else if(a>0) cout << "Positive" << endl;
  else if((b-a+1)%2==0) cout << "Positive" << endl;
  else cout << "Negative" << endl;

  return 0;

}


Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#include<iostream>
#include<cstring>
using namespace std;
const int maxn=2e5+5;
bool valid[maxn];
int l_minn[maxn],r_minn[maxn];
int main()
{
    int n,k,c;
    scanf("%d%d%d",&n,&k,&c);
    char s;
    scanf("%c",&s);
    for(int i=1;i<=n;i++)
    {
        scanf("%c",&s);
        valid[i]=(s=='o');
    }
    int cur=-c;
    for(int i=1;i<=k;i++)
    {
        for(int j=cur+c+1;j<=n;j++)
            if(valid[j])
            {
                l_minn[i]=j;
                cur=j;
                break;
            }
    }
    reverse(valid+1,valid+n+1);
    cur=-c;
    for(int i=1;i<=k;i++)
    {
        for(int j=cur+c+1;j<=n;j++)
            if(valid[j])
            {
                r_minn[i]=n+1-j;
                cur=j;
                break;
            }
    }
    reverse(r_minn+1,r_minn+k+1);
    for(int i=1;i<=k;i++)
        if(l_minn[i]==r_minn[i]&&l_minn[i])
            printf("%d\n",l_minn[i]);
    return 0;
}

Measured memory_bytes: 3200
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;

int main() {
  int N;
  cin >> N;
  vector<pair<ll, ll> > W;
  for (int i = 0; i < N; i++) {
    ll a, b;
    cin >> a >> b;
    W.emplace_back(make_pair(b, a));
  }
  sort(W.begin(), W.end());
  ll time = 0;
  for (int i = 0; i < N; i++) {
    time += W[i].second;
    if (time > W[i].first) {
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
  return 0;
}

Measured memory_bytes: 6256
#define _GLIBCXX_DEBUG
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>
using namespace std;
typedef long long ll;
#define ALL(v) (v).begin(), (v).end()
const int mod = 1e9+7;

string S;
bool flg = false;

void dfs(unsigned int itr) {
    if (itr == S.size()) {
        flg = true;
        return;
    }
    
    string s1 = S.substr(itr, 5); 
    string s2 = S.substr(itr, 6);
    string s3 = S.substr(itr, 7);

    if (s1 == "dream" || s1 == "erase") {
        dfs(itr+5);
    }
    if (s2 == "eraser") { 
        dfs(itr+6);
    }
    if (s3 == "dreamer") { 
        dfs(itr+7);
    }
}

int main() {
    cin >> S;

    dfs(0);

    if (flg) cout << "YES" << endl;
    else cout << "NO" << endl;

    return 0;
}


Measured memory_bytes: 4096
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define all(v) v.begin(), v.end()
    
int main(){
    int n,m;
    long long k;
    cin >> n >> m >> k;
    vector <long long> sa(n+1,0),sb(m+1,0);
    long long tmpa = 0, tmpb = 0;
    rep(i,n){
        long long a;
        cin >> a;
        tmpa += a;
        sa[i+1] = tmpa;
    }
    rep(i,m){
        long long b;
        cin >> b;
        tmpb += b;
        sb[i+1] = tmpb;
    }

    long long ans = 0;

    for(int i=0; i<=n; i++){
        long long okb = k - sa[i];
        if(okb < 0);
        else{
            long long ok = -1, ng = m+1;
            while(abs(ok - ng) > 1){
                long long  mid = (ok + ng)/2;
                if(sb[mid] <= okb){
                    ok = mid;
                }
                else{
                    ng = mid;
                }
            }
            if((i+ok) > ans){
                ans = i + ok;
            }
        }
    }

    cout << ans << endl;
    
}

Measured memory_bytes: 6400
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ul;
typedef signed long long ll;
ul over = 1000000007;

mt19937 mt(time(nullptr));
// uniform_int_distribution< int > rand_int(0, 10) // rand[0, 10] inclusive

int main(void)
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed;
  string s;
  cin >> s;
  int a = stoi(s.substr(0, 2)), b = stoi(s.substr(2));
  vector< int > month{31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
  bool f1=false, f2=false;
  if (1<=a && a<=12) f1 = true;
  if (1<=b && b<=12) f2 = true;
  if (f1&&f2) cout << "AMBIGUOUS" << endl;
  else if (f1) cout << "MMYY" << endl;
  else if (f2) cout << "YYMM" << endl;
  else cout << "NA" << endl;
  return 0;
}


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

#define ll long long
#define str string
#define pii pair<int, int>
#define pll pair<ll, ll>
#define fi first
#define se second

#define vc vector<char>
#define vvc vector<vc>
#define vi vector<int>
#define vll vector<ll>
#define vvi vector<vi>
#define vvll vector<vll>
#define vvvll vector<vvll>
#define vs vector<str>
#define vvs vector<vs>
#define vpii vector<pii>
#define vvpii vector<vpii>
#define vpll vector<pll>
#define vvpll vector<vpll>
#define vb vector<bool>
#define vvb vector<vb>
#define rep(i, a, b) for (int i = (a); i < int(b); i++)
#define repi(i, a, b) for (int i = (a); i <= int(b); i++)


using namespace std;
ll INF = LONG_LONG_MAX;
ll mod = 1000000000 + 7;

template <typename T, typename L>
void readVector(vector<T> & _data, L & _size, bool _shift) {
    _data.resize(_size + (ll)_shift);
    for (ll i = (ll)_shift; i < _size + (ll)_shift; i++)
        cin >> _data[i];
}

template <typename T, typename L>
void readMatrix(vector<vector<T>> & _data, L & _rows, L & _cols, bool _shiftRows, bool _shiftCols) {
    _data.resize(_rows + (ll)_shiftRows);
    for (ll i = 0; i < _rows + (ll)_shiftRows; i++)
        _data[i].resize(_cols + (ll)_shiftCols);
    for (ll i = (ll)_shiftRows; i < _rows + (ll)_shiftRows; i++)
        for (ll j = (ll)_shiftCols; j < _cols + (ll)_shiftCols; j++)
            cin >> _data[i][j];
}


//TODO: SOLUTION

ll n;
vll a, pre, f, g;

void computeG() {
    ll j = n - 2;
    g[n - 1] = n;

    while (j >= 1) {
        int k = g[j + 1];
        while (abs(pre[n] - (2*pre[k - 1]) + pre[j - 1]) > abs(pre[n] - (2*pre[k - 2]) + pre[j - 1]))
            k--;
        g[j] = k;
        j--;
    }
}

void computeF() {
    ll j = 3;
    f[2] = 1;

    while (j <= n) {
        int k = f[j - 1];
        while (abs(pre[j] - (2*pre[k])) > abs(pre[j] - (2*pre[k + 1])))
            k++;
        f[j] = k;
        j++;
    }
}

void solve() {
    cin >> n;
    readVector(a, n, 1);
    pre.resize(n + 1, 0);

    repi(i, 1, n) {
        pre[i] = pre[i - 1] + a[i];
    }

    f.resize(n + 1);
    g.resize(n + 1);

    computeF();
    computeG();

    ll ans = INF;
    repi(i, 2, n - 2) {
        ans = min(ans, max(max(max(pre[f[i]], pre[i] - pre[f[i]]), pre[n] - pre[g[i + 1] - 1]), pre[g[i + 1] - 1] - pre[i])
                      -min(min(min(pre[f[i]], pre[i] - pre[f[i]]), pre[n] - pre[g[i + 1] - 1]), pre[g[i + 1] - 1] - pre[i]));
    }

    cout << ans << endl;
}


int main() {

    // TODO: Set value of this variable manually
    bool _multipleTestCases = false;

    if (_multipleTestCases) {
        ll t; cin >> t;
        while (t--)
            solve();
    }
    else {
        solve();
    }

    return 0;
}

Measured memory_bytes: 9612