akhauriyash/Code-Regression huggingface dataset:
import java.util.*;
public class Main
{
	public static void main(String[] args) 
	{
		Scanner in=new Scanner(System.in);
		for(;;)
		{
			int n=in.nextInt();
			if(n==0)
				return;
			Point p[]=new Point[n];
			boolean exist[][]=new boolean[5001][5001];
			int max=0;
			for(int i=0;i<n;i++)
			{
				int x=in.nextInt(),y=in.nextInt();
				p[i]=new Point(x,y);
				exist[x][y]=true;
			}
			for(int i=0;i<n;i++)
				for(int j=0;j<n;j++)
				{
					if(i==j)
						continue;
					int x1=p[i].x,y1=p[i].y;
					int x2=p[j].x,y2=p[j].y;
					if(x2-y2+y1>=0&&y2+x2-x1>=0&&x1+y1-y2>=0&&y1+x2-x1>=0)
						if(x2-y2+y1<=5000&&y2+x2-x1<=5000&&x1+y1-y2<=5000&&y1+x2-x1<=5000)
							if(exist[x2-y2+y1][y2+x2-x1]&&exist[x1+y1-y2][y1+x2-x1])
								max=Math.max(max,(x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
				}
			System.out.println(max);
		}
	}
}
class Point
{
	int x;
	int y;
	Point(int x,int y)
	{
		this.x=x;
		this.y=y;
	}
}

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

using namespace std;
int main(){
	int n,k;
        string s;
	cin >> n >> k;
	cin >> s;
	if(s[k-1] == 'A') s[k-1] = 'a';
	else if (s[k-1] == 'B') s[k-1] = 'b';
	else if (s[k-1] == 'C') s[k-1] = 'c';
	cout << s << endl;
        return 0;
}

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

using namespace std;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int a, b, c;
    cin >> a >> b >> c;
    int ans = min(c, a + b + 1);
    ans += b;
    cout << ans << '\n';
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <string>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define REP(i, b, n) for (int i = (b); i < (n); i++)
using namespace std;
using ll = long long;
const ll M = 1000000007;

int main() {
	int n;
	cin >> n;
	int d1, d2;
	int cnt = 0;
	rep(i, n) {
		cin >> d1 >> d2;
		if (d1 == d2) cnt++;
		else cnt = 0;
		if (cnt >= 3) {
			cout << "Yes" << endl;
			return 0;
		}
	}
	cout << "No" << endl;
}

Measured memory_bytes: 3624
#include <iostream>
#include <fstream>
#include <algorithm>
#include <cmath>
#include <math.h>
#include <string>
#include <cstring>
#include <vector>
#include <iomanip>
#include <stack>
#include <queue>
#include <cstdio>
#include <cstdlib>
#include <numeric>
#include <array>
#include <set>
#include <regex>
 
using namespace std;
using ll = long long;
 
#define endl "\n"
#define pb push_back
#define in insert

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

    string s;
    cin >> s;
    string x = s;
    reverse(s.begin(), s.end());
    ll cnt = 0;
    for(int i = 0; i < s.size(); i++) {
        if(x[i] != s[i]) {
            cnt++;
        }
    }
    cout << cnt / 2;
}

Measured memory_bytes: 256
#pragma GCC optimize(2)
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <time.h>
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <fstream>
#include <vector>
#include <bitset>
#include <queue>
#include <stack>
#include <map>
#include <set>

using namespace std;

const int MAXN = 505;

int n,ans;
int f[MAXN][MAXN];

bool vis[MAXN][MAXN];

queue<pair<int,int> > Q;

int main()
{
	scanf("%d",&n);
	for (int i = 1;i <= n;i++)
		for (int j = 1;j <= n;j++)
		{
			vis[i][j] = 1;
			f[i][j] = min(min(i - 1,j - 1),min(n - i,n - j)) + 1;
		}
	for (int p,i = 1;i <= n * n;i++)
	{
		scanf("%d",&p);
		int x = (p - 1) / n + 1,y = p - (x - 1) * n;
		ans += f[x][y] - 1;
		vis[x][y] = 0;
		f[x][y] = min(min(f[x - 1][y],f[x][y - 1]),min(f[x + 1][y],f[x][y + 1]));
		Q.push(make_pair(x,y));
		while (!Q.empty())
		{
			x = Q.front().first,y = Q.front().second;
			Q.pop();
			if (x > 1 && f[x - 1][y] > f[x][y] + vis[x - 1][y])
			{
				f[x - 1][y] = f[x][y] + vis[x - 1][y];
				Q.push(make_pair(x - 1,y));
			}
			if (y > 1 && f[x][y - 1] > f[x][y] + vis[x][y - 1])
			{
				f[x][y - 1] = f[x][y] + vis[x][y - 1];
				Q.push(make_pair(x,y - 1));
			}
			if (x < n && f[x + 1][y] > f[x][y] + vis[x + 1][y])
			{
				f[x + 1][y] = f[x][y] + vis[x + 1][y];
				Q.push(make_pair(x + 1,y));
			}
			if (y < n && f[x][y + 1] > f[x][y] + vis[x][y + 1])
			{
				f[x][y + 1] = f[x][y] + vis[x][y + 1];
				Q.push(make_pair(x,y + 1));
			}
		}
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 5032
#include <iostream>
#include <stdio.h>
#include <string.h>
using namespace std;



int main()
{
    int a[26]={0},b[26]={0};
    int l1,l2,i;
    int flag_final=0;
    char ch1[101],ch2[101];
    scanf("%s",ch1);
    l1=strlen(ch1);
    for(i=0;i<l1;i++)
    {
        a[ch1[i]-'a']++;
    }
    scanf("%s",ch2);
    l2=strlen(ch2);
    for(i=0;i<l2;i++)
    {
        b[ch2[i]-'a']++;
    }
    int flag=0;
    for(i=0;i<26;i++)
    {
        if(a[i]!=b[i]) {flag=1;break;}
    }
    if(flag==1) {printf("No\n");return 0;}
    for(i=0;i<l1;i++)
    {
        int sum=0,j;
        for(j=0;j<l2;j++)
        {
            if(ch1[j]==ch2[(i+j)%l2])
                sum++;
        }
        if(sum==l2)
            flag_final=1;
    }
    if(flag_final==1) printf("Yes\n");
    else printf("No\n");
    return 0;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
 
## Library
 
import sys
from fractions import gcd
import math
from math import ceil,floor
import collections
from collections import Counter
import itertools
import copy

## input
 
# N=int(input())
# A,B,C,D=map(int, input().split())
# S = input()
# yoko = list(map(int, input().split()))
# tate = [int(input()) for _ in range(N)]
# N, M = map(int,input().split()) 
#    P = [list(map(int,input().split())) for i in range(M)]
#    S = []
#    for _ in range(N):
#        S.append(list(input()))

def combination(n,r):
    return int(math.factorial(n)/math.factorial(r)/math.factorial(n-r))
 
N=int(input())
L = list(map(int, input().split()))

L.sort()

if N<=2 or len(Counter(L))<3:
    print(0)
    sys.exit()

tmp = list(itertools.combinations(L,3))
ans = 0


for i in range(len(tmp)):
    if tmp[i][0] == tmp[i][1] or tmp[i][1] == tmp[i][2] or tmp[i][2] == tmp[i][0] or tmp[i][0] + tmp[i][1] <= tmp[i][2]:
        continue
    else:
        ans += 1

print(ans)


Measured memory_bytes: 93552
d = {0: 1}
s, p = 0, 1
for c in reversed(input()):
  s = (s + p * int(c)) % 2019
  d[s] = d.get(s, 0) + 1
  p = p * 10 % 2019
print(sum(x * (x - 1) // 2 for x in d.values()))


Measured memory_bytes: 9352
#include <cmath>
#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>

using namespace std;

using ll = long long;
using ld = long double;
using P = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
ld EPS = 1e-12;
int INF = numeric_limits<int>::max() / 2;
ll LINF = numeric_limits<ll>::max() / 2;
int MOD = 1e9 + 7;
#define rep(i,n) for(int i = 0; i < n; i++)
#define all(obj) (obj).begin(), (obj).end()
#define debug(x) cerr << #x << ": " << x << '\n'

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int r,g,b,n;
    cin >> r >> g >> b >> n;
    int ans = 0;
    rep(i,(n / r) + 1){
        rep(j,(n / g) + 1){
            int t = n - i * r - j * g;
            if(t >= 0 && t % b == 0) ans++;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <cmath>
#include <utility>
#include <iostream>
#include <functional>
#include <bitset>
#include <algorithm>
#include <vector>
#include <forward_list>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <numeric>
#define ll long long int
#define pb push_back
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
int mx4[] = {0,1,0,-1};
int my4[] = {1,0,-1,0};
int INF = 2e6;
ll MOD = 1e9 + 7;

int main(){
    vector<int> a(3); 
    int k;
    rep(i,3) cin >> a[i];
    cin >> k;
    int e = pow(2,k);
    sort(a.begin(),a.end());
    cout << a[0] + a[1] + a[2] * e << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<string.h>
using namespace std;
int main() {
	char st[200][20];
	int n;
	int answer = 0;
	cin >> n;
	for (int i = 0;i < n;i++) {
		cin >> st[i];
		if (i > 0) {
			if (st[i - 1][(int)strlen(st[i - 1]) - 1] != st[i][0]) {
				answer = 1;
			}
		}
	}
	for (int i = 0;i < n - 1;i++) {
		for (int i0 = i + 1;i0 < n;i0++) {
			if (strcmp(st[i], st[i0]) == 0) {
				answer = 1;
				break;
			}
		}
	}
	if (answer == 1) {
		cout << "No" << endl;
	}
	else if (answer == 0) {
		cout << "Yes" << endl;
	}
	return 0;
}


Measured memory_bytes: 256
import sys
 
 
def check(bits, M, k, s, p):
    for x in range(M):
        dec = 0
        for K in range(k[x]):
            if bits >> (s[x][K] - 1) & 1:
                dec += 1
            else:
                pass
 
        if dec % 2 == p[x]:
            pass
        else:
            return 0
 
    return 1
 
 
def main():
    N, M = map(int, input().split())
 
    k = [0] * M
    s = [0] * M
    for i in range(M):
        k[i], *s[i] = map(int, input().split())
 
 
    p = list(map(int, input().split()))
 
    ans = 0
    for bits in range(2 ** N):
        ans += check(bits, M, k, s, p)
 
    print(ans)
 
if __name__ == '__main__':
    main()

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

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

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

int compare_char(char *a,char *b){
	return strcmp(a,b);
}

int intsort(const void *a, const void *b){
	return *(int*)b - *(int*)a;
	/*qsort(a,aの配列数,sizeof(int),intsort);*/
}

int longsort(const void *a, const void *b){
	long *A=(long *)a;
	long *B=(long *)b;
	if(*A>*B) return -1;
	if(*A<*B) return 1;
	return 0;
}

int main(){
  int i,N,K,a,b;
  char ss[10000];
  scanf("%d",&N);
  a=N/100;
  b=N%100;
  if(a<13 &&a!=0){
    if(b<13&&b!=0){
      printf("AMBIGUOUS\n");
    }else{
      printf("MMYY\n");
    }
  }else{
    if(b<13&&b!=0){
      printf("YYMM\n");
    }else{
      printf("NA\n");
    }
  }
  return 0;
}

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

int main(){
    int A,B,C,K; int count=0;
    cin>>A>>B>>C>>K;

    while(A>=B){count++; B*=2;}
    while (B>=C){count++; C*=2;}
    if(K>=count){
        cout<<"Yes";
    }else cout<<"No";

    return 0;
}

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

constexpr int MOD=1000000007;

int main()
{
	for(int w;cin>>w&&w;){
		vector<string> grid(2);
		for(auto& s:grid) cin>>s;

		long long res=1;
		for(int j=0;j<w;){
			if(grid[0][j]==grid[1][j]){
				if(j==0)
					(res*=3)%=MOD;
				else if(grid[0][j-1]==grid[1][j-1])
					(res*=2)%=MOD;
				j++;
			}
			else{
				if(j==0)
					(res*=6)%=MOD;
				else if(grid[0][j-1]==grid[1][j-1])
					(res*=2)%=MOD;
				else
					(res*=3)%=MOD;
				j+=2;
			}
		}
		cout<<res<<endl;
	}
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define all(v) v.begin(), v.end()
int garr[100001];
vector<pair<pair<int, int>, int>> gvec;
int gv, gk;
int dp[100001][3];
long long whatdo(int n, int prev) { //-1 swim , 0 catch bugs, 1 homework
  long long ans = 0;
  if (n > gv)
    return 0;
  if (dp[n][prev] != -1)
    return dp[n][prev];
  if (prev != -1) {
    ans = max(ans, whatdo(n + 1, -1) + gvec[n].first.first);
  }
  if (prev != -0) {
    ans = max(ans, whatdo(n + 1, 0) + gvec[n].first.second);
  }
  if (prev != 1) {
    ans = max(ans, whatdo(n + 1, 1) + gvec[n].second);
  }
  return dp[n][prev] = ans;
}

void solve() {
  //----------------------VARs---------------------------------------------
  char car, car2;
  string s, st;
  long long n = 0, a = 0, b = 0, c = 0, e, d = 0, m = 0, t = 0, q = 0, r = 0,
            l = 0, middle = 0, count = 0, add = 0, k, ans = 300, temp = 0,
            rootsa, save = 0, bigg = 0, save2 = 0, counter = 0, counter2 = 0,
            sum = 0, x, y;
  bool flag = false, flag2;

  //-------- --------------VARs--------------------------------------------
  vector<int> vec;
  memset(dp, -1, sizeof(dp));
  cin >> gv;
  for (int i = 1; i <= gv; i++) {
    cin >> a >> b >> c;
    gvec.push_back(make_pair(make_pair(a, b), c));
  }
  cout << whatdo(0, 2);
}
int main() {
#ifndef ONLINE_JUDGE
  system("clear");
  freopen("Test0.in", "r", stdin);
#endif
  ios_base::sync_with_stdio(false), cin.tie(0);

  cout << fixed << setprecision(10);
  int t = 1;
  // cin >> t;
  while (t--) {
    solve();
    cout << endl;
  }
  return 0;
}


Measured memory_bytes: 13548
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <iomanip>
#include <climits>
using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<string> VS;
typedef vector< vector<int> > VVI;
typedef vector< vector<ll> > VVL;
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;
#define rep(i,n) for(ll i=0;i<(n);i++)
#define all(a) (a).begin(),(a).end()
#define pf push_front
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define ub upper_bound
#define lb lower_bound

int main(){
  ll A,B,N;
  cin>>A>>B>>N;
  if(N>=B) cout<<A*(B-1)/B<<endl;
  else cout<<A*N/B<<endl;
}


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

int main(int argc, char *argv[])
{
    int n, k, s;
    cin >> n >> k >> s;
    int t = s == 1e9 ? s - 1 : s + 1;
    for (int i = 0; i < k; i++) {
        cout << s << ' ';
    }
    for (int i = k; i < n; i++) {
        cout << t << ' ';
    }
    cout << '\n';
    return 0;
}


Measured memory_bytes: 1280
n = int(input())

xy = [[] for _ in range(n)]
for i in range(n):
    a = int(input())
    xy[i] = [[int(i) for i in input().split()] for _ in range(a)]

ans = 0
for i in range(2**n):
    lst = [0 for _ in range(n)]
    for j in range(n):
        if (i >> j) & 1:
            lst[j] = 1
    
    flag = True
    for j in range(n):
        if lst[j] == 1:
            for x, y in xy[j]:
                if lst[x - 1] != y:
                    flag = False
                    break
            else:
                continue
            break

    if flag:
        ans = max(ans, sum(lst))
print(ans)

Measured memory_bytes: 9220
import bisect

X, N = map(int,input().split())
if N == 0:
    Ps = []
else:
    Ps = list(map(int,input().split()))
Ps.sort()
for i in range(300):
    if i % 2 == 0:
        x = i//2
    else:
        x = -((i+1)//2)
    if (X + x) in Ps:
        continue
    else:
        print(X + x)
        break


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

const int N=22,M=21e5,zqm=1e9+7;
int f[M],a[N][N];

int main() {
	//freopen("in.txt","r",stdin);
	//freopen("out.txt","w",stdout);
	
	int n; scanf("%d",&n);
	for(int i=0;i<n;++i) {
		for(int j=0;j<n;++j) scanf("%d",&a[i][j]);
	}
	int S=1<<n;
	f[0]=1;
	for(int s=1;s<S;++s) {
		int x=__builtin_popcount(s);
		for(int i=0;i<n;++i) if((s&(1<<i))&&a[x-1][i]) (f[s]+=f[s^(1<<i)])%=zqm;
	}
	printf("%d\n",f[S-1]);
	
	return 0;
}


Measured memory_bytes: 8448
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
int main(void){
  int N;
  cin >>N;
  int a[N];
  int sum=0;
  for (int i=0; i<N ; i++){
      cin >> a[i];
  }
  int S=a[0];
  for (int j=0; j<N; j++){
      sum=sum+1;
      if(S==2){cout << sum << endl;
          return 0;
      }
      S=a[S-1];
      
      
  }
  cout << -1 << endl;
   return 0;

}


Measured memory_bytes: 640
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <bitset>
#define MM 4000005
#define MN 2005
using namespace std;
bitset <MM> s;
int a[MN],n,sum;

inline int read()
{
	int n=0,f=1; char c=getchar();
	while (c<'0' || c>'9') {if(c=='-')f=-1; c=getchar();}
	while (c>='0' && c<='9') {n=n*10+c-'0'; c=getchar();}
	return n*f;
}

int main()
{
	register int i;
	n=read();
	for (i=1;i<=n;++i) sum+=a[i]=read();
	s.set(0);
	for (i=1;i<=n;++i) s=s|(s<<a[i]);
	for (i=sum>>1;i>=0;--i)
		if (s.test(i)) {printf("%d",sum-i); break;}
}

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

using namespace std;

#define ll long long
#define pii pair<int,int>
vector<int> parent(200005);
vector<int> s(200005);

int find_set(int v) {
    if (v == parent[v])
        return v;
    return parent[v] = find_set(parent[v]);
}
void union_sets(int a,int b)
{
	a = find_set(a);
	b = find_set(b);
	if(a != b)
	{
		parent[b] = a;
		s[a] += s[b];
	}
}
int main()
{
	int n,m;
	cin>>n>>m;
	int x,y;
	for(int i=1;i<=n;i++)
	{
		s[i] =1;
		parent[i] =i;
	}
	for(int i=0;i<m;i++)
	{
		cin>>x>>y;
		union_sets(x,y);
	}
	int nax = INT_MIN;
	for(int i=1;i<n+1;i++)
	{
		nax = max(nax,s[i]);
	}
	cout<<nax<<endl;
}

Measured memory_bytes: 4696
#define NDEBUG
NDEBUG


#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cstring>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <memory>
#include <queue>
#include <random>


using namespace std;


// TC_REMOVE_BEGIN
/// caide keep
bool __hack = std::ios::sync_with_stdio(false);
/// caide keep
auto __hack1 = cin.tie(nullptr);
// TC_REMOVE_END


// Section with adoption of array and vector algorithms.


//#include <ext/pb_ds/tree_policy.hpp>
//#include <ext/pb_ds/assoc_container.hpp>
//
//template <class T> using StdTree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;


namespace template_util {
    

    constexpr int bytecount(uint64_t x) {
        return x ? 1 + bytecount(x >> 8) : 0;
    }

    template<int N>
    struct bytetype {
        
    };

    
    /// caide keep
    template<uint64_t N>
    struct minimal_uint : bytetype<bytecount(N)> {
    };
}


template<class T>
T next(istream& in) {
    T ret;
    in >> ret;
    return ret;
}


void solve(istream& in, ostream& out) {
  auto n = next<int>(in);
  int add = 0;
  while (n % 1000) {
    ++n;
    ++add;
  }
  out << add << "\n";
}

//#include <fstream>


int main() {
//  ifstream fin("bridges.in");
//  ofstream fout("bridges.out");
    solve(cin, cout);
//  solve(fin, fout);
    return 0;
}



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

int main(){
  int a,b,c[50]={},n,t,sum=0,max=0; cin>>a>>b;
  for(int i=0;i<a;i++){
    cin>>c[i];
  }
  for(int i=0;i<b;i++){
    max=0;
    for(int j=0;j<a-i;j++){
      if(max<c[j]){
	max=c[j];
        n=j;
      }
    }
    sum+=max;
    c[n]=c[a-1-i];
  }
  cout<<sum<<endl;
  return 0;
}



Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#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() {
    string s, t;
    cin >> s >> t;
    int sl = s.length(), tl = t.length();

    int dp[sl+1][tl+1];
    fill(dp[0], dp[sl+1], 0);

    for (int i = 0; i < sl; i++) {
        for (int j = 0; j < tl; j++) {
            if (s[i] == t[j]) {
                dp[i+1][j+1] = dp[i][j] + 1;
            } else {
                dp[i+1][j+1] = max(dp[i][j+1], dp[i+1][j]);
            }
        }
    }

    string ans = "";
    int i = sl, j = tl;
    while (dp[i][j] > 0) {
        if (s[i-1] == t[j-1]) {
            i--, j--;
            ans += s[i];
        } else if (dp[i-1][j] > dp[i][j-1]) {
            i--;
        } else {
            j--;
        }
    }

    reverse(ans.begin(), ans.end());
    cout << ans << "\n";

    return 0;
}

Measured memory_bytes: 35456
#include<bits/stdc++.h>
using namespace std ;
typedef long long ll ;
const int mod=1000000007 ;

int visited[21][21] ;
int dist[21][21] ;
char grid[21][21] ;

pair<int,int> directions[4]={{1,0},{0,1},{-1,0},{0,-1}} ;

bool valid(int x,int y,int h,int w){

	return x>=0 && y>=0 && x<h && y<w ;
}

int bfs(int sx,int sy,int h,int w){

	queue<pair<int,int>> q ;
	q.push({sx,sy}) ;
	dist[sx][sy]=0 ;
	visited[sx][sy]=1 ;

	int ans=0 ; 

	while(!q.empty()){

		int row=q.front().first ;
		int col=q.front().second ;

		q.pop() ;

		for(auto dir:directions){

			int new_row=row+dir.first ;
			int new_col=col+dir.second ;

			if(valid(new_row,new_col,h,w) && visited[new_row][new_col]==0 && grid[new_row][new_col]=='.'){

				q.push({new_row,new_col}) ;
				dist[new_row][new_col]=dist[row][col]+1 ;
				visited[new_row][new_col]=1 ;
				ans=max(ans,dist[new_row][new_col]) ;
			}


		}


	}

	return ans ;

}

void solve(){
	
	int h,w ;
	cin>>h>>w ;

	for(int i=0;i<h;i++){
		for(int j=0;j<w;j++){
			cin>>grid[i][j] ;
		}
	}

	int answer=0 ;

	for(int i=0;i<h;i++){
		for(int j=0;j<w;j++){
			if(grid[i][j]=='.')
			{	
				memset(visited,0,sizeof(visited)) ;
				memset(dist,0,sizeof(dist)) ;
				answer=max(answer,bfs(i,j,h,w)) ;
			}
		}
	}

	cout<<answer ;

}

int main(){
	
	int y ;

	y=1 ;
	//cin>>y ;

	while(y--)
	{	
		solve() ;
	}

}

Measured memory_bytes: 3628
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>
#include <fstream>
#include <bitset>
#include <time.h>
#include <tuple>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef complex<double> Point;

#define PI acos(-1.0)
#define EPS 1e-10
const ll INF = 1e15;
const ll MOD = 1e9 + 7;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,N) for(int i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define EQ(a,b) (abs((a)-(b))<EPS)
#define EQV(a,b) ( EQ((a).real(), (b).real()) && EQ((a).imag(), (b).imag()) )
#define fi first
#define se second
#define N_SIZE (1LL << 20)
#define NIL -1

int h, w;
string s[100];
int ans[100][1000];

int main() {
	cin >> h >> w;
	rep(i, h)cin >> s[i];
	rep(i, h) {
		rep(j, w) {
			if (s[i][j] == '#') {
				FOR(k, -1, 2) {
					FOR(l, -1, 2) {
						if (k == 0 && l == 0)continue;
						if (i + k >= 0 && i + k < h&&j + l >= 0 && j + l < w) {
							ans[i+k][j+l]++;
						}
					}
				}
			}
		}
	}
	rep(i, h) {
		rep(j, w) {
			if(s[i][j]!='#')cout << ans[i][j];
			else cout << s[i][j];
		}
		cout << endl;
	}
}

Measured memory_bytes: 512
/**
 *   author: malviyanshiv
 *   created: 09 January 2019  23:27:27
**/

#include <bits/stdc++.h>

using namespace std;

#define REP(i, a, b) for(int i = a; i < b; i++)
#define RREP(i, a, b) for(int i = a-1; i >= b; i--)
#define PB push_back
#define MP make_pair
#define MOD 1000000007
#define INF 0x7fffffff
#define MAX 100005

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

void fastscan(int &x){
    bool neg=false;
    register int c;
    x =0;
    c=getchar();
    if(c=='-'){
        neg = true;
        c=getchar();
    }
    for(;(c>47 && c<58);c=getchar())
        x = (x<<1) + (x<<3) +c -48;
    if(neg)
        x *=-1;
}

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

vector<int> dp(MAX, -1);
vector<int> h(MAX);

int cal(int idx, int k ){
    if( idx <= 0 )
        return 0;
    if( dp[idx] != -1 )
        return dp[idx];

    int res = INF;
    for(int i = 1; i <=k; i++ )
        if( idx-i < 0 )
            break;
        else
            res = min( res, cal(idx-i, k) + abs(h[idx]-h[idx-i]));
    return dp[idx] = res;
}


int main(){
	optimizeIO();
    int n, k;
    cin >> n >> k;
    REP(i, 0, n)
        cin >> h[i];

    cout << cal(n-1, k ) << endl;
	
	return 0;
}

Measured memory_bytes: 7296
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef long double ld;
 
#define REP(i,a,n) for(int (i)=(a); (i)<(int)(n); (i)++)
#define rep(i,n) REP(i,0,n)
#define vec vector 

int char_to_int(char c){
  switch(c){
    case '0': return 0;
	case '1': return 1;
	case '2': return 2;
	case '3': return 3;
	case '4': return 4;
	case '5': return 5;
	case '6': return 6;
	case '7': return 7;
	case '8': return 8;
	case '9': return 9;
	default: return 0;
  }
}



int main(){
  
  string A_str, B_str;
  cin >> A_str >> B_str;
  
  string res;

  if(A_str.size() > B_str.size()){
    res = "GREATER";
  }else{
    if(A_str.size() < B_str.size()){
      res = "LESS";
    }else{
      rep(i, A_str.size()){
        if(char_to_int(A_str.at(i)) > char_to_int(B_str.at(i))){
          res = "GREATER";
          break;
        }
        if(char_to_int(A_str.at(i)) < char_to_int(B_str.at(i))){
          res = "LESS";
          break;
        }
      }
    }
  }
  
  
  if(res != "LESS" && res != "GREATER") res = "EQUAL";
  

  
  cout << res;
         
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  vector<int> button(N);
  for (int i = 0; i < N; i++) {
    cin >> button.at(i);
  }
  int A = 1, C = 0;
  for (int i = 0; i < N; i++) {
    A = button.at(A - 1);
    C++;
    if (A == 2) {
      cout << C << endl;
      break;
    }
  }
  if (C == N) {
    cout << "-1" << endl;
  }
}

Measured memory_bytes: 3752
#!/usr/bin/env python3
from bisect import bisect_right

n, *L = map(int, open(0).read().split())
L.sort()
ans = 0
for i in range(n):
    for j in range(i + 1, n):
        ans += (bisect_right(L, L[i] + L[j] - 1) -
                bisect_right(L, L[j] - L[i]) - 1 - (L[j] - L[i] * 2 < 0))
print(ans // 3)


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

int main() {

    int N,M,sum=0;
    cin>>N>>M;
    

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

        int x;
        cin>>x;

        sum+=x;
    }

    if(N>=sum){
        
        cout<<N-sum<<endl;
    }

    else {
        cout<<-1<<endl;
    }

}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
 
using namespace std;
 
#define mp make_pair
#define endl '\n'
using ll=long long;
 
const int INF=1e9+5;
const ll lim=(ll)3e16;
const int N=3e3+5;
const int mod=1e9+7;
const ll oo=1e18+5;


int main(){
	ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(0);
	int h,n;
	int sum=0;
	cin>>h>>n;
	for(int i=0;i<n;++i){
		int x;
		cin>>x;
		sum+=x;
	}
	if(sum>=h) cout<<"Yes";
	else cout<<"No";
	return 0;
}


Measured memory_bytes: 256
#include <cassert>
#include <cstdio>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <numeric>
#include <algorithm>

using namespace std;
using lint = long long;
constexpr int MOD = 1000000007, INF = 1010101010;
constexpr lint LINF = 1LL << 60;

template <class T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
	for (const auto &e : vec) os << e << (&e == &vec.back() ? "" : " ");
	return os;
}

#ifdef _DEBUG
template <class T>
void dump(const char* str, T &&h) { cerr << str << " = " << h << "\n"; };
template <class Head, class... Tail>
void dump(const char* str, Head &&h, Tail &&... t) {
	while (*str != ',') cerr << *str++; cerr << " = " << h << "\n";
	dump(str + (*(str + 1) == ' ' ? 2 : 1), t...);
}
#define DMP(...) dump(#__VA_ARGS__, __VA_ARGS__)
#else 
#define DMP(...) ((void)0)
#endif

int main() {

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	string s;
	cin >> s;

	bool good = true;
	for (int i = 0; i < s.size(); i++) {
		if (i & 1) {
			if (s[i] != 'L' && s[i] != 'U' && s[i] != 'D') good = false;
		}
		else {
			if (s[i] != 'R' && s[i] != 'U' && s[i] != 'D') good = false;
		}
	}

	if (good) cout << "Yes" << "\n";
	else cout << "No" << "\n";

	return 0;
}

Measured memory_bytes: 256
import math

A, B = map(int, input().split())
gcd_ab = math.gcd(A, B)
factors = set()
i = 2
while i <= math.ceil(math.sqrt(gcd_ab)):
    if gcd_ab%i == 0:
        factors.add(i)
        gcd_ab = gcd_ab // i
    else:
        i += 1
factors.add(gcd_ab)
factors.add(1)
print(len(factors))


Measured memory_bytes: 63420
import java.util.Scanner;
import java.util.Comparator;
import java.util.Arrays;
import java.util.ArrayList;

public class Main {
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int M = sc.nextInt();
		long [] A = new long [N];
		int [][] BC = new int [M][2];
		for (int i = 0; i<N; i++) {
			A[i] = sc.nextLong();
		}
		Arrays.sort(A);
		for (int i = 0; i<M; i++) {
			BC[i][0] = sc.nextInt();
			BC[i][1] = sc.nextInt();
		}
		Arrays.sort(BC, new Comparator<int[]>() { //double[]でコンパレーターを実装する
			  public int compare(int[] a,int[] b) {
			    if(a[1] > b[1]) {
			      return 1;
			    }else if (a[1] == b[1]) {
			      return 0;
			    }else {
			      return -1;
			  }}});
		
		int tmp = M-1;
		int t = 0;
		Outer:
		while(BC[0][0] >=1 && t < N) {
			if(A[t] < BC[tmp][1]) {
				A[t] = BC[tmp][1];
				BC[tmp][0]--;
				t++;
				if(BC[tmp][0] == 0) {
					tmp--;
				}
			}
			else {
				break Outer;
			}
		}
		long sum = 0;
		for (int i =0; i< N;i++) {
			sum += A[i];
		}
		System.out.println(sum);
	}
}	



Measured memory_bytes: 99152
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
typedef long long ll;
int main(){
  char n[2];
  std::cin >> n[0]>>n[1];
  if(n[0]=='9'||n[1]=='9')std::cout << "Yes" << std::endl;
  else std::cout << "No" << std::endl;
}

Measured memory_bytes: 256
X = int(input())

ans = 0
if X == 1:
    print(1)
else:
    for i in range(2, X+1):
        tmp = i
        tmp_ans = 0
        j = 2
        while tmp_ans <= X:
            tmp_ans = tmp ** j
            if tmp_ans <= X:
                ans = max(ans, tmp_ans)
            j += 1
    print(ans)


Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;

int main()
{
	double a;
	cin>>a;
	cout<<setprecision(15)<<a/3*a/3*a/3<<endl;
	return 0;

}

Measured memory_bytes: 256
#include <iostream>

using namespace std;
#define pi 3.14159265

int main()
{
	long long ans = 0, i = 0, j = 0, k = 0, l = 0;
	long long N, M;
	cin >> N >> M;

	ans += (N - M) * 100 + M * 1900;
	int adv = 1;
	for (i = 0; i < M; i++) {
		adv *= 2;
	}

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

Measured memory_bytes: 256
#include <cstdio>
#include <vector>

typedef long long ll;

using namespace std;

int main() {
    ll n, b, ans = 0, p, q;
    scanf("%lld", &n);
    vector<ll> a(n + 1);
    for (ll i = 0; i <= n; ++i) scanf("%lld", &a.at(i));
    for (ll i = 0; i < n; ++i) {
        scanf("%lld", &b);
        p = min(b, a.at(i));
        ans += p;
        b -= p;
        q = min(b, a.at(i + 1));
        ans += q;
        a.at(i + 1) -= q;
    }
    printf("%lld\n", ans);
    return 0;
}


Measured memory_bytes: 1024
S = input()
a = int(S[0:2])
b = int(S[2:4])

def YY(a):
    if 0 <= a < 100:
        return True
    else: return False

def MM(a):
    if 0 < a <13:
        return True
    else:
        return False

if MM(a) and YY(b):
    if YY(a) and MM(b):
        print('AMBIGUOUS')
    else:
        print('MMYY')
elif YY(a) and MM(b):
    print('YYMM')
else:
    print('NA')

Measured memory_bytes: 3064
#include <iostream>
#include<cmath>
#include<vector>
#include<tuple>
#include <ctime>
#include<algorithm>
#include <initializer_list>
#include <cstring> 
#include <queue>

using namespace std;
 
#define tii tuple<int,int>
#define vi vector<int>
#define vii vector<vi>
#define ll long long
#define vl vector<ll>
#define vll vector<vl>
 
#define mymod 1000000007
#define sz 200002

ll power(ll a, ll b, ll p)
{
    if(a<2)
    return a;
    ll ans = 1;
    while(b)
    {
        if(b%2)
        {
            ans *= a;
            ans %= p;
        }
        b = b/2;
        a = (a*a)%p;
    }
    return ans;
}

ll mgcd(ll a, ll b)
{
    if(a==0)
        return b;
    return mgcd(b%a,a);
}

int main() {
    clock_t tstart = clock();
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    // Start
    int n;
    cin>>n;
    vi v(n);
    int mn = mymod;
    int mx = -mymod;
    for(auto &x: v){
        cin>>x;
        mx = max(mx,x);
        mn = min(mn,x);
    }
    int ans = mymod;
    for(int i=mn;i<=mx;i++) {
        int s = 0;
        for(auto x:v) s += (i-x)*(i-x);
        ans = min(ans,s);
    }
    cout<<ans;
    // cout<<"\n\nTotal Time Taken : "<<(double)(-tstart + clock())/CLOCKS_PER_SEC<<"sec\n\n";
    return 0;
}
 


Measured memory_bytes: 3644
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <limits>
#include <queue>
#include <iomanip>
#include <set>
//#include <bits/stdc++.h>
template<typename T> bool chmax(T &a,T b){if(a<b){a=b;return true;}return false;}
template<typename T> bool chmin(T &a,T b){if(a>b){a=b;return true;}return false;}
using namespace std;
#define ALL(X) X.begin(),X.end()
using ll = long long int;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<vvll> vvvll;
typedef vector<bool> vb;
typedef vector<vb> vvb;
const int MOD=1000000007;//1e9+7
//const int MOD=998244353;
const int INTMAX=2147483647;//2e9
const ll LLMAX=9223372036854775807;//9e17

bool comp(vll a,vll b){
    return a[0]<b[0];
}

bool comp2(vll a,vll b){
    return a[1]>b[1];
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    ll N;
    cin>>N;
    vvll A(N,vll(2));
    for(ll i=0;i<N;i++)cin>>A[i][0]>>A[i][1];
    vvll B=A;
    
    sort(ALL(A),comp);
    sort(ALL(B),comp2);
    
    if(N%2==1){
        ll rangeA,rangeB;
        rangeA=A[N/2][0];
        rangeB=B[N/2][1];
        cout<<rangeB-rangeA+1<<endl;
    }else{
        ll rangeA[2],rangeB[2];
        rangeA[0]=A[N/2-1][0];
        rangeB[0]=B[N/2-1][1];
        rangeA[1]=A[N/2][0];
        rangeB[1]=B[N/2][1];
        //printf("%d,%d,%d,%d\n",rangeA[0],rangeB[0],rangeA[1],rangeB[1]);
        cout<<(rangeB[1]+rangeB[0])-(rangeA[1]+rangeA[0])+1<<endl;
    }
    
    return 0;
}
/*
 6
 1 7
 3 8
 6 7
 2 5
 3 9
 4 6
 */


Measured memory_bytes: 25108
#include <stdio.h>
#include <string.h>

int map[1000][100];

int main(void) {
	int n,m,a;
	int h,p,q;
	int i,j;
	while(1) {
		scanf("%d%d%d",&n,&m,&a);
		if(n==0 && m==0 && a==0)break;
		for(i=0;i<1000;i++) {
			for(j=0;j<100;j++)map[i][j]=j;
		}
		for(i=0;i<m;i++) {
			scanf("%d%d%d",&h,&p,&q);
			h--;p--;q--;
			map[h][p]=q;
			map[h][q]=p;
		}
		for(i=1000-1,j=a-1;i>=0;i--) {
			j=map[i][j];
		}
		printf("%d\n",j+1);
	}
	return 0;
}

Measured memory_bytes: 0
import time
t1 = time.time()
h,w = map(int,input().split())
grid = []
for i in range(h):
    grid.append(list(map(int,input().split())))
for i in range(h):
    lst = list(map(int,input().split()))
    for j in range(w):
        grid[i][j] = abs(grid[i][j]-lst[j])
lst = [[set() for _ in range(w)] for _ in range(h)]
lst[0][0].add(grid[0][0])
for j in range(1,w):
    for x in lst[0][j-1]:
        lst[0][j].add(abs(grid[0][j]-x))
        if (grid[0][j] + x) <= 6400:
            lst[0][j].add(grid[0][j]+x)
for i in range(1,h):
    for x in lst[i-1][0]:
        lst[i][0].add(abs(grid[i][0]-x))
        if grid[i][0] + x <= 6400:
            lst[i][0].add(grid[i][0]+x)
for i in range(1,h):
    for j in range(1,w):
        for x in lst[i][j-1]:
            lst[i][j].add(abs(grid[i][j]-x))
            if grid[i][j] + x <= 6400:
                lst[i][j].add(grid[i][j]+x)
        for x in lst[i-1][j]:
            lst[i][j].add(abs(grid[i][j]-x))
            if grid[i][j] + x <= 6400:
                lst[i][j].add(grid[i][j]+x)
        t = time.time()
        if t - t1 > 1.8:
            print(0)
            exit()
print(min(lst[h-1][w-1]))


Measured memory_bytes: 661120
import collections
import math
n,m=map(int,input().split())
flag=0
P=[]
p=m
while flag==0:
  cur=p
  for i in range(2,int(p**0.5)+1):
    if p%i==0:
      P.append(i)
      p//=i
      break
  if p==cur:
    P.append(p)
    flag=1
c=collections.Counter(P)
Primes=set(P)
def f(i):
  return math.factorial(i)
def fn(i):
  return f(n+i-1)//(f(n-1)*f(i))%(10**9+7)
ans=1
for p in Primes:
  ans*=fn(c[p])
  ans%=(10**9+7)
print(1 if m==1 else ans) 


Measured memory_bytes: 114396
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<string>
#include<stack>
#include<queue>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<utility>
#include<set>
#include <unordered_set>
typedef long long int ll;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) for(int i=0;i<signed(n);i++)
#define EREP(i,n) for(int i=1;i<=signed(n);i++)
#define ALL(a) (a).begin(),(a).end()
using std::cout;
using std::vector;
using std::endl;
using std::cin;
using std::string;
using std::min;
using std::max;
//#define EVEL 1
#ifdef EVEL
#define DEB(X) cout << #X << ":" <<X<<" " ;
#define TF(f) f ? cout<<"true  " : cout<<"false ";
#define END cout<<"\n";
#else
#define DEB(X) {}
#define TF(f) {}
#define END {}
#endif
const ll MOD = 1000000007;
const ll INF = 9e9;
typedef std::pair<int, int> P;
struct edge { ll to, cost; };
#define VMAX 50*50+10
ll H, W, N;
char S[51][51];
ll ans = 0;
ll C[VMAX][VMAX];
ll d[VMAX];
bool F[VMAX];
void Dijkstra(int s) {
	std::fill(F, F + N, false);
	std::fill(d, d + N, INF);
	d[s] = 0;
	while (true) {
		int v = -1;
		REP(i, N) {
			if (!F[i] && (v == -1 || d[i]<d[v]))v = i;
		}
		if (v == -1)break;
		F[v] = true;
		REP(i, N) {
			d[i] = std::min(d[i], d[v] + C[v][i]);
		}
	}
}

int main() {
	std::ios_base::sync_with_stdio(false);
	cin >> H >> W;
	N = H*W;
	ll B = 0;
	REP(i, H)REP(j, W) {
		cin >> S[i][j];
		if (S[i][j] == '#')B++;
	}
	int dx[] = { 0,0,1,-1 };
	int dy[] = { 1,-1,0,0 };
	REP(i, VMAX)REP(j, VMAX)C[i][j] = INF;
	REP(i, H)REP(j, W) {
		if (S[i][j] == '#')continue;
		REP(k, 4) {
			int a = i + dy[k], b = j + dx[k];
			if (a<0 || b<0 || a >= H || b >= W || S[a][b] == '#')continue;
			C[i*W + j][a*W + b] = 1;
		}
	}
	Dijkstra(0);
	/*REP(i, H) {
		REP(j, W) {
			cout << (d[i*W + j] == INF ? 0 : d[i*W + j]) << " ";
		}END
	}*/
	DEB(d[W*H - 1])END
		cout << (d[W*H - 1] == INF ? -1 : W*H - d[W*H - 1] - B - 1) << endl;
	return 0;
}


Measured memory_bytes: 49536
#include <stdio.h>
#include <bits/stdc++.h>
 
using namespace std;
 
#define REP(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define REPO(i,n) for(int (i)=1; (i)<=(int)(n); (i)++)
#define SZ(v) ((int)(v).size())
#define ALL(v) (v).begin(),(v).end()
#define one first
#define two second
typedef long long ll;
typedef pair<int, int> pi;
const int INF = 0x3f2f1f0f;
const ll LINF = 1ll * INF * INF;
 
 
const int MAX_N = 1e5 + 100;
 
int N, M; 
ll Nr[MAX_N * 3], SumL[MAX_N * 3], SumR[MAX_N * 3];
int main() {
	//cin >> N >> M;
	cin >> N; M = N;
	for(int i=0; i<2*N+M; i++) scanf("%lld", &Nr[i]);
	priority_queue<ll, vector<ll>, greater<ll>> lq;
	priority_queue<ll> rq;
 
	for(int i=0; i<M; i++) {
		if(i) SumL[i] = SumL[i-1];
		SumL[i] += Nr[i];
		lq.push(Nr[i]);
	}
	for(int i=M; i<2*N+M; i++) {
		SumL[i] = SumL[i-1] + Nr[i];
		lq.push(Nr[i]);
		SumL[i] -= lq.top();
		lq.pop();
	}
	for(int i=2*N+M-1; i>=2*N; i--) {
		SumR[i] = SumR[i+1] + Nr[i];
		rq.push(Nr[i]);
	}
	for(int i=2*N-1; i>=0; i--) {
		SumR[i] = SumR[i+1] + Nr[i];
		rq.push(Nr[i]);
		SumR[i] -= rq.top();
		rq.pop();
	}
	ll ans = -LINF;
	for(int i=M-1; i<2*N; i++)
		ans = max(ans, SumL[i] - SumR[i+1]);
	printf("%lld\n", ans);
	return 0;
}


Measured memory_bytes: 8948
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <algorithm>
#include <numeric>
#include <random>
#include <vector>
#include <array>
#include <bitset>
#include <queue>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
 
using namespace std;
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;

int main() {
    int a, b;
    cin >> a >> b;
    if(a <= 8 && b  <= 8){
    cout << "Yay!";
    }else{
        cout << ":(";
    }
    
    return 0;
}

Measured memory_bytes: 3556
#include <iostream>
using namespace std;
int n;
int saiki (int now)
{
	if (now == n)return 1;
	if (now > n)return 0;
	int res = 0;
	res = saiki(now+1)
	+ saiki(now+2)
	+ saiki(now+3);
	return res;	
}
int main ()
{
	while(true)
	{
		cin >> n;
		if(n==0)break;
		int answer = saiki (0);
		cout << answer/3650+1 << endl;
	}

}

Measured memory_bytes: 3076
#include <stdio.h> 
int prime(int x){ 
    int i; 
    if(x < 2) 
    return 0; 
    if(x == 2) 
    return 1; 
    if(x % 2 == 0) 
    return 0; 
    for(i = 3;i * i <= x;i += 2) 
    if(x % i == 0) 
    return 0; 
    return 1; 
    
} 
int main(){ 
    int i,n, c = 0, a;
    scanf("%d", &n); 
    for(i = 0;i < n;i++){ 
        scanf("%d", &a); 
        c += prime(a); 
        
    } 
    printf("%d\n", c); 
    return 0; 
    
} 



Measured memory_bytes: 2120
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll read(){
	ll a=0,b=getchar(),c=1;
	while(!isdigit(b))c=b=='-'?-1:1,b=getchar();
	while(isdigit(b))a=a*10+b-'0',b=getchar();
	return a*c;
}
int h,a;
int main(){
	h=read(),a=read();
	while(a--)h-=read();
	if(h>0)puts("No");
	else puts("Yes");
	return 0;
}

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

using namespace std;

int sz1 , sz2;
string s;

vector<int> c[128];
int off[128][322];
int dp[301][301];
pair<int,int> to[301][301];
int flag[301][301];

int dp_search(int sz1,int sz2){
	memset(dp,-1,sizeof(dp));
	memset(flag,0,sizeof(flag));
	int r;
	dp[0][sz1] = 0;
	to[0][sz1] = make_pair(-1,-1);
	for(int p1 = 0 ; p1 <= sz1 ; p1++){
		for(int p2 = sz1 ; p2 <= sz2 ; p2++){
			if(dp[p1][p2] != -1){
				if(p1 < sz1){
					int i = off[s[p1]][p2];
					if(i != 9999){
						r = dp[p1][p2]+1;
						if(r>dp[p1+1][i+1]){
							to[p1+1][i+1] = make_pair(p1,p2);
							dp[p1+1][i+1] = r;
							flag[p1+1][i+1] = 1;
						}
					}
					r = dp[p1][p2];
					if(r > dp[p1+1][p2]){
						to[p1+1][p2] = make_pair(p1,p2);
						dp[p1+1][p2] = r;
					}
				}
				if(p2 < sz2){
					r = dp[p1][p2];
					if(r > dp[p1][p2+1]){
						to[p1][p2+1] = make_pair(p1,p2);
						dp[p1][p2+1] = r;	
					}
				}
			}
		}
	}
	return dp[sz1][sz2];
}
string get(int sz1,int sz2){
	string ans = "";
	while(sz1 != -1){
		int x = to[sz1][sz2].first;
		int y = to[sz1][sz2].second;
		if( flag[sz1][sz2] ){
			ans = string(1,s[x]) + ans;
		}
		sz1 = x;
		sz2 = y;
	}
	return ans;
}

int main(){
	while(cin >> s && s[0] != '#'){
		int last[26];
		for(int i = 0 ; i < 26 ; i++) last[i] = 9999;
		for(int i = s.size() ; i >= 0 ; i--){
			last[s[i]-'A'] = i;
			for(int j = 0 ; j < 26 ; j++){
				off[j+'A'][i] = last[j];
			}
		}
		int save[333]={0};
		int currentmx = 0;
		for(int i = 1 ; i < s.size() ; i++){
			sz1 = i; sz2 = s.size();
			if(min(sz1,sz2-sz1) <= currentmx ) continue;
			save[i] = dp_search(sz1,sz2);
			currentmx = max(save[i],currentmx);
		}
		for(int i = 1 ; i < s.size() ; i++){
			if(save[i] == currentmx){
				sz1 = i; sz2 = s.size();
				dp_search(sz1,sz2);
				cout << get(sz1,sz2) << endl;
				break;
			}
		}
	}
}

Measured memory_bytes: 2352
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int inf = 1e9;
const ll INF = 1e18;
#define rep(i, n) for (int i = 0; i < n; i++)
using Graph = vector<vector<int>>;
using pint = pair<int, int>;
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
int dxx[8] = {1, 1, 1, 0, 0, -1, -1, -1}, dyy[8] = {-1, 0, 1, -1, 1, -1, 0, 1};

int main() {
    double a, b, h, m;
    cin >> a >> b >> h >> m;
    double ax, ay, bx, by;
    const double pi = acos (-1);
    ay = a * sin (pi / 2 - (h + m / 60) * (pi / 6));
    ax = a * cos (pi / 2 - (h + m / 60) * (pi / 6));
    bx = b * cos (pi / 2 - m / 60 * 2 * pi);
    by = b * sin (pi / 2 - m / 60 * 2 * pi);
    double ans = pow ((ay - by) * (ay - by) + (ax - bx) * (ax - bx), 0.5);
    cout << fixed << setprecision (15) << ans << "\n";
}


Measured memory_bytes: 4356
S=list(input())
K=int(input())
N=len(S)
for i in range(N):
  k=(ord('z')-ord(S[i])+1)%26
  if K>=k:
    S[i]='a'
    K-=k
S[-1]=chr(ord(S[-1])+K%26)
print(''.join(S))

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


int main(void){
	int N,L;
	cin >> L >> N;
	int sum = 0;
	int x,w;
	for(int i = 0; i < N; ++i){
		cin >> x >> w;
		sum += x * w;
	}
	if(sum == 0){
		cout << 0 << endl;
		return 0;
	}

	if(sum > 0){
		if(sum % 50000 == 0){
			cout << sum / 50000 << endl;
		}else{
			cout << sum / 50000 +1<< endl;
		}
		while(true){
			if(sum <= 50000){
				cout << "-1 " << sum << endl;
				break;
			}
			cout << "-1 50000" << endl;
			sum -= 50000;
		}
		/*
		cout << sum << endl;
		for(int i = 0; i <= sum; ++i){
			cout << "-1 1" << endl;
		}
		*/
	}else{
		sum *= -1;
		if(sum % 50000 == 0){
			cout << sum / 50000 << endl;
		}else{
			cout << sum / 50000 +1<< endl;
		}
		while(true){
			if(sum <= 50000){
				cout << "1 " << sum << endl;
				break;
			}
			cout << "-1 50000" << endl;
			sum -= 50000;
		}
		/*
		cout << sum*(-1) << endl;
		for(int i = 0; i < sum*(-1); ++i){
			cout << "1 1" << endl;
		}
		*/
	}
	return 0;
}


Measured memory_bytes: 3088
#include <bits/stdc++.h>
// statics
using namespace std;
using int64 = long long;
using PAIR = pair<int, int>;
constexpr int INF = 1 << 30;
constexpr int64 LINF = 1LL << 60;
constexpr int MOD = 1e9 + 7;
constexpr int MAX_N = 101010;

// init/input
#define int int64
#define INIT ios::sync_with_stdio(false);cin.tie(0);
#define VAR(type, ...) type __VA_ARGS__;MACRO_VAR_Scan(__VA_ARGS__);
template<typename T> void MACRO_VAR_Scan(T &t) {cin>>t;}
template<typename First, typename...Rest> void MACRO_VAR_Scan(First &first, Rest&...rest) {cin>>first;MACRO_VAR_Scan(rest...);}
#define VEC(type, c, n) vector<type> c(n);for(auto &&i:c)cin>>i;

// out
#define OUT(dist) cout<<(dist);
#define FOUT(n, dist) cout<<fixed<<setprecision(n)<<(dist);
#define SP cout<<" ";
#define BR cout<<"\n";
#define debug(x) cerr << #x << ":" << (x);BR;

// utility
#define ALL(a) (a).begin(), (a).end()
#define EACH(i, a) for(auto &&i:(a))
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define RFOR(i, a, b) for(int i=(b)-1;i>=0;--i)
#define REP(i, n) for(int i=0;i<(n);++i)
#define RREP(i, n) for(int i=(n)-1;i>=0;--i)

int fact[MAX_N];
int ifact[MAX_N];

int power(int x, int n) {
	int res = 1LL;
	while (n > 0) {
		if (n & 1) (res *= x) %= MOD;
		(x *= x) %= MOD;
		n >>= 1;
	}
	return res % MOD;
}

int inv(int x) {
	return power(x, MOD - 2);
}

int nCr(int n, int r) {
	if (n < 0 || r < 0 || r > n) return 0;
	if (r > n / 2) r = n - r;
	return fact[n] * ifact[r] % MOD * ifact[n - r] % MOD;
}

signed main() {
  INIT;
	
  VAR(int, n);
	VEC(int, a, n + 1);
	vector< int > cnt(MAX_N, -1);
	int d;
	REP(i, n + 1) {
		if (cnt[a[i]] > -1) {
			d = i - cnt[a[i]] ;
			break;
		}
		cnt[a[i]] = i;
	}

	fact[0] = ifact[0] = 1LL;
  FOR(i, 1, MAX_N) {
    fact[i] = (fact[i - 1] * i) % MOD;
		ifact[i] = inv(fact[i]);
  }
	
	int ans;
	REP(i, n + 1) {
	  ans = (nCr(n + 1, i + 1) - nCr(n - d, i) + MOD) % MOD;
		OUT(ans)BR;
	}
	
  return 0;
}


Measured memory_bytes: 4352
import math

n = int(input())
p = list(map(int, input().split()))
q = list(map(int, input().split()))

num = list(range(1,n+1))
p_id = 0
q_id = 0

for i in range(n):
    p_id += num.index(p[i]) * math.factorial(len(num)-1)
    num.remove(p[i])

num = list(range(1,n+1))

for i in range(n):
    q_id += num.index(q[i]) * math.factorial(len(num)-1)
    num.remove(q[i])

print(abs(p_id-q_id))

Measured memory_bytes: 3064