akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <unordered_map>
using namespace std;
using ll = long long;
#define rep(i, j, n) for(int i = (j); i < (n); ++i)
#define rrep(i, j, n) for(int i = (n) - 1; (j) <= i; --i)
constexpr ll MOD = 1000000007;
constexpr ll INF = 1LL << 60;

// 0: 未探索、 1: 探索済み、可能、 2: 探索済み、不可能
int rec(int i, int pos, vector<int> &num, vector<unordered_map<int, int>> &dp) {
	if (i == 0) return pos == 0 ? 1 : 2;
	if (dp[i][pos] != 0) return dp[i][pos];

	int* res = &dp[i][pos];
	int res1 = rec(i - 1, pos + num[i - 1], num, dp);
	int res2 = rec(i - 1, pos - num[i - 1], num, dp);
	*res = res1 == 1 || res2 == 1 ? 1 : 2;
	return *res;
}

int main() {
	cin.tie(0); ios_base::sync_with_stdio(false);
	string s; int x, y;
	cin >> s >> x >> y;
	int n = s.size();
	int r = 0;
	while (r < n && s[r] == 'F') ++r;
	x -= r;

	int t = 0;
	int cnt = 0;
	vector<vector<int>> num(2, vector<int>());
	rep(i, r + 1, n) {
		if (s[i] == 'T') {
			t ^= 1;
			num[t].push_back(cnt);
			cnt = 0;
		}
		else ++cnt;
	}
	num[t ^ 1].push_back(cnt);

	int a = num[0].size();
	int b = num[1].size();
	vector<unordered_map<int, int>> dp1(a + 1), dp2(b + 1);

	if (rec(a, x, num[0], dp1) == 1 && rec(b, y, num[1], dp2) == 1) cout << "Yes";
	else cout << "No";
	return 0;
}


Measured memory_bytes: 176332
D[13][3]={{1,0,0},{0,1,0},{0,0,1},{1,1,0},{1,0,1},{0,1,1},{1,-1,0},{1,0,-1},{0,1,-1},{1,1,1},{-1,1,1},{1,-1,1},{1,1,-1}};
M[9][9][9],q[2];main(n,m,p,I,x,y,z,j,c,d){for(;scanf("%d%d%d",&n,&m,&p),n;){
	for(memset(M,0,sizeof(M)),c=1,I=0;I<p;c*=-1){
		scanf("%d%d",&x,&y),I++;
		for(z=1;;z++)if(!M[x][y][z]){M[x][y][z]=c;break;}
		for(d=0;d<13;d++){
			for(j=0;j<2;j++)for(q[j]=0;q[j]<m;q[j]+=2*j-1)if(M[x+D[d][0]*q[j]][y+D[d][1]*q[j]][z+D[d][2]*q[j]]!=c)break;
			if(q[1]-q[0]-1>=m){printf("%s %d\n",c==1?"Black":"White",I);goto next;}
		}
	}
	puts("Draw");
next:
	for(;I<p;I++)scanf("%d%d",&x,&y);
}exit(0);}

Measured memory_bytes: 608
#include <bits/stdc++.h>
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

using namespace std;

#define rep(i, a, b) for (int i = a; i < b; i++)
#define rrep(i, a, b) for (int i = a; i <= b; i++)
#define all(a)  begin((a)),end((a))
#define uniq(c) (c).erase(unique(all((c))), end((c)))

int main()
{
    int K, N; cin >> K >> N;
    vector<int> A(N);
    rep (i, 0, N) cin >> A[i];

    vector<int> dist;
    rrep (i, 1, N) {
        if (i == N) {
            dist.push_back(abs(K-A[i-1])+A[0]);
            break;
        }
        dist.push_back(abs(A[i-1]-A[i]));
    }

    int max_size = *max_element(dist.begin(), dist.end());

    cout << K - max_size << endl;
}

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

struct Node{
    char key;
    Node *prev, *next;
};

Node *nil;

void init(){
    nil = (Node *)malloc(sizeof(Node));
    nil -> next = nil;
    nil -> prev = nil;
}

void insert(char key, int rev, int F){
    Node *x = (Node *)malloc(sizeof(Node));
    x -> key = key;
    //反転状態かどうかで処理を変える
    if( (rev == 0 && F == 1) || (rev == 1 && F == 2) ){
        x->next = nil->next;
        nil->next->prev = x;
        nil->next = x;
        x->prev = nil;
    }else if( (rev == 0 && F == 2) || (rev == 1 && F == 1)){
        x->prev = nil->prev;
        nil->prev->next = x;
        x->next = nil;
        nil->prev = x;
    }
}


int main(){
    init();

    int rev = 0;
    string s;
    int q, t, f;
    char c;

    cin >> s;
    for(int i = 0; i < s.size(); i++){
        insert(s.at(i), rev, 2);
    }

    //Query
    cin >> q;
    rep(i,q){
        cin >> t;
        if(t == 1){
            rev = 1 - rev; //bit反転
        }else{
            cin >> f >> c;
            insert(c, rev, f);
        }
    }

    //Out put
    Node* x = nil;
    string ans;
    if(rev == 0){
        while(x->next != nil){
            ans.push_back(x->next->key);
            x = x->next;
        }
    }else{
        while(x->prev != nil){
            ans.push_back(x->prev->key);
            x = x->prev;
        }
    }
    
    cout << ans << endl;

    return 0;
}

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

int convert(char a){
	if(a == 'M') return 1000;
	else if(a == 'D') return 500;
	else if(a == 'C') return 100;
	else if(a == 'L') return 50;
	else if(a == 'X') return 10;
	else if(a == 'V') return 5;
	else return 1;
}

int main(){
	string str;
	int res,now,next;
	while(getline(cin,str)){
		res = 0;
		for(int i = 0;i < str.size();++i){
			now = convert(str[i]);
			next = i + 1 == str.size() ? 0 : convert(str[i+1]);
			if(now >= next) res += now;
			else {
				res += (next - now);
				++i;
			}
		}
		cout << res << endl;
	}
}

Measured memory_bytes: 1172
#include<stdio.h>
#include <math.h>
#include<algorithm>
#include<string.h>
using namespace std;
double a,b,x1,x2,y2,y;
int k[1005];
int main()
{
	
	int n,len,sum,n1,n2,flag,i,o,p,ans;
	o=0;
	scanf("%lf%lf",&a,&b);
	x1=(int)(a/0.08);
	x2=(int)((a+1)*12.5)+1;
	y=(int)(b*10);
	y2=(int)((b+1)*10)+1 ;
	flag=0;
	
		for(i=max(x1,y);i<=min(x2,y2);i++)
		{
			o=(int)(i*0.08);
			p=(int)(i*0.1);
			if(o==a&&p==b)
			{
				flag=1;
				ans=i;
				break;
			}
		}
			
		if(flag)
		printf("%d\n",ans);
		else 
		printf("-1\n");
	
	return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>

// output
#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
// utility
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<int(n);++i)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
template<class T> inline T chmax(T & a, const T b) { return a = (a < b) ? b : a; }
template<class T> inline T chmin(T& a, const T b) { return a = (a > b) ? b : a; }

// type/const
#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const int MOD = 1000000007;
/* const int MOD = 998244353; */
const int INF = 1e18;
const double PI = acos(-1);

using namespace std;


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

  vector<int> cnt(26, 0);
  REP(i, H){
    string s;
    cin >> s;
    REP(j, W) cnt[s[j]-'a']++;
  }

  bool ans = true;


  vector<int> requied(3, 0);
  if(H%2 == 1 && W%2 == 1){
    requied[0] = 1; 
    requied[1] = H/2+W/2;; 
  }else if(W%2 == 1){
    requied[1] = H/2;; 
  }else if(H%2 == 1){
    requied[1] = W/2;; 
  }
  requied[2] = (H*W-requied[0]-requied[1]*2)/4;

  vector<int> used(3, 0);
  REP(i, 26){
    if(cnt[i] == 0) continue;
    while(cnt[i] >= 4){
      cnt[i] -= 4;
      used[2]++;
    }
    while(cnt[i] >= 2){
      cnt[i] -= 2;
      used[1]++;
    }
    while(cnt[i] >= 1){
      cnt[i] -= 1;
      used[0]++;
    }
  }

  REP(i, 3){
    if(requied[i] < used[i]) ans = false;
    else if(i != 2){
      requied[i+1] += (requied[i]-used[i])/2;
    }
  }

  ans? Yes: No;

  return 0;
}

Measured memory_bytes: 256
N, K = map(int, input().split())
p = list(map(int, input().split()))

ans = 0
for i in range(N - K + 1):
  if i == 0:
    xe = sum(p[0 : K])
  else:
    xe = xe - p[i - 1] + p[i + K -1]
  x = (xe + K) / 2
  #print(x)
  ans = max(x, ans)
  
print(ans)


Measured memory_bytes: 24548
#include <cstdio>
#include <cstdint>
#include <cctype>
#include <cassert>
#include <map>
#include <vector>
#include <string>
#include <stdexcept>

int parse(const std::string& s, size_t& i,
          const std::map<std::string, int>& mole) {

  int res = 0;
  while (i < s.length() && s[i] != ')') {
    int cur = 0;
    if (s[i] == '(') {
      cur = parse(s, ++i, mole);
      assert(s[i] == ')');
      ++i;
    } else if (isupper(s[i])) {
      cur = mole.at(s.substr(i, 2));
      i += 2;
    } else {
      fprintf(stderr, "%s[%zu]\n", s.c_str(), i);
      assert(false);
    }
    if (isdigit(s[i])) {
      int k = s[i]-'0';
      while (++i < s.length() && isdigit(s[i]))
        k = k*10+s[i]-'0';
      cur *= k;
    }
    res += cur;
  }
  return res;
}

int main() {
  std::map<std::string, int> mole;
  while (true) {
    char buf[4];
    int d;
    scanf("%s %d", buf, &d);
    std::string s = buf;
    if (s.length() == 1) s += '.';
    if (s == "END_OF_FIRST_PART") break;
    mole[s] = d;
  }

  while (true) {
    char buf[128];
    scanf("%s", buf);
    std::string s = buf;
    if (s == "0") break;
    std::string t;
    for (size_t i=0; i<s.length(); ++i) {
      t += s[i];
      if (!isupper(s[i])) continue;
      if (!islower(s[i+1]))
        t += '.';
    }
    try {
      size_t i = 0;
      printf("%d\n", parse(t, i, mole));
    } catch (std::logic_error&) {
      puts("UNKNOWN");
    }
  }
}    



Measured memory_bytes: 2960
n, m = gets.chomp.split(" ").map(&:to_i)
lines = []
m.times do
    inputs = gets.chomp.split(" ").map(&:to_i).map{|v| v-1}
    k = inputs.shift
    lines << inputs
end
term = gets.chomp.split(" ").map(&:to_i)
ans = 0
[0, 1].repeated_permutation(n).each do |bits|
    flag = true
    m.times do |i|
        count = 0
        lines[i].each do |s|
            count += 1 if bits[s-1] == 1
        end
        flag = false if count % 2 != term[i]
    end
    ans += 1 if flag
end
puts ans

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

int main() {
  ll N, K;
  cin >> N >> K;
  ll ans = 0;
  for (ll a = 1; a <= N; a++) {
    if (2 * a % K == 0) {
      ans += ((N + a) / K - (a + 1 + K - 1) / K + 1) *
             ((N + a) / K - (a + 1 + K - 1) / K + 1);
    }
  }
  cout << ans << endl;
}


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

using namespace std;

int main()
{
  string s;
  stringstream ss;

  getline(cin, s);
  ss << s;
  string n;
  int num;
  int max_num=-1000000000;
  int min_num=1000000000;

  while(!ss.eof()){
    ss >> n;
    num=stoi(n);
    if (num > max_num){
      max_num=num;
    }
    if (num < min_num){
      min_num=num;
    }
  }
  cout << min_num << " " << max_num << endl;

  return 0;
}



Measured memory_bytes: 3224
N=int(input())
X=sorted([tuple(map(int,input().split())) for i in range(N)],key=lambda x:x[1])
S=0
for i in range(N):
    S+=X[i][0]
    if S<=X[i][1]:
        pass
    else:
        print("No")
        exit()
print("Yes")


Measured memory_bytes: 33360
N, K  = list(map(int, input().split()))
ans = 0
mod = 10 ** 9 + 7
for k in range(K, N + 2):
    min_sum = (k - 1) * k // 2
    max_sum = (2 * N - k + 1) * k // 2
    ans += max_sum - (min_sum - 1)
print(ans%mod)

Measured memory_bytes: 9188
import sys
input = sys.stdin.readline
n = int(input())
p = [[] for j in range(n)]
for i in range(n):
    ai = int(input())
    for j in range(ai):
        xij, yij = map(int, input().split())
        p[i].append([xij -1, yij])
cands = []
ans = 0
def bits(l):
    if len(l) == n:
        cands.append(l)
        return
    bits(l + [0])
    bits(l + [1])
bits([])
for cand in cands:
    f = 0
    for i, man in enumerate(cand):
        if man:
            for x, y in p[i]:
                if cand[x] != y:
                    f = 1
                    break
        if f:
            break
    if not f:
        ans = max(ans, sum(cand))
print(ans)


Measured memory_bytes: 54108
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <bitset>
# include <complex>
#include<limits.h>
#include<unordered_map>
#include<unordered_set>
#include<deque>
#include<cstdio>
using namespace std;
typedef long long int ll;
const int N = 1000000;
const ll INF = std::numeric_limits<long long>::max();
#define rep(i,n) for(ll i=(ll)0;i<(ll)n;++i)
#define ALL(x) x.begin(),x.end()
#define pp pair<ll,ll>
#define fi first
#define se second
#define sz size
string YN(bool b) { return(b ? "YES" : "NO"); }
string yn(bool b) { return(b ? "Yes" : "No"); }
int main() {
	ll n, k,ans=0;
	cin >> n >> k;
	if (k == 0)ans = n * n;
	else {
		for (ll i = k + 1; i <= n; ++i) {
			ans += (i - k)*(n / i);
			if (n%i >= k)ans += n % i - k + 1;
			//cout << i << "," << ans << endl;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main{

	public static void main(String[] args) {

		Scanner scanner = new Scanner(System.in);

		String[] tmp = scanner.nextLine().split(" ");
		int x = Integer.parseInt(tmp[0]);
		int n = Integer.parseInt(tmp[1]);

		String[] tmp1 = scanner.nextLine().split(" ");
		int[] list = new int[102];
		int a = 0;
		list[0] = 0;
 		for(int i = 0; i < n; i++) {

			a = Integer.parseInt(tmp1[i]);

			list[a]++;

		}

		int ans = 101;
		int count = 101;
		for(int i = 101; i >= 0; i --) {


			if(list[i] != 1) {

				ans = Math.min(ans, Math.abs(x - i));

				if(ans == Math.abs(x - i)) {

					count = Math.min(count, i);

				}
			}

		}

		System.out.println(count);


	}

}


Measured memory_bytes: 35696
//Coded by Abhijay Mitra
#include <iostream>
#include <stdlib.h>
#include <algorithm>
#include <cstdio>
#include <numeric>
#include <cstring>
#include <numeric>
#include <vector>
#include <iterator> 
#include <map>
#include <set>
#include <climits>
#include <queue>
#include <cmath>
#include <stack>
#include <cctype>
#include <bitset>
// #include <bits/stdc++.h>
#define double long double
#define int long long int
#define ll int
#define ibs ios_base::sync_with_stdio(false)
#define cti cin.tie(0)
#define bp __builtin_popcount
#define pb push_back
#define res(v) v.resize(unique(v.begin(), v.end()) - v.begin());
#define cnt_res(v) std::distance(v.begin(),std::unique(v.begin(), v.end())); 
#define timer cerr << "Time elapsed : " << 1.0 * clock() / CLOCKS_PER_SEC << " sec \n";
using vi = std::vector<int>;
using vvi = std::vector<vi>;
using pii = std::pair<int,int>;
using vpii = std::vector<pii>;
using vvpii = std::vector<vpii>;
#define mp         make_pair
#define rep(i,a,b) for (int i = a; i <= b; i++)
#define per(i,b,a) for (int i = b; i >= a; i--)
#define all(x)     x.begin(), x.end()
using namespace std;
const int N=2e6+10;
const int inf = /*0x3f3f3f3f*/1e18+10;
// const ll M = 998244353 ; // Mulo
// const int M = 1e9+7 ; // Mulo
const double Pi = 3.14159265;
#define F first
#define S second
int n;vi v,dp;
int f(int i){
  if(dp[i]!=-1)return dp[i];
  if(i==1)return dp[1]=abs(v[1]-v[0]);
  if(i==2)return dp[2]=min(abs(v[1]-v[0])+abs(v[2]-v[1]),abs(v[2]-v[0]));
  return dp[i]=min(f(i-1)+abs(v[i]-v[i-1]),f(i-2)+abs(v[i]-v[i-2]));
}
void solve(){
  cin>>n;v=vi(n,0);dp=vi(n,-1);dp[0]=0;
  rep(i,0,n-1)cin>>v[i];
  cout<<f(n-1);
}
int32_t main()
{
  ibs;cti;
  solve()
  /*,cout<<"\n"*/;
  // cout<<"\n";
  int xx=0;
  // int t;cin>>t;while(t--){/*xx++;cout<<"Case "<<xx<<":\n"*/;solve();cout<<"\n";}
  return 0;
}

Measured memory_bytes: 4224
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
#include <memory>
#include <regex>
using namespace std;

int main()
{
    int k, a, b;
    cin >> k >> a >> b;

    long long x = 1;
    x += min(k, a - 1);
    k -= min(k, a - 1);

    if(b - a > 1){
        x += (b - a) * (k / 2LL);
        k %= 2;
    }

    x += k;
    cout << x << endl;

    return 0;
}


Measured memory_bytes: 256
X, N = list(map(int, input().split()))
P = list(map(int, input().split()))

P = set(P)

diff = float('INF')
ans = None
for i in range(-100, 102):
    if i in P:
        continue
    d = abs(X - i)
    if d < diff:
        diff = d
        ans = i

print(ans)

Measured memory_bytes: 9116
n=int(input())
h=list(map(int,input().split()))

wrk=0
ans=0
for i in range(n-1,0,-1):
    
    if h[i] <= h[i-1]:
        wrk+=1
    else:
        ans=max(ans,wrk)
        wrk=0
ans=max(ans,wrk)
print(ans)

Measured memory_bytes: 14224
N = int(input())
S = list(input())
dic = {}
MOD = 10 ** 9 + 7
for s in S:
    dic.setdefault(s, 1)
    dic[s] += 1
all = 1
for k, v in dic.items():
    all = all * v
print((all -1) % MOD)

Measured memory_bytes: 49392
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<int,P> P3;
typedef pair<double, P3> P4;
const ll MOD = ll(1e9+7);
const int IINF = INT_MAX;
const ll LLINF = LLONG_MAX;
const int MAX_N = int(3e5 + 5);
const double EPS = 1e-6;
const int di[] = {0, 1, 0, -1}, dj[] = {1, 0, -1, 0};
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define SORT(v) sort((v).begin(), (v).end())
#define ALL(v) (v).begin(), (v).end()

struct UnionFindTree {
    vector<int> par;
    vector<int> rank;
    vector<int> siz;

    void init(int n) {
        par.resize(n);
        rank.resize(n);
        siz.resize(n);
        for (int i = 0; i < n; i++) {
            par[i] = i;
            rank[i] = 0;
            siz[i] = 1;
        }
    }
    int find(int x) {
        if (par[x] == x) {
            return x;
        } else {
            return par[x] = find(par[x]);
        }
    }
    void unite(int x, int y) {
        x = find(x);
        y = find(y);
        if (x == y) return;
        if (rank[x] < rank[y]) swap(x, y);
        if (rank[x] == rank[y]) rank[x]++;
        par[y] = x;
        siz[x] += siz[y];
    }
    bool is_same(int x, int y) {
        return find(x) == find(y);
    }
    int size(int x) {
        x = find(x);
        return siz[x];
    }
};

int main() {
    ll n, m;
    cin >> n >> m;
    vector<P> es;
    REP(i,m){
        int a, b;
        cin >> a >> b;
        a--; b--;
        es.push_back({a,b});
    }
    reverse(ALL(es));
    vector<ll> ans;
    UnionFindTree g;
    ll cnt = n*(n-1)/2;
    g.init(n);
    REP(i,m){
        ans.push_back(cnt);
        int a = es[i].first, b = es[i].second;
        if(g.is_same(a,b))continue;
        cnt -= ll(g.size(a)) * ll(g.size(b));
        g.unite(a,b);
    }
    reverse(ALL(ans));
    REP(i,m){
        cout << ans[i] << " \n";
    }
    return 0;
}


Measured memory_bytes: 4340
#include <stdio.h>

int main(void){
	int x;
	scanf("%d",&x);
	int i;
	int max = 1;
	int temp = 1;
	for(i=2;i<=x;i++){
		if ( (i*i)<=x){
			temp = i*i;
		}
		while ( temp * i <=x){
			temp = temp *i;
		}
		if (max<temp){
			max = temp;
		}
	}
	printf("%d",max);
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <utility>
#include <iomanip>
#include <cmath>
using namespace std;
#define REP(i,n) for (int i=0;i<(n);++i)
#define rep(i,a,b) for(int i=a;i<(b);++i)
template<class T> inline bool chmin(T &a, T b){ if(a > b) { a = b; return true;} return false;}
template<class T> inline bool chmax(T &a, T b){ if(a < b) { a = b; return true;} return false;}
using ll = long long;
constexpr ll INF = 1LL << 60;
constexpr ll MOD = 1e9 + 7;

int table[55];

int main() {
    cin.tie(0); ios_base::sync_with_stdio(false);
    int N,M;cin>>N>>M;
    int a,b;
    REP(i,M){
        cin >> a >> b;
        ++table[a];++table[b];
    }
    rep(i,1,N+1) cout << table[i] << '\n';
    return 0;
}

Measured memory_bytes: 256
N = int(input())
A_list = list(map(int, input().split()))

i = 1
r = 0
while r < N:
  if A_list[r] == i:
    i += 1
    r += 1
  else:
    r += 1

if i == 1:
  print(-1)
else:
  print(N - (i - 1))

Measured memory_bytes: 26268
#include <bits/stdc++.h>
#define For(i, a, b) for(int (i)=(a); (i)<(b); ++(i))
#define rFor(i, a, b) for(int (i)=(a)-1; (i)>=(b); --(i))
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef pair<int, int> pii;
typedef pair<lint, lint> pll;

int n;
pll p[200010];
lint m, M;

lint solve1(){
    set<pll> s;
    rep(i, n){
        if(p[i].fi > p[i].se) swap(p[i].fi, p[i].se);
        s.insert(p[i]);
    }
    lint ret = 1e18;
    rep(i, n){
        ret = min(ret, ((*s.rbegin()).fi - (*s.begin()).fi) * (M-m));
        pll tp = *s.begin();
        if(tp.fi > tp.se) break;
        s.erase(tp);
        s.insert(make_pair(tp.se, tp.fi));
    }
    return ret;
}

lint solve2(){
    lint rM = 0;
    lint bm = 1e18;
    rep(i, n){
      	if(p[i].fi > p[i].se) swap(p[i].fi, p[i].se);
        rM = max(rM, p[i].fi);
        bm = min(bm, p[i].se);
    }
    return (M-bm) * (rM-m);
}

int main(){
    scanf("%d", &n);
    m = 1e18;
    M = 0;
    rep(i, n){
        lint a, b;
        scanf("%lld%lld", &a, &b);
        p[i] = make_pair(a, b);
        m = min({m, a, b});
        M = max({M, a, b});
    }
    printf("%lld\n", min(solve1(), solve2()));
}

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


int n, a, b;
int main() { 
  scanf("%d", &n);
  if (n == 1) {
    cout << "Hello World";
  } else {
    scanf("%d\n%d", &a, &b); 
    cout << a + b;
  }

  return 0;
} 

Measured memory_bytes: 384
#include <iostream>
#include <stdio.h>
#include <algorithm>

using namespace std;
int n,k;
int value[1010];

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

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

    sort(value,value+n);


    int money = 0;

    for (int i = 0; i <= k-1;i ++)
    {
        money += value[i];    
    }

    cout << money << endl;

    return 0;
}

Measured memory_bytes: 3660
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(x,y) for(ll i=x;i<y;i++)
#define vll vector<ll>
#define sll set<ll>
#define pb push_back
#define in insert
#define FAST ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define MOD 1000000007
#define all(x) x.begin(),x.end()
#define tc ll t;cin>>t;while(t--)
#define rev(x) reverse(all(x))
#define low_str(x) transform(all(x),x.begin(),::tolower)
#define up_str(x) transform(all(x),x.begin(),::toupper)
int main()
{
char x;
cin>>x;
x++;
cout<<x;
return 0;
}


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

using namespace std;
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)

typedef long long ll;
typedef pair<ll, ll> P;
const ll INF = 1LL<<60;

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

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

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

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

  int N;
  cin >> N;
  ll x;
  cin >> x;
  vector<ll> a(N);
  rep(i, N) cin>>a[i];

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

  int ans = 0;
  rep(i, N){
    if(x >= a[i]){
      x-=a[i];
      ans++;
    }
  }
  if(ans==N && x > 0){
    ans--;
  }

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) (x).begin(),(x).end()
const int mod=1000000007,MAX=100003,INF=1<<30;

int main(){
    
    double A,B,X;cin>>A>>B>>X;
    double S=X/A;
    
    double left=0.0,right=M_PI/2.0;
    
    for(int i=0;i<300;i++){
        double mid=(left+right)/2.0;
        double l=A*sin(mid),h=B*sin(M_PI/2.0-mid);
        double size;
        
        if(l<=h){
            size=A*B-A*A*tan(mid)/2.0;
        }else{
            size=B*B*tan(M_PI/2.0-mid)/2.0;
        }
        
        if(size>=S) left=mid;
        else right=mid;
    }
    
  if(left==0.0) return 1;
    printf("%.12lf\n",left*90.0/(M_PI/2.0));
    //cout<<setprecision(25)<<left*90.0/(M_PI/2.0)<<endl;
}




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

#ifdef pr16
  #define pr(x)                 cerr << #x << ": " << x << endl;
  #define pr2(x, y)             cerr << #x << ": " << x << " | " << #y << ": " << y << endl;
  #define pr3(x, y, z)          cerr << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": " << z << endl;
  #define pr4(a, b, c, d)       cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << endl;
  #define pr5(a, b, c, d, e)    cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl;
  #define pr6(a, b, c, d, e, f) cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << " | " << #f << ": " << f << endl;
  #define prdd(a,r,c) for(int i=0;i<(r);i++) { for(int j = 0;j<(c);j++) cerr<<a[i][j]<<" "; cerr<<endl; } cerr<<endl;
  #define prc(a) tr(a, it) cerr<<*(it)<<" "; cerr<<endl
  #define pra(a,n) for(int i=0; i<(n); i++) cerr<<((a)[i])<<" "; cerr<<"\n"
  #define prdd(a,r,c) for(int i=0;i<(r);i++) { for(int j = 0;j<(c);j++) cerr<<a[i][j]<<" "; cerr<<endl; } cerr<<endl; 
  #define prddd(a,x,y,z) for(int i=0;i<x;i++) {cerr<<"layer "<<i<<":\n";prdd(a[i],y,z)}
 
#else
  #define pr(x)
  #define pr2(x, y)
  #define pr3(x, y, z)
  #define pr4(a, b, c, d)
  #define pr5(a, b, c, d, e)
  #define pr6(a, b, c, d, e, f)
  #define prc(a)
  #define pra(a,n)
  #define prdd(a, r, c)
  #define prddd(a,x,y,z)
#endif

int st = 0;
int x;


void check (int val, int res) {
	if (x < val and st == 0) {
		st += 1;
		cout << res << "\n";
	}
}

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

    check(600, 8);
    check(800, 7);
    check(1000, 6);
    check(1200, 5);
    check(1400, 4);
    check(1600, 3);
    check(1800, 2);
    check(2000, 1);
 
    return 0;
}

Measured memory_bytes: 3660
// /Code by : Harry_Singh/
#include<bits/stdc++.h>
#define int long long int 
#define io ios_base::sync_with_stdio(false),cin.tie(nullptr);
#define ipair pair<int,int>
#define pb push_back
#define f(i,n) for(int i=0;i<n;i++)
#define F(i,n) for(int i=1;i<=n;i++)
#define mod 1000000007
using namespace std;
#define inf 100000000000000009
#define tr cout<<"\n" 
#define N 205
// directions
int xx[5]={0,0,1,-1};
int yy[5]={1,-1,0,0};
vector<int > G[N],L[N];
 
 
void we_have_choices()
{

   int x,k,d;
   cin>>x>>k>>d;
   if(x<0)x*=-1;
   int a=x/d;
   if(a<k){
    x = x -a*d;
    k = k-a;
    }
    else{cout<<x-k*d;tr;return;}

    if(k%2==0)cout<<x;
    else cout<< abs(x-d);
    tr;

   




}



int32_t main()
{
#ifndef ONLINE_JUDGE
 freopen("input.txt","r",stdin);
 freopen("output.txt","w",stdout);
#endif
    io;
    int t=1;
    while (t--)we_have_choices();
    return 0;
}

Measured memory_bytes: 3652
n=int(input())
array=[]
array+=map(int,input().split())
flag=0
flag2=0
s=1
for m in range(len(array)):
    if array[m]==0:
        flag=1
        break
    s=s*array[m]
    if s>10**18:
        flag2=1
        break
flag3=0
if flag==1:
    print("0")
elif flag2==1:
    for i in range(m,len(array)):
        if array[i]==0:
            flag3=1
            print("0")
    if flag3==0:
        print("-1")

else:print(s)



Measured memory_bytes: 21568
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        
        int X = sc.nextInt();
        int Y = sc.nextInt();
        
        String a = null;
        
        if(Y%2 != 0){
            a = "No";
        } else if(X*2 <= Y && Y <= X*4){
            a = "Yes";
        } else {
            a = "No";
        }
        System.out.println(a);
    }
}


Measured memory_bytes: 35692
#include<bits/stdc++.h>
#include <unistd.h>
using namespace std;
#define nl cout<<"\n"
#define pb push_back
#define se second
#define fi first
#define int long long 
#define pi pair<int,int>
#define vpi vector<pi>
#define vvi vector<vpi>
#define pie =3.14159265358979323846264338327950;
const int mod= 1e9+7;

string ans="";

void back(int i,int j, string &s, string &t, vector<vector<int>> &dp){
	if(i==0 || j==0){
		return ;
	}
	if(s[i-1]==t[j-1]){
		ans.pb(s[i-1]);
		back(i-1,j-1,s,t,dp);
	}
	else{
		if(dp[i-1][j]==dp[i][j]){
			back(i-1,j,s,t,dp);
		}
		else{
			back(i,j-1,s,t,dp);
		}
	}
}

int32_t main(){
	ios_base :: sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	//freopen("input.txt", "r", stdin); 
    //freopen("output.txt", "w", stdout);
	string s,t;
	cin>>s>>t;
	int n=s.length();
	int m=t.length();
	vector<vector<int>> dp(n+1,vector<int>(m+1,0));
	for(int i=0;i<=n;i++){
		dp[i][0]=0;
	}
	for(int i=0;i<=m;i++){
		dp[0][i]=0;
	}
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			if(s[i-1]==t[j-1]){
				dp[i][j]= dp[i-1][j-1]+1;
			}
			else{
				dp[i][j]= max(dp[i][j-1],dp[i-1][j]);
			}
		}
	}
	back(n,m,s,t,dp);
	reverse(ans.begin(),ans.end());
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 73684
a=int(input())
for i in range(a):
    x,y,r=map(int,input().split())
    l=[]
    l.append(x)
    l.append(y)
    l.append(r)
    for t in range(2):
        if l[t]>l[t+1]:
            l[t],l[t+1]=l[t+1],l[t]
    if (l[0]**2)+(l[1]**2)==l[2]**2:
        print("YES")
    else:
        print("NO")
    del l
    


Measured memory_bytes: 5596
#include <bits/stdc++.h>
using namespace std;
#define finish(x) return cout << x << endl, 0
#define ll long long
 
const int N = 200001;
 
int n, X, Y, p[N], fact[N], inv[N], mod = 1e9 + 7;
vector <pair <int, int> > a;
 
int powlog(int a, int b){
    if(b == 0) return 1;
    int ret = powlog(a, b / 2);
    if(b % 2) return 1LL * ret * ret % mod * a % mod;
    return 1LL * ret * ret % mod;
}
int find(int x){
    if(p[x] == x) return x;
    return p[x] = find(p[x]);
}
void join(int x, int y){
    x = find(x);
    y = find(y);
    if(x == y) return;
    p[x] = y;
}
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    fact[0] = 1;
    for(int i = 1 ; i < N ; i++){
        fact[i] = 1LL * fact[i - 1] * i % mod;
    }
    inv[N - 1] = powlog(fact[N - 1], mod - 2);
    for(int i = N - 2 ; i >= 0 ; i--){
        inv[i] = 1LL * inv[i + 1] * (i + 1) % mod;
    }
    cin >> n >> X >> Y;
    a.resize(n);
    for(auto &i : a){
        cin >> i.first >> i.second;
        i.first--;
    }
    sort(a.begin(), a.end(), [&](pair <int, int> l, pair <int, int> r){
        return make_pair(l.second, l.first) < make_pair(r.second, r.first);
    });
    for(int i = 0 ; i < n ; i++){
        p[i] = i;
    }
    for(int i = 1 ; i < n ; i++){
        if(a[i].first != a[0].first && a[i].second + a[0].second <= Y){
            join(0, i);
        }
    }
    int h = 0;
    while(h < n && a[h].first == a[0].first) h++;
    for(int i = 0 ; i < n ; i++){
        if(a[i].first == a[0].first && a[i].second + a[h].second <= Y){
            join(h, i);
        }
    }
    vector <int> mn(n, -1);
    for(int i = 0 ; i < n ; i++){
        if(mn[a[i].first] == -1) mn[a[i].first] = i;
        if(a[i].second + a[mn[a[i].first]].second <= X){
            join(i, mn[a[i].first]);
        }
    }
    map <pair <int, int>, int> cnt;
    for(int i = 0 ; i < n ; i++){
        cnt[make_pair(find(i), -1)]++;
        cnt[make_pair(find(i), a[i].first)]++;
    }
    int ans = 1;
    for(auto &i : cnt){
        if(i.first.second == -1) ans = 1LL * ans * fact[i.second] % mod;
        else ans = 1LL * ans * inv[i.second] % mod;
    }
    cout << ans << endl;
}


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

int A[202];
int n;

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

    int res = 0;
    bool is_odd = false;

    while (true)
    {
        rep(i, n)
        {
            if (A[i] % 2 == 0)
                A[i] /= 2;
            else
                is_odd = true;
        }
        if (is_odd)
            break;
        res++;
    }

    cout << res << endl;
    return 0;
}

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

int main() {
	long n,a,b,i,j,k,ans,cur,res;
	cin >> k >> a >> b;
	for(i=a; i<=b; i++){
		if(i%k==0){
			cout << "OK" << endl; return 0;
		}
	}
	cout << "NG" << endl;
	return 0;
}

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

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

typedef long long ll;

const int INF = 1 << 30;
const ll LLINF = 1LL << 62;

int mod = 1000000007;

int main(void){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int N; cin >> N;
    int ans = 0;
    rep(i, N){
        int a; cin >> a;
        if(i%2 == 0 && a%2 == 1) ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3608
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define all(v) v.begin(),v.end()
#define mem(arr) memset(arr, 0, sizeof(arr))
#define ff first
#define ss second
#define int long long int
const int MOD = 1e9 + 7;
const int INF = 1e18;
const int N = 1e6 + 20;
vector<int> g[N];
vector<int> vis(N);
int32_t main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int tc = 1;
    while(tc--){
        string s;
        cin >> s;
        int n = s.length();
        vector<int> v(n + 1);
        for(int i = 0; i < n; i++){
            if(i == 0){
                if(s[i] == '<'){
                    v[0] = 1;
                }
                continue;
            }
            if(s[i] == '<'){
                v[i] = v[i - 1] + 1;
            }
        }
        for(int &i : v){
            if(i){
                i--;
            }
        }
        for(int i = n - 1; i >= 0; i--){
            if(s[i] == '>'){
                if(i - 1 >= 0){
                    if(s[i - 1] == '>'){
                        v[i] = v[i + 1] + 1;
                    }else{
                        v[i] = max(v[i + 1] + 1, v[i - 1] + 1);
                    }
                }
            }
        }
        if(s[0] == '>'){
            v[0] = v[1] + 1;
        }
        if(s[n - 1] == '<'){
            v[n] = v[n - 1] + 1;
        }
        int sum = 0;
        for(int i : v){
            sum += i;
        }
        cout << sum << '\n';
    }
}
/*
   0 3 2 1 0 1 2 0 1 2 3 4 5 2 1 0 1
    < > > > < < > < < < < < > > > <

    0 1 2 3 4
     < < < <
*/

Measured memory_bytes: 35996
import * as fs from 'fs';

namespace AtCoder.abc001 {

    export class Program {

        constructor(private readonly args: string[]) {
        }

        /**
         * in
         *
         * out
         *
         */
        main(this: Program): void {
            const n: number = +this.args[0];
            const set = new Set();
            for (let i = 1; i <= n; i++) set.add(this.args[i]);
            console.log(set.size);
        }
    }
}

const args: string[] = fs.readFileSync('/dev/stdin', 'utf8').trim().split('\n');
const prg: AtCoder.abc001.Program = new AtCoder.abc001.Program(args);
prg.main();


Measured memory_bytes: 57344
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <ctype.h>




int main(void){
int m,f,r;
for(;;){
    scanf("%d %d %d",&m,&f,&r);
    if(m==-1&&f==-1&&r==-1){break;}
    if(m==-1||f==-1){printf("F\n");}
    else if(m+f>=80){printf("A\n");}
    else if(m+f>=65){printf("B\n");}
    else if(m+f>=50){printf("C\n");}
    else if(m+f>=30&&r>=50){printf("C\n");}
    else if(m+f>=30&&r<50){printf("D\n");}
    else if(m+f<30){printf("F\n");}
}
}






Measured memory_bytes: 2120
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <fstream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <limits>

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

//math
//-------------------------------------------
template<class T> inline T sqr(T x) { return x * x; }

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define EXISTch(s,c) ((((s).find_first_of(c)) != std::string::npos)? 1 : 0)//cがあれば1 if(1)
#define SORT(c) sort((c).begin(),(c).end())

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI = acos(-1.0);
int const INF = INT_MAX;
const LL MOD = (LL)1000000007;//10^9+7
const LL INF2 = (LL)100000000000000000;//10^18

int main() {
	string s; cin >> s;
	int l = s.size();

	LL ans = 0;

	for (int bit = 0; bit < (1 << l - 1); bit++) {
		LL num = s[0] - '0';

		for (int j = 0; j < l - 1; j++) {
			if (bit&(1 << j)) {
				ans += num;
				num = 0;
			}

			num = num * 10 + s[j + 1] - '0';
		}

		ans += num;
	}

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

Measured memory_bytes: 256
#include<stdio.h>
#define N 2000
#define TRUE 1
#define FALSE 0

int n1,a[N];

int search(int cnt,int key){
  int ans;

  if(key==0) return TRUE;
  if(cnt>=n1) return FALSE;

  return ans=search(cnt+1,key)||search(cnt+1,key-a[cnt]);

  }

int main(){
  int i,n2,key;

  scanf("%d",&n1);
  for(i=0;i<n1;i++) scanf("%d",&a[i]);

  scanf("%d",&n2);
  for(i=0;i<n2;i++){
    scanf("%d",&key);
    if(search(0,key)==1) printf("yes\n");
    else printf("no\n");
  }
}


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

namespace test
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = ReadInt();
            var A = ReadArrayInt();
            var B = ReadArrayInt();
            var cnt = 0L;
            for (int i = 0; i < N; i++)
            {
                if (B[i] >= A[i])
                {
                    cnt += A[i];
                    B[i] -= A[i];
                    A[i] = 0;
                }
                else if (B[i] < A[i])
                {
                    cnt += B[i];
                    A[i] -= B[i];
                    B[i] = 0;
                }
                if (B[i] >= A[i + 1])
                {
                    cnt += A[i + 1];
                    B[i] -= A[i + 1];
                    A[i + 1] = 0;
                }
                else if (B[i] < A[i + 1])
                {
                    cnt += B[i];
                    A[i + 1] -= B[i];
                    B[i] = 0;
                }
            }

            Console.WriteLine(cnt);
            Console.ReadLine();
        }

        static string Read() { return Console.ReadLine(); }
        static int ReadInt() { return int.Parse(Read()); }
        static long ReadLong() { return long.Parse(Read()); }
        static int[] ReadArrayInt() { return Read().Split(' ').Select(s => int.Parse(s)).ToArray(); }
        static long[] ReadArrayLong() { return Read().Split(' ').Select(s => long.Parse(s)).ToArray(); }
    }
}

Measured memory_bytes: 34268
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7 # 998244353
input=lambda:sys.stdin.readline().rstrip()
def resolve():
    n, k = map(int,input().split())
    n %= k
    print(min(n, k - n))
resolve()

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

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

int MOD = 1e9 + 7;
ll INF = 1e18;

int main() {
    int a, b, c; cin>>a>>b>>c;
    int a1 = abs(a-b)+abs(b-c);
    int a2 = abs(a-c)+abs(c-b);
    int a3 = abs(b-a)+abs(a-c);
    int a4 = abs(b-c)+abs(c-a);
    int a5 = abs(c-a)+abs(a-b);
    int a6 = abs(c-b)+abs(b-a);
    cout << min(min(a1, min(a2, a3)), min(a4, min(a5, a6))) << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long int
using namespace std;
signed main()
{
	int t=1;
	// cin>>t;
	while(t--)
	{
		string s,t;
		cin>>s>>t;
		int ans=INT_MAX;
		for(int i=0;i<=s.size()-t.size();i++)
		{
			int count=0;
			int k=i;
			for(int j=0;j<t.size();j++)
			{
			    if(s[k]!=t[j])
			    	count++;
			    k++;
			}
			ans=min(ans,count);
		}
		cout<<ans;
	}
}


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

int main(){
    while (1){
        int x,y;
        cin>>x>>y;
        if (x==0 and y==0) {
            break;
        } else if (x<y){
            cout<<x<<" "<<y<<endl;
        }else{
            cout<<y<<" "<<x<<endl;
        }
    }
    return 0;
}


Measured memory_bytes: 3096
nm=list(map(int,input().split()))
low=1
high=nm[0]
for i in range(nm[1]):
    lr=list(map(int,input().split()))
    low=max([low,lr[0]])
    high=min([high,lr[1]])
k=high-low+1
if k<0:
    k=0
print(k)

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

//typedef
//------------------------------------------
typedef long long LL;
typedef vector<LL> VL;
typedef vector<VL> VVL;
typedef vector<string> VS;
typedef pair<LL, LL> PLL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int MOD = 1000000007;

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

//main code

int main(int argc, char const* argv[])
{
	int n;
	cin >> n;
	VL a(n);
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}

	LL res = 0,right = 0,sum = 0;
	for (int left = 0; left < n; left++) {
		while (right < n and (sum ^ a[right]) == (sum + a[right])) {
			sum += a[right];
			right++;
			// 現在のsumに対してrightの位置の和とxorが一致したら
			// sumを更新(rightの位置の数値を加える)
			// rightをインクリメント
		}
		res += right - left;
		// xorが一致しなくなったら or rightがnになったらwhileループを抜けて
		// 答えresにright - leftを足す
		if (left == right) {
			right++;
		}
		else {
			sum -= a[left];
		}
			// leftとrightが等しい -> 最初(left = right = 0)から1ステップ目では必ずrightは1つ進む
			//					   -> left = 0,right = 1になるから,sum -= a[0]で,leftのところが引かれる
	}
	cout << res << endl;
	return 0;
}


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

using namespace std;
#define lint long long

int main() {
    int N, W;
    cin >> N >> W;
    
    const lint INF = 10000000000000;
    int w[N], v[N];
    
    for(int i = 0; i < N; ++i){
        cin >> w[i] >> v[i];
    }
    
    lint dp[N * 1000 + 1];
    for(int i = 0; i < N * 1000 + 1; ++i){
        dp[i] = INF;
    }
    dp[0] = 0;
    
    for(int i = 0; i < N; ++i){
        for(int j = N * 1000 - v[i]; j >= 0 ; --j){
            if(dp[j] <= W - w[i]){
                dp[j + v[i]] = min(dp[j + v[i]], dp[j] + w[i]);
            }
        }
    }
    lint ans = 0;
    for(int i = N * 1000 ; i >= 0; --i){
        if(dp[i] < INF){
            ans = i;
            break;
        }
    }
    cout << ans << endl;
}


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

int main() {
  int N;
  cin >> N;
  int r =0;
  if(N%10==2)r++;
  N/=10;
  if(N%10==2)r++;
  N/=10;
  if(N%10==2)r++;
   if(N/10==2)r++;
   cout << r << endl; 
}


Measured memory_bytes: 256
(N, M), *ABs = readlines.map{_1.split.map(&:to_i)}

g = ABs.each_with_object(Array.new(N + 1){[]}){|(a, b), g|  g[a] << b; g[b] << a}
ans = Array.new(N + 1, nil); ans[1] = 0
q = [1]
while !q.empty?
  u = q.shift
  g[u].select{ans[_1].nil?}.each do |v|
    q << v
    ans[v] = u
  end
end
puts ['Yes'] + ans[2, N - 1]

Measured memory_bytes: 66552
N=int(input())

x=55555
import math 
L=math.floor(math.sqrt(x))#平方根を求める

Primelist=[i for i in range(x+1)]
Primelist[1]=0#1は素数でないので0にする.
 
for i in Primelist:
    if i>L:
        break
    if i==0:
        continue
    for j in range(2*i,x+1,i):
        Primelist[j]=0

Primes=[Primelist[j] for j in range(x+1) if Primelist[j]!=0]

ANS=[]
for p in Primes:
    if p%10==1:
        ANS.append(p)

for i in range(N):
    print(ANS[i],end=" ")

Measured memory_bytes: 5400
#include <bits/stdc++.h>
using namespace std;
using vec = vector<int>;
using intk = int64_t;

int main() {
int a,b,c,x;
  cin >>a>>b>>c>>x;
  int ans =0;
  for(int i=0;i<=a;i++){
  for(int j=0;j<=b;j++){
   for(int k=0;k<=c;k++){
if(x == 500*i+100*j+50*k) ans++;
     
   }
  }
  }
  cout << ans << endl;
}

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

int main(void) {
  int X, Y;
  cin >> X >> Y;
  long long money = 0;
  money += max(0, (4 - X) * 100000);
  money += max(0, (4 - Y) * 100000);
  money += (X == 1 && Y == 1) ? 400000 : 0;
  cout << money << endl;
  return 0;
}

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

using namespace std;

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

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

int main(){
    int N,M;
    cin >> N >> M ;

    auto G = vector<vector<int>>(N);
    FOR(i,0,M){
        int a,b;
        cin >> a >> b ;
        a--;b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }

    int s=0,t=G[s][0];
    auto path = vector<int>();
    path.push_back(s);
    path.push_back(t);
    auto visited = vector<int>(N);
    FOR(i,0,N){
        visited[i] = 0;
    }
    visited[s] = 1;
    visited[t] = 1;

    int solved[2] = {0,0};

    while(!solved[0] || !solved[1]){
        if(!solved[0]){
            int changed = 0;
            FOR(n, 0, G[s].size()){
                if(visited[G[s][n]])
                    continue;
                visited[G[s][n]] = 1;
                s = G[s][n];
                path.insert(path.begin(), s);
                changed = 1;
                break;
            }
            if(!changed)
                solved[0] = 1;
        }

        if(!solved[1]){
            int changed =0 ;
            FOR(n, 0, G[t].size()){
                if(visited[G[t][n]])
                    continue;
                visited[G[t][n]] = 1;
                t = G[t][n];
                path.push_back(t);
                changed = 1;
                break;
            }
            if(!changed)
                solved[1] = 1;
        }
    }

    cout << path.size() << endl;
    for(auto i : path){
        cout << i+1 << " ";
    }
    cout << endl;

    return 0;
}


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


def solve(N: int, l: "List[int]", r: "List[int]"):
    ret = 0
    for i in range(N):
        ret += r[i] - l[i] + 1
    print(ret)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    l = [int()] * (N)  # type: "List[int]" 
    r = [int()] * (N)  # type: "List[int]" 
    for i in range(N):
        l[i] = int(next(tokens))
        r[i] = int(next(tokens))
    solve(N, l, r)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
k, n = map(int, input().split())
l = list(map(int, input().split()))
d = []
for i in range(n):
  if i+1<n:
    d.append(abs(l[i+1]-l[i]))
  else:
    if 0 in l:
      d.append(abs(k - l[i]))
    else:
      d.append(abs(k - l[i] + l[0]))
print(sum(d)-max(d))

Measured memory_bytes: 26600