akhauriyash/Code-Regression huggingface dataset:
/*its_Rashid*/
#include <bits/stdc++.h>
using namespace std ;

typedef double du ;
typedef string st ;
typedef long long ll ;
typedef long double ld ;
typedef long long int lli ;

#define vi vector <lli>
#define loop(num) for (lli i = 0 ; i < num ; i ++ )
#define loop2(num) for (lli j = 0 ; j < num ; j ++ )
#define loopcin(num , ar ) for (lli i = 0 ; i < num ; i ++ ) {cin >> ar [i] ;}
#define loopcout(num , ar) for (lli i = 0 ; i < num ; i ++ ) {cout << ar [i] << ' '; }
#define looppu(num , ar) for (lli i = 0 ; i < num ;  i++) {lli x ; cin >> x ; ar . push_back (x) ;}
#define loopin(num , ar) for (lli i = 0 ; i < num ;  i++) {lli x ; cin >> x ; ar . insert (x) ;}

#define forr(num1 , num2) for (lli i = num1 ; i < num2 ; i ++ )
#define forrcin(num1 , num2 , ar ) for (lli i = num1 ; i < num2 ; i ++ ) {cin >> ar [i] ;}
#define forrcout(num1 , num2 , ar) for (lli i = num1 ; i < num2 ; i ++ ) {cout << ar [i] << ' '; }

#define D2forrcin(num1_1 , num1_2 , num2_1 , num2_2 , A ) for (lli i = num1_1 ; i < num1_2 ; i ++){ for (lli j = num2_1 ; j < num2_2 ; j++){cin >> A[i][j] ;}}
#define D2forrcout(num1_1 , num1_2 , num2_1 , num2_2 , A ) for (lli i = num1_1 ; i < num1_2 ; i ++){ for (lli j = num2_1 ; j < num2_2 ; j++){cout << A[i][j] << ' ' ;}cout << endl ;}

#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl

#define F first
#define S second
#define pb push_back
#define pf push_front
#define pob pop_back ()
#define pof pop_front ()

#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

signed main ()
{
    fastio
    ll n , x , mi = 1e9 , sum = 0 , cnt = 0 ;
    cin >> n >> x ;
    ll arr[n] ;
    loop(n){
        cin >> arr[i] ;
        mi = min (mi , arr[i]) ;
        sum += arr[i] ;
    }
    cnt = n - 1 ;
    sum -= mi ;
    for(ll i = 0 ;; i++){
        sum += mi ;
        if (sum > x)
            break ;
        cnt ++ ;
    }
    cout << cnt << endl ;

    return 0 ;
}

/*___________________________________________________________________functions___________________________________________________________________________*/



Measured memory_bytes: 256
#include <limits.h>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#define int long long
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REPS(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define FOR(i, a, b) for (int i = (a), i##_len = (b); i <= i##_len; ++i)
#define REV(i, a, b) for (int i = (a); i >= (b); --i)
#define CLR(a, b) memset((a), (b), sizeof(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define INF 1001001001001001001ll
#define fcout cout << fixed << setprecision(10)

using namespace std;

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

    int N;
    cin >> N;
    map<int, int> cnt;
    cnt[0] = 1;
    cnt[24] = 1;
    REP(i, N) {
        int d;
        cin >> d;
        cnt[d]++;
        cnt[24 - d]++;
    }

    if (cnt[0] > 1) {
        cout << 0 << endl;
        return 0;
    }

    // 右回り
    bool useNext = true;
    vector<int> r;
    FOR(i, 0, 24) {
        if (cnt.count(i) == 0) continue;
        if (cnt[i] >= 3) {
            cout << 0 << endl;
            return 0;
        }
        if (cnt[i] == 2 || i == 12 || i == 24) {
            r.push_back(i);
            continue;
        }
        if (cnt[i] == 1) {
            if (useNext) {
                r.push_back(i);
                useNext = false;
            }
            else
            {
                useNext = true;
            }
        }
    }

    int rans = INF;
    REP(i, r.size() - 1) {
        rans = min(rans, abs(r[i+1] - r[i]));
    }

    // 左回り
    useNext = true;
    vector<int> l;
    REV(i, 24, 0) {
        if (cnt.count(i) == 0) continue;
        if (cnt[i] >= 3) {
            cout << 0 << endl;
            return 0;
        }
        if (cnt[i] == 2 || i == 12 || i == 0) {
            l.push_back(i);
            continue;
        }
        if (cnt[i] == 1) {
            if (useNext) {
                l.push_back(i);
                useNext = false;
            }
            else
            {
                useNext = true;
            }
        }
    }

    int lans = INF;
    REP(i, l.size() - 1) {
        lans = min(lans, abs(l[i+1] - l[i]));
    }

    int ans = max(lans, rans);
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
package main

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

func main() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, initialBufSize), maxBufSize)
	defer wt.Flush()

	n := nextInt()
	x, y := make([]int, n), make([]int, n)
	for i := 0; i < n; i++ {
		a := nextInt()
		x[i], y[i] = a, a
	}
	sort.Sort(sort.IntSlice(y))

	center := y[n/2]

	for i := 0; i < n; i++ {
		var c int
		if x[i] < center {
			c = center
		} else if x[i] >= center {
			c = y[(n-1)/2]
		}
		puts(c)
	}
}

const (
	initialBufSize = 100000
	maxBufSize     = 10000000
)

var (
	sc = bufio.NewScanner(os.Stdin)
	wt = bufio.NewWriter(os.Stdout)
)

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	i, _ := strconv.Atoi(next())
	return i
}

func nextFloat64() float64 {
	f, _ := strconv.ParseFloat(next(), 64)
	return f
}

func nextInts(n int) []int {
	slice := make([]int, n)
	for i := 0; i < n; i++ {
		slice[i] = nextInt()
	}
	return slice
}

func nextFloat64s(n int) []float64 {
	slice := make([]float64, n)
	for i := 0; i < n; i++ {
		slice[i] = nextFloat64()
	}
	return slice
}

func putf(format string, a ...interface{}) {
	fmt.Fprintf(wt, format, a...)
}

func puts(a ...interface{}) {
	fmt.Fprintln(wt, a...)
}


Measured memory_bytes: 8960
#include <iostream>
#include <vector>
#include <algorithm>
#include <cassert>
#include <functional>
#include <numeric>
#include <limits>
#include <iomanip>
#include <queue>
#include <cmath>
#include <math.h>
#include <string>
#include <sstream>
#include <set>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
const long long INF = 1LL << 60;
using pll = pair<long long, long long>;
#define min(a, b) ((a) < (b) ? (a) : (b))


int main() {

    // 標準入力が早くなる。Cスタイルの入出力とC++スタイルの入出力を混合させてはならない。
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);

    int N;
    cin >> N;
    vector<int> X(N);

    for (size_t i = 0; i < N; i++)
    {
        cin >> X.at(i);
    }
    vector<long long> res(101, 0);

    for (int i = 1; i <= 100; i++) {
        for (int j = 0; j < N; j++) {
            res.at(i) += abs(X.at(j) - i) * abs(X.at(j) - i);
        }
    }
    sort(res.begin(), res.end());

    cout << res.at(1) << endl;

	return 0;
}


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

#ifdef ONLINE_JUDGE
#define freopen(N, M, Q)
#endif

#define ll long long
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define all(N) N.begin(), N.end()

using namespace std;

const ll INF = 1e9;

int main() {
    ios_base::sync_with_stdio(false);
	//freopen("input.txt", "r", stdin);

	string a, b;
	cin >> a >> b;

    int cnt = 0;
	for (int i = 0; i < a.size(); ++i)
	    if (a[i] == b[i])
	        cnt++;

	cout << cnt << endl;

    return 0;
}


Measured memory_bytes: 256
n, m = map(int, input().split())
good = [True] * n
h = list(map(int, input().split()))
for i in range(m):
    a, b = map(int, input().split())
    if h[a - 1] <= h[b - 1]:
        good[a - 1] = False
    if h[b - 1] <= h[a - 1]:
        good[b - 1] = False
rcnt = 0
for i in range(n):
    if good[i]:
        rcnt += 1
print(rcnt)


Measured memory_bytes: 20896
#include <iostream>
#include <sstream>
#include <string>
#include <vector>

using namespace std;

void read_separated_string(vector<int> &v, string str) {
  istringstream istr(str);
  string tmp;
  while (getline(istr, tmp, ' ')) {
    v.push_back(stoi(tmp));
  }
}

int main() {
  int N, Q;
  vector<int> n;
  vector<int> q;
  string str;
  cin >> N; cin.ignore();
  getline(cin, str);
  read_separated_string(n, str);
  cin >> Q; cin.ignore();
  getline(cin, str);
  read_separated_string(q, str);

  int count = 0;
  for (int i : q) {
    for (int j : n) {
      if (i == j) {
        count++;
        break;
      }
    }
  }
  cout << count << endl;
}

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

#define int long long

#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,m,n) for(int i=m;i<n;i++)
#define FORR(i,m,n) for(int i=m;i>=n;i--)
#define pb(x) push_back(x) 
#define SORT(x) sort((x).begin(),(x).end())
#define INF 99999999999

using namespace std;

int gcd(int a, int b){
    int r = a % b;
    if(r==0){
        return b;
    }
    else{
        return gcd(b, r);
    }
}

int lcm(int a, int b){
    return a*b/gcd(a, b);
}

int32_t main(){
    int n;
    cin >> n;
    vector<int> v(n);
    int cnt=0;
    REP(i, n){
        cin >> v[i];
        cnt+=(v[i]-1);
    }
    cout << cnt << endl;
}

Measured memory_bytes: 256
import java.util.*;
import java.util.Map.Entry;
 
 
 class Main {
	 static int mod =  (int) (Math.pow(10,9)+7);
	 static List<ArrayList<Integer>>  list = new ArrayList<ArrayList<Integer>>();
    public static void main(String[] args) {
    
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        long[] A = new long[N];
        
        long cnt=0;
        for(int i=0;i<N;i++) {
        	A[i]=sc.nextLong();
        }
        Arrays.sort(A);
        String ans="YES";
        for(int i=0;i<N-1;i++) {
        	if(A[i]==A[i+1]) {
        		ans="NO";;
        		break;
        	}
        }

        System.out.println(ans);        	
                		
    }
    
    
}

Measured memory_bytes: 65936
#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp> 
//#include <ext/pb_ds/tree_policy.hpp>
//#include <functional> // for less
//using namespace __gnu_pbds;
using namespace std;
typedef long long  L;
int main()
{
    char ch;
    cin>>ch;
    if(ch>='A'&&ch<='Z')printf("A\n");
    else printf("a\n");
    return 0;
}

Measured memory_bytes: 3688
#include <iostream>
#include <stdio.h>
#include <math.h>
using namespace std;

int main() {
    int a,b;
    char op;
    while(1) {
        cin >> a >> op >> b;
        if(op=='?')break;
        if (op == '+')cout << a + b << endl;
        else if (op == '-')cout << a - b << endl;
        else if (op == '*')cout << a * b << endl;
        else if (op == '/')cout << a / b << endl;
    }
    return 0;
    
}


Measured memory_bytes: 3092
// https://atcoder.jp/contests/abc170/tasks/abc170_b

#include <bits/stdc++.h>
using namespace std;
#define watch(x) cerr << (#x) << " is " << (x) << endl;
#define endl '\n' 

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

    int X, Y;
    cin >> X >> Y;

    for(int i = 0; i <= X; i++) {
        if(2*i + 4*(X-i) == Y) {
            cout << "Yes" << endl;
            return 0;
        }
    }

    cout << "No" << endl;
}

Measured memory_bytes: 3648
#include<stdio.h>
int main()
{
	char c;
	scanf("%c", &c);
	if(c == 'a' || c == 'i' || c == 'u' || c == 'e' || c == 'o') {
		printf("vowel");
	}
	else printf("consonant");
	return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a[3];
for(int i=0;i<3;i++)
cin>>a[i];
   int max=0;
sort(a,a+3);
max=a[2]*10+a[1]*1+a[0];
cout<<max;
return 0;
}

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

#define int long long

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPS(i,n) for(int i=1, i##_len=(n); i<=i##_len; ++i)

#define INF (3e9)

using namespace std;

int A, B, C, D, E, F;

signed main()
{
    cin >> A >> B >> C >> D >> E >> F;
    A *= 100;
    B *= 100;

    int maxSW = 0;
    int maxSG = 0;
    for (int i = 0; A*i <= F; ++i)
    for (int j = 0; A*i + B*j <= F; ++j)
    for (int m = 0; A*i + B*j + C*m <= F; ++m)
    for (int n = 0; A*i + B*j + C*m + D*n <= F; ++n)
    {
        int a = A*i + B*j;
        int b = C*m + D*n;
        if (a+b > F) continue;
        if (a/100 * E < b) continue;

        if (b*maxSW >= (a+b)*maxSG)
        {
            maxSW = a+b;
            maxSG = b;
        }
    }
    printf("%lld %lld\n", maxSW, maxSG);

    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cmath>
#include <ctime>
#include <iostream>
#include <list>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <string>
#include <tuple>
#include <vector>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n); i++)
#define all(a) begin(a),end(a)
typedef long long ll;
typedef pair<int,int> P;
const int inf=1000000007;
const ll mod=1000000007;
const double PI=3.14159265358979323846;
int dx[] = {1,-1,0,0};
int dy[] = {0,0,1,-1};
ll gcd(ll a, ll b){
  if (b==0) return a;
  else return gcd(b,a%b);
}
int cans(bool f){
  if(f) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}

using pll = pair<ll,ll>;
vector<pll> p;


int main() {
  ll N,M;
  cin >> N >> M;
  p.resize(N);
  rep(i,N){
    cin>>p[i].first>>p[i].second;
  }
  sort(all(p));
  ll res = 0;
  for(int i=0; i < N; i++) {
    res += p[i].first * min(M,p[i].second);
    M -= min(M,p[i].second);
    if(M == 0) break;
  }
  cout << res << endl;
  return 0;
}










Measured memory_bytes: 1792
//by yjz
#include<bits/stdc++.h>
using namespace std;
#define FF first
#define SS second
#define PB push_back
#define MP make_pair
typedef long long ll;
const int Imx=2147483647;
const int mod=1000000007;
const ll Lbg=2e18;
int n,m;
int dp2[3111][3111];
int dp[3111][3111];
inline void upd(int &x,int y)
{
	x+=y;
	if(x>=mod)x-=mod;
}
int main()
{
	cin>>n>>m;
	for(int j=1;j<=n;j++)dp[0][j]=1;
	for(int i=0;i<=m;i++)
	{
//		cout<<dp[i][0]<<" ";
		for(int j=1;j<=n;j++)
		{
			if(j>0)
			{
				upd(dp[i+1][j-1],dp[i][j]);
				if(j==1)upd(dp2[i+1][j],dp[i][j]);else upd(dp[i+1][j],dp[i][j]);
			}
			if(j<n)upd(dp[i+1][j+1],dp[i][j]),upd(dp[i+1][j],dp[i][j]);
//			cout<<dp[i][j]<<" ";
		}
//		cout<<endl;
	}
	dp2[0][0]=1;
	for(int i=0;i<=m;i++)
	{
		upd(dp2[i][0],dp[i][0]);
		for(int j=0;j<=i;j++)
		{
			if(j>0)upd(dp2[i+1][j-1],dp2[i][j]),upd(dp2[i+1][j],dp2[i][j]);
			if(j<n)upd(dp2[i+1][j+1],dp2[i][j]),upd(dp2[i+1][j],dp2[i][j]);
//			cout<<dp2[i][j]<<" ";
		}
//		cout<<endl;
	}
	ll ans=0;
	for(int i=0;i<=n;i++)ans+=dp2[m][i];
	cout<<ans%mod<<endl;
	return 0;
}

Measured memory_bytes: 74496
from collections import Counter
n,k,l = map(int, input().split())
def f(m):
    a = list(range(n))
    def g(i):
        if a[i] == i:
            return i
        a[i] = g(a[i])
        return a[i]
    for _ in range(m):
        p,q = map(int, input().split())
        i = g(p-1)
        j = g(q-1)
        a[j] = i
    return g
g = f(k)
h = f(l)
c = Counter((g(i),h(i)) for i in range(n))
print(' '.join((str(c[g(i),h(i)]) for i in range(n))))

Measured memory_bytes: 60516
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();

    sc.close();

    String[] S = s.split("");
    String[] T = t.split("");

    Arrays.sort(S);
    Arrays.sort(T, Comparator.reverseOrder());

    String S2 = "";
    
    for (int i = 0; i < S.length; i++) {
      S2 += S[i];
    }

    String T2 = "";

    for (int i = 0; i < T.length; i++) {
      T2 += T[i];
    }
    
    if (1 <= T2.compareTo(S2)) {
      System.out.println("Yes");
    } else {
      System.out.println("No");
    }

  }

}

Measured memory_bytes: 21716
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <map>

using namespace std;

int main(){
    int n;
    cin >> n;
    int A[25], B[55],C[55];

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

    for(int i = 0; i < n; i++){
        cin >> B[i];
    }
    
    for(int i = 0; i < n-1; i++){
        cin >> C[i];
    }    

    int ans = 0;
    int pre = 0;

    for(int i = 0; i < n; i++){
        int temp;
        temp = A[i];
        ans += B[temp-1];
        if(i > 0){
            if(pre + 1 == temp - 1){
                ans += C[pre];
            }
        }
        pre = temp - 1;
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
n = int(input())
t = 1
a = 1
for i in range(n):
    T, A = map(int, input().split())
    k = max(1, t // T + (t % T != 0), a // A + (a % A != 0))
    t = k * T
    a = k * A
print(t + a)


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

int main() {
  int num;
  cin >> num;
  string s = to_string(num);
  bool vane = false;
  for(int i=0;i<s.size();i++){
    if(s[i]=='7'){
      vane=true;
    }
  }
  if(vane==true){
    cout << "Yes";
  }else{
    cout << "No";
  }
	return 0;
}


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

int main() {
	long long A[90];
	A[0] = 2;
	A[1] = 1;
	for (int i = 2; i <= 86; i++) {
		A[i] = A[i - 1] + A[i - 2];
	}
	int n;
	cin >> n;
	cout << A[n] << endl;
}


Measured memory_bytes: 256
import Control.Monad (replicateM_)

type Point = (Double,Double)
type Radius = Double
type Circle = (Point,Radius)

main = do
    n <- readLn
    replicateM_ n (input >>= return . solve >>= output)

input :: IO (Circle,Circle)
input = do
    line <- getLine
    let
        [xa,ya,ra,xb,yb,rb] = map read $ words line
    return (((xa,ya),ra),((xb,yb),rb))

output :: String -> IO ()
output = putStrLn

solve :: (Circle,Circle) -> String
solve (((xa,ya),ra),((xb,yb),rb))
    | ra + rb < distance = "0"
    | distance + rb < ra = "2"
    | distance + ra < rb = "-2"
    | otherwise = "1"
    where
    distance = sqrt ((xa-xb)^2 + (ya-yb)^2)

Measured memory_bytes: 4452
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define all(x) (x).begin(), (x).end()
using ll = long long;
using namespace std;
template <typename T> using vec = std::vector<T>;

int main() {
    int N;
    cin >> N;
    int K = 200000;

    vec<vec<pair<int, char>>> T(K + 1), Y(K + 1), P(K * 2 + 10), M(K * 2 + 10);
    rep(i, N) {
        int x, y;
        char c;
        cin >> x >> y >> c;
        if (c == 'U' || c == 'D') {
            T[x].push_back({y, c});
            P[x + y].push_back({x, c});
            M[x - y + K].push_back({x, c});
        } else if (c == 'R' || c == 'L') {
            Y[y].push_back({x, c});
            P[x + y].push_back({x, c});
            M[x - y + K].push_back({x, c});
        }
    }

    int ans = 1e9;
    rep(i, K + 1) {
        int u = -1;
        sort(all(T[i]));
        for (auto [y, c] : T[i]) {
            if (c == 'U') u = y;
            else if (c == 'D' && u != -1) {
                ans = min(ans, (y - u)*10/2);
            }
        }
    }

    rep(i, K + 1) {
        int l = -1;
        sort(all(Y[i]));
        for (auto [x, c] : Y[i]) {
            if (c == 'R') l = x;
            else if (c == 'L' && l != -1) {
                ans = min(ans, (x - l)*10/2);
            }
        }
    }

    rep(i, K * 2 + 5) {
        int r = -1;
        int d = -1;
        sort(all(P[i]));
        for (auto [x, c] : P[i]) {
            if (c == 'R') r = x;
            else if (c == 'D')
                d = x;
            else if (c == 'U' && r != -1) {
                ans = min(ans, (x - r)*10);
            } else if (c == 'L' && d != -1) {
                ans = min(ans, (x - d)*10);
            }
        }
    }

    rep(i, K * 2 + 5) {
        int r = -1;
        int u = -1;
        sort(all(M[i]));
        for (auto [x, c] : M[i]) {
            if (c == 'R') r = x;
            else if (c == 'U')
                u = x;
            else if (c == 'D' && r != -1) {
                ans = min(ans, (x - r)*10);
            } else if (c == 'L' && u != -1) {
                ans = min(ans, (x - u)*10);
            }
        }
    }

    cout << ((ans == 1e9) ? "SAFE" : to_string(ans)) << endl;
}


Measured memory_bytes: 49736
import sys
import math

def str_input():
    S = raw_input()
    if S[len(S)-1] == "\r":
        return S[:len(S)-1]
    return S

def float_to_str(num):
    return str("{:.10f}".format(num))

def list_input(tp):
    return map(tp, str_input().split())

# # # # # # # # # # # # # # # # # # # # # # # # #

class Dice:
    pip = [0 for i in xrange(6)]

    def __init__(self, arg):
        self.pip = arg

    def rollDir(self, dr):
        nextPip = [0 for i in xrange(6)]
        if dr == "N":
            nextPip[0] = self.pip[1]
            nextPip[1] = self.pip[5]
            nextPip[2] = self.pip[2]
            nextPip[3] = self.pip[3]
            nextPip[4] = self.pip[0]
            nextPip[5] = self.pip[4]
        elif dr == "E":
            nextPip[0] = self.pip[3]
            nextPip[1] = self.pip[1]
            nextPip[2] = self.pip[0]
            nextPip[3] = self.pip[5]
            nextPip[4] = self.pip[4]
            nextPip[5] = self.pip[2]
        self.pip = nextPip

    def roll(self, dr):
        if dr == "N" or dr == "E":
            self.rollDir(dr)
        elif dr == "S":
            self.rollDir("N")
            self.rollDir("N")
            self.rollDir("N")
        elif dr == "W":
            self.rollDir("E")
            self.rollDir("E")
            self.rollDir("E")

    def check(self, a, b):
        while self.pip[0] != a:
            if self.pip[2] != a and self.pip[3] != a:
                self.roll("N")
            else:
                self.roll("N")
                self.roll("W")
                self.roll("S")

        while self.pip[1] != b:
            self.roll("N")
            self.roll("W")
            self.roll("S")
        return self.pip[2]

dice1 = Dice(list_input(int))
dice2 = Dice(list_input(int))

for i in xrange(4):
    for j in xrange(4):
        if dice1.pip == dice2.pip:
            print "Yes"
            sys.exit()
        dice2.roll("E")
    dice2.roll("N")
dice2.roll("N")
dice2.roll("E")
dice2.roll("S")
for i in xrange(4):
    if dice1.pip == dice2.pip:
        print "Yes"
        sys.exit()
    dice2.roll("E")
dice2.roll("N")
dice2.roll("E")
dice2.roll("E")
dice2.roll("S")
for i in xrange(4):
    if dice1.pip == dice2.pip:
        print "Yes"
        sys.exit()
    dice2.roll("E")

print "No"

Measured memory_bytes: 6540
#include<bits/stdc++.h>
#include<iomanip>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
typedef long long ll;
// typedef long  l;
typedef pair<int,int> P;
const ll INF=100000000000000001;
const double PI=3.141592653589;

int dp[30005][3];

int main(){
  int n,m; cin>>n>>m;
  vector<int> suki(m,0);
  rep(i,n){
    int k; cin>>k;
    rep(j,k){
      int a; cin>>a;
      a--;
      suki[a]++;
    }
  }
  int ans=0;
  rep(i,m){
    if(suki[i]==n)
    ans++;
    // cout<<suki[i]<<endl;
  }
  cout<<ans<<endl;

  return 0;
}


Measured memory_bytes: 256
# abc109_b

from collections import Counter


def solve(words):
    if Counter(words).most_common()[0][1] > 1:  # repetition is present
        return "No"
    else:
        # initial letter first word not important
        # final letter final word not important
        if list(map(lambda x: x[0], words[1:])) == list(map(lambda x: x[-1], words[:-1])):
            return "Yes"
        else:
            return "No"


def solve2(words):
    for i in range(len(words) - 1):
        if words[i] in words[i + 1:]:
            return "No"
        else:
            if words[i][-1] != words[i + 1][0]:
                return "No"
    return "Yes"


if __name__ == "__main__":
    N = int(input(""))
    words = [input("") for i in range(N)]
    print(solve2(words))


Measured memory_bytes: 3316
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 ans = a - 1;
		if(a <= b) ans++;
		System.out.println(ans);
	}
}


Measured memory_bytes: 21460
let n =
	Scanf.sscanf (read_line ()) "%d" (fun n -> n)

let str =
	let rec loop lst n =
		if n = 0 then lst
		else loop ((read_line ()) :: lst) (n - 1)
	in
	loop [] n

let () =
	List.sort compare str
	|> String.concat ""
	|> print_endline


Measured memory_bytes: 512
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
// const ll MOD = 1000000007;
// const int INF = 2000000000;

int A, B;

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

  int ans = 0;
  if (A >= 13) {
    ans = B;
  } else if (6 <= A && A <= 12) {
    ans = B / 2;
  }

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

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

signed main() {
  int N;cin>>N;
  std::vector<int> v(N,0),h(N);
  for(int i=0;i<N;i++)cin>>h[i];
  int ans=0;bool now=false;
  for(int i=0;i<N;i++){
    if(v[i]<h[i]){
      now=true;
      v[i]++;
    }
    else{
      if(now==true){
        ans++;i=-1;now=false;
      }
    }
    if(i==N-1&&now==true){
      ans++;i=-1;now=false;
    }
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
    string s;
    bool ok=true;
    cin>>s;
    int c[26]={0};
    for (int i=0; i<s.size(); i++)
    {
        c[s[i]-'a']++;
    }
    for (int i=0; i<26; i++)
    {
        if (c[i]%2==1) ok=false;
    }
    if (ok) cout<<"Yes\n";
    else cout<<"No\n";
    return 0;
}


Measured memory_bytes: 256
const main = (input) => {
  var lists = input.split("\n")[1].split(" ").map(v=>v-0);
  var ans = lists[0];
  for(var i=1;i<lists.length;i++){
    ans ^= lists[i];
  }
  console.log(ans == 0?"Yes":"No");
}

main(require('fs').readFileSync('/dev/stdin', 'UTF-8'));


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

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

  double dmean = (a + b) / 2.0;
  int imean = static_cast<int>(dmean);

  if (imean < dmean) {
    cout << imean + 1 << endl;
  } else if (imean == dmean) {
    cout << imean << endl;
  }
}

Measured memory_bytes: 256
#include<fstream>
#include<cstdlib>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<unordered_map>
#include<ctime>
#define DN 1000005
using namespace std;
int n,m,nr;
string s,t;
long long f,poz;
unordered_map<long long,char>mp;
int gcd(int a,int b)
{
    if(b==0)
        return a;
    return gcd(b,a%b);
}
long long cmmmc(int f,int g)
{
    return (1LL*f*g)/gcd(f,g);
}
int main()
{
    cin>>n>>m;
    cin>>s>>t;
    s=" "+s;
    t=" "+t;
    f=cmmmc(n,m);
    poz=1;
    while(poz<=f)
    {
        nr++;
        if(nr>n)
            break;
        mp[poz]=s[nr];
        poz+=f/n;

    }
    if(nr<n)
    {
        cout<<-1;
        return 0;
    }
    poz=1;
    nr=0;
    while(poz<=f)
    {
        nr++;
        if(nr>m)
            break;
        if(mp.find(poz)!=mp.end())
        if(mp[poz]!=t[nr])
        {
            cout<<-1;
            return 0;
        }
        poz+=f/m;
    }
    if(nr<m)
    {
        cout<<-1;
        return 0;
    }
    cout<<f;
}


Measured memory_bytes: 4224
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <iterator>
#include <list>
#include <map>
#include <queue>
#include <bitset>
#include <fstream>
#include <cmath>
#include <ctime>
#include <cstring>
#include <numeric>
using namespace std;
typedef long long ll;
typedef vector<int> vint;
typedef pair<int,int> pint;
#define REP(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define MSG(a) cout << #a << " "  << a << endl;
template<class T> void chmin(T &t, T f) { if (t > f) t = f; }
template<class T> void chmax(T &t, T f) { if (t < f) t = f; }

int dp[1000][1000];

int main()
{
	int w, h, n;
	while(cin >> h >> w >> n && w)
	{
		memset(dp, 0, sizeof(dp));
		vector<vint> field(w, vint(h));

		rep(y, h) rep(x, w)
			cin >> field[x][y];

		dp[0][0] = n-1;
		rep(x, w) rep(y, h)
		{
			// ðKêéê
			if(x+1 < w) 
				dp[x+1][y] += (dp[x][y] + dp[x][y] % 2 * -(1 - field[x][y] * 2)) / 2;
			
			// ìðKêéê
			if(y+1 < h)
				dp[x][y+1] += (dp[x][y] + dp[x][y] % 2 *  (1 - field[x][y] * 2)) / 2;
		}

		pint p = make_pair(0,0);
		while(p.first < w && p.second < h)
		{
			if(dp[p.first][p.second] & 1)
				field[p.first][p.second] = !field[p.first][p.second]; 

			if(field[p.first][p.second])
				p.first++;
			else
				p.second++;
		}

		cout << p.second + 1 << " " << p.first + 1 << endl;
	}
}

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

int ch,cv;
vector<int> sd;
vector<int> gd;
int dm[]={1,8,3,6};//h,h,v,v
typedef long long ll;
struct state{
  ll d;
  int c;
  bool operator<(const state &s) const {
    
    return c > s.c;
  }
};

ll getHash(vector<int> &d){
  ll s = 0;
  ll t = 1;
  for(int i=0;i<9;i++){
      s += d[i]*t;
      t *= 9;
  }
  return s;
}

vector<int> getrev(ll h){
  vector<int> g = vector<int>(9);
  for(int i=0;i<9;i++){
    g[i] = h%9;
    h/=9;
  }
  return g;
}


map<ll,int> H;

int get(const vector<int> &d){
  for(int i=0;i<9;i++){
    if( d[i] == 0 ) return i;
  }
  assert(false);
}

void view(const vector<int> &d){
  cout << "view" << endl;
  for(int i=0;i<9;i++){
    cout << d[i];
    if( (i+1)%3 == 0 ) cout << endl;
  }
  cout << endl;
}

int dijk(){
  priority_queue<state> q;
  H.clear();
  q.push( (state){getHash(sd),0} );
  H[getHash(sd)] = 0;
  while( !q.empty() ){
    state p = q.top(); q.pop();
    vector<int> nd = getrev(p.d);
    int c = p.c;

    if( nd == gd ) return c;
    if( H[p.d] < c ) continue;

    int ni = get(nd);
    for(int i=0;i<4;i++){
      int nc = c + ((i/2==0)?ch:cv);
      int nt = (ni + dm[i])%9;
      swap(nd[ni],nd[nt]);
      ll hs = getHash(nd);
      if( H.count(hs) == 0 || H[hs] > nc ){
        H[hs] = nc;
        q.push( (state){hs,nc} );
      }
      swap(nd[ni],nd[nt]);
    }
  }
  return -1;
}


int main(){
  while( cin >> ch >> cv && (ch||cv) ){
    sd = vector<int>(9);
    gd = vector<int>(9);
    for(int i=0;i<9;i++)
      cin >> sd[i];
    for(int i=0;i<9;i++)
      cin >> gd[i];
    cout << dijk() << endl;    
  }
}

Measured memory_bytes: 25912
import sys
from bisect import *
from heapq import *
from collections import *
from itertools import *
from functools import *
from math import *
from fractions import *

sys.setrecursionlimit(100000000)
input = lambda: sys.stdin.readline().rstrip()

def main():
    A, B, Q = map(int, input().split())
    s, t = [], []
    for _ in range(A):
        s.append(int(input()))
    for _ in range(B):
        t.append(int(input()))
    for _ in range(Q):
        x = int(input())
        i = bisect_left(s, x)
        j = bisect_left(t, x)
        # visit s[i - 1] or s[i]
        # visit t[j - 1] or t[j]
        s_candidates = [s[k] for k in [i - 1, i] if 0 <= k < A]
        t_candidates = [t[k] for k in [j - 1, j] if 0 <= k < B]
        ans = float('inf')
        for s_candidate in s_candidates:
            for t_candidate in t_candidates:
                right = max(x, s_candidate, t_candidate) - x
                left = x - min(x, s_candidate, t_candidate)
                ans = min(ans, min(right, left) * 2 + max(right, left))
        print(ans)






main()


Measured memory_bytes: 98648
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define forin(in, n) for(int i=0; i<n; i++) cin>>in[i]
#define forout(out) for(int i=0; i<(int)out.size(); i++) cout<<out[i]<<" "
#define rep(i, n) for(int i=0; i<(n); i++)

int main(){
    ll n; cin>> n;
    ll nn = sqrt(n);
    ll ans=10000000000000;
    for(int i=1; i<=nn; i++){
        if(n % i == 0){
            ans = min(ans, n/i + i - 2);
        }
    }
    cout<< ans << endl;
}

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

using namespace std;

const int N = 200100;
vector <int> g[N];
vector <int> a;

void compress(vector <int> &a) {
	vector <int> b = a;
	sort(b.begin(), b.end());
	b.resize(unique(b.begin(), b.end()) - b.begin());
	map <int, int> match;
	for (int i = 0; i < (int)b.size(); i++) {
		match[b[i]] = i;
	}
	for (int i = 0; i < (int)a.size(); i++) {
		a[i] = match[a[i]];
	}
}

vector <vector <pair <int, int>>> mem;
int inc[N];

void update(int p, int x) {
	mem.push_back({});
	for (; p < N; p = (p | (p + 1))) {
		mem.back().emplace_back(p, inc[p]);
		inc[p] = max(inc[p], x);
	}
}

int get(int p) {
	int res = 0;
	for (;p >= 0; p = (p & (p + 1)) - 1) {
		res = max(res, inc[p]);
	}
	return res;
}

void back() { 
	for (auto t : mem.back()) {
		int p = t.first;
		int val = t.second;
		inc[p] = val;
	}
	mem.pop_back();
}

int ans[N];

void dfs(int v, int p) {
	ans[v] = get(a[v] - 1) + 1;
	update(a[v], ans[v]);
	ans[v] = max(ans[v], get(N - 1));
	for (auto u : g[v]) {
		if (u == p) {
			continue;
		}
		dfs(u, v);
	}
	back();
}

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n;
	cin >> n;
	a.resize(n);
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	compress(a);
	
	for (int i = 0; i < n - 1; i++) {
		int u, v;
		cin >> u >> v;
		u--;
		v--;
		g[u].push_back(v);
		g[v].push_back(u);
	}
	
	dfs(0, -1);
	
	for (int v = 0; v < n; v++) {
		cout << ans[v] << "\n";
	}
	
	return 0;
}


Measured memory_bytes: 54644
#include<stdio.h>

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

Measured memory_bytes: 896
#include <stdio.h>

int main() {

  int cards[4][13] = {0};
  char class;
  int num, n;
  int i = 0, j;

  scanf("%d", &n);
  
  while(i < n) {
    scanf(" %c %d", &class, &num);
    switch(class) {
    case 'S': cards[0][num-1] = 1; break;
    case 'H': cards[1][num-1] = 1; break;
    case 'C': cards[2][num-1] = 1; break;
    case 'D': cards[3][num-1] = 1; break;
    default: break;
    }
    i++;
  }

  for(i = 0; i < 4; i++)
    for(j = 0; j < 13; j++)
      if(cards[i][j] == 0) {
	switch(i) {
	case 0: printf("S "); break;
	case 1: printf("H "); break;
	case 2: printf("C "); break;
	case 3: printf("D "); break;
	default: break;
	}
	printf("%d\n", j+1);
      }
	
  return 0;  
}

Measured memory_bytes: 596
n, m = [int(x) for x in input().split()]
g = [[] for _ in range(n)]
for _ in range(m):
    a, b = [int(x) for x in input().split()]
    g[a - 1].append(b - 1)
    g[b - 1].append(a - 1)
for gv in g:
    print(len(gv))

Measured memory_bytes: 3060
#前からと後ろ側から最大公約数を求めていけば途中で抜くべき値がある。2つ直すことはできないのでどちらかは最大になる。
#0と何かの数字xの最大公約数はx

from fractions import gcd
n = int(input())
a = list(map(int,input().split()))
l = [0]
r = [0]
ans = 0
for i in range(n-1):
    l.append(gcd(l[i],a[i]))
for i in range(n-1):
    r.append(gcd(r[i],a[n-1-i]))
for i in range(n):
    ans = max(ans,gcd(l[i],r[-i-1]))
print(ans)

Measured memory_bytes: 92256
#include <cstdio>

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

    for (int i = 0; i <= n; ++i)
    {
        if (i % 4 == 0 && (n - i) % 7 == 0)
        {
            printf("Yes\n");
            return 0;
        }
    }
    printf("No\n");
    return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <cstring>
#include <fstream>
#include <cmath>
#include <iomanip>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <map>
#include <deque>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <list>
#include <unordered_map>
#include <bitset>
#include <sstream>

typedef  long long ll;
#define mop 1000000007
using namespace std;

int main() {
   
    int a,b;
    cin >> a >> b;
    cout << max(0, a-2*b) << endl;
}

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

#define __STDC_FORMAT_MACROS
#define p64 PRId64

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR (i, 0, n)
#define ALL(f, x, ...)                                                         \
    ([&] (decltype ((x)) ALL) {                                                \
        return (f) (begin (ALL), end (ALL), ##__VA_ARGS__);                    \
    }) (x)

using namespace std;
using ll = int64_t;

int main() {
    int A, B, C;
    cin >> A >> B >> C;
    cout << (A < B + C ? B + C - A : 0) << endl;
    return 0;
}

Measured memory_bytes: 3628
import java.io.PrintWriter

fun main() {
    PrintWriter(System.out).use { out ->
        solve(out)
        out.flush()
    }
}

fun solve(out: PrintWriter) {
    val n = readLong()
    var ans = 0L

    // O(n^2)
//    for (i in 1..n) {
//        for (j in 1..n) {
//            if (i % j == 0L) {
//                ans += i
//            }
//        }
//    }

    // O(nlogn)
//    for (j in 1..n) {
//        for (i in 0..n step j) {
//            ans += i
//        }
//    }
    
    // O(n)
    for (i in 1..n) {
        val tmp = n / i
        ans += (tmp + 1) * tmp / 2 * i
    }
    println(ans)
}

fun readInteger() = readLine()!!.toInt()
fun readLong() = readLine()!!.toLong()
fun readStringList() = readLine()!!.split(" ")
fun readIntegerList() = readStringList().map(String::toInt)
fun readLongList() = readStringList().map(String::toLong)
fun readDoubleList() = readStringList().map(String::toDouble)


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

int prod[10][10];
int n;

int main() { // claudio van
  for (int i = 0; i < 10; ++i) {
    for (int j = 0; j < 10; ++j) {
      prod[i][j] = i * j;
    }
  }
  cin >> n;
  for (int i = 0; i < 10; ++i) {
    for (int j = 0; j < 10; ++j) {
      if (n == prod[i][j]) {
        puts("Yes");
        return 0;
      }
    }
  }
  puts("No");
  return 0;
}

Measured memory_bytes: 256
N,M = map(int,input().split())
L = []
for _ in range(M):
    L.append(int(input()))

counts = [1,1]+[0 for _ in range(10**6)]

for i in range(M):
    counts[L[i]-1] = -1

MOD = 10**9 + 7
for i in range(10**5+1):
    if counts[i] == -1:
        continue
    if counts[i+1] != -1:
        counts[i+1] += counts[i]
        counts[i+1] %= MOD
    if counts[i+2] != -1:
        counts[i+2] += counts[i]
        counts[i+2] %= MOD
print(counts[N-1]%MOD)


Measured memory_bytes: 118488
#!/usr/bin/python
# coding: UTF-8
 
n, a, b = map(int,input().split())
 
if n == 1:
  print(1 if a == b else 0)
else:
  if b >= a:
    print((b - a)*(n - 2) + 1)
  else:
    print(0)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,l,r) for(long long i=(l);i<(r);++i)
#define REP(i,n) FOR(i,0,n)
#define REPS(i,n) FOR(i,1,n+1)
#define RFOR(i,l,r) for(long long i=(l);i>=(r);--i)
#define RREP(i,n) RFOR(i,n-1,0)
#define RREPS(i,n) RFOR(i,n,1)
#define int long long

struct UnionFind {
    public:
    vector<int> par;
    UnionFind(int n){
        par=vector<int>(n,-1);
    }
    int root(int x){
        if(par[x]<0)return x;
    return par[x]=root(par[x]);
    }
    bool issame(int x,int y){
        return root(x)==root(y);
    }
    bool merge(int x,int y){
        x=root(x);
        y=root(y);
        if(x==y)return false;
        if(par[x]>par[y])swap(x,y);
        par[x]+=par[y];
        par[y]=x;
        return true;
    }
    int size(int x){
        return -par[root(x)];
    }
};

signed main(){
    int n, k, l; cin >> n >> k >> l;
    UnionFind u1(n),u2(n);
    REP(i,k){
        int a, b; cin >> a >> b; a--; b--;
        u1.merge(a,b);
    }
    REP(i,l){
        int a, b; cin >> a >> b; a--; b--;
        u2.merge(a,b);
    }
    map<pair<int,int>,int> mp;
    REP(i,n) mp[{u1.root(i),u2.root(i)}]++;
    REP(i,n) cout << mp[{u1.root(i),u2.root(i)}] << " ";
}

Measured memory_bytes: 15104
N,K=map(int, input().split())
H=list(map(int, input().split()))
for i in range(N):
    H[i]=-H[i]
import heapq as hq
hq.heapify(H)
if K>N:
    K=len(H)
for i in range(K):
    a=hq.heappop(H)
#print(H)
total=0
for i in range(len(H)):
    total-=H[i]
print(total)
#total+=K
#print(total)


Measured memory_bytes: 26176
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define loop(i,a,b) for (int i=a; i<b; ++i)
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll N,K;
    ll mod=1e9+7;
    cin >> N >> K;
    vector <ll> A(N);
    loop(i,0,N) cin >> A[i];
    ll ans=0;
    loop(i,0,N)
    {
        loop(j,0, N)
        {
            if (A[j]<A[i])
            {
                if (j>i) {ans+= (K*(K+1))/2; ans%=mod;}
                if (i>j) {ans+= (K*(K-1))/2; ans%=mod;}
            }
        }
    }
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)n; ++i)
#define repi(i, a, b) for (int i = int(a); i < int(b); ++i)
#define repr(i, n) for (int i = (int)n - 1; i >= 0; --i)
#define ALL(a) (a).begin(), (a).end()
const ll mod = 1e9 + 7;

int main() {
  int n, sum = 0;
  cin >> n;
  pair<string, int> p[n];
  rep(i, n) {
    string s;
    int x;
    cin >> s >> x;
    p[i] = make_pair(s, x);
    sum += x;
  }
  string t;
  cin >> t;
  rep(i, n) {
    if (p[i].first != t)
      sum -= p[i].second;
    else {
      sum -= p[i].second;
      break;
    }
  }
  cout << sum << endl;
  return 0;
}

Measured memory_bytes: 256
#pragma once
#include <stdio.h>
#include <sstream>
#include <string>
#include <string.h>
#include <vector>
#include <map>
#include <algorithm>
#include <iostream>
#include <utility>
#include <set>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <deque>
#include <limits>
#include <iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define bit(x,v) ((ll)x << v)

const ll INF = 1000000007;
const int MAX = 210000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}

// 二項係数計算
long long COM(int n, int k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}
int pr[100010];
void uini(int n) {
	for (size_t i = 0; i <= n; i++)
	{
		pr[i] = i;
	}
}

int parent(int x) {
	if (x == pr[x]) return x;
	return pr[x] = parent(pr[x]);
}

bool unit(int x, int y) {
	int px = parent(x);
	int py = parent(y);

	if (px == py) return false;
	if (px < py) {
		pr[py] = px;
	}
	else {
		pr[px] = py;
	}
	return true;
}

// res[i][c] := i 文字目以降で最初に文字 c が登場する index (存在しないときは n)
vector<vector<int> > calcNext(const string& S) {
	int n = (int)S.size();
	vector<vector<int> > res(n + 1, vector<int>(26, n));
	for (int i = n - 1; i >= 0; --i) {
		for (int j = 0; j < 26; ++j) res[i][j] = res[i + 1][j];
		res[i][S[i] - 'a'] = i;
	}
	return res;
}
void call(int n) {
	int i = 1;
CHECK_NUM:
	int x = i;
	if (x % 3 == 0) {
		cout << " " << i;
		goto END_CHECK_NUM;
	}
INCLUDE3:
	if (x % 10 == 3) {
		cout << " " << i;
		goto END_CHECK_NUM;
	}
	x /= 10;
	if (x) goto INCLUDE3;
END_CHECK_NUM:
	if (++i <= n) goto CHECK_NUM;

	cout << endl;
}
void solv() {

	int n;
	cin >> n;
	map<char, int> mp;
	mp['S'] = 0; mp['H'] = 1; mp['C'] =2; mp['D'] = 3;

	int pp[4][15];
	memset(pp, 0, sizeof(pp));
	for (size_t i = 0; i < n; i++)
	{
		char v;
		int c;
		cin >> v >> c;
		pp[mp[v]][c] = 1;
	}
	for (size_t i = 0; i < 4; i++)
	{
		for (size_t j = 1; j <= 13; j++)
		{
			if (pp[i][j] == 0) {
				if (i == 0) { cout << "S" << " "; }
				if (i == 1) { cout << "H" << " "; }
				if (i == 2) { cout << "C" << " "; }
				if (i == 3) { cout << "D" << " "; }
				cout << j << endl; 
			}
		}
	}
}

int main() {
	//	COMinit();
	solv();

	return 0;
}



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

int main(){
  int n,bit;
  cin >>n;
  int tmp,ans=0;
  int flag;
  vector<vector<pair<int,int>>>syogen(n);
  for(int i=0;i<n;i++){
    cin >> tmp;
    syogen.at(i).resize(tmp);
    for(int j=0;j<tmp;j++){
      cin >> syogen.at(i).at(j).first;
      cin >> syogen.at(i).at(j).second;
      syogen.at(i).at(j).first-=1;
    }
  }
  for(bit=0;bit<(1<<n);bit++){
    flag=0;
    for(int j=0;j<n;j++){
      if(!(bit>>j&1))continue;
      for(auto k:syogen.at(j)){
        if((k.second==1&&!((bit>>k.first)&1))||k.second==0&&((bit>>k.first)&1)){
          flag=1;
        }
      }
    }
    if(flag==0){
      tmp=0;
      for(int i=0;i<n;i++){
        if((bit>>i)&1)
          tmp++;
      }
      ans=max(ans,tmp);
    }
  }
  cout << ans<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
 
using namespace std;
 
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}
 
template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(vector<vector<T>> x){cerr<<"\n{"; int f=x.size();for(int i=0;i<f;i++){cerr<<"("; int g=x[i].size(); for(auto j:x[i]){cerr<<j; (--g!=0)?cerr<<",":cerr<<"";}cerr<<")\n";}cerr<<"}";}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void __print(vector<bool> x){cerr<<"{";int f=x.size();for(auto i:x){cerr<<i;(--f !=0)?cerr<<",":cerr<<"";}cerr<<"}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
 
#ifndef ONLINE_JUDGE
#define trace(x...) cerr << "[" << #x << "] = [", _print(x)
#else
#define trace(x...)
#endif
 
template<typename... T>
void read(T&... args) {
    ((cin >> args), ...);
}
 
template<typename... T>
void writ(T&&... args) {
    ((cout << args << " "), ...);
}
#define ull unsigned long long
#define ll long long
#define MOD 1000000007
#define INF (ll)1e18
#define IINF (int)1e9
#define EPS 1e-9

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll d,t,s; cin>>d>>t>>s;
    if((t*s)>=d) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}



Measured memory_bytes: 3656
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <vector>
#include <map>
#include <set>
#include <list>
#include <algorithm>
#include <iostream>
#include <string>

#define REP(i, n) for(int i=0;i<n;++i)
#define REPR(i, n) for(int i=n;i>=0;--i)
#define REPI(itr, v) for(auto itr=v.begin();itr!=v.end();++itr)
#define SORT(v, n) sort(v, v+n)
#define SORTV(v) sort(v.begin(), v.end())
#define llong long long
#define INF 999999999
#define SUR 1000000007
#define pb(a) push_back(a)

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

using namespace std;

int main(){
  
  int n;
  llong sum = 0;
  vector<int> v;

  scanf("%d", &n);
  REP(i, n){
    int t;
    scanf("%d", &t);
    v.pb(t);
    if(i != 0)
      sum += t;
  }

  llong res = llabs(sum - v[0]), cur = v[0];
  for(int i = 1; i < n - 1; ++i){
    cur += v[i];
    sum -= v[i];
    res = min(res, llabs(sum - cur));
  }

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

  return 0;
}



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

//オイラーのφ関数なんて分からない笑
//オイラーのφ関数を見て回答を作成することにした。

int main()
{
    int n;
    double p;
    vector<double> v;
    v.push_back(-1);
    
    cin >> n;

    p = n;

    for( int i = 2; i <= n; i++ )
    {
        while( n % i == 0 )
        {
            if( v[v.size()-1] != i )
                v.push_back(i);
            n /= i;
        }
    }

    for( int i = 1; i < v.size(); i++ )
        p *= ( 1 - 1 / v[i] );
    
    cout << (int)p << endl;

    return 0;
}


Measured memory_bytes: 3148