akhauriyash/Code-Regression huggingface dataset:
N = int(input())
s =[str(input()) for _ in range(N)]
M = int(input())
t =[str(input()) for _ in range(M)]

l = list(set(s))


mx  = max(s.count(l[i])-t.count(l[i]) for i in range(len(l)))
print(max(0,mx))

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

int main(){
  int a,b,c,d;
  cin >>a>>b>>c>>d;
  
  if (a+b > c+d){
    cout << "Left"<<endl;
  }
  else if (a+b == c+d){
    cout << "Balanced" << endl;
  }
  else{
    cout << "Right" <<endl;
  }

}

Measured memory_bytes: 256
numbers = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
K = int(input())
print(numbers[K - 1])

Measured memory_bytes: 2940
from fractions import Fraction
from decimal import Decimal

n, k = input().split(" ")
n = int(n)
k = int(k)

ans = 0
for i in range(1, n + 1):
    j = i
    times = 0
    while j < k:
        j *= 2
        times += 1
    x = Fraction(1, n) * Fraction(1, 2 ** times)
    ans += x
print("{:.10f}".format(Decimal(ans.numerator) / Decimal(ans.denominator)))


Measured memory_bytes: 5340
#include<stdio.h>

int main(void){
	int i,s[131072] = {0},n,k,c = 0;
	scanf("%d",&n);
	for(i=1;i<=n;i++){
		scanf("%d",&s[i]);
	}
	for(i=1;i<=n;i++){
		if(i<s[i]){
			k = s[i];
			if(s[k] == i) c++;
		}
	}
	printf("%d",c);
	return 0;
}

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

namespace ABC114A
{
    class Program
    {
        static void Main(string[] args)
        {
            int x = int.Parse(Console.ReadLine());


            if (x == 3 || x == 5 || x == 7)
                Console.WriteLine("YES");

            else
                Console.WriteLine("NO");


            Console.ReadKey();
        }
    }
}


Measured memory_bytes: 11092
#include <bits/stdc++.h>
using namespace std;using ll=int_fast64_t;using ld=long double;using pll=pair<ll,ll>;using pld=pair<ld,ld>;
const ll INF=1LL<<60;void solve();int main(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(10);solve();}
#define foreach(i,a) for(auto &i:a)
#define SELECTOR(_1,_2,_3,_4,SELECT,...) SELECT
#define rep(...) SELECTOR(__VA_ARGS__,_rep2,_rep1,_rep0)(__VA_ARGS__)
#define _rep0(i,n) for(ll i=0;i<n;++i)
#define _rep1(i,k,n) for(ll i=k;i<n;++i)
#define _rep2(i,k,n,d) for(ll i=k;d!=0&&d>0?i<n:i>n;i+=d)
template<class T> vector<T> make_v(size_t a,T b){return vector<T>(a,b);}
template<class... Ts> auto make_v(size_t a,Ts... ts){return vector<decltype(make_v(ts...))>(a,make_v(ts...));}
template<class T> inline bool chmax(T &a,const T &b){if(a<b){a=b; return 1;} return 0;}
template<class T> inline bool chmin(T &a,const T &b){if(a>b){a=b; return 1;} return 0;}

void solve(){
  ll n; cin>>n;
  vector<ll> A(n);
  rep(i,n) cin>>A[i];
  vector<ll> idx(n);
  rep(i,n) idx.at(A[i]-1)=i;

  ll ans=0;
  set<ll> s;
  rep(k,n,0,-1){
    ll i=idx[k-1];
    auto itl=s.insert(i).first;
    auto itr=itl;
    vector<ll> l(2,-1),r(2,n);
    rep(i,2){
      if(itl--==s.begin()) break;
      l[i]=*itl;
    }
    rep(i,2){
      if(++itr==s.end()) break;
      r[i]=*itr;
    }
    ans+=k*((i-l[0])*(r[1]-r[0])+(l[0]-l[1])*(r[0]-i));
  }
  cout<<ans<<"\n";
}

Measured memory_bytes: 6528
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
const int maxn=2e6+5;
const ll p=998244353;
ll a[maxn],b[maxn];

int main(){
	ios::sync_with_stdio(false);
	
	int n;
	cin>>n;
	for (int i=1;i<=n;i++){
		cin>>a[i];
	}
	
	ll sum=0,f=1;
	for (int i=1;i<=n;i++){
		sum+=f*a[i];
		f*=-1;
	}
	b[1]=sum;
	
	for (int i=2;i<=n;i++){
		b[i]=2*a[i-1]-b[i-1];
	}
	
	for (int i=1;i<=n;i++){
		cout<<b[i]<<" ";
	}
	
}


Measured memory_bytes: 6272
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#define ll long long
int main(void)
{
    ll a, b, c, k, i;
    scanf("%lld%lld%lld%lld", &a, &b, &c, &k);
    if (k <= a)
        printf("%lld\n", k);
    else if (k <= a + b)
        printf("%lld\n", a);
    else
        printf("%lld\n", a - (k - a - b));
    return 0;
}

Measured memory_bytes: 1728
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
    int n,i,f=0;
    cin >> n;
    for(i=1;i<10;i++) if(n%i==0 && n/i <10){
        f=1;
        break;
    }
    if(f==1) cout << "Yes";
    else cout << "No";
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <deque>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>
using namespace std;
using ll = long long;

int main() {
  ll N;
  cin >> N;
  vector<int> dig;
  while (N > 0) {
    dig.push_back(N % 10);
    N /= 10;
  }
  reverse(dig.begin(), dig.end());
  int res = 0, sum = 0;
  for (int i = 0; i < dig.size(); i++) {
    if (dig[i] > 0) {
      res = max(res, sum + dig[i] - 1 + 9 * ((int)dig.size() - i - 1));
    }
    sum += dig[i];
  }
  res = max(res, sum);
  cout << res << endl;
  return 0;
}


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

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

int main(){
  ll k;
  cin >> k;
  ll ans = 0;
  for (ll a=1; a<=k; a++) {
    for (ll b=1; b<=k; b++) {
      for (ll c=1; c<=k; c++) {
        ans += gcd(gcd(a, b), c);
      }
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3648
/**
 *	   author: nayakashutosh9 
**/
#include<bits/stdc++.h>
using namespace std;
#define int long long int
#define endl "\n"
#define mod 1000000007
#define inf 1e18
 
/*******************************************************************/
 

vector<int> w,v;
int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
 //    int t,tc=1;cin>>t;
	// cin.ignore();
	// while(t--){

	// }
	int n,c;cin>>n>>c;
	w.clear();w.resize(n);
	v.clear();v.resize(n);
	for(int i=0;i<n;i++) cin>>w[i]>>v[i];
	// for(int i=0;i<n;i++) cin>>v[i];
	vector<vector<int>> dp(n+1,vector<int>(c+1,0));
	for(int i=1;i<=n;i++){
		for(int j=1;j<=c;j++){
			if(j<w[i-1]){
				dp[i][j]=dp[i-1][j];
			}
			else{
				dp[i][j]=max(dp[i-1][j],v[i-1]+dp[i-1][j-w[i-1]]);
			}
		}
	}
	cout<<dp[n][c]<<endl;
}

Measured memory_bytes: 80256
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

int i,j,n,num,ccc,set,max,sum[1001][2];

int main(){
	while(scanf("%d",&n)*n){
		set++;max=0;sum[0][1]=set;sum[0][0]=1;
		for(;n>0;n--){
			scanf("%d %d",&num,&ccc);
			for(i=max;i>=0;i--){
				if(sum[i][1]==set){

					for(j=ccc;j>0;j--){
						if(i+num*j<=1000){
							if(sum[i+num*j][1]!=set){
								sum[i+num*j][0]=sum[i][0];
								sum[i+num*j][1]=set;
								if(i+num*j>max)max=i+num*j;
							}
							else sum[i+num*j][0]+=sum[i][0];
						}
					}

				}
			}
		}
		scanf("%d",&n);
		for(;n>0;n--){
			scanf("%d",&num);
			printf("%d\n",sum[num][1]==set ? sum[num][0] : 0);
		}
	}
	return 0;
}

Measured memory_bytes: 608
from sys import stdin

sr = lambda: stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

N = ir()
T = lr()
M = ir()
total = sum(T)
for _ in range(M):
    p, x = lr()
    result = total - T[p-1] + x
    print(result)

# 22

Measured memory_bytes: 3060
import math

N = int(input())

a = list(map(int, input().split()))
b = [a[0] for i in range(N)]

for i in range(1, N):
    b[i] = b[i-1] + a[i]
    
b.sort()
c = 1
ans = 0

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

def C(n, r):
    return P(n, r)//math.factorial(r)

if N==1:
    if b[0]==0:
        print(1)
    else:
        print(0)
else:
    for i in range(1, N):
        if b[i]==b[i-1]:
            c = c+1
        else:
            if c>1:
                ans = ans + C(c, 2)
            if b[i-1]==0:
                ans = ans + c
            c=1
    else:
        if c>1:
            ans = ans + C(c, 2)
        if b[i-1]==0:
            ans = ans + c
    
    print(ans)

Measured memory_bytes: 27268
import java.util.*;
public class Main{
	public static void main(String args[]){
		Scanner sc = new Scanner(System.in);
		String S = sc.next();
		String T = sc.next();
		String ans = "No";
		int len = T.length();
		if(T.substring(0,len - 1).equals(S)){
			ans = "Yes";
		}
		System.out.println(ans);
	}
}

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


int main(){
    string s;
    cin >> s;
    int t = s.size();
    for(int i = t-2;i >= 0 ;i -= 2){
        string a = s.substr(0,i/2);
        string b = s.substr(i/2,i/2);
        if(a == b){
            cout << i << endl;
            break;
        }
    }
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
    int a, b;
    char op;
    
    while (1) {
        scanf("%d %c %d", &a, &op, &b);
        
        if ( op == '?') {
            break;
        } else if ( op == '+') {
            printf("%d\n", a + b);
        } else if (op == '-') {
            printf("%d\n", a - b);
        } else if (op == '*') {
            printf("%d\n", a * b);
        } else {
            printf("%d\n", a / b);
        }
    }
    return 0;
}

Measured memory_bytes: 1028
#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
 
int main () {
  int N, M;
  cin >> N >> M;
 
  vector<int> A(N, 0);
  for (int i = 0; i < N; i++) {
    cin >> A.at(i);
  }
  
  int sum = 0;
  for (int i = 0; i < N; i++) {
    sum += A.at(i);
  }
  
  sort(A.begin(), A.end());
  reverse(A.begin(), A.end());
  
  double judge = (double)sum / (double)(4 * M);
  
  for (int i = 0; i < M; i++) {
    if (A.at(i) < judge) {
      cout << "No";
      return 0;
    }
  }
  
  cout << "Yes";
  
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
int main()
{
  char s[100000000],t[100000000];
  int i,c=0,len=0;
  scanf("%s %s",&s,&t);
  len=strlen(s); 
  for(i=0;i<len;i++){
    if(s[i]!=t[i])
      c++;
  }
  printf("%d\n",c);
  return 0;
}

Measured memory_bytes: 2128
import heapq,sys
from collections import deque

input=sys.stdin.readline

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

Q=int(input())
query=[]
for i in range(Q):
    v,d,c=map(int,input().split())
    query.append((v-1,d,c))
query=query[::-1]

ans=[0]*N
time=[-1]*N


for i in range(Q):
    v,d,c=query[i]
    que=deque([(0,v,d)])
    while que:
        val,v,di=que.popleft()
        time[v]=di
        if not ans[v]:
            ans[v]=c
        for nv in edge[v]:
            if di-1>time[nv]:
                time[nv]=di-1
                que.append((val+1,nv,di-1))

for i in range(N):
    print(ans[i])

Measured memory_bytes: 122544
#include <iostream>
using namespace std;
int main() {
    int a, b, c;
    cin >> a >> b >> c;
    if (a - b < 0) {
        cout << c << endl;
    } else if (a - b >= c) {
        cout << 0 << endl;
    } else {
        cout << c - (a - b) << endl;
    }
    return 0;
}

Measured memory_bytes: 256
let (h, w) = Scanf.sscanf (read_line ()) "%d %d" @@ fun h w -> (h, w)
let s = Array.init h @@ fun _ -> read_line ()

let t = Array.init h @@ fun _ -> Array.make w 0

let f x y ch = if x < 0 || (h - 1) < x || y < 0 || (w - 1) < y then false else t.(x).(y) = 0 && s.(x).[y] <> ch

let rec g x y i =
  t.(x).(y) <- i;
  List.iter 
    (fun (a, b) -> if f a b s.(x).[y] then g a b i) 
    [(x - 1, y); (x + 1, y); (x, y - 1); (x, y + 1)]

let () =
  let v = ref 1 in
  for i = 0 to (h - 1) do
    for j = 0 to (w - 1) do
      if t.(i).(j) = 0 then begin
        g i j !v;
        v := !v + 1
      end
    done
  done;
  let arr = Array.make !v (0, 0) in
  for i = 0 to (h - 1) do
    for j = 0 to (w - 1) do
      let n = t.(i).(j) in
      let (w, b) = arr.(n - 1) in
      arr.(n - 1) <- if s.(i).[j] = '.' then (w + 1, b) else (w, b + 1)
    done
  done;
  print_int @@ Array.fold_left (fun sum (w, b) -> sum + w * b) 0 arr;
  print_newline ()


Measured memory_bytes: 46588
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <string>
#include <vector>
#include <deque>
#include <list>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <cstring>
#include <cctype>
#include <sstream>
#include <set>
#include <map>
#include <queue>
#include <complex>
using namespace std;
#define REP(i,n) for(int i = 0; i < (int)n; i++)
#define FOR(i,a,b) for(int i = a; i < (int)b; i++)
const int INF = 1<<28;

int W, H, ppl;
char m[30][30];
string d = "WSEN";
int dx[] = {-1, 0, 1, 0}, dy[] = {0, 1, 0, -1};

bool canMove(int h, int w) {
	if(0 <= h && 0 <= w && h < H && w < W)
		if(m[h][w] == '.' || m[h][w] == 'X')
			return true;
	return false;
}

char decideDirection(int h, int w, char d2) {
	REP(i, 4) {
		int nd = (d.find(d2) + 3 + i) % 4;
		int nh = h + dy[nd], nw = w + dx[nd];
		if(canMove(nh, nw)) return d[nd];
	}
	return d2;
}

int main() {
	while(cin >> W >> H, W|H) {
		ppl = 0;
		REP(i, H) REP(j, W) {
			cin >> m[i][j];
			if(d.find(m[i][j]) != string::npos)
				ppl++;
		}

		int cnt = 0;
		while(ppl) {
			REP(i, H) REP(j, W) {
				if(d.find(m[i][j]) != string::npos) {
					m[i][j] = decideDirection(i, j ,m[i][j]);
				}
			}

			bool chk[30][30];
			memset(chk, true, sizeof(chk));
			REP(i, 4) REP(j, H) REP(k, W) {
				if(m[j][k] == d[i] && chk[j][k]) {
					int nh = j + dy[i], nw = k + dx[i];
					if(m[nh][nw] == '.' && chk[nh][nw]) {
						swap(m[j][k], m[nh][nw]);
						chk[nh][nw] = false;
					}
					else if(m[nh][nw] == 'X' && chk[nh][nw]) {
						m[j][k] = '.';
						chk[nh][nw] = false;
						ppl--;
					}
					chk[j][k] = false;
				}
			}
			cnt++;
			if(cnt > 180) break;

			//debug
//			REP(i, H) {
//				REP(j, W)
//					cout << m[i][j];
//				cout << endl;
//			}
		}
		if(cnt > 180) cout << "NA" << endl;
		else cout << cnt << endl;
	}
	return 0;
}

Measured memory_bytes: 1208
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(){
	int N, M;
	cin >> N >> M;
	vector<vector<long long>> A(N, vector<long long>(3));
	for (int i = 0; i < N; i++){
		for (int j = 0; j < 3; j++){
			cin >> A[i][j];
		}
	}
	long long ans = 0;
	for (int i = 0; i < (1 << 3); i++){
		vector<long long> S(N, 0);		
		for (int j = 0; j < N; j++){
			for (int k = 0; k < 3; k++){
				if (i >> k & 1){
					S[j] += A[j][k];
				} else {
					S[j] -= A[j][k];
				}
			}
		}
		sort(S.begin(), S.end());
		reverse(S.begin(), S.end());
		long long sum = 0;
		for (int j = 0; j < M; j++){
			sum += S[j];
		}
		ans = max(ans, sum);
	}
	cout << ans << endl;
}

Measured memory_bytes: 3632
// finish date: 2018/01/10
#include <iostream>
#include <cmath>
#include <vector>
#include <bitset>
#include <algorithm>
#include <stack>
#include <map>
#include <climits>

using namespace std;

#define FOR(i, a, b) for(int i=a;i<b;i++)
#define rep(i, n)  FOR(i,0,n)
#define ll long long

bool isExist(char c, string str) {
    rep(i, str.length()) {
        if (c == str[i]) return true;
    }
    return false;
}

int fact(int n) {
    int ans = 1;
    FOR(i, 1, n + 1) {
        ans *= i;
    }
    return ans;
}

int main() {
    int N, K, X, Y;
    cin >> N >> K >> X >> Y;
    cout << min(N, K) * X + max(N-K,0) * Y;

    return 0;
}

Measured memory_bytes: 256
if isfile("mystdin.txt");mystdin=open("mystdin.txt","r");redirect_stdin(mystdin);end
pI(x)=parse(Int,x)
pM(x::Array{SubString{String},1})=map(pI,x)
function main()
  s=chomp(readline())
  for c='a':'z'
    if !(c in s)
      println(c)
      return 0
    end
  end
  println("None")
end
main()
if isdefined(Base, :mystdin);close(mystdin);end

Measured memory_bytes: 162684
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(long i = 0; i < n; i++)
#define erep(i, n) for(long i = 1; i <= n; i++)
const long MOD = 1000000007;

int main() {string s;
cin >> s;
long N = s.size();
long ans = 0;

rep(i, N - 1){
    if(s.at(i + 1) != s.at(i)) ans++;
}



cout << ans << endl;
  return 0;
 
}



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

#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rep2(i,s,n) for(int i = (s); i < (n); ++i)
#define ll long long
#define ld long double
#define P pair<ll,ll>
#define all(v) v.begin(),v.end()

const ll mod = 1e9+7;
const ll INF = 1e18;
const double pi = acos(-1.0);

int main(void)
{
    ll h,w; cin>>h>>w;
    char s[h][w];
    rep(i,h)rep(j,w) cin>>s[i][j];

    ll di[]={1,0,-1,0},dj[]={0,1,0,-1};
    bool ok=true;
    rep(i,h){
        rep(j,w){
            if(s[i][j]=='.') continue;
            bool ok2=false;
            rep(k,4){
                ll ni=i+di[k],nj=j+dj[k];
                if(ni<0||h<=ni||nj<0||w<=nj) continue;
                if(s[ni][nj]=='#') ok2=true;
            }
            if(!ok2){
                ok=false;
                break;
            }
        }
    }
    if(ok) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 3616
package main

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

var sc = bufio.NewScanner(os.Stdin)

func scanInt() int {
	sc.Scan()
	a, err := strconv.Atoi(sc.Text())
	if err != nil {
		fmt.Println(err)
	}
	return a
}

func main() {
	sc.Split(bufio.ScanWords)

	X := scanInt()
	if X >= 30 {
		fmt.Println("Yes")
	} else {
		fmt.Printf("No")
	}
}

Measured memory_bytes: 1776
#!/usr/bin/env python3
# encoding:utf-8
import copy
import random
import bisect #bisect_left　これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
import math
import sys
import collections
from decimal import Decimal # 10進数で考慮できる

mod = 10**9+7
sys.setrecursionlimit(mod) # 再帰回数上限はでdefault1000

d = collections.deque()
def LI(): return list(map(int, sys.stdin.readline().split()))

"""
N rooms
M paths

0 room is start
"""
class UnionFind():
    # 作りたい要素数nで初期化
    # 使用するインスタンス変数の初期化
    def __init__(self, n):
        self.n = n
        # root[x]<0ならそのノードが根かつその値が木の要素数
        # rootノードでその木の要素数を記録する
        self.root = [-1]*(n+1)
        # 木をくっつける時にアンバランスにならないように調整する
        self.rnk = [0]*(n+1)

    # ノードxのrootノードを見つける
    def Find_Root(self, x):
        if(self.root[x] < 0):
            return x
        else:
            # ここで代入しておくことで、後の繰り返しを避ける
            self.root[x] = self.Find_Root(self.root[x])
            return self.root[x]
    # 木の併合、入力は併合したい各ノード
    def Unite(self, x, y):
        # 入力ノードのrootノードを見つける
        x = self.Find_Root(x)
        y = self.Find_Root(y)
        # すでに同じ木に属していた場合
        if(x == y):
            return 
        # 違う木に属していた場合rnkを見てくっつける方を決める
        elif(self.rnk[x] > self.rnk[y]):
            self.root[x] += self.root[y]
            self.root[y] = x

        else:
            self.root[y] += self.root[x]
            self.root[x] = y
            # rnkが同じ（深さに差がない場合）は1増やす
            if(self.rnk[x] == self.rnk[y]):
                self.rnk[y] += 1
    # xとyが同じグループに属するか判断
    def isSameGroup(self, x, y):
        return self.Find_Root(x) == self.Find_Root(y)

    # ノードxが属する木のサイズを返す
    def Count(self, x):
        return -self.root[self.Find_Root(x)]

N, M = LI()
AB = []
for i in range(M):
    a,b = LI()
    a -= 1
    b -= 1
    AB.append((a,b))

paths = {}
for i in range(N):
    paths[i] = []
for a, b in AB:
    paths[a].append(b)
    paths[b].append(a)

# uf = UnionFind(N)
# for a,b in AB:
#     uf.Unite(a,b)

# ans = True
# for i in range(N):
#     if not uf.isSameGroup(0, i):
#         ans = False

# if ans == False:
#     print("No")
#     sys.exit()

q = collections.deque()

# node No, parent No
q.append((0, -1))

anss = [0 for i in range(N)]
rooms = [0 for i in range(N)]
rooms[0] = 1
while len(q) > 0:
    node, p = q.popleft()

    for path in paths[node]:
        if path == p:
            continue
        if rooms[path]: # すでに探索済み
            continue
        q.append((path, node))
        rooms[path] = 1
        anss[path] = node
print("Yes")
for ans in anss[1:]:
    print(ans + 1)




Measured memory_bytes: 62440
import java.util.*;

public class Main {
	static Scanner sc = new Scanner(System.in);
	public static void main(String[] args) {
		StringBuilder sb = new StringBuilder(sc.nextLine());
		for (int i=0; i<sb.length(); i++) {
			char c = sb.charAt(i);
			if (c>=65&&c<=90) {sb.replace(i,i+1,String.valueOf(c).toLowerCase());}
			else if (c>=97&&c<=122) {sb.replace(i,i+1,String.valueOf(c).toUpperCase());}
		}
		System.out.println(sb);
	}
}


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

C = []
B_T = list(zip(*B))
for a_row in A:
    C.append([sum(a * b for a, b, in zip(a_row, b_column)) for b_column in B_T])
for row in C:
    print(' '.join(map(str, row)))

Measured memory_bytes: 7760
#include<stdio.h>
int main()
{
    int n,t,temp,a[100],b[100],i,k,cnt=0,j=0,r;
    scanf("%d",&n);
    t=n;
    while(t!=0)
    {
        temp=t%10;
        a[cnt]=temp;
        t=t/10;
        cnt++;
    }
    t=n;
    while(t!=0)

    while(t!=0)
    {
        t=t/10;
        b[j]=t;
        t=t%10;
        j++;
    }
    b[j-1]=a[0];
    for(i=0;i<cnt;i++)
    {
        for(k=0;k<j;k++)
        {
            if(a[i]==b[k])
            {
                r=1;
            }
            else
            {
                r=0;
            }
        }
    }
    if(r==1)
    {
        printf("Yes\n");
    }
    else if(r==0)
    {
        printf("No\n");
    }
    return 0;
}


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

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

  rep( i, 0, S.size() ) S[i] = 'x';
  cout << S << endl;
}


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

typedef long long ll;

ll getmax(ll a, ll b){
	if(a > b)
		return a;
	return b;
}

int main()
{
	ll A, B, K;

	cin >> A >> B >> K;

	ll Takahashi = getmax(0, A - K);
	K  = getmax(0, K - A);
	ll Aoki = getmax(0, B - K);
	cout << Takahashi << ' ' << Aoki << '\n';

	return 0;
}

Measured memory_bytes: 3560
import copy

N, K = map(int, input().split())
a = list(map(int, input().split()))

ans = [0] * N
def loop():
    global a
    ruir = [0] * (N + 1)
    ruil = [0] * (N + 1)
    for i in range(N):
        ruir[i] += 1
        tmp = i + a[i]
        if tmp < N:
           ruir[tmp + 1] -= 1
    for i in range(N):
        ruir[i + 1] += ruir[i]

    for i in reversed(range(N)):
        if a[i] - 0.5 > -1:
            ruil[i - 1] += 1
            tmp = i - a[i]
            if tmp > 0:
                ruil[tmp - 1] -= 1
    for i in reversed(range(N)):
        ruil[i - 1] += ruil[i]
    cnt = 0
    for i in range(N):
        add = ruir[i] + ruil[i]
        if add > N:
            add = N
        if add == N:
            cnt +=1
        ans[i] = add
    if cnt == N:
        print(*ans)
        exit()
    a = copy.deepcopy(ans)

for i in range(K):
    loop()
print(*ans)

Measured memory_bytes: 179496
fun main(arr: Array<String>) {
    val (n,m) = readLine()!!.split(" ").map { it.toInt() }
    val roads = (0..n).map { 0 }.toMutableList()
    for(i in (1..m)) {
        readLine()!!.split(" ").map { it.toInt() }.forEach { roads[it]++ }
    }
    (1..n).map { println(roads[it]) }
}

Measured memory_bytes: 36536
S=input()
sf=int(S[:2])
sb=int(S[2:])
if 1<=sf and sf<=12:
  if 1<=sb and sb<=12:
    print("AMBIGUOUS")
  else:
    print("MMYY")
else:
  if 1<=sb and sb<=12:
    print("YYMM")
  else:
    print("NA")

Measured memory_bytes: 38292
# coding: utf-8
# Your code here!
# coding: utf-8
while True:
    n = list(map(int,input().split()))
    if n[0] == 0:
        break
    for i in range(n[0]):
        s = ""
        for j in range(n[1]):
            if i % 2 == 0:
                if j % 2 == 0:
                    s += "#"
                else:
                    s += "."
            else:
                if j % 2 == 0:
                    s += "."
                else:
                    s += "#"
        print(s)
    print()
#        


Measured memory_bytes: 5616
# Dinic's algorithm
from collections import deque
class Dinic:
    def __init__(self, N):
        self.N = N
        self.G = [[] for i in range(N)]

    def add_edge(self, fr, to, cap):
        forward = [to, cap, None]
        forward[2] = backward = [fr, 0, forward]
        self.G[fr].append(forward)
        self.G[to].append(backward)

    def add_multi_edge(self, v1, v2, cap1, cap2):
        edge1 = [v2, cap1, None]
        edge1[2] = edge2 = [v1, cap2, edge1]
        self.G[v1].append(edge1)
        self.G[v2].append(edge2)

    def bfs(self, s, t):
        self.level = level = [None]*self.N
        deq = deque([s])
        level[s] = 0
        G = self.G
        while deq:
            v = deq.popleft()
            lv = level[v] + 1
            for w, cap, _ in G[v]:
                if cap and level[w] is None:
                    level[w] = lv
                    deq.append(w)
        return level[t] is not None

    def dfs(self, v, t, f):
        if v == t:
            return f
        level = self.level
        for e in self.it[v]:
            w, cap, rev = e
            if cap and level[v] < level[w]:
                d = self.dfs(w, t, min(f, cap))
                if d:
                    e[1] -= d
                    rev[1] += d
                    return d
        return 0

    def flow(self, s, t):
        flow = 0
        INF = 10**9 + 7
        G = self.G
        while self.bfs(s, t):
            *self.it, = map(iter, self.G)
            f = INF
            while f:
                f = self.dfs(s, t, INF)
                flow += f
        return flow

H,W=map(int,input().split())
a=[]
for i in range(H):
    a.append(input())

leaf=[]
for i in range(H):
    for j in range(W):
        if a[i][j]=="o":
            leaf.append((i,j))
        elif a[i][j]=="S":
            s=(i,j)
        elif a[i][j]=="T":
            t=(i,j)

inf=300
L=Dinic(H+W+2+2*len(leaf))
for i in range(len(leaf)):
    x,y=leaf[i]
    X,Y=x+1,y+H+1
    index=2*i+H+W+1
    L.add_edge(X,index,inf)
    L.add_edge(Y,index,inf)
    L.add_edge(index,index+1,1)
    L.add_edge(index+1,X,inf)
    L.add_edge(index+1,Y,inf)

i,j=s
L.add_edge(0,i+1,inf)
L.add_edge(0,j+H+1,inf)
i,j=t
L.add_edge(i+1,H+W+2+2*(len(leaf))-1,inf)
L.add_edge(j+H+1,H+W+2+2*(len(leaf))-1,inf)
ans=L.flow(0,H+W+2+2*(len(leaf))-1)
print(ans if inf>ans else -1)


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

string next(string s, char c) {
  string res = "";
  for (int i = 0; i < s.size() - 1; ++i) {
    if (s[i] == c || s[i + 1] == c)
      res.push_back(c);
    else
      res.push_back(s[i]);
  }
  return res;
}

int f(string s, char c) {
  if (all_of(s.begin(), s.end(), [&](char x) { return x == c; }))
    return 0;
  else
    return 1 + f(next(s, c), c);
}

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

  int ans = 100;
  char c = 'a';

  while (c <= 'z') {
    bool contains_c = false;
    for (int i = 0; i < s.size(); ++i)
      if (s[i] == c)
        contains_c = true;
    if (contains_c)
      ans = min(ans, f(s, c));
    c = c + 1;
  }

  cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
int main()
{
	ll n;
	cin>>n;
	vector<ll> vl;
	map<ll,ll> mp;
	vl.push_back(-1234);
	for(int i=1;i<=n;i++)
	{
		ll a;
		cin>>a;
		ll he = a+i;
		mp[he]++;
		vl.push_back(a);
	}
	ll sum = 0;
	for(ll i=1;i<=n;i++)
	{
		int cha = i-vl[i];
		sum+=mp[cha];
	}
	cout<<sum<<endl;
	return 0;
}

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

typedef long long ll;
int main()
{
  ll n;
  cin>>n;
  ll a[n];
  ll cnt=0;
  for(ll i=0;i<n;i++)
  {
    cin>>a[i];
    if(a[i]==0)
      cnt++;
  }
  //cout<<cnt<<endl;
  if(cnt>0)
    cout<<0;
  else
  {
    ll ans=1;
    // cout<<"";
    for(ll i=0;i<n;i++)
    {
      ll result=ans*a[i];
      cout<<"";
      if((result/a[i])!=ans)
      {
        // cout<<"negative"<<endl;
        cout<<-1;
        return 0;
      }
      ans=result;
      //cout<<ans<<endl;
    }
    if(ans>1000000000000000000)
      cout<<-1;
    else
      cout<<ans;
  }
  return 0;
}
  

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef pair<ll, int> li;
typedef pair<int, ll> il;
typedef vector<ii> vii;
typedef vector<il> vil;
typedef vector<li> vli;

#define F            first
#define S            second
#define pb(x)        push_back(x)
#define mp(a,b)      make_pair(a,b)
#define mt(a,b,c)    make_tuple(a,b,c)
#define sz           size()
#define all(A)       A.begin(), A.end()
#define mem(a, b)    memset(a, b, sizeof(a))   // all elements of A are b=0 or b=-1 else don't work
#define f0(i,b)      for(ll i=0;i<(b);i++)
#define f1(i,b)      for(ll i=1;i<=(b);i++)
#define f2(i,a,b)    for(ll i=(a);i<=(b);i++)
#define f3(i,b,a)    for(ll i=(b);i>=(a);i--)
#define rep(i,a,b,c) for(ll i=(a);i!=(b);i+=(c))

#define mod          10000007
#define PI           acos(-1.0)
#define MAX3(a,b,c)  max(a,max(b,c))

/*------------------------Bitmask-------------------------------*/
#define bitOn(N,pos)      (N | (1LL<<(pos)))
#define bitOff(N,pos)     (N & (~(1LL<<(pos))))
#define bitCheck(N,pos)   ((bool)(N & (1LL<<(pos))))
#define bitFlip(a,k)      (a^(1LL<<(k)))

#define whilee(i,t)  while(i!=t)
#define  sl(a)       scanf("%lld",&a)
#define  pl(a)       printf("%lld\n",a)

//x = 1e18 means 10^18
//for(auto it =A.begin(); it!=A.end(); it++)
//sort(A.begin(),A.end()); //sort(A, +n, greater<int>());
//binary_search(A.begin(),A.end(),x);
//reverse(A.begin(), A.end());
//cout << *max_element(A.begin(), A.end());
//cout << *min_element(A.begin(), A.end());
//count(A.begin(), A.end(), X); //counts the occurrences of X
//distance(A.begin(),A.end());  //distance between first to last element
//accumulate(A.begin(), A.end(), 0); //add
//next_permutation(A.begin(), A.end());
//prev_permutation(A.begin(), A.end());
//swap(S[0], T[0]);

//scanf("%lld",&x);
//printf("%lld\n",x);
//printf("%I64d\n", a);
//while (scanf("%lld %lld", &a, &b) == 2)
//printf("Case %lld: %lld\n", t++, a);

/*----------------------- Graph Moves---------------------------*/
// int dx[] = {1,-1,0,0} , dy[] = {0,0,1,-1};  // 4 Direction
// int dx[] = {0,0,1,-1,-1,1,-1,1} , dy[] = {-1,1,0,0,1,1-1,-1};  // 8 Direction // Kings Move
// int dx[] = {1,-1,1,-1,2,2,-2,-2} , dy[] = {2,2,-2,-2,1,-1,1,-1};  // Knight Direction
// int dx[] = {2,-2,1,1,-1,-1} , dy[] = {0,0,1,-1,1,-1};  // Hexagonal Direction

//vector <ll> A;
//deque <ll> A;
//queue <ll> A;
//stack <ll> A;
//list <int> A;
//set <ll> A;
//map <ll,ll> A;
//unordered_map <ll, ll> A;
//pair <ll,ll> A ;
//tuple <ll, ll, ll> A;
//vector <pair <ll,ll>> A;
//bitset<32> bset1;
//bool ok = true;
//char ch;
string S="abcdefghijklmnopqrstuvwxyz", T="";

ll i=0, j=0, k=0, a, b, c, d, e, f, g, h, l, m, n, o, p, q, r, s, t=1, u, v, w, x, y, z, maxx=INT_MIN, minn=INT_MAX, ans=0, sum=0, flag=0, cnt=0;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);//NULL
    cout.tie(nullptr);//NULL

    cin>>n;
    x=n;

    while(x>0)
    {
        x-=1;
        i = x%26;
        T+=S[i];
        x/=26;
    }
    reverse(all(T));
    cout<<T<<endl;
    return 0;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main()
{
    ll n;
    cin >> n;
    vector<ll> a(n);
    for(int i = 0; i < n; i++)
    {
        cin >> a[i];
    }
    vector<vector<ll>> s(21, vector<ll>(n+1));
    for(int i = 1; i <= n; i++)
    {
        for(int j = 0; j <= 20; j++)
        {
            if(i > 0) s[j][i] = s[j][i-1];
            if(a[i-1] >> j & 1)
            {
                s[j][i]++;
            }
        }
    }
 
  ll ans = 0;
    for(int i = 1; i <= n; i++)
    {
        ll tmp = n+100;
        for(int j = 0; j <= 20; j++)
        {
            ll pos = lower_bound(s[j].begin(), s[j].end(), 2+s[j][i-1]) - s[j].begin() - i;
            tmp = min(tmp, pos);
        }
        ans += tmp;
    }
    cout << ans << endl;
}



Measured memory_bytes: 36224
import java.util.Scanner;
public class Main{
    public static void main(String args[]){
	Scanner in =new Scanner(System.in);

	int m,f,r;
	String grade; 
	while(true){
	    m = in.nextInt();
	    f = in.nextInt();
	    r = in.nextInt();

	    int score = m+f;
	    if(m == -1 && f == -1 && r == -1)break;

	    if(m == -1 || f == -1)grade = "F";
	    else if(score >= 80)grade = "A";
	    else if(score >= 65 && score<80)grade = "B";
	    else if(score >= 50 && score<65)grade = "C";
	    else if(score>=30 && score <50){
		grade = "D";
		if(r>=50)grade ="C";
	    }else grade = "F";
	    System.out.println(grade);
	}

    }
}
	
	


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

using namespace std;

int main() {
    int n;
    cin>>n;
    int a[n];
    long double sum=0;
    for(int i=0;i<n;i++){
        scanf("%d",&a[i]);
        sum+=a[i];
    }
    sum=round(sum/n);
    long long cost=0;
    for(int i=0;i<n;i++){
        cost+=((sum-a[i])*(sum-a[i]));
    }
    cout<<cost;
    cout<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(obj) (obj).begin(),(obj).end()
typedef long long ll;
ll mod=ll(1e9)+7;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n,m;cin>>n>>m;
  vector<int> a(n);
  ll tot=0;
  rep(i,n){
    cin>>a[i];
    tot+=a[i];
  }
  int tmp=0;
  rep(i,n){
    if(a[i]*4*m>=tot)tmp++;
  }
  if(tmp>=m)cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
  return 0;
}


Measured memory_bytes: 256
//#define _CRT_SECURE_NO_WARNINGS
#include "bits/stdc++.h"

#define rep(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define all(x) (x).begin(),(x).end()
#define MOD 1000000007
#define INF (1LL<<60LL)
typedef long long ll;

using namespace std;



int main() {
	ll n; cin >> n;
	cout << n * (n + 1) / 2 << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = 1; i <= n; i++)
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); }
using P = pair <int, int>;
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; }

ll MOD = 1000000007;
ll INF =1<<30;

int dp[111][101011];
int main(){
    int N,W;
    cin >> N >> W;
    vector<int>w(N),v(N);
    rep(i,N) cin >> w[i] >> v[i];
    rep(j,101010) dp[0][j] = 1001000000;
    dp[0][0] = 0;
    rep(i,N+1){
        rep(j,101010){
            dp[i+1][j]=dp[i][j];
            if(j-v[i]>=0){
                dp[i+1][j] = min(dp[i+1][j],dp[i][j-v[i]]+w[i]);
            }
        }
    }
    int ans=0;
    rep(j,101010){
        if(dp[N][j]<=W){
            ans = j;
        }
    }
    cout << ans <<endl;
}


Measured memory_bytes: 43856
K = gets.to_i

i = 1
mod = 0
plus_mod = 7 % K

loop do
  if K % 2 == 0 || K % 5 == 0
    puts -1
    break
  end
  mod = (mod + plus_mod) % K

  if mod == 0
    puts i
    break
  end
  i += 1
  plus_mod = (plus_mod * 10) % K
  if plus_mod == 0
    puts -1
    break
  end
end


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

int main(){
  int n,t; cin>>n>>t;
  int minnum; cin>>minnum;
  bool flag=false;
  int diff=-1,count=0,change=0;
  for(int i=1;i<n;i++){
    int x; cin>>x;
    if(minnum>x){
      minnum=x;
      flag=true;
    }else {
      int y=x-minnum;
      if(diff==y){
        if(flag){
          change++;
          flag=false;
        }
      }else if(diff<y){
        change=1;
        diff=y;
      }
    }
  }
  cout<<change<<endl;
}

Measured memory_bytes: 256
/*FBI WARNING
Federal law provides severe civil and criminal penalties for
the unauthorzed reproduction, distribution, or exhibition of
copyrighted motion pictures (Title 17 united states code
sections 501 and 508). The federal bureau of investigation
investigates allegations of criminal copyright infringement
(Title 17, united states code sections 506).*/

#include<bits/stdc++.h>
using namespace std;
#define maxn 400010

template < typename tp > void read ( tp & dig ){
    char ch=getchar();dig=0;int flag=0;
    while(!isdigit(ch)){ if(ch=='-')flag=1;ch=getchar(); }
    while(isdigit(ch))dig=dig*10+ch-'0',ch=getchar();
    if(flag)dig=-dig;
}

int fst[maxn],nxt[maxn<<1],to[maxn<<1];
int n,m,lnum,a[maxn],sum[maxn][2];
char s[maxn];int vis[maxn];
queue <int > que;

inline void add_edge(int u,int v){
    nxt[++lnum]=fst[u];fst[u]=lnum;to[lnum]=v;
    nxt[++lnum]=fst[v];fst[v]=lnum;to[lnum]=u;
}

int main()
{

    read(n);read(m);scanf("%s",s+1);
    for(int i=1;i<=n;++i)
	a[i]=(s[i]=='A');
    for(int i=1,x,y;i<=m;++i){
	read(x),read(y);add_edge(x,y);
	++sum[x][a[y]];++sum[y][a[x]];
    }for(int i=1;i<=n;++i)
	 if(!sum[i][0]||!sum[i][1])
	     que.push(i),vis[i]=1;
    while(!que.empty()){
	int now=que.front();que.pop();
	for(int j=fst[now];j;j=nxt[j]){
	    int v=to[j];--sum[v][a[now]];
	    if(vis[v])continue;
	    if(!sum[v][0]||!sum[v][1])
		que.push(v),vis[v]=1;
	}
    }int flag=0;
    for(int i=1;i<=n;++i)
	if(!vis[i])flag=1;
    if(flag)printf("Yes\n");
    else printf("No\n");
    return 0;
    
}


Measured memory_bytes: 14080
#include<bits/stdc++.h>
using namespace std;
int main()
{
	long long a,b,n,t;
	cin>>a>>b>>n;
	
	if(b-1<=n)
	t=b-1;
	else
	t=n;
	cout<<((a*t)/b)-a*(t/b);
}

Measured memory_bytes: 3596
N = int(input())
As = list(map(int, input().split()))

neg_count = 0
max_neg = -10**9-1
max_neg_i = -1
min_pos = 10**9+1
min_pos_i = -1
total2 = 0
for i in range(N):
    if As[i] >= 0 and As[i] < min_pos:
        min_pos = As[i]
        min_pos_i = i
    if As[i] < 0 and As[i] > max_neg:
        max_neg = As[i]
        max_neg_i = i
    total2 += abs(As[i])
    if As[i] < 0:
        neg_count += 1

if neg_count % 2 == 0:
    print(total2)
else:
    cands = []
    if min_pos_i >= 0:
        cands.append(total2 - min_pos*2)
    if max_neg_i >= 0:
        cands.append(total2 + max_neg*2)
    print(max(cands))

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

#define watch(x) cout << (#x) << " = " << x << endl;
#define mkp make_pair
#define mkt make_tuple
#define pb push_back
#define ll long long
#define ld long double

using namespace std;

int n, W;
ll dp[110][100010];
int w[110], v[110];

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

	for(int i = 1; i <= n; i++){
		scanf("%d%d", &w[i], &v[i]);
	}

	for(int i = 0; i <= n; i++){
		for(int j = 0; j <= W; j++){
			dp[i][j] = -1e12;
		}
	}

	dp[1][W] = 0;

	for(int i = 1; i <= n; i++){
		for(int j = 0; j <= W; j++){
			if(j >= w[i]) dp[i + 1][j - w[i]] = max(dp[i + 1][j - w[i]], dp[i][j] + v[i]);
			dp[i + 1][j] = max(dp[i + 1][j], dp[i][j]);
		}
	}

	ll ans = -1;
	for(int i = 0; i <= W; i++) ans = max(ans, dp[n + 1][i]);

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

	return 0;
}


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

using ll=int64_t;
#define int ll

#define FOR(i,a,b) for(int i=int(a);i<int(b);i++)
#define REP(i,b) FOR(i,0,b)
#define MP make_pair
#define PB push_back
#define ALL(x) x.begin(),x.end()
#ifdef MAROON_LOCAL
#define cerr (cerr<<"-- line "<<__LINE__<<" -- ")
#else
class CerrDummy{}cerrDummy;
template<class T>
CerrDummy& operator<<(CerrDummy&cd,const T&){
	return cd;
}
using charTDummy=char;
using traitsDummy=char_traits<charTDummy>;
CerrDummy& operator<<(CerrDummy&cd,basic_ostream<charTDummy,traitsDummy>&(basic_ostream<charTDummy,traitsDummy>&)){
	return cd;
}
#define cerr cerrDummy
#endif
#define REACH cerr<<"reached"<<endl
#define DMP(x) cerr<<#x<<":"<<x<<endl
#define ZERO(x) memset(x,0,sizeof(x))
#define ONE(x) memset(x,-1,sizeof(x))

using pi=pair<int,int>;
using vi=vector<int>;
using ld=long double;

template<class T,class U>
ostream& operator<<(ostream& os,const pair<T,U>& p){
	os<<"("<<p.first<<","<<p.second<<")";
	return os;
}

template<class T>
ostream& operator <<(ostream& os,const vector<T>& v){
	os<<"{";
	REP(i,(int)v.size()){
		if(i)os<<",";
		os<<v[i];
	}
	os<<"}";
	return os;
}

ll read(){
	ll i;
	scanf("%" SCNd64,&i);
	return i;
}

void printSpace(){
	printf(" ");
}

void printEoln(){
	printf("\n");
}

void print(ll x,int suc=1){
	printf("%" PRId64,x);
	if(suc==1)
		printEoln();
	if(suc==2)
		printSpace();
}

string readString(){
	static char buf[3341000];
	scanf("%s",buf);
	return string(buf);
}

char* readCharArray(){
	static char buf[3341000];
	static int bufUsed=0;
	char* ret=buf+bufUsed;
	scanf("%s",ret);
	bufUsed+=strlen(ret)+1;
	return ret;
}

template<class T,class U>
void chmax(T& a,U b){
	if(a<b)
		a=b;
}

template<class T,class U>
void chmin(T& a,U b){
	if(b<a)
		a=b;
}

template<class T>
T Sq(const T& t){
	return t*t;
}

#define CAPITAL
void Yes(bool ex=true){
	#ifdef CAPITAL
	cout<<"YES"<<endl;
	#else
	cout<<"Yes"<<endl;
	#endif
	if(ex)exit(0);
}
void No(bool ex=true){
	#ifdef CAPITAL
	cout<<"NO"<<endl;
	#else
	cout<<"No"<<endl;
	#endif
	if(ex)exit(0);
}

const ll infLL=LLONG_MAX/3;

#ifdef int
const int inf=infLL;
#else
const int inf=INT_MAX/2-100;
#endif

signed main(){
	int n=read();
	vi l{0},r{0};
	REP(i,n)
		l.PB(read()),r.PB(read());
	sort(ALL(l),greater<int>());
	sort(ALL(r));
	int ans=0;
	REP(i,n+1)if(r[i]<l[i]){
		cerr<<r[i]<<" "<<l[i]<<endl;
		ans+=(l[i]-r[i])*2;
	}
	print(ans);
}


Measured memory_bytes: 2036
#include "bits/stdc++.h"

using namespace std;

using ll = long long;
using ld = long double;

using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using vvvl = vector<vvl>;
using vd = vector<double>;
using vvd = vector<vd>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vs = vector<string>;

const int INF = (1 << 30) - 1;
const ll INF64 = ((ll)1 << 62) - 1;
const double PI = 3.1415926535897932384626433832795;

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

int gcd(int x, int y) { return y ? gcd(y, x % y) : x; }
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
int lcm(int x, int y) { return x / gcd(x, y) * y; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }

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

	int m;
	cin >> m;

	cout << 2 * 24 - m << endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD=1000000007;
#define INF 1LL<<30
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()

vector<vector<pair<int,int>>> G(20);

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

    rep(i,n){
        int a;
        cin>>a;
        rep(j,a){
            int x,y;
            cin>>x>>y;
            x--;
            G[i].push_back({x,y});
        }
    }

    int ans=0;
    rep(bit,1<<n){
        int tmp=0;
        bool ok=true;
        rep(i,n){
            if(bit & 1<<i){
                tmp++;
                rep(j,G[i].size()){
                    int x=G[i][j].first;
                    int y=G[i][j].second;
                    if(y==0 && bit & 1<<x) ok=false;
                    else if(y==1 && !(bit & 1<<x)) ok=false;
                }
            }
        }

        if(ok) ans=max(ans,tmp);
    }

    cout<<ans<<endl;
}


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

int main(){
  int n,ans=0;
  cin>>n;
  
  rep(i,1,n+1){
    int cnt=0;
    if(i%2==0){continue;}
    rep(j,1,n+1){
      if(i%j==0){cnt++;}
    }
    if(cnt==8){ans++;}
  }
  cout<<ans<<endl;
  
  return 0;
}

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

int main() {
  int a; cin >> a;
  int b; cin >> b;
  if (a <= 5) {
    cout << 0 << endl;
  } else if (a <= 12) {
    cout << b / 2 << endl;
  } else {
    cout << b << endl;
  }
}


Measured memory_bytes: 256
// Hail god Yato
 
#include <bits/stdc++.h> 
using namespace std;
 
#define add(x) accumulate(x)
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end() 
#define rep(i, a, b) for (int i=a; i<(b); i++)
#define hs ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
typedef long long ll;
typedef pair<ll,ll> pll;
typedef vector<ll> vll;
typedef vector<pll> vpll;
const ll mod = 1000000007;
const ll INF = 1e18;
const ll MAX = 100001;
//
//

              ll modpow(ll x,ll y){
                        ll res = 1LL;
                        x%=mod;
                        while(y){
                          if(y&1){
                            res = res*x;
                            res%=mod;
                          }
                          y>>=1;
                          x=x*x;
                          x%=mod;
                        }
                        return res;
                }
                void solve(){
                        ll n, k;
                        cin>>n>>k;
                        vll dp(MAX, 0);
                        for(int i = k; i >= 1; i--){
                                ll temp = modpow(k/i, n);
                                for(int j = 2*i ; j <= k; j += i){
                                        temp -= dp[j];
                                        temp += mod;
                                        temp %= mod;
                                }
                                dp[i] = temp;
                        }
                        ll ans = 0;
                        for(int i = 1; i <= k; i++){
                                ans += (dp[i]*i)%mod;
                                ans %= mod;
                        }
                        cout<<ans;
                }
                int main(){ 
                        hs;
                        ll t;
                        t=1;
                        // cout<<modpow(3, 2);
                        // cin>>t;
                        for (int i=1; i<=t; i++){
                                //cout<<"Case #"<<i<<": ";
                                solve();
                         }
        return 0; 
}         
 

Measured memory_bytes: 3968
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<vector>
#include<math.h>
typedef long long ll;
using namespace std;

int main()
{
	int ans; scanf("%d", &ans);
	for (int i = 1; i <= 9; i++) {
		for (int j = 1; j <= 9; j++) {
			if (i*j == ans) {
				printf("Yes");
				return 0;
			}
		}
	}
	printf("No");
	return 0;
}

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

int main()
{

	char c; int f=0;
	double s,x,y,x0,y0,vx[2],vy[2];

	cin >> x0 >> c >> y0;
	cin >> x  >> c >> y ;

	vx[1] = x-x0;
	vy[1] = y-y0;

	s=0;
	while(cin >> x >> c >> y)
	{
		vx[f] = x-x0;
		vy[f] = y-y0;
		
		s+= fabs(vx[f]*vy[1-f] - vx[1-f]*vy[f]);
		
		f=1-f;
	}

	cout << s/2.0 << endl;
}


Measured memory_bytes: 3072
n = int(input())
s = [input() for i in range(n)]


ac = 0
wa = 0
tle = 0
re = 0
for i in s:
    if i == 'AC':
        ac+=1
    elif i == 'WA':
        wa+=1
    elif i == 'TLE':
        tle+=1
    else:
        re += 1

print('AC x', ac)
print('WA x', wa)
print('TLE x', tle)
print('RE x', re)

Measured memory_bytes: 79176
$%{0}=0;$A=<>,$C=map(1..1<<$_-1,glob<>),map+($%{$_|$C}//=9e9)-=$-=$%{$_|$C}-$A-$%{$_},keys%%for<>=~$"..$';print$%{2**$`-1}//-1

Measured memory_bytes: 1792