akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define Rep(i,n) for(int i=0;i<(int)(n);i++)
#define For(i,n1,n2) for(int i=(int)(n1);i<(int)(n2);i++)
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define RREP(i,n) for(ll i=((ll)(n)-1);i>=0;i--)
#define FOR(i,n1,n2) for(ll i=(ll)(n1);i<(ll)(n2);i++)
#define RFOR(i,n1,n2) for(ll i=((ll)(n1)-1);i>=(ll)(n2);i--)
#define all(a)  (a).begin(),(a).end()
#define SORT(a) sort((a).begin(),(a).end())
#define oorret 0
#define oor(x) [&](){try{x;} catch(const out_of_range& oor){return oorret;} return x;}()
#define IOS cin.tie(0),ios::sync_with_stdio(false)
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
template<typename T1, typename T2> inline bool chmin(T1& a, T2 b) { if (a > b) { a = b; return 1; }return 0; }
template<typename T1, typename T2> inline bool chmax(T1& a, T2 b) { if (a < b) { a = b; return 1; }return 0; }
template<class Type>struct is_vector : std::false_type {};
template<class ValueType, class Alloc>struct is_vector<std::vector<ValueType, Alloc>> : std::true_type {};
template <typename T> inline ostream& operator << (ostream& out, const vector<T>& v) {
	if (v.empty())return out;
	constexpr bool is_vector_v = is_vector<T>::value;
	if (is_vector_v)for (auto itr = v.begin(); itr != v.end();)out << (*itr), out << ((++itr != v.end()) ? "\n" : "");
	else for (auto itr = v.begin(); itr != v.end();)out << (*itr), out << ((++itr != v.end()) ? " " : "");
	return out;
}
inline void put() {}
template<class T> inline void put(const T& first) { std::cout << first << "\n"; }
template<class T, class... N> inline void put(const T& first, const N& ... rest) { std::cout << first << " "; put(rest...); }
inline void putn() {}
template<class T, class... N> inline void putn(const T& first, const N& ... rest) { std::cout << first << "\n"; putn(rest...); }


int main() {
	IOS;
	int n;
	cin >> n;
	vector<P> a(n);
	int res = 0;
	REP(i, n) {
		cin >> a[i].first;
		a[i].second = i+1;
	}
	sort(all(a));
	REP(i, n) {
		cout << a[i].second << " ";
	}
	put("");
	return 0;
}

Measured memory_bytes: 2432
#include <bits/stdc++.h>
#define r1(i, n) for (int i=0;i<n;i++)
#define r2(i, n) for (int i=1;i<n-1;i++)
#define intc(n) int n; cin >> n;
#define ll long long
#define llc(n) ll n; cin >> n;
using namespace std;
int main() {
  ll k,n,ans;
  cin >> k >> n;
  vector<ll> a(n),b(n),c(n);
  r1(i, n) {
    cin >> a.at(i);
    b.at(i)=a.at(i)+k;
  }
  ans=a.at(n-1)-a.at(0);
  r2(i,n) {
    ans=min(b.at(i)-a.at(i+1), ans);
  }
  cout << ans << endl;
}


Measured memory_bytes: 4992
#include<bits/stdc++.h>
#include<iomanip>
#define rep(i,n) for(int i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define yesno(flg) if(flg){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define MAX_N 1002
#define i197 1000000007

using namespace std;

typedef long long ll;
typedef pair<ll,ll> P1;
typedef pair<int,int> Pi;
typedef pair<double,Pi> Pdi;
typedef pair<ll,int>Pli;
typedef pair<P1,ll> P2;
const ll INF=1000000000000000001;
struct edge{int to,cost;};
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
struct Road{double cost;int a,b;};

int l[100001],r[100001];
int t[100001]={};

int main() {

	int n,m;
	int total=0;

	cin>>n>>m;
	rep(i,m){
		cin>>l[i]>>r[i];
		t[l[i]]++;
		t[r[i]+1]--;
	}
	for(int i=1; i<n+1; i++){
		t[i]+=t[i-1];
		if(t[i]==m)total++;
	}
	cout<<total<<endl;
	return 0;

}


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

const int MOD=1000000007;
//~ const int MOD=998244353;
const int INF=0x3f3f3f3f;
const ll INFL=0x3f3f3f3f3f3f3f3f;

vector<int>E[200000];
int main(){
	ll n;cin>>n;
	rep(i,n-1){
		int a,b;scanf("%d%d",&a,&b);a--;b--;
		E[a].push_back(b);E[b].push_back(a);
	}
	ll sum1=0;
	for(ll i=1;i<=n;i++){
		sum1+=i*(i+1)/2;
	}
	ll sum2=0;
	rep(i,n){
		for(int u:E[i]){
			if(i>u)continue;
			ll a=i,b=u;
			sum2+=(a+1)*(n-b);
		}
	}
	cout<<sum1-sum2<<endl;
}

Measured memory_bytes: 15136
import queue

INFTY=1<<21

#プリム法
def prim(n,EdgeMatrix):

    EdgeList=queue.PriorityQueue() #探索対象の辺
    used=[False]*n #頂点の使用情報

    used[0]=True #0から探索を始める
    LastNode=0 #最新の頂点
    count=1 #つないだ頂点の数
    EdgeSum=0 #重みの合計

    while count<n:

        for i in range(len(EdgeMatrix[LastNode])):
            #探索していない頂点へ辺があればキューに追加
            Edge=EdgeMatrix[LastNode][i]
            if used[Edge[0]]==False:
                EdgeList.put([Edge[1],Edge[0]])

        #探索していない頂点への最も重みの小さい辺を取り出す
        while True:
            minEdge=EdgeList.get()
            if used[minEdge[1]]==False:
                break

        EdgeSum+=minEdge[0] #辺の合計を増やす
        LastNode=minEdge[1] #最新の頂点を更新
        used[minEdge[1]]=True #頂点の使用情報を更新
        count+=1 #つないだ頂点の数を更新

    return EdgeSum


#入力
n=int(input())

#辺の隣接行列
EdgeMatrix=[[] for i in range(n)]
for i in range(n):
    l=list(map(int,input().split()))
    for j in range(n):
        if l[j]!=-1:
            EdgeMatrix[i].append([j,l[j]])
            EdgeMatrix[j].append([i,l[j]])

#最小全域木の重みの総和
print(prim(n,EdgeMatrix))



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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<pair<int,int>> vpii;

#define F first
#define S second
#define PU push
#define PUF push_front
#define PUB push_back
#define PO pop
#define POF pop_front
#define POB pop_back

#define REP(i,a,b) for(int i=a; i<=b; i++)

void solve(int test_case) {
	int n;
	cin>>n;
	vi arr(n);
	ll sum=0;
	for(int &i:arr)cin>>i,sum+=i;
	sum=round(sum/(float)n);
	ll req = 0;
	for(int &i:arr) {
		req+=(i-sum)*(i-sum);
	}
	cout<<req;
}

int main() {
	
	////// FILE BASED IO////
	//freopen("in", "r", stdin);
	//freopen("out", "w", stdout);
	///////////////
	
	ios::sync_with_stdio(0);
	cin.tie(0);
	int t=1;
	//cin>>t;
	REP(i,1,t) {
		solve(i);
	}
}	


Measured memory_bytes: 3644
//==========================================================================
//
//                   Bismillahir-Rahmanir-Rahim
//
// ==========================================================================
#include <bits/stdc++.h>
#define        ll                              long long int
#define        f(x,y,z)                        for(int x=y;x<z;x++)
#define        pii                             pair<int,int>
#define        pll                             pair<ll,ll>
#define        CLR(a)                          memset(a,0,sizeof(a))
#define        SET(a)                          memset(a,-1,sizeof(a))
#define        N                               100010
#define        M                               1000000007
#define        pi                              acos(-1.0)
#define        ff                              first
#define        ss                              second
#define        pb                              push_back
#define        inf                             (int)1e9
#define        eps                              1e-9
using namespace std;
int dx[]={0,0,1,-1,-1,-1,1,1};
int dy[]={1,-1,0,0,-1,1,1,-1};
template < class T> inline T biton(T n,T pos){return n |((T)1<<pos);}
template < class T> inline T bitoff(T n,T pos){return n & ~((T)1<<pos);}
template < class T> inline T ison(T n,T pos){return (bool)(n & ((T)1<<pos));}
template < class T> inline T gcd(T a, T b){while(b){a%=b;swap(a,b);}return a;}
template <typename T> string NumberToString ( T Number ) { ostringstream ss; ss << Number; return ss.str(); }
inline int nxt(){int aaa;scanf("%d",&aaa);return aaa;}
inline ll lxt(){ll aaa;scanf("%lld",&aaa);return aaa;}
inline double dxt(){double aaa;scanf("%lf",&aaa);return aaa;}
template <class T> inline T bigmod(T p,T e,T m){T ret = 1;
for(; e > 0; e >>= 1){
    if(e & 1) ret = (ret * p) % m;p = (p * p) % m;
} return (T)ret;}
#define sayed
#ifdef sayed
     #define debug(args...) {cerr<<"Debug: "; dbg,args; cerr<<endl;}
#else
    #define debug(args...)  // Just strip off all debug tokens
#endif
struct debugger{
    template<typename T> debugger& operator , (const T& v){
        cerr<<v<<" ";
        return *this;
    }
}dbg;
///******************************************START******************************************
vector<string> v;
int main(){
     //freopen("out.txt","w",stdout);
    //ios_base::sync_with_stdio(false);
   //cin.tie(0);
   int x,y;
   int tx,ty;
   cin>>x>>y;
   cin>>tx>>ty;
   string s;

   for(int i=x;i<tx;i++){
      s+='R';
   }
   for(int i=y;i<ty;i++){
      s+='U';
   }
   for(int i=x;i<tx;i++){
      s+='L';
   }
   for(int i=y;i<ty;i++){
      s+='D';
   }
   s+='D';
   for(int i=x;i<tx+1;i++){
      s+='R';
   }
   for(int i=y;i<ty+1;i++){
      s+='U';
   }
   s+='L';
   s+='U';
    for(int i=x;i<tx+1;i++){
      s+='L';
   }
   for(int i=y;i<ty+1;i++){
      s+='D';
   }
   s+='R';
   //cout<<s.size()<<endl;
   cout<<s<<endl;


return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(){
  int h1,m1,h2,m2,k;
  int hour;
  int hour_minit;
  int h1_mi=0;
  int ans;
  int up_time;

  scanf("%d %d %d %d %d",&h1,&m1,&h2,&m2,&k);

  //起きた時間と寝る時間が何分あるか！
  //その時間からk分を引く
  if(m1 > 0 ){
    h1 += 1;
    h1_mi = 60-m1;
  }
  hour=h2-h1;
  hour_minit=hour*60;

  up_time = hour_minit+h1_mi+m2; //起きている時間
  ans = up_time-k;

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

  return 0;
}


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

int main() {
  long long a, b, c, d;
  cin >> a >> b >> c >> d;
  
  long long max = a * c;
  if(b * c > max) {
    max = b * c;
  }
  if(a * d > max) {
    max = a * d;
  }
  if(b * d > max) {
    max = b * d;
  }
  
  cout << max << endl;
  return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define INF 1e9
#define PI 3.14159265359
#define MOD 1000000007
#define ALL(v) v.begin(),v.end()
#define ALLR(v) v.rbegin(),v.rend()
typedef long long ll;
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
//isPrime
//modpow modinv
//getDigit
int main() {
  cout << fixed << setprecision(10);
  int a,b;
  cin >> a >> b;
  cout << max(max(a+b,a-b),a*b) << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i, a, b) for(int i = a; i < b; ++i)
#define RFOR(i, a, b) for(int i = a; i >= b; --i)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) RFOR(i, n, 0)
#define show(x) cout << #x << " = " << x << endl
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
const int INF = 1e9;
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> vi;
int main() {
    int A, B, C;
    cin >> A >> B >> C;
    int D = B / A;
    if(D >= C) cout << C << endl;
    else cout << D << endl;
}

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

int main(){

  int l,a,b,c,d;
  int x = 0,y = 0;

  cin >> l >> a >> b >> c >> d;

  while(a >= c){
    a -= c;
    x++;
  }

  while(b >= d){
    b -= d;
    y++;
  }

  if(a != 0) x++;
  if(b != 0) y++;

  cout << l - max(x,y) << endl;

}

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

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

//dfsでかくと面白そう
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);

    string s;
    cin >> s;

    reverse(s.begin(), s.end());

    string t;
    vector<string> v{"maerd", "remaerd", "esare", "resare"};

    while (t.size() < s.size()) {
        string tt = t;

        for (int i = 0; i < v.size(); i++) {
            string temp = tt + v[i];

            bool b = true;
            for (int j = tt.size(); j < temp.size(); j++) {
                if (temp[j] != s[j]) {
                    b = false;
                    break;
                }
            }

            if (b) {
                t = temp;
                break;
            }
        }

        if (tt == t) {
            break;
        }
    }

    if (t == s) {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }
}

Measured memory_bytes: 912
import java.util.Scanner;

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

		int N = sc.nextInt();
		int M = sc.nextInt();

		int[] seisu = new int[N];
		for (int i=0; i<N; i++) {
			seisu[i] = -1;
		}
		
		boolean NG = false;
		
		for (int i=0; i<M; i++) {
			int s = sc.nextInt();
			int c = sc.nextInt();
			if (s > N) {
				NG = true;
				break;
			}
			else if (s == 1 && c == 0 && N != 1) {
				NG = true;
				break;
			}
			else if (seisu[s - 1] != -1 && seisu[s - 1] != c) {
				NG = true;
				break;
			}
			else {
				seisu[s - 1] = c;
			}
		}

		StringBuilder ans = new StringBuilder();
		if (NG) {
			ans.append(-1);
		}
		else {
			if (seisu[0] == -1) {
				seisu[0] = N == 1 ? 0 : 1;
			}
			
			for (int i = 0; i < N; i++) {
				ans.append(seisu[i] == -1 ? 0 : seisu[i]);
			}
		}
		
		System.out.println(ans);
	}
}

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

int main()
{
  int a,b;
  cin >> a >> b;
  if (a < 10) {
    b = 100 * (10 - a) + b;
  }
  cout << b << endl;
  return 0;
}


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

int main()
{
  i64 N;
  cin >> N;
  map<i64, i64> m;
  i64 tmp = N;
  for (i64 i = 2; i <= sqrt(N); i++)
  {
    while (tmp % i == 0)
    {
      m[i]++;
      tmp /= i;
    }
  }
  if (tmp != 1)
    m[tmp]++;
  i64 ans = 0;
  for (pair<i64, i64> i : m)
  {
    i64 t = 1;
    while (0 <= i.second - t)
    {
      i.second -= t;
      t++;
      ans++;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3724
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner scn=new Scanner(System.in);
		int n=scn.nextInt();
		int []arr=new int[n];
		for(int i=0;i<n;i++) {
			arr[i]=scn.nextInt();
		}
		for(int i=0;i<n;i++) {
			arr[i]-=scn.nextInt();
		}
		int tot=0;
		for(int i=0;i<n;i++) {
			if(arr[i]>0) {
				tot+=arr[i];
			}
		}
		System.out.println(tot);
	}

}


Measured memory_bytes: 23764
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include<random>
#include<math.h>
#include<limits.h>
#include<iterator>
#include<queue>
#define rep(i,a) for(int i=0;i<a;i++)
#define nrep(i,a,b) for(int i=a;i<b;i++)
#define mrep(i,a) for(int i=a;i>=0;i--)
#define ll long long
#define vl vector<ll> 
#define vvl vector<vector<ll> > 
#define vb vector<bool> 
#define vvb vector<vector<bool> > 
#define INF 1123456789012345
using namespace std;

int main(){
	ll h, w; cin >> h >> w;
	ll n; cin >> n;
	vl a(n); rep(i, n) cin >> a[i];
	ll i = 0, j = 0;
	ll a_index = 0;
	ll a_count = 0;
	vvl ans(h, vl(w));
	rep(i, h){
		if (!j){
			while (j < w){
				a_count++;

				ans[i][j]=(a_index + 1);

				if (a_count == a[a_index]){
					a_index++;
					a_count = 0;
				}
				j++;
			}j--;
		}
		else{
			while (j >= 0){
				a_count++;

				ans[i][j]=(a_index + 1);

				if (a_count == a[a_index]){
					a_index++;
					a_count = 0;
				}
				j--;
			}j++;
		}
	}rep(i, h){
		rep(j, w) cout << ans[i][j] << " ";
		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 512
/********************************************************
     Failing doesn’t give you a reason to give up,
     as long as you believe.
                                  - Seventh Hokage
********************************************************/

#include <bits/stdc++.h>
#include <string>
#include <cmath>
#include <set>

using namespace std;

#define int long long int
typedef vector< int >        vi;
typedef set< int >           si;
typedef pair< int, int >     pii;
typedef map< int, int >      mii;
#define sz(a)           (int)((a).size())
#define pb              push_back
#define mp              make_pair
#define all(c)          (c).begin(),(c).end()
#define rall(c)         (c).rbegin(),(c).rend()
#define ub(c,k)         (upper_bound(all(c),k)-(c).begin())
#define lb(c,k)         (lower_bound(all(c),k)-(c).begin())
#define inf             LLONG_MAX
#define _inf            LLONG_MIN
#define rep(i,a,b)      for(int i=a;i<b;i++)
#define fr(n)           for(int i=0;i<n;i++)
#define tr(a)           for(auto it=a.begin();it!=a.end();it++)
#define trr(a)          for(auto it=a.rbegin();it!=a.rend();it++)
#define find(c, x)      (c.find(x) != c.end())
#define M               1000000007
#define PI              3.1415926535897932384
#define F               first
#define S               second
#define accuracy(x)     cout<<fixed<<setprecision(x);
#define fuck            {cout<<-1;return;}
#define fasterBaby      ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define elasped_time	1.0 * clock() / CLOCKS_PER_SEC
#define N               200005
int a[N],b[N],vis[N],ans=0;
vi cnt[N];
int sol[N],k=0;
int recur(int x)
{
	//cout<<x;
	int temp=a[x];
	if(vis[x]) return 0;
	vis[x]=1;
	for(auto t:cnt[x]) {temp+=recur(t);}
	ans+=temp;
	sol[k++] = x;
	return temp;
}

void basEkBaarAur()
{
	int x;
	cin>>x;
	cout<<(x>=30?"Yes":"No");
}

signed main()
{
	accuracy(15)
	fasterBaby
	int TESTS=1,i=1;
	//cin>>TESTS;
	while(TESTS--)
	{
		//cout<<"Case#"<<i++<<endl;
		basEkBaarAur();
		cout<<endl;
	}
	cerr<<endl<<"समय गुज़रा : "<<elasped_time<<endl;
	return 0;
}

Measured memory_bytes: 8492
#include "bits/stdc++.h"

using namespace std;

void Main() {
    string N;
    cin >> N;

    int n = atoi(N.substr(N.size() - 1, 1).c_str());
    if (n == 3) {
        cout << "bon" << endl;
    }
    else if (n == 0 || n == 1 || n == 6 || n == 8) {
        cout << "pon" << endl;
    }
    else {
        cout << "hon" << endl;
    }
}

int main() {
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep1(i, n) for(int i = 1; i <= (int)(n); i++)
#define repr(i, a, b) for(int i = (int)(a); i <= (int)(b); i++)
#define showmap(is, js, x) {rep(i, is){rep(j, js){cout << x[i][j] << " ";}cout << endl;}}
#define show(x) {for(auto i: x){cout << i << " ";} cout<<endl;}
#define showm(m) {for(auto i: m){cout << m.x << " ";} cout<<endl;}
typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> llP;
ll gcd(int x, int y){ return y?gcd(y, x%y):x;}
ll lcm(ll x, ll y){ return (x*y)/gcd(x,y);}


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

    ll ans = 0;
    int div = 0;
    vector<int> sdiv(s.size(), 0);
    sdiv[0] = 1;
    repr(i, 1, s.size()-1){
        sdiv[i] = sdiv[i-1]*10;
        sdiv[i] %= 2019;
    }

    map<int, int> nump;
    nump.insert({0,1});
    rep(i, s.size()){
        int c = s[s.size()-1-i] - '0';
        div += c*sdiv[i];
        div %= 2019;
        //cout << i <<":" << div << ":" << c << endl;
        if (nump.find(div) == nump.end()){
            nump.insert({div, 1});
        } else {
            ans += nump[div];
            nump[div]++;
        }
    }

    cout << ans << endl;

}



Measured memory_bytes: 4444
//@source : 
//@create : 19:39:33 Sunday 05/07/2020
//@author : nghethuat102
//@status : 
#include <bits/stdc++.h>
using namespace std;

#define fastio() ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define debug(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
template<typename T> void write(const T&x) { cout << x; }
template<typename T, typename... Args> void write(const T&x, Args... args) { cout << x; write(args...); }
template<typename... Args> void writeln(Args... args) { write(args..., "\n"); }
template<typename T> void read(T&x) { cin >> x; }
template<typename T, typename... Args> void read(T&x, Args&... args) { cin >> x; read(args...); }
void err(istream_iterator<string> it) {}
template<typename T, typename... Args> void err(istream_iterator<string> it, T a, Args... args) { cerr << *it << " = " << a << "\n"; err(++it, args...); }

void solve() {
    int n;
    read(n);
    vector<int> a(n);
    for (int i = 0; i < n; ++i) {
        read(a[i]);
    }
    sort(a.rbegin(), a.rend());
    long long ans = 0;
    ans += a[0];
    int rem = n - 2;
    int i = 1;
    while (rem > 0) {
        rem -= 1;
        ans += a[i];
        if (rem > 0) {
            rem -= 1;
            ans += a[i];
        }
        ++i;
    }
    writeln(ans);
}

int main() {
    fastio();
    int t = 1;
    for (int it = 1; it <= t; ++it) {
        solve();
    }
    return 0;
}

Measured memory_bytes: 3984
#include <algorithm>
#include <iostream>
#include <string>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <iomanip>
#include <limits>
#include <map>
#include <queue>
#include <stack>
#include <vector>

#define FOR(i,k,n) for(int (i) = (k); (i) < (n); ++(i))
#define rep(i,n) FOR(i,0,n)
#define pb push_back
#define all(v) begin(v), end(v)
#define debug(x) cerr << #x << ": " << x << endl
#define debug2(x,y) cerr << #x << ": " << x << ", " << #y << ": " << y << endl

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<i_i, int> p_i;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
template<class T> using vv=vector<vector<T>>;
typedef deque<int> di;
typedef deque<deque<int>> ddi;


int main() {
	int x,y,s;
	while(true) {	
		cin >>  x >> y >> s;
        if(x == 0 && y == 0 && s == 0){
            return 0;
        }

        int max = 0, a = 0, as = 0;
        FOR(i, 1, (s / 2) + 1){
            if(((s - i * (100+x) / 100) + 1) * 100 % (100+x) == 0) {
                a = ((s-i * (100 +x) /100)) * 100 / (100+x);
            } else {
                a = ((s-i * (100+x) /100)+1 ) * 100/ (100+x);
            }
            as = a * (100 + y) /100 + i * (100+y) /100;
            if((a * (100+x) /100 + i *(100+x)/100) != s) {
                continue;
            }
            if( max < as) {
                max = as;
            }
        }
        cout << max << endl;;
	}
    return 0;
}

Measured memory_bytes: 3088
#include <algorithm>
#include <iostream>
#include <limits>
#include <string>

int getMinChangedCount(const std::string &directions) {
  int right_east_count = std::count(directions.begin(), directions.end(), 'E');
  int left_west_count = 0;
  int min_changed_count = std::numeric_limits<int>::max();
  for (int i = 0; i < static_cast<int>(directions.size()); ++i) {
    if (directions[i] == 'W') {
      min_changed_count =
          std::min(right_east_count + left_west_count, min_changed_count);
      ++left_west_count;
    } else {
      --right_east_count;
      min_changed_count =
          std::min(right_east_count + left_west_count, min_changed_count);
    }
  }
  return min_changed_count;
}

int main() {
  int n;
  std::string directions;
  std::cin >> n >> directions;
  std::cout << getMinChangedCount(directions) << std::endl;
  return 0;
}

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

int main(void) {
  int n, m; cin >> n >> m;
  vector<int> xs;
  for (int i = 0; i < m; i++) {
    int x; cin >> x;
    xs.push_back(x);
  }

  sort(xs.begin(), xs.end());

  int prev = xs[0];
  vector<int> subs;
  for (int i = 1; i < m; i++){
    subs.push_back(xs[i] - prev);
    prev = xs[i];
  }

  sort(subs.begin(), subs.end());

  int t = m - n;
  int sum = 0;
  for (int i = 0; i < t; i++){
    sum += subs[i];
  }

  cout << sum << endl;

  return 0;
}

Measured memory_bytes: 1400
import heapq
# sys.stdin.readline()
import sys
input = sys.stdin.readline

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

S,T,X = [],[],[]

Ev = []
for _ in range(N):
  s,t,x = list(map(int, input().split())) 
  Ev.append((s-x,True,x))
  Ev.append((t-x,False,x))
"""
2 5 6
5 -1
4 2
3 3
2 4
1 5
0 -1
"""
Ev.sort()
#print(Ev)
# C++のSetはminもO(logN)で取れるが、Pythonは無理。
# setとheapqを併用すると計算量が実現できる。
h = []
closed = set()
eidx = 0
D = []

# 受け取った方が早い・・・？
for i in range(Q):
  D.append(int(input()))

for d in D:
  # dはsortedでinputされる。
  #d = int(input())
  #Query.append(d)
  while eidx < 2*N and Ev[eidx][0] <= d:
    #pop
    t,e,x = Ev[eidx]
    eidx += 1
    if e:
      heapq.heappush(h, x)
      closed.add(x)
    else:
      closed.remove(x)
      
  # heqpqの最小値がsetに含まれている間、捨て続ければ、setの要素とheapqの要素が一致する
  while h and h[0] not in closed:
    heapq.heappop(h)
    
  # assert( len(h) == len(set) )
  if h:
    print(h[0])
  else:
    print(-1)


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

int main(){
    int N;
    cin >> N;
    long long A[100000],sum[100000];
    for(int i=0;i<N;i++){
        cin >> A[i];
    }
    sort(A,A+N);
    sum[0]=A[0];
    for(int i=1;i<N;i++) sum[i]=sum[i-1]+A[i];

    int cnt=1;
    for(int i=1;i<N;i++){
        if(sum[i-1]*2>=A[i]) cnt++;
        else cnt=1;
    }

    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 1792
import sys
import copy

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

in_n = lambda: int(readline())
in_nn = lambda: map(int, readline().split())
in_s = lambda: readline().rstrip().decode('utf-8')
in_nl = lambda: list(map(int, readline().split()))
in_nl2 = lambda H: [in_nl() for _ in range(H)]
in_map = lambda: [s == ord('.') for s in readline() if s != ord('\n')]
in_map2 = lambda H: [in_map() for _ in range(H)]
in_all = lambda: map(int, read().split())


INF = 10**18


def warshall_floyd(V, cost):
    for k in range(V):
        for i in range(V):
            for j in range(V):
                if cost[i][k] < INF and cost[k][j] < INF:
                    cost[i][j] = min(cost[i][j], cost[i][k] + cost[k][j])


def main():

    V = in_n()
    cost = [[] for _ in range(V)]

    for i in range(V):
        cost[i] = in_nl()

    short_cost = copy.deepcopy(cost)
    warshall_floyd(V, short_cost)

    ans = 0
    for i in range(V):
        for j in range(i + 1, V):
            if short_cost[i][j] < cost[i][j]:
                print(-1)
                exit()
            for k in range(V):
                if i == k or j == k:
                    continue
                if short_cost[i][k] + short_cost[k][j] == cost[i][j]:
                    break
            else:
                ans += cost[i][j]

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 76820
import numpy
import scipy

p = []
for _ in range(5):
    p.append(int(input())) 
k = int(input())

ends = False

for i in range(4):
    for j in range(i,5):
        if (p[j] - p[i] > k):
            print(':(')
            ends = True
            break

    if ends:
        break

if not ends:
    print('Yay!')

Measured memory_bytes: 21604
#include<stdio.h>

void selectionSort(int A[], int N){
    int num = 0;

    for(int i = 0; i < N; i++){
       int minj = i;
       int tmp;
       for(int j = i; j < N; j++){

            if(A[j] < A[minj]){
                minj = j;
            }

        }
            if(minj != i){
                tmp = A[minj];
                A[minj] = A[i];
                A[i] = tmp;
                num++;                
            }
    }

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

int main(void){
    int n, a[200];
    scanf("%d", &n);
    for(int i = 0; i < n; i++){
        scanf("%d", &a[i]);
    }
    selectionSort(a, n);

    return 0;   
}


Measured memory_bytes: 2760
/*input

*/
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<double,double> pdd;
#define IOS ios_base::sync_with_stdio(0); cin.tie(0)
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define F first
#define S second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define pb push_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#ifdef leowang
#define debug(...) do{\
	fprintf(stderr,"%s - %d : (%s) = ",__PRETTY_FUNCTION__,__LINE__,#__VA_ARGS__);\
	_DO(__VA_ARGS__);\
}while(0)
template<typename I> void _DO(I&&x){cerr<<x<<endl;}
template<typename I,typename...T> void _DO(I&&x,T&&...tail){cerr<<x<<", ";_DO(tail...);}
#else
#define debug(...)
#endif
template<typename T1,typename T2>
ostream& operator<<(ostream& out,pair<T1,T2> P){
	out<<'('<<P.F<<','<<P.S<<')';
	return out;
}
//}}}
const ll maxn=300005;
const ll maxlg=__lg(maxn)+2;
const ll INF64=8000000000000000000LL;
const int INF=0x3f3f3f3f;
const ll MOD=ll(1e9+7);
const double PI=acos(-1);
//const ll p=880301;
//const ll P=31;

ll mypow(ll a,ll b){
	ll res=1LL;
	while(b){
		if(b&1) res=res*a%MOD;
		a=a*a%MOD;
		
		b>>=1;
	}
	return res;
}

int main()
{
	IOS;
	int a,b;
	cin>>a>>b;
	cout<<a+b/2;

	return 0;
}


Measured memory_bytes: 256
from collections import Counter
n = int(input())
a = list(map(int, input().split()))
C = Counter(a)
q = int(input())
ans = sum(a)
for i in range(q):
    b, c = map(int, input().split())
    ans += (c-b)*C[b]
    C[c] += C[b]
    C[b] = 0
    print(ans)


Measured memory_bytes: 24324
import sys
from collections import deque, Counter
def I(): return int(sys.stdin.readline().rstrip())

if __name__=='__main__':
    n = I()
    l = []
    for _ in range(n):
        l.append(I())
    c = [0]*n
    now = 0
    c[now] = 1
    for i in range(1,n+1):
        now = l[now]-1
        c[now] += 1
        if now==1:
            print(i)
            exit()
        if c[now]==2:
            print(-1)
            exit()
    exit()

Measured memory_bytes: 14036
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>
#include <set>
#define lowbit(x) (x&(-x))
#define MAX(a,b) (a<b?b:a)
#define MIN(a,b) (a<b?a:b)
using namespace std;

typedef long long ll;
const int N = 3e5;
const int maxn = 3e5 + 5;
ll mod = 1e9 + 7;

ll n, m;
char s[maxn], t[maxn];
ll gcd(ll a, ll b)
{
	while (b)
	{
		a %= b;
		swap(a, b);
	}
	return a;
}
int main()
{
	cin >> n >> m >> s >> t;
	ll k = n * m / gcd(n, m);

	for (int i = 0; i < n; i++)
	{
		if (i % (k / m) == 0)
		{
			if (s[i] != t[(ll)i*m / n])
			{
				cout << -1;
				return 0;
			}
		}
	}
	cout << k;
}

Measured memory_bytes: 384
#include <iostream>
using namespace std;
#define debug(x) std::cerr << #x << " = " << (x) << std::endl
typedef long long LL;
const int MAXN = 2e5+17;
const int MOD = 1e9+7;
int dp[MAXN],nxt[MAXN][26+3],ocr[26+3];
int main(int argc ,char const *argv[])
{
	#ifdef noob
	freopen("Input.txt","r",stdin);freopen("Output.txt","w",stdout);
	#endif	
	string str;
	cin>>str;
	int n = str.length();
	for (int i = 0; i < 26; ++i)
	{
		ocr[i] = n;
	}
	dp[n]=1;
	for (int i = n-1; i > -1; --i)
	{
		ocr[str[i]-'a'] = i;
		for (int j = 0; j < 26; ++j)
		{
			nxt[i][j] = ocr[j];
		}
		dp[i] = MOD;
		
	}
	// debug(nxt[0][25]);
	for (int i = n-1; i > -1; --i)
	{
		for (int j = 0; j < 26; ++j)
		{
			
			dp[i] = min(dp[i],dp[nxt[i][j]+1]+1);
		// 	if(i==0)
		// 	{

		// 		debug(j);
		// 		debug(dp[i]);
		// 		debug(nxt[i][j]);
		// 	}
		}
		// debug(i);
		// debug(dp[i]);
	}
	debug(dp[0]);
	for (int i = 0; dp[0]; --dp[0])
	{
		for (int j = 0; j < 26; ++j)
		{
			if(dp[i]==dp[nxt[i][j]+1]+1)
			{
				printf("%c",j+'a');
				i = nxt[i][j]+1;
				break;
			}
		}
	}
	return 0;	
}

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

const int maxn = 100;
vector<int>g[maxn];
int vis[maxn];
int n,m;
int num,tot;
void dfs(int t)
{	
	int j;
	for(j=1;j<=n;j++)
	{
		if(vis[j]!=1)
			break;
	}
	if(j==n+1)
	{
		num++;
		return;
	}
	for(int i=0;i<g[t].size();i++)
	{
		int x = g[t][i];
		if(vis[x]==0)
		{
			vis[x]=1;
			dfs(x);
			vis[x]=0;
		}
	}
	return ;
}
int main()
{
	memset(vis,0,sizeof(vis));
	cin>>n>>m;
	tot=0;
	num=0;
	for(int i=1;i<=n;i++)
	{
		g[i].clear();
	}
	for(int i=1;i<=m;i++)
	{
		int a,b;
		cin>>a>>b;
		g[a].push_back(b);
		g[b].push_back(a);
	}
	vis[1]=1;
	num=0;
	for(int i=0;i<g[1].size();i++)
	{
		int x=g[1][i];
		vis[x]=1;
		dfs(x);
		vis[x]=0;
	}
	cout<<num<<endl;
	
	return 0;
}


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

#define rep(i,s,n) for (int i = (int)s; i < (int)n; i++)
#define ll long long
#define pb push_back
#define All(x) x.begin(), x.end()
#define Range(x, i, j) x.begin() + i, x.begin() + j
#define lbidx(x, y) lower_bound(x.begin(), x.end(), y) - x.begin()
#define ubidx(x, y) upper_bound(x.begin(), x.end(), y) - x.begin()
#define BiSearchRangeNum(x, y, z) lower_bound(x.begin(), x.end(), z) - lower_bound(x.begin(), x.end(), y)
template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
};

template<class T>
inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
};

vector<ll> divisor(ll n) {
  vector<ll> ret;
  for(ll i = 1; i * i <= n; i++) {
    if(n % i == 0) {
      ret.push_back(i);
    }
  }
  return (ret);
}

int main() {
    ll n;
    cin >> n;
    vector<ll> divs = divisor(n);
    ll a = divs[divs.size() - 1];
    ll b = n / a;
    ll ans = a + b - 2;
    cout << ans << endl;
};


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main() {

	string s;
	cin >> s;
	int i;
	i = s.size() - 1;
	int flag = 0;
	while(i>=4){
		flag = 0;
		if (s[i] == 'm' && s[i - 1] == 'a' && s[i - 2] == 'e' && s[i - 3] == 'r' && s[i - 4] == 'd') {
			i = i - 5; flag = 1;
		}
		else if (s[i] == 'e' && s[i - 1] == 's' && s[i - 2] == 'a' && s[i - 3] == 'r' && s[i - 4] == 'e') {
			i = i - 5; flag = 1;
		}
		else if (i >= 5) {
			if (s[i] == 'r' && s[i - 1] == 'e' && s[i - 2] == 's' && s[i - 3] == 'a' && s[i - 4] == 'r' && s[i - 5] == 'e') {
				i = i - 6; flag = 1;
			}else if (i >= 6) {

				if (s[i] == 'r' && s[i - 1] == 'e' && s[i - 2] == 'm' && s[i - 3] == 'a' && s[i - 4] == 'e' && s[i - 5] == 'r' && s[i - 6] == 'd') {
					i = i - 7; flag = 1;
				}
			}
		}
		if (flag == 0) {
			cout << "NO" << endl;
			return 0;
		}
	}
	cout << "YES" << endl;
	return 0;

}

Measured memory_bytes: 3780
//#pragma GCC optimize("03", "unroll-loops")
//#pragma GCC target("avx2")

#include <bits/stdc++.h>

#define fast() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define FOR(i,n) for(i=0;i<n;i++)
#define FORn(i,j,n) for(i=j;i<n;i++)
#define pb push_back
#define unique_sort(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define vli vector<lli>
#define vi vector<int>
#define vs vector<string>
#define vprint(v) for(auto t:v)cout<<t<<" "
#define endl "\n"

typedef long long int lli;
typedef long int li;

const lli mod=1000000007;
const lli limit=1000000;

using namespace std;

void fc(lli &x)
    {
        bool neg=false;
        register char c;
        x =0;
        c=getchar();
        if(c=='-')
        {
            neg = true;
            c=getchar();
        }
        for(;(c>47 && c<58);c=getchar())
            x = (x<<1) + (x<<3) +c -48;
        if(neg)
            x *=-1;
    }

int main() {

    fast()
    lli n,q,t;
    long double temp,temp1,temp2,temp3;
    lli i,j,k;
    cin>>temp;
    temp=temp/3.0;
    temp*=temp*temp;
    cout<<setprecision(20)<<temp<<endl;
 
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <iterator>
#include <algorithm>

int main(){
  std::string S,copy,cf="abcdefghijklmnopqrstuvwxyz";;
  std::cin >> S;
  if(S.length() < 26){
    copy = S;
    std::sort(copy.begin(),copy.end());
    std::string lack;
    for(int i = 0; i < 26; ++i){
      if(copy[i] != cf[i]){
	lack = cf[i];
	break;
      }
    }
    S += lack;
  }
  else{
    for(int i = 25; i >= -1; --i){
      if(i == -1){
	std::cout << "-1" << std::endl;
	return 0;
      }
      else if(S[i] < S[i+1]){
	copy = S;
	std::sort(copy.begin()+i+1,copy.end());
	for(int j = i+1; j < 26; ++j){
	  if(copy[j] > S[i]){
	    S[i] = copy[j];
	    break;
	  }
	}
	S.erase(S.begin()+i+1,S.end());
	break;
      }
    }
  }
  std::cout << S << std::endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <stack>
#include <string>
#include <queue>
#include <cmath>
#include <numeric>
#include <list>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <climits>
#include <memory.h>
#include <memory>
#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <map>
#define _USE_MATH_DEFINES
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef pair<int, P> PP;
typedef vector<int> vec;
typedef vector<vec> mat;
const int INF = 1 << 30;
const double EPS = 1e-9;

map<int, bool> hos;
int dist[100][101];
vector<P> G[100];

int main(){
	int N, M, L, K, A, H;
	int h;
	int x, y, dis;
	while(cin >> N >> M >> L >> K >> A >> H && (N || M || L|| K|| A|| H)){
		for(int i = 0; i < L; i++){
			cin >> h;
			hos[h] = true;
		}
		for(int i = 0; i < K; i++){
			cin >> x >> y >> dis;
			G[x].push_back(P(y, dis));
			G[y].push_back(P(x, dis));
		}

		bool f = true;
		fill(&dist[0][0], &dist[99][100] + 1, INF);
		dist[A][M] = 0;
		priority_queue<PP, vector<PP>, greater<PP> > que;
		que.push(PP(0, P(A, M)));

		while(!que.empty()){
			PP pp = que.top();
			que.pop();
			int time = pp.first;
			int place = pp.second.first;
			int rest = pp.second.second;
			if(time < dist[place][rest]) continue;
			if(place == H){
				cout << dist[place][rest] << endl;
				f = false;
				break;
			}

			if(hos[place]){
				for(int i = rest + 1; i <= M; i++){
					if(dist[place][i] > dist[place][rest] + i - rest){
						dist[place][i] = dist[place][rest] + i - rest;
						que.push(PP(dist[place][i], P(place, i)));
					}
				}
			}

			for(int i = 0; i < G[place].size(); i++){
				P p = G[place][i];
				if(rest - p.second < 0) continue;
				if(dist[p.first][rest - p.second] > dist[place][rest] + p.second){
					dist[p.first][rest - p.second] = dist[place][rest] + p.second;
					que.push(PP(dist[p.first][rest - p.second], P(p.first, rest - p.second)));
				}
			}
		}
		if(f) cout << "Help!" << endl;
		for(int i = 0; i < 100; i++) G[i].clear();
		hos.clear();
	}
	return 0;
}

Measured memory_bytes: 1088
#include<map>
#include<set>
#include<stack>
#include<cmath>
#include<queue>
#include<cstdio>
#include<string>
#include<vector>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;

int main()
{
	int n, m;
	scanf("%d%d", &n, &m);
	for (int i = m / n; i >= 1; i--)
		if (m % i == 0)
		{
			printf("%d", i);
			break;
		}
	return 0;
}

Measured memory_bytes: 256
import java.util.*;

class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int list[] = new int[52];
		String mark = " ";
		int num = 0;
		for(int i = 0;i < n;i++){
			mark = sc.next();
			num = sc.nextInt();
			switch(mark){
			case "S":
				list[num-1] = 1;
				break;
			case "H":
				list[num + 12] = 1;
				break;
			case "C":
				list[num + 25] = 1;
				break;
			case "D":
				list[num + 38] = 1;
				break;
			}
		}
		for(int j = 0;j < 52;j++){
			if(1 != list[j]){
				if(j >= 0 && j < 13){
					mark = "S";
					num = j + 1;
				}else if(j > 12 && j < 26){
					mark = "H";
					num = j - 12;
				}else if(j > 25 && j < 39){
					mark = "C";
					num = j - 25;
				}else{
					mark = "D";
					num = j - 38;
				}
				System.out.println(mark + " " + num);
			}
		}
	}
}


Measured memory_bytes: 25944
#include<bits/stdc++.h>
#define llong long long
#define mkpr make_pair
#define x first
#define y second
#define iter iterator
#define riter reversed_iterator
#define y1 Lorem_ipsum_
#define tm dolor_sit_amet_
using namespace std;

inline int read()
{
	int x = 0,f = 1; char ch = getchar();
	for(;!isdigit(ch);ch=getchar()) {if(ch=='-') f = -1;}
	for(; isdigit(ch);ch=getchar()) {x = x*10+ch-48;}
	return x*f;
}

const int N = 128;
const int S = 62;
vector<int> s[S*4+3];
vector<int> apr[S+3];
int n;

char decode(int x) {return x<=26?64+x:(x<=52?96-26+x:48+x-52-1);}

bool ask(int u,int i,int j)
{
	int len = n;
	printf("? "); for(int k=0; k<s[u].size(); k++) {len--; printf("%c",decode(s[u][k]));} len--; printf("%c",decode(s[u<<1][i]));
	for(int k=j; k<s[u<<1|1].size(); k++) {len--; printf("%c",decode(s[u<<1|1][k]));} puts(""); fflush(stdout);
	int res; scanf("%d",&res); return res==len;
}
void solve(int u,int le,int ri)
{
	if(le==ri)
	{
		s[u] = apr[le];
		return;
	}
	int mid = (le+ri)>>1;
	solve(u<<1,le,mid); solve(u<<1|1,mid+1,ri);
	for(int i=0,j=0; i<s[u<<1].size()||j<s[u<<1|1].size();)
	{
		if(i<s[u<<1].size()&&(j==s[u<<1|1].size()||ask(u,i,j))) {s[u].push_back(s[u<<1][i]); i++;}
		else {s[u].push_back(s[u<<1|1][j]); j++;}
	}
}

int main()
{
	for(int i=1; i<=S; i++)
	{
		printf("? "); for(int j=1; j<=N; j++) {printf("%c",decode(i));} puts(""); fflush(stdout);
		int res; scanf("%d",&res);
		for(int j=1; j<=N-res; j++) apr[i].push_back(i);
		n += apr[i].size();
	}
	solve(1,1,S);
	printf("! "); for(int i=0; i<s[1].size(); i++) printf("%c",decode(s[1][i])); puts(""); fflush(stdout);
	return 0;
}

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

int main(){
    
    int n,x;
    cin>>n;
    
    map <int,bool>m;
    while(n--){
        cin>>x;
        if(m[x]){
            cout<<"NO"<<endl;
            return 0;
        }
        else{
            m[x]=true;
        }
    }
    cout<<"YES"<<endl;
    return 0;
}

Measured memory_bytes: 9600
import java.util.*;
import java.util.stream.Collectors;
import java.io.*;
import java.nio.charset.StandardCharsets;

public class Main {

	public static void main(String[] args) throws IOException {
		InputStreamReader reader = new InputStreamReader(System.in, StandardCharsets.UTF_8);
		BufferedReader in = new BufferedReader(reader);
		Main ins = new Main(in);
		ins.calc();
		ins.showResult();
	}

	Main(BufferedReader in) throws IOException {
		int A, B, C;
		String[] tokens = in.readLine().split(" ");
		A = Integer.parseInt(tokens[0]);
		B = Integer.parseInt(tokens[1]);
		C = Integer.parseInt(tokens[2]);
		if (A == B || B == C || A == C) {
			if (A == B && B == C) {
				System.out.println("No");
			} else {
				System.out.println("Yes");
			}
		} else {
			System.out.println("No");
		}
	}

	void calc() {
	}

	void showResult() {
	}
}


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

//typedef
typedef long long LL;
typedef unsigned int UINT;
typedef unsigned long long ULL;
typedef set<int, greater<int> > setdownINT;
typedef set<long long, greater<long long> > setdownLL;
typedef priority_queue<int, vector<int>, greater<int> > priqueupINT;
typedef priority_queue<long long, vector<long long>, greater<long long> > priqueupLL;
//container utill
#define ALL(v) (v).begin(),(v).end()
#define sortdown(v) sort((v).begin(),(v).end()), reverse((v).begin(),(v).end())
#define PB(a) push_back(a)
#define MP make_pair
#define MT make_tuple
//constant
#define PI 3.141592653589793

int main(){
    //input
    string s;
    int K;
    cin >> s >> K;

    //calc
    set<string> st;
    int i,j;
    for(i=1; i<=5; i++){
        for(j=0 ;j+i<=s.length(); j++){
            st.insert(s.substr(j,i));
        }
    }
    auto it=st.begin();
    while(K>1){
        it++;
        K--;
    }

    //output
    cout << *it << endl;
    system("pause");
    return 0;
}

Measured memory_bytes: 4752
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		String S = sc.next();
		int topingCnt=0;

		for (int i=0; i<3; i++){
			if (S.substring(i, i+1).equals("o")){
				topingCnt++;
			}
		}
		System.out.println(700 + (100*topingCnt));
	}

}


Measured memory_bytes: 21844
from operator import itemgetter
import sys
input=sys.stdin.readline
mod=998244353

def bit_add(i):
    while i<=n:
        tree[i]+=1
        i+=i&(-i)
        
def bit_sum(i):
    s=0
    while i>0:
        s+=tree[i]
        i-=i&(-i)
    return s

n=int(input())
xy=[[i+1]+list(map(int,input().split())) for i in range(n)]
data=[[] for i in range(n+1)]
for i in [1,2]:
    xy.sort(key=itemgetter(i))
    for j in range(n):
        data[xy[j][0]].append(j+1)
    
data=sorted(data[1:])
lst=[]
for i1,i2 in data:
    lst.append(i2)

lsls=[1]*(n+1)
for i in range(1,n+1):
    lsls[i]=lsls[i-1]*2%mod
for i in range(n+1):
    lsls[i]-=1
    
s=pow(2,n,mod)-1
tree=[0]*(n+1)
ans=0
for i in range(n):
    y=lst[i]
    num=bit_sum(y)
    bit_add(y)
    a,b,c,d=i-num,num,y-1-num,n-y-i+num
    zzz=lsls[i]+lsls[n-i-1]+lsls[n-y]+lsls[y-1]
    yyy=lsls[a]+lsls[b]+lsls[c]+lsls[d]
    t=(zzz%mod-yyy%mod)%mod
    ans=(ans+s-t)%mod
print(ans)

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

int mp(int A, int B, int C, vector<int> bamboo){
	int ans = INT_MAX;

	for (int i = 0; i < bamboo.size(); i++) {
		for (int j = 0; j < bamboo.size(); j++) {
			if (i != j) for (int k = 0; k < bamboo.size(); k++) {
				if (i != k and j != k) ans = min(ans, abs(A - bamboo[i]) + abs(B - bamboo[j]) + abs(C - bamboo[k]));
			}
		}
	}

	if (bamboo.size() == 3 or ans <= 10) return ans;

	int test = 0;
	for (int i = 0; i < bamboo.size(); i++) {
		for (int j = 0; j < i; j++) {
			vector<int> newbb(bamboo);
			newbb.push_back(newbb[i] + newbb[j]);
			newbb.erase(newbb.begin() + i);
			newbb.erase(newbb.begin() + j);
			ans = min(ans, mp(A, B, C, newbb) + 10);
		}
	}
	return ans;
}

int main()
{
	int N, A, B, C; cin >> N >> A >> B >> C;
	vector<int> bamboo(N);
	for (int i = 0; i < N; i++) cin >> bamboo[i];

	cout << mp(A, B, C, bamboo) << endl;
}

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

char a[150];
int len;

signed main()
{
	scanf("%s",a);
	len=strlen(a);
	for(int i=0;i<len;i++)
	{
		if(a[i]=='C')
		{
			for(int j=i+1;j<len;j++)
			{
				if(a[j]=='F')
				{
					printf("Yes");
					return 0;
				}
			}
			break;
		}
	}
	printf("No");
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <climits>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <string>
#include <bitset>
#include <utility>
#include <numeric>
#include <queue>
#include <stack>

using ll = long long;
using namespace std;

constexpr int MOD = 1e9 + 7;
constexpr ll MOD_LL = ll(1e9) + 7;

int main(void) {
	int n, d;
	cin >> n >> d;
	
	vector< vector<int> > x(n, vector<int>(d));
	for(int i = 0; i < n; ++i) {
		for(int j = 0; j < d; ++j) {
			cin >> x[i][j];
		}
	}
	
	int ans = 0;
	for(int i = 0; i < n; ++i) {
		for(int j = i + 1; j < n; ++j) {
			int sum = 0;
			
			for(int k = 0; k < d; ++k) {
				sum += (x[i][k] - x[j][k]) * (x[i][k] - x[j][k]);
			}
			
			bool ok = false;
			for(int k = 1; k <= sum; ++k) {
				if( k * k == sum ) ok = true;
			}
			
			if( ok ) ans++; 
		}
	}
	
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;
const int Maxn=2e3+5;
int n;
long long tmp,ans,dp[Maxn][Maxn];
struct A
{
	int pos;
	long long val;
}num[Maxn];
bool cmp(A a,A b)
{
	return a.val>b.val;
}
int main()
{
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>tmp;
		num[i].val=tmp;
		num[i].pos=i;
	}
	sort(num+1,num+n+1,cmp);
	for(int i=1;i<=n;i++)
	{
		dp[i][0]=dp[i-1][0]+num[i].val*abs(num[i].pos-(n-i+1));
		dp[i][i]=dp[i-1][i-1]+num[i].val*abs(num[i].pos-i);
		for(int j=1;j<i;j++)
		{
			dp[i][j]=max(dp[i-1][j-1]+num[i].val*abs(num[i].pos-j),
						dp[i-1][j]+num[i].val*abs(num[i].pos-(n-i+j+1)));
		}
	}
	for(int i=1;i<=n;i++)
		ans=max(ans,dp[n][i]);
	cout<<ans;
	return 0;
}


Measured memory_bytes: 26308
#include <iostream>
#include <string>

using namespace std;

int main(void) {
    string S;
    cin >> S;
    for(int i=1; i<4; i++) {
        if(S.at(i) == S.at(i-1)) {
            cout << "Bad" << endl;
            return 0;
        }
    }
    cout << "Good" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(void){
    int a, b, c;
    int sum_1 = 0; 
    int sum_2 = 0;

    scanf("%d %d %d", &a, &b, &c);

    sum_1 = a - b;
    sum_2 = c - sum_1;


    if (sum_2 > 0)
    {
        printf ("%d\n", sum_2);
    }

    else
    {
        printf ("%d\n", 0);
    }
    
  
    return 0;
    
}

Measured memory_bytes: 128