akhauriyash/Code-Regression huggingface dataset:
import sys
import heapq


def can_eat_with_score(key):
    now_K = K
    for i, now_score in enumerate(score):
        if key < now_score:
            now_K -= (now_score-key+F[i]-1) // F[i]
            if now_K < 0:
                return False
    return True


input = sys.stdin.readline

priority_que = []
N, K = map(int, input().split())
A = sorted(map(int, input().strip().split()))
F = sorted(map(int, input().strip().split()))[::-1]
score = [A[i]*F[i] for i in range(N)]
if sum(A) <= K:
    print("0")
    exit()


left = -1
right = max(score)
while right - left > 1:
    mid = (left+right) // 2
    can_eat = can_eat_with_score(mid)
    # print(mid, can_eat)
    if can_eat:
        right = mid
    else:
        left = mid
print(left+1)


Measured memory_bytes: 117632
#include<bits/stdc++.h>
using namespace std;
const int N=10010;
char s1[N],s2[N];
int _a[N],n1,n2,_b[N],*a=_a+5005,*b=_b+5005,n;
int main(){
	scanf("%d",&n);
	scanf("%s%s",s1+1,s2+1);
	if (s1[1]!=s2[1])a[++n1]=0;
	for (int i=1;i<n;i++)
		if (s1[i]!=s1[i+1])a[++n1]=i;
	for (int i=1;i<n;i++)
		if (s2[i]!=s2[i+1])b[++n2]=i;
	int k1=n1,k2=n2;
	while (k1<=5000)a[++k1]=n;
	while (k2<=5000)b[++k2]=n;
	int ans=1e9;
	for (int i=-n1;i<=n2;i++){
		if (i&1)continue;
		int res=0;
		for (int j=-5000;j<=5000;j++){
			if (j+i>=-5000&&j+i<=5000)res+=abs(a[j+i]-b[j]);
			else{
				if (j+i<-5000)res+=b[j];
				else res+=n-b[j];
			}
		}
		ans=min(ans,res);
	}
	printf("%d\n",ans);
}


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

using namespace std;

int main() {
  int n,t;
  cin >> n >> t;
  vector<int> tn(n);
  int ans = 0;

  for (int i=0; i<n; i++) cin>>tn[i];

  int stop = tn[0] + t;
  for (int i=1; i<n; i++) {
    if (stop < tn[i] ) ans += t;
    else ans += t - (stop - tn[i]);
    stop = tn[i] + t;
  }

  cout << ans + t << endl;
}

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

int NMAX = 100000;

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

  long long v[3][NMAX+1], dp[3][NMAX+1];
  //for (int i = 0; i < NMAX; i++) {
  //  for (int j = 0; j < 3; j++) {
  //    v[j][i] = 0;
  //    dp[j][i] = 0;
  //  }
  //}

  for (int i = 1; i <= N; i++) {
    for (int j = 0; j < 3; j++) {
      cin >> v[j][i];
    }
  }

  for (int i = 0; i < N; i++) {
    for (int j = 0; j < 3; j++) {
      for (int k = 0; k < 3; k++) {
        if (j == k) continue;

        dp[j][i + 1] = max(dp[j][i + 1], dp[k][i] + v[j][i + 1]);
      }
    }
  }
  long long ans = -1;
  for (int i = 0; i < 3; i++) {
    ans = max(ans, dp[i][N]);
  }
  cout << ans << endl;
}


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

int main() {
	int n;
	while (cin >> n) {
		vector<int> freq(7, 0);
		vector<int> dups(7, 0);
		for (int i = 0; i < n; i++) {
			int t;
			cin >> t;
			freq[t % 10]++;
			freq[t / 10]++;
			if (t % 10 == t / 10) dups[t / 10]++;
		}
		int numOdd = 0;
		bool hasAloneDup = false;
		for (int i = 0; i <= 6; i++) {
			if (freq[i] % 2 == 1) numOdd++;
			if (freq[i] > 0 && freq[i] - dups[i] * 2 == 0) hasAloneDup = true;
		}
		cout << (n < 2 || !hasAloneDup && (numOdd == 0 || numOdd == 2) ? "Yes" : "No") << endl;
	}
	return 0;
}

Measured memory_bytes: 0
#
# 　　  ⋀_⋀　 
#　　  (･ω･)  
# .／ Ｕ ∽ Ｕ＼
#  │＊　合　＊│
#  │＊　格　＊│ 
#  │＊　祈　＊│ 
#  │＊　願　＊│ 
#  │＊　　　＊│ 
#      ￣
#
import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
from math import floor,ceil,sqrt,factorial,log #log2ないｙｐ
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
inf=float('inf')
mod = 10**9+7
def pprint(*A): 
    for a in A:     print(*a,sep='\n')
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
    H,W=MI()
    A=LLIN(H)
    B=LLIN(H)
    X=80*(H+W)
    can = [[0]*W for _ in range(H)]
    can[0][0] += 1<<(X-abs(A[0][0]-B[0][0]))
    for h in range(H):
        for w in range(W):
            absol = abs(A[h][w]-B[h][w])
            if h:
                can[h][w]|=can[h-1][w]<<absol
                can[h][w]|=can[h-1][w]>>absol
            if w:
                can[h][w]|=can[h][w-1]<<absol
                can[h][w]|=can[h][w-1]>>absol
    for i in range(160*(H+W)+5):
        if can[-1][-1] & ((1<<X<<i) | (1<<X>>i)):
            print(i)
            break

if __name__ == '__main__':
    main()

Measured memory_bytes: 56284
#include <algorithm>
#include <cstring>
#include <iostream>
#include <vector>
#include <cmath>
#include <math.h>
using namespace std;

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

int main(){
    long long N,tmp;
    cin>>N;
    vector <long long > A(N);
    vector <long long > B(N);
    B.push_back(0);

    for(int i=0;i<N;i++){
        cin>>tmp;
        A[i] = tmp;
        B.push_back(tmp);
    }
    sort(B.begin(),B.end(),greater<ll>());
    for(int i=0;i<N;i++){

        if(A[i]==B[0]){
            cout<<B[1]<<"\n";
        }else{
            cout<<B[0]<<"\n";
        }
    }

    return 0;
}

Measured memory_bytes: 9956
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <unordered_map>
#include <functional>
#include <cstring>
#include <cmath>
#include <ctime>
#include <cstdlib>

using namespace std;
typedef long long llong;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<llong, llong> pll;

void fail() {
    printf("-1\n");
    exit(0);
}

int n;
int a[200001];
int main() {
    scanf("%d", &n);
    for (int i = 1; i <= n; ++i) {
        scanf("%d", a + i);
    }
    if (a[1] != 0) fail();
    int mn = -1;
    llong ans = 0;
    for (int i = n; i > 0; --i, --mn) {
        if (a[i] < mn) fail();
        if (a[i] > mn) {
            mn = a[i];
            ans += a[i];
        }
    }
    printf("%lld\n", ans);
	return 0;
}


Measured memory_bytes: 1152
import math
while True:
    n = int(input())
    if n == 0:
        break
    a = 0
    nums = [int(e) for e in input().split()]
    for i in range(n):
        a = a + (nums[i]-sum(nums)/n)**2
    a = a / n
    print(math.sqrt(a))


Measured memory_bytes: 5708
/*
[agc031] B - Reversi
*/

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;

const int MAX_N = 2e5;
const int MAX_C = 2e5;
const ll MOD = 1e9 + 7;

int N;
int C[MAX_N];
ll dp[MAX_N];

ll solve() {
    int pre[MAX_N];
    int last[MAX_C];
    memset(last, -1, sizeof(last));
    for (int i = 0; i < N; i++) {
        pre[i] = last[C[i]];
        last[C[i]] = i;
    }

    dp[0] = 1;
    for (int i = 1; i < N; i++) {
        dp[i] = dp[i - 1];
        if (0 <= pre[i] && pre[i] < i - 1) {
            (dp[i] += dp[pre[i]]) %= MOD;
        }
    }

    return dp[N - 1];
}

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

    cout << solve() << endl;

    return 0;
}


Measured memory_bytes: 4096
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <iomanip>
using namespace std;
typedef long long unsigned int ll;
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define MOD 1000000007

#define REP(i,n) for(int i=0;i<n;i++)
#define REPS(i,f,n) for(int i=(f);i<(n);i++)
#define EACH(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)

#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

int dy4[]={0, 0, 1, -1};
int dx4[]={1, -1, 0, 0};
int dx8[]={0, 0, 1, -1, 1, 1, -1, -1};
int dy8[]={1, -1, 0, 0, 1, -1, -1, 1};

// https://beta.atcoder.jp/contests/abc060/tasks/abc060_b

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

    for (int i = 1; i <= B; i++) if(A*i % B == C) {
        cout << "YES" << "\n";
        return 0;
    }

    cout << "NO" << "\n";
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
    int N=0;
    cin>>N;
    int boss[200001]={0};
    for(int i=2;i<=N;i++){
        int tem=0;
        cin>>tem;
        boss[tem]++;
    }
    for(int i=1;i<=N;i++){
        cout<<boss[i]<<endl;
    }
}




Measured memory_bytes: 4388
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, begin, end) for(ll i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(ll i=(begin)-1;i>=(end);i--)
#define IREP(i, n) IFOR(i,n,0)
#define SORT(a) sort(a.begin(), a.end())	//昇順
#define ISORT(a) sort(a.begin(), a.end(),greater<ll>())	//降順
#define REVERSE(a) reverse(a.begin(), a.end())
#define debug(x) cout << #x << "=" << x << endl;
#define vdebug(v) cout << #v << "=(" << v[0]; FOR(i_debug, 1, v.size()){ cout << "," << v[i_debug]; } cout << ")" << endl;
#define mdebug(m) cout << #m << "=" << endl; REP(i_debug, m.size()){ REP(j_debug, m[i_debug].size()){ cout << m[i_debug][j_debug] << ","; } cout << endl;}
#define Lower_bound(v, x) distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) distance(v.begin(), upper_bound(v.begin(), v.end(), x))
#define Max(a, b) a = max(a, b)
#define Min(a, b) a = min(a, b)

#define ll long long
#define ld long double
#define f first
#define s second
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define INF 1000000000000000000


using vec = vector<ll>;
using mat = vector<vec>;
using Pii = pair<ll, ll>;
using PiP = pair<ll, Pii>;
using PPi = pair<Pii, ll>;
using bvec = vector<bool>;
using Pvec = vector<Pii>;


template<typename T> void readv(vector<T> &a){ REP(i, a.size()) cin >> a[i]; }
void readv_m1(vector<int> &a){ REP(i, a.size()){cin >> a[i]; a[i]--;} }

ll mod = 1000000007;

int main()
{
	ll r;
    cin>>r;

    cout<<r*r<<endl;
    
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define N 100123
#define endl '\n'

using namespace std;

int n, m, a[N], u, v;
set<int> adj[N];

int main() {
    ios_base::sync_with_stdio(0);
    
    cin >> n >> m;

    for(int i=1; i <= n; ++i) {
        cin >> a[i];
    }

    while(m--) {
        cin >> u >> v;
        adj[u].emplace(a[v]);
        adj[v].emplace(a[u]);
    }

    int ans = 0;
    for(int i=1; i <= n; ++i) {
        if(adj[i].size() == 0){ 
            ans++;
        }
        else {
            auto it = adj[i].end();
            it--;
            if(*it < a[i]) {
                ans++;
            }
        }
    }
    cout << ans << endl;


    return 0;
}


Measured memory_bytes: 18160
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
int gcd(int a,int b)
{
	if(b==0)
	return a;
	
	return gcd(b,a%b);
}
int power(int x,int y,int p)
{
	int res=1;
	x=x%p;
	while(y>0)
	{
		if(y&1)
		res=(res*x)%p;
		
		y=y>>1;
		x=(x*x)%p;
	}
	return res;
}
struct Matrix{ 
	int a[2][2] = {{0,0},{0,0}};
	Matrix operator *(const Matrix& other){
		Matrix product;
		for(int i=0;i<2;i++){
			for(int j=0;j<2;j++){
				for(int k=0;k<2;k++){
						product.a[i][k] =product.a[i][k] + (ll)a[i][j]*other.a[j][k];
				}
			}
		}
		return product;
	}
};
int modInverse(int n,int p)
{
	return power(n,p-2,p);
}
int main() {
	// your code goes here
	 ios_base::sync_with_stdio(0);
	 cin.tie(0);
	 string s,t;
	 cin>>s>>t;
	 int n = s.length();
	 int m = t.length();
	 int ans = 10000;
	 for(int i=0;i+m-1<n;i++)
	 {
		 string str = s.substr(i,m);
		 int cnt = 0;
		 for(int j=0;j<m;j++)
		 {
			 if(str[j] != t[j])
			 {
				 cnt++;
			 }
		 }
		 ans = min(ans,cnt);
	 }
	 cout<<ans<<'\n';
	 return 0;
}


Measured memory_bytes: 3656
#include <bits/stdc++.h>
 
using namespace std;
inline void prep ()
{
  cin.tie (0);
  cin.sync_with_stdio (0);
};
const double pi = acos(-1.);
//printf(%.12lf\n,mid);
// __builtin_popcount(int) count 1's in binary
// get decimal part of number
/*
double intpart;
double thiss = modf((double)(n*m)/(double)k, &intpart);
*/
// round = (int)(num+.5)
long long mod = 998244353;
 
// 32 mil = ~1 sec 
long long mymod(long long num){
  if (num< 0 && !(num%mod == 0)){
    if (mod == 1){
      return 0;
    }
    return mod-abs(num)%mod;
  }else{
    return num%mod;
  }
}
 
/*string sentence = And I feel fine...;
    istringstream iss(sentence);
*/  
const int biggg = 1000000000;
const long eps = .0000000001;


int main ()
{
  prep();
  double r;
  cin >> r;
  cout << 2*r*pi;
  return 0;
}


Measured memory_bytes: 3796
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define irep(i, n) for (int i = (n); i >= 0; i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = 1 << 30;
 
int main() {
  int h,w;
  cin >> h >> w;
  int cnt = 0;
  rep(i,h) rep(j,w) {
    char c; cin >> c;
    if (c == '#') cnt++;
  }
  if (cnt == h+w-1) cout << "Possible" << endl;
  else cout << "Impossible" << endl;
  return 0;
}

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

using namespace std;

const int M = 1e5 + 1;

int memo[M];

int poww(int n, int p) {
    int ans = 1;
    while (p--)
        ans *= n;
    return ans;
}

int solve(int n) {
    if (!n)
        return 0;
    if (n < 0)
        return 1e9;

    int &r = memo[n];

    if (r == -1) {
        r = 1e9;

        for (int i = 1; i <= 5; i++)
            r = min(r, 1 + solve(n - poww(9, i)));

        for (int i = 1; i <= 6; i++)
            r = min(r, 1 + solve(n - poww(6, i)));

        r = min(r, 1 + solve(n - 1));
    }

    return r;
}

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

    memset(memo, -1, sizeof memo);

    int n;
    cin >> n;
    cout << solve(n) << '\n';

    return 0;
}

Measured memory_bytes: 1152
import bisect
N = int(input())
L = list(map(int, input().split()))
L = sorted(L)
ans = 0

for i in range(N-2):
    for j in range(i+1, N-1):
        ans += bisect.bisect_left(L, L[i]+L[j]) - (j+1)

print(ans)


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

using namespace std;

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

int main(){
    
    yala_besor3a();
    
    int n, k, q, a[100001];
    cin >> n >> k >> q;
    for(int i = 0; i < n; ++i) 
        a[i] = k;
    int change = 0, idx;    
    while(q--){
        cin >> idx;
        change++;
        a[--idx]++;
    }
    for(int i = 0; i < n; ++i)
        if(a[i] - change <= 0) cout << "No\n";
        else cout << "Yes\n";
        
    return 0;
}

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

int main(){
  int64_t A, B, N;
  cin >> A >> B >> N;
  int64_t x = N;
  if(B-1 < x)
    x = B-1;
  
  int64_t ans;
  ans = A*x/B - A*(x/B);
  
  cout << ans << endl;
  
  return 0;
  
}

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

using namespace std;
#define ff(i, a, b) for(int i = (a), _b = (b); i <= _b; ++i)
#define rep(i, a, b) for(int i = (a), _b = (b); i < _b; ++i)
#define fd(i, a, b) for(int i = (a), _b = (b); i >= _b; --i)
#define SZ(x) ((int)(x).size())
#define db(x) cout << #x << " == " << x << endl
#define _ << ", " << 
#define X first
#define Y second
#define pb(x) push_back(x)
#define mp(x, y) make_pair(x, y)
#define endl '\n'
#define pc putchar
#define gc getchar 
#define bit(i) (1<<(i))
typedef long long ll;
typedef pair<int, int> ii;
typedef pair<ii, int> iii;

const int N=1e5+5;

// ans(i) la bit dau tien nho hon

int n,k,a[N],b[N];

bool onbit(int i,int mask){
	if (mask & bit(i)) return 1;
	else return 0;
}

void enter(){
	cin>>n>>k;
	ff(i,1,n) cin>>a[i]>>b[i];
}

void process(){
	ll ans=0;
	rep(st,-1,30){
		if (st<0 || (onbit(st,k))){
			ll cur=0;
			// den bit thu st thi phai tat
			// tat ca ca bit thap hon no the nao 
			// cung duoc
			ff(i,1,n){
				if (st>=0 && onbit(st,a[i])) continue;
				bool ok=1;
				rep(j,st+1,30) if (onbit(j,a[i]) && !onbit(j,k)){
					ok=0;
					break;
				}
				if (ok) cur+=b[i];
			}
			ans=max(ans,cur);
		}
	}
	cout<<ans<<endl;
}


int main(){
	ios_base::sync_with_stdio(false); cin.tie(NULL);
//	freopen("test.inp","r",stdin);
//	freopen("test.out","w",stdout);

	enter();
	process();	

	return 0;
}

Measured memory_bytes: 1024
# https://atcoder.jp/contests/abc083/tasks/abc083_b


import bisect


def digit_sum(a):
    s = str(a)
    total = 0
    for i in range(len(s)):
        total += int(s[i])
    return total


N, A, B = map(int, input().split())

digits = [(digit_sum(i), i) for i in range(1, N + 1)]
sorted_digits = sorted(digits, key=lambda a: a[0])
a_sorted_digits = [sorted_digits[i][0] for i in range(len(sorted_digits))]
left = bisect.bisect_left(a_sorted_digits, A)
right = bisect.bisect_right(a_sorted_digits, B)
print(sum([a[1] for a in sorted_digits[left:right]]))


Measured memory_bytes: 4288
#include<bits/stdc++.h>
#define MIN -1000000
using namespace std;
typedef long long ll;
const int MOD=1e9+7;
ll comb[2005][2005];
int N;
ll A[100005];
ll X[100005];
ll rain[100005];
int main(void)
{
  cin >> N;
  memset(rain,0LL,sizeof(rain));
  memset(X,0LL,sizeof(X));
  ll sum=0;
  for(int i=1;i<=N;i++)
  {
    cin >> A[i];
    sum+=A[i];
  }
  X[1]=sum;
  for(int i=2;i<=N-1;i+=2)
  {
    X[1]-=(2*A[i]);
  }
  for(int i=2;i<=N;i++)
  {
    X[i]=2*A[i-1]-X[i-1];
  }
  for(int i=1;i<=N;i++)
  {
    if(i!=N) printf("%lld ",X[i]);
    else printf("%lld\n",X[i]);
  }
}


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

int main()
{
    int s;
    int key1 = 0, key2 = 0;
    
    cin >> s;
    
    if(s % 100 >= 1 and s % 100 <= 12) {
        key1 = 1;
    }
    if(s / 100 >= 1 and s / 100 <= 12) {
        key2 = 1;
    }
    
    if(key1 == 1 and key2 == 1) {
        cout << "AMBIGUOUS" << endl;
    } else if(key1 == 1) {
        cout << "YYMM" << endl;
    } else if(key2 == 1) {
        cout << "MMYY" << endl;
    } else {
        cout << "NA" << endl;
    }
    
    return 0;
}


Measured memory_bytes: 256
def solve(n, s):
    num = 0
    a, b, ab = 0, 0, 0
    for i in range(n):
        num += s[i].count("AB")
        if s[i].endswith("A"):
            a += 1
        if s[i].startswith("B"):
            b += 1
        if s[i].endswith("A") and s[i].startswith("B"):
            ab += 1
    a -= ab
    b -= ab
    cnt = 0
    if ab > 0:
        cnt += ab - 1
        if a > 0:
            cnt += 1
            a -= 1
        if b > 0:
            cnt += 1
            b -= 1
    cnt += min(a, b)
    return num + cnt

n = int(input())
s = [input() for i in range(n)]
print(solve(n, s))

Measured memory_bytes: 3700
//  LINK ZADATKA: http://abc069.contest.atcoder.jp/tasks/abc069_b

#include <queue>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <complex>
#include <fstream>
#include <cstring>
#include <string>
#include <climits>

using namespace std;

typedef long long ll;
typedef complex<double> point;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector< vector<int> > vvi;


#define FOR(k,a,b) for(int k=(a); k<=(b); ++k)
#define REP(k,a) for(int k=0; k<(a);++k)
#define SZ(a) int((a).size())
#define ALL(c) (c).begin(),(c).end()
#define PB push_back
#define MP make_pair
#define INF 999999999
#define INFLONG 1000000000000000000
#define MOD 1000000007
#define MAX 100
#define ITERS 100
#define MAXM 200000
#define MAXN 1000000
#define _gcd __gcd
#define eps 1e-9
char s[150], sol[150];
int main(){
	
	scanf("%s", s);
	
	int dulj = strlen(s), cek, tempDulj, brT = 0;
	
 	dulj -= 2;
	tempDulj = dulj;
	sol[0] = s[0];
	
	while(tempDulj){
		brT++;
		tempDulj/=10;
	}
	cek = brT;
	sol[cek+1] = s[dulj+1];
	for(int i = cek; i > 0; i--){
		//printf("%d\n", dulj%10);
		sol[i] = (dulj%10) + '0';
		dulj /= 10;
	}
	
	printf("%s", sol);
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <set>
#include <cmath>
#include <vector>

typedef long long ll;

using namespace std;

int main()
{
    ll n;

    cin >> n;

    vector<ll> p(n);

    for (auto &i: p)
        cin >> i;

    vector<ll> sorted(p);
    sort(p.begin(), p.end());

    ll counter(0);
    for (ll i=0; i<n; i++)
    {
        if (sorted[i] - p[i]) counter++; 
    }

    if (counter <= 2)
        cout << "YES" << endl;
    else
        cout << "NO" << endl;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n,m;
string s1,s2;
int mi[3001][3001];
int pi[3001][3001];
/*
int fun(int i, int j)
{
  if(i==n  || j==m )
   {
     mi[i][j]=0;
     pi[i][j]=0;
     return 0;
     }
 
     

  int ans1=0,ans2=0;
  if(s1[i]==s2[j])
   {
       ans1=1+fun(i+1, j+1);
        ans2=1;
	  }
	 else
	 { 		int p1,p2;
			p1=fun(i+1,j);
			p2=fun(i,j+1);
		if(p1>p2)
		{
	        ans1=p1;
	         ans2=2;
	      }
	      
	      else
	      {
	        ans1=p2;
	        ans2=3;
			}
			
			}
			
			mi[i][j]=ans1;
			pi[i][j]=ans2;
			
	return ans1;
	}
	* 
	*/

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cin>>s1>>s2;
	
	
	n=s1.size();
	m=s2.size();
	for(int i=n-1;i>=0;i--)
	{
			for(int j=m-1;j>=0;j--)
			{
				if(s1[i]==s2[j])
				{
					mi[i][j]=1+mi[i+1][j+1];
					pi[i][j]=1;
				}
				
				else if(mi[i+1][j] >mi[i][j+1])
				{
					 mi[i][j]=mi[i+1][j];
					 pi[i][j]=2;
				 }
				 
				 else
				 {
					 mi[i][j]=mi[i][j+1];
					 pi[i][j]=3;
				  }
			}
			
	 }
					 
				
				 
	string s;
	
	int i=0;
	int j=0;
	
	while(i!=n && j!=m)
	{
		if(pi[i][j]==1)
		{
			s+=s1[i];
			i++;
			j++;
		 }
		 
		 else if(pi[i][j]==2)
		 {
			  i++;
		 }
		 else
		  j++;
	  }
		 
	
	
	cout<<s<<endl;
	
	return 0;
	}
	


Measured memory_bytes: 70656
#include <algorithm>
#include <iostream>
#include <vector>
#include <string>
using namespace std;
 
int main()
{
  int n, m;
  cin >> n >> m;
  vector<int> input(n,0);
  int sum = 0;
  for (int i = 0; i < n; i++) {
    cin >> input.at(i);
  }
  
  int max = 0;
  for (int i = 0; i < n; i++) {
    if(i < m){
      sum += input[i];
    }else{
      sum = sum - input[i-m] + input[i];
    }
    if(sum > max) max = sum;
  }
  
  cout << (max + m)/2;
  
  if((max + m)%2 == 0)
    cout << "" << endl;
  else
    cout << ".5" << endl;
  
  return 0;
}

Measured memory_bytes: 1024
#include <iostream>

using namespace std;

int main()
{
    int i, h, m, s;
    
    cin >> i;
    
    h=i/3600;
    m=i/60-h*60;
    s=i%60;
    
    cout << h << ":" << m << ":" << s << endl;

    return 0;
}



Measured memory_bytes: 3048
// https://atcoder.jp/contests/dp/tasks/dp_d
#include<iostream>
#include <cstdlib>
#include <algorithm>

using namespace std;


struct object{
	int weight,value;
};

object arr[100007];
long long dp[100007][107];

long long res(int weight, int n)
{
	if(n<=0 || weight<=0)
		return 0;
	if(dp[weight][n])
		return dp[weight][n];
	if(arr[n-1].weight <= weight)
		dp[weight][n] = max( res(weight-arr[n-1].weight,n-1) + arr[n-1].value, res(weight,n-1));
	else
		dp[weight][n] = res(weight,n-1);
	return dp[weight][n];
}

int main()
{
	ios_base::sync_with_stdio(false);cin.tie(NULL);
	int n,w;
	cin >> n >> w;
	for(int i=0;i<n;i++)
		cin >> arr[i].weight >> arr[i].value;
	cout << res(w,n) << endl;
	return 0;
}

Measured memory_bytes: 86392
#include <iostream>
#include <string>
#include <stack>
#include <cstdlib>
#include <cstdio>
using namespace std;
stack <int> st;
int solve(string);
int main(){
  string str;
  while(cin>>str){
    if(str=="+"||str=="-"||str=="*"||str=="/")
      st.push(solve(str));
    else st.push(atoi(str.c_str()));
    if(getchar()=='\n'){
      cout << st.top() << endl;
      return 0;
    }
  }
}
int solve(string str){
  int b = st.top(); st.pop();
  int a = st.top(); st.pop();
  if(str=="+")return a+b;
  else if(str=="-")return a-b;
  else if(str=="*")return a*b;
  else if(str=="/")return a/b;
}


Measured memory_bytes: 3156
import math
from functools import reduce
n = int(input())
ans = 0
li = []
buf = n

for i in range(1,n+1):
    for j in range(1,n+1):
        tmp = math.gcd(i,j)
        li.append(tmp)
for i in range(len(li)):
    for j in range(1,n+1):
        ans += math.gcd(li[i],j)

print(ans)


Measured memory_bytes: 9852
#include <stdlib.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <cmath>


using namespace std;

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

    int A[3][N+5];
    int DP[3][N+5];

    for(int i=1;i<=N;i++){
        cin >> A[1][i];
        DP[0][i]=0;
    }
    DP[0][0]=0;
    DP[1][0]=0;
    DP[2][0]=0;
    for(int i=1;i<=N;i++){
        cin >> A[2][i];
    }

    for(int i=1;i<=2;i++){
        for(int j=1;j<=N;j++){
            DP[i][j] = max(DP[i-1][j], DP[i][j-1]) + A[i][j];
        }
    }
    cout << DP[2][N] << endl;
    return 0;
    
}


Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
main(){
  char str[100],str1[100];
  int cnt=0,i,l,j;

  while(scanf("%s",str)!=EOF){
    l=strlen(str);
    for(i=0,j=l-1;j>=0;i++,j--) str1[i]=str[j];
    str1[l]='\0';
    if(strcmp(str,str1)==0)cnt++;
  }

  printf("%d\n",cnt);
  return 0;
}
  

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

a = []
b = []

for i in range(n):
    a.append(input())
for i in range(m):
    b.append(input())
OKFlag = False

for i in range(n*n):
    SPRow,SPColumn = divmod(i,n)
    if SPRow + m-1 <= n-1 and SPColumn + m-1 <= n-1:
        for j in range(m*m):
            MPRow,MPColumn = divmod(j,m)

            if a[SPRow + MPRow][SPColumn + MPColumn] == b[MPRow][MPColumn]:
                if MPRow == (m-1) and MPColumn == (m-1):
                    OKFlag = True
                continue
            else:
                break
    else:
        continue
print("Yes" if OKFlag else "No")

Measured memory_bytes: 3064
from collections import defaultdict

n = int(input())
arr = list(map(int, input().split()))

d = defaultdict(int)
for x in arr:
    d[x] += 1

a = d[0] + d[1] + d[2]
ans = [a]

for i in range(max(arr) - 2):
    a -= d[i]
    a += d[i + 3]
    ans.append(a)

print(max(ans))

Measured memory_bytes: 24552
K = int(input())
l = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
 
print(l[K-1])

Measured memory_bytes: 3060
#include <iostream>
#include <sstream>
#include <string>
#include <cmath>
#include <cstdio>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <functional>
#include <numeric>
#include <iomanip>

using namespace std;
typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;

#define REP(i,n) for(int i = 0; i < (int)(n); ++i)
#define FOR(i,a,b) for(int i = (a); i < (int)(b); ++i)
#define ALL(c) (c).begin(), (c).end()
#define SIZE(v) ((int)v.size())

#define pb push_back
#define mp make_pair
#define mt make_tuple

int main(void)
{
    cin.sync_with_stdio(false);
    string s;
    cin >> s;
    int K;
    cin >> K;

    string ans = "";
    for (auto ch : s) {
        if (ch == 'a') {
            ans += 'a';
            continue;
        }
        int need = 26 - (ch - 'a');
        if (need <= K) {
            ans += 'a';
            K -= need;
        }
        else {
            ans += ch;
        }
    }

    int num = ans.back() - 'a';
    num = (num + K) % 26;
    ans.back() = ('a' + num);

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 768
#include <iostream>
#include <algorithm>

#define MAX_N 101

int N, A, B, C[MAX_N], cal[MAX_N], all = 0;

int main(){
    int in;
    std::cin >> N >> A >> B >> in;
    
    for(int i = 0; i < N; ++i)
        std::cin >> cal[i];
        
    std::sort(cal, cal + N, std::greater<int>());
    
    all = in;
    int ans = all / A;
    all += cal[0];
    for(int i = 0; i < N; ++i){
        ans = std::max(ans, all / (A + B * (i + 1)));
        all += cal[i + 1];
    }
    std::cout << ans << std::endl;
    return 0;
}

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

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

int main(){
	int t;
	while(cin >> t, t){
		int n, sum=0;
		cin >> n;
		rep(i,n){
			int s, f;
			cin >> s >> f;
			sum += f-s;
		}
		if( t <= sum )
			cout << "OK" << endl;
		else
			cout << t-sum << endl;
	}
	return 0;
}

Measured memory_bytes: 1160
#include<stdio.h>
#define INF 999999999

int m[101][101];
int p[101];

void matrixChainOrder(int n){
  int i,j,k,l,q;
  
  for(i=1;i<=n;i++) m[i][i] = 0;

  for(l=2;l<=n;l++){
    for(i=1;i<=n-l+1;i++){
      j = i+l-1;
      m[i][j] = INF;
      for(k=i;k<j;k++){
	q = m[i][k]+m[k+1][j]+((p[i-1])*(p[k])*(p[j]));
	m[i][j] = min(m[i][j],q);
      }
    }
  }
  
}

int min(int a,int b){
  if(a <= b) return a;
  else return b;
}

int main(){
  int i,n,k,c=0;
  
  scanf("%d",&n);
  scanf("%d %d",&p[0],&p[1]);
  
  for(i=2;i<=n;i++){
    scanf("%d %d",&k,&p[i]);
   
  }
  matrixChainOrder(n);

  printf("%d\n",m[1][n]);
  return 0;
}
    



Measured memory_bytes: 2104
#include <iostream>
#include <algorithm>
#include <vector>
#include <unordered_map>
#include <cmath>
#include <string>

using std::cin;
using std::cout;
using std::endl;
using std::max;
using std::min;
using std::sort;
using std::string;
using std::vector;

using ll = long long int;

#define rep(i,s,t)for(ll i = s;i <= t;i++)
#define rrep(i,s,t)for(ll i = s;i >= t;i--)

int main()
{
	ll a, b;
	cin >> a >> b;

	if(a > b){
		ll c = a;
		a = b;
		b = c;
	}

	rep(i,0,b - 1)cout << a;

	cout << endl;

	return 0;
}


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

using namespace std;

typedef long long ll;

int main()
{
    ll A,B,C,D;
    cin >> A >> B >> C >> D;
    int flag = 1;
    while (1)
    {
        if(flag == 1) {
            if(C - B <= 0) {
                cout << "Yes" << endl;
                break;
            }
            C = C - B;
        } else {
            if (A - D <= 0) {
                cout << "No" << endl;
                break;
            }
            A = A - D;
        }
        flag *= -1;
    }
}

Measured memory_bytes: 3640
#include <iostream>
using namespace std;
int main(void){
  for(;;){
    int h, w;
    cin >> h >> w;
    if(h == 0 && w == 0){ return 0; }
    string r[h];
    for(int i=0;i<h;i++){
      cin >> r[i];
    }
    string s;
    cin >> s;

    // Constructing a mapping from character to coordiante:
    // c |-> (x[c], y[c]) 
    int x[128]; int y[128];
    for(int i=0;i<h;i++){
      for(int j=0;j<w;j++){
	x[r[i][j]] = i;
	y[r[i][j]] = j;
      }
    }

    int tempx = 0; int tempy = 0;
    int d=0;
    for(int i=0;i<s.length();i++){
      d += abs(x[s[i]] - tempx) + abs(y[s[i]] - tempy) + 1;
      tempx = x[s[i]]; tempy = y[s[i]];
    }

    cout << d << endl;
  }
}



Measured memory_bytes: 3164
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <climits>
#include <vector>
#include <map>
#include <set>
#include <list>
#include <stack>
#include <queue>
#include <algorithm>
#include <iostream>
#include <string>

#define REP(i,n) for(int i=0;i<n;++i)
#define REPR(i,n) for(int i=n;i>=0;--i)
#define REPI(itr,v) for(auto itr=v.begin();itr!=v.end();++itr)
#define REPIR(itr,v) for(auto itr=v.rbegin();itr!=v.rend();++itr)
#define FOR(i,a,b) for(int i=a;i<b;++i)
#define SORT(v,n) sort(v, v+n)
#define SORTV(v) sort(v.begin(), v.end())
#define ALL(v) v.begin(),v.end()
#define llong long long
#define INF 999999999
#define SUR 1000000007
#define pb push_back
#define pf push_front
#define MP make_pair

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

using namespace std;

typedef pair<int,int> pii;

bool isbig(int a, int b, int c, int d){
  if(a*a + b*b > c*c + d*d){
    return true;
  }else if(a*a + b*b == c*c + d*d){
    return a > c;
  }
  return false;
}

int main(){

  const int N = 151;
  while(true){
    int h, w;
    scanf("%d %d", &h, &w);

    if(h == 0 && w == 0){
      break;
    }

    int x = -1, y = -1;
    bool found = false;
    FOR(i,1,N){
      FOR(j,i+1,N){
        if(i == h && j == w){
          continue;
        }

        if(!found){
          if(isbig(i,j,h,w)){
            x = i, y = j;
            found = true;
            //cout << x << " " << y << endl;
          }
        }else{
          if(isbig(i,j,h,w) && isbig(x,y,i,j)){
            x = i;
            y = j;
          }
        }
      }
    }
    printf("%d %d\n", x, y);
  }
  return 0;
}




Measured memory_bytes: 3156
use std::io::*;
use std::str::FromStr;
use std::char::*;
use std::cmp::*;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char) 
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

//const MAX:usize = 100006;

fn main(){
    println!("{}", (read::<u32>()).pow(2));
}

Measured memory_bytes: 4352
import sys
input = sys.stdin.buffer.readline
 
H, W, M = map(int, input().split())
 
X = [0] * W
Y = [0] * H
Map = []
 
for _ in range(M):
    h, w = map(int, input().split())
    h -= 1
    w -= 1
    Y[h] += 1
    X[w] += 1
    Map.append((h, w))
 
MX = max(X)
MY = max(Y)
ans = MX + MY
Xans = set()
Yans = set()
for i, x in enumerate(X):
    if x == MX:
        Xans.add(i)
for i, y in enumerate(Y):
    if y == MY:
        Yans.add(i)
cnt = 0
for h, w in Map:
    if h in Yans and w in Xans:
        cnt += 1
if cnt == len(Xans) * len(Yans):
    ans -= 1
print(ans)

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


void solve(long long A, long long B, long long C){
    cout << (A ^ B ^ C) << endl;
}

// Generated by 1.1.3 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long A;
    scanf("%lld",&A);
    long long B;
    scanf("%lld",&B);
    long long C;
    scanf("%lld",&C);
    solve(A, B, C);
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define V vector<long long>
#define VV vector<vector<long long>>
#define VVV vector<vector<vector<long long>>>
#define P pair<ll,ll>
#define rep(i,n) for(ll (i)=0;(i)<(n);++(i))
using namespace std;

int main() {
    ll x;
    cin>>x;
    ll a,b;
    for(ll i=1;i<sqrt(x)+1;i++){
        if(x%i==0){
            ll y=i;
            ll z=x/i;
            ll hanbetu=5*y*y*y*y+20*z;
            ll sq=sqrt(hanbetu);
            if(sq*sq!=hanbetu)continue;
            ll a1=sq-5*y*y;
            ll a2=-sq-5*y*y;
            if(a1%10==0){
                ll c=y;
                ll d=a1/10;
                ll han=c*c+4*d;
                ll sqq=sqrt(han);
                if(sqq*sqq==han){
                    ll aa1=sqq-c;
                    ll aa2=-sqq-c;
                    if(aa1%2==0){
                        b=aa1/2;
                        a=b+c;
                        break;
                    }
                    if(aa2%2==0){
                        b=aa2/2;
                        a=b+c;
                        break;
                    }
                }
            }
            if(a2%10==0){
                ll c=y;
                ll d=a2/10;
                ll han=c*c+4*d;
                ll sqq=sqrt(han);
                if(sqq*sqq==han){
                    ll aa1=sqq-c;
                    ll aa2=-sqq-c;
                    if(aa1%2==0){
                        b=aa1/2;
                        a=b+c;
                        break;
                    }
                    if(aa2%2==0){
                        b=aa2/2;
                        a=b+c;
                        break;
                    }
                }
            }
        }
    }
    cout<<a<<" "<<b<<endl;
}


Measured memory_bytes: 3684
#include <bits/stdc++.h>
using namespace std;
#define MAX 10010

#define int long long

int cost[100010];
int unit[100010];
unordered_map<int, map<int, int> > dp;
int cap; int n;

int func(int i, int w)
{
    if(i==n) return 0;
    if(dp[i][w]!=0) return dp[i][w];
    int p1;
    if(w+unit[i]<=cap) {
        p1=cost[i]+func(i+1, w+unit[i]);
    }
    else p1=0;
    int p2=func(i+1, w);
    dp[i][w]=max(p1, p2);
    return dp[i][w];
}

int32_t main ()
{
    cin>>n>>cap;
    for(int i=0; i<n; i++) {
        cin>>unit[i]>>cost[i];
    }
    cout<<func(0,0)<<endl;
    return 0;
}


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

#define Fast ios_base::sync_with_stdio(0);cin.tie(0),cout.tie(0)
#define FO freopen("in.txt", "r", stdin)
#define FC freopen("out.txt", "w", stdout)
#define aise cout<<"aise"<<endl
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define mp make_pair
#define ll long long
#define all(x) x.begin(), x.end()
#define mset(v, a) memset(v, a, sizeof(v))
#define pll pair< ll, ll >
#define pdd pair< double, double >
#define ff first
#define ss second
#define pi acos(-1.0)
#define mxN 2010
#define inf 1e9
#define MOD 1000000007

int main()
{

    string ss, t;
    cin >> ss >> t;
    vector<ll> s(26,0), tt(26,0);
    for(ll i = 0; i < ss.size(); i++) s[ss[i] - 'a']++;
    for(ll i = 0; i < t.size(); i++) tt[t[i] - 'a']++;
    sort(s.begin(), s.end());
    sort(tt.begin(), tt.end());
    if(s==tt) cout << "Yes";
    else cout << "No";
}


Measured memory_bytes: 776
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
typedef unsigned int uint;
using namespace std;

int main(){
  int N,K;
  cin >> N >> K;
  int A[N];
  for(int i=0;i<N;i++){
    cin >> A[i];
  }

  int i=0;
  int ans=0;
  while(i<N-1){
    i += K-1;
    ans++;
  }

  cout << ans;
  return 0;
}


Measured memory_bytes: 640
#include <cstdio>
using namespace std;

int bsort(int *a, int n) {
  int t, c = 0;
  for (int i=0; i<n-1; i++) {
    for (int j=0; j<n-i-1; j++) {
      if (a[j] > a[j+1]) {
        t = a[j];
        a[j] = a[j+1];
        a[j+1] = t;
        ++c;
      }
    }
  }
  return c;
}

int main() {
  int n, a[100];
  while (1) {
    scanf("%d", &n);
    if (!n) break;
    for (int i=0; i<n; i++) {
      scanf("%d", &a[i]);
    }
    printf("%d\n", bsort(a, n));
  }
  return 0;
}

Measured memory_bytes: 1028
#include <iostream>
#include <array>
#include <algorithm>

int main()
{
    int a, b, c;
    std::cin >> a >> b >> c;
    std::array<int, 3> inputs = {a, b, c};

    std::sort(inputs.begin(), inputs.end());

    std::cout << inputs.at(0) << " " << inputs.at(1) << " " << inputs.at(2) << std::endl;

    return 0;
}


Measured memory_bytes: 3152
N = int(input())
d = [list(map(int,input().split())) for i in range(N)]
#print(d[1][0])
s=0
for x in range(0,N):
  for y in range(0,N):
    s += (((d[x][0]-d[y][0])**2)+((d[x][1]-d[y][1])**2))**(1/2)

print(s/N)

Measured memory_bytes: 3064
#include <iostream>
#include <fstream>
#include <cassert>
#include <typeinfo>
#include <vector>
#include <stack>
#include <cmath>
#include <set>
#include <map>
#include <string>
#include <algorithm>
#include <cstdio>
#include <queue>
#include <iomanip>
#include <cctype>
#include <random>
#include <complex>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<59;
const double pi=acos(-1);
const double eps=1e-7;
const ll mod=1e9+7;
const int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};

int n,m;

int main(){
	cin>>n>>m;
	cout<<(1<<m)*(n*100+m*1800)<<endl;
}

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

signed main(){
  string S,ans="AC";
  cin>>S;
  int SL=S.size();
  if(S[0]!='A')ans="WA";
  int co=0;
  for(int i=1;i<SL;i++){
    if(isupper(S[i])){
      if(i==1||i==SL-1||S[i]!='C')ans="WA";
      co+=1;
    }
  }
  if(co!=1)ans="WA";
  cout<<ans<<endl;
}

Measured memory_bytes: 256
def main()
  n = gets.chomp.to_i
  a = []
  b = []
  sum_ary = []
  result = 0
  for i in 0..(n-1) do
    a[i], b[i] = gets.chomp.strip.split(' ').map(&:to_i)
    sum_ary[i] = a[i] + b[i]
    result -= b[i]
  end

  sum_ary = sum_ary.sort.reverse
  index=0
  while sum_ary.size > index do
    result += sum_ary[index] if index.even?
    index += 1
  end
  
  puts "#{result}"
end
main


Measured memory_bytes: 5884
#include <iostream>
#include <vector>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <set>
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define RREP(i, n) for (int i = (n) - 1; 0 <= i; --i)
using namespace std;
using ll = long long;
using arr = vector<ll>;
constexpr ll MOD = 1000000007;
constexpr ll INF = 1LL << 60;
constexpr int MAX = 2020;

string s, t;

int main()
{
  cin >> s >> t;
  int n = (int)s.size();
  int m = (int)t.size();
  s += s;
  vector<arr> next(n * 2 + 1, arr(26, -1));
  RREP(i, n * 2 - 1) {
    REP(j, 26) {
      if (s[i] - 'a' == j) {
        next[i][j] = i;
      } else {
        next[i][j] = next[i + 1][j];
      }
    }
  }

  ll ans = 0;
  ll pos = 0;
  REP(i, m) {
    if (next[pos][t[i] - 'a'] == -1) {
      cout << -1;
      return 0;
    }
    ans += next[pos][t[i] - 'a'] - pos + 1;
    pos = (next[pos][t[i] - 'a'] + 1) % n;
  }
  cout << ans;
  return 0;
}

Measured memory_bytes: 49024
/*
AUTHOR : Chandan Agrawal
College : Poornima College of Engg. jaipur, Raj
Mail : chandanagrawal23@gmail.com
*/

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

#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define MAX 100050

#define ll long long
#define ld long double
#define lli long long int

#define pb emplace_back
#define INF 1000000000
#define mod 1000000007

// trignometric function always give value in Radians only
#define PI acos(-1) //3.1415926535897932384626433832795028
#define dsin(degree) sin(degree*(PI/180.0))
#define dcos(degree) cos(degree*(PI/180.0))
#define dtan(degree) tan(degree*(PI/180.0))

#define rsin(radian) sin(radian)
#define rcos(radian) cos(radian)
#define rtan(radian) tan(radian)

#define loop(i,n) for (lli i = 0; i < n; i++)
#define loopitr(xt,vec) for (auto xt : vec)
#define FOR(i,a,b) for (lli i = a; i < b; i+=1)
#define loop_rev(i,n) for (lli i = n-1; i >= 0; i--)
#define FOR_REV(i,a,b) for (lli i = a; i >= b; i--)
#define itr :: iterator it
#define WL(t) while(t --)

#define all(v) v.begin(),v.end()
#define sz(x) int(x.size())
#define F first
#define S second

#define mii map<lli,lli>
#define vi vector<lli>
#define seti set<lli>
#define pii pair<lli,lli>

#define gcd(a,b) __gcd((a),(b))
#define lcm(a,b) (a/gcd(a,b))*b
#define abs(x) ((x < 0)?-(x):x)

template <typename T>
void print(T x){cout<<x<<endl;}
template <typename T1, typename T2>
void print2(T1 x,T2 y){cout<<x<<" "<<y<<endl;}
template <typename T1, typename T2,typename T3>
void print3(T1 x, T2 y,T3 z){cout<<x<<" "<<y<<" "<<z<<endl;}

#define scanarr(a,n) for(lli i=0;i<n;i++)    cin>>a[i];
#define scanvector(a,n) for(lli i=0;i<n;i++){ lli x ; cin>>x; a.push_back(x);}

#define printarr(a,n) for(lli i=0;i<n;i++)   cout<<a[i]<<" "; cout<<endl;
#define printvector(vec) for(auto xt : vec) cout<<xt<<" ";    cout<<"\n";
#define printset(st) for(auto xt : st) cout<<xt<<" ";    cout<<"\n";

#define FD(N) fixed<<setprecision(N)

#define endl '\n'

#define deb(x) cout<<#x<<" "<<x<<endl;

// chandan1,2
void chandan1(){int y=1;return;}
void chandan2(){
        loop(i,10){
        lli x=1;
    }
    return(chandan1());
}

bool isPrime(lli n){
if(n<=1) return false;
if(n<=3) return true;
if(n==5) return true;
if((n%2==0)||(n%3==0) || (n%5==0)) return false;
for(lli i=5;i*i<=n;i+=6)
    if((n%i==0)||(n%(i+2)==0))
        return false;
return true;
}

bool ispower2(lli n){
    return(n and (n&(n-1))==0 );
}

int main(){
fastio
lli t=1;
//cin>>t;
chandan2();
while(t--) {
    lli n;
    string s;
    char ch;
    cin>>ch;
    if(ch>='a' and ch<='z')
        print('a');
    else
        print('A');
  }
return 0;
}

Measured memory_bytes: 3616
#include<bits/stdc++.h>
#define N 109
using namespace std;
typedef long long ll;
int main(void)
{
    //freopen("in.txt","r",stdin);
 
    ll n;
    scanf("%lld",&n);
    ll s=0;
    for(ll i=1;i<=n;i++)
    {
        if(i%3!=0 && i%5!=0) s+=i;
    }
    printf("%lld\n",s);
    return 0;
}

Measured memory_bytes: 3812
#include<iostream>
#include<iomanip>
#include<cassert>
#include<stdexcept>
#include<utility>
#include<functional>
#include<numeric>
#include<cmath>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<array>
#include<stack>
#include<queue>
#include<deque>
#include<vector>
#include<complex>
#include<set>
#include<map>
#include<unordered_map>
#include<unordered_set>
#include<string>
#include<bitset>
#include<memory>
using namespace std;
using ll=long long;

int main(){
    string s;
    cin>>s;
    cout<<s.substr(0,3)<<endl;
    
    return 0;
}


Measured memory_bytes: 3628
// Last Change: 04/20/2019 21:06:54.
#include <algorithm>
#include <array>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;
using ll = long long;

namespace NS {
void LoopUntilZeroInpput() {
  int hogegegege = 0;
  while (cin >> hogegegege && hogegegege != 0) {
  }
}
} // namespace NS

int main() {
  int N, K;
  string S;
  cin >> N >> S >> K;

  char tar = S[K - 1];
  for (int i = 0; i < N; ++i) {
    if (S[i] != tar) {
      S[i] = '*';
    }
  }

  cout << S << endl;

  //NS::LoopUntilZeroInpput();
}


Measured memory_bytes: 256