akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <stdio.h>
#include <vector>
#define mp make_pair
using namespace std;

int fib(int x){
	switch(x){
		case 0:
		return 1;
		case 1:
		return 1;
		case 2:
		return 2;
		case 3:
		return 3;
		case 4:
		return 5;
		case 5:
		return 8;
		case 6:
		return 13;
		case 7:
		return 21;
		default:
		return 34;
	}
}
int main(){
	int h, w, k;
	cin>>h>>w>>k;
	long long s[w];
	long long e[w];
	for(int i = 0;i < w;i ++){
		s[i]=(i==0);
	}
	for(int i = 0;i < h;i ++){
		for(int j = 0;j < w;j ++){
			e[j]=0;
		}
		for(int j = 0;j < w;j ++){
			if(j){
				e[j-1]+=s[j]*fib(j-1)*fib(w-j-1);
				e[j-1]%=1000000007;
			}
			if(j<w-1){
				e[j+1]+=s[j]*fib(j)*fib(w-j-2);
				e[j+1]%=1000000007;
			}
			e[j]+=s[j]*fib(j)*fib(w-j-1);
			e[j]%=1000000007;
		}
		for(int j = 0;j < w;j++){
			s[j]=e[j];
		}
	}
	cout<<e[k-1]<<"\n";
}

Measured memory_bytes: 256
a,b=map(int,input().split())
while a or b:
    for i in range(a):
        if i%2==0:
            if b%2==0:
                print('#.'*(b//2))
            else:
                print('#.'*(b//2)+'#')
        else:
            if b%2==0:
                print('.#'*(b//2))
            else:
                print('.#'*(b//2)+'.')
    print()
    a,b=map(int,input().split())


Measured memory_bytes: 5616
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<cctype>
#include<cmath>
#include<cstdlib>
#include<queue>
#include<ctime>
#include<vector>
#include<set>
#include<map>
#include<stack>
using namespace std;
const long long mod = 998244353;
long long c[4100][4100],pw[4100],vis[4100];
inline void getc(){
	  long long i,j;
	  for(i=0;i<=4000;i++)
	    c[i][0]=c[i][i]=1;
	  for(i=1;i<=4000;i++)
	    for(j=1;j<i;j++)
	      c[i][j]=(c[i-1][j]+c[i-1][j-1])%mod;
	  return;
}
inline void getpw(){
	  pw[0]=1;
	  for(long long i=1;i<=4000;i++)pw[i]=pw[i-1]*2%mod;
	  return;
}
inline long long work(long long i,long long n,long long k){
	  long long k1,k2,Ans=0,wh=-1,j;
      k2=min(k-i/2,(i-1)/2);
      k1=k-k2*2-(i+1)%2;
      for(j=0;j<=k2;j++){
      	wh*=-1;
      	Ans=(Ans+wh*c[n+k1+k2-j-1][k1+k2-j-1]*pw[k2-j]%mod*c[k2][k2-j]%mod
		  +mod)%mod;
      }
      return Ans;
}
int main(){
      long long n,k,i;
      scanf("%lld%lld",&k,&n);
      getc();
      getpw();
      for(i=2;i<=2*k;i++){
      	if(i&1){
      	  printf("%lld\n",work(i,n,k));
      	}else printf("%lld\n",(work(i,n,k)+work(i,n-1,k))%mod);
      }
	  return 0;
}

Measured memory_bytes: 127616
#include <bits/stdc++.h>
const int maxn=3001000;
const int mod=1e9+7;
const long long inf=1e15;
typedef long long ll;
using namespace std;

ll qpow(ll x,ll y)
{
    ll sum=1;
    while(y)
    {
        if(y&1)
            sum=(sum*x)%mod;
        x=x*x%mod;
        y/=2;
    }
    return sum;
}

int main()
{
    ll x;
    cin>>x;
    ll mine=inf;
    for(int i=1;i<sqrt(x+0.5);i++){
        if(x%i==0){
            mine=min(mine,i+x/i);
        }
    }
    cout<<mine-2<<endl;
}


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

int main()
{
    int A, B, C, X, Y;
    cin >> A >> B >> C >> X >> Y;
    int price[3];
    // Cを買わない場合
    price[0] = A * X + B * Y;
    // 少ない方の分 C で買う場合
    int cmin = min(X, Y);
    price[1] = cmin * 2 * C + (X - cmin) * A + (Y - cmin) * B; 
    // 多い方の分 C で買う場合
    int cmax = max(X, Y);
    price[2] = cmax * 2 * C;
    cout << * min_element(price, price + 3) << '\n';
    return 0;
}

Measured memory_bytes: 256
s = input()
ans = 0
p = 0
q = len(s) - 1
while p < q:
	if s[p] == s[q]:
		p += 1
		q -= 1
	elif s[p] == "x":
		p += 1
		ans += 1
	elif s[q] == "x":
		q -= 1
		ans += 1
	else:
		ans = -1
		break
print(ans)

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

int main (){
    vector<int> a(9);
    vector<int> c(9);
    for (int i=0; i<9; i++){
        cin >> a.at(i);
        c.at(i) = 0;

    }

    int n;
    cin >> n;
    vector<int> b(n);
    for(int i=0; i<n; i++){
        cin >> b.at(i);

        for (int j=0; j<9; j++){
            if (b.at(i) == a.at(j)){
                c.at(j)++;
            }
        }
    }

    string out;
    if (c.at(0) == 1 && c.at(1) == 1 && c.at(2) == 1){
        out = "Yes";
    }else if (c.at(3) == 1 && c.at(4) == 1 && c.at(5) == 1){
        out = "Yes";
    }else if (c.at(6) == 1 && c.at(7) == 1 && c.at(8) == 1){
        out = "Yes";
    }else if (c.at(0) == 1 && c.at(3) == 1 && c.at(6) == 1){
        out = "Yes";
    }else if (c.at(1) == 1 && c.at(4) == 1 && c.at(7) == 1){
        out = "Yes";
    }else if (c.at(2) == 1 && c.at(5) == 1 && c.at(8) == 1){
        out = "Yes";
    }else if (c.at(0) == 1 && c.at(4) == 1 && c.at(8) == 1){
        out = "Yes";
    }else if (c.at(2) == 1 && c.at(4) == 1 && c.at(6) == 1){
        out = "Yes";
    }else{
        out = "No";
    }

    cout << out << endl;
}

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

#define ntest 0

using namespace std;
long long x,k,d;
void solve() {
    cin >> x >> k >> d;
    x = abs(x);
    if (x / d >= k) {
        cout << x - k * d;
        return;
    }
    long long tmpk = x / d;
    long long remain = k - tmpk;
    if (remain&1) cout << abs(x-(tmpk+1)*d);
    else cout << x - tmpk * d;
}
int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    if(ntest){
        int t;
        cin >> t;
        while(t--) solve();
    } else {
        solve();
    }

}




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

#define N 100005

int d[N], n, cnt[N], mx;

const int mod = 998244353;

int main() {
    scanf("%d", &n);
    for (int i = 1; i <= n; i ++) {
      scanf("%d", &d[i]);
      cnt[d[i]] ++;
      mx = max(mx, d[i]);
    }
    if (d[1] != 0) return puts("0"), 0;
    for (int i = mx; i >= 0; i --) if (cnt[i] == 0) return puts("0"), 0;
    if (cnt[0] > 1) return puts("0"), 0;
    int ans = 1;
    for (int i = 1; i <= n; i ++) {
      int k = d[i];
      if (k>0) ans = 1ll * ans * cnt[k-1] % mod;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 4380
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i,n) for(int i=n; i>-1; --i)
#define ALL(a) (a).begin(),(a).end()
#define INIT(a,n,x); REP(i,(n)){ (a)[i]=(x); }
#define CINA(a,n); REP(i,(n)){ cin >> (a)[i]; }
#define INIT2(a,n,m,x); REP(i,(n)){ REP(j,(m)){(a)[i][j]=(x);} }
#define CINA2(a,n,m); REP(i,(n)){ REP(j,(m)){cin >> (a)[i][j];} }
#define Liny "Yes\n"
#define Linn "No\n"
#define LINY "YES\n"
#define LINN "NO\n"

#define umap unordered_map
//cout << setfill('0') << right << setw(4) << 12; // "0012"
int keta(ll x){ if(x<10){return 1;} else{return keta(x/10) + 1;}}
int keta_wa(ll x){ if(x<10){return x;} else{return keta_wa(x/10) + x%10;} }
int ctoi(char c){ return ( (c>='0' && c<='9')? c - '0': 0 );}
ll sum(ll a[],ll N){ return accumulate(a,a+N,0LL);}
ll gcd(ll a,ll b){if(a<b)swap(a,b); return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){if(a<b){swap(a,b);} return a/gcd(a,b)*b;}

ll func(ll X,ll Y){
  if(X>Y){ return pow(10,9)+1; }
  else return Y-X;
}

int main(){
  ll X,Y; cin>>X>>Y;
  ll r1,r2,r3,r4;
  r1 = func(X,Y);
  r2 = func(-X,Y)+1;
  r3 = func(X,-Y)+1;
  r4 = func(-X,-Y)+2;
  ll r = min({r1,r2,r3,r4});
  cout << r <<"\n";
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <limits>
#include <vector>
#include <cstdio>
#include <bits/stdc++.h>
#include <set>
#include <map>
#include <stdio.h>
#include <stack>
#include <queue>
#include <deque>
#include <numeric>
#include<bits/stdc++.h>
#include <utility>

#define ALL(obj) (obj).begin(), (obj).end()
#define FOR(i,a,b) for(int i = (a); i < (b); i++)
#define RFOR(i,a,b) for(int i = (a); (b) <= i; i--)
#define REP(i,n) for(int i = 0; i < (n); i++)
#define RREP(i,n) for(int i = n; n <= i; i--)
#define ABS(a) ((a < 0) ? ((-1)*(a)) : (a))
#define elif else if
#define MOD 1000000007
#define INF (1<<29)

using namespace std;
using ll = long long;
map <int ,int> mpa,mpb;
typedef pair<ll, ll> P;
priority_queue<P, vector<P>, greater<P>> pque;

int main(){
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  string S;
  cin >> S;
  int ans=0;
  for(int i=0;i<S.size();i++){
    if(S[i]=='+') ans++;
    else ans--;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<vector>
#include<cstring>
#include<stack>
using namespace std;
const int MAXN=205;
 
int N;
vector<int> adj[MAXN];
bool vis[MAXN];
int match[MAXN];
 
bool aug(int u)
{
	for(int i=0;i<(int)adj[u].size();i++)
		if(!vis[adj[u][i]])
		{
			int v=adj[u][i];
			vis[v]=true;
			if(match[v]==0||aug(match[v]))
			{
				match[u]=v;
				match[v]=u;
				return true;
			}
		}
	return false;
}
 
int Match()
{
	int ans=0;
	for(int i=1;i<=2*N;i++)
		if(match[i]==0)
		{
			memset(vis,0,sizeof vis);
			ans+=aug(i);
		}
	return ans;
}
 
pair<int,int> A[MAXN],B[MAXN];
 
int main()
{
	scanf("%d",&N);
	for(int i=1;i<=N;i++)
		scanf("%d%d",&A[i].first,&A[i].second);
	for(int i=1;i<=N;i++)
		scanf("%d%d",&B[i].first,&B[i].second);
		
	for(int i=1;i<=N;i++)
		for(int j=1;j<=N;j++)
			if(A[i].first<B[j].first&&A[i].second<B[j].second)
			{
				adj[i].push_back(j+N);
				adj[j+N].push_back(i);
			}
	
	printf("%d\n",Match());
	
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int input = scanner.nextInt();

        String answer = "No";
        for (int i = 1; i < 10; i++) {
          if((input % i) == 0 && (input / i) < 10){
          answer = "Yes";
          }
        }

        System.out.println(answer);
    }
}

Measured memory_bytes: 23764
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        final Scanner scanner = new Scanner(System.in);
        final int N = scanner.nextInt();
        final int[] h = new int[N];
        final int maxHeight;
        {
            int maxHeightCandidate = 0;
            for (int k = 1; k <= N; k++) {
                h[k - 1] = scanner.nextInt();
                if (maxHeightCandidate < h[k - 1]) {
                    maxHeightCandidate = h[k - 1];
                }
            }
            maxHeight = maxHeightCandidate;
        }

        int totalCount = 0;
        for (int height = 1; height <= maxHeight; height++) {
            int countPerHeight = 0;
            boolean exists = false;
            for (int k = 1; k <= N; k++) {
                if (exists) {
                    if (h[k - 1] < height) {
                        exists = false;
                    }
                } else {
                    if (h[k - 1] >= height) {
                        exists = true;
                        countPerHeight++;
                    }
                }
            }
            totalCount += countPerHeight;
        }
        System.out.println(totalCount);
    }
}


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

int main() {
    ll a,b,c,d;
    cin >> a >> b >> c >> d;
    ll w,x,y,z,ans = 0;
    w = a * c;
    x = a * d;
    y = b * c;
    z = b * d;
    ans = max(w,max(x,max(y,z)));
    cout << ans << endl;
}

Measured memory_bytes: 3628
#include<stdio.h>
int main(){
  int N,i,j,k,A[1000],v;
  scanf("%d",&N);
  for(i=0;i<N;i++)scanf("%d",&A[i]);
  for(i=1;i<N;i++){
    for(k=0;k<N-1;k++)printf("%d ",A[k]);
    printf("%d\n",A[k]);
    v=A[i];
    j=i-1;
    while(j>=0 && A[j]>v){
      A[j+1]=A[j];
      j--;
    }
    A[j+1]=v;
  }
  for(k=0;k<N-1;k++)printf("%d ",A[k]);
  printf("%d\n",A[k]);
  return 0;
}



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

using namespace std;

const int maxn=1e5+5,mod=1e9+5;

typedef long long ll;


int main()
{
    int N,M;
    while(scanf("%d%d",&N,&M)!=EOF)
    {
        if(N==M)
            printf("Yes\n");
        else
            printf("No\n");
    }
    return 0;
}


Measured memory_bytes: 256
import java.io.*;
import java.util.StringTokenizer;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));

        long W = in.nextLong();
        long H = in.nextLong();
        int x = in.nextInt();
        int y = in.nextInt();
        out.print( W * H / 2.0);
        out.print(" ");
        if (x == W / 2.0 && y == H / 2.0) {
            out.print(1);
        }   else {
            out.print(0);
        }
        out.close();
    }

    static class Scanner {
        StringTokenizer st;
        BufferedReader br;

        public Scanner(InputStream s) {
            br = new BufferedReader(new InputStreamReader(s));
        }

        public Scanner(String s) {
            try {
                br = new BufferedReader(new FileReader(s));
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            }
        }

        public String next() {
            while (st == null || !st.hasMoreTokens()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

        public double nextDouble() {
            return Double.parseDouble(next());
        }

        public int[] nextIntArray(int n) {
            int[] arr = new int[n];
            for (int i = 0; i < n; i++) {
                arr[i] = nextInt();
            }
            return arr;
        }

        public double[] nextDoubleArray(int n) {
            double[] arr = new double[n];
            for (int i = 0; i < n; i++) {
                arr[i] = nextDouble();
            }
            return arr;
        }

        public long[] nextLongArray(int n) {
            long[] arr = new long[n];
            for (int i = 0; i < n; i++) {
                arr[i] = nextLong();
            }
            return arr;
        }

        public char[] nextCharArray(int n) {
            char[] arr = nextLine().trim().replaceAll("\\s", "").toCharArray();
            return arr;
        }

        public String[] nextStringArray(int n) {
            String[] arr = new String[n];
            for (int i = 0; i < n; i++) {
                arr[i] = next();
            }
            return arr;
        }
    }
}


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

res = 0
t = 0
resl = []

for i in range(N-1):
    if (H[i] >= H[i+1]):
        t += 1
        resl.append(t)
    else:
        res = max(t, res)
        t = 0
    
if len(resl) == 0:
    print(0)
else:
    print(max(resl))

Measured memory_bytes: 64228
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 998244353;
const ll MAX = 200000;

ll fac[MAX], finv[MAX], inv[MAX];

// コンビネーションのテーブルを作る前処理
// ll COMとワンセット
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;
}

ll modpow(ll a, ll n, ll mod) {
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

int main() {
    ll N, M, K;
    cin >> N >> M >> K;
    COMinit();
    ll ans = 0;
    for (int i = 0; i <= K; i++) {
        ll a = M * COM(N-1, i) % MOD;
        a = a * modpow(M-1, N-1-i, MOD) % MOD;
        ans = (ans + a) % MOD;
    }
    cout << ans << endl;
}

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

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

  int x,a,b;cin>>x>>a>>b;
  if(x+a<b){
    cout<<"dangerous"<<endl;
  }else if (b<=a) {
    cout<<"delicious"<<endl;
  }else {
    cout<<"safe"<<endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include <stdlib.h>
#include<iostream>
#include<bits/stdc++.h>
#include<cmath>
#define ll long long
const int INF=0x3f3f3f3f;
#define mod 1000000007
using namespace std;
//priority_queue
int x[10003],y[10003];
ll gcd(ll a,ll b)
{
    return b==0?a:gcd(b,a%b);
}
int main()
{

ll a,b,c,d;
cin>>a>>b>>c>>d;
ll e=gcd(c,d);
ll z=(b-a+1);a--;
cout<<z-(b/c+b/d-b/(c*d/e)-(a/c+a/d-a/(c*d/e)))<<endl;
}



Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <queue>

using namespace std;

#define TRACE(x) cerr << #x << " " << x << endl
#define FOR(i, a, b) for (int i = (a); i < int(b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define _ << " " <<

#define fst first
#define snd second

typedef long long llint;
typedef pair<int, int> pii;

const int B = 27397, MOD = 1e9 + 7;
const int B1 = 33941, MOD1 = 1e9 + 9;

llint n, x;

llint f(llint a, llint b) {
  if (a > b) return f(b, a);
  if (b % a == 0) return 2*b - a;
  return (b/a)*2*a + f(a, b % a);
}

int main(void) {
  scanf("%lld%lld", &n, &x);
  printf("%lld\n", n + f(x, n - x));
  return 0;
}

Measured memory_bytes: 256
from sys import exit, setrecursionlimit, stderr
from functools import reduce
from itertools import *
from collections import defaultdict, Counter
from bisect import bisect

setrecursionlimit(10**7)

def read():
  return int(input())

def reads():
  return [int(x) for x in input().split()]

N, A, B = reads()

M = min(A, B)
m = max(A + B - N, 0)
print(M, m)


Measured memory_bytes: 38256
#include<bits/stdc++.h>
using namespace std;
typedef pair<long long,string> P;
main(){
  long long m,n;
  long long cm;
  string str="";
  string tani[18]={"","Man","Oku","Cho","Kei","Gai","Jo","Jou","Ko","Kan","Sei","Sai","Gok","Ggs","Asg","Nyt","Fks","Mts"};
  while(1){
    str="";
    cin>>m>>n;
    if(m==0&&n==0) break;
    cm=m;
    while(cm>0){
      str+=(char)('0'+(char)(cm%10));
      cm/=10;
    }
    for(int i=1;i<n;i++){
      string plus=str;
      for(int j=1;j<m;j++){
	long long kuriage=0;
	for(int k=0;k<str.size();k++){
	  long long sum;
	  if(k<plus.size()){
	    sum=(str[k]-'0')+(plus[k]-'0');
	  }
	  else{
	    sum=str[k]-'0';
	  }
	  sum+=kuriage;
	  if(sum>=10){
	    kuriage=1;
	  }
	  else{
	    kuriage=0;
	  }
	  str[k]=(char)('0'+(sum%10));
	}
	if(kuriage==1){
	  str+='1';
	}
      }
    }
    stack<P> sta;
    for(int i=0;i<str.size();i+=4){
      long long num=0;
      for(int j=min(i+3,(int)str.size()-1);j>=i;j--){
	num*=10;
	num+=(str[j]-'0');
      }
      if(num>0){
	sta.push(P(num,tani[i/4]));
      }
    }
    while(!sta.empty()){
      cout<<sta.top().first<<sta.top().second;
      sta.pop();
    }
    cout<<endl;
  }
}
  

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

struct UnionFind {
    vector<int> d;
    UnionFind(int n=0): d(n, -1) {}
    int find(int x) {
        if (d[x] < 0) return x;
        return d[x] = find(d[x]);
    }
    bool unite(int x, int y) {
        x = find(x); y = find(y);
        if (x == y) return false;
        if (d[x] > d[y]) swap(x, y);
        d[x] += d[y];
        d[y] = x;
        return true;
    }
    bool same(int x, int y) {
        return find(x) == find(y);
    }
    int size(int x) {
        return -d[find(x)];
    }
};

int main() {
    int n, m;
    cin >> n >> m;
    UnionFind uf(n);
    rep(i, m) {
        int x, y, z;
        cin >> x >> y >> z;
        x--; y--;
        uf.unite(x, y);
    }
    set<int> s;
    rep (i, n) s.insert(uf.find(i));
    cout << s.size() << endl;
    return 0;
}

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


int main() {
 
  int64_t n,m;
  cin>>n>>m;


  vector<pair<int64_t, int64_t> > student_pos(n);
  for(int i=0;i<n;i++){
    cin>>student_pos.at(i).first>>student_pos.at(i).second;
  }
 
  vector<pair<int64_t, int64_t> > checkpoint_pos(m);
  for(int i=0;i<m;i++){
    cin>>checkpoint_pos.at(i).first>>checkpoint_pos.at(i).second;
  }



  for(int i=0;i<n;i++){
    int64_t min_dist=10000000000;
    int64_t index_min_dist;
    for(int j=0;j<m;j++){
      int64_t dist=abs(student_pos.at(i).first-checkpoint_pos.at(j).first)+abs(student_pos.at(i).second-checkpoint_pos.at(j).second);
      if(dist<min_dist){
        min_dist=dist;
        index_min_dist=j+1;
      }
    }
    cout<<index_min_dist<<endl;
  }


	return 0;
}



Measured memory_bytes: 3592
n = int(input())
v = []
i = 6
while i<=n:
    v.append(i)
    i *= 6
i=9
while i <= n:
    v.append(i)
    i *= 9
v.sort()
dic = dict()
def dp(i, N):
    if i < 0:
        return N
    if (i, N) not in dic:
        dic[(i, N)] = min(dp(i, N-v[i])+1, dp(i-1, N)) if N-v[i] >= 0 else dp(i-1, N)
    return dic[(i, N)]
print(dp(len(v)-1, n))

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

void WA()
{
	cout << "WA" << endl;
}

void AC()
{
	cout << "AC" << endl;
}

int main() {

	string str;
	cin >> str;

	// 先頭がAじゃないなら終了
	if( str[ 0 ] != 'A' ) {
		WA();
		return 0;
	}

	// 3番目と末尾2番目の間にC
	int cCounter = 0;
	int cIndex = 0;
	for( int i = 2; i <= str.length()-2; ++i )
	{
		if( str[ i ] == 'C' )
		{
			cIndex = i; //Cの在処
			cCounter++;
		}

		if( 2 <= cCounter )
		{
			WA();
			return 0;
		}
	}

	if( cCounter <= 0 )
	{
			WA();
			return 0;
	}


	// 全て小文字か
	for( int i = 1; i < str.length(); ++i )
	{
		if( i == cIndex )
		{
			continue;
		}

		if( (int)str[ i ] <= 96 )
		{
			WA();
			return 0;
		}
	}

	AC();

	return 0;
}


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

int main()
{
    std::string s;
    std::cin >> s;

    std::unordered_map<char, int> map;
    for (auto c : s) {
        map[c]++;
    }

    for (auto i = map.begin(); i != map.end(); i++) {
        if (i->second != 1) {
            std::cout << "no" << std::endl;
            return 0;
        }
    }
    std::cout << "yes" << std::endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
/// TONI BO$$ was here
/// #MLC

using namespace std;

int main()
{
    int l,r;
    scanf("%d%d",&l,&r);
    if(l%2019>=r%2019)
        printf("0");
    else
        if(r-l>=2019)
            printf("0");
        else
        {
            long long rez=2020,i,j;
            for(i=l; i<r; i++)
                for(j=l+1; j<=r; j++)
                    if((i*j)%2019<rez)
                        rez=(i*j)%2019;
            printf("%d",rez);
        }

    return 0;
}


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

namespace kyoupuro {

    class MainClass {

        public static void Main() {
            var X = Input.NextLong();

            Console.WriteLine(Enumerable.Range(1, 100000).FirstOrDefault(i => (long)i * (i + 1) / 2 >= X));
        }
    }

    class Input {
        static IEnumerator<string> enumerator = new string[] { }.AsEnumerable().GetEnumerator();

        public static string Line() {
            return Console.ReadLine();
        }

        public static int NextInt() {
            while (!enumerator.MoveNext()) {
                enumerator = StrArr().AsEnumerable().GetEnumerator();
            }
            return int.Parse(enumerator.Current);
        }

        public static long NextLong() {
            while (!enumerator.MoveNext()) {
                enumerator = StrArr().AsEnumerable().GetEnumerator();
            }
            return long.Parse(enumerator.Current);
        }

        public static string[] StrArr() {
            return Line().Split(' ');
        }

        public static List<int> IntList() {
            return StrArr().Select(int.Parse).ToList();
        }

        public static List<long> LongList() {
            return StrArr().Select(long.Parse).ToList();
        }

        public static void Skip(int line = 1) {
            enumerator.Reset();
            for (int i = 0; i < line; i++) Console.ReadLine();
        }

        public static void Reset() {
            enumerator.Reset();
        }
    }
}

Measured memory_bytes: 13268
if __name__ == "__main__":
    stack =[]
    ope = {"+": lambda a, b: b + a, "-": lambda a, b: b - a, "*": lambda a, b: b * a}
    for x in input().split():
        if x in ope:
            stack.append(ope[x](stack.pop(),stack.pop()))
        else:
            stack.append(int(x))
    print(stack[-1])

Measured memory_bytes: 7744
import java.util.*;


public class Main {
	public static void main(String[] aargs) {
		Scanner sc = new Scanner(System.in);
		Map<String,Integer>A=new HashMap<>();
		int a=sc.nextInt();
		int q,x;
        String key;
		for(int i=0;i<a;i++) {
			q=sc.nextInt();
		if(q==0){
            key = sc.next();
            x = sc.nextInt();
            A.put(key,x);
		}else if(q==1){
            key = sc.next();
            System.out.println(A.get(key));
        }
        }
		
	}
}



Measured memory_bytes: 193872
date=input()
if 1<=int(date[:2])<=12:
    if 1 <= int(date[2:]) <= 12:
        print("AMBIGUOUS")
        exit(0)
    else:
        print("MMYY")
        exit(0)
if int(date[2:])==0 or 13 <= int(date[2:]):
    print("NA")
    exit(0)
print("YYMM")

Measured memory_bytes: 8992
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < n; i++)
#define repr(i, n) for(int i = n; i >= 0; i--)
#define INF 
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

vector<ll> div(ll n) {
  vector<ll> vec;
  for(ll i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      vec.push_back(i);
      vec.push_back(n/i);
    }
  }
  sort(vec.begin(), vec.end());
  return vec;
}

int main()
{
  ll n;
  cin >> n;
  vector<ll> vec = div(n);

  ll ans = pow(10, 12);
  rep(i, vec.size()) {
    ans = min(ans, (vec[i] - 1) + (n / vec[i] - 1));
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3620
from collections import defaultdict
Poll_Dict = defaultdict(int)

N = int(input())

for _ in range(N):
    Poll_Dict[str(input())] += 1

Max_Number = max(Poll_Dict.values())    
Max_List = sorted([k[0] for k in Poll_Dict.items() if k[1] == Max_Number])

for i in Max_List:
    print(i)

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

using namespace std;

int main()
{
	int t;
   t=1;
	while(t--)
	{
	
   int i,j,k,n,m;
   cin>>n;
    string s[100];
    
    s[0]="AC";
    s[1]="WA";
    s[2]="TLE";
    s[3]="RE";
    
  
  int a[100] {0};
   
     for(i=0;i<n;i++)
     {
     	
     string tt;
	 cin>>tt;
	 
	  for(j=0;j<4;j++)
	  {
	  	if(tt==s[j])
	  	{
	  		a[j]++;
	  		break;
		  }
	  	
	   } 
     	
	 }
	 
	 for(i=0;i<4;i++)
	 {
	 	cout<<s[i]<<" x "<<a[i]<<endl;
	 	
	 }
   
	
	
	}



}


Measured memory_bytes: 3600
// 1_7_C
#include <iostream>
#include <vector>
using namespace std;

int main(){
  int r, c, i, j;
  cin >> r >> c;
  vector< vector<int> > sheet(r+1, vector<int>(c+1, 0));
  for(i = 0; i < r; i++){
    for(j = 0; j < c; j++){
      cin >> sheet[i][j];
      sheet[i][c] += sheet[i][j];
      sheet[r][j] += sheet[i][j];
    }
    sheet[r][c] += sheet[i][c];
  }

  for(i = 0; i < r+1; i++){
    for(j = 0; j < c; j++){
      cout << sheet[i][j] << " ";
    }
    cout << sheet[i][j] << endl;
  }
  return 0;
}

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

const int MAX_N = 22;
const int MOD = 1e9+7;

int to[MAX_N][MAX_N];
int dp[MAX_N][(1<<MAX_N)];

void modadd(int &a, int b ){ 
  a = (a+b)%MOD;
}

signed main(void){ 
  
  int N; cin >> N;
  for(int i = 0; i < N; i++){ 
    for(int j = 0; j < N; j++){
      cin >> to[i][j];
    }
  }
  
  //一番はじめの男についてだけ愚直に計算する
  
  for(int f = 0; f < N; f++){ 
    if( to[0][f] ){ 
      dp[0][(1<<f)]++;
    }
  }
  
  for(int male = 0; male < N-1; male++){ //何番目の男までを見たか
    for(int female = 0; female < (1<<N); female++){ //どの女がまだ残っているか
      //次に追加するのは male+1　番目の男である
      
      //枝刈り
      
      int cnt = 0;
      for(int i = 0; i < N; i++){ 
        if( female >> i  & 1 ){ cnt++;}
      }
      
      if( cnt != male+1 ){ continue;}
      
      
      for(int check = 0; check < N; check++){ 
        if( !(female >> check & 1) && to[male+1][check] ){
          //まだ残っていて、かつmaleと相性がいい女がいたら合わせる
          modadd(dp[male+1][female|(1<<check)],dp[male][female]);
          
        }
      }
    }
  }
  
  cout << dp[N-1][(1<<N)-1] << endl;
  
  return 0;
}
  

Measured memory_bytes: 319744
def main():
    S = input()
    ans = "Yes"
    N = len(S)
    tmp1 = S[: (N - 1) // 2]
    tmp2 = S[(N + 3) // 2 - 1 :]
    if S != S[::-1]:
        ans = "No"
    elif tmp1 != tmp1[::-1]:
        ans = "No"
    elif tmp2 != tmp2[::-1]:
        ans = "No"
    print(ans)

if __name__ == '__main__':
    main()

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

    int n;
    cin >> n;
    int mat[100][100] = {};
    rep(i, n){
        int k, l;
        cin >> k >> l;
        rep(j, l){
            int v;
            cin >> v;
            mat[k-1][v-1] = 1;
        }
    }

    rep(i, n){
        rep(j, n){
            cout << mat[i][j];
            if(j == n-1){
                cout << "\n";
            }
            else{
                cout << ' ';
            }
        }
    }


    return 0;
}


Measured memory_bytes: 3148
#include <iostream>

int main()
{
	int x ,y;
	std::cin >> x >> y;
	while(x != 0 ||y != 0){
		if (x < y) {
			std::cout << x << " " << y << std::endl;
		}
		else {
			std::cout << y << " " << x << std::endl;
		}
		std::cin >> x >> y;
	}
}


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

int main(){
    int n,k,q;
    cin >>n>>k>>q;
    vector<int> score(n,k-q);
    for(int i=0; i<q; ++i){
        int a; cin >> a;
        score[a-1] +=1;
    }
    for(int p:score){
        if(p>=1) cout << "Yes" << endl;
        else cout << "No" << endl;
    }
}

Measured memory_bytes: 1024
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<queue>
#include<stack>
#include<vector>
#include<queue>
#include<deque>
#include<set>
#include<map>
#include<unordered_map>
#include<bitset>
using namespace std;
typedef long long ll;
typedef pair<int, int>pii;
const int inf = 0x3f3f3f3f;
bool ok; char ch;
void read(int& x) {
	for (ok = 0, ch = getchar(); !isdigit(ch); ch = getchar()) if (ch == '-') ok = 1;
	for (x = 0; isdigit(ch); x = x * 10 + ch - '0', ch = getchar());
	if (ok) x = -x;
}
void write(int x)
{
	if (x < 0) {
		putchar('-');
		x = -x;
	}
	if (x > 9)
		write(x / 10);
	putchar(x % 10 + '0');
	return;
}

unordered_map<int, int>s;
int main() {
	int n;
	cin >> n;
	while (n--) {
		int a;
		cin >> a;
		if (s[a]) {
			cout << "NO";
			return 0;
		}
		s[a] = 1;
	}
	cout << "YES";
	return 0;
}

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

using lint = long long;

int main() {
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int n;
    cin >> n;
    vector<vector<int>> edges(n+1);
    for (int i = 2; i <= n; ++i) {
    	int from;
    	cin >> from;
    	edges[from].push_back(i);
    }
    for (int i = 1; i <= n; ++i)
    	cout << edges[i].size() << '\n';
}

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

int main(){
    int n;
    cin >> n;
    int A[100];
    for(int i=0; i<n; i++){
        cin >> A[i];
    }
    
    int count=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;
        }
        int v = A[minj];
        A[minj] = A[i];
        A[i] = v;
        if(minj != i) count++;
    }
    
    for(int k=0; k<n; k++){
        if(k>0) cout << " ";
        cout << A[k];
    }
    cout << endl;
    cout << count << endl;
    
    return 0;
}


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

using namespace std;

int main() {
	ios::sync_with_stdio(false); cin.tie(0);
	
	int sx, sy, tx, ty, x, y; cin >> sx >> sy >> tx >> ty;

	for (x = sx; x < tx; x++) {
		cout << "R";
	}
	for (y = sy; y < ty; y++) {
		cout << "U";
	}
	for (x = tx; x > sx; x--) {
		cout << "L";
	}
	for (y = ty; y > sy; y--) {
		cout << "D";
	}
	cout << "D";
	for (x = sx; x < tx + 1; x++) {
		cout << "R";
	}
	for (y = sy-1; y < ty; y++) {
		cout << "U";
	}
	cout << "LU";
	for (x = tx; x > sx-1; x--) {
		cout << "L";
	}
	for (y = ty+1; y > sy; y--) {
		cout << "D";
	}
	cout << "R";
	return 0;
}

Measured memory_bytes: 256
n, m, r = gets.strip.split.map(&:to_i)
r = gets.strip.split.map(&:to_i)
abc = readlines.map {|line| line.strip.split.map(&:to_i) }

roads = Array.new(n+1) { [10**8]*(n+1) }

abc.each do |a, b, c|
  roads[a][b]=roads[b][a]=c
end

(n+1).times do |via|
  (n+1).times do |s|
    s_via = roads[s][via]
    (n+1).times do |g|
      via_center = s_via + roads[via][g]
      roads[g][s] = roads[s][g] = via_center if roads[s][g] > via_center
    end
  end
end

def recursive_roads_check(current, cost, remains, roads)
  return cost if remains.empty?

  remains.map {|next_town|
    next_remains = remains.dup - [next_town]
    next_cost = 0
    next_cost = cost + roads[current][next_town] if current
    recursive_roads_check(next_town, next_cost, next_remains, roads)
  }.min
end

#roads.each {|r|p r}

p recursive_roads_check(nil, 0, r, roads)



Measured memory_bytes: 6140
#include <iostream>
#include <string>
#include <queue>
#include <stack>
#include <algorithm>
#include <list>
#include <vector>
#include <complex>
#include <utility>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <bitset>
#include <ctime>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cassert>
#include <cstddef>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <sstream>
#include <fstream>
#include <functional>

using namespace std;
#define REP(i, n) for (int (i) = 0; (i) < (n); (i)++)
#define FOR(i, a, b) for (int (i) = (a); (i) < (b); (i)++)
#define RREP(i, a) for(int (i) = (a) - 1; (i) >= 0; (i)--)
#define FORR(i, a, b) for(int (i) = (a) - 1; (i) >= (b); (i)--)
#define DEBUG(C) cerr << #C << " = " << C << endl;
using LL = long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<LL>;
using VVL = vector<VL>;
using VD = vector<double>;
using VVD = vector<VD>;
using PII = pair<int, int>;
using PDD = pair<double, double>;
using PLL = pair<LL, LL>;
using VPII = vector<PII>;
template<typename T> using VT = vector<T>;
#define ALL(a) begin((a)), end((a))
#define RALL(a) rbegin((a)), rend((a))
#define SORT(a) sort(ALL((a)))
#define RSORT(a) sort(RALL((a)))
#define REVERSE(a) reverse(ALL((a)))
#define MP make_pair
#define FORE(a, b) for (auto &&a : (b))
#define FIND(s, e) ((s).find(e) != (s).end())
#define EB emplace_back
template<typename T> inline bool chmax(T &a, T b){if (a < b){a = b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if (a > b){a = b;return true;}return false;}

const int INF = 1e9;
const int MOD = INF + 7;
const LL LLINF = 1e18;

int main(void) {
    int N, A, B;
    cin >> N >> A >> B;
    int ma = min(A, B), mi = 0;
    if (A + B >= N) {
        mi = (A + B) - N;
    }
    cout << ma << " " << mi << endl;
}


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

int main() {
    int N;
    cin >> N;
    int a[2][N];

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

    int dp[2][N];

    dp[0][0] = a[0][0];
    for (int i = 1; i < N; i++) {
        dp[0][i] = dp[0][i-1] + a[0][i];
    }

    dp[1][0] = a[0][0] + a[1][0];
    for (int i = 1; i < N; i++) {
        dp[1][i] = max(dp[0][i], dp[1][i-1]) + a[1][i];
    }

    cout << dp[1][N-1] << endl;

    return 0;
}

Measured memory_bytes: 256
import java.lang.Math
fun main(args : Array<String>){
  val (x,a,b) = readLine()!!.split(" ").map { it.toInt() }
  when {
    Math.abs(x-a) < Math.abs(x-b) -> "A"
    else -> "B"
  }.let {
    println(it)
  }
}

Measured memory_bytes: 37864
#include<stdio.h>

int main()
{
	int s,h,m;
	scanf("%d",&s);
	h=s/3600;
	m=(s%3600)/60;
	s=s-3600*h-60*m;
	printf("%d:%d:%d\n",h,m,s);
	return 0;
}


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

int main()
{
    string s1,s2;
    cin >>s1>>s2;
    ll n=s1.size();
    ll m=s2.size();
    ll dp[n+1][m+1];
   // cout<<n<<m;
    for(int i=0;i<=n;i++)
    {
        for(int j=0;j<=m;j++)
        {
            if(i==0||j==0)
            dp[i][j]=0;
            else if(s1[i-1]==s2[j-1])
            {
                    dp[i][j]=1+dp[i-1][j-1];
            }
            else
            {
                    dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
                 
            }
        }
    }
    // for(int i=0;i<=n;i++)
    // {
    //     for(int j=0;j<=m;j++)
    //     {
    //         cout<<dp[i][j]<<" ";
    //     }
    //     cout<<endl;
    // }
    vector<char> ans;
    int curri=n;
    int currj=m;
    if(curri>0&&currj>0)
    while(1)
    {
       // cout<<curri<<" "<<currj<<endl;
        if(dp[curri][currj]==dp[curri-1][currj])
            curri--;
        else if(dp[curri][currj]==dp[curri][currj-1])
            currj--;
        else
            {
                ans.pb(s1[curri-1]);
                //cout<<s1[curri-1];
                curri--;
                currj--;  
            }
        
        if(curri==0||currj==0)
        {
            break;
        }       
    }
    if(dp[curri][currj]!=0)
    {
        if(curri==0&&currj==0)
        {
            ans.pb(s1[curri]);
        }
        else if(curri==0)
        {
            ans.pb(s1[0]);
        }
        else if(currj==0)
        {
            ans.pb(s2[0]);  
        } 
    }
    reverse(ans.begin(),ans.end());
   // cout<<ans.size();
    for(int i=0;i<ans.size();i++)
    cout<<ans[i];
}

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

int main() {
  int X, N;
  cin >> X >> N;
  bool f[101] = {};
  for (int i = 0; i < N; i++) {
    int p;
    cin >> p;
    f[p] = true;
  }

  int ans = 10000;
  for (int i = -10; i <= 110; i++) {
    if (i >= 0 && i <= 100 && f[i]) continue;
    if (abs(ans - X) > abs(i - X)) ans = i;
  }
  cout << ans << endl;
}

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

#define REP(i, n) for(int (i)=0;(i)<(n);++(i))
#define REPV(iter, v) for(auto (iter)=(v).begin(); (iter)!=(v).end();++(iter))
#define ALL(v) (v).begin(),(v).end()

#define MOD 1000000007

using namespace std;

typedef long long ll;

int main()
{
    double L;
    cin >> L;
    double ans = L * L * L / (3.0 * 3.0 * 3.0);

    cout << fixed;
    cout << setprecision(10) << ans << endl;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-


def gcd(a, b):
    if a < b:
        a, b = b, a
    if b == 0:
        return a
    c = a % b
    return gcd(b, c)


n, x = map(int, input().split())
X = list(map(int, input().split()))
ans = None
for i in range(n):
    if i == 0:
        ans = abs(X[i]-x)
    else:
        ans = gcd(ans, abs(X[i]-x))
print(ans)


Measured memory_bytes: 14224
import java.util.Scanner;

public class  Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in); //台形の面積を求める
        int a = sc.nextInt(); //上辺
        int b = sc.nextInt(); //下辺
        int h = sc.nextInt(); //高さ
      
        System.out.println((a+b)*h/2);
    }
}

Measured memory_bytes: 23252
#include<bits/stdc++.h>
using namespace std;
#define LL long long
#define pa pair<int,int>
const int Maxn=100010;
const int inf=2147483647;
int read()
{
	int x=0,f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9')x=(x<<3)+(x<<1)+(ch^48),ch=getchar();
	return x*f;
}
int a[Maxn],n,b[Maxn];LL ans=0;
int main()
{
	n=read();
	for(int i=1;i<=n;i++)a[i]=read();
	sort(a+1,a+1+n);
	int l=1,r=n;
	for(int i=1;i<=n;i++)
	if(i&1)b[i]=a[l++];else b[i]=a[r--];
	if(!(n&1))
	{
		swap(b[1],b[n-1]);
		for(int i=1;i<n;i++)ans+=(LL)abs(b[i]-b[i+1]);
	}
	else
	{
		swap(b[1],b[n-2]);
		for(int i=1;i<n;i++)ans+=(LL)abs(b[i]-b[i+1]);
		LL t=0;
		l=1,r=n;
		for(int i=1;i<=n;i++)
		if(i&1)b[i]=a[r--];else b[i]=a[l++];
		swap(b[1],b[n-2]);
		for(int i=1;i<n;i++)t+=(LL)abs(b[i]-b[i+1]);
		ans=max(ans,t);
	}
	printf("%lld",ans);
}


Measured memory_bytes: 1024
from collections import deque
K = int(input())

que = deque(range(1, 10))
for _ in range(K):
    x = que.popleft()
    target = x%10
    num = x*10 + target
    if target != 0:
        que.append(num-1)
    que.append(num)
    if target != 9:
        que.append(num+1)
print(x)


Measured memory_bytes: 11880
#include<iostream>
#include<cstdio>
#include<string>
#define len 150000

using namespace std;


struct A
{
	char name[100];
	int time;
};

int head, tail,N, interval;
A a[len];

A dequeue()
{
	A x = a[head++];
	head = head%len;
	return x;
}

void enqueue(A m)
{
	a[tail] = m;
	tail = (tail + 1) % len;
}

int main()
{
	cin >> N >> interval;
	for (int i = 0; i < N; i++)
	{
		scanf("%s", a[i].name);
		scanf("%d", &a[i].time);
	}
	head = 0;
	tail = N;
	int sum = 0;
	while (head != tail)
	{
		A x = dequeue();
		if (x.time <= interval)
		{
			sum = sum + x.time;
			cout << x.name << ' ' << sum << endl;
		}
		else
		{
			x.time = x.time - interval;
			sum = sum + interval;
			enqueue(x);
		}
	}

	return 0;
}


Measured memory_bytes: 18360
#include <iostream>
#include <vector>
#include <map>
#include <queue>
#include <set>

using namespace std;

typedef pair<int,int> P;

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

    vector<int> mp[H];
    vector<P> pool;

    for(int i=0; i<H; ++i) {
        for(int j=0; j<W; ++j) {
            int temp;
            cin >> temp;
            mp[i].push_back(temp);
        }
    }

    for(int i=0; i<H; ++i) {
        for(int j=0; j<W; ++j) {
            if((i==0 || mp[i][j]<mp[i-1][j]) && (i==H-1 || mp[i][j]<mp[i+1][j])
                && (j==0 || mp[i][j]<mp[i][j-1]) && (j==W-1 || mp[i][j]<mp[i][j+1])) pool.push_back(P(i,j));
        }
    }

    queue<P> q;
    map<P,int> check,m;
    int dh[4]={-1,0,1,0};
    int dw[4]={0,1,0,-1};
    int ans=0;

    for(auto x : pool) {
        q.push(x);
        m.clear();
        while(!q.empty()) {
            P p=q.front(); q.pop();
            int h=p.first;
            int w=p.second;

            if(m[p]!=0) continue;
            m[p]=1; ++check[p];
            if(check[p]==2) ++ans;

            for(int i=0; i<4; ++i) {
                if(h+dh[i]>=0 && h+dh[i]<H && w+dw[i]>=0 && w+dw[i]<W 
                    && mp[h][w]<mp[h+dh[i]][w+dw[i]]) q.push(P(h+dh[i],w+dw[i]));
            }
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 131924
#include<algorithm>//sort(all(変数),greater<型名>())で降順に、*max_element(all(変数))で最大値を獲得
#include<bits/stdc++.h>
#include<cmath>//切り上げceil(値)
#include<deque>
#include<iomanip>//setprecision(数字)
#include<iostream>
#include<list>
#include<map>
#include<numeric>
//xとyのgcdは__gcd(x,y),xとyのlcmは(x*y)/__gcd、accumulate(all(変数),0)で要素の全加算
#include<queue>//priority_queue<型名> 変数
#include<set>
#include<stack>
#include<string>
#include<vector>
#define rep(i,n)  for(ll i=0; i<n; i++)
#define rrep(i,n) for(ll i=n-1; 0<=i; i--)
#define vll vector<ll>
#define vi vector<int>
#define all(x) (x).begin(),(x).end()
#define INF 1e18
using ll = long long;
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

int main(){
  int k; cin >> k;
  string s; cin >> s;
  if(s.size() <= k){
    cout << s;
  }else{
    rep(i,k) cout << s[i];
    cout << "...";
  }
}


Measured memory_bytes: 3620
parseInt(x) = parse(Int, x)
parseBigInt(x) = parse(BigInt, x)
parseFloat(x) = parse(Float64, x)
parseBigFloat(x) = parse(BigFloat, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)

function main()
    n,m=parseMap(split(readline()))
    a=parseMap(split(readline()))
    ans=sum(a)
    if ans>n
        println(-1)
    else
        println(n-ans)
    end
end
main()

Measured memory_bytes: 164384
#include <cstdio>
#include <algorithm>
#include <stack>
#include <queue>
#include <deque>
#include <vector>
#include <string>
#include <string.h>
#include <cstdlib>
#include <ctime>
#include <cmath>
#include <map>
#include <set>
#include <iostream>
#include <sstream>
#include <numeric>
#include <cctype>
#include <bitset>
#include <cassert>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define gep(i,g,j) for(int i = g.head[j]; i != -1; i = g.e[i].next)
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define rng(a) a.begin(),a.end()
#define maxs(x,y) x = max(x,y)
#define mins(x,y) x = min(x,y)
#define pb push_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcount
#define uni(x) x.erase(unique(rng(x)),x.end())
#define snuke srand((unsigned)clock()+(unsigned)time(NULL));
#define df(x) int x = in()
#define dame { puts("-1"); return 0;}
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,vector<T>,greater<T> >
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
inline int in() { int x; scanf("%d",&x); return x;}
inline void priv(vi a) { rep(i,sz(a)) printf("%d%c",a[i],i==sz(a)-1?'\n':' ');}
template<typename T>istream& operator>>(istream&i,vector<T>&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T>string join(vector<T>&v)
{stringstream s;rep(i,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename T>ostream& operator<<(ostream&o,vector<T>&v)
{if(sz(v))o<<join(v);return o;}
template<typename T1,typename T2>istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<typename T1,typename T2>ostream& operator<<(ostream&o,pair<T1,T2>&v)
{return o<<v.fi<<","<<v.se;}
const int MX = 2505, INF = 1001001001;
const ll LINF = 1e18;
const double eps = 1e-10;

ll dp[MX][MX][2];

int main() {
  int n;
  scanf("%d",&n);
  vi a(n), b(n);
  rep(i,n) scanf("%d%d",&a[i],&b[i]);
  vi id(n);
  rep(i,n) id[i] = i;
  sort(rng(id),[&](int i, int j) { return a[i]+b[i] > a[j]+b[j];});
  int m = n/2;
  rep(i,m+1)rep(j,m+1)rep(k,2) dp[i][j][k] = LINF;
  dp[0][0][0] = 0;
  rep(i,n) {
    ll x = a[id[i]];
    ll y = b[id[i]];
    ll w = x+y;
    rep(k,2)rep(l,m+1) {
      int r = i-k-l;
      if (r < 0) break;
      if (!k) {
        mins(dp[l][r][k+1], dp[l][r][k]+w*m);
      }
      mins(dp[l+1][r][k], dp[l][r][k]+w*l+y);
      mins(dp[l][r+1][k], dp[l][r][k]+w*r+x);
    }
  }
  cout<<dp[m][m][n&1]<<endl;
  return 0;
}































Measured memory_bytes: 98304
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		long N = sc.nextLong();
		
		long A = 1;
		for(long i=1;i*i<=N;i++) {
			if(N%i == 0 && i>A) {
				A = i;
			}
		}
		long B = N/A;
		
		
		System.out.println(A+B-2);
		
		sc.close();
	}
}

Measured memory_bytes: 22868
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int x = sc.nextInt();
        int a = sc.nextInt();
        if (x < a) {
            System.out.println(0);
            return;
        }
        System.out.println(10);
    }

}


Measured memory_bytes: 23636