akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
  ll n,q;cin>>n>>q;
  ll niko[n];
  ll sum[n];
  ll a[n];
  for(ll i=0;i<n;i++){
    cin>>a[i];
    if(i==0)sum[i]=a[i];
    else sum[i]=sum[i-1]+a[i];
    if(i==0||i==1)niko[i]=a[i];
    else niko[i]=niko[i-2]+a[i];
  }
  vector<ll> kyou;
  for(ll i=n/2;i<n-1;i++){
    ll t=n-i-1;
    kyou.push_back((a[i]+a[i-t])/2+1);
  }
  kyou.push_back((a[n-1]+a[n-2])/2+1);
  //for(ll i=0;i<n;i++)cout<<niko[i];return 0;
  for(ll i=0;i<q;i++){
    ll x;cin>>x;
    ll y=upper_bound(kyou.begin(),kyou.end(),x)-kyou.begin();
    //cout<<y<<endl;
    if(y==0)cout<<sum[n-1]-sum[n/2-1]<<endl;
    else if(y==kyou.size()){
      cout<<niko[n-1]<<endl;
    }
    else{
      ll u=n/2+y-1;
      ll ans=sum[n-1]-sum[u];
      cout<<ans+niko[2*u-n+1]<<endl;
    }
  }
}

Measured memory_bytes: 4600
n, m = map(int, input().split())
a = sorted(map(int, input().split()))

bc = []

for _ in range(m):
    bi, ci = map(int, input().split())

    bc.append((bi, ci))

bc.sort(reverse=True, key=lambda x: x[1])

i = 0

c = 0

for b, c in bc:
    j = 0

    while i < n and j < b and a[i] <= c:
        a[i] = c

        i += 1
        j += 1

print(sum(a))

Measured memory_bytes: 74264
fn main() {
    let n: isize = read();
    let mut sum = 0;
    let mut ma = -std::isize::MAX;
    let mut mi = std::isize::MAX;
    for _ in 0..n {
        let v: isize = read();
        sum += v;
        ma = max(ma, v);
        mi = min(mi, v);
    }
    println!("{} {} {}", mi, ma, sum);
}

// =========
#[allow(unused_imports)]
use std::cmp::{max, min};
#[allow(unused_imports)]
use std::collections::{HashMap, HashSet};
#[allow(unused_imports)]
use std::process::exit;

#[allow(dead_code)]
const MOD: isize = 1000000007;

fn read<T: std::str::FromStr>() -> T {
    use std::io::Read;
    let stdin = std::io::stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

// =========



Measured memory_bytes: 5048
#include<bits/stdc++.h>
using namespace std;
int main(){
	string a,b;
	cin>>a>>b;
	if(a.size()==b.size()){
		for(int i=0;i<a.size();i++){
			if(a[i]==b[i]) continue;
			else if(a[i]<b[i]){
				cout<<"LESS";return 0;
			}
			else{
				 cout<<"GREATER";return 0;	
			} 
		}
		cout<<"EQUAL";
	}
	else if(a.size()>b.size()){
		cout<<"GREATER";
	}
	else cout<<"LESS";
	return 0;
}

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

int main(int argc, char const *argv[]) {

  int ant[5] = {0};
  int k;

  uint8_t max = 0;  //UINT8_MIN
  uint8_t min = 255;  //UINT8_MAX

  scanf("%d\n", &ant[0]);
  scanf("%d\n", &ant[1]);
  scanf("%d\n", &ant[2]);
  scanf("%d\n", &ant[3]);
  scanf("%d\n", &ant[4]);
  scanf("%d\n", &k);

  for(int i = 0; i < 5; ++i){
    if(max < ant[i]){
      max = ant[i];
    }
    if(min > ant[i]){
      min = ant[i];
    }
  }

  if(max - min <= k){ cout << "Yay!" << endl;}
  else{ cout << ":(" << endl;}

  return 0;
}


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

typedef long long ll;
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    ll n;
    cin>>n;
    vector<ll>v(n);
    ll i=1;
    for(auto &x: v)
    {
        ll a;
        cin>>a;
        x=a-i;
        i++;
    }
    sort(v.begin(),v.end());
    ll ans=0;
    ll p=v[n/2];
    for(auto x: v)
    {
        ans+=abs(x-p);
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 1792
#include <stdio.h>

int main(){

  int n,y;
  scanf("%d%d",&n,&y);

  int i,j;

  for(i=0;i<=n;++i){
    for(j=0;j<=n-i;++j){
      if(i*10000+j*5000+(n-i-j)*1000==y){
        printf("%d %d %d",i,j,(n-i-j));
        return 0;
      }
    }
  }

  printf("-1 -1 -1");

  return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<cmath>
#include<string>
#include<cstdlib>

using namespace std;

int main()
{
  string S;
  string T;

  cin >> S;
  cin >> T;

  int count =0;

  for(int i=0; i<3; i++)
    {
      if(S[i]==T[i])
	count++;
    }

  cout << count << endl;


  return 0;
}



Measured memory_bytes: 256
arr = input("")
num = [int(n) for n in arr.split()]
num.sort()
ans = (num[2]-num[0])//2 + (num[2]-num[1])//2
num[0] = (num[2]-num[0])//2*2+num[0]
num[1] = (num[2]-num[1])//2*2+num[1]


if(num[0]==num[1] and num[0]==num[2]):
    print(ans)
elif (num[0]==num[1] and num[0]!=num[2]):
    print(ans+1)
elif(num[0] == num[2] and num[1]!=num[2]):
    print(ans+2)
elif(num[1] == num[2] and num[0]!=num[2]):
    print(ans+2)
elif(num[0] == num[1] and num[0]!=num[2]):
    print(ans+1)


Measured memory_bytes: 38256
#include<bits/stdc++.h>
#define M 100002
#define mo 1000000007
using namespace std;
int n,m;
vector<int>son[M];
long long dfs(int x,int fa){
	long long res=1;
	long long num=fa==0?m-1:m-2,tot=1;
	if(son[x].size()-(fa!=0)>num)return 0;
	for(int i=1;i<=son[x].size()-(fa!=0);i++)tot=(1ll*(num-i+1)*tot)%mo;
	for(int i=0;i<son[x].size();i++){
		int y=son[x][i];
		if(y==fa)continue;
		res=(res*dfs(y,x))%mo;
	}
	return (res*tot)%mo;
}
int main(){
	int u,v;
	scanf("%d%d",&n,&m);
	for(int i=1;i<n;i++)scanf("%d%d",&u,&v),son[u].push_back(v),son[v].push_back(u);
	printf("%lld\n",(m*dfs(1,0))%mo);
	return 0;
}

Measured memory_bytes: 11520
#include<stdio.h>

int divisor(int a){
    int i,cnt=0;
    for(i=1;i<=a;i++){
        if(a%i==0)cnt++;
    }
    return cnt;
}

int main(){
    int n,i,j,div,cnt=0;
    scanf("%d",&n);
    for(i=1;i<=n;i+=2){
        div=divisor(i);
        if(div==8)cnt++;
    }
    printf("%d\n",cnt);
    return 0;

}


Measured memory_bytes: 128
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

sum = 0
for i in range(N):
    sum += B[A[i] - 1]
    if A[i] - A[i - 1] == 1 and i > 0:
        sum += C[A[i - 1] - 1]
print(sum)


Measured memory_bytes: 3064
import java.util.*;
import java.io.*;

class Main {

	void solve() {

		int n = inint(), a = inint();
		out.println(n%500<=a ? "Yes" : "No");

	}

	public static Scanner in = new Scanner(System.in);
	public static PrintWriter out = new PrintWriter(System.out);

	public static void main(String[] args) {
		new Main().solve();
		out.flush();
	}

	public int inint() {
		return in.nextInt();
	}

	public String instr() {
		return in.next();
	}

	public int[] inintar(int num) {
		int[] a = new int[num];
		for (int i=0; i<num; i++) {
			a[i] = in.nextInt();
		}
		return a;
	}

	public char[] incharar() {
		return in.next().toCharArray();
	}

}

Measured memory_bytes: 21844
#include <stdio.h>

int main(){
	long long int a,b,c,k;
	scanf("%lld%lld%lld%lld",&a,&b,&c,&k);
	while(k--){
		if(a>b && a>c)
			a*=2;
		else if(b>a && b>c)
			b*=2;
		else
			c*=2;
	}
	printf("%lld\n",a+b+c);
	return 0;
}

Measured memory_bytes: 128
#include<stdio.h>  

void trace(int A[],int N){
  int i;
  for (i=0;i<N;i++){
    if(i>0)printf(" ");
    printf("%d",A[i]);
  }
  printf("\n");
}

void insertionSort(int A[],int N){
  int j,i,v;
  for (i=1;i<N;i++){
    v = A[i];
    j = i-1;
    while(j >= 0 && A[j] > v){
      A[j + 1] = A[j];
      j--;
    }
    A[j + 1] = v;
    trace(A,N);
  }
}

int main(){
  
  int N;
  int A [100];
  int i,j;
  
  scanf("%d",&N);
  
  for(i = 0;i < N;i++)scanf("%d",&A[i]);
  
  trace(A,N);
  insertionSort(A,N);
  return 0;
}






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

int main(){
 int N; cin >> N;
 int H[N];
 int res = 0;

 for(int i=0; i<N; i++) cin >> H[i];
 
 for(int i=N-1; i>=0; i--){
   int flag = 1;
   for(int j=i-1; j>=0; j--){
   	int tmp = H[j] - H[i];
    if(tmp>0) flag = 0;
   }
   if(flag) res++;
 }
  cout << res << endl;
  return 0;
}

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

using namespace std;

int n, m;
char a[501][501];
char r[501][501];
char b[501][501];

int main () {
	cin >> n >> m;
	for (int i = 1;i <= n;i ++) {
		for (int j = 1;j <= m;j ++) {
			cin >> a[i][j];
			r[i][j] = b[i][j] = '.';
		}
	}
	for (int i = 1;i <= n;i ++) {
		r[i][1] = '#';
		if (i % 2) {
			for (int j = 1;j < m;j ++) {
				r[i][j] = '#';
			}
		}   	
	}
	for (int i = 1;i <= n;i ++) {
		b[i][m] = '#';
		if (i % 2 == 0) {
			for (int j = 2;j <= m;j ++) {
				b[i][j] = '#';
			}
		}   	
	}
	for (int i = 1;i <= n;i ++) {
		for (int j = 1;j <= m;j ++) {
			if (a[i][j] == '#') r[i][j] = '#';
			cout << r[i][j];
		}
		cout << endl;
	}
	cout << endl;
	for (int i = 1;i <= n;i ++) {
		for (int j = 1;j <= m;j ++) {
			if (a[i][j] == '#') b[i][j] = '#';
			cout << b[i][j];
		}
		cout << endl;
	}
	return 0;
}

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

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

using namespace std;

int main(){
  int n,k;cin>>n>>k;
  int result=0;

  rep(i,n){
    int x;cin>>x;
    result+=2*min(x,abs(k-x));
  }
  cout<<result;

  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);

		int a=scan.nextInt();
		int b=scan.nextInt();
		int c=scan.nextInt();

		int aa=b+c;
		int bb=a+c;
		int cc=a+b;


		if(a==aa) {
			System.out.println("Yes");

		}else if(b==bb) {
			System.out.println("Yes");

		}else if(c==cc) {
			System.out.println("Yes");

		}else {
			System.out.println("No");
		}

	}

}

Measured memory_bytes: 23892
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()
def resolve():
    n,k=map(int,input().split())
    H=list(map(int,input().split()))
    ans=0
    for h in H:
        ans+=(h>=k)
    print(ans)
resolve()

Measured memory_bytes: 51440
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxN = 3e5 + 10;
const int maxT = 3e5;
pair<int,int> a[maxN];
int cnt[maxN];

int main(){
//  freopen("abc.inp", "r", stdin); freopen("abc.out", "w", stdout);
  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  int n, m;
  cin >> n >> m;
  int q; cin >> q;
  priority_queue< pair<int, int> > pq;
  multiset<int> ms;
  for (int i = 1; i <= maxT; ++i) {
    ms.insert(0);
  }
  for (int i = 1; i <= q; ++i) {
    cin >> a[i].first >> a[i].second;
    auto it = ms.lower_bound(cnt[a[i].second]);
    ms.erase(it);
    ++cnt[a[i].second];
    ms.insert(cnt[a[i].second]);
  }
  sort(a + 1, a + q + 1);

  int ans = 0;
  for (int i = 1; i <= q; ++i) {
    int j = i;
    int dem = 0;
    while (j <= q && a[j].first == a[i].first) {
      ++dem;
      auto it = ms.lower_bound(cnt[a[j].second]);
      ms.erase(it);
      --cnt[a[j].second];
      ms.insert(cnt[a[j].second]);
      ++j;
    }
    --j;
    auto it = ms.end();
    --it;
    ans = max(ans, dem + *it);
    while (i <= j) {
      it = ms.lower_bound(cnt[a[i].second]);
      ms.erase(it);
      ++cnt[a[i].second];
      ms.insert(cnt[a[i].second]);
      ++i;
    }
  --i;
  }
  cout << ans;
return 0;
}


Measured memory_bytes: 21156
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <queue>
#include <algorithm>
using namespace std;
typedef unsigned int uint;
typedef long long ll;
typedef pair<int, int> P;
const int c_INF = 111111111;
const int c_mINF = -111111111;
const int c_YET = -1;
const int c_Dx[4] = { 0,0,1,-1 };
const int c_Dy[4] = { 1,-1,0,0 };
const int c_div = 1000000007; //10^9 + 7


int main() {


	int N;
	scanf("%d", &N);

	if (N < 1200)printf("ABC");
	else if (N < 2800)printf("ARC");
	else  printf("AGC");


}

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

using namespace std;

int n, a[100100], b[100100], c[100100];
int dp[100100][3];

int main() {
    
    cin >> n;
    
    for(int i = 1;i <= n;++i){
        cin >> a[i] >> b[i] >> c[i];
    }
    
    for(int i = 1;i <= n;++i){
        dp[i][0] = a[i] + max(dp[i - 1][1], dp[i - 1][2]);
        dp[i][1] = b[i] + max(dp[i - 1][0], dp[i - 1][2]);
        dp[i][2] = c[i] + max(dp[i - 1][0], dp[i - 1][1]);
    }
    
    cout << max(dp[n][0], max(dp[n][1], dp[n][2]));
}

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

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

    static class abc163_a {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            float R = in.nextFloat();
            out.println(2 * 3.141592 * R);
        }

    }
}



Measured memory_bytes: 37432
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <set>
#include <utility>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <deque>
#include <unordered_map>
#include <map>
#include <bitset>
#include <string>
#include <cstring>

#define pb push_back
#define mp make_pair
#define l(x) x << 1
#define r(x) x << 1 | 1
#define scan(x) do {while((x=getchar())<'0') ; for(x-='0'; '0'<=(_=getchar()); x=(x<<3)+(x<<1)+_-'0') ; } while(0)
char _;
#define x first
#define y second

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<float, float> pff;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;
typedef map<int, int> mii;
typedef unordered_map<int, int> umii;

int main() {
    string s;
    cin >> s;
    for (int i = 0, j = s.length() - 1; i < j; i++, j--) {
        if (s[i] != s[j]) {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n) ;i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define sz(x) ((int)(x).size())
using ll=long long;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define MOD  1000000007
const ll INF=1e18;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b){ a = b; return 1; } return 0; }
const int MAX = 510000;
long long fac[MAX], finv[MAX], inv[MAX];
ll gcd(ll a, ll b){
        if(b == 0) return a;
        return gcd(b, a % b);
}

map< int64_t, int > prime_factor(int64_t n) {
  map< int64_t, int > ret;
  for(int64_t i = 2; i * i <= n; i++) {
    while(n % i == 0) {
      ret[i]++;
      n /= i;
    }
  }
  if(n != 1) ret[n] = 1;
  return ret;
}

int main(int argc, char const *argv[]) {
  ll a,b;
  cin >> a >> b;
  ll m=gcd(a,b);
  set<ll> S;
  for(auto p : prime_factor(m)) {
    while(p.second--){
      S.insert(p.fi);
    }
  }
  cout << S.size()+1 << endl;


  return 0;
}


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

#define rep(i, n) for (int i = 0; i < (n); i++)
#define repr(i, n) for (int i = (n) - 1; i >= 0; i--)

using namespace std;
using ll = long long;

const int MOD = 1000000007;

class mint {
  int n;
public:
  mint(int n_ = 0) : n(n_) {}
  friend mint operator-(mint a) { return -a.n + MOD * (a.n != 0); }
  friend mint operator+(mint a, mint b) { int x = a.n + b.n; return x - (x >= MOD) * MOD; }
  friend mint operator-(mint a, mint b) { int x = a.n - b.n; return x + (x < 0) * MOD; }
  friend mint operator*(mint a, mint b) { return (long long)a.n * b.n % MOD; }
  friend mint &operator+=(mint &a, mint b) { return a = a + b; }
  friend mint &operator-=(mint &a, mint b) { return a = a - b; }
  friend mint &operator*=(mint &a, mint b) { return a = a * b; }
  friend bool operator==(mint a, mint b) { return a.n == b.n; }
  friend bool operator!=(mint a, mint b) { return a.n != b.n; }
  friend istream &operator>>(istream &i, mint &a) { return i >> a.n; }
  friend ostream &operator<<(ostream &o, mint a) { return o << a.n; }
};

vector<mint> F_{1, 1}, R_{1, 1}, I_{0, 1};

void check_fact(int n) {
  for (int i = I_.size(); i <= n; i++) {
    I_.push_back(I_[MOD % i] * (MOD - MOD / i));
    F_.push_back(F_[i - 1] * i);
    R_.push_back(R_[i - 1] * I_[i]);
  }
}

#ifdef SLOW
mint I(int n) { check_fact(abs(n)); return n >= 0 ? I_[n] : -I_[-n]; }
mint F(int n) { check_fact(n); return n < 0 ? 0 : F_[n]; }
mint R(int n) { check_fact(n); return n < 0 ? 0 : R_[n]; }
mint C(int n, int r) { return F(n) * R(n - r) * R(r); }
mint P(int n, int r) { return F(n) * R(n - r); }
mint H(int n, int r) { return n == 0 ? (r == 0) : C(n + r - 1, r); }
#else
mint I(int n) { return I_[n]; }
mint F(int n) { return F_[n]; }
mint R(int n) { return n < 0 ? 0 : R_[n]; }
mint C(int n, int r) { return F(n) * R(n - r) * R(r); }
mint P(int n, int r) { return F(n) * R(n - r); }
mint H(int n, int r) { return n == 0 ? (r == 0) : C(n + r - 1, r); }
#endif

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int H, W, K;
  cin >> H >> W >> K;
  F_.reserve(H+W+1);
  R_.reserve(H+W+1);
  I_.reserve(H+W+1);
  check_fact(H+W);
  mint ans;
  for (int i=1; i<=K; i++) {
    ans += F(i) * P(H+W-i, K-i) * (C(H+W,i) + (H+W)*C(H+W-1,i-1) + C(H+W-2,i-2)*H*W);
  }
  cout << ans << '\n';
}



Measured memory_bytes: 234624
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define fi first
#define se second
#define vll vector<ll>
#define pii pair<ll,ll>
#define vvll vector< vector<ll> >
#define pb push_back
#define sz(v) (ll)(v).size()
#define inf 1e18
#define md 1000000007
#define all(v) (v).begin(),(v).end()
#define rep(i,a,b) for(ll i=a;i<b;++i)
#define tel(a){cout<<a<<"\n";}
#define tell(a,b){cout<<a<<" | "<<b<<"\n";}
#define telll(a,b,c){cout<<a<<" | "<<b<<" | "<<c<<"\n";}
#define teln(v,n){cout<<"v- ";rep(o,0,n)cout<<v[o]<<" ";cout<<"\n";}
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;

#define M 100010


int main(){
    IOS;
     
    ll n,k;cin>>n>>k;
    ll a[n];
    rep(i,0,n)cin>>a[i];
    sort(a,a+n);
    ll ans=1;
    if(a[n-1]==0 and (k&1)){
    	cout<<0;return 0;
    }
    if(a[n-1]<=0 and (k&1)){
    	for(ll i=n-1;i>=n-k;--i){a[i]%=md;(ans*=a[i])%=md,(ans+=md)%=md;}
    	cout<<ans;
    	return 0;
    }
    ll i=0,j=n-1;
    if(k&1){a[j]%=md,(ans*=a[j])%=md,(ans+=md)%=md;j--,k--;}k/=2;
	rep(p,0,k){
		ll l=a[i]*a[i+1],r=a[j]*a[j-1];
		if(l>r){l%=md;(ans*=l)%=md,(ans+=md)%=md;i+=2;}
		else {r%=md;(ans*=r)%=md,(ans+=md)%=md;j-=2;}
		// tell(i,j);
	}     
    cout<<ans;
    
    return 0;
}


Measured memory_bytes: 5136
N, M = map(int, input().split())

l = []
for i in range(N):
  K, *A = map(int, input().split())
  for k in range(K):
    l.append(A[k])

cnt = 0
for i in list(set(l)):
  if l.count(i) == N:
    cnt = cnt + 1

print(cnt)

Measured memory_bytes: 3060
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#pragma GCC target ("avx2,tune=native")
#include<bits/stdc++.h>
#include<ext/pb_ds/tree_policy.hpp>
#include<ext/pb_ds/assoc_container.hpp>
#define pb push_back
#define __V vector
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define oit ostream_iterator
#define mod 1000000007ll
using namespace std;
using namespace __gnu_pbds;
void doin() {
	cin.tie();
	cout.tie();
	ios::sync_with_stdio(0);
#ifndef ONLINE_JUDGE
//	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);
#endif
}
template<typename X, typename Y>
istream& operator>>(istream& in, pair<X, Y> &a) {
	in >> a.first >> a.second;
	return in;
}
template<typename T>
void getv(T& i) {
	cin >> i;
}
template<typename T, typename ... Ns>
void getv(vector<T>& v, int n, Ns ... ns) {
	v.resize(n);
	for (auto& i : v)
		getv(i, ns...);
}
template<typename T>
void getv1(T& i) {
	cin >> i;
}
template<typename T, typename ... Ns>
void getv1(vector<T>& v, int n, Ns ... ns) {
	v.resize(n + 1);
	for (int i = 1; i <= n; i++)
		getv1(v[i], ns...);
}
#ifdef _WIN32
#define getchar_unlocked() _getchar_nolock()
#define _CRT_DISABLE_PERFCRIT_LOCKS
#endif
inline void getch(char &x) {
	while (x = getchar_unlocked(), x < 33) {
		;
	}
}
inline void getstr(string &str) {
	str.clear();
	char cur;
	while (cur = getchar_unlocked(), cur < 33) {
		;
	}
	while (cur > 32) {
		str += cur;
		cur = getchar_unlocked();
	}
}
template<typename T> inline bool sc(T &num) {
	bool neg = 0;
	int c;
	num = 0;
	while (c = getchar_unlocked(), c < 33) {
		if (c == EOF)
			return false;
	}
	if (c == '-') {
		neg = 1;
		c = getchar_unlocked();
	}
	for (; c > 47; c = getchar_unlocked())
		num = num * 10 + c - 48;
	if (neg)
		num *= -1;
	return true;
}
template<typename a, typename b>
void minq(a& x, b y) {
	if (x > y)
		x = y;
}
template<typename a, typename b>
void maxq(a& x, b y) {
	if (x < y)
		x = y;
}
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef ll _I;
typedef pair<_I, _I> pi;
typedef pair<ld, ld> pd;
typedef map<_I, _I> mii;
typedef __V <_I> vi;
typedef __V <char> vc;
typedef __V <string> vs;
typedef __V <ld> vd;
typedef __V <vd> vvd;
typedef __V <pi> vpi;
typedef __V <__V<_I>> vvi;
typedef __V <__V<char>> vvc;
typedef __V <__V<pi>> vvpi;
using AntonTsypko = void;
using arsijo = AntonTsypko;
using god = arsijo;
//store differences, not the elements for rsq in fenwick or array(for write-only)
//Sum Over Subsets + inclusion-exclusion is a thing! (Solved div1E (383E) using it!)
//SQRT-heuristic divide items into groups: >sqrt and <=sqrt and do something according to group(eg. trie for one, z-func for other) - 1202E
uniform_real_distribution<double> double_dist(0, 1);
//WHEN DOING MODULAR SUBTRACTION ALWAYS **ALWAYS** ADD MOD
//don't use AVX at AtCoder(=RE)
//Trie: MAXDEPTH!=MAXSIZE
//suspiciously big numbers? use python, seriosly you don't wanna waste your time if it overflows
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int main() {
	doin();
	ll a, b;
	cin >> a >> b;
	cout << max({a+b, a-b, a*b});
}


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

int main(){
  int n;
  cin >> n;
  vector<int> p(n);
  rep(i,n) cin >> p[i];
  
  sort(p.begin(),p.end());
  
  int ans = 0;
  ans = p[n/2] - p[n/2-1];
  
  cout << ans << endl;
}


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

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vint;
typedef vector<double> vd;
typedef vector<ll> vll;
typedef vector<string> vstr;
typedef vector<vector<int>> vvint;
typedef vector<pair<int, int>> vpii;
typedef vector<pair<ll, ll>> vpll;
typedef priority_queue<int, vector<int>, greater<int>> spqint; //小さい順に取り出し
typedef priority_queue<ll, vector<ll>, greater<ll>> spqll;     //小さい順に取り出し
typedef priority_queue<int, vector<int>, less<int>> bpqint;    //大きい順に取り出し
typedef priority_queue<ll, vector<ll>, less<ll>> bpqll;        //大きい順に取り出し

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, a, b) for (int i = (int)a; i < (int)b; i++)
#define IREP(i, v) for (auto i = (v).begin(); i != (v).end(); i++)
#define FI first
#define SE second
#define MP make_pair
#define MT make_tuple
#define PB push_back
#define PF push_front
#define TS to_string
#define BS binary_search
#define LB lower_bound
#define UB upper_bound
#define NP next_permutation
#define ALL(v) (v).begin(), (v).end()
#define SZ(x) (ll) x.size()
#define SP(x) setprecision((ll)x)

int INF = 1e9;
int NIL = -1;
ll MOD = 1000000007;
ll LINF = 1e18;
double EPS = 1e-9;
double PI = M_PI;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; } //最大公約数
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }     //最小公倍数

void yes(){ cout << "Yes" << endl;}
void no(){ cout << "No" << endl;}
//-----------------------------------------

//-----------------------------------------
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    std::chrono::system_clock::time_point start,end;
    start = std::chrono::system_clock::now();

    string  s;
    int k ;
    cin >> s >> k ;
    int n = SZ(s) ;
    vint cost(n) ;
    REP(i,n){
        cost[i] = 'z' - s[i] + 1 ;
    }
    REP(i,n-1){
        if(k>=cost[i] && s[i]!='a'){
            s[i] = 'a' ;
            k -= cost[i] ;
        }
    }
    s[n-1] = (s[n-1] - 'a' + k)%26 + 'a' ;

    cout << s <<endl;



    end = std::chrono::system_clock::now();
    auto elapsed = std::chrono::duration_cast< std::chrono::milliseconds >(end - start).count();
    //std::cout << elapsed <<"ms"<< std::endl;

    

    return 0;
}



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

using namespace std;

typedef long long ll;

int main() {
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n, l;
    cin >> n >> l;
    vector<int> a(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    for (int i = 0; i + 1 < n; ++i) {
        if (a[i] + a[i + 1] >= l) {
            cout << "Possible\n";
            for (int j = 1; j <= i; ++j) {
                cout << j << '\n';
            }
            for (int j = n - 1; j > i; --j) {
                cout << j << '\n';
            }
            return 0;
        }
    }
    cout << "Impossible";
    return 0;
}

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

int main(){
    string S;
    cin>>S;
    bool flg;
    flg=true;
    if(S[0]!='A'){
        flg=false;
    }
    int cnt=0;
    for(int i=2;i<S.size()-1;i++){
        if(S[i]=='C'){
            cnt++;
        }
    }
    if(cnt!=1){
        flg=false;
    }
    int cnt1=0;
    for(int i=0;i<S.size();i++){
        if(('A'<=S[i]) && (S[i]<='Z')){
            cnt1++;
        }
    }
    if(cnt1!=2){
        flg=false;
    }
    if(flg){
        cout<<"AC"<<endl;
    }
    else{
        cout<<"WA"<<endl;
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main()
{
	int n, m;
	cin >> n >> m;
	vector<long long> vX, vY, vZ, vT;
	long long r = 0;
	vX.assign(n, 0); vY.assign(n, 0); vZ.assign(n, 0); vT.assign(n, 0);
	for (int i = 0; i < n; ++i)
		cin >> vX[i] >> vY[i] >> vZ[i];

	int P[8][3] = { {1,1,1},{1,1,-1},{1,-1,1},{1,-1,-1},{ -1,1,1 },{ -1,1,-1 },{ -1,-1,1 },{ -1,-1,-1 } };
	for (int i = 0; i < 8; ++i) {
		for (int j = 0; j < n; ++j) 
			vT[j] = vX[j] * P[i][0] + vY[j] * P[i][1] + vZ[j] * P[i][2];
		sort(vT.begin(), vT.end());
		long long a = 0;
		for (int k = n - m; k < n; ++k)
			a += vT[k];
		if (r < a)
			r = a;
	}
	cout << r << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <climits>
#include <string>
#include <bitset>
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define fin(ans) cout<<(ans)<<endl
#define STI(s) atoi(s.c_str())
#define mp(p,q) make_pair(p,q)
#define pb(n) push_back(n)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define Sort(a) sort(a.begin(),a.end())
#define Rort(a) sort(a.rbegin(),a.rend())
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
const int P = 1000000007;
const int INF = INT_MAX;
const ll LLINF = 1LL<<60;



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

    int n;
    cin>>n;
    vi a(n);
    rep(i,n)cin>>a[i];
    map<int,int> m;
    rep(i,n){
        if(m.find(a[i])!=m.end()){
            m[a[i]]++;
        }
        else m[a[i]]=1;
    }
    int sum=0;
    for(auto it=m.begin();it!=m.end();it++){
        sum+=it->second-1;
    }
    if(sum%2==1)sum++;
    cout<<max(0,n-sum)<<endl;


//////////////////////////////////////////////////////
return 0;}

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

typedef long long int ll;

int main(){
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	string s, t;
	cin >> s >> t;
	int count = 0, n = s.size();
	for (int i = 0; i < n; i++)
		count += (s[i] != t[i]);
	cout << count << '\n';
}

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

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> mat;
#define FOR(i,a,b) for(int i=(a);i<(int)(b);++i)
#define rep(i,n) FOR(i,0,n)
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
#define mset(a,x) memset(a,x,sizeof(a))
#define FASTIO cin.tie(0),ios::sync_with_stdio(0)




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

    int all = 1, sub = 1;
    for (int i = 0; i < n; i++) {
        int a;
        cin >> a;
        if (a % 2 == 0) sub *= 2;
        all *= 3;
    }

    cout << all - sub << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int mod = 1000000007;

int main() {
    ios::sync_with_stdio(false);
    int n, c[22] = {}, v[22] = {}, z = 0;
    cin >> n;
    for (int i = 0; i < n; i++) cin >> c[i];
    for (int i = 0; i < n; i++) cin >> v[i];
    for (int i = 0; i < (1 << n); i++) {
        int x = 0, y = 0;
        for (int j = 0; j < n; j++) if (i & (1 << j)) x += c[j], y += v[j];
        z = max(z, x - y);
    }
    cout << z;
}


Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<cmath>
using namespace std;

int main()
{
    while (true) {
        int n;
        cin >> n;
        
        if (n == 0) {
            break;
        }
        
        double s[n] = {0};
        for (int i = 0; i < n; i++) {
            double temp;
            scanf("%lf", &temp);
            s[i] = temp;
        }
        
        double avg = 0;
        for (int j = 0; j < n; j++) {
            avg += s[j];
        }
        avg /= n;
        
        double a_2 = 0;
        for (int k = 0; k < n; k++) {
            a_2 += pow(s[k] - avg, 2.0);
        }
        a_2 /= n;
        
        printf("%lf\n", sqrt(a_2));
    }
}


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

const int N = 3010;

typedef long long LL;

struct edge {
    int to, next, w, c;
} e[N * 10];

int head[N], ecnt = 1;

inline void adde(int from, int to, int w, int c) {
    e[++ecnt] = (edge){to, head[from], w, -c}, head[from] = ecnt;
    e[++ecnt] = (edge){from, head[to], 0, c}, head[to] = ecnt;
}

int vis[N], cur[N]; LL dis[N];

inline bool SPFA(int s, int t) {
    memset(dis, 0x3f, sizeof(dis)), memset(vis, 0, sizeof(vis));
    queue<int> q; q.push(t), vis[t] = 1, dis[t] = 0;
    while (!q.empty()) {
        int u = q.front(); q.pop(), vis[u] = 0;
        for (int i = head[u]; i; i = e[i].next)
            if (e[i ^ 1].w && dis[e[i].to] > dis[u] - e[i].c) {
                dis[e[i].to] = dis[u] - e[i].c;
                if (!vis[e[i].to]) q.push(e[i].to), vis[e[i].to] = 1;
            }
    }
    return dis[s] < 1e17;
}

LL ans;

int DFS(int u, int t, int f) {
    if (u == t || !f) return f;
    int res = 0; vis[u] = 1;
    for (int &i = cur[u], tmp; i; i = e[i].next)
        if (!vis[e[i].to] && e[i].w && dis[u] - e[i].c == dis[e[i].to] && 
            (tmp = DFS(e[i].to, t, min(f, e[i].w)))) {
                res += tmp, f -= tmp, e[i].w -= tmp, e[i ^ 1].w += tmp, ans += (LL)tmp * e[i].c;
                if (!f) break;
            }
    return res;
}

inline LL dinic(int s, int t) {
    while (SPFA(s, t)) memcpy(cur, head, sizeof(head)), DFS(s, t, 1e9);
    return ans;
}

int main() {
    int n, s, t; scanf("%d", &n), s = n * 2 + 5, t = s + 1;
    for (int i = 1; i <= n; i++) {
        int x, y, c; scanf("%d%d%d", &x, &y, &c);
        adde(s, i, c, 0);
        adde(i, 2 * n + 1, 1e9, -x - y), adde(i, 2 * n + 2, 1e9, x + y);
        adde(i, 2 * n + 3, 1e9, y - x), adde(i, 2 * n + 4, 1e9, x - y);
    }
    for (int i = 1; i <= n; i++) {
        int x, y, c; scanf("%d%d%d", &x, &y, &c);
        adde(i + n, t, c, 0);
        adde(2 * n + 1, i + n, 1e9, x + y), adde(2 * n + 2, i + n, 1e9, -x - y);
        adde(2 * n + 3, i + n, 1e9, x - y), adde(2 * n + 4, i + n, 1e9, y - x);
    }
    printf("%lld\n", -dinic(s, t));
    return 0;
}//

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define FOR(i,n,m) for(ll i=(n);i<(m);i++)
#define REP(i,n) FOR(i,0,n)
#define REPR(i,n) for(ll i=(n);i>=0;i--)
#define all(vec) vec.begin(),vec.end()
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using P=pair<ll,ll>;
using PP=pair<ll,P>;
using vp=vector<P>;
using vpp=vector<PP>;
using vs=vector<string>;
#define fi first
#define se second
#define pb push_back
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>bool chmin(T &a,const T &b){if(a>b){a=b;return true;}return false;}
const ll MOD=1000000007LL;
const int INF=1<<30;
const ll LINF=1LL<<60;
int main(){
    int a,b,c;
    cin>>a>>b>>c;
    if(a<=c&&c<=b){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }
    return 0;
}

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

N = int(readline())
X = list(map(int,readline().split()))

S = sorted(X)
mM = S[N // 2 - 1]
lM = S[N // 2]

for i in range(N):
  if X[i] <= mM:
    print(lM)
  else:
    print(mM)


Measured memory_bytes: 26756
// C++ implementation of the approach 
#include <bits/stdc++.h> 
using namespace std;

// Function to find special numbers 
void divisibilityCheck(int arr[], int n)
{

	// Storing all array elements in a hash 
	// and finding maximum element in the array 
	unordered_set<int> s;
	int max_ele = INT_MIN;
	for (int i = 0; i < n; i++) {
		s.insert(arr[i]);

		// Update the maximum element of the array 
		max_ele = max(max_ele, arr[i]);
	}

	// Traversing the array elements and storing the array 
	// multiples that are present in s in res 
	unordered_set<int> res;
	for (int i = 0; i < n; i++) {

		// Check for non-zero values only 
		if (arr[i] != 0) {

			// Checking the factors of current element 
			for (int j = arr[i] * 2; j <= max_ele; j += arr[i]) {

				// If current factor is already part 
				// of the array then store it 
				if (s.find(j) != s.end())
					res.insert(j);
			}
		}
	}

	// For non-distinct elmments 
	// To store the frequency of elements 
	unordered_map<int, int> mp;
	for (int i = 0; i < n; i++)
		mp[arr[i]]++;

	unordered_map<int, int>::iterator it;
	vector<int> ans;
	for (it = mp.begin(); it != mp.end(); it++) {

		// If frequency is at least 2 
		if (it->second >= 2) {
			if (res.find(it->first) == res.end()) {

				// If frequency is greater than 1 and 
				// the number is not divisible by 
				// any other number 
				int val = it->second;

				// Then we push the element number of 
				// times it is present in the vector 
				while (val--)
					ans.push_back(it->first);
			}
		}

		// If frequency is greater than 1 and the number 
		// is divisible by any other number 
		if (res.find(it->first) != res.end()) {
			int val = it->second;

			// Then we push the element number of 
			// times it is present in the vector 
			while (val--)
				ans.push_back(it->first);
		}
	}
	int cnt = 0;
	set<int>v(ans.begin(), ans.end());
	for (int i = 0; i < n; i++) {
		if (v.find(arr[i]) == v.end()) {
			cnt++;
		}
	}
	cout <<cnt<< endl;

}

// Driver code 
int main()
{
	int n;
	cin >> n;
	int *arr = new int[n];
	for (int i = 0; i < n; i++)cin >> arr[i];
	divisibilityCheck(arr, n);
	

	return 0;
}

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

using namespace std;

int main(){
  
  //freopen("input.txt","r",stdin);
  //freopen("outputu.txt","w",stdout);
  long long n,m,i,j,k,s(0);
  cin>>n;
  m=pow(2,floor(log10(n)/log10(2)))*2;
  cout<<m-1;

  
  


  
 
 
 
    
 
return 0;
}

Measured memory_bytes: 512
import itertools

N, M = map(int, input().split())
c = [[False] * N for i in range(N)]
for i in range(M):
	a, b = map(int, input().split())
	c[a - 1][b - 1] = True
	c[b - 1][a - 1] = True
ans, d = 0, [i for i in range(N)]
for i in itertools.permutations(d[1:]):
	e, f = True, list(i)
	f.insert(0, d[0])
	for j in range(N - 1):
		if not c[f[j]][f[j + 1]]:
			e = False
			break
	if e:
		ans += 1
print(ans)

Measured memory_bytes: 3064
#include <cstdio>
#include <vector>
#include <algorithm>
const int MOD = 1000000007;
int N, M, K, f[524288], g[524288];
inline void add(int &x, int y)
{
	x = x + y < MOD ? x + y : x + y - MOD;
}
void Sanho(int *f, int d)
{
	if (d == 0)
		return;
	add(f[1 << d - 1], f[0]);
	for (int i = 1; i < 1 << d - 1; i <<= 1)
		for (int j = 0; j < i; j++)
			add(f[(1 << d - 1) + j], f[i + j]);
	Sanho(f, d - 1);
	Sanho(f + (1 << d - 1), d - 1);
}
std::vector < std::pair < int, int > > lim[20];
int main()
{
	scanf("%d%d%d", &N, &M, &K);
	N--;
	while (K--)
	{
		int a, b, c;
		scanf("%d%d%d", &a, &b, &c);
		lim[a - 1].push_back({ N - b, c });
	}
	f[0] = 1;
	for (int i = 0; i < M; i++)
	{
		Sanho(f, N);
		for (int j = 0; j < 1 << N; j++)
			for (auto k : lim[i])
				if ((j >> k.first & 1) != k.second)
					f[j] = 0;
	}
	int O = 0;
	for (int i = 0; i < 1 << N; i++)
		add(O, f[i]);
	printf("%d\n", O);
	return 0;
}


Measured memory_bytes: 2304
#include<iostream>
#include<iomanip>
#include<functional>
#include<algorithm>
#include<string>
#include<vector>
#include<utility>
#include<tuple>
#include<map>
#include<set>
#include<queue>
#include<cmath>

using namespace std;
#define LL long long

LL N,ans=1;
LL GCD(LL a, LL b) {
	if (b == 0)return a;
	return GCD(b, a%b);
}

int main() {
	cin>>N;
	for(int i=0;i<N;i++){
		LL T;
		cin>>T;
		LL g=GCD(ans,T);
		ans=ans/g*T;
	}
	cout<<ans<<endl;

	return 0;
}



Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
        int n;
        cin>>n;
        int r[n];
        for(int i=0;i<n;i++) cin>>r[i];
        int min = r[0];
        int ret = r[1]-r[0];
        for(int i=1;i<n;i++){
                ret = ret>r[i]-min? ret:r[i]-min;
                min = min<r[i]? min:r[i];
        }
        cout<<ret<<endl;
        return 0;
}


Measured memory_bytes: 3872
#include <stdio.h>

int main(){
  int n,i,j,c=0,f[100],minj,x;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&f[i]);
  }
  for(i=0;i<n;i++){
    minj=i;
    for(j=i;j<n;j++){
      if(f[j]<f[minj]){
	minj=j;
      }
    }
     if(f[i]>f[minj]){
        c++;
      }
	x=f[minj];
	f[minj]=f[i];
	f[i]=x;
  }
  for(i=0;i<n-1;i++){
    printf("%d ",f[i]);
  }
  printf("%d\n",f[n-1]);
  printf("%d\n",c);
  return 0;
}



Measured memory_bytes: 2128
N,Ma,Mb=[int(x) for x in input().split()]
A=[]
B=[]
C=[]
for i in range(N):
	a,b,c=[int(x) for x in input().split()]
	A.append(a)
	B.append(b)
	C.append(c)


ANS=[[[-1 for k in range(401)] for j in range(401)] for i in range(41)]

INF=1000000000000000000000

def f(ind,wa,wb):
	global Ma
	global Mb
	global N
	if ANS[ind][wa][wb]==-1:
		if ind==0:
			if (wa+A[0])*Mb==(wb+B[0])*Ma:
				ANS[ind][wa][wb] = C[0]
			elif wa*Mb==wb*Ma and (wa!=0 and wb!=0):
				ANS[ind][wa][wb] = 0
			else:
				ANS[ind][wa][wb] = INF
		else:
			ANS[ind][wa][wb] = min(f(ind-1,wa,wb),f(ind-1,wa+A[ind],wb+B[ind])+C[ind])
	return ANS[ind][wa][wb]

ans=f(N-1,0,0)

if ans==INF:
	print(-1)
else:
	print(ans)

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

typedef struct{
  int to,cost;
}Edge;

const int N = 100;
vector<Edge> edge[N];
int f[N];
int findMax(int n,int src,int maxhp){
  for(int i=0;i<n;i++){
    f[i] = 0;
  }
  for(int i=0;i<edge[src].size();i++){
    int next = edge[src][i].to;
    f[next] = max(f[next],maxhp+edge[src][i].cost);
    f[next] = min(f[next],maxhp);
  }
  //O(VE)
  for(int loop=0;loop<n-1;loop++){
    for(int i=0;i<n;i++){
      int now = i;
      if (f[now] == 0)continue;
      for(int j=0;j<edge[i].size();j++){
	int next = edge[now][j].to;
	f[next] = max(f[next],f[now]+edge[now][j].cost);
	f[next] = min(f[next],maxhp);
      }
    }
  }
  return f[src];
}

int cost[N];
int prevCost[N];
bool haveInfLoop[N];
int solve(int n,int src,int dst,int maxhp){
  edge[dst].clear();
  for(int i=0;i<n;i++){
    int tmp = findMax(n,i,maxhp);
    haveInfLoop[i] = tmp == maxhp;
  }


  for(int i=0;i<n;i++){
    cost[i] = 0;
    prevCost[i] = 0;
  }
  cost[src] = maxhp;
  prevCost[src] = maxhp;
  for(int loop=0;loop<n;loop++){
    for(int now=0;now<n;now++){
      if (cost[now] == 0)continue;
      for(int j=0;j<edge[now].size();j++){
	int next = edge[now][j].to;
	cost[next] = max(cost[next],cost[now]+edge[now][j].cost);
	cost[next] = min(cost[next],maxhp);
      }
    }

    for(int now=0;now<n;now++){
      if (cost[now] == 0)continue;
      for(int j=0;j<edge[now].size();j++){
	int next = edge[now][j].to;
	if (min(maxhp,cost[now] + edge[now][j].to)  != cost[next]){
	  //if (findMax(n,next,maxhp) == maxhp){
	  if (haveInfLoop[next]){
	    cost[next] = maxhp;
	  }
	}
      }
    }
  end:;
  }
  return cost[dst];
}

main(){
  int n,m;
  int tc = 1;
  while(cin>>n>>m && n){
    for(int i=0;i<n;i++){
      edge[i].clear();
    }
    for(int i=0;i<m;i++){
      int f,t,w;
      cin>>f>>t>>w;
      edge[f].push_back((Edge){t,w});
    }
    int s,t,hp;
    cin>>s>>t>>hp;
    int ans = solve(n,s,t,hp);
    cout <<"Case " << tc++ << ": ";
    if (ans == 0)cout <<"GAME OVER" << endl;
    else cout << ans << endl;
  }
  return false;
}

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

int main() {
  int n, k;
  cin >> n >> k;
  
  int ans = 0;
  for (int i = 0; i < n; i++) {
	int x;
    cin >> x;
    ans += min(2 * x, 2 * abs(x - k));
  }
  
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <stdio.h>
#include <iomanip>
#include <limits>
#include <list>
#include <queue>
#include <tuple>
#include <map>
#include <set>
#include <sstream>
using namespace std;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define FOR(i,a,b) for(int i=a; i<(int)(b); i++)
#define ALL(x) (x).begin(),(x).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define SORT(c) sort(ALL(x))
#define CLR(a) memset((a), 0 ,sizeof(a))
#define PB push_back
#define MP make_pair
#define SP << " " <<
const int INF = 1001001001;
const ll LINF = 100100100100100100;
const double EPS = 1e-10;
const double PI  = acos(-1.0);
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){

    std::fill( (T*)array, (T*)(array+N), val );
}

__attribute__((constructor))
void initial(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}

bool IsPrime(ll num){
    if(num < 2) return false;
    else if(num == 2) return true;
    else if(num % 2 == 0) return false; // 偶数はあらかじめ除く

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

double dabs(double a, double b){
  if(a>b) return a-b;
  else return b-a;
}

signed main(){
  int n; cin>>n;
  VI a(n); rep(i,n) cin>>a[i]; sort(ALL(a));
  int s = a[n-1], t = a[0];
  double m = (double)s/2;
  rep(i,n){
    if(dabs((double)t,m)>dabs((double)a[i],m)) t = a[i];
  }
  cout << s SP t << endl;

  return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <fstream>
#include <cstring>
#include <string>
#include <algorithm>
#include <cmath>
#include <climits>
#include <vector>
#include <map>
#include <unordered_map>
#include <set>
#include <queue>
#include <deque>
#include <unordered_set>
#include <stack>
#include <iomanip>
using namespace std;

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

    int n, m, d[5];

    cin >> n >> m;
    for(int i=1; i<=n; i++)
        d[i] = -1;
    for(int i=0; i<m; i++) {
        int s, c;
        cin >> s >> c;
        if((d[s]!=-1 && d[s]!=c) || (n>1 && s==1 && c==0)) {
            cout << "-1\n";
            return 0;
        }
        d[s] = c;
    }
    if(n==1) {
        cout << max(d[1], 0) << "\n";
        return 0;
    }

    cout << max(d[1], 1);
    for(int i=2; i<=n; i++)
        cout << max(d[i], 0);
    cout << "\n";

    return 0;
}

Measured memory_bytes: 256
import bisect,copy,heapq,string
from collections import *
from math import *
from itertools import *
import sys
def input() : return sys.stdin.readline().strip()
def INT()   : return int(input())
def MAP()   : return map(int,input().split())
def LIST()  : return list(MAP())

n = INT()
a = LIST()

x = a[0]
for y in a:
        x = gcd(x, y)
print(x)

Measured memory_bytes: 21744
#include<bits/stdc++.h>
using namespace std;
long long n,a[100005],dp[100005];
int main(){
    cin >> n;
    for(int i=1;i<=n;i++){ cin>>a[i]; }
	memset(dp,0x7f7f7f,sizeof(dp)); dp[1]=0;
    for(int i=2;i<=n;i++){ 
		dp[i]=min(min(abs(a[i-1]-a[i]) + dp[i-1], abs(a[i-2]-a[i]) + dp[i-2]),dp[i]);
	}
    cout<<dp[n]<<'\n';
}   

Measured memory_bytes: 5160
#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() {
   int n;
   cin>>n;
   vector<int> a(1000000,0);
   rep(i,n){
      int x;
      cin>>x;
      a[x]++;
   }
   
   ll ans=0;
   rep(i,100000){
      ll kari=a[i]+a[i+1]+a[i+2];
      ans=max(ans,kari);
   }
   cout<<ans<<endl;
}




Measured memory_bytes: 7192
<?php
//その都度計算しているとTLEになるので、最初に$max値で計算
//

$max = 1000000;

// 配列の初期化。素数には１が入る。ここがポイント。
for ($i = 0; $i < $max; $i++) {
    $array[$i] = 1;
}
$array[1] = 0;

// ふるい。０と１は素数では無いので２から探索開始
for ($i=2; $i<$max; $i++) {
  if ( $array[$i]===0 )
    // スタート値がふるい落とされていたら、その倍数も既出
    continue;
  else
  // $i自身は素数なので、その2倍から探索開始
  for ($j=$i*2; $j<$max; $j+=$i) {
    $array[$j] = 0;
  }
}

// 各整数に素数の数を格納。ポイント。
for ($i=2; $i<$max; $i++){
  $array[$i] += $array[$i-1];	//素数ならば１が入っているのでカウンターとして使う。
}

while(1){
  $res = fscanf(STDIN, '%d', $n);
  if ($res==0) break;
  
  $cnt = $array[$n];
  
  // 出力
  echo $cnt.PHP_EOL;
}

Measured memory_bytes: 147520
#include <iostream>
#include <cstdio>
using namespace std;
typedef long long ll;
int n;
ll p=1,s;
int main(void){
    scanf("%d%lld",&n,&s);
    s--;
    for(int i=0;i<n-1;i++){
        ll a;
        scanf("%lld",&a);
        if(a==p+1)p=a;
        else s+=(a-1)/(p+1);
    }
    printf("%lld\n",s);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ALL(a)  (a).begin(),(a).end()
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<long long, long long> Pll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<long long> vll;
typedef vector<vector<long long>> vvll;
template <typename T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template <typename T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;
const int INT_INF = 1LL << 30;

int main(){
  ll N;
  cin >> N;
  vll a(N);
  for(int i = 0; i < N; i++){
    cin >> a.at(i);
  }
  ll ans = INF;
  for(int i = -100; i <= 100; i++){
    ll sum = 0;
    for(int j = 0; j < N; j++){
      sum += (a.at(j) - i) * (a.at(j) - i);
    }
    chmin(ans, sum);
  }
  cout << ans << endl;
}

Measured memory_bytes: 256