akhauriyash/Code-Regression huggingface dataset:
using System;
class Program
{
    static void Main(string[] args)
    {
        string[] input = Console.ReadLine().Split(' ');

        int x = int.Parse(input[0]);
        int y = int.Parse(input[1]);
        int flag = 0;
        for(var i = 0; i<=x; i++) // iは亀の数
        {
            int sum = i * 4 + (x - i) * 2;
            if (sum == y)
            {
                Console.WriteLine("Yes");
                flag++;
                break;
            }
        }
        if(flag==0)
        {
            Console.WriteLine("No");
        }
    }
}


Measured memory_bytes: 27504
#include <bits/stdc++.h>
 
using namespace std;
 
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<string> g(n);
  for (int i = 0; i < n; i++) {
    cin >> g[i];
  }
  int ans = 0;
  for (int st = 0; st < n; st++) {
    vector<int> dist(n, -1);
    vector<int> que(1, st);
    dist[st] = 0;
    for (int b = 0; b < (int) que.size(); b++) {
      for (int i = 0; i < n; i++) {
        if (g[que[b]][i] == '1' && dist[i] == -1) {
          que.push_back(i);
          dist[i] = dist[que[b]] + 1;
        }
      }
    }
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n; j++) {
        if (g[i][j] == '1' && dist[i] == dist[j]) {
          cout << -1 << '\n';
          return 0;
        }
      }
    }
    int mx = *max_element(dist.begin(), dist.end());
    ans = max(ans, mx);
  }
  cout << ans + 1 << endl;
  return 0;
}

Measured memory_bytes: 3660
#include <bits/stdc++.h>
#define INF 1e+9
#define debug(x) cerr << #x << ": " << x << "\n";
using namespace std;
using ll = long long;
using P = pair<int, int>;

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

    int res = 1;
    while(x < y){
        x *= 2;
        if(x <= y) res++;
    }

    cout << res << '\n';
    return 0;
}

Measured memory_bytes: 256
n = int(input())
n_list = [input() for i in range(n)]
m = int(input())
m_list = [input() for i in range(m)]

get_money = []

for word in n_list:
    plus = [i for i, j in enumerate(n_list) if j == word]
    plus = len(plus)
    minus = [i for i, j in enumerate(m_list) if j == word]
    minus = len(minus)
    price = 1*plus - 1*minus
    get_money.append(price)

ans = max(get_money)
if ans > 0:
    print(ans)
else:
    print(0)

Measured memory_bytes: 3064
import java.util.*;

public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		char[] arr = sc.next().toCharArray();
		int left = 0;
		int right = arr.length - 1;
		int count = 0;
		while (right - left > 0) {
			if (arr[right] == arr[left]) {
				left++;
				right--;
			} else if (arr[right] == 'x') {
				right--;
				count++;
			} else if (arr[left] == 'x') {
				left++;
				count++;
			} else {
				System.out.println(-1);
				return;
			}
		}
		System.out.println(count);
	}
}


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

using namespace std;
#define inputInt(a) int a; cin >> a; 
#define inputInt2(a,b) int a; int b; cin >> a >> b; 
#define inputInt3(a,b,c) int a; int b; int c; cin >> a >> b >> c;
#define inputLong(a) long a;cin >> a;
#define inputIntArray(a,N) int a[N];for(int i=0;i<N;i++){cin >> a[i];}
#define inputLongArray(a,N) long a[N];for(int i=0;i<N;i++){cin >> a[i];}
#define inputDoubleArray(a,N) double a[N];for(int i=0;i<N;i++){cin >> a[i];}
#define inputIntArray2(a,b,N) int a[N]; int b[N]; for(int i=0;i<N;i++){cin >> a[i] >> b[i];}
#define output(answer) cout << answer << endl;
#define fN(i,N)    for(int i=0; i<N; i++)
#define fSE(i,s,e) for(int i=s; i<=e; i++)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

int main(){
  //accumulateを用いる時は、第3引数がint型かどうか注意しましょう！！（自戒）
  
  //input
  inputInt(N);
  inputIntArray(v,N);
  inputIntArray(c,N);
  
  vector<int> a(N,0);
  fN(i,N) a[i]=v[i]-c[i];
  
  //main
  int ans = 0;
  sort(a.begin(), a.end());
  int positive = lower_bound(a.begin(), a.end(), 1) - a.begin();
  fSE(i,positive,N-1) ans += a[i];
  
  //output
  output(ans);
  
  return 0;
}

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

string hw[101];

int main() {
    int n, m, k;
    cin >> n >> m >> k;
    rep(i, n+1) {
        rep(j, m+1) {
            if (m * i + n * j - 2 * i * j == k) {
                cout << "Yes" << endl;
                return 0;
            }
        }
    }
    cout << "No" << endl;
}


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef int itn;

const int inf = numeric_limits<int>::max() /4;
const ll linf = numeric_limits<ll>::max() /4;
const ull ulinf = numeric_limits<ull>::max()/4;
const double pi = acos(-1);
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
const int dx8[8]={-1,0,1,-1,1,-1,0,1};
const int dy8[8]={-1,-1,-1,0,0,1,1,1};

#define p_queue(i) priority_queue<i> 
#define rp_queue(i) priority_queue<i, vector<i>, greater<i>> 
#define P(p) cout<<(p)<<endl
#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define mod(i) ((i)%(ll)(1e9 + 7))
#define divm(a,b) (mod(a * modpow((ll)b,(ll)(1e9+5))))
#define rsort(a,b,c) sort(a, b, greater<c>())
#define vsort(v) sort(v.begin(), v.end());
#define rvsort(v) sort(v.end(), v.begin());
#define ft first
#define sd second
#define pb push_back
#define it insert
#define sz(x) ((int)(x).size())
#define lb(a,n,k) (lower_bound(a,a+n,k) - a) 
#define vlb(a,k)  (lower_bound(a.begin(),a.end(),k) - a.begin())
#define ub(a,n,k) (upper_bound(a,a+n,k) - a) 
#define vub(a,k)  (upper_bound(a.begin(),a.end(),k) - a.begin())
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define ret return

ll modpow(ll i,ll j){ ll tmp=1; while(j){ if(j%2)tmp=mod(tmp*i);i=mod(i*i);j/=2;}return tmp;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

vector<string> split(const string &str, char sep){
    vector<string> v;
    stringstream ss(str);
    string buffer;
    while( getline(ss, buffer, sep) ) {
        v.push_back(buffer);
    }
    return v;
}

//ll ncr[100][100];
//ll nCr(int n, int r){if(n==r) ret ncr[n][r] = 1; if(r==0) ret ncr[n][r] = 1; if(r==1) ret ncr[n][r] = n;if(ncr[n][r]) ret ncr[n][r]; ret ncr[n][r] = nCr(n-1,r) + nCr(n-1,r-1);}

//ll npr[100][100]={};
//ll nPr(int n,int r){if(npr[n][r])ret npr[n][r];if(r==0)ret npr[n][r] = 1;if(r==1)ret npr[n][r] = n;ret npr[n][r] = n * nPr(n-1,r-1);}

//ll nHr(int n,int r){ret nCr(n+r-1,r);}

///////////////////////////////////////////////////////////////////////////



int main(){
    int n,k;
    cin >> n >> k;
    int a[100005] = {};

    rep(i,0,n)cin >> a[i];
    rsort(a,a+n,int);

    int sum = 0;
    rep(i,0,k)sum += a[i];
    P(sum);
	
	return  0;
}

Measured memory_bytes: 640
import java.util.Scanner;
import java.lang.Math;
class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        char[] alp = s.toCharArray();
        int a = (int)(alp[0]);
        alp[0] = (char)(a+1);
        System.out.print(alp[0]);
    }
}

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

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define FOR(i, a, b) for (int (i) = (a); (i) <= (b); (i)++)
#define ROF(i, a, b) for (int (i) = (a); (i) >= (b); (i)--)
#define REP(i, n) FOR(i, 0, (n)-1)
#define sqr(x) ((x) * (x))
#define all(x) (x).begin(), (x).end()
#define reset(x, y) memset(x, y, sizeof(x))
#define uni(x) (x).erase(unique(all(x)), (x).end());
#define BUG(x) cerr << #x << " = " << (x) << endl
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define _1 first
#define _2 second

ll k, a, b;

int main() {
    cin >> k >> a >> b;
    if (b - 2 <= a) {
        cout << 1 + k;
        return 0;
    }
    if (a + 1 > k) {
        cout << 1 + k;
        return 0;
    }
    cout << max(1 + k, (k - a + 1) / 2 * (b - a) + a + (k - a + 1) % 2);
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <string.h>
#include <vector>
#include <cstdio>
#include <cmath>

#define PI 3.141592
#define INF 100001
#define ll long long
#define loop(i,n) for(int i=0;i<n;i++)

using namespace std;

int main(){
    int n;
  cin>>n;
  bool jud=true;
  for(int i=0;i<n;i++){
    char temp;
    cin>>temp;
    if(temp=='Y'){
      jud=false;
      break;
    }
  }
  if(jud==true){
    cout<<"Three";
  }else{
    cout<<"Four";
  }
  return 0;
}


Measured memory_bytes: 256
using System;
using System.Diagnostics;
using System.IO;
using System.Text;
using System.Linq;
using System.Collections.Generic;

class Program
{
    static void Main(string[] args) {
#if DEBUG
        MyDebugger.Test(process, "../TextFile1.txt");
        //MyDebugger.Test(process, "../TextFile2.txt");
        //MyDebugger.MakeTestCase("../TextFile2.txt");
#else
        object ret = process(new StreamReader(Console.OpenStandardInput()));
        Console.WriteLine(ret);
#endif
    }

    static object process(TextReader input) {
        var spl   = input.ReadLine().Split(' ');
        var n     = int.Parse(spl[0]);
        var t     = int.Parse(spl[1]);

        var cc = new List<int>();

        for(int i=0; i<n; i++) {
            spl   = input.ReadLine().Split(' ');
            var cx     = int.Parse(spl[0]);
            var tx     = int.Parse(spl[1]);

            if(tx <= t) {
                cc.Add(cx);
            }
        }

        if (cc.Count == 0) return "TLE";

            return cc.Min();
    }
}


Measured memory_bytes: 13268
#include <iostream>

using namespace std;

int main() {
    int a, b, c, d, e, f;
    cin >> a >> b >> c >> d >> e >> f;

    int r_wat = 100 * a, r_sug = 0;
    for (int i = 0; i <= f; i += 100 * a) {
        for (int j = 0; i + j <= f; j += 100 * b) {
            for (int k = 0; i + j + k <= f; k += c) {
                for (int l = 0; i + j + k + l <= f; l += d) {
                    int wat = i + j;
                    int sug = k + l;

                    if (wat > 0
                            && wat / 100 * e >= sug
                            && static_cast<double>(r_sug) / (r_wat + r_sug)
                                    < static_cast<double>(sug) / (wat + sug)) {
                        r_wat = wat;
                        r_sug = sug;
                    }
                }
            }
        }
    }

    cout << (r_wat + r_sug) << " " << r_sug << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<bitset>
#include<cctype>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<functional>
#include<limits>
#include<list>
#include<map>
#include<set>
#include<stack>
#include<string>
#include<sstream>
#include<queue>
#include<vector>
using namespace std;

#define MOD 1000000007
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL

int main() {
	string s; cin >> s;
	for (int i = 0; i < s.size(); i++) {
		if (s[i] - 3 >= 'A')
			cout << (char)(s[i] - 3);
		else
			cout << (char)(s[i] - 3 + 26);
	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 1176
###==================================================
### import
#import bisect
#from collections import Counter, deque, defaultdict
#from copy import deepcopy
#from functools import reduce, lru_cache
#from heapq import heappush, heappop
#import itertools
#import math
#import string
import sys
### stdin
def input(): return sys.stdin.readline()
def iIn(): return int(input())
def iInM(): return map(int, input().split())
def iInM1(): return map(int1, input().split())
def iInLH(): return list(map(int, input().split()))
def iInLH1(): return list(map(int1, input().split()))
def iInLV(n): return [iIn() for _ in range(n)]
def iInLV1(n): return [iIn()-1 for _ in range(n)]
def iInLD(n): return [iInLH() for _ in range(n)]
def iInLD1(n): return [iInLH1() for _ in range(n)]
def sInLH(): return list(input().split())
def sInLV(n): return [input().rstrip('\n') for _ in range(n)]
def sInLD(n): return [sInLH() for _ in range(n)]
### stdout
def OutH(lst, deli=' '): print(deli.join(map(str, lst)))
def OutV(lst): print('\n'.join(map(str, lst)))
### setting
sys.setrecursionlimit(10 ** 6)
### utils
int1 = lambda x: int(x) - 1
### constants
INF = int(1e9)
MOD = 1000000007
dx = (-1, 0, 1, 0)
dy = (0, -1, 0, 1)
###---------------------------------------------------

X = iIn()
A = iIn()
B = iIn()

ans = (X - A) % B
print(ans)

Measured memory_bytes: 61504
#include <iostream> 
#include <vector> 
#include <algorithm> 
#include <bits/stdc++.h> 
#include <stdlib.h> 
#include <stdio.h> 
#include <functional> 
#include<math.h> 
using namespace std;
int main(void){
    // Your code here!
    long long int N,K;
    cin >> N >> K;
    long long int count = 0;
    for(int i = 1;i <= N; i++){
        if(i > K){
            count += (i - K) * (N / i) ;
            if(K == 0){
                count--;
            }
            if(N % i - K +1 > 0){
                count += N % i - K + 1;
            }
        }
        //cout << count << endl;
    }
    cout << count << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned int u32;
typedef pair<int, int> p;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
int Inf = (1<<30);
ll inf = (1LL<<60);
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
int main() {
	int n;
	cin >> n;
	int t;
	cin >> t;
	int i;
	ll ans = 0;
	int zen = 0;
	for (i = 0; i < n; i++) {
		int a;
		cin >> a;
		if (n >= 1) ans += min(t, a - zen);
		zen = a;
	}
	ans += t;
	cout << ans;
	return 0;
}

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

int main()
{
    string s;
    cin >> s;
    if (s == "SUN")
        cout << "7";
    if (s == "MON")
        cout << "6";
    if (s=="TUE")
    {
        cout << "5";
    }
    if (s == "WED")
    {
        cout << "4";
    }
    if (s == "THU")
    {
        cout << "3";
    }
    if (s == "FRI")
    {
        cout << "2";
    }
    if (s == "SAT")
    {
        cout << "1";
    }
    return 0;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
"""
Created on Mon Sep  7 21:29:58 2020

@author: liang
"""

N, M = map(int, input().split())
adj = [list() for _ in range(N)]

for i in range(M):
    a, b = map(int, input().split())
    adj[a-1].append(b-1)
    adj[b-1].append(a-1)

visited = [False for i in range(N)]
sign = [-1]*N

from collections import deque

visited[0] = True
q = deque()
q.append(0)
sign[0] = 0

while q:
    cur = q.popleft()
    for a in adj[cur]:
        if not visited[a]:
            visited[a] = True
            sign[a] = cur + 1
            q.append(a)

if all(x >= 0 for x in sign):
    print("Yes")
    [print(a) for a in sign[1:] ]
else:
    print("No")    

Measured memory_bytes: 39392
#include <stdio.h>
int main()
{
int a, b, c, max;
scanf("%d %d %d",&a ,&b ,&c);
if(a < c && b < c){
max=c;
}
else if(a < b && c < b){
max=b;
b=c;
}
else if(b < a && c < a){
max=a;
a=b;
b=c;
}
if(a<b){
printf("%d %d %d\n",a ,b ,max);
}
else{
printf("%d %d %d\n",b ,a ,max);
}


return 0;
}

Measured memory_bytes: 2704
#include<bits/stdc++.h>
#define all(x) begin(x),end(x)
#define dbg(x) cerr << #x << " = " << x << endl
#define _ << " " <<
#define X real()
#define Y imag()
using namespace std;
using ll=long long;
using point=complex<ll>;

const int MXN=200005;

int n,qh,h[MXN];
point hull[MXN];
ll dp[MXN],C;

bool ccw(point a,point b,point c){
  const point p=b-a,q=c-a;
  if(p.Y/p.X!=q.Y/q.X)return p.Y/p.X<q.Y/q.X;
  return p.Y%p.X*q.X<=q.Y%q.X*p.X;
}

void insert(point p){
  while(qh>=2&&ccw(p,hull[qh-1],hull[qh-2]))qh--;
  hull[qh++]=p;
}

ll sqr(int x){return(ll)x*x;}

ll query(int x){
  int lo=0,hi=qh-1;
  while(lo<hi){
    int md=(lo+hi)/2;
    ll r1=hull[md].X*x+hull[md].Y;
    ll r2=hull[md+1].X*x+hull[md+1].Y;
    if(r1>r2){
      lo=md+1;
    }else{
      hi=md;
    }
  }
  // dbg(hull[lo]);
  return hull[lo].X*x+hull[lo].Y+C;
}

int main(){
  scanf("%d%lld",&n,&C);
  for(int i=1;i<=n;++i)scanf("%d",h+i);
  insert({-2*h[n],sqr(h[n])});
  for(int i=n-1;i>=1;--i){
    // for(int i=0;i<qh;++i)cout<<hull[i]<<",";
    dp[i]=query(h[i])+sqr(h[i]);
    // dbg(dp[i]);
    insert({-2*h[i],dp[i]+sqr(h[i])});
  }
  printf("%lld\n",dp[1]);
}


Measured memory_bytes: 5760
#include <bits/stdc++.h>
using namespace std;
constexpr int CONTEST_NUM=26;

int score_function(const vector<int> &t,const vector<vector<int>> &s,const vector<int> &c,const int &d){
    vector<int> last(27);
    int manzoku=0;
    for(int i=1;i<=d;i++){
        manzoku+=s[i][t[i]];
        last[t[i]]=i;
        int sum=0;
        for(int j=1;j<=CONTEST_NUM;j++){
            sum+=c[j]*(i-last[j]);
        }
        manzoku-=sum;
    }
    return manzoku;
}

void set_ans(const vector<int> &t,vector<int> &ans,const int &d){
    for(int i=1;i<=d;i++){
        ans[i]=t[i];
    }
}

int main() {
    int d;cin>>d;
    vector<int> c(27);
    for(int i=1;i<=CONTEST_NUM;i++){
        cin>>c[i];
    }
    vector<vector<int>> s(d+1,vector<int>(27));
    for(int i=1;i<=d;i++){
        for(int j=1;j<=CONTEST_NUM;j++){
            cin>>s[i][j];
        }
    }
    vector<int> t(d+1);
    vector<int> ans(d+1);
    int old_ans=-1000000000;
    std::random_device rnd;
    std::mt19937 mt(rnd());
    std::uniform_int_distribution<> rand26(1,26);
    std::uniform_int_distribution<> randd(1,d);

    for(int i=1;i<=d;i++){
        int max_contest=-1;
        for(int j=1;j<=CONTEST_NUM;j++){
            if(max_contest<s[i][j]){
                max_contest=s[i][j];
                t[i]=j;
            }
        }
    }
    int k=0;
    while(k<305000){
        int che1=randd(mt);
        int che2=randd(mt);
        int che3=randd(mt);
        int old_f=t[che1];
        int old_g=t[che2];
        int old_h=t[che3];
        t[che1]=rand26(mt);
        t[che2]=rand26(mt);
        t[che3]=rand26(mt);
        int tmp=score_function(t,s,c,d);
        if(tmp>old_ans){
            old_ans=tmp;
        }
        else{
            t[che1]=old_f;
            t[che2]=old_g;
            t[che3]=old_h;
        }
        k++;
    }
    //cout<<old_ans<<endl;
    for(int i=1;i<=d;i++){
        cout<<t[i]<<endl;
    }

    return 0;
}


Measured memory_bytes: 3708
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<queue>
#include<utility>
#include<cstdlib>
using namespace std;
typedef long long ll;
typedef pair<int,int> pi;
typedef pair<ll,ll> pl;
typedef double db;
#define ls(x) x<<1
#define rs(x) x<<1|1
#define low(x) (x&-x)
#define all(x) x.begin(),x.end()
#define mp make_pair
#define X first
#define Y second
#ifdef _DEBUG
	const int N=1e3+10;
#else
	const int N=1e6+10;
#endif
const ll mod=1e9+7;
template<typename T> inline T gcd(T a,T b){return !b?a:gcd(b,a%b);}
template<typename T> inline T q_pow(T a,T x){T ans=1,tmp=a;while(x){if(x&1)(ans*=tmp)%=mod;(tmp*=tmp)%=mod;x>>=1;}return ans;}
template<typename T> inline void re(T &N){int f=1;char c;while((c=getchar())< '0'||c> '9')if(c=='-')f=-1;N=c-'0';while((c=getchar())>='0'&&c<='9')N=N*10+c-'0';N*=f;}
int m,n,t=1,st,en;
int a[N],b[N],c[N];
char s[N];
int x,y,A,B,C;
priority_queue<int,vector<int>,greater<int> >q;
int main()
{
	// freopen("data.txt","r",stdin);
	re(x);re(y);re(A);re(B);re(C);
	for(int i=1;i<=A;i++)re(a[i]);
	for(int i=1;i<=B;i++)re(b[i]);
	for(int i=1;i<=C;i++)re(c[i]);
	sort(a+1,a+A+1,greater<int>());
	sort(b+1,b+B+1,greater<int>());
	sort(c+1,c+C+1);
	ll ans=0;
	for(int i=1;i<=x;i++)ans+=a[i],q.push(a[i]);
	for(int i=1;i<=y;i++)ans+=b[i],q.push(b[i]);
	for(int i=1;i<=C;i++)
	{
		int tmp=q.top();
		if(c[i]>tmp)
		{
			ans+=c[i]-tmp;
			q.pop();q.push(c[i]);
		}
	}
	printf("%lld\n",ans);
	return 0;
}


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

const int MAXN = 2e5+5;
vector<int> h;

vector<int> dp(MAXN, -1);

int solve(int x) {
	if (dp[x] != -1)
		return dp[x];

	if (x == 0)
		return 0;
	if (x == 1)
		return abs(h[x] - h[0]);

	return dp[x] = min(abs(h[x] - h[x - 1]) + solve(x - 1),
			   abs(h[x] - h[x - 2]) + solve(x - 2));
}


int main(int argc, char const **argv) 
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	int n, x;

	cin >> n;
	for (int i = 0 ; i < n ; i++) {
		cin >> x;
		h.push_back(x);
	}

	cout << solve(n - 1);
	
	return 0;
}


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

int M;
int N;

void dfs(Graph G,vector<int> &A,const vector<int> B,int &cnt){
    if(A.size()==N-1){
        bool flag=true;
        vector<int>C=A;
        sort(C.begin(),C.end());
        if(C!=B){
            flag=false;
        }
        if(G[0].count(A[0])){
        }
        else{
            flag=false;
        }
        if(N>2&&flag){
            rep(i,N-2){
                if(G[A[i]].count(A[i+1])){
                }
                else{
                    flag=false;
                    break;
                }
            }
        }
        if(flag){
            cnt++;
        }
        return;
    }//数列のサイズがNになったら終わる
    for(int v=1;v<=N-1;v++){
        A.push_back(v);
        dfs(G,A,B,cnt);
        A.pop_back();
    }//0からMまで入れていく
}//M^N通りの数列を作ることができる

int main(){
    //頂点と辺の数を受け取る
    cin>>N>>M;
    //グラフのデータを受け取る
    Graph G(N);
    rep(i,M){
        int a,b;
        cin>>a>>b;
        a--;b--;
        G[a].insert(b);
        G[b].insert(a);
    }
    int cnt=0;
    vector<int>A;
    vector<int>B;
    rep(i,N-1){
        B.push_back(i+1);
    }
    dfs(G,A,B,cnt);
    cout<<cnt<<endl;
}


Measured memory_bytes: 256
/*
confirm 0LL and 1LL
confirm cornercases such as 0
confirm times of cin < 10^6
*/
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll, ll>;
using Pld = pair<ld, ld>;
using Vec = vector<ll>;
using VecP = vector<P>;
using VecB = vector<bool>;
using VecC = vector<char>;
using VecD = vector<ld>;
using VecS = vector<string>;
using Graph = vector<VecP>;
template <typename T>
using Vec1 = vector<T>;
template <typename T>
using Vec2 = vector<Vec1<T> >;
#define REP(i, m, n) for(ll (i) = (m); (i) < (n); ++(i))
#define REPN(i, m, n) for(ll (i) = (m); (i) <= (n); ++(i))
#define REPR(i, m, n) for(ll (i) = (m)-1; (i) >= (n); --(i))
#define REPNR(i, m, n) for(ll (i) = (m); (i) >= (n); --(i))
#define rep(i, n) REP(i, 0, n)
#define repn(i, n) REPN(i, 1, n)
#define repr(i, n) REPR(i, n, 0)
#define repnr(i, n) REPNR(i, n, 1)
#define all(s) (s).begin(), (s).end()
#define pb push_back
#define fs first
#define sc second
template <typename T>
bool chmax(T &a, const T b){if(a < b){a = b; return true;} return false;}
template <typename T>
bool chmin(T &a, const T b){if(a > b){a = b; return true;} return false;}
template <typename T>
ll pow2(const T n){return (1LL << n);}
template <typename T>
void cosp(const T n){cout << n << ' ';}
void co(void){cout << '\n';}
template <typename T>
void co(const T n){cout << n << '\n';}
template <typename T1, typename T2>
void co(pair<T1, T2> p){cout << p.fs << ' ' << p.sc << '\n';}
template <typename T>
void co(const Vec1<T> &v){for(T i : v) cosp(i); co();}
template <typename T>
void co(initializer_list<T> v){for(T i : v) cosp(i); co();}
template <typename T>
void ce(const T n){cerr << n << endl;}
void sonic(){ios::sync_with_stdio(false); cin.tie(0);}
void setp(const ll n){cout << fixed << setprecision(n);}
constexpr int INF = 1e9+1;
constexpr ll LINF = 1e18+1;
constexpr ll MOD = 1e9+7;
//constexpr ll MOD = 998244353;
constexpr ld EPS = 1e-11;
const ld PI = acos(-1);

int main(void){
	ll n, m;
	cin >> n >> m;
	Vec a(n);
	rep(i, n) cin >> a[i];

	ll sum = 0;
	rep(i, n) sum += a[i];

	ll cnt = 0;
	rep(i, n){
		if(a[i] * 4 * m >= sum) cnt++;
	}
	if(cnt >= m) puts("Yes");
	else puts("No");

	return 0;
}


Measured memory_bytes: 256
n=int(input())
a,b,c=list(map(int,input().split())),list(map(int,input().split())),list(map(int,input().split()))
count=b[a[0]-1]
for i in range(1,n):
  if a[i]-a[i-1]==1:
    count+=c[a[i-1]-1]
  count+=b[a[i]-1]
print(count)

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

const int N = 1e5 + 7;
string str;
int pref[N];
int n, q;

int main() {

  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);

  cin >> n >> q >> str;
  for (int i = 1; i < n; ++i) {
    pref[i + 1] = pref[i];
    if (str[i - 1] == 'A' && str[i] == 'C') {
      pref[i + 1]++;
    }
  }
  for (int i = 0; i < q; ++i) {
    int l, r;
    cin >> l >> r;
    l--; r--;
    cout << pref[r + 1] - pref[l] - (l && str[l - 1] == 'A' && str[l] == 'C') << "\n";
  }

  return 0;
}



Measured memory_bytes: 1488
#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>

using namespace std;

typedef pair<int, int> Range; // represents [first, second]

int countOf(const Range &r) {
    return r.second - r.first + 1;
}

int check(int R, const Range &r) {
    if(R < r.first) return 0;
    if(r.second <= R) return countOf(r);
    return countOf(r)-countOf(Range(R+1, r.second));
}

int main() {
    while(true) {
        int N;
        cin >> N;
        if(!N) break;
        int M, P, Q, R;
        cin >> M >> P >> Q >> R;

        vector<Range> cards;
        cards.push_back(Range(1, N));
        while(M--) {
            int x, y;
            cin >> x >> y;

            vector<Range> next;
            int cnts[] = {N-y, y-x, x};
            int cntidx = 0;
            int end = cards.size();
            for(int i = cards.size()-1; i >= 0; --i) {
                int cnt = countOf(cards[i]);
                if(cnts[cntidx]-cnt <= 0) {
                    int rem = cnts[cntidx];
                    next.push_back(Range(cards[i].second-rem+1, cards[i].second));
                    for(int j = i+1; j < end; ++j) {
                        if(countOf(cards[j]) > 0) next.push_back(cards[j]);
                    }
                    cards[i].second -= rem;
                    end = i+1;
                    if(++cntidx == 4) {
                        break;
                    }
                    else {
                        ++i;
                        continue;
                    }
                }
                cnts[cntidx] -= cnt;
            }
            cards = next;
        }
        /*
        for(int i = 0; i < cards.size(); ++i) {
            cout << '(' << cards[i].first << ", " << cards[i].second << ')' << endl;
        }
        */
        int ans = 0;
        int currCount = 0;
        for(int i = 0; i < cards.size(); ++i) {
            int cnt = countOf(cards[i]);
            Range r = cards[i];

            bool ok = false;
            if(currCount < P && currCount+cnt >= P) {
                r.first += P-currCount-1;
                ok = true;
                //cout << i << ' ' << ans << endl;
            }
            if(currCount < Q && currCount+cnt >= Q) {
                r.second -= currCount+cnt-Q;
                ok = true;
                //cout << i << ' ' << ans << endl;
            }
            if(P <= currCount+cnt && currCount+cnt <= Q) ok = true;

            if(ok) ans += check(R, r);
            currCount += cnt;
        }
        cout << ans << endl;
    }
}

Measured memory_bytes: 1132
process.stdin.resume();
process.stdin.setEncoding('utf8');

var lines = [];
var reader = require('readline').createInterface({
  input: process.stdin,
  output: process.stdout
});
reader.on('line', (line) => {
  lines.push(line);
});
reader.on('close', () => {
    let [A, B, C] = lines[0].split(" ").map(v=>v-0);
    let ans = 0;
    while(A%2===0 && B%2===0 && C%2===0){
        if(ans > 100000) break;
        const a = B/2+C/2;
        const b = A/2+C/2;
        const c = B/2+A/2;
        A = a; B = b; C = c;
        ans++;
    }
    console.log(ans>100000?-1:ans);
    
});


Measured memory_bytes: 32632
n, m = map(int, input().split())
a = [list(map(int, input().split())) for _ in range(n)]
ans = [0]*m
num = 0

for i in range(n):
  for j in range(1,a[i][0]+1):
    ans[a[i][j]-1] += 1 

for k in range(m):
  num += ans[k]//n
  
print(num)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define int long long
#define endl '\n'
#define FOR(i, a, n) for (int i = (a); i < (n); ++i)
#define REP(i, n) FOR(i, 0, n)
using namespace std;

void _main() {
    int N, K, C;
    string S, revS;
    cin >> N >> K >> C >> S;
    revS = S;
    reverse(revS.begin(), revS.end());
    vector<vector<int>> dp(2);
    REP (i, 2) dp[i].resize(N);
    int mx0 = -1, mx1 = -1;
    REP (i, N) {
        if (S[i] == 'o') dp[0][i] = (mx0 < 0 ? 1 : mx0 + 1);
        if (i - C >= 0) mx0 = max(mx0, dp[0][i - C]);
        if (revS[i] == 'o') dp[1][i] = (mx1 < 0 ? 1 : mx1 + 1);
        if (i - C >= 0) mx1 = max(mx1, dp[1][i - C]);
    }
    reverse(dp[1].begin(), dp[1].end());
    map<pair<int, int>, vector<int>> mp;
    REP (i, N) {
        if (dp[0][i] + dp[1][i] > K + 1) return;
        if (S[i] == 'x' || dp[0][i] + dp[1][i] < K + 1) continue;
        mp[make_pair(dp[0][i], dp[1][i])].push_back(i + 1);
    }
    vector<int> ans;
    for (auto p : mp) {
        if (p.second.size() == 1) ans.push_back(p.second[0]);
    }
    sort(ans.begin(), ans.end());
    REP (i, ans.size()) cout << ans[i] << endl;
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(10);
    _main();
    return 0;
}

Measured memory_bytes: 30612
#pragma region
#include <bits/stdc++.h>
using namespace std;
inline void ci(void){
  return;
}
template <typename First, typename... Rest>
void ci(First& first, Rest&... rest){
  cin >> first;
  ci(rest...);
  return;
}
inline void co(void){
  cout << "\n";
  return;
}
template <typename First, typename... Rest>
void co(First first, Rest... rest){
  cout << first << " ";
  co(rest...);
  return;
}
#define ll long long
#define ld long double
#define st string
#define dl double
#define wh while
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define tp tuple
#define ft first
#define sc second
#define ve vector
#define tos to_string
#define len length
#define rt return 0
#define br break
#define con continue
#define lcm(n, m) (n * m / gcd(n, m))
#define np next_permutation
#define repi(i, m, n) for(int i=(int)(m);i<(int)(n);i++)
#define rep(i, n) repi(i, 0, n)
#define repill(i, m, n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define repll(i, n) repill(i, 0, n)
#define revi(i, m, n) for(int i=(int)(m);i>(int)(n);i--)
#define rev(i, m) revi(i, m, 0)
#define revill(i, m, n) for(ll i=(ll)(m);i>(ll)(n);i--)
#define revll(i, n) revill(i, 0, n)
#define sz(v) ((int)(v).size()) 
#define each(i, n) for(auto&& i: n)
#define all(n) (n.begin(), n.end())
#define allr(n) (n.rbegin(), n.rend())
#define sp(n) cout << fixed << setprecision(n)
#pragma endregion
// sqrt ルート, int 2*10^9, gcd　最大公約数
// __builtin_popcount bitの個数

int main() {
  st s;
  ci(s);
  rep(i, sz(s)){
    if(s.at(i) == ','){
      s.at(i) = ' ';
    }
  }
  co(s);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
const ll LINF=0x1fffffffffffffff;
const int INF=0x3fffffff;
const int MOD=1000000007;
#define VAR(type,...) type __VA_ARGS__;in(__VA_ARGS__)
#define VEC(type,name,size) vector<type> name(size);each(x, name)in(x)
#define rep(i,a,b) for(int i=(a);i<(b);++i)
#define rrep(i,a,b) for(int i=(a-1);i>=(b);--i)
#define each(x,v) for(auto &x:(v))
#define all(x) (x).begin(),(x).end()
#define print(x) cout<<(x)<<endl
void in(){} template<class T,class... U> void in(T &t,U &...u){cin>>t;in(u...);}
void solve();
int main(){cin.tie(0);ios::sync_with_stdio(0);solve();}

void solve() {
  VAR(int, N);
  VAR(string, S);
  deque<char> d;
  int m = 0;
  rep(i, 0, N) {
    d.push_back(S[i]);
    if (S[i] == '(') {
      m++;
    } else {
      if (m < 1) {
        d.push_front('(');
      } else {
        m--;
      }
    }
  }
  each(x, d) {
    cout << x;
  }
  rep(i, 0, m) {
    cout << ')';
  }
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
#include "math.h"
 
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<int> vin;
typedef pair<ll,ll> P;
typedef vector<P> vp;
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define drep(i,a,b) for(ll i=(a);i>=(b);--i)
#define SIZE(a) int((a).size())
#define out(a) cout<<(a)<<endl;
const int INF=INT_MAX;
const int MAX = 510000;
const ll MOD = 1000000007;
ll fac[MAX], finv[MAX], inv[MAX];

int main(){
  ll a,b,x;cin>>a>>b>>x;
  ll ans=(b/x)-(a/x);
  if(a%x==0){ans++;}
  cout<<ans<<endl;
}


Measured memory_bytes: 3580
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <tuple>
#include <algorithm>
using namespace std;

int main() {
	long long N,M;
	cin >> N >> M;

	long long ans = 0;
	long long sigma_m = 0;
	for (long long i = 1; i*i <= M; i++) {
		if (M%i == 0) {
			sigma_m = M / i;
			if (N <= sigma_m) {
				ans =max(ans, i);
			}
			if (i >= N && sigma_m >= i && M%sigma_m == 0) {
				ans = max(ans,sigma_m);
			}
		}
	}	

	cout << ans;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <utility>
#include <numeric>
#include <array>
#include <cmath>
#include <memory>
using namespace std;
//変数デバッグ
#define DEB(variable) cout << #variable << '=' << variable << endl

//for簡易表記(引数ミス防止)
#define FOR(LoopVariable,numberOFbegin,numberOFend) for (int LoopVariable = (numberOFbegin); (LoopVariable) < (numberOFend); (LoopVariable)++)
#define DEFOR(LoopVariable,numberOFbegin,numberOFend) for (int LoopVariable = (numberOFbegin)-1; (LoopVariable) >= (numberOFend); (LoopVariable)--)
#define REP(LoopVariable,numberOFend) for(int LoopVariable = 0;(LoopVariable)<(numberOFend);LoopVariable++)

constexpr long long int linf = numeric_limits<long long int>::max()-5;
constexpr int inf= numeric_limits<int>::max()-5;
constexpr long long int mod = 1000000007;

int main(){

    int n;
    cin>>n;
    vector<int> v(n),c(n);
    REP(i,n){
        cin>>v[i];
    }
    REP(i,n){
        cin>>c[i];
    }
    int result=0;
    REP(i,n){
        if(v[i]-c[i]>0){
            result+=v[i]-c[i];
        }
    }
    cout<<result<<endl;

    return 0;
}


Measured memory_bytes: 256
st = list(input())
s = [int(i) for i in st]

a1 = [0, 1] * (len(s) // 2)
a2 = [1, 0] * (len(s) // 2)
if len(s) % 2 == 1:
    a1.append(0)
    a2.append(1)

count = 0
l = [0] * 2
for i in range(len(s)):
    if s[i] != a1[i]:
        l[0] += 1
    if s[i] != a2[i]:
        l[1] += 1
print(min(l))

Measured memory_bytes: 6316
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<vector>

const int Maxv = 100020, INF = 0x7fffffff; 
std::vector<int> g[Maxv]; 
int v[Maxv], fa[Maxv], idx[Maxv], cnt, n, m; 
long long ans; 
bool vis[Maxv]; 

inline int read(){
    int 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 << 3) + (x << 1) + ch - '0'; 
        ch = getchar();
    }
    return x * f; 
}

bool cmp(int a, int b){
    return v[a] < v[b]; 
}

inline int find(int x){
    if (fa[x] == x) {
        return x; 
    }
    else {
        fa[x] = find(fa[x]);
    }
    return fa[x]; 
}

inline void merge(int u, int v){
    int fu = find(u); 
    int fv = find(v); 
    if (fu != fv) {
        fa[fu] = fv; 
    }
    cnt++; 
}

int main(){
    n = read();
    m = read(); 
    for (int i = 1; i <= n; i++) {
        v[i] = read(); 
        fa[i] = i; 
    }
    for (int i = 1; i <= m; i++) {
        int u = read() + 1; 
        int v = read() + 1; 
        merge(u, v); 
    }
    if (cnt == n - 1) {
        printf("0"); 
        return 0; 
    }
    int k = (n - 1 - cnt) << 1; 
    if (k > n) {
        printf("Impossible"); 
        return 0; 
    }
    for (int i = 1; i <= n; i++) {
        idx[i] = i; 
    }
    std::sort(idx + 1, idx + n + 1, cmp); 
    for (int i = 1; i <= n; i++) {
        int fi = find(i); 
        g[fi].push_back(i); 
    }
    for (int i = 1; i <= n; i++) {
        if (i == fa[i]) {
            int Min = INF;
            int Index; 
            for (int j = 0; j < g[i].size(); j++) {
                if (v[g[i][j]] < Min) {
                    Min = v[ g[i][j] ]; 
                    Index = g[i][j]; 
                }
            } 
            ans += Min; 
            vis[Index] = true; 
            k--; 
        }
    }
    for (int i = 1; i <= n; i++) {
        if (k && !vis[ idx[i] ]) {
            ans += v[ idx[i] ]; 
            vis[ idx[i] ] = true; 
            k--; 
        }
    }
    printf("%lld", ans); 
    return 0; 
}

Measured memory_bytes: 5632
#include <bits/stdc++.h>
using namespace std;
#pragma optimize("-O3")
#define int long long int
#define pb push_back
#define f first
#define s second
#define endl '\n'

main() {
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int n, k;
	cin>>n>>k;
	int arr[n];
	for(int i=0; i<n; i++){
		cin>>arr[i];
	}
	int lo=1;
	int hi=1e9;
	int ans=-1;
	while(lo<=hi){
		int mid=(lo+hi)/2;
		int val=0;
		for(int i=0; i<n; i++){
			if(arr[i]%mid==0){
				val+=((arr[i]/mid)-1);
			}
			else{
				val+=(arr[i]/mid);
			}
		}
		if(val<=k){
			ans=mid;
			hi=mid-1;
		}
		else{
			lo=mid+1;
		}
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 5168
#include<stdio.h>

void buildMaxHeap(int *);
void maxHeapify(int*,int);

int h;

int main(){

  int A[500001],i;

  scanf("%d",&h);

  
  for(i=1;i<=h;i++){

    scanf("%d",&A[i]);

  }

  //printf("wa-i1\n");
  
  buildMaxHeap(A);

  //printf("wa-i\n");

  for(i=1;i<=h;i++){

    if(i==h)printf(" %d\n",A[i]);
    else printf(" %d",A[i]);

  }
  return 0;
}

void maxHeapify(int A[],int i){

  int l,r,largest,change;

  //printf("i:%d\n",i);
  
  l=2*i;
  r=2*i+1;

  if(l<=h && A[l]>A[i]) largest = l;
  else largest = i;

  if(r<=h && A[r] > A[largest]) largest = r;
  
  if(largest !=i){

    change = A[i];
    A[i]=A[largest];
    A[largest]=change;
    maxHeapify(A,largest);
  }


}

void buildMaxHeap(int A[]){

  int i;

  // printf("wa-i3\n");
  
  for(i=h/2;i>0;i--){
    maxHeapify(A,i);

    //printf("i:%d\n",i);
  }

  // printf("wa-i2\n");
}

Measured memory_bytes: 2548
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
using namespace std;
int cl(int a, int b) {
	return (a - (a%b)) / b;//b=0だと積む
}
int up(int a, int b) {
	return cl(a + b - 1, b);//b=0だと積む
}
int main() {
	int n,m, ba,tu; int ans = 0;
	cin >> n>>m;
	for (int i = 0; i < m; i++) {
		int x, y;
		cin >> x >> y;
		int so = min(min(x - 1, n - x),min( y - 1,n-y));
		cout << (so % 3) + 1<<endl;
	}
}


Measured memory_bytes: 3072
import sys
sys.setrecursionlimit(10**6)
input = sys.stdin.readline

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

path = [[] for _ in range(n)]
for i in range(n-1):
    a,b = map(int,input().split())
    path[a-1].append(b-1)
    path[b-1].append(a-1)

X = [0]*n
for i in range(q):
    p,x = map(int,input().split())
    X[p-1] += x


ans = [0]*n

def dfs(f,cnt):
    ans[f] += cnt + X[f]
    for nxt in path[f]:
        if reached[nxt] : continue
        reached[nxt] = True
        dfs(nxt,cnt + X[f])
    return

reached = [True] + [False]*(n-1)
dfs(0,0)

print(' '.join(str(i) for i in ans))


Measured memory_bytes: 247156
#include <cstdio>
#include <algorithm>
using namespace std;
int n;
int arr[17][17];
long long bmask[400005];
int main(){
    scanf("%d",&n);
    for (int x=0;x<n;x++){
        for (int y=0;y<n;y++){
            scanf("%d",&arr[x][y]);
        }
    }

    for (int x=0;x<(1<<n);x++){ ///O(2^n n^2)
        for (int i=0;i<n;i++){
            for (int j=i+1;j<n;j++){
                if (((1<<i)&x)==0 || ((1<<j)&x)==0) continue;
                bmask[x]+=arr[i][j];
            }
        }
    }

    for (int x=0;x<(1<<n);x++){
        for (int s=x;s;s=(s-1)&x){
            bmask[x]=max(bmask[x],bmask[s]+bmask[s^x]);
        }
    }

    printf("%lld\n",bmask[(1<<n)-1]);
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;

int a[200010], cnt[200010];

int main() {
    ios_base::sync_with_stdio(0);
    int n; cin >> n;
    for (int i=0;i<n;i++) {
        cin >> a[i];
        cnt[a[i]]++;
    }

    ll ans = 0;
    for (int i=1;i<=n;i++) ans += 1LL*cnt[i]*(cnt[i]-1)/2LL;

    for (int i=0;i<n;i++) cout << ans-cnt[a[i]]+1 << endl;
}


Measured memory_bytes: 5204
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using ld=long double;
using st=string;
using ch=char;
typedef pair<ll,ll> P;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<P> vP;
typedef vector<ch> vc;
typedef vector<vc> vvc;
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,n) FOR(i,0,n)
#define ROF(i,a,b) for(ll i=a;i>=b;i--)
#define per(i,a) ROF(i,a,0)
const ll MOD=1000000007;
const ll MOD2=998244353;
const ld PI=acos(-1);
const ll INF=1e18;
st abc="abcdefghijklmnopqrstuvwxyz";
st ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
struct edge{ll to,cost;};

int main() {
  ll N;
  cin >> N;
  vP p(N);
  rep(i,N){
    ll x,y;
    cin >> x >> y;
    p[i].first=x+y;
    p[i].second=y;
  }
  sort(p.begin(),p.end());
  reverse(p.begin(),p.end());
  ll ans=0;
  rep(i,N){
    if(i%2==0){
      ans+=p[i].first-p[i].second;
    }
    else{
      ans-=p[i].second;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 1792
#include <iostream>
#include <algorithm>
#include <complex>
#include <utility>
#include <vector>
#include <string>
#include <queue>
#include <tuple>
#include <cmath>
#include <bitset>
#include <cctype>
#include <set>
#include <map>
#include <numeric>
#include <functional>
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(ll i=ll(a);i<ll(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define PRINT(V) cout << V << "\n"
#define SORT(V) sort((V).begin(),(V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())
using namespace std;
using ll = long long;
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; }
inline void Yes(bool condition){ if(condition) PRINT("Yes"); else PRINT("No"); }
template<class itr> void cins(itr first,itr last){
    for (auto i = first;i != last;i++){
        cin >> (*i);
    }
}
template<class itr> void array_output(itr start,itr goal){
    string ans = "",k = " ";
    for (auto i = start;i != goal;i++) ans += to_string(*i)+k;
    if (!ans.empty()) ans.pop_back();
    PRINT(ans);
}
ll gcd(ll a, ll b) {
    return a ? gcd(b%a,a) : b;
}
const ll INF = 1e15;
const ll MOD = 1000000007;
typedef pair<ll,ll> P;
const ll MAX = 400010;
constexpr ll nx[8] = {1,0,-1,0,-1,-1,1,1};
constexpr ll ny[8] = {0,1,0,-1,-1,1,-1,1};
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,m;
    cin >> n >> m;
    PRINT((n-1)*(m-1));
}


Measured memory_bytes: 256
use std::io;


#[allow(dead_code)]
fn read<T>() -> Vec<T>
where T:
    std::str::FromStr,
    T::Err: std::fmt::Debug {

    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.split(' ')
        .map(|s| s.trim().parse().unwrap())
        .collect()
}

#[allow(dead_code)]
fn read_one<T>() -> T
where T:
    std::str::FromStr,
    T::Err: std::fmt::Debug {

    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.trim().parse().unwrap()
}

fn main() {

    let n = read_one::<isize>();
    let mut a = read::<f64>();

    a.sort_by(|a, b| a.partial_cmp(b).unwrap());

    let mut b = a.clone();
    let x = a[(n - 1) as usize];
    let half :f64= x / 2f64;
    b.sort_by(|a, b| {
        (half - a).abs().partial_cmp(&(half - b).abs()).unwrap()
    });

    println!("{} {}", x, b[0]);
}

Measured memory_bytes: 6396
import java.io.BufferedInputStream;
import java.util.Arrays;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        //System.setIn(Main.class.getResourceAsStream("input"));
        // max + min - 2 < 0
        Scanner sc = new Scanner(new BufferedInputStream(System.in));
        long n = sc.nextLong();
        long a = sc.nextLong();
        long b = sc.nextLong();
        long max = Math.max(a,b);
        long min = Math.min(a,b);
        long res;
        if ((max - min) % 2 == 0) res = (max - min) / 2;
        else {
            long tmp = min - 1;
            long res1 = tmp + 1 + (max-1-tmp)/2;

            tmp = n - max;
            long res2 = tmp + 1 + (n-(tmp+min+1))/2;
            res = Math.min(res1, res2);
        }
        System.out.println(res);
    }
    static long pgcd(long a, long b) {
        if(b == 0) return a;
        return pgcd(b, a%b);
    }
    private static int nextInt(Scanner sc) {
        return Integer.valueOf(sc.nextLine());
    }
    private static int[] toArray(String text) {
        return Arrays.stream(text.split("\\s")).mapToInt(Integer::valueOf).toArray();
    }

}

Measured memory_bytes: 25044
#include <stdio.h>

void chmin(int *a, int b){
  if(*a > b) *a = b;
}

int main(void){
  int H, W;
  scanf("%d%d", &H, &W);

  int c[10][10];
  for (int i = 0; i < 10; i++) {
    for (int j = 0; j < 10; j++) {
      scanf("%d", &c[i][j]);
    }
  }

  for (int k = 0; k < 10; k++) {
    for (int i = 0; i < 10; i++) {
      for (int j = 0; j < 10; j++) {
        chmin(&c[i][j], c[i][k]+c[k][j]);
      }
    }
  }

  int a;
  int ans = 0;
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      scanf("%d", &a);
      if(a == -1) continue;
      ans += c[a][1];
    }
  }

  printf("%d\n", ans);

  return 0;
}

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

int main() {
  int flag = 1;
  string S;
  cin >> S;
  
  for(int i=0; i<S.size(); i++) {
    if(i%2==0) {
      if(S[i]=='L') {
        flag = 0;
        break;
      }
    } else {
      if(S[i]=='R') {
        flag = 0;
        break;
      }
    }
  }
  
  if(flag==0) {
    cout << "No" << endl;
  } else {
    cout << "Yes" << endl;
  }
  
 return 0;
}

Measured memory_bytes: 256
s = input()
n = len(s)

for i in range(n//2):
    if s[i] != s[-i-1]:
        print('No')
        exit()
s_ = s[:(n-1)//2]
for i in range(len(s_)//2):
    if s_[i] != s[-i-1]:
        print('No')
        exit()
s__ = s[(n+3)//2-1:]
for i in range(len(s__)//2):
    if s__[i] != s[-i-1]:
        print('No')
        exit()
print('Yes')

Measured memory_bytes: 3064