akhauriyash/Code-Regression huggingface dataset:
// clang-format off
#include <bits/stdc++.h>
#define int long long
#define main signed main()
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
#define forever for (;;)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define prec(n) fixed << setprecision(n)
template<typename A> using V = std::vector<A>;
template<typename A> using F = std::function<A>;
template<typename A, typename B> using P = std::pair<A, B>;
using pii = P<int, int>;
using vi = V<int>;
using vd = V<double>;
using vs = V<std::string>;
using vpii = V<pii>;
using vvi = V<vi>;
using vvpii = V<vpii>;
constexpr int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
constexpr int MOD = 1000000007;
constexpr double PI = acos(-1);
template<typename A, typename B> bool cmin(A &a, const B &b) { return a > b ? (a = b, true) : false; }
template<typename A, typename B> bool cmax(A &a, const B &b) { return a < b ? (a = b, true) : false; }
template<typename T> std::istream &operator>>(std::istream &is, std::vector<T> &v) { for (T &x : v) is >> x; return is; }
template<typename A, typename B> std::istream &operator>>(std::istream &is, std::pair<A, B> &p) { is >> p.first; is >> p.second; return is; }
using namespace std;
// clang-format on

constexpr bool isPrime(const int &n) {
  if (n == 1) return false;
  for (int i = 2; i * i <= n; i++) {
    if (n % i == 0) return false;
  }
  return true;
}

main {
  int n, x;
  while (cin >> n >> x, n) {
    vi v(n);
    cin >> v;
    vi dp(x + 1);
    dp[0] = true;
    for (auto &t : v) rep(i, x + 1 - t) dp[i + t] |= dp[i];
    for (int i = x; i > 0; i--) {
      if (dp[i] && isPrime(i)) {
        cout << i << endl;
        goto next;
      }
    }
    cout << "NA" << endl;
  next:;
  }
}

Measured memory_bytes: 16768
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>
#include <fstream>
#include <bitset>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef complex<double> Point;

#define PI acos(-1.0)
#define EPS 1e-10
const ll INF = 1e9 + 7;
const ll MOD = 1e9 + 7;

#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define REP(i,N) for(long long i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define EQ(a,b) (abs((a)-(b))<EPS)
#define EQV(a,b) ( EQ((a).real(), (b).real()) && EQ((a).imag(), (b).imag()) )
#define fi first
#define se second

ll n;
ll a[100100];
ll d[100100];

int main(){
	cin >> n;
	ll k = 0;
	REP(i, n){
		cin >> a[i];
		k += a[i];
	}
	a[n] = a[0];
	ll num = n*(n + 1) / 2;

	if (k%num != 0){
		cout << "NO" << endl;
		return 0;
	}
	k /= num;
	REP(i, n){
		d[i] = a[i + 1] - a[i];
		d[i] -= k;
		//cout << d[i] << endl;
	}
	REP(i, n){
		if (d[i] > 0 || abs(d[i]) % n != 0){
			cout << "NO" << endl;
			return 0;
		}
	}
	cout << "YES" << endl;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1LL<<60;
int N;
vector<int> A;
vector<vector<int>> G;
vector<ll> dp;
vector<int> res;
int ma;
void f(int p, int q) {
	ll x = A[p];
	auto y = (int)(lower_bound(dp.begin(), dp.end(), x) - dp.begin());
	auto tmp_ma = ma;
	ma = max(ma, y);
	res[p] = ma;
	auto tmp = dp[y];
	dp[y] = x;
	for (int v : G[p]) if (v != q) {
		f(v, p);
	}
	dp[y] = tmp;
	ma = tmp_ma;
}
int main() {
	cin >> N;
	A.resize(N);
	for (auto& x : A) cin >> x;
	G.resize(N);
	for (int i = 0; i < N-1; ++ i) {
		int u, v;
		cin >> u >> v;
		-- u; -- v;
		G[u].push_back(v);
		G[v].push_back(u);
	}
	res.resize(N);
	dp.resize(N+10, INF);
	dp[0] = -INF;
	f(0, -1);
	for (auto x : res) cout << x << endl;
}


Measured memory_bytes: 31708
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
//using System.Text;
//using System.Text.RegularExpressions;
//using System.Globalization;
//using System.Diagnostics;
using static System.Console;
//using System.Numerics;
//using static System.Math;
//using pair = Pair<int, int>;

class Program
{
    static void Main()
    {
        //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
        new Program().solve();
        Out.Flush();
    }
    readonly Scanner cin = new Scanner();
    readonly int[] dd = { 0, 1, 0, -1, 0 }; //→↓←↑
    readonly int mod = 1000000007;
    void chmax<T>(ref T a, T b) where T : IComparable<T> { a = a.CompareTo(b) < 0 ? b : a; }
    void chmin<T>(ref T a, T b) where T : IComparable<T> { a = a.CompareTo(b) < 0 ? a : b; }

    void solve()
    {
        int N = cin.nextint;
        int W = cin.nextint;
        var dp = new long[100000 + 1];
        for (int i = 0; i < dp.Length; i++)
        {
            dp[i] = long.MaxValue / 3;
        }
        dp[0] = 0;
        for (int i = 0; i < N; i++)
        {
            int w = cin.nextint;
            int v = cin.nextint;
            for (int j = dp.Length - 1; j >= 0; j--)
            {
                if (j - v < 0)
                {
                    break;
                }
                chmin(ref dp[j], dp[j - v] + w);
            }
        }
        for (int i = dp.Length - 1; i >= 0; i--)
        {
            if (dp[i] <= W)
            {
                WriteLine(i);
                return;
            }
        }
    }

}

class Scanner
{
    string[] s; int i;
    readonly char[] cs = new char[] { ' ' };
    public Scanner() { s = new string[0]; i = 0; }
    public string[] scan { get { return ReadLine().Split(); } }
    public int[] scanint { get { return Array.ConvertAll(scan, int.Parse); } }
    public long[] scanlong { get { return Array.ConvertAll(scan, long.Parse); } }
    public double[] scandouble { get { return Array.ConvertAll(scan, double.Parse); } }
    public string next
    {
        get
        {
            if (i < s.Length) return s[i++];
            string st = ReadLine();
            while (st == "") st = ReadLine();
            s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
            i = 0;
            return next;
        }
    }
    public int nextint { get { return int.Parse(next); } }
    public long nextlong { get { return long.Parse(next); } }
    public double nextdouble { get { return double.Parse(next); } }
    public void join<T>(IEnumerable<T> values) { WriteLine(string.Join(" ", values)); }
}

Measured memory_bytes: 13792
#include <iostream>
#include <math.h>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <algorithm>
#include <iomanip>
#include <string.h>

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define ALL(a)  (a).begin(),(a).end()

typedef long long lint;

using namespace std;


int main(){
  lint D,G;
  cin>>D>>G;
  int N=0;
  REP(i,D)N+=1<<i;
  int p[D];
  int c[D];
  REP(i,D)cin>>p[i]>>c[i];
  lint ans=9999;
  REP(i,N+1){
    lint score=G;
    int temp=0;
    REP(j,D){
      if(i&(1<<j)){
        // cout<<j;
        temp+=p[j];
        score-=p[j]*100*(j+1)+c[j];
      }
    }
    for(int j=D-1;j>=0;j--){
      if(score<=0)break;
      if(!(i&(1<<j))){
        int m=min(p[j]-1,int((score-1)/(100*(j+1))+1));
        temp+=m;
        score-=m*100*(j+1);
      }
    }
    // cout<<" ";
    // cout<<temp<<endl;
    if(temp<ans and score<=0)ans=temp;
  }
  cout<<ans<<endl;
  return 0;
}


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

using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)  //(i, 10) i=0～i=9まで

int main() {
    int n;
    cin >> n;
    int v[n], c[n];
    rep(i, n) { cin >> v[i]; }
    rep(i, n) { cin >> c[i]; }

    int ans = 0;
    rep(i, n) {
        if (v[i] - c[i] >= 0) {
            ans += v[i] - c[i];
        }
    }

    cout << ans << endl;

    return 0;
}


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

int main(){
string b;
cin >> b;
ll n = b.size(), c = 0;
if(b[0] == 'A' && b[1] != 'C' && b[n - 1] != 'C') {
for(int i = 1; i < n; i++) {
if(b[i] == 'C') {
c++;
} else if (isupper(b[i])) {
c = 10;
break;
}
}
if(c == 1 && islower(b[1])) cout << "AC" << endl;
else cout << "WA" << endl;
} else cout << "WA" << endl;
return 0;
}




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

int N;
int A[3][101];

int dp[3][101];

int main()
{
	cin >> N;

	for(int i = 1;i <= 2;i++)
	{
		for(int j = 1;j <= N;j++)
		{
			cin >> A[i][j];
		}
	}


	for(int i = 1;i <= 2;i++)
	{
		for(int j = 1;j <= N;j++)
		{
			dp[i][j] = max(dp[i - 1][j] , dp[i][j - 1]) + A[i][j];
		}
	}

	cout << dp[2][N] << endl;
	return 0;
	}


Measured memory_bytes: 256
#include<stdio.h>
#include<assert.h>
typedef long long ll;
const int T=10000;
int pr[T+10];
bool np[T+10];
void sieve(){
	int i,j,M=0;
	for(i=2;i<=T;i++){
		if(!np[i])pr[++M]=i;
		for(j=1;j<=M&&i*pr[j]<=T;j++){
			np[i*pr[j]]=1;
			if(i%pr[j]==0)break;
		}
	}
}
ll gcd(ll a,ll b){return a%b==0?b:gcd(b,a%b);}
ll lcm(ll a,ll b){
	if(a==0||b==0)return a|b;
	return a/gcd(a,b)*b;
}
ll a[510][510];
int main(){
	sieve();
	int n,i,j,M;
	scanf("%d",&n);
	if(n==2){
		puts("4 7\n23 10");
		return 0;
	}
	M=0;
	for(i=1;i<n;i+=2){
		M++;
		for(j=1;j<=i;j++)a[j][i-j+1]=pr[M];
	}
	if(n&1){
		M++;
		for(i=1;i<=n;i++)a[n-i+1][i]=pr[M];
	}
	for(i=1;i<n;i+=2){
		M++;
		for(j=1;j<=i;j++)a[n-j+1][n-i+1+j-1]=pr[M];
	}
	for(i=1;i<=n;i+=2){
		M++;
		for(j=1;i+j-1<=n;j++)a[j][i+j-1]*=pr[M];
	}
	for(i=3;i<=n;i+=2){
		M++;
		for(j=1;i+j-1<=n;j++)a[i+j-1][j]*=pr[M];
	}
	for(i=1;i<=n;i++){
		for(j=1;j<=n;j++){
			if((i+j)&1)a[i][j]=lcm(lcm(a[i-1][j],a[i][j-1]),lcm(a[i+1][j],a[i][j+1]))+1;
		}
	}
	for(i=1;i<=n;i++){
		for(j=1;j<=n;j++)printf("%lld ",a[i][j]);
		putchar('\n');
	}
}

Measured memory_bytes: 5120
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int d, x;
  cin >> d >> x;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (int i = 0; i < n; i++) {
    x++;
    int t = 1 + a[i];
    while (t <= d) {
      x++;
      t += a[i];
    }
  }
  cout << x << endl;
  return 0;
}

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

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

    int cnt = 0;
    for (int i = 0; i < 3; i++) {
        if (s[i] == t[i]) {
            cnt++;
        }
    }

    cout << cnt << endl;



    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n,a,b;
  cin >> n ;
  
  a=n%1000;
  b=n-n%10;
  
  if(a%111==0 ||b%111==0){
    cout << "Yes"<< endl;
  }
  else{
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
N = int(input())
A = []
B = []
for _ in range(N):
    temp = int(input())
    A.append(temp)
    B.append(temp)

B.sort(reverse=True)
max_first = B[0]
max_second = B[1]

for i in range(N):
    if A[i] == max_first:
        print(max_second)
    else:
        print(max_first)

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

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

#define rep(i,cc,n) for(int i=cc;i<n;++i)
#define lrep(i,cc,n) for(long long i=cc;i<n;++i)
#define sqrep(i,cc,n) for(long long i=cc;i*i<=n;++i)
#define rrep(i,cc,n) for(long i=cc;i>n;--i)
#define pii pair<int, int>
#define pll pair<long long, long long>
 
using ll = long long;

const vector<int> dx = {1, 0, -1, 0};
const vector<int> dy = {0, 1, 0, -1};
const ll inf = 1001001001;
const ll e9  = 1000000000;
const ll mod = 1000000007;


int main(){
  int n;
  cin >> n;
  vector<int>a(n+1), cnt(200200),ans;
  rep(i, 1, n+1)cin >> a[i];
  //reverse(a.begin(),a.end());
  for(int i=n; i>=1; i--){
    int p = 0;
    for(int j=2*i; j<=n; j+=i)if(cnt[j]!=0)p++;
    if(p%2==a[i])continue;
    ans.push_back(i);
    cnt[i] = 1;
  }
  cout << ans.size() << endl;
  rep(i, 0, ans.size()){
    cout << ans[ans.size()-1-i] << " ";
  }
  cout << endl;
}

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

/************************** definations *******************************/
#define pi              2*acos(0.0)
#define ll              long long int
#define sc1(a)          scanf("%lld",&a)
#define sc2(a,b)        scanf("%lld %lld",&a,&b)
#define pf1(a)          printf("%lld\n",a)
#define pf2(a,b)        printf("%lld %lld\n",a,b)
#define Case(a)         printf("Case %d: ",a)
#define Casel(a)        printf("Case %lld: ",a)
#define INF             1e9
#define INFL            1e18
#define XX              first
#define YY              second
#define PB              push_back
#define MP              make_pair
#define NL              cout << endl;
#define DONE            cerr << "Done" << endl
#define PAUSE           system("pause")
#define DEBUG(x)        cerr << #x << " = " << x << endl
#define READ            freopen("alu.txt", "r", stdin)
#define WRITE           freopen("vorta.txt", "w", stdout)
#define FASTIO          ios_base::sync_with_stdio(false);cin.tie(NULL)
#define M               10000007
#define mod             100000007
#define Mod             1000000007
#define N               1000000
/************************** definations *******************************/
int main()
{
    ll x;
    cin >> x;
    cout << ((x/500)*1000 + ((x%500)/5)*5);
}


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

int main() {
  vector<char> V(4);
  int yymm=1, mmyy=1;
  for (int i=0; i<4; i++) {
    cin >> V[i];
  }
  if ((V[0]-'0')*10+(V[1]-'0')>12 || (V[0]-'0')*10+(V[1]-'0')<1) {
    mmyy=0;
  }
  if ((V[2]-'0')*10+(V[3]-'0')>12 || (V[2]-'0')*10+(V[3]-'0')<1) {
    yymm=0;
  }
  
  if (mmyy==1 && yymm==1) {
    cout << "AMBIGUOUS" << endl;
  }
  else if (mmyy==0 && yymm==1) {
    cout << "YYMM" << endl;
  }
  else if (mmyy==1 && yymm==0) {
    cout << "MMYY" << endl;
  }
  else if (mmyy==0 && yymm==0) {
    cout << "NA" << endl;
  }
}


Measured memory_bytes: 3604
using System;

public class Program
{
    static void Main()
    {
        string[] input = Console.ReadLine().Split(' ');
        int N = int.Parse(input[0]);
        int M = int.Parse(input[1]);
        string a = Console.ReadLine();
        string[] mojiretu = new string[N];
        string TrueMojiretu = "";

        string b = a[M - 1].ToString().ToLower();
        for (int i = 0; i < N; i++)
        {
            if(i == M - 1)
            {
                mojiretu[i] = a[M - 1].ToString().ToLower();
            }
            else
            {
                mojiretu[i] = a[i].ToString();
            }
            TrueMojiretu += mojiretu[i];
        }
        Console.WriteLine(TrueMojiretu);
    }
}


Measured memory_bytes: 13140
fun main(args: Array<String>){
    val line: String = readLine() as String
    val nm=line.split(" ")
    val n = nm[0].toLong()
    val m = nm[1].toLong()
    if (n==1L&&m==1L){
        print(1)
    }else if(n==1L||m==1L){
        print(n*m-2)
    }else print((n-2)*(m-2))

}

Measured memory_bytes: 37572
n=gets.to_i
an=gets.split(' ').map(&:to_i)
rn=[]
rn << an.map.with_index(1){|a,i|(i%2!=0)? a : -a}.sum
(n-1).times do |i|
  rn << 2*an[i]-rn.last
end
puts rn.join(' ')

Measured memory_bytes: 23508
#include <bits/stdc++.h>
using namespace std;
const int N=1e5+10;
int n,m,ht=0,hd[N],d[N],vis[N];
struct edge{int v,n;}e[N*2];
void addedge(int u,int v){
    e[++ht]=(edge){v,hd[u]};
    hd[u]=ht;d[u]++;
}
void dfs(int u,int f,int T){
    for(int i=hd[u],v;i;i=e[i].n){
        v=e[i].v;
        if(v==f||u==T||vis[v]) continue;
        vis[v]=1;dfs(v,u,T);
    }
}
bool judge(){
    int num=0,s[5];
    for(int i=1;i<=n;i++)
        if(d[i]&1) return 0;
    for(int i=1;i<=n;i++)
        if(d[i]>=6) return 1;
        else if(d[i]>=4){
            if(++num>=3) return 1;
            s[num]=i;
        }
    if(num<=1) return 0;
    return dfs(s[1],0,s[2]),vis[s[1]];
}
int main(){
    scanf("%d%d",&n,&m);
    for(int i=1,u,v;i<=m;i++){
        scanf("%d%d",&u,&v);
        addedge(u,v),addedge(v,u);
    }
    if(judge()) puts("Yes");
    else puts("No");
    return 0;
}

Measured memory_bytes: 5376
#pragma region cp-helper
#include <bits/stdc++.h>
using namespace std;
#define AC ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define int long long
#define ll long long
#define ull unsigned long long
#define ii pair<int, int>
#define lll pair<ll, ll>
#define vi vector<int>
#define vvi vector<vi>
#define vl vector<ll>
#define vll vector<lll>
#define vvl vector<vl>
#define vii vector<ii>
#define all(a) a.begin(), a.end()
#define qsort(a) sort(all(a))
#define qsortd(a) sort(all(a), greater<>())
#define qsortf(a, f) sort(all(a), f)
#define pb(n) push_back(n)
#define eb(n) emplace_back(n)
#define pp(a, b) emplace_back(a, b)
#define umap unordered_map
#define uset unordered_set
#define nl '\n'
#define fileio(in, out) freopen(in, "r", stdin); freopen(out, "w", stdout)
#define qmod %mod
#define pls signed
#define give main()
const int mod = 1000000007;
#pragma endregion

const int N = 100005;

pls give {
    AC;
    int a, b, c;
    cin >> a >> b >> c;
    if ((a == b and a != c) or (b == c and b != a) or (a == c and b != a)) cout << "Yes";
    else cout << "No";
}

Measured memory_bytes: 256
package main

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

type Scanner struct {
	sc *bufio.Scanner
}

func NewScanner() *Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024), int(1e+9))
	return &Scanner{sc}
}

func (s *Scanner) nextStr() string {
	s.sc.Scan()
	return s.sc.Text()
}

func (s *Scanner) nextInt() int {
	i, e := strconv.Atoi(s.nextStr())
	if e != nil {
		panic(e)
	}
	return i
}

func (s *Scanner) nextFloat() float64 {
	f, e := strconv.ParseFloat(s.nextStr(), 64)
	if e != nil {
		panic(e)
	}
	return f
}

func (s *Scanner) nextRuneSlice() []rune {
	return []rune(s.nextStr())
}

func (s *Scanner) nextIntSlice(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextInt()
	}
	return res
}

func max(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m < i {
			m = i
		}
	}
	return m
}

func min(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m > i {
			m = i
		}
	}
	return m
}

func abs(x int) int {
	if x > 0 {
		return x
	}
	return -x
}

func pow(x, y int) int {
	res := 1
	for i := 0; i < y; i++ {
		res *= x
	}
	return res
}

func main() {
	sc := NewScanner()
	r, D, x := sc.nextInt(), sc.nextInt(), sc.nextInt()
	before := x
	for i := 1; i <= 10; i++ {
		fmt.Println(r*before - D)
		before = r*before - D
	}
}


Measured memory_bytes: 640
#include <bits/stdc++.h>   
using namespace std;
#define N 50   
#define REP(i, n) for(int i=0; i<n; i++)
int h,w;
string str[N];
int can=1;
int main(void){

    cin >> h;
    cin >> w;

    REP(i,h){
        cin >> str[i];
    }
    const int dx[4]={-1,0,0,1};
    const int dy[4]={0,-1,1,0};
    REP(i,h){
        REP(j,w){  
            if(str[i][j]=='#'){
                int check=0;
                REP(k,4){
                int x=j+dx[k];
                int y=i+dy[k];
                if(x<0 or x>=w or y<0 or y>=h)continue;
                if(str[y][x]=='#')check=1;
                }
                if(check==0)can=0;
            }
            
        }
    }
    
    if(can==1){
     printf("Yes");   
    }else{
     printf("No");
    }
  //  for (int i = 0; i < h; ++i) cout << str[i] << endl;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
long long pre[200007];
int main(){
	ios::sync_with_stdio(false);//关同步 
	long long n,d,a;
	cin>>n>>d>>a;
	vector<pair<long long,long long> >v;
	for(int i=1;i<=n;++i){
		long long x,y;
		cin>>x>>y;
		long long z=(y-1)/a+1;
        v.push_back({x,z});
    }
    sort(v.begin(),v.end());
    long long ans=0;
    long long sum=0;
    int r=1;//打不到的最近范围 
    for(int i=0;i<n;++i){
		while(r<n&&v[r].first<=v[i].first+2*d)
			++r;
		sum-=pre[i];//sum为当前位置已经预先承受的伤害总量
		v[i].second-=sum;
		if(v[i].second<=0)
			continue;
		sum+=v[i].second;//累计伤害 
		pre[r]+=v[i].second;//r位置以前承受的伤害总量 
		ans+=v[i].second;
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 6384
N=int(input())
A=list(map(int,input().split()))
B=[]
for k in range(N):
  B.append(A[k]-k-1)
B=sorted(B)
if N%2==0:
  b=(B[N//2]+B[-1+N//2])//2
else:
  b=B[N//2]
ans=0
for k in range(N):
    ans+=abs(A[k]-b-k-1)
print(ans)

Measured memory_bytes: 25200
#include"bits/stdc++.h"
using namespace std;

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

    int cnt = 1;
    int ans = 0;

    for(int i=0;i<n-1;i++){
        if(a[i]==a[i+1]){
            cnt++;
        }
        else{
            ans += cnt / 2;
            cnt = 1;
        }
    }
    ans += cnt / 2;

    cout << ans << endl;
}

Measured memory_bytes: 256
A, B, C, K = map(int, input().split())
ans = 0
if K > 0:
	if A >= K:
		ans += K
		K = 0
	else:
		ans += A
		K -= A

if K > 0:
	if B >= K:
		K = 0
	else:
		K -= B
if K > 0:
	ans -= K

print(ans)

Measured memory_bytes: 9192
import sys
#input = sys.stdin.readline
input = sys.stdin.buffer.readline

# mod=10**9+7
# rstrip().decode('utf-8')
# map(int,input().split())
#import numpy as np


def main():
	li=[[0]*10 for i in range(10)]
	n=int(input())
	for i in range(1,n+1):
		i=str(i)
		li[int(i[0])][int(i[-1])]+=1

	ans=0

	for i in range(1,10):
		for j in range(1,10):
			ans+=li[i][j]*li[j][i]

	print(ans)
















if __name__ == "__main__":
	main()


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

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		long K = sc.nextLong();
		long A[] = new long[N];
		for(int i=0;i<N;i++)A[i]=sc.nextLong();
		sc.close();
	
		//以下の方法でXを作ることで、答えを最大にしうるXを無駄なく全探索する。
		//方法：
		// Kを上から見て、基本的にはKに一致させるようにXを作成していく。
		// ただし、途中Kのある桁が１のとき、Xの同桁を０にする。
		// すると、それより下の桁はどう選んでもXがKを越えない。
		// したがって見ている桁について、貪欲に、A1~ANの１の数が０の数より大きければ０、そうでなければ１として良い。
		
		// 以上から、Kのある桁iが１の時に、Xの同桁を最初に０とするようなiを全部試す。（全探索する）
		
		//桁の操作には関係ないが、あとで使うのでA_1~A_Nの各桁の１の数を調べておく。
		long cnt1[] = new long[61]; 
		for(int d = 60;d >= 0;d--) {
			for(int i=0;i<N;i++) {
				long a = A[i];
				if((a>>d & 1)==1) cnt1[d]++;
			}
		}
	
		long ans = 0;
		
		for(int d = 60;d >= -1;d--) { //dはXの桁を上から見ていくための添字。d==-1とすると、Kに完全に一致する場合を一緒に表現できる。
			long res = 0;
			if((K>>d&1)!=1 && d!=-1) continue; //上からd桁目が1でない（つまり0）ならXの同桁も0にするだけ。その場合の最大値は以降のループに含まれる。また、別で全一致の状態を調べるために最後のd=-1のときだけは以下の処理を行う。
			//Kの、上からd桁目が1のとき
			//Xの同桁を0にし、上の桁はKに一致、下の桁は答えが最大になるように決める。ループで作りながら答えを求める。
			for(int e = 60;e>=0;e--) {
				long tmp = 0;
				if(e>d) { //Kに一致させる
					if((K>>e & 1)==1) tmp += N - cnt1[e];
					else tmp += cnt1[e];
				}
				else if(e==d) { //０にするということ
					tmp += cnt1[e];
				}
				else { //答えを最大化するように０と１を選ぶ
					tmp += Math.max(cnt1[e], N-cnt1[e]);
				}
				res += tmp << e;
			}
			ans = Math.max(ans, res);
		}
		
		System.out.println(ans);

	}
}


Measured memory_bytes: 51996
#include<bits/stdc++.h>
using namespace std;
int main(){
  int K;
  string S;
  cin>>S>>K;
  int n=S.length();
  if(S.at(0)!='1'){
    cout<<S.at(0)<<endl;
  }
  else{
    bool frag=true;
    for(int i=0;i<min(K,n);i++){
      if(S.at(i)=='1'){
      }
      else{
        cout<<S.at(i)<<endl;
        frag=false;
        break;
      }
    }
    if(frag==true){
      cout<<'1'<<endl;
    }
    else{
    }
  }
}
  


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

public class MainClass
{
	public const long Giri = 1000000007;
	public const long DpInf = 99999999999999;
	
	public static void Main(string[] args)
	{
		var n  = Console.ReadLine().ToInt();
		var a = Input().ToInt(-1);
		var k = new long[n];
		for(int i = 0; i < n-1; i++)
		{
			k[a[i]]++;
		}
		for(int i = 0; i < n; i++)
		{
			Console.WriteLine(k[i]);
		}
		
	}
	
	static long GCD(long a, long b)
	{
		var v = new[] { a, b };
		while (v[1] != 0) { v = new[] { v[1], v[0] % v[1] }; }
		return v[0];
	}
	public static string[] Input() { return Console.ReadLine().Split(); }
}

public static class Smarter
{
	public static int ToInt(this string str) { return int.Parse(str); }
	public static long ToLong(this string str) { return long.Parse(str); }
	public static int[] ToInt(this string[] str, int offset = 0)
	{
		var r = new int[str.Length];
		for(int i = 0; i < str.Length; i++) r[i] = str[i].ToInt() + offset;
		return r;
	}
}

Measured memory_bytes: 43704
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

use std::cmp::max;

fn main() {
    input! {
        n: usize,
        t: usize,
        ab: [(i64, i64); n],
    }

    let ans = solve(0, t, 0, &ab, &mut vec![vec![vec![None; t + 1]; n + 1]; 2]);

    println!("{}", ans);
}

fn solve(
    i: usize,
    time: usize,
    last: usize,
    ab: &[(i64, i64)],
    tbl: &mut Vec<Vec<Vec<Option<i64>>>>,
) -> i64 {
    if i == ab.len() || time <= last {
        return 0;
    }

    if let Some(ret) = tbl[last][i][time] {
        return ret;
    }

    let mut ret = solve(i + 1, time, last, ab, tbl);

    if time - last >= ab[i].0 as usize {
        ret = max(
            ret,
            solve(i + 1, time - ab[i].0 as usize, last, ab, tbl) + ab[i].1,
        );
    }

    if last == 0 {
        ret = max(ret, solve(i + 1, time, 1, ab, tbl) + ab[i].1);
    }

    tbl[last][i][time] = Some(ret);
    ret
}


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

int main(){
    int N;
    int T, A;
    cin >> N >> T >> A;

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

    float min = 114514;
    int ans = 1;
    for(int i = 0; i < N; i++){
        float sa = A - T + 0.006*h[i];
        if(sa < 0) sa = 0-sa;
        if(min > sa) {
            min = sa;
            ans = i+1;
        }
    }

    cout << ans << endl;
}

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

using namespace std;
#define PI 3.1415926535897932384626433832795
#define MOD (1000000007)
#define EPS (1e-15)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repc(i, s, n) for (int i = (s); i <= (n); i++)
#define rrep(i, n) for (int i = (n) - 1; i >= 0; i--)
#define rrepc(i, s, n) for (int i = (s); i >= (n); i--)
#define bet(x, a, b) (a) <= (x) && (x) < (b)
typedef long long ll;
typedef unsigned long long ull;



int main()
{
	int n, taro = 0, hanako = 0;
	string T, H;

	cin >> n;
	rep(i, n) {
		cin >> T >> H;
		if (T < H) hanako += 3;
		else if (T > H) taro += 3;
		else hanako++, taro++;
	}

	cout << taro << ' ' << hanako << endl;

	return 0;
}



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

int main(void){
	ll a,b,c;
	cin >> a >> b >> c;
  	ll d = c-(a+b);
  	if(d<0){
      cout << "No";
      return 0;
    }
  	if(d*d>4*a*b) cout << "Yes";
 	 else cout << "No";
    
return 0;
}

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

int main(void) {
    int n;
    cin >> n;
    string s;
    cin >> s;
    int ma = 0, x = 0;
    for (int i = 0; i < n; i++) {
        char c = s.at(i);
        if (c == 'I') {
            x++;
            ma = max(ma, x);
        }
        else {
            x--;
        }
    }
    cout << ma << endl;
    return 0;
}

Measured memory_bytes: 3568
#include<bits/stdc++.h>
//#pragma GCC optimize("Ofast","no-stack-protector","unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,sse4.2,popcnt,abm,mmx,avx")
//#include<bits/extc++.h>
//using namespace __gnu_pbds;
using namespace std;
#define int long long
#define F(i,L,R) for(int i=L;i<R;++i)
#define FE(i,L,R) for(int i=L;i<=R;++i)
#define getI(a) scanf("%lld",&a)
#define getII(a,b) scanf("%lld%lld",&a,&b)
#define getIII(a,b,c) scanf("%lld%lld%lld",&a,&b,&c)
#define VgetI(n) int (n); scanf("%lld",&(n))
#define VgetII(n,m) int (n),(m); scanf("%lld%lld",&(n),&(m))
#define VgetIII(n,m,k) int (n),(m),(k); scanf("%lld%lld%lld",&(n),&(m),&(k))
#define debug(x) cout<<(#x)<<"="<<x<<"\n";
#define qq cout<<"QQ\n";
#define pb push_back
#define pii pair<int,int>
#define mp make_pair
#define f first
#define s second
#define INF 2000000000
#define maxN 100005
int cnt[maxN];
main(){
	int n;
	while(~getI(n)){
		F(i,0,maxN) cnt[i]=0;
		F(i,0,n){
			VgetI(tmp);
			cnt[tmp]++;
		}
		int sum=0;
		F(i,0,maxN) sum+=cnt[i]*i;
		VgetI(q);
		while(q--){
			VgetII(b,c);
			sum+=(c-b)*cnt[b];
			cnt[c]+=cnt[b];
			cnt[b]=0;
			printf("%lld\n",sum);
		}
	}
}


Measured memory_bytes: 4588
import sys
 
inf = float('inf')
 
n, m = map(int, sys.stdin.readline().split())
abc = []
for _ in range(m):
    a, b, c = map(int, sys.stdin.readline().split())
    abc.append((a-1, b-1, -c))
 
def main():
    dist = [inf] * n
    dist[0] = 0
    for _ in range(n-1):
        for a, b, c in abc:
            dist[b] = min(dist[b], dist[a] + c)
 
    for _ in range(n):
        for a, b, c in abc:
            if dist[a] + c < dist[b]:
                dist[b] = -inf
 
    return -dist[n-1]
 
if __name__ == '__main__':
    ans = main()
    print(ans)

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

int main(){
	int n;
  cin >> n;
  string str;
  cin >> str;
  int cnt=1;
  char ch = str[0];
  for(int i=1;i<n;i++){
     if(ch != str[i]){
       cnt++;
       ch = str[i];
     }
  }
  cout<<cnt;
  return 0;
}

Measured memory_bytes: 512
X,N=map(int,input().split())
p=[]
if N != 0:
  p=list(map(int,input().split()))
  p.sort()
i=0
while True:
  if X-i not in p:
    print(X-i)
    break
  elif X+i not in p:
    print(X+i)
    break
  i += 1

  

Measured memory_bytes: 9032
#include<stdio.h>
int main(){
  int i, j, cal, min = 2018;
  int L, R;
  scanf("%d %d", &L, &R);
    if(R-L>=2019)
{      min=0;
   }
 else
   {    
	for(i = L; i < R; i++){
      for(j = i+1; j <= R; j++){
        cal = (i%2019)*(j%2019)% 2019;
        if(cal < min){
          min = cal;
        }
      }
     }
    }
  printf("%d", min);
}


Measured memory_bytes: 128
# -*- coding: utf-8 -*-
"""
https://beta.atcoder.jp/contests/abc087/tasks/abc087_b

"""
import sys
from sys import stdin
input = stdin.readline


def solve(A, B, C, X):
    ans = 0

    for a in range(A+1):
        for b in range(B+1):
            for c in range(C+1):
                if 500*a + 100*b + 50*c == X:
                    ans += 1
    return ans


def main(args):
    A = int(input())
    B = int(input())
    C = int(input())
    X = int(input())
    ans = solve(A, B, C, X)
    print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])


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

int n,r;


int main(){
    ios_base::sync_with_stdio(0);
    //freopen("input.txt","r",stdin);

    cin>>n>>r;

    if(n>=10){
        cout << r;
    }else{
        cout << r + 100*(10-n);
    }
}


Measured memory_bytes: 384
N=int(input())
A=list(map(int,input().split()))
count=0
B=[]
for i in range(N):
    if A[i]<0:
        B.append((-1)*A[i])
        count+=1
    else:
        B.append(A[i])
if count%2==0:
    print(sum(B))
else:
    print(sum(B)-2*min(B))

Measured memory_bytes: 14284
#include <iostream>
#include <string>
#include <algorithm>
#include <utility>
#include <iomanip>
#include <functional>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <cctype>
#include <cstdio>
#include <bitset>
#include <complex>
#define ll long long
#define INF 1000000000000000001
#define MOD 998244353
using namespace std;


int main(){
    int n;
    cin >> n;
    string s;
    cin >> s;
    for(int i=0; i<s.length(); i++){
        s[i] = ((s[i]-'A')+n)%26 + 'A';
    }
    
    cout<<s<<endl;
    return 0;
    
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define REP(i, n) rep(i, 0, n)
#define int long long
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e18;

signed main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	int s, w;
	cin >> s >> w;
	if(s <= w) cout << "unsafe" << endl;
	else cout << "safe" << endl;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 10;
int n, ans;
int p[maxn], pos[maxn], f[maxn];
int main()
{
	scanf("%d", &n);
	for(int i = 1; i <= n; ++i) 
	{
		scanf("%d", &p[i]);
		pos[p[i]] = i;
	}
	for(int i = n; i; --i)
	{
		if(pos[i + 1] > pos[i])
			f[i] = f[i + 1] + 1;
		else
			f[i] = 1;
	}
	ans = n - f[1];
	for(int i = 1; i <= n; ++i)
		ans = min(ans, n - (p[1] == i) - f[i + 1]);
	printf("%d\n", ans);
	return 0;
}
	

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

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<int, int> Pi;
typedef vector<ll> Vec;
typedef vector<int> Vi;
typedef vector<string> Vs;
typedef vector<vector<ll>> VV;

#define REP(i, a, b) for(ll i=(a); i<(b); i++)
#define rep(i, n) REP(i, 0, n)
const int INF=1e9;
const int MAX=100005;
const int MOD=1000000007;
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl;
#define YES(n) cout << ((n) ? "YES" : "NO") << endl;
#define ALL(v) v.begin(), v.end()
#define dbg(x_) cerr << #x_ << ":" << x_ << endl;
#define pb(x) push_back(x)
#define mp(a, b) make_pair(a,b)
#define Each(a,b) for(auto &a :b)
#define REPM(i, mp) for (auto i = mp.begin(); i != mp.end(); ++i)
#define dbgmap(mp) cerr << #mp << ":"<<endl; for (auto i = mp.begin(); i != mp.end(); ++i) { cerr << i->first <<":"<<i->second << endl;}
#define dbgarr(n,m,arr) rep(i,n){rep(j,n){cout<<arr[i][j]<<" ";}cout<<endl;}
#define sum(v) accumulate(ALL(v),0)
#define fi first
#define se second

template<typename T1, typename T2>
ostream &operator<<(ostream &s, const pair<T1, T2> &p) { return s<<"("<<p.first<<", "<<p.second<<")"; }

// vector
template<typename T>
ostream &operator<<(ostream &s, const vector<T> &v) {
    int len=v.size();
    for(int i=0; i<len; ++i) {
        s<<v[i];
        if(i<len-1) s<<"	";
    }
    return s;
}

// 2 dimentional vector
template<typename T>
ostream &operator<<(ostream &s, const vector<vector<T> > &vv) {
    int len=vv.size();
    for(int i=0; i<len; ++i) {
        s<<vv[i]<<endl;
    }
    return s;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n;
    cin>>n;
    Vec color (n+1,0);
    ll colored[n+1];
    memset(colored,0, sizeof(colored));
//    ll tree[n+1][n+1];
//    memset(tree, 0, sizeof(tree));
    vector<vector<P>> tree(n+1);
    ll a,b,c;
    rep(i,n-1){
        cin>>a>>b>>c;
        tree[a].pb(mp(b,c));
        tree[b].pb(mp(a,c));
    }

    queue<P> q;
    q.push(mp(1,0));
    while (!q.empty()){
        P &task = q.front();
        if(!colored[task.fi]){
            color[task.fi] = task.se;
            colored[task.fi] = 1;
        }
        Each(leaf,tree[task.fi]){
            if(!colored[leaf.fi]){
                q.push(mp(leaf.fi,(leaf.se+color[task.fi])%2));
            }
        }
        q.pop();
    }

    REP(i,1,n+1){
        cout << color[i] << endl;
    }
    return  0;
}


Measured memory_bytes: 9472
#include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#define REP(i,n) for(int i=0;i<(n);i++)
#define EREP(i,x,n) for(int i=(x);i<(n);i++)
#define FOR(i,n) for(int i=1;i<(n);i++)
using namespace std;
int main(){
	long long int x,t;
	cin>>x>>t;
	if(x<t){
		cout<<0<<endl;
	}
	else{
		cout<<x-t<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#include<algorithm>
#include<cmath>
#include<climits>
#include<string>
#include<set>
#include<numeric>
#include<map>
#include<iostream>
using namespace std;
#define rep(i,n) for(int i = 0;i<((int)(n));i++)
#define reg(i,a,b) for(int i = ((int)(a));i<=((int)(b));i++)
#define irep(i,n) for(int i = ((int)(n)-1);i>=0;i--)
#define ireg(i,a,b) for(int i = ((int)(b));i>=((int)(a));i--)
typedef long long ll;
typedef pair<ll, ll> mp;
ll mod = 1e9+7;

int main(void){
	ll A,B,C,K;
	scanf("%lld%lld%lld%lld",&A,&B,&C,&K);
	if(K%2==0){
		printf("%lld\n",A-B);
	}else{
		printf("%lld\n",B-A);
	}
	return 0;
}

Measured memory_bytes: 256
/*
 *Author - Abhas Jain
 *Code is inside the solve function
 */
 
#include <bits/stdc++.h>
 
#define F first
#define S second
#define all(c) c.begin(), c.end()
#define endl '\n'
#define pb push_back
#define mp make_pair 
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp> 
 
typedef long long ll;
typedef long double ld;

#define rep(i,a,b) for(ll i=a;i<b;i++)
#define bac(i,a,b) for(ll i=a;i>=b;i--)

 
using namespace std;
using namespace __gnu_pbds;
template <typename A, typename B>
string to_string(pair<A, B> p);
 
string to_string(const string& s) {
  return '"' + s + '"';
}
 
string to_string(const char* s) {
  return to_string((string) s);
}
 
string to_string(bool b) {
  return (b ? "true" : "false");
}
 
string to_string(vector<bool> v) {
  bool first = true;
  string res = "{";
  for (int i = 0; i < static_cast<int>(v.size()); i++) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(v[i]);
  }
  res += "}";
  return res;
}
 
template <size_t N>
string to_string(bitset<N> v) {
  string res = "";
  for (size_t i = 0; i < N; i++) {
    res += static_cast<char>('0' + v[i]);
  }
  return res;
}
 
template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto &x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}
 
template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
 
void debug_out() { cerr << endl; }
 
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
 
#ifdef AJ47
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 
#endif

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> oset;
typedef tree<pair<ll,ll>,null_type,less<pair<ll,ll> >,rb_tree_tag,tree_order_statistics_node_update> ordered_multiset;
mt19937 rang(chrono::high_resolution_clock::now().time_since_epoch().count());
 
const ld PI = 3.141592653589793;
const ll INF = 9223372036854775807ll;
const ll mod = 1e9 + 7;
 
void solve() 
{
    ll n, a, b;
    cin >> n >> a >> b;
    if ((b - a) % 2 == 0) cout << (b - a) / 2 << endl;
    else {
    	ll pr = a + (b - a - 1) / 2;
    	pr = min(pr, n - b + 1 + (b - a - 1) / 2);
    	cout << pr << endl;
    }
}
 
int main( )
{   
    ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    srand(chrono::high_resolution_clock::now().time_since_epoch().count());
    solve();
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); 
#define endl '\n'
#define ll long long
#define mod 1000000007
#define inf 1000000000000000000

int main()
{
	fastio;
	#ifdef APNA_IO
		freopen("input.txt" , "rt" ,stdin);
		freopen("output.txt" , "wt" ,stdout);
	#endif
	ll n;
	cin>>n;
	ll a,b,c,d;
	a=n%10;
	n=n/10;
	b=n%10;
	n=n/10;
	c=n%10;
	n=n/10;
	d=n%10;
	n=n/10;
	if(a==b || b==c || c==d)
		cout<<"Bad"<<endl;
	else
		cout<<"Good"<<endl;

	return 0;
}





Measured memory_bytes: 256
#絶対値を求める関数
def CalAbs(a, b):
    sol=a-b
    if sol<0:
        sol=sol*(-1)
    return sol
    
#桁数を求める関数    
def CalDigi(a):    
    digi=1
    flag=0
    while flag==0:
        a=a/10
        if a>=1:
            digi=digi+1
        else:
            flag=1
    return digi
    
#標準入力
input_line = input().split(" ")
N=int(input_line[0])
K=int(input_line[1])

rec=10**18+1

#Nが大きすぎる時、Kの倍数でそぎ落とす
N=N%K+K


i=0
times=100
count=0
while i<=times:
    if rec>N:
        rec=N
    N=CalAbs(N,K)
    if i==times:
     lastN=N
    i=i+1
if rec>N:
    rec=N
    

    

print(rec)




Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define zero_pad(num) setfill('0') << std::right << setw(num)
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;

int INF = 1001001001;
vector<int> a(200000);
vector<vector<int>> to(200000);
vector<int> ans(200000);
vector<int> dp(200000, INF);

P dfs(int v, int p = -1){
    auto it = lower_bound(dp.begin(), dp.end(), a[v]);
    P ret = make_pair(it-dp.begin(), *it);
    *it = a[v];
    ans[v] = lower_bound(dp.begin(), dp.end(), INF) - dp.begin();
    for(int t : to[v]){
        if(t == p)continue;
        P m = dfs(t, v);
        dp[m.first] = m.second;
    }
    return ret;
}

int main() {
    int n;
    cin >> n;
    rep(i, n)cin >> a[i];
    rep(i, n-1){
        int u, v;
        cin >> u >> v;
        u--; v--;
        to[u].push_back(v);
        to[v].push_back(u);
    }

    dfs(0);
    rep(i, n)cout << ans[i] << endl;
}

Measured memory_bytes: 27920
while True:
	n,l,r = map(int,input().split())
	if n == 0:
		break
	a = []
	for _ in range(n):
		a.append(int(input()))
	a.append(1)
	ans = 0
	for i in range(l,r+1):
		for j,aa in enumerate(a):
			if i % aa == 0:
				if j % 2 == 0:
					ans += 1
				break
	print(ans)


Measured memory_bytes: 5600
#include <iostream>
#include <string>
#include <cstdlib>
#include <cmath>

using namespace std;

int main() {
    int n, t, a, h[1000];
    cin >> n >> t >> a;
    for (int i = 0; i < n; i++) cin >> h[i];

    int x = 1;
    double min_diff = fabs(a - (t - h[1] * 0.006));

    for (int i = 0; i < n; i++) {
        double diff = fabs(a - (t - h[i] * 0.006));
        if (diff < min_diff) {
            min_diff = diff;
            x = i + 1;
        }
    }

    cout << x << endl;
}


Measured memory_bytes: 256
n = int(input())
A = list(map(int,input().split()))
B = A.copy()
A_max = max(A)
ans = 100

for i in range(n):
    if B[i] > A_max // 2:
        B[i] = A_max-B[i]

B.sort()
if B[-1] in A:
    print(str(A_max)+" "+str(B[-1]))
else:
    print(str(A_max)+" "+str(A_max-B[-1]))

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

int main(void){
  int N, M;
  cin >> N >> M;
  int A[N][M];
  map<int, int> mp;
  for(int i=0; i<=M; i++) mp[i] = 0;
  for(int i=0; i<N; i++) {
    int Ki;
    cin >> Ki;
    for(int j=0; j<Ki; j++) {
      int tmp;
      cin >> tmp;
      mp[tmp]++;
    }
  }
  int ans = 0;
  for(int i=0; i<=M; i++) if(mp[i] == N) ans++;
  cout << ans << endl;
  return 0;  
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cmath>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <memory>
#include <cstring>
#include <cassert>
#include <numeric>
#include <sstream>
#include <complex>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <cctype>
#include <unordered_map>
#include <unordered_set>
using namespace std;

#define REP2(i, m, n) for (int i = (int)(m); i < (int)(n); i++)
#define REP(i, n) REP2(i, 0, n)
#define ALL(S) (S).begin(), (S).end()

template <typename T, typename E>
ostream &operator<<(std::ostream &os, const std::pair<T, E> &p){
  return os << "(" << p.first << ", " << p.second << ")";
}

typedef long long ll;

const int MAX = 16;

int n, m;
double win[MAX][MAX];
double memo[MAX][1 << MAX];

double rec(int p, int mask){
  if (p == n){
    return 1.0;
  }
  
  if (mask == 0){
    return 0.0;
  }
  
  if (memo[p][mask] > -0.5){
    return memo[p][mask];
  }
  
  double &res = memo[p][mask] = 0;
  
  REP(i, m) if (mask & (1 << i)){
    int nmask = mask  ^ (1 << i);
    double expected = 0;
    double alive    = 1;
    
    REP2(j, p, n){
      expected += alive * (1 - win[i][j]) * rec(j, nmask);
      alive *= win[i][j];
    }
    expected += alive * rec(n, nmask);
    res = max(res, expected);
  }
  
  // cout << p << " " << mask << " " << res << endl;
  return res;
}

int main(){
  ios::sync_with_stdio(false);
  while (cin >> m >> n && n + m){
    REP(i, m) REP(j, n) cin >> win[i][j];
    fill(&memo[0][0], &memo[0][0] + MAX * (1 << MAX), -1);
    cout << fixed << setprecision(20) << rec(0, (1 << m) - 1) << endl;
  }
  return 0;
}

Measured memory_bytes: 9492
#include<stdio.h>
int main() {
	int a, b, c, d, s1, s2;
	scanf("%d %d %d %d", &a, &b, &c, &d);
	s1 = a*b;
	s2 = c*d;
	if (s1 <= s2) {
		printf("%d\n", s2);
	}
	else
		printf("%d\n", s1);
	return 0;
}

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

int main(){
	string s;
	cin >> s;
	string ans = "";
	for (int i = 0; i < s.size(); i++) {
		if (s[i] != 'B') ans += s[i];
		else {
			if (ans != "") ans.erase(ans.size() - 1);
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define F first
#define S second
using namespace std;
typedef long long LL;
typedef pair<int, int> pii;
int main() {
    ios_base::sync_with_stdio(false); cin.tie(0);
    int n; cin >> n;
    cout << ((n - 1) / 1000 + 1) * 1000 - n << '\n';
}

Measured memory_bytes: 3612
import java.io.*;
import java.util.*;


public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		UnionFind UF = new UnionFind(n);
		int m = sc.nextInt();
		for(int i = 0;i < m;i++){
			int num = sc.nextInt();
			int x = sc.nextInt();
			int y = sc.nextInt();
			if(num == 0){
				UF.unite(x,y);
			}else{
				System.out.println(UF.same(x,y) ? 1 : 0);
			}
		}
	}
	public static class UnionFind {
        final int[] data;

        public UnionFind(int size) {
            data = new int[size];
            for (int i = 0; i < size; i++) {
                data[i] = i;
            }
        }

        int find(int x) {
            if (data[x] == x) return x;
            else return data[x] = find(data[x]);
        }

        void unite(int x, int y) {
            data[find(x)] = data[find(y)];
        }

        boolean same(int x, int y) {
            return find(x) == find(y);
        }
    }
//	public Main(){
//		new A().doIt();
//	}
//	class A{
//		void doIt(){
//			
//		}
//	}
}

Measured memory_bytes: 100820
n,k = map(int,input().split())
r,s,p = map(int,input().split())
t = input()
ans = 0
ans_list = [0 for i in range(n)]

for i in range(len(t)):
  if t[i] == 'r':
    if (t[i-k] != 'r') | (ans_list[i-k] == 0):
      ans_list[i] = 1
      ans += p
    else:
      ans_list[i] = 0
      ans += 0
  if t[i] == 's':
    if (t[i-k] != 's') | (ans_list[i-k] == 0):
      ans_list[i] = 1
      ans += r
    else:
      ans_list[i] = 0
      ans += 0
  if t[i] == 'p':
    if (t[i-k] != 'p') | (ans_list[i-k] == 0):
      ans_list[i] = 1
      ans += s
    else:
      ans_list[i] = 0
      ans += 0
      
print(ans)

Measured memory_bytes: 4212