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

typedef long long ll;

int v[100001];
int numEven[100001];
int numOdd[100001];

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

  for ( int i = 1; i <= n; i++ ) {
    cin >> v[i];
    if ( i % 2 == 0 ) {
      numEven[v[i]]++;
    } else {
      numOdd[v[i]]++;
    }
  }
  
  bool f = true;
  int top = v[1];
  for ( int i = 2; i <= n; i++ ) {
    if( top != v[i] ) f = false;
  }

  if (f) {
    cout << n/2 << endl;
    return 0;
  }
  
  int maxNumEven = 0;

  int Even;

  int maxNumOdd = 0;

  int Odd;


  
  for ( int i = 1; i <= 100000; i++ ) {
    if ( numEven[v[i]] > maxNumEven ) {
      maxNumEven = numEven[v[i]];
      Even = v[i];
    }
  }

  for ( int i = 1; i <= 100000; i++ ) {
    if ( numOdd[v[i]] > maxNumOdd && v[i]  ) {
      maxNumOdd = numOdd[v[i]];
      Odd = v[i];
    }
  }
  if ( Even != Odd ) f = true;

  if (f) {
    int cntEven = 0;

    for ( int i = 2; i <= n; i+=2 ) {
      if ( v[i] != Even ) cntEven++;
    }
    int cntOdd = 0;
    for ( int i = 1; i <= n; i+=2 ) {
      if ( v[i] != Odd ) cntOdd++;
    }
    
    cout << cntEven + cntOdd << endl;
    return 0;
  } else {
    ///
    int tmpEven = Even;
    int tmpOdd = Odd;
    //cout << Even << endl;
    //cout << Odd << endl;
    maxNumEven = 0;

    maxNumOdd = 0;
    
    for ( int i = 1; i <= 100000; i++ ) {
      if ( numEven[v[i]] > maxNumEven && v[i] != tmpEven ) {
	maxNumEven = numEven[v[i]];
	Even = v[i];
      }
    }

    for ( int i = 1; i <= 100000; i++ ) {
      if ( numOdd[v[i]] > maxNumOdd   ) {
	maxNumOdd = numOdd[v[i]];
	Odd = v[i];
      }
    }
    //cout << "!=Even" << endl;
    // cout << Even << endl;
    //cout << Odd << endl;
    int cnt1 = 0;

    for ( int i = 2; i <= n; i+=2 ) {
      if ( v[i] != Even ) cnt1++;
    }
    
    for ( int i = 1; i <= n; i+=2 ) {
      if ( v[i] != Odd ) cnt1++;
    }
    


    ///
    maxNumEven = 0;
    maxNumOdd = 0;
    for ( int i = 1; i <= 100000; i++ ) {
      if ( numEven[v[i]] > maxNumEven  ) {
	maxNumEven = numEven[v[i]];
	Even = v[i];
      }
    }

    for ( int i = 1; i <= 100000; i++ ) {
      if ( numOdd[v[i]] > maxNumOdd && v[i] != tmpOdd ) {
	maxNumOdd = numOdd[v[i]];
	Odd = v[i];
      }
    }
    //cout << "!=Odd" << endl;
    //cout << Even << endl;
    //cout << Odd << endl;
    int cnt2 = 0;

    for ( int i = 2; i <= n; i+=2 ) {
      if ( v[i] != Even ) cnt2++;
    }
    
    for ( int i = 1; i <= n; i+=2 ) {
      if ( v[i] != Odd ) cnt2++;
    }
    //cout << "ans" << endl;
    cout << min(cnt1,cnt2) << endl;
  }
  return 0;
}


Measured memory_bytes: 1408
def great_ocean_view(N: int, H: list)->int:
    max_h = 0
    count = 0
    for h in H:
        if max_h <= h:
            count += 1
            max_h = h
    return count


if __name__ == "__main__":
    N = int(input())
    H = [int(s) for s in input().split()]
    ans = great_ocean_view(N, H)
    print(ans)


Measured memory_bytes: 2940
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define mk make_pair
#define rint register int
using namespace std;
inline int read() {
	int w=1,s=0;
	char ch=getchar();
	while(!isdigit(ch)) {
		if(ch=='-')w=-1;
		ch=getchar();
	}
	while(isdigit(ch)) {
		s=s*10+ch-'0';
		ch=getchar();
	}
	return w*s;
}
struct node {
	int to,next;
} e[1000010];
int tag[1000010],h[1000010],tot,n,fa[200010][21],Max[200010][21],Mx[200010],dep[200010];
inline void add(int from,int to) {
	e[++tot].next=h[from];
	h[from]=tot;
	e[tot].to=to;
}
inline void DFS1(int now,int ffa) {
	fa[now][0]=ffa;
	Max[now][0]=max(now,ffa);
	dep[now]=dep[ffa]+1;
	Mx[now]=max(now,Mx[ffa]);
	for(rint i=h[now]; i; i=e[i].next) {
		int to=e[i].to;
		if(to==ffa) continue;
		DFS1(to,now);
	}
}
inline void DFS2(int now,int ffa) {
	tag[now]+=tag[ffa];
	for(rint i=h[now]; i; i=e[i].next) {
		int to=e[i].to;
		if(to==ffa) continue;
		DFS2(to,now);
	}
}
inline void Build() {
	for(rint i=1; i<=20; ++i) for(rint j=1; j<=n; ++j) fa[j][i]=fa[fa[j][i-1]][i-1];
	for(rint i=1; i<=20; ++i) for(rint j=1; j<=n; ++j) Max[j][i]=max(Max[fa[j][i-1]][i-1],Max[j][i-1]);
	tag[1]=1;
	for(rint i=2; i<=n; ++i) {
		if(Mx[i]==i) {
			tag[i]++;
			continue;
		} else {
			int pos=Mx[i];
			int now=i;
			int mx=i;
			int tt=now;
			for(rint i=20; i>=0; --i) if(dep[fa[now][i]]>=dep[pos]+1) mx=max(mx,Max[now][i]),now=fa[now][i];
			if(mx<Mx[fa[pos][0]]) tt=pos;
			else tt=now;
			tag[tt]++;//cout<<i<<" "<<tt<<"\n";
		}
	}
	DFS2(1,0);
}
int main() {
//	freopen("1.in","r",stdin);
	n=read();
	for(rint i=1; i<n; ++i) {
		int u=read(),v=read();
		add(u,v);
		add(v,u);
	}
	DFS1(1,0);
	Build();
	for(rint i=2; i<=n; ++i) cout<<tag[i]-1<<" ";
	return 0;
}

Measured memory_bytes: 53248
#include <iostream>

int main() {
  int a, b, c;
  std::cin >> a >> b >> c;

  int ba = b - a;
  int cb = c - b;
  if ( ba == cb ) {
    std::cout << "YES" << std::endl;
  } else {
    std::cout << "NO" << std::endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<list>
#include<cmath>
#include<algorithm>
#include<cstdio>
#include<set>
#include<queue>
using namespace std;

typedef long long ll;

int main() {
  ll N,T; cin >> N >> T;
  ll t[200010];
  ll sum = 0;
  for ( int i =  0; i < N; i++ ) cin >> t[i];
  for ( int i = 0; i < N-1; i++ ) {
    sum += min(T,t[i+1]-t[i]);
  }
  sum += T;

  cout << sum << endl;
  return 0;
}


Measured memory_bytes: 1792
n = int(raw_input())
arr = [int(x) for x in raw_input().split()] 

count = 0
min_subarr = 2 * 10**5 + 1
for i in range(0, len(arr)):
	if arr[i] < min_subarr:
		min_subarr = arr[i]
		count += 1
print count


Measured memory_bytes: 50624
#include<iostream>
using namespace std;
#include<stdio.h>
int main(){
    
    double r,p=3.141592653589,S,L;
    cin>>r;
    S = r*r*p;
    L = 2*r*p;
    printf("%.8f %.8f", S, L );
    
    return 0;
}


Measured memory_bytes: 3196
#pragma GCC optimize("Ofast",3,"inline")
#include<bits/stdc++.h>
using namespace std;
#define fir first
#define sec second
#define m_p make_pair
#define y1 ygftgfgcdtfgxffgx
#define y2 yfdsesgvtyghftfvv
#define x1 xvyr6cf6fgcfgf676
#define x2 xcr6rfc5r66y6r6fr
#define up_bound upper_bound
#define low_bound lower_bound
#define next_per next_permutation
#define pb push_back
#define i_to_s to_string
typedef priority_queue<int> p_queue;
typedef priority_queue<int, vector<int>, greater<int> > min_p_queue;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
int mon[20]={31,28,31,30,31,30,31,31,30,31,30,31};
ll gcd(ll x,ll y){return ((y==0)?x:gcd(y,x%y));}
ll INF=10000000;
ll a[100010],b[100010];
int n;
ll cnt1,cnt2,x;;
int main() {
	cin>>n;
	for(int i=0;i<n;i++)cin>>a[i];
    for(int i=0;i<n;i++)cin>>b[i];
    for(int i=0;i<n;i++){
		x+=b[i]-a[i];
		if(a[i]<b[i]){
			if((b[i]-a[i])%2==1)cnt2++;
			cnt1+=(b[i]-a[i]+1)/2;
		}
		else if(a[i]>b[i]) cnt2+=a[i]-b[i];
	}
	if (cnt1<=x&&cnt2<=x)cout<<"Yes";
	else cout<<"No";
}



Measured memory_bytes: 384
#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//using namespace __gnu_pbds;


//      DEEP

using namespace std;
#define boost ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define all(v) v.begin(),v.end()
#define pb push_back
#define endl '\n'
#define mp make_pair

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef pair<int,int> pi;
typedef pair<long long,long long> pll;
typedef set<int> si;


/*
typedef tree<int,null_type,less<int>,rb_tree_tag,
tree_order_statistics_node_update> indexed_set;
*/
/*
typedef tree<
pair<int, int>,
null_type,
less<pair<int, int>>,
rb_tree_tag,
tree_order_statistics_node_update> ordered_set;
*/

const ll mod = 1e9 + 7;
const ll modl=998244353;
const double pie=3.1415926535;
                                                    //power
ull power(ull x,ull y){
   if(y==0) return 1;
   else{
     if(y%2==0) return power(x*x,y/2);
     else return x*power(x*x,(y-1)/2);
   }
}

                        //                    Modular Exponentiation

ll mod_power(ll x, ll y, ll m)
{
    ll r = 1;     // Initialize result

    x = x % m; // Update x if it is more than or equal to m

    if (x == 0) return 0; // In case x is divisible by m;

    while (y > 0)
    {
        // If y is odd, multiply x with result
        if (y & 1)
            r = (r*x) % m;

        // y must be even now
        y = y/2;
        x = (x*x) % m;
    }
    return r;
}

                                                      //GCD
ll gcd(ll x,ll y){
   if(y==0)return x;
   return gcd(y,x%y);
}
                                              // SIEVE

/*
bool isPrime[100001];
void sieve(int N) {

        for(int i = 0; i <= N;++i) {
            isPrime[i]=true;
        }
        isPrime[0]=false;
        isPrime[1]=false;

        for(int i = 2; i * i <= N; ++i) {
             if(isPrime[i] == true) {
                 for(int j = i * i; j <= N ;j += i)
                     isPrime[j] = false;
            }
        }
    }
*/

int main(){
    boost;
    int TESTS=1;
    //cin>>TESTS;
    while(TESTS--){
        int n;
        cin>>n;
        set<int>s;
        for(int i=0;i<n;i++){
          int x;
          cin>>x;
          s.insert(x);
        }
        if(s.size()==n)cout<<"YES"<<endl;
        else cout<<"NO"<<endl;
      }
}















Measured memory_bytes: 12952
#include <iostream>
#include <assert.h>
#include <vector>
#include <unordered_map>
#include <queue>
#include <climits>
#include <cmath>
#include <algorithm>
using namespace std;
constexpr int64_t MOD = 1e9 + 7;

void rotate(string& S) {
  int size = (int)S.size();
  for (int i = 0; i < size / 2; i++) {
    char tmp = S[i];
    S[i] = S[size - 1 - i];
    S[size - 1 - i] = tmp;
  }
  return;
}

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

  string S;
  cin >> S;
  int Q;
  cin >> Q;
  vector<char> heads;
  vector<char> tails;
  int numRot = 0;
  for (int i = 0; i < Q; i++) {
    int T;
    cin >> T;
    if (T == 1) {
      numRot++;
    } else {
      int F;
      char C;
      cin >> F;
      cin >> C;
      if ((F == 1 && (numRot % 2 == 0)) || (F == 2 && (numRot % 2 == 1))) {
        heads.emplace_back(C);
      } else {
        tails.emplace_back(C);
      }
    }
  }

  string res;
  if (numRot % 2 == 0) {
    for (int i = (int)heads.size() - 1; i >= 0; i--) {
      res += heads[i];
    }
    res += S;
    for (auto c : tails) {
      res += c;
    }
  } else {
    rotate(S);
    for (int i = (int)tails.size() - 1; i >= 0; i--) {
      res += tails[i];
    }
    res += S;
    for (auto c : heads) {
      res += c;
    }
  }
  cout << res << endl;
  return 0;
}


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



typedef unsigned long ul;
typedef unsigned long long ull;
typedef long long ll;
typedef vector<ll> vint;
typedef vector< vector<ll> > vvint;
typedef vector< vector< vector<ll> > > vvvint;
typedef vector<string> vstring;
typedef vector< vector<string> > vvstring;
typedef vector<char> vchar;
typedef vector< vector<char> > vvchar;
typedef vector<long double> vdouble;
typedef vector< vector<long double> > vvdouble;
typedef vector< vector< vector<long double> > > vvvdouble;
typedef pair<ll,ll> pint;
typedef vector<pint> vpint;
typedef vector<bool> vbool;

#define rep(i,n) for(ll i=0;i<n;i++)
#define repf(i,f,n) for(ll i=f;i<n;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define ALL(obj) (obj).begin(), (obj).end()
// #define LLONG_MAX 9223372036854775806
#define vmax(vec) *max_element(vec.begin(), vec.end())
#define vmin(vec) *min_element(vec.begin(), vec.end())
#define vsort(vec) sort(vec.begin(), vec.end())
#define vsortgr(vec) sort(vec.begin(), vec.end(), greater<ll>())
#define MOD 1000000007
// #define MOD 998244353
// #define MOD LLONG_MAX
const double PI=3.14159265358979323846;

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }




int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0,};




void printv(vint &v){
  for(auto e:v) cout<<e<<" ";
  cout<<endl;
}


int main() {


  cout<<fixed<<setprecision(10);

  int y,m,d;
  scanf("%d/%d/%d", &y, &m, &d);

  if(y*10000 + m*100 + d <= 20190430) puts("Heisei");
  else puts("TBD");


}

//


Measured memory_bytes: 256
n,p=map(int, input().split())
ans=1
m=int(pow(p,1/n))+1
if n==1:
    print(p)
else:
    m=int(pow(p,1/n))+1
    i=2
    c=0
    while(i<=p and i<=m):
        #print('i,p=',i,p)
        if p % i == 0:
            p=p/i
            c=c+1
            if p % i != 0:
                #print('i**(c//n)=',i**(c//n))
                ans = ans * ( i**(c//n) )
                i=i+1
                c=0
        else:
            i=i+1
    print(ans)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
//#include <atcoder/all>

using namespace std;
//using namespace atcoder;
 
#ifdef DEBUG
    #include "debug.h"
    #define dump(...)                                                              \
        DUMPOUT << "  " << string(#__VA_ARGS__) << ": "                            \
                << "[" << to_string(__LINE__) << ":" << __FUNCTION__ << "]"        \
                << endl                                                            \
                << "    ",                                                         \
            dump_func(__VA_ARGS__)
#else
    #define dump(...)
#endif

template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

template<typename T,typename V>
typename enable_if<is_class<T>::value==0>::type
fill_v(T &t,const V &v){t=v;}

template<typename T,typename V>
typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t,const V &v){
  for(auto &e:t) fill_v(e,v);
}

#define int long long
#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define YES puts("YES")
#define Yes puts("Yes")
#define NO  puts("NO")
#define No  puts("No")
#define ALL(v) (v).begin(), (v).end()
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

//*
#define mod 1000000007 /*/
#define mod 998244353 //*/

typedef pair<int, int> P;
#define INF (1LL<<60)
    
void solve(){
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    cout << max({a*c,b*d,a*d,b*c}) << endl;
}


signed main(){
    cout << fixed << setprecision(18);
    cerr << fixed;
    solve();
}


Measured memory_bytes: 3672
#include <bits/stdc++.h>
#define pr(s) std::cout << s << std::endl
#define prb(s) std::cout << s
using namespace std;


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


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

  array<int, 3> val{a+a-1, b+b-1, a+b};

  if (val[0] >= val[1] && val[0] >= val[2]) pr(val[0]);
  else if (val[1] >= val[0] && val[1] >= val[2]) pr(val[1]);
  else pr(val[2]);

  return 0;
}


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

#define INF (int)1e9
#define vi vector<int>
#define pii pair<int, int>
#define pb push_back
#define fi first
#define se second
#define ll long long
#define pq priority_queue
#define qq queue
#define w(n) while(n--)
#define for0(i, n) for(i = 0; i < n; i++)
#define for1(i, n) for(i = 1; i <= n; i++)

#define MAXN 101
ll n, w, peso[MAXN], val[MAXN];
ll dp[MAXN][100001];

int main() {
    ios::sync_with_stdio(0); cin.tie(0);
    cin >> n >> w;
    
    int i;
    for1(i, n) {
        cin >> peso[i] >> val[i];
    }
    
    int j;
    for1(i, n) {
        for1(j, w) {
            if (j - peso[i] >= 0)
                dp[i][j] = max(dp[i-1][j], dp[i-1][j-peso[i]] + val[i]);
            else dp[i][j] = dp[i-1][j];
        }
    }

    cout << dp[n][w] << endl;

    return 0;
}


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

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep3(i,m,n) for(int (i)=m;(i)<=(n);(i)++)
#define rep3rev(i,m,n) for(int (i)=m;(i)>=(n);(i)--)
#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define eb emplace_back

typedef long long ll;
typedef vector<ll> vll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef pair<int, int> pii;

void Main()
{
	int n, m;
	cin >> n >> m;
	cout << n*(n-1)/2 + m*(m-1)/2 << endl;
	return;
}

int main()
{
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Main();
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<stdlib.h>

using namespace std;

int main()
{

    int N; //?????????????????°
    int i, j, k;
    int key;
    cin >> N;

    int* A = (int*)malloc(sizeof(int)*(N+1));

    for (i = 1; i <= N; i++) {
        cin >> A[i];
    }

    for (j = 1; j <= N; j++) {
        k = j - 1;
        key = A[j];
        while (k >= 1 && A[k] > key) {
            A[k + 1] = A[k];
            k = k - 1;
        }
        A[k + 1] = key;


        for (i = 1; i <= N-1; i++) {
            cout << A[i] << " ";
        }
        cout << A[N] << "\n";
    }

 /*   for (i = 1; i <= N; i++) {
        cout << A[i] << " ";
    }*/

}

Measured memory_bytes: 3088
#include <stdio.h>

int N, A[5000], B[5000], C[5000], D[5000];
int point[112][2], ans[112];

int main(void) {
	scanf("%d", &N);
	for (int i = 0; i < N*(N - 1) / 2; ++i) { scanf("%d%d%d%d", &A[i], &B[i], &C[i], &D[i]); }

	for (int i = 0; i < N*(N - 1) / 2; ++i) {
		if (C[i] < D[i]) { point[B[i] - 1][0] += 3; }
		if (C[i] > D[i]) { point[A[i] - 1][0] += 3; }
		if (C[i] == D[i]) { point[A[i] - 1][0]++; point[B[i] - 1][0]++; }
	}

	for (int i = 0; i < N; i++) {
		for (int j = 0; j < N; j++) {
			if (point[i][0] < point[j][0]) {
				ans[i]++;
			}
		}
		printf("%d\n", ans[i] + 1);
	}
	return 0;
}

Measured memory_bytes: 2712
n=int(input())
a=[]
best_cnt=0
[a.append(int(input())) for _ in range(n)]
b = sorted(a)
if len(set(b))==1:
  best=better=b[-1]
else:
  best=list(set(b))[-1]
  better=list(set(b))[-2]
for i in range(n):
  if a[i]==best:
    best_cnt+=1
    
for i in range(n):
  if a[i] == best:
    if best_cnt==1:
      print(better)
    else:
      print(best)
  else:
    print(best)

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

typedef long long ll;

int n,x[15],y[15],p[15],D[15],d[15];
ll ans[16];

int main(){

    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    cin>>n;
    for(int i=0;i<n;i++)cin>>x[i]>>y[i]>>p[i];
    memset(ans,0x3f,sizeof(ans));
    ans[0]=0;
    for(int i=0;i<n;i++){
        D[i]=min(abs(x[i]),abs(y[i]));
        ans[0]+=(ll)p[i]*D[i];
    }
    for(int s=0;s<1<<n;s++){
        for(int t=s;t;t=(t-1)&s){
            memcpy(d,D,sizeof(d));
            for(int i=0;i<n;i++){
                if(s>>i&1){
                    if(t>>i&1){
                        for(int j=0;j<n;j++){
                            d[j]=min(d[j],abs(x[i]-x[j]));
                        }
                    }else{
                        for(int j=0;j<n;j++){
                            d[j]=min(d[j],abs(y[i]-y[j]));
                        }
                    }
                }
            }
            ll cur=0;
            for(int i=0;i<n;i++){
                cur+=(ll)d[i]*p[i];
            }
            ans[__builtin_popcount(s)]=min(ans[__builtin_popcount(s)],cur);
        }
        {
            int t=0;
            memcpy(d,D,sizeof(d));
            for(int i=0;i<n;i++){
                if(s>>i&1){
                    if(t>>i&1){
                        for(int j=0;j<n;j++){
                            d[j]=min(d[j],abs(x[i]-x[j]));
                        }
                    }else{
                        for(int j=0;j<n;j++){
                            d[j]=min(d[j],abs(y[i]-y[j]));
                        }
                    }
                }
            }
            ll cur=0;
            for(int i=0;i<n;i++){
                cur+=(ll)d[i]*p[i];
            }
            ans[__builtin_popcount(s)]=min(ans[__builtin_popcount(s)],cur);
        }
    }
    for(int i=0;i<=n;i++)cout<<ans[i]<<'\n';

    return 0;
}

Measured memory_bytes: 3612
from collections import defaultdict as dd
from collections import deque
N, M = map(int, input().split())
e = dd(list)
inf = 10 ** 9
for _ in range(M):
  u, v = map(int, input().split())
  e[u].append(v + N)
  e[u + N].append(v + 2 * N)
  e[u + 2 * N].append(v)
S, T = map(int, input().split())
S += 2 * N
T += 2 * N
stopped = [inf] * (3 * (N + 1))
Q = deque()
Q.append(S)
stopped[S] = 0
while len(Q) != 0:
  p = Q.popleft()
  if stopped[p] >= stopped[T]:
    break
  for q in e[p]:
    if stopped[q] > stopped[p] + 1:
      Q.append(q)
      stopped[q] = stopped[p] + 1
if stopped[T] == inf:
  print(-1)
else:
  print(stopped[T] // 3)

Measured memory_bytes: 79624
import Data.List
import Data.Array
getInts = do
    x <- getLine
    let y = map (read::String->Int) (words x) 
    return y
 
 
change [] n = []
change s n = 
    if isPrefixOf "AC" s then 
        [n] ++ change (tail s) (n + 1)
    else 
        [n] ++ change (tail s) n
 
solve' x q = do
    [a,b] <- getInts
    print $ (x ! b) - (x ! a)
    if q > 1 then solve' x (q-1)
    else return ()
 
solve s n q = 
    solve' x q
    where
        x = listArray (0,n) ([0]++(change s 0))
 
main::IO()
main=do
    [n,q] <- getInts
    s <- getLine
    solve s n q

Measured memory_bytes: 8788
#define LOCAL
#define _USE_MATH_DEFINES
#include <array>
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <complex>
#include <cmath>
#include <numeric>
#include <bitset>
#include <functional>
#include <random>
#include <ctime>

using namespace std;

template <typename A, typename B>
ostream& operator <<(ostream& out, const pair<A, B>& a) {
  out << "(" << a.first << "," << a.second << ")";
  return out;
}
template <typename T, size_t N>
ostream& operator <<(ostream& out, const array<T, N>& a) {
  out << "["; bool first = true;
  for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
  return out;
}
template <typename T>
ostream& operator <<(ostream& out, const vector<T>& a) {
  out << "["; bool first = true;
  for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
  return out;
}
template <typename T, class Cmp>
ostream& operator <<(ostream& out, const set<T, Cmp>& a) {
  out << "{"; bool first = true;
  for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "}";
  return out;
}
#ifdef LOCAL
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
#else
#define trace(...) 42
#endif
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}

typedef long long int64;
typedef pair<int, int> ii;
const int INF = 1 << 29;
const int MOD = 1e9 + 7;
mt19937 mrand(random_device{}());
int rnd(int x) { return mrand() % x; }

struct fast_ios {
  fast_ios() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
  };
} fast_ios_;

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


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

#define int long long
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define all(v) (v).begin(),(v).end()
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
#define pb push_back
#define fi first
#define se second
template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

int H,W,N;

signed main(){
    vpint vec;
    cin>>H>>W>>N;
    vpint lis;
    rep(i,N){
        int a,b;
        cin>>a>>b;
        for(int dx=-2;dx<=0;dx++){
            for(int dy=-2;dy<=0;dy++){
                int y=a+dy;
                int x=b+dx;
                if(y>=1&&x>=1&&y+2<=H&&x+2<=W){
                    lis.pb(pint(y,x));
                }
            }
        }
        vec.pb(pint(a,b));
    }

    sort(all(vec));
    sort(all(lis));
    lis.erase(unique(all(lis)),lis.end());

    //rep(i,lis.size())cout<<"\t"<<lis[i].fi<<" "<<lis[i].se<<endl;

    int sum[10]={};
    rep(i,lis.size()){
        int y,x;
        tie(y,x)=lis[i];
        int cnt=0;
        for(int dy=0;dy<=2;dy++){
            for(int dx=0;dx<=2;dx++){
                if(binary_search(all(vec),pint(y+dy,x+dx)))cnt++;
            }
        }
        sum[cnt]++;
    }

    sum[0]=(H-2)*(W-2)-lis.size();
    rep(i,10)cout<<sum[i]<<endl;
    return 0;
}


Measured memory_bytes: 18536
loop {
    e = gets.to_i
    break if e == 0
    min = e
    (0..(e**(1.0/3)).to_i+1).each{|z|
        z3 = z * z * z
        next if e - z3 < 0
        y = Math.sqrt(e - z3).to_i
        y2 = y * y
        x = e - z3 - y2
        m = z + y + x
        min = m if m < min
    }
    p min
}

Measured memory_bytes: 6220
package main

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

var sc, wr = bufio.NewScanner(os.Stdin), bufio.NewWriter(os.Stdout)

func scanString() string   { sc.Scan(); return sc.Text() }
func scanRunes() []rune    { return []rune(scanString()) }
func scanInt() int         { a, _ := strconv.Atoi(scanString()); return a }
func scanInt64() int64     { a, _ := strconv.ParseInt(scanString(), 10, 64); return a }
func scanFloat64() float64 { a, _ := strconv.ParseFloat(scanString(), 64); return a }

func scanInts(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = scanInt()
	}
	return res
}

func debug(a ...interface{}) { fmt.Fprintln(os.Stderr, a...) }

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}
func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

//•*¨*•.¸¸♪main•*¨*•.¸¸♪(　-ω-)ノ　(　・ω・)
func main() {
	defer wr.Flush()
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 10000), 1001001)

	n := scanInt()
	x := scanString()

	memo := make([]int, n+1)
	for i := 0; i < n; i++ {
		c := 0
		for b := i + 1; b != 0; b >>= 1 {
			if b&1 == 1 {
				c++
			}
		}
		memo[i+1] = memo[(i+1)%c] + 1
	}

	cn := 0
	for _, s := range x {
		if s == '1' {
			cn++
		}
	}

	a1, a2 := 0, 0
	p1, p2 := 1, 1
	for i := 0; i < n; i++ {
		if x[n-1-i] == '1' {
			if cn != 1 {
				a1 = (a1 + p1) % (cn - 1)
			}
			a2 = (a2 + p2) % (cn + 1)
		}
		if cn != 1 {
			p1 = p1 * 2 % (cn - 1)
		}
		p2 = p2 * 2 % (cn + 1)
	}

	ans := make([]int, n)
	p1, p2 = 1, 1
	for i := 0; i < n; i++ {
		c := cn
		a := 0
		if x[n-1-i] == '1' {
			if cn != 1 {
				c--
				a = (a1 - p1%c + c) % c
			} else {
				ans[n-1-i] = 0
				continue
			}
		} else {
			c++
			a = (a2 + p2%c) % c
		}
		ans[n-1-i] = memo[a] + 1
		if cn != 1 {
			p1 = p1 * 2 % (cn - 1)
		}
		p2 = p2 * 2 % (cn + 1)
	}

	for i := 0; i < n; i++ {
		fmt.Fprintln(wr, ans[i])
	}
}


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

bool sort_pair_sec(pair<int, int> l, pair<int, int> r){
    return l.second < r.second;
}

int main(){
    int N;
    cin >> N;
    vector<pair<int, int>> AB(N);
    int max_h = 0;
    ll sum_h = 0;
    for(int i=0; i<N; i++){
        cin >> AB.at(i).first >> AB.at(i).second;
        max_h = max(max_h, AB.at(i).second);
        sum_h += AB.at(i).first;
    }
    if(max_h < sum_h){
        cout << "No" << endl;
        return 0;
    }

    sort(AB.begin(), AB.end(), sort_pair_sec);

    sum_h = 0;
    for(pair<int, int> ab : AB){
        sum_h += ab.first;
        // cout << "sum_h:" << sum_h << " ab.second:" << ab.second << endl;
        if(sum_h > ab.second){
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;

    return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define all(x) x.begin(),x.end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
template<class T> inline bool chmax(T&a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T&a,T b){if(a>b){a=b;return 1;}return 0;}
typedef long long ll;

int n,m,a,b,c;
string s,t;

int main() {
  cin >> n;
  int h[100005];
  rep(i,n) cin >> h[i];
  int ans=0,l; bool ok,f;
  while(1){
    ok=true,f=false; l=0;
    rep(i,n){
      if(h[i]>0) f=true,ok=false;
      if((h[i]==0 || h[n-1]>0 && i==n-1) && f){
        for(int j=l;j<=i;j++)if(h[j]>0) h[j]--;
        ans++,l=i+1; f=false;
      }
    } 
    if(ok) break;
  }
  cout << ans << endl;
}

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

vector<int> prime;
int prime_factor[1010] = {};

void PrimeEnumeration(int n) {
  FOR(i, 2, n+1) {
    bool flag = true;
    FOR(j, 2, i) {
      if (j*j > i) break;
      if (i%j == 0) {
        flag = false;
        break;
      }
    }
    if (flag) prime.push_back(i);
  }
}

void PrimeFactorization(int n) {
  for (int i = 0; n >= prime[i];) {
    if (n%prime[i] == 0) {
      n /= prime[i];
      prime_factor[prime[i]]++;
    } else {
      i++;
    }
  }
}

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

  int n;
  cin >> n;

  PrimeEnumeration(1000);

  rep(i, n+1) {
    PrimeFactorization(i);
  }

  ll ans = 1;
  rep(i, n+1) {
    ans = ans * (prime_factor[i]+1) % MOD;
  }

  cout << ans << endl;
}

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

int main() {
  string L[] = {"SUN","MON","TUE","WED","THU","FRI","SAT"};
  string S;
  cin >> S;

  rep(i,7) {
    if(S == L[i]) {
      cout << (7-i) << endl;
    }
  }

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <map>
#include <string>

#define ll long long
#define vi vector<int>
#define vll vector<ll>
#define vvi vector<vector<int>>
#define INF (int)1e9
#define fora(i,a,b) for(ll i=a;i<b;i++)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define si size()
#define be begin()
#define en end()
#define le length()
#define mp(x,y) make_pair(x,y)
#define mii map<int,int>
using namespace std;

int main()
{   ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    
    ll n,r;
    cin>>n>>r;
    if(n>=10)
        cout<<r;
        else
        cout<<r+100*(10-n);
    return 0;
}




Measured memory_bytes: 256
def N(): return int(input())
def NM():return map(int,input().split())
def L():return list(NM())
def LN(n):return [N() for i in range(n)]
def LL(n):return [L() for i in range(n)]
n=N()
l=L()
l.sort()
def im():
    print("Impossible")
    quit()
def po():
    print("Possible")
    quit()
if l[0]!=(l[-1]+1)//2:
    im()
import collections
c=collections.Counter(l)
if l[-1]%2:
    if c[l[0]]!=2:
        im()
    for i in range(l[0]+1,l[-1]+1):
        if c[i]<2:
            im()
    po()
if c[l[0]]!=1:
    im()
for i in range(l[0]+1,l[-1]+1):
    if c[i]<2:
        im()
po()

Measured memory_bytes: 3316
#include<stdio.h>
int main(void){
	int n,i,a,b,cnt=0;
	int p[20];
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%d",&p[i]);
	}
	for(i=1;i<n-1;i++){
		a=p[i-1];
		b=p[i+1];
		if(p[i+1]<p[i-1]){
			a=p[i+1];
			b=p[i-1];
		}
		if(a<p[i]&&p[i]<b){
			cnt++;
		}
	}
	printf("%d",cnt);
	return 0;
}

Measured memory_bytes: 1736
class FermatCombination():
    def __init__(self, size, mod):
        self.mod = mod
        self.factrial = [1]
        self.inverse = [1]
        for i in range(1, size + 1):
            self.factrial.append((self.factrial[i-1]*i) % self.mod)
            self.inverse.append(self.modpow(self.factrial[i], self.mod - 2) % self.mod)

    def modpow(self, x, n):
        ret = 1
        while(n > 0):
            if n & 1:
                ret = ret * x % self.mod
            x = x * x % self.mod
            n >>= 1
        return ret

    def combine(self, n, k):
        return self.factrial[n] * self.inverse[k] % self.mod * self.inverse[n - k] % self.mod


N, K = map(int, input().split())
mod = 10**9+7

fermat = FermatCombination(N + 2, mod)

for i in range(1, K+1):
    if N-K+1 < i:
        print(0)
    else:
        print(fermat.combine(N-K+1, i) * fermat.combine(K-1, i-1) % mod)




Measured memory_bytes: 3444
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Security;
using System.Xml.Serialization;

namespace AtCoderCs
{

    class Program
    {

        const int Mod = 1000000007;

        static void Main()
        {

            var args = Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray();
            var result = 0;
            if (args[3] <= args[0])
            {

                Console.WriteLine(args[3]);

            }
            else if (args[3] <= args[1])
            {

                Console.WriteLine(args[0]);

            }
            else
            {

                Console.WriteLine(args[0] - (args[3] - (args[1] + args[0])));

            }

        }


    }
}


Measured memory_bytes: 28188
import java.util.*;

public class Main{
	public static void main(String args[]) {

		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int M = sc.nextInt();
		int L = Integer.MIN_VALUE;
		int R = Integer.MAX_VALUE;
		for(int i = 0; i < M; i++) {
			L = Math.max(L, sc.nextInt());
			R = Math.min(R, sc.nextInt());
		}
		sc.close();
		System.out.println(Math.max(R - L + 1, 0));
	}
}

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

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

  string s, t;
  cin >> s >> t;
  int ans = 1e9;
  for (int i = 0; i < (int) s.size(); i++) {
    int cost = 0;
    for (int j = 0; j < (int) t.size(); j++) {
      if (i + j >= (int) s.size()) {
        cost = 1e9;
        break;
      }
      if (s[i + j] != t[j]) {
        cost += 1;
      }
    }
    ans = min(ans, cost);
  }
  cout << ans << "\n";
  return 0;
}


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

int main(){
    std::vector<int> bou(5, 0);
    for (int i = 0; i < 5; ++i){
        cin >> bou[i];
    }
    int k;
    cin >> k;
    if (bou[4] - bou[0] <= k){
        cout << "Yay!" << endl;
    }else{
        cout << ":(" << endl;
    }
}

Measured memory_bytes: 256
from itertools import *
N,M = map(int,input().split())
C = [list(map(int,input().split())) for n in range(N)]
print(max([sum(sorted([i*x+j*y+k*z for x,y,z in C],reverse=True)[:M]) for i,j,k in product([-1,1],[-1,1],[-1,1])]))

Measured memory_bytes: 9456
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG //これつけるとA[N]でもいいらしい
//for文のマクロ
 #define rep(i, n) for (int i = 0; i < (int)(n); i++)
 #define big 1000000007
int main(){
    int a,b;
    cin>>a>>b;
    string s;
    cin>>s;
    bool ans = true;
    rep(i,a+b+1){
        //cout<<s[i]-'0'<<endl;
        if(i==a){
            if(s[i]!='-'){
                ans = false;
            }
        }
        else{
            if(s[i]-'0'<0 || s[i]-'0'>9){
                ans = false;
            }
        }
    }
    if(ans){
        cout<<"Yes"<<endl;
    }
    else{
        cout<<"No"<<endl;
    }
}

Measured memory_bytes: 256
// Youtube解説AC
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<int(N);++i)
using ll = long long;
const int MOD = 1e9 + 7;
const int INF = 1001001001;
// const ll INF = 1000000000000000000LL;

int main() {
    ll x,y,a,b,c;
    cin >> x >> y >> a >> b >> c;
    vector<ll> p(a);
    vector<ll> q(b);
    vector<ll> r(c);
    rep(i,a) cin >> p[i];
    rep(i,b) cin >> q[i];
    rep(i,c) cin >> r[i];
    sort(p.begin(),p.end(),greater<ll>());
    sort(q.begin(),q.end(),greater<ll>());
    vector<ll> pq;
    rep(i,x) pq.push_back(p[i]);
    rep(i,y) pq.push_back(q[i]);
    rep(i,c) pq.push_back(r[i]);
    sort(pq.begin(),pq.end(),greater<ll>());
    ll sum = 0;
    rep(i,x+y)
        sum+=pq[i];
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 9744
from random import *
D=int(input())
C=list(map(int,input().split()))
S=[list(map(int,input().split())) for i in range(D)]
X=[0]*26
XX=[0]*26
P=[]
for i in range(D):
  for j in range(26):
    X[j]+=C[j]
    XX[j]+=X[j]
  P.append([])
  for j in range(26):
    P[i].append(j)
  P[i].sort(reverse=True,key=lambda x:X[x]+S[i][x])
  XX[P[i][0]]-=X[P[i][0]]
  X[P[i][0]]=0
SC,SC2=0,0
X=[0]*26
for i in range(D):
  SC+=S[i][P[i][0]]
  for j in range(26):
    X[j]+=C[j]
  X[P[i][0]]=0
  SC-=sum(X)
YY=[]
for i in range(D):
  for k in range(2):
    SC2=SC
    YY=XX[:]
    SC2-=S[i][P[i][0]]
    SC2+=S[i][P[i][k+1]]
    for j in range(26):
      X[j]=0
    YY[P[i][0]],YY[P[i][k+1]]=0,0
    for j in range(D):
      if j==i:
        Z=P[j][k+1]
      else:
        z=P[j][0]
      X[P[i][0]]+=C[P[i][0]]
      X[P[i][k+1]]+=C[P[i][k+1]]
      X[Z]=0
      YY[P[i][0]]+=X[P[i][0]]
      YY[P[i][k+1]]+=X[P[i][k+1]]
    if SC2-sum(YY)>SC-sum(XX):
      P[i].insert(0,P[i][k+1])
      del P[i][k+1]
      XX=YY[:]
      SC=SC2
for i in range(D):
  print(P[i][0]+1)

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

int main(){
	string s;
	cin>>s;
	
	char np='A';
	int ans=0;
	
	for(int i=0;i<s.size();i++){
		if(np>=s[i]){
			ans++;
		}
		np=s[i];
	}
	
	cout<<ans<<endl;
	
	return 0;
}

Measured memory_bytes: 3156
#include <bits/stdc++.h>
using namespace std;
vector<int> a, b;
int n, t, tmp;
int main(){
    cin>>n;
    for(int i = 0; i < n; i++){
        cin>>tmp;
        a.push_back(tmp);
    }
    for(int i = 0; i < n; i++){
        cin>>tmp;
        b.push_back(tmp);
    }
    if(a>b) swap(a,b);
    do{
        if(a==b) break;
        t++;
    }while(next_permutation(a.begin(),a.end()));
    cout<<t;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<algorithm>
#include<math.h>
using namespace std;
const double EPS = 1e-10;
const double INF = 1e+10;
const double PI = acos(-1);
int sig(double r) { return (r < -EPS) ? -1 : (r > +EPS) ? +1 : 0; }
inline double ABS(double a){return max(a,-a);}
struct Pt {
	double x, y;
	Pt() {}
	Pt(double x, double y) : x(x), y(y) {}
	Pt operator+(const Pt &a) const { return Pt(x + a.x, y + a.y); }
	Pt operator-(const Pt &a) const { return Pt(x - a.x, y - a.y); }
	Pt operator*(const Pt &a) const { return Pt(x * a.x - y * a.y, x * a.y + y * a.x); }
	Pt operator-() const { return Pt(-x, -y); }
	Pt operator*(const double &k) const { return Pt(x * k, y * k); }
	Pt operator/(const double &k) const { return Pt(x / k, y / k); }
	double ABS() const { return sqrt(x * x + y * y); }
	double abs2() const { return x * x + y * y; }
	double arg() const { return atan2(y, x); }
	double dot(const Pt &a) const { return x * a.x + y * a.y; }
	double det(const Pt &a) const { return x * a.y - y * a.x; }
};
double tri(const Pt &a, const Pt &b, const Pt &c) { return (b - a).det(c - a); }
int iSP(Pt a, Pt b, Pt c) {
	int s = sig((b - a).det(c - a));
	if (s) return s;
	if (sig((b - a).dot(c - a)) < 0) return -2; // c-a-b
	if (sig((a - b).dot(c - b)) < 0) return +2; // a-b-c
	return 0;
}
int iLL(Pt a, Pt b, Pt c, Pt d) {
	if (sig((b - a).det(d - c))) return 1; // intersect
	if (sig((b - a).det(c - a))) return 0; // parallel
	return -1; // correspond
}
Pt pLL(Pt a, Pt b, Pt c, Pt d) {
	b = b - a; d = d - c; return a + b * (c - a).det(d) / b.det(d);
}

pair<int,double> dp[1<<10][11][11];
Pt p[12];
int main(){
	int a;
	while(scanf("%d",&a),a){
		for(int i=0;i<a;i++){
			double x,y;
			scanf("%lf%lf",&x,&y);
			p[i]=Pt(x,y);
		}
		for(int i=0;i<(1<<a);i++)for(int j=0;j<a;j++)for(int k=0;k<a;k++)
			dp[i][j][k]=make_pair(999999999,999999999);
		for(int i=0;i<a;i++){
			for(int j=0;j<a;j++){
				if(i==j)continue;
				int to=(1<<i)+(1<<j);
				for(int k=0;k<a;k++){
					if(iSP(p[i],p[k],p[j])==2)to|=(1<<k);
				}
				dp[to][i][j]=make_pair(0,(p[i]-p[j]).ABS());
			}
		}
		for(int i=0;i<(1<<a);i++){
			for(int j=0;j<a;j++)for(int k=0;k<a;k++){
				if(dp[i][j][k].first>99999)continue;
				for(int l=0;l<a;l++){
					int to=i|(1<<l);
					for(int m=0;m<a;m++){
						if(iSP(p[k],p[m],p[l])==2)to|=(1<<m);
					}
					dp[to][k][l]=min(dp[to][k][l],make_pair(dp[i][j][k].first+1,dp[i][j][k].second+(p[k]-p[l]).ABS()));
				}
				for(int l=0;l<a;l++)for(int m=0;m<a;m++){
					if(l==m)continue;
					if(iLL(p[j],p[k],p[l],p[m])!=1)continue;
					Pt t=pLL(p[j],p[k],p[l],p[m]);
					if(iSP(p[j],p[k],t)==2&&iSP(t,p[l],p[m])==2){
						int to=i|(1<<l)|(1<<m);
						for(int n=0;n<a;n++){
							if(iSP(t,p[n],p[m])==2)to|=(1<<n);
						}
						dp[to][l][m]=min(dp[to][l][m],make_pair(dp[i][j][k].first+1,dp[i][j][k].second+(t-p[k]).ABS()+(p[m]-t).ABS()));
					}
				}
			}
		}
		pair<int,double>ret=make_pair(999999999,99999999);
		for(int i=0;i<a;i++)for(int j=0;j<a;j++)ret=min(ret,dp[(1<<a)-1][i][j]);
		printf("%d %.12f\n",ret.first,ret.second);
	}
}

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

Measured memory_bytes: 1536
package main
import (
  "bufio"
  "fmt"
  "os"
)
func main() {
  var n int
  fmt.Scan(&n)
  var s1 string = query(0)
  if s1 == "Vacant" { os.Exit(0) }
  var sn string = query(n-1)
  if sn == "Vacant" { os.Exit(0) }
  var min,max int = 0,n-1
  for max-min > 1 {
    var m int = (min+max)/2
    var sm string = query(m)
    if sm == "Vacant" { os.Exit(0) }
    if ((m-min)%2 == 0) == (sm != s1) {
      max = m
      sn = sm
    }
    if ((max-m)%2 == 0) == (sm != sn) {
      min = m
      s1 = sm
    }
  }
}
var w = bufio.NewWriter(os.Stdout)
func query(i int) string {
  var s string
  fmt.Fprintln(w,i)
  _ = w.Flush()
  fmt.Scan(&s)
  return s
}

Measured memory_bytes: 1108
#include<bits/stdc++.h>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
using namespace std;

int main(){
	long long n;
	while(1){
		cin>>n;
		if(!n)break;
		char from[n],to[n];
		bool check[n];
		rep(i,n){
			cin>>from[i]>>to[i];
		}
		char desk;
		long long m;
		string ans="";
		cin>>m;
		for(long long i=0;i<m;i++){
			cin>>desk;
			for(long long j=0;j<n;j++)check[j]=false;
			int cnt=0;
			for(long long j=0;j<n;j++){
				if(desk==from[j]){
					if(!check[j]){
						ans+=to[j];
						check[j]=true;
						cnt++;
					}	
				}
				if(cnt)break;
			}
			if(!cnt)ans+=desk;
		}
		cout<<ans<<endl;
	}
	return 0;
}

Measured memory_bytes: 1336
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>
#include <iostream>
#include <sstream>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <numeric>
#include <algorithm>
#include <bitset>
#include <complex>
#include <array>
#include <list>
#include <stack>
#include <valarray>

using namespace std;

typedef unsigned uint;
typedef long long Int;
typedef unsigned long long UInt;

const int INF = 1001001001;
const Int INFLL = 1001001001001001001LL;

template<typename T> void pv(T a, T b) { for (T i = a; i != b; ++i) cout << *i << " "; cout << endl; }
template<typename T> void chmin(T& a, T b) { if (a > b) a = b; }
template<typename T> void chmax(T& a, T b) { if (a < b) a = b; }
int in() { int x; scanf("%d", &x); return x; }
double fin() { double x; scanf("%lf", &x); return x; }
Int lin() { Int x; scanf("%lld", &x); return x; }

int N;
struct Line {
  Int A, B, C;
} L[50050];

int B[55555];
void init() {
  for (int i = 0; i <= N; ++i) {
    B[i] = 0;
  }
}
void add(int x) {
  while (x <= N) {
    ++B[x];
    x += x & -x;
  }
}
int sum(int x) {
  int s = 0;
  while (x > 0) {
    s += B[x];
    x -= x & -x;
  }
  return s;
}

double solve() {
  sort(L, L + N, [] (const Line& a, const Line& b) {
    return -a.A / (double)a.B > -b.A / (double)b.B;
  });
  // for(int i=0;i<N;++i)cerr<<L[i].A<<' '<<L[i].B<<' '<<L[i].C<<endl;

  Int P = (Int)N * (N - 1) / 2;
  P = (P + 1) / 2;

  double lo = -1e12, hi = 1e12;
  for (int loop = 0; loop < 80; ++loop) {
    double M = (hi + lo) / 2;
    vector<pair<double, int>> ps;
    for (int i = 0; i < N; ++i) {
      ps.emplace_back((-L[i].A * M + L[i].C) / L[i].B, i + 1);
    }
    sort(ps.begin(), ps.end());
    reverse(ps.begin(), ps.end());
    // cerr<<M<<": ";
    // for (int i=0;i<N;++i)cerr<<"("<<ps[i].first<<','<<ps[i].second<<")";cerr<<endl;

    Int tt = 0;
    init();
    for (int i = 0; i < N; ++i) {
      tt += sum(ps[i].second);
      add(ps[i].second);
    }

    if (tt < P) {
      lo = M;
    } else {
      hi = M;
    }
  }
  return (hi + lo) / 2;
}

int main() {
  N = in();
  for (int i = 0; i < N; ++i) {
    L[i].A = lin();
    L[i].B = lin();
    L[i].C = lin();
  }

  const double X = solve();
  for (int i = 0; i < N; ++i) {
    swap(L[i].A, L[i].B);
  }
  const double Y = solve();

  printf("%.12f %.12f\n", X, Y);

  return 0;
}


Measured memory_bytes: 3480
#include<iostream>
#include<stdlib.h>

#define N 100000

int n;
long a[N];
long sum[N];

int input(){
	std::cin >> n;
	std::cin >> a[0];
	sum[0] = a[0];
	for( int i = 1; i < n; i++ ){
		std::cin >> a[i];
		sum[i] = sum[i-1] + a[i];
	}
	return 0;
}

int run(){
	/*
	for( int i = 0; i < n; i++ ){
		std::cout << sum[i] << ",";
	}
	std::cout << std::endl;
	*/long r1 = 0, r2 = 0;
	// positive
	long s = 0;
	long bef = -1;
	long k = 0;
	for( int i = 0; i < n; i++ ){
		k = 0;
		if( (sum[i] + s) * bef >= 0 ){
			k = -(bef + (sum[i]+s));
			r1 += labs(k);
			s += k;
		}
		//std::cout << k << ",";
		bef *= (-1);
	}
	//std::cout << std::endl;
	// negative
	s = 0;
	bef = 1;
	for( int i = 0; i < n; i++ ){
		k = 0;
		if( (sum[i]+s) * bef >= 0 ){
			k = -(bef + (sum[i]+s));
			r2 += labs(k);
			s += k;
		}
		//std::cout << "(" <<  k << "," << sum[i]+s << "), ";
		bef *= (-1);
	}
	//std::cout << std::endl;
	if( r1 < r2 ){
		std::cout << r1 << std::endl;
	}else{
		std::cout << r2 << std::endl;
	}
	return 0;
}

int main(){
	input();
	run();
	return 0;
}

Measured memory_bytes: 1792
import queue

n, q = map(int, input().split())
que = queue.Queue(n)

for i in range(n):
    name, time = input().split()
    que.put([name, int(time)])

c_time = 0
while True:
    try:
        name, time = que.get(block=False)
    except queue.Empty:
        break
    else:
        if time > q:
            que.put([name, time - q])
            c_time += q
        else:
            c_time += time
            print(name, c_time, sep=' ')



Measured memory_bytes: 14428
#include<bits/stdc++.h>
using namespace std;
#define F(i,s,e) for(int i=s;i<e;++i)

int main()
{
    int a[3][3];
    F(i,0,3){
        F(j,0,3){
            cin >> a[i][j];
        }
    }
    int n;
    cin >> n;
    int b;
    F(i,0,n){
        cin >> b;
        F(i,0,3){
            F(j,0,3){
                if(a[i][j]==b) a[i][j]=-1;
            }
        }
    }
    bool f=false;
    F(i,0,3){
        if(a[i][0]==a[i][1] && a[i][1]==a[i][2]) f=true;
    }
    F(i,0,3){
        if(a[0][i]==a[1][i] && a[1][i]==a[2][i]) f=true;
    }
    if(a[0][0]==a[1][1] && a[1][1]== a[2][2]) f=true;
    if(a[0][2]==a[1][1] && a[1][1]==a[2][0]) f=true;
    if(f) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

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

N = int(input())
A = [list(map(int, input().split(' '))) for _ in range(2)]
ans = 0
total = 0
for j in range(N):
    for m in range(j+1):
        total += A[0][m]
    for n in range(j, N):
        total += A[1][n]
    ans = max(ans, total)
    total = 0
print(ans)

Measured memory_bytes: 3064