akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()

typedef long long ll;
const int INF = 1000000000;
const long INF64 = 9223372036854775807;
const int MOD = 1000000007;

int main(){
	string s,t;
	std::cin >> s>>t;
	std::vector<int> r(26,-1),rr(26,-1);
	bool ans=true;
//	rep(i,26)han[i]=1;
	rep(i,s.size()){
		int ss=s[i]-97,tt=t[i]-97;
		

		if((r[ss]>=0&&r[ss]!=tt)||(rr[tt]>=0&&rr[tt]!=ss))ans=false;
		if(r[ss]==-1){
			r[ss]=tt;
		}
		if(rr[tt]==-1){
			rr[tt]=ss;
		}
	}
	if(ans)std::cout << "Yes" << std::endl;
	else std::cout << "No" << std::endl;
}

Measured memory_bytes: 776
n,y = map(int,input().split())

for i in range(n+1):
    for j in range(n-i+1):
        if 10000*i + 5000*j + 1000*(n-i-j) == y:
            print(i,j,n-i-j)
            break
    else:
        continue
    break
else:
    print(-1,-1,-1)

Measured memory_bytes: 9152
#include <iostream>
#include <stdio.h>
#include <math.h> 
#include <algorithm>
#include <numeric>
#include <functional>
#include <vector>
#include <string>
#include <numeric>
#include <bitset>
#include <queue>

using namespace std;


int main() {
	//input
	int a, b;
	cin >> a >> b;

	if (a*b%2 == 0) {
		cout << "No" << endl;
	}
	else {
		cout << "Yes" << endl;
	}

	return 0;
}

Measured memory_bytes: 256
L = gets.to_i

def make(n, l, ns, vs, n2s)
	if l == 1
		return
	end
	
	n_new = n + 1
	ns << n_new
	
	x = l / 2
	make(n_new, x, ns, vs, n2s)
	vs << [n, n_new, 0]
	vs << [n, n_new, x]
	
	if l % 2 == 1
		n2s << [n, l - 1]
	end
end

ns = [1]
vs = []
n2s = []

make(1, L, ns, vs, n2s)

last_n = ns[-1]

puts "#{last_n} #{vs.length + n2s.length}"

vs.each{|n1, n2, length|
	puts "#{n1} #{n2} #{length}"
}
n2s.each{|n, length|
	puts "#{n} #{last_n} #{length}"
}




Measured memory_bytes: 1788
#include <stdio.h>
#define n 3
int main(void){
	int a[n];
	int i,j,temp;
	for(i=0;i<n;i++)scanf("%d",&a[i]);
	for(i=0;i<n-1;i++){
		for(j=i+1;j<n;j++){
			if(a[i]>a[j]){
				temp=a[i];
				a[i]=a[j];
				a[j]=temp;
			}
		}
	}
	i=0;
	while(i<n){
		printf("%d",a[i]);
		i++;
		if(i==n)break;
		printf(" ");
	}
	printf("\n");
	return 0;
}



Measured memory_bytes: 1992
import itertools
import sys

n, k = map(int, input().split())
h = [int(input()) for _ in range(n)]

h = sorted(h)
cusum = [0] * n
for i in range(1, n):
    cusum[i] = cusum[i - 1] + h[i - 1]

m = 1e9
k -= 1
for i in range(k, n):
    m = min(m, h[i] - h[i - k])

print(m)


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

using namespace std ;
#define   ll long long
#define   null NULL
#define   double dll
#define   endl "\n"
#define   mp make_pair
#define   pb push_back
#define   ff first
#define   ss second

ll mod = (ll)(1e9 + 7);
ll inf = (ll)(1e17 + 17);

int main () {
	int x , y ;
	cin >> x >> y ;
	if (y > 4 * x) {
		cout << "No" ;
		return 0 ;
	}
	if (y % 2) {
		cout << "No" ;
		return 0 ;
	}
	if ((y % 4 == 0 || y % 2 == 0) && (4*x >= y && 2*x <= y) ){
		cout << "Yes"  ;
		return 0 ;
	}
	cout << "No" ;
	return 0 ;
}


Measured memory_bytes: 3620
import java.util.Scanner;

class Main {
  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);
    int a = scanner.nextInt();
    int b = scanner.nextInt();
    int c = scanner.nextInt();
    int count = 0;

    for (int i = a; i <= b; i++) {
      if (c % i == 0) {
        count += 1;
      }
    }

    System.out.println(count);
  }
}

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

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

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

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

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

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

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

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

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}
fn main() {
    input! {
    n: usize,
    rc: [(usize, usize); n]
    }
    let mut dp = vec![vec![0; n]; n];
    let ans = dfs(0, n - 1, &rc, &mut dp);
    println!("{}", ans);
}

fn dfs(i: usize, j: usize, rc: &Vec<(usize, usize)>, dp: &mut Vec<Vec<usize>>) -> usize {
    if dp[i][j] > 0 { return dp[i][j]; }
    if i == j {return 0}
    let res = if j - i == 1 {
        rc[i].0 * rc[i].1 * rc[j].1
    } else {
        let mut t = std::usize::MAX;
        for k in i..j {
            t = min(dfs(i, k, rc, dp) + dfs(k + 1, j, rc, dp) + rc[i].0 * rc[k].1 * rc[j].1, t)
        }
        t
    };
    dp[i][j] = res;
    res
}



Measured memory_bytes: 5048
#include<iostream>
#include<vector>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
int main()
{
    int n;
    cin>>n;
    vector<int> a(n-1,0);
    vector<int> b(n);
    rep(i,n-1) cin>>a[i];
    rep(i,n-1)
    {
        int j=a[i]-1;
        b[j]++;
    }
    
    rep(i,n) cout<<b[i]<<endl;

    return 0;
}

Measured memory_bytes: 4776
using System;
using System.Linq;
using System.Text;

namespace ALDS1_6_C {
    public class Card {
        public char Suit;
        public int Number;

        public override string ToString() {
            return Suit + " " + Number;
        }
    }

    public static class MyExtension {
        public static void QuickSort(this Card[] arr,int p,int r) {
            if (p < r) {
                int q = arr.Pertition(p, r);
                arr.QuickSort(p, q - 1);
                arr.QuickSort(q + 1, r);
            }
        }

        public static int Pertition(this Card[] arr, int p, int r) {
            Card x = arr[r];
            int i = p - 1;
            for (int j = p; j < r; j++) {
                if (arr[j].Number <= x.Number) {
                    i++;
                    arr.Replace(i, j);
                }
            }
            arr.Replace(i + 1, r);
            return i + 1;
        }

        public static void Replace(this Card[] arr, int indexA, int indexB) {
            Card temp = arr[indexA];
            arr[indexA] = arr[indexB];
            arr[indexB] = temp;
        }
    }

    class Program {
        static void Main(string[] args) {
            int n = int.Parse(Console.ReadLine());
            Card[] cards = new Card[n];
            for(int i = 0; i < n; i++) {
                string[] input = Console.ReadLine().Split(' ');
                cards[i] = new Card { Suit = input[0][0], Number = int.Parse(input[1]) };
            }
            Card[] stable = cards.OrderBy(c => c.Number).ToArray();
            cards.QuickSort(0, n - 1);

            StringBuilder sb = new StringBuilder();
            sb.AppendLine(cards.SequenceEqual(stable) ? "Stable" : "Not stable");
            foreach (Card card in cards)
                sb.AppendLine(card.ToString());
            Console.Write(sb);
        }
    }
}

Measured memory_bytes: 21664
#include <stdio.h>
#define N 100000
#define Q 100000
int binarySearch(int a,int b);
int S[N];

int main(){
  int i,n,q,T[Q],a=0;
  
  scanf("%d",&n);
  for(i=0;i<n;i++)scanf("%d",&S[i]);
   scanf("%d",&q);
  for(i=0;i<q;i++)scanf("%d",&T[i]);
  
  for(i=0;i<q;i++){
    a+=binarySearch(T[i],n);
  }

  printf("%d\n",a);

  return 0;
}

int binarySearch(int t,int n){
  int left,right,mid;
  left = 0;
  right = n;
  while(left < right){
    mid = (left + right)/2;
    if(S[mid] == t)    return 1;
    else if(t < S[mid])right=mid;
    else left = mid +1;
  }
  return 0;
}
  

Measured memory_bytes: 1192
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,a,b) for (ll i = (a); i < (b); i++)
#define REP(i,n) rep(i,0,n)

void solve() 
{
    string s;cin>>s;
    if(s=="SSS")cout<<0;
    else if(s=="RSS"||s=="SRS"||s=="SSR"||s=="RSR")cout<<1;
    else if(s=="RRS"||s=="SRR")cout<<2;
    else cout<<3;cout<<endl;
}

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

Measured memory_bytes: 3608
#include<bits/stdc++.h>
using namespace std;
int gcd(int a,int b);
int main(){
    int n;
    cin>>n;
    vector<int> a(n);
    for(int i=0;i<n;i++)cin>>a[i];
    int ans=a[0];
    for(int i=1;i<n;i++){
        ans=gcd(ans,a[i]);
    }
    cout<<ans<<endl;
    return 0;
}
int gcd(int a,int b){
    if(b==0)return a;
    else return gcd(b,a%b);
}


Measured memory_bytes: 640
N = int(input())
A = [int(i) for i in input().strip().split()]

count = 0
while True:
    exist_odd = False
    for a in A:
        if a % 2 == 1:
            exist_odd = True

    if exist_odd:
        break
    else:
        A = [a // 2 for a in A]
        count += 1

print(count)


Measured memory_bytes: 2940
import math
import numpy as np
from fractions import gcd
import fractions
import statistics
import collections
from functools import reduce
import itertools
from collections import defaultdict
import bisect

N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

A.sort()
C.sort()

ans = 0
for i in range(N):
    a_num = bisect.bisect_right(A,B[i]-1)
    c_num = N-bisect.bisect_left(C,B[i]+1)
    ans += a_num * c_num

print(ans)

Measured memory_bytes: 34008
n = int(input())
input_list = list(map(int, input().split()))
input_list.sort(reverse=True)
# aliceは奇数番目のものを、bobは偶数番目のものをとる
a = 0
b = 0
for i in range(n):
    if (i+1) % 2 == 1:
        a += input_list[i]
    else:
        b += input_list[i]
print(a - b)

Measured memory_bytes: 38384
#include<stdio.h>
int main(void)
{
 int n;
 int i=1;
 int num;
 int count;
 int max=1;
 scanf("%d",&n);
  if(n>=2)
   max=2;
  if(n>=4)
   max=4;
  if(n>=8)
   max=8;
  if(n>=16)
   max=16;
  if(n>=32)
   max=32;
  if(n>=64)
   max=64;
 printf("%d",max);
}

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

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

typedef long long int ll;

const ll INF=(ll)1e19;
//const int INF=(1<<30);

vector<int> eratosthenes(const int n){
  vector<bool> is_prime(n+1,true);

  vector<int> p;

  for(int i = 2; i <= n; i++){
    if(is_prime[i]){
      for(int j=2; j*i<=n; j++){
        is_prime[i*j]=false;
      }
      p.emplace_back(i);
    }
  }

  return p;
}

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

  int cnt=0;
  for(auto &i :eratosthenes(55555)){
    if(i%5==1){
      if(cnt>0)cout<<" ";
      cout << i;
      cnt++;
    }
    if(cnt==n)break;
  }
  cout << endl;

}



Measured memory_bytes: 892
"""
Problem A: 次期町長
https://onlinejudge.u-aizu.ac.jp/problems/1159
2≤ N ≤10000、1≤ K ≤10000、1≤ M ≤ Nß
"""
def solve(n, k, m):

    table = [i+1 for i in range(n)]
    taget = m-1
    while(len(table)>1):

        table.pop(taget)
        taget -= 1
        taget = (taget+k)%len(table)

    return table[0]

if __name__ == '__main__':
    ans = []
    while(True):
        n, k, m = map(int, input().split())
        if n == 0 and k == 0 and m == 0:
            break
        ans.append(solve(n, k, m))
    print(*ans, sep='\n')



Measured memory_bytes: 6024
#n=int(input())
a,b,x=map(int,input().split())
#l=list(map(int,input().split()))
#l=[list(map(int,input().split())) for i in range(n)]

import math

s=x/a
if x==a*a*b:
    print(0)
elif s<= a*b/2:
    c=2*s/b
    deg=math.degrees(math.atan(c/b))
    ans=90.0-deg
    print('{:.9f}'.format(ans))
else:
    s=a*b-s
    h=2*s/a
    deg=math.degrees(math.atan(a/h))
    ans=90.0-deg
    print('{:.9f}'.format(ans))


Measured memory_bytes: 3060
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <iomanip>
#include <stdio.h>
#include <numeric>
#include <math.h>
#include <algorithm>
#include <functional>
#include <string>
#include <array>
#include <vector>
#include <list>
#include <stack>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <deque>
#include <queue>
#include <complex>
#include <bitset>
#define full(c) c.begin(), c.end()
#define vector2d(name,type,h,w,init) vector<vector<type>> name(h,vector<type>(w,init)) 
const int PRIME = 1000000007;
const int INT_INF = 2147483647;
const long long int LL_INF = 9223372036854775807;
const double PI = acos(-1);
const double EPS = 0.000000001;
typedef unsigned long long int ull;
typedef long long int ll;
using namespace std;

int main(){
	//ios_base::sync_with_stdio(false);
	//cin.tie(NULL);
	ll n, m;
	cin >> n >> m;
	if (m > 2 * n) cout << n + (m - 2 * n) / 4 << endl;
	else cout << min(n, m / 2) << endl;
	return 0;
}

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

int main(){
    int n;
    cin>>n;
    int a[n],b[n];
    ll sum=0;
    int minb=INF;
    for(int i=0;i<n;i++){
        cin>>a[i]>>b[i];
        sum+=a[i];
        if(a[i]>b[i]){
            minb=min(minb,b[i]);
        }
    }
    if(minb==INF)cout<<0<<endl;
    else cout<<sum-minb<<endl;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define INF 0x3f3f3f3f
int main(){
	string n;
	cin>>n;
	int sum=0,len=n.length();
	for(int i=0;i<len;i++)
	{
		sum=sum+(n[i]-'0');
	}
	if(sum%9==0)
	cout<<"Yes"<<endl;
	else
	cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 3684
#include<stdio.h>
int main(void) {
    int n, p[21], i, j;
    scanf("%d",&n);
    for(i = 0; i < n; i++ ) {
        scanf("%d",&p[i]);
    }
    j = 0;
    for(i = 1; i < n-1; i++) {
        if(p[i-1]<p[i] && p[i] <= p[i+1]) {
            j ++;
        } else if(p[i+1] < p[i] && p[i] <= p[i-1]) {
            j ++;
        }
    }
    printf("%d\n",j);
    return 0;
}

Measured memory_bytes: 128
#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;

int main() {
#if _DEBUG
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	ios_base::sync_with_stdio(false); cin.tie(0);
	int n;
	string s;
	cin >> n >> s;
	n < 3200 ? cout << "red" : cout << s;
	return 0;
}


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

#define N 100

int main(){

  int x,top=0;
  char s[N];
  int num[N];

  while(scanf("%s",s)!=EOF){
    if(s[0] == '+'){
      num[top-2] = num[top-2] + num[top-1];
      top--;
    }else if(s[0] == '-'){
      num[top-2]=num[top-2]-num[top-1];
      top--;
    }else if(s[0] == '*'){
      num[top-2]=num[top-2]*num[top-1];
      top--;
    }else{
      num[top]=atoi(s);
      top++;
    }
  }
  printf("%d\n",num[0]);
  return 0;
}

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

int main()
{
    long long  N, D;
    cin >> N >> D;
    int res = 0;
    long long X, Y;
    for(int i=0;i<N;i++){
        cin >> X >> Y;
        if(X*X + Y*Y <= D*D) res++;
    }
    cout << res << endl;

    return 0;
}

Measured memory_bytes: 3632
#include <cstdio>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <cstring>
using namespace std;
const int MXN = 100010;

char s[MXN];
int w[26] = {};
int main()
{
    scanf("%s", s);
    int n = strlen(s);
    for (int i = 0; i < n; ++i)
        ++w[s[i] - 'a'];
    for (int i = 0; i < 26; ++i) if (!w[i])
    {
        putchar('a' + i);
        return 0;
    }
    puts("None");
    return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod = (int)1e9 + 7;
const int INF = (int)100100100;

int main() {
    ll N; cin >> N;
    //ll N,M; cin >> N >> M;
    //string S; cin >> S;
    //ll H,W; cin >> H >> W;
    vector<int> a(N+1);
    vector<int> b(N+1);
    for(int i=0;i<N+1;i++){
        cin >> a[i];
    }
    for(int i=0;i<N;i++){
        cin >> b[i];
    }
    b[N]=0;
    ll sum=0;
  	sum+=min(a[0],b[0]);
  	b[0]=max(b[0]-a[0],0);
    for(int i=1;i<N;i++){
      	sum+=min(a[i],b[i-1]);
      	a[i]=max(0,a[i]-b[i-1]);
        sum+=min(a[i],b[i]);
        b[i]=max(b[i]-a[i],0);
    }
  	sum+=min(a[N],b[N-1]);
  	a[N]=max(0,a[N]-b[N-1]);
    sum+=min(a[N],b[N]);
    cout << sum;
}

/*
トレンディモンスター...
 */



Measured memory_bytes: 1024
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
typedef long long ll;
typedef vector<int> vint;
#define rep(i,n) for (ll i = 0; i < (ll)(n); ++i)
#define rrep(i,j,n) for(ll i = (ll)(j); i < (ll)(n); i++)
#define mrep(i,n) for (ll i = (ll)(n); i > 0; i--)
#define be(v) (v).begin(), (v).end()
#define dcout cout << fixed << setprecision(20) 
ll INF = 1LL << 60;
ll mod = 1e9 + 7;
ll modn = 998244353;

int main() {
	ll n; cin >> n;
	string s="";
	while(n>0) {
		n--;
		ll md=n%26;
		s+=char('a'+md);
		n/=26;
	}
	reverse(be(s));
	cout << s << endl;
}

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

typedef long long ll;

vector<int> getDivisors(int x) {
    vector<int> ans;
    for(int i = 1; i * i <= x; i++) {
        if(x % i == 0) {
            ans.push_back(i);
            if(i != x / i) ans.push_back(x / i);
        }
    }
    return ans;
}

int main() {
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

    int n, k;
    cin >> n >> k;

    vector<int> a(n);
    int sum = 0;

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

        sum += a[i];
    }

    vector<int> divs = getDivisors(sum);
    int ans = 0;

    for(int d : divs) {
        vector<int> t = a;

        int totalSum = 0;

        for(int i = 0; i < n; i++) {
            t[i] %= d;

            totalSum += t[i];
        }

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

        int curSum = 0;

        for(int i = 0; i < n; i++) {
            curSum += t[i];
            int leftSum = d * (n - i - 1) - (totalSum - curSum);

            if(curSum == leftSum && curSum <= k) {
                ans = max(ans, d);
            }
        }

    }

    cout << ans << endl;

}

/**
*/


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

int main() {
	long a,b,c;
	cin>>a>>b>>c;
	long ans=0;
	if(a==b) ++ans;
	if(b==c) ++ans;
	if(c==a) ++ans;
	
	if(ans==1) cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 256
import math
N = int(input())

count = 0
for i in range(1, N+1):
  for j in range(i, N+1):
    k = N - i*j
    #print(i,j,k)
    if k >0:
      if i==j:
        count += 1
      else:
        count += 2
    else:
      break
print(count)

Measured memory_bytes: 9168
using System;
using static System.Console;
using System.Collections.Generic;
using System.Linq;

namespace Atcoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var nm = InputNumList();
            var n = nm[0];
            var m = nm[1];
            var a = InputNumList();

            var b = a.OrderBy(x => x).ToArray();

            var listDis = new List<int>();
            int ans = 0;
            if (n >= m)
            {

            }
            else
            {
                for (int i = 0; i < m - 1; i++)
                {
                    listDis.Add(b[i + 1] - b[i]);
                }
                listDis.Sort();
                listDis.Reverse();
                for (int i = 0; i < n - 1; i++)
                {
                    listDis.RemoveAt(0);
                }
                ans = listDis.Sum();
            }
            WriteLine(ans);
        }

        static int InputNum()
        {
            return int.Parse(ReadLine());
        }
        static List<int> InputNumList()
        {
            return ReadLine().Split(' ').Select(int.Parse).ToList();
        }
    }
}

Measured memory_bytes: 23264
#include<bits/stdc++.h> 
#define fo(i,a,b) for(i=a;i<=b;i++)
#define fd(i,a,b) for(i=a;i>=b;i--)
#define min(a,b) (a<b?a:b)
#define max(a,b) (a>b?a:b)
typedef long long ll;
using namespace std;
inline int read(){
	int n=0,f=1;char c;
	for(c=getchar();(c<'0'||c>'9')&&c!='-';c=getchar());
	if (c=='-') c=getchar(),f=-1;
	for(;c>='0'&&c<='9';c=getchar()) n=n*10+c-48;
	return n*f;
}
const int maxn=2e3+5;
char A[maxn],B[maxn];
struct ar{
	int l,r,id;
}w[maxn];
int i,j,t,n,s,mx,mi,now,ans,cnt;
bool cmp(ar a,ar b){
	return (a.r==b.r)?a.l<b.l:a.r<b.r; 
} 
bool bz[maxn];
int main(){
	scanf("%s%s",&A,&B);
	n=strlen(A);
	fo(i,0,n-1) if (B[i]=='1') break;
	if (i==n){
		fo(i,0,n-1) if (A[i]=='1') return puts("-1"),0;
		return puts("0"),0;
	}
	fo(i,0,n-1){
		for(j=i,t=0;B[j]!='1';j=(j==n-1)?0:j+1,t++);
		w[i+1].r=t;
		for(j=i,t=0;B[j]!='1';j=(j==0)?n-1:j-1,t--);
		w[i+1].l=t,w[i+1].id=i;
	}
	sort(w+1,w+1+n,cmp);
	ans=1e9;
	fo(s,-n+1,n-1){
		memset(bz,0,sizeof(bz));
		cnt=0;
		fo(i,0,n-1) cnt+=(bz[i]=A[i]!=B[(i+s+n)%n]);
		mi=min(s,0),now=n;
		int S=abs(s);
		fd(mx,n-1,max(0,s)){
			for(;now&&w[now].r>mx;now--)if (bz[w[now].id]) mi=min(mi,w[now].l);
			ans=min(ans,2*(mx-mi)-S+cnt);
		}
	}
	printf("%d\n",ans);
}

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

#define REP(i,n) for(ll i=0;i<n;++i)
#define RREP(i,n) for(ll i=n-1;i>=0;--i)
#define FOR(i,m,n) for(ll i=m;i<n;++i)
#define RFOR(i,m,n) for(ll i=n-1;i>=m;--i)
#define ALL(v) (v).begin(),(v).end()
#define PB(a) push_back(a)
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());
#define DUMP(v) REP(aa, (v).size()) { cout << v[a]; if (a != v.size() - 1)cout << " "; else cout << endl; }
#define INF 1000000001ll
#define MOD 1000000007ll
#define EPS 1e-9

const int dx[8] = { 1,1,0,-1,-1,-1,0,1 };
const int dy[8] = { 0,1,1,1,0,-1,-1,-1 };


using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
ll max(ll a, int b) { return max(a, ll(b)); }
ll max(int a, ll b) { return max(ll(a), b); }
ll min(ll a, int b) { return min(a, ll(b)); }
ll min(int a, ll b) { return min(ll(a), b); }
///(´・ω・`)(´・ω・`)(´・ω・`)(´・ω・`)(´・ω・`)(´・ω・`)///
bool comp(pii a, pii b) {
	if (a.first*a.first + a.second*a.second == b.first*b.first + b.second*b.second) {
		return a.first < b.first;
	}
	else {
		return a.first*a.first+a.second*a.second < b.first*b.first+b.second*b.second;
	}
}
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	vector<pii> v;
	FOR(i, 1, 151) {
		FOR(j, i + 1, 151) {
			v.push_back({ i,j });
		}
	}
	sort(ALL(v), comp);
	while (1) {
		int h, w;
		cin >> h >> w;
		if (!h)break;
		int c = find(ALL(v), make_pair(h, w)) - v.begin();
		cout << v[c + 1].first << " " << v[c + 1].second << endl;
	}

	return 0;
}

Measured memory_bytes: 3312
#include <functional>
#include <algorithm>
#include <iostream>
#include <numeric>
#include <iomanip>
#include <utility>
#include <cstdlib>
#include <cstring>
#include <sstream>
#include <bitset>
#include <vector>
#include <cstdio>
#include <ctime>
#include <queue>
#include <deque>
#include <cmath>
#include <stack>
#include <list>
#include <map>
#include <set>

using namespace std;

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

#define dump(x)  cerr << #x << " = " << (x) << endl
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb push_back

#define for_(i,a,b) for(int i=(a);i<(b);++i)
#define for_rev(i,a,b) for(int i=(a);i>=(b);--i)

struct Edge {
    int u, id, cost, day;
    Edge(int _u, int _id, int _cost = 0, int _day = 0) : u(_u), id(_id), cost(_cost), day(_day) {}
    
    bool operator > (const Edge& e) const {
        return cost > e.cost;
    }
};

int N, M, E, S, T, R;
vector< vector< Edge > > edges;
int eve[110];

int cost[110][1 << 10][110];

void solve() {
    for_(i,0,110) for_(j,0,1<<10) for_(k,0,110) cost[i][j][k] = (int)1e9;
    
    priority_queue< Edge, vector< Edge >, greater< Edge > > que;
    
    if (eve[S] >= 0) {
        que.push(Edge(S, 1 << eve[S], 0, 0));
        cost[S][1 << eve[S]][0] = 0;
    } else {
        que.push(Edge(S, 0, 0, 0));
        cost[S][0][0] = 0;
    }
    
    while (!que.empty()) {
        Edge e = que.top(); que.pop();
        
        if (cost[e.u][e.id][e.day] < e.cost) continue;
        
        // okarina
        if (cost[S][e.id][0] > e.cost + 1) {
            cost[S][e.id][0] = e.cost + 1;
            que.push(Edge(S, e.id, cost[S][e.id][0], 0));
        }
        
        if (e.day < R) {
            int esize = (int)edges[e.u].size();
            
            for_(i,0,esize) {
                Edge ei = edges[e.u][i];
                
                if (ei.id >= 0 && !(e.id >> ei.id & 1)) continue;
            
                int nxid = e.id, nday = e.day + 1;
                if (eve[ei.u] >= 0) {
                    nxid |= 1 << eve[ei.u];
                }
            
                if (cost[ei.u][nxid][nday] > e.cost + 1) {
                    cost[ei.u][nxid][nday] = e.cost + 1;
                    que.push(Edge(ei.u, nxid, cost[ei.u][nxid][nday], nday));
                }
            }
        }
    }
    
    int ans = (int)1e9;
    for_(j,0,1 << E) for_(k,0,110) ans = min(ans, cost[T][j][k]);
    if (ans == (int)1e9) cout << -1 << endl;
    else cout << ans << endl;
}

int main() {
    cin >> N >> M >> E >> S >> T >> R;
    
    edges.assign(N, vector< Edge >());
    for_(i,0,M) {
        int u, v;
        cin >> u >> v;
        edges[u].push_back(Edge(v, -1));
        edges[v].push_back(Edge(u, -1));
    }
    
    memset(eve, -1, sizeof(eve));
    for_(i,0,E) {
        int a, b, c;
        cin >> a >> b >> c;
        eve[c] = i;
        edges[a].push_back(Edge(b, i));
        edges[b].push_back(Edge(a, i));
    }
    
    solve();
}

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

int main() {
    int64_t N;
    cin >> N;
    vector<int64_t> A(N);
    vector<int64_t> kosu(N+1,0);//i番目にiの数
    for(int64_t i = 0; i < N; i++){
        cin >> A.at(i);
        int64_t tmp = A.at(i);
        kosu.at(tmp)++;
    }
    int64_t total = 0;
    for(int64_t j = 0; j < N+1; j++){
        total += kosu.at(j)*(kosu.at(j)-1)/2;
    }
    for(int64_t i = 0; i < N; i++){
        int64_t ans = total-kosu.at(A.at(i))+1;
        cout << ans << endl;
    }
}


Measured memory_bytes: 5760
import sys

def solve():
    input = sys.stdin.readline
    X, Y, A, B, C = map(int, input().split())
    P = [int(p) for p in input().split()]
    Q = [int(q) for q in input().split()]
    R = [int(r) for r in input().split()]
    P.sort(reverse = True)
    Q.sort(reverse = True)
    R.sort(reverse = True)
    pi, qi = 0, 0
    sumPQ = [0] * (X + Y + 1)
    for i in range(X + Y):
        #print(pi, qi)
        if pi == min(A, X):
            sumPQ[i + 1] = sumPQ[i] + Q[qi]
            qi += 1
        elif qi == min(B, Y):
            sumPQ[i + 1] = sumPQ[i] + P[pi]
            pi += 1
        elif P[pi] >= Q[qi]:
            sumPQ[i + 1] = sumPQ[i] + P[pi]
            pi += 1
        else:
            sumPQ[i + 1] = sumPQ[i] + Q[qi]
            qi += 1
    Ans = sumPQ[X + Y]
    rVal = 0
    for i in range(min(C, X + Y)):
        rVal += R[i]
        Ans = max(Ans, rVal + sumPQ[X + Y - i - 1])
    print(Ans)
    #print(sumPQ)
    return 0

if __name__ == "__main__":
    solve()

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

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

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

    // start
    int a, b, c;
    cin >> a >> b >> c;
    cout << ((a < c && c < b) || (a > c && c > b) ? "Yes" : "No") << endl;
    // end

    return 0;
}


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

using namespace std;

typedef long long int ll;

#define all(x) x.begin(),x.end()

const ll mod = 1e9+7;
const ll INF = 1e9;
const ll MAXN = 1e9;

int main()
{
	int n;
	cin >> n;
	if(n%2 == 0) cout << n;
	else cout << 2*n << endl;


	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int selectionSort(int *,int);

int main() {
  int i,j,k,sum,num;
  scanf("%d",&sum);

  int sei[sum];
  for(i=0;i<sum;i++)
    {
      scanf("%d",&sei[i]);
    }

  num = selectionSort(sei,sum);

  for(i=0;;i++)
    {
      printf("%d",sei[i]);
      if(i>=sum-1)break;
      printf(" ");
    }

  printf("\n%d\n",num);

  return 0;
}

int selectionSort(int *A,int N)
{
  int i,j,k,minj,num=0,tmp;

  for(i=0;i<N;i++)
    {
      minj = i;
      for(j=i;j<N;j++)
	{
	  if(A[j] < A[minj])
	    {
	      minj = j;
	    }
	}
      if(minj!=i)
	{
	  tmp = A[i];
	  A[i] = A[minj];
	  A[minj] = tmp;
	  num++;
	}
    }

  return num;
}

Measured memory_bytes: 604
// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>

#define FOR(i, a, b) for (int i = (a); i < int(b); ++i)
#define RFOR(i, a, b) for (int i = (b)-1; i >= int(a); --i)
#define REP(i, n) FOR(i, 0, n)
#define REP1(i, n) FOR(i, 1, int(n) + 1)
#define RREP(i, n) RFOR(i, 0, n)
#define RREP1(i, n) RFOR(i, 1, int(n) + 1)
#define ALL(c) begin(c), end(c)

int _ = (
#ifndef LOCAL
    std::cin.tie(nullptr), std::ios::sync_with_stdio(false),
#endif
    std::cout.precision(10), std::cout.setf(std::ios::fixed));

using ll = long long;
using ull = unsigned long long;
using ld = long double;
template <typename T> using vec = std::vector<T>;
using namespace std;

int main() {
  ll N;
  cin >> N;
  vec<ll> a(N);
  REP(i, N) {
    cin >> a[i];
    a[i]--;
  }

  set<pair<ll, ll>> res;
  REP(i, N) {
    if (a[a[i]] == i) {
      ll t = a[i], u = i;
      if (t > u) {
        swap(t, u);
      }
      res.emplace(t, u);
    }
  }
  cout << res.size() << endl;
  return 0;
}


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

#define rep(i, n) for(int i=0; i<n; ++i)
#define repit(it, li) for(auto it=li.begin(); it!=li.end(); it++)
#define ll long long int

int main(){
    int n, m;
    cin>>n>>m;
    int suma=0;
    rep(i, m){
        int a;
        cin>>a;
        suma+=a;
    }

    int ans= (n-suma>=0)?(n-suma):(-1);
    cout << ans << endl;
    return 0;
}


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

#include <ext/pb_ds/assoc_container.hpp> //required
#include <ext/pb_ds/tree_policy.hpp> //required

using namespace __gnu_pbds; 
using namespace std;

template <typename T> using ordered_set =  tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; 
typedef long long  ll;
typedef vector<ll> VL;
typedef vector<int> VI;
typedef pair<ll,ll> PLL;
typedef pair<int,int> PII;
#define pb push_back

#define F first
#define S second
#define SZ(a) int((a).size())
#define ALL(a) a.begin(),a.end()
#define fr(i,x,y) for(int i=x;i<y;i++)
#define frr(i,x,y) for(int i=x-1;i>=y;i--)
#define inf 1e18+1
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
const int mod=1000000007;
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
ll power(ll a,ll b){ll ans=1;while(b!=0){if(b&1){ans*=a;}a=a*a;b>>=1;}return ans;}
ll powerm(ll a,ll b){ll ans=1;while(b!=0){if(b&1){ans*=a;ans%=mod;}a=a*a;a%=mod;b>>=1;}return ans%mod;}
// string to integer stoi()
// string to long long stoll()
// string.substr(position,length);
// integer to string to_string();

void solve()
{
    ll l,r,d;
    cin>>l>>r>>d;
    ll ct=0;
    fr(i,l,r+1)
    {
        if(i%d==0)
            ct++;
    }
    cout<<ct<<endl;
    return;
}
int main()
{
    IOS;
    ll t=1;
    //cin>>t;
    while(t--)
    {
        solve();
    }
    return 0;
}
/* stuff you should look for
        * int overflow, array bounds
        * special cases (n=1?)
        * do smth instead of nothing and stay organized
        * WRITE STUFF DOWN
*/
// BITMASK:
// 1)When some constrall is of the order of 15-20, think of bitmask DP.
// 2)When some constrall is around 40, try out meet in the middle
// 3) See Strings,palindromes,prefix,suffix etc -> KMP,Z algorithm

Measured memory_bytes: 3628
#include <bits/stdc++.h>
#include <math.h>
#include <vector>
#include <queue>
#include <iomanip>
#include <string>
#include <algorithm>
using namespace std;
using Graph = vector<vector<int>>;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep_1 (i,j,n) for(int i=j;i<n;i++)
typedef long long ll;
typedef long l;
const ll l_INF = 101010101000;
const int INF = 1010101010;
const int dx[4] = {-1,0,1,0};
const int dy[4] = {0,-1,0,1};
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using pii = pair<int,int>;

int main(){
  int n; cin>>n;
  vi d(n); rep(i,n) cin>>d[i];
  sort(d.begin(),d.end());
  int k=n/2;
  cout<<d[k]-d[k-1]<<endl;
}


Measured memory_bytes: 3788
from math import atan2, hypot

def solve():
    N = int(input())
    engines = [tuple(map(int, input().split())) for _ in range(N)]

    engines.sort(key=lambda x: atan2(x[1], x[0]))

    ans = 0
    for L in range(N):
        for R in range(L, L+N):
            x, y = 0, 0
            for i in range(L, R+1):
                i %= N
                dx, dy = engines[i]
                x, y = x+dx, y+dy
            dist = hypot(x, y)
            if dist > ans:
                ans = dist

    print(ans)


solve()


Measured memory_bytes: 39024
#include <iostream>
#include <string>
#include <queue>
#include <stack>
#include <algorithm>
#include <list>
#include <vector>
#include <complex>
#include <utility>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <bitset>
#include <ctime>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cassert>
#include <cstddef>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <sstream>
#include <fstream>
#include <functional>

using namespace std;
#define REP(i, n) for (int (i) = 0; (i) < (n); (i)++)
#define FOR(i, a, b) for (int (i) = (a); (i) < (b); (i)++)
#define RREP(i, a) for(int (i) = (a) - 1; (i) >= 0; (i)--)
#define FORR(i, a, b) for(int (i) = (a) - 1; (i) >= (b); (i)--)
#define DEBUG(C) cerr << #C << " = " << C << endl;
using LL = long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<LL>;
using VVL = vector<VL>;
using VD = vector<double>;
using VVD = vector<VD>;
using PII = pair<int, int>;
using PDD = pair<double, double>;
using PLL = pair<LL, LL>;
using VPII = vector<PII>;
template<typename T> using VT = vector<T>;
#define ALL(a) begin((a)), end((a))
#define RALL(a) rbegin((a)), rend((a))
#define SORT(a) sort(ALL((a)))
#define RSORT(a) sort(RALL((a)))
#define REVERSE(a) reverse(ALL((a)))
#define MP make_pair
#define FORE(a, b) for (auto &&a : (b))
#define EB emplace_back
#define GREATER(T) T, VT<T> greater<T>
template<typename T> inline bool chmax(T &a, T b){if (a < b){a = b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if (a > b){a = b;return true;}return false;}

const int INF = 1e9;
const int MOD = INF + 7;
const LL LLINF = 1e18;

int main(void) {
    int H, W, N;
    cin >> H >> W >> N;

    cout << min((N + H - 1) / H, (N + W - 1) / W) << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
int gcd(int a, int b) {  
  return b != 0 ? gcd(b, a % b) : a;
}//MAX
int lcm(int a, int b) { 
   return a * b / gcd(a, b);
   }
//MIN
 main() {
int n;
cin >> n;
int che =0,chea=0;
for(int i=0;i<n;i++){
  int z;
  cin >> z;
  if(z%4==0)che++;
  else if(z%2==0)chea++;
}
che+=chea/2;
if(n%2==1){
  if(n/2<=che)cout <<"Yes"<<endl;
  else{
    cout << "No"<<endl;
  }
}
else if(n==2){
  if(che>=1)cout <<"Yes"<<endl;
  else cout << "No"<<endl;
}
else{
 if(n/2<=che)cout << "Yes"<<endl;
 else{
   cout <<"No"<<endl;
 }
}
 }
 


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
long  long int M=1000000007;
#define ll long long int
ll binaryExponentiation(int a,int b)

{

    if(b==0)
        return 1;
        if(b==1)
            return a;

      ll aux=binaryExponentiation(a,b/2);
      aux=(aux*aux)%M;

      if(b%2)
        aux=(aux*a)%M;

      return aux;





}




int main()

{
    int i,j;

    int n,a,b;
    cin>>n;
    cin>>a>>b;

    ll ans=binaryExponentiation(2,n);
    //cout<<ans<<endl;
    ans=(ans-1)%M;
    if(ans<0)
        ans+=M;

    ll evala=1;
    ll evalb=1;
    
        ll aux=1;
        for(i=0;i<a;i++)
            {evala=(evala*(n-i))%M;
            aux=(aux*(i+1))%M;            }

            //cout<<evala<<endl;

        evala=(evala* binaryExponentiation(aux,M-2))%M;

       // cout<<evala<<endl;

    


     
    
        aux=1;
        for(i=0;i<b;i++)
            {evalb=(evalb*(n-i))%M;
            aux=(aux*(i+1))%M;            }
            //cout<<evalb<<endl;

        evalb=(evalb * binaryExponentiation(aux,M-2))%M;
        //cout<<evalb;

    



    ans=(ans-evala)%M;
    if(ans<0)
            ans+=M;
     ans=(ans-evalb)%M;
     if(ans<0)
                ans+=M;
     cout<<ans<<endl;



    return 0;

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+1;
long long n,a[N],M=1e9,s,c;
int main()
{
	cin>>n;
	for(int i=1;i<=n;i++)
		cin>>a[i];
	for(int i=1;i<=n;i++)
	{
		M=min(M,abs(a[i])),s+=abs(a[i]);
		if(a[i]<0)
			c++;
	}
	if(c&1)
		cout<<s-2*M;
	else
		cout<<s;
	return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <map>
using namespace std;
int main(void){
    // Your code here!
    int N;
    cin >> N;
    map<string, int> str_map;
    for (int i=0; i<N; i++) {
        string str;
        cin >> str;
        if(str_map.find(str)==str_map.end())
            str_map[str] = 1;
        else
            str_map.at(str)++;
    }
    int max_value=0;
    for (auto p : str_map) {
        auto key = p.first;
        auto value = p.second;
        max_value=max(max_value,value);
    }
        for (auto p : str_map) {
        auto key = p.first;
        auto value = p.second;
        if (value==max_value)
            cout << key << endl;
    }
}

Measured memory_bytes: 25216
def solve(N):
    x, y = 0, 0
    for _ in range(N):
        ti, xi, yi = [int(n) for n in input().split()]
        diff_x = abs(xi - x)
        diff_y = abs(yi - y)
        distance = diff_x + diff_y
        left = abs(ti - distance)

        if ti >= distance and left % 2 == 0:
            continue
        else:
            return False
    return True


N = int(input())
if solve(N):
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define int long long int 
const int INF = 1001001001001001LL;


//(l, r]
vector<pair<int, int> > findminmax(vector<int> &vec, int l, int r){

    int sum = vec[r] - vec[l];
    int idx = upper_bound(vec.begin(), vec.end(), (vec[l] + sum / 2)) - vec.begin();

    vector<pair<int, int> >  res;
    //cout << l << " " << r << " " << idx << endl;
    //誤差+-1
    for(int k = -1; k <= 1; k++){
        int x = idx + k;
        int ma = vec[x] - vec[l];
        int mi = vec[r] - vec[x];
        if(x < l || r < x){
            //continue;
            //cout << x << " " << l << " " << r << endl;
            //cout << ma << " " << mi << endl;
        }

        if(ma < mi) swap(ma, mi);

        //cout << l << " " << r << " " << mi << " " << ma << endl;
        res.push_back({mi, ma});
    }

    return res;
}

signed main(){

    int n; cin >> n;
    vector<int> acc(n + 1, 0);        //累積和
    acc[0] = 0;

    for(int i = 1; i <= n; i++){
        cin >> acc[i];
        acc[i] += acc[i - 1];
        //cout << acc[i] << " ";
    }
    //cout << endl;

    
    
    //cout << acc[4] - acc[2] << endl;
    //1-indexed
    //(l, r] := acc[r] - acc[l]
    int ans = INF;
    for(int t = 2; t <= n - 2; t++){

        auto va = findminmax(acc, 0, t);
        auto vb = findminmax(acc, t, n);

        
        for(int i = 0; i < va.size(); i++){
            for(int j = 0; j < vb.size(); j++){
                int ma = max(va[i].second, vb[j].second);
                int mi = min(va[i].first, vb[j].first);
                //cout << t << " " << ma << " " << mi << endl;
                ans = min(ans, ma - mi);
            }
        }

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

Measured memory_bytes: 1792
import java.util.*;

class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int L[] = new int[N];
    for (int i = 0; i < N; i++) {
      L[i] = sc.nextInt();
    }
    Arrays.sort(L);
    int sum = 0;
    for (int i = 0; i < N - 1; i++) {
      sum += L[i];
    }
    if (sum > L[N - 1]) {
      System.out.println("Yes");
    } else {
      System.out.println("No");
    }
  }
}

Measured memory_bytes: 23764
#include<stdio.h>
int main(){
	struct Dice{
		int surface[6];
		int surface2[6];
		char s[100];
	};
	struct Dice d1;
	for(int i=0;i<6;i++){
	scanf("%d",&d1.surface[i]);
	d1.surface2[i] = d1.surface[i];
	}
	scanf("%s",d1.s);
	for(int i=0;i<100;i++){
		if(d1.s[i]=='\0') break;
		if(d1.s[i]=='S'){
			d1.surface2[0] = d1.surface[4];
			d1.surface2[1] = d1.surface[0];
			d1.surface2[2] = d1.surface[2];
			d1.surface2[3] = d1.surface[3];
			d1.surface2[4] = d1.surface[5];
			d1.surface2[5] = d1.surface[1];
		}
		else if(d1.s[i]=='E'){
			d1.surface2[0] = d1.surface[3];
			d1.surface2[1] = d1.surface[1];
			d1.surface2[2] = d1.surface[0];
			d1.surface2[3] = d1.surface[5];
			d1.surface2[4] = d1.surface[4];
			d1.surface2[5] = d1.surface[2];
		}
		else if(d1.s[i]=='W'){
			d1.surface2[0] = d1.surface[2];
			d1.surface2[1] = d1.surface[1];
			d1.surface2[2] = d1.surface[5];
			d1.surface2[3] = d1.surface[0];
			d1.surface2[4] = d1.surface[4];
			d1.surface2[5] = d1.surface[3];
		}
		else{
			d1.surface2[0] = d1.surface[1];
			d1.surface2[1] = d1.surface[5];
			d1.surface2[2] = d1.surface[2];
			d1.surface2[3] = d1.surface[3];
			d1.surface2[4] = d1.surface[0];
			d1.surface2[5] = d1.surface[4];
		}
		for(int j=0;j<6;j++){
			d1.surface[j] = d1.surface2[j];
		}
	}
	printf("%d\n",d1.surface2[0]);
	return 0;
}

Measured memory_bytes: 2732
import heapq
from heapq import heappush, heappop

n,m = map(int,input().split())

heap = list(map(int,input().split()))
heap = list(map(lambda x:-1*x, heap))
heapq.heapify(heap)

for i in range(m):
    a = heappop(heap)
    a = int(a / 2)
    heappush(heap,a)


print(-sum(heap))

Measured memory_bytes: 73196
#define _CRT_SECURE_NO_WARNINGS
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <functional>
#include <ccomplex>
#include <unordered_map>
#include <cstring>
#include <iostream>
#include <numeric>
#include <sstream>
#include <set>
#include <tuple>
#include <iomanip>
#include <bitset>

using namespace std;
#define MAX 1LL << 60

typedef long long ll;
typedef unsigned long long ull;

#define rep(i, s, e) for(ll i = s; i < e; i++)
#define repR(i, s, e) for(ll i = s; i > e; i--)
#define reft0(i, j) setfill('0') << setw(i) << j

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

int main(){
    ll A, B;
    cin >> A >> B;

    ll cntA = A / 2;
    ll cntA2 = A % 2;
    ll cntB = (B+1) / 2;
    ll cntB2 = (B+1) % 2;

    ll tempA = (cntA % 2) ^ ((cntA2 != 0) ? (A-1):0);
    ll tempB = (cntB % 2) ^ ((cntB2 != 0) ? B:0);

    ll ans = tempA ^ tempB;

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

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main() {
	cin.tie(0); ios::sync_with_stdio(false);
	int A, B, C, D, L; cin >> L >> A >> B >> C >> D;
	int kokugo = A / C, sugaku = B / D;
	if (A%C != 0)kokugo++;
	if (B%D != 0)sugaku++;
	cout << L - max(kokugo,sugaku) << endl;
}

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

#define rep(i, n) for(int i = 0; i < (n); i++)
using LL = long long;
using ULL = unsigned long long;

void solve() {
	int n = 0, s = 0, w = 0, e = 0;
	string S; cin >> S;
	rep(i, S.size()) {
		if (S[i] == 'N') n++;
		if (S[i] == 'S') s++;
		if (S[i] == 'W') w++;
		if (S[i] == 'E') e++;
	}
	if (n == 0 && s == 0);
	else if (n != 0 && s != 0);
	else { cout << "No" << endl; return; }
	if (w == 0 && e == 0);
	else if (w != 0 && e != 0);
	else { cout << "No" << endl; return; }
	cout << "Yes" << endl;
}

int main() {

	solve();

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <math.h>
#include <algorithm>
#include <queue>
using namespace std;

typedef long long ll;
const int maxn = 200200;

int main()
{
    int n;
    cin >> n;
    int a[n + 1];
    for (int i = 0; i < n; i++)
        cin >> a[i];
    for (int i = 0; i < n; i++){
        if (a[i] % 2 == 0 && a[i] % 3 != 0 && a[i] % 5 != 0){
            puts("DENIED");
            return 0;
        }
    }
    puts("APPROVED");
    return 0;
}





Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod=1000000007;
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,a,b) for(int i=a;i<b+1;i++)
#define Per(i,b,a) for(int i=b;i>=a;i--)

void bfs(int N,int X,int Y,int *k,int start){
    bool done[2000];
    queue<int> q;
    q.push(start);
    int d=0;
    rep(i,N) done[i] = false;
    while(1){
        int l = q.size();
        if(l==0) break;
        rep(i,l){
            int pos = q.front();
            q.pop();
            if(done[pos]) continue;
            if(pos-1>=0 && !done[pos-1]) q.push(pos-1); 
            if(pos+1<N && !done[pos+1]) q.push(pos+1); 
            if(pos==X && !done[X]) q.push(Y);
            if(pos==Y && !done[Y]) q.push(X);
            done[pos] = true;
            k[d]++;
        }
        d++;
    }
}

int main(){
    int N,X,Y;
    cin>>N>>X>>Y;
    X--;Y--;
    int k[2000];
    rep(i,N) k[i] = 0;
    rep(i,N){
        bfs(N,X,Y,k,i);
    }
    Rep(i,1,N-1){
        cout<<k[i]/2<<endl;
    }
    return 0;
}

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

int main(){
    int N;
    cin >>N;
    long long A[N];
    long long max=0;
    for(int i=0;i<N;i++){
        cin >> A[i];
        if(max<A[i]){
            max=A[i];
        }
    }
    bool *k;
    k=(bool*)calloc(max,sizeof(bool));
    for(int i=0;i<N;i++){
        if(k[A[i]]==false){
            k[A[i]]=true;
        }else{
            cout << "NO";
            return 0;
        }
    }

    cout << "YES";
    return 0;
}

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

ll gcd(ll a,ll b){
  return b?gcd(b,a%b) :a;
}
ll lcm(ll a,ll b){
  return a/gcd(a,b)*b;
}
ll f(ll x, int c, int d){
  ll res = x;
  res -= x/c;
  res -= x/d;
  res += x/lcm(c,d);
  return res;
}
int main() {
  ll a,b;
  int c,d;
  cin >> a >> b >> c >> d;
  cout << f(b,c,d)-f(a-1,c,d) << endl;
}

Measured memory_bytes: 256