akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
int main(){	
    long long x,i=2,sum=1;
    cin>>x;
    for(;i<=x;i++){
    	if(i%3==0||i%5==0);
    	else	sum=sum+i;
	}
	cout<<sum;
  cout<<endl;
    return 0;
}

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

int main() {
  string S;
  cin >> S;
  
  if (S == "SUN") {
    cout << "7";
  } else if (S == "MON") {
    cout << "6";
  } else if (S == "TUE") {
    cout << "5";
  } else if (S == "WED") {
    cout << "4";
  } else if (S == "THU") {
    cout << "3";
  } else if (S == "FRI") {
    cout << "2";
  } else if (S == "SAT") {
    cout << "1";
  }
  return 0; 
}

Measured memory_bytes: 256
#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[i];

    int ans = A[0];
    for (int i = 0; i < N; i++) ans = __gcd(ans, A[i]);

    cout << ans << endl;
}

Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <set>
#include <string>
#include <algorithm>
#include <iomanip>
static const double PI = 3.14159265359;

int main()
{
	int K;
	std::cin >> K;
	int sum = 0;
	for (int a = 1; a <= K; ++a) {
		for (int b = a; b <= K; ++b) {
			for (int c = b; c <= K; ++c) {
				int gcd = a;
				const int same = ((a==b)?1:0) + ((b == c) ? 1 : 0);
				for (; gcd > 1; --gcd) {
					if ((a%gcd == 0) && (b%gcd == 0) && (c%gcd == 0)) {
						break;
					}
				}
				switch (same) {
				case 0:
					sum += gcd*6;
					break;
				case 1:
					sum += gcd*3;
					break;
				case 2:
					sum += gcd;
					break;
				}
			}
		}
	}
	std::cout << sum << std::endl;
	return 0;
}

Measured memory_bytes: 3600
# coding: utf-8
X,Y,A,B,C = list(map(int, input().split()))
P = sorted(list(map(int, input().split())))[-X:]
Q = sorted(list(map(int, input().split())))[-Y:]
R = list(map(int, input().split()))

total = sorted(P + Q + R)[-X-Y:]
print(sum(total))

Measured memory_bytes: 23256
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,a,b)  for(int i=(a),i##formax=(b);i< i##formax;i++)
#define FORR(i,a,b) for(int i=(a),i##formin=(b);i>=i##formin;i--)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define pcnt __builtin_popcount
#define sz(x) (int)(x).size()
#define maxs(x,y) x=max((x),(y))
#define mins(x,y) x=min((x),(y))
#define show(x) cout<<#x<<" = "<<(x)<<endl;
#define all(a) ((a).begin()),((a).end())
#define each(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define bit(n) (1LL<<(n))
typedef long long ll;
typedef __int128_t lll;
template<class T>using V=vector<T>;
template<class T>using VV=V<V<T>>;
template<class T,class Y>using P=pair<T,Y>;
template<class T,class Y>ostream& operator<<(ostream&o,P<T,Y>&p){return o<<"("<<p.fi<<","<<p.se<<")";}
template<class T>ostream& operator<<(ostream&o,V<T>&v){for(T&t:v)o<<t<<",";return o<<endl;}
template<class T>void uniq(V<T>&v){sort(all(v));v.erase(unique(all(v)), v.end());}

lll gcd(lll a,lll b,lll&x,lll&y){if(!b){x=1;y=0;return a;}lll d=gcd(b,a%b,y,x);y-=a/b*x;return d;}
ll modInv(ll a,ll m){lll x,y;gcd(a,m,x,y);return(x%m+m)%m;}
ll modPow(lll a,lll n,ll m){lll p=1;for(;n;n>>=1,a=a*a%m)if(n&1)p=p*a%m;return p;}
//V<ll>F,R;void setF(int n,int mod){F=R=V<ll>(++n);F[0]=1;FOR(i,1,n)F[i]=F[i-1]*i%mod;R[n-1]=modInv(F[n-1],mod);FORR(i,n-1,1)R[i-1]=R[i]*i%mod;}
//ll comb(int a,int b,int m){return a<b||b<0?0:F[a]*R[b]%m*R[a-b]%m;}

const int IINF = 1e9;
const ll LINF = 1e18;
const int MOD = 1e9+7; //99844353;
const int N = 2e5+1;
int n, k, _p[N], *p=_p+1;
set<int> s;
main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> n >> k;
  p[-1] = IINF;
  FOR(i, 0, n) cin >> p[i];
  int ans = 0, c, u = 0;
  s.insert(p[-1]);
  FOR(i, 0, n){
    if(p[i-1] > p[i]){
      c = 1;
    }else{
      c++;
    }
    s.insert(p[i]);
    if(i<k-1) continue;
    s.erase(p[i-k]);
    if(p[i-k]<*s.begin() && p[i]==*s.rbegin()) continue;
    if(c>=k && ++u) continue;
    ans++;
  }
  cout << ans+!!u << endl;
}

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

int main() {
	int n;cin>>n;
	int f[55555];
	for(int i=0;i<55555;i++)f[i]=i;
	f[0]=0;
	f[1]=0;
	for(int i=2;i<300;i++){
		if(f[i]){
			int k=2;
			while(i*k<55555){
				f[i*k]=0;
				k++;
			}
		}
	}
	int count=0;
	for(int i=0;i<55555;i++){
		if(i%5==1){
			if(f[i]){
				cout<<i<<endl;
				count++;
			}
		}
		if(count==n)break;
	}
	return 0;
}

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

int main(int argc, char *argv[])
{
    int W;
    int a, b;
    scanf("%d %d %d", &W, &a, &b);

    if ( b > a ){
        if ( a+W > b ){
            printf("0\n");
        } else {
            printf("%d\n", abs(b - (a + W)));
        }
    } else {
        if ( b+W > a ){
            printf("0\n");
        } else {
            printf("%d\n", abs(a - (b + W)));
        }
    }
    return 0;
}

Measured memory_bytes: 128
#pragma GCC optimize("Ofast")
#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;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<long long, long long>;
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
constexpr char ln = '\n';
constexpr long long MOD = 1000000007;
//constexpr long long MOD = 998244353;
template<class T1, class T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return true;} return false; }
template<class T1, class T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return true;} return false; }
inline int popcount(int x) {return __builtin_popcount(x);}
inline int popcount(long long x) {return __builtin_popcountll(x);}
void print() { cout << "\n"; }
template<class T, class... Args>
void print(const T &x, const Args &... args) {
    cout << x << " ";
    print(args...);
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    ll X,K,D; cin >> X >> K >> D;
    X = abs(X);
    ll p = X/D;
    if (K <= p) {
        cout << X-K*D << ln;
        return 0;
    }
    K -= p;
    ll ans = X%D;
    if (K&1) {
        ans = D-ans;
    }
    cout << ans << ln;
}

Measured memory_bytes: 3660
#include <iostream>
#include <cstdio>
using namespace std;
int main(void){
  // printf("Hello World\n") // Your code here!
    int S ,h , m, s;

    cin >> S;
    
    h=S/3600;
    m=S%3600/60;
    s=S%60;
   
    cout <<h;
    cout <<":";
    cout <<m;
    cout <<":";
    cout <<s;
    cout << endl;
}



Measured memory_bytes: 3112
import itertools

mMNQ = map(int, input().split())
lMNQ = list(mMNQ)

mPts = [map(int, input().split()) for i in range(lMNQ[2])]
lPts = [list(j) for j in mPts]

lNum = range(1, lMNQ[1] + 1)

lSet = itertools.combinations_with_replacement(lNum, r = lMNQ[0])
lSet = list(lSet)

pMax = 0
for s in lSet:
    sum = 0
    
    for p in lPts:
        if(s[p[1]-1] - s[p[0]-1] == p[2]):
            sum += p[3]
    
    if(sum > pMax):
        pMax = sum
        
print(pMax)

Measured memory_bytes: 21544
#include <iostream>
#include <string>

using namespace std;

int main(){
	int a,b,c;
	string str;
	cin >> a;
	cin >> b;
	cin >> c;
	if(a<b && b<c)
		str = "Yes";
	else
		str = "No";
	cout << str <<endl;
	return 0;
}

Measured memory_bytes: 1192
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#define Rep(i,a,b) for(register int i=(a),i##end=(b);i<=i##end;++i)
#define Repe(i,a,b) for(register int i=(a),i##end=(b);i>=i##end;--i)
#define For(i,a,b) for(i=(a),i<=(b);++i)
#define Forward(i,a,b) for(i=(a),i>=(b);--i)
#define Chkmax(a,b) a=a>b?a:b
#define Chkmin(a,b) a=a<b?a:b
template<typename T>inline void read(T &x)
{
	T f=1;x=0;char c;
	for(c=getchar();!isdigit(c);c=getchar())if(c=='-')f=-1;
	for(;isdigit(c);c=getchar())x=x*10+(c^48);
	x*=f;
}
using namespace std;
const int MAXN=111;
static int a[3];
inline void init()
{
	read(a[1]);read(a[2]);read(a[3]);
	sort(a+1,a+4);
	a[3]-=a[1];a[2]-=a[1];a[1]=0;
}
static int ans=10000;
struct node
{
	int x,y,z,id;
	friend bool operator<(node a,node b){return a.x^b.x?a.x<b.x:a.y^b.y?a.y<b.y:a.z<b.z;}
}u,v;
queue<node>G;
map<node,bool>K;
void resolve(node&x)
{
	if(x.z<x.y)swap(x.z,x.y);
	if(x.y<x.x)swap(x.y,x.x);
	if(x.z<x.y)swap(x.y,x.z);
	x.z-=x.x;x.y-=x.x;x.x=0;
}
void bfs()
{
	G.push((node){0,a[2],a[3],0});
	while(!G.empty())
	{
		u=G.front();G.pop();
		if(!u.z){ans=u.id;return;}
		v=u;v.id=u.id+1;
		v.x+=2;
		resolve(v);
		if(!K[v]){K[v]=true;G.push(v);}
		v=u;v.id=u.id+1;
		++v.x;++v.y;resolve(v);
		if(!K[v]){K[v]=true;G.push(v);}
		v=u;v.y+=2;
		resolve(v);
		if(!K[v]){K[v]=true;G.push(v);}
		v=u;v.id=u.id+1;
		++v.x;++v.z;resolve(v);
		if(!K[v]){K[v]=true;G.push(v);}
		v.z+=2;
		resolve(v);
		if(!K[v]){K[v]=true;G.push(v);}
		v=u;v.id=u.id+1;
		++v.y;++v.z;resolve(v);
		if(!K[v]){K[v]=true;G.push(v);}}
}
	
inline void solve()
{
	if(!a[3])return (void)puts("0");
	bfs();
	printf("%d\n",ans);
}
int main()
{
	init();
	solve();
	return 0;
}

Measured memory_bytes: 640
#include<stdio.h>

int main(){
	double mt,max,min,flag=0;
	while(scanf("%lf",&mt)!=EOF){
		if(flag==0){
			max=mt;
			min=mt;
			flag=1;
		}
		if(mt>max)
			max=mt;
		else if(mt<min)
			min=mt;
	}

	printf("%.1f\n",max-min);
	return 0;
}

Measured memory_bytes: 652
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <tuple>
#include <queue>
#include <set>
#include <math.h>
#include <array>
#include <list>
#include <set>
const int MOD=1000000007;
const int INF=1000000000;
using namespace std;
typedef long long ll;
typedef tuple<ll,int,int> tup;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pair<int,int> > vp;
set<char> st;
string s;
int ans=700;;
int main(int argc,char const* argv[])
{
  cin >>s;
  for(int i=0;i<s.size();i++)
    {
      if(s[i]=='o') ans+=100;
    }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 764
#include <bits/stdc++.h>
#include <vector> 
# include <cstdint>
#define FOR(i,l,r) for(int i=(l);i<(r);++i)
#define RFOR(i,l,r) for(int i=(l);i>=(int)(r);i--)
#define rep(i,n)  FOR(i,0,n)
#define rrep(i,n)  RFOR(i,n-1,0)

#define int long long
using namespace std;
const int MX = 1e6;
const int inf = 1e9;
const int mod = 1e9+7;
typedef pair<int, int> P;

int dist[100005][3];
signed main(){
    int n,k;
    cin >> n >> k;
    vector<int> a(n+1);
    FOR(i,1,n+1) cin >> a[i];
    vector<int> v(n+1);
    rep(i,n+1) v[i] = 0;
    vector<int> rop;
    int now = 1;
    int cnt = 0;
    while(true) {

        if(cnt == k) {
            cout << now << endl;
            return 0;
        }
        if(v[now] != 0) break;
        rop.push_back(now);
        cnt++;
        v[now] = cnt;
        now = a[now];
        
    }
    //for(auto r:rop) cout << cnt<<" "<<r<<" "<<now <<" "<< v[now]<< endl;
    k = k-v[now]+1;
    int index = k%(cnt-(v[now]-1));

    //cout << index << endl;
    cout << rop[index+(v[now]-1)] << endl;

    
    return 0;
}

Measured memory_bytes: 8496
import copy
def explore(key, flags):
    flags = copy.copy(flags)
    if flags[key-1]:
        return 0
    flags[key-1] = True
    if False not in flags:
        return 1
    elif key in graph:
        value = graph[key]
        ans = 0
        for i in value:
            ans += explore(i, flags)
        return ans
    else:
        return 0

n, m = map(int, input().split())
graph = {}
for i in range(m):
    a, b = map(int, input().split())
    if a in graph:
        graph[a].append(b)
    else:
        graph[a] = [b]
    if b in graph:
        graph[b].append(a)
    else:
        graph[b] = [a]

flags = [False for i in range(n)]
ans = explore(1, flags)
print(ans)


Measured memory_bytes: 3444
def A():
    N = int(input())
    H = int(input())
    W = int(input())
    print((N - H + 1) *(1 + N - W))
#A()

def B():
    N = int(input())
    A, B = map(int, input().split())
    P = list(map(int, input().split()))
    f = []
    s = []
    t = []
    for i in P:
        if i <= A:
            f.append(i)
        elif i <= B:
            s.append(i)
        else:
            t.append(i)
    print(min(len(f), len(s), len(t)))
B()

Measured memory_bytes: 3064
import java.util.*;

public class Main {
		public static void main(String[] args) {
			
			Scanner sc = new Scanner(System.in);
			
			int H = sc.nextInt();
			int N = sc.nextInt();
			Integer A[] = new Integer[N];
			for (int i=0; i<N; i++) {
				A[i] = sc.nextInt();
			}
			int sum = 0;
           for(int i=0; i<N; i++) {
        	   sum += A[i];
           }
		if(H <= sum) {
			System.out.println("Yes");
		}else
			System.out.println("No");
		}
		}

Measured memory_bytes: 63388
#include <cstring>
#include <iostream>
#include <numeric>
#include <bits/stdc++.h>
using namespace std;
int main(){
int N,t=0;
cin>>N;
int a[N],b[N],c[N],d;
for(int i=0;i<N-1;i++){
cin>>a[i]>>b[i]>>c[i];}
for(int j=0;j<N-1;j++){
for(int i=j;i<N-1;i++){
if(t<=b[i]){d+=b[i]+a[i];}
else if(t%c[i]==0){d+=t+a[i];}
else {d+=t+a[i]+(c[i]-t%c[i]);}
t=d;
d=0;}
cout<<t<<endl;
t=0;}
cout<<0<<endl;
}



Measured memory_bytes: 256
#include <stdio.h>
typedef long long int lld;

int gcd(int a, int b) {
  int r;
  while (1) {
    if (b == 0) {
      return a;
    }
    r = a % b;
    a = b;
    b = r;
  }
}

int main(void) {
  lld s = 0;
  int k, t;
  scanf("%d", &k);
  for (int a = 1; a <= k; a++) {
    if (a == 1) {
      s += k * k;
      continue;
    }
    for (int b = 1; b <= k; b++) {
      if (b == 1) {
        s += k;
        continue;
      }
      t = gcd(a, b);
      if (t == 1) {
        s += k;
        continue;
      }
      for (int c = 1; c <= k; c++) {
        if (c == 1) {
          s++;
          continue;
        }
        s += gcd(t, c);
      }
    }
  }
  printf("%lld\n", s);
}

Measured memory_bytes: 1724
import java.util.Arrays;
import java.util.Scanner;

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

		int maxX = Arrays.stream(sc.nextLine().split(" ", 0)).mapToInt(Integer::parseInt).max().getAsInt();
		int minY = Arrays.stream(sc.nextLine().split(" ", 0)).mapToInt(Integer::parseInt).min().getAsInt();

		int lowerZ = Math.max(X, maxX) + 1;
		int upperZ = Math.min(Y, minY);
		boolean found = false;
		for (int Z = lowerZ; Z <= upperZ; Z++) {
			if (X < Z || Z <= Y || maxX < Z || Z <= minY) {
				found = true;
				break;
			}
		}
		System.out.println(found ? "No War" : "War");
		sc.close();
	}
}

Measured memory_bytes: 28500
#include <bits/stdc++.h>
using namespace std;
long long n,m;
long long Max(long long a,long long b)
{
	return a>b?a:b;
}
long long Min(long long a,long long b)
{
	return a>b?b:a;
}
int main()
{
	cin>>n>>m;
	cout<<Min(n,m/2)+Max(m-n*2,0)/4<<"\n";
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main{
	public static void main(String[] args)
	{
		Scanner sc =new Scanner(System.in);
		int a=sc.nextInt();
		int b=sc.nextInt();
		int c=sc.nextInt();
		
		if(b-a==c-b) System.out.println("YES");
		else System.out.println("NO");
	}
} 

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

using namespace std;

int L, N;
string Snake;

int main() {
	int same;
	unsigned long long int len;

	len = 0;
	same = 0;
	cin >> L >> N >> Snake;
	for (int i = 1; i < L; ++i) {
		if (Snake[i - 1] == 'o'&&Snake[i] == 'o') {
			++same;
		}
	}
	len = 3 * (((unsigned long long int)(1) << N) - 1) * same;

	cout << len + L << endl;

	return 0;
}


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

int main(){
  int K;
  cin >> K;
  if((K%2==0)||(K%5==0)){
    cout << -1 << endl;
  }else{
    if(K%7==0){
      K/=7;
    }
    int mod=9*K;
    int x=1%(9*K);
    for(int i=1;;i++){
      x=(x*(10%mod))%mod;
      if(x==1){
        cout << i << endl;
        return 0;
      }
    }
  }
  return 0;
}


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

int main()
{
    double l;
    cin >> l;
    double  ans;
    ans = (l / 3) * (l / 3) * (l / 3);

    printf("%f\n",ans);

    return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <cstring>
#include <math.h>
#include <algorithm>
#include <vector>
#include <string>
#include <stdlib.h>
#include <queue>
#include <utility>
#define rep(i,n) for(int i=0;i<n;i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ll long long
#define LL long long
#define INF 1000000001
#define mod 1000000007
using namespace std;
int keta(int n,int k){return (n/int(pow(10,double(k-1)))) % 10;} //nの下からk桁目
ll gcd(ll n,ll m){
	if(n<m){ll a=m;m=n;n=a;}
	ll r=n%m;
	while(r!=0){
		n=m;
		m=r;
		r=n%m;
	}
	return m;
}
ll lcm(ll n,ll m){
	return n*m/gcd(n,m);
}

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

	int a,b;
	int amin,bmin=INF;
	rep(i,n){
		cin>>a>>b;
		if(bmin>b){
			amin=a;
			bmin=b;
		}
	}
	cout<<amin+bmin<<endl;
	
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T, class C> void chmax(T& a, C b){ a>b?:a=b; }
template<class T, class C> void chmin(T& a, C b){ a<b?:a=b; }
int gcd(int a, int b) { return b ? gcd(b, a%b) : a; }
int main(int argc, char* argv[]) {
   int n;
   cin >> n;
   vint a(n);
   rep(i,n) cin >> a[i];
   
   vint cuml(n+1);
   vint cumr(n+1);
   
   cumr[0]=0;
   cuml[0]=0;
   rep(i,n) cuml[i+1]=gcd(cuml[i],a[i]);
   for(int i=n-1;i>=0; i--)   cumr[i]=gcd(cumr[i+1],a[i]);

    int ans =0;

   for(int i = 0; i <n ; i ++){
       
       int l = cuml[i];

       int r = cumr[i+1];
       
       chmax(ans,gcd(l,r));
   }
   cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1408
#include<iostream>
using namespace std;
typedef long long ll;
int main(){
ll n;
cin>>n;
ll a[n];
for(ll i=0;i<n;i++){
cin>>a[i];
}
int count=0;
for(ll i=0;i<n;i++){
while(a[i]%2==0){
a[i]=a[i]/2;
count++;
}

}

cout<<count;
return 0;
}

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


def fizzbuzz(n):
    if n % 5 == 0 and n % 3 == 0:
        return 0
    elif n % 3 == 0:
        return 0
    elif n % 5 == 0:
        return 0
    else:
        return n


def main():
    n = int(input())
    li = list(range(1, n+1))

    change_li = list(map(fizzbuzz, li))

    print(sum(change_li))


if __name__ == '__main__':
    main()


Measured memory_bytes: 56324
#include <iostream>
#include <vector>
#include <string>

using namespace std;
// template for creating 2d vector
template<typename T>
vector<vector<T>> make_2d_vector(size_t rows, size_t cols, T init)
{ return vector< vector<T> >(rows, vector<T>(cols, init)); }



#define debug(x) cout << #x << "==" << x << endl;

const int inf = 100000000;

typedef long long ll;

int main() {
  ios::sync_with_stdio(false);

  vector<int> hoge(1e7);

  char a, b;
  cin >> a >> b;
  if(a==b) {
    cout << "H" << endl;
  } else {
    cout << "D" << endl;
  }


  return 0;
}


Measured memory_bytes: 39296
#include<bits/stdc++.h>
using namespace std;
const int maxn = 1e5+5;
struct node{
	int num;
	int id;
}n1[maxn];
bool cmp(node a,node b){
	return a.num < b.num;
}
int main()
{
	int n;
	cin >> n;
	for(int i = 1;i <= n;i++){
		scanf("%d",&n1[i].num);
		n1[i].id = i;
	}
	sort(n1 + 1,n1 + 1 + n,cmp);
	for(int i = 1;i <= n;i++){
		cout << n1[i].id << " ";
	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 1536
#define _USE_MATH_DEFINES
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <complex>
#include <cmath>
#include <numeric>
#include <bitset>
#include <functional>
#include <random>
#include <ctime>

using namespace std;

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

typedef long long int64;
typedef pair<int, int> ii;
const int INF = 1 << 29;
const int MOD = 1e9 + 7;

int main() {
  int n;
  cin >> n;
  int ret = 1;
  vector<bool> flag(n + 1);
  for (int i = 2; i <= n; ++i) {
    if (flag[i]) continue;
    int cnt = 1;
    for (int t = n; t; t /= i) cnt += t / i;
    ret = (int64)ret * cnt % MOD;
    for (int j = i + i; j <= n; j += i) flag[j] = true;
  }
  cout << ret << endl;
  return 0;
}


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

int main(){
	int a,b,d1,d2;
	double d3;
	cin>>a>>b;
	d1=a/b;
	d2=a%b;
	d3=(a*1.0)/b;
	cout<<d1<<" "<<d2<<" ";
	cout<<fixed<<setprecision(5)<<d3<<"\n";
	return 0;
}


Measured memory_bytes: 3260
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vl;
#define rep(i, n) for(ll i = 0;i < n;i++)
#define all(i) i.begin(), i.end()
template<class T, class U> void cmax(T& a, U b) { if (a<b) a = b; }
template<class T, class U> void cmin(T& a, U b) { if (a>b) a = b; }

template <std::uint_fast64_t Modulus> class modint {
  using u64 = std::uint_fast64_t;

public:
  u64 a;

  constexpr modint(const u64 x = 0) noexcept : a(x % Modulus) {}
  constexpr u64 &value() noexcept { return a; }
  constexpr const u64 &value() const noexcept { return a; }
  constexpr modint operator+(const modint rhs) const noexcept {
    return modint(*this) += rhs;
  }
  constexpr modint operator-(const modint rhs) const noexcept {
    return modint(*this) -= rhs;
  }
  constexpr modint operator*(const modint rhs) const noexcept {
    return modint(*this) *= rhs;
  }
  constexpr modint operator/(const modint rhs) const noexcept {
    return modint(*this) /= rhs;
  }
  constexpr modint &operator+=(const modint rhs) noexcept {
    a += rhs.a;
    if (a >= Modulus) {
      a -= Modulus;
    }
    return *this;
  }
  constexpr modint &operator-=(const modint rhs) noexcept {
    if (a < rhs.a) {
      a += Modulus;
    }
    a -= rhs.a;
    return *this;
  }
  constexpr modint &operator*=(const modint rhs) noexcept {
    a = a * rhs.a % Modulus;
    return *this;
  }
  constexpr modint &operator/=(modint rhs) noexcept {
    u64 exp = Modulus - 2;
    while (exp) {
      if (exp % 2) {
        *this *= rhs;
      }
      rhs *= rhs;
      exp /= 2;
    }
    return *this;
  }
};

const ll MOD = 1000000007;

vector<ll> fac;
vector<ll> ifac;

ll modpow(ll a, ll n, ll p) {
  ll res = 1;
  while (n) {
    if (n&1) res = res * a % p;
    a = a * a % p;
    n >>= 1;
  }
  return res;
}
 
void combinit(ll n) {
  fac.resize(n+1);
  ifac.resize(n+1);
 
  fac[0] = ifac[0] = 1;
  rep(i, n) {
    fac[i+1] = fac[i]*(i+1) % MOD;
    ifac[i+1] = ifac[i]*modpow(i+1, MOD-2, MOD) % MOD;
  }
}
 
ll comb(ll n, ll k) {
  if (n == 0 && k == 0) return 1;
  if (n < k || n < 0) return 0;
  return (fac[n]*ifac[k]%MOD)*ifac[n-k]%MOD;
}

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

  using mint = modint<MOD>;
  mint n, m;
  int k;
  cin >> n.a >> m.a >> k;

  int a = n.a*m.a;

  combinit(a);

  mint ans = 0;
  for (mint d = 0; d.a < n.a; d.a++) {
    ans += d * (n-d) * m*m * comb(a-2, k-2);
  }

  for (mint d = 0; d.a < m.a; d.a++) {
    ans += d * (m-d) * n*n * comb(a-2, k-2);
  }

  cout << ans.a << endl;
}


Measured memory_bytes: 3328
#include <bits/stdc++.h>
#include <vector> 
# include <cstdint>
#define FOR(i,l,r) for(int i=(l);i<(r);++i)
#define RFOR(i,l,r) for(int i=(l);i>=(int)(r);i--)
#define rep(i,n)  FOR(i,0,n)
#define rrep(i,n)  RFOR(i,n-1,0)

#define int long long
using namespace std;
const int MX = 1e6;
const int inf = 1e9;
const int mod = 1e9+7;
#define ll long long
  
signed main() {
  int l,r,d;
  cin >>l>>r>>d;
  int ans = 0;
  FOR(i,l,r+1) {
    if(i%d==0) ans++;
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 3628
//ALDS1_10A
#include <iostream>
using namespace std;

int main(){
 int n;
 cin>>n;
 int F[50];
 F[0]=F[1]=1;
 for(int i=2;i<=n;i++) F[i]=F[i-1]+F[i-2];
 cout<<F[n]<<endl;
 return 0;
}

Measured memory_bytes: 1160
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <regex>
#include <numeric>
using namespace std;

/*--- Macro ---*/
#define rep(i, n) for(int i=0; i<(int)n; i++)
#define rep1(i, n) for(int i=1; i<(int)n; i++)
#define mp make_pair
#define pb push_back

/*---  Type ---*/
typedef long long ll;

/*--- Constants ---*/
template <typename T> const T INF = numeric_limits<T>::max() / 10;
const int MOD = (int)1e9 + 7;

// Floating
const double EPS = 1e-11;
#define EQ0(x) (abs(x) < EPS)
#define EQ(x, y) (abs(a-b) < EPS)

// Util
int max(int a, int b, int c) {return max(a, max(b, c));}
int min(int a, int b, int c) {return min(a, min(b, c));}
ll max(ll x, ll y) {return x > y ? x : y;}
ll min(ll x, ll y) {return x < y ? x : y;}
ll max(ll a, ll b, ll c) {return max(a, max(b, c));}
ll min(ll a, ll b, ll c) {return min(a, min(b, c));}

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



int main() {
  int n;
  cin >> n;
  if(n % 10 == 9 || n / 10 == 9) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define re register
using namespace std;
inline int read(){
	re int t=0;re char v=getchar();
	while(v<'0')v=getchar();
	while(v>='0')t=(t<<3)+(t<<1)+v-48,v=getchar();
	return t;
}
int a,b,c,d;
int main(){
	a=read();b=read();c=read();d=read();
	b=(c-1)/b+1;d=(a-1)/d+1;
	if(b<=d)puts("Yes");
	else puts("No");
}


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

int main() {
	string s;
	cin>>s;
	if(s=="SUN") {
		cout<<7;
	}
	if(s=="MON") {
		cout<<6;
	}
	if(s=="TUE") {
		cout<<5;
	}
	if(s=="WED") {
		cout<<4;
	}
	if(s=="THU") {
		cout<<3;
	}
	if(s=="FRI") {
		cout<<2;
	}
	if(s=="SAT") {
		cout<<1;
	}
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--)
#define IREP(i, n) IFOR(i,0,n)
#define SORT(a) sort(a.begin(), a.end())
#define REVERSE(a) reverse(a.begin(), a.end())
#define Lower_bound(v, x) distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) distance(v.begin(), upper_bound(v.begin(), v.end(), x))
#define int long long
#define INF 1000000000000000000
using namespace std;

typedef vector<int> vec;
typedef vector<vec> mat;
typedef pair<int, int> Pii;

template<typename T>
void readvec(vector<T> &a);
void readindex(vector<int> &a);



signed main(){

    int N; cin >> N;
    string s; cin >> s;
    vector<bool> ans(N);
    bool find = false;

    REP(i, 2){
        REP(j, 2){
            if(i == 0) ans[0] = true;
            else ans[0] = false;
            if(j == 0) ans[1] = true;
            else ans[1] = false;
            FOR(i, 2, N){
                if(((s[i - 1] == 'o') == ans[i - 1])) ans[i] = ans[i - 2];
                else ans[i] = !ans[i - 2];
            }
            if((((s[0] == 'o') == ans[0]) == (ans[1] == ans[N - 1])) && (((s[N - 1] == 'o') == ans[N - 1]) == (ans[N - 2] == ans[0]))){
                find = true;
                break;
            }
        }
        if(find) break;
    }

    if(find){
        REP(i, N){
            if(ans[i]) cout << "S";
            else cout << "W";
        }
    }else{
        cout << -1;
    }


    return 0;
}


template<typename T>
void readvec(vector<T> &a){
    REP(i, a.size()){
        cin >> a[i];
    }
}
void readindex(vector<int> &a){
    REP(i, a.size()){
        cin >> a[i];
        a[i]--;
    }
}

Measured memory_bytes: 512
#include <stdio.h>
#include <iostream>
#include <vector>
#include <string>
#include <math.h>
#include <algorithm>
using namespace std;
typedef long long ll;


int main(){
  ll n,t,a,ans,x;
  ans=0;
  double b=9999999;
  cin>>n;
  cin>>t>>a;
  for(int i=0;i<n;i++){
    cin>>x;
    if(b>fabs((t-x*0.006)-a)){
      b=fabs((t-x*0.006)-a);
      ans=i;
    }
  }
  cout<<ans+1<<endl;
}


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

// #undef DEBUG  // Uncomment this line to forcefully disable debug print.
#if DEBUG
template <typename T>
void debug(T value) {
  std::cerr << value;
}
template <typename T, typename... Ts>
void debug(T value, Ts... args) {
  std::cerr << value << ", ";
  debug(args...);
}
#define DBG(...)                              \
  do {                                        \
    cerr << #__VA_ARGS__ << ": ";             \
    debug(__VA_ARGS__);                       \
    cerr << " (L" << __LINE__ << ")" << endl; \
  } while (0)
#else
#define DBG(...)
#endif

#define ALL(x) (x).begin(), (x).end()
#define FOR(i, n) for (auto i : (n))
#define REP(i, n) for (int i = 0; i < (int)(n); ++i)

using ll = long long;

using namespace std;

ll dp[1000001][2];

int main() {
  string N;
  cin >> N;

  dp[0][0] = 0;
  dp[0][1] = 1;
  REP(i, N.size()) {
    int digit = N[i] - '0';
    dp[i + 1][0] = min(dp[i][0] + digit,
                       min(dp[i][1] + (10 - digit),
                           dp[i][1] + 1 + digit));
    dp[i + 1][1] = min(dp[i][0] + 1 + (9 - digit),
                       dp[i][1] + (9 - digit));
    /*
    if (digit == 0) {
      dp[i + 1][1] = min(dp[i + 1][1], dp[i][1] + 1);
    }
    */
    DBG(i, N[i], dp[i + 1][0], dp[i + 1][1]);
  }
  cout << min(dp[N.size()][0], dp[N.size()][1] + 1) << endl;
}


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

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

    int count1 = 0, count2;
    int A;
    for (int i = 1; i <= N; i += 2) {
        count2 = 0;
        A = i;
        for (int j = 3; j < N; j += 2) {
            if (A % j == 0) {
                A /= j;
                count2++;
            }
        }
        if (count2 == 3) {
            count1++;
        }
    }

    cout << count1 << endl;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
"""
Created on Sat Apr 21 21:25:13 2018

@author: Kim
"""

IN = input().split()
A = int(IN[0])
B = int(IN[1])
C = int(IN[2])
X = int(IN[3])
Y = int(IN[4])

#そのまま買う
As = A * X
Bs = B * Y
ALLSUM = As + Bs

#ハーフをどちらかに合わせる
Cmax = 2 * max(X,Y) * C
Cmin = 2 * min(X,Y) * C

#ハーフの場合で小さい方に合わせた時の差分とその額
sabunkosuu = max(X,Y) - min(X,Y)
if X > Y:
    sabungaku = A * sabunkosuu
elif X < Y:
    sabungaku = B * sabunkosuu
else:
    sabungaku = 0

#そしてそれを足した時の額
halfmin = Cmin + sabungaku 

#全部比べる
ANS = min(ALLSUM, Cmax, halfmin)
print(ANS)

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

using namespace std;
#define FOR(i,o,n) for(long long i = o;i<n;i++)
#define oneforall ios::sync_with_stdio(false);cin.tie(0);
#define all(v) (v).begin(),(v).end()
#define ini(...) int __VA_ARGS__; in(__VA_ARGS__)
#define inl(...) long long __VA_ARGS__; in(__VA_ARGS__)
#define ins(...) string __VA_ARGS__; in(__VA_ARGS__)
#define int long long
const long long INF=1e18;
void in(){} template <typename T,class... U> void in(T &t,U &...u){ cin >> t; in(u...);}
void out(){cout << "\n";} template <typename T,class... U> void out(const T &t,const U &...u){ cout << t; if(sizeof...(u)) cout << " "; out(u...);}
typedef vector<int> vi;
typedef vector<long long> vl;
typedef long long ll;
typedef vector<pair<long, long > > vpll;
typedef vector<pair<int, int > > vpii;


int32_t main() {
    oneforall
    oneforall
    oneforall
    oneforall
    oneforall
    oneforall
    oneforall
    oneforall
    oneforall
    oneforall
    oneforall
    oneforall
    oneforall
    oneforall
    
    ini(n);
    ini(n1);
    multiset<int> set1;
    FOR(i,0,n){
        ini(x);
        set1.insert(x);
    }
    FOR(i,0,n1){
        int x1 = *set1.rbegin();
        set1.insert(x1/2);
        set1.erase(set1.find(x1));
    }
    int tmp = 0;
    for(auto v:set1){
        tmp+=v;
    }
    out(tmp);
    
    
    
    
    
    return 0;
}


Measured memory_bytes: 4992
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a),i##formax=(b);i<i##formax;i++)
#define FORR(i,a,b) for(int i=(a),i##formax=(b);i>=i##formax;i--)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define pcnt __builtin_popcount
#define sz(x) (int)(x).size()
#define maxs(x,y) x=max(x,y)
#define mins(x,y) x=min(x,y)
#define show(x) cout<<#x<<" = "<<x<<endl;
#define all(a) (a.begin()),(a.end())
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define perm(c) sort(all(c));for(bool c##p=1;c##p;c##p=next_permutation(all(c)))
#define uniq(v) sort(all(v));v.erase(unique(all(v)), v.end());
#define bit(n) (1LL<<(n))
#define randInt(l,r) (uniform_int_distribution<ll>(l,r)(rnd))
#define randDouble(l,r) (uniform_real_distribution<double>(l,r)(rnd))
#define dout(d) printf("%.12f\n",d)

typedef long long ll;
typedef __int128_t lll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
template<class T>using V=vector<T>;
template<class T>using VV=V<V<T>>;
template<class T,class Y>ostream& operator<<(ostream& o,const pair<T,Y>& p){return o<<"("<<p.fi<<", "<<p.se<<")";}
template<typename A,size_t N,typename T>void Fill(A (&array)[N],const T&v){fill((T*)array,(T*)(array+N),v);}
lll gcd(lll a,lll b,lll &x,lll &y){if(!b){x=1;y=0;return a;}lll d=gcd(b,a%b,y,x);y-=a/b*x;return d;}
ll gcd(ll a,ll b){lll x=0,y=0;return gcd(a,b,x,y);}
ll modPow(lll a,lll n,ll m){if(!a)return a;lll p=1;for(;n>0;n>>=1,a=a*a%m)if(n&1)p=p*a%m;return(ll)p;}
bool isPrime(ll n){if(n<2||n%2==0)return n==2;lll t=n-1,d=t/(t&-t);for(lll a:{2,325,9375,28178,450775,9780504,1795265022})if(a%n){for(t=d,a=modPow(a,t,n);t!=n-1&&a!=1&&a!=n-1;a=a*a%n,t=t*2%n);if(a!=n-1&&t%2==0)return 0;}return 1;}
const int IINF = 1e9+6;
const ll LINF = 1e18;
const int MOD = 1e9+7;
const double PI = acos(-1);
const double EPS = 1e-10;
static random_device rd;
static mt19937 rnd(rd());

const int N = 1e5;
int a, b;
main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> a >> b;
  cout << (a > b*2-2 ? "YES" : "NO") << endl;
}

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

typedef char String[1024];

int main(void)
{
    String str_a, str_b, str_c;
    scanf("%s %s %s", str_a, str_b, str_c);
    
    int a = atoi(str_a);
    int b = atoi(str_b);
    int c = atoi(str_c);
    int count = 0;

    while (a <= b)
    {
        if (c % a == 0)
        {
            count++;
        }
        a++;
    }
    printf("%d\n", count);
    return (0);
}


Measured memory_bytes: 2036
#include<bits/stdc++.h>
using namespace std;
#define int long long 
#define FAST ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);

int32_t main(){
    FAST
    int n,m,k;cin>>n>>m>>k;
    vector<string> v(n);
    for(string &i : v) cin>>i;

    int ans=0;

    for(int i=0;i<(1<<n);i++){
        for(int j=0;j<(1<<m);j++){
            int blacks=0;
            for(int x=0;x<n;x++){
                for(int y=0;y<m;y++){
                    if(((1<<x)&i)||((1<<y)&j)) continue;
                    blacks+=(v[x][y]=='#');
                }
            }
            if(blacks==k) ans++;
        }
    }

    cout<<ans<<"\n";

    return 0;
}

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

const int di[] = {-1, 0, 1, 0};
const int dj[] = {0, -1, 0, 1};

int main(){
  int h, w;
  cin >> h >> w;
  int si, sj;
  cin >> si >> sj;
  int ti, tj;
  cin >> ti >> tj;
  --si, --sj, --ti, --tj;
  vector<string> s(h);
  rep(i, h) cin >> s[i];
  const int INF = 1e9;
  vector<vector<int>> dist(h, vector<int>(w, INF));
  deque<P> q;
  dist[si][sj] = 0;
  q.emplace_back(si, sj);
  while (!q.empty()){
    int i = q.front().first;
    int j = q.front().second;
    int d = dist[i][j];
    q.pop_front();
    if (dist[i][j] != d) continue;
    rep(v, 4){
      int ni = i + di[v], nj = j + dj[v];
      if (ni < 0 || ni >= h || nj < 0 || nj >= w) continue;
      if (s[ni][nj] == '#') continue;
      if (dist[ni][nj] <= d) continue;
      dist[ni][nj] = d;
      q.emplace_front(ni, nj);
    }
    for (int ei = -2; ei <= 2; ++ei){
      for (int ej = -2; ej <= 2; ++ej){
        int ni = i + ei, nj = j + ej;
        if (ni < 0 || ni >= h || nj < 0 || nj >= w) continue;
        if (s[ni][nj] == '#') continue;
        if (dist[ni][nj] <= d+1) continue;
        dist[ni][nj] = d+1;
        q.emplace_back(ni, nj);
      }
    }
  }
  int ans = dist[ti][tj];
  if (ans == INF) ans = -1;
  cout << ans << endl;
  return 0;
}


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

int read(string inp);
int ex(char c);

int main(){
    string inp;
    while(cin >>inp){
        inp += "I";
        cout <<read(inp) <<endl;
    }
    return 0;
}

int read(string inp){
    int sum = 0;
    for(int i = 0; i < (inp.size() - 1); i++){
        int now = ex(inp[i]), next = ex(inp[i + 1]);
        if(now >= next){
            sum += now;
        } else{
            sum += (next - now);
            i++;
        }
    }
    return sum;
}

int ex(char c){
    int ret;
    if(c == 'I'){
        ret = 1;
    } else if(c == 'V'){
        ret = 5;
    } else if(c == 'X'){
        ret = 10;
    } else if(c == 'L'){
        ret = 50; 
    } else if(c == 'C'){
        ret = 100;
    } else if(c == 'D'){
        ret = 500;
    } else if(c == 'M'){
        ret = 1000;
    }
    return ret;
}

Measured memory_bytes: 0
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
int main(){
	int a,b,d,r;
	double f;
	cin>>a>>b;
	d=a/b;
	r=a%b;
	f=(double)a/b;
	cout<<d<<" "<<r<<" ";
	printf("%.8lf\n",f);
}

Measured memory_bytes: 3184
#include <bits/stdc++.h>
#define ll long long
using namespace std;
 
const int MAX = 1e5 + 111;

int n;

int a[MAX];

ll calc(int id, ll sum) {
    ll ans = 0;
    for (int i = id; i < n; ++i) {
        ll cur = sum + a[i];
        //cerr << i << " " << sum << " " << cur << "\n";
        if (sum < 0 && cur > 0) {
            sum = cur; 
            continue;
        }
        if (sum > 0 && cur < 0) {
            sum = cur;
            continue;
        }
        if (cur == 0) {
            if (sum < 0)
                cur = 1;
            else
                cur = -1;
            sum = cur;
            ans++;
            continue;
        }
        if (sum < 0) {
            ans += 1 - cur;
            cur = 1;
        } else {
            ans += cur + 1;
            cur = -1;
        }
        sum = cur;
    }
    return ans;
}

int main() {
#ifdef LOCAL
    freopen("xxx.in", "r", stdin);
    freopen("xxx.out", "w", stdout);    
#endif
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin >> n;
    int id = -1;
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
        if (a[i] != 0 && id == -1)
            id = i;
    }
    if (id == -1) {
        cout << 1 + (n - 1) * 2;
        return 0;
    }
    if (id != 0) {
        ll ans1 = calc(id, -1);
        ll ans2 = calc(id, 1);
        cout << min(ans1, ans2) + 1 + 2 * (id - 1);
    } else {
        ll ans1 = calc(1, 1) + abs(a[0] - 1);
        ll ans2 = calc(1, -1) + abs(a[0] + 1);
        ll ans3 = calc(1, a[0]);
        cout << min(min(ans1, ans2), ans3);
    }
    return 0;
}

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

using namespace std;

#define G getline
#define SZ size()
#define C clear()
#define B begin()
#define F front()
#define T top()
#define E end()
#define EM empty()
#define V vector
#define Q queue
#define DQ deque
#define PQ priority_queue
#define ST stack
#define FI first
#define SE second
#define PI acos(-1)
#define PS push
#define PP pop()
#define PSF push_front
#define PSB push_back
#define PPF pop_front()
#define PPB pop_back()
#define LL long long
#define ULL unsigned long long
#define PII pair<int,int>
#define PSI pair<string,int>
#define PIS pair<int,string>
#define PLI pair<LL,int>
#define PLL pair<LL,LL>
#define MII map<int,int>
#define MSI map<string,int>
#define MIS map<int,string>
#define MLI map<LL,int>
#define FAST() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)





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




const int N=2e5+5;
const LL mod=998244353;

LL cnt[N];
int n,lb[12],rb[12];

void Update(int idx,LL val)
{
    while(idx <= n)
    {
        cnt[idx]=(cnt[idx]+val)%mod;
        idx+=idx & (-idx);
    }
}

LL Query(int idx)
{
    LL ans=0;
    while(idx > 0)
    {
        ans=(ans+cnt[idx])%mod;
        idx-=idx & (-idx);
    }
    return ans;
}

int main()
{
    FAST();
    cnt[1]=1;
    LL i,j,k,l,r,ans,check;
    cin >> n >> k;
    for(i=1;i<=k;i++)cin >> lb[i] >> rb[i];
    for(i=2;i<=n;i++)
    {
        ans=0;
        for(j=1;j<=k;j++)
        {
            r=i-lb[j];
            if(r < 1)continue;
            l=max(1LL,i-rb[j]);
            check=Query(r)-Query(l-1);
            check%=mod;
            if(check < 0)check+=mod;
            ans=(ans+check)%mod;
        }
        Update(i,ans);
    }
    cout << Query(n);
    return 0;
}


Measured memory_bytes: 5196
#include <iostream>
#include <string>
#include <sstream>
#include <utility>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <cmath>
#include <functional>
#include <chrono>
#include <cstring>
#include <bits/stdc++.h>


using namespace std;
typedef long long lint;
typedef vector<int> vi;
typedef pair<int,int> pii;

typedef vector<lint> vl;
typedef pair<lint,lint> pll;

#define mpr make_pair


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

    int h, w, k; cin>>h>>w>>k;
    vector<string> mp(h);
    for (auto &s : mp) cin>>s;
    int res = 0;
    for (int rm = 0; rm < (1<<h); ++rm){
        for (int cm = 0; cm < (1<<w); ++cm){
            int cnt = 0;
            for (int i=0; i<h; ++i){
                for (int j=0; j<w;++j){
                    if (mp[i][j] == '#' && (rm & (1<<i)) && ( cm & (1<<j)) )
                        cnt++;
                }
            }
            if (cnt == k) res++;
        }
    }
    cout<<res;
}


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

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

  // ここにプログラムを追記
  int M8 = (N%100000000-N%10000000)/10000000;
  int M7 = (N%10000000-N%1000000)/1000000;
  int M6 = (N%1000000-N%100000)/100000;
  int M5 = (N%100000-N%10000)/10000;
  int M4 = (N%10000-N%1000)/1000;
  int M3 = (N%1000-N%100)/100;
  int M2 = (N%100-N%10)/10;
  int M1 = N%10;
  int M = M1+M2+M3+M4+M5+M6+M7+M8;
  if (N%M == 0) {
    cout << "Yes" << endl;
  }else {
    cout << "No" << endl;
  }
}


Measured memory_bytes: 256
INF = 10**9

N = int(input())
h = [int(i) for i in input().split()] + [0, 0]

dp = [INF] * 100010
dp[0] = 0

for i in range(N):
    dp[i+1] = min(dp[i+1], dp[i]+abs(h[i+1]-h[i]))
    dp[i+2] = min(dp[i+2], dp[i]+abs(h[i+2]-h[i]))

print(dp[N-1])

Measured memory_bytes: 13928
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <queue>
#include <set>
#include <map>

using namespace std;
typedef long long ll;

struct UnionFind {
  vector<int> data;
  UnionFind(int size) : data(size, -1) { }
  bool unionSet(int x, int y) {
    x = root(x); y = root(y);
    if (x != y) {
      if (data[y] < data[x]) swap(x, y);
      data[x] += data[y]; data[y] = x;
    }
    return x != y;
  }
  bool findSet(int x, int y) {
    return root(x) == root(y);
  }
  int root(int x) {
    return data[x] < 0 ? x : data[x] = root(data[x]);
  }
  int size(int x) {
    return -data[root(x)];
  }
};

struct edge{
    int to, cost;
};

int R, C, N;
map<int, int> mp[200000];
int dist[200000];
int min_d[200000];
int root_min_d[200000];
vector<edge> G[200000];

bool used[200000];
bool ok = true;
const int INF = 1e9;

void dfs(int v, int d){
    used[v] = true;
    dist[v] = d;
    for(edge e : G[v]){
        int to = e.to, cost = e.cost;
        if(used[to]){
            if(dist[to] != d+cost) ok = false;
        }else{
            dfs(to, d+cost);
        }
    }
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setprecision(10) << fixed;
    cin >> R >> C >> N;
    for(int i = 0; i < N; i++){
        int r, c, a;
        cin >> r >> c >> a;
        r--; c--;
        mp[r][c] = a;
    }
    UnionFind uf(C);
    for(int i = 0; i < R; i++){
        int prev_c, prev_a;
        for(auto it = mp[i].begin(); it != mp[i].end(); it++){
            int c = it->first, a = it->second;
            if(it != mp[i].begin()){
                G[prev_c].push_back((edge){c, a-prev_a});
                G[c].push_back((edge){prev_c, prev_a-a});
                uf.unionSet(c, prev_c);
            }
            prev_c = c, prev_a = a;
        }
    }
    for(int i = 0; i < C; i++){
        if(!used[i]){
            dfs(i, 0);
            if(!ok){
                cout << "No" << endl;
                return 0;
            }
        }
    }
    for(int i = 0; i < C; i++) root_min_d[i] = INF;
    for(int i = 0; i < C; i++){
        int r = uf.root(i);
        root_min_d[r] = min(root_min_d[r], dist[i]);
    }
    for(int i = 0; i < R; i++){
        if(mp[i].size() == 0) continue;
        auto it = mp[i].begin();
        int c = it->first;
        int a = it->second;
        int r = uf.root(c);
        // cout << i << ' ' << dist[c] << ' ' << c << ' ' << a << ' ' << root_min_d[r] << ' ' << a-dist[c]+root_min_d[r] << endl;
        if(a-dist[c]+root_min_d[r] < 0){
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
}

Measured memory_bytes: 24960
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(x) (x).begin(),(x).end()
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;}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,k; cin>>n>>k;
    string s;cin>>s;
    vector<pair<char, int>> le;
    // 後の計算用に、先頭と末尾を1にしておく
    int top = 0;
    if(s[0]=='0'){
        le.push_back(make_pair('1', 0));
        top++;
    }
    le.push_back(make_pair(s[0], 1));
    for(int i=1; i<n; i++){
        if(s[i] == le[top].first){
            le[top].second++;
        }else{
            le.push_back(make_pair(s[i], 1));
            top++;
        }
    }
    // 末尾も1にしておく
    if(le[le.size()-1].first == '0') le.push_back(make_pair('1', 0));
    int le_n = le.size();

    // 累積和作戦
    vector<int> sums(le_n+1, 0);
    for(int i=0; i<le_n; i++) sums[i+1] = sums[i]+le[i].second;

    int ans = 0;
    // 区間長k + (k+1)=2k+1の中で最大を求める
    for(int left=0; left<le_n; left+=2){ //偶数番スタートのみ考えればよい
        // cout<<left<<" "<<right<<endl;
        int right = left + 2*k+1;
        if(right >= sums.size()) right = sums.size()-1;
        ans = max(ans, sums[right]-sums[left]); 
    }
    cout<<ans<<endl;
}

// abc124_d

Measured memory_bytes: 1604