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


int main() {
	//code
	int x1,x2,x3,x4,x5;
	cin>>x1>>x2>>x3>>x4>>x5;
	int sum=0;
	sum=x1+x2+x3+x4+x5;
	cout<<15-sum;
	return 0;
}


Measured memory_bytes: 3520
N, M = map(int, input().split())
# [ACしたかどうか, 初ACは何回目の提出か]
prob = [[0] * 2 for _ in range(N + 1)]
# print(prob)
ps_list = [[0, 0]]

for i in range(1, M + 1):
    p, s = input().split()
    p = int(p)
    ps_list.append([p, s])
    if s == "AC" and prob[p] == [0, 0]:
        prob[p] = [1, i]


# print(prob)
# この段階でACは数えられる
ac = 0
for item in prob:
    if item[0] == 1:
        ac += 1

penalty = 0
for i in range(1, M + 1):
    p = ps_list[i][0]
    s = ps_list[i][1]
    if s == "WA" and i < prob[p][1]:
        penalty += 1

print(ac, penalty)


Measured memory_bytes: 38976
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define o(a) cout << a << endl
#define int long long
#define first first
#define second se
using namespace std;
typedef pair<int, int> P;
typedef vector<int> vi;

signed main(){
    int n, k;
    cin >> n >> k;
    int ans = k;
    rep(i, 1, n){
        ans *= k - 1;
    }
    o(ans);
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
    static int A,B,N,hmax;
    static int[] h;
    public static void main(String[] args) {
        // TODO Auto-generated method stub
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        A = sc.nextInt();
        B = sc.nextInt();
        h = new int[N];
        int sum = 0;
        hmax=0;
        for(int i = 0; i<N; i++){
            h[i] = sc.nextInt();
            if(h[i] > hmax)
                hmax=h[i];
        }
        int T=hmax/B+2;
        int err=T;
        int h=T;
        int l = 1;        
        int mid = (h+l)/2;
        while(true){
        //    System.out.println(h + " " + mid + " " + l);
            if(err==0)
                break;
            if(isSol(mid)){
                h=mid;
            }else{
                l = mid+1;
            }
            err=h-l;
            mid=(h+l)/2;
        }
        System.out.println(h);

    }
    static boolean isSol(int T){
        if(func(T)>=0){
            return true;
        }else{
            return false;
        }
    }
    static int func(int n){
        double sum = 0;
        for(int i = 0; i <h.length;i++ ){
            sum += (Math.ceil(Math.max(((double)h[i]-(double)B*n)/(A-B),0)));
        }
        return n-(int)(sum);
    }

}


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

int main() {
	int N;
	string S;
	cin>>N;
	cin>>S;
	if(N%2==1){
		cout<<"No"<<endl;
		return 0;
	}
	string be="",af="";
	for(int i=0; i<N/2; i++){
		be+=S[i];
	}
	for(int i=N/2; i<N; i++){
		af+=S[i];
	}
	if(be==af) cout<<"Yes"<<endl;
	else       cout<<"No"<<endl;

}

Measured memory_bytes: 256
object Main extends App {

  import scala.io.StdIn._
  import scala.math._

  val n = readLine.trim.toInt

  val numbers = readLine.trim.split(' ').map(_.toInt)
  val mod = 1000000007L
  println(
    calPattern(numbers)
  )
  def calPattern(numbers: Array[Int]): Long = {
    val memo = Array.tabulate(n){_ ⇒ Array.tabulate(2){_ ⇒ None: Option[Long]}}
    val prime = primes(1000000)
    def sub(number: List[Int], position: Int, lastPrime: Int, count: Int = 0): Long = {
      number match {
        case Nil ⇒ 1L
        case p::t ⇒
          memo(position)(count) match {
            case Some(r) ⇒ r
            case None if lastPrime < p ⇒
              (binarySearch(prime, p) match {
                case Some(_) ⇒
                  t match {
                    case e::rest ⇒ (sub(rest, position + 2, p, 1) + sub(t, position + 1, p, 0)) % mod
                    case Nil ⇒ 1L
                  }
                case None ⇒ 0L
              }).also{r ⇒ memo(position)(count) = Some(r)}
            case None ⇒
              memo(position)(count) = Some(0L)
              0L
          }
      }
    }
    sub(numbers.toList, 0, 0)
  }
  def binarySearch(array: Array[Int], target: Int): Option[Int] = {
    var left = 0
    var right = array.length
    while (left < right){
      val mid = (left + right) / 2
      if (array(mid) < target){
        left = mid + 1
      }else {
        right = mid
      }
    }
    if (right < array.length && array(right) == target) Some(right)
    else None
  }
  def primes(upper: Int): Array[Int] = {
    val memo = Array.tabulate(upper + 1){_ ⇒ true}
    for (i ← 2 to math.sqrt(upper).toInt){
      if (memo(i)){
        for (j ← i * 2 to upper by i){
          memo(j) = false
        }
      }
    }
    (2 to upper).filter(i ⇒ memo(i)).toArray
  }


  implicit class Extension[T](val value :T){
    def also(func: T ⇒ Unit): T = {
      func(value)
      value
    }
    def let[R](func: T ⇒ R): R = func(value)
  }
}


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

using namespace std;

#define all(x) x.begin(), x.end()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define reps(i, m, n) for (int i = m; i <= n; ++i)

using i64 = long long;
using pii = pair<i64, i64>;

template<class A, class B>inline bool chmax(A &a, const B &b){return b > a ? a = b,1 : 0;}
template<class A, class B>inline bool chmin(A &a, const B &b){return b < a ? a = b,1 : 0;}

constexpr int INF = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int mod = int(1e9) + 7;

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

  i64 n;
  cin >> n;

  i64 fact = 1;
  for (i64 i = 1; i <= n; ++i) {
    fact *= i;
    fact %= mod;
  }

  cout << fact << "\n";
  return 0;
}

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

using namespace std;
int main()
{
    int w, a, b;
    cin >> w >> a >> b;
    if (a < b)
    {
        if (b - a - w > 0)
        {
            cout << b - a - w << endl;
            return 0;
        }
        else
        {
            cout << "0" << endl;
        }
    }
    else if (b < a)
    {
        if (a - b - w > 0)
        {
            cout << a - b - w << endl;
            return 0;
        }
        else
        {
            cout << "0" << endl;
        }
    }
    else
    {
        cout << "0" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
import java.io.*;
class Main{
  public static void main(String[] args)throws IOException{
    BufferedReader mBufferedReader=new BufferedReader(new InputStreamReader(System.in));
    String str=mBufferedReader.readLine();
    String[] arr=str.split(" ");
    int a=Integer.parseInt(arr[0]);
    int b=Integer.parseInt(arr[1]);
    int c=Integer.parseInt(arr[2]);
    if(a<b && b<c){
      System.out.println("Yes");
    }else{
      System.out.println("No");
    }
  }
}


Measured memory_bytes: 24348
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define Rep(i,s,n) for(int i=s;i<n;i++)
typedef long long int ll;
typedef pair<int, int> P;
typedef long double ld;
void ans(bool x){if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;}

const ll INF=1001001001;
// auto mod int
const int mod = 1000000007;

int main(){
  int n;cin>>n;
  ll a[n];
  rep(i,n){
    cin>>a[i];
  }
  ll ans=0;
  ll m=1;
  rep(i,60){
    ll a1=0;
    rep(j,n){
      if(a[j]>>i&1){
        a1+=1;
        a1%=mod;
      }
    }
    ll now=a1*(n-a1)%mod;
    rep(j,i) now=now*2%mod;
    ans+=now;
    ans%=mod;
  }
  
  cout<<ans<<endl;
}

Measured memory_bytes: 2560
import java.util.*;

class Main{
 public static void main(String[] args){
  Scanner scn = new Scanner(System.in);
   long n = scn.nextLong();
   long x = scn.nextLong();
   long t = scn.nextLong();
   
   
   System.out.println((n+x-1)/x*t);
 }
  
}


Measured memory_bytes: 26940
n = int(input())
ans = []
def num2alpha(num):
    if num<=26:
        return chr(64+num)
    elif num%26==0:
        return num2alpha(num//26-1)+chr(90)
    else:
        return num2alpha(num//26)+chr(64+num%26)
print(num2alpha(n).lower())


Measured memory_bytes: 9020
#include <bits/stdc++.h>  // ver2.2.5
#define int long long
#define endl "\n"
#define ALL(v) (v).begin(),(v).end()
#define COUNT(a,i) upper_bound(ALL(a),i)-lower_bound(ALL(a),i)
#define Vi vector<int>
#define VVi vector<Vi>
#define Vs vector<string>
#define Pii pair<int,int>
#define VPii vector<Pii>
#define Tiii tuple<int,int,int>
#define PQi priority_queue<int>
#define PQir priority_queue<int,vector<int>,greater<int>>
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define itos to_string
#define stoi stoll
#define FI first
#define SE second
#define cYES cout<<"YES"<<endl
#define cNO cout<<"NO"<<endl
#define cYes cout<<"Yes"<<endl
#define cNo cout<<"No"<<endl
#define _ <<' '<<
#define sortr(v) sort(v,greater<>())
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repeq(i,a,b) for(int i=a;i<=b;i++)
#define repreq(i,a,b) for(int i=a;i>=b;i--)
#define leng(n) (int)(log10(n)+1)
#define dem(a,b) ((a+b-1)/(b))
#define Vin(a) rep(iI,0,a.size())cin>>a[iI]
#define Vout(a) rep(lZ,0,a.size()-1)cout<<a[lZ]<<' ';cout<<a.back()<<endl
#define VVout(a) rep(lY,0,a.size()){Vout(a[lY]);}
#define VPout(a) rep(lX,0,a.size())cout<<a[lX].FI<<' '<<a[lX].SE<<endl
#define Verr(a) rep(iZ,0,a.size()-1)cerr<<a[iZ]<<' ';cerr<<a.back()<<endl
#define VVerr(a) rep(iY,0,a.size()){Verr(a[iY]);}
#define VPerr(a) rep(iX,0,a.size())cerr<<a[iX].FI<<' '<<a[iX].SE<<endl
#define INF 3000000000000000000  //  3.0*10^18(MAXの1/3くらい)
#define MAX LLONG_MAX
#define MOD 1000000007  //  10^9 + 7
using namespace std;

int gcd(int a,int b){return b?gcd(b,a%b):a;}  //  最大公約数gcd
int lcm(int a,int b){return a/gcd(a,b)*b;}  //  最小公倍数lcm
void press(auto &v){v.erase(unique(ALL(v)),v.end());}  //  圧縮
int mypow(int x, int n, int m){  //  累乗x^n(mod m)  O(log(n))
if(n==0)return 1;if(n%2==0)return mypow(x*x%m,n/2,m);else return x*mypow(x,n-1,m)%m;}



signed main() {
  cin.tie(0);cout.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(12);
  int n;
  cin >> n;
  repeq(i,1,9){
    repeq(j,1,9){
      if(i*j == n) {cYes;return 0;}
    }
  }
  cNo;
  return 0;
}

Measured memory_bytes: 256
n,k = map(int, input().split())
s = str(input())

cnt = s.count('RL')
ans = 0

for i in range(0,n-1):
    if s[i] != s[i+1]:
        cnt += 1
    else:
        ans += 1


if cnt >= k:
    ans += 2*k
else:
    ans += 2*cnt
    if k-cnt>=2:
        if s[-1] == 'L' and s[0] == 'L':
            ans += 2
        elif s[-1] == 'L' or s[0] == 'L':
            ans += 1
    else:
        if s[-1] == 'L' or s[0] == 'L':
            ans += 1       


print(min(ans,n-1))

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

#define INF 1e9
#define llINF 1e18
#define MOD 1e9+7
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long
using namespace std;
int main(){
  int n;cin>>n;
  vector<ll>A(n),B(n);
  for(int i=0;i<n;i++)
    cin>>A[i]>>B[i];
  reverse(A.begin(),A.end());
  reverse(B.begin(),B.end());
  ll ans=0;
  for(int i=0;i<n;i++){
    if((A[i]+ans)%B[i])
    ans+=(B[i]-(A[i]+ans)%B[i]);
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
int gcd(int a,int b,int &x,int &y)
{
	if(b==0)
	{
		x=1; y=0;
		return a;
	}
	int g=gcd(b,a%b,x,y);
	int t1=y;
	int t2=x-(a/b)*y;
	x=t1;
	y=t2;
	return g;
}
int main() {
	// your code goes here
	int a[3][3];
	for(int i=0;i<3;++i)for(int j=0;j<3;++j)cin>>a[i][j];
	int n; cin>>n;
    int b[3][3];
    memset(b,0,sizeof(b));
    while(n--)
    {
    	int x; cin>>x;
    	for(int i=0;i<3;++i)for(int j=0;j<3;j++)if(a[i][j]==x)b[i][j]=1;
    }
    int flag=0;
    for(int i=0;i<3;++i)if(b[i][0]&&b[i][1]&&b[i][2])flag=1;
    for(int i=0;i<3;++i)if(b[0][i]&&b[1][i]&&b[2][i])flag=1;
    if(b[0][0]&&b[1][1]&&b[2][2])flag=1;
    if(b[0][2]&&b[1][1]&&b[2][0])flag=1;
    if(flag)cout<<"Yes";
    else cout<<"No";
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <time.h>
#include <stack>
#include <array>
#include <list>
#define popcount __builtin_popcount
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;

int main()
{
	int x; cin>>x;
	int g=gcd(360, x);
	cout<<360/g<<endl;
	return 0;
}


Measured memory_bytes: 3644
#include <iostream>
#include <cstdio>
#include <cmath>
#include <string>

using namespace std;
typedef long long ll;

int main(){
  string a;cin>>a;
  if(a[0]=='1'){
    a[0]='9';
  }else{
    a[0]='1';
  }
  if(a[1]=='1'){
    a[1]='9';
  }else{
    a[1]='1';
  }
  if(a[2]=='1'){
    a[2]='9';
  }else{
    a[2]='1';
  }
  cout<<a<<endl;
}

Measured memory_bytes: 256
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let n: i8 = read();
    let mut vec = vec![];
    for _ in 0..n {
        let v: f64 = read();
        vec.push(v);
    }
    //reverse order
    vec.sort_by(|a, b| b.partial_cmp(a).unwrap());
    for _ in 0..(n - 1) {
        let v1 = vec.pop().unwrap();
        let v2 = vec.pop().unwrap();
        vec.push((v1 + v2) / 2.0);
        vec.sort_by(|a, b| b.partial_cmp(a).unwrap());
    }
    println!("{}", vec.pop().unwrap());
}


Measured memory_bytes: 4352
#include <iostream>
#include <iomanip>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <tuple>
#include <stack>

using namespace std;
typedef long long ll;

#define MAX_N 1000000
#define INF 1000000

int a[MAX_N];
int b[MAX_N];


int main() {

  // ---------------------
  // Input
  
  cin.tie(nullptr);
  ios::sync_with_stdio(false);

  int N, K;
  cin >> N >> K;

  // ---------------------
  // 

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

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


Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
int main()
{
    int h,w;
    int i,j;
    char text[100][100];
    char nu;
    scanf("%d %d",&h,&w);
    scanf("%c",&nu);
    for (i=0;i<h;i++)
    {
        for (j=0;j<w;j++)
        {
            scanf("%c",&text[i][j]);
        }
        scanf("%c",&nu);
    }
    for (i=0;i<h;i++)
    {
        for (j=0;j<w;j++)
        {
            printf("%c",text[i][j]);
        }
        printf("\n");
         for (j=0;j<w;j++)
        {
            printf("%c",text[i][j]);
        }
        printf("\n");
    }
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using pint = pair<int,int>;
ll mod = 1000000007,mod2 = 998244353;

void chmin(long long &a, long long b) { if (a > b) a = b; }
void chmax(long long &a, long long b) { if (a < b) a = b; }
const long long INF = 1LL<<60;
ll gcd(ll a,ll b){
    if(b == 0) return a;
    else return gcd(b,a%b);
}

template<int MOD> struct Fp {
    long long val;
    constexpr Fp(long long v = 0) noexcept : val(v % MOD) {
        if (val < 0) val += MOD;
    }
    constexpr int getmod() { return MOD; }
    constexpr Fp operator - () const noexcept {
        return val ? MOD - val : 0;
    }
    constexpr Fp operator + (const Fp& r) const noexcept { return Fp(*this) += r; }
    constexpr Fp operator - (const Fp& r) const noexcept { return Fp(*this) -= r; }
    constexpr Fp operator * (const Fp& r) const noexcept { return Fp(*this) *= r; }
    constexpr Fp operator / (const Fp& r) const noexcept { return Fp(*this) /= r; }
    constexpr Fp& operator += (const Fp& r) noexcept {
        val += r.val;
        if (val >= MOD) val -= MOD;
        return *this;
    }
    constexpr Fp& operator -= (const Fp& r) noexcept {
        val -= r.val;
        if (val < 0) val += MOD;
        return *this;
    }
    constexpr Fp& operator *= (const Fp& r) noexcept {
        val = val * r.val % MOD;
        return *this;
    }
    constexpr Fp& operator /= (const Fp& r) noexcept {
        long long a = r.val, b = MOD, u = 1, v = 0;
        while (b) {
            long long t = a / b;
            a -= t * b; swap(a, b);
            u -= t * v; swap(u, v);
        }
        val = val * u % MOD;
        if (val < 0) val += MOD;
        return *this;
    }
    constexpr bool operator == (const Fp& r) const noexcept {
        return this->val == r.val;
    }
    constexpr bool operator != (const Fp& r) const noexcept {
        return this->val != r.val;
    }
    friend constexpr ostream& operator << (ostream &os, const Fp<MOD>& x) noexcept {
        return os << x.val;
    }
    friend constexpr Fp<MOD> modpow(const Fp<MOD> &a, long long n) noexcept {
        if (n == 0) return 1;
        auto t = modpow(a, n / 2);
        t = t * t;
        if (n & 1) t = t * a;
        return t;
    }
};

const int MOD = 1000000007;
using mint = Fp<MOD>;

mint cal(ll n, ll k){
    mint ans = 1;
    for (ll i = 0; i < k; ++i) {
        ans *= (n-i);
        ans /= (i+1);
    }
    return ans;
}

int main() {
    ll n,a,b;
    cin >> n >> a >> b;
    mint ans = modpow(mint(2),n)-1;
    ans -= cal(n,a)+cal(n,b);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
X = int(input())

def make_div(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
    divisors.sort()
    return divisors

def f(x, y):
  return x**5 - y**5 - X

Flag = True

for A in range(-1000, 1000):
  if Flag:
    for i in make_div(X):
      B = A - i
      if f(A, B) == 0:
        print(A, B)
        Flag = False
        break
  else:
    break


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

using namespace std;

int main()
{
	int x,y,z;
	while(cin >> y >> x >> z && x)
	{
		double set=sqrt(x*x+z*z)/2;
		int n,r;
		cin >> n;
		while(n--)
		{
			cin >> r;
			if(set<r)cout<<"OK"<<endl;
			else cout<<"NA"<<endl;
		}
	}
}

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

using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;


#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))

int dx4[4] = {1,0,-1,0}, dy4[4] = {0,1,0,-1};


int main()
{
    char c;
    cin>>c;
    if('a'<=c && c<='z')
    {
        cout<<"a"<<endl;
    }
    else
    {
        cout<<"A"<<endl;
    }
    
    
    return 0;
}

Measured memory_bytes: 3632
from collections import deque

H,W=map(int,input().split())

ch,cw =map(int,input().split())
dh,dw =map(int,input().split())

S = [list(map(str,input())) for _ in range(H)]


pathA = [(1,0),(0,1),(-1,0),(0,-1)]

pathB =[]
for n in range(5):
    for m in range(5):
        pathB.append((n-2,m-2))

visited  =[[-1]*W for _ in range(H)]

queue =deque([])
queue.append((ch-1,cw-1,0))
while queue:
    h,w,d =queue.popleft()
    if visited[h][w] ==-1:
        visited[h][w] =d
        
        for h1,w1 in pathA:
            newh = h1+h
            neww = w1+w
            if newh>=0 and newh<H and neww >=0 and neww <W and S[newh][neww]==".":
                queue.appendleft((newh,neww,d))
        
        for h1,w1 in pathB:
            newh = h1+h
            neww = w1+w
            if newh>=0 and newh<H and neww >=0 and neww <W and S[newh][neww]==".":
                queue.append((newh,neww,d+1))
                
    
print(visited[dh-1][dw-1])


Measured memory_bytes: 294572
import std.stdio, std.string, std.conv, std.range;
import std.algorithm, std.array, std.typecons, std.container;
import std.math, std.numeric, std.random, core.bitop;

enum inf = 1_001_001_001;
enum infl = 1_001_001_001_001_001_001L;
enum mod = 1_000_000_007L;

int[] dist, prev;

void main() {
    int a, b;
    scan(a, b);
    auto ans = a < 10 && b < 10 ? a * b : -1;
    writeln(ans);
}






void scan(T...)(ref T args) {
    import std.stdio : readln;
    import std.algorithm : splitter;
    import std.conv : to;
    import std.range.primitives;

    auto line = readln().splitter();
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}

void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}

bool chmin(T, U...)(ref T x, U args) {
    bool isChanged;

    foreach (arg; args) {
        if (x > arg) {
            x = arg;
            isChanged = true;
        }
    }

    return isChanged;
}

bool chmax(T, U...)(ref T x, U args) {
    bool isChanged;

    foreach (arg; args) {
        if (x < arg) {
            x = arg;
            isChanged = true;
        }
    }

    return isChanged;
}


Measured memory_bytes: 256
x,n = map(int,input().split())
lst = sorted(list(map(int,input().split())))

ans = x
if ans in lst:
    pass
else:
    print(ans)
    exit()

left,right = ans-1,ans+1

while True:
    if left in lst and right in lst:
        left -=1
        right += 1

    elif left in lst:
        print(right)
        exit()

    else:
        print(left)
        exit()







Measured memory_bytes: 9180
#define _CRT_SECURE_NO_WARNINGS

/* include ***********************/
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>

/* define *************************/
//for
#define REP(i,n) for(int i=0,i##_len=(int)(n);i<i##_len;i++)
#define REPS(i,n) for(int i=1,i##_len=(int)(n);i<=i##_len;i++)
#define RREP(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define RREPS(i,n) for(int i=(int)(n);i>0;i--)
#define FOR(i,s,n) for(int i=(int)(s),i##_len=(int)(n);i<i##_len;i++)
#define RFOR(i,s,n) for(int i=(int)(n)-1,i##_len=(int)(s);i>=i##_len;i--)

//printf
#define PRINTD(d) printf("%d\n",(d))
#define PRINTL(d) printf("%lld\n",(d))

//memset
#define m0(s) memset(s,0,sizeof(s))
#define ml(s) memset(s,63,sizeof(s))
#define fill(s,c) memset(s,c,sizeof(s))

#define INF 1e9
#define MOD 1000000007

typedef long long ll;
typedef unsigned long long ull;

int diff[4][2] = {
	{ 0, -1 },
	{ -1, 0 },
	{ 1, 0 },
	{ 0, 1 },
};
//今回の変数

int Min(int a, int b) {
	return (a)<(b) ? (a) : (b);
}
int Max(int  a, int  b) {
	return (a) > (b) ? (a) : (b);
}
ll Minl(ll a, ll b) {
	return (a)<(b) ? (a) : (b);
}
ll Maxl(ll a, ll b) {
	return (a)>(b) ? (a) : (b);
}

int main() {
	int n, l;
	scanf("%d%d", &n, &l);

	int ans = 0;
	if (l >= 0) {
		FOR(i, l, l + n) {
			ans += i;
		}
		if (l != 0)ans -= l;
	}
	else {
		FOR(i, l, l + n) {
			ans += i;
		}
		if (l + n - 1 < 0) ans -= l + n - 1;
	}
	PRINTD(ans);
}


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

int main() {
  string s;
  cin >> s;
  
  if(s.at(0)==s.at(1) && s.at(1)==s.at(2)){
    cout << "No" << endl;
  }
  else{
    cout << "Yes" << endl;
  }

}

Measured memory_bytes: 256
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <queue>
#include <string>
using namespace std;

bool equal3(int a, int  b, int c){
  return a==b && b==c;
}

int main(){
  int c[3][3];
  for(int i = 0; i < 3; i++){
    for(int j = 0; j < 3; j++){
      cin >> c[i][j];
    }
  }
  if(equal3(c[0][0]-c[0][1],c[1][0]-c[1][1],c[2][0]-c[2][1])&&
    equal3(c[0][1]-c[0][2],c[1][1]-c[1][2],c[2][1]-c[2][2])&&
    equal3(c[0][0]-c[1][0],c[0][1]-c[1][1],c[0][2]-c[1][2])&&
    equal3(c[1][0]-c[2][0],c[1][1]-c[2][1],c[1][2]-c[2][2])){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Diagnostics;

namespace AtCoder
{
    class Program
    {
        private static string Read() { return Console.ReadLine(); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }

        private static CompareInfo ci = new System.Globalization.CultureInfo("ja-JP").CompareInfo;
        private static int Compare(string a, string b) { return ci.Compare(a, b, System.Globalization.CompareOptions.Ordinal); }

        static long Solve(int N, string S)
        {
            var r = new List<int>();
            var g = new List<int>();
            var b = new HashSet<int>();
            for (int i = 0; i < N; ++i)
            {
                switch (S[i])
                {
                case 'R':
                    r.Add(i);
                    break;
                case 'G':
                    g.Add(i);
                    break;
                case 'B':
                    b.Add(i);
                    break;
                }
            }
            long cnt = 0;
            foreach (int i in r)
            {
                foreach (int j in g)
                {
                    int p = Math.Min(i, j);
                    int q = Math.Max(i, j);
                    if (b.Contains(p - (q - p))) { ++cnt; }
                    if (b.Contains(q + (q - p))) { ++cnt; }
                    if ((p + q) % 2 == 0 && b.Contains((p + q) / 2)) { ++cnt; }
                }
            }
            return Math.BigMul(r.Count, g.Count) * b.Count - cnt;
        }

        static void Main(string[] args)
        {
            int N = ReadInt();
            string S = Read();
            Console.WriteLine(Solve(N, S));
        }
    }
}


Measured memory_bytes: 27952
from math import gcd

n=int(input())
nums=list(map(int,input().split()))
g=nums[0]
g=[gcd(g,i) for i in nums[1:]]
a=set()
for i in range(1,int(g[0]**0.5)+1):
    if g[0]%i==0:
        a.add(i)
        a.add(g[0]//i)
a=[print(i) for i in sorted(list(a))]


Measured memory_bytes: 5696
/*input

*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef tree<long long, null_type, less_equal<long long>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
#pragma GCC optimize("unroll-loops,no-stack-protector")
//order_of_key #of elements less than x
// find_by_order kth element
typedef long long int ll;
#define ld double
#define pii pair<ll,ll>
#define f first
#define s second
#define pb push_back
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(int i=1;i<=n;i++)
#define FILL(n,x) memset(n,x,sizeof(n))
#define ALL(_a) _a.begin(),_a.end()
#define sz(x) (int)x.size()
const ll maxn=100005;
const ll maxlg=__lg(maxn)+2;
const ll INF64=4e18;
const int INF=0x3f3f3f3f;
const ll MOD=ll(1e9+7);
const ld PI=acos(-1);
const ld eps=1e-9;
#define lowb(x) x&(-x)
#define MNTO(x,y) x=min(x,(__typeof__(x))y)
#define MXTO(x,y) x=max(x,(__typeof__(x))y)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
ll mult(ll a,ll b){
    return (a*b)%MOD;
}
ll mypow(ll a,ll b){
    if(b<=0) return 1;
    ll res=1LL;
    while(b){
        if(b&1) res=mult(res,a);
        a=mult(a,a);
        b>>=1;
    }
    return res;
}
int main(){
    int r;
    cin>>r;
    cout<<r*r;
}

Measured memory_bytes: 256
/*** author: yuji9511 ***/
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using lpair = pair<ll, ll>;
const ll MOD = 1e9+7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i=(m);i<(n);i++)
#define rrep(i,m,n) for(ll i=(m);i>=(n);i--)
#define printa(x,n) for(ll i=0;i<n;i++){cout<<(x[i])<<" \n"[i==n-1];};
void print() {}
template <class H,class... T>
void print(H&& h, T&&... t){cout<<h<<" \n"[sizeof...(t)==0];print(forward<T>(t)...);}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll a,b;
    cin >> a >> b;
    if(a <= 9 && b <= 9){
        print(a*b);
    }else{
        print(-1);
    }
    

}

Measured memory_bytes: 256
#include<stdio.h>
n,d[20],s,x,y,*i;
main() {
 scanf("%d",&n);
 for(i=d;d+n-i;i++) scanf("%d",i);
 for(i=d;d+n-i;i++){
  scanf("%d",&x);
  if((y=*i-x)>0) s+=y;
 }
 printf("%d",s);
}

Measured memory_bytes: 128
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
      	int A = sc.nextInt();
      	int B = sc.nextInt();
     	int AB = sc.nextInt();
		int X = sc.nextInt();
      	int Y = sc.nextInt();
      	
        Long sum = (long) 0;
      	if(2*AB>=(A+B)){
          	sum = (long) (A*X+B*Y);
      		System.out.println(sum);
          	return;
        }
      
      	int min = X;
      	int max = Y;
      	int addpizza = B; 
      	
      	if(Y<X){
        	min = Y;
          	max = X;
          	addpizza = A; 
        }
      
        Long sum2 = (long) (2*AB*max);
      	sum = (long) (addpizza*(max-min)+2*(AB*min));
      	if(sum<sum2){
      		System.out.println(sum);
        }else{
          System.out.println(sum2);
        }
        return;
	}
}


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

int main() {
    int N;
    cin >> N;
    vector<int> A(N);
    for(int i=0; i<N; ++i) cin >> A[i];

    sort(A.begin(), A.end());
    A.erase(unique(A.begin(), A.end()), A.end());
    if(A.size() % 2) cout << A.size() << endl;
    else cout << A.size() - 1 << endl;
    return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <cstdio>
#include <stdio.h>
#include <cstdlib>
#include <stack>
#include <queue>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <string>
#include <cstring>
#include <set>
#include <map>
#include <climits>
#include <cassert>
using namespace std;

int n, A[1000000];
long long cnt;
vector <int> G;
void insertionsort(int A[], int n, int g) {
	for (int i = g; i < n; i++) {
		int v = A[i];
		int j = i - g;
		//&&?????????????????§?????????
		while ( j >= 0 && A[j] > v) {
			A[j+g] = A[j];
			j -= g;//?????????????????°???2?????\???????????´?????????????????????
			cnt++;
		}
		A[j + g] = v;//??????j-=g??????????????¨?????????????????§???
	}
}

void Shellsort(int A[], int n) {
	cnt = 0;
	//??°????????????????????????1????????????
	for (int h = 1; ; ) {
		if (h > n) {
			break;
		}
		G.push_back(h);
		h = 4 * h;
	}

	for (int i = G.size() - 1; i >= 0; i--) {
		insertionsort(A,n,G[i]);
	}
}

int main() {
	int n;
	cin >> n;
	for (int i = 0; i < n; i++) {
		scanf("%d", &A[i]);
	}
	cnt = 0;
	Shellsort(A, n);

	cout << G.size() << endl;

	for (int i = G.size() - 1; i>=0; i--) {
		printf("%d", G[i]);
		if (i) {
			printf(" ");
		}
	}
	printf("\n");
	printf("%d\n", cnt);
	for (int i = 0; i < n; i++) {
		printf("%d\n", A[i]);
	}
}

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

int main(){
	int n,ans=0;
  cin >> n;
  for(int i=1; i<=n; i++){
  	for(int x=1; x<=n; x++){
      if(x*x+2*x+3 > i) break;
      int xx=x*x;
    	for(int y=x; y<=n; y++){
            int xy = xx+y*(x+y);
          if(xy+x+y+1>i) break;
         for(int z=y; z<=n; z++){
           if(i == xy+z*(x+y+z)) {
           //if(i == x*x+x*y+x*z+y*y+z*z+z*y) {
             if(x == y && y == z) ans++;
             else if(x != y && y != z && z != x) ans+=6;
             else ans+=3;
             
           }
           if(i < (x+y+z)*(x+y+z)-z*y-z*x-x*y) break;
         }
        }
    }
    cout << ans << endl;
    ans=0;
  }
}


Measured memory_bytes: 3612
<?php
fscanf(STDIN, "%d", $N);
$A = array_map('intval', explode(' ', trim(fgets(STDIN))));
$cursor = 0;
$arrays = [];
for ($i = 1; $i < $N; $i++) {
    if ($A[$i - 1] > $A[$i]) {
        $arrays[] = array_slice($A, $cursor, $i - $cursor);
        $cursor = $i;
    }
    if ($i === $N - 1) {
        $arrays[] = array_slice($A, $cursor, $i - $cursor + 1);
        $cursor = $i;
    }
}
$ans = 1000;
foreach ($arrays as $array) {
    $mmax = max($array);
    $mmin = min($array);
    if ($mmax === $mmin) {
        
    } else {
        $stocks = intdiv($ans, $mmin);
        $ans += $stocks * ($mmax - $mmin);
    }
}
printf("%d", $ans);


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

typedef long long ll;

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl

const int maxn = 4e5 + 5;

int n,m;

map<ll, int> modprefix;
ll a[maxn];

int main() {
  ios_base::sync_with_stdio(false); cin.tie(0);  cout.tie(0);
  cin>>n>>m;

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

  ll ans = 0;
  ll p=0;
  modprefix[0]++;
  for (int i=0; i<n; i++) {
    p = (p + a[i])%m;
    ans += modprefix[p];
    modprefix[p]++;
  }

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


Measured memory_bytes: 4992
main = do
 s <- getLine
 print $ solve s

solve :: String -> Integer
solve = recur (0,0)

recur :: (Integer,Integer) -> String -> Integer
recur (b,w) [] = 0
recur (b,w) ('B':xs) = recur (b+1,w) xs
recur (b,w) ('W':xs) = b + recur (b,w+1) xs 

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

int main() {
  int a,b;
  cin >> a >> b;
  int m;
  for (int i=1; i<=999; i++) {
	if (b-a==i) m=i-1;
  }
  
  int sum;
  for (int i=1; i<=m; i++) {
	sum +=i;
  }
		  cout << sum-a;
}

		  

Measured memory_bytes: 256
#include <stdio.h>

int main(void) {
	int h, w;
	int i, j;
	while(1) {
		scanf("%d %d", &h, &w);
		if(h == 0 && w == 0) break;
		for(i = 1; i <= h; i++) {
			for(j = 1; j <= w; j++) {
				if(i == 1 || i == h || j == 1 || j == w) printf("#");
				else printf(".");
			}
			printf("\n");
		}
		printf("\n");
	}
	return 0;
}


Measured memory_bytes: 2028
import sys
def input(): return sys.stdin.readline().strip()

def main():
    N, M = map(int, input().split())
    S = input()

    def isOK(index):
        return S[index] == "0"
    
    ans = []
    now = N
    while now:
        for step in range(min(now, M), -1, -1):
            if step == 0:
                print(-1)
                exit()

            if isOK(now-step):
                ans.append(step)
                now -= step
                break
    print(*ans[::-1], sep=" ")



if __name__ == "__main__":
    main()

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

using namespace std;

#define pb push_back
#define ff first
#define ss second
#define sz(x) (int)x.size()
#define all(x) (x).begin(),(x).end()
#define F(i,x,n,y) for(i=x;i<n;i+=y)
#define fi(i,x,n) for(i=x;i<n;++i)
#define f(n) for(int i=0;i<n;++i)
#define fr(i,x,n) for(i=x;i>=n;--i)
#define endl '\n'

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> ii;

int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    vi v;
    int x;
    cin>>x;
    v.pb(x);
    cin>>x;
    v.pb(x);
    cin>>x;
    v.pb(x);
    sort(all(v));
    cout<<v[1]-v[0]+v[2]-v[1]<<endl;
    
    return 0;
}



Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <climits>
#include <vector>
#include <map>
#include <set>
#include <list>
#include <stack>
#include <queue>
#include <algorithm>
#include <iostream>
#include <string>

#define REP(i,n) for(int i=0;i<n;++i)
#define REPR(i,n) for(int i=n;i>=0;--i)
#define REPI(itr,v) for(auto itr=v.begin();itr!=v.end();++itr)
#define REPIR(itr,v) for(auto itr=v.rbegin();itr!=v.rend();++itr)
#define FOR(i,a,b) for(int i=a;i<b;++i)
#define SORT(v,n) sort(v, v+n)
#define SORTV(v) sort(v.begin(), v.end())
#define ALL(v) v.begin(),v.end()
#define llong long long
#define INF 999999999
#define SUR 1000000007
#define pb(a) push_back(a)
#define pf(a) push_front(a)
#define MP make_pair

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

using namespace std;

typedef pair<int,int> pii;

int main(){

  int x, y, z;
  scanf("%d %d %d", &x, &y, &z);


  int res = 1;
  while(true){
    if((res + 1) * y + (res + 2) * z > x){
      break;
    }else{
      res++;
    }
  }

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



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

int main() {
    int n, x, y;
    cin >> n >> x >> y;
    x--;
    y--;
    vector<int> adj[10000];
    rep(i, n - 1) {
        adj[i].push_back(i + 1);
        adj[i + 1].push_back(i);
    }
    adj[x].push_back(y);
    adj[y].push_back(x);

    vector<int> counter(n, 0);
    for (int start = 0; start < n; start++) {
        queue<int> q;
        q.push(start);
        vector<int> dist(n, 1e9);
        dist[start] = 1;
        while (!q.empty()) {
            int now = q.front();
            q.pop();
            for (int to : adj[now]) {
                if (dist[to] != 1e9) continue;
                if (dist[to] > dist[now] + 1) {
                    dist[to] = dist[now] + 1;
                    q.push(to);
                }
            }
        }
        for (int i = start + 1; i < n; i++) {
            counter[dist[i] - 1]++;
        }
        // cout << "start: " << start << ", counter: ";
        // for (int i = 0; i < n; i++) {
        //     cout << counter[i] << " ";
        // }
        // cout << endl;
    }
    for (int i = 1; i < n; i++) {
        cout << counter[i] << endl;
    }
}

Measured memory_bytes: 512
while True:
    h, w = map(int, input().split())
    if h == 0 and w == 0:
        exit()
    for i in range(1, h+1):
        if i % 2 != 0:
            W = ["#"]*w
            W[1::2] = ["."]*(w//2)
            print(*W, sep="")
        else:
            W = ["#"] * w
            W[::2] = ["."]*(-(-w//2))
            print(*W, sep="")
    print()


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

using namespace std;

#define rep(i, n) for(int i = 0; i < (int)n; ++i)
#define FOR(i, a, b) for(int i = a; i < (int)b; ++i)
#define rrep(i, n) for(int i = ((int)n - 1); i >= 0; --i)

typedef long long ll;
typedef long double ld;

const ll Inf = 1e18;
const double EPS = 1e-9;
const int MOD = 1e9 + 7;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(0);
    int a, b, c;
    cin >> a >> b >> c;
    bool ok = true;
    if (a == b) {
        if (a != c) ok = false;
    } else if (a == c) {
        if (a != b) ok = false;
    } else if (b == c) {
        if (b != a) ok = false;
    }
    if (!ok) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<set>
#include<string>
#include<map>
#include<string.h>
#include<complex>
#include<math.h>
#include<queue>
#include <functional>
#include<time.h>
#include <stack>
#include<iomanip>
using namespace std;
#define rep(i,a,n) for(ll i=(a);i<(n);i++)
#define ll long long
#define llint long long int
#define reverse(v)  reverse(v.begin(), v.end());
#define Yes(ans) if(ans)cout<<"Yes"<<endl; else cout<<"No"<<endl;
#define YES(ans) if(ans)cout<<"YES"<<endl; else cout<<"NO"<<endl;
#define hei(a) vector<a>
#define whei(a) vector<vector<a>>
#define UF  UnionFind 
#define Pint pair<int,int>
#define keta(a)  fixed << setprecision(a)
constexpr auto INF = 1000000000000000000;
constexpr auto mod = 1000000007;
//辞書順はnext_permutation( begin( v ), end( v ) );やで！
struct edge { int to, cost; };

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

long long modpow(long long a, long long n, long long mod) {
	long long res = 1;
	while (n > 0) {
		if (n & 1) res = res * a % mod;
		a = a * a % mod;
		n >>= 1;
	}
	return res;
}

// mod. m での a の逆元 a^{-1} を計算するよ！
long long modinv(long long a, long long m) {
	long long b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}


//aCbをmod.mで割った余りを求める
ll int c(ll int a, ll int b, ll int m) {
	ll int ans = 1;
	for (ll int i = 0; i < b; i++) {
		ans *= a - i;
		ans %= m;
	}
	for (ll int i = 1; i <= b; i++) {
		ans *= modinv(i, m);
		ans %= m;
	}
	return ans;
}
struct UnionFind {
	vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

	UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
		for (int i = 0; i < N; i++) par[i] = i;
	}
	int size(int a) {
		return par[root(a)];
	}

	int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
		if (par[x] == x) return x;
		return par[x] = root(par[x]);
	}

	void unite(int x, int y) { // xとyの木を併合
		int rx = root(x); //xの根をrx
		int ry = root(y); //yの根をry
		if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
		par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
	}

	bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
		int rx = root(x);
		int ry = root(y);
		return rx == ry;
	}
};
int main(){
	int n;
	cin >> n;
	hei(ll) a(n);
	rep(i, 0, n) {
		cin >> a[i];
		a[i] -= (i + 1);
	}
	sort(a.begin(), a.end());
	ll x = a[n / 2];
    ll ans = 0;
	rep(i, 0, n)ans += abs(x - a[i]);
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <iomanip>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <climits>
#include <cfloat>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <algorithm>
#include <functional>
#include <utility>
#include <numeric>

using namespace std;

typedef unsigned int UI;
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int,int> PII;
typedef istringstream ISS;
typedef ostringstream OSS;

#define REP( i, m, n ) for ( int i = (int)( m ); i < (int)( n ); ++i )
#define EACH( v, c ) for ( auto &v : c )

#define ITER( c ) __typeof( (c).begin() )
#define IREP( c, it ) for ( ITER(c) it = c.begin(); it != c.end(); ++it )
#define ALL( c ) (c).begin(), (c).end()

#define PB( n ) push_back( n )
#define MP( a, b ) make_pair( ( a ), ( b ) )
#define EXIST( c, e ) ( (c).find( e ) != (c).end() )

#define fst first
#define snd second

#define DUMP( x ) cerr << #x << " = " << ( x ) << endl
#define DEBUG( x ) cerr << __FILE__ << ":" << __LINE__ << ": " << #x << " = " << ( x ) << endl

typedef vector<double> VD;
typedef vector< VD > VVD;

VD solve( VVD matrix )
{
	REP( i, 0, matrix.size() )
	{
		double a = matrix[i][i];

		REP( j, 0, matrix[i].size() )
		{
			matrix[i][j] /= a;
		}

		REP( j, 0, matrix.size() )
		{
			if ( i == j )
			{
				continue;
			}

			double b = matrix[j][i];

			REP( k, 0, matrix[j].size() )
			{
				matrix[j][k] -= b * matrix[i][k];
			}
		}
	}

	VD res;

	transform( ALL( matrix ), back_inserter( res ), []( VD m ){ return m.back(); } );

	return res;
}

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

	double a, b, c, d, e, f;

	cout.precision( 3 );
	cout << fixed;

	while ( cin >> a >> b >> c >> d >> e >> f )
	{
		VVD matrix { { a, b, c }, { d, e, f } };

		auto res = solve( matrix );

		cout << res[0] << ' ' << res[1] << endl;
	}

	return 0;
}

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

/* snippet: useful macros and functions */
#define ARC(i, a, b) for(Int i = (a); i < (b); ++i)
#define RC(i, n) ARC(i, 0, n)
#define ARCH(i, a, b) for(Int i = (a) - 1; i >= (b); --i)
#define RCH(i, n) ARCH(i, n, 0)
template<class T> T ant(const T &a, const T &b){ return a > b ? a : b; }
template<class T> T ont(const T &a, const T &b){ return a < b ? a : b; }
template<class T> T rng(const T &a, const T &b){ return a < b ? b - a : a - b; }
template<class T> void th(T &a, const T &b, T (*f)(const T &, const T &)){ a = f(a, b); }
#define anth(a, b) th(a, b, ant)
#define onth(a, b) th(a, b, ont)

/* snippet: modint library */
template<class T, int MOD>
class Modint{
	T val;
public:
	Modint(T val = 0) : val(val % MOD + (val > 0 ? 0 : MOD)) {}
	operator T(){ return val; }
	Modint &operator+=(const Modint &a){ val += a.val; if(val >= MOD) val -= MOD; return *this; }
	Modint &operator-=(const Modint &a){ val -= a.val; if(val < 0) val += MOD; return *this; }
	Modint &operator*=(const Modint &a){ val = val * a.val % MOD; return *this; }
	void inverse(){T x[2]={MOD,val},a[2]={0,1};int i;for(i=0;x[!i];i^=1){a[i]-=x[i]/x[!i]*a[!i];x[i]=x[i]%x[!i];}if(!i)a[i]+= MOD;val=a[i];}
	Modint &operator/=(Modint a){ a.inverse(); return *this *= a; }
	friend Modint modpow(Modint a, int n){ Modint ret(1); while(n){ if(n & 1) ret *= a; a *= a; n >>= 1; } return ret; }
	friend Modint operator+(Modint a, const Modint &b){ return a += b; }
	friend Modint operator-(Modint a, const Modint &b){ return a -= b; }
	friend Modint operator*(Modint a, const Modint &b){ return a *= b; }
	friend Modint operator/(Modint a, const Modint &b){ return a /= b; }
	friend std::ostream &operator<<(std::ostream &os, const Modint &a){ return os << a.val; }
};

/* snippet: using declarations */
using Int = long long;
using std::cout;
using std::cin;
using std::endl;
using Mint = Modint<long long, 1000000007>;

int main(){
	int s, w;
	cin >> s >> w;
	cout << (s <= w ? "unsafe" : "safe") << endl;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
int main(){
long long H,W; cin>>H;
long long a=0;
long long b=0;
for(long long i=0;i<H;i++){
cin>>W;
if(W%2==0){
a++;}
else
b++;}
if(b%2==1){
cout<<"NO"<<endl;
}
else
cout<<"YES"<<endl;}

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

#define ll long long

// Range of evaluation of 'x'
// max value + 1 since range [l,r)
const int MAX = 1000001;    
const ll INF = (ll)(3e17);

ll eval (vector <ll> &l, ll x) {
    return x*l[0] + l[1];
}

// -inf for max value at each step
vector <vector<ll>> st(MAX<<2, {0LL, INF});

void insert(vector <ll> l, int tl = 1, int tr = MAX, int v = 1) {
    int tm = (tl + tr) >> 1;
    
    bool left_dominance = eval(l, tl) < eval(st[v], tl);
    bool mid_dominance = eval(l, tm) < eval(st[v], tm);

    if (mid_dominance)
        swap(st[v], l);
    
    if (tl == tr - 1)
        return;
    
    if (left_dominance ^ mid_dominance)
        insert(l, tl, tm, v<<1);
    else 
        insert(l, tm, tr, (v<<1)|1);
}

ll query (ll x, int tl = 1, int tr = MAX, int v = 1) {
    int tm = (tl + tr) >> 1;
    ll curr = eval(st[v], x);
    if (tl == tr - 1)
        return curr;
    if (x < tm)
        return min(curr, query(x, tl, tm, v<<1));
    else 
        return min(curr, query(x, tm, tr, (v<<1)|1));
}

ll dp[200002];
ll h[200002];

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

    for (int i=1; i<=n; i++)
        cin >> h[i];

    for (int i=2; i<=n; i++) {
        insert({-2LL*h[i-1], h[i-1]*h[i-1]+dp[i-1]});
        dp[i] = query(h[i]) + c + h[i]*h[i];
    }
    cout << dp[n] << '\n';
    return 0;
}

Measured memory_bytes: 225260
#include<iostream>
#include<string>
using namespace std;
int main()
{string s;
 cin>>s;
 if(s=="RRR")
     cout<<3;
 else if(s=="RRS")
     cout<<2;
 else if(s=="SRR")
     cout<<2;
else if(s=="SSS")
    cout<<0;
else
  cout<<1;
}

Measured memory_bytes: 3620
#include<iostream>
 
using namespace std;
 
int main()
{
  int a, b, c, ret = 0;
 
  cin >> a >> b >> c;

  for(int i = a; i <= b; i++)
    {
      if( c % i == 0 ) ret++;
    }
 
  cout << ret << endl;
 
  return 0;
}

Measured memory_bytes: 1164