akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h> 
using namespace std;
typedef long long ll;
const int INF=0x3f3f3f3f;
const int N=5e5+5;
struct Edge{
	int to,w,next;
}edge[N];

struct node{
	int id,d;
	node(int x,int y){id=x;d=y;}
	bool operator <(const node &a)const{
		return d>a.d;
	}
};

int head[N];
int n,m,cnt;
void addedge(int u,int v,int w){
	edge[cnt].to=v;
	edge[cnt].w=w;
	edge[cnt].next=head[u];
	head[u]=cnt++;
}
int dis[N],pre[N];
bool done[N];
void init(){
	for(int i=0;i<N;i++){
		edge[i].next=-1;
		head[i]=-1;
	}
	cnt=0;
}


void dijkstra(){
	int s=1;
	for(int i=1;i<=n;i++){
		dis[i]=INF;
		done[i]=false;
	}
	dis[s]=0;
	priority_queue<node>q;
	q.push(node(s,0));
	while(!q.empty()){
		node u=q.top();
		q.pop();
		if(done[u.id])continue;
		done[u.id]=true;
		for(int i=head[u.id];~i;i=edge[i].next){
			int v=edge[i].to,w=edge[i].w;
			if(done[v])continue;
			if(dis[v]>u.d+w){
				dis[v]=u.d+w;
				q.push(node(v,dis[v]));
				pre[v]=u.id;
			}
		}
	}
	int f=1;
	for(int i=2;i<=n;i++){
		if(dis[i]==INF){
			puts("No\n");
			f=0;
		}	
	}
	if(f==1){
		printf("Yes\n");
		for(int i=2;i<=n;i++){
			printf("%d\n",pre[i]);
		}
	}
}

int main(){
		scanf("%d%d",&n,&m);
		init();
		while(m--){
			int a,b,c;
			scanf("%d%d",&a,&b);
			addedge(a,b,1);
			addedge(b,a,1);
		}
		dijkstra();
	
	return 0;
}

Measured memory_bytes: 13024
#include<bits/stdc++.h>
using namespace std;
const int N=200005;
typedef long long ll;
ll read(){
	ll x=0,f=1; char ch=getchar();
	while (ch<'0'||ch>'9'){if (ch=='-') f=-1; ch=getchar();	}
	while (ch>='0'&&ch<='9'){x=x*10+ch-'0'; ch=getchar();}
	return x*f;
}
ll a[N],b[N],s[N],n,pre[N];
set<int>sx;
map<int,int>mp;
struct BIT{
	ll s[N],m;
	ll lowbit(ll x){
		return x&(-x);
	}
	void clear(){
		for (ll i=0;i<=m;i++) s[i]=0;
	}
	void modify(ll x,ll y){
		for (ll i=x;i<=m;i+=lowbit(i)) s[i]+=y;
	}
	ll query(ll x){
		ll ans=0;
		for (ll i=x;i;i-=lowbit(i)) ans+=s[i];
		return ans;
	}
}tree;
ll calc(ll mid){
	s[0]=0; tree.clear(); tree.modify(n,1);
	ll ans=0;
	for (ll i=1;i<=n;i++){
		if (a[i]<=mid) s[i]=s[i-1]+1;
		else s[i]=s[i-1]-1;
		ans+=tree.query(n+s[i]-1);
		tree.modify(n+s[i],1);
	}
	return ans;
}
int main(){
	n=read();
	for (ll i=1;i<=n;i++) a[i]=read(),sx.insert(a[i]);
	ll cnt=0;
	for (set<int>::iterator it=sx.begin();it!=sx.end();it++) 
	mp[*it]=++cnt,pre[cnt]=*it;
	tree.m=2*n;
	for (ll i=1;i<=n;i++) a[i]=mp[a[i]];
	ll l=1,r=cnt,ans=0;
	ll x=n*(n+1)/4;
	while (l<=r){
		ll mid=(l+r)>>1;
		if (calc(mid)>x) ans=mid,r=mid-1; else l=mid+1;
	}
	ans=pre[ans];
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 14464
#include<iostream>
#include<sstream>
#include<vector>
#include<iterator>
#include<queue>
#include<utility>
using namespace std;

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

    vector<int> A(N), B(N);
    for (int i = 0; i < N; i++)
        cin >> A[i] >> B[i];

    using pll = pair<long long, long long>;
    priority_queue<pll> task;
    for (int i = 0; i < N; i++)
        task.push(pll(-B[i], A[i]));

    long long time = 0;
    bool ok = true;
    while (ok == true && task.empty() != true) {
        auto p = task.top();
        task.pop();

        int a = p.second;
        int b = -p.first;

        if (time + a > b)
            ok = false;

        time += a;
    }

    if (ok == true)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;

    return 0;
}


Measured memory_bytes: 8048
from collections import deque

N = int(input())
A = deque(maxlen=N)
x = [int(e) for e in input().split()]
x.sort()
for a in x:
    A.append(a)
l = []
for i in range(N - 2):
    (a, b, c) = (A[0], A[1], A[-1])
    if b < 0:
        l.append((c, a))
        A[-1] = c - a
    else:
        l.append((a, b))
        A[1] = a - b
    A.popleft()
print(A[1] - A[0])
l.append((A[1], A[0]))
for v in l:
    print(v[0], v[1])

Measured memory_bytes: 20828
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
#include <time.h>
typedef long long ll;
typedef long double ld;
#define INF (1LL<<60)
/*swap 交換*/
void swap(ll *a, ll *b){ll c;c=*b;*b=*a;*a=c;}
/*2つのうち大きい数を返す*/
ll max2(ll a,ll b){return a>=b?a:b;}
/*2つのうち小さい数を返す*/
ll min2(ll a,ll b){return a>=b?b:a;}
/*絶対値*/
ll ABS(ll a){return a>=0?a:(-a);}
typedef struct{
    ll aa;
    ll bb;
}frequent;
// 小大
int compare(const void *a, const void *b){return *(ll *)a - *(ll *)b;}

int main(void){
    ll i,ans=0;
    ll c[9];
    for(i=0;i<9;i++){
        scanf("%lld",&c[i]);
    }
    if( !(c[0]-c[1]==c[3]-c[4] && c[3]-c[4]==c[6]-c[7]) || !(c[2]-c[1]==c[5]-c[4] && c[5]-c[4]==c[8]-c[7]) || !(c[0]-c[3]==c[1]-c[4] && c[1]-c[4]==c[2]-c[5]) || !(c[6]-c[3]==c[7]-c[4] && c[7]-c[4]==c[8]-c[5]) ){
        ans=1;
    }
    if(ans==1) printf("No\n");
    if(ans==0) printf("Yes\n");
    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i++)
#define rng(a) a.begin(),a.end()
using namespace std;
using ll = long long;
using P = pair<int,int>;
const int INF = 1001001001;


int n, k;
int dp[100100];

int main() {
  cin >> n >> k;
  vector<int> h(n);
  rep(i,n) cin >> h[i];
  rep(i,100100) dp[i] = INF;
  dp[0] = 0;
  rep(i,n) {
    for(int j = 1; j <= k; j++) {
      if(i<n-j) dp[i+j] = min(dp[i+j],dp[i]+abs(h[i+j]-h[i]));
    }
  }
  cout << dp[n-1] << endl;
  return 0;
}

Measured memory_bytes: 4028
#include <bits/stdc++.h>
#define FOR(i, a, n) for(ll i = (ll)a; i < (ll)n; i++)
#define FORR(i, n) for(ll i = (ll)n - 1LL; i >= 0LL; i--)
#define rep(i, n) FOR(i, 0, n)
#define ALL(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
template <typename T> using V = vector<T>;

constexpr int Mod = 998244353;
constexpr int mod = 1e9 + 7;
constexpr ll inf = 1LL << 60;

template <typename T> constexpr bool chmax(T &a, const T &b) {
    if(a >= b) return false;
    a = b;
    return true;
}
template <typename T> constexpr bool chmin(T &a, const T &b) {
    if(a <= b) return false;
    a = b;
    return true;
}

/*-------------------------------------------*/

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

    int n;
    ll ans = 0;
    ll t;
    cin >> n >> t;
    ll pre = -inf;
    ll x;
    rep(i, n) {
        cin >> x;
        ans += min(t, x - pre);
        pre = x;
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>

int main(void)
{
	double a, b, c, d, e, f;
	
	scanf("%lf %lf %lf %lf", &a, &b, &c, &d);
	
	e = ((c-a)*(c-a))+((d-b)*(d-b));
	f = sqrt(e);
	
	printf("%.8f\n", f);
}


Measured memory_bytes: 2112
import copy

s = input()
X, Y = list(map(int, input().split()))

#少なくとも、右にx,↑にy進まなきゃいけない
# Fはくっつけられる
# s < 8000 よって N^2くらいならok
# Tが1回→左右 2回→前か後ろ 3回→左右
# この性質から、左右は左右のみで考えればいい
# x方向の数字N個をつかって、xを作成する 足し引きのみ 2^N xを加えて0にできるかどうか

s += "T"

now = 1
# 1はx方向、-1はy方向とする
start = 0
go = 0
x = []
y = []
for i in s:
    if i == "T":
        if start == 0:
            X = X - go
            go = 0
            start = 1
        else:
            if go != 0:
                if now == 1:
                    x.append(go)
                else:
                    y.append(go)
                go = 0
        now *= -1
    if i == "F":
        go += 1
x.sort()
y.sort()
x = x[::-1]
y = y[::-1]
X = abs(X)
Y = abs(Y)
x_use = sum(x) - X
y_use = sum(y) - Y
if x_use % 2 == 1 or y_use % 2 == 1 or x_use < 0 or y_use < 0:
    print("No")
    exit()
x_use = x_use//2
y_use = y_use//2


def solve(integer_list, target_sum,  i=0, sum=0):
    if sum > target_sum:
        return False
    if sum == target_sum:
        return True
    if i == len(integer_list):
        return sum == target_sum
    if (solve(integer_list, target_sum, i + 1, sum)):
        return True
    if (solve(integer_list, target_sum, i + 1, sum + integer_list[i])):
        return True
    return False

#if solve(x, x_use) and solve(y, y_use):
#    print("Yes")
#else:
#    print("No")


def part_sum0(a,A):
    #初期化
    N=len(a)
    dp=[[0 for i in range(A+1)] for j in range(N+1)]
    dp[0][0]=1

    #DP
    for i in range(N):
        for j in range(A+1):
            if a[i]<=j: #i+1番目の数字a[i]を足せるかも
                dp[i+1][j]=dp[i][j-a[i]] or dp[i][j]
            else: #入る可能性はない
                dp[i+1][j]=dp[i][j]
    return dp[N][A]
 
if part_sum0(x,x_use) and part_sum0(y, y_use):
    print("Yes")
else:
    print("No")

Measured memory_bytes: 17384
#include <bits/stdc++.h>
using namespace std;
int n,m,ans;
bool used[9],d[9][9];
void dfs(int p, int c){
  if(c==n) ans++;
  used[p]=1;
  for(int i=1; i<=n; i++){
  	if(!used[i] && d[p][i]) dfs(i, c+1);
  }
  used[p]=0;
}
  int main(){
    cin >> n >> m;
    for(int i=0,a,b; i<m; i++){
    	cin >> a >> b;
      d[a][b]=d[b][a]=1;
    }
	dfs(1,1);
    cout << ans << endl;
}

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

int int_len(int n) {
  int s=0;
  while(n!=0) s++, n/=10;
  return s;
}

int int_sum(int n) {
  int m=0,s=0,a=n;
  while(a!=0) s++, a/=10;
  for(int i=s-1;i>=0;i--) m+=n/((int)pow(10,i))-(n/((int)pow(10,i+1)))*10;
  return m;
}






int gcd(int a,int b)
{
 
  int r, tmp;
 
  
 
  /* 自然数 a > b を確認・入替 */
  if(a<b){
    tmp = a;
    a = b;
    b = tmp;
  }
 
  /* ユークリッドの互除法 */
  r = a % b;
  while(r!=0){
    a = b;
    b = r;
    r = a % b;
  }
 
 
 
  return b;
}







int fac(int n){
  int m=1;
  while(n>=1) m*=n,n--;
  return m;
}

int vec_sum(vector<int> v){
  int n=0;
  for(int i=0;i<v.size();i++) n+=v[i];
  return n;
}
///////////////////////////
int main() {
  int n,ans=0;
  cin>>n;
  vector<int> v(n);
  rep(i,n) cin>>v[i];
  for(int i=0;i<n-1;i++){
    for(int j=i+1;j<n;j++){
      ans+=v[i]*v[j];
    }
  }
  cout<<ans<<endl;
  
  
}
///////////////////////////

Measured memory_bytes: 256
using System;
using System.CodeDom.Compiler;
using System.Collections.Generic;
using System.ComponentModel.Design;
using System.Drawing;
using System.Linq;
using System.Runtime.InteropServices;
using System.Threading;
using System.Windows.Markup;

namespace AlgoTest1
{

    class Program
    {
        static void Main(string[] args)
        {
            Int32 K = Int32.Parse(Console.ReadLine());
            string S = Console.ReadLine();

            if(S.Length <= K)
            {
                Console.WriteLine(S);
            }
            else
            {
                Console.WriteLine(S.Substring(0, K) + "...");
            }
        }
    }
}

Measured memory_bytes: 27488
#include <bits/stdc++.h>
#define rep(i,a,b) for (int i = (a); i < (b); i++)
#define REP(i,n) rep(i,0,n)
using namespace std;

int main()
{  
    int n,comm,key;
    string color;
    multimap<string,int>s;
    cin>>n;
    REP(i,n)
    {
        cin>>comm;
        if(comm==0)
        {
            cin>>color>>key;
            s.insert(make_pair(color,key));
        }
        if(comm==1)
        {
            cin>>color;
            for(auto it=s.lower_bound(color);it!=s.end()&&it->first==color;it++)
            {
                cout<<it->second<<endl;
            } 
        }
        if(comm==2)
        {
            cin>>color;
            s.erase(color);
        }
        if(comm==3)
        {
            string l,r;
            cin>>l>>r;
            decltype(s)::iterator it=s.lower_bound(l);
            decltype(s)::iterator end=s.upper_bound(r);
            while(it!=end)
            {
                cout<<it->first<<" "<<it->second<<endl;
                it++;
            }
        }
    }
}



Measured memory_bytes: 24804
a=input()
list=['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
print(list[1+list.index(a)])

Measured memory_bytes: 2940
#include <iostream>
#include <string>
#include <vector>
#include <stdio.h>

using namespace std;

//マクロ
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 999999999

//debug
#define dump(x) cout << #x << " = " << (x) << endl;

//配列の要素を順番に出力
void trace(int A[], int N){
    int i;
    for (i = 0; i < N; i++){
        if (i>0) printf(" ");
        printf("%d", A[i]);
    }
    printf("\n");
}

///////////////////////////////////////////////////////////////
//ALDS1_2_b
//Selection Sort

void selection_sort(int A[], int N, int& count){
    int i, j, minj;
    for (i=0; i<N; i++){
        minj = i;
        for (j=i; j<N; j++){
            if (A[j] < A[minj]){
                minj = j;
            }
        }
        swap(A[i], A[minj]);
        if (i != minj) count++;
    }
}

int main(){
    const int N_MAX = 100;
    int A[N_MAX], N, count;
    count = 0;
    scanf("%d", &N);
    REP(i, N) scanf("%d", &A[i]);
    selection_sort(A, N, count);
    trace(A, N);
    printf("%d\n", count);
    return 0;
}


Measured memory_bytes: 3216
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using static System.Console;
using static System.Math;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var A = ReadInt();
            var B = ReadInt();
            var C = ReadInt();
            var D = ReadInt();
            var E = ReadInt();

            var ans = 0;
            if (A < 0)
            {
                //凍っている
                var a = 0 - A;
                ans += a * C;
                ans += D;

                ans += B * E;
            }
            else
            {
                //凍っていない
                ans += (B - A) * E;
            }
            WriteLine(ans);
        }

        private static string Read() { return ReadLine(); }
        private static string[] Reads() { return (Read().Split()); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }
    }
}


Measured memory_bytes: 15868
#include <iostream>
#include <iomanip>
#include <string>
#include <stack>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <map>
#include <set>
#include <queue>
#include <list>
#include <regex>
using namespace std;
using pii  = pair<int,int>;
using ll=long long;
using ld=long double;
#define pb push_back
#define mp make_pair
#define sc second
#define fr first
#define stpr setprecision
#define cYES cout<<"YES"<<endl
#define cNO cout<<"NO"<<endl
#define cYes cout<<"Yes"<<endl
#define cNo cout<<"No"<<endl
#define rep(i,n) for(ll i=0;i<(n);++i)
#define Rep(i,a,b) for(ll i=(a);i<(b);++i)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define rRep(i,a,b) for(int i=a;i>=b;i--)
#define crep(i) for(char i='a';i<='z';++i)
#define psortsecond(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.second<b.second;});
#define ALL(x) (x).begin(),(x).end()
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl;
#define endl '\n'
int ctoi(const char c){
  if('0' <= c && c <= '9') return (c-'0');
  return -1;
}
ll gcd(ll a,ll b){return (b == 0 ? a : gcd(b, a%b));}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}
constexpr ll MOD=1000000007;
constexpr ll INF=1000000011;
constexpr ll MOD2=998244353;
constexpr ll LINF = 1001002003004005006ll;
constexpr ld EPS=10e-8;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
template<typename T> istream& operator>>(istream& is,vector<T>& v){for(auto&& x:v)is >> x;return is;}
template<typename T,typename U> istream& operator>>(istream& is, pair<T,U>& p){ is >> p.first; is >> p.second; return is;}
template<typename T,typename U> ostream& operator>>(ostream& os, const pair<T,U>& p){ os << p.first << ' ' << p.second; return os;}
template<class T> ostream& operator<<(ostream& os, vector<T>& v){
    for(auto i=begin(v); i != end(v); ++i){
        if(i !=begin(v)) os << ' ';
        os << *i;
    }
    return os;
}

ld N;
ld X[10],Y[10],W=0;

int main(){
    ll C[10];
    cin >> N;
    ld ans=0;
    rep(i,10){
        C[i]=0;
    }
    rep(i,(int)N){
        cin >> X[i] >> Y[i];
    }
    rep(i,(int)N-1){
        Rep(j,i+1,(int)N){
            W+=sqrt((ld)fabs(X[i]-X[j])*(ld)fabs(X[i]-X[j])+(ld)fabs(Y[i]-Y[j])*(ld)fabs(Y[i]-Y[j]));
            ans+=1;
        }
    }
    cout << stpr(10) << W/ans*(N-1)<< endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define iinf 2000000000
#define linf 1000000000000000000LL
#define ulinf 10000000000000000000ull
#define MOD1 1000000007
#define lson(v) ((v)<<1)
#define rson(v) (((v)<<1)^1)
#define mpr make_pair
typedef long long LL;
typedef unsigned long long ULL;
typedef unsigned long UL;
typedef unsigned short US;
typedef pair < int , int > pii;
clock_t __stt;
inline void TStart(){__stt=clock();}
inline void TReport(){printf("\nTaken Time : %.3lf sec\n",(double)(clock()-__stt)/CLOCKS_PER_SEC);}
template < typename T > T MIN(T a,T b){return a<b?a:b;}
template < typename T > T MAX(T a,T b){return a>b?a:b;}
template < typename T > T ABS(T a){return a>0?a:(-a);}
template < typename T > void UMIN(T &a,T b){if(b<a) a=b;}
template < typename T > void UMAX(T &a,T b){if(b>a) a=b;}
int n,a[2005];
bitset < 4000005 > cur; 
int main(){
    // inputing start
    scanf("%d",&n);
	int xb,x2,sum=0,tot=0,tar;
	for(xb=0;xb<n;++xb) {
		scanf("%d",a+xb);
		tot+=a[xb];
	}
    #ifdef LOCAL
        TStart();
    #endif
    // calculation start
	tar=(tot+1)/2;
	cur[0]=cur[a[0]]=1;
	for(xb=1;xb<n;++xb){
		cur|=cur<<a[xb];
	}
	for(xb=tar;xb<4000003;++xb){
		if(cur[xb]){
			printf("%d\n",xb);
			return 0;
		}
	}
    #ifdef LOCAL
        TReport();
    #endif
    return 0;
}

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

using namespace std;


void DividetheProblems()//problems 132
{
  int n;
  cin >> n;
  vector<int> d(n);
  cin >> d[0];
  int min = d[0];
  for (int i = 1; i < n; i++)
  {
    cin >> d[i];
    if (min > d[i]) min = d[i];
  }
  sort(d.begin(), d.end());
  int id = n / 2;
  cout << d[id] - d[id - 1] << endl;
  return;
}


int main()
{
  DividetheProblems();
  return 0;
}

Measured memory_bytes: 640
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<utility>
#include<map>
#include<set>
#include <sstream>
#include<queue>
#include<stack>
#include<functional>
#include<math.h>
using namespace std;

int main(void){
    string S;
    string T;
    cin >> S;
    cin >> T;
    auto x = T.substr(0,S.size());
    if(x == S && S.size()+1 == T.size()){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
int dfs(int x,int y);
char mp[409][409];
int dx[]={0,1,0,-1};
int dy[]={-1,0,1,0};
int f[409][409];
int cnt=1,h,w;
typedef pair<long long,long long>P;
P t[1000000];

int main(){
  cin>>h>>w;
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      cin>>mp[i][j];
    }
  }
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      if(f[i][j]==0){
	dfs(j,i);
	cnt++;
      }
    }
  }
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      //cout<<f[i][j]<<' ';
      if(mp[i][j]=='#'){
	t[f[i][j]].first++;
      }
      else{
	t[f[i][j]].second++;
      }
    }
    //cout<<endl;
  }
  long long ans=0;
  for(int i=1;i<=h*w;i++){
    ans+=t[i].first*t[i].second;
  }
  cout<<ans<<endl;
  return(0);
}

int dfs(int x,int y){
  f[y][x]=cnt;
  for(int i=0;i<4;i++){
    int nx=x+dx[i];
    int ny=y+dy[i];
    if(0<=nx&&nx<w&&0<=ny&&ny<h&&f[ny][nx]==0){
      //cout<<mp[y][x]<<' '<<mp[ny][nx]<<endl;
      if(mp[y][x]!=mp[ny][nx]){
	dfs(nx,ny);
      }
    }
  }
}


Measured memory_bytes: 9856
import sys
input = sys.stdin.readline
inputs = lambda:map(int, input().split())
n, q = inputs()
e = [[] for _ in range(n)]
counter = [0] * n
m = n-1
for _ in range(m):
    v1, v2 = inputs()
    v1 -= 1
    v2 -= 1
    e[v1] += v2,
    e[v2] += v1,
for _ in range(q):
    p, x = inputs()
    p -= 1
    counter[p] += x
used = [False] * n
s = 0
used[s] = True
stack = [s]
while stack:
    s = stack.pop()
    for c in e[s]:
        if used[c]:
            None
        else:
            used[c] = True
            counter[c] += counter[s]
            stack += c,
print(*counter)

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

int ans = 8;
int p[30];
int q[30] = {1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 4, 4,
             4, 6, 6, 6, 5, 5, 5, 3, 3, 3, 3, 3, 3, 3, 3, 3};
bool flag;
void swap(int* a, int* b) {
    int tmp = *a;
    *a = *b;
    *b = tmp;
}

void rot(int i) {
    if (i == 0) {
        swap(p[0], p[27]);
        swap(p[1], p[28]);
        swap(p[2], p[29]);
        swap(p[14], p[15]);
        swap(p[18], p[20]);
    } else if (i == 1) {
        swap(p[6], p[21]);
        swap(p[7], p[22]);
        swap(p[8], p[23]);
        swap(p[12], p[17]);
        swap(p[9], p[11]);
    } else if (i == 3) {
        swap(p[0], p[23]);
        swap(p[3], p[26]);
        swap(p[6], p[29]);
        swap(p[9], p[20]);
        swap(p[15], p[17]);
    } else {
        swap(p[2], p[21]);
        swap(p[5], p[24]);
        swap(p[8], p[27]);
        swap(p[11], p[18]);
        swap(p[12], p[14]);
    }
}

void solve(int n) {
    if (n == 8) return;
    
    flag = true;
    for (int i = 0; i < 30; i++) {
        if (p[i] != q[i]) flag = false;
    }
    if (flag) {
        ans = min(ans, n);
        return;
    }
    for (int i = 0; i < 4; i++) {
        rot(i);
        solve(n + 1);
        rot(i);
    }
}

int main() {
    int N;
    cin >> N;
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < 30; j++) {
            cin >> p[j];
        }
        ans = 8;
        flag = false;
        solve(0);
        cout << ans << "\n";
    }
    return 0;
}


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

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

	string res = "No";
	if ( (A == B && B != C) || (A == C && B != C) || (B == C && A != C) )
	{
		res = "Yes";
	}

	cout << res << endl;
}


Measured memory_bytes: 256
import java.util.*;

class Main{

    String lefts="qwertasdfgzxcvb";
    String rights="yuiophjklnm";

    void solve(){
	Scanner sc=new Scanner(System.in);
	while(true){
	    String s=sc.next();
	    if(s.equals("#"))break;
	    boolean lr=true;
	    int count=0;
	    String c="";c+=s.charAt(0);
	    if(lefts.contains(c))lr=true;
	    else lr=false;

	    for(int i=1;i<s.length();i++){
		c="";c+=s.charAt(i);
		boolean z=lefts.contains(c);
		if(lr && !z){count++;lr=false;}
		else if(!lr && z){count++;lr=true;}

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

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

using namespace std;
int main() {
  int H, A;
  cin >> H;
  cin >> A;
  int n;
  n = H / A;
  if (H % A == 0) {
    cout << n << endl;
  } else {
    cout << n + 1 << endl;
  }
  return 0;
}

Measured memory_bytes: 256
h, w = map(int, input().split())
s = [['+']*(w+2)]

for a in range(h):
    tmp = list(str(input()))
    tmp.insert(0, '+')
    tmp.append('+')
    s.append(tmp)

s.append(['+']*(w+2))

count = 0
word = ''

for a in range(1, h+1):
    for b in range(1, w+1):
        if s[a][b] == '.':
            if s[a-1][b] == '#':
                count += 1
            if s[a-1][b-1] == '#':
                count += 1
            if s[a-1][b+1] == '#':
                count += 1

            if s[a][b-1] == '#':
                count += 1
            if s[a][b+1] == '#':
                count += 1

            if s[a+1][b-1] == '#':
                count += 1
            if s[a+1][b] == '#':
                count += 1
            if s[a+1][b+1] == '#':
                count += 1
            word += str(count)
        elif s[a][b] == '#':
            word += '#'
        count = 0
    print(word)
    word = ''


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

using namespace std;

int main()
{
    int x, y;
    cin >> x >> y;

    if (y % 2 == 0 and y >= 2 * x and y <= 4 * x)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;

    return 0;
}


Measured memory_bytes: 3588
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
int main(){
	char ca[105];
	char cb,cc;
	int i,j,k;
	int a,b,c;
	int s=105;
	cin>>ca;
	for(cb='a';cb<='z';cb++){
		for(a=0,b=0,i=0;i<strlen(ca);i++,b++){
			if(ca[i]==cb){
				if(a<b)a=b;
				b=-1;
			}
		}
		if(a<b)a=b;
		if(a<s)s=a;
	}
	cout<<s<<endl;
	return 0;
}
		
			


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll         long long
#define mod        1000000007
#define setbits(x) __builtin_popcountll(x)
#define zrobits(x) __builtin_ctzll(x)
#define inf        1e18
#define ps(x,y)    fixed<<setprecision(y)<<x

int main() {

#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	int n, x, y;
	cin >> n >> x >> y;
	int a[n];
	x--; y--;
	for (int i = 0; i < n; ++i)
	{
		cin >> a[i];
	}
	std::vector<int> v(n, 0);
	for (int i = 0; i < n - 1; ++i)
	{
		for (int j = i + 1; j < n; ++j)
		{
			int m = min(j - i, min(abs(x - i) + 1 + abs(y - j), abs(x - j) + 1 + abs(y - i)));
			v[m]++;
		}
	}
	for (std::vector<int>::iterator i = v.begin() + 1; i != v.end(); ++i)
	{
		cout << *i << endl;
	}

}

Measured memory_bytes: 3604
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		int a = sc.nextInt();
		int b = sc.nextInt();
int c = 0;
		if (a > b) {
			c += a;
			a--;
		} else {
			c += b;
			b--;
		}
		if (a > b) {
			c += a;
			a--;
		} else {
			c += b;
			b--;
		}
		System.out.println(c);
	}
}

Measured memory_bytes: 23892
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
int main(void)
{
    int n, k, i, j, d, da;
    int count = 0;
    int sn[101] = {0};

    scanf("%d %d", &n, &k);
    for (i = 0; i < k; i++)
    {
        scanf("%d", &d);
        for (j = 0; j < d; j++)
        {
            scanf("%d", &da);
            sn[da - 1] = 1;
        }
    }
    for (i = 0; i < n; i++)
    {
        if (sn[i] == 0)
            count++;
    }
    printf("%d\n", count);
    return 0;
}

Measured memory_bytes: 1728
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll,ll>;
using vl = vector<ll>;
using Map = map<ll,ll>;
using Tup = tuple<ll,ll,ll>;
using vvl = vector<vector<ll>>;
#define all(v) v.begin(), v.end()
#define prt(v) cout<<(v)<<"\n";
#define fl cout<<flush;
#define fi(v) get<0>(v)
#define se(v) get<1>(v)
#define th(v) get<2>(v)
#define endl "\n"
template <typename T> bool chmax(T &a, const T &b){if (a<b){a=b;return 1;}return 0;}
template <typename T> bool chmin(T &a, const T &b){if (a>b){a=b;return 1;}return 0;}
const ll INF=1LL<<60;
const ll MOD=1000000007;
const ll MOD2=998244353;
const ld pi=3.141592653589793238;

signed main(void){
    cin.tie(0);cout.tie(0);ios::sync_with_stdio(false);
    ll N;
    cin >> N;
    vector<ll> L(N,0);
    for(ll i=0;i<N;++i)cin>>L[i];
    auto F=[&]{
        ll Max=0;
        for(ll i=0;i<N;++i)chmax(Max,L[i]);
        ll sum=0;
        for(ll i=0;i<N;++i)sum+=L[i];
        if(sum-Max>Max)return 1;
        else return 0;
    };
    if(F())prt("Yes")
    else prt("No")


    return 0;
}


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

long long n, p, q, ans, tmp;
vector<long long> c, d;

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cin >> n >> p >> q;
	c.resize(n);
	for(auto &i:c) cin >> i;
	d.resize(n);
	for(int i=0; i<n; ++i){
		d[i] = c[i] + p * (i+1);
	}
	sort(d.begin(), d.end());
	ans = tmp = accumulate(c.begin(), c.end(), 0ll);
	for(int i=0; i<n; ++i){
		tmp += p*q + (2*i+1)*p - d[i];
		ans = max(ans, tmp);
	}
	cout << ans << "\n";
}


Measured memory_bytes: 10744
#include "bits/stdc++.h"
#define _overload3(_1,_2,_3,name,...)name
#define _rep(i,n)repi(i,0,n)
#define repi(i,a,b)for(int i=int(a),i##_len=(b);i<i##_len;++i)
#define MSVC_UNKO(x)x
#define rep(...)MSVC_UNKO(_overload3(__VA_ARGS__,repi,_rep,_rep)(__VA_ARGS__))
#define all(c)c.begin(),c.end()
#define write(x)cout<<(x)<<'\n'
using namespace std; typedef long long ll; template<class T>using vv = vector<vector<T>>;
template<class T>auto vvec(int n, int m, T v) { return vv<T>(n, vector<T>(m, v)); }
constexpr int INF = 1 << 29, MOD = int(1e9) + 7; constexpr ll LINF = 1LL << 60;
struct aaa { aaa() { cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(10); }; }aaaa;

ll mpow(ll x, ll n) { ll y = 1; for (; n > 0; n /= 2) { y = n % 2 ? y * x % MOD : y; x = x * x % MOD; } return y; }
struct Combination {
    static ll mpow(ll x, ll n) { ll y = 1; for (; n > 0; n /= 2) { y = n % 2 ? y * x % MOD : y; x = x * x % MOD; } return y; }
    vector<ll> fact, ifact;
    Combination(int n) : fact(n + 1), ifact(n + 1) {
        fact[0] = 1; for (int i = 0; i < n; ++i) fact[i + 1] = fact[i] * (i + 1) % MOD;
        ifact[n] = mpow(fact[n], MOD - 2); for (int i = n; i > 0; --i) ifact[i - 1] = ifact[i] * i % MOD;
    }
    ll operator ()(int n, int k) { return k < 0 || k > n ? 0 : fact[n] * ifact[n - k] % MOD * ifact[k] % MOD; }
} C(4e5 + 10);

int main() {
    ll N, K;
    cin >> N >> K;

    if (K >= N - 1) {
        write(C(N + N - 1, N - 1));
        return 0;
    }

    ll ans = 0;
    rep(n, N - K, N + 1) {
        ll m = N - n;
        ans = (ans + C(N, n) * C(m + n - 1, n - 1)) % MOD;
    }
    write(ans);
}

Measured memory_bytes: 6556
#include <algorithm>
#include <climits>
#include <iostream>
#include <string>
#include <utility>
#include <vector>
#include <set>
#include <map>
#include <queue>


using namespace std;
using ll = long long int;

template <class T> ostream &operator<<(ostream &os, vector<T> &v) {
  for (auto i = v.begin(); i != v.end(); i++) {
    os << *i << " ";
  }
  return os;
}


void solve(long long r){
  std::cout << double(r*r) << std::endl;
}

int main(){
  long long r;
  scanf("%lld",&r);
  solve(r);
  return 0;
}



Measured memory_bytes: 256
#include"bits/stdc++.h"
using namespace std;
typedef long long ll;
#define int ll
const int N=1e5+10;
int a[N],b[N];
int32_t main()
{
  #ifndef ONLINE_JUDGE
  freopen("in","r",stdin);
  freopen("out","w",stdout);
  #endif 
  int n;
  cin>>n;
  for(int i=0;i<n;i++){cin>>a[i];b[i]=a[i];}

  int mx=max_element(a,a+n)-a;
  int nn=a[mx];
  int half=nn/2;
  for(int i=0;i<n;i++)
  {
    if(i==mx)continue;
    if(b[i]>half)b[i]=nn-b[i];
  }
  int r=0;int dist=half-b[0];
  if(0==mx){r=1;dist=half-b[1];}

  for(int i=0;i<n;i++)
  {
    if(i==mx)continue;
    if(half-b[i]<dist){dist=half-b[i];r=i;}
  }
  cout<<nn<<" "<<a[r];
  
 
}

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

const int MAX = 510000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main() {
	int n; cin >> n;
	vector<int> appear[n+1];
	int l, r;
	for(int i = 1; i <= n+1; i++) {
		int a; cin >> a;
		appear[a].push_back(i);
		if(appear[a].size() == 2) {
			l = appear[a][0];
			r = appear[a][1];
		}
	}

	COMinit();
	for (int i = 1; i <= n+1; i++)
	{
		int res = COM(n+1, i) - COM(l+n-r, i-1);
		if(res < 0) res += MOD;
		cout << res << endl;
	}


	return 0;
}


Measured memory_bytes: 18688
#include <stdio.h>
#include <string.h>
#define MN 20
#define MM 60
int n=20,m,l,tot,size[MN+5];
int hd[MN+5],to[MM+5],val[MM+5],nxt[MM+5];
void add(int u,int v,int w){
	to[m]=v,val[m]=w,nxt[m]=hd[u];
	hd[u]=m++;
}
int main(){
	memset(hd,0xff,sizeof(hd));
	scanf("%d",&l);
	for(int i=2;i<20;i++){
		add(i,i+1,0);
		add(i,i+1,1<<(19-i));
		size[i]=(1<<(20-i));
	}size[20]=1;
	for(int i=2;i<=n;i++)
		while(l-tot>=size[i]){
			add(1,i,tot);
			tot+=size[i];
		}
	printf("%d %d\n",n,m);
	for(int i=1;i<=n;i++)
		for(int j=hd[i];~j;j=nxt[j])
			printf("%d %d %d\n",i,to[j],val[j]);
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define fol(i,n) for(int i=0;i<n;++i)
using namespace std;
const int lim = 1e5;
int main(){
    int a[lim]={};
    string s;
    for(int i=1e4;i<lim;++i){
        a[i]+=a[i-1];
        s = to_string(i);
        if(s[0]==s[4]&&s[1]==s[3]) a[i]++;
    }
    int b,c;cin>>b>>c;
    cout << a[c]-a[b-1]<<endl;
    return 0;
}


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

int main(){
    int N,M; cin >> N >> M;
    int cnt[M+1]={};
    for(int i=0;i<N;i++){
        int k; cin >> k;
        for(int j=0;j<k;j++){
            int a;
            cin >> a;
            cnt[a]++;
        }
    }
    int ans=0;
    for(int i=1;i<=M;i++){
        if(cnt[i]==N) ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <map>
#include <set>
#include <cmath>
#include <queue>
#include <cstdio>
#include <vector>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm>
using namespace std;
const int N=1e5+5;
#define ll long long
#define inf 0x3f3f3f3f
#define mem(x) memset(x,0,sizeof(x))
#define sca(x) scanf("%d",&x)
#define scall(x) scanf("%lld",&x)
#define eps 1e-6
int main()
{
	ll a,sum;scall(a);
	sum=a+a*a+a*a*a;
	cout<<sum<<endl;
}

Measured memory_bytes: 3664
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
const double eps = 1e-10;
const ll MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1ll<<50;
template<typename T>
void printv(const vector<T>& s) {
  for(int i=0;i<(int)(s.size());++i) {
    cout << s[i];
    if(i == (int)(s.size())-1) cout << endl;
    else cout << " ";
  }
}
template<typename T1, typename T2>
ostream& operator<<(ostream &os, const pair<T1, T2> p) {
  os << p.first << ":" << p.second;
  return os;
}
int ans = 0;
int start = 0;
void dfs(int n, int now, int val, bitset<40> &bs, const vvi &g, const vi &b) {
  if(n == now) {
    ans = max(ans, val);
    return;
  }
  bool ok = true;
  bool distinct = true;
  for(int i=0;i<(int)(g[now].size());++i) {
    ok &= !bs[g[now][i]];
    distinct &= !bs[g[now][i]] && g[now][i] < now;
  }
  if(ok) {
    bs[now] = 1;
    dfs(n, now+1, val + b[now], bs, g, b);
    bs[now] = 0;
  }
  if(!distinct && now != start) {
    dfs(n, now+1, val, bs, g, b);
  }
}
void solve(int n) {
  vector<string> A(n);
  vector<int> B(n);
  vector<int> c(n);
  vector<vector<string>> D(n);
  set<pair<int, string>> st;
  for(int i=0;i<n;++i) {
    cin >> A[i] >> B[i] >> c[i];
    for(int j=0;j<c[i];++j) {
      string s; cin >> s;
      D[i].push_back(s);
    }
    st.insert({c[i], A[i]});
  }
  map<string, int> mp;
  int id = n-1;
  for(auto &e: st) {
    mp[e.second] = id;
    id--;
  }
  vvi g(n);
  for(int i=0;i<n;++i) {
    for(int j=0;j<c[i];++j) {
      g[mp[A[i]]].push_back(mp[D[i][j]]);
    }
  }
  vi b(n);
  for(int i=0;i<n;++i) {
    b[mp[A[i]]] = B[i];
  }
  start = mp[A[0]];
  ans = 0;
  bitset<40> bs(0);
  dfs(n, 0, 0, bs, g, b);
  cout << ans << endl;
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  while(1) {
    int n; cin >> n;
    if(n == 0) break;
    solve(n);
  }
}



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

void chk(int init, vector<pair<int, int>>& flow, vector<int>& a) {
	flow[0].first = init;
	for(int i=0; i<n; i++) {
		flow[i].second = a[i] - flow[i].first;
		if(i == n-1) break;
		flow[i+1].first = flow[i].second;
	}
}
int main() {
	ios::sync_with_stdio(0);cin.tie(0);
	cin >> n;
	vector<int> a(n);
	vector<pair<int, int>> flow(n);
	for(int i=0; i<n; i++) {
		cin >> a[i];
	}
	chk(0, flow, a);
	chk(flow.back().second/2, flow, a);
	cout << flow[0].first+flow.back().second << ' ';
	for(int i=1; i<n; i++) {
		cout << flow[i-1].second + flow[i].first << ' ';
	}
}

Measured memory_bytes: 2560
#include <queue>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
void reader(int *x) {
	int k = getchar_unlocked(); *x = k - '0';
	while (1) {
		k = getchar_unlocked();
		if (k < '0' || k > '9') break;
		*x = ((*x) << 1) + ((*x) << 3) + k - '0';
	}
}
struct state {
	int sx, sy, cost;
};
bool operator<(const state& s1, const state& s2) {
	return s1.cost < s2.cost;
}
int R, H[2], W[2], sx[2], sy[2], a[2][509][509], cnt[2], b[2][250009], vis[509][36];
int dir[] = { 0, 1, 0, -1 };
int main() {
	while (scanf("%d", &R), R) {
		for (int i = 0; i < 2; i++) {
			scanf("%d%d%d%d", &W[i], &H[i], &sy[i], &sx[i]); sy[i]--, sx[i]--;
			for (int j = 0; j < H[i]; j++) {
				for (int k = 0; k < W[i]; k++) {
					reader(&a[i][j][k]);
				}
			}
			priority_queue<state> que; que.push(state{ sx[i], sy[i], -1 });
			memset(vis, 0, sizeof(vis));
			vis[sx[i]][sy[i] >> 5] |= 1 << (sy[i] & 31); cnt[i] = 1;
			while (!que.empty()) {
				state u = que.top(); que.pop();
				b[i][cnt[i]++] = a[i][u.sx][u.sy];
				if (cnt[i] > R) break;
				for (int j = 0; j < 4; j++) {
					int tx = u.sx + dir[j], ty = u.sy + dir[j ^ 1];
					if (0 <= tx && tx < H[i] && 0 <= ty && ty < W[i] && !(vis[tx][ty >> 5] & (1 << (ty & 31)))) {
						a[i][tx][ty] = max(a[i][tx][ty], a[i][u.sx][u.sy]);
						vis[tx][ty >> 5] |= 1 << (ty & 31);
						que.push(state{ tx, ty, -a[i][tx][ty] });
					}
				}
			}
		}
		int ret = 2000000009;
		for (int i = 0; i <= R && i <= H[0] * W[0]; i++) {
			int z = max(R - i, 0);
			if (z > H[1] * W[1]) continue;
			ret = min(ret, b[0][i] + b[1][z]);
		}
		printf("%d\n", ret);
	}
	return 0;
}

Measured memory_bytes: 5640
N, M = map(int, input().split())
Ss = [tuple(map(int, input().split())) for i in range(N)]
CPs = [tuple(map(int, input().split())) for i in range(M)]

for a, b in Ss:
    dist = [abs(a - c) + abs(b - d) for c, d in CPs]
    print(dist.index(min(dist)) + 1)


Measured memory_bytes: 3060
import java.io.*;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;
public class Main {
	static String a;
	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		int n = stdIn.nextInt();
		int[] list = new int[n];
		int maxAns = Integer.MIN_VALUE;
		
		list[0] = stdIn.nextInt();
		int min = list[0];
		int max = -2000000000;
		for(int i = 1; i < n; i++) {
			list[i] = stdIn.nextInt();
			max = list[i];
			if(maxAns < max - min) {
				maxAns = max - min;
			}
			if(min > list[i]) {
				min = list[i];
			}
			
			
		}
		
		
		System.out.println(maxAns);
	}
}

Measured memory_bytes: 96556
m=int(input())
n=list(map(int,input().split()))
cnt=0
flag=1
while flag:
  flag=0
  for j in range(m-1,0,-1):
    if n[j]<n[j-1]:
      n[j],n[j-1]=n[j-1],n[j]
      cnt+=1
      flag=1

print(' '.join(map(str, n)))
print(cnt)


Measured memory_bytes: 5600
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string s;
  cin >> s;
  
  int ans = 0;
  for (int i = 0; i < 8; i++) {
    bool flag = true;
    int count = 0;
    
    for (int j = i; j < 10; j++) {
      if (flag) {
        if (s[j]=='A'||s[j]=='C'||s[j]=='G'||s[j]=='T') {
          flag = false;
          count ++;
        }
      }
      else {
        if (s[j]=='A'||s[j]=='C'||s[j]=='G'||s[j]=='T')
          count ++;
        else
          break;
      }
    }
    
    if (count > ans)
      ans = count;
  }
  cout << ans << endl;
}

Measured memory_bytes: 3596
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define countof(array) (sizeof(array) / sizeof(array[0]))
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,n,s) for(int i = s; i < (n); ++i)
#define rsrep(i,n,s) for(int i = (n)-1; i >= s; --i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define aall(a) (a), (a)+countof(a)//for array sorting
#define raall(a) (a), (a)+countof(a), greater<>()
#define show(x) cout<<#x<<" = "<<x<<endl;
#define vfind(v, a) find(all(v), a) != v.end()
#define yn(f) { if (f) puts("YES"); else puts("NO"); }
#define yns(f) { if (f) puts("Yes"); else puts("No"); }
#define show_ary(...) { cout<<#__VA_ARGS__<<" = "; for (const auto& x : (__VA_ARGS__)) { cout<<x<<" "; } cout<<endl; }
#define show_pair(...) cout<<#__VA_ARGS__<<" = "<<endl; for (const auto& x : (__VA_ARGS__)) { cout<<"  "<<x.fi<<" : "<<x.se<<endl; }
#define out_ary(...) { for (const auto& x : (__VA_ARGS__)) { cout<<x<<" "; } cout<<endl; }
#define argmax(v) distance((v).begin(), max_element(all(v)))
#define argmin(v) distance((v).begin(), min_element(all(v)))
#define vmax(v) *max_element(all(v))
#define vmin(v) *min_element(all(v))
typedef long long int ll;
typedef pair<int, int> P;
typedef vector<P> vpair;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<double> vdouble;
typedef vector<string> vstr;
typedef vector<bool> vbool;
typedef vector<vint> vvint;
typedef vector<vll> vvll;
typedef vector<vstr> vvstr;
typedef vector<vbool> vvbool;
const ll LINF = 2000000000000000000ll;
const int INF = 1000000100;
const ll MOD = 1e9+7;

int main() {
    int h, w;
    cin >> h >> w;
    map<char, int> mp;
    rep(i, h) rep(j, w) {
        char a;
        cin >> a;
        mp[a]++;
    }
    vint rm;
    int sum = 0;
    for (auto x : mp) {
        if (x.se%4 != 0) {
            rm.push_back(x.se%4);
            sum += x.se%4;
        }
    }
    if (h%2 == 0 && w%2 == 0) {
        if (rm.size() == 0) puts("Yes");
        else puts("No");
    }
    else if (h%2 == 1 && w%2 == 1) {
        int odd = 0;
        for (int r : rm) if (r%2 == 1) odd++;
        if (odd == 1 && sum <= h+w-1) puts("Yes");
        else puts("No");
    }
    else if (h%2 == 1) {
        int odd = 0;
        for (int r : rm) if (r%2 == 1) odd++;
        if (odd == 0 && sum <= w) puts("Yes");
        else puts("No");
    }
    else {
        int odd = 0;
        for (int r : rm) if (r%2 == 1) odd++;
        if (odd == 0 && sum <= h) puts("Yes");
        else puts("No");
    }
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cstring>
using namespace std;
int main(){
	string A,B;
	cin>> A;
	cin>> B;
	if (A.size() > B.size()){
		cout<< "GREATER" <<endl;
		return 0;
	} else if (B.size() > A.size()){
		cout<< 	"LESS" <<endl;
		return 0;
	} else{
		long long i = 0;
		while (A[i] != '\0' && B[i] != '\0'){
			if (A[i] > B[i]){
				cout<< "GREATER" <<endl;
				return 0;
			} else if (A[i] < B[i]){
				cout<< "LESS" <<endl;
				return 0;
			}
			i++;
		}
		if (i == A.size())
			cout<< "EQUAL" <<endl;
	}
	return 0;	
}

Measured memory_bytes: 256
class UnionFind
    def initialize(n)
        @par = Array.new(n)
        n.times{ |i| @par[i] = i }
        @rank = Array.new(n, 0)
    end

    def find(x)
        if @par[x] == x
            x
        else
            @par[x] = find(@par[x])
        end
    end

    def unite(x,y)
        x = find(x)
        y = find(y)
        return if x == y

        if @rank[x] < @rank[y]
            @par[x] = y
        else
            @par[y] = x
            @rank[x] += 1 if @rank[x] == @rank[y]
        end
    end

    def same?(x, y)
        find(x) == find(y)
    end
end

# edge = [src, dst, cost]
def kruskal(n, edges)
    edges = edges.sort_by{|edge| edge[2]}
    uf = UnionFind.new(n)
    res = 0
    edges.each do |edge|
        u = edge[0]
        v = edge[1]
        unless uf.same?(u, v)
            uf.unite(u, v)
            res += edge[2]
        end
    end
    return res
end


N = gets.to_i
xys = []
N.times do |i|
    xys[i] = [i] + gets.split.map(&:to_i)
end

xsort = xys.sort_by{|arr| arr[1]}
ysort = xys.sort_by{|arr| arr[2]}

edges = []
(N-1).times do |i|
    m, n = xsort[i][0], xsort[i+1][0]
    dist = [(xys[m][1]-xys[n][1]).abs, (xys[m][2]-xys[n][2]).abs].min
    edges.push([m, n, dist])
    m, n = ysort[i][0], ysort[i+1][0]
    dist = [(xys[m][1]-xys[n][1]).abs, (xys[m][2]-xys[n][2]).abs].min
    edges.push([m, n, dist])
end

puts kruskal(N, edges)

Measured memory_bytes: 33616
#include<bits/stdc++.h>
using namespace std;
int main(){
    long h,n;
    cin >> h >> n;
    long a[n];
    long summ = 0;
    for(int i=0;i<n;i++){
        cin >> a[i];
        summ += a[i];
    }
    if( h <= summ)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;

}

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

using namespace std;

typedef long long ll;

const ll MOD = 1000000007;
const ll INF = 1LL<<60;
//int INF = numeric_limits<int>::max();

int main(int, char**) {
	int c11, c12, c13, c21, c22, c23, c31, c32, c33;
	cin >> c11 >> c12 >> c13 >> c21 >> c22 >> c23 >> c31 >> c32 >>c33;
	int a1, a2, a3;
	a1 = c11 + c22 + c33;
	a2 = c21 + c32 + c13;
	a3 = c31 + c12 + c23;
	string ret = "No";
	if (a1==a2 && a2==a3) ret = "Yes";
	cout << ret << endl;
	return 0;
}

Measured memory_bytes: 3616
#include <cstdio>

int main(){
    int a, b;
    scanf("%d %d", &a, &b);

    int hoge, hoge1;
    hoge = (a+b)/2;
    hoge1 = (a+b)%2;

    printf("%d\n", (hoge+hoge1));

    return 0;
}


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

int main() {
	int a, b, c, d, ta, ao;
	cin >> a >> b >> c >> d;
	if (c % b != 0)ta = c / b + 1;
	else ta = c / b;
	if (a % d != 0)ao = a / d + 1;
	else ao = a / d;

	if (ta > ao || ta > (ao+1))cout << "No";
	else cout << "Yes";
}

Measured memory_bytes: 3624
#include<stdio.h>

int main(void) {
  char a;
  scanf("%c", &a);
  if (a >= 'a' && a <= 'z') {
    printf("a\n");
  }
  else if (a >= 'A' && a <= 'Z') {
    printf("A\n");
  }
  return 0;
}


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

int main() {

  string s;

  char c;

  string word;

  vector<string> ans;

  getline( cin, s );

  for ( int i = 0; i < s.size(); i++ ) {

    c = s[i];
    if ( c == ' ' || c == '.' || c == ',' ) {

      if ( word.size() >= 3 && word.size() <= 6 ) {
	ans.push_back( word );
      }
      word = "";

    }else {

      word += c;

    }

  }

  if ( word.size() >= 3 && word.size() <= 6 ) {
      ans.push_back( word );
  }

  for ( int i = 0; i < ans.size(); i++ ) {

    if ( i != 0 ) cout << " ";
    cout << ans[i];

  }

  cout << endl;

  return 0;

}

Measured memory_bytes: 1184
#include <stdio.h>
#include <cmath>
#include <bits/stdc++.h>



using namespace std;

typedef vector<int> VI;
typedef vector<string> VS;


//container util
#define SORT(c) sort((c).begin(),(c).end())

//repetition
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)



int main(void){

	int x, y; cin >> x >> y;
	int group[12] = {1,3,1,2,1,2,1,1,2,1,2,1};

	if(group[--x] == group[--y]) cout << "Yes" << endl;
	else cout << "No" << endl;


	return 0;

}


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

int main(){
    int a, b, c, x, y;
    cin >> a >> b >> c >> x >> y;
    int ans1, ans2, ans3;
    ans1 = min(x, y) * c * 2;
    if (x < y) {
        ans1 += (y - x) * b;
    } else {
        ans1 += (x - y) * a;
    }
    ans2 = x * a + y * b;
    ans3 = max(x, y) * c * 2;
    cout << min(ans1, min(ans2, ans3)) << endl;
    return 0;
}

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

int main()
{
	int num[100][100];
	
	int H, W;
	scanf("%d %d", &H, &W);
	
	for (int i = 0; i < H; i++){
		for (int j = 0; j < W; j++){
			scanf(" %c", &num[i][j]);
			num[i][j] -= '0';
		}
	}
	
	for (int i = H - 1; i >= 0; i--){
		for (int j = W - 1; j >= 0; j--){
			if (i < H - 1 && j < W - 1){
				num[i][j] += min(num[i + 1][j], num[i][j + 1]);
			}
			else if (i == H - 1){
				num[i][j] += num[i][j + 1];
			}
			else if (j == W - 1){
				num[i][j] += num[i + 1][j];
			}
		}
	}
/*	
	for (int i = 0; i < H; i++){
		for (int j = 0; j < W; j++){
			printf("%3d", num[i][j]);
		}
		puts("");
	}
*/	
	printf("%d\n", num[0][0]);
	
	return 0;
}

Measured memory_bytes: 1052