akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for(int(i) = 0; (i) < (n); (i)++)
#define FOR(i, m, n) for(int(i) = (m); (i) < (n); (i)++)
#define All(v) (v).begin(), (v).end()
#define pb push_back
#define MP(a, b) make_pair((a), (b))
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const int INF = 1 << 30;
const ll LINF = 1LL << 60;
const int MOD = 1e9 + 7;

int main() {
    int X, Y, Z;
    cin >> X >> Y >> Z;
    cout << Z << " " << X << " " << Y << endl;
    return 0;
}

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

#include <algorithm>
#include <iomanip>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>

int main() {

    long long int x;
    cin >> x;

    for ( long long int a = -1000; a <= 1000; a++ ) {
        long long int aa = a * a * a * a * a;
        for ( long long int b = -1000; b <= 1000; b++ ) {
            long long int bb = b * b * b * b * b;
            if ( aa - bb != x ) continue;
            cout << a << " " << b << endl;
            return 0;
        }
    }

    return 0;

}


Measured memory_bytes: 3596
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10**9 + 7
#from decimal import *

N, K = MAP()
A = LIST()

C = Counter(A)

n = sorted(list(C.values()))
print(sum(n[:len(n)-K]))



Measured memory_bytes: 34840
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=2e5+10;
const ll inf=2e16;
int n,num;
ll ans,res,t[N],rv[N],a[N];

int main(){
     int i,j,pos;
	 cin>>n;
     for(i=1;i<=n;++i){
     	cin>>a[i];
     	a[i]-=i;
     }t[0]=0;rv[n+1]=0;
     if(n==1) {printf("0\n");return 0;}
     sort(a+1,a+n+1);t[1]=-a[1];rv[n]=a[n];
     for(i=2;i<=n;++i) t[i]=t[i-1]-a[i];
     for(i=n-1;i>=1;--i) rv[i]=rv[i+1]+a[i];
     if(n&1){pos=(n+1)>>1;ans=t[pos-1]+rv[pos+1];}
     else{pos=n>>1;ans=t[pos]+rv[pos+1];}
     cout<<ans<<endl;
}

Measured memory_bytes: 4992
import math, string
# 10進数整数を2進数文字列に変換する関数
# decimal : 10進数整数
# press   : 上位桁の0を切り詰めるフラグ
def toBinary(decimal, press=True):
    if decimal == 0: return '0'
    bin_str = ""
    i = 31
    while i >= 0:
        bi = int((decimal & int(math.pow(2, i))) >> i)
        bin_str += str(bi)
        i -= 1
    if press:
        try:
            bin_str = bin_str[bin_str.index('1'):]
        except ValueError:
            print('error')
            bin_str = '0'
    return bin_str

def isLight(bin_temp):
    for index,light in enumerate(light_list):
        light_count=0
        for switch_num in light:
            light_count += int(bin_temp[switch_num-1])
        if light_count%2 != even_or_odd[index]:
            return False
    return True
    
N,M= map(int,input().split())
light_list=[]
even_or_odd=[]
for i in range(M):
    temp=list(map(int,input().split()))
    temp = temp[1:]
    light_list.append(temp)

even_or_odd=list(map(int,input().split()))
pattern_list=[]
ans =0
for i in range(2**N):
    bin_temp = toBinary(i).rjust(N,'0')
    bin_temp=bin_temp[::-1]
    pattern_list.append(bin_temp)
    
    if isLight(bin_temp):
        ans += 1
        #print("ans has become %d" % ans)
            


print(ans)

Measured memory_bytes: 3832
MOD = 10**9 + 7
N, K = map(int, input().split())
cusum = [0]
for i in range(1, N+1):
    cusum += [cusum[-1] + i]
ans = 0
for k in range(K, N+1):
    ans += (cusum[N]-cusum[N-k]-cusum[k-1] + 1)
    ans %= MOD
print((ans+1)%MOD)

Measured memory_bytes: 81868
n=int(input())
a = [input() for i in range(n)]
A=str(a.count("AC"))
B=str(a.count("WA"))
C=str(a.count("TLE"))
D=str(a.count("RE"))
print("AC x "+ A)
print("WA x "+ B)
print("TLE x "+ C)
print("RE x "+ D)

Measured memory_bytes: 16300
#include <bits/stdc++.h>
using namespace std;
int main(){
    int h,w;
    vector<vector<char>> a(100,vector<char>(100));
    
    cin >> h >> w;
    
    for(int i=0;i<w+2;i++) cout << "#";
    
    cout << "\n";
    
    for(int i=0;i<h;i++){
        cout << "#";
        for(int j=0;j<w;j++){
            cin >> a[i][j];
            cout << a[i][j];
        }
        cout << "#\n";
    }
    
    for(int i=0;i<w+2;i++) cout << "#";
    
    cout << "\n";
}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <ios>
#include <iostream>
#include <vector>

#define ll unsigned long long

using namespace std;

ll K;
vector<ll> num(50);

int main()
{
    cin >> K;
    cout << 50 << endl;

    ll q = K / 50;
    ll r = K % 50;

    for (size_t i = 0; i < 50; i++) {
        num[i] = i + q;
    }

    for (size_t j = 0; j < r; j++) {
        for (size_t k = 0; k < 50; k++) {
            if (k == j) {
                num[k] += 50;
            } else {
                num[k] -= 1;
            }
        }
    }

    for (size_t i = 0; i < 50; i++) {
        cout << num[i] << " ";
    }
    cout << endl;

    return 0;
}

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

int main()
{

    ll n,i,j,k,l,a,b,c,d,m,f1,f2;
    cin>>a>>b>>c;
    k=10000000000;
    l=k-b;
    l+=c;
    m=k+a;
    if(l<=k)
    {
        cout<<"delicious"<<endl;
    }
    else if(l>k&&l<=m)
    {
        cout<<"safe"<<endl;
    }
    else if(l>m)
    {
        cout<<"dangerous"<<endl;
    }
    return 0;
}


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

using namespace std;

typedef struct {
    int x, y;
    bool root[4];
} Node;

Node v[5][5];
const string ord = "URDL";
const int dx[] = {-1, 0, 1, 0}, dy[] = {0, 1, 0, -1};

void init() {
    for (int i = 0; i < 5; i++) {
        for (int j = 0; j < 5; j++) {
            v[i][j].x = i;
            v[i][j].y = j;
            for (int k = 0; k < 4; k++)
                v[i][j].root[k] = false;
        }
    }
}

void solve(int x, int y, char c) {
    cout << c;
    if (x == 0 && y == 0) {
        cout << '\n';
        return;
    }

    int start = (ord.find(c) + 3) % 4;
    for (int i = 0; i < 4; i++) {
        int ni = (i + start) % 4;
        if (v[x][y].root[ni]) {
            solve(x + dx[ni], y + dy[ni], ord[ni]);
            return;
        }
    }
}

int main() {
    init();

    for (int i = 0; i < 9; i++) {
        string input;
        cin >> input;

        for (int j = 0; j < input.size(); j++) {
            if (input[j] != '1') continue;
            
            if (i % 2) {
                v[(i + 1) / 2 - 1][j].root[2] = true;
                v[(i + 1) / 2][j].root[0] = true;
            } else {
                v[i / 2][j].root[1] = true;
                v[i / 2][j + 1].root[3] = true;
            }
        }
    }

    solve(0, 1, 'R');

    return 0;
}


Measured memory_bytes: 2932
using System;
using System.Collections.Generic;
using System.Linq;
 
namespace Template
{
    public class Scanner
    {
        public string NextLine => Console.ReadLine();
        public int NextInt => int.Parse(NextLine);
        public long NextLong => long.Parse(NextLine);
        public double NextDouble => double.Parse(NextLine);
 
        public string[] StrAry(char separator = ' ') => Console.ReadLine().Split(separator);
        public int[] IntAry(char separator = ' ') => Array.ConvertAll(StrAry(separator), int.Parse);
        public long[] LongAry(char separator = ' ') => Array.ConvertAll(StrAry(separator), long.Parse);
        public double[] DoubleAry(char separator = ' ') => Array.ConvertAll(StrAry(separator), double.Parse);
    }
 
    internal class Template
    {
        public static void Swap<T>(ref T a, ref T b) { var tmp = a; a = b; b = tmp; }
        private static void Fill<T>(T[] src, T value, int len) { for (int i = 0; i < len; i++) { src[i] = value; } }
 
        static void Solve() 
        {
            var scan = new Scanner();
            var val = scan.NextInt;
            Console.WriteLine((val < 1200) ? "ABC" : "ARC");
        }
 
        private static void Main()
        {
            Console.SetOut(new System.IO.StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });
            Solve();
            Console.Out.Flush();
        }
    }
}


Measured memory_bytes: 11092
#include <bits/stdc++.h>
using namespace std;
using Pi = pair < int, int >;
using Pii = pair < int , Pi >;

constexpr int INF = (1 << 30) - 1;
constexpr int dx[] = {1, 0, -1, 0};
constexpr int dy[] = {0, 1, 0, -1};

int main()
{
        int W, H, N;
        int mc[55][55];
        priority_queue < Pii > pq;

        cin >> W >> H >> N;
        
        fill_n(*mc, 55 * 55, INF);

        for ( int i = 0; i < N; i++ ) {
                int x, y, a;
                cin >> x >> y >> a; --x, --y;
                mc[y][x] = a;
                pq.push(Pii(a, Pi(x, y)));
        }
        
        while ( !pq.empty() ) {
                Pii dat = pq.top(); pq.pop();
                int x = dat.second.first, y = dat.second.second, a = dat.first;
                for ( int i = 0; i < 4; i++ ) {
                        int nx = x + dx[i], ny = y + dy[i];
                        if ( 0 <= nx && nx < W && 0 <= ny && ny < H ) {
                                if ( mc[ny][nx] == INF ) {
                                        mc[ny][nx] = a - 1;
                                        pq.push(Pii(a - 1, Pi(nx, ny)));
                                } else if ( abs(mc[y][x] - mc[ny][nx]) >= 2 ) {
                                        cout << "No" << endl;
                                        return ( 0 );
                                }
                        }
                }
        }
        
        int sum = 0;
        for ( int i = 0; i < H; i++ ) {
                for ( int j = 0; j < W; j++ ) {
                        sum += mc[i][j];
                }
        }

        cout << sum << endl;

        return ( 0 );
}



Measured memory_bytes: 3144
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using static System.Console;
using static System.Math;

namespace Atcoder
{
    class Program
    {
        static StreamWriter sw = new StreamWriter(OpenStandardOutput()) { AutoFlush = false };
        static void Main(string[] args)
        {
            try
            {
                SetOut(sw);
                Solve.Answer();
                Out.Flush();
            }
            catch (Exception ex)
            {
                WriteLine(ex.ToString());
            }
        }
    }

    public class Solve
    {
        public static void Answer()
        {
            var s = ReadLine();
            var k = IO.RLong;

            for (int i = 0; i < s.Length; i++)
            {
                if (s[i] != '1')
                {
                    if (k <= i)
                    {
                        WriteLine('1');
                        return;
                    }
                    WriteLine(s[i]);
                    return;
                }
            }
            WriteLine('1');
        }
    }

    public class IO
    {
        #region Input
        public static int RInt => int.Parse(ReadLine());
        public static long RLong => long.Parse(ReadLine());
        public static double RDouble => double.Parse(ReadLine());

        public static string[] RSString => ReadLine().Split();
        public static int[] RSInt => ReadLine().Split().Select(s => int.Parse(s)).ToArray();
        public static long[] RSLong => ReadLine().Split().Select(s => long.Parse(s)).ToArray();
        public static double[] RSDouble => ReadLine().Split().Select(s => double.Parse(s)).ToArray();
        #endregion

        #region Output
        public static void OutJoinSpace<T>(IEnumerable<T> list) => WriteLine(string.Join(" ", list));
        public static void WriteLineYes_or_No(bool flag) => WriteLine(flag ? "Yes" : "No");
        public static void WriteLineYES_or_NO(bool flag) => WriteLine(flag ? "YES" : "NO");
        #endregion
    }

    public class Mod
    {
        #region
        private readonly static long M = 1000000007;

        public static long Add(long a, long b) => (a * b) % M;
        public static long Sub(long a, long b) => (a - b) % M >= 0 ? (a - b) % M : (a - b) % M + M;
        public static long Multi(long a, long b) => (a * b) % M;
        #endregion
    }
}

Measured memory_bytes: 13140
#include <bits/stdc++.h>
#ifdef IS_MY_ENV
#include <tourist>
#endif
using namespace std;

int dp[100100][3];
int act[100100][3];

signed main() {

    int n;
    cin >> n;
    for ( int i = 0; i < n; i++ ) {
        for ( int j = 0; j < 3; j++ ) {
            cin >> act[i][j];
        }
    }

    for ( int i = 0; i < n; i++ ) {
        for ( int j = 0; j < 3; j++ ) {
            dp[i+1][j] = max(dp[i][(j+1)%3] + act[i][(j+1)%3],
                           dp[i][(j+2)%3] + act[i][(j+2)%3]);
        }
    }

    cout << max ( dp[n][0], max ( dp[n][1], dp[n][2] ) ) << endl;

    return 0;
}

Measured memory_bytes: 2560
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

struct node{
	unsigned int key;
	struct node *next;
	struct node *prev;
};

typedef struct node * NodePointer;

NodePointer nil;

NodePointer listSearch( int key )
{
	NodePointer cur = nil->next;
	while( cur != nil && cur->key != key ) {
		cur = cur->next;
	}
	return cur;
}

void init( )
{
	nil = malloc( sizeof(struct node) );
	nil->next = nil;
	nil->prev = nil;
}

void printList( )
{
	NodePointer cur = nil->next;
	int isf = 1;
	while( cur != nil ) {
		if( isf == 0) { printf(" "); }
		printf( "%d", cur->key );
		cur = cur->next;
		isf = 0;
	}
	printf("\n");
}

void deleteNode( NodePointer t )
{
	t->prev->next = t->next;
	t->next->prev = t->prev;
	free( t );
}

void deleteFirst( )
{
	NodePointer t = nil->next;
	if( t == nil ) return;
	deleteNode( t );
}

void deleteLast( )
{
	NodePointer t = nil->prev;
	if( t == nil ) return;
	deleteNode( t );
}

void delete( int key )
{
	NodePointer t = listSearch( key );
	if( t == nil ) return;
	deleteNode( t );
}

void insert( int key )
{
	NodePointer x;
	x = malloc( sizeof(struct node) );
	x->key = key;
	x->next = nil->next;
	x->next->prev = x;
	x->prev = nil;
	nil->next = x;
}


int main( int argc, char *argv[] ) 
{
	int key, n, i;
	char com[20];
	
	scanf( "%d", &n );
	init( );
	for( i = 0; i < n; i++ ) {
		scanf( "%s%d", com, &key );
		if( com[0] == 'i' ) {
			insert( key ); 
		} else if( com[0] == 'd' ) {
			if( 6 < strlen( com )  ) {
				if( com[6] == 'F' ) { 
					deleteFirst( );
				} else if( com[6] == 'L' ) {
					deleteLast( );
				}
			} else {
				delete( key );
			}
		}
	}
	printList( );
	
    return 0;
}

Measured memory_bytes: 31656
n, k = map(int, input().split())
p = list(map(int, input().split()))
lis = []
for i in range(n):
    lis.append((p[i]+1)/2)
#print(lis)
val = [0]
for i in range(1,n+1):
    val.append(val[i-1] + lis[i-1])
#print(val)

ans = val[k-1]
for i in range(k,n+1):
    if val[i] - val[i-k] > ans:
        ans = val[i] - val[i-k]
print(ans)

Measured memory_bytes: 78984
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define watch(x) cout <<(#x)<<" is "<<(x)<<endl
#define debug cout <<"hi"<<endl
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
const int MOD=1e9+7;
const int INF32=1<<30;
const ll INF64=1LL<<60;

int main(){
  int n,d; cin >>n >>d;
  cout <<ceil(1.0*n/(2*d+1));
return 0;}

Measured memory_bytes: 3800
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define E "\n"

using namespace std;
const long long MOD = (long long)1e9 + 7;

int a, b;
string s, t, u;

int main()
{
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin >> s >> t >> a >> b >> u;
    if (s == u) a--;
    else b--;
    cout << a << " " << b << E;
    //system("pause");
    return 0;
}

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

int main(){
	
	int x;
	
	cin >> x;
	
	int ans = 0;
	int cnt = 0;
	while (x >= 500){
		x-=500;
		ans+=1000;
	}
	
	while (x >= 5){
		x-=5;
		ans+=5;
	}
	
	cout << ans;
	
}

Measured memory_bytes: 256
#include <iostream>
#include <math.h>
#include <iomanip>
using namespace std;
 
int main() {
  double A;
  double B;
  double H;
  double M;
  double a;
  double b;
  double c;
  double pi = 3.141592653589793238;
  double ans;
  cin >> A;
  cin >> B;
  cin >> H;
  cin >> M;
  a = M * 6.0;
  b = H * 30.0 + M * 0.50;
  c = (a - b) / 180.0 * pi;
  ans = sqrt(A * A + B * B - 2 * A * B * cos(c));
  
  
    cout << fixed << setprecision(20) << ans << endl;
 
  
}

Measured memory_bytes: 4196
#include <iostream>
#include <cstdio>
#include <vector>
#include <cmath>
#include <cstring>
#include <numeric>
#include <algorithm>
#include <functional>
#include <array>
#include <map>
#include <queue>
#include <limits.h>
#include <set>
#include <bitset>
#include <stack>
#include <cstdlib>
#define REP(i,n) for(int i = 0; n > i; i++)
#define MOD 1000000007
using namespace std;
typedef vector<int> Ivec;
typedef pair<int, int> pii;
typedef long long int ll;
const pii four_Dir[4] = { //?????????
	{ -1 ,0 },{ 0 ,1 },{ 1 ,0 },{ 0 ,-1 }
};

int main() {
	int n;
	while (scanf("%d", &n)) {
		if (!n)
			return 0;
		int left = 0, right = 0, up = 0, down = 0;
		map<int, pii> block;
		block[0] = { 0,0 };
		REP(i, n-1) {
			int a, b;
			scanf("%d %d", &a, &b);

			block[i + 1] = { block[a].first + four_Dir[b].first, block[a].second + four_Dir[b].second };
			left = min(block[i+1].first, left);
			right = max(block[i + 1].first, right);
			up = min(block[i + 1].second, up);
			down = max(block[i + 1].second, down);
		}
		printf("%d %d\n", right - left+1, down - up +1);
	}

	return 0;
}

Measured memory_bytes: 3216
def primes(n):
    n, correction = n-n%6+6, 2-(n%6>1)
    sieve = [True] * (n//3)
    for i in range(1, int(n**0.5)//3+1):
        if sieve[i]:
            k = 3*i+1|1
            sieve[k*k//3::2*k] = [False] * ((n//6-k*k//6-1)//k+1)
            sieve[k*(k-2*(i&1)+4)//3::2*k] = [False] * ((n//6-k*(k-2*(i&1)+4)//6-1)//k+1)
    return [2, 3] + [3*i+1|1 for i in range(1, n//3-correction) if sieve[i]]
from collections import defaultdict

n=int(input())
primelist=primes(int(n**0.5+1))+[n+1]
factors=defaultdict(lambda :0)
for prime in primelist:
    if prime>n:
        factors[n]+=1
        break
    while n%prime==0:
        n=n//prime
        factors[prime]+=1
factors[n]=1

ans=0
for i in factors:
    if i!=1:
        f=factors[i]
        for j in range(1,50):
            f-=j
            if f<0:
                break
            ans+=1
print(ans)

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

typedef long long ll;

const int N=101, V=1e5+66;

int vv[N];ll ww[N];
ll dp[N][V];

ll f(int i,int v){
    if(v<=0)return 0;
    if(i==-1)return INT_MAX;
    ll &res=dp[i][v];
    if(res!=-1)return res;
    res=min(
            f(i-1, v-vv[i])+ww[i],
            f(i-1, v)
    );
    return res;
}

int main(){
    memset(dp, -1, sizeof dp);
    int n;ll w;scanf("%d%lld",&n,&w);
    for(int i=0;i<n;i++)
        scanf("%lld%d",&ww[i],&vv[i]);
    for(int i=V-1;i>=0;i--)
    if(f(n-1, i)<=w){
        printf("%d\n", i);
        exit(0);
    }
}


Measured memory_bytes: 79232
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
using PII = pair<int, int>;
#define FI(i,a,b) for(int i=(a);i<=(b);++i)
#define FD(i,b,a) for(int i=(b);i>=(a);--i)
#define DEBUG(x) cerr << #x << ": " << (x) << endl;
constexpr LL inv(LL x, LL m) { return x > m ? inv(x % m, m) : x > 1 ? inv(m % x, m) * (m - m / x) % m : x; }
constexpr LL mpow(LL a, LL k, LL m) { LL r(1); for (a %= m; k; k >>= 1, a = a * a % m) if (k & 1)r = r * a % m; return r; }

const int N = 405;
char S[N][N];
int h, w, Color[N * N], Vis[N * N], cnta, cntb;
vector<int> G[N * N];
void dfs(int u) {
    Vis[u] = 1;
    if (Color[u]) cnta++;
    else cntb++;
    for (auto v : G[u]) {
        if (!Vis[v]) dfs(v);
    }
}

int main() {
    cin >> h >> w;
    FI(i, 1, h) scanf("%s", S[i] + 1);
    int dx[4] = {-1, 0, 1, 0}, dy[4] = {0, -1, 0, 1};
    FI(i, 1, h) FI(j, 1, w) {
        int idx = w * (i - 1) + j;
        Color[idx] = S[i][j] == '.';
        FI(k, 0, 3) {
            int ni = i + dx[k], nj = j + dy[k];
            if (ni < 1 || ni > h || nj < 1 || nj > w) continue;
            int nidx = w * (ni - 1) + nj;
            if (S[i][j] != S[ni][nj]) {
                G[idx].push_back(nidx);
                G[nidx].push_back(idx);
            }
        }
    }
    LL ans = 0;
    FI(i, 1, h * w) {
        if (!Vis[i]) cnta = cntb = 0, dfs(i), ans += 1LL * cnta * cntb;
    }
    cout << ans << endl;
}


Measured memory_bytes: 18048
use proconio::{fastout, input};
use std::cmp::min;
use std::collections::BinaryHeap;

const M: u64 = 0xffffffffffffffff;

#[derive(Debug)]
struct Node {
    t: u64,
    c: usize,
    d: usize,
    n: Vec<(usize, usize, usize)>,
    s: Vec<u64>,
}

#[fastout]
fn main() {
    input! {
    in_n: u64, in_m: u64, in_s: usize,
    in_ns: [[usize; 4]; in_m], in_cs: [[usize; 2]; in_n]};
    let mut nodes = Vec::new();
    let size = (in_n * 50 + 1) as usize;

    for in_c in &in_cs {
        nodes.push(Node {
            t: M,
            c: in_c[0],
            d: in_c[1],
            n: vec![],
            s: vec![M; size],
        });
    }

    for in_n in &in_ns {
        nodes[in_n[0] - 1].n.push((in_n[1] - 1, in_n[2], in_n[3]));
        nodes[in_n[1] - 1].n.push((in_n[0] - 1, in_n[2], in_n[3]));
    }

    let mut queue = BinaryHeap::new();

    if in_s < size {
        queue.push((M, 0 as u64, 0, in_s));
    } else {
        queue.push((M, 0, 0, size - 1));
    }

    while !queue.is_empty() {
        let (_, t, i, s) = queue.pop().unwrap();

        if nodes[i].s[s] <= t {
            continue;
        }

        nodes[i].t = min(t, nodes[i].t);
        nodes[i].s[s] = t;

        if s + nodes[i].c < nodes[i].s.len() {
            let nt = t + nodes[i].d as u64;

            queue.push((M - nt, nt, i, s + nodes[i].c));
        }

        for n in &nodes[i].n {
            let (ni, rs, rt) = *n;
            let nt = t + rt as u64;

            if rs > s {
                continue;
            }

            queue.push((M - nt, nt, ni, s - rs));
        }
    }

    for n in nodes[1..].iter() {
        println!("{}", n.t);
    }
}


Measured memory_bytes: 11156
#include <bits/stdc++.h>
using namespace std;
#define oo 2000000000
const int N = 100010;
int n , m , arr[N];

int main(){
 	//freopen("in.txt","r",stdin);
	int a, b, c, d , n;
	scanf("%d%d%d%d",&a,&b,&c,&d);
	scanf("%d",&n);
	if(a * 2 < b)
		b = a * 2;
	if(b * 2 < c)
		c = b * 2;
	if(c * 2 < d)
		d = c * 2;
	int f = n / 2;
	long long ans = (long long)f * (long long)d;
	if(n % 2)
		ans+=c;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python

import sys
import math
import itertools as it
from collections import deque

sys.setrecursionlimit(10000000)

while True:
    S = raw_input()
    if S == '#':
        break
    S = list(S)
    for i in range(len(S)):
        if S[i] in ['y', 'u', 'i', 'o', 'p', 'h', 'j', 'k', 'l', 'n', 'm']:
            S[i] = 1
        else:
            S[i] = 0
    ans = 0
    for i in range(len(S) - 1):
        if S[i] != S[i + 1]:
            ans += 1
    print ans


Measured memory_bytes: 5024
import java.io.BufferedWriter;
import java.io.OutputStreamWriter;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
 
public class Main {
    public static void main(String[] args) {
        FastReader reader = new FastReader();
        BufferedWriter log = new BufferedWriter(new OutputStreamWriter(System.out));
        try {
            String s = reader.nextLine();
            if (s.equals("ARC")) {
                log.write("ABC");
            } else {
                log.write("ARC");
            }
            log.flush();
            log.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
  	static class FastReader {
    BufferedReader br;
    StringTokenizer st;
 
    public FastReader() {
        br = new BufferedReader(new InputStreamReader(System.in));
    }
 
    public String next() {
        while (st == null || !st.hasMoreElements()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        return st.nextToken();
    }
 
    public int nextInt() {
        return Integer.parseInt(next());
    }
 
    public long nextLong() {
        return Long.parseLong(next());
    }
 
    public String nextLine() {
        String str = "";
        try {
            str = br.readLine();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return str;
    }
}
}

Measured memory_bytes: 25324
#include<iostream>	// 入出力
#include<math.h>	// 数学の関数
#include<vector>	// 配列
#include<string>	// 文字列
#include<map>		// 連想配列
#include<stack>		// スタック
#include<queue>		// キュー
#include<algorithm> // ソートとか


using namespace std;


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


	vector<int> num(N, 0);


	for (int i = 0; i < M; ++i) {
		int a, b;
		cin >> a >> b;
		++num[a - 1];
		++num[b - 1];
	}


	for (int i = 0; i < N; ++i) {
		cout << num[i] << endl;
	}


	return 0;
}

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

int main() {

    long A; //Aピザ 値段
    long B; //Bピザ 値段
    long C; //ハーフピザ 値段

    long X; //Aピザ 必要枚数
    long Y; //Bピザ 必要枚数

    // long x = 0;  //a枚数
    // long y = 0;  //b枚数
    // long z = 0; //ab枚数

    long goukei = 0;
    // 最小値を求める
    // (A * a_mai) + (B * b_mai) + (C * ab_mai) = goukei

    cin >> A >> B >> C >> X >> Y;

    // ハーフビザ2枚 = Aを1枚 + Bを1枚
    // 2C = A + B

    long saishou_mai = min(X, Y);
    long a_tarinai = 0;
    long b_tarinai = 0;
    long sa = X - Y;

    if (sa >= 0){
        a_tarinai = sa;
    }
    else{
        b_tarinai = abs(sa);
    }

    // 単体の方が安いパターン
    if ((2 * C) >= (A + B)){

        goukei = (A * saishou_mai) + (B * saishou_mai) + (A * a_tarinai) + (B * b_tarinai);
    }
    // ハーフの方が安いパターン
    else if ((2 * C) < (A + B)){

        //goukei = (2 * C * saishou_mai)+ (A * a_tarinai) + (B * b_tarinai);

        // A足りない
        if (sa >= 0){

            if ((A * a_tarinai) >= (2 * C * a_tarinai)){
                goukei = (2 * C * saishou_mai) + (2 * C * a_tarinai);
            }
            else {
                goukei = (2 * C * saishou_mai) + (A * a_tarinai);
            }

        }
        // Bが足りない
        else{

            if ((B * b_tarinai) >= (2 * C * b_tarinai)){
                goukei = (2 * C * saishou_mai) + (2 * C * b_tarinai);
            }
            else {
                goukei = (2 * C * saishou_mai) + (B * b_tarinai);
            }
        }
    }

    cout << goukei << endl;


    return 0;

}

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

using namespace std;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  vector<vector<int>> c(3, vector<int>(3));
  for (int i = 0; i < 3; ++i) {
    for (int j = 0; j < 3; ++j) {
      cin >> c[i][j];
    }
  }
  for (int i = 0; i < 2; ++i) {
    for (int j = 0; j < 2; ++j) {
      if (c[i][j] - c[i][j+1] != c[i+1][j] - c[i+1][j+1] ||
          c[i][j] - c[i+1][j] != c[i][j+1] - c[i+1][j+1]
      ) {
        cout << "No\n";
        return 0;
      }
    }
  }
  cout << "Yes\n";
}


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


int main() {

    int n;
    cin >> n;
    vector<int> a(100005, 0);
    for (int i = 0; i < n; ++i) {
        int num; cin >> num;
        a[num]++;
    }
    int mx = 0;
    for(int i = 1; i < 100005; ++i) {
        mx = max(a[i-1]+a[i]+a[i+1], mx);
    }
    cout << mx << endl;
    return 0;
}

Measured memory_bytes: 768
#include <iostream>
#include <numeric>
#include <cmath>
#include <limits>
#include <stdio.h>
#include <iomanip>
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
using namespace std;
using ll = long long;
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)
ll Max(ll(a), ll(b), ll(c)) {
	return max(max(a, b), c);
}
ll Min(ll(a), ll(b), ll(c)) {
	return min(min(a, b), c);
}
ll gcd(ll(a), ll(b)) {
	ll c = a;
	while (a % b != 0) {
		c = a % b;
		a = b;
		b = c;
	}
	return b;
}



int main() {

	ll N,an=9999999;
	cin >> N;
	rep(i, N) {
		ll A,k=0;
		cin >> A;
		while (A % 2 == 0) {
			A /= 2;
			k++;
		}
		an = min(an, k);
	}
	cout << an << endl;
}


Measured memory_bytes: 256
import java.util.LinkedList;
import java.util.List;
import java.util.Scanner;

public class Main{
	public static void main(String[] args) {

		Scanner scanner = new Scanner(System.in);

		String[] tmp = scanner.nextLine().split(" ");
		int n = Integer.parseInt(tmp[0]);
		int k = Integer.parseInt(tmp[1]);
		List<Character> list = new LinkedList<Character>();

		while(n > 0) {

			list.add((char) (n % k));
			n /= k;

		}



		System.out.println(list.size());

	}
}

Measured memory_bytes: 35704
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
using namespace std;
using bint = boost::multiprecision::cpp_int;
using ll = long long;
using pint = pair<int, int>;
using pll = pair<ll, ll>;
#define rep(i,n) for (int i = 0; i < (n); i++)
#define repSE(i,s,n) for (int i = (s); i < (n); i++)
#define rrepSE(i,s,e) for (int i = (s); i > (e); i--)
#define ssort(v) sort(v.begin(), v.end())
#define gsort(v) sort(v.rbegin(), v.rend())
template<typename T> istream &operator>>(istream &is, vector<T> &vec){ for (auto &v : vec) is >> v; return is; }
template<typename T> ostream &operator<<(ostream &os, const vector<T> &vec){ os << "["; for (auto v : vec) os << v << ","; os << "]"; return os; }
template<typename T> ostream &operator<<(ostream &os, const deque<T> &vec){ os << "deq["; for (auto v : vec) os << v << ","; os << "]"; return os; }
template<typename T> ostream &operator<<(ostream &os, const set<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const unordered_set<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const multiset<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const unordered_multiset<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &pa){ os << "(" << pa.first << "," << pa.second << ")"; return os; }
template<typename TK, typename TV> ostream &operator<<(ostream &os, const map<TK, TV> &mp){ os << "{"; for (auto v : mp) os << v.first << "=>" << v.second << ","; os << "}"; return os; }
template<typename TK, typename TV> ostream &operator<<(ostream &os, const unordered_map<TK, TV> &mp){ os << "{"; for (auto v : mp) os << v.first << "=>" << v.second << ","; os << "}"; return os; }
template<typename T> bool chmax(T &m, const T q) { if (m < q) {m = q; return true;} else return false; }
template<typename T> bool chmin(T &m, const T q) { if (q < m) {m = q; return true;} else return false; }
#define DEBUG_PRINT(var) std::cout << #var << " = " << var << "\n";

ll n;

deque<ll> num2digs(ll n) {
    deque<ll> digs;
    while (n) {
        digs.push_front(n%10);
        n = n / 10;
    }
    return digs;
}

bool check753(deque<ll> arr) {
    bool has3 = false, has5 = false, has7 = false;
    for (auto ele : arr) {
        if (ele == 3) has3 = true;
        else if (ele == 5) has5 = true;
        else if (ele == 7) has7 = true;
    }
    return has3 && has5 && has7;
}

int dfs(ll num) {
    if (num > n) return 0;
    int ret = check753(num2digs(num)) ? 1: 0;
    ret += dfs(num * 10 + 3);
    ret += dfs(num * 10 + 5);
    ret += dfs(num * 10 + 7);
    return ret;
}

int main()
{
    cin >> n;
    int ans = dfs(0);
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
long long N,A[100002],B[100001];
int main() {
	cin>>N;
	for(int i=1;i<=N+1;i++)cin>>A[i];
	for(int i=1;i<=N;i++)cin>>B[i];
	long long c=0;
	for(int i=1;i<=N;i++){
		if(B[i]<=A[i]){c+=B[i];A[i]-=B[i];B[i]=0;}
		else{c+=A[i];B[i]-=A[i];A[i]=0;
		   if(B[i]<=A[i+1]){c+=B[i];A[i+1]-=B[i];B[i]=0;}
		   else{c+=A[i+1];B[i]-=A[i+1];A[i+1]=0;}
		}
	}
	cout<<c;
	return 0;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
#define ll                long long int
#define ld                long double
#define pb                push_back
#define pf                push_front
#define ppb               pop_back
#define ppf               pop_front
#define sz                size()
#define pi                acos(-1.0)
#define mod               1000000007
#define F                 first
#define S                 second
#define C                 continue
#define G                 goto done
#define maxe              max_element
#define mine              min_element
#define min3(a,b,c)       min(a,min(b,c))
#define max3(a,b,c)       max(a,max(b,c))
#define min4(a,b,c,d)     min(a,min(b,min(c,d)))
#define max4(a,b,c,d)     max(a,max(b,max(c,d)))
#define mem(a,b)          memset(a,b,sizeof(a))
#define all(a)            (a).begin(),(a).end()
#define gcd(a,b)          __gcd(a,b)
#define lcm(a,b)          ((a)*((b)/gcd(a,b)))
#define case(a)           cout<<"Case "<<(a)<<": "
#define point(a)          fixed<<setprecision(a)
#define get(a)            for(auto &x:a) cin>>x
#define print(a)          for(auto x:a) cout<<x<<" "; cout<<endl
#define see(x)            cout<<#x<<" = "<<x<<endl
#define uniq(a)           sort(all(a)); (a).erase(unique((a).begin(),(a).end()),(a).end())
#define big(a)            transform((a).begin(),(a).end(),(a).begin(),::toupper)
#define small(a)          transform((a).begin(),(a).end(),(a).begin(),::tolower)
#define ischar(a)         (('a'<=a&&a<='z')('A'<=a&&a<='Z'))
#define isvowel(a)        (a=='a'||a=='e'||a=='i'||a=='o'||a=='u'||a=='A'||a=='E'||a=='I'||a=='O'||a=='U')
#define fast              ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define tc                int test; cin>>test; while(test--)
using namespace std;
int main()
{
    ll n; cin>>n;
    ll d[n+1];
    ll f[n+1];
    ll b[n+1]; mem(b,0);
    for(ll i=1;i<=n;i++) cin>>d[i];
    for(ll i=1;i<=n;i++) cin>>f[i];
    for(ll i=1;i<n;i++) cin>>b[i];
    ll s=f[d[1]];
    for(ll i=2;i<=n;i++)
    {
        s+=f[d[i]];
        if( d[i] == d[i-1]+1 )
        {
            s+=b[d[i-1]];
        }
    }
    cout<<s;
}




















Measured memory_bytes: 3556
import decimal
import sys
sys.setrecursionlimit(10**9)

def main():
    A,B=input().split()
    ab = decimal.Decimal(A)*decimal.Decimal(B)
    print(ab.quantize(decimal.Decimal('0'), rounding=decimal.ROUND_FLOOR))




if __name__ == "__main__":
  main()

Measured memory_bytes: 9936
use std::io::prelude::*;

fn input<T>() -> T
where
    T: std::str::FromStr,
{
    let stdin = std::io::stdin();
    let token = stdin
        .lock()
        .bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect::<String>();
    token.parse().ok().unwrap()
}

fn main() {
    let n: usize = input();
    let c: i64 = input();
    let mut x = vec![0i64; n + 2];
    let mut v = vec![0i64; n + 2];
    for i in 1..n + 1 {
        x[i] = input();
        v[i] = input();
    }
    x[n + 1] = c;

    let mut sum_l = vec![0i64; n + 2];
    let mut sum_r = vec![0i64; n + 2];
    let mut temp_l = 0;
    let mut temp_r = 0;
    for i in 1..n + 1 {
        temp_l += v[i] - (x[i] - x[i - 1]);
        sum_l[i] = std::cmp::max(sum_l[i - 1], temp_l);
        temp_r += v[n - i + 1] - (x[n - i + 2] - x[n - i + 1]);
        sum_r[n - i + 1] = std::cmp::max(sum_r[n - i + 2], temp_r);
    }

    let mut ans = 0;
    for i in 0..n + 1 {
        ans = std::cmp::max(ans, sum_l[i] - x[i] + sum_r[i + 1]);
        ans = std::cmp::max(ans, sum_r[i + 1] - (c - x[i + 1]) + sum_l[i]);
    }
    println!("{}", ans);
}


Measured memory_bytes: 8444
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rrep(i, n) for (int i = (n - 1); i >= 0; i--)
#define ALL(v) v.begin(), v.end()
using namespace std;
using P = pair<int, int>;
typedef long long ll;

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  rep(i, n) cin >> a[i];
  ll ans = 10000000000000000;
  for (int bit = 0; bit < (1 << n); bit++){
    int mx = 0;
    int ok = 0;
    ll cost = 0;
    vector<int> tmp = a;
    rep(i, n) {
      if(bit & (1 << i)){
        if(tmp[i] > mx){
          mx = tmp[i];
        }else{
          cost += (mx + 1) - a[i];
          mx++;
          tmp[i] = mx;
        }
      }else{
        if(a[i] > mx)mx = a[i];
      }
    }
    mx = 0;
    rep(i, n) {
      if(tmp[i] > mx){
        ok++;
        mx = tmp[i];
      }
    }
    if(ok >= k)ans = min(ans, cost);
  }
  cout << ans << endl;
}

Measured memory_bytes: 3540
rate = int(input())
if 400 <= rate < 600:
  print("8")
elif 600 <= rate <800:
  print("7")
elif 800 <= rate <1000:
  print("6")
elif 1000 <= rate <1200:
  print("5")
elif 1200 <= rate <1400:
  print("4")
elif 1400 <= rate <1600:
  print("3")
elif 1600 <= rate <1800:
  print("2")
elif 1800 <= rate <2000:
  print("1")


Measured memory_bytes: 9160
import heapq
from collections import deque
from enum import Enum
import sys
import math
from _heapq import heappush, heappop
import copy
from test.support import _MemoryWatchdog

BIG_NUM = 2000000000
HUGE_NUM = 99999999999999999
MOD = 1000000007
EPS = 0.000000001
sys.setrecursionlimit(100000)


num_item,W = map(int,input().split())

dp = [-BIG_NUM]*(W+1)
dp[0] = 0

for _ in range(num_item):
    value,weight = map(int,input().split())
    for i in range(W,weight-1,-1):
        if dp[i-weight] == -BIG_NUM:
            continue
        dp[i] = max(dp[i],dp[i-weight]+value)

ans = 0
for i in range(W+1):
    ans = max(ans,dp[i])

print("%d"%(ans))



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

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

int main(void){
  SPEEDUP
  cout << setprecision(15);
  int N;cin >> N;
  cout << "ABC" << N << endl;
  return 0;
}


Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func main() {
	n := getInt()
	d := getInt()

	x := 2*d + 1

	ans := (n + x - 1) / x
	fmt.Println(ans)
}

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

var scanner = wordScanner()

func wordScanner() *bufio.Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	return sc
}

func getInt() int {
	scanner.Scan()
	i, err := strconv.Atoi(scanner.Text())
	if err != nil {
		panic(err)
	}
	return i
}

func getIntSlice(n int) []int {
	is := make([]int, n)
	for i := range is {
		is[i] = getInt()
	}
	return is
}

func getString() string {
	scanner.Scan()
	s := scanner.Text()
	return s
}


Measured memory_bytes: 640
#include<iostream>
using namespace std;
int main(){
	int n;
	string s;
	cin>>n>>s;
	int cnt=0;
	for(int i=0;i<=s.size()-3;++i)
		if(s[i]=='A'&&s[i+1]=='B'&&s[i+2]=='C')
			++cnt;
	cout<<cnt<<endl;
	return 0;
}

Measured memory_bytes: 256
def main():
    N, K = map(int, input().split())
    V = list(map(int, input().split()))
    ans = 0
    for l in range(K + 1):
        for r in range(K - l + 1):
            if l + r > N:
                continue
            d = K - l - r
            s = V[:l] + V[N - r:N]
            now = 0
            now += sum(s)
            s.sort()
            for i in range(d):
                if i >= len(s):
                    break
                if s[i] > 0:
                    break
                now -= s[i]
            ans = max(ans, now)
    print(ans)


main()


Measured memory_bytes: 3064
#include <algorithm>
#include <bits/stdc++.h>
#include <bitset>
#include <cassert>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <cmath>
#include <memory>
#include <queue>
#include <set>
#include <stack>
#include <utility>
#include <vector>
using namespace std;
#define REP(i, n) for (int64_t i = 0; i < (int64_t)n; i++)
#define REP_FOR(i, a, b) for (int64_t i = (int64_t)a; i < (int64_t)b; i++)
#define REP_REV(i, a, b) for (int64_t i = (int64_t)a; i > (int64_t)b; i--)
#define FORALL(v) (v).begin(), (v).end()
#define mp(a, b) make_pair(a, b)
#define eb(x) emplace_back(x)
#define F first
#define S second
typedef long long ll;
typedef long double ld;
typedef pair<int64_t, int64_t> pii;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pdd;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<int64_t> vii;
typedef vector<vii> vvii;
const ll mod = 1e9 + 7;
const int64_t infi = 1147483600;
const ll infl = 4e18 + 5;
const char EOL = '\n';
const ll MOD = 998244353;

int main() {
    ll N;
    cin >> N;
    vector<ll> X(N);
    for (auto & x : X) {
        cin >> x;
    }
    ll res = 1e10;
    for (ll p = 1; p <= 100; ++p) {
        ll cost = 0;
        for (auto & x : X) {
            cost += (x - p) * (x - p);
        }
        res = min(res, cost);
    }
    cout << res << endl;
}


Measured memory_bytes: 256
n,m=map(int,input().split())
h=list(map(int,input().split()))
a=[list(map(int, input().split())) for i in range(m)]

b=[0]*n

for i in range(m):
  if h[a[i][0]-1] < h[a[i][1]-1]:
    b[a[i][0]-1]+=1
  elif h[a[i][0]-1]==h[a[i][1]-1]:
    b[a[i][0]-1]+=1
    b[a[i][1]-1]+=1
  else:
    b[a[i][1]-1]+=1
d=b.count(0)
print(d)

Measured memory_bytes: 96608
#include<bits/stdc++.h>
#define F first
#define S second
using namespace std;
typedef pair<int,string> P;
main(){
  int n;
  string goal="111111111222444666555333333333";
  cin>>n;
  for(int i=0;i<n;i++){
    map<string,int> check;
    string start;
    string s;
    for(int j=0;j<30;j++){
      cin>>s;
      start+=s;
    }
    if(start==goal){
      cout<<'0'<<endl;
    }
    else{
      queue<P> que;
      int mins=10;
      que.push(P(0,start));
      while(!que.empty()){
	int size;
	size=que.size();
	for(int j=0;j<size;j++){
	  P p=que.front();
	  que.pop();
	  for(int k=0;k<4;k++){
	    string now=p.S;
	    switch(k){
	    case 0:
	      swap(now[0],now[27]);
	      swap(now[1],now[28]);
	      swap(now[2],now[29]);
	      swap(now[14],now[15]);
	      swap(now[18],now[20]);
	      break;
	    case 1:
	      swap(now[6],now[21]);
	      swap(now[7],now[22]);
	      swap(now[8],now[23]);
	      swap(now[17],now[12]);
	      swap(now[9],now[11]);
	      break;
	    case 2:
	      swap(now[0],now[23]);
	      swap(now[3],now[26]);
	      swap(now[6],now[29]);
	      swap(now[9],now[20]);
	      swap(now[15],now[17]);
	      break;
	    case 3:
	      swap(now[2],now[21]);
	      swap(now[5],now[24]);
	      swap(now[8],now[27]);
	      swap(now[11],now[18]);
	      swap(now[12],now[14]);
	      break;
	    }
	    if(now==goal){
	      mins=min(mins,p.F+1);
	    }
	    if(check[now]==0){
	      que.push(P(p.F+1,now));
	    }
	    check[now]=p.F+1;
	  }
	}
      }
      cout<<mins<<endl;
    }
  }
}
  

Measured memory_bytes: 1276
#include <stdio.h>
#include <math.h>
#include <stdlib.h>

int compare_int(const void* a, const void* b)
{
	return *(int*)b - *(int*)a;
}

int main() {
	int x, n, p[110],ans=1000,t=0,as;
	scanf("%d%d", &x, &n);
	for (int i = 0; i < n; i++) {
		scanf("%d", &p[i]);
	}
	qsort(p, n, sizeof(int), compare_int);

	for (int i = 101; i >= 0; i--) {
		if (i == p[t]) {
			t++;
			continue;
		}
		if (abs(i - x) <= ans) {
			as = i;
			ans = abs(i - x);
		}
	}
	printf("%d", as);
	return 0;
}

Measured memory_bytes: 1732
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N=5010;
int h[N],e[N],ne[N],idx;
int p[N],c[N],num[N],res,root;
LL d[N][N],w[N];
bool st[N];
void add(int a,int b,int c)
{
    e[idx]=b,w[idx]=c,ne[idx]=h[a],h[a]=idx++;
}
void dfs(int u,int step)
{
    res=max(res,step);
    for(int i=h[u];i!=-1;i=ne[i])
    {
        int j=e[i];
        if(st[j]) continue;
        st[j]=true;
        d[root][step+1]=d[root][step]+w[i];
        dfs(j,step+1);
    }
}
int main()
{
    int n,k;
    cin>>n>>k;
    memset(h,-1,sizeof h);
    for(int i=1;i<=n;i++)
        cin>>p[i];
    for(int i=1;i<=n;i++)
        cin>>c[i];
    for(int i=1;i<=n;i++)
        add(i,p[i],c[p[i]]);
    for(int i=1;i<=n;i++)
    {
        memset(st,false,sizeof st);
        memset(d[i],0,sizeof d[i]);
        res=0,root=i;
        dfs(i,0);
        num[i]=res;
    }
    LL ans=-1e18;
    for(int i=1;i<=n;i++)
    {
        LL x=k/num[i],y=k%num[i];
        LL sum=-1e18,res=-1e18;
        for(int j=1;j<=num[i]&&j<=k;j++)
        {
            ans=max(ans,d[i][j]);
            res=max(res,d[i][j]);
            if(j<=y) sum=max(sum,d[i][j]);
        }
        if(d[i][num[i]]>0)
        {
            ans=max(ans,x*d[i][num[i]]+sum);
            if(x>1)
                ans=max(ans,(x-1)*d[i][num[i]]+res);
        }
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 199868