akhauriyash/Code-Regression huggingface dataset:
/*
How to lambda
  ex) sort(ALL(cont),[](dat a,dat b){return a.l<b.l;});
lower_bound/upper_bound
  1 2 2 2 3 3 
    ^lb   ^ub */
#include <bits/stdc++.h>
#define BR "\n"
#define REP(i,n) for(int (i)=0;(i)<(n);++(i))
#define ALL(cont) begin(cont),end(cont)
#define AS_MOD(a,b) ((((a) % (b) ) + (b)) % (b))
#define FEACH(it,cont) for(auto (it) = begin(cont); it!=end(cont);++it)
#define FEACHR(it,cont) for(auto (it) = rbegin(cont); it!=rend(cont);++it)
#define pb push_back
#define pob pop_back
#define fi first
#define se second
#define getll() ([](){ll s;scanf("%lld", &s);return s;})()
#define getld() ([](){ld s;scanf("%Lf", &s);return s;})()
#define prl(P) printf("%lld", P)
#define prd(P) printf("%.10Lf", P)
#define pr(P) printf(P)
#define assign_if_greater(V, T) V=max(V,T)
using namespace std;
typedef long long ll;
typedef long double ld;
int A,B,Q;
ll As[100000];
ll Bs[100000];
ll INF=(ll)1000*1000*1000*1000;
int main() {

  scanf("%d%d%d", &A, &B, &Q);
  REP(i,A)
    As[i]=getll();
  REP(i,B)
    Bs[i]=getll();
  REP(i,Q) {
    ll x;
    scanf("%lld", &x);
    ll* ita=lower_bound(As, As+A, x);
    ll* itb=lower_bound(Bs, Bs+B, x);
    ll ans=INF;
    ll alis[2],blis[2];
    alis[0]=ita!=As+A?*ita:INF;
    blis[0]=itb!=Bs+B?*itb:INF;
    alis[1]=ita!=As?ita[-1]:-INF;
    blis[1]=itb!=Bs?itb[-1]:-INF;
    for(ll a:alis)
      for(ll b:blis) {
        ans = min(ans,abs(a-x)+abs(b-a));
        ans = min(ans,abs(b-x)+abs(b-a));
      }
    printf("%lld\n",ans);
  }


  return 0;
}


Measured memory_bytes: 2816
import sys
n = int(input())
A = [int(e)for e in sys.stdin]
cnt = 0
G = [int((2.25**i-1)/1.25)for i in range(17,0,-1)]
G = [v for v in G if v <= n]
def insertionSort(A, n, g):
    global cnt
    for i in range(g, n):
        v = A[i]
        j = i - g
        while j >= 0 and A[j] > v:
            A[j+g] = A[j]
            j = j - g
            cnt += 1
        A[j+g] = v
for g in G:
    insertionSort(A, n, g)
print(len(G))
print(*G)
print(cnt)
print('\n'.join(map(str,A)))


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

#define ipair pair<int,int>
#define rep(i,n) for(i=0;i<n;i++)
#define repj(i,j,n) for(i=j;i<n;i++)

#define PB(a,i) (a).push_back(i)
#define ALL(a) (a).begin(),(a).end()
#define SIZE(a,n) (a).resize(n)

#define OK(i) cout<<"OK "<<i<<endl
#define Yes cout<<"Yes"<<endl
#define YES cout<<"YES"<<endl
#define No cout<<"No"<<endl
#define NO cout<<"NO"<<endl

using namespace std;

typedef long long int lli;
typedef long long ll;
typedef vector<int> vi;
typedef vector< vector<int> > Matrix;



int main() {
	int a, b;

	cin >> a >> b;

	if (a >= 13)cout << b;
	else if (a >= 6)cout << b / 2;
	else cout << 0;

	return 0;
}


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

void Push(stack<long long> &st, long long val) {
    int op = st.top(); st.pop();
    long long back = st.top(); st.pop();
    if (op == -1) back += val;
    else back *= val;
    st.push(back);
    st.push(op);
}

void Pop(stack<long long> &st) {
    st.pop();
    long long val = st.top(); st.pop();
    int op = st.top(); st.pop();
    long long back = st.top(); st.pop();
    if (op == -1) back += val;
    else back *= val;
    st.push(back);
    st.push(op);
}

void print(stack<long long> st) {
    while (!st.empty()) {
        cout << st.top() << ", ";
        st.pop();
    }
    cout << endl;
}

int main() {
	int n;
	while (cin >> n) {
		if (n == 0) break;
        if (n == 1) {
            int num; cin >> num;
            cout << num << endl;
        }
        else {
            stack<long long> st;
            for (int _ = 0; _ < n; ++_) {
                string str; cin >> str;
                int s = (int)str.size() - 1;

                while (st.size() > s * 2) Pop(st);
                if (str.back() == '+') st.push(0), st.push(-1);
                else if (str.back() == '*') st.push(1), st.push(-2);
                else Push(st, str.back() - '0');
                
                //print(st);
            }
            while (st.size() > 2) Pop(st);
            st.pop();
            cout << st.top() << endl;
        }
	}
}


Measured memory_bytes: 3200
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
#define rep(i,m,n) for(int (i)=(m);(i)<(n);++(i))
#define rREP(i,m,n) for(int (i)=(n)-1;(i)>=(m);--(i))
#define all(x) (x).begin(),(x).end()
#define out(y,x,h,w) (y)<0||(x)<0||(y)>=(h)||(x)>=(w)
constexpr int INF = 1000000001;
constexpr ll mod = 1000000007;
constexpr double PI = 3.1415926535897932;
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;
}
inline void init() {
	cin.tie(nullptr); cout.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}


int main() {
	init();

	int n, m; cin >> n >> m;
	vector<int>price(m);
	rep(i, 0, m)cin >> price[i];
	vector<int>dp(n + 1, INF);
	dp[0] = 0;
	rep(i, 0, n + 1) {
		if (dp[i] == INF)continue;
		rep(j, 0, m) {
			if (i + price[j] > n)continue;
			dp[i + price[j]] = min(dp[i + price[j]], dp[i] + 1);
		}
	}
	cout << dp[n] << "\n";

	return 0;
}



Measured memory_bytes: 3220
#include <bits/stdc++.h>
using namespace std;
#define lo long
const int lmax=1999999999;
const long long lmx=1999999999999999999;
int w;
string s;
int main(){std::ios::sync_with_stdio(false);
cin>>s>>w;
for(int i=0;i<s.size();i+=w)
{
	cout<<s[i];
}
cout<<endl;
}
/*

                   *         *
                  * *       * *
                 *   *     *   *
                *     *   *     *
               *       * *       *
               *        *        *
                *               *
                 *             *
                  *           *
                   *         *
                    *       *
                     *     *
                      *   *
                       * *
                        *



*/





Measured memory_bytes: 256
N = int(input())
F = [list(map(int, input().split())) for _ in range(N)]
P = [list(map(int, input().split())) for _ in range(N)]

ans = -(1<<60)
for bit in range(1, 1<<10): # 2**10
  tmp = 0
  for i in range(N):
    cnt = 0
    for j in range(10):
      if (bit>>j)&1 and F[i][j]:
        cnt += 1
    tmp += P[i][cnt]
  
  if ans<tmp:
    ans = tmp
print(ans)
    

Measured memory_bytes: 3064
#include<iostream>
#include<map>
#include<algorithm>
#include<vector>

using namespace std;

struct s {
  long long l;
  long long r;
  bool operator<(const s& ss) const {
    return r < ss.r;
  }
};

struct s2 {
  long long l;
  long long r;
  bool operator<(const s2& ss) const {
    return l < ss.l;
  }
};

int main(){
    long long N;
    cin>>N;
    vector<struct s> v;
    vector<struct s2> v2;
    for(long long i=0;i<N;i++){
        long long X,L;
        cin>>X>>L;
        struct s ts;
        ts.l=X-L;
        ts.r=X+L;
        struct s2 ts2;
        ts2.l=X-L;
        ts2.r=X+L;
        v.push_back(ts);
        v2.push_back(ts2);
    }

    sort(v.begin(),v.end());
    sort(v2.begin(),v2.end());

    long long ans=0;
    long long x=-99999999999;
    for(long long i=0;i<v.size();i++){
        //cout<<v[i].l<<","<<v[i].r<<endl;
        if(x<=v[i].l){
            ans++;
            x=v[i].r;
        }
    }
    long long ans2=0;
    long long x2=999999999999;
    for(long long i=v.size()-1;i>=0;i--){
        //cout<<v[i].l<<","<<v[i].r<<","<<x2<<","<<ans2<<endl;
        if(x2>=v[i].r){
            ans2++;
            x2=v[i].l;
        }
    }
    long long ans3=0;
    long long x3=-99999999999;
    for(long long i=0;i<v2.size();i++){
        //cout<<v[i].l<<","<<v[i].r<<endl;
        if(x3<=v2[i].l){
            ans3++;
            x3=v2[i].r;
        }
    }
    long long ans4=0;
    long long x4=999999999999;
    for(long long i=v2.size()-1;i>0;i--){
        //cout<<v[i].l<<","<<v[i].r<<endl;
        if(x4>=v2[i].r){
            ans4++;
            x4=v2[i].l;
        }
    }
    cout<<max(ans,max(ans3,max(ans2,ans4)))<<endl;
}


Measured memory_bytes: 3692
<?php
fscanf(STDIN, "%d%d%d%d%d", $hs, $ms, $he, $me, $long);

$dist = ($he * 60 + $me) - ($hs * 60 + $ms);
if($dist > $long){
    echo $dist - $long;
}else{
    echo 0;
}

Measured memory_bytes: 16060
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define INF 1000000009
typedef long long ll;
#define REP(i,n) for(int i=0;i<(n);i++)
#define RREP(i,n) for(int i=(n)-1;i>=0;i--)
#define rollcall cout<<"I'm Sucu."<<endl
#define YES(s) s?cout << "YES" << endl:cout << "NO" << endl
#define Yes(s) s?cout << "Yes" << endl:cout << "No" << endl
#define Taka(s) s?cout << "Takahashi" << endl:cout << "Aoki" << endl
#define int ll

signed main(void){
   int N;
   cin >> N;
   if(N%2==0){
       cout << N;
   }else{
       cout << 2*N;
   }
   cout << endl;
  return 0;
}


Measured memory_bytes: 256
n,k,c=map(int,input().split())
s=list(input())
i=0
l=[0]*k
r=[0]*k
j=0
while i<n and l[-1]==0:
  if s[i]=='o':
    l[j]=i+1
    i+=c+1
    j+=1
  else:
    i+=1
i=0
j=k-1
while i<n and r[0]==0:
  if s[-i-1]=='o':
    r[j]=n-i
    i+=c+1
    j-=1
  else:
    i+=1
for i in range(k):
  if r[i]==l[i]:
    print(r[i])

Measured memory_bytes: 21916
#include <stdio.h>
#include <algorithm>

// 入力受付用の変数
#define BUF 200002
char str[BUF];

// 入力された値
#define LIM_A 100001
int N;
int L[LIM_A];

bool comp(int a, int b) {
	return b < a;
}

void receive_input() {
	fgets(str, sizeof(str), stdin);
	sscanf(str, "%d", &N);

	for (size_t i = 0; i < N; i++) {
		scanf("%d", &L[i]);
	}
}

void solve() {
	std::sort(L, L+N, comp);

	int ans = 0;

	for (size_t i = 0; i < N; i++) {
		for (size_t j = i+1; j < N; j++) {
			if (L[i] > L[j] * 2) {
				break;
			}

			for (size_t k = j+1; k < N; k++) {
				if (L[i] < L[j] + L[k]) {
					ans ++;
				} else {
					break;
				}
			}
		}
	}

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


int main(void) {
	receive_input();

	solve();

	return 0;
}


Measured memory_bytes: 128
#pragma comment(linker,"/stack:16777216")
#include<iostream>
#include<cstdio>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<list>
#include<stack>
#include<queue>
#include<deque>
#include<functional>
#include<utility>
#include<algorithm>
#include<sstream>
#include<cstring>
#include<cmath>
#include<cctype>
#include<exception>
#include<climits>
#include<cfloat>
#include<iomanip>
#include<bitset>
#include<streambuf>
#include<cstdlib>
#include<ctime>
//#include"functions.h"
//#include"highprecision.h"
#define pb push_back
#define pf push_front
#define ppb pop_back
#define mp make_pair
#define np next_permutation
#define fi first
#define sc second
#define vi vector<int>
#define vll vector<long long>
#define vvi vector<vector<int> >
#define vpi vector<pair<int,int> >
#define pii pair<int,int>
#define pll pair<long long,long long>
#define pff pair<float,float>
#define pdd pair<double,double>
#define psi pair<string,int>
#define pis pair<int,string>
#define ppi pair<pii,int>
#define pdi pair<pii,pii>
#define LN 84757
#define INF 1e9
#define LLINF 1e18
#define MAXINT 0x7fffffff
#define MAXLL 0x7fffffffffffffff
#define EPS 1e-5
#define DEPS 1e-9
#define LDEPS 1e-13
#define MOD 1000000007
#define E 2.7182818284
#define PI 3.1415926535
#define rep(a,b) for(int a=0;a<b;a++)
#define rep(a,b) for(int a=0;a<b;a++)
#define forn(a,n) for(int a=1;a<=n;a++)
#define forr(a,n) for(int a=n;a>=1;a--)
#define repn(a,n,p) for(int a=0;a<n;a+=p)
#define repr(a,n) for(int a=n-1;a>=0;a--)
#define foreach(a,b) for(__typeof(b.begin())a=b.begin();a!=b.end();a++)
#define fillemp(a) memset(a,0,sizeof(a))
#define fillinf(a) memset(a,0x3f,sizeof(a))
#define frestream freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define stdf(a,b) freopen(a,"r",stdin);freopen(b,"w",stdout);
#define inputf(a) freopen(a,"r",stdin);
#define outputf(a) freopen(a,"w",stdout);
#define sz(a) a.size()
#define all(a) a.begin(),a.end()
#define MOD 1000000007
typedef long long ll;
typedef long double ld;
using namespace std;

int main(int argc,char** argv){
	int a[10];
	rep(i,5)cin>>a[i];
	rep(i,5){
		if(a[i]==0){
			cout<<i+1;
			return 0;
		}
	}
	return 0;
}

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

using namespace std;

int A, B, C;
int X;

int myrand() {
    int res = X;
    X = (A*X + B) % C;
    return res;
}

bool solve() {
    int N;
    cin >> N >> A >> B >> C >> X;
    if(!N && !A && !B && !C && !X) return false;

    vector<int> ys(N);
    for(int i = 0; i < N; ++i) {
        cin >> ys[i];
    }
    int turn = 0;
    int pos = 0;
    for(; turn <= 10000; ++turn) {
        int rv = myrand();
        if(rv == ys[pos]) {
            ++pos;
            if(pos == N) break;
        }
    }
    cout << (turn > 10000 ? -1 : turn) << endl;
    return true;
}

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

    for(int case_num = 1; solve(); ++case_num) ;
    return 0;
}

Measured memory_bytes: 1200
#include<bits/stdc++.h>
using namespace std;
int main(){
    int A, B, C, D, N, K, H, X, Y, ans=0;
    vector<int> v(3);
    string S;
    cin >> v[0] >> v[1] >> v[2];

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


    
    // cout <<ans<<endl;
    
    // if(A<B)
    // 	cout << 0<<endl;
    // else
    // 	cout <<10<<endl;
    

    // string S;
    // cin >>S;
    // cout << S + "pp"<<endl;

    if(v[0]==5 && v[1]==5 && v[2]==7)
    	puts("YES");
    else
    	puts("NO");    
    	
}


Measured memory_bytes: 256
#include<iostream>
#include<sstream>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<algorithm>
#include<numeric>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<cassert>

#define rep(i,n) for(int i=0;i<n;i++)
#define all(c) (c).begin(),(c).end()
#define mp make_pair
#define pb push_back
#define rp(i,c) rep(i,(c).size())
#define fr(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define dbg(x) cerr<<#x<<" = "<<(x)<<endl

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
const int inf=1<<28;
const double INF=1e12,EPS=1e-9;

int main()
{
	int sum;
	while(cin>>sum,sum)
	{
		int t;
		rep(i,9)cin>>t,sum-=t;
		cout<<sum<<endl;
	}
	
	return 0;
}

Measured memory_bytes: 0
A=int(input())
B=int(input())
C=int(input())
X=int(input())
cnt=0
for i in range(A+1):
	for j in range(B+1):
		for k in range(C+1):
			if 500*i+100*j+50*k==X:
				cnt=cnt+1

print(cnt)

Measured memory_bytes: 3060
#include<queue>
#include<cstdio>
#include<algorithm>

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

using namespace std;

int hash(const vector<int> &a){
	int n=a.size();
	int res=0,fac=1;
	rep(i,n){
		int c=0;
		for(int j=i+1;j<n;j++) if(a[i]<a[j]) c++;
		res+=c*fac;
		fac*=n-i;
	}
	return res;
}

void bfs(vector<int> a,short *memo){
	int n=a.size();
	memo[hash(a)]=0;
	queue< pair<int,vector<int> > > Q; Q.push(make_pair(0,a));
	while(!Q.empty()){
		int t=Q.front().first;
		vector<int> a=Q.front().second; Q.pop();

		if(t==4) break;

		rep(l,n) for(int r=l+1;r<n;r++) {
			reverse(a.begin()+l,a.begin()+r+1);
			int h=hash(a);
			if(memo[h]==-1){
				memo[h]=t+1;
				Q.push(make_pair(t+1,a));
			}
			reverse(a.begin()+l,a.begin()+r+1);
		}
	}
}

int main(){
	int n; scanf("%d",&n);
	int fact=1;
	vector<int> a(n);
	rep(i,n) scanf("%d",&a[i]), fact*=i+1;

	static short memo1[3628800],memo2[3628800];
	rep(i,fact) memo1[i]=memo2[i]=-1;
	bfs(a,memo1);
	sort(a.begin(),a.end());
	bfs(a,memo2);

	int ans=9;
	rep(i,fact) if(memo1[i]!=-1 && memo2[i]!=-1) ans=min(ans,memo1[i]+memo2[i]);
	printf("%d\n",ans);

	return 0;
}

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

int main(){
	int h, m, s;
	cin >> s;
	h = s / 3600;
	s %= 3600;
	m = s / 60;
	s %= 60;
	
	cout << h << ':' << m << ':' << s << endl;
	
	return 0;
}


Measured memory_bytes: 3084
#include<stdio.h>
#include<math.h>
#define N 10000
#define TRUE 1
#define FALSE 0
int isprime(int);
int main()
{
  int i,a,b[N],c=0;
  scanf("%d",&a);
  for(i=0;i<a;i++){
    scanf("%d",&b[i]);
    if(isprime(b[i])==TRUE)c++;
  }
  printf("%d\n",c);
       
  return 0;
}
int isprime(int x){
  int i,a;
  if(x==2)return TRUE;
  
  if(x<2||x%2==0)return FALSE;
  i=3;
  a=sqrt(x);
  while(i<=a){
    if(x%i==0)return FALSE;
    i=i+2;
  }
    return TRUE;
}




Measured memory_bytes: 2128
/************************************************
   Start coding only after you have clear idea. 
*************************************************/

#include <bits/stdc++.h>

#define x first
#define y second
#define pii pair<int,int>
#define sz(x) (int)(x).size()
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long LL;
const int maxm = 2e3+23;
const int maxn = 2e5+35;
int n,a[maxn];
int main(){
    cin >> n;
    int ans = 0;
    for(int i = 1;i <= n; ++i){
        cin >> a[i];
        if((i&1)&&(a[i]&1)) ans += 1;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3620
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;
#define rep(i, begin, n) for (int i = begin; i < n; i++)
#define repe(i, begin, n) for (int i = begin; i <= n; i++)
#define repr(i, begin, n) for (int i = begin; i > begin - n; i--)
#define repre(i, begin, end) for (int i = begin; i >= end; 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;
}

const int inf = 1000000007;
const int MOD = 1000000007;
const long long INF = 1000000000000000007;

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

int H, W;
string S[2020];
int up[2020][2020], down[2020][2020], l[2020][2020], r[2020][2020];

int main() {
  cin >> H >> W;
  rep(i, 0, H) { cin >> S[i]; }

  for (int j = 0; j < W; ++j) {
    for (int i = 1; i < H; ++i) {
      if (S[i - 1][j] == '.') {
        up[i][j] = up[i - 1][j] + 1;
      } else {
        up[i][j] = 0;
      }
    }

    for (int i = H - 2; i >= 0; --i) {
      if (S[i + 1][j] == '.') {
        down[i][j] = down[i + 1][j] + 1;
      } else {
        down[i][j] = 0;
      }
    }
  }

  for (int i = 0; i < H; ++i) {
    for (int j = 1; j < W; ++j) {
      if (S[i][j - 1] == '.') {
        l[i][j] = l[i][j - 1] + 1;
      } else {
        l[i][j] = 0;
      }
    }

    for (int j = W - 2; j >= 0; --j) {
      if (S[i][j + 1] == '.') {
        r[i][j] = r[i][j + 1] + 1;
      } else {
        r[i][j] = 0;
      }
    }
  }

  int ans = 0;
  rep(i, 0, H) {
    rep(j, 0, W) {
      if (S[i][j] == '#') continue;

      chmax(ans, up[i][j] + down[i][j] + l[i][j] + r[i][j] + 1);
    }
  }

  cout << ans;
}


Measured memory_bytes: 74284
#include <iostream>
#include <string>
#include <queue>
#include <stack>
#include <algorithm>
#include <list>
#include <vector>
#include <complex>
#include <utility>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <bitset>
#include <ctime>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cassert>
#include <cstddef>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <sstream>
#include <fstream>
#include <functional>

using namespace std;
#define REP(i, n) for (int (i) = 0; (i) < (n); (i)++)
#define FOR(i, a, b) for (int (i) = (a); (i) < (b); (i)++)
#define RREP(i, a) for(int (i) = (a) - 1; (i) >= 0; (i)--)
#define FORR(i, a, b) for(int (i) = (a) - 1; (i) >= (b); (i)--)
#define DEBUG(C) cerr << #C << " = " << C << endl;
using LL = long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<LL>;
using VVL = vector<VL>;
using VD = vector<double>;
using VVD = vector<VD>;
using PII = pair<int, int>;
using PDD = pair<double, double>;
using PLL = pair<LL, LL>;
using VPII = vector<PII>;
template<typename T> using VT = vector<T>;
#define ALL(a) begin((a)), end((a))
#define RALL(a) rbegin((a)), rend((a))
#define SORT(a) sort(ALL((a)))
#define RSORT(a) sort(RALL((a)))
#define REVERSE(a) reverse(ALL((a)))
#define MP make_pair
#define FORE(a, b) for (auto &&a : (b))
#define EB emplace_back
#define GREATER(T) T, VT<T> greater<T>
template<typename T> inline bool chmax(T &a, T b){if (a < b){a = b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if (a > b){a = b;return true;}return false;}

const int INF = 1e9;
const int MOD = INF + 7;
const LL LLINF = 1e18;

int main() {
    int a[] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
    int K;
    cin >> K;
    cout << a[K - 1] << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define sz(x) (int)(x).size()
#define Ifor(i, a, b) for (int i = int(a); i < int(b); i++)
#define Dfor(i, a, b) for (int i = int(b) - 1; i >= int(a); i--)
#define Trav(e, v) for (auto& e : v)
#define pb push_back
#define mp make_pair
#define all(x) begin(x), end(x)
using namespace std;
using ll = long long;
using ii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vii = vector<ii>;
template <typename T> bool ckmin (T& a, T b) { return (b < a) ? a = b, 1 : 0; }
template <typename T> bool ckmax (T& a, T b) { return (b > a) ? a = b, 1 : 0; }
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#ifdef XVENOM
	#define errp(...) fprintf(stderr, __VA_ARGS__)
	#define dbg(...) errp("[%s]: ", #__VA_ARGS__), dbg_str(__VA_ARGS__)
#else
	#define errp(...)
	#define dbg(...)
#endif
template <typename U, typename V> string to_string (pair<U, V>);
string to_string (string& e) { return "\"" + e + "\""; }
string to_string (char e) { return "\'" + string(1, e) + "\'"; }
string to_string (bool e) { return e ? "true" : "false"; }
template <typename T> string to_string (T e) {
	string s = "[ ";
	for (auto& x : e) s += to_string(x) + " ";
	return s + "]";
}
template <typename U, typename V> string to_string (pair<U, V> e) {
	return "(" + to_string(e.first) + ", " + to_string(e.second) + ")";
}
void dbg_str () { errp(" \n"); }
template <typename U, typename... V> void dbg_str (U u, V... v) {
 	errp(" %s", to_string(u).c_str()); dbg_str(v...);
}
/* --- */
const int N = 110;
int n, f[N][11], p[N][11];

int profit (int b) {
	int pr = 0;
	Ifor(i, 0, n) {
		int cnt = 0;
		Ifor(j, 0, 10) if ((b & (1 << j)) && f[i][j + 1])
			cnt++;
		pr += p[i][cnt];
	}
	return pr;
}

int main() {
	ios_base::sync_with_stdio(0); cin.tie(0);
	/* --- */
	cin >> n;
	Ifor(i, 0, n) Ifor(j, 1, 11) cin >> f[i][j];
	Ifor(i, 0, n) Ifor(j, 0, 11) cin >> p[i][j];
	int ans = profit(1);
	Ifor(i, 1, (1 << 10)) ckmax(ans, profit(i));
	cout << ans << '\n';
}



Measured memory_bytes: 256
//標準関数をすべてインクルードする。
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;

const int_least64_t INF = 10000000;

int main(){
    //cin coutを高速化
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);
	std::cout.tie(0);

    string s, t, u;
    int a, b;
    cin >> s >> t;
    cin >> a >> b;
    cin >> u;

    if(s == u){
        --a;
    }else{
        --b;
    } 

    cout << a << ' ' << b << endl;

    return 0;
}

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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,n,m) for(int i=(int)(n); i<=(int)(m); i++)
#define RFOR(i,n,m) for(int i=(int)(n); i>=(int)(m); i--)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)

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 ld long double
#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>

#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 mp make_pair
#define ins insert

using namespace std;

/* Some Libraries */

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

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s; cin>>s;
    cout<<s[0]<<s.size()-2<<s[s.size()-1]<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define ppb         pop_back
#define endl        '\n'
#define mii         map<ll int,ll int>
#define msi         map<string,ll int>
#define mis         map<ll int, string>
#define rep(i,a,b)    for(ll int i=a;i<b;i++)
#define repp(i,a,b)    for(ll int i=b-1;i>=a;i--)
#define tr(container,it) for(__typeof__(container.begin()) it = container.begin(); it != container.end(); it++)
#define pii         pair<ll int,ll int>
#define vi          vector<ll int>
#define mpi         map<pair<ll int,ll int>,ll int>
#define vii         vector<pair<ll,pair<ll,ll> > >
#define vs          vector<string>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll)x.size()
#define hell        998244353
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
#define what_is(x)  cerr << #x << " is " << x << endl;
using namespace std;
#define N  300005
#define time        cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";

// ll m[20000005];
// class MemoryGame{
// public:
// // vs construct(int n){
void solve(){
	ll a,b,h,m;
	cin>>a>>b>>h>>m;
	h*=5;
	long double x=abs(h-m+m/12.0);
	x=min(x,60-x);
	if(x==30){
		cout<<a+b<<endl;
		return;
	}	
	if(x==0){
		cout<<abs(a-b);
		return;
	}
	x=(x*2*M_PI)/60.0;
	long double c=a*a+b*b-2*a*b*cos(x);
	cout<<setprecision(20)<<sqrt(c);
}
// };
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    ll TESTS=1,an=1;
    // cin>>TESTS;
    while(TESTS--){
        // cout<<"Case #"<<an<<": ";
        an++;
        solve();

    }
    return 0;
}           

Measured memory_bytes: 4176
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define REP(i,a,b) for(int i=int(a);i<(int)b;++i)
#define Graph vector<vecctor<ll>>
#define pairs vector<pair<ll,ll>>
#define pb push_back



using namespace std;
using ll = long long;
const ll INF = 1e18;
const double PI = acos(-1);

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

const ll mod = 1e9 + 7;

ll modpow(ll a, ll b){
    if(b == 0)return 1;
    if(b%2 == 0){
        ll k = modpow(a,b/2);
        return k*k%mod;
    }else{
        return modpow(a,b-1)*a%mod;
    }
}

int main(void)
{
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);
    int a,b;
    cin >> a >> b;
    rep(i,3){
        if(i+1 != a && i+1!=b){
            cout << i+1 << endl;
            break;
        }
    }
    return 0;


}


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

#define int long long
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define REP(i, n) for (int i = 0; i < n; ++i)
#define range(i,a,b) ((a)<=(i) && (i)<(b))
#define debug(x) cout << #x << " = " << (x) << endl;
#define fs first
#define sc second
#define pb push_back
#define eb emplace_back
#define SP << " " <<

typedef long long ll;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;
typedef vector<int> vec;
typedef vector<P> pvec;
typedef vector<vector<int>> vvec;
typedef vector<vector<P>> pvvec;
typedef priority_queue<int> PQI;
typedef priority_queue<P> PQP;
typedef priority_queue<int,vector<int>,greater<int>> PQIG;
typedef priority_queue<P,vector<P>,greater<P>> PQPG;

const vector<int> DX = {0, -1, 0, 1, 1, 1, -1, -1};
const vector<int> DY = {1, 0, -1, 0, 1, -1, 1, -1};
constexpr int MOD = (1000000007);
// const int MOD = (998244353);
// const int INF = (1 << 30); // 1073741824
const ll INF = (1LL << 60); // 1152921504606846976
const double PI = (3.141592653589794);
const double EPS = (0.0000000001); // 10^(-10)

template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return 1;} return 0;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return 1;} return 0;}
template<class T> inline T ceil(T a, T b) {return T((a + b - 1) / b);}
template<class T> inline T round(T a, T b) {return T(a / b);}
template< typename T1, typename T2 > istream &operator>>(istream &is, pair< T1, T2 > &p) { is >> p.first >> p.second; return is; }
template <class T> inline void out(T &a) { bool flag=true; for(auto&x:a){if(flag) {flag=false;} else{ cout << ' '; } cout<<x; } cout << endl; }



//----------------------------------------------------------------
int nmax=200000; // 2*(10^5)
vvec G(nmax);





void solve4ts()
{
  
  
  int n,k;
  cin>>n>>k;
  vector<int> a(n);
  rep(i,n) cin >> a[i];
  sort(all(a));
  int ans=0;
  rep(i,k) ans+=a[i];
  cout<<ans<<endl;
  
  
}
//-----------------------------------------------------------------

signed main(){ ios::sync_with_stdio(false); cin.tie(0); cout << fixed << setprecision(15);
    int repeat = 1;
    // cin >> repeat;
    while(repeat--) solve4ts();
}

Measured memory_bytes: 7812
#include <iostream>
#include <queue>
#include <stack>
#include <vector>
#include <stdio.h>
#include <algorithm>
#include <string.h>
#include <string>
#include <cmath>
#include <complex>
#include <map>
using namespace std;

#define rep(i,n) for(int i=0;i<int(n);++i)
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define EPS 1e-8
#define F first
#define S second

static const double PI=6*asin(0.5);
typedef long long ll;
typedef complex<double> CP;
typedef pair<long long,int> P;
static const int INF=1<<24;

int n;
int a[10100],b[10100];

int main(){
	while(cin>>n,n){
		rep(i,n){
			cin>>a[i]>>b[i];
		}
		ll ans1=0,ans2=0;
		rep(i,n){
			if(a[i]<b[i]){
				ans2+=a[i]+b[i];
			}
			else if(a[i]==b[i]){
				ans1+=a[i];
				ans2+=b[i];
			}
			else{
				ans1+=a[i]+b[i];
			}
		}
		cout<<ans1<<" "<<ans2<<endl;
	}
	return 0;
}

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

struct st {
	char f[10][11]; int cnt;
};
int w, h, dx[]{ 1,-1,0,0 }, dy[]{ 0,0,1,-1 };
char dir[] = "RGB";
bool ok(st&s) {
	char c = s.f[0][0];
	rep(i, h)rep(j, w) {
		if (s.f[i][j] != c)return false;
	}
	return true;
}
void dfs(st&s, int x, int y, char b, char c) {
	s.f[x][y] = c;
	rep(i, 4) {
		int nx = x + dx[i], ny = y + dy[i];
		if (0 <= nx&&nx < h && 0 <= ny&&ny < w&&s.f[nx][ny] == b)
			dfs(s, nx, ny, b, c);
	}
}
int main() {
	while (scanf("%d%d", &w, &h), h) {
		st in; in.cnt = 0; memset(in.f, 0, sizeof(in.f));
		rep(i, h)rep(j, w)cin >> in.f[i][j];
		queue<st>que; que.push(in);
		while (1) {
			st p = que.front(); que.pop();
			if (ok(p)) {
				printf("%d\n", p.cnt); break;
			}st u;
			rep(i, 3) {
				u = p;
				if (dir[i] == u.f[0][0])continue;
				dfs(u, 0, 0, u.f[0][0], dir[i]); u.cnt++;
				que.push(u);
			}
		}
	}
}

Measured memory_bytes: 31716
def solve(n, a_list):
    if n % 2 == 0:
        res_a = [0] * (n // 2 + 1)
        res_b = [0] * (n // 2 + 1)
        for i in range(0, n // 2):
            res_a[i + 1] = res_a[i] + a_list[i * 2]
        for i in range(n // 2 - 1, -1, -1):
            res_b[i] = res_b[i + 1] + a_list[i * 2 + 1]
        return max([res_a[i] + res_b[i] for i in range(n // 2 + 1)])
    else:
        # type a
        dp = [[0] * 3 for _ in range(n)]
        dp[0][0] = a_list[0]
        dp[1][1] = a_list[1]
        dp[2][2] = a_list[2]
        for i in range(n):
            if i % 2 == 0:
                if i >= 2:
                    dp[i][0] = dp[i - 2][0] + a_list[i]
                    dp[i][1] = dp[i - 1][1]
                if i >= 3:
                    dp[i][2] = max(dp[i - 3][1] + a_list[i], dp[i - 2][2] + a_list[i])
            else:
                if i >= 3:
                    dp[i][1] = max(dp[i - 2][1] + a_list[i], dp[i - 3][0] + a_list[i])
                dp[i][0] = dp[i - 1][0]
                dp[i][2] = dp[i - 1][2]
        res_a = max(dp[-1])
        # print(dp)

        # type b
        even = [a_list[i] for i in range(0, n, 2)]
        res_b = sum(even) - min(even)

        return max(res_a, res_b)


def main():
    n = int(input())
    a_list = list(map(int, input().split()))
    res = solve(n, a_list)
    print(res)


def test():
    assert solve(6, [1, 2, 3, 4, 5, 6]) == 12
    assert solve(5, [-1000, -100, -10, 0, 10]) == 0
    assert solve(10, [1000000000] * 10) == 5000000000


if __name__ == "__main__":
    test()
    main()


Measured memory_bytes: 53048
#include<iostream>
#include<iomanip>
#include<vector>
#include<map>
#include<set>
#include<algorithm>
#include<numeric>
#include<limits>
#include<bitset>
#include<functional>
#include<type_traits>
#include<queue>
#include<stack>
#include<array>
#include<random>
#include<utility>
#include<cstdlib>
#include<ctime>

using namespace std;

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

#define rep(i,n) for(int i=0;i<(int)n;i++)
#define rep2(i, begin_i, end_i) for (int i = (int)begin_i; i < (int)end_i; i++)
#define ll long long

long long INF = 1LL<<60;
long long dp[100010];
int h[100010];

int main(){
    int n,count=0,temp=0;
    cin>>n;
    map<int,int> a;
    rep(i,n){
        int t;
        cin>>t;
        a[t]++;
    }
    for(auto it=a.begin();it!=a.end();it++){
        if(it->second%2==1)
            count++;
    }
    cout<<count<<endl;
    return 0;
}




Measured memory_bytes: 4992
N, K = tuple(map(int, input().split()))

def cmb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2,r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result


a = N - K + 1
b = K - 1
for i in range(1, K+1):
    if i > a:
        for j in range(i, K+1):
            print(0)
        break
    print((cmb(a, i) * cmb(b, i - 1)) % 1000000007)


Measured memory_bytes: 3316
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define llu unsigned long long int
#define sa(a,n,t) for(int ii=0;ii<n;ii++) scanf("%"#t"",&(a)[ii])
#define rep(i,n) for(int i=0;i<n;i++) 
#define reps(i,a,n) for(int i=a;i<n;i++) 
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define rreps(i,a,n) for(int i=n-1;i>=a;i--)
#define validl(i,a,b) ((i>=a)&&(i<=b))?1:0
#define validmat(x,y,a,b,c,d) (validl(x,a,b) && validl(y,a,b))?1:0
#define validmn(x,y,m,n) validmat(x,y,0,m,0,n)
#define valid(i,n) validl(i,0,n)
#define v(t) vector<t>
#define vv(t) vector<vector<t> >
#define mk make_pair
#define pb push_back
#define pa(a,n,t)  for(int i=0;i<n;i++) printf("%"#t"",a[i])
#define p2 pair<int,int>
#define p3 pair<p2,int>
#define fi first
#define se second
#define sd(a) scanf("%d",&a)
#define sl(a) scanf("%lld",&a)
#define pl(a) printf("%lld",a)
#define pd(a) printf("%d",a)
#define sf(a) scanf("%lf",&a)
#define pf(a) printf("%lf",a)
#define nline printf("\n")
#define ss(a) scanf("%s",a)
#define ps(a) printf("%s",a)
#define sc(a) scanf("%c",&a)
#define pc(a) printf("%c",&a)
#define mf(m,f) m.find(f)!=m.end()
#define pp3(m) cout<<m.fi.fi<<" "<<m.fi.se<<" "<<m.se<<" "
#define pp2(m) cout<<m.fi<<" "<<m.se<<" "
#define debug 0
/*v(int) adj[200001];
void dfs(int i,int p){
    rep(j,adj[i].size()){
        if(p!=adj[i][j])
            dfs(adj[i][j],i);
    }
}*/
int main()
{
 
  int arr[100];
  int n,k;
  cin>>n;
  rep(i,n){
      cin>>arr[i];
  }
  lli ans=1000;
  rep(i,n-1){
      if(arr[i]<arr[i+1]){
          lli st=ans/arr[i];
          ans-=st*arr[i];
          ans+=st*arr[i+1];
      }
  }
  cout<<ans<<endl;
  //cout<<d;
  return 0;
}


Measured memory_bytes: 3628
#include<bits/stdc++.h>
#define ll long long
#define N 3000
#define M 1000000007
#define pii pair<ll,ll>
#define fast ios_base::sync_with_stdio(0);cin.tie(0);
using namespace std;
vector<pii>v;
ll dp[N][N];
int n;
ll run(int idx,int first)
{
    if(idx==n)
        return 0;
    if(dp[idx][first]!=-1)
        return dp[idx][first];
    ll ans=0;
    ll last=n-1-(idx-first);
    ll x=v[idx].first,y=v[idx].second;

    ans=max(ans,x*abs(y-first)+run(idx+1,first+1));
    ans=max(ans,x*abs(y-last)+run(idx+1,first));
    return dp[idx][first]=ans;
}

main()
{
    memset(dp,-1,sizeof dp);

    cin>>n;
    for(int i=0;i<n;i++)
    {
        int x;
        cin>>x;
        v.push_back({x,i});
    }
    sort(v.begin(),v.end());
    reverse(v.begin(),v.end());
    cout<<run(0,0);
}



Measured memory_bytes: 74168
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007

long long gcd(long long a,long long b) {
  if(b == 0) return a;
  else return gcd(b,a%b);
}

int main() {

  int N;
  cin >> N;

  int cnt[10][10] = {};
  for(int i = 1;i <= N;i++) {
    int h = i,t = i % 10;
    while(h >= 10) h /= 10;
    cnt[h][t]++;
  }

  int ans = 0;
  for(int i = 0;i <= 9;i++) {
    for(int j = 0;j <= 9;j++) {
      ans += cnt[i][j]*cnt[j][i];
    }
  }

  cout << ans << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
int n,m;
int t[200001];

int u[200001];

int main(){
  int i;
  
  scanf("%d %d",&n,&m);
  
  for(i=0;i<m;i++){
    scanf("%d",&t[i]);
  }
  
  for(i=m-1;i>=0;i--){
    int num=t[i];
    if( u[num] == 0 ){
      printf("%d\n",num);
      u[num]=1;
    }
  }

  for(i=1;i<=n;i++){
    if(u[i]==0){
      printf("%d\n",i);
      u[i]=1;
    }
  }
  return 0;
}

Measured memory_bytes: 1768
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <bitset>
# include <complex>
#include<limits.h>
#include<unordered_map>
#include<unordered_set>
#include<deque>
#include<cstdio>
using namespace std;
typedef long long int ll;
const int N = 1000000;
const int mod = 1000000007;
const int INF = 1 << 30;
#define rep(i,n) for(ll i=(ll)0;i<(ll)n;++i)
#define ALL(x) x.begin(),x.end()
#define pp pair<ll,ll>
#define fi first
#define se second
#define pb push_back
ll ppow(ll x, ll n) {
	ll ans = 1;
	while (n > 0) {
		if ((n & 1) == 1)ans = ans * x;
		x = x * x;
		n >>= 1;
		x %= mod;
		ans %= mod;
	}
	return ans;
}
string YN(bool b) { return(b ? "YES" : "NO"); }
string yn(bool b) { return(b ? "Yes" : "No"); }
ll sz, fact[N], inv[N];
void setinv() {
	fact[0] = 1; inv[0] = 1;
	for (int i = 1; i <= sz; i++) {
		fact[i] = (fact[i - 1] * i) % mod;  //階乗を求める
		inv[i] = ppow(fact[i], (ll)mod - 2) % mod; // フェルマーの小定理で逆元を求める
	}
}
ll conv(ll r) {//nCr
	return fact[sz] * inv[r] % mod * inv[sz - r] % mod;
}
int main() {
	ll w, h, n,ans=0;
	cin >> w >> h >> n;
	int nx, ny;
	int x, y;
	rep(i, n) {
		cin >> x >> y;
		if (i == 0) { nx = x; ny = y; continue; }
		if ((x - nx)*(y - ny) > 0) {
			ans += min(abs(x - nx), abs(y - ny));
			ans += abs(x - nx - min((x - nx), (y - ny))) + abs(y - ny - min((x - nx), (y - ny)));
		}
		else {
			ans += abs(nx - x) + abs(ny - y);
		}
		//cout << ans << endl;
		nx = x; ny = y;
	}
	cout << ans << endl;
}


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

#define int long long
#define ct(n) cout << n << endl;
#define cts(n) cout << n << " ";
#define cte cout << endl;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define repo(i,o,n) for(int i=o;i<n;i++)
#define repm(i,n) for(int i=n-1;i>=0;i--)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define sperase(v,n) (v).erase(remove(all(v), n), (v).end());
#define vdelete(v) (v).erase(unique(all(v)), (v).end());
#define vcopy(v1,v2) copy((v1).begin(), (v1).end(), back_inserter((v2)));
#define pb(n) push_back(n);

string s[3];

main() {
    rep(i,3) cin >> s[i];
    rep(i,3) cout << (char)(s[i][0]+'A'-'a');
    cte
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define INF 1e18
#define int long long
#define Rep(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) Rep(i, 0, n)
#define all(a) (a).begin(), (a).end()
using namespace std;
typedef pair<int, int> P;
typedef pair<int, P> PP;
const int mod = 1000000007;

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

    int a, b, c;
    cin >> a >> b >> c;
    cout << max({a, b, c}) - min({a, b, c}) << endl;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

constexpr int k = 10000;

int c[k];

int main()
{
    for (int i = 0; i < k; ++i) {
        c[i] = 0;
    }

    int n;
    cin >> n;
    int x;
    for (int i = 0; i < n; ++i) {
        cin >> x;
        ++c[x];
    }

    bool first = true;
    for (int i = 0; i < k; ++i) {
        if (c[i] != 0) {
            for (int j = 0; j < c[i]; ++j) {
                if (first) {
                    first = false;
                    cout << i;
                }
                else {
                    cout << " " << i;
                }
            }

        }
    }
    cout << endl;
}




Measured memory_bytes: 3140
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define sz(x) (int)(x).size()
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef set<int> S;
typedef queue<int> Q;
typedef queue<P> QP;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
const int MOD = 1000000007;

void warshall_floyed(vv(ll) &C,int V) {
  rep(k,V) {
    rep(i,V) {
      rep(j,V) {
        if(C[i][j] > C[i][k] + C[k][j]) {
          C[i][j] = C[i][k] + C[k][j];
        }
      }
    }
  }
}
  
int main() {
  int N,M,R;
  cin >> N >> M >> R;
  vi rs(R);
  rep(i,R) {
    cin >> rs[i];
  }
  vv(ll) C(N,v(ll)(N,LINF));
  rep(i,M) {
    int a,b,c;
    cin >> a >> b >> c;
    a--;
    b--;
    C[a][b] = c;
    C[b][a] = c;
  }
  warshall_floyed(C,N);
  
  sort(rng(rs));
  ll ans = LINF;
  do {
    ll cost = 0;
    rep(i,R-1) {
      int a = rs[i];
      int b = rs[i+1];
      cost += C[a-1][b-1];
    }
    ans = min(ans,cost);
  } while(next_permutation(rng(rs)));

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

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

#define INF 1e9
#define llINF 1e18
#define MOD 1e9+7
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long
using namespace std;
ll koubaisuu(ll a,ll b){
  ll ma=max(a,b);
  ll mi=min(a,b);
  ll mi2=mi;
  ll r=ma%mi;
  while(r!=0){
    ll tmp=r;
    r=mi%r;
    mi=tmp;
  }
  return ma/mi*mi2;
}
int main(){
  ll n;cin>>n;
  ll num1=0;
  cin>>num1;
  for(int i=1;i<n;i++){
    ll num2;cin>>num2;
    num1=koubaisuu(num1,num2);
  }
  cout<<num1<<endl;
  return 0;
}


Measured memory_bytes: 256
using System;
using System.Linq;
using System.Collections.Generic;

namespace Algorithm
{
    class Program
    {
        static void Main(string[] args)
        {
            var l = Console.ReadLine().Split().Select(int.Parse).ToArray();
            int N = l[0], K = l[1];
            var p = Console.ReadLine().Split().Select(int.Parse).ToArray();

            var val1 = new double[1001];
            var val2 = new double[1001];
            for (var i = 1; i <=1000; i++)
            {
                val1[i] = val1[i - 1] + i;
                val2[i] = val1[i] / i;
            }

            var ans = 0D;
            var acum = 0D;
            for (var i = 1; i <= N; i++)
            {
                acum += val2[p[i-1]];
                if (i > K) acum -= val2[p[i - K-1]];

                ans = Math.Max(ans, acum);
            }


            Console.WriteLine(ans);
        }
    }
}


Measured memory_bytes: 31452
#include <algorithm>
#include <cmath>
#include <chrono>
#include <cstdio>
#include <ctime>
#include <iostream>
#include <random>
#include <string>
#include <vector>
using namespace std;

#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
/*---------------------------------------*/

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  // freopen("input.txt", "r", stdin);

  int n; cin >> n;
  vector<string> w(n);
  REP(i, n) cin >> w[i];

  REP(i, n) {
    FOR(j, i+1, n) {
      if (w[i] == w[j]) {
        cout << "No" << "\n";
        return 0;
      }
    }
  }
  REP(i, n-1) {
    if (w[i][w[i].length()-1] != w[i+1][0]) {
      cout << "No" << "\n";
      return 0;
    }
  }
  cout << "Yes" << "\n";
  return 0;
}


Measured memory_bytes: 256
import java.util.*;
public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    String a = sc.next();
    char a2 = a.charAt(0);
    if (Character.isUpperCase(a2)) {
      System.out.println("A");
    } else {
      System.out.println("a");
    }
  }
}


Measured memory_bytes: 35580
import sys
#入力
N, M = map(int, input().split())

lst = list(map(int, input().split()))

lst.sort()
#print (lst)

sa = []

for i in range(M-1):
    sa += [abs(lst[i] - lst[i+1])]

sa.sort(reverse = True)
#print(sa)

ans = -(lst[0] - lst[M-1])
#print (ans)
if not sa ==[]:
    if N <= M:
        for j in range(N-1):
            ans -= sa[j]
    else:
        ans = 0
print (ans)

Measured memory_bytes: 13968
(n,m,),*a=$<.map{|z|z.split.map &:to_i}
r=[-1]*-~n
c=r.dup
f=->x{r[x]>0?f[r[x]]:x}
a.map{|u,v|x,y=[f[u],f[v]].sort
(m-=1)>=0&&x!=y&&[r[x]+=r[y],r[y]=y=x]
x==y&&[c[u]-=1,c[v]-=1]}
(1..n).map{|i|p c[i]-r[f[i]]}

Measured memory_bytes: 55520
def kai(a):
    return a==a[::-1]
s=input()
x=0
if kai(s)==False:
    for i in range(len(s)//2):
        if s[i]!=s[-1-i]:
            x+=1
            for j in range(25):
                s[i]==chr(97+j)
print(x)

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <limits.h>
#include <algorithm>
#include <string>
#include <math.h>
#include <limits.h>
#include <queue>
#include <map>
#include <set>
#include <iomanip>
#include <bitset>
#include <cassert>
#include <random>
#include <functional>
#include <stack>
#include <iomanip>
#include <cassert>
//#include <boost/multiprecision/cpp_int.hpp>
#include <complex>
#include <cstdio>
#include <list>
#include <bitset>

//< in.txt > out.txt
using namespace std;
//std::ios::sync_with_stdio(false);
//std::cin.tie(0);
const long long MOD = 1e9 + 7;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<ld, ll> pdl;
typedef pair<ld, ld> pdd;
typedef vector<ll> VLL;
typedef vector<VLL> VVLL;
//typedef boost::multiprecision::cpp_int bigint;

ll N, Q;
string S;
struct query {
	string s;
	ll d;
};
vector<query> querys;

bool judgel(ll X) {
	for (query q: querys) {
		if (S[X] != q.s[0])continue;
		X += q.d;
	}
	return (X == 0);
}

bool judger(ll X) {
	for (query q : querys) {
		if (S[X] != q.s[0])continue;
		X += q.d;
	}
	return (X == N+1);
}

int main() {
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);
	cin >> N >> Q;
	cin >> S;
	S = string(" ") + S + string(" ");
	querys.resize(Q);
	for (ll n = 0; n < Q; n++) {
		cin >> querys[n].s;
		string d;
		cin >> d;
		if (d[0] == 'L')querys[n].d = -1;
		else querys[n].d = 1;
	}
	ll ls = 0, le = N+1;
	//ls以左の駒は<1に出て死ぬ le以右は死なない
	while (le - ls > 1) {
		ll m = (le + ls) / 2;
		if (judgel(m))ls = m;
		else le = m;
	}
	ll re = N + 1, rs = 0;
	//re以右の駒は>Nに出て死ぬ rs以左は死なない
	while (re - rs > 1) {
		ll m = (re + rs) / 2;
		if (judger(m))re = m;
		else rs = m;
	}
	cout << rs - le + 1 << "\n";
	return 0;
}

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

int main() {
	int a, b;
	cin >> a >> b;
	if (a == 1)a += 13;
	if (b == 1)b += 13;

	if (a > b)cout << "Alice" << endl;
	else if (a < b)cout << "Bob" << endl;
	else cout << "Draw" << endl;
	return 0;
}


Measured memory_bytes: 256