akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
 
bool SecondCompare(const pair<int,int> &a,const pair<int,int> &b)
{
       return a.second<b.second;
}
 
bool SecondCompareDes(const pair<int,int> &a,const pair<int,int> &b)
{
       return a.second>b.second;
}
 
int n, ch, s,t,c;
int a[32][100001], ans[100001];
int main(){
    cin >> n >> ch;
    for(int i = 0; i < n; i++){
        cin >> s >> t >> c;
        a[c-1][s]++;
        a[c-1][t]--;
    }

    for(int i = 0; i < ch; i++){
        for(int j = 1; j < 100001; j++){
            if(a[i][j] == 1)    ans[j-1]++;
            else if(a[i][j] == -1)  ans[j]--;
        }
    }

    int ma = 0, cou = 0;
    for(int i = 0; i < 100001; i++){
        cou += ans[i];
        ma = max(ma, cou);
    }
    cout << ma << endl;
}

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

using namespace std;

#define INF 1000000007
#define LINF (1LL << 62)

typedef long long i64;
typedef pair<i64,i64> P;


int h,w;
string s[1010];
int ans[1010][1010];

int main(){
	cin >> h >> w;
	for(int i = 0; i < h; i++){
		cin >> s[i];
	}
	
	queue<pair<P, int>> q;
	for(int i = 0; i < h; i++){
		for(int j = 0; j < w; j++){
			if(s[i][j] == '#'){
				q.push(make_pair(make_pair(i,j),0));
			}
		}
	}
	
	for(int i = 0; i < h; i++){
		for(int j = 0; j < w; j++){
			ans[i][j] = INF;
		}
	}
	int dx[4] = {0,-1,0,1}, dy[4] = {1,0,-1,0};
	while(!q.empty()){
		pair<P, int> p = q.front();
		q.pop();
		int H = p.first.first, W = p.first.second, cnt = p.second;
		if(ans[H][W] <= cnt) continue;
		ans[H][W] = cnt;
		for(int i = 0; i < 4; i++){
			int nx = dx[i]+H, ny = dy[i]+W;
			if(nx < 0 || nx >= h || ny < 0 || ny >= w) continue;
			if(s[nx][ny] == '.'){
				q.push(make_pair(make_pair(nx,ny), cnt+1));
			}
		}
	}
	
	int ma = 0;
	for(int i = 0; i < h; i++){
		for(int j = 0; j < w; j++){
			ma = max(ma, ans[i][j]);
		}
	}
	cout << ma << endl;
	
	return 0;
}

Measured memory_bytes: 36444
import java.util.Scanner;
import java.util.StringJoiner;

public class Main implements Runnable {

    private static Scanner sc = new Scanner(System.in);

    public static void main(String[] args) {
        new Thread(null, new Main(), "", 128 * 1024 * 1024).start();
    }

    public void run() {
        int n = sc.nextInt();
        int[] arr = new int[n];
        int count = 0;
        int i;
        for (i = 3; count < n && i <= 55_555; i += 2) {
            boolean tmp = true;
            if (i % 5 != 1) {
                tmp = false;
            }
            if (tmp) {
                for (int j = 3; j <= Math.sqrt(i); j += 2) {
                    if (i % j == 0) {
                        tmp = false;
                        break;
                    }
                }
            }
            if (tmp) {
                arr[count] = i;
                count++;
            }
        }
        StringJoiner sj = new StringJoiner(" ");
        for (int prime : arr) {
            sj.add(String.valueOf(prime));
        }
        System.out.println(sj.toString());
    }
}

Measured memory_bytes: 23764
import sys
readline = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
#mod = 998244353
INF = 10**18
eps = 10**-7


N = int(readline())
A = list(map(int,readline().split()))
B = list(map(int,readline().split()))
Ka = sum(B)-sum(A)
Kb = Ka
for a,b in zip(A,B):
    if a > b:
        Kb -= a-b
    else:
        if (b-a)%2:
            Ka -= (b-a+1)//2
            Kb -= 1
        else:
            Ka -= (b-a)//2
print('Yes' if Ka >= 0 and Kb >= 0 else 'No')




Measured memory_bytes: 4596
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int main(){
 	string S,T;
	cin >>S>>T;
  	int ans;
 	ans = T.size();
 	for(int i = 0; i <= S.length() - T.length();i++){
      int diff =0;
      for(int j = 0;j < T.length(); j++){
 			if(S[i+j]!=T[j])diff++;
        }
    ans = min(ans,diff);
    }
 cout<<ans<<endl;
 }

Measured memory_bytes: 3608
#include <iostream>

using namespace std;

bool budget[1000001];
bool P[1000001];

void eratos()
{
	for( int i = 0;i < 1000001;i++ ) P[i] = true;
	P[0] = P[1] = false;
	for( int i = 0;i < 1000001;i++ ){
		if( P[i] ) for( int j = 2;j * i < 1000001;j++ ) P[i * j] = false;
	}
}

void prim( int n, int x, int *v )
{
	for( int i = 1;i <= n;i++ ) budget[v[i]] = true;

	for( int i = 1;i <= x;i++ ) if( budget[i] ) {
		for( int j = 1;j <= n;j++ ) if( i + v[j] < 1000001 )budget[i + v[j]] = true;
	}
	int i;
	for( i = x;i >= 2;i-- ) if( budget[i] && P[i] ){ cout << i << endl; break;}
	if( i == 1 ) cout << "NA" << endl;
}

int main(int argc, char const* argv[])
{
	int n,x;
	int v[31];

	eratos();

	while( cin >> n >> x && x != 0 ){
		for( int i = 1;i <= n;i++ ) cin >> v[i];
		for( int i = 0;i < 1000001;i++ ) budget[i] = false;

		prim( n, x, v );
	}

	return 0;
}

Measured memory_bytes: 0
package main

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

//Util
func nextStr() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func maxInt(a, b int) int {
	if a > b {
		return a
	} else {
		return b
	}
}

func minInt(a, b int) int {
	if a > b {
		return b
	} else {
		return a
	}
}

func absInt(a int) int {
	if a >= 0 {
		return a
	} else {
		return -a
	}
}

func absFloat64(a float64) float64 {
	if a >= 0 {
		return a
	} else {
		return -a
	}
}

func maxFloat64(a, b float64) float64 {
	if a > b {
		return a
	} else {
		return b
	}
}

func minFloat64(a, b float64) float64 {
	if a > b {
		return b
	} else {
		return a
	}
}

func str2Int(s string) int {
	n, _ := strconv.Atoi(s)
	return n
}

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

func pow(p, q int) int {
	return int(math.Pow(float64(p), float64(q)))
}

func isPrime(x int) bool {
	if x == 1 {
		return false
	}
	if x == 2 {
		return true
	}
	if x%2 == 0 {
		return false
	}

	b := true
	rootx := int(math.Sqrt(float64(x)))
	i := 3
	for i <= rootx {
		if x%i == 0 {
			b = false
			break
		}
		i += 2
	}
	return b
}

func PrimeFactors(n int) (pfs []int) {
	// Get the number of 2s that divide n
	for n%2 == 0 {
		pfs = append(pfs, 2)
		n = n / 2
	}

	// n must be odd at this point. so we can skip one element
	// (note i = i + 2)
	for i := 3; i*i <= n; i = i + 2 {
		// while i divides n, append i and divide n
		for n%i == 0 {
			pfs = append(pfs, i)
			n = n / i
		}
	}

	// This condition is to handle the case when n is a prime number
	// greater than 2
	if n > 2 {
		pfs = append(pfs, n)
	}

	return
}

//Main
const (
	initialBufSize = 10000
	maxBufSize     = 1000000
	mod            = 1e9 + 7
)

var (
	sc *bufio.Scanner = func() *bufio.Scanner {
		sc := bufio.NewScanner(os.Stdin)
		buf := make([]byte, initialBufSize)
		sc.Buffer(buf, maxBufSize)
		return sc
	}()
)

var w string

func main() {
	sc.Split(bufio.ScanWords)

	w = nextStr()
	N := len(w)
	m := make(map[string]int, N)

	for i := 0; i < N; i++ {
		s := string(w[i])
		//mapにkeyが存在するか判定
		if _, ok := m[s]; ok {
			m[s]++
		} else {
			m[s] = 1
		}
	}

	for _, v := range m {
		if v%2 == 1 {
			fmt.Println("No")
			return
		}
	}
	fmt.Println("Yes")
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
int main(){
  int H, W, K;
  cin >> H >> W >> K;
  vector<vector<char>> vec(H,vector<char>(W));
  for(int i=0; i<H; i++){
    for(int j=0; j<W; j++){
      cin >> vec.at(i).at(j);
    }
  }
  int ans = H*W;
  int N = H-1;
  for(int bit = 0; bit < (1 << N); bit++){
    map<int,bool> mp;
    for(int n=0; n<N; n++){
      if(bit & (1 << n)){
        mp[n+1] = true;
      }
    }
    vector<int> cnt(mp.size()+1,0);
    vector<int> pos(0);
    for(auto itr = mp.begin(); itr != mp.end(); itr++){
      pos.push_back(itr->first);
    }
    pos.push_back(H);
    int ans_x = mp.size();
    bool clear = true;
    for(int j=0; j<W; j++){
      int num = 0;
      bool over = false;
      for(int i=0; i<H; i++){
        if(i >= pos.at(num)){
          num++;
        }
        if(vec.at(i).at(j) == '1'){
          cnt.at(num)++;
        }
        if(cnt.at(num) > K){
          over = true;
        }
      }
      if(over){
        ans_x++;
        num = 0;
        for(int i=0; i<cnt.size(); i++){
          cnt.at(i) = 0;
        }
        for(int i=0; i<H; i++){
          if(i >= pos.at(num)){
            num++;
          }
          if(vec.at(i).at(j) == '1'){
            cnt.at(num)++;
          }
          if(cnt.at(num) > K){
            clear = false;
          }
        }
      }
    }
    if(clear){
      ans = min(ans,ans_x);
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10000000)
MOD = 10 ** 9 + 7
INF = 10 ** 15

N = int(input())
T = list(map(int,input().split()))
V = list(map(int,input().split()))

def calc_area(v1,v2,t,lim):
    if v1 > v2:
        v1,v2 = v2,v1
    if v2 == lim:
        if lim - v1 < t:
            return t*lim - (lim - v1)*(lim - v1)/2
        else:
            return (v1 + v2)*t/2
    else:
        if 2*lim - v1 - v2 < t:
            return t*lim - (lim - v1)*(lim - v1)/2 - (lim - v2)*(lim - v2)/2
        else:
            mid = (t + v2 - v1)/2
            return (mid + 2*v1)*mid/2 + (t - mid + 2*v2)*(t - mid)/2

def calc(N,T,V,maxv):
    ans = 0
    v = 0
    for i in range(N):
        next_v = min(v + T[i],maxv[i])
        ans += calc_area(v,next_v,T[i],V[i])
        v = next_v
    return ans

maxV = [0] * N
for i in range(N - 2,-1,-1):
    maxV[i] = min(maxV[i + 1] + T[i + 1],V[i],V[i + 1])
ans = calc(N,T,V,maxV) 
print(ans)

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

using namespace std;

int main(){
	int N; cin >> N;
  	char S[N];
  	for(int i = 0; i < N; ++i){
    	cin >> S[i];
      	if(S[i] == 'Y'){
          	cout << "Four" << endl;
          	return 0;
        }
    }
  	cout << "Three" << endl;
  	return 0;
}

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

int main(){
  int N;
  cin >> N;
  map<string, int> C;
  C["AC"] = 0;
  C["WA"] = 0;
  C["TLE"] = 0;
  C["RE"] = 0;
  string s;
  rep(i, N){
    cin >> s;
    C.at(s)++;
  }
  cout << "AC x " << C.at("AC") << endl; 
  cout << "WA x " << C.at("WA") << endl; 
  cout << "TLE x " << C.at("TLE") << endl; 
  cout << "RE x " << C.at("RE") << endl; 
}


Measured memory_bytes: 3640
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <iomanip>
#include <math.h>
#include <map>
using namespace std;

#define INF 1e9
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;


int main() {
    ll n, m;
    ll ans = 0;
    cin >> n >> m;
    vector<vector<ll>> a(n, vector<ll> (2));
    rep(i, n) {
        rep(j, 2) {
            cin >> a.at(i).at(j);
        }
    }
    sort(a.begin(), a.end());
    rep(i, n) {
        if (a.at(i).at(1) <= m) {
            m -= a.at(i).at(1);
            ans += a.at(i).at(0) * a.at(i).at(1);
        }
        else {
            ans += a.at(i).at(0) * m;
            goto last;
        }
    }
    last:
    cout << ans << endl;
}

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

#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 

#define ll long long
#define db double
#define el "\n"
#define ld long double
#define rep(i,n) for(int i=0;i<n;i++)
#define rev(i,n) for(int i=n;i>=0;i--)
#define rep_a(i,a,n) for(int i=a;i<n;i++)
#define tr(ds, it) for(auto it=ds.begin(); it!=ds.end(); it++)
#define rtr(ds, it) for(auto it=ds.rbegin(); it!=ds.rend(); it--)
#define all(ds) ds.begin(), ds.end()
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
typedef priority_queue <int> pq;
typedef vector< long long > vi;
typedef pair<long long, long long> ii;
#define o_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> 
#define graph vector<vi>

const ll mod = 1000000007;
ll po(ll x, ll n ){ 
  ll ans=1;
     while(n>0){
       if(n&1) ans=(ans*x)%mod;
       x=(x*x)%mod;
       n/=2;
     }
     return ans;
}



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

  int T=1;
  //cin >> T;
  while(T--){
    string s;
    ll k, cnt, f=0,g;
    cin>>s>>k;
    ll ant, ans=0;
    vi v;
    rep(i,s.length()){
      //cout<<i<<" ";

      char c=s[i];
      cnt=0;
      while(s[i]==c){
        cnt++;
        i++;
        if(i==s.length()) break;
      }
      i--;
      //cout<<i<<el;
      v.pb(cnt);
    }
    // rep(i,v.size()) cout<<v[i]<<" ";
    // cout<<el;
    if(v[0]==s.length()){
      cout<<(k*(s.length()))/2<<el;
      return 0;
    }
    else if(s[0]==s[s.length()-1]){
      if(v[0]%2 && v[v.size()-1]%2){
        ans+=(v[0]+v[v.size()-1])/2;
        f=1;
        g=ans;
      }
      else{
        ans+=v[0]/2+v[v.size()-1]/2;
      }
      //cout<<ans<<el;
    }
    else ans+=v[0]/2+v[v.size()-1]/2;
    //cout<<ans<<el;
    rep_a(i,1,v.size()-1) ans+=v[i]/2;
    if(!f) cout<<k*ans<<el;
    else{
      cout<<k*ans-g+v[0]/2+v[v.size()-1]/2<<el;
    }

  }

  return 0;
}

Measured memory_bytes: 256
# jsc2019-qualB - Kleene Inversion
from collections import Counter
from itertools import accumulate


def main():
    N, K = tuple(map(int, input().split()))
    A = tuple(map(int, input().split()))
    MOD = 10 ** 9 + 7
    C = list(Counter(A).values())
    ac = list(accumulate(C[:-1]))
    x = sum(i * j for i, j in zip(C[1:], ac)) % MOD
    y = sum(sum(b > a for b in A[i + 1 :]) for i, a in enumerate(A[:-1]))
    ans = (x * (1 + K) * K // 2) % MOD
    ans = (ans - y * K) % MOD
    print(ans)


if __name__ == "__main__":
    main()

Measured memory_bytes: 3564
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;

ll mod = 998244353;
const ld error = 1e-5;
const ld PI = acosl(-1); //const ld PI = acosl(-1)

#define FASTIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define eq(x, y) (fabs((x)-(y))<error)
#define bt(i) (1LL<<(i))

#define debug(x) cerr<<#x<<" = "<<(x)<<"\n"
#define hoise cerr<<"hoise - "<<__LINE__<<"\n"
#define tham getchar()
mt19937 rng((unsigned)chrono::system_clock::now().time_since_epoch().count()); //mt199937_64 for ll

inline ll MOD(ll x, ll m = mod)
{
    ll y = x % m;
    return (y >= 0) ? y: y+m;
}

const int inf = 1e9;
const ll infl = 1e18+1;
const int nmax = 50+10;
///===========================================  template  =======================================================

vector<pair<int, int> > facts[nmax];

int main(){
    FASTIO;
    int n;
    cin>>n;
    for(int i = 0; i<n; i++){
        int k;
        cin>>k;
        facts[i].resize(k);
        for(int j = 0; j<k; j++){
            cin>>facts[i][j].first>>facts[i][j].second;
            facts[i][j].first--;
        }
    }

    int ans = 0;
    for(int mask = 0; mask<bt(n); mask++){
        int k = __builtin_popcount(mask);
        bool ok = true;

        for(int i = 0; i<n && ok; i++){
            if((bt(i)&mask) == 0) continue;

            for(auto p: facts[i]){
                if(!(bt(p.first)&mask) != !(p.second))
                    ok = false;
            }
        }
        if(!ok) continue;
        ans = max(ans, k);
    }
    cout<<ans<<"\n";
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
#define MAX 100
int main(void){
    // Your code here!
    int n;
    cin >> n;
    int a;
    cin >> a;
    int A[MAX];
    for(int i = 0; i < a; i++)cin >> A[i];
    
    int b;
    cin >> b;
    int B[MAX];
    for(int i = 0; i < b; i++)cin >> B[i];
    
    int c;
    cin >> c;
    int C[MAX];
    for(int i = 0; i < c; i++)cin >> C[i];
    
    for(int i = 0; i < b; i++){
        for(int j = 0; j < c; j++){
            if(B[i] == C[j]) C[j] = -1;
        }
    }
    
    for(int i = 0; i < a; i++){
        for(int j = 0; j < c; j++){
            if(A[i] == C[j] && C[j]!= -1) C[j] = -2;
        }
    }
    int count = 0;
    for(int i = 0; i < c; i++){
        if(C[i] >= -1) count++;
    }
    cout << count << endl;
}



Measured memory_bytes: 3112
from itertools import combinations

N = int(input())
L = list(map(int,input().split()))

ls = list(combinations(L,3))

cnt = 0
for (i,j,k) in ls:
  if i != j and j != k and k != i:
    T = sorted([i,j,k])
    if T[2] < (T[0] + T[1]):
      cnt += 1
print(cnt)

Measured memory_bytes: 20616
#include <iostream>
#include <iomanip>
#include <vector>
#include <utility>
#include <algorithm>

using namespace std;

int main(){
    int N,M;
    cin >> N >> M;
    vector<vector<pair<long long,long long>>> year(N);
    for(long long i=0; i<M; i++){
        long long a;
        long long b;
        cin >> a >> b;
        year[a-1].push_back(make_pair(b,i));
    }
    long long ans[M];
    for(long long i=0; i<N; i++){
        sort(year[i].begin(),year[i].end());
        for(long long j=0; j<year[i].size(); j++){
            long long t = (i+1) * 1000000 + j + 1;
            ans[year[i][j].second] = t;
        }
    }
    for(long long i=0; i<M; i++){
        cout << setw(12) << setfill('0') << ans[i] << endl;
    }
    return 0;
}


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

typedef long long int ll;

const ll mod = 1000000000 + 7;

ll solve(int s, map<int,ll> &memo) {
    if (s == 0) {
        return 1;
    }
    if (memo.find(s) != memo.end()) {
        return memo.find(s)->second;
    }
    ll sum = 0;
    for (int i = 3; i <= s; i++) {
        int next = s - i;
        sum += solve(next, memo);
        sum %= mod;
    }
    memo[s] = sum;
    return sum;
}

int main () {

    int input;
    cin >> input;
    map<int, ll> memo;
    cout << solve(input, memo) << endl;
    return 0;
}

Measured memory_bytes: 3308
#include <stdio.h>
#include <string.h>

int main(void){
        char tcard[101],hcard[101];
        int n,i,res,tpoi=0,hpoi=0;
        scanf("%d",&n);
        for(i=0;i<n;i++){
                scanf("%s %s",tcard,hcard);
                res=strcmp(tcard,hcard);
                if(res==0){
                        tpoi++;
                        hpoi++;
                }else if(res>0)
                        tpoi+=3;
                else
                        hpoi+=3;
        }
        printf("%d %d\n",tpoi,hpoi);
        return 0;
}

Measured memory_bytes: 604
#include<stdio.h>
#include <algorithm>
#include<string.h>
using namespace std;
const int N = 2e5+10;
const int M = 24005;
const int MOD = 1e9+7;
int h,w,a,b;
long long f[N];
long long finv[N];
long long c(long long n,long long m) {
    long long ret=f[n];
    ret=(ret*finv[n-m])%MOD;
    ret=(ret*finv[m])%MOD;
    return ret;
}
long long calc(long long i,long long j) {
    return c(i+j-2,i-1);
}
long long qp(long long x,long long n) {
    long long ret=1;
    while (n) {
        if (n&1) ret=(ret*x)%MOD;
        n=n>>1;
        x=(x*x)%MOD;
    }
    return ret;
}
int main()
{
    int h,w,a,b;
    while(~scanf("%d%d%d%d",&h,&w,&a,&b))
    {
        memset(f,0,sizeof(f));
        memset(finv,0,sizeof(finv));
        f[0]=finv[0]=1;
        for (int i=1; i<=200000; i++) {
        f[i]=(f[i-1]*i)%MOD;
        finv[i]=qp(f[i],MOD-2);
        }
        long long ans=0;
    for (int i=1; i<=w-b; i++) {
        ans=(ans+(calc(a,i)*calc(h-a,w-i+1))%MOD)%MOD;
        ans=(ans+MOD)%MOD;
    }
    printf("%lld\n",ans);
    }
    return 0;
}


Measured memory_bytes: 3328
#include <bits/stdc++.h>
//#define int long long

using namespace std;
using LL = long long;
using P = pair<int, int>;

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

#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()

const int INF = (int)1e9;
const LL INFL = (LL)1e18;
const int MOD = (int)1e9 + 7;

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

    int a, b, c, x;
    cin >> a >> b >> c >> x;

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

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

#define MAX(p,q) ((p>q)?(p):(q))
#define MIN(p,q) ((p<q)?(p):(q))

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

int main(void)
{
  int a,b,c;
  scanf("%d%d%d",&a,&b,&c);
  int max,other;
  max = MAX(MAX(a,b),c);
  other = a+b+c-max;
  printf("%d\n",max*10+other);
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(){
	int A,B,sum=0;
  	scanf("%d %d",&A,&B);
  	if(A>B){
      sum=A;
      A--;
    }
  	else{
      sum=B;
      B--;
    }
  
  if(A>B) sum+=A;
  else sum+=B;
  
  printf("%d",sum);
  return 0;
}
  
  	
  

Measured memory_bytes: 128
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
 
namespace ConsoleApplication32
{
    class Program
    {  
      static void Main(){
		 int[] a = new int [10];
		 for(int b = 0;b<10;b++)
		 a[b] = int.Parse(Console.ReadLine());
		 int[] c = new int [10];
		 for(int d = 0;d<10;d++)
		 c[d] = int.Parse(Console.ReadLine());
		 Array.Sort(a);
		 Array.Sort(c);
		 Console.WriteLine("{0} {1}",a[9]+a[8]+a[7],c[9]+c[8]+c[7]);	      
		  }
		  }
		  }
      
      

Measured memory_bytes: 9184
from collections import Counter
N = int(input())
S = [input() for i in range(N)]

C = []

for s in S:
  cnt = Counter()
  for cha in s:
    cnt[cha] += 1
  C.append(cnt)

merged = C[0]
for c in C:
  cnt = Counter()
  for (key1, value1) in merged.items():
    for (key2, value2) in c.items():
      if key1 == key2:
        cnt[key1] = min(value1, value2)
  merged = cnt

ans = ""

for (key, value) in merged.items():
  ans += key * value

print("".join(sorted(ans)))

Measured memory_bytes: 3436
n = int(input())
cards = [[0 for i in range(13)] for j in range(4)]

for i in range(n):
    Input = input().split()
    if Input[0] == "S":
        cards[0][int(Input[1])-1]= 1
    if Input[0] == "H":
        cards[1][int(Input[1]) - 1] = 1
    if Input[0] == "C":
        cards[2][int(Input[1]) - 1] = 1
    if Input[0] == "D":
        cards[3][int(Input[1]) - 1] = 1

for i in range(4):
    for j in range(13):
        if cards[i][j] == 0:
            if i == 0:
                print("S",j+1)
            if i == 1:
                print("H",j+1)
            if i == 2:
                print("C", j + 1)
            if i == 3:
                print("D", j + 1)

Measured memory_bytes: 7692
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
#define rep(i,n) for (int i=0; i<n;++i)
#define rep_down(i,n) for (int i=n-1; i>=0;--i)
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; }
typedef long long ll;
using namespace std;
const ll MOD = 1000000007LL;
int A, B, C, D;

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

  cin >> A >> B >> C >> D;
  int ans = min(A, B) + min(C, D);

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

Measured memory_bytes: 256
N = int(input())
xyss = []
for i in range(N):
    A = int(input())
    xys = []
    for j in range(A):
        x, y = map(int, input().split())
        xys.append((x-1, y))
    xyss.append(xys)

ans = 0
for S in range(2**N):
    numHonest = 0
    isOK = True
    for i in range(N):  # 人i
        if (S>>i)&1 == 0:
            continue

        numHonest += 1
        xys = xyss[i]
        A = len(xys)
        for x, y in xys:  # 証言j
            if (S>>x)&1 != y:
                isOK = False
                break
        if not isOK:
            break

    if isOK:
        ans = max(ans, numHonest)

print(ans)


Measured memory_bytes: 3064
#include "bits/stdc++.h"
using namespace std;
char Str[105];

int main(){
    int i , j;
    scanf( "%s" , Str );
    i = 0;
    j = int(strlen(Str)) - 1;
    int Ans = 0;

    while( i <= j ){
        if( Str[i] != Str[j] ) ++Ans;
        ++i;
        --j;
    }

    printf( "%d\n" , Ans );
    return 0;
}

Measured memory_bytes: 256
#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;
typedef long double ld;

const int INF = 1e9;
const ld EPS = 1e-8;

vector<int> compressor(const vector<ll> &x_) {
  int n = x_.size();
  vector<ll> x = x_;
  vector<int> ret(n);
  sort(ALL(x));
  auto itr = unique(ALL(x));
  REP(i,n) ret[i] = lower_bound(x.begin(), itr, x_[i]) - x.begin();
  return ret;
}

template<class T>
struct BIT{
  vector<T> bit;
  BIT(int n) : bit(n, 0) {}
  void add(int k, T a) {
    for(int x = k; x < bit.size(); x |= x + 1) bit[x] += a;
  }
  T sum(int i, int j) {
    if(i == 0) {
      T S = 0;
      for(int k = j; k >= 0; k = (k & (k + 1)) - 1) S += bit[k];
      return S;
    }else{
      return sum(0, j) - sum(0, i - 1);
    }
  }
};

int main(){
  int N, K;
  cin >> N >> K;
  vector<int> a(N);
  REP(i,N) cin >> a[i];

  REP(i,N) a[i] -= K;
  vector<ll> b(N + 1, 0);
  REP(i,N) b[i + 1] = b[i] + a[i];

  vector<int> c = compressor(b);
  BIT<int> bit(N + 1);

  ll ret = 0;
  REP(i,N + 1) {
    ret += bit.sum(0, c[i]);
    bit.add(c[i], 1);
  }

  cout << ret << endl;
  return 0;
}



Measured memory_bytes: 4992
#include<iostream>
#include<vector>
#include<string>
#include<utility>
#include<algorithm>

typedef long long ll;

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

	int ans = (n+999)/1000;
	std::cout << ans * 1000 - n << std::endl;

	return 0;
}

Measured memory_bytes: 3628
import java.util.*;
import java.io.*;
 
public class Main {
  public static void main(String[] args) throws Exception{
    FastScanner sc = new FastScanner(System.in);
    int n = sc.nextInt();
    int m = sc.nextInt();
    int[] num = new int[m];
    for(int i = 0; i < m; ++i) {
      num[i] = sc.nextInt();
    }
    new Solution(n, m, num);
  }
}

class Solution {
  public Solution(int n, int m, int[] num) {
    long res = 0;
    for(int i = 0; i < m; ++i) {
      res += num[i];
    }
    if(res > n) System.out.println(-1);
    else System.out.println(n - res);
    // System.out.println(res);
  }
}

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

  public FastScanner(InputStream source) {
    in = source;
  }

  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: 33344
#include <bits/stdc++.h>
using namespace std;
 
#define   ipr         	pair<int, int>
#define   pb            push_back
#define   ff            first
#define   ss            second
#define   fr(i, j, k)   for (int i = j; i < k; i++)
#define   rf(i, j, k)   for (int i = j; i >= k;i--)
#define   int           long long
#define   ll 			unsigned long long
#define   ld            long double
#define   all(x)        x.begin(), x.end()
#define   rall(x)       x.rbegin(),x.rend()
#define   mp            make_pair
#define   inf           INT_MAX
#define   read_file();	freopen("input.txt", "r", stdin);	freopen("output.txt", "w", stdout);
#define   IOS           std::ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
 
const int Maxn  =  10000;
const ld  pi   =  acos(-1);
const int mod =  1000000007;
 
 
template<class T> ostream& operator <<(ostream &out,vector<T> &A){for(auto x:A) out<<x;return out;}
template<class T> ostream& operator <<(ostream &out,set<T> &A){for(auto x:A) out<<x<<" ";return out;}
template <class T1,class T2>T1 powr(T1 a,T2 b){T1 res = 1;fr(i,1,b+1)res = res*a;return res;}
int roundUp(int numToRound, int multiple)
{
 if(multiple == 0)
 {
  return numToRound;
 }

 int roundDown = ( (int) (numToRound) / multiple) * multiple;
 int roundUp = roundDown + multiple; 
 int roundCalc = roundUp;
 return (roundCalc);
}
 

 
int32_t main(){IOS
int x,y,a,b,c;
cin>>x>>y>>a>>b>>c;
vector<int>red(a),green(b),cl(c);
fr(i,0,a){
  
   cin>>red[i];
   
}
fr(i,0,b){
  
   cin>>green[i];
  
}
fr(i,0,c){
  
   cin>>cl[i];
  
}
sort(red.begin(),red.end());
reverse(red.begin(),red.end());
sort(green.begin(),green.end());
reverse(green.begin(),green.end());

sort(cl.begin(),cl.end());
reverse(cl.begin(),cl.end());

vector<int>cum(x+y+c);
fr(i,0,x)cum[i]=red[i];
fr(i,0,y)cum[i+x]=green[i];


fr(i,0,c){
   
  cum[x+y+i]=cl[i];
   
}
sort(cum.begin(),cum.end());
reverse(cum.begin(),cum.end());

int sum=0;
for(int i=0;i<x+y;i++){
   sum+=cum[i];
}

cout<<sum<<endl;

}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
#define REP(i, n) for(int i=0; i<n; i++)

int num[4];
int main(){
    for(int i = 0; i < 3; i++){
        int a, b;
        cin >> a >> b;
        a--, b--;
        num[a]++;
        num[b]++;
    }

    bool ans = true;
    for(int i = 0; i < 4; i++){
        int n = num[i];
        if(n >= 3) ans = false;
    }
    
    if(ans)
        cout << "YES" << endl;
    else
        cout << "NO" << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n,t,a,index;
    cin>>n>>t>>a;
    double arr[n],mini=INT_MAX;
    for(int i=0;i<n;i++)
    {
        int b;
        cin>>b;
        arr[i]=abs(a-(t-b*0.006));
        if(arr[i]<mini)
        {
            mini=arr[i];
            index=i;
        }
    }
    cout<<index+1;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
#define ll          long long int
#define ld          long double
#define pb          push_back
#define mp          make_pair
#define ff          first
#define se          second
#define endl        '\n'
#define fd(n)       fixed<<setprecision(n)
#define MAX         100000000000000000
#define MAXN        10000005
#define mod         998244353  
#define pi          3.1415926535897932384626433
 
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n,i,x,count=0;
    cin>>n;
    for(i=1;i<=n;i++){
        cin>>x;
        if(x%2==i%2 && i%2==1){
            count++;
        }
    }
    cout<<count;
}

Measured memory_bytes: 3632
#include <cstdio>
#include <vector>
#include <algorithm>
#include <cstring>
#include <cstdlib>

using namespace std;

int main() {
  int n, m, x;
  scanf("%d %d %d\n", &n, &m, &x);
  std::vector<int> a;
  for(int i=0; i<m; ++i) {
    int x;
    scanf("%d", &x);
    a.push_back(x);
  }
  int left = count_if(begin(a), end(a), [=](auto v){return v<x;});
  int right= count_if(begin(a), end(a), [=](auto v){return v>x;});
  printf("%d\n", min(left, right));
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
template<typename T = int> vector<T> create(size_t n){ return vector<T>(n); }
template<typename T, typename... Args> auto create(size_t n, Args... args){ return vector<decltype(create<T>(args...))>(n, create<T>(args...)); }
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	vector<int> s = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
	assert(s.size() == 32);
	int k; cin >> k;
	cout << s[k - 1] << endl;
	return 0;
}


Measured memory_bytes: 256
x = int(input())
for i in range(1, x+1):
    j = i
    if j % 3 == 0:
        print(f" {i}", end = "")
        continue
    while j > 1:
        if j % 10 == 3:
            print(f" {i}", end = "")
            break
        j = j // 10
print()



Measured memory_bytes: 5884
// Problem : A - Circle Pond
// Contest : AtCoder - AtCoder Beginner Contest 163
// URL : https://atcoder.jp/contests/abc163/tasks/abc163_a
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>
using namespace std;


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

    int r;
    cin >> r;
    cout << 2 * (3.14159265359) * r;
    
    return 0;
}


Measured memory_bytes: 3800
import java.util.*;

public class Main {

    void run() {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();

        if (n == 4) {
            System.out.println(4);
            System.out.println(1 + " " + 2);
            System.out.println(1 + " " + 3);
            System.out.println(4 + " " + 2);
            System.out.println(4 + " " + 3);
            return;
        } else if (n == 3) {
          System.out.println(2);
            System.out.println(3 + " " + 1);
            System.out.println(3 + " " + 2);
            return;
        }

        ArrayList<ArrayList<Integer>> ans = new ArrayList<>();
        if (n % 2 == 1) {
            ArrayList<Integer> a = new ArrayList<>();
            a.add(n);
            ans.add(a);
            n--;
        }
        for (int i = 1; i <= n / 2; i++) {
            ArrayList<Integer> a = new ArrayList<>();
            a.add(i); a.add(n - i + 1);
            ans.add(a);
        }

        int len = ans.size();
        int m = 0;
        for (int i = 0; i < len; i++) {
            m += ans.get(i).size() * ans.get((i + 1) % len).size();
        }

        System.out.println(m);
        for (int i = 0; i < len; i++) {
            for (int j: ans.get(i)) for (int k: ans.get((i + 1) % len)) {
                System.out.println(j + " " + k);
            }
        }
    }

    // 1 2 3 4 5

    void debug(Object...os) {
        System.err.println(Arrays.deepToString(os));
    }

    public static void main(String[] args) {
        new Main().run();
    }
}

Measured memory_bytes: 23764
using System;
using System.Linq;
using System.Collections.Generic;
class P
{
    static void Main()
    {
        int n = int.Parse(Console.ReadLine());
        int[] nm = Console.ReadLine().Split().Select(int.Parse).ToArray();

        long res = 1;
        for (int i = 0; i < nm.Length; i++)
        {
            res *= (((nm[i] + 1) % 2) + 1);
        }
        Console.WriteLine(power(3,n) - res);
    }

    static int power(int n, int m)
    {
        const int mod = 1000000007;
        long pow = n;
        long res = 1;
        while (m > 0)
        {
            if ((m & 1) == 1) res = (res * pow) % mod;
            pow = (pow * pow) % mod;
            m >>= 1;
        }
        return (int)res;
    }
}


Measured memory_bytes: 13268
#include<iostream>
#include<string>
#include<stdio.h>

char iota(int n){
  switch (n) {
    case 0: return '0';
    case 1: return '1';
    case 2: return '2';
    case 3: return '3';
    case 4: return '4';
    case 5: return '5';
    case 6: return '6';
    case 7: return '7';
    case 8: return '8';
    case 9: return '9';
  }
  return '0';
}

int main(){

  std::string num1;   //("10000");
  std::string num2;   //("990000");
  char sum[100]={};
  int n,i,j,flag=0,temp;

  std::cin >> n;
  //n=1;

  for(i=0;i<n;i++){
    for(j=0;j<100;j++){
      sum[j]='\0';
    }
    std::cin >> num1 >> num2;
    if(num1.size()<num2.size()){
      num1.swap(num2);
    }
    //std::cout << num1 << std::endl;
    //std::cout << num2 << std::endl;
    for(j=0;j<num1.size();j++){
      if(j<num2.size()){
        temp = (num1[num1.size()-j-1]-'0')+(num2[num2.size()-j-1]-'0');
      }
      if(j>=num2.size()){
        temp = num1[num1.size()-j-1]-'0';
      }
      if(flag){
      ++temp;
      flag = 0;
      }
      if(temp>9){
        temp -= 10;
        flag = 1;
      }
      sum[j] = iota(temp);
    }
    if(flag){
      sum[j] = '1';
      flag = 0;
    }
    //printf("%s\n",sum);
    j=0;
    while(sum[j]!='\0'){
      ++j;
    }
    //std::cout << j <<std::endl;
    if(j>80){
      std::cout << "overflow" << std::endl;
    }else{
      while(j>0){
        printf("%c",sum[j-1]);
        --j;
      }
      std::cout << std::endl;
    }
  }
}

Measured memory_bytes: 3144
# -*- coding: utf-8 -*-
import itertools

N = int(input())
An = list(map(int, input().split()))

dict1 = {}
for A in An:
    if A in dict1:
        dict1[A] += 1
    else:
        dict1[A] = 1

h,w = 0,0
for k,v in sorted(dict1.items(), key=lambda x: -x[0]):
    if v < 2:
        continue
    if v >= 4 and h == 0 and w == 0:
        h,w = k,k
        break
    if h == 0:
        h = k
        continue
    if w == 0:
        w = k
        break
print(h*w)


Measured memory_bytes: 24972
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>; 
using pll = pair<long long, long long>;
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007LL;
constexpr long long INF = 1001001001LL;
constexpr long long LINF = 1001001001001001001;
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define rept(i, j, n) for(int i=(j); i<(n); i++)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }


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

  vector<ll> res;
  for(int i=1; i<=n; i++){
    int num = n;
    int cnt = 0; 
    for(int x=1; x*x<num; x++){
      for(int y=x; (x*x + y*y + x*y)<num; y++){
        for(int z=y; (x*x + y*y + z*z + x*y + y*z + z*x)<=num; z++){
          ll tmp = x*x + y*y + z*z + x*y + y*z + z*x;
             if(tmp == i){
             if(x==y && y == z)cnt += 1;
             else if (x!=y && y != z && x != z)cnt += 6;
             else cnt += 3;
           } 
        }    
      }
    }
    res.push_back(cnt);
  }
  for(auto a: res)cout << a << ln;
}



Measured memory_bytes: 3592
inf = 10**9 + 7

n, W = map(int, input().split())
dp = []
w = []
v = []
for _ in range(n):
    dp.append([inf for _ in range(10**5+1)])
    line = list(map(int, input().split()))
    w.append(line[0])
    v.append(line[1])
dp.append([inf for _ in range(10**5+1)])
for i in range(n+1):
    dp[i][0] = 0
for i in range(n):
    for j in range(10**5+1):
        if j >= v[i]:
            dp[i+1][j] = min(dp[i][j], dp[i][j-v[i]]+w[i])
        else:
            dp[i+1][j] = min(dp[i][j], w[i])
ans = 0
for j in range(10**5+1):
    if dp[n][j] <= W:
        ans = j

print(ans)

Measured memory_bytes: 166704
S = input()
tmp1,tmp2 = 0,0
c1,c2 = 0,1
ans = 0
length = len(S)

for i in range(length):
	tmp1 += 1 if int(S[i]) == c1 else 0
	tmp2 += 1 if int(S[i]) == c2 else 0
	c1 = abs(c1 - 1)
	c2 = abs(c2 - 1)

ans = min(tmp1,tmp2)
print(ans)

Measured memory_bytes: 3188
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
typedef long long ll;

using namespace std;

// init {{{
struct ProconInit {
    static constexpr int IOS_PREC = 15;
    static constexpr bool AUTOFLUSH = false;

    ProconInit() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(IOS_PREC);
        if(AUTOFLUSH)
            cout << unitbuf;
    }
} PROCON_INIT;


const int NM = 101001;//ここを問題の制約を見ながらいじる．配列の確保に使う．
//int A[NM];//あまり褒められたことではないが関数の外側に配列を確保すると怒られにくい．

// Main program
void solve(){
  ll N,A,B;
  cin >> N ;
  cin >> A ;
  cin >> B ;

  ll out;
  
  /*
  if( ((B-A) <=B && (B-A) <= (N-A)) && (B-A)%2 == 0){
    out = (B-A)/2;
  }
  else if( ((B-A) <=B && (B-A) <= (N-A)) && (B-A)%2 != 0){
    out = (B-A+1)/2 + 1;
  }
  else{
    if( (N-B) > (A-1) ){
      out = B-1; 
    }
    else{
      out = N-A;
    }
  }
  */
  if( (B==N && A==N-1) || (A==1 && B==2) ){
    out = 1;
  }
  else if((B-A)%2 == 0){
    out = (B-A)/2;
  }
  else{
//    if( A==1 || B==N ){
//      out = ((B-A - 1)/2) + 1;      
//    }
//    else{
      if( (N-B) > (A-1) ){
        if(A<(B-2)){
          out = A+(B-A)/2;
        }
        else{
          out = B-1; 
        }
      }
      else{
        if(N-B<(N-A+2)){
          out = N-B+1+(B-A)/2;
        }
        else{
          out = N-A;
        }
      }
        //    }    
  }
 
  
  cout << out;
  return;
  

}

int main() {
    solve();
    return 0;
}







Measured memory_bytes: 256
// package atcoder;

import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        final Scanner in = new Scanner(System.in);
        final int X = in.nextInt();
        final int Y = in.nextInt();

        for (int k = 0; k <= X; ++k) {
            if (2*k + 4*(X - k) == Y) {
                System.out.println("Yes");
                return;
            }
        }
        System.out.println("No");
    }
}


Measured memory_bytes: 35672
#include <iostream>
#include <vector>
#include<algorithm>

using namespace std;

int main()
{
	int n, left, right, ansmin, sum=0;

	cin >> n;

	vector<int> w(n);
	vector<int> sw(n);
	vector<int> ab(n);

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

    for (int j=0; j < n; j++) {
			sum += w[j];
			sw[j] = sum;
		   }

	for (int t = 0; t < n; t++) {

		left = sw[t];
		right = sum - left;

		ab[t] = abs(right - left);
	}
	ansmin = ab[0];
	for (int k = 1; k < n; k++) {
		if (ansmin > ab[k]) ansmin = ab[k];
	}
	cout << ansmin;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
 
using namespace std;
 
int main(){
    int a,b;
    scanf("%d %d",&a,&b);
    if(a > b){
        printf("a > b\n");
    }else if(a < b){
        printf("a < b\n");
    }else{
        printf("a == b\n");
    }
}


Measured memory_bytes: 2596
# import sys
# import math #sqrt,gcd,pi
# import decimal
# import queue # queue
# import bisect
# import heapq # priolity-queue
# import time
# from itertools import product,permutations,\
    # combinations,combinations_with_replacement
# 重複あり順列、順列、組み合わせ、重複あり組み合わせ
# import collections # deque
# from operator import itemgetter,mul
# from fractions import Fraction
# from functools import reduce

mod = int(1e9+7)
# mod = 998244353
INF = 1<<50

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

def Divisors(a): # 約数列挙
    divisors = []
    for i in range(1,int(a**0.5)+1):
        if a%i==0:
            divisors.append(i)
            if i!=a//i:
                divisors.append(a//i)
    divisors.sort()
    return divisors

def main():
    n = int(input())
    c = input()
    red = 0
    for i in range(n):
        if c[i]=='R':
            red += 1
    ans = 0
    for i in range(red):
        if c[i]=='W':
            ans += 1
    print(ans)
    return

if __name__=='__main__':
    main()


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

int n, m;
vector<int> v[100004];

int main() {
	cin>>n>>m;
	for(int i = 0;i<n;i++){
		int a, b;
		cin>>a>>b;
		v[a].push_back(b);
	}
	priority_queue<int> pq;
	int ans = 0;
	for(int i = 1; i<=m; i++){
		for(int val : v[i])	pq.push(val);
		if(!pq.empty()){
			ans += pq.top();
			pq.pop();
		}
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 5632
import math
import itertools
N = int(input())
points = []
for _ in range(N):
    points.append(tuple(map(int, input().split(" "))))

distances = [[0 for _ in range(N)] for __ in range(N)]
for si in range(N):
    for ei in range(N):
        distances[si][ei] = ((points[si][0] - points[ei][0]) ** 2 +
                             (points[si][1] - points[ei][1]) ** 2) ** 0.5

total = 0
for route in itertools.permutations([i for i in range(N)]):
    for s, e in zip(route, route[1:]):
        total += distances[s][e]

print(total / math.factorial(N))

Measured memory_bytes: 3064
#include<bits/stdc++.h>				//written by thidailoc
using namespace std;				//team three wolves
typedef long long ll;
typedef vector<ll> vi;
typedef pair<ll,ll> pll;
#define fu(i,a,b)   for(ll i=a;i<b;i++)
#define fd(i,b,a)   for(ll i=b;i>=a;i--)
#define ms(a,x) 	memset(a, x, sizeof a)
#define prec(n) 	fixed<<setprecision(n)
#define pb(i)	    push_back(i)
#define popb()    	pop_back()
#define sc(a) 	    cin>>a
#define sc2(a,b)    cin>>a>>b
#define pr(a)	    cout<<a<<" "
#define pr2(a,b)    cout<<a<<" "<<b<<" "
#define lowb(a,n,x) lower_bound(a,a+n,x) -a
#define lowb2(a,x)	lower_bound(a.begin(),a.end(),x) -a.begin()
#define all(x) 		(x).begin(), (x).end()
#define sz(a) 		(ll)a.size()
#define le			length()						
#define re 			return 	
#define	mp(a,b)  	make_pair(a,b)
#define se			second
#define fi			first 
#define debug(x)    cerr << #x << " = " << x << endl
#define INPUT       freopen("locin.txt", "r", stdin)
#define OUTPUT      freopen("locout.txt", "w", stdout)

double const eps = 1e-6;
ll const Base=1e9+7,oo=1e17;
ll arr[1000000],mark[10000000];


ll Solves(){
//	INPUT;
	ll n,k,cnt=0,ans=0,x,p,test,sum=0,query,a,b,c,d;
	// PROCESSING IN HERE
	sc(n);
	fu(i,0,n){
		sc(x);
		mark[x/400]++;	
		if(x>=3200)cnt++;
	}
	x=0;
	fu(i,0,8)if(mark[i])x++;
	
	pr2(max(1LL,x),x+cnt);
	re 0;
}


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

Measured memory_bytes: 256
import java.util.Scanner;

public class Main{

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner scn=new Scanner(System.in);
		int n =scn.nextInt();
		long sum=0;
		for(int i=1;i<=n;i++){
			if(i%3!=0 &&i%5!=0){
				sum+=i;
			}
		}
      System.out.println(sum);
	}

}

Measured memory_bytes: 35776
import sys
sys.setrecursionlimit(1000000)
N,A,B,C = [int(x) for x in input().split()]
l = [int(input()) for _ in range(N)]

def calc(li):
    bam = [0]*4
    scr = [0]*4
    for index,i in enumerate(li):
        if(i == 0): continue
        scr[i] += 10 if bam[i]!=0 else 0
        bam[i] += l[index]
    scr[1] += abs(bam[1]-A)
    scr[2] += abs(bam[2]-B)
    scr[3] += abs(bam[3]-C)
    global ans
    ans = min(ans,sum(scr))

def dfs(num,li):
    if(num == N):
        exist = [0]*4
        mul = 1
        for i in li:
            exist[i]+=1
        for i in exist[1:]:
            mul *= i
        if(mul == 0): return 0        
        calc(li)
    else:
        for i in range(4):
            dfs(num+1,li+[i])


li1=[]
ans = 10**9
dfs(0,li1)
print(ans)


Measured memory_bytes: 3064
import java.util.*;
public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        String str = sc.next();
        char[] c = str.toCharArray();
        int  j=c.length, cnt=0;
        for(int i=0; i<j/2; i++){
            if(c[i] != c[j-1-i]){
                cnt++;
            }
        }
        System.out.println(cnt);
    }
}

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

int main() {
  string S;
  cin >>S;
  if(S.at(5)=='1'||S.at(6)=='5'||S.at(6)=='6'||S.at(6)=='7'||S.at(6)=='8'||S.at(6)=='9'){
    cout<<"TBD"<<endl;
  }
  else{
    cout<<"Heisei"<<endl;
  }
}

Measured memory_bytes: 256