akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < n; ++i)
const ll INF = LLONG_MAX;
const ll MOD = 1e9 + 7;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    vector<ll> num(3);
    rep(i, 3) { cin >> num[i]; }
    sort(num.begin(), num.end());
    ll sum = 0;
    for (auto& n : num) {
        sum += n;
    }
    if (sum % 2 == num[2] % 2) {
        cout << (2 * num[2] - num[1] - num[0] + 1) / 2 << endl;
    } else {
        cout << (2 * num[2] - num[1] - num[0] + 1) / 2 + 1 << endl;
    }
    return 0;
}

Measured memory_bytes: 256
X = int(input())
# X = 1
stopFlag = 0
for i in range (-201, 201):
    a = i
    for j in range(-201, 201):
        if a**5 - j**5 == X:
            print (a, j)
            stopFlag = 1            
        if stopFlag:
            break
    if stopFlag:
        break

Measured memory_bytes: 9076
#include <iostream>
#include <string>
#include <string.h>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cmath>
#include <stdio.h>
#include <vector>
#include <time.h>
#include <iomanip>
#include <thread>
#include <atomic>
#include <mutex>
#include <future>
#define double long double
#define int long long
#define low lower_bound
#define upp upper_bound
#define mod (int)1e9+7
#define inf (int)1e16
#define rep(i,n) for(int i=0;i<n;i++)
#define all(vec) vec.begin(),vec.end()
#define vsort(vec) sort(all(vec))
#define vrever(vec) reverse(all(vec));
#define vunsort(vec) vsort(vec); vrever(vec);
#define bisea binary_search
#define cend cout<<endl;
#define P pair<int,int>
#define prique priority_queue<P,vector<P>,greater<P>>
using namespace std;
signed main() {
	int a, b, t;
	cin >> a >> b >> t;
	cout << b * (t / a) << endl;
}


Measured memory_bytes: 256
#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[] = { -1, 0, 1, 0 };
const int dy[] = { 0, 1, 0, -1 };

int gcd(int x, int y) { return y ? gcd(y, x % y) : x; }
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
int lcm(int x, int y) { return x / gcd(x, y) * y; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }

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

	string s;
	cin >> s;

	vector<int> count(26);
	for (auto c : s) {
		int t = c - 'a';
		count[t]++;
	}

	for (int i = 0; i < 26; i++) {
		if (count[i] == 0) {
			char c = i + 'a';
			cout << c << endl;
			return 0;
		}
	}

	cout << "None" << endl;
	return 0;
}


Measured memory_bytes: 512
#include<iostream>
#include<vector>
#include<algorithm>
#include<map>
#include<cstring>
#include<math.h>
#include<bitset>
#include<queue>
#include<set>
#include<iomanip>
#include<assert.h>
#include<string>
#include<cstdlib>
#include<cctype>
#include<unordered_map>
#include<sstream>
#include<numeric>
#include<stack>
// #include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int,int>;
constexpr ll INF = 9e18;
constexpr int inf = 1e9;
const double INFD = 1e100;
const ll mod = 1000000007;
const double PI = 3.1415926535897932384626433832795028841971;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
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やllをstringに変換
template<typename T> inline string toString(const T &a){
  ostringstream oss;
  oss << a;
  return oss.str();
};
// ----------------------------------------------------------------------------

int main(){
  string S;
  cin >> S;
  int N;
  N = S.size();
  for(int i=0; i<N; i++){
    if(i+1<N && S[i] == S[i+1]){
      cout << i+1 << " " << i+2 << endl;
      return 0;
    }
    if(i+2<N && S[i] == S[i+2]){
      cout << i+1 << " " << i+3 << endl;
      return 0;
    }
  }
  cout << -1 << " " << -1 << endl;
  return 0;
}


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

#define REP(i,n) for(ll i=0;i<ll(n);++i)
#define RREP(i,n) for(ll i=ll(n)-1;i>=0;--i)
#define FOR(i,m,n) for(ll i=m;i<ll(n);++i)
#define RFOR(i,m,n) for(ll i=ll(n)-1;i>=ll(m);--i)
#define ALL(v) (v).begin(),(v).end()
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());
#define INF 1000000001ll
#define MOD 1000000007ll
#define EPS 1e-9

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


using namespace std;

using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vvl = vector<vl>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

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

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	vector<pii> v(3);
	REP(i, 3) {
		cin >> v[i].first;
		v[i].second = i;
	}
	sort(ALL(v));
	cout << char(v[2].second + 'A') << endl;
}


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

int stones[100000];

int min(int a, int b) {
	return a < b ? a : b;
}

int main() {
	int N;
	if (scanf("%d", &N) != 1)	return -1;
	for (int i = 0; i < N; i++) {
		if (scanf("%d", stones + i) != 1)	return -1;
	}
	int p1 = 0, p2 = abs(stones[1] - stones[0]), p3;
	for (int p = 2; p < N; p++) {
		int p13 = abs(stones[p] - stones[p - 2]);
		int p23 = abs(stones[p] - stones[p - 1]);
		p3 = min(p13 + p1, p23 + p2);
		p1 = p2;
		p2 = p3;
	}
	printf("%d\n", p2);
	system("pause");
	return 0;
}

Measured memory_bytes: 4200
const t={input:require('fs').readFileSync('/dev/stdin','utf8').split(/[\s]/),n:(arg:number=0):any=>{if(arg){const a=[];for(let i=0;i<arg;i++){a.push(t.n())}return a}else{const a=t.input[0];t.input.shift();return Number(a)}},s:(arg:number=0):any=>{if(arg){const a=[];for(let i=0;i<arg;i++){a.push(t.s())}return a}else{const a=t.input[0];t.input.shift();return String(a)}},c:(arg:number=0):any=>{if(arg){const a=[];for(let i=0;i<arg;i++){a.push(t.c())}return a}else{let a=t.input[0].split('');const b=a[0];a.shift();if(a.length>0){t.input[0]=a.join('')}else{t.input.shift()}return String(b)}},o:(...arg)=>{console.log(...arg)},abs:(a)=>{return Math.abs(a)},min:(...a)=>{return Math.min(...a)},max:(...a)=>{return Math.max(...a)},floor:(a)=>{return Math.floor(a)},asc:(ar:number[])=>{return ar.sort((a,b)=>{return a-b})},desc:(ar:number[])=>{return ar.sort((a,b)=>{return b-a})},sw:(a,arr:any[],op:'=='|'>='|'>'|'<='|'<'='==')=>{for(let i=0;i<arr.length;i+=2){if(eval(a+op+arr[i]))return arr[i+1];}return arr[arr.length-1]}};
const main=()=>{
  let n=t.n()
  let av=t.n(n),ac=t.n(n),c=0
  for(let i=0;i<n;i++)if(av[i]>ac[i])c+=(av[i]-ac[i])
  t.o(c)
}
main()

Measured memory_bytes: 7372
a = [input().split() for l in range(2)]
forecast = list(str(a[0]))
real = list(str(a[1]))
count = 0
if forecast[2] == real[2]:
  count = count + 1
if forecast[3] == real[3]:
  count = count + 1
if forecast[4] == real[4]:
  count = count + 1
 
print(str(count))


Measured memory_bytes: 3060
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
using namespace std;
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; ++i )
#define rep(i,n) REP(i,0,n)
typedef long long ll;
typedef pair<int,int> pint;
typedef pair<ll,int> pli;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

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

int main(){
    ll n,m;
    cin>>n>>m;
    string s,t;
    cin>>s>>t;
    ll g=gcd(n,m);
    rep(i,g){
        if(s[i*n/g]!=t[i*m/g]){
            cout<<-1<<endl;
            return 0;
        }
    }
    cout<<m*n/g<<endl;
    return 0;
}

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

#define rep(i,n) for(int i=0; i<(n); i++)
#define rep2(i,x,n) for(int i=x; i<(n); i++)
#define all(x) x.begin(),x.end()
typedef long long ll;
ll mod = 1000000007;
ll inf = 1e18;
int main(){

    string s;
    cin >> s;
    int n=s.size();
    if(s[n-1]=='s') s+="es";
    else s+='s';

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

Measured memory_bytes: 3624
#![allow(non_snake_case)]
#![allow(dead_code)]
#![allow(unused_macros)]
#![allow(unused_imports)]

use std::str::FromStr;
use std::io::*;
use std::collections::*;
use std::cmp::*;

struct Scanner<I: Iterator<Item = char>> {
    iter: std::iter::Peekable<I>,
}

macro_rules! exit {
    () => {{
        exit!(0)
    }};
    ($code:expr) => {{
        if cfg!(local) {
            writeln!(std::io::stderr(), "===== Terminated =====")
                .expect("failed printing to stderr");
        }
        std::process::exit($code);
    }}
}

impl<I: Iterator<Item = char>> Scanner<I> {
    pub fn new(iter: I) -> Scanner<I> {
        Scanner {
            iter: iter.peekable(),
        }
    }

    pub fn safe_get_token(&mut self) -> Option<String> {
        let token = self.iter
            .by_ref()
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>();
        if token.is_empty() {
            None
        } else {
            Some(token)
        }
    }

    pub fn token(&mut self) -> String {
        self.safe_get_token().unwrap_or_else(|| exit!())
    }

    pub fn get<T: FromStr>(&mut self) -> T {
        self.token().parse::<T>().unwrap_or_else(|_| exit!())
    }

    pub fn vec<T: FromStr>(&mut self, len: usize) -> Vec<T> {
        (0..len).map(|_| self.get()).collect()
    }

    pub fn mat<T: FromStr>(&mut self, row: usize, col: usize) -> Vec<Vec<T>> {
        (0..row).map(|_| self.vec(col)).collect()
    }

    pub fn char(&mut self) -> char {
        self.iter.next().unwrap_or_else(|| exit!())
    }

    pub fn chars(&mut self) -> Vec<char> {
        self.get::<String>().chars().collect()
    }

    pub fn line(&mut self) -> String {
        if self.peek().is_some() {
            self.iter
                .by_ref()
                .take_while(|&c| !(c == '\n' || c == '\r'))
                .collect::<String>()
        } else {
            exit!();
        }
    }

    pub fn peek(&mut self) -> Option<&char> {
        self.iter.peek()
    }
}

trait Joinable {
    fn join(self, sep: &str) -> String;
}

impl<U: ToString, T: Iterator<Item = U>> Joinable for T {
    fn join(self, sep: &str) -> String {
        self.map(|x| x.to_string()).collect::<Vec<_>>().join(sep)
    }
}
fn main() {
    let cin = stdin();
    let cin = cin.lock();
    let mut sc = Scanner::new(cin.bytes().map(|c| c.unwrap() as char));
    let N: usize = sc.get();
    let S: Vec<char> = sc.chars();
    let mut i = 0;
    let mut ans = String::new();
    while i < N {
        let c = S[i];
        ans.push(c);
        while i < N && c == S[i] {
            i += 1;
        }
    }
    println!("{}", ans.len());
}


Measured memory_bytes: 4352
#include<iostream>
using namespace std;
main()
{
	int m;cin>>m;
	for(;m--;)
	{
		int L,y,n;cin>>L>>y>>n;
		int ans=0;
		for(;n--;)
		{
			int f,c;double d;
			cin>>f>>d>>c;
			int A=L,B=0;
			for(int i=0;i<y;i++)
			{
				if(f)A+=A*d;
				else B+=A*d;
				A-=c;
			}
			ans=ans<A+B?A+B:ans;
		}
		cout<<ans<<endl;
	}
}



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

using namespace std;
using ll = long long;

int main() {
  int n;
  cin >> n;
  char c;
  map<string, int> mp;
  for (int i = 0; i < n; ++i) {
    string s;
    cin >> s;
    mp[s]++;
    if (i) {
      if (s[0] != c || mp[s] > 1) {
        cout << "No" << endl;
        return 0;
      } else {
        c = s[s.length() - 1];
      }
    } else {
      c = s[s.length() - 1];
    }
  }
  cout << "Yes" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define min_3(a,b,c) min(a,min(b,c))
#define max_3(a,b,c) max(a,max(b,c))
#define nout(ans) cout << (ans) << "\n"
#define sout(ans) cout << (ans) << " "
using namespace std;

const double pi = 3.14159265359;
const ll INF = 1e12;
const ll MOD = 1e9 + 7;
const ll N = 1e5 + 5; 
/*
Decimal Places: cout << fixed << setprecision(n) << ans << endl
*/

bool compare(const pair<int, int>&i, const pair<int, int>&j)
{
    return i.second < j.second;
}

ll raise(ll a, ll b) {
    ll res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a;
        a = a * a;
        b >>= 1;
    }
    return res;
}


ll n, a[100];

void solve()
{
    cin >> n;
    for (int i=1; i<=n; ++i) cin >> a[i];
    ll i=1, k=1000;
    while (i<n) {
        while (i<n && a[i+1]<=a[i]) i++;
        if (i==n) break;
        ll start=i++;
        while (i<=n && a[i]>=a[i-1]) i++;
        ll end=i-1;
        ll stock = k/a[start];
        k = k%a[start];
        k += stock*a[end];
    }
    nout(k);
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    int t = 1;
    //cin >> t;
    for (int i=1; i<=t; i++)
    {
        solve();
    }
    return 0;
}       

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

using namespace std;
using ll = long long int;

int main() {
    static const double pi = 3.141592653589793;
    int a, b, h, m;
    cin >> a >> b >> h >> m;

    double rad =
        pi * 2 *
        ((double)h / 12.0 + ((double)m / 60.0) / 12.0 - (double)m / 60.0);

    double pow = (double)(a * a + b * b) - (double)(2 * a * b) * cos(rad);

    printf("%20.20Lf\n", sqrtl(pow));
}

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


def judge_dist(X, Y):
    total = 0
    for x, y in zip(X, Y):
        total += (x - y) ** 2
    return int(math.sqrt(total)) ** 2 == total


def solve(N: int, D: int, X: "List[List[int]]"):
    count = 0
    for i in range(1, N):
        for j in range(i):
            if judge_dist(X[i], X[j]):
                count += 1
    print(count)
    return


# Generated by 1.1.4 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():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    D = int(next(tokens))  # type: int
    X = [ [ int(next(tokens)) for _ in range(D) ] for _ in range(N) ]  # type: "List[List[int]]"
    solve(N, D, X)

if __name__ == '__main__':
    main()


Measured memory_bytes: 38256
#include <cstdio>
 
const int MAX_S = 200000;
 
long long int c = 0;
int w = 0;
 
char p[MAX_S];
 
void solve() {
  for (int i = 0; i < MAX_S; i++) {
    if (p[i] == 'W') {
      c += i - w;
      w += 1;
    }
  }
}
 
int main() {
  scanf("%s", p);
  solve();
  printf("%lld\n", c);
 
  return 0;
}


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

Measured memory_bytes: 3620
#include <bits/stdc++.h>
#define rep(i,cc,n) for(int i=cc;i<=n;++i)
#define drep(i,cc,n) for(int i=cc;i>=n;--i)
#define sz(s) (int)(s.size())
#define mod 1000000007

using namespace std;
class CompareFirst
{
public:
  bool operator()(pair<int,int> n1,pair<int,int> n2) {
    return n1.first>n2.first; //>:desc <:asc
  }
};


int main(){

  string s;
  int i,j,l,n,m;
  long long k;
  vector<string> vs;
  vector<int> vi;
  pair<int,int> pr;
  //unordered_map<string,int> mp;
  //priority_queue<int> pq; // default ‘å‚«‚¢‡
  //priority_queue<pair<int,int>,vector<pair<int,int>>,CompareFirst> pq;

  cin >> n >> k;
  cin >> s;
  long long ans = 0;
  long long lr = 0;
  long long rl = 0;
  
  rep(i,1,n-1){
    
    if(s[i] == s[i-1])++ans;
    if(k == 0)continue;
    if(s[i-1] == 'L' && s[i] == 'R'){
      if(rl > 0){
        ans += 2;
        --rl;
        --k;
      }else{
      ++lr;
        }
    }
    
    if(s[i-1] == 'R' && s[i] == 'L'){
      if(lr > 0){
        ans += 2;
        --lr;
        --k;
      }else{
      ++rl;
        }
    }
    if(i == n-1 && s[i] == 'R'){
      if(lr > 0){
        ans += 1;
        --lr;
        --k;
      }else{
      ++rl;
        }
    }
    if(i == n-1 && s[i] == 'L'){
      if(rl > 0){
        ans += 1;
        --rl;
        --k;
      }else{
      ++lr;
        }
    }
  }
//  ans += max(lr + rl,k);
  
  cout << ans << endl;
//  printf("%.10f\n",ans);

  return 0;

}


Measured memory_bytes: 512
a,b=(int(x) for x in input().split())
la=[]
for i in range(b):
  la.append(str(a))
ao="".join(la)
lb=[]
for i in range(a):
  lb.append(str(b))
bo="".join(lb)
l=[]
l.append(ao)
l.append(bo)
l.sort()
print(l[0])

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

int main(){
    int K;
    cin >> K;
    vector<ll> A(K);
    for (int i = 0; i < K; i++) cin >> A[i];
    ll l = 0;
    ll r = 1e15;
    while (r - l > 1) {
        ll c = (l+r)/2;
        ll d = c;
        for (int i = 0; i < K; i++) {
            d /= A[i];
            d *= A[i];
        }
        if (d < 2) l = c;
        else r = c;
    }
    ll s = r;
    
    l = 0;
    r = 1e15;
    while (r - l > 1) {
        ll c = (l+r)/2;
        ll d = c;
        for (int i = 0; i < K; i++) {
            d /= A[i];
            d *= A[i];
        }
        if (d < 3) l = c;
        else r = c;
    }
    ll t = r;
    if (s == t) cout << -1 << endl;
    else cout << s << " " << t-1 << endl;
    return 0;
}

Measured memory_bytes: 1152
s = int(input())

n = [0, 0, 1]

for i in range(3, s) :
    next_n = sum(n[0:i-2]) + 1
    n.append(next_n)

if s > 2 :
    print(n[-1] % (10**9 + 7))
else :
    print(0)

Measured memory_bytes: 73748
#include <bits/stdc++.h>
#define rep(i,N) for (int i = 0; i < (N); ++i)
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int inf{int(1e9)};
int main(void){
  string A, B;
  cin >> A >> B;

  if (A.length() > B.length()){
    cout << "GREATER" << endl;
  }else if(A.length() < B.length()){
    cout << "LESS" << endl;
  }else{
    if (A > B) cout << "GREATER" << endl;
    else if (A < B) cout << "LESS" << endl;
    else if (A == B) cout << "EQUAL" << endl;
  }
}


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

using ll = int64_t;
#define int ll

#define FOR(i, a, b) for (int i = int(a); i < int(b); i++)
#define REP(i, b) FOR(i, 0, b)
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define ALL(x) x.begin(), x.end()

using pi = pair<int, int>;
using vi = vector<int>;
using ld = long double;

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << "(" << p.first << "," << p.second << ")";
  return os;
}

template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
  os << "{";
  REP(i, (int)v.size()) {
    if (i)
      os << ",";
    os << v[i];
  }
  os << "}";
  return os;
}

ll read() {
  ll i;
  scanf("%" SCNd64, &i);
  return i;
}

void printSpace() { printf(" "); }

void printEoln() { printf("\n"); }

void print(ll x, int suc = 1) {
  printf("%" PRId64, x);
  if (suc == 1)
    printEoln();
  if (suc == 2)
    printSpace();
}

string readString() {
  static char buf[3341000];
  scanf("%s", buf);
  return string(buf);
}

char *readCharArray() {
  static char buf[3341000];
  static int bufUsed = 0;
  char *ret = buf + bufUsed;
  scanf("%s", ret);
  bufUsed += strlen(ret) + 1;
  return ret;
}

template <class T, class U> void chmax(T &a, U b) {
  if (a < b)
    a = b;
}

template <class T, class U> void chmin(T &a, U b) {
  if (b < a)
    a = b;
}

template <class T> T Sq(const T &t) { return t * t; }

const int mod = 1e9 + 7;

signed main() {
  int n = read(), ans = 0;
  vector<string> s(n);
  REP(i, n) {
    s[i] = readString();
    sort(s[i].begin(), s[i].end());
  }
  sort(ALL(s));
  int cnt = 0;
  REP(i, n - 1) {
    if (s[i] == s[i + 1]) {
      cnt++;
    } else if (cnt) {
      ans += (cnt * (cnt + 1)) / 2;
      cnt = 0;
    }
  }
  if (cnt)
    ans += (cnt * (cnt + 1)) / 2;
  print(ans);
}


Measured memory_bytes: 7808
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;

namespace Tasks
{
    public class B
    {
        static void Main(string[] args)
        {
            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);
            Solve();
            Console.Out.Flush();
        }

        public static void Solve()
        {
            var (N, K) = Scanner.Scan<int, int>();
            var answer = 0;

            while (N > 0)
            {
                N /= K;
                answer++;
            }

            Console.WriteLine(answer);
        }

        public static class Scanner
        {
            private static Queue<string> queue = new Queue<string>();
            public static T Next<T>()
            {
                if (!queue.Any()) foreach (var item in Console.ReadLine().Trim().Split(" ")) queue.Enqueue(item);
                return (T)Convert.ChangeType(queue.Dequeue(), typeof(T));
            }
            public static T Scan<T>() => Next<T>();
            public static (T1, T2) Scan<T1, T2>() => (Next<T1>(), Next<T2>());
            public static (T1, T2, T3) Scan<T1, T2, T3>() => (Next<T1>(), Next<T2>(), Next<T3>());
            public static (T1, T2, T3, T4) Scan<T1, T2, T3, T4>() => (Next<T1>(), Next<T2>(), Next<T3>(), Next<T4>());
            public static (T1, T2, T3, T4, T5) Scan<T1, T2, T3, T4, T5>() => (Next<T1>(), Next<T2>(), Next<T3>(), Next<T4>(), Next<T5>());
            public static IEnumerable<T> ScanEnumerable<T>() => Console.ReadLine().Trim().Split(" ").Select(x => (T)Convert.ChangeType(x, typeof(T)));
        }
    }
}


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

using namespace std;

int main() {
    cin.tie(0);
    cout.tie(0);
    ios_base::sync_with_stdio(0);
    int n;
    long long sum =0;
    cin >> n;
    for(int i= 1; i <= n; ++i){
        if(i % 3 != 0 && i % 5 !=0)
            sum+=i;
    }
    cout << sum ;
}

Measured memory_bytes: 3640
#ifdef LOCAL
#define _GLIBCXX_DEBUG
#endif
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define reps(i,a,b) for(int i=a;i<b;++i)
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
using namespace std;
using ll = long long;
using P = pair<int, int>;
template<typename T> inline bool chmax(T &a,T b){if(a<b){a=b;return 1;}return 0;}
template<typename T> inline bool chmin(T &a,T b){if(b<a){a=b;return 1;}return 0;}
template<typename T> vector<T> make_vec(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>
auto make_vec(size_t a,Ts... ts){return vector<decltype(make_vec<T>(ts...))>(a,make_vec<T>(ts...));}
template<typename T,typename U,typename... V>
typename enable_if<is_same<T,U>::value>::type fill_v(U &u,const V... v){u=U(v...);}
template<typename T,typename U,typename... V>
typename enable_if<!is_same<T,U>::value>::type fill_v(U &u,const V... v){for(auto &e:u)fill_v<T>(e,v...);}

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

    int x;
    cin >> x;
    int l = lcm(x, 360);
    int ans = l / x;
    cout << ans << endl;
}


Measured memory_bytes: 3648
fun main(args: Array<String>) {
    val (a, b) = readInputLine().split(" ").map { Integer.parseInt(it) }

    var bef = 1

    for (i in 2..999) {
        val aft = i * (i + 1) / 2
        if (aft - b == bef - a) {
            println("${aft - b}")
            return
        }
        bef = aft
    }
}
 
fun readInputLine(): String {
    return readLine()!!
}


Measured memory_bytes: 35988
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define vi vector<int>
#define vll vector<ll>
#define vvi vector < vi >
#define pii pair<int,int>
#define pll pair<long long, long long>
#define vpll vector < pair<long long,long long> >
#define fill(a,val)  memset(a,val, sizeof (a))
#define sort_unique(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define all(cont) cont.begin(), cont.end()
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define MAX   1e9
#define MIN  -1e9
typedef map<int,int> mpi;
typedef set<int> seti;
typedef multiset<int> mseti;
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define rep(i, n)    for(long long int i = 0; i < (n); ++i)
#define repA(i, a, n)  for(int i = a; i <= (n); ++i)
#define repD(i, a, n)  for(int i = a; i >= (n); --i)
#define repn(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define trav(a, x) for(auto& a : x)
#define dbg(x) cout << #x << " = " << x << '\n'
#define dbg2(x,y) cout<<#x<<" = "<<x<<" & "<<#y<<" = "<<y<<endl
#define inp(a,start,len) for(long long int i = start;i < len;i++) cin>>a[i]
struct Interval{ll start,end;};
bool compare(Interval i1, Interval i2) {return (i1.start < i2.start);}

vll adj[100005];
ll vis[100005];

void dfs(ll curr){
  vis[curr] = 1;
  rep(i,adj[curr].size()){
    if(!vis[adj[curr][i]]){
      dfs(adj[curr][i]);
    }
  }
}

int main(){
	fio;
	#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	#endif
  ll n,m;
  cin>>n>>m;
  rep(i,m){
    ll a,b;
    cin>>a>>b;
    adj[a].pb(b);
    adj[b].pb(a);
  }
  ll ans = 0;
  repA(i,1,n){
    if(!vis[i]){
      ans++;
      dfs(i);
    }
  }
  cout<<ans-1;
  return 0;
}


Measured memory_bytes: 11104
local mmi = math.min
local h, w, k = io.read("*n", "*n", "*n", "*l")
local t = {}
local inf = 1000000007
local spos = 0
local len = {}
for i = 1, h do
  local str = io.read()
  for j = 1, w do
    local idx = (i - 1) * w + j
    local ss = str:sub(j, j)
    t[idx] = not (ss == "#")
    len[idx] = inf
    if ss == "S" then
      spos = idx
    end
  end
end

local taskstate = {}
for i = 1, h * w do taskstate[i] = false end
local tasks = {}
local tasknum = 0
local done = 0
local tasklim = h * w

local function addtask(idx)
  if not taskstate[idx] then
    taskstate[idx] = true
    tasknum = tasknum + 1
    local taskidx = tasknum % tasklim
    if taskidx == 0 then taskidx = tasklim end
    tasks[taskidx] = idx
  end
end

local function walk(src, dst)
  if t[dst] and len[src] < k and len[src] + 1 < len[dst] then
    len[dst] = len[src] + 1
    addtask(dst)
  end
end

len[spos] = 0
addtask(spos)

while done < tasknum do
  done = done + 1
  local taskidx = done % tasklim
  if taskidx == 0 then taskidx = tasklim end
  local idx = tasks[taskidx]
  taskstate[idx] = false

  if w < idx then walk(idx, idx - w) end
  if idx <= (h - 1) * w then walk(idx, idx + w) end
  if idx % w ~= 0 then walk(idx, idx + 1) end
  if idx % w ~= 1 then walk(idx, idx - 1) end
end

local ret = inf

for i = 1, h do
  for j = 1, w do
    local idx = (i - 1) * w + j
    if len[idx] <= k then
      local cand = mmi(i - 1, h - i)
      cand = mmi(cand, j - 1)
      cand = mmi(cand, w - j)
      ret = mmi(ret, 1 + math.ceil(cand / k))
    end
  end
end
print(ret)


Measured memory_bytes: 33652
#include <bits/stdc++.h>
//#define int long long

using namespace std;
using LL = long long;
using P = pair<int, int>;

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

#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()

const int INF = (int)1e9;
const LL INFL = (LL)1e18;
const int MOD = 1e9 + 7;

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

    string s;
    cin >> s;

    stack<char> st;
    int ans = 0;
    REP(i, s.size()){
        if(s[i] == '0' && !st.empty() && st.top() == '1'){
            ans += 2;
            st.pop();
        }else if(s[i] == '1' && !st.empty() && st.top() == '0'){
            ans += 2;
            st.pop();
        }else{
            st.push(s[i]);
        }
    }
    cout << ans << endl;
}

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

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << setprecision(10) << fixed;

	int n; cin >> n;
	int* v = new int[n];
	for(int i = 0; i < n; i++){
		cin >> v[i];
	}

	sort(v,v + n);
	double ans = v[0];
	for(int i = 1; i < n; i++){
		ans = (ans+v[i])/2;
	}
	cout << ans << endl;

	delete[] v;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vb=vector<bool>;
using vvb=vector<vb>;
using vd=vector<double>;
using vvd=vector<vd>;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
using tll=tuple<ll,ll>;
using tlll=tuple<ll,ll,ll>;
using vs=vector<string>;

#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rep(i,n) range(i,0,n)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define range(i,a,n) for(int i=(a);i<(n);i++)

#define LINF ((ll)1ll<<60)
#define INF ((int)1<<30)
#define EPS (1e-9)
#define MOD (1000000007ll)
#define fcout(a) cout<<setprecision(a)<<fixed
#define fs first
#define sc second
#define PI 3.1415926535897932384

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

template<class T>bool chmax(T&a,T b){if(a<b){a=b; return true;}return false;}
template<class T>bool chmin(T&a,T b){if(a>b){a=b; return true;}return false;}
template<class S>S acm(vector<S>&a){return accumulate(all(a),S());}
template<class S>S max(vector<S>&a){return *max_element(all(a));}
template<class S>S min(vector<S>&a){return *min_element(all(a));}
void YN(bool b){cout<<(b?"YES":"NO")<<"\n";}
void Yn(bool b){cout<<(b?"Yes":"No")<<"\n";}
void yn(bool b){cout<<(b?"yes":"no")<<"\n";}

ll max(int a,ll b){return max((ll)a,b);} ll max(ll a,int b){return max(a,(ll)b);}
template<class T>void puta(T&&t){cout<<t<<"\n";}
template<class H,class...T>void puta(H&&h,T&&...t){cout<<h<<' ';puta(t...);}
template<class S,class T>ostream&operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class S>auto&operator<<(ostream&os,vector<S>t){bool a=1; for(auto s:t){os<<(a?"":" ")<<s;a=0;} return os;}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n,k;
	cin>>n>>k;
	vvb vv(n,vb(n,true));
	rep(i,n-1){
		rep(j,min(k,n-i-2))vv[i][j+i+1]=false;
		k-=(n-i-2);
	}
	if(k>0){cout<<-1<<endl;
		return 0;
	}
	vl x,y;
	rep(i,n)range(j,i+1,n){
		if(vv[i][j]){
			x.push_back(i+1);
			y.push_back(j+1);
		}
	}
	cout<<x.size()<<endl;
	rep(i,x.size())puta(x[i],y[i]);
}


Measured memory_bytes: 512
#include<iostream>
#include<cstdio>
#include<math.h>
#include<algorithm>
using namespace std;
long long n,a[300006],s,sum=0,sum1=0;
int main()
{
	scanf("%lld",&n);
	for(int i=1;i<=n;++i)
	{
		scanf("%lld",&a[i]);
	}
	for(int i=1;i<=n;++i)
    {
		sum1+=(a[i]*sum);
		sum1%=1000000007;
		sum+=a[i];
		sum%=1000000007;
	}
	/*sort(a+1,a+n);
	for(int i=1;i<=n;++i)
	{
		s=sqrt(a[i])+1;
		for(int j=1;j<=s;++j)
		{
			if(a[j]>s)
			break;
			if(a[i]%a[j]==0&&a[i]!=a[j])
			sum+=a[i];
		}
	}*/
	printf("%lld",sum1%1000000007);
	return 0;
}

Measured memory_bytes: 5388
import java.util.*;
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String S = sc.next();
		String[] Sarray = S.split("");
		int num0 = 0;
		int num1 = 0;
		int answer = 0;
		for(int i = 0; i < S.length(); i++) {
			if(Sarray[i].equals("0")) num0 += 1;
			else num1 += 1;
		}
		if(num0 < num1) answer = num0*2;
		else answer = num1*2;
		System.out.println(answer);
		}

}


Measured memory_bytes: 33152
n, k = list(map(int, input().split()))
l = list(range(1, n + 1))
count = 0
for i in l:
    if i < k:
        while True:
            l[i - 1] = l[i - 1] * 2
            count += 1
            if l[i - 1] >= k:
                l[i -1] = (1 / n) * (0.5 ** count)
                count = 0
                break
    else:
        l[i -1] = (1 / n)
print(sum(l))


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

int main() {
  int A,B,C,D;
  cin >> A >> B >> C >> D;

  int bgn= max(A,C);
  int end= min(B,D);

  int ans= max(0, end-bgn);
  
  cout << ans << endl;
}

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

using namespace std;

int a[3];
int cnt[4];

bool calc(){
  for(int i=0;i<3;i++){
    if(a[i] + a[(i+1)%3] <= a[(i+2)%3]) return false;
  }
  cnt[0]++;
  if(a[0] * a[0] + a[1] * a[1] == a[2] * a[2]) cnt[1]++;
  if(a[0] * a[0] + a[1] * a[1] > a[2] * a[2]) cnt[2]++;
  if(a[0] * a[0] + a[1] * a[1] < a[2] * a[2]) cnt[3]++;
  return true;
}

main(){
  fill(cnt, cnt+4, 0);
  bool f = true;
  while(cin >> a[0] >> a[1] >> a[2]){
    sort(a, a+3);
    if(f){
      if(!calc()) f = false;
    }
  }
  for(int i=0;i<4;i++){
    if(i) cout << ' ';
    cout << cnt[i];
  }
  cout << endl;
}

Measured memory_bytes: 1176
N, M = gets.split.map(&:to_i)
edges = Array.new(N){[]}
M.times do
    a, b = gets.split.map(&:to_i)
    edges[a-1].push(b-1)
    edges[b-1].push(a-1)
end

parity = [0]
stack = [0]
while stack.length > 0
    u = stack.pop
    edges[u].each do |v|
        if parity[v]
            if parity[u] == parity[v]
                puts N*(N-1)/2 - M
                exit
            end
        else
            parity[v] = 1 - parity[u]
            stack.push(v)
        end
    end
end
puts parity.count(0) * parity.count(1) - M

Measured memory_bytes: 12540
N, M = [int(i) for i in input().split()]
counter = {
  i+1: 0 for i in range(N)
}
for _ in range(M):
  a,b = [int(i) for i in input().split()]
  counter[a] += 1
  counter[b] += 1

for i in counter.values():
  print(i)

Measured memory_bytes: 3060
#include <iostream>
#include <cmath>
#include <set>
#include <string>
#include <algorithm>
#include <vector>
#include <bitset>
#include <iomanip>
#include <map>
#include <queue>
#include <numeric>

using std::cin;
using std::cout;
using std::endl;
using std::string;
using std::vector;
using std::bitset;

#define rep(i,n)    for(int i=0; i<(int)n; i++)
#define reps(i,s,e) for(int i=s; i<(int)e; i++)
#define coutd(i) cout << std::fixed << std::setprecision(i)
typedef long double ld;
typedef long long ll;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef std::pair<int, int> pii;
typedef std::pair<ll, ll> pll;

template<class T>
using Graph = vector<vector<T>>;

const int INT_BIG = 1<<28;

int main() {
    int placeNum, roadNum;
    cin >> placeNum >> roadNum;

    vint heights(placeNum);
    rep(i, placeNum) {
        cin >> heights[i];
    }

    // 0未調査 1調査済み
    vint flag(placeNum, 0);

    Graph<int> dest(placeNum, vint());
    rep(i, roadNum) {
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        dest[a].push_back(b);
        dest[b].push_back(a);
    }

    int count = 0;
    rep(i, placeNum) {
        if (flag[i] == 0) {
            flag[i] = 1;
            for(int d : dest[i]) {
                if (heights[i] > heights[d]) {
                    flag[d] = 1;
                } else {
                    goto OUT;
                }
            }
            count++;
            OUT:
            ;
        }
    }

    cout << count << endl;
}

Measured memory_bytes: 9064
#include <stdio.h>
int main()
{
	int zai,n,m[10001];
	scanf("%d %d",&n,&zai);
for(int i=0;i<n;i++)
{	
scanf("%d",&m[i]);
zai -= m[i];
}

for(int i=n-1;i>0;i--)
{

if(m[i]<m[i-1])
{int f=0; 
f = m[i];
m[i] = m[i-1];
m[i-1] = f;
}


}


while(zai>=m[0])
{
zai -= m[0];
n++;

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

}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<(int64_t)N;i++)
typedef int64_t LL;
int main()
{
  int N;
  LL sum=0;
  cin>>N;
  rep(i,N){if((i+1)%3>0&&(i+1)%5>0)sum+=i+1;}
  return cout<<sum<<endl,0;
}

Measured memory_bytes: 3588
N = int(input())
A = [int(i) for i in input().split()]

A_dict = {}
for a in A:
  A_dict[a] = A_dict.get(a,0) + 1
  A_dict[a+1] = A_dict.get(a+1,0) + 1
  A_dict[a-1] = A_dict.get(a-1,0) + 1

ans = max(A_dict.values())
print(ans)


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

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

using namespace std;

int main(){
	int d; scanf("%d",&d);
	vector c(26,0);
	rep(j,26) scanf("%d",&c[j]);
	vector a(d,vector(26,0));
	rep(i,d) rep(j,26) scanf("%d",&a[i][j]);
	vector t(d,0);
	rep(i,d) scanf("%d",&t[i]), t[i]--;

	vector score(26,0),last(26,0);
	rep(i,d){
		score[t[i]]+=a[i][t[i]];
		last[t[i]]=i+1;
		rep(j,26) score[j]-=c[j]*(i+1-last[j]);
	}

	int q; scanf("%d",&q);
	rep(_,q){
		int x,t2; scanf("%d%d",&x,&t2); x--; t2--;
		int t1=t[x];
		t[x]=t2;
		score[t1]=last[t1]=0;
		score[t2]=last[t2]=0;
		rep(i,d){
			if(t[i]==t1 || t[i]==t2){
				score[t[i]]+=a[i][t[i]];
				last[t[i]]=i+1;
			}
			score[t1]-=c[t1]*(i+1-last[t1]);
			score[t2]-=c[t2]*(i+1-last[t2]);
		}
		printf("%d\n",accumulate(score.begin(),score.end(),0));
	}

	return 0;
}


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

template<typename First, typename Second, typename Third>
struct triple {
   First first;
   Second second;
   Third third;
};

using namespace std;

void solve(){
    int c,k;
    cin>>c>>k;
    vector<int>v(c);
    for(int i=0;i<c;i++){
           cin>>v[i];
    }

    sort(v.rbegin(),v.rend());
    long long sum=0;
    for(int i=0;i<k;i++)
         sum+=v[i];    
    cout<<sum; 
       
}

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

    solve(); 
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
char d[10];
int main()
{
    ios_base:: sync_with_stdio(false);
    cin.ignore(NULL);
    int n,k,i,j;
    char a;

    cin>>n>>k;
    for(i=0;i<k;i++){
        cin>>a;
        d[a-'0']=1;
    }
    for(i=n;i<100000;i++){
        string s=to_string(i);
        for(j=0;j<s.size();j++){
            if(d[s[j]-'0']==1) goto e;
        }
        cout<<i;break;e:;
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i < (n); i++)
#define lower(s) transform(s.begin(), s.end(), s.begin(), ::tolower)
using namespace std;
using ll = long long;
int INF = 1001001001;

int main() {
  int n;
  cin >> n;
  vector<int> b(n-1);
  rep(i, n-1) cin >> b[i];
  vector<int> a(n);
  a[0] = b[0];
  for(int i=1; i<n-1; i++) {
    a[i] = min(b[i-1], b[i]);
  }
  a[n-1] = b[n-2];
  int ans = 0;
  rep(i,n) ans+=a[i];
  cout << ans << endl;
  return 0;
}

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

int main(){
  int n,nu=1e9;
  cin>>n;
  vector<int>x(n);
  for(int i=0;i<n;i++){
    cin>>x[i];
  }
  for(int i=1;i<100;i++){
    int hu=0;
    for(int j=0;j<n;j++){
      hu+=(x[j]-i)*(x[j]-i);
    }
    nu=min(nu,hu);
  }
  cout<<nu<<endl;
}


Measured memory_bytes: 256
n,m = map(int,input().split())
lng = [0]
for _ in range(n-1):
    lng.append(lng[-1] + int(input()))
i = 0
sm = 0
for _ in range(m):
    j = i+int(input())
    sm += abs(lng[i]-lng[j])
    sm %= 100000
    i = j
print(sm)

Measured memory_bytes: 11600
import java.util.Arrays;
import java.util.Scanner;
 
//選択ソート
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] A = new int[n];
        for (int i = 0; i < A.length; i++) {
            A[i] = sc.nextInt();
        }
        int cnt = new Main().selectionSort(A);
        String ans = Arrays.toString(A);
        System.out.println(ans.replace("[", "").replace(",", "").replace("]", ""));
        System.out.println(cnt);
 
    }
 
    int selectionSort(int[] array) {
        int cnt = 0; // 交換回数
        for (int i = 0; i < array.length - 1; i++) { // 最後の要素1つだけのときはやらなくていいのでn-1
            int minv = i;
            for (int j = i + 1; j < array.length; j++) {
                if (array[j] < array[minv]) {
                    minv = j;
                }
            }
            if (minv != i) {
                int tmp = array[i];
                array[i] = array[minv];
                array[minv] = tmp;
                cnt++;
            }
        }
        return cnt;
    }
 
}


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

int main() {
  ll a,b;
  cin>>a>>b;
  ll c=min(a,b);
  ll k;
  cin>>k;
  ll g=0;
  vector<ll>vec(0);
  for(ll i=1;i<=c;i++){
    if(a%i==0&&b%i==0){
      vec.push_back(i);
      g+=1;
      }
    }
  cout<<vec.at(g-k)<<endl;
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
bool is_prime(ll n) {
    if(n == 1) return false; // 1 は素数ではない。
    for(ll i = 2; i*i <= n; ++i) { // 2 <= i <= sqrt(n) に約数があれば、
        if(n % i == 0) return false; // n は素数ではない
    }
    return true;
}
int main(){
  ll n,ans=0;
  cin >>n;
  if(is_prime(n)){
   while(1){
    if(n==0) break;
    ans++;
    n/=10;
   }
   cout <<ans<<endl;
  }
  else {
    ll k=sqrt(n),i;
    for(i=k;;i--){
     if(n%i==0) break;
    }
    ll p=n/i,ans1=0;
    while(1){
     if(p==0) break;
     ans1++;
     p/=10;
    }
    while(1){
     if(i==0) break;
     ans++;
     i/=10;
    }
    cout <<max(ans,ans1)<<endl;
  }
  }


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long int ll;
int main(){
	int N, A[100000];
	cin >> N;
	for(int i = 0; i < N; i++) cin >> A[i];
	int ans = 0;
	for(int i = 0; i < N; i++){
		int cnt = 0;
		while(i + 1 < N && A[i + 1] == A[i]) i++;
		if(A[i + 1] > A[i]){
			while(i + cnt + 1 < N && A[i + cnt + 1] >= A[i + cnt]){
				cnt++;
			}
		}else{
			while(i + cnt + 1 < N && A[i + cnt + 1] <= A[i + cnt]){
				cnt++;
			}
		}
		i += cnt;
		ans++;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define mp make_pair
#define pb push_back
#define all(x) x.begin(), x.end()
#define fi first
#define se second
#define println(x) cout << x << '\n'
#define print(x) cout << x << " "
#define inf INT_MAX
#define sz(x) (ll)x.size()
#define boost ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef pair< int , pii> piii;
typedef pair<int,bool> pib;
typedef vector<pii> vii;
typedef vector<pib> vib;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef pair<string,string> pss;
typedef vector<pss> vss;
const int MOD = 1e9 + 7; //998244353;
int n , m;
int maxi = 0;
vi dp;
vvi graph;
int compute(int n){
   if(dp[n] != -1)return dp[n];
   dp[n] = 0;
   for(int i : graph[n]){
       dp[n] = max(dp[n] , compute(i) + 1);
   }
   maxi = max(dp[n] , maxi);
   return dp[n];
}
int main(){
    boost;
    cin >> n >> m;
    dp.resize(n);
    fill(all(dp), -1);
    graph.resize(n);
    while(m--){
        int x , y;
        cin >> x >> y;
        graph[y-1].pb(x-1);
    }
    for(int i = 0;i<n;i++){
        if(dp[i] == -1) compute(i);
    }
    cout << maxi;
}


Measured memory_bytes: 10624
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
void Say(bool say, string a = "Yes", string b = "No"){cout << (say ? a : b) << endl;};

typedef pair<ll, ll>P;

ll N, M;
vector<ll>path[202020];
ll parent[202020];
ll depth[202020];

ll cnt[202020];

int main(){

    cin >> N >> M;
    for(ll i = 0; i < N - 1; i++){
        ll a, b;
        cin >> a >> b;
        path[a].push_back(b);
        path[b].push_back(a);
    }
    queue<ll>Q;
    Q.push(1);
    depth[1] = 1;
    while(!Q.empty()){
        ll idx = Q.front();
        Q.pop();
        for(ll i = 0; i < path[idx].size(); i++){
            ll nxt = path[idx][i];
            if(depth[nxt])continue;
            depth[nxt] = depth[idx] + 1;
            parent[nxt] = idx;
            Q.push(nxt);
        }
    }
    vector<P>v;
    for(ll i = 1; i <= N; i++){
        v.push_back(P(depth[i], i));
    }
    sort(v.begin(), v.end());

    for(ll i = 0; i < M; i++){
        ll p, x;
        cin >> p >> x;
        cnt[p] += x;
    }
    for(ll i = 0; i < v.size(); i++){
        ll idx = v[i].second;
        for(ll j = 0; j < path[idx].size(); j++){
            ll nxt = path[idx][j];
            if(nxt == parent[idx])continue;
            cnt[nxt] += cnt[idx];
        }
    }

    for(ll i = 1; i <= N; i++){
        cout << cnt[i];
        if(i == N)cout << endl;
        else cout << " ";
    }


    return 0;
}

Measured memory_bytes: 25196
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(int i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1};

int main() {
  int n;
  cin >> n;
  vector<P> red(n), blue(n);
  rep(i, n) {
    int a, b;
    cin >> a >> b;
    red[i] = P(b, a);
  }
  rep(i, n) {
    int a, b;
    cin >> a >> b;
    blue[i] = P(a, b);
  }
  sort(all(red));
  reverse(all(red));
  sort(all(blue));
  rep(i, n) red[i] = P(red[i].second, red[i].first);
  int ans = 0;
  for(auto bp : blue) {
    int bx = bp.first;
    int by = bp.second;
    rep(i, red.size()) {
      int rx = red[i].first;
      int ry = red[i].second;
      if(rx < bx && ry < by) {
        ans++;
        red.erase(red.begin() + i);
        break;
      }
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
	ll n,a[114514];
	cin>>n;
	for(int i=0;i<n;i++)cin>>a[i];
	sort(a,a+n);
	cout<<a[n/2]-a[n/2-1];
	return 0;
}

Measured memory_bytes: 1024
from operator import itemgetter

n = int(input())
XL = []
for _ in range(n):
    x, l = map(int, input().split())
    XL.append([x-l, x+l])
XL.sort(key=itemgetter(1))
INF = 10**18
cur = -INF
ans = 0
for i in range(n):
    if cur <= XL[i][0]:
        ans += 1
        cur = XL[i][1]
print(ans)


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

using namespace std;
typedef long long ll;

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

    vector<int> v(100001,0);
    ll sum=0;
    for(int i=1;i<=n;++i) {
        int temp;
        cin>>temp;
        sum+=temp;

        v[temp]++;
    }

    int q;
    cin>>q;

    ll b,c;
    while(q--)
    {
        cin>>b>>c;

            sum-=(v[b]*b);
            sum+=(v[b]*c);

            v[c] += v[b];
            v[b]=0;
        
        cout<<sum<<endl;
    }
}

Measured memory_bytes: 3764
#include<iostream>
    #include<stdio.h>
    //#include <bits/stdc++.h>
    #include<vector>
    #include<float.h>
    #include<iomanip>
    #include<algorithm>
    #include<string>
    #include<cstring>
    #include<math.h>
    #include<cmath>
    #include<sstream>
    #include<set>
    #include<map>
    #include<queue>
    #include <cassert>
    #include <cmath>
    #include<cstdint>

    #define INF 1e9
    #define rep(i,n)for(int i=0;(i)<(int)(n);i++)
    #define REP(i,a,b)for(int i=(int)(a);(i)<=(int)(b);i++)
    #define VEC(type, c, n) std::vector<type> c(n);for(auto& i:c)std::cin>>i;
    #define vec(type,n) vector<type>(n)
    #define vvec(m,n) vector<vector<int>> (int(m),vector<int>(n))

    using namespace std;
    using ll = long long;
    using Graph = vector<vector<int>>;
    using P = pair<int,int>;

    int main(){
       int n;cin>>n;
       vector<P> p;
       rep(i,n){
           ll a,b;cin>>a>>b;
           p.emplace_back(b,a);
       }
       sort(p.begin(),p.end());
       ll now = 0;
       rep(i,n){
           ll f = p[i].first;
           ll s = p[i].second;
           now += s;
           if(now>f){
               cout<<"No";
               return 0;
           }
       }
       cout<<"Yes";
    }
    


Measured memory_bytes: 2420