akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr int Inf = 2000000010;
constexpr ll INF= 2000000000000000000;
constexpr ll MOD = 1000000007;
const double PI = 3.1415926535897;
typedef pair<int,int> P;
typedef pair<int,P> PP;

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

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

void mod(ll &val, ll M) {
    val = val % M;
    if(val < 0) {
        val += M;
    }
}

template<typename T>
T RS(T N, T P, T M){
    if(P == 0) {
        return 1;
    }
    if(P < 0) {
        return 0;
    }
    if(P % 2 == 0){
        ll t = RS(N, P/2, M);
        if(M == -1) return t * t;
        return t * t % M;
    }
    if(M == -1) {
        return N * RS(N,P - 1,M);
    }
    return N * RS(N, P-1, M) % M;
}

ll fac[1000010], finv[1000010], inv[1000010];

// テーブルを作る前処理
void COMinit()
{
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < 1000010; i++)
    {
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k)
{
    if (n < k)
        return 0;
    if (n < 0 || k < 0)
        return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main() {
    int N;
    cin >> N;
    COMinit();
    ll ret = 0;
    for(int i = 1;i < 2000;i++) {
        if(i * 3 <= N) {
            int cnt = N - 3 * i;
            ret += COM(cnt + i - 1,i - 1);
            mod(ret,MOD);
        }
    }
    cout << ret << endl;
}

Measured memory_bytes: 27068
#include<stdio.h>
int bubblesort(int A[100],int n);
int A[100],out=0;

int main()
{
  int i,n;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&A[i]);
  }
  bubblesort(A,n);
  for(i=0;i<n-1;i++){
    printf("%d ",A[i]);
  }
  printf("%d\n",A[n-1]);
  printf("%d\n",out);
  return 0;
}

int bubblesort(int A[],int n)
{
  int i,j,temp;
  for(i=0;i<n;i++){
    for(j=n-1;j>i;j--){
      if(A[j]<A[j-1])
        {
          temp = A[j];
          A[j] = A[j-1];
          A[j-1] = temp;
          out++;
        }
    }
  }
}



Measured memory_bytes: 2128
import java.util.*;
import java.io.PrintWriter;
import static java.lang.Integer.*;
import static java.lang.Long.*;
import static java.lang.Math.*;
import static java.lang.System.*;

public class Main {
	public static int MOD = 1000000007;
	public static void main(String[] args) {
		int i,j;
		Scanner sc = new Scanner(in);
		int n = parseInt(sc.next());
		int[] a = new int[n];
		int[][] x = new int[n][];
		int[][] y = new int[n][];
		for(i=0;i<n;i++) {
			a[i] = parseInt(sc.next());
			x[i] = new int[a[i]]; 
			y[i] = new int[a[i]]; 
			for (j = 0; j < a[i]; j++) {
				x[i][j] = parseInt(sc.next());
				y[i][j] = parseInt(sc.next());
			}
		}
		sc.close();
		int[] b1pat = new int[n];
		int[] b0pat = new int[n];
		for (i = 0; i < n; i++) {
			b1pat[i] |= 1 << i;
			for (j = 0; j < a[i]; j++) {
				if(y[i][j]==1) {
					b1pat[i] |= 1 << (x[i][j]-1);
				} else {
					b0pat[i] |= 1 << (x[i][j]-1);
				}
			}
		}
//		out.println(Arrays.toString(b1pat));
//		out.println(Arrays.toString(b0pat));
		int mx = 0;
		int lm=(int)pow(2,n)-1;
		for (i = 1; i <= lm; i++) {
			boolean f = false;
			for (j = 0; j < n; j++) {
//				out.printf("%d:%d,%d%n",i,b1pat[j],b0pat[j]);
				if((i&(1<<j))==0)continue;
//				out.printf("%d:%d,%d%n",i,b1pat[j],b0pat[j]);
				if((i&b1pat[j])!=b1pat[j]||(b0pat[j]!=0&&((lm-i)&b0pat[j])!=b0pat[j])) {
					f = false;
					break;
				}
				f = true;
//				out.printf("%d:%d,%d%n",i,b1pat[j],b0pat[j]);
			}
			if(f) {
//				out.printf("%d:%n",i);
				int tmp =  Integer.bitCount(i);
				if(mx<tmp) mx = tmp; 
			}
		}
		out.println(mx);
	}
}


Measured memory_bytes: 21840
#include<iostream>
#include<math.h>
#include<string>
#include<map>
#include<vector>
#include<map>
#include<unordered_map>
#include<set>
#include<unordered_set>
#include<bitset>
#include<stack>
#include<algorithm>
#include<climits>
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL);
#define ll long long int
#define vii vector<ll>
#define mii map<ll, ll>
#define debug(x) cerr << #x << " is " << x << "\n";
#define debug1(x, y) cerr << #x << " is " << x << "\n" << #y << " is " << y << "\n";
#define w(x) ll x; cin >> x; while(x--)
#define endl "\n"
#define f first 
#define s second 
#define fo(n) for(ll i = 0LL; i < n; ++i) 
#define setbits(n) __builtin_popcount(n)
#define all(x) x.begin(), x.end()
#define sortAll(x) sort(x.begin(), x.end())
#define pb push_back
#define mk make_pair
#define PERMUTE next_permutation
#define RESET(a, b) memset(a, b, sizeof(a))
#define MOD 1000000007
using namespace std;
 
int main(){
    fast
    ll n, k;
    cin >> n >> k;
    vector<ll> a(n, 0), dp(n, INT_MAX);
    fo(n) cin >> a[i];
    dp[0] = 0;
    for(int i = 0; i < n; ++i) 
        for(int j = i + 1; j < n && j <= i + k; ++j)
            dp[j] = min(dp[j], dp[i] + abs(a[i] - a[j]));
        
    cout << dp[n - 1] << endl;
    return 0;
}

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

int main()
{
	char b;
	cin >> b;

	if ('A' == b) {
		cout << 'T' <<endl;
		return 0;
	}

	if ('T' == b) {
		cout << 'A' <<endl;
		return 0;
	}

	if ('C' == b) {
		cout << 'G' <<endl;
		return 0;
	}

	if ('G' == b) {
		cout << 'C' <<endl;
		return 0;
	}

	return 0;
}


Measured memory_bytes: 3528
from math import sqrt

def main():
    N=int(input())
    x=[0 for i in range(0,N)]
    y=[0 for i in range(0,N)]
    for i in range(0,N):
        x[i],y[i]=map(int,input().split())

    s=0
    for i in range(0,N):
        for j in range(0,N):
            s=s+sqrt((x[i]-x[j])**2+(y[i]-y[j])**2)
    s=s/N
    print(s)

if __name__=='__main__':
    main()

Measured memory_bytes: 3064
import sys
import math
import bisect
input = sys.stdin.readline
MOD = 10**9 + 7
INF = float('INF')

def main():
    n = int(input())
    b = list(map(int,input().split()))
    ans = b[0] + b[-1]
    for i in range(n-2):
        ans += min(b[i],b[i+1])
    print(ans)

if __name__ == '__main__':
    main()

Measured memory_bytes: 38256
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();
        System.out.println(saiki(n,k));


    }

    private static int saiki(int n,int k){
        if(n<k)return 1;
        else return saiki(n/k,k)+1;
    }

}




Measured memory_bytes: 23252
#include<iostream>
#include<iomanip>
#include<string>
#include<vector>
#include<algorithm>
#include<utility>
#include<tuple>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<numeric>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>

using namespace std;

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

#define BIL ((ll)1e9)
#define MOD ((ll)1e9+7)
#define INF (1LL<<60)           //1LL<<63でオーバーフロー
#define inf (1<<29)             //1<<29でオーバーフロー

int main(int argc,char* argv[]){
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout << fixed << setprecision(20);

    int n;
    cin >> n;

    ll ans=0;
    for(int a=1;a<n;a++){
        if(n%a==0){
            ans+=n/a-1;
        }else{
            ans+=n/a;
        }
    }

    cout << ans << endl;

    return 0;
}


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

int main()
{
    int n, m;
    cin >> n >> m;
    valarray<int> b(0, m);
    vector<valarray<int> > A(n, b);
    REP(i,n) {
        REP(j,m) cin >> A.at(i)[j];
    }
    REP(i,m) cin >> b[i];
    REP(i,n){
        valarray<int> c(m);
        c = A.at(i) * b;
        cout << c.sum() << endl;
    }

    return 0;
}

Measured memory_bytes: 3164
import std.stdio;
import std.array;
import std.algorithm;
import std.conv;
import std.string;


void main()
{
	int inputnum = to!int(chomp(readln()));
	for(int i = 0; i < inputnum; i++)
    {
		string[] input = split(readln());
		int[] side = new int[3];
		side[0] = to!int(input[0]);
		side[1] = to!int(input[1]);
		side[2] = to!int(input[2]);
		static bool smaller(int x,int y)
		{
			return x < y;
		}
		sort!(smaller)(side);
		if(side[0]^^2 + side[1]^^2 == side[2]^^2)
			writeln("YES");
		else
			writeln("NO");
	}
}

Measured memory_bytes: 1064
#include <bits/stdc++.h>
using namespace std;
using uint = unsigned int;
using lint = long long int;
using ulint = unsigned long long int;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;
template<class T, class U> void assign(V<T>& v, int n, const U& a) { v.assign(n, a); }
template<class T, class... Args> void assign(V<T>& v, int n, const Args&... args) { v.resize(n); for (auto&& e : v) assign(e, args...); }


template<class Int> map<Int, int> factor(Int n) {
  map<Int, int> res;
  for (Int i = 2; i * i <= n; ++i) while (n % i == 0) ++res[i], n /= i;
  if (n != 1) ++res[n];
  return res;
}

int main() {
  cin.tie(nullptr); ios_base::sync_with_stdio(false);
  int n; cin >> n;
  V<> p(100);
  for (int i = 1; i <= n; ++i) {
    for (const auto& e : factor(i)) {
      p[e.first] += e.second;
    }
  }
  // 3 * 5 * 5;
  // 3 * 25
  // 15 * 5
  // 75
  lint res = 0;
  for (int i = 0; i < 100; ++i) if (p[i] >= 74) ++res;
  for (int i = 0; i < 100; ++i) for (int j = 0; j < 100; ++j) if (i != j) {
    if (p[i] >= 2 and p[j] >= 24) ++res;
  }
  for (int i = 0; i < 100; ++i) for (int j = 0; j < 100; ++j) if (i != j) {
    if (p[i] >= 4 and p[j] >= 14) ++res;
  }
  for (int i = 0; i < 100; ++i) for (int j = 0; j < 100; ++j) for (int k = j + 1; k < 100; ++k) if (i != j and i != k) {
    if (p[i] >= 2 and p[j] >= 4 and p[k] >= 4) ++res;
  }
  cout << res << '\n';
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;;
#define ll long long
#define rep(i, n) for(int i = 0;i < n;i++)
#define repr(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define INF 1<<30
#define LINF 1LL<<62
#define all(x) (x).begin(), (x).end()
#define mp make_pair
#define pb push_back
const int MOD = 1000000007;
 
typedef pair<ll, ll> P;
typedef pair<ll, P> PP;


int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n;cin >> n;
  vector<ll> a(n+1);
  rep(i,n+1){
      cin >> a[i];
  }
  vector<ll> b(n);
  rep(i,n){
      cin >> b[i];
  }
  ll ans = 0;
  repr(i,n-1){
      if(a[i+1]>=b[i]){
          ans += b[i];
          b[i] = 0;
      }else{
          ans += a[i+1];
          b[i] -= a[i+1];
      }
      if(a[i]>=b[i]){
          ans += b[i];
          a[i] -= b[i];
      }else{
          ans += a[i];
          a[i] = 0;
      }
  }
  cout << ans << endl;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
#define int long long
int c[100000000],d[100000000];
signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int a,b,n=0,p=1;
  int q,w,m=0;
  cin>>a;
  for(int i=1;i<=a;i++){
    cin>>c[i];
    d[i]=c[i];
  }
  sort(d+1,d+a+1);
  for(int i=1;i<=a;i++){
    if(d[i]==c[i]) n++;
  }
  if(n==a&&p!=0){
    cout<<m<<"\n";
    p=0;
  }
  cin>>b;
  for(int i=1;i<=b;i++){
    cin>>q>>w;
    n=0;
    m++;
    swap(c[q],c[w]);
    int f=0;
    for(int i=1;i<=a;i++){
      if(d[i]!=c[i]) {
	f=1;
	break;
      }
      if(d[a+1-i]!=c[a+1-i]){
	f=1;
	break;
      }
    }
    if(f!=1&&p!=0){
      cout<<m<<"\n";
      p=0;
    }
  }
  if(p==1) cout<<"-1\n";
  return(0);
}




Measured memory_bytes: 7836
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define fi first
#define se second
ll sieve[1000001]={0},i,j;
ll power(ll p, ll k)
{
ll a=1;
while(k)
{
if(k&1)
a=(a*p);
p=(p*p);
k>>=1;
}
return a;
}
using namespace std;
  ll countDivisors(ll n) 
{ 
    ll cnt = 0; 
    for (ll i = 1; i <= sqrt(n); i++) { 
        if (n % i == 0) { 
            if (n / i == i) 
                cnt++; 
  
            else 
                cnt = cnt + 2; 
        } 
    } 
    return cnt; 
} 
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
 int tc=1;
//cin>>tc;
ll cas=1;
 while(tc--)
 {
	ll n;
	cin>>n;
	ll a[n];
	for(i=0;i<n;i++)
	cin>>a[i];
	ll dp[n+1][n+1];
	for(ll L=n-1;L>=0;L--)
	for(ll R=L;R<n;R++)
	{
		if(L==R)
		dp[L][R]=0;
		else
		{
			dp[L][R]=1e18;
			for(ll i=L;i<R;i++)
			{
				ll sum=0;
				for(j=L;j<=R;j++)
				sum+=a[j];
				dp[L][R]=min(dp[L][R],dp[L][i]+dp[i+1][R]+sum);
			}
		}
		
	}
	//cout<<dp[0][1]<<dp[1][2]<<dp[2][3];
	//cout<<dp[1][3]<<dp[0][2];
	cout<<dp[0][n-1];
	cout<<"\n"; 
 } 
}


Measured memory_bytes: 1536
#include <bits/stdc++.h>
 
using namespace std;
 
#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl;
#define DEBUG_MAT(v) cerr<<#v<<endl;for(int i=0;i<v.size();i++){for(int j=0;j<v[i].size();j++) {cerr<<v[i][j]<<" ";}cerr<<endl;}
typedef long long ll;
#define int ll
 
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
template<class S, class T> pair<S, T> operator+(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first + t.first, s.second + t.second); }
template<class S, class T> pair<S, T> operator-(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first - t.first, s.second - t.second); }
template<class S, class T> ostream& operator<<(ostream& os, pair<S, T> p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
#define X first
#define Y second
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define rrep1(i,n) for(int i=(n);i>0;i--)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define in(x, a, b) (a <= x && x < b)
#define all(c) c.begin(),c.end()
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a = b; return 1; } return 0; }
#define UNIQUE(v) v.erase(std::unique(v.begin(), v.end()), v.end());
const ll inf = 1000000001;
const ll INF = (ll)1e18 + 1;
const long double pi = 3.1415926535897932384626433832795028841971L;
#define Sp(p) cout<<setprecision(25)<< fixed<<p<<endl;
//int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
//int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };
vi dx = {1, 0, -1, 0}, dy = {0, 1, 0, -1};
vi dx2 = { 1,1,0,-1,-1,-1,0,1 }, dy2 = { 0,1,1,1,0,-1,-1,-1 };
#define fio() cin.tie(0); ios::sync_with_stdio(false);
const ll MOD = 1000000007;
//const ll MOD = 998244353;
// #define mp make_pair
//#define endl '\n'



signed main() {
    fio();
    ll x;
    cin >> x;
    ll y = x / 500;
    x = x % 500;
    ll z = x / 5;
    ll ans = y * 1000 + z * 5;
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<cstdio>
#include<vector>
#include<algorithm>
#include<utility>
#include<numeric>
#include<iostream>
#include<array>
#include<string>
#include<sstream>
#include<stack>
#include<queue>
#include<list>
#include<functional>
#include<set>
#include<complex>
#include<complex>
#define _USE_MATH_DEFINES

#include<math.h>
#include<map>

#define INF 200000000

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<double, double> pdd;

enum
{
	BOTTOM,
	LEFT,
	RIGHT,
	TOP
};

struct P
{
	double x, y;
	P(double x,double y) :x(x), y(y) {}
	P() :P(0, 0) {}
	P operator+(const P& v)const
	{
		return P(x + v.x, y + v.y);
	}
	P operator-(const P& v)const
	{
		return P(x - v.x, y - v.y);
	}
	P operator*(const double v)const
	{
		return P(x*v, y*v);
	}
	bool operator==(const P& v)const
	{
		return abs(x - v.x) <= 0.0000000000001&&abs(y - v.y) <= 0.00000000000001;
	}
	bool operator!=(const P& v)const
	{
		return abs(x - v.x) > 0.0000000000001 || abs(y - v.y) > 0.00000000000001;
	}

	double dot(const P& v)const
	{
		return x*v.x + y*v.y;
	}
	double cross(const P& v)const
	{
		return x*v.y - y*v.x;
	}
	double length()const
	{
		return sqrt(x*x + y*y);
	}
	double length2()const
	{
		return (x*x + y*y);
	}

	P unit()const
	{
		return P(x / length(), y / length());
	}
	
	bool operator<(const P& v)const
	{
		return x<v.x || (x == v.x) && y < v.y;
	}
	bool operator>(const P& v)const
	{
		return x>v.x || (x == v.x) && y > v.y;
	}
};

pair<P,P> cli(double a, double b, double c, double x1, double y1, double r)
{
	double l = a*a + b*b, k = a*x1 + b*y1 + c, d = l*r*r - k*k;
	if (d > 0)
	{
		double ds = sqrt(d), apl = a / l, bpl = b / l, xc = x1 - apl*k, yc = y1 - bpl*k, xd = bpl*ds, yd = apl*ds;
		return make_pair(P(xc - xd, yc + yd), P(xc + xd, yc - yd));
	}
	else
	{
		return make_pair(P(x1 - a*k / l, y1 - b*k / l), P(x1 - a*k / l, y1 - b*k / l));
	}
}

pair<P, P> cci(P p1, P p2, double r1, double r2)
{
	double a = p1.x - p2.x, b = p1.y - p2.y;
	return cli(a, b, 0.5*((r1 - r2)*(r1 + r2) - a*(p1.x + p2.x) - b*(p1.y + p2.y)), p1.x, p1.y, r1);
}

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

	double px, py, cx, cy, r;
	cin >> px >> py >> cx >> cy >> r;
	
	px -= cx;
	py -= cy;
	pair<P, P> tanp = make_pair(P(r*(px*r + py*sqrt(px*px + py*py - r*r)) / (px*px + py*py) + cx, r*(py*r - px*sqrt(px*px + py*py - r*r)) / (px*px + py*py) + cy), P(r*(px*r - py*sqrt(px*px + py*py - r*r)) / (px*px + py*py) + cx, r*(py*r + px*sqrt(px*px + py*py - r*r)) / (px*px + py*py) + cy));
	if (tanp.first > tanp.second)
	{
		swap(tanp.first, tanp.second);
	}

	printf("%.10lf %.10lf\n%.10lf %.10lf\n", tanp.first.x, tanp.first.y, tanp.second.x, tanp.second.y);

	return 0;
}


Measured memory_bytes: 3324
import java.util.*;
public class Main 
{
	public static void main(String[] args) 
	{
		Scanner stdIn = new Scanner(System.in);
		while(stdIn.hasNext())
		{
			int n = stdIn.nextInt();
			if(n == 0)
			{
				break;
			}
			List<ArrayList<Integer> > list = new ArrayList<ArrayList<Integer> >();
			for(int i = 0; i < n; ++i)
			{
				list.add(new ArrayList<Integer>());
				for(int j = 0; j < n; ++j)
				{
					list.get(i).add(0);
				}
			}
			int x = n / 2;
			int y = n / 2 + 1;
			int count = 1;
			list.get(y).set(x, count);
			int square = n * n;
			while(count < square)
			{
				++count;
				++x;
				++y;
				if(x >= n)
				{
					x = 0;
				}
				if(y >= n)
				{
					y = 0;
				}
				while(list.get(y).get(x) != 0)
				{
					--x;
					++y;
					if(x < 0)
					{
						x = n -1;
					}
					if(y >= n)
					{
						y = 0;
					}
				}
				list.get(y).set(x, count);
			}
			for(int i = 0; i < list.size(); ++i)
			{
				for(int j = 0; j < list.get(i).size(); ++j)
				{
					System.out.printf("%4d", list.get(i).get(j));
				}
				System.out.println("");
			}
		}
	}
}

Measured memory_bytes: 12000
#include <iostream>			//cout,endl,cin
#include <string>			//string,to_string,stoi
#include <vector>			//vector
#include <algorithm>		//min,max,swap,sort,reverse,lower_bound,upper_bound
#include <utility>			//pair,make_pair
#include <tuple>			//tuple,make_tuple
#include <cstdint>			//int64_t,int*_t
#include <cstdio>			//printf
#include <map>				//map
#include <queue>			//queue,priority_queue
#include <set>				//set
#include <stack>			//stack
#include <deque>			//deque
#include <unordered_map>	//unordered_map
#include <unordered_set>	//unordered_set
#include <bitset>			//bitset
#include <cctype>			//isupper,islower,isdigit,toupper,tolower
#include <math.h>
#include <cstdio>
#include <cstring>
#include <iomanip>

using namespace std;
typedef long long ll;

/*
int main() {
    ll a;
    double b;
    cin >> a >> b;
    cout << fixed << (ll)(floor(a * b)) << endl;
}
*/


int main() {
    ll n;
    ll result = 1;
    int a = 0;
    //vector<int> vc;
    cin >> n;
    while (n--) {
        ll x;
        cin >> x;
        //result = result * x;
        if (x == 0 || result == 0) {
            a = 0;
        }
        else if (x > 1000000000000000000/result) {
            a = 1;
            result = 1;
        }
        result = result * x;
        //cout << result << endl;
        //vc.push_back(x);
    }
    if (result > 1000000000000000000 || a==1) {
        cout << -1 << endl;
    }
    else {
        cout << result << endl;
    }
}



Measured memory_bytes: 3636
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<math.h>
using namespace std;
typedef long long ll;
#define int long long
#define double long double
typedef vector<int> VI;
typedef pair<int, int> pii;
typedef vector<pii> VP;
typedef vector<string> VS;
typedef priority_queue<int> PQ;
template<class T>bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }
#define fore(i,a) for(auto &i:a)
#define REP(i,n) for(int i=0;i<n;i++)
#define eREP(i,n) for(int i=0;i<=n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define eFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define rSORT(c) sort((c).rbegin(),(c).rend())
#define LB(x,a) lower_bound((x).begin(),(x).end(),(a))
#define UB(x,a) upper_bound((x).begin(),(x).end(),(a))
#define INF 1000000000
#define LLINF 9223372036854775807
#define mod 1000000007
#define eps 1e-12 
//priority_queue<int,vector<int>, greater<int> > q2;

int gcd(int a, int b) {//最大公約数
	if (b == 0)return a;
	return gcd(b, a%b);
}
int lcm(int a, int b) {//最小公倍数
	int g = gcd(a, b);
	return a / g * b;
}

int solve(int N, VI A) {

	bool F[1000010] = { false };

	REP(i, N) {
		vector<int> ret;
		int n = A[i];
		for (int i = 1; i*i <= n; ++i)
		{
			if (n%i == 0)
			{
				ret.push_back(i);
				if (i*i != n)
				{
					ret.push_back(n / i);
				}
			}
		}
		fore(j, ret) {
			if (j == 1)continue;
			if (F[j])return 2;
			F[j] = 1;
		}
	}


	return 1;
}

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

	int N; cin >> N;
	VI A(N);
	REP(i, N)cin >> A[i];

	int tmp = gcd(A[0], A[1]);
	FOR(i, 2, N)tmp = gcd(tmp, A[i]);

	int ans = solve(N, A);



	if (tmp != 1 && ans != 1)cout << "not coprime" << endl;
	else if (ans == 1)cout << "pairwise coprime" << endl;
	else cout << "setwise coprime" << endl;

	return 0;
}



Measured memory_bytes: 19812
S = input()
S_odd = S[1::2]
S_even = S[0::2]

oddlist = []
evenlist = []

for i in range(len(S_odd)):
    oddlist.append(int(S_odd[i]))
for i in range(len(S_even)):
    evenlist.append(int(S_even[i]))

EvenSum = sum(evenlist)
OddSum = sum(oddlist)


if EvenSum <= OddSum:
    ans = len(oddlist) - OddSum
    ans += EvenSum
else:
    ans = len(evenlist) - EvenSum
    ans += OddSum

print(ans)

Measured memory_bytes: 4060
#include <bits/stdc++.h>
using namespace std;
int ans=2020;
int main() { 
    //freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	int l,r;
	cin>>l>>r;
	r=min(l+2019,r);
	for(int i=l;i<=r;i++){
		for(int j=i+1;j<=r;j++){
			ans=min(ans,((i%2019)*(j%2019)%2019));
		}
	}
	cout<<ans<<endl;
    return 0; 
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <cmath>
#define ll long long
#define pb push_back
#define mp make_pair
#define vi vector<int>
#define vl vector<int>
#define endl "\n"
#define allb(x) sort((x).begin(), (x).end())
#define allg(x) sort((x).begin(), (x).end(), greater<int>())
using namespace std;
const ll M = 1e9+7;

ll GCD(ll a, ll b)
{
	if(a==0){return b;}
	if(b==0){return a;}
	return GCD(b,a%b);
}
ll GCD_EUCLID(ll a, ll b)
{
	ll dividend = a>=b ? a:b;
	ll divisor = a<=b ? a:b;
	while(divisor!=0)
	{
		ll remainder = dividend%divisor;
		dividend = divisor;
		divisor = remainder;
	}
	return dividend;
}
ll ModExponent(ll p, ll q)
{
	ll int y=0;
	if(q==0){return 1;}
	if(q%2==0)
	{
		y = ModExponent(p,q/2);
		return (y*y)%M;
	}
	else
	{
		y = ModExponent(p,q-1);
		return ((p%M)*(y))%M;
	}

}
void PrimeNumbers()
{
	//time complexity using sieve of Eratoshthenes O(loglogn)

	int n;
	cin>>n;
	int prime[n+1];
	for(int i = 0; i<=n; i++)
	{
		prime[i]=1;
	}
	prime[0]=0;
	prime[1]=0;
	//As the pair repeat after the square root
	//of any number so we will just check till square root
	//and update all the multiples of the no. to 0
	for(int i = 0; i<=sqrt(n); i++)
	{
		if(prime[i]==1)
		{
			for(int j = 2; i*j<=n; j++)
			{
				prime[i*j]=0;
			}
		}
	}
	//print all index which contains 1
	for(int i = 0; i<=n; i++)
	{
		if(prime[i]==1)
		{
			cout<<i<<" ";
		}
	}
	cout<<"\n";

}
void solve()
{
	string s;
	cin>>s;
	int l = s.length();
	if(s[l-1]!='s')
    {
        cout<<s<<"s";
    }
    else
    {
        cout<<s<<"es";
    }
}

int main()
{
	ll t=1;
	//cin>>t;
	while(t--)
	{
		solve();
	}
    return 0;
}


Measured memory_bytes: 3600
N=int(input())
a=list(map(int,input().split()))

chk=[0 for i in range(N)]
ans=0
for i in range(N):
    if chk[i]==1:
        continue
    if a[a[i]-1]==(i+1):
        ans+=1
        chk[i]=1
        chk[a[i]-1]=1
    else:
        chk[i]=1

print(ans)

Measured memory_bytes: 14008
n = gets.to_i
@a = [[]] + n.times.map {gets.split.map(&:to_i)}
@d = Array.new(n + 1, 0)
@c = Array.new(n + 1)

def calc(i)
    if @c[i]
        puts -1
        exit
    end

    @c[i] = 0
    j = @a[i][0]

    calc(j) while i != @a[j][0]

    @c[i] = nil
    m = [@d[i], @d[j]].max
    @d[i] = @d[j] = m + 1
    @a[i].shift
    @a[j].shift
end

n.times do |i|
    calc(i) until @a[i].empty?
end

p @d.max

Measured memory_bytes: 11644
parseInt(x) = parse(BigInt, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)

px(s::String)=print(s)

function main()
	n = readline() |> parseInt
	if n==2
		println(-1)
	elseif n==3
		println("aa.")
		println("..a")
		println("..a")
	else
		x = n%4+4
		for ii in 1:div(n-4,4)*4
			for jj in 1:n
				if div(jj-1,4)==div(ii-1,4)
					i = ii%4
					j = jj%4
					if (i,j)==(1,1)||(i,j)==(1,2)||(i,j)==(3,3)||(i,j)==(3,0)
						px("a")
					elseif (i,j)==(1,3)||(i,j)==(2,3)||(i,j)==(3,1)||(i,j)==(0,1)
						px("b")
					elseif (i,j)==(1,0)||(i,j)==(2,0)||(i,j)==(3,2)||(i,j)==(0,2)
						px("c")
					else
						px("d")
					end
				else
					px(".")
				end
			end
			println("")
		end
		for i in 1:x
			for j in 1:div(n-4,4)*4
				px(".")
			end
			if x==4
				if i==1
					px("aabc")
				elseif i==2
					px("ddbc")
				elseif i==3
					px("bcaa")
				else
					px("bcdd")
				end
			elseif x==5
				if i==1
					px("aabba")
				elseif i==2
					px("bcc.a")
				elseif i==3
					px("b..cb")
				elseif i==4
					px("a..cb")
				else
					px("abbaa")
				end
			elseif x==6
				if i==1
					px("aabc..")
				elseif i==2
					px("ddbc..")
				elseif i==3
					px("..aabc")
				elseif i==4
					px("..ddbc")
				elseif i==5
					px("bc..aa")
				else
					px("bc..dd")
				end
			elseif x==7
				if i==1
					px("aabbcc.")
				elseif i==2
					px("dd.dd.a")
				elseif i==3
					px("..d..da")
				elseif i==4
					px("..d..db")
				elseif i==5
					px("dd.dd.b")
				elseif i==6
					px("..d..dc")
				else
					px("..d..dc")
				end
			end
			println("")
		end
	end
end

main()

Measured memory_bytes: 176316
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define mp make_pair
#define pb push_back
#define f(i,x,n) for(int i=x;i<n;i++)
#define all(c) c.begin(),c.end()
#define print(x) cerr << (#x) << "is "<< x << "\n"
using ll = long long;
using pii = pair<int,int>;
const int MOD = 1e9+7, N = 1e5 + 10;

int32_t main(){
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	int n,d;
	cin >> n >> d;
	ll a[n][d];
	f(i,0,n){
		f(j,0,d){
			cin >> a[i][j];
		}
	}
	ll res = 0;
	f(i,0,n){
		f(j,i+1,n){
			ll ans = 0;
			f(k,0,d){
				ans += (a[i][k]-a[j][k])*(a[i][k]-a[j][k]);
			}
			ll s = sqrt(ans);
			// cout << s  << ' ' << ans<< '\n';
			if(s*s == ans){
				res++;
			}
		}
	}
	cout << res << '\n';
	return 0;
}

Measured memory_bytes: 256
main :: IO ()
main = do
    [a,b,c,x] <- map read . words <$> getContents
    print $ calc a b c x

calc :: Int -> Int -> Int -> Int -> Int
calc a b c x = length $ pairs a b c x

pairs :: Int -> Int -> Int -> Int -> [(Int,Int,Int)]
pairs a b c x = [(na,nb,nc) | na <- [0..a]
                            , nb <- [0..b]
                            , nc <- [0..c]
                            , exact na nb nc x]

exact :: Int -> Int -> Int -> Int -> Bool
exact a b c x = 500 * a + 100 * b + 50 * c == x


Measured memory_bytes: 508
#include<bits/stdc++.h>
using namespace std;
#define forr(i,a,n)	for(long long int i=a; i<n; i++)
#define loop(i,a,n)	for(long long int i=a; i>=n; i--)

int main() 
{
	ios_base :: sync_with_stdio(false),cin.tie(NULL),cout.tie(0);
	int a;
	cin>>a;
	long long int b[a],ct=0;
	forr(i,0,a)
		cin>>b[i],ct+=b[i];
	cout<<ct-a;	
	
	return 0;
}


Measured memory_bytes: 256
program monster
  implicit none
  integer(8) :: n,i,attack,attacker
  integer(8), allocatable :: a(:)
  logical, allocatable :: mask(:)

  read *, n 
  allocate (a(n),mask(n))
  read *, a 

  do while (sum(a) /= maxval(a))
    mask = a>0
    attack = minval(a,mask)
    attacker = minloc(a,1,mask)
    do i =1,n 
      a(i) = mod(a(i),attack)
    end do 
    a(attacker) = attack
  end do 
  print '(i0)', maxval(a)
  stop
end program monster

Measured memory_bytes: 1920
#include <bits/stdc++.h>
#define nl ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define ll long long
#define all(v) (v).begin(), (v).end()
#define allr(v) (v).rbegin(), (v).rend()

using namespace std;

int main() {
    nl // NIKI - lowkey

    int n; cin >> n;
    if(n == 1) cout << "Hello World";
    else {
        int a, b; cin >> a >> b;
        cout << a + b;
    }
    return 0;
}

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

int main() {
  int N , M;
  cin >> N >> M;
  int a ,b;
  vector<int> vec(N);
  for (int i = 0; i < M; i++){
    cin >> a >> b;
    vec.at(a - 1) += 1;
    vec.at(b - 1) += 1;
  }
  for (int i = 0; i < N; i++){
    cout << vec.at(i) << endl;
  }
}

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

int gcd ( int a, int b ){
  int c;
  while ( a != 0 ) {
    c = a; a = b%a;  b = c;
  }
  return b;
}

int main(){
  int N,K;
  cin>>N>>K;
  vector<int> data(N);
  for(int i=0;i<N;i++) {
    cin>>data[i];
  }
  sort(data.begin(),data.end());

  if (N==1) {
    if (data[0]==K)cout<<"POSSIBLE"<<endl;
    else cout<<"IMPOSSIBLE"<<endl;
  } else {
    bool flag = false;
    int d = gcd(data[0],data[1]);
    if (d == 1) flag = true;
    for(int i=2;!flag && i<N;i++) {
      d = gcd(d,data[i]);
      if (d == 1) flag = true;
    }

    if (flag) {
      cout<<"POSSIBLE"<<endl;
    }else{
      if ((K%d)==0&&K<=data[N-1])cout<<"POSSIBLE"<<endl;
      else cout<<"IMPOSSIBLE"<<endl;
    }
  }
  return 0;
}


Measured memory_bytes: 640
dp = [0] * 34
dp[0] = 1
for i in range(30):
    dp[i+1] += dp[i]
    dp[i+2] += dp[i]
    dp[i+3] += dp[i]
while True:
    n = input()
    if n == 0: break
    print(dp[n]//3650+1)

Measured memory_bytes: 4208
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#define CK(N, A, B) (A <= N && N < B)
#define REP(i, a, b) for (int i = a; i < b; i++)
#define RREP(i, a, b) for (int i = (b - 1); a <= i; i--)
#define F first
#define S second
#define ll long long

const int INF = 1e9;
const long long LLINF = 1e18;

using namespace std;

int dy[] = {0,1,0,-1};
int dx[] = {1,0,-1,0};
int dy8[] = {0,1,1,1,0,-1,-1,-1};
int dx8[] = {1,1,0,-1,-1,-1,0,1};

/*==================================================*/
/*variable*/
string S;
/*==================================================*/
/*function*/

/*==================================================*/

int main(){

    cin>>S;

    bool alp[26];
    REP(j,0,26) alp[j] = false;

    if(S.size() < 26){
        REP(j,0,S.size()){
            alp[int(S[j] - 'a')] = true;
        }
        REP(j,0,26){
            if(!alp[j]){
                cout<<S<<char('a' + j)<<endl;
                return 0;
            }
        }
    }else{
        REP(j,0,S.size()){
            alp[int(S[j] - 'a')] = true;
        }
        RREP(i,0,S.size()){
            alp[int(S[i] - 'a')] = false;
            REP(j,0,26){
                if(!alp[j] && S[i] < char('a' + j)){
                    cout<<S.substr(0,i)<<char('a' + j)<<endl;
                    return 0;
                }
            }
        }
    }

    if(S.size() == 26){
        cout<<-1<<endl;
        return 0;
    }else{
        REP(j,0,26){
            if(!alp[j]){
                cout<<S<<char('a' + j)<<endl;
                return 0;
            }
        }
    }
    return 0;
}



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

main()
{
    std::string s;
    std::cin >> s;
    int flag = 0;
    for (int i=0; i<3; i++) {
        if (s[i] == s[i+1]) {flag = 1;}
    }
    if (flag) {
        std::cout << "Bad" << std::endl;
    } else {
        std::cout << "Good" << std::endl;
    }
}

Measured memory_bytes: 256
// 2020-08-23 05:56:12
#include<bits/stdc++.h>
#ifdef LOCAL
#include "lib/debug.hpp"
#else
#define debug(...) 1
#endif
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define rep(i, n) REP(i, 0, (n))
#define repc(i, n) REPC(i, 0, (n))
#define REP(i, n, m) for (int i = (int)(n); i < (int)(m); i++)
#define REPC(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define REPCM(i, n, m) for (int i = (int)(n); i >= (int)(m); i--)
using namespace std;
using ll = long long;
using ld = long double;
using pr = pair<ll, ll>;
using vll = vector<ll>;
using vpr = vector<pr>;
using P = pair<int, int>;
template<class T> inline bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; } else return false; }
template<class T> inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } else return false; }
const int mod = 1000000007;
struct mint {
  ll val;
  constexpr mint(ll v = 0) noexcept : val(v % mod) {
    if (val < 0) val += mod;
  }
  constexpr mint operator + (const mint& rhs) const noexcept {
    return mint(*this) += rhs;
  }
  constexpr mint operator - (const mint& rhs) const noexcept {
    return mint(*this) -= rhs;
  }
  constexpr mint operator * (const mint& rhs) const noexcept {
    return mint(*this) *= rhs;
  }
  constexpr mint operator / (const mint& rhs) const noexcept {
    return mint(*this) /= rhs;
  }
  constexpr mint operator ~ () const noexcept {
    ll a = this->val, b = mod, u = 1, v = 0;
    while (b > 0) {
      ll t = a / b;
      a -= t * b;
      u -= t * v;
      ll c = a; a = b; b = c;
      ll w = u; u = v; v = w;
    }
    if (u < 0) u += mod;
    u %= mod;
    return u;
  }
  constexpr mint& operator += (const mint& rhs) noexcept {
    val += rhs.val;
    if (val >= mod) val -= mod;
    return *this;
  }
  constexpr mint& operator -= (const mint& rhs) noexcept {
    if (val < rhs.val) val += mod;
    val -= rhs.val;
    return *this;
  }
  constexpr mint& operator *= (const mint& rhs) noexcept {
    val = val * rhs.val % mod;
    return *this;
  }
  constexpr mint& operator /= (const mint& rhs) noexcept {
    val = val * (~(mint(rhs))).val % mod;
    return *this;
  }
  friend mint modpow (mint a, ll n) noexcept {
    auto res = mint(1);
    while(n > 0) {
      if(n&1) res *= a;
      a *= a;
      n >>= 1;
    }
    return res;
  }
  friend std::ostream& operator << (std::ostream& os, const mint& a) noexcept {
    return os << a.val;
  }
  friend std::string debug_s (mint a) noexcept {
    return std::to_string(a.val);
  }
};

mint dp[50][1<<16];
void answer() {
  int n, x, y, z, sz, ng;
  cin >> n >> x >> y >> z;
  sz = x + y + z - 1;
  ng = 1;
  ng <<= x;
  ng |= 1;
  ng <<= y;
  ng |= 1;
  ng <<= z-1;
  dp[0][0] = 1;
  rep(i, n) rep(b, 1<<sz) REPC(m, 1, 10) {
    int nxt = b << 1;
    nxt |= 1;
    nxt <<= m - 1;
    if((nxt & ng) == ng) continue;
    nxt &= (1 << sz) - 1;
    dp[i+1][nxt] += dp[i][b];
  }
  mint ans = modpow(mint(10), n);
  rep(b, 1<<sz) ans -= dp[n][b];
  cout << ans << '\n';
}
int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  answer();
  return 0;
}

Measured memory_bytes: 24012
#include <iostream>
#include <algorithm>
#define rep(i, a, n) for(int i = a;i < n;i++)
using namespace std;


int a, b, c, x;


int main(){
	cin >> a >> b >> c >> x;

	int cnt = 0;

	rep(i, 0, a+1){
		rep(j, 0, b+1){
			rep(k, 0, c+1){
				if(i*500 + j*100 + k*50 == x) cnt++;
			}
		}
	}

	cout << cnt << endl;

	return 0;
}

Measured memory_bytes: 384
class GuessWhat:
    def __init__(self, n):
        self.what = [10 for _ in range(n)]
        self.guessable = True
    
    def set_sc(self, s, c):
        if self.what[s - 1] == 10:
            self.what[s - 1] = c
        elif not self.what[s - 1] == c:
            self.guessable = False
    
    def get_what(self):
        if len(self.what) > 1:
            if self.what[0] == 0:
                self.guessable = False
            else:
                for i in range(len(self.what)):
                    if self.what[i] == 10:
                        if i == 0:
                            self.what[i] = 1
                        else:
                            self.what[i] = 0
        else:
            if self.what[0] == 10:
                self.what[0] = 0
        if self.guessable:
            return "".join("{}".format(w) for w in self.what)
        else:
            return "-1"

n, m = list(map(int, input().split(" ")))
gw = GuessWhat(n)

for i in range(m):
    s, c = list(map(int, input().split(" ")))
    gw.set_sc(s, c)

print(gw.get_what())

Measured memory_bytes: 3064
#include <stdio.h>
int main (void)
{
    int kazu=1,tou=1;//???????????\??????????????????¨??????
    int a,b,c;//for???????????????¨?????????¢???°
    int an=0;//??????????????????¨??????¢???°
 
     
    while(1)
    {
         
        scanf("%d %d",&kazu,&tou);
        if((kazu==0)&&(tou==0)) break;
         
 
        for(a=1;a<=kazu;a++)//???°????????¢???????????????????????????????°?????\?????????
        {
            for(b=a+1;b<=kazu;b++)
            {
                for(c=b+1;c<=kazu;c++)
                {
                    if((a+b+c==tou)&&(a!=b)&&(b!=c)&&(c!=a)) 
                    {
                        an++;
                    }
                }
            }
        }
         
        printf("%d\n",an);
        an=0;
    }
 
    return 0;
}

Measured memory_bytes: 600
#include <bits/stdc++.h>
using i64 = long long;

int main() {
    i64 n, q;
    std::cin >> n >> q;
    std::vector<i64> a(n), s(n + 1), ss(n + 1);
    for (int i = 0; i < n; i++) {
        std::cin >> a[i];
        s[i + 1] = s[i] + a[i];
    }

    ss[0] = a[0];
    ss[1] = a[1];
    for (int i = 2; i < n; i++) {
        ss[i] = ss[i - 2] + a[i];
    }

    while (q--) {
        i64 x;
        std::cin >> x;

        int pos = std::lower_bound(a.begin(), a.end(), x) - a.begin();
        int l = pos ? pos - 1 : 0, r = n;
        while (r - l > 1) {
            int mid = (l + r) / 2;
            i64 d = std::abs(a[mid] - x);
            int p = std::lower_bound(a.begin(), a.end(), x - d) - a.begin();
            int k = mid - p + 1;
            // printf("d = %d, p = %d, k = %d\n", d, p, k);
            if (n - k > mid) l = mid;
            else r = mid;
        }
        // std::cout << "l : " << l << std::endl;

        int k = n - 1 - l;
        int p = l - k;
        if (p < 0) {
            std::cout << s[n] - s[l + 1] << std::endl;
        } else {
            std::cout << s[n] - s[l + 1] + ss[p] << std::endl;
        }
    }

    return 0;
}

Measured memory_bytes: 4096
#include <bits/stdc++.h>
using namespace std;
bitset<5005> pref[5005], suff[5005];
int a[5005];
int main(){
    int n, k;
    scanf("%d%d", &n, &k);
    pref[0][0] = suff[n+1][0] = 1;
    for(int i=1;i<=n;i++){
        scanf("%d", &a[i]);
        for(int j=0;j<=k;j++){
            if(pref[i-1][j]){
                if(j+a[i] <= k) pref[i][j+a[i]] = 1;
                pref[i][j] = 1;
            }
        }
    }
    for(int i=n;i>=1;i--){
        for(int j=0;j<=k;j++){
            if(suff[i+1][j]){
                if(j+a[i] <= k) suff[i][j+a[i]] = 1;
                suff[i][j] = 1;
            }
        }
    }
    int ans = 0;
    for(int i=1;i<=n;i++){
        if(a[i] >= k) continue;
        int l = k-a[i], r = k-1, sum = 0, ok = 1;
        for(int j=l;j<=r;j++) if(suff[i+1][j]) sum++;
        for(int j=0;j<=k-1;j++){
            if(pref[i-1][j] && sum > 0){
                ok = 0;
                break;
            }
            if(l > 0){
                l--;
                if(suff[i+1][l]) sum++;
            }
            if(suff[i+1][r]) sum--;
            r--;
        }
        if(ok) ans++;
    }
    printf("%d\n", ans);
}

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

using namespace std;
using ll = long long;
using ld = long double;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define reps(i,s,n) for(int i=(int)(s);i<(int)(n);i++)
#define allsort(v) sort(v.begin(),v.end())
const ll mod = 1e9 + 7;
const int inf = 1e9;

int main() {
	cin.sync_with_stdio(false);
	int N, x;
	cin >> N >> x;
	vector<int>a(N);
	for (auto &i : a)cin >> i;
	ll ans = 0;
	rep(i, N - 1) {
		ll sum = a[i] + a[i + 1];
		if (sum > x) {
			a[i + 1] -= (sum - x <= a[i + 1] ? sum - x : a[i + 1]);
			ans += sum - x;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 640
N, T = gets.chomp.split(" ").map(&:to_i)
A = gets.chomp.split(" ").map(&:to_i)

D = Hash.new{|h, k| h[k] = 0}
mx = 0
A.reverse.each{|a|
  mx = a if mx < a
  D[mx-a] += 1 if mx > a
}

puts D[D.keys.max]


Measured memory_bytes: 17540
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.IOException;
import java.util.NoSuchElementException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        FasterScanner in = new FasterScanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskB solver = new TaskB();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskB {
        public void solve(int testNumber, FasterScanner in, PrintWriter out) {
            final int n = in.nextInt();
            final int k = in.nextInt();

            int ans = 0;
            for (int i = 0; i < n; i++) {
                int cn = in.nextInt();
                ans += 2 * Math.min(cn, Math.abs(cn - k));
            }
            out.println(ans);
        }

    }

    static class FasterScanner {
        private InputStream in;
        private byte[] buffer;
        private int bufPointer;
        private int bufLength;

        public FasterScanner(InputStream in) {
            this.in = in;
            buffer = new byte[1024];
        }

        private boolean hasNextByte() {
            if (bufPointer < bufLength) return true;
            bufPointer = 0;
            try {
                bufLength = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            return (bufLength > 0);
        }

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

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

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

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

        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' || b > '9') throw new NumberFormatException();

            while (true) {
                if (b >= '0' && b <= '9') {
                    n *= 10;
                    n += b - '0';
                } else if (b == -1 || !isPrintableChar(b)) {
                    return minus ? -n : n;
                } else {
                    throw new NumberFormatException();
                }
                b = readByte();
            }
        }

    }
}



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

using namespace std;

const int N=1e6+5,MOD=998244353;

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

typedef long long ll;

int u,v,p,d,n,tc,q,k,l,r,c,m,b[N],cnt,curr,a[N],ans;

bool sum[N];

char s[N];

int main()
{
    int p,q,r;
    scanf("%d%d%d",&p,&q,&r);
    printf("%d\n",min(q+r,min(p+q,p+r)));
}







Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<ctime>
#include<cmath>
#include<cstring>
#include<cctype>
#include<complex>
#include<iostream>
#include<sstream>
#include<algorithm>
#include<functional>
#include<vector>
#include<string>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<bitset>
#include<numeric>
using namespace std;
const int dx[]={1,0,-1,0};
const int dy[]={0,1,0,-1};
#define INF 1e+8
#define EPS 1e-7
#define PB push_back
#define fi first
#define se second
#define ll long long
#define reps(i,j,k) for(int i = (j); i < (k); i++)
#define rep(i,j) reps(i,0,j)
typedef pair<int,int> Pii;
typedef vector<int> vi;
int main(){
    int n;
    while(scanf("%d",&n),n){
        vector <ll> jo;
        ll sum = 0;
        rep(i,n){
            int p;
            scanf("%d",&p);
            sum += (ll)p;
        }
        rep(i,n-1){
            ll x;
            scanf("%lld",&x);
            jo.PB(x);
        }
        ll ans = -1*INF;
        sort(jo.begin(),jo.end());
        reverse(jo.begin(),jo.end());
        jo.PB(0);
        for(int i = n-1;i > 0; i--){
            jo[i] = jo[i-1];
        }
        jo[0]=0;
        partial_sum(jo.begin(),jo.end(),jo.begin());
        rep(i,n){
            ll sub = sum;
            sub += jo[n-i-1];
            sub *= (i+1);
            ans = max(ans,sub);
        }
        printf("%lld\n",ans);
    }
    return 0;
}

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

#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)

#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=int(a)-1;i>=int(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)

#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
#define popcount(n) (__builtin_popcountll(n))

template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}

using namespace std;

using ll=long long;
using R=double;
const R eps=1e-10;
using vec=valarray<R>;
using mat=valarray<vec>;

vec gauss_jordan(mat &a){
	const int n=a.size(),m=a[0].size();
	rep(i,n){
		int pivot=i;
		rep(j,i,n) if(abs(a[j][i])>abs(a[pivot][i])) pivot=j;
		swap(a[i],a[pivot]);

		if(abs(a[i][i])<eps) return vec();

		rep(j,i+1,m) a[i][j]/=a[i][i];
		rep(j,n) if(i!=j) rep(k,i+1,m) a[j][k]-=a[j][i]*a[i][k];
	}	

	vec x(0.0,n);
	rep(i,n) x[i]=a[i][n];
	return x;
}

ll comb[21][21];

inline ll calc(int a,int ai,int b,int bi){
	ll ret=1LL;
	rep(loop,ai) ret*=a;
	rep(loop,bi) ret*=b;
	return ret;
}

int main(void){
	rep(i,21)rep(j,i+1){
		if(j==0||j==i)
			comb[i][j]=1LL;
		else
			comb[i][j]=comb[i-1][j]+comb[i-1][j-1];
	}

	int a,m,b,n;
	while(cin >> a >> m >> b >> n,a){
		const int row=m*n,col=m*n+1;
		mat matrix(vec(0.0,col+1),row+1);

		for(int d=0;d<col;++d){
			for(int k=0;k<=d;++k){
				ll coef=comb[d][k];
				coef*=calc(a,(d-k)/m,b,k/n);
				matrix[((d-k)%m)*n+k%n+1][col-1-d]+=coef;
			}
		}

		matrix[0][0]=1;
		matrix[0][m*n+1]=1;

		vec ans=gauss_jordan(matrix);
		rep(i,col) cout << (i?" ":"") << int(round(ans[i]));
		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 3088