akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
//#include <boost/multiprecision/cpp_int.hpp>
//using multiInt = boost::multiprecision::cpp_int;

using ll = long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
template<typename Q_temp>
using smaller_queue = priority_queue <Q_temp, vector<Q_temp>, greater<Q_temp> >;

const int INF = (int) 1e9;
const ll LINF = (ll) 4e18;
const ll MOD = (ll) (1e9 + 7);
const double PI = acos(-1.0);
const int limit = 200010;

#define REP(i,m,n) for(ll i = m; i < (ll)(n); ++i)
#define rep(i,n) REP(i, 0, n)
#define MP make_pair
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible") << endl
#define all(v) v.begin(), v.end()
#define NP(v) next_permutation(all(v))
#define dbg(x_) cerr << #x_ << ":" << x_ << endl;
#define dbg2(x_) for(auto a_ : x_) cerr << a_ << " "; cerr << endl;
#define dbg3(x_ , sx_) rep(i, sx_) cerr << x_[i] << " "; cerr << endl;
vector<int> Dx = {0, 0, -1, 1, -1, 1, -1, 1, 0};
vector<int> Dy = {1, -1, 0, 0, -1, -1, 1, 1, 0};

//------------------------------------------------------

void numeration_add(int N, vector<int> &pattern, int i) { //N進法
    if (pattern[i] != N - 1) pattern[i]++;
    else {
        pattern[i] = 0;
        numeration_add(N, pattern, i + 1);
    }
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n, length[3];
    cin >> n;
    rep(i, 3) cin >> length[i];
    ll l[n];
    rep(i, n) cin >> l[i];
    vector<int> pattern(n + 1, 0);
    ll best = LINF;
    while (pattern[n] == 0) {
        ll kadomatsu[3] = {};

        rep(i, n) {
            if (pattern[i] != 3) kadomatsu[pattern[i]] += l[i];
        }

        ll cost = 0;
        rep(i, 3) cost += abs(kadomatsu[i] - length[i]);
        vector<int> cnt(4, 0);
        rep(i, n) cnt[pattern[i]]++;
        bool invalid = false;
        rep(i, 3) if (cnt[i] == 0) {
            invalid = true;
            break;
        }
        numeration_add(4, pattern, 0);
        if (invalid) continue;
        rep(i, 3) cost += (cnt[i] - 1) * 10;
        best = min(best, cost);
    }
    cout << best << endl;
    return 0;
}

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

long long int mod=1e9+7;

int main(){
  string s,t;
  cin>>s>>t;

  int f=0;
  for(int i=0;i<s.size();i++){
    if(s==t)f=1;
    t=t[t.size()-1]+t.substr(0,t.size()-1);
  }
  if(f){
    cout<<"Yes"<<endl;
  }else{
    cout<<"No"<<endl;
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int max_m=50,max_n=50;
bool ans=false;
char a[max_m][max_m],b[max_n][max_n];

void check(int x,int y,int m,bool &ans){
  bool flag=false;
  for (int i=0;i<m;i++) {
    for (int j=0;j<m;j++) {
      if (a[x+i][y+j]!=b[i][j]) {
        flag=true;
        break;
      }
      else if (i==m-1 && j==m-1) ans=true;
    }
    if (flag) break;
  }
}

int main() {
  int n,m;
  cin>>n>>m;
  for (int i=0;i<n;i++) for (int j=0;j<n;j++) cin >> a[i][j];
  for (int i=0;i<m;i++) for (int j=0;j<m;j++) cin >> b[i][j];
  for (int i=0;i<n-m+1;i++) for (int j=0;j<n-m+1;j++) check(i,j,m,ans);
  if (ans) cout << "Yes" <<endl;
  else cout << "No" << endl;
}


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

int main(){
  int a, b, c;
  cin >> a >> b >> c;
  
  if(a <= b && b <= c)
     cout << a << " " << b << " " << c << endl;
  else if(a <= c && c <= b)
     cout << a << " " << c << " " << b << endl;
  else if(b <= a && a <= c)
     cout << b << " " << a << " " << c << endl;
  else if(b <= c && c <= a)
     cout << b << " " << c << " " << a << endl;
  else if(c <= a && a <= b)
     cout << c << " " << a << " " << b << endl;
  else if(c <= b && b <= a)
     cout << c << " " << b << " " << a << endl;

  return 0;
}

Measured memory_bytes: 1164
import java.util.*;
public class Main{
        public static void main(String[] args){
                Scanner sc = new Scanner(System.in);
                int a = sc.nextInt();
                int b = sc.nextInt();
                int c = sc.nextInt();
                int x = sc.nextInt();
                sc.close();
                int yono = 0;
                for(int i = 0 ; i <= a ; i++){
                        for(int j = 0 ; j <= b ; j++){
                                for(int k = 0 ; k <= c ; k++){
                                        if(x == 500 * i + 100 * j + 50 * k) yono++;
                                }
                        }
                }
                System.out.println(yono);
        }
}//0=48
//鶏になれ

Measured memory_bytes: 35500
a,b,c=map(int, input().split())

if a == b and a!= c:
    print('Yes')
if b == c and b !=a:
    print('Yes')
if c == a and c != b:
    print('Yes')
if a == b == c:
    print('No')
if a != b and a != c and b != c:
    print('No')

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

using namespace std;
#define int long long
#define rep(i, n) for(int i=0;i<(n);++i)
#define INF (1ll<<60)
#define FI first
#define SE second

int N;
int A[100100];

signed main() {
    cin >> N;
    rep(i, N) {
        int a;
        cin >> a;
        A[a]++;
    }
    int ans = 0;
    rep(i, 100000) {
        ans = max(ans, A[i] + A[i + 1] + A[i + 2]);
    }
    cout << ans << endl;
}

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

int main(){
  long long N,K; cin>>N>>K;
  vector<pair<int,int>>P(N);
  for(int i=0;i<N;i++)
   cin>>P.at(i).first>>P.at(i).second;
  
  sort(P.begin(),P.end());
  
  for(int i=0;i<N;i++){
    int a,b;
    tie(a,b)=P.at(i);
    
    K-=b;
    
    if(K<=0){
      cout<<a;
      break;
    }
  }
}
    

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

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
//const ll mod = 1000000007;
int N;
int a[205];

bool is_sorted() {
    for(int i = 1; i < N; i++) {
        if(a[i - 1] >= a[i]) return false;
    }
    return true;
}
vector<int> ans;

int main() {
    //cout.precision(10);
    cin >> N;
    for(int i = 0; i < N; i++) {
        cin >> a[i];
    }
    while(!is_sorted()) {
        for(int i = 0; i < N; i++) {
            //cout << a[i] << " ";
        }
        //cout << endl;
        //cout << 1 << endl;
        ans.push_back(1);
        int tmp = a[0];
        for(int i = 0; i < N - 1; i++) {
            a[i] = a[i + 1];
        }
        a[N - 1] = tmp;
        if(is_sorted()) break;
        if(a[0] < a[N - 1]) {
            if(a[0] == 0 && a[N - 1] == (N - 1)) continue;
            //cout << N - 1 << endl;
            ans.push_back(N - 1);
            swap(a[0], a[N - 1]);
        }
    }
    cout << ans.size() << endl;
    for(int i = 0; i < ans.size(); i++) {
        cout << ans[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 764
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <unordered_map>
#include <vector>
#include <string.h>
#include <set>

using namespace std;

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl

template<class T> void printvec(const vector<T>& v) {
  for (auto x : v) { cout << x << " "; }
  cout << endl;
}
template<class T> void printtree(const vector< vector<T> >& tree) {
  for (long long i = 0; i < tree.size(); ++i) {
    cout << i + 1 << ": "; printvec(tree[i]);
  }
}
template<class T, class U> void printmap(const map<T, U>& mp) {
  for (auto x : mp) { cout << x.first << "=>" << x.second << endl; }
}

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

#define rep(i, n) for(ll i = 0; i < n; ++i)
#define all(s) s.begin(), s.end()
#define sz(x) (ll)(x).size()
#define fr first
#define sc second
#define mp make_pair
#define pb push_back
#define eb emplace_back

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> triple;
typedef double D;
typedef vector<ll> vl;
typedef vector<P> vp;

const ll INF = 1e12;
const ll MOD = 1000000007;  // 1e9 + 7

int main(int argc, char** argv) {
  cin.tie(NULL);
  cout.tie(NULL);
  ios_base::sync_with_stdio(false);
  //cout << setprecision(10) << fixed;

  ll n, k;
  cin >> n >> k;
  vector<ll> h(n);
  rep(i, n) {
    cin >> h[i];
  }
  vector<ll> dp(n, INF);
  dp[0] = 0;
  rep(i, n) {
    for (int j = i-k; j < i; ++j) { // loop in [i-k, i)
      if (j < 0) { continue; } // skip
      chmin(dp[i], dp[j] + abs(h[i]-h[j]));
    }
  }
  cout << dp[n-1] << endl;
}


Measured memory_bytes: 1792
using System;
using System.Collections.Generic;
using System.Linq;
 
public class Hello{
    public static void Main(){
        var n = Int32.Parse(Console.ReadLine());
        var a = Console.ReadLine().Split(' ').Select(x => Int32.Parse(x)).ToList();
        var li = new List<int>(n);
        
        for(var i = 0; i < n; ++i){
            li.Add(0);
        }
        
        long ret = 0;
        for(var i = 0; i < n; ++i){
            if (0 <= i - a[i]){
                ret += li[i - a[i]];
            }
            
            if (i + a[i] < n) {
                li[i + a[i]] += 1;
            }
        }
        
        Console.WriteLine(ret);
    }
}

Measured memory_bytes: 44464
#pragma warning disable

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.Serialization.Formatters.Binary;
using System.Text;
using System.Text.RegularExpressions;
using System.Diagnostics;
using System.Numerics;
using System.Collections;
using System.Timers;

static class MainClass
{
    public static void Main(string[] args)
    {
        var a = Console.ReadLine();
        var b = Console.ReadLine();
        var c = Console.ReadLine();
        var before = "a";
        while (true)
        {
            {
                if (before == "a")
                {
                    if (a.Length == 0)
                    {
                        Console.WriteLine("A");
                        break;
                    }
                    before = a[0].ToString();

                    a = a.Remove(0, 1);
                }
                else if (before == "b")
                {
                    if (b.Length == 0)
                    {
                        Console.WriteLine("B");
                        break;
                    }
                    before = b[0].ToString();

                    b = b.Remove(0, 1);
                }
                else
                {
                    if (c.Length == 0)
                    {
                        Console.WriteLine("C");
                        break;
                    }
                    before = c[0].ToString();

                    c = c.Remove(0, 1);

                }
            }
        }

        Console.ReadLine();
    }

    #region ライブラリ
    public static long ToInt64(this string str) => long.Parse(str);
    public static int ToInt32(this string str) => int.Parse(str);
    public static BigInteger ToBigInteger(this string str) => BigInteger.Parse(str);
    public static List<string> SplittedStringToList(this string str) => str.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).ToList();
    public static List<int> SplittedStringToInt32List(this string str) => str.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).Select(x => int.Parse(x)).ToList();
    public static List<BigInteger> SplittedStringToBigInteger(this string str) => str.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).Select(x => BigInteger.Parse(x)).ToList();

    public const int INF = int.MaxValue / 2;
    #endregion
}


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

using namespace std;

int main () {
	double W, H, x, y;
	cin >> W >> H >> x >> y;
	cout << fixed;
	cout << setprecision(15);
	cout << (W * H / 2.0) << " ";
	if (x * 2.0 == W && y * 2.0 == H) {
		cout << 1 << endl;
	} else {
		cout << 0 << endl;
	}
}


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

ll inf=9223372036854775806;

int main()
{
	//freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
	ios_base::sync_with_stdio(false); cin.tie(0);
	int a,b,c,x,d[20001]={0},i,j,k;
	cin>>a>>b>>c>>x;
	for (i=0;i<=a;i++){
		for (j=0;j<=b;j++){
			for (k=0;k<=c;k++){
				if (500*i+100*j+50*k<=20000){
					d[500*i+100*j+50*k]++;
				}
			}
		}
	}
	cout<<d[x];
	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
typedef long long int ll;
typedef long double ld;
#define pb push_back
#define pii pair < int, int >
#define F first
#define S second
#define int  long long int
#define sync ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#pragma GCC optimize ("Ofast")
#pragma GCC optimize ("unroll-loops")
using namespace std;
/// khodaya komak kon
const int N=2e5;
ll vis[N];
int32_t main(){
    ll n;
    cin >> n;
    ll k;
    cin >> k;
    for (int i=0;i<k;i++){
        ll x;
        cin >> x;
        vis[x]=1;
    }
    for (int i=n;i<N;i++){
        ll z=i;
        ll p1=0;
        while(z>0){
            ll p=z%10;
            if (vis[p])
                p1=1;
            z/=10;
        }
        if (!p1){
            cout << i;
            return 0;
        }
    }
}


Measured memory_bytes: 256
#include <stdio.h>
int func(int x){
	int num = x;
	int sum = 0;
	int dig;
	while(num){
	dig = num % 10;
	sum = sum + dig;
	num = num / 10;
	}
	return sum;
}
int main(void){
	int n,a,b;
	scanf("%d%d%d",&n,&a,&b);
	int i,ans=0,temp;
	for(i=1;i<=n;i++){
		temp = func(i);
		if(temp>=a && temp<=b)ans+=i;
	}
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
using namespace std;
int n;
#define Maxn 200010
int a[Maxn],l1[Maxn],l2[Maxn],b[Maxn];
int main(){
	scanf("%d",&n);
	bool flag0=true;bool flag1=true;
	for(register int i=1;i<=n;++i)scanf("%d",&a[i]);
	b[n]=a[n];
	for(register int i=n-1;i>=1;--i){
		int d=0;
		for(register int j=2*i;j<=n;j+=i)d+=b[j];
		d%=2;
		if(d^a[i])b[i]=1;
		else b[i]=0;
	}
	int cnt=0;
	for(register int i=1;i<=n;++i)
	if(b[i])cnt++;
	printf("%d\n",cnt);
	for(register int i=1;i<=n;++i)
	if(b[i])printf("%d\n",i); 
	return 0;
}

Measured memory_bytes: 2432
let a, b, c, d, e, f = Scanf.scanf " %d %d %d %d %d %d" @@ fun a b c d e f -> a, b, c, d, e, f
let ws = Array.make (f + 1) false
let ss = Array.make (f + 1) false
let (<=@) (w, s) (w2, s2) = (w2 + s2) * s <= (w + s) * s2
let ans = ref (f, 0)
let _ =
  for i = 0 to f / 100 do
    for j = 0 to f / 100 do let w = 100 * i * a + 100 * j * b in if w <= f then ws.(w) <- true done done;
  for i = 0 to f do
    for j = 0 to f do if i * c + j * d <= f then ss.(i * c + j * d) <- true done done;
  for i = 0 to f do
    for j = 0 to f do if ws.(i) && ss.(j) && i + j <= f && 100 * j <= i * e then (ans := if !ans <=@ (i, j) then i, j else !ans) done done;
  let w, s = !ans in Printf.printf "%d %d\n" (w + s) @@ s

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define FOR(i,a,b) for(int i=a; i<(int)(b); i++)
#define ALL(x) (x).begin(),(x).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define CLR(a) memset((a), 0 ,sizeof(a))
#define PB push_back
#define MP make_pair
#define SP << " " <<
const int INF = 1001001001;
const ll LINF = 100100100100100100;
const double EPS = 1e-10;
const long double PI  = acos(-1.0L);
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
#define chmax(a,b) a = (((a)<(b))?(b):(a))
#define chmin(a,b) a = (((a)>(b))?(b):(a))

__attribute__((constructor))
void initial(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}

signed main(){
	ll n; cin>>n;
	ll ans = 1;
	for(ll i=1;i<=n;i++){
		ans = (ans*i)%MOD;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
XY_list = list(map(int, input().split()))
X = XY_list[0]
Y = XY_list[1]
k = Y/2 - X
t = 2*X - Y/2
if k%1 == 0 and t%1 == 0 and t >= 0 and k >= 0:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 9188
# import bisect
# from collections import Counter, defaultdict, deque
# import copy
# from heapq import heappush, heappop, heapify
# from fractions import gcd
# import itertools
# from operator import attrgetter, itemgetter
# import math

import sys

# import numpy as np

ipti = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)

def main():
    n, k = list(map(int,ipti().split()))
    if k == 1:
        print(0)
    else:
        print(n-k)

if __name__ == '__main__':
    main()

Measured memory_bytes: 38256
import sys
def input(): return sys.stdin.readline().strip()

def resolve():
    a,b,c,d=map(int, input().split())
    x=a+b
    y=c+d
    if x>y:
        print('Left')
    elif x==y:
        print('Balanced')
    else:
        print('Right')
resolve()

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

int n, m, k, q, a[2004], b[2004];

int main() {
	cin >> n >> k >> q;
	for (int i=0; i<n; i++) cin >> a[i], b[i] = a[i];

	sort(b, b+n);
	m = unique(b, b+n) - b;

	int ans = 2e9;
    for (int i=0; i<m; i++) {
		vector<int> v, u;
		for (int j=0; j<=n; j++) {
			if (a[j] < b[i]) {
				sort(v.begin(), v.end());
				for (int t=0; t<(int)v.size()-k+1; t++) u.push_back(v[t]);
				v.clear();
			} else v.push_back(a[j]);
		}
		sort(u.begin(), u.end());
		if (u.size() >= q) ans = min(ans, u[q-1] - b[i]);
    }
    cout << ans;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <string>

using namespace std;

string sa,sb;
int a[501],b[501];
int m,mod=10000;
int dp[502][501][10][4][2];

int solve(int d[],int sz,bool low){
    memset(dp,0,sizeof(dp));
    dp[0][0][0][0][0]=1;
    for(int i=0;i<sz;++i){
        for(int j=0;j<m;++j){
            for (int k=0;k<10;++k){
                for(int l=0;l<4;++l){
                    for(int p=0;p<2;++p){
                        int lim=p?9:d[i];
                        for(int q=0;q<=lim;++q){
                            if(l==0)(dp[i+1][q%m][q][q!=0][p||q<lim] +=dp[i][j][k][l][p])%=mod;
                            else if(l==1&&q!=k)(dp[i+1][(j*10+q)%m][q][q<k?2:3][p||q<lim] +=dp[i][j][k][l][p])%=mod;
                            else if(l==2&&q>k)(dp[i+1][(j*10+q)%m][q][3][p||q<lim] +=dp[i][j][k][l][p])%=mod;
                            else if(l==3&&q<k)(dp[i+1][(j*10+q)%m][q][2][p||q<lim] +=dp[i][j][k][l][p])%=mod;
                        }
                    }
                }
            }
        }
    }
    int res=0;
    for(int i=0;i<10;++i){
        for(int j=0;j<4;++j){
            for(int k=0;k<2;++k){
                if(low&&k==0) continue;
                (res += dp[sz][0][i][j][k])%=mod;
            }
        }
    }
    return res;
}

int main(){
    cin>>sa>>sb>>m;
    for(int i=0;i<sb.size();++i) b[i]=sb[i]-'0';
    for(int i=0;i<sa.size();++i) a[i]=sa[i]-'0';
    cout<<(solve(b,sb.size(),false)-solve(a,sa.size(),true)+mod)%mod<<endl;
    return 0;
}

Measured memory_bytes: 81756
n = gets.to_i
a = gets.split(' ').map(&:to_i)
cand = Array.new(n + 1, 0) # i = {i-1 | not chosen yet}
cand[0] = 3
mod = 1_000_000_007
res = 1
a.each do |x|
  res *= cand[x] # *=#{x-1 | not chosen yet}
  res %= mod
  cand[x] -= 1
  cand[x + 1] += 1
end
p res

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


double solve(const vector<pair<double,double>> &points) {
    int N = points.size();
    double x_low = -1000.0;
    double x_high = 2000.0;
    double y_low = -1000.0;
    double y_high = 2000.0;
    REP(i,200) {
        double x1 = (2.0*x_low+x_high)/3.0;
        double x2 = (x_low+2.0*x_high)/3.0;
        double R1 = 0;
        double R2 = 0;
        y_low = -1000.0;
        y_high = 2000.0;
        REP(j,200) {
            double y1 = (2.0*y_low+y_high)/3.0;
            double y2 = (y_low+2.0*y_high)/3.0;
            double R3 = 0;
            double R4 = 0;
            REP(k,N) {
                double x = points[k].first;
                double y = points[k].second;
                R3 = max(R3,(x-x1)*(x-x1)+(y-y1)*(y-y1));
                R4 = max(R4,(x-x1)*(x-x1)+(y-y2)*(y-y2));
            }
            if(R3>R4) y_low = y1;
            else y_high = y2;
            R1 = R3;
        }
        y_low = -1000.0;
        y_high = 2000.0;
        REP(j,200) {
            double y1 = (2.0*y_low+y_high)/3.0;
            double y2 = (y_low+2.0*y_high)/3.0;
            double R3 = 0;
            double R4 = 0;
            REP(k,N) {
                double x = points[k].first;
                double y = points[k].second;
                R3 = max(R3,(x-x2)*(x-x2)+(y-y1)*(y-y1));
                R4 = max(R4,(x-x2)*(x-x2)+(y-y2)*(y-y2));
            }
            if(R3>R4) y_low = y1;
            else y_high = y2;
            R2 = R3;
        }
        if(R1>R2) x_low = x1;
        else x_high = x2;
    }
    double res = 0.0;
    REP(k,N) {
        double x = points[k].first;
        double y = points[k].second;
        res = max(res,(x-x_low)*(x-x_low)+(y-y_low)*(y-y_low));
    }
    res = sqrt(res);
    return res;
}

int main() {
    int N; cin >> N;
    vector<pair<double,double>> points(N);
    REP(i,N) cin >> points[i].first >> points[i].second;
    cout << fixed << setprecision(10) << solve(points) << endl;
    return 0;
}

Measured memory_bytes: 256
/**
 *  author: MahfuzAhmed
 *  created: 26.08.2019
**/

#include <bits/stdc++.h>
using namespace std;
#define debug(x) cout << '>' << #x << ':' << x << endl;
//~ const double pi = 2*acos(0.0);
//~ const long long mod = 1e9+7;
//~ const int max_n = 1e6+5;
typedef long long ll;


int main(int argc, char* argv[]){
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
       
    #ifdef _DEBUG
    freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    #endif
    
    ll a, b; cin >> a >> b;
    
    if(a > b){
        swap(a, b);
    }
    
    ll cnt = a;
    
    b -= a;
    a = 0;
    
    
    
    while(b >= a){
        if(a == b){
            cout << cnt << "\n";
            return 0;
        }else{
            a++;
            b--;
            cnt++;
        }
    }
    
    cout << "IMPOSSIBLE\n";
    
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <unordered_map>
#include <queue>
#include <vector>

#define rep(i,min,max) for(int i=min;i<max;i++)
#define rrep(i,min,max) for(int i=max;i>=min;i--)

using namespace std;

int main(){
  int a,b,c,d,e,k;
  cin >>a>>b>>c>>d>>e>>k;

  if(e-a <= k)
    cout << "Yay!" << endl;
  else
    cout << ":(" << endl;
    
  return 0;
}



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

#define INF_LL (int64)1e18
#define INF (int32)1e9
#define REP(i, n) for(int i = 0;i < (n);i++)
#define FOR(i, a, b) for(int i = (a);i < (b);i++)
#define all(x) x.begin(),x.end()
#define fs first
#define sc second

using int32 = int_fast32_t;
using uint32 = uint_fast32_t;
using int64 = int_fast64_t;
using uint64 = uint_fast64_t;
using PII = pair<int32, int32>;
using PLL = pair<int64, int64>;

const double eps = 1e-6;

template<typename A, typename B>inline void chmin(A &a, B b){if(a > b) a = b;}
template<typename A, typename B>inline void chmax(A &a, B b){if(a < b) a = b;}

const int64 mod = 1e9+7;

int main(void){
	int32 N, M;
	while(cin >> N >> M && N+M){
		vector<int64> h(N+1), w(M+1);
		REP(i, N) cin >> h[i+1];
		REP(i, N) h[i+1] += h[i];
		map<int64, int64> cnt;
		REP(i, N+1){
			FOR(j, i+1, N+1){
				cnt[h[j]-h[i]]++;
			}
		}
		REP(i, M) cin >> w[i+1];
		REP(i, M) w[i+1] += w[i];
		int64 res = 0;
		REP(i, M+1){
			FOR(j, i+1, M+1){
				res += cnt[w[j]-w[i]];
			}
		}
		cout << res << endl;
	}
}


Measured memory_bytes: 26892
import java.io.*;

public class Main {
	public static void main(String[] args) {
		try {
			BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
			int n = Integer.parseInt(in.readLine());
			for (int i = 0; i < n; i++) {
				String str = in.readLine();
				str = str.replaceAll("Hoshino", "Hoshina");
				System.out.println(str);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}

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

int main(void){
    int n, m, i, j, k, po=0;
    scanf("%d", &n);

    if(n%2 == 0){
        printf("%d\n", n*(n-1)/2-n/2);
        for(i=1; i<=n; i++){
            for(j=i+1; j<=n; j++){
                if(i+j != n+1) printf("%d %d\n", i, j);
            }
        }
    }else{
        printf("%d\n", n*(n-1)/2-(n-1)/2);
        for(i=1; i<=n; i++){
            for(j=i+1; j<=n; j++){
                if(i+j != n) printf("%d %d\n", i, j);
            }
        }
    }
}

Measured memory_bytes: 128
//#include <ext/pb_ds/assoc_container.hpp> 
    // #include <ext/pb_ds/tree_policy.hpp> 
    #include <iostream>
    #include <iomanip>
    #include <sstream>
    #include <cstring>
    #include <vector>
    #include <deque>
    #include <queue>
    #include <set>
    #include <map>
    #include <valarray>
    #include <iterator>
    #include <functional>
    #include <limits>
    #include <algorithm>
    #include <numeric>
    #include <cmath>
    #include <cassert>
    #include <unordered_map>
    #include <unordered_set>
    #include <stack>
    using namespace std;
    #define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
    #define trace(x) cerr << #x << ": " << x << " " << endl;
     
    typedef int64_t ll;
     
    #define endl '\n'
    #define int ll
    ll mod=1e9+7;
    ll mod1=1e9+5;
     
    ll power(ll a,ll b)
    {
        if(b==0) return 1;
        else if(b%2==0)
            return power((((a%mod)*(a%mod))%mod),b/2)%mod;
        else return ((a%mod)*(power((((a%mod)*(a%mod))%mod),b/2)%mod))%mod;
    }
     
    // using namespace __gnu_pbds;
    // #define ordered_set tree<pair<int,int>, null_type,less<pair<int,int>>, rb_tree_tag,tree_order_statistics_node_update>
    //find_by_order(k)  returns iterator to kth element starting from 0;
    //order_of_key(k) returns count of elements strictly smaller than k;
    //erase,insert same as normal set
  
    int32_t main()
    {
        IOS
 
        
       int h;
       cin>>h;
      if(h==1)
      {
        cout<<1;
        return 0;
      }
       multiset<int> m;
       m.insert(h);
       map<int,int> m1;
       int ans=0;
       m1[h]++;
       while(1)
       {
        if(m.size()==0)
            break;
        int x=*m.rbegin();
         if(m.find(x)!=m.end())
        m.erase(m.find(x));
        ans+=m1[x];
        
        if((x/2)==1)
        {
            ans+=2*m1[x];
            continue;
        }
        else
        {
            int te=x;
            x/=2;
            m.insert(x);
            m1[x]+=2*m1[te];
        }
       }
       cout<<ans<<endl;


    }       


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

int main()
{
  int N, K, X, Y;
  cin >> N >> K >> X >> Y;
  if(N <= K)
  {
    cout << N * X << endl;
  }
  else
  {
    cout << K * X + (N - K) * Y << endl;
  }
  return 0;
}

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

int main(void)
{
    int N;
    cin >> N;
    vector<int> b(N);
    vector<int> result;
    for(int i=0; i<N; ++i){
        cin >> b[i];
    }

    while(b.size()>0){

        for(int i=b.size()-1; i>=0; --i){
            if(b[i] == i+1){
                result.push_back(b[i]);
                b.erase(b.begin()+i);
                break;
            }
            if(i==0){
                cout << -1 << endl;
                return(0);
            }
        }

    }

    for(int i=N-1; i>=0; --i){
        cout << result[i] << endl;
    }
}

Measured memory_bytes: 256
// AtCoder Beginner Contest - Problem C: Five Transportations (https://atcoder.jp/contests/abc123/tasks/abc123_c)
#include <bits/stdc++.h>

using namespace std;
using ll = long long;

ll solve(ll N, const vector<ll>& xs)
{
    auto x = *min_element(xs.begin(), xs.end());

    return 4 + (N + x - 1)/x;
}

int main()
{
    ios::sync_with_stdio(false);

    ll N;
    cin >> N;

    vector<ll> xs(5);

    for (int i = 0; i < 5; ++i)
        cin >> xs[i];

    auto ans = solve(N, xs);

    cout << ans << '\n';

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define ALL(x) (x).begin(), (x).end()
typedef long long ll;
typedef pair<int, int> pii;
const int INF = 1e9;
const int MOD = 1000000007;
const double PI = acos(-1);
int dx[4] = {0,1,0,-1};
int dy[4] = {1,0,-1,0};

void solve() {
  int n;
  cin >> n;
  vector<int> h(n);
  rep(i,n) cin >> h[i];
  int mn = 0;
  int res = 0;
  rep(i,n) {
    if (mn < h[i]) {
      res += h[i] - mn;
    }
    mn = h[i];
  }
  cout << res << endl;
}

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

Measured memory_bytes: 3604
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
  
int main(){
  ll x;
  cin >> x;
  ll p=100, step=0;
  while(p<x) {
  	p += p/100;
    step++;
  }
  cout << step << endl;
  return 0;
}

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

int main() {
	long long n;
	cin >> n;
	vector<long long> div;
	long long ans = 0;
	for(int i = 1; i <= sqrt(n); i++) {
		if(n%i == 0) div.push_back(i);
	}
	long long tam = div.size();
	for(int i = 0; i < tam; i++) if(div[i] != sqrt(n)) div.push_back(n / div[i]);
	tam = div.size();
	for(int i = 0; i < tam; i++) div[i] -= 1;
	for(int i = 0; i < tam; i++) {
		if(div[i] >= sqrt(n)) ans += div[i];
	}
	cout << ans;
	return 0;
}

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

  int main(){
    int a[5];
    int s=0;
    for (int i;i<5;i++){
      cin >> a[i];
      s+=(a[i]+9)/10*10;
      a[i]=(10-a[i]%10)%10;
    }
    sort(a,a+5);
    cout << s-a[4] << endl;
  }

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
using pint = pair<int, int>;
using plint = pair<lint, lint>;
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;

#define ALL(x) (x).begin(), (x).end()
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)



int main(){
    int a,b,c;
    cin >> a>>b>>c;
    cout << a*b/2 << "\n";
    // Failed to predict input format
    return 0;
}



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

#define ios ios_base::sync_with_stdio(0); cout.tie(0);cin.tie(0);
#define endl "\n"

using namespace std;

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

const int N = 2e5;
int c[N];

int main() {
    ios
    int n, q;
    cin >> n;
    int a[n];
    ll sum = 0;
    for (int i = 0; i < n; ++ i) {
        cin >> a[i];
        sum += a[i];
        c[a[i]] ++;
    }
    cin >> q;
    while(q --) {
        ll b, to;
        cin >> b >> to;
        sum -= c[b] * b;
        sum += c[b] * to;
        c[to] += c[b];
        c[b] = 0;
        cout << sum << endl;
    }
}


Measured memory_bytes: 4400
#include <bits/stdc++.h>
using namespace std;
int check(vector<int> &d2, vector<vector<int>> &x){
  int a = d2[0];
  int b = d2[1];
  int c = d2[2];
  int d = d2[3];
  int e = d2[4];
  return x[x[x[x[x[0][a]][b]][c]][d]][e];
}
int main(){
  vector<vector<int>> x(10, vector<int>(10));
  for (int i = 0; i < 10; i++){
    for (int j = 0; j < 10; j++){
      cin >> x[i][j];
    }
  }
  int ans = 0;
  for (int i = 0; i < 10000; i++){
    string S = to_string(i);
    while (S.size() < 4){
      S = '0' + S;
    }
    vector<int> d(5);
    for (int j = 0; j < 4; j++){
      d[j] = S[j] - '0';
    }
    d[4] = x[x[x[x[0][d[0]]][d[1]]][d[2]]][d[3]];
    bool err = false;
    for (int i = 0; i < 5; i++){
      for (int j = 0; j < 10; j++){
        if (d[i] != j){
          vector<int> d2 = d;
          d2[i] = j;
          if (check(d2, x) == 0){
            err = true;
          }
        }
      }
    }
    for (int i = 0; i < 4; i++){
      if (d[i] != d[i + 1]){
        vector<int> d2 = d;
        swap(d2[i], d2[i + 1]);
        if (check(d2, x) == 0){
          err = true;
        }
      }
    }
    if (err){
      ans++;
    }
  }
  cout << ans << endl;
}


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

bool check(const string s) {
	// cout << s << endl;
	int n = s.size();
	bool flag = true;
	rep(i, n / 2) {
		if (s[i] != s[n - i - 1]) {
			flag = false;
		}
	}
	return flag;
}

int main(int argc, char const *argv[])
{
	string s; cin >> s;
	int n = s.size();
	bool flag = check(s) & check(s.substr(0, (n - 1) / 2)) & check(s.substr((n + 3) / 2 - 1));
	cout << (flag ? "Yes" : "No") << endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long ll;
typedef pair<ll,ll> P;
const ll mod=1000000007;
const ll LINF=1LL<<60;
const int INF=1<<30;

ll n,m;
vector<ll> A(100000,0LL);
vector<ll> sum(100000,0LL);


ll bs1(int tot){//totは探索する価値の値
	ll res = 0;
	for(int i = 0; i < n; i++) {
		int Ay = tot - A[i];
		int index = lower_bound(ALL(A),Ay) - A.begin();//Ax + Ay >= totを満たす最小のインデックス
		res += n - index;//条件を満たすのはindexより後ろの値
	}
	return res;
}

ll getsum(int tot){
	for(int i = 0; i < n; i++) {
		sum[i] = A[i];
	}
	for(int i = n - 2; i >= 0; i--) {
		sum[i] += sum[i + 1];//sum[i] = A[i]からA[n - 1]までの和
	}
	ll res = 0;
	for(int i = 0; i < n; i++) {
		int Ay = tot - A[i];
		int index = lower_bound(ALL(A),Ay) - A.begin();//Ax + Ay >= totを満たす最小のインデックス
		int cnt = n - index;
		res += 1 * A[i] * cnt;//Axの和を計算
		res += sum[index];//Ayの部分を計算
	}
	return res;
}

int main(){
	cin >> n >> m;
	A.resize(n);
	sum.resize(n);
	for(int i = 0; i < n; i++) {
		cin >> A[i];
	}
	sort(ALL(A));

	int ok = 0,ng = INF;
	while(ok + 1 != ng){//境界が見つかるまでループ(O(logN))最終的に見つかるのがtotの取りうる最大値
		int md = (ok + ng) / 2;
		if (m <= bs1(md)){//md以上の要素がm個以上見つかった
			ok = md;
		}
		else{//m個未満の時
			ng = md;
		}
	}
	ll ans = (m - bs1(ok + 1)) * ok + getsum(ok + 1);//第一項は握手の値がちょうどokとなるものの和、第二項はok以上の価値の握手の和

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

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

int main(){
    string s, t, u;
    int a, b;
    cin >> s >> t;
    cin >> a >> b;
    cin >> u;
    if (u==s) cout << a-1 << " " << b << endl;
    if (u==t) cout << a << " " << b-1 << endl;
}

Measured memory_bytes: 256
/*
Author : N_o_o_B
Created : January 12 2020 12:01:41 
*/
#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 TRACE
#ifdef TRACE
#define trace(...) { cerr<<"[ "; __trace__(#__VA_ARGS__, __VA_ARGS__);}
#undef endl
template <typename Arg1,typename Arg2>
ostream& operator << (ostream& out, const pair<Arg1,Arg2> &x) {
    return out<<"("<<x.first<<","<<x.second<<")";
}
 
template <typename Arg1>
ostream& operator << (ostream& out, const vector<Arg1> &a) {
    out<<"[";for(const auto &x:a)out<<x<<",";return out<<"]";
}
 
template <typename Arg1>
ostream& operator << (ostream& out, const set<Arg1> &a) {
    out<<"[";for(const auto &x:a)out<<x<<",";return out<<"]";
}
 
template <typename Arg1,typename Arg2>
ostream& operator << (ostream& out, const map<Arg1,Arg2> &a) {
    out<<"[";for(const auto &x:a)out<<x<<",";return out<<"]";
}
 
template <typename Arg1>
void __trace__(const string name, Arg1&& arg1){
    cerr << name << " : " << arg1 << " ] " << endl;
}
 
template <typename Arg1, typename... Args>
void __trace__(const string names, Arg1&& arg1, Args&&... args){
    const string name = names.substr(0,names.find(','));
    cerr<<name<<" : "<<arg1<<" | ";
    __trace__(names.substr(1+(int)name.size()), args...);
}
#else
    #define trace(args...)
#endif
 
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<pair<int,int>> vii;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<pair<ll,ll>> vll;
typedef vector<vl> vvl;
//typedef tree<pii, null_type, less<pii>, rb_tree_tag, tree_order_statistics_node_update> oset;
#define fori(i,n) for(int i=0;i<n;i++)
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define repd(i,a,b) for(int i=a;i>=b;i--)
#define ford(i,n)  for(int i=n-1;i>=0;i--)
#define trav(x,a) for(auto& x:a)
#define all(x) x.begin(),x.end()
#define pb push_back
#define endl '\n'
#define sz(a) (int)a.size()
#define fi first
#define se second
clock_t time_p=clock();
void time_taken()
{
    time_p=clock()-time_p;
    cerr<<"Time Taken : "<<(float)(time_p)/CLOCKS_PER_SEC<<"\n";
}
//const ll mod=998244353;
const ll mod=1e9+7;
const ll INF=1e18;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
    cout.precision(12);cout << fixed;


    int n;
    cin >> n;
    vi a(n);
    iota(all(a),1);
    vi p(n),q(n);
    fori(i,n) cin >> p[i];
    fori(i,n) cin >> q[i];
    int x,y;
    int cnt = 0;
    do{ 
       // trace(a,(a==p),(a==q));
        cnt++;
        if(p==a) x = cnt;
        if(q==a) y = cnt;

    }while(next_permutation(all(a)));
    cout << (int)abs(x-y) << endl;
    time_taken();
    return 0;
}

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

#define REP(i, s, n) for (int i = s; i < n; ++i)
#define rep(i, n) REP(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())
#define IINF INT_MAX
#define LLINF LLONG_MAX
#define DEBUG false

int main()
{
    int w, n;
    cin >> w >> n;
    vector<int> k(w);
    rep(i, w)
    {
        k[i] = i + 1;
    }
    int a, b, c;
    rep(i, n)
    {
        scanf("%d, %d", &a, &b);
        c = k[a - 1];
        k[a - 1] = k[b - 1];
        k[b - 1] = c;
    }
    rep(i, w)
    {
        cout << k[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 3128
#include <iostream>
#include <string>
#include <map>
#include <queue>
#include <cstring>
using namespace std;

int ar[11], ag[11], ab[11];
bool checked[59049];
int p3[11];
int change[9] = {0, 8, 4, 8, 4, 0, 4, 0, 8};

int conv(string s) {
	int ret = 0;
	for (int i=0; i<(int)s.size(); ++i) {
		ret *= 3;
		if (s[i] == 'g') ret += 1;
		if (s[i] == 'b') ret += 2;
	}
	return ret;
}

int rotate(int x, int n) {
	int ret = 0;
	for (int i=0; i<n; ++i) {
		ret = ret * 3 + (x % 3 + 1) % 3;
		x /= 3;
	}
	return ret;
}

int main() {
	p3[0] = 1;
	for (int i=1; i<=10; ++i) {
		p3[i] = p3[i-1] * 3;
	}
	ar[0] = ag[0] = ab[0] = 0;
	for (int i=1; i<=10; ++i) {
		ar[i] = ar[i-1];
		ag[i] = ag[i-1] * 3 + 1;
		ab[i] = ab[i-1] * 3 + 2;
	}
	string s;
	while (cin >> s, s != "0") {
		memset(checked, false, sizeof checked);
		int n = s.size();
		int first = conv(s);
		queue<pair<int,int> > q;
		q.push(make_pair(first, 0));
		checked[first] = true;
		int res = -1;
		while ( ! q.empty()) {
			int col = q.front().first;
			int t = q.front().second;
			q.pop();
			if (col == ar[n] || col == ag[n] || col == ab[n]) {
				res = t;
				break;
			}
			for (int i=0; i<n-1; ++i) {
				int replace = change[(col / p3[i]) % 9];
				int nx = (col / p3[i+2]) * p3[i+2] + replace * p3[i] + (col % p3[i]);
				if ( ! checked[nx]) {
					q.push(make_pair(nx, t+1));
					checked[nx] = true; nx = rotate(nx, n);
					checked[nx] = true; nx = rotate(nx, n);
					checked[nx] = true;
				}
			}
		}
		if (res < 0) cout << "NA" << endl;
		else cout << res << endl;
	}
	return 0;
}

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

int64_t lucas(int64_t a, int64_t b, int n){
    if (n == 0) return a;
    if (n == 1) return b;
    if (n == 2) return a + b;

    int64_t res = a + b;
    return lucas(b, res, n - 1);
}

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

    int64_t a = 2;
    int64_t b = 1;

    cout << lucas(a, b, N) << endl;    
}

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

int main(){
  long long int  a,b[200001],c=0,d=0,e=0,f=0,g=1145141919810072;
  cin>>a;
  for(int i=0;i<a;i++){
    cin>>b[i];
}
  for(int i=0;i<a;i++){
    c+=b[i];
}
    for(int j=0;j<a-1;j++){
      d+=b[j];
      e=c-d;
      f=d-e;
      if(f<0){f=f*(-1);}
      if(g>f){g=f;}
    }
  cout <<g<<endl;
  return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repp(i, a, b) for (int i = a; i <= (b); ++i)
#define repr(i, a, b) for (int i = a; i >= (b); --i)
#define bit(n) (1LL << (n))
#define sz(x) ((int)(x).size())
typedef long long ll;
const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1000000007;

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

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

int main() {
  int N;
  cin >> N;
  vector<ll> A(N);
  rep(i, N) {
    cin >> A[i];
    A[i]--;
  }

  typedef pair<int, int> P;  // pos : even, odd
  map<ll, P> num;
  rep(i, N) {
    if (i % 2 == 0)
      num[A[i]].fi++;
    else
      num[A[i]].se++;
  }

  sort(all(A));

  int ans = 0;
  rep(i, N) {
    if (i % 2 == 0) {
      if (num[A[i]].fi > 0) {
        num[A[i]].fi--;
      } else {
        ans++;
        num[A[i]].se--;
      }
    } else {
      if (num[A[i]].se > 0) {
        num[A[i]].se--;
      } else {
        ans++;
        num[A[i]].fi--;
      }
    }
  }
  ans /= 2;
  cout << ans << endl;
}

Measured memory_bytes: 7296
#include<stdio.h>

#define N 100

int main(){
  int A[N];
  int b, a, j, i, min,count=0;

  scanf("%d",&a);
  for(i=0;i<a;i++){
    scanf("%d",&A[i]);
  }

  for(i=0;i<a;i++){
    min = i;
    for(j=i;j<a;j++){
      if(A[j]<A[min]){
        min = j;
      }
    }
    if(A[i] != A[min]){
      count +=1;
    }
    b = A[i];
    A[i] = A[min];
    A[min] = b;
  }
  for(i=0;i<a-1;i++){
    printf("%d ",A[i]);
  }
  printf("%d\n",A[a-1]);
  printf("%d\n",count);
  
  return 0;
}

Measured memory_bytes: 600
package main

import (
	"sort"
	"math"
	"fmt"
)

func main() {
	var n int
	fmt.Scan(&n)

	weights := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&weights[i])
	}

	fmt.Println(exec(weights, n))
}

func exec(slice []int, n int) int {
	array := make([]int, n-1)
	for i := 0; i < n-1; i++ {
		array[i] = abs(slice, i)
	}
	return min(array)
}

func sum(slice []int) int {
	result := 0
	for _, item := range slice {
		result = result + item
	}
	return result
}

func abs(slice []int, t int) int {
	diff := sum(slice[:t+1]) - sum(slice[t+1:])
	return int(math.Abs(float64(diff)))
}

func min(slice []int) int {
	sort.Sort(sort.IntSlice(slice))
	return slice[0]
}

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

using namespace std;

#define orz int

int main()
{
	int k; scanf("%d",&k);
	if(k <= 500)
	{
		printf("%d\n",k);
		for(int i = 1;i <= k; ++ i)
		{
			for(int j = 1;j <= k; ++ j)
				printf("%d ",i);
			printf("\n");
		}
	}
	else
	{
      printf("500\n");
		for(int i = 1;i <= 500; ++ i)
		{
			for(int j = 1;j <= 500; ++ j)
			{
				orz jk = (j - i + 500);
				jk = (jk - 1) % 500 + 1;
				if(jk + 500 <= k && (i & 1))
					printf("%d ",jk + 500);
				else printf("%d ",jk);
			}
			printf("\n");
		}
	}
	return 0;
}

Measured memory_bytes: 3780
// SeeAlso: https://atcoder.jp/contests/abc121/tasks/abc121_d

#include <bits/stdc++.h>

using namespace std;

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

#define MAX 100000

typedef int _loop_int;
#define REP(i,n) for(int i = 0; i < n; i++)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define CHMIN(a,b) a=min((a),(b))
#define CHMAX(a,b) a=max((a),(b))

ll oddsolve(ll a){
    return (a+1)/2%2;
}
ll solve(ll a){
    if(a%2==1) return oddsolve(a);
    else return oddsolve(a+1)^(a+1);
}
 
int main(void) {
    ll A,B;
    cin>>A>>B;
    cout<<(solve(B)^solve(A-1))<<endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Diagram diagram = new Diagram();
		try (Scanner stdin = new Scanner(System.in)) {
			int h, w;
			while (stdin.hasNext()) {
				h = Integer.parseInt(stdin.next());
				w = Integer.parseInt(stdin.next());
				if (h < 0 || h > 300 || w < 0 || w > 300) {
					throw new RuntimeException("Input Error:Range 0 to 300");
				}
				if (h == 0 && w == 0) {
					break;
				}
				diagram.draw(h, w);
				System.out.println("");
			}
		} catch (RuntimeException e) {
			e.printStackTrace();
		}
	}
}

abstract class AbstractDiagram {
	abstract void draw(int height, int width);
}

class Diagram extends AbstractDiagram {
	//
	@Override
	void draw(int h, int w) {
		StringBuilder sb = new StringBuilder();
		for (int i = 1; i <= h; i++) {
			for (int j = 1; j <= w; j++) {
				if ((i == 1 || i == h) || (j == 1 || j == w)) {
					sb.append('#');
				} else {
					sb.append('.');
				}
			}
			System.out.println(sb);
			sb.setLength(0); // sb clear
		}
	}
}

Measured memory_bytes: 27536
#include <bits/stdc++.h>
using namespace std;
int main(){
	// freopen("input.txt", "r", stdin);
	// freopen("output.txt", "w", stdout);
	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	string s, a, b;
	cin>>s;
	int q;
	cin>>q;
	bool flag = false;
	while (q--){
		int type;
		cin>>type;
		if (type == 1){
			flag = !flag;
		}
		else{
			int add;
			cin>>add;
			char let;
			cin>>let;
			if (add == 1){
				if (flag == false){
					a.push_back(let);
				}
				else{
					b.push_back(let);
				}
			}
			else{
				if (flag == false){
					b.push_back(let);
				}
				else{
					a.push_back(let);
				}
			}
		}
	}
	if (flag == false){
		reverse(a.begin(), a.end());
		cout<<a<<s<<b;
	}
	else{
		reverse(b.begin(), b.end());
		reverse(s.begin(), s.end());
		cout<<b<<s<<a;
	}
}

Measured memory_bytes: 1040
#include <stdio.h>

main(void){
int n,c;
int cnt=0;

char s[100];

scanf("%d",&n);

scanf("%s",&s);
if(n%2==0){
	c=n/2;
	for(int i=0;i<c;i++){
		if(s[i+c]==s[i]){
			cnt++;
		}
	}
	if(cnt==c){
		printf("Yes\n");
	}else{
		printf("No\n");
	}
}else{
	printf("No\n");
}

}

Measured memory_bytes: 128