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

using namespace std;
#define ll long long
#define ull unsigned long long
#define all(x) x.begin(), x.end()
typedef vector<ll> vll;
typedef vector<int> vi;
const ll N = 1e7 + 10;
const int M = 1e9 + 7;
const double eps = 1e-9;
ll nod[N];

int main() {
    ll m, n, sum;
    cin >> m >> n >> sum;
    vll a(m), b(n);
    for (int i = 0; i < m; ++i) {
        cin >> a[i];
    }
    for (int i = 0; i < n; ++i) {
        cin >> b[i];
    }
    vll pa(m), pb(n);
    for (int i = 0; i < m; ++i) {
        pa[i] = (i == 0 ? a[i] : a[i] + pa[i - 1]);
    }
    for (int i = 0; i < n; ++i) {
        pb[i] = (i == 0 ? b[i] : b[i] + pb[i - 1]);
    }
    int ans = 0;
    for (int i = 0; i < m && pa[i] <= sum; ++i) {
        ll rem = sum - pa[i];
        int j = upper_bound(all(pb), rem) - pb.begin();
        ans = max(ans, i + 1 + j);
    }
    for (int i = 0; i < n && pb[i] <= sum; ++i) {
        ll rem = sum - pb[i];
        int j = upper_bound(all(pa), rem) - pa.begin();
        ans = max(ans, i + 1 + j);
    }
    cout << ans << endl;
}



Measured memory_bytes: 9596
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iomanip>
using namespace std;
int a,b,c,x,d;
 
int main()
{
int wry =78;
    cin>>a>>b>>c>>x;
    for(int i = 0;i <= a;i ++)
    {
        for(int j = 0;j <= b;j ++)
        {
            for(int k = 0;k <= c;k ++)
                if(i * 500 + j * 100 + k * 50 == x)d ++;
        }
    }
    cout<<d<<endl;
}//parshant

Measured memory_bytes: 256
n, m = map(int, input().split())
a = list(map(int, input().split()))
dp = [0] * (n+1)
for i in range(n) :
    dp[i+1] = (dp[i] + a[i]) % m

dp = sorted(dp)

cnt = 1
now = dp[0]
ans = 0
for i in range(1,n+1) :
    if now == dp[i] :
        cnt += 1
    elif now != dp[i] :
        ans += cnt * (cnt-1) // 2
        now = dp[i]
        cnt = 1
else :
    ans += cnt * (cnt-1) // 2

print(ans)


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

using namespace std;
using ll = long long;

ll lcm(ll a, ll b) {
    return (a * (b / __gcd(a, b)));
}

void fileIO() {
    #ifdef ROBIN
        freopen("in", "r", stdin);
        freopen("out", "w", stdout);
    #endif // ROBIN
}

int main() {
    // optimize();
    fileIO();
    int n; ll m;
    scanf("%d %lld", &n, &m);
    ll l = 1;
    ll a[n];
    for (int i = 0; i < n; i++) {
        ll x; scanf("%lld", &x);
        x /= 2;
        l = lcm(l, x);
        a[i] = x;
    }

    for (int i = 0; i < n; i++) {
        if ((l / a[i]) % 2 == 0) {
            printf("0\n");
            return 0;
        }
    }

    ll ans = m / l;
    printf("%lld\n", (ll) ceil(ans / 2.0));
}


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

int A[9][9], N, X;
bool B[105];

main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	for (int i = 1; i <= 3; i++) for (int j = 1; j <= 3; j++)
		cin >> A[i][j];
	cin >> N;
	for (int i = 1; i <= N; i++) cin >> X, B[X] = 1;;
	for (int i = 1; i <= 3; i++) for (int j = 1; j <= 3; j++)
		if (B[A[i][j]]) A[i][j] = 1;
		else A[i][j] = 0;
	bool C = (A[1][1] && A[2][2] && A[3][3]) || (A[1][3] && A[2][2] && A[3][1]);
	for (int i = 1; i <= 3; i++) {
		bool y = 1;
		for (int j = 1; j <= 3; j++) if (!A[i][j]) y = 0;
		C |= y;
	}
	for (int j = 1; j <= 3; j++) {
		bool y = 1;
		for (int i = 1; i <= 3; i++) if (!A[i][j]) y = 0;
		C |= y;
	}
	cout << (C ? "Yes" : "No") << '\n';
}


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

int main(){

    string s;
    cin>>s;
    
    int ans=0;
    rep(i,s.size()-1)
        if(s[i]!=s[i+1])
            ans++;
    
    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 512
N, X = map(int, input().split())
B = [0] * (N + 1)
P = [1] * (N + 1)
for i in range(N):
  B[i + 1] = 2 * B[i] + 2
  P[i + 1] = 2 * P[i] + 1
S = [B[i] + P[i] for i in range(N + 1)]
cnt = 0
def burg(L, X):
  cnt = 0
  if X <= L:
    return 0
  if L == 0:
    return 1
  if X <= S[L - 1] + 1:
    return burg(L - 1, X - 1)
  if X == S[L]:
    return P[L]
  else:
    return P[L - 1] + 1 + burg(L - 1, X - S[L - 1] - 2)
print(burg(N, X))

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

using namespace std;
typedef long long ll;

#define out(ans) cout << ans << endl
#define in(n) cin >> n
#define floop(i, N) for (ll i = 0; i < N; i++)
#define floop1(i, N) for (ll i = 1; i <= N; i++)
#define floopi(i, j, N) for (ll j = i + 1; j < N; j++)

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

constexpr ll inf = 1e18;

void solve();

int main()
{
    solve();
}

void solve()
{
    ll n, W;
    in(n);
    in(W);
    ll w[n], v[n];
    floop(i, n)
    {
        in(w[i]);
        in(v[i]);
    }
    ll dp[n + 1][W + 1];
    floop(i, n + 1)
    {
        floop(j, W + 1)
        {
            dp[i][j] = 0;
        }
    }
    floop(i, n)
    {
        floop(j, W + 1)
        {
            if (j - w[i] >= 0)
                chmax(dp[i + 1][j], dp[i][j - w[i]] + v[i]);
            chmax(dp[i + 1][j], dp[i][j]);
        }
    }
    out(dp[n][W]);
}

Measured memory_bytes: 79104
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, n) for (int i = (int)(n); i >= 0; i--)
#define REP(i, m, n) for (int i = (int)(m); i <= (int)(n); i++)
#define all(v) v.begin(), v.end()
typedef long long ll;

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

const long long INF = 1LL << 60;

int main(){
  int n; cin >> n;
  vector<int> x(n), y(n), h(n);
  rep(i, n) cin >> x[i] >> y[i] >> h[i];

  bool ok;
  int CX, CY, H;
  rep(cx, 101){
    rep(cy, 101){
      rep(i, n) if(h[i] != 0){
        H = abs(x[i]-cx) + abs(y[i]-cy) + h[i];
        break;
      }
      ok = true;
      rep(i, n){
        if(h[i] != 0 && H != abs(x[i]-cx) + abs(y[i]-cy) + h[i]){
          ok = false;
          break;
        }
        if(h[i] == 0 && H - abs(x[i]-cx) - abs(y[i]-cy) > 0){
          ok = false;
          break;
        }
      }
      if(ok){
        CX = cx;
        CY = cy;
        cx = 101;
        break;
      }
    }
  }

  cout << CX << " " << CY << " " << H << endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string.h>
#include <vector>
#include <algorithm>
#include <cmath>
#include <map>
#include <functional>
#include <cassert>
#include <utility>
#include <stack>
#include <queue>
using namespace std;
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,n1,n2) for(int i=n1;i<n2;i++)
typedef long long ll;
typedef pair<int,int> Pii;
const int INF=(1<<30)-1;
const int MAX=310;
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a/gcd(a, b)*b;}
int main(){
	int n;
	cin>>n;
	int p[n];
	int max,min;
	cin>>p[0];
	max=p[0];
	min=p[0];
	for(int i=1;i<n;i++){
		cin>>p[i];
		max=max(p[i],max);
		min=min(p[i],min);
	}
	if(!(max==min||max==min+1)){
		cout<<"No"<<endl;
		return 0;
	}
	if(max==min){
		if(max==1||max==n-1){
			cout<<"Yes"<<endl;
			return 0;
		}else{
			if(n/max>=2){
				cout<<"Yes"<<endl;
				return 0;
			}else{
				cout<<"No"<<endl;
				return 0;
			}
		}
	}
	int a=0,b=0;
	REP(i,n){
		if(p[i]==min)a++;
		else b++;
	}
	if(max-a<=0){
		cout<<"No"<<endl;
		return 0;
	}
	if(2*(max-a)<=b){
		cout<<"Yes"<<endl;
	}else{
		cout<<"No"<<endl;
	}
	return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
 
using namespace std;
 
#define sf(n) scanf("%d", &n)
#define pd(n) printf("%.12lf", n)
#define pf(n) printf("%d", n)
#define p() printf("\n")
#define ps() printf(" ")
#define ll long long
#define ull unsigned long long
#define MAX 1e9
const int mod = 1000 * 1000 * 1000 + 7;
#define ex 1e18
#define dbl 2e09
#define qu(q) queue<int> q
#define pqu(q) priority_queue<int> q
#define len(s) s.length()
#define sz(x) int(x.size())
#define pb(x) push_back(x)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define F first
#define S second
#define clr(x) x.clear()
#define LOG(x) std::cout << x << std::endl;
 
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const double PI = 3.14159265359;
 
int dx[4] = {1, -1, 0, 0};
int dy[4] = {0, 0, 1, -1};


int main(){
   string s;
   cin>>s;
   int qt;
   cin>>qt; 
   bool rev=0;
   deque<char>q;
   for(int i=0;i<s.size();++i){
      q.push_back(s[i]);
   }
   while(qt--){
      int t;
      cin>>t;
      if(t==1){
         rev=!rev;
      }
      if(t==2){
         int f;
         char c;
         cin>>f>>c;
         if(!rev){
            if(f==1){
               q.push_front(c);
            }
            else {
               q.push_back(c);
            }
         }
         else{
           if(f==2){
               q.push_front(c);
            }
            else {
               q.push_back(c);
            } 
         }
      }
   }
   string ans="";
   while(!q.empty()){
      ans+=q.front();
      q.pop_front();
   }
   if(rev)
      reverse(all(ans));

   cout<<ans<<endl;
   return 0;
}

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

#define trace(...) __f( #__VA_ARGS__ , __VA_ARGS__ )
template <typename Arg1>
void __f( const char* name , Arg1&& arg1 ) {
        cerr << name << " : " << arg1 << "\n";
}
template <typename Arg1, typename... Args>
void __f( const char* na , Arg1&& arg1 , Args&&... args ) {
        const char* c = strchr( na + 1 , ',' );
        cerr.write( na , c - na ) << " : " << arg1 << " , ";
        __f( c + 1 , args... );
}
#define endl "\n"
#define all(V) V.begin(),V.end()
#define Unique(V) sort(all(V)),V.erase(unique(all(V)),V.end())
#define IO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
typedef long long int LL;
typedef pair <int,int> pii;
const int MOD = 1e9 + 7;
const int inf = 1e9;
const double EPS = 1e-9;
const double PI = acos(-1.0);
const long long INF = 1e18;
const int N = 1e5 + 5;

int main( ) {
        IO;
        #ifdef LOCAL
            //freopen( "input.txt" , "r" , stdin );
        #endif // LOCAL
        LL a , b;
        cin >> a >> b;
        LL m = ( a + b ) >> 1;
        if( abs( a - m ) == abs( b - m ) ) cout << m << endl;
        else cout << "IMPOSSIBLE" << endl;
        return 0;
}









Measured memory_bytes: 256
// 161-C Replacing Integer

#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <math.h>
#include <assert.h>
#include <string.h>
#include <memory.h>
#include <malloc.h>
#include <stdlib.h>

// qsortで用いる比較用関数．*a<*bならaが先になる．
int compare(const void* a, const void* b) {
    return *(int*)a - *(int*)b;
}


int main() {

    int r, g, b;

    assert(scanf("%d %d %d", &r, &g, &b) == 3);

    if ((g * 10 + b) % 4 == 0) {
        printf("YES\n");
    }
    else {
        printf("NO\n");
    }
    return 0;
}

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

using namespace std;
 
#define MD 1000000007
typedef long long int ll;

int main(){
    int a,b;
    cin>>a>>b;
    for(int i=1;i<=3;i++){
        if(a*b*i%2==1){
            cout<<"Yes"<<endl;
            return 0;
        }
    }
    cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define INF (1<<30)
#define INFLL (1ll<<60)
typedef pair<ll, int> P;
#define MOD (1000000007ll)

ll sq(ll x){
	return x*x;
}

int main(void){
	int i,p[3];
	string s[3];
	for(i=0; i<3; ++i){
		cin >> s[i];
		p[i] = s[i].length();
		reverse(s[i].begin(),s[i].end());
	}
	i = 0;
	while(true){
		if(!p[i]){
			cout << ((char)(i+'A')) << endl;
			break;
		}
		p[i]--;
		i = s[i][p[i]]-'a';
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, b) for (ll i = a; i < b; ++i)
#define ll long long
#define M 100000007
#define fr first
#define sc second
#define endl "\n"
#define vc vector
#define pb push_back
#define pii pair<ll, ll>
#define psi pair<string, ll>
#define fast                                                                   \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(0);                                                                  \
  cout.tie(0);
#define PI 3.14159265
#define r0 return 0
#define sz(a) int((a).size())
#define pb push_back
#define all(c) (c).begin(), (c).end()
#define tr(c, i) for (typeof((c)).begin() i = (c).begin(); i != (c).end(); i++)
#define present(c, x) ((c).find(x) != (c).end())
#define cpresent(c, x) (find(all(c), x) != (c).end())
#define what_is(x) cerr << #x << " is " << x << endl;
using namespace std;

typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<vi> vvi;
typedef vector<ii> vii;
const char char_max = (char)(((unsigned char) char(-1)) / 2);

int main() {
  fast
  string a;
  cin>>a;
  rep(i,0,a.length()) cout<<"x";
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n,m,fa[100005],a[100005],b[100005],t,x,y;
long long s;
int find(int r){return fa[r]?fa[r]=find(fa[r]):r;}
int main(){
	scanf("%d%d",&n,&m);
	if(m==n-1) return 0*puts("0");
	for(int i=1;i<=n;++i) scanf("%d",&a[i]),s+=a[i];
	for(int i=1;i<=m;++i){
		scanf("%d%d",&x,&y);
		x=find(x+1),y=find(y+1);
		s-=max(a[x],a[y]);
		b[++t]=max(a[x],a[y]);
		if(a[x]>a[y]) fa[x]=y;else fa[y]=x;
	}
	if(t<n-m-2) return 0*puts("Impossible");
	sort(b+1,b+t+1);
	for(int i=1;i<=n-m-2;++i) s+=b[i];
	printf("%lld",s);
}

Measured memory_bytes: 1408
#include<cstdio>
#include<queue>
#include<algorithm>
using namespace std;
#define INF int(1e9+7)

int d,g,t,ans=INF;
int p[15],v[15],c[15],s[15],zz[15];
int cnt[15];

int main() {
	scanf("%d %d",&d,&g);
	for(int i=1;i<=d;i++) {
		scanf("%d %d",&p[i],&c[i]);
		v[i]=i*100;
		s[i]=p[i]*v[i];
	}
	int lim=1<<d;
	for(int st=0;st<lim;st++) {
		bool flag=false;
		int sum=g,tot=0,tmp=INF;
		for(int i=0;i<d;i++)
			if((1<<i)&st)
				sum=sum-(s[i+1]+c[i+1]),tot+=p[i+1];
		if(sum<0) continue;
		for(int i=0;i<d;i++)
			if(!((1<<i)&st))
				if(s[i+1]+c[i+1]>=sum)
					tmp=min(tmp,min((sum+v[i+1]-1)/v[i+1],p[i+1])),flag=true;
		if(flag)
			ans=min(ans,tot+tmp);
	}
	printf("%d\n",ans);
	return 0;
}

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

int main(){
    int n,ans;
    cin>>n;
    vector<int>d(n);
    for(int i=0;i<n;i++){
        cin>>d.at(i);
        ans+=d.at(i);
        }
    for(int t=0;t<n;t++){
    int a=0,b=0;
    for(int i=0;i<n;i++){
        if(i<=t){
            a+=d.at(i);
        }else{
            b+=d.at(i);
            }
        }
        int c=a-b;
        if(c<0){c=-c;}
        if(ans>c){
            ans=c;
            }
        }
            cout<<ans<<endl;
            }


Measured memory_bytes: 256
#include <iostream>
#include <numeric>
#include <cmath>
#include <limits>
#include <stdio.h>
#include <iomanip>
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
using namespace std;
using ll = long long;
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)
ll Max(ll(a), ll(b), ll(c)) {
	return max(max(a, b), c);
}
ll Min(ll(a), ll(b), ll(c)) {
	return min(min(a, b), c);
}





int main() {
	ll N,an=0;
	cin >> N;
	vector<int> p(N);
	rep(i, N) {
		cin >> p.at(i);
	}
	rep(i, N - 1) {
		if (p[i] == i + 1) {
			an++;
			swap(p[i], p[i + 1]);
		}
	}
	if (p[N - 1] == N)an++;
	cout << an << endl;
}

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

using namespace std;

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

    for (int i = 0; i < K; i++)
    {
        if (i % 2 == 0)
        {
            int x = A / 2;
            A = x;
            B += x;
        }
        else
        {
            int x = B / 2;
            B = x;
            A += x;
        }
    }
    cout << A << " " << B << endl;
}

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

int ans;
 
main(){
  int n;
  cin>>n;
  vector<int>v;
  map<int,int>M;
  r(i,n){
    int a;
    cin>>a;
    M[a]++;
  }
  for(map<int,int>::iterator it=M.begin();it!=M.end();it++){
    int x=(*it).first;
    int y=(*it).second;
    if(x<y)ans+=y-x;
    else if(x>y)ans+=y;
  }
  cout<<ans<<endl;
}

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

#define sz 100005
#define nl printf("\n");
#define ll long long int

char f,g;
bool flag;
pair < int ,int > pi;
map < int , int > mp;
vector < int > v,va,vb;
int arr[sz],brr[sz],crr[sz];



int main(){

    double a,b,c,d,temp=INT_MAX,ans=INT_MAX,temp2;
    int n,m, i,j,k, x=0,y=0,z=0,idx;

    cin>>n>>a>>b;
    for(i=1; i<=n; i++){
        cin>>c;

        temp=a-c*0.006;
        temp2=(b-temp);
        if(temp2<0)
            temp2*=-1.0;
        if(temp2<ans){
            ans=temp2;
            idx=i;
        }
    }
    cout<<idx<<endl;



    return 0;

}


Measured memory_bytes: 256
#include<stdio.h>
#include<algorithm>
using namespace std;
int m[10][10];
int R;
int C;
int a,b;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
int solve(int s,int t,int u){
	if(u==0){
		if(s==R||t==C)return 1;
		else return 0;
	}
	int ret=0;
	for(int i=0;i<4;i++){
		int row=s;
		int col=t;
		while(1){
			row+=dx[i];
			col+=dy[i];
			if(row<0||col<0||row>=a||col>=b)break;
			if(m[row][col]==1){
				m[row][col]=3;
				ret+=solve(row,col,u-1);
				m[row][col]=1;
				break;
			}
		}
	}
	return ret;
}
int main(){
	while(scanf("%d%d",&b,&a),a){
		int c=0;
		for(int i=0;i<a;i++)
			for(int j=0;j<b;j++){
				scanf("%d",&m[i][j]);
				if(m[i][j]==1)c++;
				if(m[i][j]==2){R=i;C=j;}
			}
		printf("%d\n",solve(R,C,c));
	}
}

Measured memory_bytes: 1028
n = list(str(input()))
a = ["R", "U", "D"]
b = ["L", "U", "D"]

ans = "No"
aa = [True if n[i] in a else False for i in range(0, len(n), 2)]
bb = [True if n[i] in b else False for i in range(1, len(n), 2)]
if all(aa) and all(bb):
    ans = "Yes"
print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
 
const int MAX_N = 1005;
 
int N;
int M;
 
int L[MAX_N];
 
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
 
    cin >> N;
    M = 2 * N;
 
    for (int i = 0; i < M; ++i) {
        cin >> L[i];
    }
 
    sort(L, L+M);
 
    //for (int i = 0; i < M; ++i) {
    //    cout << L[i] << endl;
    //}
    //cout << endl;

    int ans = 0;
 
    for (int i = 0; i < N; ++i) {
        ans += min(L[2*i], L[2*i+1]);
    }
 
    cout << ans << endl;
 
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using ll=long long;
using namespace std;
#define rep_i(i, n) for (int i = 0; i < (n); ++i)
#define rep_ll(i, n) for (long long i = 0; i < (n); ++i)
#define r_rep_i(i, start, end) for (int i = (start); i < (end); ++i)
#define r_rep_ll(i, start, end) for (long long i = (start); i < (end); ++i)
#define debug_vi(v) copy((v).begin(), (v).end(), ostream_iterator<int>(cout, " "));
#define debug_vll(v) copy((v).begin(), (v).end(), ostream_iterator<long long>(cout, " "));
#define debug_vd(v) copy((v).begin(), (v).end(), ostream_iterator<double>(cout, " "));
#define sort_v(v) sort((v).begin(), (v).end()); //昇順
#define d_sort_vi(v) sort((v).begin(), (v).end(), greater<int>()); //降
#define d_sort_vll(v) sort((v).begin(), (v).end(), greater<long long>()); //降
#define d_sort_vd(v) sort((v).begin(), (v).end(), greater<double>()); //昇順
#define say(t) cout << (t) << endl;
#define sum_vi(v) accumulate((v).begin(), (v).end(), 0);
#define sum_vll(v)accumulate((v).begin(), (v).end(), 0LL);

ll gcd(ll a, ll b) { return b?gcd(b, a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a, b)*b;}
const int IINF=(1<<30);
const ll LLINF = 1LL<<60;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(0);
  int n; cin >> n;
  // vector<int> hoge(n);
  deque<int> fuga;
  int tmp;
  rep_i(i, n){
    cin >> tmp;
    if(i%2 == 0){
      fuga.push_front(tmp);
    }else{
      fuga.push_back(tmp);
    }
  }
  if(n%2 == 0){
    for (auto i = fuga.rbegin(); i != fuga.rend(); i++){
      if(i == fuga.rbegin()){
        cout << *i;
      }else{
        cout << " " << *i;
      }
    }
    cout << endl;
  }else{
    for (auto i = fuga.begin(); i != fuga.end(); i++){
      if(i == fuga.begin()){
        cout << *i;
      }else{
        cout << " " << *i;
      }
    }
    cout << endl;
  }
}

Measured memory_bytes: 3072
#include"stdio.h"
int main()
{
    int i,j,k,n,a[3];
    scanf("%d %d %d",&a[0],&a[1],&a[2]);
    i=a[2];
    a[2]=a[1];
    a[1]=i;
    j=a[1];
    a[1]=a[0];
    a[0]=j;
    printf("%d %d %d",a[0],a[1],a[2]);

    return 0;
}


Measured memory_bytes: 128
//##Moh_K_Imar .......
//27/08/2020  ...  7.55
//Ya Rab....
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using ld=long double;
int main(){
    ll a;
    cin>>a;
    if(a>=30){
        cout<<"Yes"<<endl;
    }
    else cout<<"No"<<endl;


    return 0;
}



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

#pragma GCC optimize("O3")

using namespace std;

#define MAXN 1000001

#define FOR(i, n) for (int i = 0; i < n; i++)
#define FORR(j, i, n) for (int i = j; i < n; i++)
#define FORD(i, n) for (int i = n - 1; i >= 0; i--)
#define FOBIR(i, n) for (int i = 1; i <= n; i++)
#define pb push_back
#define mp make_pair
#define endl '\n'
#define DUEHOANG                  \
	ios_base::sync_with_stdio(0); \
	cin.tie(NULL);                \
	cout.tie(NULL)

#define JaydenXia(in, out) \
	freopen(in, "r", stdin); \
	freopen(out, "w", stdout);

#define ll long long

typedef set<int> si;
typedef vector<int> vi;
typedef pair<ll, ll> pii;
typedef vector<pii> vii;
typedef priority_queue<int> pqi;
typedef stack<int> sti;
typedef queue<int> qi;
typedef deque<int> di;
typedef map<int, int> mii;
#define f first
#define s second

int n;
vi adj[MAXN];

int pack(int a, int b)
{
    int c=min(a,b);
    int d=max(a,b);
    return c * 1000 + d;
}

pii unpack(int w)
{
    int a = w / 1000;
    int b = w % 1000;
    return mp(a,b);
}

int ind[MAXN];
int main()
{
    cin >> n;
    FOR(i, n)
    {
        int a;
        cin >> a;
        a--;
        FOR(j, n-2)
        {
            int b;
            cin >> b;
            b--;
            adj[pack(i,a)].pb(pack(i,b));
            ind[pack(i,b)]++;
            a=b;
        }
    }
    // cerr << "ok" << endl;
    vi q;
    FOR(i, MAXN) if(!ind[i]) q.pb(i);
    int fin = 0;
    int ans = 0;
    // cerr << "ok" << endl;
    while(!q.empty())
    {
        ans++;
        fin += q.size();

        vi nq;
        for(int i : q)
        {
            for(int nx : adj[i])
            {
                ind[nx]--;
                if(ind[nx] == 0) nq.pb(nx);
            }
        }

        q=nq;
    }
    if(fin != MAXN)
    {
        cout << -1 << endl;
    } else 
    {
        cout << ans << endl;
    }
}

Measured memory_bytes: 45432
#include<bits/stdc++.h>
#define mt make_tuple
#define mp make_pair
#define pu push_back
#define INF 1000000001
#define MOD 1000000007
#define EPS 1e-6
#define ll long long int
#define ld long double
#define fi first
#define se second
#define all(v) v.begin(),v.end()
#define pr(v) { for(int i=0;i<v.size();i++) { v[i]==INF? cout<<"INF " : cout<<v[i]<<" "; } cout<<endl;}
#define t1(x)                cerr<<#x<<" : "<<x<<endl
#define t2(x, y)             cerr<<#x<<" : "<<x<<" "<<#y<<" : "<<y<<endl
#define t3(x, y, z)          cerr<<#x<<" : " <<x<<" "<<#y<<" : "<<y<<" "<<#z<<" : "<<z<<endl
#define t4(a,b,c,d)          cerr<<#a<<" : "<<a<<" "<<#b<<" : "<<b<<" "<<#c<<" : "<<c<<" "<<#d<<" : "<<d<<endl
#define t5(a,b,c,d,e)          cerr<<#a<<" : "<<a<<" "<<#b<<" : "<<b<<" "<<#c<<" : "<<c<<" "<<#d<<" : "<<d<<" "<<#e<<" : "<<e<<endl
#define t6(a,b,c,d,e,f)          cerr<<#a<<" : "<<a<<" "<<#b<<" : "<<b<<" "<<#c<<" : "<<c<<" "<<#d<<" : "<<d<<" "<<#e<<" : "<<e<<" "<<#f<<" : "<<f<<endl
#define GET_MACRO(_1,_2,_3,_4,_5,_6,NAME,...) NAME
#define t(...) GET_MACRO(__VA_ARGS__,t6,t5, t4, t3, t2, t1)(__VA_ARGS__)
#define _ cerr<<"here"<<endl;
#define __ {ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);}

using namespace std;
template<class A, class B> ostream& operator<<(ostream& out, const pair<A, B> &a){ return out<<"("<<a.first<<", "<<a.second<<")";}
template <int> ostream& operator<<(ostream& os, const vector<int>& v) { os << "["; for (int i = 0; i < v.size(); ++i) { if(v[i]!=INF) os << v[i]; else os << "INF";if (i != v.size() - 1) os << ", "; } os << "]\n"; return os; } 
template <typename T> ostream& operator<<(ostream& os, const vector<T>& v) { os << "["; for (int i = 0; i < v.size(); ++i) { os << v[i]; ;if (i != v.size() - 1) os << ", "; } os << "]\n"; return os; } 


int main()
{
  __;
  ll a,b,v,w,t;
  cin >> a >> v >> b >> w >> t;
  ll dist = abs(a-b);
  if(v < w) cout << "NO" << endl;
  else
  {
    if(t*abs(v-w) >= dist) cout << "YES" << endl;
    else cout << "NO" << endl;
  }
  return 0;
}


Measured memory_bytes: 3652
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<queue>
#include<map>
#include<deque>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
typedef long long ll;
typedef pair<int,int> P;
template<class T> inline bool chmax(T&a , T b){ if(a<b){ a=b; return true; } else{ return false; } }
template<class T> inline bool chmin(T&a , T b){ if(a>b){ a=b; return true; } else{ return false; } } 

const int INF = 1e9;
const int MOD = 1e7;
const ll LINF = 1e18;

int main(){
    string s;
    cin >> s;
    reverse(s.begin(),s.end());
    vector<ll> v(2020,0);
    ll cur=0;
    ll p=1;
    v[0]++;
    for(int i=0;i<s.size();i++){
        cur = cur + p*(s[i]-'0');
        cur  %= 2019;
        p = (p*10)%2019;
        v[cur]++;
    }
    ll ans=0;
    for(int i=0;i<=2019;i++){
        ans += v[i]*(v[i]-1)/2;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3768
# coding: utf-8
import sys
#from operator import itemgetter
sysread = sys.stdin.buffer.readline
read = sys.stdin.buffer.read
#from heapq import heappop, heappush
#from collections import defaultdict
sys.setrecursionlimit(10**7)
import math
#from itertools import product, accumulate, combinations, product
#import bisect
#import numpy as np
#from copy import deepcopy
#from collections import deque
#from decimal import Decimal
#from numba import jit

INF = 1 << 50
EPS = 1e-8

def check_merge(merged,S):
    merged = set(merged)
    for i in merged:
        for j, e in enumerate(S[i]):
            if int(e) and j in merged:
                return False
    return True

def run():
    N = int(sysread())
    S = []
    for i in range(N):
        S.append(input())

    ans = 0

    #for s in S:
    #    print(s)
    for k in range(N):
        #print(k, '-------------------')
        seen = set()
        seen.add(k)
        merged = [k]
        count = 0
        while merged:
            #print(merged)
            count += 1
            nexts = []
            for i in merged:
                for j, e in enumerate(S[i]):
                    if int(e) and not j in seen:
                        nexts.append(j)
                        seen.add(j)
            if not check_merge(merged, S):
                seen = set()
                break
            merged = nexts
        if len(seen) == N:
            ans = max(ans, count)
    if ans:
        print(ans)
    else:
        print(-1)


if __name__ == "__main__":
    run()


Measured memory_bytes: 75304
hirou = 0
n, a, b = map(int, input().split())
x = list(map(int, input().split()))
for i in range(len(x) - 1):
    if (x[i + 1] - x[i]) * a >= b:
        hirou += b
    else:
        hirou += (x[i + 1] - x[i]) * a
print(hirou)

Measured memory_bytes: 14480
package main

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

var (
	readString func() string
	readBytes  func() []byte
)

func init() {
	readString, readBytes = newReadString(os.Stdin)
}

func newReadString(ior io.Reader) (func() string, func() []byte) {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)

	f1 := func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
	f2 := func() []byte {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Bytes()
	}
	return f1, f2
}

func readInt() int {
	return int(readInt64())
}

func readInt64() int64 {
	i, err := strconv.ParseInt(readString(), 10, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

func readFloat64() float64 {
	f, err := strconv.ParseFloat(readString(), 64)
	if err != nil {
		panic(err.Error())
	}
	return f
}

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
}

func minInt64(a, b int64) int64 {
	if a < b {
		return a
	}
	return b
}

func maxInt64(a, b int64) int64 {
	if a > b {
		return a
	}
	return b
}

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

func absInt64(a int64) int64 {
	if a < 0 {
		return -a
	}
	return a
}

func sum(a []int) int {
	var ret int
	for i := range a {
		ret += a[i]
	}
	return ret
}

func sumInt64(a []int64) int64 {
	var ret int64
	for i := range a {
		ret += a[i]
	}
	return ret
}

func sumFloat64(a []float64) float64 {
	var ret float64
	for i := range a {
		ret += a[i]
	}
	return ret
}

func gcdInt64(m, n int64) int64 {
	for m%n != 0 {
		m, n = n, m%n
	}
	return n
}

func lcmInt64(m, n int64) int64 {
	return m / gcdInt64(m, n) * n
}

// sort ------------------------------------------------------------

type int64Array []int64

func (s int64Array) Len() int           { return len(s) }
func (s int64Array) Swap(i, j int)      { s[i], s[j] = s[j], s[i] }
func (s int64Array) Less(i, j int) bool { return s[i] < s[j] }

type xxx struct {
	x int
}

type sortArray []xxx

func (s sortArray) Len() int           { return len(s) }
func (s sortArray) Swap(i, j int)      { s[i], s[j] = s[j], s[i] }
func (s sortArray) Less(i, j int) bool { return s[i].x < s[j].x }

// -----------------------------------------------------------------

func main() {
	n := readInt()
	d := readInt()
	x := make([][]int, n)
	for i := range x {
		x[i] = make([]int, d)
		for j := range x[i] {
			x[i][j] = readInt()
		}
	}

	ans := 0
	for i := range x {
		for j := i + 1; j < n; j++ {
			s := 0
			for k := range x[0] {
				s += (x[i][k] - x[j][k]) * (x[i][k] - x[j][k])
			}
			a := math.Sqrt(float64(s))
			if a == float64(int(a)) {
				ans++
			}
		}
	}

	fmt.Println(ans)
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
long long dsum(long long n){
  if(n==0) return 0;
  else return n%10+dsum(n/10);
}
int main(){
  long long n,i,k = 10,s;cin >> n;
  long long ans = dsum(n);
  while(n>=k){
    s = n/k*k-1;
    ans = max(ans,dsum(s));
    k *= 10;
  }
  cout << ans << "\n";
}

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

typedef struct { int x, y; }point;

int main() {
	int n, x, y, del = -1, max_y = -1, ans = 0;
	cin >> n;
	vector<point>a(n), b(n);
	for (int i = 0; i < n; i++)cin >> a[i].x >> a[i].y;
	sort(a.begin(), a.end(), [](const point& a, const point& b) {return a.x != b.x ? a.x < b.x : a.y < b.y; });
	for (int i = 0; i < n; i++)cin >> b[i].x >> b[i].y;
	sort(b.begin(), b.end(), [](const point& a, const point& b) {return a.x != b.x ? a.x < b.x : a.y < b.y; });
	for (int i = 0; i < n; del = max_y = -1, i++) {
		for (int j = 0; j < a.size(); j++)if (a[j].x < b[i].x && a[j].y < b[i].y && max_y < a[j].y)max_y = a[j].y, del = j;
		if (del >= 0) { a.erase(a.begin() + del); ans++; }
	}
	cout << ans << endl;
	
	return 0;
}

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

int main(){
  int X[] = {0,1,3,1,2,1,2,1,1,2,1,2,1};
  int A,B;
  cin >> A >> B;
  if(X[A] == X[B]){
    cout << "Yes" << endl;
  }
else{
cout << "No" << endl;
}
}


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

int main(){
    int cnt=0;
    string s;
    cin >> s;
    int n=s.size();
    for(int i=0; i<n; i++){
        if(s[i]!=s[n-1-i])cnt++;
    }
    if(cnt%2==1)cout << (cnt+1)/2;
    else cout << cnt/2;
    cout << endl;
}


Measured memory_bytes: 256
n = int(input())
a = [ list(input().split()) for _ in range(n) ]
#a = [['10','JPY'],['0.00001','BTC']]

yen = 0
btc = 0
for i,j in a:
  if j == 'JPY':
    yen += int(i)
  else:
    btc += float(i)

print(yen + btc * 380000)

Measured memory_bytes: 2940
N = int(input())

def modpow(a, n, mod):
    res = 1
    n_bi = str(format(n, 'b'))

    for i in range(len(n_bi)):
        res = (res*res) % mod
        if n_bi[i] == "1":
            res = (res*a) % mod
        
    return res

p = 1000000007

if (N == 1):
    print(0)
elif (N == 2):
    print(2)
else:
    temp = (modpow(10, N, p) - modpow(9, N, p)) % p
    temp = (temp - modpow(9, N, p)) % p
    temp = (temp + modpow(8, N, p)) % p
    print(temp)

Measured memory_bytes: 9208
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <vector>

using namespace std;

int main()
{
   long long n, a, b, c, d, e, f;
   cin>>n>>a>>b;
   c=a+b;
   d=n/c;
   e=n%c;
   if(e>a){
      f=d*a+a;
   }else{
      f=d*a+e;
   }
   cout<<f<<endl;

}

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

using namespace std;

typedef long long lli;
typedef double lld;
typedef vector<lli> vll;
typedef vector<bool> vbl;
typedef vector<double> vdl;
typedef vector<vector<lli>> mat;
typedef vector<vdl> mad;
typedef unordered_map<lli,unordered_map<lli,lli>> graph;
typedef complex<double> cmp;
typedef vector<cmp> vcl;

lli n;
multiset<vll> lr,rl;
multiset<vll> a,b;
lli g_ans;

int main(){
  cin >> n;
  for(lli i = 0;i < n;i++){
    lli l,r;
    cin >> l >> r;
    lr.insert(vll({l,r}));
    rl.insert(vll({r,l}));
  }
  a = lr;
  b = rl;
  lli x = 0;
  lli ans = 0;
  while(a.size() > 0){
    vll p = *a.rbegin();
    if(p[0] > x){
      ans += p[0]-x;
      x = p[0];
    }
    if(p[1] < x){
      ans += x-p[1];
      x = p[1];
    }
    a.erase(a.find(p));
    reverse(p.begin(),p.end());
    b.erase(b.find(p));
    if(b.size() == 0) break;
    p = *b.begin();
    if(p[0] < x){
      ans += x-p[0];
      x = p[0];
    }
    if(p[1] > x){
      ans += p[1]-x;
      x = p[1];
    }
    b.erase(b.find(p));
    reverse(p.begin(),p.end());
    a.erase(a.find(p));
  }
  g_ans = ans+(x < 0 ? -x : x);
  a = lr;
  b = rl;
  x = 0;
  ans = 0;
  while(b.size() > 0){
    vll p = *b.begin();
    if(p[0] < x){
      ans += x-p[0];
      x = p[0];
    }
    if(p[1] > x){
      ans += p[1]-x;
      x = p[1];
    }
    b.erase(b.find(p));
    reverse(p.begin(),p.end());
    a.erase(a.find(p));
    if(a.size() == 0) break;
    p = *a.rbegin();
    if(p[0] > x){
      ans += p[0]-x;
      x = p[0];
    }
    if(p[1] < x){
      ans += x-p[1];
      x = p[1];
    }
    a.erase(a.find(p));
    reverse(p.begin(),p.end());
    b.erase(b.find(p));
  }
  ans += (x < 0 ? -x : x);
  g_ans = max(g_ans,ans);
  cout << g_ans << endl;
}


Measured memory_bytes: 39808
#include <iostream>
#include <algorithm>
using namespace std;
main () {
	int n;
	cin>>n;
	int a[n];
	for (int i=0;i<n;i++)
	{
		cin>>a[i];
	}
	sort (a, a+n);
	int hasil = 0;
	for (int i=0;i<n-1;i++)
	{
		hasil += (a[i+1]- a[i]);
	}
	cout<<hasil;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>

#define M_PI 3.14159265358979323846

typedef struct tagPoint {
	double x, y;
}Point;

void koch(int n, Point a, Point b)
{
	if (n == 0) return;
	Point s, u, t;
	double rad = M_PI * 60.0 / 180.0;

	s.x = (2 * a.x + 1 * b.x) / 3;
	s.y = (2 * a.y + 1 * b.y) / 3;
	t.x = (1 * a.x + 2 * b.x) / 3;
	t.y = (1 * a.y + 2 * b.y) / 3;
	u.x = (t.x - s.x)*cos(rad) - (t.y - s.y)*sin(rad) + s.x;
	u.y = (t.x - s.x)*sin(rad) + (t.y - s.y)*cos(rad) + s.y;
	koch(n - 1, a, s);
	printf("%.8f %.8f\n", s.x, s.y);
	koch(n - 1, s, u);
	printf("%.8f %.8f\n", u.x, u.y);
	koch(n - 1, u, t);
	printf("%.8f %.8f\n", t.x, t.y);
	koch(n - 1, t, b);
}

int main()
{
	int n;
	Point a = { 0.0, 0.0 };
	Point b = { 100.0, 0.0 };

	scanf("%d", &n);

	printf("%.8f %.8f\n", a.x, a.y);
	koch(n, a, b);
	printf("%.8f %.8f\n", b.x, b.y );
	return 0;
}



Measured memory_bytes: 2076
//#define NDEBUG
#include <cstddef>
#include <cstdint>
#include <vector>

using i8 = ::std::int_least8_t;
using i32 = ::std::int_least32_t;
using i64 = ::std::int_least64_t;
using u8 = ::std::uint_least8_t;
using u32 = ::std::uint_least32_t;
using u64 = ::std::uint_least64_t;
using isize = ::std::ptrdiff_t;
using usize = ::std::size_t;

template <class T = usize> class rep {
	const T f, l;

public:
	class itr {
		friend rep;
		T i;
		constexpr itr(T x) noexcept : i(x) {}

	public:
		void operator++() noexcept { ++i; }
		constexpr T operator*() const noexcept { return i; }
		constexpr bool operator!=(const itr x) const noexcept { return i != x.i; }
	};
	constexpr rep(const T first, const T last) noexcept : f(first), l(last) {}
	constexpr itr begin() const noexcept { return itr(f); }
	constexpr itr end() const noexcept { return itr(l); }
};
template <class T = usize> class revrep {
	const T f, l;

public:
	class itr {
		friend revrep;
		T i;
		constexpr itr(T x) noexcept : i(x) {}

	public:
		void operator++() noexcept { --i; }
		constexpr T operator*() const noexcept { return i; }
		constexpr bool operator!=(const itr x) const noexcept { return i != x.i; }
	};
	constexpr revrep(const T first, const T last) noexcept : f(first), l(last) {}
	constexpr itr begin() const noexcept { return itr(l - 1); }
	constexpr itr end() const noexcept { return itr(f - 1); }
};
template <class T> bool amax(T &a, const T &b) {
	return a <= b ? (a = b, 1) : 0;
}
template <class T> bool amin(T &a, const T &b) {
	return b <= a ? (a = b, 1) : 0;
}
template <class T> bool asmax(T &a, const T &b) {
	return b <= a ? 0 : (a = b, 1);
}
template <class T> bool asmin(T &a, const T &b) {
	return a <= b ? 0 : (a = b, 1);
}
template <class T> using vec_alias = ::std::vector<T>;
template <class T> auto md_vec(usize n, const T &value) {
	return ::std::vector<T>(n, value);
}
template <class... Args> auto md_vec(usize n, Args... args) {
	return ::std::vector<decltype(md_vec(args...))>(n, md_vec(args...));
}
template <class T> const T &as_const(const T &v) noexcept { return v; }
template <class T> constexpr T difference(const T &a, const T &b) {
	return a <= b ? b - a : a - b;
}


#include <algorithm>
#include <iostream>
#include <utility>
#include <string>
#include <cstdio>
#include <set>


int main() {
	static constexpr i64 INF = 1000000000000LL;
	usize a, b, q;
	::std::cin >> a >> b >> q;
	::std::set<i64> s({ -INF,INF }), t({ -INF,INF });
	while (a--) {
		i64 v;
		::std::cin >> v;
		s.insert(v);
	}
	while (b--) {
		i64 v;
		::std::cin >> v;
		t.insert(v);
	}
	while (q--) {
		i64 x;
		::std::cin >> x;
		i64 sp = *::std::prev(s.upper_bound(x));
		i64 sn = *s.lower_bound(x);
		i64 tp = *::std::prev(t.upper_bound(x));
		i64 tn = *t.lower_bound(x);
		::std::cout << ::std::min({
			::std::max(sn,tn) - x,
			x - ::std::min(sp,tp),
			(sn - x) * 2 + (x - tp),
			(x - sp) * 2 + (tn - x),
			(tn - x) * 2 + (x - sp),
			(x - tp) * 2 + (sn - x)
		}) << ::std::endl;
	}
	return 0;
}


Measured memory_bytes: 10752
#include<bits/stdc++.h>
using namespace std;
int n,a,b,ans;
bool check(int n)
{
	int sum=0;
	while(n)
	{
		sum+=n%10;
		n/=10;
	}
	if(sum<=b&&a<=sum) return 1;
	return 0;
}
int main()
{
	scanf("%d%d%d",&n,&a,&b);
	for(int i=1;i<=n;i++)
	if(check(i))
	ans+=i;
	printf("%d",ans);
	return 0; 
}

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

int main() {
    int n;
    int count=0;
    cin >> n;
    string s;
    cin >> s;
    
    for (int i = 0; i < n-1; i++)
    {
        if (s[i] == s[i+1])
        {
            count++;
        }
    }
    cout << (n - count) << endl;
}

Measured memory_bytes: 512
#include <stdio.h>

int main(void) {
	int i, j, count = 0;
	int a[100], n, tmp;

	scanf("%d", &n);

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

	for (i = 0; i < n - 1; i++) {
		for (j = n - 1; j > i; j--) {
			if (a[j] < a[j - 1]) {
				tmp = a[j];
				a[j] = a[j - 1];
				a[j - 1] = tmp;
				count++;
			}
		}
	}

	for (i = 0; i < n; i++) {
		printf("%d", a[i]);
		if (i != n - 1) {
			putchar(' ');
		}
	}
	putchar('\n');

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

	return 0;
}



Measured memory_bytes: 2140
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = 1e9 + 7;
const int iinf = 1 << 28;
const long long llinf = 1ll << 60;
const double PI = 3.14159265;

int n;
vector<vector<int>> v(2e5+1);

int main() {
    cin >> n;
    for (int i = 1; i <= n; ++i) {
        int a; cin >> a;
        v[a].push_back(i);
    }
    if (v[1].size() == 0) {
        cout << "-1"; return 0;
    }
    int ans = n-1;
    for (int pos : v[1]) {
        int pos1 = pos;
        for (int i = 2; i <= n; ++i) {
            /*
            int e = -1;
            for (int j : v[i]) {
                if (j > pos1) {
                    e = j;
                    break;
                }
            }
            if (i == n && e != -1) {
                ans = 0; break;
            }
            if (e == -1) {
                ans = min(ans, n - (i-1)); break;
            } else {
                pos1 = e;
            }
            */
            
            int b = 0, e = v[i].size() - 1;
            while (b < e) {
                int m = b + ((e-b)>>1);
                if (v[i][m] < pos1) {
                    b = m + 1;
                } else {
                    e = m;
                }
            }
            if (i == n && e != -1) {
                ans = 0; break;
            }
            if (e == -1 || v[i][e] < pos1) {
                ans = min(ans, n - (i-1)); break;
            } else {
                pos1 = v[i][e];
            }
            
        }
    }
    cout << ans;


    return 0;
}


Measured memory_bytes: 11136
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin>>n;
  int sum;
  for(int i=n;i>0;i--){
    int r,l,pop;
    cin>>l>>r;
    pop=r-l+1;
    sum=sum+pop;
  }
  cout<<sum<<endl;
}
  

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std ;
const int N= 3e5;
int Mod = 1e9+7 ;
long long cum [N];


int main(){
    int X;
    cin >> X;
    if (X>=30) {
        std::cout << "Yes" << std::endl;
    } else {
        std::cout << "No" << std::endl;
    }
    
    return 0;
}


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

int main(){
  int A,B,C,X;
  int ans=0;
  cin>>A>>B>>C>>X;
  for(int i=0;i<=A;i++){
   for(int j=0;j<=B;j++){
      for(int k=0;k<=C;k++){
   if(500*i+100*j+50*k==X){
   ans++;
   }     
  }
  }
  }
  
    cout<<ans<<endl;
   
}


Measured memory_bytes: 3636
#include<iostream>
#include<stdio.h>
#include<vector>
using namespace std;

const int maxn=1e5+5;
int n;
struct node {
	int to,c,v;
};

struct query {
	int id,c,d,flag;
};

vector<query>q[maxn];
vector<node>a[maxn];
int p[maxn][20],dep[maxn],dis[maxn],s[maxn],t[maxn],ans[maxn];

void dfs(int x,int f,int d,int s) {
	p[x][0]=f,dep[x]=d,dis[x]=s;
	for(int i=0; i<(int)a[x].size(); i++) {
		int y=a[x][i].to;
		if(y==f)continue;
		dfs(y,x,d+1,s+a[x][i].v);
	}
}

void init() {
	for(int j=1; j<20; j++)
		for(int i=1; i<=n; i++)
			p[i][j]=p[p[i][j-1]][j-1];
}

int up(int x,int step) {
	for(int i=0; i<20; i++)
		if((1<<i)&step)x=p[x][i];
	return x;
}

int LCA(int a,int b) {
//	puts("1");
	if(dep[a]>dep[b])swap(a,b);
	b=up(b,dep[b]-dep[a]);
	if(a==b)return a;
	for(int i=19; i>=0; i--)
		if(p[a][i]!=p[b][i])
			a=p[a][i],b=p[b][i];
	return p[a][0];
}

void DFS(int x,int f) {
	for(int i=0; i<(int)q[x].size(); i++) {
		int c=q[x][i].c;
		int d=q[x][i].d;
		ans[q[x][i].id]+=q[x][i].flag*(dis[x]-t[c]+s[c]*d);
	}
	for(int i=0; i<(int)a[x].size(); i++) {
		int y=a[x][i].to;
		if(y==f)continue;
		s[a[x][i].c]++;
		t[a[x][i].c]+=a[x][i].v;
		DFS(y,x);
		s[a[x][i].c]--;
		t[a[x][i].c]-=a[x][i].v;
	}
}

int main() {
	int m;
	scanf("%d %d",&n,&m);
	for(int i=1; i<n; i++) {
		int x,y,c,d;
		scanf("%d %d %d %d",&x,&y,&c,&d);
		a[x].push_back((node)<%y,c,d%>);
		a[y].push_back((node)<%x,c,d%>);
	}
	dfs(1,0,0,0);
	init();
	for(int i=1; i<=m; i++) {
		int x,y,c,d;
		scanf("%d %d %d %d",&c,&d,&x,&y);
		q[x].push_back((query)<%i,c,d,1%>);
		q[y].push_back((query)<%i,c,d,1%>);
		q[LCA(x,y)].push_back((query)<%i,c,d,-2%>);
	}
//	puts("1");
	DFS(1,0);
	for(int i=1; i<=m; i++)printf("%d\n",ans[i]);
	return 0;
}

Measured memory_bytes: 31220
#include <stdio.h>

enum Surface {TOP, BELOW, RIGHT, LEFT, FRONT, BACK};

#define ROTATE(dice, v)\
{\
    int j;\
    int save = dice[v[0]];\
    for (j=0; j<3; j++) {\
        dice[v[j]] = dice[v[j+1]];\
    }\
    dice[v[3]] = save;\
}

int main() {
    while (1) {
        int i;
        int n;
        int dice[6];
        int ans;
    
        scanf("%d", &n);
        if (n == 0) return 0;

        dice[TOP] = 1;
        dice[BELOW] = 6;
        dice[RIGHT] = 3;
        dice[LEFT] = 4;
        dice[FRONT] = 2;
        dice[BACK] = 5;
    
        ans = 1;
        for (i=0; i<n; i++) {
            char dir_s[10];
    
            scanf("%s", dir_s);
            if (dir_s[0] == 'N') {
               int v[4] = {TOP, FRONT, BELOW, BACK};
               ROTATE(dice, v);
            } else if (dir_s[0] == 'E') {
               int v[4] = {TOP, LEFT, BELOW, RIGHT};
               ROTATE(dice, v);
            } else if (dir_s[0] == 'S') {
               int v[4] = {TOP, BACK, BELOW, FRONT};
               ROTATE(dice, v);
            } else if (dir_s[0] == 'W') {
               int v[4] = {TOP, RIGHT, BELOW, LEFT};
               ROTATE(dice, v);
            } else if (dir_s[0] == 'R') {
               int v[4] = {FRONT, RIGHT, BACK, LEFT};
               ROTATE(dice, v);
            } else if (dir_s[0] == 'L') {
               int v[4] = {FRONT, LEFT, BACK, RIGHT};
               ROTATE(dice, v);
            }
    
            ans += dice[TOP];
        }
    
        printf("%d\n", ans);
    }
}

Measured memory_bytes: 1032
import scala.io.Source.stdin

object Main extends App {
  var b = new StringBuilder

  def integral(i:Int,s:Int,d:Int):Unit = if(i*d >= 600-d) b.append((s + i*i*d*d*d)+"\n") else integral (i+1, s + i*i*d*d*d, d)

  for(i<-stdin.getLines)
    integral(0,0,i.toInt)

  print(b.result)
}

Measured memory_bytes: 44000
#include <stdio.h>
int main(void){
  char b[0];
  scanf("%s",b);
  if(b[0]=='A'){
    printf("T");
    return 0;
  }
  if(b[0]=='C'){
    printf("G");
    return 0;
  }
  if(b[0]=='G'){
    printf("C");
    return 0;
  }
  if(b[0]=='T'){
    printf("A");
    return 0;
  }
  return 0;
}

Measured memory_bytes: 128
#include <vector>
#include <iostream>

#pragma GCC target ("arch=ivybridge")
#pragma GCC optimize ("-O3", "unroll-loops")

using namespace std;

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

  size_t n;
  cin >> n;
  vector<unsigned> av(n);
  vector<unsigned> bv(n);
  for ( size_t i = 0; i < n; ++i ) cin >> av[i];
  for ( size_t i = 0; i < n; ++i ) cin >> bv[i];

  const size_t block_size = 8192;

  unsigned ret = 0;
  for ( size_t i = 0; i < n; i += block_size ) {
    size_t i_max = min(n, i + block_size);
    size_t j = 0;
    for ( ; j + 3 < n; j += 4 ) {
      for ( size_t ii = i; ii < i_max; ++ii ) {
        ret ^= av[j] + bv[ii];
        ret ^= av[j + 1] + bv[ii];
        ret ^= av[j + 2] + bv[ii];
        ret ^= av[j + 3] + bv[ii];
      }
    }
    for ( ; j < n; ++j ) {
      for ( size_t ii = i; ii < i_max; ++ii ) {
        ret ^= av[j] + bv[ii];
      }
    }
  }
  cout << ret << endl;

  return 0;
}


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

using namespace std;

int main() {

	int n;
	cin >> n;
	vector<int> a(n, 0);
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	sort(a.begin(), a.end(), greater<int>());
	long long aa = 0;
	long long bb = 0;
	for (int i = 0; i < n-1; i++) {
		if (a[i] == a[i + 1]) {
			if (aa == 0) { aa = a[i]; i++; }
			else if (bb == 0) { bb = a[i]; break; }
		}
	}
	cout << aa * bb << endl;
}

Measured memory_bytes: 640