akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <cmath>

int people;
int score[1000];

int main(){	

	while(1){
		int sum =0;
		scanf("%d", &people);
		if(people == 0){
			break;
		}
		for(int i=0; i<people; ++i){
			scanf("%d", &score[i]);
			sum += score[i];
		}
		double mean = 0.;
		double temp = 0.;
		double deviation = 0.;
		double error = 0.;
		
		mean = (double)sum / (double)people;
		
		for(int i=0; i<people; ++i){
			error = (double)score[i] - mean;
			temp += error*error;
		}	
		deviation = sqrt(temp / (double)people);		
		printf("%.8lf\n", deviation);
	}
	
}


Measured memory_bytes: 2720
fn main() {
    let (first, second) = {
        let input = get_input_read_line();
        let numbers : Vec<i32> = input
                                    .split(" ")
                                    .map(|value| value.trim().parse().unwrap())
                                    .collect();
        (numbers[0], numbers[1])
    };

    match second % first {
        0 => println!("{:?}", first + second),
        _ => println!("{:?}", second - first)
    };
}

fn get_input_read_line() -> String {
    let mut input = String::new();
    std::io::stdin().read_line(&mut input).ok();
    input
}


Measured memory_bytes: 4352
import java.io.*;
  
public class Main {
  
    public static void main(String[] args){
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        try{
        
        String[] data = br.readLine().split(" ");
        int a = Integer.parseInt(data[0]);
        int b = Integer.parseInt(data[1]);
 
        System.out
            .println((a / b) + " " + (a % b) + " "
                + String.format("%.5f", ((double) a / (double) b)));
                
    }catch(IOException e){}
    }
}

Measured memory_bytes: 24732
A = int(input())
B = int(input())
C = int(input())
X = int(input())
count = 0
for a in range(A+1):
    for b in range(B+1):
        for c in range(C+1):
            if 500*a + 100*b + 50*c == X:
                count += 1
print(count)

Measured memory_bytes: 3060
while True:
    try:
        lst = list(map(int, input().split()))
        a, b, c, d, e, f = lst[0], lst[1], lst[2], lst[3], lst[4], lst[5]
        x = (b*f - c*e)/(b*d - a*e)
        y = (c*d - a*f)/(b*d - a*e)
        print('{:.3f}'.format(x+0.0), end = " ")
        print('{:.3f}'.format(y+0.0))
    
    except:
        break


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

int main() {
	int n,x;
	cin>>n;
	vector<int>v;
	for(int i=0;i<n;i++){
	    cin>>x;
	    v.push_back(x);
	}
	vector<int>result(n,INT_MAX);
	result[0]=0;
	for(int i=0;i<n;i++){
	    for(int j:{i+1,i+2}){
                if(j<n){
	            result[j]=min(result[j],abs(v[i]-v[j])+result[i]);}
	    }
	}
// 	for(auto it=result.begin();it!=result.end();it++){cout<<*it<<endl;}
	cout<<*(result.end()-1);
	
	return 0;
}







Measured memory_bytes: 1144
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define all(v) v.begin(),v.end()
#define inf (int)(3e18)
#define P pair<int,int>
#define mod (int)(1e9+7)

template<class T> inline void chmin(T &a, T b) {
	a = min(a, b);
}
template<class T> inline void chmax(T &a, T b) {
	a = max(a, b);
}

int N,M;
vector<vector<int>>G;
bool flag=true;
int co[100005];
int wh,bl;
void dfs(int x){
    if(co[x]==1)wh++;
    else bl++;
    for(int i:G[x]){
        if(co[i]&&co[i]==co[x]){
            flag=false;return;
        }
        if(co[i])continue;
        co[i]=co[x]*-1;
        dfs(i);
    }
}
signed main(){
    cin>>N>>M;G.resize(N);
    rep(i,M){
        int a,b;cin>>a>>b;a--;b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    co[0]=1;
    dfs(0);
    if(flag){
        cout<<wh*bl-M<<endl;
    }else {
        cout<<N*(N-1)/2-M<<endl;
    }
}

Measured memory_bytes: 7296
s = raw_input().strip()
t = 'keyence'
for i in xrange(7):
    if s[i] != t[i]:
        break
else:
    i = 8
for j in xrange(7):
    if s[-j-1] != t[-j-1]:
        break
else:
    j = 8
print "YES" if i + j >= 7 else "NO"


Measured memory_bytes: 2568
#include <iostream>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#define INF 1.0e9
using namespace std;
typedef long long ll;

int X;

int main() {
    cin >> X;
    if (X == 3 || X == 5 || X == 7) cout << "YES" << endl;
    else cout << "NO" << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<functional>
#include<queue>
#include <iomanip>
#include<map>
#include<limits>
#include<cmath>
#include<algorithm>
#include<bitset>
#include<utility>
#include<complex>
#include<cstdlib>
#include<set>
#include<cctype>

#define DBG cerr << '!' << endl;
#define REP(i,n) for(int (i) = (0);(i) < (n);++i)
#define rep(i,s,g) for(int (i) = (s);(i) < (g);++i)
#define rrep(i,s,g) for(int (i) = (s);i >= (g);--(i))
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {for(int i = 0;i < (n);i++)cerr << v[i] << ' ';cerr << endl << endl;}
#define SHOW2d(v,i,j) {for(int aaa = 0;aaa < i;aaa++){for(int bbb = 0;bbb < j;bbb++)cerr << v[aaa][bbb] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()

using namespace std;

typedef long long ll;
typedef vector<int> iv;
typedef vector<iv> iiv;
typedef vector<string> sv;

int main()
{
	int n;cin >> n;
	
	vector<ll> va(n);
	vector<ll> vb(n);
	vector<ll> vc(n);
	
	REP(i,n)cin>>va[i];
	REP(i,n)cin>>vb[i];
	REP(i,n)cin>>vc[i];
	
	sort(ALL(va));
	sort(ALL(vb));
	sort(ALL(vc));
	
	
	ll ans = 0;
	
	REP(i,n)
	{
		ans += (lower_bound(ALL(va),vb[i])-va.begin()) * (vc.end() - upper_bound(ALL(vc),vb[i]));
	}

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

Measured memory_bytes: 2560
#include<bits/stdc++.h>
#define fo0n for(int i=0;i<n;i++)
const int M =1e9+7;
const int N=1e5+3;
typedef long long ll;
typedef unsigned long long ull;
typedef double ld;
using namespace std;
struct node{
	int x,y;
};
void solve (){
	int n,m;
	cin>>n>>m;
	cout<<n-m+1;
}
int main(){
	int t=1;
	//cin>>t;
	while(t--){
		solve();
	}
}




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

int main() {
  string s;
  cin>>s;
  int q;
  cin>>q;
  int ti,fi;
  char ci;
  bool rev = false;
  vector<char> c1, c2;
  rep(i,q) {
    cin>>ti;
    if(ti==1){
      if (rev) rev=false;
      else rev=true;
    } else {
      cin>>fi>>ci;
      if ((!rev and fi==1) or (rev and fi==2)) {
        c1.push_back(ci);
      } else {
        c2.push_back(ci);
      }
      
    }
  }
  
  if (rev) {
    reverse(c2.begin(),c2.end());
    rep(i,c2.size()) cout<<c2[i];
    reverse(s.begin(),s.end());
    cout << s;
    rep(i,c1.size()) cout << c1[i];
  } else {
    reverse(c1.begin(),c1.end());
    rep(i,c1.size()) cout << c1[i];
    cout << s;
    rep(i,c2.size()) cout<<c2[i];
  }
  
}


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

int number_of_ways(int K) {
    // se for par
    if (K % 2 == 0) {
        int x;
        x = K/2;
        return (x * x);
    }
    // se for impar
    else {
        int y;
        y = (K - 1)/2;
        int w;
        w = y + 1;
        return (w * y);
    }
}

int main() {

    int K;

    cin >> K;

    cout << number_of_ways(K) << endl;
}


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

#include <boost/range/adaptors.hpp>
#include <boost/range/irange.hpp>

using namespace std;
using namespace boost;
using namespace boost::adaptors;

int64_t root(vector<int64_t>& g, int64_t v) {
    if (g[v] != v) {
        g[v] = root(g, g[v]);
    }

    return g[v];
}

void merge(vector<int64_t>& g, int64_t v, int64_t u) {
    g[root(g, v)] = root(g, u);
}

int main() {
    int64_t n, m;
    cin >> n >> m;

    vector<int64_t> a(n);
    for (auto&& aa : a) {
        cin >> aa;
    }

    vector<int64_t> g(n);
    iota(g.begin(), g.end(), 0L);

    auto b = a;
    int64_t c = n;
    for (auto _ : irange(0L, m)) {
        int64_t x, y;
        cin >> x >> y;

        if (root(g, x) != root(g, y)) {
            int64_t tmp = min(b[root(g, x)], b[root(g, y)]);
            merge(g, x, y);
            b[root(g, x)] = tmp;
            --c;
        }
    }

    if (n < 2 * (c - 1)) {
        cout << "Impossible" << endl;
        return 0;
    }

    if (c == 1) {
        cout << 0 << endl;
        return 0;
    }

    int64_t ans = 0;
    vector<int64_t> r;
    for (auto i : irange(0L, n)) {
        if (b[root(g, i)] == a[i]) {
            b[root(g, i)] = 1L << 40;
            ans += a[i];
        } else {
            r.push_back(a[i]);
        }
    }

    sort(r.begin(), r.end());
    for (auto i : irange(0L, 2 * (c - 1) - c)) {
        ans += r[i];
    }

    cout << ans << endl;
}

Measured memory_bytes: 3704
h, w, k = map(int,input().split())
import copy

def generate_n_bit(n):
    bins= []
    for i in range(2**n):
        bins.append(list(str(format(i,'b').zfill(n))))
    
    return bins

h_all = generate_n_bit(h)
w_all = generate_n_bit(w)
ans = 0

field = [list(input()) for i in range(h)]

for i_l in h_all:
    for j_l in w_all:
        c  = 0 
        fields = copy.deepcopy(field)
       
        
        for i_i, i in enumerate(i_l):
            for j_i, j in enumerate(j_l):
            
                if i == '1':
                    for a in range(w):
                        fields[i_i][a] = 'r'
                    
                if j == '1':
                    for b in range(h):
                        fields[b][j_i] = 'r'
        
        for q in range(h):
            for e in range(w):
                if fields[q][e] == '#':
                    c += 1
       
        if c == k:
            ans += 1
        
        
                
print(ans)


Measured memory_bytes: 9168
#include <iostream>
#include <vector>
#include <string>
 
using namespace std;
 
int main(void) {
    int n;
    int tan[5] = {5,7,5,7,7};
    cin >> n;
    while (n != 0) {
        vector<string> str(n);
        for (int i = 0; i < n; ++i) {
            cin >> str[i];
        }
        bool find = false;
        bool over = false;
        int ind = 0;
        int ln = 0;
        int ret;
        for (int i = 0; !find && i < n; ++i) {
            over = false;
            ind = 0;
            ln = 0;
            for (int j = i; !over && j < n; ++j) {
                if (ln + str[j].length() == tan[ind]) {
                    if (ind == 4) {
                        find = true;
                        ret = i+1;
                    }
                    else {
                        ++ind;
                        ln = 0;
                    }
                }
                else if (ln + str[j].length() < tan[ind]) {
                    ln += str[j].length();
                }
                else {
                    over = true;
                }
            }
        }
        cout << ret << endl;
        cin >> n;
    }
    return 0;
}

Measured memory_bytes: 3108
#include<bits/stdc++.h>
#define ll long long

const int N = 20;

ll ans = 0;
int d;
int a[N];
ll power[N], coe[N], suf[N];

void dfs(int dep, int sz, ll now, bool flag){
	if (dep == sz){
		if (now == d){
			ll ret = 1;
			for (int i = 0; i < sz; ++ i){
				ret *= 10 - std::abs(a[i]) - !i;
			}
			if (flag){
				ret *= 10;
			}
			ans += ret;
		}
		return;
	}
	if (std::abs(now - d) > suf[dep]){
		return;
	}
	for (int i = -9; i <= 9; ++ i){
		a[dep] = i;
		dfs(dep + 1, sz, now + coe[dep] * i, flag);
	}
}

int main(){
	power[0] = 1;
	for (int i = 1; i <= 18; ++ i){
		power[i] = power[i - 1] * 10;
	}
	scanf("%d", &d);
	for (int i = 2; i <= 18; ++ i){
		for (int j = 0; j < i >> 1; ++ j){
			coe[j] = power[i - j - 1] - power[j];
		}
		for (int j = (i >> 1) - 1; ~j; -- j){
			suf[j] = suf[j + 1] + coe[j] * 9;	
		}
		dfs(0, i >> 1, 0, i & 1);
	}
	return printf("%lld\n", ans), 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.stream.Stream;

class Main {

	final static int MAX = 1_000;
	final static int VMAX = 10_000;

	static int n, small;
	static int[] a;
	static int[] b = new int[MAX];
	static int[] truery = new int[VMAX+1];

	public static void main(String[] args) {

		try(BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {

			n = Integer.parseInt(br.readLine());
			a = Stream.of(br.readLine().split(" ")).mapToInt(Integer::parseInt).toArray();

		} catch (IOException e) {
			e.printStackTrace();
		}

		small = VMAX;
		for(int w : a) {
			small = Math.min(small, w);
		}

		int ans = solve();
		System.out.println(ans);

	}

	private static int solve() {
		int ans = 0;
		b = Arrays.copyOf(a, n);						// ??£?????????????????????b
		boolean[] valid = new boolean[MAX];			// ??£?????????????????§?????£???????????????????????£???????????????

		Arrays.sort(b);
		for (int i = 0; i < n; i++) truery[b[i]] = i;	// ????????????number?????¬??\?????????????????????????¨????

		for (int i = 0; i < n; i++) {
			if (valid[i]) continue;
			int cur = i;
			int sum = 0;		// ??????????????????????????????
			int min = VMAX;		// ??????????????§????°???????
			int an = 0;			// ?????????????´???°

			while(true) {
				valid[cur] = true;
				an++;
				int val = a[cur];
				min = Math.min(min, val);
				sum += val;
				cur = truery[val];
				if (valid[cur]) break;
			}

			ans += Math.min( sum + (an-2) * min, min + sum + (an+1) * small );

		}
		return ans;
	}
}

Measured memory_bytes: 31196
#include<algorithm>//sort,二分探索,など
#include<bitset>//固定長bit集合
#include<cmath>//pow,logなど
#include<complex>//複素数
#include<deque>//両端アクセスのキュー
#include<functional>//sortのgreater
#include<iomanip>//setprecision(浮動小数点の出力の誤差)
#include<iostream>//入出力
#include<iterator>//集合演算(積集合,和集合,差集合など)
#include<map>//map(辞書)
#include<numeric>//iota(整数列の生成),gcdとlcm(c++17)
#include<queue>//キュー
#include<set>//集合
#include<stack>//スタック
#include<string>//文字列
#include<unordered_map>//イテレータあるけど順序保持しないmap
#include<unordered_set>//イテレータあるけど順序保持しないset
#include<utility>//pair
#include<vector>//可変長配列

#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using P = pair<int,int>;
using ll = long long;
const int INF = 100005;
const int MAX_N = 100005;

bool comp(P a, P b){
    if(a.second != b.second){
        return a.second < b.second;
    }else{
        return a.first < b.first;
    }
}

int n;
int main(){
    cin >> n;
    vector<P> a,b;
    int x,y;
    rep(i,n){
        cin >> x >> y;
        a.push_back(make_pair(x,y));
    }

    rep(i,n){
        cin >> x >> y;
        b.push_back(make_pair(x,y));
    }

    sort(a.rbegin(),a.rend());
    sort(b.begin(),b.end(),comp);

    int count =0;
    

    rep(i,n){
        for(int j=0; j<b.size(); j++){
            if(a[i].first < b[j].first && a[i].second < b[j].second ){
                count ++;
                b.erase(b.begin()+j);
                break;
            }
        }
    }

    cout << count << endl;

}

Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, start, end) for (int i = (start); i <= (int)(end); i++)

int main(){
  int n,m;
  cin >> n >> m;
  vector<int> height(n);
  vector<int> cond(n,1);
  rep(i,n){
    int h;
    cin >> h;
    height.at(i) = h;
  }

  rep(i,m){
    int a,b;
    cin >> a >> b;
    if (height.at(a-1) >= height.at(b-1)) cond.at(b-1) = 0;
    if (height.at(b-1) >= height.at(a-1)) cond.at(a-1) = 0;
  }

  int answer = 0;
  rep(i,n) answer += cond.at(i);

  cout << answer << endl;

}


Measured memory_bytes: 4040
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	
	public static void main(String args[])
	{
		Scanner scan=new Scanner(System.in);
		int n=scan.nextInt();
		int m=scan.nextInt();
		UnionFind uf=new UnionFind(n);
		
		for(int i=0;i<m;i++)
		{
			uf.unite(scan.nextInt()-1, scan.nextInt()-1);
			int x=scan.nextInt();
		}
		long ans=0l;
		for(int i=0;i<n;i++)
		{
			if(uf.par[i]<0)
			{
				ans++;
			}
		}
		System.out.println(ans);
		
	}
}

class UnionFind{
	int[] par;
	public UnionFind(int size)
	{
		par=new int[size];
		Arrays.fill(par, -1);
	}
	public int root(int x)
	{
		if(par[x]<0)
		{
			return x;
		}
		int z=root(par[x]);
		par[x]=z;
		return z;
	
	}
	public boolean same(int a,int b)
	{
		return (root(a)==root(b));
	}
	public void unite(int a,int b)
	{
		if(!same(a,b)) {
			int ra=root(a);
			int rb=root(b);
			//right now both ra and rb ==-1
			
			if(par[ra]<par[rb])
			{
				par[ra]+=par[rb];
				par[rb]=ra;
			}else {
				par[rb]+=par[ra];
				par[ra]=rb;
			}
		}
	}
	public int size(int a)
	{
		return -par[root(a)];
	}
	
}

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

#define CPP_STR(x) CPP_STR_I(x)
#define CPP_CAT(x,y) CPP_CAT_I(x,y)
#define CPP_STR_I(args...) #args
#define CPP_CAT_I(x,y) x ## y

using i8  = int8_t;
using u8  = uint8_t;
using i16 = int16_t;
using u16 = uint16_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;

using f32 = float;
using f64 = double;

#define FOR(i, start, end) for(i64 i = (start), CPP_CAT(i,xxxx_end)=(end); i < CPP_CAT(i,xxxx_end); ++i)
#define REP(i, n) FOR(i, 0, n)
#define REPS(i, n) for(i64 i = 1; i <= n; ++i)
#define RREP(i, n) for(i64 i = n - 1; i >= 0 ; --i)
#define RREPS(i, n) for(i64 i = n; i >= 1; --i)

#define ALL(f,c,...) (([&](decltype((c)) cccc) { return (f)(std::begin(cccc), std::end(cccc), ## __VA_ARGS__); })(c))

#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

#define pb push_back
#define mp make_pair
#define F first
#define S second

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

template<typename C>
i64 SIZE(const C& c) { return static_cast<i64>(c.size()); }

template<typename T, size_t N>
i64 SIZE(const T (&)[N]) { return static_cast<i64>(N); }


struct ProconInit {
    static constexpr int IOS_PREC = 15;
    static constexpr bool AUTOFLUSH = false;

    ProconInit() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(IOS_PREC);
        if(AUTOFLUSH)
            cout << unitbuf;
    }
} PROCON_INIT;

string s;

int main() {
    set<char> code = {'A', 'C', 'G', 'T'};

    cin >> s;

    i64 maxlen = 0;
    i64 len = 0;
    REP(i, s.length()) {
        if (code.count(s[i]) > 0) {
            len++;
            chmax(maxlen, len);
        } else {
            len = 0;
        }
    }
    cout << maxlen << endl;

    return 0;
}

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

// clang-format off
#define  range(i, l, r) for (int i = (int)(l); i < (int)(r); ++(i))
#define rrange(i, l, r) for (int i = (int)(r) - 1; i >= (int)(l); --(i))

#define  whole(f, x, ...) ([&](decltype((x)) container) { return (f)(  begin(container),  end(container), ## __VA_ARGS__); })(x)
#define rwhole(f, x, ...) ([&](decltype((x)) container) { return (f)( rbegin(container), rend(container), ## __VA_ARGS__); })(x)

#define endl '\n'
#define debug(x) cerr << "(" << __LINE__ << ")" << #x << ": " << (x) << endl

using i32 = int;
using u32 = unsigned int;
using i64 = long long;
using u64 = unsigned long long;

// constexpr i32 mod   = 998244353;
constexpr i32 mod   = 1e9 + 7;
constexpr i32 inf   = 1001001001;
constexpr i64 infll = 1001001001001001001ll;

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

struct IoSetup { IoSetup(int x = 15){ cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(x); cerr << fixed << setprecision(x); } } iosetup;

template <typename T = i64> T input() { T x; cin >> x; return x; }

template <typename T> ostream &operator<<(ostream &os, vector<T> &v) { range(i, 0, v.size()) { os << v[i] << (i + 1 != v.size() ? " " : ""); } return os; } 
template <typename T> istream &operator>>(istream &is, vector<T> &v) { for (T &in : v) is >> in; return is; }

template <typename T1, typename T2> ostream &operator<<(ostream &os, pair<T1, T2> p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
template <typename T1, typename T2> istream &operator>>(istream &is, pair<T1, T2> &p) { is >> p.first >> p.second; return is; }

template <typename T> vector<T> make_vector(size_t a, T b) { return vector<T>(a, b); }
template <typename... Ts> auto make_vector(size_t a, Ts... ts) { return vector<decltype(make_vector(ts...))>(a, make_vector(ts...)); }

template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }
// clang-format on

void solver() {
    int N = input(), W = input();
    
    vector< i64 > dp(N * 1000 + 1, infll);
    dp[0] = 0;
    
    range(i, 0, N) {
        int w = input(), v = input();
        
        rrange(j, v, dp.size()) {
            chmin(dp[j], dp[j - v] + w);
        }
    }
    
    i64 ans = infll;
    range(i, 0, dp.size()) {
        if (dp[i] <= W) ans = i;
    }
    
    cout << ans << endl;
}

signed main(int argc, char *argv[]) {
    solver();
}


Measured memory_bytes: 1024
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <functional>
#include <cmath>
#include <complex>
#include <cctype>
#include <cassert>
#include <sstream>
#include <ctime>
 
using namespace std;
 
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
 
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
 
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<pii, int> P;
 
#define INF (1<<29)
#define INFL (1ll<<60)
#define EPS (1e-8)
#define PI (acos(-1))
const ll MOD = 1000000007ll;

struct UnionFind {
	vector<int> par;
	vector<int> rank;
	
	UnionFind() {}
	UnionFind(int n) {
		init(n);
	}
	
	int operator[] (int x) {
		return find(x);
	}

	void init(int n) {
		par.resize(n);
		rank.resize(n);
		REP(i, n) {
			par[i] = i;
			rank[i] = 0;
		}
	}

	int find(int x) {
		if (par[x] == x) return x;
		return par[x] = find(par[x]);
	}

	void unite(int x, int y) {
		x = find(x);
		y = find(y);
		if (x == y) return;

		if (rank[x] < rank[y]) {
			par[x] = y;
		} else {
			par[y] = x;
			if (rank[x] == rank[y]) rank[x]++;
		}
	}

	bool same(int x, int y) {
		return find(x) == find(y);
	}
};

int n, m;
vector<int> g[112345];


int color[112345];

bool binary_color(int v,int c) {
	color[v] = c;
	
	REP(i, g[v].size()) {
		int u = g[v][i];
		
		if (color[u] == 0) {
			if (!binary_color(u, -c)) return false;
		}
		else {
			if (color[u] == c) return false;
		}
	}
	
	return true;
}

int main() {
	cin >> n >> m;
	
	UnionFind uf(n);
	
	REP(i, m) {
		int u, v;
		scanf("%d %d", &u, &v);
		u--; v--;
		g[u].push_back(v);
		g[v].push_back(u);
		
		uf.unite(u, v);
	}
	
	ll isc = 0; // 孤立点
	ll bpc = 0; // 二部グラフ
	ll odc = 0; // not二部グラフ
	
	map<int, int> m;
	REP(i, n) m[uf[i]]++;
	
	bool done[112345] = {};
	REP(i, n) {
		if (done[uf[i]]) continue;
		done[uf[i]] = true;
		
		if (m[uf[i]] == 1) isc++;
		else {
			fill(color, color + n, 0);
			if (binary_color(i, 1)) bpc++;
			else odc++;
		}
	}
	
	ll ans = 2*bpc*bpc + isc*isc + odc*odc + 2 * (bpc * odc + isc * (n - isc));
	
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 11136
N, K = map(int, input().split())
A = sorted([int(a) for a in input().split()])
F = sorted([int(a) for a in input().split()])[::-1]
l = -1
r = 10**18
while r-l > 1:
    m = (l+r)//2
    if sum([max(0, A[i] - m//F[i]) for i in range(N)]) <= K:
        r = m
    else:
        l = m
print(r)

Measured memory_bytes: 138880
#include<algorithm>
#include<bitset>
#include<cmath>
#include<complex>
#include<cstdlib>
#include<iomanip>
#include<iostream>
#include<map>
#include<queue>
#include<set>
#include<string>
#include<utility>
#include<vector>

using namespace std;

#define ll long long
#define pal pair<ll,ll>
#define pad pair<double,double>
#define PB push_back
#define MP make_pair
#define F first
#define S second

const ll MOD = 1e9+7;
const ll INF = 1e18;
const double EPS = 1e-8;

long long MODPOW(long long x, long long n) {
    long long ret = 1;
    while (n > 0) {
        if (n & 1) ret = ret * x % MOD;
        x = x * x % MOD;
        n >>= 1;
    }
    return ret;
}

template<typename T,typename U>
bool chmax(T& max, const U& x){
	if(max<x){
		max = x;
		return true;
	}
	return false;
}

template<typename T,typename U>
bool chmin(T& min, const U& x){
	if(min>x){
		min = x;
		return true;
	}
	return false;
}


int main(){
	ll n,x,t;
    cin >> n >> x >> t;
    cout << (n+x-1)/x*t << endl;
}

Measured memory_bytes: 3628
#include <stdio.h>

int main(void)
{
	int top[3] = {0,0,0};
	int input, i, j;
	int tmp, tmp2, flag = 0;
	
	for (i=0; i<10; i++)
	{
		scanf("%d",&input);
		for (j=0; j<3; j++)
		{
			if (flag == 1)
			{
				tmp2 = top[j];
				top[j] = tmp;
				tmp = tmp2;
				continue;
			}
			if (top[j] < input)
			{
				tmp = top[j];
				top[j] = input;
				flag = 1;
			}
		}
		
		flag = 0;
	}
	
	for (j=0; j<3; j++)
	{
		printf("%d\n",top[j]);
	}
	
	return 0;
}

Measured memory_bytes: 600
using System;
using System.Collections.Generic;
using System.Linq;
class Program
 {
        static void Main(string[] args)
        {
        　　int A,B;
            string[] str = Console.ReadLine().Split(' ');//2つ以上のスペース区切り入力の取得
            A = int.Parse(str[0]);  //数値で受け取りたい場合は変換する
            B = int.Parse(str[1]);
            if((A + B)%2 == 0)
            {
                Console.Write((A + B)/2);
            }
            else
            {
                Console.Write("IMPOSSIBLE");
            }
        }
 }

Measured memory_bytes: 11092
import java.util.*;

public class Main {
    public static void main (String[] args) {
        Scanner scanner = new Scanner(System.in);
       
        while (scanner.hasNext()) {
            long x0 = scanner.nextLong();
            long y0 = scanner.nextLong();
            
            long x = x0;
            long y = y0;
            long gcd = 0;
            long lcm = 0;
            
            while (x != y) {
                if (y > x) {
                    long temp = y;
                    y = x;
                    x = temp;
                }
                x = x - y; 
            }
            gcd = x;         
            lcm = x0 * y0 /gcd;
            System.out.println(gcd + " " + lcm);
        }
    }
}

Measured memory_bytes: 15384
#include <bits/stdc++.h>
 
using namespace std;
 
int main(){
int k;string s;
  cin>>k>>s;
  if(k>=s.length())cout<<s<<endl;
  else{
    s = s.substr(0,k)+"...";
    cout<<s<<endl;
  }
return 0;
 
}

Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
#define num 1000000007
//#define num 998244353
#define REP(i,a,n) for(ll i=a;i<n;i++)
#define inarr(i,a,n,A) for(ll i=a;i<n;i++) { cin>>A[i]; }
#define vll vector<long long>
#define pii pair <int,int>
#define pll pair<long long, long long>
#define vpii vector< pair <int,int>>
#define vpll vector< pair<long long, long long>>
#define max(a,b) ((a>b)?a:b)
#define min(a,b) ((a>b)?b:a)
#define max3(a,b,c) ((a>b)?(a>c)?a:c:(b>c)?b:c)
#define min3(a,b,c) ((a<b)?(a<c)?a:c:(b<c)?b:c)
#define avg(a,b) ((a)+(b))/2
#define pb push_back
#define pob pop_back
#define sf int flag=0     //Remember semicolon
#define assmin(a,b) if(b<=a) { a=b; }
#define assmax(a,b) if(b>=a) { a=b; }
#define f first
#define s second
#define fix(f,n) std::fixed<<std::setprecision(n)<<f
#define all(x) x.begin(), x.end()
#define M_PI 3.14159265358979323846
#define epsilon (double)(0.00000000001)
typedef long long ll;
ll mod(ll a, ll b)
{
	if(a%b<0)
	{
		return a%b + b;
	}
	return a%b;
}
 
 
ll mod_exp(ll a, ll b, ll c)
{
	ll res=1;
	a=a%c;
	while(b>0)
	{
		if(b%2==1)
		{
			res=(res*a)%c;
		}
		b/=2;
		a=(a*a)%c;
	}
	return res;
}
ll mymod(ll a,ll b)
{
    return ((a%b)+b)%b;
}
bool prime[200001];
void SieveOfEratosthenes() 
{ 
    memset(prime, true, sizeof(prime)); 
    prime[1]=false;
    for (int p=2; p*p<=200000; p++) 
    { 
        if (prime[p] == true) 
        { 
            for (int i=p*p; i<=200000; i += p) 
                prime[i] = false; 
        } 
    } 
    return;
}
ll powe[200005];
void power()
{
    powe[0]=1;
    REP(i,1,200005)
    {
        powe[i]=mymod(2*powe[i-1],num);
    }
}
ll gcdExtended(ll,ll,ll *,ll *);
ll modInverse(ll a, ll m) 
{ 
    ll x, y; 
    ll g = gcdExtended(a, m, &x, &y); 
        ll res = (x%m + m) % m;
        return res;
} 
ll gcdExtended(ll a, ll b, ll *x, ll *y) 
{ 
    if (a == 0) 
    { 
        *x = 0, *y = 1; 
        return b; 
    } 
    ll x1, y1; 
    ll gcd = gcdExtended(b%a, a, &x1, &y1); 
    *x = y1 - (b/a) * x1; 
    *y = x1; 
    return gcd; 
}
ll n; 
struct node
{
	vll adj;
    ll dist;
   // ll max_depth;
    ll cwgd;
};

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll n;
    cin>>n;
    ll count[n+1]={};
    REP(i,0,n-1)
    {
        ll a;
        cin>>a;
        count[a]++;
    }
    REP(i,1,n+1)
    {
        cout<<count[i]<<"\n";
    }
	return 0;
}

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

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


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

    using namespace std;
     vector<int> path;
vector<vector<int>> NtoN;
vector<int> minpath;



    int main(){
     
      int N,M;
      string buf;
      getline(cin,buf);
      {
      stringstream line(buf);
        line >> N >> M;
      }
      NtoN = vector(N,vector<int>(0,0));
      
      path = vector<int>(N,0);
      minpath = vector<int>(N,N);
minpath[0] = 0;

      
      for(int i = 0;i < M;i++)
      {
        getline(cin,buf);
        int a,b;
        stringstream line(buf);
        line >> a >> b;
        NtoN[a-1].push_back(b-1);
        NtoN[b-1].push_back(a-1);
        
        path[a-1]++;
        path[b-1]++;
      }
      
      
 auto nextto = vector<int>(1,0);
      for(int d = 1; d < N;d++)
      {
        auto tmp = nextto;
    nextto = vector<int>();
        for(auto &j: tmp)
        {
          for(auto &i : NtoN[j]){
if(minpath[i] > d){
         	nextto.push_back(i);
  	minpath[i] = d;
}
          }

        }
      } // end
      
     

      auto f = vector<int>(N,0);

for(int i = 1;i < N;i++)
{
 for(int j = 0;j < path[i];j++){
   if(minpath[i] == minpath[NtoN[i][j]] + 1){
     
     f[i] = NtoN[i][j];
     break;
   }
 }
}
      cout << "Yes" << endl;
      for(int i = 1;i < N ;i++)
        cout << f[i] + 1 << endl;
    }

Measured memory_bytes: 10396
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String s = scanner.nextLine();
        
        if (s.charAt(2)==s.charAt(3) && s.charAt(4)==s.charAt(5)){
            System.out.println("Yes");
        }else {
            System.out.println("No");
        }
    }
}


Measured memory_bytes: 21844
n = input()
p = list(map(int, input().split()))

cnt = 0
for n in range(1, len(p) - 1):

    if p[n - 1] > p[n + 1]:
        if p[n - 1] > p[n] and p[n] > p[n + 1]:
  
            cnt = cnt + 1
    elif p[n - 1] < p[n] and p[n] < p[n + 1]:
        cnt = cnt + 1

print(cnt)


Measured memory_bytes: 3060
/*
 
Coded and Decoded by : Yash Kapoor
 
*/
#include <bits/stdc++.h>
using namespace std;
 
#define ll          long long
#define ld          long double
#define pb          push_back
#define pf          push_front
#define mp          make_pair
#define pll         pair<ll,ll>
#define vl          vector<ll>
#define sl          set<ll> 
#define vll         vector<pll>
#define ml          map<ll,ll>
#define mll         map<pll,ll>
#define all(a)      a.begin(),a.end()
#define x           first
#define y           second
#define sz(x)       (ll)x.size()
#define dl          '\n'
#define why         (ll)1000000007
//#define why         (ll)998244353
#define lp(i,a,b)   for(ll i=a;i<b;++i)
#define lpr(i,a,b)  for(ll i=a;i>=b;i--)
#define lpd(i,x)    for(auto i:x)
#define ios         ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
ll inf = 1e18;
ld pi = 3.141592653589;
ll mod = why;
ll fast_power(ll base,ll power,ll mod)
{
    ll result=1;
    while(power)
    {
        if(power%2)
        result=(result*base)%mod;
        base=(base*base)%mod;
        power/=2;
    }
    return result;
}
 
ll inverse(ll base,ll mod)
{
    return fast_power(base,mod-2,mod);
}
 
ll solve(){ 
    ld r; cin>>r;
    cout<<fixed<<setprecision(10)<<(2*pi*r);
    return 0;
}  
 
int main(){
    ios
    ll t=1; 
    //cin>>t;
    while(t--){
        solve();
    }
}

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


int main() {
  int a, b, c;
  cin >> a >> b >> c;
  if(a == 5 && b == 7 && c == 5)  cout << "YES" << endl;
  else if(a == 5 && b == 5 && c == 7)  cout << "YES" << endl;
  else if(a == 7 && b == 5 && c == 5)  cout << "YES" << endl;
  else cout << "NO" << endl;
  return 0;
}

Measured memory_bytes: 256
str = $stdin.gets.chomp

if str.size == 1
    puts str.to_i
elsif str.size == 2
    puts 9
elsif str.size == 3
    puts 10 + ((str[0].to_i - 1).to_s + str[1] + str[2]).to_i
elsif str.size == 4
    puts 909
elsif str.size == 5
    puts 910 + ((str[0].to_i - 1).to_s + str[1] + str[2] + str[3] + str[4]).to_i
else
    puts 90909
end

Measured memory_bytes: 1788
#include<bits/stdc++.h>
#define rep(i,N) for(int i=0;i<(N);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e12;
const int inf = 1e9;
const int mod = 1e9+7;
typedef long long ll;
typedef pair<ll,int> P;
typedef set<int> S;
int main(){
    cout << fixed << setprecision(10);
    int n;
    cin >> n;
    int now = 0;
    int xx = 0;
    int yy = 0;
    bool ok = 1;
    rep(i,n){
        int t,x,y;
        cin >> t >> x >> y;
        int dis = abs(xx-x) + abs(yy-y);
        if(dis>t-now){
            if(ok) cout << "No" << endl;
            ok = 0;
        }else{
            if(dis%2 != (t-now)%2){
                if(ok) cout << "No" << endl;
                ok = 0;
            }
        }
        now = t; xx = x; yy = y;
    }
    if(ok) cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 256
/******************************************************************************

                              Online C++ Compiler.
               Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.

*******************************************************************************/

#include <iostream>

using namespace std;

int main()
{
    int l,r,d;
    cin>>l>>r>>d;
    int count=0;
    for(int i=l;i<=r;i++)
    {
        if(i%d==0)
        count++;
        
        
    }
    cout<<count;
    return 0;
}


Measured memory_bytes: 3620
use std::i64;

#[allow(unused_macros)]
macro_rules! scan {
    () => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().to_string()
        }
    };
    (;;$n:expr) => {
        (0..$n).map(|_| scan!()).collect::<Vec<_>>()
    };
    ($t:ty) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t:ty),*) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            (
                $(iter.next().unwrap().parse::<$t>().unwrap(),)*
            )
        }
    };
    ($t:ty;;) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.split_whitespace()
                .map(|t| t.parse::<$t>().unwrap())
                .collect::<Vec<_>>()
        }
    };
    ($t:ty;;$n:expr) => {
        (0..$n).map(|_| scan!($t;;)).collect::<Vec<_>>()
    };
    ($t:ty; $n:expr) => {
        (0..$n).map(|_|
                    scan!($t)
        ).collect::<Vec<_>>()
    };
    ($($t:ty),*; $n:expr) => {
        (0..$n).map(|_|
                    scan!($($t),*)
        ).collect::<Vec<_>>()
    };
}

const MOD: i64 = 1_000_000_007;

fn pow(a: i64, b: i64) -> i64 {
    if b == 0 {
        1
    } else if b % 2 == 0 {
        pow((a * a) % MOD, b / 2) % MOD
    } else {
        (a * pow((a * a) % MOD, b / 2)) % MOD
    }
}

#[test]
fn test_pow() {
    assert_eq!(pow(2, 5), 32);
}

fn comb(n: i64, k: i64, fact: &[i64]) -> i64 {
    if n < 0 || k < 0 || n < k {
        return 0;
    }
    if n == 0 && k == 0 {
        return 1;
    }

    ((fact[n as usize] * pow(fact[k as usize], MOD - 2)) % MOD)
        * pow(fact[(n - k) as usize], MOD - 2)
        % MOD
}

#[test]
fn test_comb() {
    let mut fact: Vec<_> = (0..100_002).collect();
    for i in 1..(fact.len() - 1) {
        fact[i + 1] *= fact[i];
        fact[i + 1] %= MOD;
    }
    assert_eq!(fact[3], 6);
    assert_eq!(comb(3, 2, &fact), 3);
    assert_eq!(comb(10, 4, &fact), 210);
    assert_eq!(comb(0, 3, &fact), 0);
    assert_eq!(comb(10, 0, &fact), 0);
}

fn main() {
    let n = scan!(i64);
    let vs = scan!(i64;;);
    let mut sorted = vs.clone();
    let mut fact: Vec<_> = (0..100_002).collect();
    fact[0] = 1;
    for i in 0..(fact.len() - 1) {
        fact[i + 1] *= fact[i];
        fact[i + 1] %= MOD;
    }

    sorted.sort();
    let mut dup = 0;
    for (&v1, &v2) in sorted.iter().zip(sorted[1..].iter()) {
        if v1 == v2 {
            dup = v1;
            break;
        }
    }
    let l = vs.iter().position(|&x| x == dup).unwrap() as i64;
    let r = (vs.len() - vs.iter().rposition(|&x| x == dup).unwrap() - 1) as i64;
    for i in 1i64..n + 2 {
        println!(
            "{}",
            (comb(n + 1, i, &fact) - comb(l + r, i - 1, &fact) + MOD) % MOD
        )
    }
}


Measured memory_bytes: 9340
//どの頂点も一度ずつ通るので、頂点0を出発点と決めてしまって良い。
//次に行ける頂点は、今までに通った頂点の集合visitedと現在地posから求まる。
//また, (visited, pos)は次行く場所を決めると更新できる。
//よって、これらを用いて探索を書けないか考える。すると「上手く書ける」。あとはメモ化すればよい。
//visited = {1,2,4,5}みたいな集合を、visited = (110110)b = 2^5 + 2^4 + 2^2 + 2^1 = 54のように表現した漸化式・メモ化再帰を
//「ビットDP」という。
//
//上手く書ける：
//例えば、頂点1->2->…->1という経路Pを、[1->2] + [2->…->1]と分解したとき、
//Pの長さを最小化したければ、[2->…->1]の長さも最小化したいという性質。
//（難しいので, 分からなければ読み飛ばしてください＞＿＜）

#include <iostream>
#include <algorithm>	//min()関数が入っている
using namespace std;

int INF = 1000000007;	//十分大きな整数. INF + INFがオーバーフローしないようにしておくと、ちょっと安心？（今回は関係ないけど）
int n, m;
bool canMove[15][15] = {false};	//canMove[i][j] = 頂点i->jと移動できるか
int ecost[15][15];
int dp[1 << 15][15];	//dp[visited][pos] = minCost.

//pos     … 今いる頂点. posから移動したい.
//visited … visitedの下位i(>=0)ビット目は, 頂点iを訪れたことがあれば1, なければ0.
//戻り値  … これから進む距離の最小値
int dfs(int pos, int visited) {
	if (visited == (1 << n) - 1) {	//全ての頂点を訪れていたら, pos->頂点0と移動して終了
		if (!canMove[pos][0]) return INF;	//移動不可能な場合
		return ecost[pos][0];
	}
	if (dp[visited][pos] != -1) {
		return dp[visited][pos];
	}
	
	int ret = INF;
	for (int nPos = 0; nPos < n; nPos++) {
		if (!canMove[pos][nPos]) continue;
		if ((visited >> nPos) & 1) continue;	//下位nPosビット目が1なら, 頂点nPosを既に訪れている.
		int res = ecost[pos][nPos] + dfs(nPos, visited + (1 << nPos));
		ret = min(ret, res);
	}
	return dp[visited][pos] = ret;
}

int main() {
	int i, j;
	
	cin >> n >> m;
	for (i = 0; i < m; i++) {
		int s, t, d;
		cin >> s >> t >> d;
		ecost[s][t] = d;
		canMove[s][t] = true;
	}
	
	//初期化. (1 << n)は1をnビット右シフトしたもの。2のn乗と同じ。
	for (i = 0; i < (1 << n); i++) for (j = 0; j < n; j++) dp[i][j] = -1;
	
	int res = dfs(0, 1);
	if (res >= INF) cout << -1 << endl;
	else cout << res << endl;
	return 0;
}


Measured memory_bytes: 4960
import std.stdio;
import std.string;
import std.array; // split
import std.conv; // to

void main()
{
   string n = chomp(readln());
   int a = to!int(n);
   if(a%10 == a/100){
       writeln("Yes");
   } else {
       writeln("No");
   }
}

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

int main(){
	string words;
	cin >> words;
	for (int i = 0; i < 12; ++i)
	{
		cout << words[i];
		if (i == 3)
		{
			cout << " "; 
		}
	}
	cout << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ADD(a, b) a = (a + ll(b)) % mod
#define MUL(a, b) a = (a * ll(b)) % mod
#define MAX(a, b) a = max(a, b)
#define MIN(a, b) a = min(a, b)
#define rep(i, a, b) for(int i = int(a); i < int(b); i++)
#define rer(i, a, b) for(int i = int(a) - 1; i >= int(b); i--)
#define all(a) (a).begin(), (a).end()
#define sz(v) (int)(v).size()
#define pb push_back
#define sec second
#define fst first
#define debug(fmt, ...) Debug(__LINE__, ":", fmt, ##__VA_ARGS__)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<int, pi> ppi;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> mat;
typedef complex<double> comp;
void Debug() {cerr << '\n'; }
template<class FIRST, class... REST>void Debug(FIRST arg, REST... rest){
	cerr<<arg<<" ";Debug(rest...);}
template<class T>ostream& operator<<(ostream& out,const vector<T>& v) {
	out<<"[";if(!v.empty()){rep(i,0,sz(v)-1)out<<v[i]<<", ";out<<v.back();}out<<"]";return out;}
template<class S, class T>ostream& operator<<(ostream& out,const pair<S, T>& v){
	out<<"("<<v.first<<", "<<v.second<<")";return out;}
const int MAX_N = 500010;
const int MAX_V = 100010;
const double eps = 1e-6;
const ll mod = 1000000007;
const int inf = (1 << 30) - 1;
const ll linf = 1LL << 60;
const double PI = 3.14159265358979323846;
mt19937 rng; //use it by rng() % mod, shuffle(all(vec), rng)
///////////////////////////////////////////////////////////////////////////////////////////////////

int N;
string S[MAX_N];
int A[MAX_N];

void solve() {
	cin >> N;
	rep(i, 0, N) {
		cin >> S[i] >> A[i];
	}
	string X; cin >> X;
	ll sum = 0;
	rer(i, N, 0) {
		if(X == S[i]) break;
		else sum += A[i];
	}
	cout << sum << "\n";
}

uint32_t rd() {
	uint32_t res;
#ifdef __MINGW32__
	asm volatile("rdrand %0" :"=a"(res) ::"cc");
#else
	res = std::random_device()();
#endif
	return res;
}

int main() {
#ifndef LOCAL
	ios::sync_with_stdio(false);
    cin.tie(0);
#endif
    cout << fixed;
	cout.precision(20);
    cerr << fixed;
	cerr.precision(6);
	rng.seed(rd());
#ifdef LOCAL
	//freopen("in.txt", "wt", stdout); //for tester
	if(!freopen("in.txt", "rt", stdin)) return 1;
#endif	
	solve();
    cerr << "Time: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
	return 0;
}



Measured memory_bytes: 4224
#define __USE_MINGW_ANSI_STDIO 0
#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9;
const int MOD = 1000000007;


int main(){
	int N;
	cin >> N;
	long long power =1;
	for(int i=1;i<=N;i++){
		power = power*i%MOD;

	}
	cout << power <<endl;
	}

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

int main()
{
    string s, t;
    int j[10];

    while( cin >> s >> t )
    {
        if( s == "0" && t == "0" )
            break;
        for( int i = 0; i < 10; i++ )
            j[i] = 0;

        int hit = 0, blow = 0;
        for( int i = 0; i < 4; i++ )
        {
            if( s[i] == t[i] )
                hit++;
            j[s[i]-'0']++;
            j[t[i]-'0']++;
        }
        for( int i = 0; i < 10; i++ )
            if( j[i] == 2 )
                blow++;
        cout << hit << " " << blow - hit << endl;
    }
    return 0;
}


Measured memory_bytes: 3144
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define mod (1000*1000*1000+7)

int main(){
    int N; cin>>N;
    bool A[N+1]={};
    bool flag;
    for(int i=2;i<=N;i++){
        flag=0;
        for(int j=2;j<i;j++){
            if(i%j==0){
                flag=1;
                break;
            }
        }
        if(flag==0) A[i]=1;
    }

    int B[N+1]={}; 
    for(int i=2;i<=N;i++){
        int tmp = i;
        for(int j=2;j<=i;j++){
            while(tmp%j==0 && A[j]){
                tmp/=j;
                B[j]++;
            }
        }
    }
    

    ll ans=1;
    for(int i=2;i<=N;i++){
        if(A[i]){
            ans = ans*(B[i]+1)%mod;
            // cout << ans<< ' ';
        }
    }
    
    // cout <<endl;
    cout <<ans<<endl;

    // for(int i=2;i<N;i++) cout << B[i]<< ' ';
    cout <<endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void) {

  long n;
  scanf("%ld", &n);
  char s[n+1];
  scanf("%s", s);
  long left,right = n-1,count = 0;
  for (left = 0; left < n; left++) {
    if (s[left] == 'R') {
      continue;
    }
    while (s[right] == 'W') {
      right--;
    }
    if (right <= left) {
      break;
    }
    s[left] = 'R';
    s[right] = 'W';
    count++;
  }
  printf("%ld\n", count);

  return 0;
}

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

int main() {
  int N, K;
  cin >> N >> K;
  vector<int> x(N);
  for (int i=0; i<N; i++) cin >> x.at(i);
  int ans = 0;
  for (int i=0; i<N; i++) {
    if (2*x.at(i)<K) ans += 2*x.at(i);
    else ans += 2*(K-x.at(i));
  }
  cout << ans << endl;
}

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

int main() {
  string s;
  cin >> s;
  int first;
  int end;
  int n=s.size();
  for (int i=0;i<n;i++){
    if(s[i]=='A'){
      first=i;
      break;
    }
  }
  for (int i=0;i<n;i++){
    if(s[i]=='Z'){
      end=i;
    }
  }
    cout << end-first+1<<endl;
      
}


Measured memory_bytes: 640
#include <iostream>
#include <vector>

using namespace std;

double q[1001];

int main() {
    int N, K;
    cin >> N >> K;
    vector<int> p(N);

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

    q[0] = 0;
    for(int i = 1; i <= 1000; i++) {
        q[i] = (double)(i+1.0)/2.0;
    }

    vector<double> accum(N+2);
    accum[0] = 0;
    for(int i = 1; i <= N; i++) {
        accum[i] = accum[i-1] + q[p[i-1]];
    }
    // 0 1 2 3 4 5

    double ans = 0;
    for(int i = 0; i<=N-K; i++) {
        ans = max(accum[i+K] - accum[i], ans);
    }

    printf("%.10lf\n", ans);
}

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

int main(){
  int n,m,h;
  int data[110];
  while(1){
    cin >> n >> m >> h;
    if(n == 0 && m == 0 && h == 0) break;
    int sum = 0;
    for(int i=0;i<n;i++){
      cin >> data[i];
      sum += data[i];
    }
    if(data[m-1]==0) {
      cout << "0" << endl;
      continue;
    }
    sum = sum * 100;
    sum = sum * (100-h);
    sum = sum / 100;
    cout << sum / data[m-1] << endl;
  }
}

Measured memory_bytes: 1160
#include <stdio.h>
int main(void){
    int i,N,s[100]={};
    for(scanf("%d",&N),i=0;i<N;i++)
    scanf("%d",&s[N-i-1]);
    for(i=0;i<N;i++)
    printf("%d%s",s[i],i==N-1?"\n":" ");
}

Measured memory_bytes: 1832
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,v,m,i;
  map<int,int> m0,m1;
  vector<pair<int,int>> v0,v1;
  cin>>n;
  for(i=0;i<n;i++){
    cin>>v;
    if(i%2==0){
      if(m0.count(v)) m0.at(v)++;
      else m0[v]=1;
    }
    else if(i%2==1){
      if(m1.count(v)) m1.at(v)++;
      else m1[v]=1;
    }
  }
  for(auto z:m0) v0.push_back(make_pair(z.second,z.first));
  sort(v0.begin(),v0.end());
  reverse(v0.begin(),v0.end());
  for(auto z:m1) v1.push_back(make_pair(z.second,z.first));
  sort(v1.begin(),v1.end());
  reverse(v1.begin(),v1.end());
  if(v0.at(0).second!=v1.at(0).second) cout<<n-v0.at(0).first-v1.at(0).first<<endl;
  else if(v0.at(0).first+v1.at(0).first==n) cout<<n/2<<endl;
  else if(v0.size()>1&&v0.size()>1){
    m=max(v0.at(0).first+v1.at(1).first,v0.at(1).first+v1.at(0).first);
    cout<<n-m<<endl;
  }
  else if(v0.size()>1) cout<<n/2-v0.at(1).first<<endl;
  else if(v1.size()>1) cout<<n/2-v1.at(1).first<<endl;
}

Measured memory_bytes: 8760