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

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

	void run(){
		char[] wormcolor;
		Scanner sc = new Scanner(System.in);
		while(true){
			wormcolor = sc.next().toCharArray();
			if(wormcolor[0] == '0'){
				break;
			}
			System.out.println(BFS(wormcolor));
		}
	}

	String BFS(char[] wc){
		HashSet<String> used = new HashSet<String>();
		Queue<Worm> q = new LinkedList<Worm>();
		Worm wm = new Worm(wc, 0);
		q.add(wm);
		while(!q.isEmpty()){
			Worm cur = q.poll();
			if(cur.isSameColor()){
				return cur.getDepth()+"";
			}
			if(used.contains(String.valueOf(cur.getColor()))){
				continue;
			}
			used.add(String.valueOf(cur.getColor()));
			for(Worm nw: cur.getNext()){
				q.add(nw);
			}
		}
		return "NA";
	}
}

class Worm{
	char[] color;
	int depth;
	HashMap<String,Character> table = new HashMap<String,Character>(); 
	public Worm(char[] color, int depth){
		this.color = color;
		this.depth = depth;
		table.put("rg",'b'); table.put("gr",'b');
		table.put("rb",'g'); table.put("br",'g');
		table.put("gb",'r'); table.put("bg",'r');
	}

	boolean isSameColor(){
		for(int i=0; i < color.length - 1; i++){
			if(color[i] != color[i+1]){
				return false;
			}
		}
		return true;
	}

	public int getDepth(){
		return depth;
	}

	public char[] getColor() {
		return color;
	}

	public ArrayList<Worm> getNext(){
		ArrayList<Worm> result = new ArrayList<Worm>();
		for(int i = 0; i < color.length - 1; i++){
			if(color[i] == color[i+1]){
				continue;
			}
			char[] cp = Arrays.copyOf(color, color.length);
			cp[i] = table.get(String.valueOf(color[i]) + color[i+1]);
			cp[i+1] = table.get("" + color[i] + color[i+1]);
			result.add(new Worm(cp, depth+1));
		}
		return result;
	}
}

Measured memory_bytes: 178468
#include <iostream> 
#include <string> 
#include <vector> 
#include <algorithm> 
#include <utility> 
#include <tuple> 
#include <cstdint> 
#include <cstdio> 
#include <map> 
#include <queue> 
#include <set> 
#include <stack> 
#include <deque> 
#include <unordered_map> 
#include <unordered_set> 
#include <bitset> 
#include <cctype> 
using namespace std;

int jousu(int, int);
int jousu(int x, int y) {
	int z = 1;
	for (int i = 0; i < y; i++) {
		z *= x;
	}
	return z;
}
int kurai(int x, int y) {
	int z = (x%jousu(10,y)) / jousu(10, y-1);
	return z;
}
int keta(int x) {
	int z = x;
	int w = 0;
	while (z != 0) {
		z /= 10;
		w++;
	}
	return w;
}


int main(){
	int n, a = 0;
	string s;
	cin >> n >> s;
	for (int i = 0; i < s.size() - 2; i++) {
		if (s[i] == 'A') {
			if (s[i + 1] == 'B') {
				if (s[i + 2] == 'C') {
					a++;
				}
			}
		}
	}
	cout << a << endl;
}

Measured memory_bytes: 256
<?php
$num=trim(fgets(STDIN));
$array=[];
for($i=0;$i<$num;$i++){
 $array[]=trim(fgets(STDIN));   
}

$sum=0;

rsort($array);
$sum+=intdiv($array[0],2);

unset($array[0]);
$sum+=array_sum($array);

echo $sum;
?>

Measured memory_bytes: 4728
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AGC017B {
    class Program {
        static void Main(string[] args) {
            int[] input = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
            int n = input[0] - 1;
            int A = input[1];
            int B = input[2];
            int C = input[3];
            int D = input[4];
            int target = Math.Abs(B - A);
            bool ok = true;
            int first = (target + D - 1) / D;
            if (first > n) {
                ok = false;
            } else {
                int remain = n - first;
                if (remain % 2 == 0) {
                    int fhigh = first * D;
                    int flow = first * C;
                    if (flow <= target) {
                        ok = true;
                    } else {
                        if(D - C == 0) {
                            ok = false;
                        } else {
                            int diff = flow - target;
                            int p = (diff + (D - C) - 1) / (D - C);
                            if (p <= remain / 2) {
                                ok = true;
                            } else {
                                ok = false;
                            }
                        }
                    }
                } else {
                    int fhigh = (first + 1) * D;
                    int flow = (first + 1) * C;
                    if (flow <= target) {
                        ok = true;
                    } else {
                        if(D - C == 0) {
                            ok = false;
                        } else {
                            int diff = target - (first - 1) * D;
                            int p = (diff + (D - C) - 1) / (D - C);
                            if (p <= (remain + 1) / 2) {
                                ok = true;
                            } else {
                                ok = false;
                            }
                        }
                    }
                }
            }
            if (ok) {
                Console.WriteLine("YES");
            } else {
                Console.WriteLine("NO");
            }
        }
    }
}


Measured memory_bytes: 13396
#include <bits/stdc++.h>
using namespace std;
long long n;
long long x[1100000],y[1100000],xx[1100000],yy[1100000];
long long ans;
int main()
{
	cin >> n;
	for(int i=1; i<=n; i++)
		cin >> x[i] >> y[i],xx[i] = x[i] + y[i],yy[i] = x[i] - y[i];
	sort(xx + 1, xx + 1 + n);
	ans = xx[n] - xx[1];
	sort(yy + 1, yy + 1 + n);
	ans = max(ans, yy[n] - yy[1]);
	cout << ans << endl;
}

Measured memory_bytes: 9880
#include<iostream>
#include<string>
#include<iomanip>
#include<cmath>
#include<vector>
#include<algorithm>

using namespace std;

#define int long long
#define endl "\n"

constexpr long long INF = (long long)1e18;
constexpr long long MOD = 1'000'000'007; 

string yn(bool f){return f?"Yes":"No";}
string YN(bool f){return f?"YES":"NO";}

void dfs(vector<vector<int>> &tree, vector<int> &dis, int node, int per, int d){
	dis[node] = d;
	
	for(int next : tree[node]){
		if(next == per) continue;
		
		dfs(tree, dis, next, node, d+1);
	}
}

signed main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cout<<fixed<<setprecision(10);
	
	int ans = 0;
	int N, u, v;
	vector<vector<int>> tree;
	vector<int> dis, dis2;
	
	cin>>N>>u>>v;
	
	u--, v--;
	
	tree.resize(N);
	dis.resize(N);
	dis2.resize(N);
	
	for(int i = 0; i < N-1; i++){
		int A, B;
		
		cin>>A>>B;
		
		A--, B--;
		
		tree[A].push_back(B);
		tree[B].push_back(A);
	}
	
	dfs(tree, dis, u, -1, 0);
	dfs(tree, dis2, v, -1, 0);
	
	for(int i = 0; i < N; i++){
		if(dis[i] <= dis2[i]) {
			ans = max(ans, dis2[i]-1);
		}
	}
	
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 13952
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int N = 1e3 + 10;

signed main() {
	// ios::sync_with_stdio(false);
	ll a, b, c;
	scanf("%lld %lld.%lld", &a, &b, &c);
	b = b * 100 + c;
	ll x = a * b;
	string ans;
	while (x) ans += x % 10 + '0', x /= 10;
	if (ans.size() <= 2) printf("0\n");
	else {
		for (int i = ans.size() - 1; i > 1; i--)
			printf("%c", ans[i]);
		printf("\n");
	}
	return 0;
}

Measured memory_bytes: 3640
'use strict'

const main = (input) => {
    input = input.split('\n').map(v => parseInt(v))
    const n = input[0]
    const arr = input.slice(1, n + 1)
    let max = -100000000000
    let min = arr[0]

    for(let j = 1; j < arr.length; j++){
        max = Math.max(max, arr[j] - min)
        min = Math.min(min, arr[j])
    }

    console.log(max)
}

main(require('fs').readFileSync('/dev/stdin', 'utf-8'))


Measured memory_bytes: 44056
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0,i##_max=(N);i<i##_max;++i)
#define repp(i,l,r) for(int i=(l),i##_max=(r);i<i##_max;++i)
#define per(i,N) for(int i=(N)-1;i>=0;--i)
#define perr(i,l,r) for(int i=r-1,i##_min(l);i>=i##_min;--i)
#define all(arr) (arr).begin(), (arr).end()
#define SP << " " <<
#define SPF << " "
#define SPEEDUP cin.tie(0);ios::sync_with_stdio(false);
#define MAX_I INT_MAX //1e9
#define MIN_I INT_MIN //-1e9
#define MAX_UI UINT_MAX //1e9
#define MAX_LL LLONG_MAX //1e18
#define MIN_LL LLONG_MIN //-1e18
#define MAX_ULL ULLONG_MAX //1e19
  typedef long long ll;
  typedef pair<int,int> PII;
  typedef pair<char,char> PCC;
  typedef pair<ll,ll> PLL;
  typedef pair<char,int> PCI;
  typedef pair<int,char> PIC;
  typedef pair<ll,int> PLI;
  typedef pair<int,ll> PIL; 
  typedef pair<ll,char> PLC; 
  typedef pair<char,ll> PCL; 

inline void YesNo(bool b){ cout << (b?"Yes" : "No") << endl;}
inline void YESNO(bool b){ cout << (b?"YES" : "NO") << endl;}
inline void Yay(bool b){ cout << (b?"Yay!" : ":(") << endl;}

int main(void){
  SPEEDUP
  cout << setprecision(15);
  int N,K;cin >> N >> K;
  vector<double> v(N+1,0.0);
  rep(i,N){
    cin >> v[i+1];
    v[i+1] = (v[i+1]+1.0)/2.0;
  }
  rep(i,N){
    v[i+1] += v[i];
  }
  double ans = 0;
  repp(i,K,N+1){
    ans = max(ans,v[i]-v[i-K]);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1792
import java.io.IOException;
import java.io.InputStream;
import java.util.NoSuchElementException;

public class Main {
	public static void main(String[] args) {
		FastScanner sc = new FastScanner();
		char[] S = sc.next().toCharArray();
		char[] T = sc.next().toCharArray();
		String ans = "No";
		int len = S.length - 1;
		for (int i = 0; i <= len; i++) {
			if (new String(S).equals(new String(T))) {
				ans = "Yes";
				break;
			}
			char in = S[len];
			for (int j = 0; j <= len; j++) {
				char temp = S[j];
				S[j] = in;
				in = temp;
				
			}
		}
		if (new String(S).equals(new String(T))) ans = "Yes";
		System.out.println(ans);
	}



	public static long gcd(long a, long b) {
		long remainder = a % b;
		if (remainder == 0) {
			return b;
		} else {
			return gcd(b, remainder);
		}
	}
}

class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        } else {
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }

    private int readByte() {
        if (hasNextByte())
            return buffer[ptr++];
        else
            return -1;
    }

    private static boolean isPrintableChar(int c) {
        return 33 <= c && c <= 126;
    }

    public boolean hasNext() {
        while (hasNextByte() && !isPrintableChar(buffer[ptr]))
            ptr++;
        return hasNextByte();
    }

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

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

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

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


Measured memory_bytes: 21204
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		long time = 100 * (n - m) + 1900 * m;
		System.out.println(time * (1 << m));
	}
}


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

using namespace std;

bool cmp(pair<int, int> &a, pair<int, int> &b) { return a.second > b.second; }

int main() {
  int n;
  cin >> n;
  vector<pair<int, int>> red(n), blue(n);

  for (int i = 0; i < n; i++) {
    cin >> red[i].first >> red[i].second;
  }

  for (int i = 0; i < n; i++) {
    cin >> blue[i].first >> blue[i].second;
  }
  sort(blue.begin(), blue.end());
  sort(red.begin(), red.end(), cmp);

  vector<bool> is_used_red(n, false);

  int ans = 0;
  for (int i = 0; i < n; i++) {
    int blue_x = blue[i].first;
    int blue_y = blue[i].second;
    for (int j = 0; j < n; j++) {
      if (is_used_red[j]) {
        continue;
      }
      int red_x = red[j].first;
      int red_y = red[j].second;
      if (red_x < blue_x && red_y < blue_y) {
        is_used_red[j] = true;
        ans++;
        break;
      }
    }
  }

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

Measured memory_bytes: 256
#include <stdio.h>
int main (void){
    int h,w;
    scanf("%d%d\n",&h,&w);
    int loop1,loop2;
    char temp;
    int count=0;
    for(loop1=0;loop1<h;loop1++){
        for(loop2=0;loop2<w;loop2++){
            scanf("%c",&temp);
            //printf("%c",temp);
            if(temp=='#')count++;
        }
        scanf("\n");
    }
    if(count==(h+w-1))printf("Possible\n");
    else printf("Impossible\n");
    //printf("%d",count);
    return 0;
}

Measured memory_bytes: 128
#include<iostream>

using lli = long long int;
using namespace std;

int main(){
  lli N,sum = 0;
  cin >> N;
  for(lli i=1;i<=N;i++){
    if(i % 3 !=0 &&  i % 5!=0){
      sum += i;
    }
  }
  cout << sum << endl;
  return 0;
}


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

typedef long long ll;
const ll INF = 1e18;
const int BIG = 1e9 + 555;

int n;
map<ll, ll> mp;

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

	cin >> n;

	for(int i = 1; i <= n; i++){
		ll x;	cin >> x;
		mp[x]++;
	}

	vector<ll> vv;
	
	ll fRes = 0;
	for(map<ll, ll>::iterator it = mp.begin(); it != mp.end(); it++){
		if(it->second < 2){
			continue;
		}
		vv.push_back(it->first);
		if(it->second >= 4){
			fRes = max(fRes, (it->first) * (it->first));
		}
	}
	
	if((int)vv.size() > 1){
		int L = (int)vv.size();
		fRes = max(fRes, vv[L - 2] * vv[L - 1]);
	}

	cout << fRes << '\n';

	return 0;
}

Measured memory_bytes: 6528
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<vector>
#include<string.h>
#include<math.h>
#include<map>

#define MOD 1e9+7;
#define INF 1e17+9;
#define PI acos(-1);

using namespace std;

int main(){
	string s;
	cin >> s;
	int cnt_0=0,cnt_1=0;
	for(int i=0;i<s.size();i++){
		if(s[i]=='0')cnt_0++;
		if(s[i]=='1')cnt_1++;	
	}
	
	int ans=min(cnt_0,cnt_1)*2;
	
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define F(i,j,k) for(int i=(j);i<=(k);++i)
#define D(i,j,k) for(int i=(j);i>=(k);--i)
#define rep(it,s) for(auto it=s.begin();it!=s.end();++it)
#define Rep(a,s) for(auto a:s)
#define FF first
#define SS second
#define PB push_back
#define MP make_pair
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
template<class Type>inline ll quick_pow(Type x,Type y,Type MOD){
   ll res=1;
   while(y){
      if(y&1)res=res*x%MOD;
      x=x*x%MOD,y>>=1;
   }
   return res;
}
template<class Type>inline ll inv(Type x,Type MOD){return quick_pow(x,MOD-2);}
template<class Type>inline void read(Type &x){
   x=0;static int f=1;char ch=getchar();
   while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
   while(ch<='9'&&ch>='0'){x=x*10+ch-'0';ch=getchar();}
   x*=f;
}
const int N=105;
int n,m,top,a[N],b[N];
int main(){
   #ifndef ONLINE_JUDGE
      freopen("in.txt","r",stdin);
      freopen("out.txt","w",stdout);
   #endif
   read(n),read(m);
   F(i,1,m){
       read(a[i]);
       if(a[i]&1)++top;
   }
   if(top>2){
       cout<<"Impossible"<<endl;
       return 0;
   }
   F(i,2,m){
       if(a[i]&1){
           if(a[1]&1)swap(a[i],a[m]);
           else swap(a[i],a[1]);
       }
   }
   F(i,1,m)cout<<a[i]<<' ';cout<<'\n';
   if(m==1){
       if(n>1)cout<<2<<'\n'<<1<<' '<<n-1<<'\n';
       else cout<<1<<'\n'<<1<<'\n';
       return 0;
   }
   F(i,1,m){
       if(i==1)b[i]=a[i]-1;
       else if(i==m)b[i]=a[i]+1;
       else b[i]=a[i];
   }
   if(b[1]>0){
       cout<<m<<endl;
       F(i,1,m)cout<<b[i]<<' ';cout<<'\n';
   }
   else{
       cout<<m-1<<endl;
       F(i,2,m)cout<<b[i]<<' ';cout<<'\n';
   }
   return 0;
}


Measured memory_bytes: 3588
N = int(input())
A = list(map(int,input().split()))
A.sort()

w_min = A[1]

for i in range(w_min,0,-1):
    count = 0
    for j in A:
        if j%i != 0:
            count = count + 1
            if count > 1:
                break
    if count < 2:
        print(i)
        break

Measured memory_bytes: 14080
#include <stdio.h>

int main(void){
    int N, K, h[100005], x, i;
    scanf("%d%d", &N, &K);
    for (i=1; i<=N; i++) scanf("%d", &h[i]);
    x=0;
    for (i=1; i<=N; i++) {
        if (h[i]>=K) x++;
    }
    printf("%d", x);
    return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)
typedef pair<int,int> P;
typedef long long ll;
const int INF = 1001001001;
const ll INFL = 1e17;
const int MOD = 1e9+7;


int main(){
    int n;
    cin >> n;
    vector<ll> a(n);
    rep(i,n) cin >> a[i];
    ll ans = 0;
    rep(i,60){
        ll x = 0;
        rep(j,n) if(a[j]>>i & 1) ++x;
        ll now = x*(n-x)%MOD;
        rep(j,i) now = now*2%MOD;
        ans += now;
        ans %= MOD;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 5616
#include <bits/stdc++.h>
using namespace std;
int main() {
	string s,t;
	cin >> s;
	for (size_t i = 0; i < s.size(); i++)
	{
		if (s.at(i)!='x')
		{
			t += s.at(i);
		}
	}
	for (size_t i = 0; i < t.size()/2; i++)
	{
		if (t.at(i)!=t.at(t.size()-1-i))
		{
			cout << -1;
			return 0;
		}
	}
	vector<int> spot(t.size() + 1);
	int chking = 0;
	for (size_t i = 0; i < s.size(); i++)
	{
		if (chking<t.size()&&s.at(i)==t.at(chking))
		{
			chking++;
		}
		else
		{
			spot.at(chking)++;
		}
	}
	int ans=0;
	for (size_t i = 0; i < spot.size()/2; i++)
	{
		ans += abs(spot.at(i) - spot.at(spot.size() - 1 - i));
	}
	cout << ans;
}


Measured memory_bytes: 1024
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<queue>
#include<stack>
#include<complex>
#include<numeric>
using namespace std;
#define MOD 1000000007
#define MOD2 998244353
#define PRIM 3
#define INF (1<<29)
#define LINF (1LL<<60)
#define EPS (1e-10)
#define PI 3.1415926535897932384626433832795028
typedef long long Int;
typedef pair<Int, Int> P;
typedef long double Real;
typedef complex<Real> CP;
 
Int n;
Real a[440000];
Real b[440000];
Real e[440000];
Real c[440000];
 
Real bi_sum[440000];
Real b_sum[440000];
 
vector<P> highs;
set<int> done;
 
int main(){
    cin >> n;
    int mxa = 0;
    for(int i = 0;i < n;i++){
        cin >> a[i];
        a[i+n] = a[i];
        if(a[mxa] < a[i])mxa = i;
    }
    for(int i = 0;i < n;i++){
        cin >> b[i];
        b[i+n] = b[i];
    }
    e[mxa] = e[mxa + n] = a[mxa];
    for(int i = 1;i < n;i++){
        c[mxa + i+1] = - 2 * b[mxa + i] + 2*c[mxa + i] - c[mxa + i-1];
//        cout << c[mxa + i + 1] << endl;
    }
 
    using RP = pair<Real, Real>;
    vector<RP> ch = {{mxa, a[mxa] + c[mxa]}};
 
    for(int i = 1;i <= n;i++){
        RP p = {mxa + i, a[mxa + i] + c[mxa + i]};
        while(ch.size() >= 2){
            RP bb = ch[ch.size() - 2];
            RP b = ch.back();
            bb.first -= p.first;bb.second -= p.second;
            b.first -= p.first;b.second -= p.second;
            if(b.first * bb.second - b.second * bb.first <= 0)ch.pop_back();
            else break;
        }
        ch.push_back(p);
    }
    for(auto p:ch){
//        cout << p.first << " " << p.second << endl;
    }
    Real ans = a[mxa];
    for(int i = 1;i < n;i++){
        int ind = mxa + i;
        auto r = lower_bound(ch.begin(), ch.end(), RP(ind, -INF));
        auto l = prev(r);
        auto l_dist = ind - l->first;
        auto r_dist = r->first - ind;
//        cout << ind << " "  << (l_dist * r->second + r_dist * l->second) /(l_dist + r_dist) - c[ind] << endl;
        ans += (l_dist * r->second + r_dist * l->second) /(l_dist + r_dist) - c[ind]; 
    }
    printf("%.10lf\n", double(ans / n));    
    
    return 0;
}

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

#define rep(i,z) for(int i = 0; i<(int)(z); i++)
#define rep1(i,z) for(int i = 1; i<=(int)(z); i++)
 
using namespace std;

typedef long long ll;
const ll MOD=1e9+7;
using pear = pair<int,int>;

int main(){
 ll n; cin>>n;
 ll l[n];
 rep(i,n) cin>>l[i];
 ll ans=0;
 rep(i,n-2){
   for(int j=i+1;j<n-1;j++){
     if(l[i]!=l[j]){
       for(int k=j+1;k<n;k++){
         if(l[k]!=l[i]&&l[k]!=l[j]&&l[i]+l[j]>l[k]&&l[j]+l[k]>l[i]&&l[k]+l[i]>l[j]){
         ans++;
         }
       }
     }
   }
 }
 cout<<ans<<endl;
}


Measured memory_bytes: 3632
#include <cstdio>
#include <climits>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <list>
#include <set>
#include <bitset>
#include <iterator>
#define loop(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) for(long long i = 0; i < (long long)(n); i++)
#define debug(x)  cout << #x << " = " << (x) << endl;

using namespace std;
using LL = long long int;
using ULL = unsigned long long;

vector<int> common_prefix(string str) {
    int n = str.size();

    vector<int> ret(n, 0);
    ret[0] = n;
    int i = 1, j = 0;
    while (i < n) {
        while (i + j < n and str[j] == str[i + j]) ++j;

        ret[i] = j;
        if (j == 0) {
            ++i;
            continue;
        }
        int k = 1;
        while (i + k < n and k + ret[k] < j) ret[i + k] = ret[k], ++k;
        i += k; j -= k;
    }
    return ret;
}
int main() {
    int n; cin >> n;
    string s; cin >> s;

    int ans = 0;
    rep(i, n) {
        auto prefix = common_prefix(s.substr(i, n - i));
        rep(j, prefix.size()) prefix[j] = min(prefix[j], (int)j);

        ans = max(ans, *max_element(prefix.begin(), prefix.end()));
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <string>
#include <bits/stdc++.h>
#include <stdio.h>
#include<math.h>
#include <ctype.h>
#include <algorithm> // sort
#include <map> // pair
using namespace std;


int main() {
  int n,a;
  cin >> n >> a;
  cout << n*n-a << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <cmath>
#include <list>
#include <vector>
#include <tuple>
using namespace std;
//#define FILENAME "./F/in/b04"
#define rep(i,n) for(int i=0;i<n;i++)
#define ll long long

#define MOD 1000000007

ll x,a,b,a5,b5,sign;


ll mypow(ll n, ll p) {
  if(p < 1) return 1;

  if(p % 2 == 0) {int powtmp = mypow(n,p/2); return powtmp*powtmp;}
  else {int powtmp = mypow(n,p/2); return powtmp*powtmp*n;}
}


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

#ifdef FILENAME
  ifstream file(FILENAME);
  cin.rdbuf(file.rdbuf());
#endif

  cin >> x;

  for(a = 0; a < 200; a++) {
    for(b = -200; b < 200; b++) {
      if(mypow(a,5) - mypow(b,5) == x) {
	cout << a << " " << b << endl;
	return 0;
      }
    }
  }

  return 0;
}


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


int main(void) {
    int n, x;
    int ls[100];

    scanf("%d %d", &n, &x);
    for (int i=0;i<n;i++) {
        scanf("%d", ls+i);
    }

    int sum = 0;
    for (int i=0;i<n;i++) {
        sum += ls[i];       //D[i+2]
        if (sum > x) {
            printf("%d\n", i+1);
            return 0;
        }
    }

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

Measured memory_bytes: 128
N, M = map(int, input().split())

L = []
R = []

for i in range(0, M):
    l, r = map(int, input().split())
    L.append(l)
    R.append(r)

ans = min(R) - max(L) + 1
if ans < 0:
    ans = 0

print(ans)


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

int main(){
	int N;
	int i;
	int ans;
	
	cin >> N;
	
	int V[N],C[N];
	
	for(i=0; i<N; i++){
		cin >> V[i];
	}
	for(i=0; i<N; i++){
		cin >> C[i];
	}
	
	ans=0;
	for(i=0; i<N; i++){
		if(V[i]-C[i] > 0){
			ans+=V[i]-C[i];
		}
	}
	
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <algorithm>

int main()
{
    int n,k,m,ans;
    ans=0;
    scanf("%d%d",&n,&m);
    for (int i=0;i<n;i++) scanf("%d",&k);
    ans=1;
    n=n-m;
    if (n>0)
    {
        ans+=n/(m-1);
        if (n%(m-1)!=0) ans++;
    }
    printf("%d\n",ans);
    return 0;
}


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

int main() {
  int n, max = 0;
  cin >> n;
  vector<string> blue(n);
  for (int i = 0; i < n; i++) {
    cin >> blue.at(i);
  }
  int m;
  cin >> m;
  vector<string> red(m);
  for (int i = 0; i < m; i++) {
    cin >> red.at(i);
  }
  for (int i = 0; i < n; i++) {
    if (blue.at(i) == "D") {
      continue;
    }
    int money = 1;
    for (int j = i + 1; j < n; j++) {
      if (blue.at(j) == blue.at(i)) {
        money++;
        blue.at(j) = "D";
      }
    }
    for (int k = 0; k < m; k++) {
      if (red.at(k) == blue.at(i)) {
        money--;
      }
    }
    if (money > max) {
      max = money;
    }
  }
  cout << max << endl;
}

Measured memory_bytes: 256
N = int(input())
S = []
for _ in range(N):
    S.append(input())
print("AC x {}".format(S.count("AC")))
print("WA x {}".format(S.count("WA")))
print("TLE x {}".format(S.count("TLE")))
print("RE x {}".format(S.count("RE")))

Measured memory_bytes: 16120
N = int(input())
H = list(map(int, input().split()))

st, m = 0, 0
for i in range(1, N):
	if H[i - 1] >= H[i]:
		st += 1
	else:
		m = max(st, m)
		st = 0
m = max(st, m)

print(m)

Measured memory_bytes: 15020
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
using ld = long double;
using pii = pair<int, int>;

vector<int> b, a;
int main() {
    ios_base::sync_with_stdio(false);
    int n;
    cin >> n;
    a.resize(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    while (!a.empty()) {
        bool ok = false;
        for (int i = (int)a.size() - 1; i >= 0; --i) {
            if (a[i] == i + 1) {
                ok = true;
                b.push_back(a[i]);
                a.erase(a.begin() + i);
                break;
            }
        }
        if (!ok) {
            cout << -1 << endl;
            return 0;
        }
    }
    reverse(all(b));
    for (auto x: b) {
        cout << x << endl;
    }

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ld long double
#define ll long long
#define P pair<int,int>
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<n;i++)
#define all(v) v.begin(),v.end()
#define pb push_back
#define eb emplace_back
template<class T>void chmax(T &a,T b){if(a<b)a=b;}
template<class T>void chmin(T &a,T b){if(a>b)a=b;}
constexpr int INF=1000000000000000000;
constexpr int mod=1000000007;
constexpr double eps=1e-8;
const double pi=acos(-1);
int dx[]={0,1,0,-1},dy[]={1,0,-1,0};
int Random(int mi,int ma){
    random_device rnd;
    mt19937 mt(rnd());//32bit
    //[mi,ma]
    uniform_int_distribution<int>engine(mi,ma);
    return engine(mt);
}
int gcd(int a,int b){
    if(b==0)return a;
    return gcd(b,a%b);
}
int lcm(int a,int b){
    return a/gcd(a,b)*b;
}
bool prime(int a){
    if(a==1)return false;
    for(int i=2;i*i<=a;i++){
        if(a%i==0)return false;
    }
    return true;
}
int modpow(int a,int b){
    if(b==0)return 1;
    if(b%2)return modpow(a,b-1)*a%mod;
    int memo=modpow(a,b/2);
    return memo*memo%mod;
}
vector<int>kaijo,invkaijo;
void init_fact(int n){
    kaijo.resize(n+1);
    invkaijo.resize(n+1);
    kaijo[0]=1;
    for(int i=1;i<=n;i++){
        kaijo[i]=kaijo[i-1]*i;
        kaijo[i]%=mod;
    }
    rep(i,n+1)invkaijo[i]=modpow(kaijo[i],mod-2);
}
int comb(int a,int b){
    if(a<b)return 0;
    if(a<0||b<0)return 0;
    return kaijo[a]*invkaijo[a-b]%mod*invkaijo[b]%mod;
}
int inv(int x){
    x=modpow(x,mod-2);
    return x;
}
int d,c[26],s[400][26],t[400],last[26];
signed main(){
    cin.tie(0);ios::sync_with_stdio(false);
    cin>>d;
    rep(i,26)cin>>c[i];
    rep(i,d){
        rep(j,26){
            cin>>s[i][j];
        }
    }
    int score=0;
    fill(last,last+26,-1);
    rep(i,d){
        int maidx=-1,ma=-INF;
        rep(j,26){
            int score=s[i][j];
            int memo=last[j];
            last[j]=i;
            rep(k,26)score-=c[k]*(i-last[k]);
            last[j]=memo;
            if(ma<score){
                ma=score;
                maidx=j;
            }
        }
        cout<<maidx+1<<endl;
        last[maidx]=i;
    }
    return 0;
}

Measured memory_bytes: 3740
#include<bits/stdc++.h>
using namespace std;
int n,odd[100009],even[100009],input;
int posOddMax(){
	int m=0,pos=1;
	for(int i=1;i<=100000;i++) if(m<odd[i]) m=odd[i],pos=i;
	return pos;
}
int posEvenMax(){
	int m=0,pos=1;
	for(int i=1;i<=100000;i++) if(m<even[i]) m=even[i],pos=i;
	return pos;
}
int main(){
	scanf("%d",&n);
	n/=2; 
	for(int i=1;i<=n;i++){
		scanf("%d",&input);
		odd[input]++;
		scanf("%d",&input);
		even[input]++;
	}
	int q,w;
	q=posOddMax(); w=posEvenMax();
	int iq,iw; iq=odd[q],iw=even[w];
	if(q==w){
		odd[q]=0,even[w]=0;
		q=posOddMax(); w=posEvenMax();
		if((iq-odd[q])>(iw-even[w])) iw=even[w];
		else iq=odd[q];
	}
	printf("%d",n*2-iq-iw);
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
char s[1100];
int w;
int main() {
	scanf("%s", s);
	scanf("%d", &w);
	int len = strlen(s);
	for (int i = 0; i < len; i += w) putchar(s[i]);
	puts("");
	return 0;
}
	


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

int N;
string S;
vector<vector<int>> cnt(10, vector<int>(30010, 0));

int getL(int s, int x, int i) {
  int l = s, r = N + 1;
  while (l + 1 < r) {
    int m = (l + r) / 2;
    if (cnt[i][m] > x) {
      r = m;
    } else {
      l = m;
    }
  }
  return l + 1;
}

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

  cin >> N >> S;

  for (int i = 1; i <= N; i++) {
    int t = S[i - 1] - '0';
    for (int j = 0; j < 10; j++) {
      if (j == t) cnt[j][i] = cnt[j][i - 1] + 1;
      else cnt[j][i] = cnt[j][i - 1];
    }
  }

  int ans = 0;
  for (int i = 0; i < 10; i++) {
    if (cnt[i][N] == 0) continue;
    int li = getL(0, 0, i);

    for (int j = 0; j < 10; j++) {
      if (cnt[j][N] == cnt[j][li]) continue;
      int lj = getL(li, cnt[j][li], j);

      for (int k = 0; k < 10; k++) {
        if (cnt[k][N] == cnt[k][lj]) continue;
        ans++;
      }
    }
  }
  cout << ans << '\n';
  return 0;
}

Measured memory_bytes: 1536
#include<iostream>
#include<string>
#include<vector>
std::string r1[100],r2[100],s[1000000];
int main(){
	int n;
	int m;
	while(true){
	std::cin>>n;
	if(n==0)break;
	for(int i=0;i<n;i++)
		std::cin>>r1[i]>>r2[i];
	std::cin>>m;
	for(int i=0;i<m;i++)
		std::cin>>s[i];
	for(int i=0;i<m;i++){
		for(int j=0;j<n;j++){
			if(r1[j]==s[i]){
				s[i]=r2[j];
				goto p;
			}
		}
		p:;
	}
	for(int i=0;i<m;i++){
		if(i==m-1)
			std::cout<<s[i]<<std::endl;
		else{
	        std::cout<<s[i];
		}
	}
   }
}

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


int main() {
  int a, b;
  cin >> a >> b;
  int ans = a + b;
  if(ans > 9) cout << "error" << endl;
  else cout << ans << endl;
  return 0;
  
}

Measured memory_bytes: 256
#include <iostream>
#include <climits>
#include <stack>
#include <queue>
#include <string>
#include <random>
#include <utility>
#include <cmath>
#include <string.h>
#include <iomanip>
#include <stdlib.h>
#include <algorithm>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
long long int INF = 1e18;
double Pi = 3.141592653589;
const int mod = 1000000007;
// memset(a,0,sizeof(a)); →全部０にする

struct edge{int to,cost;};
vector<int> G[100005];
 
long long int n,k,i,j=1;
ll h,w,d,aaa;
int dx[8]={1,0,-1,0,1,1,-1,-1};
int dy[8]={0,1,0,-1,1,-1,-1,1,};

std::vector<P> tree[100010];
long long int a[100005],b[100005],dp[100005];
bool flag=false;
char s[105];

int main(){
	cin>>h>>w>>d;
	for(i=1;i<=h;i++){
		for(j=1;j<=w;j++){
			cin>>aaa;
			a[aaa]=i;
			b[aaa]=j;
		}
	}
	ll q;
	cin>>q;
	for(i=1;i<=h*w;i++){
		if((i-1)/d==0){
			dp[i]=0;
		}else{
			ll kore;
			kore = abs(a[i]-a[i-d])+abs(b[i]-b[i-d]);
			dp[i]=dp[i-d]+kore;
		}
	}
	ll left[100005],right[100005];
	for(i=1;i<=q;i++){
		cin>>left[i]>>right[i];
	}
	for(i=1;i<=q;i++){
		cout<<dp[right[i]]-dp[left[i]]<<endl;
	}
	return 0;
}

Measured memory_bytes: 9600
#include <iostream>
using namespace std;
 
int main()
{
    string str;
    cin >> str;
    int l = str.length();
    
    string judge = "AC";
    bool existC = false;
    for(int i = 0; i < l && judge == "AC"; i++){
        char c = str[i];
        if(i == 0){
            if(c != 'A'){
                judge = "WA";
            }
        }else if(i < 2){
            if(c < 'a' || c > 'z'){
                judge = "WA";
            }
        }else if(i < l - 1){
            if(c < 'a' || c > 'z'){
                if(c == 'C' && !existC){
                    existC = true;
                }else{
                    judge = "WA";
                }
            }
        }else if(c < 'a' || c > 'z' || !existC){
            judge = "WA";
        }
    }
    cout << judge << endl;
    
    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 ll long long
const long long INF = 1LL<<60;
const long long mod = 1e9 + 7;

int main(){
    float T, X;
    cin >> T >> X;
    float ans = T / X;
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define REPS(i,n) for(int i=1;i<=(int)(n);i++)
using namespace std;
using ll = long long;
using ld = long double;

ll gcd(ll m, ll n) {
    ll tmp;
    while (m % n != 0) {
        tmp = n;
        n = m % n;
        m = tmp;
    }
    return n;
}

int main(void) {
    ll N, X;
    cin >> N >> X;
    ll a[N];
    REP(i, N) {
        cin >> a[i];
        a[i] = abs(a[i]-X);
    }
    ll ans = 0;
    REP(i, N) {
        if (i == 0) {
            ans = a[0];
        }
        if (a[i] != 0) {
            ans = gcd(ans, a[i]);
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 1152
#include<iostream>
#include<cstring>
#include<algorithm>
#include<vector>
#include<map>
using namespace std;
const int N=200010;
map<int,int> nums;
vector<int> alls;
int a[N];
int main(){
    int n;
    cin>>n;
    for(int i=0;i<n;i++){
        scanf("%d",&a[i]);
        alls.push_back(a[i]);
        nums[a[i]]++;
    }
    sort(alls.begin(), alls.end());
    alls.erase(unique(alls.begin(),alls.end()), alls.end());
    
    long long anspre=0;
    for(auto p:alls){
        
        long long t=nums[p];
        anspre+=t*(t-1)/2;
    }
    
    for(int i=0;i<n;i++){
        long long t=nums[a[i]];
        long long q=t-1;
        long long ans=anspre-(t*(t-1)/2-q*(q-1)/2);
        cout<<ans<<endl;
    }
    return 0;
}



Measured memory_bytes: 10612
#include<stdio.h>
#define MAX 100000

typedef long long l;

int n,k;
l T[MAX];
int check(l P){
  int i=0;
  for(int j=0;j<k;j++){
    l s=0;
    while(s+T[i]<=P){
      s+=T[i];
      i++;
      if(i==n)return n;
    }
  }
  return i;
}
int solve(){
  l left=0;
  l right=100000*10000;
  l mid;
  while(right-left>1){
    mid=(left+right)/2;
    l v=check(mid);
    if(v>=n)right=mid;
    else left=mid;
  }
  return right;
}
int main(void){
  scanf("%d %d",&n,&k);
  for(int i=0;i<n;i++){
      scanf("%lld",&T[i]);
  }
  l ans=solve();
  printf("%lld\n",ans);
  return 0;
}


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

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

	vector<int> ans;
	int odd = 0;
	if( n % 2 ) odd = 1;
	for( int i = 0; i < n; i++ ) {
		if( (i + odd) % 2 == 0 ) ans.push_back( a[i] );
		else ans.insert( ans.begin(), a[i] );
	}

	for( int i = 0; i < n; i++ ) {
		if( i ) cout << " ";
		cout << ans[i];
	}
	cout << endl;
}


Measured memory_bytes: 3828
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int T = sc.nextInt();
		int[] c = new int[N];
		int[] t = new int[N];
		int min = 10000;
		for(int i=0; i<N; i++) {
			c[i] = sc.nextInt();
			t[i] = sc.nextInt();
			if(t[i]<=T) {
				if(c[i]<=min) {
					min = c[i];
				}
			}
		}
		sc.close();
		System.out.println(min==10000?"TLE":min);
	}

}

Measured memory_bytes: 35568
#include <bits/stdc++.h>
#define ll long long int
#define dbg(x) cout<<"( "<<#x<<" -> "<<x<<" )"<<endl;
using namespace std;
int main()
{
    int n;
    scanf("%d",&n);
    string s;
    cin>>s;
    int c=0;
    for (int i=0;i<n-2;i++)
    {
        string s1=s.substr(i,3);
        if (s1=="ABC")
        c++;
    }
    printf("%d\n",c);
    return 0;
}

Measured memory_bytes: 3792
//package AtCoder.ABC158;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Main {

    public static void main(String[] args) {
        long a = in.NL(), b = in.NL();
        long ans = -1;
        for (long i=2500;i>=0;i--) {
            if ( (i*8)/100 == a && (i*10)/100 == b ) {
                ans = i;
            }
        }
        out.println(ans);
        out.close();
    }

    static InputStream inputStream = System.in;
    static OutputStream outputStream = System.out;
    static InputReader in = new InputReader(inputStream);
    static PrintWriter out = new PrintWriter(outputStream);

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int NI() {
            return Integer.parseInt(next());
        }

        public long NL() {
            return Long.parseLong(next());
        }

    }
}

Measured memory_bytes: 23124
/* Code by : Suraj (@suraj1611) */

#include<bits/stdc++.h>
#include <string>

using namespace std;

#define ll long long int
#define rep(i,n) for(int i=0; i<n; i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define mx INT_MAX
#define mn INT_MIN
#define md 1000000007
#define pb push_back
#define mp make_pair
#define maxsize 1100005
#define lb cout<<endl;
#define endl "\n"
#define F first
#define S second
#define label cout<<"hello!"<<endl
#define IOS ios_base::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);

ll power(ll x, ll  y) 
{ 
	ll m=md;
   	ll ans=1;
    while (y > 0) 
    {
        if (y & 1)
            ans = (ans * x) % m;
        x = (x * x) % m;
        y >>= 1;
    }
    return ans;
} 

int main()
{
	IOS
	


	ll a,b,t;
	cin>>a>>b>>t;
	cout<<(t/a)*b<<endl;



    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
int main()
{
  string a,b;
  cin >> a >> b;
  if(a<b)
    cout << "<" << endl;
  else if(a>b)
    cout << ">" << endl;
  else
    cout << "=" << endl;
  return 0;
}

Measured memory_bytes: 3596
from itertools import groupby

a = ['_','.,!? ','abc','def','ghi','jkl','mno','pqrs','tuv','wxyz']
for i in xrange(input()):
	b = [[i for i in j] for i,j in groupby(raw_input())]
	c = []
	d = ''
	for i in b:
		index = int(i[0])
		s = a[index][(len(i))%len(a[index])-1]
		if s == '_':
			d = d + ''.join(c)
			c = []
		else:
			c.append(s)
	print d

Measured memory_bytes: 4392
import sys


def input(): return sys.stdin.readline().strip()
def I(): return int(input())
def LI(): return list(map(int, input().split()))
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def S(): return input()
def LS(): return input().split()


INF = float('inf')


n = I()
p = IR(n)
p.sort()
ans = sum(p[:-1]) + p[-1]//2
print(ans)


Measured memory_bytes: 9192
program main
  implicit none
  
  integer :: n,k,x(100)=0,i,s=0
  read(*,*)n
  read(*,*)k
  read(*,*)(x(i),i=1,n)
  
  do i = 1, n
    s = s + 2*min(x(i), abs(x(i) - k))
  end do
  
  write(*,*)s
end program main

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

using namespace std;

int main(void){
    //使用する変数の定義
    int N, M;
    int X, Y;

    //N, M, X, Y を受け取る
    cin >> N >> M;
    cin >> X >> Y;

    //vector x を受け取り，昇順にソート
    vector<int> x(N);
    for(int i = 0; i < N; i++){
        cin >> x.at(i);
    }
    sort(x.begin(), x.end());

    //vector y を受け取り，昇順にソート
    vector<int> y(M);
    for(int i = 0; i < M; i++){
        cin >> y.at(i);
    }
    sort(y.begin(), y.end());

    //戦争が勃発するか否かのフラグ
    //初めは戦争が勃発する世界線
    bool isWarHappenFlag = true;

    for(int z = X+1; z <= Y; z++){
        if(z <= x.back()){
            continue;
        } else if(z > y.front()){
            continue;
        } else {
            isWarHappenFlag = false;
            break;
        }
    }
    if(isWarHappenFlag){
        cout << "War" << endl;
    } else {
        cout << "No War" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#define rep(i,n) for(int i=0;i<(n);i++)
#define psortsecond(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.second<b.second;});
#define psortfirst(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.first<b.first;});
#define All(x) (x).begin(),(x).end()
using namespace std;
using pii  = pair<int,int>;
long long gcd(long long a, long long b){return (b == 0 ? a : gcd(b, a%b));}
long long lcm(long long a, long long b){return a*b/gcd(a,b);}
typedef long long ll;
#define MOD 1000000007
#define EPS 10e-8

int main() {
    ll A[4];
    rep(i,3){
        cin >> A[i];
    }
    ll B=abs(A[2]-A[0]);
    ll C=abs(A[1]-A[0]);
    //sort(A,A+3);
    cout << (B>C ? "A" : "B") << endl;
}

Measured memory_bytes: 888
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 1000000000000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


#define SIZE 100005

ll N;
ll table[SIZE];



int main(){

	for(int i = 0; i < SIZE; i++){

		table[i] = 0;
	}

	scanf("%lld",&N);

	ll sum = 0;
	ll tmp;

	for(ll i = 0; i < N; i++){

		scanf("%lld",&tmp);
		sum += tmp;
		table[tmp]++;
	}

	int num_query;
	scanf("%d",&num_query);

	ll from,to;

	for(int loop = 0; loop < num_query; loop++){

		scanf("%lld %lld",&from,&to);
		if(table[from] == 0){

			printf("%lld\n",sum);
			continue;
		}

		sum += (to-from)*table[from];
		table[to] += table[from];
		table[from] = 0;

		printf("%lld\n",sum);
	}

	return 0;
}


Measured memory_bytes: 4596
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
#include <stack>
#include <iomanip>
using namespace std;
#define all(x) x.begin(), x.end()
typedef vector <int> vi;
typedef pair<int,int> ii;
typedef long long ll;
typedef long double ld;
const int mod = 1e9 + 7;
const ll inf = 3e18 + 5;
int add(int a, int b) { return (a += b) < mod ? a : a - mod; }
int mul(int a, int b) { return 1LL * a * b % mod; }
int sub(int a, int b) { return (a -= b) < 0 ? a + mod : a; }
int ctz(int x) { return __builtin_ctz(x); }
int clz(int x) { return __builtin_clz(x); }

int main(){
  ios_base::sync_with_stdio(false); cin.tie(0);
  #ifdef LOCAL
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
  #endif

  ll a, b, k;
  cin >> a >> b >> k;
  ll d = min(a, k);
  a -= d;
  k -= d;
  b -= min(b, k);
  cout << a << " " << b;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
   long long n,k,m,i;
   cin>>n>>k;
   if(n<k)
   {
       m=k-n;
       if(n<m)
        cout<<n<<endl;
       else
        cout<<m<<endl;
   }
   else
   {
       if(n%k==0)
       {
           m=0;
           cout<<m<<endl;
       }
       else
       {
           m=n%k;
           i=k-m;
           if(m<i)
           cout<<m<<endl;
           else
            cout<<i<<endl;
       }
   }
    return 0;
}


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

const long long mod=1000000007;

long long pw(long long x,int y){
	long long a=1;
	while(y){
		if(y&1)a=a*x%mod;
		x=x*x%mod;
		y/=2;
	}
	return a;
}

int N;

int main(){
	cin>>N;
	cout<<(pw(10,N)-(mod+pw(9,N)*2-pw(8,N))%mod+mod)%mod<<endl;
}



Measured memory_bytes: 3580
#include<stdio.h>
int P[100];
int A[101];
int main(void){
    int n;
    int i,j,ans;

    scanf("%d",&n);
    for(i=0;i<n;i++){
	scanf("%d",&P[i]);
	for(j=P[i];j>=0;j--){
	    A[j]++;
	}
    }

    ans=0;
    for(i=0;i<=100;i++){
	if(A[i]>=i) ans=i;
    }
    printf("%d\n",ans);

    return 0;
}

Measured memory_bytes: 596
#include<bits/stdc++.h>
#define I 900000
using namespace std;
int x[99],z[99],y[99][20],h[100],a,b,c,d,e,f,i,j,k;string S;
int main(){
while(true){
for(i=0;i<99;i++){x[i]=I;}
memset(y,0,sizeof(y));
memset(h,0,sizeof(h));
cin>>a>>b>>c;
if(a==0){break;}
for(i=0;i<c;i++){
cin>>d>>e>>f>>S;
if(S[0]=='W'){
y[d][e]++;
}
else{
x[d]+=I;
x[d]-=f+1200*y[d][e];
}
}
for(i=1;i<=a;i++){z[i]=x[i];}
sort(x+1,x+a+1);
for(i=a;i>=1;i--){
for(j=1;j<=a;j++){
if(z[j]==x[i]&&h[j]==0){
cout<<j<<' '<<(x[i]+I-1)/I-1<<' '<<(99*I-x[i])%I<<endl;
h[j]=1;
}
}
}
}
}

Measured memory_bytes: 1228
#include<stdio.h>
int main(void){
        int i,n,h[11];

        for(i=0;i<10;i++){
                scanf("%d",&n);
                Ins(h,n);
        }

        for(i=0;i<3;i++){
                printf("%d\n",h[i]);
        }

        return(0);
}

Ins(int h[] , int n){
        int i;
        for(i=0;i<10;i++){
                if(h[i] < n){
                        int a =  h[i];
                        h[i] = n;
                        Ins(h,a);
                        return(0);
                }
        }
}

Measured memory_bytes: 0
import numpy as np

S = input()
b = np.zeros(len(S)-1)
num = 0
for i in range(2**(len(S)-1) -1):
    str = S[0]
    for k in range(len(S)-1):
        if b[k] == 0:
            str = str + S[k+1]
        else:
            str = str + "+" + S[k+1]
            
    num += eval(str)
    
    b[0] += 1
    for k in range(len(S)-1):
        if b[k] == 2:
            b[k+1] += 1
            b[k] = 0
            
str = S[0]
for k in range(len(S)-1):
    if b[k] == 0:
        str = str + S[k+1]
    else:
        str = str + "+" + S[k+1]
            
    
num += eval(str)

print(num)

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

int k, a,b;

int main() {
    cin >> k >> a >> b;
    int aw = a / k;
    int bw = b / k;
    if (bw - aw || a % k == 0 || b % k ==  0) {
        cout << "OK" << endl;
        return 0;
    }
    cout << "NG" << endl;
    return 0;
}

Measured memory_bytes: 3620