akhauriyash/Code-Regression huggingface dataset:
h,w = map(int,input().split())
a = []
yoko = [False]*h
tate = [False]*w
for i in range(h):
    s = input()
    a.append(s)
cnt = 0
for i in range(h):
    state = False
    cnt = 0
    for j in range(w):
        if a[i][j] == ".":
            cnt += 1
    if cnt == w:
        yoko[i] = True
cnt = 0
for i in range(w):
    state = False
    cnt = 0
    for j in range(h):
        if a[j][i] == ".":
            cnt += 1
    if cnt == h:
        tate[i] = True

for i in range(h):
    if yoko[i] == True:
        continue
    else:
        ans = ""
        for j in range(w):
            if tate[j] == True:
                continue
            else:
                ans += a[i][j]
        print(ans) 


Measured memory_bytes: 3064
a_e = [int(input()) for i in range(5)]
k = int(input())
new_a_e = a_e.copy()
res = False
for i in range(len(a_e)):
    for j in range(len(new_a_e)):
        if i == j:
            del new_a_e[j]
        else:
            dis = abs(a_e[i]-a_e[j])
            if dis>k:
                print(':(')
                res = True
                break
    if res==True:
        break
if res==False:
    print('Yay!')


Measured memory_bytes: 3060
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = uint32_t;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

int main() {
    int h, w, n;
    cin >> h >> w >> n;
    int a, b; string s, t;
    cin >> a >> b >> s >> t;
    string X = "LRUD";
    int dx[] {-1, 1, 0, 0}, dy[] {0, 0, -1, 1};
    auto in = [&](int yy, int xx){
        return 1 <= yy && yy <= h && 1 <= xx && xx <= w;
    };
    for (int i = 0; i < 4; ++i) {
        char taka = X[i], ao = X[i^1];
        int p = a, q = b;
        for (int j = 0; j < n; ++j) {
            if(s[j] == taka){
                p += dy[i], q += dx[i];
            }
            if(!in(p, q)){
                puts("NO");
                return 0;
            }
            if(t[j] == ao && in(p+dy[i^1], q+dx[i^1])){
                p += dy[i^1], q += dx[i^1];
            }
        }
    }
    puts("YES");
    return 0;
}

Measured memory_bytes: 776
#include<bits/stdc++.h>
using namespace std;
const int N=5; 
int read(){
	int f=1,s=0;char c=getchar();
	for(;c<'0'||c>'9';c=getchar())if(c=='0')f=-1;
	for(;c>='0'&&c<='9';c=getchar())s=s*10+c-48;
	return f*s; 
}
const int oo=0x3f3f3f3f;
map<int,int>a;
bool work(){
	int n=read();
    for(int i=1;i<=n;i++)
    	a[read()]++;
    if(a.size()>2)return false;
	int m=a.begin()->first;
    if(a.size()==1){    	
    	if(m==n-1||m+m<=n)return true;
    	else return false;
	}
	if(a.rbegin()->first-a.begin()->first>1)return false;
	if(a.begin()->second<=m&&(m+1-a.begin()->second)*2<=n-a.begin()->second)return true;
	else return false;
}
int main(){
    if(work())printf("Yes");
    else printf("No");
    return 0;
}


Measured memory_bytes: 4992
n, m = map(int, input().split())
shop = []

for _ in range(n):
    yen, num = map(int, input().split())
    shop.append([yen, num])

shop.sort()

ans = 0
for yen, num in shop:
    if num < m:
        ans += yen*num
        m -= num
    else:
        ans += yen*m
        break

print(ans)


Measured memory_bytes: 20056
#include<bits/stdc++.h>
using namespace std;
int main(){
  long long n,h,sum,nmax=0,cnt=0;
  long long a,b[100009];
  cin>>n>>h;
  for(int i=0;i<n;i++){
    cin>>a>>b[i];
    nmax=max(nmax,a);
  }
  sort(b,b+n);
  reverse(b,b+n);
  for(int i=0;i<=n;i++){
    if(n!=i&&b[i]>=h||nmax>=h){
      cout<<cnt+1<<endl;
      break;
    }
    else if(b[i]<=nmax||n==i){
      long long ans=h/nmax;
      if(h%nmax!=0)ans++;
      cout<<cnt+ans<<endl;
      break;
    }
    else h-=b[i];
    cnt++;
  }

  return(0);
}
  


Measured memory_bytes: 1024
'use strict';
function main(input) {
    input = input.split("\n");
    const input1 = input[0].split(" ");
    const heights = input[1].split(" ");
    const num = input1[0], threshold = input1[1];
    
    let count = 0;
    for(let i=0; i<num; i++) {
        if(parseInt(heights[i]) < parseInt(threshold)) {
            continue;
        }
        count++;
    }

    return count;
}

var input = require("fs").readFileSync("/dev/stdin", "utf8");
console.log(main(input));

Measured memory_bytes: 18636
using System;
using System.Linq;
using System.Collections.Generic;

public class Program{
    public static void Main(){
        var nm = Console.ReadLine().Split().Select(int.Parse).ToArray();
        int n = nm[0], m = nm[1];
        var ans = (n-1)*(m-1);
        Console.WriteLine(ans);
    }
}


Measured memory_bytes: 13268
n, m = map(int, input().split())

ans = 0
flag = [0] * n

for _ in range(m):
    P, s = input().split(' ')
    p = int(P) - 1
    if s == 'AC':
        if flag[p] != -1:
            ans += flag[p]
            flag[p] = -1
    elif flag[p] != -1:
        flag[p] += 1

print(flag.count(-1), ans)

Measured memory_bytes: 3828
#include<iostream>
#include<string>
#include<iomanip>
using namespace std;
int main(){
	double r;
	cin>>r;
	cout<<fixed<<setprecision(10)<<r*r*3.14159265358979<<endl;
	cout<<fixed<<setprecision(10)<<r*2*3.14159265358979<<endl;
	return 0;
}

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

using namespace std;





// int main_old()
// {
// int N;



// cin >> N;

// vector<string> S(N);


// cin >>S[0];






// for(int i = 1;i<N;i++){

//     string k;

//     cin >>k;


//     int count =0;





//     for(int j =0;j<S.size();j++){


//         if (S[j] == k){

//             count =1;
//             break;

//         }

        
//     }

//     if(count ==0){

//         S.push_back(k);
    

//     }
    

// }


// cout << S.size()<< endl;









// return 0;

// }


int main()
{
int N;



cin >> N;

set<string> S;







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

    string k;

    cin >>k;


    int count =0;
    
    
    S.insert(k);
    

    

}


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









return 0;

}




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

using namespace std;

#define int long long
#define endl '\n'
#define MOD 1000000007
#define maxn 100010

int f[11];

double dist(pair<int, int> a, pair<int, int> b) {
    return sqrt((a.first - b.first) * (a.first - b.first) + (a.second - b.second) * (a.second - b.second));
}

int32_t main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int n;
    cin >> n;

    f[0] = 1;
    for (int i = 1; i <= 10; i++)
        f[i] = i * f[i - 1];
    vector<pair<int, int>> v(n);
    for (int i = 0; i < n; ++i) {
        cin >> v[i].first >> v[i].second;
    }

    vector<int> vx(n);
    double ans = 0;
    iota(vx.begin(), vx.end(), 0);
    do {
        for (int i = 1; i < n; i++) {
            ans += dist(v[vx[i]], v[vx[i - 1]]);
        }
    } while (next_permutation(vx.begin(), vx.end()));
    ans = ans / f[n];
    cout << fixed << setprecision(10) << ans << endl;
}

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

int main(){
    uint64_t n;
    cin >> n;

    int digit = 0, ans = INT_MAX;
    for (uint64_t a =1; a <= (uint64_t)sqrt((double)n); a++) {
        if (n % a) continue;
        digit = max((int)log10((double)a), (int)log10(n / (double)a)) + 1;
        if (ans > digit) ans = digit;
    }

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL)
#define ll long long
#define ld long double
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define gcd __gcd
#define pcount __builtin_popcount
#define pcountll __builtin_popcountll
#define nxtperm next_permutation
//primitive roots: 998244353 - 3; 7340033 - 5
//#pragma 03
//#pragma GCC target ("sse4.2")

const ll mod = 1000000007;		const double PI = acos(-1.);
using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>,rb_tree_tag, tree_order_statistics_node_update> ordered_set;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef complex<double> cd;

struct custom_hash
{
    static uint64_t splitmix64(uint64_t x)
	{
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const
	{
        static const uint64_t kawaii = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + kawaii);
    }
};

const int maxn = 3005; 
int n; 
double res, p[maxn], dp[maxn][maxn]; // probability of having j heads for i coins. 

signed main()
{
//	freopen("in.txt", "r", stdin); freopen("out.txt", "w", stdout);
// 	fast_cin();
	cin >> n;
	for(int i=1;i<=n;i++) cin >> p[i]; 
	dp[0][0] = 1; 
	for(int i=1;i<=n;i++)
	{
		for(int j=0;j<=n;j++)
 		{
 			if(j == 0) 
 			{
 				dp[i][0] = dp[i-1][0] * (1 - p[i]);
 				continue; 
			 }
 			dp[i][j] = p[i] * dp[i-1][j-1] + (1 - p[i]) * dp[i-1][j]; 
			if(i == n and j > n/2) res += dp[i][j]; 
		}
  	}
 	cout << setprecision(10) << fixed << res ;
}

/*
	Test input:
*/


Measured memory_bytes: 70656
#include <iostream>
#include <vector>
#include <algorithm>
/**
 Answer #1
 **/

using namespace std;

int main()
{

    //    cout << " a" << endl;
    long long X, Y, Z;
    long long K;
    long long A[1000], B[1000], C[1000];

    cin >> X >> Y >> Z >> K;
    for (int i = 0; i < X; ++i)
    {
        cin >> A[i];
    }
    sort(A, A + X, greater<long long>());

    for (int i = 0; i < Y; ++i)
    {
        cin >> B[i];
    }
    sort(B, B + Y, greater<long long>());

    for (int i = 0; i < X; ++i)
    {
        cin >> C[i];
    }

    std::vector<long long> AB(1000000);
    for (int i = 0; i < X; ++i)
    {
        for (int j = 0; j < Y; ++j)
        {
            AB[i * Y + j] = A[i] + B[j];
        }
    }

    sort(AB.begin(), AB.begin() + (X * Y), greater<long long>());

    vector<long long> ABC(3000 * 1000);
    for (int i = 0; i < K; ++i)
    {
        for (int j = 0; j < Z; ++j)
        {
            ABC[i * Z + j] = AB[i] + C[j];
        }
    }

    sort(ABC.begin(), ABC.begin() + (K * Z), greater<long long>());

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

    return 0;
}

Measured memory_bytes: 31616
//waz
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)((x).size()))
using namespace std;
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef long long int64;
typedef unsigned int uint;
typedef unsigned long long uint64;

const int MaxN = 2e5 + 10, mod = 1e9 + 7;

int n, c[MaxN], f[MaxN], g[MaxN], pre[MaxN];

int Inc(int a, int b) {
  a += b;
  return a >= mod ? a - mod : a;
}

int Dec(int a, int b) {
  a -= b;
  return a < 0 ? a + mod : a;
}

int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) {
  	scanf("%d", c + i);
  	pre[i] = g[c[i]];
  	g[c[i]] = i;
  }
  f[0] = 1;
  for (int i = 1; i <= n; ++i) {
  	f[i] = f[i - 1];
  	if (pre[i] && pre[i] != i - 1) {
  	  f[i] = Inc(f[i], f[pre[i]]);
	}
  }
  printf("%d\n", f[n]);
  return 0;
}


Measured memory_bytes: 3328
module.exports=function(r){var e={};function t(n){if(e[n])return e[n].exports;var o=e[n]={i:n,l:!1,exports:{}};return r[n].call(o.exports,o,o.exports,t),o.l=!0,o.exports}return t.m=r,t.c=e,t.d=function(r,e,n){t.o(r,e)||Object.defineProperty(r,e,{enumerable:!0,get:n})},t.r=function(r){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(r,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(r,"__esModule",{value:!0})},t.t=function(r,e){if(1&e&&(r=t(r)),8&e)return r;if(4&e&&"object"==typeof r&&r&&r.__esModule)return r;var n=Object.create(null);if(t.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:r}),2&e&&"string"!=typeof r)for(var o in r)t.d(n,o,function(e){return r[e]}.bind(null,o));return n},t.n=function(r){var e=r&&r.__esModule?function(){return r.default}:function(){return r};return t.d(e,"a",e),e},t.o=function(r,e){return Object.prototype.hasOwnProperty.call(r,e)},t.p="",t(t.s=0)}([function(r,e,t){t(1)(t(2).readFileSync("/dev/stdin","UTF-8"))},function(r,e){function t(r,e){return function(r){if(Array.isArray(r))return r}(r)||function(r,e){var t=[],n=!0,o=!1,u=void 0;try{for(var i,f=r[Symbol.iterator]();!(n=(i=f.next()).done)&&(t.push(i.value),!e||t.length!==e);n=!0);}catch(r){o=!0,u=r}finally{try{n||null==f.return||f.return()}finally{if(o)throw u}}return t}(r,e)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance")}()}r.exports=function(r){for(var e=r.split("\n"),n=t(e[0].split(" ").map(function(r){return Number(r)}),2),o=n[0],u=n[1],i=[],f=0;f<o;f++){var a=e[f+1].split(" ").map(function(r){return Number(r)});i.push(a)}for(var l=[],c=0;c<=o;c++){var p=new Array(1e5+1).fill(10000000100);p[0]=0,l.push(p)}for(var s=0;s<o;s++)for(var d=0;d<=1e5;d++){var v=l[s][d],y=v+1,b=i[s];d>=b[1]&&(y=l[s][d-b[1]]+b[0]),l[s+1][d]=Math.min(v,y)}for(var m=0,h=0;h<=1e5;h++)l[o][h]<=u&&(m=h);console.log(m)}},function(r,e){r.exports=require("fs")}]);

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

using namespace std;

#define DB( x ) cout << #x << " = " << x << endl;
#define LEFT(n) (2 * (n))
#define RIGHT(n) (2 * (n) + 1)

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> node;
//typedef vector <vector <ll>> matrix;

const ll INF = 1e16;
const double EPS = 1e-9;
const ll MOD = (ll)(1e9 + 7);
const ll MAXV = (ll)(2e5 + 10);
const ll MAXE = (ll)(1e6 + 10);


int main(){
	cin.sync_with_stdio( 0 );cin.tie( 0 );

	ll a, b;

	cin >> a >> b;

	ll curr = 1;
	ll ans = 0;

	while(curr < b){

		curr += a - 1;
		ans ++;

	}

	cout << ans << "\n";

	return 0;
}


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

int main() {
	int N;
    int A, B, C;
    cin >> A >> B >> C;

    int a[3];

    a[0] = A;
    a[1] = B;
    a[2] = C;

    sort(a, a + 3, greater<int>());

    cout << (max(A, max(B, C)) * 10 + a[1]) + min(A, min(B, C))  << endl;

}

Measured memory_bytes: 256
#include<vector>
#include<algorithm>
#include<cstdio>
#include<cstring>
using namespace std;
template<class T>
class Bit{
public:
	vector<T> a;
	Bit(int n):a(n){
	}
	T operator[](int p){
		T sm=0;
		for(;p>=0;p=(p&p+1)-1)
			sm+=a[p];
		return sm;
	}
	void update(int p,T q){
		for(;p<(int)a.size();p|=p+1)
			a[p]+=q;
	}
};
struct S{
	int a,b;
	bool operator<(const S& p)const{
		return a<p.a;
	}
};
int main(){
	int i;
	int n;
	scanf("%d",&n);
	S a[300000];
	for(i=0;i<n;++i)
		scanf("%d%d",&a[i].a,&a[i].b);
	sort(a,a+n);
	Bit<long long> b(100000);
	Bit<int> c(100000);
	int mx=0;
	for(i=0;i<n;++i){
		b.update(100000-a[i].b,a[i].a);
		c.update(100000-a[i].b,1);
		for(int p=c[c.a.size()-1];b[b.a.size()-1]>(100001-b.a.size())*p;p=c[c.a.size()-1]){
			mx=max(mx,p-1);
			b.a.pop_back();
			c.a.pop_back();
			if(!b.a.empty())
				continue;
			printf("%d\n",mx);
			return 0;	
		}
	}
	for(i=0;i<(int)c.a.size();++i)
		mx=max(mx,c[i]);
	printf("%d\n",mx);
	return 0;
}

Measured memory_bytes: 4436
package main

import (
	"fmt"
	"math"
	"sort"
)

func main() {
	var a1, a2, a3 float64
	fmt.Scan(&a1, &a2, &a3)
	
	s := make([]float64, 3)
	s[0] = math.Abs(a1 - a2)
	s[1] = math.Abs(a1 - a3)
	s[2] = math.Abs(a2 - a3)

	sort.Float64s(s)
	fmt.Println(s[0] + s[1])
}

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

using namespace std;

#define endl            "\n"
#define sz(x)          (int) (x.size())
#define all(v)          v.begin(), v.end()
#define isOdd(n)       (n&1)
#define pow(n, m)      (ll)powl(n, m)
#define clr(x, val)     memset(x, val, sizeof(x))

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef vector<int> vi;


int main()
{
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);

    int n; cin >> n;
    ll c = 0;
    for(int i = 1; i < n; i++){
        ll k = i;
        while(k < n) c++, k += i;
    }
    cout << c;
    return 0;
}


Measured memory_bytes: 3636
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
const int maxn=2e5+5;
typedef long long ll;
pair<int,int> a[maxn];
int n,t;
ll ans=0;
int main(){
	cin>>n>>t;
	int maxr=-1e9;
	for (int i=1;i<=n;i++){
		scanf("%d",&a[i].first);
		a[i].second=a[i].first+t;
	}
	for (int i=1;i<=n;i++){
		maxr=max(maxr,a[i].first);
		ans+=a[i].second-maxr;
		maxr=max(maxr,a[i].second);
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 5208
/*
title:

url:
*/

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <functional>
#include <queue>
#include <limits>
#include <string>
#include <utility>
#include <cstring>
#include <map>
#include <cmath>
#include <iterator>

using namespace std;

#define rep(i, n) for (int i = 0; i < (n); i++)
#define INF 1000000007

typedef pair<int, int> pint;
typedef long long ll;

int main()
{
    string S;
    cin >> S;
    for (int i = S.size() - 2; i >= 0; i--)
    {
        if (i % 2 == 1)
        {
            bool is_even = true;
            for (int j = 0; j < (i + 1) / 2; j++)
            {
                if (S[j] != S[(i + 1) / 2 + j])
                {
                    is_even = false;
                }
            }
            if (is_even)
            {
                cout << i + 1 << endl;
                return 0;
            }
        }
    }
    return 0;
}

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

int sa(int x,int y){
	return ((x-y)>=0 ? x-y:y-x);
}

int mymax(int x,int y){
	return (x>y?x:y);
}

int main(){
	int w,h,n;
	int aryw[1000];
	int aryh[1000];

	cin>>w>>h>>n;
	aryw[0]=aryh[0]=1;
	for(int i=0;i<n;i++){
		cin>>aryw[i]>>aryh[i];
	}

	int cntr=0;
	for(int i=0;i<n-1;i++){
		if((aryw[i]>aryw[i+1]&&aryh[i]>aryh[i+1])||(aryw[i]<aryw[i+1]&&aryh[i]<aryh[i+1]))
			cntr+=mymax(sa(aryw[i],aryw[i+1]),sa(aryh[i],aryh[i+1]));
		else
			cntr+=(sa(aryw[i],aryw[i+1])+sa(aryh[i],aryh[i+1]));
	}

	cout<<cntr<<endl;
}

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

// {U}{INT,LONG,LLONG}_{MAX,MIN}
#define ALPHABET    (26)
#define INF         INT_MAX
#define MOD         (1000000007LL)

using LL  = long long;
// }}}

int main() {
    std::ios::sync_with_stdio(false);
    int n;cin >> n;
    int f[100][10];
    int p[100][11];
    for(int i=0;i<n;i++){
        for(int j=0;j<5;j++){
            for(int k=0;k<2;k++){
                cin >> f[i][j*2+k];
            }
        }
    }
    for(int i=0;i<n;i++){
        for(int j=0;j<=10;j++){
            cin >> p[i][j];
        }
    }

    int ans = -1000000005;
    for(int i=1;i<1<<10;i++){
        int sum = 0;
        for(int j=0;j<n;j++){
            int cnt = 0;
            for(int k=0;k<10;k++){
                if(i&(1<<k)){
                    cnt += f[j][k];
                }
            }
            sum += p[j][cnt];
        }
        ans = max(ans, sum);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 384
#include<iostream>
#include<array>
#include<vector>
#include<string>

#include<queue>
#include<utility>

using namespace std;
int main(){
	
	int W, H;
	cin >> H >> W;

	char buf;
	queue<pair<int, int>> que;
	vector<array<int, 1000>> arr(H);

	int MAX = 0;

	for(int y = 0; y < H; y++){
	for(int x = 0; x < W; x++){
		cin >> buf;
		if(buf == '#'){
			arr[y][x] = 0;
			que.push(make_pair(y, x));
		}
		else{
			arr[y][x] = 1000000000;
		}
	}
	}

	while(!que.empty()){
		auto Tg = que.front();
		que.pop();
		if(Tg.first > 0){
			if(arr[Tg.first-1][Tg.second] > arr[Tg.first][Tg.second] + 1){
				arr[Tg.first-1][Tg.second] = arr[Tg.first][Tg.second] + 1;
				que.push(make_pair(Tg.first-1, Tg.second));
			}
		}
		if(Tg.first < H - 1){
			if(arr[Tg.first+1][Tg.second] > arr[Tg.first][Tg.second] + 1){
				arr[Tg.first+1][Tg.second] = arr[Tg.first][Tg.second] + 1;
				que.push(make_pair(Tg.first+1, Tg.second));
			}
		}
		if(Tg.second > 0){
			if(arr[Tg.first][Tg.second-1] > arr[Tg.first][Tg.second] + 1){
				arr[Tg.first][Tg.second-1] = arr[Tg.first][Tg.second] + 1;
				que.push(make_pair(Tg.first, Tg.second - 1));
			}
		}
		if(Tg.second < W - 1){
			if(arr[Tg.first][Tg.second+1] > arr[Tg.first][Tg.second] + 1){
				arr[Tg.first][Tg.second+1] = arr[Tg.first][Tg.second] + 1;
				que.push(make_pair(Tg.first, Tg.second + 1));
			}
		}

		MAX = max(MAX, arr[Tg.first][Tg.second]);
	}

	cout << MAX << endl;

	return 0;
}

Measured memory_bytes: 12304
#include <iostream>
#include <cstdio>
#include <vector>
#define MAX_NODE 100000
#define MAX_EDGE 100000

using namespace std;

int n;//num of nodes
int e;//num of edges
int group[MAX_NODE+1];//0オリジン
int q;

bool neighbor_a[MAX_NODE+1];
vector<int> neighbor_v[MAX_NODE+1];//連接リスト

void addNeighbor(int num,int ori){//oriを含む連結グラフをつくる
	int ngb;
	
	for(int i = 0;i < neighbor_v[num].size();i++){//深さ優先探索
		if(neighbor_a[neighbor_v[num][i]] == false){
			neighbor_a[neighbor_v[num][i]] = true;
			neighbor_v[ori].push_back(neighbor_v[num][i]);
			ngb = neighbor_v[num][i];
			addNeighbor(ngb,ori);
		}
	}
}


int main(){
	int v_1,v_2;
	scanf("%d %d",&n,&e);

	for(int i = 0;i < e;i++){
		scanf("%d %d",&v_1,&v_2);
		neighbor_v[v_1].push_back(v_2);
		neighbor_v[v_2].push_back(v_1);
	}

	for(int i  = 0;i < n;i++) group[i] = -1;

	for(int i = 0;i < n;i++){
		if(group[i] != -1) continue;

		for(int j = 0;j < n;j++) neighbor_a[j] = false;//iの連接配列
		neighbor_a[i] = true;
		neighbor_v[i].push_back(i);

		addNeighbor(i,i);

		for(int j = 0;j < neighbor_v[i].size();j++) group[neighbor_v[i][j]] = i;

	}
	//for(int i = 0;i < n;i++) cout <<group[i] <<" ";
	//for(int i = 0;i < neighbor_v[5].size();i++) cout <<neighbor_v[5][i] <<" ";

	scanf("%d",&q);

	for(int i = 0;i < q;i++){
		scanf("%d %d",&v_1,&v_2);
		if(group[v_1] == group[v_2]) cout <<"yes" <<endl;
		else cout <<"no" <<endl;
	}
	return 0;
}

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

const int INF= 1e9 +5;
typedef std::vector<int> vi;
typedef pair<int,int> ii;


int main() {

	//freopen("input.txt", "r", stdin); 
  	//freopen("output.txt", "w", stdout); 
int n;
	scanf("%d",&n);
  	std::vector<double> dp(n+1,0);
  	dp[0]=1;

  	for(int i=1;i<=n;i++)
  	{
  		double p;
  		scanf("%lf",&p);
  		for(int j=i;j>=0;j--)
  		{
  			dp[j]=((j==0) ? 0:dp[j-1]*p) + dp[j]*(1-p);
  		}

  	}

  	double ans=0;
  	for(int h=0;h<=n;h++){
  		int t=n-h;
  		if(h>t)
  		{
  			ans+=dp[h];
  		}

  		
  	}
  	printf("%.10lf",ans);


	
	return 0;
}

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

using namespace std;

int keta(int t){
    int g, sum1;
    sum1 = 0;
    while (t > 0){
        g = t % 10;
        t = t / 10;
        sum1 += g;
    }
    return sum1;
    
}



int main(){
    int n, a, b, sum;
    cin >> n >> a >> b;
    sum = 0;
    for (int x = 1; x <= n; x ++){
        if (keta(x) <= b && keta(x) >= a)
            sum += x;
    }
    cout << sum << endl;
    
}

Measured memory_bytes: 256
N, L = gets.chomp.split(" ").map(&:to_i)

taste = []

(1..N).map{|i|
  taste[i-1] = L + i - 1
}

def minAbsPoint(ary)
  min_abs = ary[0].abs
  min_abs_point = 0
  (1...N).map{|i|
    if ary[i].abs < min_abs then
      min_abs = ary[i].abs
      min_abs_point = i
    end
  }
  min_abs_point
end

answer = taste[0...N].inject(:+) - taste[minAbsPoint(taste)]

p answer


Measured memory_bytes: 1788
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;

class TEST{
	static void Main(){
		Sol mySol =new Sol();
		mySol.Solve();
	}
}

class Sol{
	public void Solve(){
		
		if(N == 1){
			Console.WriteLine(2);
			return;
		}
		
		long mod = (long)1e9 + 7;
		
		long[] dpA = new long[N+1];
		long[] dpB = new long[N+1];
		long[] sumA = new long[N+2];
		long[] sumB = new long[N+2];
		
		dpA[0] = 1;
		sumA[1] = 1;
		dpB[0] = 1;
		sumB[1] = 1;
		
		int clA = 0;// [0,clA) を0にするフラグ (S[clA-1] ≦ S[clA] - A が成り立たない）
		int clB = 0;
		
		int okA = 0;// [0,okA) を足す事が出来る（S[i]-A ≧ S[okA] となる最大のインデックス + 1
		int okB = 0;
		
		for(int i=1;i<N;i++){
			while(S[okA] <= S[i+1] - A && okA < i) okA++;
			while(S[okB] <= S[i+1] - B && okB < i) okB++;
			
			// dpB[*]は [0,okA) からdpA[i] に配れるが，[0,clB)は 0 になっている
			// → 実際に行けるのは [clB,okA)  
			if(okA >= clB) dpA[i] = sumB[okA] - sumB[clB] + mod; if(dpA[i] >= mod) dpA[i] -= mod;
			if(okB >= clA) dpB[i] = sumA[okB] - sumA[clA] + mod; if(dpB[i] >= mod) dpB[i] -= mod;
			
			// dpA[*] [0,i) は S[i+1] >= S[i] + A なら そのまま dpA[*] に残る
			// → そうでないなら dpA[*] [0,i)は すべて 0 になる 
			if(S[i+1] - A < S[i]) clA = i;
			if(S[i+1] - B < S[i]) clB = i;
			
			sumA[i+1] = sumA[i] + dpA[i]; if(sumA[i+1] >= mod) sumA[i+1] -= mod;
			sumB[i+1] = sumB[i] + dpB[i]; if(sumB[i+1] >= mod) sumB[i+1] -= mod;
		}
		
		long ans = sumA[N] + sumB[N] +(-sumA[clA] + mod) + (-sumB[clB] + mod);
		ans %= mod;
		
		Console.WriteLine(ans);
		
	}
	int N;
	long A,B;
	long[] S;
	public Sol(){
		var d = rla();
		N = (int) d[0]; A = d[1]; B = d[2];
		S = new long[N+1];
		S[0] = -(long)3e18;
		for(int i=0;i<N;i++) S[i+1] = rl();
	}

	static String rs(){return Console.ReadLine();}
	static int ri(){return int.Parse(Console.ReadLine());}
	static long rl(){return long.Parse(Console.ReadLine());}
	static double rd(){return double.Parse(Console.ReadLine());}
	static String[] rsa(char sep=' '){return Console.ReadLine().Split(sep);}
	static int[] ria(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>int.Parse(e));}
	static long[] rla(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>long.Parse(e));}
	static double[] rda(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>double.Parse(e));}
}




Measured memory_bytes: 10840
require 'prime'
MAX = 10000
c = [0] * 10001
primes = Prime.each.take_while{ |p| p < MAX }
(1..1/0.0).each do |i|
  break if primes[0,i].reduce(:+) > MAX
  primes.each_cons(i) do |ps|
    break if (sum = ps.reduce(:+)) > MAX
    c[sum] += 1
  end
end

while n = gets.to_i
  break if n == 0
  puts c[n]
end

Measured memory_bytes: 9500
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<sstream>
#include<vector>
#include<queue>
#include<stack>
#include<string>
#include<climits>
#include<map>
#include<set>
#include<cassert>
#include<deque>
#define REP(i,s,n) for(int i=s;i<n;i++)
#define rep(i,n) REP(i,0,n)
#define INF 1<<27
#define all(n) n.begin(),n.end()
#define insert(a,b,c,d) PP(P(a,b),P(c,d))
#define F first
#define S second
#define pb push_back
#define foreach(i,c) for(iter(c) i=(c).begin();i!=(c).end();++i)
using namespace std;
typedef pair<int,int> P;
typedef pair<P,P> PP;
int h,w,imap[400][400],d[400][400];
static const int dx[4] = {0,1,0,-1};
static const int dy[4] = {1,0,-1,0};

void solve(){
  queue<P> que;
  que.push(P(0,0));
  d[0][0] = 1;
  while(!que.empty()){
    P p = que.front(); que.pop();
    //cout << "p = "<< p.F << "," <<  p.S << endl;
    rep(i,4){
      int limx = p.S%2==0?w-1:w;
      if(imap[p.S+dy[i]][p.F+dx[i]] == 1)continue;
      int nx = p.F+dx[i]*2,ny = p.S+dy[i]*2;
      if(0<= nx && nx < w*2-1 && 0<= ny && ny < h*2-1 && d[ny][nx] > d[p.S][p.F]+1){
	d[ny][nx] = d[p.S][p.F]+1;
	//	cout << "nx = " << nx << ", ny = "<< ny << ",d["<<ny<<"]["<<nx<<"] = " << d[ny][nx] << endl;
	que.push(P(nx,ny));
      }
    }
  }
    
  if(d[h*2-2][w*2-2] == INF)cout << 0 << endl;
  else cout << d[h*2-2][w*2-2] << endl;
}

bool input(){
  cin >> w >> h;
  if(h+w == 0)return false;
    rep(i,h*2-1){
    for(int j=0;j<w*2-1;j++){
      if((i%2==0 && j%2==0) || (i%2!=0 && j%2!=0)){
	imap[i][j] = 8;
	d[i][j] = INF;
	continue;
      }
      cin >> imap[i][j];
      d[i][j] = INF;
    }
  }
  return true;
}

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

Measured memory_bytes: 1412
#include<iostream>

using namespace std;

int n; 
int a[3000 + 5];

int main(){
  cin >> n;
  int ans = 0;
  for(int i = 0; i < n; ++i){
    cin >> a[i];
    ans += a[i] - 1;
  }
  cout << ans << endl;
}

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

int main() {
  int N; cin >> N;
  vector<int> point(N);
  
  for (int i = 0; i < N; i++) {
    cin >> point.at(i);
  }
  
  double sum = 0;
  
  for (int i = 0; i < N; i++) {
    sum += 1.0 / (double)point.at(i);
  }
  
  cout << 1.0 / (double)sum << endl;
  
}
  
  

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

using namespace std;

#define LOG(...) fprintf(stderr, __VA_ARGS__)
//#define LOG(...)
#define FOR(i, a, b) for(int i = (int)(a); i < (int)(b); ++i)
#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
#define RREP(i, n) for(int i = (int)(n - 1); i >= 0; --i)
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define EXIST(s, e) ((s).find(e) != (s).end())
#define SORT(c) sort(ALL(c))
#define RSORT(c) sort(RALL(c))
#define SQ(n) (n) * (n)

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<pii> vpi;
typedef vector<pll> vpl;
typedef vector<ll> vll;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef vector<vc> vvc;
typedef vector<vll> vvll;

int main() {
  int n;
  cin >> n;
  string seq;
  REP(i, n){
    char c;
    cin >> c;
    seq.push_back(c);
  }

  int i;
  for(i = 0;; i++) {
    if(seq.find(to_string(i)) == string::npos) break;
  }
  cout << i << endl;
}

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

int main() {
    int a, b;
    cin >> a >> b;
    if (b == 1) cout << 0 << endl;
    else {
        cout << ceil((double)(b-1) / (double)(a-1)) << endl;
    }
}

Measured memory_bytes: 256
import numpy as np 
from itertools import combinations

n,m,x = map(int, input().split())
n_num = [_ for _ in range(n)]

l = np.array([list(map(int, input().split())) for _ in range(n)])

ans = []
for i in range(n):
    ptn = list(combinations(n_num, i+1))
    for j in range(len(ptn)):
        tmp = np.array([0]*(m+1))
        for k in range(len(ptn[j])):
            tmp += l[ptn[j][k]]
        if min(tmp[1:]) >= x:
            ans += [tmp[0]]

print(-1 if ans == [] else min(ans))

Measured memory_bytes: 27540
n = int(input())
s = input()

ans = s.count("R") * s.count("G") * s.count("B")

for i in range(n):
    for j in range(i+1, n):
        k = 2 * j - i
        if k >= n:
            break
        ans -= s[k] != s[i] != s[j] != s[k]

print(ans)

Measured memory_bytes: 9020
from collections import defaultdict
n, k = map(int, input().split())
a = [0] + [int(i) for i in input().split()]
d = defaultdict(int)
next = 1
for t in range(k):
  if d[next]!=0:
    period = t - d[next]
    res = (k - t)%period
    for _ in range(res):
      next = a[next]
    break
  elif d[next]==0:
    d[next] = t
    next = a[next]
print(next)

Measured memory_bytes: 32708
#include<bits/stdc++.h>
using namespace std;
int n,l,r,ans;
int main()
{
	cin>>n;
	for(int i=1;i<=n;i++)
	{ 
	cin>>l>>r;
	ans+=r-l+1;
	}
	cout<<ans<<endl;
	return 0; 
 } 

Measured memory_bytes: 256
import functools

import os

INF = float('inf')


def inp():
    return int(input())


def inpf():
    return float(input())


def inps():
    return input()


def inl():
    return list(map(int, input().split()))


def inlf():
    return list(map(float, input().split()))


def inls():
    return input().split()


def debug(fn):
    if not os.getenv('LOCAL'):
        return fn

    @functools.wraps(fn)
    def wrapper(*args, **kwargs):
        print('DEBUG: {}({}) -> '.format(
            fn.__name__,
            ', '.join(
                list(map(str, args)) +
                ['{}={}'.format(k, str(v)) for k, v in kwargs.items()]
            )
        ), end='')
        ret = fn(*args, **kwargs)
        print(ret)
        return ret

    return wrapper


a = inps()
b = inps()
c = inps()
print(a[0] + b[1] + c[2])


Measured memory_bytes: 3572
import numpy as np


def solve(n):
    # primes
    primes = np.ones(10 ** 6 + 1, dtype=int)
    primes[:2] = 0
    for p in range(2, 10 ** 6 + 1):
        if primes[p]:
            primes[p * p::p] = 0

    res = 0
    for p in range(10 ** 6 + 1):
        if primes[p] and n % p == 0:
            c = 0
            while n % p == 0:
                n = n // p
                c += 1
            d = 1
            while c >= d:
                c -= d
                res += 1
                d += 1
    if n > 1:
        res += 1

    return res


def main():
    n = int(input())
    res = solve(n)
    print(res)


def test():
    assert solve(24) == 3
    assert solve(1) == 0
    assert solve(64) == 3
    # assert solve(1000000007) == 1
    # assert solve(997764507000) == 7


if __name__ == "__main__":
    test()
    main()


Measured memory_bytes: 34976
import math
N = int(input())
all_gcd = []
for i in range(1, N+1):
  for j in range(1, N+1):
    x = math.gcd(i, j) if i != j else i
    for m in range(1, N+1):
      y = math.gcd(x, m) if x != m else x
      all_gcd.append(y)

print(sum(all_gcd))


Measured memory_bytes: 71632
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL)
#define endl "\n"
#define pb push_back
#define mod 1000000007
int dx[]={1,-1,0,0};
int dy[]={0,0,1,-1};
int dx8[]={1,-1,0,0,1,1,-1,-1};
int dy8[]={0,0,1,-1,1,-1,1,-1};

ll binexp(ll a, ll b, ll m) {
	a %= m;
	ll res = 1;
	while (b > 0) {
		if (b & 1)
			res = res * a % m;
		a = a * a % m;
		b >>= 1;
	}
	return res;
}
ll modinvfermat(ll a, ll m)
{
	return binexp(a, m - 2, m);
}
void task(bool flag)
{
	if (flag)
		cout << "YES\n";
	else
		cout << "NO\n";
}
ll lcm(ll a, ll b)
{
	return ((1LL * a * b) / (__gcd(a, b)));
}
ll n,m;
ll c;

vector<ll> v[200001];
ll vis[200001];
void dfs(ll node){
	vis[node]=1;
	c++;

	
	for(auto i:v[node]){
		if(vis[i]==0){
			

			dfs(i);

		}
	}
}

void solve(){
	
	cin>>n>>m;
	for(ll i=0;i<m;i++){
		ll a,b;
		cin>>a>>b;
		v[a].pb(b);
		v[b].pb(a);

	}
	ll cc=INT_MIN;
	for(ll i=1;i<=n;i++){
		if(vis[i]==0){
			c=0;

			dfs(i);
			cc=max(cc,c);


		}

	}
	cout<<cc<<endl;












return;
}




int main()
{  
#ifndef ONLINE_JUDGE
	// for getting input from input.txt
	freopen("input.txt", "r", stdin);
	// for writing output to output.txt
	freopen("output.txt", "w", stdout);
#endif
    fast;
    ll t;
    t=1;
   //cin>>t;
    while(t--){
    	solve();
    }
    
   
  



#ifndef ONLINE_JUDGE
	cout << "\nTime Elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " sec\n";
#endif
return 0;
}

Measured memory_bytes: 22344
N=int(input())
A=[int(i) for i in input().split()]
B=[int(i) for i in input().split()]
C=[(B[i]-A[i],A[i],B[i]) for i in range(3)]
C.sort()
ans=0
#print(C)
if C[2][0]<=0:
  for i in range(3):
    C[i]=(A[i]-B[i],B[i],A[i])
  C.sort()
  A,B=B,A
#print(A,B)

if C[0][0]>=0:
  for p in range(N+1):
    for q in range(N+1):
      if p*A[0]+q*A[1]<=N:
        r=(N-p*A[0]-q*A[1])//A[2]
        s=N-(p*A[0]+q*A[1]+r*A[2])
        ans=max(ans,p*B[0]+q*B[1]+r*B[2]+s)
elif C[0][0]<0 and C[1][0]>=0:
  for p in range(N+1):
    if p*C[1][1]<=N:
      q=(N-C[1][1]*p)//C[2][1]
      s=N-(p*C[1][1]+q*C[2][1])
      n=p*C[1][2]+q*C[2][2]+s
      r,m=n//C[0][2],n-C[0][2]*(n//C[0][2])
      n=m+C[0][1]*r
      ans=max(ans,n)
else:
  r,m=N//C[2][1],N-C[2][1]*(N//C[2][1])
  N_=m+C[2][2]*r
  for p in range(N_+1):
    if p*C[0][2]<=N_:
      q=(N_-C[0][2]*p)//C[1][2]
      s=N_-(p*C[0][2]+q*C[1][2])
      n=p*C[0][1]+q*C[1][1]+s
      #print(p,q,s,n)
      ans=max(ans,n)
        
  
    
print(ans)  

Measured memory_bytes: 41836
#include <bits/stdc++.h>
 
#define rep(i,n) for(ll i=0;i<n;++i)
#define ALL(a) (a).begin(),(a).end()
 
using namespace std;
using ll  = long long;
using pll = pair<ll, ll>;
using pdd = pair<double, double>;
 
const ll MOD  = 1e9+7;
const ll LINF = 1LL << 60;
const int INF = 1e9 + 7;

int main(){
    ll n;
    cin >> n;
    
    vector<ll> s(n);
    rep(i, n)cin >> s[i];

    ll q;
    cin >> q;

    ll ans = 0;

    rep(i, q){
        ll t;
        cin >> t;

        ll left = 0;
        ll right = n;

        while(left < right){
            ll mid = (left + right) / 2;

            if(t == s[mid]){
                ans++;
                break;
            }
    
            if(s[mid] > t)right = mid;
            else left = mid+1;
        }
    }

    cout << ans << endl;

}


Measured memory_bytes: 3516
#include <bits/stdc++.h>
#include <iomanip>
#define rep(i,n)for(long long i=0;i<(n);i++)
using namespace std;
typedef long long ll;
 
const int MOD=1000000007;
const int INF=0x3f3f3f3f;
const ll INFL=0x3f3f3f3f3f3f3f3f;

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

int main(){
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  
  ll n,k;
  cin >> n >> k ;
  vector<int>a(n);
  vector<int>f(n);
  rep(i,n) cin >> a[i];
  rep(i,n) cin >> f[i];
  sort(a.begin(),a.end());
  sort(f.begin(),f.end(),greater<int>());
  
  ll left=-1,right=1e12;
  while(right-left>1){
    ll mid=(left+right)/2;
    ll num=0;
    rep(i,n){
      ll b=a[i]-mid/f[i];
      num+=max(0ll,b);
    }
    if(num<=k) right=mid;
    else left=mid;
  }
  
  cout << right << endl;
}

Measured memory_bytes: 1792
import Data.List

parse :: String -> (String , Int)
parse xs = let [s , i] = words xs in (s , read i)

output :: [(String , Int)] -> IO ()
output xs = putStrLn (fst $ head xs) >> (putStrLn $ unwords $ map (show . snd) xs)

main :: IO ()
main = getContents
    >>= return . map parse . lines
    >>= return . groupBy (\ x y -> fst x == fst y) . sort
    >>= mapM_ output

Measured memory_bytes: 4108
#include <iostream>
#define lli long long int
using namespace std;

int main() 
{
    lli n, k;
    cin >> n >> k;
    lli a[n + 1];
    a[0] = 0;
    for(lli i = 1; i <= n; i++)
        cin >> a[i];
    lli dp[n+1] = {0};
    dp[2] = abs(a[2] - a[1]);
    lli m;
    for(lli i = 3; i <= n; i++)
    {
        m = 111111111111111;
        for(lli j = k; j > 0; j--)
            if(i - j > 0)
                m = min(m, dp[i - j]+ abs(a[i] - a[i - j]));
        dp[i] = m;
    }
    cout << dp[n];
    return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
int main(void){
    long long int N,K;
    cin >> N >> K;
    long long int Health[N];
    for(int i=0;i<N;i++) cin >> Health[i];
    sort(Health,Health+N);
    long long int ans=0;
    for(int i=0;i<N-K;i++){
        ans+=Health[i];
    }
    cout << ans;
}

Measured memory_bytes: 5124
# coding:utf-8

import sys
# from collections import Counter, defaultdict

INF = float('inf')
MOD = 10 ** 9 + 7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return input()


def main():
    n = II()
    A = LI()
    A.sort()
    A.reverse()
    res = 0
    for i in range(n):
        res += A[1 + i * 2]

    return res


print(main())


Measured memory_bytes: 37212
package main

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

const (
	initialBufSize = 100000
	maxBufSize     = 10000000
)

var (
	sc = bufio.NewScanner(os.Stdin)
	wt = bufio.NewWriter(os.Stdout)
)

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	i, _ := strconv.Atoi(next())
	return i
}

func puts(a ...interface{}) {
	fmt.Fprintln(wt, a...)
}

func main() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, initialBufSize), maxBufSize)
	defer wt.Flush()

	n, d := nextInt(), nextInt()

	ans := 0
	for i := 0; i < n; i++ {
		x, y := nextInt(), nextInt()
		if d*d >= x*x+y*y {
			ans++
		}
	}

	puts(ans)
}


Measured memory_bytes: 5000
import random
N = int(input())
A = list(map(int, input().split()))
 
S = A[0]+A[1]
X = 0
for a in A[2:]:
  X ^= a
 
D = (S-X)>>1
if S!=X+(D<<1) or D>A[0] or (X&D)!=0:
  print(-1)
  exit(0)
a = D
b = 2**64
while b>0:
  if (X&b)!=0 and (a|b)<=A[0]:
    a |= b
  b >>= 1
if a==0:
  print(-1)
  exit(0)
print(A[0]-a)

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

#define ll long long

int main(){
	
	int n;cin>>n;
	while(n--){
		ll s,d;
		int ans=0;
		cin>>s>>d;
		
		while(s!=d){
			ll tmp=s;
			
			for(ll x=1;true;x*=2){
				if(s%x!=0)break;;
				if(s+x>d)break;
				tmp=s+x;
			}
			
			s=tmp;
			ans++;
		}
		
		cout<<ans<<endl;
	}
	
	return 0;
}


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

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;
typedef vector<pdd> vdd;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define mem(a,b) memset(a, b, sizeof(a) )
#define all(x) (x).begin(),(x).end()
#define INF 1000000000000
#define MOD 1000000007
#define PB push_back
#define MP make_pair
#define F first
#define S second

inline void normal(ll &a) { a %= MOD; (a < 0) && (a += MOD); }
inline ll modMul(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a*b)%MOD; }
inline ll modAdd(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a+b)%MOD; }
inline ll modSub(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); a -= b; normal(a); return a; }
inline ll modPow(ll b, ll p) { ll r = 1; while(p) { if(p&1) r = modMul(r, b); b = modMul(b, b); p >>= 1; } return r; }
inline ll modInverse(ll a) { return modPow(a, MOD-2); }
inline ll modDiv(ll a, ll b) { return modMul(a, modInverse(b)); }

ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

int ctoi(char c) {
	if (c >= '0' && c <= '9') {
		return c - '0';
	}
	return 0;
}

int main(){
	ll n;cin>>n;
	ll ans=0;
	ans+=n/500*1000;
	n=n-n/500*500;
	ans+=n/5*5;
	cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int main() {
	int i, n, c[20], v[20];
	int csum = 0, vsum = 0;

	scanf("%d", &n);

	for (i = 0; i < n; i++) scanf("%d", &c[i]);
	for (i = 0; i < n; i++) scanf("%d", &v[i]);

	for (i = 0; i < n; i++) {
		if (c[i] > v[i]) {
			csum += c[i];
			vsum += v[i];
		}
	}

	printf("%d\n", csum - vsum);

	return 0;
}

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

int n;
bool s[504], t[504], bans=1;
unsigned long long u[504], v[504], ans[504][504];

int main(){
	cin >> n;
	for (int i=0;i<n;i++) cin >> s[i];
	for (int i=0;i<n;i++) cin >> t[i];
	for (int i=0;i<n;i++) cin >> u[i];
	for (int i=0;i<n;i++) cin >> v[i];
	for (int i=0;i<n;i++){
		for (int j=0;j<n;j++){
			ans[i][j]=u[i];
		}
	}
	for (int j=0;j<n;j++){
		if (t[j]){ // OR
			unsigned long long tmp=0;
			for (int i=0;i<n;i++) tmp|=ans[i][j];
			for (unsigned long long bit=0;bit<64;bit++){
				if ((tmp&(1LL<<bit))==((v[j]&(1LL<<bit)))) continue;
				if ((v[j]&(1LL<<bit))){ // turn on
					if (j&1){ // go from above
						for (int i=0;i<n;i++){
							if (s[i]) continue;
							if ((ans[i][j]&(1LL<<bit))==0){
								ans[i][j]|=(1LL<<bit);
								break;
							}
						}	
					}
					else{ // go from below
						for (int i=n-1;i>=0;i--){
							if (s[i]) continue;
							if ((ans[i][j]&(1LL<<bit))==0){
								ans[i][j]|=(1LL<<bit);
								break;
							}
						}	
					}
				}
				else{ // turn off
					for (int i=0;i<n;i++) ans[i][j]&=(~(1LL<<bit));
				}
			}	
		}
		else{ // AND
			unsigned long long tmp=(~0);
			for (int i=0;i<n;i++) tmp&=ans[i][j];
			for (unsigned long long bit=0;bit<64;bit++){
				if ((tmp&(1LL<<bit))==((v[j]&(1LL<<bit)))) continue;
				if ((v[j]&(1LL<<bit))){ // turn on
					for (int i=0;i<n;i++) ans[i][j]|=(1LL<<bit);
				}
				else{ // turn off
					if (j&1){ // go from above
						for (int i=0;i<n;i++){
							if (!s[i]) continue;
							if ((ans[i][j]&(1LL<<bit))){
								ans[i][j]&=(~(1LL<<bit));
								break;
							}
						}	
					}
					else{ // go from below
						for (int i=n-1;i>=0;i--){
							if (!s[i]) continue;
							if ((ans[i][j]&(1LL<<bit))){
								ans[i][j]&=(~(1LL<<bit));
								break;
							}
						}	
					}
				}
			}	
		}
	}
	for (int i=0;i<n;i++){
			if (s[i]){ // OR
				unsigned long long tmp=0;
				for (int j=0;j<n;j++) tmp|=ans[i][j];
				if (tmp!=u[i]) bans=0;
			}
			else{ // AND
				unsigned long long tmp=(~0);
				for (int j=0;j<n;j++) tmp&=ans[i][j];
				if (tmp!=u[i]) bans=0;
			}
		}
		if (!bans){
			cout << "-1\n";
			return 0;
		}
		for (int i=0;i<n;i++){
			for (int j=0;j<n;j++){
				cout << ans[i][j] << " ";
			}
			cout << "\n";
		}
}

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

typedef long long int ll;
typedef pair<int,int>P;
#define INF (1e9)
#define EPS (1e-7)
#define MOD ((ll)1e9+7)
#define REP(i,n) for(int i = 0; i < (int)(n); i++)
#define FOR(i,k,n) for(int i = (k); i < (int)(n); i++)
#define ALL(a)  a.begin(),a.end()
#define RALL(a) a.begin(),a.end(),greater<int>()
#define pb push_back
#define vec vector<int>


/*--------------------------------------------*/
/*ll factorial(ll);
void list_Prime(ll);
ll divisor(ll);*/
/*--------------------------------------------*/
ll lcm(ll, ll);//AとBの最小公倍数
ll gcd(ll,ll);

int main(){
    int n;cin>>n;
    ll t[n];
    REP(i,n)cin>>t[i];
  	ll tmp=1;
    //REP(i,n)cout<<t[i]<<endl;
    for(int i=0;i<n;i++){
        tmp=lcm(tmp,t[i]);
    }
    cout<<tmp<<endl;
}

ll lcm(ll A, ll B) {//最小公倍数
    ll a = A;
    ll b = B;
    if (a == 0 || b == 0) { return 0; }
    if (a < 0) { a = -a; }
    if (b < 0) { b = -b; }
    while (b > 0) {
        ll c = a % b;
        a = b;
        b = c;
    }
    return A/a*B;
}

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


/*--------------------------------------------*/
/*
ll factorial(ll n){
    if(n==1)return 1;
    return n*factorial(n-1);
}


void list_Prime(ll n){//n以下の素数を全て見つける
    ll Limit=(int)sqrt((double)n);
    for(ll i=2;i<=n;i++)prime[i]=1;//最初はみんな素数かも
    //素数の整数倍を消していく(ルートnまで)
    for(ll i=2;i<=Limit;i++){
        if(prime[i]){
            for(ll j=2*i;j<=n;j++){
                if(j%i==0){
                    prime[j]=0;                
                }
            }
        }
    }
}

ll divisor(ll n){
    for(ll i=2;i<=n;i++){
        ll d=1;
        ll tmp=i;
        while(tmp>0){
            d++;
            while(tmp%d==0){
                prime[i]++;
                tmp/=i;
            }
        }
    }
    ll sum=1;
    for(ll i=2;;i<=n;i++){
        sum*=(prime[i]+1)/MOD;
    }    
    cout<<"sum="<<sum<<endl;

    return sum%MOD;
}
*/


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

int main()
{
  int N;
  string S;
  cin >> N >> S;
  string ret;
  for(char c :S){
    char tmp = c + N;
    if(tmp > 'Z'){
      tmp -= 26;
    }
    ret += tmp;
  }
  cout << ret << endl;
  return 0;
}


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

void c_p_c() {
	ios_base::sync_with_stdio(false); cin.tie(NULL);

#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("error.txt", "w", stderr);
	freopen("output.txt", "w", stdout);
#endif
}

int main() {
	c_p_c();
	int n;
	cin >> n;
	int rem = n % 1000;
	(rem != 0) ? cout << 1000 - rem : cout << 0;
}




Measured memory_bytes: 3696
import java.util.Scanner;
public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int w=sc.nextInt();
        int n=sc.nextInt();
        int[]v=new int[w];
        
        for(int i=0; i<w; i++){
            v[i]=i+1;
        }
        
        for(int i=0; i<n; i++){
            String str = sc.next();
            String[] ab = str.split(",");
            int a = Integer.parseInt(ab[0])-1;
            int b = Integer.parseInt(ab[1])-1;
        
            int z=v[a];
            v[a]=v[b];
            v[b]=z;
        }
        for(int i=0; i<w; i++){
            System.out.println(v[i]);
        }
    }
}


Measured memory_bytes: 25924