akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<vector>
using namespace std;
int main(){
    int N;
    cin >> N;
    vector<int> A(N);
    int MAX1=1,MAX2=1;
    for(int i=0;i<N;i++){
        int tmp;
        cin >> A.at(i);
        if(A.at(i)>MAX1){
            tmp = MAX1;
            MAX1 = A.at(i);
            MAX2 = tmp;
        }
        else if(A.at(i)>MAX2) MAX2 = A.at(i);
    }
    for(int i=0;i<N;i++){
        if(A.at(i)==MAX1) cout << MAX2 << endl;
        else cout << MAX1 << endl;
    }
    return 0;
}

Measured memory_bytes: 2432
N=int(input())
A=list(map(int, input().split()))
Ma,ma=max(A),min(A)
b=Ma-ma<=1
if b:
    if Ma==ma:
        b=N==Ma+1 or N//2>=Ma
    else:
        Mc=len(list(a for a in A if a==Ma))
        mc=N-Mc
        b=mc+1<=Ma<=mc+Mc//2
print("YNeos"[not b::2])

Measured memory_bytes: 14092
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

using namespace std;
using ll = long long;
using vpii = vector<pair<int, int>>;
using vpll = vector<pair<ll, ll>>;
// ceil() 切り上げ, floor() 切り捨て
// next_permutation(all(x))

int		main(void)
{
	int N, M;
	cin >> N >> M;
	vector<int> L(M);
	vector<int> R(M);
	for (int i = 0; i < M; i++)
		cin >> L[i] >> R[i];
	sort(rall(L));
	sort(all(R));
	int ans = R[0] - L[0] + 1;
	if (ans < 0)
		cout << 0 << endl;
	else
		cout << ans << endl;
}



Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <string>
typedef long long ll;
using namespace std;

int pre[105];
int in[105];
int post[105];

void rebuild(int preL, int inL, int postL, int N)
{
	if (N == 0)
		return;
	post[postL + N - 1] = pre[preL];
	if (N > 1)
	{
		int i;
		for (i = 0; i < N; ++i)
		{
			if (pre[preL] == in[inL + i])
				break;
		}
		rebuild(preL + 1, inL, postL, i);
		rebuild(preL + i + 1, inL + i + 1, postL + i, N - i - 1);
	}
}


int main()
{
	int n;
	cin >> n;
	for (int i = 0; i < n; ++i)
		cin >> pre[i];
	for (int i = 0; i < n; ++i)
		cin >> in[i];
	rebuild(0, 0, 0, n);
	for (int i = 0; i < n - 1; ++i)
		cout << post[i] << ' ';
	cout << post[n - 1] << endl;
	return 0;
}

Measured memory_bytes: 3096
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws Exception {

	BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
	String str = br.readLine();

	int x = Integer.parseInt(str);
        int h, m, s;

        h = x / 3600;
        m = x % 3600 / 60;
        s = x % 60;

        System.out.println(h + ":" + m +":" + s);
	}
}

Measured memory_bytes: 24420
#include <bits/stdc++.h>
using namespace std;
int main() {
    int n, w, i, j;
    long v, wt;
    cin >> n >> w >> wt >> v;
    long long dp[n][w+1];
    for(i=0;i<n;++i) for(j=0;j<=w;++j) dp[i][j] = 0;
    for(j=wt;j<=w;++j) dp[0][j] = v;
    for(i=1;i<n;++i) {
        cin >> wt >> v;
        for(j=0;j<=w;++j) {
            if(j>=wt) dp[i][j] = max(dp[i-1][j-wt]+v, dp[i-1][j]);
            else dp[i][j] = dp[i-1][j];
        }
    }
    cout << dp[n-1][w];
    return 0;
}

Measured memory_bytes: 81556
N = int(input())
W = list(map(int,input().split()))

diff = 100 * N

for i in range(0,N - 1):
	left = sum(j for j in W[0:i + 1])
	right = sum(j for j in W[i + 1:N])
	if(diff>abs(left - right)):
		diff = abs(left - right)
	else:
		break

print(diff)

Measured memory_bytes: 3060
package main

import "fmt"

func abs(x int) int {
	if x < 0 {
		return -x
	}
	return x
}
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func main() {
	var n int
	fmt.Scan(&n)
	xs := make([]int, n)
	ys := make([]int, n)
	hs := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&xs[i], &ys[i], &hs[i])
	}

	check := func(cx, cy int) int {
		ch := -1
		for i := 0; i < n; i++ {
			if hs[i] != 0 {
				ch = hs[i] + abs(xs[i]-cx) + abs(ys[i]-cy)
			}
		}

		for i := 0; i < n; i++ {
			h := max(ch-abs(xs[i]-cx)-abs(ys[i]-cy), 0)
			if h != hs[i] {
				return -1
			}
		}
		return ch
	}

	for cx := 0; cx <= 100; cx++ {
		for cy := 0; cy <= 100; cy++ {
			ch := check(cx, cy)
			if ch != -1 {
				fmt.Println(cx, cy, ch)
			}
		}
	}
}


Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <set>
using namespace std;

int main(){
  int N,M;
  set<int> ball_prob={1};
  int from,to;
  cin >> N >> M;
  vector<int> ball_num(N,1);

  for(int i=0;i<M;i++){
    cin >> from >> to;
    auto it = ball_prob.find(from);
    if(it!=ball_prob.end()){
      ball_prob.insert(to);
    }
    ball_num.at(from-1)--;
    ball_num.at(to-1)++;
    if(ball_num.at(from-1)==0){
      auto it = ball_prob.find(from);
      if(it!=ball_prob.end()){
        ball_prob.erase(from);
      }
    }
  }
  cout << ball_prob.size() << endl;
}

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

using namespace std;

int i,j,k,m,n;

int main()
{
  cin >> i>>j>>k;
  
  m=i+j+k;
  if(m>=22) cout<<"bust";
  else cout <<"win";
  
}

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

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int k;
  cin>>k;
  int ans = 0;
  if( k%2 == 0 ){ ans = (k/2) * (k/2) ;}
  else{ ans = (k/2)*(k/2 + 1 ); }
  cout<<ans<<"\n";
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<vector>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<time.h>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double EPS=1e-10;
const int inf=1e8;
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
int ma,n,m;
vvi out;
vi d;
void func(int a){
	if(a==n){
		vvi	tmp=out;
		rep(i,n)if(d[i])rep(j,m)tmp[i][j]^=1;
		int sum=0;
		rep(i,m){
			int co=0;
			rep(j,n)if(tmp[j][i])co++;
			sum+=max(co,n-co);
		}
		ma=max(ma,sum);
		return;
	}
	d[a]=1;
	func(a+1);
	d[a]=0;
	func(a+1);
}
int main(){
	while(cin>>n>>m,n+m){
		ma=-1;
		d=vector<int>(n);
		vvi in(n,vi(m));
		rep(i,n)rep(j,m)cin>>in[i][j];
		out=in;
		func(0);
		cout<<ma<<endl;
	}
}

Measured memory_bytes: 2288
#include <bits/stdc++.h>
#define nl ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define ll long long
#define all(v) (v).begin(), (v).end()
#define allr(v) (v).rbegin(), (v).rend()
#define pi acos(-1)

using namespace std;

int main() {
    nl // Bazzi - Paradise

    string s; cin >> s;

    for(int i=0; s[i]; ++i) {
        if(i == 3) s[i] = '8';
    }
    cout << s;
    return 0;
}

Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
#ifndef STOP_DEBUG
#define debug(...)\
    do { cerr << boolalpha << "[" << #__VA_ARGS__ << "]:";\
    debug_cerr(__VA_ARGS__); cerr << noboolalpha; } while (0)
#else
#define debug(...)
#endif
void debug_cerr(){ cerr << '\n'; }
template<class Head, class... Tail>
void debug_cerr(Head head, Tail... tail){
  cerr << ' ' << head;
  debug_cerr(tail...);
}
void chmax(lint &a, lint b) { if (a < b) a = b; }
void chmin(lint &a, lint b) { if (a > b) a = b; }
struct IoSetup{
    IoSetup(){
      ios::sync_with_stdio(false);
      cin.tie(nullptr);
      cout << fixed << setprecision(20);
      cerr << fixed << setprecision(20);
    }
} iosetup;

int main() {
  map<string, int> mp;
  mp["SUN"] = 7;
  mp["MON"] = 6;
  mp["TUE"] = 5;
  mp["WED"] = 4;
  mp["THU"] = 3;
  mp["FRI"] = 2;
  mp["SAT"] = 1;
  string s;
  cin >> s;
  cout << mp.at(s) << '\n';
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int A1, A2, A3;
    cin >> A1 >> A2 >> A3;
    puts(A1+A2+A3 > 21 ? "bust" : "win");
    return 0;
}


Measured memory_bytes: 256
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 998244353
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)
def pe(s): return print(str(s), file=sys.stderr)
def JA(a, sep): return sep.join(map(str, a))


def main():
    n = I()
    a = LI()
    s = sum(a)
    t = 0
    r = s
    for c in a:
        t += c
        s -= c
        u = abs(t-s)
        if r > u:
            r = u

    return r


print(main())



Measured memory_bytes: 5188
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define rep(i,n) for (int i=0; i<(n); i++)
#define reps(i,s,n) for (int i=(s); i<(n); i++)
#define rep1(i,n) for (int i=1; i<=(n); i++)
#define repr(i,s,n) for (int i=(s)-1; i>=(n); i--)
#define print(a) cout << (a) << endl
#define all(v) v.begin(), v.end()
#define rsort(v) sort(v.rbegin(), v.rend())


int main() {
  int N;
  cin >> N;
  ll A[N+1];
  A[0] = 0;
  rep1(i,N) {
    cin >> A[i];
    A[i] += A[i-1];
  }
  int l = 1, r = 3;
  ll ans = 1e9;
  reps(i,2,N-1) {
    while (l<i-1 && abs(2*A[l]-A[i])>abs(2*A[l+1]-A[i])) {
      l++;
    }
    while (r<N-1 && abs(2*A[r]-A[N]-A[i])>abs(2*A[r+1]-A[N]-A[i])) {
      r++;
    }
    ll P, Q, R, S, tmp;
    P = A[l];
    Q = A[i]-A[l];
    R = A[r]-A[i];
    S = A[N]-A[r];
    tmp = max(max(P,Q),max(R,S)) - min(min(P,Q),min(R,S));
    ans = min(ans, tmp);
    if (r == i+1)
      r++;
  }
  print(ans);
  return 0;
}

Measured memory_bytes: 5152
#include <iostream>
#include <algorithm>
#include <map>
using namespace std;
typedef long long ll;
ll N,K,t,d;
pair<ll,int> A[100010];
int main(){
	cin >> N >> K;
	for(int i=1;i<=N;i++){
		cin >> t >> d;
		A[i] = {d,t};
	}
	map<int,ll> m;
	sort(A+1,A+N+1);
	ll ans = 0,sum = 0,r = 0;
	for(int i=N;i>=1;i--){
		if(i>=N-K+1){
			m[A[i].second]++;
			sum += A[i].first;
			if(i==N-K+1){
				ll s = m.size();
				ans = sum + s*s;
				r = N-K+1;
			}
		}else{
			if(!m.count(A[i].second)){
				m[A[i].second]++;
				while(r<=N && m[A[r].second]==1) r++;
				if(r==N+1) break;
				sum += A[i].first-A[r].first;
				m[A[r].second]--; r++;
				ll s = m.size();
				ans = max(ans,sum+s*s);
			}
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 5760
#include <bits/stdc++.h>
#define ll long long
#define PB push_back
#define MP make_pair

#define REP(i,n) for(i=0;i<(n);++i)
#define FOR(i,l,h) for(i=(l);i<=(h);++i)
#define FORD(i,h,l) for(i=(h);i>=(l);--i)

#define max(a,b) a>b?a:b
#define min(a,b) a>b?b:a
using namespace std;

//*********************************
//******problem F DP contest LCS ***

int main(){
    ios_base::sync_with_stdio(false);
  	cin.tie(NULL);
    cout.tie(NULL);
    string s1,s2;
    cin>>s1>>s2;
   ll int m,n;
    n = s1.length();
    m = s2.length();
    vector<vector<int> > dp(n+2, vector<int> (m+2, 0));
  //  memset(dp,0,sizeof(dp));
    for(ll int i=0;i<=n;i++){
        for(ll int j=0;j<=m;j++){
            if(i==0 || j==0)dp[i][j] = 0;
            else if(s1[i-1] == s2[j-1]){
                 dp[i][j] = dp[i-1][j-1]+1;
                 //ans += s1[i];
             }
            else
                dp[i][j] = max(dp[i-1][j] , dp[i][j-1]);
        }
    }
    int lclen =dp[n][m];
  string ans(lclen,'.');
    ll int i=n,j=m;
    while(i>0 && j>0){
        if(s1[i-1] == s2[j-1]) {
            ans[lclen-1] =s1[i-1];
            i--;j--;lclen--;
        }
        else if(dp[i-1][j] < dp[i][j-1]) j--;
        else
             i--;
    }
    //cout<<dp[n][m]<<"\n";
   // reverse(ans.begin(),ans.end());
    cout<<ans;
    return 0;
}


Measured memory_bytes: 35584
n,k=map(int, input().split())
s=input()
if s[k-1]=="A":
    s=s[:k-1]+"a"+s[k:]
elif s[k-1]=="B":
    s=s[:k-1]+"b"+s[k:]
else:
    s=s[:k-1]+"c"+s[k:]
print(s)   

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll mod = 1000000007;

ll r(ll x, ll y) {
  if (y == 0) return 1;
  else if (y % 2 == 0) return r(x, y/2) * r(x, y/2) % mod;
  else return x * r(x, (y-1)/2) % mod * r(x, (y-1)/2) % mod;
}

int main() {
  int n, a, b, c;
  cin >> n >> a >> b >> c;
  vector<ll> abc(3);
  abc[0] = a;
  abc[1] = b;
  abc[2] = c;
  bool F = 1;
  vector<string> ABC(n);
  for (int i = 0; i< n; i++) {
    cin >> ABC[i];
  }
  vector<char> ans(0);
  for (int i = 0; i< n ;i++) {
    int l = ABC[i].at(0) - 65;
    int r = ABC[i].at(1) - 65;
    
    if (abc[l] == 1 && abc[r] == 1 && i < n - 1) {
      int ll = ABC[i+1].at(0) - 65;
      int rr = ABC[i+1].at(1) - 65;
      if (l == ll || l == rr) {
        abc[l]++;
        abc[r]--;
        ans.push_back(ABC[i].at(0));
      }
      else {
        abc[l]--;
        abc[r]++;
        ans.push_back(ABC[i].at(1));
      }
    }
    else if (abc[l] == 0 && abc[r] == 0) {
      cout << "No" <<endl;
      F = 0;
      break;
    }
    else {
      if (abc[l] >= abc[r]) {
        abc[l]--;
        abc[r]++;
        ans.push_back(ABC[i].at(1));
      }
      else {
        abc[l]++;
        abc[r]--;
        ans.push_back(ABC[i].at(0));
      }
    }
  }
  if (F) {
    cout << "Yes" <<endl; 
    for (char x : ans) {
      cout << x <<endl;
    }
  }
}

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

using namespace std;

bool palindromo_Fuerte(string s){
    for(int i=0, j=s.size()-1; i<=j; i++,j--){
        if(s[i] != s[j]){
            return false;
        }
    }
    for(int i=0, j=(s.size()-1)/2-1; i<=j;i++, j--){
        if(s[i] != s[j]){
            return false;
        }
    }
    for(int i=(s.size()+3)/2-1, j=s.size()-1; i<=j; i++,j--){
        if(s[i] != s[j]){
            return false;
        }
    }
    return true;
}

int main(){
    string s; cin >> s;
    if(palindromo_Fuerte(s)){
        cout << "Yes";
    }else{
        cout << "No";
    }
    return 0;
}

Measured memory_bytes: 256
N=int(input())
An=list(map(int,input().split()))

abs_total = 0
n_count = 0
min_abs_a = 10**9
for A in An:
    a = abs(A)
    abs_total += a
    if a < min_abs_a:
        min_abs_a = a
    if A <= 0:
        n_count += 1
if n_count%2 == 1:
    abs_total -= min_abs_a*2
print(abs_total)


Measured memory_bytes: 15020
#include <iostream>
#include <math.h>
#include <string>
using namespace std;

int main()
{
    string s ;
    cin >> s ;
    if (s[0]==s[1] |s[1]==s[2] |s[2]==s[3]) {
        cout << "Bad" ;
    }
    else {
        cout << "Good" ;
    }
    return 0;
}


Measured memory_bytes: 3592
require "set"

class Priority_queue
  attr_accessor :a
  def initialize(max)
    @h = 0
    @a = Array.new(max+1)
    @INF = 1<<30
  end
  
  def max_heapify(i)
    l = 2*i
    r = 2*i+1
    
    if l<=@h && @a[l][0]>@a[i][0]
      largest = l
    else
      largest = i
    end
    
    if r<=@h && @a[r][0] > @a[largest][0]
      largest = r
    end
    
    if largest != i
      @a[i], @a[largest] = @a[largest], @a[i]
      max_heapify(largest)
    end
  end
  
  def extract
    if @h < 1
      return [-@INF]
    end
    
    maxv = @a[1]
    @a[1] = @a[@h]
    @h-=1
    max_heapify(1)
    return maxv
  end
  
  def increase_key(i, key)
    if key[0] < @a[i][0]
      return
    end
    
    @a[i] = key
    
    while i>1 && @a[i/2][0] < @a[i][0]
      @a[i], @a[i/2] = @a[i/2], @a[i]
      i = i/2
    end
  end
  
  def insert(key)
    @h+=1
    @a[@h] = [-@INF]
    increase_key(@h, key)
    
    return key.to_s
  end
end

q = Priority_queue.new(3000*3)
memo = Set.new

xmax,ymax,zmax,k = gets.split.map(&:to_i)
a = gets.split.map(&:to_i).sort.reverse
b = gets.split.map(&:to_i).sort.reverse
c = gets.split.map(&:to_i).sort.reverse

q.insert([a[0]+b[0]+c[0], 0, 0, 0])
memo.add([a[0]+b[0]+c[0], 0, 0, 0])

[k,xmax*ymax*zmax].min.times do
  #p q.a
  sum,s,t,u = q.extract
  p sum
  #p [sum,s,t,u]

  if s+1<xmax
    if !memo.include?(key = [a[s+1]+b[t]+c[u],s+1,t,u])
      q.insert(key)
      memo.add(key)
    end
  end
  
  if t+1<ymax
    if !memo.include?(key = [a[s]+b[t+1]+c[u],s,t+1,u])
      q.insert(key)
      memo.add(key)
    end
  end
  
  if u+1<zmax
    if !memo.include?(key = [a[s]+b[t]+c[u+1],s,t,u+1])
      q.insert(key)
      memo.add(key)
    end
  end
end


Measured memory_bytes: 3448
#include<bits/stdc++.h>
using namespace std;
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	long long n,k;
	cin >> n >>k;
	long long heights[n];
	for(long long i = 0; i<n; i++)
	{
		cin >> heights[i];
	}
	long long dp[n];
	for(int i = 0; i<n; i++)
	{
		dp[i] = INT_MAX;
	}
	dp[0] = 0;
	for(long long i = 1; i<n; i++)
	{
		for(long long j = 1; j<=k; j++)
		{
			if(i - j < 0)
			{
				break;
			}
			dp[i] = min(dp[i-j] + abs(heights[i] - heights[i-j]), dp[i]);
		}
	}
	cout << dp[n-1];
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef pair<ll,ll> pll;
const ll mod=1e9+7;
//const ll mod=998244353;
const ll inf=1LL<<61;

int main() {
  ll n,k;
  cin >> n >> k;
  vec a(n);
  for(ll i=0;i<n;i++) cin >> a[i];
  for(ll i=k;i<n;i++) {
    if(a[i]>a[i-k]) cout << "Yes" << endl;
    else cout << "No" << endl;
  }
}

Measured memory_bytes: 4840
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>

using namespace std;

typedef long long LL;
typedef pair<int, int> P;
const int MAXN = 1e5 + 5;

int n;

inline LL lcm(LL a, LL b) {
  return a / __gcd(a, b) * b;
}

int main() {
  while (~scanf("%d", &n)) {
    LL ans = 1, x;
    for (int i = 0; i < n; ++i) {
      cin >> x;
      ans = lcm(ans, x);
    }
    cout << ans << endl;
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
const double eps = 1e-10;
const int MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1ll<<50;
template<typename T>
void printv(const vector<T>& s) {
  for(int i=0;i<(int)(s.size());++i) {
    cout << s[i];
    if(i == (int)(s.size())-1) cout << endl;
    else cout << " ";
  }
}
int main() {
  cin.tie(0);
  cout << fixed << setprecision(10);
  int n; cin >> n;
  vector<int> a(n);
  for(int i=0;i<n;++i) {
    cin >> a[i];
  }
  ll now = -2*INF;
  ll cnt = 0;
  for(int i=n-1;i>=0;--i) {
    if(a[i] - i > 0 || now > a[i] - i) {
      cout << -1 << endl;
      return 0;
    } else if(now < a[i] - i) {
      now = a[i] - i;
      cnt += a[i];
    }
  }
  cout << cnt << endl;
}


Measured memory_bytes: 1024
x1,y1,x2,y2 = map(int,input().split())

#点2を平行移動
x2b = x2 - x1
y2b = y2 - y1

#点2bを90度回転
x4b = -y2b
y4b = x2b

#点2bを平行移動して点2にする
x4 = x4b + x1
y4 = y4b + y1

#2bと4bを足し合わせて点3bを求める
x3b = x2b + x4b
y3b = y2b + y4b
#点3bを点3に平行移動
x3 = x3b + x1
y3 = y3b + y1

print(x3,y3,x4,y4)

Measured memory_bytes: 3060
a = map(int, raw_input().split())
N = a[0]
Y = a[1]
x = y = z = 0
z = N
while(1):
    if 10000*x+5000*y+1000*z == Y:
        print x,y,z
        break
    else:
        if z > 0:
            y += 1
            z -= 1
        elif y > 0:
            x += 1
            y = 0
            z =	N - x
        else:
            print -1, -1, -1
            break

Measured memory_bytes: 2568
#include<bits/stdc++.h>
using namespace std;
int main() {
	int a,b,c,x;
	cin >>a>>b>>c>>x;
    int ans=0;

	for(int i=0;i<=a;i++){
        for(int j=0;j<=b;j++){
            for(int k=0;k<=c;k++){
                if(x==500*i+100*j+50*k){
                    ans++;
                }
            }
        }
    }


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


Measured memory_bytes: 256
# coding: utf-8
import re
import math
#import numpy as np

mod=int(10**9+7)

#main
N=int(input())
P=list(map(int,input().split()))
min_=mod
ans=0
for a in P:
    if min_>=a:
        min_=a
        ans+=1
print(ans)

Measured memory_bytes: 75344
#include <bits/stdc++.h>
using namespace std;
int main(void){
    
    string s="";
    char t[100009];
    int j=0;
    
    cin >> s;
    
    for(int i=0; i<=100009; i++){
        
        if(i>=s.size()){
            
            break;
            
        }
        
        if(i%2==0){
            
            j = i / 2;
            t[j] = s.at(i);
            
        }
        
    }
    
    cout << t << endl;
    
    return 0;
    
}

Measured memory_bytes: 512
n,k=map(int,input().split())
x = list(map(int,input().split()))

import bisect

zero_index = bisect.bisect_left(x,0)
start_index = max(0,zero_index-k)
x = x[start_index:zero_index+k]

answer = (x[-1]-x[0])*k
for i in range(len(x)-k+1):
  if x[i+k-1]*x[i]>0:
    answer = min(answer,max(abs(x[i+k-1]),abs(x[i]))) 
  else:
    answer = min(answer,min(abs(x[i+k-1]),abs(x[i]))*2+max(abs(x[i+k-1]),abs(x[i])))

print(answer)

Measured memory_bytes: 14128
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
 
int main(){
  int a, b;
  char x;
  cin >> a >> x >> b;
  if(x == '+')cout << a+b << endl;
  else{cout << a-b << endl;}
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef  long long ll;
using vll=vector<ll>;
using vvll=vector<vll>;
using vi=vector<int>;
using vvi=vector<vector<int>>;
using vb=vector<bool>;
using pii=pair<int,int>;
using vpii=vector<pair<int,int>>;
using plli=pair<ll,int>;
using vplli=vector<pair<ll,int>>;
using pllll=pair<ll,ll>;
using vpllll=vector<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;}

//pow(llpow,modpow)
template<class T> ll llpow(ll x,T n){ll ans=1;if(x==0)ans=0;while(n){if(n&1)ans*=x;x*=x;n>>=1;}return ans;}
long long modpow(long long a, long long n, long long mod) {long long res = 1;while (n > 0) {if (n & 1) res = res * a % mod;a = a * a % mod;n >>= 1;}return res;}
//最大公約数
template<class T> inline T gcd(T x,T y){if(y==0)return x; else {return gcd(y,x%y);}}
//最小公倍数
template<class T> inline T lcm(T x,T y){return x/gcd(x,y)*y;}
//逆元
long long modinv(long long a, long long m) {long long b = m, u = 1, v = 0;while (b) {long long t = a / b;a -= t * b; swap(a, b);u -= t * v; swap(u, v);}u %= m;if (u < 0) u += m;return u;}

#define rep(i, begin_i, end_i) for (ll i = (ll)begin_i; i < (ll)end_i; i++)
//試験導入
#define irep(i, end_i, begin_i) for (ll i = (ll)begin_i-1; i >= (ll)end_i; i--)

long long INF = 1LL<<60;
int main( ){
    int n,k;
    cin>>n>>k;
    vi p(n);
    rep(i,0,n)cin>>p[i];
    sort(p.begin(),p.end());
    ll sum=0;
    rep(i,0,k)sum+=p[i];
    cout<<sum<<endl;
    return 0;
}




Measured memory_bytes: 3632
#include <bits/stdc++.h>
#include <string>
#include <vector>

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

int main() {
    double ans, N;
    cin >> N;
    ans = (fmod(N,2)==0) ? (N/2)/N : ((N/2)+0.5)/N;
    cout << ans;
}

Measured memory_bytes: 256
# include <bits/stdc++.h>
# define ll long long
using namespace std;
const ll N = 3005, mod = 1e9 + 7;
double dp[N][N], p[N], ans;
int main(){
    int n;
    cin >> n;
    for(int i = 1; i <= n; i++){
        cin >> p[i];
    }
    dp[0][0] = 1;
    for(int i = 1; i <= n; i++){
        for(int j = 0; j <= n; j ++){
            if(j != 0)dp[i][j] = dp[i - 1][j - 1] * p[i];
            dp[i][j] += dp[i - 1][j] * (1 - p[i]);
        }
    }
    for(int i = n / 2 + 1; i <= n; i++){
        ans += dp[n][i];
    }
    cout << setprecision(12) << ans << endl; 
}   

Measured memory_bytes: 70656
import java.util.Scanner;
import java.math.*;
 
public class Main {
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    BigInteger A = new BigInteger(sc.nextLine());
    BigInteger B = new BigInteger(sc.nextLine());
    BigInteger C = A.subtract(B);
    int a = C.signum();
    if(a == 1){
    	System.out.println("GREATER");
    }else if(a == -1){
    	System.out.println("LESS");
    }else if(a == 0){
    	System.out.println("EQUAL");
    }
  }
}

Measured memory_bytes: 23380
#include <iostream>

typedef long long ll;

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

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

using namespace std;

int main(void){

  int n;
  cin >> n;
  n--;
  long long rqT[n], stT[n], frqT[n];
  REP(i,n){
    cin >> rqT[i] >> stT[i] >> frqT[i];
  }

  long long ans = 0;
  REP(i,n){
    ans = rqT[i] + stT[i];
    FOR(j,i+1,n){
      long long waitTime = stT[j] - ans;
      if(waitTime > 0){
        ans += waitTime;
      }else{
        long long  t = frqT[j] - (ans % frqT[j]);
        if(ans % frqT[j] != 0){
          ans += t;
        }
      }
      ans += rqT[j];
    }
    cout << ans << endl;
  }

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define MP make_pair
#define PII pair<int, int>
#define PLL pair<ll, ll>
#define PLI pair<ll, int>
#define PIL pair<int, ll>
#define STR string
#define Fst first
#define Snd second
#define SHN 1e9
#define LSHN 1e18
using namespace std;
int x,y;
int main()
{
	cin >>x>>y;
	if (x<y) for (int i=0;i<y;i++) cout <<x;
	else for (int i=0;i<x;i++) cout <<y;
	return 0; 
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main() {
  string s, t;
  cin >> s >> t;
  int ans = 0;
  for (int i = 0; i < 3; ++i) {
    ans += (s.at(i) == t.at(i));
  }
  cout << ans << endl;
  return 0;
}

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

int by[300][3];
int cost[300];
int N, M;

int dp(int k) {
  int maxi = -1;
  int value[M+1];
  fill(value, value+M+1, 0);

  for(int i = 0; i < N; i++) {
    for(int j = cost[i]; j <= M; j++) {
      value[j] = max(value[j], by[i][k] + value[j-cost[i]]);
      maxi = max(value[j], maxi);
    }
  }
  return maxi;
}

main() {
  while(1) {
    cin >> N >> M;
    if(cin.eof()) break;
    for(int i = 0; i < N; i++) {
      string dumy;
      getchar();
      getline(cin, dumy);
      cin >> cost[i] >> by[i][0] >> by[i][1] >> by[i][2];
    }

    int maxi = 0;
    for(int k = 0; k < 3; k++) {
      maxi = max(maxi, dp(k));
    }
    cout << maxi << endl;
  }
}

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

#define FOR(i, j, k, in) for (int i=j ; i<k ; i+=in)
#define RFOR(i, j, k, in) for (int i=j ; i>=k ; i-=in)
#define REP(i, j) FOR(i, 0, j, 1)
#define RREP(i, j) RFOR(i, j, 0, 1)

#define INF (int)1e9
#define PI 3.1415926535897932384626433832795
#define MOD 1000000007
#define endl "\n"

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<string, string> pss;
typedef map<int, int> mii;

void solve(ll test_case)
{
  int n,k;
  cin>>n>>k;
  vi arr(n);
  int ans=0;
  for(int i=0;i<n;i++)
    cin>>arr[i];
  sort(arr.begin(),arr.end());
  for(int i=0;i<k;i++){
    ans+=arr[i];
  }
  cout<<ans;


}

int main()
{

//#ifndef ONLINE_JUDGE
//    freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdout);
//#endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll t=1, t1 = 0;
    //cin >> t;
    while (t1 < t)
    {
        solve(t1 + 1);
        t1++;
    }
 return 0;
}


Measured memory_bytes: 3660
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<algorithm>
using namespace std;
char a, b;
int main()
{
	scanf("%c %c", &a, &b);
	if(a == 'H')
	{
		if(b == 'H')printf("H\n");
		else printf("D\n");
	}
	else
	{
		if(b == 'H')printf("D\n");
		else printf("H\n");
	}
	return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<vector>
#include<algorithm>
#include<iterator>
#include<cstdint>
using namespace std;

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

        vector<int_fast32_t> a;
        a.reserve(n);
        copy_n(istream_iterator<int_fast32_t>{cin}, n, back_inserter(a));

        nth_element(a.begin(), a.end()-1, a.end());
        int_fast32_t ai = *(a.end()-1);

        vector<int_fast32_t> a_tmp ( a.begin(),a.end()-1 );
        vector<int_fast32_t>::iterator a_tmp_iter;
        for_each(a_tmp.begin(), a_tmp.end(), [ai](int_fast32_t& x){ x = min(x,ai-x); });
        a_tmp_iter = max_element(a_tmp.begin(), a_tmp.end());
        int_fast32_t aj = a[a_tmp_iter - a_tmp.begin()];

        cout << ai << ' ' << aj << endl;

        return 0;
}


Measured memory_bytes: 1792
def input_multiple_number():
    return map(int, input().split())

def input_multiple_number_as_list():
    return list(map(int, input().split()))


K ,N = input_multiple_number()
listA = input_multiple_number_as_list()

# listA[0] += listA[-1]
# listA[-1] = 0

diffy=[0]*(len(listA))

bif = 0
for d in range(len(diffy)):
	diffy[d] = listA[d]-bif
	bif = listA[d]
diffy[0] += (K-listA[-1])

maxx = 0
for a in diffy:
	maxx = max(a,maxx)

print(K-maxx)

Measured memory_bytes: 26444
n=int(input())
c=[0]*(n-1)
s=[0]*(n-1)
f=[0]*(n-1)
for i in range(n-1):c[i],s[i],f[i]=map(int,input().split())
for i in range(n-1):
    ans=s[i]+c[i]
    for j in range(i+1,n-1):
        ans=max(s[j],f[j]*((ans+f[j]-1)//f[j]))+c[j]
    print(ans)
print(0)

Measured memory_bytes: 3188
#include <stdio.h>

int main()
{
    int max[4] = {0};
    int i, j, t;

    for ( i = 0; i < 10; i++ )
    {
	scanf( "%d", &t );

	for ( j = 2; j >= 0; j-- )
	{
	    if ( max[j] < t )
	    {
		max[j+1] = max[j];
		max[j] = t;
	    }
	}
    }

    for ( i = 0; i < 3; i++ )
    {
	printf( "%d\n", max[i] );
    }

    return 0;
}

Measured memory_bytes: 600
#include <iostream>
#include <vector>
#include <stdio.h>

#include <iomanip>

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

using ll = long long;
using namespace std;

double rec(int a, int b, int c, const int& N, std::vector<std::vector<std::vector<double>>>& dp) {
 
	if (dp[a][b][c] != 0) return dp[a][b][c];
	if (a == 0 && b == 0 && c == 0) return 0;
	double su = a + b + c; // 残りの枚数
	double res = 1.0 * (double)N / su;
	if (a > 0) res += rec(a - 1, b + 1, c, N, dp) * (a / su);
	if (b > 0) res += rec(a, b - 1, c + 1, N, dp) * (b / su);
	if (c > 0) res += rec(a, b, c - 1, N, dp) *(c / su);
	return dp[a][b][c] = res;
}
void solve() {
  int N;
	cin >> N;
  std::vector<std::vector<std::vector<double>>> dp(305, std::vector<std::vector<double>>(305, std::vector<double>(305, 0)));
  std::vector<int> a(3, 0);
	for (size_t i = 0; i < N; i++)
	{
		int b;
		cin >> b;
		if (b == 0) continue;
		a[3 - b]++;
	}
	cout << fixed << setprecision(10) << rec(a[0], a[1], a[2], N, dp) << endl;
}
int main() {
  solve();
}


Measured memory_bytes: 225664
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <set>
#include <unordered_map>

int main()
{
    int N;
    std::cin >> N;
    std::string S;
    std::cin >> S;

    int ans = 0;
    for (int i = 1; i < N; i++)
    {
        if (S[i] == 'E')ans++;
    }
    int cnt = ans;
    for (int i = 1; i < N; i++)
    {
        if (S[i] == 'E')cnt--;
        if (S[i - 1] == 'W') cnt++;
        ans = std::min(cnt, ans);
    }


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

Measured memory_bytes: 900
import math

a,b,c = map(int,input().split())
S = a * b * math.sin(math.radians(c)) / 2
L = a + b + math.sqrt(a*a+b*b-2*a*b*math.cos(math.radians(c)))
h = S / a * 2
print(S)
print(L)
print(h)


Measured memory_bytes: 5704
#include <bits/stdc++.h>
#include <boost/range/irange.hpp>
#include <boost/range/adaptors.hpp>

using namespace std;
using namespace boost;
using namespace boost::adaptors;
using uint = unsigned int;
using ll = long long int;
using ull = unsigned long long int;

int main() {
    ll H, W;
    cin >> H >> W;
    ll mindiff;
    if (W % 3 == 0 || H % 3 == 0){
        cout << 0;
        return 0;
    } else {
        mindiff = min(H, W);
    }
    for (auto &&i: irange(1LL, H)){
//        cout << "i: " << i << endl;
        ll s_large = W * i;
        ll remaining_hen = H-i;
        if (W%2 == 1){
//            cout << abs(W/2*remaining_hen - s_large) << " " << abs((W/2+1)*remaining_hen-s_large) << " " << remaining_hen << endl;
            mindiff = min(mindiff, max(max(abs(W/2*remaining_hen - s_large), abs((W/2+1)*remaining_hen-s_large)), remaining_hen));
        } else {
//            cout << abs(W/2*remaining_hen - s_large) << endl;
            mindiff = min(mindiff, abs(W/2*remaining_hen - s_large));
        }
    }
    swap(H, W);
    for (auto &&i: irange(1LL, H)){
//        cout << "i: " << i << endl;
        ll s_large = W * i;
        ll remaining_hen = H-i;
        if (W%2 == 1){
//            cout << abs(W/2*remaining_hen - s_large) << " " << abs((W/2+1)*remaining_hen-s_large) << " " << remaining_hen << endl;
            mindiff = min(mindiff, max(max(abs(W/2*remaining_hen - s_large), abs((W/2+1)*remaining_hen-s_large)), remaining_hen));
        } else {
//            cout << abs(W/2*remaining_hen - s_large) << endl;
            mindiff = min(mindiff, abs(W/2*remaining_hen - s_large));
        }
    }
    cout << mindiff;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <cmath>
#include <numeric>
#include <iostream>
#include <sstream>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
#include <stack>
#include <deque>
#include <list>
#include <unordered_map>
#include <tuple>
#include <complex>


#define FOR(i, a, b)		for(int i = (int)(a); i < (int)(b); ++i)
#define FORE(i, a, b)		for(int i = (int)(a); i <= (int)(b); ++i)
#define REP(i, n)			FOR(i, 0, n)
#define REPE(i, n)			FORE(i, 0, n)
#define ALL(x)				(x).begin(),(x).end()
#define DEBUG_DC(x)			cout << #x << ": " << x << endl
#define VEC_TYPE			int
#define INF					1e5+1

using namespace std;
typedef long long ll;
typedef vector<VEC_TYPE> vdef;
typedef vector<vdef> vvdef;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmaxE(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; }
template<class T> inline bool chminE(T& a, T b) { if (a >= b) { a = b; return 1; } return 0; }
template<typename T> inline T mygcd(T a, T b) { return b ? mygcd(b, a%b) : a; }
template<typename T> inline T mylcm(T a, T b) { return a * b / mygcd(a, b); }

int main()
{
	int l, r;
	cin >> l >> r;
	int mod = 2019;
	int ans = 0;

	int modl = l % mod;
	int modr = r % mod;

	if ((r - l) > 2017 || modl > modr)
	{

	}
	else
	{
		ans = mod;
		for (int i = modl; i <= modr; ++i)
		{
			for (int j = i + 1; j <= modr; ++j)
			{
				chmin(ans, (i*j) % mod);
			}
			if (ans == 0) break;
		}
	}

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

Measured memory_bytes: 256
#include <iostream>
#include <array>
#include <algorithm>
#include <vector>
#include <bitset>
#include <set>
#include <unordered_set>
#include <cmath>
#include <complex>
#include <deque>
#include <iterator>
#include <numeric>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <limits>
#include <iomanip>
#include <functional>
#include <cassert>
using namespace std;

using ll=long long;
template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
using vll = V<ll>;
using vvll = V<vll>;
#define rep(i, k, n) for (ll i=k; i<(ll)n; ++i)
#define REP(i, n) rep(i, 0, n)
#define ALL(v) v.begin(),v.end()
template < class T > inline bool chmax(T& a, T b) {if (a < b) { a=b; return true; } return false; }
template < class T > inline bool chmin(T& a, T b) {if (a > b) { a=b; return true; } return false; }
#define DEBUG_VLL(vec) REP(sz, vec.size()) std::cerr<<vec[sz]<<(sz==vec.size()-1?'\n':' ');

const long long MOD = 1000000007;
const long long HIGHINF = (long long)1e18;
const int INF = (int)1e9;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    ll tmp = 0;
    int sz = 1;
    while (tmp < n) {
        tmp += sz;
        sz++;
    }
    sz--;

    if (tmp != n) cout << "No\n";
    else {
        cout << "Yes\n";
        cout << sz + 1 << '\n';
        V< V<int> > ans(sz + 1);
        for (int i = 0; i < sz; i++) ans[0].emplace_back(i + 1);
        ans[1].emplace_back(1);
        for (int i = sz + 1; i < sz + sz; i++) ans[1].emplace_back(i);
        ll tmp = (ll)(sz + sz);
        for (int i = 1; i < sz; i++) {
            ans[i + 1].emplace_back(ans[0][i]);
            ans[i + 1].emplace_back(ans[1][i]);
            for (int j = i + 1; j < sz; j++) {
                ans[i + 1].emplace_back(tmp);
                ans[j + 1].emplace_back(tmp);
                tmp++;
            }
        }
        for (int i = 0; i < sz + 1; i++) {
            cout << ans[i].size() << ' ';
            for (int j = 0; j < ans[i].size(); j++) cout << ans[i][j] << (j == ans[i].size() - 1 ? '\n' : ' ');
        }
    }
    return 0;
}


Measured memory_bytes: 2304
#include<bits/stdc++.h>
using namespace std;
#define lli long long int
#define pii pair<int,int>
#define pll pair<lli, lli>
#define vi  vector<int>
#define vii vector<pair<int,int>>
#define vll vector<lli>
#define pb  push_back
#define mpr  make_pair
#define ss  second
#define ff  first
#define INF 1000000001
#define inf1 1000000000000000001
#define mod 1000000007
#define pie 3.14159265358979323846264338327950L
#define all(x) x.begin(),x.end()
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define testcase() int tc;cin>>tc;while(tc--)
#define clean(x) memset(x,0,sizeof(x))
const lli maxn = 1e5+9;
vector<lli> catlan(int n) {
    vector<lli> dp(n + 1, 0);
    dp[0] = 1;
    dp[1] = 1;
    for (int i = 2; i <= n; i ++) {
        for (int j = 0; j < i; ++ j) {
            dp[i] += dp[j] * dp[i - j - 1];
        }
    }
    return dp;
}
lli b_ex(lli n,lli a){lli res=1;while(n){if(n%2==1)res*=a;n>>=1;a=a*a;}return res;}
lli ncr(lli n,lli k){lli ans=1;if(k>n-k)k=n-k;for(lli i=1;i<=k;i++){ans*=(n-i+1),ans=ans/i;}return ans;}
lli power(lli a , lli n){lli ans = 1;while(n){if(n % 2)ans = (ans * a) % mod;n /= 2;a = (a * a) % mod;}return ans;}
lli set_bits(lli n)
{
    int c=0;
    if(n==0)return 0;
    while(n)
    {
        if((n&1)==1)
        {
           cout<<c<<" ";
        }
        c++;
        n=n>>1;
    }
    return c;
}
lli lcm(lli a,lli b)
{
    lli ans=(a*b)/(__gcd(a,b));
    return ans;
}
///------------------ALWAYS lli-----TEMP TSF99--------------------------------------------------------------------------------------///
void solve()
{
    char a,b;cin>>a>>b;
    if(a=='H' and b=='H')cout<<"H\n";
    else if(a=='D' and b=='D')cout<<"H\n";
    else cout<<"D\n";
}
int main()
{
    FAST;
    //int tc=1;cin>>tc;while(tc--)solve();
    solve();
}



Measured memory_bytes: 3628
n = input()
t, goal_temp = input().split()
high_list = [float(i) for i in input().split()]
best_score, best_index = float('inf'), float('inf')

for i,high in enumerate(high_list):
  temp = int(t) - high*0.006
  best_score = min(abs(temp - int(goal_temp)), best_score)
  if abs(temp - int(goal_temp))==best_score:
    best_index = i
print(best_index+1)

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

#define REP(i, x, n) for (int i = x; i < (int)(n); i++)
#define rep(i, n) REP (i, 0, n)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x.size())
#define popcount(x) __builtin_popcount(x)
#define popcountll(x) __builtin_popcountll(x)
#define uniq(x) x.erase(unique(x.begin(), x.end()), x.end())
#define F first
#define S second
#define mp make_pair
#define eb emplace_back

using namespace std;

typedef long long ll;

// const int INF = 1 << 30;
// const ll INF = 1LL << 60;
// const int MOD = 1000000007;

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

  vector<int> a(n);
  ll ans = 0;
  int mCnt = 0;
  rep (i, n) {
    cin >> a[i];
    if (a[i] < 0) {
      mCnt++;
      a[i] *= -1;
    }
    ans += a[i];
  }

  sort(all(a));

  if (mCnt % 2) ans -= 2 * a[0];

  cout << ans << endl;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#include <map>
#include <set>
#include <vector>
#include <algorithm>
#include <iostream>
#include <bitset>
#include <cassert>
#include <queue>
#include <stack>
#include <iomanip>
#include <math.h>
#include <time.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define repf(i, a, b) for (int i = (int)a; i < (int)b; i++)
#define repr(i, a, b) for (int i = (int)a; i > (int)b; i--)
#define all(v) (v).begin(), (v).end()
#define mp(a, b) make_pair(a, b)
#define pb(x) push_back(x)
#define eb(x) emplace_back(x)
#define F first
#define S second
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pdd;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<int> vii;
typedef vector<vii> vvii;
const ll mod = 1e9 + 7;
const int infi = 1147483600;
const ll infl = 1e18 + 5;
const char ENDL = '\n';
//cout << fixed << setprecision(17) << res << endl;
int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    cin >> n;
    vll a(n);
    rep(i, n) cin >> a[i];
    if (a[0]>0){
        cout << -1 << ENDL;
        return 0;
    }
    ll ans = 0;
    rep(i,n-1){
        if (a[i+1]>a[i]+1){
            cout << -1 << ENDL;
            return 0;
        }
        if (a[i]+1==a[i+1])
            ans++;
        else{
            ans += a[i + 1];
        }
    }
    cout << ans << ENDL;
}

Measured memory_bytes: 1792
from collections import deque

def dfs(n):
    stack = deque(['3','5','7'])
    ansl = []
    while stack:
        num_s = stack.pop()
        num = int(num_s)
        if num > n: continue
        if '7' in num_s and '5' in num_s and '3' in num_s:
            ansl.append(num)
        stack.append(num_s+'7')
        stack.append(num_s+'5')
        stack.append(num_s+'3')
    return ansl


def main():
    n = int(input())
    ansl = dfs(n)
    print(len(ansl))


if __name__ == "__main__":
    main()

Measured memory_bytes: 69396
#include <iostream>

using namespace std;
char a[200005];
int ans;
int fast_pow(int a,int n)
{
    int res=1;
    int temp=a;
    while(n)
    {
        if(n&1)
        {
            res=(1ll*res*temp)%ans;
        }
        temp=(1ll*temp*temp)%ans;
        n>>=1;
    }
    return res%ans;
}
int main()
{
    int res=0;
    int n;
    cin>>n;
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
        if(a[i]=='1')
        {
            res++;
        }
    }
    ans=res+1;
    int yv1=0;
    int yv2=0;
    for(int i=0;i<n;i++)
    {
        if(a[i]=='1')
        yv1=(1ll*yv1+fast_pow(2,n-1-i))%ans;
    }
    ans=res-1;
    if(ans>0)
    for(int i=0;i<n;i++)
    {
        if(a[i]=='1')
        yv2=(1ll*yv2+fast_pow(2,n-1-i))%ans;
    }
    for(int i=0;i<n;i++)
    {
        if(a[i]=='0')
        {
            int time=1;
            ans=res+1;
            int aa=fast_pow(2,n-1-i);
            aa=(1ll*aa+yv1)%ans;
            while(aa)
            {
                int bb=aa;
                int temp1=0;
                while(bb)
                {
                    bb=bb&(bb-1);
                    temp1++;
                }
                aa=aa%temp1;
                time++;
            }
            cout<<time<<endl;
        }
        else if(a[i]=='1')
        {
            int time=1;
            ans=res-1;
            if(ans==0)
            {
                cout<<0<<endl;
                continue;
            }
            int aa=fast_pow(2,n-1-i);
            aa=(1ll*yv2+ans-aa)%ans;
            while(aa)
            {
                int bb=aa;
                int temp1=0;
                while(bb)
                {
                    bb=bb&(bb-1);
                    temp1++;
                }
                aa=aa%temp1;
                time++;
            }
            cout<<time<<endl;
        }
    }
    return 0;
}


Measured memory_bytes: 3832
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, c) for (int i = 0; i < (int)c; i++)
#define all(v) v.begin(), v.end()
using ll = long long;
using P = pair<int, int>;
const int inf = 1000000000; //10^9
const ll MOD = 1e9 + 7;
//加算代入演算子は+=！！！！！
//int 2^31 10^9まで

vector<vector<int>> G;

void dfs(int v, vector<bool> &seen, int &res) // 0、チェック済み配列、まずは0
{
    bool end = true; // 終了フラグ
    for (int i = 0; i < seen.size(); i++) //チェック済み配列の長さ分最大N繰り返す
        if (!seen[i] && i != v) //もしチェック済みじゃなくて、かつ、iがvじゃなければ
            end = false; //終了しない
    if (end) //チェック済みなら
    {
        ++res; //終了する場合はカウンタを加算して返す
        return;
    }

    seen[v] = true; //チェック済み配列のv番目をチェック済みにする
    for (auto nv : G[v]) //v番目に入ってる値でループする
    {
        if (seen[nv]) //チェック済みだったら抜ける
            continue;
        dfs(nv, seen, res); //チェックしてなかったらdfsの再帰 dfs(G[v], true, 0) resが加算される
    }
    seen[v] = false; //v番目をfalseにする
}

int main()
{
    int N, M; //N頂点、M辺
    cin >> N >> M;
    G.assign(N, vector<int>()); //N個のint型の配列を入れる
    // 各辺と頂点の関係性の表の作成。下記のように各頂点と線でつながってる頂点の表ができる。
    // G[0] {1, 3}
    // G[1] {0, 3}
    // G[2] {0, 1}
    for (int i = 0; i < M; i++)
    {
        int a, b;
        cin >> a >> b;
        --a, --b; //配列の0スタートに合わせてる
        G[a].push_back(b);
        G[b].push_back(a); //無向グラフのため
    }
    vector<bool> seen(N, false); //チェック済みの頂点を格納してる配列 初期値はN個のfalse
    int res = 0; //結果
    dfs(0, seen, res); //深さ優先探索dfs 0、チェック済み配列、0をまず渡す
    cout << res << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <queue>
#include <stack>
#include <set>
#include <map>

using namespace std;

int main(){
	int n;
	while(cin >> n && n!=0){
		vector<int> a(n);
		char tmp;
		for(int i=0;i<n;i++){
			cin >> tmp;
			a[i] = tmp -'A';
		}
		vector<int> v(30,0);
		int ma=0,second=0;
		int cha_ma=-1,cha_se=-1;
		for(int i=0;i<n;i++){
			v[a[i]]+=1;
			if(v[a[i]]>=ma){
				if(cha_ma!=a[i]){
					second = ma;
					cha_se = cha_ma;
					ma = v[a[i]];
					cha_ma = a[i];
				}else{
					ma += 1;
				}
				if(ma-second>n-1-i){
					cout << (char)('A'+cha_ma) << " " << i+1 << endl;
					break;
				}
			}else if(v[a[i]]>=second){
				second = v[a[i]];
				cha_se = a[i];
				if(ma-second>n-1-i){
					cout << (char)('A'+cha_ma) << " " << i+1 << endl;
					break;
				}
			}else{
				if(ma-second>n-1-i){
					cout << (char)('A'+cha_ma) << " " << i+1 << endl;
					break;
				}
			}
			if(i==n-1){
				cout << "TIE" << endl;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 3068
#include<bits/stdc++.h>
using namespace std;
using Int = long long;

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

//INSERT ABOVE HERE
signed main(){
  Int n,l;
  cin>>n>>l;
  vector<Int> x(n),y(n),t(n);
  for(Int i=0;i<n;i++) cin>>x[i];
  for(Int i=0;i<n;i++) cin>>t[i];

  Int ans=1;
  Int a=0,b=0,c=0;
  for(Int i=0;i<n;i++){
    y[i]=l-x[i];
    ans+=t[i]/(2*l);
    t[i]%=2*l;
    if(!t[i]) continue;
    if(min(x[i],y[i])*2>=t[i]) c++;
    else if(x[i]*2>=t[i]) a++;
    else if(y[i]*2>=t[i]) b++;
    else ans++;
  }
  
  Int mat=0;
  auto calc=
    [&](Int k)->Int{
      Int res=0;
      Int op=0;
      for(Int i=0;i<n;i++){
	if(!t[i]) continue;
	Int z=-1;
	if(min(x[i],y[i])*2>=t[i]) z=(k-->0);
	else if(x[i]*2>=t[i]) z=1;
	else if(y[i]*2>=t[i]) z=0;
	if(z<0) continue;
	
	if(!z){
	  if(op) res++,op--;
	  else if(i+1==n) res++;
	}
	if(z) op++;
      }
      chmax(mat,res);
      return res;
    };
  //for(int i=0;i<=c;i++) calc(i);
  {
    Int l=0,r=c;
    calc(l);calc(r);
    while(l+1<r){
      Int m=(l+r)>>1;
      if(calc(m)<calc(m+1)) l=m;
      else r=m;
    }
  }
  //cout<<a<<" "<<b<<" "<<c<<":"<<mat<<endl;
  ans+=(a+b+c)-mat;
  cout<<ans*(l*2)<<endl;
  return 0;
}


Measured memory_bytes: 9344
D = [
    (1, 5, 2, 3, 0, 4), # 'U'
    (3, 1, 0, 5, 4, 2), # 'R'
    (4, 0, 2, 3, 5, 1), # 'D'
    (2, 1, 5, 0, 4, 3), # 'L'
]
C = 'NESW'

*L, = map(int, input().split())
for c in input():
    L[:] = (L[e] for e in D[C.index(c)])
print(L[0])



Measured memory_bytes: 5604
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  int K;
  cin>>N>>K;
  
  int a=1;
  
  for (int i=0; i<N; i++) {
    if (a*2 > a+K) {
      a=a+K;
    } 
    else if (a*2 <= a+K) {
      a=a*2;
    }
  }
  cout<<a<<endl;
}

Measured memory_bytes: 256