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

#define pb push_back
#define mp make_pair

typedef long long ll;

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

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

  vector<int> v;
  for(int i = 0; i < n; i++){
    int a;
    cin >> a;
    v.pb(a);
  }

  sort(v.begin(), v.end(), greater<int>());
  
  int x = -1, y = -1;
  int cnt = 1;
  for(int i = 1; i < n; i++){
    if(v[i] == v[i-1]){
      cnt++;
      if(cnt == 2){
        cnt = 0;
        if(x == -1) x = v[i];
        else{
          y = v[i];
          break;
        }
      }
    }else{
      cnt = 1;
    }
  }

  if(x == -1 or y == -1) cout << 0 << endl;
  else cout << (ll)x*y << endl;

  return 0;
}


Measured memory_bytes: 892
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;
using LLONG = long long;
const LLONG MOD = 1000000007;

int main()
{
    int N; cin >> N;
    int rem = N % 10;
    if (N % 10 == 3)
    {
        cout << "bon" << endl;
    }
    else if (rem == 0 || rem == 1 || rem == 6 || rem == 8)
    {
        cout << "pon" << endl;
    }
    else
    {
        cout << "hon" << endl;
    }
}

Measured memory_bytes: 3596
all = gets.split.map(&:to_i)
q,h,s,d = all
l = [0.25, 0.5, 1.0, 2.0]
ata = 4.times.map{|i| all[i] / l[i] * 2}.map(&:to_i)

N = gets.to_i

min2 = ata.index(ata.min)
atau1 = ata[0..2]
min1 = atau1.index(atau1.min)

w2 = (N/2)*2
b2 = w2*ata[min2]
ama = N%2
b1 = ama*ata[min1]


puts (b2+b1)/2


Measured memory_bytes: 1788
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
  private static class FastScanner {
    private BufferedReader reader = null;
    private StringTokenizer tokenizer = null;

    public FastScanner(InputStream in) {
      reader = new BufferedReader(new InputStreamReader(in));
      tokenizer = null;
    }

    public String next() {
      if (tokenizer == null || !tokenizer.hasMoreTokens()) {
        try {
          tokenizer = new StringTokenizer(reader.readLine());
        } catch (IOException e) {
          throw new RuntimeException(e);
        }
      }
      return tokenizer.nextToken();
    }

    public String nextLine() {
      if (tokenizer == null || !tokenizer.hasMoreTokens()) {
        try {
          return reader.readLine();
        } catch (IOException e) {
          throw new RuntimeException(e);
        }
      }

      return tokenizer.nextToken("\n");
    }

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

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

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

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

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

  public static void main(String[] args) {
    FastScanner sc = new FastScanner(System.in);
    int n = sc.nextInt();
    int[] a = sc.nextIntArray(n);
    int count = 0;
    for (int i = 0; i < n; i++) {
      int num = i + 1;
      if (num % 2 == 1 && a[i] % 2 == 1) count++;
    }
    System.out.println(count);
  }
}

Measured memory_bytes: 32500
#include <iostream>
#include <numeric>
#include <math.h>
#include <algorithm>
#include <float.h>
#include <limits>
#include <vector> 
#include <string.h>
#include <iomanip>

#define rep(i,a,n) for(ll int (i) = (a);(i) < (n);(i)++)
#define urep(i,a,n) for(ll int (i) = (a);(i) > (n);(i)--)
#define MOD 1000000007
#define INF 2147483647
#define ll long long
#define asort(a) sort(a.begin(),a.end());//昇順ソート
#define usort(a) sort(a.rbegin(),a.rend());//降順ソート

using namespace::std;

int jo(ll int a, ll int b){//累乗
    ll int num=1;
    rep(i,0,b) num=num*a;
    return num;
}
char tobig(char s){//char大文字化
  return (s-0x20);
}
char tolow(char s){//char小文字化
  return (s+0x20);
}
int ctoi(char a){//char->int
  if('0'<=a&&a<='9') return (a-'0');
  return -1;
}

int gcd(ll int a,ll int b) {//最大公約数
  if(a<b) return gcd(b,a);
  int c;
  while ((c=a%b)) {
    a=b;
    b=c;
  }
  return b;
}
int lcm(ll int a,ll int b){//最小公倍数
 return (a*b)/gcd(a,b);
}


int main(){
  string S;cin>>S;
  int AC=0;
  rep(i,0,S.length()-1){
    if(S[i]=='A'&&S[i+1]=='C') AC++;
  }
  cout<<(AC?"Yes":"No");
}




// vector<vector<int>> 変数名(左の個数, vector<int>(右の個数));

//cout<<fixed<<setprecision(n);  //小数点n桁まで表示

//  vector<pair<int,int>> data(N);  //2つのデータを格納、.first/.secondで参照
// pairのソートはfirst優先の昇順


Measured memory_bytes: 256
import java.util.*;
class Main {
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		int a,b,c,d,sum;
		a = sc.nextInt();
		b = sc.nextInt();
		c = sc.nextInt();
		d = sc.nextInt();
		sum = a+c;
		if(a+d < sum)sum = a+d;
		if(b+c < sum)sum = b+c;
		if(b+d < sum)sum = b+d;
		System.out.println(sum);
	}
}

Measured memory_bytes: 21844
#include<bits/stdc++.h>
#define LL long long
#define db double

using namespace std;
const int N=55;
int rd()
{
    int x=0,w=1;char ch=0;
    while(ch<'0'||ch>'9'){if(ch=='-') w=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+(ch^48);ch=getchar();}
    return x*w;
}
struct graph
{
	int to[N<<2],nt[N<<2],ban[N<<2],hd[N],dg[N],tot;
	graph(){tot=1;}
	void adde(int x,int y){++tot,to[tot]=y,nt[tot]=hd[x],hd[x]=tot,++dg[y];}
	void wd()
	{
		int x=to[tot],y=to[tot-1];
		hd[x]=nt[hd[x]],hd[y]=nt[hd[y]],--dg[x],--dg[y];
		tot-=2;
	}
}t0,t1,g0;
bool z2[N][N],mk[N],ban[N];
int n,ans,na,fa[N],f2[N];
queue<int> q;
void dfs1(int x)
{
	for(int i=t0.hd[x];i;i=t0.nt[i])
	{
		int y=t0.to[i];
		if(t0.ban[i>>1]||y==fa[x]) continue;
		fa[y]=x,mk[y]=mk[x]&z2[x][y],dfs1(y);
	}
}
void dfs2(int x)
{
	for(int i=t1.hd[x];i;i=t1.nt[i])
	{
		int y=t1.to[i];
		if(t1.ban[i>>1]||y==f2[x]) continue;
		f2[y]=x,dfs2(y);
	}
}
void wk(int i,int o)
{
	memset(mk,0,sizeof(bool)*(n+1));
	fa[i]=f2[i]=0,mk[0]=mk[i]=1;
	dfs1(i),dfs2(i),mk[i]=o;
	memset(g0.hd,0,sizeof(int)*(n+1)),memset(g0.dg,0,sizeof(int)*(n+1)),g0.tot=1;
	na=n;
	for(int j=1;j<=n;++j)
	{
		na-=mk[j];
		if(fa[j]!=i&&!mk[j]&&!mk[fa[j]]) g0.adde(fa[j],j);
		if(f2[j]!=i&&!mk[j]&&!mk[f2[j]]) g0.adde(j,f2[j]);
	}
	for(int j=1;j<=n;++j)
		if(!g0.dg[j]) q.push(j);
	int rs=n;
	while(!q.empty())
	{
		int x=q.front();
		q.pop();
		--rs;
		for(int k=g0.hd[x];k;k=g0.nt[k])
		{
			int y=g0.to[k];
			--g0.dg[y];
			if(!g0.dg[y]) q.push(y);
		}
	}
	if(!rs) ans=min(ans,na);
}

int main()
{
	int T=rd();
	while(T--)
	{
		n=rd();
		memset(t0.hd,0,sizeof(int)*(n+1)),memset(t0.dg,0,sizeof(int)*(n+1)),t0.tot=1;
		for(int i=1;i<n;++i)
		{
			int x=rd(),y=rd();
			t0.adde(x,y),t0.adde(y,x);
		}
		memset(t1.hd,0,sizeof(int)*(n+1)),t1.tot=1;
		memset(z2,0,sizeof(z2));
		for(int i=1;i<n;++i)
		{
			int x=rd(),y=rd();
			t1.adde(x,y),t1.adde(y,x),z2[x][y]=z2[y][x]=1;
		}
		ans=n+1;
		for(int i=1;i<=n;++i) wk(i,1);
		for(int x=1;x<=n;++x)
		{
			if(t0.dg[x]>1) continue;
			int j=t0.hd[x];
			t0.ban[j>>1]=1;
			for(int y=1;y<=n;++y)
				if(x!=y) t0.adde(x,y),t0.adde(y,x),wk(x,0),t0.wd();
			t0.ban[j>>1]=0;
		}
		printf("%d\n",ans<=n?ans:-1);
	}
	return 0;
}


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

#define fast_io ios_base::sync_with_stdio(false) ; cin.tie(0); cout.tie(0);

int main() {
    fast_io;
    string s;
    cin>>s;

    ll x;
    cin>>x;

    ll rev=0;
    for(int i=0;i<x;i++) {
        int t;
        cin>>t;

        if(t==2) {
            if(rev%2!=0) {
                reverse(s.begin(),s.end());
            }
            rev=0;
            int pos;
            cin>>pos;

            string y;
            cin>>y;
            if(pos==1) {
                s.insert(0,y);
            }
            else {
                s.append(y);
            }
        }
        else {
            rev++;
        }
    }
    if(rev%2!=0) {
        reverse(s.begin(),s.end());
    }
    cout<<s<<endl;
}




Measured memory_bytes: 3860
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long 
#define inf 0x3f3f3f3f
#define infll 0x3f3f3f3f3f3f3f3f
#define all(x) (x).begin(),(x).end()
#define forn(i, a, b) for (int i=a; i<(signed)(b); ++i)
#define pb push_back
 
 
// debug templates 
#define debug(x)       cerr<< #x <<" : "<< x << endl;
#define debuga(A,N)    cerr<< #A <<" : [";for(int i = 0; i<N;i++) cerr<<A[i]<<" "; cerr<<"]\n";
#define debuga2(A,N,M) cerr<< #A << " : \n"; for(int i=0;i<N;i++){cerr<<"[";for(int j=0;j<M;++j) cerr<<A[i][j]<<" ";cerr<<"]\n";}
#define debugp(p)      cerr<< #p <<" : "<<"("<<(p).first<<","<<(p).second<<")\n";
#define debugv(v)      cerr<< #v <<" : "<<"[";for(int i = 0; i< (v).size(); i++) cerr<<v[i]<<" "; cerr<<"]\n";
#define debugv2(v)     cerr<< #v << " : \n"; for(int i=0;i<v.size();i++){cerr<<"[";for(int j=0;j<(v[0].size());++j) cerr<<v[i][j]<<" ";cerr<<"]\n";}
#define debugs(m)      cerr<< #m <<" : [ "; for(auto itr = m.begin(); itr!=m.end();itr++) cerr<<*itr<<" "; cerr<<"]\n";
#define debugm(m)      cerr<< #m <<" : [ "; for(auto itr = m.begin();itr!=m.end(); itr++) cerr<<"("<<itr->first<<","<<itr->second<<") ";cerr<<"]\n";
 

void solve(){
	int x1,x2,x3,x4,x5; cin >> x1 >> x2 >> x3 >> x4 >> x5;
	if(!x1) cout << 1;
	if(!x2) cout << 2;
	if(!x3) cout << 3;
	if(!x4) cout << 4;
	if(!x5) cout << 5;
}
 
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	
	solve();
	return 0;
}
 


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

static const int MAX = 100;
static const int INFTY = 1000000000;
static const int WHITE = 0, BLACK = 2;

int n;
int A[MAX][MAX];
int d[MAX], color[MAX];

void sssp() {
	for (int i = 0; i < n; i++) {
		d[i] = INFTY;
		color[i] = WHITE;
	}

	d[0] = 0;

	while (1) {
		int minv = INFTY, u = -1;
		for (int i = 0; i < n; i++) { 
			if (d[i] < minv && color[i] != BLACK) {
				minv  = d[i];
				u = i;
			}
		}
		if (u == -1) break;
		color[u] = BLACK;

		for (int j = 0; j < n; j++) { 
			if (A[u][j] < INFTY && color[j] != BLACK) {
				d[j] = min(d[j], d[u] + A[u][j]);
			}
		}
	}
}

int main() {
	cin >> n;
	for (int i = 0; i < n; i++)	{
		for (int j = 0; j < n; j++) {
			A[i][j] = INFTY;
		}
	}
	
	for (int i = 0; i < n; i++) {
		int u, k, v;
		cin >> u >> k;
		for (int j = 0; j < k; j++) {
			int t;
			cin >> v >> t;
			A[u][v] = t;
		}
	}

	sssp();

	for (int i = 0; i < n; i++) {
		cout << i << ' ' << d[i] << endl;
	}

	return 0;
}

Measured memory_bytes: 1200
#include <iostream>
#include <string>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <queue>
using namespace std;

#define N 24

char d[1<<N];
int x[N],y[N],r[N],c[N];
int n;
int over[N];

bool pailed(int a,int b){
  int d2 = (x[a]-x[b])*(x[a]-x[b])+(y[a]-y[b])*(y[a]-y[b]);
  int r2 = (r[a]+r[b])*(r[a]+r[b]);
  return d2 < r2;
}

int dfs(int i){
  if(d[i]!=-1) return d[i];
  d[i] = 0;
  for(int j=0;j<n-1;j++){
    //jがないorjの上に円盤がある
    if(!(i>>j&1)||over[j]&i) continue;
    for(int k=j+1;k<n;k++){
      //kがないorkの上に円盤があるor色が違う
      if(!(i>>k&1)||over[k]&i||c[k]!=c[j]) continue;
      d[i] = max( (int)d[i],2 + dfs((~(1<<j))&(~(1<<k))&i) );
    }
  }
  return d[i];
}

int main(){
  while(cin >> n,n){
    fill(over,over+n,0);

    for(int i=0;i<n;i++){
      scanf("%d%d%d%d",&x[i],&y[i],&r[i],&c[i]);
    }
    for(int i=n-1;i>=0;i--){
      for(int j=i-1;j>=0;j--){
        if(pailed(i,j)){
          over[i] |= 1<<j;
        }
      }
    }

    fill(d,d+(1<<n),-1);
    cout << (int)dfs((1<<n)-1) << endl;
  }
}

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

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

  int x, oneway = 0;
  for (int i = 0; i < n; i++) {
    cin >> x;
    if (x > k - x) {
      oneway += k - x;
    } else {
      oneway += x;
    }
  }
  cout << oneway * 2 << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;using ll=long long;using vi=vector<int>;using vvi=vector<vi>;using vl=vector<ll>;using vvl=vector<vl>;using P=pair<int,int>;using PL=pair<ll,ll>;using vp=vector<P>;using vpl=vector<PL>;
template<typename T>constexpr auto inf=numeric_limits<T>::max()/2;constexpr int INF=inf<int>,MOD=1000000007;constexpr ll LINF=inf<ll>;
#define _ol3(_1,_2,_3,name,...)name
#define _rep(i,n)_repi(i,0,n)
#define _repi(i,a,b)for(int i=a,i##_l=(b);i<i##_l;++i)
#define REP(...)_ol3(__VA_ARGS__,_repi,_rep,)(__VA_ARGS__)
#define REPR(i,n)for(int i=n-1;i>=0;--i)
#define REPA(i,v)REP(i,v.size())
#define all(v)(v).begin(),(v).end()
#define bit(n)(1ll<<(n))
#define uniq(v)sort(all(v));v.erase(unique(all(v)),v.end())
#define F first
#define S second
#define endl '\n'
#define cho(n,a,b)cout<<((n)?a:b)<<endl
void YES(int n){cho(n,"YES","NO");}void Yes(int n){cho(n,"Yes","No");}void Poss(int n){cho(n,"Possible","Impossible");}
void _print(ostream&s){}template<class T,class...U>void _print(ostream&s,T&&t,U&&...u){s<<t<<(sizeof...(u)?' ':'\n');_print(s,u...);}
template<class...T>void print(T&&...t){_print(cout,t...);}
#ifndef LOCAL
struct osd{template<class T>osd&operator<<(const T&t){return*this;}};osd cer_;
#define dprint(...)
#define cerr cer_
#else
template<class...T>void dprint(T&&...t){_print(cerr,t...);}
#endif
template<class T>void chmax(T&a,const T&b){if(a<b)a=b;}template<class T>void chmin(T&a,const T&b){if(a>b)a=b;}
template<class T>ostream&operator<<(ostream&o,const vector<T>&v){for(auto&&i:v)o<<i<<' ';return o;}
template<class T>istream&operator>>(istream&i,vector<T>&v){for(T&j:v)i>>j;return i;}
template<class T,class U>ostream&operator<<(ostream&o,const pair<T,U>&p){return o<<p.F<<' '<<p.S;}
template<class T,class U>istream&operator>>(istream&i,pair<T,U>&p){return i>>p.F>>p.S;}
template<class T>ostream&operator<<(ostream&o,const set<T>&v){for(auto&&i:v)o<<i<<' ';return o;}
template<class T>ostream&operator<<(ostream&o,const multiset<T>&v){for(auto&&i:v)o<<i<<' ';return o;}
template<class T>vector<T>&operator<<(vector<T>&v,const T&t){v.push_back(t);return v;}
template<class T>set<T>&operator<<(set<T>&v,const T&t){v.insert(t);return v;}
template<class T>multiset<T>&operator<<(multiset<T>&v,const T&t){v.insert(t);return v;}

int main(){
    cin.tie(0);ios::sync_with_stdio(0);
    int w,h,x,y;
    cin>>w>>h>>x>>y;
    print(ll(w)*h/2.0,(w==x*2 && h==y*2));
    return 0;
}


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

// 二分搜索
bool BinarySearch(int A[], int n, int key) {
    int left = 0 , right = n, mid;

    while (left < right) {
        mid = (left + right) / 2;
        if (key == A[mid])
            return true;

        if(key > A[mid])
            left = mid + 1;
        if (key < A[mid])
            right = mid;
    }
    return false;

}
int main() {
    int n, q, key;
    int sum = 0;
    int A[100000 + 10];
    scanf("%d", &n);
    for (int i = 0; i < n; i++)
        scanf("%d", &A[i]);
    scanf("%d", &q);
    for (int i = 0; i < q; i++) {
        scanf("%d", &key);
        if (BinarySearch(A, n, key))
            sum++;
    }
    printf("%d\n", sum);
}


Measured memory_bytes: 3484
while True :
    n,k = map(int,input().split())
    if n == 0 and k == 0 :
        break
    a = 0
    x = [ ]
    for i in range (n):
        y = int(input())
        x.append(y)
    b = 0
    for j in range (k):
        b += x[j]
    S = [ ]
    S.append(b)
    for i in range (1,n-k+1):
        b = S[i-1] + x[i+k-1] - x[i-1]
        S.append(b)
    print(max(S))



Measured memory_bytes: 11468
/*input
10
5 3
5 7
8 9
1 9
9 10
8 4
7 4
6 10
7 2

*/
/*

**************************
*						 *
* AUTHOR :: knight_coder *
*						 *
**************************

*/
#include<bits/stdc++.h>
#define lld          long long int
#define pb          push_back
#define ppb         pop_back
#define	endl		'\n'
#define mii         map<lld,lld>
#define msi         map<string,lld>
#define mis         map<lld, string>
#define mpi         map<pair<lld ,lld >,lld >
#define pii         pair<lld,lld>
#define vi          vector<lld>
#define vpi 		vector<pii>
#define vs          vector<string>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (lld)x.size()
#define hell        1000000007
#define rrep(i,m,n)	for(lld i=m;i>=n;i--)
#define rep(i,m,n)	for(lld i=m;i<n;i++)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
#define what_is(x)  cerr << #x << " is " << x << endl;
#define pr(x) 		cout<< x << " ";
#define pre(x)		cout<< x << endl ;
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
template<typename T>
using ordered_set = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>; 
//change null_type to get ordered_map
#define N  100005
void solve()
{
	lld n;
	cin >> n;
	lld val=0;
	rep(i,1,n){
		lld x,y;
		cin >> x >> y;
		if(x>y){
			swap(x,y);
		}
		val=val+x*(n-y+1);
	}
	lld add=0;
	rep(i,1,n+1){
		add+=i*(n-i+1);
	}
	cout << add-val << endl;
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int tests=1;
	//cin>>tests;
	while(tests--)
	{
		solve();
	}
}

Measured memory_bytes: 3504
import collections


def in_place_solve(n, bs):
    bs.sort()
    xs = collections.deque((bs[0], bs[n - 1]))
    i = 1
    j = n - 2
    while i < j:
        left = bs[i]
        right = bs[j]
        cs = (abs(xs[0] - left), abs(xs[-1] - left), abs(xs[0] - right), abs(xs[-1] - right))
        m = max(cs)
        if m == cs[0]:
            xs.appendleft(left)
            i += 1
        elif m == cs[1]:
            xs.append(left)
            i += 1
        elif m == cs[2]:
            xs.appendleft(right)
            j -= 1
        else:
            xs.append(right)
            j -= 1
    if i == j:
        rest = bs[i]
        if abs(xs[0] - rest) >= abs(xs[-1] - rest):
            xs.appendleft(rest)
        else:
            xs.append(rest)
    ys = list(xs)
    s = sum(abs(yj - yi) for yi, yj in zip(ys[:-1], ys[1:]))
    return s


def main():
    n = int(input())
    bs = [int(input()) for _ in range(n)]
    print(in_place_solve(n, bs))


if __name__ == '__main__':
    main()

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

ll gcd(ll a, ll b) {
	if(a==0||b==0) return 0;
	if(a<b) swap(a,b);
	ll tmp = a%b;
	while(tmp!=0) {
		a = b;
		b = tmp;
		tmp = a%b;
	}
	return b;
}

ll fac(ll x) {
	ll f=1;
	for(ll i=2; i<x; i++) {
		f*=i;
	}
	return f;
}

ll npr(ll n, ll r) {
	ll result=1;
	for(ll i=r+1; i<=n; i++) result*=i;
	return result;
}

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;
}



int main() {
	int n; cin>>n;
	int a[n]; for(int &ai: a) cin>>ai;
	bool flag[n]={false};
	
	int i=0,num=0;
	while(i!=1) {
		flag[i]=true;
		i=a[i]-1;
		if(flag[i]) {
			cout << -1 << endl;
			return 0;
		}
		num++;
	}
	cout << num << endl;
}


Measured memory_bytes: 768
#include <bits/stdc++.h>
using namespace std;
 
int main()
{
  int N, count, tmp;
  char S[100000];
  cin >> N;
  for(int i=0;i<N;i++)
  {
     cin >> S[i];
  }
  count=N;
  for(int j=0;j<N;j++)
  {
    if(S[j]==S[j+1]){count--;}
  }
  cout << count << endl;
}

Measured memory_bytes: 384
N,M = map(int,input().split())
Hls = list(map(int,input().split()))
lst = [[] for i in range(10**5)]
for i in range(M):
    A,B = map(int,input().split())
    lst[A-1].append(Hls[B-1])
    lst[B-1].append(Hls[A-1])
k = 0
for i in range(N):
    if bool(lst[i]):
        if Hls[i] > max(lst[i]):
            k += 1
    else:
        k += 1

print(k)

Measured memory_bytes: 94572
#include<bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
using LL = long long;
const LL LINF = 1e18;
using namespace std;
#define COUT(v) cout<<(v)<<endl
#define CIN(n)  int(n);cin >> (n)
#define LCIN(n) LL(n);cin >> (n)
#define SCIN(n) string(n);cin >> (n)
#define YES(n) cout<<((n)? "YES" : "NO")<<endl
#define Yes(n) cout<<((n)? "Yes" : "No")<<endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE"  ) << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible"  ) <<endl

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

#define FOREACH(x,a) for(auto& (x) : (a) )

#define ALL(obj) (obj).begin(),(obj).end()

#define P pair<LL,LL>
#define I vector<int>
#define S set<int>
#define pb(v) push_back(v)
#define V vector
#define rt return
#define rmsame(a) sort(ALL(a)),a.erase(unique(ALL(a)), a.end())

typedef string::const_iterator State;
class PalseError {};
class Edge{
public:
    LL from,to,value;
    Edge(LL a,LL b,LL c){
        from = a;
        to = b;
        value = c;
    }
    Edge(LL a,LL b){
        from = a;
        to = b;
    }
};

int main(){
    CIN(N);CIN(A);CIN(b);
    I vec;
    vec.pb(N);
    vec.pb(A);
    vec.pb(b);
    int ans = 0;
    sort(ALL(vec));
    int ins = vec.front();
    REP(a,3){
        ans += abs(vec.at(a)-ins);
        ins = vec.at(a);
    }
    COUT(ans);
    return 0;
}


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


int main()
{
	int x,y;
	scanf("%d%d",&x,&y);
	for(int i=0;i<=x;++i) {
		if(i*2+(x-i)*4==y) {puts("Yes");return 0;}
	}
	puts("No");
}

Measured memory_bytes: 3684
N , Y = map(int,input().split())
frag1 = 0
for i in range(0, N + 1):
    if frag1 == 1:
        break
    else:
        for j in range(0, N + 1 - i):
            total = 10000 * i + 5000 * j + 1000 * (N - i - j )
            if total == Y:
                a = i
                b = j
                c = N - i - j
                frag1 = 1
                break
if frag1 == 1:
    print("{0} {1} {2}".format(a , b , c))
else:
    print("-1 -1 -1")

Measured memory_bytes: 3064
#!/usr/bin/python3
# -*- coding:utf-8 -*-

def main():
  h, w = map(int, input().strip().split())
  maze = [list(input().strip()) for _ in range(h)]
  countw = [[0]*w for _ in range(h)]
  counth = [[0]*w for _ in range(h)]
  for i in range(h):
    l=r=0
    for j in range(w):      
      if maze[i][j] == '#':
        l=0
      else:
        l+=1
        countw[i][j] += l
      if maze[i][-(j+1)] == '#':
        r=0
      else:
        r+=1
        countw[i][-(j+1)] += r
        
  for j in range(w):
    t=b=0
    for i in range(h):
      if maze[i][j] == '#':
        t=0
      else:
        t+=1
        counth[i][j] += t
      if maze[-(i+1)][j] == '#':
        b=0
      else:
        b+=1
        counth[-(i+1)][j] += b
    
  max = -1
  for i in range(h):
    for j in range(w):
      score = counth[i][j] + countw[i][j]
      if max < score:
        max = score
  print(max-3)
  
if __name__=='__main__':
  main()



Measured memory_bytes: 245000
X = input()
ans = 0
S_count = 0
for i in range(len(X)):
    if X[i] == 'S':
        S_count -= 1
    elif S_count == 0 and X[i] == 'T':
        ans += 1
    elif X[i] == 'T':
        S_count += 1

print(2*ans)


Measured memory_bytes: 3500
#include<bits/stdc++.h>
using namespace std;
int main(){
  int x;
  cin >> x;
  int i = 2;
  int y = x;
  while(y<100004){
  bool b = true;
  for(int i = 2; i<y-1; i++){
    if(y%i ==0){
      b = false;
    }
  }
    if(b){
      cout << y << endl;
      return 0;
    }
    else{
      y++;
    }
}
}



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


// # DEFINES # //
#define ll long long
#define M (ll)(1e9+7)
#define EPS 1e-9

using namespace std;

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

    ll a, b;

    cin >> a >> b;

    cout << max(a+b, max(a-b, a*b)) << endl;
 
    return 0;
}

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

namespace ConsoleApp1
{
    static class DModSum
    {
        static void Main(string[] args)
        {
            var n = decimal.Parse(Console.ReadLine());

            if (n == 1)
            {
                Console.WriteLine(0);
                Console.ReadLine();
                return;
            }

            Console.WriteLine(n * (n - 1) / 2);
            Console.ReadLine();
        }
    }
}

Measured memory_bytes: 13268
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <map>
#include <cstdio>
#include <string>
#include <cstdlib>
#include <cstring>
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
const long double EPS = 1e-9;
const ll mod = 1e9 + 7;
const ll INF = 1e9;

#define rep(i, n) for(ll i = 0; i < n ; i++ )
#define For(i, a, b) for(ll i = (a); i < (b) ; i++ )
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()

const ll MAX_N = 100;

int main(void){
    ll x, y;
    ll answer = 1;

    cin >> x >> y;

    while(2 * x <= y){
        answer ++;
        x *= 2;
    }

    cout << answer << endl;

    return 0;
}

Measured memory_bytes: 256
n,k = map(int,input().split())
li = []
lia = [0]*(n-k+1)
for i in range(n):
    li.append(int(input()))
li.sort()
for i in range(n-k+1):
    lia[i] += li[i+k-1] - li[i]
print(min(lia))

Measured memory_bytes: 51292
#!/usr/bin/env python

from collections import deque, defaultdict
import itertools as ite
import sys
import math
import decimal

sys.setrecursionlimit(1000000)

INF = 10 ** 18
MOD = 10 ** 9 + 7
X, Y = map(int, raw_input().split())
ans = max(4 - X, 0) * 100000 + max(4 - Y, 0) * 100000
if X * Y == 1:
    ans += 400000
print ans

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

int main() {
  int K, A, B;
  cin >> K >> A >> B;

  for (int i = A; i <= B; i++) {
    if (i % K == 0) {
      cout << "OK";
      return 0;
    }
  }

  cout << "NG";

  return 0;
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
#define endl "\n"
#define ll long long int

int main()
 {
	//code
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll N,i;
    cin>>N;
    ll A[N],B[N];
    for(i=0;i<N;i++)
        cin>>A[i];
    B[N-1] = 0;
    B[N-2] = abs(A[N-1] - A[N-2]);
    for(i=N-3;i>=0;i--)
    {
        B[i] = min((abs(A[i] - A[i+1])+B[i+1]), (abs(A[i] - A[i+2])+B[i+2]));
    }
    cout<<B[0]<<endl;
	return 0;
}


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

int main(){
	int N,K;
	cin >> N >> K;
	int a[N];
	int num [N];
	for(int i=0;i<N;i++){
		cin >> a[i];
		num[i]=0;
	}
	for(int i=0;i<N;i++){
		num[a[i]-1]++;
	}
	sort(num, num+N);
	reverse(num, num+N);
	int ans=N;
	for(int i=0;i<K;i++){
		ans = ans - num[i];
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1920
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); ++i)
#define rep2(i,n) for(int i=1; i<=(n); ++i)
#define all(x) (x).begin(),(x).end()
#define Sort(x) sort((x).begin(),(x).end())
#define Sort2(x) sort((x).begin(),(x).end(), greater<int>())
#define pb push_back
using namespace std;
using ll = long long;
using P = pair<int,int>;
using Graph = vector<vector<int>>;

ll f(ll x) {
  return x*(x+1)/2;
}

int main()
{
  int n; cin >> n;
  ll ans = 0;
  vector<ll> tot(n+1);
  rep2(i,n){
    ans += i * f(n/i);
  }
  cout << ans << endl;
  return 0;
}

/*
g++ c.cpp
./a.out

oj d https://atcoder.jp/contests/abc172/tasks/abc172_c
g++ c.cpp
oj t
*/


Measured memory_bytes: 81340
from collections import defaultdict
n = int(input())
info = defaultdict(int)

def drawbuilding(n):
    for room_num in range(1,4):
        for floor_num in range(1,11):
            print(' '+str(info[f'{[n,room_num,floor_num]}']),end='')
        print()

for _ in range(n):
    tmp = list(map(int,input().split()))
    info[f'{tmp[:3]}'] += tmp[3]
    if info[f'{tmp[:3]}'] < 0:
        info[f'{tmp[:3]}'] = 0

for i in range(1,5):
    drawbuilding(i)
    if i < 4:
        print('#'*20)


Measured memory_bytes: 6020
#include <bits/stdc++.h>
using namespace std;
const long long INF = 1LL << 60;
const int mod = 1e9 + 7;

const int m = 2019;

int main()
{
    while (1)
    {
        long long h, w;
        cin >> h >> w;
        if (h == 0 && w == 0)
        {
            break;
        }
        for (int i = 0; i < h; i++)
        {
            for (int j = 0; j < w; j++)
            {
                if (i % 2 == 0)
                {
                    if (j % 2 == 0)
                    {
                        cout << '#';
                    }
                    else
                    {
                        cout << '.';
                    }
                }
                else
                {
                    if (j % 2 == 0)
                    {
                        cout << '.';
                    }
                    else
                    {
                        cout << '#';
                    }
                }
            }
            cout << endl;
        }
        cout << endl;
    }

    return 0;
}


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

const int d = 365;
int main() {
  vector<int> c(26);
  for (int i = 0; i < 26; i++) {
    cin >> c[i];
  }
  vector<vector<int>> s(d, vector<int>(26));
  for (int i = 0; i < d; i++) {
    for (int j = 0; j < 26; j++) {
      cin >> s[i][j];
    }
  }

  vector<int> t(26);
  for (int i = 0; i < 26; i++) {
    t[i] = i + 1;
  }

  for (int i = 0; i < d; i++) {
    cout << t[rand() % 26] << endl;
  }

  return 0;
}


Measured memory_bytes: 3668
#include <bits/stdc++.h>
#define all(a) (a).begin(), (a).end()
#define REP(i, n) for(int (i)=0; (i)<(n); (i)++)
#define RREP(i, n) for(int (i)=(n)-1, (i)>=0; (i)--)
#define ios() cin.tie(0), ios::sync_with_stdio(false)
typedef long long ll;
typedef unsigned long long ull;
ll const MOD = 1e9+7;
ll const INF = 1e18;
using namespace std;

int main(){
    string s, t, r;
    cin >> s >> t >> r;
    printf("%c%c%c\n", toupper(s.front()), toupper(t.front()), toupper(r.front()));
    return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
   public static void main(String[] args) {
      Scanner sc = new Scanner(System.in);

      int H = sc.nextInt();
      int W = sc.nextInt();
      int h = sc.nextInt();
      int w = sc.nextInt();

      System.out.println(H * W - h * W - H * w + h * w);

   }
}

Measured memory_bytes: 22996
#include<stdio.h>
#include<algorithm>
#include<functional>
using namespace std;
int main(void)
{
	int i,s=0,z=0,a[11],aa[10];
	for(i=1;i<=10;i++){
		scanf("%d",&a[i]);
	}
	sort(a+1,a+11,greater<int>());
	for(i=0;i<10;i++){
		scanf("%d",&aa[i]);
	}
	sort(aa,aa+10,greater<int>());
	s=a[1]+a[2]+a[3];
	z=aa[0]+aa[1]+aa[2];
	printf("%d %d\n",s,z);
	return 0;
}

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

public class Main {
  private static InputReader in;
  private static PrintWriter out;

  public static void main(String[] args) throws IOException {
    in = new InputReader(System.in);
    out = new PrintWriter(System.out, true);

    int a = in.nextInt(), b= in.nextInt();
    if (a <= 0 && b >= 0) {
      out.println("Zero");
    } else if (a > 0 && b > 0) {
      out.println("Positive");
    } else {
      int terms = (b-a+1);
      out.println(terms%2 == 0 ? "Positive" : "Negative");
    }
    
    
    out.close();
    System.exit(0);
  }

  static class InputReader {
    public BufferedReader reader;
    public StringTokenizer tokenizer;

    public InputReader(InputStream stream) {
      reader = new BufferedReader(new InputStreamReader(stream), 32768);
      tokenizer = null;
    }

    public String next() {
      while (tokenizer == null || !tokenizer.hasMoreTokens()) {
        try {
          tokenizer = new StringTokenizer(reader.readLine());
        } catch (IOException e) {
          throw new RuntimeException(e);
        }
      }
      return tokenizer.nextToken();
    }

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


}


Measured memory_bytes: 8020
#define r(a,i)for(i=0;i<a;i++)
#define s (scanf("%d",&w),w)
#define c(a,b)a=a<b?a:b
d[999],p[999];main(i,j,w,n,m){n=s;m=s;r(n,i)d[i]=s;r(n,i)p[i]=1e9;r(m,j){s;r(n,i)c(p[i],p[i+1]+w*d[n-i-1]);}printf("%d\n",*p),exit(0);}

Measured memory_bytes: 604
x1, y1, x2, y2 = map(int,input().split())
X, Y = (x2-x1),(y2-y1)
x3, y3 = (x2 - Y),(y2 + X)
x4, y4 = (x3 - X),(y3 - Y)
print(x3, y3, x4, y4)

Measured memory_bytes: 3316
#include <stdio.h>
#include <stdlib.h>
#include<math.h>

int compare(const void *p, const void *q) {
  int a = *(int*)p, b = *(int*)q;
  return b-a;
}


int main(){
  int i, n, d[1000],prev,post,sum=0,sum1=0;
  scanf("%d",&n);
  for(i=0;i<2*n;i++)
    scanf("%d",&d[i]);
  qsort(d, 2*n, sizeof(int), compare);
  for(i=1;i<2*n;i+=2)
    sum+=d[i];
  printf("%d\n",sum);
  return 0;

}

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

#define LLD_SPEC "%lld"

int main() {
    int n;
    scanf("%d", &n);
    vector<int> a(2 * n);
    for (int i = 0; i < 2 * n; ++i) {
        scanf("%d", &a[i]);
    }
    sort(a.begin(), a.end());

    int result = 0;
    for (int i = 0; i < 2 * n; i += 2) {
        result += a[i];
    }

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

    return 0;
}

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

const ll INF = 200005;

void func(long long N, std::vector<long long> P){
    int ans = 0;
    int min = INF;
    rep(i,N) {
        if (P[i] <= min) {
            ++ans;
            min = P[i];
        } 
    }
    cout << ans << endl;
}

int main(){
    // cout << fixed << setprecision(5);

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


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

int main(){
    int n;
    cin >> n;
    int x[n];
    bool used[2100] = {};
    for(int i = 0; i < n; i++){
        cin >> x[i];
        used[x[i]] = true;
    }
    int m;
    cin >> m;
    while(m-- > 0){
        int k;
        cin >> k;
        k--;
        if(x[k] != 2019 && !used[x[k]+1]){
            used[x[k]++] = false;
            used[x[k]] = true;
        }
    }
    for(int i = 0; i < n; i++)  cout << x[i] << endl;
    return 0;
}


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

using namespace std;

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

#ifdef LOCAL
#include "debug.h"
#endif

const int N = 110;

int h, w;
char cell[N][N];
int dp[N][N];

int main() {
	#ifdef LOCAL
	freopen("in", "r", stdin);
	freopen("out", "w", stdout);
	#endif

	cin >> h >> w;
	for (int i = 1; i <= h; i++) {
		for (int j = 1; j <= w; j++) {
			scanf(" %c", &cell[i][j]);
			dp[i][j] = INT_MAX;
		}
	}

	dp[h][w] = cell[h][w] == '#';
	for (int r = h; r >= 1; r--) {
		for (int c = w; c >= 1; c--) {
			if (cell[r][c] == '.') {
				if (r < h) dp[r][c] = min(dp[r][c], dp[r + 1][c]);
				if (c < w) dp[r][c] = min(dp[r][c], dp[r][c + 1]);
			}
			else {
				if (r < h) dp[r][c] = min(dp[r][c], dp[r + 1][c] + (cell[r + 1][c] == '.'));
				if (c < w) dp[r][c] = min(dp[r][c], dp[r][c + 1] + (cell[r][c + 1] == '.'));
			}
		}
	}

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

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file 
#include <ext/pb_ds/tree_policy.hpp> 
#include <functional> // for less 
#define pb push_back
#define For(i,s,e) for (ll i=(s); i<(e); i++)
#define Debug_array(a,n) for (ll i=(0); i<(n); i++) cout<<a[i]<<" "
#define Foe(i,s,e) for (ll i=(s); i<=(e); i++)
#define Fod(i,s,e) for (ll i=(s)-1; i>=(e); i--)
#define Mod 1000000007
#define pii pair<ll,ll>
#define fi first
#define se second
#define endl "\n"
#define mp make_pair
#define big_prime 15486277
#define bigger_prime 179424697
#define biggest_prime 32416188691
//#define random_shuffle(indices.begin(), indices.end());
//std::random_device rd;
//std::mt19937 g(rd());
//std::shuffle(v.begin(), v.end(), g);
using namespace __gnu_pbds; 
using namespace std;

typedef long long ll;
typedef tree<ll, null_type, less<ll>, rb_tree_tag,tree_order_statistics_node_update> ordered_set; 

#define MAX 5002
ll power(ll a,ll b){
	if(b==0) return 1;
	ll temp = power(a,b/2)%Mod;
	if(b%2==0){
		return (temp*temp)%Mod;
	}else{
		return (a*((temp*temp)%Mod))%Mod;
	}
}

int main(){
	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	
	ll n,a,b,c;cin>>n>>a>>b>>c;
	pii C[2*n];
	C[n-1]={1,1};
	For(i,n,2*n){
		C[i].fi = (C[i-1].fi*(i))%Mod;
		C[i].se = (C[i-1].se*(i-n+1))%Mod;
	}

	ll p = 0;
	ll q = (power(a+b,2*n)*(100-c))%Mod;
	Foe(m,n,2*n-1){
		ll c = (C[m-1].fi*power(C[m-1].se,Mod-2))%Mod;

		ll term1 = (power(a,n)*power(b,m-n))%Mod;
		ll term2 = (power(a,m-n)*power(b,n))%Mod;

		ll t1 = m;
		
		ll t2 = (term1*power(a+b,2*n-m))%Mod;
		t2 = (t2+(term2*power(a+b,2*n-m))%Mod)%Mod;
		t2 = (t2*c)%Mod;
		
		p += (t1*t2)%Mod;
		p %= Mod; 
	}
	p = (p*100)%Mod;
	cout<<(p*power(q,Mod-2))%Mod<<endl;









	
}

Measured memory_bytes: 3328
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a [] = { 0, 1, 3, 1, 2, 1, 2, 1, 1, 2, 1, 2, 1};
  
  int x, y;
  cin >> x >> y;
  
  if (a[x] == a[y]){
    cout  << "Yes" << endl;
  }
  
  else{
    cout << "No" << endl;
  }
}

Measured memory_bytes: 384
#include <algorithm>
#include <iostream>
#include <limits>
#include <numeric>
#include <string>
#include <cmath>

#define rep(i, x, n) for (int i = x; i < n; i++)
using namespace std;
const long long INF = 1LL << 60;

int main()
{
    int X, Y;
    cin >> X >> Y;
    rep(i, 0, X + 1)
    {
        if (i * 4 + (X - i) * 2 == Y)
        {
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
}

Measured memory_bytes: 3640
import math
a,b,h,m = map(int, input().split())
 
hrad = 30 * h + 0.5 * m
mrad = 6 * m
diff = abs(hrad - mrad)
if diff > 180:
  diff = abs(mrad - hrad)
  
ans = math.sqrt(a*a + b*b - 2*a*b*math.cos(math.radians(diff)))
print(ans)

Measured memory_bytes: 9508
def bubble_sort(A, N):
    count = 0
    flag = True
    while flag:
        flag = False
        for i in range(N-1, 0, -1):
            if A[i] < A[i-1]:
                A[i-1], A[i] = A[i], A[i-1]
                count += 1
                flag = True
    return count


N = int(input())
A = list(map(int, input().split()))

count = bubble_sort(A, N)
print(" ".join(list(map(str, A))))
print(count)



Measured memory_bytes: 5604
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        char[] s = sc.next().toCharArray();
        int[] a = new int[4];
        for(int i=0;i<4;i++){
            a[i] = s[i]-'0';
        }
        sc.close();
        int sum;
        int sign = 1;
        for(int i=0;i<8;i++){
            sign = 1;
            sum = 0;
            for(int j=0;j<3;j++){
                if(((i>>2-j)&1)==1){
                    sum+=sign*a[j];
                    sign = 1;
                }else{
                    sum+=sign*a[j];
                    sign = -1;
                }
            }
            sum+=a[3]*sign;
            if(sum==7){
                StringBuilder sb = new StringBuilder();
                for(int j=0;j<3;j++){
                    sb.append(a[j]);
                    if(((i>>2-j)&1)==1){
                        sb.append('+');
                    }else{
                        sb.append('-');
                    }
                }
                sb.append(a[3]);
                sb.append("=7");
                System.out.println(sb.toString());
                return;
            }
        }
    }

}

Measured memory_bytes: 22996
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <queue>
#include <set>
#include <stack>
#include <map>
#include <unordered_map>
#include <cmath>
#include <utility> // pair make_pair
#include <algorithm>
#include <functional>
#include <iomanip>
#include <climits> // LLONG_MAX, LLONG_MIN, INT_MIN, INT_MAX
#include <assert.h>

#define m0(x) memset(x,0,sizeof(x))
#define m1(x) memset(x,63,sizeof(x))
#define fill(x,y) memset(x,y,sizeof(x))
#define ll long long
#define int ll
#define INF LLONG_MAX/100000

using namespace std;
using Pi = pair<int, int>;
using Graph = vector<vector<int> >;
using WeightGraph = vector<vector<Pi> >;


static const int MAX = 2500;

int d[MAX];
WeightGraph WG(MAX);

// true if negative loop, false if no negative loop
// O (|E| * |V|)
pair<bool, int > bellman_ford(const WeightGraph& WG, int (&d)[MAX], const int &n, const int& s) {
  // initialize to INF except the starting node
  for (int i = 0; i < n; i++) {
    d[i] = INF;
  }
  d[s] = 0;

  int flag;
  int ans = INF;
  for (int i = 0; i < 2*n; i++) {
    if (i == n - 1) {
      flag = d[s];
      ans = d[0];
    }
    for (int v = 0; v < n; v++) {
      for (auto adjacent : WG[v]) {
        int nv = adjacent.first;
        int nd = adjacent.second;
        if (d[v] != INF && d[nv] > d[v] + nd) {
          if (i == n - 1) {
            //cout << "negative loop" << endl;
            //return true;

            d[nv] = d[v] + nd - INF;
          } else {
            d[nv] = d[v] + nd;
          }
        }
      }
    }
  }

  return Pi(flag == d[s], d[0]);
}


signed main() {
  int N, M, P; cin >> N >> M >> P;

  Graph G(N);
  
  for (int i = 0; i < M; i++) {
    int a, b, c;
    cin >> a >> b >> c;
    a--; b--; c -= P; c = -1*c;
    G[b].push_back(a);
    WG[b].push_back(Pi(a, c));
  }

  // DAG dg(G);
  // dg.tsort();
  // if (dg.is_acyclic == false) {
  //   cout << -1 << endl;
  //   return 0;
  // }

  Pi A =  bellman_ford(WG, d, N, N-1);

  if (!A.first) {
    cout << -1 << endl;
    return 0;
  } else {
    if (A.second <= -1*INF/100) {
      cout << -1 << endl;
    } else if ( A.second > 0) {
      cout << 0 << endl;
    } else {
      cout << -1 * A.second << endl;
    }
  }
}


Measured memory_bytes: 640
import java.util.*;

public class Main {
    public static void main(String[] args)  {
        Scanner sc = new Scanner(System.in);
        int H = sc.nextInt();
        int W = sc.nextInt();
        String [] S = new String [H];
        int [] [] ans = new int [H] [W];
        
        for(int i=0; i<H; i++){
            S[i] = sc.next();
        }
        
        for(int i =0; i<H; i++){
            for(int j=0; j<W; j++){
            if(S[i].charAt(j) == '#'){
                ans[i][j] = -1;
            }else{
                    if(i > 0 && S[i-1].charAt(j) == '#') ans[i][j]++;
                    if(i < H-1 && S[i+1].charAt(j) == '#') ans[i][j]++;
                    if(j > 0 && S[i].charAt(j-1) == '#') ans[i][j]++;
                    if(j < W-1 && S[i].charAt(j+1) == '#') ans[i][j]++;
                    if(i > 0 && j > 0 && S[i-1].charAt(j-1) == '#') ans[i][j]++;
                    if(i < H-1 && j < W-1 && S[i+1].charAt(j+1) == '#') ans[i][j]++;
                    if(i < H-1 && j > 0 && S[i+1].charAt(j-1) == '#') ans[i][j]++;
                    if(i > 0 && j < W-1 && S[i-1].charAt(j+1) == '#') ans[i][j]++;
            }
            }
        }
        
        for(int i =0; i<H; i++){
            for(int j=0; j<W; j++){
                if(ans[i][j] == -1){
                    System.out.print('#');
                }else{
                    System.out.print(ans[i][j]);
                }
            }
            
            System.out.println("");
        }
    }
}


Measured memory_bytes: 36488
#include<bits/stdc++.h>
using namespace std;
inline int read(){
    int f=1,x=0;
    char ch;
    do{
        ch=getchar();
        if(ch=='-'){
            f=-1;
        }
    }while(ch<'0'||ch>'9');
    do{
        x=x*10+ch-48;
        ch=getchar();
    }while(ch>='0'&&ch<='9');
    return f*x;
}
int main(){
    int n=read(),a=read();
    int mj=n*n;
    printf("%d\n",mj-a);
    return 0;
}

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

using namespace std;
typedef long long ll;
typedef pair<int,int> PI;
const double EPS=1e-6;
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define F first
#define S second
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define SZ(a) (int)((a).size())
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) a.rbegin(),a.rend()
#define FLL(a,b) memset((a),b,sizeof(a))
#define CLR(a) FLL(a,0)
#define declare(a,it) __typeof(a) it=(a)
#define FOR(it,a) for(declare(a.begin(),it);it!=a.end();++it)
#define FORR(it,a) for(declare(a.rbegin(),it);it!=a.rend();++it)
template<class T,class U> ostream& operator<< (ostream& o, const pair<T,U>& v){return o << "(" << v.F << ", " << v.S << ")";}
template<class T> ostream& operator<< (ostream& o, const vector<T>& v){o << "{";rep(i,SZ(v)) o << (i?", ":"") << v[i];return o << "}";}
int dx[]={0,1,0,-1,1,1,-1,-1};
int dy[]={1,0,-1,0,-1,1,1,-1};
int s2i(string& a){stringstream ss(a);int r;ss>>r;return r;}
int geti(){int n;scanf("%d", &n);return n;}

int ns,nl;
int s[20],t[20], d[20];

int memo[10][1<<20];
int rec(int v,int st){
  if(memo[v][st] >= 0)
    return memo[v][st];
  int& ret = memo[v][st] = 0;

  for(int i = 0; i < nl; ++i){
    if((st>>i)&1) continue;
    if(v == s[i])
      ret = max(ret, rec(t[i], st|(1<<i)) + d[i]);
    if(v == t[i])
      ret = max(ret, rec(s[i], st|(1<<i)) + d[i]);
  }
  
  return ret;
}

int getpath(int v,int st){
  cout << v+1;
  if(memo[v][st] == 0){
    cout << endl;
    return memo[v][st];
  }
  cout << " ";
  int ret = memo[v][st];
  int ne = ns;
  int nst;
  
  for(int i = 0; i < nl; ++i){
    if((st>>i)&1) continue;
    if(v == s[i] && rec(t[i], st|(1<<i)) + d[i] == ret && t[i] < ne){
      ne = t[i];
      nst = st | (1<<i);
    }

    if(v == t[i] && rec(s[i], st|(1<<i)) + d[i] == ret && s[i] < ne){
      ne = s[i];
      nst = st | (1<<i);
    }    
  }

  getpath(ne,nst);
  
  return ret;
}


int main(int argc, char *argv[])
{
  while(cin >> ns >> nl && ns){
    for(int i = 0; i < nl; ++i){
      cin >> s[i] >> t[i] >> d[i];
      --s[i], --t[i];
    }
    memset(memo, -1, sizeof(memo));
    int ma = 0;
    for(int i = 0; i < ns; ++i)
      ma = max(ma, rec(i, 0));
    cout << ma << endl;
    for(int i = 0; i < ns; ++i){
      if(rec(i,0) == ma){
        getpath(i,0);
        break;
      }
    }
  }
  return 0;
}

Measured memory_bytes: 42132
#include <iostream>
#include <string>
#include <cstring>
#include <fstream>
#include <cmath>
#include <iomanip>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <map>
#include <deque>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <list>
#include <unordered_map>
#include <bitset>
#include <sstream>

typedef  long long ll;
#define mop 1000000007
using namespace std;

const ll MAX = 200001;
ll dp[MAX] = {};

int main() {
    

    ll n;
    cin >> n;
    vector <ll> v;
//    vector <ll> pos[20001];
    ll pos[MAX] = {};
    for (ll i=0;i<n;i++){
        ll c;
        cin >> c;
        if(i == 0){
            v.push_back(c);

        }else{
            if(v[v.size()-1] != c){
                v.push_back(c);
            }
        }
    }
    dp[0] = 1;
    for (ll i=1;i<=v.size();i++){
        dp[i] = dp[i-1];

//        cout << pos[v[i-1]].size() << endl;
//        for (ll j=0;j<pos[v[i-1]].size();j++){
        if(pos[v[i-1]] != 0) {
            dp[i] += dp[pos[v[i-1]]];
        }
        dp[i] %= mop;
        pos[v[i-1]] = i;

//            dp[i] %= mop;
//        }
//        pos[v[i-1]].push_back(i);

    }
//    for (ll i=0;i<=v.size();i++){
//        cout << i << " " << dp[i] << endl;
//    }
    cout << dp[v.size()] << endl;

}

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

static const int INF = 1e9+7;

int main(){
    int N;
    cin>>N;
    vector<int> H(N);
    vector<int> dp(100000,INF);

    for(int i=0; i<N; i++) cin>>H[i];
    dp[0] = 0;

    for(int i=1; i<N; i++){
        dp[i] = min(dp[i-1]+abs(H[i]-H[i-1]),dp[i]);
        if(i> 1) dp[i] = min(dp[i-2]+abs(H[i-2]-H[i]),dp[i]);
    }

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

    return 0;

}



Measured memory_bytes: 1024