akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Linq;
using System.Collections.Generic;

namespace AtCoder
{
	class Program
	{
		public static void Main()
		{
			var intArray = IO.ReadIntArray();
			var lakeDistance  =intArray[0];
			var buildNum = intArray[1];

			var positions = IO.ReadIntArray().ToList();
			positions.Insert(0 , positions[buildNum - 1] - lakeDistance);
			var maxDistance = 0;
			for(var iIndex = 1 ; iIndex <= buildNum ; ++ iIndex)
			{
				maxDistance = Math.Max(maxDistance , positions[iIndex] - positions[iIndex - 1]);
			}			
			IO.Write(lakeDistance - maxDistance);
		}
	}

	public static class IO
	{
		public static string   Read()							   { return Console.ReadLine(); }
		public static string[] ReadArray(char iSplitter = ' ')	   { return Read().Split(iSplitter); }
		public static int	   ReadInt()						   { return int.Parse(Read()); }
		public static int[]	   ReadIntArray(char iSplitter = ' ')  { return ReadArray().Select(iText => int.Parse(iText)).ToArray(); }
		public static long	   ReadLong()						   { return int.Parse(Read()); }
		public static long[]   ReadLongArray(char iSplitter = ' ') { return ReadArray().Select(iText => long.Parse(iText)).ToArray(); }
		public static char[]   ReadCharArray()					   { return Read().ToCharArray(); }

		public static void Write(string iValue)			  { Console.WriteLine(iValue); }
		public static void Write(int iValue)			  { Console.WriteLine(iValue); }
		public static void Write(IEnumerable<int> iValue) { Console.WriteLine(string.Join(" " , iValue)); }
		public static void Write(long iValue)			  { Console.WriteLine(iValue); }
		public static void Write(decimal iValue)		  { Console.WriteLine(iValue); }
		public static void Write(bool iValue)			  { Console.WriteLine(iValue ? "Yes" : "No"); }
	}

	public static class Util
	{
		public static long Gcd(long i0 , long i1) { return (i0 > i1) ? _Gcd(i0 , i1) : _Gcd(i1 , i0); }
		public static long Lcm(long i0 , long i1) { return (i0 * i1) / Gcd(i0 , i1); }
		public static long ModPow(long iBaseNumber , long iPow , long iModNumber)
		{
			var num = 1L;
			while(iPow != 0)
			{
				if((iPow & 0x1) != 0)
				{
					num = (num * iBaseNumber) % iModNumber;
				}
				iBaseNumber = (iBaseNumber * iBaseNumber) % iModNumber;
				iPow >>= 1;
			}
			return num;
		}

		private static long _Gcd(long i0 , long i1)	{ return (i1 == 0) ? i0 : _Gcd(i1 , i0 % i1); }
	}
}


Measured memory_bytes: 34780
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
 
/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
    sizeは(int)とキャストしよう
    ごちゃごちゃ場合分けを考える前に全探索は考えましたか？
*/

int main(){
    int a, b, h; cin >> a >> b >> h;
    cout << (a+b)*h/2 << endl;
}

Measured memory_bytes: 256
import math
#import numpy as np
import queue
from collections import deque,defaultdict
import heapq as hpq
from sys import stdin,setrecursionlimit
#from scipy.sparse.csgraph import dijkstra
#from scipy.sparse import csr_matrix
ipt = stdin.readline
setrecursionlimit(10**7)

def main():
    d = int(ipt())
    c = [int(i) for i in ipt().split()]
    s = [[int(i) for i in ipt().split()] for _ in range(d)]
    ld = [-1]*26
    edval = [0]*26

    for i in range(d):
        edval = s[i]*1
        for j in range(26):
            dl = i-ld[j]
            edval[j] += c[j]*dl*(dl+1)/200
        v = edval.index(max(edval))
        ld[v] = i
        print(v+1)

    return

if __name__ == '__main__':
    main()


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

int main()
{
	int N, d[102],ans = 1;

	cin >> N;

	for (int i = 0; i < N; i++)
		cin >> d[i];

	sort(d, d + N);
	reverse(d, d + N);

	for (int i = 1,j = 0; i < N; i++) {
		if (d[j] > d[i]) {
			ans++;
			j = i;
		}
	}

	cout << ans;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstring>
#include <algorithm>
#include <queue>
#include <vector>
#include <cmath>
using namespace std;

#define LL long long

const int MAXN = 500000 + 5;


int main()
{
    int D, T, S;
    cin >> D >> T >> S;
    if (T * S >= D){
        cout << "Yes";
    }
    else{
        cout << "No";
    }
    system("pause");
    return 0;
}

Measured memory_bytes: 3696
a = [list(map(int,input().split()))	 for i in range(3)]
n = int(input())
b = [int(input()) for i in range(n)]
for i in range(n):
    for j in range(3):
        for k in range(3):
            if b[i] == a[j][k]:
                a[j][k] = 0

for i in range(3):
    yoko=0
    for j in range(3):
        if a[i][j]==0:
            yoko+=1
            if yoko == 3:
                print("Yes")
                exit()
if (a[0][0] == 0 and a[1][1] == 0 and a[2][2]==0) or (a[0][2] == 0 and a[1][1] == 0 and a[2][0]==0):
    print("Yes")
    exit()
for i in range(3):
    tate=0
    for j in range(3):
        if a[j][i]==0:
            tate+=1
            if tate == 3:
                print("Yes")
                exit()
print("No")

Measured memory_bytes: 3064
from fractions import gcd
N, M = map(int, input().split())
S = input()
T = input()
GCD = gcd(N, M)
LCM = N*M // gcd(N, M)
# print(GCD, LCM)
ok = True
for i in range(GCD):
    # print(i*N//GCD, i*M//GCD)
    if S[i*(N//GCD)] != T[i*(M//GCD)]:
        ok = False

if ok:
    print(LCM)
else:
    print(-1)


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

// #include <ext/pb_ds/assoc_container.hpp> // Common file
// #include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
// using namespace __gnu_pbds;
using namespace std;
#define int long long
//for set
// typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;   
// for multiset
// typedef tree<
// int,
// null_type,
// less<int>,
// rb_tree_tag,
// tree_order_statistics_node_update> ordered_multiset;

#define ff first
#define ss second
#define endl "\n"
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x.size())
#define PI 3.1415926535897932384626433832795
int MOD=1e9+7;
// int MOD=998244353;
int powmod(int a,int l, int md){int res=1;while(l){if(l&1)res=res*a%md;l/=2;a=a*a%md;}return res;}
int binpow(int a,int l){int res=1;while(l){if(l&1)res=res*a;l/=2;a=a*a;}return res;}
typedef long long ll; typedef vector<int> vi; typedef pair<int,int> ii; typedef vector<ii> vii;
#define pb push_back
int __set(int b, int i) {return b|(1<<i);} //set ith bit
int __unset(int b, int i) {return b&(~(1UL<<i));}
int __check(int b, int i) {return b&(1<<i);} //returns 0 if ith bit is 0
int mulmod(int a, int b, int md) {return ((a%md)*(b%md))%md;}
int addmod(int a, int b, int md) {return (a+b)%md;}
int submod(int a, int b, int md) {return (((a-b)%md)+md)%md;}
int divmod(int a, int b, int md) {return mulmod(a, powmod(b, md-2, md), md);} //if md is prime;
const ll inf = 0xFFFFFFFFFFFFFFFL; //very large number
priority_queue<int, vector<int>, greater<int> > pq; //for min priority_queue
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
clock_t time_p=clock();
void time()
{
    time_p=clock()-time_p;
    cerr<<"Time Taken : "<<(float)(time_p)/CLOCKS_PER_SEC<<"\n";
}


signed main(void)
{
	IOS; 
	int x,y,z,k;
	cin>>x>>y>>z>>k;
	vi a(x); vi b(y); vi c(z);
	for(int i = 0; i < x; i++)
		cin>>a[i];
	for(int i = 0; i < y; i++)
		cin>>b[i];
	for(int i = 0; i < z; i++)
		cin>>c[i];
	vi combine;
	for(int i = 0; i < x; i++) {
		for(int j = 0; j < y; j++) {
			combine.pb(a[i]+b[j]);
		}
	}
	sort(all(combine), greater<int>());
	vi nn;
	for(int i = 0; i < min(k,sz(combine)); i++)
		nn.pb(combine[i]);
	vi ans;
	for(int i = 0; i < sz(nn); i++) {
		for(int j = 0; j < z; j++)
			ans.pb(nn[i]+c[j]);
	}
	sort(all(ans), greater<int>());
	for(int i = 0; i < k; i++)
		cout<<ans[i]<<endl;
	// time();
	return 0;
}

Measured memory_bytes: 43528
#include <bits/stdc++.h>
#define pb push_back
#define ll long long
#define md 1000000007
using namespace std;

int main(){
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    long long n, i = 0, j= 0, k = 0, l = 0, m = 0, a = 0, b = 0, sum = 0, x = 0, y = 0, z = 0, c, p;
    cin >> n >> k;
    long long arr[n+1], dp[n+1];
    for(i = 1; i <= n; i++){
        cin >> arr[i];
    }
    dp[1] = 0;
    dp[2] = abs(arr[2]-arr[1]);
    for(i = 3; i <= n; i++){
        m = LLONG_MAX;
        for(j = max(i-k,(ll)1); j < i; j++){
           m = min(m,abs(arr[i]-arr[j])+dp[j]);
        }
        dp[i] = m;
    }
    cout << dp[n];

    return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<(n);i++)
#define rrep(i,n) for(ll i = 1; i <= (n); ++i)
#define drep(i,n) for(ll i = (n)-1; i >= 0; --i)
#define all(v) v.begin(),v.end()
#define len(x) (ll)(x).length()
#define maxs(x,y) x = max(x,y)
#define mins(x,y) x = min(x,y)
#define pb push_back
#define sz(x) (ll)(x).size()
#define v(T) vector<T>
#define vv(T) vector<vector<T>>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
ll gcd(ll a,ll b){if(a%b==0){return b;}else{return(gcd(b,a%b));}}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
const int INF=1e9;
const ll MX = 1e18;
const ll MOD=INF+7;
const int di[] = {-1,0,1,0};
const int dj[] = {0,-1,0,1};
const double PI=acos(-1);
const string tr="abcdefghijklmnopqrstuvwxyz";
#define dame { puts("-1"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
#define YN {puts("YES");}else{puts("NO");}
const ll MAX = 1000001;
long long fac[MAX], finv[MAX], inv[MAX];
void COMinit() {fac[0] = fac[1] = 1;finv[0] = finv[1] = 1;inv[1] = 1;for (ll i = 2; i < MAX; 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(ll n, ll k){if (n < k) return 0;if (n < 0 || k < 0) return 0;return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;}
ll llpow(ll n,ll i){ll cnt=n;  for(ll j=0;j<i-1;j++){n*=cnt;}return n;}

int main(){
  ll n;
  cin>>n;
  v(ll) a(n),b(n);
  ll suma=0;
  ll sumb=0;
  ll ans=0;
  rep(i,n) {
    cin>>a[i];
    suma+=a[i];
  }
  rep(i,n) {
    cin>>b[i];
    sumb+=b[i];
  }
  if(sumb>suma) dame;
  v(ll) yokei(n);
  ll tarinai=0;
  rep(i,n){
    if(a[i]>b[i]){
      yokei[i]+=a[i]-b[i];
    }
    if(b[i]>a[i]){
      tarinai+=b[i]-a[i];
      ans++;
    }
  }
  sort(all(yokei));
  reverse(all(yokei));
  for(ll i=0;tarinai>0;i++){
    tarinai-=yokei[i];
    ans++;
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 5576
/*
Mangal bhavan amangal haari
Drabahu su Dasharath achar Bihari
Raam Siya Raam Siya Raam jai jai Raam
Raam Siya Raam Siya Raam jai jai Raam
Ho hoi hai wohi jo Raam rachi raakha
Ko kari tarak badhave saakha
Raam Siya Raam Siya Raam jai jai Raam
Ho dheeraj dharam mitra aru naari
Aapad kaal parakhiye chaari
Ho jehike jehi par satya sanehu
So tehi milay na kachhu sandehu
Ho jaaki rahi bhawana jaisi
Prabhu murati dekhi tin taisi
Ho Raghukul reet sada chali aayi
Praan jaaye par vachan na jaayi
Raam Siya Raam Siya Raam jai jai Raam, Raam
Raam Siya Raam Siya Raam jai jai Raam
Ho hari anant hari katha ananta
Kahahi sunahi bahuvidhi sab santa
Raam Siya Raam Siya Raam jai jai Raam, Raam
Raam Siya Raam Siya Raam jai jai Raam
Raam Siya Raam Siya Raam jai jai Raam
*/


#include<bits/stdc++.h>
using namespace std;
#define ll long long 
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define all(v) v.begin(),v.end()
//auto->.
//map<int,int>::iterator i
vector<int> sieve(int n) 
{ 

    vector<bool> prime(n+1,true); 
       
    prime[0] = false; 
    prime[1] = false; 
    int m = sqrt(n); 
   vector<int> ans;

    for (int p=2; p<=m; p++) 
    { 
    
        if (prime[p]) 
        { 
         
            for (int i=p*2; i<=n; i += p) 
            prime[i] = false; 
        } 
    }  
    //vector<int> ans; 
    for (int i=0;i<n;i++) 
        if (prime[i]) 
            ans.push_back(i); 
    return ans; 
}

int gcd(int a,int b)
{
	if(b==0) return a;
	return gcd(b,a%b);
}
int mod = 1e9 + 7;
int power(int a , ll b)
{
	int res = 1;
	while(b)
	{
		if(b & 1)
			res = 1LL * res * a ;//% mod;
		a = 1LL * a * a ;//% mod;
		b >>= 1;
	}
	return res;
}
bool sortbysec(const pair<int,int> &a, 
              const pair<int,int> &b) 
{ 
    return (a.second < b.second); 
}
ll min(int a,ll b)
{
	if(a>b)
	return b;
	return a;
}
ll max(int a,ll b)
{
	if(a>b)
	return a;
	return b;
}
ll myXOR(ll x, ll y) 
{ 
   return (x | y) & (~x | ~y); 
}
int conti(int x)
{
	if(x<1)
	return 0;
	if(x%4==0)
	return x;
	if(x%4==1)
	return 1;
	if(x%4==2)
	return x+1;
	if(x%4==3)
	return 0;
}
 
bool ispfsq(long double x) 
{   
  // Find floating point value of  
  // square root of x. 
  long double sr = sqrt(x); 
  
  // If square root is        an integer 
  return ((sr - floor(sr)) == 0); 
}
#define PI 3.141592653589793


vector<int > adj[200005];
bool visited[2005][2005];
int ch[100005],dep[100005];
void solve()
{
ll n,k;
cin>>n;
ll ans=0;
for(ll i=1;i<=n;i++)
{
	ans+=i*(n-i+1);
}
for(ll i=1;i<n;i++)
{
	ll u,v;
	cin>>u>>v;
	if(u>v)
	swap(u,v);
	ans-=u*(n-v+1);
}
cout<<ans;
}

int main()
{
	
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
int mul=0;
if(mul==1)
{
 int t;
    cin>>t;
   while(t--)
    {
		solve();
	cout<<"\n";
    }
    
}
else
{
//	fun();
	solve();
}
}

Measured memory_bytes: 8340
#include <bits/stdc++.h>
using namespace std;
map<string,int> a;

int main() {
  int n,mx=0;
  cin >> n;
  string x;
  for(int i=0;i<n;i++){
    cin >> x; a[x]++;mx = max(mx,a[x]);
  }
  for(auto p : a){
    if(p.second == mx) cout << p.first << endl;
  }
}


Measured memory_bytes: 25216
# -*- coding: utf-8 -*-
import sys
N, Y = map(int, input().split())
k = int(Y / 1000)
t = k - N
# 9x + 4y = t
for x in range(0, N + 1):
    for y in range(0, N + 1 - x):
        if 9 * x + 4 * y == t:
            z = N - (x + y)
            print(x, y, z)
            sys.exit()
print('-1 -1 -1')


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

typedef long long ll;

using namespace std;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	ll N, K;
	cin >> N >> K;
	vector<ll>H(N);
	ll sum = 0;
	for (int i = 0; i < N; i++){
		cin >> H[i];
		sum += H[i];
	}
	sort(H.begin(), H.end(), greater<ll>());
	for (int i = 0; i < K; i++){
		if (N == i) {
			break;
		}
		sum -= H[i];
	}

	cout << sum << endl;

	return 0;
}

Measured memory_bytes: 1792
s = list(input())
k = int(input())
n = len(s)
res = 0
i = 1
if s.count(s[0]) == n: # 全て同じ
    print(n*k//2)
    exit()

while i < n:
    if s[i-1] == s[i]:
        res += 1
        i +=1
    i+=1
res *= k

if s[0] != s[n-1]:
    print(res)
else:
    a=0
    b=0
    v=s[0]
    i=0
    while s[i] == v:
        a+=1
        i+=1
    while s[n-1] == v:
        b+=1
        n-=1
    res -= (((a//2)+(b//2))-((a+b)//2))*(k-1)
    print(res)

Measured memory_bytes: 9236
#include<iostream>
using namespace std;
int main(){
    char S[99];
    cin>>S;
    int len;
    len=strlen(S);
    char S2[99];
    int j=len-1;
    int count=0;
    for(int i=0;i<len;i++){
        S2[i]=S[j];
        j--;
    }
    for(int k=0;k<len;k++){
        if(S[k]==S2[k]){
            count++;
        }
    }
    if(count==len){
        len=len/2;
        j=len-1;
        count=0;
        for(int i=0;i<len;i++){
            S2[i]=S[j];
            j--;
        }
        for(int k=0;k<len;k++){
            if(S[k]==S2[k]){
                count++;
            }
         }
        if(count==len){
            cout<<"Yes"<<endl;
            return 0;
        }
        cout<<"No"<<endl;
        return 0;
    }
    cout<<"No"<<endl;
}

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

#define ll long long
#define vi vector<int>
#define vl vector<ll>
#define pii pair<int,int>
#define pll pair<ll,ll>
// pll pp; -> (pp.first,pp.second)
// vector<vl> pp(n,vl(2)); sort(pp.begin(),pp.end(),[](vl a,vl b){return a[0]<b[0];});

#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 CHMAX(a,b) a=max((a),(b))
#define CHMIN(a,b) a=min((a),(b))
/*}}}*/
int main() {
  ll n;
  cin >> n;
  vector<vl> node(n,vl(3));
  REP(i,n){
    node[i][0] = i;
    cin >> node[i][1];
    cin >> node[i][2];
  }
  vector<vl> edge(n,vl(0));
  sort(node.begin(),node.end(),[](vl a,vl b){return a[1]<b[1];});
  REP(i,n-1){
    edge[node[i][0]].push_back(node[i+1][0]);
    edge[node[i][0]].push_back(node[i+1][1]-node[i][1]);
    edge[node[i+1][0]].push_back(node[i][0]);
    edge[node[i+1][0]].push_back(node[i+1][1]-node[i][1]);
  }
  sort(node.begin(),node.end(),[](vl a,vl b){return a[2]<b[2];});
  REP(i,n-1){
    edge[node[i][0]].push_back(node[i+1][0]);
    edge[node[i][0]].push_back(node[i+1][2]-node[i][2]);
    edge[node[i+1][0]].push_back(node[i][0]);
    edge[node[i+1][0]].push_back(node[i+1][2]-node[i][2]);
  }

  // construct minimum spanning tree
  vector<bool> incl(n,false);
  auto cp = [](vl a,vl b){return a[1]>b[1];};
  ll ans = 0;
  ll cnt = 1;
  priority_queue<vl,vector<vl>,decltype(cp)> cand(cp);
  incl[0] = true;
  REP(j,edge[0].size()/2){
    cand.push({edge[0][2*j],edge[0][2*j+1]});
  }

  while(cnt<n){
    vl eg = cand.top();
    cand.pop();
    if(!incl[eg[0]]){
      incl[eg[0]] = true;
      cnt ++;
      REP(i,edge[eg[0]].size()/2){
        if(incl[edge[eg[0]][2*i]]) continue;
        cand.push({edge[eg[0]][2*i],edge[eg[0]][2*i+1]});
      }
      ans += eg[1];
    }
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 23160
R, G, B, N = map(int, input().split())
ans = 0
for r in range(N // R + 1):
    for g in range(N // G + 1):
        b = (N - R * r - G * g) / B
        if b == int(b) and b >= 0:
            ans += 1
print(ans)


Measured memory_bytes: 40940
#include<bits/stdc++.h>
#define MAX 1000000007
#define ll long long
using namespace std;
int main(){
  int n;
  cin>>n;
  ll a[1050]={};
  for(int i=2;i<=n;i++){
    int tmp=i;
    for(int j=2;j<=n;j++){
      if(tmp%j==0){
	while(tmp%j==0){
	  a[j]++;
	  tmp/=j;
	}
      }
      if(tmp==1){break;}
    }
  }
  long long sum=1;
  for(int i=2;i<=n;i++){
    if(a[i]!=0){
      sum=sum*(a[i]+1)%MAX;
      //cout<<sum<<endl;
    }
    if(sum==0){
      break;
    }
    //cout<<a[i]<<endl;
  }
  cout<<sum<<endl;
  return 0;
}


Measured memory_bytes: 256
(defun solve (a b c)
  (let* ((maxi (max a b c)) 
         (da (floor (/ (- maxi a) 2)))
         (db (floor (/ (- maxi b) 2)))
         (dc (floor (/ (- maxi c) 2))))
    (setq a (+ a (* da 2)))
    (setq b (+ b (* db 2)))
    (setq c (+ c (* dc 2)))
    (+ (case (- (* 3 maxi) a b c)
         (0 0)
         (1 2)
         (2 1))
       da db dc)))

(princ (solve (read) (read) (read)))

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

P = [0] * N
sum_WA = 0

for _ in range(M):
    p_i, s_i = list(input().split())
    p_i = int(p_i) - 1
    if P[p_i] != 'AC':
        if s_i == 'WA':
            P[p_i] += 1
        else:
            sum_WA += P[p_i]
            P[p_i] = 'AC'


sum_AC = P.count('AC')
print(sum_AC, sum_WA)

Measured memory_bytes: 3828
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>

using namespace std;

int main(){
	
	int m, n, d;
	
	int ans, _;
	
	vector<int> v;
	
	string str;
	
	while(true){
		cin >> d;
		if(d == 0){
			break;
		}
		cin >> n >> m;
		v.push_back(0);
		for(int i = 0; i < n - 1; i++){
			cin >> _;
			v.push_back(_);
		}
		v.push_back(d);
		v.push_back(d);
		sort(v.begin(), v.end());
		vector<int>::iterator ite1, ite2;
		ans = 0;
		for(int i = 0; i < m; i++){
			cin >> _;
			ite2 = lower_bound(v.begin(), v.end(), _);
			ite1 = ite2;
			if(*ite2 != 0){
				ite1--;
			}
			ans += min(abs(*ite1 - _), abs(*ite2 - _));
		}
		printf("%d\n", ans);
		v.erase(v.begin(), v.end());
	}
	
	return 0;
}

Measured memory_bytes: 1712
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define int long long
#define double long double
#define rep(i,s,n) for(int i = (s); i < (n); i++)
#define all(v) begin(v), end(v)
#define allg(v) begin(v), end(v), greater<int>()



signed main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  
  string s;
  ll n, x, y;
  
  cin >> n >> x >> y;
  
  vector<ll> a(n);
  rep(i, 1, n+1) {
    rep(j, i, n+1) {
      ll dis = min(j-i, abs(y-j) +1 +abs(x-i));
      a[dis]++;
    }
  }    
  rep(i, 1, n)  cout << a[i] << "\n";

}


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

namespace abc119d
{
    class Program
    {
        static void Main(string[] args)
        {
            var abcde = new int[5];
            for (int i = 0; i < 5; i++)
            {
                abcde[i] = ReadInt();
            }
            var k = ReadInt();
            String ans = ":(";
            if (abcde[4] - abcde[0] <= k)
            {
                ans = "Yay!";
            }
            Console.WriteLine(ans);
#if DEBUG
            Console.ReadKey();
#endif
        }

        private static bool IsRange(int a, int from, int to) => (from <= a && a <= to);
        private static int ReadInt() => int.Parse(Console.ReadLine());
        private static List<int> ReadIntList() => Console.ReadLine().Split().Select(int.Parse).ToList();
        private static double ReadDouble() => double.Parse(Console.ReadLine());
        private static List<double> ReadDoubleList() => Console.ReadLine().Split().Select(double.Parse).ToList();
        private static long ReadLong() => long.Parse(Console.ReadLine());
        private static List<long> ReadLongList() => Console.ReadLine().Split().Select(long.Parse).ToList();
        private static List<int> Int2Digits(int a) => a.ToString().ToCharArray().Select(_ => int.Parse(_.ToString())).ToList();
        private static int BinarySearch<Type>(IReadOnlyList<Type> s, Type target) // target 以下の最大要素のインデックスを返す
            where Type : IComparable
        {
            var lower = 0;
            var upper = s.Count - 1;
            while (upper - lower > 1)
            {
                var mid = lower + (upper - lower) / 2;
                if (s[mid].CompareTo(target) <= 0)
                {
                    lower = mid;
                }
                else
                {
                    upper = mid;
                }

            }
            return lower;
        }
    }
}


Measured memory_bytes: 13140
import collections

# 入力
N = int(input())
c = collections.Counter(list(map(int, input().split())))

# DPテーブルを初期化
dp = [[[0.0 for k in range(310)] for j in range(310)] for i in range(310)]


for k in range(0, c[3] + 1):
    for j in range(0, c[2]+c[3]-k + 1):
        for i in range(0, c[1]+c[2]+c[3]-j-k + 1):
            if i == j == k == 0:
                continue
            dp[i][j][k] = (N+i*dp[i - 1][j][k]+j *
                           dp[i + 1][j - 1][k]+k*dp[i][j + 1][k - 1])/(i+j+k)


# 答えを得て出力
print(dp[c[1]][c[2]][c[3]])


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

int main(){
    std::string str,order;
    std::string prnt_str,repl_str;
    int i,j,k,n;
    int a=0,b=0;
    std::cin>>str>>n;


    for(i=0;i<n;i++){
        k=0;
        std::cin>>order>>a>>b;
        prnt_str=str.substr(a,b-a+1);

        if(order=="print"){
            std::cout<<prnt_str<<std::endl;
        }else if(order=="replace"){
            std::cin>>repl_str;
            for(j=a;j<=b;j++){
                str[j]=repl_str[k];
                k++;
            }
        }else if(order=="reverse"){
            for(j=b;j>=a;j--){
                str[j]=prnt_str[k];
                k++;
            }
        }
    }
    return 0;
}



Measured memory_bytes: 3208
#include <bits/stdc++.h>
using namespace std;
int main() {
    int A, B, C, D;
    cin >> A >> B >> C >> D;
    int overlap;
    if (A<=C) {
        if (C<=B && D<=B) overlap = D-C;
        else if (C<=B && D>B) overlap = B-C;
        else overlap = 0;
    }

    if (C<A) {
        if (A<=D && D<=B) overlap = D-A;
        else if (A<=D && D>B) overlap = B-A;
        else overlap = 0;
    }

    cout << overlap << endl;

    return 0;
}

Measured memory_bytes: 256
import std.algorithm, std.container, std.conv, std.math, std.range, std.typecons, std.stdio, std.string;

auto rdsp(){return readln.splitter;}
void pick(R,T)(ref R r,ref T t){t=r.front.to!T;r.popFront;}
void readV(T...)(ref T t){auto r=rdsp;foreach(ref v;t)pick(r,v);}

const mod = 10^^9+7;
alias mint = FactorRing!mod;

void main()
{
  int n; readV(n);

  int[int] h;
  foreach (i; 1..n+1) {
    auto m = i;
    while (m > 1) {
      foreach (j; 2..i+1) {
        while (m%j == 0) {
          h[j]++;
          m /= j;
        }
        if (m == 1) break;
      }
    }
  }

  auto r = mint(1);
  foreach (hi; h.byValue) r *= hi+1;

  writeln(r);
}

struct FactorRing(int m, bool pos = false)
{
  version(BigEndian) union { long vl; struct { int vi2; int vi; } } else union { long vl; int vi; }
  alias FR = FactorRing!(m, pos);
  @property static init() { return FR(0); }
  @property int value() { return vi; }
  @property void value(int v) { vi = mod(v); }
  alias value this;

  this(int v) { vi = v; }
  this(int v, bool runMod) { vi = runMod ? mod(v) : v; }
  this(long v) { vi = mod(v); }

  ref auto opAssign(int v) { vi = v; return this; }

  pure auto mod(int v) const { static if (pos) return v%m; else return (v%m+m)%m; }
  pure auto mod(long v) const { static if (pos) return cast(int)(v%m); else return cast(int)((v%m+m)%m); }

  static if (!pos) pure ref auto opUnary(string op: "-")() { return FR(mod(-vi)); }

  static if (m < int.max / 2) {
    pure ref auto opBinary(string op)(int r) if (op == "+" || op == "-") { return FR(mod(mixin("vi"~op~"r"))); }
    ref auto opOpAssign(string op)(int r) if (op == "+" || op == "-") { vi = mod(mixin("vi"~op~"r")); return this; }
  } else {
    pure ref auto opBinary(string op)(int r) if (op == "+" || op == "-") { return FR(mod(mixin("vl"~op~"r"))); }
    ref auto opOpAssign(string op)(int r) if (op == "+" || op == "-") { vi = mod(mixin("vl"~op~"r")); return this; }
  }
  pure ref auto opBinary(string op: "*")(int r) { return FR(mod(vl*r)); }
  ref auto opOpAssign(string op: "*")(int r) { vi = mod(vl*r); return this; }

  pure ref auto opBinary(string op)(ref FR r) if (op == "+" || op == "-" || op == "*") { return opBinary!op(r.vi); }
  ref auto opOpAssign(string op)(ref FR r) if (op == "+" || op == "-" || op == "*") { return opOpAssign!op(r.vi); }
}


Measured memory_bytes: 256
#include <iostream>
#include <math.h>
#include <numeric>
#include <vector>
#include <map>
#include <algorithm>
#include <queue>
#include <tuple>
#include <functional>

#define PI 3.14159265359
#define INF 1e9
#define LINF 1e18
#define rep(i,n) for(int i = 0; i < n; i++)
#define rep2(i,a,n) for(int i = a; i < n; i++)
#define in(a) cin >> a
#define out(a) cout << a << endl

using namespace std;

typedef long long ll;
typedef pair<ll, ll> PLL;

int main() 
{
    int n,i;cin >> n >> i;
    cout << n-i+1;
    return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>
#include <map>
#include <functional>
#include <algorithm>

int main() {
  int N;
  std::cin >> N;
  std::vector<int> p(N);
  for (int i = 0; i < N; ++i) { std::cin >> p[i]; }
  int ans = 0;
  for (int i = 0; i < N; ++i) {
    if (p[i] == i + 1) {
      ++ans;
      ++i;
    }
  }
  std::cout << ans << std::endl;
  return 0;
}

Measured memory_bytes: 1016
#include <iostream>
#include <utility>
#include <vector>
#include <string>
#include <stdlib.h>
using namespace std;
#define int long long
#define REP(i, n) for (int i = -200; i < (int)(n); i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define SORT(x) sort(x.begin(), x.end())
#define RS(x) rsort(x.begin(),x,end()))
#define REVE(x) reverse(x.begin(), x.end())
#define ALL(x) (x).begin(), (x).end()
typedef long double ld;
signed main(){
int n=0,m=0,a,b,c;
cin >> n >> m;
cout << n*m;
}

Measured memory_bytes: 3636
H,W = map(int,input().split())
Gd = [list(input()) for _ in range(H)]
ret = [['0']*W for _ in range(H)]
direc = [[1,0],[-1,0],[0,1],[0,-1],[1,1],[1,-1],[-1,1],[-1,-1]]
for h in range(H):
  for w in range(W):
    if Gd[h][w]=='#':
      ret[h][w]='#'
      for d in direc:
        hs, ws = h + d[0], w + d[1]
        if 0<=hs<H and 0<=ws<W:
          if Gd[hs][ws]!='#':
            ret[hs][ws]=str(1+int(ret[hs][ws]))
for _ in ret:
  print(''.join(_))

Measured memory_bytes: 3064
#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;
}

int main(){
  int n,m; cin >> n >> m;
  vector<ll> dis(n,(1e+16));dis[0] = 0;
  vector<heaP<P<int,int>>> info(n);
  for(int i = 0; i < m; ++i){
    int l,r,c; cin >> l >> r >> c;l--;r--;
    info[l].emplace(c,r);    
  }
  for(int i = 0; i < n; i++){
    int idx = i+1;
    while(!info[i].empty()){
      int topr = info[i].top().second;
      int topc = info[i].top().first;
      info[i].pop();
      while(topr >= idx){
	ChangeMin(dis[idx], dis[i]+topc);
	idx++;
      }
    }
    // debug(i);
    // debug(dis[i]);
  }
  if(dis[n-1] == (1e+16)) cout << -1 << endl;
  else cout << dis[n-1] << endl;
  return 0;
}


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

int N, Q;
long K;
int A;
int MEM[100000];

int main(void) {
	cin >> N >> K >> Q;
	

	

	for (int i = 0; i < Q; i++) {
		cin >> A;
		MEM[A - 1] += 1;
	}

	for (int i = 0; i < N; i++) {
		if ((MEM[i] + K - Q)>0)cout << "Yes" << endl;
		else cout << "No" << endl;
	}
	system("pause");
	return 0;
}

Measured memory_bytes: 1272
N = int(input())
a = [int(i) for i in input().split(" ")]
a_sum = sum(a)
ans = 100000000000
x = a[0]
y = a_sum - x
if N == 2:
    print(abs(x-y))
else:
    ans = abs(x-y)
    for i in range(1,N-1):
        x += a[i]
        y -= a[i]
        tmp = abs(x-y)
        if ans >= tmp :
            ans = tmp
    print(ans)

Measured memory_bytes: 23792
/*** author: yuji9511 ***/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> lpair;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i = (m); i < (n); i++)
#define rrep(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define print2(x,y) cout << (x) << " " << (y) << endl;
#define printa(x,n) for(ll i = 0; i < n; i++){ cout << (x[i]) << " \n"[i==n-1];};

struct HashData {
	ll h1, h2;
	bool operator==(const HashData& rhs) const {
		return h1 == rhs.h1 && h2 == rhs.h2;
	}
	bool operator!=(const HashData& rhs) const { return !(*this == rhs); }
};

class RollingHash {
	template<const ll B, const ll M>
	class RollingHashPart {
	private:
		size_t len;
		vector<ll> pow_b, hash;
	public:
		RollingHashPart() {}
		template<typename T>
		RollingHashPart(const T& s) : len(s.size()), pow_b(s.size() + 1), hash(s.size() + 1) {
			pow_b[0] = 1;
			hash[0] = 0;
			for (ll i = 0; i < len; i++) {
				pow_b[i + 1] = pow_b[i] * B % M;
				hash[i + 1] = (hash[i] * B + s[i]) % M;
			}
		}
		// [l, r)
		ll get(ll l, ll r) const {
			ll res = (hash[r] - hash[l] * pow_b[r - l]) % M;
			if (res < 0) res += M;
			return res;
		}
	};
public:
	RollingHashPart<1033, 1000000007> rh1;
	RollingHashPart<6037, 999999937> rh2;
 
	RollingHash() {}
	template<typename T> RollingHash(const T & s) : rh1(s), rh2(s) {}
	// [l, r)
	HashData get(ll l, ll r) const {
		return (HashData){ rh1.get(l, r), rh2.get(l, r) };
	}

	lpair getPair(ll l, ll r) const {
		return make_pair(rh1.get(l,r) , rh2.get(l, r));
	}
	// [l1, r1), [l2, r2)
	ll lcp(const RollingHash & rhs, ll l1, ll r1, ll l2, ll r2) const {
		ll lb = 0, ub = min(r1 - l1, r2 - l2) + 1;
		while (ub - lb > 1) {
			ll md = (lb + ub) >> 1;
			(get(l1, l1 + md) == rhs.get(l2, l2 + md) ? lb : ub) = md;
		}
		return lb;
	}
};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N;
    cin >> N;
    string S;
    cin >> S;
    RollingHash r(S);
    ll lv = 0, rv = N+1;
    while(rv - lv > 1){
        ll mid = (rv + lv) / 2;
        bool ok = false;
        rep(i,0,N){
            rep(j,i+1,N){
                if(j - i < mid) continue;
                if(j+mid-1 >= N) continue;
                if(r.getPair(i, i+mid) == r.getPair(j, j+mid)){
                    ok = true;
                    break;
                }
            }
            if(ok) break;
        }
        if(ok){
            lv = mid;
        }else{
            rv = mid;
        }
    }
    print(lv);


    
}


Measured memory_bytes: 512
#include<cstdio>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
using namespace std;
typedef long long ll;
struct edge
{
	ll x,w,c;
	bool operator<(const edge&y)const
	{
		return w>y.w;
	}
	bool operator>(const edge&y)const
	{
		return w<y.w;
	}
}h,v;
ll ans[100005],n,m,ss,t,i,a[100005],x,y,w,c,b[100005],vis1[100005],vis2[100005];
vector<edge> s[100005];
priority_queue<edge> q;
ll minn(ll a,ll b){return a<b?a:b;}
int main()
{
	cin>>n>>m>>ss>>t;
	for(i=1;i<=n;i++)a[i]=b[i]=1e16;
	for(i=1;i<=m;i++)
	{
		cin>>x>>y>>w>>c;
		s[x].push_back((edge){y,w,c});
		s[y].push_back((edge){x,w,c});
	}
	a[ss]=0;
	q.push((edge){ss,0,0});
	while(!q.empty())
	{
		h=q.top();
		q.pop();
		if(vis1[h.x])continue;
		vis1[h.x]=1;
		for(i=0;i<s[h.x].size();i++)
		{
			v=s[h.x][i];
			if(vis1[v.x])continue;
			if(a[v.x]>a[h.x]+v.w)
			{
				a[v.x]=a[h.x]+v.w;
				q.push((edge){v.x,a[v.x],0});
			}
		}
	}
	b[t]=0;
	q.push((edge){t,0,0});
	while(!q.empty())
	{
		h=q.top();
		q.pop();
		if(vis2[h.x])continue;
		vis2[h.x]=1;
		for(i=0;i<s[h.x].size();i++)
		{
			v=s[h.x][i];
			if(vis2[v.x])continue;
			if(b[v.x]>b[h.x]+v.c)
			{
				b[v.x]=b[h.x]+v.c;
				q.push((edge){v.x,b[v.x],0});
			}
		}
	}
	for(i=1;i<=n;i++)a[i]+=b[i];
	ans[n+1]=1e16;
	for(i=n;i>0;i--)
	{
		ans[i]=minn(ans[i+1],a[i]);
	}
	for(i=1;i<=n;i++)cout<<1000000000000000-ans[i]<<endl;
	return 0;
}

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

#define fst first
#define snd second
#define ll long long
#define ld long double
#define pb push_back
#define emp emplace_back
#define pii pair<int, int>
#define usg unsigned
#define sg signed
#define mp make_pair

using namespace std;

void setIO(){
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	// freopen("input.txt", "r", stdin);
	// freopen("output.txt", "w", stdout);
}

const ld PI = 4*atan((ld)1);
const int INF = 1e9+7;
const ll _INF = 1e18+7;


int main(){
	setIO();
	int n, x, t;
	cin >> n >> x >> t;
	cout << (n+x-1)/x*t << endl;
}

Measured memory_bytes: 3608
#include<stdio.h>

int main(void){
  long int a[200001],x[200001];
  long int n,i;
  scanf("%ld\n",&n);
  for(i=1;i<=n;i++){
    scanf("%ld ",&a[i]);
    x[i]=0;
  }
  
  for(i=1;i<=n;i++){
    x[a[i]]++;
  }
  
  long int s=0;
  for(i=1;i<=n;i++){
    s=s+x[i]*(x[i]-1)/2;
  }
  
  for(i=1;i<=n;i++){
    printf("%ld\n",s-x[a[i]]+1);
  }
  
  return 0;
}


Measured memory_bytes: 5632
#include<iostream>
#include<utility>
using namespace std;
int N;

long long int max(long long int a, long long int b) {
	if (a > b) { return a; }

	return b;
}
long long int A[105];
int main(void) {
	cin >> N;
	long long int tmp;
	for (int i = 1; i <= N; i++) {
		cin >> tmp;
		A[i] = tmp;
	}


	long long int ans = 0;

	for (int i = 1; i <= N - 1; i++) {
		for (int j = i + 1; j <= N; j++) {
			ans = max(ans, abs(A[i] - A[j]));
		}
	}
	cout << ans << endl;
//	system("pause");
	return 0;
}

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

int main() {
    int N; cin >> N;
    vector<long long> A(N*3);
    for (int i = 0; i < N*3; ++i) cin >> A[i];
    sort(A.begin(), A.end(), greater<long long>());
    long long res = 0;
    for (int i = 1, j = 0; j < N; i += 2, ++j) res += A[i];
    cout << res << endl;
}


Measured memory_bytes: 2560
x, y = map(int, input().split())

# これで通らないのは、y/xが大きな数字になったとき
# print(int(log2(y/x)) + 1)

tmp = y//x
cnt = 0
while tmp >= 2:
    cnt += 1
    tmp = tmp // 2
print(cnt + 1)


Measured memory_bytes: 2940
#include <iostream>
#include <vector>
#include <map>
using namespace std;
int main(){
  int N;
  map<int,int> A;
  cin >> N;
  for(int i=0;i<N;i++){
    int tmp;
    cin >> tmp;

    if (A.count(tmp)==1){
      A.erase(tmp);
    } else {
      A[tmp] = 1;
    }
  }

  cout << A.size() << endl;

}

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

int main() {
  int n, k;
  int d;
  cin >> n >> k;
  vector<int> have(n, 0);
  for(int i = 0; i < k; i++) {
    cin >> d;
    vector<int> sweet(d);
    for(int j = 0; j < d; j++) {
      cin >> sweet.at(j);
      have.at(sweet.at(j)-1)++;
    }
  }
  int count = 0;
  for(int i = 0; i < n; i++) {
    if(have.at(i) == 0) {
      count ++;
    }
  }
  cout << count << endl;
}

Measured memory_bytes: 3624
#include<iostream>
#include<vector>
#include<queue>
using namespace std;
long N;
int M,Q;
int A[1<<17];
int d[4]={0,1,0,-1};
long f(int h)
{
	vector<vector<bool> >mp(h,vector<bool>(7,true));
	for(int i=0;i<Q;i++)
	{
		for(int j=A[i];j<7*h;j+=M)
		{
			mp[j/7][j%7]=false;
		}
	}
	long cnt=0;
	for(int i=0;i<h;i++)for(int j=0;j<7;j++)if(mp[i][j])
	{
		queue<pair<int,int> >P;P.push(make_pair(i,j));
		mp[i][j]=false;
		cnt++;
		while(!P.empty())
		{
			int x=P.front().first,y=P.front().second;P.pop();
			for(int r=0;r<4;r++)
			{
				int tx=x+d[r],ty=y+d[r^1];
				if(tx<0||ty<0||tx>=h||ty>=7||!mp[tx][ty])continue;
				mp[tx][ty]=false;
				P.push(make_pair(tx,ty));
			}
		}
	}
	return cnt;
}
main()
{
	cin>>N>>M>>Q;
	for(int i=0;i<Q;i++)cin>>A[i];
	int X=M%7?7*M:M;
	long S=f(X/7);
	if(X/7<N)
	{
		long T=f(2*X/7);
		long a=T-S,b=S-a;
		S=N/(X/7)*a+b;
	}
	cout<<S<<endl;
}

Measured memory_bytes: 14396
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;


public class Main {
    public void solve(BufferedReader stdin, PrintWriter stdout) throws NumberFormatException, IOException {
        int n = Integer.parseInt(stdin.readLine());
        stdout.println((n - 2) * 180);
    }

    public static void main(String[] args) throws NumberFormatException, IOException {
        BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter stdout = new PrintWriter(System.out, false);
        new Main().solve(stdin, stdout);
        stdout.flush();
    }
}


Measured memory_bytes: 21076
#include <bits/stdc++.h>
#define cout16 cout << setprecision(16) 
#define rep(i,n) for(int i=0;i<n;i++ )
#define rep2(i,f,n) for(int i=f;i<n;i++ )
#define MAX(A) *max_element(A.begin(),A.end())
#define MIN(A) *min_element(A.begin(),A.end())
#define SORT(A) sort(A.begin(),A.end())
#define REV(A) reverse(A.begin(),A.end())
typedef long long int ll;
using vi = std::vector<int>;
using vvi = std::vector<std::vector<int>>;
using vll = std::vector<ll>;
using vvll = std::vector<std::vector<ll>>;
using P = std::pair<int,int>;
using vp = std::vector<P>;
using namespace std;
#define INF 1001001001
#define LL_INF 1001001001001001001
#define fi first
#define se second

int main(void) {
	int n; cin >> n;
	vi x(n);
	rep(i,n){
		cin >> x[i];
		x[i]--;
	}
	int ans = INF;
	rep(p,100){
		int sum = 0;
		rep(i,n) sum += (x[i]-p)*(x[i]-p);
		ans = min(ans,sum);
	}
	cout << ans << endl;
	
}




Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <algorithm>
using namespace std;
const int MAXN = 105;

int n, l[MAXN], s[MAXN], tot[MAXN], m, ans;

bool check(int x, int y, int z) {
	if (l[x] != l[y] && l[x] != l[z] && l[z] != l[y] && l[x] + l[y] > l[z] && l[x] + l[z] > l[y] && l[z] + l[y] > l[x]) return 1;
	else return 0;
}

int main() {
	scanf ("%d", &n);
	for (int i = 1; i <= n; i++) {
		scanf ("%d", &l[i]);
	} 
	for (int i = 1; i <= n; i++) {
		for (int j = i + 1; j <= n; j++) {
			for (int k = j + 1; k <= n; k++) {
				if (check(i, j, k)) ans ++;
			}
		}
	}
	printf ("%d\n", ans);
	return 0;
}

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

using namespace std;

int main(){
	ios_base::sync_with_stdio (false);
	cout << fixed;
	cout.precision(10);
	if(fopen("joke.in", "r")){
		freopen ("joke.in","r",stdin);
		freopen ("joke.out","w",stdout);
	}

	int n, k;
	cin >> n >> k;
	vector<int> h(n + 1);
	for(int i = 1; i <= n; ++i){
		cin >> h[i];
	}

	vector<int> dp(n + 2, 1e9);

	dp[1] = 0;
	for(int i = 1; i < n; ++i){
		for(int d = 1; d <= k && i + d <= n; ++d){
			dp[i + d] = min(dp[i + d], dp[i] + abs(h[i] - h[i + d]));
		}
	}
	cout << dp[n];

    return 0;
}


Measured memory_bytes: 1024
from collections import deque
K = int(input())

dp = [[0]*10 for _ in range(17)]
for i in range(10):
    dp[0][i] = 1

for keta in range(1, 17):
    for i in range(10):
        if 1 <= i and i <= 8:
            dp[keta][i] += dp[keta-1][i-1]+dp[keta-1][i]+dp[keta-1][i+1]
        if i == 0:
            dp[keta][i] += dp[keta-1][0]+dp[keta-1][1]
        if i == 9:
            dp[keta][i] += dp[keta-1][9]+dp[keta-1][8]
SUM = 0
for keta in range(17):
    SUM += sum(dp[keta][1:])
    if SUM >= K:
        break
SUM = 0
for i in range(keta):
    SUM += sum(dp[i][1:])

r = K-SUM
tmp_r = 0
for i in range(1, 10):
    tmp_r += dp[keta][i]
    if tmp_r >= r:
        tmp_r -= dp[keta][i]
        r -= tmp_r
        break
keta += 1
if keta == 1:
    print(i)
else:
    l=[i]
    rr = 0
    for k in range(keta-1, 0, -1):
        q = deque()
        if i == 0:
            q.append(0)
            q.append(1)
        elif i == 9:
            q.append(8)
            q.append(9)
        else:
            q.append(i-1)
            q.append(i)
            q.append(i+1)
        while q:
            num = q.popleft()
            rr += dp[k-1][num]
            if rr >= r:
                rr -= dp[k-1][num]
                l.append(num)
                i = num
                break
    keta = len(l)
    ans = 0
    for i in range(keta):
        ans += l[keta-i-1]*10**i
    print(ans)

Measured memory_bytes: 38384
'use strict';
function Main(input) {
  input = input.split("\n");
  var a = parseInt(input[0], 10);
  var b = parseInt(input[1], 10);
  var h = parseInt(input[2], 10);
  console.log(((a + b) * h) / 2);
}

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


Measured memory_bytes: 7372
from collections import deque

N, K =map(int, input().split())
V=list(map(int, input().split()))
Vd = deque(V)
score = 0

for a in range(min(K,N)+1):
  for b in range(min(K-a+1,N-a+1)):
    hou = []
    Vd = deque(V)
    for _ in range(a):
      hou.append(Vd.popleft())
    for _ in range(b):
      hou.append(Vd.pop())
    hou.sort()
    for _ in range(K-a-b):
      if hou:
        if hou[0]>0:
          break
        hou.pop(0)
    score = max(score,sum(hou))
    
print(score)

Measured memory_bytes: 3444
#include<cstdio>
#include<cstring>
int n,col[777],c1,c2;
bool a[2][777];
bool g[777][777];
bool dfs(int x,int c){
	if(col[x] == 0){
		col[x] = c;
		if(c == 1)c1++;else
			c2++;
	}
	else
		return col[x] == c;
	for(int i=0; i<n; i++)if(x!=i && !g[x][i]){
		if(!dfs(i, -c))
			return false;
	}
	return true;
}
int main(){
	int m;
	scanf("%d%d",&n,&m);
	while(m--){
		int x,y;
		scanf("%d%d",&x,&y);
		--x;--y;
		g[x][y] = g[y][x] = true;
	}
	a[0][0] = true;bool flag = false;
	for(int i=0; i<n; i++){
		if(col[i] == 0){
			c1 = 0; c2 = 0;
			if(!dfs(i,1)){
				puts("-1");
				return 0;
			}
			memset(a[!flag],0,sizeof(a[!flag]));
			for(int j=0; j<=n; j++)if(a[flag][j]){
				a[!flag][j+c1] = a[!flag][j+c2] = true;
			}
			flag = !flag;
		}
	}
	for(int i=n/2; i>=0; i--)if(a[flag][i]){
		printf("%d\n", i*(i-1)/2 + (n-i)*(n-i-1)/2);
		return 0;
	}
}


Measured memory_bytes: 640
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
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; }

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    set<string> st;
    rep(i,n){
        string s;
        cin >> s;
        st.insert(s);
    }
    cout << st.size() << endl;
    return 0;
}


Measured memory_bytes: 19060
#include <stdio.h>
int main(void){
	int N,T=0,F=0;
	scanf("%d",&N);
	int a[N];
	for(int i=0;i<N;i++){
		scanf("%d",&a[i]);
		if(a[i]%2 ==0 && a[i]%4 !=0){
			T++;
		}
		if(a[i]%4 ==0){
			F++;
		}
	}
	if( N/2 <=(F+T/2)){
		printf("Yes");
		return 0;
	}
	if( N ==T){
		printf("Yes");
		return 0;
	}
	printf("No");
	return 0;
}

Measured memory_bytes: 512
#include <stdio.h>
#include<string.h>
int main()
{
  int i,j,count=0;
  char a[100];
  scanf("%s",a);
  for(i=0;i<strlen(a)/2;i++)
  {
  	if(a[strlen(a)-1-i]!=a[i])
  	count++;
  }
  printf("%d",count);
return 0; 
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int a[1000001];
	long long d[1000001];
int main()
{
	int n;
	cin>>n;
	
	
	for(int i=1;i<=n;i++){
		cin>>a[i];
	}
	d[1]=0;
	d[2]=abs(a[2]-a[1]);
	for(int i=3;i<=n;i++){
		if(d[i-2]+abs(a[i]-a[i-2])<=d[i-1]+abs(a[i]-a[i-1])){
			d[i]=d[i-2]+abs(a[i]-a[i-2]);
		}
		else
		d[i]=d[i-1]+abs(a[i]-a[i-1]);
	}
	cout<<d[n];
	
	
	
	return 0;
}

Measured memory_bytes: 5120
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
#define fi first
#define se second
#define pb push_back
#define forn(i,n) for(int i=0;i<(n);i++)
#define for1(i,n) for(int i=1;i<=n;i++)
#define forr(i,n) for(int i=n;i>=0;i--)
#define all(x) x.begin(), x.end()
const int MAXN = 1e5 +5;

void fio(){
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}

vector<array<int,4> > Q;
int n,m,q;
int an = 0;
vector <int> v;

void dfs(int u){
	if(v.size()==n){
		int ma = 0;
		an = max(an, accumulate(all(Q), ma, [&](int k, array<int,4> z){
			return v[z[1]] - v[z[0]] == z[2]? k + z[3]: k;
		}));
		return;
	}
	for(int i = u; i<=m ;i++){
		v.pb(i);
		dfs(i);
		v.pop_back();
	}
}

int main(){
  fio();
  cin>>n>>m>>q;
  Q.resize(q);
  forn(i,q){
  	cin>>Q[i][0]>>Q[i][1]>>Q[i][2]>>Q[i][3];
  	Q[i][0]--,Q[i][1]--;
  }
  dfs(1);
  cout<<an<<endl;
  return 0;
}

Measured memory_bytes: 3664
#include "bits/stdc++.h"

using namespace std;

using ll = long long;
using ld = long double;

const double PI = 3.1415926535897932384626433832795;

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

int gcd(int x, int y) { return y ? gcd(y, x % y) : x; }
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
int lcm(int x, int y) { return x / gcd(x, y) * y; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }

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

	const int MOD = 1000000007;

	int h, w, k;
	cin >> h >> w >> k;

	vector<vector<int>> dp(h + 1, vector<int>(w, 0));
	dp[0][0] = 1;

	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			for (int k = 0; k < 1 << (w - 1); k++) {

				bool ok = true;
				for (int l = 0; l < w - 2; l++) {
					if ((k & (1 << l)) && (k & (1 << (l + 1)))) {
						ok = false;
						break;
					}
				}

				if (!ok) {
					continue;
				}

				if (j >= 1 && (k & (1 << (j - 1)))) {
					// 左
					dp[i + 1][j - 1] += dp[i][j];
					dp[i + 1][j - 1] %= MOD;
				} else if (j <= w - 2 && k & (1 << j)) {
					// 右
					dp[i + 1][j + 1] += dp[i][j];
					dp[i + 1][j + 1] %= MOD;
				} else {
					// 直進
					dp[i + 1][j] += dp[i][j];
					dp[i + 1][j] %= MOD;
				}
			}
		}
	}

	cout << dp[h][k - 1] << endl;
	return 0;
}


Measured memory_bytes: 256