akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>
#include <iomanip>
#include <numeric>
#include <unordered_map>
#include <sstream>
#include<limits.h>
#include<float.h>
#include<list>
#include <array>
#include <complex>
#include<stdio.h>
#include<string.h>
#include <bitset>
// #include<assert.h>
#include<random>
using namespace std;
#define int long long

#define I32_MAX 2147483647
#define I64_MAX 9223372036854775807LL
#define I64_MAX2 1223372036854775807LL
#define INF I64_MAX2
#define MOD 1000000007
// #define MOD 998244353 
#define MEM_SIZE 10000
#define DEBUG_OUT true
#define ALL(x) (x).begin(), (x).end()

template<typename T> void DEBUG(T e){if(DEBUG_OUT == false)return; std::cout << e <<" ";}
template<typename T> void DEBUG(const std::vector<T>& v){if(DEBUG_OUT == false)return;for(const auto& e : v){std::cout<< e << " "; } std::cout << std::endl;}
template<typename T> void DEBUG(const std::vector<std::vector<T> >& vv){if(DEBUG_OUT == false)return;for(const auto& v : vv){ DEBUG(v); } }
template<class T,class... Ts> void DEBUG(T d, Ts... e){if(DEBUG_OUT == false)return;DEBUG(d);DEBUG(e...);}
template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; abort();}}
template< typename T1, typename T2 > inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template< typename T1, typename T2 > inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

void solve(void)
{ 
  int N; cin>>N;
  vector<int> vec (N,0);
  for (int i = 0; i < N; i++)
  {
     cin>>vec[i];
  }
  if(N == 1)
  {
    cout<<vec[0]/2<<endl;
    return;
  }
  int res = 0;
  for (int i = 1; i < N; i++)
  {
    res += (vec[i-1] + vec[i])/2;
    vec[i] = ((vec[i-1] + vec[i])%2 &&(vec[i] != 0));
  }
  cout<<res<<endl;
  
  return;
}
int32_t main(int32_t argc, const char *argv[])
{
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);

  std::cout << std::fixed;
  std::cout << std::setprecision(11);
  solve();

  return 0;
}


Measured memory_bytes: 3960
#include <stdio.h>
int main(){
    
	int n,x;
    
	int i,j,k,m=0;
    
	int d[100][100][100];
    
    
    
	while(1){
        
		scanf("%d %d",&n,&x);
        
		if(n==0 && x==0) break;
        
		for(i=0;i<n-2;i++){
            
			for(j=i+1;j<n-1;j++){
                    
				for(k=j+1;k<n;k++){
                        
					//printf("%d %d %d\n",i,j,k);
                        
					if((i+j+k+3)==x){
                            
						m++;
                        
					}        
                    
				}
            
			}
        
		}
        printf("%d\n",m);
        m=0;
	}  
    
	return 0;
    
}



Measured memory_bytes: 2092
#include<bits/stdc++.h>
using namespace std;
template <typename T>
inline void readin(T &x) {
	x = 0;
	T fh = 1;
	char ch = getchar();
	for (; !isdigit(ch); ch = getchar()) if (ch == '-') fh = -1;
	for (; isdigit(ch); ch = getchar()) x = (x << 1) + (x << 3) + (ch ^ 48);
	x *= fh;
}
inline void d_read(double &x) {
	x = 0.0;
	int fh = 1;
	char ch = getchar();
	for (; !isdigit(ch); ch = getchar()) if (ch == '-') fh = -1;
	for (; isdigit(ch); ch = getchar()) x = x * 10 + (ch ^ 48);
	if (ch == '.') {
		double num = 1.0;
		ch = getchar();
		for (; isdigit(ch); ch = getchar()) x = x + (num /= 10) * (ch ^ 48);
	}
	x *= fh;
}

template <typename T>
inline void wt(T x) {
	if (x > 9) wt(x / 10);
	putchar(x % 10 + 48);
}
template <typename T>
inline void writeln(T x, char c) {
	if (x < 0) {
		putchar('-');
		x = -x;
	}
	wt(x);
	putchar(c);
}
int a[100005]; 
int main() {
	int n;
	readin(n);
	for (int i = 1; i <= n; i ++) {
		readin(a[i]);
	}
	int ans = 0;
	for (int i = 1; i <= n; i += 2) {
		if (a[i] % 2 == 1) {
			ans ++;
		}
	}
	writeln(ans, '\n');
	return 0;
}




Measured memory_bytes: 3628
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) {
		BufferedReader input = new BufferedReader(new InputStreamReader(System.in));

		try {
			String str = input.readLine();

			str = str.replace("peach", "temp");
			str = str.replace("apple", "peach");
			str = str.replace("temp", "apple");
			
			System.out.println(str);
		} catch (IOException e) {
			// TODO ????????????????????? catch ????????????
			System.out.println("halll");
		}

	}

}

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

typedef long long ll;

vector<ll> divisors(ll n) {
    vector<ll> res;
    for(ll i = 1; i*i <= n; ++i) {
        if(n % i != 0) continue;
        res.push_back(i);
        if(n/i == i) continue; // 上の行で追加済み。
        res.push_back(n/i);
    }
    return res;
}

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

int main() {
  ll a, b;
  cin >> a >> b;
  vector<ll> x = divisors(a), y = divisors(b);
  map<ll, ll> m;
  for (ll i = 0; i < x.size(); i++) {
    m[x[i]]++;
  }
  for (ll i = 0; i < y.size(); i++) {
    m[y[i]]++;
  }
  vector<ll> l;
  for (auto i = m.begin(); i != m.end(); i++) {
    if (i->second == 2) {
      l.push_back(i->first);
    }
  }
  sort(l.begin(), l.end());
  ll n = l.size();
  ll ans = 0;
  vector<ll> p(n, 1);
  for (ll i = 0; i < n; i++) {
    if (p[i] == 0) {
      continue;
    }
    ans++;
    for (ll j = i + 1; j < n; j++) {
      if (gcd(l[i], l[j]) != 1) {
        p[j] = 0;
      }
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 896
def canCommunicate(arr)
  if (arr[0] - arr[2]).abs <= arr[3]
    return "Yes"
  end
  if (arr[0] - arr[1]).abs > arr[3]
    return "No"
  end
  if (arr[1] - arr[2]).abs > arr[3]
    return "No"
  end
  return "Yes"
end

arr = gets.chomp.split().map!(&:to_i)
puts canCommunicate(arr)

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

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

    int ans = 0;
    int prev;
    for (int i = 0; i < n; i++) {
        ans += b[a[i]];
        if (i > 0 && a[i] == prev + 1) ans += c[prev];
        prev = a[i];
    }

    cout << ans << endl;
}


Measured memory_bytes: 256
use std::vec::Vec;

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().split_whitespace()
        .map(|e| e.parse().ok().unwrap()).collect()
}

fn main() {
    let v: Vec<i32> = read_vec();
    let a = v[0];
    let b = v[1];
    let t = v[2];
    println!("{}", (t / a) * b)
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
#define all(x) x.begin(),x.end()
#define rep(i,j,n) for (int i = j; i < (int)(n); i++)
#define _GLIBCXX_DEBUG
#define MOD 1000000007
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; }
//name[i][j]-> vvl name(i,vl(j))
//map<int,int>mp
//余りを切り上げる =>  (a + b - 1) / b 

signed main(){
	int n,m; cin>>n>>m;
	vvi vec(m);
	rep(i,0,m){
		int k; cin>>k;
		vec[i].resize(k);
		rep(j,0,k){
			int s; cin>>s;
			--s;
			vec[i][j]=s;
		}
	}
	ll ans=0;
	vi p(m);
	rep(i,0,m) cin>>p[i];
	rep(i,0,(1<<n)){
		bool ok=true;
		rep(j,0,m){
			int cnt=0;
			for(int c:vec[j]){
				if(!(i>>(c) & 1)) continue;
				++cnt;
			}
			if(cnt%2!=p[j]){
				ok=false;
				//break;
			}
		}
		if(ok) ans++;
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep_(i, n, m) for (int i = n; i < (int)(m); i++)
#define all(v) v.begin(), v.end()
#define int long long
#define stoi stoll
//#define _GLIBCXX_DEBUG

signed main() {
  int N; cin >> N;
  map<int,int> m;
  int ans = 0;
  rep(i, N) {
    int a; cin >> a;
    m[a]++;
    ans += a;
  }
  
  int Q; cin >> Q;
  rep(i, Q) {
    int b, c; cin >> b >> c;
    ans -= m[b]*b;
    ans += m[b]*c;
    m[c] += m[b];
    m[b] = 0;
    cout << ans << endl;
  }
  
  
  

}

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

#ifdef ONLINE_JUDGE
#define freopen \
  if (0) freopen
#define cerr \
  if (0) cerr
#endif

#define fi first
#define se second

#define pb push_back
#define pp pop_back
#define mp make_pair

#define rep(i, a, b) for (int i = (a); i <= (b); i++)
#define per(i, a, b) for (int i = (a); i >= (b); i--)

#define sqr(a) ((a)*1ll * (a))
#define sz(a) (int)a.size()
#define len(a) (int)a.length()
#define all(a) a.begin(), a.end()
#define nl '\n'

using namespace std;

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

typedef vector<int> vi;
typedef vector<vector<int> > vvi;
typedef pair<int, int> pi;

const int inf = (int)1e9 + 7;
const int mod = (int)1e9 + 7;
const ll linf = (ll)1e18 + 7;

int n, a, x[55];
ll dp[55][55][2555], res;

void solve() {
  cin >> n >> a;
  rep(i, 1, n) cin >> x[i];

  dp[0][0][0] = 1;
  rep(i, 1, n) {
    rep(j, 0, i) {
      rep(sum, 0, 3000) {
        dp[i][j][sum] = dp[i - 1][j][sum];
        if (j - 1 >= 0 && sum - x[i] >= 0)
          dp[i][j][sum] += dp[i - 1][j - 1][sum - x[i]];
      }
    }
  }

  rep(i, 1, n) {
    res += dp[n][i][a * i];
  }
  cout << res;
}

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

  freopen(".in", "r", stdin);

  solve();

  return 0;
}


Measured memory_bytes: 30404
import sys


def input():
    return sys.stdin.readline()[:-1]


def ii(t: type = int):
    return t(input())


def il(t: type = int):
    return list(map(t, input().split()))


def imi(N: int, t: type = int):
    return [ii(t) for _ in range(N)]


def iml(N: int, t: type = int):
    return [il(t) for _ in range(N)]


A, B, C, X, Y = il()
m = A * X + B * Y
for i in range(2, 2 * max(X, Y) + 1, 2):
    tmp = A * max(X - i // 2, 0) + B * max(Y - i // 2, 0) + C * i
    if tmp < m:
        m = tmp
print(m)


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


public class Main {

	final static long MOD = 1000000007;
	public static String[] Ws = null;
	public static int wsIndx = 0;
	public static BufferedReader in = null;
	public static long cnt=0;
	public static PrintWriter pw = new PrintWriter(System.out);
	public static void main(String[] args) throws Exception {
//		solveA(args);
		solveB(args);
//		solveC(args);
//		solveD(args);
//		solveE(args);
		if(in!=null){
			in.close();
		}
		pw.flush();
		pw.close();
	}

	public static void solveA(String[] args) throws Exception{
		String a = nextString();
		if('a'<= a.charAt(0) && a.charAt(0) <='z') {
			pw.println("a");

		}else {
			pw.println("A");
		}
	}
	public static void solveB(String[] args) throws Exception{
		int N=nextInt();
		int K=nextInt();

		int[] p = nextInts();
		Arrays.sort(p);
		int ans = 0;
		for(int i=0;i<K;i++) {
			ans+=p[i];
		}
		pw.println(ans);
	}
	public static void solveC(String[] args) throws Exception{

	}
	public static void solveD(String[] args) throws Exception{

	}
	public static void solveE(String[] args) throws Exception{

	}


	public static void check() throws Exception{
		if(in == null){
			in = new BufferedReader(new InputStreamReader(System.in));
		}
		if(Ws==null || Ws.length<=wsIndx){
			Ws = in.readLine().split(" ");
			wsIndx=0;
		}
	}
	public static int nextInt()throws Exception{
		check();
		return Integer.parseInt(Ws[wsIndx++]);
	}

	public static long nextLong()throws Exception{
		check();
		return Long.parseLong(Ws[wsIndx++]);
	}

	public static String nextString()throws Exception{
		check();
		return Ws[wsIndx++];
	}

	public static int[] nextInts()throws Exception{
		check();
		int[] tmp = new int[Ws.length];
		for(int i=0;i<tmp.length;i++){
			tmp[i]=Integer.parseInt(Ws[i]);
		}
		wsIndx=Ws.length;
		return tmp;
	}

	public static long[] nextLongs()throws Exception{
		check();
		long[] tmp = new long[Ws.length];
		for(int i=0;i<tmp.length;i++){
			tmp[i]=Long.parseLong(Ws[i]);
		}
		wsIndx=Ws.length;
		return tmp;
	}

	public static String[] nextStrings()throws Exception{
		check();
		wsIndx=Ws.length;
		return Ws;
	}

}



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

using namespace std;

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

int main() {
	ios::sync_with_stdio(false);
	string T;
	cin >> T;
	for (int i = 0; i < T.size(); i++) {
		cout << (T[i] == '?' ? 'D' : T[i]);
	}
	cout << endl;
}

Measured memory_bytes: 3788
#include <algorithm>
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <string>
#include <stack>
#include <sstream>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <cmath>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)

using namespace std;
typedef long long int ll;

int main(){
	int n,x;
	cin>>n>>x;
	int sum = 0;
	vector<int> m(n);
	int miniDonuts = 1000;
	for(int i = 0;i < n; i++){
		cin>>m[i];
		sum += m[i];
		miniDonuts = min(m[i],miniDonuts);
	}
	x = x - sum;
	cout<< (x / miniDonuts) + n<<endl;
	return 0;
}


Measured memory_bytes: 3164
#include<bits/stdc++.h>
using namespace std;
using ull=unsigned long long;
#define mod 1000000007
#define mod2 998244353 
#define PI 3.14159265
#define ll long long
#define ld long double
#define pi pair<ll,ll>
#define pb push_back
#define vi vector<ll>
#define sz size()
#define setbits(x)  __builtin_popcount(x)
#define fi first
#define se second
#define lz length()
#define all(x) (x).begin(),(x).end()
#define scf(x) scanf("%lld",&x)
#define rep(i,n) for(ll i=0;i<n;i++)
const int INF = (int)1e9;
const ll IINF=1LL<<62;
const int maxn=10000005;

//int divr[maxn];
/**/
/*void divisor()
{for(int i=2;i<sqrt(maxn);i++)
     {
          if(!divr[i])
          {
               for(int j=i*i;j<maxn;j+=i)if(!divr[j])divr[j]=i;     
          }
     }
     for(int i=1;i<maxn;i++)if(!divr[i])divr[i]=i;
}*/
 
/*const int N=1000005;
ll n;
struct line {
    long long m, c;
    long long eval(long long x) { return m * x + c; }
    long double intersectX(line l) { return (long double) (c - l.c) / (l.m - m); }
};
vector<pair<pi,ll>> rect;
deque<line> dq;
*/
ll modexpo(ll a,ll b)
{
     ll res=1LL;
     while(b>0)
     {
          if(b&1)res=(res*a)%mod;
          a=(a*a)%mod;
          b>>=1;
     }
     return res;
}
 
 
 
 
 
 
 




vector<pair<int,int>> adj[100005];
ll dist[100005];
int n;
void dfs(int node,int par){
     for(auto ch:adj[node]){
          if(ch.fi==par)continue;
          dist[ch.fi]=dist[node]+ch.se;
          dfs(ch.fi,node);
     }
}




int main()
{
    int n,k;
    cin>>n>>k;
    int a[n];
    for(int i=0;i<n;i++)cin>>a[i];
    ll res=0;
    for(int i=-1;i<=n;i++){
         for(int j=i+1;j<=n;j++){
              if(i+1+n-j>k)continue;
              int z=k-(i+1+n-j);
              ll sum=0;
              vector<int> tmp;
              for(int k=0;k<=i;k++){sum+=a[k];
              if(a[k]<0)
              tmp.push_back(a[k]);}
              for(int k=j;k<n;k++){sum+=a[k];
              if(a[k]<0)tmp.push_back(a[k]);}
              sort(tmp.rbegin(),tmp.rend());
              while(!tmp.empty()&&z>0){
                   sum+=abs(tmp.back());tmp.pop_back();
                   z--;
              }
              //cout<<sum<<"\n";
              res=max(res,sum);
         }
    }
    cout<<res;

}



































Measured memory_bytes: 5956
def selectionSort(a, n):
  count = 0
  for i in range(0, n):
    minj = i
    for j in range(i, n):
      if a[j] < a[minj]:
        minj = j
    if i != minj:
      w = a[i]
      a[i] = a[minj]
      a[minj] = w
      count += 1
  print(' '.join(map(str, a)))
  print(count)

n = int(input())
a = list(map(int, input().split()))
selectionSort(a, n)


Measured memory_bytes: 5600
// Author : Mohamed Sameh
#include <bits/stdc++.h>
typedef long long ll ;
#define pb push_back
#define f first
#define s second
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define SZ(a) (int)a.size()
#define Flush fflush(stdout);
using namespace std ;
int n , m;
int a[100000];
int main ()
{
    scanf ("%d%d" , &n ,&m);
    priority_queue<int> pq ;
    for (int i =0 ; i < n ;i++)
    {
        int  v ;scanf ("%d" , &v ); pq.push(v);
    }
    while (m)
    {
        int cur = pq.top();
        pq.pop();
        cur/=2;
        m--;
        pq.push(cur);
    }
    ll ans =0 ;
    while (!pq.empty())
    {
        ans += pq.top();pq.pop();
    }
    cout << ans <<"\n";


}


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

int main(){
	long long n,W;
	cin>>n>>W;
	vector<long long> value(n+1,0),weight(n+1,0);
	for(long long i=0;i<n;i++){
		cin>>weight[i]>>value[i];
	}
	vector<vector<long long>> dp(n+1,vector<long long>(W+1,0)); //max value till index n with bag capacity of w
	for(long long indx=0;indx<=n;indx++){
		for(long long capacity=0;capacity<=W;capacity++){
			if(indx==0 or capacity==0)
				dp[indx][capacity]=0;
			else if(capacity>=weight[indx-1])
				dp[indx][capacity]=max(dp[indx-1][capacity],
									dp[indx-1][capacity-weight[indx-1]]+value[indx-1]);
			else
				dp[indx][capacity]=dp[indx-1][capacity];
		}
	}
	cout<<dp[n][W]<<endl;
	return 0;
}

Measured memory_bytes: 80256
# coding: utf-8
# Your code here!

import sys
sys.setrecursionlimit(10**6)
readline = sys.stdin.readline 



#n = int(input())
#n,m = [int(i) for i in input().split()]
#ab = [[int(i) for i in input().split()] for _ in range(n-1)]


a = ["SUN","MON","TUE","WED","THU","FRI","SAT"]

d = {c:i for i,c in enumerate(a)}

s = input()

n = d[s]

print((-n)%7+(0 if n else 7))


Measured memory_bytes: 2940
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int N = Integer.parseInt(scan.next());
		int[] x = new int[N];
		int[] y = new int[N];
		long[] h = new long[N];
		for (int i = 0; i < N; i++) {
			x[i] = Integer.parseInt(scan.next());
			y[i] = Integer.parseInt(scan.next());
			h[i] = Integer.parseInt(scan.next());
		}
		int Cx = -1;
		int Cy = -1;
		long candidateH = 0;
		boolean find = true;
		int candidateIndex = 0;
		while (h[candidateIndex] == 0) {
			candidateIndex++;
		}

		for (int i = 0; i <= 100; i++) {
			Cx = i;
			for (int j = 0; j <= 100; j++) {
				Cy = j;
				find = true;
				candidateH = h[candidateIndex] + Math.abs(Cx - x[candidateIndex]) + Math.abs(Cy - y[candidateIndex]);
				for (int k = 0; k < N; k++) {
					if (h[k] != Math.max(candidateH - Math.abs(Cx - x[k]) - Math.abs(Cy - y[k]), 0)) {
						find = false;
						break;
					}
				}
				if (find) {
					System.out.println(Cx + " " + Cy + " " + candidateH);
					return;
				}
			}
		}
	}
}


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

int main(){

    char s[3+1];

    scanf("%s", s);

    if(strcmp(s,"AAA") == 0 || strcmp(s,"BBB") == 0){
        printf("No\n");
    }
    else{
        printf("Yes\n");
    }

    return 0;
}
        



Measured memory_bytes: 128
//naveen mall
#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pb               push_back
#define sz(c)            (int)c.size()
#define len(c)           (int)c.length()
#define vec              vector
#define int              long long int
#define all(c)           c.begin(), c.end()
#define rall(c)          c.rbegin(), c.rend()
#define trav(a,i)        for(auto& i: a)
#define fl(i,a,b) for(int i = (int)(a); i <= (int)(b); i++)
#define rfl(i,a,b) for(int i = (int)(a); i >= (int)(b); i--)
#define invect(v,n)       for(int i=0;i<n;i++ ){int arb;cin>>arb;v.pb(arb);}
#define inset(s,n)        forloop(n){int aset;cin>>aset;s.insert(aset);}
#define display(c)        trav(c,i) cout<<i<<" ";cout<<"\n";
#define F                 first
#define S                 second
#define pii               pair<int,int>
#define PB                pop_back
#define endl              "\n"
#define copy(a,b)         copy(all(a),back_inserter(b));
#define section(a,b,w)    set_intersection(a.begin(), a.end(),b.begin(), b.end(),back_inserter(w));
#define union(a,b,w)      set_union(a.begin(), a.end(),b.begin(), b.end(),back_inserter(w));
#define diff(a,b,w)       set_difference(a.begin(), a.end(),b.begin(), b.end(),back_inserter(w));
#define symdiff(a,b,w)    set_symmetric_difference(a.begin(), a.end(),b.begin(), b.end(),back_inserter(w));

const long long INF64 = 1e18;





void solve()
 { 

int n;
cin>>n;
vec<int> v;
invect(v,n)
int dp[n];
for(int i=0;i<n;i++)
	  dp[i]=INF64;
dp[0]=0;
dp[1]=abs(v[1]-v[0]);
for(int i=2;i<n;i++)
   {
   	dp[i]=min(dp[i-1]+abs(v[i]-v[i-1]),dp[i-2]+abs(v[i]-v[i-2]));
   }
cout<<dp[n-1];


  }



  








 



signed main()
{fast
	int t;
   //cin>>t;
	t=1;

	while(t--)
		 {
		 	solve();
		 }
}












Measured memory_bytes: 1908
from collections import Counter

s = input()

a = list(Counter(s).keys())   

ans = [0] * len(a)
for i in range(len(a)):
    c = 0
    for j in range(len(s)):
        if s[j] != a[i]:
            c += 1
        else:
            ans[i] = max(ans[i], c)
            c = 0
        if j == len(s)-1:
            ans[i] = max(ans[i], c)
            
print(min(ans))

Measured memory_bytes: 3700
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<climits>
#include<string>
#include<vector>
#include<map>
#include<queue>
#include<set>
#include<algorithm>

#define ll long long
#define sz 105

using namespace std;

int main()
{
    char str1[sz],str2[sz],str3[sz];

    scanf("%s %s %s",str1,str2,str3);

    char ch1=toupper(str1[0]);
    char ch2=toupper(str2[0]);
    char ch3=toupper(str3[0]);

    printf("%c%c%c\n",ch1,ch2,ch3);

    return (0);
}


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

signed main() {
    int n, p[50], sp[50], ans;
    string s;
    
    cin >> n;
    for ( int i = 0; i < n; i++ ) {
        cin >> p[i];
        sp[i] = p[i];
    }
    s = "NO\n";
    sort(sp, sp + n);
    
    for ( int i = 0; i < n; i++ ) {
        for ( int j = i; j < n; j++ ) {
            swap(p[i], p[j]);
            ans = 0;
            
            for ( int k = 0; k < n; k++ ) {
                if ( sp[k] == p[k] ) {
                    ans++;
                }
            }
            
            if ( ans == n ) {
                s = "YES\n";
            }  
            
            swap(p[i], p[j]);
        }
    }
    
    cout << s;
    return (0);
}

Measured memory_bytes: 3500
#include <stdio.h>
#include <vector>
#include <iostream>
#include <queue>
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<vs> vvs;

typedef vector<pair<int, int>> vpi;
typedef vector<tuple<int, int, int>> vti;


int main() {
    ios::sync_with_stdio(0); cin.tie(0);
    ll n, m, i;
    cin >> n >> m;
    priority_queue<int> a;
    for (i=0;i<n;i++) {
        int t;
        cin >> t;
        a.push(t);
    }
    
    for (i=0;i<m;i++){
        a.push(a.top() / 2);
        a.pop();
    }

    ll sum=0;
    while (a.size()) {
        sum += a.top();
        a.pop();
    }
    cout << sum << endl;
}


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

using namespace std;

struct pos {
    int x;
    int y;
};

const vector<pos> moves = {{0,  1},
                           {0,  -1},
                           {1,  0},
                           {-1, 0}};

void dfs(pos now, vector<vector<int>> &ban) {
    ban[now.x][now.y] = 1;
    for (auto move:moves) {
        pos next = {now.x + move.x, now.y + move.y};
        if (0 <= next.x && next.x < ban.size() - 1 && 0 <= next.y && next.y < ban[next.x].size() - 1) {
            if (ban[next.x][next.y] == 0) dfs(next, ban);
        }
    }
}

int main() {
    while (true) {
        int w, h;
        cin >> w >> h;
        if (w == 0 && h == 0)break;
        int n;
        cin >> n;

        set<int> tate;
        tate.insert(0);
        tate.insert(h);
        set<int> yoko;
        yoko.insert(0);
        yoko.insert(w);
        vector<vector<int>> tapes(n, vector<int>(4));
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < 4; j++) {
                cin >> tapes[i][j];
                (j % 2 == 0 ? yoko : tate).insert(tapes[i][j]);
            }
        }
        vector<int> tatev(tate.begin(), tate.end());
        vector<int> yokov(yoko.begin(), yoko.end());

        vector<vector<int>> c_sum(tatev.size(), vector<int>(yokov.size()));
        for (int i = 0; i < n; i++) {
            pos start;
            start.y = lower_bound(yokov.begin(), yokov.end(), tapes[i][0]) - yokov.begin();
            start.x = lower_bound(tatev.begin(), tatev.end(), tapes[i][1]) - tatev.begin();

            pos end;
            end.y = lower_bound(yokov.begin(), yokov.end(), tapes[i][2]) - yokov.begin();
            end.x = lower_bound(tatev.begin(), tatev.end(), tapes[i][3]) - tatev.begin();

            c_sum[start.x][start.y]++;
            c_sum[start.x][end.y]--;
            c_sum[end.x][start.y]--;
            c_sum[end.x][end.y]++;
        }

        for (int i = 0; i < tatev.size(); i++) {
            for (int j = 0; j < yokov.size(); j++) {
                if (i > 0)c_sum[i][j] += c_sum[i - 1][j];
                if (j > 0)c_sum[i][j] += c_sum[i][j - 1];
                if (i > 0 && j > 0)c_sum[i][j] -= c_sum[i - 1][j - 1];
            }
        }

        int ret = 0;
        for (int i = 0; i < tatev.size() - 1; i++) {
            for (int j = 0; j < yokov.size() - 1; j++) {
                if (c_sum[i][j] == 0) {
                    ret++;
                    dfs({i, j}, c_sum);
                }
            }
        }
        cout << ret << endl;
    }
    return 0;
}


Measured memory_bytes: 8032
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
#include <unordered_map>
#define stop(x) {cout<<x<<endl;exit(0);}
#define all(x) x.begin(),x.end()
#define szz(s) int(s.size())
#define endl '\n'
int dx[] = { 0, 0, 1, -1, 1, -1, 1, -1 };
int dy[] = { 1, -1, 0, 0, -1, 1, 1, -1 };
typedef long long ll;
using namespace std;

void file() {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
    if (freopen("input.txt", "r", stdin));
    if (freopen("output.txt", "w", stdout));
#endif
}



int main() {
    //file();

    ll n, m;
    cin >> n >> m;
    vector < ll > v(n);

    for (auto& e : v)cin >> e;

    vector < ll > dp(n + 1, 1e11);

    dp[0] = 0;

    for (int i = 0; i < n; i++) {
        for (int k = i + 1; k < min(i + m +1, n); k++) {
            dp[k] = min(dp[k], dp[i] + abs(v[i] - v[k]));
        }
    }

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

        
}

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

int main(){
	int a,b,c,d;
	cin>>a>>b>>c;
  	d=max(a,b);
  	d=max(d,c);
  	int ans=a+b+c-d;
  	int k;
  	cin>>k;
  	for(int i=0;i<k;++i){
      	d=2*d;
    }ans+=d;
  cout<<ans<<endl;
  	return 0;
}

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

int main(){
  int n,z[100];
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>z[i];
  }
  sort(z,z+n);
  double ans=z[0];
  for(int i=1;i<n;i++){
    ans=(ans+z[i])/2;
  }
  cout<<ans<<endl;
  
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
  int x = 0;
  int y = 0;
  cin >> x >> y;
  if(y < 2 * x){
    cout << "No" << endl;
  }
  else{
    int b = y - x * 2;
    if(b % 2 == 0){
      if(b / 2 <= x){
        cout << "Yes" << endl;
      }
      else{
        cout << "No" << endl;
      }
    }
    else{
      cout << "No" << endl;
    }
  }
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
int main(){
  int a,b;
  int ans;
  cin >> a >> b;
  if(a>b){
    ans = a*2-1;
  }
  else if( a==b){
    ans = a+b;
  }
  else{
    ans = b*2 -1;
  }
  cout << ans << endl;
}

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

class Main {
	public static void main(String args[]) {
    	Scanner s = new Scanner(System.in);
        int n = s.nextInt();
        int[] a = new int[n];
        int i = 0;
        while( i < n) {
            a[i] = s.nextInt();
            i++;
        }
        i = 0;
        int ans = 0;
        int prev = 0;
        while( i < n) {

            while(i+1 < n && a[i+1] >= a[i]) {
                i++;
            }
            ans += a[i] - prev;
            while(i+1 < n && a[i+1] < a[i]) {
                i++;
            }
            prev = a[i];
            if(i+1 == n) break;
        }
        System.out.println(ans);
    }
}

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

using namespace std;

using ll = long long;
using ld = long double;
using D = double;
using uint = unsigned int;

#ifdef WIN32
    #define LLD "%I64d"
#else
    #define LLD "%lld"
#endif

#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second

#define popcount(x) __builtin_popcount(x)

const int maxn = 16;
const int maxmask = 1 << 16;
const ld inf = 1e18;

int x[maxn], y[maxn], a[maxn];
ld ans[maxmask], answer[maxmask];
ld d[maxn][maxn];
ld mindist[maxmask][maxn];
int n;

inline ld shedge(int m1, int m2)
{
    ld answer = inf;
    for (int j = 0; j < n; j++) if (m1 & (1 << j)) answer = min(answer, mindist[m2][j]);
    return answer;
}

int main()
{
    scanf("%d", &n);
    for (int i = 0; i < n; i++)
    {
        scanf("%d%d%d", &x[i], &y[i], &a[i]);
    }
    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < n; j++) d[i][j] = sqrt((ld)(x[i] - x[j]) * (x[i] - x[j]) + (ld)(y[i] - y[j]) * (y[i] - y[j]));
    }
    int km = 1 << n;
    for (int mask = 0; mask < km; mask++)
    {
        for (int i = 0; i < n; i++)
        {
            mindist[mask][i] = inf;
            for (int j = 0; j < n; j++) if (mask & (1 << j)) mindist[mask][i] = min(mindist[mask][i], d[i][j]);
        }
    }
    for (int i = 0; i < n; i++) ans[1 << i] = a[i];
    for (int mask = 1; mask < km; mask++) if (popcount(mask) > 1)
    {
        ans[mask] = -inf;
//         for (int i = 0; i < n; i++) if (mask & (1 << i))
//         {
//             ld d = mindist[mask ^ (1 << i)][i];
//             /*if (a[i] > d || ans[mask ^ (1 << i)] / (popcount(mask) - 1) > d)*/ ans[mask] = max(ans[mask], ans[mask ^ (1 << i)] + a[i] - d);
//         }
        for (int submask = (mask & (mask - 1)); submask > 0; submask = ((submask - 1) & mask))
        {
            ld d = shedge(submask, mask ^ submask);
            ans[mask] = max(ans[mask], ans[submask] + ans[mask ^ submask] - d);
        }
//         cout << mask << ' ' << ans[mask] << endl;
    }
//     cout.precision(20);
//     cout << ans[km - 1] / n << endl;
    for (int i = 0; i < n; i++) answer[1 << i] = a[i];
    for (int mask = 1; mask < km; mask++) if (popcount(mask) > 1)
    {
        answer[mask] = ans[mask] / popcount(mask);
        for (int submask = (mask & (mask - 1)); submask > 0; submask = ((submask - 1) & mask))
        {
            answer[mask] = max(answer[mask], min(answer[submask], answer[mask ^ submask]));
        }
    }
    cout.precision(20);
    cout << answer[km - 1] << endl;
    return 0;
}

Measured memory_bytes: 9472
//Love and Freedom.
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<cstring>
#define ll long long
#define inf 20021225
using namespace std;
int n; 
int main()
{
	scanf("%d",&n);
	printf("%d\n",n*(n-1)/2-n/2);
	if(n&1)
	{
		for(int i=1;i<=n;i++)
			for(int j=i+1;j<=n;j++)
			{
				if(i+j==n)	continue;
				printf("%d %d\n",i,j);
			}
	}
	else
	{
		for(int i=1;i<=n;i++)
			for(int j=i+1;j<=n;j++)
			{
				if(i+j==n+1)	continue;
				printf("%d %d\n",i,j);
			}
	}
	return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int min(int a, int b)
{
    return a < b? a: b;
}
int main(void)
{
    int n, y;
    scanf("%d%d", &n, &y);
    int yen_1k = y / 1000;
    int yen_5k = 0;
    int yen_10k = 0;
    int cnt = yen_1k + yen_5k + yen_10k;
    if (cnt == n) printf("%d %d %d\n", yen_10k, yen_5k, yen_1k);
    else if (cnt < n) printf("-1 -1 -1\n");
    else {
        int dif = cnt - n;
        int y1k_2_y5k = min(dif / 4, yen_1k / 5);
        yen_5k += y1k_2_y5k;
        yen_1k -= y1k_2_y5k * 5;
        cnt = yen_1k + yen_5k + yen_10k;
        if (cnt == n) printf("%d %d %d\n", yen_10k, yen_5k, yen_1k);
        else {
            dif = cnt - n;
            int y5k_2_y10k = min(dif, yen_5k / 2);
            yen_10k += y5k_2_y10k;
            yen_5k -= y5k_2_y10k * 2;
            cnt = yen_1k + yen_5k + yen_10k;
            if (cnt == n) printf("%d %d %d\n", yen_10k, yen_5k, yen_1k);
            else printf("-1 -1 -1\n");
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i,a,b) for(ut i=(a);i<(ut)(b);i++)
#define REP(i,b) FOR(i,0,b)
#define ALL(c) c.begin(),c.end()
#define PB push_back
#define cat //cout << __LINE__ << endl;
using namespace std;
typedef long long LL;
typedef double ld;
typedef LL ut;
typedef vector<ut> VI;
typedef pair<ut,ut> pr;
typedef pair<ut,pr> ppr;
typedef vector<pr> Vpr;
typedef vector<ppr> Vppr;
typedef priority_queue<ut,VI> PQ;
const ut INF=1LL<<30;
const int SIZE=2001;
char x[]{'.','.','#','#'},y[]{'.','#','.','#'};
int main(){
	int N;
	cin >> N;
	string s1,s2;
	string ret;
	bool last=false;
	REP(i,N){
		if(!last)
			REP(j,4){
				cout << s1+x[j] <<endl << s2+y[j] << endl;
				cin >> ret;
				if(ret=="End") return 0;
				if(ret=="T"){
					s1+=x[j];
					s2+=y[j];
					break;
				}
				if(ret=="F" && j==3){
					last=true;
					i--;
				}
			}
		else{		
			REP(j,4){
				cout << x[j]+s1 <<endl << y[j]+s2 << endl;
				cin >> ret;
				if(ret=="End") return 0;
				if(ret=="T"){
					s1=x[j]+s1;
					s2=y[j]+s2;
					break;
				}
			}
		}
	}
	
	return 0;
}

Measured memory_bytes: 720
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<stack>
#include<cmath>
#include <bits/stdc++.h>
using namespace std;

int main(){
    long long arr[500];
    long long arr2[1001];
    long long MOD=1000000007;
    for(int i=0;i<1001;i++)arr2[i]=1;
    int ind=1;
    arr[0]=2;
    for(long long i=3;i<1000;i++){
    	bool ok=true;
    	for(int j=0;j<ind;j++){
    		if(i%arr[j]==0){
    			ok=false;
    			break;
    		}
    	}
    	if(ok)arr[ind++]=i;
    }
   // for(int i=0;i<ind;i++)cout<<arr[i]<<endl;
   // cout<<ind<<endl;
    long long n;
    cin>>n;
    
    if(n==1){cout<<1<<endl;return 0;}
    for(long long i=2;i<=n;i++){
    	
    	for(long long ind2=0, j=0;j<=i&&ind2<168;ind2++){
    		j=arr[ind2];
    		long long cnt=0;
    		long long cur=i;
    	//	cout<<j<<" "<<i<<" "<<ind2<<endl;
    		while(cur%j==0&&cur!=0){
    			cur=cur/j;
    			cnt=cnt+1;
    			//cout<<cnt<<" "<<cur<<endl;
    		}
    		arr2[j]+=cnt;
    		
    		//cout<<arr2[arr[j]]<<endl;
    	}
    }
    long long ans=1;
    for(int i=0;i<=n;i++){
    	ans=ans*arr2[i]%MOD;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
n=int(input())
if int(n**(1/2))!=n**(1/2):
    a=int(n**(1/2))+1
else:
    a=int(n**(1/2))
ans=0
for i in range(1,a):
    if (n-i)%i==0 and n-i>=i and (n-i)//i>i:
        ans+=(n-i)//i
print(ans)

Measured memory_bytes: 40300
import itertools
N = int(input())
L = [int(i) for i in input().split()]
cnt = 0
for v in itertools.combinations(L, 3):
    if (
        (len(set(v)) == 3) and
        (v[0] + v[1] > v[2]) and 
        (v[1] + v[2] > v[0]) and 
        (v[0] + v[2] > v[1])
    ):
         cnt = cnt + 1
print(cnt)

Measured memory_bytes: 9176
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
const int INF = 100000000;
const int MAX_N = 100;
typedef pair<int , int> P;
typedef long long ll;
 
int main () {
  int A, B, C, K, ans;
  ans = 0;
  cin >> A >> B >> C >> K;
  ans += min(A, K);
  if (A < K) {
    K -= A;
  } else {
    K = 0;
  }
  if (B < K) {
    K -= B;
  } else {
    K = 0;
  }
  ans -= K;
  printf("%d\n", ans);
  return 0;
}

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

#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))
#define ABS(a) ((a)>(0)?(a):-(a))
#define rep(i,a,b) for(int (i)=int(a);(i)<int(b);(i)++)
#define rrep(i,a,b) for(int (i)=int(a);(i)>=int(b);(i)--)

#define put(a) cout << (a) << endl
#define puts(a) cout << (a) << " "

#define INF 1e9+1
#define MOD 1e9+7
#define INF64 1e18+1

#define F first
#define S second

#define Pii  pair<int,int>
#define Pll  pair<long long,long long>
#define Piii pair<int,pair<int,int>>
#define Plll pair<long long,pair<long long,long long>>

#define Vll(a,b,c)    vector<vector<long long>> (a)((b),vector<long long>((c))
#define Vlll(a,b,c,d) vector<vector<vector<long long>>> (a)((b),vector<vector<long long>>((c),vector<long long>((d)))

#define MAX_N 1000000

int main (void)
{
  int N;
  cin >> N;
  vector<int> A(N);

  rep(i,0,N) {
    cin >> A[i];
  }

  int ct=0;

  for(int i=0;i<N;i++) {
    if(A[i] != i+1) {
      ct++;
    }
  }

  if((ct==2)||(ct==0)) {
    put("YES");
  }else {
    put("NO");
  }

  return 0;
}


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

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;
#define NIL NULL

Node root;

Node treeMinimum(Node x){
    while(x->left!=NIL)x=x->left;
    return x;
}

Node treeMaximum(Node x){
    while(x->right!=NIL)x=x->right;
    return x;
}

Node treeSearch(Node u, int k){
  if(u==NIL||u->key==k)return u;
  if(u->key<k)return treeSearch(u->right,k);

  return treeSearch(u->left,k);
}

Node treeSuccessor(Node x){
    if(x->right!=NIL)return treeMinimum(x->right);
    Node y=x->parent;
    while(y!=NIL&&x==y->right){
        x=y;
        y=y->parent;
    }
    return y;
}

void treeDelete(Node z){
  Node y; // node to be deleted
  Node x; // child of y
  if(z->left==NIL||z->right==NIL)y=z;
  else y=treeSuccessor(z);
  
  if(y->left!=NIL)x=y->left;
  else x=y->right;

  if(x!=NIL)x->parent=y->parent;

  if(y->parent==NIL)root=x;
  else if(y==y->parent->left)y->parent->left=x;
  else y->parent->right =x;

  if(y!=z)z->key=y->key;

}

void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;

  z = (Node)malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;
  while(x!=NIL){
    y=x;
    if(z->key<x->key)x=x->left;
    else x=x->right;

  }
  z->parent=y;
  if(y==NIL)root=z;
  else if(z->key<y->key)y->left=z;
  else y->right=z;
}

void inorder(Node u){
  if(u==NIL)return;
    inorder(u->left);
    cout<<" "<<u->key;
    inorder(u->right);

}
void preorder(Node u){
   if(u==NIL)return;
    cout<<" "<<u->key;
    preorder(u->left);
    preorder(u->right);

}


int main(){
  int n, i, x;
  char com[20];
  scanf("%d", &n);

  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
    if ( com[0] == 'f' ){
      scanf("%d", &x);
      Node t = treeSearch(root, x);
      if ( t != NIL ) printf("yes\n");
      else printf("no\n");
    } else if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    } else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    } else if ( com[0] == 'd' ){
      scanf("%d", &x);
      treeDelete(treeSearch(root, x));
    }
  }

  return 0;
}



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

int selectionSort(vector<int> &A, int N)
{
    int counter = 0;
    for (int i = 0; i < N-1; ++i) {
        int minj = i;
        for (int j = i; j < N; ++j) {
            if (A[j] < A[minj]) {
                minj = j;
            }
        }

        if (i != minj) {
            swap(A[i], A[minj]);
            counter++;
        }
    }
    return counter;
}

int main()
{
    vector<int> A;
    int N;

    cin >> N;

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

    int counter = selectionSort(A, N);

    for (int i = 0; i < N-1; ++i) {
        cout << A[i] << " ";
    }
    cout << A[N-1] << endl;
    cout << counter << endl;

    return 0;
}

Measured memory_bytes: 3172
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author indy256
 */

#include <bits/stdc++.h>

using namespace std;

void solve(istream &in, ostream &out) {
    int x;
    in >> x;

    vector<int> w;
    for (int i = 100; i <= 105; ++i) {
        w.emplace_back(i);
    }

    vector<bool> dp(x + 1);
    dp[0] = true;
    for (int i = 0; i < w.size(); ++i) {
        for (int j = w[i]; j < dp.size(); ++j) {
            dp[j] = dp[j] | dp[j - w[i]];
        }
    }

    out << (dp[x] ? 1 : 0) << '\n';
}


int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    std::istream& in(std::cin);
    std::ostream& out(std::cout);
    solve(in, out);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define el "\n"
const ll mod=1000000007;
const ll MAX=1e6+5;
#define all(v) v.begin(),v.end()




 
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int tc=1,i,j;
    //cin >> tc;
    while(tc--)
    {
        ll a,b;
        cin >> a >> b;
        cout << a*b << el;
    }
    return 0;
}

Measured memory_bytes: 3624
#include<iostream>
#include<algorithm>
#include<vector>
#include<numeric>
#include<string>
#include<cmath>
#include<set>
#include<queue>
#include<bitset>
#include<iomanip>
#include<cctype>

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep2(i,a,b) for (int (i)=a;(i)<(b);(i)++)
#define all(x) (x).begin(),(x).end()

using namespace std;
const int inf = 1001001000;

void print(vector<vector<int>> a){
	for (int i=0;i<a.size();i++){
		for (int j=0;j<a[i].size();j++){
			cout << a[i][j] << " ";
		}
		cout << endl;
	}
}

void print(vector<vector<long long int>> a){
	for (int i=0;i<a.size();i++){
		for (int j=0;j<a[i].size();j++){
			cout << a[i][j] << " ";
		}
		cout << endl;
	}
}

void print(vector<int> a){
    int n = a.size();
    for (int j=0;j<n;j++) {
        if (j != n-1) cout << a[j] << " ";
        else cout << a[j] << endl;
    }
}




void func(int H){
	int table[H][5];

	for(int i = 0; i < H; i++){
		for(int k = 0; k < 5; k++)scanf("%d",&table[i][k]);
	}

	bool FLG;
	int count = 0;

	while(true){

		FLG = false;

		for(int i = 0; i < H; i++){
			for(int k = 0,p = 0; k <= 2; k++){
				if(table[i][k] == -1)continue;
				for(p = 1; k+p < 5 && table[i][k+p] == table[i][k]; p++);
				if(p >= 3){
					for(int a = k; a < k+p; a++){
						count += table[i][a];
						table[i][a] = -1;
						FLG = true;
					}
					break;
				}
			}
		}

		for(int col = 0; col < 5; col++){
			for(int row = H-2,i = 0; row >= 0; row--){
				if(table[row][col] != -1){
					for(i = row+1; i < H && table[i][col] == -1; i++);
					if(i > row+1){
						table[i-1][col] = table[row][col];
						table[row][col] = -1;
					}
				}
			}
		}

		if(!FLG)break;
	}

	printf("%d\n",count);
}


int main(){

	int H;

	while(true){
		scanf("%d",&H);
		if(H == 0)break;

		func(H);
	}

    return 0;
}


Measured memory_bytes: 3220
H, W, M = map(int, input().split())

from collections import defaultdict
from collections import Counter
h_dic = defaultdict(int)#h[i]にいくつ爆発物があるか
w_dic = defaultdict(int)#w[i]にいくつ爆発物があるか

bomb = defaultdict(lambda:defaultdict(int))


for i in range(M):
  h,w = map(int,input().split())
  h_dic[h] += 1
  w_dic[w] += 1
  bomb[h][w] = 1
now_x = 0

firsth, num = max(h_dic.items(), key = lambda x:x[1])
for i,j in sorted(w_dic.items(), key = lambda x:x[1], reverse=True):
  if j <= now_x:
    break
  if bomb[firsth][i] == 1:
    x = j-1
  else:
    x = j
    now_x = x
    break
  now_x = x
fhans = num + now_x

now_x = 0
firstw, num = max(w_dic.items(), key = lambda x:x[1])
for i,j in sorted(h_dic.items(), key = lambda x:x[1], reverse=True):
  if j <= now_x:
    break
  if bomb[i][firstw] == 1:
    x = j-1
  else:
    x = j
    now_x = x
    break
  now_x = x
fwans = num + now_x
print(max(fhans,fwans))

Measured memory_bytes: 159016
l,k = map(int,input().split())
dp = [[0,0] for i in range(l+1)]
dp[1][0] = 1
if k <= l:
    dp[k][0] = 1
for h in range(1,l):
    dp[h+1][0] += dp[h][1]
    dp[h+1][1] += dp[h][0]
    if h+k <= l:
        dp[h+k][1] += dp[h][0]
ans = 0
for b,w in dp:
    ans += b
print(ans)

Measured memory_bytes: 5604
#include <algorithm>
#include <cstdio>
#include <utility>
using namespace std;
typedef pair<int,int> P;

int W,H;

bool used[200020];
int restx,resty;
P costs[200020];
int main(int argc, const char * argv[]) {
  scanf("%d%d", &W,&H);
  restx = W+1;
  resty = H+1;
  for(int i=0;i<W;++i) {
    int p;
    scanf("%d", &p);
    costs[i] = P(p, i);
  }
  for(int i=0;i<H;++i) {
    int q;
    scanf("%d", &q);
    costs[i+W] = P(q, i+W);
  }
  
  sort(costs, costs+W+H);
  
  long long answer = 0;
  for(int i=0;i<W+H;++i) {
    P cur = costs[i];
    int index = cur.second;
    if (index >= W) {
      answer += 1ll * cur.first * restx;
      resty--;
    } else {
      answer += 1ll * cur.first * resty;
      restx--;
    }
  }
  printf("%lld\n", answer);
  
  return 0;
}

Measured memory_bytes: 1664
def main():
  N, K = map(int, input().split())
  R, S, P = map(int, input().split())
  T = input()

  l = ["" for i in range(K)]
  s = 0
  for i in range(N):
    # print(l)
    if l[i%K] == T[i]:
      l[i%K]=""
      continue

    if l[i%K] == "":
      if T[i] == "r":
        s = s+P
        l[i%K] = "r"
      elif T[i] == "s":
        s = s+R
        l[i%K] = "s"
      else:
        s = s+S
        l[i%K] = "p"

    elif T[i]=="r":
      s = s+P
      l[i%K] = "r"
    elif T[i]=="s":
      s = s+R
      l[i%K] = "s"
    else:
      s = s+S
      l[i%K] = "p"

  print(s)

if __name__ == "__main__":
    main()

Measured memory_bytes: 9852
import math
a, b, x = map(int, input().split())
ans = 0

if a*a*b/2 < x:
    t = 2*x/(a*a) - b
    ans =  math.degrees(math.atan((b-t)/a))
else:
    t = 2*x/(a*b)
    ans = math.degrees(math.atan(b/t))

print(ans)

Measured memory_bytes: 9288
package main

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

type dice struct {
	t int64
	e int64
	w int64
	s int64
	n int64
	b int64
}

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)

	d := &dice{
		t: nextInt(sc),
		s: nextInt(sc),
		e: nextInt(sc),
		w: nextInt(sc),
		n: nextInt(sc),
		b: nextInt(sc),
	}

	q := nextInt(sc)
	for i := int64(0); i < q; i++ {
		d.setTopAndSouth(nextInt(sc), nextInt(sc))
		d.PrintE()
	}
}

func (d *dice) PrintE() {
	fmt.Println(d.e)
}

func (d *dice) setTopAndSouth(t, s int64) {
	d.setTop(t)
	switch s {
	case d.e:
		d.pitchL()
	case d.n:
		d.pitchR()
		d.pitchR()
	case d.w:
		d.pitchR()
	}
}

func (d *dice) setTop(t int64) {
	switch t {
	case d.s:
		d.rollN()
	case d.n:
		d.rollS()
	case d.e:
		d.rollW()
	case d.w:
		d.rollE()
	case d.b:
		d.rollN()
		d.rollN()
	}
}

func (d *dice) rollS() {
	oldB := d.b
	d.b = d.s
	d.s = d.t
	d.t = d.n
	d.n = oldB
}

func (d *dice) rollN() {
	oldB := d.b
	d.b = d.n
	d.n = d.t
	d.t = d.s
	d.s = oldB
}

func (d *dice) rollE() {
	oldB := d.b
	d.b = d.e
	d.e = d.t
	d.t = d.w
	d.w = oldB
}

func (d *dice) rollW() {
	oldB := d.b
	d.b = d.w
	d.w = d.t
	d.t = d.e
	d.e = oldB
}

func (d *dice) pitchR() {
	oldN := d.n
	d.n = d.e
	d.e = d.s
	d.s = d.w
	d.w = oldN
}

func (d *dice) pitchL() {
	oldN := d.n
	d.n = d.w
	d.w = d.s
	d.s = d.e
	d.e = oldN
}

func nextString(sc *bufio.Scanner) string {
	sc.Scan()
	return sc.Text()
}

func nextInt(sc *bufio.Scanner) int64 {
	i, err := strconv.ParseInt(nextString(sc), 10, 64)
	if err != nil {
		panic(err)
	}
	return i
}



Measured memory_bytes: 1108