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

constexpr int INF = 1e9;

int N, M;
int memo[51][51][51][51][2][2];
vector<int> a, b;

int calc(int si, int sj, int i, int j, int turn) {
    int score_a = 0, score_b = 0;
    if(turn == 0) {
        if(i - si < j - sj) {
            if(b[sj] != -1) {
                score_b = b[sj];
            }
            sj += 1;
        }
        for(int k=0; k<i-si; ++k) {
            if(a[si+k] == -1) {
                score_b = 0;
            } else {
                score_a += a[si+k];
            }
            if(b[sj+k] == -1) {
                score_a = 0;
            } else {
                score_b += b[sj+k];
            }
        }
    } else {
        if(j-sj < i-si) {
            if(a[si] != -1) {
                score_a = a[si];
            }
            si += 1;
        }
        for(int k=0; k<i-si; ++k) {
            if(b[sj+k] == -1) {
                score_a = 0;
            } else {
                score_b += b[sj+k];
            }
            if(a[si+k] == -1) {
                score_b = 0;
            } else {
                score_a += a[si+k];
            }
        }
    }
    return score_a - score_b;
}

// [si, i), [sj, j)
int dp(int si, int sj, int i, int j, int turn, int pass) {
    int& r = memo[si][sj][i][j][turn][pass];
    if(r != INF) {
        return r;
    }
    if(turn == 0) {
        r = -INF;
        if(pass == 1) {
            r = max(r, 0);
        } else {
            r = max(r, dp(i, j, i, j, 1, (i == si && j == sj)) + calc(si, sj, i, j, 0));
        }
        if(i < N) {
            r = max(r, dp(si, sj, i+1, j, 1, 0));
        }
    } else {
        r = INF;
        if(pass == 1) {
            r = min(r, 0);
        } else {
            r = min(r, dp(i, j, i, j, 0, (i == si && j == sj)) + calc(si, sj, i, j, 1));
        }
        if(j < M) {
            r = min(r, dp(si, sj, i, j+1, 0, 0));
        }
    }
    return r;
}

int main() {
    cin >> N >> M;
    a.resize(N);
    b.resize(M);
    for(int i=0; i<N; ++i) {
        cin >> a[i];
    }
    for(int i=0; i<M; ++i) {
        cin >> b[i];
    }
    fill(memo[0][0][0][0][0], memo[50][50][50][50][2], INF);
    cout << dp(0, 0, 0, 0, 0, 0) << endl;
}


Measured memory_bytes: 108828
S = input()
a = 0
b = 0
for i in range(len(S)):
	if i % 2 == 0:
		if S[i] == '0':
			a += 1
		else:
			b += 1
	else:
		if S[i] == '0':
			b += 1
		else:
			a += 1
print(min(a, b))


Measured memory_bytes: 3188
#include<iostream>
#include<vector>
#include<map>
#include<algorithm>
using namespace std;
int main(){
  int n,m,x,y;
  while(cin >>n,n){
    vector<pair<int, int> > doll;
    doll.push_back(make_pair(0,0));
    int dp[201] = {0};
    int ans = 0;
    for(int i=0; i<n; i++){cin >>x>>y;doll.push_back(make_pair(x,y));}
    cin >>m;
    for(int i=0; i<m; i++){cin >>x>>y;doll.push_back(make_pair(x,y));}
    sort(doll.begin(),doll.end());
    for(int i=1; i<doll.size(); i++){
      int r = 0;
      for(int j=0; j<i; j++){
	if(doll[j].second<doll[i].second && doll[j].first<doll[i].first && r<dp[j]){r = dp[j];}
      }
      dp[i] = r+1;
    }
    for(int i=0;i<doll.size();i++){
      if(ans<dp[i]){ans = dp[i];}
    }
    cout <<ans<<endl;
  }
  return 0;
}

Measured memory_bytes: 1204
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;

int main() {
  string s;
  cin >> s;
  int count[2];
  count[0] = count[1] = 0;
  for (int i = 0; i < s.size(); i++) {
    if (s[i] == '+') count[0]++;
    else count[1]++;
  }
  cout << count[0] - count[1] << endl;
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <memory.h>
int main(void){
  int i,j,n,a[11][11];
  while(scanf("%d",&n),n){
    memset(a,0,sizeof(a));
    for(i=0;i<n;i++){
      for(j=0;j<n;j++){
	scanf("%d",&a[i][j]);
	a[n][j]+=a[i][j];
	a[i][n]+=a[i][j];
      }
    }
    for(i=0;i<n;i++)
      a[n][n]+=a[n][i];
    for(i=0;i<=n;i++){
      for(j=0;j<=n;j++){
	printf("%5d",a[i][j]);
      }
      puts("");
    }
  }
  return 0;
}

Measured memory_bytes: 620
#include <stdio.h>
#include <iostream>
#include <string.h>
#include <string>
#include <math.h>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <stdlib.h>
#include <time.h>
#include <limits.h>
#include <assert.h>
using namespace std;
int n, k, a[100000], dp[100000];
int calc(int i) {
	if (i == n - 1) return 0;
	if (dp[i] != -1) return dp[i];
	int res = calc(i + 1) + abs(a[i] - a[i + 1]);
	for (int j = 2; j <= k; j++) {
		if (i + j >= n) break;
		res = min(res, calc(i + j) + abs(a[i] - a[i + j]));
	}
	return dp[i] = res;
}
int main() {
	scanf("%d %d", &n, &k);
	for (int i = 0; i < n; i++) scanf("%d", &a[i]);
	memset(dp, -1, sizeof(dp));
	int ans = calc(0);
	printf("%d\n", ans);
	return 0;
}

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

using namespace std;

int main()
{
    string s;
    cin >> s;
    int cnt = 0;
    for (int i = 0; i < s.size(); i++)
    {
        if (s[i] == '1')
            cnt++;
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int MAXN=5010;
char s[MAXN],ans[MAXN],t[MAXN<<1];
int n,k;
inline void change(register int x)
{
	for(register int i=1;i<=n;i++) t[(n<<1)-i+1]=t[i];
	memmove(t+1,t+x,n);
	return;
}
inline void work(register int l,register int r)
{
	memcpy(t+1,s+1,n);
	if(k==1) change(l);
	else
	{
		register int now=k;
		if(r!=n) change(n-l+2),l=n+l-r,r=n,now--;
		for(register int i=1;i<now&&l>1;i++) change(n-l+2),l=(l<<1)-n-1;
		l=max(l,1);
		change(l);
	}
	if(strcmp(t+1,ans+1)<0) memcpy(ans+1,t+1,n);
}
int main()
{
	scanf("%d%d%s",&n,&k,s+1);
	memcpy(ans+1,s+1,n);
	for(register int i=1;i<=n;)
	{
		register int ri=i;
		while(s[ri]==s[i]) ri++;
		work(i,ri-1);
		i=ri;
	}
	puts(ans+1);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<(n);i++)
#define all(x) (x).begin(), (x).end()
using ll = long long;
using namespace std;
template <typename T>
using vec = std::vector<T>;


int main() {
    int N;
    string S;
    cin >> N >> S;
    
    int ans = 0;
    function<void(string)> dfs = [&](string s) {
        if(s.size()==3){
            int index = 0;
            for(auto e:S){
                if(e==s[index]) ++index;
                if(index==3){
                    ++ans;
                    break;
                }
            }
        } else {
            rep(i,10) dfs(s+to_string(i));
        }
    };
    dfs("");
    cout << ans << endl;
}

Measured memory_bytes: 256
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define ll long long
#define rep(i,n) for(ll i=0;i<(n);i++)
#define pll pair<ll,ll>
#define pii pair<int,int>
#define pq priority_queue
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define endl '\n'
#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define lb(c,x) distance(c.begin(),lower_bound(all(c),x))
#define ub(c,x) distance(c.begin(),upper_bound(all(c),x))

using namespace std;

const ll INF=1e15;

int main(){
    ll n;
    cin >> n;
    ll cnt=0;
    bool ok=false;
    rep(i,n){
        ll a,b;
        cin >> a >> b;
        if(a==b) cnt++;
        else cnt=0;
        if(cnt==3){
            ok=true;
            break;
        }
    }
    if(ok) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

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

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for(int i=0;i<n;i++){
    cin >> a.at(i);
  }
  bool b=true;
  for(int i=0;i<n;i++){
    if(a.at(i)%2==0){
      if(a.at(i)%3!=0 && a.at(i)%5!=0)
        b=false;
    }
  if(!b)break;
  }
  if(b) cout << "APPROVED" << endl;
  else cout << "DENIED" << endl;
  
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int max_n=200005;
const int mod=998244353;
inline int Add(int x,int y){
    return (x+=y)>=mod?x-mod:x;
}
inline int Sub(int x,int y){
    return (x-=y)<0?x+mod:x;
}
inline int Mul(int x,int y){
    return 1ll*x*y%mod;
}
inline int Pow(int x,int y){
    int res=1;
    while(y){
        if(y&1)res=1ll*res*x%mod;
        y>>=1;
        x=1ll*x*x%mod;
    }
    return res;
}
int n;
char s[max_n];
int a[max_n];
int solve(int x){
    int k=n/x;
    int res=0;
    for(int i=1;i<=k;i++){
        res=Add(res,res);
        if(s[i]=='1')res=Add(res,1);
    }
    bool flag=true;
    for(int i=k+1;i<=n;i++){
        int r=(i-1)%(2*k)+1;
        int c;
        if(r<=k)c=s[r]-'0';
        else c=(s[r-k]-'0')^1;
        if(c<s[i]-'0')break;
        else if(c==s[i]-'0')continue;
        else{
            flag=false;
            break;
        }
    }
    if(flag==true)res=Add(res,1);
    return res;
}
int main(){
    scanf("%d %s",&n,s+1);
    for(int i=1;i<=n;i++){
        if(n%i||i%2==0)continue;
        a[i]=solve(i);
    }
    for(int i=n;i>=1;i--){
        for(int j=i*2;j<=n;j+=i)a[i]=Sub(a[i],a[j]);
    }
    int ans=0;
    for(int i=1;i<=n;i++)ans=Add(ans,Mul(n/i*2,a[i]));
    printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 896
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll,ll>;
using vl = vector<ll>;
using Map = map<ll,ll>;
using T = tuple<ll,ll,ll>;
using vvl = vector<vector<ll>>;
#define all(v) v.begin(), v.end()
#define prt(v) cout<<(v)<<"\n";
#define fi(v) get<0>(v)
#define se(v) get<1>(v)
#define th(v) get<2>(v)
#define endl "\n"
template <typename T> bool chmax(T &a, const T &b){if (a<b){a=b;return 1;}return 0;}
template <typename T> bool chmin(T &a, const T &b){if (a>b){a=b;return 1;}return 0;}
const ll INF=1LL<<60;
const ll MOD=1000000007;


signed main(void){
    cin.tie(0);cout.tie(0);ios::sync_with_stdio(false);
    ll N;
    cin >> N;
    vector<ll> P(N,0);
    for(ll i=0;i<N;++i)cin>>P[i];

    deque<ll> deq;
    ll ren=0;
    for(ll i=0;i<N;++i){
        if(P[i]==i+1){ren++;continue;}
        else if(ren)deq.emplace_back(ren);
        ren=0;
    }
    if(ren)deq.emplace_back(ren);

    ll ans=0;
    for(ll i=0;i<deq.size();++i){
        ans+=(deq[i]+1)/2;
    }
    prt(ans)
    //for(auto p: deq)prt(p)

    return 0;
}


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

typedef long long Int;

constexpr Int INF = 10000000000;
Int a[200005];

int main(){
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
  }

  auto f = [&a, &n](Int x) -> Int {
      Int sum = 0;
      for (int i = 0; i < n; ++i) {
          sum += abs(a[i] - (x + (i + 1)));
      }
      return sum;
  };

  auto tenary_search = [&f]() -> Int {
      Int l = -INF, r = INF;
      Int a, b;

      for (int i = 0; i < 100; ++i) {
          a = (2 * l + r) / 3;
          b = (l + 2 * r) / 3;
          if (f(a) < f(b)) r = b;
          else l = a;
      }

      Int res = f(r);
      for (Int i = l; i < r; ++i) {
        Int temp = f(i);
        if (temp < res) {
          res = temp;
        }
      }
      return res;
  };

  cout << tenary_search() << "\n";
}


Measured memory_bytes: 1792
#include<cstring>
#include<string>
#include<vector>
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<stack>
#include<queue>
#include<cmath>
#include<algorithm>
#include<list>
#include<set>
#include<map>
#include<complex>
#include<sstream>
#include<climits>
#define rep(X,Y) for (int (X) = 0;(X) < (Y);++(X))
#define rrep(X,Y) for (int (X) = (Y)-1;(X) >=0;--(X))
#define all(X) (X).begin(),(X).end()
#define pb push_back
#define mp make_pair
#define fi first
#define sc second
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

const int MAX_N = 100000;
int N, L, Q;
int x[MAX_N];
int r[20][MAX_N];

int can_reach(int i, int d) {
  if (d == 0) return i;
  int k = 0;
  while (d >= (1<<k)) ++k;
  --k;
  return can_reach(r[k][i], d-(1<<k));
}

int main() {
  cin >> N;
  rep(i,N) cin >> x[i];
  cin >> L >> Q;

  for (int i = 0; i < N; ++i) {
    r[0][i] = upper_bound(x, x+N, x[i]+L) - x - 1;
  }

  int K = 0;
  while (N >= (1<<K)) ++K;
  for (int k = 1; k < K; ++k) {
    for (int i = 0; i < N; ++i) {
      r[k][i] = r[k-1][r[k-1][i]];
    }
  }


  while (Q--) {
    int a, b;
    scanf("%d%d", &a, &b);
    --a; --b;
    if (a > b) swap(a,b);

    int lb = 0, ub = N, d = 0;
    while (ub-lb > 1) {
      d = (ub+lb)/2;
      if (can_reach(a, d) >= b) ub = d;
      else lb = d;
    }
    printf("%d\n", ub);
  }

  return 0;
}


Measured memory_bytes: 9088
// includes {{{
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<tuple>
#include<cmath>
#include<random>
#include<cassert>
#include<bitset>
#include<cstdlib>
// #include<deque>
// #include<multiset>
// #include<cstring>
// #include<bits/stdc++.h>
// }}}
using namespace std;
using ll = long long;

int main() {
  std::ios::sync_with_stdio(false), std::cin.tie(0);
  int a, b;
  cin >> a >> b;
  cout << 1 + 2 + 3 - a - b << endl;
  return 0;
}


Measured memory_bytes: 256
n,m = map(int, input().split())
ans = [-1] *n
f= 0
for i in range(m):
    s,c = map(int, input().split())
    #if (ans[s-1] != -1) and (ans[s-1] != c):  # 重複
    if (ans[s-1] == -1) or (ans[s-1] == c):
        ans[s-1] = c
    else:
        print('-1')
        exit()
'''
        f = 1
if f == 1:
    print('-1')
    exit()'''

if ans[0] == 0 and len(ans) != 1:  # 1桁以外の頭0
    print('-1')
    exit()

if ans[0] == -1:
    if len(ans) != 1:  # 頭に指定がない時は1
        ans[0] = 1
    else:
        print(0)
        exit()

for i in range(n):
    if ans[i] == -1:
        ans[i] = 0
print(''.join(map(str, ans)))



Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define rep2(i, s, n) for(int i=s; i<(n); ++i)
#define ALL(v) (v).begin(), (v).end()

using namespace std;

typedef long long ll;

static const int INTINF = (2147483647 >> 1); // 10^9 + 5000
static const ll LLINF = (9223372036854775807 >> 1);
static const int MAX = 1e5+1;
static const ll MOD = 1e9+7;

namespace Printer{
    template<class T>
    void print(T x){
        cout << x << endl;
    }

    template<class T>
    void print(T x, T y){
        cout << x << "," << y << endl;
    }

    template<class T>
    void print(vector<T> v){
        rep(i, v.size()){
            if(i) cout << " ";
            cout<< v[i];
        }
        cout << endl;
    }

    template<class T>
    void print(vector<vector<T> > vv){
        rep(i, vv.size()){
            rep(j, vv[i].size()){
                if(j) cout << " ";
                cout << vv[i][j];
            }
            cout << endl;
        }
    }

    void print(pair<int, int> p){
        cout << "(" << p.first << ", " << p.second << ")" << endl;
    }
};
using namespace Printer;

//--global--//



//----------//

int main(int argc, const char * argv[]) {
    //提出時、消す----//
    //--------------//

    string str;
    cin >> str;
    int n = str.size();
    vector<int> x(n);
    rep(i, n){
        if(str[i] == 'S')x[i] = 1;
        else x[i] = -1;
    }
    int ans = 0;
    int sum = 0;
    rep(i, n){
        if(sum + x[i] >= 0 && x[i] < 0) ans++;
        sum += x[i];
        if(sum < 0) sum = 0;
    }
    cout << n - ans * 2 << endl;
    
    
    return 0;
}


Measured memory_bytes: 1412
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>

using namespace std;

int main(){

	int m;
	while(cin>>m&&m!=0){
		int cnts[101];
		fill(cnts,cnts+101,0);
		// dp[i][j]ツづ絞ツ氾板姪堋づ個青板篠堋づーツづつつゥツづづツづーツづつつュツづェツづゥツ古つ青板づーツ表ツつキ
		int dp[101][2001];
		for(int i = 0; i < 100; i++){
			for(int j = 0; j < 1001; j++){
				dp[i][j]=0;
			}
		}
		dp[0][0]=1;
		for(int i = 0; i < m; i++){
			int a,b;
			cin>>a>>b;
			cnts[a]+=b;
		}
		for(int i = 1; i <= 100; i++){
			if(cnts[i]!=0){
				for(int j = 0; j <= 1000; j++){
					for(int k = 0; k <= cnts[i]; k++){
						if(j-k*i>=0){
							dp[i][j]+=dp[i-1][j-k*i];
						}
						else
							break;
					}
				}
			}
			else{
				for(int j = 0; j <= 1000; j++){
					dp[i][j]=dp[i-1][j];
				}
			}
		}
		int g;
		cin>>g;
		for(int i = 0; i < g; i++){
			int n;
			cin>>n;
			cout<<dp[100][n]<<endl;
		}
	}

	return 0;
}

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

int main() {
    string a;
    getline(cin, a);
    int b=a.size();
    for(int i=0; i<b; i++){
        char &c=a.at(i);
        if(isupper(c)){
            c=tolower(c);
            continue;
        }
        if(islower(c)) c=toupper(c);
    }
    cout << a << endl;
    return 0;
}




Measured memory_bytes: 3168
from collections import defaultdict
n = int(input())
s = [list(map(int,input().split())) for i in range(n)]
s.sort()
c = []
if n == 1:
    print(1)
else:
    for i in range(n):
        for j in range(i+1,n):
            x = s[j][0] - s[i][0]
            y = s[j][1] - s[i][1]
            c.append(str(x) + " " + str(y))
    r = defaultdict(int)
    for g in c:
        r[g] += 1
    q = list(r.values())
    q1 = max(q)
    print(n-q1)


Measured memory_bytes: 39664
def p_b():
    N, K = map(int, input().split())
    H = list(map(int, input().split()))
    ans = [10 ** 9] * N
    ans[0] = 0
    for i in range(1, N):
        k = max(0, i - K)
        for j in range(k, i):
            ans[i] = min(ans[i], ans[j] + abs(H[j] - H[i]))

    print(ans[-1])


if __name__ == '__main__':
    p_b()


Measured memory_bytes: 54136
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)n; ++i)
#define repi(i, a, b) for (int i = int(a); i < int(b); ++i)
#define repr(i, n) for (int i = (int)n - 1; i >= 0; --i)
#define ALL(a) (a).begin(), (a).end()
using ll = long long;
using Graph = vector<vector<int>>;
const ll mod = 1e9 + 7;

int main() {
  string s;
  cin >> s;
  int n = s[0] + s[1] + s[2];
  if (n != 195) {
    if (n != 198)
      cout << "Yes" << endl;
    else
      cout << "No" << endl;
  } else
    cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 256
from sys import exit
N,K = map(int,input().split())
town = [None]+list(map(int,input().split()))

flag = [None]+[0]*N
remain = K
piece = 1
cnt = 1
while remain > 0:
    if flag[town[piece]] != 0:
        q = cnt-flag[town[piece]]
        piece = town[piece]
        remain -= 1
        break
    else:
        piece = town[piece]
        flag[piece] = cnt
        remain -= 1
        cnt += 1

if remain == 0:
    print(piece)
    exit(0)

remain %= q

while remain > 0:
    piece = town[piece]
    remain -= 1

print(piece)

Measured memory_bytes: 100848
#include<bits/stdc++.h>
#define ll long long int
using namespace std;
 
const int N=(int)2e5+10;
int arr[N];
int n,k;
bool isvalid(int mid)
{
	int kk=k;
	if(mid==0)
	return 0;
	for(int i=0;i<n;i++)
	{
		if(arr[i]<=mid)
		continue;
		int t=arr[i]/mid;
		kk-=t;
	}
	return (kk>=0);
}
int main()
{
	cin>>n>>k;
	for(int i=0;i<n;i++)
	cin>>arr[i];
	
	int i=0,j=(int)1e9+10;
	while(i<j)
	{
		int mid=(i+j)/2;
		if(isvalid(mid))
		{
			j=mid;
		}
		else
		i=mid+1;
	}
	cout<<j<<endl;
}

Measured memory_bytes: 4340
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  vector<int>A(N);
  for(int i=0;i<N;i++){
    cin >> A.at(i);
  }
  int max = 0;
  int second = 0;
  vector<int>argmax(N,0);
  for(int i=0;i<N;i++){
    if(max < A.at(i)){
      max = A.at(i);
    }else if(second < A.at(i)){
      second = A.at(i);
    }
  }
  int dbl = 0;
  for(int i=0;i<N;i++){
    if(max == A.at(i)){
      argmax.at(i) = 1;
      dbl += 1;
    }
  }
  for(int i=0;i<N;i++){
    if(dbl > 1){
      cout << max << endl;
    }else if(argmax.at(i) == 1){
      cout << second << endl;
    }else{
      cout << max << endl;
    }
  }
}

Measured memory_bytes: 3200
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define speed ios_base::sync_with_stdio(0); cin.tie(0);
#define FL(i,a,n) for(ll i=a;i<n;i++)
#define even(x) (((x)%(2))==(0))
#define odd(x) (((x)%(2))==(1))
#define meme(x) memset(x, 0, sizeof(x))
#define mod 1000000007

#define pb push_back
#define mp make_pair
#define ff first
#define ss second

int main()
{
    speed
    int n;cin>>n;
    int a[n];
    int cnt=0;
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
        if(even(i) && odd(a[i]))
        cnt++;
    }
    cout<<cnt;
}



Measured memory_bytes: 3652
#include<iostream>
#include<string>
using namespace std;
int main(){
string w;
cin >>w;
int a[26]={};
for(int i=0;i<w.size();i++){
a[w[i]-'a']++;
}
bool flag=true;
for(int i=0;i<26;i++){
if(a[i]%2!=0)
flag=false;
}
if(flag)
cout <<"Yes";
else
cout<<"No";
return 0;
}


Measured memory_bytes: 256
/*
 * Author:  heyuhhh
 * Created Time:  2020/5/13 17:07:47
 */
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <vector>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include <iomanip>
#include <assert.h>
#define MP make_pair
#define fi first
#define se second
#define pb push_back
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
#define INF 0x3f3f3f3f
#define Local
#ifdef Local
  #define dbg(args...) do { cout << #args << " -> "; err(args); } while (0)
  void err() { std::cout << std::endl; }
  template<typename T, typename...Args>
  void err(T a, Args...args) { std::cout << a << ' '; err(args...); }
  template <template<typename...> class T, typename t, typename... A> 
  void err(const T <t> &arg, const A&... args) {
  for (auto &v : arg) std::cout << v << ' '; err(args...); }
#else
  #define dbg(...)
#endif
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
//head
const int N = 2e5 + 5;

int n, k, c;
char s[N];
int nxt[N], last[N];

void run() {
    cin >> n >> k >> c;
    cin >> (s + 1);
    int t = 0;
    int now;
    for (int i = 1, j; i <= n; i = j) {
        now = i;
        j = i + c + 1;
        while (j <= n && s[j] == 'x') ++j;
        if (j <= n) {
            nxt[i] = j;
            last[j] = i;
            ++t;
        }
    }
    ++t;
    if (t != k) {
        return;
    }
    vector <int> pre(n + 2);
    for (int i = 1; i <= n + 1; i++) {
        pre[i] = pre[i - 1] + (s[i] == 'o');
    }
    vector <int> ans;
    int rb = n + 1;
    for (int i = now; i; i = last[i]) {
        if (rb == i || pre[rb] - pre[i] == 0) {
            ans.push_back(i);
        }
        for (int j = min(rb, i + c); j >= i; j--) {
            if (s[j] == 'o') {
                rb = j - c - 1;
                break;
            }
        }
    }
    sort(all(ans));
    for (auto it : ans) cout << it << '\n';
}

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

Measured memory_bytes: 6572
#![allow(unused)]

use std::{cell, cmp, collections, convert, fmt, io, iter, ops, str};

use cell::{Cell, RefCell};
use cmp::Ordering::{Equal, Greater, Less};
use collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, LinkedList, VecDeque};
use io::{Read, Write};

#[cfg(feature = "debug")]
macro_rules! debug {
    ($($args: tt)*) => { eprint!($($args)*) };
}

#[cfg(feature = "debug")]
macro_rules! debugln {
    ($($args: tt)*) => { eprintln!($($args)*) };
}

#[cfg(not(feature = "debug"))]
macro_rules! debug {
    ($($args:tt)*) => {};
}

#[cfg(not(feature = "debug"))]
macro_rules! debugln {
    ($($args:tt)*) => {};
}

macro_rules! vmax {
    ($x: expr, $y: expr) => { cmp::max($x, $y) };
    ($x: expr, $($args: expr),*) => { cmp::max($x, vmax!($($args),*)) };
}

macro_rules! vmin {
    ($x: expr, $y: expr) => { cmp::min($x, $y) };
    ($x: expr, $($args: expr),*) => { cmp::min($x, vmin!($($args),*)) };
}

fn main() {
    let tasks = parse_vec::<i32>();

    let cost = |idx0: usize, idx1: usize, idx2: usize| -> i32 {
        (tasks[idx1] - tasks[idx0]).abs() + (tasks[idx2] - tasks[idx1]).abs()
    };

    let ans = vmin!(
        cost(0, 1, 2),
        cost(0, 2, 1),
        cost(1, 0, 2),
        cost(1, 2, 0),
        cost(2, 0, 1),
        cost(2, 1, 0)
    );
    println!("{}", ans);
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn test() {
        //
    }
}

fn read_line() -> String {
    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.trim().to_owned()
}

fn read_word() -> String {
    const CAPACITY: usize = 16;

    let mut stdin = io::stdin();
    let mut byte: [u8; 1] = [0];

    loop {
        let mut buf = Vec::with_capacity(CAPACITY);

        loop {
            let res = stdin.read(&mut byte);

            if res.unwrap_or(0) == 0 || byte[0] <= b' ' {
                break;
            } else {
                buf.push(byte[0]);
            }
        }

        if !buf.is_empty() {
            return String::from_utf8(buf).unwrap();
        }
    }
}

fn parse_line<T: str::FromStr>() -> T {
    read_line().parse().ok().unwrap()
}

fn parse_word<T: str::FromStr>() -> T {
    read_word().parse().ok().unwrap()
}

fn parse_vec<T: str::FromStr>() -> Vec<T> {
    read_line()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

fn flush() {
    io::stdout().flush();
}

fn next_prime(x: i32) -> i32 {
    for i in (x + 1).. {
        if is_prime(i) {
            return i;
        }
    }

    panic!("attempt to add with overflow");
}

fn is_prime(x: i32) -> bool {
    let ceil = f64::from(x).sqrt().ceil() as i32;
    x == 2 || (2..(ceil + 1)).all(|i| x % i != 0)
}

fn bit_high(bits: u64, pos: u64) -> bool {
    bits & (1 << pos) != 0
}


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

int main(){
    int n; cin >> n;
    int a[n];

    for (int i=0;i<n;i++){
        cin >> a[i];
    }

    sort(a, a+n);
    cout << a[n-1] - a[0] << endl;
	return 0;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-

"""
・幅優先
"""

import sys, re
from collections import deque, defaultdict, Counter
from math import sqrt, hypot, factorial, pi, sin, cos, radians
if sys.version_info.minor >= 5: from math import gcd
else: from fractions import gcd 
from heapq import heappop, heappush, heapify, heappushpop
from bisect import bisect_left, bisect_right
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from functools import reduce, partial
from fractions import Fraction
from string import ascii_lowercase, ascii_uppercase, digits

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def round(x): return int((x*2+1) // 2)
def fermat(x, y, MOD): return x * pow(y, MOD-2, MOD) % MOD
def lcm(x, y): return (x * y) // gcd(x, y)
def lcm_list(nums): return reduce(lcm, nums, 1)
def gcd_list(nums): return reduce(gcd, nums, nums[0])
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

H, W = MAP()

# 右左上下
directions = [(0,1),(0,-1),(1,0),(-1,0)]
# 四方に一回り大きいグリッドを作る
grid = [['*'] * (W+2) for i in range(H+2)]
for i in range(1,H+1):
    row = list(input())
    for j in range(1, W+1):
        grid[i][j] = row[j-1]

visited = list2d(H+2, W+2, False)

def bfs(start):
    que = deque()
    # スタート位置
    que.append(start)
    # 白マス通過カウント
    w_cnt = 0
    # 黒マス通過カウント
    b_cnt = 0
    while len(que):
        cur = que.popleft()
        # 見終わった場所はもうやらない
        if visited[cur[0]][cur[1]]:
            continue
        # 訪問済にする
        visited[cur[0]][cur[1]] = True
        # 今のマスのカウント追加
        if grid[cur[0]][cur[1]] == '.':
            w_cnt += 1
        elif grid[cur[0]][cur[1]] == '#':
            b_cnt += 1
        # 4方向見る
        for direction in directions:
            # 上下左右に1つずつ動かした座標
            nxt = list(map(lambda x,y: x+y, cur, direction))
            # 壁か今のマスと同じ色はスキップ
            if grid[nxt[0]][nxt[1]] == '*' or grid[cur[0]][cur[1]] == grid[nxt[0]][nxt[1]]:
                continue
            # キューに次のマスを足す
            que.append(nxt)
    # 今回調べた範囲で得られるカウントを返却
    return w_cnt * b_cnt

cnt = 0
for i in range(H+2):
    for j in range(W+2):
        if grid[i][j] == '#' and not visited[i][j]:
            cnt += bfs((i, j))
print(cnt)


Measured memory_bytes: 8036
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
// const int INF = (1 << 30) - 1;
// const ll LL_INF = (1LL << 62) - 1;
// const ll MOD = 1e9 + 7;

int A, P;

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

  int ans = ((3 * A) + P) / 2;

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

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <math.h>
#include <algorithm>
#include <functional>
#include<iostream>
#include <string>
using namespace std;
typedef long long ll;
#define pb pushback
#define fr(i,n) for(int i=0;i<n;i++)
#define fro(i,j,n) for(int i=j;i<n;i++)
#define ifr(i,n) for(int i=n-1;i>=0;i--)


int main() {
    int x;
    int ans=0;
	cin >> x;
    if(x>=9){
      ans+=9;
      if(x>=999){
        ans+=900;
        if(x>=99999){
         ans+=90000;
        }else if(x>9999)ans+=x-9999;
      }else if(x>99)ans+=x-99;
    }else ans+=x;
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cmath>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <algorithm>

#ifdef _DEBUG
#define DMP(x) cerr << #x << ": " << x << "\n"
#else
#define DMP(x) ((void)0)
#endif

const int MOD = 1000000007, INF = 1111111111; 
using namespace std;
using lint = long long;

int main() {

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	string s1, s2, s3;
	cin >> s1 >> s2 >> s3;

	cout << s1[0] << s2[1] << s3[2] << "\n";

	return 0;
}

Measured memory_bytes: 764
#include <bits/stdc++.h>
#include <numeric>
using namespace std;
#define ll long long
#define mod 100000007
#define rep(i, n) for (int i = 0; i < n; ++i)
using Graph = vector<vector<int>>;
#define grepq  priority_queue<double, std::vector<double>, std::greater<double>>

int lcm(ll a, ll b)
{
    return a * b / __gcd(a, b);
}

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




int main(){
    string S;
    cin >> S;
    int N = S.size();
    sort(S.begin(), S.end());
    char hav = S[0];
    int count = 0;
    if(N%2 == 1){
        cout << "No" << endl;
        return 0;
    }
        for (int i = 0; i < N; i++)
        {
            if(S[i] != S[i+1]){
                cout << "No" << endl;
                return 0;
            }
            i++;
        }
        cout << "Yes" << endl;

}


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

#define FOR(i,a,b) for(int i=a;i<b;i++)
#define REP(i,b) FOR(i,0,b)
#define MP make_pair
#define PB push_back
#define REACH cerr<<"reached line "<<__LINE__<<endl
#define DBG(x) cerr<<"line "<<__LINE__<<" "<<#x<<":"<<x<<endl

using uint=unsigned int;
using ll=long long;
using pii=pair<int,int>;
using vi=vector<int>;
using ld=long double;

template<class T,class U>
ostream& operator<<(ostream& os,const pair<T,U>& p){
	os<<"("<<p.first<<","<<p.second<<")";
	return os;
}

template<class T>
ostream& operator <<(ostream& os,const vector<T>& v){
	os<<"[";
	REP(i,(int)v.size()){
		if(i)os<<",";
		os<<v[i];
	}
	os<<"]";
	return os;
}

int read(){
	int i;
	scanf("%d",&i);
	return i;
}

ll readLL(){
	ll i;
	scanf("%lld",&i);
	return i;
}

string readString(){
	static char buf[3341919];
	scanf("%s",buf);
	return string(buf);
}

char* readCharArray(){
	static char buf[3341919];
	static int bufUsed=0;
	char* ret=buf+bufUsed;
	scanf("%s",ret);
	bufUsed+=strlen(ret)+1;
	return ret;
}

template<class T,class U>
void chmax(T& a,U b){
	if(a<b)
		a=b;
}

template<class T,class U>
void chmin(T& a,U b){
	if(a>b)
		a=b;
}

template<class T>
T Sq(const T& t){
	return t*t;
}

const int Nmax=114514;
int w[Nmax];
vi tree[Nmax];

struct Res{
	bool imp,any;
	int s,t;
} z[Nmax];
Res dfs(int v,int p){
	Res r=Res{false,true,-1,-1};
	if(w[v]!=-1){
		r.any=false;
		r.s=r.t=w[v];
	}
	for(auto c:tree[v])if(c!=p){
		Res g=dfs(c,v);
		if(g.imp)
			return Res{true};
		if(!g.any){
			g.s--;
			g.t++;
			if(r.any){
				r.any=false;
				r.s=g.s;
				r.t=g.t;
			}else{
				if((r.s&1)!=(g.s&1))
					return Res{true};
				if((r.t&1)!=(g.t&1))
					return Res{true};
				chmax(r.s,g.s);
				chmin(r.t,g.t);
				if(r.t<r.s)
					return Res{true};
			}
		}
	}
	return z[v]=r;
}

int ans[Nmax];
void dfs1(int v,int p,Res r){
	if(!z[v].any){
		chmax(r.s,z[v].s);
		chmin(r.t,z[v].t);
	}
	ans[v]=r.s;
	r.s--;
	r.t=r.s+2;
	for(auto c:tree[v])if(c!=p)
		dfs1(c,v,r);
}

int main(){
	int n=read();
	REP(_,n-1){
		int a=read()-1,b=read()-1;
		tree[a].PB(b);
		tree[b].PB(a);
	}
	int k=read();
	fill(w,w+n,-1);
	REP(i,k){
		int v=read()-1,p=read();
		w[v]=p;
	}
	Res r=dfs(0,-1);
	if(r.imp)
		cout<<"No"<<endl;
	else{
		cout<<"Yes"<<endl;
		dfs1(0,-1,z[0]);
		REP(i,n)
			printf("%d\n",ans[i]);
	}
}


Measured memory_bytes: 21248
import sys
input = sys.stdin.readline

N,K=[int(val) for val in input().split()]

list_x=list()
list_y=list()
list_z=list()

ans=float('inf')

for i in range(N):
  x,y=(int(val) for val in input().split())
  list_x.append(x)
  list_y.append(y)
  list_z.append((x,y))
#  heapq.heappush(list_x, x)
#  heapq.heappush(list_y, y)
list_x.sort()
list_y.sort()

for i in list_y:
  for j in list_y:
    if i<=j:
      break
    else:
      for k in list_x:
        for l in list_x:
          if k<=l:
            break
          else:
            cnt=0
            for m in range(len(list_z)):
              if l<=list_z[m][0]<=k and j<=list_z[m][1]<=i:
                cnt+=1
              if K <= cnt:
                tmp=(i-j)*(k-l)
                if tmp < ans:
                  ans=tmp
                break

print(ans)




Measured memory_bytes: 49500
#include<iostream>
using namespace std;
int main(){

int a[1000];
int n;


cin>>n;
int i;
for(i=0;i<=n-1;i=i+1)
{cin>>a[i];}

int j;
for(j=n-1;j>-1;j=j-1)
{cout<<a[j];
if(j>0){cout<<" ";}
if(j==0){cout<<endl;}
}
}


Measured memory_bytes: 3088
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>

using namespace std;

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

	vector<string> sv;

	for(int i=1;i<=s.size();i++)
	{
		for(int j=1;j<=k;j++)
		{
			sv.push_back(s.substr(i-1,j));
		}
	}

	sort(sv.begin(),sv.end());
	sv.erase(unique(sv.begin(),sv.end()),sv.end());

	cout <<  sv[k-1] << endl;
}


Measured memory_bytes: 1660
import java.util.*;
public class Main{
   public static void main(String[] args) {
     Scanner sc = new Scanner(System.in);
     int  N = sc.nextInt();
     int L = sc.nextInt();
     int ans=0;
     if(L*(L+N-1)<0){
       for(int i=1;i<N+1;i++){
         ans+=L+i-1;
       }
     }else if(L<0){
       for(int i=1;i<N;i++){
         ans+=L+i-1;
       }
     }else{
       for(int i=2;i<N+1;i++){
         ans+=L+i-1;
       }
     }
     System.out.println(ans);
   }
}


Measured memory_bytes: 22868
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string s,t;
  cin>>s>>t;
  sort(s.begin(),s.end());
  sort(t.begin(),t.end());
  reverse(t.begin(),t.end());
  if(s<t) cout<<"Yes"<<endl; else cout<<"No"<<endl;
}

Measured memory_bytes: 256
parseInt(x)=parse(Int,x)
parseMap(x::Array{SubString{String},1})=map(parseInt,x)
function bsearch(a::Array{Int,1},x::Int);l,r=1,length(a);while l<=r;m=l+div(r-l,2);if a[m]<x;l=m+1;else;r=m-1;end;end;return(l-1);end

function main()
	n = readline() |> parseInt
	a = readline() |> split |> parseMap
	b = Array{Int}(n)
	k = 0
	for i in 1:n
		if a[i] < 0
			k += 1
		end
		b[i] = abs(a[i])
	end
	println(k%2==0?sum(b):sum(b)-2*minimum(b))
end
main()


Measured memory_bytes: 128976
s = input()
cnt = {'N':0,'S':0,'E':0,'W':0}
ok = True
for x in s:
    cnt[x] +=1
if ((cnt['N'] >0)^(cnt['S']>0)) == 1:ok = False
if ((cnt['E'] >0)^(cnt['W']>0)) == 1:ok = False
if ok:print('Yes')
else:print('No')

    


Measured memory_bytes: 3188
#include<bits/stdc++.h>
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3f
#define MOD 1000000007
#define EPS (1e-10)
#define rep(i,n)for(int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
typedef pair<int, int>P;

ll san(ll h, ll w) {
	ll a = h / 3, b = h / 3 + (h % 3 > 1), c = h / 3 + (h % 3 > 0);
	return c*w - a*w;
}
ll ni(ll h, ll w) {
	ll a = h / 3, b = h - h / 3;
	ll c = h / 3 + 1; ll d = h - c;
	ll e = max({ a*w,b*(w / 2),b*(w - w / 2) }) - min({ a*w,b*(w / 2),b*(w - w / 2) });
	ll f = max({ c*w,d*(w / 2),d*(w - w / 2) }) - min({ c*w,d*(w / 2),d*(w - w / 2) });
	return min(e, f);
}
signed main() {
	ll h, w; scanf("%lld%lld", &h, &w);
	ll Min = san(h, w);
	Min = min(Min, san(w, h));
	Min = min(Min, ni(h, w));
	Min = min(Min, ni(w, h));
	printf("%lld\n", Min);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
using ll = int64_t;
using ld = long double;
using ull = uint64_t;
using namespace std;
using namespace __gnu_pbds;
typedef vector <int> vi;
typedef pair <int, int> ii;

const int INF = (int)1e9;

#define maxn 100010



int main() {
#ifdef BZ
    freopen("in.txt", "r", stdin); freopen("out.txt", "w", stdout);
#endif
    ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); cout.setf(ios::fixed); cout.precision(6);

    string s;
    ll k;
    cin >> s >> k;

    int l = s.size() - 1;
    for(int i = 0; i < s.size(); i++) {
        if(s[i] != '1') {
            l = i;
            break;
        }
    }

    if(k <= l) {
        cout << s[k - 1] << "\n";
    }  else {
        cout << s[l] << "\n";
    }

}

Measured memory_bytes: 256
package main

import (
	"fmt"
)

func main() {
	var a, b, c int
	fmt.Scan(&a, &b, &c)

	if (a == b && a != c) ||
		(b == c && a != b) ||
		(c == a && a != b) {
		fmt.Println("Yes")
		return
	}

	fmt.Println("No")
}


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

#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 

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

int getRand(int l, int r)
{
    uniform_int_distribution<int> uid(l, r);
    return uid(rng);
}
  
#define int long long 
#define pb push_back
#define S second
#define F first
#define f(i,n) for(int i=0;i<n;i++)
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define vi vector<int>
#define pii pair<int,int>
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 
#define precise(x) fixed << setprecision(x) 

const int MOD = 1e9+7;

int mod_pow(int a,int b,int M = MOD)
{
    int res = 1;
    
    while(b)
    {
        if(b&1) res=(res*a)%M;
        a=(a*a)%M;
        b>>=1;
    }
    
    return res;
}


void solve()
{
   int x;
    cin >> x;
    cout << 1 - x;
    
    
}

signed main()
{
    fast;
    
    int t = 1;
    
//    cin >> t;
    
    while(t--)
        
    solve();
}

Measured memory_bytes: 3644
#include <iostream>
using namespace std;
int main()
{
    int a, b, c;
    cin >> a >> b >> c;
    if (a < b)
    {
        if (b < c)
        {
            cout << "Yes" << endl;
        }
        else
        {
            cout << "No" << endl;
        }
    }
    else
    {
        cout << "No" << endl;
    }
}


Measured memory_bytes: 3120
#include <iostream>
#include <ios> 
#include <vector>
#include <string>
#include <algorithm>
#include <functional>
#include <queue>
#include <set>
#include <cmath>
#include <map>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)

using namespace std;
typedef long long int lli;
const int MAX=1e5+3;

int main(){
	lli N;
	cin>>N;
	lli a[MAX],b[MAX],c[MAX];
	rep1(i,N){cin>>a[i]>>b[i]>>c[i];}
	
	lli ah[MAX],bh[MAX],ch[MAX];
	ah[0]=bh[0]=ch[0]=0;
	rep1(i,N){
		ah[i]=max(bh[i-1],ch[i-1])+a[i];
		bh[i]=max(ch[i-1],ah[i-1])+b[i];
		ch[i]=max(ah[i-1],bh[i-1])+c[i];
	}
	lli hap1=max(ah[N],bh[N]);
    lli hap2=max(hap1,ch[N]);
	cout<<hap2;
}

Measured memory_bytes: 4992
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//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; }

/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
*/

int main(){
    string s; cin >> s;
    int g=0, p=0;
    for(int i=0; i<s.size(); i++){
        if(s[i] == 'g') g++;
        if(s[i] == 'p') p++;
    }

    cout << (g-p)/2 << endl;
}

Measured memory_bytes: 512
inf = float('inf')
V,E,P = map(int,input().split())
edge = []
for i in range(E):
    A,B,C = map(int,input().split())
    c = P-C
    if A == B:
        c *= 10**6
    edge.append([A-1,B-1,c])

d = [inf]*V
d[0] = 0
for i in range(V):
    update = False
    for j in range(E):
        From,To,cost = edge[j]
        if d[From] != inf and d[To]>d[From]+cost:
            d[To]=d[From]+cost
            update = True
    if not update:
        break

ans = d[V-1]

for i in range(V):
    update = False
    for j in range(E):
        From,To,cost = edge[j]
        if d[From] != inf and d[To]>d[From]+cost:
            d[To]=d[From]+cost
            update = True
    if not update:
        break
loop = ans != d[V-1]

if loop:
    print(-1)

else:
    ans = -d[-1]
    print(max(0,ans))

Measured memory_bytes: 55160
#include<bits/stdc++.h>
#define ll long long
using namespace std;
signed main(){
  ll d,n,s=1;
  cin>>d>>n;
  for(ll i=0;i<d;i++){
    s *= 100;
  }
    if(n <= 99){
      cout<<s*n<<"\n";
    }else{
      cout<<s*101<<"\n";
    }
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int lli;
typedef vector <int> vi;
typedef vector <vi> vvi;
typedef pair <int,int> pr;
#define fr(i, n) for(int i = 0; i < n; i++)
#define sz(a) int((a).size())
#define pb push_back
#define all(c)(c).begin(), (c).end()
#define tr(c, i) for (typeof ((c).begin() i = (c).begin(); i != (c).end(); i++)
#define present(c, x)((c).find(x) != (c).end())
#define cpresent(c, x)(find(all(c), x) != (c).end())
// for mod power a^b%m use power<lli> (a,b,m)
template < class mytype >
mytype power(mytype a, mytype b, mytype m){if (b == 1) return a % m;if (b == 0) return 1;
mytype root = power < lli > (a, b / 2, m);mytype ans = (root * root) % m;if (b % 2) ans = (ans * a) % m;
return ans;
}
// for gcd use gcd<int> (a,b)
template < class type >type gcd(type a, type b){if (a == 0) return b;else return gcd(b % a, a);}
template < class type >type mod_inv(type a, type p) {return power(a, p - 2, p);}
const lli MOD = 1e9 + 7;
int main()
{
   int n;
   cin >> n;
   vector<double> p(n);
   for(int i = 0 ; i < n ; i++) cin >> p[i];
   vector<double> dp(n+1 , 0);
   dp[0] = 1 - p[0];
   dp[1] = p[0];double prev = 0, prevsum = 0, ans = 0.0;
   for(int i = 1 ; i < n ; i++){
     prev = 0;
    for(int j = 0 ; j <= n ; j++ ){
        prevsum = prev*p[i];
        prev = dp[j];
        dp[j] = prevsum + dp[j]*(1-p[i]);
    }
   }

   for(int i = n ; i > (n/2) ; i--) ans += dp[i];
   cout << setprecision(10) << ans << endl;

   return 0;
}











Measured memory_bytes: 384
#include <iostream>
using namespace std;
int main(){
	int n,s[100];
	cin>>n;
	for( int i=0 ; i<n ; i++ ){
		cin >> s[i] ;
	}

	int flag=1;
	int counter=0;
	while(flag){
		flag=0;
		for( int i=n-1 ; i>0 ; i-- ){
			if( s[i] < s[i-1] ){
				swap(s[i],s[i-1]);
				flag=1;
				counter++;
			}
		}
	}
	for( int i=0 ; i<n ; i++ ){
		cout << s[i];
		if( i!=n-1 )
			cout <<" ";
	}
	cout << endl;
	cout << counter << endl;
	return 0;
}

Measured memory_bytes: 3104
import numpy as np

n, k = map(int, input().split())
h = np.array(list(map(int, input().split())))

dp = np.zeros(n, dtype=int)

for i in range(1, n):
    s = max(i - k, 0)
    dp[i] = np.min(dp[s:i] + np.abs(h[s:i] - h[i]))

print(dp[-1])

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

int main()
{
    string str;

    cin >> str;

    str += 'a';

    int a = 0, b = 0;
    for( int i = 1; i < str.size(); i++ )
    {
        if( str[i-1] != str[i] && str[i-1] == 'o' )
            a++;
        if( str[i-1] != str[i] && str[i-1] == 'x' )
            b++;
    }

    if( a >= b )
        cout << 'o' << endl;
    else
        cout << 'x' << endl;

    return 0;
}


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

typedef long long ll;

const ll INF = 1e18;
const int Nmax = 3e3 + 10;
ll dp[Nmax][Nmax][4], v[Nmax][Nmax];

void self_max(ll &a, ll b) {
	a = max(a, b);
}

int main() {
	int R, C, K;
	cin >> R >> C >> K;
	for (int i = 0; i < K; ++i) {
		int r, c, val;
		cin >> r >> c >> val;
		--r, --c;
		v[r][c] = val;
	}
	for (int i = 0; i < Nmax; ++i)
		for (int j = 0; j < Nmax; ++j)
			for (int k = 0; k <= 3; ++k)
				dp[i][j][k] = -INF;
	dp[0][0][0] = 0;
	for (int i = 0; i < R; ++i) {
		for (int j = 0; j < C; ++j) {
			for (int k = 2; k >= 0; --k)
				if (dp[i][j][k] >= 0)
					self_max(dp[i][j][k + 1], dp[i][j][k] + v[i][j]);
			for (int k = 0; k <= 3; ++k) {
				if (dp[i][j][k] >= 0) {
					if (i + 1 < R)
						self_max(dp[i + 1][j][0], dp[i][j][k]);
					if (j + 1 < C)
						self_max(dp[i][j + 1][k], dp[i][j][k]);
				}
			}
		}
	}
	ll res = -INF;
	for (int k = 0; k <= 3; ++k)
		self_max(res, dp[R - 1][C - 1][k]);
	cout << res << '\n';
}


Measured memory_bytes: 357228
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int N = 2e5 + 10;
const int INF = 0x3f3f3f3f;
ll n;
int main() {
	cin >> n;
	ll a = n / 500; ll b = n % 500;
	ll c = b / 5;
	printf("%lld\n", a * 1000 + c * 5);
	return 0;
}

Measured memory_bytes: 256
from collections import deque

INF = 10101010

def main():
    h,w = map(int,input().split())
    s = []
    for i in range(h):
        s.append(input())



    d = [[INF for j in range(w)] for i in range(h)]
    d[0][0] = 0
    que = deque()
    que.append((0,0))
    while len(que):
        y,x = que.pop()
        for dx,dy in [(1,0),(-1,0),(0,1),(0,-1)]:
            nx,ny = x+dx, y+dy
            if 0 <= nx < w and 0 <= ny < h:
                if s[ny][nx] != '#' and d[ny][nx]>d[y][x]+1:
                    d[ny][nx] = d[y][x]+1
                    que.append((ny,nx))

    if d[h-1][w-1] == INF:
        return -1

    ans = -(d[h-1][w-1]+1)
    for i in range(h):
        for j in range(w):
            if s[i][j] == '.':
                ans += 1
    return ans

if __name__ == '__main__':
    print(main())


Measured memory_bytes: 3444
#include <algorithm>
#include <cassert>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>

#include <limits.h>

using namespace std;

typedef long long ll;

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

vector<ll> calc_divs(ll M) {
    vector<ll> divs;
    divs.push_back(1LL);
    divs.push_back(M);
    for (int i = 2; i * i <= M; i++) {
        if (M % i == 0) {
            divs.push_back(ll(i));
            if (i * i != M) divs.push_back(ll(M / i));
        }
    }
    sort(divs.begin(), divs.end());
    return divs;
}

int main(void) {
    ll N, M;
    cin >> N >> M;

    vector<ll> divs = calc_divs(M);
    reverse(divs.begin(), divs.end());
    int ans = -1;
    for (int i = 0; i < (int) divs.size(); i++) {
        // printf("divs: %lld\n", divs[i]);
        if (divs[i] * N <= M) {
            ans = divs[i];
            break;
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256