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

typedef double db;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef vector<ll> vll;
typedef vector<int> vi;
typedef complex<double> com;

#define MOD 1000000007
#define PI 3.14159265359
#define endl '\n'
#define eb emplace_back
#define pb push_back
#define F first
#define S second
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define unique_sort(x) (sort(x.begin(), x.end()), x.resize(distance(x.begin(), unique(x.begin(), x.end()))))
#define fast_io() ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define dbg(x) cout << #x << " = " << x << '\n'
#define dbg2(x,y) cout<<#x<<" = "<<x<<" & "<<#y<<" = "<<y<<endl;

void test()
{
	int n,ans=0;
	long double d;
	cin>>n>>d;

	for(int i=0;i<n;i++)
	{
		long double x,y;
		cin>>x>>y;

		long double a = sqrt(x*x + y*y);

		if(a<=d)
			ans++;

	}

	cout<<ans<<endl;

}

int main()
{   
fast_io();
cout << fixed << setprecision(15);
int t = 1;

//cin>>t;

for(int i = 0; i < t; i++)
{
	test();
}
return 0;
}

Measured memory_bytes: 3860
#include <bits/stdc++.h>
using namespace std;
int main() {
  int K;
  string S;
  cin >> K >> S;
  if(S.size() > K){
    for(int i = 0; i < K; i++){
      cout << S.at(i);
    }
    cout << "..." << endl;
  }
  else cout << S << endl;
}
  

Measured memory_bytes: 3560
#include<stdio.h>
int main()
{
    long int n, a[100005], i, b[100005], j;
    scanf("%ld", &n);
    for(i=0; i<n; i++)
    {
        scanf("%ld", &a[i]);
    }
    for(i=0; i<n; i++)
    {
        j=a[i]-1;
        b[j]=i+1;
    }
    for(j=0; j<n; j++)
    {
        printf("%ld ", b[j]);
    }
    return 0;
}

Measured memory_bytes: 3276
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<29;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-11;
const ll mod=1e9+7;
const int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};

const int M=120;
ll C[M][M];
int n,m;

int main(){
	C[0][0]=1;
	for(int i=0;i<M-1;i++) for(int j=0;j<=i;j++) C[i+1][j]+=C[i][j],C[i+1][j+1]+=C[i][j];
	cin>>n>>m;
	ll res=0;
	for(int i=1;2*i-1<=n;i++) for(int j=0;j<=i;j++) if(i-1+i-j+m*j<=n){
		res+=C[i][j];
	}
	cout<<res<<endl;
}


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

using namespace std;

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

  int n;
  cin >> n;
  vector<int> ans(n);
  for (int i = 1; i < n; ++i) {
    int p;
    cin >> p;
    ++ans[p - 1];
  }
  for (int i = 0; i < n; ++i) {
    cout << ans[i] << '\n';
  }

  return 0;
}

Measured memory_bytes: 3984
#include<cstdio>
#include<iostream>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<stack>
#include<queue>
#include<deque>
#include<list>
#include<cstdlib>
#include<cctype>
#include<ctime>

using namespace std;

int a, b;
int main()
{
	cin >> a >> b;
	int c = 6 - a - b;
	cout << c << endl; 
	return 0;
 } 

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <ctime>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include<cstdio>
#define PI 3.1415927
#include <vector>
using namespace std;

int main()
{
    int r,c,n;
    int a[200][200];
    cin>>r>>c>>n;
    int x=1,y=1;
    for(int i=1; i<=n; i++)
    {
        int m;
        cin>>m;
        while(m--)
        {
            a[x][y]=i;
            if(y==c&&x%2==1)
            {
                y=c,x++;
            }
            else if(y==1&&x%2==0)
            {
                y=1,x++;
            }
            else if(x&1)
            {
                y++;
            }
            else
            {
                y--;
            }
        }
    }
    for(int i=1; i<r+1; i++)
    {
        for(int j=1; j<c+1; j++)
        {
            printf("%d%c",a[i][j],j==c?'\n':' ');
        }
    }
    return 0;
}



Measured memory_bytes: 384
#include<iostream>
#include<vector>
#include<algorithm>
#include<math.h>
using namespace std;

struct UnionFind {
  vector<int> par, con;

  UnionFind(int N) : par(N), con(N, 1) {
    for (int i = 0; i < N; i++) par[i] = i;
  }

  int root(int x) {
    if (par[x] == x) return x;
    return par[x] = root(par[x]);
  }

  void unite(int x, int y) {
    int rx = root(x);
    int ry = root(y);
    if (rx == ry) return;
    par[rx] = ry;
    con[ry] += con[rx];
  }

  bool same(int x, int y) {
    int rx = root(x);
    int ry = root(y);
    return rx == ry;
  }

  int count_same_root(int rx) {
    return con[rx];
  }
};

int main() {
  int N, M, K; cin >> N >> M >> K;
  UnionFind tree(N);
  vector<int> direct_or_block(N);

  for (int i = 0; i < M; i++) {
    int a, b; cin >> a >> b; a--; b--;
    tree.unite(a, b);
    direct_or_block[a]++;
    direct_or_block[b]++;
  }

  for (int i = 0; i < K; i++) {
    int c, d; cin >> c >> d; c--; d--;
    if (!tree.same(c, d)) continue;
    direct_or_block[c]++;
    direct_or_block[d]++;
  }

  for (int i = 0; i < N; i++) {
    int root = tree.root(i);
    int sum = tree.count_same_root(root);
    cout << (sum - direct_or_block[i] - 1);
    if (i != N - 1) cout << " ";
    else cout << endl;
  }
}


Measured memory_bytes: 2432
#include <bits/stdc++.h>
#include <iomanip>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define Rreps(i,n,e) for(int i = n - 1; i >= e; --i)
#define Rrep(i,n) Rreps(i,n,0)
#define ALL(a) a.begin(), a.end()
#define fi first
#define se second
#define mp make_pair
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;

ll N,M,H,W,K,Q,A,B;
string S;
//const ll MOD = 998244353;
const ll MOD = (1e+9) + 7;
const ll INF = 1LL << 60;
typedef pair<ll,ll> P;

ll dfs(ll hp){
    if(hp == 1) return 1;
    return dfs(hp / 2) * 2 + 1LL;
}

int main(){
    cin>>N;
    cout<<dfs(N)<<endl;
}

Measured memory_bytes: 256
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,copy,functools
import time,random

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
mod2 = 998244353
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)
def pe(s): return print(str(s), file=sys.stderr)
def JA(a, sep): return sep.join(map(str, a))
def JAA(a, s, t): return s.join(t.join(map(str, b)) for b in a)


def main():
    s = S()
    c = collections.Counter(s)
    if len(c) == 1:
        return "No"

    return "Yes"


print(main())





Measured memory_bytes: 5444
#include <bits/stdc++.h>
using namespace std;
using LL = long long int;
#define incID(i, l, r) for(int i = (l)    ; i <  (r); ++i)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); --i)
#define incII(i, l, r) for(int i = (l)    ; i <= (r); ++i)
#define decII(i, l, r) for(int i = (r)    ; i >= (l); --i)
#define inc(i, n)  incID(i, 0, n)
#define dec(i, n)  decID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define dec1(i, n) decII(i, 1, n)
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))
#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define MT make_tuple
#define FI first
#define SE second
#define FR front()
#define BA back()
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
auto setmin   = [](auto & a, auto b) { return (b <  a ? a = b, true : false); };
auto setmax   = [](auto & a, auto b) { return (b >  a ? a = b, true : false); };
auto setmineq = [](auto & a, auto b) { return (b <= a ? a = b, true : false); };
auto setmaxeq = [](auto & a, auto b) { return (b >= a ? a = b, true : false); };
#define SI(v) static_cast<int>(v.size())
#define RF(e, v) for(auto & e: v)
#define until(e) while(! (e))
#define if_not(e) if(! (e))
#define ef else if
#define UR assert(false)
#define IN(T, ...) T __VA_ARGS__; IN_(__VA_ARGS__);
void IN_() { };
template<typename T, typename ... U> void IN_(T &  a, U &  ... b) { cin >> a; IN_(b ...); };
template<typename T                > void OUT(T && a            ) { cout << a << endl; }
template<typename T, typename ... U> void OUT(T && a, U && ... b) { cout << a << " "; OUT(b ...); }

// ---- ----

int main() {
	IN(int, n);
	map<string, int> mp;
	inc(i, n) {
		IN(string, s);
		mp[s]++;
	}
	OUT("AC x",  mp["AC"]);
	OUT("WA x",  mp["WA"]);
	OUT("TLE x", mp["TLE"]);
	OUT("RE x",  mp["RE"]);
}


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

int main() {
	ll H,W,r=0;
	cin >> H >> W;

	if(H==1 || W==1)
		r = 1;
	else {
		r = H*(W/2ll);
		r += (H/2ll+H%2ll)*(W%2ll);
	}

	cout << r << 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 rep2(i,s,n) for (int i = s; i < n; ++i)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define tmax(a,b,c) max(a,max(b,c))
#define tmin(a,b,c) min(a,min(b,c))
#define pb push_back
using namespace std;
using ll = long long;
using P = pair<int,int>;
template<class T> inline bool chmin(T& a,T b) {if(a > b){a = b; return true;} return false;}
template<class T> inline bool chmax(T& a,T b) {if(a < b){a = b; return true;} return false;}
const int inf = 1001001001;
const ll linf = 1001001001001001001;

int main() {
    int a,b;
    cin >> a >> b;
    if(a <= b) {
        rep(i,b) cout << a;
    } else {
        rep(i,a) cout << b;
    }
    cout << endl;
}


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

#define pb(n) push_back(n)
#define fi first
#define se second
#define all(r) (r).begin(),(r).end()
#define gsort(st,en) sort((st),(en),greater<int>())
#define vmax(ary) *max_element(all(ary))
#define vmin(ary) *min_element(all(ary))
#define debug(x) cout<<#x<<": "<<x<<endl
#define fcout(n) cout<<fixed<<setprecision((n))
#define scout(n) cout<<setw(n)
#define vary(type,name,size,init) vector< type> name(size,init)

#define rep(i,n) for(int i = 0; i < (int)(n);++i)
#define REP(i,a,b) for(int i = (a);i < (int)(b);++i)
#define repi(it,array) for(auto it = array.begin(),end = array.end(); it != end;++it)
#define repa(n,array) for(auto &n :(array))

using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using dict = map<string,int>;
using pii = pair<int,int> ;

constexpr int imax = ((1<<30)-1)*2+1 ;
constexpr int inf = 100000000;
constexpr double PI = acos(-1.0) ;
double eps = 1e-10 ;
const int dy[] = {-1,0,1,0};
const int dx[] = {0,-1,0,1};

inline bool value(int x,int y,int w,int h){
  return (x >= 0 && x < w && y >= 0 && y < h);
}

template<typename T>
void Unique(vector<T> &v){
  sort(all(v));
  v.erase(unique(all(v)),v.end());
}

template<typename T>
T ston(string& str, T n){
  istringstream sin(str) ;
  T num ;
  sin >> num ;
  return num ;
}

void Ans(bool f){
  if(f) cout << "YES"<<endl;
  else cout << "NO"<<endl;
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  vector<vector<int>> v(n+1,vector<int>(n+1,0));
  REP(i,1,n+1){
    REP(j,1,n+1){
      cin >> v[j][i];
    }
  }
  auto v2 = v;
  REP(i,1,n+1){
    REP(j,1,n+1){
      v2[j][i] += v2[j-1][i];
    }
  }
  REP(i,1,n+1){
    REP(j,1,n+1){
      v2[j][i] += v2[j][i-1];
    }
  }
  int ma = -inf;
  bool zero = false;
  REP(i,0,n+1){
    REP(j,0,n+1){
      REP(h,1,n+1-i){
        REP(w,1,n+1-j){
          ma = max(ma,v2[j][i]+v2[j+w][i+h]-v2[j+w][i] - v2[j][i+h]);
        }
      }
    }
  }
  if(zero && ma < 0){
    cout << 0 << endl;
  }
  else{
    cout << ma << endl;
  }
  return 0;
}

Measured memory_bytes: 3240
#include<iostream>
#include<string>
using namespace std;
int main() {
	
	int a,b;
	char ans = 'C';

	cin >> a;
	b=a / 1000;
	a = a % 1000;
	for (int i = 0; i < b; i++) {
		ans++;
	}

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

Measured memory_bytes: 256
n = gets.chomp.to_i
value = gets.split.map(&:to_i)
cost = gets.split.map(&:to_i)

array = []
n.times do |i|
  if value[i] > cost[i]
    array << (value[i] - cost[i])
  else
    array << 0
  end
end

p array.inject(:+)


Measured memory_bytes: 1788
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<bitset>
#include<cstdio>
#include<cmath>
#include<deque>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<string>
#include<tuple>
#include<utility>
#include<vector>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector<vector<long long>> vvll;
typedef vector<vector<int>> vvi;

#define rep(i, a, n)  for(int i=a; i<n; i++)
#define REP(i, n)  for(int i=0; i<(int)(n); i++)
#define REPS(i, n)  for(int i=1; i<=(int)(n); i++)
#define PER(i, n) for(int i=(int)(n)-1; i>= 0; i--)
#define PERS(i, n)  for(int i=(int)(n); i>0; i--)
#define FOR(i, c) for(__typeof((c).begin()) i = (c).begin(); i!=(c).end(); i++)
#define RFOR(i, c)  for(__typeof((c).rbegin()) i=(c).rbegin(); i!=(c).end(); i++)
#define ALL(container)  (container).begin(), (container).end()
#define RALL(container) (container).rbegin(), (container).rend()
#define SZ(container) (container).size()
#define FILL0(n)  setfill('0') << right << setw(n)
#define mp(a, b)  make_pair(a, b)
#define toLower(c)  c+0x20
#define toUpper(c)  c-0x20
#define pb  push_back
#define eb  emplace_back

const int INF = 1e9;
const long long LLINF = 1e18;
const int MOD = 1000000007;

int main(){
  int k;  cin >> k;
  int a, b; cin >> a >> b;
  for(int i=a; i<=b; i++){
    if(i%k==0){
      cout << "OK" << endl;
      return 0;
    }
  }
  cout << "NG" << endl;
  return 0;
}


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

int main() {
  int ans = 0;
  string s;
  cin >> s;

  for (char t : s) {
    if (t == '1') ans++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
N = int(input())
An = [int(val) for val in input().split()]

# 各踏み台を初期化
Fn = [0 for _ in range(N)]

an_1 = An[0]
fn_1 = 0

for i in range(1, N):
    an = An[i]
    fn =  max(0, an_1 + fn_1 - an)

    Fn[i] = fn
    fn_1 = fn
    an_1 = an

sum = 0
for fi in Fn:
    sum += fi

print(sum)



Measured memory_bytes: 32320
card = [list(map(int,input().split())) for i in range(3)]
n = int(input())
numbers = [int(input()) for i in range(n)]


for number in numbers:
    for i in range(3):
        for j in range(3):
            if card[i][j] == number:
                card[i][j] = 0
    
bingo = False

for i in range(3):
    if card[i][0] == 0 and card[i][1] == 0 and card[i][2] == 0:
        bingo = True
    
for i in range(3):
    if card[0][i] == 0 and card[1][i] == 0 and card[2][i] == 0:
        bingo = True

if card[0][0] == 0 and card[1][1] == 0 and card[2][2] == 0:
    bingo = True
    
if card[0][2] == 0 and card[1][1] == 0 and card[2][0] == 0:
    bingo = True

if bingo:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3064
n,m = map(int,input().split())
c = [list(map(int,input().split())) for i in range(n)]
ca = sorted(c,key=lambda x:x[0])

import sys
if n ==1:
    print(ca[0][0]*ca[0][1])
    sys.exit()
money = 0
i = 0
num = 0
while True:
    #print(str(i)+"だよ")
    if num + ca[i][1] < m:
        num += ca[i][1]
        money += ca[i][0] * ca[i][1]
        i += 1
        #print(num,money)
    else:
        money += ca[i][0]*(m-num)
        break    
print(money)

Measured memory_bytes: 94336
n=gets.to_i
a=gets.split.map(&:to_i)
b=gets.split.map(&:to_i)
c=gets.split.map(&:to_i)


ary=0
(0..n-2).each do |i|
  ary += c[a[i]-1] if (a[i+1] - a[i])==1
end

result = b.inject(:+) + ary
puts result

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

using namespace std;
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;

int main() {

    int n; cin >> n;

    string s, t; cin >> s >> t;

    string ans = "";

    for (int i = 0; i < n; ++i) {
        ans += s[i];
        ans += t[i];
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"
#include "ctime"

using namespace std;

constexpr long long int MOD = 1000000007;
//constexpr int MOD = 1000000007;
//constexpr int MOD = 998244353;
//constexpr long long int MOD = 998244353;
constexpr double EPS = 1e-12;

//int N, M, K, T, H, W, L, R;
long long int N, M, K, T, H, W, L, R;



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

	while (cin >> N, N) {
		vector<int>v(N);
		long double score = MOD;
		int a = 0, b = 0, c = 0;
		for (auto &i : v)cin >> i;
		for (int i = 0; i < 16; i++) {
			for (int j = 0; j < 16; j++) {
				for (int k = 0; k < 16; k++) {
					int p = i;
					vector<int>w(256);
					for (int l = 0; l < N; l++) {
						p = p * j + k;
						p %= 256;
						w[(v[l] + p) % 256]++;
					}
					long double cscore = 0;
					for (int l = 0; l < 256; l++) {
						if(w[l])cscore -= logl(w[l])*w[l];
					}
					//cout << i << " " << j << " " << k << " " << cscore << endl;
					if (cscore +EPS< score) {
						score = cscore;
						a = i, b = j, c = k;
					}
				}
			}
		}
		cout << a << " " << b << " " << c << endl;
	}
}


Measured memory_bytes: 3360
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<map>
#include<cstdio>
#include<stack>
#include<queue>
#include<fstream>
#include<cstdio>
#include<deque>
#include<iomanip>
#include <random>

using namespace std;
#define ok1 printf("ok1\n");
#define ok2 printf("ok2\n");
#define M 1000000000000000000LL
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);(i)--)
#define all(a) (a).begin(),(a).end()
#define reall(a) (a).rbegin(),(a).rend()
#define pb push_back
#define pf push_front
#define MIN(a,b) a=min((a),(b))
#define MAX(a,b) a=max((a),(b))
#define SIZE(v) (int)v.size()
const double pi = acos(-1.0);

typedef vector<int> vi;
typedef vector<string> vs;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef deque<ll> dll;
ll mod = 1e9 + 7;

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

	ll n, c;
	cin >> n >> c;
	vll x(n), v(n);
	rep(i, n) {
		cin >> x[i] >> v[i];
	}
	
	vll a(n), b(n);
	ll dist, sum = 0;
	rep(i, n) {
		dist = x[i];
		sum += v[i];
		a[i] = sum - dist;
		if (i > 0) {
			MAX(a[i], a[i - 1]);
		}
	}

	sum = 0;
	repr(i, n) {
		dist = c - x[i];
		sum += v[i];
		ll j = n - i - 1;
		b[j] = sum - dist;
		if (j > 0) {
			MAX(b[j], b[j - 1]);
		}
	}

	ll ans = 0, parants = 0;
	MAX(ans, a[n - 1]);
	MAX(ans, b[n - 1]);

	sum = 0;
	rep(i, n) {
		dist = x[i];
		sum += v[i];
		if (n - i - 2 >= 0) {
			parants = sum - 2 * dist + b[n - i - 2];
			MAX(ans, parants);
		}
	}

	sum = 0;
	repr(i, n) {
		dist = c - x[i];
		sum += v[i];
		ll j = n - i - 1;
		if (n - j - 2 >= 0) {
			parants = sum - 2 * dist + a[n - j - 2];
			MAX(ans, parants);
		}
	}

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

Measured memory_bytes: 3456
#include<iostream>
#include<string>
using namespace std;
typedef long long ll ;
 
int main(){
  int n,k;
  cin >> n >> k;
  string s;
  cin >> s;
  if(s[k-1]=='A')s[k-1]='a';
  if(s[k-1]=='B')s[k-1]='b';
  if(s[k-1]=='C')s[k-1]='c';
  cout << s << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <sstream>
#include <string>
#include <cstdio>
#include <stack>
#include <queue>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cstring>
#include <tuple>
#include <utility>
#include <list>
#include <cmath>

using namespace std;

typedef long long LL;
typedef vector<int> Array;
typedef pair<int, int> P;

const int INF = 1 << 29;
const LL MOD = 100000;
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define all(c) (c).begin(), (c).end()

struct edge{ int to, cost; edge(int t, int c) :to(t), cost(c){} };

int dxk[] = { 1, 1, 1, 0, -1, 0 };
int dxg[] = { 0, 1, 0, -1, -1, -1 };
int dy[] = { -1, 0, 1, 1, 0, -1 };

struct node
{
	LL value, lw, rw, left, right;
};

LL gcd(LL a, LL b)
{
	if (a < b) swap(a, b);
	return a % b == 0 ? b : gcd(b, a % b);
}
LL sks(LL a, LL b)
{
	LL g = gcd(a, b);
	return a / g * b;
}

LL dfs(int idx, vector<node>& bars)
{
	if (idx == -1) return 1LL;
	node& node = bars[idx];
	if (node.value != 0) return node.value;

	LL r = dfs(node.right, bars), l = dfs(node.left, bars);

	int m = 1;
	while ((r * node.rw * m) % (l * node.lw) != 0) m++;
	int lm = r * node.rw * m / (l * node.lw);
	//r*lの最小公倍数を基礎値としてm:nにする
	//LL s = sks(r * node.rw, l * node.lw);
	//return node.value = s / node.rw + s / node.lw;
	return node.value = m * r + lm * l;
}

int main()
{
	int n;
	while (cin >> n && n)
	{
		vector<node> bars(n);
		rep(i, n)
		{
			int p, q, r, b;
			cin >> p >> q >> r >> b;
			int g = gcd(p, q);
			bars[i].rw = q / g;
			bars[i].lw = p / g;
			bars[i].left = r - 1;
			bars[i].right = b - 1;
		}

		LL ans = 0;
		rep(i, n) ans = max(dfs(i, bars), ans);
		cout << ans << endl;
	}

	return 0;
}

Measured memory_bytes: 1188
#include <bits/stdc++.h>
#define FOR(I,X,Y) for(int (I)=(X);(I)<(Y);(I)++)
#define REP(I,X,Y) for(int (I)=(Y)-1;(I)>=(X);(I)--)
#define ALL(X) (X).begin(),(X).end()
#define INF 1000000007
#define LINF 1000000000000000007
typedef long long ll;
using namespace std;

int main(){
  int K;
  cin >> K;
  cout << (K/2)*(K/2+K%2) << endl;
}


Measured memory_bytes: 256
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author
 */

#include<bits/stdc++.h>
using namespace std;
using ll=long long;
#define fr(i,n) for(int i=0;i<(n);++i)
#define Fr(i,n) for(int i=1;i<=(n);++i)
#define ifr(i,n) for(int i=(n)-1;i>=0;--i)
#define iFr(i,n) for(int i=(n);i>0;--i)

class CSequenceGrowingEasy {
public:
    void solve(istream& in, ostream& out) {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        int n;
        in>>n;
        vector<int> a(n);
        for(auto&i:a) in>>i;
         bool f=false;
        if(a[0]) f=true;
        fr(i,n-1) if(a[i+1]>a[i]+1) f=true;
        if(f){
            out<<-1<<endl;
            return;
        }
        ll ans=0;
        fr(i,n-1){
            if(a[i+1]==a[i]+1) ++ans;
            else ans+=a[i+1];
        }
        out<<ans<<endl;
    }
};

int main() {
    CSequenceGrowingEasy solver;
    std::istream& in(std::cin);
    std::ostream& out(std::cout);
    solver.solve(in, out);
    return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
unordered_map<long long,long long >mp;
int main()
{
    long long  int n,m,a,b;
    long long int sum=0;
    cin>>n;
    for(int i=1; i<=n; i++)
    {
        cin>>a;
        sum+=a;
        mp[a]++;
    }
    cin>>m;
    for(int i=1; i<=m; i++)
    {
        cin>>a>>b;
        sum=sum-mp[a]*a+mp[a]*b;
        cout<<sum<<endl;
        mp[b]+=mp[a];
        mp[a]=0;
    }
}


Measured memory_bytes: 7052
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
using namespace std;
int main(){
  int N, W, H;
  cin >> N >> W >> H;
  vector< pair<int,int> > X, Y;
  int x, y, w;
  for(int i = 0; i < N; ++i){
    cin >> x >> y >> w;
    X.push_back(make_pair(max(0,x-w),min(W,x+w)));
    Y.push_back(make_pair(max(0,y-w),min(H,y+w)));
  }
  sort(X.begin(),X.end());
  sort(Y.begin(),Y.end());
  int l = X[0].first, r = X[0].second;
  for(int i = 1; i < N; ++i){
    int l_i = X[i].first, r_i = X[i].second;
    if(l_i <= r) r = max(r,r_i);
  }
  if(l == 0 && r == W){
    cout << "Yes" << endl;
    return 0;
  }
  l = Y[0].first, r = Y[0].second;
  for(int i = 1; i < N; ++i){
    int l_i = Y[i].first, r_i = Y[i].second;
    if(l_i <= r) r = max(r,r_i);
  }
  if(l == 0 && r == H){
    cout << "Yes" << endl;
    return 0;
  }
  cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 4708
#include <bits/stdc++.h>
#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define YES() printf("YES\n")
#define NO() printf("NO\n")
#define Yes() printf("Yes\n")
#define No() printf("No\n")
using namespace std;

#define int long long
//typedef    long long          ll;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      P;
 
const int INF=1e+9;
const double EPS=1e-9;
const int MOD=1000000007;
 
const int dx[]={1,0,-1,0},dy[]={0,-1,0,1};

signed main(){
	string s;
	cin >> s;
	if(s[0]=='a'){
		cout << "vowel" << endl;
		return 0;
	}
	if(s[0]=='i'){
		cout << "vowel" << endl;
		return 0;
	}
	if(s[0]=='u'){
		cout << "vowel" << endl;
		return 0;
	}
	if(s[0]=='e'){
		cout << "vowel" << endl;
		return 0;
	}
	if(s[0]=='o'){
		cout << "vowel" << endl;
		return 0;
	}
	cout << "consonant" << endl;
return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main()
{
    int x,y,z,k,t,gcd,sum=0,gcd2,a,b,c;

    scanf("%d",&k);
    for(x=1;x<=k;x++)
    {
        for(y=1;y<=k;y++)
        {
            for(z=1;z<=k;z++)
            {
                a=x;
                b=y;
                c=z;
                while(c!=0)
                {
                    t=c;
                    c=b%c;
                    b=t;
                }
                gcd=b;
                while(gcd!=0)
                {
                    t=gcd;
                    gcd=a%gcd;
                    a=t;
                }
                gcd2=a;
                sum+=gcd2;

            }
        }
    }
    printf("%d",sum);
    return 0;

}


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

using namespace std;
int main(){
	string s,t;
	cin>>s>>t;
	vector<string>v;
	int ans=1e9;
	for(int i=0;i<=s.size()-t.size();i++){
		int cnt=0;
		for(int j=0;j<t.size();j++){
			if(t[j]!=s[i+j])cnt++;
		}
		ans=min(ans,cnt);
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 3628
import java.util.*;

public class Main {
	public static void main(String... args) {
		Scanner sc = new Scanner(System.in);
		String n = sc.next();

		if("Sunny".equals(n)) {
			System.out.println("Cloudy");
		}
		if("Cloudy".equals(n)) {
			System.out.println("Rainy");
		}
		if("Rainy".equals(n)) {
			System.out.println("Sunny");
		}

	}
}

Measured memory_bytes: 20180
#include <bits/stdc++.h>
using namespace std;
int main(void){
  int min_1 = 10;
  int sum = 0;
  int t;
  for (int i = 0; i < 5; i++) {
    cin >> t;
    if (t % 10 != 0 && t % 10 < min_1) min_1 = t % 10;
    sum += int(ceil(t / 10.0) * 10);
  }
  cout << sum - 10 + min_1 << endl;
}


Measured memory_bytes: 256
n,m = map(int,input().split())
ls = [0]*n

for i in range(n) :
    a,b = map(int,input().split())
    ls[i] = [a,b]
    
ls.sort(key=lambda x:x[0])

c = m + 0
ans = 0

while c > 0 :
    if c >= ls[0][1] :
        ans += ls[0][0] * ls[0][1]
        c -= ls[0][1]
        ls.pop(0)
    else :
        ans += ls[0][0] * c
        c = 0

print(ans)

Measured memory_bytes: 21224
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define si(X) scanf("%d", &(X))
#define sll(X) scanf("%lld",&(X))
const ll mod = 1e9+7;
#define INFL 0x3f3f3f3f3f3f3f3fLL
 
//-------------------------<MATH>-------------------------------------------------------//
ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);}
ll expo(ll base,ll pow){ll ans = 1;
   while(pow!=0){if(pow&1==1){ans = ans*base;ans = ans%mod;}
   base *= base;base%=mod;pow/=2;}return ans;}
ll inv(ll x){return expo(x,mod-2);}
ll mult_mod(ll a , ll b){a = a%mod; b = b%mod;
ll c = (a * b)%mod;
//cout << a << " " << b << endl;
return c;}
ll add_mod(ll a , ll b){a = (a + mod)%mod;b = (b + mod)%mod;ll c = (a + b)%mod;return c;}
ll fac[(int)(5e5 + 5)] , inv_fac[(int)(5e5 + 5)];
void precomp_factorial(int M){fac[0] = 1;for(int i = 1 ; i <= M ; i++) fac[i] = mult_mod(i , fac[i - 1]);
    inv_fac[M] = inv(fac[M]);for(int i = M - 1 ; i >= 0 ; i--) inv_fac[i] = mult_mod(i + 1 , inv_fac[i + 1]);}
ll nCk(ll n , ll k){ll ans = fac[n];ans = mult_mod(ans , inv_fac[n - k]);ans = mult_mod(ans , inv_fac[k]);return ans;}
int lo[(int)(1e3 + 6)];
void sieve(int M){for(int i = 2 ; i < M ; i++){ if(lo[i]) continue; for(int j = i ; j < M ; j += i)lo[j] = i;}}
int max_expo_prime_n_fac(ll N , int prime){int ress = 0;while(N){ress += (N/prime);N /= prime;}return ress;}
//-------------------------</MATH>-------------------------------------------------------//
 
//-------------------------<STRING>-------------------------------------------------------//
string get_prefix(string x , int MAX){return x.substr(0 , min((int)x.size() , MAX));}
string get_suffix(string x,int MAX){int dn=1;for(int i=x.size()-1;i>=0;i--){if(dn==MAX)return x.substr(i);dn++;}return x;}
string convert_to_binary(int x,int len) {string ans=""; while(x){if(x&1){ans='1'+ans;}
    else{ans ='0'+ans;}x/=2;}int k = ans.size();while(k < len){ans = '0' + ans;k++;}return ans;}
//-------------------------</STRING>-------------------------------------------------------//
 
ull llrand() {ull r = 0;for(int i = 0; i < 5; ++i){r = (r << 15)|(rand() & 0x7FFF);}return r & 0xFFFFFFFFFFFFFFFFULL;}
int dx[8] = {1 , 0 , -1 , 0 , 1 , -1 , -1 , 1};    // last 4 diagonal
int dy[8] = {0 , 1 , 0 , -1 , 1 , 1 , -1 , -1};
 
const int SZ = 2345678;

ll vec[213456];

int check(ll mid, ll k, ll n){
    ll k1 = 0;

    for(int i = 0; i < n; i++){
        ll cnt1 = vec[i]/mid;
        if(vec[i]%mid) cnt1++;
        k1 += (cnt1-1LL);
    }

    return (k1 <= k);
}



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

     ll ans = 0LL;
     for(int i = 0; i < n; i++){
         cin >> vec[i];
         ans = max(ans, vec[i]);
     }
     
     ll start = 1LL, end1 = ans;

     while(start <= end1){
           ll mid = (start+end1)/2LL;
           if(check(mid, k, n)){
               ans = mid;
               end1 = mid-1LL;
           } else start = mid+1;
     }
     cout << ans;
 }


Measured memory_bytes: 5180
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdlib>
#include <map>
#include <iomanip>
#include <set>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define int long long
#define pie 3.141592653589793238462643383279
#define mod 1000000007
#define INF 1145141919364364
#define all(vec) vec.begin(),vec.end()
#define P pair<int,int>
#define S second
#define F first
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x%y);
}
int lcm(int x, int y) {
	return x / gcd(x, y)*y;
}
bool prime(int x) {
	for (int i = 2; i <= sqrt(x); i++) {
		if (x%i == 0)return false;
	}
	return true;
}

int kai(int x) {
	if (x == 1)return 1;
	return kai(x - 1)*x%mod;
}

int mod_pow(int x, int y, int moder) {
	int res = 1;
	while (y > 0) {
		if (y & 1)res = res * x%moder;
		x = x * x%moder;
		y >>= 1;
	}
	return res;
}

int comb(int x, int y) {
	if (y > x)return 0;
	if (x == y)return 1;
	return kai(x)* mod_pow(kai(x - y), mod - 2, mod) % mod * mod_pow(kai(y), mod - 2, mod) % mod;
}

int l, r;
int ans = INF;

signed main() {
	cin >> l >> r;
	int l1 = l % 2019;
	int r1 = r % 2019;
	if (l1 >= r1 || r - l >= 2019)cout << 0 << endl;
	else {
		for (int i = l1; i <= r1; i++) {
			for (int j = i + 1; j <= r1; j++) {
				ans = min(ans, (i*j) % 2019);
			}
		}
		cout << ans << endl;
	}
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define Would
#define you
#define all(n)  n.begin(),n.end()
#define rall(n) n.rbegin(),n.rend()
typedef long long ll;
const ll INF = 2147483647;
const ll MOD = 1e9 + 7;
const double EPS = 1e-10;
const double pi = acos(-1);//3.1415926535897932384626433832795028...
const ll SIZE = 1 << 17;
int dx[] = { 1,0,-1,0 }, dy[] = { 0,1,0,-1 }, alp[30];
ll fac[200005], finv[200005], inv[200005];
vector<ll>dij;
struct edge { ll to, cost; };
vector<vector<edge> >G;

ll mod_pow(ll a, ll b) {
	ll res = 1, mul = a;
	for (int i = 0; i < 31; ++i) {
		if (b >> i & 1) {
			res *= mul;
			res %= MOD;
		}
		mul = (mul * mul) % MOD;
	}
	return res;
}

void addedge(int from, int to, int cost) {
	G[from].push_back({ to,cost });
	G[to].push_back({ from,cost });
}

template<typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }

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

template<typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T & t, const V & v) { t = v; }

template<typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T & t, const V & v) {
	for (auto& e : t) fill_v(e, v);
}

template<typename T>
void outp(vector<T>v) {
	for (int i = 0; i < v.size(); ++i) {
		cout << v[i];
		if (i != v.size() - 1) { cout << " "; }
	}
}

double add(double a, double b) {
	if (abs(a + b) < EPS * (abs(a) + abs(b))) { return 0; }
	return a + b;
}

double len(int a, int b, int c, int d) {
	return (double)sqrt((a - c) * (a - c) + (b - d) * (b - d));
}

int n, uku = 1;
double ans, mon;
int main() {
	cin >> n;
	vector<int>vi(n);
	vector<pair<double, double>>v(n);
	for (int i = 1; i < n + 1; ++i) { uku *= i; }
	for (int i = 0; i < n; ++i) { cin >> v[i].first >> v[i].second; }
	for (int i = 0; i < n; ++i) { vi[i] = i; }
	do {
		mon = 0;
		for (int i = 0; i < n - 1; ++i) {
			mon += sqrt(pow((v[vi[i]].first - v[vi[i + 1]].first), 2) + pow((v[vi[i]].second - v[vi[i + 1]].second), 2));
		}
		ans += mon;
	} while (next_permutation(all(vi)));

	cout << setprecision(20) << ans / (double)uku << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
#include<complex>
#include<numeric>
using namespace std;

//#define int long long
typedef long long ll;

typedef unsigned long long ul;
typedef unsigned int ui;
constexpr ll mod = 1000000007;
const ll INF = mod * mod;
typedef pair<int, int>P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
#define all(v) (v).begin(),(v).end()
typedef pair<ll, ll> LP;
typedef long double ld;
typedef pair<ld, ld> LDP;
const ld eps = 1e-12;
const ld pi = acos(-1.0);

void chmin(ll &a, ll b) {
	a = min(a, b);
}
void chmax(ll &a, ll b) {
	a = max(a, b);
}
ll mod_pow(ll a, ll n, ll m = mod) {
	a %= m;
	ll res = 1;
	while (n) {
		if (n & 1)res = res * a%m;
		a = a * a%m; n >>= 1;
	}
	return res;
}

struct modint {
	ll n;
	modint() :n(0) { ; }
	modint(ll m) :n(m) {
		if (n >= mod)n %= mod;
		else if (n < 0)n = (n%mod + mod) % mod;
	}
	operator int() { return n; }
};
bool operator==(modint a, modint b) { return a.n == b.n; }
modint operator+=(modint &a, modint b) { a.n += b.n; if (a.n >= mod)a.n -= mod; return a; }
modint operator-=(modint &a, modint b) { a.n -= b.n; if (a.n < 0)a.n += mod; return a; }
modint operator*=(modint &a, modint b) { a.n = ((ll)a.n*b.n) % mod; return a; }
modint operator+(modint a, modint b) { return a += b; }
modint operator-(modint a, modint b) { return a -= b; }
modint operator*(modint a, modint b) { return a *= b; }
modint operator^(modint a, int n) {
	if (n == 0)return modint(1);
	modint res = (a*a) ^ (n / 2);
	if (n % 2)res = res * a;
	return res;
}

ll inv(ll a, ll p) {
	return (a == 1 ? 1 : (1 - p * inv(p%a, a)) / a + p);
}
modint operator/(modint a, modint b) { return a * modint(inv(b, mod)); }
const int max_n = 1 << 18;
modint fact[max_n], factinv[max_n];
void init_f() {
	fact[0] = modint(1);
	for (int i = 0; i < max_n - 1; i++) {
		fact[i + 1] = fact[i] * modint(i + 1);
	}
	factinv[max_n - 1] = modint(1) / fact[max_n - 1];
	for (int i = max_n - 2; i >= 0; i--) {
		factinv[i] = factinv[i + 1] * modint(i + 1);
	}
}
modint comb(int a, int b) {
	if (a < 0 || b < 0 || a < b)return 0;
	return fact[a] * factinv[b] * factinv[a - b];
}

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

int trans(int x, int y) {
	return x * 60 + y;
}

void solve() {
	int h1, m1, h2, m2;
	cin >> h1 >> m1 >> h2 >> m2;
	int s = trans(h1, m1);
	int g = trans(h2, m2);
	int k; cin >> k;
	int ans = g - s - k;
	if (ans < 0)ans = 0;
	cout << ans << "\n";
}


signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(10);
	//init_f();
	//init();
	//int t; cin >> t; rep(i, t)solve();
	solve();
	stop
		return 0;
}


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

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

  int m = n;
  set<int> st;
  for (int t = 0; t < 2; t++) {
    for (int i = 2; i * i <= n; i++) {
      if(n % i == 0) {
        st.insert(i);
        st.insert(n/i);
      }
    }
    st.insert(n);
    n--;
  }

  st.erase(1);

  int answer = 0;
  for (auto & k : st) {
    int x = m;
    while (true) {
      if(x % k == 0) x /= k;
      else if(x % k == 1) {
        answer++;
        break;
      } else {
        break;
      }
    }
  }
  cout << answer << '\n';
}


Measured memory_bytes: 3756
s = str(input())
t = str(input())
lens = int(len(s))
lent = int(len(t))
icchi = []
c = 0
for i in range(lens-lent+1):
    scut = s[i:lent+i]
    for j in range(lent):
        if scut[j] == t[j]:
            c += 1
    icchi.append(c)
    c=0
print(lent-max(icchi))

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

#ifdef NON_SUBMIT
#define TEST(n) (n)
#else
#define TEST(n) ((void)0)
#endif

using namespace std;

vector<int> A;
int tree[222222];

void update(int n, int v)
{
	for(;n<222222;n+=n&-n) tree[n]+=v;
}

int get_cnt(int n)
{
	int ret=0;
	for(;n;n-=n&-n) ret+=tree[n];
	return ret;
}

long long cnt_pair(int l)
{
	long long ret=0;
	int c=A.size()+1;
	memset(tree,0,sizeof(tree));
	update(c,1);
	for(auto a: A) {
		ret+=get_cnt(c+=(a>=l ? 1:-1));
		update(c,1);
	}
	return ret;
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);
	TEST(freopen("input.txt", "r", stdin));
	TEST(freopen("output.txt", "w", stdout));
	TEST(freopen("debug.txt", "w", stderr));
	int N, s=1, e=1e9;
	long long K;
	cin>>N;
	K=(1LL*N*(N+1)/2+1)/2;
	A.resize(N);
	for(int i=0;i<N;i++) cin>>A[i];
	while(s<=e) {
		int m=(s+e)>>1;
		if(cnt_pair(m)>=K) s=m+1;
		else e=m-1;
	}
	cout<<e<<'\n';
	return 0;
}

Measured memory_bytes: 1536
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define SORT(x) sort(x.begin(), x.end())
#define RS(x) rsort(x.begin(),x,end()))
#define REVE(x) reverse(x.begin(), x.end())
#define ALL(x) (x).begin(), (x).end()
int INF = 1e9 + 1;
int MOD = 1e9+7;
struct initon
{
    initon()
    {
        cin.tie(0);
        ios::sync_with_stdio(false);
    };
};
signed main()
{
  int a,b;
  cin >>a>>b;
  if(a==1||b==1){
  cout << 1;
  }else if(a*b%2==0){
  cout << (a*b)/2;
  }else{
    cout << (a*b)/2+1;
  }
}

Measured memory_bytes: 256
//Bismillahir Rahmanir Rahim
#include<bits/stdc++.h>
using namespace std;
int main (void)
{
  int n,h,max=0,ans=0;
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>h;
    if(h>=max){max=h,ans++;}
  }
  cout<<ans<<endl;

  return 0;
}


Measured memory_bytes: 3568
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define FOR(i, a, b) for(ll i = (ll)a; i <= (ll)b; i++)
#define DEC(i, a, b) for(ll i = (ll)a; i >= (ll)b; i--)
typedef pair<ll, ll> pi;
typedef pair<ll, pi> pii;
typedef pair<pi, pi> pipi;
#define f first
#define s second
typedef vector<ll> vi;
typedef vector<pi> vpi;
typedef vector<pii> vpii;
#define pb push_back
#define pf push_front
#define all(v) v.begin(), v.end()
#define disc(v) sort(all(v)); v.resize(unique(all(v)) - v.begin());
#define INF (ll) 1e9 + 100
#define LLINF (ll) 1e18
#define fastio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());    //can be used by calling rng() or shuffle(A, A+n, rng)
inline ll rand(ll x, ll y) { ++y; return (rng() % (y-x)) + x; } //inclusivesss

int x, ans;

int main() {
	fastio; cin >> x;
	ans += (x <= 1999);
	ans += (x <= 1799);
	ans += (x <= 1599);
	ans += (x <= 1399);
	ans += (x <= 1199);
	ans += (x <= 999);
	ans += (x <= 799);
	ans += (x <= 599);
	cout << ans;
}


Measured memory_bytes: 3652
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define FOR(i,n,m) for(ll i=(n);i<(m);i++)
#define REP(i,n) FOR(i,0,n)
#define REPR(i,n) for(ll i=(n);i>=0;i--)
#define all(vec) vec.begin(),vec.end()
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using P=pair<ll,ll>;
using PP=pair<ll,P>;
using vp=vector<P>;
using vpp=vector<PP>;
using vs=vector<string>;
#define fi first
#define se second
#define pb push_back
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>bool chmin(T &a,const T &b){if(a>b){a=b;return true;}return false;}
const ll MOD=1000000007LL;
const int INF=1<<30;
const ll LINF=1LL<<60;
int main(){
    vl vec(3);
    REP(i,3){
        cin>>vec[i];
    }
    sort(all(vec));
    int a=0;
    REP(i,3){
        if(vec[i]%2){
            a++;
        }
    }
    int ans=0;
    if(a==1){
        REP(i,3){
            if(vec[i]%2==0){
                vec[i]++;
            }
        }
        ans++;
    }else if(a==2){
        REP(i,3){
            if(vec[i]%2){
                vec[i]++;
            }
        }
        ans++;
    }
    REP(i,2){
        ans+=abs(vec[i]-vec[2])/2;
    }
    cout<<ans<<endl;
    return 0;
}

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

typedef long long ll;
#define endl "\n"
#define deb(x) cerr << #x << ":" << x << "\n"

void DP_82(){
    string s,c,start="",end="";
    cin>>s;
    ll q,t,f;
    bool normal=1;
    cin>>q;
    while(q--){
        cin>>t;
        if(t==1){
            normal^=1;
        }else{
            cin>>f>>c;
            if(!normal)f=3-f;
            if(f==1)start=c+start;
            else end+=c;
        }
    }
    if(!normal){
        swap(start,end);
        reverse(s.begin(),s.end());
        reverse(start.begin(),start.end());
        reverse(end.begin(),end.end());
    }
    cout<<start<<s<<end;
}

int main()
{

    ios::sync_with_stdio(0);
    cin.tie(0);
    DP_82();
    return 0;
}

Measured memory_bytes: 1160
#ifndef LOCAL
#pragma GCC optimize("O3")
#endif
#include <iostream>
using namespace std;

int main(){
    string str;
    string answer = "Yes";

    cin >> str;

    for (int i=0; i < str.size(); i++){
        if ((i+1) % 2 == 1 and str.substr(i, 1) == "L") answer = "No";
        else if ((i+1) % 2 == 0 and str.substr(i, 1) == "R") answer = "No"; 
       // cout << i << endl;
       // cout << (i+1) % 2 << endl;
       // cout << str.substr(i, 1);

    }

    cout << answer << endl;

}

Measured memory_bytes: 768
#include<bits/stdc++.h>
using namespace std;
int dp[100001]; int a[100001];
int main()
{
    int t,i,n,j,k;
        cin>>n;
        for(j=1;j<=n;j++)
            cin>>a[j];
        dp[1]=0;
        dp[2]=abs(a[2]-a[1]);
        for(j=3;j<=n;j++)
        {
            dp[j]=min((dp[j-1]+abs(a[j-1]-a[j])),(dp[j-2]+abs(a[j]-a[j-2])));
        }
        cout<<dp[n]<<endl;
    return 0;
}

Measured memory_bytes: 1024
#include "bits/stdc++.h"
 
typedef long long ll;
#define int ll
#define fi first
#define se second
#define SORT(a) sort(a.begin(),a.end())
#define rep(i,n) for(int i = 0;i < (n) ; i++) 
#define REP(i,n) for(int i = 0;i < (n) ; i++) 
#define MP(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define INF LLONG_MAX/2
 
using namespace std;
int MOD = 1000000007;
int V[101][100100];
signed main(){

    int n,W;
    cin >> n >> W;
    int a,b;
    cin >> a >> b;
    rep(i,n) rep(j,100010)V[i][j] = INF;
    V[0][b] = a;
    for(int i = 1;i < n;i++){
        int w,v;
        cin >> w >> v;
        rep(j,100005){
            if(j < v)V[i][j] = V[i-1][j];
            else if(j == v)V[i][j] = min(V[i-1][j],w);
            else V[i][j] = min(V[i-1][j],V[i-1][j-v]+w);
        }
    }
    int maxi = 0;
    rep(i,100001){
        if(V[n-1][i] <= W)maxi = max(maxi,i);
    }
    cout << maxi << endl;

    return 0;   
}

// g++ -std=c++14 code1.cpp
// rm -r -f test;oj dl https://dp.contest.atcoder.jp/tasks/dp_a
// rm -r -f test;oj dl http://yahoo-procon2017-qual.contest.atcoder.jp/tasks/yahoo_procon2017_qual_c

Measured memory_bytes: 78464
N,W=map(int,input().split())
DP=[[0 for j in range(W+1)]for i in range(N+1)]
for i in range(N):
    w,v=map(int,input().split())
    for j in range(1,W+1):
        if j>=w:
            DP[i+1][j]=max(DP[i][j-w]+v,DP[i][j])
        else:
            DP[i+1][j]=DP[i][j]
print(DP[N][W])


Measured memory_bytes: 171400
# https://beta.atcoder.jp/contests/arc098/tasks/arc098_a
# C - Attention

# C_Attention_beta.py

N = int(input())
S = input()

e = [0 for i in range(N)]
w = [0 for i in range(N)]

# 累積和を求める
# そこからE側の人で、Wを向くべきなのにEを向いている人
for i in range(N):
    if i > 0:
        w[i] += w[i-1]
    if i < N-1:
        if S[i] == "W":
            w[i+1] += 1
# そこからW側の人で、Eを向くべきなのにWを向いている人
for j in range(N):
    i = N-1-j
    if i < N-1:
        e[i] += e[i+1]
    if i > 0:
        if S[i] == "E":
            e[i-1] += 1

min = 10 ** 6
for i in range(N):
    total = e[i] + w[i]
    if total < min:
        min = total
print(min)


Measured memory_bytes: 27332
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <map>
#include <cstring>
#include <string>
#include <vector>
#include <cmath>
#include <random>
#include <set>
#include <deque>
#include <queue>
#include <bitset>
#include <stack>

#define mod 1000000007
#define INF2 9999999999
#define INF (1<<30)
#define rep(i,n) for(int (i)=0; (i)<(n); (i)++)
//#define P pair<int, int>

using namespace std;
using ll = __int64_t;

int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};
int DX[] = {1, 1, 0, -1, -1, -1, 0, 1};
int DY[] = {0, -1, -1, -1, 0, 1, 1, 1};

struct edge{
  int from;
  int to;
};

void solve(){
  int n, m;
  set<int> s;
  cin >> n >> m;
  
  edge e[m];
  rep(i, m) cin >> e[i].from >> e[i].to;

  rep(i, m){
    if(e[i].from == 1){
      s.insert(e[i].to);
    }
  }
  rep(i, m){
    if(e[i].to == n){
      decltype(s)::iterator it = s.find(e[i].from);
      if(it != s.end()){
        cout << "POSSIBLE" << endl;
        return;
      }
    }
  }
  cout << "IMPOSSIBLE" << "\n";
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  solve();
  return 0;
}


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

#define fio ios_base::sync_with_stdio(false);cin.tie(NULL)
// #define int long long 

using namespace std;

int32_t main()
{
	fio;
	int n;
	cin>>n;
	int *a=new int[n+1];
	fill(a,a+n+1,0);
	for(int i=0;i<n-1;i++)
	{
		int num;
		cin>>num;
		a[num]++;
	}

	for(int i=1;i<=n;i++)
	{
		cout<<a[i]<<endl;
	}
	return 0;
}

Measured memory_bytes: 4432