akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
using namespace std;
int main()
{
    int a[3][3];
    int num[105]={0};
    int n,x;
    for(int i=0;i<3;i++)
        for(int j=0;j<3;j++)
        cin>>a[i][j];
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>x;
        num[x]++;
    }
    if(num[a[0][0]]>0&&num[a[0][1]]>0&&num[a[0][2]]>0){
        cout<<"Yes"<<endl;
        return 0;
    }
    if(num[a[1][0]]>0&&num[a[1][1]]>0&&num[a[1][2]]>0){
        cout<<"Yes"<<endl;
        return 0;
    }
    if(num[a[2][0]]>0&&num[a[2][1]]>0&&num[a[2][2]]>0){
        cout<<"Yes"<<endl;
        return 0;
    }
    if(num[a[0][0]]>0&&num[a[1][0]]>0&&num[a[2][0]]>0){
        cout<<"Yes"<<endl;
        return 0;
    }
    if(num[a[0][1]]>0&&num[a[1][1]]>0&&num[a[2][1]]>0){
        cout<<"Yes"<<endl;
        return 0;
    }
    if(num[a[0][2]]>0&&num[a[1][2]]>0&&num[a[2][2]]>0){
        cout<<"Yes"<<endl;
        return 0;
    }
    if(num[a[0][0]]>0&&num[a[1][1]]>0&&num[a[2][2]]>0){
        cout<<"Yes"<<endl;
        return 0;
    }
    if(num[a[0][2]]>0&&num[a[1][1]]>0&&num[a[2][0]]>0){
        cout<<"Yes"<<endl;
        return 0;
    }
    cout<<"No"<<endl;
    return 0;
}






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

 
int main(){
	ll n ; cin>>n ; string s ; cin>>s; int ans = 0 ;

	int minlen = 0 ; int maxlen= n/2;

	while(minlen<=maxlen){
		int mid = (minlen+maxlen)/2;
		bool repeated=false;

		unordered_map<string,vector<int>>mapp;

		for(int i =0 ; i < n-mid+1 ; i++){
			string pattern = s.substr(i,mid);
			mapp[pattern].push_back(i);
		}

		for(auto it=mapp.begin() ; it!=mapp.end() ; it++){
			if(it->second.size()>1){
				if(it->second[it->second.size()-1]>it->second[0]+mid-1){
					repeated=true;
				}
			}
		}

		if(repeated){
			ans=mid;
			minlen=mid+1;
		}
		else{
			maxlen=mid-1;
		}
	}

	cout<<ans;



	

 	int q;cin>>q;
 
	
}

Measured memory_bytes: 6756
// lcm、__builtin_popcountとかはg++ -std=c++17 default.cppみたいなかんじで
#include <bits/stdc++.h>
#define ll long long
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
using namespace std;

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

    ll i,j,k,l,m,n,maxi=0,f=0,mini=1e10,sum=0;
    string str;
    ll a,b,s;
    ll bsum=0;
    cin>>n>>a>>b>>str;
    rep(i,n){
        if(str[i]=='c') {cout<<"No"<<endl;continue;}
        if(str[i]=='a'){
            if(a+b>sum) {cout<<"Yes"<<endl;sum++;}
            else cout<<"No"<<endl;
        }
        if(str[i]=='b'){
            if(a+b>sum&&b>bsum) {cout<<"Yes"<<endl;sum++;bsum++;}
            else cout<<"No"<<endl;
        }
    }
    return 0;
}

Measured memory_bytes: 848
def main():
    n, m = (int(x) for x in input().split())
    a = [int(x) for x in input().split()]

    th = sum(a) / (4 * m)
    a_ = [0 if x < th else 1 for x in a]

    print(["Yes", "No"][not m <= sum(a_)])


if __name__ == "__main__":
    main()


Measured memory_bytes: 2940
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
#define ss(x) (int) x.size()
#define fi first
#define se second
#define cat(x) cerr << #x << " = " << x << endl
#define rep(i, j, n) for (int i = j; i <= n; ++i)
#define per(i, j, n) for (int i = n; j <= i; --i)
#define all(x) x.begin(), x.end()
#define ld long double

using namespace std;	

const int N = 1e5 + 101;

int n, m, a, b, d[N];

int main() {
	scanf ("%d%d", &n, &m);
	rep(i, 1, m) {
		scanf ("%d%d", &a, &b);
		d[a]++; d[b]++;
	}
	rep(i, 1, n)
		if (d[i] & 1) return printf ("NO\n"), 0;
	printf ("YES\n");
	
	return 0;
}


Measured memory_bytes: 4124
#include <bits/stdc++.h>
#define ll long long
using namespace std;
int main() {
   ll n;
   cin>>n;
   ll ans=10000000000000;
   ll a=-1;
   ll b=-1;
   for(int i=1;i<=sqrt(n);++i){
        if(n%i==0){
            a=i;
            b=n/i;
            ans = min(ans,(a+b-2));
            //i=sqrt(n)+1;
        }
   }
   cout<<ans<<'\n';
   return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
  long long X;
  long long ans = 0;
  
  scanf("%lld", &X);
  
  ans = 2 * (X / 11);
  
  if(X % 11 == 0) ;
  else if(X % 11 <= 6) ans++;
  else ans += 2; 
  
  printf("%lld\n", ans);
  
  return 0;
}

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

using namespace std;

#define int long long
#define ll long long
typedef pair<int, int> P;
#define mod 1000000007
#define INF (1LL<<60)

#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define YES cout << "YES" << endl;
#define Yes cout << "Yes" << endl;
#define NO cout << "NO" << endl;
#define No cout << "No" << endl;

int cnt[123456];

signed main(){

	int N;
	cin >> N;
	vector<int> a(N);
	rep(i, N) cin >> a[i];
	
	rep(i, N) cnt[a[i]]++;

	int ans = 0, even = 0;
	rep(i, 123456){
		if (cnt[i] != 0) ans++;
		if (cnt[i]>0 && cnt[i] % 2 == 0) even++;
	}
	
	if (even % 2 == 1) ans--;
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = 1e9 + 7;
const int INF = 2e9;

int main()
{
    vector<ll> a(5, 0);
    string s;
    int n;
    cin >> n;
    for (int i = 0; i < n; i++)
    {
        cin >> s;
        switch (s[0])
        {
        case 'M':
            a[0]++;
            break;
        case 'A':
            a[1]++;
            break;
        case 'R':
            a[2]++;
            break;
        case 'C':
            a[3]++;
            break;
        case 'H':
            a[4]++;
            break;
        }
    }
    ll ans = 0;
    for (int i = 0; i < 5; i++)
    {
        for (int j = i + 1; j < 5; j++)
        {
            for (int k = j + 1; k < 5; k++)
            {
                ans += a[i] * a[j] * a[k];
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <tuple>
#include <vector>

using namespace std;
typedef long long ll;

#define rep(i, n) for (ll i = 0; i < (n); i++)
#define reps(i, f, n) for (ll i = (f); i < (n); i++)
#define repr(i, n) for (ll i = n; i >= 0; i--)
#define repv(v) for (auto it = (v).begin(); it != (v).end(); it++)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
#define pb push_back
#define INIT    \
    cin.tie(0); \
    ios::sync_with_stdio(false);

template <class T>
inline bool chmax(T& a, T b) {
    return a = (a < b) ? b : a;
}
template <class T>
inline bool chmin(T& a, T b) {
    return a = (a > b) ? b : a;
}

ll const INF = 1LL << 60;
ll const MOD = 1000000007;

std::vector<int> find_all(const std::string str, const std::string subStr) {
    std::vector<int> result;

    int subStrSize = subStr.size();
    int pos = str.find(subStr);

    while (pos != std::string::npos) {
        result.push_back(pos);
        pos = str.find(subStr, pos + subStrSize);
    }

    return result;
}

int main() {
    INIT;

    string s;
    cin >> s;

    bool flg = false;
    rep(i, 10) {
        string sc = to_string(i) + to_string(i) + to_string(i);
        vector<int> f = find_all(s, sc);
        if (SZ(f) > 0) {
            flg = true;
        }
    }

    if (flg) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 3676
#include<iostream>
#include<vector>
#include<algorithm>
typedef long long ll;
using namespace std;
ll inf = 1000000007;
ll c[55];
int main() {
	int n, m, x;
	cin >> n >> m >> x;
	
	vector<vector<int>>a(n);
	for (int i = 0; i < n; i++) {
		cin >> c[i];
		a[i].resize(m);
		for (int j = 0; j < m; j++) {
			cin >> a[i][j];
		}
	}
	ll sum = inf;
	for (int bit = 0; bit < (1 << n); bit++) {
		bool ok = true;
		ll ans = 0;
	    vector<ll>t(m, 0);
		for (int j = 0; j < n; j++) {
			if (bit & (1 << j)) {
				ans += c[j];
				for (int k = 0; k < m; k++) {
					t[k] += a[j][k];
				}
			}
		}
		for (int j = 0; j < m; j++) {
			if (t[j] < x) {
				ok = false;
			}
		}
		if (ok) {
			sum = min(ans, sum);
		}
	}
	if (sum == inf) {
		cout << "-1" << endl;
	}
	else {
		cout << sum << endl;
	}
}

Measured memory_bytes: 3632
import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val n = sc.nextInt()
    println(problem079a(n))
}

fun problem079a(n: Int): String {
    val n = n.toString()
    return if ((n[1] == n[2]) && (n[0] == n[1] || n[2] == n[3])) "Yes" else "No"
}

Measured memory_bytes: 31396
#include<bits/stdc++.h>
using namespace std;
#define MAX 10000000
int arr[MAX];
int ans[MAX];

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

    int n;
    cin>>n;
  //  int arr[n];

    for(int i=1;i<=n-1;i++)
    {
        cin>>arr[i];
    }
    for(int i=1;i<=n-1;i++)
    {
        //if(arr[i]==)
        ans[arr[i]]++;
    }
     for(int i=1;i<=n;i++)
    {
        cout<<ans[i]<<endl;
    }

    return 0;
}


Measured memory_bytes: 5084
import sys
import bisect
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
n = int(readline())

lst1 = [[0]*26 for _ in range(n)]
kijun = ord("a")
for i in range(n):
    s = readline().rstrip().decode('utf-8')
    for j in s:
        lst1[i][ord(j)-kijun] += 1

ans = [100]*26

for i in lst1:
    for j in range(26):
        ans[j] = min(ans[j],i[j])

res = ""
for i in range(26):
    if ans[i] != 0:
        res += chr(kijun+i)*ans[i]

print(res)


Measured memory_bytes: 39792
#include<cstdio>
#include<cstdlib>
#include<cstring>
const int MAXN = 200 + 5;
const int inf = 0x3f3f3f3f;

inline int min(int a,int b){ return a<b? a: b;}
inline int max(int a,int b){ return a>b? a: b;}
inline void error(void){ printf("-1"); exit(0);}

int n;
char s[MAXN][MAXN];
int g[MAXN][MAXN],f[MAXN][MAXN];

int c[MAXN];
void dfs(int u)
{
	for(int v=1; v<=n; ++v) if(g[u][v])
	{
		if(c[v]==-1) c[v]=c[u]^1, dfs(v);
		else if(c[v] != (c[u]^1)) error();
	}
}

int main(void)
{
	scanf("%d",&n);
	for(int i=1; i<=n; ++i) scanf("%s",s[i]+1);
	for(int i=1; i<=n; ++i)
		for(int j=1; j<=n; ++j)
			g[i][j]=s[i][j]-'0';
	
	memset(c,-1,sizeof(c));
	c[1]=0; dfs(1);
	
	memset(f,0x3f,sizeof(f));
	for(int i=1; i<=n; ++i)
	{
		f[i][i]=0;
		for(int j=1; j<=n; ++j)
			if(g[i][j]) f[i][j]=1;
	}
	
	for(int k=1; k<=n; ++k)
		for(int i=1; i<=n; ++i) if(f[i][k]!=inf)
			for(int j=1; j<=n; ++j) if(f[k][j]!=inf)
				f[i][j] = min(f[i][j], f[i][k]+f[k][j]);
	int ans=0;
	for(int i=1; i<=n; ++i)
		for(int j=1; j<=n; ++j)
			ans = max(ans,f[i][j]);
	printf("%d",ans+1);
	return 0;
}

Measured memory_bytes: 512
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
	int n,m,in,out,ans;
	cin >> n >> m;
	ans = m;
	for(int i=0;i<n;i++){
		cin >> in >> out;
		m+=(in-out);
		if(m<0){
			cout << 0 << endl;
			return 0;
		}
		ans = max(ans,m);
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3068
from itertools import product
N,M = map(int,input().split())
G = {i:[] for i in range(M)}
for i in range(M):
    a,b = map(int,input().split())
    G[i] = [a,list(map(int,input().split()))]
INFTY = 10**11
dp = [[INFTY for S in range(2**N)] for _ in range(M+1)]
for j in range(M+1):
    dp[j][0] = 0
for j in range(M):
    for S in range(2**N):
        y = 0
        for x in G[j][1]:
            y += 2**(x-1)
        dp[j+1][S] = min(dp[j][S],dp[j][S&(~y)]+G[j][0])
a =dp[M][2**N-1]
if a>=INFTY:
    print(-1)
else:
    print(a)

Measured memory_bytes: 78808
#include <iostream>

using namespace std;

int Area(int a, int b);
int Perimeter(int a, int b);

int main() {
    int a, b;
    int area, perimeter;
    
    cin >> a >> b ;
    area = Area(a, b);
    perimeter = Perimeter(a, b);
    
    cout << area << ' ' << perimeter << endl;
    
    return 0;
}

int Area(int a, int b) {
    return a * b;
}

int Perimeter(int a, int b) {
    return 2 * (a + b);
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
using P=pair<int,int>;
using ll=long long;

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

    int n;
    cin>>n;
    vector<char> c(n);
    int cnt=0;
    for(int i=0;i<n;i++){
        cin>>c[i];
        if(c[i]=='R'){
            cnt++;
        }
    }
    int ans=0;
    for(int i=0;i<cnt;i++){
        if(c[i]=='W'){
            ans++;
        }
    }

    cout<<ans<<endl;

}

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

ll fn(ll a)
{
    if (a!=2&&a%2==0) {return 0;}
    for(ll i=3;i<=sqrt(a);i+=2)
    {
        if (a%i==0) {return 0;}
    }
    return 1;
}

int main() {
    ll p,n,i,l; cin>>n;
    if (n==2) {cout<<n; return 0;}
    if (n%2==0) {n++;}
    for(i=n;i<=n*n;i+=2)
    {
        if (fn(i)==1) {cout<<i; return 0;}
    }
	return 0;
}

Measured memory_bytes: 3652
import sys
import bisect

def main():
    num_segments = int(input())
    events = [None] * num_segments * 2
    num_events = 0

    lines = sys.stdin.readlines()
    for line in lines:
        pt1_x, pt1_y, pt2_x, pt2_y = map(int, line.split())
        if pt1_x == pt2_x:
            if pt1_y > pt2_y:
                pt1_y, pt2_y = pt2_y, pt1_y
            events[num_events] = (pt1_y, pt1_x, 0)
            num_events += 1
            events[num_events] = (pt2_y, pt2_x, 2)
            num_events += 1
        elif pt1_y == pt2_y:
            if pt1_x > pt2_x:
                pt1_x, pt2_x = pt2_x, pt1_x
            events[num_events] = (pt1_y, (pt1_x, pt2_x), 1)
            num_events += 1
        else:
            raise AssertionError

    events = events[:num_events]
    events.sort(key=lambda x: (x[0], x[2]))

    cross_count = 0
    vertical = []
    for event in events:
        if event[2] == 0:
            bisect.insort_left(vertical, event[1])
        elif event[2] == 2:
            i = bisect.bisect_left(vertical, event[1])
            del vertical[i]
        else:   # horizontal
            left_x, right_x = event[1][0], event[1][1]
            for v_x in vertical:
                if left_x <= v_x <= right_x:
                    cross_count += 1
    print(cross_count)


main()


Measured memory_bytes: 49984
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const int INF = (1<<30);
const ll INFLL = (1ll<<60);
const ll MOD = (ll)(1e9+7);

#define l_ength size

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	a = (a<MOD)?a:(a-MOD);
	b = (b<MOD)?b:(b-MOD);
	a += b;
	a = (a<MOD)?a:(a-MOD);
}

int u[10101],v[10101];

int main(void){
	int n,k,i,j,m=0,cnt;
	cin >> n >> k;
	if(k>((n-1)*(n-2)/2)){
		cout << "-1" << endl;
		return 0;
	}
	for(i=1; i<n; ++i){
		u[m] = 0; v[m] = i; ++m;
	}
	cnt = (n-1)*(n-2)/2;
	for(i=1; i<n; ++i){
		for(j=1; j<i; ++j){
			u[m] = i; v[m] = j;
			++m; --cnt;
			if(cnt==k){
				break;
			}
		}
		if(cnt==k){
			break;
		}
	}
	cout << m << endl;
	for(i=0; i<m; ++i){
		cout << (v[i]+1) << " " << (u[i]+1) << endl;
	}
	return 0;
}


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

using namespace std;

int main(void) {
    int N;
    string S;
    cin >> N >> S;
    int x = 0;
    int ans = 0;
    for(int i=0; i<N; i++) {
        if(S[i] == 'I') {
            x++;
        } else {
            x--;
        }
        ans = max(ans, x);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
int N,M,Q,i,D[100],t;
main()
{
for(;scanf("%d%d",&N,&Q),N;)
{
memset(D,0,sizeof(D));
for(i=0;i<N;i++)
for(scanf("%d",&M);M--;)
{
scanf("%d",&t);
D[t]++;
}
for(i=0,t=-1;i<100;i++)
if ((t==-1&&D[i]>=Q)||(t!=-1&&D[i]>D[t]))
t=i;
printf ("%d\n",t==-1?0:t);
}
}

Measured memory_bytes: 1776
N,W = map(int,input().split())
tmpv = [[] for _ in range(4)]
w1 = None
for i in range(N):
    tw, tv = map(int,input().split())
    if i==0:
        w1 = tw
        tmpv[0].append(tv)
    else:
        tmpv[tw-w1].append(tv)

v = []
for tv in tmpv:
    v.append(sorted(tv, reverse=True)+[0])
    
ans = 0
for i in range(len(v[0])):
  for j in range(len(v[1])):
    for k in range(len(v[2])):
      for l in range(len(v[3])):
        tw = w1*i+(w1+1)*j+(w1+2)*k+(w1+3)*l
        tv = sum(v[0][:i]) + sum(v[1][:j]) + sum(v[2][:k]) + sum(v[3][:l])
        if tw<=W:
          ans = max(ans, tv)
print(ans)

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

#define PI acos(-1.0)
#define INF 0x3f3f3f3f
#define FAST_IO ios::sync_with_stdio(false)
#define CLR(arr,val) memset(arr,val,sizeof(arr))

typedef long long LL;

int main(){
    string s;
    cin>>s;
    int n=s.size();
    int ans1=n,ans2=n;
    for(int i=0;i<n;i++){
        if(s[i]=='0') ans1=min(ans1,max(n-i-1,i));
        else ans2=min(ans2,max(n-i-1,i));
    }
    cout<<max(ans1,ans2)<<endl;
    return 0;
}


Measured memory_bytes: 512
<?php
//error_reporting(0);
$N = (int)trim(fgets(STDIN));
//$S = trim(fgets(STDIN));
//list($N,$M) = explode(" ",trim(fgets(STDIN)));
//$a = array_map('intval',explode(" ",trim(fgets(STDIN))));

$u1 = intdiv($N,500);
$u2 = intdiv(($N - $u1 * 500),5);

printf("%d\n",$u1*1000+$u2*5);


Measured memory_bytes: 4856
#include <iostream>
#include <math.h>
#include <algorithm>
#include <string>
#include <string.h>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <tuple>
#include <stdlib.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
#define PI 3.14159265358979
typedef long long int ll;

const double pi=3.1415;
ll absc(ll a,ll b){return (a-b>0?a-b:b-a);
}
ll mini(ll a,ll b){return (a>b?b:a);}
ll gcd(ll a,ll b){
	if(a<b)swap(a,b);
	return (a%b?gcd(a%b,b):b);
}
int main()
{
   int a,b,c,d;
   string s,t;
   cin>>a>>b>>c>>d;
   cout<<(((a-1)/d+1)<((c-1)/b+1)?"No":"Yes");
}


Measured memory_bytes: 3628
#include <iostream>
#include <string>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <utility>
#include <iomanip>

#define ll long long int
#define pb push_back
#define mk make_pair
#define pq priority_queue

using namespace std;
typedef pair<int, int> P;
typedef pair<ll, int> Pl;
const int inf = 1e9;
const ll linf = 1LL << 50;

int main(int argc, char const* argv[])
{
	int a1, a2, a3;
	cin >> a1 >> a2 >> a3;
	int maxi = max(a1, max(a2, a3));
	int mini = min(a1, min(a2, a3));
	int mid = 0;
	if(a1 != maxi && a1 != mini)mid = a1;
	if(a2 != maxi && a2 != mini)mid = a2;
	if(a3 != maxi && a3 != mini)mid = a3;
	cout << maxi - mini << endl;
	return 0;
}


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

int main() {
  int N, D, X;
  cin >> N >> D >> X;
  vector<int> vec(N);
  for (int i = 0; i < N; i++) cin >> vec.at(i);

  for (int i = 1; i <= D; i++) {
    for (int j = 0; j < N; j++) {
      if ((i - 1) % vec.at(j) == 0) X++;
    }
  }

  cout << X << endl;
}

Measured memory_bytes: 256
#pragma GCC target ("avx2")
#pragma GCC optimize ("unroll-loops")
#pragma GCC optimize ("O3")
#include "bits/stdc++.h"
#include <unordered_set>
#include <unordered_map>
#include <random>
using namespace std;
typedef long long ll;
const ll MOD = 1'000'000'007LL; /*998'244'353LL;*/
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for(int (i)=0; (i)<(n); (i)++)
const int dx[4]={ 1,0,-1,0 };
const int dy[4]={ 0,1,0,-1 };

template<typename T>
T power(T x, long long n, const T &m){
    if(n == 0) return 1;
    if(n == 1) return x;
    T tmp = power(x, n/2, m);
    if(n%2 == 0) return tmp * tmp % m;
    else return tmp * tmp % m * x % m;
}

template<typename T>
T inverse(T x, const T &m){
    return power(x, m-2, m);
}

struct Combination{
private:
    int N;
    long long M;
    vector<long long> f, i;
public:
    void init(int n, long long m){
        N = n; M = m;
        f.resize(N+1); f[0] = 1;
        i.resize(N+1); i[0] = 1;
        for(long long j=1; j<=N; j++){
            f[j] = f[j-1]*j%M;
            i[j] = inverse(f[j], M);
        }
    }
    long long fact(int n){
        return f[n];
    }
    long long C(int n, int r){
        return f[n] * i[r] % M * i[n-r] % M;
    }
};

int K;
string S;
Combination C;

signed main(){
    cin >> K >> S;
    C.init(K+S.size(), MOD);
    ll ans = 0;
    ll p1 = 1;
    ll p2 = power(26LL, K, MOD);
    ll inv = inverse(26LL, MOD);
    rep(i, K+1){
        ans += C.C(i+S.size()-1, i) * p1 % MOD * p2 % MOD;
        p1 = p1*25LL%MOD;
        p2 = p2*inv%MOD;
    }
    cout << ans%MOD << endl;
}

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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define CHMIN(a,b) a=min((a),(b))
#define CHMAX(a,b) a=max((a),(b))

// mod
const ll MOD = 1000000007ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

// floating
typedef double Real;
const Real EPS = 1e-11;
#define EQ0(x) (abs(x)<EPS)
#define EQ(a,b) (abs(a-b)<EPS)
typedef complex<Real> P;

int n;
char s[125252];
typedef unsigned int Hash;
const Hash base = 10007ll;
Hash hsh[125252];
Hash bpow[125252];
typedef short Hash2;
const Hash2 base2 = 29;
const Hash2 mod2 = 251;
Hash2 hsh2[125252];
Hash2 bpow2[125252];
Hash2 mdmp[65536];

int calc(int x){
  typedef pair<Hash,Hash2> yo;
  set<yo> S;
  REP(i,n-x+1){
    // substr
    int l = i;
    int r = l+x;
    Hash h = hsh[r] - hsh[l]*bpow[x];
    Hash hh = mdmp[hsh2[r] - mdmp[hsh2[l]*bpow2[x]] + mod2];
    S.insert(yo(h,hh));
  }
  return S.size();
}

int main(){
  scanf("%s",s);
  n = strlen(s);
  REP(i,65536)mdmp[i] = i%mod2;
  // create hash
  REP(i,n)hsh[i+1] = hsh[i]*base + (Hash)s[i];
  bpow[0] = 1ll;
  REP(i,n)bpow[i+1] = bpow[i]*base;
  // create hash 2
  REP(i,n)hsh2[i+1] = mdmp[ mdmp[hsh2[i]*base2] + (Hash2)(s[i]-'a') ];
  bpow2[0] = 1;
  REP(i,n)bpow2[i+1] = mdmp[ bpow2[i]*base2 ];
  // go
  int low = 1, high = n;
  while(low+2<high){
    int ml = (low+high)/2;
    int mh = ml+1;
    if(calc(ml)<calc(mh)){
      low = ml;
    }else{
      high = mh;
    }
  }
  int ans = 0;
  FOR(i,low,high+1)CHMAX(ans,calc(i));
  printf("%d\n",ans);
  return 0;
}


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

#define pb(n) push_back(n)
#define fi first
#define se second
#define all(r) (r).begin(),(r).end()
#define vmax(ary) *max_element(all(ary))
#define vmin(ary) *min_element(all(ary))
#define debug(x) cout<<#x<<": "<<x<<endl
#define fcout(n) cout<<fixed<<setprecision((n))
#define scout(n) cout<<setw(n)
#define vary(type,name,size,init) vector< type> name(size,init)
#define vvl(v,w,h,init) vector<vector<ll>> v(w,vector<ll>(h,init))
#define mp(a,b) make_pair(a,b)

#define rep(i,n) for(int i = 0; i < (int)(n);++i)
#define REP(i,a,b) for(int i = (a);i < (int)(b);++i)
#define repi(it,array) for(auto it = array.begin(),end = array.end(); it != end;++it)
#define repa(n,array) for(auto &n :(array))

using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using dict = map<string,int>;
using pii = pair<int,int> ;
using pll = pair<ll,ll> ;

const int mod = 1000000007;
constexpr int inf = ((1<<30)-1)*2+1 ;
constexpr double PI = acos(-1.0) ;
double eps = 1e-10 ;

inline bool value(int x,int y,int w,int h){
  return (x >= 0 && x < w && y >= 0 && y < h);
}
const int dy[] = {0,1, 0,-1};
const int dx[] = {1,0,-1, 0};
const int DY[4][4] = {{-1,0, 1,0},{1,2, 1,0},{ 1, 0,-1,0},{-1,-2,-1,0}};
const int DX[4][4] = {{ 1,2, 1,0},{1,0,-1,0},{-1,-2,-1,0},{-1, 0, 1,0}};
const int chdir[] = {3,0,1,2};
const string Dir = "URDLURDL";
ll grid[10][10];
// u = 1,r = 2, d = 4, l = 8
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  vary(char,v,5,0);
  rep(i,9){
    if(i % 2){
      rep(j,5){
        cin >> v[j];
        v[j] -= '0';
        grid[j*2][i] = v[j];
      }
    }
    else{
      rep(j,4){
        cin >> v[j];
        v[j] -= '0';
        grid[j*2+1][i] = v[j];
      }
    }
  }
  ll x = 1,y = 0,c = 0,dir = 0;
  cout << "R";
  while(1){
    if(x == 1 && y == 0 && c) break;
    rep(i,4){
      ll nx = x + (DX[dir][i]),ny = y + (DY[dir][i]);
      if(value(nx,ny,10,10) && grid[nx][ny]){
        x = nx,y = ny;
        cout << Dir[dir+i];
        dir += chdir[i];
        dir %= 4;
        break;
      }
    }
    ++c;
    if(c > 100) break;
  }
  cout << endl;
//   rep(i,10){
//     rep(j,10){
//       scout(3) << grid[j][i];
//     }
//     cout << endl;
//   }
  return 0;
}

Measured memory_bytes: 3180
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		sc.close();
		
		long ans = 1;
		for(long i = 1;i < N;++i) {
			if(i * i > N) {
				ans = (i-1) * (i-1);
				break;
			}
		}
		System.out.println(ans);
	}
}


Measured memory_bytes: 23764
'use strict';
function min(a, b){
  return a > b ? b : a;
}

function Main(inputs) {
  // 1行目がinput[0], 2行目がinput[1], …に入る
  const input = inputs.split("\n");
  const n = Number(input[0]);
  const h = input[1].split(' ');
  const dp = Array(n).fill(1e10);
  dp[0] = 0;

  for (let i = 0; i < n - 1; i++) {
    dp[i + 1] = min(dp[i + 1], dp[i] + Math.abs(h[i] - h[i + 1]));
    dp[i + 2] = min(dp[i + 2], dp[i] + Math.abs(h[i] - h[i + 2]));
  }
  dp[n - 1] = min(dp[n - 1], dp[n - 2] + Math.abs(h[n - 2] - h[n - 1]));
  console.log(dp[n - 1]);
}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 28848
import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop, core.stdc.stdio;

void main() {
    auto s = readln.split.map!(to!int);
    auto H = s[0];
    auto W = s[1];
    auto A = H.iota.map!(_ => readln.chomp).array;

    immutable int INF = 1 << 29;
    immutable int[] dr = [0, 0, -1, 1];
    immutable int[] dc = [-1, 1, 0, 0];

    DList!(int[]) que;
    auto dist = new int[][](H, W);

    int f(int sr, int sc) {
        que.clear;
        foreach (i; 0..H) dist[i][] = INF;
        que.insertBack([sr, sc, 0]);

        while (!que.empty) {
            auto t = que.front;
            que.removeFront;
            auto r = t[0];
            auto c = t[1];
            auto d = t[2];
            if (dist[r][c] != INF) continue;
            dist[r][c] = d;
            foreach (i; 0..4) {
                auto nr = r + dr[i];
                auto nc = c + dc[i];
                if (nr < 0 || nr >= H || nc < 0 || nc >= W || A[nr][nc] == '#') continue;
                if (dist[nr][nc] == INF) que.insertBack([nr, nc, d+1]);
            }
        }

        int ans = -1;
        foreach (i; 0..H) foreach (j; 0..W) if (dist[i][j] != INF) ans = max(ans, dist[i][j]);
        return ans;
    }

    int ans = -1;
    foreach (i; 0..H) foreach (j; 0..W) if (A[i][j] != '#') ans = max(ans, f(i, j));
    ans.writeln;
}

Measured memory_bytes: 1276
from bisect import *
from collections import *
from fractions import gcd
from math import factorial
from itertools import *
from heapq import *
import copy


#int(input())
#map(int,input().split())
N=int(input())
A=list(map(int,input().split()))

for a in A:
    if a%2==0:
        if a%3==0 or a%5==0:
            pass
        else:
            print("DENIED")
            exit()
print("APPROVED")


Measured memory_bytes: 64492
using System;
using System.Collections.Generic;
using System.Text;

namespace AtCoder.Abc
{
    //https://atcoder.jp/contests/abc142/tasks/abc142_a
    public class QuestionA
    {
        public static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            if(n % 2 == 0)
            {
                Console.WriteLine(0.5);
            }
            else
            {
                float count = (n / 2) + 1;
                Console.WriteLine(count / n);
            }
        }
    }
}


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

struct Product{string name;double value;};
bool comp(Product a,Product b)
{
  return a.value!=b.value?a.value>b.value:a.name<b.name;
}

int main()
{
  int N;
  string L;
  double P,A,B,C,D,E,F,S,M;
  while(cin>>N,N){
    vector<Product>list;
    for(int i=0;i<N;i++){
      cin>>L>>P>>A>>B>>C>>D>>E>>F>>S>>M;
      double time=A+B+C+(D+E)*M;
      Product p={L,(F*S*M-P)/time};
      list.push_back(p);
    }
    sort(list.begin(),list.end(),comp);
    for(int i=0;i<list.size();i++)cout<<list[i].name<<endl;
    cout<<"#"<<endl;
  }
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
#define ll long long int
#define M 1000000007
#define mp(x,y) make_pair(x,y)
#define pb(x) push_back(x)
#define pi pair<ll,ll>
using namespace std;

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

    int n,i;
    cin>>n>>i;
    cout<<n-i+1;

return(0);
}


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

#define INF (1e9)
#define INF_LL (1e17)
#define YJ 1145141919810
#define mod 1000000007

using LL = long long;
using ULL = unsigned long long;

using namespace std;

#define MAX_N 100005
#define MAX_D 11

int N, M, Q;
vector<int> Edge[MAX_N];

int V[MAX_N], C[MAX_N], D[MAX_N];

int Stamp[MAX_N];
bool Color[MAX_N][MAX_D];

using II = pair<int, int>;

void solve()
{
  memset(Color, 0, sizeof(Color));

  for (int q = Q-1; 0 <= q; q--) {

    if(Color[V[q]][D[q]]){
      continue;
    }

    queue<II> que;
    que.push(II(V[q], D[q]));

    while(que.size()){
      II p = que.front();
      que.pop();

      int v = p.first;
      int d = p.second;


      if(Stamp[v] == 0)
        Stamp[v] = C[q];

      if(d == 0){
        continue;
      }

      for (int i = 0; i < Edge[v].size(); i++) {
        int next = Edge[v][i];
        if(!Color[next][d-1]){
          Color[next][d-1] = true;
          que.push(II(next, d-1));
        }
      }

    }

  }

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

}

int main()
{
  cin >> N >> M;
  for (int i = 0; i < M; i++) {
    int a, b;
    cin >> a >> b; a--; b--;
    Edge[a].push_back(b);
    Edge[b].push_back(a);
  }
  cin >> Q;
  for (int i = 0; i < Q; i++) {
    cin >> V[i] >> D[i] >> C[i];
    V[i]--;
  }

  solve();

  return 0;
}


Measured memory_bytes: 9708
using System;
using System.Collections.Generic;
public class ABC136A {
    public static void Main() {
        int A, B, ans = 0;
        int plus, minus, seki;
        string[] str = Console.ReadLine().Split(' ');
        A = int.Parse(str[0]);
        B = int.Parse(str[1]);

        plus = A + B;
        minus = A - B;
        seki = A * B;
        ans = Math.Max(Math.Max(plus, minus),seki);
        Console.WriteLine(ans);
    }
}


Measured memory_bytes: 13268
/* 
    AABRA KA DABRA.. !! 
*/
#include "bits/stdc++.h"
using namespace std;
typedef long double ld;
#define int long long
#define RAGE ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define rep(i,n) for(i=0; i <n; i++)
#define repv(i,k,n) for(int i=k; i<=n; i++)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define sz(x) (int)x.size()
#define all(v) v.begin(),v.end()
#define endl '\n'
#define deb(x) cout<<#x<<" = "<<x<<endl
#define gcd __gcd
#define inf LLONG_MAX
#define minf LLONG_MIN 
const int mod = (int)(1e9+7);

int power(int x,int n)
{   
    if(n==0)    return 1;
    if(n==1)    return x%mod;
    if(n%2==0)  {   int y = power(x,n/2)%mod;return (y*y)%mod;}
    if(n&1)     {   int y = power(x,n-1);return (x%mod * y%mod)%mod;}
    return 0;
}
bool is_power_2(int n)
{
    return log2(n)==floor(log2(n));
}
bool is_prime(int n)
{
    for(int i=2; i*i<=n; i++)
        if(n%i==0)
            return 0;
    return 1;
}
int dx[]    =  {-1, 0, 1,  0, -1, -1, 1,  1};
int dy[]    =  { 0, 1, 0, -1, -1,  1, 1, -1};
const int maxn = 200005;

/*                                                                 
    ╩═╦═╩═╦═╩═╦═╩═╦═╩═╦═╩╦═╩═╦═╩═╦═╩═╦═╩═╦═╩╦═╩═╦═╩═╦═╩═╦═╩═╦═╩╦═╩═╦═╩═╦ 
*/  


void solve()
{   
    int n,i,j,k,m;
    cin>>n;
    k =1;
    while( (360*k)%n!=0)
        k++;
    cout<<(360*k)/n;
}   
signed main()
{
    RAGE;
    int t=1;
    //  cin>>t;
    while(t--)
        solve();
    return 0;
}

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

#define pb(n) push_back(n)
#define fi first
#define se second
#define all(r) (r).begin(),(r).end()
#define gsort(st,en) sort((st),(en),greater<int>())
#define vmax(ary) *max_element(all(ary))
#define vmin(ary) *min_element(all(ary))
#define debug(x) cout<<#x<<": "<<x<<endl
#define fcout(n) cout<<fixed<<setprecision((n))
#define scout(n) cout<<setw(n)
#define vary(type,name,size,init) vector< type> name(size,init)

#define rep(i,n) for(int i = 0; i < (int)(n);++i)
#define REP(i,a,b) for(int i = (a);i < (int)(b);++i)
#define repi(it,array) for(auto it = array.begin(),end = array.end(); it != end;++it)
#define repa(n,array) for(auto &n :(array))

using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using dict = map<string,int>;
using pii = pair<int,int> ;

constexpr int imax = ((1<<30)-1)*2+1 ;
constexpr int inf = 100000000;
constexpr double PI = acos(-1.0) ;
double eps = 1e-10 ;
const int dy[] = {-1,0,1,0};
const int dx[] = {0,-1,0,1};

inline bool value(int x,int y,int w,int h){
  return (x >= 0 && x < w && y >= 0 && y < h);
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  char x;
  while(cin>>n && n){
    vector<vector<int>> vc(n,vector<int>(n,0));
    rep(i,n){
      rep(j,n){
        cin >> x;
        vc[j][i] = x;
        vc[j][i] -= '0';
      }
    }
    auto tmp = vc;
    int ma = 0;
    rep(i,n){
      rep(j,n){
        if( j > 0 && tmp[j][i]){
          tmp[j][i] += tmp[j-1][i];
        }
        ma = max(ma,tmp[j][i]);
      }
    }
    tmp = vc;
    rep(j,n){
      rep(i,n){
        if( i > 0 && tmp[j][i]){
          tmp[j][i] += tmp[j][i-1];
        }
        ma = max(ma,tmp[j][i]);
      }
    }
    //??????->??????
    tmp = vc;
    rep(i,n){
      rep(j,n){
        if( j < n-1 && i > 0&& tmp[j][i]){
          tmp[j][i] += tmp[j+1][i-1];
        }
        ma = max(ma,tmp[j][i]);
      }
    }
    //??????->??????
    tmp = vc;
    rep(i,n){
      rep(j,n){
        if( j > 0 && i > 0 && tmp[j][i]){
          tmp[j][i] += tmp[j-1][i-1];
        }
        ma = max(ma,tmp[j][i]);
      }
    }
    cout << ma << endl;
  }
  return 0;
}

Measured memory_bytes: 3424
use std::io::*;
use std::str::FromStr;

pub 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")
}

use std::cmp::min;

fn main() {
    let n: usize = read();
    let mut a: Vec<i64> = vec![];
    for _ in 0..n {
        let ai = read();
        a.push(ai);
    }

    // first is -
    let mut flag = -1;
    let mut sum = 0;
    let mut ans1 = 0;
    for i in 0..a.len() {
        let ai = a[i];
        sum += ai;
        if flag == -1 && sum >= 0 {
            ans1 += (sum + 1).abs();
            sum = -1;
        }
        if flag == 1 && sum <= 0 {
            ans1 += (1 - sum).abs();
            sum = 1;
        }
        flag = -flag;
    }
    let mut flag = 1;
    let mut sum = 0;
    let mut ans2 = 0;
    for i in 0..a.len() {
        let ai = a[i];
        sum += ai;
        if flag == -1 && sum >= 0 {
            ans2 += (sum + 1).abs();
            sum = -1;
        }
        if flag == 1 && sum <= 0 {
            ans2 += (1 - sum).abs();
            sum = 1;
        }
        flag = -flag;
    }
    println!("{}", min(ans2, ans1));

    // first is +
}


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

using namespace std;

int main() {
  int K, A, B;
  cin >> K >> A >> B;
  int t = (A + K - 1) / K;
  if (t * K <= B) {
    cout << "OK" << endl;
  } else {
    cout << "NG" << endl;
  }
  return 0;
}


Measured memory_bytes: 3600
/* - - - - - - - - - - - - - - -
	User : 		VanishD
	problem :
	Points : 	
- - - - - - - - - - - - - - - */
# include <bits/stdc++.h>
# define 	ll 		long long
using namespace std;
const int inf = 0x3f3f3f3f, INF = 0x7fffffff;
const ll  infll = 0x3f3f3f3f3f3f3f3fll, INFll = 0x7fffffffffffffffll;
int read(){
	int tmp = 0, fh = 1; char ch = getchar();
	while (ch < '0' || ch > '9'){ if (ch == '-') fh = -1; ch = getchar(); }
	while (ch >= '0' && ch <= '9'){ tmp = tmp * 10 + ch - '0'; ch = getchar(); }
	return tmp * fh;
}
const int N = 300010;
int n, k, ans, l[N], r[N], numl, numr;
int main(){
//	freopen(".in", "r", stdin);
//	freopen(".out", "w", stdout);
	n = read(), k = read();
	for (int i = 1; i <= n; i++){
		int x = read();
		if (x < 0) l[++numl] = -x;
			else r[++numr] = x;
	}
	for (int i = 1, j = numl; i < j; i++, j--) swap(l[i], l[j]);
	ans = inf;
	for (int i = 1; i <= numl && i <= k; i++)
		if (k - i <= numr) ans = min(ans, l[i] * 2 + r[k - i]);
	for (int i = 1; i <= numr && i <= k; i++)
		if (k - i <= numl) ans = min(ans, r[i] * 2 + l[k - i]);
	if (numl >= k) ans = min(ans, l[k]);
	if (numr >= k) ans = min(ans, r[k]);
	printf("%d\n", ans);
	return 0;
}


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

int N, M, sum;
int A[50], B[50];
bool AB[50][50];
bool V[50];

int dfs(int v) {
	V[v] = true;
	sum++;

	if (sum == N) 
		return true;

	for (int m = 0; m < M; m++) {
		if ((AB[v][m] == true || AB[m][v] == true) && V[m] == false)
			if (dfs(m))return true;
	}

	return false;
}

int main()
{
	int ans = 0;

	cin >> N >> M;

	for (int m = 0; m < M; m++) {
		cin >> A[m] >> B[m];
		A[m]--;
		B[m]--;
		AB[A[m]][B[m]] = AB[B[m]][A[m]] = true;
	}

	for (int m = 0; m < M; m++) {
		sum = 0;

		AB[A[m]][B[m]] = AB[B[m]][A[m]] = false;

		for (int v = 0; v < 50; v++)
			V[v] = false;

		if (!dfs(A[0]))ans++;

		AB[A[m]][B[m]] = AB[B[m]][A[m]] = true;
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int n;
long long x[200001],y[200001],yp[200001],xp[200001],mnx=0x3f3f3f3f3f3f3f3f,mny=0x3f3f3f3f3f3f3f3f,mxx=-0x3f3f3f3f3f3f3f3f,mxy=-0x3f3f3f3f3f3f3f3f,ans[200001],out;
int main() {
    cin>>n;
    for (int i=0; i<n; i++) {
        cin>>x[i]>>y[i];
        xp[i]=x[i]-y[i];
        mnx=min(mnx,xp[i]);
        mxx=max(mxx,xp[i]);
        yp[i]=x[i]+y[i];
        mny=min(mny,yp[i]);
        mxy=max(mxy,yp[i]);
    }
    for (int i=0; i<n; i++) {
        long long a=max(abs(xp[i]-mnx),abs(mxx-xp[i])),b=max(abs(yp[i]-mny),abs(mxy-yp[i]));
        ans[i]=max(a,b);
    }
    for (int i=0; i<n; i++) {
        out=max(out,ans[i]);
    }
    cout<<out<<'\n';
}

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

int main(){
    using namespace std;
    unsigned long N, X, Y;
    cin >> N >> X >> Y;
    vector<unsigned long> d(N);
    for(unsigned long i{2}; i <= N; ++i)for(unsigned long j{1}; j < i; ++j)++d[min({i - j, max(i, X) - min(i, X) + 1 + max(j, Y) - min(j, Y), max(i, Y) - min(i, Y) + 1 + max(j, X) - min(j, X)})];
    copy(d.begin() + 1, d.end(), ostream_iterator<unsigned long>(cout, "\n"));
    return 0;
}

Measured memory_bytes: 256
# import sys
# import math
# import itertools
from collections import deque
# from collections import defaultdict
# import heapq
# import copy
# import bisect
# import numpy as np
# from scipy.special import comb

# def my_input(): return sys.stdin.readline().rstrip()
# sys.setrecursionlimit(100000)
# INF = 1001001001001
# MOD = 1000000007


def main():

    S = input()
    Q = int(input())

    str_q = deque()

    for s in S:
        str_q.append(s)

    reverse = False
    for _ in range(Q):
        t, *query = input().split()
        if t == '1':
            reverse = not reverse
        else:
            f, c = query
            if f == '1':
                if reverse:
                    str_q.append(c)
                else:
                    str_q.appendleft(c)
            else:
                if reverse:
                    str_q.appendleft(c)
                else:
                    str_q.append(c)

    ans = list(str_q)
    if reverse:
        ans = ans[::-1]
    print(''.join(ans))


if __name__ == '__main__':
    main()


Measured memory_bytes: 10100
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n;i>0;i--)
#define rep1(i,s,n) for(int i=s;i<n;i++)
#define max0(a,b,c) max(max(a,b),c)
#define min0(a,b,c) min(min(a,b),c) 
using namespace std;
using Graph = vector<vector<int>>;
typedef long long ll;

int main(){
    int n,k=0,ans=1;
    cin >> n;
    vector<ll> a(n),b(n,0);
    rep(i,n) cin >> a[i];
    sort(a.begin(),a.end());
    rep(i,n-1){
        if(a[i]==a[i+1]){
            b[k]++;
        }else{
            ans++;
            b[k]++;
            k++;
        }
    }
    b[k]++;
    rep(i,n){
        if(b[i]==0) break;
        if(b[i]%2==0) ans--;
    }
    cout << ans << endl;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define MOD	1000000007
#define int	long long
#define pii pair<int,int> 
#define vi vector<int>
using namespace std;

int32_t main(){
	int n, k;
	cin >> n >> k;
	int a[n];
	for(int i = 0; i < n; i++)
		cin >> a[i];
	
	int dp[n] = {0};
	dp[0] = 0;
	for(int i = 1; i < n; i++){
		dp[i] = 1e18;
		for(int j = i-1; j >= max(0LL,i-k); j--){
			dp[i] = min(dp[i],dp[j]+abs(a[i]-a[j]));
		}
	}
	cout << dp[n-1];

	return 0;
}



Measured memory_bytes: 1792
n = gets.chomp.split[0].to_i
w = gets.chomp.split(" ").map(&:to_i)


left = []
right = []

l = 0
r = 0

for i in 1..n-1
    l += w[i-1]
    r += w[-i]
    left.push(l)
    right.push(r)
end
right.reverse!

ans = w[0] + r
for i in 1..n-1
    dif = (right[i-1] - left[i-1]).abs
    if dif < ans 
        ans = dif
    end
end

p ans

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

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	map<ll,ll> cnt;
	int n;
	cin>>n;
	ll total = 0;
	for(int i=0; i<n; ++i){
		ll x; cin>>x;
		cnt[x]++;
		total += x;
	}
	int q;
	cin>>q;
	while(q--){
		ll a, b;
		cin>>a>>b;
		// cout<<"Before:"<<total<<" ";
		total -= cnt[a] * a;
		total += cnt[a] * b;
		cnt[b] += cnt[a];
		cnt[a] = 0;
		cout<<total<<'\n';
	}
	return 0;
}


Measured memory_bytes: 9520
#include<iostream>
#include<vector>
#include<string>
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<algorithm>
using namespace std;
int a_1(int a) {										//素数判定
	int x = 0;
	for (int i = 2; i < a; i++) {
		if (a % i == 0)x++;
	}
	if (x == 0) {
		return 0;//素数であるとき
	}
	if (x != 0) {
		return 1;//素数でないとき
	}
}
int gcd(int a, int b) {
	if (a < b) {
		a ^= b;
		b ^= a;
		a ^= b;
	}
	return b ? gcd(b, a % b) : a;
}
int lcm(int a, int b) {
	return a * b / gcd(a, b);
}
int main() {
	int a;
	cin >> a;
	cout << a + a * a + a * a * a << endl;
	return 0;
}

Measured memory_bytes: 3604
<?php

class Answer
{
    private $N;
    private $numbers;

    public function __construct()
    {
        $this->N = trim(fgets(STDIN));
        $number = trim(fgets(STDIN));
        $this->numbers = explode(' ', $number);
    }

    public function selectionSort()
    {
        $numbers = $this->numbers;
        $count = 0;
        for ($i = 0; $i < $this->N; ++$i) {
            $minj = $i;
            for ($j = $i; $j < $this->N; ++$j) {
                if ($numbers[$j] < $numbers[$minj]) {
                    $minj = $j;
                }
            }

            if ($minj === $i) {
                continue;
            }

            list($numbers[$i], $numbers[$minj]) = [$numbers[$minj], $numbers[$i]];
            ++$count;
        }
        echo implode(' ', $numbers).PHP_EOL;
        echo $count.PHP_EOL;
    }
}

$answer = new Answer();
$answer->selectionSort();



Measured memory_bytes: 9388
import java.util.*;

public class Main{
    void solve(){
        Scanner scan = new Scanner(System.in);
        System.out.println(Math.min(scan.nextInt(), scan.nextInt()) + Math.min(scan.nextInt(), scan.nextInt()));
        scan.close();
    }

    public static void main(String[] args){
        new Main().solve();
    }
}


Measured memory_bytes: 35644
#include<iostream>
#include<cstdio>
#include<queue>
#include<algorithm>
using namespace std;
priority_queue<double,vector<double>,greater<double> > q;
//double a[1001];
//int cmp(double x,double y)
//{
//	return x > y;
//}
int main(void)
{
	int n;
	double m;
	double ans = 0;
	scanf("%d",&n);
	for(int i = 1;i<=n;i++) 
	{
		scanf("%lf",&m);
//		a[i] = m;
		q.push(m);
	}
//	sort(a+1,a+1+n,cmp);
//	for(int i = 1;i<=n;i++)
//	{
//		if(i == 1) ans = a[i];
//		else
//		{
//			ans = (ans + a[i])/2.0;
//		}
//		sort(a+i+1,a+n+1,cmp);
//	}
	while(q.size()!=1)
	{
		double a = q.top();
		q.pop();
		double b = q.top();
		q.pop();
		ans = (double)(a+b)*0.5;
		q.push(ans);
	}
	printf("%.7lf",q.top());
	return 0;
} 

Measured memory_bytes: 256
// Let's bring the sky down :)
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int N = 15 + 5;
const int K = 17;
ll a[N][N];
ll dp[1 << K];
ll sum[1 << K];
int main()
{
    ios_base ::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    int n;
    cin >> n;
    for(int i = 0; i < n; i++)
        for(int j = 0; j < n; j++)
            cin >> a[i][j];
    int M = (1 << n);
    for(int i = 0; i < M; i++){
        ll ans = 0;
        for(int j = 0; j < n; j++){
            for(int k = 0; k < n; k++){
                if(((1 << j) & i) && ((1 << k) & i)){
                    ans += a[j][k];
                }
            }
        }
        ans >>= 1;
        sum[i] = ans;
    }
    fill(dp, dp + M, LLONG_MIN);
    dp[0] = 0;
    for(int mask = 0; mask < M; mask++){
        for(int submask = mask; submask > 0; submask = (submask - 1) & mask){
            dp[mask] = max(dp[mask], dp[mask ^ submask] + sum[submask]);
        }
    }
    cout << dp[M - 1];
return 0;
}


Measured memory_bytes: 1280
#include <functional>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;
const ll MOD = 1000000007LL;

class Combination {
public:
    vector <ll> fac, inv, fiv;

    Combination(int N) : fac(N + 1), inv(N + 1), fiv(N + 1) {
        fac[0] = inv[0] = fiv[0] = fac[1] = inv[1] = fiv[1] = 1;
        for (ll i = 2; i <= N; i++) {
            fac[i] = fac[i - 1] * i % MOD; // n!
            inv[i] = inv[MOD % i] * (MOD - MOD / i) % MOD; // n^-1
            fiv[i] = fiv[i - 1] * inv[i] % MOD; // (n!)^-1
        }
    }

    ll C(ll n, ll k) {
        if (k < 0 || n < k) return 0;
        return fac[n] * fiv[k] % MOD * fiv[n - k] % MOD;
    }
};

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

    ll r1, c1, r2, c2;
    cin >> r1 >> c1 >> r2 >> c2;

    Combination com(3000005);

    ll cur = com.C(r1 + c1, r1);
    ll ans = cur;
    ll mn = r1, mx = r1;
    for (int i = r1 + c1 + 1; i <= r2 + c2; i++) {
        cur = cur * 2 % MOD;

        ll new_mn = max(r1, i - c2);
        if (new_mn == mn) {
            cur += com.C(i - 1, mn - 1);
        } else {
            cur -= com.C(i - 1, mn);
        }
        mn = new_mn;

        ll new_mx = min(r2, i - c1);
        if (new_mx == mx) {
            cur -= com.C(i - 1, mx);
        } else {
            cur += com.C(i - 1, mx + 1);
        }
        mx = new_mx;

        ans = (ans + cur + MOD + MOD) % MOD;
    }

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

Measured memory_bytes: 70528