akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#include<stdlib.h>

#define MAX 256
int main(){
    int mountain[10];
    int i,j,tmp;
    char str[MAX];

    /* input */
    for(i = 0; i<=9; i++)
    {
        fgets(str, MAX, stdin);
        mountain[i] = atoi(str);
    }

    /* sorting(bubble) */
    for(i = 0; i<=8; i++)
    {
        for(j = 9; j > i; j--)
        {
            if(mountain[j-1] < mountain[j])
            {
                tmp = mountain[j-1];
                mountain[j-1] = mountain[j];
                mountain[j] = tmp;
            }
        }
    }

    /* output */
    for(i = 0; i<=2; i++)
    {
        printf("%i\n",mountain[i]);
    }

    return 0;
}

Measured memory_bytes: 528
#include<bits/stdc++.h>
using namespace std;
int main(){
	int a,b,c,t7=0;
	scanf("%d%d%d",&a,&b,&c);
	if(a==7) t7++;
	if(b==7) t7++;
	if(c==7) t7++;
	if(t7==1) printf("YES");
	else printf("NO");
}

Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<stdio.h>
#include <ctype.h>
#include<iomanip>
#include<algorithm>
#include<string>
#include<stack>
#include<set>
#include<map>
#include<deque> //<< fixed << setprecision()
#include<queue> //priority_queue
#include<vector>
typedef long long ll;
using namespace std;
const double pi = (2 * acos(0));

typedef tuple<int, int, int> line;

struct point
{
	long double x, y;
};
double area(int x1, int y1, int x2, int y2, int x3, int y3)
{
	double a = (x2*y3) - (x3*y2) - (x1*y3) + (x3*y1) + (x1*y2) - (x2*y1);
	a /= 2;
	return fabs(a);
}

long double anyarea(point p[], int n)
{
	long double sum1 = p[n - 1].x * p[0].y, sum2 = p[n - 1].y * p[0].x;
	for (int i = 0; i < n - 1; i++)
	{
		sum1 += p[i].x * p[i + 1].y;
		sum2 += p[i].y * p[i + 1].x;
	}
	return  fabs((sum1 - sum2) * 0.5);
}

ll fastpow(ll base, ll p, ll m)
{
	if (p == 0)
		return 1;
	ll ans = fastpow(base, p / 2, m);
	ans = ((ans%m)*(ans%m)) % m;
	if (p % 2)
		ans = ((base%m)*ans) % m;
	return ans;
}
ll GCD(ll M, ll m)
{
	if (M%m == 0)
		return m;
	M %= m;
	ll x1 = M, x2 = m;
	m = min(x1, x2);
	M = max(x1, x2);
	return GCD(M, m);

	
}
ll lcm(ll M, ll m)
{
	return (M*m) / GCD(max(M, m), min(M, m));

}

int main()
{
	int n;
	int h[100005], ans[100005] = {};
	cin >> n;
	for (int i = 0; i < n; i++)
	{
		cin >> h[i];
	}
	ans[1] = abs(h[0] - h[1]);

	for (int i = 2; i < n; i++)
	{
		ans[i] = min(ans[i - 1] + abs(h[i] - h[i - 1]), ans[i - 2] + abs(h[i] - h[i - 2]));
	}
	cout << ans[n - 1];
/*

	int n,k;
	int h[100005], ans[100005] = {};
	cin >> n>>k;
	for (int i = 0; i < n; i++)
	{
	cin >> h[i];
	}
	ans[1] = abs(h[0] - h[1]);

	for (int i = 2; i < n; i++)
	{
		int ans1 = 100000000;
		for (int j = 1; j < min(i, k); i++)
		{
			ans1 = min(ans1, abs(h[i] - h[i - j]) + ans[i - j]);
		}
		ans[i] = ans1;
	}
	cout << ans[n - 1];




	*/




}

Measured memory_bytes: 1024
#define PROBLEM "http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=DPL_5_L"

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

#define call_from_test
#ifndef call_from_test
#include<bits/stdc++.h>
using namespace std;
#endif
//BEGIN CUT HERE
template<typename T,T MOD = 1000000007>
struct Mint{
  static constexpr T mod = MOD;
  T v;
  Mint():v(0){}
  Mint(signed v):v(v){}
  Mint(long long t){v=t%MOD;if(v<0) v+=MOD;}

  Mint pow(long long k){
    Mint res(1),tmp(v);
    while(k){
      if(k&1) res*=tmp;
      tmp*=tmp;
      k>>=1;
    }
    return res;
  }

  static Mint add_identity(){return Mint(0);}
  static Mint mul_identity(){return Mint(1);}

  Mint inv(){return pow(MOD-2);}

  Mint& operator+=(Mint a){v+=a.v;if(v>=MOD)v-=MOD;return *this;}
  Mint& operator-=(Mint a){v+=MOD-a.v;if(v>=MOD)v-=MOD;return *this;}
  Mint& operator*=(Mint a){v=1LL*v*a.v%MOD;return *this;}
  Mint& operator/=(Mint a){return (*this)*=a.inv();}

  Mint operator+(Mint a) const{return Mint(v)+=a;}
  Mint operator-(Mint a) const{return Mint(v)-=a;}
  Mint operator*(Mint a) const{return Mint(v)*=a;}
  Mint operator/(Mint a) const{return Mint(v)/=a;}

  Mint operator-() const{return v?Mint(MOD-v):Mint(v);}

  bool operator==(const Mint a)const{return v==a.v;}
  bool operator!=(const Mint a)const{return v!=a.v;}
  bool operator <(const Mint a)const{return v <a.v;}

  static Mint comb(long long n,int k){
    Mint num(1),dom(1);
    for(int i=0;i<k;i++){
      num*=Mint(n-i);
      dom*=Mint(i+1);
    }
    return num/dom;
  }
};
template<typename T,T MOD> constexpr T Mint<T, MOD>::mod;
template<typename T,T MOD>
ostream& operator<<(ostream &os,Mint<T, MOD> m){os<<m.v;return os;}
//END CUT HERE
#ifndef call_from_test

//INSERT ABOVE HERE
signed ABC127_E(){
  cin.tie(0);
  ios::sync_with_stdio(0);

  int h,w,k;
  cin>>h>>w>>k;
  using M = Mint<int>;

  M ans{0};
  for(int d=1;d<h;d++)
    ans+=M(d)*M(h-d)*M(w)*M(w);

  for(int d=1;d<w;d++)
    ans+=M(d)*M(w-d)*M(h)*M(h);

  ans*=M::comb(h*w-2,k-2);
  cout<<ans<<endl;
  return 0;
}
/*
  verified on 2019/06/12
  https://atcoder.jp/contests/abc127/tasks/abc127_e
*/

signed main(){
  //ABC127_E();
  return 0;
}
#endif

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

#endif
//BEGIN CUT HERE
// put n identical balls into k identical boxes
template<typename M>
struct Partition{
  vector< vector<M> > dp;
  Partition(int h,int w):dp(h+1,vector<M>(w+1,0)){
    dp[0][0]=M(1);
    for(int i=0;i<=h;i++){
      for(int j=1;j<=w;j++){
        dp[i][j]=dp[i][j-1];
        if(i-j>=0) dp[i][j]+=dp[i-j][j];
      }
    }
  }
  M operator()(int n,int k){
    return dp[n][k];
  }
};
//END CUT HERE

#ifndef call_from_test
signed main(){
  return 0;
}
#endif

#undef call_from_test

signed main(){
  int n,k;
  scanf("%d %d",&n,&k);
  Partition<Mint<int>> P(n,k);
  printf("%d\n",k<=n?P(n-k,k).v:0);
  return 0;
}



Measured memory_bytes: 6796
#include <bits/stdc++.h>
#define pb push_back
#define F first
#define S second
#define all(x) x.begin(), x.end()
using namespace std;
typedef long long ll; 
typedef long double ld;
typedef pair<ll, ll> pll;

const ll N = 2e5 + 30, Mod = 1e9 + 7;
const ll SQ = 330;
const ll L  = 0;
const ll G = 1e7;

ll n, k, a[N];
map<ll, ll> Fen;
ll ps[N], rem[N];

void Add(ll x) {
	x += L;
	for (; x < G; x += x & -x) {
		Fen[x] ++;
	}
}
ll Get(ll x) {
	x += L;
	ll res = 0;
	for (; x; x ^= x & -x) {
		res += Fen[x];
	}
	return res;
}
int main () {
	ios::sync_with_stdio(0), cin.tie(0);
	cin >> n >> k;
	for (int i = 1; i <= n; i ++) {
		cin >> a[i];
		ps[i] = ps[i - 1] + a[i];
	}
	ll ans = 0;
	vector<ll> vec;
	for (int i = 0; i <= n; i ++) {
		rem[i] = ps[i] - k * i;
		vec.pb(rem[i]);
	}
	sort(all(vec));
	vec.resize(unique(all(vec)) - vec.begin());
	for (int i = 0; i <= n; i ++) {
		rem[i] = lower_bound(all(vec), rem[i]) - vec.begin();
		rem[i] += 5;
	}
	for (int i = 0; i <= n; i ++) {
		ans += Get(rem[i]);
		Add(rem[i]);
	}
	cout << ans;
	
}

Measured memory_bytes: 19056
def main():
    n = int(input())
    a=list(map(int,input().split(' ')))
    b=list(map(int,input().split(' ')))
    c=list(map(int,input().split(' ')))
    ans = 0
    tmp = a[0]
    for i in range(n):
        if tmp +1 == a[i]:
            ans += b[a[i]-1]+c[a[i]-2]
        else:
            ans += b[a[i]-1]
        tmp = a[i]
    print(ans)

if __name__ == '__main__':
    main()

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

int main() {
  int N; cin >> N;
  vector<vector<pair<int, int>>> W(N);
  for (int i = 0; i < N; i++) {
    int A; cin >> A;
    for (int j = 0; j < A; j++) {
      int x, y;
      cin >> x >> y;
      x--;
      W.at(i).push_back(make_pair(x, y));  // i 番が証言
    }
  }
  int ans = 0;
  for (int tmp = 0; tmp < (1 << N); tmp++) {
    bitset<16> s(tmp);
    int honest = 0;
    vector<int> P(N);  // ホント・ウソ仮定
    for (int i = 0; i < N; i++) {
      if (s.test(i)) {
        P.at(i) = 1;
        honest++;
      }
      else P.at(i) = 0;
    }
    bool ok = true;
    for (int i = 0; i < N; i++) {
      for (auto p : W.at(i)) {
        if (P.at(i) == 1) {
          if (P.at(p.first) == p.second) continue;
          else ok = false;
        }
      }
    }
    if (ok) ans = max(ans, honest);
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
ll ans = 0;
ll h , w ;
bool inarea(ll x,ll y){
  return x >= 0 && y >= 0 && x < w && y < h ;
}

int main()
{
cin >> h >> w ;
vector<vector<char>> v(h, vector<char>(w,0) );
rep(i,h)rep(j,w)cin >> v[i][j];

rep(i,h)rep(j,w){
  if(v[i][j]=='#')continue;
  vector<vector<ll>> vv(h, vector<ll>(w,-1));
  queue<pair<ll,ll>> q;
  vv[i][j]=0;
  q.push(make_pair(i,j));
  while(!q.empty()){
    auto r=q.front();
    q.pop();
    ll y=r.first,x=r.second;
    ll xx[4]={0,1,0,-1};
    ll yy[4]={1,0,-1,0};
    rep(kk,4){
      if(inarea(x+xx[kk],y+yy[kk])&&v[y+yy[kk]][x+xx[kk]]=='.'&&vv[y+yy[kk]][x+xx[kk]]==-1){
        vv[y+yy[kk]][x+xx[kk]]=vv[y][x]+1;
        ans=max(ans,vv[y+yy[kk]][x+xx[kk]]);
        q.push(make_pair(y+yy[kk],x+xx[kk]));
      }
    }
  }
}
cout << ans << endl;
return 0;
}

Measured memory_bytes: 256
n = int(input())
l = list(map(int, input().split()))

total = 0
ans1 = 0
ans2 = 0

for i, j in enumerate(l):
    total += j
    if i % 2 == 1:
        if total <= 0:
            ans1 += 1 + abs(total)
            total = 1
    else:
        if total >= 0:
            ans1 += 1 + abs(total)
            total = -1

total = 0

for i, j in enumerate(l):
    total += j
    if i % 2 == 0:
        if total <= 0:
            ans2 += 1 + abs(total)
            total = 1
    else:
        if total >= 0:
            ans2 += 1 + abs(total)
            total = -1

print(min(ans1, ans2))


Measured memory_bytes: 14468
#include<cstdio>
#include<iostream>
#include<cstring>

using namespace std;

string str;
int len;

int main(){
	cin>>str;
	len=str.size();
	for (int i=0;i<len;++i){
		if ((i+1)%2==1){
			cout<<str[i];
		}
	}
	return 0;
}

Measured memory_bytes: 512
import java.util.Scanner;

public class Main{

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ

		Scanner sc=new Scanner(System.in);
		String S=sc.next();
		String ARC="ARC";
		String ABC="ABC";
		
		if(S.equals(ARC)) {
			System.out.println(ABC);
		}else if(S.equals(ABC)){
			System.out.println(ARC);
		}
	}

}


Measured memory_bytes: 35608
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
//--<for debugging>
#define whatis(x) cout << #x << " is " << x<<" ";
#define whatisl(x) cout << #x << " is " << x<<"\n";
#define parr(array,end)for(ll loop=0;loop<end;loop++)cout<<array[loop]<<" ";cout<<"\n";
#define lline cout<<"\n";
#define errorl(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args);cout<<"\n";}
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args);cout<<"___";}
    
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
    cout << *it << " = " << a <<" , ";
    err(++it, args...);
}
//--</for debugging> 
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define testcase ll tt; cin >> tt; while(tt--)
#define boost ios_base::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back 
#define vars ll h,i,j,k,d,l,p,q,r,x,y,a,b,c,v,var,n,m,z,s,ans,ind1,ind2,flag,limit1,limit2,limit3,mod;
#define vll vector<ll>
#define pll pair<ll,ll>
#define sll set<ll>
#define pint pair<int,int>
const ll INF=1e9+7;
const ll MOD=1e9+7;
int main()
{
    boost vars
    cin>>a>>b>>c>>d;
    s=c/b;
    if(c%b)s++;
    z=a/d;
    if(a%d)z++;
    if(s<=z)cout<<"Yes";
    else cout<<"No";
}

Measured memory_bytes: 3652
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        final Scanner sc = new Scanner(System.in);
        final long a = sc.nextLong();
        final long b = sc.nextLong();
        final long c = sc.nextLong();
        final long x = sc.nextInt();
        final long y = sc.nextInt();

        if ((a + b) <= c * 2) {
            System.out.println(a * x + b * y);
            return;
        }

        long numReplace = Math.min(x, y);
        long x1 = x - numReplace;
        if (x1 < 0) x1 = 0;
        long y1 = y - numReplace;
        if (y1 < 0) y1 = 0;
        long half1 = numReplace * 2;
        long sum1 = a * x1 + b * y1 + c * half1;

        long numReplace2 = Math.max(x, y);
        long x2 = x - numReplace2;
        if (x2 < 0) x2 = 0;
        long y2 = y - numReplace2;
        if (y2 < 0) y2 = 0;
        long half2 = numReplace2 * 2;
        long sum2 = a * x2 + b * y2 + c * half2;


        long answer = Math.min(sum1, sum2);
        System.out.println(answer);
    }
}


Measured memory_bytes: 21844
n = int(input())

ac = 0
wa = 0
tle = 0
re = 0
for i in range(n):
    temp = input()
    if(temp == "AC"):
        ac += 1
    elif(temp == "WA"):
        wa += 1
    elif(temp == "TLE"):
        tle += 1
    else:
        re += 1




print("AC x", ac)
print("WA x", wa)
print("TLE x", tle)
print("RE x", re)

Measured memory_bytes: 69808
def bin_search(arr, i):
    left = 0 
    right = len(arr) - 1
    while left <= right:
        mid = (left + right) //2
        if arr[mid] == i:
            return True
        elif arr[mid] < i:
            left = mid + 1
        else:
            right = mid - 1
        
    return False
n = int(input())
S = list(map(int, input().split()))
n = int(input())
T = list(map(int, input().split()))
ans = 0
for i in T:
    if bin_search(S, i) is True:
        ans += 1

print(ans)


Measured memory_bytes: 16712
k=int(input())
mal=1      
n=list(map(int,input().split()))
      
          
for i in range(0,len(n)):
    mal=mal*n[i]
    if(mal>10**18):
            mal=-1
            break
for j in range(0,len(n)):
    if(n[j]==0):
        mal=0
print(mal)        
        
           


Measured memory_bytes: 21652
#include <iostream>
#include <sstream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>
 
using namespace std;
 
#define FOR(i,k,n) for(int i=(k); i<(int)(n); ++i)
#define REP(i,n) FOR(i,0,n)
#define FORIT(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
 
template<class T> void debug(T begin, T end){ for(T i = begin; i != end; ++i) cerr<<*i<<" "; cerr<<endl; }
inline bool valid(int x, int y, int W, int H){ return (x >= 0 && y >= 0 && x < W && y < H); }
 
typedef long long ll;
const int INF = 100000000;
const double EPS = 1e-8;
const int MOD = 1000000007;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
int edit_dist(const string& s, const string& t){
  int l1 = s.size();
  int l2 = t.size();
  int dp[32][32] = {};
  REP(i, l1) dp[i + 1][0] = i + 1;
  REP(j, l2) dp[0][j + 1] = j + 1;
  REP(i, l1) {
    REP(j, l2){
      if(s[i] == t[j]) dp[i + 1][j + 1] = dp[i][j];
      else dp[i + 1][j + 1] = min(dp[i][j], min(dp[i + 1][j], dp[i][j + 1])) + 1;
    }
  }
  return dp[l1][l2];
}
bool check(string s, string t, int D){
  if(D == 0){
    if(s == t) return true;
  }else if(D == 1){
    if(edit_dist(s, t) <= 1) return true;
    if(s.size() == t.size()) REP(i, s.size() - 1){
      swap(s[i], s[i + 1]);
      if(s == t) return true;
      swap(s[i], s[i + 1]);
    }
  }else if(D == 2){
    if(edit_dist(s, t) <= 2) return true;
    REP(i, s.size() - 1){
      swap(s[i], s[i + 1]);
      if(edit_dist(s, t) <= 1) return true;
      if(s.size() == t.size()) REP(k, s.size() - 1) {
        swap(s[k], s[k + 1]);
        if(s == t) return true;
        swap(s[k], s[k + 1]);
      }
      swap(s[i], s[i + 1]);
    }
    REP(i, s.size() - 2){
      string ss = s.substr(0, i) + s[i + 2] + s[i] + s.substr(i + 3);
      if(ss == t) return true;
    }
  }else {
    assert(false);
  }
  return false;
}
int main(){
  int N, D;
  while(cin >> N >> D && N){
    vector<string> name(N);
    REP(i, N) cin >> name[i];
    vector< pair<string, string> > ans;
    REP(i, N) FOR(j, i + 1, N){
      if(check(name[i], name[j], D)) ans.push_back(make_pair( min(name[i], name[j]), max(name[i], name[j]) ));
    }
    sort(ans.begin(), ans.end());
    REP(i, ans.size()){
      printf("%s,%s\n", ans[i].first.c_str(), ans[i].second.c_str());
    }
    printf("%d\n", (int)ans.size());
  }
  return 0;
}

Measured memory_bytes: 1256
#include <iostream>
#include <string>

int main()
{
    std::string s;
    std::cin >> s;
    int start,end;
    for(int i = 0; i < s.size(); i++){
        if(s[i] == 'A') {
            start = i;
            break;
        }
    }
    for(int j = s.size(); j >= 0; j--){
        if(s[j] == 'Z'){
            end = j;
            break;
        }
    }

    std::cout << end - start +1;
    return 0;
}




Measured memory_bytes: 832
#include <bits/stdc++.h>
using namespace std;
# define ll long long int
int main(){
	ios::sync_with_stdio(false);
  	cin.tie(0);
  	ll n,i,p,k;
  	cin>>n>>k;
  	vector<ll>v(n),a(n);
  	for(i=0;i<n;i++){
  		a[i]=1e18;
	  }a[0]=0;
  	for(i=0;i<n;i++){
  		cin>>v[i];
	  }for(i=0;i<n;i++){
	  	for(p=1;p<=k;p++){
	  		if(i+p<n){
	  			a[i+p]=min(a[i+p],a[i]+abs(v[i]-v[i+p]));
			  }
		  }
	  }//for(i=0;i<n;i++)	cout<<a[i]<<" ";
	  cout<<a[n-1];
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define IO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define ll long long
#define pii pair<int, int>

using namespace std;

int main() {
    //freopen("output.txt", "w", stdout);
    int n; cin >> n; 
    string s; cin >> s;
    int rs = 0, ws = 0;
    for (auto i: s) {
        if (i == 'R') rs++;
        else ws++;
    }
    int cnt = 0;
    for (int i=0; i<rs; i++) if (s[i] == 'W') cnt++;

    cout << cnt << endl;
}

Measured memory_bytes: 3752
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner input=new Scanner (System.in);
        int n=input.nextInt();
     	ArrayList <Integer>ind=new <Integer>ArrayList();
   		int q=input.nextInt();
        System.out.flush();
     	String str=input.next();
        
        int max=0;
        int co=0;
        int arr[]=new int[n];
        arr[0]=0;
        for(int i=1;i<n;i++)
        {
            if(str.charAt(i-1)=='A'&& str.charAt(i)=='C')
            {
                ind.add(i);
                co++;
                arr[i]=co;
            }
            else
                arr[i]=co;
        }
        for(int i=0;i<q;i++)
        {
            int l=input.nextInt();
            int r=input.nextInt();
            int count=arr[r-1]-arr[l-1];

            System.out.println(count);
        }
    }
}


Measured memory_bytes: 66812
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <complex>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000
#define sz(x) ((int)(x).size())
#define fi first
#define sec second
#define SORT(x) sort((x).begin(),(x).end())
#define all(x) (x).begin(),(x).end()
#define EQ(a,b) (abs((a)-(b))<EPS)
int f[110][110];
int n;
int calc(int a,int b,int c,int d)
{
	return f[c][d]-f[c][b-1]-f[a-1][d]+f[a-1][b-1];
}
int main()
{
	cin >> n;
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=n;j++)
		{
			cin >> f[i][j];
		}
	}
	for(int i=1;i<=n;i++)
	{
		for(int j=2;j<=n;j++)
		{
			f[i][j]+=f[i][j-1];
		}
	}
	for(int j=1;j<=n;j++)
	{
		for(int i=2;i<=n;i++)
		{
			f[i][j]+=f[i-1][j];
		}
	}
	int ans=-INF;
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=n;j++)
		{
			for(int l=1;l<=i;l++)
			{
				for(int m=1;m<=j;m++)
				{
					ans=max(ans,calc(l,m,i,j));
				}
			}
		}
	}
	cout << ans << endl;
	return 0;
}

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

int main() {
	ll n,j,r,sum=0;
	cin>>n;
	j=n;
	while(j>0){
		sum+=j%10;
		j/=10;
	}
	if(n%sum==0)
	cout<<"Yes"<<endl;
	else
	cout<<"No"<<endl;
	return 0;
}

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

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

    for(int i=1; i<=n; ++i) {
        int x = i;
        if (x % 3 == 0) {
            cout << " " << i;
            continue;
        }
        if (x % 10 == 3) {
            cout << " " << i;
            continue;
        }

        bool flag = true;
        while(flag) {
            x /= 10;
            if (x) {
                if (x % 10 == 3) {
                    cout << " " << i;
                    flag = false;
                }
            } else {
                flag = false;
            }
        }
    }

    cout << endl;
    return 0;
}


Measured memory_bytes: 3100
#include <bits/stdc++.h>
using namespace std;
#define all(c) c.begin(),c.end()
#define init(c) memset(c,0,sizeof c)
#define S second
#define F first
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
const int N=20000005;
int n,k,x,t,a,b,m;
string s;
vi v;
int main(){

	cin >> n>>k;
	for(int i =0;i<n;i++){
		cin >> x;
		v.push_back(x);
	}
	vi dp;
	dp.resize(n+5,1e9);
	dp[0]=0;
	for(int i =0;i<n;i++){
		if(dp[i]==1e9)continue;
		for(int j=1;i+j<n&&j<=k;j++){
			dp[i+j]=min(dp[i]+abs(v[i]-v[i+j]),dp[i+j]);
		}
	}
	cout << dp[n-1];

	
	return 0;
}

Measured memory_bytes: 1144
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<string>
using namespace std;
typedef pair<int,int> P;
typedef pair<string,P> P2;
P2 mk_sp(int a,int b){
  return P2("split",P(a,b));
}
P2 mk_jn(int a,int b){
  return P2("join",P(a,b));
}

void que_debug(queue<int> q){
  while(!q.empty()){
    cout<<q.front();
    q.pop();
  }
  cout<<endl;
}
int main(){
  int q;
  cin>>q;
  vector<string> sq;
  for(int i=0;i<q;i++){
    string s;
    cin>>s;
    sq.push_back(s);
  }
  for(int pr=0;pr<q;pr++){
    vector<P2> ans;
    string s=sq[pr];
    int n=s.length();
    if(n==1){
  //    cout<<sq[pr]<<endl;;
      cout<<(s[0]=='o'?0:-1)<<endl;
      continue;
    }
    else if(n==2){
  //    cout<<sq[pr]<<endl;
      cout<<((s[0]==s[1]&&s[1]=='x')?"-1":"0")<<endl;
      continue;
    }
    int ok=0,xk=0;
    for(int i=0;i<n;i++){
      if(s[i]=='o') ok++;
      else xk++;
    }
    if(ok<xk){
    //  cout<<sq[pr]<<endl;
      cout<<-1<<endl;
      continue;
    }
    else if(ok==xk){
      bool f=true;
      for(int i=0;i<n;i+=2){
        if(s[i]==s[i+1]){
          f=false;
          break;
        }
      }
      if(f){
        int m=0;
        for(int i=n-3;i>=1;i-=2){
          ans.push_back(mk_sp(m,1));
          m+=2;
        }
      }
      else{
    //    cout<<sq[pr]<<endl;
        cout<<-1<<endl;
        continue;
      }
    }
    else{
      int m=0;
      while(xk>0){
        if(s[0]!=s[1]){
        //  cout<<"split "<<m<<" "<<1<<endl;
          ans.push_back(mk_sp(m,1));
          m+=2;
          ok--;
          xk--;
          s=s.substr(2,s.length()-2);
        //  cout<<s<<endl;
        }
        else if(s[0]=='o'){
          ans.push_back(mk_sp(m,0));
        //  cout<<"split "<<m<<" "<<0<<endl;
          m+=2;
          ans.push_back(mk_jn(m,m-1));
        //  cout<<"join "<<m<<" "<<m-1<<endl;
          m++;
          s=s.substr(1,s.length()-1);
          s+='o';
        //  cout<<s<<endl;
        }
        else{
          int ko=0,kx=1;
          for(int i=1;i<s.length()-1;i++){
            if(s[i]=='o') ko++;
            else kx++;
            if(ko>=kx&&s[i+1]=='o'&&(ok-ko)>=(xk-kx)){
              ans.push_back(mk_sp(m,i));
            //  cout<<"split "<<m<<" "<<i<<endl;
              m+=2;
              ans.push_back(mk_jn(m,m-1));
            //  cout<<"join "<<m<<" "<<m-1<<endl;
              m++;

              string s1=s.substr(0,i+1);
              s=s.substr(i+1,s.length()-(i+1));
              s+=s1;
              //cout<<s<<" "<<ko<<" "<<kx<<endl;
              break;
            }
          }
        }
      }
      //cout<<s<<endl;
      while(s.length()>2){
        ans.push_back(mk_sp(m,0));
        m+=2;
        s=s.substr(0,s.length()-1);
      }
    }
  //  cout<<sq[pr]<<endl;
    cout<<ans.size()<<endl;
    for(int i=0;i<ans.size();i++) cout<<ans[i].first<<" "<<ans[i].second.first<<" "<<ans[i].second.second<<endl;
  }
}



Measured memory_bytes: 3200
#include <bits/stdc++.h>
typedef long long int lint;

#define PI acos(-1)
#define INF64 1LL << 60
#define INF32 1 << 29
#define all(a) (a).begin(), (a).end()
#define INV ((long long int)1000000007)

using namespace std;

void execute()
{
	int N;
	cin >> N;

	priority_queue<lint> data;
	for (int i = 0; i < N; i++)
	{
		lint tmp;
		cin >> tmp;
		data.push(tmp);
	}

	lint side = 0;
	lint ans = 0;
	for (; !data.empty();)
	{
		lint current = data.top();
		data.pop();
		if (data.empty())
		{
			break;
		}
		if (current == data.top())
		{
			if (side == 0)
			{
				side = data.top();
			}
			else
			{
				ans = side * data.top();
				break;
			}
			data.pop();
		}
	}
	cout << ans << endl;
	return;
}

int main()
{
	cin.tie(0);
	ios_base::sync_with_stdio(false);
	std::cout << std::fixed << std::setprecision(15);
	execute();

	int stop;
	cin >> stop;

	return 0;
}

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

int main() {
  string a,b;
  cin >> a >> b;
  int N = b.size();
  for (int i=0; i<N; i++) {
    cout << a[i] << b[i];
  }
  if (a.size() != b.size()) {
    cout << a[N];
  }
  cout << endl;
}

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

long long a;

string b;

int main() {
	cin >> a >> b;
	int c = (b[0] - '0') * 100 + (b[2] - '0') * 10 + b[3] - '0';
	cout << a * c / 100 << endl;

}


Measured memory_bytes: 3580
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, srt, end) for (long long i = (srt); i < (long long)(end); i++)
#define VL vector<ll>
ll N,R;
int main(){
    cin>>N>>R;
    if(N>=10){
        cout<<R;
        return 0;
    }else{
        cout<<R+(100*(10-N));
        return 0;
    }
    
}

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

#define ll long long int

using namespace std;

int main() {
    ll n;
    cin >> n;
    vector<ll> A(n);
    for (auto & a : A) cin >> a;

    vector<bool> used(1000000 + 1, false);
    vector<bool> available(1000000 + 1, true);

    for (auto a : A) {
        if (used[a]) {
            available[a] = false;
            continue;
        }
        used[a] = true;

        ll t = a * 2;
        while (t <= 1000000) {
            available[t] = false;
            t += a;
        }
    }

    ll res = 0;
    for (auto a : A) {
        if (available[a]) ++res;
    }

    cout << res << endl;
}


Measured memory_bytes: 5108
use proconio::input;
#[allow(unused_imports)]
use proconio::marker::*;

fn main() {
    input! {
        n: usize,
        k: i64,
        a: [Usize1; n],
    }
    let mut t = vec![None; n];
    let mut x = 0;
    let mut l = 0;
    while l < k {
        if let Some(t) = t[x] {
            let d = l - t;
            // println!("aa {} {} {}", x + 1, l, d);
            if k - l > d {
                l += (k - l) / d * d + 1;
            } else {
                l += 1;
            }
        } else {
            t[x] = Some(l);
            l += 1;
        }
        if l <= k {
            x = a[x];
        }
        // println!("{:?}", t);
        // println!("{} {}", x + 1, l);
    }
    println!("{}", x + 1);
}


Measured memory_bytes: 8004
#include <bits/stdc++.h>
using namespace std;
int main() {
  string s;
  cin >> s;
  for (int i = s.size()/2-1; i>0; i--) {
    if (s.substr(0,i) == s.substr(i,i)) {
      cout << i * 2 << endl;
      return 0;
    }
  }
}


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

int main()
{
    string str;
    cin>>str;
    ll n = str.length()+1;

    ll a[n] = {0};
    for(ll i=0;i<(n-1);i++)
    {
        if(str[i] == '<')
        {
            a[i+1] = a[i] + 1;
        }
    }

    for(ll i=n-2;i>=0;i--)
    {
        if(str[i] == '>')
        {
            a[i] = max(a[i],a[i+1]+1);
        }
    }

    //for(ll i=0;i<n;i++) cout<<a[i]<<" ";
    //cout<<"\n";

    ll sum = 0;
    for(ll i=0;i<n;i++) sum += a[i];
    cout<<sum;
    return 0;
}


Measured memory_bytes: 4740
/*
これを入れて実行
g++ code.cpp
./a.out
 */
 
#include <iostream>
#include <stdio.h>
#include <vector>
#include <string>
#include <cstring>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <cmath>
#include <math.h>
#include <tuple>
#include <iomanip>
#include <bitset>
#include <functional>
#include <cassert>
#include <random>

#define all(x) (x).begin(),(x).end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
 
using namespace std;
typedef long long ll;
typedef long double ld;
 
int dy4[4] = {-1, 0, +1, 0};
int dx4[4] = {0, +1, 0, -1};
int dy8[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
int dx8[8] = {0, 1, 1, 1, 0, -1, -1, -1};
 
const long long INF = 1LL << 60;
const ll MOD = 1e9 + 7;
 
bool greaterSecond(const pair<int, int>& f, const pair<int, int>& s){
    return f.second > s.second;
}
 
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 conbinationMemo[100][100];

void cmemoInit(){
    rep(i, 100){
        rep(j, 100){
            conbinationMemo[i][j] = -1;
        }
    }
}
 
ll nCr(ll n, ll r){
    if(conbinationMemo[n][r] != -1) return conbinationMemo[n][r];
    if(r == 0 || r == n){
        return 1;
    } else if(r == 1){
        return n;
    }
    return conbinationMemo[n][r] = (nCr(n - 1, r) + nCr(n - 1, r - 1));
}
 
ll nPr(ll n, ll r){
    r = n - r;
    ll ret = 1;
    for (ll i = n; i >= r + 1; i--) ret *= i;
    return ret;
}
//-----------------------ここから-----------
int main(void){
    ll n;
    cin >> n;
    vector<ll> a(n);
    rep(i, n) {
        cin >> a[i];
    }
    ll g = a[0];
    for(ll i = 1; i < n; i++){
        g = gcd(g, a[i]);
    }

    if(g != 1){
        cout << "not coprime" << endl;
        return 0;
    }
    bool f = true;
    vector<ll> mp(1e6 + 1, 0);
    for(ll i = 0; i < n; i++){
        ll num = a[i];
        for(ll j = 2; j * j <= a[i]; j++){
            if(num % j == 0){
                if(mp[j] > 0){
                    cout << "setwise coprime" << endl;
                    return 0;
                }
                mp[j]++;
            }
            while(num % j == 0){
                num /= j;
            }
        }
        if(num == 1) continue;
        if(mp[num] > 0){
            cout << "setwise coprime" << endl;
            return 0;
        }
        mp[num]++;
    }
    cout << "pairwise coprime" << endl;
}   

Measured memory_bytes: 18768
#include<bits/stdc++.h>
#include<iostream>
#include<vector>
#include<math.h>
#include<iomanip>
#include<string>
#include<algorithm>
#include<numeric>
#include<utility>
#define ll long long
#define endl "\n"
#define ss string
using namespace std;
/*ll  mod(ll  a,ll  b)
{
  if(a>b)
    return (a-b);
  else
    return (b-a);
}
double distance(ll  x1, ll  y1, ll  x2, ll  y2)
{

    return sqrt(pow(x2 - x1, 2) +
                pow(y2 - y1, 2) * 1.0);
}*/

int main()
{
  /*ll t;
  cin>>t;
  while(t--)
  {
    ll n,q;
    cin>>n>>q;
    ss s;
    cin>>s;
    ss s2=s;
    ss s3=s;
    ll arr[q];
    for(int i=0;i<q;i++)
    {
      cin>>arr[i];
    }
    for(ll i=0;i<q;i++)
    {

      ss s1;
      for(ll j=0;j<s.size();)
      {
        if(count(s1.begin(),s1.end(),s[j])<=arr[i])
       {
         s1.push_back(s[j]);
         s.erase(s.begin()+j);
       }
       cout<<s1<<" "<<s<<endl;

      }
      cout<<s1<<endl;
      cout<<s.size()<<endl;
        s1.clear();
       s2=s3;
       s=s3;
    }*/
    ll n;
    cin>>n;
    ll x=100;
    ll i;
    for( i=0;x<n;i++)
    {
      x=x+(x/100);
    }
    cout<<i;



  return 0;
}


Measured memory_bytes: 3636
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<iostream>
#include<queue>
#include<vector>
#include <bitset>
using namespace std;
#define INF 110000000000
#define MAX 100000
typedef long long ll;
typedef pair<ll,int> P;

int N,p[51];

int main(){
  cin>>N;
  for(int i=1;i<=N;i++) cin>>p[i];
  int count=0;
  for(int i=1;i<=N;i++){
    if(p[i]!=i) count++; 
  }
  if(count<=2) cout<<"YES"<<endl;
  else cout<<"NO"<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#define rep(i, n) for(int i = 0; i < n; i++)
#define repr(i, n) for(int i = n;i >= 0;i--)
 
int main() {
  int a[3];
  cin >> a[0] >> a[1] >> a[2];
  sort(a, a + 3, greater<int>());
  int p = 2 * a[0] - a[1] - a[2]; 
  int count = 0;
  while (p > 0) {
    if (a[1] == a[2] && a[0] == a[1] + 1) {
      cout << count + 1 << endl;
      return 0;
    }
    else if ( a[0] == a[1] ) {
      a[2] += 2;
      count ++;
    }
    else {
      a[1] ++;
      a[2] ++;
      count ++;
    }
    sort(a, a + 3, greater<int>());
    p = 2 * a[0] - a[1] - a[2] ;
  }
  cout << count << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <queue>
using namespace std;

int main() {
	int n, m;
	cin >> n >> m;
	priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> w;
	int wa, wb;
	for (int i = 0; i < n; i++) {
		cin >> wa >> wb;
		w.push(make_pair(wa, wb));
	}

	priority_queue<int> pay;
	int ans = 0;
	for (int a = 1; a <= m; a++) {
		while (!w.empty() && w.top().first <= a) {
			pay.push(w.top().second);
			w.pop();
		}
		if (!pay.empty()) {
			ans += pay.top();
			pay.pop();
		}
	}

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

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

int main()
{
    int n;
    std::cin >> n;
    std::vector<int> a(n);
    for(int i = 0; i < n; i++)std::cin >> a[i];
    std::sort(a.begin(), a.end());
    int cnt = 0;
    for(int i = 0; i < n; i++){
        for(int j = i + 1; j < n; j++){
            auto itr = std::lower_bound(a.begin(),a.end(),a[j] + a[i]);
            cnt += itr - (a.begin() + j + 1);
        }
    }
    std::cout << cnt << std::endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define double long double
#define SZ(x) ((int)(x).size())
#define rep(i,n) for(int i=0;i<(n);++i)
#define fore(i,a) for(auto &i:a)
#define min(...) min({__VA_ARGS__})
#define max(...) max({__VA_ARGS__})
#define Yes cout << "Yes" << endl;
#define No cout << "No" << endl;
#define ALL(x) (x).begin(),(x).end()
signed _main(); signed main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
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> using v = vector<T>;
template<class T> using vv = vector<v<T>>;
const int MOD=1e9+7;
const long long INF = 1LL << 60;
using P=pair<int,int>;

signed _main(){
  int H,N; cin >> H >> N;
  int A=0;
  rep(i,N){
    int a; cin >> a;
    A+=a;
  }
  if(A>=H) Yes
  else No
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
  int N;
  cin>>N;
  int X[N];
  for(int i=0;i<N;i++){
    cin>>X[i];
  }
  long long min=100000000;
  for(int P=1;P<=100;P++){
    long long sum=0;
    for(int i=0;i<N;i++){
      sum+=(X[i]-P)*(X[i]-P);
    }
    if(sum<min){
      min=sum;
    }
  }
  cout<<min;
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
 
#define N 4
int main(){
  int A[N],B[N],i,j;
  while(scanf("%d %d %d %d",&A[0],&A[1],&A[2],&A[3])!=EOF){
    scanf("%d %d %d %d",&B[0],&B[1],&B[2],&B[3]);
    int cnt_hit=0,cnt_blow=0;
    for (i=0;i<N;i++){
      if (A[i]==B[i]){
        cnt_hit++;
      }
    }
    for (i=0;i<N;i++){
      for (j=0;j<N;j++){
        if (A[i]==B[j]){
          cnt_blow++;
        }
      }
    }
    printf("%d %d\n",cnt_hit,cnt_blow-cnt_hit);
  }
 
  return 0;
}

Measured memory_bytes: 596
#include <bits/stdc++.h>
#define LL               long long
#define PB               push_back
using namespace std;
int main (){
  int n,k,x; cin >> n>>k;
  int v[n];
  for (int i=0;i<n;i++){
    cin >> v[i];
  }
  for (int i=0;i<n-k;i++){
    if (v[i]<v[i+k]) cout<< "Yes"<< endl;
    else cout<< "No"<<endl;
  }
}

Measured memory_bytes: 4380
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define watch(x) cout <<(#x)<<" is "<<(x)<<endl
#define debug cout <<"hi"<<endl
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
const int MOD=1e9+7;
const int INF32=1<<30;
const ll INF64=1LL<<60;

int main(){
  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  int n; cin >>n;
  int a[n],dp[n]; for(auto &i:a) cin >>i; dp[0]=0; dp[1]=abs(a[1]-a[0]);
  for(int i=2; i<n; i++) dp[i]=min(dp[i-1]+abs(a[i]-a[i-1]),dp[i-2]+abs(a[i]-a[i-2]));
  cout <<dp[n-1];
return 0;}

Measured memory_bytes: 4436
#include <queue>
#include <cstdio>

using namespace std;

int main()
{
	char Query[7]; int Number;

	priority_queue<int> que;

	while (Query[2] != 'd')
	{
		scanf("%s", Query);

		if (Query[0] == 'i') 
		{ 
			scanf("%d", &Number); que.push(Number); 
		}
		else if (Query[1] == 'x') 
		{ 
			printf("%d\n", que.top()); que.pop(); 
		}
	}

	return 0;
}

Measured memory_bytes: 6524
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int INF=1e9;

template<typename T>
struct BinaryIndexedTree{
    vector<T> dat;
    BinaryIndexedTree(int n):dat(n+1,0){}
    void add(int i,T x){
        if (i==0) return;
        for (;i<=dat.size();i+=(i&-i)) dat[i]+=x;
    }
    T sum(int i){
        T res=0;
        for (;i>0;i-=(i&-i)) res+=dat[i];
        return res;
    }
    T query(int l,int r){ //[l,r)
        return sum(r-1)-sum(l-1);
    }
    int lower_bound(T x){
        if (x<=0) return 0;
        int lb=0,r=1;
        while(r<dat.size()) r<<=1;
        for (;r>0;r>>=1){
            if (lb+r<dat.size()&&dat[lb+r]<x){
                x-=dat[lb+r]; lb+=r;
            }
        }
        return lb+1;
    }
    void add0(int i,T x){add(i+1,x);}
    T sum0(int i){return sum(i+1);}
    T query0(int l,int r){return sum(r)-sum(l);}
};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string S; cin >> S;
    int n=S.size();
    vector<vector<int>> pos(26);
    for (int i=0;i<n;++i) pos[S[i]-'a'].emplace_back(i);
    int odd=0;
    vector<queue<pair<int,int>>> que(26);
    for (int i=0;i<26;++i){
        int s=pos[i].size();
        odd+=s&1;
        for (int j=0;j<s-1-j;++j) que[i].emplace(pos[i][j],pos[i][s-1-j]);
    }
    if (odd!=(n&1)){cout << -1 << '\n'; return 0;}
    BinaryIndexedTree<int> BIT(n+1);
    for (int i=0;i<n;++i) BIT.add0(i,1);
    ll ans=0;
    for (int i=0;i<n/2;++i){
        int Min=INF,nxt;
        for (int j=0;j<26;++j){
            if (que[j].empty()) continue;
            auto p=que[j].front();
            if (BIT.query0(0,p.first)+BIT.query0(p.second+1,n)<Min){
                Min=BIT.query0(0,p.first)+BIT.query0(p.second+1,n);
                nxt=j;
            }
        }
        ans+=Min;
        auto p=que[nxt].front(); que[nxt].pop();
        BIT.add0(p.first,-1); BIT.add0(p.second,-1);
    }
    cout << ans << '\n';
}

Measured memory_bytes: 2964
#include <bits/stdc++.h>
#include <sys/types.h>
#include <unistd.h>

#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)

#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=int(a)-1;i>=int(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)

#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
#define popcount(n) (__builtin_popcountll(n))

using namespace std;

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

using ll=long long;
using R=long double;
const R EPS=1e-9L; // [-1000,1000]->EPS=1e-8 [-10000,10000]->EPS=1e-7
inline int sgn(const R& r){return(r > EPS)-(r < -EPS);}
inline R sq(R x){return sqrt(max(x,0.0L));}

template<typename T> vector<T> make_vector(size_t sz){
	return vector<T>(sz);
}

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

template<typename T,typename U,typename... V> 
typename enable_if<is_same<T, U>::value!=0>::type 
fill_value(U &u, const V... v){
	u=U(v...);
}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value==0>::type
fill_value(U &u, const V... v){
	for(auto &e:u){
		fill_value<T>(e,v...);
	}
}

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

const pid_t pid = getpid();
// Problem Specific Parameter:

char graph[210][210];

int solve(int n, int root){
	vector<int> dist(n, -1);

	queue<int> que;
	dist[root] = 0;
	que.push(root);

	int ret = 0;

	while(!que.empty()){
		const int cur = que.front(); que.pop();
		rep(nxt, n){
			if(graph[cur][nxt] == '0') continue;
			if(dist[nxt] >= 0) continue;
			dist[nxt] = dist[cur] + 1;
			que.push(nxt);
		}
	}

	rep(i, n) chmax(ret, dist[i] + 1);

	rep(i, n) rep(j, n){
		if(graph[i][j] == '0') continue;
		if(abs(dist[i] - dist[j]) != 1) ret = -1;
	}

	return ret;
}	

int main(void){
	int n;
	cin >> n;
	rep(i, n) rep(j, n) cin >> graph[i][j];

	int ans = -1;
	rep(root, n) chmax(ans, solve(n, root));
	cout << ans << endl;

	return 0;
}

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

int main() {
  int A, B, C, D;
  cin >> A >> B >> C >> D;
  if ((A+B) > (C+D)) cout << "Left" << endl;
  else if ((A+B) == (C+D)) cout << "Balanced" << endl;
  else cout << "Right" << endl;
}

Measured memory_bytes: 256
import sys
import math
from collections import deque
import heapq
import itertools
from decimal import Decimal
import bisect
from operator import itemgetter
MAX_INT = int(10e18)
MIN_INT = -MAX_INT
mod = 1000000000+7
sys.setrecursionlimit(1000000)
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

def tami(now, ContestType):
  res = c[ContestType] * (now - LastDay[ContestType])
  return res

def nasu(now, x, y, z):
  res = 0
  res += s[now-1][x]
  res += s[now][y]
  res += s[now+1][z]
  if x == y == z:
    res += (D - now) * ((D - LastDay[x]) * c[x])
    now += 1
    res += (D - now) * (1 * c[y])
    now += 1
    res += (D - now) * (1 * c[z])
  elif x == y:
    res += (D - now) * ((D - LastDay[x]) * c[x])
    now += 1
    res += (D - now) * (1 * c[y])
    now += 1
    res += (D - now) * ((D - LastDay[z]) * c[z])
  elif y == z:
    res += (D - now) * ((D - LastDay[x]) * c[x])
    now += 1
    res += (D - now) * ((D - LastDay[y]) * c[y])
    now += 1
    res += (D - now) * (1 * c[z])
  elif x == z:
    res += (D - now) * ((D - LastDay[x]) * c[x])
    now += 1
    res += (D - now) * ((D - LastDay[y]) * c[y])
    now += 1
    res += (D - now) * (2 * c[z])
  else:
    res += (D - now) * ((D - LastDay[x]) * c[x])
    now += 1
    res += (D - now) * ((D - LastDay[y]) * c[y])
    now += 1
    res += (D - now) * ((D - LastDay[z]) * c[z])
  return res

D = I()
c = IL()
s = [IL() for i in range(D)]

LastDay = [0]*26
for i in range(1,D+1-3):
  tmp = ["", 0]
  for x in range(26):
    for y in range(26):
      for z in range(26):
        score = nasu(i, x, y, z)
        if tmp[1] < score:
          tmp = [(x, y, z), score]
  LastDay[tmp[0][0]] = i
  print(tmp[0][0]+1)
else:
  tmp = ["", 0]
  for x in range(26):
    for y in range(26):
      for z in range(26):
        score = nasu(D-2, x, y, z)
        if tmp[1] < score:
          tmp = [(x, y, z), score]
  for i in tmp[0]:
    print(i+1)

Measured memory_bytes: 75324
#include "bits/stdc++.h"

#define REP(i, a, b) for (int i = (a); i <= (b); ++i)
#define REV(i, a, b) for (int i = (a); i >= (b); --i)
#define FORV(a, A) for (auto &a : A)

using namespace std;

using ll = long long;

void Main()
{
   int Q;
   cin >> Q;

   int m;
   ll a, b, x = 0;
   ll f = 0;
   multiset<ll> left, right;
   ll lm = 0, rm = 0;
   REP(i, 0, Q - 1)
   {
      cin >> m;
      if (m == 2)
      {
         cout << *(--left.end()) << " " << f << endl;
      }
      else
      {
         cin >> a >> b;
         f += b;
         left.insert(a);
         right.insert(a);
         lm = *(--left.end());
         rm = *(right.begin());
         if (lm > rm)
         {
            f += lm - rm;
            left.erase(--left.end());
            right.erase(right.begin());
            left.insert(rm);
            right.insert(lm);
         }
      }
   }
}

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


Measured memory_bytes: 19072
import sys
sys.setrecursionlimit(10**7)

def main():
  s=input()
  k=int(input())
  n=len(s)
  def dp(i,j,smaller):
    # i桁目以降について、0以外の値を残りj個使用可能という状況を考える。i桁目までは決定している。残りn-i桁
    # このときi桁目までの部分が「等しい」か「strict に小さくなっている」かを smaller フラグによって分岐する。
    if n==i: # 0でない数字をk個つかえなかったパターン。
      return 0 if j>0 else 1
    if smaller:# 残りのn-i桁の中からj桁選び好きな数字にできる。j桁以外はすべて0
      if j==0:
        return 1
      elif j==1:
        return (n-i)*9
      elif j==2:
        return ((n-i)*(n-i-1))//2*9**2
      elif j==3:
        return ((n-i)*(n-i-1)*(n-i-2))//6*9**3
    if j==0: # i桁目以降はすべて0で決まり
      return 1
    ret=0
    # i+1桁目が0なら0を使うしかない
    if s[i]=='0':
      ret+=dp(i+1,j,smaller)
    else:
      ret+=dp(i+1,j-1,smaller) # i+1桁目でsと同じ数字を使う
      ret+=(int(s[i])-1)*dp(i+1,j-1,True) # i+1桁目で0より大きくs未満の数字使う
      ret+=dp(i+1,j,True) # i+1桁目で0を使う。
    return ret
  print(dp(0,k,False))
if __name__=='__main__':
  main()


Measured memory_bytes: 3064
import math
import copy
import sys
import fractions
import numpy as np
from functools import reduce

# ===FUNCTION===

def getInputInt():
    inputNum = int(input())
    return inputNum

def getInputListInt():
    outputoData = []
    inputData = input().split()
    outputData = [int(n) for n in inputData]

    return outputData

def getSomeInputInt(n):
    outputDataList = []
    for i in range(n):
        inputData = int(input())
        outputDataList.append(inputData)

    return outputDataList

def getSomeInputListInt(n):
    inputDataList = []
    outputDataList = []
    for i in range(n):
        inputData = input().split()
        inputDataList = [int(n) for n in inputData]
        outputDataList.append(inputDataList)

    return outputDataList

# ===CODE===

n, = map(int, input().split())

tmp = str(n)
length = len(tmp)

def dfs(cnt, num, sev, fiv, thr):
    if cnt == 0:
        return 1 if n >= num and sev*fiv*thr > 0 else 0

    sevp = dfs(cnt-1, num + 7*(10**(cnt-1)), sev + 1, fiv, thr)
    fivp = dfs(cnt-1, num + 5*(10**(cnt-1)), sev, fiv + 1, thr)
    thrp = dfs(cnt-1, num + 3*(10**(cnt-1)), sev, fiv, thr + 1)

    zerop = 0
    if num == 0:
        zerop = dfs(cnt - 1, num , sev, fiv, thr)

    return sevp + fivp + thrp + zerop

print(dfs(length, 0, 0, 0, 0))

Measured memory_bytes: 22732
#include<iostream>
#include<algorithm>
#include<cmath>
#define for0(i, n) for(int i = 0; i < (n); i++)
using namespace std;
signed main() {
	int n, a[1234]; cin >> n; for0(i, n)cin >> a[i]; sort(a, a + n); cout << (a[n - 1] - a[0] + 1) / 2 << endl;
}


Measured memory_bytes: 3132