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

int main() {
  int a,b,c;
  cin>>a>>b>>c;;
  bool s=false;
  if(a==b&&a!=c)s=true;
  if(a==c&&a!=b)s=true;
  if(c==b&&a!=c)s=true;
  if(s)cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
  
  
}



Measured memory_bytes: 256
//A.cpp
#include <iostream>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <queue>
#include <stack>
#include <math.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
ll gcd(ll a,ll b){return b!=0?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}
const ll mod=1e9+7;


int main(){
  int n,m;
  cin >> n >> m;
  int lmax = 0;
  int rmin = 1e6;
  int a,b;
  rep(i,m){
    cin >> a >> b;
    lmax = max(lmax,a);
    rmin = min(rmin,b);
  }
  if(rmin >= lmax){
    printf("%d\n", rmin - lmax + 1);
  }else{
    printf("0\n");
  }
  return 0;
}


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

int A,B,C,X;
int t = 0;

int main() {
  cin >>A>>B>>C>>X;
  for (int i=0;i<A+1;i++) {
    for (int j=0;j<B+1;j++) {
      for (int s=0;s<C+1;s++) {
        if(500*i+100*j+50*s==X){
          t++;}
    }
    }}
  

   cout<<t<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
 
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define REP(i,n) for(int i=0;i<(n);i++)
#define RREP(i,n) for(int i=(n)-1;i>=0;i--)
#define VSORT(v) sort(v.begin(), v.end())
#define DVSORT(v) sort(v.begin(), v.end(),greater<int>())
#define SORT(v, n) sort(v, v+n)
#define DSORT(v,n) sort(v, v+n,greater<int>())
#define vi vector<int>
#define pb push_back
#define P pair<int,int>
 
template <class T> void chmin(T&a,const T&b) { a = min(a,b); }
template <class T> void chmax(T&a,const T&b) { a = max(a,b); }
 
void print(){cout<<endl;}
template <class Head, class... Tail>
void print(Head&& h,Tail&&... t){ 
	if(sizeof...(t)==0)
		cout<<h;
	else
		cout<<h<<' ';
	print(move(t)...);
}
 
const double EPS =1e-9;
const long INF =2147483647;//32bit 2*1e+9
const long MOD =1e+9+7;
#define PI 3.14159265258979
 
int dy[]={0, 0, 1, -1, 1, 1, -1, -1};
int dx[]={1, -1, 0, 0, 1, -1, -1, 1};

int N,numbers[20],result=0;

void fn(int i,int oc){
	if(i==N){
		if(oc!=N) result++;
	}else{
		FOR(j,-1,2)
			fn(i+1,oc+((numbers[i]+j)%2));
	}
	return;
}

int main(void){	
	cin>>N;
	REP(i,N) cin>>numbers[i];
	
	fn(0,0);
	print(result);
	return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <string>
#include <cmath>
#include <vector>
#include <algorithm>
#include <functional>
#include <cstdio>
#include <cstdlib>
#include <iomanip>
#include <cctype>
#include <bits/stdc++.h>
#include <queue>

using namespace std;
// for loop
#define F(i, L, R) for(long i = L; i < R; i++)
#define FE(i, L, R) for(long i = L; i <= R; i++)
// for (reversed)
#define FR(i, L, R) for(long i = L; i > R; i--)
#define FRE(i, L, R) for(long i = L; i >= R; i--)

// data types
#define Int long
#define ul unsigned long
#define ll long long
#define ull unsigned long long
#define ui unsigned int
#define us unsigned shoft

// vectors
typedef vector<int> vi;
typedef vector<long> vl;
typedef vector<long long> vll;
typedef vector<vi> vvi;
typedef pair<int, int> ii;
#define ALL(c) (c).begin(),(c).end()
#define last(vec) vec.size()-1
#define lastEle(vec) vec[last(vec)]
#define pb push_back
#define InputV(a, n) F(i,0,n){long l; cin >> l; a.pb(l);}

// debug
#define DBG(vari) cerr<<#vari<<" = "<<(vari)<<endl;
#define printA(a, L, R) FE(i, L, R) cout << a[i] << (i==R?'\n':' ')
#define printAF(a, L) printA(a, 0, L-1)
#define printV(a) printA(a, 0, a.size()-1)

// utils
#define char2int(c) (c-'0')
#define bit(x, i) (x&(1<<i))
#define space ' '
#define PI 3.14159265358979323

#define TST 0
int main() {
#if TST==1
    ifstream in ("input.txt");
    cin.rdbuf(in.rdbuf());
#endif
    long n;
    cin >> n;
    long k;
    cin >> k;
    vl h(n);
    // dp table has mininum cost to go i-1 th.
    // for convenience, allocate more memory than actually is
    vll dp(n+100);
    F(i, 0, n){
        cin >> h[i];
    }
    dp.assign(n+100, pow(10, 9));
    dp[0] = 0;
    F(i, 0, n){
        FE(j, 1, k){
        dp[i+j] = min(dp[i+j], dp[i] + abs(h[i] - h[i+j]));
        
        
    }}
    cout << dp[n-1] << endl;
#if TST==1

#endif
}


Measured memory_bytes: 1792
#include <iostream>
using namespace std;
int main(void) {
	int n;
	int i;

	int h;
	int w;

	int A = 0;
	int B = 0;
	int C = 0;

	cin >> n;
	cin >> h;
	cin >> w;

	for (i = h; i <= n; i++) {
		A++;
	}
	for (i = w; i <= n; i++) {
		B++;
	}
	C = A * B;
	cout << C;

	return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;

typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;

template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const int MOD = 1000000007;
const ll INF = 1e18;
const int MX = 100001; //check the limits, dummy

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);    
    
    int N, M; cin >> N >> M;
    vpl data;
    F0R(i, N) {
		ll A, B; cin >> A >> B;
		//sort by increasing date
		data.pb(mp(A, B));
	}
	sort(all(data));
	ll ans = 0;
	
	int nxt = 0;
	priority_queue<ll> pq;

	FOR(i, 1, M+1) {
		while (nxt < N && data[nxt].f == (ll) i) {
			pq.push(data[nxt].s); nxt++;
		}
		if (!pq.empty()) {
			ans += pq.top();
			pq.pop();
		}
	}
    
    cout << ans << endl;
    return 0;
}

// read the question correctly (ll vs int)
// template by bqi343


Measured memory_bytes: 3696
parseInt(x) = parse(Int, x)
parseArray(x::Array{SubString{String}, 1}) = map(parseInt, x)

function main()
  S=readline()|>strip
  
  j=-1
  result="Good"
  for i in map(parseInt,collect(S))
    i==j && (result="Bad")
    j=i
  end
  println(result)
end

main()


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

using namespace std;

int main(){
  int N, tmp;
  cin >> N;
  vector<int> T;
  for (int i=0; i<N; i++){
    cin >> tmp;
    T.push_back(tmp);
  }
  int ans = 0;
  for (int i=0; i<N; i++){
    for (int j=i+1; j<N; j++){
      ans += T[i] * T[j];
    }
  }
  cout << ans << endl;
  return 0;
}

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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define CHMIN(a,b) a=min((a),(b))
#define CHMAX(a,b) a=max((a),(b))

// mod
const ll MOD = 1000000007ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

// floating
typedef double Real;
const Real EPS = 1e-11;
#define EQ0(x) (abs(x)<EPS)
#define EQ(a,b) (abs(a-b)<EPS)
typedef complex<Real> P;

int n;
int a[25][21];

ll dp[25][1<<21];

int main(){
  scanf("%d",&n);
  REP(i,n)REP(j,n)scanf("%d",&a[i][j]);
  dp[0][0] = 1;
  REP(i,n)REP(msk,1<<n)if(dp[i][msk]){
    REP(j,n)if(a[i][j] && !(msk>>j&1)){
      (dp[i+1][msk | (1<<j)] += dp[i][msk]) %= MOD;
    }
  }
  printf("%lld\n",dp[n][(1<<n)-1]);
  return 0;
}


Measured memory_bytes: 311552
X,K,D = map(int,input().split())

#十分に原点から離れている場合
if abs(X) >= K*D:
    ans = abs(X) - K*D
else:
    t = (abs(X) - D*(K%2)) // (2*D)
    t = 2*t + K%2
    if X > 0:
        t = -t
    A = [t-2,t,t+2]
    ans = 3*D
    for a in A:
        if abs(X+D*a)<ans:
            ans = abs(X+D*a)


print(ans)

Measured memory_bytes: 9096
#include <bits/stdc++.h>
#include <math.h>
#define ALL(a)    a.begin(), a.end()
using namespace std;

int main() {
long long int N, M;cin >> N >> M;
vector<int> A(N);
long long count = 0;
bool C = 1;

for(int i = 0; i < M; i++){
cin >> A[i];
count += A[i];
if(count > N){cout << "-1";C = 0;break;}
}
if(C)cout << N - count << endl;


}

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

#define int long long int
#define IOS ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define endl "\n"

int32_t main()
{
	IOS;
	float r;
	cin >> r;
	cout << 6.28 * r << endl;



	return 0;
}

Measured memory_bytes: 3756
#include <bits/stdc++.h>
using namespace std;
int main(){
  string S;cin>>S;
  int i=0;
  while(i<S.size()&&S.at(i)!='C')i++;
  if(i==S.size())cout<<"No"<<endl;
  else{
    while(i<S.size()&&S.at(i)!='F')i++;
    if(i==S.size())cout<<"No"<<endl;
    else cout<<"Yes"<<endl;
  }
}

Measured memory_bytes: 256
#include<iostream>
#include<math.h>
using namespace std;
 
int main(){
  int n;
  cin>>n;
  int a[n];
  int sum=0;
  for(int i=0;i<n;i++){
  	cin>>a[i];
  }
  for(int i=0;i<n-1;i++){
  	for(int j=i+1;j<n;j++){
  	  	sum+=a[i]*a[j];
  	}
  }
  cout<<sum;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define f first
#define s second
#define mod 1000000007
#define N 500043
#define mp(a,b) make_pair(a,b)
#define loop(a,b) for(int i=a;i<b;i++)
#define test int t; cin >> t; while(t--)
using namespace std;
 
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    ll a,b;
    cin >> a >> b;
    ll x,y;
    cin >> x >> y;
    cout << max(y*b,max(a*x,max(b*x,a*y)));
}

Measured memory_bytes: 3652
#include<stdio.h>
#include<stdlib.h>

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;
#define NIL NULL

Node root;
/*
Node treeMinimum(Node x){


}

Node treeMaximum(Node x){


}
*/
Node treeSearch(Node u, int k){
  while(u!=NIL && k != u->key){ 
    if(k<u->key)u=u->left;
    else u=u->right;
  }
  return u;
}
/*
Node treeSuccessor(Node x){


}

void treeDelete(Node z){
  Node y; // node to be deleted
  Node x; // child of y



}
*/

void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;

  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;

 while(x!=NIL){
   y=x;
    if(z->key < x->key){
      x=x->left;
    }
    else {
      x=x->right;
    }
  }
  z->parent=y;
  if(y==NIL){
    root=z;
  }
  else{
    if(z->key < y->key){
      y->left=z;
    }
    else{
      y->right=z;
    }
  }


}

void inorder(Node u){
if(u==NIL)return ;
  inorder(u->left);
  printf(" %d",u->key);
  inorder(u->right);

}
void preorder(Node u){
 if(u==NIL)return ;
  printf(" %d",u->key);
  preorder(u->left);
  preorder(u->right);
}


int main(){
  int n, i, x;
  char com[20];
  scanf("%d", &n);

  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
  if ( com[0] == 'f' ){
      scanf("%d", &x);
      Node t = treeSearch(root, x);
      if ( t != NIL ) printf("yes\n");
      else printf("no\n");
    }
    if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
   } else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    }
  }

  return 0;
}

Measured memory_bytes: 19364
#Treeอสิระท่ีเช่ือมต่อทกุๆVertixในGraph โดยพยายามหาค่าให้มีค่าต่ำที่สุดในการสร้าง

n = int(input()) #รับจำนวน node ทั้งหมด
a = []

for i in range(n):
    inp = input() #รับข้อมูลทั้งหมด
    if "-1" in inp:
        inp = inp.replace("-1","10000") #แทนที่ -1 ด้วย 100000
    a.append(list(map(int, inp.split()))) #splitข้อมูลเป็น int เก็บค่าข้อมูลไว้ใน list

w = 0
v = set()
v.add(0)

while len(v) < n: #วน loop ตามจำนวน n 
    min_w   = 10000 #min weight
    min_idx = 0 #min index
    i = 0
    for node in v:
        if min_w > min(a[node]):
            min_w = min(a[node])
            i = node
            min_idx = a[i].index(min_w)
    if min_idx in v:
        a[i][min_idx] = 10000
        continue
    else:
        w += min_w
        v.add(min_idx)

print(w)



Measured memory_bytes: 5948
#include<bits/stdc++.h>
#define to edge[i].v
#define mp make_pair
#define rint register int
#define fgx cerr<<"-------------"<<endl
#define N 1000000
using namespace std;
typedef long long ll;
typedef long double db;
typedef pair<int,int> pii;
void dbg(){cerr<<endl;}
template<typename A,typename... B>void dbg(A x,B... y){cerr<<x<<" ";dbg(y...);}
#define debug(...) cerr<<#__VA_ARGS__<<"=",dbg(__VA_ARGS__)
char c[N];
int main()
{	scanf("%s",c+1); ll ans=0; int n=strlen(c+1),C=0,cur=0;
	for(rint i=n;i>=1;i--)
	if(c[i]=='C'){if(C)cur=0;else C=1;}
	else if(c[i]=='B'){if(C)cur++,C=0;else cur=0;}
	else{if(C)cur=C=0;else ans+=cur;}
	cout<<ans;
	return 0;
}


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

int gcd(int x, int y) { return (x % y)? gcd(y, x % y): y; }

int main(void) {
    int K;
    cin >> K;

    int a[K+1],b[K+1],c[K+1];

    int total = 0;
    for(int i=1; i<=K; i++){
      for(int j=1; j<=K; j++){
          for(int l=1; l<=K; l++){
            total += gcd(gcd(i,j),l);
          }
      }

    }

    cout << total << endl;

    return 0;
}


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

using namespace std;
const int mod = 1e9+7;

int main(){
	int n;
	cin >> n;
	vector<double> p(n);
	for(int i = 0; i < n; i++){
		cin >> p[i];
	}
	vector<vector<double> > dp(n,vector<double>(n+1));
	dp[0][1] = p[0];
	dp[0][0] = 1-p[0];
	
	for(int i = 1; i < n; i++){
		for(int j = 0; j <= n; j++){
			if(j)dp[i][j] = dp[i-1][j-1] * p[i] + dp[i-1][j] * (1-p[i]);
			else dp[i][j] = dp[i-1][j] * (1-p[i]);    
		}
	}
	double ans = 0.0;
	for(int j = n/2+1; j<= n; j++) ans+=dp[n-1][j];
	cout << fixed << setprecision(12);
	cout << ans << "\n";
 	return 0;
}


Measured memory_bytes: 70656
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i < (n); i++)
#define lower(s) transform(s.begin(), s.end(), s.begin(), ::tolower)
using namespace std;
using ll = long long;
int INF = 1001001001;

int main() {
  int n;
  cin >> n;
  vector<int> x(n);
  vector<int> y(n);
  rep(i, n) cin >> x[i] >> y[i];

  vector<int> p;
  rep(i, n) p.push_back(i);
  double ans = 0;
  do {
    double sum = 0;
    rep(i, n-1) {
      int xl = x[p[i+1]] - x[p[i]];
      int yl = y[p[i+1]] - y[p[i]];
      sum += sqrt(xl * xl + yl * yl);
    }
    ans += sum;
  } while(next_permutation(p.begin(), p.end()));

  int n2 = 1;
  for(int i=1; i<=n; i++) n2 *=i;

  ans /= n2;
  printf("%.10f", ans);
  return 0;
}

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

struct StNode
{
  StNode* m_poParnt;
  StNode* m_poLeft;
  StNode* m_poRigt;
  int m_nKey;

  StNode(int nNo) :
    m_poParnt(nullptr), m_poLeft(nullptr), m_poRigt(nullptr), m_nKey(nNo)
  { }
};

void fnPreOrder(StNode* poNode)
{
  if (poNode == nullptr)  return;

  cout << " " << poNode->m_nKey;
  fnPreOrder(poNode->m_poLeft);
  fnPreOrder(poNode->m_poRigt);
}

void fnInOrder(StNode* poNode)
{
  if (poNode == nullptr)  return;

  fnInOrder(poNode->m_poLeft);
  cout << " " << poNode->m_nKey;
  fnInOrder(poNode->m_poRigt);
}

void fnInsert(StNode*& rpoRoot, StNode* poNewNod)
{
  StNode* poParnt = nullptr;
  StNode* poNode = rpoRoot;

  while (poNode != nullptr)
  {
    poParnt = poNode;
    if (poNewNod->m_nKey < poNode->m_nKey)
      poNode = poNode->m_poLeft;
    else
      poNode = poNode->m_poRigt;
  }

  poNewNod->m_poParnt = poParnt;
  if (poParnt == nullptr)
    rpoRoot = poNewNod;
  else if (poNewNod->m_nKey < poParnt->m_nKey)
    poParnt->m_poLeft = poNewNod;
  else
    poParnt->m_poRigt = poNewNod;
}

void fnBinSchTree(StNode*& rpoRoot)
{
  int nMaxSiz;
  cin >> nMaxSiz;

  for (int i = 0; i < nMaxSiz; ++i)
  {
    string sCmd;
    cin >> sCmd;
    if (sCmd[0] == 'i')
    {
      int nNo;
      cin >> nNo;
      StNode* poNewNod = new StNode(nNo);
      fnInsert(rpoRoot, poNewNod);
    }
    if (sCmd[0] == 'p')
    {
      fnInOrder(rpoRoot);
      cout << endl;
      fnPreOrder(rpoRoot);
      cout << endl;
    }
  }
}

void fnPstOrder(StNode* poNode)
{
  if (poNode == nullptr)  return;

  fnPstOrder(poNode->m_poLeft);
  fnPstOrder(poNode->m_poRigt);
  delete poNode;
}

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  StNode* poRoot = nullptr;

  fnBinSchTree(poRoot);
  fnPstOrder(poRoot);
  return 0;
}

Measured memory_bytes: 26560
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>

using namespace std;

int main() {
	int N,W;
	cin >>N >>W;
	vector< pair<int,int> > A(N);
	for(int i = 0; i< N ; i++) {
		cin >>A[i].first;
		cin >>A[i].second;
	}
	
	vector<vector<int> > dp(N, vector<int>(W+1));
	for(int i = 0; i<N;i++){
		for(int c = 0;c<=W;c++){
			int k = c-A[i].second;
			if(i == 0){
						if(k >=0)	dp[0][c] = A[0].first;
						else	dp[0][c] = 0;
 					}	
			else if(k < 0) {
				dp[i][c] = dp[i-1][c];
				}
			else {
					if(A[i].first+dp[i-1][k]<dp[i-1][c])
							dp[i][c] = dp[i-1][c];
					else dp[i][c] = A[i].first + dp[i-1][k];
				}
		}
	}

	cout << dp[N-1][W] << endl;
	return 0 ;
}

Measured memory_bytes: 4964
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;
int n,m;
int tbl[300000];
int sum[300000];
int cnt[300001];
int s[300001],t[300001];
int a[300001];
ll G[300000];
int main(){
  cin >> n>>m;
  for(int i=0;i<n;++i)
    cin>>a[i];
  for(int i=0;i+1<n;++i){
    s[i]=a[i];
    t[i]=a[i+1];
    if(s[i]>t[i])
      t[i]+=m;
    int x = s[i];
    int y = t[i];
    if(y-x>1){
      sum[y]+=y-x-1;
      cnt[x+1]++;
      cnt[y]--;
    }
  }
  for(int i=1;i<=2*m;++i)
    cnt[i]+=cnt[i-1];
  for(int i=0;i+1<n;++i)
    G[0]+=t[i]-s[i];
  for(int i=0;i+1<n;++i){
    int x=s[i], y=t[i];
    if(x<m+1 && m+1<=y)
      G[1]+=m-x;
  }
  for(int f=1;f+1<=m;++f)
    G[f+1]=G[f]+cnt[f]+cnt[m+f]-sum[f]-sum[m+f];
  ll gain = 0;
  for(int f=1;f<=m;++f)
    gain = max(gain, G[f]);
  cout << G[0]-gain << endl;
  return 0;
}


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


// type definitions
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector< vi > vvi;
typedef pair<int, int> pii;
typedef vector<pii> vpii;
typedef complex<int> ci;
typedef complex<double> cd;
typedef complex<long double> cld;

// macros
#define rep(i, a, b) for(int i=a; i<b; i++)
#define TIME clock() * 1.0 / CLOCKS_PER_SEC
#define all(c) c.begin(), c.end()
#define tr(c, it) for(auto it=(c).begin(); it!=c.end(); it++)
#define pb push_back
#define mp make_pair
#define bitcount __builtin_popcount
#define ispresent(c, x) ((c).find(x) != (c).end())
#define watch(x) cout<< (#x) << " is " << (x) <<"\n";
#define sz(x) ((int)((x).size()))
#define UNIQUE(c) (c).resize(unique(all(c)) - (c).begin())
#define pii2ll(p) ((ll)(p).first<<32 | (p).second)

// template functions
template <typename T>
inline void printV(vector<T>& a) { rep(i, 0, sz(a)) { cout<<a[i]<<" "; } cout<<"\n"; }
template <typename T>
inline void printV(vector<T>& a, int n) { rep(i, 0, n) { cout<<a[i]<<" "; } cout<<"\n"; }
template <typename T>
inline void printVV(vector<vector<T>>& a)
{
	rep(i, 0, sz(a)) {
		printV(a[i]);
	}
	cout<<"\n";
}

template <typename T>
inline void clearVV(vector<vector<T>>& a)
{
	for(auto& x:a) {
		x.clear();
	}
	a.clear();
}
template <typename T>
inline void assignVV(vector<vector<T>> &a, T val)
{
	for(int i=0; i<sz(a); i++) {
		for(int j=0; j<sz(a[i]); j++) {
			a[i][j]=val;
		}
	}
}


// constants
const long double eps = 1e-9;
const int inf = 5e8;
const int modn = 1e9+7;
const int MAX = 1e5;

string s, t;
string lcs;



int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    // Your code here
    s+='.', t+='.';
    string stmp, ttmp;
    cin>>stmp>>ttmp;
    s+=stmp;
    t+=ttmp;
	int n1=s.size()-1;
	int n2=t.size()-1;
	vector<vector<int>> dp(n1+1, vector<int>(n2+1));
	vector<vector<pair<int, int>>> nx(n1+1, vector<pair<int, int>>(n2+1));
	
	for(int i=1; i<=n1; i++) {
		for(int j=1; j<=n2; j++) {
			int ans1=max((dp[i-1][j]), (dp[i][j-1]));
			bool flag=1;
			if(s[i]==t[j]) {
				int ans2=1+(dp[i-1][j-1]);
				if(ans2>ans1) {
					dp[i][j]=dp[i-1][j-1]+1;
					nx[i][j]={i-1, j-1};
					flag=0;
				}
				assert(ans2>=ans1);
			}
			if(flag) {
				dp[i][j]=(ans1==(dp[i-1][j])?dp[i-1][j]:dp[i][j-1]);
				if(ans1==dp[i-1][j]) {
					nx[i][j]={i-1, j};
				}
				else {
					nx[i][j]={i, j-1};
				}
			}
		}
	}
	function<void(int, int)> printlcs = [&](int x, int y)
	{
		if(x<=0 or y<=0) return;
		if(s[x]==t[y] and nx[x][y]==make_pair(x-1, y-1)) {
			lcs+=s[x];
		}
		int newx=nx[x][y].first;
		int newy=nx[x][y].second;
		printlcs(newx, newy);
	};
	printlcs(n1, n2);
	//~ for(int i=0; i<sz(nx); i++) {
		//~ for(int j=0; j<sz(nx[i]); j++) {
			//~ cout<<nx[i][j].first<<" "<<nx[i][j].second<<"\n";
		//~ }
	//~ }
	reverse(all(lcs));
	cout<<lcs<<"\n";
    return 0;
}



Measured memory_bytes: 106240
#include <bits/stdc++.h>
#define MAX 100005
#define ll long long
#define upperlimit 1000100
#define INF 1e18
#define eps 1e-8
#define endl '\n'
#define pcc pair<char,char>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define tr(container,it) for(typeof(container.begin()) it=container.begin();it!=container.end();it++)
#define MOD 1000000007
#define slld(t) scanf("%lld",&t)
#define sd(t) scanf("%d",&t)
#define pd(t) printf("%d\n",t)
#define plld(t) printf("%lld\n",t)
#define mp(a,b) make_pair(a,b)
#define FF first
#define SS second
#define pb(x) push_back(x)
#define vi vector<int>
#define clr(a) memset(a,0,sizeof(a))
#define debug(a) printf("check%d\n",a)
#define csl ios::sync_with_stdio(false);cin.tie(0);
#define fi(a,b,c) for(int i=a;i<b;i=i+c)
#define fj(a,b,c) for(int j=a;j<b;j+=c)
using namespace std;
 
ll gcd(ll n1,ll n2) {
	if(n1%n2==0)return n2;
	return gcd(n2,n1%n2);
}
ll powmod(ll base,ll exponent) {
	ll ans=1;
	while(exponent){
		if(exponent&1)ans=(ans*base)%MOD;
		base=(base*base)%MOD;
		exponent/=2;
	}
	return ans;
}
ll max(ll a,ll b,ll c) {
	return max(a,max(b,c));
}
int max(int a,int b,int c) {
	return max(a,max(b,c));
}

int main()
{
	string s;
	cin>>s;
	int cur=0, maxc=0;
	for(int i=0;i<s.length();i++){
		if(s[i]=='R'){
			cur++;
		}else{
			maxc=max(maxc, cur);
			cur=0;
		}
	}
	cout<<max(maxc, cur);
}

Measured memory_bytes: 3616
N,M,C = map(int,input().split())
B=[0]*M
tmp = input().split()
for m in range(M):
    B[m] = int(tmp[m])

cnt = 0
for n in range(N):
    tmp = input().split()
    point = 0
    for m in range(M):
        point += B[m]*int(tmp[m])
    point += C
    if point > 0:
        cnt += 1

print(cnt)

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

#define REP(i,n) for(int i = 0;i < n;i++)
#define REPR(i,n) for(int i = n-1;i >= 0;i--)
#define FOR(i,m,n) for(int i = m;i < n;i++)
#define PRINT(s) cout<<s
#define PRINTS(s) cout<<s<<' '
#define PRINTL(s) cout<<s<<endl
#define INF 2e9
#define ALL(v) v.begin(),v.end()
#define ll long long
#define GREATER greater<int>()

using namespace std;

string pop_back(string s){
    string t = s.substr(0,s.size()-1);
    return t;
}

int gcd(int max,int min){
    
    if(max<min){
        int tmp=max;
        max=min;
        min=tmp;
    }

    if(max%min==0)return min;
    else return gcd(min,max%min);

}

int main(void){

    string a,b;
    cin>>a>>b;
    string c=a+b;
    int n=stoi(c);
    for(int i=0;i*i<=n;i++){
        if(i*i==n){
            puts("Yes");
            return 0;
        }
    }
    puts("No");

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <tuple>
using namespace std;

int main(){
	int N;
	cin >> N;
	vector<string>S(N);
	vector<int>P(N);
	vector<tuple<string,int,int> >p(N);
	for(int i=0;i<N;i++){
		cin >> S[i] >> P[i];
		p[i]=make_tuple(S[i],-1*P[i],i);
	}
	
	sort(p.begin(),p.end());
	
	for(int i=0;i<N;i++)cout<<1+get<2>(p[i])<<endl;
		
}

Measured memory_bytes: 256
import copy

s = input()
t = input()

sn = len(s)
tn = len(t)
answer = int(copy.deepcopy(tn))

for i in range(sn-tn+1):
    sk = s[i:i+tn]
    count = 0
    for j in range(tn):
        if sk[j] != t[j]:
            count += 1
    if count < answer:
        answer = count

print(answer)

Measured memory_bytes: 9220
#include <cstdio>
#include <string>

using namespace std;

int n,c=0;
char k[256],v[256];

main(){
  scanf("%s%d",k,&n);
  while(n--){
    scanf(" %s ", v);
    for(int i=0;i<10;i++) v[i+10] = v[i];
    string s(v);
    if(s.find(k) != string::npos) c++;
  }
  printf("%d\n", c);
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long ll;
typedef pair<ll,ll> P;
const ll mod=1000000007;
const ll LINF=1LL<<60;
const int INF=1<<30;

int main(){
	int x,y;
	cin >> x >> y;
	if (x == y && x == 1){
		cout << 1000000 << endl;
	}

	else{
		ll ans = 0;
		if(x == 1) {
			ans += 300000;
		}
		if(x == 2){
			ans += 200000;
		}
		if(x == 3){
			ans += 100000;
		}

		if(y == 1) {
			ans += 300000;
		}
		if(y == 2){
			ans += 200000;
		}
		if(y == 3){
			ans += 100000;
		}
		cout << ans <<endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <string.h>
#include <vector>
#include <cstdio>
#include <cmath>

using namespace std;

int main(){
    int n,a,b;
  cin>>n>>a>>b;
  if((n*a-b)>0){
    cout<<b;
  }else{
    cout<<a*n;
  }
    return 0;
}

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

int main() {
  int N;
  cin >> N ;
  vector<int> p(N);
  for (int i = 0; i < N; i++) {
    cin >> p.at(i);
  }
  int count = 0;
  for (int i = 0; i < N - 1; i++) {
    for (int j = i + 1; j < N; j++) {
      count += p.at(i) * p.at(j);
    }
  }
  cout << count <<endl;
}

Measured memory_bytes: 256
class UnionFind:
    def __init__(self, n):
        self.parent = list(range(n)) #親ノード
        self.size = [1]*n #グループの要素数
 
    def root(self, x): #root(x): xの根ノードを返す．
        while self.parent[x] != x:
            self.parent[x] = self.parent[self.parent[x]]
            x = self.parent[x]
        return x 
 
    def merge(self, x, y): #merge(x,y): xのいる組とyのいる組をまとめる
        x, y = self.root(x), self.root(y)
        if x == y: return False
        if self.size[x] < self.size[y]: x,y=y,x #xの要素数が大きいように
        self.size[x] += self.size[y] #xの要素数を更新
        self.parent[y] = x #yをxにつなぐ
        return True
 
    def issame(self, x, y): #same(x,y): xとyが同じ組ならTrue
        return self.root(x) == self.root(y)
        
    def getsize(self,x): #size(x): xのいるグループの要素数を返す
        return self.size[self.root(x)]

# coding: utf-8
# Your code here!
import sys
read = sys.stdin.read
readline = sys.stdin.readline

n,*xy = map(int,read().split())

mp = iter(xy)
xyi = [(x,y,i) for i,(x,y) in enumerate(zip(mp,mp))]

res = []

xyi.sort()
for (x,y,i),(z,w,j) in zip(xyi[1:],xyi):
    res.append((x-z,i,j))
xyi.sort(key = lambda x:x[1])
for (x,y,i),(z,w,j) in zip(xyi[1:],xyi):
    res.append((y-w,i,j))

#print(res)
res.sort()
UF = UnionFind(n)

num = 1
ans = 0
for d,i,j in res:
    if UF.merge(i,j):
        num += 1
        ans += d
    if num==n: break

print(ans)





Measured memory_bytes: 52524
#include <bits/stdc++.h>
#include <algorithm>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i=0;i<(n);++i)
#define all(x) (x).begin(), (x).end()
#define PB(x) push_back(x)
#define MP(x,y) make_pair(x,y)
using namespace std;
typedef long long ll;
 
int main() {

    ll n,a,b;
    cin>>n>>a>>b;

    ll c=a+b;
    ll ans=a*(n/c);
    if(n%c>a)   ans+=a;
    else    ans+=n%c;
    
    cout<<ans<<endl;

 return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    private static final long MOD = 1_000_000_007;

    public static void main(final String[] args) {
        final Scanner scanner = new Scanner(System.in);
        final int n = scanner.nextInt();
        final int k = scanner.nextInt();

        long sum = 0;
        final long[] array = new long[k + 1];
        for (int i = k; i >= 1; i--) {
            final int nums = k / i;
            long multi = iterativePow(nums, n);

            for (int j = 2; i * j <= k; j++) {
                multi = (multi + MOD - array[i * j]) % MOD;
            }

            sum += (multi * i) % MOD;
            sum %= MOD;
            array[i] = multi;
        }
        System.out.println(sum);
    }

    private static long iterativePow(long a, long b) {
        if (a == 1) {
            return 1;
        }
        long tmp = 1;
        while (b > 0) {
            if ((b & 1) == 1) {
                tmp *= a;
            }
            a *= a;
            a %= MOD;
            b >>= 1;
            tmp %= MOD;
        }

        return tmp;
    }
}


Measured memory_bytes: 36372
#include<cstdio>
#define max(a,b) (a>b?a:b)
#define MaN 200005
int n,m,a[MaN],l,ans=0;
int ton[MaN],mip[MaN],cnt[MaN];
int main(){
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++){scanf("%d",&a[i]);ton[a[i]]++;}
	for(int i=1;i<=n;i++){
		mip[i+1]--;
		if(i+1-ton[i]<1){
			mip[1]+=1+ton[i]-i;
			mip[2]-=ton[i]-i;
			continue;
		}
		mip[i+1-ton[i]]++;
	}
	for(int i=1;i<=n;i++){
		cnt[i]=cnt[i-1]+mip[i];
		if(cnt[i]==0) ans++;
	}
	int x,y,ls;
	for(int i=1;i<=m;i++){
		scanf("%d%d",&x,&y);
		if(a[x]==y){
			printf("%d\n",ans);
			continue;
		}
		if(!cnt[max(y-ton[y],1)]) ans--;
		cnt[max(y-ton[y],1)]++;
		cnt[max(a[x]+1-ton[a[x]],1)]--;
		if(!cnt[max(a[x]+1-ton[a[x]],1)]) ans++;
		ton[a[x]]--;ton[y]++;
		a[x]=y;
		printf("%d\n",ans);
	}
	return 0;
}

Measured memory_bytes: 4480
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    int a=n%10;
    n=n/10;
    int b=n%10;
    n=n/10;
    int c=n%10;
    n=n/10;
    int d=n%10;
    if(a==b&&b==c||b==c&&c==d)
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin>>N;
  string S;
  cin>>S;
  int count=0;
  for(int i=0;i<N;i++){
    S[i];
    if(N%2==0){
      if(S[i]==S[N/2+i]){
        count++;
      }
    }
  }
  if(2*count==N){
    cout<<"Yes"<<endl;
  }
  if(2*count!=N){
    cout<<"No"<<endl;
  }
}

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

int main(){
    string S;
    cin >> S;
    map<char,int>Map;
    for(int i = 0; i < S.size(); i++) {
        Map[S[i]]++;
    }
    for(int i = 0; i < S.size(); i++) {
        if(Map[S[i]] > 1) {
            cout << "no" << endl;
            return 0;
        }
    }
    cout << "yes" << endl;
}



Measured memory_bytes: 256
# B
a = int(input())
b = int(input())
c = int(input())
x = int(input())

cnt = 0
for c500 in range(a+1):
    for c100 in range(b+1):
        for c50 in range(c+1):
            if c500*500 + c100*100 + c50*50 == x:
                cnt += 1
        
print(cnt)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = 1e+9 +7;

template<class T>
class seg_tree{
    vector<T> tree;
    int N;
    T def_val;
    function<T(T,T)> selector;

    public: 
        seg_tree(vector<T> &v, function<T(T,T)> f, T default_val){
            int n = v.size();
            N = pow(2, ceil(log2(n))); 
            tree.resize(2*N-1);
            selector = f;
            def_val = default_val;

            for(int i=0;i<N;i++) tree[N-1+i] = (i>=n?def_val:v[i]);
            for(int i=N-2;i>=0;i--) tree[i] = selector(tree[2*i+1], tree[2*i+2]);
        };

        void update(int ind, T val){
            ind += N - 1;
            tree[ind] = val;
            while(ind > 0){
                ind = (ind - 1) / 2;
                tree[ind] = selector(tree[2*ind+1], tree[2*ind+2]);
            }
        };
        T query(int a, int b, int ind = 0, int l = 0, int r = -1){
            if(r < 0) r = N;
            if(r <= a || b <= l) return def_val;
            if(a <= l && r <= b) return tree[ind];
            else return selector(query(a, b, 2*ind+1, l, (l+r)/2), 
                                 query(a, b, 2*ind+2, (l+r)/2, r));
        };
};

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

    ll dp[n+1][n+1] = {}; // dp[先頭からn桁目]['<'の当てはまる要素数]
    // 1桁目は1~nまで('<'の当てはまる要素数が0~n-1まで)一つずつありえる
    for( int i = 0; i < n; i++){
        dp[0][i] = 1;
    }

    for( int i = 1; i < n; i++){
        vector<ll> vc(dp[i-1], dp[i-1] + n - i + 1); // 先頭から離れる毎に対象区間を狭める
        seg_tree<ll> st(vc, [](const ll x, const ll y){return (x+y)%MOD;}, 0);
        for( int j = 0; j < n; j++){
            dp[i][j] += (s[i-1] == '<'? st.query(0, j+1): st.query(j+1,n));
        }
    }
    cout << dp[n-1][0] << endl;
}

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

#define pb push_back
#define mp make_pair

#define all(x) (x).begin(), (x).end()

#define fi first
#define se second

using namespace std;

typedef long long ll;

const int MAXN = 2e5;
const ll INF = 1e11; 

int n, k;
ll s;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    
    cin >> n >> k >> s;

    for (int i = 1; i <= n; i++) {
        if (k) cout << s << ' ', k--;
        else cout << (s != 1e9 ? (int)1e9 : s - 1) << ' ';
    }

    return 0;
}

Measured memory_bytes: 1280
s = input()

if len(s) == 2:
    if s[0] == s[1]:
        print(1, 2)
    else:
        print(-1, -1)
else:
    for i in range(0, len(s) - 2):
        if s[i] == s[i + 1] or s[i] == s[i + 2] or s[i + 1] == s[i + 2]:
            print(i + 1, i + 3)
            break
    else:
        print(-1, -1)


Measured memory_bytes: 3188
#include <iostream>
#include <stack>
#include <algorithm>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <functional>
#include <string>
#include <cstdlib>
#include <numeric>
#include <cstdbool>
#include <cstring>
#include <map> 
#include<set>
#include<queue>
#include <iomanip>

typedef long long ll;

#define rep(i,n) for(ll i=0;i<n;i++)
using namespace std;

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

const long long INF = 1000000000000000;
const ll inf = -1e18;
typedef pair<ll, ll> P;
ll ma = 1000000000 + 7;
ll mx = 1000003;
ll h,n, w,m,t; string s;
ll R, C;
ll sy, sx, gy, gx;
char maze[20][20];
ll dis[20][20];
int dx[4] = { 1, 0, -1, 0 };
int dy[4] = { 0, 1, 0, -1 };
ll gcd(ll x, ll y) {
	if (x % y == 0) return y;
	return gcd(y, x % y);
}
ll lcm(ll a,ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}
void comb(vector<vector <ll> >& v) {
	for (ll i = 0; i < v.size(); i++) {
		v[i][0] = 1;
		v[i][i] = 1;
	}
	for (ll k = 1; k < v.size(); k++) {
		for (int j = 1; j < k; j++) {
			v[k][j] = (v[k - 1][j - 1] + v[k - 1][j])%ma;
		}
	}
}

ll GetDigit(ll num) {
	return log10(num) + 1;
}
ll Combination(int n, int r)
{
	if (n - r < r) r = n - r;
	if (r == 0) return 1;
	if (r == 1) return n;

	vector<ll> numerator(r);
	vector<ll> denominator(r);

	for (int k = 0; k < r; k++)
	{
		numerator[k] = n - r + k + 1;
		denominator[k] = k + 1;
	}

	for (int p = 2; p <= r; p++)
	{
		int pivot = denominator[p - 1];
		if (pivot > 1)
		{
			int offset = (n - r) % p;
			for (int k = p - 1; k < r; k += p)
			{
				numerator[k - offset] /= pivot;
				denominator[k] /= pivot;
			}
		}
	}

	ll result = 1;
	for (int k = 0; k < r; k++)
	{
		if (numerator[k] > 1) result *= numerator[k];
		result %= ma;
	}

	return result;
}

ll bfs() {
	queue<P> que;
	for (int i = 0; i < R; i++) {
		for (int j = 0; j < C; j++) dis[i][j] = INF;
	}
	que.push(P(sy - 1, sx - 1));
	dis[sy - 1][sx - 1] = 0;

	while (que.size() > 0) {
		P p = que.front();
		que.pop();
		if (p.first == gy - 1 && p.second == gx - 1) break;
		for (ll i = 0; i < 4; i++) {
			ll ny = p.first + dy[i];
			ll nx = p.second + dx[i];
			if (0 <= ny && ny < R && 0 <= nx && nx < C && maze[ny][nx] == '.' && dis[ny][nx] == INF) {
				que.push(P(ny, nx));
				dis[ny][nx] = dis[p.first][p.second] + 1;
			}
		}
	}
	return dis[gy - 1][gx - 1];
}
ll dp[20500];
int main() {
	cin >> s;
	map<char,ll> mp;
	rep(i, s.size()) {
		mp[s[i]]++;
	}
	if (mp['N'] > 0 && mp['S'] > 0 && mp['E'] > 0 && mp['W'] > 0) {
		cout << "Yes" << endl;
	}
	else if (mp['N'] > 0 && mp['S'] > 0 && mp['E'] == 0 && mp['W'] == 0) {
		cout << "Yes" << endl;
	}
	else if (mp['N'] == 0 && mp['S'] == 0 && mp['E'] > 0 && mp['W'] > 0) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define vi vector<int>
#define vll vector<ll>
#define vbool vector<bool>
#define umap unordered_map
#define uset unordered_set
#define frw(i, a, b) for(int i = a; i < b; i++)
#define bck(i, a, b) for(int i = a; i > b; i--)
#define fi first
#define se second
#define pow asdihagsiduh
#define pub push_back
#define in insert
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define sz(a) int(a.size())
#define pii pair<int, int>
#define pll pair<ll, ll>
#define plll pair<ll, pll>
#define vpll vector<pll>
#define vpii vector<pii>

#define trace(...) ZZ(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1> 
void ZZ(const char* name, Arg1&& arg1){
	std::cerr << name << " = " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void ZZ(const char* names, Arg1&& arg1, Args&&... args){
	const char* comma = strchr(names + 1, ',');
	std::cerr.write(names, comma - names) << " = " << arg1;
	ZZ(comma, args...);
}

const int N = 1e5 + 5;
const int MOD = 1e9 + 7;

vector<vi> dp;
vector<vector<double>> ans;
vector<double> prob;

double rec(int heads, int upto){
	if(heads == 0 and upto == 0)	return 1;
	if(dp[heads][upto] != -1)	return ans[heads][upto];
	dp[heads][upto] = 1;
	double &aux = ans[heads][upto];
	aux = (1 - prob[upto]) * rec(heads, upto - 1);
	if(heads)	aux += prob[upto] * rec(heads - 1, upto - 1);
	return aux;
}

int main(){
	ios::sync_with_stdio(0);
	int n; cin >> n;
	dp.assign(n + 1, vi (n + 1, -1));
	ans.assign(n + 1, vector<double> (n + 1, 0.0));
	prob.assign(n + 1, 0.0);
	frw(i, 1, n + 1)	cin >> prob[i];
	double ans = 0;
	frw(i, n / 2 + 1, n + 1)	ans += rec(i, n);
	cout << fixed << setprecision(10) << ans;
}

Measured memory_bytes: 108288
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

struct P {
	string a;
	int b;
};

int main() {
	string a;
	int b;
	P retu[110];
	int i = 0;
	while (cin >> a >> b) {
		P p;
		p.a = a;
		p.b = b;
		retu[i] = p;
		i++;
	}
	for (int j = i; j > 0; j--) {
		for (int k = 0; k < j-1; k++) {
			if (retu[k].a > retu[k+1].a) {
				swap(retu[k], retu[k+1]);
			} else if (retu[k].a == retu[k+1].a) {
				if (retu[k].b > retu[k+1].b) {
					swap(retu[k], retu[k+1]);
				}
			}
		}
	}
	for (int j = 0; j < i; j++) {
		if (j == 0) {
			cout << retu[0].a << endl << retu[0].b;
		} else {
			if (retu[j].a == retu[j-1].a) {
				cout << ' ' << retu[j].b;
			} else {
				cout << endl << retu[j].a << endl << retu[j].b;
			}
		}
	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 1224
#include<iostream>
#include<string>
#include<cctype>

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

using namespace std;

int main(){

long long int count_change=0,b[100]={0};                           //count_change??????????????£????????????????????????b[100]??????????????????????????????????????????????´????????????°
string member,change;                                   //member?????????????????????????????????????´????change????????£????????????????????????????´????????????°

while(1){

  cin >> member;                                      //????????????????????????????????\???
   if(member == "-") break;                              // ???????????????????????????????????¶
   cin >> count_change;                                 //?????£????????????????????°?????\???
   rep(i , 0 , count_change){                              //???????????????
     cin >> b[i];                                          //?????£????????????????????°?????\???
     change = member.substr(0,b[i]);                         //???????????????????????????????????????????????\?????????????????£????????????????????°?????§???????????????change???????´?
     member += change;                                      //member????????????????????????????????£?????????
     member = member.substr(b[i],member.length());                //????????????????????????????????????member???????´?

   }
cout << member << endl;                                  //??¨???

  }

return 0;

}

Measured memory_bytes: 1216
#include <iostream>

using namespace std;

void swap(int *x, int *y, int *z, int *w) {
	int temp;    // 値を一時保存する変数

	temp = *x;
	*x = *y;
	*y = temp;
	temp = *z;
	*z = *w;
	*w = temp;
}

int partition(int array1[], int array2[], int left, int right) {
	int i, j, pivot;
	i = left;
	j = right + 1;
	pivot = left;   // 先頭要素をpivotとする

	do {
		do { i++; } while (array1[i] < array1[pivot]);
		do { j--; } while (array1[pivot] < array1[j]);
		// pivotより小さいものを左へ、大きいものを右へ
		if (i < j) { swap(&array1[i], &array1[j], &array2[i], &array2[j]); }
	} while (i < j);

	swap(&array1[pivot], &array1[j], &array2[pivot], &array2[j]);   //pivotを更新

	return j;
}

void quick_sort(int array1[], int array2[], int left, int right) {
	int pivot;

	if (left < right) {
		pivot = partition(array1, array2, left, right);
		quick_sort(array1, array2, left, pivot - 1);   // pivotを境に再帰的にクイックソート
		quick_sort(array1, array2, pivot + 1, right);
	}
}

int main()
{
	int n, k;

	cin >> n;

	int *a = new int[n];
	int *b = new int[n];
	int i;

	for (i = 0; i < n; i++) {
		cin >> a[i];
		b[i] = i;
	}
	quick_sort(a, b, 0, n-1);
	for (i = 0; i < n - 1; i++) {
		cout << b[i]+1 << " ";
	}
	cout << b[i]+1 << endl;

	return 0;
}


Measured memory_bytes: 1664
# coding: utf-8

n = input()
s = map(int, [raw_input() for _ in xrange(n)])
s.sort(reverse=True)
t = 0
while True:

    for i in xrange(1, len(s) + 1):
        total = sum(s) - t

        if total % 10 != 0:
            print total
            exit()

        t = s[-i]

    s.pop()

    if not s:
        print 0
        break


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

int main(){
  int N, Q; cin >> N >> Q;
  vector<pair<int,int>> H(N-1);
  vector<pair<int,int>> P(Q);
  for(int i=0;i<N-1;i++){
    cin >> H[i].second >> H[i].first;
  }
  sort(H.begin(), H.end());
  for(int i=0;i<Q;i++){
    cin >> P[i].first >> P[i].second;
  }
  vector<int64_t> ans(N,0);
  vector<int64_t> plus(N+1,0);
  for(int i=0;i<Q;i++){
    plus[P[i].first]+=P[i].second;
  }
  ans[0]=plus[1];
  for(int i=1;i<N;i++){
    ans[i]=ans[H[i-1].second-1]+plus[i+1];
  }
  for(int i=0;i<N;i++){
    cout << ans[i] << endl;
  }
}
  

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

#define max(a, b) ((a > b) ? a : b)
#define min(a, b) ((a < b) ? a : b)

#define forn(n) for(int i = 0; i < n; i++)
#define fork(k, n) for(int i = k; i < n; i++)

#define pb(n) push_back(n);

typedef long long ll;
typedef double dbl;

const int MX = 1e6;
const int MOD = 1e9 + 7;
const string ALPHA = "abcdefghijklmnopqrstuvwxyz";
const double PI = 3.1415926535;

int main(){
    int x;
    cin>>x;
    cout<<(!x)<<endl;
}

Measured memory_bytes: 3600
#include <bits/stdc++.h>
#define FOR(i,n) for(int i=0;i<(int)(n);i++)
#define FORR(i,m,n) for(int i=(int)(m);i<(int)(n);i++)
#define pb(a) push_back(a)
#define mp(x,y) make_pair(x,y)
#define ALL(a) a.begin(),a.end()
#define ZERO(a) memset(a,0,sizeof(a))
#define len(a) sizeof(a)
#define ll long long
#define pii pair<int,int>
#define INF 1<<29
#define MAX 101010
using namespace std;

int n,l,a[MAX],dp[MAX];

int dfs(int now){
 if(dp[now]) return dp[now];
 if(a[now]>a[now-1]&&a[now]>a[now+1]) return dp[now]=l-a[now];
 int ma=0;
 if(a[now]<=a[now-1]) ma=dfs(now-1);
 if(a[now]<=a[now+1]) ma=max(ma,dfs(now+1));
 return dp[now]=ma+l-a[now];
}

void solve(){
 cin>>n>>l;
 a[0]=a[n+1]=0;
 FOR(i,n) cin>>a[i+1];
 ZERO(dp);
 int ma=0;
 FOR(i,n) ma=max(ma,dfs(i+1));
 cout<<ma<<endl;
}

int main(){
 solve();
 return 0;
}

Measured memory_bytes: 5232
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
#define fi first
#define se second
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define pf push_front
#define eb emplace_back
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define SZ(x) (int)(x).size()
#define ft front()
#define bk back()
#define endl '\n'
#define FOR(a, b, c) for (auto(a) = (b); (a) < (c); ++(a))
#define ROF(a, b, c) for (auto(a) = (b); (a) > (c); --(a))
#define F0R(a, b) FOR ((a), 0, (b))
#define R0F(a, b) ROF ((a), (b), -1)
#define CEIL(a, b) ((a) + (b)-1) / (b)
#define SET(a, b) memset((a), (b), sizeof(a))
template <class t>
bool ckmin(t& a, const t& b) {
    return a > b ? a = b, true : false;
}
template <class t>
bool ckmax(t& a, const t& b) {
    return a < b ? a = b, true : false;
}
#ifndef DEBUG
#define DEBUG 0
#endif
#define dout \
    if (DEBUG) std::cerr
#define dvar(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
template <class a, class b>
ostream& operator<<(ostream& o, const pair<a, b>& p);
template <class T>
struct IsC {
    template <class C>
    static char test(typename C::const_iterator*);
    template <class C>
    static int test(...);
    static const bool value = sizeof(test<T>(0)) == sizeof(char);
};
template <>
struct IsC<string> {
    static const bool value = false;
};
template <class C>
typename enable_if<IsC<C>::value, ostream&>::type operator<<(ostream& o,
                                                             const C& c) {
    o << '{';
    for (auto it = c.begin(); it != c.end();)
        o << *it << (++it != c.end() ? ", " : "}");
    return o;
}
template <class a, class b>
ostream& operator<<(ostream& o, const pair<a, b>& p) {
    return o << '(' << p.fi << ", " << p.se << ')';
}

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

    int a, b, c, d;
    cin >> a >> b >> c >> d;
    int ourt = c / b + (!!(c % b));
    int theirt = a / d + (!!(a % d));

    cout << (ourt > theirt ? "No" : "Yes") << endl;

    return 0;
}


Measured memory_bytes: 3656
#include<bits/stdc++.h>
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define watch(x); cout<<#x<<"="<<x<<endl;
#define watch2(x,y); cout<<#x<<"="<<x<<" "<<#y<<"="<<y<<endl;
#define endl "\n"
#define int long long
using namespace std;    

long long inverseMod(long long x,long long mod);
long long nCr(long long n,long long r,long long mod){
    //when r is lesser and is greater
    long long res=1;
    if(r>n-r)r=n-r;
    long long div=1;
    for(long long  i=0;i<r;i++){
        res=(res*(n-i))%mod;
    }

    for(long long i=1;i<=r;i++){
        div=(div*i)%mod;
    }
    return (res*inverseMod(div,mod))%mod;
}


long long power(long long x,long long n,long long mod){
//(x^n)%mod
long long result=1;

    while(n){
        if(n%2)
            result=(result*x)%mod;
        x=(x*x)%mod;
        n/=2;
    }
    return result;
}

long long inverseMod(long long x,long long mod){

return power(x,mod-2,mod);
}




int32_t main(){

    fast
    int n;
    cin>>n;
    vector<int>arr(n+1);
    map<int,int>mp;
    int ans=0;
    for(int i=1;i<=n;i++){
        cin>>arr[i];
        ans+=mp[i-arr[i]];
        mp[i+arr[i]]++;
    }
    cout<<ans;


    return 0;
}



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

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << setprecision(20) << fixed;

  int H, N;
  cin >> H >> N;
  long long ans = 0;
  for(int i = 0; i < N; i++){
    int A;
    cin >> A;
    ans += A;
  }
  if(ans >= H){
    cout << "Yes" <<endl;
  } else{
    cout << "No" <<endl;
  }
}

Measured memory_bytes: 384