akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <assert.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define PB push_back
#define MP make_pair
#define MOD 1000000007LL
#define endl "\n"
const ll UNDEF = -1;
const ll INF=1e18;
template<typename T> inline bool chkmax(T &aa, T bb) { return aa < bb ? aa = bb, true : false; }
template<typename T> inline bool chkmin(T &aa, T bb) { return aa > bb ? aa = bb, true : false; }
typedef pair<ll,ll> pll;

#ifdef DEBUG
     #define debug(args...)            {dbg,args; cerr<<endl;}
#else
    #define debug(args...)              // Just strip off all debug tokens
#endif

struct debugger
{
    template<typename T> debugger& operator , (const T& v)
    {    
        cerr<<v<<" ";    
        return *this;    
    }
} dbg;
const ll mn=1e5+4;
ll a[mn];
bool used[mn];
int main()
{
	ios_base::sync_with_stdio(false); cin.tie(0);
	ll n; scanf("%lld",&n);
	for (ll i=0;i<n;i++) scanf("%lld",a+i);
	//sort(a,a+n, greater<ll>());
	ll all=0;
	for (ll i=0;i<n;i++) all^=a[i];
	ll ans=0;
	memset(used,0,sizeof used);
	for (ll b=31;b>=0;b--) {
		ll bm=1LL<<b;
		ll msk=(1LL<<(b+1))-1;
		if (0==(all&bm)) continue;
		bool found=false;
		for (ll i=0;i<n;i++) {
			if (used[i]) continue;
			if ((msk&a[i])==bm) {
				all^=a[i];
				a[i]--;
				all^=a[i];
				found=true;
				ans++;
				used[i]=true;
				break;
			}
		}
		if (!found) {
			printf("-1\n");
			return 0;
		}
	}
	printf("%lld\n",ans);
}



Measured memory_bytes: 1152
temp = gets.split.map(&:to_i)
points = [temp[0], temp[1]], [temp[2], temp[3]]

# 3点目を求める
move_x = points[1][0] - points[0][0] # x座標での移動量
move_y = points[1][1] - points[0][1] # y座標での移動量
points << [points[1][0] - move_y, points[1][1] + move_x]

# 4点目を求める
points << [points[0][0] - move_y, points[0][1] + move_x]

puts "#{points[2].join(' ')} #{points[3].join(' ')}"


Measured memory_bytes: 1788
a = [int(input()) for _ in range(int(input()))]

dp = [[0] * 5 for _ in range(len(a) + 1)]

for i, x in enumerate(a):
    m = x % 2
    y = m + (not x) * 2
    z = 1 - m
    
    dp[i+1][0] = dp[i][0] + x
    dp[i+1][1] = min(dp[i][:2]) + y
    dp[i+1][2] = min(dp[i][:3]) + z
    dp[i+1][3] = min(dp[i][:4]) + y
    dp[i+1][4] = min(dp[i]) + x

print(min(dp[-1]))

Measured memory_bytes: 67736
#include "bits/stdc++.h"
using namespace std;
#define FOR(i,j,k) for(int (i)=(j);(i)<(int)(k);++(i))
#define rep(i,j) FOR(i,0,j)
#define each(x,y) for(auto &(x):(y))
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define debug(x) cout<<#x<<": "<<(x)<<endl
#define smax(x,y) (x)=max((x),(y))
#define smin(x,y) (x)=min((x),(y))
#define MEM(x,y) memset((x),(y),sizeof (x))
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;

int main(){
    int N;
    cin >> N;
    vi L(2*N);
    rep(i, 2*N)cin >> L[i];
    sort(all(L),greater<int>());
    ll ans = 0;
    for(int i = 1; i < 2 * N; i += 2){
        ans += L[i];
    }
    cout << ans << endl;
}

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

int main() {
  string s, t;
  int minNum;
  ll d;
  cin >> s >> t >> d;
  vector<int> ans(s.length());
  rep(i,s.length() - t.length() + 1) {
    ans[i] = 0;
    rep(l,t.length()) {
      if (s[i + l] != t[l]) {
        ans[i]++;
      }
  	}
    if (i == 0) {
      minNum = ans[i];
    }
    minNum = min(minNum, ans[i]);
  }
  cout << minNum << endl;
  return 0;
}


Measured memory_bytes: 3620
//package AtCoder;
import java.util.*;
public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc=new Scanner(System.in);
		Map<String,Integer> map=new HashMap<>();
		int n=sc.nextInt();
		int max=1;
		for(int i=0;i<n;i++)
		{
			String s=sc.next();
			if(map.containsKey(s))
			{
				int val=map.get(s)+1;
				if(val>max)
					max=val;
				map.put(s,val);
			}
			else
			{
				map.put(s, 1);
			}
		}
		Set<String> set=new TreeSet<>();
		for(Map.Entry<String, Integer> entry:map.entrySet())
		{
			if(entry.getValue()==max)
				set.add(entry.getKey());
		}
		List<String> list=new ArrayList<>(set);
		for(String str:list)
		{
			System.out.println(str);
		}

	}

}


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

#define ll long long
#define f(i, a, b) for(ll i=a;i<b;i++)
#define fi(i, a, b) for(ll i=b-1;i>=a;i--)
#define pb push_back
#define vi vector<int>
#define vl vector<ll>
#define ml map<ll,ll>
#define pll pair<ll,ll>


int main()
{
  int a,b;
  cin>>a>>b;
  cout<<(a*b);
 }


Measured memory_bytes: 3620
import java.util.*;

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 = sc.nextInt();
        int d = sc.nextInt();
        if(a * b < c *d){
            System.out.println(c * d);
            return;
        }
        System.out.println(a * b);
    }
}


Measured memory_bytes: 22612
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)

using namespace std;

using ll = long long;
const int INF = 1001001001;
const ll LLINF = 1001001001001001001;

typedef struct tagNode_t {
  ll cost; // このノードへの現時点で判明している最短距離
  int from; // どこから来たのか
} Node_t;

int main()
{
        int n, m, R;
        cin >> n >> m >> R;
        vector<int> r(R);
        rep (i, R) cin >> r[i];
        sort(r.begin(), r.end());
        Node_t initNode = {.cost = INF, .from = 0};
        vector<vector<Node_t>> g(n+1, vector<Node_t>(n+1, initNode));

        // src dst edge cost の順で入力がある
        // 繋がっていないnodeについては初期値 INF が入っている
        rep (i, m) {
                int src, dst;
                ll cost;
                cin >> src >> dst >> cost;
                g[src][dst].cost = cost;
                g[dst][src].cost = cost;
        }

        for (int k = 1; k <= n; k++) { // 経由する頂点
                for (int i = 1; i <= n; i++) { // 始点
                        for (int j = 1; j <= n; j++) { // 終点
                          if (g[i][j].cost > g[i][k].cost + g[k][j].cost) {
                                  g[i][j].cost = g[i][k].cost + g[k][j].cost;
                                  g[i][j].from = k;
                          }
                        }
                }
        }

        ll res = LLINF;
        do {
                ll cost = 0;
                rep (i, R-1) {
                        cost += g[r[i]][r[i+1]].cost;
                }
                res = min(cost, res);
        } while (next_permutation(r.begin(), r.end()));

        cout << res << endl;
}


Measured memory_bytes: 4136
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    
    int n = sc.nextInt();
    String s = sc.next();

    char[] c = s.toCharArray();
    
    boolean ans = true;
    
    if(n % 2 == 1) {
      ans = false;
    } else {    

      for(int i = 0; i < n/2 ; i++) {
      if(c[i] != c[n/2+i]) {
        ans = false;
        break;
      }
    }
    }
    
    if(ans) {
      System.out.println("Yes");
    } else {
      System.out.println("No");
    }      
    
    
  }
}

Measured memory_bytes: 23636
#!/bin/bash
''':'
docker run --rm -it -v $(cd $(dirname $0) && pwd):/vo:ro pypy:3-2.4.0 \
   /bin/bash -c "pypy3 /vo/$(basename $0) < /vo/g.inp"
exit $?
'''
import sys


def _ia(): return [int(x) for x in sys.stdin.readline().strip().split()]


MOD = 10**9 + 7


def add(a, b):
    return (a+b) % MOD


def mul(a, b):
    return (a*b) % MOD


def pow(a, n):
    ret = 1
    an = a
    while n > 0:
        if n & 1 == 1:
            ret = (ret * an) % MOD
        an = (an * an) % MOD
        n >>= 1
    return ret


def div(a, b):
    if a % b == 0:
        return a//b
    return (a * pow(b, MOD-2)) % MOD


def comb(n, k):
    global fact, ifact
    if k == 0:
        return 1
    return mul(mul(fact[n], ifact[n-k]), ifact[k])


n, k = _ia()
k = min(n-1, k)

fact = [1] * (n+1)
ifact = [1] * (n+1)
for i in range(1, n+1):
    fact[i] = mul(i, fact[i-1])
    ifact[i] = div(ifact[i-1], i)

ret = 0
for i in range(k+1):
    ret = (ret + comb(n-1, i) * comb(n, i)) % MOD
print(ret)


Measured memory_bytes: 47268
log = console.log;
var stdin = require("fs").readFileSync("/dev/stdin", "UTF-8");
var lines = stdin.split("\n");
var N = lines[0].split(" ").map(Number)[0];
var X = lines[0].split(" ").map(Number)[1];
var Points = lines
  .slice(1)
  .filter(v => v !== "")
  .map(v => v.split(" ").map(Number));

Points = Points[0];

var D = 0;
var count = 0;
Points.forEach((v, i) => {
  D += v;
  if (D > X && count === 0) count = i + 1;
});
if (count === 0) {
  log(N + 1);
} else {
  log(count);
}


Measured memory_bytes: 21064
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
string s[100];
int n;
int main()
{
	scanf("%d%*d",&n);
	for(int i=0;i<n;i++)
	{
		cin>>s[i];
	}
	sort(s,s+n);
	for(int i=0;i<n;i++)
	{
		cout<<s[i];
	}
}

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

//#define int long long
typedef long long ll;

typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = mod * mod;
const int INF_N = 1e+9;
typedef pair<int, int> P;
// #define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
#define all(v) (v).begin(),(v).end()
typedef pair<ll, ll> LP;
typedef long double ld;
typedef pair<ld, ld> LDP;
const ld eps = 1e-12;
const ld pi = acos(-1.0);
//typedef vector<vector<ll>> mat;
typedef vector<int> vec;

//繰り返し二乗法
ll mod_pow(ll a, ll n, ll m) {
	ll res = 1;
	while (n) {
		if (n & 1)res = res * a%m;
		a = a * a%m; n >>= 1;
	}
	return res;
}

struct modint {
	ll n;
	modint() :n(0) { ; }
	modint(ll m) :n(m) {
		if (n >= mod)n %= mod;
		else if (n < 0)n = (n%mod + mod) % mod;
	}
	operator int() { return n; }
};
bool operator==(modint a, modint b) { return a.n == b.n; }
modint operator+=(modint &a, modint b) { a.n += b.n; if (a.n >= mod)a.n -= mod; return a; }
modint operator-=(modint &a, modint b) { a.n -= b.n; if (a.n < 0)a.n += mod; return a; }
modint operator*=(modint &a, modint b) { a.n = ((ll)a.n*b.n) % mod; return a; }
modint operator+(modint a, modint b) { return a += b; }
modint operator-(modint a, modint b) { return a -= b; }
modint operator*(modint a, modint b) { return a *= b; }
modint operator^(modint a, int n) {
	if (n == 0)return modint(1);
	modint res = (a*a) ^ (n / 2);
	if (n % 2)res = res * a;
	return res;
}

//逆元(Eucledean algorithm)
ll inv(ll a, ll p) {
	return (a == 1 ? 1 : (1 - p * inv(p%a, a)) / a + p);
}
modint operator/(modint a, modint b) { return a * modint(inv(b, mod)); }

const int max_n = 1 << 18;
modint fact[max_n], factinv[max_n];
void init_f() {
	fact[0] = modint(1);
	for (int i = 0; i < max_n - 1; i++) {
		fact[i + 1] = fact[i] * modint(i + 1);
	}
	factinv[max_n - 1] = modint(1) / fact[max_n - 1];
	for (int i = max_n - 2; i >= 0; i--) {
		factinv[i] = factinv[i + 1] * modint(i + 1);
	}
}
modint comb(int a, int b) {
	if (a < 0 || b < 0 || a < b)return 0;
	return fact[a] * factinv[b] * factinv[a - b];
}
using mP = pair<modint, modint>;

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




void solve() {
    int a, b; cin >> a >> b;
    int res = 1;
    int cnt = 0;
    while(res < b){
        res += a-1;
        cnt++;
    }
    cout << cnt << endl;
}

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  //cout << fixed << setprecision(10);
  //init_f();
  //init();
  //int t; cin >> t; rep(i, t)solve();
  solve();
//   stop
    return 0;
}


Measured memory_bytes: 7744
import sys
def input(): return sys.stdin.readline().strip()

def resolve():
    n,l=map(int, input().split())
    ll=list(range(l,l+n))
    moto=sum(ll)
    if ll[0]>0:
        print(moto-ll[0])
    elif ll[-1]<0:
        print(moto-ll[-1])
    else:
        print(moto)
resolve()

Measured memory_bytes: 3064
import bisect

n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))

a.sort()
c.sort()

sum = 0
for j in range(n):
  atemp = bisect.bisect_left(a, b[j])
  ctemp = n - bisect.bisect_right(c, b[j])
  sum += atemp * ctemp

print(sum)


Measured memory_bytes: 105572
#include<bits/stdc++.h>
using namespace std;
#define M ((ll)(1e9)+7)
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
typedef long long ll;

void solve()
{
   int h,a;
   cin>>h>>a;
   int ans=0;
   while(h>0)
   {
       h-=a;
       ans++;
   }
   cout<<ans<<endl;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    solve();
    return 0;
}

Measured memory_bytes: 256
n,m=map(int,input().split())
l = [list(map(int,input().split())) for _ in range(m)]


for i in range(10**(n)):
    x=str(i)
    tf=True
    if len(x)==n:
        for j in range(m):
            if str(l[j][1])!=x[int(l[j][0])-1]:
                tf=False
        if tf:
            print(x)
            exit()

print(-1)
        


Measured memory_bytes: 39408
#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define pb push_back
#define mp make_pair
#define ll long long int
#define vi vector<int>
#define vl vector<ll>
#define v2i vector<vector<int>>
#define v2l vector<vector<ll>>
#define ppi pair<int,int>
#define vpi vector<ppi>
#define ppl pair<ll,ll>
#define all(x) x.begin(),x.end()
#define ii int,int 
#define ff first    
#define ss second
#define forn(i,a,b) for(int i=a;i<b;i++)
#define forr(i,a,b) for(int i=a;i>=b;i--)
#define forv(i,m) for(auto i : m)
#define imx INT_MAX
#define imn INT_MIN
#define inf LONG_MAX
#define minf LONG_MIN
#define endl "\n"
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);
#define sze size()
#define rvs reverse 
#define itr iterator 
#define pre cout<<fixed<<setprecision(10);
#define umap unordered_map
#define uset unordered_set

/*
#define MODM(a,b,md) ((a%md)*(b%md))%md
#define MODA(a,b,md) ((a%md)+(b%md))%md
#define ull unsigned long long int
#define si short int
*/

/*
bool compare(int a,int b) {return a > b;}
bool compare1(ppi a,ppi b) {return a.ff > b.ff;}
bool compare2(ppi a,ppi b) {return a.ss < b.ss;}
ll Npower(ll a,ll b) {ll product = 1; while(b){if(b&1){product = product*a;}a = a*a;b = b>>1;} return product;}
ll power(ll a,ll b,ll md) {ll product = 1; while(b){if(b&1){product = MODM(product,a,md);}a = MODM(a,a,md);b = b>>1;} return product%md;}
ll GCD(ll a,ll b) {return b==0 ? a:GCD(b,a%b);}
ll LCM(ll a,ll b) {return (a/GCD(a,b))*b; }
*/

int main()
{
    fast


        
    int n;
    cin>>n;

    vi v(n);
    forn(i,0,n)
    {
        cin>>v[i];
    }

    vi c = v;

    sort(all(c));
    int count = 0;
    forn(i,0,n)
    {
        if(c[i] != v[i]) count++;
    }

    if(count == 2 || count == 0) cout<<"YES";
    else cout<<"NO";





    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
bool is_p(unsigned long long int p){
  if(p%2==0) return(false);
  for(unsigned long long int i=3;i*i<=p;i+=2) if(p%i==0) return(false);
  return(true);
}
int main(){
  unsigned long long int n,m,ans=1;
  cin>>n>>m;
  for(unsigned long long int i=1;i*i<=m;i++){
    if(m%i==0){
      unsigned long long int j=m/i;
      if(i>=n) ans=max(ans,j);
      if(j>=n) ans=max(ans,i);
    }
  }
  
  cout<<ans;
}

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

typedef long long ll;
const ll MOD = 1e9 + 7;
const long long INF = 1LL<<60;
const double PI=3.14159265358979323846;
const int NMAX=100005;
using namespace std;


int main(){
    int n,k;
    cin >> n >> k;
    vector<ll> a(n);
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }

    for(int j = 0; j < k; j++){
        ll ad[n], sb[n];
        for(int i = 0; i < n; i++){
            ad[i] = 0;
            sb[i] = 0;
        }
        for(int i = 0; i < n; i++){
            int left = i-a[i];
            int right = i+a[i];
            if(left > 0){
                if(left >= n){
                    ad[n-1]++;
                } else {
                    ad[left]++;
                }
            } else {
                ad[0]++;
            }
            if(right < n){
                sb[right]++;
            }
        }
            
        a[0] = ad[0];
        bool flag = true;
        for(int i = 1; i < n; i++){
            a[i] = a[i-1]+ad[i]-sb[i-1];
            if(a[i] != n) flag = false;
        }
        if(flag == true) break;
    }
    
    cout << a[0];
    for(int i = 1; i < n; i++){
        cout << " " << a[i];
    }
    cout << endl;

    return 0;
}

Measured memory_bytes: 7920
N = gets.chomp
keta = N.length
count = 0
for i in (3..keta) do
    ary = [3, 5, 7].repeated_permutation(i).to_a
    ary.each do |a|
        if a.include?(3) && a.include?(5) && a.include?(7) && a.join.to_i <= N.to_i
            count += 1   
        end  
    end
end

puts count 

Measured memory_bytes: 7168
N = int(input())
l = list(map(int,input().split()))
num = 0
while(True):
  odd_flag = False
  for i in l:
    if (i % 2 !=0):#奇数があったらフラグ
      odd_flag = True
  if(odd_flag):
    break
  for i in range(len(l)):
    l[i] = l[i] // 2
  num +=1
    
print(num)
  

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,n) for(long long i=0;i<n;++i)
#define REPP(i,m,n) for(long long i=m;i<n;++i)
#define rep(i,n) for(long long i = n-1;i>=0;--i)
#define repp(i,n,m) for(long long i = n-1; i >= m; --i)
#define ALL(N) (N.begin(),N.end())
#define de cout << "line : " << __LINE__ << " debug" << endl;
#define pb push_back
#define pq priority_queue
#define Dcout(N) cout << setprecision(20) << N << endl
constexpr int MOD = 1000000007;
constexpr int INF = 2147483647;
constexpr long long INFF = 9223372036854775807;

signed main() {
    cin.tie(0);
	ios::sync_with_stdio(false);
    int N;cin >> N;
    while(N--){
        int t,x,y;cin >> t >> x >> y;
        if(t % 2 == 0 && (x+y) % 2 == 0){
            if(t >= x+y) continue;
        }
        if(t % 2 == 1 && (x+y) % 2 == 1){
            if(t >= x+y) continue;
        }
        cout << "No" << endl;
        return 0;
    }
    cout << "Yes" << endl;
}

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

using namespace std;

typedef long long int64;
typedef vector<int,int> vec;
#define read(a) scanf("%d",&a)
#define printarr(a,n) for(int i=0;i<n;i++) cout<<a[i]<<" ";

const int rmax = 1e5 + 10;
const int inf = INT_MAX;

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

    mnn = a;

    if(b < a)
        mnn--;

    cout<<mnn<<endl;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n;
int a[100010],f[100010];
int main()
{
	memset(f,0x3f,sizeof(f));
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);
	}
	f[1]=0;
	f[2]=abs(a[1]-a[2]);
	for(int i=3;i<=n;i++)
	{
		f[i]=min(abs(a[i]-a[i-1])+f[i-1],abs(a[i]-a[i-2])+f[i-2]);
	}
	printf("%d",f[n]);
	return 0;
}


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

int main() {
	string S;
	cin >> S;

	bool result = false;

	if( S.at( 0 ) == S.at( 1 ) && S.at( 2 ) == S.at( 3 ) && S.at( 0 ) != S.at( 2 ) ) {
		result = true;
	}
	else if( S.at( 0 ) == S.at( 2 ) && S.at( 1 ) == S.at( 3 ) && S.at( 0 ) != S.at( 1 ) ) {
		result = true;
	}
	else if( S.at( 0 ) == S.at( 3 ) && S.at( 1 ) == S.at( 2 ) && S.at( 0 ) != S.at( 1 ) ) {
		result = true;
	}

	cout << (result ? "Yes" : "No") << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int A[100005], B[100005];
pair<int, int> P[100005];
int main(){
	int N; scanf("%d",&N);
	for(int i=0; i<N; ++i) scanf("%d%d",A+i, B+i), P[i] = {A[i]+B[i], i};
	sort(P, P+N);
	reverse(P, P+N);
	long long ans = 0;
	for(int i=0; i<N; ++i){
		if(i&1) ans -= B[P[i].second];
		else ans += A[P[i].second];
	}
	printf("%lld\n",ans);
	return 0;
}

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

int main(){
  int n; cin >> n;
  string s; cin >> s;
  int l = 0, r = 0;
  int lcnt = 0, rcnt = 0;
  for(int i = 0; i < n-1; i++){
    if(s[i] == '(') lcnt++;
    if(s[i] == ')') rcnt++;
    if(s[i] != s[i+1]){
      if(lcnt > rcnt){
        continue;
      }
      if(lcnt < rcnt){
        l += rcnt - lcnt;
        lcnt = 0;
        rcnt = 0;
      }
    }
  }
  if(s[n-1] == '(') lcnt++;
  else{
    rcnt++;
    l += max(0, rcnt - lcnt);
  }
  r = max(lcnt - rcnt, 0);
  for(int i = 0; i < l; i++) cout << '(';
  cout << s;
  for(int i=  0; i < r; i++) cout << ')';
}

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

int main(){
    using namespace std;
    constexpr unsigned long C = 26;
    unsigned long D;
    cin >> D;
    vector<unsigned long> c(C);
    for(auto&& i : c)cin >> i;
    vector v(D, vector<unsigned long>(C));
    for(auto&& i : v)for(auto&& j : i)cin >> j;

    vector last(C, vector<unsigned long>{0});
    vector<unsigned long> ans(D);

    for(unsigned long i{0}; i < D; ++i){
        unsigned long mx{0}, mxi{0};
        for(unsigned long j{0}; j < C; ++j){
            unsigned long tmp{v[i][j] + c[j] * (i + 1 - last[j].back())};
            if(tmp > mx){
                mx = tmp;
                mxi = j;
            }
        }
        ans[i] = mxi;
        last[mxi].push_back(i + 1);
    }
    for(auto&& i : last)i.push_back(D + 1);

    mt19937_64 mt{random_device{}()};
    uniform_int_distribution<unsigned long> uid(1, D);

    for(unsigned long iter{0}; iter < 100; ++iter){
        unsigned long d{uid(mt)};
        auto f = ans[d - 1];
        unsigned long tmp{c[f] * (*upper_bound(begin(last[f]), end(last[f]), d) - d) * (d - *prev(lower_bound(begin(last[f]), end(last[f]), d))) + v[d - 1][f]};
        unsigned long mx{tmp}, mxi{0};
        for(unsigned long i{0}; i < C; ++i){
            unsigned long temp{c[i] * (*upper_bound(begin(last[i]), end(last[i]), d) - d) * (d - *prev(lower_bound(begin(last[i]), end(last[i]), d))) + v[d - 1][i]};
            if(temp > mx){
                mx = temp;
                mxi = i;
            }
        }
        if(mx > tmp){
            last[f].erase(lower_bound(begin(last[f]), end(last[f]), d));
            last[mxi].insert(upper_bound(begin(last[mxi]), end(last[mxi]), d), d);
            ans[d - 1] = mxi;
        }
    }

    for(const auto& i : ans)cout << i + 1 << endl;

    return 0;
}

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

typedef long long ll;
typedef int64_t i6;
typedef std::vector<std::vector<int64_t> > Graph;

#define rep(i, n) for (int64_t i = 0; i < n; ++i)
#define rep2(i, n) for (int64_t i = 1; i <= n; ++i)
#define repb(i, l, n) for (int64_t i = l; i < n; ++i)
#define repb2(i, l, n) for (int64_t i = l; i <= n; ++i)
#define ALL(v) (v).begin(), (v).end()
#define Sort(x) sort(ALL(x))
#define Sort_rev(x) Sort(x);reverse(ALL(x))
#define Push_back(p, a, b) (p).push_back( make_pair( (a), (b) ) )

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 V,typename T> bool find_num(V v, T num) { if ( find(ALL(v), num) == v.end() ) { return false; } return true; }

int main() {
    int64_t n;
    cin >> n;
    std::vector<int64_t> a(n);
    rep(i, n) {
        cin >> a[i];
    }

    int64_t ans = 0;
    repb(i, 1, n) {
        if ( a[i] < a[i-1] ) {
            ans += a[i-1] - a[i];
            a[i] = a[i-1];
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 4696
# -*- coding: utf-8 -*-

"""
参考：https://img.atcoder.jp/arc065/editorial.pdf
・Union-Find木
"""

import sys
def input(): return sys.stdin.readline().strip()
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

from collections import Counter

# Union-Find木
class UnionFind:
    def __init__(self, n):
        # 親要素のノード番号を格納。par[x] == xの時そのノードは根
        # 1-indexedのままでOK、その場合は[0]は未使用
        self.par = [i for i in range(n+1)]
        # 木の高さを格納する（初期状態では0）
        self.rank = [0] * (n+1)

    # 検索
    def find(self, x):
        # 根ならその番号を返す
        if self.par[x] == x:
            return x
        else:
            # 走査していく過程で親を書き換える
            self.par[x] = self.find(self.par[x])
            return self.par[x]

    # 併合
    def union(self, x, y):
        # 根を探す
        x = self.find(x)
        y = self.find(y)
        # 木の高さを比較し、低いほうから高いほうに辺を張る
        if self.rank[x] < self.rank[y]:
            self.par[x] = y
        else:
            self.par[y] = x
            # 木の高さが同じなら片方を1増やす
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1

    # 同じ集合に属するか判定
    def same(self, x, y):
        return self.find(x) == self.find(y)

N, K, L = map(int, input().split())
uf1 = UnionFind(N)
uf2 = UnionFind(N)
for i in range(K):
    p, q = map(int, input().split())
    uf1.union(p, q)
for i in range(L):
    p, q = map(int, input().split())
    uf2.union(p, q)

# (道路グループ番号, 鉄道グループ番号) のペアを各都市について作る
pairs = [None] * N
for i in range(N):
    pairs[i] = (uf1.find(i+1), uf2.find(i+1))

# 同じ内容のペアについて数える
c = Counter(pairs)

ans = [0] * N
for i in range(N):
    # 自分のペアのカウント数を各都市について取得
    ans[i] = c[pairs[i]]
print(*ans)


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

int main() {
    string S; cin >> S;
    int Q; cin >> Q;
    vector<string> T(2, "");
    int d = 0;
    while(Q--) {
        int t; cin >> t;
        if(t == 1) { // 反転
            d ^= 1;
        } else {
            int f; cin >> f;
            char c; cin >> c;
            if(f == 1) { // 先頭
                T[d^1] += c;
            } else { // 末尾
                T[d] += c;
            }
        }
    }
    if(d) {
        reverse(S.begin(), S.end());
        reverse(T[0].begin(), T[0].end());
        cout << T[0] << S << T[1] << '\n';
    } else {
        reverse(T[1].begin(), T[1].end());
        cout << T[1] << S << T[0] << '\n';
    }
    return 0;
}


Measured memory_bytes: 1088
//prepared by dumb
#include<bits/stdc++.h>
using namespace std;
#define   ll  long long int
#define   dl double
#define   llu unsigned long long int
#define   scll(x) scanf("%lld",&x)
#define   scld(x) scanf("%lf",&x)
#define   scull(x) scanf("%llu",&x)
#define   scch(x) scanf(" %c",&x)
#define   pb(x) push_back(x)
#define   pf(x) push_front(x)
#define   ppb() pop_back()
#define   ppf() pop_front()
#define   Pi acos(-1.0)
#define   inf 1000000000000000000
#define   mod 1000000007
#define   ff first
#define   ss second
#define   mpr make_pair
#define   debug(x) cout<<x<<'\n';
#define   eps 1e-8
// Creates a min heap
//priority_queue <int, vector<int>, greater<int> > pq;
//sin((x*pi)/180.0)[x in degree]
//sin(x)[x in radian]
//asin(x)[radian]
//(asin(x)*180)/pi[degree]
//or(|)//and(&)//xor(^)//not(~)
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
ll lcm(ll a, ll b)
{
    return (a * b) / __gcd(a, b);
}
int main()
{
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    ll a, b, c=0, e, f = 0, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, z;
    ll cnt = 0, ans = 0, l1, l2, l3, c1 = 0, c2 = 0, c3 = 0, mx = 0, mn = 0;
    ll prevsum = 0, ans1 = 0, ans2 = 0, odd = 0, even = 0, hh, mm,d,x,y;
    string str, str1, str2,str3="",str4="";
    scll(n);
    scll(d);
    for(i=0;i<n;i++)
    {
    	scll(x);
    	scll(y);
    	if((x*x+y*y)<=d*d)
    		c++;
    }
  cout<<c;

return 0;
}

Measured memory_bytes: 3688
import java.util.Scanner;



class Main {

	public static void main(String[] args) {
      	// loading data
        Scanner scan = new Scanner(System.in);
        String A = scan.next();
        String B = scan.next();
        scan.close();
      
      	// processing
      	int a_num  = Integer.parseInt(A);
      	int b_num  = Integer.parseInt(B);
      	int ab_sum = a_num + b_num;

      	if(a_num<=8 && ab_sum <= 16 && b_num<=8){ 
          System.out.println("Yay!");
        }else{
          System.out.println(":(");
        }

 	}
  

}

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

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

    ll n, m, k;
    cin >> n >> m >> k;
    vector<ll> a(n+1, 0), b(m+1, 0);
    rep(i, n) cin >> a[i+1];
    rep(i, n) a[i+1] += a[i];
    rep(i, m) cin >> b[i+1];
    rep(i, m) b[i+1] += b[i];

    int b_cnt = m;
    int res = 0;
    rep(a_cnt, n+1){
        if(a[a_cnt]>k) break;
        while(a[a_cnt] + b[b_cnt] > k) --b_cnt;
        res = max(res, a_cnt+b_cnt);
    }

    cout << res << endl;

    return 0;
}

Measured memory_bytes: 6340
n, m = map(int, input().split())
score = [(False, 0) for i in range(n)]
for i in range(m):
	problem, s = input().split()
	p = int(problem)-1
	if not score[p][0]:
		score[p] = (True, score[p][1]) if s=="AC" else (False, score[p][1]+1)
	

print(sum(i[0] for i in score), sum(j if i else 0 for i, j in score))

Measured memory_bytes: 10200
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <numeric>
#include <string>
#include <utility>
#include <vector>

using namespace std;

int main(void){
    int N=0, num, card[4][13];
    string suit;
    // S:0 H:1 D:2 C:3
    for(int i=0; i<4; i++){
        for(int j=0; j<13; j++){
            card[i][j] = j+1;
        }
    }

    cin >> N;

    for(int i=0; i<N; i++){
        cin >> suit >> num;
        if(suit == "S")
            card[0][num-1] = 0;
        else if(suit == "H")
            card[1][num-1] = 0;
        else if(suit == "C")
            card[2][num-1] = 0;
        else
            card[3][num-1] = 0;
    }

    for(int i=0; i<4; i++){
        for(int j=0; j<13; j++){
            if(card[i][j] != 0){
                if(i == 0)
                    cout << "S " << j+1 << endl;
                else if(i == 1)
                    cout << "H " << j+1 << endl;
                else if(i == 2)
                    cout << "C " << j+1 << endl;
                else
                    cout << "D " << j+1 << endl;
            }
        }
    }
}


Measured memory_bytes: 3168
import sys
import math
import string
import fractions
import random
from operator import itemgetter
import itertools
from collections import deque
import copy
import heapq
import bisect

MOD = 10 ** 9 + 7
INF = float('inf')
input = lambda: sys.stdin.readline().strip()

sys.setrecursionlimit(10 ** 8)


class UnionFind:
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())


n, q = map(int, input().split())
uf = UnionFind(n)
for _ in range(q):
    com, x, y = map(int,input().split())
    if com == 0:
        uf.union(x, y)
    else:
        if uf.same(x, y):
            print(1)
        else:
            print(0)


Measured memory_bytes: 9828
#include<iostream>
#include<string>
#include<vector>
#include<utility>
#include<queue>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<complex>
#define INF 2147483647
#define llINF 9223372036854775807
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long

using namespace std;
int main(){
  int n;cin>>n;
  vector<pair<int,int> >rpi(n);
  vector<pair<int,int> >bpi(n);
  for(int i=0;i<n;i++)
    cin>>rpi[i].F>>rpi[i].S;
  for(int i=0;i<n;i++)
    cin>>bpi[i].F>>bpi[i].S;
  sort(rpi.begin(),rpi.end());
  sort(bpi.begin(),bpi.end());
  ll ans=0;
  for(int i=0;i<n;i++){
    int po=-1,ma=-1;
    for(int j=0;j<rpi.size();j++){
      if(bpi[i].F>rpi[j].F){
	if(bpi[i].S>rpi[j].S&&ma<rpi[j].S){
	  ma=rpi[j].S;
	  po=j;
	}
      }else
	break;
    }
    if(po!=-1){
      ans++;
      rpi.erase(rpi.begin()+po);
    }
  }
  cout<<ans<<endl;
  return 0;
}

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

using ll = long long;
using Vi = vector<int>;
using Vl = vector<ll>;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

constexpr int I_INF = numeric_limits<int>::max();
constexpr ll L_INF = numeric_limits<ll>::max();

//==================================

using Point = valarray<double>;

double distance(const Point& a, const Point& b) {
    Point d = a - b;
    return sqrt(d[0] * d[0] + d[1] * d[1]);
}

int main() {
#ifdef FASTIO
    cin.tie(0), cout.tie(0);
    ios::sync_with_stdio(false);
#endif
#ifdef FILEINPUT
    ifstream ifs("./in_out/input.txt");
    cin.rdbuf(ifs.rdbuf());
#endif

    ll N;
    cin >> N;
    vector<Point> ps(N, Point(2));
    for (ll i = 0; i < N; i++) {
        cin >> ps[i][0] >> ps[i][1];
    }

    double left = 0.0, right = 1e+4;
    Point c(2), t(2), p(2);
    vector<Point> can;
    for (ll _ = 0; _ < 100; _++) {
        double mid = (left + right) * 0.5;
        can.clear();
        for (ll i = 0; i < N; i++) {
            for (ll j = i + 1; j < N; j++) {
                c = (ps[i] + ps[j]) * 0.5;
                t = ps[i] - ps[j];
                t /= sqrt(t[0] * t[0] + t[1] * t[1]);  // 正規化
                // 90deg回転
                t[0] *= -1;
                swap(t[0], t[1]);

                // 交点を求める
                double d = distance(ps[i], ps[j]);
                double esq = mid * mid - d * d * 0.25;
                if (esq < 0) continue;
                double e = sqrt(esq);
                p = c + t * e;
                can.emplace_back(p);
                p = c - t * e;
                can.emplace_back(p);
            }
        }
        bool ok = false;
        for (const auto& p : can) {
            ok = true;
            for (ll i = 0; i < N; i++) {
                if (distance(p, ps[i]) > mid + 1e-9) {
                    ok = false;
                }
                if (!ok) break;
            }
            if (ok) break;
        }
        if (ok) {
            right = mid;
        }
        else {
            left = mid;
        }
    }

    cout << setprecision(20) << right << endl;

    return 0;
}

Measured memory_bytes: 384
#include<iostream>
#include<vector>
using namespace std;
int main()
{
    int m,n,c;
    cin>>n>>m>>c;
    vector<int> v;
    for(int i=1;i<=m;i++)
    {
        int a;
        cin>>a;
        v.push_back(a);
    }
    int cnt=0;
    for(int i=1;i<=n;i++)
    {
        vector<int> t;

        for(int j=1;j<=m;j++)
        {
            int b;
            cin>>b;
            t.push_back(b);
        }
        int sum=0;
        for(int k=0;k<m;k++)
        {
            sum=sum+(v[k]*t[k]);
        }
        sum=sum+c;
        if(sum>0)
        {
            cnt++;
        }
    }

    cout<<cnt<<endl;

}


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

#define ll long long int
#define pb push_back
#define fi first
#define se second
#define mp make_pair
#define mt make_tuple
#define all(A) A.begin(), A.end()
#define sz(A) (int)A.size()
typedef vector <int> vi;
typedef vector <ll> vl;
typedef pair <int, int> pii;
const ll mod = 1e9 + 7;
//const ll mod = 998244353;
const int inf = 1e9;
//const ll inf = 1e18;
const int N = 2e5;

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int s, w;
	cin >> s >> w;
	if (w >= s) cout << "unsafe\n";
	else cout << "safe\n";
 	return 0;
}

Measured memory_bytes: 3612
//Zombie Island
#include <iostream>
#include <vector>
#include <queue>
#include <climits>

using namespace std;

typedef long long ll;

static const int MAX = 100000;

int N, M, K, S, P, Q;

enum {
    SAFE,
    DENGEROUS,
    ZOMBIE
};

struct City {
    int state = SAFE;
    vector<int> adj;
};

City C[MAX + 1];
bool visited[MAX + 1];

void setState(int t) {
    queue<pair<int, int> > Queue;
    for(int i = 0; i < MAX + 1; i++) visited[i] = false;
    Queue.push(make_pair(t, 0));
    visited[t] = true;
    while(!Queue.empty()) {
        pair<int, int> p = Queue.front();
        Queue.pop();
        if(p.first != t && C[p.first].state == ZOMBIE) continue;
        if(C[p.first].state == SAFE) C[p.first].state = DENGEROUS;
        if(p.second == S) continue;
        for(auto i: C[p.first].adj) {
            if(!visited[i]) {
                Queue.push(make_pair(i, p.second + 1));
                visited[i] = true;
            }
        }
    }
}

ll dijkstra() {
    priority_queue<pair<ll, int>, vector<pair<ll, int> >, greater<pair<ll, int> > > PQ;
    ll d[MAX + 1];
    for(int i = 0; i < MAX + 1; i++) d[i] = LONG_LONG_MAX;
    PQ.push(make_pair(0, 1));
    d[1] = 0;
    while(!PQ.empty()) {
        pair<ll, int> p = PQ.top();
        PQ.pop();
        for(auto i: C[p.second].adj) {
            if(i == N) {
                if(d[i] > p.first) d[i] = p.first;
            } else if(C[i].state == SAFE) {
                if(d[i] > p.first + P) {
                    d[i] = p.first + P;
                    PQ.push(make_pair(p.first + P, i));
                }
            } else if(C[i].state == DENGEROUS){
                if(d[i] > p.first + Q) {
                    d[i] = p.first + Q;
                    PQ.push(make_pair(p.first + Q, i));
                }
            }
        }
    }
    return d[N];
}

int main() {
    cin >> N >> M >> K >> S >> P >> Q;

    int c;
    int zombie_city[K];
    for(int i = 0; i < K; i++) {
        cin >> c;
        zombie_city[i] = c;
        C[c].state = ZOMBIE;
    }
    int a, b;
    for(int i = 0; i < M; i++) {
        cin >> a >> b;
        C[a].adj.push_back(b);
        C[b].adj.push_back(a);
    }

    for(int i = 0; i < K; i++) {
        setState(zombie_city[i]);
    }

    cout << dijkstra() << endl;
}


Measured memory_bytes: 11320
c0 = gets.chomp.split(" ").map(&:to_i)
c1 = gets.chomp.split(" ").map(&:to_i)
c2 = gets.chomp.split(" ").map(&:to_i)

a01 = c1[0] - c0[0]
a02 = c2[0] - c0[0]

b01 = c0[1] - c0[0]
b02 = c0[2] - c0[0]

for a0 in 0..100 do
for b0 in 0..100 do
a1 = a0 + a01
a2 = a0 + a02
b1 = b0 + b01
b2 = b0 + b02
if
  c0[0] == a0 + b0 and
  c0[1] == a0 + b1 and
  c0[2] == a0 + b2 and
  c1[0] == a1 + b0 and
  c1[1] == a1 + b1 and
  c1[2] == a1 + b2 and
  c2[0] == a2 + b0 and
  c2[1] == a2 + b1 and
  c2[2] == a2 + b2 then
  puts "Yes"
  exit
end
end
end
puts "No"

Measured memory_bytes: 3836
from heapq import heappush, heappop
INF = 10 ** 10

direct = ((0, -1), (0, 1), (-1, 0), (1, 0))

def dist(fr, to, mp):
  que = []
  heappush(que, (0, fr))
  visited = [[False] * len(mp[0]) for _ in range(len(mp))]
  visited[fr[1]][fr[0]] = True
  while que:
    d, point = heappop(que)
    x, y = point
    for dx, dy in direct:
      nx, ny = x + dx, y + dy
      if (nx, ny) == to:
        return d + 1
      if not visited[ny][nx] and mp[ny][nx] != "x":
        visited[ny][nx] = True
        heappush(que, (d + 1, (nx, ny)))
  else:
    return -1

def my_hash(rest):
  ret = 0
  for i in rest:
    ret += 10 ** i
  return ret

def shortest(fr, rest, edges, dp):
  if rest == set():
    return 0
  h = my_hash(rest)
  if h in dp[fr]:
    return dp[fr][h]
  ret = INF
  for d, to in edges[fr]:
    if to in rest:
      score = d + shortest(to, rest - {to}, edges, dp)
      if score < ret:
        ret = score
  dp[fr][h] = ret
  return ret

def main():
  while True:
    w, h = map(int, input().split())
    if w == 0:
      break
    mp = ["x" + input() + "x" for _ in range(h)]
    mp.insert(0, "x" * (w + 2))
    mp.append("x" * (w + 2))
    
    stains = []
    for y in range(1, h + 1):
      for x in range(1, w + 1):
        if mp[y][x] == "*":
          stains.append((x, y))
        elif mp[y][x] == "o":
          start = len(stains)
          stains.append((x, y))
    
    stain_num = len(stains)
    edges = [[] for _ in range(stain_num)]
    miss_flag = False
    for i in range(stain_num):
      for j in range(i + 1, stain_num):
        fr = stains[i]
        to = stains[j]
        d = dist(fr, to, mp)
        if d == -1:
          miss_flag = True
        edges[i].append((d, j))
        edges[j].append((d, i))
    if miss_flag:
      print(-1)
      continue

    dp = [{} for _ in range(stain_num)]
    print(shortest(start, {i for i in range(stain_num) if i != start}, edges, dp))

main()


Measured memory_bytes: 5900
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int A,B,C,D;
    cin >> A >> B >> C >> D;
    if(A+B > C+D) cout << "Left" << endl;
    else if(A+B < C+D) cout << "Right" << endl;
    else cout << "Balanced" << endl;
}


Measured memory_bytes: 256
al = list(map(int, input()))
bl = list(map(int, input()))
if len(al) > len(bl):
  print('GREATER')
  quit()
elif len(al) < len(bl):
  print('LESS')
  quit()
for a, b in zip(al, bl):
  if a > b:
    print('GREATER')
    quit()
  elif a < b:
    print('LESS')
    quit()
else:
  print('EQUAL')

Measured memory_bytes: 3064
#include <cstdio>
#include <climits>
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <cmath>
#include <stack>
#include <algorithm>
#include <random>
#include <iomanip>
#include <map>
#include <queue>
#include <functional>
#include <numeric>
#include <chrono>
#include <cstdlib>
using ll = long long;
using namespace std;

const ll MOD = 1e9 + 7;
const double pi = acos(-1);
typedef pair<int, int> P;
#define REP(i, n) for (int(i) = 0; (i) < (n); ++(i))
#define repi(i, a, b) for (int i = int(a); i < int(b); ++i)
#define EPS 1e-4
#define OUTPUT(i) (cout << (ll)i << endl)
#define ALL(a) ((a).begin(), (a).end())

bool operator<(const pair<ll, ll> &a, const pair<ll, ll> &b)
{

    if (a.first == b.first)
        return a.second < b.second;

    return a.first < b.first;
}

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

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

    //cout << fixed << setprecision(15);

    int A, B, C, D, P;
    cin >> A >> B >> C >> D >> P;

    cout << min(A * P, B + max(0, P - C) * D) << endl;
    return 0;
}



Measured memory_bytes: 3172
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

/* 基本要素 */
typedef complex<double> Point;
typedef pair<Point, Point> Line;
typedef vector<Point> VP;
const double PI = acos(-1);
const double EPS = 1e-9; // 許容誤差^2
const double INF = 1e9;
#define X real()
#define Y imag()
#define LE(n,m) ((n) - (m) < EPS)
#define GE(n,m) (EPS > (m) - (n))
#define EQ(n,m) (abs((n)-(m)) < EPS)

// 点集合を含む最小の円の中心
Point minEnclosingCircle(const VP& ps) {
  Point c;
  double move = 0.5;
  rep(i,39) {  // 2^(-39-1) \approx 0.9e-12
    rep(t,100) {
      double max = 0;
      int k = 0;
      rep (j, ps.size()) if (max < norm(ps[j]-c)) {
        max = norm(ps[j]-c);
        k = j;
      }
      c += (ps[k]-c) * move;
    }
    move /= 2;
  }
  return c;
}

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

    VP p(n);
    rep(i,n){
        int x,y;
        cin >>x >>y;
        p[i] = {x,y};
    }

    Point c = minEnclosingCircle(p);
    double ans = 0;
    rep(i,n) ans = max(ans, abs(c-p[i]));
    printf("%.15f\n", ans);
    return 0;
}


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

using namespace std;

int main() {

	int D;
	cin >> D;

	vector<int> c(27);
	for (int i = 1; i <= 26; i++) {
		cin >> c[i];
	}

	vector<vector<int>> sd(D + 1, vector<int>(27));

	for (int i = 1; i <= D; i++) {
		for (int j = 1; j <= 26; j++) {
			cin >> sd[i][j];
		}
	}

	mt19937 mt{ std::random_device{}() };

	uniform_int_distribution<int> dist(1, 26);


	long long resmax = -100000000000000;
	vector<int> maxcont(D + 1);

	for (int k = 0; k < 100000; k++) {

		long long tmpres = 0;
		vector<int> cont(D + 1);
		vector<int> lastcont(27);

		for (int i = 1; i <= D; i++) {

			cont[i] = dist(mt);

			lastcont[cont[i]] = i;
			tmpres += sd[i][cont[i]];

			for (int j = 1; j <= 26; j++) {
				tmpres -= c[j] * (i - lastcont[j]);
			}

		}

		if (resmax < tmpres) {
			resmax = tmpres;
			maxcont = cont;
		}
	}

	for (int i = 1; i <= D; i++) {
		cout << maxcont[i] << endl;
	}

	return 0;

}

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

int main(void){
    // Here your code !
    int n,m;
    cin >> n >> m;
    vector<vector<int>> boxes(n,vector<int>(1,0));
    boxes[0][0] = 1;
    
    for(int i = 0; i < m; i++){
        int x,y;
        cin >> x >> y;
        x--;y--;
        
        if(boxes[x].size() == 1){
            if(boxes[x][0] == 1){
                boxes[y].push_back(1);
            }else{
                boxes[y].push_back(0);
            }
            boxes[x].pop_back();
            
            continue;
        }
        
        if(boxes[x].end() != find(boxes[x].begin(),boxes[x].end(),1)){
            boxes[y].push_back(1);
            boxes[x].pop_back();
            boxes[x][0] = 1;
        }else{
            boxes[y].push_back(0);            
            boxes[x].pop_back();        
        }
        
    }
    
    int ans = 0;
    for(int i = 0; i < n; i++){
        
        if(boxes[i].end() != find(boxes[i].begin(),boxes[i].end(),1))ans++;
    }
    
    cout << ans << endl;
}


Measured memory_bytes: 6396
const main = (input) => {
  input = input.trim().split('\n')
  const n = Number(input[0])
  const as = input[1].split(' ').map(n => Number(n))
  let cnt = 1;
  let result = 0;
  for (let i = 0; i < n; i++) {
    const a = as[i]
    if (a !== cnt) {
      result++
      continue;
    }
    cnt++
  }
  if (cnt === 1) {
    result = -1
  }
  console.log(result)
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'))

Measured memory_bytes: 26320
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define repr(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define invrepr(i,a,b) for(int i=b-1;i>=a;i--)
#define invrep(i,n) invrepr(i,0,n)
#define repitr(itr,a) for(auto itr=a.begin();itr!=a.end();++itr)
const int MOD=1e9+7;
 

vector<int> binary(int a, int n) {
    vector<int> bit(n);
    rep(i,n) {
        bit[i]=a%2;
        a/=2;
    }
    return bit;
}


bool isflag(vector<int> sum, vector<int> p) {
    bool flag=1;
    rep(i,sum.size()) {
        if (sum[i]+p[i]==2) flag=0;
    }
    return flag;
}


int main() {
    int n;
    cin >> n;
    vector<vector<int>> b;
    int ain;
    rep(i,n) {
        cin >> ain;
        vector<int> bit=binary(ain,20);
        b.push_back(bit);
    }
    ll ans=0;
    vector<int> now(20);
    int right=0;
    rep(left,n) {
        while (right<n && isflag(now,b[right])) {
            rep(i,20) now[i]+=b[right][i];
            ++right;
        }
        ans+=right-left;
        if (left==right) ++right;
        else {
            rep(i,20) now[i]-=b[left][i];
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 25132