akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <map>
#include <string>
#define int long long
#define r(i,n) for(int i=0;i<n;i++)
using namespace std;

signed main(){
    int q;
    multimap<string,int>m;
    cin>>q;
    while(q--){
        int t,y;
        string x;
        cin>>t;
        if(t==0){
            cin>>x>>y;
            m.insert(make_pair(x,y));
        }
        if(t==1){
            string l;
            cin>>l;
            map<string,int>::iterator end,it;
            it=m.lower_bound(l);
            end=m.upper_bound(l);
            for(;it!=end;it++){
                cout<<(*it).second<<endl;
            }
        }
        if(t==2){
            cin>>x;
            m.erase(x);
        }
        if(t==3){
            string l,r;
            cin>>l>>r;
            map<string,int>::iterator end,it;
            it=m.lower_bound(l);
            end=m.upper_bound(r);
            for(;it!=end;it++){
                cout<<(*it).first<<' '<<(*it).second<<endl;
            }
        }
    }
}



Measured memory_bytes: 24912
using System;
using System.Collections.Generic;
using System.Linq;
class Program
{
    static void Main(string[] args)
    {
        var N = int.Parse(Console.ReadLine());
        var array = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
        var nums = new List<Number>();
        for (int i = 0; i < N; i++)
        {
            nums.Add(new Number(i, array[i]));
        }
        var sorted = nums.OrderByDescending(x => x.Value).ToArray();
        for (int i = 0; i < N; i++)
        {
            var isFormer = array[i] > sorted[(N + 1) / 2].Value;
            if (isFormer)
            {
                Console.WriteLine(sorted[(N + 1) / 2].Value);
            }
            else
                Console.WriteLine(sorted[(N + 1) / 2-1].Value);
            
        }
    }
}
public struct Number
{
    public Number(int index, int value)
    {
        Index = index;
        Value = value;
    }
    public int Index, Value;
}

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

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
using ll = long long;
string char_to_string(char val) {
  return string(1, val);
}
int char_to_int(char val) {
  return val - '0';
}
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;
}
int vector_finder(std::vector<ll> vec, int number) {
  auto itr = std::find(vec.begin(), vec.end(), number);
  size_t index = std::distance( vec.begin(), itr );
  if (index != vec.size()) { // 発見できたとき
    return 1;
  }
  else { // 発見できなかったとき
    return 0;
  }
}
struct edge {
  ll to, cost;
};

int main() {
  ll N, M; cin >> N >> M;
  vector<pair<int, int>> ans(N + 1); // 提出数と0, 1の正解か不正解か
  REP(i, M) {
    int p; string S; cin >> p >> S;
    if(S == "WA" && ans[p].second == 0) ans[p].first++;
    else if(S == "AC") ans[p].second = 1;
  }
  ll res = 0; ll pena = 0;
  REP(i, N + 1) {
    if(ans[i].second == 1) {
      res++;
      pena += ans[i].first;
    }
  }
  cout << res << " " << pena << endl;
}

Measured memory_bytes: 3996
n = int(input())
a = [int(input())-1 for i in range(n)]
#ボタンを押す=listから値を取得して-1にする
#取得した値=光っているボタンの番号
#光っているボタンの番号が1ならbreak
#取得した値が-1なら2を通らずループしてしまっている
sb = 0
ans = 0
while True:
    if sb == 1:
        flag = True
        break
    elif sb == -1:
        flag = False
        break
    tmp = a[sb]
    a[sb] = -1
    sb = tmp
    ans += 1
if flag:
    print(ans)
else:
    print(-1)
    

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

int main() {
    int n;
    cin >> n;
    for (int i=1; i<10; ++i) {
        if (n % i == 0) {
            if (n / i > 0 && n / i < 10){ cout << "Yes";
                return 0;
            }
        }
    }
    cout << "No";
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
typedef long long ll;
ll dat[100], n,dp[100][100];
ll rec(int now,int sum){
  if(sum > 20 || sum < 0) return 0;
  if(now == n - 1) return sum == dat[n - 1];
  if(dp[now][sum]) return dp[now][sum];
  return dp[now][sum] = rec(now + 1,sum + dat[now]) + rec(now + 1,sum - dat[now]);
}
int main(){
  cin >> n;
  for(int i = 0 ; i < n ; i++ ) cin >> dat[i];
  cout << rec(1,dat[0]) << endl;
}

Measured memory_bytes: 1236
#include <bits/stdc++.h>
using namespace std;
 
#define rep(i,x,y) for(int i=(x);i<(y);++i)
#define debug(x) #x << "=" << (x)
 
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define show(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define show(x)
#endif
 
typedef long long int ll;
typedef pair<int,int> pii;
template<typename T> using vec=std::vector<T>;
 
const int inf=1<<30;
const long long int infll=1LL<<62;
const double eps=1e-9;
const int dx[]={1,0,-1,0},dy[]={0,1,0,-1};
 
template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){
    os << "[";
    for (const auto &v : vec) {
        os << v << ",";
    }
    os << "]";
    return os;
}
 
template<class T> class segtree{
public:
    int n;
    vector<T> dat,sum; //????????????,??????????????§??????¶?????????????
    segtree(int size,T x){
        n=1;
        while(n<size) n*=2;
        dat.assign(2*n-1,x);
        sum.assign(2*n-1,x);
    }
    void add(int a,int b,T x){ add(a,b,x,0,0,n); }
    T add(int a,int b,T x,int k,int l,int r){
        if(b<=l or r<=a) return dat[k];
        if(a<=l and r<=b){
            sum[k]+=x;
            return dat[k]+=x*(r-l);
        }
        int m=(l+r)/2;
        return dat[k]=add(a,b,x,2*k+1,l,m)+add(a,b,x,2*k+2,m,r);
    }
    T query(int a,int b){ return query(a,b,0,0,n); }
    T query(int a,int b,int k,int l,int r){
        if(b<=l or r<=a) return 0;
        if(a<=l and r<=b) return dat[k];
        int m=(l+r)/2;
        return query(a,b,2*k+1,l,m)+query(a,b,2*k+2,m,r)+sum[k]*(min(r,b)-max(l,a));
    }
};
 
void solve(){
    int n,q;
    cin >> n >> q;
    segtree<ll> seg(n,0);
    rep(i,0,q){
        int com,x,y;
        cin >> com >> x >> y;
        if(com==0) seg.add(x-1,x,y);
        if(com==1) cout << seg.query(x-1,y) << endl;
    }
}
 
int main(){
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(10);
    solve();
    return 0;
}

Measured memory_bytes: 7056
//B - Palindromic Numbers: 
//Assunto: 
#include <bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define loop(i, a, b) for(int i = a; i < b; i++)
#define loopBack(i, a, b) for(int i = a; i >= b; i--)
#define INF INT_MAX
#define LINF LLONG_MAX
#define DINF DBL_MAX
#define MAX 100005
#define MOD 1000000007
using namespace std;
typedef long long int ll;
typedef pair<int, int> ii;

bool palindromo(int x) {
    string s = to_string(x);
    int i = 0, j = s.size()-1;
    loop(k, 0, s.size()) {
        if(s[i] != s[j]) return false;
        i++; j--;
    }
    return true;
}

int main() {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    //freopen("in.txt", "r", stdin);
    //freopen("out.txt", "w", stdout);
    int a, b, ans = 0;
    cin >> a >> b;
    loop(i, a, b+1) {
        if(palindromo(i)) ans++;
    }
    cout << ans << "\n";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const ll N=5e5,M=4003,P=1000000007;

#define C getchar()-48
ll read()
{
  ll s=0,t=1,k=C;
  for (;k<0||9<k;k=C) if (k==-3) t=-1;
  for (;0<=k&&k<=9;k=C) s=(s<<1)+(s<<3)+k;
  return s*t;
}

#define f(x,y) f[x+2001][y+2001]
  ll n;
  ll a[N],b[N];
  ll f[M][M];
void in()
{
  cin>>n;
  for (ll i=0;++i<=n;)
    a[i]=read(),b[i]=read(),
		++f(-a[i],-b[i]);
}

  ll F[M+M],G[M+M],c[M+M];
void pre()
{
  c[1]=1;
  F[0]=F[1]=1;
  G[0]=G[1]=1;
  for (ll i=1;++i<M+M;)
    c[i]=(P-P/i)*c[P%i]%P,
    F[i]=F[i-1]*i%P,
    G[i]=G[i-1]*c[i]%P;
}

ll com(ll x,ll y)
{
  return F[x+y]*G[x]%P*G[y]%P;
}

  ll A;
void wor()
{
  for (ll i=-2001;++i<2001;)
    for (ll j=-2001;++j<2001;)
      {
        f(i,j)+=f(i,j-1)+f(i-1,j);
        while (f(i,j)>=P) f(i,j)-=P; 
      }
  for (ll i=0;++i<=n;)
    A+=f(a[i],b[i])-com(a[i]*2,b[i]*2);
  A=(A%P+P)%P;
}

void out()
{
  cout<<A*c[2]%P;
}

int main()
{
  in();
  pre();
  wor();
  out();
  exit(0);
}

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

using namespace std;

using ll = long long;

int main () {
    ll n, m;
    cin >> n >> m;

    vector<ll> a(n);
    vector<ll> s(n + 1);

    for (int i = 0; i < n; i++) cin >> a[i];
    sort(a.begin(), a.end());

    for (int i = 0; i < n; i++) s[i + 1] = s[i] + a[i];

    ll ng = 0, ok = 1e+18;
    while (ok - ng > 1) {
        ll mid = (ng + ok) / 2;
        ll sum = 0;
        for (int i = 0; i < n; i++) {
            ll d = mid - a[i]; 
            sum += a.end() - lower_bound(a.begin(), a.end(), d);
        }
        if (sum < m) ok = mid;
        else ng = mid;
    }

    ll ans = 0;
    for (int i = 0; i < n; i++) {
        ll t = upper_bound(a.begin(), a.end(), ng - a[i]) - a.begin();
        ll cnt = n - t;
        ans += s[n] - s[t] + a[i] * cnt;
        m -= cnt;
    }
    ans += m * ng;

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

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

int main()
{
	long long a,b,ans=0;cin>>a>>b;
	if(a>b){
		ans+=a;
		a--;
	}
	else{
		ans+=b;
		b--;
	}
	if(a>b){
		ans+=a;
	}
	else ans+=b; 
	cout<<ans<<endl;
}


Measured memory_bytes: 256
l,r = map(int,input().split())
 
x = []
 
if r-l >4038:
    print(0)
else:
    for i in range(l,r+1):
        x.append(i%2019)
        
    x.sort()
    
    ans = x[0]*x[1]%2019
    
    x = list(set(x))
    
    for s in range(len(x)):
        for t in range(s+1,len(x)):
            ans = min(ans,x[s]*x[t]%2019)
        
    print(ans)

Measured memory_bytes: 9000
// ???????????£???????????????
#include <iostream>
#include <cstdio>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>

#define rep(i,n) for(int i=0; i<(n); i++)
#define rrep(i,n) for(int i=(n)-1; i>=0; i--)
#define all(X) (X).begin(),(X).end()

using namespace std;
typedef long long int ll;
typedef pair<int,int> P;

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

template<class A, size_t N, class T> void Fill(A (&a)[N], const T &v){ fill( (T*)a, (T*)(a+N), v ); }

const int INF = 0xfffffff;

struct ST{
	ll d;
	int z, b, n;
	// priority_queue??¨  const???????????????
	bool operator< (const ST& a) const {
		return (d > a.d);
	}
};

int N, M, R;
int v[2][205][205];
int Z[1005];
int dp[1005][205];		// z, boat
int ans[205];  // boat

int solve(){
	priority_queue<ST> que;
	ll d, z, b, n;

	Fill( dp, INF );
	dp[ 0 ][ Z[0] ] = 0;
	Fill( ans, INF );
	ans[ Z[0] ] = 0;
	rep(z,R-1){
		rep(b,N){
			chmin( dp[z+1][b], dp[z][b] + v[0][ Z[z] ][ Z[z+1] ] );
			rep(nb, N){
				chmin( dp[z+1][nb], dp[z][b] + v[0][ Z[z] ][b] + v[1][b][nb] + v[0][nb][ Z[z+1] ] );
			}
		}
		//rep(b,N) cout << "dp[" << z+1 << "][" << b << "] = " << dp[z+1][b] << endl;
		continue;
		rep(b,N) if( ans[b] < INF ){
			que.push( ST{ans[b], z, b, Z[z]} );
		}
		Fill( dp, INF );
		Fill( ans, INF );
		while( !que.empty() ){
			ST st = que.top();
			que.pop();
			d = st.d;
			//z = st.z;
			b = st.b;
			n = st.n;
			if( dp[b][n] < d ) continue;
			dp[b][n] = d;
//			cout << "hit " << d << " " << z << " " << b << " " << n << endl;
			rep(k, 2) if( !k || b == n ){
			//	for(auto _v: v[k][n]){
			//		int to = _v.first;
			//		ll cost = dp[b][n] + _v.second;
			//		int nz = z, nb = b;
			//		if( k ) nb = to;
			//		//if( to == Z[z+1] ) nz++;
			//		if( to == Z[z+1] ){
			//			chmin( ans[nb], cost );
			//		}else if( chmin(dp[nb][to], cost) ){
			//			que.push( ST{ cost, nz, nb, to } );
			//		}
			//	}
			}
		}
	}
	int ret = INF;
	rep(b,N){
		//chmin( ret, ans[b] );
		chmin( ret, dp[R-1][b] );
	}
	return ret;
}

int main(){
	int x, y, t;
	char sl;

	while(cin >> N >> M, N|M){
		Fill(v, INF);
		rep(i,M){
			cin >> x >> y >> t >> sl;
			x--; y--;
			if( sl == 'L' ){
				v[0][x][y] = t;
				v[0][y][x] = t;
			}else{
				v[1][x][y] = t;
				v[1][y][x] = t;
			}
		}
		cin >> R;
		rep(i,R){
			cin >> Z[i];
			Z[i]--;
		}

		rep(l,2) rep(i,N) v[l][i][i] = 0;
		rep(l,2) rep(k,N) rep(i,N) rep(j,N) {
			chmin( v[l][i][j], v[l][i][k] + v[l][k][j] );
		}
		
		cout << solve() << endl;
	}

	return 0;
}

Measured memory_bytes: 4236
#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 REPR(i, m, n) for (int i = (int)(m); i >= (int)(n); i--)
#define all(v) v.begin(), v.end()
typedef long long ll;

#define MAX 100000

int a[MAX+1];

int parent(int i){return i/2;};
int left(int i){return i*2;};
int right(int i){return i*2+1;};

int main(){
  int h; cin >> h;
  REP(i, 1, h) cin >> a[i];

  REP(i, 1, h){
    printf("node %d: ", i);
    printf("key = %d, ", a[i]);
    if(i != 1) printf("parent key = %d, ", a[parent(i)]);
    if(left(i) <= h) printf("left key = %d, ", a[left(i)]);
    if(right(i) <= h) printf("right key = %d, ", a[right(i)]);
    printf("\n");
  }

  return 0;
}





Measured memory_bytes: 3220
#include<cstdio>
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cassert>

using namespace std;

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

typedef pair<int,int> pii;

const int N = 222;
const int R = 1111;
const int INF = 500000000;
int n,m;

vector<pii> sea[N];
vector<pii> land[N];
vector<int> move;

int wsea[N][N];
int wland[N][N];

void init(){
	rep(i,N)sea[i].clear();
	rep(i,N)land[i].clear();
	move.clear();
	
	rep(i,N)rep(j,N)wsea[i][j]=wland[i][j]=INF;
}

bool input(){
	cin>>n>>m;
	if(n==0)return false;
	rep(i,m){
		int a,b,c;
		string d;
		cin>>a>>b>>c>>d;
		if(d=="L"){
			land[a].push_back(pii(b,c));
			land[b].push_back(pii(a,c));
		}
		if(d=="S"){
			sea[a].push_back(pii(b,c));
			sea[b].push_back(pii(a,c));
		}
	}
	int r;
	cin>>r;
	rep(i,r){
		int a;
		cin>>a;
		move.push_back(a);
	}
	
	return true;
}

void solve_wf_edge(int memo[N][N], vector<pii> edge[N]){
	rep(i,N)rep(j,N)memo[i][j]=INF;
	reps(i,1,n+1)memo[i][i]=0;
	rep(i,n+1){
		rep(j,edge[i].size()){
			pii e = edge[i][j];
			memo[i][e.first] = e.second;
			memo[e.first][i] = e.second;
		}
	}
	
	reps(k,1,n+1){
		reps(i,1,n+1){
			reps(j,1,n+1){
				memo[i][j] = min(memo[i][j], memo[i][k]+memo[k][j]);
			}
		}
	}
}

void solve_wf(){
	solve_wf_edge(wsea, sea);
	solve_wf_edge(wland, land);
}

int solve_dp(){
	int dp[R][N];
	rep(i,R)rep(j,N)dp[i][j]=INF;
	
	dp[0][move[0]]=0;
	
	reps(i,1,move.size()){
		int prev = move[i-1];
		int now = move[i];
		reps(j,1,n+1){
			dp[i][j]=min(INF,dp[i-1][j]+wland[prev][now]);
			reps(k,1,n+1){
				dp[i][j] = min(dp[i][j], dp[i-1][k]+wland[prev][k]+wsea[k][j]+wland[j][now]);
			}
		}
	}
	
	int ret = INF;
	reps(i,1,n+1)ret = min(ret, dp[move.size()-1][i]);
	if(ret>=INF)return -1;
	return ret;
}

int solve(){
	solve_wf();
	return solve_dp();
}

int main(){
	while(init(),input()){
		printf("%d\n",solve());
	}
}

/*
3 3
1 2 5 L
1 2 7 S
2 3 11 S
3
1 2 3
0 0


*/

Measured memory_bytes: 2704
#include<iostream>
#include<string>
#include<numeric>
#include<set>
#include<algorithm>
#include<map>
#include<vector>
using namespace std;
typedef long long li;
#define minimize(a,b) (a>(b)?a=(b),1:0)
#define maximize(a,b) (a<(b)?a=(b),1:0)
#define ceil(a,b) (((a)+(b)-1)/(b))
#define yn(i) print((i)?"Yes":"No")
#define chmin(a,b) (a>(b)?a=(b),1:0)
#define abs(n) max((n),-(n))
#define dist(a,b) max((a)-(b),(b)-(a))
#define chmax(a,b) (a<(b)?a=(b),1:0)
#define repa(i,a,n) for(int i=(a);i<(n);i++)
#define MOD 1000000000
#define rep(i,n) for(int i=0;i<(n);i++)

#define df 0
template<class T> void print(const T& t){ cout << t << "\n"; }
template<class T, class... Ts> void print(const T& t, const Ts&... ts) { cout << t; if (sizeof...(ts)) cout << " "; print(ts...); }

// Container コンテナ型, map以外
template< template<class ...> class Ctn,class T>
std::ostream& operator<<(std::ostream& os,const Ctn<T>& v){
  auto itr=v.begin();
  while(itr!=v.end()){
    if(itr!=v.begin())cout << " ";
    cout << *(itr++);
  }
  return os;
}




string key="keyence";

void add(char m,string s,set<string> st){
  int n=s.size();
  rep(i,n){
    if(s[i]!=m) continue;
    string t;
    repa(j,i,n){
      t.push_back(s[j]);
      st.insert(t);
    }
  }
}

int gcd(int a,int b){
  return b?gcd(b,a%b):a;
}

int main(){
  string s; cin >>s;
  int ans=0,n=s.size();
  rep(i,n) (ans+=s[i]-'0')%=9;
  yn(!ans);
}





Measured memory_bytes: 3756
//#include <bits/stdc++.h>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <map>
#include <stack>
#include <bitset>
#include <array>
#include <set>
#include <string>

#include <iterator>
#include <algorithm>
#include <numeric>

#include <ios>
#include <sstream>
#include <iostream>
#include <fstream>

#include <climits>
#include <cmath>

using namespace std;

#define EPS (1e-7)
#define MOD ((int)1e9+7)
#define PI (atan(1.0)*4)

using ll=long long;
using vi=vector<int>;
using vll=vector<ll>;
using vvi=vector<vi>;
using vs=vector<string>;
using pii=pair<int,int>;
using pll=pair<ll,ll>;

void OUT(bool isTrue, string t="YES", string f="NO"){
    cout<<(isTrue?t:f)<<endl;
}
void Out(bool isTrue, string t="Yes", string f="No"){
    cout<<(isTrue?t:f)<<endl;
}
void out(bool isTrue, string t="yes", string f="no"){
    cout<<(isTrue?t:f)<<endl;
}
void bulk(){}
template <class Head, class... Tail>
void bulk(Head& head, Tail&... tail){
    cin>>head;
    bulk(tail...);
}
template <typename T>
string printItr(T b, T e, string delim=" ")
{
    stringstream ss;
    ostream_iterator<decltype(*b)> out_it(ss, delim.c_str());
    copy(b,e - 1, out_it);
    ss<<*(e-1);
    return ss.str();
}

#define rep(i,n) for(int i=0;i<n;i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define range(i,m,n) for(int i=m; i<n;i++)
#define each(i,n) for(auto i:n)
#define all(i) i.begin(),i.end()
#define cint(...) int __VA_ARGS__;bulk(__VA_ARGS__);


int main(void){
    cint(n);
    vi a(n),b(n),c(n);
    each(&i,a)cin>>i;
    each(&i,b)cin>>i;
    each(&i,c)cin>>i;
    sort(all(a));
    sort(all(b));
    sort(all(c));
    ll ans=0;
    each(d,b){
        ans+=(ll)(lower_bound(all(a),d)-a.begin())*(c.end()-upper_bound(all(c),d));
    }
    cout<<ans;
}

Measured memory_bytes: 1408
import java.awt.*;
import java.io.PrintWriter;
import java.lang.reflect.Array;
import java.math.BigInteger;
import java.util.*;
import java.util.List;

public class Main {

    static String br = System.getProperty("line.separator");
    static Scanner sc = new Scanner(System.in);
    static PrintWriter out = new PrintWriter(System.out);

    public static void main(String[] args) {
        long X = nextLong();
        long Y = nextLong();

        int count = 0;
        for(int i=1;;i++){
            count++;
            X = X*2;
            if(X > Y) break;
        }

        println(count);
    }

    static int nextInt() {
        return Integer.parseInt(next());
    }

    static Long nextLong() {
        return Long.parseLong(next());
    }

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

    static String nextLine(){
        return sc.nextLine();
    }

    static void println(Object o) {
        out.println(o);
        out.flush();
    }

    static void print(Object o) {
        PrintWriter out = new PrintWriter(System.out);
        out.print(o);
        out.flush();
    }
}


Measured memory_bytes: 21972
import itertools
import operator

def f():
    t, d, l = map(int, input().split())
    if t == d == l == 0:
        return True

    hist = [0] * (10**5*2 + 1)
    for i in range(t):
        x = int(input())
        if x >= l:
            hist[i + 1] += 1
            hist[i + d + 1] -= 1

    print(sum(map(bool, itertools.accumulate(hist[:t], operator.add))))

while not f(): pass



Measured memory_bytes: 8072
#include<iostream>
using namespace std;
#define rep(i, n) for ( int i = 0; i < n; i++)
static const int MAX = 10000;
static const int INFTY = (1<<24);

main(){
  int N, P[MAX], dp[2][MAX/2+1][2]; 
  cin >> N;
  rep(i, N-1) cin >> P[i];

  rep(i, 2) rep(j, N/2+1) dp[i][j][0] = dp[i][j][1] = INFTY;

  dp[1][1][1] = dp[1][0][0] = 0;

  for ( int i = 1; i < N; i++ ){
    for ( int j = 0; j <= N/2; j++ ){
      dp[(i+1)%2][j][0] = INFTY;
      dp[(i+1)%2][j+1][1] = INFTY;
      // + 0
      dp[(i+1)%2][j][0] = min(dp[(i+1)%2][j][0], min(dp[i%2][j][0], dp[i%2][j][1] + P[i-1]));
      // + 1
      if ( j+1 > N/2 ) continue;
      dp[(i+1)%2][j+1][1] = min(dp[(i+1)%2][j+1][1], min(dp[i%2][j][0] + P[i-1], dp[i%2][j][1]));
    }
  }

  cout << min(dp[0][N/2][0], dp[0][N/2][1]) << endl;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
typedef long long int ll;
#define FOR(i, a, b) for (ll i = (signed)(a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define EREP(i, n) for (int i = (n)-1; i >= 0; --i)
#define MOD 1000000007
#define pb push_back
#define INF 93193111451418101
#define MIN -93193111451418101
#define EPS 1e-11
#define tp(a, b, c) make_tuple(a, b, c)
#define lb(a, b) lower_bound((a).begin(), (a).end(), (b))
#define ub(a, b) upper_bound((a).begin(), (a).end(), (b))
#define bitcnt(a) (ll) __builtin_popcount((a))
using namespace std;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> T;
template <typename T> void fill_all(T &arr, const T &v) { arr = v; }
template <typename T, typename ARR> void fill_all(ARR &arr, const T &v) {
  for (auto &i : arr) {
    fill_all(i, v);
  }
}
//------------------変数-----------------------//
//-------------------関数----------------------//
ll par[300000], depth[300000];
ll cnt[214514];
void init(ll n) {
  REP(i, n) {
    par[i] = i;
    depth[i] = 0;
  }
  return;
}

ll find(ll x) {
  if (par[x] == x) {
    return x;
  } else {
    return par[x] = find(par[x]);
  }
}

void merge(ll x, ll y) {
  x = find(x);
  y = find(y);
  if (x == y) {
    return;
  }
  if (depth[x] > depth[y]) {
    par[y] = x;
  } else {
    par[x] = y;
    if (depth[x] == depth[y]) {
      depth[y]++;
    }
  }
}

bool same(ll x, ll y) {
  if (find(x) != find(y)) {
    return false;
  }
  return true;
}
//親を知りたいときは必ずfind()を使う！
ll par2[300000], depth2[300000];
void init2(ll n) {
  REP(i, n) {
    par2[i] = i;
    depth2[i] = 0;
  }
  return;
}

ll find2(ll x) {
  if (par2[x] == x) {
    return x;
  } else {
    return par2[x] = find2(par2[x]);
  }
}

void merge2(ll x, ll y) {
  x = find2(x);
  y = find2(y);
  if (x == y) {
    return;
  }
  if (depth2[x] > depth2[y]) {
    par2[y] = x;
  } else {
    par2[x] = y;
    if (depth2[x] == depth2[y]) {
      depth2[y]++;
    }
  }
}

bool same2(ll x, ll y) {
  if (find2(x) != find2(y)) {
    return false;
  }
  return true;
}
bool vis[314514];
bool one[314514];

void check(vector<ll> v) {
  ll center = v[0], c = 0;
  vector<ll> vv;
  REP(i, v.size()) {
    if (same2(center, v[i])) {
      vv.pb(v[i]);
      c++;
    } else {
      cnt[v[i]] = 1;
    }
  }
  REP(i, vv.size()) { cnt[vv[i]] = c; }
  return;
}
int main() {
  ll n, k, l;
  cin >> n >> k >> l;
  init(n);
  init2(n);
  REP(i, k) {
    ll p, q;
    cin >> p >> q;
    p--;
    q--;
    merge(p, q);
  }
  REP(i, l) {
    ll p, q;
    cin >> p >> q;
    p--;
    q--;
    merge2(p, q);
  }
  REP(i, n) {
    find(i);
    find2(i);
  }

  map<P, ll> mp;
  REP(i, n) { mp[P(par[i], par2[i])]++; }
  REP(i, n) {
    if (i)
      cout << " ";
    cout << mp[P(par[i], par2[i])];
  }
  cout << endl;
}


Measured memory_bytes: 22272
#include<bits/stdc++.h>
using namespace std;
int main()
{
  char a[3],aa[3];
  cin>>a>>aa;
  int cnt=0;
  for(int i=0;i<3;i++)
  {
    if(a[i]==aa[i])
    {
      cnt++;
    }
  }
  cout<<cnt<<endl;
}

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

int main() {
	long long n,a,b,c,d,e,k=0;
	cin >> n >> a >> b >> c >> d >> e;
	long long a1=0,b1=0,c1=0,d1=0,e1=0;
	if(n%a!=0)
	{
		a1=1;
	}
	if(n%b!=0)
	{
		b1=1;
	}
	if(n%c!=0)
	{
		c1=1;
	}
	if(n%d!=0)
	{
		d1=1;
	}
	if(n%e!=0)
	{
		e1=1;
	}
	k=(n/a)+a1;
	if(b>=a)
	{
		k++;
		if(c>=a)
		{
			k++;
			if(d>=a)
			{
				k++;
				if(e>=a)
				{
					k++;
				}
				else
				{
					k=(n/e)+4+e1;
				}
			}
			else
			{
				k=(n/d)+3+d1;
				if(e>=d)
				{
					k++;
				}
				else
				{
					k=(n/e)+4+e1;
				}
			}
		}
		else
		{
			k=(n/c)+2+c1;
			if(d>=c)
			{
				k++;
				if(e>=c)
				{
					k++;
				}
				else
				{
					k=(n/e)+4+e1;
				}
			}
			else
			{
				k=(n/d)+3+d1;
				if(e>=d)
				{
					k++;
				}
				else
				{
					k=(n/e)+4+e1;
				}
			}
		}
	}
	else
	{
		k=(n/b)+1+b1;
		if(c>=b)
		{
			k++;
			if(d>=b)
			{
				k++;
				if(e>=b)
				{
					k++;
				}
				else
				{
					k=(n/e)+4+e1;
				}
			}
			else
			{
				k=(n/d)+3+d1;
				if(e>=d)
				{
					k++;
				}
				else
				{
					k=(n/e)+4+e1;
				}
			}
		}
		else
		{
			k=(n/c)+2+c1;
			if(d>=c)
			{
				k++;
				if(e>=c)
				{
					k++;
				}
				else
				{
					k=(n/e)+4+e1;
				}
			}
			else
			{
				k=(n/d)+3+d1;
				if(e>=d)
				{
					k++;
				}
				else
				{
					k=(n/e)+4+e1;
				}
			}
		}
	}
	cout << k << endl;
	return 0;
}


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

#define int long long
#define rep(i, n) for (int i = 0; i < (n); i++)
#define reps(i, n) for (int i = 1; i <= (n); i++)
#define all(x) begin(x), end(x)
#define uniq(x) (x).erase(unique(all(x)), end(x))
#define bit(n) (1LL << (n))
#define cdiv(a, b) (((a) - 1) / (b) + 1)
#define dump(x) cerr << #x " = " << (x) << endl
using vint = vector<int>;
using vvint = vector<vint>;
using pint = pair<int, int>;
using vpint = vector<pint>;
template<typename T> using priority_queue_rev = priority_queue<T, vector<T>, greater<T>>;
constexpr long double PI = 3.1415926535897932384626433832795028L;
constexpr int DY[8] = {0, 1, 0, -1, 1, 1, -1, -1};
constexpr int DX[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int gcd(int a, int b) {
    while (b) { swap(a %= b, b); }
    return a;
}
int lcm(int a, int b) { return a / gcd(a, b) * b; }
template<typename T> void fin(T mes) {
    cout << mes << endl;
    exit(0);
}
template<typename T, typename U> bool chmax(T &a, const U &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template<typename T, typename U> bool chmin(T &a, const U &b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}
template<typename T, typename U> ostream &operator<<(ostream &os, const pair<T, U> &rhs) {
    os << "(" << rhs.first << ", " << rhs.second << ")";
    return os;
}
template<typename T> ostream &operator<<(ostream &os, const vector<T> &rhs) {
    os << "{";
    for (auto itr = rhs.begin(); itr != rhs.end(); itr++) {
        os << *itr << (next(itr) != rhs.end() ? ", " : "");
    }
    os << "}";
    return os;
}
struct setup {
    static constexpr int PREC = 20;
    setup() {
        cout << fixed << setprecision(PREC);
        cerr << fixed << setprecision(PREC);
    };
} setup;

template<typename F> long long discrete_binary_search(long long ok, long long ng, F is_ok) {
    while (abs(ok - ng) > 1) {
        long long mid = (ok + ng) / 2;
        (is_ok(mid) ? ok : ng) = mid;
    }
    return ok;
}

int x;
signed main() {
    cin >> x;
    cout << discrete_binary_search(1e15, 0, [&](int n) {
        int y = n * 5 + cdiv(n, 2);
        return x <= y;
    }) << endl;
}

Measured memory_bytes: 384
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]
K = input()
K = int(K)
K -= 1
print(a[K])

Measured memory_bytes: 3060
#class#############################################
class orders():
    def __init__(self,str):
        self.str=str
        
    def printout(self,a,b):
        result=""
        array=[]
        array=list(self.str)

        for i in range(a,b+1):
            result=result+array[i]
        print(result)
    
    def reverse(self,a,b):
        result_r=""
        re_array=[]
        array_r=[]
        array_r=list(self.str)

        for i in range(0,a):
            result_r=result_r+array_r[i]
       
        for j in range(a,b+1):
           
            re_array.append(array_r[j])
          
        for jj in re_array[::-1]:
            result_r=result_r+jj
            
        for k in range(b+1,len(array_r)):
            result_r=result_r+array_r[k]

        self.str=result_r
     
    def replace_out(self,a,b,p):
        result_p=""
        array_r=[]
        array_r=list(self.str)
        for i in range(0,a):
            result_p=result_p+array_r[i]
        
        result_p=result_p+p

        for k in range(b+1,len(array_r)):
            result_p=result_p+array_r[k]
        
        self.str=result_p
###########################################
if __name__=="__main__":
    
    input_text=input()

    number=input()
    num=int(number)
    i=1
    object1=orders(input_text)
    while i <=num:
        in_array=[]
        inp=""
        inp=input()
        in_array=inp.split()

        if in_array[0]=="replace":
            object1.replace_out(int(in_array[1]),int(in_array[2]),in_array[3])
           
        
        elif in_array[0]=="reverse":
            object1.reverse(int(in_array[1]),int(in_array[2]))

        elif in_array[0]=="print":
            object1.printout(int(in_array[1]),int(in_array[2]))

        i=i+1

    


Measured memory_bytes: 5636
//八皇后问题
#include <iostream>

using namespace std;

enum {
    NOT_FREE,FREE
};

const int n = 8;

int row[n];//row[i]=FREE表示第i行不会受到攻击
int col[n];//col[j]=FREE表示第j列不会受到攻击
int dpos[2*n-1];//同理，副对角线不会受到攻击
int dneg[2*n-1];//主对角线不会受到攻击

bool Graph[n][n];

void initialize() {
	for (int i=0; i<n; i++) {
		row[i] = col[i] = FREE;
	}

	for (int i=0; i<2*n-1; i++) {
		dpos[i] = dneg[i] = FREE;
	}

	for (int i=0; i<n; i++) {
		for (int j=0; j<n; j++) {
			Graph[i][j] = 0;
		}
	}
}

void printQ() {
	for (int i=0; i<n; i++) {
		for (int j=0; j<n; j++) {
			if (Graph[i][j] && row[i] != j) { //不符合题目要求的解
				return;
			}
		}
	}
	for (int i=0; i<n; i++) {
		for (int j=0; j<n; j++) {
			if (j == row[i]) {
				cout << "Q";
			} else {
				cout << ".";
			}
		}
		cout << endl;
	}
}

void solve(int r) {
	if (r == n) { //成功放置皇后
		printQ();
		return;
	}


	for (int j=0; j<n; j++) {
		if (col[j] == NOT_FREE || dpos[r+j] == NOT_FREE || dneg[r-j+n-1] == NOT_FREE) continue; //i-j相同的在主对角线上，为什么要加上n-1呢，是因为i-j可能为负数，为了避免分支，加上n-1就可以保证不越界
		//在i,j放置皇后
		row[r] = j;
		col[j] = dpos[r+j] = dneg[r-j+n-1] = NOT_FREE;
		solve(r+1); //求解下一行
		row[r] = col[j] = dpos[r+j] = dneg[r-j+n-1] = FREE;//回溯
	}


}

int main() {
	initialize();
	int k;
	cin >> k;
	while (k--) {
		int x,y;
		cin >> x >> y;
		Graph[x][y] = 1;
	}
	//从第0行开始搜索
	solve(0);
	return 0;
}


Measured memory_bytes: 3112
#include<bits/stdc++.h>
using namespace std;
#define ALL(obj) (obj).begin(),(obj).end()
#define RALL(obj) (obj).rbegin(),(obj).rend()
#define REP(i, n) for(int i=0;i<(n);++i)
#define RANGE(i, a, b) for(int i=(a);i<(b);++i)
#define RREP(i, n) for(int i=(n)-1;i>= 0;--i)

#define endl '\n'
#define pb push_back
#define eb emplace_back
#define pque priority_queue
#define umap unordered_map
#define uset unordered_set
#define BIG 2000000000
#define VERYBIG 1000000000000000ll
#define dcout cout<<fixed<<setprecision(20)
#define Accepted_MAGIC cin.tie(0);ios::sync_with_stdio(false)

// typedef long long ll;
using Real = long double;
#define int long long

const long long dx[]={1,0,-1,0,1,1,-1,-1}, dy[]={0,-1,0,1,1,-1,1,-1};
const long long MOD = 1e9+7;
constexpr Real eps = 1e-9, pi = acos(-1);

template<typename T> inline T GCD(T a,T b){T c;while(b!=0){c=a%b;a=b;b=c;}return a;}
template<typename T> inline T LCM(T a,T b){T c=GCD(a,b);a/=c;return a*b;}
template<typename T> inline T nCr(T a,T b){T i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;}
template<typename T> inline T nHr(T a,T b){return nCr(a+b-1,b);}
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}

typedef pair<int, int> INTP;
typedef vector<int> INTV;
struct edge2 {int to, cost;};
struct edge3 {int from, to, cost;};

vector<INTV> graph;
INTV dist;

void bfs(int st){
  queue<int> que;
  que.push(st);
  while(!que.empty()){
    int pos = que.front(); que.pop();
    for(auto nx : graph[pos]){
      if(dist[nx] == -1){
        dist[nx] = dist[pos] + 1;
        que.push(nx);
      }
    }
  }
}

signed main(void){
  Accepted_MAGIC;
  
  int N, X, Y; cin >> N >> X >> Y;
  X--; Y--;
  graph.resize(N);
  graph[X].eb(Y);
  graph[Y].eb(X);
  REP(i, N-1){
    graph[i].eb(i+1);
    graph[i+1].eb(i);
  }
  INTV ans(N, 0);
  REP(i, N){
    dist.assign(N, -1); dist[i] = 0;
    bfs(i);
    REP(j, N){
      ans[dist[j]]++;
    }
  }
  for(int i = 1; i < N; i++){
    cout << ans[i]/2 << endl;
  }
}

Measured memory_bytes: 384
N = int(input())
AB = [[int(_) for _ in input().split()] for i in range(N)]

AB = sorted(AB, key=lambda x:x[0] + x[1], reverse=True)

result = 0
result = sum(a for a, b in AB[0::2]) - sum(b for a, b in AB[1::2])

print(result)


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

using namespace std;

int main() {
    int n;
    cin>>n;
    long long  a[n];
    long long  v[200001]={0};
    
    for(int i=0;i<n;i++)
    {
    cin>>a[i];    
    v[a[i]]++;
    
    }
    

    long long  sum=0;
    for(int i=1;i<200001;i++)
    {
    sum+=(v[i]*(v[i]-1))/2;
    
    
    }




    for(int i=0;i<n;i++)
    {
        long long ans;
        ans=sum-v[a[i]]+1;
        cout<<ans<<endl;
    }
    
    
    
    
    
    
    
}

Measured memory_bytes: 6400
#include <bits/stdc++.h>
#define MOD 1000000007
typedef long long int ll;
using namespace std;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    ll t, ans = 0;
    cin >> t;
    map<string, ll> msl;
    string inp;
    while(t--){
        cin >> inp;
        sort(inp.begin(), inp.end());
        msl[inp] = msl[inp] + 1;
    }
    for(map<string, ll>::iterator itr = msl.begin(); itr != msl.end(); ++itr)
        if(itr->second != 1)
            ans += (itr->second - 1)*(itr->second)/2;
    cout << ans;
    return 0;
}

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

using namespace std;

typedef long long ll;

ll cnt[100010];

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N;
	ll K;
	cin >> N >> K;
	for (int i = 0; i < N; i++) {
		int a, b;
		cin >> a >> b;
		cnt[a] += b;
	}

	ll sum = 0;
	for (int i = 1; i <= 100000; i++) {
		if (sum < K && sum + cnt[i] >= K) {
			cout << i << endl;
			break;
		}
		sum += cnt[i];
	}
	return 0;
}

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

long gcd(long a,long b){
    int tmp;
    if(a<b){
        tmp = a;
        a = b;
        b = tmp;
    }

    tmp = a % b;

    while(tmp!=0){
        a = b;
        b = tmp;
        tmp = a % b;
    }
    return b;
}

int main(){
    long N;
    cin >> N;
    vector<long> A(N);
    for(int i=0;i<N;++i) cin >> A[i];
    vector<long> L(N,0);
    vector<long> R(N,0);
    L[0]=A[0];
    for(int i=0;i<N-2;++i){
        L[i+1] = gcd(A[i+1],L[i]);
    }
    R[N-1]=A[N-1];
    for(int i=N-2;i>=0;--i){
        R[i] = gcd(A[i],R[i+1]);
    }
    long ans = max(L[N-2],R[1]);
    for(int i=0;i<N-2;++i){
        ans = max(ans,gcd(L[i],R[i+2]));
    }

    cout << ans << endl;

}

Measured memory_bytes: 2560
h, w = map(int, input().split())
board = [list(input()) for _ in range(h)]
dx = [-1, 0, 1, -1, 1, -1, 0, 1]
dy = [-1, -1, -1, 0, 0, 1, 1, 1]
for i in range(h):
    for j in range(w):
        if board[i][j] is '.':
            board[i][j] = 0
            for k in range(8):
                ni = i + dy[k]
                nj = j + dx[k]
                if ni >= 0 and ni < h and nj >= 0 and nj < w:
                    board[i][j] += 1 if board[i + dy[k]][j + dx[k]] is '#' else 0
for s in board:
    print(''.join(map(str, s)))



Measured memory_bytes: 3064
#include <stdio.h>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <cctype>
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>

using namespace std;

/*#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;*/ //int order_of_key, it find_by_order

typedef long long ll;
typedef unsigned int ui;
typedef long double ld;
typedef pair<int, int> pii;

#define pb push_back
#define ft first
#define sd second
#define mpr make_pair
#define max3(a, b, c) max((a), max((b), (c)))
#define max4(a, b, c, d) max(max((a), (b)), max((c), (d)))
#define all(x) begin((x)), end((x))
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for(int (i) = 0; (i) < (n); ++(i))
#define isz(x) (int)(x).size()

/* <----------------------------------------------------------> */

int cnt[26];

void no()
{
    puts("No");
}

void solve()
{
    int n, m;
    cin >> n >> m;
    forn (i, n)
    {
        string s;
        cin >> s;
        for (char c : s) ++cnt[c - 'a'];
    }
    if ((n & 1) && (m & 1))
    {
        forn (i, 26) if (cnt[i] & 1)
        {
            --cnt[i];
            break;
        }
        forn (i, 26) if (cnt[i] & 1) return no();
        int x = n + m - 2;
        for (int i = 0; i < 26 && x; ++i) if (cnt[i] % 4 == 2)
        {
            x -= 2;
            cnt[i] -= 2;
        }
        forn (i, 26) if (cnt[i] % 4 == 2) return no();
        if (x % 4) return no();
        while (x)
        {
            int _x = x;
            forn (i, 26) if (cnt[i] >= 4)
            {
                cnt[i] -= 4;
                x -= 4;
            }
            if (_x == x) break;
        }
        if (x) return no();
        puts("Yes");
        return;
    }
    if ((n & 1) || (m & 1))
    {
        if (m & 1) swap(n, m);
        int x = m;
        forn (i, 26) if (cnt[i] & 1) return no();
        for (int i = 0; i < 26 && x; ++i) if (cnt[i] % 4 == 2)
        {
            x -= 2;
            cnt[i] -= 2;
        }
        if (x % 4) return no();
        while (x)
        {
            int _x = x;
            forn (i, 26) if (cnt[i] >= 4)
            {
                x -= 4;
                cnt[i] -= 4;
            }
            if (_x == x) break;
        }
        if (x) return no();
    }
    forn (i, 26) if (cnt[i] % 4) return no();
    puts("Yes");
}

/* <----------------------------------------------------------> */

// #define LOCAL
// #define FILE_NAME ""

int main()
{
    #if defined LOCAL
        freopen("input.txt", "r", stdin);
    #elif defined FILE_NAME
        freopen(FILE_NAME".in", "r", stdin);
        freopen(FILE_NAME".out", "w", stdout);
    #endif

    ios_base::sync_with_stdio(0);
    cin.tie(0);

    solve();

    return 0;
}


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

int main(){
int n;
   std::cin >> n;
   int a[n];
   for(int i=0;i<n;i++)
       std::cin >> a[i];
  std::sort(a,a+n,std::greater<int>());
  int al=0,b=0;
  for(int i=0;i<n;i++){
    if(i&1)
       b+=a[i];
    else
       al+=a[i];
  }
  std::cout << al-b << std::endl;
 return 0;
}

Measured memory_bytes: 3644
#include <iostream>

using namespace std;

int n, l, sz, i, j;
int a, b;
bool canUntie2[100001];
int order[100001];

int main()
{
    cin>> n >> l >> a;
    for(i = 2; i <= n; i++)
    {
        cin >> b;
        canUntie2[i - 1]=((a + b) >= l);
        a = b;
    }

    for(i = 1; i <= n - 1; i++)
    {
        if(canUntie2[i]==1)
        {
            int stop = n;
            for(j = i + 1; j <= n - 1; j++)
            {
                if(canUntie2[j]==1)
                {
                    stop = j;
                    break;
                }
            }
            if(stop != n)
            {
                for(j = i + 1; j <= stop - 1; j++)
                {
                    order[++sz] = j;
                }
            }
            else
            {
                for(j = n - 1; j >= i + 1; j--)
                    order[++sz] = j;
            }
            i = stop - 1;
        }
        else
        {
            bool ok = false;
            for(j = i; j <= n - 1; j++, i++)
            {
                if(canUntie2[j] == 1)
                {
                    ok = true;
                    break;
                }
                order[++sz] = j;
            }
            i--;
            if(!ok)
            {
                cout<< "Impossible ";
                return 0;
            }
        }
    }
    for(i = 1; i <= n - 1; i++)
    {
        if(canUntie2[i] == 1)
            order[++sz] = i;
    }
    if(sz == n - 1)
    {
        cout << "Possible" << '\n';
        for(i = 1; i <= n - 1; i++)
        {
            cout << order[i] << '\n';
        }
    }
    return 0;
}


Measured memory_bytes: 1280
import collections
import sys

s=input()
S=collections.Counter(x for x in s)

a=S['a']
b=S['b']
c=S['c']

L=set([x for x in s])

if len(s)==1:
  print('YES')
  sys.exit()
elif len(s)==2:
  if len(L)==2:
    print('YES')
  else:
    print('NO')
  sys.exit()
elif len(s)==3:
  if len(L)==3:
    print('YES')
  else:
    print('NO')
  sys.exit()

if a==b and b==c:
  print('YES')
elif a==b:
  if min(b,c)+1==max(b,c):
    print('YES')
  else:
    print('NO')
else:
  if min(a,b)+1==max(a,b):
    if a==c or b==c:
      print('YES')
    else:
      print('NO')
  else:
    print('NO')

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

int main(){
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  string a,b;
  cin>>a>>b;
  int d=a.length();
  int e=b.length();
  if(d>e){
    cout<<"GREATER";
    return 0;
  }else if(d<e){
    cout<<"LESS";
    return 0;
  }else{
    for(int i=0;i<a.length();i++){
      if(a[i]<b[i]){
        cout<<"LESS";
        return 0;
      }
      if(a[i]>b[i]){
        cout<<"GREATER";
        return 0;
      }
    }
    cout<<"EQUAL";
    return 0;
  }


}

Measured memory_bytes: 256
import math

K = int(input())

sum_ans = 0
gcd_list = []
for i in range(1, K+1):
    for j in range(1, K+1):
        tmp = math.gcd(i, j)
        gcd_list.append(tmp)

for k in range(1, K+1):
    for g in gcd_list:
            tmp = math.gcd(k, g)
            sum_ans += tmp

print(sum_ans)

Measured memory_bytes: 9432
/*
 KUNAL RAUT (ZUKONIT14)  :- "DO WHAT YOU LIKE!"
 -PICT,PUNE! :)
 */
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define int long long
#define ld long double
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define mod 1000000007
#define mod9 1000000009
#define pi 3.1415926535
#define MAXN 1000001
#define N 1000001
#define MAX2N 1*1000 + 10
#define all(v) v.begin(), v.end()
#define ms(s, n) memset(s, n, sizeof(s))
#define prec(n) fixed<<setprecision(n)
#define forci(p,n) for(ll i=p;i<(ll)n;i++)
#define forcj(p,n) for(ll j=p;j<(ll)n;j++)
#define bolt ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define bits(a) __builtin_popcount(a)
#define test ll t;cin>>t;for(ll testi=1;testi<=t;testi++)
ll zero=0;
ll one=1;
ll gcd(ll a,ll b){    if(b==0) return a;    return gcd(b,a%b);}
ll lcm(ll a,ll b) {    return (a/gcd(a,b)*b);}
ll expo(ll x, ll y) {ll res=1;x=x%mod;while(y>0){if(y&1)res=(1ll*res*x)%mod;
    y=y>>1;x=(1ll*x*x)%mod;} return res;}
ll ncr(ll n,ll r){ ll res=1; if(r>n-r)r=n-r; for(ll i=0;i<r;i++) {  res*=n-i;  res/=i+1; } return res;}
ll max(ll a,ll b){return (a>b)?a:b;}
bool prime(ll n){ll i;for(i=2;i<=sqrt(n);i++){if(n%i==0)return false;}return true;}
bool sortbysec(const pair<ll,ll> &a,const pair<ll,ll> &b)
{   if(a.second == b.second)
    return a.first < b.first;
    return (a.second < b.second);}
//https://www.youtube.com/watch?v=WTJSt4wP2ME

ll rr[]={0,1,1,1,0,-1,-1,-1,};
ll cc[]={1,1,0,-1,-1,-1,0,1};
#define MOD 998244353

signed main()
{
    bolt;
    ll A, B, K;
    cin >> A >> B >> K;
    ll t = min(A, K);
    A -= t;
    if (A == 0) {
        K -= t;
        B -= min(B, K);
    }
    cout << A << ' ' << B << endl;
}



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

bool isPrime(int n){
  auto rt = sqrt(n);
  int prpr[100005];
  memset(prpr, 0, sizeof(prpr));
  for(int i=2;i<rt;++i){
    if(!prpr[i]) {
      if(n / i * i == n) return false;
      for(int j=i; j<=rt; j+=i) prpr[j] = 1;
    }
  }
  return true;
}

int main() {
  int x;
  cin >> x;
  while(1) {
    if(isPrime(x)) {
      cout << x << endl;
      return 0;
    }
    x++;
  }
}

Measured memory_bytes: 640
n = int(input())
S = [input() for _ in range(n)]

count = 0
ba = 0
wa = 0
bw = 0
for s in S:
    count += s.count('AB')
    if s[0] == 'B' and s[-1] == 'A':
        ba += 1
    elif s[0] == 'B':
        bw += 1
    elif s[-1] == 'A':
        wa += 1

if ba:
    count += ba - 1
    ba = 1
if ba:
    if wa and bw:
        count += 2
        wa -= 1
        bw -= 1
        ba -= 1
    if ba:
        if wa < bw:
            wa += 1
        else:
            bw += 1
count += min(wa,bw)

print(count)



Measured memory_bytes: 45656
/*  -*- coding: utf-8 -*-
 *
 * a.cc: C: Reconciled?
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_N = 100000;

typedef long long ll;
const ll MOD = 1000000007;

/* typedef */

/* global variables */

/* subroutines */

ll fs[MAX_N + 1];

/* main */

int main() {
  int n, m;
  cin >> n >> m;
  if (n < m) swap(n, m);

  if (n > m + 1) {
    puts("0");
    return 0;
  }

  fs[0] = 1;
  for (int i = 1; i <= n; i++) fs[i] = (fs[i - 1] * i) % MOD;

  ll ans = fs[n] * fs[m] % MOD;
  if (n == m) ans = (ans * 2) % MOD;

  printf("%lld\n", ans);
  return 0;
}


Measured memory_bytes: 1024