akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;
import java.util.Stack;

public class Main {
	
//	public static void main(String[] args) {
//		try(Scanner sc = new Scanner(System.in)){
//			int N = sc.nextInt();
//			int[] d = new int[100010];
//			for(int i=0; i<N; i++) {
//				int a = sc.nextInt();
//				int b = sc.nextInt();
//				for(int j = a; j <= b; j++) {
//					d[j]++;
//				}
//			}
//			int p;
//			for(p = d.length-1; d[p] < p-1; p--) {
//			}
//			System.out.println(p-1);
//		}
//	}
	
	static boolean check(String s) {
		Stack<Character> stack = new Stack<>(); //
		for(int i = 0; i < s.length(); i++) {
			char c = s.charAt(i);
			if(c == '.') {
				break;
			}
			if(c == '(') {
				stack.push(')');
			}
			if(c == '[') {
				stack.push(']');
			}
			if(c == ')' || c == ']') {
				if(stack.isEmpty() || stack.pop() != c) {
					return false;
				}
			}
		}
		return stack.isEmpty();
	}

	public static void main(String[] args) {
		try (Scanner sc = new Scanner(System.in)) {
			while(sc.hasNextLine()){
				String s = sc.nextLine();
				if(s.equals(".")) {
					break;
				}
				if(check(s)) {
					System.out.println("yes");
				}
				else {
					System.out.println("no");
				}
			}
		}
	}
}



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

using namespace std;

const int N = int(2e5) + 5;
const int MOD = int(1e9) + 7;
const int inf = int(2e9);



int main() {
    ios_base :: sync_with_stdio(0);
    cin.tie(0),cout.tie(0);

    int N,R;
    cin >> N >> R;
    if (N >= 10) cout << R;
    else cout << R + 100*(10-N);
    return 0;
}


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

int main(void){
    int n,x,y;
    int i,j,p;
    int option[3];
    vector<int> route;
    cin >> n >> x >> y;
    for(i=0;i<n-1;i++){
        route.push_back(0);
    }
    for(i=1;i<n;i++){
        for(j=0;j<3;j++){
            option[j]=0;
        }
        for(j=i+1;j<=n;j++){
            option[0] = j-i;
            option[1] = abs(x-i)+abs(y-j)+1;
            option[2] = abs(y-i)+abs(x-j)+1;
            p=min(option[0],option[1]);
            p=min(p,option[2]);
            route[p-1]++;
        }
    }
    for(i=0;i<n-1;i++){
        cout<<route[i]<<"\n";
    }
    return 0;
}

Measured memory_bytes: 888
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
#define Rapido ios::sync_with_stdio(0); cin.tie(0)
const int maxS = 2e5 + 10;
int MOD = 998244353;
int DP[2 * maxS];

void code_idhr_h() {
    int N, K; cin >> N >> K;
    vector<int> L(K + 1), R(K + 1);
    for(int i = 1; i <= K; i++) cin >> L[i] >> R[i];
    DP[1] = 1;
    for(int i = 1; i <= N; i++) {
        for(int j = 1; j <= K; j++) {
            DP[i + L[j]] = (DP[i + L[j]] + DP[i]) % MOD;
            DP[i + R[j] + 1] = (DP[i + R[j] + 1] - DP[i] + MOD) % MOD;
        }
        DP[i + 1] = (DP[i + 1] + DP[i]) % MOD;
    }
    cout << (DP[N] - DP[N - 1] + MOD) % MOD;
}

int32_t main() {
    Rapido;
    int T = 1; //cin >> T;
    for(int t = 1; t <= T; t++) {
        code_idhr_h();
    }
    return 0;
}

Measured memory_bytes: 6684
n = int(input())

for i in range(n):
    tmp = list(map(int,input().split()))
    a,b,cnt = 0,0,0
    
    for j in range(10):
        if a<tmp[j]: a = tmp[j]
        elif b<tmp[j]: b = tmp[j]
        else: cnt += 1
        
    if cnt==0: print("YES")
    else: print("NO")
        


Measured memory_bytes: 5596
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a,b,k;
  cin >> a>>b >>k;
  for(int i=a;i<=b;i++){
    if( i<=a+k -1 || i>=b-k+1 ){
      cout <<i<<endl;
    }
  }
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>

int compara(const void * a,const void * b){
    int x = *(int*) a, y = *(int*)b;
    return x>y?-1:x<y?1:0;
}

int main(int argc, char const *argv[]) {
    int n,k,c=0;
    scanf("%d %d", &n,&k);
    int *a = malloc(sizeof(int)*n);

    for (int i = 0; i < n; i++) {
        scanf("%d\n",&a[i]);
    }
    qsort(a,n,sizeof(int),compara);
    for (int i = 0; i < k; i++) {
        c+=a[i];
    }
    printf("%d\n",c);

    return 0;
}


Measured memory_bytes: 128
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

N, A, B, C, D = mapint()
S = list(input())

def exp(idx, goal):
    while 1:
        if idx==goal:
            return True
        if idx+1<N and S[idx+1]==".":
            idx += 1
        elif idx+2<N and S[idx+2]=='.':
            idx += 2
        else:
            return False

if C<D:
    if exp(A-1, C-1) and exp(B-1, D-1):
        print('Yes')
    else:
        print('No')
else:
    for i in range(B-2, min(N-2, D-1)):
        if S[i]=="." and S[i+1]=="." and S[i+2]==".":
            if exp(A-1, C-1) and exp(B-1, D-1):
                print('Yes')
            else:
                print('No')
            break
    else:
        print('No')

Measured memory_bytes: 82340
from copy import deepcopy
import math
import string
import collections
from collections import Counter
from collections import deque
from decimal import Decimal
import sys
import fractions
from operator import itemgetter
import itertools
import copy


def readints():
    return list(map(int, input().split()))


def nCr(n, r):
    return math.factorial(n)//(math.factorial(n-r)*math.factorial(r))


def has_duplicates2(seq):
    seen = []
    for item in seq:
        if not(item in seen):
            seen.append(item)
    return len(seq) != len(seen)


def divisor(n):
    divisor = []
    for i in range(1, n+1):
        if n % i == 0:
            divisor.append(i)
    return divisor


def gcd(a, b):
    while(b != 0):
        a, b = b, a % b
    return a


# coordinates
dx = [-1, -1, -1, 0, 0, 1, 1, 1]
dy = [-1, 0, 1, -1, 1, -1, 0, 1]
a, b, c, k = map(int, input().split())
#print(a, b, c, k)
if a >= k:
    print(k)
elif a+b >= k:
    print(a)
else:
    print(a-(k-a-b))


Measured memory_bytes: 10496
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define rep1(i, n) for (ll i = 1; i <= (n); ++i)
#define rrep(i, n) for (ll i = (n - 1); i >= 0; --i)
#define perm(c) sort(ALL(c));for(bool c##p=1;c##p;c##p=next_permutation(ALL(c)))
#define ALL(obj) (obj).begin(), (obj).end()
#define pb push_back
#define to_s to_string
#define len(v) (ll)v.size()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
#define print(x) cout << (x) << '\n'
#define drop(x) cout << (x) << '\n', exit(0)
#define debug(x) cout << #x << ": " << (x) << '\n'
using namespace std;
using ll = long long;
typedef pair<ll, ll> P;
typedef vector<ll> vec;
typedef vector<vector<ll>> vec2;
typedef vector<vector<vector<ll>>> vec3;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
ll MOD = 1e9 + 7;
ll devc(ll x, ll y) { return 1 + (x - 1) / y; }

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

    ll N, M;
    cin >> N >> M;
    vec ans(N, -1);

    rep(i, M){
        ll s, c;
        cin >> s >> c;
        --s;
        if(ans[s] != -1 and ans[s] != c) drop(-1);
        ans[s] = c;
    }

    if(ans[0] == 0 and N > 1) drop(-1);
    if(ans[0] == -1){
        if(N == 1) ans[0] = 0;
        else ans[0] = 1;
    }

    string out = "";
    for(auto a : ans){
        if(a == -1) a = 0;
        out += to_s(a);
    }
    print(out);

    

    return 0;
}

Measured memory_bytes: 256
s = input()
s = [i for i in s]
a = []
for i in s:
    if i not in a:
        a.append(i)
ans = 1000

for i in a:
    count = 0
    b = s[:]
    c = []
    while len(b) != b.count(i):
        count += 1
        for j in range(len(b)-1):
            if b[j] == i or b[j+1] == i:
                c.append(i)
            else:
                c.append(b[j])
        b = c[:]
        c = []

    ans = min(ans,count)
print(ans)

Measured memory_bytes: 3064
#include<iostream>
#include<queue>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
using namespace std;

int main(){
	int n;
	while(1){
		cin>>n;
		if(!n)break;
		bool cards[n*2+1];
		rep(i,n*2+1)cards[i]=false;//false:hanako
		int num;
		rep(i,n){
			cin>>num;
			cards[num]=true;//true:taro
		}
		priority_queue<int,vector<int>,greater<int> > hanako,taro;
		loop(i,1,n*2+1){
			if(cards[i]){
				taro.push(i);
			}else{
				hanako.push(i);
			}
		}
		int hanapoint,taropoint;
		hanapoint=0;
		taropoint=0;
		int field=0;
		for(int i=1;;i++){
			if(i%2){//taro's turn
				queue<int> alt;
				while(taro.top()<=field && !taro.empty()){
					alt.push(taro.top());
					taro.pop();
				}
				if(!taro.empty()){
					field=taro.top();
					taro.pop();
				}else{
					field=0;
				}
				while(!alt.empty()){
					taro.push(alt.front());
					alt.pop();
				}
			}else{//hanako's turn
				queue<int> alt;
				while(hanako.top()<=field && !hanako.empty()){
					alt.push(hanako.top());
					hanako.pop();
				}
				if(!hanako.empty()){
					field=hanako.top();
					hanako.pop();
				}else{
					field=0;
				}
				while(!alt.empty()){
					hanako.push(alt.front());
					alt.pop();
				}
			}
			if(taro.empty()){
				taropoint=hanako.size();
				hanapoint=0;
				break;
			}else if(hanako.empty()){
				hanapoint=taro.size();
				taropoint=0;
				break;
			}
		}
		cout<<taropoint<<endl;
		cout<<hanapoint<<endl;
	}
	return 0;
}

Measured memory_bytes: 1220
import Data.Bits
f _ _ [] [] = 0
f n x ~yys@(y:ys) zzs
  | not (null zzs) && x+z == x`xor`z = f (n+1) (x`xor`z) yys zs
  | otherwise = n + f (n-1) (x`xor`y) ys zzs
  where ~(z:zs) = zzs
main = do
  n <- getLine
  a <- map read . words <$> getLine :: IO [Int]
  print $ f 0 0 a a

Measured memory_bytes: 77820
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin >> n;
    string s = to_string(n);
    int sum=0;
    for(int i=0;i<s.length();i++)sum+=(s[i]-'0');
    if(n%sum==0)cout << "Yes";
    else cout << "No";
}

Measured memory_bytes: 3700
import java.util.*;
import static java.lang.Math.*;
import java.math.BigInteger;

public 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();
		
		// 計算
		String result = "";
		
		char[] c = s.toCharArray();
		//c[k-1] += 32;
		c[k-1] = Character.toLowerCase(c[k-1]);
		result = new String(c);
		
		// 出力
		System.out.println(result);
	}
}

Measured memory_bytes: 21844
#include<bits/stdc++.h>
#define MAX_N 100001
#define INF_INT 2147483647
#define INF_LL 9223372036854775807
#define REP(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> P;
void init(int n);
int find(int n);
void unite(int x,int y);
bool same(int x, int y);
ll bpow(ll,ll,ll);
typedef vector<int> vec;
typedef vector<vec> mat;
mat mul(mat &A,mat &B);
mat pow(mat A,ll n);
int dx[4] = {1,0,0,-1};
int dy[4] = {0,1,-1,0};


bool cmp_P(const P &a,const P &b){
  return a.second < b.second;
}
long long int MOD = 1000000007;
long long int ruiseki[200001];
int ncrset(){
  ruiseki[0] = 1;
  for(int i=1;i<200001;i++){
    ruiseki[i] = (ruiseki[i-1] * i) % MOD;
  }
}

long long int powld(long long int x,long long int n){
  long long int ans = 1;
  while(n > 0){
    if((n&1) == 1){
      ans = (ans*x)  % MOD;
    }
    x = (x*x) % MOD;
    n >>= 1;
  }
  return ans % MOD;
}

int ncrgyaku(int n,int r){
  long long int gyakuk,gyakur;
  long long int res = 1,x,y,z;
  y = powld(ruiseki[r],MOD-2);
  z = powld(ruiseki[n-r],MOD-2);
  return (((ruiseki[n]*y) % MOD)*z) % MOD;

}
int main()
{
  ncrset();
  ll N,M,dp[100001],d=0,res=0,f=1;
  cin >> N >> M;
  dp[0] = 1;
  vector<int> soinsu;
  set<int> soin;
  for(int i=2;M != 1;i++){
    while(M % i == 0){
      soinsu.push_back(i);
      soin.insert(i);
      M /= i;
    }
  }
  d += soinsu.size();
  for(auto itr=soin.begin();itr!=soin.end();itr++){
    f = (f*ncrgyaku(N-1+count(soinsu.begin(),soinsu.end(),*itr),N-1))%MOD;
  
  }
  cout << f << endl;
  return 0;
}

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


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define ll long long int
using namespace std;
 
int main()
{
    ll t,i,j,k,l,n,m;
    cin>>n;
    ll A[n];
    ll B[n],sum=0;
    for(i=0;i<n;++i){
        cin>>A[i];
        B[i]=A[i];
    }
    map<ll,ll> M;
    ll ans=0;
M[0]++;
    for(i=0;i<n;++i){
        sum+=A[i];
        
        ans+=M[sum];
        M[sum]++;
    }
    cout<<ans;
 
 
    return 0;
}

Measured memory_bytes: 15872
n = int(input())
ls = [[2,1]]
two = 2
i = 1
while True:
    two *= 2
    i += 1
    if two > 200:
        break
    ls.append([two,i])
    
if n == 1:
    print(1)
else:
    for i in range(len(ls)):
        if ls[i][0] > n:
            print(ls[i-1][0])
            break

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pcc pair<char,char>
#define vi vector <int>
#define vl vector <ll>
#define sd(x) scanf("%d",&x)
#define slld(x) scanf("%lld",&x)
#define pd(x) printf("%d",x)
#define plld(x) printf("%lld",x)
#define pds(x) printf("%d ",x)
#define pllds(x) printf("%lld ",x)
#define pdn(x) printf("%d\n",x)
#define plldn(x) printf("%lld\n",x)
#define INF 2e9
#define INFLL 4e18
using namespace std;
ll powmod(ll base,ll exponent,ll mod){ // with mod < 1e9
	ll ans=1;
	while(exponent){
		if(exponent&1)ans=(ans*base)%mod;
		base=(base*base)%mod;
		exponent/=2;
	}
	return ans;
}
ll gcd(ll a, ll b){
	if(b==0) return a;
	else return gcd(b,a%b);
}
const int upperlimit = 1e6+100;
const int mod = 1e9+7;
ll prefa[upperlimit];
ll prefb[upperlimit];
int main() {
//	freopen(".in","r",stdin);freopen(".out","w",stdout);
	int n,m;
	ll k;
	sd(n);sd(m);slld(k);
	for(int i = 1; i <= n; i++){
		slld(prefa[i]);
		prefa[i]+=prefa[i-1];
	}
	for(int i = 1; i <= m; i++){
		slld(prefb[i]);
		prefb[i]+=prefb[i-1];
	}
	int ans=0;
	int j=m;
	for(int i = 0; i <= n; i++){
		while((prefa[i]+prefb[j]>k)&&(j>0)) j--;
		if(prefa[i]+prefb[j]<=k){
			ans=max(ans,i+j);
			// pds(i);pdn(j);
		}
	}
	pd(ans);
	return 0;
}

Measured memory_bytes: 6932
package main

import(
    "fmt"
    "sort"
    "strings"
)



func main() {
    var s string
    fmt.Scan(&s)
    a := make([]int, 26)
    ans := "Yes"
    for i:=0;i<len(s);i++{
        a[s[i]-'a']++
    }
    for i:=0;i<26;i++{
        if a[i]%2==1{
            ans = "No"
        }
    }
    fmt.Println(ans)
}





// Pairsort
type Pair struct {
    first,second int64
}

type By func(p1, p2 *Pair) bool

func (by By) Sort(pairs []Pair) {
    ps := &pairSorter{
            pairs : pairs,
            by: by,
    }
    sort.Sort(ps)
}

type pairSorter struct {
    pairs []Pair
    by func(p1, p2 *Pair) bool
}

func (s *pairSorter) Len() int {
    return len(s.pairs)
}

func (s *pairSorter) Swap(i, j int) {
    s.pairs[i], s.pairs[j] = s.pairs[j], s.pairs[i]
}

func (s *pairSorter) Less(i, j int) bool {
    return s.by(&s.pairs[i], &s.pairs[j])
}

func first (p1, p2 *Pair) bool {
        return p1.first < p2.first
}

func second (p1, p2 *Pair) bool {
        return p1.second < p2.second
}
// end



func abs32(a int) int {
    if a<0{
        return -a
    }
    return a
}

func abs64(a int64) int64 {
    if a<0{
        return -a
    }
    return a
}

func min32(a, b int) int {
    if a >= b {
        return b
    }
    return a
}

func max32(a, b int) int {
    if a >= b {
        return a
    }
    return b
}

func min64(a, b int64) int64 {
    if a >= b {
        return b
    }
    return a
}

func max64(a, b int64) int64 {
    if a >= b {
        return a
    }
    return b
}

func gcd(a, b int64) int64 {
    if a % b == 0 {
        return b
    } else {
        return gcd(b, a%b)
    }
}

func lcm(a, b int64) int64 {
    return a / gcd(a, b) * b
}

func scanNums(len int) (nums []int){
    var num int
    for i:=0; i<len; i++{
        fmt.Scan(&num)
        nums = append(nums,num)
    }
    return
}

func scanNums64(len int) (nums []int64){
    var num int64
    for i:=0; i<len; i++{
        fmt.Scan(&num)
        nums = append(nums,num)
    }
    return
}

func scanString(len int) (str []string){
    var s string
    for i:=0; i<len; i++{
        fmt.Scan(&s)
        str = append(str,s)
    }
    return
}

func makeTwoNums(n,m int) ([][]int){
    Nums := make([][]int, n)
    for i:=0; i<n; i++{
        Nums[i] = make([]int, m)
    }
    return Nums
}

func sortString(s string) string{
    t := strings.Split(s, "")
    sort.Strings(t)
    return strings.Join(t, "")
}

func reverseString(s string) string{
    t := []rune(s)
    for i,j := 0, len(s)-1 ; i < j ; i, j = i+1, j-1 {
        t[i], t[j] = t[j], t[i]
    }
    return string(t)
}

func inside(h,w,H,W int) bool{
    if h>=0 && h<H && w>=0 && w<W{
        return true
    }
    return false
}


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


int main() {
    
    int n;cin>>n;
    int weight;cin>>weight;
    long long int dp[n+1][weight+1]={0};
    for(int i=0;i<=n;i++){
        for(int j=0;j<=weight;j++){
            dp[i][j] = 0;
        }
        
    }
    int weights[n];
    long long int values[n];
    int mn = INT_MAX;
    for(int i=0;i<n;i++){
        cin>>weights[i]>>values[i];
        mn = min(weights[i],mn);
    }
    
   
    for(int i=0;i<=n;i++){
        for(int j=0;j<=weight;j++){
           if(i==0||j==0){
               dp[i][j]=0;
           }
            else if(j-weights[i-1]>=0){
                dp[i][j] = max(values[i-1]+dp[i-1][j-weights[i-1]],dp[i-1][j]);
            }
            else{
                dp[i][j] = dp[i-1][j];
            }
        }
        
    }
   
    cout<<dp[n][weight];




}

Measured memory_bytes: 79104
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int INF = 1e9 + 7, MOD = 1e9 + 7;
const long long LINF = 1e18;
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

int Cnt(int n) {
	string s = to_string(n);
	return s.size();
}

signed main() {
	int n;
	long long ans = LINF;
	cin >> n;
	for (int i = 1; i * i <= n; i++) {
		if (n % i == 0) {
			ans = min(ans, max(Cnt(i), Cnt(n / i)));
		}
	}
	cout << ans << endl;
	return 0;
}

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

using namespace std;

typedef long long ll;

const ll MOD = 1000000007;

ll Pot(ll p, ll w)
{
    if (w == 0)
        return 1;
    if (w % 2 == 0)
    {
        ll pol = Pot(p, w / 2);
        return pol * pol % MOD;
    }
    return Pot(p, w - 1) * p % MOD;
}

int main()
{
    ios_base::sync_with_stdio(0);
    ll n, k;
    cin >> n >> k;
    vector<ll> dp(k + 1);
    dp[k] = 1;
    for (ll i = k - 1; i >= 1; --i)
    {
        ll kan = (k - k % i) / i;
        dp[i] = Pot(kan, n);
        for (ll j = 2 * i; j <= k; j += i)
        {
            dp[i] -= dp[j];
            if (dp[i] < 0)
                dp[i] += MOD;
        }
    }
    ll odp = 0;
    for (ll i = 1; i <= k; ++i)
        odp = (odp + i * dp[i]) % MOD;
    cout << odp;
    return 0;
}


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

int main(){
	char s[20];

	cin >> s;
	char h1[6], h2[8], h3[6];
	int i;

	for(i=0; i<5; i++){
		h1[i] = s[i];
	}
	for(i=0; i<7; i++){
		h2[i] = s[i+6];
	}
	for(i=0; i<5; i++){
		h3[i] = s[i+14];
	}

	cout << h1 << " " << h2 << " " << h3 << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <string>
#include <algorithm>
#include <functional>
#include <set>
#include <map>
#include <unordered_map>
#include <queue>
#include <deque>
#include <cmath>
#include <cstdio>

using namespace std;

typedef long long ll;

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

int main(int argc, char **argv)
{
    int N, K;
    cin >> N >> K;

    double p = 0;
    FOR(i, 1, N + 1) {
        int t = i;
        double q = 1.0;
        while (t < K) {
            t *= 2;
            q /= 2;
        }
        p += q;
    }
    cout << std::fixed;
    cout << setprecision(12) << p / (double)N << endl;
    return 0;
}


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

int main() {
  int N, K;
  cin >> N >> K;
  vector<double> p(N+1, 0);
  int x;
  double val;
  
  for(int i=1; i<=N; i++){
    cin >> x;
    val = x*(x+1) * 0.5 / x;
    p.at(i) = p.at(i-1) + val;
  }
  
  double maxi=0;
  for(int i=0; i<N-K+1; i++){
    maxi = max(maxi, p.at(K+i) - p.at(i)); 
  }
  printf("%.6f\n", maxi);
  return 0;
}

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

int main(){
    using namespace std;
    constexpr unsigned long MOD = 998244353;

    constexpr unsigned long mx = 1000001;

    unsigned long N;
    cin >> N;
    vector<unsigned long> A(N);
    copy_n(istream_iterator<unsigned long>(cin), N, A.begin());

    unsigned long ans{0};
    unsigned long max_size{*max_element(A.begin(), A.end()) + 1};
    vector<unsigned long> hoge(max_size);
    for(const auto& i : A)++hoge[i];

    vector<unsigned long> coef(max_size, 1), prime;
    iota(coef.begin(), coef.end(), 0UL);

    vector<unsigned long> sieve(max_size, 1);
    for(unsigned long i = 2; i < max_size; ++i)if(sieve[i]){
        prime.push_back(i);
        for(unsigned long j = i * i; j < max_size; j += i)sieve[j] = 0;
    }

    for(const auto& i : prime)for(unsigned long j = max_size / i; j; --j){
        hoge[j] += hoge[j * i] * i;
        (coef[j * i] *= MOD + 1 - i) %= MOD;
    }
    for(auto& i : hoge)i %= MOD;

    ans = MOD - hoge[1];
    for(unsigned long i = 1; i < max_size; ++i)if(hoge[i])ans += hoge[i] * hoge[i] % MOD * coef[i] % MOD;
    (ans += (ans & 1) * MOD) >>= 1;
    cout << ans % MOD << endl;

    return 0;
}

Measured memory_bytes: 26360
import Foundation

let N = Int(readLine()!)!
let A = readLine()!.split(separator: " ").map { Int($0)! }

let absolutes = A.map { abs($0) }
let sum = absolutes.reduce(0, +)
let min = absolutes.min()!
let isEven = A.filter({ $0.signum() == -1 }).count % 2 == 0

let answer = isEven ? sum : sum - min * 2

print(answer)


Measured memory_bytes: 19156
N, T = map(int, input().split())
a = list(map(int, input().split()))

# 準備
N0 = 2 ** (N - 1).bit_length()
data = [float('inf')] * (2 * N0)

# a_k の値を x に更新
def update(k, x):
    k += N0 - 1
    data[k] = x
    while k >= 0:
        k = (k - 1) // 2
        data[k] = min(data[2 * k + 1], data[2 * k + 2])

# [a_l, a_(l+1), ..., a_(r-1)]の最小値を求める
def query(l, r):
    L = l + N0
    R = r + N0
    s = float('inf')
    while L < R:
        if R & 1:
            R -= 1
            s = min(s, data[R - 1])

        if L & 1:
            s = min(s, data[L - 1])
            L += 1
        L >>= 1
        R >>= 1
    return s


# まずupdate()を使ってa_kの値を更新
for i in range(len(a)):
    update(i, -a[i])

from collections import defaultdict
dic = defaultdict(int)
for L in range(1, N):
    d = -a[L - 1] - query(L, N)
    if d > 0:
        dic[d] += 1

print(dic[sorted(dic.keys())[-1]])


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

using namespace std;


void solve() {
    int X; cin >> X;
    int n = X/100;
    for (int i = 1; i <= n; i++) {
        int r = X - (i*100);
        if (r <= 5*i) {
            cout << 1;
            return;
        }
    }
    cout << 0;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    solve();
    cout << endl;
}


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <vector>
#include <set>
#include <string>
#include <algorithm>
#include <cmath>

using namespace std;

const int CMax = 100002;

int n, y, s10, s5, s1;

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

    y /= 1000;

    s10 = y / 10;
    y %= 10;
    s5 = y / 5;
    y %= 5;
    s1 = y;

    if (s10 + s5 + s1 > n) {
        printf("-1 -1 -1\n");
        return 0;
    }

    while (s10 + s5 + s1 < n) {
        int sk = n - (s10 + s5 + s1);
        if (sk >= 4 && s5 > 0) {
            s5--;
            s1 += 5;
        } else if (sk >= 1 && s10 > 0) {
            s10--;
            s5 += 2;
        } else {
            printf("-1 -1 -1\n");
            return 0;
        }
    }

    printf("%d %d %d\n", s10, s5, s1);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define oo 1000000000
#define mod 1000000007
#define mod2 998244353
const int N = 1000010;
char a[N] , b[N];
int n , m;

map < long long , int > mp;

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

int main(){
    scanf("%d%d",&n,&m);
    scanf("%s%s",a,b);
    long long cur = (long long)n / gcd(n,m) * m;
    for(int i=0;i<n;i++){
        mp[(long long)cur / n * i + 1] = a[i];
    }
    for(int i=0;i<m;i++){
        if(mp[(long long)cur / m * i + 1] != 0 && mp[(long long)cur / m * i + 1] != b[i]){
            cout << -1 << endl;
            return 0;
        }
    }
    cout << cur << endl;
    return 0;
}

Measured memory_bytes: 10880
#include<bits/stdc++.h>
#define rep(i,N) for(int i=0;i<(N);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e12;
const int inf = 1e9;
const int mod = 1e9+7;
typedef long long ll;
typedef pair<ll,int> P;
typedef set<int> S;
int main(){
    cout << fixed << setprecision(10);
    string s;
    cin >> s;
    map<char, int> msi;
    for(auto u : s){
        msi[u]++;
    }
    int n = s.size();
    int a[] = { msi['a'], msi['b'], msi['c'] };
    if(n%3 == 0){
        for(auto u : a){
            if(u != n/3){
                cout << "NO" << endl;
                return 0;
            }
        }
        cout << "YES" << endl;
    }else{
        for(auto u : a){
            if(u != (n+2)/3 && u != n/3){
                cout << "NO" << endl;
                return 0;
            }
        }
        cout << "YES" << endl;
    }
    return 0;
}

Measured memory_bytes: 3768
#include<stdio.h>
#include<math.h>
#define Q 10
int main(void){
    int a[Q][Q],N,D,i,j,p,count=0;
    double sum;
    scanf("%d %d ",&N,&D);
    for(i=0;i<N;i++){
        for(j=0;j<D;j++){
            scanf("%d",&a[i][j]);
        }
    }
    for(i=0;i<N;i++){
        for(j=i+1;j<N;j++){
            sum=0;
            for(p=0;p<D;p++){
                sum+=pow(a[i][p]-a[j][p],2);
            }
            if(ceil(sqrt(sum)) == floor(sqrt(sum)))count++;
        }
    }
    printf("%d\n",count);
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define FOR(i,a,b) for(int i=(a); i<=(b); i++)
#define rep(i,n) for(int i = 0; i < (n); i++)
#define chmin(a,b) if((a)>(b)) (a)=(b);
#define chmax(a,b) if((a)<(b)) (a)=(b);
#define vi vector<int>
#define pii pair<int,int>
#define all(v) (v).begin(),(v).end()
#define allr(v) (v).rbegin(),(v).rend()
#define pb push_back
#define pf push_front
int gcd(int a,int b){/*a>=0,b>=0,￢(a=b=0)*/
  while(min(a,b)>0){if(a<b)swap(a,b);a%=b;}return max(a,b);
}
int dx[]={1,0,-1,0,1,-1,-1,1};
int dy[]={0,1,0,-1,1,1,-1,-1};
const int MOD = 1e9+7;
const int INF = 1e18+10;

/*----------------------------------------------*/


signed main(){
  int n,k;
  cin>>n>>k;
  vi a(n);
  rep(i,n)cin>>a[i];

  while(k--){
    vi b(n+1,0);
    rep(i,n){
      int x=max(0ll,i-a[i]),y=min(i+a[i],n-1);
      b[x]++;
      b[y+1]--;
    }
    rep(i,n){
      b[i+1]+=b[i];
    }
    b.pop_back();
    if(a==b) break;
    rep(i,n){
      a[i]=b[i];
    }
  }

  rep(i,n){
    cout<<a[i];
    if(i<n-1) cout<<' ';
  }
  cout<<endl;
  return 0;
}


Measured memory_bytes: 6316
#include <bits/stdc++.h>
using namespace std;
int main() {
	int n,m;
	while(cin>>n>>m,n,m){
		string str;
		for(int i=n;i>0;i--)str+=i-'0';
		for(int i=0,p,c;i<m;i++){
			string now;
			cin>>p>>c;
			for(int j=0;j<c;j++)now+=str[p-1+j];
			for(int j=0;j<n;j++)if(j<p-1||j>p+c-2)now+=str[j];
			str=now;
		}
		cout<<str[0]+'0'<<endl;
	}
}

Measured memory_bytes: 1208
#include <iostream>
#include <algorithm>
using namespace std;
using i64 = int64_t;
#define rep(i, j, n) for(int i = (j); i < (n); ++i)
constexpr i64 MOD = 1000000007;
constexpr i64 INF = 1LL << 60;

int main() {
	int n; cin >> n;
	int* a = new int[n];
	rep(i, 0, n) cin >> a[i];

	sort(a, a + n);

	bool ok = true;
	rep(i, 0, n) 
		ok &= a[i] == ((i + (n & 1)) / 2 * 2 + ((n ^ 1) & 1));

	i64 ans = 1;
	rep(i, 0, n / 2) ans = ans * 2 % MOD;
	cout << (ok ? ans : 0);
    delete[] a;
	return 0;
}

Measured memory_bytes: 3732
import java.io.IOException;
import java.io.InputStream;
import java.util.*;

public class Main {

    public static void main(String[] args) {
        FastScanner fs = new FastScanner();
        int N = fs.nextInt();

        int ans = 0;
        for (int i = 1; i <= N; ++i) {
            int tmp = i;
            int cnt = 0;
            while (tmp != 0) {
                tmp /= 10;
                ++cnt;
            }
            if (cnt % 2 == 1) ++ans;
        }

        System.out.println(ans);
    }
}

class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;

    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        }else{
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }

    private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
    private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
    public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}

    public String next() {
        if (!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while(isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }

    public long nextLong() {
        if (!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while(true){
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            }else if(b == -1 || !isPrintableChar(b)){
                return minus ? -n : n;
            }else{
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }

    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
        return (int) nl;
    }

    public double nextDouble() { return Double.parseDouble(next());}
}




Measured memory_bytes: 32464
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define rep(i, n) for(int i=0;i<n;++i)
#define rrep(i, n) for(int i=n;i>=0;--i)
const int inf=1e9+7;
const ll mod=1e9+7;
const ll big=1e18;
const double PI=2*asin(1);

int main() {
  int N, M;
  cin>>N>>M;
  int K;
  vector<vector<int> > L(N), L1(M);
  int tmp;
  for(int i=0;i<N;++i){
    cin>>K;
    for(int k=0;k<K;++k){
      cin>>tmp;
      L[i].push_back(tmp-1);
      L1[tmp-1].push_back(i);
    }
  }
  map<int, int> amap, bmap;
  queue<int> que;
  que.push(0);
  int state;
  while(!que.empty()){
    state = que.front();que.pop();
    if(amap[state]>0) continue;
    amap[state]++;
    for(int i=0;i<L[state].size();++i){
      if(bmap[L[state][i]]>0) continue;
      bmap[L[state][i]]++;
      for(int j=0;j<L1[L[state][i]].size();++j){
        if(amap[L1[L[state][i]][j]]>0) continue;
        que.push(L1[L[state][i]][j]);
      }
    }
  }
  bool ans = true;
  for(int i=0;i<N;++i){
    if(amap[i]==0) ans = false;
  }
  if(ans) cout<<"YES"<<endl;
  else cout<<"NO"<<endl;
}



Measured memory_bytes: 16300
//g++ main.cpp -I /usr/local/include/ac-library
#include<cmath>
//#include <atcoder/all>
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
//using namespace atcoder;
stack<int> st;
queue<int> qu;
priority_queue<int> pq;
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define rep2(i,n) for(int i=1; i<=(int)(n); i++)
#define mins(x,y) x=min(x,y)
#define maxs(x,y) x=max(x,y)
#define ALL(a) a.begin(), a.end()
typedef set<int> set_t;
typedef set<string> set_g;
typedef complex<double> xy_t;
static const int NIL = -1;
static const int INF = 1000000007;
#define mp make_pair
#define pb push_back
#define sz(x) (int)(x).size()
#define mod 1000000007
//#define mint=modint1000000007
#define reps(i,s,n) for(int i = s; i < n; i++)
#define Rreps(i,n,e) for(int i = n - 1; i >= e; --i)
#define Rrep(i,n) Rreps(i,n,0)
deque<int> deq;
#define fi first
#define se second
//const ll MOD = 998244353;
const ll MOD = (1e+9) + 7;
typedef pair<int, int> P;
typedef vector<ll> vec;
typedef vector<vec> mat;
int n, x, y, z;
int a[100000];
int main() {
	scanf("%d", &n);
	x = n;
	for (int i = 0; i < n; i++) {
		scanf("%d", a + i);
		if (a[i] < x)x = a[i];
		if (a[i] > y)y = a[i];
	}
	if (y - x > 1) {
		printf("No\n");
		return 0;
	}
	if (y == x) {
		if (y == n - 1)printf("Yes\n");
		else if (y <= n / 2)printf("Yes\n");
		else printf("No\n");
		return 0;
	}
	for (int i = 0; i < n; i++) {
		if (a[i] == x)z++;
	}
	if (z < y && y <= z + (n - z) / 2)printf("Yes\n");
	else printf("No\n");
    return 0;
}


Measured memory_bytes: 4096
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <math.h>
#include <deque>
using ll = long long;
using namespace std;

int main(){
    int a, b;
    cin >> a >> b;
    if(a==1) a+=13;
    if(b==1) b+=13;
    if(a==b) cout << "Draw" << endl;
    if(a>b) cout << "Alice" << endl;
    if(b>a) cout << "Bob" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;

const long double PI = acos(-1);
constexpr long double EPS = 1e-15;
constexpr int inf = 2e9;
constexpr ll INF = 2e18;
constexpr ll MOD = 1e9+7;
constexpr ll MOD1 = 998244353;
typedef pair<ll,ll> P;

//#define all(v) (v).begin(), (v).end()
#define rep(i,a,b) for (int i = (a); i < (b); i++)
#define REP(i,n) rep(i,0,n)
#define sz(s) (s).size()
#define pb push_back
#define fi first
#define se second
//#define mp make_pair

void solve() {
  double w,h,x,y;
  cin >> w >> h >> x >> y;
  cout << w * h / 2 << " " << (x == w/2 && y == h/2) << endl;
}

int main(int argc, char *argv[]){

  /*Regular*/
  int case_num = 1;
  if (argc > 1 && stoi(argv[1])) cin >> case_num;
  REP(case_no, case_num) {
    cerr << endl << "case " << case_no + 1 << endl;
    solve();
  }

  // /*ICPC*/
  // while (cin >> t >> d >> l, t) {
  //   solve();
  // }

  //solve();
  return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
namespace AOJ {
  public class AOJ {
    public static void Main(string[] args) {
      var n = int.Parse(Console.ReadLine());
      var mas = n % (60 * 60);
      var h = (n - mas) / 3600;
      var s = n % 60;
      var m = (mas - s) / 60;
      Console.WriteLine("{0}:{1}:{2}",h,m,s);
    }
  }
}

Measured memory_bytes: 9228
#include <iostream>
#include <map>
#include <set>
#include <vector>
#include <algorithm>
#include <math.h>
#include <cmath>
#include <deque>
#include <queue>
using namespace std;
 
typedef long long ll;
 
const int MAX_N = 3000;
int dp[MAX_N+1][MAX_N+1];
 
int main(){
   int N, T;
   cin >> N >> T;
   vector<pair<int, int>> a(N);
   for(int i = 0; i <= N-1; i++){
       int A, B;
       cin >> A >> B;
       a[i]= make_pair(A, B);
   }
   sort(a.begin(), a.end());
   
   for(int i = 0; i < N; i++){
        for(int j = 1; j < T; j++){
            if(j >= a[i].first ){
                dp[i+1][j] = max(max(dp[i][j], dp[i+1][j-1]), a[i].second+dp[i][j-a[i].first]);
            } else
                dp[i+1][j] = max(dp[i][j], dp[i+1][j-1]);
        }
        dp[i+1][T] = max(dp[i+1][T-1], dp[i][T-1]+a[i].second);
   }
   int ans = 0;
   for(int i = 1; i <= N; i++) ans = max(ans, dp[i][T]);
   cout << ans << endl;
}

Measured memory_bytes: 35456
def gaishin(p,q,r):
  a = ((q[0]-r[0])**2+(q[1]-r[1])**2)**(0.5) #qとrの間
  b = ((r[0]-p[0])**2+(r[1]-p[1])**2)**(0.5) #rとpの間
  c = ((p[0]-q[0])**2+(p[1]-q[1])**2)**(0.5) #pとqの間
  cosp = (b**2+c**2-a**2)/(2*b*c)
  cosq = (c**2+a**2-b**2)/(2*c*a)
  cosr = (a**2+b**2-c**2)/(2*a*b)
  if cosp >= 1: cosp = 1
  if cosp <= -1: cosp = -1
  if cosq >= 1: cosq = 1
  if cosq <= -1: cosq = -1
  if cosr >= 1: cosr = 1
  if cosr <= -1: cosr = -1
  sinp = (1-cosp**2)**(0.5)
  sinq = (1-cosq**2)**(0.5)
  sinr = (1-cosr**2)**(0.5)
  sin2p = 2*sinp*cosp
  sin2q = 2*sinq*cosq
  sin2r = 2*sinr*cosr
  if sin2p+sin2q+sin2r == 0:
    infinite = float("inf")
    return (infinite, infinite)
  x = (sin2p*p[0]+sin2q*q[0]+sin2r*r[0])/(sin2p+sin2q+sin2r)
  y = (sin2p*p[1]+sin2q*q[1]+sin2r*r[1])/(sin2p+sin2q+sin2r)
  #R = a/(2*sinp) #正弦定理による外接円
  return (x,y)

N = int(input())
A = []
for i in range(N):
  x,y = map(int,input().split())
  A.append((x,y))
INF = float("inf")
ans = INF
for i in range(N):
  for j in range(i+1,N):
    z = ((A[i][0]+A[j][0])/2,(A[i][1]+A[j][1])/2) #二点の中心
    dx = A[i][0]-A[j][0]
    dy = A[i][1]-A[j][1]
    hankei = ((dx**2+dy**2)**(0.5))/2
    Flag = True
    for t in range(N):
      if t == i or t == j: #選んだ二点ならスキップ
        continue
      temp = ((z[0]-A[t][0])**2+(z[1]-A[t][1])**2)**(0.5)
      hankei = max(hankei,temp)
    ans = min(ans,hankei)
#print(ans)
if N == 2:
  print(ans)
  exit()
for i in range(N):
  for j in range(i+1,N):
    for k in range(j+1,N):
      p = A[i]; q = A[j]; r = A[k]
      z = gaishin(p,q,r)
      #print(z)
      hankei = 0
      for t in range(N):
        temp = ((z[0]-A[t][0])**2+(z[1]-A[t][1])**2)**(0.5)
        hankei = max(hankei,temp)
      ans = min(ans,hankei)
print(ans)

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

int main() {
	string s; int a = 0, b = 0;	cin>>s;
	for(int i = 0 ;i<s.length();i++){
		a += s[i] == '1';
		b += s[i] == '0';
	}
	cout<<min(a,b)*2;
	return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
using namespace std;


int main()
{
	long long int K;
	long long int tmp;

	cin >> K;

	queue<long long int> que;
	for(int i=1; i<=9; i++){
		que.push(i);
	}

	for(int i=0; i<K; i++){
		tmp = que.front();
		que.pop();
		if(tmp%10 != 0){
			que.push(tmp*10 + tmp%10-1);
		}
		que.push(tmp*10 + tmp%10);
		if(tmp%10 != 9){
			que.push(tmp*10 + tmp%10+1);
		}
	}


	cout << tmp ;
	return 0;
}

Measured memory_bytes: 1792
//これ苦手
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <tuple>
#include <cstdio>
#include <cmath>
#define rep(i, n) for(i = 0; i < n; i++)
using namespace std;
typedef tuple<int, int, int> T;

struct BIT {
	int val[500002], n;
	BIT() {}
	
	BIT(int n) {
		this->n = n;
		int i; rep(i, n + 1) val[i] = 0;
	}
	
	void add(int p, int w) {
		for (int x = p; x <= n; x += x & -x) {
			val[x] += w;
		}
	}
	
	int sum(int p) {
		int ret = 0;
		for (int x = p; x > 0; x -= x & -x) {
			ret += val[x];
		}
		return ret;
	}
};

int n, q;
int c[500000];
vector<int> poses[500000];
int nr[500000];
T query[500000];
BIT seg(500001);
int ans[500000];

signed main() {
	int i, j;
	
	cin >> n >> q;
	rep(i, n) {
		cin >> c[i];
		c[i]--;
	}
	
	rep(i, n) {
		poses[c[i]].push_back(i);
	}
	
	rep(i, n) { nr[i] = n; }
	rep(i, n) {
		rep(j, (int)poses[i].size() - 1) {
			nr[poses[i][j]] = poses[i][j + 1];
		}
	}
	
	//rep(i, n) { cout << "nr[" << i << "] = " << nr[i] << endl; }
	
	rep(i, q) {
		int l, r;
		cin >> l >> r;
		l--; r--;
		query[i] = T(l, r, i);
	}
	sort(query, query + q);
	
	//nr[i]追加
	rep(i, n) {
		seg.add(nr[i] + 1, 1);
	}
	
	int cor = 0;
	rep(i, q) {
		int l = get<0>(query[i]);
		int r = get<1>(query[i]);
		int len = r - l + 1;
		
		//cout << "l, r = " << l << ", " << r << endl;
		
		//nr[i]削除
		while (cor < l) {
			seg.add(nr[cor] + 1, -1);
			cor++;
		}
		
		//和を求める
		int s = seg.sum(r + 1);
		
		//cout << "s = " << s << endl;
		
		ans[get<2>(query[i])] = len - s;
	}
	
	rep(i, q) cout << ans[i] << endl;
	return 0;
}

Measured memory_bytes: 44816
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

class IO {
    private static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    private static String[] buffers = new String[1];
    private static int cur=1;

    static BufferedReader getBr() {
        return br;
    }

    static String next() {
        String res = null;
        try {
            res = br.readLine();
            cur = buffers.length;
        } catch (IOException e) {
            e.printStackTrace();
        }
        return res;
    }

    static int nextInt() {
        if(buffers.length == cur) {
            buffers = next().split(" ");
            cur = 0;
        }
        return Integer.parseInt(buffers[cur++]);
    }

    static long nextLong() {
        if(buffers.length == cur) {
            buffers = next().split(" ");
            cur = 0;
        }
        return Long.parseLong(buffers[cur++]);
    }

    static double nextDouble() {
        if(buffers.length == cur) {
            buffers = next().split(" ");
            cur = 0;
        }
        return Double.parseDouble(buffers[cur++]);
    }

    static void out(Object... obj) {
        StringBuilder sb = new StringBuilder();
        for(Object o:obj) {
            sb.append(o);
        }
        System.out.println(sb);
    }

    static void outs(Object... obj) {
        StringBuilder sb = new StringBuilder();
        sb.append(obj[0]);
        for(int i=1; i<obj.length; i++) {
            sb.append(" ").append(obj[i]);
        }
        System.out.println(sb);
    }
}

public class Main {

    public static void main(String[] args) {
        int R = IO.nextInt(), G = IO.nextInt();
        System.out.println(2*G-R);
    }
}


Measured memory_bytes: 22996
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
template<class T, class U> inline bool chmax(T& a,U b) { if (a < b) { a = b; return 1; } return 0; }
template<class T, class U> inline bool chmin(T& a,U b) { if (a > b) { a = b; return 1; } return 0; }
const int MAX_N = 1001000;

int main() {
    string s;
    cin >> s;
    int n = s.length();
    long long dp[MAX_N][2];
    for (int i = 0; i < MAX_N; i++) dp[i][0] = dp[i][1] = 0;
    
    // dp[i][0] : ぴったり払う
    // dp[i][1] : 1多く払う
    dp[1][0] = s[0] - '0';
    dp[1][1] = 10 - (s[0] - '0');
    for (int i = 1; i < n; i++) {
        const int c = s[i] - '0';
        dp[i+1][0] = min(dp[i][0] + c, dp[i][1] + c + 1);
        dp[i+1][1] = min(dp[i][0] + 10 - c, dp[i][1] + 10 - (c + 1));
    }
    
    cout << min(dp[n][0], dp[n][1]+1) << endl;
    return 0;
}

Measured memory_bytes: 17028
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using u64 = unsigned long long;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

template <class T, class U>
vector<T> make_v(U size, const T& init){ return vector<T>(static_cast<size_t>(size), init); }

template<class... Ts, class U>
auto make_v(U size, Ts... rest) { return vector<decltype(make_v(rest...))>(static_cast<size_t>(size), make_v(rest...)); }

template<class T> void chmin(T &a, const T &b){ a = (a < b ? a : b); }
template<class T> void chmax(T &a, const T &b){ a = (a > b ? a : b); }

int main() {
    int n;
    cin >> n;
    vector<pair<ll, ll>> v(n);
    for (int i = 0; i < n; ++i) {
        scanf("%lld", &v[i].first);
        v[i].second = i;
    }
    sort(v.begin(),v.end());
    vector<vector<ll>> dp(n+1, vector<ll>(n+1));
    for (int i = 0; i < n; ++i) {
        for (int l = 0, r = i; r < n; ++l, ++r) {
            chmax(dp[l][r+1], dp[l+1][r+1]+v[i].first*(v[i].second-l));
            chmax(dp[l][r+1], dp[l][r]+v[i].first*(r-v[i].second));
        }
    }
    ll ans = 0;
    for (auto &&j : dp) for (auto &&i : j) chmax(ans, i);
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 34744
#include <iostream>

using namespace std;
typedef long long ll;
// 入力
ll n,r,temp,mini;

int main(){
	temp = -10e9-1;
	mini = 10e9+1;
	cin >> n;
	for(int i=0;i<n;i++){
		cin >> r;
		temp = max(temp,r-mini);
		if(mini > r)mini = r;
	}
	cout << temp << endl;
}

Measured memory_bytes: 1160
n, m = map(int, input().split())
switch = [list(map(lambda x:int(x)-1, input().split()))[1:] for _ in range(m)]
rest = list(map(int, input().split()))
ans = 0
for bit in range(1<<n):
    for j in range(m):
        on_sum = 0
        for i in range(n):
            if bit >> i & 1 and i in switch[j]:
                on_sum += 1
        if on_sum % 2 != rest[j]:
            break
    else :
        ans += 1
print(ans)



Measured memory_bytes: 9188
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
using namespace std;
int main(void){
    int a,b,c;
    cin>>a>>b>>c;
    if(a==b){
        cout<<c<<endl;
    }else if(b==c){
        cout<<a<<endl;
    }else{
        cout<<b<<endl;
    }
}

Measured memory_bytes: 256
import java.io.BufferedReader
import java.io.InputStream
import java.io.InputStreamReader
import java.util.*

fun main(args: Array<String>) {
    val sc = FastScanner(System.`in`)

    val x = sc.nextInt()
    val y = sc.nextInt()

    val m = listOf(300000, 200000, 100000)
    var sum = 0
    if (x == 1 && y == 1) sum += 400000
    if (x in 1..3) sum += m[x - 1]
    if (y in 1..3) sum += m[y - 1]

    println(sum)

}

class FastScanner(s: InputStream) {
    private var st = StringTokenizer("")
    private val br = BufferedReader(InputStreamReader(s))

    fun next(): String {
        while (!st.hasMoreTokens()) st = StringTokenizer(br.readLine())

        return st.nextToken()
    }

    fun nextInt() = next().toInt()
    fun nextLong() = next().toLong()
    fun nextLine() = br.readLine()
    fun nextDouble() = next().toDouble()
    fun ready() = br.ready()
}


Measured memory_bytes: 33740
#include <bits/stdc++.h>
using namespace std;
const long long inf = 1e18;
typedef long long ll;
typedef vector<ll> vl;
#define rp(i, f, t) for (int i = f; i < t; i++)
#define pr(i, f, t) for (int i = t - 1; i >= f; i--)
#define ca(n, a) rp(ca_i, 0, n) cout << a[ca_i] << ((ca_i == n - 1) ? "\n" : " ")
#define za(n, a) rp(za_i, 0, n) a[za_i] = 0
#define be(a) a.begin(), a.end()
int main()
{
    string alp[26] = {
        "a",
        "b",
        "c",
        "d",
        "e",
        "f",
        "g",
        "h",
        "i",
        "j"};
    ll n;
    cin >> n;
    vector<string> ans, ini, ans2;
    ans.push_back("a");

    rp(i, 0, n - 1)
    {
        ll s = ans.size();
        rp(j, 0, s)
        {
            set<char> sss;
            rp(kk, 0, ans[j].size())
                sss.insert(ans[j][kk]);
            rp(k, 0, sss.size() + 1)
            {

                ans2.push_back(ans[j] + alp[k]);
            }
        }
        ans = ans2;
    }
    sort(be(ans));
    rp(i, 0, ans.size())
    {
        if (ans[i].size() == n)
            cout << ans[i] << endl;
    }
}

Measured memory_bytes: 38796
#include <utility>
#include <stdio.h>
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<cmath>
#define REP(i, n) for (int i = 0; i < (n); i++)
#define YES(b) std::cout<< (b ? "YES" : "NO")
using namespace std;
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n, m, l, a[101] = {}, count = 0;
	cin >> n>>m>>l;
	a[n]++;
	count++;
	if (a[m] == 0) {
		a[m]++;
		count++;
	}
	if (a[l] == 0) {
		a[l]++;
		count++;
	}
	cout << count;
}


Measured memory_bytes: 256