akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <cassert>
#include <cstring>
#include <iostream>
#include <vector>
#include <set>

using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define TRACE(x) cout << #x << " = " << x << endl
#define _ << " _ " <<

typedef long long llint;

const int MAX = 100100;

bool bio[MAX];
vector<int> E[MAX];

vector<int> v;

void dfs(int x) {
  if (bio[x]) return;

  bio[x] = true;
  v.push_back(x);

  for (int y: E[x]) {
    dfs(y);
  }
}

int main(void) {
  int N, M;
  scanf("%d %d", &N, &M);

  vector<int> p(N);
  REP(i, N) {
    scanf("%d", &p[i]);
    --p[i];
  }

  REP(i, M) {
    int a, b;
    scanf("%d %d", &a, &b);
    --a, --b;
    E[a].push_back(b);
    E[b].push_back(a);
  }

  int ret = 0;
  REP(i, N) {
    if (!bio[i]) {
      v.clear();
      dfs(i);

      set<int> vi;
      for (int x: v) vi.insert(p[x]);

      for (int x: v) {
        ret += vi.count(x);
      }
    }
  }

  printf("%d\n", ret);
  return 0;
}


Measured memory_bytes: 14328
#include<bits/stdc++.h>
#include <iostream>
#include <numeric>
#include <math.h>
#define ll  long long
#define ull unsigned long
#define mpa make_pair
#define pb push_back
#define ff first
#define pii pair<ll,ll>
#define dd double
#define trace(x) cerr << #x << " : " << x << endl
#define ss second
#define boost ios_base::sync_with_stdio(0)
#define forp(i,a,b) for(ll i=a;i<=b;i++)
#define rep(i,n)    for(ll i=0;i<n;++i)
#define ren(i,n)    for(ll i=n-1;i>=0;i--)
#define forn(i,a,b) for(ll i=a;i>=b;i--)
#define all(c) (c).begin(),(c).end()
#define tr(c,i) for(typeof((c).begin()) i = (c).begin(); i != (c).end();
#define sc(x) scanf("%lld",&x)
#define clr(x,val) memset(x,val,sizeof(x))
#define pr(x) printf("%lld\n",x) 
#define gc getchar
#define pdd pair<dd,dd>
#define prec(x) cout<<fixed<<setprecision(x)
using namespace std;
int main(){
  ll k;
  string s;
  cin>>k>>s;
  ll n=s.size();
  if(n<=k){
    cout<<s;
  }
  else{
    for(ll i=0;i<k;i++)cout<<s[i];
    cout<<"...";
  }
}

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

using namespace std;


     
#define ll long long int
#define ld long double


#define fr first
#define se second



#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define sz(v) (int)v.size()
#define sunq(v) sort(all(v));v.resize(distance(v.begin(),unique(all(v))))


#define pb push_back
#define mp make_pair

#define debug(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
#define emla(a, val) memset(a, val, sizeof(a))

#define easm(a, b) (a + b - 1)/b 


#define PI 3.141592653589793238
#define E  2.718281828459045235


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


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

const int N = 1e5 + 10;

int dp[N];
vector<int>ad[N];


int solve(int node){
  int &re = dp[node];
  if(re != -1)return re;
  int mx = 0;
  for(auto u : ad[node])
    mx = max(mx, 1 + solve(u));
  re = mx;
  return re;
}


int main(){
  //freopen("input.in", "r", stdin);
  //freopen("output.txt", "w", stdout);
  clock_t z = clock();
  int n, m;
  cin >> n >> m;
  emla(dp, -1);
  for(int i = 0; i < m; i++){
    int x, y;
    cin >> x >> y;
    ad[x].pb(y);
  }
  int mx = 0;
  for(int i = 1; i <= n; i++)
    mx = max(mx, solve(i));
  cout << mx << endl;
  debug("Total Time: %.3f\n", (double)(clock() - z) / CLOCKS_PER_SEC);
  /*
  *try tricky test cases:
    -bounds
    -integer overflow
    -small input (0, 1)
    -big input
    -random tests
  */
  return 0;
}

Measured memory_bytes: 8192
from collections import defaultdict
MOD = 10**9+7
N = int(input())
d = defaultdict(int)

# 階乗のそれぞれの要素について素因数分解する
for i in range(2,N+1):
    p = 2
    x = i
    # 割り切れる間は素因数で割る
    while p * p <= x:
        while x % p == 0:
            d[p] += 1
            x //= p
        p += 1
    # 割り切れなくなったときに残って居たらそれも素因数なので追加する
    if x > 1:
        d[x] += 1
    
ans = 1
for k in d.keys():
    ans *= (d[k] + 1)

print(ans%MOD)

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

int main() {
  int n, m, a, b;
  cin >> n >> m;
  vector<int> data(n);
  for (int i = 0; i < m; i++) {
    cin >> a >> b;
    data.at(a - 1) = data.at(a - 1) + 1; 
    data.at(b - 1) = data.at(b - 1) + 1;
  }
  for (int i = 0; i < n; i++) {
    cout << data.at(i) << endl;
  }
}  

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

int int_len(int n) {
  int s=0;
  while(n!=0) s++, n/=10;
  return s;
}

int int_sum(int n) {
  int m=0,s=0,a=n;
  while(a!=0) s++, a/=10;
  for(int i=s-1;i>=0;i--) m+=n/((int)pow(10,i))-(n/((int)pow(10,i+1)))*10;
  return m;
}


int vec_sum(vector<int> v){
  int n=0;
  for(int i=0;i<v.size();i++) n+=v[i];
  return n;
}

int main() {
  int n,a,b;
  cin>>n>>a>>b;
  if(n>=a+b){
    cout<<min(a,b)<<' '<<0<<endl;
  }else{
    cout<<min(a,b)<<' '<<a+b-n<<endl;
  }
}


Measured memory_bytes: 256
import java.util.*;
import java.util.Scanner;
public class Main{
  public static void main(String[] args){
    Scanner s  = new Scanner(System.in);
    double D = s.nextDouble();
    double T = s.nextDouble();
    double S = s.nextDouble();
    double t = D/S;
    if(t<=T){
      System.out.println("Yes");
    }
     else{
       System.out.println("No");
     }
    
  }
}
  


Measured memory_bytes: 28716
#include <stdio.h>
#include <math.h>

int main(){
  int nm, i, j=0, k, inp, flag=0;

  scanf("%d", &inp);

  for(k = 0; k < inp; k++){
    scanf("%d", &nm);
    flag = 1;
    for(i = 2; i<= sqrt(nm); i++){
      if(nm == 2) break;
      if(nm % i == 0){
        flag = 0;
        break;
      }
    }
    if(flag == 1) j++;
  }
  printf("%d\n", j);

  return 0;
}



Measured memory_bytes: 2048
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;

public class Main
{

  public static void main(String[] args) throws IOException
  {
    BufferedReader r = new BufferedReader(new InputStreamReader(System.in), 1);

    String s;
    String sl[];

    int c[] = new int[100];
    int v[] = new int[100];

    s = r.readLine();
    sl = s.split(" ");
    int n = Integer.parseInt(sl[0]);

    s = r.readLine();
    sl = s.split(" ");
    for(int i = 0; i < n; i++)
    {
      v[i] = Integer.parseInt(sl[i]);
    }

    s = r.readLine();
    sl = s.split(" ");
    for(int i = 0; i < n; i++)
    {
      c[i] = Integer.parseInt(sl[i]);
      v[i] -= c[i];
    }

    Arrays.sort(v);

    int ss = 0;
    for(int i = 99; i >= 0; i--)
    {
      if(v[i] <= 0) break;
      ss += v[i];
    }
    System.out.println(ss);


  }

}

Measured memory_bytes: 21204
// ------------------------------------
// Date:2018/ 2/20
// Problem:ABC 085 Otoshidama c.cpp
//
// ------------------------------------

#include <bits/stdc++.h>

using namespace std;

#define EACH(i,a) for (auto&& i : a)
#define FOR(i,a,b) for(int i=(int)a;i<(int)b;++i)
#define RFOR(i,a,b) for(int i=(int)b-1;i>=(int)a;--i)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)

int main()
{
  int N,Y;
  cin >> N >> Y;
  REP(i10,N+1) {
    REP(i5,N-i10+1) {
      if (i10*10000 + i5*5000 + (N-i10-i5)*1000 == Y) {
        cout << i10 <<  " "  << i5 << " " << N-i10-i5 << endl;
        return 0;
      }
    }
  }
  cout << "-1 -1 -1" << endl;
  return 0;
}


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

using namespace std;

typedef long long int ll;
typedef pair<ll, ll> pll;

#define FOR(i, n, m) for(ll (i)=(m);(i)<(n);++(i))
#define REP(i, n) FOR(i,n,0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll) 1e15;

bool check(string S) {
    ll N = S.length();
    REP(i, N) {
        if (S[i] != S[N - 1 - i])
            return false;
    }

    ll n = (N - 1) / 2;
    REP(i, n) {
        if (S[i] != S[n - 1 - i])
            return false;
    }

    ll m = (N + 3) / 2;
    for (ll i = m - 1; i < N; ++i) {
        if (S[i] != S[N - 1 - i])
            return false;
    }
    return true;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    string S;
    cin >> S;
    if (check(S))
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iostream>
#include <algorithm>
#include <functional>
using namespace std;
 
int main() {
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  int sumA = min(a, b), sumB = min(c, d);
  cout << sumA + sumB << endl;
}

Measured memory_bytes: 256
class dice():
    def __init__(self,men1,men2,men3,men4,men5,men6):
        self.men=[men1,men2,men3,men4,men5,men6]
        self.current_men=1
        self.men_udlr=[5,2,4,3]
        self.move_d=0
        
    def move_dice(self,direction): 
        if direction=="E":
            s=self.men_udlr[2]
            self.men_udlr=[self.men_udlr[0],self.men_udlr[1],
                          7-self.current_men,self.current_men]
            self.current_men=s
        if direction=="N":
            s=self.men_udlr[1]
            self.men_udlr=[self.current_men,7-self.current_men
                           ,self.men_udlr[2],self.men_udlr[3]]
            self.current_men=s
        if direction=="S":
            s=self.men_udlr[0]
            self.men_udlr=[7-self.current_men,self.current_men
                           ,self.men_udlr[2],self.men_udlr[3]]
            self.current_men=s
        if direction=="W":
            s=self.men_udlr[3]
            self.men_udlr=[self.men_udlr[0],self.men_udlr[1]
                           ,self.current_men
                           ,7-self.current_men]
            self.current_men=s
        
    def show_num(self):

        return self.men[self.current_men-1]

m_n=list(map(int,input().split()))
cmd=input()
d=dice(*m_n)
for c in cmd:
    d.move_dice(c)
print(d.show_num())

Measured memory_bytes: 7748
def bsearch_find_max(array,x)
  array[bsearch_index_find_max(array, x)]
end

def bsearch_index_find_max(array, x)
  return nil if array.empty?
  return array.size - 1 if array.last <= x
  index = array.bsearch_index{|a| a > x}
  return nil if index.nil? || index.zero?
  index = index - 1
end

n,m,k = gets.split.map(&:to_i)
tmp_as = gets.split.map(&:to_i)
tmp_bs = gets.split.map(&:to_i)

as = []
tmp_as.each.with_index do |a, i|
  if i == 0
    as[i] = a
  else
    as[i] = as[i-1] + a
  end
end

bs = []
tmp_bs.each.with_index do |b, i|
  if i == 0
    bs[i] = b
  else
    bs[i] = bs[i-1] + b
  end
end

ans = 0
as.each.with_index do |a, a_i|
  leftover = k - a
  break if leftover < 0

  b_i = bsearch_index_find_max(bs, leftover)
  b_cnt = b_i.nil? ? 0 : b_i + 1
  ans = [ans, a_i + 1 + b_cnt].max
end

bs.each.with_index do |a, a_i|
  leftover = k - a
  break if leftover < 0

  b_i = bsearch_index_find_max(as, leftover)
  b_cnt = b_i.nil? ? 0 : b_i + 1
  ans = [ans, a_i + 1 + b_cnt].max
end

puts ans


Measured memory_bytes: 45272
#include <iostream>
#include <utility>
#include <map>
#include <vector>
#include <algorithm>
#include <queue>
#include <math.h>
#include <stack>
#include <set>
#include <deque>
#include <cmath>
#include <cassert>

using namespace std;
typedef long long ll;
ll mod = 1e9+7;
#define rep(i,n) for(int i = 0; i < (n); ++i)

int main() {
    int n;
    string s, t;
    cin >> n >> s >> t;
    ll ans = 1;
    bool flg = false;
    rep(i, n) {
        if (i == 0) {
            ans *= 3;
            if (i < n - 1 && s[i] == s[i+1]) {
                //cout << "t" << endl;
                ans = (ans * 2) % mod;
                ++i;
                flg = true;
            }
            continue;
        }
        if (s[i] == t[i]) {
            if (flg) {
                flg = false;
            }
            else {
                ans = (ans * 2) % mod;
                flg = false;
            }
        }
        else if (i < n - 1 && s[i] == s[i+1]) {
            if (flg) {
                ans = (ans * 3) % mod;
                flg = true;
            }
            else {
                ans = (ans * 2) % mod;
                flg = true;
            }
            ++i;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3544
#![allow(non_snake_case, unused_macros, unused_imports)]

// Input
macro_rules! input { (source = $s:expr, $($r:tt)*) => { let mut iter = $s.split_whitespace(); let mut next = || { iter.next().unwrap() }; input_inner!{next, $($r)*} }; ($($r:tt)*) => { let stdin = std::io::stdin(); let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock())); let mut next = move || -> String{ bytes.by_ref().map(|r|r.unwrap() as char).skip_while(|c|c.is_whitespace()).take_while(|c|!c.is_whitespace()).collect() }; input_inner!{next, $($r)*} }; }
macro_rules! input_inner { ($next:expr) => {}; ($next:expr, ) => {}; ($next:expr, $var:ident : $t:tt $($r:tt)*) => { let $var = read_value!($next, $t); input_inner!{$next $($r)*} };}
macro_rules! read_value { ($next:expr, ( $($t:tt),* )) => { ( $(read_value!($next, $t)),* ) }; ($next:expr, [ $t:tt ; $len:expr ]) => { (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>() }; ($next:expr, chars) => { read_value!($next, String).chars().collect::<Vec<char>>() }; ($next:expr, bytes) => { read_value!($next, String).into_bytes() }; ($next:expr, usize1) => { read_value!($next, usize) - 1 }; ($next:expr, $t:ty) => { $next().parse::<$t>().expect("Parse error") }; }

// Module
use std::cmp::{min,max};
use std::collections::{HashSet,BTreeMap};

// Main
fn main(){
    input!{
        n: usize,
        v: [i32; n],
    }
    // BTreeMapに偶奇場合分けして格納
    let mut map1 = BTreeMap::new();
    let mut map2 = BTreeMap::new();
    for i in 0..n{
        if i%2==0{
            *map1.entry(v[i]).or_insert(0) += 1;
        }else{
            *map2.entry(v[i]).or_insert(0) += 1;
        }
    }
    // k,v逆にしてVecに格納
    let mut c1:Vec<(i32,i32)> = map1.into_iter().map(|(k,v)| (v,k)).collect();
    let mut c2:Vec<(i32,i32)> = map2.into_iter().map(|(k,v)| (v,k)).collect();
    // 全要素が同一の場合のために、ダミーで-1を0回出現として追加
    c1.push((0,-1));
    c2.push((0,-1));
    // 降順ソート
    c1.sort_by(|a,b| b.cmp(a));
    c2.sort_by(|a,b| b.cmp(a));
    // 最大の要素が同一でない場合は、それ以外を変換すれば良い
    if c1[0].1!=c2[0].1{
        println!("{}", n as i32 - (c1[0].0+c2[0].0));
    // 最大の要素が同一の場合は、2番目に多い要素まで考慮しましょう
    }else{
        println!("{}", min(n as i32 - (c1[0].0+c2[1].0),n as i32 - (c1[1].0+c2[0].0)));
    }
}


Measured memory_bytes: 8444
x=int(input())
sosu=[]
for i in range(2,10**5+1000):
  temp=2
  flag=1
  while temp**2<=i:
    if i%temp==0:
      flag=0
      break
    temp+=1

  if flag==1:
    sosu.append(i)

import bisect

a=bisect.bisect_left(sosu,x)
print(sosu[a])

Measured memory_bytes: 3536
main = do
  n <- readLn
  inps <- mapM (const (fmap (map read . words) getLine)) [1..n]
  mapM_ (print . solve) inps


solve :: [Int] -> Int
solve [a,b] =
  2*n - sa - sb - sm
  where
    m  = floor (sqrt (fromIntegral(a*b-1)))
    sa = if a <= n then 1 else 0
    sb = if b <= n then 1 else 0
    sm = if n*(n+1) >= a*b then 1 else 0
    n  = if m*m >= a*b then m-1 else m

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

void solve() {
	int a, b, c;
	cin >> a >> b >> c;
	double t=(double)a/c;
	if(t<=b) {
		cout << "Yes\n";
	}
	else {
		cout << "No\n";
	}
}

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

	solve();
	return 0;
}

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

int main(){
  int N, D;
  ll cnta=0, cntb=0, ans;
  cin >> N >> D;
  for(int i=1; i<=N; i++){
    if(i % D == 0) cnta++;
  }
  if(!(D%2)){
    for(int i=1; i<=N; i++){
      if(i % D == D/2) cntb++;
    }
  }
  ans = pow(cnta, 3) + pow(cntb, 3);
  cout << ans << endl;
  
 
}

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

const int MOD = 1000000007;
const int INF = 1000000000;

//long long
using ll = long long;

//出力系
#define print(x) cout << x << endl
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
 
// begin() end()
#define all(x) (x).begin(),(x).end()

//for
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)

//最大公約数 
unsigned gcd(unsigned a, unsigned b) {
  if(a < b) return gcd(b, a);
  unsigned r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}

// 最小公倍数
unsigned lcm(unsigned a, unsigned b){
    return a / gcd(a, b) * b; 
}

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

double ki(double a){
    int su = 0;
    for(int i = 1; i <= a; i++) su += i;
    return su / a;
}

int main(){
int a, b, c;
cin >> a >> b >> c;
if(a == b && b == c) yes;
else no;
}


Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<string>
#include<algorithm>
using namespace std;
int main(){
	int k, n;
	cin >> n >> k;
	int a[200001];
	for (int i = 1; i <= n; i++){
		cin >> a[i];
	}
	for (int i = k + 1; i <= n; i++){
		if (a[i] > a[i - k]){
			cout << "Yes" << endl;
		}
		else{
			cout << "No" << endl;
		}
	}
	return 0;
}

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

int main()
{
	ios::sync_with_stdio(false), cin.tie(0);
	int n;
	while (cin >> n, n) {
		vector<string> s(n);
		for (int i = 0; i < n; i++) {
			cin >> s[i];
		}
		bool ok = true;
		vector<vector<int>> d(26, vector<int>(26, 1e9));
		for (int i = 1; i < n; i++) {
			int l1 = s[i - 1].size(), l2 = s[i].size();
			int p = 0;
			while (p < l1 && p < l2 && s[i - 1][p] == s[i][p]) ++p;
			if (p < l1 && p < l2) {
				d[s[i - 1][p] - 'a'][s[i][p] - 'a'] = -1;
			}
			else if (p < l1) {
				ok = false;
			}
		}
		for (int k = 0; k < 26; k++) {
			for (int i = 0; i < 26; i++) {
				for (int j = 0; j < 26; j++) {
					d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
				}
			}
		}
		for (int i = 0; i < 26; i++) {
			if (d[i][i] < 0) {
				ok = false;
			}
		}
		puts(ok ? "yes" : "no");
	}
	return 0;
}



Measured memory_bytes: 3124
K, N = map(int,input().split())
A = list(map(int, input().split()))

li = []
for i in range(N - 1):
  li.append(A[i + 1] - A[i])
  
li.append(abs(A[0] + (K - A[-1])))
index = li.index(max(li))
li.pop(index)
print(sum(li))

Measured memory_bytes: 26420
#include<iostream>
#include<cstdio>
using namespace std;
int a[101],b[101];
int main()
{
	int i=1,j,n,s=1;
	bool yes;
	while(cin>>a[i])
	{
		if(a[i]==0)
		{
			j=i-1;
			yes=true;
			while(yes==true)
			{
				if(a[j]!=0)
				{
					b[s]=a[j];
					a[j]=0;
					s++;
					yes=false;
				}
				j--;
			}
		}
		i++;
	}
	for(i=1;i<s;i++)cout<<b[i]<<endl;
	return 0;
}

Measured memory_bytes: 2964
#include <bits/stdc++.h>
using namespace std;
using ll = long long; // ll は long long　と同じとする。
int main() {
    int a , b , c;
    cin >> a >> b >> c;
    if(a == 5 && b == 5 && c == 7){
        cout << "YES" << endl;
    }
    else if(b == 5 && c == 5 && a == 7){
        cout << "YES" << endl;
    }
    else if(c == 5 && a == 5 && b == 7){
        cout << "YES" << endl;
    }
    else {
        cout << "NO" << endl;
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long int
#define yorn(f) cout<<((f)?"Yes":"No")<<endl;
#define YORN(f) cout<<((f)?"YES":"NO")<<endl;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repi(i, n) for (int i = 1; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define put(x) cout << x << endl;
#define println(x) cout << x << endl;
using namespace std;
signed main()
{
    int k;
    cin >> k;
    int v = 7;
    rep (i, k) {
        if (v % k == 0) {
            put(i+1);
            return 0;
        }
        v = (10 * v + 7) % k;
    }
    put(-1)
    return 0;
}

Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
int fib(int a){
    int b=0;
    if(a==1){
        return 1;
    }
  else if(a==2){
    return 2;
  }
    else{
        b=+(fib(a-1)+fib(a-2));
        return b;
    }
}
int main(){
   string s;
   cin>>s; 
   ll count=0;
  for(int i=0;i<3;i++){
    if(s[i]==s[i+1])count++;
  }
  if(count==0)cout<<"Good"<<endl;
  else cout<<"Bad"<<endl;
}

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

int main() {
  string S;
  int count = 0, length = 0;
  cin >> S;
  for (int i = 0; i < S.size(); i++) {
    if (S.at(i) == 'A' || S.at(i) == 'T' || S.at(i) == 'C' || S.at(i) == 'G') {
    for (int j = i; j < S.size(); j++) {
      if (S.at(j) == 'A' || S.at(j) == 'T' || S.at(j) == 'C' || S.at(j) == 'G')
        length++;
      else 
        break;
    if (length > count) {
      count = length;
    }
    }
    length = 0;
    }
  }
  cout << count << endl;
}

Measured memory_bytes: 256
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <stdlib.h>
#include <stdio.h>

using namespace std;

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

int abs_A(int num) {
    if (num > 0)
        return num;
    else
        return -num;
}

int abs_B(long long num, long long numb) {
    if (num - numb >= 0)
        return num - numb;
    else
        return -1 * (num - numb);
}

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

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

bool permutation(vector<int>& vec,vector<int>& P) {
    bool ok = true;
    for (int i = 0; i < vec.size(); i++) {
        //cout << vec.at(i);
        if (vec.at(i) != P.at(i)) {
            ok = false;
        }
    }
    return ok;
}

/*bool nibu(vector<int>& retu,int key) {
    
}*/

const long long MOD = 1000000007;
const int INF = 1001001001;

int main() {
    int N;
    cin >> N;
    vector<int> fib(45);
    fib.at(0) = 1;
    fib.at(1) = 1;
    for (int i = 2; i <= N; i++) {
        fib.at(i) = fib.at(i - 1) + fib.at(i - 2);
    }
    cout << fib.at(N) << endl;
}




Measured memory_bytes: 3112
import sys

while True:
	a, op, b = sys.stdin.readline().split( " " )
	if "?" == op:
		break
	a = int( a )
	b = int( b )
	if "+" == op:
		print( "{:d}".format( a+b ) )
	elif "-" == op:
		print( "{:d}".format( a-b ) )
	elif "*" == op:
		print( "{:d}".format( a*b ) )
	elif "/" == op:
		print( "{:d}".format( a//b ) )

Measured memory_bytes: 4224
# from collections import deque
from collections import Counter
# from scipy.misc import comb
# from copy import deepcopy

n = int(input())
a = list(map(int, input().split()))
C = Counter(a)
S = 0
"""
for key in C:
    S += comb(C[key], 2, exact=True)
"""
for i in C.keys():
    S += C[i]*(C[i]-1)//2

for k in range(n):
    A = a[k]
    print(S - C[A] + 1)

Measured memory_bytes: 87884
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;

bool check(vector<int> a) {
  int x=7,y=7;
  for(int i=0; i<6; i++) {
    if(a[i]<7&&a[i]>x) return 0;
    if(a[i]>7&&a[i]<y) return 0;
    x=min(x,a[i]);
    y=max(y,a[i]);
  }
  return 1;
}

int main() {
  int T;
  cin >> T;
  while(T--) {
    vector<int> a(6),b;
    for(int i=0; i<6; i++) cin >> a[i];
    for(int j=1; j<14; j++) {
      if(j==7) continue;
      bool f=1;
      for(int i=0; i<6; i++) if(a[i]==j) f=0;
      if(f) b.push_back(j);
    }
    sort(a.begin(),a.end());
    sort(b.begin(),b.end());
    do {
      if(!check(a)) continue;
      bool f=1;
      do {
        if(!check(b)) continue;
        P p=P(7,7);
        int x,y;
        bool u[6],u2[6];
        memset(u,0,sizeof(u));
        memset(u2,0,sizeof(u2));
        for(x=0,y=0;x<6&&y<6;) {
          for(int i=0; i<6; i++) {
            if(!u[i]) {
              if(a[i]==p.first-1){p.first--,u[i]=1,x++;break;}
              else if(a[i]==p.second+1){p.second++,u[i]=1,x++;break;}
            }
          }
          for(int i=0; i<6; i++) {
            if(!u2[i]) {
              if(b[i]==p.first-1){p.first--,u2[i]=1,y++;break;}
              else if(b[i]==p.second+1){p.second++,u2[i]=1,y++;break;}
            }
          }
        }
        if(x<6) f=0;
      } while(next_permutation(b.begin(),b.end()));
      if(f) {
        cout << "yes" << endl;
        goto end;
      }
    } while(next_permutation(a.begin(),a.end()));
    cout << "no" << endl;
  end:;
  }
  return 0;
}


Measured memory_bytes: 3148
def main():
    a,b,c,d = map(int, input().split())
    if abs(c-a) <= d:
        print('Yes')
    elif abs(c-b) <= d and abs(b-a) <= d:
        print('Yes')
    else:
        print('No')

    

if __name__ == "__main__":
    main()


Measured memory_bytes: 2940
#include "bits/stdc++.h"
using namespace std;
using ll     = long long;
using pii    = pair<int, int>;
using pll    = pair<ll, ll>;
using vi     = vector<int>;
using vl     = vector<ll>;
using vvi    = vector<vi>;
using vvl    = vector<vl>;
const ll INF = 1LL << 60;
const ll MOD = 1000000007;
template <class T>
bool chmax(T &a, const T &b) {
    return (a < b) ? (a = b, 1) : 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    return (b < a) ? (a = b, 1) : 0;
}
template <class C>
void print(const C &c, std::ostream &os = std::cout) {
    std::copy(std::begin(c), std::end(c), std::ostream_iterator<typename C::value_type>(os, " "));
    os << std::endl;
}

struct UnionFind {
    vector<int> rank, parent, size;

    // +1 for 1-indexed nodes
    UnionFind(int n) : rank(n + 1, 0), parent(n + 1), size(n + 1, 1) {
        iota(parent.begin(), parent.end(), 0); // parent is itself
    }
    int root(int x) {
        if (x != parent[x]) {
            parent[x] = root(parent[x]);
        }
        return parent[x];
    }
    bool isSame(int x, int y) { return root(x) == root(y); }
    bool unite(int x, int y) { return link(root(x), root(y)); }
    bool link(int x, int y) {
        if (x == y)
            return false;
        if (rank[x] > rank[y]) {
            parent[y] = x;
            size[x] += size[y];
        } else {
            parent[x] = y;
            size[y] += size[x];
            if (rank[x] == rank[y]) {
                rank[y]++;
            }
        }
        return true;
    }
    int getSize(int x) { return size[root(x)]; }
};

int main() {
    ll n, m;
    cin >> n >> m;
    vector<pll> a(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i].first;
        a[i].second = i;
    }
    // sort(a.begin(), a.end());
    UnionFind uf(n);
    for (int i = 0; i < m; ++i) {
        int x, y;
        cin >> x >> y;
        uf.unite(x, y);
    }
    if (n - 1 - m > n / 2) {
        cout << "Impossible"
             << "\n";
        return 0;
    }
    if (m == n - 1) {
        cout << 0 << "\n";
        return 0;
    }
    map<int, deque<ll>> costs;
    for (int i = 0; i < n; ++i) {
        int r = uf.root(i);
        costs[r].push_back(a[i].first);
    }
    vector<deque<ll>> pq;
    for (auto &p : costs) {
        sort(p.second.begin(), p.second.end());
        pq.push_back(p.second);
    }
    ll ret = 0;
    vector<ll> left;
    for (int i = 0; i < (int)pq.size(); ++i) {
        ret += pq[i].front();
        pq[i].pop_front();
        for (auto &p : pq[i]) {
            left.push_back(p);
        }
    }
    sort(left.begin(), left.end());
    for (int i = 0; i < 2 * (n - 1 - m) - (int)pq.size(); ++i) {
        ret += left[i];
    }
    cout << ret << "\n";
    return 0;
}

Measured memory_bytes: 85008
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string.h>
using namespace std;
int a[100005];
int main()
{
	int n;
	scanf("%d",&n);
	int b=0;
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);
	}
	for(int i=1;i<n;i++)
	{
	    if(a[i]==i)
	    {
	    	swap(a[i],a[i+1]);
	    	b++;
		} 
	}
	if(a[n]==n)
	b++; 
	printf("%d\n",b);
	return 0;
}


Measured memory_bytes: 640
#![allow(non_snake_case)]

use std::io::*;

pub fn main() {
    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();
    let xs = buf
        .trim_right()
        .split_whitespace()
        .map(|s| s.parse().unwrap())
        .collect::<Vec<i32>>();
    let N = xs[0];
    let K = xs[1];
    let r = if N % K == 0 { 0 } else { 1 };
    println!("{}", r);
}


Measured memory_bytes: 4352
#include <cstdio>
#include<iostream>
#include<map>
#include<algorithm>
#include<vector>
#include <cmath>
#include <iomanip>
#include <regex>
#include <queue>
using namespace std;
using ll = long long;
const int mod = 1000000007;

bool cmp(pair<ll,ll> p1,pair<ll,ll> p2){
    return p2.second<p1.second;
}
int main(){
    ll N,M;
    cin>>N>>M;
    vector<ll> A(N);
    vector<pair<ll,ll>> cntrl(M);
    for(ll i=0;i<N;i++){
        ll a;
        cin>>a;
        A[i]=a;
    }
    for(ll i=0;i<M;i++){
        cin>>cntrl[i].first>>cntrl[i].second;
    }
    sort(A.begin(),A.end());
    sort(cntrl.begin(),cntrl.end(),cmp);
    ll ind=0;
    for(ll i=0;i<N;i++){
        if(cntrl[ind].second>A[i]){
            A[i] = cntrl[ind].second;
            cntrl[ind].first--;
            if(cntrl[ind].first==0){
                ind++;
            }
        }
        if(ind>=M)break;
    }
    ll res=0;
    for(ll i=0;i<N;i++){
        res += A[i];
        // cout<<A[i]<<endl;
    }
    cout<<res<<endl;
}

Measured memory_bytes: 2688
#include <algorithm>
#include <iostream>
#include <numeric>
#include <set>
#include <string>
#include <tuple>
#include <vector>

using namespace std;

#define loop(i, times) for(int i = 0; i < times; i++)
#define seloop(i, start_index, end_index) for(int i = start_index; i < end_index; i++)
#define eqseloop(i, start_index, end_index) for(int i = start_index; i <= end_index; i++)


int Check(tuple<long, int, int>& ans, vector<tuple<long, int, int, bool>>& hint_collection)
{
	int correct = 0;

	for (const auto& e : hint_collection)
	{
		if (!get< 3 >(e))
			continue;

		if (get< 0 >(e) == 0)
		{	// 例外処理 ヒントの高さが0のとき
			if (0 < get< 0 >(ans) - abs(get< 1 >(ans) - get< 1 >(e)) - abs(get< 2 >(ans) - get< 2 >(e)))
				break;
		}
		else
		{	// 通常処理 ヒントの高さが0でないとき
			if (get< 0 >(e) != get< 0 >(ans) - abs(get< 1 >(ans) - get< 1 >(e)) - abs(get< 2 >(ans) - get< 2 >(e)))
				break;
		}

		correct++;
	}

	return correct;
}

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

	vector<tuple<long, int, int, bool>> hint_collection;
	hint_collection.resize(101 * 101);
	loop(x, 101)
	{	// ヒントコンテナの初期化
		loop(y, 101)
		{
			tuple<long, int, int, bool> t = make_tuple(0, x, y, false);
			hint_collection[x * 101 + y] = t;
		}
	}

	loop(i, n)
	{	// ヒントコンテナを作る
		int x; cin >> x;
		int y; cin >> y;
		long h; cin >> h;
		tuple<long, int, int, bool> t = make_tuple(h, x, y, true);
		hint_collection[x * 101 + y] = t;
	}

	tuple<long, int, int, bool> max = make_tuple(-1, 0, 0, false);
	loop(i, 101 * 101)
	{	// ヒントのうち最大の高さを調べる
		if (get< 3 >(hint_collection[i]) && get< 0 >(max) < get< 0 >(hint_collection[i]))
			max = hint_collection[i];
	}

	vector<tuple<long, int, int>> ans_collection;
	ans_collection.resize(101 * 101);
	loop(x, 101)
	{	// 答えを予想するコンテナの作成
		loop(y, 101)
		{
			long h = get< 0 >(max) + abs(x - get< 1 >(max)) + abs(y - get< 2 >(max));
			tuple<long, int, int> t = make_tuple(h, x, y);
			ans_collection[x * 101 + y] = t;
		}
	}

	loop(x, 101)
	{	// 予想したコンテナから答えを探す
		loop(y, 101)
		{
			if (Check(ans_collection[x * 101 + y], hint_collection) == n)
			{
				cout << get< 1 >(ans_collection[x * 101 + y]) << " " << get< 2 >(ans_collection[x * 101 + y]) << " " << get< 0 >(ans_collection[x * 101 + y]);
				return 0;
			}
		}
	}

	return 0;
}


Measured memory_bytes: 640
def main():
    n = int(input())
    a = []
    for i in range(n):
        a.append(int(input()))

    a_sort = sorted(a)
    a_max = a_sort[-1]
    a_second = a_sort[-2]

    for i in range(n):
        if a[i] == a_sort[-1]:
            print(a_second)
        else:
            print(a_max)


if __name__ == '__main__':
    main()


Measured memory_bytes: 91088
#include <bits/stdc++.h>
#pragma GCC optimize ("O2,unroll-loops")
//#pragma GCC optimize("no-stack-protector,fast-math")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<pii, int> piii;
typedef pair<ll, ll> pll;
#define debug(x) cerr<<#x<<'='<<(x)<<endl;
#define debugp(x) cerr<<#x<<"= {"<<(x.first)<<", "<<(x.second)<<"}"<<endl;
#define debug2(x, y) cerr<<"{"<<#x<<", "<<#y<<"} = {"<<(x)<<", "<<(y)<<"}"<<endl;
#define debugv(v) {cerr<<#v<<" : ";for (auto x:v) cerr<<x<<' ';cerr<<endl;}
#define all(x) x.begin(), x.end()
#define pb push_back
#define kill(x) return cout<<x<<'\n', 0;

const ld eps=1e-7;
const int inf=1000000010;
const ll INF=10000000000000010LL;
const int mod=1000000007;
const int MAXN=200010, LOG=20;

ll n, m, k, u, v, x, y, t, a, b, ans;
pii A[MAXN];
int L[MAXN], R[MAXN], B[MAXN];
ll seg[MAXN<<2], dp[MAXN];
vector<int> vec[MAXN];

ll Get(int id, int tl, int tr, int l, int r){
	if (r<=tl || tr<=l) return 0;
	if (l<=tl && tr<=r) return seg[id];
	int mid=(tl+tr)>>1;
	return Get(id<<1, tl, mid, l, r) + Get(id<<1 | 1, mid, tr, l, r);
}

void Set(int id, int tl, int tr, int pos, ll val){
	if (pos<tl || tr<=pos) return ;
	if (tr-tl==1){
		seg[id]=val;
		return ;
	}
	int mid=(tl+tr)>>1;
	Set(id<<1, tl, mid, pos, val);
	Set(id<<1 | 1, mid, tr, pos, val);
	seg[id]=(seg[id<<1] + seg[id<<1 | 1])%mod;
}

int main(){
	ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	cin>>n;
	for (int i=1; i<=n; i++) cin>>A[i].second>>A[i].first;
	sort(A+1, A+n+1);
	B[n+1]=inf;
	for (int i=n; i; i--) B[i]=min(B[i+1], A[i].second);
	for (int i=1; i<=n; i++) R[i]=upper_bound(B+1, B+n+1, A[i].second)-B-1;
	for (int i=1; i<=n; i++) B[i]=max(B[i-1], A[i].second);
	for (int i=1; i<=n; i++){
		L[i]=lower_bound(B+1, B+n+1, A[i].second)-B;
//		debug2(L[i], R[i])
		vec[R[i]].pb(L[i]);
	}
	Set(1, 0, n+1, 0, dp[0]=1);
	for (int i=1; i<=n; i++){
		sort(all(vec[i]));
		for (int l:vec[i]){
			ll sum=Get(1, 0, n+1, l-1, i+1);
			dp[i]=(dp[i]+sum)%mod;
//			debug(sum)
			Set(1, 0, n+1, i, dp[i]);
		}
	}
	ans=dp[n];
	cout<<ans<<'\n';
	
	return 0;
}


Measured memory_bytes: 24148
#include<iostream>
#include<queue>
#define INF 1000000
using namespace std;

 queue<int> q;
int a[101][101];
int d[101];
int n;

void bfs(int s){
  int t;
  for(int i=1;i<=n;i++)d[i]=INF;
  d[s]=0;
  while(!q.empty()){
    t=q.front(),q.pop();
    for(int i=1;i<=n;i++){
      if(d[i]!=INF || a[t][i]!=1) continue;
       q.push(i),d[i]=d[t]+1;
    }
  }
}

int main(){
  int top,m,s;
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>top>>m;
    for(int j=0;j<m;j++)
      cin>>s,a[top][s]=1;
     } 
  q.push(1);
   bfs(1);
   for(int i=1;i<=n;i++){
     if(d[i]==INF) d[i]=-1;
     cout<<i<<" "<<d[i]<<endl;
   }
    return 0;
}

Measured memory_bytes: 1240
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

var scanner = bufio.NewScanner(os.Stdin)

func nextInt() (int, error) {
	scanner.Scan()
	return strconv.Atoi(scanner.Text())
}

func nextString() string {
	scanner.Scan()
	return scanner.Text()
}

func shellSort(arrOrig []int) ([]int, int, []int) {
	n := len(arrOrig)

	arr := make([]int, n)
	copy(arr, arrOrig)

	cnt := 0

	m := n
	g := []int{}
	i := m
	for i > 0 {
		g = append(g, i)
		// fmt.Println(m, i, g)

		if i/2 != 0 {
			i = i / 2
		} else if i == 1 {
			i = 0
		} else {
			i = 1
		}
	}

	for i := 0; i < len(g); i++ {
		cnti := 0
		cnti = insertionSort(arr, g[i])
		// fmt.Println(arr)
		cnt += cnti
	}
	return arr, cnt, g
}

func insertionSort(arr []int, g int) int {
	n := len(arr)

	cnt := 0
	for i := g; i < n; i++ {
		v := arr[i]
		j := i - g
		for j >= 0 && arr[j] > v {
			arr[j+g] = arr[j]
			j -= g
			cnt++
		}
		arr[j+g] = v
	}
	return cnt
}

func stringifyArray(arr []int) string {
	return strings.TrimRight(fmt.Sprintf("%+v", arr)[1:], "]")
}

func main() {
	scanner.Split(bufio.ScanWords)

	size, _ := nextInt()
	arr := make([]int, size)
	for i := 0; i < size; i++ {
		arr[i], _ = nextInt()
	}

	// fmt.Println(arr)
	arrShell, cnt, g := shellSort(arr)
	fmt.Println(len(g))
	fmt.Println(stringifyArray(g))
	fmt.Println(cnt)
	fmt.Println(strings.Replace(stringifyArray(arrShell), " ", "\n", -1))
}



Measured memory_bytes: 75860
#include <iostream>
#include<algorithm>
#include<set>
#include<queue>
#include<bitset>
#define rep(i,j,n) for(int i=j;i<n;i++)
using namespace std;
#define int long long
int mul[214514];
int divi[214514];
#define inf 1000000007
int bit[114514],n;
struct edge{int u,v,cost;};
edge es[214514];
int zero=0;
int dp[55][55][3000];
string alph("abcdefghijklmnopqrstuvwxyz");


signed main(){
    int a,b;cin>>a>>b;
    if(a%2&&b%2)cout<<"Odd"<<endl;
    else cout<<"Even"<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
#define f0r(a, b) for (long long a = 0; a < (b); a++)
#define f1r(a, b, c) for (long long a = (b); a < (c); a++)
#define f0rd(a, b) for (long long a = (b); a >= 0; a--)
#define f1rd(a, b, c) for (long long a = (b); a >= (c); a--)
#define ms(arr, v) memset(arr, v, sizeof(arr))
#define pb push_back
#define mp make_pair
#define f first
#define s second
using ll = long long;
using pll = pair<ll, ll>;
using vl = vector<ll>;
 
void fio() {
  ios_base::sync_with_stdio(0);
  cin.tie(0); 
  cout.tie(0);
}
 
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 

 
const long double pi = 3.14159265358979323846;
const ll mod = (ll)(1e9 + 7);
 
void solve() {
  ll n, k; cin >> n >> k;
  ll a[n]; f0r(i, n) {
    cin >> a[i]; --a[i];
  }
  int vis[n];
  ms(vis, 0);

  ll len = 0, targ = 0;
  do {
    vis[targ] = len + 1;
    targ = a[targ]; 
    ++len; --k;
  } while (k > 0 && vis[targ] == 0);
  if (k > 0) {
    k %= (len - vis[targ] + 1);
    while (k--) targ = a[targ];
  }
  cout << targ + 1 << '\n';
}
 
int main() {
  fio();
  
  int T;
  T = 1;
  // cin >> T;
  while (T--) solve();
} 

Measured memory_bytes: 6004
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep2(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
const ll INF = 1LL<<60;
const ll MOD = 1e9+7;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll n; cin>>n;
    ll M = 1;
    for(ll i=1; i*i<=n; i++){
        if(n%i==0)M = i+n/i;
    }
    cout<<M-2;

    return 0;
}

Measured memory_bytes: 256
//#define _USE_MATH_DEFINES
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
using namespace std;

int main() {
	set<string>ss;
	int n;
	cin >> n;
	for (int i = 0; i < n; i++) {
		string s;
		cin >> s;
		ss.insert(s);
	}
	cout << ss.size() << endl;
	return 0;
}

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

int main()
{
    int N, M;
    cin >> N >> M;
    vector<int> X, interval;

    // input
    for (int i = 0; i < M; i++)
    {
        int xi;
        cin >> xi;
        X.push_back(xi);
    }

    if (N >= M)
    {
        cout << 0 << endl;
        return 0;
    }

    sort(X.begin(), X.end());

    // interval
    int ans = X[M - 1] - X[0];
    for (int i = 0; i < M - 1; i++)
    {
        interval.push_back(X[i + 1] - X[i]);
    }
    sort(interval.begin(), interval.end());

    // remove the longest interavls N-1 times
    for (int i = 0; i < N - 1; i++)
    {
        ans -= interval[M - 2 - i];
    }

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

Measured memory_bytes: 1400
#include <iostream>
#include <cmath>
#include <complex>
#include <string>
#include <sstream>
#include <limits>
#include <algorithm>
#include <functional>

#include <map>

using namespace std;

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

	int N;
	cin >> N;

	map<int, int> divisors_cnt;

	for (int i = 1; i <= N; i++)
	{
		if (i % 2 == 0) continue;

		for (int j = i; j <= N; j += i)
		{
			divisors_cnt[j]++;
		}
	}

	int result = 0;
	for (auto it = divisors_cnt.begin(); it != divisors_cnt.end(); it++)
	{
		if (it->second == 8)
		{
			result++;
		}
	}

	cout << result;

	return 0;
}

Measured memory_bytes: 3628
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <cmath>

using namespace std;

int main(){
    int n;
    int ans = 0;
    cin >> n;
    // 全ての桁の数字を10で割った余りが全て等しい！

    int a,b,c;
    a = n / 100; //100の位
    b = (n / 10) % 10; //10の位
    c = n % 10; //1の位

    if(a > b){
        ans = 100 * a + 10 * a + a;
    }
    else if(a == b){
        if(b >= c){
            ans = 100 * a + 10 * a + a;
        }
        else if(b < c){
            a++;
            ans = 100 * a + 10 * a + a;
        }
    }
    else{
        a++;
        ans = 100 * a + 10 * a + a;
    }
    printf("%d",ans);
}


Measured memory_bytes: 256
MAX = 101010
is_prime = [1]*MAX
is_prime[0] = 0
is_prime[1] = 0
for i in range(2,MAX):
    if not is_prime:
        continue
    for j in range(i*2,MAX,i):
        is_prime[j] = 0

a = [0]*MAX
for i in range(MAX):
    if i%2==0:
        continue
    if is_prime[i] and is_prime[(i+1)//2]:
        a[i] = 1


s = [0]*(MAX+1)
for i in range(MAX):
    s[i+1] = s[i] + a[i]

Q = int(input())
for _ in range(Q):
    l, r = map(int, input().split())
    print(s[r+1]-s[l])

Measured memory_bytes: 8020
#include<stdio.h>
#include<math.h>
#include<string.h>
#include<iostream>
#include<algorithm>
using namespace std;
#define ll long long
ll num[100005];
bool cmp(ll x,ll y)
{
    return x>y;
}
int main()
{
    int n;
    int flag=1;
    ll a,c;
    while(~scanf("%d",&n))
    {
        for(int i=0; i<n; i++)
        {
            scanf("%lld",&num[i]);
        }
        sort(num,num+n,cmp);
        int f=0;
        for(int i=0; i<n; i++)
        {
            if(num[i]==num[i+1]&&f==0)
            {
                a=num[i+1];
                f=1;
                i++;
               ///  printf("%d\n",a);
            }
            else  if(num[i]==num[i+1]&&f==1)
            {
                c=num[i+1];
                i++;
             ///    printf("%d\n",c);
                break;
            }
            else if(i==n-1)
                flag=0;
        }
        if(flag)
            printf("%lld\n",a*c);
        else
            printf("0\n");
    }
    return 0;
}
/**
6
1 1 2 2 3 3
**/


Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

const long long INF = 1LL << 60;

template<typename T>
class RangeUpdateQuery {
public:
    explicit RangeUpdateQuery(int n, T def) : N(calcN_(n)) {
        mVal.assign(2*N+1, make_pair(-1, def));
    }
    void update(int l, int r, T value, int ts){
        updateImpl_(l, r, make_pair(ts, value), 0, 0, N);
    }
    T get(int idx){
        int i = N + idx - 1;
        auto res = mVal[i];
        while(i > 0){
            i = (i-1)/2;
            res = max(mVal[i], res);
        }
        return res.second;
    }
private:
    int calcN_(int n){
        int res = 1;
        while(res < n) res *= 2;
        return res;
    }
    void updateImpl_(int l, int r, pair<int, T> value, int idx, int rangeL, int rangeR){
        if(r <= rangeL || rangeR <= l) return;
        if(l <= rangeL && rangeR <= r){
            mVal[idx] = value;
        } else {
            int rangeM = (rangeL+rangeR)/2;
            updateImpl_(l, r, value, 2*idx+1, rangeL, rangeM);
            updateImpl_(l, r, value, 2*idx+2, rangeM, rangeR);
        }
    }
    const int N;
    vector<pair<int,T>> mVal; 
};

int main(){
    int N, M;
    while(cin >> N >> M){
        vector<pair<pair<int,int>, int>> vp(M);
        for(auto& p : vp){
            cin >> p.first.first >> p.first.second >> p.second;
            --p.first.first;
            --p.first.second;
        }
        sort(vp.begin(), vp.end());
        RangeUpdateQuery<long long> ruq(N, INF);
        ruq.update(0, 1, 0, 0);
        for(int i=0;i<M;i++){
            auto& p = vp[i];
            auto next = ruq.get(p.first.first) + p.second;
            if(ruq.get(p.first.second) <= next) continue;
            int L = p.first.first, R = p.first.second;
            while(R-L > 1){
                int mid = (L+R)/2;
                if(ruq.get(mid) > next) R = mid;
                else L = mid;
            }
            ruq.update(R, p.first.second+1, next, i+1);
        }
        auto res = ruq.get(N-1);
        cout << (res == INF ? -1 : res) << endl;
    }
}


Measured memory_bytes: 5504
#include <iostream>
#include <stdio.h>
#include <cstring>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
using namespace std;
typedef long long ll;
const int maxn=1e5+111;
int main(){
    char s[10];
    scanf("%s",s);
    if(s[1]=='B'){
        puts("ARC");
    }
    else{
        puts("ABC");
    }
    return 0;
}

Measured memory_bytes: 3688
n,k = map(int, input().split())
a = [0] + list(map(int, input().split()))
 
now = 1
check = [-1]*(n+1)
 
for i in range(k):
  if check[now] == -1:
    check[now] = i
    now = a[now]
  else:
    loop = i - check[now]
    afterloop = (k-(i-loop))%loop
    print(check.index((i-loop) + afterloop))
    exit()
print(now)

Measured memory_bytes: 32376
#include<bits/stdc++.h>
using namespace std ;
#define ll long long 
#define all(x) x.begin() , x.end()

int n , v[105] , s , md;
ll an = 1000000000 , ann;
ll go(int val){
    ll sm = 0 ; 
    for(int i=0;i<n;++i){
        sm += (val - v[i]) * (val-v[i]);
    }
        return sm; 
}
int main(){
    scanf("%d",&n);
    for(int i=0;i<n;++i){
        scanf("%d",v+i);
        s += v[i];
    }
    for(int i=-100;i<=100;++i){
        an = min(an , go(i));
    }
    printf("%lld\n",an);
}

Measured memory_bytes: 256
card = ["a","b","c"]
S = dict()
for i in card:
    S[i] = input()

turn = "a"
while True:
    if len(S[turn])==0:
        print(turn.upper())
        break
    else:
        next_turn = S[turn][0]
        S[turn] = S[turn][1:]
        turn = next_turn

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

int main()
{
    long long h, w;
    cin >> h >> w;
    long long r;
    if (h == 1 || w == 1) {
        r = 1;
    } else if (h % 2 == 1 && w % 2 == 1) {
        r = (h*w+1) / 2;
    } else {
        r = h*w / 2;
    }
    cout << r << endl;
}

Measured memory_bytes: 888
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>

using namespace std;

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

// container util
#define all(x) (x).begin(), (x).end()

// debug
#define dump(x) cerr << #x << " = " << (x) << endl;
#define debug(x)                                         \
  cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \
       << " " << __FILE__ << endl;

// typedef
typedef long long lint;
typedef unsigned long long ull;
typedef complex<long double> Complex;
typedef pair<int, int> P;
typedef tuple<int, int, int> TP;
typedef vector<int> vec;
typedef vector<vec> mat;

// constant
const int MOD = (int)1e9 + 7;
const int INF = (int)1e18;
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};

// conversion
inline int toInt(string s) {
  int v;
  istringstream sin(s);
  sin >> v;
  return v;
}
template <class T>
inline string toString(T x) {
  ostringstream sout;
  sout << x;
  return sout.str();
}

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

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

  int n;
  cin >> n;

  int ans = 0;
  for (int i = 1; i <= n; i++) {
    if (i < 10)
      ans++;
    else if (100 <= i && i < 1000)
      ans++;
    else if (10000 <= i && i < 100000)
      ans++;
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256