akhauriyash/Code-Regression huggingface dataset:
use std::usize::MAX;

fn main() {
    let s = std::io::stdin();
    let mut sc = Scanner { stdin: s.lock() };

    let n: usize = sc.read();
    let k: usize = sc.read();
    let a: Vec<usize> = sc.vec(n);
    let max_a = *a.iter().max().unwrap();
    let mut add = vec![0; n];
    let mut last: Vec<usize> = vec![MAX; max_a + 1];
    for i in 0..(2 * n) {
        let a = a[i % n];
        if last[a] != MAX {
            if last[a] < n {
                add[last[a]] = i - last[a];
            }
        }
        last[a] = i;
    }
    assert!(add.iter().all(|&add| add > 0));

    let (first, second) = find_cycle(&add);
    let length = (n * k - first) % (second - first) + first;
    let mut start = 0;
    loop {
        let next = add[start % n] + 1 + start;
        if next >= length {
            break;
        }
        start = next;
    }

    let mut set: Vec<bool> = vec![false; max_a + 1];
    let mut ans: Vec<usize> = vec![];
    for i in start..length {
        let a = a[i % n];
        if set[a] {
            while let Some(tail) = ans.pop() {
                assert!(set[tail]);
                set[tail] = false;
                if tail == a {
                    break;
                }
            }
        } else {
            set[a] = true;
            ans.push(a);
        }
    }
    for (i, ans) in ans.into_iter().enumerate() {
        if i > 0 {
            print!(" ");
        }
        print!("{}", ans);
    }
    println!();
}

fn find_cycle(add: &Vec<usize>) -> (usize, usize) {
    let n = add.len();
    let mut last: Vec<usize> = vec![MAX; n];
    let mut cur = 0;
    loop {
        if last[cur % n] != MAX {
            return (last[cur % n], cur);
        }

        last[cur % n] = cur;
        cur += add[cur % n] + 1;
    }
}

pub struct Scanner<R> {
    stdin: R,
}

impl<R: std::io::Read> Scanner<R> {
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .stdin
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n')
            .take_while(|&b| b != b' ' && b != b'\n')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}


Measured memory_bytes: 15740
fun main(args : Array<String>) {
    var h = readLine()!!.toLong()

    var cnt = 0
    while(h > 1) {
        h /= 2
        cnt++
    }

    var ans = 0L
    for (i in 0..cnt) {
        ans += Math.pow(2.0, i.toDouble()).toLong()
    }

    println(ans)
}

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

using namespace std;

#define all(x) x.begin(), x.end()
#define sz(x) (int) x.size()
#define debug(args...){string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args);}
#define endl "\n"

typedef long long ll;
typedef unsigned long long ull;
typedef pair <int, int> ii;
typedef pair <ii, int> iii;

void err(istream_iterator<string> it){}
template <typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args){
	cerr << *it << " = " << a << endl;
	err(++it, args...);
}

int main(){
  int n;
  cin >> n;
  vector <bool> same(n, 0);
  for(int i = 0; i < n; i++){
    int x, y;
    cin >> x >> y;
    same[i] = (x == y);
  }
  bool ans = false;
  for(int i = 0; i < n-2; i++){
    ans |= (same[i]+same[i+1]+same[i+2]) == 3;
  }
  cout << (ans ? "Yes" : "No") << endl;
  return 0;
}

Measured memory_bytes: 3628
#include<bits/stdc++.h>
//#define int long long
#define FOR(i, a, b) for (int i = a; i < b; ++i)
#define rep(N) for (int i = 0; i < N; ++i)
#define Rep(a, b) for (int i = a; i < b; ++i)
#define For(i, N) for (int i = 0; i < N; ++i)
#define all(v) v.begin(), v.end()
#define rev(v) v.rbegin(), v.rend()
#define mi(N) int N; cin >> N;
#define ms(s) string s; cin >> s;
#define md(d) double d; cin >> d;
#define mv(v, N) vi v(N); rep(N)cin >> v[i];
#define mod 1000000007

using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vll = vector<ll>;
using vb = vector<bool>;
using vvb = vector<vector<bool>>;
using vs = vector<string>;
using pii = pair<int, int>;
using pis = pair<int, string>;
using msi = map<string, int>;

template<typename T>
void say(T s) {
	cout << s << "\n";
}

template<typename T>
void say(vector<T> s) {
	auto itr = s.begin();
	cout << *(itr++);
	while (itr != s.end()) {
		cout << " " << *(itr++);
	}
	cout << "\n";
}

template<typename T>
void say(vector<T> s, char r) {
	auto itr = s.begin();
	cout << *(itr++);
	while (itr != s.end()) {
		cout << r << *(itr++);
	}
	cout << "\n";
}

void yn(bool b) {
	if (b)say("yes");
	else say("no");
}

void Yn(bool b) {
	if (b)say("Yes");
	else say("No");
}

void YN(bool b) {
	if (b)say("YES");
	else say("NO");
}

void Yay(bool b) {
	if (b)say("Yay!");
	else say(":(");
}

template<typename T>
void maxi(T& a, T b) {
	a = max(a, b);
}

template<typename T>
void mini(T& a, T b) {
	a = min(a, b);
}

void exact_say(double x) {
	cout << setprecision(numeric_limits<double>::max_digits10) << x << endl;
}

template<typename T>
vector<vector<T>> fill_vector(int h, int w, T val) {
	vector<vector<T>> ret;
	vector<T> v(w, val);
	rep(h)ret.push_back(v);
	return ret;
}

template<typename T>
T max(vector<T> v) {
	T ret = v[0];
	Rep(1, v.size())maxi(ret, v[i]);
	return ret;
}

template<typename T>
T min(vector<T> v) {
	T ret = v[0];
	Rep(1, v.size())mini(ret, v[i]);
	return ret;
}

signed main() {
	ms(s);
	int n = s.size();
	int ans = 0;
	for (int i = 0; i < n; i += 2) {
		if (s[i] == '0')ans++;
	}
	for (int i = 1; i < n; i += 2) {
		if (s[i] == '1')ans++;
	}
	say(min(ans, n - ans));
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using ull = long long unsigned;
using P = pair<int,int>;
const int INF=1001001001;
const int NMAX=8;
const int MOD=1000000007;
const int dbase=80*160;

bool isprime(int x){
	if (x<=1) return false;
	for(int i=2;i*i<=x;i++){
		if (x%i==0)return false;
	}
	return true;

}

int main()
{
	int x;
	cin>>x;
	while (x>0){
		if (isprime(x)){
		cout<<x;
		return 0;
	}
		x++;
	}
}


Measured memory_bytes: 256
import java.util.*;

class Main {
  public static void main (String[] args) {
    Scanner scanner = new Scanner(System.in);
    int d = 0;
    int e = 0;
    while (scanner.hasNext()) {
      String line = scanner.nextLine();
      String[] s = line.split(",");
      int a = Integer.parseInt(s[0]);
      int b = Integer.parseInt(s[1]);
      int c = Integer.parseInt(s[2]);
      if (a * a + b * b == c * c) {
        d++;
        continue;
      }
      if (a == b) {
        e++;
        continue;
      }
    }
    System.out.println(d);
    System.out.println(e);
  }
}

Measured memory_bytes: 17140
object Main{
  def main(args: Array[String]){
    if (sys.env.getOrElse("TEST", "")=="1"){
      println(test());
    }else{
      val input=io.Source.stdin.getLines().mkString("\n");
      println(solve(input).trim());
    }
  }

  def solve(input:String):String={
    val list=input.split("\n").drop(1).map(_.split(" ").map(_.toInt)).map{case Array(t,x,y)=>(t,x,y)}.toList;
    if(((0,0,0)::list).zip(list).forall{case ((t,x,y),(nextT,nextX,nextY))=>{
      val dt = nextT - t;
      val dist = (nextX-x).abs + (nextY-y).abs;
      dt >= dist&&dist % 2 == dt % 2
    }}){
      "Yes"
    }else{
      "No"
    }
  }
 
  val tests=List("""2
3 1 2
6 1 1""" -> """Yes""",
    """1
2 100 100""" -> """No""",
"""2
5 1 1
100 1 1"""->"""No""");
 
  def test():String= {
    return tests.map{case (i,o)=>(i.trim(),o.trim())}.zipWithIndex.map{case ((input,outputExpect),i)=>{
      val output=solve(input).trim();
      s"test${i+1}:"+(if(output==outputExpect){
        "Passed"
      }else{
        s"Failed\nexpect:\n${outputExpect}\noutput:\n${output}"
      })
    }}.mkString("\n");
  }
}

Measured memory_bytes: 95792
#include <iostream>
#include <algorithm>
#include <string>
#include <math.h>
#include <bitset>
#include <vector>
#include <queue>
#include <map>

#define i64 int64_t
#define ff(ii,nn,mm) for(int ii=nn;ii<mm;ii++)
#define sort(vvv) sort(vvv.begin(),vvv.end())
#define rvs(vvv) reverse(vvv.begin(),vvv.end())
int inf = 1000000007;

using namespace std;

int main() {
	int n;
	cin >> n;
	vector<int> data(n);
	int d2=0, d4=0;
	ff(i, 0, n) {
		cin >> data.at(i);
		if (data.at(i) % 4 == 0) {
			d4++;
			d2++;
		}
		else if (data.at(i) % 2 == 0) {
			d2++;
		}
	}
	if (n % 2 == 1 && d4 > 0) d4++;
	if (d4 + d2 >= n) {
		cout << "Yes" << endl;
	}
	else cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 640
//http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=2015

#include<iostream>
#include<map>
#include<vector>
#include<algorithm>
#include<cmath>
#include<climits>
#include<ctime>
#include<cstring>
#include<numeric>

#define ALL(v) (v).begin(),(v).end()
#define REP(i,p,n) for(int i=p;i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define dump(a) (cerr << #a << "=" << (a) << endl)
#define DUMP(list) cout << "{ "; for(auto nth : list){ cout << nth << " "; } cout << "}" << endl;

using namespace std;

const int MAX = 1500001;

int main()
{
	int N,M;
	while(cin >> N >> M && N)
	{
		vector<int> h(N);
		vector<int> w(M);
		
		rep(i,N){
			cin >> h[i];
		}

		rep(i,M){
			cin >> w[i];
		}

		vector<int> vertical(MAX,0);
		rep(i,h.size())
		{
			int tmp=0;
			REP(j,i,h.size())
			{
				tmp += h[j];
				vertical[tmp]++;
			}
		}

		vector<int> horizontal(MAX,0);
		rep(i,w.size())
		{
			int tmp=0;
			REP(j,i,w.size())
			{
				tmp += w[j];
				horizontal[tmp]++;
			}
		}

		int ans=0;
		rep(i,MAX){
			ans += vertical[i] * horizontal[i];
		}

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

Measured memory_bytes: 12868
#include <iostream>
#include <set>
#include <vector>
#include <string>
#include <algorithm>
#include <iterator>

using namespace std;

#define rep(i, n) for(int i = 0; i < n; i++)
#define repi(i, n) for(auto i = (n).begin(); i != (n).end(); i++)
#define in_arr(type, a, n) copy_n(istream_iterator<type>(cin), n, (a).begin());
#define ll long long int

class Path{
    public:
        int a, b;
};

vector<Path> p;
int n, m;

int count_ans(int ma, int start);

int main(){
    cin >> n >> m;
    p.resize(m);
    repi(i, p){
        *i = Path();
        cin >> (*i).a >> (*i).b;
    }
    cout << count_ans(1, 1) << endl;
    return 0;
}

int count_ans(int ma, int start){
    if(ma == (1 << n) - 1){
        return 1;
    }
    int res = 0;
    repi(i, p){
        if((*i).a == start && ((1 << ((*i).b - 1)) & ma) == 0){
            res += count_ans((1 << ((*i).b - 1)) | ma, (*i).b);
        }else if((*i).b == start && (1 << ((*i).a - 1) & ma) == 0){
            res += count_ans((1 << ((*i).a - 1)) | ma, (*i).a);
        }
    }
    return res;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>
#include <string>
using namespace std;
#define ll long long

int main(int argc, const char * argv[]) {
    // insert code here...
    
    int N;
    vector<ll> march(5,0);
    cin >> N;
    
    vector<ll> c3 = {0,0,0,1,4,10};
    
    string temp;
    for (int i=0; i<N; i++) {
        cin >> temp;
        switch (temp[0]) {
            case 'M':
                march[0]+=1;
                break;
            case 'A':
                march[1]+=1;
                break;
            case 'R':
                march[2]+=1;
                break;
            case 'C':
                march[3]+=1;
                break;
            case 'H':
                march[4]+=1;
                break;
            default:
                break;
        }
    }
    int count = 0;
    for (int i=0; i<5; i++) {
        if (march[i] > 0) {
            count += 1;
        }
    }
    if (count < 3) {
        cout << "0" << endl;
        return 0;
    }
    
    ll ans = 0;
    
    for (int i=0; i<5; i++) {
        for (int j=i+1; j<5; j++) {
            for (int k=j+1; k<5; k++) {
                ans += march[i]*march[j]*march[k];
            }
        }
    }
    
    
    cout << ans << endl;
    
    return 0;
}

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

int main()
{
    std::string S;
    std::cin >> S;
    int length = S.length();
    int tempcount=0,count=0;
    for(int i=0; i<length; i++){
        if(S[i]=='A' || S[i]=='G' || S[i]=='T' || S[i]=='C'){
            tempcount++;
        }else{
            if(count <= tempcount){
                count = tempcount;
            }
            tempcount=0;
        }
    }
    if(count <= tempcount){
        count = tempcount;
    }
    std::cout << count <<std::endl;
    return 0;
}

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

int main() {
  vector<string> vec(1);
  cin >> vec.at(0);
  
  if (vec.at(0) == "AAA") {
    cout << "No" << endl;
  } else if (vec.at(0) == "BBB") {
    cout << "No" << endl;
  } else {
    cout << "Yes" << endl;
  }
  
}


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

// macros
#define ll long long int
#define pb emplace_back
#define mk make_pair
#define pq priority_queue
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define rep(i, n) FOR(i, 0, n)
#define rrep(i, n) for(int i=((int)(n)-1);i>=0;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 FI first
#define SE second
using namespace std;

//  types
typedef pair<int, int> P;
typedef pair<ll, int> Pl;
typedef pair<ll, ll> Pll;
typedef pair<double, double> Pd;
 
// constants
const int inf = 1e9;
const ll linf = 1LL << 50;
const double EPS = 1e-10;
const int mod = 1e9 + 7;

// solve
template <class T>bool chmax(T &a, const T &b){if(a < b){a = b; return 1;} return 0;}
template <class T>bool chmin(T &a, const T &b){if(a > b){a = b; return 1;} return 0;}
template <typename T> istream &operator>>(istream &is, vector<T> &vec){for(auto &v: vec)is >> v; return is;}

template <typename T>
struct edge{int from, to; T cost;};

template <typename T>
struct Graph{
  int n;
  vector<T> d;
  vector<edge<T>> es;
  Graph(int n_){
    n = n_;
    d.resize(n, numeric_limits<T>::max());
  }
  void adde(edge<T> e){
    es.push_back(e);
  }
  bool bellman_ford(int s){
    T maxim = numeric_limits<T>::max();
    fill(d.begin(), d.end(), maxim);
    d[s] = 0;
    for(int i = 0; i < n; i++){
      bool update = false;
      for(auto e: es){
        if(d[e.from] != maxim && d[e.to] > d[e.from] + e.cost){
          d[e.to] = d[e.from] + e.cost;
          update = true;
          if(i == n - 1)return false;
        }
      }
      if(!update)break;
    }
    return true;
  }
};

int main(int argc, char const* argv[])
{
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n, m, r;
  cin >> n >> m >> r;
  Graph<ll> graph(n);
  rep(i, m){
    int a, b, d;
    cin >> a >> b >> d;
    graph.adde(edge<ll>{a, b, d});
  }
  int t = graph.bellman_ford(r);
  if(!t)cout << "NEGATIVE CYCLE" << endl;
  else {
    rep(i, n){
      if(graph.d[i] != numeric_limits<ll>::max())cout << graph.d[i] << endl;
      else cout << "INF" << endl;
    }
  }
	return 0;
}



Measured memory_bytes: 3200
# coding: UTF-8

alphabets = "abcdefghijklmnopqrstuvwxyz"

while input = gets
   26.times.with_index do |i|
       output = input.chomp.tr("a-z", alphabets.split("").rotate(i).join)
       puts output if output =~ /th(e|is|at)/
   end
end

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

using namespace std;

string S;

int main(void)
{
    cin >> S;
    int ans = 0;
    int cnt = 0;

    do {
        cnt = 0;
//        cout << S << endl;
        for(int i = 0; i < S.size()-1; i++) {
            if(S[i] != S[i + 1]) {
                S.erase(i,2);
                cnt += 2;
                break;
            }
        }
        ans += cnt;
    } while(cnt > 0 && S.size() >= 2);
    cout << ans << endl;
}




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

using namespace std;

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

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

    cout<<a[n-1]-a[0];
    return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/math/common_factor_rt.hpp>
using namespace boost::multiprecision;
using namespace std;
using LL = long long;
string start;
bool flag = false;
void da(int i,int e){
    if((e-i)<=1){
        cout<<e<<endl;
        string c;cin >> c;
        return;
    }
    int s = (e-i)/2;
    cout<<i+s<<endl;
    string c;cin >> c;
    if(c=="Vacant")return;
    if(s%2==0){
        if(start==c){
            start = c;
            da(i+s,e);
        }else{
            da(i,i+s);
        }
    }else{
        if(start!=c){
            start = c;
            da(i+s,e);
        }else{
            da(i,i+s);
        }
    }
}
void culu(int i,int e){
    if(e-i<=1){
        cout<<e<<endl;
        return;
    }
    int s = (e -i)/2;
    cout<<i+s<<endl;
    string c;cin >> c;
    if(c=="Vacant")return;
    if(s%2==0){
        if(start==c){
            start = c;
            //cout<<"T"<<endl;
            culu(i+s,e);
        }else{
            //cout<<"F"<<endl;
            da(i,i+s);
        }
    }else{
        if(start!=c){
            //cout<<"T"<<endl;
            start = c;
            culu(i+s,e);
        }else{
            //cout<<"F"<<endl;
            da(i,i+s);
        }
    }
}
int main()
{
    LL N;cin >> N;
    cout<<0<<endl;
    cin >> start;
    culu(0,N-1);
    return 0;
}


Measured memory_bytes: 852
#include <stdio.h>
int main(){
	int n,i;
	int fib[45];
	fib[0] = 1;
	fib[1] = 1;

	
	for(i=2; i<=44; i++){
		fib[i] = fib[i-1]+fib[i-2];
	}
	scanf("%d",&n);
	printf("%d\n",fib[n]);
	return 0;
}



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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcountll

#define INF 1e16
#define mod 1000000007

struct add{
  ll i,j,val;
};

ll N,Q;
ll A[3001];
ll x[3001],y[3001];
ll p2[5001];
ll last[3001][3001];
ll dp[3001][3001];

ll extract(ll i,ll j,ll t){
  if(t-last[i][j]>1){
    dp[i][j]*=p2[t-last[i][j]-1];
    dp[i][j]%=mod;
  }
  last[i][j]=t;
  return dp[i][j];
}

void adding(ll i,ll j,ll v,ll t){
  if(t-last[i][j]>1){
    dp[i][j]*=p2[t-last[i][j]-1];
    dp[i][j]%=mod;
  }
  last[i][j]=t;
  (dp[i][j]+=v)%=mod;
}

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

  p2[0]=1;
  rep(i,5000)p2[i+1]=p2[i]*2%mod;

  cin>>N>>Q;
  rep(i,N)cin>>A[i];
  rep(i,Q){
    cin>>x[i]>>y[i];
    x[i]--; y[i]--;
    if(x[i]>y[i])swap(x[i],y[i]);
  }

  rep(i,N)rep(j,N){
    if(A[i]<A[j])dp[i][j]=1;
  }

  memset(last,-1,sizeof(last));

  rep(i,Q){
    vector<add> ads;
    rep(a,N){
      if(a==x[i]||a==y[i])continue;
      ads.push_back((add){y[i],a,extract(x[i],a,i)});
      ads.push_back((add){a,y[i],extract(a,x[i],i)});

      ads.push_back((add){x[i],a,extract(y[i],a,i)});
      ads.push_back((add){a,x[i],extract(a,y[i],i)});
    }
    ads.push_back((add){x[i],y[i],extract(y[i],x[i],i)});
    ads.push_back((add){y[i],x[i],extract(x[i],y[i],i)});

    for(add a : ads)adding(a.i,a.j,a.val,i);
  }

  ll res=0;
  rep(i,N)rep(j,N){
    if(j<i){
      (res+=extract(i,j,Q))%=mod;
    }
  }
  cout<<res<<endl;

  return 0;
}


Measured memory_bytes: 141888
n,m,c=map(int,input().split())
b=input().split()
for i in range(m):
  b[i]=int(b[i])
  
ans=0
for i in range(n):
  a=input().split()
  t=c
  for j in range(m):
    a[j]=int(a[j])
    t+=a[j]*b[j]
  if t>0:
    ans+=1
print(ans)
      

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

ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
constexpr int mod = 1e9 + 7;

// clang-format off
struct mint {
  ll x; // typedef long long ll;
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  mint &operator+=(const mint a) { if ((x += a.x) >= mod) x -= mod; return *this; }
  mint &operator-=(const mint a) { if ((x += mod - a.x) >= mod) x -= mod; return *this; }
  mint &operator*=(const mint a) { (x *= a.x) %= mod; return *this; }
  mint operator+(const mint a) const { mint res(*this); return res += a; }
  mint operator-(const mint a) const { mint res(*this); return res -= a; }
  mint operator*(const mint a) const { mint res(*this); return res *= a; }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t >> 1);
    a *= a; if (t & 1) a *= *this;
    return a; }
  mint inv() const { return pow(mod - 2); }
  mint &operator/=(const mint a) { return (*this) *= a.inv(); }
  mint operator/(const mint a) const { mint res(*this); return res /= a; }
  friend ostream &operator<<(ostream &os, const mint &a) { os << a.x; return os; }
  friend istream &operator>>(istream &is, mint &a) { is >> a.x; return is; }
};
struct combination {
  vector<mint> fact, ifact;
  combination(int n) : fact(n + 1), ifact(n + 1) {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i - 1] * i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i - 1] = ifact[i] * i;
  }
  mint operator()(int n, int k) { if (k < 0 || k > n) return 0; return fact[n] * ifact[k] * ifact[n - k]; }
};
// clang-format on

int top(int n) {
  while (n >= 10) { n /= 10; }
  return n;
}
int last(int n) { return (n % 10); }

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

  vector<vector<int>> c(10, vector<int>(10, 0));
  for (int k = 1; k <= n; ++k) {
    string s = to_string(k);
    int i = s.front() - '0';
    int j = s.back() - '0';
    c[i][j]++;
  }

  ll num = 0;
  for (int i = 0; i < 10; ++i) {
    for (int j = 0; j < 10; ++j) { num += c[i][j] * c[j][i]; }
  }

  cout << num << endl;
}


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

typedef struct Card{
    char name[1];
    int val;
} Card;

void swap(Card* A, Card* B){
    Card C = *A;
    *A = *B;
    *B = C;
}

int Divide(Card A[], int low, int high){
    int i = low-1;
    for(int j=low; j<high; j++){
        if(A[j].val <= A[high].val){
            i++;
            swap(&A[i],&A[j]);
        }
    }
    swap(&A[i+1],&A[high]);

    return i+1;
}

void QuickSort(Card A[], int low, int high){
    if(low < high){
        int mid = Divide(A,low,high);
        QuickSort(A,low,mid-1);
        QuickSort(A,mid+1,high);
    }
}

bool Stability(Card A[], Card B[], int n){
    // Card Deck with no overlapping-value cards
    int tmp[n];
    int tmp_size = 0;
    for(int i=0; i<n; i++){
        if(A[i].val != A[i+1].val){
            tmp[tmp_size] = A[i].val;
            tmp_size++;
        }
    }
    // Check for stability 
    for(int i=0; i<tmp_size; i++){    
        Card a[n], b[n];
        int count_a = 0, count_b = 0;

        for(int j=0; j<n; j++){
            if(tmp[i] == A[j].val){
                a[count_a] = A[j];
                count_a++;
            }
            if(tmp[i] == B[j].val){
                b[count_b] = B[j];
                count_b++;
            }
        }

        for(int i=0; i<count_a; i++){
            if(a[i].name[0] != b[i].name[0])
                return 0;
        }
    }
    return 1;
}

void copyCard(Card A[], Card B[], int n){
    for(int i=0; i<n; i++)
        B[i] = A[i];
}

void printCard(Card A[], int n){
    for(int i=0; i<n; i++)
        printf("%s %d\n",A[i].name,A[i].val);
}


int main(){
    int n;
    scanf("%d",&n);
    Card A[n], B[n];
    for(int i=0; i<n; i++)
        scanf("%s %d",A[i].name,&A[i].val);

    copyCard(A,B,n);
    QuickSort(A,0,n-1);
    
    if(Stability(A,B,n) == 1)
        printf("Stable\n");
    else
        printf("Not stable\n");
    printCard(A,n);

    return 0;
}


Measured memory_bytes: 3396
S =  list(input())
R =[0 for i in range(len(S))]
L =[0 for i in range(len(S))]
ans=[0 for i in range(len(S))]
r_cnt=0
l_cnt=0
for i in range(len(S)):
    if S[i]=="R":
        r_cnt+=1
    else:
        if r_cnt!=0:
            R[i]+=r_cnt//2
            R[i-1]+=r_cnt-r_cnt//2
            r_cnt=0
S.reverse()
for i in range(len(S)):
    if S[i] == "L":
        l_cnt+=1
    else:
        if l_cnt!=0:
            L[i]+=l_cnt//2
            L[i-1]+=l_cnt-l_cnt//2
            l_cnt=0
L.reverse()

for i in range(len(S)):
    ans[i]+=R[i]+L[i]
print(*ans)



Measured memory_bytes: 8632
import java.util.*;
import java.io.*;
public class Main
{
    public static void main(String []args) throws IOException {
    	FastScanner in  = new FastScanner(System.in);
    	PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)), false); 
    	solve(in, out);
    	in.close();
    	out.close();
    }
    static long gcd(long a, long b){ return (b==0) ? a : gcd(b, a%b); }
    static int gcd(int a, int b){ return (b==0) ? a : gcd(b, a%b); }
    
    public static int[] generatePrimes(int n) {
		boolean[] prime = new boolean[n + 1];
		Arrays.fill(prime, 2, n + 1, true);
		for (int i = 2; i * i <= n; i++)
			if (prime[i])
				for (int j = i * i; j <= n; j += i)
					prime[j] = false;
		int[] primes = new int[n + 1];
		int cnt = 0;
		for (int i = 0; i < prime.length; i++)
			if (prime[i])
				primes[cnt++] = i;
		return Arrays.copyOf(primes, cnt);
	}
    static class FastScanner{
	BufferedReader reader;
	StringTokenizer st;
	FastScanner(InputStream stream){reader=new BufferedReader(new InputStreamReader(stream));st=null;}	
	String next(){while(st == null || !st.hasMoreTokens()){try{String line = reader.readLine();if(line == null){return null;}		    
	     st = new StringTokenizer(line);}catch (Exception e){throw new RuntimeException();}}return st.nextToken();}
	String nextLine()  {String s=null;try{s=reader.readLine();}catch(IOException e){e.printStackTrace();}return s;}	    	  	
	int    nextInt()   {return Integer.parseInt(next());}
	long   nextLong()  {return Long.parseLong(next());}		
	double nextDouble(){return Double.parseDouble(next());}
	char   nextChar()  {return next().charAt(0);}
	int[]  nextIntArray(int n)         {int[] arr= new int[n];   int i=0;while(i<n){arr[i++]=nextInt();}  return arr;}
	long[] nextLongArray(int n)        {long[]arr= new long[n];  int i=0;while(i<n){arr[i++]=nextLong();} return arr;}	
	int[]  nextIntArrayOneBased(int n) {int[] arr= new int[n+1]; int i=1;while(i<=n){arr[i++]=nextInt();} return arr;}	    	
	long[] nextLongArrayOneBased(int n){long[]arr= new long[n+1];int i=1;while(i<=n){arr[i++]=nextLong();}return arr;}	    	
	void   close(){try{reader.close();}catch(IOException e){e.printStackTrace();}}				
    }
    
    /********* SOLUTION STARTS HERE ************/
    
    private static void solve(FastScanner in, PrintWriter out){
        out.println(Math.max(0L,in.nextLong() - (2*in.nextLong())));
    }
    /************* SOLUTION ENDS HERE **********/
}

Measured memory_bytes: 22484
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
typedef long double ld;
const ll INF = 1e+14;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
#define fr first
#define sc second
#define all(c) c.begin(),c.end()
#define pb push_back

void Yes(){
	cout<<"Yes"<<endl;
	exit(0);
}

void No(){
	cout<<"No"<<endl;
	exit(0);
}

int main(){
  ll X,Y;
  cin>>X>>Y;
  ll Z;
  Z=Y/2;
  ll ans=X+Z;
  cout<<ans<<endl;
}
  
    

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

int main() {
	std::string x;
	std::cin >> x;
	
	std::string y;
	std::cin >> y;

	int count = 0;
	for (int i = 0; i < x.length(); i++ ) {
		if(x[i] != y[i])
			count += 1;
	}
	cout <<count;
}


Measured memory_bytes: 3912
#include<iostream>
#include<stdio.h>
#include<string>
#include<vector>
#include<map>
#include<tuple>
#include<algorithm>
#include<cmath>
#include<limits>
#include<set>
#include<queue>
using namespace std;
#define int long  long int
#define ll long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }

signed main() {
	int num;
	cin >> num;
	vector<int>v(4);
	v[0] = num / 1000;
	v[1] = (num / 100) % 10;
	v[2] = (num / 10) % 10;
	v[3] = num % 10;
	int sum;
	char ch[3];
	for (int i = 0; i < (1 << 3); i++) {
		sum = v[0];
		for (int j = 1; j <= 3; j++) {
			if ((i >> (j - 1)) & 1) {
				sum += v[j];
				ch[j - 1] = '+';
			}
			else {
				sum -= v[j];
				ch[j - 1] = '-';
			}
		}
		if (sum == 7) {
			cout << v[0] << ch[0] << v[1] << ch[1] << v[2] << ch[2] << v[3] << "=7";
			return 0;
		}
	}
}

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

int main() {

	int h, w;
	cin >> h >> w;
	vector<string> a(h);
	for (int i = 0; i < h; i++) 
		cin >> a[i];

	vector<vector<int>> dp(h, vector<int>(w, 0));
	
	dp[0][0] = a[0][0] == '#' ? 1 : 0;
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			if (i == 0 && j == 0)
				continue;
			if (i == 0 && j > 0)
				dp[i][j] = dp[i][j-1] + (a[i][j] != a[i][j-1]);
			else if (i > 0 && j == 0)
				dp[i][j] = dp[i-1][j] + (a[i-1][j] != a[i][j]);
			if (i > 0 && j > 0) {
				if (dp[i-1][j] < dp[i][j-1]) {
					dp[i][j] = dp[i-1][j] + (a[i-1][j] != a[i][j]);
				} else {
					dp[i][j] = dp[i][j-1] + (a[i][j] != a[i][j-1]);
				}
			}
		}
	}

	int ans = (dp[h-1][w-1] / 2) + (dp[h-1][w-1] % 2 > 0);
	cout << ans << endl;

	// for (auto nums : dp) {
	// 	for (auto n : nums) {
	// 		cout << n << " ";
	// 	}
	// 	cout << "\n";
	// }

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <bits/stdc++.h>
#include <algorithm>
#include <complex>
#define FIXED_FLOAT(x)  std::fixed <<std::setprecision(7)<<(x)
#define fast ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)

using namespace  std;

using ll = long long;
const ll mod = 1e9 + 7;
typedef pair<int , int > pairs;
typedef complex<ll> G;
const int N=2e5+5;

const ll INF = 1e18;

void done() {
    int n;cin >> n;
    set<int>ans;
    for(int i=0;i < n;i++) {
        int a;cin >> a;
        ans.insert(a);
    }
    if(ans.size()==n)cout << "YES";
    else cout << "NO";

}
void solve() {

    int n;
    cin >>n;
    vector<int>a(n);
    vector<int>b(n);
    vector<long double>c;
    for(int i=0;i < n;i++) {
        cin >> a[i];
    }
    int r = 0;
    for(int i=0;i < n;i++) {
        cin >> b[i];
        if(a[i]!=0) {
            c.push_back(b[i]/a[i]*1.0);
        }else if(b[i]=='0') {
            r++;
            c.push_back(-999999999);
        }
        else {
            c.push_back(-999999999);
        }
    }
    int sum = 1;
    int best = 0;
    sort(c.begin(), c.end());
    for(int i=1;i < n;i++) {
        if(c[i]==c[i-1] && c[i-1]!=-999999999) {
                sum++;
        }
        else {
            if(sum > best && c[i-1]!=-999999999) {
                best = sum;
                sum = 1;
            }
        }
    }
    if(sum > best && c[n-1]!=-999999999) {
        best = sum;
    }
    cout << best+r << '\n';
}
void another() {
    int n;cin >> n;

    string s;
    cin >> s;
    int left= 0, right = 0;
    int d = (s[0]=='<') ?1 : 0;
    int c = (s[n-1]=='>')?1 : 0;

    for(int i=0;i < n;i++) {
        if(i!=0 && s[i]=='<')left++;
        else if(i!=n-1 && s[i]=='>')right++;
    }
    if(left <= right) {
        swap(left, right);
        swap(d, c);
    }
    if(d) {
        cout << max(1, right-1) << '\n';
    }
    else cout << max(0, right-1) << '\n';



}
void test_case() {
    int t;
    cin >> t;
    while(t--)solve();
}
int main() {

    fast;
    done();

}



Measured memory_bytes: 13064
// 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)
using namespace std;
//kaewasuretyuui
typedef long long ll;
//#define int ll
typedef ll 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,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};
int main(){
	ll n,a,b;
	while(cin>>n>>a>>b,n){
		a--;b--;
		vi q(n);
		ll T=a;
		rep(i,n){
			ll t=1ll<<(n-1-i);
			q[i]=T<t;
			T=max(t-T-1,T-t);
//			cout<<q[i]<<" "<<T<<endl;
		}
		rep(i,n){
			ll t=1ll<<(n-1-i);
			if(b<t&&q[n-1-i]){
				cout<<"L";
				b=t-b-1;
			}else if(t<=b&&q[n-1-i]==0){
				cout<<"L";
				b=b-t;
			}else if(b<t&&q[n-1-i]==0){
				cout<<"R";
				b=b;
			}else if(t<=b&&q[n-1-i]){
				cout<<"R";
				b=2*t-b-1;
			}
		}
		cout<<endl;
	}
}








Measured memory_bytes: 2972
#include<bits/stdc++.h>
#include<numeric>
#include<cassert>
#include <boost/multiprecision/cpp_int.hpp>
#define ll long long int
#define CON 100010
const long long mod=1e9+7;
const int INF=1001001001;
//const ll inf=1e9+7;
//const ll ful=1e18;
using namespace std;

//namespace mp = boost::multiprecision;
int main() 
{
	ll x,y;
	cin>>x>>y;
	bool flag=false;
	for(int i=0;i<=x;i++)
	{
		if(2*i+4*(x-i)==y) flag=true;
	}
	if(flag) cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 3620
#include "bits/stdc++.h"

using namespace std;

using ll = long long;
using ld = long double;

const int INF = (1 << 30) - 1;
const ll INF64 = ((ll)1 << 62) - 1;
const double PI = 3.1415926535897932384626433832795;

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

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

	int n, q;
	cin >> n >> q;

	vector<int> a(n);
	for (auto& v : a) {
		cin >> v;
	}

	for (int i = 0; i < q; i++) {
		ll x;
		cin >> x;

		ll res = 0, knyackiSum = 0;
		int right = 0;
		for (int left = 0; left < n; left++) {
			while (right < n && knyackiSum + a[right] <= x) {
				knyackiSum += a[right];
				right++;
			}

			res += abs(right - left);

			if (left == right) {
				right++;
			} else {
				knyackiSum -= a[left];
			}
		}

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



Measured memory_bytes: 3336
N = int(input())

lst = []
i = 1
sm = 0
while sm < N:
  lst.append(i)
  sm += i
  i += 1
  
if sm == N:
  for l in lst:
    print(l)
else:
  a = sm - N
  lst.remove(a)
  for l in lst:
    print(l)

Measured memory_bytes: 74376
#include <cstdio>
#include <iostream>
#include <algorithm>
using namespace std;
int s[1111];
int main(void){
  for(int i = 1; i <= 1000; i++) s[i] = i+s[i-1];
  int n;
  while(cin >> n && n){
    int c = 0;
    for(int i = 1; i <= n; i++){
      for(int j = 0; j < i-1; j++){
	if(s[i]-s[j] == n) c++;
      }
    }
    cout << c << endl;
  }
}

Measured memory_bytes: 1164
#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;
int n,k;
int main()
{
	cin>>k; int cnt=0;
	for(int i=1;i<=k;i++){
		n=(n*10+7)%k; ++cnt;
		if(!n){cout<<cnt<<endl;return 0;}
	} puts("-1");
	return 0;
}

Measured memory_bytes: 3612
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<climits>
using namespace std;

int n;
long long a,b;
long long x[111111],y;
long long ans;

int main(){

  scanf(" %d %lld %lld",&n,&a,&b);

  x[0]=0;
  scanf(" %lld",&y);
  for(int i=1;i<n;i++){
    scanf(" %lld",&x[i]);
    x[i]-=y;
    y+=x[i];
  }

  /*                                                                            
  for(int i=0;i<n;i++){                                                         
    printf(" %lld",x[i]);                                                       
  }                                                                             
  cout << endl;                                                                 
  */

  //  printf(" %lld %lld\n",a,b);                                               

  ans=0;
  for(int i=1;i<n;i++){
    if(a*x[i]<b){
      ans+=a*x[i];
    }else{
      ans+=b;
    }
  }

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

  return 0;

}

Measured memory_bytes: 1024
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from heapq import heapify, heappop, heappush

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
 
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

S, T = S_MAP()
A, B = MAP()
U = input()

dic = defaultdict(int)
dic[S] = A
dic[T] = B
if dic[U] > 0:
    dic[U] -= 1
print(dic[S], dic[T])

Measured memory_bytes: 3944
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define pi 3.141592653589793238
#define int long long
using namespace __gnu_pbds;
using namespace std;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;


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

#ifndef ONLINE_JUDGE
	if(fopen("INPUT.txt","r"))
	{
	freopen ("INPUT.txt" , "r" , stdin);
	freopen ("OUTPUT.txt" , "w" , stdout);
	}
#endif  

	int a,b,c;
	cin>>a>>b>>c;
	map<pair<int,pair<int,int> >,int>mm;
	pair<int,pair<int,int> > s={a,{b,c}};
	int cnt=0;
	while (!mm[s])
	{
		if((s.first&1)||(s.second.first&1)||(s.second.second&1))
		{
			cout<<cnt<<endl;
			return 0;
		}
		pair<int,pair<int,int> > t;
		t.first=(s.second.first/2+s.second.second/2);
		t.second.first=(s.first/2+s.second.second/2);
		t.second.second=(s.second.first/2+s.first/2);
		mm[s]=1;
		s=t;
		cnt++;
	}
	cout<<-1;
	

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
using namespace std;
 
int solve(int n, int arr[]){
  int dp[n];
  if(n == 1) return 0;
  dp[0] = 0;
  if(n == 2) return abs(arr[1] - arr[0]);
  dp[1] = abs(arr[1] - arr[0]);
  if(n == 3) return abs(arr[2] - arr[0]);
  dp[2] = abs(arr[2] - arr[0]);
  for(int i = 3; i < n; i++){
    dp[i] = min(abs(arr[i]-arr[i-1])+dp[i-1], abs(arr[i]-arr[i-2])+dp[i-2]);
  }
  return dp[n-1];
}
 
signed main(){
  int n;
  cin >> n;
  int arr[n];
  for(int i = 0; i < n; i++){
    cin >> arr[i];
  }
  cout << solve(n, arr) << "\n";
}

Measured memory_bytes: 5140
#include<stdio.h>

int main() {
	
	int n, a[106] = {},memo=100000,result=0,count=1;
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		scanf("%d", &a[i]);
	}
	for (int i = 0; i < n; i++) {
		
		if (memo == a[i]) {
			count++;
		}
		else {
			result = (count / 2)+result;
			count = 1;
			memo=a[i];
		}
	}
  result = (count / 2)+result;
	printf("%d", result);
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repr(i,n) for(int i = (int)(n); i >= 0; i--)
#define all(v) v.begin(),v.end()
typedef long long ll;

struct union_find{
    vector<int> par;
    vector<int> rank;
    vector<int> siz;
    
    union_find(int N) : par(N), rank(N), siz(N){
        rep(i,N){
            par[i] = i;
            rank[i] = 0;
            siz[i] = 1;
        }
    }
    
    int root(int x){
        if (par[x] == x){
            return x;
        }
        return par[x] = root(par[x]);
    }
    
    void unite(int x, int y){
        int rx = root(x);
        int ry = root(y);
        if (rx == ry) return;
        if (rank[rx] < rank[ry]){
            par[rx] = ry;
            siz[ry] += siz[rx];
        }
        else{
            par[ry] = rx;
            siz[rx] += siz[ry];
            if (rank[rx] == rank[ry]) rank[rx]++;
        }
    }
    
    bool same(int x, int y){
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
    
    int size(int x){
        return siz[root(x)];
    }
};

int main(){
    int N,M;
    cin >> N >> M;
    vector<int> vec(N);
    rep(i,N){
        cin >> vec[i];
    }
    vector<int> detect(N);
    rep(i,N){
        detect[vec[i] - 1] = i;
    }
    union_find tree(N);
    rep(i,M){
        int x,y;
        cin >> x >> y;
        x--;
        y--;
        tree.unite(x,y);
    }
    int ans = 0;
    rep(i,N){
        if (tree.same(detect[i], i)) ans++;
    }
    cout << ans << endl;
}


Measured memory_bytes: 4964
using System;
using System.Linq;
using System.Collections.Generic;
public class Hello
{

    static void swap(ref long a, ref long b)
    {
        long box;
        box = a;
        a = b;
        b = box;
    }


    public static void Main()
    {
        int N = int.Parse(Console.ReadLine());
        long ans = 1;
        long max, min, r,m_1,m_2;
        for (int i = 0; i < N; i++)
        {
            max = long.Parse(Console.ReadLine());
            min = ans;
            if (max == min) continue;
            if (max < min) swap(ref max, ref min);
            m_1 = max;
            m_2 = min;
            r = max % min;

            while (r != 0)
            {
                max = min;
                min = r;
                r = max % min;
            }

            ans = m_1 / min;
            ans = ans * m_2;

        }
        Console.WriteLine(ans);
    }
}

Measured memory_bytes: 13140
#include <iostream>
#include <vector>

int main(){
std::vector<int> number;
	int inputNum,tmp;


	std::cin >> inputNum;

	for(int i = 0; i < inputNum; ++i){
		std::cin >> tmp;
		number.push_back(tmp);
	}

	std::vector<std::vector<long int>> vec(inputNum + 1, std::vector<long int>(21, 0));

	vec[0][number[0]] = 1;

	for(int i = 0; i < inputNum; ++i){
		for(int j = 0; j < 21; j++){
			if(vec[i][j] != 0){
				if(j + number[i + 1] <= 20){
					vec[i+1][j + number[i + 1]] += vec[i][j];
				}
				if(j - number[i + 1] >= 0){
					vec[i+1][j - number[i + 1]] += vec[i][j];
				}
			}
		}
	}

	std::cout << vec[inputNum - 2][number[inputNum - 1]] << std::endl;

	return 0;
}

Measured memory_bytes: 1236
/**
     **author : _KMS_
     **created : 14-03-2020
**/
#include<bits/stdc++.h>
using namespace std;
const long long M =1e5+100,MOD=2e9;
typedef long long ll;
string s,p,qq;

int main() 
{ 
      
 ios::sync_with_stdio(false);
 cin.tie(0);
 int l=-1,r=0;
 cin>>s;
 for(int i=0;i<s.size();i++)
 {
       if(s[i]=='A'&&l==-1)l=i;
       else if(s[i]=='Z'&&l!=-1)r=i;
 }
 cout<<r-l+1<<"\n";

	return 0; 
} 

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

int main(){
  int s,count=1;
  cin >> s;
  map<int,int> m;
  m[s]++;
  while(1){
    if(s%2==0)s/=2;
    else s=s*3+1;
    m[s]++;
    count++;
    if(m[s]==2)break;
  }
  cout << count << endl;
}


Measured memory_bytes: 256
#!/usr/bin/env python3
import sys

N=0
M=0

def next_num(x):
    if int(x[-1]) < M:
        return x[:-1] + [str(int(x[-1]) + 1)]
    elif int(x[-1]) == M:
        oya = next_num(x[:-1])
        return oya + [oya[-1]]


def solve(N: int, M: int, Q: int, a: "List[int]", b: "List[int]", c: "List[int]", d: "List[int]"):
    start = ['1' for i in range(N)]
    current = start
    ans = 0
    while True:
        result = 0
        for a_, b_, c_, d_ in zip(a, b, c, d):
            if int(current[b_]) - int(current[a_]) == c_:
                result += d_
        if result > ans:
            ans = result
        if current[0] == str(M):
            break
        current = next_num(current)
    print(ans)
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    global N, M
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    Q = int(next(tokens))  # type: int
    a = [int()] * (Q)  # type: "List[int]"
    b = [int()] * (Q)  # type: "List[int]"
    c = [int()] * (Q)  # type: "List[int]"
    d = [int()] * (Q)  # type: "List[int]"
    for i in range(Q):
        a[i] = int(next(tokens)) - 1
        b[i] = int(next(tokens)) - 1
        c[i] = int(next(tokens))
        d[i] = int(next(tokens))
    solve(N, M, Q, a, b, c, d)

if __name__ == '__main__':
    main()


Measured memory_bytes: 9328
from collections import Counter

N=int(input())
S = [input() for i in range(N)]
result=[]

counter = Counter(S)
m = max(counter.values())

for name in counter.keys():
    if m==counter[name]:
        result.append(name)

result_sort=sorted(result)

for i in range(len(result_sort)):
    print(result_sort[i])

Measured memory_bytes: 35564
# Problem C - Guess The Number

# input
N, M = map(int, input().split())

# initialization
keta = 0
if N==0:
    keta = 1
else:
    keta = N
keta_list = [-1]*keta
input_ok = True
for i in range(M):
    s, c = map(int, input().split())
    if not keta_list[s-1]==-1:
        if not keta_list[s-1]==c:
            input_ok = False
            break
    else:
        keta_list[s-1] = c
if keta>1 and keta_list[0]==0:
    input_ok = False

if input_ok:
    if keta==1:
        if keta_list[0]==-1:
            print(0)
        else:
            print(keta_list[0])
    else:
        ans = 100000
        for n in range(1000):
            tmp_keta = len(str(n))
            if tmp_keta==keta:
                tmp = ''
                for i in range(len(keta_list)):
                    if i==0 and keta_list[i]==-1:
                        tmp += '1'
                    elif keta_list[i]==-1:
                        tmp += '0'
                    else:
                        tmp += str(keta_list[i])
                tmp = int(tmp)
                ans = min(ans, tmp)
        print(ans)
else:
    print(-1)


Measured memory_bytes: 3064