akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define inf 2147483647
#define ll long long
using namespace std;
struct node{
    int u,v;
    ll cost;
}edge[500005];
ll dis[10005];
int n,m,s;
void init()
{
    for(int i=0;i<n;i++) dis[i]=(i==s?0:inf);
}
bool Bellman_Ford()
{
    init();
    bool flag=true;
    for(int i=0;i<n;i++)
    {
        flag=true;
        for(int j=0;j<m;j++)
        if(dis[edge[j].v]>dis[edge[j].u]+edge[j].cost&&dis[edge[j].u]!=inf)
        {
            dis[edge[j].v]=dis[edge[j].u]+edge[j].cost;
            flag=false;
        }
        if(flag) return true;
    }
    for(int j=0;j<m;j++)
    if(dis[edge[j].v]>dis[edge[j].u]+edge[j].cost&&dis[edge[j].u]!=inf) return false;
    return true;
}
int main()
{
    cin>>n>>m>>s;
    for(int i=0;i<m;i++) cin>>edge[i].u>>edge[i].v>>edge[i].cost;
    if(Bellman_Ford())
    for(int i=0;i<n;i++)
	if(dis[i]!=inf) cout<<dis[i]<<endl;
	else cout<<"INF"<<endl;
    else cout<<"NEGATIVE CYCLE"<<endl;
    return 0;
}


Measured memory_bytes: 3160
package main

import (
	"fmt"
)

var a, b, c, d int

func getGCD(m int, n int) int {
	var tmp int

	for {
		tmp = m % n
		if tmp > 0 {
			m = n
			n = tmp
		} else {
			return n
		}
	}
}

func getLCM(m int, n int) int {
	return m * n / getGCD(m, n)
}

func getCount(n int) int {
	mod := a % n
	var start int
	if mod == 0 {
		start = a
	} else {
		start = a + n - mod
	}
	var count int
	if start > b {
		count = 0
	} else {
		count = (b-start)/n + 1
	}

	return count
}

func main() {
	fmt.Scan(&a, &b, &c, &d)
	x := getLCM(c, d)

	countC := getCount(c)
	countD := getCount(d)
	countX := getCount(x)

	result := b - a + 1 - countC - countD + countX

	fmt.Println(result)
}

Measured memory_bytes: 512
#include <iostream>
#include <algorithm>
using namespace std;
int main(){
    string a[101];
    long long n,i,l;
    cin>>n>>l;
    for(i=0;i<n;i++)
        cin>>a[i];
    sort(a,a+n);
    for(i=0;i<n;i++)
        cout<<a[i];
    return 0;
}

Measured memory_bytes: 256
from collections import Counter
n = int(input())
A = list(map(int, input().split()))
d = Counter(A)
key = d.keys()
ans = []
for k in key:
    if d[k] >= 2:
        ans.append(k)
        if d[k] >= 4:
            ans.append(k)
if len(ans) < 2:
    print(0)
else:
    ans.sort()
    print(ans[-1]*ans[-2])

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

bool is_palindrome(string &s)
{
  string tmp = s;
  reverse(tmp.begin(), tmp.end());
  return (s == tmp);
}

int main()
{
  string s;
  cin >> s;
  string sub_s1 = s.substr(0, (s.size() - 1) / 2);
  string sub_s2 = s.substr((s.size() + 3) / 2 - 1, s.size() - (s.size() + 3) / 2 + 1);
  bool ans = (is_palindrome(s) && is_palindrome(sub_s1) && is_palindrome(sub_s2));
  cout << (ans ? "Yes" : "No") << endl;
}


Measured memory_bytes: 256
// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=1132&lang=jp

#include <iostream>
#include <complex>
#include <cmath>
#include <iomanip>
using namespace std;

typedef complex<double> xy_t;

const xy_t rot[2] = { xy_t(0, 1), xy_t(0, -1) };
const double eps = 1e-6; // 最初から誤差の見積もりがあるのでそれに甘えた。

int main() {
  int N;
  while (scanf("%d", &N) != EOF && N) {
    xy_t P[310];
    for (int i=0; i<N; i++) {
      double X, Y;
      scanf("%lf%lf", &X, &Y);
      P[i] = xy_t(X, Y);
    }
    int ans = 1;
    for (int i=0; i<N; i++) {
      for (int j=i+1; j<N; j++) {
	if ( abs(P[i] - P[j]) > 2 - eps ) continue;
	for (int k=0; k<2; k++) {
	  xy_t c = (P[i] + P[j])/2.0; // 中点
	  xy_t n = (P[i] - P[j]);
	  xy_t m = n/abs(n) * rot[k] * sqrt(1 - abs(n/2.0) * abs(n/2.0));
	  xy_t center = c + m;
	  int count = 0;
	  for (int k=0; k<N; k++) {
	    if (abs(center - P[k]) < 1 + eps) count++;
	    // cerr << fixed << setprecision(10) << abs(center - P[k]) << endl;
	  }
	  ans = max(ans, count);
	}
      }
    }
    printf("%d\n", ans);
  }
}

Measured memory_bytes: 1228
import java.io.*;
public class Main{
	public static void main(String[] args)throws Exception{
		BufferedReader input=new BufferedReader(new InputStreamReader(System.in));
		StringBuilder sb=new StringBuilder();
		while(true){
		String str=input.readLine();
		String[] arr=str.split(" ");
		int h=Integer.parseInt(arr[0]);	
		int w=Integer.parseInt(arr[1]);
		if(h==0&&w==0){
			break;
		}
	
		for(int i=0;i<h;i++){

			for(int j=0;j<w;j++){
				if(i%2==0){
					if(j%2==0){
						sb.append("#");
					}else{
						sb.append(".");
						}
					}

				if(i%2==1){
					if(j%2==1){
						sb.append("#");
					}else{
						sb.append(".");
					}
				}
			}
			
				sb.append("\n");
		}
			sb.append("\n");

	}
		
		
		
		System.out.print(sb);
	}
}

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

const int MXN = 3e3 + 20;

int n;
vector<double> a;
double dp[MXN][MXN], ans;

void npt() {
	cin >> n;
	for (int i = 0; i < n; i++) {
		double tmp;
		cin >> tmp;
		a.push_back(tmp);
	}
}

void slv() {
	for (int i = 0; i < MXN; i++)
		for (int j = 0; j < MXN; j++)
			if (i >= j)
				dp[i][j] = 1;
	dp[1][0] = 1 - a[0];
	for (int i = 1; i <= n; i++)
		dp[i][0] = dp[i - 1][0] * (1 - a[i - 1]);
	for (int i = 1; i <= n; i++)
		for (int j = 1; j <= n; j++) {
			if (i >= j)
				dp[i][j] = dp[i - 1][j] * (1 - a[i - 1]) + 
					dp[i - 1][j - 1] * a[i - 1];
		}
}

void tpt() {
	for (int j = n / 2 + 1; j <= n; j++)
		ans += dp[n][j];
	cout << fixed << setprecision(10) << ans << endl;
}

int main() {
	npt();
	slv();
	tpt();
	return 0;
}


Measured memory_bytes: 69888
#define _CRT_SECURE_NO_WARNINGS
#include <cstdio>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <stack>
#define linkNum 3
const int MAXN = 1000005;
using namespace std;
int x;

int main() {
	cin >> x;
	if (x) cout << 0 << endl;
	else cout << 1 << endl;
	return 0;
}


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

int main(){
  int h,w;
  cin >> h >> w;
  vector<vector<char>> a(h,vector<char> (w));

  for(int i = 0;i < h;i++){
    for(int j = 0;j < w;j++){
      cin >> a.at(i).at(j);
    }   
  }

  
  vector<int> cntH(h),cntW(w);
  int k = 0;
  for(int i = 0;i < h;i++){
    for(int j = 0;j < w;j++){
      if(a.at(i).at(j) == '#'){
        cntH.at(k) = i;
        k++;
        break;
      }   
    }   
  }
  
  int m = 0;
  for(int i = 0;i < w;i++){
    for(int j = 0;j < h;j++){
      if(a.at(j).at(i) == '#'){
        cntW.at(m) = i;
        m++;
        break;
      }   
    }   
  }

  for(int i = 0;i < k;i++){
    for(int j = 0;j < m;j++){
      cout << a.at(cntH.at(i)).at(cntW.at(j));
    }   
    cout << endl;
  }
  return 0;
 }

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
const int N=2e5+9;
const int mod=1e9+7;

int main()
{
#ifndef ONLINE_JUDGE
    freopen("in.txt", "r", stdin);
#endif
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n,x,c;
    ll ans=0;
    cin>>n;
    cin>>x;
    for(int i=0;i<n-1;i++){
    	cin>>c;
    	if(c<x){
    		ans+=abs(x-c);
    		//x=c;
    	}
    	else x=c;
    	
    }
    cout<<ans;
    

}


    


Measured memory_bytes: 3652
#include<queue>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<math.h>
#include<stdlib.h>
#include<stack>
#include<stdio.h>
#include<vector>
#include<map>
#include<string.h>
#define ll long long
#define db double
#define F(n) for(int i=1;i<=n;i++)
using namespace std; 
const int mx=3e5+10;
int main(){
	int a,b,c;
	cin>>a>>b>>c;
	cout<<c<<" "<<a<<" "<<b<<endl;
	return 0;	
}

Measured memory_bytes: 3580
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <algorithm>
#include <iomanip>
#include <math.h>
#include <string.h>
using namespace std; using ll = long long; using pll = pair<ll, ll>;
using vl = vector<ll>; using vll = vector<vl>; using vpll = vector<pll>;
int ctoi(char c) {
	switch (c) {
	case '0': return 0; case '1': return 1; case '2': return 2;
	case '3': return 3; case '4': return 4; case '5': return 5;
	case '6': return 6; case '7': return 7; case '8': return 8;
	case '9': return 9;  default: return 0;
	}
}
bool pairCompare(const pll firstElof, pll secondElof)
{
	return firstElof.second < secondElof.second;
}
ll nod(ll F) { return log10(F) + 1; }
//**定義場所**//
//gcd, isPrime, eratos, modinv, bitSearch, dfs, bfs, dijkstra, UnionFind, COM//
ll i, j, k, l, m, n; ll N, M, K, H, W, L; string S;
ll MOD = 1000000007; ll ans = 0; ll INF = 9999999999999;
vl flag, color; vll path;
//***********//
int main() {
	string S;
	cin >> S;
	cin >> K;
	N = S.length();
	vl A(N);
	for (i = 0; i < N; i++) {
		A[i] = ctoi(S[i]);
	}
	// dp[i][smaller][j]
	// 今調べている桁をi, 未満フラグをsmaller, 0が出た回数をjとする
	vector<vll> dp(N+1, vll(2, vl(K+1, 0)));
	// 0桁目は便宜上0であると考える
	// 0桁目は0しかありえないがこれはsmallerが確定していないのでsmaller=0しかありえない
	// 結局dp[0][0][0]=1, それ以外は全て0で初期化すればよい
	for (i = 0; i < N + 1; i++) {
		for (j = 0; j < 2; j++) {
			for (k = 0; k < K + 1; k++) {
				dp[i][j][k] = 0;
			}
		}
	}
	dp[0][0][0] = 1;
	for (i = 0; i < N; i++) {
		for (ll smaller = 0; smaller < 2; smaller++) {
			for (j = 0; j < K + 1; j++) {
				for (ll x = 0; x <= (smaller ? 9 : A[i]); x++) {
					if (j == K && x > 0) { continue; }
					dp[i + 1][smaller || x < A[i]][j + (x > 0)] += dp[i][smaller][j];
				}
			}
		}
	}
	// smaller=0 から smaller=0 → x = A[i] のとき寄与
	// smaller=0 から smaller=1 → x < A[i] のとき寄与
	// smaller = 1 から smaller = 0 → 常に寄与なし
	// smaller=1 から smaller=1 → 常に寄与
	// j=p から j=p → x=0のとき寄与
	// j=p から j=p+1 → x!=0のとき寄与
	cout << dp[N][0][K] + dp[N][1][K];
}


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

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

	int maxA = A.rbegin()->first;
	vector<int> X(maxA+1, 0);

	int count = 0;
	for (auto it = A.begin(); it != A.end(); it++) {
		int a = it->first;
		if (X[a] == 0) {
			if (it->second == 1) count++;
			while (a <= maxA) {
				X[a] = 1;
				a += it->first;
			}
		}
	}
	cout << count << endl;
	return(0);
}


Measured memory_bytes: 16276
#include<bits/stdc++.h>
using namespace std;
int main()
{
	long long n,a,b;
	scanf("%lld%lld%lld",&n,&a,&b);
	long long sum=n/(a+b)*a;
	long long ans=n%(a+b);
	sum+=min(ans,a);
	printf("%lld",sum);
}

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

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

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

    int cnt = -1;
    bool is_even = true;
    while (is_even) {
        for (int i = 0; i < A.size(); i++) {
            if (A.at(i) % 2 ==0) {
                A.at(i) /= 2;
            }
            else {
                is_even = false;
                break;
            }
        }
        cnt++;
    }

    cout << cnt << endl;
    return 0;
}

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


def solve(N, K, A):
    visited = [1]
    vset = set()
    vset.add(1)
    now = 1
    b = 0
    l = 0
    for _ in range(N):
        now = A[now - 1]
        if now in vset:
            b = visited.index(now)
            l = len(visited) - b
            break
        else:
            visited.append(now)
            vset.add(now)
    if K >= b:
        x = (K - b) % l
        print(visited[b + x])
    else:
        print(visited[K])
    return

# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(N)]
    solve(N, K, A)


if __name__ == '__main__':
    main()

Measured memory_bytes: 127948
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#define LL long long
#define fo(i,j,k) for(int i=j;i<=k;i++)
#define fd(i,j,k) for(int i=j;i>=k;i--)
#define fr(i,j) for(int i=beg[j];i;i=nex[i])
using namespace std;
int const mn=100+3,inf=1e9+7;
int n,m,ans,S,T,cnt,lef[mn][mn],up[mn][mn],gra,beg[mn*mn*2],
	now[mn*mn*2],vis[mn*mn*2],dis[mn*mn*2],
	to[mn*mn*mn*4],size[mn*mn*mn*4],nex[mn*mn*mn*4];
void ins(int u,int v,int w){
	to[++gra]=v;
	size[gra]=w;
	nex[gra]=beg[u];
	beg[u]=gra;
	to[++gra]=u;
	size[gra]=0;
	nex[gra]=beg[v];
	beg[v]=gra;
}
int updis(){
	int tmp=inf;
	fo(i,1,cnt)if(vis[i])fr(j,i)if(size[j]&&(!vis[to[j]]))
		tmp=min(tmp,dis[to[j]]+1-dis[i]);
	if(tmp==inf)return 0;
	fo(i,1,cnt)if(vis[i])dis[i]+=tmp;
	return 1;
}
int add(int p,int T){
	vis[p]=1;
	if(p==T){ans++;return 1;}
	for(int i=now[p];i;i=nex[i],now[p]=i)
		if(size[i]&&(!vis[to[i]])&&(dis[p]==dis[to[i]]+1)){
		int tmp=add(to[i],T);
		if(tmp){
			size[i]--;
			size[i^1]++;
			return 1;
		}
	}
	return 0;
}
int main(){
	gra=1;
	scanf("%d%d\n",&n,&m);
	int sx,sy,tx,ty;
	fo(i,1,n){
		fo(j,1,m){
			char ch=getchar();
			if(ch!='.'){
				cnt++;
				if(ch=='S')S=cnt*2,sx=i,sy=j;
				else if(ch=='T')T=cnt*2-1,tx=i,ty=j;
				fo(k,1,lef[i][0])ins(lef[i][k]*2,cnt*2-1,1),ins(cnt*2,lef[i][k]*2-1,1);
				fo(k,1,up[j][0])ins(up[j][k]*2,cnt*2-1,1),ins(cnt*2,up[j][k]*2-1,1);
				ins(cnt*2-1,cnt*2,1);
				lef[i][++lef[i][0]]=cnt;
				up[j][++up[j][0]]=cnt;
			}
		}
		getchar();
	}
	cnt*=2;
	do{
		fo(i,1,cnt)now[i]=beg[i];
		do{
			memset(vis,0,sizeof(vis));
		}while(add(S,T));
	}while(updis());
	if((sx==tx)||(sy==ty))printf("-1");
	else printf("%d",ans);
	return 0;
}


Measured memory_bytes: 51712
#include<iostream>
#include<string>
#include<cmath>
#include<math.h>
//#include<array>
#include<algorithm>
#include<queue>
#include<deque>
#include<vector>
//#include<utility>
//#include<set>
#include<map>
//#include<list>
//#include<bitset>
//#include<iomanip>

using namespace std;
using LLI = long long int;
LLI N;

//配列,座標
/*array<int, 8>dir_x = { 0,0,1,1,1,-1,-1,-1 };
array<int, 8>dir_y = { 1,-1,1,0,-1,1,0,-1 };
array<int, 4>dir_x2 = { 0,0,1,-1 };
array<int, 4>dir_y2 = { 1,-1,0,0 };
char alp[] = { 'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z' };*/

//Union Find
/*class UnionFind {
public:
	vector<int>data;
	UnionFind(int size) :data(size, -1) {};
	bool unionset(int x, int y) {
		x = root(x), y = root(y);
		if (x != y) {
			if (data[y] < data[x]) {
				swap(x, y);
			}
			data[x] += data[y];
			data[y] = x;
		}
		return x != y;
	}
	bool findset(int x, int y) {
		return root(x) == root(y);
	}
	int root(int x) {
		return data[x] < 0 ? x : data[x] = root(data[x]);
	}
	int size(int x) {
		return -data[root(x)];
	}
};*/

//最大公約数,最小公倍数
/*LLI gcd(LLI x, LLI y) {
	LLI  r;
	if (x < y) {
		swap(x, y);
	}
	r = x % y;
	while (r != 0) {
		x = y;
		y = r;
		r = x % y;
	}
	return y;
}
LLI lcm(LLI x, LLI y) {
	return x / gcd(x, y) * y;
}*/

//組み合わせ
/*long nCr(int n, int r) {
	long ans = 1;
	for (int i = n; i > n - r; i--) {
		ans = ans * i;
	}
	for (int i = 1; i < r + 1; i++) {
		ans = ans / i;
	}
	return ans;
}
long nHr(int n, int r) {
	n = n + r - 1;
	return nCr(n, r);
}*/

//素数判定
/*bool IsPrime(int num)
{
	if (num < 2) return false;
	else if (num == 2) return true;
	else if (num % 2 == 0) return false;

	double sqrtNum = sqrt(num);
	for (int i = 3; i <= sqrtNum; i += 2)
	{
		if (num % i == 0)
		{
			// 素数ではない
			return false;
		}
	}

	// 素数である
	return true;
}*/

//桁数
/*LLI GetDigit(LLI num) {
	LLI digit = 0;
	while (num != 0) {
		num /= 10;
		digit++;
	}
	return digit;
}*/

//サンプル
/*const int n_max = 8;
array<array<bool, n_max>, n_max>graph;
int dfs(int v,int N,array<bool,n_max>visited) {
	int ret = 0;
	bool all_visited = true;
	for (int i = 0; i < N;i++) {
		if (visited[i] == false) {
			all_visited = false;
		}
	}
	if (all_visited) {
		return 1;
	}
	for (int i = 0; i < N;i++) {
		if (graph[v][i] == false) {
			continue;
		}
		if (visited[i] == true) {
			continue;
		}
		visited[i] = true;
		ret += dfs(i,N,visited);
		visited[i] = false;
	}
	return ret;
}*/

//サンプル
/*vector<vector<int>>sub;
int dfs(int id) {
	if (sub[id].size() == 0) {
		return 1;
	}
	int minP = (int)1e9;
	int maxP = 0;
	for (int i : sub[id]) {
		int P = dfs(i);
		minP = min(minP, P);
		maxP = max(maxP, P);
	}
	return minP + maxP + 1;
}*/

//#define debug(x) cerr << #x << " : " << x << endl
//#define debugv(x) cerr << #x << " : "; for(auto i:x) cerr << i << ", "; cerr<<endl

int main(void) {
	LLI L, R, res = 1e9;
	cin >> L >> R;
	if (R - L >= 2019) {
		res = 0;
	}
	else {
		for (LLI i = L; i <= R; i++) {
			for (LLI j = L; j <= R; j++) {
				if (i == j) {
					break;
				}
				else {
					res = min(res, (i * j) % 2019);
				}
			}
		}
	}
	cout << res << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n); for(int i = 0;i < (int)(n);i++)
#define all(x) (x).begin(),(x).end()
typedef long long ll;
int main(){
    ll n,m;
    cin >> n >> m;
    m /= 2;
    if(n>m){
        cout << m << endl;
    }else{
        cout << (n+m)/2 << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define SORT(x) sort(x.begin(),x.end())
#define ALL(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1000000000
#define mod 1000000007
typedef long long ll;
const ll LINF = 1001002003004005006ll;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
#define No cout<<"No"<<endl
#define Yes cout<<"Yes"<<endl
#define NO cout<<"NO"<<endl
#define YES cout<<"YES"<<endl;
int gcd(int a,int b){return b?gcd(b,a%b):a;}

int main(){
    int n;
    cin>>n;
    vector<pair<int,int>> red;
    rep(i,n){
        int a,b;
        cin>>a>>b;
        red.push_back(make_pair(b,a));
    }
    vector<pair<int,int>> blue;
    rep(i,n){
        int a,b;
        cin>>a>>b;
        blue.push_back(make_pair(a,b));
    }
    SORT(red);SORT(blue);
    int ans=0;
    for(int i=0;i<n;i++){
        for(int j=red.size()-1;j>=0;j--){
            if(red[j].second<blue[i].first&&red[j].first<blue[i].second){
                ans++;
                red.erase(red.begin()+j);
                break;
            }
        }
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.*;
import static java.lang.System.*;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		A(sc);
	}
	
	public static void A(Scanner sc) {
		String s = sc.next();
		out.println(s.substring(0,3) + 8 + s.substring(4,10));
	}
}


Measured memory_bytes: 21716
//////////////////////////// ⛎🎱💲♏☢🤘(NOOB 383)
//////////////////////////// 🇨🇸🇪 48
//////////////////////////// 🇯🇦🇭🇦🇳🇬🇮🇷🇳🇦🇬🇦🇷 🇺🇳🇮🇻🇪🇷🇸🇮🇹🇾((JU))

#include<bits/stdc++.h>
using namespace std;
#define LL long long int
#define DL double
#define MLL map<LL,LL>::iterator
#define MSL map<string,L>::iterator
#define MLS map<LL,string>::iterator
#define MSS map<string,string>::iterator
#define MCL map<char,LL>::iterator
#define SL set<LL>::iterator
#define SS set<string>::iterator sl
#define G getline
#define SZ size()
#define IN insert
#define C clear()
#define B begin()
#define F front()
#define T top()
#define E end()
#define EM empty()
#define V vector
#define Q queue
#define DQ deque
#define PQ priority_queue
#define ST stack
#define FI first
#define SE second
#define PI acos(-1)
#define PS push
#define PP pop()
#define PSF push_front
#define PSB push_back
#define PPF pop_front()
#define PPB pop_back()
#define endl "\n"
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
V< pair<LL,LL> >u,v;
int main()
{
    FAST;
    LL n,m,i,j,k,p,q,o,l,s,t,z;

    string a;
    cin>>a;
    p=0;q=0;
    for(i=0,k=0;a[i];i++)
    {
        if((i%2==0 && a[i]!='h') ||(i%2==1 && a[i]!='i'))
        {
            k=1;
            break;
        }
        if(a[i]=='h')
        {
            p++;
        }
        else if(a[i]=='i')
        {
            q++;
        }
    }
    if(k==0 && p==q)
    {
        cout<<"Yes"<<endl;
    }

 else
 {
     cout<<"No"<<endl;
 }
    return 0;

}


Measured memory_bytes: 256
package main

import (
	"fmt"
)

func main() {
	var s string
	fmt.Scan(&s)
	ret := 9999
	for i := 0; i < len(s)-2; i++ {
		ans := int(s[i]-'0')*100 + int(s[i+1]-'0')*10 + int(s[i+2]-'0') - 753
		if ans < 0 {
			ans *= -1
		}
		if ans < ret {
			ret = ans
		}
	}
	fmt.Println(ret)
}


Measured memory_bytes: 512
import math
N, D = map(int, input().split())
X = []
for i in range(N):
    x = list(map(int, input().split()))
    X.append(x)

count = 0
for i in range(N):
    for j in range(i+1, N):
        rr = 0
        for d in range(D):
            rr += (X[i][d] - X[j][d])**2

        r = math.sqrt(rr)
        if float(int(r)) == r:
            count+=1

print(count)

Measured memory_bytes: 3064
#include<cstdio> 
#include<algorithm>
#include<cstring>
#include<cmath>
using namespace std;
#define fo(i,j,k) for(i=j;i<=k;i++)
#define fd(i,j,k) for(i=j;i>=k;i--)
#define cmax(a,b) (a=(a>b)?a:b)
#define cmin(a,b) (a=(a<b)?a:b)
typedef long long ll;
const int N=1e6+5,M=2e6+5,mo=1e9+7;
int f[2][(1<<20)+5],c[25][25],n,m,K,x,y,z,q1,q2,i,j,s,ts,ns,ds,ans;
int main()
{
    scanf("%d %d %d",&n,&m,&K);
    n--;
    fo(i,1,K)
    {
        scanf("%d %d %d",&x,&y,&z);
        c[x][y-1]=z+1;
    }
    f[0][0]=1;
    q1=0;
    q2=1;
    ts=1<<n;ts--;
    fo(i,1,m)
        fo(j,0,n-1)
        {
            fo(s,0,ts)
            if (f[q1][s])
            {
                //left
                if (c[i][j]!=2&&((s>>j)&1)==0)
                {
                    f[q2][s]+=f[q1][s];
                    if (f[q2][s]>=mo) f[q2][s]-=mo;
                }
                //right
                if (c[i][j]!=1)
                {
                    if ((s>>j)&1) ns=s;
                    else
                    {
                        ns=((-1)^(1<<j+1)-1)&s;
                        if (!ns) ds=0;
                        else ds=ns&(-ns);
                        ns=s^(1<<j)^ds;
                    }
                    f[q2][ns]+=f[q1][s];
                    if (f[q2][ns]>=mo) f[q2][ns]-=mo;
                }
            }
            fo(s,0,ts) f[q1][s]=0;
            q1^=1;
            q2^=1;
        }
    fo(s,0,ts) 
    {
        ans+=f[q1][s];
        if (ans>=mo) ans-=mo;
    }
    printf("%d\n",ans);
}

Measured memory_bytes: 8320
import java.io.IOException;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws IOException {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);

		int x = sc.nextInt();

		int result = 1;
		for(int i = 2; i <= x - 1; i++){
			int p = 2;

			while(Math.pow(i, p) <= x){
				result = (int)Math.max(result, Math.pow(i, p));
				p++;
			}
		}

		System.out.println(result);
	}
}


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

string s;

int main(){
	cin>>s;
	
	for(char c='a'; c<='z'; c++){
		if(s.find(c)==-1){
			cout<<c<<endl;
			return 0;
		}
	}
	cout<<"None"<<endl;
}


Measured memory_bytes: 3732
#ifdef __APPLE__
#include <iostream>
#include <vector>
#include <utility>
#include <stack>
#include <queue>
#include <set>
#include <algorithm>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <iomanip>
#include <cmath>
#include <ctgmath>
#include <math.h>
#include <cassert>
#include <chrono>
#else
#include <bits/stdc++.h>
#endif

using namespace std;
#define io ios_base::sync_with_stdio(false), cin.tie(NULL)
#define GFOR(i,a,n) for (i=a;i<n;i++)
#define FOR(i,a,n) for (int i=a;i<n;i++)
#define RFOR(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define sz(x) ((int)(x).size())
#define tc(t) for (int tc=1; tc<=t; tc++)
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<long long int> vll;
typedef vector<pair<int, int> > vpi;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
mt19937 mrand(random_device{}()); 
const ll mod=1000000007;
int rnd(int x) { return mrand() % x;}
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
ll modInverse (ll a) {ll p = mod - 2; return powmod(a, p);}
// head

void solve() {
    int d, t, s;
    cin >> d >> t >> s;
    if (d > t*s) {
        cout << "No" << "\n";
    } else {
        cout << "Yes" << "\n";
    }
}

int main() {
    #ifdef LOCAL
    auto t1 = std::chrono::high_resolution_clock::now();
    #endif

    io;
    solve();

    #ifdef LOCAL
    auto t2 = std::chrono::high_resolution_clock::now();
    auto duration = std::chrono::duration_cast<std::chrono::milliseconds>( t2 - t1 ).count();

    std::cout << "Time Taken: " << duration << "\n";
    #endif

}
// check for edge cases in limits
// printing double may print 1.223232e9 like values, beware of that
// carefully observe simulation of test cases
// multiset erase is does not do what it is supposed to


Measured memory_bytes: 3624
#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <numeric>
#include <ctime>
#include <complex>
#include <bitset>
#include <random>
#include <stack>

using namespace std;

typedef long long ll;
typedef long double ld;

#define int ll
#define double ld
#define loop(i, n) for(int i = 0; i < (int)n; ++i)
#define loop1(i, n) for(int i = 1; i <= (int)n; ++i)
#define F first
#define S second
#define pb push_back
#define pi pair <int, int>
#define all(x) begin(x), end(x)
#define ti tuple <int, int, int>
#define Point Vect
#define mkt make_tuple
#define no {cout << -1; return;}

const int N = 20;

int calc[N][N];

void solve() {
    int n; cin >> n;
    loop(i, n) {
        string s; cin >> s;
        int x = 0;
        while (s.size() && s[0] != '.') {
            x = x * 10 + (s[0] - '0');
            s.erase(s.begin());
        }
        if (s.size())
            s.erase(s.begin());
        loop(j, 9)
            x = x * 10 + (s.size() > j ? s[j] - '0' : 0);
        int two = 0, five = 0;
        while (!(x & 1)) {
            x >>= 1; ++two;
        }
        while (x % 5 == 0) {
            x /= 5; ++five;
        }
        ++calc[min(two, N - 1)][min(five, N - 1)];
    }
    int dif = 0, eq = 0;
    loop(i, N)
        loop(j, N)
            loop(x, N)
                loop(y, N)
                    if (i + x >= 18 && j + y >= 18) {
                        if (i == x && j == y)
                            eq += calc[i][j] * (calc[i][j] - 1) / 2;
                        else
                            dif += calc[i][j] * calc[x][y];
                    }
    cout << dif / 2 + eq;
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    //int t; cin >> t; loop(i, t)
    solve();
    return 0;
}

Measured memory_bytes: 3644
import sys
from functools import lru_cache


@lru_cache(maxsize=None)
def func(num, pos):
    if num == 1:
        return 1
    elif pos == 1:
        return 0
    elif 1 < pos < (num + 2 - 1) // 2:
        return func((num - 3) // 2, pos - 1)
    elif pos == (num + 2 - 1) // 2:
        return func((num - 3) // 2, (num - 3) // 2) + 1
    elif (num + 2 - 1) // 2 < pos < num:
        return func((num - 3) // 2, (num - 3) // 2) + func((num - 3) // 2, pos - (num - 3) // 2 - 2) + 1
    elif pos == num:
        return func((num - 3) // 2, (num - 3) // 2) * 2 + 1


def solve():
    input = sys.stdin.readline
    mod = 10 ** 9 + 7
    n, x = list(map(int, input().rstrip('\n').split()))
    t = 1
    for i in range(n):
        t = t * 2 + 3
    print(func(t, x))


if __name__ == '__main__':
    solve()


Measured memory_bytes: 38384
var n,sol:longint;



procedure nhap;
begin
 read(n);
end;

procedure xuly;
begin
 sol:=1;
while sol*2<=n do
 begin
 sol:=sol*2;
 end;
end;

procedure xuat;
begin
 write(sol);
end;
begin
 nhap;
 xuly;
 xuat;
end.

Measured memory_bytes: 128
#include <iostream>

using namespace std;

const int MAXN = 100 * 1000 + 10;

int dp[MAXN], a[MAXN];

int main()
{
	int n;
	cin >> n;
	for (int i = 0; i < n; i++)
		cin >> a[i];
	for (int i = 0; i < n; i++)
	{
		if (a[i] == i + 1)
		{
			dp[i + 1] = dp[i] + 1;
			if (i > 0)
				dp[i + 1] = min(dp[i - 1] + 1, dp[i + 1]);
		}
		else
			dp[i + 1] = dp[i];
	}
	cout << dp[n] << endl;
}

Measured memory_bytes: 1024
package main

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

var scanner = bufio.NewScanner(os.Stdin)

func nextFloat() (float64, error) {
	return strconv.ParseFloat(nextString(), 64)
}

func nextString() string {
	scanner.Scan()
	return scanner.Text()
}

func stringifyArray(arr []int) string {
	return strings.TrimRight(fmt.Sprintf("%+v", arr)[1:], "]")
}

func main() {
	scanner.Split(bufio.ScanWords)

	r, _ := nextFloat()
	pi := math.Pi

	fmt.Printf("%f %f\n", pi*r*r, 2*pi*r)
}



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

int main() {
  int N;
  int sum = 0;
  cin >> N;

  // ここにプログラムを追記
  rep (i, N) {
    int l, r;
    cin >> l >> r;
    sum += r - l + 1;
  }
  cout << sum << endl;
}


Measured memory_bytes: 3596
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
using namespace std;

int main(){
	int a,b;
	cin>>a>>b;
	if(max(a,b)>9){
		cout<<-1<<endl;
	}else{
		cout<<a*b<<endl;
	}
	return 0;
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS

#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <cstring>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <list>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <unordered_set>
#include <unordered_map>
#include <array>
#include <cassert>
#include <bitset>
using namespace std;
using LL = long long;

const LL MOD = 1000000007;
LL mpow(LL a, LL x) {
	if (x == 0)return 1;
	LL half = mpow(a, x / 2);
	half *= half;
	half %= MOD;
	if (x % 2) {
		half *= a;
		half %= MOD;
	}
	return half;
}

LL fact[1234567];
LL nCr(LL n, LL r) {
	if (n == 0 && r == 0)return 1;
	if (r == 0 || r == n)return 1;
	return ((fact[n] * mpow(fact[r], MOD - 2)) % MOD * mpow(fact[n - r], MOD - 2)) % MOD;
}

LL N, A, B, C;

LL prob(LL lcnt, LL wp, LL lp, LL tp) {
	LL res = mpow(wp, N);
	res *= mpow(lp, lcnt);
	res %= MOD;
	LL tmp = nCr(N - 1 + lcnt, lcnt);
	res *= tmp;
	res %= MOD;
	LL one = mpow((MOD + 1 - tp) % MOD, N + lcnt);
	one = mpow(one, MOD - 2);
	LL two = mpow((MOD + 1 - tp) % MOD, N + lcnt + 1);
	two = mpow(two, MOD - 2);
	two *= tp;
	two %= MOD;
	two *= (N + lcnt);
	two %= MOD;
	LL right = (two + (one * (N + lcnt)) % MOD) % MOD;
	res *= right;
	//res *= 16;
	res %= MOD;
	return res;
}

int main() {
	fact[0] = 1;
	for (LL i = 1; i <= 1000000; ++i) {
		fact[i] = fact[i - 1] * i;
		fact[i] %= MOD;
	}
	cin >> N >> A >> B >> C;
	LL a, b, c;
	a = mpow(100, MOD - 2) * A;
	b = mpow(100, MOD - 2) * B;
	c = mpow(100, MOD - 2) * C;
	a %= MOD; b %= MOD; c %= MOD;
	LL ans = 0;
	for (int bnum = 0; bnum < N; ++bnum) {
		ans += prob(bnum, a, b, c);
		ans %= MOD;
	}
	for (int anum = 0; anum < N; ++anum) {
		ans += prob(anum, b, a, c);
		ans %= MOD;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 8448
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <tuple>
#include <vector>
using namespace std;
typedef long long ll;
ll const INF = 1LL << 60;

int main() {
  ll N;
  cin >> N;
  vector<ll> W(N), accum(N, 0);
  for (int i = 0; i < N; i++) {
    cin >> W[i];
    if (i == 0)
      accum[0] = W[0];
    else
      accum[i] = accum[i - 1] + W[i];
  }
  ll ans = INF;
  for (int i = 0; i < N; i++) {
    ans = min(ans, abs(accum[i] - (accum[N - 1] - accum[i])));
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3616
#include <limits.h>
#include <math.h>
#include <stdio.h>

int main(void) {
  int x, mod, hyaku;
  scanf("%d", &x);
  mod = x % 100;
  hyaku = x / 100;
  int sum = 0;
  while (!(hyaku <= 0 || mod < 10)) {
    mod = mod - 5;
    hyaku--;
  }
  for (int i = 5; i > 0; i--) {
    if (mod == 0 || hyaku == 0) break;
    if (i <= mod) {
      mod -= i;
      hyaku--;
    }
  }

  if (mod == 0) {
    printf("1\n");
  } else {
    printf("0\n");
  }

  return 0;
}

Measured memory_bytes: 128
#include<stdio.h>
int main (void)
{
	int W,H,x,y,r;
	scanf("%d %d %d %d %d",&W,&H,&x,&y,&r);
	if(x-r>=0 && W-x>=r && y-r>=0 && H-y>=r){
		printf("Yes\n");
	}
	else {
		printf("No\n");
	}
	return 0;
}

Measured memory_bytes: 584
#include <iostream>
#include <stdio.h>
#include <vector>
#include <algorithm>

using namespace std;

void solve(){
    string dance;
    cin >> dance;
    bool result = true;
    for(int i = 0; i < dance.size(); i++){
        if((i+1) % 2 != 0){
            if (dance.substr(i,1) == "L"){
                result = false;
                break;
            }
        } else {
            if (dance.substr(i,1) == "R"){
                result = false;
                break;
            }
        }
    }
    if(result) cout << "Yes" << endl;
    else cout << "No" << endl;
}


int main() {
    solve();
    return 0;
}

Measured memory_bytes: 256
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append(cnt)
    if temp!=1:
        arr.append(1)
    if arr==[]:
        arr.append(1)
    return arr

def calc(n):
    val = 1
    count = 0
    for i in range(2,100000):
        count += 1
        val = val + i
        if val > n:
            return count

N = int(input())
if N == 1:
    print(0)
    exit(0)

arr = factorization(N)

ans = 0 
for val in arr:
    ans += calc(val)
 
print(ans)

Measured memory_bytes: 63404
def resolve():
    n = int(input())
    l=[1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
    print(l[n- 1])


if __name__ == '__main__':
    resolve()


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define REP(i,n) for(int i=0; i<(n); ++i)
#define REP2(i,x,n) for(int i=x; i<(n); i++)
#define ALL(n) begin(n),end(n)
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
const long long INF = numeric_limits<long long>::max();
using ll = long long;
using P = pair<int, int>;
const int di[] = {-1, 0, 1, 0};
const int dj[] = {0, -1, 0, 1};
int main()
{
  int h, w;
  cin >> h >> w;
  int si, sj;
  cin >> si >> sj;
  int ti, tj;
  cin >> ti >> tj;
  --si; --sj; --ti; --tj;
  vector<string> s(h);
  REP(i,h) cin >> s[i];
  const int INF = 1e9;
  vector<vector<int>> dist(h, vector<int>(w, INF));
  deque<P> q;
  dist[si][sj] = 0;
  q.emplace_back(si, sj);
  while (!q.empty()){
    int i = q.front().first;
    int j = q.front().second;
    int d = dist[i][j];
    q.pop_front();
    REP(v,4){
      int ni = i + di[v], nj = j + dj[v];
      if (ni < 0 || ni >= h || nj < 0 || nj >= w) continue;
      if (s[ni][nj] == '#') continue;
      if (dist[ni][nj] <= d) continue;
      dist[ni][nj] = d;
      q.emplace_front(ni, nj);
    }
    for (int ei = -2; ei <= 2; ++ei){
      for(int ej = -2; ej <= 2; ++ej){
        int ni = i + ei, nj = j +ej;
        if (ni < 0 || ni >= h || nj < 0 || nj >= w) continue;
        if (s[ni][nj] == '#') continue;
        if (dist[ni][nj] <= d + 1) continue;
        dist[ni][nj] = d+1;
        q.emplace_back(ni, nj);
      }
    }
  }
  int ans = dist[ti][tj];
  if (ans == INF) ans = -1;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 8648
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <cmath>
#include <map>
#include <cstdlib>
using namespace std;
using ll = long long int;

int main()
{
    string S;
    cin >> S;
    if (S.length() == 2) cout << S;
    else {reverse(S.begin(),S.end()); cout << S;}
}


Measured memory_bytes: 256
import sys

def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  #空白あり
def S(): return sys.stdin.readline().rstrip()


X,Y,Z,K = map(int,S().split())
A = LI()
B = LI()
C = LI()

A = [0] + sorted(A,reverse = True)
B = [0] + sorted(B,reverse = True)
C = [0] + sorted(C,reverse = True)

ANS = []

# i+j+k <= K の範囲だけ考えればよい
for i in range(1,X+1):
    for j in range(1,min(K//i+1,Y)+1):
        for k in range(1,min(K//(i*j)+1,Z)+1):
            ANS.append(A[i]+B[j]+C[k])

ANS = sorted(ANS,reverse=True)

for i in range(K):
    print(ANS[i])

Measured memory_bytes: 46960
import java.io.InputStreamReader;
import java.util.Scanner;
 
public class Main {
	public static final long sosu = 1000000007;
	public static void main(String[] args) {
		try(Scanner scan = new Scanner(new InputStreamReader(System.in))){
			int N = scan.nextInt();
			int M = scan.nextInt();
			
			long ans = 1;
			
			int min = N;
			int max = M;
			
			if(N > M){
				min = M;
				max = N;
			}
			
			if(min + 1 < max){
				System.out.println(0);
				return;
			}
			
			for(int i = min; i>0; i--){
				ans = (ans * i) % sosu;
			}
			
			if(min == max){
				ans = (((ans * ans) % sosu) * 2) % sosu;
				System.out.println(ans);
				return;
			}
			
			ans = (((ans * ans) % sosu) * max) % sosu;
			System.out.println(ans);
		}
	}
}


Measured memory_bytes: 22996
#include <iostream>
#include <vector>
#include <string>
#include <utility>
#include <queue>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <climits>
using namespace std;

#define MOD1097 1000000007

#define ll long long
#define pint pair<int, int>
#define pll pair<ll, ll>
#define pb push_back
#define mpair make_pair
#define pm(first, second) pb(mpair(first, second))
#define SPACE " "
#define fpf first.first
#define fps first.second
#define spf second.first
#define sps second.second

#define all(X) (X).begin(), (X).end()
#define reall(X) (X).rbegin(), (X).rend()
#define divcel(a, b) (((a) + ((b) - 1)) / (b))

int main(){

    ll k, x;
    cin >> k >> x;
    for(int i = x-k+1; i <= x+k-1; i++){
        cout << i << SPACE;
    }

    return 0;
}

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


int main(void){
  int n,i,a[200005],t;
  
  cin >> n;
  for (i=0;i<n;i++) cin >> a[i];
  
  t=0;
  for (i=0;i<n;i++){
    if (a[i]==t+1) t++;
  }
  
  if (t==0) cout << -1 << endl;
  else cout << n-t << endl;
  
  return 0;
}

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

typedef long long llt;

const int MaxN = 100000 + 5;

int N;
llt A[MaxN];
llt ans1, ans2;
deque <llt> que1, que2;

inline llt llAbs(llt x) {
    if (x < 0) return -x;
    return x;
}

int main() {
    scanf("%d", &N);
    for (int i = 1; i <= N; ++i) scanf("%lld", &A[i]);

    sort(A + 1, A + 1 + N);

    que1.push_back(A[1]);
    que2.push_back(A[N]);

    llt Max = A[N], Min = A[2];
    int Maxi = N, Mini = 2;
    for (int i = 2; i <= N; ++i) {
        llt F = que1.front(), L = que1.back();
        llt ValF = max(llAbs(F - Max), llAbs(F - Min)),
            ValL = max(llAbs(L - Max), llAbs(L - Min));
        if (ValF > ValL) {
            ans1 += ValF;
            // printf("ans1 += %lld\n", ValF);
            if (llAbs(F - Max) == ValF) que1.push_front(Max), Maxi--;
            else que1.push_front(Min), Mini++;
        } else {
            ans1 += ValL;
            // printf("ans1 += %lld\n", ValL);
            if (llAbs(L - Max) == ValL) que1.push_back(Max), Maxi--;
            else que1.push_back(Min), Mini++;
        }
        Max = A[Maxi]; Min = A[Mini];
    }

    Max = A[N - 1], Min = A[1];
    Maxi = N - 1, Mini = 1;
    for (int i = 2; i <= N; ++i) {
        llt F = que2.front(), L = que2.back();
        llt ValF = max(llAbs(F - Max), llAbs(F - Min)),
            ValL = max(llAbs(L - Max), llAbs(L - Min));
        if (ValF > ValL) {
            ans2 += ValF;
            // printf("ans2 += %lld\n", ValF);
            if (llAbs(F - Max) == ValF) que2.push_front(Max), Maxi--;
            else que2.push_front(Min), Mini++;
        } else {
            ans2 += ValL;
            // printf("ans2 += %lld\n", ValL);
            if (llAbs(L - Max) == ValL) que2.push_back(Max), Maxi--;
            else que2.push_back(Min), Mini++;
        }
        Max = A[Maxi]; Min = A[Mini];
    }

    cout << max(ans1, ans2) << endl;
    return 0;
}

Measured memory_bytes: 2688
#include <bits/stdc++.h>
using namespace std;
char s[111];
bool c,f;
int main() {
  scanf("%s",s);
  for (int i=0; s[i]; i++) if (s[i]=='F') {
    if (c) f=true;
  } else if (s[i]=='C') c=true;
  puts(f?"Yes":"No");
  return 0;
}


Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

/**
 * 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;
        FastScanner in = new FastScanner(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, FastScanner in, PrintWriter out) {
            int[] count = new int[26];
            for (char cc : in.next().toCharArray()) {
                if (count[cc - 'a']++ > 0) {
                    out.println("no");
                    return;
                }
            }
            out.println("yes");
        }

    }

    static class FastScanner {
        private InputStream in;
        private byte[] buffer = new byte[1024];
        private int bufPointer;
        private int bufLength;

        public FastScanner(InputStream in) {
            this.in = in;
        }

        private int readByte() {
            if (bufPointer >= bufLength) {
                if (bufLength == -1)
                    throw new InputMismatchException();

                bufPointer = 0;
                try {
                    bufLength = in.read(buffer);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }

                if (bufLength <= 0)
                    return -1;
            }
            return buffer[bufPointer++];
        }

        private static boolean isPrintableChar(int c) {
            return c >= 33 && c <= 126;
        }

        public String next() {
            StringBuilder sb = new StringBuilder();

            int b = readByte();
            while (!isPrintableChar(b))
                b = readByte();

            while (isPrintableChar(b)) {
                sb.appendCodePoint(b);
                b = readByte();
            }

            return sb.toString();
        }

    }
}



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

using namespace std;

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

const int INF = 1000000000; //
const ll LINF = (ll) 4000000000000000000; //
const ll MOD = (ll) 1000000007; //
const double PI = acos(-1.0); //

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep2(i,n) for(int i=1;i<=(int)(n);i++)
#define rep3(i,n) for(int i=0;i<=(int)(n);i++)
#define REP(i,m,n) for(int i=m;i<(int)(n);i++)
#define repll(i,n) for(ll i=0;i<(ll)(n);i++)
#define repll2(i,n) for(ll i=1;i<=(ll)(n);i++)
#define REPLL(i,m,n) for(ll i=m;i<(ll)(n);i++)
#define MP make_pair
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible") << endl
#define NP(v) next_permutation(v.begin(),v.end())

//------------------------------------------------------

int main() {
    int n, m;
    cin >> n >> m;
    bool red[n] = {};
    red[0] = true;

    int ball[n];
    rep(i, n) ball[i] = 1;

    rep(i, m) {
        int x, y;
        cin >> x >> y;
        x--;
        y--;
        ball[x]--;
        ball[y]++;
        if (red[x]) red[y] = true;
        if (ball[x] == 0) red[x] = false;
    }

    int cnt = 0;
    rep(i, n) if (red[i] && ball[i] > 0) cnt++;

    cout << cnt << endl;


    return 0;
}


Measured memory_bytes: 768
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#define DEBUG(x) std::cout << '>' << #x << ':' << x << '\n';
#define PRINTVEC(x) for (int i = 0; i < (int)x.size(); i++) std::cout << x[i] << ' '; std::cout << '\n';
#define PRINTPAIR(x) for (int i = 0; i < (int)x.size(); i++) std::cout << x[i].first << ' ' << x[i].second << '\n'; std::cout << '\n';
#define PRINTSET(x) for (auto it = x.begin(); it != x.end(); it++) { std::cout << *it << ' '; } std::cout << '\n';
#define io std::ios_base::sync_with_stdio(false);std::cin.tie(NULL);   
const int INF = 1<<29;
typedef long long ll;
using namespace std;


int main()
{
	io;
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin); 
    freopen("output.txt", "w", stdout);  
    #endif

    int n;
    cin >> n;
    vector<int> v(4);
    string s;
    while(n--) {
        cin >> s;
        if (s == "AC") v[0]++;
        else if (s == "WA") v[1]++;
        else if (s == "TLE") v[2]++;
        else if (s == "RE") v[3]++;

    }
    cout << "AC x " << v[0] << endl;
    cout << "WA x " << v[1] << endl;
    cout << "TLE x " << v[2] << endl;
    cout << "RE x " << v[3] << endl;

    #ifndef ONLINE_JUDGE   
    std::cout << '\n' << "Time elapsed : " << 1.0 * clock() / CLOCKS_PER_SEC << " sec \n";
    #endif
    return 0;
}


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

int main()
{
	long N,i,temp,ans=0;
	vector<long> A,B;
	cin>>N;
	for(i=0;i<N-1;i++){
		cin>>temp;
		B.push_back(temp);
	}
	A.push_back(B.at(0));
	for(i=0;i<N-1;i++){
		if(A.at(i)>B.at(i)){
			A.at(i)=B.at(i);
		}
		A.push_back(B.at(i));
	}
	for(i=0;i<N;i++){
		ans+=A.at(i);
	}
	cout<<ans;
	return 0;
}


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

using namespace std;

int main(int argc, const char *argv[]) {
  int A, B;
  cin >> A;
  cin >> B;

  if(A == 1){
    if (B == 2) {
      cout << "3" << endl;
    }else{
      cout << "2" << endl;
    }
  }
  if(A == 2){
    if (B == 1) {
      cout << "3" << endl;
    }else{
      cout << "1" << endl;
    }
  }
  if(A == 3){
    if (B == 1) {
      cout << "2" << endl;
    }else{
      cout << "1" << endl;
    }
  }
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define square(x) pow(x 2.0)
#define all(x) (x).begin(),(x).end()
#define F first
#define S second
#define max_queue(x) priority_queue<x>
#define min_queue(x) priority_queue<x, vector<x>, greater<x>>
#define big_sort(v) sort(all(v), [](int a, int b) { return a > b; })//大きい順にソート
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vs = vector<string>;
// aよりもbが大きいならばaをbで更新する
// (更新されたならばtrueを返す)
template <typename T>
bool chmax(T &a, const T& b) {
  if (a < b) {
    a = b;  // aをbで更新
    return true;
  }
  return false;
}
// aよりもbが小さいならばaをbで更新する
// (更新されたならばtrueを返す)
template <typename T>
bool chmin(T &a, const T& b) {
  if (a > b) {
    a = b;  // aをbで更新
    return true;
  }
  return false;
}
/*
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
*/
int main() {
  set<string> s;
  int n;
  string str;
  cin >> n;
  rep(i,n){
    cin >> str;
    s.insert(str);
  }
  cout << s.size() << endl;
  return 0;
}


Measured memory_bytes: 19124