akhauriyash/Code-Regression huggingface dataset:
N = int(input())
lsa = list(map(int,input().split()))
ans = 'Yes'
i4 = 0
i2 = 0
i1 = 0
for i in range(N):
    if lsa[i] % 4 == 0:
        i4 += 1
    elif lsa[i] % 2 == 0:
        i2 += 1
    else:
        i1 += 1
if i4+1 < i1:
    ans = 'No'
elif i2%2 == 1 and i4+1 == i1:
    ans = 'No'
print(ans)

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

using namespace std;
typedef long long ll;


int main() {
  ios_base::sync_with_stdio(false); cin.tie(NULL); 
  int a, b, c, d, e, f;
  cin >> a >> b >> c >> d >> e >> f;
  int concn = 0, concd = 100*a, wat, sug;
  for (int i = 0; 100*i*a <= f; i++) {
    for (int j = 0; 100*i*a+100*j*b <= f; j++) {
      wat = 100*i*a+100*j*b;
      for (int k = 0; wat + k*c <= f; k++)
        for (int l = 0; wat + l*d + k*c <= f; l++) {
          sug = l*d+k*c;
          if (e*wat/100 < sug) continue;
          if (concn*wat < concd*sug) {
            concn = sug;
            concd = wat;
          }
        }
    }
  }
  cout << concn + concd << " " << concn << endl;
  return 0;
}



Measured memory_bytes: 256
import bisect
import cmath
import heapq
import itertools
import math
import operator
import os
import random
import re
import string
import sys
from collections import Counter, defaultdict, deque
from copy import deepcopy
from decimal import Decimal
from functools import lru_cache, reduce
from math import gcd
from operator import add, itemgetter, mul, xor

import numpy as np

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(10 ** 9)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7
# MOD = 998244353


N = int(sys.stdin.buffer.readline())
S = [sys.stdin.buffer.readline().decode().rstrip() for _ in range(N)]

ans = set(S)
print(len(ans))


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

int main(){
    int N,M;
    cin >> N;
    vector<string> blues(N);
    for(int i=0;i<N;i++){
        cin >> blues.at(i);
    }
    cin >> M;
    vector<string> reds(M);
    for(int i=0;i<M;i++){
        cin >> reds.at(i);
    }

    int answer=0;

    for(int i=0;i<N;i++){
        int a=1;
        for(int j=0;j<M;j++){
            if(blues.at(i)==reds.at(j)){
                a--;
            }
        }
        for(int j=0;j<N;j++){
            if(i==j){
                continue;
            }
            else if(blues.at(i)==blues.at(j)){
                a++;
            }
        }
        if(a>answer){
            answer=a;
        }
    }
    cout << endl;
    cout << answer << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;typedef long long l;l a=0;l r[10]={1,11,112,1124,11248,112496,1124992,11249984,112499968,1124999936};string s;int main(){cin>>s;for(int i=0;i<s.size();++i)a+=r[s.size()-i-1]*(1<<i)*(s[i]-'0');cout<<a<<endl;return 0;}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
  int n,m;
  while(cin>>n){
    if(n==0) break;
    char c[n][2],s;
    for(int i=0;i<n;i++) cin >> c[i][0] >> c[i][1];
    cin >> m;
    for(int i=0;i<m;i++){
      cin >> s;
      for(int j=0;j<n;j++){
	if(s==c[j][0]){
	  s = c[j][1];
	  break;
	}
      }
      cout << s;
    }
    cout << endl;
  }
  return 0;
}
  

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

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

MOD = 10**9+7

ans = 1

p = [1]*1001
for i in range(2,1001):
    if p[i]:
        v = 0
        nn = n
        while nn:
            v += nn//i
            nn//= i
        #print(i,v)
        ans *= v+1
        ans %= MOD
        p[i::i] = [0]*(1000//i)

print(ans)

    






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

int main() {
  int N;
  cin >> N;
  vector<int> vec1(N);
  
  for (int i=0; i<N; i++){
    cin >> vec1.at(i);
  }
  
  int A=0, B=0, count=0;
  
  for (int i=100; i>0; i--){
    for (int j=0; j<N; j++){
      if (vec1.at(j) == i){
        if (count % 2 == 0){
          A += i;
          count++;
        }
        else{
          B += i;
          count++;
        }
      }
    }
  }
  
  cout << A-B << endl;
}

Measured memory_bytes: 256
N=int(input())
A=list(map(int,input().split()))
bucket=[0]*(max(A)+1)
answer=0
for number in A:
    bucket[number]+=1
if len(bucket)<3:
    answer=sum(bucket)
for i in range(1,max(A)):
    candidate=bucket[i-1]+bucket[i]+bucket[i+1]
    if candidate>answer:
        answer=candidate
print(answer)

Measured memory_bytes: 14092
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <numeric>
#include <queue>
#include <stack>
#include <map> 
#include <set>
#include <string>
#include <functional>
#include <list>
#include <random>
#include <time.h>
#include <iomanip>
#include <assert.h>
#include <numeric>
#include <new>
#define BIT(nr) (1ULL << (nr))
#define int long long
//#define ll long long
#define double long double
#define mod 1000000007
#define MAXN (int)1e+5 * 2+1
#define LL_MAX 9223372036854775807	//ない環境用
#define LL_HALFMAX 9223372036854775807 / 2	//ない環境用
#define MIN -(9223372036854775807 / 2)
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
#define REPS(i,x) for(int i=1;i<=(int)(x);i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RREPS(i,x) for(int i=((int)(x));i>0;i--)
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define mp make_pair
template<typename T1, typename T2> inline void chmin(T1 & a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1& a, T2 b) { if (a < b) a = b; }


using namespace std;

signed main() {
    string S, S0;
    cin >> S;
    S0 = S;
    int vertexNum = S0.length();
    S = "*" + S;
    if (S[1] == '0') {
        cout << -1 << "\n";
        return 0;
    }
    if (S[vertexNum] == '1') {
        cout << -1 << "\n";
        return 0;
    }
    REPS(i, vertexNum - 1) {
        if (S[i] != S[vertexNum - i]) {
            cout << -1 << "\n";
            return 0;
        }
    }
    int hub = 0;
    int nowNode = 2;
    REP(i, 0, vertexNum-1) {

        cout << hub  + 1<< " " << i + 2 << "\n";

        //サイズiの部分木が作れていいなら直線的に伸ばしてハブを移動する
        if (S0[i] == '1') {
            hub = i + 1;
        }
    }


    return 0;
}


Measured memory_bytes: 1664
#define _USE_MATH_DEFINES 
#include<iomanip> 
#include<cmath>  
#include<iostream>
#include<fstream>
#include<vector>
#include<algorithm>
#include<numeric>
#include<bitset>
#include<map>
#include<unordered_map>
#include<set>
#include<unordered_set>
#include<queue>
#include<deque>
#include<stack>
using namespace std;
typedef long long ll;
#define repi(i,a,b) for(ll i = (ll)(a) ; i < (ll)(b) ; i++)
#define repd(i,a,b) for(ll i = (ll)(a) ; i > (ll)(b) ; i--)
#define rd(x) cin >> x
#define wr(x)  cout << x
#define wrln(x) cout << x << endl
const ll MAX_10p5 = 100010;
const ll MAX_10p9 = 1000000010;
const ll MAX_10p18 = 1000000000000000010;
const ll MOD = 1000000007;
const ll m4x[4] = { 1,0,-1,0 };
const ll m4y[4] = { 0,1,0,-1 };
const ll m8x[8] = { 1,1,0,-1,-1,-1,0,1 };
const ll m8y[8] = { 0,1,1,1,0,-1,-1,-1 };
const ll m9x[9] = { 1,1,0,-1,-1,-1,0,1,0 };
const ll m9y[9] = { 0,1,1,1,0,-1,-1,-1,0 };

struct edge {
	ll from, to, cost;
	bool operator<(const edge& right) const {
		return cost < right.cost;
	}
};
struct point {
	ll x, y;
	bool operator<(const point& right) const {
		return x == right.x ? y < right.y : x < right.x;
	}
};

///////////////////////////////////////////////////////////////////////////////////////

struct el {
	ll i, j;
	bool operator<(const el& right) const {
		return i == right.i ? j < right.j : i < right.i;
	}
};

ll N, W, ans;
ll w[110], v[110];

map<el, ll> dp;


ll solv(ll i, ll j) {
	ll ret;
	el e;
	e.i = i, e.j = j;
	if (i == N) ret = 0;
	else if (dp.find(e) != dp.end()) ret = dp[e];
	else if (j < w[i]) {
		ret = solv(i + 1, j);
	}
	else {
		ret = max(solv(i + 1, j), solv(i + 1, j - w[i]) + v[i]);
	}
	if (dp.find(e) == dp.end()) dp[e] = ret;
	return ret;
}

int main() {
	cin >> N >> W;
	repi(i, 0, N) {
		cin >> w[i] >> v[i];
	}
	ans = solv(0,W);
	wrln(ans);
	return 0;
}


Measured memory_bytes: 6400
conv1 = {' ':"101","'":"000000",",":"000011","-":"10010001",".":"010001","?":"000001","A":"100101","B":"10011010","C":"0101","D":"0001","E":"110","F":"01001","G":"10011011","H":"010000","I":"0111","J":"10011000","K":"0110","L":"00100","M":"10011001","N":"10011110","O":"00101","P":"111","Q":"10011111","R":"1000","S":"00110","T":"00111","U":"10011100","V":"10011101","W":"000010","X":"10010010","Y":"10010011","Z":"10010000"}
conv2 = {"00000":"A","00001":"B","00010":"C","00011":"D","00100":"E","00101":"F","00110":"G","00111":"H","01000":"I","01001":"J","01010":"K","01011":"L","01100":"M","01101":"N","01110":"O","01111":"P","10000":"Q","10001":"R","10010":"S","10011":"T","10100":"U","10101":"V","10110":"W","10111":"X","11000":"Y","11001":"Z","11010":" ","11011":".","11100":",","11101":"-","11110":"'","11111":"?"}
while 1:
    try:
        s = raw_input()
        s1 = ""; s2 = "";
        for c in s:
            s1 += conv1[c]
        if len(s1)%5>0 :s1 += "0"*(5-(len(s1)%5))
        for i in xrange(0,len(s1),5):
            s2 += conv2[s1[i:i+5]]
        print s2
    except EOFError:
        break

Measured memory_bytes: 4324
#encoding:utf-8 No.0502 2014.11.13
class Dice
  def initialize
    @top = 1
    @under = 6
    @north = 5
    @south = 2
    @east = 3
    @west =4
  end

  attr_accessor :top

  def north
    @top,@north,@under,@south = @south,@top,@north,@under
  end

  def south
    @top,@north,@under,@south = @north,@under,@south,@top
  end

  def east
    @top,@east,@under,@west = @west,@top,@east,@under
  end

  def west
    @top,@east,@under,@west = @east,@under,@west,@top
  end

  def right
    @north,@east,@south,@west = @west,@north,@east,@south
  end

  def left
    @north,@east,@south,@west = @east,@south,@west,@north
  end
end

while true
  dice = Dice.new
  sum = 1
  n = gets.chomp.to_i

  if n == 0
    break
  end

  n.times do
    case gets.chomp
    when "North"
      dice.north
      sum += dice.top
    when "South"
      dice.south
      sum += dice.top
    when "East"
      dice.east
      sum += dice.top
    when "West"
      dice.west
      sum += dice.top
    when "Right"
      dice.right
      sum += dice.top
    when "Left"
      dice.left
      sum += dice.top
    end
  end

  puts sum
end

Measured memory_bytes: 6112
#include<bits/stdc++.h>
#define REP(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
const ll MOD = 1000000007;

int main() {
  string s, sf, sb;
  int q, t, f;
  char c;

  bool state = true;
  cin >> s >> q;

  REP(i, q) {
    scanf("%d", &t);
    if (t == 1) {
      state = !state;
    } else {
      scanf("%d %c", &f, &c);
      if (f == 1) {
        if (state) {
          sf += c;
        } else {
          sb += c;
        }
      } else {
        if (state) {
          sb += c;
        } else {
          sf += c;
        }
      }
    }
  }

  reverse(sf.begin(), sf.end());
  sf += s;
  sf += sb;
  if (!state) {
    reverse(sf.begin(), sf.end());
  }
  cout << sf << endl;
  return 0;
}

Measured memory_bytes: 1348
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)

using namespace std;
typedef long long unsigned int ll;


int main() {
	string week[] = { "SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT" };
	string s;
	cin >> s;

	REP(i, 7) {
		if (s == week[i])cout << (7 - i);
	}
}

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

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
using namespace std;
using namespace __gnu_pbds;
 
 
#define all(x) x.begin(), x.end()
#define allr(x) x.rbegin(), x.rend()
#define speedhack() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define form(i, n) for (size_t i = 0; i < size_t(n); ++i)
#define forn(i, n) for (size_t i = 1; i <= size_t(n); ++i)
template<class T> using ordered_set=tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
long long mod(long long a, long long b) { return (a%b+b)%b; }
long long gcd(long long x, long long y) { return __gcd(x, y); }
long long lcm(long long x, long long y) { return x * 1ll * y / gcd(x, y); }
 
 
const long long MAXN = 1e9 + 9;
const long long SIZE = 3e5 + 5;
const long long MOD  = 1e9 + 7;

int res;

int main() { speedhack()

	string s, t;

	cin >> s;
	cin >> t;

	for (int i = 0; i < (int)s.size(); i++) 
		if (s[i] != t[i])
			++res;

	cout << res;
	

	return 0;
}

Measured memory_bytes: 3824
#include<iostream>

int a[7], b[7], m, dp[7001][7];

//次i
int rec(int n, int i){
	if(n >= 0 && i < m && dp[n][i] != -1){
		return dp[n][i];
	}

	if(n == 0){
		return 1;
	}

	if(n < 0 || i >= m){
		return 0;
	}

	int res = 0;
	for(int j=0;j<=b[i];j++){
		res += rec(n-a[i]*j, i+1);
	}

	return dp[n][i] = res;
}

int main(){
	while(std::cin >> m, m){
		for(int i=0;i<7001;i++){
			for(int j=0;j<7;j++){
				dp[i][j] = -1;
			}
		}
		for(int i=0;i<m;i++){
			std::cin >> a[i] >> b[i];
		}
		int g, n;
		std::cin >> g;
		for(;g--;){
			std::cin >> n;
			std::cout << rec(n, 0) << std::endl;;
		}
	}
}

Measured memory_bytes: 1352
#include<iostream>
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <iomanip>//setprecision
#include<math.h>
#include <functional>
#include<climits>
using namespace std;
template <typename T> bool chmax(T &u, const T z) { if (u < z) {u = z; return true;} else return false; }
template <typename T> bool chmin(T &u, const T z) { if (u > z) {u = z; return true;} else return false; }
#define ll  long long 
const ll INF=1LL<<60;
#define rep(i, n)        for(ll i=0; i<(ll)(n); ++i)
vector<pair<ll,ll>>s[100001];
ll dis[100001];
int main(){
    ll a,b,c,d;cin>>a>>b>>c;
    if(b*c>=a)cout<<"Yes";
    else cout<<"No";
}

Measured memory_bytes: 5968
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#define MOD 1000000007
typedef long long ll;
using namespace std;

int main(){
  ll L,N;
  cin>>L>>N;
  vector<ll> x(N);
  for(int i=0;i<N;i++) cin>>x[i];

  ll ans=0;
  for(int k=0;k<2;k++){
      vector<ll> rx(N);
      for(int i=0;i<N;i++) rx[i]=L-x[N-i-1];
      vector<ll> sum(N+1,0),rsum(N+1,0);
      for(int i=1;i<=N;i++) sum[i]+=sum[i-1]+x[i-1];
      for(int i=1;i<=N;i++) rsum[i]+=rsum[i-1]+rx[i-1];

      for(int i=0;i<N;i++){
          int l=(N-i+1)/2;
          int r=N-(l+i);

          ll res=2*(sum[i+l]-sum[i]);
          res+=2*rsum[r];

          if(l==r) res-=rx[r-1];
          else res-=x[i+l-1];
          
          ans=max(ans,res);
      }
      swap(x,rx);
  }

  cout<<ans<<endl;

  return 0;
}


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

int main()
{
    int N,K;
    cin >> N >> K;

    ll ans = 1;

    for(ll i = 0; i < N; i++)
    {
        if(i == 0)ans *= K;
        else ans *= K-1;
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<unordered_map>
#include<bitset>
#include<iomanip>
#include<list>
#include<deque>
using namespace std;
//#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define END {}
#endif
typedef long long ll;
#define int ll
#define uset unordered_set
#define umap unordered_map
typedef std::pair<int,int> P;
struct edge{int to,cost;};
const int INF=100000000000000000;
const int INF2=9223372036854775807;
const int MOD=1000000007;
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define min(X,Y) (((int)(X)<(int)(Y))?(X):(Y))
#define max(X,Y) (((int)(X)>(int)(Y))?(X):(Y))
#define MAX(X,Y) (*max_element(X,Y))
#define MIN(X,Y) (*min_element(X,Y))
#define NP(X,Y) next_permutation(X,Y)
#define setp(X,Y) cout<<fixed<<setprecision(Y)<<X;
int ceil2(int a,int b){if(a%b==0){return a/b;}else{return a/b+1;}}
int pow2(int a,int b){int r=1;for(int i=1;i<=b;i++){r*=a;}return r;}
int Log2(int a){int t=0;while(1){if(a==0||a==1){break;}a/=2;t++;}return t;}

signed main(){
	int N,K;
	cin>>N>>K;
	N-=K;
	if(K==1){
		cout<<0<<endl;
	}
	else{
		cout<<N<<endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>

using namespace std;

int main()
{
	int a,b,c;
	cin >> a >> b >> c;

	if(a < b) swap(a,b);
	if(a < c){
		swap(a,c);
		swap(b,c);
	}

	int count = 0;
	if((a-b) % 2 != (a-c) % 2){
		while(!((a-b) % 2 == (a-c) % 2)){
			a += 1;
			b += 1;
			count++;
		}
	}
	
	if((a-b) % 2 == 1 && (a-c) % 2 == 1 ){
		b += 1;
		c += 1;
		count++;
	}

	while(a != b){
		b += 2;
		count++;
	}
	while(a != c){
		c += 2;
		count++;
	}

	cout << count << endl;

	return 0;
}

Measured memory_bytes: 256
///Nahid Hasan Raju
#include <bits/stdc++.h>
#define ll int
#define MS(ARRAY,VALUE) memset(ARRAY,VALUE,sizeof(ARRAY))
#define Fin freopen("input.txt","r",stdin)
using namespace std;

#define P(XX) cout<<XX<<endl
#define P1(XX) cerr<<"db1: "<<XX<<endl
#define P2(XX,YY) cerr<<"db2: "<<XX<<" "<<YY<<endl
#define P3(XX,YY,ZZ) cerr<<"db3: "<<XX<<" "<<YY<<" "<<ZZ<<endl
#define FAST ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define Fout freopen("output.txt","w",stdout)
#define rep(i,a,b) for(i=a;i<=b;i++)
#define EPS 0.00000001
#define INF INT_MAX
#define PI 2*acos(0.0)
#define set(XX,POS) XX|=(1<<POS)
#define reset(XX,POS) XX&=(~(1<<POS))
#define check(XX,POS) (bool)(XX&(1<<POS))
#define toggle(XX,POS) (XX^(1<<POS))
#define SORT(v) sort(v.begin(),v.end())
#define REVERSE(V) reverse(v.begin(),v.end())
#define VALID(X,Y,R,C) X>=0 && X<R && Y>=0 && Y<C
#define SIZE(ARRAY) sizeof(ARRAY)/sizeof(ARRAY[0])
#define RT printf("Run Time : %0.3lf seconds\n", clock()/(CLOCKS_PER_SEC*1.0))
#define pb push_back
#define pll pair<ll,ll>
#define pii pair<int,int>

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
using namespace __gnu_pbds;
typedef tree< pair<int,int> , null_type, less< pair<int,int> >, rb_tree_tag, tree_order_statistics_node_update> odrst;

#define MOD 1000000007ll
#define MX 102  ///200005

ll m,n;
ll w[MX], val[MX];
string s;

int main()
{
    int test=1, tc=0, i, j;
    #ifndef ONLINE_JUDGE
    Fin;
    test=2;
    #endif
    ll k, ans, t;
    ///scanf("%d", &test);
    while(test--)
    {
        cin>>s;
        n=s.size();
        t=k=0;
        for(i=0;i<n;i++){
            if(s[i]=='R'){
                k++;
            }
            else{
               t=max(k,t);
             k=0;
            }
        }
        t=max(k,t);
        P(t);
    }
    return 0;
}

Measured memory_bytes: 3640
#include <iostream>
#include <algorithm>
#include <functional>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <string>
#include <numeric>
#include <cmath>

#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
using P = pair<ll, ll>;

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

const ll MOD = 1000000007;
const int INF = 1<<30;
//const ll INF = (ll)1e18 + 1;

int main(){
  int N; cin >> N;
  vector<int> a(N); rep(i, N) cin >> a[i];

  int ans = 0;
  rep(i, N){
    while (i + 1 < N && a[i] == a[i + 1]) ++i;
    if(i + 1 < N && a[i] > a[i + 1]) while (i + 1 < N && a[i] >= a[i + 1]) ++i;
    else if (i + 1 < N && a[i] < a[i + 1]) while (i + 1 < N && a[i] <= a[i + 1]) ++i;
    ans++;
  }
  cout << ans << endl;
}


Measured memory_bytes: 640
#include"bits/stdc++.h"
using namespace std;
using ll = int64_t;

constexpr ll MOD = (ll)1e9 + 7;

ll MODpow(ll n, ll m) {
    ll result = 1;
    while (m) {
        if (m % 2 == 1) {
            result *= n;
            result %= MOD;
        }

        m /= 2;
        n *= n;
        n %= MOD;
    }

    return result;
}

class Combination {
public:
    Combination(ll max_num, ll mod) {
        fact_.resize(max_num + 1, 1);
        inv_fact_.resize(max_num + 1, 1);
        mod_ = mod;
        for (ll i = 2; i <= max_num; i++) {
            fact_[i] = i * fact_[i - 1] % mod_;
            inv_fact_[i] = MODpow(fact_[i], mod_ - 2);
            assert(fact_[i] * inv_fact_[i] % mod_ == 1);
        }
    }
    ll operator()(ll n, ll m) const {
        if (m < 0 || m > n) return 0;
        return fact_[n] * inv_fact_[n - m] % mod_ * inv_fact_[m] % mod_;
    }
private:
    ll MODpow(ll n, ll m) const {
        ll result = 1;
        while (m) {
            if (m % 2 == 1) {
                result *= n;
                result %= mod_;
            }

            m /= 2;
            n *= n;
            n %= mod_;
        }

        return result;
    }

    vector<ll> fact_, inv_fact_;
    ll mod_;
};

ll N, A, B, C;

int main() {
    cin >> N >> A >> B >> C;

    ll probA = A * MODpow(100 - C, MOD - 2) % MOD;
    ll probB = B * MODpow(100 - C, MOD - 2) % MOD;

    Combination comb(2 * N, MOD);

    ll one_step = 100 * MODpow(100 - C, MOD - 2) % MOD;

    ll ans = 0;
    for (ll i = 0; i < N; i++) {
        //高橋君がN - 1勝 i敗となる
        ll a = comb(N - 1 + i, N - 1) * MODpow(probA, N - 1) % MOD * MODpow(probB, i) % MOD;
        (a *= probA) %= MOD;
        (ans += (a * one_step % MOD * (N + i)) % MOD) %= MOD;

        ll b = comb(N - 1 + i, N - 1) * MODpow(probB, N - 1) % MOD * MODpow(probA, i) % MOD;
        (b *= probB) %= MOD;
        (ans += (b * one_step % MOD * (N + i)) % MOD) %= MOD;
    }

    cout << ans << endl;
}

Measured memory_bytes: 3328
#include <iostream>
#include <iomanip>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <stack>
#include <queue>
#include <bitset>

#define FOR(i, b, e) for(ll i = (ll)(b); i < (ll)(e); ++i)
#define RFOR(i, b, e) for(ll i = (ll)(e-1); i >= (ll)(b); --i)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) RFOR(i, 0, n)
#define REPC(x,c) for(const auto& x:(c))
#define VS vector<string>
#define VL vector<long long>
#define VI vector<int>
#define VVI vector<vector<int>>
#define VVL vector<vector<ll>>
#define ALL(x) (x).begin(),(x).end()
#define SORT(x) sort(ALL(x))
#define RSORT(x) sort((x).rbegin(),(x).rend())
#define PAIR pair<ll,ll>
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

using  ll = long long;
constexpr ll MOD = 1000000007;
using std::cout;
using std::endl;
using std::cin;
using std::sort;
using std::pair;
using std::string;
using std::stack;
using std::queue;
using std::vector;
using std::list;
using std::map;
using std::unordered_map;
using std::multimap;
using std::unordered_multimap;
using std::set;
using std::unordered_set;
using std::multiset;

ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
ll pow(ll a, ll b) {
	ll ans = 1;
	while (b > 0) {
		if (b % 2 == 1) {
			ans *= a;
			ans %= MOD;
		}
		b /= 2;
		a *= a;
		a %= MOD;
	}
	return ans;
}
ll comb(ll a, ll b) {
	if (a - b < b) { return comb(a, a - b); }
	static unordered_map<ll, ll> memo;

	ll c = 1;
	FOR(i, a - b + 1, a + 1) {
		c *= i;
		c %= MOD;
	}
	if (memo.find(b) == memo.end()) {
		ll k = 1;
		FOR(i, 2, b + 1) {
			k *= i;
			k %= MOD;
		}
		memo[b] = pow(k, MOD - 2);
	}
	c *= memo[b];
	return c % MOD;
}
multiset<ll> prime_decomposition(ll n) {
	ll i = 2;
	multiset<ll> table{};
	while (i * i <= n) {
		while (n % i == 0) {
			n /= i;
			table.emplace(i);
		}
		++i;
	}
	if (n > 1) {
		table.emplace(n);
		return table;
	}
	return table;
}
/*
-- bit --
REP(i, (1 << n)) {
	REP(j, n) {
		cout << (1 & (i >> j));
	}
	cout << endl;
}
*/

bool in(ll x1, ll y1, ll x2, ll y2, ll xn, ll yn) {
	return (x1 <= xn && xn <= x2 && y1 <= yn && yn <= y2);
}

int main() {
	string str;
	cin >> str;
	vector<PAIR> v(26, { 0,0 });
	int j = 0;
	REPC(c, str) {
		int i = c - 'a';
		if (j - v[i].first > v[i].second) {
			v[i].second = j - v[i].first;
		}
		v[i].first = j + 1;
		++j;
	}
	for (auto&& x : v) {
		if (str.size() - x.first > x.second) {
			x.second = str.size() - x.first;
		}
	}
	ll min = 1e10;
	REPC(x, v) {
		min = std::min(min, x.second);
	}
	cout << min << endl;
}

Measured memory_bytes: 256
/* ex 9_1
   riverstone */

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

//スタックに格納するデータの数
#define SIZE 20
 
//スタックの定義
typedef struct stack{
    int size;//格納最大数
    int count;//現在のデータ数
    char data[SIZE];//データ配列
    char *top;//topへのポインタ
} stack;

void initialize_stack(stack *stk);
void push(stack *stk, char elem);
char pop(stack *stk);
void print_stack(stack *stk);

int main(void){
    int i=0;
    char string[SIZE];
    stack stk;
 
    //スタックを初期化
    initialize_stack(&stk);
 
    //入力を受け取る
    scanf("%s", string);

    //stringの中身を一文字ずつ見ていく
    for(i=0;i<strlen(string);i++){
        //入力文字が0か1の場合
        if(string[i]=='0' || string[i]=='1'){
            //スタックにプッシュする
            push(&stk,string[i]);
        }

        //入力文字がBの場合
        else if(string[i]=='B' && stk.count>0){
            //スタックから一文字popする
            pop(&stk);
        }
    } 

    //stackの中身を出力
    print_stack(&stk);
    printf("\n");
    return 0;
}


//スタックの初期化
void initialize_stack(stack *stk){
    stk->count = 0;//個数を０にセット
    stk->size = SIZE;//格納最大数はSIZEに
    stk->top = &(stk->data[SIZE]);//topは配列の最終要素の1つ手前。
}

//データの追加
void push(stack *stk, char elem){
    if(stk->count >= stk->size){
        fprintf(stderr, "Error: stack overflow. (x=%c)\n", elem);
        exit(1);
    }
    else{
        //topを1つ上に上げる(1つ手前に移動する)
        stk->top--;
        //そこにデータを格納する
        *(stk->top) = elem;
        //現在のデータ数を1つ増やす
        stk->count++;
    }
}

//データの取り出し
char pop(stack *stk){
    char latest;
    if(stk->count <= 0){
        fprintf(stdout, "Error: stack underflow.\n");
        exit(1);
    }
    else{
        latest = *(stk->top);//topの位置からデータを取り出す
        stk->top++;//topを1つ下に下げる
        stk->count--;//現在のデータ数を1つ減らす
        return latest;
    }
}
 
//出力
void print_stack(stack *stk){
    int i;
    //topの位置から、古いデータに向かって順番に印刷
    for (i=0;i < stk->count;i++){
        printf("%c",stk->data[SIZE-i-1]);
    }
    printf("\n");
}


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

using namespace std;

int gcd(int m, int n) {
    // 引数に０がある場合は０を返す
    if ((0 == m) || (0 == n))
        return 0;

    // ユークリッドの方法
    while (m != n) {
        if (m > n)
            m = m - n;
        else
            n = n - m;
    }
    return m;
} // gcd
long long lcm(int m, int n) {
    // 引数に０がある場合は０を返す
    if ((0 == m) || (0 == n))
        return 0;

    return (((long long)m / (long long)gcd(m, n)) *
            (long long)n); // lcm = m * n / gcd(m,n)
} // lcm
int main() {
    string s, t;
    int n, m;
    cin >> n >> m >> s >> t;
    int GCD = gcd(n, m);
    long long ans = lcm(n, m);
    int n2 = n / GCD, m2 = m / GCD;
    for (int i = 0; i < GCD; i++) {
        if (s[i * n2] != t[i * m2]) {
            ans = -1;
            break;
        }
    }
    cout << ans;
}


Measured memory_bytes: 512
#include<iostream>
#include<map>
#include<string.h>
#include<queue>
#include<algorithm>
#include<vector>
#include<string>
#include<utility>
#include<cstdlib>
#include<math.h>
#include<set>
#include<array>
using namespace std;

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



#define rep(n) for(int i=0;i<(n);i++)
typedef pair<int, int> pii;

typedef long long ll;
typedef pair<ll, ll>pll;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<ll> vl;
typedef vector<vl> vll;
const int MOD = 1000000007;
const int INF = 1 << 29;
const long long LINF = 1LL << 60;

int main() {
	
	string s, t;
	cin >> s >> t;
	vll dp(3001, vl(3001,0));
	
	for (int i = 0; i < s.size(); i++) {
		for (int j = 0; j < t.size(); j++) {
			if (s[i] == t[j])dp[i + 1][j + 1] = dp[i][j] + 1;
			chmax(dp[i + 1][j + 1], dp[i][j + 1]);
			chmax(dp[i + 1][j + 1], dp[i + 1][j]);
		}
	}
	string ans = "";
	int i = s.size(); int j = t.size();
	while (i > 0 && j > 0) {

		if (dp[i][j] == dp[i - 1][j])i--;
		else if (dp[i][j] == dp[i][j - 1])j--;
		else {
			ans = s[i - 1] + ans;
			i--; j--;
		}
	}
	cout << ans << endl;
	return 0;
}

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

int vec_sum(vector<int> cont , int x){
  
  int sum = 0;
  for(int i = 0 ; i < x ; i++){
    sum += cont.at(i);
  }
  return sum;
}
    
int main() {
  
  int N;
  cin >> N;
  vector<int> cont(N);
  
  for(int i = 0 ; i < N ; i++){
    cin >> cont.at(i);
  }
  
  int all_sum = vec_sum(cont , N);
  int min_sum = all_sum;
  int a;
  
  for(int i = 0 ; i < N ; i++){
    
    if( (all_sum - 2*(vec_sum(cont , i) ) ) < 0){
      
      a = (-1)*(all_sum - 2*(vec_sum(cont , i) ) );
    }
    else{
      a = (all_sum - 2*(vec_sum(cont , i) ) );
    }
    
    min_sum = min(a , min_sum);
    
  }
  
  cout << min_sum << endl;
  
}

Measured memory_bytes: 256
/*
* Welcome to my code!
*---------------------------------------------*
* author : lynmisakura(twitter : @andoreiji11)
*/
#include<bits/stdc++.h>

using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define repn for(int i = 0;i < n;i++)
#define ain(a) for(auto& i : a)cin >> i;
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x.size()) 
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define cont continue

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using pi = pair<int,int>;
using vpi = vector<pi>;
using pl = pair<ll,ll>;
using vpl = vector<pl>;

template<class T> bool chmin(T& a,T b){if(a > b){a = b;return true;}else return false;}
template<class T> bool chmax(T& a,T b){if(a < b){a = b;return true;}else return false;}
template<class T> void print(std::vector<T> a){ int sz = a.size();
for(int i=0;i<a.size();i++)cout << a[i] << (i < sz-1 ? ' ' : '\n'); }
void ioboost(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(20);}
///////////////////////////////////////////////////////////

int main(){
	string s;cin >> s;
	if(s == "ARC")cout << "ABC" << '\n';
	else cout << "ARC" << '\n';
}

Measured memory_bytes: 3612
package main

import (
	"fmt"
)

func main() {
	list := make([]int, 5)
	for i := 0; i < 5; i++ {
		fmt.Scan(&list[i])
	}

	for i := 0; i < 5; i++ {
		if list[i] == 0 {
			fmt.Println(i + 1)
		}
	}

}


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

int main() {
  string a, b, c;
  char s1, s2, s3;
  string hello = "Hello";
  cin >> a >> b >> c;
  s1 = a.at(0);
  s2 = b.at(0);
  s3 = c.at(0);
  cout << s1 << s2 << s3<< endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <queue>
#include <vector>
#include <map>
using namespace std;
#define fors(i,a,b) for(int i=(a);i<=(b);++i)
#define ford(i,a,b) for(int i=(a);i>=(b);--i)
#define min(x,y) ((x) < (y) ? (x) : (y))
#define max(x,y) ((x) < (y) ? (y) : (x))
#define swap(x,y) ((x)^=(y),(y)^=(x),(x)^=(y))
const int maxn=1e6+7;
typedef long long ll;
const int inf=1<<25;
int read(){
    int s=0,f=1;
    char c=getchar();
    while(c<'0' || c>'9') {if(c=='-') f=-1; c=getchar();}
    while(c>='0' && c<='9') {s=s*10+c-48;c=getchar();}
    return s*f;
}
void write(int x){
    if(x<0) {putchar('-');x=-x;}
    if(x>9) write(x/10);
    putchar(x%10+48);
}

int abs(int x){
    return x < 0 ? -x : x; 
}
int a[maxn],b[maxn],n,m,c,flag;
char s[45];

int main(int argc, char const *argv[])
{
    n=read();
    fors(i,1,n){
        a[i]=read(),b[i]=read();
        ((a[i]+b[i]) & 1) ?  ++c : --c;
    }
    
    if(abs(c) != n) return 0 * puts("-1") ;

    m=31 + (c < 0);

    write(m),putchar(10);

    fors(i,0,30){
        printf("%d ", 1<<i );
    }

    if(c < 0) putchar('1');

    putchar(10);
    
    fors(i,1,n){
        int x=a[i],y=b[i];
        if(c < 0) s[31]='R' , --x;
        flag = 0;
        ford(j,30,0){
            if(abs(x) < abs(y)) swap(x,y),flag ^= 1; 
            if(x > 0 ) x-= 1<<j ,s[j] = flag ?  'U' : 'R';
            else x+= 1 << j , s[j] = flag ? 'D' : 'L';    
        }

        puts(s);
    
    }

    return 0;
}

Measured memory_bytes: 2304
#include <iostream>
#include <vector>
#include <map>
#include <string>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <functional>
#include <queue>
#include <utility>
using namespace std;
typedef long long ll;
int main(){
  int n;
  cin >> n;
  vector<ll> a(n);
  for(int i = 0;i < n;i++)cin >> a[i];

  //-,+,-,...か+,-,+,...のどちらか

  ll now_sum = 0;
  ll ans_1 = 0;
  for(int i = 0;i < n;i++){
    now_sum += a[i];
    if(i % 2 == 0){//このとき+とする.
      if(now_sum <= 0){
        ans_1 += (1 - now_sum);
        now_sum = 1;
      }
    }
    else{//このとき-とする.
      if(now_sum >= 0){
        ans_1 += (now_sum + 1);
        now_sum = -1;
      }
    }
  }

  now_sum = 0;
  ll ans_2 = 0;
  for(int i = 0;i < n;i++){
    now_sum += a[i];
    if(i % 2 == 0){//このとき-とする.
      if(now_sum >= 0){
        ans_2 += (now_sum + 1);
        now_sum = -1;
      }
    }
    else{//このとき+とする.
      if(now_sum <= 0){
        ans_2 += (1 - now_sum);
        now_sum = 1;
      }
    }
  }

  cout << min(ans_1,ans_2) << endl;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
typedef long long ll;
// Welcome to my source code!

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

const int INF = 1e9;

int main() {
    int n;
    cin >> n;
    int h[n], dp[n];
    for (int i = 0; i < n; i++) { cin >> h[i]; dp[i] = INF; }
    dp[0] = 0, dp[1] = abs(h[1] - h[0]);
    for (int i = 2; i < n; i++) {
        dp[i] = min(dp[i-1] + abs(h[i] - h[i-1]), dp[i-2] + abs(h[i] - h[i-2]));
    }
    cout << dp[n-1] << endl;
}

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

using namespace std;

#define DUMP(x) std::cerr << (#x) << " = " << (x) << "\n"
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define REP(i, k, n) for (int i = (k); i < (int)(n); ++i)
#define ALL(r) r.begin(), r.end()
#define YES puts("YES")
#define Yes puts("Yes")
#define NO puts("NO")
#define No puts("No")
#define IMP puts("IMPOSSIBLE")
#define Imp puts("Impossible")
#define imp puts("impossible")
#define M1 puts("-1")
#define pb push_back

template <typename T>
ostream &operator<<(ostream &os, vector<T> &v)
{
    os << "{";
    rep(i, v.size()) os << v[i] << (i == (int)v.size() - 1 ? "" : ", ");
    os << "}";
    return os;
}
template <typename T>
T dup(T x, T y)
{
    return (x + y - 1) / y;
};
template <typename A, size_t N, typename T>
inline void arrayFill(A (&array)[N], const T &val) { std::fill((T *)array, (T *)(array + N), val); }
struct in
{
    const size_t n = 0;
    in() = default;
    in(size_t n) : n(n){};
    template <typename T>
    operator T()
    {
        T ret;
        cin >> ret;
        return ret;
    }
    template <typename T>
    operator vector<T>()
    {
        assert(n != 0);
        vector<T> ret(n);
        for (auto &x : ret)
            cin >> x;
        return ret;
    }
};

using ll = int64_t;
using vint = vector<int32_t>;
using vvint = vector<vint>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vstr = vector<string>;
using pint = pair<int32_t, int32_t>;
using pll = pair<ll, ll>;
using setint = set<int32_t>;
using setstr = set<string>;
using qint = queue<int32_t>;
using qpint = queue<pint>;

constexpr std::int32_t INF = 1001001001;
constexpr std::int64_t LINF = 1001001001001001001;

bool same(vint &a, vint &b)
{
    rep(i, a.size())
    {
        if (a[i] != b[i])
            return false;
    }
    return true;
}

void Main()
{
    int n = in();
    vint p = in(n), q = in(n);
    vint v(n);
    rep(i, n)
    {
        v[i] = i + 1;
    }
    int a, b;
    int cnt = 1;
    do
    {
        if (same(v, p))
        {
            a = cnt;
        }
        if (same(v, q))
        {
            b = cnt;
        }

        ++cnt;
    } while (next_permutation(ALL(v)));
    cout << abs(a - b) << endl;
}

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


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

int main() {
  int a, b, k;
  cin >> a >> b >> k;
  stack<int> d;
  for(int i = 1; i <= 100; i++) {
    if(a % i == 0 && b % i == 0) {
      d.push(i);
    }
  }
  for(int i = 0; i < k - 1; i++) {
    d.pop();
  }
  cout << d.top() << endl;
}

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

using namespace std;
typedef long long ll;
typedef long int li;
typedef long double lb;
#define rep(i,j,n) for (ll i = j; i < (n); i++)
#define repr(i,j,n) for(ll i = j; i >= (n); i--)
#define all(x) (x).begin(),(x).end()
#define CLR(mat,f) memset(mat, f, sizeof(mat))
#define IN(a, b, x) (a<=x&&x<b)
#define out(ans) cout << ans << endl
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
typedef pair<ll,ll>P;
const ll mod=1e9+7;
const ll INF = 1LL<<60;
const lb PI=3.14159265359;

int main(){

  ll n;cin>>n;
  ll a[n];
  ll table[n][n];
  rep(i,0,n)CLR(table[i],-1);
  rep(i,0,n){
    cin>>a[i];
    rep(j,0,a[i]){
      ll x,y;cin>>x>>y;
      table[i][--x]=y;
    }
  }

  ll ans=0;
  rep(bit,0,(1<<n)){
    vector<ll>bl(n,0);
    rep(i,0,n)if((bit>>i)&1)bl[i]=true;

    bool e=true;
    ll count=0;

    rep(i,0,n){
      if(bl[i]){
        count++;
        rep(j,0,n){
          if(table[i][j]==-1)continue;
          if(table[i][j]!=bl[j])e=false;
        }
      }
    }

    if(e)chmax(ans,count);
  }

  out(ans);

  return 0;
}


Measured memory_bytes: 256
//#pragma GCC oplmize(2)
#include <bits/stdc++.h>
#define ll long long
#define sc(x) scanf("%lld",&x)
#define scs(x) scanf("%s",x+1)
#define pr(x) printf("%lld\n",x)
#define prs(x) printf("%s\n",x)
using namespace std;
const int maxn=1e7+5;
const int mod=998244353;
const double pi=acos(-1.0);
const double eps = 1e-8;
char s[maxn];
int a[maxn],len;
ll dp[2][maxn];   //每个状态有两个选择，dp[0][i]表示支付x张10^i元货币，dp[1][i]表示支付一张10^(i+1)，找10-x张10^i元货币

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    scs(s);
    len=strlen(s+1);
    for(int i=1;i<=len;i++){
        a[i]=s[len-i+1]-'0';
    }
    dp[0][1]=a[1];
    dp[1][1]=10-a[1];
    for(int i=2;i<=len+1;i++){
        dp[0][i]=min(dp[0][i-1]+a[i],dp[1][i-1]+a[i]+1);
        dp[1][i]=min(dp[0][i-1]+10-a[i],dp[1][i-1]+10-(a[i]+1));
    }
    pr(min(dp[0][len+1],dp[1][len+1]));
    return 0;
}

Measured memory_bytes: 24296
#include <bits/stdc++.h> 
using namespace std;
typedef long long intl;
const int N=2*1e5+2;
int dp[N][2];       
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
 	string s;
 	cin>>s;
 	int n=s.size();
 	dp[0][0]=1;
 	dp[0][1]=-1e9;
 	dp[1][1]=1;
 	for(int i=1;i<n;i++){
 		if(i>2){
 			if(s[i]!=s[i-2]||s[i-3]!=s[i-1]){
 				dp[i][1]=max(dp[i][1],dp[i-2][1]+1);
			 }
		 }
		 if(i>1){
		 	dp[i][1]=max(dp[i][1],dp[i-2][0]+1);
		 }
		 if(s[i]!=s[i-1]){
		 	dp[i][0]=max(dp[i-1][0]+1,dp[i][0]);
		 }
		 dp[i][0]=max(dp[i][0],dp[i-1][1]+1);
	 }
	 cout<<max(dp[n-1][0],dp[n-1][1])<<endl;
}

Measured memory_bytes: 2196
object Main extends App {
  import scala.io.StdIn._
  val n = readInt()
  val s = readLine()
  if (n % 2 == 1) {
    println("No")
  } else if (s.take(n/2) == s.takeRight(n/2)) {
    println("Yes")
  } else {
    println("No")
  }
}

Measured memory_bytes: 25536
import sys
from math import sqrt, cos, pi
def input(): return sys.stdin.readline().strip()


def main():
    A, B, H, M = map(int, input().split())
    time = H * 60 + M
    s = 0.5 * time
    l = 6 * time
    angle = min(abs(s - l), 360 - abs(s - l))
    dist = sqrt(A**2 + B**2 - 2 *A * B * cos(angle * 2 * pi / 360))
    print(dist)



if __name__ == "__main__":
    main()


Measured memory_bytes: 62428
#include<bits/stdc++.h>
#define ll long long
using namespace std;
struct edge{
	int to,nxt,dis;
}e[200101];
int head[101010],tot,n;
inline void made(int from,int to,ll dis){
	e[++tot].to=to;e[tot].nxt=head[from];head[from]=tot;
	e[tot].dis=dis;
}
int a[101010],b[100],f[201010],g[202020];
void dfs(int u,int faa){
	for (int i=head[u];i;i=e[i].nxt){
		int v=e[i].to;
		if (v==faa) continue; 
		a[u]^=e[i].dis,a[v]^=e[i].dis;
		dfs(v,u);
	}
}
signed main(){
	scanf("%d",&n);
	for (int i=1;i<n;i++){
		int x,y,z;
		scanf("%d%d%d",&x,&y,&z);
		made(x+1,y+1,z),made(y+1,x+1,z);
	}
	dfs(1,0); 
	int all=0,ans=0;
	for (int i=1;i<=n;i++){
		if (a[i]) b[a[i]-1]++,all^=(1<<(a[i]-1));
	}
	for (int i=0;i<15;i++) ans+=b[i]/2,b[i]&=1;
	for (int zt=1;zt<=all;zt++){
		bool flag=0;
		for (int i=0;i<15;i++){
			if (((1<<i)&zt)&&(!b[i])){
				flag=1;break;
			}
			else if ((1<<i)&zt) g[zt]^=i+1;
		}
		if (!flag){
			f[zt]=__builtin_popcount(zt)-1;
			for (int i=zt&(zt-1);i;i=zt&(i-1)){
				if (g[zt^i]*g[i]){
					f[zt]=min(f[zt],f[zt^i]+f[i]+1);
				}else{
					f[zt]=min(f[zt],f[zt^i]+f[i]);
				}
			}
		}
	}
	cout<<f[all]+ans;
    return 0;
}


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


int main()
{
    int A, B, C, D, E, F;
    cin >> A >> B >> C >> D >> E >> F;
    //合計iグラムでの砂糖。値は砂糖の量
    int dp[F + 1];
    rep(i, F + 1) {
         dp[i] = -1;
    }
    //水をいれる走査をくりかえし、存在可能な場所を0(砂糖なし)でマーク
    dp[0] = 0;
    for (int i = 0; i <= F; i += 100 * A) {
        dp[i] = 0;
        for (int j = i; j <= F; j += 100 * B) {
            dp[j] = 0;
        }
    }
    //操作C
    double maxE = 0;
    int waterAtMax = A * 100;
    int sugarAtMax = 0;

    for (int loop = 0; loop < 2; loop++) {
        int ADD = (loop == 0) ? C : D;
        for (int i = 100; i <= F; i++) {
            int sugar = dp[i];
            if (sugar < 0) {
                continue;
            }
            int water = i - sugar;
            sugar += ADD;
            int total = water + sugar;
            if (total > F) {
                break;
            }
            double e = sugar * 100.0 / water;
            if (e == E) {
                waterAtMax = water;
                sugarAtMax = sugar;
                loop = 100;
                break;
            }
            if (e < E) {
                dp[total] = max(dp[total], sugar);
                if (e > maxE) {
                    maxE = e;
                    waterAtMax = water;
                    sugarAtMax = sugar;
                }
            }
        }
    }
    cout << (waterAtMax + sugarAtMax) << " " << sugarAtMax << endl;
    return 0;
}

Measured memory_bytes: 256
/* << IN THE NAME OF GOD >> */
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define pob pop_back
#define ft first
#define ftt ft.ft
#define ftc ft.sc
#define sc second
#define err(x) cerr << #x  << " = "<<  x << '\n'
#define out(x) cout << x << '\n'
#define forp(i, r, l) for(int i = int(r); i < int(l); i++)
#define forn(i, r, l) for(int i = int(r); i > int(l); i--)
#define FAST ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
typedef long long ll;
#define ctz __builtin_ctz
typedef pair<int, int> pii;
typedef pair<ll ,ll> pll;
const int maxn = 1e6 + 120;
 



int a ,sum ,res ,mx;
int main(){FAST;
    forp(i ,0 ,3)
        cin >> a ,mx = max(mx ,a) ,sum += a;
    (3 * mx) % 2 == sum % 2 ? res = 3 * mx : res = 3 *(mx + 1);
    cout << ( (res  - sum) >> 1);

    


   return 0;
}
 












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

int mp[15000000];
int Hash(string s) {
	int cnt = 0, t = 1;
	rep(i, s.size()) {
		cnt += s[i]*t;
		t *= 3;
	}
	return cnt;
}
int main() {
	int n, m;
	while (scanf("%d%d", &n, &m), n) {
		memset(mp, 0, sizeof(mp));
		string in(15, 0);
		rep(i, 3) {
			int len; scanf("%d", &len);
			rep(j, len) {
				int a; scanf("%d", &a);
				in[--a] = i;
			}
		}
		queue<string>que;
		mp[Hash(in)] = 1;
		que.push(in);
		while (!que.empty()) {
			string u = que.front(); que.pop();
			if (count(u.begin(), u.begin() + n, 0) == n ||
				count(u.begin(), u.begin() + n, 2) == n) {
				printf("%d\n", mp[Hash(u)] - 1);
				goto g;
			}
			if (mp[Hash(u)] > m)continue;
			rep(k, 2)rep(t, 2) {
				int i, j;
				if (t) { i = k, j = k + 1; }
				else { i = k + 1; j = k; }
				int fi = u.rfind(i, n - 1), fj = u.rfind(j, n - 1);
				if (fi == -1 || fi < fj)continue;
				string v = u;
				v[fi] = j;
				if (!mp[Hash(v)]) {
					mp[Hash(v)] = mp[Hash(u)] + 1;
					que.push(v);
				}
			}
		}
		puts("-1");
	g:;
	}
}



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


int main(){
    int A;
    int B;
    int K;
    scanf("%d", &K);
    scanf("%d %d", &A, &B);
    int myK = K;
    int i = 0;
    while (myK < 1001)
    {
        if (A <= myK && myK <= B)
        {
            i = 1;
            break;
        }else{
            myK += K;
        }
    }
    
    if(i == 1){
        printf("OK\n");
    }else{
        printf("NG\n");
    }
    
    return 0;
}

Measured memory_bytes: 3764
#include <bits/stdc++.h>
#define rep(i, a, b) for(int i = int(a); i < int(b); i++)
#define rer(i, a, b) for(ll i = ll(a) - 1; i >= ll(b); i--)
#define sz(v) (int)(v).size()
#define pb push_back
#define sc second
#define fr first
#define sor(v) sort(v.begin(),v.end())
#define rev(s) reverse(s.begin(),s.end())
#define lb(vec,a) lower_bound(vec.begin(),vec.end(),a)
#define ub(vec,a) upper_bound(vec.begin(),vec.end(),a)
#define uniq(vec) vec.erase(unique(vec.begin(),vec.end()),vec.end())
using namespace std;
typedef long long int ll;
typedef pair <int, int> P;

const ll MOD=1000000007;
vector<int> E[400000];
int flag[400000];
int N,M;
bool dfs(int x){
    if(flag[x]==1) return true;
    flag[x]=1;
    for(int &to : E[x]){
        if(flag[to]>=0&&dfs(to)) return true;
    }
    flag[x]=-1;
    return false;
}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin>>N>>M;
    string s;
    cin>>s;
    rep(i,0,M){
        int a,b;
        cin>>a>>b;
        a--;
        b--;
        if(s[a]==s[b]){
            E[N+a].pb(b);
            E[b+N].pb(a);
        }
        else{
            E[a].pb(b+N);
            E[b].pb(a+N);
        }
    }
    rep(i,0,2*N){
        if(flag[i]==0&&dfs(i)){
                cout <<"Yes"<<"\n";
                return 0;
        }
    }
    cout <<"No"<<"\n";
}

Measured memory_bytes: 24912