akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <unistd.h>
 
using namespace std;
 
typedef long long ll;
typedef pair<ll,ll> P;
 
long long int INF = 1e18;
const ll fact_table = 5000000;
double Pi = 3.1415926535897932384626;
 
vector<ll> G[550010];
vector<ll> R[550010];
vector<pair<ll, double> > tree[500010];
priority_queue <ll> pql;
priority_queue <P> pqp;
//big priority queue
priority_queue <ll,vector<ll>,greater<ll> > pqls;
priority_queue <P,vector<P>,greater<P> > pqps;
//small priority queue
//top pop
 
ll dx[8]={1,0,-1,0,1,1,-1,-1};
ll dy[8]={0,1,0,-1,1,-1,-1,1};
char dir[] = "DRUL";
//ll bit[500005];
//↓,→,↑,←
 
 
#define p(x) cout<<x<<"\n";
#define el cout<<"\n";
#define pe(x) cout<<(x)<<" ";
#define ps(x) cout<<fixed<<setprecision(25)<<x<<endl;
#define pu(x) cout<<(x);
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define CLEAR(a) a = decltype(a)(); 
 
 
ll mod = 998244353;
//ll mod = 1000000007;
 
ll rui(ll number1,ll number2){
 
    if(number2 == 0){
        return 1;
    }else{
        ll number3 = rui(number1,number2 / 2);
        number3 *= number3;
        number3 %= mod;
        if(number2%2==1){
            number3 *= number1;
            number3 %= mod;
        }
        return number3;
    }
}
ll gcd(ll number1,ll number2){
 
    if(number1 > number2){
        swap(number1,number2);
    }
    if(number1 == 0 || number1 == number2){
        return number2;
    }else{
        return gcd(number2 % number1,number1);
    }
}
void YES(bool condition){
 
    if(condition){
        p("YES");
    }else{
        p("NO");
    }
    return;
}
void Yes(bool condition){
 
    if(condition){
        p("Yes");
    }else{
        p("No");
    }
    return;
}
 
/*
ll fact[fact_table + 5],rfact[fact_table + 5];
 
void c3_init(){
    fact[0] = rfact[0] = 1;
    for(ll i=1; i<=fact_table; i++){
        fact[i] = (fact[i-1]*i) % mod;
    }
    rfact[fact_table] = rui(fact[fact_table],mod - 2);
    for(ll i=fact_table; i>=1; i--){
       rfact[i-1] = rfact[i] * i;
       rfact[i-1] %= mod;
    }
    return;}
ll c3(ll n,ll r){
    return (((fact[n] * rfact[r]) % mod ) * rfact[n-r]) % mod;}
*/
 
ll n,m,num,sum,a,b,c,d,e,f,g,h,w,i,j,q,r,l;
ll k,ans;
ll x[500005],y[500005],z[500005];
ll dp[5005][5005];
char s[500005];

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    cin >> n;
    for(ll i=0;i<n;i++){
        cin >> x[i];
    }
    ll look = 0;
    for(ll i=0;i<n;i++){
        if(x[i] == look + 1){
            look++;
        }
    }
    if(look == 0){
        p(-1);
        return 0;
    }
    p(n - look);

    return 0;
}















Measured memory_bytes: 42880
using System;

namespace ConsoleApplication6
{
    class Program
    {
        static void Main(string[] args)
        {
            string read = Console.ReadLine();
            int N = int.Parse(read);
            int output = 0;
            for (int i = 0; i < N; i++)
            {
                read = Console.ReadLine();
                string[] split = read.Split(' ');
                int A = int.Parse(split[0]);
                int B = int.Parse(split[1]);
                output += B - A + 1;
            }
            Console.WriteLine(output);
        }
    }
}

Measured memory_bytes: 13140
#include<stdio.h>
#define MAX 101
#define INF 5000000
#define WHITE 0
#define GRAY 1
#define BLACK 2

int n,m[MAX][MAX];

void dijkstra(){
  int minv,i,u,v;
  int d[MAX],color[MAX];

  for(i = 0;i<n;i++){
    d[i] = INF;
    color[i] = WHITE;
  }

  d[0] = WHITE;
  color[0] = GRAY;
  while(1){
    minv = INF;
    u = -1;
    for(i = 0;i<n;i++){
      if(minv > d[i] && color[i] != BLACK){
	u = i;
	minv = d[i];
      }
    }
    if(u == -1)break;
    color[u] = BLACK;
    for(v = 0;v<n;v++){
      if(color[v] != BLACK && m[u][v] != INF){	if(d[v] > d[u] + m[u][v]){
	  d[v] = d[u] + m[u][v];
	  color[v] = GRAY;
	}
      }
    }
    
  }
 for(i=0;i<n;i++){
    printf("%d ",i);
    if(d[i]==INF)printf("-1\n");
    else printf("%d\n",d[i]);
  }
}
 
int main(){
  int i,j;
  int k,c,u,v;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      m[i][j]=INF;
    }
  }
 
  for(i=0;i<n;i++){
    scanf("%d%d",&u,&k);
    for(j=0;j<k;j++){
      scanf("%d%d",&v,&c);
      m[u][v]=c;
    }
  }
  dijkstra();
  return 0;
  
  }
  



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

using namespace std;

int main() {

    int n;
    cin>>n;
    int nn = n;
    int dig;
    int sum=0;
    while(n){
        dig=n%10;
        sum+=dig;
        n/=10;
    }
    if(nn%sum==0){
        cout<<"Yes"<<endl;
    }
    else{
        cout<<"No"<<endl;
    }

}

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

using namespace std;

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


int main() {

	int n,i;

	cin>>n>>i;

	cout<<n-i+1<<endl;

	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <cstdlib>
#include <cassert>
#include <iostream>
#include <set>
#include <vector>
#include <cstring>
#include <string>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <complex>
#include <map>
#include <queue>
#include <array>
#include <bitset>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef long double ld;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<int, int> pii;
typedef pair<double, double> pdd;
typedef vector<pii> vii;
typedef vector<string> vs;
//typedef long long int;

int main() {
  std::ios::sync_with_stdio(false); std::cin.tie(0);
  int n, k;
  cin >> n >> k;
  vi a(n), c(n);
  for (int i = 0; i < n; ++i) cin >> a[i] >> c[i];
  ll ma = 0;
  int p = 0;
  for (int b = 30; b >= 0; --b) {
    int B = 1 << b;
    int cur = p + max(k % 2, B - 1);
    if ((k & B) || b == 0) {
      ll s = 0;
      for (int i = 0; i < a.size(); ++i) if ((a[i] | cur) == cur) s += c[i];
      ma = max(ma, s);
    }
    if (k & B) {
      p |= B;
    }
  }
  cout << ma << endl;
  return 0;
}

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

int main(){
    int n;
    
    while(cin>>n,n!=0){
        vector<int> s(n);
        rep(i,n) cin >> s[i];
        double ave=0;
        double dis=0;
        rep(i,n) ave+=s[i];
        ave /= (double)(n);
        rep(i,n) dis+=(s[i]-ave)*(s[i]-ave);
        dis /= (double)(n);
        dis = sqrt(dis);
        printf("%.5f\n",dis);
    }
}


Measured memory_bytes: 3208
#include <bits/stdc++.h>
using namespace std;
using lint     = long long;
const lint inf = 1LL << 60;
const lint mod = 1000000007;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    lint n;
    cin >> n;
    map<lint, lint> cnt;
    for (int i = 0; i < n; ++i) {
        lint a;
        cin >> a;
        cnt[a]++;
    }
    lint ret = 0;
    for (auto &p : cnt) {
        if (p.second % 2 == 1)
            ret++;
    }
    cout << ret << "\n";
    return 0;
}

Measured memory_bytes: 6528
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
using namespace std;

const int MAXN=300100;
int w,h,n;

struct point
{
	int x,y;
    bool operator <( const point &a) const
	{return x<a.x;}
}p[MAXN];

struct segment_tree{int w,tag;}tr[MAXN<<2];
void pushup(int k){tr[k].w=max(tr[k<<1].w,tr[k<<1|1].w);}

void pushdown(int k){
	if(tr[k].tag)
	{
		int tmp(tr[k].tag);
		tr[k<<1].w+=tmp,tr[k<<1].tag+=tmp,
		tr[k<<1|1].w+=tmp,tr[k<<1|1].tag+=tmp,
		tr[k].tag=0;
	}
}

void modify(int k,int l,int r,int x,int y,int val){
	if(l>=x && r<=y)
	{tr[k].w+=val,tr[k].tag+=val;return ;}
	int mid=(l+r)>>1;pushdown(k);
	if(x<=mid) modify(k<<1,l,mid,x,y,val);
	if(y>mid) modify(k<<1|1,mid+1,r,x,y,val);
	pushup(k);
}

int query(int k,int l,int r,int x){
	if(l==r) return tr[k].w;
	int mid=(l+r)>>1;pushdown(k);
	return x<=mid ? query(k<<1,l,mid,x) : query(k<<1|1,mid+1,r,x);
}

int Y[MAXN];
int st[2][MAXN],top[2];
int ans;

void solve(){
	register int i;
	sort(p+2,p+1+n);

	top[0]=top[1]=0,
	st[0][0]=st[1][0]=1;
	modify(1,1,n,1,n,h<<1);
	for(i=2;i<=n;i++){
		modify(1,1,n,1,i-1,(p[i].x-p[i-1].x)<<1);
		ans=max(ans,tr[1].w);
		if(p[i].y>=(h>>1)){
			modify(1,1,n,st[0][top[0]],i-1,(p[i].y-h)<<1);
			while(top[0] && p[st[0][top[0]]].y>=p[i].y)
				modify(1,1,n,st[0][top[0]-1],st[0][top[0]]-1,(p[i].y-p[st[0][top[0]]].y)<<1),
				top[0]--;
			st[0][++top[0]]=i;
		}
		else{
			modify(1,1,n,st[1][top[1]],i-1,-p[i].y<<1);
			while(top[1] && p[st[1][top[1]]].y<=p[i].y)
				modify(1,1,n,st[1][top[1]-1],st[1][top[1]]-1,(p[st[1][top[1]]].y-p[i].y)<<1),
				top[1]--;
			st[1][++top[1]]=i;
		}
	}
	memset(tr,0,sizeof(tr));
}

int main(){
	scanf("%d%d%d",&w,&h,&n); n++;
	for(int i=2;i<=n;i++)
		scanf("%d%d",&p[i].x,&p[i].y);
	p[++n]=(point){w,h};
	solve();
	swap(w,h);
	for(int i=1;i<=n;i++)
		swap(p[i].x,p[i].y);
	solve();
	printf("%d\n",ans);
}


Measured memory_bytes: 13952
/*! at_abc162c.cc
 *  2020-04-30
 *  GCC+17
 *  Info Fields (opt.)
 *  - Type: math
 *  - Keywords: number theory, GCD
 *  - Notes: Implementing my own gdc(a,b,c) function was very stupid. Should
 *    have used the fact that gcd(a,gcd(b,c)) == gcd(gcd(a,b),c)
 */

#include <stdio.h>
#include <string.h>

// Driver Program to test above function
long long unsigned gcd(const int *allpr, int a, int b, int c) {
    int i = 0;
    long long unsigned mygcd = 1;
    int smaller = a < b ? (a < c ? a : c) : (b < c ? b : c);
    for (; allpr[i] <= smaller; i++)
        while ((a % allpr[i] == 0) && (b % allpr[i] == 0) &&
               (c % allpr[i] == 0)) {
            a /= allpr[i];
            b /= allpr[i];
            c /= allpr[i];
            mygcd *= allpr[i];
        }
    return mygcd;
}

int main() {
    int n = 250;
    bool prime[n + 1];
    int allpr[n + 1];
    memset(prime, true, sizeof(prime));
    memset(allpr, 0, sizeof(allpr));

    for (int p = 2; p * p <= n; p++)
        if (prime[p])
            for (int i = p * p; i <= n; i += p)
                prime[i] = false;

    int top = 0;
    for (int i = 2; i < n + 1; i++)
        if (prime[i])
            allpr[top] = i, top++;


    int in;
    long long unsigned sum = 0;
    scanf("%i", &in);
    for (int l = 1; l <= in; l++)
        for (int j = 1; j <= in; j++)
            for (int k = 1; k <= in; k++)
                sum += gcd(allpr, l, j, k);

    printf("%llu\n", sum);

    return 0;
}


Measured memory_bytes: 1712
#include <bits/stdc++.h>
#define int long long

using namespace std;

const int mod = 1e9 + 7;

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int n, k, ans = 0;
    cin >> n >> k;
    for (int i = k; i <= n + 1; ++i) {
        ans = (ans + i * (n - i + 1) + 1) % mod;
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 3652
#pragma GCC optimize("O3")
#pragma GCC target("avx")
#include <bits/stdc++.h>
#define rep(i ,n) for(int i=0;i<(int)(n);++i)
#define repr(i ,n) for(int i=n;i>(int)(n);--i)
#define rep1(i ,n) for(int i=1;i<=(int)(n);++i)
#define ALL(a) a.begin(), a.end()
#define RSORT(a) sort(ALL(a),greater<>())
#define SORT(a) sort(ALL(a))
#define bit_check(bit, i) ((bit>>(i)) & 1)
#define PRINT(x) printf("%d\n",(x));
#define ENDL printf("\n");
using namespace std;
typedef long long int i64;
typedef unsigned long long u64;
template<class T> using V = vector<T>;
using VI = V<int>;
const int INF = 2e9;
const i64 MOD = 1e9 + 7;

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

signed main(){
    int r ; cin >> r;
    double PI = acos(-1);
    cout << fixed << 2 * PI * (double)r << endl;
}

Measured memory_bytes: 3772
//#define _GLIBCXX_DEBUG

#include<bits/stdc++.h>
using namespace std;

#define endl '\n'
#define lfs cout<<fixed<<setprecision(10)
#define ALL(a)  (a).begin(),(a).end()
#define ALLR(a)  (a).rbegin(),(a).rend()
#define spa << " " <<
#define fi first
#define se second
#define MP make_pair
#define MT make_tuple
#define PB push_back
#define EB emplace_back
#define rep(i,n,m) for(ll i = (n); i < (ll)(m); i++)
#define rrep(i,n,m) for(ll i = (ll)(m) - 1; i >= (ll)(n); i--)
using ll = long long;
using ld = long double;
const ll MOD1 = 1e9+7;
const ll MOD9 = 998244353;
const ll INF = 1e18;
using P = pair<ll, ll>;
template<typename T1, typename T2>
bool chmin(T1 &a,T2 b){if(a>b){a=b;return true;}else return false;}
template<typename T1, typename T2>
bool chmax(T1 &a,T2 b){if(a<b){a=b;return true;}else return false;}
ll median(ll a,ll b, ll c){return a+b+c-max({a,b,c})-min({a,b,c});}
void ans1(bool x){if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;}
void ans2(bool x){if(x) cout<<"YES"<<endl;else cout<<"NO"<<endl;}
void ans3(bool x){if(x) cout<<"Yay!"<<endl;else cout<<":("<<endl;}
template<typename T1,typename T2>
void ans(bool x,T1 y,T2 z){if(x)cout<<y<<endl;else cout<<z<<endl;}  
template<typename T>
void debug(vector<vector<T>>&v,ll h,ll w){for(ll i=0;i<h;i++)
{cout<<v[i][0];for(ll j=1;j<w;j++)cout spa v[i][j];cout<<endl;}};
void debug(vector<string>&v,ll h,ll w){for(ll i=0;i<h;i++)
{for(ll j=0;j<w;j++)cout<<v[i][j];cout<<endl;}};
template<typename T>
void debug(vector<T>&v,ll n){if(n!=0)cout<<v[0];
for(ll i=1;i<n;i++)cout spa v[i];cout<<endl;};
template<typename T>
vector<vector<T>>vec(ll x, ll y, T w){
  vector<vector<T>>v(x,vector<T>(y,w));return v;}
ll gcd(ll x,ll y){ll r;while(y!=0&&(r=x%y)!=0){x=y;y=r;}return y==0?x:y;}
vector<ll>dx={1,0,-1,0,1,1,-1,-1};
vector<ll>dy={0,1,0,-1,1,-1,1,-1};
template<typename T>
vector<T> make_v(size_t a,T b){return vector<T>(a,b);}
template<typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v(ts...))>(a,make_v(ts...));
}
template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2>&p){
  return os << p.first << " " << p.second;
}  
/*void dfs(P &mx,ll k,vector<vector<ll>>&g,vector<ll>&h,vector<bool>&used){
  if(mx.fi==h[k])mx.se++;
  else chmax(mx,MP(h[k],1LL));
  used[k]=true;
  for(auto to:g[k]){
    if(used[to])continue;
    dfs(mx,to,g,h,used);
  }
}*/
int main(){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  ll res=0,buf=0;
  bool judge = true;
  ll n,m;cin>>n>>m;
  vector<ll>h(n);
  rep(i,0,n)cin>>h[i];
  vector<vector<ll>>g(n);
  rep(i,0,m){
    ll u,v;cin>>u>>v;u--;v--;
    g[u].PB(v);
    g[v].PB(u);
  }
  rep(i,0,n){
    bool sw=true;
    for(auto to:g[i])if(h[to]>=h[i])sw=false;
    res+=sw;
  }
  cout<<res<<endl;
  return 0;
}

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

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int m1, d1, m2, d2;
  cin >> m1 >> d1 >> m2 >> d2;
  if (m2 > m1) cout << 1 << '\n';
  else cout << 0 << '\n';
  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int r = sc.nextInt();
    int g = sc.nextInt();
    int b = sc.nextInt();
    if((g * 10 + b) % 4 == 0){
      System.out.println("YES");
    } else {
      System.out.println("NO");
    }
  }
}

Measured memory_bytes: 21712
#include<stdio.h>
#include<math.h>
int main(){
  int x,ans=1,t,xx;
  scanf("%d",&x);
  xx=(int)sqrt(x);
  for(int i=2; i<=xx; i++)
  {
    t=i;
    while(t<=x) t*=i;
    ans=(ans>t/i)?ans:t/i;
  }
  printf("%d",ans);
  return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<(int)(n); i++)
#define all(v) v.begin(), v.end()
#define PRINT(v) for (auto x : (V)) cout <<x <<" " <<endl;
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
const ll MOD = 1000000007;
const ll INF = 10000000000000000;
vector<int> x4 = {0, 1, 0, -1}, x8 = {0, 1, 1, 1, 0, -1, -1, -1};
vector<int> y4 = {1, 0, -1, 0}, y8 = {1, 1, 0, -1, -1, -1, 0, 1};
template<class T> struct edge { int from, to; T cost;};
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;}
template<class T> inline T powerM(T a,T b){if (b==0) return 1;
T tmp = powerM(a,b/2); if (b%2==0) return tmp*tmp%MOD; else return tmp*tmp%MOD*a%MOD; }
template<class T> inline T power(T a,T b,T m){ if (b==0) return 1;
  T tmp = power(a,b/2,m); if (b%2==0) return tmp*tmp%m; else return tmp*tmp%m*a%m; }
template<class T> inline T gcd(T a, T b){if (b==0) return a; return gcd(b, a%b);}
template<class T> inline T lcm(T a, T b){return a / gcd(a,b) * b;}
// ax+by=gcd(a,b)を解く
template<class T> inline T extgcd(T a,T b,T &x,T &y){if (b==0){x=1; y=0; return a;} T d=extgcd(b,a%b,y,x); y -= a/b*x; return d;}
void hey(){ cout <<"hey" <<endl; }


int main() {
  int n; cin >>n;
  int a,b; cin >>a >>b;
  int c = 0, d = 0, e = 0;
  rep(i, n){
    int p; cin >>p;
    if (p <= a) c++;
    else if (p <= b) d++;
    else e++;
  }
  int res = min( min( c, d ), e );
  cout <<res <<endl;
}


Measured memory_bytes: 256
#include <stdint.h>
#include <inttypes.h>
#include <stdio.h>

static int64_t u[100000];

int64_t root(int64_t i)
{
  if (u[i] < 0) return i;
  return u[i] = root(u[i]);
}

int main(void)
{
  int64_t n, m;
  scanf("%" SCNd64 "%" SCNd64, &n, &m);
  int64_t a[m], b[m], ans[m];
  for (int i = 0; i < n; i++) u[i] = -1;
  for (int i = 0; i < m; i++) {
    scanf("%" SCNd64 "%" SCNd64, &a[i], &b[i]);
    a[i]--;
    b[i]--;
  }
  ans[m - 1] = n * (n - 1) / 2;
  for (int i = m - 1; i > 0; i--) {
    ans[i - 1] = ans[i];
    int64_t ra = root(a[i]);
    int64_t rb = root(b[i]);
    if (ra != rb) {
      ans[i - 1] -= u[ra] * u[rb];
      if (u[ra] < u[rb]) {
        u[ra] += u[rb];
        u[rb] = ra;
      } else {
        u[rb] += u[ra];
        u[ra] = rb;
      }
    }
  }
  for (int i = 0; i < m; i++) {
    printf("%" PRId64 "\n", ans[i]);
  }
}


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

typedef long long ll;

int main() {
    int N;
    cin >> N;
    if (N % 1000 == 0) {
        cout << 0 << endl;
    } else {
        int a = N % 1000;
        int ans = 1000 - a;
        cout << ans << endl;
    }
}


Measured memory_bytes: 3616
#include <limits.h>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#define int long long
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REPS(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define FOR(i, a, b) for (int i = (a), i##_len = (b); i <= i##_len; ++i)
#define REV(i, a, b) for (int i = (a); i >= (b); --i)
#define CLR(a, b) memset((a), (b), sizeof(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define INF (LLONG_MAX - 1e5)
#define fcout cout << fixed << setprecision(10)

using namespace std;

struct edge {
    int to, cost;
    edge(int _to, int _cost) : to(_to), cost(_cost) {}
    edge() {}
};
typedef pair<int, int> P;

void dijkstra(int s, int n, vector<edge> E[], int a[]) {
    priority_queue<P, vector<P>, greater<P> > que;
    REP(i, n + 1)
    a[i] = INF;
    a[s] = 0;
    que.push(P(0, s));

    while (!que.empty()) {
        P p = que.top();
        que.pop();
        int v = p.second;
        if (a[v] < p.first) continue;
        for (int i = 0; i < E[v].size(); ++i) {
            edge e = E[v][i];
            if (a[e.to] > a[v] + e.cost) {
                a[e.to] = a[v] + e.cost;
                que.push(P(a[e.to], e.to));
            }
        }
    }
}

int N, M, S, T;
vector<edge> Yen[100005];
vector<edge> Snuke[100005];
int s[100005];
int t[100005];
int ans[100005];

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

    cin >> N >> M >> S >> T;
    REP(i, M) {
        int u, v, a, b;
        cin >> u >> v >> a >> b;
        Yen[u].push_back(edge(v, a));
        Yen[v].push_back(edge(u, a));
        Snuke[u].push_back(edge(v, b));
        Snuke[v].push_back(edge(u, b));
    }

    dijkstra(S, N, Yen, s);
    dijkstra(T, N, Snuke, t);

    ans[N] = INF;
    REV(i, N - 1, 0) { ans[i] = min(ans[i + 1], s[i + 1] + t[i + 1]); }
    REP(i, N) { cout << (int)1e15 - ans[i] << endl; }

    return 0;
}


Measured memory_bytes: 19196
n,q = map(int,input().split())
base = input()

counter = [0]*(n+1)
count=0
for i,s in enumerate(base):
    if i < n-1 and s=="A" and base[i+1]=="C":
        count+=1
    counter[i+1]=count

ans=[]
for i in range(q):
    l,r = map(int,input().split())
    ans.append(str(counter[r-1]-counter[l-1]))
print('\n'.join(ans))

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

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

    bool a[200000] = {false};
    bool b[200000] = {false};

    int n, m; cin >> n >> m;
    for (int i = 0; i < m; ++i) {
        int d1, d2;
        cin >> d1 >> d2;
        if (d1 == 1 || d2 == 1) a[d1] = a[d2] = true;
        if (d1 == n || d2 == n) b[d1] = b[d2] = true;
    }

    for (int i = 0; i < n; ++i) {
        if (a[i] && b[i]) {
            cout << "POSSIBLE" << endl;
            return 0;
        }
    }

    cout << "IMPOSSIBLE" << endl;

    return 0;
}

Measured memory_bytes: 640
import java.util.Scanner;

public class Main{

	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		String S = scan.nextLine();
		boolean flag = false;
		boolean yes = false;
		for(int i=0; i<S.length();i++){
			if(S.substring(i,i+1).equals("C")){
				flag = true;
			}
			if(S.substring(i,i+1).equals("F")&&flag){
				yes = true;
			}
		}
		if(yes){
			System.out.println("Yes");
		}else{
			System.out.println("No");
		}
	}

}

Measured memory_bytes: 10192
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
const int maxn=2e5+10,logn=20;
int st[2][logn][maxn];
int p[maxn],pos[maxn];
int n,logf[maxn],tot;
std::vector<int> ed[maxn];
int co[maxn];
std::priority_queue<int,std::vector<int>,std::greater<int>> now;
struct Seq
{
    int l,r,h;
};
inline int minp(int x,int y)
{
    return p[x]<p[y]?x:y;
}
bool operator <(const Seq &a,const Seq &b)
{
    return p[a.h]<p[b.h];
}
int askmin(int l,int r,int id)
{
    if(l>r) return 0;
    int lg=logf[r-l+1];
    return minp(st[id][lg][l],st[id][lg][r-(1<<lg)+1]);
}
int work(int l,int r)
{
    int t1=askmin(l,r,l%2),t2=askmin(t1+1,r,r%2);
    co[p[t1]]=p[t2];
    if(t1>l) ed[p[t1]].push_back(work(l,t1-1));
    if(t1+1<t2-1) ed[p[t1]].push_back(work(t1+1,t2-1));
    if(t2<r) ed[p[t1]].push_back(work(t2+1,r));
    return p[t1];
}
int main()
{
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
    {
        scanf("%d",&p[i]);
        pos[p[i]]=i;
    }
    p[0]=n+1;
    logf[1]=0;
    for(int i=2;i<=n;++i) logf[i]=logf[i-1]+((i&(i-1))==0?1:0);
    for(int id=0;id<2;id++)
    {
        auto &sti=st[id];
        for(int i=1;i<=n;i++)
            sti[0][i]=(i%2==id)?i:0;
        for(int i=1;i<=logf[n];i++)
            for(int j=1;j<=n;j++)
            {
                sti[i][j]=sti[i-1][j];
                if(j+(1<<(i-1))<=n)
                    sti[i][j]=minp(sti[i][j],sti[i-1][j+(1<<(i-1))]);
            }
    }
    tot=0;
    int root=work(1,n);
    now.push(root);
    while(!now.empty())
    {
        int cur=now.top();
        printf("%d %d ",cur,co[cur]);
        now.pop();
        for(auto &i:ed[cur]) now.push(i);
    }
    return 0;
}


Measured memory_bytes: 49792
#include <stdio.h>  
#include <algorithm>  
#include <bitset>
#include <cassert>
#include <ctime>  
#include <cmath>  
#include <cstdlib>  
#include <cstring>  
#include <functional>  
#include <iostream>  
#include <deque>  
#include <stack>
#include <queue>  
#include <vector>  
#include <map>  
#include <set>  
#include <string>  
#include <unordered_map>  
#include <unordered_set>  

using namespace std;

#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define endl '\n'

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, int> pdi;

const ll INF = 1e18;
const int MAXN = 3e5 + 5;

ll a, b, c;
int cnt[10];

bool nxt(string &s) {
	for(int i=s.size()-1; i>0; i--) {
		if(cnt[s[i]-'a'] == 1) continue;
		cnt[s[i]-'a']--;
		s[i] = (char)(s[i] + 1);
		cnt[s[i]-'a']++;
		for(int j=i+1; j<s.size(); j++) {
			cnt[s[j]-'a']--;
			s[j] = 'a';
			cnt[0]++;
		}
		return 1;
	}
	return 0;
}

int main() {
	ios::sync_with_stdio(0); cin.tie(0);
	int N; cin >> N;
	string s;
	for(int i=0; i<N; i++) s += 'a';
	cnt[0] = N;
	cout << s << endl;
	while(nxt(s)) cout << s << endl;
}



Measured memory_bytes: 1536
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
 
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

l = LIST()
l.append(sum(l))
for c in l:
    if c % 3 == 0:
        print("Possible")
        os.sys.exit()
print("Impossible")




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

#define M 1000000007
#define maxn 603

using namespace std;
typedef long long ll;

inline ll add(ll a, ll b) {return a + b < M ? a + b : a + b - M;}
inline ll sub(ll a, ll b) {return a - b < 0 ? a - b + M : a - b;}
inline ll mult(ll a, ll b) {return a * b % M;}

int n, k;
int a[maxn], b[maxn];

ll d[maxn][maxn];
int s[maxn][maxn];

ll g[maxn];

int main(){
  #define TASK "ABC"
 // freopen(TASK".inp", "r", stdin); freopen(TASK".out", "w", stdout);
  ios_base::sync_with_stdio(0);

  cin >> n >> k;
  n *= 2;
  
  for (int i = 0; i < k; ++i) {
  	int a, b;
	cin >> a >> b;
	::a[i] = min(a, b);
	::b[i] = max(a, b);
	
	s[a][a] = s[b][b] = 1;
  }
  
  g[0] = 1;
  for (int i = 2; i <= n; i += 2) 
  	g[i] = mult(g[i - 2], i - 1);
  	
  for (int i = 1; i <= n; ++i)
    for (int j = i + 1; j <= n; ++j)
	  s[i][j] = s[i][j - 1] + s[j][j]; 
  
  ll ans = 0;
  for (int l = 1; l < n; l += 2)
  	for (int i = 1; i + l <= n; ++i) {
	  int j = i + l;
	
	  bool flag = 0;   
	  
	  for (int ik = 0; ik < k; ++ik) 
	    if ((i <= a[ik] && a[ik] <= j) ^ (i <= b[ik] && b[ik] <= j)) 
	      flag = 1;
	    	
	  if (flag) continue;
	  
	  d[i][j] = g[l + 1 - s[i][j]];
	  
	  for (int ik = i + 1; ik < j; ik += 2) 
	  	d[i][j] = sub(d[i][j], mult(d[i][ik], g[j - ik - s[ik + 1][j]]));
	  
	  ans = add(ans, mult(d[i][j], g[n - 2 * k + s[i][j] - l - 1]));	  
	}
	
  cout << ans;
  
  return 0;
}

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

#define fast ios_base::sync_with_stdio(false),cin.tie(NULL)
#define ldb long double 
#define db double
#define int long long

#define fr first
#define se second
#define lb lower_bound 
#define ub upper_bound 
#define pb push_back
#define mpr make_pair

#define pi pair<int,int>
#define pdb pair<db,db>
#define pldb pair<ldb,ldb>

#define vi vector<int>
#define vdb vector<db>
#define vldb vector<ldb>
#define vpi vector< pi >

#define mi map<int,int>
#define mdb map<db,db>
#define mldb map<ldb,ldb>


#define forr(a,b) for (int i = (a); i < (b); ++i)
#define rrof(a,b) for (int i = (b)-1; i >= (a); --i)

#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)

const int md = 1e9+7;
const int MX = 2e5+5;
const int INF = 1e18; 
const ldb PI = 4*atan((ldb)1);

int power_md(int a,int n)
{
 int res=1;
 while(n)
{
 if(n%2)
  res=(res%md*a%md)%md;
  a=(a%md*a%md)%md;
  n/=2;
}
res%=md;
return res;
}

int power(int a,int n)
{
 int res=1;
 while(n)
{
 if(n%2)
  res*=a;
  a=a*a;
  n/=2;
}
return res;
}

int abst(int a)
{
 return ((a<0)?(-1*a):(a));
}

class cmp_set{
public:
	bool operator() (int a, int b){
		return a > b;
	}
};

vector<string> vec_splitter(string s) {
	s += ',';
	vector<string> res;
	while(!s.empty()) {
		res.push_back(s.substr(0, s.find(',')));
		s = s.substr(s.find(',') + 1);
	}
	return res;
}
void debug_out(
vector<string> __attribute__ ((unused)) args,
__attribute__ ((unused)) int idx, 
__attribute__ ((unused)) int LINE_NUM) { cerr << endl; } 
template <typename Head, typename... Tail>
void debug_out(vector<string> args, int idx, int LINE_NUM, Head H, Tail... T) {
	if(idx > 0) cerr << ", "; else cerr << "Line(" << LINE_NUM << ") ";
	stringstream ss; ss << H;
	cerr << args[idx] << " = " << ss.str();
	debug_out(args, idx + 1, LINE_NUM, T...);
}
#ifdef XOX
#define debug(...) debug_out(vec_splitter(#__VA_ARGS__), 0, __LINE__, __VA_ARGS__)
#else
#define debug(...) 42
#endif

int32_t main()
{
    fast;
    int n,m;
    cin>>n>>m;
    int arr[m];
    for(int i=0;i<m;i++)
     cin>>arr[i];
     sort(arr,arr+m);
    multiset< int > st;
    for(int i=1;i<m;i++)
    {
        st.insert((arr[i]-arr[i-1]));
    }
    int res=0;
    if(n>=m)
     res=0;
     else
     {
         int cnt=0;
         auto it=st.begin();
         while(cnt<(m-n))
         {
             int p=*(it);
             res+=p;
             it++;
             cnt++;
         }
     }
     cout<<res<<"\n";
    return 0;
}

Measured memory_bytes: 5760
#![allow(non_snake_case, unused)]
use std::cmp::*;
use std::collections::*;
use std::f64::consts::*;

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input!{
        mut w: chars,
    }
    let mut dicts = HashMap::new();
    for c in w.iter() {
        *(dicts.entry(c).or_insert(0)) += 1;
    }
    println!(
        "{}",
        if dicts.len() == dicts.iter().filter(|&(_, x)| x % 2 == 0).count() {
            "Yes"
        } else {
            "No"
        }
    );
}


Measured memory_bytes: 4352
reizouNum, rangeNum, waribikiNum = map(int, input().split())

reizous = list(map(int, input().split()))
ranges = list(map(int, input().split()))

waribikis = [ list(map(int, input().split())) for _ in range(waribikiNum) ]



ans = 0
minreizou = min(reizous)
minrange = min(ranges)

ans = minreizou + minrange
# 割引券の額を総当たりする
for rei, rai, discount in waribikis:
    cost = reizous[rei-1] + ranges[rai-1] - discount
    ans = min(ans, cost)

print(ans)

Measured memory_bytes: 38568
#include <cstdio>

using namespace std;

void CheckLongest(int& longest, int i, int j)
{
    if (longest < j - i + 1){
        longest = j - i + 1;
        //printf("length:%d\n\n", longest);
    }
}

int main()
{
    int n;
    int k;

    while (scanf("%d %d", &n, &k) * n != 0){
        char card[100005] = {0};
        int longest = 0;
        bool zero_flag;

        for (int i = 0; i < k; i++){
            int tmp;
            scanf("%d", &tmp);
            card[tmp] = 1;
        }

        zero_flag = card[0];
        for (int i = 1, j = 1; i <= n; ){
            //for (int k = i; k <= j || !printf("f:%d\n", zero_flag); k++) printf("%d ", k);
            if (card[j] != 1){
                if (j <= n && zero_flag){
                    zero_flag = false;
                    CheckLongest(longest, i, j);
                    j++;
                }
                else {
                    if (card[i] != 1){
                        zero_flag = card[0];
                    }
                    i++;
                    if (j < i){
                        j = i;
                    }
                }
            }
            else {
                CheckLongest(longest, i, j);
                j++;
            }
        }
        printf("%d\n", longest);
        //puts("");
    }

    return 0;
}

Measured memory_bytes: 1132
#include<stdio.h>
int main(void)
{
	char s[3];
	int i,cnt;
	for(i=0;i<3;i++){
		scanf("%c",&s[i]);
		if(s[i]=='1'){
			cnt+=1;
		}
	}
	printf("%d\n",cnt);
	return 0;
}


Measured memory_bytes: 128
import heapq

n,m=map(int,input().split())
A=list(map(lambda x:int(x)*(-1),input().split()))
heapq.heapify(A)

for _ in range(m):
    tmp_min = heapq.heappop(A)
    heapq.heappush(A,(-1)*(-tmp_min//2))

print(-sum(A))

Measured memory_bytes: 14180
//is there any case of -1 or any special corner cases ?
#include<bits/stdc++.h>
using namespace std;
#define int long long int 
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define vi vector<int>
#define pi pair<int,int>
#define all(v) v.begin(),v.end()
#define zeros(arr) memset(arr,0,sizeof(arr));
#define precise(num)  cout<<fixed; cout << std::setprecision(num)
#define nl cout<<"\n";
#define test int t;cin>>t;while(t--) 
const int maxx  = 2*1e6 , limit = 9*1e18 , MOD=1e9+7;
string binary(int n){bitset<60>b(n) ;string p =b.to_string();return p;}
int decimal(string n) { int dec_value = 0;  int base = 1;  for (int i = n.size() - 1; i >= 0; i--) { if (n[i] == '1') 
dec_value += base; base = base * 2; } return dec_value; } 
bool isPrime(int n){if (n <= 1) return false; if (n <= 3) return true;if (n % 2 == 0 || n % 3 == 0) return false;
for (int i = 5; i * i <= n; i = i + 6) if (n % i == 0 || n % (i + 2) == 0) return false; return true; }
int pow (int x, int n,int mod) {if (n == 0) return 1; int res = pow (x, n / 2,mod);res = (res * res) % mod;if (n % 2) res = (res * x ) % mod;return res;}

#define boost  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define endl '\n';

int32_t main(){
    int n;
    cin>>n;
    int a[n+1];
    
    int su = 0;
    for(int i =0 ; i <  n ; i++ ){
      cin>>a[i];  
    
        su = su^a[i];
    }
    
    for(int i  =0 ; i < n ;i ++ ){
        int res = su^a[i];
        cout<<res<< " ";
    }cout<<endl;
    
    
}


Measured memory_bytes: 5104
N=int(input())
F=[]
for i in range(N):
    tem = list(map(int,input().split()))
    F.append(tem)
P=[]
for i in range(N):
    tem = list(map(int,input().split()))
    P.append(tem)


max_benef =-float("inf")

for d in range(1,2**10):
    op = ["-"] * 10  # あらかじめ ["-", "-", "-"] というリストを作っておく
    for j in range(10):
        if ((d >> j) & 1):
            op[10 - 1 - j] = "+"  # フラグが立っていた箇所を "+" で上書き
    
    m =0
    count=[0 for s in range(N)]
    for t in range(10):
        if op[t]=="+":
            for s in range(N):
                if F[s][t]==1:
                    count[s]+=1
    for s in range(N):
        m += P[s][count[s]]
    max_benef = max(m,max_benef)
    
print(max_benef)






Measured memory_bytes: 3188
from bisect import bisect_right
from collections import defaultdict
import sys
read = sys.stdin.readline

s = read()[:-1]
t = read()[:-1]
# 即時終了
if set(t) - set(s):
    print(-1)
    exit()

# 前処理
# 0based indexにおいてi文字目以降に文字cが出てくるidxを取得する

# 前処理の前処理、0文字目から見たときにその文字が何文字目にあるかを記録しておく
mojiidx = defaultdict(lambda: [])
for i, ss in enumerate(s + s):
    mojiidx[ss].append(i)

# i文字目において、次に文字cが出てくるのは何文字あと？
skiptable = []
for i in range(0, len(s)):
    tmp = {}
    for c, ls in mojiidx.items():
        tmp[c] = ls[bisect_right(ls, i)] - i
    skiptable.append(tmp)

# print(skiptable)

# 本処理
# 最初にうまく飛べる点を探索
for i, ss in enumerate(s):
    if ss == t[0]:
        now = i
        break

for tt in t[1:]:
    idx = now % len(s)
    now += skiptable[idx][tt]
print(now + 1)

Measured memory_bytes: 252544
import java.util.Scanner;

public class Main {

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

        int m = sc.nextInt();

        Node tree = null;
        for (int i = 0; i < m; i++) {
            String command = sc.next();

            if (command.equals("insert")) {
                long key = sc.nextLong();
                if (tree == null) {
                    tree = new Node();
                    tree.value = key;
                } else {
                    tree.insert(key);
                }
            } else {
                if (tree != null) {
                    tree.printInOrder();
                    System.out.println();
                    tree.printPreOrder();
                    System.out.println();
                }
            }
        }
    }

    static class Node {
        long value;
        Node left;
        Node right;

        void insert(long newValue) {
            if (newValue < this.value) {
                if (left == null) {
                    left = new Node();
                    left.value = newValue;
                } else {
                    left.insert(newValue);
                }
            } else {
                if (right == null) {
                    right = new Node();
                    right.value = newValue;
                } else {
                    right.insert(newValue);
                }
            }
        }

        void printInOrder() {
            if (left != null) {
                left.printInOrder();
            }
            System.out.print(" " + value);
            if (right != null) {
                right.printInOrder();
            }
        }

        void printPreOrder() {
            System.out.print(" " + value);
            if (left != null) {
                left.printPreOrder();
            }
            if (right != null) {
                right.printPreOrder();
            }
        }
    }
}



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

using namespace std;

#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define all(x) x.begin(),x.end()
#define sz(x) ((int)x.size())

const int MOD = 1e9+7;

typedef long long ll;
typedef pair<int,int> pii;
inline ll sqr(ll x) {
	return x*x;
}
ll ar[200];
int main() {
//	freopen("TASK.in","r",stdin);freopen("TASK.out","w",stdout);
	int n;
	cin>>n;
	for(int i=1;i<=n;i++) cin>>ar[i];
	ll ans=1e18;
	for(int i=-100;i<=100;i++) {
		ll tempans=0;
		for(int j=1;j<=n;j++) tempans+=sqr(i-ar[j]);
		ans=min(ans,tempans);
	}
	cout<<ans<<endl;
	return 0;
}

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

signed main(){
	int N, M, A, i;
	scanf("%lld%lld", &N, &M);
	priority_queue<int> pq;
	for(i = 0; i < N; i++){
		scanf("%lld", &A);
		pq.push(A);
	}
	for(i = 0; i < M; i++){
		A = pq.top();
		pq.pop();
		pq.push(A / 2);
	}
	int ans = 0;
	while(pq.size() > 0){
		ans += pq.top();
		pq.pop();
	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 1400
#include<iostream>
using namespace std;
 
int main(){
  int n;
  int ar[4] = {};

  cin >> n;
  for(int i=0; i<n; i++){
      string s;
      cin >> s;
      if(equal(s.begin(), s.end(), "AC")) ar[0]++;
      if(equal(s.begin(), s.end(), "WA")) ar[1]++;
      if(equal(s.begin(), s.end(), "TLE")) ar[2]++;
      if(equal(s.begin(), s.end(), "RE")) ar[3]++;
  }

  cout << "AC x " << ar[0] << endl;
  cout << "WA x " << ar[1] << endl;
  cout << "TLE x " << ar[2] << endl;
  cout << "RE x " << ar[3] << endl;
}

Measured memory_bytes: 3632
import math
a, b, h, m = map(int,input().split())
pi = 0

#円周率
for i in range(1, 100, 2):
    pi += (-1) ** (i // 2) * (1 / 2 ** i + 1 / 3 ** i) / i
pi = pi * 4 

x = (30 * h + 0.5 * m - 6 * m) * pi / 180
ans = (a * a + b * b - 2 * a * b * math.cos(x))**0.5
print(ans)

Measured memory_bytes: 9508
#include <iostream>
#include <map>
#include <stdio.h>
using namespace std;

int gcd2(int a,int b){
	while(b!=0){
		int w=a%b;
		a=b;
		b=w;
	}
	return a;
}

int main(void){
  int n;cin>>n;
  cin.ignore();
  while(n--){
    string s;
    getline(cin,s);
    bool f=true;
    for(int a=0;f;++a){
      if(gcd2(a,26)!=1) continue;
      for(int b=0;b<26&&f;++b){
        map<char,char> T;
        for(char c='a';c<='z';++c){
          T[((c-'a')*a+b)%26+'a']=c;
        }
        string s1;
        for(int i=0;i<s.size();++i)s1+=('a'<=s[i]&&s[i]<='z')?T[s[i]]:s[i];
        //cerr<<s1<<endl;
        if(s1.find("this") != -1|| s1.find("that") != -1){cout<<s1<<endl;f=false;}
      }
    }
  }
  return 0;
}

Measured memory_bytes: 1212
#include <bits/stdc++.h>
using namespace std;
#define FOR(I,X,Y) for(long long (I)=(X);(I)<(Y);(I)++)
#define REP(I,X,Y) for(long long (I)=(Y)-1;(I)>=(X);(I)--)
#define ALL(X) (X).begin(),(X).end()
#define pb push_back
#define COUNT(V,X) upper_bound((V).begin(),(V).end(),X)-lower_bound((V).begin(),(V).end(),X)
#define debug(x) cerr<<#x<<':'<<x<<endl;
#define DEBUG(v) cerr<<#v<<':';for(auto x:v)cerr<<x<<' ';cerr<<endl;
#define INF 1000000007
#define LINF 1000000000000000007
#define EPS 1e-9
typedef long long ll;

ll levenshtein(string s1,string s2){
  long long n = s1.size();
  long long m = s2.size();
  long long DP[n+1][m+1]={0};
  for(long long i = 0;i < n+1;i++)DP[i][0] = i;
  for(long long j = 0;j < m+1;j++)DP[0][j] = j;
  for(long long i = 1;i < n+1;i++){
    for(long long j = 1;j < m+1;j++){
      long long cost = (s1[i-1]==s2[j-1] ? 0 :1);
      DP[i][j] = min({DP[i-1][j]+1,DP[i][j-1]+1,DP[i-1][j-1]+cost});
    }
  }
  return DP[n][m];
}

signed main(){
  string s1,s2;
  cin >> s1 >> s2;
  cout << levenshtein(s1,s2) << endl;
}


Measured memory_bytes: 11028
/*  -*- coding: utf-8 -*-
 *
 * a.cc: A - Takoyaki
 */

#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 */

/* typedef */

/* global variables */

/* subroutines */

/* main */

int main() {
  int n, x, t;
  scanf("%d%d%d", &n, &x, &t);

  printf("%d\n", (n + x - 1) / x * t);
  return 0;
}


Measured memory_bytes: 3220
#include <bits/stdc++.h>
using namespace std;
const int N = 5e5;
vector<int> ed[N];
int n, m, q[N], used[N];
int cnt[N][2];
string s;
int main() {
    ios_base::sync_with_stdio(0);
    cin >> n >> m;
    cin >> s;
    for (int i = 1; i <= m; i++) {
        int u, v;
        cin >> u >> v;
        ed[u].push_back(v);
        ed[v].push_back(u);
    }
    for (int i = 1; i <= n; i++) {
        for (auto to: ed[i]) cnt[i][s[to - 1] - 'A']++;
    }
    int l = 1;
    int sz = 0;
    for (int i = 1; i <= n; i++)
        if (cnt[i][0] == 0 || cnt[i][1] == 0) {
            used[i] = 1;
            sz++;
            q[sz] = i;
        }
    while (l <= sz) {
        int v = q[l];
        for (auto to: ed[v]) {
            if (used[to]) continue;
            cnt[to][s[v - 1] - 'A']--;
            if (min(cnt[to][0], cnt[to][1]) == 0) {
                sz++;
                used[to] = 1;
                q[sz] = to;
            }
        }
        l++;
    }
    if (sz == n) cout << "No\n";
    else cout << "Yes\n";
    return 0;
}


Measured memory_bytes: 24784
n = int(input())
t,h,x = 0,0,0

for i in range(n):
    a,b = input().split()
    if ord(a[0]) < ord(b[0]):
        h += 3
    elif a == b:
        h += 1
        t += 1
    elif ord(a[0]) == ord(b[0]):
        if len(a) >= len(b):
            if b == a[:len(b)]:
                t += 3
            else:
                for i in range(len(b)):
                    if ord(a[i]) == ord(b[i]):
                        pass
                    elif ord(a[i]) < ord(b[i]):
                        h += 3
                        break
                    else:
                        t += 3
                        break
        elif len(a) < len(b):
            if a == b[:len(a)]:
                h += 3
            else:
                for i in range(len(a)):
                    if ord(b[i]) == ord(a[i]):
                        pass
                    elif ord(b[i]) < ord(a[i]):
                        t += 3
                        break
                    else:
                        h += 3
                        break
    else:
        t += 3
print(f"{t} {h}")
        
    
    


Measured memory_bytes: 5628
public class Hello{
    public static void Main(){

        string[] str = System.Console.ReadLine().Split(' ');
        int A = int.Parse(str[0]);
        int B = int.Parse(str[1]);
        int count = 0;
        
        for(int i = A; i <= B; i++){
            string num = i.ToString();
            if(num[0] == num[4] && num[1] == num[3]) count++;
        }
        System.Console.WriteLine(count);
    }
}


Measured memory_bytes: 13140
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n,t;
  cin >> n >>t;
  int ma= 0;
  for(int i=0;i<t;i++){
    int s;
    cin>> s;
    ma=max(s,ma);
  }
  cout << max(0,ma - ((n-ma)+1));
}


Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG

#include<bits/stdc++.h>
#define PI 3.14159265359
using namespace std;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
const int INF= 1e9+5;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll> >vvl;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> T;
const ll MOD=1000000007LL;
string abc="abcdefghijklmnopqrstuvwxyz";
string ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
int main(){
  ll n,m;cin>>n>>m;
  map<ll,ll>M;
  vl a(n);
  rep(i,n){
    cin>>a[i];
    M[a[i]]++;
  }
  vl b(m),c(m);
  rep(i,m){
    cin>>b[i]>>c[i];
    M[c[i]]+=b[i];
  }
  vector<P>vec;
  for(auto p:M){
    vec.push_back(make_pair(p.first,p.second));
  }
  reverse(vec.begin(),vec.end());
  ll ans=0;
  ll count=0;
  for(auto k:vec){
    //cout<<k.first<<" "<<k.second<<endl;
  }
  for(auto t:vec){
    if(count+t.second<=n){
      ans+=t.second*t.first;
      count+=t.second;
    }
    else {
      ans+=(n-count)*t.first;
      break;
    }
  }
  cout<<ans<<endl;
}
      
  
  
  
      
    
    
  

Measured memory_bytes: 20464
import string
S = input()
if len(S) == 26:
    if S == "zyxwvutsrqponmlkjihgfedcba":
        print(-1)
    else:
        i = len(S) - 1
        while 0 <= i:
            if S[i-1] < S[i]:
                break
            i -= 1
        ans = ""
        for x in range(i):
            ans += S[x]

        for j in S[i:][::-1]:
            if ans[-1] < j:
                ans = ans[:-1] + j
                break

        print(ans)

    exit()

chars_set = set(S)
for c in string.ascii_lowercase:
    if c not in chars_set:
        S += c
        break
print(S)

Measured memory_bytes: 3768
#include <iostream>
#include <fstream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <utility>
#include <map>
#include <set>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <functional>
#include <sstream>
#include <cstring>
#include <bitset>
#include <stack>
using namespace std;
#define MP make_pair
#define PB push_back
const int INF=1e9;

int n,e,t,pos;
long long a[100005];
long long dp[100005],cur;

int main()
{
	cin>>n>>e>>t;
	for (int i=1;i<=n;i++) cin>>a[i];
	dp[0]=0;
	cur=1e18;
	pos=0;
	for (int i=1;i<=n;i++)
	{
		while (t<=2*(a[i]-a[pos+1]))
		{
			cur=min(cur,dp[pos]-2*a[pos+1]);
			pos++;
		}
		dp[i]=min(cur+2*a[i],dp[pos]+t);
	}
	cout<<dp[n]+e;
	return 0;
}

Measured memory_bytes: 1792