akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
using namespace std;
using ll = long long;
#define in(v) v; cin >> v;
#define rep(i,n) for(int i=0,_i=(n);i<_i;++i)
const ll INF = 1e18;
ll dp[101][100001];
int main() {
  int in(N); int in(W);

  int w[100], v[100];
  rep(i, N)
    cin >> w[i] >> v[i];

  rep(i, N+1) rep(j, 1e5+1) dp[i][j] = i == 0 ? 0 : -INF;

  rep(i, N) {
    rep(j, 1e5+1) {
      if (j - w[i] >= 0)
        dp[i+1][j] = max(dp[i][j], dp[i][j-w[i]] + v[i]);
      else
        dp[i+1][j] = dp[i][j];
    }
  }

  cout << dp[N][W] << endl;


  return 0;
}


Measured memory_bytes: 79104
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
 
int top, S[1000];
 
void push(int x) {
  S[++top] = x;
}
 
int pop() {
  top--;
  return S[top+1];
}
 
int main() {
  int a, b;
  top = 0;
  char s[100];
 
  while( scanf("%s", s) != EOF ) {
    if ( s[0] == '+' ) {
      b = pop();
      a = pop();
      push(a + b);
    } else if ( s[0] == '-' ) {
      b = pop();
      a = pop();
      push(a - b);
    } else if ( s[0] == '*' ) {
      b = pop();
      a = pop();
      push(a * b);
    } else {
      push(atoi(s));
    }
  }
 
  printf("%d\n", pop());
 
  return 0;
}


Measured memory_bytes: 2104
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    n, k, c = list(map(int, readline().split()))
    s = input()
    day_ealiest = []
    day_latest = []

    rest_day = 0
    work_cnt = 0
    for day, ch in enumerate(s, 1):
        if rest_day <= 0:
            if ch == "o":
                rest_day = c
                day_ealiest.append(day)
                work_cnt += 1
                if work_cnt == k:
                    break
        else:
            rest_day -= 1

    s_reversed = s[::-1]
    rest_day = 0
    work_cnt = 0
    for i, ch in enumerate(s_reversed):
        day = n - i
        if rest_day <= 0:
            if ch == "o":
                rest_day = c
                day_latest.append(day)
                work_cnt += 1
                if work_cnt == k:
                    break
        else:
            rest_day -= 1

    day_latest.reverse()

    res = []
    for de, dl in zip(day_ealiest, day_latest):
        if de == dl:
            res.append(de)

    print(*res, sep="\n")


if __name__ == '__main__':
    main()


Measured memory_bytes: 68496
n = int(input())
arr = [i for i in range(1,n+1)]
counter = 0
while len(arr) > 1:
  counter += 1
  i = 0
  while i < len(arr):
    if arr[i] % 2 != 0:
      arr.pop(i)
    else:
      arr[i] //= 2
      i += 1
print(arr[0] * (2**counter))

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

class weighted_unionfind {
  vector<int> par, weight, s;
  
public:
  weighted_unionfind(int n) {
    for (int i = 0; i < n; i++) {
      par.push_back(i);
      weight.push_back(0);
      s.push_back(1);
    }
  }
  
  int find(int n) {
    if (par.at(n) == n) return n;
    int r = find(par.at(n));
    weight.at(n) += weight.at(par.at(n));
    return par.at(n) = r;
  }
  
  void merge(int m, int n, int d) {
    d += diff(m) - diff(n);
    if (s.at(m) < s.at(n)) {
      swap(m, n);
      d = -d;
    }
    m = find(m); n = find(n);
    par.at(n) = m;
    weight.at(n) = d;
    s.at(m) += s.at(n);
  }
  
  int diff(int n) {
    if (par.at(n) == n) return 0;
    return weight.at(n);
  }
};

int main() {
  int n, m;
  cin >> n >> m;
  weighted_unionfind t(n);
  for (int i = 0; i < m; i++) {
    int l, r, d;
    cin >> l >> r >> d;
    l--; r--;
    if (t.find(l) != t.find(r)) {
      t.merge(l, r, d);
    } else {
      if (t.diff(r) - t.diff(l) != d) {
        puts("No");
        return 0;
      }
    }
  }
  puts("Yes");
}


Measured memory_bytes: 1644
#include<iostream>
#include<cmath>
#include<algorithm>
#include<vector>
#include<functional>
#include<string>
#include<iomanip>
#include<map>
#include<utility>
#include<string>
#include<unordered_map>
#include<queue>

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

using namespace std;

typedef long long ll;
typedef pair<int, int> P;
int gcd(int a, int b){return b ? gcd(b, a%b) : a;}

int main(){
    int r;
    cin >> r;
    cout << float(3.14159265*2*r) << endl;
    return 0;
}


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

int main() {
	int N, M; cin >> N >> M;

	vector<vector<int>> vec(M);

	for (int i = 0; i < M; ++i) {
		int k; cin >> k;
		vec[i].resize(k);
		for (int j = 0; j < k; ++j) {
			cin >> vec[i][j];
			--vec[i][j];
		}
	}

	vector<int> p(M);
	for (int i = 0; i < M; ++i) cin >> p[i];

	int ans = 0;
	for (int i = 0; i < (1 << N); ++i) {
		bool ok = true;
		for (int j = 0; j < M; ++j) {
			int c = 0;
			for (int id : vec[j]) {
				if ((i >> id) & 1) {
					++c;
				}
			}
			c %= 2;
			if (c != p[j]) {
				ok = false;
			}
		}
		if (ok) {
			++ans;
		}
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 384
#include<iostream>
#include<string>
using namespace std;
int main(){
	string in;
	int c;
	while(cin>>in){
	for(int i=0;i<in.size();i++){
		if(in[i]!='@')cout<<in[i];
		else {
		c=in[++i]-'0';i++;
		for(int j=0;j<c;j++){
			cout<<in[i];	
		}
		}
				
	}
cout<<endl;
}
}

Measured memory_bytes: 1172
#include <iostream>
#include <stdio.h>

using namespace std;

void change2(int* a, int* b) {
	int tmp;
	
	tmp = *a;
	*a  = *b;
	*b  = tmp;
}

int main(void) {
	int w, n;
	int a, b;
	int value[30];
	char buf[256];
	
	for (int i=0; i<30; i++) {
		value[i] = i+1;
	}
	
	fgets(buf, sizeof(buf), stdin);
	sscanf(buf, "%d", &w);
	fgets(buf, sizeof(buf), stdin);
	sscanf(buf, "%d", &n);
	
	for (int i=0; i<n; i++) {
		fgets(buf, sizeof(buf), stdin);
		sscanf(buf, "%d,%d", &a, &b);
		change2(&value[a-1], &value[b-1]);
	}
	
	for (int i=0; i<w; i++) {
		printf("%d\n", value[i]);
	}
	
	return 0;
}

Measured memory_bytes: 1196
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long LL;
typedef pair<int,int> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const LL mod=1000000007;
const LL LINF=1LL<<60;
const int INF=1<<30;
int dx[]={1,0,1,-1,1,-1,-1,0};
int dy[]={0,1,1,-1,-1,1,0,-1};



int main(){
    LL h;cin >> h;
    LL ans = 1;
    while(h){
        ans <<= 1;
        h >>= 1;
    }
    cout << ans - 1 << endl;
    return 0;
}


Measured memory_bytes: 256
N, M = map(int, input().split())
graph = [[] for _ in range(N)]
for i in range(M):
    a, b = map(int, input().split())
    graph[a-1].append(b-1)
    graph[b-1].append(a-1)

visited = [False]*N

ans = 0
import copy

def dfs(node, visited):
    global ans
    v = copy.copy(visited)
    if v[node]:
        return
    v[node] = True
    if all(v):
        ans += 1
    else:
        cands = graph[node]
        for cand in cands:
            dfs(cand, v)

dfs(0, visited)
print(ans)


Measured memory_bytes: 44252
#include<stdio.h>
int X[]={-1,-1,-1,0,0,0,1,1,1};
int Y[]={-1,0,1,-1,0,1,-1,0,1};
int mbk(long long a,int n,int m){return n?(mbk((a*a)%m,n/2,m)*(n%2?a:1))%m:1;}
int inv(int a,int m){return mbk((long long)a,m-2,m);}
int aCb(int a,int b,int m){
  int i;
  long long s=1;
  if(b>a-b)b=a-b;
  for(i=0;i<b;i++){
    s=(s*(a-i))%m;//printf("%lld ",s);
    s=(s*inv(i+1,m))%m;//printf("%lld ",s);
  }
  return (int)s;
}
int main(){
  //printf("%d\n",aCb(5,2,107));
  int w,h,a,b,x,y,d[10][2],dx,dy,i,min=10000,s=0;
  scanf("%d %d %d %d",&w,&h,&x,&y);
  for(i=0;i<9;i++){
    d[i][0]=x+w*X[i];
    d[i][1]=y+h*Y[i];
  }
  scanf("%d %d",&x,&y);
  for(i=0;i<9;i++){
    dx=abs(d[i][0]-x);
    dy=abs(d[i][1]-y);
    if(dy+dx<min){
      min=dy+dx;
      s=0;
    }//printf("%d %d %d\n",dy,dx,max);
    if(dy+dx==min)s+=aCb(min,dx,100000007);
    s%=100000007;
  }
  printf("%d\n",s);
  return 0;
}

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

using namespace std;
typedef long long ll;
ll N, C, K;

ll T[100001];
int main() {
  cin >> N >> C >> K;

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

  sort(T,T+N);

  ll ans = 1;

  ll tmp = T[0];
  ll count = 0;
  for(int i = 0; i < N; i++) {
    if(tmp + K < T[i] || count == C) {
      ans++;
      tmp = T[i];
      count = 1;
    }
    else count++;
      
  }
  

  cout << ans <<endl;
}


Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <vector>
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
using namespace std;
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(a > b){ a = b; return 1; } return 0; }
int main()
{
  int a,b; cin >> a >> b;
  cout << max(0, a - 2*b) << "\n";
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main()
{
	int a,sum;
	while(scanf("%d",&a)!=EOF)
	{
		sum=0;
		for(int i=1;i<4;i++)
		{
			sum=sum+a%10;
			a=a/10;
		}
		printf("%d\n",sum);
	}
 } 

Measured memory_bytes: 128
/*BISMILLAH
THE WHITE WOLF
NO DREAM IS TOO BIG AND NO DREAMER IS TOO SMALL*/

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

#define io ios_base::sync_with_stdio(false)
#define ll long long
#define ull unsigned long long
#define vi vector<int>
#define vll vector<long long>
#define pb push_back
#define mod 100000007
#define pii pair<int, int>
#define PI 2*acos(0.0)

double a, b, h, m;

int main()
{
    io;
    cin>> a>>b>>h >>m;
    h += m/60;
    double ma = PI/30*m, ha = PI/6*h;
    double ang = ha - ma;
    double ans = sqrt(a*a + b*b - 2*a*b*cos(ang));
    printf("%.15f", ans);
    return 0;
}


Measured memory_bytes: 4112
#include <iostream>
#include <vector>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;

int main(){
  int n;
  cin >> n;
  vector<int> a(n), b(n), c(n-1);
  rep(i, n) {cin >> a[i]; a[i]--;}
  rep(i, n) cin >> b[i];
  rep(i, n-1) cin >> c[i];
  
  int ans = 0;
  rep(i, n){
    ans += b[a[i]];
    if (i == 0) continue;
    if (a[i] == a[i-1] + 1) ans += c[a[i-1]];
  }
  cout << ans << endl;
  
  return 0;
}

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

using namespace std;
typedef long long int ll;
typedef pair<int, int> ii;

struct fastio {
    fastio() {
        ios::sync_with_stdio(false);
        cout << setprecision(10) << fixed;
        cin.tie(0);
    }
};

fastio _fast_io;

const int N = 1e5 + 5;
int n, m, k, ans;

int main() {
    cin >> n;
    for (int i = 0; i < n; ++i) {
        cin >> m;
        k = max(k, m);
        ans += m;
    }
    cout << ans - k / 2 << endl;
    return 0;
}


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

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, k, r, s, p;
    cin >> n >> k >> r >> s >> p;
    string t;
    cin >> t;
    long long ans = 0;
    for(int i = 0; i < n; i++){
        if(i+k >= n){
            if(t[i] == 'r') ans += p;
            if(t[i] == 's') ans += r;
            if(t[i] == 'p') ans += s;
        }
        else if(t[i] != t[i+k]){
            if(t[i] == 'r') ans += p;
            if(t[i] == 's') ans += r;
            if(t[i] == 'p') ans += s;
        }
        else{
            if(t[i] == 'r') ans += p;
            if(t[i] == 's') ans += r;
            if(t[i] == 'p') ans += s;
            t[i+k] = 'n';
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 512
#include <stdio.h>

int main(void) {
	// your code goes here
	int r,h;
	int ans;
	
	scanf("%d%d",&h,&r);
	if(h==(-1)*r) ans=0;
	else if(h<(-1)*r) ans=-1;
	else ans=1;
	
	printf("%d\n",ans);
	
	return 0;
}

Measured memory_bytes: 596
n = int(input())
water = list(map(int,input().split()))

half_sum_water = sum(water) // 2

ans = []

m = n // 2
x0 = half_sum_water
for i in range(m):
    x0 = x0 - water[(1 + (i * 2)) % n]

print(x0 * 2,end = ' ')

x = x0
for i in range(n - 1):
    x = water[i] - x
    print(x * 2,end = ' ')

print()   


Measured memory_bytes: 14028
#include <algorithm>
#include <iostream>
#include <vector>
#include <math.h>
#include <set>
#include <map>
#include <string>
#include <stack>
#include <queue>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <bitset>
#include <complex>
#include <unistd.h>
#include <cassert>
#include <cctype>
#include <random>
#include <time.h>
#include <functional>
#define _USE_MATH_DEFINES
#define _GLIBCXX_DEBUG
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> plglg;
typedef pair<double, ll> pdlg;
typedef tuple<int, int, int> tiii;
typedef tuple<ll, ll, ll> tlglglg;
typedef tuple<ll, ll, ll, ll> tlglglglg;
typedef tuple<double, double, double> tddd;
typedef complex<double> xy_t;
typedef vector<ll> vll;
typedef vector< vector<ll> > matrix;
typedef unsigned int uint;
typedef unsigned long long ull;
template <class T> using V = vector<T>;
template <class T> using VV = V<V<T>>;
template <class T> using VVV = V<VV<T>>;
#define REP(i, x, y) for(ll i = (ll)x; i < (ll)y; i++)
#define DREP(i, x, y, d) for(ll i = (ll)x; i < (ll)y; i += (ll)d)
#define PER(i, x, y) for(ll i = (ll)x; i > (ll)y; i--)
#define DPER(i, x, y, d) for(ll i = (ll)x; i > (ll)y; i -= (ll)d)
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
double pi = 3.141592653589793;
ll mod = 1000000007;
int intmax = 2147483647;
int intmin = -2147483648;
ll llmax = 9223372036854775807;
ll llmin = -9223372036854775807;
int iinf = intmax / 8;
ll inf = llmax / 8;
double eps = 1e-12;
void yesno(bool ok, string yes = "Yes", string no = "No") {
    if (ok) {
        cout << yes << endl;
    } else {
        cout << no << endl;
    }
}

int pn = 0;
int primes[16000000];
int eulnums[16000000];

void eulerprime(int n) {
    fill(eulnums, eulnums + n + 1, 0);
    for (int i = 2; i <= n; i++) {
        if (eulnums[i] == 0) {
            eulnums[i] = i;
            primes[pn] = i;
            pn++;
        }

        for (int j = 0; i * primes[j] <= n; j++) {
            eulnums[i * primes[j]] = primes[j];
            if (i % primes[j] == 0) {
                break;
            }
        }
    }
}

ll bo[10000010];

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N;
    cin >> N;
    eulerprime(N);
    fill(bo, bo + N + 1, 1);
    REP(i, 0, pn) {
        ll p = primes[i];
        ll num = N / p;
        REP(j, 1, num + 1) {
            ll tmp = p * j;
            // cout << tmp << endl;
            ll a = 0;
            while (tmp % p == 0) {
                a++;
                tmp /= p;
            }
            // cout << a << " bbb" << endl;
            bo[p * j] *= a + 1;
        }
    }
    ll ans = 0;
    REP(i, 1, N + 1) {
        ans += i * bo[i];
    }
    // REP(i, 1, N + 1) {
    //     cout << bo[i] << " ";
    // }
    // cout << endl;
    cout << ans << endl;
}


Measured memory_bytes: 123424
#include <cassert>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <iostream>
#include <vector>
#include <string>
#include <sstream>
#include <algorithm>
#include <utility>
#include <unordered_set>
#include <unordered_map>
#include <stack>
#include <queue>
#include <deque>
#include <functional>
#include <numeric>
#include <complex>
#include <iomanip>

using namespace std;

#define bitcount(n) __builtin_popcount(n)

#define debug(n) cout << n << endl;

#define PREC(n) setprecision(n)
#define DOTPREC(n) fixed << setprecision(n)

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<pii> vpii;

#define fst first
#define scd second
#define PB push_back
#define MP make_pair
#define rep(i,x) for(int i=0;i<(x);++i)
#define rep1(i,x) for(int i=1;i<=(x);++i)
#define rrep(i,x) for(int i=(x)-1;i>=0;--i)
#define rrep1(i,x) for(int i=(x);i>=1;--i)
#define FOR(i,a,x) for(int i=(a);i<(x);++i)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()

#define omajinai ios::sync_with_stdio(false); cin.tie(0)

template<typename T> bool chmax(T&a,T b) { if(a < b) {a = b; return true;} return false;}
template<typename T> bool chmin(T&a,T b) { if(a > b) {a = b; return true;} return false;}

const int inf = 1e9;
const ll linf = 3e18;
const double eps = 1e-9;

const ll MOD = 1000000007;

string a, b, c;

int main(void)
{
    cin >> a >> b >> c;
    vector<string> cards = {a, b, c};
    int index = 0;
    int str_index[3] = {0, 0, 0};
    while (1) {
        if (cards[index].size() <= str_index[index]) {
            cout << char(index + 'A') << endl;
            return 0;
        }
        index = cards[index][str_index[index]++] - 'a';
    }

    return 0;
}


Measured memory_bytes: 760
fun main(args: Array<String>) {

    val num = readLine()!!.toString()

    val firstAndSecond = Integer.parseInt(num.take(2))
    val thirdAndFourth = Integer.parseInt(num.takeLast(2))
    var isMM__ = false
    var is__MM = false

    if ((firstAndSecond >= 1) && (firstAndSecond <= 12)) {
        isMM__ = true
    }

    if ((thirdAndFourth >= 1) && (thirdAndFourth <= 12)) {
        is__MM = true
    }

    if (isMM__ && is__MM) {
        print("AMBIGUOUS")
        return
    }

    if (isMM__ && !is__MM) {
        print("MMYY")
        return
    }

    if (!isMM__ && is__MM) {
        print("YYMM")
        return
    }
    if (!isMM__ && !is__MM) {
        print("NA")
        return
    }
    if ((firstAndSecond == 0) && is__MM) {
        print("YYMM")
    }

    if ((thirdAndFourth == 0) && isMM__) {
        print("MMYY")
    }

}



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

int main() {
  int A,B,C,D;
  cin >> A >> B >> C >> D;
  if(A+B > C+D)
    cout << "Left" << endl;
  else if(A+B < C+D)
    cout << "Right" << endl;
  else
    cout << "Balanced" << endl;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
   int s;
   int m;
   int h;
   int a;
   int b;
   cin>>s;
   h=s/3600;
   a=s%3600;
   m=a/60;
   b=a%60;
   cout<<h<<":"<<m<<":"<<b<<endl;
   return 0;
}


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

#ifdef LOCAL
#define debug(var) cerr << (#var) << " = " << (var) << endl;
#else
#define debug(var)
#endif

void init() {
  ios_base::sync_with_stdio(0);
  cin.tie(0); cout.tie(0);
}

const double EPSILON = 1e-9;
const double PI = acos(-1);

bool eq(double a, double b) {
  return abs(a-b) <= EPSILON;
}

void solve() {
  int a, b, h, m; scanf("%d%d%d%d", &a, &b, &h, &m);
  h = h*60+m;
  double H = 1.*h/(12*60), M = 1.*m/60;
  if (eq(H, M)) {
    printf("%d", abs(a-b));
    return;
  }
  double angle;
  if (M < H) {
    angle = (H - M)*2*PI;
  } else {
    angle = (M - H)*2*PI;
  }
  double ans = sqrt(a*a+b*b - 2*a*b*cos(angle));
  printf("%.9f", ans);
}

int main() {
  init();
  int t = 1; //scanf("%d", &t);
  while (t--) {
    solve();
  }
  return 0;
}


Measured memory_bytes: 4268
// https://atcoder.jp/contests/dwacon6th-prelims/tasks/dwacon6th_prelims_a

#include "algorithm"
#include "bitset"
#include "cmath"
#include "functional"
#include "iomanip"
#include "iostream"
#include "map"
#include "numeric"
#include "queue"
#include "set"
#include "string"
#include "vector"
#define rep(i, to) for (ll i = 0; i < (to); ++i)
#define rep1(i, to) for (ll i = 1; i <= (to); ++i)
#define repf(i, from, to) for (ll i = from; i < (to); ++i)
#define repr(i, from) for (ll i = from - 1; i >= 0; --i)
#define all(vec) vec.begin(), vec.end()
#define unless(cond) if (!(cond))
#define fi first
#define se second
using namespace std;
typedef long long ll;
template <typename T>
using V = vector<T>;
using VL = V<ll>;
using VVL = V<VL>;
template <typename T, typename U>
using P = pair<T, U>;
using PL = P<ll, ll>;
using VPL = V<PL>;
template <typename T>
inline bool chmax(T& a, T b);
template <typename T>
inline bool chmin(T& a, T b);
void print_ints(vector<ll> v);
template <typename T>
void drop(T a);

const ll INF = 1e18;

void solve() {
  ll N;
  cin >> N;

  V<P<string, ll>> ms(N);
  rep(i, N) {
    string t;
    ll s;
    cin >> t >> s;
    ms[i] = {t, s};
  }

  string X;
  cin >> X;

  bool appeared = false;
  ll res = 0;

  rep(i, N) {
    if (appeared) {
      res += ms[i].se;
    }

    if (ms[i].fi == X) {
      appeared = true;
    }
  }

  cout << res << endl;
}

struct exit_exception : public std::exception {
  const char* what() const throw() { return "Exited"; }
};

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

  try {
    solve();
  } catch (exit_exception& e) {
  }

  return 0;
}
#endif

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

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

void print_ints(vector<ll> v) {
  rep(i, v.size()) {
    if (i > 0) {
      cout << " ";
    }

    cout << v[i];
  }

  cout << endl;
}

template <typename T>
void drop(T res) {
  cout << res << endl;
  throw exit_exception();
}


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

// template {{{  0 
// using {{{ 1
using ll = long long int;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vii = vector<pii>;
using vll = vector<pll>;
// }}} 1
// definition {{{ 1
// scaning {{{ 2
#define Scd(x) scanf("%d", &x)
#define Scd2(x,y) scanf("%d%d", &x, &y)
#define Scd3(x,y,z) scanf("%d%d%d", &x, &y, &z)
#define Scll(x) scanf("%lld", &x)
#define Scll2(x,y) scanf("%lld%lld", &x, &y)
#define Scll3(x,y,z) scanf("%lld%lld%lld", &x, &y, &z)
#define Scc(c) scanf("%c", &c);
#define Scs(s) scanf("%s", s);
#define Scstr(s) scanf("%s", &s);
// }}} 2
// constants {{{ 2
#define EPS (1e-7)
#define INF (2e9)
#define PI (acos(-1))
// }}} 2
// systems {{{ 2
#define Repe(x,y,z) for(ll x = z; x < y; x++)
#define Rep(x,y) Repe(x,y,0)
#define RRepe(x,y,z) for(ll x = y-z-1; x >= 0; x--)
#define RRep(x,y) RRepe(x,y,0)
// }}} 2
// output {{{ 2
#define YesNo(a) (a)?printf("Yes\n"):printf("No\n")
#define YESNO(a) (a)?printf("YES\n"):printf("NO\n")
// }}} 2
// }}} 1
// input {{{ 1
// }}} 1
// }}} 0

int main() {

    int N,L;
    Scd(N);
    vi x(N);
    Rep(i,N){
        Scd(x[i]);
    }
    Scd(L);

    vector<vi> pare(N,vi(20));

    int to = 1;
    Rep(from,N){
        while( to < N-1 && x[to+1] <= x[from]+L ){
            to++;
        }
        pare[from][0] = to;
    }

    RRep(from,N){
        Repe(di,20,1){
            pare[from][di] = pare[pare[from][di-1]][di-1];
        }
    }

    auto paresch = [&]( int a, int dis){
        int bi = 0;
        while( dis >= (1<<bi) ){
            if( dis & (1<<bi) ) a = pare[a][bi];
            bi++;
        }
        return a;
    };

    auto sch = [&]( int a, int b ){
        int l = 0,r = N-1,c = 1;
        // (l,r]
        while( r-l > 1 ){
            c = (r+l)/2;
            if( paresch(a,c) >= b ) r = c;
            else l = c;
        }
        return r;
    };

    int Q;
    int a,b;
    Scd(Q);
    Rep(qqi,Q){
        Scd2(a,b);
        a--,b--;
        if( a>b ) swap(a,b);
        printf ("%d\n", sch(a,b) );
    }

    return 0;
}



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

using namespace std;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int k, a, b;
    cin >> k >> a >> b;
    for (int i = 0; i <= (b - a); i++) {
        if ((a+i) % k == 0) {
            cout << "OK";
            return 0;
        }
    }
    cout << "NG";
}


Measured memory_bytes: 3584
h,n = [int(i) for i in input().split()]
ab = []
for i in range(n):
  a,b = [int(i) for i in input().split()]
  ab.append([a,b])
dp = [[float('inf')]*((h+1)+10**4) for i in range(n+1)]
dp[0][0]=0
for i in range(n):
  for j in range(h+1+10**4):
    if j>=ab[i][0]:
      dp[i+1][j]=min(dp[i][j],dp[i+1][j-ab[i][0]]+ab[i][1])
    else:
      dp[i+1][j]=dp[i][j]
      
ans = float('inf')    
for i in range(n+1):
  for j in range(h,h+1+10**4):
    ans = min(ans,dp[i][j])
print(ans)

Measured memory_bytes: 564616
#pragma GCC optimize ("O3")
#include <iostream>
#include <iomanip>
#include <istream>
#include <ostream>
#include <sstream>
#include <iterator>
#include <vector>
#include <algorithm>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <bitset>
#include <utility>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <string>
#include <ctime>
#include <cctype>
#include <cstdlib>
#define IINF 10e8
#define INF 1<<30
#define MOD 1000000007
#define mod 10007
#define REP(i, a, n) for (ll i = a; i < (ll)(n); i++)
#define REPE(i, a, n) for (ll i = a; i <= (ll)(n); i++)
#define Endl endl
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define eb emplace_back
#define mmax(x,y)(x>y?x:y)
#define mmin(x,y)(x<y?x:y)
#define chmax(x,y) x=mmax(x,y)
#define chmin(x,y) x=mmin(x,y)
#define all(x) (x).begin(),(x).end()
#define siz(x) (ll)(x).size()
#define PI acos(-1.0)
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
typedef pair<int,int>Pin;
typedef pair<ll,ll>Pll;
template<class T> using V=vector<T>;
long long GCD(long long a, long long b) {return b?GCD(b,a%b):a;}
long long LCM(long long a, long long b) {return a/GCD(a,b)*b;}
int dx[4]={-1,0,1,0};
int dy[4]={0,-1,0,1};
int ddx[8]={-1,0,1,0,1,1,-1,-1};
int ddy[8]={0,-1,0,1,1,-1,1,-1};
ll cmp(pair<ll,ll>a,pair<ll,ll> b){
        if(a.se!=b.se)
        return a.se<b.se;
        else
        return a.fi<b.fi;
}
//----------------------------------------------------------------------

//----------------------------------------------------------------------
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    //-------------------------------  
    //ll begin_time=clock();
    //------------------------------
    int a,b;cin>>a>>b;
    cout<<a*b<<" "<<a+a+b+b<<endl;
    //-------------------------------  
    //ll end_time=clock();cout<<"time="<<end_time-begin_time<<"ms"<<endl;
    //-------------------------------
    return 0;
}
//----------------------------------------------------------------------




/*
9 4
1 0 1 0 1 0 0 1 1
1 2
2 4
2 3
4 5
1 6
6 7
6 8
7 9
*/



































Measured memory_bytes: 3228
#include <stdio.h>
#include <cctype>
#include <limits.h>
#include <math.h>
#include <complex>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <cstring>
#include <string>
#include <sstream>
#include <algorithm>
#include <iomanip>
#include <iostream>

#define VARIABLE(x) cerr << #x << "=" << x << endl
#define BINARY(x) static_cast<bitset<16> >(x);
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define REP(i,m,n) for (int i=m;i<(int)(n);i++)
#define if_range(x, y, w, h) if (0<=(int)(x) && (int)(x)<(int)(w) && 0<=(int)(y) && (int)(y)<(int)(h))

const int INF = 1000000000;
const double EPS = 1e-8;
const double PI = 3.14159;
int dx[4]={-1, 0, 1, 0}, dy[4]={0, -1, 0, 1};
using namespace std;
typedef pair<int, int> P;

/** Problem0595 : Taxis **/
int cost[5000][5000];
int N, K;
vector<int> G[5000];
int d[5000];

void dijkstra(int s)
{
	priority_queue<P, vector<P>, greater<P> > Q;
	fill(d, d+N, INF);
	d[s] = 0;
	Q.push(P(0, s));
	
	while (Q.size()) {
		P p = Q.top(); Q.pop();
		int v = p.second;
		if (d[v] < p.first) continue;
		rep(i, N) {
			int to = i;
			if (d[to] > d[v] + cost[v][to]) {
				d[to] = d[v] + cost[v][to];
				Q.push(P(d[to], to));
			}
		}
	}
}

int main()
{
	cin>>N>>K;
	vector<int> C(N), R(N);
	
	rep(i, 5000) rep(j, 5000) cost[i][j] = (i==j)?0:INF;
	
	rep(i, N) cin>>C[i]>>R[i];
	rep(i, K) {
		int a, b; cin>>a>>b;
		a--, b--;
		G[a].push_back(b);
		G[b].push_back(a);
	}
	
	rep(i, N) {
		queue<P> Q;
		bool vis[5000]; fill(vis, vis+5000, false);
		Q.push(P(i, 0));
		vis[i] = true;
		
		while (Q.size()) {
			P p = Q.front(); Q.pop();
			cost[i][p.first] = min(cost[i][p.first], C[i]);
			
			if (p.second < R[i]) {
				rep(j, G[p.first].size()) {
					int to = G[p.first][j];
					if (!vis[to]) {
						vis[to] = true;
						Q.push(P(to, p.second+1));
					}
				}
			}
		}
	}
	
	dijkstra(0);
	
	cout << d[N-1] << endl;
}

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

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

    int N;
    cin >> N;

    map<int, int> s;

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

    int ans = 0;

    for(auto i = begin(s); i != s.end(); i++) {
        if(i -> second % 2) ans++;
    }

    cout << ans << endl;
}

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

int main() {
  double n,sum=0;
  cin>>n;
  for(int i=0; i<n; i++){
    double x; string y;
    cin>>x>>y;
    if(y=="BTC") x *= 380000;
    sum += x;
  }
  cout<<setprecision(13)<<sum;
}

Measured memory_bytes: 256
#include <cstdio>
#include <list>
#include <algorithm>
using namespace std;

int main() {
    int q, x;
    char com[20];

    list<int> v;
    scanf("%d", &q);

    for (int i = 0; i < q; i++) {
        scanf("%s", com);
        if (com[0] == 'i') { // insert
            scanf("%d", &x);
            v.push_front(x);
        } else if (com[6] == 'L') { // deleteLast
            v.pop_back();
        } else if (com[6] == 'F') { // deleteFirst
            v.pop_front();
        } else if (com[0] == 'd') { // delete
            scanf("%d", &x);
            for (list<int>::iterator it = v.begin(); it != v.end(); it++) {
                if (*it == x) {
                    v.erase(it);
                    break;
                }
            }
        }
    }

    int i = 0;
    for (list<int>::iterator it = v.begin(); it != v.end(); it++) {
        if (i++) printf(" ");
        printf("%d", *it);
    }
    printf("\n");

    return 0;
}


Measured memory_bytes: 33884
#include <bits/stdc++.h>
using namespace std;
#define testing 0
#define FOR(ii, ss, ee) for(ll ii = (ss); ii <= (ll)(ee); ++ii)
#define DEC(ii, ss, ee) for(ll ii = (ss); ii >= (ll)(ee); --ii)
#define IAMSPEED ios_base::sync_with_stdio(false); cin.tie(0);
#define db(x) cerr << #x << "=" << x << endl
#define db2(x, y) cerr << #x << "=" << x << " , " << #y << "=" << y << endl
#define db3(a,b,c) cerr<<#a<<"="<<a<<","<<#b<<"="<<b<<","<<#c<<"="<<c<<endl
#define dbv(v) cerr << #v << ":"; for (auto i : v) cerr << i << ' '; cerr << endl
#define dbvp(v) cerr << #v << ":"; for (auto i : v) cerr << "{"  << i.f << ',' << i.s << "} "; cerr << endl
#define dba(a,ss,ee) cerr << #a << ":"; FOR(i,ss,ee) cerr << a[i] << ' '; cerr << endl
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define ll long long 
#define pb push_back
#define inf (int)1e9
#define oo (ll)1e18
#define all(x) (x).begin(), (x).end()
#define f first
#define s second
#define reach cerr << "hi\n";
typedef pair <int, int> pi;
typedef pair <ll,ll> pl;
typedef pair <pi, int> pii;
string lts(ll x) {stringstream s; s << x; return s.str(); }
ll stl(string x) {stringstream s(x); ll temp; s >> temp; return temp; }
string cts(char x) {string s(1,x); return s;}
const int MOD = 1e9 + 7;
template <typename T> void maxself(T& a, T b) {
    a = max(a, b);
}
template <typename T> void minself(T& a, T b) {
    a = min(a, b);
}
#define MAXN 
#if !testing
    #define cerr if(0)cout
#endif
int A[200005];
int dp[200005];
int main() {
    IAMSPEED
    // set testing to 0 when submitting to judge
    #if testing
        freopen("input.txt", "r", stdin);
    #endif
    int n; cin >> n;
    FOR(i,1,n) {
        cin >> A[i];
    }
    int idx = -1;
    FOR(i,1,n) {
        if (A[i]==1) {dp[i] = 1; idx = i;break; }
    }
    if (idx==-1) return cout << -1, 0;
    FOR(i,idx+1,n) {
        dp[i] = dp[i-1];
        if (A[i] == dp[i]+1) ++dp[i];
    }
    cout << n-dp[n];
}


Measured memory_bytes: 1792
N=int(input())
alist=list(map(int,input().split()))

cset=set()
free=0
for a in alist:
  if a>=3200:
    free+=1
  else:
    cset.add(a//400)
#print(cdic)

occupy=len(cset)
if occupy==0:
  print(1,occupy+free)
else:
  print(occupy,occupy+free)

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

long long int N;

struct StrangeBank{
    int val[101010];
    int c[12] = {1, 6, 9, 36, 81, 216, 729, 1296, 6561, 7776, 46656, 59049};

    constexpr StrangeBank() : val(){
        val[0] = 0;
        for(int i = 1, j = 1; i < 101010; ++i){
            val[i] = 9999999;
            while(j < 12 && c[j] <= i)++j;
            for(int k = 0; k < j; ++k){
                val[i] = min(val[i], val[i - c[k]] + 1);
            }
        }
    }
};

constexpr StrangeBank sb = StrangeBank();

int main(){
    scanf("%lld", &N);
    cout << sb.val[N] << endl;
    return 0;
}


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

using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);cin.tie(NULL);
    int x;cin>>x;
    unsigned long long s=0;
    int i;
    for (i=1;;i++){
        s+=i;
        if (s>=x)break;
    }cout<<i<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
int main(void){
    int A,B,C;
    scanf("%d %d %d",&A,&B,&C);
    if((A>=B)&&(A>=C)){
        printf("%d",10*A+B+C);

    }else if((B>=A)&&(B>=C)){
        printf("%d",10*B+A+C);

    }else if((C>=B)&&(C>=A)){
        printf("%d",10*C+A+B);

    }
    return 0;
}

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

int gcd(int a, int b)
{
    if (a < b) swap(a,b);
    int r = a % b;
    while(r != 0){
        a = b;
        b = r;
        r = a % b;
    }
    return b;
}
int main(void)
{
    int k;
    cin >> k;
    ll ans = 0;
    for(int a=1; a<=k; a++){
        for (int b=1; b<=k; b++){
            for (int c=1; c<=k; c++){
                int r = gcd(a, b);
                ans += gcd(r, c);
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
using ll =long long;
#define all(v) v.begin(),v.end()
 
int main() {
  ll N;
  cin>>N;
  if(N%7==0) {
cout<<"Yes"<<endl;
    return 0;
  }
  ll money=N/7*7;
  
  for(ll i=0;i<N/7+1;i++) {
  while(money<N) {
money+=4;
  }
  if(money==N) {
cout<<"Yes"<<endl;
  return 0;
  }
    money-=7;
  }

  
  cout<<"No"<<endl;
}
  
  
  
  


Measured memory_bytes: 3604
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    
    int n;
    cin >> n;
    
    unsigned long long int count = 0;
    for(int i=1; i<=n; i++){
        if(i%3!=0 && i%5!=0) {
            count += i;
        }
    }
    
    cout << count << endl;
    
}

Measured memory_bytes: 3648
#include <iostream>
#include <algorithm>
#include <queue>
using namespace std;

#define int long long

typedef pair<int, int> ii;

const int N = 1e5 + 5;

int X, Y, Z, a[N], b[N], c[N], ans, l[N], r[N], val, p[N];
priority_queue<int, vector<int>, greater<int> > pq;

bool cmp(int u, int v) {
	return (a[u] + b[v] > a[v] + b[u] || (a[u] + b[v] == a[v] + b[u] && u > v));
}

signed main() {
	cin >> X >> Y >> Z;
	for(int i = 1; i <= X + Y + Z; ++i) {
		cin >> a[i] >> b[i] >> c[i];
		ans += c[i];
	}
	for(int i = 1; i <= X + Y + Z; ++i) p[i] = i;
	for(int i = 1; i <= X + Y + Z; ++i) a[i] -= c[i], b[i] -= c[i];
	sort(p + 1, p + X + Y + Z + 1, cmp);
	for(int k = 1; k <= X + Y + Z; ++k) {
		int i = p[k];
		l[k] = -1e18;
		pq.push(a[i]); val += a[i];
		if(pq.size() > X) {
			val -= pq.top();
			pq.pop();
		}
		if(pq.size() >= X) l[k] = val;
	}
	while(pq.size()) pq.pop(); val = 0;
	for(int k = X + Y + Z; k >= 1; --k) {
		int i = p[k];
		r[k] = -1e18;
		pq.push(b[i]); val += b[i];
		if(pq.size() > Y) {
			val -= pq.top();
			pq.pop();
		}
		if(pq.size() >= Y) r[k] = val;
	}
	val = -1e18; l[0] = -1e18; r[X + Y + Z + 1] = -1e18;
	for(int i = 0; i <= X + Y + Z; ++i) val = max(val, l[i] + r[i + 1]);
	cout << val + ans;
}

Measured memory_bytes: 5880
#include<bits/stdc++.h>
using namespace std;
#define ALL(obj) (obj).begin(),(obj).end()
#define RALL(obj) (obj).rbegin(),(obj).rend()
#define REP(i, n) for(int i=0;i<(n);++i)
#define RANGE(i, a, b) for(int i=(a);i<(b);++i)
#define RREP(i, n) for(int i=(n)-1;i>= 0;--i)

#define endl '\n'
#define pb push_back
#define eb emplace_back
#define pque priority_queue
#define umap unordered_map
#define uset unordered_set
#define BIG 2000000000
#define VERYBIG 1000000000000000ll
#define dcout cout<<fixed<<setprecision(20)
#define Accepted_MAGIC cin.tie(0);ios::sync_with_stdio(false)

// typedef long long ll;
using Real = long double;
#define int long long

const long long dx[]={1,0,-1,0,1,1,-1,-1}, dy[]={0,-1,0,1,1,-1,1,-1};
const long long MOD = 998244353;
constexpr Real eps = 1e-9, pi = acos(-1);

template<typename T> inline T GCD(T a,T b){T c;while(b!=0){c=a%b;a=b;b=c;}return a;}
template<typename T> inline T LCM(T a,T b){T c=GCD(a,b);a/=c;return a*b;}
template<typename T> inline T nCr(T a,T b){T i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;}
template<typename T> inline T nHr(T a,T b){return nCr(a+b-1,b);}
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}

typedef pair<int, int> INTP;
typedef vector<int> INTV;
struct edge2 {int to, cost;};
struct edge3 {int from, to, cost;};

signed main(void){
  Accepted_MAGIC;
  
  int N, K; cin >> N >> K;
  cout << min(N%K, K-N%K) << endl;
}

Measured memory_bytes: 256
package main

import (
	"fmt"
	"strconv"
	"strings"
)

func main() {
	var a int
	var b string
	fmt.Scan(&a, &b)
	bInt, _ := strconv.Atoi(strings.Replace(b, ".", "", -1))
	fmt.Println(a * bInt  / 100)
}



Measured memory_bytes: 1820
fn main() {
    let (r, w) = (std::io::stdin(), std::io::stdout());
    let mut sc = IO::new(r.lock(), w.lock());
    let n: usize = sc.read();
    let m: usize = sc.read();
    let mut ans = vec![10; n];
    for _ in 0..m {
        let s = sc.read::<usize>() - 1;
        let c = sc.read::<usize>();
        if ans[s] != 10 && ans[s] != c {
            println!("-1");
            return;
        }
        ans[s] = c;
    }
    if ans[0] == 0 {
        if n == 1 {
            println!("0");
        } else {
            println!("-1");
        }
        return;
    }
    if ans[0] == 10 {
        if n == 1 {
            println!("0");
            return;
        } else {
            ans[0] = 1;
        }
    }
    for ans in ans.into_iter() {
        if ans == 10 {
            print!("0");
        } else {
            print!("{}", ans);
        }
    }
    println!();
}

pub struct IO<R, W: std::io::Write>(R, std::io::BufWriter<W>);

impl<R: std::io::Read, W: std::io::Write> IO<R, W> {
    pub fn new(r: R, w: W) -> IO<R, W> {
        IO(r, std::io::BufWriter::new(w))
    }
    pub fn write<S: std::ops::Deref<Target = str>>(&mut self, s: S) {
        use std::io::Write;
        self.1.write(s.as_bytes()).unwrap();
    }
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .0
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n' || b == b'\r' || b == b'\t')
            .take_while(|&b| b != b' ' && b != b'\n' && b != b'\r' && b != b'\t')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}


Measured memory_bytes: 4352
/*{{{*/
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstring>
#include <unordered_map>
#include <unordered_set>
#include <cassert>
using namespace std;
typedef pair<int, int> PP;
typedef long long LL;
#define pb push_back
#define fr first
#define sc second
#define bitcnt __builtin_popcount
#define all(x) x.begin(), x.end()
inline LL ri() {LL x; scanf("%lld", &x); return x;}
#define rep2(i, n, ...) for (int i = 0; i < (n); i ++) 
#define rep3(i, a, b, ...) for (int i = (a); i < (b); i ++)
#define GET_MACRO(_1, _2, _3, NAME, ...) NAME
#define rep(...) GET_MACRO(__VA_ARGS__, rep3, rep2)(__VA_ARGS__)
#define drep2(i, n, ...) for (int i = (n) - 1; i >= 0; i --)
#define drep3(i, a, b) for (int i = (a) - 1; i >= (b); i --)
#define drep(...) GET_MACRO(__VA_ARGS__, drep3, drep2)(__VA_ARGS__)
template<typename T>inline bool smax(T&a, T b){if(a<b){a=b;return true;}return false;} 
template<typename T>inline bool smin(T&a, T b){if(a>b){a=b;return true;}return false;} 
/*}}}*/


int solve(string&a, string&b) {
  int n = a.size();
  vector<int> p(2 * b.size() + 5);
  p[0] = 0;
  rep(i, n) p[i + 1] = (b[i] - '0') + p[i];
  rep(i, n) p[i + n + 1] = (b[i] - '0') + p[i + n];
  set<int> s;
  rep(i, n) if (b[i] == '1') s.insert(i);

  int res = 1e9;
  rep(i, n) {
    int ans = i, left = 0;
    vector<PP> leftside;
    rep(j, n) if (b[(j + i) % n] != a[j]) { // need to flip j
      // [j, j + i]
      
      if (p[j + i + 1] == p[j]) { // not found
        // [0, j)
        auto it = s.lower_bound(j);
        if (it != s.begin()) { // found one
          it --;
          smin(left, (*it) - j);
          leftside.pb(PP((*it) - j, j));
        } else {
          auto iit = s.rbegin();
          leftside.pb(PP((*iit) - n - j, j));
          //smin(left, (*iit) - n - j);
        }
      }

      ans ++;
    }

    int right = 0;
    sort(leftside.begin(), leftside.end());
    //cout << ans << ' ' << left << endl;
    //ans -= left * 2;
    
    for (int j = 0; j < leftside.size(); j ++) {
      smin(res, ans + 2 * (right - leftside[j].first));

      int k = leftside[j].second;
      auto it = s.lower_bound((k + i) % n);
      if (it != s.end()) {
        smax(right, (*it) - (k + i) % n);
      } else {
        smax(right, (*s.begin()) + n - (k + i) % n);
      }
    }

    smin(res, ans + 2 * right);
  }
  //cout << "----------";
  return res;
}
int main() {

  string a, b;
  cin >> a >>b;
  int n = a.size();
  bool hasone = false;
  rep(i, n) if (b[i] == '1') {
    hasone = true;
    break;
  }
  if (a.size()!= b.size() || (!hasone && a != b)) {
    cout <<-1<<endl; return 0;
  }
  int res = solve(a, b);
  reverse(a.begin(), a.end());
  reverse(b.begin(), b.end());
  smin(res, solve(a, b));
  cout << res << endl;
  
  return 0;
}


Measured memory_bytes: 384
import sys
import heapq
hpush = heapq.heappush
hpop = heapq.heappop
input = sys.stdin.readline
N = int(input())
a = list(map(int, input().split()))
h = []
ltable = [0] * (N + 1)
for i in range(N):
  ltable[0] += a[i]
  hpush(h, a[i])
for i in range(N):
  hpush(h, a[N + i])
  ltable[i + 1] = ltable[i] + a[N + i] - hpop(h)

a.reverse()
h = []
rtable = [0] * (N + 1)
for i in range(N):
  rtable[0] += a[i]
  hpush(h, -a[i])
for i in range(N):
  hpush(h, -a[N + i])
  rtable[i + 1] = rtable[i] + a[N + i] + hpop(h)
#print(ltable, rtable)
res = -10 ** 15
for i in range(N + 1): res = max(res, ltable[i] - rtable[N - i])
print(res)

Measured memory_bytes: 113904
#include <iostream>
#include <iomanip>
#include <vector>
typedef long long ll;
using namespace std;
const ll INF = 1e9;
const ll MOD = 1e9 + 7;
#define repi(i, n, init) for (ll i = init; i < (n); i++)
vector<int> to[200005]; //vector<int>型の配列
vector<int> ans;

void dfs(int v, int p = -1)
{
    for (int u : to[v])
    {
        if (u == p)
            continue;
        ans[u] += ans[v];
        dfs(u, v);
    }
}
int main()
{
    int n, q;
    cin >> n >> q;
    repi(i, n - 1, 0)
    {
        int a, b;
        cin >> a >> b;
        --a;
        --b;
        to[a].push_back(b);
        to[b].push_back(a);
    }
    ans.resize(n); //resize すると0で埋められる
    repi(i, q, 0)
    {
        int p, x;
        cin >> p >> x;
        --p;
        ans[p] += x;
    }
    dfs(0);
    repi(i, n, 0)
    {
        cout << ans[i] << endl;
    }
    return 0;
}

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

#define PI 4*atan(1)
#define INF 1e8

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

int main(){
  int N;
  cin >> N;
  vector<int> a(N), tmp(N, -1);
  for(int i = 0; i < N; i++){
    cin >> a[i];
    tmp[i] = a[i] - 1;
  }
  int cnt = 0;
  for(int i = 0; i < N; i++){
    if(i != -1 && i == tmp[a[i] - 1]){
      cnt++;
      tmp[i] = -1;
      tmp[a[i] - 1] = -1;
    }
  }
  cout << cnt << endl;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
#define rep(i,N) for(ll (i)=0;(i)<(N);(i)++)
const int mod = 1000000007;
const ll INF = 1LL<<60;

int MAX_V = 210; // 頂点数
vector<vector<ll>> d(MAX_V, vector<ll>(MAX_V, INF));
void warshall_floyd() {
  for(int k = 0; k < MAX_V; ++k)
    for(int i = 0; i < MAX_V; ++i)
      for(int j = 0; j < MAX_V; ++j)  d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
}

int main(){
  int n, m, r;
  cin >> n >> m >> r;
  vector<int> p(r);
  rep(i, r) {
    int a;
    cin >> a;
    --a;
    p[i] = a;
  }
  rep(i, m) {
    int a, b, c;
    cin >> a >> b >> c;
    --a;
    --b;
    d[a][b] = c;
    d[b][a] = c;
  }
  rep(i, n) {
    d[i][i] = 0;
  }
  warshall_floyd();

  ll ans = INF;
  sort(p.begin(), p.end());
  do {
    ll t = 0;
    for (int i = 1; i < r; ++i) {
      t += d[p[i]][p[i - 1]];
    }
    ans = min(ans, t);
  } while (next_permutation(p.begin(), p.end()));
  cout << ans << endl;
}

Measured memory_bytes: 640
s = input()
t = input()

n, m = len(s), len(t)

ma = 0
for i in range(n-m+1):
    tmp = 0
    s_sub = s[i:i+m]
    for j in range(m):
        if s_sub[j] == t[j]:
            tmp += 1
    ma = max(ma, tmp)

print(m - ma)

Measured memory_bytes: 67400
#include <bits/stdc++.h>
#include <cstdlib>  // abs() for integer 絶対値求めやつ
#include <cmath>    // abs() for float, and fabs()
#include <algorithm>
#include <vector>
#include <string>
#include<iomanip>//浮動小数点数を出力する制度の指定
//使い方　数値をnumとして　cout<<setprecision(n)<<num ;nは桁数
#define rep(i,n) for(int i = 0; i < (n);i++)
#define SORT(a) sort((a).begin(),(a).end())
#define REV(a) reverse((a).begin(),(a).end())
using namespace std;
using ll =long long;
#define INF 2000000000
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
#define che(a,string) cout<<"//"<<string <<"=="<<(a)<<"//" <<endl;
bool IsInt(double a){int b = a/1;if(a==b){return true;}else {return false;}}
/*覚えてないことメaモ
数値型から文字列に変換　to_string(number);これは簡単
文字列から数値型に変換　stoi(number)
文字列からllに変換　stoll(number)*/

//ここから書き始める

int main(){
    int x1, y1 , x2, y2;
    cin >> x1 >> y1 >> x2 >> y2;
    int x=x2;
    int y=y2;
    int dx = x2-x1;
    int dy = y2-y1;
    x-=dy;
    y+=dx;
    cout<<x<<" "<<y<<" ";
    x-=dx;
    y-=dy;
    cout<<x<<" "<<y<<" ";
}

Measured memory_bytes: 256
// </> : towhid1zaman

#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair< int, int > pii;
typedef pair< pii, int > ppi;
#define fill(a,b) memset(a,b,sizeof(a))
#define all(v) (v).begin(),(v).end()
#define sp(k) cout<<setprecision(k)<<fixed;
#define rep(i,a) for(int i=0;i<a;i++)
#define rep1(i,a,b) for(int i=(a);i<=(b);++i)
#define irep(i,b,a) for(int i=(b);i>=(a);--i)
#define minv(v) *min_element(all(v))
#define maxv(v) *max_element(all(v))
#define unq(v) sort(all(v)),(v).erase(unique(all(v)),(v).end())
#define _ ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define endl "\n"
#define sqr(a) ((a)*(a))
#define sz(a) int(a.size())
#define ff first
#define ss second
#define pb push_back

const double pi = acos(-1.0);
const int mod = 1000000007; // (int)1e9+7
const int inf = 0x3f3f3f3f;// (int)3e18;
const int maxn = 2000100;



int main(){
        _
          string s;
          cin>>s;
          int ans=0;
          ans+=s[0]-1-'0';
          ans+=9*(s.size()-1);
          int ans0=0;
          rep(i,s.size()){
            ans0+=s[i]-'0';
          }
          ans=max(ans,ans0);
          cout<<ans<<endl;

return 0;
}




Measured memory_bytes: 256