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

#define CHOOSE(a) CHOOSE2 a
#define CHOOSE2(a0, a1, a2, a3, a4, x, ...) x
#define dump_1(x1) cerr << #x1 << ": " << x1 << endl
#define dump_2(x1, x2) \
  cerr << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << endl
#define dump_3(x1, x2, x3)                                                \
  cerr << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << ", " #x3 << ": " \
       << x3 << endl
#define dump_4(x1, x2, x3, x4)                                            \
  cerr << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << ", " #x3 << ": " \
       << x3 << ", " #x4 << ": " << x4 << endl
#define dump_5(x1, x2, x3, x4, x5)                                        \
  cerr << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << ", " #x3 << ": " \
       << x3 << ", " #x4 << ": " << x4 << ", " #x5 << ": " << x5 << endl
#define dump(...) \
  CHOOSE((__VA_ARGS__, dump_5, dump_4, dump_3, dump_2, dump_1, ~))(__VA_ARGS__)
#define check(s) cerr << s << endl

#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define unique(v) v.erase(unique(v.begin(), v.end()), v.end());
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)

using namespace std;

using ll = long long;

vector<int> dx = {0, 1, 0, -1};
vector<int> dy = {1, 0, -1, 0};

const ll LINF = 2e18;
const int INF = 1e9;

void yes() { cout << "Yes" << endl; }
void no() { cout << "No" << endl; }
void yesOrNo(bool flg) {
  if (flg)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}

void solve(ll X) { yesOrNo(X >= 30); }

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  ll X;
  scanf("%lld", &X);
  solve(X);
  return 0;
}


Measured memory_bytes: 3712
#include<bits/stdc++.h>
using namespace std;
int n;
int main()
{
	cin>>n;
	if(n%2==0)
	{
		cout<<n*(n-2)/2<<endl;
		for(int i=1;i<=n;i++)
			for(int j=i+1;j<=n;j++)
				if(i+j!=n+1)
					cout<<i<<" "<<j<<endl;
	}
	else
	{
		cout<<(n-1)*(n-1)/2<<endl;
		for(int i=1;i<n;i++)
			for(int j=i+1;j<n;j++)
				if(i+j!=n)
					cout<<i<<" "<<j<<endl;
		for(int i=1;i<n;i++)
			cout<<i<<" "<<n<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
int main(){
  string str;
  getline(cin,str);
  while(str.find("apple")!=-1) str.replace(str.find("apple"),5,"00000");
  while(str.find("peach")!=-1) str.replace(str.find("peach"),5,"11111");
  while(str.find("00000")!=-1) str.replace(str.find("00000"),5,"peach");
  while(str.find("11111")!=-1) str.replace(str.find("11111"),5,"apple");
  cout << str << endl;
  return 0;
}

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

long long cnt[1233],ans;
int main(){
    string s; cin>>s;
    for(char c:s)++cnt[c];
    ans=s.size()*1ll*(s.size()-1)/2;
    for(int i=0;i<333;++i)ans-=cnt[i]*1ll*(cnt[i]-1)/2;
    cout<<ans+1<<endl;
}


Measured memory_bytes: 640
a,b,c,d=map(int,input().split())

myturn=a//d
yourturn=c//b
e=a%d
f=c%b

if e!=0:
  myturn+=1
if f!=0:
  yourturn+=1

if myturn>=yourturn:
  print("Yes")
else:
  print("No")

Measured memory_bytes: 9116
#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>;
using vi = vector<ll>;
using vv = vector<vi>;
//const int MOD = 1000000007;
//const int MOD = 998244353;
const ll INF = 1001001001001;

ll dp[4][3003][3003];


int main(){
    int r,c,k; cin>>r>>c>>k;
    
    vv items(r, vi (c, 0));
    
    rep(i,k){
        int a,b,v;
        cin>>a>>b>>v;
        a--;b--;
        items[a][b] = v;
    }
    
    if(items[0][0])dp[1][0][0] = items[0][0];
    
    rep(i,r)rep(j,c){
        
        rep(num,4){
            if(i!=r-1){
                dp[0][i+1][j] = max(dp[0][i+1][j], dp[num][i][j]);
                dp[1][i+1][j] = max(dp[1][i+1][j], dp[num][i][j] + items[i+1][j]);
            }
            if(j!=c-1){
                dp[num][i][j+1] = max(dp[num][i][j+1], dp[num][i][j]);
                if(num!=3)
                    dp[num+1][i][j+1] = max(dp[num+1][i][j+1], dp[num][i][j] + items[i][j+1]);
            }
            
        }
        
        
        
    }
    ll ans = 0;
    rep(i,4)ans = max(ans, dp[i][r-1][c-1]);
    
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 354832
#include<iostream> 
using namespace std; 
int main()
{
    char str[27];
    cin>>str;
    int i,cnt[26];
    for(i=0;i<26;i++){
        cnt[i]=0;
    }
    for(i=0;str[i]!='\0';i++){
        cnt[str[i]-'a']++;
    }
    for(i=0;i<26;i++){
        if(cnt[i]>1){
           cout<<"no"<<endl;
            return 0;
        }
    }
    cout<<"yes"<<endl;
    return 0; 
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int mod = 1e9 + 7;
const int inf = (1 << 30) - 1;
const ll infll = (1LL << 61) - 1;

ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }

int main()
{
    ll n, x;
    cin >> n >> x;
    cout << 3 * (n - gcd(n, x)) << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<map>
using namespace std;
typedef long long li;
#define rep(i,n) for(int i=0;i<(n);i++)
#define df 0
template<class T> void print(const T& t){ cout << t << "\n"; }
template<class T, class... Ts> void print(const T& t, const Ts&... ts) { cout << t; if (sizeof...(ts)) cout << " "; print(ts...); }

int main(){
  li a,b; cin >>a >>b;
  int cnt=0;
  while(b>=a){
    b/=2; cnt++;
  }
  print(cnt);
}


Measured memory_bytes: 256
import java.util.Scanner;

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

    	System.out.println(S.substring(0, 1) + String.valueOf(S.length()-2) + S.substring(S.length()-1, S.length()));
	}
}

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

int main(){
    int A,B,X;
    cin >> A >> B >> X;

    int ans=10000000;
    for(int i=0;i<100;i++){ //全探索
        for(int j=0;j<100;j++){
            int sum = i*1000+j*500;//合計を全パターン
            if(sum>=X){
                ans = min(ans,A*i + B*j);//最小値
            }
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3124
import core.bitop, std.algorithm, std.ascii, std.bigint, std.conv, std.math,
    std.functional, std.numeric, std.range, std.stdio, std.string, std.random,
    std.typecons, std.container, std.format;
static import std.ascii;

// dfmt off
T lread(T = long)(){return readln.chomp.to!T();}
T[] lreads(T = long)(long n){return generate(()=>readln.chomp.to!T()).take(n).array();}
T[] aryread(T = long)(){return readln.split.to!(T[])();}
void scan(TList...)(ref TList Args){auto line = readln.split();
foreach (i, T; TList){T val = line[i].to!(T);Args[i] = val;}}
alias sread = () => readln.chomp();enum MOD = 10 ^^ 9 + 7;
alias PQueue(T, alias less = "a<b") = BinaryHeap!(Array!T, less);
// dfmt on

void main()
{
    long a, b, c;
    scan(a, b, c);
    writeln((b - a == c - b) ? "YES" : "NO");
}


Measured memory_bytes: 256
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn solve(n: i32, an: Vec<i32>) -> i32 {
    let mut flags = [0; 300000];
    for i in 0..n {
        if an[i as usize] == 1 || flags[an[i as usize] as usize - 1] > 0 {
            flags[an[i as usize] as usize] = i + 1;
        }
    }

    let mut m = 0;
    for i in 0..(n+1) {
        if flags[i as usize] > 0 {
            m = i;
        }
    }

    if m == 0 { -1 } else { n - m }
}

fn main() {
    input!{
        n: i32,
        an: [i32; n]
    }

    println!("{:?}", solve(n, an));
}


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

int main() {
  int N,K,sum;
  cin >> N >> K;
  sum = 0;
  for (int i = 0 ; i < N ; i++){
    int x;
    cin >> x;
    if (K > 2*x) sum += x*2;
    else sum += (K-x)*2;
  }
  cout << sum << endl;
}

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

int main() {
	// your code goes here
	int N = 0;
	int x = 0;
	cin >> N;
	cin >> x;
	vector <int> vect(N);
	for (int i = 0; i < N; i++)
	{
		cin >> vect[i];
	}
	sort(vect.begin(), vect.end());
	int res = 0;
	for (int i = 0; i < N; i++)
	{
		if (x >= vect[i])
		{
			x = x - vect[i];
			res++;
			if(i == N-1 && x !=0)
			{
			    res--;
			}
		}
	}
	cout << res;
	return 0;
}


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

using namespace std;

int main(){
    array<string, 8> day = {"SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT", "SUN"};
    string S;
    cin >> S;
    int ans = 1;
    int i = 0;
    for (; i < 8; i++){
        if (S == day[i])
            break;
    }

    while(day[++i] != "SUN")
        ans++;

    cout << ans << endl;
}

Measured memory_bytes: 256
var input = require("fs").readFileSync("/dev/stdin", "utf8");
input = parseInt(input)

const ary = [input];

const roop = (num) => {
    const ans = num % 2 === 0 ? num / 2 : 3 * num + 1;
    if (ary.indexOf(ans) !== -1) {
        console.log(ary.length + 1);
    } else {
        ary.push(ans);
        roop(ans);
    }
}

roop(ary[0]);

Measured memory_bytes: 7372
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0;i < (n);i++)
#define all(v) v.begin(),v.end()
#define dec(n) cout << fixed << setprecision(n);
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using vl = vector<ll>;
using vvl = vector<vl>;

ll gcd(ll a,ll b){
  if(b == 0) return a;
  return gcd(b , a % b);
}

ll mod(ll a){
  return (a % 1000000007);
}

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


int main(){
  ll a,b; cin >> a >> b;
  
  if(a <= 8 && b <= 8) cout << "Yay!" << endl;
  else cout << ":(" << endl;
}

Measured memory_bytes: 256
import java.util.ArrayDeque;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class Main {
	public static void main(String[] args) {
		new Main().run();
	}

	long toKey(int a, int b) {
		if (a < b) {
			return (long) b << 32 | a;
		} else {
			return (long) a << 32 | b;
		}
	}

	void run() {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		Set<Integer>[] g = new Set[N];
		for (int i = 0; i < N; ++i) {
			g[i] = new HashSet<>();
		}
		int[] rep = new int[N];
		for (int i = 0; i < N; ++i) {
			rep[i] = i;
		}
		ArrayDeque<Long> pend = new ArrayDeque<>();
		for (int i = 0; i < 2 * (N - 1); ++i) {
			int a = sc.nextInt();
			int b = sc.nextInt();
			--a;
			--b;
			if (g[a].contains(b)) {
				pend.add(toKey(a, b));
			}
			g[a].add(b);
			g[b].add(a);
		}
		DJSet ds = new DJSet(N);
		while (!pend.isEmpty()) {
			long key = pend.poll();
			int a = (int) (key >> 32);
			int b = (int) (key);
			a = rep[ds.root(a)];
			b = rep[ds.root(b)];
			if (ds.equiv(a, b))
				continue;
			ds.setUnion(a, b);
			if (g[a].size() < g[b].size()) {
				int tmp = a;
				a = b;
				b = tmp;
			}
			g[a].remove(b);
			g[b].remove(a);
			for (int v : g[b]) {
				g[v].remove(b);
				g[v].add(a);
				if (g[a].contains(v)) {
					pend.add(toKey(v, a));
				}
				g[a].add(v);
			}
			g[b].clear();
			rep[ds.root(b)] = a;
		}
		if (ds.size(0) == N) {
			System.out.println("YES");
		} else {
			System.out.println("NO");
		}
	}

	class DJSet {
		int n;
		int[] upper;

		public DJSet(int n) {
			this.n = n;
			upper = new int[n];
			Arrays.fill(upper, -1);
		}

		boolean equiv(int x, int y) {
			return root(x) == root(y);
		}

		int root(int x) {
			return upper[x] < 0 ? x : (upper[x] = root(upper[x]));
		}

		void setUnion(int x, int y) {
			x = root(x);
			y = root(y);
			if (x == y)
				return;
			if (size(x) < size(y)) {
				int tmp = x;
				x = y;
				y = tmp;
			}
			upper[x] += upper[y];
			upper[y] = x;
		}

		int size(int x) {
			return -upper[root(x)];
		}
	}

	private static void tr(Object... o) {
		System.out.println(Arrays.deepToString(o));
	}
}


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

#define SIZE_OF_ARRAY(array) sizeof(array)/sizeof(array[0])

int main() {
    int N, M;
    cin >> N >> M;
    bool ab = true;
    int ans[N];
    int used[N];
    for(int i = 0; i < M; i++){
        int s, c;
        cin >> s >> c;
        s--;
        if(used[s]){
            if(ans[s] != c){
                ab = false;
                break;
            }
        } else {
            ans[s] = c;
            used[s] = 1;
        }
    }
    for(int i = 0; i < N; i++){
        if(used[i]) continue;
        if(i){
            ans[i] = 0;
        }else {
            if(N>1){
                ans[i] = 1;
            }else{
                ans[i] = 0;
            }
            
        }
    }
    if(!ab || (N!=1 && ans[0]==0)){
        cout << -1 << endl;
    } else {
        for(int i = 0; i < N; i++){
            cout << ans[i];
        }
        cout << endl;
    }
}


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

using namespace std;

typedef long long ll;

typedef vector<int> vi;
typedef vector<long long> vl;
typedef vector<double> vd;

#define INF (1e9)

// テンプレート関数
#define REP(i, x, n) for (int i = x; i < n; i++)
#define rep(i, n) REP(i, 0, n)

int main()
{
    int n;
    cin >> n;
    vector<int> a(n);

    rep(i, n) cin >> a[i];

    // 昇順ソート
    sort(a.begin(), a.end());

    // 配列の合計最大値を求める
    vi ps, ns;

    // マイナスしかなくても、ここでいい感じになる
    ps.push_back(a[n - 1]);
    ns.push_back(a[0]);

    for (int i = 1; i < n - 1; ++i)
    {
        // プラスをマイナスで分ける
        if (a[i] > 0) ps.push_back(a[i]);
        else ns.push_back(a[i]);
    }

    int ans = 0;
    for (auto p : ps) ans += p;
    for (auto n : ns) ans -= n;
    cout << ans << endl;

    // ここから操作手順を書く
    // 一番小さい値からでかい値をくっつける
    int tmp = ns[0];
    for (int i = 1; i < ps.size(); ++i)
    {
        cout << tmp << " " << ps[i] << endl;
        tmp = tmp - ps[i];
    }
    // 一番大きい値から引く
    cout << ps[0] << " " << tmp << endl;
    tmp = ps[0] - tmp;

    for (int i = 1; i < ns.size(); ++i)
    {
        cout << tmp << " " << ns[i] << endl;
        tmp = tmp - ns[i];
    }

    return 0;
}

Measured memory_bytes: 2808
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
string s;
int main() {
   cin >> s;
   if (s=="SSS") cout << 0;
   else if (s=="RRR") cout << 3;
   else if (s=="RRS" || s=="SRR") cout << 2;
   else cout << 1;
}

Measured memory_bytes: 3636
L, R = map(int, input().split())
result = R*R
if R - L + 1 > 2019:
    R = L + 2018
for i in range(L,R+1):
    for j in range(i+1,R+1):
        if (i * j) % 2019 < result:
            result = (i * j) % 2019
print(result)

Measured memory_bytes: 9120
#include<iostream>
#include<algorithm>
#include<functional>
#include<cmath>
#include<string>
#include<vector>
using namespace std;
const int mod = 1000000007;
#define ll long long

int main()
{
	int N; cin >> N;
	cout << N * 800 - 200 * (N / 15) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
	int n, d;
	cin >> n >> d;
	vector<vector<int>> x(n, vector<int>(d, 0));
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < d; j++) {
			cin >> x.at(i).at(j);
		}
	}
	int ans = 0;
	for (int i = 0; i < n - 1; i++) {
		for (int j = i + 1; j < n; j++) {
			int res = 0;
			for (int k = 0; k < d; k++){
				res += (x.at(i).at(k) - x.at(j).at(k)) * (x.at(i).at(k) - x.at(j).at(k));
			}
			if ((int)sqrt(res) == sqrt(res)) ans++;
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int n,a;
    cin>>n;
    int swap_cnt=0;
    int flag=0;
    std::deque<int> deq;
    for (int i=0;i<n;i++) {
        cin>>a;
        deq.emplace_back(a);
    }
    for (int j=0;j<n;j++) {
        if (deq[j]!=j+1) {
            if (swap_cnt==0) {
                if (deq[deq[j]-1]!=j+1) {
                    cout<<"NO"<<endl;
                    flag=1;
                    break;
                } else {
                    swap(deq[j],deq[deq[j]-1]);
                    swap_cnt++;
                }
            } else {
                cout<<"NO"<<endl;
                flag=1;
                break;
            }
        }
    }
    if (flag==0) {
        cout<<"YES"<<endl;
    }
}

Measured memory_bytes: 256
import math

r = 999999
sqrt = int(math.sqrt(r))
p = [1]*r
p[0] = 0
for i in range(1,sqrt):
    if p[i]:
        for j in range(2*i+1,r,i+1):
            p[j] = 0

while True:
    try:
        n = int(raw_input())
        print sum(p[:n])
    except:
        break

Measured memory_bytes: 35252
#include <bits/stdc++.h>
#define rep(i,n)for(int i=0;i<(n);i++)
#define MOD 1000000007
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3f
#define EPS (1e-10)
using namespace std;
typedef long long ll;
typedef pair<int,int>P;
 
map<int,bool>dp[2][10000];
vector<int>a[2];
set<P>se[9000][2];
int sum1[9000],sum2[9000];
int dx[]{1,-1,0,0},dy[]{0,0,1,-1};
 
signed main(){
	string s;cin>>s;
	int x,y;scanf("%d%d",&x,&y);
	vector<int>v{0};
	for(char c:s){
		if(c=='F')v.back()++;
		else v.push_back(0);
	}
	if(v.size()<6000){
		for(int i=v.size()-1;i>=0;i--){
		sum1[i]=sum1[i+1]+(i%2==0?v[i]:0);
		sum2[i]=sum2[i+1]+(i%2==1?v[i]:0);
	}
	se[0][0].insert(P(v[0],0));
	int cnt=0;
	rep(i,v.size()-1)rep(k,2){
		for(auto p:se[i][k]){
			rep(j,4){
				if(k==j/2)continue;
				if(abs(p.first+dx[j]*v[i+1]-x)<=sum1[i+1]&&abs(p.second+dy[j]*v[i+1]-y)<=sum2[i+1]){
					se[i+1][j/2].insert(P(p.first+dx[j]*v[i+1],p.second+dy[j]*v[i+1]));
					cnt++;
					if(cnt>100000)goto g;
				}
			}
		}
	}
	if(se[v.size()-1][0].count(P(x,y))||se[v.size()-1][1].count(P(x,y)))puts("Yes");
	else puts("No");
	return 0;
}
g:;
	rep(i,v.size()){
		a[i%2].push_back(v[i]);
	}
	rep(i,2){
		dp[i][0][0]=true;
		rep(j,a[i].size()){
			for(auto p:dp[i][j]){
				if(p.second==false)continue;
				dp[i][j+1][p.first-a[i][j]]=true;
				dp[i][j+1][p.first+a[i][j]]=true;
			}
		}
	}
	if(dp[0][a[0].size()][x]&&dp[1][a[1].size()][y]){
		puts("Yes");
	}
	else puts("No");
}

Measured memory_bytes: 192640
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main()
{
    int n, m, ans=0, cnt=0;
    cin >> n >> m;
    vector<int> a(n);
    for(int i=0; i < n; i++) cin >> a[i];
    for(int i=0; i < n; i++) ans += a[i];
    for(int i=0; i < n; i++) if(a[i]*(4*m) >= ans) cnt++;
    if(cnt >= m) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 3616
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pi;
#define repn(i, a, b) for(int i = (a); i < (b); i++)
#define rep(i, a) for(int i = 0; i < (a); i++)
#define all(v) v.begin(), v.end() 
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define endl '\n'

#ifdef LOCAL
clock_t timer = clock();
#endif

int dp[100005];

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	//freopen("input.in", "r", stdin);
	//freopen("output.out", "w", stdout);
	int n;
	cin >> n;
	int h[n];
	for(int i = 0; i < n; i++){
		cin >> h[i];
	}
	for(int i = 0; i < n; i++){
		dp[i] = 1e9;
        }
	dp[0] = 0;
	for(int i = 0; i < n; i++){
		for(int j = i + 1; j <= i + 2; j++) if(j < n){
			dp[j] = min(dp[j], dp[i] + abs(h[j] - h[i]));
		}
	}
	cout << dp[n - 1] << endl;
#ifdef LOCAL
        cout << "Total Time: " << (double)(clock() - timer) / CLOCKS_PER_SEC << endl;
#endif
	return 0;
}
/*
Things to look out for:
	- Integer overflows
	- Array bounds
	- Special cases
Be careful!
*/


Measured memory_bytes: 1024
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <set>
#include <map>
#include <queue>
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <cstring>

using namespace std;

int main(){
	
	long long int A,B,C;
	cin>>A>>B>>C;
	
	if(A+B>=C){
		cout<<B+C<<endl;
	}else{
		cout<<A+B+1+B<<endl;
	}
	
	return 0;
}

Measured memory_bytes: 256
# def friends(arr):
#     table = [{}]
#     for a in arr:
#         seted = False
#         for t in table:
#             if a[0] in t or a[1] in t:
#                 seted = True
#                 t.add(a[0])
#                 t.add(a[1])
#         if not seted:
#             table.append({a[0], a[1]})
#
#     return max(table, key=len)
# def start():
#     n, m = [int(x) for x in input().split(" ")]
#     arr = []
#     while m:
#         arr.append([int(x) for x in input().split(" ")])
#         m -= 1
#     print(len(friends(arr)))
# start()

def friends(n,arr):
    import collections
    graph = collections.defaultdict(list)
    for i in range(len(arr)):
        graph[arr[i][0]].append(arr[i][1])
        graph[arr[i][1]].append(arr[i][0])
    visited = [False]*(n+1)
    maxi = 0
    for i in range(1,n+1):
        if not visited[i]:
            queue = collections.deque()
            queue.append(i)
            visited[i] = True
            temp = 0
            while queue:
                temp += 1
                s = queue.popleft()
                for t in graph[s]:
                    if not visited[t]:
                        queue.append(t)
                        visited[t] = True
            maxi = max(maxi, temp)
    return maxi

def start():
    n, m = [int(x) for x in input().split(" ")]
    arr = []
    while m:
        arr.append([int(x) for x in input().split(" ")])
        m -= 1
    print((friends(n,arr)))
start()

Measured memory_bytes: 75216
num=int(input())
H=0
T=0
for i in range(num):
	a=input().split()
	if a[0]<a[1]:
		T+=3
	elif a[1]<a[0]:
		H+=3
	else:
		T+=1
		H+=1
print(str(H)+' '+str(T))



Measured memory_bytes: 5596
#include <bits/stdc++.h>
using namespace std;
int main(){
	string a,b;
	cin>>a>>b;
	set<char>ar[26],arr[26];
	for(int i=0;i<a.size();i++){
		ar[(a[i]-'a')].insert(b[i]);
		arr[(b[i]-'a')].insert(a[i]);
	}
	for(int i=0;i<26;i++){
		if(ar[i].size()>1){
			cout<<"No"<<endl;
			return 0;
		}
	}
	for(int i=0;i<26;i++){
		if(arr[i].size()>1){
			cout<<"No"<<endl;
			return 0;
		}
	}
	cout<<"Yes"<<endl;
}

Measured memory_bytes: 776
input_line = input().split()
n = int(input_line[0])
d = int(input_line[1])

count = 0
for i in range(n):
  c = input().split()
  x = int(c[0])
  y = int(c[1])
  if x**2 + y**2 <= d**2:
    count += 1

print(count)

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

using namespace std;
using  ll = long long;
#define rep(i,n) for (int i = 0; i < (n); ++i)
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}


int main(){
  int n;
  std::cin >> n;
  std::map<string, int> m;

  rep(i,n){
    string temp;
    std::cin >> temp;
    m[temp]++;
  }

  std::cout << m.size() << '\n';
  return 0;
}


Measured memory_bytes: 19256
#include <stdio.h>

int main() {
	int A, B, i;
	scanf("%d %d", &A, &B);
	if (A <= B) {
		for (i = 1; i <= B; i++) {
			printf("%d",A);
		}
	}
	else {
		for (i = 1; i <= A; i++) {
			printf("%d", B);
		}
	}
	return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define rrep(i,a,b) for(int i=(a);i>=(b);--i)
#define PB push_back
#define ar2 array<int,2> 
#define vs vector<string>
typedef long long LL;
const LL P = 1e9+7;
const int N = 2e5+5;
mt19937 rng(time(0));

vector<int> g[N];
int n, x, y, a[N], r[4];

void dfs(int x, int fa, int num){
	a[x] = num;
	for(auto u:g[x])
		if(u!=fa) dfs(u, x, 1-num);
}

int main() {
	scanf("%d",&n);
	rep(i,1,n-1){
		scanf("%d%d",&x,&y);
		g[x].PB(y), g[y].PB(x);
	}
	dfs(1,0,1);
	int cnt = 0;
	rep(i,1,n) cnt += a[i];
	if(cnt*2>n){
		rep(i,1,n) a[i] = 1-a[i];
		cnt = n - cnt;
	}
	
	if(cnt*3<=n){
		rep(i,1,n) if(a[i]==1) a[i] = 3;
		r[1] = (n+2)/3, r[2] = (n+1)/3, r[3] = n/3-cnt;
		rep(i,1,n) if(a[i]==0){
			rep(j,1,3) if(r[j]){
				r[j]--, a[i] = j;
				break;
			}
		}
	}else{
		rep(i,1,n) if(a[i]==0) a[i] = 1; else a[i] = 2;
		r[1] = n - cnt - (n+2)/3, r[2] = cnt - (n+1)/3;
		rep(i,1,n){
			int x = a[i];
			if(!r[x]) continue;
			r[x]--, a[i] = 3;
		}
	}
	rep(i,1,3) r[i] = i;
	rep(i,1,n) x = r[a[i]], r[a[i]] += 3, a[i] = x;
	rep(i,1,n) printf("%d ",a[i]);
	return 0;
}

Measured memory_bytes: 18432
#include<bits/stdc++.h>
using namespace std;
typedef complex<double> P;
typedef pair<P,P> L;
#define EPS (1e-10)

int N;
vector<L> S;

double dot(P a,P b) { return real(conj(a)*b); }
double cross(P a,P b ){ return imag(conj(a)*b); }

int ccw(P a,P b, P c){
  b-=a;
  c-=a;
  if( cross( b,c ) > EPS ) return 1;
  if( cross( b,c ) < -EPS ) return -1;
  if( dot(b,c) < -EPS ) return 2;
  if( norm(b) < norm(c) ) return -2;
  return 0;      
}

bool equalPoint( P a, P b ){
  if( abs( a-b ) < EPS ) return true;
  return false;
}


bool isIntersect(L s1, L s2 ) {
  if( max( real(s1.first), real(s1.second)) + EPS < min( real(s2.first), real(s2.second) ) ||
      max( imag(s1.first), imag(s1.second)) + EPS < min( imag(s2.first), imag(s2.second) ) ||
      max( real(s2.first), real(s2.second)) + EPS < min( real(s1.first), real(s1.second) ) ||
      max( imag(s2.first), imag(s2.second)) + EPS < min( imag(s1.first), imag(s1.second) ) ) return false;

  if(equalPoint(s1.first,s2.first) || equalPoint(s1.first,s2.second) ||
     equalPoint(s1.second,s2.first) || equalPoint(s1.second,s2.second) ) return false;
  return ( ccw(s1.first, s1.second, s2.first) * ccw(s1.first , s1.second, s2.second) <= 0 &&
	   ccw(s2.first, s2.second, s1.first) * ccw(s2.first , s2.second, s1.second) <= 0 );
}


P crossPoint(L l,L m){
  double A = cross(l.second - l.first, m.second - m.first);
  double B = cross(l.second - l.first, l.second - m.first);
  if ( fabs( A ) < EPS && fabs( B ) < EPS ) return m.first;
  else if ( fabs(A) >= EPS ) return m.first + B/ A * (m.second - m.first);
}

int res;

void check(L s){
  vector<P> flag;
  for(int i=0;i<(int)S.size();i++){
    if( isIntersect( S[i], s ) ) {
      P a = crossPoint(S[i],s);
      bool f = false;
      for(int j=0;j<(int)flag.size();j++){
	if( equalPoint(flag[j],a) ) f = true;
	if( f ) break;
      }
      if( f ) continue;
      flag.push_back(a);
      // cout << " i "<<res << endl;
      res++;
    }
  }
}

int main() {
  while( cin >> N && N ){
    res = 1;
    for(int i=0;i<N;i++){
      res++;
      int x1, y1, x2, y2;
      cin >> x1 >> y1 >> x2 >> y2;
      L s = L( P((double)x1,(double)y1) , P((double)x2,(double)y2) );
      check( s );
      S.push_back( s );
    }
    S.clear();
    cout << res << endl;
  }
}

Measured memory_bytes: 1228
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vi;
typedef pair<ll,ll> pi;
typedef vector<pi> vpi;
typedef long double ld;
#define pb emplace_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define ALL(x) x.begin(), x.end()
#define SZ(x) (ll)x.size()
#define f first
#define s second
#define MAXN 501010

ll T,N,M,a,b;
ll A[MAXN];
vi V[MAXN];

int main(){
	string S;
	cin>>S;
	for (auto i:S)if(i=='A')++a;else ++b;
	if (min(a,b))cout<<"Yes";
	else cout<<"No";
}


Measured memory_bytes: 12544
// #pragma GCC target("avx2")  // CPU 処理並列化
// #pragma GCC optimize("O3")  // CPU 処理並列化
// #pragma GCC optimize("unroll-loops")  // 条件処理の呼び出しを減らす
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<stack>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#include<stdlib.h>
#include<cassert>
#include<time.h>
#include<bitset>
#include<numeric>
using namespace std;
const long long mod=1000000007;
const long long inf=mod*mod;
const long long d2=(mod+1)/2;
const double EPS=1e-10;
const double INF=1e+10;
const double PI=acos(-1.0);
const int C_SIZE = 3121000;
namespace{
	long long fact[C_SIZE];
	long long finv[C_SIZE];
	long long inv[C_SIZE];
	long long Comb(int a,int b){
	 	if(a<b||b<0)return 0;
	 	return fact[a]*finv[b]%mod*finv[a-b]%mod;
	}
	void init_C(int n){
		fact[0]=finv[0]=inv[1]=1;
		for(int i=2;i<n;i++){
			inv[i]=(mod-(mod/i)*inv[mod%i]%mod)%mod;
		}
		for(int i=1;i<n;i++){
			fact[i]=fact[i-1]*i%mod;
			finv[i]=finv[i-1]*inv[i]%mod;
		}
	}
	long long pw(long long a,long long b){
		if(a<0LL)return 0;
		if(b<0LL)return 0;
		long long ret=1;
		while(b){
			if(b%2)ret=ret*a%mod;
			a=a*a%mod;
			b/=2;
		}
		return ret;
	}
	int ABS(int a){return max(a,-a);}
	long long ABS(long long a){return max(a,-a);}
	double ABS(double a){return max(a,-a);}
	int sig(double r) { return (r < -EPS) ? -1 : (r > +EPS) ? +1 : 0; }
}
// ここから編集しろ
int p[30];
int q[30];
int r[30];
int main(){
	int a;scanf("%d",&a);
	for(int i=0;i<a;i++){
		scanf("%d",p+i);p[i]--;
	}
	for(int i=0;i<a;i++){
		scanf("%d",q+i);
	}
	for(int i=0;i<a-1;i++){
		scanf("%d",r+i);
	}
	int ret=0;
	for(int i=0;i<a;i++){
		ret+=q[p[i]];
		if(i&&p[i-1]+1==p[i])ret+=r[p[i-1]];
	}
	printf("%d\n",ret);
}


Measured memory_bytes: 128
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<deque>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<iterator>
#include<complex>
#include<stack>
#include "stdio.h"
using namespace std;

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

using ll = long long;
using Pii = pair<int, int>;

const int inf = 1e9 + 7;
const ll longinf = 1LL << 50;
const long long mod_const = 1e9+7;

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

using MIte = multimap<ll, ll, greater<ll> >::iterator;

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

using pll = pair<long long, long long>;

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

	string S;
	cin >> S;

	vector<int> va(S.length() + 1, 0);

	rep(i, S.length()) {
		if (S[i] == '>' && S[i + 1] == '<') {
			va[i + 1] = 0;
		}
	}

	if (S[0] == '<') va[0] = 0;
	if (S[S.length()] == '>') va.back() = 0;

	for (int i = 0; i != S.length(); ++i) {
		if (S[i] == '<') {
			va[i + 1] = max(va[i + 1], va[i] + 1);
		}
	}

	for (int i = S.length() - 1; i != -1; --i) {
		if (S[i] == '>') {
			va[i] = max(va[i], va[i+1] + 1);
		}
	}

	ll ans = 0;
	rep(i, va.size()) {
		ans += va[i];
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 2844
def is_included(i, n):
    return True if S[i] >= n else False


def search(n):
    inc = N
    exc = -1
    while abs(inc-exc) > 1:
        mid = (exc+inc) // 2
        if is_included(mid, n):
            inc = mid
        else:
            exc = mid
    return inc < N and S[inc] == n


def main():
    ans = 0
    for t in T:
        if search(t):
            ans += 1
    print(ans)


if __name__ == "__main__":
    N = int(input())
    S = sorted([int(s) for s in input().split()])
    Q = int(input())
    T = [int(t) for t in input().split()]
    main()


Measured memory_bytes: 16896
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<stack>
#include<queue>
#include<cmath>
#define int long long
#define INF 100000000000
#define EPS 0.0000000001

using namespace std;
int movex[300000], movey[300000];
int graphx[300];
int graphy[300];
int photox[10100];
int photoy[1010];

void syoki() {
	for (int i = 0; i<300000; i++) {
		movex[i] = 0;
		movey[i] = 0;
	}
	for (int i = 0; i<1010; i++) {
		graphx[i] = 0;
		graphy[i] = 0;
		photox[i] = 0;
		photoy[i] = 0;
	}
}

signed main() {
	int m, n;
	int x, y;
	while (1) {
		syoki();
		cin >> m;
		if (m == 0)break;
		for (int i = 0; i < m; i++) {
			cin >> x >> y;
			graphx[i] = x;
			graphy[i] = y;
		}
		cin >> n;
		for (int i = 0; i < n; i++) {
			cin >> x >> y;
			photox[i] = x;
			photoy[i] = y;

		}
		int k = 0;
		for (int i = 0; i < m; i++) {
			for (int j = 0; j < n; j++) {
				movex[k] = photox[j] - graphx[i];
				movey[k] = photoy[j] - graphy[i];
				k++;
			}
		}
		int cntx = 0;
		int cnty = 0;
		int ansx = 0, ansy = 0;
		sort(movex, movex + k);
		sort(movey, movey + k);
		for (int i = 0; i < k; i++) {
			if (movex[i] == movex[i + 1])cntx++;
			else cntx = 0;
			if (movey[i] == movey[i + 1])cnty++;
			else cnty = 0;
			if (cntx == m - 1)ansx = movex[i];
			if (cnty == m - 1)ansy = movey[i];
			//cout << movex[i] << " " << movey[i] << endl;
			//printf("[%d] [%d]",cntx,cnty);
			if (ansx&&ansy)break;
		}
		cout << ansx << " " << ansy << endl;
	}
	return 0;
}

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

int main() {
	int N;
	cin>>N;
	vector<int> hei(N);
	for(int i=0;i<N;i++){
		cin >> hei.at(i);
	}
	
	int count=0;
	int max=0;
	
	for (int i=0;i<N-1;i++){
		if(hei.at(i)>=hei.at(i+1)){
			count++;
			if(count >max){
				max=count;
			}
		}
		else{
			count=0;
		}
	}
	
	cout << max << endl;
	
}


Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <stack>
#include <queue>
#include <string>

using namespace std;

int main(){
  int n, x, y;
  cin >> n >> x >> y;
  x--, y--;
  vector <int> k(n,0);
  for (int i = 0; i < n - 1; i++){
    for (int j = i + 1; j < n; j++){
      if (i >= y || j <= x){
       k[j-i]++;
       continue;
      }
      if (i <= x && j >= y){
       k[x - i + j - y + 1]++;
       continue;
      }
      if (i <= x && j <= y){
        int mini = min(x - i + 1 + y - j, j - i);
        k[mini]++;
        continue;
      }
      if (i >= x && j >= y){
        int mini = min(i - x + 1 + j - y, j - i);
        k[mini]++;
        continue;
      }
      if (i >= x && j <= y){
        int mini = min(i - x + y - j + 1, j - i);
        k[mini]++;
        continue;
      }
    }
  }
  for (int i = 1; i <= n - 1; i++)
   cout << k[i] << endl;
}

Measured memory_bytes: 256
import bisect
import math
def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))


N = int(input())
An = list(map(int,input().split(' ')))


An.sort()
max_num = An[N-1]

half_val = max_num//2
idx =  bisect.bisect_right(An[0:N-1],half_val)
if idx == 0:
    print(max_num,An[idx])
elif idx == N-1:
    print(max_num,An[idx-1])
else:
    A = An[idx] - half_val
    B = half_val - An[idx-1]
    if A > B:
        print(max_num,An[idx-1])
    else:
        print(max_num,An[idx])

Measured memory_bytes: 58536
#include<bits/stdc++.h>
#define LL long long
using namespace std;
LL digitSum(LL a,LL b){
	LL x=0;
	while(a>0){
		x+=a%10;
		a/=10;
	}
	while(b>0){
		x+=b%10;
		b/=10;
	}
	return x;
}
int main() {
	LL n;
	cin>>n;
	LL p=1000000;
	for(LL i=1;i<=(n+1)/2;i++){
		p=min(digitSum(i,n-i),p);
	}
	cout<<p<<endl;
}


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

int main()
{
	int n;
	cin>>n;
	
	int a[n+20],i,maxv=0,total;
	
	for(i=1;i<=n;i++)
	{
	    cin>>a[i];
	}
	for(i=1;i<=n;i++)
	{
		if(a[i]>=maxv)
		{
			total++;
			maxv=a[i];
		}
	}
	cout<<total<<endl;
	return 0;
}

Measured memory_bytes: 256
# 10で割っていくやつ
[N, A, B] = list(map(int, input().split()))
sum = 0
a = 0
for i in range(1, N+1):
  n = i
  while n > 0:
    a += n % 10
    n //= 10
  if A <= a <= B:
    sum += i
    a = 0
  else:
    a = 0
    continue
print(sum)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rrep(i, n) for (int i = (n - 1); i >= 0; i--)
#define ALL(v) v.begin(), v.end()
using namespace std;
using P = pair<int, int>;
typedef long long ll;

int main() {
  string s;
  cin >> s;
  int num = 0;
  int ans = 0;
  rep(i, 3) {
    if(s[i] == 'R'){
      num++;
    }else{
      ans = max(num,ans);
      num = 0;
    }
  }
  ans = max(num,ans);
  cout << ans << endl;
}

Measured memory_bytes: 3624
#include<iostream>
#include<vector>
using namespace std;
  
class DisjointSet{
    public:
        vector<int> rnk, par, weight;
          
        DisjointSet(){}
        DisjointSet(int size){
            rnk.resize(size, 0);
            par.resize(size, 0);
            weight.resize(size, 0);
            for(int i = 0; i < size; i++) makeSet(i);
        }
  
        void makeSet(int x){
            par[x] = x;
            rnk[x] = 0;
            weight[x] = 0;
        }
  
        bool same(int x, int y){
            return find(x) == find(y);
        }
  
        void unite(int x, int y, int z){
            par[x] = find(x);
            par[y] = find(y);
            int add = z - (weight[y] - weight[x]);
            if(rnk[par[x]] > rnk[par[y]]){
                weight[par[y]] = add;
                par[par[y]] = par[x];
            }else{
                weight[par[x]] = -add;
                par[par[x]] = par[y];
                if(rnk[par[x]] == rnk[par[y]]){
                	rnk[par[y]]++;
                }
            }
        }
          
        int diff(int x, int y){
            return weight[y] - weight[x];
        }
  
        int find(int x){
            if(x != par[x]){
                int t = find(par[x]);
                weight[x] += weight[par[x]];
                return par[x] = t;
            }
            else return x;
        }
};
  
int main(){
    int n, q;
    cin >> n >> q;
    DisjointSet UF(n);
    for(int i = 0; i < q; i++){
        int query;
        cin >> query;
        if(query == 0){
            int x, y, z;
            cin >> x >> y >> z;
            if(UF.same(x, y)) continue;
            UF.unite(x, y, z);
            //for(int j = 0; j < n; j++) cout << UF.weight[j] << (j == n - 1 ? '\n' : ' ');
        }else{
            int x, y;
            cin >> x >> y;
            if(UF.same(x, y)){
                cout << UF.diff(x, y) << endl;
            }else{
                cout << '?' << endl;
            }
        }
    }
    return 0;
}


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

int main() {
  stack<int> st;
  string s;
  int a, b;
  while(cin >> s) {
    if (s == "+") {
      b = st.top();
      st.pop();
      a = st.top();
      st.pop();
      st.push(a + b);
    } else if (s == "-") {
      b = st.top();
      st.pop();
      a = st.top();
      st.pop();
      st.push(a - b);
    } else if (s == "*") {
      b = st.top();
      st.pop();
      a = st.top();
      st.pop();
      st.push(a * b);
    } else {
      st.push(stoi(s));
    }
  }

  cout << st.top() << endl;
}



Measured memory_bytes: 3216
#include<iostream>
#include<string.h>
#include<string>
#include<stdio.h>
#include<algorithm>
#include<vector>
#include<math.h>
#include<queue>
#include<set>
#include<map>
using namespace std;
typedef long long ll;
typedef long double db;
const int N=10000;
const db pi=acos(-1.0);
#define lowbit(x) (x)&(-x)
#define sqr(x) (x)*(x)
#define rep(i,a,b) for (register int i=a;i<=b;i++)
#define per(i,a,b) for (register int i=a;i>=b;i--)
#define fir first
#define sec second
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define maxd 998244353
#define eps 1e-8
string a;
set<char> s;
int read()
{
    int x=0,f=1;char ch=getchar();
    while ((ch<'0') || (ch>'9')) {if (ch=='-') f=-1;ch=getchar();}
    while ((ch>='0') && (ch<='9')) {x=x*10+(ch-'0');ch=getchar();}
    return x*f;
}

int main()
{
    cin >> a;
    rep(i,0,3) s.insert(a[i]);
    if (s.size()==2) puts("Yes");else puts("No");
    return 0;
}


Measured memory_bytes: 256
// g++ -std=c++11 a.cpp
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<unordered_map>
#include<utility>
#include<cmath>
#include<random>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define FOR(i,a) for(auto i:a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
#define show1d(v) rep(i,v.size())cout<<" "<<v[i];cout<<endl<<endl;
#define show2d(v) rep(i,v.size()){rep(j,v[i].size())cout<<" "<<v[i][j];cout<<endl;}cout<<endl;
using namespace std;
//kaewasuretyuui
typedef long long ll;
//#define int ll
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
// #define mt make_tuple
// typedef tuple<int,int,int> tp;
// typedef vector<tp> vt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
//template<class C>constexpr int size(const C &c){return (int)c.size();}
//template<class T,size_t N> constexpr int size(const T (&xs)[N])noexcept{return (int)N;}
const double PI=acos(-1);
const double EPS=1e-9;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9+10;
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
string s;
int f(int a){
	int t=-1,co=0;
	if(a)t=4;
	rep(i,s.size()){
		int b=(s[i]-'1')%3;
		if(!a&&t>b)co++,a^=1;
		else if(a&&t<b)co++,a^=1;
		t=b;
		a^=1;
	}
	return co;
}
int main(){
	while(cin>>s,s!="#"){
		cout<<min(f(0),f(1))<<endl;
	}
}








Measured memory_bytes: 3176
import sys
# import collections
# import math
# import string
# import bisect
# import re
# import itertools
# import statistics

def main():
    s = list(sys.stdin.readline().rstrip())
    s[3] = '8'
    print(''.join(s))


if __name__ == "__main__":
    # execute only if run as a script
    main()


Measured memory_bytes: 2940
#include <iostream>
#include <vector>
#include <algorithm>
#include <math.h>
#include <queue>
using namespace std;

typedef long long ll;

vector<int> Zalgo(string S) {
	int n = S.size(), i = 1, w = 0, k;
	vector<int> Z(n); Z[0] = n;
	while (i < n) {
		while (i + w < n && S[w] == S[i + w]) {
			w++; 
		}
		Z[i] = w;
		if (w == 0) {
			i++; continue; 
		}
		for (k = 1; i + k < n && k + Z[k] < w; k++) {
			Z[i + k] = Z[k]; 
		}
		i += k;
		w -= k;
	}
	return Z;
}

int main() {
	int N, ans = 0; cin >> N;
	string S; cin >> S;
	for (int i = 0; i < N - 1; i++) {
		vector<int> Z(N - i);
		Z = Zalgo(S.substr(i));
		for (int j = 1; j < N - i; j++) {
			if (j >= Z[j]) {
				ans = max(ans, Z[j]); 
			}
		}
	}
	cout << ans << "\n";
	return 0;
}


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

  int N ;
  int ans = 0 ;
  cin >> N ;
  string S ;
  cin >> S ;
  rep(i,1000){
    int A[4] = { i/100 , (i/10)%10 , i%10 , 1000 } ;
    int j = 0 ;
  	rep( i , S.size() ) if( S.at(i) == A[j] + '0' ) j++ ;
    if( j == 3 ) ans++ ;
    }
    cout << ans << endl;                       
}

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

#define pow(n) (n)*(n)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()

#define space cout << endl;
#define test_data(data) cout << data << endl;
#define test_comp(var1, var2) cout << var1 << " " << var2 << endl;

using namespace std;

/* function */
//  - none - 


/* code */
int main (void) 
{

  /* Variable_Proclamation */
  int64_t S; // input

  int i;    // subscript

  int bit;
  int64_t tmp;
  int64_t sum;


  /* Input, Array_Proclamation */
  cin >> S;


  /* Initialize */
  sum = 0;


  /* Calculation */
  vector<int> digit;
  while( S > 0 )
  {
    digit.push_back( S%10 );
    S /= 10;
  }
  reverse( all(digit) );

  for(bit = 0; bit < ( 1 << digit.size() -1 ); bit++)
  {

    vector<char> op;
    for(i=0; i<digit.size()-1; i++)
    {
      (bit & (1<<i))? op.push_back('+'): op.push_back(' ');
    }

    tmp = digit.at(0);
    for(i=0; i<op.size(); i++)
    {
      if(op.at(i) == '+')
      {
        sum += tmp;
        tmp = digit.at(i+1);
      }
      else
      {
        tmp = tmp*10 + digit.at(i+1);
      }
    }
    sum += tmp;

  }
  

  /* Output */
  cout << sum << endl;


  return 0;

}


/* entity */
//  - none -




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

#define ll long long
#define N 410
char G[N][N];
int n, m;
int pre[N * N], tot[N * N];
int find(int x) { return pre[x] == 0 ? x : pre[x] = find(pre[x]); }
void join(int u, int v)
{
	int fu = find(u), fv = find(v);
	if (fu != fv) pre[fu] = fv;
}
int f(int x, int y) { return (x - 1) * m + y; }
int Move[][2] = 
{
	-1, 0,
	 0,-1,
};
bool ok(int x, int y) 
{
	if (x < 1 || x > n || y < 1 || y > m) return false;
	return true;
}

int main()
{
	while (scanf("%d%d", &n, &m) != EOF)
	{
		for (int i = 1; i <= n; ++i) scanf("%s", G[i] + 1);
		memset(pre, 0, sizeof pre);
		memset(tot, 0, sizeof tot);
		for (int i = 1; i <= n; ++i) for (int j = 1; j <= m; ++j)
		{
			for (int k = 0; k < 2; ++k) 
			{
				int nx = i + Move[k][0];
				int ny = j + Move[k][1];
				if (ok(nx, ny) && G[i][j] != G[nx][ny]) join(f(i, j), f(nx, ny));	
			}
		}
		for (int i = 1; i <= n; ++i) for (int j = 1; j <= m; ++j) if (G[i][j] == '.')
			++tot[find(f(i, j))];
		ll res = 0;
		for (int i = 1; i <= n; ++i) for (int j = 1; j <= m; ++j) if (G[i][j] == '#') res += tot[find(f(i, j))];
		printf("%lld\n", res);
	}
	return 0;
}


Measured memory_bytes: 1664
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Practice
{
    class Program
    {
        static void Main(string[] args)
        {
            Solve();
        }
        private const int MOD = 1000000007;
        static void Solve()
        {
            var nk = ReadAndParseIntArr();
            int n = nk[0];
            int k = nk[1];
            var list = new List<int>();
            for(int i=0;i<n;++i)
            {
                list.Add(ReadAndParseInt());
            }
            list.Sort();

            int min = int.MaxValue;
            int lastIdx = n - k;
            for(int i=0;i<=lastIdx; ++i)
            {
                int tmp = list[i + k - 1] - list[i];
                min = Math.Min(min, tmp);
            }
            Console.WriteLine(min);
        }

        #region よく使う便利関数
        private static bool isPrime(long x)
        {
            if (x == 2) { return true; }
            if (x < 2 || x % 2 == 0) { return false; }
            long i = 3;
            while (i * i <= x)
            {
                if (x % i == 0) { return false; }
                i = i + 2;
            }
            return true;
        }
        private static long lcm(long x, long y)
        {
            return x / gcd(x, y) * y;
        }
        private static long gcd(long x, long y)
        {
            return y > 0 ? gcd(y, x % y) : x;
        }
        private static long pow(long x, long n)
        {
            if (n == 0) { return 1; }
            long res = pow(x * x % MOD, n / 2);
            if (n % 2 == 1)
            {
                res = res * x % MOD;
            }
            return res;
        }
        private static int ReadAndParseInt()
        {
            return int.Parse(Console.ReadLine());
        }
        private static int[] ReadAndParseIntArr()
        {
            return Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
        }
        private static long ReadAndParseLong()
        {
            return long.Parse(Console.ReadLine());
        }
        private static long[] ReadAndParseLongArr()
        {
            return Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse);
        }
        #endregion
    }
}

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

int main() {
	int N;
	cin >> N;
	if ( N % 2 == 0) cout << 0.5000000000 << endl;
	else {
		double NN = N;
		double ans = ((NN - 1) / 2 + 1) / NN;
		cout << ans << endl;
	}

	return 0;
}

Measured memory_bytes: 256