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

using namespace std;

using ll = long long;

constexpr ll MOD = 1000000007;

#ifndef ONLINE_JUDGE
template <class T, class U>ostream &operator<<(ostream &o, const map<T, U>&obj) {o << "{"; for (auto &x : obj) o << " {" << x.first << " : " << x.second << "}" << ","; o << " }"; return o;}
template <class T>ostream &operator<<(ostream &o, const set<T>&obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
template <class T>ostream &operator<<(ostream &o, const multiset<T>&obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
template <class T>ostream &operator<<(ostream &o, const vector<T>&obj) {o << "{"; for (int i = 0; i < (int)obj.size(); ++i)o << (i > 0 ? ", " : "") << obj[i]; o << "}"; return o;}
template <class T, class U>ostream &operator<<(ostream &o, const pair<T, U>&obj) {o << "{" << obj.first << ", " << obj.second << "}"; return o;}
template <template <class tmp>  class T, class U> ostream &operator<<(ostream &o, const T<U> &obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr)o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
void print(void) {cout << endl;}
template <class Head> void print(Head&& head) {cout << head;print();}
template <class Head, class... Tail> void print(Head&& head, Tail&&... tail) {cout << head << " ";print(forward<Tail>(tail)...);}
#else
#define print(...)
#endif

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

    ll n;


    cin >> n;

    string ans;

    switch(n%10){
    case 2:
    case 4:
    case 5:
    case 7:
    case 9: ans = "hon"; break;
    case 0:
    case 1:
    case 6:
    case 8: ans = "pon"; break;
    default : ans = "bon"; break;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3652
#include<bits/stdc++.h>
using namespace std;
#define rep(i,j,n) for(int i=(int)(j);i<(int)(n);i++)
#define REP(i,j,n) for(int i=(int)(j);i<=(int)(n);i++)
#define MOD 1000000007
#define int long long
#define ALL(a) (a).begin(),(a).end()
#define vi vector<int>
#define vii vector<vi>
#define pii pair<int,int>
#define priq priority_queue<int>
#define disup(A,key) distance(A.begin(),upper_bound(ALL(A),(int)(key)))
#define dislow(A,key) distance(A.begin(),lower_bound(ALL(A),(int)(key)))
#define tii tuple<int,int,int>
signed main(){
  int N,M; cin>>N>>M;
  string S; cin>>S;
  stack<int> ans;
  bool flag=0;
  int G=N;
  while(G-M>0){
    flag=1;
    rep(i,0,M){
      int K=M-i;
      if(S[G-K]=='0'){
        G-=K;
        ans.push(K);
        flag=0;
        break;
      }
    }
    if(flag)
      break;
  }
  if(flag)
    cout<<-1<<endl;
  else{
    cout<<G<<" ";
    while(ans.size()>0){
      int A=ans.top();
      ans.pop();
      cout<<A<<" ";
    }
    cout<<endl;
  }
  }



Measured memory_bytes: 1196
#include <bits/stdc++.h>
using namespace std;
const long long N = 1e6;
int d()
{
    int ret;
    scanf("%d", &ret);
    return ret;
}
long long lld()
{
    long long ret;
    scanf("%lld", &ret);
    return ret;
}
bool cmp(pair<int, int> s, pair<int, int> f)
{
    if (f.first > s.first)
        return true;
    else if (f.first == f.second && f.second < s.second)
        return true;
    else
        return false;
}

int main()
{
    int n;
    cin>>n;
    if(n%2==0)
    cout<<n<<endl;
    else
    cout<<2*n<<endl;
}


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

float calculate_distance(vector<int> d_1, vector<int> d_2){
    int vector_size = d_1.size();
    int distance_sum = 0;
    for (int i=0;i<vector_size;i++){
        distance_sum += pow((d_1[i] - d_2[i]), 2.0);
    }
    return sqrt(distance_sum);
}

bool judge_if_integer_or_float(float value){
    return (ceil(value) == floor(value));
}

int main(){
    int n,d;
    cin >> n >> d;
    vector<vector<int>> matrix(n, vector<int>(d));
    for (int i=0;i<n;i++){
        for (int j=0;j<d;j++){
            cin >> matrix[i][j];
        }
    }
    
    int integer_number = 0;
    for (int i_1=0;i_1<n-1;i_1++){
        for (int i_2=i_1+1;i_2<n;i_2++){
            float distance = calculate_distance(matrix[i_1], matrix[i_2]);
            if (judge_if_integer_or_float(distance)){
                integer_number += 1;
            }
        }
    }
    cout << integer_number << endl;
    return 0;
}

Measured memory_bytes: 256
/**
 *    author: gxfireball       
**/
#include <bits/stdc++.h>
#define ll long long
#define endl '\n'
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); 
using namespace std;

int main(){
   fastio;
   ll x;
   cin >> x;
   for(ll i=-500; i <=500; ++i){
	   for(ll j=-500; j<=500; ++j){
		   if(pow(i,5)-pow(j,5) == x){
			   cout << i << " " << j ;
			   return 0;
		   }
	   }
   }
}



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

int main(){
        int A,B,C;
        int i;
        cin >> A >> B >> C;
        for(i=1; i<=100; i++) {
                if((A*i)%B == C) {
                        cout << "YES" << endl;
                        break;
                }else if((A*i)%B != C && i ==100) {
                        cout << "NO" << endl;
                }
        }
        return 0;
}


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

int main(){
	cin.tie(0),ios::sync_with_stdio(false);
	int n,W; cin>>n>>W;
	vector<int>v(n),w(n); for(int i=0;i<n;++i)cin>>v.at(i)>>w.at(i);
	vector<int>dp(W+1);
	for(int i=0;i<n;++i){
		for(int j=W;j>=w.at(i);--j){
			dp.at(j)=max(dp.at(j),dp.at(j-w.at(i))+v.at(i));
		}
	}
	cout<<dp.back()<<"\n"s;
}


Measured memory_bytes: 3244
#include<stdio.h>
int main(void){
  int odd=0 ,n,i;
  scanf("%d",&n);
  int a[n];
  for(i = 0; i < n ;i++){
    scanf("%d",&a[i]);
    if(a[i] % 2 != 0){
      odd ++;
    }
  }
  if(odd % 2 == 0){
    printf("YES");
  }else{
    printf("NO");
  }
  return 0;
}


Measured memory_bytes: 512
# 壁の各マスは独立に扱ってよいので、2→1、3→1、……の最低コストを求めればよい。
# https://qiita.com/e869120/items/eb50fdaece12be418faa だとワーシャル・フロイドの項に挙がっているが、
# ダイクストラだとダメなのかな?
# →ダイクストラは「ある1つの始点から、他のすべての点までの最短距離」をO(E log V)で計算する。
# 今回は始点が 1以外の9点なので、ダイクストラには向かない
# （2→3と3→2のコストは同じではないので、1から他のすべての点までを計算するのは不可。
# ダイクストラでも計算コスト上はできる。ダイクストラを9回やる羽目になるけど。）


def warshall_floyd(distance, v):
    for k in range(v):
        for i in range(v):
            for j in range(v):
                distance[i][j] = min(distance[i][j], distance[i][k] + distance[k][j])

v = 10

h, w = list(map(int, input().split()))

d = [list(map(int, input().split())) for i in range(10)]
wall = [list(map(int, input().split())) for i in range(h)]

warshall_floyd(d, v)

ans =0
for i in range(h):
    for j in range(w):
        num = wall[i][j]
        if num == -1:
            pass
        else:
            # num → 1 の距離はc_{num, 1}
            ans += d[num][1]

print(ans)


Measured memory_bytes: 3444
#include <iostream>
#include <stdio.h>
#include<algorithm>
#include <math.h>
#include <string.h>
#define eps 1e-9
typedef long long int ll;
using namespace std;
int a[200005];
double b[200005];
double sum;
double maxs;
int main()
{
    int n,k;
    cin>>n>>k;
    int j=0;
    for(int i=0;i<n;i++)
    {
        scanf("%d",&a[i]);
        b[i]=(a[i]+1)*1.0/2;
    }
    for(int i=0;i<n;i++)
    {
        if(i-j<k)
        {
            sum+=b[i];
        }
        if((i-j)==k)
        {
            sum+=b[i];
            sum-=b[j];
            j++;

        }
        maxs=max(maxs,sum);
    }
    printf("%.12lf",maxs);
    return 0;
}


Measured memory_bytes: 2560
#include <stdio.h>

int main(void){
	int n, u, k, v;
	int Adj[101][101] = { 0 };
	int i, j;

	scanf("%d", &n);
	for (i = 1; i <= n; i++){
		scanf("%d %d", &u, &k);
		for (j = 1; j <= k; j++){
			scanf("%d", &v);
			Adj[u][v] = 1;
		}
	}

	for (i = 1; i <= n; i++){
		for (j = 1; j <= n; j++){
			if (j != n)
				printf("%d ", Adj[i][j]);
			else
				printf("%d\n", Adj[i][j]);
		}
	}

	return 0;
}

Measured memory_bytes: 648
#include <iostream>
#include <cstring>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <set>
#include <utility>
#include <cstdlib>
#include <queue>
#include <iomanip>
#include <cstdio>
#include <map>

using namespace std;

string s;
int x, y, tot;
vector<int> fo;
bool dp[4000][16001], dp2[4000][16001];

int main(){
    //入力
    cin >> s >> x >> y;

    //それぞれのx軸とy軸のそれぞれどのくらいの位置にいるか知る。
    int cnt = 0;
    vector<int> xf, yf;
    int tur = 0;
    for(int i = 0; i < s.length(); i++){
        if(s[i] == 'F'){
            cnt++;
        }
        else{
            if(!tur) xf.push_back(cnt);
            else yf.push_back(cnt);
            cnt = 0;
            //偶奇の入れ替え
            tur = 1 - tur;
        }
    }
    //残った分
    if(!tur) xf.push_back(cnt);
    else yf.push_back(cnt);

    //xとyのそれぞれの最大の大きさを求める。
    int N = xf.size(), M = yf.size();

    //xの座標の可能性を示すdp
    dp[1][8000+xf[0]] = true;
    for(int i = 1; i < N; i++){
        for(int j = 0; j < 16001; j++){
            if(dp[i][j]){
                dp[i+1][j+xf[i]] = true;
                dp[i+1][j-xf[i]] = true;
            }
        }
    }

    //yの座標の可能性を示すdp
    dp2[0][8000] = true;
    for(int i = 0; i < M; i++){
        for(int j = 0; j < 16001; j++){
            if(dp2[i][j]){
                dp2[i+1][j+yf[i]] = true;
                dp2[i+1][j-yf[i]] = true;
            }
        }
    }

    //出力
    if(dp[N][x+8000] && dp2[M][y+8000]) cout << "Yes" << endl;
    else cout << "No" << endl;
}



Measured memory_bytes: 123648
#include <iostream>
#include <memory>
#include <vector>

struct Node;
using NodePtr = std::shared_ptr<Node>;

enum class TraverseState {
  NOT_VISITED,
  ON_PATH,
  VISITED,
};

struct Node {
  Node() = default;
  Node(const unsigned int id_) : state(TraverseState::NOT_VISITED), id(id_), neighbors{}{}
  TraverseState state;
  unsigned int id;
  std::vector<NodePtr> neighbors;
};

bool IsAcyclic(NodePtr& tree) {
  tree->state = TraverseState::ON_PATH;
  for (auto& neighbor : tree->neighbors) {
    if (neighbor->state == TraverseState::ON_PATH) {
      return true;
    }
    if (neighbor->state == TraverseState::VISITED) {
      continue;
    }
    if (IsAcyclic(neighbor)) {
      return true;
    }
  }
  tree->state = TraverseState::VISITED;
  return false;
}

int main() {
  int numVertices;
  int numEdges;
  std::cin >> numVertices >> numEdges;
  std::vector<NodePtr> vertices(numVertices);
  for (auto i = 0u; i < numVertices; ++i) {
    vertices[i] = std::make_shared<Node>(i);
  }
  for (auto i = 0u; i < numEdges; ++i) {
    int srcNum;
    int dstNum;
    std::cin >> srcNum >> dstNum;
    vertices[srcNum]->neighbors.push_back(vertices[dstNum]);
  }
  for (auto& node : vertices) {
    if (node->state != TraverseState::NOT_VISITED) {
      continue;
    }
    if (IsAcyclic(node)) {
      std::cout << static_cast<int>(true) << std::endl;
      return 0;
    }
  }
  std::cout << static_cast<int>(false) << std::endl;
}


Measured memory_bytes: 3128
#include <stdio.h>

int solve(int n,  int m, int a){
  short line[101][1001] = {};
  int i, j,h, p, q;
  for(i = 0; i < m; i++){
    scanf("%d %d %d", &h, &p, &q);
    line[p][h] = q;
    line[q][h] = p;
  }
  
  i = 1000;
  j = 0;
  while(j < m){
    if(line[a][i] != 0){
      a = line[a][i];
      j++;
    }
    i--;
    if(i <= 0) break;
  }

  return a;
}

int main(void){
  int n, m, a;

  while(1){
    scanf("%d %d %d", &n, &m, &a);
    if(n == 0 && m == 0 && a == 0) break;
    printf("%d\n", solve(n, m, a));
  }

  return 0;
}


Measured memory_bytes: 804
#include<iostream>  
#include<cstring>  
#include<cstdio>  
#include<cmath>  
#include<algorithm>  
  
using namespace std;  
  
bool s[15][10005]= {0};  
  
int n, m;  

void reverse(int row){
    for(int i=1; i<=m; i++){
        if(s[row][i]==0) s[row][i]=1;
        else s[row][i]=0;
    }
}

int dfs(int x)  
{  
    if(x==n+1)  
    {  
        int sum=0;  
        int term=0;  
        for(int j=1;j<=m;j++)  
        {  
            for(int i=1;i<=n;i++)  
                if(s[i][j]==1)term++;  
            sum += term > n-term ? term : n-term;  
            term=0;  
        }  
        return sum;  
    }  
    int a=dfs(x+1);  
    reverse(x);
    //for(int i=1;i<=m;i++)  
      //  s[x][i]=!s[x][i];  
    int b=dfs(x+1);  
    return a>b?a:b;
}  
  
int main()  
{  
    //freopen("in.in","r",stdin);  
    while(scanf("%d%d",&n,&m)!=EOF)  
    {  
        if(n==0&&m==0)break;   
        for(int i=1; i<=n; i++)  
            for(int j=1; j<=m; j++)  
                scanf("%d",&s[i][j]);  
        cout<<dfs(1)<<endl;  
    }  
    return 0;  
} 


Measured memory_bytes: 3252
#include <stdio.h>
#include <iostream>
using namespace std;
int main()
{
    char a,b;
    cin>>a>>b;
    if(a=='H'&&b=='H')
    cout<<"H";
    else
    if(a=='H'&&b=='D')
    cout<<"D";
    else
    if(a=='D'&&b=='H')
    cout<<"D";
    else
    if(a=='D'&&b=='D')
    cout<<"H";
}




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

#define REPI(i, n) for(int i = 0; i < n; i++)
#define REPJ(j, n) for(int j = 0; j < n; j++)

using ll = long long;
using namespace std;

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

    int a, ans = 0, max_num = 0; cin >> a;
    char c;
    while(cin >> c){
        c == 'I' ? ans++ : ans--;
        max_num = max(ans, max_num);
    }cout << max_num;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <time.h>
#include <stack>
#include <array>
#define popcount __builtin_popcount
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;

int main()
{
	int n; cin>>n;
	int a[100];
	for(int i=0; i<n; i++) cin>>a[i];
	P dp[2][101];
	for(int i=0; i<=n; i++) dp[0][i]=dp[1][i]=P(-1, -1);
	dp[0][0]=P(1000, 0);
	for(int i=0; i<n; i++){
		dp[0][i+1]=max(dp[0][i+1], dp[0][i]);
		dp[1][i+1]=max(dp[1][i+1], dp[1][i]);
		if(dp[0][i].first>=0) dp[1][i+1]=max(dp[1][i+1], P(dp[0][i].second+dp[0][i].first/a[i], dp[0][i].first%a[i]));
		if(dp[1][i].first>=0) dp[0][i+1]=max(dp[0][i+1], P(dp[1][i].second+dp[1][i].first*a[i], 0));
	}
	cout<<dp[0][n].first<<endl;
	return 0;
}

Measured memory_bytes: 3548
#include <stdio.h>
#include <stdlib.h>
 
int compare_int(const void *a, const void *b)
{
    //??????
    return *(int*)a - *(int*)b;
}
 
int main(void) {
    int n;
    int number[3];
    
    n=3;
    scanf("%d %d %d", number,number+1,number+2);   
    qsort(number, n, sizeof(int), compare_int);       
    printf("%d %d %d\n", number[0],number[1],number[2]);
 
    return 0;
}

Measured memory_bytes: 600
#include<iostream>
using namespace std;
int s[10004];
int cnt,n;
void find(int s[],int num)
{
	for(int i=0;i<n;i++)
	{
		if(s[i]==num)
		{
			cnt++;
			break;
		}	
	}
}
int main()
{
	cin>>n;
	for(int k=0;k<n;k++)
	{
		cin>>s[k];
	}
	int q;
	cin>>q;
	while(q--)
	{
		int nn;
		cin>>nn;
		find(s,nn);
		
	} 
	cout<<cnt<<endl;
	return 0;
}


Measured memory_bytes: 3100
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
 
int main()
{
	
	    string s;
	    ll k;
	    cin>>s;
	    cin>>k;
	    long long int i,c=0,flag=0;
	    for(i=0;i<=s.size();i++)
	    {
	        if(s[i]=='1')
	        {
	            c++;
	            if(c>=k)
	            {
	                flag=1;cout<<"1"<<endl;break;
	            }
	        }
	        else break;
	    }
	    if(flag==0)
	    cout<<s[i]<<endl;

	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a,b;
  cin>>a>>b;
  int ll=b-(a-1);
  int ul=b+(a-1);
  for(int i=ll;i<=ul;i++){
    cout<<i<<" ";
  }
  cout<<endl;
  return 0;}


Measured memory_bytes: 256
#include "bits/stdc++.h"
#pragma GCC optimize "03"
using namespace std;
 
#define int long long int
#define ld long double
#define pi pair<int, int>
#define pb push_back
#define fi first
#define se second
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#ifndef LOCAL
#define endl '\n'
#endif
 
const int N = 2e5 + 5;
const int mod = 1e9 + 7;
const int inf = 1e9 + 9;

int t[4*N], a[N], ans[N];
vector<int> g[N];

void upd(int nd, int s, int e, int id, int v){
	if(s == e){
		t[nd] = v;
		return ;
	}
	int md = (s + e) >> 1;
	if(id <= md)
		upd(nd << 1, s, md, id, v);
	else
		upd(nd << 1|1, md+1, e, id, v);
	t[nd] = max(t[nd << 1], t[nd << 1 | 1]);
}

int query(int nd, int s, int e, int l, int r){
	if(s > e || s > r || e < l)
		return 0;
	if(s >= l && e <= r)
		return t[nd];
	int md = (s + e) >> 1;
	return max(query(nd << 1, s, md, l, r), query(nd << 1|1, md+1, e, l, r));
}

void dfs(int u, int p = 0){
	int x = query(1, 1, N, 1, a[u]-1);
	int v = query(1, 1, N, a[u], a[u]);
	upd(1, 1, N, a[u], x+1);
	ans[u] = t[1];
	for(auto i: g[u]){
		if(i == p)	continue;
		dfs(i, u);
	}
	upd(1, 1, N, a[u], v);
}

signed main() {
	IOS;
	int n;	cin >> n;
	map<int, int> m;
	for(int i = 1; i <= n; i++){
		cin >> a[i];
		m[a[i]] = 1;
	}
	int p = 0;
	for(auto &i: m){
		p += i.se;
		i.se = p;
	}
	for(int i = 1; i <= n; i++)
		a[i] = m[a[i]];
	for(int i = 1; i <= n-1; i++){
		int u, v;
		cin >> u >> v;
		g[u].push_back(v);
		g[v].push_back(u);
	}	
	dfs(1);
	for(int i = 1; i <= n; i++)
		cout << ans[i] << endl;;
	return 0;
}

Measured memory_bytes: 41988
A=int(input())
B=int(input())
C=int(input())
D=int(input())
E=int(input())

count=0
if A%10!=0:
    A1=A-A%10+10
else:
    A1=A
if B%10!=0:
    B1=B-B%10+10
else:
    B1=B
if C%10!=0:
    C1=C-C%10+10
else:
    C1=C
if D%10!=0:
    D1=D-D%10+10
else:
    D1=D
if E%10!=0:
    E1=E-E%10+10
else:
    E1=E


total=[]

total+=[A1+B1+C1+D1+E]
total+=[A1+B1+C1+E1+D]
total+=[A1+B1+D1+E1+C]
total+=[A1+C1+D1+E1+B]
total+=[B1+C1+D1+E1+A]


print(min(total))


Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define each(a,x) for(auto a : (x))
#define all(a) (a).begin(),(a).end()
#define chmin(a,b) ((a) = min((a),(b)))
#define chmax(a,b) ((a) = max((a),(b)))
#define in_range(x,l,r) ((l)<=(x) && (x)<(r))
#define printvec(a) rep(i,a) cout << a[i] << " \n"[i+1==(a).size()];
#define fs first
#define sc second
#define em emplace
#define eb emplace_back
#define sz size()
#define MP make_pair
using namespace std;
typedef long long ll;
typedef double D;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<string> vs;

const ll INF = 1e8;
const D EPS = 1e-8;
const ll MOD = 1e9+7;

int main(){
  string s;
  cin >> s;
  int cnt_one = 0;
  vector<int> pos_zero;
  rep(i, s.size()) {
    if (s[i] == '1') {
      cnt_one++;
    } else {
      pos_zero.push_back(cnt_one);
    }
  }

  ll ans = 0;
  for (int i = 1; i <= cnt_one; ++i) {
    ans += (i + 1) / 2;
  }

  vector<int> used(pos_zero.size(), -1);
  int cnt_used_zero = 0;
  rep(i, pos_zero.size()) {
    pos_zero[i] += cnt_used_zero;
    if (pos_zero[i] % 2 == 1) {
      used[i] = cnt_used_zero;
      cnt_used_zero++;
      ans += (cnt_one + cnt_used_zero + 1) / 2;
    }
  }

  int rev_cnt_zero = 0;
  int odd_pos = 0;
  int even_pos = 0;
  rrep(i, pos_zero.size()) {
    if (used[i] < 0) {
      rev_cnt_zero++;
      int len = (cnt_one + cnt_used_zero + rev_cnt_zero);
      swap(odd_pos, even_pos);
      odd_pos++;
      ans += (len + 1) / 2 - odd_pos;
    } else {
      even_pos++;
    }
  }
      
  cout << ans << endl;
}


Measured memory_bytes: 5192
/**
*    created: 09.07.2020 22:29:21
**/
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
// #include <boost/multiprecision/cpp_int.hpp>
// using bint = boost::multiprecision::cpp_int;
using namespace std;
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define pcnt(bit) __builtin_popcountll(bit)
template<class T> bool chmax(T &a, const T &b) {if (a < b) {a = b; return 1;} return 0;}
template<class T> bool chmin(T &a, const T &b) {if (b < a) {a = b; return 1;} return 0;}
const long double pi = acos(-1.0);
const int MAX = 1000010;
const int INF = 1LL << 60;
const int MOD = 1000000007;
// const int MOD = 998244353;

signed main() {

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

    int n, m;
    cin >> n >> m;
    int p = 0;
    if (m > 2 * n) {
        p += n;
        p += (m - 2 * n) / 4;
        cout << p << endl;
    }
    else {
        p += m / 2;
        cout << p << endl;
    }
    return 0;
}

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



int main()
{
    ll a,b,c,d;
    cin>>a>>b>>c>>d;
    if(c>=a&&d<=b)cout<<d-c;
    else if(a>=c&&b<=d)cout<<b-a;
    else if(a>=c&&b>=d&&a<=d)cout<<d-a;
    else if(c>=a&&d>=b&&c<=b)cout<<b-c;
    else if(c<=a&&d<=b&&d>=a)cout<<d-a;
    else if(a<=c&&b<=d&&b>=c)cout<<b-c;
    else cout<<0;

    return 0;
}


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

using namespace std;

typedef long long ll;
typedef pair < int, int > ii;

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

inline int add(int x, int y) {
  return x + y >= mod ? x + y - mod : x + y;
}

inline int mul(int x, int y) {
  return (ll) x * y % mod;
}

inline int fe(int x, int k) {
  int res = 1;
  while(k) {
    if(k & 1)
      res = mul(res, x);
    x = mul(x, x);
    k >>= 1;
  }
  return res;
}

inline int dv(int x, int k) {
  return mul(x, fe(k, mod - 2));
}

int n, m;
int dp[N], cant[N];

int main() {
  scanf("%d %d", &n, &m);
  for(int i = 1; i <= m; i++) {
    int x;
    scanf("%d", &x);
    cant[x] = 1;
  }
  dp[0] = 1;
  for(int i = 1; i <= n; i++) {
    dp[i] = add(i > 1 ? dp[i - 2] : 0, dp[i - 1]);
    if(cant[i])
      dp[i] = 0;
  }
  cout << dp[n] << endl;
  return 0;
}

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

int main() {
  int N;
  cin>>N;
  vector<int>L(N);
  for(int i=0;i<N;i++) cin>>L[i];
  sort(L.begin(),L.end());
  int sum=0;
  for(int i=0;i<N-1;i++) sum+=L[i];
  if(sum>L[N-1]) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define MAX_N 10000
#define INF 1e9

using namespace std;

typedef int long long ll;
typedef int long l;
typedef pair<int, int> Pii;
const ll MOD = 1000000007;


int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    int n = s.size() - 1;
    ll ans = 0;
    for (ll i = 0; i < (1 << n); i++) {
        int pre = 0;
        for (int j = 0; j < n; j++) {
            if ((i >> j) & 1) {
                ans += stoll(s.substr(pre, j +1 - pre));
                // cout << s.substr(pre, j+1 - pre) << endl;
                pre = j+1;
            }
        }
        if(pre>=n+1)
            continue;
        // cout << s.substr(pre) << endl;
        ans += stoll(s.substr(pre));
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
int main()
{
    char a;
    cin>>a;
    int b = (int)(a);
    if(b>=65 && b<=90)
        cout<<"A"<<endl;
    else if(b>=97 && b<=122)
        cout<<"a"<<endl;
    return 0;
}


Measured memory_bytes: 3540
N, M = gets.split.map(&:to_i)
require 'set'
KS = M.times.map { Set.new(gets.split.drop(1).map(&:to_i)) }
P = gets.split.map(&:to_i)

ans = 0
(0...(1 << N)).each do |state|
  k = 0
  is_ok = KS.all? do |set|
    c = (1..N).count do |s|
      state[s - 1] == 1 && set.include?(s)
    end
    ret = c % 2 == P[k]
    k += 1
    ret
  end
  ans += 1 if is_ok
end
puts ans

Measured memory_bytes: 2044
#include <bits/stdc++.h>
using namespace std;
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int (i)=0;i<(n);i++)
#define rrep(i,n) for(int (i)=1;i<=(n);i++)
#define REP(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define MOD 1000000007
#define INF 1e18
#define int long long
#define endl "\n"
#define yorn(f) puts((f)?"Yes":"No")
#define YORN(f) puts((f)?"YES":"NO")
typedef long long ll;
typedef pair<int, int> P;
int gcd(int a,int b){return b?gcd(b,a%b):a;};
int lcm(int a,int b){return a/gcd(a,b)*b;};
int mod(int a,int b){return (a+b-1)/b;};
template<typename A, size_t N, typename T>
void Fill(A(&array)[N],const T &val){std::fill((T*)array,(T*)(array+N),val);}
template<class T>inline bool chmax(T& a,T b){if(a<b){a=b;return true;}return false;};
template<class T>inline bool chmin(T& a,T b){if(a>b){a=b;return true;}return false;};



signed main() {
	cin.tie(nullptr);
	cout.tie(nullptr);
	ios::sync_with_stdio(false);
	//cout << fixed << setprecision(15);
	
	string s;
	cin >> s;
	int sum = 0;
	rep(i, s.size()) {
		sum += s[i] - '0';
	}
	yorn(sum % 9 == 0);
	return 0;
}

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define SP << " " 
#define LLi long long int

using namespace std;

int imax=2147483647;
long long int llimax=9223372036854775807;

//int型vectorを出力
void PV(vector<int> pvv) {
	rep(i, pvv.size()) cout << pvv[i] SP;
	cout << endl;
}

//LLi型vectorを出力
void PVL(vector<LLi> pvv) {
	rep(i, pvv.size()) cout << pvv[i] SP;
	cout << endl;
}

int main(){

	int n, k, s, pos, rem, shu, flag;
	LLi ans=0, ma=-llimax;
	vector<int> p, v;

	cin>> n >> k;
	p.resize(n+1);
	v.resize(n+1);

	rep(i, n) cin >> p[i+1];
	rep(i, n) cin >> v[i+1];

	rep(i, n) {
		s=i+1;
		pos=s;
		rem=k;
		ans=0;
		flag=0;
		while(rem>0){
			ans+=v[p[pos]];
			pos=p[pos];
			rem--;
			ma=max(ma, ans);
			if(pos==s && flag==0){
				shu=k-rem;
				if(rem>shu){
					ans*=rem/shu;
					rem=rem%shu+shu;
				}
				flag=1;
			}
		}
	}

	cout<< ma << endl;
 
	return 0;
}

Measured memory_bytes: 3664
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
class Node{
public:
  int location;
  int p,l,r;
  Node(){}
};
class Point{
public:
  int id,x,y;
  Point(){}
  Point(int id,int x,int y): id(id),x(x),y(y){}
  bool operator < (const Point &p){return id<p.id;}
};
static const int MAX =1000000;
static const int NIL = -1;
int n;
Point P[MAX];
Node T[MAX];
int np;
bool lessX(const Point &p1,const Point &p2){return p1.x<p2.x;}
bool lessY(const Point &p1,const Point &p2){return p1.y<p2.y;}
int makeKDTree(int l,int r, int d){
  if(!(l<r))return NIL;
  int mid=(l+r)>>1;
  int t=np++;
  nth_element(P+l,P+mid,P+r,(d&1 ? lessY : lessX));
  T[t].location=mid;
  T[t].l=makeKDTree(l,mid,d+1);
  T[t].r=makeKDTree(mid+1,r,d+1);
  return t;
}
void find(int v,int sx,int tx,int sy,int ty,int d,vector<Point> &ans){
  int x=P[T[v].location].x;
  int y=P[T[v].location].y;
  if(sx<=x&&x<=tx&&sy<=y&&y<=ty)ans.push_back(P[T[v].location]);
  if(d%2==0){
    if(T[v].l!=NIL&&sx<=x)find(T[v].l,sx,tx,sy,ty,d+1,ans);
    if(T[v].r!=NIL&&x<=tx)find(T[v].r,sx,tx,sy,ty,d+1,ans);
  }
  else{
    if(T[v].l!=NIL&&sy<=y)find(T[v].l,sx,tx,sy,ty,d+1,ans);
    if(T[v].r!=NIL&&y<=ty)find(T[v].r,sx,tx,sy,ty,d+1,ans);
  }
}
int main(){
  int x,y;
  cin>>n;
  rep(i,n){
    scanf("%d %d",&x,&y);
    P[i]=Point(i,x,y);
    T[i].l=T[i].r=T[i].p=NIL;
  }
  np=0;
  int root=makeKDTree(0,n,0);
  int q;
  cin>>q;
  int sx,sy,tx,ty;
  vector<Point>ans;
  rep(i,q){
    scanf("%d %d %d %d",&sx,&tx,&sy,&ty);
    ans.clear();
    find(root,sx,tx,sy,ty,0,ans);
    sort(ans.begin(),ans.end());
    rep(j,ans.size())printf("%d\n",ans[j].id);
    cout<<endl;
  }return 0;
}


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

int main(){
	ios::sync_with_stdio(0);
	cout << setprecision(10) << fixed;
	int n, k, c;
	cin >> n >> k >> c;
	string s;
	cin >> s;
	vector<int> pre(n, 0), suff(n, 0);
	int j = 0, tmpk = 0;
	while (j < n){
		if (s[j] == 'o'){
			pre[j] = ++tmpk;
			j += (c + 1);
			if (tmpk == k){
				break;
			}
		}
		else{
			j++;
		}
	}
	j = n - 1, tmpk = 0;
	while (j >= 0){
		if (s[j] == 'o'){
			suff[j] = ++tmpk;
			j -= (c + 1);
			if (tmpk == k){
				break;
			}
		}
		else{
			j--;
		}
	}
	for (int i = 0; i < n; ++i){
		if (pre[i] == k - suff[i] + 1 && pre[i] != 0){
			cout << i + 1 << "\n";
		}
	}
	return 0;
}



Measured memory_bytes: 3348
read = input 
rn = lambda :list(map(int, read().split()))
def reverse_range(r):return range(r-1, -1, -1)
def sol(a):
    s = set()
    for i in range(1, 10):
        for j in range(1, 10):
            s.add(i*j)
    if a in s:
        print("Yes")
    else:
        print("No")
a = rn()[0]
sol(a)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<(n); ++i)
#define REP(i, d, n) for(int i=(d); i<(n); ++i)
#define all(v) v.begin(), v.end()
using ll = long long;
using P = pair<int, int>;

int main() {

    string s;
    cin >> s;

    string t = s.substr(0, 4);
    string u = s.substr(4);

    cout << t + " " + u << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int inf = numeric_limits<int>::max();

int gcd(int a,int b){
  if(b > a)swap(a,b);
  if(a % b == 0)return b;
  else return gcd(b,a%b);
}

int main(void){
  ll n,m;
  ll a[1100];
  cin >> n >> m;
  for(int i = 0;i < n;++i)cin >> a[i];
  int now = 0;
  ll res = 0;
  ll r = (n*m)/gcd(n,m);
  r /= m;
  for(int i = 0;i < r;++i){
    ll ma = 0;
    ll mi = inf;
    for(int j = 0;j < m;++j){
      ma = max(ma,a[now]);
      mi = min(mi,a[now]);
      ++now;
      now %= n;
    }
    res += ma - mi;
  }
  cout << res << endl;
  return 0;
}

Measured memory_bytes: 3048
using System;
using System.Collections.Generic;
using System.Text;

namespace ConsoleApplication2
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] s =Console.ReadLine().Split(' ');
            int a = int.Parse(s[0]);
            int b = int.Parse(s[1]);
            int c = int.Parse(s[2]);
            int count = 0;

            for (int i = a; i <= b; i++)
            {
                if ((c % i) == 0)
                {
                    count++;
                }
            }

            Console.WriteLine(count);

        }
    }
}

Measured memory_bytes: 5612
#include<bits/stdc++.h>
using lint=long long;
int main(){
    std::cin.tie(nullptr);std::ios_base::sync_with_stdio(false);
    std::cout.setf(std::ios_base::fixed);std::cout.precision(15);
    lint n,m;std::cin>>n>>m;
    std::vector<lint>p(n);
    for(lint i=0;i<n;i++){
        std::cin>>p.at(i);
        p.at(i)--;
    }
    std::vector<std::vector<lint>>g(n);
    while(m--){
        lint u,v;std::cin>>u>>v;u--,v--;
        g.at(u).push_back(v);
        g.at(v).push_back(u);
    }
    std::vector<lint>cmp(n,-1);
    for(lint i=0,j=0;i<n;i++){
        if(cmp.at(i)!=-1)continue;
        std::queue<lint>que;
        que.push(i);
        cmp.at(i)=j;
        while(!que.empty()){
            lint x=que.front();que.pop();
            for(lint y:g.at(x)){
                if(cmp.at(y)!=-1)continue;
                cmp.at(y)=j;
                que.push(y);
            }
        }
        j++;
    }
    lint ans=0;
    for(lint i=0;i<n;i++){
        ans+=cmp.at(i)==cmp.at(p.at(i));
    }
    std::cout<<ans<<'\n';
}


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

#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef vector<int> vi;

ll n,m,q,T,k;
const ll big = 1000000007ll;

vector<ll> A;

vector<ll> X;
vector<ll> Y;

int main() {
    ll a,b,c,d;

    ll ni = 0;
    ll mab = 0;

    cin >> n;
    for(ll c1 = 0; c1 < n; c1++){
        cin >> a;
        A.push_back(a);
        if(abs(a) > mab){
            mab = abs(a);
            ni = c1;
        }
    }

    for(ll c1 = 0; c1 < n; c1++){
        if(c1 != ni){
            X.push_back(ni);
            Y.push_back(c1);
            A[c1] += A[ni];
        }
    }

    if(A[ni] < 0){

        for(ll c1 = n-1; c1 > 0; c1--){
            X.push_back(c1);
            Y.push_back(c1-1);
            A[c1-1] += A[c1];
        }

    }
    else{
        for(ll c1 = 0; c1 < n-1; c1++){
            X.push_back(c1);
            Y.push_back(c1+1);
            A[c1+1] += A[c1];
        }

    }

    cout << sz(X) << "\n";
    for(ll c1 = 0; c1 < sz(X); c1++){
        cout << X[c1]+1 << " " << Y[c1]+1 << "\n";
    }


    return 0;
}


Measured memory_bytes: 256
a, v = map(int, input().split())
b, w = map(int, input().split())
t = int(input())

sa = abs(a - b)
sas = abs(v - w)
if w >= v:
    print("NO")
    exit(0)

d = sa // sas

if d >t:
    print("NO")
if d == t:
    if sa % sas == 0:
        print("YES")
    else:
        print("NO")
if d < t:
    if sa - (d*sas) -sas <=0:
        print("YES")
    else:
        print("NO")


Measured memory_bytes: 9200
import java.util.*;

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

      int N=sc.nextInt();

      int[] A = new int[N+1];
      int[] B = new int[N];

      for(int i=0;i<N+1;i++){
        A[i]=sc.nextInt();
      }
      for(int i=0;i<N;i++){
        B[i]=sc.nextInt();
      }

      long cnt=0;

for(int i=0;i<N;i++){

if(A[i]>=B[i]){
//////////////////////////////////
cnt = cnt + B[i];
/////////////////////////////////
}

if(A[i]<B[i]){
//////////////////////////////////
cnt = cnt + A[i];
B[i] = B[i] - A[i];
  if(A[i+1]>=B[i]){
    cnt = cnt + B[i];
    A[i+1] = A[i+1] - B[i];
  }
  else{
    cnt = cnt + A[i+1];
    A[i+1] = 0;
  }
/////////////////////////////////
}

}

System.out.println(cnt);


    }
}


Measured memory_bytes: 81224
#include <iostream>
#include <cstring>
#include <vector>
#include <set>
#include <map>
#include <sstream>
#include <cstdio>
#include <algorithm>
#include <stack>
#include <queue>
#include <cmath>
#include <iomanip>
#include <fstream>
//#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = (1 << 30);
const ll inf = (1LL << 60LL);
const int  maxn = 305;
const ll MOD = 1e9 + 7;
ll cnt[27];
int main(int argc, const char * argv[]) {
    ios_base::sync_with_stdio(false);
    string s;
    int n;
    cin >> n >> s;
    memset(cnt, 0, sizeof cnt);
    for(int i = 0; i < n;i ++){
        cnt[s[i] - 'a'] ++;
    }
    ll ret = 1;
    for(int i = 0; i < 26; i ++){
        if(cnt[i] != 0){
            ret *= (cnt[i] + 1);
            ret %= MOD;
        }
        
    }
    cout << ret - 1 << endl;
    return 0;
}



Measured memory_bytes: 512
sa,sb,sc=[input() for _ in range(3)]
a=0
b=c=-1
def check(s,i):
  global a,b,c,ans
  if i >= len(s):
    if s == sa:
      ans = "A"
    elif s == sb:
      ans = "B"
    else:
      ans = "C"
  else:
    if s[i] == "a":
      a += 1
      check(sa,a)
    elif s[i] == "b":
      b += 1
      check(sb,b)
    else:
      c += 1
      check(sc,c)
check(sa,a)
print(ans)

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

int main(){
	char a[4];
  	cin>>a;
   	if(a[0]=='7')   {cout<<"Yes";      return 0;}
  	if(a[1]=='7')   {cout<<"Yes";		 return 0;}
  	if(a[2]=='7')   {cout<<"Yes";      return 0;}
  	cout<<"No";
  	return 0;
}

Measured memory_bytes: 3624
import std.stdio;
import std.string;
import std.conv;
import std.typecons;
import std.algorithm;
import std.functional;
import std.bigint;
import std.numeric;
import std.array;
import std.math;
import std.range;
import std.container;
import std.ascii;
void times(alias fun)(int n) {
    foreach(i; 0..n) fun();
}
auto rep(alias fun, T = typeof(fun()))(int n) {
    T[] res = new T[n];
    foreach(ref e; res) e = fun();
    return res;
}
// fold was added in D 2.071.0.
template fold(fun...) if (fun.length >= 1) {
    auto fold(R, S...)(R r, S seed) {
        static if (S.length < 2) {
            return reduce!fun(seed, r);
        } else {
            return reduce!fun(tuple(seed), r);
        }
    }
}

void main() {
    int N, K;
    readf("%d %d\n", &N, &K);
    char[] ary = readln.split.to!(char[]);
    (10*N).iota.find!(a => a>=N && a.to!string.all!(b => !ary.canFind(b))).front.writeln;
}


Measured memory_bytes: 1276
// {{{
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <functional>
#include <numeric>
#include <utility>
#include <limits>
#include <time.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>

using namespace std;

typedef long int i32;
typedef unsigned long int u32;
typedef long long int i64;
typedef unsigned long long int  u64;
typedef pair<i32, i32> PII;
typedef vector<i32> VI;
typedef vector<string> VS;
typedef vector<PII> VII;
typedef vector<VI> VVI;
typedef map<i32, i32> MPII;
typedef set<i32> SETI;
typedef multiset<i32> MSETI;
#define IN(x) cin >> x;
#define SCD(t) scanf("%d",&t)
#define SCLD(t) scanf("%ld",&t)
#define SCLLD(t) scanf("%lld",&t)
#define SCC(t) scanf("%c",&t)
#define SCS(t) scanf("%s",t)
#define SCF(t) scanf("%f",&t)
#define SCLF(t) scanf("%lf",&t)
#define MEM(a, b) memset(a, (b), sizeof(a))
#define ZERO(a) memset(a, 0, sizeof(a))
#define FOR(i, j, k, in) for (int i=j ; i<k ; i+=in)
#define RFOR(i, j, k, in) for (int i=j ; i>=k ; i-=in)
#define REP(i, j) FOR(i, 0, j, 1)
#define RREP(i, j) RFOR(i, j, 0, 1)
#define all(cont) cont.begin(), cont.end()
#define rall(cont) cont.end(), cont.begin()
#define FOREACH(it, l) for (auto it = l.begin(); it != l.end(); it++)
#define BTW(A, B, C) assert( B <= A && A <= C)
#define MP make_pair
#define PB push_back
#define PF push_front
#define INF (int)1e9
#define EPS 1e-9
#define PI 3.1415926535897932384626433832795
#define MOD 1000000007
#define DEBUG(x) cout << #x << ": " << x << endl;

template<typename T, typename U> inline void amin(T &x, U y) { if(y < x) x = y; }
template<typename T, typename U> inline void amax(T &x, U y) { if(x < y) x = y; }
// }}}

const int MAX_N = 100;
const int MAX_V = 100; 
const int MAX_T = 200;
const int RANGE = 2 * MAX_N * MAX_T;
i32 t[MAX_N];
i32 v[MAX_N];
double dp[RANGE][2*MAX_V+2];
int main() {
    int N;
    IN(N);
    REP(i, RANGE) {
        REP(j, MAX_V+1) {
            dp[i][j] = -INF;
        }
    }
    REP(i, N) {
        IN(t[i]);
    }
    REP(i, N) {
        IN(v[i]);
    }
    u32 Tsum = 0;
    REP(i, N) {
        Tsum += t[i];
    }
    u32 index = 0;
    u32 T = t[0];
    dp[0][0] = 0;
    REP(i, 2 * Tsum) {
        if(i >= 2 * T) {
            T += t[++index];
        }
        REP(j, 2*v[index]+1) {
            const float tv = j / 2.0;
            if(dp[i][j] < 0) {
                break;
            }
            if(tv > 0.0) {
                amax(dp[i+1][j-1], dp[i][j] + 0.5 * tv - 0.125);
            }
            if(tv + 0.5 <= v[index]) {
                amax(dp[i+1][j+1], dp[i][j] + 0.5 * tv + 0.125);
            }
            amax(dp[i+1][j], dp[i][j] + 0.5 * tv);
        }
    }
    // REP(i, 2*Tsum) {
    //     REP(j, 2*v[index]+1) {
    //         printf("dp[%d][%d]: %f\n", i+1, j, dp[i+1][j]);
    //     }
    // }
    printf("%0.10lf\n", dp[2*Tsum][0]);
    return 0;
}



Measured memory_bytes: 63488
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cmath>
#include <iomanip>
using namespace std;
typedef long long int LL;
typedef pair<int,int> P;
const int INF=100000000;
const int MOD_2=998244353;

LL ans(LL num)
{
	if(num==1)return 1;
	else return 2*ans(num/2)+1;
}
int main()
{
	LL H;
	cin>>H;
	cout<<ans(H)<<"\n";
	return 0;
}
	

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

int main(){
int N, sum, mi;
  cin>> N;
  sum = 0;
  mi = 100;
    
int a[N];
  for(int i = 0;i < N;i++){
    cin >> a[i];
    sum += a[i];
    if(a[i] % 10 != 0){
    mi = min(mi, a[i]);
    }
  } 
    
   if((sum % 10 != 0) && (sum > 0)){
      cout << sum << endl;
    }
    
   else if((sum % 10 == 0) && (mi > 0) && (mi != 100)){
     sum -= mi;
     cout << sum << endl;
    }  
  
   else if((sum % 10 == 0) && (mi == 100)){
     cout << 0 << endl;
    }  
  
   else if(sum == 0){
    cout << 0 << endl;
        }
  
  return 0;
}

Measured memory_bytes: 256
/**
 * Quick Sort
 * http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_6_C&lang=ja
 */

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

/*
quicksort(A, p, r)
  if p < r
    q = partition(A, p, r)
    quickSort(A, p, q-1)
    quickSort(A, q+1, r)
*/

struct Card {
  char suit; // D,H..
  int value; // 1..13
};

int partition(vector<Card> &A, int p, int r) {
  int x = A.at(r).value;
  int i = p - 1;
  for (int j = p; j < r; j++) {
    if (A.at(j).value <= x) {
      i = i+1;
      // cout << "swap" << i << ' ' << j;
      swap(A.at(i), A.at(j));
    }
  }

  swap(A.at(i + 1), A.at(r));
  return i + 1;
}

void quickSort(vector<Card> &A, int p, int r) {
  if (p < r) {
    int q = partition(A, p, r);
    quickSort(A, p, q-1);
    quickSort(A, q+1, r);
  }
}

/**
 * ソートが安定的かどうかを判定する
 */
string isStable(vector<Card>A, vector<Card>S, int N) {
  // int count = 0;
  for (int i = 0; i < N - 1; i++) {
    for (int j = 0; j < S.size(); j++) {
      // 一致する要素が登場したら、一致した要素は安定的であるとして削除する
      if (S.at(j).suit == A.at(i).suit && S.at(j).value == A.at(i).value) {
        S.erase(S.begin() + j);
        break;
      }
      // 一致する要素が登場する前に、数字が同じ他のカードが登場してしまった
      if (A.at(i).value == S.at(j).value) {
        return "Not stable";
      }
    }
  }

  return "Stable";
}

void printCard(vector<Card> &A) {
    for (int i = 0; i < A.size(); i++) {
      cout << A.at(i).suit << ' ' << A.at(i).value << endl;
  }
}

int main() {
  // 1行目にカードの枚数 n が与えられます。
  int n;
  cin >> n;

  // 2行目以降で n 枚のカードが与えられます。各カードは絵柄を表す１つの文字と数（整数）のペアで１行に与えられます。絵柄と数は１つの空白で区切られています。 
  vector<Card> A(n);
  for (int i = 0; i < n; i++) {
    struct Card c;
    cin >> c.suit >> c.value;
    A.at(i) = c;
  }

  // ソート前の配列をAとし、ソート対象の配列をSとする
  vector<Card> S = A;
  quickSort(S, 0, n - 1);

  // 結果の出力
  cout << isStable(A, S, n) << endl;
  printCard(S);
}



Measured memory_bytes: 5948
#include<bits/stdc++.h>
using namespace std;
map<int, int>M;
int t;
long long ans;
int main()
{
	int N;
	scanf("%d", &N);
	for (int i = 0; i < N; i++) {
		scanf("%d", &t);
		M[t]++;
	}
	int minn = 0 , maxn = 0;
	for (auto it = M.begin(); it != M.end(); it++) {
		if (it->second >= 4) {
			minn = maxn = it->first;
		}
		else if (it->second >= 2) {
			minn = maxn;
			maxn = it->first;
		}
	}
	ans = 1LL * minn*maxn;
	printf("%lld", ans);
}

Measured memory_bytes: 4992
#                          JAI SHREE RAM

import math; from collections import *
import sys; from functools import reduce

def get_ints(): return map(int, input().strip().split())
def get_list(): return list(get_ints())
def getlistofstring(): return list(input().strip().split())
def printxsp(*args): return print(*args, end="")
def printsp(*args): return print(*args, end=" ")

UGLYMOD = int(1e9)+7; SEXYMOD = 998244353; MAXN = int(1e5)

# sys.setrecursionlimit(10**6)
# sys.stdin=open("input.txt","r");sys.stdout=open("output.txt","w")

# for _testcases_ in range(int(input())):
N = int(input())
dp = [2] * (N+1)
dp[1] = 1
i = 2
while i < N:
    for j in range(2*i, N+1, i):
        dp[j] += 1
    i += 1
# print(dp[1:])
print(sum(i * dp[i] for i in range(1, N+1)))

'''
>>> COMMENT THE STDIN!! CHANGE ONLINE JUDGE !!
THE LOGIC AND APPROACH IS MINE @luctivud ( UDIT GUPTA )
Link may be copy-pasted here if it's taken from other source.
DO NOT PLAGIARISE.
>>> COMMENT THE STDIN!! CHANGE ONLINE JUDGE !!
'''

Measured memory_bytes: 152876
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
using namespace std;
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; ++i )
#define rep(i,n) REP(i,0,n)
typedef long long ll;
typedef pair<int,int> pint;
typedef pair<ll,int> pli;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

int main(){
  ll n,m;
  cin >> n >> m;
if(m<2*n)cout << m/2 << endl;
else cout << n+(m-2*n)/4 << endl;
return 0;}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vb = vector<bool>;
using vs = vector<string>;
using msi = map<string, int>;
using mii = map<int, int>;
using psi = pair<string, int>;
using pii = pair<int, int>;
using vlai = valarray<int>;
#define rep(i,n) for(int i=0;i<n;i++)
#define range(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 fs first
#define sc second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define INF 1E9
#define LINF 1E17
#define EPS 1E-9
#define MOD 1000000007
#define PI 3.1415926535897932384

template<class S, class T>ostream& operator<<(ostream&os, pair<S, T>p) { os << "[" << p.first << ", " << p.second << "]"; return os; };
template<class S>auto&operator<<(ostream&os, vector<S>t) { bool a = 1; for (auto s : t) { os << (a ? "" : " ") << s; a = 0; } return os; }

//int dx[]={1,1,1,0,-1,-1,-1,0},dy[8]={1,0,-1,-1,-1,0,1,1,1};
//
constexpr ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }


int main() {
	int n,q,k;
	ll a, b, c;
	vl av, bv, cv;
	cin >> n;
	rep(i, n-1) {
		cin >> a >> b >> c;
		av.push_back(a-1);
		bv.push_back(b-1);
		cv.push_back(c);
	}
	cin >> q >> k;
	k--;
	vector<vector<tuple<int, int>>> vv(n);
	rep(i, av.size()) {
		tuple<int, int> t(bv[i], cv[i]);
		vv[av[i]].push_back(t);
		tuple<int, int> s(av[i], cv[i]);
		vv[bv[i]].push_back(s);
	}
	vl dist(n,-1);
	dist[k] = 0;
	stack<int> stk;
	stk.push(k);
	while (!stk.empty()) {
		int tgt = stk.top(); stk.pop();
		rep(i, vv[tgt].size()) {
			int to = get<0>(vv[tgt][i]);
			if (dist[to] == -1) {
				dist[to] = dist[tgt] + get<1>(vv[tgt][i]);
				stk.push(to);
			}
		}
	}
	rep(i, q) {
		cin >> a >> b;
		cout << (dist[a-1]+dist[b-1]) << endl;
	}
}


Measured memory_bytes: 11104
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
#include <memory>
#include <regex>
using namespace std;

const int INF = INT_MAX / 2;

int main()
{
    int n;
    cin >> n;
    vector<vector<int> > v(n, vector<int>(3));
    for(int i=0; i<n; ++i){
        for(int j=0; j<3; ++j){
            cin >> v[i][j];
        }
    }

    vector<int> dp(3, 0);
    for(int i=0; i<n; ++i){
        vector<int> nextDp(3, -INF);
        for(int j=0; j<3; ++j){
            for(int k=0; k<3; ++k){
                if(j != k)
                    nextDp[k] = max(nextDp[k], dp[j] + v[i][k]);
            }
        }
        dp = move(nextDp);
    }
    int ans = *max_element(dp.begin(), dp.end());
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 5760