akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <iostream>

using namespace std;

namespace {

class Cube {
 private:
  enum Face {
    TOP,     // 1
    FRONT,   // 2
    RIGHT,   // 3
    LEFT,    // 4
    BACK,    // 5
    BOTTOM,  // 6
  };

 public:
  Cube() = default;
  Cube(const int* face) { copy(face, face + 6, face_); }

  // to east
  void rotate_x() { rotate(TOP, LEFT, BOTTOM, RIGHT); }
  // to north
  void rotate_y() { rotate(TOP, FRONT, BOTTOM, BACK); }

  void rotate_z() { rotate(FRONT, LEFT, BACK, RIGHT); }

  bool equal_faces(const Cube& other) const {
    for (int i = 0; i < 6; ++i) {
      if (face_[i] != other.face_[i])
        return false;
    }
    return true;
  }

 private:
  void rotate(Face f1, Face f2, Face f3, Face f4) {
    const int t = face_[f1];
    face_[f1] = face_[f2];
    face_[f2] = face_[f3];
    face_[f3] = face_[f4];
    face_[f4] = t;
  }

  int face_[6];
};

// Check two dices are identical.
inline bool operator==(const Cube& a, const Cube& b) {
  Cube c = b;
  // http://www.prefield.com/algorithm/misc/dice.html
  for (int i = 0; i < 6; ++i) {
    for (int j = 0; j < 4; ++j) {
      if (a.equal_faces(c))
        return true;
      c.rotate_z();
    }
    if (i % 2 == 1)
      c.rotate_x();
    else
      c.rotate_y();
  }
  return false;
}

bool FindIdentical(const Cube* cubes, int n) {
  for (int i = 0; i < n; ++i) {
    for (int j = i + 1; j < n; ++j) {
      if (cubes[i] == cubes[j]) {
        return true;
      }
    }
  }
  return false;
}

}  // namespace

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

  int faces[100][6];
  Cube cubes[100];
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < 6; ++j)
      cin >> faces[i][j];
    cubes[i] = Cube(faces[i]);
  }

  if (FindIdentical(cubes, n))
    cout << "No" << endl;
  else
    cout << "Yes" << endl;

  return 0;
}

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

namespace C
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = RInt();
            int[] a = RArInt();

            long[] beforeI = new long[n];
            long[] afterI = new long[n];

            long gcd = 0;
            for (int i = 0; i < n; i++)
            {
                gcd = Gcd(gcd, a[i]);
                beforeI[i] = gcd;
            }

            gcd = 0;
            for (int i = n - 1; i >= 0; i--)
            {
                gcd = Gcd(gcd, a[i]);
                afterI[i] = gcd;
            }

            gcd = 0;
            for (int i = 0; i < a.Length; i++)
            {
                if (i == 0)
                {
                    gcd = Math.Max(gcd, Gcd(0, afterI[i + 1]));
                }
                else if (i == a.Length - 1)
                {
                    gcd = Math.Max(gcd, Gcd(beforeI[i - 1], 0));
                }
                else
                {
                    gcd = Math.Max(gcd, Gcd(beforeI[i - 1], afterI[i + 1]));
                }
            }
            Console.WriteLine(gcd);
        }

        /// <summary>
        ///最大公約数
        /// </summary>
        public static long Gcd(long a, long b)
        {
            if (a < b) return Gcd(b, a);  // 引数を入替えて自分を呼び出す
            if (b == 0) return a; //一方が0の場合は、もう片方の数自身がGCD

            long d = 0;
            do
            {
                d = a % b;
                a = b;
                b = d;
            } while (d != 0);
            return a;
        }

        static string RSt() { return Console.ReadLine(); }
        static int RInt() { return int.Parse(Console.ReadLine().Trim()); }
        static long RLong() { return long.Parse(Console.ReadLine().Trim()); }
        static double RDouble() { return double.Parse(Console.ReadLine()); }
        static string[] RArSt(char sep = ' ') { return Console.ReadLine().Trim().Split(sep); }
        static int[] RArInt(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Trim().Split(sep), e => int.Parse(e)); }
        static long[] RArLong(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Trim().Split(sep), e => long.Parse(e)); }
        static double[] RArDouble(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Trim().Split(sep), e => double.Parse(e)); }
        static string WAr<T>(IEnumerable<T> array, string sep = " ") { return string.Join(sep, array.Select(x => x.ToString()).ToArray()); }
    }
}


Measured memory_bytes: 26588
import heapq

n, m = map(int, input().split())
a = list(map(lambda x: -(int(x)), input().split()))
heapq.heapify(a)

for i in range(m):
    mx = heapq.heappop(a)
    heapq.heappush(a, -(-mx // 2))
    
print(sum(a) * -1)

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

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
template<class T>bool chmin(T&a,const T&b){return a>b?(a=b,1):0;}
template<class T>bool chmax(T&a,const T&b){return a<b?(a=b,1):0;}


int nextInt() { int x; scanf("%d", &x); return x;}

int D[200000 + 10];
int T[200000 + 10];

int main2() {
  int N = nextInt();
  REP(i, N) D[i] = nextInt();
  int M = nextInt();
  REP(i, M) T[i] = nextInt();
  sort(D, D+N);
  sort(T, T+M);

  int i = 0;
  int j = 0;
  for(;i < N && j < M;) {
    if (D[i] == T[j]) {
      i++;
      j++;
    } else {
      i++;
    }
  }
  cout << (j == M ? "YES":"NO") << endl;
  return 0;
}

int main() {
  for (;!cin.eof();cin>>ws) main2();
  return 0;
}



Measured memory_bytes: 1792
#include <iostream>
#include <algorithm>
using namespace std;
int main(){
long long int a,b,x,ans=0,z;
  cin >>a>>b>>x;
  if(a!=0){
ans=b/x;
z=(a-1)/x;
cout << ans-z<<endl;
}
else{
  cout << (b/x)+1<<endl;
}
}


Measured memory_bytes: 256
T=list(input())
l=len(T)
S=[]
for i in range(l-1):
  if T[i]=="P" or T[i]=="D":
    S.append(T[i])
  if T[i]=="?":
    S.append("D")
      
if T[l-1]=="P" or T[l-1]=="D":
  S.append(T[l-1])
if T[l-1]=="?":
  S.append("D")

P=''.join(S)
print(P)

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

int main(){
  int m[60], f[60], r[60], end;
  for(int i=0;i<60;i++){
    cin>>m[i]>>f[i]>>r[i];
    if(m[i]==-1 && f[i]==-1 && r[i]==-1){
      end = i;
      break;
    }
  }
  for(int i=0;i<end;i++){
    int sum = m[i] + f[i];
    if(m[i]==-1 || f[i]==-1) cout<<"F"<<endl;
    else if(sum>=80)cout<<"A"<<endl;
    else if(sum>=65)cout<<"B"<<endl;
    else if(sum>=50)cout<<"C"<<endl;
    else if(sum>=30){
      if(r[i]>=50)cout<<"C"<<endl;
      else cout<<"D"<<endl;
    }
    else cout<<"F"<<endl;
  }
  return 0;
}




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

#define ll long long
#define all(x) (x).begin(), (x).end()
const long long INF = 1LL << 60;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)  //(i, 10) i=0～i=9まで
#define repr(i, n) for (int i = n; i >= 0; i--)   // (i, 10) i=10～i=0まで
#define FOR(i, m, n) for (int i = m; i < n; i++)  // (i, 3, 10) i=3～i=9まで

// 総数を1000000007で割った余り
const long long mod = 1e9 + 7;

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

    // 入力
    int a, b, c, d;
    cin >> a >> b >> c >> d;

    // 処理
    // 出力
    cout << (a * b >= c * d ? a * b : c * d) << endl;

    return 0;
}


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

int n,q,m;
char s[N];

int main()
{
	scanf("%d",&n);
	scanf("%s",s+1);
	for (scanf("%d",&q);q;q--) {
		scanf("%d",&m);
		int l=1,r=0,sm=0,sc=0;
		long long res=0,ans=0;
		for (;r<m;r++) {
			if (s[r+1]=='C') res+=sm,sc++;
			if (s[r+1]=='M') sm++;
		}
		for (;l<=n;l++,r++) {
			if (s[l]=='D') ans+=res;
			if (s[l]=='M') res-=sc,sm--;
			if (s[l]=='C') sc--;
			if (s[r+1]=='M') sm++;
			if (s[r+1]=='C') res+=sm,sc++;
		}
		printf("%lld\n",ans);
	}
	return 0;
}

Measured memory_bytes: 1280
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main()
{
  int n,tmp;
    double ans;
  vector<int> all;
  cin>>n;
  for(int i = 0;i<n;i++)
  {
    cin>>tmp;
    all.push_back(tmp);
  }
    sort(all.begin(),all.end());
    ans=all.at(0);
    for(int i = 1;i<all.size();i++)
{
    
    ans=(ans+all.at(i))/2.0;
}
  
  
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a,b,c,d,e,k,i,j,g[5];
	cin>>a>>b>>c>>d>>e>>k;
	g[0]=a;
	g[1]=b;
	g[2]=c;
	g[3]=d;
	g[4]=e;
	for(i=0;i<5;i++)
	{
		for(j=0;j<5;j++)
		{
			if(g[i]>g[j])
			{
				if(g[i]-g[j]>k) 
				{
					cout<<":(";
					return 0;
				}
			}
			else if(g[i]<g[j])
			{
				if(g[j]-g[i]>k) 
				{
					cout<<":(";
					return 0;
				}
			}			
		}
	}
	cout<<"Yay!";
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0,i##_max=(N);i<i##_max;++i)
#define repp(i,l,r) for(int i=(l),i##_max=(r);i<i##_max;++i)
#define per(i,N) for(int i=(N)-1;i>=0;--i)
#define perr(i,l,r) for(int i=r-1,i##_min(l);i>=i##_min;--i)
#define all(arr) (arr).begin(), (arr).end()
#define SP << " " <<
#define SPF << " "
#define SPEEDUP cin.tie(0);ios::sync_with_stdio(false);
#define MAX_I INT_MAX //1e9
#define MIN_I INT_MIN //-1e9
#define MAX_UI UINT_MAX //1e9
#define MAX_LL LLONG_MAX //1e18
#define MIN_LL LLONG_MIN //-1e18
#define MAX_ULL ULLONG_MAX //1e19
  typedef long long ll;
  typedef pair<int,int> PII;
  typedef pair<char,char> PCC;
  typedef pair<ll,ll> PLL;
  typedef pair<char,int> PCI;
  typedef pair<int,char> PIC;
  typedef pair<ll,int> PLI;
  typedef pair<int,ll> PIL; 
  typedef pair<ll,char> PLC; 
  typedef pair<char,ll> PCL; 

inline void YesNo(bool b){ cout << (b?"Yes" : "No") << endl;}
inline void YESNO(bool b){ cout << (b?"YES" : "NO") << endl;}
inline void Yay(bool b){ cout << (b?"Yay!" : ":(") << endl;}

int main(void){
  SPEEDUP
  cout << setprecision(15);
  int N;cin >> N;
  vector<int> v(N);
  vector<int> w(N+2);
  rep(i,N){
    cin >> v[i];
    w[v[i]] = i+1;
  }
  set<int> stl;
  set<int> str;
  ll ans = 0;
  perr(x,1,N+1){
    auto itl = stl.upper_bound(-w[x]);
    auto itr = str.upper_bound(w[x]);
    ll l1,l2,r1,r2;
    //自分より大きい一番近く
    if(itl == stl.end()) l1 = 0;
    else l1 = *itl;
    if(itr == str.end()) r1 = N+1;
    else r1 = *itr;

    //自分より大きい二番目に近く
    if(l1==0)l2 == 0;
    else{
      stl.erase(itl);
      itl = stl.upper_bound(-w[x]);
      if(itl == stl.end()) l2 = 0;
      else l2 = *itl;
      stl.insert(l1);
    }
    if(r1==N+1)r2 = N+1;
    else{
      str.erase(itr);
      itr = str.upper_bound(w[x]);
      if(itr == str.end()) r2 = N+1;
      else r2 = *itr;
      str.insert(r1);
    }
    stl.insert(-w[x]);
    str.insert(w[x]);

    l1=-l1;
    l2=-l2;
    //ans += x*(l1-l2)*(r1-w[x]); 
    //ans += x*(r2-r1)*(w[x]-l1);
    if(l1 != 0) ans += x*(l1-l2)*(r1-w[x]);
    if(r1 != N+1) ans += x*(r2-r1)*(w[x]-l1);
    //cout << x SP -l2 SP -l1 SP r1 SP r2 SP ans << endl;
  }
  cout << ans << endl;
  return 0;
}


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

int main() {
  string s;
  cin >> s;

  rep(i,0,s.size()) {
    if (i%2 == 0) {cout << s[i];}
  }
  cout << endl;
}


Measured memory_bytes: 512
import java.util.Arrays;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int a = scan.nextInt();
        int b = scan.nextInt();

        if (a % 3 == 0 || b % 3 == 0 || (a + b) % 3 == 0) {
            System.out.println("Possible");
            return;
        }
        System.out.println("Impossible");
    }
}

Measured memory_bytes: 21844
input_str = input()

while(True):
  if input_str[0:11] == "dreameraser":
    input_str = input_str[11:]
  elif input_str[0:10] == "dreamerase":
    input_str = input_str[10:]
  elif input_str[0:7] == "dreamer":
    input_str = input_str[7:]
  elif input_str[0:6] == "eraser":
    input_str = input_str[6:]
  elif input_str[0:5] == "dream" or input_str[0:5] == "erase":
    input_str = input_str[5:]
  else:
    print("NO")
    break
  
  if len(input_str) == 0:
    print("YES")
    break

Measured memory_bytes: 9220
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,N) for(int i = 0;i < (int)(N);i++)
int main(){
int n,m;
  cin>>n>>m;
 int ans=n*(n-1)/2+m*(m-1)/2;
  cout<<ans<<endl;}


Measured memory_bytes: 256
#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;
const int MX= 1000005;

int main(){
  int n,k;
  cin>>n>>k;
  int sum=0;
  rep(i,k){
    int u;
    cin>>u;
    sum+=u;
    }
  if(n>=sum){
    cout<<n-sum<<endl;
  }
  else{
    cout<<-1<<endl;
  }
}

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

using namespace std;

int main()
{
    char ch;
    scanf("%c",&ch);
    if(ch=='A')putchar('T');
    else if(ch=='T')putchar('A');
    else if(ch=='C')putchar('G');
    else putchar('C');
    return 0;
}


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

int main() {
	// your code goes here
	int n;
	cin >> n;
	vector<int> v(n);
	for(int i=0;i<n;i++)cin >> v[i];
	int temp=0;
	int min=v[n-1];
	for(int i=n-1;i>=0;i--){
		if(v[i]<=min)
		  min=v[i];
		else{
		    if(v[i]-min>1){
		     temp=1;
		     break;
		    }
		}
		
	}
	if(temp==1)cout<<"No";
	else cout <<"Yes";
	return 0;
}

Measured memory_bytes: 640
def main():
    N = int(input())
    A = list(map(int, input().split()))
    x = 1
    for a in A:
        if a == x:
            x += 1
    if x > 1:
        print(N - x + 1)
    else:
        print(-1)


if __name__ == "__main__":
    main()

Measured memory_bytes: 26140
using System;
using System.Linq;
using System.IO;
using System.Text;
using System.Collections;
using System.Collections.Generic;
 
class Program{
    static void Main(){
        var ans = new List<int>();
        string[] inputs;
        while(true)
        {
            string input = Console.ReadLine();
            if(string.IsNullOrEmpty(input)) break;
            inputs = input.Split(' ');
            ans.Add(DigitNumber(int.Parse(inputs[0]) + int.Parse(inputs[1])));
        }

        foreach (int val in ans)
        {
            Console.WriteLine(val);
        }
    }

    static bool IsNullOrEmpty(Array array){
        return array == null || array.Length == 0;
    }

    static int DigitNumber(int num){
        int cnt = 0;
        do
        {
            num /= 10;
            cnt++;
        } while (num > 0);
        return cnt;
    }
}

Measured memory_bytes: 9048
N, M = map(int, input().split())
MOD = 10**9 + 7

def primeFact(N):
    R = int(N**(0.5)) + 1  # 素数の範囲
    factor = {}  # 素数のリスト
    n = N
    for num in range(2, R):
        factor[num] = 0
        while n % num == 0:
            n //= num
            factor[num] += 1
    if n > 1 :
        factor[n] = 1
    return factor

def dictFilter (filter, dic) :
    return { key : val for key, val in dic.items() if filter(key, val)}

primeCount = dictFilter(lambda key, val : val > 0, primeFact(M))

def comb(n, k) :
    p = 1
    div = 1
    for i in range(k) :
        p *= (n - i)
        div *= (i + 1)
    return p // div

ans = 1
for _, count in primeCount.items() :
    ans *= comb(count + N - 1, count) % MOD

print(ans % MOD)

Measured memory_bytes: 6132
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int main(void){
    int x, y;
    cin >> x >> y;
    int b = y/2-x;
    int a = x-b;
    if(a>=0&&b>=0&&a+b == x && a*2+b*4==y){
        puts("Yes");
    }else{
        puts("No");
    }
}


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

#define REP(i,x,y) for(int i=(x);i<(y);i++)
#define RREP(i,x,y) for(int i=(y)-1;i>=(x);i--)
#define all(x) (x).begin(),(x).end()
// #define int long long

using namespace std;

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

#ifdef LOCAL
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#define dump(x)  cerr << #x << " = " << (x) << endl
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl
#else
#define eprintf(...) 42
#define dump(x) 42
#define debug(x) 42
#endif

typedef long long ll;

const ll MOD = 1e9 + 7;

void solve(int W, int H, int x, int y) {
    double area = (double) W * (double) H / 2.0;
    int isMid = (x * 2 == W && y * 2 == H) ? 1 : 0;

	stringstream ss;
	ss << area << " " << isMid;

	cout << ss.str() << '\n';

    return;
}

signed main() {
    int W, H, x, y;
    cin >> W >> H >> x >> y;

//    vector<int> A(N);
//    REP(i,0,N) cin >> A[i];
    
    solve(W, H, x, y);
    
    return 0;
}



Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            ABC084_B();
        }

        static void ABC084_B()
        {
            var AB = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
            var S = Console.ReadLine().Select(x => x.ToString()).ToArray();
            var A = AB[0];
            var B = AB[1];
            var ok = true;
            if (S[A] == "-")
            {
                for (int i = 0; i < S.Length; i++)
                {
                    if (i != A && !IsDigit(S[i].ToString()) || (i != A && (0 > int.Parse(S[i]) || int.Parse(S[i]) > 9)))
                        ok = false;
                }
            }
            else
            {
                ok = false;
            }
            Console.WriteLine(ok ? "Yes" : "No");
        }

        public static IEnumerable<int> Range(int start, int stop)
        {
            if (start < 0 || stop < 0)
                throw new Exception("0??");

            if (start > stop || (start == 0 && stop == 0))
                return new List<int>();

            return Enumerable.Range(start, stop - start);
        }

        public static bool IsDigit(string str)
        {
            var i = 0;
            return int.TryParse(str, out i);
        }

        public static int DigitsSum(long num)
        {
            return num.ToString().Select(x => x.ToString()).Sum(int.Parse);
        }
    }

    public static class MyExtensions
    {
        public static string Slice(this string str, int start = 0, int stop = 0)
        {
            if (start > str.Length || stop > str.Length || start < 0 || stop < 0)
                return "";

            if (stop == 0) stop = str.Length;
            return str.Substring(start, stop - start);
        }
    }
}

Measured memory_bytes: 13396
#include <iostream>
#include <array>
#include <vector>
#include <iomanip>
#include <string>
#include <cmath>
#include <algorithm>
#include <queue>
#include <map>
#include <set>

using namespace std;

typedef  pair<int,int> P;
typedef long long LL;
typedef vector<LL> VEC;


const LL INF=1<<30;
const LL MOD=1000000007;

LL gcd(LL a,LL b){
    if(b==0)return a;

    return gcd(b,a%b);
}
LL lcm(LL a,LL b){
    LL g=gcd(a,b);
    return a/g*b;
}

LL kaijo(LL n){
    LL ans=1;
    for(LL i=1;i<=n;++i){
        (ans*=i)%=MOD;
    }
    return ans;
}


int main(){
    int n;
    cin>>n;
    LL LCM=1;
    LL t;
    for(int i=0;i<n;++i){
        cin>>t;
        LCM=lcm(t,LCM);
    }
    cout<<LCM<<endl;

}

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

// lib/detail/ceil_and_floor.hpp
#ifndef DETAIL_CEIL_AND_FLOOR_HPP
#define DETAIL_CEIL_AND_FLOOR_HPP

namespace tools {
  template <typename T>
  constexpr T floor(T lhs, T rhs);

  template <typename T>
  constexpr T ceil(T lhs, T rhs);

  template <typename T>
  constexpr T floor(const T lhs, const T rhs) {
    return
      lhs >= 0 && rhs >= 0 ?
        lhs / rhs :
      lhs < 0 && rhs >= 0 ?
        -ceil<T>(-lhs, rhs) :
      lhs >= 0 && rhs < 0 ?
        -ceil<T>(lhs, -rhs) :
        floor<T>(-lhs, -rhs);
  }

  template <typename T>
  constexpr T ceil(const T lhs, const T rhs) {
    return
      lhs >= 0 && rhs >= 0 ?
        (lhs - 1 + rhs) / rhs :
      lhs < 0 && rhs >= 0 ?
        -floor<T>(-lhs, rhs) :
      lhs >= 0 && rhs < 0 ?
        -floor<T>(lhs, -rhs) :
        ceil<T>(-lhs, -rhs);
  }
}

#endif

// lib/ceil.hpp
#ifndef CEIL_HPP
#define CEIL_HPP


/*
usage:

tools::ceil(5, 3) // => 2 (i.e., ceil(5 / 3))
*/

#endif

// main.cpp

int main() {
  std::int_fast64_t n, h;
  std::cin >> n >> h;
  std::vector<std::int_fast64_t> a, b;
  a.reserve(n);
  b.reserve(n);
  for (std::int_fast64_t i = 0; i < n; ++i) {
    std::int_fast64_t a_i, b_i;
    std::cin >> a_i >> b_i;
    a.push_back(a_i);
    b.push_back(b_i);
  }

  std::int_fast64_t common_damage = *std::max_element(a.begin(), a.end());
  std::sort(b.begin(), b.end(), std::greater<std::int_fast64_t>());
  std::int_fast64_t answer = 0;
  for (const std::int_fast64_t& b_i : b) {
    if (b_i <= common_damage) break;
    if (h <= 0) break;
    ++answer;
    h -= b_i;
  }
  if (h > 0) {
    answer += tools::ceil(h, common_damage);
  }

  std::cout << answer << std::endl;
  return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define mp make_pair
#define si(x) int(x.size())
const int mod=1000000007,MAX=500005,INF=1<<30,D=700;
int N,Q;
int A[MAX],cnt[MAX],ans[MAX];
int sum=0,l=-1,r=-1;

struct dat{
    int l;
    int r;
    int id;
};

vector<dat> S;

int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    cin>>N>>Q;
    
    for(int i=0;i<N;i++) cin>>A[i];
    
    S.resize(Q);
    for(int i=0;i<Q;i++){
        cin>>S[i].l>>S[i].r;
        S[i].id=i;
        S[i].l--;S[i].r--;
    }
    
    sort(all(S),[](auto a,auto b){
        if(a.l/D==b.l/D) return a.r<b.r;
        return a.l/D<b.l/D;
    });
    
    for(int i=0;i<Q;i++){
        while(S[i].r<r){
            cnt[A[r]]--;
            if(cnt[A[r]]==0) sum--;
            r--;
        }
        while(S[i].r>r){
            cnt[A[r+1]]++;
            if(cnt[A[r+1]]==1) sum++;
            r++;
        }
        
        while(S[i].l<l){
            cnt[A[l-1]]++;
            if(cnt[A[l-1]]==1) sum++;
            l--;
        }
        while(S[i].l>l){
            cnt[A[l]]--;
            if(cnt[A[l]]==0) sum--;
            l++;
        }
        
        ans[S[i].id]=sum;
    }
    
    for(int i=0;i<Q;i++) cout<<ans[i]<<"\n";
}


Measured memory_bytes: 15508
#include <bits/stdc++.h>
using namespace std;
  #define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  #define int long long
  #define endl "\n"
  #define all(v) v.begin(),v.end()
  #define double long double
  #define trace1(x)                cerr<<#x<<": "<<x<<endl
  #define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
  #define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
  #define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
  #define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<< ": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
  #define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
  #define cases int testcases;cin>>testcases; while(testcases--)
  const int N = 200005;


int32_t main()
{


    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    IOS



    int a,b,c;
    cin >> a >> b >> c;
    
    int ans = 0;

    while(a%2 == 0 and b%2 == 0 and c%2 == 0)
    {
       if(a%2 or b%2 or c%2)break;

      int x = a, y = b, z = c;
      a = (y+z)/2;
      b = (x+z)/2;
      c = (x+y)/2;
       ans++;

        if(a == b and b == c)
        {
          cout << -1;
          return 0;
        }

      if(a%2 or b%2 or c%2)break;
    }


    cout << ans;


    return 0; 
}


Measured memory_bytes: 3612
#include<bits/stdc++.h>
#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long
#define vi vector<ll>
#define vvi vector<vi>
#define BITLE(n) (1LL<<((ll)n))
#define SHIFT_LEFT(n) (1LL<<((ll)n))
#define SUBS(s,f,t) ((s).substr((f),(t)-(f)))
#define ALL(a) (a).begin(),(a).end()
using namespace std;
ll lis(vi A){
  ll n = A.size();
  vi dp(n,llINF);
  for(int i=0;i<n;i++){
    *upper_bound(ALL(dp),A[i]) = A[i];
  }
  return (lower_bound(ALL(dp),llINF)-dp.begin());
}
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n;cin>>n;
  vi A(n);
  for(auto &a:A)cin>>a;
  reverse(ALL(A));
  cout<<lis(A)<<endl;
  return 0;
}


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

typedef long long ll;

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

    string s,t;
    cin >> s >> t;
    string copy = s;
    int ssize = s.size();
    int tsize = t.size();
    string ans = "zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz";
    if(ssize < tsize){
        cout << "UNRESTORABLE" << endl;
        return 0;
    }
    for(int i=0;i<ssize-tsize+1;i++){
        int cnt = 0;
        s = copy;
        for(int j=0;j<tsize;j++){
            if(s[i+j]==t[j]||s[i+j]=='?') cnt++;
            else break;
        }
        if(cnt==tsize){
            int l = 0;
            for(int k=i;k<i+tsize;k++){
                s[k] = t[l++];
            }
            for(int m=0;m<ssize;m++){
                if(s[m]=='?') s[m] = 'a';
            }
            ans = min(ans,s);
        }
    }
    if(ans=="zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz") cout << "UNRESTORABLE" << endl;
    else cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
program not_k_perm_counting
  implicit none
  integer(8), parameter :: md = 924844033_8
  integer :: n, k, i, j, l, m, p
  integer(8) :: ans = 0_8, t = 1_8
  integer(8), dimension(0:4000) :: f = 0_8, a = 0_8
  integer(8), dimension(0:4000,0:1) :: g = 0_8
  read(*,*) n, k
  f(0) = 1_8
  do i = 1, n
    f(i) = mod(f(i-1)*int(i,8),md)
  end do
  g(0,0) = 1_8
  do i = 1, k
    m = (n-i)/k
    do p = 1, 2
      do j = 1, m
        do l = n, 1, -1
          g(l,0) = mod(g(l,0)+g(l,1),md)
          g(l,1) = g(l-1,0)
        end do
        g(0,0) = mod(g(0,0)+g(0,1),md)
      end do
      do j = 0, n
        g(j,0) = mod(g(j,0)+g(j,1),md)
        g(j,1) = 0_8
      end do
    end do
  end do
  do i = 0, n
    ans = modulo(ans+t*mod(g(i,0)*f(n-i),md),md)
    t = -t
  end do
  write(*,'(i0)') ans
end program not_k_perm_counting

Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        B solver = new B();
        solver.solve(1, in, out);
        out.close();
    }

    static class B {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            // 入力
            int n = Integer.parseInt(in.next());
            int k = Integer.parseInt(in.next());
            int ans = 0;
            int d[] = new int[k];
            int a[][] = new int[k][100];
            int b[][] = new int[100][1];
            for (int i = 0; i < k; i++) {
                d[i] = Integer.parseInt(in.next());
                for (int j = 0; j < d[i]; j++) {
                    a[i][j] = Integer.parseInt(in.next());
                    b[a[i][j] - 1][0]++;
                }
            }

            for (int i = 0; i < n; i++) {
                if (b[i][0] == 0) ans++;
            }
            // 出力
            out.println(ans);

        }

    }
}



Measured memory_bytes: 41128
#include "bits/stdc++.h"
using namespace std;
#define REP(i,a) for(int i = 0; i < (a);i++)
#define ALL(a) (a).begin(),(a).end()
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;
const int MOD = 1e9 + 7;
using Graph = vector < vector<int>>;
long int sum[200020] = {};
/*第二引数で第一引数を割ったときの切り上げの計算*/
long long int maxtime(long long int x,long long int y) {
	return(x + y-1) / y;

}
/*最大公約数*/
long long int lcm(long long int number1, long long int number2) {
	long long int m = number1;
	long long int n = number2;

	if (number2 > number1) {
		m = number2;
		n = number1;
	}
	long long int s = -1;
	while (s != 0) {
		s = m % n;
		m = n;
		n = s;
	}
	return m;
}
/*最大公倍数*/
long long int gcd(long long int number1, long long int number2) {
	long long int m = number1;
	long long int n = number2;
	return m / lcm(m, n) * n;
}

int main() {
	int n, k;
	cin >> n >> k;
	string N;
	cin >> N;
	vector<int> L;
	vector<int> R;
	int sum = 0;
	char C = ' ';
	int l = 0;
	int r = 0;
	int b = 0;
	if (N[0] == 'R') {
		b = 1;
	}
	for (int i = 0; i < N.size(); i++) {
		if (i == 0) {
			C = N[i];
			sum = sum + 1;
			continue;
		}

		if (N[i] == C) {
			sum = sum + 1;
			if (i == n - 1) {
				if (C == 'L') {
					L.push_back(sum);
					l = l + 1;
				}
				else {
					R.push_back(sum);
					r = r + 1;
				}
			}
		}
		else {
			if (C == 'L') {
				L.push_back(sum);
				C = 'R';
				sum = 1;
				l = l + 1;
				if (i == n - 1) {
					if (C == 'L') {
						L.push_back(sum);
						l = l + 1;
					}
					else {
						R.push_back(sum);
						r = r + 1;
					}
				}
			}
			else {
				R.push_back(sum);
				C = 'L';
				sum = 1;
				r = r + 1; 
				if (i == n - 1) {
					if (C == 'L') {
						L.push_back(sum);
						l = l + 1;
					}
					else {
						R.push_back(sum);
						r = r + 1;
					}
				}
			}
		}
	}
	sum = 0;
	for (int i = 0; i < r; i++) {
			sum = sum + R[i] - 1;
	}
	for (int i = 0; i < l; i++) {
			sum = sum + L[i] - 1;
	}

	if (min(l, r) <= k) {
		sum = N.size() - 1;
	}
	else {
		sum = sum + k + k;
	}
	cout << sum;
}

Measured memory_bytes: 1020
#include<stdio.h>
int main(void){
int d,t,s;
  scanf("%d%d%d",&d,&t,&s);
  if(d%s==0){
    if(d/s>t)printf("No");
    else printf("Yes");
  }
  else{
    if(d/s+1>t)printf("No");
    else printf("Yes");
  }
  return 0;
}

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

using namespace std;

using ll = long long;

const double eps = 1e-10;
const int MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1ll<<50;

template<typename T>
void printv(const vector<T>& s) {
  for(int i=0;i<(int)(s.size());++i) {
    cout << s[i];
    if(i == (int)(s.size())-1) cout << endl;
    else cout << " ";
  }
}

int main () {
  cin.tie(0);
  cout << fixed << setprecision(10);

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

  int mi = INF;
  for(int i=0;i<120;++i) {
    //printv(a);
    int now = 0;
    for(int j=0;j<5;++j) {
      now += (10 - now % 10) % 10;
      now += a[j];
    }
    //cout << now << endl;
    mi = min(mi, now);
    next_permutation(a.begin(), a.end());
  }
  cout << mi << endl;
}


Measured memory_bytes: 256
from math import ceil

while True:
    h, w = map(int, input().split())
    if h == w == 0:
        break

    ha, wa = 150, 150
    dia = h**2 + w**2
    for hi in range(1, 150):
        wi = ceil((dia - hi ** 2) ** (1 / 2))

        if hi >= wi:
            break

        if dia == hi**2 + wi**2:
            if hi <= h:
                wi += 1

        if ha**2 + wa**2 > hi**2 + wi**2:
            ha, wa = hi, wi

    print(ha, wa)


Measured memory_bytes: 5712
#include<bits/stdc++.h> 
using namespace std; 
// Binary indexed tree supporting binary search.
 
 
#define x first
#define y second

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

typedef pair<int, int> pii;
//#define forn(i, a,b) for (int i = (int) a; i <= (int) b; ++i)
const int MAXN = 101;
long long dp1[2019];
long long dp[2019];
int modu(int a){
	return ((a%2019) + 2019)%2019;
}
int main(){
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    
   string s;
   cin>>s;
   int n = s.size();
   //cout<<s<<" "<<n<<endl;
   dp[s[0] - '0']++;
   long long suma = 0;
   forn(i,n-1){
   	//cout<<i<<endl;
   	forn(j,2019){
   	 	dp1[j]=0;
	 }
   	 forn(j,2019){
   	 	dp1[modu((10*j)+(s[i+1]-'0'))]+=dp[j];
	 }
	 dp1[s[i+1]-'0']++;
	 forn(j,2019){
   	 	dp[j]=dp1[j];
	 }
	 suma+=dp[0];
   }
   
   cout<<suma<<endl;
	

	return 0;	
}

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

using pii = pair<int, int>;

int main() {
    string s;
    while(cin >> s) {
        vector<string> v(8);
        v[0] = s;
        for(int i = 0; i < 7; ++i) {
            cin >> v[i + 1];
        }
        vector<vector<pii>> m = {{pii{0, 0}, pii{0, 1}, pii{1, 0}, pii{1, 1}},
                                 {pii{0, 0}, pii{1, 0}, pii{2, 0}, pii{3, 0}},
                                 {pii{0, 0}, pii{0, 1}, pii{0, 2}, pii{0, 3}},
                                 {pii{0, 0}, pii{1, -1}, pii{1, 0}, pii{2, -1}},
                                 {pii{0, 0}, pii{0, 1}, pii{1, 1}, pii{1, 2}},
                                 {pii{0, 0}, pii{1, 0}, pii{1, 1}, pii{2, 1}},
                                 {pii{0, 0}, pii{0, 1}, pii{1, -1}, pii{1, 0}}};
        vector<pii> b;
        for(int i = 0; i < 8; ++i) {
            for(int j = 0; j < 8; ++j) {
                if(v[i][j] == '1') b.emplace_back(i, j);
            }
        }
        sort(begin(b), end(b));
        for(int i = 3; i >= 0; --i) {
            b[i].first -= b[0].first;
            b[i].second -= b[0].second;
        }

        char ans = 'A' + find(begin(m), end(m), b) - begin(m);
        cout << ans << endl;
    }
}


Measured memory_bytes: 3092
#include <stdio.h>

int main() {
    int HOUR = 60 * 60;
    int MINUTE = 60;

    int s, hour, minute, second;;
    scanf("%d", &s);

    hour = s / HOUR;
    s -= hour * HOUR;
    minute = s / MINUTE;
    s -= minute * MINUTE;
    second = s;

    printf("%d:%d:%d\n", hour, minute, second);

    return 0;
}


Measured memory_bytes: 2144
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define MAX 300003
#define MOD 1000000007
#define INF 1000000000000000000

int N,M,Q;
vector<int> a,b,c;
vector<ll> d;

void dfs(vector<int> &A,ll &ans){
  if(A.size()==N){
    ll tmp=0;
    for(int i=0;i<Q;i++){
      if(A[b[i]]-A[a[i]]==c[i]){
        tmp+=d[i];
      }
    }
    ans=max<ll>(ans,tmp);
    return ;
  }
  if(A.size()==0){
    for(int i=1;i<=M;i++){
      A.push_back(i);
      dfs(A,ans);
      A.pop_back();
    }
  }else{
    int ba=A.back();
    for(int i=ba;i<=M;i++){
      A.push_back(i);
      dfs(A,ans);
      A.pop_back();
    }
  }
}

int main(){
  cin>>N>>M>>Q;
  a.resize(Q);
  b.resize(Q);
  c.resize(Q);
  d.resize(Q);
  for(int i=0;i<Q;i++){
    cin>>a[i]>>b[i]>>c[i]>>d[i];
    a[i]--;
    b[i]--;
  }
  ll ans=0;
  vector<int> A;
  dfs(A,ans);
  cout<<ans<<endl;

}


Measured memory_bytes: 3632
#include<vector>
#include<unordered_map>
#include<algorithm>
template<typename T> class Compression {
 public:
  Compression(const std::vector<T>& list) : value_(list) {
    std::sort(begin(value_), end(value_));
    value_.erase(std::unique(begin(value_), end(value_)), end(value_));
    for(int i = 0; i < value_.size(); ++i) index_[value_[i]] = i;
  }
  int size() const {return value_.size();}
  int index(const T& v) const {return index_.at(v);}
  int operator[](const int i) const {return value_.at(i);}
 private:
  std::unordered_map<T, int> index_;
  std::vector<T> value_;
};

#include<vector>
using Size = int;
template<typename T> class SegmentTree {
 public:
  SegmentTree(Size N) : N(size(N)), node_(2 * size(N) - 1) {}
  void add(Size i, T v) {
    i += N - 1;
    node_[i] += v;
    while(i != parent(i)) {
      i = parent(i);
      node_[i] = node_[lchild(i)] + node_[rchild(i)];
    }
  }
  T sum(Size a, Size b) const {return sum(a, b, 0, 0, N);}
 private:
  constexpr Size pop_lsb(Size N) const {return N & (N - 1);}
  constexpr Size msb(Size N) const {while(pop_lsb(N)) N = pop_lsb(N); return N;}
  constexpr Size size(Size N) const {return pop_lsb(N) ? msb(N) << 1 : N;}
  inline Size parent(Size n) const {return (n - 1) / 2;}
  inline Size lchild(Size n) const {return 2 * n + 1;}
  inline Size rchild(Size n) const {return 2 * n + 2;}
  T sum(Size a, Size b, Size k, Size l, Size r) const {
    if(b <= l || r <= a) return 0;
    if(a <= l && r <= b) return node_[k];
    auto m = (l + r) / 2;
    return sum(a, b, lchild(k), l, m) + sum(a, b, rchild(k), m, r);
  }
  const Size N;
  std::vector<T> node_;
};

#include<bits/stdc++.h>
using namespace std;

int main() {
  using LL = long long;
  struct Query {LL n, a, b;};
  LL D = 1e9 + 1;

  int N;
  cin >> N;

  vector<Query> Q(N);
  for(auto& q: Q) {
    cin >> q.n;
    if(q.n == 1) cin >> q.a >> q.b;
  }

  vector<LL> p = {0, LL(1e9+D)};
  for(auto& q: Q) q.a += D;
  for(const auto& q: Q) if(q.n == 1) p.emplace_back(q.a);
  Compression<LL> comp(p);

  SegmentTree<LL> sum(comp.size()+1), num(comp.size()+1);
  auto f = [&](auto i) {
    auto x = comp[i];
    return x*num.sum(0, i)-sum.sum(0, i) + sum.sum(i+1, comp.size())-x*num.sum(i+1, comp.size());
  };
  LL c = 0;
  for(const auto& q: Q) {
    if(q.n == 1) {
      c += q.b;
      sum.add(comp.index(q.a), abs(q.a));
      num.add(comp.index(q.a), 1);
    } else {
      LL l = 0, h = comp.size()-1;
      while(1 < h-l) {
        LL m = (l+h)/2;
        if(f(m)-f(m-1) < 0) l = m;
        else                h = m;
      }
      if(f(l) > f(h)) l = h;
      cout << comp[l]-D << " " << f(l)+c << endl;
    }
  }
}


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

using ll = long long;
using ld = long double;
using vi = vector<int>;
using vll = vector<ll>;

const int INF = 1e9;
const ll INFLL = 1e18;
const int MOD = 1e9 + 7;
const int NIL = -1;

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

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

#define DEBUG

int main()
{
	ios::sync_with_stdio(false); cin.tie(0);
	int n;
	cin >> n;
	cout << "ABC" << n << endl;
	return 0;
}

Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()


int main() {
  int n, x;
  cin >> n >> x;
  vector<int> a(n);
  ll sum = 0;
  rep(i, n) {
    cin >> a[i];;
    sum += a[i];
  }
  sort(all(a));
  
  ll i = 0, cnt = 0;
  while (i < n) {
    cnt += a[i];
    if (cnt > x) {
      break;
    }
    i++;
  }
  
  if (x > sum) {
    i--;
  }
  cout << i << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define next Next
#define gc getchar
#define int long long
int n,A,B;
/*char buf[1<<21],*p1=buf,*p2=buf;
inline int gc(){return p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++;}*/
inline int read()
{
    int ret=0,f=0;char c=gc();
    while(!isdigit(c)){if(c=='-')f=1;c=gc();}
    while(isdigit(c)){ret=ret*10+c-48;c=gc();}
    if(f)return -ret;return ret;
}
signed main()
{
	n=read();A=read();B=read();
	int ans=1e19;
	if(A>B)swap(A,B);
	if((B-A)%2==0)ans=min(ans,(B-A)/2);
	else{
		int x=B-A;
		if((x-1)%2==0)ans=min(ans,(x-1)/2+A);
		x=A+n-B+1;
		if((n-x)%2==0)ans=min(ans,(n-x)/2+n-B+1);
	}
	cout<<ans;
}

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

using namespace std;
using namespace __gnu_cxx;

#define REP(i,n) for( (i)=0 ; (i)<(n) ; (i)++ )
#define rep(i,x,n) for( (i)=(x) ; (i)<(n) ; (i)++ )
#define REV(i,n) for( (i)=(n) ; (i)>=0 ; (i)-- )
#define FORIT(it,x) for( (it)=(x).begin() ; (it)!=(x).end() ; (it)++ )
#define foreach(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();++it)
#define rforeach(it,c) for(__typeof((c).rbegin()) it=(c).rbegin();it!=(c).rend();++it)
#define foreach2d(i, j, v) foreach(i,v) foreach(j,*i)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define SZ(x) ((int)(x).size())
#define MMS(x,n) memset(x,n,sizeof(x))
#define mms(x,n,s) memset(x,n,sizeof(x)*s)
#define pb push_back
#define mp make_pair
#define NX next_permutation
#define UN(x) sort(all(x)),x.erase(unique(all(x)),x.end())
#define CV(x,n) count(all(x),(n))
#define FIND(x,n) find(all(x),(n))-(x).begin()
#define ACC(x) accumulate(all(x),0)
#define PPC(x) __builtin_popcountll(x)
#define LZ(x) __builtin_clz(x)
#define TZ(x) __builtin_ctz(x)
#define mxe(x) *max_element(all(x))
#define mne(x) *min_element(all(x))
#define low(x,i) lower_bound(all(x),i)
#define upp(x,i) upper_bound(all(x),i)
#define NXPOW2(x) (1ll << ((int)log2(x)+1))
#define PR(x) cout << #x << " = " << (x) << endl ;

typedef unsigned long long ull;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
typedef pair<int, int> pii;

const int OO = (int) 2e9;
const double eps = 1e-9;

int cnt[26];

string s;

int main() {
	std::ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
#ifndef ONLINE_JUDGE
//	freopen("in.txt", "rt", stdin);
//	freopen("out.txt", "wt", stdout);
#endif
	cin >> s;
	int n = SZ(s);
	for (int i = 0; i < n; i++) {
		cnt[s[i] - 'a']++;
	}
	ll res = n * (n - 1LL) / 2 + 1LL;
	for (int i = 0; i < 26; i++) {
		res -= cnt[i] * (cnt[i] - 1LL) / 2;
	}
	cout << res << endl;
	return 0;
}


Measured memory_bytes: 720
#define _USE_MATH_DEFINES
#include<iostream>
#include<algorithm>
#include<string>
#include<iomanip>
#include<cmath>
#include<vector>
#include<deque>
#include<queue>
#include<map>
#include<set>
#define ll long long
#define str string
#define ld long double
#define vec vector
#define vll vec<ll>
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define rrep(i,b,a) for(ll i=b;i>=a;i--)
#define ALL(a) a.begin(),a.end()
#define rALL(a) a.rbegin(),a.rend()
#define kai "\n"
#define yuque priority_queue
#define ryuque(t) priority_queue<t,vec<t>,greater<t>>
#define pub push_back
#define pob pop_back
#define puf push_front
#define pof pop_front
#define mie min_element
#define mae max_element
#define tos to_string
#define sep setprecision
#define MOD 1000000007ll
using namespace std;
void solve();
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed;
	solve();
}

//nCk(mod p)
const ll NUM = 2;
ll fac[NUM], finv[NUM], inv[NUM];
void cmodf(ll p = MOD) {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	rep(i, 2, NUM) {
		fac[i] = fac[i - 1] * i%p;
		inv[i] = p - inv[p%i] * (p / i) % p;
		finv[i] = finv[i - 1] * inv[i] % p;
	}
}
ll cmod(ll n, ll k, ll p = MOD) {
	return fac[n] * (finv[k] * finv[n - k] % p) % p;
}

//最大公約数
ll gcd(ll n, ll m) {
	ll k = n % m;
	while (k != 0) { n = m; m = k; k = n % m; }
	return m;
}
ll gcd(vector<ll> a) {
	rep(i, 1, a.size()) {
		ll k = a[i - 1] % a[i];
		while (k != 0) {
			a[i - 1] = a[i];
			a[i] = k;
			k = a[i - 1] % a[i];
		}
	}
	return a.back();
}

//最小公倍数
ll lcm(ll n, ll m) {
	ll t = n * m, k = n % m;
	while (k != 0) { n = m; m = k; k = n % m; }
	return t / m;
}
ll lcm(vector<ll> a) {
	ll n;
	rep(i, 1, a.size()) {
		n = a[i - 1] * a[i];
		ll k = a[i - 1] % a[i];
		while (k != 0) {
			a[i - 1] = a[i];
			a[i] = k;
			k = a[i - 1] % a[i];
		}
		n /= a[i];
		a[i] = n;
	}
	return n;
}

//keyの小さい方から探していった時に初めてvalueがjoken以上になる時のkey（keyが増えたらvalueも増えるか同じになるとき）
ll value(ll key) {
	/*変更*/
	return 0;
}
ll mink(ll lkey, ll rkey/*ここも調べる*/, ll joken) {
	ll mkey;
	while (lkey != rkey) {
		mkey = (lkey + rkey) / 2;
		if (value(mkey) >= joken)rkey = mkey;
		else lkey = mkey + 1;
	}
	return rkey;
}

//ペア配列の整理
struct pea {
	ll f, s;
	bool operator<(const pea &c)const {
		return f != c.f ? f < c.f : s < c.s;
	};
};

//変数定義

//再帰関数

//アルゴリズム
void solve() {
	ll n; cin >> n;
	vec<vll> a(n, vll(n, MOD));
	rep(i, 0, n) {
		ll u, k; cin >> u >> k;
		rep(j, 0, k) {
			ll v, c; cin >> v >> c;
			a[u][v] = c;
		}
	}
	vll ans(n), p;
	ans[0] = 0;
	p.pub(0);
	rep(i, 0, n)a[i][0] = MOD;
	while (p.size() != n) {
		ll m = MOD, jj;
		rep(i, 0, p.size())rep(j, 0, n)if (ans[p[i]] + a[p[i]][j] < m) {
			m = a[p[i]][j] + ans[p[i]];
			jj = j;
		}
		p.pub(jj);
		ans[jj] = m;
		rep(i, 0, n)a[i][jj] = MOD;
	}
	rep(i, 0, n)cout << i << " " << ans[i] << kai;
}


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

int main() {
	int n; cin >> n;
	rep(i,25){
		rep(y,14){
			if(4*i+7*y==n){
				cout << "Yes" << endl;
				return 0;
			}
		}
	}
	cout << "No" << endl;
	return 0;
}



Measured memory_bytes: 256
n=97,t,s;
int c(int i,int j,int k){printf("< %d %d %d ",i,j,k);}
int a(int i,int j,int k){printf("+ %d %d %d ",i,j,k);}
int m(int i,int j,int k){for(t=0;t<59;++t){a(k,k,k);for(s=0;s<=t;++s)if(s<30&&s+30>t){a(i+t-s,j+s,98);c(n,98,99);a(k,99,k);}}}
int d(int x,int i,int j){for(t=0;t<30;++t){a(j+t-1,j+t-1,j+t);a(j+t,n,j+t);for(s=t;s<29;++s)a(j+s,j+s,j+s+1);c(j+29,x,i+t);a(j+t-1,j+t-1,j+t);a(j+t,i+t,j+t);}}
main(){puts("3933");a(0,1,n);c(2,n,n);a(0,n,3);a(1,n,4);d(3,5,36);d(4,36,67);m(5,36,2);}

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

int main(void) {
	int tmp,x=0,n,t,ti[200000];
	cin >> n >> t;
	for (int i = 0; i < n; i++) {
		cin >> ti[i];
	}
	for (int i = 1; i < n; i++) {
		if ((tmp=( ti[i]-ti[i-1]))< t) {
			x += tmp;
		}
		else {
			x += t;
		}
	}
	x += t;
	cout << x << endl;
}

Measured memory_bytes: 1024
#include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <functional>
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int X; cin >> X;
    int c = 360;
    while(true) {
        if(c % X == 0) {
            cout << c / X << endl;
            return 0;
        }
        c += 360;
    }

    return 0;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
int MOD = 1000000007;
int INF = numeric_limits<int>::max() / 2;


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

  int N;
  cin >> N;
  int C[N];
  int A[16][16], B[16][16];
  rep(i, 16){
    rep(j, 16){
      A[i][j] = -1;
      B[i][j] = -1;
    }
  }
  for(int i=0;i<N;i++){
    cin >> C[i];
    for(int j=0;j<C[i];j++){
      int a, b;
      cin >> a >> b;
      a--;
      A[i][j] = a, B[i][j] = b;
    }
  }
  int ans = 0;
  for(int bit=0;bit<(1<<N);bit++){
    int res = 0;
    bool ok = true;
    for(int i=0;i<N;i++){
      for(int j=0;j<N;j++){
        if(B[i][j] == -1) break;
        if((1 & (bit >> i)) == 0) break;
        if(B[i][j] !=  (1&(bit >> A[i][j]))){
          ok = false;
        }
      }
    }
    if(ok){
      rep(k, N){
        if((bit>>k) & 1) res++;
      }
      ans = max(ans, res);
    }
  }

  cout << ans << endl;

}

Measured memory_bytes: 256