akhauriyash/Code-Regression huggingface dataset:
n, k = (int(i) for i in input().split())

a = [int(i) for i in input().split()]

dic = {}

for i in range(n):
    if a[i] in dic:
        dic[a[i]] += 1
    else:
        dic[a[i]] = 1

ans_num= len(dic)-k
ans = 0


if ans_num <= 0:
    ans *= 0 
else:
    sort = sorted(dic.items(), key=lambda x:x[1])
    for i in range(ans_num):
        ans += sort[i][1]

print(ans)


Measured memory_bytes: 39044
import java.util.Scanner;

public class Main
{
	public static void main(String arg[])
	{
		Scanner in = new Scanner(System.in);
		while(in.hasNext())
		{
			int n= in.nextInt();
			if(n==0)
				return;
			int a=0;
			int b=0;
			while(n--!=0)
			{
				int x=in.nextInt();
				int y=in.nextInt();
				if(x>y)
					a+=x+y;
				else if(y>x)
					b+=x+y;
				else{
					a+=x;
					b+=y;	
				}	
			}
			System.out.println(a+" "+b);
		}
	}
}

Measured memory_bytes: 12000
#include <iostream>

int main(){
  long long K;
  std::cin >> K;

  long long r = K/50, m=K%50;
  long long ans[50];
  for(int i = 0; i < 50; i++){
    ans[i] = i+r;
  }
  for(int i = 0; i < m; i++){
    ans[i] += 51;
    for(int j = 0; j < 50; j++){
      ans[j] -= 1;
    }
  }

  std::cout << "50\n";
  for(int i = 0; i < 50; i++){
    std::cout << ans[i] << " ";
  }
  std::cout << std::endl;

  return 0;
}



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

int main() {
ll n;
cin>>n;
ll mon[200000];
ll sen[200000];

for(ll i=0;i<n+1;i++)cin>>mon[i];
for(ll i=0;i<n;i++)cin>>sen[i];
ll ans = 0;
for(int i=0;i<n;i++){
ans += min(mon[i],sen[i]);
if(mon[i]<sen[i]){
sen[i]-=mon[i];
ans+=min(mon[i+1],sen[i]);
mon[i+1]-=min(mon[i+1],sen[i]);
}
}
cout<<ans<<endl;
}



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

//短縮
#define rep(i,n) for(int i=0;i<(n);++i)
//sort()用
#define all(v) v.begin(), v.end()

#define PB(N) push_back(N)

using namespace std;

using Graph = vector<vector<int>>;

int main(){
  int N,K; cin >> N >> K;
  vector<int> p(N);
  vector<double> v(N);

  rep(i,N){
    cin >> p[i];
  }
  rep(i,N){
    rep(j,p[i]){
      v[i]+=(j+1)/(double)p[i];
    }
  }

  //累積和をする
  rep(i,N){
    if(i==0)continue;
    v[i] += v[i-1];
  }
  double vmax=0;

  rep(i,N-K+1){
    if(i==0){
      if(vmax<v[i+K-1]) vmax=v[i+K-1];
    }
    else{
      if(vmax<v[i+K-1]-v[i-1]) vmax=v[i+K-1]-v[i-1];
    }
  }
  printf("%.7lf",vmax);

  return 0;
}


Measured memory_bytes: 5628
#include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<queue>
#include<deque>
#include<regex>
#include<stack>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
#include<iomanip>
#define rep(i,n) for(int i=0;i<n;i++)

typedef int long long ll;
using namespace std;
typedef pair<int,int> P;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
const ll MOD=1e9+7;
static const int MAX = 100;
static const int INF = (1<<23);
template<class T> T gcd(T a, T b){return b? gcd(b,a%b) : a;}
template<class T> T lcm(T a,T b){return a / gcd(a,b)*b;}
int n,m,x;
vector<ll> c;
vector<int> a[100001];
int main(){
    cin>>n>>m>>x;
    c.resize(n+1);
    rep(i,n){
        cin>>c[i];
        rep(j,m){
            int aa;
            cin>>aa;
            a[i].push_back(aa);
        }
    }
    ll anss = MOD;



    for(int i=0;i<(1<<n);i++){
        int bit=i;
        vector<int> ans(m,0);
        ll asum = 0;
        for(int j=0;j<n;j++){
         if(bit&1){
             for(int k=0;k<m;k++){
                 ans[k]+=a[j][k];
             }
             asum+=c[j];
         }
         bit = bit>>1;
        }

        bool f = true;
        rep(ii,m){
            if(ans[ii]<x){
                f=false;
            }
        }

        if(f){
            anss=min(anss,asum);
        }
    }
    if(anss==MOD){
        cout<<-1<<endl;
    }else{
        cout<<anss<<endl;
    }








return 0;
}


Measured memory_bytes: 5988
#include<bits/stdc++.h>
using namespace std;
int main(){
    int a,b,c;cin>>a>>b>>c;
    if(a==b&&a!=c){
        cout<<"Yes"<<endl;
    }
    else if(b==c&&b!=a){
        cout<<"Yes"<<endl;
    }
    else if(c==a&&c!=b){
        cout<<"Yes"<<endl;
    }
    else{
        cout<<"No"<<endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long int  ll;
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL) ; cout.tie(NULL);

int main() {

    fastio;

    string s,t,u= "";
    vector<vector<ll>> dp(3005 , vector<ll>(3005));
    ll count = 0;

    cin >> s >> t;

    //OPTIMAL SUB-PROBLEM :

    // dp[i][j] = max length of the lcs

    // BASE CASE :

    for(ll i = 0; i < sizeof(t); i++) dp[0][i] = 0;
    for(ll i = 0; i < sizeof(s); i++) dp[i][0] = 0;

    // RECURSIVE RELATION :

    for(ll i = 1; i <= s.size(); i++)
    {
        for(ll j = 1; j <= t.size(); j++)
        {
            if(s[i-1] == t[j-1])
            {
                dp[i][j] = 1 + dp[i-1][j-1];
            }
            else dp[i][j] = max(dp[i-1][j] , dp[i][j-1]);
        }
    }

    ll i = s.size(), j = t.size(), p = dp[s.size()][t.size()];

    while (i > 0 && j > 0)
    {
        if (s[i-1] == t[j-1])
        {
            u[p-1] = t[j-1];
            i--; j--;p--;count++;
        }

        else if (dp[i-1][j] > dp[i][j-1])
            i--;
        else
            j--;
    }

    //OPTIMAL SOLUTION :

    for(ll i = 0; i < count; i++) cout << u[i];

    return 0;
}

Measured memory_bytes: 70912
#include <stdio.h>

int main() 
{

    int ninzu, syurui;
    int sunuke[101] = {0};
    int goukei;
    int tmp;
    scanf("%d %d", &ninzu, &syurui);

    for (int i = 0; i < syurui; i++ ) {
        scanf("%d", &goukei);
        for ( int j = 0; j < goukei; j++ ){
            scanf("%d", &tmp);
            sunuke[tmp-1]++;
        }
    }

    tmp = 0;
    for ( int i = 0; i < ninzu; i++ ){
        if ( sunuke[i] == 0 ){
            tmp++;
        }
    }
    printf("%d", tmp);

    return 0;
}



Measured memory_bytes: 1736
#include <algorithm>
#include <cstdio>
#include <map>

using namespace std ;

const int N=2e5+10 ;

int a[N] ;
int n , k ;

map<int,int> Mp ;

int main ()
{
	int i ;
	scanf("%d%d",&n,&k);
	for ( i=1 ; i<=n ; i++ )
		scanf("%d",a+i),
		(a[i]+=a[i-1])%=k;
	for ( i=1 ; i<=n ; i++ )
		a[i]-=i;
	for ( i=1 ; i<=n ; i++ )
		a[i]=(a[i]%k+k)%k;
	long long res=0 ;
	for ( i=0 ; i<=n ; i++ )
	{
		if ( i-k>=0 ) Mp[a[i-k]]--;
		res+=Mp[a[i]];
		Mp[a[i]]++;
	}
	// for ( i=0 ; i<n ; i++ )
	// 	for ( j=i+1 ; j<=n && j-k<i ; j++ )
	// 		a[j]-j==a[i]-i;
	printf("%lld\n",res);
	return 0 ;
}


Measured memory_bytes: 10368
def input():
    import sys
    return sys.stdin.readline().rstrip()


def main():
    import math
    import collections
    import itertools

    n = int(input())

    t_before, x_before, y_before = 0, 0, 0
    for _ in range(n):
        t, x, y = map(int, input().split())
        diff_t = t - t_before
        diff_d = abs(x - x_before) + abs(y - y_before)
        if diff_t >= diff_d and (diff_t - diff_d) % 2 == 0:
            t_before, x_before, y_before = t, x, y
            pass
        else:
            print("No")
            break
    else:
        print("Yes")



if __name__ == '__main__':
    main()

Measured memory_bytes: 3316
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
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; }

const int NIL = -1;
const int INF = (1<<21);
const long long MOD = 1e9+7;
const int di[] = {-1, 0, 1, 0};
const int dj[] = {0, -1, 0, 1};


int main() {
  int N; cin >> N;
  vector<pair<pair<string, int>, int>> S(N);
  for (int i = 0; i < N; ++i) {
    string s; int p;
    cin >> s >> p;
    S[i].first.first = s;
    S[i].first.second = p * (-1);
    S[i].second = i+1;
  }
  sort(S.begin(), S.end());
  for (int i = 0; i < N; ++i) cout << S[i].second << endl;
}


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

int main(){
    std::ios::sync_with_stdio(0);
    std::cin.tie(0);
    std::cout.tie(0);
    unordered_set<int> uset;
    int a[200],n;
    cin>>n;
    for(int i = 0;i<2*n;i++){
        cin>>a[i];
    }
    sort(a,a+2*n);
    int res = 0;
    for(int i = 0;i<2*n;i+=2){
        res +=a[i];
    }
    cout<<res<<"\n";
    return 0;
    
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> pi;
void solve(vector<int>&arr){
	long long ret = 0;
	for(int i=0; i<arr.size(); i++) ret+=arr[i];
	cout<<ret;
}
int main(){
	int n,m;
	cin>>n>>m;
	vector<int>arr(n);
	for(int i=0; i<n; i++) cin>>arr[i];
	vector<pi>op(m);
	for(int i=0; i<m; i++) cin>>op[i].second>>op[i].first;
	sort(arr.begin(),arr.end());
	sort(op.begin(),op.end());
	int p = 0;
	reverse(op.begin(),op.end());
	for(int i=0; i<op.size(); i++){
		int change_to = op[i].first;
		int change_num = op[i].second;
		while(p<arr.size() && change_num){
			if(arr[p]<change_to) arr[p] = change_to;
			else break;
			p++;
			change_num--;
		}
	}
	solve(arr);
}

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

int main() {
  
  int a,b;
  cin>>a>>b;
  
  if(a%2==0||b%2==0){
    cout<<"Even"<<endl;
  }
  
  else{
    cout<<"Odd"<<endl;
  }
  
}


Measured memory_bytes: 3568
import sys
input = sys.stdin.readline


def read():
    S = input().strip()
    return S,

def solve(S):
    k = []
    for s in S:
        if s != "B":
            k.append(s)
        elif len(k) > 0:
            k.pop()
    return "".join(k)

if __name__ == '__main__':
    inputs = read()
    print(solve(*inputs))


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

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;
#define NIL NULL

Node root;

Node treeMaximum(Node x){
  while(x->right!=NIL)x=x->right;
  return x;
}

Node treeMinimum(Node x){
  while(x->left!=NIL)x=x->left;
  return x;

}

Node treeSuccessor(Node x){
  Node y;
  if(x->right!=NIL)return treeMinimum(x->right);

  y=x->parent;
  while(y!=NIL && x==y->right){
    x=y;
    y=y->parent;
  }
  return y;
}


Node treeSearch(Node u, int w){
  while(u!=NIL&&w!=u->key){
    if(w<u->key)u=u->left;
    else u=u->right;
  }
  return u;
}

void insert(int w){
  Node y = NIL;
  Node x = root;
  Node z;

  z = malloc(sizeof(struct node));
  z->key = w;
  z->left = NIL;
  z->right = NIL;

  while(x!=NIL){
    y=x;
    if(z->key<x->key)
      x=x->left;
    else x=x->right;
  }
  z->parent=y;

  if(y==NIL)
    root=z;
  else if(z->key<y->key)
    y->left=z;
  else
    y->right=z;
    
}

void inParse(Node u){
  if(u==NIL){
      return;
  }
  printf(" %d",u->key);
  inParse(u->left);
  inParse(u->right);
}

void preParse(Node u){
  if(u==NIL){
      return;
  }
  preParse(u->left);
  printf(" %d",u->key);
  preParse(u->right);
}


int main(){
  int a,b,i,j;
  char d[20];
  int c[100];
  int e=0;
  scanf("%d", &a);

  for ( i = 0; i < a; i++ ){
    scanf("%s", d);
    
if ( d[0] == 'i' ){
      scanf("%d", &b);
      insert(b);
    } else if ( d[0] == 'p' ){
       
      preParse(root);
      printf("\n");
      inParse(root);
      printf("\n");
    } else if(d[0]=='f'){
        scanf("%d",&b);
   Node t = treeSearch(root, b);
      if ( t != NIL ) {
 printf("yes\n");
      }else{
          printf("no\n");
      }
    }
  }

  return 0;
}


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

int main(){

  int a;
  int out=0;
  for(int i=0;i<5;i++){
    cin >> a;
    if(a==0){
      out = i+1;
    }
    //cout << a << endl;
  }

  cout << out << endl;
}

Measured memory_bytes: 3624
using System;
using System.Linq;
using System.Diagnostics;
using System.Collections.Generic;
using static System.Math;

class P
{
    static void Main()
    {
        long n = long.Parse(Console.ReadLine());
        int min = 100;
        for (int i = 1; i <= 100000; i++)
        {
            if (n % i != 0) continue;
            min = Min(min, Max(i.ToString().Length, (n / i).ToString().Length));
        }
        Console.WriteLine(min);
    }
}

Measured memory_bytes: 13140
import java.util.*;
public class Main {

	public static void main(String[] args) {
		Scanner seer = new Scanner(System.in);
		int n = seer.nextInt();
		int[] arr = new int[n];
		int[] gcdleft = new int[n];
		int[] gcdright = new int[n];		
		for(int i = 0; i < n; i++){
			arr[i] = seer.nextInt();
		}
		int g = 0;
		for(int i = 0; i < n; i++){
			gcdleft[i] = gcd(g, arr[i]);
			g = gcdleft[i];
		}
		g = 0;
		for(int i = n-1; i >= 0; i--){
			gcdright[i] = gcd(g, arr[i]);
			g = gcdright[i];
		}
		int maxgcd = 0;
		for(int i = 0; i < n; i++){
			int currg = gcd(i==0?0:gcdleft[i-1], i==n-1?0:gcdright[i+1]);
			maxgcd = Integer.max(maxgcd, currg);
		}
		System.out.println(maxgcd);
	}
	static int gcd(int a, int b){
		if(a < b) return gcd(b, a);
		if(b == 0) return a;
		else return gcd(b, a%b);
	}
}


Measured memory_bytes: 59184
import java.util.Scanner;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    while(true){
      int H = Integer.parseInt(sc.next());
      int W = Integer.parseInt(sc.next());
      if(H == 0 && W == 0){
        break;
      }
      for(int i = 0; i < H; i ++){
        for(int j = 0; j < W; j++){
          System.out.printf("#");
        }
        System.out.printf("\n");
      }
      System.out.printf("\n");
    }
  }
}


Measured memory_bytes: 62756
n = int(input())
list_a = list(map(int, input().split()))

max_a = [-1, -1]
for i in range(n):
  if abs(list_a[i]) > max_a[1]:
    max_a = [i, abs(list_a[i])]

print(2 * n - 1)
for i in range(n):
  print(max_a[0]+1, i+1)
if list_a[max_a[0]] > 0:
  for i in range(n-1):
    print(i+1, i+2)
else:
  for i in range(n-1)[::-1]:
    print(i+2, i+1)

Measured memory_bytes: 3064
// failed to generate code

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
vector<pair<string,P> >vec;
vector<ll> cur(1000);

int main(){	
	ll N;
	cin >> N;
	vector< vector<ll> > A(N, vector<ll>(N));
	rep(i, N) {
		rep(j, N-1) {
			cin >> A[i][j];
			A[i][j]--;
		}
	}
	ll res = 0, mincur = 0;
	queue<ll> que;
	rep(i,N) {
		que.push(i);
	}
	while(mincur < N-1) {
		queue<ll> newque;
		vector<ll> oldcur(N);
		rep(i,N) {
			oldcur[i] = cur[i];
		}

		vector<bool> used(N);
		while(!que.empty()) {
			ll i = que.front();
			que.pop();
			if (!used[i] && !used[A[i][oldcur[i]]] && oldcur[i] < N-1 && oldcur[A[i][oldcur[i]]] < N-1 && i == A[A[i][oldcur[i]]][oldcur[A[i][oldcur[i]]]]) {
				used[i] = true;
				used[A[i][oldcur[i]]] = true;
				cur[A[i][oldcur[i]]]++;
				cur[i]++;
				newque.push(A[i][oldcur[i]]);
				newque.push(i);
			}
		}

		ll now = INF;
		rep(i,N) {
			now = min(now, cur[i]);
		}
		mincur = now;

		bool minus = true;
		rep(i,N) {
			// cout << cur[i];
			if (oldcur[i] != cur[i]) {
				minus = false;	
			}
		}
		// cout << endl;
		if (minus) {
			printf("-1\n");
			return 0;
		}
		res++;
		while(!newque.empty()) {
			que.push(newque.front());
			newque.pop();
		}
	}
	cout << res << endl;
	return 0;
}


Measured memory_bytes: 8192
#include <stdio.h>

int main(void){

  long n,m;
  scanf("%ld %ld", &n, &m);
  long p[m];
  char s[m][2];
  for (long i = 0; i < m; i++) {
    scanf("%ld %c%c", &p[i], &s[i][0], &s[i][1]);
  }

  long list[n][2];
  for (long i = 0; i < n; i++) {
    list[i][0] = 0;
    list[i][1] = 0;
  }

  long ac_count = 0;
  long wa_count = 0;
  for (long i = 0; i < m; i++) {
    if (s[i][0] == 'A') {
      if (list[p[i]-1][0] == 0) {
        list[p[i]-1][0] = 1;
        ac_count++;
      }
    } else {
      if (list[p[i]-1][0] == 0) {
        list[p[i]-1][1]++;
      }
    }
  }

  for (long i = 0; i < n; i++) {
    if (list[i][0] == 1) {
      wa_count += list[i][1];
    }
  }

  printf("%ld %ld\n", ac_count, wa_count);

  return 0;
}

Measured memory_bytes: 2688
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <algorithm>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#define vv(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define vvi std::vector<std::vector<int> >
#define vvl std::vector<std::vector<ll> >
#define MODs 1000000007;
typedef long long int ll;
typedef long double ld;
using namespace std;

int main(int argc, char const *argv[]) {
  ll N, M, a, b, c, INF = 1000000000000;
  std::cin >> N >> M;
  std::vector<ll> tp(14, 1);
  for(int i=1;i<=N;i++) tp[i] = tp[i-1] * 2;
  std::vector<ll> key(M+1, 0);
  std::vector<ll> p(M+1);
  for(int i=1;i<=M;i++){
    std::cin >> a >> b;
    p[i] = a;
    for(int j=0;j<b;j++){
      std::cin >> c;
      key[i]+=tp[c-1];
    }
  }
  /*
  for(int i=1;i<=M;i++){
    std::cout << key[i] << '\n';
  }
  */
  vvl dp = vv(M+1, (1<<N), INF, ll);
  dp[0][0] = 0;
  for(int i=1;i<=M;i++){
    for(int j=0;j<(1<<N);j++) dp[i][j] = dp[i-1][j];
    for(int j=0;j<(1<<N);j++){
      dp[i][j|key[i]] = min({dp[i][j|key[i]], dp[i-1][j|key[i]], dp[i-1][j]+p[i]});
    }
  }
  /*
  for(int i=0;i<=M;i++){
    for(int j=0;j<(1<<N);j++) {
      if(dp[i][j]!=INF) std::cout << i << " " << j << " " << dp[i][j] << endl;
    }
  }
  */
  std::cout << (dp[M][(1<<N)-1]==INF?-1:dp[M][(1<<N)-1]) << '\n';
  return 0;
}


Measured memory_bytes: 32384
#![allow(unused_imports)]
use std::cmp::*;
use std::collections::*;
use itertools::Itertools;
use num::clamp;
use proconio::{input, marker::*, fastout};
use superslice::*;

#[fastout()]
fn main() {
    input! {
        s: Chars,
        t: Chars,
    }

    let mut map = HashMap::new();
    for (i, &c) in s.iter().enumerate() {
        map.entry(c).or_insert_with(Vec::new).push(i);
    }

    let mut round = 0;
    let mut pos = 0;
    for c in t {
        if let Some(vec) = map.get(&c) {
            let pos2 = vec.lower_bound(&pos);
            if pos2 == vec.len() {
                round += 1;
                pos = vec[0] + 1;
            } else {
                pos = vec[pos2] + 1;
            }
        } else {
            println!("-1");
            return;
        }
    }
    let ans = pos + round * s.len();
    println!("{}", ans);
}


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

int main() {
  int n, q;
  cin >> n >> q;
  vector<queue<int>> vq(n);
  for (int i = 0; i < q; i++) {
    int a;
    cin >> a;
    if (a == 0) {
      int t, x;
      cin >> t >> x;
      vq.at(t).push(x);
    }
    if (a == 1) {
      int t;
      cin >> t;
      if (!vq.at(t).empty())
      cout << vq.at(t).front() << endl;
    }
    if (a == 2) {
      int t;
      cin >> t;
      if (!vq.at(t).empty())
      vq.at(t).pop();
    }
  }
}


Measured memory_bytes: 4312
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;

public class Main {

    public static void main(String args[]) throws IOException {

        try (BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {
            br.lines()
                    .map(line -> Arrays.stream(line.split(" "))
                            .mapToInt(Integer::parseInt)
                            .toArray())
                    .forEach(inputs -> {
                        int n = Integer.valueOf(inputs[0]);
                        int a = Integer.valueOf(inputs[1]);
                        int b = Integer.valueOf(inputs[2]);

                        output(Math.min(a,b) + " " + (a + b > n ? a + b - n: 0));
                    });
        }

    }

    private static void output(String message){
        System.out.println(message);
    }
}


Measured memory_bytes: 26708
#include "bits/stdc++.h"
#define _overload3(_1,_2,_3,name,...)name
#define _rep(i,n)repi(i,0,n)
#define repi(i,a,b)for(int i=int(a),i##_len=(b);i<i##_len;++i)
#define MSVC_UNKO(x)x
#define rep(...)MSVC_UNKO(_overload3(__VA_ARGS__,repi,_rep,_rep)(__VA_ARGS__))
#define all(c)c.begin(),c.end()
#define write(x)cout<<(x)<<'\n'
using namespace std; typedef long long ll; template<class T>using vv = vector<vector<T>>;
template<class T>auto vvec(int n, int m, T v) { return vv<T>(n, vector<T>(m, v)); }
constexpr int INF = 1 << 29, MOD = int(1e9) + 7; constexpr ll LINF = 1LL << 60;
struct aaa { aaa() { cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(10); }; }aaaa;

int main() {
    string S;
    int K;
    cin >> S >> K;
    int N = S.size();

    vv<vector<ll>> dp = vvec(N + 1, 2, vector<ll>(5, 0LL));
    dp[0][1][0] = 1;
    rep(i, N) rep(k, K + 1) {
        // if (i != 0) {
            if (S[i] != '0') {
                dp[i + 1][0][k] += dp[i][0][k] + dp[i][1][k];
            }
            else {
                dp[i + 1][0][k] += dp[i][0][k];
                dp[i + 1][1][k] += dp[i][1][k];
            }
        // } 
        rep(d, 1, 10) {
            if (d < S[i] - '0') {
                dp[i + 1][0][k + 1] += dp[i][0][k] + dp[i][1][k];
            }
            else if (d == S[i] - '0') {
                dp[i + 1][0][k + 1] += dp[i][0][k];
                dp[i + 1][1][k + 1] += dp[i][1][k];
            }
            else {
                dp[i + 1][0][k + 1] += dp[i][0][k];
            }
        }
    }
    ll ans = dp[N][0][K] + dp[N][1][K];
    write(ans);
}

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

int main(){
    int A, B;
    scanf("%d %d", &A, &B);

    if (A!=1 && B!=1){
        if (A > B){
            printf("Alice\n");
        } else if ( A < B){
            printf("Bob\n");
        } else{
            printf("Draw\n");
        }
    } else {
        if (A == 1 && B != 1){
             printf("Alice\n");
        } else if (A != 1 && B == 1){
            printf("Bob\n");
        } else {
            printf("Draw\n");
        }
    }

    return 0;
}

Measured memory_bytes: 128
#include <algorithm>
#include <cmath>
#include <complex>
#include <cstdio>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <string>
#include <vector>

const long long int INF = 1e9;
typedef long long int ll;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define Rep(i, n) for(int i = 1; i <= (int)(n); i++)
#define llrep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define llRep(i, n) for(ll i = 1; i <= (ll)(n); i++)

using namespace std;

struct Point{
	int x,y;
};

bool vector_finder(std::vector<ll> vec, ll number) {
    auto itr = std::find(vec.begin(), vec.end(), number);
    size_t index = std::distance( vec.begin(), itr );
  if (index != vec.size()) { // 発見できたとき
    return true;
    }
  else { // 発見できなかったとき
    return false;
    }
}

ll factorial(ll N){
    ll ans = 1;
    llRep(i,N){
        ans *= i;
    }
    return ans;
}

vector<ll> Eratosthenes(ll N){
    bool arr[N+1];
    //initialization
    arr[0] = false;
    arr[1] = false;
	for(ll i = 2; i < N+1; i++){
		arr[i] = true;
	}
    //eratosthenes
	for(ll i = 2; i <= sqrt(N); i++){
		if(arr[i]){
			for(ll j = 0; i * (j + 2) <= N; j++){
				arr[i *(j + 2)] = false;//not prime number
			}
		}
	}
    vector<ll> prime;
    llRep(i,N){
        if (arr[i]==true){
            prime.push_back(i);
        }
    }
    return prime;
}

char alphabet[] = {
    'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'
};

int main(){
    ll H,W;
    vector<ll> min_cands;
    cin >> H >> W;

    // どちらかの辺が3で割り切れる場合
    if (H%3==0 || W%3==0){
        cout << 0 << endl;
        return 0;
    }

    // 横を割ってみる
    ll best=INF;
    ll best_w;
    llrep(i,W){
        if (abs(H*i - (float)(H*W/3.0)) < best){
            best = abs(H*i - (float)(H*W/3.0));
            best_w = i;
        }
    }
    ll rest = H*W - H * best_w;
    if (H%2==0 || (W-best_w)%2==0){
        min_cands.push_back(abs(H*best_w - rest/2));
    }else{
        ll cand_a = max( abs( H*best_w - H*((W-best_w)/2+1) ), abs( H*best_w - H*((W-best_w)/2) ) );
        ll cand_b = max( abs( H*best_w - (W-best_w)*(H/2+1) ), abs( H*best_w - (W-best_w)*(H/2) ) );
        min_cands.push_back( min(cand_a, cand_b) );
    }

    // 縦を割ってみる
    best=INF;
    ll best_h;
    llrep(i,H){
        if (abs(W*i - (float)(H*W/3.0)) < best){
            best = abs(W*i - (float)(H*W/3.0));
            best_h = i;
        }
    }
    rest = H*W - W * best_h;
    if (W%2==0 || (H-best_h)%2==0){
        min_cands.push_back( abs(W*best_h - rest/2) );
    }else{
        ll cand_a = max( abs( W*best_h - W*((H-best_h)/2+1) ), abs( W*best_h - W*((H-best_h)/2) ) );
        ll cand_b = max( abs( W*best_h - (H-best_h)*(W/2+1) ), abs( W*best_h - (H-best_h)*(W/2) ) );
        min_cands.push_back( min(cand_a, cand_b) );
    }

    sort(min_cands.begin(), min_cands.end());
    cout << min_cands[0] << endl;

    return 0;
}


Measured memory_bytes: 256
package main

import (
	"fmt"
)

func main() {
	var N,M int
	fmt.Scan(&N,&M)
  machi := []int{0,2,5,5,4,5,6,3,7,6}
  numlist := make([]int,10)
  A := make([]int,M)
  for i:=0;i<M;i++{
    fmt.Scan(&A[i])
    numlist[A[i]]=machi[A[i]]
  }
  dp := make([]int,N+1)
  for i,_:=range dp{
    if i == 0{
      dp[i] = 0
      continue
    }
    max :=-2
    for _,s:=range numlist{
      if s == 0{
        continue
      }
      if i-s < 0{
        continue
      }
      if dp[i-s] < 0{
        continue
      }
      if max <dp[i-s]{
        max = dp[i-s]
      }
    }
    dp[i]=max+1
  }
  anslist := make([]int,dp[N])
  nokori := N
  for j:=0;j<dp[N];j++{
    for i:=9;i>0;i--{
      if numlist[i] == 0{
        continue
      }
      if nokori - numlist[i] < 0{
        continue
      }
      if dp[nokori-numlist[i]] == dp[nokori]-1{
        nokori = nokori - numlist[i]
        anslist[j]=i
        break
      }
    }
  }
  for i,_:=range anslist{
    fmt.Print(anslist[i])
  }
  return
}


Measured memory_bytes: 640
import itertools as itr
n = int(input())
xy = []
for i in range(n):
    x, y = map(int, input().split(" "))
    xy.append([x, y])
all = list(itr.permutations(xy))
n_n = 1
ans = []
for i in range(2,n+1):
    n_n = n_n*i
for line in all:
    r = [0] * (n+1)
    x = [0]*(n+1)
    y = [0]*(n+1)
    for i in range(n-1):
        x[i+1] = line[i+1][0] - line[i][0]
        y[i+1] = line[i+1][1] - line[i][1]
        r[i+1] = (x[i+1]**2 + y[i+1]**2)**(1/2)
    ans.append(sum(r))
print(sum(ans)/n_n)


Measured memory_bytes: 9332
/*The woods are lovely, dark and deep,
But I have promises to keep,
And miles to go before I sleep,
And miles to go before I sleep.*/

//PRABHJOT SINGH A.K.A. PRABHI
//~~~~~conquizztador~~~~~


#include<bits/stdc++.h>
using namespace std;
using lli = long long int;
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
const int MOD = 1000000007;
const int MOD1 = 998244353;
const int maxn = 100010;
const int lim = (int)1e9;
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int n = 0, k = 0;
	cin >> n >> k;
	vector<lli> a(n);
	for (auto &i : a)
		cin >> i;
	sort(a.begin(), a.end());
	lli res = 1ll;
	if (k == n || a[n - 1] < 0ll)
	{
		if (k % 2 == 0)
		{
			for (int i = 0; i < k; ++i)
			{
				res = (1ll * res * a[i]) % MOD;
				if (res < 0ll)
					res += MOD;
			}
		}
		else
		{
			for (int i = n - k; i < n; ++i)
			{
				res = (1ll * res * a[i]) % MOD;
				if (res < 0ll)
					res += MOD;
			}
		}
	}
	else
	{
		if (k % 2 == 0)
		{
			for (int i = 0, j = n - 1; k; k -= 2)
			{
				if (1ll * a[i]*a[i + 1] > 1ll * a[j]*a[j - 1])
				{
					res = (1ll * res * a[i] % MOD * a[i + 1] % MOD) % MOD;
					if (res < 0ll)
						res += MOD;
					i += 2;
				}
				else
				{
					res = (1ll * res * a[j] % MOD * a[j - 1] % MOD) % MOD;
					if (res < 0ll)
						res += MOD;
					j -= 2;
				}
			}
		}
		else
		{
			res = (1ll * res * a[n - 1]) % MOD;
			if (res < 0ll)
				res += MOD;
			--k;
			for (int i = 0, j = n - 2; k; k -= 2)
			{
				if (1ll * a[i]*a[i + 1] > 1ll * a[j]*a[j - 1])
				{
					res = (1ll * res * a[i] % MOD * a[i + 1] % MOD) % MOD;
					if (res < 0ll)
						res += MOD;
					i += 2;
				}
				else
				{
					res = (1ll * res * a[j] % MOD * a[j - 1] % MOD) % MOD;
					if (res < 0ll)
						res += MOD;
					j -= 2;
				}
			}
		}
	}
	cout << res << endl;
}

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

bool find(vector<int> p,int u){
    rep(i,0,p.size()){
        if(p[i]==u) return true;
    }
    return false;
}

int main(){
    //A
    /*
    vector<int> x(5);
    int p;
    rep(i,0,5) {
        cin>>x[i];
        if(x[i]==0){
            p=i;
            break;
        }
    }
    cout<<p+1<<endl;
    */
   //B?
   int x,y;
   cin>>x>>y;
   int a;
   rep(b,0,x+1){
       a=x-b;
       if(2*b+4*a==y){
           cout<<"Yes"<<endl;
           return 0;
       }
   }
   cout<<"No"<<endl;

  //C
  /*
  int x,n;cin>>x>>n;
  vector<int> p(n);
  rep(i,0,n) cin>>p[i];
  if(n==0){ 
    cout<<x<<endl;
    return 0;
  }
  sort(p.begin(),p.end());
  int u=x;
  int l=x;
  while(u>0||l<=100){
      if(find(p,u)==true){
          u--;
          if(find(p,l)==true){
              l++;
          }
          else {
              cout<<l<<endl;
              return 0;
          }
      }
      else{
          cout<<u<<endl;
          return 0;
      }
  }
  */
}

/*
total=4*x;
   while(total!=y){
       if(total<y){
           cout<<"No"<<endl;
           return 0;
       }
       total-=2;
       //cout<<total<<endl;
   }
    if(total==y){
        cout<<"Yes"<<endl;
    }
    else cout<<"No"<<endl;
   //cout<<"a"<<endl;
   */

Measured memory_bytes: 3620
#include <iostream>
using namespace std;
int main()
{
    int x,y;
     cin >> x>> y;
     if(y%2!=0)
     {
         cout << "No\n";
         return 0;
     }
     y/=2;
     if(y-x>=0&& 2*x-y>=0)
     {
         cout<<"Yes\n";
     }
     else
     {
         cout << "No\n";
         return 0;
     }
     
}

Measured memory_bytes: 3628
def roll(inst):
    global u, s, e, w, n, d
    if inst == 'N':
        u, s, n, d = s, d, u, n
    elif inst == 'E':
        u, e, w, d = w, u, d, e
    elif inst == 'S':
        u, s, n, d = n, u, d, s
    elif inst == 'W':
        u, e, w, d = e, d, u, w

u, s, e, w, n, d = map(int, input().split())
q = int(input())
for i in range(q):
    u1, s1 = map(int, input().split())
    if u1 == u:
        pass
    elif u1 == s:
        roll('N')
    elif u1 == e:
        roll('W')
    elif u1 == w:
        roll('E')
    elif u1 == n:
        roll('S')
    elif u1 == d:
        roll('N')
        roll('N')
    if s1 == s:
        print(e)
    elif s1 == e:
        print(n)
    elif s1 == n:
        print(w)
    elif s1 == w:
        print(s)

Measured memory_bytes: 7724
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <climits>
using namespace std;
#define MOD 1000000007

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    vector<int> x(N);
    vector<int> a(N, 0);
    for(int i=0; i<N; i++) cin >> x[i];
    x[0] = 1;
    if(x[1] > 2) x[1] = 3;
    for(int i=2; i<N; i++){
        if(x[i-1] == x[i-2] + 1 && a[i-1] == a[i-2]){
            x[i] = x[i-1] + 1;
            a[i] = a[i-1] + 1;
        }
        else{
            x[i] = min(x[i-1] + 2, x[i]);
            a[i] = a[i-1];
        }
    }

    vector<unsigned long long> c(N, 0);
    for(auto i : a) c[i]++;

    unsigned long long ans = 1;
    vector<unsigned long long> d(N, 0);
    d[0] = c[0];
    for(int i=1; i<N; i++)
        d[i] = d[i-1] + c[i] - 1;

    for(int i=0; i<N; i++){
        ans *= d[i];
        ans %= MOD;
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 2560
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;

void main()
{
    auto X = readln.chomp.to!long;
    auto fs = new long[](1001);
    foreach (long i; 0..1001) fs[i] = i^^5;

    foreach (i; 0..1001) {
        foreach (j; 0..1001) {
            if (fs[i] - fs[j] == X) {
                writeln(i, " ", j);
                return;
            }
            if (fs[i] + fs[j] == X) {
                writeln(i, " ", -j);
                return;
            }
            if (-fs[i] + fs[j] == X) {
                writeln(-i, " ", -j);
                return;
            }
        }
    }
}

Measured memory_bytes: 2688
import Control.Monad
import Data.Maybe
import qualified Data.ByteString.Char8 as BS
import Data.List

readInt = fst . fromJust . BS.readInt
readIntList = map readInt . BS.words
getInt = readInt <$> BS.getLine
getIntList = readIntList <$> BS.getLine

main = do
    [a, b, c, d] <- getIntList
    let l = lcm c d
    print $ (solve b c d l) - (solve (a-1) c d l)

solve n c d l = n - (n `div` c + n `div` d - n `div` l)

Measured memory_bytes: 380
#include <iostream>
#include <string>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <unordered_map>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#include <functional>
#include <bitset>
#include <assert.h>
#include <unordered_map>
#include <fstream>
#include <ctime>
#include <complex>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef pair<ll,ll> P;
typedef pair<int,int> pii;
typedef vector<P> vpl;
typedef tuple<ll,ll,ll> tapu;
#define rep(i,n) for(int i=0; i<(n); i++)
#define REP(i,a,b) for(int i=(a); i<(b); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const int inf = 1<<30;
const ll linf = 1LL<<62;
const int MAX = 510000;
ll dy[8] = {1,-1,0,0,1,-1,1,-1};
ll dx[8] = {0,0,1,-1,1,-1,-1,1};
const double pi = acos(-1);
const double eps = 1e-7;
template<typename T1,typename T2> inline bool chmin(T1 &a,T2 b){
	if(a>b){
		a = b; return true;
	}
	else return false;
}
template<typename T1,typename T2> inline bool chmax(T1 &a,T2 b){
	if(a<b){
		a = b; return true;
	}
	else return false;
}
template<typename T> inline void print(T &a){
    rep(i,a.size()) cout << a[i] << " ";
    cout << "\n";
}
template<typename T1,typename T2> inline void print2(T1 a, T2 b){cout << a << " " << b << "\n";}
template<typename T1,typename T2,typename T3> inline void print3(T1 a, T2 b, T3 c){
	cout << a << " " << b << " " << c << "\n";
}
ll pcount(ll x) {return __builtin_popcountll(x);}
//const int mod = 1e9 + 7;
const int mod = 998244353;

template<typename T> struct BIT{
	vector<T> dat;
	ll sz;
	//all 1-indexed
	BIT(ll sz) : sz(sz){
		dat.assign(++sz, 0);
	}

	T sum(ll k){
		T ret = 0;
		for(++k; k > 0; k -= k & -k) ret += dat[k];
		return (ret);
	}

	void add(ll k, T x){
		for(++k; k < dat.size(); k += k & -k) dat[k] += x;
	}
	
	ll get(T k){
		if(k <= 0) return 0; 
		ll ret = 0;
		int n = 1; while(n < sz) n *= 2;
		for(int i=n/2; i>0; i/=2){
			if(ret+i < sz && dat[ret+i] < k){
				k -= dat[ret+i];
				ret += i;
			}
		}
		return ret;
	}
};

int main(){
	int n; cin >> n;
	vs s(n); rep(i,n) cin >> s[i];
	vector<pair<string,char>> t(n);
	rep(i,n){
		reverse(all(s[i]));
		t[i].second = s[i].back();
		s[i].pop_back();
		t[i].first = s[i];
	}
	sort(all(t));
	vvl ls(n,vl(26,0));
	rep(i,n){
		for(auto j : t[i].first) ls[i][j-'a']++;
		ls[i][t[i].second-'a']++;
	}
	ll pre = -1;
	vector<BIT<int>> cnt(26,BIT<int>(1000000));
	ll ans = 0;
	rep(i,n){
		ll l=i, r=n;
		while(r-l > 1){
			ll m = (l+r)/2;
			if(t[i].first < t[m].first.substr(0,t[i].first.size())) r = m;
			else l = m;
		}
		if(l > pre){
			for(int j=l; j>i; j--){
				rep(k,26) cnt[k].add(ls[j][k],1);
			}
		}else{
			rep(k,26) cnt[k].add(ls[i][k],-1);
			for(int j=pre; j>l; j--){
				rep(k,26) cnt[k].add(ls[j][k],-1);
			}
		}
		char c = t[i].second;
		ans += cnt[c-'a'].sum(1000000) - cnt[c-'a'].sum(ls[i][c-'a']-1);
		pre = l;
	}
	cout << ans << "\n";
}

Measured memory_bytes: 171080
#include<stdio.h>
int main()
{
    long long int a,b,c=0,o,e,d=1,i,t,j,n,x,y,k,m,l,r=0;
    scanf("%lld%lld%lld%lld",&a,&b,&c,&d);
    i=c/b;
    j=a/d;
    if(i<j){printf("Yes\n");}
    else if(i==j)
    {
        if((c%b==0&&a%d>=0)||(c%b>0&&a%d>0)){printf("Yes\n");}
        else{printf("No\n");}
    }
    else
    {
        if(i-j==1&&c%b==0&&a%d!=0){printf("Yes\n");}
        else
        {
        printf("No\n");
        }
    }


}


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

int main() {
ll a,b,c,x,y; cin>>a>>b>>c>>x>>y;
  
  if(a+b<=c*2){
    cout<<a*x+b*y<<endl;
  return 0;}
  
  if(x>=y){
    if(a<=2*c){
      cout<<2*c*y+a*(x-y)<<endl;}
    else cout<<2*c*x<<endl;
  }
  
  else{
    if(b<=2*c){
      cout<<2*c*x+b*(y-x)<<endl;}
    else cout<<2*c*y<<endl;
  }

  
}


Measured memory_bytes: 256
def LinearSearch(intList,target):
    i=0
    intList.append(target)
    while intList[i] != target:
        i+=1
    intList.pop()
    if i == len(intList):
        return False
    return True

n = int(input())
S = list(map(int, input().split()))
q = int(input())
T = list(map(int, input().split()))
cnt = 0

for i in range(len(T)):
    if LinearSearch(S, T[i]):
        cnt+=1
print(cnt)


Measured memory_bytes: 6552
import sys
input = sys.stdin.readline
s = list(input())
del s[-1]
t = list(input())
del t[-1]


table_s = [-1]*26
table_t = [-1]*26

for i in range(len(s)):
    if table_s[ord(s[i])-ord("a")] == -1:
        table_s[ord(s[i])-ord("a")] = ord(t[i])-ord("a")
        table_t[ord(t[i])-ord("a")] = ord(s[i])-ord("a")
    else:
        if table_s[ord(s[i])-ord("a")] != ord(t[i])-ord("a"):
            print("No")
            exit()

table_s = [-1]*26
table_t = [-1]*26

for i in range(len(t)):
    if table_t[ord(t[i])-ord("a")] == -1:
        table_t[ord(t[i])-ord("a")] = ord(s[i])-ord("a")
        table_s[ord(s[i])-ord("a")] = ord(t[i])-ord("a")
    else:
        if table_t[ord(t[i])-ord("a")] != ord(s[i])-ord("a"):
            print("No")
            exit()


print("Yes")

Measured memory_bytes: 6576
import bisect
A,B,Q=[int(i) for i in input().split(" ")]

shrine=[-10**11]
for i in range(A):
    shrine.append(int(input()))
shrine.append(10**11)
temple=[-10**11]
for j in range(B):
    temple.append(int(input()))
temple.append(10**11)

def nearest_place(x,spot):
    if spot=="shrine":
        ind=bisect.bisect_left(shrine,x)-1

        left=shrine[ind]
        try:
            right=shrine[ind+1]
        except IndexError:
            right=shrine[ind]
        return left,right
    else:
                ind=bisect.bisect_left(temple,x)-1
                left=temple[ind]
                try:
                    right=temple[ind+1]
                except IndexError:
                    right=temple[ind]
                return left,right
ans=[]
for q in range(Q):
    x=int(input())
    retval=[]
    ls,rs=nearest_place(x,"shrine")
    lslt,lsrt=nearest_place(ls,"temple")
    rslt,rsrt=nearest_place(rs,"temple")
    lt,rt=nearest_place(x,"temple")
    ltls,ltrs=nearest_place(lt,"shrine")
    rtls,rtrs=nearest_place(rt,"shrine")
    retval.append(abs(x-ls)+abs(ls-lt))
    retval.append(abs(x-ls)+abs(ls-rt))
    retval.append(abs(x-rs)+abs(rs-lt))
    retval.append(abs(x-rs)+abs(rs-rt))
    retval.append(abs(x-lt)+abs(lt-ls))
    retval.append(abs(x-lt)+abs(lt-rs))
    retval.append(abs(x-rt)+abs(rt-ls))
    retval.append(abs(x-rt)+abs(rt-rs))
    ans.append(min(retval))

for a in ans:
    print(a)


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

def _sum(s):
    result = 0
    S = str(s)
    for i in range(len(S)):
        result += int(S[i])

    return result

ans = 10**6
for A in range(1,N):
    B = N-A
    tmp = _sum(A)+_sum(B)
    if (tmp < ans):
        ans = tmp

print(ans)

Measured memory_bytes: 3060
double x[100],y[100],A,h,X,Y,C,S,v,w;i,j,k,s,m,M;main(n){for(;~scanf("%d",&n);n&&printf("%d\n",M+2)){for(M=n;M--;)scanf("%lf,%lf",x+M,y+M);for(i=n;i-->0;)for(j=i;j--;)if(v=x[i]-x[j],w=y[i]-y[j],A=hypot(v,w)/2,A<=1)for(S=atan2(w,v),C=cos(S),S=sin(S),h=sqrt(1-A*A);++s%3;h=-h)for(m=0,k=n;k--;M=m>M?m:M)m+=k-i&&k-j&&hypot(x[j]+A*C-h*S-x[k],y[j]+A*S+h*C-y[k])<=1;}}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
 
template <typename T> void print(T t) { cout<<t<<endl; }
template<typename T, typename... Args> void print(T t, Args... args) { cout<<t<<" "; print(args...); }
 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl '\n'
#define int long long
#define double long double

vector<int>v;
void gen(int val)
{
    if(val>1e10)
        return ;
    v.push_back(val);
    int dig=val%10;
    if(dig!=0 && dig!=9)
    {
        gen(val*10+dig);
        gen(val*10+dig+1);
        gen(val*10+dig-1);
        return ;
    }
    if(dig==0)
    {
        gen(val*10+dig);
        gen(val*10+dig+1);
    }
    else
    {
        gen(val*10+dig);
        gen(val*10+dig-1);
    }
}
int32_t main() 
{
    IOS;
    int k;
    cin>>k;
    for(int i=1;i<=9;i++)
        gen(i);
    sort(v.begin(),v.end());
    print(v[k-1]);
}   


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

int main() {
   int n;
   cin >> n;
   int a[n];
   for(int i = 0; i < n; i++){
      cin >> a[i];
   }
   int f;
   for (int i = 0; i < n; i++){
      f += a[i];
   }
   f -= n;
   cout << f << endl;
   return 0;
}


Measured memory_bytes: 256
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <complex>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;

typedef long long ll;

int main() {
  int N;
  cin >> N;
  string s;
  cin >> s;

  int ans = INT_MAX;

  int cnt1 = 0;
  int cnt2 = 0;
  for (int i = 0; i < N; i++) {
    if (s[i] == 'W') {
      cnt1++;
    } else {
      cnt2++;
    }
  }
  ans = min(cnt1, cnt2);

  int l = 0, r = N - 1;
  int cnt3 = 0;
  while (l < N && r >= 0 && l < r) {
    if (s[l] == 'R') {
      l++;
      continue;
    }
    if (s[r] == 'W') {
      r--;
      continue;
    }
    swap(s[l], s[r]);
    l++;
    r--;
    cnt3++;
  }
  ans = min(ans, cnt3);

  cout << ans << endl;
}


Measured memory_bytes: 3752
a, b, c = map(int, input().split(' '))
k = int(input())

flag=0
for i in range(0, k+1):
  bb = b * (2**i)
  j = k-i
  cc = c * (2**j)
  if (a < bb) and (bb < cc):
    print('Yes')
    flag=1
    break

if flag==0:
  print('No')

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

int main()
{
	int n;
  cin >> n;
  int seq = 0;
  int seqmax = 0;
  for(int i = 0; i < n; ++i){
  	int a,b;
    cin >> a >> b;
    if (a==b) {
      seq++;
      if(seq>seqmax) seqmax = seq;
      continue;
    }
    seq = 0;
  }
  if (seqmax > 2) cout << "Yes";else cout << "No";
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+10;
int n,a[N];
int main()
{
	scanf("%d",&n);
	for (int i=1;i<=n;i++) scanf("%d",&a[i]);
	int ans=1;
	for (int i=2,sig=0;i<=n;i++){
		if (a[i]>a[i-1]) if (sig!=-1) sig=1;else ans++,sig=0;
		if (a[i]<a[i-1]) if (sig!=1) sig=-1;else ans++,sig=0;
	}
	printf("%d\n",ans);
	return 0;
}

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

int main()
{
  string s;
  cin>>s;
  int K;
  cin>>K;

  for(int i=0; i<s.length(); i++)
  {
    if(s[i] == 'a') continue;
    //cout<<"K: "<<K<<" "<<(s[i]-'a')<<" "<<(26 - (s[i] - 'a'))<<endl;
    if(26 - (s[i] - 'a') <= K)
    {
      K -= (26 - (s[i] - 'a'));
      s[i] = 'a';
    }
  }
  K %= 26;
  s[s.length()-1] += K;
  cout<<s;
  return 0;
}


Measured memory_bytes: 512
#include<iostream>
#include<string>
#include<vector>
#include<stdio.h>
#include<algorithm>
#include<math.h>
#include<numeric>
#include<iomanip>
#include<deque>
#include<tuple>
#include<queue>
#include<map>
#include <cstdint>
#include <boost/multiprecision/cpp_int.hpp>


#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define vi vector<int>
#define all(x) (x).begin(),(x).end()
#define Endl endl
#define F first
#define S second

namespace mp = boost::multiprecision;

using cpp_int = mp::cpp_int;
using ll = long long;
using namespace std;

int main(){
	int n, m;
	cin >> n >> m;
	deque<int>b1;
	map<int, int>a2;
	rep(i, m) {
		int a, b;
		scanf("%d %d",&a,&b);
		if (a == 1) {
			b1.push_back(b);
		}
		if (b == n) {
			a2[a] = i + 1;
		}
	}
	bool flag = false;
	rep(i, b1.size()) {
		if (a2[b1[i]]>0) {
			flag = true;
			break;
		}
    }
	
	if (flag) {
		cout << "POSSIBLE" << endl;
	}
	else {
		cout << "IMPOSSIBLE" << endl;
	}
}

Measured memory_bytes: 9984
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (ll i = a; i < b; i++)
#define REP(i,b) FOR(i,0,b)
#define RFOR(i,a,b) for (ll i = a-1; i >= b; i--)
#define RREP(i,a) RFOR(i,a,0)
#define REPALL(i,x) for (ll i = 0; i < x.size(); i++)
#define RREPALL(i,x) for (ll i = x.size()-1; i >= 0; i--)
#define REPITR(itr,x) for (auto itr = (x).begin(); itr != (x).end(); itr++)
#define ALL(x) (x).begin(), (x).end()
#define SORT(x) sort(ALL(x))
#define MIN_ELEMENT(x) min_element(ALL(x))
#define MAX_ELEMENT(x) max_element(ALL(x))
#define COUNT(x,num) count(ALL(x), num)
#define MEMSET(x,val) memset(x, val, sizeof(x))
#define CHMAX(a,b) a = max(a,b)
#define CHMIN(a,b) a = min(a,b)
#define debug(x) cerr<<__LINE__<<": "<<(#x)<<" = "<<(x)<<endl;
void YES(bool flag) {cout<<(flag ? "YES" : "NO")<<endl;}
void Yes(bool flag) {cout<<(flag ? "Yes" : "No")<<endl;}
void yes(bool flag) {cout<<(flag ? "yes" : "no")<<endl;}
#define e1 first
#define e2 second
#define newline putchar('\n')
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> VI;
typedef vector<vector<int>> VVI;
typedef vector<ll> VLL;
typedef vector<vector<ll>> VVLL;
const int INF = 1e7;
const ll MOD = 1e9 + 7;
const double pi = 3.141592653589793;
const VI dx = {1, 0, -1, 0};
const VI dy = {0, 1, 0, -1};

int s(ll n, ll k)
{
    if (n % k == 1) {
        return 1;
    } else if (n % k == 0) {
        return s(n / k, k);
    } else {
        return 0;
    }
}

int main()
{
    ll n, ans = 0;
    cin>>n;

    set<ll> div;
    ll m;
    m = n;
    for (ll i = 1; i * i <= m; i++) {
        if (m % i != 0)
            continue;

        div.insert(i);
        div.insert(m/i);
    }
    m = n - 1;
    for (ll i = 1; i * i <= m; i++) {
        if (m % i != 0)
            continue;

        div.insert(i);
        div.insert(m/i);
    }
    div.erase(1);

    REPITR(itr, div) {
        ans += s(n, *itr);
        //cout<<*itr<<" "<<s(n, *itr)<<endl;
    }
    cout<<ans<<endl;

    return 0;
}


Measured memory_bytes: 3864