akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <iostream>
using namespace std;

bool exor(bool a, bool b) {
    return a != b;
}

int encode[128];
char decode[4] = "SW";
char ans[101010];

int N;
string S;

int main() {
    encode[(int)'S'] = 0; encode[(int)'W'] = 1;

    cin >> N >> S;

    for (int j = 0; j < 2; ++j) {
        for (int k = 0; k < 2; ++k) {
            ans[0] = (j == 0) ? 'S' : 'W';
            ans[1] = (k == 0) ? 'S' : 'W';

            for (int l = 2; l < N; ++l) {
                if (exor(S[l-1] == 'o', ans[l-1] != 'S')) {
                    ans[l] = ans[l-2];
                } else {
                    ans[l] = decode[1-encode[(int)ans[l-2]]];
                }
            }

            char a0 = exor(S[N-1] == 'o', ans[N-1] != 'S') ?
                        ans[N-2] : decode[1-encode[(int)ans[N-2]]];
            if (a0 != ans[0]) { continue; }

            char a1 = exor(S[0] == 'o', ans[0] != 'S') ?
                        ans[N-1] : decode[1-encode[(int)ans[N-1]]];
            if (a1 != ans[1]) { continue; }
            cout << ans << endl;
            return 0;
        }
    }
    cout << "-1" << endl;

    return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
#define INF 100000000
#define rep(i,a,b) for(int (i)=a;(i)<(int)(b);(i)++)

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

    cout <<2*N*3.14159265  << endl;
}

Measured memory_bytes: 3772
x,n=map(int,input().split())
import sys
if n==0:
    _=input()
    print(x)
    sys.exit()
    
p_list=list(map(int,input().split()))
r=list(range(102))
a=list(set(r)-set(p_list))
ans=100000
kkk=100000
for i in a:
    tem=abs(i-x)
    if ans>tem:
        ans=tem
        kkk=i
    
print(kkk)

Measured memory_bytes: 9212
#include<iostream>
#include<string>
#include<cstring>
using namespace std;
int main()
	{
int C=0,F=0;
string li;
cin>>li;
int l=li.size();
for(int j=0;j<=l-1;j++)
	{
	if(li[j]!='C'&&li[j]!='F')
	{
		li[j]='0';
	}
	else
	{
		if(li[j]=='C')
		{
			C=1;
		}
		else
		{
			if(C==1)
			{	
				F=1;
				//cout<<"Yes"<<endl;
				//return 0;
			}
		}
	}
	}
	if(F==1&&C==1)
	{
		cout<<"Yes"<<endl;
		return 0;
	}
	cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vb=vector<bool>;
using vvb=vector<vb>;
using vd=vector<double>;
using vvd=vector<vd>;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pll=pair<ll,ll>;
using tll=tuple<ll,ll>;
using tlll=tuple<ll,ll,ll>;
using vs=vector<string>;
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rep(i,n) range(i,0,n)
#define rrep(i,n) for(ll i=(n)-1;i>=0;i--)
#define range(i,a,n) for(ll i=(a);i<(n);i++)
#define LINF ((ll)1ll<<60)
#define INF ((int)1<<30)
#define EPS (1e-9)
#define MOD (1000000007ll)
#define fcout(a) cout<<setprecision(a)<<fixed
#define fs first
#define sc second
#define PI (3.1415926535897932384)

int dx[]={1,0,-1,0,1,-1,-1,1},dy[]={0,1,0,-1,1,1,-1,-1};
template<class T>bool chmax(T&a,T b){if(a<b){a=b; return true;}return false;}
template<class T>bool chmin(T&a,T b){if(a>b){a=b; return true;}return false;}
template<class S>S sum(vector<S>&a){return accumulate(all(a),S());}
template<class S>S max(vector<S>&a){return *max_element(all(a));}
template<class S>S min(vector<S>&a){return *min_element(all(a));}
ll max(int a,ll b){return max((ll)a,b);} ll max(ll a,int b){return max(a,(ll)b);}

template<class T>void puta(T&&t){cout<<t<<"\n";}
template<class H,class...T>void puta(H&&h,T&&...t){cout<<h<<' ';puta(t...);}
template<class S,class T>void tf(bool b,S t,T f){if(b)puta(t);else puta(f);}
void YN(bool b){tf(b,"YES","NO");}
void Yn(bool b){tf(b,"Yes","No");}
void yn(bool b){tf(b,"yes","no");}
template<class S,class T>ostream&operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class S>auto&operator<<(ostream&os,vector<S>t){bool a=1;for(auto s:t){os<<(a?"":" ")<<s;a=0;}return os;}
template<class S>auto&operator>>(istream&is,vector<S>&t){for(S&a:t)cin>>a;return is;}

/*他のライブラリを入れる場所*/


int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n,k;
	string s;
	cin>>n>>k>>s;
	s[k-1]+=('a'-'A');

	puta(s);
	return 0;
}

Measured memory_bytes: 256
import math
import sys
sys.setrecursionlimit(10 ** 6 + 10)
from collections import defaultdict

from math import factorial

def combinations_count(n, r):
    return factorial(n) // (factorial(n - r) * factorial(r))

def permutations_count(n, r):
    return math.factorial(n) // math.factorial(n - r)



def main():
    mod = 10 ** 9 + 7
    high, width, num = map(int, input().split())
    toori = combinations_count(high * width - 2, num - 2)

    kyori = high + width - 2

    ans = 0
    for now_kyori in range(1, kyori + 1):
        kari = 0
        if now_kyori < high:
            kari += width * width * (high - now_kyori)
        if now_kyori < width:
            kari += high * high * (width - now_kyori)
        ans += now_kyori * kari

        if now_kyori >= high and now_kyori >= width:
            break

    ans = ans * toori % mod

    print(ans)



if __name__ == '__main__':
    main()


Measured memory_bytes: 74588
/*
[keyence2019] E - Connecting Cities
*/

#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;

typedef pair<ll, pii> edge;

const int MAX_N = 2e5;
const pli INF = {1e18, -1};

template <typename T>
class RMQ {
public:
    int n;
    vector<T> dat;
    void init(int _n) {
        n = 1;
        while (n < _n) {
            n <<= 1;
        }
        dat.reserve(2 * n - 1);
        fill(dat.begin(), dat.end(), INF);
    }
    void update(int k, T a) {
        k += n - 1;
        dat[k] = a;
        while (k > 0) {
            k = (k - 1) / 2;
            dat[k] = min(dat[k * 2 + 1], dat[k * 2 + 2]);
        }
    }
    T query(int a, int b) { return query(a, b, 0, 0, n); }

private:
    T query(int a, int b, int k, int l, int r) {  // [a, b), [l, r)
        if (r <= a || b <= l) {
            return INF;
        }
        if (a <= l && r <= b) {
            return dat[k];
        }
        return min(query(a, b, k * 2 + 1, l, (l + r) / 2),
                   query(a, b, k * 2 + 2, (l + r) / 2, r));
    }
};

class UnionFind {
public:
    vector<int> data;
    UnionFind(int size) : data(size, -1) {}
    bool unite(int x, int y) {
        x = root(x);
        y = root(y);
        if (x == y) {
            return false;
        }
        if (data[y] < data[x]) {
            swap(x, y);
        }
        data[x] += data[y];
        data[y] = x;

        return true;
    }
    bool same(int x, int y) { return root(x) == root(y); }
    int root(int x) { return data[x] < 0 ? x : (data[x] = root(data[x])); }
    int size(int x) { return -data[root(x)]; }
};

int N;
ll D;
ll A[MAX_N];
RMQ<pli> tl, tr;

ll solve() {
    vector<pli> ais;
    tl.init(N);
    tr.init(N);
    for (int i = 0; i < N; i++) {
        ais.push_back({A[i], i});
        tl.update(i, {A[i] - i * D, i});
        tr.update(i, {A[i] + i * D, i});
    }
    sort(ais.begin(), ais.end(), greater<pli>());

    vector<edge> q;
    for (auto& ai : ais) {
        int i = ai.second;
        pli ci = tl.query(0, i);
        if (ci != INF) {
            edge e = {ci.first + A[i] + i * D, {ci.second, i}};
            q.push_back(e);
        }
        ci = tr.query(i + 1, N);
        if (ci != INF) {
            edge e = {ci.first + A[i] - i * D, {ci.second, i}};
            q.push_back(e);
        }
        tl.update(i, INF);
        tr.update(i, INF);
    }
    sort(q.begin(), q.end());

    ll ans = 0;
    UnionFind uf(N);
    for (auto& e : q) {
        int u = e.second.first, v = e.second.second;
        if (!uf.same(u, v)) {
            ans += e.first;
            uf.unite(u, v);
        }
    }

    return ans;
}

int main() {
    cin >> N >> D;
    for (int i = 0; i < N; i++) {
        cin >> A[i];
    }

    cout << solve() << endl;

    return 0;
}


Measured memory_bytes: 31084
int main(){while(1){int n,m,i,j,a,b,x[501]={},c[501][501]={},num[501]={},sum=0;scanf("%d%d",&n,&m); if(n==0)break; for(i=1;i<=m;i++){scanf("%d %d",&a,&b); if(a==1){num[b]++;}c[a][b]=1;c[b][a]=1;}for(i=1;i<=n;i++){for(j=1;j<=n;j++){if(c[1][i]==1 && c[i][j]==1){num[j]++;}}}for(i=2;i<=n;i++){if(num[i]!=0) sum++;}printf("%d\n",sum);}return 0;}

Measured memory_bytes: 1588
#include <bits/stdc++.h>
#include <iostream>
#include <string>
#include <limits.h>
#include <algorithm>
#include <iomanip>
using namespace std;

int main(){
  int S, W,  ans = 0 ;
  cin >> S >> W ;
  if(S <= W){
    cout << "unsafe" << endl ;
  }  
  else{
    cout << "safe" << endl ;
  }  
  return 0 ;
}  

Measured memory_bytes: 3636
#include<iostream>
#include<algorithm>
#include<cstdlib>
#include<cstdio>
#include<cmath>
using namespace std;

#define Max_n  1000

int main(){
    int n, wt, wy;
    int size_t, size_y;
    int count = 0;

    cin >> n >> wt >> wy;

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

        cin >> size_t >> size_y;
        if(size_t / wt == 0 || size_y / wy == 0){
            //
        } else {
            if(size_t / wt == size_y / wy){
                count += size_t / wt;
            } else {
                count += min(size_t / wt, size_y / wy);
            }
        }
    }

    printf("%d", count);
    
    return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace abc54
{
    class Program
    {
        static void Main(string[] args){
            var inp = ScanInt;
            int a = p(inp[0]);
            int b = p(inp[1]);
            if (a > b)
            {
                Console.WriteLine("Alice");
            }else if (a == b)
            {
                Console.WriteLine("Draw");
            }
            else
            {
                Console.WriteLine("Bob");
            }
            
        }
        static int p(int a)
        {
            return (a == 1) ? 14 : a;
        }
        static int[] ScanInt {
            get {
                return Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
            }
        }
        static string[] Scan {
            get {
                return Console.ReadLine().Split(' ');
            }
        }
    }
}


Measured memory_bytes: 11092
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <iostream>
#include <istream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <tuple>
#include <iomanip>
#include <climits>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
//typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < (n); i++)
#define revrep(i, n) for(ll i = (n)-1; i >= 0; i--)
#define pb push_back
#define f first
#define s second
#define chmin(x, y) x = min(x, y);
#define chmax(x, y) x = max(x, y);

//const ll INFL = LLONG_MAX;//10^18 = 2^60
const ll INFL = 1LL<<60;
//const int INF = INT_MAX;
const ll INF = 1 << 30;//10^9
ll MOD = 1000000007;
//ll MOD = 998244353;

vector<ll> dy = {0, 1, 0, -1, 1, 1, -1, -1, 0};
vector<ll> dx = {1, 0, -1, 0, 1, -1, 1, -1, 0};

void pres(double A, ll x = 20){cout << fixed << setprecision(x) << A << endl;}
void BinarySay(ll x, ll y = 60){rep(i, y) cout << (x>>(y-1-i) & 1); cout << endl;}
ll cnt_bit(ll x){return __builtin_popcountll(x);}

ll pow_long(ll x, ll k){
  ll res = 1;
  while(k > 0){
    if(k % 2) res *= x;
    x *= x; k /= 2;
  }
  return res;
}

ll pow_mod(ll x, ll k){
  ll res = 1;
  while(k > 0){
    if(k % 2){
      res *= x; res %= MOD;
    }
    x *= x; x %= MOD;
    k /= 2;
  }
  return res;
}

ll inverse(ll x){return pow_mod(x, MOD - 2);};

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

ll lcm(ll x, ll y){
  ll res = x / gcd(x, y);
  res *= y;
  return res;
};


/*
//コンビネーション
const int MAXcomb = 200010;
ll fac[MAXcomb], finv[MAXcomb], inv[MAXcomb];
//facはn!,finvは1/n!
//invは逆元
void COMinit(){
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for(int i = 2; i < MAXcomb; i++){
        fac[i] = fac[i-1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD/i) % MOD;
        finv[i] = finv[i-1] * inv[i] % MOD;
    }
}
ll comb(int n, int k){
    if(n < k) return 0;
    if(n < 0 || k < 0) return 0;
    return fac[n] * finv[k] % MOD * finv[n-k] % MOD;
}

const int MAXkai = 200010;
ll kai_memo[MAXkai];
ll kai(ll N){
  if(kai_memo[N] != 0) return kai_memo[N];
  if(N <= 1) return 1;
  return kai_memo[N] = N * kai(N-1) % MOD;
}
*/


void solve(){
  ll N, K;
  cin >> N >> K;
  vector<ll> p(N);
  rep(i, N) cin >> p[i];
  double tmp = 0;
  double ans = 0;
  rep(i, K){
    tmp += 1.0 * (p[i] + 1) / 2;
  }
  ans = tmp;
  rep(i, N-K){
    tmp += 1.0 * (p[i+K] + 1) / 2;
    tmp -= 1.0 * (p[i] + 1) / 2;
    ans = max(ans, tmp);
  }
  pres(ans);
}


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


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

int main(){

  ll n,a,b;
  
  ll ans;
  
  
  cin >> n >> a >> b;
  
  if(a+b == 0){
    cout << 0 << endl;
    return 0;
  }
  
  ll m = n / (a+b);
  ans = m * a ;  
  
  if((n - m * (a+b)) >= a){
    ans += a;
  }else{
    ans += (n - m * (a+b));
  }
  
  cout << ans <<  endl;
  
    return 0;
}


Measured memory_bytes: 256
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

def main():
  n=I()
  l=LI()

  l2=copy.deepcopy(l)
  l2.sort()

  c=0
  l3=[]
  l4=[]
  for i in range(n):
    if l[i]!=l2[i]:
      c+=1
      l3.append(l[i])
      l4.append(l2[i])

  if c==0:
    return 'YES'
  l3.sort()
  l4.sort()
  if c==2 and l3==l4:
    return 'YES'
  return 'NO'

# main()
print(main())


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

using namespace std;

#define endl "\n"
#define lln long long int
#define IOS ios::sync_with_stdio(0);cin.tie(0);

const int MOD = 1e9 + 7;

int main(){
	IOS;

	int n;
	cin >> n;
	lln nine = 1, ten = 1,eig = 1;
	for(int i=0;i<n;i++){
		ten = (ten * 10) % MOD;
		nine = (nine * 9) % MOD;
		eig = (eig * 8) % MOD;
	}
	lln val = (ten -2*nine + eig) % MOD;
	cout << (val + MOD) % MOD << endl;
	return 0;    
}


Measured memory_bytes: 3588
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
typedef long long ll;
//a-k +-(b-k)
//a-+b k-+k
int main(void) {
    int a, b; cin >> a >> b;
    if((a+b)%2==1){
        cout << "IMPOSSIBLE";
    }else{
        cout << (a+b)/2;
    }
    return 0;
}


Measured memory_bytes: 256
def s0():return input()
def s1():return input().split()
def s2(n):return [input() for x in range(n)]
def s3(n):return [input().split() for _ in range(n)]
def s4(n):return [[x for x in s] for s in s2(n)]
def n0():return int(input())
def n1():return [int(x) for x in input().split()]
def n2(n):return [int(input()) for _ in range(n)]
def n3(n):return [[int(x) for x in input().split()] for _ in range(n)]
def t3(n):return [tuple(int(x) for x in input().split()) for _ in range(n)]
def p0(b,yes="Yes",no="No"): print(yes if b else no)
# from sys import setrecursionlimit
# setrecursionlimit(1000000)
# from collections import Counter,deque,defaultdict
# import itertools
# import math
# import networkx as nx
# from bisect import bisect_left,bisect_right
# from heapq import heapify,heappush,heappop
n=n0()
AB=n3(n)
AB.sort(key=lambda x:x[1])

time=0
f=True
for a,b in AB:
    time+=a
    if time<=b:
        pass
    else:
        f=False
        break
p0(f)

Measured memory_bytes: 88152
// D - FT Robot
#include <bits/stdc++.h>
using namespace std;

int main(){
	string S; int X,Y; cin>>S>>X>>Y; S += "T";
	vector<int> dx,dy;
	int d = 0;
	for(auto s:S) if(s=='F') d++; else{ (dx.size()==dy.size()? dx:dy).push_back(d); d = 0; }
	sort(dx.rbegin(), dx.rend());
	sort(dy.rbegin(), dy.rend());
	int x = dx.back(), y = 0;
	dx.erase(dx.end()-1);
	for(auto d:dx) x += d * (x<X? 1:-1);
	for(auto d:dy) y += d * (y<Y? 1:-1);
	cout<<(x==X && y==Y? "Yes":"No")<<endl;
}

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

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

if ((a * b) % 2==0) {
  cout << "Even" << endl;
}

else if ((a * b) % 2==1) {
  cout << "Odd" << endl;
}
}

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



using namespace std;

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


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

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



int main(void){

	int K,S; scanf("%d %d", &K, &S);

	int ans = 0;
	REP(x,K+1){
		REP(y,K+1){
			int z = S - ( x + y );
			if(0 <= z and z <= K) ans++;
		}
	}

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

	return 0;

}


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

int main()
{
  int n, m, c;
  cin >> n >> m >> c;
  vector<int> a(m), b(m), x(m);
  for (int i = 0; i < m; i++) cin >> b[i];
  int ans = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) cin >> a[j];
    if (inner_product(begin(a), end(a), begin(b), c) > 0) ans++;
  }
  cout << ans << endl;
}


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

int main(){
  int n,m,p,q[15],a;
  while(cin>>n>>m,n||m){
    for(int i=0;i<3;++i){
      cin>>p;
      while(p--){
	cin>>a;
	q[a-1]=i;
      }
    }
    a=0;p=0;
    for(int i=0;i<n;++i){
      if(q[i]==1){
	a+=pow(3,n-i-1);p=(p==0)?2:(p==1)?1:0;
      }
      else if(q[i]!=p){
	a+=2*pow(3,n-i-1);
      }
    }
    a=min(a,(int)pow(3,n)-1-a);
    cout<<((m>=a)?a:-1)<<endl;
  }
  return 0;
}

Measured memory_bytes: 1200
#ifndef BZ
#pragma GCC optimize "-O3"
#endif
#include <bits/stdc++.h>

#define FASTIO
#define ALL(v) (v).begin(), (v).end()
#define rep(i, l, r) for (int i = (l); i < (r); ++i)

#ifdef FASTIO
#define scanf abacaba
#define printf abacaba
#endif

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

using namespace std;


/*
ll pw(ll a, ll b) {
	ll ans = 1; while (b) {
		while (!(b & 1)) b >>= 1, a = (a * a) % MOD;
		ans = (ans * a) % MOD, --b;
	} return ans;
}
*/

const int MAXN = 120000;

int n, m;

int p[MAXN];

int ass[MAXN];
ll s[MAXN];
vector<tuple<ll, int, int>> ed;

int get(int a) {
	if (p[a] == a)
		return a;
	return p[a] = get(p[a]);
}

int main() {
#ifdef FASTIO
	ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
#endif
	cin >> n >> m;
	for (int i = 0; i < n; ++i) {
		p[i] = i;
		cin >> s[i];
		ass[i] = 0;
	}
	for (int i = 0; i < m; ++i) {
		int a, b;
		ll y;
		cin >> a >> b >> y;
		--a, --b;
		ed.emplace_back(y, a, b);
	}
	sort(ALL(ed));
	for (auto e: ed) {
		int a, b;
		ll y;
		tie(y, a, b) = e;
		a = get(a), b = get(b);
		if (a == b) {
			if (s[a] < y)
				++ass[a];
		}
		else {
			p[a] = b;
			s[b] += s[a];
			ass[b] += ass[a];
			if (s[b] >= y)
				ass[b] = 0;
			else
				ass[b] += 1;
		}
	}
	for (int i = 0; i < n; ++i) {
		if (p[i] == i) {
			cout << ass[i] << "\n";
			return 0;
		}
	}
	return 0;
}




Measured memory_bytes: 4084
function main(input) {
  var x = 0;
  for (i = 0; i < input.length; i++)
    {
      if (input[i] == 1)
      {
        x += 1;
      }
      else continue;
    }
  console.log(x);
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 7372
#include<iostream>
using namespace std;
string s="";
int main(){
	int n,d;
	cin >> n;
	if(n==0)
		s="0";
	while(n){
		d=n;
		if(d<0){
			d=-d;
		}
		if(d%2==1){
			s='1'+s;
			if(n<0){
				n=(d+1)/2;
			}
			else{
				n=-(d-1)/2;
			}
		}
		else{
			s='0'+s;
			if(n<0){
				n=d/2;
			}
			else{
				n=-d/2;
			}
		}
	}
	cout << s << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
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<int MOD> struct ModInt {
    static const int Mod = MOD; unsigned x; ModInt() : x(0) { }
    ModInt(signed sig) { x = sig < 0 ? sig % MOD + MOD : sig % MOD; }
    ModInt(signed long long sig) { x = sig < 0 ? sig % MOD + MOD : sig % MOD; }
    int get() const { return (int)x; }
    ModInt &operator+=(ModInt that) { if ((x += that.x) >= MOD) x -= MOD; return *this; }
    ModInt &operator-=(ModInt that) { if ((x += MOD - that.x) >= MOD) x -= MOD; return *this; }
    ModInt &operator*=(ModInt that) { x = (unsigned long long)x * that.x % MOD; return *this; }
    ModInt &operator/=(ModInt that) { return *this *= that.inverse(); }
    ModInt operator+(ModInt that) const { return ModInt(*this) += that; }
    ModInt operator-(ModInt that) const { return ModInt(*this) -= that; }
    ModInt operator*(ModInt that) const { return ModInt(*this) *= that; }
    ModInt operator/(ModInt that) const { return ModInt(*this) /= that; }
    ModInt inverse() const { long long a = x, b = MOD, u = 1, v = 0;
        while (b) { long long t = a / b; a -= t * b; std::swap(a, b); u -= t * v; std::swap(u, v); }
        return ModInt(u); }
    bool operator==(ModInt that) const { return x == that.x; }
    bool operator!=(ModInt that) const { return x != that.x; }
    ModInt operator-() const { ModInt t; t.x = x == 0 ? 0 : Mod - x; return t; }
};
template<int MOD> ostream& operator<<(ostream& st, const ModInt<MOD> a) { st << a.get(); return st; };
template<int MOD> ModInt<MOD> operator^(ModInt<MOD> a, unsigned long long k) {
    ModInt<MOD> r = 1; while (k) { if (k & 1) r *= a; a *= a; k >>= 1; } return r; }
typedef ModInt<1000000007> mint;
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     @hamayanhamayan0
　　　　／　　　＼　 　  |　|
　　　 /　　 /￣￣￣￣/　　|
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿
　 　　　＼/＿＿＿＿/　（u　⊃
---------------------------------------------------------------------------------------------------*/














int N, K;
//---------------------------------------------------------------------------------------------------
void _main() {
    cin >> N >> K;

    mint ans = 0;
    rep(k, K, N + 2) {
        mint mi = (mint(0) + mint(k - 1)) * k / 2;
        mint ma = (mint(N) + mint(N - k + 1)) * k / 2;
        ans += ma - mi + 1;
    }
    cout << ans << endl;
}







Measured memory_bytes: 3640
#include<iostream>
#include<string>
#include<queue>
#include<cstring>
#include<set>
using namespace std;

//I¹Èç1ðÔ·
int samechar(string str);

//¯¶àÌª©Â©Á½ç1AÝÂ©ÈçÈ©Á½ç0ðÔ·
int samecheck(string str);

//strÌ[chari_1]Æ[chari_2]ÌFðÏ»³¹é
string exchange(string str, int chari_1, int chari_2);

set<string> samecheckset;

int main(){
	string input;
	while(cin >>input){
		if(input[0] == '0') break;
		
		samecheckset.clear();
		
		//cnt = oÍ·é¦([³) endflag = I¹ðª©Â©Á½ç1
		int cnt = 0, endflag = 0;
		
		//qu1 = ¡Ì[³Ìg qu2 = Ì[³Ìg
		queue<string> qu1, qu2;
		qu1.push(input);
		qu2.push("temp");
		while(!qu2.empty()){
			while(!qu2.empty()){
				qu2.pop();
			}
			while(!qu1.empty()){
				string temp = qu1.front();
				qu1.pop();
				
				//I¹ð¾Á½çbreak
				if(samechar(temp) == 1){
					endflag = 1;
					break;
				}
				
				//¯¶àÌªsamechecksetÉ©Â©Á½çcontinue
				if(samecheck(temp) == 1){
					continue;
				}
				
				//temp©çÏ»·é·×ÄÌFÌp^[ÌÂ\«ðqu2Éüêé
				for(int i = 0; i < temp.size() - 1; i++){
					if(temp[i] != temp[i + 1]){
						qu2.push(exchange(temp, i, i + 1));
					}
				}
			}
			
			if(endflag == 1){
				break;
			}
			
			//Ì[³ÉÚéÌÅAqu2Ìgð·×Äqu1ÉÚ·
			qu1 = qu2;
			
			//[³(b)ð1Ââ·
			cnt++;
		}
		if(endflag == 0){
			cout <<"NA" <<endl;
		} else{
			cout <<cnt <<endl;
		}
	}
}

string exchange(string str, int chari_1, int chari_2){
	if(str[chari_1] != 'r' && str[chari_2] != 'r'){
		str[chari_1] = 'r';
		str[chari_2] = 'r';
	} else if(str[chari_1] != 'g' && str[chari_2] != 'g'){
		str[chari_1] = 'g';
		str[chari_2] = 'g';
	} else if(str[chari_1] != 'b' && str[chari_2] != 'b'){
		str[chari_1] = 'b';
		str[chari_2] = 'b';
	}
	return str;
}

int samechar(string str){
	int ans = 1;
	char temp = str[0];
	for(int i = 1; i < str.size(); i++){
		if(temp != str[i]){
			ans = 0;
		}
	}
	return ans;
}

int samecheck(string str){
	if(samecheckset.find(str) == samecheckset.end()){
		samecheckset.insert(str);
		return 0;
	} else{
		return 1;
	}
}

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

int main(void) {
    int K; cin >> K;
    int A,B;cin>>A>>B;
    for (int i = A; i <= B; i++) {
        if (i % K == 0) {
            cout << "OK" << endl;
            return 0;
        }
    }
    cout << "NG" << endl;
    return 0;
}

Measured memory_bytes: 3128
// Package main provides
//
// File:  b.go
// Author: ymiyamoto
//
// Created on Thu Jan  3 15:38:27 2019
//
package main

import "fmt"

func main() {
	var A, B int
	var s string

	fmt.Scan(&A, &B, &s)

	for i := 0; i < A; i++ {
		if !('0' <= s[i] && s[i] <= '9') {
			fmt.Println("No")
			return
		}
	}

	if s[A] != '-' {
		fmt.Println("No")
		return
	}

	for i := A + 1; i < len(s); i++ {
		if !('0' <= s[i] && s[i] <= '9') {
			fmt.Println("No")
			return
		}
	}

	fmt.Println("Yes")
}


Measured memory_bytes: 512
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
 
using namespace std;
 
#define PB push_back
#define MP make_pairA
#define REP(i,n) for(int i=0;i<(n);i++)
int main()
{
    int r;
    cin>>r;
    cout<<r*r*3<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
template <class T>
inline bool chmax(T &a, T b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
inline bool chmin(T &a, T b)
{
    if (a > b)
    {
        a = b;
        return 1;
    }
    return 0;
}
typedef long long int ll;

#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define endl "\n"
const double EPS = 1e-7;
const int INF = 1 << 30;
const ll LLINF = 1LL << 60;
const double PI = acos(-1);
const int MOD = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

//-------------------------------------

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n;
    cin >> n;
    ll ans = LLINF;
    for (ll i = 1; i * i <= n; i++)
    {
        if (n % i == 0)
        {
            ll a = i;
            ll b = n / i;
            chmin(ans, a + b - 2);
        }
    }
    cout << ans << endl;
}

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

int main(){
    int n,m; cin >> n >> m;
    vector<int> h(n);
    vector<bool> ok(n,true);
    rep(i,n) cin >> h[i];
    vector<vector<int>> g(n);
    rep(i,m){
        int a,b; cin >> a >> b;
        a--;b--;
        if(h[a]>h[b]) ok[b] = false;
        else if(h[a]<h[b]) ok[a] = false;
        else {
            ok[a] = false;
            ok[b] = false;
        }
    }
    int ans = 0;
    rep(i,n) if(ok[i]) ans ++;
    cout << ans << endl;
}

Measured memory_bytes: 5900
#include <vector>
#include <bits/stdc++.h>
#include <iomanip>
#include <stdio.h>
using namespace std;

int main(){
    string a; cin >> a;
    int ans = 0;
    double n;
    if(a.size()%2 == 0){
        n = a.size()/2;
    }
    else{
        n = a.size()/2 + 1;
    }
    int j = n;
    for( int i = 0;i < j; i++){
        if(a[i] != a[a.size()-(1+i)]){
            ans++;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
const int dic[] = {0,100,1,2,3,4,5,6,7,8,9,10,11,12};
int main(){
	int a, b;
	scanf("%d%d", &a, &b);
	int res = dic[a] - dic[b];
	if(res){
		if(res>0){
			printf("Alice");
		}else printf("Bob");
	}else{
		printf("Draw");
	}
	printf("\n");
	return 0;
}

Measured memory_bytes: 128
#include <cstdio>
#include <vector>
#include <stack>
#include <iostream>
#include <string>
#include <tuple>
#include <random>
#include <map>
#include <queue>
#include <set>
#include <complex>
#include <algorithm>
#include <cassert>
#include <iterator>
#include <numeric>
#include <cmath>
#include <stdio.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> T;

const double eps = 1e-8;

const ll INF = 1e15;
const ll MOD = 1e9 + 7;

int main() {
	ll N;
	cin >> N;
	vector<ll> Aa(N);
	for (int i = 0;i < N;i++) {
		cin >> Aa[i];
	}
	vector<ll> A = Aa;
	A.push_back(INF);
	vector<ll> rans(N+1);
	vector<ll> rne(N + 1);
	for (int i = N - 1;i >= 0;i--) {
		if (A[i] <= A[i + 1] || i == N - 1) {
			rans[i] = rans[i + 1];
			if (A[i] * 4 <= A[i + 1])
				rne[i] = i;
			else
				rne[i] = rne[i + 1];
		}else {
			rans[i] = rans[i + 1];
			ll cnt = 0;
			ll temp = A[i + 1];
			while (A[i] > temp) {
				cnt += 2;
				temp <<= 2LL;
				rans[i] += 2 * (rne[i + 1] - i);
				A[rne[i + 1]] <<= 2;
				if (!(A[rne[i + 1]] * 4 <= A[rne[i + 1] + 1] || rne[i + 1] + 1 == N))
					rne[i + 1] = rne[rne[i + 1] + 1];
			}
			rne[i] = rne[i + 1];
		}
	}
	reverse(Aa.begin(), Aa.end());
	A = Aa;
	A.push_back(INF);
	vector<ll> lans(N + 1);
	vector<ll> lne(N + 1);
	for (int i = N - 1;i >= 0;i--) {
		if (A[i] <= A[i + 1] || i == N - 1) {
			lans[i] = lans[i + 1];
			if (A[i] * 4 <= A[i + 1])
				lne[i] = i;
			else
				lne[i] = lne[i + 1];
		}
		else {
			lans[i] = lans[i + 1];
			ll cnt = 0;
			ll temp = A[i + 1];
			while (A[i] > temp) {
				cnt += 2;
				temp <<= 2LL;
				lans[i] += 2 * (lne[i + 1] - i);
				A[lne[i + 1]] <<= 2;
				if (!(A[lne[i + 1]] * 4 <= A[lne[i + 1] + 1] || lne[i + 1] + 1 == N))
					lne[i + 1] = lne[lne[i + 1] + 1];
			}
			lne[i] = lne[i + 1];
		}
	}
	ll answer = INF;
	for (int i = 0;i < N;i++) {
		answer = min(answer, i + lans[N-i-1] + rans[i]);
	}
	cout << answer << endl;
	return 0;
}


Measured memory_bytes: 10980
N, M, X = map(int, input().split())
I = [list(map(int, input().split())) for i in range(N)]
C = [0] * N
A = [[0] * M] * N
for i in range(N):
    C[i] = I[i][0]
    A[i] = I[i][1:]
ans = -1
anslist = []

for i in range(2**N):
    flag = 0
    c = 0
    total = [0] * M
    for j in range(N):
        if ((i >> j) & 1):
            c += C[j]
            for k in range(M):
                total[k] += A[j][k]
    for k in range(M):
        if total[k] < X:
            flag = 1
            break
    if flag == 1:
        continue
    anslist.append(c)

if len(anslist) != 0:
    anslist.sort()
    ans = anslist[0]

print(ans)

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

// int/long:		-2,147,483,648 - 2,147,483,648 (-2^31 <= int < 2^31)
// long/long long:	-9,223,372,036,854,775,808 - 9,223,372,036,854,775,807 (-2^63 <= long < 2^63)

#define	INF (1<<29)
//536,870,912

// lower_bound(A.begin(), A.end(), N)
// upper_bound(...

// A.erase(unique(A.begin(), A.end()), A.end())

// bit: &/and, |/or, ^/xor, ~/not

// getline(cin, String)

// Graph
// Warshall-Floyd: Distance between each node, N^3
// Dijkstra: Distance from the start node, N^2
// DFS(Depth-First Search)

#define	MOD 1000000007

long 	f(long n) {
	if(n<10)
		return n;
	long NN=10000000000000000;
	while(NN>n)
		NN /=10;
	long N1=n/NN;
	long N2=n%NN;
	long S=max(N1+f(N2), N1-1+f(NN-1));
	return S;
}


int	main() {
	long N;
	cin >>N;
	cout << f(N) <<endl;
	return 0;
}



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

using namespace std;

int main() {
    int K;
    int input;
    vector<int> a;
    for(int i = 0; i < 5; i++)
    {
        cin >> input;
        a.push_back(input);
    }
    cin >> K;
    
    string ans = "Yay!";
    for(int i = 0; i < a.size(); i++)
    {
        for (int j = 0; j < a.size(); j++)
        {
            int dist = abs(a[i] - a[j]);
            if (dist > K) {
                ans = ":(";
            }
        }
    }
    cout << ans << endl;
}

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

using namespace std;

#define REP(i,n) for(ll (i) = (0); (i) < (n); ++i)
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define ALL(v) v.begin(),v.end()
#define Decimal fixed << setprecision(20)
#define SHOWP(x) cerr<<"["<<(x).FI<<", "<<(x).SE<<"]";
#define SHOWX(x) cerr<<#x<<": "<<x<<endl;
#define SHOWVEC(v, e) REP(i, e) cerr << (v[i]) << ' '; cerr << endl;
#define SHOW2D(a, h, w) REP(i, h){REP(j, w)cerr<<setw(3)<<(a[i][j])<<' ';cerr<<endl;}
constexpr int INF = 1 << 30 - 1;
constexpr long long LLINF = 1LL << 60;
constexpr long long MOD = 1000000007;

typedef long long ll;
typedef pair<ll, ll> P;


int main()
{
  int A, B, C;
  cin >> A >> B >> C;
  if (A == B && B == C && C == A) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const double pi = 3.141592654;

void solve()
{
    ll n;
    cin>>n;
    ll arr[n+1];
    deque<ll>q;

    for(int i=0; i<n; i++)
    {
        cin>>arr[i];
        if(i%2==0)
            q.push_back(arr[i]);
        else
            q.push_front(arr[i]);
    }
    if(n%2 !=0)
        reverse(q.begin(),q.end());
    for(int i=0;i<n;i++)
        cout<<q[i]<<" ";


}

int main()
{
    ios_base :: sync_with_stdio(false);
    ll t,i=1;
    //cin>>t;
    t=1;
    while(t--)
    {
        solve();
    }
}


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

int main() {
  int D, N;
  cin >> D >> N;
  if(N == 100) {
    if(D == 2) cout << 1010000 << endl;
    else {
      N++;
      cout << pow(100, D)*N << endl;
    }
  }
  else cout << pow(100, D)*N << endl;
}

Measured memory_bytes: 384
package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
	"strconv"
)

var (
	readString func() string
	stdout     *bufio.Writer
)

func init() {
	readString = newReadString(os.Stdin)
	stdout = bufio.NewWriter(os.Stdout)
}

func newReadString(ior io.Reader) func() string {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)

	return func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
}

func readInt() int {
	return int(readInt64())
}

func readInt64() int64 {
	i, err := strconv.ParseInt(readString(), 0, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

func readIntSlice(n int) []int {
	b := make([]int, n)
	for i := 0; i < n; i++ {
		b[i] = readInt()
	}
	return b
}

func readLengthAndSlice() (int, []int) {
	n := readInt()
	return n, readIntSlice(n)
}

func printf(f string, args ...interface{}) (int, error) {
	return fmt.Fprintf(stdout, f, args...)
}

func println(args ...interface{}) (int, error) {
	return fmt.Fprintln(stdout, args...)
}

func eprintln(args ...interface{}) (int, error) {
	return fmt.Fprintln(os.Stderr, args...)
}

func eprintf(f string, args ...interface{}) (int, error) {
	return fmt.Fprintf(os.Stderr, f, args...)
}

// readString() string
// readInt() int
// readIntSlice(n int) []int
// readLengthAndSlice() []int

// -----------------------------------------------------------------------------

func main() {
	defer stdout.Flush()
	n := readInt()
	a := make([]int64, n)
	for i := range a {
		a[i] = readInt64()
	}
	m := make(map[int64]int64)
	var s int64 = 0
	m[s]++
	for i := range a {
		s = s + a[i]
		m[s]++
	}
	var ans int64
	for _, v := range m {
		if 1 < v {
			ans += v * (v - 1) / 2
		}
	}
	println(ans)
}

// -----------------------------------------------------------------------------


Measured memory_bytes: 14336
#include <stdio.h>

int main(void)
{
    float N;
    char c;
    
    
    scanf("%f%c", &N, &c);
    
    
    if((int)((int)(N*25/27)*27/25) == (int)N)
    {
        printf("%d\n", (int)(N*25/27));
    }
    else if((int)((int)(N*25/27+1)*27/25) == (int)N)
    {
        printf("%d\n", (int)(N*25/27+1));
    }
    else
    {
        printf(":(\n");
    }
    
    
    //system("pause");
    
    return 0;
}

Measured memory_bytes: 128
W,H,N= map(int,input().split())
Black = [[True for _ in range(W)] for i in range(H)]
for i in range(N):
    x,y,a = map(int,input().split())
    for j in range(H):
        for k in range(W):
            if a == 1:
                if k < x:
                    Black[j][k] = False
            elif a == 2:
                if k >= x:
                    Black[j][k] = False
            elif a == 3:
                if j < y:
                    Black[j][k] = False
            elif a == 4:
                if j >= y:
                    Black[j][k] = False
                    #print(Black)

c = 0
#print(Black)
for i in range(H):
    c += Black[i].count(True)
print(c)



                

Measured memory_bytes: 9276
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,b,c,d,i,j,s=0,ss=0,aa=0,aaa=0,cc,ccc;
    cin>>a;
    int sss[a];
    for(i=0; i<a; i++)
    {
        cin>>sss[i];
        s+=sss[i];
        ss++;
        d=(s/ss);
        c=d+1;
    }
    for(i=0; i<a; i++)
    {
        cc=sss[i]-d;
        aa+=pow(cc,2);
        ccc=sss[i]-c;
        aaa+=pow(ccc,2);
    }
    if(aa>aaa)
        cout<<aaa<<endl;
    else
        cout<<aa<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N, A, B;
  
  cin >> N >> A >> B;
  
  int C = N * A;
  
  if (C < B){
    cout << C << endl;
  }
  else{
    cout << B << endl;
  }
}

Measured memory_bytes: 256
N=int(input())
X=list(map(int,input().split()))

mn=10**18
#for p in range(min(X),max(X)+1):
for p in range(1,101):
    sm=0
    for x in X:
        sm+=((x-p)**2)
    #print(p,sm)
    mn=min(sm,mn)
print(mn)

Measured memory_bytes: 3060
from collections import deque


def nearlist(N, LIST):  # 隣接リスト
    NEAR = [{} for _ in range(N)]
    for a, b, c in LIST:
        NEAR[a - 1][b - 1] = c
        NEAR[b - 1][a - 1] = c
    return NEAR


def bfs(NEAR, S, N):  # 幅優先探索  # キュー
    DIST = [-1 for _ in range(N)]  # 前処理
    DIST[S] = 0
    que, frag = deque([S]), set([S])

    while len(que) > 0:
        q = que.popleft()
        for i, c in NEAR[q].items():  # 移動先の候補
            if i in frag:  # 処理済みか否か
                continue
            DIST[i] = DIST[q] + c
            que.append(i), frag.add(i)
    return DIST


n = int(input())
abc = [list(map(int, input().split())) for _ in range(n - 1)]
q, k = map(int, input().split())
xy = [list(map(int, input().split())) for _ in range(q)]

near = nearlist(n, abc)
dist = bfs(near, k - 1, n)
for x, y in xy:
    print(dist[x - 1] + dist[y - 1])


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

ll extGCD(ll a, ll b, ll &x, ll &y) {
    if (b == 0) {
        x = 1;
        y = 0;
        return a;
    }
    ll d = extGCD(b, a % b, y, x);
    y -= a / b * x;
    return d;
}

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

    ll a, b;
    cin >> a >> b;
    ll x, y;
    extGCD(a, b, x, y);
    cout << x << ' ' << y << endl;

    return 0;
}


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


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

    std::vector<int> abc(3);

    for(int i = 0;i<3;++i)
        std::cin >>abc[i];
    
    std::sort(abc.begin(),abc.end());

    if(abc[0] == 5 && abc[1] == 5 && abc[2] == 7)
        std::cout <<"YES\n" << std::endl ;
    else
        std::cout <<"NO\n" << std::endl ;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <math.h>
#include <cmath>
#include <limits.h>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <functional>
using namespace std;
 
 
int main() {
    
    bool ans = false;
    vector< vector<int> > edge;
    int N,M;
    cin >> N >> M;
    
    edge.resize(N);
    
    for ( int i = 0; i < M; i++ ) {
        int a,b;
        cin >> a >> b;
        a--;
        b--;
        edge[a].push_back(b);
        edge[b].push_back(a);
    }
    
    for ( int i = 0; i < N; i++ ) {
        
        bool x,y;
        x = y = false;
        for ( int j = 0; j < edge[i].size(); j++ ) {
            if (edge[i][j] == 0) { x = true; }
            if (edge[i][j] == N-1) { y= true; }
        }
        if ( x && y ) { ans = true; break;}
    }
    
    
    cout << (ans ? "POSSIBLE" : "IMPOSSIBLE" ) << endl;;
    
    return 0;
}

Measured memory_bytes: 12016
#include <iostream>
#include <vector>
#include <climits>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <string>
#include <bitset>
#include <utility>
#include <numeric>
#include <queue>
#include <stack>

using ll = long long;
using namespace std;

constexpr int MOD = 1e9 + 7;
constexpr ll MOD_LL = ll(1e9 + 7);

int main(void) {
	int n, a, b, c, d;
	string s;
	cin >> n >> a >> b >> c >> d >> s;
	a--; b--;
	c--; d--;
	
	auto can_reach = [&](int start, int goal) {
		for(int i = start; i < goal; ++i) {
			if( s[i] == '#' && s[i + 1] == '#' ) return false;
		}
	
		return true;
	};
	
	if( !can_reach(a, c) || !can_reach(b, d) ) {
		cout << "No" << endl;
		return 0;
	}
	
	if( c < d ) {
		cout << "Yes" << endl;
	} else if( c > d ) {
		bool threeDot = false;
		
		for(int i = b; i <= d; ++i) {
			if( s.substr(i - 1, 3) == "..." ) {
				threeDot = true;
			}
		}
	
		if( threeDot ) cout << "Yes" << endl;
		else cout << "No" << endl;
	}	
	
	return 0;
}


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

struct Candidate{
	int num;
};

int main(void) {
	for (;;) {
		int n, p;
		cin >> n >> p;
		if (n == 0 && p == 0)
			break;
		Candidate candidate[50];
		for (int i = 0; i < 50; i++) {
			candidate[i].num = 0;
		}
		
		int winner;
		int t = p;
		for (int i = 0; i <= 1000000; i=(i+1)%n) {
			if (p != 0) {
				candidate[i].num++;
				p--;
			}
			else if (p == 0) {
				p+=candidate[i].num;
				candidate[i].num = 0;
			}
			if (candidate[i].num == t) {
				winner = i;
				break;
			}
		}
		printf("%d\n", winner);
	}
	return 0;
}

Measured memory_bytes: 1144
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
int main(void){
  int n,i,price[11],max=0,sum=0;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&price[i]);
    if(price[i]>max) max=price[i];
    sum+=price[i];
  }
  sum-=max;
  printf("%d",sum+(max/2));
  return 0;
}

Measured memory_bytes: 128
#include<iostream>

using namespace std;

string dp[10009];
const string num[] = { "1","2","3","4","5","6","7","8","9" };
const int x[] = { 2,5,5,4,5,6,3,7,6 };
int a[10];

string comp(const string s, const string t) {
	if (s.size() != t.size()) {
		return s.size() > t.size() ? s : t;
	}
	return s > t ? s : t;
}

int main() {
	int n, m;
	cin >> n >> m;
	for (int i = 0; i < m; i++) {
		cin >> a[i];
		a[i]--;
	}
	fill(dp, dp + n + 1, "");
	for (int i = 1; i <= n; i++) {
		string ans = "";
		for (int j = 0; j < m; j++) {
			const int pre = i - x[a[j]];
			if (pre < 0||(pre!=0&&dp[pre]=="")) {
				continue;
			}
			
			const string tmp = num[a[j]] + dp[pre];
			ans = comp(ans, tmp);
		}
		dp[i] = ans;
	}
	/*for (int i = 0; i <= n; i++) {
		cout << i << "     " << dp[i] << endl;
	}*/
	cout << dp[n] << endl;
	return 0;
}

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

int main() {
  int N;
  cin >> N;
  
  long sum = 0;
  
  vector<int> A(N);
  for (int i = 0; i < N; i++){
    cin >> A.at(i);
  }
  
  int minus;
   for (int i = 0; i < N; i++){
     if(A.at(i) < 0){minus++;}
   }
  

    for (int i = 0; i < N; i++){
      if(A.at(i) < 0){ 
        sum -= A.at(i);
        A.at(i) = -A.at(i);
      } else { sum += A.at(i);}
    }

  if (minus % 2 == 0){
    cout << sum << endl;
  } else {
    int minA = min(A.at(0), A.at(1));
    for (int i = 0; i < N; i++){
      minA = min(minA, A.at(i));
    }
    cout << sum - 2*minA << endl;}
      
  
}
  
    

Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <queue>
#include <stack>
#include <tuple>
#include <cmath>
#include <iomanip>
#include <map>
#include <cstring>
#include <functional>
#include <cctype>
#include <locale>
#define ll long long
#define rep(i,n) for(int i=0;i<(n);i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define fi first
#define se second
#define pb push_back
#define ALL(a) (a).begin(),(a).end()
using namespace std;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
typedef pair<int,int> P;
typedef pair<long long,long long> Pll;
#define fout(num) cout << fixed << setprecision(20) << (num) << endl
//s[i]=tolower(s[i]); islower(s[i]); cout << tolower(s[i])はバグ
//vector<vector<ll>> dp(n,vector<ll>(n))
//2-dim:vector<vector<Type>> vv(n, vector<Type>(m, d));
//3-dim:vector<vector<vector<Type>>> vvv(n, vector<vector<Type>>(m, vector<Type>(l, d)));

signed main(){
    std::cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    int x; cin >> x;
    if(x==0) cout << 1 << endl;
    else cout << 0 << endl;
}




Measured memory_bytes: 3608
from operator import itemgetter
n,m = map(int,input().split())
a = list(map(int,input().split()))
a = sorted(a,reverse = True)
x = []
for _ in range(m):
    b,c = map(int,input().split())
    x.append([c,b])
x.sort(key = itemgetter(0),reverse = True)
i=0
j=0
#print(a,x)
s=0
p = 0
x1 = len(x)
while p<n:
    if (j == x1) or (a[i]>x[j][0]):
        s+=a[i]
        p+=1
        i+=1
    else:
        if (p + x[j][1]) > n:
            temp = n - p
            p+=temp
            s = s + x[j][0]*temp
        else:
            p = p + x[j][1]
            s = s + x[j][0]*x[j][1]
        #print(y)
        j+=1
print(s)

Measured memory_bytes: 25192
n = int(input())
ll = []
for i in range(n):
  x, l = map(int, input().split())
  ll.append([x-l, x+l])
ll = sorted(ll)

ans = n
r = ll.pop()[0]

while ll:
  while ll and ll[-1][1] > r:
    ans -= 1
    ll.pop()
  if ll:
    r = ll.pop()[0]

print(ans)

Measured memory_bytes: 20876
#[allow(unused_imports)]
use proconio::{fastout, input};

#[fastout]
fn main() {
    input!(n: usize, b: [usize; n - 1]);

    let mut sum = 0;
    for i in 1..n - 1 {
        sum += if b[i] > b[i - 1] { b[i - 1] } else { b[i] };
    }
    sum += b[0];
    sum += b[n - 2];

    println!("{}", sum);
}


Measured memory_bytes: 2184