akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
const int maxn=4e5+5;
typedef long long LL;
int a[maxn]; int b[maxn]; int base[60]; int c[maxn];
int main(void)
{
	for(int i=0;i<31;i++) base[i]=(1<<i);
	int n; scanf("%d",&n);
	for(int i=1;i<=n;i++) scanf("%d",&a[i]);
	for(int i=1;i<=n;i++) scanf("%d",&c[i]);
	int res=0;
	for(int i=0;i<30;i++)
	{
		for(int j=1;j<=n;j++) b[j]=c[j]%base[i+1];
		sort(b+1,b+1+n);
		LL cnt=0;
		for(int j=1;j<=n;j++)
		{
			int l,r;	
			l=lower_bound(b+1,b+1+n,base[i]-(a[j]%base[i+1]))-b;
			r=upper_bound(b+1,b+1+n,base[i+1]-(a[j]%base[i+1])-1)-b;
			r--;
			if(r-l+1>=0) cnt+=r-l+1;
			
			l=lower_bound(b+1,b+1+n,base[i]+base[i+1]-(a[j]%base[i+1]))-b;
			r=upper_bound(b+1,b+1+n,base[i+2]-2-(a[j]%base[i+1]))-b;
			r--;
			if(r-l+1>=0) cnt+=r-l+1;
		}
		if(cnt&1) res|=base[i];
	}
	printf("%I64d\n",res);
	return 0;
}

Measured memory_bytes: 3584
#include <iostream>
#include <sstream>
#include <string>
#include <cmath>
#include <array>
#include <vector>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <utility>
#include <iomanip>
#include <numeric>
#include <climits>
#include <algorithm>
#include <cstdint>
using namespace std;

int main()
{
    int n;
    cin >> n;
    vector<int> niz(n);

    int sum = 0, max = INT_MIN;
    for (int i = 0; i < n; i++)
    {
        cin >> niz[i];
        sum += niz[i];
        if (niz[i] > max)
            max = niz[i];
    }

    cout << sum - (max / 2);
}

Measured memory_bytes: 3484
#include<bits/stdc++.h>
using namespace std;
int l,i,j,len,ans;
char s[102],s1[102],s2[102],c;
bool fl;
int main(){
	scanf("%s",s),l=strlen(s);
	ans=1e9;
	for (c='a';c<='z';c++){
		memcpy(s2,s,sizeof(s));
		len=l;
		for (j=0;;j++){
			fl=1;
			for (i=0;i<len && fl;i++)
				if (s2[i]!=c) fl=0;
			if (fl) break;
			swap(s1,s2);
			for (i=0;i<len-1;i++)
				if (s1[i]==c || s1[i+1]==c) s2[i]=c;
				else s2[i]=s1[i];
			len--;
		}
		ans=min(ans,j);
	}
	printf("%d",ans);
}

Measured memory_bytes: 256
S = input()

head = S[:2]
tail = S[2:]

is_yymm = True
is_mmyy = True

if head == "00" or head >= "13":
    is_mmyy = False

if tail == "00" or tail >= "13":
    is_yymm = False

if is_yymm and is_mmyy:
    print("AMBIGUOUS")
elif is_yymm:
    print("YYMM")
elif is_mmyy:
    print("MMYY")
else:
    print("NA")

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int mod, n;
typedef long long ll;
int add(int a,int b){a+=b;return a>=mod?a-mod:a;}
int sub(int a,int b){a-=b;return a<0?a+mod:a;}
int mul(int a,int b){return (ll)a*b%mod;}
int qpow(int a,int b){int ret=1;for(;b;b>>=1,a=mul(a,a))if(b&1)ret=mul(ret,a);return ret;}
/* math */
const int N = 5010;
int f[2][N],g[2][N],h1[2][N],h2[2][N];

inline void Do0(int p,int i){
	for(int j=0;j<=n;j++)f[i][j] = g[i][j] = h1[i][j] = h2[i][j] = 0;
	for(int j=0;j<=n;j++){
		f[i][j] = add(f[i][j], f[i^1][j]);
		if(j>=p){
			f[i][j] = add(f[i][j], f[i][j-p]);
		}
	}
}

inline void Do1(int p,int i){
	for(int j=0;j<=n;j++)f[i][j] = g[i][j] = h1[i][j] = h2[i][j] = 0;
	for(int j=0;j<=n;j++){
		f[i][j] = add(f[i][j], f[i^1][j]);
		if(j>=p){
			f[i][j] = add(f[i][j], f[i][j-p]);
		}
	}
}
inline void Do2(int p,int i){
	for(int j=0;j<=n;j++)f[i][j] = g[i][j] = h1[i][j] = h2[i][j] = 0;
	for(int j=0;j<=n;j++){
		f[i][j] = add(f[i][j], f[i^1][j]);
		if(j>=p){
			f[i][j] = add(f[i][j], f[i][j-p]);
		}
	}
	for(int j=0;j<=n;j++){
		h1[i][j] = add(h1[i][j], 1ll*f[i^1][j]*(j/p-1)%mod);
		if(j>=p){
			h1[i][j] = add(h1[i][j], h1[i][j-p]);
		}
	}
	for(int j=0;j<=n;j++){
		f[i][j] = sub(mul(f[i][j], j/p),h1[i][j]);
	}
}

int main()
{
	cin >> n >> mod;
	int _d = (n-1)/2;
	bool flg=0;
	if(n%2==0){ flg=1; }
	int cur = 0;
	f[cur][0] = 1;
	for(int i=_d;i;i--){
		int p = i;
		Do0(p,cur^=1);
		if(i==_d && flg)Do2(p+1,cur^=1);
		else Do1(p+1,cur^=1);
	}
	int ans = 0;
	if(n==2){cout << 3 << endl;return 0;}
	for(int i=0;i<=n;i++){
		ans = add(ans, mul(f[cur][i], n-i));
	}
	cout << ans << endl;
}

Measured memory_bytes: 384
/**
 *      ABC 62 B
 *      author  : kyomukyomupurin
 *      created : 2018-09-05 03:37:40
**/

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

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int H, W; cin >> H >> W;
    string a[H];
    for (int i = 0; i < H; ++i) {
        cin >> a[i];
    }
    for (int i = 0; i < W + 2; ++i) {
        cout << '#';
    }
    cout << endl;
    for (int i = 0; i < H; ++i) {
        cout << '#' << a[i] << '#' << endl;
    }
    for (int i = 0; i < W + 2; ++i) {
        cout << '#';
    }

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const long long INF = 1LL << 60;
const ll C = 1e9+7;

int main() {
    int N;
    cin >> N;
    int X = 0, Y = 0, T = 0;

    for(int i=0; i<N; i++) {
        int x, y, t;
        cin >> t >> x >> y;
        X = abs(x - X);
        Y = abs(y - Y);
        T = t - T;
        if((T < X + Y) || (T - X - Y) % 2 != 0) {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
}

Measured memory_bytes: 3576
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a,b,c,d;
  cin>>a>>b>>c>>d;
  if(a+b>c+d){
    cout<<"Left"<<endl;
  }
  else if(a+b==c+d){
    cout<<"Balanced"<<endl;
  }
  else if(a+b<c+d){
    cout<<"Right"<<endl;
  }
}

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

int main() {
  
  // 入力
  
  int N, K;
  cin >> N >> K;
  
  vector<long long> V(N);
  for (int i = 0; i < N; i++) {
    cin >> V[i];
  }
  
  // 左側に対してx個掘るとき
  
  vector<vector<long long>> value_left(N + 1, vector<long long>(2 * (N + 1)));
  
  value_left[0][0] = 0;
  
  for(int x = 1; x <= N; x++) {
    
    vector<long long> vec;
    long long value = 0;
    
    for(int i = 0; i < x; i++) {
      vec.push_back(V[i]);
      value += V[i];
    }
    
    sort(vec.begin(), vec.end());
    
    value_left[x][x] = value;
    
    for(int i = 0; i < x; i++) {
      value_left[x][x + i + 1] = value_left[x][x + i] - vec[i];
    }
    
  }
  
  // 右側に対してx個掘るとき
  
  vector<vector<long long>> value_right(N + 1, vector<long long>(2 * (N + 1)));
    
  value_right[0][0] = 0;
  
  for(int x = 1; x <= N; x++) {
    
    vector<long long> vec;
    long long value = 0;
    
    for(int i = 0; i < x; i++) {
      vec.push_back(V[N - i - 1]);
      value += V[N - i - 1];
    }
    
    sort(vec.begin(), vec.end());
    
    value_right[x][x] = value;
    
    for(int i = 0; i < x; i++) {
      value_right[x][x + i + 1] = value_right[x][x + i] - vec[i];
    }
    
  }
  
  // 価値の最大値を求める
  
  long long MAX = 0;
  
  for (int x = 0; x <= N; x++) { //　左側x個掘る
    for (int y = 0; y <= N; y++) { // 右側y個掘る
      
      for (int i = x; i <= 2 * x; i++) {// 左側iステップ
        for (int j = y; j <= 2 * y; j++) {// 右側jステップ
          
          if(x + y <=N && i + j <= K && value_left[x][i] + value_right[y][j] > MAX) {
            MAX = value_left[x][i] + value_right[y][j];
          }
          
        }
      }
      
    }
  }
  
  cout << MAX << endl;
  
}

Measured memory_bytes: 384
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<cstring>
#include<string>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
#include<map>
#include<set>
using namespace std;
const int inf=2147483647,dx[]={-1,0,1,0},dy[]={0,-1,0,1},N=100005,M=1000005,mod=1000000007;
const long long llinf=9223372036854775807ll;
int n,a[1005],b[1005],a1,b1;
long long ans;
long long cut(int x,int y)
{
	return min(x/a1,y/b1);
}
int main(){
	cin>>n>>a1>>b1;
	for(int i=1;i<=n;i++)
	{
		cin>>a[i]>>b[i];
		ans+=cut(a[i],b[i]);
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define N 100005
using namespace std;
int n;
int head[N],ver[N*2],nxt[N*2],tot;
void add(int a,int b)
{
	tot++;nxt[tot]=head[a];head[a]=tot;ver[tot]=b;return ;
}
int sz1,sz2;
int dis1[N];
void dfs(int x,int fa,int dep)
{
	dis1[x]=dep;
	for(int i=head[x];i;i=nxt[i])
	{
		if(ver[i]==fa)continue;
		dfs(ver[i],x,dep+1);
	}
}
int dis2[N];
void dffs(int x,int fa,int dep)
{
	dis2[x]=dep;
	for(int i=head[x];i;i=nxt[i])
	{
		if(ver[i]==fa)continue;
		dffs(ver[i],x,dep+1);
	}
}
int main()
{
	scanf("%d",&n);
	int t1,t2;
	for(int i=1;i<n;i++)
	{
		scanf("%d%d",&t1,&t2);
		add(t1,t2);add(t2,t1);	
	}
	dfs(1,-1,1);
	dffs(n,-1,1);
	for(int i=1;i<=n;i++)
	{
		if(dis1[i]<=dis2[i])sz1++;
		else sz2++;
	}
	if(sz1>sz2)puts("Fennec");
	else puts("Snuke"); 
	return 0;
}

Measured memory_bytes: 7680
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

import static java.lang.Integer.parseInt;

/**
 * Celsius and Fahrenheit
 */
public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line;
		String[] words;

		int F = parseInt(br.readLine());

		System.out.println((F - 30) / 2);
	}
}



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

const int M = 1000000;
int n;
int sch[400][20];
bool dp[2][M];
int dy[] = {0,-1,0,1,0}, dx[] = {0,0,1,0,-1};
bool table[5][5];
int y,x;

int main(){
  while(cin >> n,n){
    for(int i=0;i<n;i++){
      for(int j=0;j<16;j++)cin >> sch[i][j];
    }

    for(int i=0;i<M;i++)dp[0][i] = false;
    dp[0][4] = !sch[0][5] && !sch[0][6] && !sch[0][9] && !sch[0][10];
    

    for(int i=0;i<n-1;i++){
      int now = i&1, nxt = 1-now;
      for(int j=0;j<M;j++)dp[nxt][j] = false;

      for(int j=0;j<M;j++){
	if(dp[now][j]){
	  for(int ii=0;ii<4;ii++){
	    for(int jj=0;jj<4;jj++){
	      table[ii][jj] = ((i<5)?true:false);
	    }
	  }

	  int tmp = j;
	  for(int z=0;z<6;z++){
	    int pos = tmp%10;
	    y = pos/3; x = pos%3;
	    for(int ii=0;ii<=1;ii++){
	      for(int jj=0;jj<=1;jj++){
		table[y+ii][x+jj] = true;
	      }
	    }
	    tmp/=10;
	  }

	  tmp = j%10;
	  y = tmp/3; x = tmp%3;

	  for(int ii=1;ii<=2;ii++){
	    for(int jj=0;jj<=4;jj++){
	      bool f = true;
	      int ny = y+ii*dy[jj], nx = x+ii*dx[jj];
	      if(ny<0 || nx<0 || ny>=3 || nx>=3)continue;
	      
	      bool piyo[5][5];
	      for(int iii=0;iii<4;iii++){
		for(int jjj=0;jjj<4;jjj++){
		  piyo[iii][jjj] = table[iii][jjj];
		}
	      }

	      for(int iii=0;iii<=1;iii++){
		for(int jjj=0;jjj<=1;jjj++){
		  if(sch[i+1][ (ny+iii)*4+nx+jjj ]){
		    f = false;
		    goto END;
		  }
		  piyo[ny+iii][nx+jjj] = true;
		}
	      }

	      for(int iii=0;iii<4;iii++){
		for(int jjj=0;jjj<4;jjj++){
		  if(!piyo[iii][jjj]){
		    f = false;
		    goto END;
		  }
		}
	      }
	    END:;
	      dp[nxt][(j*10+(ny*3+nx))%M] |= f;
	    }
	  }
	}
      }
    }
    bool ans = false;
    for(int i=0;i<M;i++)ans |= dp[(n-1)&1][i];
    if(ans)cout << "1\n";
    else cout << "0\n";
  }
}

          
	  

Measured memory_bytes: 3108
// Problem : B - Frog 2
// Contest : AtCoder - Educational DP Contest
// URL : https://atcoder.jp/contests/dp/tasks/dp_b
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

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

#define pb push_back
#define vi vector<int>


int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	
	int n,k;
	cin>>n>>k;
	
	vi v(n);
	
	vi dp(n,1e9);
	
	for(int i=0;i<n;i++)
		cin>>v[i];
		
	dp[0]=0;
	dp[1]=abs(v[0]-v[1]);
	
	for(int i=2;i<n;i++)
	{
		for(int j=1;j<=k;j++)
		{
			if(i-j>=0)
				dp[i]=min(dp[i],dp[i-j]+abs(v[i]-v[i-j]));
		}
	}
		
	cout<<dp[n-1]<<"\n";
	
   	return 0;
}



Measured memory_bytes: 1024
#include <array>
#include <iostream>
#include <numeric>

int main()
{
        std::array<int, 5> scores;

        for(int& i : scores)
        {
                std::cin >> i;
                if(i < 40)
                {
                        i = 40;
                }
        }

        int sum = std::accumulate(scores.begin(), scores.end(), 0);

        std::cout << sum / scores.size() << std::endl;
        
        return 0;
}

Measured memory_bytes: 1156
#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
template<class T>
using Table = vector<vector<T>>;
const ld eps=1e-9;

//// < "D:\D_Download\Visual Studio 2015\Projects\programing_contest_c++\Debug\a.txt"
int main() {
	while (1) {
		int N; cin >> N;
		if (!N)break;
		vector<pair<int, int>>ps;
		for (int i = 0; i < N; ++i) {
			int c; cin >> c;
			if (!(i % 2)) {
				if (ps.empty()) {
					ps.emplace_back(c, 1);
				}
				else {
					if (ps.back().first == c) {
						ps.back().second++;
					}
					else {
						ps.emplace_back(c, 1);
					}
				}
			}
			else {
				if (ps.back().first == c) {
					ps.back().second++;
				}
				else {
					ps.back().first = c;
					ps.back().second++;
					if (ps.size() >= 2) {
						ps[ps.size() - 2].second += ps.back().second;
						ps.pop_back();
					}
				}
			}
		}
		int ans = 0;
		for (int i = 0; i < ps.size(); ++i) {
			if (!ps[i].first)ans += ps[i].second;
		}
		cout << ans << endl;
	}
	
	return 0;
}

Measured memory_bytes: 3028
#include<algorithm>
#include<iostream>
using namespace std;
const int N=50;
int temp1[N],temp2[N],m[N],n[N];
int main()
{
	string s,t;
	cin>>s>>t;
	int len1=s.size(),len2=t.size();
	int count1=0,count2=0;
	for(int i=0;i<len1;i++)
	{
		temp1[s[i]-'a']++;
	}
	for(int i=0;i<len2;i++)
	{
		temp2[t[i]-'a']++;
	}
	for(int i=1;i<=26;i++)
	{
		m[count1++]=temp1[i];
		n[count2++]=temp2[i];
	}
	sort(temp1,temp1+count1);
	sort(temp2,temp2+count2);
	if(count2!=count1)
	{
		cout<<"No"<<endl;
	}
	bool flag=0;
	for(int i=0;i<count1;i++)
	{
		if(temp2[i]!=temp1[i])
		{
			flag=1;
			break;
		}
	}
	if(flag)cout<<"No"<<endl;
	else {
		cout<<"Yes"<<endl;
	}
}

Measured memory_bytes: 1020
#include <stdio.h>

int main(void) {

	int n, b, f, r, v;
	int a[4][3][10] = { 0 };

	scanf("%d", &n);

	for (int n_i = 0; n_i < n; n_i++) {
		scanf("%d %d %d %d", &b, &f, &r, &v);

		a[b-1][f-1][r-1] += v;
	}

	for (int b_i = 0; b_i < 4; b_i++) {
		for (int f_i = 0; f_i < 3; f_i++) {
			for (int r_i = 0; r_i < 10; r_i++) {
				if (r_i == 9) {
					printf(" %d\n", a[b_i][f_i][r_i]);
				}
				else {
					printf(" %d", a[b_i][f_i][r_i]);
				}
			}
		}

		if (b_i < 3) {
			puts("####################");
		}
	}

	return 0;
}




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

using namespace std;

#define debug(n) cerr << #n << ':' << n << endl;
#define dline    cerr << __LINE__ << endl;

using ll = long long;
template<class T, class U> using P = pair<T,U>;
template<class T> using Heap = priority_queue<T>;
template<class T> using heaP = priority_queue<T,vector<T>,greater<T>>;
template<class T,class U> using umap = unordered_map<T,U>;
template<class T> using uset = unordered_set<T>;

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

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

template<class T, size_t N, class U>
void Fill(T (&a)[N], const U&v){
    fill((U*)a,(U*)(a+N),v);
}

template<class T>
istream& operator >> (istream&is, vector<T>&v){
  for(auto&e:v)is >> e;
  return is;
}

template<long long mod>
class modint{
private:
  long long num;
  long long extgcd(long long a, long long b, long long&x, long long&y)const {
    long long d = a;
    if(b != 0){d = extgcd(b, a%b, y, x);  y -= (a/b) * x;}
    else{x = 1; y = 0;}
    return d;
  }
  long long modinverse()const{
    long long x, y;
    extgcd(num, mod, x, y);
    return (mod + x%mod)%mod;
  }
public:
  modint():num(0){}
  modint(const long long x):num((x < 0?(x+mod):x)%mod ){}
  friend modint operator+(const modint&a, const modint&b)
  {    return modint(a.num + b.num);  }
  friend modint operator-(const modint&a, const modint&b)
  {    return modint(a.num - b.num);  }
  friend modint operator*(const modint&a, const modint&b)
  {    return modint(a.num * b.num);  }
  friend modint operator/(const modint&a, const modint&b)
  {    return modint(a*b.modinverse());  }
  friend ostream& operator<<(ostream&os, const modint&a){
    os << a.num;
    return os;
  }
};
const ll mod = (1e+9)+7;
vector<modint<mod>> kai(3000010,1);

int main(){
  for(int i = 2; i < 3000001; ++i){
    kai[i] = kai[i-1] * i;
  }
  int x, y; cin >> x >> y;
  modint<mod> ans = 0;
  for(int i = 0; i <= x; ++i){
    ll a = i;
    ll b = x - 2*a;
    if(b < 0)continue;
    if(2*a + b == x && a + 2*b == y){
      ans = kai[a+b]/(kai[a]*kai[b]) + ans;
    }
  }
  cout << ans << endl;
  return 0;
}


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll, ll> P;

#define EACH(i,a) for (auto& i : a)
#define FOR(i,a,b) for (ll i=(a);i<(b);i++)
#define RFOR(i,a,b) for (ll i=(b)-1;i>=(a);i--)
#define REP(i,n) for (ll i=0;i<(n);i++)
#define RREP(i,n) for (ll i=(n)-1;i>=0;i--)
#define debug(x) cout<<#x<<": "<<x<<endl
#define pb push_back
#define ALL(a) (a).begin(),(a).end()

const ll linf = 1e18;
const int inf = 1e9;
const double eps = 1e-12;
const double pi = acos(-1);

template<typename T>
istream& operator>>(istream& is, vector<T>& vec) {
	EACH(x,vec) is >> x;
	return is;
}
/*
template<class... T>
ostream& operator<<(ostream& os, tuple<T...>& t) {
	for (size_t i = 0; i < tuple_size< tuple<T...> >::value; ++i) {
		if (i) os << " ";
		os << get<0>(t);
	}
	return os;
}
*/
template<typename T>
ostream& operator<<(ostream& os, vector<T>& vec) {
	REP(i,vec.size()) {
		if (i) os << " ";
		os << vec[i];
	}
	return os;
}
template<typename T>
ostream& operator<<(ostream& os, vector< vector<T> >& vec) {
	REP(i,vec.size()) {
		if (i) os << endl;
		os << vec[i];
	}
	return os;
}

int main() {
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);
	int W, H; cin >> W >> H;
	int N; cin >> N;
	vector<int> x(N), y(N);
	REP(i, N) {
		cin >> x[i] >> y[i];
	}
	int xl = 0, xr = W;

	vector<int> X = x, Y = y;
	sort( ALL(X) );
	sort( ALL(Y) );
	int idx = (N-1)/2;
	ll ans = linf;
	int ax = inf, ay = inf;
	vector<int> kx, ky;
	for (int d = -3; d <= 3; ++d) {
		if (idx+d < 0 || idx+d >= N) continue;
		kx.pb(X[idx+d]);
		ky.pb(Y[idx+d]);
	}
	REP(u, kx.size()) REP(w, ky.size()) {
		int sx = kx[u], sy = ky[w];
		vector<ll> a;
		REP(i, N) {
			a.pb( abs(x[i]-sx) + abs(y[i]-sy) );
		}
		sort( ALL(a) );
		ll sum = a[N-1];
		REP(i, N-1) {
			sum += a[i]*2;
		}
		if (sum < ans || (sum == ans && P(sx, sy) < P(ax, ay))) {
			ans = sum;
			tie(ax, ay) = P(sx, sy);
		}
	}
	cout << ans << endl;
	cout << ax << " " << ay << endl;
}

Measured memory_bytes: 6320
import sys

X,N = (int(a) for a in input().split())
p = list(map(int,input().split()))

if N == 0 :
    print(X)
    sys.exit()

for i in range(N+1) :
    if X not in p :
        print(int(X))
        sys.exit()
    else :
        X = X + (i+1)* ( (-1)**((i+1) ))


Measured memory_bytes: 9192
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int x = sc.nextInt();
    int a = sc.nextInt();
    int ans = 10;
    if(x<a){
      ans=0;
    }
    System.out.println(ans);
  
  }
}

Measured memory_bytes: 23124
from __future__ import print_function
# import numpy as np
# import numpypy as np
import sys
input = sys.stdin.readline

def eprint(*args, **kwargs):
    print(*args, file=sys.stderr, **kwargs)
    return

import math
import string
import fractions
from fractions import Fraction
from fractions import gcd

def lcm(n,m):
    return int(n*m/gcd(n,m))

import re
import array
import copy
import functools
import operator

import collections
import itertools
import bisect
import heapq


from heapq import heappush
from heapq import heappop
from heapq import heappushpop
from heapq import heapify
from heapq import heapreplace

from queue import PriorityQueue as pq

def reduce(p, q):
    common = fractions.gcd(p, q)
    return (p//common , q//common )
# from itertools import accumulate
# from collections import deque

import random


def main():
    n = int(input().strip())
    nn=int(n//1.08)
    nnn=nn+1
    if int(nn*1.08) == n:
        print(nn)
    elif int(nnn*1.08) == n :
        print(nnn)
    else:
        print(":(")
    return

if __name__ == '__main__':
    main()


Measured memory_bytes: 65388
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner cin = new Scanner(System.in);
		int n, q, time_cost = 0;
		Task temp = new Task();
		Queue costQueue = new Queue(), endQueue = new Queue();
		n = cin.nextInt();
		q = cin.nextInt();
		while (cin.hasNext()) {
			temp.name = cin.next();
			temp.costTime = cin.nextInt();
			costQueue.insert(temp);
		}
		while (!costQueue.empty()) {
			temp = costQueue.remove();
			if (temp.costTime <= q) {
				time_cost += temp.costTime;
				temp.endTime = time_cost;
				endQueue.insert(temp);
				continue;
			}
			time_cost += q;
			temp.costTime -= q;
			costQueue.insert(temp);
		}
		while (!endQueue.empty()) {
			temp = endQueue.remove();
			System.out.println(temp.name + " " + temp.endTime);
		}
	}
}

class Task {
	String name;
	int costTime;
	int endTime;
}

class Queue {
	int MAX = 100002;
	Task[] entry = new Task[MAX];
	int front;
	int rear;
	int count;
	public Queue() {
		for (int i = 0; i < MAX; i++) {
			entry[i] = new Task();
		}
		front = 0;
		rear = -1;
		count = 0;
	}
	public void insert(Task t) {
		rear = (rear + 1) % MAX;
		count++;
		entry[rear].name = t.name;
		entry[rear].costTime = t.costTime;
		entry[rear].endTime = t.endTime;
	}
	public Task remove() {
		Task temp = entry[front];
		front = (front + 1) % MAX;
		count--;
		return temp;
	}
	public boolean empty() {
		return (count == 0);
	}
}


Measured memory_bytes: 84412
function main(input) {
  const lines = input.split("\n");
  const values = lines[0].split(' ').map(Number);

  let i = 1;
  while (true) {
    const target = i == 3 ? 0 : i+1;
    const hp = values[target] - values[i];
    if (hp <= 0) break;
    values[target] = hp;
    i = (i + 2) % 4;
  }
  const res = i == 1 ? 'Yes' : 'No';

  console.log(res);
}

main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 29624
;; -*- coding: utf-8 -*-
(eval-when (:compile-toplevel :load-toplevel :execute)
  (defparameter OPT
    #+swank '(optimize (speed 3) (safety 2))
    #-swank '(optimize (speed 3) (safety 0) (debug 0)))
  #+swank (ql:quickload '(:cl-debug-print :fiveam))
  #-swank (set-dispatch-macro-character #\# #\> (lambda (s c p) (declare (ignore c p)) (read s nil (values) t))))
#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)
#-swank (disable-debugger) ; for CS Academy

;; BEGIN_INSERTED_CONTENTS
(defmacro dbg (&rest forms)
  #+swank
  (if (= (length forms) 1)
      `(format *error-output* "~A => ~A~%" ',(car forms) ,(car forms))
      `(format *error-output* "~A => ~A~%" ',forms `(,,@forms)))
  #-swank (declare (ignore forms)))

(defmacro define-int-types (&rest bits)
  `(progn
     ,@(mapcar (lambda (b) `(deftype ,(intern (format nil "UINT~A" b)) () '(unsigned-byte ,b))) bits)
     ,@(mapcar (lambda (b) `(deftype ,(intern (format nil "INT~A" b)) () '(signed-byte ,b))) bits)))
(define-int-types 2 4 7 8 15 16 31 32 62 63 64)

(declaim (inline println))
(defun println (obj &optional (stream *standard-output*))
  (let ((*read-default-float-format* 'double-float))
    (prog1 (princ obj stream) (terpri stream))))

(defconstant +mod+ 1000000007)

;; Body

(defun main ()
  (declare #.OPT)
  (let* ((s (read-line))
         (prevs (make-array 26 :element-type 'int32 :initial-element #x-80000000)))
    (declare (simple-string s))
    (dotimes (i (length s))
      (let ((c (- (char-code (aref s i)) 97)))
        (if (>= (- i (aref prevs c)) 3)
            (setf (aref prevs c) i)
            (progn
              (format t "~D ~D~%" (+ 1 (aref prevs c)) (+ 1 i))
              (return-from main)))))
    (write-line "-1 -1")))

#-swank (main)


Measured memory_bytes: 13156
N = gets.to_i

a = gets.to_i

m1 = a
m2 = 0
mi= 0

1.upto(N - 1) do |i|
  a = gets.to_i
  if m1 < a
    mi = i
    m2 = m1
    m1 = a
  elsif m2 < a
    m2 = a
  end 
end

0.upto(N - 1) do |i|
  puts i == mi ? m2 : m1
end


Measured memory_bytes: 3452
#include <bits/stdc++.h>
#define rep(var,cnt) for(int (var)=0; (var)<(int)(cnt); ++(var))
#define Rep(var,init,cnt) for(int (var)=(init); (var)<(int)(cnt); ++(var))
#define ran(var,vec) for(auto &(var):(vec))
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define SORT(v) sort(all(v))
#define RSORT(v) sort(rall(v))
#define SUM(v) accumulate(all(v),0)
#define tget(tp,idx) get<idx>(tp)
#define TF(flag) ((flag)?1:0)
#define YN(flag) cout<<(flag?"YES":"NO")<<endl;
#define Yn(flag) cout<<(flag?"Yes":"No")<<endl;
#define yn(flag) cout<<(flag?"yes":"no")<<endl;
using namespace std;

using ll = long long;
using ull = unsigned long long;
using pi = pair<int,int>;
using pl = pair<ll,ll>;
using ti = tuple<int,int,int>;
using tl = tuple<ll,ll,ll>;

template<typename T>
using vec = vector<T>;
template<typename T>
using mat = vector<vec<T>>;
template<typename T>
using cub = vector<mat<T>>;
template<typename T>
using val = valarray<T>;

template<typename T>
using pq = priority_queue<T>;
template<typename T>
using rpq = priority_queue<T,vec<T>,greater<T>>;

template<typename T1,typename T2>
ostream &operator<<(ostream &os, const pair<T1,T2> &p){
  os<<"P("<<p.first<<", "<<p.second<<") ";
  return os;
}

template<typename T1,typename T2>
istream &operator>>(istream &is, pair<T1,T2> &p){
  is>>p.first>>p.second;
  return is;
}

template<typename T>
ostream &operator<<(ostream &os, const vector<T> &v){
  cout<<"V{";
  for(int i=0; i<(int)v.size(); ++i){
    os<<v[i]<<(i+1!=v.size()?" ":"");
  }
  cout<<"}";
  return os;
}

template<typename T>
istream &operator>>(istream &is, vector<T> &v){
  for(T &in:v) is>>in;
  return is;
}

template<typename T>
ostream &operator<<(ostream &os, const valarray<T> &v){
  cout<<"V{";
  for(int i=0; i<(int)v.size(); ++i){
    os<<v[i]<<(i+1!=v.size()?" ":"");
  }
  cout<<"}";
  return os;
}

template<typename T>
istream &operator>>(istream &is, valarray<T> &v){
  for(T &in:v) is>>in;
  return is;
}

// Usual Template End ===================

// Template End =========================

int main(void){
  vec<int> v(3); cin>>v; RSORT(v);
  cout<<v[0]*10+v[1]+v[2]<<endl;
}












Measured memory_bytes: 256
#include <math.h>
#include <assert.h>

#include <vector>
#include <numeric>
#include <iostream>
#include <algorithm>
#include <functional>

template <typename T>
void in(T& x) {
    std::cin >> x;
}

template <typename T>
void out(const T H) {
    std::cout << H;
}

template <typename T1, typename... T2>
void out(const T1 H, const T2... T) {
    std::cout << H << " "; out(T...);
}

template <typename T1, typename T2>
std::ostream& operator<<(std::ostream& os, const std::pair<T1, T2>& v) {
    return os << "(" << v.first << " " << v.second << ")";
}

template <typename T>
std::ostream& operator<<(std::ostream& os, const std::vector<T>& v) {
    os << "[ "; for (auto &i: v) os << i << " "; return os << "]";
}

template <typename T>
void eout(const char *s, const T H) {
    std::cerr << s << "=" << H << "\n";
}

template <typename T1, typename... T2>
void eout(const char *s, const T1 H, const T2... T) {
    while (*s != ',') std::cerr << *s++;
    std::cerr << "=" << H << " | "; eout(++s, T...);
}

#define nl                std::cout << "\n"
#define err(args...)      eout(#args, args)

#define inn(x)            int x; in(x)
#define rep(i, n)         for (int i =  0 ; i < (n); ++i)
#define per(i, n)         for (int i = (n) - 1; i > -1; --i)
#define repr(i, l, r)     for (int i = (l); i < (r); ++i)

#define sz(v)             ((int) v.size())
#define all(v)            (v).begin(), (v).end()
#define lla(v)            (v).rbegin(), (v).rend()

#define no                std::cout << "NO\n"
#define yes               std::cout << "YES\n"

const int INF           = 2147483647;
const long long int LNF = 9223372036854775807LL;

using ll  = long long int;
using vi  = std::vector<int>;
using vb  = std::vector<bool>;
using ii  = std::pair<int, int>;
using iii = std::pair< ii, int>;
using vii = std::vector<ii>;

const int N  = 505050;
const int MD = 1000*1000*1000 + 7;

int solve();
int main() {
    std::ios_base::sync_with_stdio(0); std::cin.tie(0);
    //std::cout.tie(0);

    //inn(t); repr(tc, 1, t + 1)
    solve();

    return 0;
}

int solve() {
    inn(n);
    vi a(n + 1); rep(i, n + 1) in(a[i]);
    vi b(n); rep(i, n) in(b[i]);

    ll ans = 0;
    rep(i, n) {
        int x = std::min(b[i], a[i]);
        b[i] -= x;
        ans += x;
        int y = std::min(b[i], a[i + 1]);
        a[i + 1] -= y;
        ans += y;
    }

    out(ans);
    return 0;
}


Measured memory_bytes: 1024
<?php
fscanf(STDIN, "%d", $N);
$ab=array();
$aaa=array();
$bbb=array();
for($i=0;$i<$N;$i++){
 fscanf(STDIN, "%d %d", $a,$b);
 $aaa[]=$a;
 $bbb[] = $b;
  
}
asort($bbb);
$sum=0;
foreach($bbb as $aa=>$bb){
  $sum+=$aaa[$aa];
  if($sum>$bb){
    echo  "No"."\n";
    exit;
  }
}


  echo  "Yes"."\n";
?>


Measured memory_bytes: 31212
import java.util.*;

class Main{
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		while(scan.hasNext()){
			int i, ans = 0;
			String str = scan.next();
			for(i = 0;i < str.length();i++){
				int f = translate(str.charAt(i));
				if(i == str.length() - 1){
					ans += f;
					break;
				}
				int s = translate(str.charAt(i + 1));
				if(f < s){
					ans += s - f;
					i++;
				}else{
					ans += f;
				}
			}
			System.out.println("" + ans);
		}
	}
	static int translate(char c){
		final String rl = "IVXLCDM";
		final int[] val = {1,5,10,50,100,500,1000};
		return val[rl.indexOf(c)];
	}
}

Measured memory_bytes: 17164
input_conditions = input().split()
times = int(input_conditions[0])
amount = int(input_conditions[1])
donuts_list = []
default_ryou = 0

for i in range(times):
    donut = int(input())
    donuts_list.append(donut)
    default_ryou += donut

donuts_list.sort()
amount -= default_ryou
extra = amount // donuts_list[0]
print(extra + times)


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

// #define int long long
#define rep(i, n) for (long long i = (long long)(0); i < (long long)(n); ++i)
#define reps(i, n) for (long long i = (long long)(1); i <= (long long)(n); ++i)
#define rrep(i, n) for (long long i = ((long long)(n)-1); i >= 0; i--)
#define rreps(i, n) for (long long i = ((long long)(n)); i > 0; i--)
#define irep(i, m, n) for (long long i = (long long)(m); i < (long long)(n); ++i)
#define ireps(i, m, n) for (long long i = (long long)(m); i <= (long long)(n); ++i)
#define SORT(v, n) sort(v, v + n);
#define REVERSE(v, n) reverse(v, v+n);
#define vsort(v) sort(v.begin(), v.end());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) long long(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vs = vector<string>;
using vpll = vector<pair<ll, ll>>;
using vtp = vector<tuple<ll,ll,ll>>;
using vb = vector<bool>;

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

const ll INF = 1e9;
const ll MOD = 1e9+7;
const ll LINF = 1e18;

ll dp[105][2][5]; // i文字目までで、n以下であるかの状態がjで、0でない数字がk個あるような物の個数

signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  string n; ll K; cin>>n>>K;
  ll N=n.size();
  
  dp[0][0][0]=1;
  rep(i,N) rep(j,2) rep(k,K+1){
    ll num=n[i]-'0';
    rep(nxt,10){
      if(nxt>num && j==0) continue;
      // if(i==0&&nxt==0) continue; <= 先頭桁が0は一見このように除外したくなるが誤り
      // nxt=0がN回続いて、dp[N][1][0]に格納されるのは1であり、これは0000...0つまり0という数字に対応している
      // 同様に例えば、dp[N][0 or 1][2]には、0000..0230つまり230に対応する場合も管理されているはずである
      // よって先頭桁0というのは、0以外の値が出るまで先頭に何もない、を意味するだけでdpがカウントする数字は辻褄が合う
      
      ll nj=j;
      if(nxt<num) nj=1;
      ll nk=k;
      if(nxt!=0) nk++;
      dp[i+1][nj][nk]+=dp[i][j][k];
    }
  }
  
  ll ans=dp[N][0][K]+dp[N][1][K];
  cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vll = vector<long long>;
using vp = vector<pair<int, int>>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;
using vvll = vector<vector<long long>>;
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 (b<a) {a=b; return 1;} return 0;}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int H, W, h, w;
    cin >> H >> W >> h >> w;
    cout << (H-h) * (W-w) << endl;
}

Measured memory_bytes: 256
#include <iostream> 
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mk make_pair
#define MAX 1000001
ll prime[MAX];
#define mod 1000000007

ll rec(vector<vector<ll> >& dp,vector<ll>& arr,int n,int i,int k,int w)
{
  ll ans=0;
  if(i>=n)
    return 0;

  if(dp[i][k]!=-1)
    return dp[i][k];


  if(k!=0)
  ans=max(rec(dp,arr,n,i+1,w,w),arr[i]+rec(dp,arr,n,i+1,k-1,w));
  else
  ans=max(rec(dp,arr,n,i+1,k,w),rec(dp,arr,n,i+1,w,w));

  return dp[i][k]=ans;

}

ll t[400008];
void build(vector<ll>& a, int v, int tl, int tr) {
    if (tl == tr) {
        t[v] = a[tl];
    } else {
        int tm = (tl + tr) / 2;
        build(a, v*2, tl, tm);
        build(a, v*2+1, tm+1, tr);
        t[v] = max(t[v*2] ,t[v*2+1]);
    }
}

ll maxi(int v, int tl, int tr, int l, int r) {
    if (l > r) 
        return 0;
    if (l == tl && r == tr) {
        return t[v];
    }
    int tm = (tl + tr) / 2;
    return max(maxi(v*2, tl, tm, l, min(r, tm)) ,maxi(v*2+1, tm+1, tr, max(l, tm+1), r));
}



void update(int v, int tl, int tr, int pos, ll new_val) {
    if (tl == tr) {
        t[v] = new_val;
    } else {
        int tm = (tl + tr) / 2;
        if (pos <= tm)
            update(v*2, tl, tm, pos, new_val);
        else
            update(v*2+1, tm+1, tr, pos, new_val);
        t[v] = max(t[v*2] ,t[v*2+1]);
    }
}


void sieve(ll divi[],ll n)
{
 
}

int main() { 


ll n;
cin>>n;
ll divi[n+1]={0};


 for(int i=1;i<=n;i++)
  {
    divi[i]++;
    for(int j=i*2;j<=n;j+=i)
    {
      divi[j]++;
    }

  }

ll ans=0;
for(int i=1;i<=n;i++)
  ans+=i*divi[i];

cout<<ans;
return 0;
}


Measured memory_bytes: 81692
using System;
using System.Linq;

namespace AFiveAntennas
{
    class Program
    {
        private string Read()
        {
            return Console.ReadLine();
        }
        private int[] ReadIntArray()
        {
            return Read().Split().Select(int.Parse).ToArray();
        }
        
        private void C()
        {
            //var K = ReadIntArray();
            //var n = K[5];
            var array = new int[6];
            
            for (int i = 0; i < array.Length; i++)
            {
                array[i] = int.Parse(Read());
            }
            var ac = 0;
            string ans = "";
            var a = array[0];
            var e = array[4];
            var k = array[5];
            //ans = K[1] - K[0] <= n && K[2] - K[0] <= n && K[3] - K[0] <= n && K[4] - K[0] <= n && K[2] - K[1] <= n && K[3] - K[1] <= n && K[4] - K[1] <= n && K[3] - K[2] <= n && K[4] - K[2] <= n && K[4] - K[3] <= n ? "Yay!" : ":(";
            ans = array[4] - array[0] <= array[5] ? "Yay!" : ":(";
            Console.WriteLine(ans);

        }

        static void Main(string[] args)
        {
            new Program().C();
        }
    }
}


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

//{ START
using namespace std;
#define int int64_t
#define rep(i, a, n) for (int i = (a); i < (n); ++i)
#define reps(i, a, n) for (int i = (a); i > (n); --i)
#define arep(i, x) for (auto &&i : (x))
#define irep(i, x) for (auto i = (x).begin(); i != (x).end(); ++i)
#define rirep(i, x) for (auto i = (x).rbegin(); i != (x).rend(); ++i)
//降順はgreater<T>()
#define all(x) (x).begin(), (x).end()
#define rv(s) reverse((s).begin(), (s).end())
// gcd lcmはそのままok
#define gcd(a, b) __gcd(a, b)
#define bits(n) (1LL << (n))
#define pcnt(x) __builtin_popcountll(x)
//配列内等要素削除
#define unique(x) (x).erase(unique((x).begin(), (x).end()), (x).end())
#define Fixed(n) fixed << setprecision(n)
//総和
#define sowa(n) ((n) * ((n) + 1)) / 2
#define pb(x, a) (x).push_back(a)
#define fb(x, a) (x).push_front(a)
#define eb(x, a) (x).emplace_back(a)
#define cauto const auto &
using P = pair<int, int>;
using Graph = vector<vector<P>>;
template <class T>  //昇順
using min_heap = priority_queue<T, vector<T>, greater<T>>;
template <class T>  //降順
using max_heap = priority_queue<T>;
template <class A, class B>
using umap = unordered_map<A, B>;
template <class A>
using uset = unordered_set<A>;
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {  //多次元初期化
  std::fill((T *)array, (T *)(array + N), val);
}
template <class A, class B>
bool chmax(A &a, const B &b) {  //最大値更新 返り値はbool
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class A, class B>
bool chmin(A &a, const B &b) {  //最小値更新 返り値はbool
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
constexpr int INF = 0x3f3f3f3f;
constexpr int LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int mod1 = 1e9 + 7;
constexpr int mod2 = 998244353;
//} END

signed main() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);

  int n;
  cin >> n;

  int ans = 0;

  rep(i, 1, n + 1) {
    int itr = sowa(n / i);
    ans += itr * i;
  }
  cout << ans << '\n';
  return 0;
}

Measured memory_bytes: 3572
from sys import stdin
input=stdin.readline().rstrip()
output_list=[]
for i in range(len(input)):
  if input[i]!="B":
    output_list.append(input[i])
  else:
    if len(output_list)!=0:
      output_list.pop(-1)
      
#print(output_list)
output="".join(output_list)
print(output)

Measured memory_bytes: 3060
#include <iostream>
using namespace std;
#include <string>
#include <vector>
#include <algorithm>
#include <map>
typedef long long ll;

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

	cin >> n;

	ll s=0, s2=0, d;
	for (int i=0; i<n; i++)
	{
		cin >> d;
		s+=d;
		s2+=(d*d);
	}
	
	cout << (s*s-s2)/2 << endl;
	return 0;
}



Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using static System.Console;
using System.Linq;

namespace ConsoleApp2
{
    class Program {
        static void Main(string[] Args) {
            long res = 0;
            var NM = new List<string>(ReadLine().Split(' ')).Select(long.Parse).ToList();

            res += Math.Min(NM[0], NM[1] / 2);

            NM[1] -= res * 2;

            res += NM[1] / 4;

            WriteLine(res);

            ReadLine();
        }
    }
}


Measured memory_bytes: 13396
import Control.Monad
import Data.Array.ST
import Data.Array.Unboxed
import Data.STRef

dex :: Int
dex = 1000000007

main :: IO ()
main = do
  [n,k] <- map read . words <$> getLine
  solve n k $ bio n k
  
solve :: Int -> Int -> UArray (Int,Int) Int -> IO ()
solve n0 k0 b1 = forM_ [1..k0] $ \i -> print $ ((b1!(n0-k0+1,i)) * (b1!(k0-1,i-1))) `mod` dex

bio :: Int -> Int -> UArray (Int,Int) Int
bio n0 k0 = runSTUArray $ do
  dptbl <- newArray ((0,0),(n0,k0)) 0
  forM_ [(n',k') | n' <- [0..n0], k' <- [0..k0], n'>=k'] $ \(n,k) ->
    if k == 0 || k == n
    then writeArray dptbl (n,k) 1
    -- else liftM2 (+) (readArray dptbl (n-1,k-1)) (readArray dptbl (n-1,k)) >>= writeArray dptbl (n,k)
    else liftM2 (\x y -> (x+y)`mod`dex) (readArray dptbl (n-1,k-1)) (readArray dptbl (n-1,k)) >>= writeArray dptbl (n,k)
  return dptbl


Measured memory_bytes: 32892
#include <iostream>
#include <string>
#include <vector>
#include <set>

using namespace std;

int main() {
	vector<int> xs, ys;
	int gx, gy;
	bool dir = true;
	string s;
	cin >> s >> gx >> gy;
	s += "T";   //'T'区切りなので最後にTをつけると扱いやすい
	for (int i = 0, l = 0; i < s.size(); i++) {
		if (s[i] == 'T') {
			if (dir)
				xs.push_back(l);
			else
				ys.push_back(l);
			l = 0;
			dir = !dir;
		}
		else l++;
	}
	set<int> xcan, ycan;   //xとyは独立に扱える
	xcan.insert(xs[0]);
	ycan.insert(0);
	for (int i = 1; i < xs.size(); i++) {
		set<int> tmp;
		for (auto itr : xcan) {
			tmp.insert(itr + xs[i]);
			tmp.insert(itr - xs[i]);
		}
		xcan = tmp;
	}
	for (int i = 0; i < ys.size(); i++) {
		set<int> tmp;
		for (auto itr : ycan) {
			tmp.insert(itr + ys[i]);
			tmp.insert(itr - ys[i]);
		}
		ycan = tmp;
	}
	if (xcan.count(gx) && ycan.count(gy))
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 768
#include<cstdio>
#include<iostream>
using namespace std;
int main()
{
  int n;
  scanf("%d", &n);
  int A[50];
  A[0] = A[1] = 1;
  for(int i=2; i<=n; i++)
  {
    A[i] = A[i-1] + A[i-2];
  }
  printf("%d\n", A[n]);//dynamic programing;


  return 0;
}



Measured memory_bytes: 3192
#include <bits/stdc++.h>
#include <iostream>
#include <cmath>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <numeric>

typedef unsigned long long int ull;
typedef long long int ll;

#define deb(x) cout << "Value - " << x << "\n"; 

using namespace std;

// Class Starts Here



// Class Ends Here

// Functions Starts Here

void prime()
{
    
}

// Functions Ends Here

int main()
{
    // *********************
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    // *********************
    
    // Driver Function Starts Here

    ll arr[4];
    cin >> arr[0] >> arr[1] >> arr[2] >> arr[3];
    vector<ll> vec;
    for (int i=0; i<2; i++)
    {
        for (int j=2; j<4; j++)
        vec.push_back(arr[i]*arr[j]);
    }
    cout << *max_element(vec.begin(), vec.end()) << "\n";

    // Driver Function Ends Here
    return 0;
}

Measured memory_bytes: 3648
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <memory>
#include <complex>
#include <numeric>
#include <cstdio>
#include <iomanip>

#define REP(i,m,n) for(int i=int(m);i<int(n);i++)
#define RREP(i,m,n) for(int i=int(n)-1;i>=int(m);--i)
#define EACH(i,c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())

#ifdef LOCAL
#define DEBUG(s) cout << (s) << endl
#define dump(x)  cerr << #x << " = " << (x) << endl
#define BR cout << endl;
#else
#define DEBUG(s) do{}while(0)
#define dump(x) do{}while(0)
#define BR 
#endif
using namespace std;

using UI = unsigned int;
using UL = unsigned long;
using LL = long long int;
using ULL = unsigned long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VS = vector<string>;
using PII = pair<int,int>;
using VP = vector<PII>;

//struct edge {int from, to, cost;};

constexpr double EPS = 1e-10;
//constexpr double PI  = acos(-1.0);
//constexpr int INF = INT_MAX;
constexpr int MOD = 1'000'000'007;

template<class T> inline T sqr(T x) {return x*x;}

void solve() {
    int n,k;
    cin >> n >> k;
    VI a(n);
    REP(i,0,n) cin >> a[i];
    vector<bool> dp(k+1, true);
    dp[0] = false;
    REP(i,1,k+1) {
        REP(j,0,n) {
            if (a[j] > i) break;
            dp[i] = (dp[i] & dp[i - a[j]]);
        }
        dp[i] = !dp[i];
    }
    if (dp[k]) cout << "First" << endl;
    else cout << "Second" << endl;
}

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1e9+7;
int main() {
    ll k;
    cin >> k;
    if(k%2==0||k%5==0){
        cout << -1 << endl;
        return 0;
    }
    ll l=9*k;
    if(l%7==0)l/=7;
    ll x=10;
    ll ans=0;
    for(ll i=0;i<k;i++){
        ans++;
        x%=l;
        if(x==1){
            break;
        }
        x*=10;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3600
def solve(H, W, a):
    mod = 10 ** 9 + 7

    dp = [[0] * W for _ in range(H)]
    dp[0][0] = 1

    for i in range(H):
        for j in range(W):
            if a[i][j] == '.':
                if i == 0 and j == 0:
                    continue
                if i == 0:
                    dp[i][j] = dp[i][j-1]
                    dp[i][j] %= mod
                else:
                    dp[i][j] = dp[i-1][j] + dp[i][j-1]
                    dp[i][j] %= mod

    return dp[H-1][W-1]


if __name__ == "__main__":
    H, W = map(int, input().split())
    a = [input() for _ in range(H)]

    print(solve(H, W, a))


Measured memory_bytes: 49276
#include <bits/stdc++.h>
using namespace std;
#define int long long

map<string ,int> mp;
signed main(){
	string str;
	int n, m;
	scanf("%lld", &n);
	for(int i = 0;i < n;i++){
		cin >> str;
		mp[str]++;
	}
	scanf("%lld", &m);
	for(int i = 0;i < m;i++){
		cin >> str;
		mp[str]--;
	}
	int ans = 0;
	for(auto it = mp.begin();it != mp.end();it++){
		ans = max(ans, it->second);
	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define LL              long long
#define ll              long long
#define SL(n)           scanf("%lld",&n)
#define LF              double
#define SF(n)           scanf("%lf",&n)

#define pb              push_back
#define ff              first
#define ss              second
#define mp              make_pair

#define ON(n,i)         (n|(1LL<<i))
#define OFF(n,i)        (n&(~(1LL<<i)))
#define CHK(n,i)        (n&(1LL<<i))

#define SET(arr)        memset( arr , -1 , sizeof arr)
#define RESET(arr)      memset( arr,0,sizeof arr)

#define srt(v)          sort(v.begin(),v.end())
#define uniq(v)			v.resize(distance(v.begin(),unique(v.begin(),v.end())))
#define found( s,d )    (s.find(d) != s.end())

#define FOR(i,s,e)      for( LL i = s ; i<=e ; i++ )

#define FILEIN          freopen("in.txt","r",stdin)
#define FILEOUT         freopen("out.txt","w",stdout)

/// DEBUG
#define deb             printf("OKA\n")
/// DEBUG ENDSk

using namespace std;

LL a[1001];

int main(){
       
       LL N,M;
       SL(N); SL(M);
       LL sum = 0;
       FOR(i,1,N){
           SL(a[i]);
           sum+=a[i];
       }
       
       LL cnt = 0;
       FOR(i,1,N){
           if( a[i]*M*4>=sum ) cnt++;
       }
       if(cnt>=M) cout<<"Yes"<<endl;
       else cout<<"No"<<endl;
   
return 0;}

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

#define ll long long
#define pb push_back
#define an "\n"

using namespace std;


int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	int n, k, a[10000], sum=0;
	cin >> n >> k;
	for(int i=0;i<n;i++) {
		cin >> a[i];
	}
	sort(a, a+n);
	for(int i=0;i<k;i++) {
		sum+=a[i];
	}
	cout << sum;
}



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

int main() {
  int H, W;
  cin >> H >> W;
  
  for(int i = 0; i <W+2; i++){
    cout << "#" ;}
  cout << endl;
  
  vector<string> A(H);
  for(int i = 0; i < H; i++){
    cin >> A.at(i);
    cout << "#" << A.at(i) << "#" << endl;}
  
  for(int i = 0; i <W+2; i++){
    cout << "#" ;}
  cout << endl;
}


Measured memory_bytes: 256
n=int(input())
num=list(map(int,input().split()))
for i in range(n):
  num[i]-=i+1
num.sort()
if n%2==1:
  ans=num[n//2]
else:
  x=(num[n//2-1]+num[n//2])/2
  if num[n//2]-x>x-num[n//2-1]:
    ans=num[x//2-1]
  else:
    ans=num[n//2]
print(sum([abs(num[i]-ans) for i in range(n)]))

Measured memory_bytes: 25748
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		if (s.replaceAll("eraser", "").replaceAll("erase", "").replaceAll("dreamer", "").replaceAll("dream", "")
				.equals("")) {
			System.out.println("YES");
		} else {
			System.out.println("NO");
		}
		sc.close();

	}
}

Measured memory_bytes: 30712