akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Linq;
using System.Collections.Generic;
using System.Text;

namespace Program
{
    public class ABC084D
    {
        static public void Main(string[] args)
        {
            var prime = new HashSet<int>(Prime(10000000).ToArray());
            var sumary = new int[100001];
            for (int i = 1; i <= 100000; ++i)
            {
                if (prime.Contains(i) && prime.Contains((i + 1) / 2))
                {
                    sumary[i] = 1;
                }
                sumary[i] += sumary[i - 1];
            }

            var Q = NextInt;
            for (int i = 0; i < Q; ++i)
            {
                var l = NextInt;
                var r = NextInt;
                Console.WriteLine(sumary[r] - sumary[l - 1]);
            }
        }

        static class Console_
        {
            private static Queue<string> param = new Queue<string>();
            public static int NextInt() => int.Parse(NextString());
            public static long NextLong() => long.Parse(NextString());
            public static string NextString()
            {
                if (param.Count == 0) foreach (var item in Console.ReadLine().Split(' ')) param.Enqueue(item);
                return param.Dequeue();
            }
        }
        static int NextInt => Console_.NextInt();
        static long NextLong => Console_.NextLong();
        static string NextString => Console_.NextString();

        static IEnumerable<int> Prime(int x)
        {
            if (x < 2) yield break;
            yield return 2;
            var halfx = x / 2;
            var table = new bool[halfx + 1];
            var max = (int)(Math.Sqrt(x) / 2);
            for (int i = 1; i <= max; ++i)
            {
                if (!table[i])
                {
                    var add = 2 * i + 1;
                    yield return add;
                    for (int j = 2 * i * (i + 1); j <= halfx; j += add)
                    {
                        table[j] = true;
                    }
                }
            }
            for (int i = max + 1; i <= halfx; ++i)
            {
                if (!table[i]) yield return 2 * i + 1;
            }
        }
    }
}


Measured memory_bytes: 31328
#include <iostream>
int main() {
	int a, b, c, _;
	std::cin >> a >> b >> c;
	int x[] = {a, b, c};
	for (int i = 0; i < 2; i++)
		for (int j = 0; j < 2 - i; j++)
			x[j] > x[j + 1] ? _ = x[j], x[j] = x[j + 1], x[j + 1] = _ : 0;
	for (int i = 0; i < 3; i++)
		i == 2 ? std::cout << x[i] << "\n" : std::cout << x[i] << " ";
	return 0;
}


Measured memory_bytes: 3124
import java.util.Scanner;
import java.util.StringTokenizer;

public class Main {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();
		while (n-- > 0) {
			StringTokenizer tokenizer = new StringTokenizer(scanner.next(), ":");
			double h = Double.parseDouble(tokenizer.nextToken());
			double m = Double.parseDouble(tokenizer.nextToken());
			double a = (h * 5 + m / 12) * 6;
			double b = Math.abs(a - (m * 6));
			b = Math.min(b, 360 - b);
			if (b < 30)
				System.out.println("alert");
			else if (b < 90)
				System.out.println("warning");
			else
				System.out.println("safe");

		}
	}
}

Measured memory_bytes: 19188
package main

import "fmt"

func main() {
	// Code for A - B +/- A
	var A, B int
	fmt.Scanf("%d %d", &A, &B)
	if B%A == 0 {
		fmt.Println(A + B)
	} else {
		fmt.Println(B - A)
	}
}


Measured memory_bytes: 1828
import java.util.*;

class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    
    int n = sc.nextInt();
    int k = sc.nextInt();
    String s = sc.next();
    if (s.charAt(k-1) == 'A'){
      System.out.println(s.substring(0,k-1)+"a"+s.substring(k));
    }
    if (s.charAt(k-1) == 'B'){
      System.out.println(s.substring(0,k-1)+"b"+s.substring(k));
    }
    if (s.charAt(k-1) == 'C'){
      System.out.println(s.substring(0,k-1)+"c"+s.substring(k));
    }
  }
}

Measured memory_bytes: 21716
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

int main(void)
{
  double d,t,s;
  scanf("%lf %lf %lf",&d,&t,&s);

  if(d/s<=t) printf("Yes\n");
  else printf("No\n");

  return 0;
}


Measured memory_bytes: 1680
#include <bits/stdc++.h>
using namespace std;
int main(){

int n;
cin >> n;
vector<char> S(n);

for(int i = 0;i < n;i++){
    cin >> S.at(i);
} 

int count = 0;

for(int i = 0;i < n-2;i++){
    if(S.at(i) == 'A'){
        if(S.at(i+1) == 'B'){
            if(S.at(i+2) == 'C'){
                count++;
            }
        }
    }
}


cout << count << endl;
return 0;
}

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

int main(){
    int n;
double b=1,summ=0;
double ans;
cin>>n;
int a[n];
for (int i=0;i<n;i++){
    cin>>a[i];
    b=b*a[i];
    }

for (int i=0;i<n;i++){
    summ=summ+(b/a[i]);
}

    ans=b/summ;
    cout<<ans;


}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
typedef long long ll;
ll mod = 1000000007;

ll dp[2000][2000];
ll p[10000];
ll q[10000];

ll calc(ll a,ll b){
    if(b==0)return 1;
    if(b==1)return a;
    if(b%2==0){
        ll k = calc(a,b/2);
        return k*k%mod;
    }else{
        ll k = calc(a,b/2);
        k *=k;
        k %= mod;
        return k*a %mod;
    }
}

int main(){
    int n,a,b,c,d;
    cin >> n >> a >> b >> c >> d;
    p[0]=1;
    for(int i=1;i<=n;i++){
        p[i] =p[i-1]*i%mod;
    }
    q[n] = calc(p[n],mod-2);
    for(ll i=n-1;i>=0;i--){
        q[i] = q[i+1]*(i+1)%mod;
    }
    dp[a-1][0] = 1;
    
    for(int i=a;i<=b;i++){
        for(int j=0;j<=n;j++){
            dp[i][j] += dp[i-1][j];
            dp[i][j]%=mod;
            for(int k=c;k<=d;k++){
                if(j-i*k<0)break;
                ll tmp = q[k]*calc(q[i],k)%mod;
                dp[i][j] += dp[i-1][j-i*k]*tmp%mod;
                dp[i][j] %= mod;
            }
        }
    }
    cout << p[n]*dp[b][n]%mod << endl;
    return 0;
}

Measured memory_bytes: 16128
#include <stdlib.h>
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
using ll=long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
inline constexpr ll gcd(ll a,ll b){if(!a||!b)return 0;while(b){ll c=b;b=a%b;a=c;}return a;}
inline constexpr ll lcm(ll a,ll b){if(!a||!b)return 0;return a*b/gcd(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;
}
const long long INF=1LL << 60;
long long a,b;
long long dp[100200][110];
long long w[110],v[110];


int main(){
  int a;
  cin>>a;
  vector<int> vec(a);
  rep(i,a){
      cin>>vec.at(i);
  }
  int ans=0;
  bool flag=true;
  while(flag){
      int p;
      int cou=0;
      rep(i,a){
          if(vec.at(i)==0){
              cou++;
          }
      }
      if(cou==a){
          break;
      }
      rep(i,a){
          if(vec.at(i)>0){
              p=i;
              //cout<<p<<endl;
              break;
          }
      }
      for(int i=p;i<a;i++){
          if(vec.at(i)>0){
              vec.at(i)--;
          }
          else{
              break;
          }
      }
      ans++;
  }
  cout<<ans<<endl;
}



Measured memory_bytes: 256
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <functional>
#include <bits/stdc++.h>
using namespace __gnu_pbds;
using namespace std;

typedef tree<int, null_type, less<int>, rb_tree_tag,tree_order_statistics_node_update>	tree_set;
typedef long long ll;
typedef long double ld;
void fast()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
}

ll mod=1e9 + 7;

int main()
{
    fast();
    string str;
    cin>>str;
    cout<<str[0];
    cout<<str.length()-2;
    cout<<str[str.length()-1];
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
	int arr[5];
	for(int i=0;i<5;i++){
		cin>>arr[i];
		if(arr[i]==0){
			cout<<i+1<<endl;
		}
	}
	return 0;
}

Measured memory_bytes: 3536
// AOJ 2428: Lost Number
// 2017.10.19 bal4u@uu

#include <stdio.h>
#include <string.h>

#define MAX 1024

char q[10002][102]; int top;

char *expr();
char *factor(char *s, char *p, int *z, int *op)
{
	int x, k;

	if (*p == '(') {
		k = 0;
		if ((p = expr(s, p+1, &x, &k)) == NULL) return NULL;
		if (!k || (*p != ')' && *p != '.')) return NULL;
		p++;
		*op = 0;
	} else if (*p == '1' || *p == '0' || *p == '.') {
		x = 0;
		while (*p == '1' || *p == '0') x = (x << 1) + (*p++ - '0');
		while (*p == '.') {
			strcpy(q[top], s), q[top++][p-s] = '1';
			strcpy(q[top], s), q[top++][p-s] = '0';
			strcpy(q[top], s), q[top++][p-s] = '+';
			strcpy(q[top], s), q[top++][p-s] = '-';
			strcpy(q[top], s), q[top++][p-s] = '*';
			strcpy(q[top], s), q[top++][p-s] = '(';
			strcpy(q[top], s), q[top++][p-s] = ')';
			x = (x << 1) + 1, p++;
		}
		while (*p == '1' || *p == '0') x = (x << 1) + (*p++ - '0');
		*op = 0;
	} else return NULL;
	if (x < 0 || x >= MAX) return NULL;
	*z = x;
	return p;
}

char *term(char *s, char *p, int *z, int *op)
{
	int x, y, k = 0;

	if ((p = factor(s, p, &x, &k)) == NULL) return NULL;
	while (1) {
		if (*p == '.') {
			strcpy(q[top], s), q[top++][p-s] = '*';
			strcpy(q[top], s), q[top++][p-s] = '+';
			strcpy(q[top], s), q[top++][p-s] = '-';
			break;
		} else if (*p == '*') ;
		else break;
		if ((p = factor(s, p+1, &y, &k)) == NULL) return NULL;
		x *= y, k = 1;
		if (x < 0 || x >= MAX) return NULL;
	}
	*z = x;
	*op = k;
	return p;
}

char *expr(char *s, char *p, int *z, int *op)
{
	int x, y, t, k = 0;
	
	if ((p = term(s, p, &x, &k)) == NULL) return NULL;
	while (1) {
		if (*p == '.') {
			strcpy(q[top], s), q[top++][p-s] = '*';
			strcpy(q[top], s), q[top++][p-s] = '+';
			strcpy(q[top], s), q[top++][p-s] = '-';
			break;
		} else if (*p == '+') t = 1;
		else if (*p == '-') t = 0;
		else break;
		if ((p = term(s, p+1, &y, &k)) == NULL) return NULL; 
		if (t) x += y;
		else   x -= y;
		k = 1;
		if (x < 0 || x >= MAX) return NULL;
	}
	*z = x;
	*op = k;
	return p;
}

int main()
{
	int n, op, ans;
	char *p;

	scanf("%s", q[0]);
	ans = -1, top = 1;
	while (top > 0) {
		top--;
		if ((p = expr(q[top], q[top], &n, &op)) == NULL) continue;
		if (*p) continue;
		if (n >= 0 && n < MAX && n > ans) ans = n;
	}
	printf("%d\n", ans);
	return 0;
}

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

typedef uint64_t u64;
typedef int64_t i64;
typedef uint32_t u32;
typedef int32_t i32;
typedef uint16_t u16;
typedef int16_t i16;
typedef uint8_t u8;
typedef int8_t i8;

using namespace std;

#define rep(idx, N) for (u64 idx = 0; idx < N; idx++)

int main() {
  u32 n;
  vector<i32> h;
  cin >> n;

  rep(i, n) {
    u32 hi;
    cin >> hi;
    h.push_back(hi);
  }

  vector<u32> dp(n, UINT32_MAX);

  dp[0] = 0;
  dp[1] = dp[0] + abs(h[0] - h[1]);
  for (u32 i = 2; i < n; i++) {
    dp[i] =
        min(dp[i - 1] + abs(h[i - 1] - h[i]), dp[i - 2] + abs(h[i - 2] - h[i]));
  }

  cout << dp[n - 1];

  return 0;
}


Measured memory_bytes: 3920
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <cstring>
using namespace std;
const int maxn = 2e5+2;
long long num[maxn];
int main(){
    int n;
    scanf("%d",&n);
    memset(num, 0, sizeof(num));
    for(int i = 0; i < n; i++){
        scanf("%lld",&num[i]);
        if(i != 0)
            num[i] += num[i-1];//前缀和
    }
    sort(num,num+n);//从小到大排序
    long long ans = 0;//最终答案
    long long pair = 0;//前缀和相等的对数
    if(num[0]==0)//单独考虑，因为下面有i-1
        ans++;
    for(int i = 1; i < n; i++){
        if(num[i] == 0)
            ans++;
        if(num[i] == num[i - 1])//因为排好序，相等的必然是连续的
            pair++;
        if(num[i] != num[i - 1] && pair || i == n - 1 && pair){//一旦不相等了，就处理一次
            ans += (pair + 1) * pair / 2;//比如说有两对相等的，那么就是num[i-1],num[i],num[i+1],每两个之间的和都为0，就是组合数C(pair+1,2)
            pair = 0;//置为0，免得干扰后面的
        }
    }
    printf("%lld\n", ans);
return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep1(i, n) for (int i = 1; i < (n); ++i)
using namespace std;
typedef long long ll;
const ll INF = 1LL << 60;

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

    string s;
    cin >> s;
    int n = s.size();

    vector<int> abc(3, 0);
    rep(i, n) ++abc[s[i] - 'a'];

    if(n <= 3){
        if(n==1) puts("YES");
        if(n==2){
            if(abc[0]<2 && abc[1]<2 && abc[2]<2) puts("YES");
            else puts("NO");
        }
        if(n==3){
            if(abc[0]==1 && abc[1]==1 && abc[2]==1) puts("YES");
            else puts("NO");
        }

        return 0;
    }
    
    if(max({abc[0], abc[1], abc[2]}) - min({abc[0], abc[1], abc[2]}) < 2) puts("YES");
    else puts("NO");

    return 0;
}

Measured memory_bytes: 512
#include<iostream>
#include<vector>
#include<map>
#include<algorithm>
#include<math.h>
#include<string>
#include <iomanip>
#include<deque>

typedef long long ll;
typedef unsigned long long ull;
typedef int itn;
const ll LINF = 1e18;
const int INF = 1e8;

using namespace std;


//マクロ定義
#define vvint(vec,n,m,l) vector<vector<int>> vec(n, vector<int>(m,l));	// lで初期化
#define vvll(vec,n,m,l) vector<vector<ll>> vec(n,vector<ll>(m,l));
#define vint vector<int>
#define pint pair<int,int>
#define rep(i,a) for(int i=0;i<(a);i++)
#define all(x) (x).begin(),(x).end()
#define debug system("pause")				//デバッグ用

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

	int n;
	cin >> n;
	vector<pair<ll, ll>> b(n);
	ll sigoto = 0;

	bool muri = false;

	rep(i, n)
	{
		cin >> b[i].second >> b[i].first;
	}

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

	sigoto = b[0].first - b[0].second;
	if (sigoto < 0)
	{
		muri = true;
	}

	for(int i=1;i<n;i++)
	{
		sigoto += (b[i].first-b[i-1].first) - b[i].second;
		if (sigoto < 0)
		{
			muri = true;
			break;
		}
	}

	if (muri)
	{
		cout << "No" << endl;
	}
	else
	{
		cout << "Yes" << endl;
	}

}

Measured memory_bytes: 3456
#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0); cout.tie(0);
  int x;
  cin >> x;
  int ans = ((x%500)/5)*5 + (x/500)*1000;
  cout << ans << '\n';
  return 0;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-

def readInts():
  return [int(s) for s in input().split(" ")]

def is_on(L, i):
  if L & (1 << (i-1)):
    return True
  else:
    return False

def is_ok(L, s, p):
  c = 0
  for i in s:
    if is_on(L, i):
      c += 1
  return (c % 2) == p

def main():
  N, M = readInts()
  S = []
  for _ in range(M):
    data = readInts()
    S.append(data[1:])
  P = readInts()

  ans = 0
  for L in range(2**N):
    ok = True
    for i, s in enumerate(S):
      if not is_ok(L, s, P[i]):
        ok = False
        break
    if ok:
      ans += 1

  print(ans)

if __name__ == "__main__":
  main()


Measured memory_bytes: 3064
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_poizcy.hpp>
typedef long long  ll;
#define pb                push_back
#define mp                make_pair
#define all(a)            (a).begin(), (a).end()
#define mem(a,h)          memset(a, (h), sizeof(a))
#define fi first
#define se second
#define por(a,b) (((a%MOD) * (b%MOD))%MOD)
#define forg(i, b, e, c)    for (ll i = (ll)b; i < (ll)e; i+=c)
#define forr(i, b, e)    for (int i = b; i < e; i++)
 
 
using namespace std;
//using namespace __gnu_pbds;
typedef long double lldb;
typedef pair<ll, ll>  ii;
typedef pair<lldb, lldb>  iidb;
typedef pair<ll, ii>  iii;
typedef vector<ll>     vi;
typedef vector<ll>      vll;
//typedef tree<ii,null_type,less<ii>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
const ll INF = 1e9+7;
const lldb PI = acos(-1);
#define initseg ll new_nodo=(nodo*2),mid=(iz+der)/2;
 
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define tam 2020000
#define offset 200
#define ptr nodo*
const ll MOD=1e9+7;
#define lazy first
#define sum second
int vmin[tam],viz[tam],vder[tam];
int main()
{
	forr(i,0,tam)
	vmin[i]=INF;
	int H,W;
	cin>>H>>W;
	map<int,int> mapa;
	multiset<int> mins;
	forr(i,1,W+1){
		mapa[i]=0;
		mins.insert(0);
	}

	forr(i,0,H)
	{
		cin>>viz[i]>>vder[i];
		auto iteiz=mapa.lower_bound(viz[i]);
		int minimo=INF;
		while(iteiz!=mapa.end())
		{
			if (iteiz->fi>vder[i])
				break;
			minimo=min(minimo,iteiz->se+(vder[i]+1)-iteiz->fi);
			auto elim=iteiz;
			mins.erase(mins.find(elim->se));
			iteiz++;
			mapa.erase(elim);
		}
		//if (minimo==INF)continue;
		if (vder[i]+1<=W && minimo!=INF){
			if (mapa.find(vder[i]+1)==mapa.end())
			{
				mapa[vder[i]+1]=minimo;
				mins.insert(minimo);
			}
			else
			{
				if (mapa[vder[i]+1]>minimo)
				{
					mins.erase(mins.find(mapa[vder[i]+1]));
					mins.insert(minimo);
					mapa[vder[i]+1]=minimo;
				}
			}
		}
		
		if (!mins.empty())
		cout<<(*mins.begin())+i+1<<endl;
		else
		cout<<-1<<endl;

	}
}

Measured memory_bytes: 31832
import sys
IS = lambda: sys.stdin.readline().rstrip()
II = lambda: int(IS())
MII = lambda: list(map(int, IS().split()))
MIIZ = lambda: list(map(lambda x: x-1, MII()))

def dfs(g,e,now,ret):
    e[now] = True
    if all(e): ret += 1
    for next in g[now]:
        if e[next]: continue
        ret = dfs(g,e,next,ret)
    e[now] = False
    return ret

def main():
    n, m = MII()
    g = {i: [] for i in range(n)}
    for _ in range(m):
        x, y = MIIZ()
        g[x].append(y)
        g[y].append(x)
    ret = 0
    e = [False]*n
    e[0] = True
    ret = dfs(g,e,0,ret)
    print(ret)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <cmath>
#include <iomanip>
#include <queue>
#include <algorithm>
#define shosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=(1<<31)-1;
const double pi=acos(-1);

int N,M;
vector<ll> a,b,c,dp;
ll tmp=0;

int main(){
	cin>>N;
	a=vector<ll>(N);
	for(int i=0;i<N;i++) cin>>a[i];
	cin>>M;
	b=vector<ll>(M);
	c=vector<ll>(M);
	for(int i=0;i<M;i++){
		cin>>b[i];
		tmp=max(tmp,b[i]);
	}
	dp=vector<ll>(tmp+1);
	for(int i=0;i<M;i++) cin>>c[i];
	sort(a.begin(),a.end());
	for(int i=1;i<=tmp;i++){
		dp[i]=dp[i-1]+i*(upper_bound(a.begin(),a.end(),i)-lower_bound(a.begin(),a.end(),i));
	}
	for(int i=0;i<M;i++){
		if(dp[b[i]]>=c[i]) cout<<"Yes"<<endl;
		else cout<<"No"<<endl;
	}
}

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

struct st {
	int p, a, c, s;
};
bool operator<(st a, st b) {
	return a.c > b.c;
}
int d[5001][1 << 5][5], x[5001], y[5001], len[5], t[5][1001];
char c[1001];

int main() {
	int w, h;
	while (scanf("%d%d", &w, &h), w) {
		int sx, sy, gx, gy, s = 0;
		memset(len, 0, sizeof(len));
		memset(d, 0x3f, sizeof(d));
		priority_queue<st>que;
		rep(i, h) {
			scanf("%s", c);
			rep(j, w) {
				if ('1' <= c[j] && c[j] <= '5') {
					c[j] -= '1'; len[c[j]]++;
					t[c[j]][len[c[j]]] = ++s;
					x[s] = i; y[s] = j;
				}
				if (c[j] == 'S') {
					x[0] = i; y[0] = j;
					rep(k, 5) {
						d[0][1 << k][k] = 0;
						que.push({ 0,1 << k,0,k });
					}
				}
				if (c[j] == 'G')gx = i, gy = j;
			}
		}
		while (!que.empty()) {
			st p = que.top(); que.pop();
			if (d[p.p][p.a][p.s] != p.c)continue;
			rep(i, 5) {
				if ((p.a >> i & 1) || !(p.a >> ((i + 4) % 5) & 1))continue;
				for (int j = 1; j <= len[i]; j++) {
					int&o = d[t[i][j]][p.a | 1 << i][p.s],
						u = p.c + abs(x[p.p] - x[t[i][j]]) + abs(y[p.p] - y[t[i][j]]);
					if (o > u) {
						o = u; que.push({ t[i][j],p.a | 1 << i,o,p.s });
					}
				}
			}
		}
		int Min = INF, id;
		rep(i, s + 1) {
			rep(j, 5) {
				int cost = d[i][(1 << 5) - 1][j] + abs(x[i] - gx) + abs(y[i] - gy);
				if (cost < Min)Min = cost, id = j + 1;
				else if (cost == Min)id = min(id, j + 1);
			}
		}
		if (Min == INF)puts("NA");
		else printf("%d %d\n", id, Min);
	}
}

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

signed main(){
    int N, K; cin >> N >> K;
    vector<int> a(N);
    for(int i = 0; i < N; i++) cin >> a[i];
    int g = a[0];
    for(int i = 1; i < N; i++) g = __gcd(g, a[i]);
    int num = *max_element(a.begin(), a.end());
    if(num >= K && K % g == 0) cout << "POSSIBLE" << endl;
    else cout << "IMPOSSIBLE" << endl;
}


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

using namespace std;

int ans[3004][3004], cnt[3004];

int main(){
    int N, M, A, B;
    scanf("%d %d %d %d", &N, &M, &A, &B);
    if(A > M / 2 || B > N / 2){
        puts("-1"); return 0;
    }
    int C, D = -1, ff = 1;
    for(int i = 0; i <= M; ++i){
        C = B * i + (M - i) * (N - B);
        for(int j = 0; j <= N; ++j){
            if(j * A + (N - j) * (M - A) == C){
                D = j; C = i;
                ff = 0;
                break;
            }
        }
        if(!ff) break;
    }
    if(D == -1){
        puts("-1"); return 0;
    }
    int j = 0, st = 0;
    for(int i = 0; i < N; ++i){
        while(st < M){
            if(st < C && cnt[st] >= B) ++st;
            else if(st >= C && cnt[st] >= N - B) ++st;
            else break;
        }
        j = max(j, st);
        if(i < D){
            for(int k = 0; k < A; ++k){
                ans[i][j] = 1; ++cnt[j];
                j = (j + 1) % M;
        j = max(j, st);
            }
        }
        else{
            for(int k = 0; k < M - A; ++k){
                ans[i][j] = 1; ++cnt[j];
                j = (j + 1) % M;
        j = max(j, st);
            }
        }
    }
    for(int i = 0; i < N; ++i){
        for(int j = 0; j < M; ++j){
            printf("%d", ans[i][j] ^ 1);
        }
        puts("");
    }
    return 0;
}


Measured memory_bytes: 12800
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <cmath>
#include <tuple>
#include <cstdio>
#include <bitset>
#include <sstream>
#include <iterator>
#include <numeric>
#include <map>
#include <cstring>

using namespace std;

//#define DEBUG_ //!!提出時にコメントアウト!!
#ifdef DEBUG_
	#define dump(x)  cerr << #x << " = " << (x) << endl;
#else
	#define dump(x)  ; //何もしない文
#endif

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SZ(x) ((int)(x).size()) //unsignedのサイズをint型に変換

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

template <typename T>
std::string printVector(const std::vector<T> &data)
{
    std::stringstream ss;
    std::ostream_iterator<T> out_it(ss, ", ");
    ss << "[";
    std::copy(data.begin(), data.end() - 1, out_it);
    ss << data.back() << "]";
    return ss.str();
}

const LL LINF = 1001002003004005006ll;
const int INF = 1001001001;

const int MOD = 1e9+7;
const int MAX_N = 105;
const int MAX_V = 1e5+10;

LL dp[MAX_N][MAX_V];

//ここから書き始める
int main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);	

    int N,W;
    cin >> N >> W;
    VI w(N),v(N);
    REP(i,N)
    {
        cin >> w[i] >> v[i];
    }


    REP(i,MAX_N)
    {
        REP(j,MAX_V)
        {
            dp[i][j] = LINF;
        }
    }

    dp[0][0] = 0;


    REP(i,N)
    {
        for(int tv = 0; tv <= MAX_V; ++tv)
        {
            if(tv >= v[i])
            {
                dp[i+1][tv] = min({dp[i][tv], dp[i][tv-v[i]] + w[i]});
            }
            else
            {
                dp[i+1][tv] = dp[i][tv];
            }
        }
    }
    LL ans = 0;

    REP(n,N+1)
    {
        REP(i,100)
        {
        if(dp[n][i] != LINF)
        {
            dump(n)
            dump(i)
            dump(dp[n][i])
        }
        }
    }

    for(int i = MAX_V-1; i >= 0; --i)
    {
        if(dp[N][i] != LINF)
        {
            dump(i)
            dump(dp[N][i])
        }
        if(dp[N][i] <= W)
        {
            dump(W)
            dump(dp[N][i] <= W)
            ans = i;
            break;
        }
    }

    cout << ans << endl;


}


Measured memory_bytes: 82432
#include <stdio.h>

int N; // テストケース数
int a[10]; // 入力数値
int b[2]; // それぞれのレーンの一つ前の数字
int main(void){
  int i, j, k;
  scanf("%d", &N);
  for(i = 0;i < N;i++){
    int answer = 0; // 0:NO 1:YES
    for(j = 0;j < 10;j++){
      scanf("%d", &a[j]);
    }
    
    for(j = 0;j < 1<<10;j++){
      int tmp_ans = 1;
      b[0] = b[1] = 0;

      for(k = 0;k < 10;k++){
        if(b[(j >> k) & 1] >= a[k]){
          tmp_ans = 0;
        }
        b[(j >> k) & 1] = a[k];
      }
      if(tmp_ans){
        answer = 1;
      }
    }
    if(answer){
      printf("YES\n");
    }else{
      printf("NO\n");
    }
  }
  return 0;
}

Measured memory_bytes: 0
#include<math.h>
#include<stdio.h>
int main(void){
	int i, n, x[100], y[100];
	double D1 = 0, d2 = 0, Dm = 0, d3 = 0, ab[100];
	scanf("%d", &n);
	
	for (i = 0; i<n; i++)
	{
		scanf("%d", &x[i]);
	}
	for (i = 0; i<n; i++)
	{
		scanf("%d", &y[i]);
	}
	for (i = 0; i<n; i++)
	{
		ab[i] = abs(x[i] - y[i]);
		if (i == 0)
		{
			 Dm = ab[0]; 
		}
		
		else if (ab[i]>Dm)
		{
			 Dm = ab[i]; 
		}
		
		D1 += ab[i];
		d2 += ab[i] * ab[i];
		d3 += pow(ab[i], 3.0);
	}
	printf("%f\n%f\n%f\n%f\n", D1, sqrt(d2), pow(d3, 1.0 / 3.0), Dm);
	
	return 0;
}


Measured memory_bytes: 2104
#include <iostream>
#define NUMBER 10000
using namespace std;
int main() 
{
    int  i, num;
    long a[NUMBER];
    cin >> num;
    for(i = 0; i < num; i++) {
            cin >> a[i];
    }
 
    long min, max, sum;
    min = max = sum = a[0];
    for(i = 1; i < num; i++) {
            if(a[i] > max) {
                max = a[i];
            }
            if(a[i] < min) {
                min = a[i];
            }
            sum += a[i];
    }
    cout << min << " " << max << " " << sum << endl;
    return 0;
}


Measured memory_bytes: 3144
#include<cstdio>
#include<algorithm>
using namespace std;

int a, b, x;

int main() {
  scanf("%d%d%d", &a, &b, &x);
  a = min(a, b*2);
  int temp = (x / 1000) * a;
  int ans = 100000000;
  x %= 1000;
  if (x == 0) ans = temp;
  ans = min(ans, temp + a);
  if (x <= 500) ans = min(ans, temp + b);
  printf("%d\n", ans);
}



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

ans = 0
i = 0

while i < N:
  if P[i] == i+1:
    ans += 1
    i += 2
  elif i >= N-2:
    break
  elif P[i+1] == i+2:
    i += 1
  else:
    i += 2

print(ans)

Measured memory_bytes: 14008
#include "bits/stdc++.h"
using namespace std;
 
long long MOD = 1000000007;
static long long F[100010] = {}, RF[100010] = {};
 
long long Calc(int a, int b) {
	if (b == 0) return 1;
	if (b % 2 == 0) {
		long long c = Calc(a, b / 2) % MOD;
		return (c * c) % MOD;
	}
	return (a * Calc(a, b - 1)) % MOD;
}
 
void Fac() {
	F[0] = F[1] = RF[0] = RF[1] = 1;
	for (int i = 2; i <= 100001; i++) {
		F[i] = (F[i - 1] * i) % MOD;
		RF[i] = (RF[i - 1] * Calc(i, MOD - 2)) % MOD;
	}
}
 
long long Comb(int a, int b) {
	if (a < b) return 0;
	return (((F[a] * RF[b]) % MOD) * RF[a - b]) % MOD;
}
 
int main() {
	int N, A, L, R;
	map<int, int> mp;
	cin >> N;
	for (int i = 0; i < N + 1; i++) {
		cin >> A;
		if (mp[A] == 0) mp[A] = i + 1;
		else L = mp[A] - 1, R = N - i;
	}
	Fac();
	for (int i = 1; i <= N + 1; i++) {
		cout << (Comb(N + 1, i) + MOD * 2 - Comb(L+ R, i - 1)) % MOD << endl;
	}
}

Measured memory_bytes: 7424
#include<bits/stdc++.h>
using namespace std;
int main()
{
	long long int N,i;
	cin>>N;
	long long int arr[N];
	long long int s[N];
	cin>>arr[0];
	s[0]=0;
	cin>>arr[1];
	s[1]=abs(arr[1]-arr[0]);
    for ( i = 2; i < N; ++i)
    {
    	cin>>arr[i];
    	s[i]=min(abs(arr[i]-arr[i-1])+s[i-1],abs(arr[i]-arr[i-2])+s[i-2]);

    }
    cout<<s[N-1]<<endl;
	return 0;
}

Measured memory_bytes: 1792
import sys
from collections import deque

H,W=map(int,input().split())
si,sj=[int(x)-1 for x in input().split()]
ti,tj=[int(x)-1 for x in input().split()]
A=list(sys.stdin)

dirs=[-2,-1,0,1,2]
dist=[[float('inf')]*W for _ in range(H)]
dist[si][sj]=0
dq=deque()
dq.append((0,si,sj))
ok=False
while dq:
    k,i,j=dq.popleft()
    if k>dist[i][j]:
        continue
    if i==ti and j==tj:
        ok=True
        break
    for di in dirs:
        for dj in dirs:
            if di==dj==0:
                continue
            ni,nj=i+di,j+dj
            if not (0<=ni<H and 0<=nj<W):
                continue
            if A[ni][nj]=='#':
                continue
            if abs(di)+abs(dj)==1:
                append=dq.appendleft
                nk=k
            else:
                append=dq.append
                nk=k+1
            if k>=dist[ni][nj]:
                continue
            dist[ni][nj]=nk
            append((nk,ni,nj))
      
if ok:
    ans=dist[ti][tj]
else:
    ans=-1

print(ans)


Measured memory_bytes: 227612
#include<map>
#include<cmath>
#include<queue>
#include<cstdio>
#include<algorithm>

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

using namespace std;

typedef vector< vector<int> > graph;

// G を連結成分に分解する
vector<graph> decomp(const graph &G){
	int n=G.size();
	vector<graph> cc;
	map<int,int> f; // G における頂点番号 -> 連結成分の番号
	map<int,int> g; // G における頂点番号 -> 連結成分における頂点番号

	int c_id=0;
	vector<bool> vis(n);
	rep(u,n) if(!vis[u]) {
		vis[u]=true;

		vector<int> tmp; // 今調べている連結成分
		queue<int> Q; Q.push(u);
		while(!Q.empty()){
			int v=Q.front(); Q.pop();
			tmp.push_back(v);
			rep(i,G[v].size()){
				int w=G[v][i];
				if(!vis[w]) vis[w]=true, Q.push(w);
			}
		}

		cc.push_back(graph(tmp.size()));
		rep(i,tmp.size()){
			f[tmp[i]]=c_id;
			g[tmp[i]]=i;
		}
		c_id++;
	}

	rep(u,n) rep(i,G[u].size()) {
		int v=G[u][i];
		cc[f[u]][g[u]].push_back(g[v]);
	}

	return cc;
}

bool is_bipartite(const graph &G,int &L_res,int &R_res){
	int n=G.size();
	int L=0,R=0;
	vector<int> color(n,-1);

	rep(u,n) if(color[u]==-1) {
		color[u]=2*(L++);

		queue<int> Q; Q.push(u);
		while(!Q.empty()){
			int v=Q.front(); Q.pop();

			rep(i,G[v].size()){
				int w=G[v][i];
				if(color[w]%2==color[v]%2) return false;
				if(color[w]==-1){
					if(color[v]%2==0) color[w]=2*(R++)+1;
					else              color[w]=2*(L++);
					Q.push(w);
				}
			}
		}
	}

	L_res=L;
	R_res=R;
	return true;
}

vector<int> unify_ones(const vector<int> &a){
	vector<int> res;
	int one=0;
	rep(i,a.size()){
		if(a[i]==1) one++;
		else        res.push_back(a[i]);
	}

	int two=1;
	while(one>0){
		res.push_back(min(two,one));
		one-=min(two,one);
		two<<=1;
	}
	return res;
}

int main(){
	int n,m; scanf("%d%d",&n,&m);
	graph G(n);
	rep(i,m){
		int u,v; scanf("%d%d",&u,&v); u--; v--;
		G[u].push_back(v);
		G[v].push_back(u);
	}

	vector<graph> cc=decomp(G);

	vector<int> L(cc.size()),R(cc.size()); // 二部グラフの左右の頂点数
	rep(i,cc.size()){
		if(!is_bipartite(cc[i],L[i],R[i])) return puts("-1"),0;
		if(L[i]>R[i]) swap(L[i],R[i]);
	}

	int L_sum=0;
	vector<int> add(cc.size());
	rep(i,cc.size()){
		L_sum+=L[i];
		add[i]=R[i]-L[i];
	}

	// add[i]==1 がたくさんあると部分和問題を解くのに時間がかかりすぎるので, 適当にまとめる ( 個数制約があるナップザックと同じ tips )
	add=unify_ones(add);
	sort(add.begin(),add.end(),greater<int>());

	// knapsack DP
	int N=L_sum; // 最適な左の頂点数 ( n/2 以下で最大になるよう振り分ける )
	vector<bool> dp(n+1); dp[0]=true;
	rep(i,add.size()){
		for(int j=n/2-L_sum-add[i];j>=0;j--){
			if(dp[j]){
				dp[j+add[i]]=true;
				if(abs(L_sum+j+add[i]-n/2.0)<abs(N-n/2.0)) N=L_sum+j+add[i];
			}
		}
	}

	printf("%u\n",N*(n-N)-m);

	return 0;
}

Measured memory_bytes: 22516
#include <bits/stdc++.h>
#define rep(i, n) for (lli i = 0; i < (n); i++)
#define rrep(i, n) for (lli i = (n)-1; i >= 0; i--)
#define vall(x) (x).begin(), (x).end()
using namespace std;
using lli = long long int;
void YESNO(bool), YesNo(bool);
template <class T1, class T2> bool chmin(T1 &l, const T2 &r);
template <class T1, class T2> bool chmax(T1 &l, const T2 &r);
template <class T1, class T2> void vadd(vector<T1> &v, T2 x);

#define int long long int

void solve(long long N, std::vector<long long> A) {
  lli ret =0;
  rep(i, N-1){
    if(A[i+1]<A[i]){
      ret += A[i]-A[i+1];
      A[i+1] = A[i];
    }
  }
  cout << ret <<endl;
}

signed main() {
  long long N;
  scanf("%lld", &N);
  std::vector<long long> A(N);
  for (int i = 0; i < N; i++) {
    scanf("%lld", &A[i]);
  }
  solve(N, std::move(A));
  return 0;
}

// -- lib
void YESNO(bool b) { cout << (b ? "YES" : "NO") << endl; }
void YesNo(bool b) { cout << (b ? "Yes" : "No") << endl; }

template <class T1, class T2> bool chmin(T1 &l, const T2 &r) {
  return (l > r) ? (l = r, true) : false;
}

template <class T1, class T2> bool chmax(T1 &l, const T2 &r) {
  return (l < r) ? (l = r, true) : false;
}

template <class T1, class T2> void vadd(vector<T1> &v, T2 x) {
  for (auto &s : v)
    s += T2(x);
}


Measured memory_bytes: 4748
#include<string>
#include<iostream>
#include<vector>
#define int long long
using namespace std;
signed main(){
    int N; cin >> N;
    vector<string>v(N);
    for(auto& s : v) cin >> s;
    int ans = 0;
    for(auto s : v){
        bool ext = false;
        for(auto c : s){
            if(c == 'A') ext = true;
            else if(c == 'B' and ext){
                ++ans; ext = false;
            } else {
                ext = false;
            }
        }
    }
    vector<int>cnt(3,0);
    for(auto s : v){
        if(s.front() == 'B' and s.back() != 'A')
            cnt[0]++;
        else if(s.front() != 'B' and s.back() == 'A')
            cnt[1]++;
        else if(s.front() == 'B' and s.back() == 'A')
            cnt[2]++;
    }
    int mini = min(cnt[0],cnt[1]);
    ans += mini;
    if(cnt[2] != 0){
        ans += cnt[2] - 1 + (cnt[1] + cnt[0] > 0 ? 1 :0);
    }
    cout << ans << endl;
    
}


Measured memory_bytes: 768
#include <bits/stdc++.h>
using namespace std;
#define int long long   // <-----!!!!!!!!!!!!!!!!!!!

#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n)-1;i>=0;i--)
#define rrep2(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define all(a) (a).begin(),(a).end()

typedef long long ll;
typedef pair<int, int> Pii;
typedef tuple<int, int, int> TUPLE;
typedef vector<int> V;
typedef vector<V> VV;
typedef vector<VV> VVV;

typedef complex<double> P;
typedef vector<P> G;
#define here(g, i) g[i]
#define next(g, i) g[(i + 1) % g.size()]
#define prev(g, i) g[(i - 1 + g.size()) % g.size()]
const double EPS = 1e-10;
const double INF = 1e12;

struct L {
    P a, b, v;
    L(){}
    // L(P _a, P _b) {a = _a, b = _b, v = b - a;}
    L(P _a, P _b) : a(_a), b(_b), v(b - a) {}
    L(double _ax, double _ay, double _bx, double _by) : L(P(_ax, _ay), P(_bx, _by)) {}
        // : a(_ax, _ay), b(_bx, _by), v(b - a) {}
};

double cross(P a, P b) {
    return imag(conj(a) * b);
}

double dot(P a, P b) {
    return real(conj(a) * b);
}

// 2: parallel
// 1: orthogonal
// 0: otherwise
int relationLL(L l1, L l2) {
    if (cross(l1.v, l2.v) == 0) return 2;
    if (dot(l1.v, l2.v) == 0) return 1;
    return 0;
}

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

    int q;
    cin >> q;
    while (q--) {
        double v[4][2];
        rep(i, 4) rep(j, 2) cin >> v[i][j];
        L l1(v[0][0], v[0][1], v[1][0], v[1][1]);
        L l2(v[2][0], v[2][1], v[3][0], v[3][1]);
        cout << relationLL(l1, l2) << endl;
    }

}

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

long long gcd(long long a, long long b){
    while(a%b!=0){
        a%=b;
        swap(a,b);
    }
    return b;
}

long long lcm(long long a, long long b){
    return a/gcd(a,b)*b;
}

int main(void){
    int n,i;
    long long lcm_num=1;
    cin>>n;
    for(i=0;i<n;i++){
        long long t;
        cin>>t;
        lcm_num=lcm(lcm_num,t);
    }
    cout<<lcm_num;
}




Measured memory_bytes: 256
#![allow(unused_imports)]

use text_io::*;
use proconio::*;
use std::collections::*;
use itertools::Itertools;
use std::process::exit;
use std::cmp::*;
use num::*;
use num::integer::Roots;

fn main() {
    input! {
    mut a:usize,
    mut b:usize,
    mut c:usize,
    }
    let mut d=0;
    let mut e=0;
    let mut f=0;
    for i in 0..100000 {
        if a%2==1||b%2==1||c%2==1{
            println!("{}",i);exit(0)
        }
        else{
            d=(b+c)/2;
            e=(a+c)/2;
            f=(a+b)/2;
            a=d;
            b=e;
            c=f;
        }
    }
    println!("-1")
}

Measured memory_bytes: 2156
import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner scan = new Scanner(System.in);
    int N = scan.nextInt();
    int K = scan.nextInt();
    int s[] = new int[N];

    for (int i = 0; i < K; i++) {
      int d = scan.nextInt();
      for (int y = 0; y < d; y++) {
        int A = scan.nextInt();
        s[A - 1]++;
      }
    }

    System.out.println(Arrays.stream(s).filter(i -> i == 0).count());
  }
}

Measured memory_bytes: 46800
#include<bits/stdc++.h>
using namespace std;
int a[600][600],e[600],d,minx=8888,n,I;
int main(){
	cin>>n;
	for(int i=0;i<n;i++){
		for(int j=0;j<n;j++){
			char c;cin>>c;
			if(c=='#'){a[i][j]=1;I=1;}
		}
	}
	for(int i=0;i<n;i++){
		int p=1,q=0;
		for(int j=0;j<n;j++){if(a[j][i]==0)p=0;else q=1;}
		d+=p;e[i]=q;
	}
	for(int i=0;i<n;i++){
		int u=0;
		if(e[i]==0)u=1;
		int cnt=0;
		for(int j=0;j<n;j++){
			cnt+=a[i][j];
		}
		minx=min(minx,(n-d)+(n-cnt)+u);
	}
	if(I==0)minx=-1;
	cout<<minx<<endl;
	return 0;
}


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

int main(){

  int k;
  cin >> k;

  string s;
  cin >> s;

  if(s.size() <= k){
    cout << s << endl;
    return 0;
  }

  for(int i=0; i<k; ++i){
    cout << s[i];
  }
  cout << "..." << endl;


  return 0;
}


Measured memory_bytes: 3620
H, W, N = gets.split.map(&:to_i)
SR, SC = gets.split.map(&:to_i)
S = gets.chomp.chars
T = gets.chomp.chars

left = 1
right = W
up = 1
down = H

(N - 1).downto(0) do |i|
  s = S[i]
  t = T[i]

  if i < N - 1
    case t
    when 'R'
      left = [1, left - 1].max
    when 'L'
      right = [W, right + 1].min
    when 'U'
      down = [H, down + 1].min
    when 'D'
      up = [1, up - 1].max
    end
  end

  case s
  when 'R'
    right -= 1
  when 'L'
    left += 1
  when 'U'
    up += 1
  when 'D'
    down -= 1
  end

  if right <= 1 || W + 1 <= left || down <= 1 || H + 1 <= up
    puts 'NO'
    exit
  end
end

if left <= SC && SC <= right && up <= SR && SR <= down
  puts 'YES'
else
  puts 'NO'
end


Measured memory_bytes: 35640
n,q=map(int,input().split())
s=[0]+list(input())+[0]
a=[input().split()for i in range(q)][::-1]
l,r=0,n+1
for(m,h)in a:
    if m==s[l+1]and h=="L":
        l+=1
    elif m==s[l]and h=="R":
        l-=1
    if m==s[r-1]and h=="R":
        r-=1
    elif m==s[r]and h=="L":
        r+=1
print(max(0,r-l-1))

Measured memory_bytes: 42252
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file 
#include <ext/pb_ds/tree_policy.hpp> 
#include <functional> // for less 
#define MAX 702
#define pb push_back
#define For(i,s,e) for (ll i=(s); i<(e); i++)
#define Debug_array(a,n) for (ll i=(0); i<(n); i++) cout<<a[i]<<" "
#define Foe(i,s,e) for (ll i=(s); i<=(e); i++)
#define Fod(i,s,e) for (ll i=(s)-1; i>=(e); i--)
#define Mod 1000000007
#define pii pair<ll,ll>
#define fi first
#define se second
#define endl "\n"
#define mp make_pair
#define big_prime 15486277
#define bigger_prime 179424697
#define biggest_prime 32416188691
//#define random_shuffle(indices.begin(), indices.end());
//std::random_device rd;
//std::mt19937 g(rd());
//std::shuffle(v.begin(), v.end(), g);
using namespace __gnu_pbds; 
using namespace std;

typedef long long ll;
typedef tree<ll, null_type, less<ll>, rb_tree_tag,tree_order_statistics_node_update> ordered_set; 

ll n,m;
vector<ll> G[MAX];
ll color[MAX];

set<ll> component;
bool dfs(ll s,ll c){
	if(color[s]!=-1){
		if(color[s]==c) return 1;
		else return 0;
	}
	component.insert(s);
	color[s]=c;
	for(ll x:G[s]){
		if(!dfs(x,c^1)) return 0;
	}
	return 1;
}
vector<pii> a;
ll dp[MAX][MAX];
ll f(ll index,ll A){
	if(index==a.size()) return (A*(A-1))/2+((n-A)*(n-A-1))/2;
	if(dp[index][A]!=-1) return dp[index][A];
	ll t1 = f(index+1,A+a[index].fi);
	ll t2 = f(index+1,A+a[index].se);
	dp[index][A]=min(t1,t2);
	return min(t1,t2);
}

int main(){
	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	memset(color,-1,sizeof(color));
	memset(dp,-1,sizeof(dp));
	cin>>n>>m;
	set<pii> e;
	For(i,0,m){
		ll x,y;cin>>x>>y;x--;y--;
		e.insert({x,y});
		e.insert({y,x});
	}	
	For(i,0,n) For(j,i+1,n) if(e.find({i,j})==e.end()){
		G[i].pb(j);
		G[j].pb(i);
	}

	For(i,0,n){
		if(color[i]==-1){
			component.clear();
			bool x = dfs(i,0);
			if(!x){
				cout<<-1<<endl;
				return 0;
			}
			ll count[2] = {0};
			for(ll x:component){
				count[color[x]]++;
			}
			a.pb({count[0],count[1]});
		}
	}

	ll ans=f(0,0);
	cout<<ans<<endl;










	
}

Measured memory_bytes: 34688
N = int(input())
if N == 0:
    print('0')
    exit()

ans = ''
while abs(N) > 0:
    if abs(N) % 2 == 0:
        ans += '0'
        N //= 2
    else:
        N -= 1
        N //= 2
        ans += '1'
    N *= -1
print(ans[::-1])


Measured memory_bytes: 9172
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author toshibablack
 */

#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstring>
#include <fstream>
#include <functional>
#include <iostream>
#include <iomanip>
#include <iterator>
#include <memory>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <vector>

#define ll long long int
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define REP(i, n) for(int i=0;i<n;++i)
#define FOREACH(x, a) for(auto& (x) : (a))
#define ALL(a) (a).begin(),(a).end()
#define COUT(x) out << (x) << endl;
#define M0(x) memset(x,0,sizeof(x))
#define MINF(x) memset(x,0x3f,sizeof(x))
#define MMINUS(a) memset(a,0xff,sizeof(a))

const int INF = 0x3f3f3f3f;
const int MOD = 1e9+7;
const ll LINF = 1e18;
const double EPS = 1.0/LINF;

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

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

int gcd(int a,int b){return b?gcd(b,a%b):a;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}

using namespace std;

class CRectangleCutting {
public:
    ll W, H, x, y;

    void solve(std::istream& in, std::ostream& out) {
        in >> W >> H >> x >> y;
        double area = W * H / 2.0;
        int ans = abs(W - 2*x) < EPS && abs(H - 2*y) < EPS ? 1 : 0;
        out << area << " " << ans;
    }
};


int main() {
    CRectangleCutting solver;
    std::istream& in(std::cin);
    std::ostream& out(std::cout);
    solver.solve(in, out);
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<iomanip>
using namespace std;
typedef long long ll;
typedef long  l;
typedef pair<int,int> P;
#define rep(i,n) for(int i=0;i<n;i++)
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
const double PI=3.141592653589;
const int INF=1000000007;
const ll LMAX=1000000000000001;
ll gcd(ll a,ll b){if(a<b)swap(a,b);while((a%b)!=0){a=b;b=a%b;}return b;}
int dx[]={-1,0,1,0};
int dy[]={0,1,0,-1};


int main(){
  int n; cin>>n;
  vector<int> p(n);
  rep(i,n) cin>>p[i];
  int m=INF;
  int c=0;
  rep(i,n){
    m=min(m,p[i]);
    if(p[i]<=m)
    c++;
  }
  cout<<c<<endl;


  return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <iomanip>
#include <set>
#include <map>
#include <utility>
#include <algorithm>
#include <cstdint>

using namespace std;

typedef long long signed int ll;

constexpr ll inf = 1000000000000000;

ll c[1000][1000], n, d[1000],m,e[1000];

int main() {
	for (ll i = 0; i < 1000; i++) for (ll j = 0; j < 1000; j++) c[i][j] = -inf;
	for (ll i = 0; i < 1000; i++) d[i] = -inf;
	for (ll i = 0; i < 1000; i++) e[i] = -inf;
	cin >> n >> m;
	for (ll i = 0; i < m; i++) {
		ll a, b, cc;
		cin >> a >> b >> cc;
		c[a-1][b-1] = cc;
	}
	d[0] = 0;
	bool update = true;
	for (ll i = 0; i < n && update; i++) {
		update = false;
		for (ll j = 0; j < n; j++) {
			for (ll k = 0; k < n; k++) {
				if (d[k] < d[j] + c[j][k]) {
					d[k] = d[j] + c[j][k];
					update = true;
				}
			}
		}
	}
	for (ll i = 0; i < n && update; i++) {
		update = false;
		for (ll j = 0; j < n; j++) {
			for (ll k = 0; k < n; k++) {
				if (d[k] < d[j] + c[j][k]) {
					d[k] = d[j] + c[j][k];
					e[k] = 0;
					update = true;
				}
			}
		}
	}
	if (e[n-1] == 0) cout << "inf";
	else cout << d[n-1];
	cout << endl;
}

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

// macros
#define ll long long int
#define pb emplace_back
#define mk make_pair
#define pq priority_queue
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define rep(i, n) FOR(i, 0, n)
#define rrep(i, n) for(int i=((int)(n)-1);i>=0;i--)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
#define FI first
#define SE second
using namespace std;

//  types
typedef pair<int, int> P;
typedef pair<ll, int> Pl;
typedef pair<ll, ll> Pll;
typedef pair<double, double> Pd;
 
// constants
const int inf = 1e9;
const ll linf = 1LL << 50;
const double EPS = 1e-10;
const int mod = 1e9 + 7;

// solve
template <class T>bool chmax(T &a, const T &b){if(a < b){a = b; return 1;} return 0;}
template <class T>bool chmin(T &a, const T &b){if(a > b){a = b; return 1;} return 0;}
template <typename T> istream &operator>>(istream &is, vector<T> &vec){for(auto &v: vec)is >> v; return is;}

typedef struct UnionFind_ {
  vector<int> par;
  vector<int> rank_;
  UnionFind_(int n): rank_(n, 0) {
    for(int i = 0; i < n; i++)par.push_back(i);
  }
  int find(int x) {
    if(par[x] == x)return x;
    else return par[x] = find(par[x]);
  }
  bool same(int x, int y) {
    if(find(x) == find(y))return true;
    else return false;
  }
  bool unite(int x, int y){
    int xp = find(x);
    int yp = find(y);
    if(xp == yp)return false;
    if(rank_[xp] > rank_[yp])par[yp] = xp;
    else if(rank_[xp] < rank_[yp])par[xp] = yp;
    else {
      par[yp] = xp;
      rank_[xp]++;
    }
    return true;
  }
} UnionFind;

template <typename T>
struct edge{
  int from;
  int to;
  T cost;
};

template <typename T>
bool comp(const edge<T> &a, const edge<T> &b){
  return a.cost < b.cost;
}

template <typename T>
struct Graph {
  int n;
  vector<edge<T>> es;
  Graph(int n_){
    n = n_;
  }
  void adde(int from, int to, T cost){
    es.push_back((edge<T>){from, to, cost});
  }
  T kruskal(){
    T res = 0;
    UnionFind uf(n);
    sort(es.begin(), es.end(), comp<T>);
    for(auto e: es){
      int from = e.from;
      int to = e.to;
      T cost = e.cost;
      if(uf.same(from, to))continue;
      res += cost;
      uf.unite(from, to);
    }

    return res;
  }
};

using GraphI = Graph<int>;

int main(int argc, char const* argv[])
{
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  GraphI graph(n);
  rep(i, m){
    int a, b, c;
    cin >> a >> b >> c;
    graph.adde(a, b, c);
  }
  cout << graph.kruskal() << endl;
	return 0;
}



Measured memory_bytes: 4584
N=int(input())
dp=[[0]*3 for i in range(N+1)]
for i in range(1,N+1):
  a=list(map(int,input().split()))
  for j in range(3):
    tmp=[]
    for k in range(3):
      if j!=k:
        dp[i][k]=max(dp[i][k],dp[i-1][j]+a[k])  
print(max(dp[-1]))

Measured memory_bytes: 22800
ans = 0
position = []
for i in range(5):
    x = int(input())
    position.append(x)
k = int(input())
distance_list = []
for i in range(5):
    for j in range(5):
        if i != j:
            distance = abs(position[i] - position[j]) 
            distance_list.append(distance)

y = max(distance_list)
if y <= k:
    print('Yay!')
else:
    print(':(')



Measured memory_bytes: 9180
import bisect
n=int(input())
l=[int(i) for i in input().split()]
l.sort()
ans=0
for i in range(n):
    for j in range(i+1,n):
        a=l[i]
        b=l[j]
        ans+=bisect.bisect_left(l,a+b,lo=j)-j-1
print(ans)

Measured memory_bytes: 45588