akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

vector<int> table(26, -1);
vector<bool> used(10, false);
int dfs(int d, vector<string> &str, vector<char> &clist, vector<bool> &nonzero, vector<long long int> &num){
    if(d==0){
        long long int sum=0;
        for(int i=0; i<(int)clist.size(); i++){
            sum += num[i]*table[clist[i]-'A'];
        }
        if(sum==0){
            return 1;
        }else{
            return 0;
        }
    }

    int ret = 0;
    for(int i=0; i<=9; i++){
        if(used[i]) continue;
        if(i==0 && nonzero[clist[d-1]-'A']) continue;
        used[i] = true;
        table[clist[d-1]-'A'] = i;
        ret += dfs(d-1, str, clist, nonzero, num);
        table[clist[d-1]-'A'] = -1;
        used[i] = false;
    }
    return ret;
}

int main(){
    while(1){
        int n;
        cin >> n;
        if(n==0) break;

        vector<string> str(n);
        vector<char> clist;
        vector<bool> nonzero(26, false);
        for(int i=0; i<n; i++){
            cin >> str[i];
            for(int j=0; j<(int)str[i].length(); j++){
                clist.push_back(str[i][j]);
            }
            if((int)str[i].length()!=1){
                nonzero[str[i][0]-'A'] = true;
            }
        }
        sort(clist.begin(), clist.end());
        clist.erase(unique(clist.begin(), clist.end()), clist.end());
        
        int numc = clist.size();
        vector<long long int> num(numc, 0);
        for(int d=0; d<numc; d++){
            for(int i=0; i<n; i++){
                long long int sub = 0;
                for(int j=0; j<(int)str[i].length(); j++){
                    sub *= 10;
                    if(str[i][j] == clist[d]) sub+=1;
                }
                if(i==n-1) num[d] -= sub;
                else num[d] += sub;
            }
        }
        cout << dfs(numc, str, clist, nonzero, num) << endl;
    }
    return 0;
}

Measured memory_bytes: 3044
#include <iostream>
#include <vector>
#include <functional>

using namespace std;

template<class T> struct dual_segment_tree {
	using F = function<T(T, T)>;
	using value_type = T;
private : 
	int n, hight;
	const F f;
	const value_type ie;
	vector<value_type> node;

public : 
	dual_segment_tree (const F &f, const value_type &ie) : f(f), ie(ie) { }
	
	void resize (int _n) {
		n = 1; hight = 0;
		while (n < _n) { n <<= 1; hight++; }
		node.resize(2 * n);
		fill(node.begin(), node.end(), ie);
	}

	void resize (int _n, const value_type &e) {
		n = 1; hight = 0;
		while (n < _n) { n <<= 1; hight++; }
		node.resize(2 * n);
		fill(node.begin(), node.end(), ie);
		for (int i = n; i < 2 * n; i++) node[i] = e;
	}
	
	template<class iter>
	void build (iter l, iter r) {
		resize(r - l);
		for (int i = n; l != r; i++, l++) node[i] = (*l);
	}

	void propagate (int i) {
		if (node[i] == ie) return;
		node[i << 1 | 0] = f(node[i << 1 | 0], node[i]);
		node[i << 1 | 1] = f(node[i << 1 | 1], node[i]);
		node[i] = ie;
	}

	inline void apply (int i) {
		for (int j = hight; j > 0; j--) propagate(i >> j);
	}

	void update (int a, int b, const value_type &x) {
		apply(a + n); apply(b + n - 1);
		for (int l = a + n, r = b + n; l < r; l >>= 1, r >>= 1) {
			if (l & 1) { node[l] = f(node[l], x); l++; }
			if (r & 1) { r--; node[r] = f(node[r], x); }
		}
	}

	const value_type &operator[] (int i) {
		apply(i + n);
		return node[i + n];
	}

	void swap (dual_segment_tree &s) {
		(this->node).swap(s.node);
	}

};


int main() {
	int n, k;
	cin >> n >> k;
	vector<int> a(n);
	for (int &e : a) cin >> e;
	
	auto f = [](int a, int b) { return (a + b); };
	dual_segment_tree<int> seg(f, 0);
	seg.build(a.begin(), a.end());

	for (int _ = 0; _ < k; _++) {
		dual_segment_tree<int> buff(f, 0);
		buff.resize(n);
		for (int i = 0; i < n; i++) {
			int d = seg[i];
			buff.update(max(0, i - d), min(n, i + d + 1), 1);
		}
		bool fin = true;
		for (int i = 0; i < n; i++) {
			fin &= (buff[i] == n);
		}
		seg.swap(buff);
		if (fin) break;
	}
	
	for (int i = 0; i < n; i++) cout << seg[i] << ' ';
	
	return 0;
}

Measured memory_bytes: 8280
#include<bits/stdc++.h>
using namespace std;
int main()
{
  ios_base::sync_with_stdio(false);
  int n , t , i;
  int a[100002] , dp[100002];
  cin >> n >> t;
  for(i=1;i<=n;i++)
  {
    cin >> a[i];
  }
  dp[n] = a[n];
  for(i=n-1;i>=1;i--)
  {
    if(dp[i+1] > a[i])
    {
      dp[i] = dp[i+1];
    }
    else dp[i] = a[i];
  }
  int ansm = 0 , ansc = 0;
  for(i=1;i<=n;i++)
  {
    int d = dp[i] - a[i];
    if(d > ansm)
    {
      ansm = d;
      ansc = 1;
    }
    else if(d == ansm)
    {
      ansc++;
    }
  }
  cout << ansc;
  return 0;
}


Measured memory_bytes: 1152
#include <iostream>
#include <string>
#include <queue>
#include <map>
#include <vector>
using namespace std;

typedef pair<char,char> P;

int main(){
	int t;
	cin >> t;
	for(int a = 0;a < t;a++){
		int h,w;
		map<char,int> xmin,xmax,ymin,ymax,in;
		map<char,bool> used;
		map<char,vector<int> > G;
		map<P,bool> already;
		string field[50];
		cin >> h >> w;
		for(int i = 0;i < h;i++){
			cin >> field[i];
			for(int j = 0;j < w;j++){
				if(field[i][j] != '.'){
					if(xmin.find(field[i][j]) == xmin.end()){
						xmin[field[i][j]] = i;
						xmax[field[i][j]] = i;
						ymin[field[i][j]] = j;
						ymax[field[i][j]] = j;
					}
					else{
						xmin[field[i][j]] = min(i,xmin[field[i][j]]);
						xmax[field[i][j]] = max(i,xmax[field[i][j]]);
						ymin[field[i][j]] = min(j,ymin[field[i][j]]);
						ymax[field[i][j]] = max(j,ymax[field[i][j]]);
					}
				}
			}
		}
		bool flag = true;
		for(auto it = xmin.begin();it != xmin.end();it++) {
			in[it->first] = 0;
			used[it->first] = false;
		}
		for(auto it = xmin.begin();it != xmin.end();it++){
			char c = it->first;
			for(int i = xmin[c];i <= xmax[c];i++){
				for(int j = ymin[c];j <= ymax[c];j++){
					if(field[i][j] == '.') flag = false;
					else if(field[i][j] != c && !already[P(c,field[i][j])]){
						G[c].push_back(field[i][j]);
						in[field[i][j]]++;
						already[P(c,field[i][j])] = true;
					}
				}
			}
		}
		queue<char> que;
		for(auto it = in.begin();it != in.end();it++){
			if(it->second == 0) que.push(it->first);
		}
		while(!que.empty()){
			char v = que.front();que.pop();
			used[v] = true;
			for(int i = 0;i < G[v].size();i++){
				char to = G[v][i];
				in[to]--;
				if(!in[to]){
					que.push(to);
				}
			}
		}
		for(auto it = used.begin();it != used.end();it++){
			if(!it->second) flag = false;
		}
		if(flag) cout << "SAFE" << endl;
		else cout << "SUSPICIOUS" << endl;
	}
	return 0;
}

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

using namespace std;

#define N 3000
#define INF 0x3f3f3f3f

int n,m,p,ans,a[N],b[N],c[N];

int main(){
	scanf("%d%d%d",&n,&m,&p);
	for (int i=1;i<=n;++i) scanf("%d",&a[i]);
	ans=INF;
	for (int i=1;i<=n;++i){
		int xb=0,tot=0;
		for (int j=1;j<=n;++j)
			if (a[j]>=a[i]) b[++xb]=a[j];
			else{
				sort(b+1,b+xb+1);
				for (int k=1;k+m-1<=xb;++k) c[++tot]=b[k];
				xb=0;
			}
		sort(b+1,b+xb+1);
		for (int k=1;k+m-1<=xb;++k) c[++tot]=b[k];
		if (tot>=p){
			sort(c+1,c+tot+1);
			ans=min(ans,c[p]-c[1]);
		}
	}
	printf("%d\n",ans);
	
	return 0;
}
			

Measured memory_bytes: 256
import static java.util.stream.Collectors.groupingBy;

import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Scanner;

public class Main {
    static final Scanner sc = new Scanner(System.in);
    static final int MOD = (int) 1E9 + 7;
    
    public static void main(String[] args) {
        int N = nint();
        int M = nint();
        
        List<City> cities = new ArrayList<>(1000000);
        for (int i = 1; i <= M; i++) {
            cities.add(new City(nint(), nint()));
        }
        
        Map<Integer, List<City>> map =
                cities.stream().collect(groupingBy(city -> city.pref));
        
        for (List<City> list : map.values()) {
            list.sort((c1, c2) -> c1.since - c2.since);
            
            for (int i = 1; i <= list.size(); i++) {
                list.get(i-1).no = i;
            }
        }
        
        PrintWriter out = new PrintWriter(System.out);
        for (City city: cities) {
            out.println(String.format("%06d%06d", city.pref, city.no));
        }
        out.flush();
    }
    
    static class City {
        int pref;
        int since;
        int no;
        
        public City(int pref, int since) {
            this.pref = pref;
            this.since = since;
        }
    }

    private static long nlong() {
        return sc.nextLong();
    }

    private static int nint() {
        return sc.nextInt();
    }

    private static String nstr() {
        return sc.next();
    }

    private static char[] nsToChars() {
        return sc.next().toCharArray();
    }

    private static long[] nlongs(int n) {
        return nlongs(n, 0, 0);
    }

    private static int[] nints(int n) {
        return nints(n, 0, 0);
    }

    private static int[] nints(int n, int padL, int padR) {
        int[] a = new int[padL + n + padR];
        for (int i = 0; i < n; i++)
            a[padL + i] = nint();
        return a;
    }

    private static long[] nlongs(int n, int padL, int padR) {
        long[] a = new long[padL + n + padR];
        for (int i = 0; i < n; i++)
            a[padL + i] = nlong();
        return a;
    }

    private static String[] nstrs(int n) {
        String[] a = new String[n];
        for (int i = 0; i < n; i++)
            a[i] = nstr();
        return a;
    }

    private static char[][] nsToChars2D(int h, int w) {
        return nsToChars2D(h, w, 0);
    }

    private static char[][] nsToChars2D(int h, int w, int pad) {
        char[][] a2 = new char[h + pad * 2][w + pad * 2];
        for (int i = 0; i < h; i++)
            System.arraycopy(nsToChars(), 0, a2[pad + i], pad, w);
        return a2;
    }
}


Measured memory_bytes: 163924
import itertools
N, M = [int(_) for _ in input().split()]
KS = [[int(_) - 1 for _ in input().split()] for _ in range(M)]
P = [int(_) for _ in input().split()]
ans = 0
for switches in itertools.product(range(2), repeat=N):
    f = all(
        sum(switches[s] for s in ks[1:]) % 2 == P[i]
        for i, ks in enumerate(KS))
    ans += f
print(ans)


Measured memory_bytes: 9144
#include<bits/stdc++.h>
#define llenar(a,val)   memset(a,val,sizeof(a))
#define pb          push_back 
#define endl        "\n"
#define mostrar(x,y) cout<<x<<" "<<y<<endl;
#define f           first
#define s           second
#define mod         1000000007
#define EPS         1e-9
using namespace std;
typedef pair<int,int> ii;
typedef pair<pair<int,int>,int> iii;
typedef vector<int> vi;
typedef vector<pair<int,int>> vii;
typedef long long ll;
typedef vector< pair<pair<int,int>,int> > viii;




int main(){
    ofstream out("output.txt");
    
    int n;
    cin>>n;

    int a[n];
    for(int i =0;i<n;i++) a[i] = 0;
    int b[n-1];
    for(int i =0;i<n-1;i++) cin>>b[i];
    ll total = 0;
    for(int i =0;i<n-1;i++){
        if(i == 0) total += 2*b[i];
        else {
            if(b[i]<b[i-1]){
                total -= b[i-1];
                total += 2*b[i];
            }
            else{
                total += b[i];
            }
        }
        //cout<<i<<" "<<total<<e7ndl;
    }

    cout<<total<<endl;
    return 0;
}

 
 







Measured memory_bytes: 256
import collections
 
n = int(input())
ln = list(map(int, input().split()))
m = int(input())
lm = list(map(int, input().split()))
 
c1 = collections.Counter(lm)
c2 = collections.Counter(ln)
 
for i in c1.keys():
    if c2[i] < c1[i]:
        print("NO")
        exit()
 
print("YES")

Measured memory_bytes: 57056
#include<bits/stdc++.h>
#define ios ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ll long long
#define hell 1000000007
#define hell1 1000000006
#define pb push_back
#define x first
#define y second
#define MAXL 100005
#define pll pair<ll,ll>
#define L 1000000000
using namespace std;
//vector<ll>prime(15000002,0);
ll mM(ll a,ll b,ll mod){ll res = 0;a %= mod;while(b){if (b & 1)res = (res + a) % mod;a = (2 * a) % mod;b >>= 1;}return res;}
ll fpow(ll x,ll y,ll p){x=x%p;ll res=1;while(y){if(y&1)res=(res*x)%p;res%=p;if(res<0)res=(res+p)%p;y=y>>1;x=(x*x)%p;if(x<0)x=(x+p)%p;x%=p;}return res;}
ll inv(ll n,ll p){return fpow(n,p-2,p);}
ll modmul(ll x,ll y){return (x*y)%hell;}
ll modadd(ll x,ll y){if(x>=hell)x-=hell;if(y>=hell)y-=hell;ll temp=x+y;if(temp>=hell)temp-=hell;if(temp<0)temp = temp+hell;return temp;}
/*void sieve(){
	prime[1] = 1;
	for(ll i=2;i<=15000000;i++)
		if(!prime[i])
			for(ll j=i;j<=15000000;j+=i)
				if(!prime[j])
					prime[j] = i;
}*/
int main(){
	ios
	ll t = 1;
	//cin >> t;
	//sieve();
	while(t--)
	{
		ll n;
		cin >> n;
		vector<ll>a(n),b(n),c(n);
		for(int i=0;i<n;i++)
			cin >> a[i] >> b[i] >> c[i];
		ll dp[n][3] = {{0}};
		dp[0][0] = a[0];
		dp[0][1] = b[0];
		dp[0][2] = c[0];
		for(int i=1;i<n;i++)
		{
			dp[i][0] = max(dp[i-1][1],dp[i-1][2]) + a[i];
			dp[i][1] = max(dp[i-1][0],dp[i-1][2]) + b[i];
			dp[i][2] = max(dp[i-1][0],dp[i-1][1]) + c[i];	
		}
		cout << max(dp[n-1][2],max(dp[n-1][0],dp[n-1][1])) << "\n";
	}
}


Measured memory_bytes: 4992
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long LL;
typedef pair<LL,LL> P;
const LL mod=1e9+7;
const LL LINF=1LL<<62;
const int INF=1<<30;

string u="10";

int main(){
    string s;cin >> s;
    int t=0,ans=INF;
    for (int i = 0; i < s.length(); i++) {
        if(s[i]!=u[i%2]) t++;
    }
    ans = min(ans,t);
    t=0;
    for (int i = 0; i < s.length(); i++) {
        if(s[i]==u[i%2]) t++;
    }
    ans = min(ans,t);
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < n; i++)
using P = pair <int, int>;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
ll gcd(ll a,ll b) {return  b ? gcd(b,a%b) : a;}
const long long INF = 1LL << 60;
const int mod = 1000000007;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};

int main () {
    ll a,b,n;
    cin >> a >>b >>n;
    ll ans = min((b-1),n)*a/b-a*(min((b-1),n)/b);
    cout << ans <<endl;
}

Measured memory_bytes: 3560
list = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]

num = int(input()) - 1
print(list[num])

Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <algorithm>
using ll = long long;
#define rep(i, n) for (ll i = 0; i < (n); i++)
using namespace std;

int main(){
  int n;
  cin >> n;
  vector<int> p(n);
  rep(i, n) cin >> p[i];
  vector<int> q(p);
  sort(q.begin(), q.end());
  int count = 0;
  rep(i, n){
    if (p[i] == q[i]) count++;
  }
  if (count >= n-2) cout << "YES" << endl;
  else cout << "NO" << endl;
  
  return 0;
}

Measured memory_bytes: 3576
def flatten(lst):
    result=[]
    for i in lst:
        if type(i) != list:
            result.append(i)
        else:
            #resultを上書きしないようにextendを使用
            result.extend(flatten(i))
    return result

import numpy as np
from sys import stdin
a=[]
for i in range(3):
    a.append([(x) for x in stdin.readline().rstrip().split()])

if len(set(flatten(a))) !=4:
    print("NO")

else:
    if flatten(a).count("1") < 3 and flatten(a).count("2") < 3 and flatten(a).count("3") < 3 and flatten(a).count("4") < 3 :
        print ("YES")
    else:
        print("NO")

Measured memory_bytes: 21288
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(int i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
using ll = long long;
using P = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
using vd = vector<double>;
vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1};

int main() {
  ll x, n;
  cin >> x >> n;
  vb e(110, true);
  rep(i, n) {
    ll p;
    cin >> p;
    e[p] = false;
  }
  ll ans = x, mn = 1e9;
  rep(i, 110) {
    if(e[i] && mn > abs(x - i)) {
      ans = i;
      mn = abs(x - i);
    }
  }
  cout << ans << endl;
}

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

#define pout(n)  printf ("%d\n", n)
#define rep(i,a,n) for (int i = a;i < n;i++)
#define per(i,n,a) for (int i = n-1;i >= a;i--)
 
typedef long long ll;
using namespace std;
 
int main (){
  int h,w;
  cin >> h >> w;
  char b[h+2][w+2];

  rep(i,0,h+2){
    rep(j,0,w+2){
      b[i][j] = '#';
    }
  }

  rep(i,0,h){
    rep(j,0,w){
      cin >> b[i+1][j+1];
    }
  }
  
  rep(i,0,h+2){
    rep(j,0,w+2){
      printf("%c",b[i][j]);
    }
    printf("\n");    
  }
  return 0;
}

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

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n"

using namespace std;
using ll = long long;

void solve()
{
  int k;
  cin >> k;

  if (k % 2 == 0)
  {
    cout << -1;
    return;
  }

  ll num = 0;
  for(int i = 1; i <= k; ++i)
  {
    num = num * 10 + 7;
    num %= k;
    if (num == 0)
    {
      cout << i;
      return;
    }
  }  
  cout<< -1;
}

int main()
{
  fastio;
  solve();

  return 0;
}

Measured memory_bytes: 3608
#include <bits/stdc++.h>
#define ref1(i,s,e,c) for(int i=s;i<e;i=i+c)
#define ref2(i,s,e,c) for(int i=s;i<=e;i=i+c)
#define ref3(i,e,s,c) for(int i=e;i>=s;i=i-c)
using namespace std;
typedef long long ll;
const int MAXSIZE=100005;
bool cmp(const int &a,const int &b){
	if(a%10>b%10){
		return true;
	}
	else return false;
}
int main()
{
    int arr[5],num=5,sum=0;
    ref1(i,0,num,1){
    	cin>>arr[i];
    	if(arr[i]%10==0){
    		sum+=arr[i];
    		num--;
    		i--;
		}
	}
	sort(arr,arr+num,cmp);
	ref1(i,0,num,1){
		if(i<num-1){
			arr[i]+=10-arr[i]%10;
		}
		sum+=arr[i];
	}
	cout<<sum;
    return 0;
}

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

int main() {
  int H,W;
  cin >> H >> W ;
  for(int i=0;i<W+2;i++){
    cout << "#";
  }
  cout << endl;
  vector<string> pic(H);
  for(int i=0;i<H;i++){
    cin >> pic.at(i);
    cout << "#" << pic.at(i) << "#" << endl;
  }
   for(int i=0;i<W+2;i++){
    cout << "#";
  }
}


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

int main() {
    int N;
    cin >> N;
    map<string, int> paper;
    int max_num = 0;
    for(int i = 0; i < N; i++) {
        string S;
        cin >> S;
        paper[S]++;
        max_num = max(max_num, paper[S]);
    }
    set<string> word;
    for(auto itr = paper.begin(); itr != paper.end(); itr++) {
        if(itr->second == max_num) {
            word.insert(itr->first);
        }
    }
    for(auto itr = word.begin(); itr != word.end(); itr++) {
        cout << *itr << endl;
    }
    return 0;
}

Measured memory_bytes: 34560
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N, Sp = 0, Sw = 0, Sg = 0, Sy = 0;

  cin >> N;

  vector<char> vec(N);

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

      if(vec.at(i) == 'P'){
          Sp++;
      }
      else if(vec.at(i) == 'W'){
          Sw++;
      }
      else if(vec.at(i) == 'G'){
          Sg++;
      }
      else if(vec.at(i) == 'Y'){
          Sy++;
      }
  }

  if(Sp > 0 && Sw > 0 && Sg > 0 && Sy == 0){
      cout << "Three" << endl;
  }
  else if(Sp > 0 && Sw > 0 && Sg > 0 && Sy > 0){
      cout << "Four" << endl;
  }
  else{
    cout << "error" << endl;
  }



}


Measured memory_bytes: 256
/********************/
/* K B G D E L T A */
/*     DA-IICT      */
/********************/
 
#include<bits/stdc++.h>
using namespace std;
using   ll=long long;
using   ld=long double;
#define fast           ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define endl           "\n"
#define F(i,n)         for(ll i=0;i<n;i++)
#define rep(i,a,b)     for(ll i=a;i<b;i++)
#define repp(i,a,b)    for(ll i=a;i>=b;i--)
#define pb             push_back
#define mp             make_pair
#define vll            vector<ll>
#define f              first
#define s              second
#define pll            pair<ll,ll>
#define ALL(v)         v.begin(),v.end()
#define ALLR(v)        v.rbegin(),v.rend()
#define pii            3.14159265358979323
#define mod            1000000007
#define N              100001
 
void solve()
{
    ll n,sum=0;

    cin>>n;

    vll a(n,1e5);

    vector<pll> b(n-1);

    F(i,n-1)
    {
        cin>>b[i].f;

        b[i].s=i;
    }

    sort(ALL(b));

    F(i,n-1)
    {
        a[b[i].s]=min(a[b[i].s],b[i].f);
        a[b[i].s+1]=min(a[b[i].s+1],b[i].f);
    }

    F(i,n)
    {
        sum+=a[i];
    }

    cout<<sum;
}
 
signed main(){
 
    fast;
 
    ll t=1;
 
    //cin>>t;
 
    while(t--)
    {
        solve();
    }
 
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long int
#define booga cout << "booga" << endl
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
using namespace std;


int main(int argc, char** argv){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin >> n;
	vector<int> l(n);
	for(int i{0};i < n;i++){
		cin >> l[i];
	}
	sort(l.begin(),l.end());
	int ans{0};
	for(int sec{1};sec < n;sec++){
		for(int thir{sec+1};thir < n;thir++){
			auto find = lower_bound(l.begin(),l.begin()+sec,l[thir]-l[sec]+1);
			ans += (l.begin() + sec - find);
		}
	}
	cout << ans << "\n";
	return 0;
}



Measured memory_bytes: 256
use std::cmp::Ordering;
use std::str::FromStr;
use std::io;

fn main() {

	let mut line = String::new();
	io::stdin().read_line(&mut line);
	let split : Vec<&str> = line.split(' ').collect(); 

	let x = i32::from_str(split[0].trim()).unwrap();
	let a = i32::from_str(split[1].trim()).unwrap();
	let b = i32::from_str(split[2].trim()).unwrap();

	let xa = (a - x).abs();
	let xb = (b - x).abs();

	match xa.cmp(&xb) {
        Ordering::Less    => println!("A"),
        Ordering::Greater => println!("B"),
        Ordering::Equal => println!("Invalid"),
    }
}


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

using namespace std;


int main()
{
	int k;
	string str;
	cin >> str;
	cin >> k;
	int n = str.length();
	set<string> strMap;
	vector<string> strVec;
	//cout << str.substr(1, 2) << endl;
	for (int i = 0; i < n; i++) {
		for (int j = 1; j <= (n-i); j++) {
			//cout << i << " " << j << " "<<str.substr(i, j) << endl;
			if(strVec.size() >= k && strVec[k-1] < str.substr(i,j)){
				break;
			}
			if( strMap.count(str.substr(i,j)) == 0){
				strMap.insert(str.substr(i, j));
				strVec.push_back(str.substr(i,j));
			}
			sort(strVec.begin(),strVec.end());
		}
	}
	sort(strVec.begin(), strVec.end());
	cout << strVec[k-1] << endl;
	return 0;
}


Measured memory_bytes: 256
let sentinel = 1000000001
let cnt = ref 0

let to_int_list str =
  Str.split (Str.regexp_string " ") str |> List.map int_of_string

let merge a l m r =
  let ni = m - l in
  let nj = r - m in
  let init_ary n p =
    Array.init (n + 1) (fun i -> if i = n then sentinel else a.(p + i))
  in
  let ai = init_ary ni l in
  let aj = init_ary nj m in
  let rec doit i j k =
    if k >= r then ()
    else begin
      if ai.(i) <= aj.(j) then (a.(k) <- ai.(i); doit (i + 1) j (k + 1))
      else (a.(k) <- aj.(j); cnt := !cnt + (ni - i); doit i (j + 1) (k + 1))
    end
  in
  doit 0 0 l

let rec merge_sort a l r =
  if (l + 1) < r then begin
    let m = (l + r) / 2 in
    merge_sort a l m;
    merge_sort a m r;
    merge a l m r
  end

let () =
  let n = read_int () in
  let a = Array.of_list (to_int_list (read_line ())) in
  merge_sort a 0 n;
  Printf.printf "%d\n" !cnt

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

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

#define FOR(i, n, m) for (ll(i) = (m); (i) < (n); ++(i))
#define REP(i, n) FOR(i, n, 0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll)1e15;

ll A[100005];

int main()
{
    ll N, M;
    cin >> N >> M;
    priority_queue<ll, vector<ll>, function<bool(ll, ll)>> q([](ll a, ll b) { return a < b; });
    REP(i, N)
    {
        ll a;
        cin >> a;
        q.push(a);
    }

    REP(i, M)
    {
        ll t = q.top();
        q.pop();
        q.push(t / 2);
    }

    ll sum = 0;
    while (!q.empty())
    {
        ll t = q.top();
        q.pop();
        sum += t;
    }
    cout << sum << endl;
    return 0;
}

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


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

int main() {
    ll q,h,s,d,n;
    cin>>q>>h>>s>>d>>n;
    cout<<(n/2) * min(8*q,min(4*h,min(2*s,d))) + (n%2) * min(4*q,min(2*h,s));
}

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

#define LL long long
#define LD long double
#define SC(t,x) static_cast<t>(x)
#define AR(t) vector < t >
#define PII pair < int, int >
#define PLL pair < LL, LL >
#define PIL pair < int, LL >
#define PLI pair < LL, int >
#define MP make_pair
#define PB push_back
#define PF push_front
#define POB pop_back
#define POF pop_front
#define PRF first
#define PRS second
#define INIT(ar,val) memset ( ar, val, sizeof ( ar ) )
#define lp(loop,start,end) for ( int loop = start; loop < end; ++loop )
#define lpd(loop,start,end) for ( int loop = start; loop > end; --loop )
#define lpi(loop,start,end) for ( int loop = start; loop <= end; ++loop )
#define lpdi(loop,start,end) for ( int loop = start; loop >= end; --loop )
#define qmax(a,b) (((a)>(b))?(a):(b))
#define qmin(a,b) (((a)<(b))?(a):(b))
#define qabs(a) (((a)>=0)?(a):(-(a)))

const int INF = 0x3fffffff;
const int SINF = 0x7fffffff;
const long long LINF = 0x3fffffffffffffff;
const long long SLINF = 0x7fffffffffffffff;
const int MAXN = 100007;

int n;
int a[MAXN];

void init ();
void input ();
void work ();



int main()
{
	init();
	input();
	work();
}



void init ()
{
	// Init Everything Here

	ios::sync_with_stdio ( false );
}

void input ()
{
	// input method

	scanf ( "%d", &n );
	lpi ( i, 1, n ) scanf ( "%d", &a[i] );
}

void work ()
{
	// main work

	int la = a[1], tag = 0, ans = 0;
	lpi ( i, 2, n ){
		if ( !tag ){
			if ( a[i] ^ la ){
				tag = ( a[i] > la ) ? 1 : -1;
			}
		} else if ( ( a[i] ^ la ) && ( ( ( a[i] > la ) ? 1 : -1 ) ^ tag ) ){
			tag = 0;
			++ans;
		}
		la = a[i];
	}
	++ans;
	printf ( "%d\n", ans );
}

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

#define INF 1234567890
#define ll long long

string s;

bool f(int l, int r)
{
	for(int i=l; i<=r; i++)
	{
		if (s[i] != s[r-(i-l)])
			return false;
	}
	return true;
}

int main()
{
	cin >> s;
	int N = s.size();
	s = ' ' + s;
	if (f(1, N) && f(1, (N-1)/2) && f((N+3)/2, N))
		cout << "Yes";
	else cout << "No";
	return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {

	static int[] S ;
	public static void main(String[] args) throws Exception {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		String W = in.readLine();
		int N = Integer.parseInt(W);


		System.out.println(N/2+N%2);
	}


}


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

int main() {
	char str[105];
  	cin>>str;
  int n=strlen(str);
  if(n%2==0)
    cout<<"No";
  else
  {
    for(int i=0;i<n/2;i++)
    {
      if(str[i]!=str[n-i-1])
      {
        cout<<"No";
        return 0;
      }
    }
    for(int i=0;i<=(n/2)/2;i++)
    {
      if(str[i]!=str[(n/2)-i-1])
      {
        cout<<"No";
        return 0;
      }
    }
    
  }
  cout<<"Yes";
	return 0;
}

Measured memory_bytes: 256
using System;

namespace ITP1
{
    class Program
    {
        static void Main(string[] args)
        {

            string[] input = Console.ReadLine().Split(' ');
            int W = int.Parse(input[0]);
            int H = int.Parse(input[1]);
            int x = int.Parse(input[2]);
            int y = int.Parse(input[3]);
            int r = int.Parse(input[4]);

            if (x-r < 0 | x+r > W | y-r < 0 | y+r > H)
            {
                Console.WriteLine("No");
            }
            else
            {
                Console.WriteLine("Yes");
            }

        }
    }
}

Measured memory_bytes: 8964
N = int(input())
h = list(map(int, input().split(" ")))

cost = 0
cost_1 = 0
cost_2 = 0

cost_1 = abs(h[-1] - h[-2])
cost = cost_1

for i in range(N-2):
    j = N-3-i
    cost = min(cost_1 + abs(h[j+1] - h[j]),
                cost_2 + abs(h[j+2] - h[j]))
    cost_2 = cost_1
    cost_1 = cost

print(cost)


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

const int u=2e5+5;
vector<int> adj[u];

int arr[u]={0};

bool mark[u];
void dfs(int v,int c){
    mark[v]=1;
    arr[v]+=c;
    for(int i:adj[v]){
        if(!mark[i]){
            dfs(i,arr[v]);
        }
    }
    return;
}

int32_t main(){
    ios_base::sync_with_stdio(false);cin.tie(NULL);
    
    int n,q;
    cin>>n>>q;
    for(int i=1;i<n;i++){
        int x,y;
        cin>>x>>y;
        adj[x].push_back(y);
        adj[y].push_back(x);
    }

    while(q--){
        int p,x;
        cin>>p>>x;
        arr[p]+=x;        
    }

    dfs(1,0);

    for(int i=1;i<=n;i++){
        cout<<arr[i]<<" ";
    }
    cout<<endl;

    return 0;
}

Measured memory_bytes: 21376
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 998244353

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


def main():
    rr = []

    while True:
        n,m = LI()
        a = [I() for _ in range(m)][::-1]
        f = [None] * (n+1)
        for c in a:
            if f[c] is None:
                f[c] = 1
                rr.append(c)

        for c in range(1,n+1):
            if f[c] is None:
                rr.append(c)

        break



    return '\n'.join(map(str, rr))


print(main())




Measured memory_bytes: 37120
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll mod = 1e9 + 7;
const ll inf = (1 << 30) - 1;
const ll infll = (1LL << 61) - 1;

int N, ans;

int main()
{
    cin >> N;
    vector<int> V(N), C(N);
    for (int i = 0; i < N; i++)
    {
        cin >> V[i];
    }
    for (int i = 0; i < N; i++)
    {
        cin >> C[i];
    }
    for (int i = 0; i < N; i++)
    {
        int a = V[i] - C[i];
        if (a > 0)
            ans += a;
    }
    cout << ans << endl;
}

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

using namespace std;

int silly_sort(vector<int> v, int n){
	vector<pair<int, int> > temp(n);
	for (int i = 0; i < n; i++){
		temp[i].first = v[i];
		temp[i].second = i;
	}
	sort(temp.begin(), temp.end());

	int cost = 0, s = temp[0].first;
	for (int i = 0; i < n; i++){
		int j = temp[i].second;
		if (j != i && j >= 0){
			int n = 1, amin, sum;
			amin = sum = temp[i].first;
			while (j != i){
				int next = temp[j].second;
				sum += temp[j].first;
				n++;
				temp[j].second = -1;
				j = next;
			}
			cost += min(sum + (n - 2) * amin, sum + amin + (n + 1) * s);
		}
	}
	return cost;
}
int main(){
	int n;
	cin >> n;
	vector<int> v(n);
	for (int i = 0; i < n; i++) cin >> v[i];
	cout << silly_sort(v, n) << endl;
}

Measured memory_bytes: 3136
///
// File:  a.cpp
// Author: ymiyamoto
//
// Created on Sat Dec 23 21:41:27 2017
//

#include <cstdint>
#include <iostream>

using namespace std;

int32_t main()
{
  uint32_t A, B, C, D;
  cin >> A >> B >> C >> D;

  if (A + B == C + D) {
    cout << "Balanced" << endl;
  } else if (A + B < C + D) {
    cout << "Right" << endl;
  } else {
    cout << "Left" << endl;
  }

  return 0;
}


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

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

  vector<int> a(N);
  for_each(a.begin(), a.end(),
           [](auto &v){cin >> v;});

  long long all_sum = 0;
  for_each(a.begin(), a.end(),
           [&](auto v){all_sum += v;});

  long long partial_sum = 0;
  long long ans = 1e16;
  for(int i = 0; i < N - 1; i++){
    partial_sum += a[i];
    ans = min(ans, abs((all_sum - partial_sum) - partial_sum));
  }

  cout << ans << endl;
}



Measured memory_bytes: 1024
import sys
def input(): return sys.stdin.readline().strip()

def resolve():
    s1=input()
    s11=s1[::-1]
    s2=s1[:(len(s1)-1)//2]
    s22=s2[::-1]
    s3=s1[(len(s1)+3)//2-1:]
    s33=s3[::-1]
    if s1==s11 and s2==s22 and s3==s33:
        print('Yes')
    else:
        print('No')
resolve()

Measured memory_bytes: 3064
import java.io.IOException
import java.io.InputStream
import java.util.*

val scanner = FastScanner()

fun main() {
    val (a, b, c, k) = scanner.readIntArray(4)

    var x = k - a
    var res = 0
    if (k >= a) {
        res = a
        if (x > 0) {
            x -= b
            if (x > 0) {
                res -= x
            }
        }
    } else {
        res = k
    }
    println(res)
}

@Suppress("MemberVisibilityCanBePrivate")
class FastScanner {
    private val `in`: InputStream = System.`in`
    private val buffer = ByteArray(1024)
    private var ptr = 0
    private var buflen = 0
    private fun hasNextByte(): Boolean {
        if (ptr < buflen) {
            return true
        } else {
            ptr = 0
            try {
                buflen = `in`.read(buffer)
            } catch (e: IOException) {
                e.printStackTrace()
            }
            if (buflen <= 0) {
                return false
            }
        }
        return true
    }

    private fun readByte(): Int {
        return if (hasNextByte()) buffer[ptr++].toInt() else -1
    }

    operator fun hasNext(): Boolean {
        while (hasNextByte() && !isPrintableChar(buffer[ptr].toInt())) ptr++
        return hasNextByte()
    }

    operator fun next(): String {
        if (!hasNext()) throw NoSuchElementException()

        return buildString {
            var b = readByte()

            while (isPrintableChar(b)) {
                appendCodePoint(b)
                b = readByte()
            }
        }
    }

    fun nextLong(): Long {
        if (!hasNext()) throw NoSuchElementException()
        var n: Long = 0
        var minus = false
        var b = readByte()

        if (b == '-'.toInt()) {
            minus = true
            b = readByte()
        }

        if (b < '0'.toInt() || '9'.toInt() < b) {
            throw NumberFormatException()
        }

        while (true) {
            if ('0'.toInt() <= b && b <= '9'.toInt()) {
                n *= 10
                n += b - '0'.toInt().toLong()
            } else if (b == -1 || !isPrintableChar(b)) {
                return if (minus) -n else n
            } else {
                throw NumberFormatException()
            }

            b = readByte()
        }
    }

    fun nextInt(): Int {
        val nl = nextLong()
        if (nl < Int.MIN_VALUE || nl > Int.MAX_VALUE) throw NumberFormatException()
        return nl.toInt()
    }

    fun nextDouble(): Double {
        return next().toDouble()
    }

    fun readIntArray(n: Int): IntArray {
        val arr = IntArray(n)

        for (i in 0 until n) {
            arr[i] = nextInt()
        }

        return arr
    }

    companion object {
        private fun isPrintableChar(c: Int): Boolean {
            return c in 33..126
        }
    }
}


Measured memory_bytes: 33988
#define _USE_MATH_DEFINES

#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <utility>
#include <climits>
#include <vector>
#include <map>
#include <queue>
#include <set>
using namespace std;

#define ll long long
const int MOD = 1000000007;//10^9+7
const string SPACE = " ";

ll powsur(ll a, ll b, ll p) {

	if (b == 0) {

		return 1;

	}
	else if (b % 2 == 0) {

		ll d = powsur(a, b / 2, p);
		return ((d%p)*(d%p)) % p;

	}
	else {

		return ((a%p)*powsur(a, b - 1, p) % p) % p;

	}

}
//pは素数,aのb乗をpで割った余り

ll CMOD(ll n, ll r, ll p) {

	ll a = 1, b = 1, c = 1, re;
	for (int i = 1; i <= n; i++) {

		a *= i;
		a = a%p;

	}
	for (int i = 1; i <= r; i++) {

		b *= i;
		b = b%p;

	}
	for (int i = 1; i <= n - r; i++) {

		c *= i;
		c = c%p;

	}
	b = powsur(b, p - 2, p);
	c = powsur(c, p - 2, p);
	re = ((a%p)*(b%p)) % p;
	re = ((re%p)*c%p) % p;

	return re;

}
//pは素数,(nCr)%p

ll gcd(ll a, ll b) {

	if (a > b) {

		ll tmp = a;
		a = b;
		b = tmp;

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

}
//最大公約数

ll lcm(ll a, ll b) {

	return (a / gcd(a, b))*b;

}
//最小公倍数

ll MAX(ll a, ll b) {

	if (a > b)return a;
	else return b;

}
//MAX

ll MIN(ll a, ll b) {

	if (a < b)return a;
	else return b;

}
//MIN

bool p_judge(ll p) {

	if (p == 1)return false;
	else if (p == 2)return true;
	else {

		bool flag = true;
		for (int i = 2; i <= sqrt(p); i++) {

			if (p%i == 0) {

				flag = false;
				break;

			}

		}
		return flag;

	}

}
//素数判定,素数=true,合成数=false

ll func(ll num) {

	ll cnt = 0;
	while (num % 2 == 0) {

		cnt++;
		num /= 2;

	}
	return cnt;

}

int main() {

	int N;
	ll A[205], ans = 1000000000;

	cin >> N;
	for (int i = 0; i < N; i++) {

		cin >> A[i];
		ans = MIN(ans, func(A[i]));

	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
n,k=map(int,input().split())

mod=10**9+7
ans=0
for x in range(k,n+2):
  min_a=(0+x-1)*x//2
  max_a=(n-x+1+n)*x//2
  aa=max_a-min_a+1
  ans+=aa
  
print(ans%mod)

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

int main()
{
    int a,b;
    cin >> a >> b;
    if(a < 9 && b < 9 && a + b <= 16){
        cout << "Yay!";
    }
    else {
        cout << ":(";
    }
    return 0;
}


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

using namespace std;

int main(void){
  int x, y;
  cin >> x >> y;
  
  int ans[] = {0, 2, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0};

  if(ans[x-1] == ans[y-1]) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define rep2(i,x,n) for(int i=x; i<(n); i++)
#define all(n) begin(n),end(n)
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
const long long INF = numeric_limits<long long>::max();
int main(){
    double A,B,H,M;
    cin>>A>>B>>H>>M;
    double minute=H*60.00000000000+M;//何分経った？
    const double pi=3.14159265358979323846;
    double Atheta,Btheta;//それぞれの角度
    Atheta=(2.0000000*pi*minute)/720.00000000;
    Btheta=(2.000000*pi*M)/60.00000000;
    //二つの座標は(Acos,Asin)と(Bcos,Bsin)よりその距離を求めれば終わり
    
    double ans=sqrt(A*A+B*B-2*A*B*cos(Atheta-Btheta));
    cout << fixed << setprecision(15) << ans << endl;
    return 0;
}

Measured memory_bytes: 4244
#include <bits/stdc++.h>
#define err(args...) {}
#ifdef DEBUG
#include "_debug.cpp"
#endif
using namespace std;
using ll = long long;
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n, m;
    cin >> n >> m;
    vector<ll> a(n + 1);
    for(int i = 1; i <= n; i++) {
        cin >> a[i];
    }
    vector<ll> rsq(n + 1);
    partial_sum(a.begin(), a.end(), rsq.begin());
	map<ll, int> counter;
    counter[0] = 1;
    ll ans = 0;
    for(int i = 1; i <= n; i++) {
        ans += counter.count(rsq[i] % m) ? counter[rsq[i] % m] : 0;
        counter[rsq[i] % m]++;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 5760
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)a;i<(int)b;++i)
int main(){
    int n;cin>>n;
    string s,t;cin>>s>>t;
    string ans="";
    rep(i,s.size()){
        ans+=s[i];
        ans+=t[i];
    }
    cout<<ans<<endl;
    return 0;
}

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

int32_t main(){
    ios::sync_with_stdio(0);cin.tie(0);
    
    int n,k,c=0;
    cin>>n>>k;
    for(int i=0;i<n;i++){
        int x;
        cin>>x;
        if(x>=k){
            c++;
        }
    }
    cout<<c;

    return 0;
}

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

int main() {
    int a, b, c, tmp;

    cin >> a >> b >> c;

    if (a > b) {
        tmp = a;
        a = b;
        b = tmp;
    }

    if (b > c) {
        tmp = b;
        b = c;
        c = tmp;
    }

    if (a > b) {
        tmp = a;
        a = b;
        b = tmp;
    }

    cout << a << " " << b << " " << c << endl;

    return 0;
}


Measured memory_bytes: 3100
while True:
    x,y=map(int,input().split())
    if x == 0 and y == 0:
        break
    if  y > x:
     print(str(x)+' '+str(y))
    elif x > y:
     print(str(y)+' '+str(x))
    
    else:
      print(str(x)+' '+str(y))




Measured memory_bytes: 5616
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
struct QQ{
    int a;
    int b;
    int c;
    int d;
}S[10050];
int arr[10050];
int main(){
    int n,m,q;
    ll ans=0;
    scanf("%d%d%d",&n,&m,&q);
    for(int i=1;i<=q;i++){
        scanf("%d%d%d%d",&S[i].a,&S[i].b,&S[i].c,&S[i].d);
    }

    for(int i=1;i<=q;i++) arr[i]=1;
    while(arr[0]==0){
        ll anss=0;
        for(int i=1;i<=q;i++){
          if(arr[S[i].b]-arr[S[i].a]==S[i].c)
          anss+=(ll) S[i].d;
        }
        ans=max(ans,anss);
        for(int i=n;i>=0;i--){
            if(arr[i]<m){
                arr[i]++;
                for(int j=i+1;j<=n;j++) arr[j]=arr[j-1];
                break;
            }
        }
    }
    printf("%lld",ans);
}


Measured memory_bytes: 3792
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
using namespace std;
int main() {
    int N, K, sum = 0; cin >> N >> K;
    vector<int> P(N, 0);
    for (int i = 0; i < N; i++) cin >> P[i];
    sort(P.begin(), P.end());
    for (int i = 0; i < K; i++) sum += P[i];
    printf("%d\n", sum);
}


Measured memory_bytes: 3604
#include <iostream>
#include <string>
#include <cstdlib>
#include <algorithm>
#include <bitset>
#include <vector>
#include <set>
using namespace std;

int main(){
    int N, M, all=0;
    cin >> N >> M;

    vector<vector<int>> A(40, vector<int>(40));

    vector<int> ans(40);

    for(int i = 0; i < N; i++){
        int K;
        cin >> K;
        for(int j = 0; j < K; j++){
            cin >> A.at(i).at(j);
            int tmp = A.at(i).at(j);
            ans.at(tmp)++;
        }
    }

    for(int i = 0; i < ans.size(); i++){
        if(ans.at(i) == N){
            all++;
        }
    }
    cout << all << endl;

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int N=200005;
ll a[N],c[N];
ll b[N];
ll sum;
int main(){
	int n,x;
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>x;
		c[i]=x;
		a[x]++;
	}
	for(int i=1;i<=n;i++)
	{
	  sum+=(a[i]-1)*a[i]/2; 	
	}
	for(int i=1;i<=n;i++)
	{
	  if(a[c[i]]<=1) cout<<sum<<endl;
	  else
	     cout<<sum-a[c[i]]+1<<endl;	
	}
	return 0;
} 

Measured memory_bytes: 5248
import numpy as np
N = int(input())
a = np.array(list(map(int, input().split())), dtype=int)
b = a - np.arange(1, N + 1)
b.sort()
if N % 2 == 0:
    bb = (b[N // 2 - 1] + b[N // 2]) // 2
else:
    bb = b[N // 2]
print(np.sum(np.abs(b - bb)))

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

int main() {
  int N, M;
  cin >> N >> M;
  
  vector<int> vec(N);
  for(int i = 0; i < M; i++){
    int x, y;
    cin >> x >> y;
    vec.at(x-1) += 1;
    vec.at(y-1) += 1;
  }
  for(int i = 0; i < N; i++){
    cout << vec.at(i) << endl;
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(long long int i = 0; i < n; i++)
#define print(n) std::cout << n << std::endl
#define _print(n) std::cout << n
using namespace std;
typedef long long ll;
const int N = 1000000;

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

    int ans = 0;

    for (int i = 1; i < n; ++i) {
        int count = 0;
        for (char c = 'a'; c <= 'z'; c++){
            bool flag_left = false;
            bool flag_right = false;
            for (int j = 0; j < i; ++j) {
                if (s[j] == c)flag_left = true;
            }
            for (int j = i; j < n; ++j) {
                if (s[j] == c)flag_right = true;
            }
            if(flag_left && flag_right)count++;
        }
        ans = max(ans,count);
    }
    print(ans);
}

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

int main() {
    ll a,b,c,d;
    cin>>a>>b>>c>>d;
    ll ans =a*d;
    if(ans<a*c)
    ans=a*c;
    if(ans<b*c)
    ans=b*c;
    if(ans<b*d)
    ans=b*d;
    cout<<ans<<endl;
}

Measured memory_bytes: 3652
/**
 * @author: shashankchdhry
 * @made:   2020-04-05 12:14:49 
**/
#include <bits/stdc++.h>
#define ll long long 
using namespace std;

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

    int w, a, b;
    cin >> w >> a >> b;

    ll ans = abs(b-a)-w;
    cout << (ans>0?ans:0) << "\n";

    return 0;
}

Measured memory_bytes: 256
use std::io::prelude::*;
use std::io::stdin;
use std::str::FromStr;

fn main() {
    let a: i32 = read();
    let b: i32 = read();

    println!("{}", 6 - a - b);
}

#[allow(dead_code)]
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let token: String = stdin
        .lock()
        .bytes()
        .map(|b| b.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().unwrap()
}


Measured memory_bytes: 4352
#include<iostream>

using namespace std;

int main()
{
    int n,d;
    cin>>n;
    while(n)
    {
        d=n%10;
        n/=10;
        if(d==7)
        {
            cout<<"Yes"<<endl;
            return 0;
        }
    }
    cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 3104
import java.util.ArrayList;
import java.util.Scanner;

public class Main {

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

		ArrayList<Integer> nList = new ArrayList<Integer>();

		while (true) {
			n = sc.nextInt();
			if (n == 0)
				break;

			nList.add(n);
		}

		for (int i = 1; i <= nList.size(); i++) {
			System.out.println("Case " + i + ": " + nList.get(i - 1));
		}

	}
}

Measured memory_bytes: 43756