akhauriyash/Code-Regression huggingface dataset:
S=input()
T=input()

def possible(S, T):
  for i in range(len(S) - len(T) + 1):
    s = S[i:i + len(T)]
    ok = True
    for j in range(len(T)):
      if s[j] != '?' and s[j] != T[j]:
        ok = False
    if ok:
      return True
  return False  

for i in range(len(S)):
  if S[i] == '?':
    found = False
    for c in 'abcdefghijklmnopqrstuvwxyz':
      s = S[:i] + c + S[i+1:]
      if possible(s, T):
        found = True
        S = s
        break
    if not found :
      print('UNRESTORABLE')
      break
else:
  print(S)


Measured memory_bytes: 3064
package main

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

var reader = bufio.NewReaderSize(os.Stdin, 1000000)
var writer = bufio.NewWriter(os.Stdout)
func NextLine() string {
  buffer := make([]byte, 0)
  for true {
    line, isPrefix, err := reader.ReadLine()
    if err != nil { panic(err) }
    buffer = append(buffer, line...)
    if !isPrefix { break }
  }
  return string(buffer)
}
func NextInt() int {
  n, _ := strconv.Atoi(NextLine())
  return n
}
func NextIntVec() []int {
  L := strings.Split(NextLine(), " ")
  N := make([]int, len(L))
  for i := range N {
    N[i], _ = strconv.Atoi(L[i])
  }
  return N
}
func Write(s interface{}) {
  fmt.Fprintln(writer, s)
}
func Output() {
  _ = writer.Flush()
}

func Grundy (T *[][]int, P *[]int, r int) int {
  if len((*T)[r]) < 2 { return 0 }
  G := 0
  for _, adj := range (*T)[r] {
    if adj == (*P)[r] { continue }
    G = G ^ (Grundy(T, P, adj) + 1)
  }
  return G
}

func Solve() {
  N := NextInt()
  T := make([][]int, N)
  for i := range T {
    T[i] = make([]int, 0)
  }
  for i := 1; i < N; i++ {
    XY := NextIntVec()
    x, y := XY[0] - 1, XY[1] - 1
    T[x] = append(T[x], y)
    T[y] = append(T[y], x)
  }
  P := make([]int, N)
  for i := range P {
    P[i] = -1
  }
  P[0] = N
  Q := make([]int, N)
  pos := 1
  for _, q := range Q {
    for _, adj := range T[q] {
      if 0 <= P[adj] { continue }
      P[adj] = q
      Q[pos] = adj
      pos++
    }
  }
  T[0] = append(T[0], N)
  ans := "Alice"
  if Grundy(&T, &P, 0) == 0 { ans = "Bob" }
  Write(ans)
  return
}

func main() {
  Solve()
  Output()
}

Measured memory_bytes: 43520
#include<stdio.h>
int main(void)
{
    int N,M,day[10000];
    scanf("%d%d",&N,&M);
    int left = N;
    for(int i=0;i<M;i++)
    {
        scanf("%d",&day[i]);
        left = left - day[i];
    }
    if(left<0)
    {
        printf("-1");
    }
    else
    {
        printf("%d",left);
    }
    

}

Measured memory_bytes: 1772
// Learn more about F# at http://fsharp.org

open System

[<EntryPoint>]
let main _argv =
    let input = stdin.ReadLine()
    let chars = input.ToCharArray(0, input.Length)
    
    let acgt = [|'A'; 'C'; 'T'; 'G'|]
    
    let createRes (chars: Char[]) =
        let last = chars.Length-1
        let rec loop res cnt index =
            if index > last then
                res
            else
                let newIndex = index + 1
                let newCnt = cnt |> fun i -> if Array.IndexOf(acgt, chars.[index]) >= 0 then i + 1 else 0
                let newRes = newCnt |> fun i ->if i > res then i else res
                loop newRes newCnt newIndex
        loop 0 0 0
    
    createRes chars
    |> printfn "%d"
    
    0 // return an integer exit code


Measured memory_bytes: 14040
#include<cstdio>
#include<algorithm>
using namespace std;
int a[200005];
long long sa[200005];
int main(void)
{
	int n,q,s,t,x,l,r,i,j;
	long long sum,psum,msum;
	scanf("%d %d %d %d",&n,&q,&s,&t);
	for(i=0;i<=n;i++){
		scanf("%d",&a[i]);
	}
	psum=0;
	msum=0;
	sa[0]=0;
	for(i=1;i<=n;i++){
		sa[i]=a[i]-a[i-1];
		if(sa[i]<0){
			msum+=sa[i];
		}
		else{
			psum+=sa[i];
		}
	}
	for(i=0;i<q;i++){
		scanf("%d %d %d",&l,&r,&x);
		if(sa[l]>=0){
			if(x+sa[l]>=0){
				psum+=x;
				sa[l]+=x;
			}
			else{
				psum-=sa[l];
				msum+=sa[l]+x;
				sa[l]+=x;
			}
		}
		else{
			if(x+sa[l]>=0){
				msum-=sa[l];
				psum+=sa[l]+x;
				sa[l]+=x;
			}
			else{
				msum+=x;
				sa[l]+=x;
			}
		}
		x=-x;
		if(r+1<=n){
			if(sa[r+1]>=0){
				if(x+sa[r+1]>=0){
					psum+=x;
					sa[r+1]+=x;
				}
				else{
					psum-=sa[r+1];
					msum+=sa[r+1]+x;
					sa[r+1]+=x;
				}
			}
			else{
				if(x+sa[r+1]>=0){
					msum-=sa[r+1];
					psum+=sa[r+1]+x;
					sa[r+1]+=x;
				}
				else{
					msum+=x;
					sa[r+1]+=x;
				}
			}
		}
		sum=-psum*s-msum*t;
		printf("%lld\n",sum);
	}
	return 0;
}
	


Measured memory_bytes: 5096
// これ賢い…(n回目) 自分で思いつけてもいい 自分の実力で実装できるし
// pdf
#include <bits/stdc++.h>
#define ll long long
#define rep(i,n) for(int i = 0; i < n; i++)
using namespace std;

int main() {
  int n;
  cin >> n;
  int a[100010];
  a[0] = 0;
  rep(i,n) cin >> a[i + 1];
  a[n + 1] = 0;
  int sum = 0;
  rep(i,n + 1) sum += abs(a[i + 1] - a[i]);
  for (int i = 1; i <= n; i++) {
    cout << sum  + abs(a[i + 1] - a[i - 1]) - abs(a[i] - a[i - 1]) - abs(a[i + 1] - a[i]) << endl;
  }
}

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

int gcd(int x, int y){
    if (x < y){
        int temp = x;
        x = y;
        y = temp;
    }
    if (x % y == 0){
        return y;
    } else {
        return gcd(y, x%y);
    }
}

int main(int argc, char const *argv[]) {
    int x,y;
    cin >> x >> y;
    cout << gcd(x,y) << endl;
    return 0;
}



Measured memory_bytes: 3100
until (n = gets.to_i).zero?
  h = {}
  
  n.times do
    c1, m1, s1, m2, s2, m3, s3, m4, s4 = gets.split.map(&:to_i)
    h[c1] = 60 * (m1 + m2 + m3 + m4) + s1 + s2 + s3 + s4
  end
  
  h = h.sort_by{ |k, v| v }
  
  puts h[0][0], h[1][0], h[-2][0]
end

Measured memory_bytes: 9528
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<queue>
#include<stack>
#include<cmath>

using namespace std;


int main() {
	long long N, A, B;
	cin >> N >> A >> B;
	long long AB = A + B;
	long long k = N / AB;
	long long l = min(A, N % AB);
	cout << k * A + l << endl;

	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <list>
#include <queue>
#include <set>
#include <stack>
#include <vector>
using namespace std;
typedef long long int ll;
#define rep(i, a, n) for (int i = (a); i < (n); i++)
#define repr(i, n, a) for (int i = (n)-1; i >= (a); i--)
#define each(it, v) for (auto(it) = (v).begin(); (it) != (v).end(); (it)++)
#define all(v) (v).begin(), (v).end()
#define vi vector<int>
#define vvi vector<vi>
#define vd vector<double>
#define vvd vector<vd>
#define co(x) cout << (x)
#define con(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
const double PI = 3.14159265;
const int MAXN = 1 << 15;
const ll LINF = 1LL << 60;
const int INF = 1 << 30;
#define Pr(a) (#a) << "=" << (a) << " "
#define pr(a) cout << Pr(a) << '\n'
///////////////////////////////////////////////////////////

int N;
vector<int> V;
deque<int> D;
list<int> L;

int main() {
  auto it = L.end(); 

  auto insert = [&](int x) {
    L.insert(it, x);
    it--;
  };

  auto move = [&](int d) {
    while (d > 0) d--, it++;
    while (d < 0) d++, it--;
  };

  auto erase = [&]() {
    auto tmp = it++;
    L.erase(tmp);
  };

  int q;
  cin >> q;
  while (q--) {
    int cmd;
    cin >> cmd;
    if (cmd == 0) {
      int x;
      cin >> x;
      insert(x);
    }
    if (cmd == 1) {
      int d;
      cin >> d;
      move(d);
    }
    if (cmd == 2) {
      erase();
    }
  }

  for (int l : L) cout << l << endl;
  return 0;
}


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

using namespace std;
using ll = long long;

int main(int argc, const char *argv[]) {
  int n;
  cin >> n;

  ll ans = 0;
  for (int i = 0; i < n; ++i) {
    ll l, r;
    cin >> l >> r;
    ans += (r - l + 1);
  }

  cout << ans << '\n';

  return 0;
}

Measured memory_bytes: 3568
#include <bits/stdc++.h>
using namespace std;using ll=long long;using uint=unsigned int;using pii=pair<int,int>;using pll=pair<ll,ll>;using ull = unsigned long long;using ld=long double;template<typename T>void _(const char*s,T h){cerr<<s<<" = "<<h<<"\n";}template<typename T,typename...Ts>void _(const char*s,T h,Ts...t){int b=0;while(((b+=*s=='(')-=*s==')')!=0||*s!=',')cerr<<*s++;cerr<<" = "<<h<<",";_(s+1,t...);}// break continue pop_back 998244353
// #define int ll
// #define pii pll
#define f first
#define s second
#define pb emplace_back
#define forn(i,n) for(int i=0;i<(n);++i)
#define sz(a)((int)(a).size())
#define sqr(x) ((x)*(x))
struct init{init(){cin.tie(0);iostream::sync_with_stdio(0);cout<<fixed<<setprecision(10);cerr<<fixed<<setprecision(5);}~init(){
#ifdef LOCAL
#define dbg(...) _(#__VA_ARGS__,__VA_ARGS__)
cerr<<"Time elapsed: "<<(double)clock()/CLOCKS_PER_SEC<<"s.\n";
#else
#define dbg(...) 
#endif
}}init;template<typename T,typename U>void upx(T&x,U y){if(x<y)x=y;}template<typename T,typename U>void upn(T&x,U y){if(x>y)x=y;}mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());const int D=4,dx[]={+1,0,-1,0},dy[]={0,+1,0,-1};
const int N=3e5+5,K=300;
int p[N],l[N],r[N],a[N];
int32_t main(){
    int n,m;
    cin>>n>>m;
    forn(i,n){
        cin>>l[i]>>r[i];
        int pl=N;
        for(int k=1;k<=N;++k){
            int cl=(l[i]+k-1)/k,cr=r[i]/k;
            if(cl<K){
                if(min(cr,pl-1)>=K-1){
                    p[K]++;
                    p[min(cr,pl-1)+1]--;
                }
                break;
            }
            p[cl]++;
            p[min(cr,pl-1)+1]--;
            pl=cl;
        }
        for(int j=1;j<K;++j){
            int x=(l[i]+j-1)/j;
            if(x*j<=r[i])a[j]++;
        }
    }
    int ans=p[0];
    for(int i=1;i<=m;++i){
        ans+=p[i];
        cout<<ans+a[i]<<'\n';
    }
    return 0;
}

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

template <typename _Tp> inline _Tp read(_Tp&x){
	char c11=getchar();x=0;while(!isdigit(c11))c11=getchar();
	while(isdigit(c11))x=x*10+c11-'0',c11=getchar();return x;
}

const int N=101000;
ll k[N],a[N],dx[N],n;
int q,top;

int main(){
	read(n),read(q);
	a[top=1]=n;
	for(int i=1;i<=q;++i){
		ll x;read(x);
		while(top&&a[top]>=x)--top;
		a[++top]=x;
	}k[top]=1;
	for(int i=top,id;i;--i){
		ll L=a[i],l;
		while(L>a[1]){
			id=upper_bound(a+1,a+i,L)-a-1;
			l=a[id],k[id]+=k[i]*(L/l),L%=l;
		}dx[L]+=k[i];
	}
	for(int i=n;i;--i)dx[i]+=dx[i+1];
	for(int i=1;i<=n;++i)printf("%lld\n",dx[i]);
	return 0;
}

Measured memory_bytes: 4096
import fileinput

for line in fileinput.input():
    tokens = list(map(int, line.strip().split()))
    W, H, x, y, r = tokens[0], tokens[1], tokens[2], tokens[3], tokens[4]

    flag = True
    if x - r < 0:
        flag = False
    if x + r > W:
        flag = False
    if y - r < 0:
        flag = False
    if y + r > H:
        flag = False

    if flag:
        print("Yes")
    else:
        print("No")

Measured memory_bytes: 7736
/**
 *    author:  otera    
**/
#include<iostream>
#include<string>
#include<cstdio>
#include<cstring>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<deque>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
using namespace std;

//#define int long long
typedef long long ll;
typedef unsigned long long ul;
typedef unsigned int ui;
typedef long double ld;
const int inf=1e9+7;
const ll INF=1LL<<60 ;
const ll mod=1e9+7 ;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<int, int> P;
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
#define fr first
#define sc second
#define all(c) c.begin(),c.end()
#define pb push_back
#define debug(x)  cerr << #x << " = " << (x) << endl;
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; }

int n, m;
vector<vector<int>> g;
vector<int> depth;
vector<int> deg;
deque<int> deq;

void dfs(int v, int d, bool left) {
    depth[v] = d;
    if(left) {
        deq.push_front(v);
    } else {
        deq.push_back(v);
    }
    if(deg[v] == 1) {
        return;
    }
    for(auto u: g[v]) {
        if(depth[u] == -1) {
            dfs(u, d + 1, left);
            return;
        }
    }
}

void solve() {
	cin >> n >> m;
    g.assign(n, vector<int>());
    depth.assign(n, -1);
    deg.assign(n, 0);
    rep(i, m) {
        int a, b; cin >> a >> b; --a; --b;
        g[a].pb(b);
        g[b].pb(a);
        deg[a] ++;
        deg[b] ++;
    }
    deq.push_back(0);
    depth[0] = 0;
    if(deg[0] == 1) {
        dfs(g[0][0], 1, true);
    } else {
        dfs(g[0][0], 1, true);
        for(auto u: g[0]) {
            if(depth[u] == -1) {
                dfs(u, 1, false);
                break;
            }
        }
    }
    cout << deq.size() << endl;
    for(auto u: deq) {
        cout << u + 1 << " ";
    }
    cout << endl;
}

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

Measured memory_bytes: 11776
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
using namespace std;

#define MAX 300001

typedef long long ll;

int main(){
  bool p[MAX];
  vector<ll> ms;
  int n;

  memset(p, true, sizeof(p));
  
  for(int i = 1 ; i < MAX ; i++){
    if(i % 7 == 1 || i % 7 == 6) ms.push_back(i);
  }
  
  for(ll i = 1 ; ms[i]*ms[i] < MAX ; i++){
    if(p[ms[i]]){
      for(ll j = ms[i]*ms[i] ; j < MAX ; j+=ms[i]){
	p[j] = false;
      }
    }
  }
  
  vector<ll> msp;

  for(int i = 1 ; i < ms.size() ; i++){
    if(p[ms[i]]) msp.push_back(ms[i]);
  }
  
  
  while(cin >> n){
    if(n == 1) break;
    
    printf("%d:", n);
    
    for(int i = 0 ; i < msp.size() ; i++){
      if(n % msp[i] == 0) cout << ' ' << msp[i];
    }
    cout << endl;
  }
  return 0;
}

Measured memory_bytes: 2316
n=int(input())
temp,a=map(int,input().split())
hs=map(int,input().split())

t=list(map(lambda h: temp-h*0.006, hs))
t=list(enumerate(t,1))

def solve(best,a,t):
    if not t:
        return best[0]
    if abs(best[1] - a) < abs(t[0][1] - a):
        return solve(best, a, t[1:])
    else:
        return solve(t[0],a,t[1:])

min_diff = 100000000
res = 0
for i in range(len(t)):
    if min_diff > abs(t[i][1] - a):
        min_diff = abs(t[i][1] - a)
        res = i + 1


print(res)


Measured memory_bytes: 3064
#include <iostream>
using namespace std;
int main(){
	char a,b;cin >> a >> b;
	if(a == 'H' && b == 'H'){
		cout << 'H' << endl;
	}else if(a == 'D' && b == 'D'){
		cout << 'H' << endl;
	}else{
		cout << 'D' << endl;
	}
}

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

using namespace std;
using ll = long long;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int ti = clock();
  // start-----------------------------------------------
  int n, m;
  while(cin >> n >> m && n && m){
    vector<int> unit_h(n), unit_w(m);
    for(int &i: unit_h) cin >> i;
    for(int &i: unit_w) cin >> i;
    vector<int> h, w;
    for(int i = 0; i < n; i++){
      int tmp = 0;
      for(int j = i; j < n; j++){
        tmp += unit_h[j];
        h.push_back(tmp);
      }
    }
    for(int i = 0; i < m; i++){
      int tmp = 0;
      for(int j = i; j < m; j++){
        tmp += unit_w[j];
        w.push_back(tmp);
      }
    }
    sort(h.begin(), h.end());
    sort(w.begin(), w.end());
    int ans = 0;
    for(int i = 0; i < h.size(); i++){
      auto it = lower_bound(w.begin(), w.end(), h[i]);
      while(it != w.end() && *it == h[i]){
        ans++;
        it++;
      }
    }
    cout << ans << endl;
  }

  // end-----------------------------------------------
  // cerr << 1.0 * (clock() - ti) / CLOCKS_PER_SEC << endl;
}



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

using namespace std;
int n;
long long k, a, b;
vector<pair<int, int>> parovi;
int mod = 998244353;
vector<int> faktorijele;

int add(int a, int b){
    a += b;
    if (a >= mod)return a-mod;
    else return a;
}
int sub(int a, int b){
    a-=b;
    if (a < 0){
        return a+mod;
    }else{
        return a;
    }
}
int mul(int a, int b){
    return ((long long)a*b)%mod;
}
int potenciranje(int b, int x){
    if(x == 0)return 1;
    if(x == 1)return b;
    int a = potenciranje(b, x/2);

    if (x%2==0)return mul(a, a) ;
    else return mul(mul(a, a), b);
}
int divi(int a, int b){
    return mul(a, potenciranje(b, mod-2));
}
void generejt(){
    int faktorijela = 1;
    faktorijele.push_back(1);
    for (int i = 1; i < 500000; ++i){
        faktorijela = mul(faktorijela, i);
        faktorijele.push_back(faktorijela);
    }
}
int main()
{
    generejt();
    cin >>n >>a >>b >>k;
    for (int i = 0; i <= n; ++i){
        long long umn = a*i;
        if (umn > k) break;
        if ((k-umn) % b == 0) {
            long long j = (k - umn) / b;
            if (j > n) continue;
            parovi.push_back({i, j});
        }
    }
    int sol = 0;
    for (int i = 0; i < parovi.size(); ++i){
        int pr = (divi(faktorijele[n], mul(faktorijele[parovi[i].first], faktorijele[n - parovi[i].first])));
        int dr = (divi(faktorijele[n], mul(faktorijele[parovi[i].second], faktorijele[n - parovi[i].second])));
        ///cout <<faktorijele[n] <<" " <<faktorijele[parovi[i].first] <<" " <<faktorijele[parovi[i].second] <<endl;
        ///cout <<parovi[i].first <<" " <<parovi[i].second <<" " <<pr <<" " <<dr <<endl;
        sol = add(sol, mul(pr, dr));
    }
//    for (int i = 0; i < 20; ++i)cout <<faktorijele[i] <<" ";
    /*
    cout <<endl;
    cout <<add(2, 2) <<endl;
    cout <<sub(5, 10)<<endl;
    cout <<mul(2, 2)<<endl;
    cout <<divi(8, 2)<<endl;
    cout <<potenciranje(2, mod-2) <<endl;
    */
    cout <<sol;
return 0;
}


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

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
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; }
const int INF = (1<<30) - 1;
const ll LINF = (1LL<<60) - 1;

int main(){
    int r;
    cin >> r;
    cout << fixed << setprecision(20) << 2 * r * acos(-1) << endl;
}

Measured memory_bytes: 3696
N = int(input())
S = input()

if N % 2 != 0:
  print('No')
else:
  T1 = S[:int(len(S)/2)]
  T2 = S[int(len(S)/2):]
  if T1 == T2:
    print('Yes')
  else:
    print('No')

     

Measured memory_bytes: 2940
/*
 AUTHOR : ANSHU BABU RAJPUT
 
    JAI MAA SARASWATI
    OM NAMAH SHIVAY
    JAI SHRI KRISHNA
    JAI SHRI RAM
    BHARAT MATA KI JAI

    #PKMKB	
    #CKMKB
*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

#define int  long long 
#define endl    ("\n")
#define ff       first
#define ss      second
#define pb   push_back
#define pf  push_front
#define ppb   pop_back
#define ppf  pop_front
#define mp   make_pair
#define mod 1000000007

#define L(x)    x.length()
#define B(x)     x.begin()
#define E(x)       x.end()
#define F(x)     x.front()
#define SZ(x)     x.size()
#define CLR(x)   x.clear()

#define all(x)                      x.begin(),x.end()
#define sortD(x) sort(x.begin(),x.end(),greater<int>)
#define rev(x)             reverse(x.begin(),x.end())

#define intV vector<int>

#define PI          (3.141592653589)
#define PMAX     priority_queue<int>
#define PMIN             priority_queue<int,vi,greater<int>>
#define setbits(x)                   __builtin_popcountll(x)
#define zrobits(x)                        __builtin_ctzll(x)

#define KING(i, n) for (int(i) = 0; (i) < n; (i)++)
#define MAHAKAL(i, n) for (int(i) = n-1; (i) >= 0; (i)--)

#define Anshu        int t; cin>>t; while(t--)
#define SITARAM(n,type) type* input=new type[n]

mt19937                          rng(chrono::steady_clock::now().time_since_epoch().count());
 
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;


void ViLiFY_KiNG()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    freopen("error.txt","w",stderr);
#endif
}
 
int32_t main()
{
    ViLiFY_KiNG();
    char ch;
    cin>>ch;

    int num = (int)ch;
    // cout<<num<<endl?;
    if(num < 95) {
        cout<<'A'<<endl;
    } else {
        cout<<'a'<<endl;
    }
    return 0;
}

Measured memory_bytes: 3548
#include <bits/stdc++.h>
using namespace std;typedef long long ll;typedef vector<ll> vl;typedef vector<vl> vvl;typedef pair<ll,ll> pl;typedef vector<pl> vp;const ll INF=1001001001;const ll LINF=1001001001001001001;const ll D4[]={0,1,0,-1,0};const ll D8[]={0,1,1,0,-1,-1,1,-1,0};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;}
#define fore(i,a,b) for(ll i=(ll)(a);i<=(ll)(b);++i)
#define rep(i,n) fore(i,0,(n)-1)
#define all(x) (x).begin(),(x).end()

template< typename T >
struct edge {
  int src, to;
  T cost;

  edge(int to, T cost) : src(-1), to(to), cost(cost) {}

  edge(int src, int to, T cost) : src(src), to(to), cost(cost) {}

  edge &operator=(const int &x) {
    to = x;
    return *this;
  }

  operator int() const { return to; }
};

template< typename T >
using Edges = vector< edge< T > >;
template< typename T >
using WeightedGraph = vector< Edges< T > >;
using UnWeightedGraph = vector< vector< int > >;
template< typename T >
using Matrix = vector< vector< T > >;

void solve(long long N, long long X, long long Y){
    UnWeightedGraph g(N);
    rep(i,N-1){
        g[i].push_back(i+1);
        g[i+1].push_back(i);
    }
    g[X-1].push_back(Y-1);
    g[Y-1].push_back(X-1);

    vl ans(N);
    rep(i,N){
        vl d(N,INF);
        d[i]=0;
        priority_queue<pl,vp,greater<>> q;
        q.emplace(0,i);
        while(q.size()){
            ll cost,to;
            tie(cost,to)=q.top();q.pop();
            if(d[to]<cost)continue;
            for(ll to2:g[to]){
                if(d[to2]<=d[to]+1)continue;
                d[to2]=d[to]+1;
                q.emplace(d[to2],to2);
            }
        }
        rep(i,N){
            ans[d[i]]++;
        }
    }
    rep(i,N){
        if(i==0)continue;
        cout<<ans[i]/2<<endl;
    }
}

int main(){
    long long N;
    scanf("%lld",&N);
    long long X;
    scanf("%lld",&X);
    long long Y;
    scanf("%lld",&Y);
    solve(N, X, Y);
}


Measured memory_bytes: 384
while True:
    H,W=map(int,input().split())
    if H==0 and W==0:
        break
    for i in range(H):
        for j in range(W):
            if i==0 or j==0 or j==W-1 or i==H-1:
                print("#",end="")
            else:
                print(".",end="")
        print()
    print()


Measured memory_bytes: 7000
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>

int main() {
    using namespace std;
    constexpr unsigned long maxN = 200010;
    unsigned long N;
    scanf("%lu", &N);
    array<unsigned long, maxN> perm;
    {
        array<pair<long, long>, maxN> p;
        for(unsigned long i = 0; i < N; ++i)scanf("%lu%lu", &p[i].first, &p[i].second);
        sort(p.begin(), p.begin() + N);
        for(unsigned long i = 0; i < N; ++i)p[i] = {p[i].second, i + 1};
        sort(p.begin(), p.begin() + N);
        transform(p.cbegin(), p.cbegin() + N, perm.begin(), [](auto i){return i.second;});
    }

    constexpr unsigned long MOD = 998244353;
    array<unsigned long, maxN> binary;
    unsigned long n = binary[0] = 1;
    generate(binary.begin() + 1, binary.end(), [&n](){if(n >= MOD)n -= MOD;return n <<= 1;});

    array<unsigned long, maxN> fenwick_tree{};
    auto que = [&fenwick_tree, &N](unsigned long i){
        unsigned long s{0}, j{i};
        while (i) { s += fenwick_tree[i]; i -= i & -i; }
        while (j <= N) { ++fenwick_tree[j]; j += j & -j; }
        return s;
    };

    array<unsigned long, maxN> coef{};
    coef[N] = N + MOD - 4;
    for(unsigned long i = 0; i != N; ++i){
        auto p = perm[i], q = que(p);
        ++coef[q];
        ++coef[i - q];
        ++coef[p - q - 1];
        ++coef[N - i - p + q];
    }

    cout << inner_product(binary.begin(), binary.begin() + N + 1, coef.begin(), 4 + MOD - N) % MOD << endl;
    return 0;
}

Measured memory_bytes: 8064
#include <iostream>
#include <iomanip>
#include <vector>
#include <cmath>

using namespace std;

int main(){
    double A, B, H, M;
    cin >> A >> B >> H >> M;

    double ans;

    //kakudo 
    double ang;
    ang = (30*H+ 0.5*M)-6*M;

    if(abs(ang) == 180){
        ans = A + B;
    }else if(ang == 0){
        ans = abs(A-B);
    }else{
        if( -360.0 < ang || ang <= (double)-180.0 ){
            ang += 360.0;
        }else if(-180.0 < ang || ang < 0.0 ){
            ang = abs(ang);
        }else if( 0.0 < ang || ang < 180.0){
            ang = abs(ang);
        }else{
            ang -= 180.0; 
        }


        double cosine = cos(ang * M_PI / 180.0);
        double tmp = (A*A)  + (B*B) - (2.0 * A * B * cosine);
        ans = sqrt(tmp);
    }


    cout << fixed << setprecision(10) << ans << endl;
}

Measured memory_bytes: 4164
#![allow(non_snake_case)]
#![allow(unused_variables)]
#![allow(dead_code)]

fn main() {
    let (K, S): (i64, i64) = {
        let mut line: String = String::new();
        std::io::stdin().read_line(&mut line).unwrap();
        let mut iter = line.split_whitespace();
        (
            iter.next().unwrap().parse().unwrap(),
            iter.next().unwrap().parse().unwrap()
        )
    };

    let ans = (0..(K + 1)).map(|x| (0..(K + 1)).filter(|&y| x + y <= S && x + y >= S - K).count()).sum::<usize>();

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

Measured memory_bytes: 4352
using System;

namespace A
{
    class Program
    {
        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());
            int A = int.Parse(Console.ReadLine());
            int modulo = N % 500;
            if(modulo <= A)
            {
                Console.WriteLine("Yes");
            }
            else
            {
                Console.WriteLine("No");
            }
        }
    }
}

Measured memory_bytes: 13140
N=int(input())
a=list(range(N+1))
b=list()
i=0
for i in range(N+1):
    if a[i]%3==0:
      b.append(0)
    elif a[i]%5==0:
      b.append(0)
      
    else:
      b.append(a[i])
print(sum(b))


Measured memory_bytes: 56356
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;
const int MOD = 1e9 + 7;

double nCr(const int n, int r) {
  if (n == 0) {
    return 0;
  }
  if (r == 0) {
    return 1;
  }
  if (r == 1) {
    return n;
  }
  if (n == r) {
    return 1;
  }

  if (r > n / 2) {
    r = n / 2;
  }

  double result = 1;
  for (double i = 1; i <= r; i++) {
    result *= (n - i + 1) / i;
  }

  return (result);
}

int main() {
  int n;
  cin >> n;
  map<string, int> bin;
  for (int i = 0; i < n; i++) {
    string s;
    cin >> s;
    sort(all(s));
    bin[s]++;
  }
  ll ans = 0;
  for (auto i = bin.begin(); i != bin.end(); i++) {
    if ((*i).second < 2) continue;
    ans += nCr((*i).second, 2);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 11136
#include <iostream>
#include <cstdio>

using namespace std;
typedef long long ll;

int main(){
    ll n;
    cin >> n;
    long double x = 0;
    for(int i = 0; i < n; ++i){
        long double a;
        cin >> a;
        x += 1.0 / a;
    }
    printf("%.06Lf\n", 1.0 / x);
    return 0;
}


Measured memory_bytes: 888
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
typedef long long ll;
typedef pair<int, int> P;
typedef pair<pair<int, int>, int> PP;
const ll INFL = 1LL << 60;
const ll MOD = 1000000007;
const int INF = INT_MAX;
const int MAX = 300000;
ll GCD(ll a, ll b) { return b ? GCD(b, a % b) : a; }
ll LCM(ll a, ll b) { return (a * b) / GCD(a, b); }
//------------------------------------------------------------------------------------------------------------------------------

int main(void) {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    ll N, K;
    cin >> N >> K;
    if (N > K) {
        N = N % K;
    }
    cout << min(N, K - N) << endl;
}

Measured memory_bytes: 256
# 1. priority_queue

import heapq

N = int(input())
cost = [1 << 60 for i in range(N + 1)]

que = [] ; cost[0] = 0
heapq.heappush(que, 0)

while len(que) != 0:
    elem = heapq.heappop(que)

    # 9
    for i in range(6):
        new_num = elem + 9 ** i
        if new_num <= N and cost[new_num] > cost[elem] + 1:
            cost[new_num] = cost[elem] + 1
            heapq.heappush(que, new_num)

    # 6
    for i in range(7):
        new_num = elem + 6 ** i
        if new_num <= N and cost[new_num] > cost[elem] + 1:
            cost[new_num] = cost[elem] + 1
            heapq.heappush(que, new_num)

ans = 1 << 60
for i in range(N + 1):
    ans = min(ans, cost[i] + (N - i))
print(ans)

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

int memo[1111];
int p[] = {500, 100, 50, 10, 5, 1};

int solve(int n){
  
  if(!n) return 0;
  if(n<0) return 1<<28;
  if(memo[n]) return memo[n];
  
  int ans = 1<<28;
  for(int i=0;i<6;i++) ans = min(ans, solve(n-p[i])+1);
  
  return memo[n] = ans;
}

int main(){

  int n;
  while(cin >> n, n) cout << solve(1000-n) << endl;
  
}

Measured memory_bytes: 1164
N = int(input())
h = [int(x) for x in input().split()]
cost = [0 for i in range(N)]
cost[1] = abs(h[1]-h[0])
for i in range(2,N):
    cost[i] = min(cost[i-1] + abs(h[i]-h[i-1]),cost[i-2]+abs(h[i]-h[i-2]))
print(cost[-1])

Measured memory_bytes: 13928
a,b=map(int,input().split())
for s in range(b//10000+1):
    try:
        for t in range(b//5000+1):
            r=a-s-t
            if r<0:
                break
            if 10000*s+5000*t+1000*r==b and s+t+r==a:
                print(s,t,r)
                exit()
    except ZeroDivisionError:
        continue
print(-1,-1,-1)

Measured memory_bytes: 3060
N = int(input())

def make_divisors(n):
    divisors = []
    # Nの最大の約数は√N
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
    return divisors

m = 10**12
divs = make_divisors(N)
for d1 in divs:
    d2 = N // d1
    m = min(m, d1+d2-2)
print(m)

Measured memory_bytes: 39280
import java.util.Scanner;

public class Main{
	public static void main(String[] args){
    Scanner sc= new Scanner(System.in);
    int A = sc.nextInt();
    int B = sc.nextInt();
    int c;
    int first;
    int second;
      
    if (B>=A){
     c=A;
     A=B;
     B=c;
    }
    first=A;
    A--;
      
    if (B>=A){
      c=A;
      A=B;
      B=c;
    }
      second=A;
      
      System.out.println(first+second);
      
    
    }
    }

Measured memory_bytes: 22868
count = 0
n = int(raw_input())
endA = 0
begB = 0
both = 0
for i in xrange(n):
    word = raw_input()
    for j in xrange(len(word)-1):
        if word[j] == "A" and word[j+1] == "B":
            count += 1
    if word[0] == "B" and word[len(word)-1] == "A":
        both += 1
    elif word[0] == "B":
        begB += 1
    elif word[len(word) - 1] == "A":
        endA += 1

if endA > 0 and both > 0:
    count += 1
    endA -= 1
if begB > 0 and both > 0:
    count += 1
    begB -= 1
if both > 0:
    count += both - 1
count += min(endA, begB)
print count

Measured memory_bytes: 2696
import sys
input = sys.stdin.readline

def main():
    N, x = map(int, input().split())
    a_list = list(map(int, input().split()))
    ans = 0
    for a in sorted(a_list):
        if a <= x:
            ans += 1
            x -= a
        else:
            break
    if x == 0 or ans != N:
        print(ans)
    else:
        print(max(ans - 1, 0))

if __name__ == '__main__':
    main()

Measured memory_bytes: 3060
#include <iostream>

using namespace std;

int main()
{
    int n; scanf("%d",&n);
    
    int a[n+1];
    for(int i=1; i<=n; i++) scanf("%d",&a[i]);
    
    int dp[n];
    
    dp[1] = 0;
    dp[2] = abs(a[2] - a[1]);
    
    for(int i=3; i<=n; i++){
        dp[i] = min(dp[i-1]+abs(a[i]-a[i-1]), dp[i-2]+abs(a[i]-a[i-2]));
    }
    printf("%d",dp[n]);
}

Measured memory_bytes: 1024
// Problem Code: abc176_e

#include <iostream>
#include <vector>
#include <set>
#include <algorithm>

using namespace std;

int bomber(int H, int W, int M, vector<int>& h, vector<int>& w) {
	int max_bombs, max_row, max_col;
	set<pair<int, int>> seen;
	vector<int> candidate_rows, candidate_cols, rows(H), cols(W);
	
	for (int i = 0; i < M; i++) {
		rows[h[i]]++;
		cols[w[i]]++;
		seen.emplace(h[i], w[i]);
	}
	
	max_row = *max_element(rows.begin(), rows.end());
	max_col = *max_element(cols.begin(), cols.end());
	max_bombs = max_row + max_col - 1;
	
	for (int i = 0; i < H; i++)
		if (rows[i] == max_row)
			candidate_rows.push_back(i);
	for (int i = 0; i < W; i++)
		if (cols[i] == max_col)
			candidate_cols.push_back(i);
	
	for (int& row: candidate_rows)
		for (int& col: candidate_cols)
			if (!seen.count({row, col}))
				return 1 + max_bombs;
	
	return max_bombs;
}

int main() {
	int H, W, M;
	cin >> H >> W >> M;
	vector<int> h(M), w(M);
	for (int i = 0; i < M; i++) {
		cin >> h[i] >> w[i];
		h[i]--, w[i]--;
	}
	cout << bomber(H, W, M, h, w);
	return 0;
}

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

import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7

N, x, y = MAP()
x -= 1; y -= 1
nodes = [[] for i in range(N)]
for i in range(N-1):
    a, b = MAP()
    a -= 1; b -= 1
    nodes[a].append(b)
    nodes[b].append(a)

memo  = [INF] * N
stack = [(y, 0, -1)]
while stack:
    u, cost, prev = stack.pop()
    if memo[u] != INF:
        continue
    memo[u] = cost
    for v in nodes[u]:
        if v == prev:
            continue
        stack.append((v, cost+1, u))
memo2  = [INF] * N
stack = [(x, 0, -1)]
while stack:
    u, cost, prev = stack.pop()
    if memo2[u] != INF:
        continue
    memo2[u] = cost
    if u == y:
        continue
    for v in nodes[u]:
        if v == prev:
            continue
        stack.append((v, cost+1, u))

mx = -INF
for i in range(N):
    if memo[i] >= memo2[i]:
        mx = max(mx, memo[i])
print(mx - 1)


Measured memory_bytes: 75064
import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val a = sc.nextInt()
    val b = sc.nextInt()
    val c = sc.nextInt()
    val d = sc.nextInt()
    println(if (Math.abs(c - a) <= d || Math.abs(b-a)<=d && Math.abs(c-b)<=d) "Yes" else "No")
}

Measured memory_bytes: 31392
n,a,b = map(int,input().split())

mod = 1000000007

def modpow(a,n,m):
    x = 1
    while n:
        if n%2: x *= a
        a *= a
        a %= m
        n //= 2
    return x

def nCr(n,r,m):
    a = b = 1
    for i in range(r):
        a *= n - i
        b *= r - i
        a %= m
        b %= m
    return a * modpow(b, m-2, m) % m

ans = modpow(2,n,mod) - 1
ans -= nCr(n,a,mod)
ans -= nCr(n,b,mod)
ans %= mod
if ans<0: ans += mod
print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int maxN = 1e3+7;
const int maxV = 90010;
//const int INF = 1e9+9;
//const ll INF = (1ll)<<60;
const int INF = 2e9+9;
const int MOD = 1e9+7;



int n,K;
int a[maxN];
int cost[maxN];
int main()
{
	scanf("%d%d",&n,&K);
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);
	}
	vector<int> tmp;
	int ans = 0;
	for(int L=0;L<=n;L++)
	{
		for(int R=0;R+L<=n;R++)
		{
			tmp.clear();
			if (L+R>K) continue;
			int sum = 0;
			for(int i=1;i<=L;i++)
			{
				tmp.push_back(a[i]);
				sum += a[i];
			}
			for(int i=n;i>=n-R+1;i--)
			{
				tmp.push_back(a[i]);
				sum += a[i];
			}
			int cnt = L+R;
			ans = max(ans,sum);
			if(cnt>=K) break;
			sort(tmp.begin(),tmp.end());
			for(auto y:tmp)
			{
				if(y<0)
				{
					sum -= y;
					ans = max(ans,sum);
					cnt++;
					if(cnt>=K)
						break;
				}
			}
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); 
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#define int long long
void test_case(){
	double x; cin>>x;
	if(x == 0){
		cout<<1<<endl;
	}
	else if(x == 1) cout<<0<<endl;
	
}
		
 
signed main(){
	IOS;
	int t=1, i=1; 
	//cin>>t;
	while(t--){
		//cout<<"Case #"<<i<<": ";
		test_case();
		i++;
	}
}


Measured memory_bytes: 3796
using System;

namespace a
{
    class Program
    {
        static void Main(string[] args)
        {
            var b = Console.ReadLine();

            if(b == "A")
            {
                Console.WriteLine("T");
            }
            if(b == "T")
            {
                Console.WriteLine("A");
            }

            if(b == "C")
            {
                Console.WriteLine("G");
            }

            if(b == "G")
            {
                Console.WriteLine("C");
            }
        }
    }
}


Measured memory_bytes: 11092
#include<cstdio>
int main(){
	int a,b,c,d,e,i;
	int n;
	while(~scanf("%d%d",&a,&b))
	{	d=0;e=1;
		for(i=0;i<a;i++)
		{
			scanf("%d",&n);
//			getchar();
	
			d+=n;
			if(d<=b)
			e+=1;
		}
		printf("%d\n",e);
	}
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<map>
#include<string>
#include<queue>
#include<stack>
#include<vector>
#include<list>
using namespace std;

int frequency = 0;

void bubbleSort(int A[],int N){
	bool flag = true;
	int i = 0;
	while (flag){
		flag = false;
		for (int j = N - 1; j >= i+1; j--){
			if (A[j] < A[j - 1]){
				swap(A[j], A[j - 1]);
				flag = true;
				frequency++;
			}
		}
		i++;
	}
}


int main(){
	int N;

	int A[100];

	cin >> N;

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

	for (int i = 0; i < N; i++){
		if (i<N-1) cout << A[i] << " ";
		else cout << A[i] << endl;
	}
	cout << frequency << endl;

	return 0;
}

Measured memory_bytes: 1160
// B - Resistors in Parallel
#include <bits/stdc++.h>
using namespace std;

int main(){
	int n; cin>>n;
	double a;
	for(int i=0; i<n; i++){
		double x;cin>>x;
		a += (double)1./x;
	}
	// printf("%lf\n",1./a);
	printf("%.16g\n",1./a);
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;

namespace AIDU {
    class AIDU0014
    {
        public static void Main(){
            List<int> ints=new List<int>();
            string s;
            int res,i,d;
            while(true) {
                s=Console.ReadLine();
                if(string.IsNullOrEmpty(s))
                    break;
                d=int.Parse(s);
                res=0;
                for(i=0;i<600;i+=d)
                    res+=i*i*d;
                ints.Add(res);
            }
            foreach(int res1 in ints)
                Console.WriteLine(res1);
            Console.ReadLine();
        }
    }
}

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


int main() {
    int N,D;
    cin>>N>>D;
    int sum;
    int count=0;
    vector<vector<int>>data(N,vector<int>(D));

    rep(i,N){
        rep(j,D) cin>>data[i][j];
    }

    for(int k=0;k<N-1;k++){
    for(int i=k+1;i<N;i++){
        sum=0;
        for(int j=0;j<D;j++){
            sum+=(data[i][j]-data[k][j])*(data[i][j]-data[k][j]);
        }
        for(int l=1;l<=sqrt(sum);l++){
            if(l*l==sum)count++;
        }
    }
}
cout<<count<<endl;
}

Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
using namespace std;
typedef long long int ll;
int main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	int n; cin >> n;
	vector<ll> l(n),r(n);
	for(int i=0;i<n;i++){
		cin >> l[i] >> r[i];
	}
	sort(l.begin(),l.end());
	reverse(l.begin(),l.end());
	sort(r.begin(),r.end());
	ll ans=0;
	ll sum=0;
	for(int i=0;i<n;i++){
		ans=max(ans,sum+2*max(l[i],-r[i]));
		sum+=2*(l[i]-r[i]);
		ans=max(ans,sum);
	}
	cout << ans << endl;
}

Measured memory_bytes: 1792
# O(N)
def is_not_empty(A):
    for x in A:
        if x:
            return True
    return False

def main():
    import sys
    input = sys.stdin.readline
    from collections import deque

    N = int(input())
    # 1-indexed
    A = [deque() for _ in range(N+1)]
    # O(N^2)
    for i in range(1,N+1):
        for j in input().split():
            A[i].append(int(j))

    # 当日の参加者
    today = set()
    # 初日
    for i in range(1,N+1):
        # 既に参加した人はダメ
        if i in today:
            continue
        enemy = A[i].popleft()
        ME = A[enemy].popleft()
        if ME == i and not(enemy in today):
            today.add(ME)
            today.add(enemy)
        else:
            A[i].appendleft(enemy)
            A[enemy].appendleft(ME)
    # 初日に誰も試合できなかったとき
    if not today:
        print(-1)
        exit()

    # 前日の参加者
    yesterday = today
    # 日数
    answer = 1
    while is_not_empty(A):
        today = set()
        # 前日に試合した人は必ず次の日に試合する
        for i in yesterday:
            if not A[i]:
                continue
            if i in today:
                continue
            enemy = A[i].popleft()
            ME = A[enemy].popleft()
            if ME == i and not(enemy in today):
                today.add(ME)
                today.add(enemy)
            else:
                A[i].appendleft(enemy)
                A[enemy].appendleft(ME)
        if not today:
            print(-1)
            exit()
        answer += 1
        yesterday = today

    print(answer)

if __name__ == '__main__':
    main()

Measured memory_bytes: 36168
#include <iostream>
using namespace std;
typedef long long unsigned int ll;
 
int main() {
 
  int a,b,c,d;
  cin >> a;
  cin >>b;
  c=0;
  d=0;
  if(a==2||b==2) {
	cout <<"No" <<endl;
    return 0;
  }
  if(a==4||a==6||a==9||a==11) c=1;
  if(b==4||b==6||b==9||b==11) d=1;
  if(c==d){
	cout <<"Yes" <<endl;
  }else{
	cout <<"No" <<endl;
    
  }
    return 0;
}


Measured memory_bytes: 256
from operator import itemgetter

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

i = max(enumerate(map(abs, A)), key=itemgetter(1))[0]
print(2*N)
if A[i]<0:
    print(i+1, N)
    print(i+1, N)
    for j in range(N, 1, -1) :
        print(j, j-1)
        print(j, j-1)
else :
    print(i+1, 1)
    print(i+1, 1)
    for j in range(1, N) :
        print(j, j+1)
        print(j, j+1)

Measured memory_bytes: 3064
#include <iostream>
#include <string>

using namespace std;

int main() {
    int h;
    int w;
    cin >> h >> w;
    string s;
    for (int i = 0; i < w + 2; i++){
        cout << "#";
    }
    cout << endl;
    for (int i = 0; i < h; i++){
        cin >> s;
        cout << "#" << s << "#" << endl;
    }

    for (int i = 0; i < w + 2; i++){
        cout << "#";
    }
    cout << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <iomanip>
#define ll long long
using namespace std;

int main()
{
  ll H, W;
  cin >> H >> W;
  if (H == 1 || W == 1)
  {
    cout << 1 << endl;
    return 0;
  }
  if (H % 2 == 0 || W % 2 == 0)
  {
    cout << H * W / 2 << endl;
    return 0;
  }
  else
  {
    cout << (H * W + 1) / 2 << endl;
    return 0;
  }
}


Measured memory_bytes: 256
//@@@@@@@@@@ JAI BAJRANG BALI @@@@@@@@@
/********** code by naman *******/

#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define maxn 10000001
#define endl "\n"
#define im INT_MAX
#define vec vector <ll>
#define mps map <ll,ll>
#define ppl vector<pair<ll,ll>> 
#define fi first
#define si second
#define pr pair<ll,ll> 
#define mvec map<ll,vector <ll>>
  
int main()
{
 
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n;
    cin>>n;
    ll sum=0;
    for(ll i=1;i<=n;i++)
    {
    	if(i%15==0 || i%3==0 ||i%5==0)
    		sum=sum+i;
    }

    ll ans=n*(n+1)/2-sum;
    cout<<ans<<endl;



return 0;
}


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

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

	ll l = 0, r = 0, sum = 0;
	ll ans = 0;
	while (l < N) {
		while (r < N && (sum^A[r]) == sum + A[r]) {
			sum ^= A[r];
			r++;
			ans++;
		}
		sum ^= A[l];
		l++;
		ans += r - l;
	}
	cout << ans << endl;
}

Measured memory_bytes: 1792
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <map>

long long GetDigit(long long num) {
    long long digit = 0;
    while (num != 0) {
        num /= 10;
        digit++;
    }
    return digit;
}

long long digit_sum(long long n) {
    if (n < 10)  return n;
    return digit_sum(n / 10) + n % 10;
}

int main() {
    std::string s; std::cin >> s;
    int t = s.size();
    int f = s[0] - '0';
    int ans = (f - 1) + (9 * (s.size() - 1));
    int ans2 = 0;
    for (int i = 0; i < s.size(); ++i)
        ans2 += s[i] - '0';
    std::cout << std::max(ans, ans2) << std::endl;

    return 0;
}

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

int main(void)
{
	char a,b;
	char boll = 'A';
	
	while(scanf("%c,%c", &a, &b) != EOF){
		if(a == boll) boll = b;
		else if(b == boll) boll = a;
	}
	
	printf("%c\n", boll);
}

Measured memory_bytes: 976
#include <bits/stdc++.h>
typedef long long int ll;
using namespace std;
int main ()
{
    string s,t;
    cin>>s>>t;
    ll dp[s.length()+1][t.length()+1];
    for(ll i = 0; i <= s.length(); i++)
    {
        for(ll j = 0; j <= t.length(); j++)
        {
            if(i == 0 || j == 0)
            {
                dp[i][j] = 0;
            }
            else if(s[i-1] == t[j-1])
            {
                dp[i][j] = 1 + dp[i-1][j-1];
            }
            else
            {
                dp[i][j] = max(dp[i-1][j],dp[i][j-1]);
            }
        }
    }
    //cout<<dp[s.length()][t.length()]<<endl;
    //backtracking to find the substring
    ll i = s.length();
    ll j = t.length();
    string s1 = "";
    while(i > 0 && j > 0)
    {
        if(s[i-1] == t[j-1])
        {
            s1 += s[i-1];
            i--;
            j--;
        }
        else if(dp[i-1][j] > dp[i][j-1])
        {
            i--;
        }
        else j--;
    }
    reverse(s1.begin(),s1.end());
    cout<<s1<<endl;
    return 0;
}

Measured memory_bytes: 70656
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(I,A,B) for(ll I = int(A); I < int(B); ++I)

int main(){
	ll n;
	cin >> n;
	vector<ll> a(n);
	FOR(i,0,n) cin>>a[i];
	ll q;
	cin >> q;
	FOR(i,0,q){
		ll b,e,t;
		cin >> b >> e >> t;
		FOR(k,0,e-b){
			swap(a[b+k],a[t+k]);
		}
	}
	cout << a[0];
	FOR(i,1,n){
		cout << " " << a[i];
	}
	cout << endl;
}


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

  return 0;
}

Measured memory_bytes: 1816
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1LL << 60;

int main() {
    int n;
    string s;
    cin >> n >> s;
    string ans = "Yes";
    if (n % 2) {
        ans = "No";
    }
    for (int i = 0; i * 2 < n; i++) {
        if (s[i] != s[n / 2 + i]) {
            ans = "No";
            break;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3608