akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <map>
#include <string>
using namespace std;
int main() {
  map<string, int> m;
  string s, t, u;
  int n, k = 0, l = 0;
  while (cin >> s) {
    if (s.size() > l) {
      l = s.size();
      u = s;
    }
    m[s]++;
    if (m[s] > k) {
      k = m[s];
      t = s;
    }
  }
  cout << t << ' ' << u << endl;
  return 0;
}

Measured memory_bytes: 1192
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5+5;
int n, k, a[N];
long long dp[N];
long long solve (int i){
    if (i == n-1) return 0;
    if ( dp[i] != -1) return dp[i];
    int diff = n-i-1;
    int limit = min(diff, k);
    long long mini = 1e10;
        for (int j =1;j<=limit; j++){
            long long x= abs(a[i+j]-a[i]) + solve(i+j);
            if ( x< mini) mini=x;
        }
        return dp[i] =mini;
}

int main()
{
    memset(dp, -1, sizeof dp);
    cin >> n >> k;
    for ( int i=0; i<n; i++) cin >> a[i];
    cout << solve (0);
    return 0;
}


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

using namespace std;
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)

typedef long long ll;
typedef pair<ll, ll> P;
const ll INF = 1LL<<60;

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

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; }

ll modpow(ll a, ll n, ll mod) {
  ll res = 1;
  while (n > 0) {
    if (n & 1) res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}

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

  ll N;
  cin >> N;

  ll K;
  cin >> K;

  ll base = 1;

  ll ans = 0;

  while(base <= N){
    base = base * K;
    ans++;
  }

  cout << ans << endl;




  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <set>
#include <string>
#include <queue>
#include <deque>
#include <vector>
#include <map>
#include <math.h>
#include <limits.h>

using namespace std;

int main() {
	set<int> s;
  int a, b, c;
  cin >> a >> b >> c;
  s.insert(a);
  s.insert(b);
  s.insert(c);
  if((int)s.size() == 2){
  	cout << "Yes" << endl;
  }
  else cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
namespace my_header {
#define pb push_back
#define mp make_pair
#define pir pair<int, int>
#define vec vector<int>
#define pc putchar
#define clr(t) memset(t, 0, sizeof t)
#define pse(t, v) memset(t, v, sizeof t)
#define bl puts("")
#define wn(x) wr(x), bl
#define ws(x) wr(x), pc(' ')
    const int INF = 0x3f3f3f3f;
    typedef long long LL;
    typedef double DB;
    inline char gchar() {
        char ret = getchar();
        for(; (ret == '\n' || ret == '\r' || ret == ' ') && ret != EOF; ret = getchar());
        return ret; }
    template<class T> inline void fr(T &ret, char c = ' ', int flg = 1) {
        for(c = getchar(); (c < '0' || '9' < c) && c != '-'; c = getchar());
        if (c == '-') { flg = -1; c = getchar(); }
        for(ret = 0; '0' <= c && c <= '9'; c = getchar())
            ret = ret * 10 + c - '0';
        ret = ret * flg; }
    inline int fr() { int t; fr(t); return t; }
    template<class T> inline void fr(T&a, T&b) { fr(a), fr(b); }
    template<class T> inline void fr(T&a, T&b, T&c) { fr(a), fr(b), fr(c); }
    template<class T> inline char wr(T a, int b = 10, bool p = 1) {
        return a < 0 ? pc('-'), wr(-a, b, 0) : (a == 0 ? (p ? pc('0') : p) : 
            (wr(a/b, b, 0), pc('0' + a % b)));
    }
    template<class T> inline void wt(T a) { wn(a); }
    template<class T> inline void wt(T a, T b) { ws(a), wn(b); }
    template<class T> inline void wt(T a, T b, T c) { ws(a), ws(b), wn(c); }
    template<class T> inline void wt(T a, T b, T c, T d) { ws(a), ws(b), ws(c), wn(d); }
    template<class T> inline T gcd(T a, T b) {
        return b == 0 ? a : gcd(b, a % b); }
    template<class T> inline T fpw(T b, T i, T _m, T r = 1) {
        for(; i; i >>= 1, b = b * b % _m)
            if(i & 1) r = r * b % _m;
        return r; }
};
using namespace my_header;

const int N = 333;

int n, m, a[N][N];
int fob[N], cnt[N];

int main() {
#ifdef lol
	freopen("b.in", "r", stdin);
	freopen("b.out", "w", stdout);
#endif

	fr(n, m);
	int ans = n;
	for (int i = 1; i <= n; ++i)
		for (int j = 1; j <= m; ++j)
			fr(a[i][j]);
	for (int i = 1; i <= m; ++i) {
		memset(cnt, 0, sizeof cnt);
		for (int j = 1; j <= n; ++j) {
			for (int l = 1; l <= m; ++l)
				if (!fob[a[j][l]]) {
					++cnt[a[j][l]];
					break;
				}
		}
		int p = distance(cnt, max_element(cnt + 1, cnt + m + 1));
		ans = min(ans, cnt[p]);
		fob[p] = 1;
	}
	wt(ans);

	return 0;
}


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

import sys

rectangle = []
h,w = 1,1

while not(h == 0 and w == 0):
    h,w = map(int, input().split())
    rectangle.append([h,w])

l = len(rectangle)
count = 0

for rec in rectangle:
    count += 1
    for row in range(rec[0]):
        for col in range(rec[1]):
            sys.stdout.write('#')
        print('')
    if (count < l):
        print('')

Measured memory_bytes: 8348
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const ll INF = 100000000;
#define rep1(i, n) for (ll i=0; i<(n); i++) 
#define rep2(i, k, n) for (ll i=k; i<(n); i++)



vector<ll> zalgo(const string &s){
    ll n = (ll)s.size();
    vector<ll> a(n,0);
    a[0] = n;
    ll i = 1, j = 0;
    while (i < n){
        while (i+j < n && s[j] == s[i+j]){
            j++;
        }
        a[i] = j;
        if (j == 0){
            i++;
            continue;
        }
        ll k = 1;
        while (i+k < n && k+a[k] < j){
            a[i+k] = a[k];
            k++;
        }
        i += k;
        j -= k;
    }
    return a;
}




int main() {
    ll n;
    cin >> n;
    string s;
    cin >> s;
    ll ans = 0;
    rep1(i,n){
        string t = s.substr(i);
        auto lcp = zalgo(t);
        
        rep1(j,t.size()){
            ll l = min(lcp[j],j);
            ans = max(ans, l);
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(){
  long n,i,all=0,total=0;
  long a[200000];
  long mod=1000000007;
  
  scanf("%ld",&n);
  for(i=0;i<n;i++){
    scanf("%ld",&a[i]);
    all=(all+a[i])%mod;
  }
  
  for(i=0;i<n;i++){
    all-=a[i];
    if(all<0){
      all+=mod;
    }
    total=(total+all*a[i])%mod;
  }
  
  printf("%ld",total);
}

Measured memory_bytes: 3260
import itertools
n=int(input())
H=list(map(int,input().split()))

ans=[]
for i in range(1,n):
  if H[i-1]>=H[i]:
    ans.append(1)
  else:
    ans.append(0)

out=0
tmp=0
for a in ans:
  if a==1:
    tmp+=1
  else:
    out=max(out,tmp)
    tmp=0
print(max(out,tmp))

Measured memory_bytes: 14528
from collections import defaultdict
import sys
def solve():
    readline = sys.stdin.readline
    write = sys.stdout.write
    MOD = 10**9 + 7
    Na, Nt, Ng, Nc = map(int, readline().split())
    L = Na + Nt + Ng + Nc
    M = int(readline())
    MP = {}
    S = []
    for i in range(M):
        s = readline().strip()
        s1, s2 = s.split(": ")
        MP[s1] = s2.split(" ")
        S.append(s1)
    R = []
    memo = {}
    def dfs(s):
        if s in memo:
            return memo[s]
        r = []
        for e in MP[s]:
            if e[0] == "[":
                w = 0
                for v in map("ATGC".index, e[1:-1]):
                    w |= 1 << v
                r.append(w)
            else:
                r0 = dfs(e)
                if r0 is None:
                    return None
                r.extend(r0)
        if len(r) > L:
            return None
        memo[s] = r
        return r
    res = dfs(S[0])
    if res is None or len(res) < L:
        write("0\n")
        return
    L = len(res)

    T = [defaultdict(int) for i in range(L+1)]
    T[0][Na, Nt, Ng, Nc] = 1
    for k in range(L):
        s = res[k]
        p0 = s & 1; p1 = s & 2; p2 = s & 4; p3 = s & 8
        T1 = T[k+1]
        for (a, b, c, d), v in T[k].items():
            v %= MOD
            if p0 and a:
                T1[a-1, b, c, d] += v
            if p1 and b:
                T1[a, b-1, c, d] += v
            if p2 and c:
                T1[a, b, c-1, d] += v
            if p3 and d:
                T1[a, b, c, d-1] += v
    write("%d\n" % (T[L][0, 0, 0, 0] % MOD))
solve()


Measured memory_bytes: 907908
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    ll i,ans1,ans2,a,b,v,w,t,flag=0;
    scanf("%lld %lld",&a,&v);
    scanf("%lld %lld",&b,&w);
    scanf("%lld",&t);
    if(a<b)
    {
        if(v<=w)
        {
            flag=0;
        }
        else
        {
            if((b-a)%(v-w)==0)
            {
                if((b-a)/(v-w)<=t)
                {
                    flag=1;
                }
                else
                {
                    flag=0;
                }
            }
            else
            {
                 if((b-a)/(v-w)<=t-1)
                {
                    flag=1;
                }
                else
                {
                    flag=0;
                }
            }
        }
    }
    if(a>b)
    {
        if(v<=w)
        {
            flag=0;
        }
        else
        {
            if((a-b)%(v-w)==0)
            {
                if((a-b)/(v-w)<=t)
                {
                    flag=1;
                }
                else
                {
                    flag=0;
                }
            }
            else
            {
                if((a-b)/(v-w)<=t-1)
                {
                    flag=1;
                }
                else
                {
                    flag=0;
                }
            }
        }
    }
    if(flag==0)
    {
        printf("NO");
    }
    else
    {
        printf("YES");
    }


}


Measured memory_bytes: 3832
#include <iostream>
#include <vector>
#include <cstdio>
#include <algorithm>
#include <set>
#include <map>
#include <cassert>
#include <numeric>
#include <string>
#include <cstring>
#include <cmath>
using namespace std;

#ifdef LOCAL
	#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
	#define eprintf(...) 42
#endif

typedef long long int int64;



const int N = 1005;
char str[N];
map <char, int> cnt;

int main(int,  char **)
{
#ifdef LOCAL
//	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);
#endif

    int n, m;
    scanf("%d%d", &n, &m);
    for (int i = 0; i < n; i++)
    {
        scanf("%s", str);
        for (int j = 0; j < m; j++)
            cnt[str[j] ]++;
    }

    int k4 = (n / 2) * (m / 2);
    int k1 = (n & 1) * (m & 1);
    int k2 = (n * m - 4 * k4 - k1) / 2;


    for (auto p : cnt)
    {
        int x = p.second;
        while (x & 1)
        {
            k1--;
            x--;
        }
        while (x & 3)
        {
            k2--;
            x -= 2;
        }
        while (x)
        {
            k4--;
            x -= 4;
        }
    }
    if (k1 < 0 || k2 < 0)
        printf("No\n");
    else
        printf("Yes\n");

	return 0;
}



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

bool IsPrime( int n );

int main()
{
    int n;
    int cnt = 0;

    scanf("%d", &n );

    for ( int i = 0; i < n; ++i ) {
        int x;
        scanf("%d", &x );
        if ( IsPrime( x ) ) cnt++;
    }

    printf("%d\n", cnt );

    return 0;
}

bool IsPrime( int n )
{
    if ( n < 2 ) return false;
    else if ( n == 2 ) return true;
    else if ( n % 2 == 0 ) return false;

    for ( int i = 3; i <= sqrt( n ); i += 2 ) {
        if ( n % i == 0 ) return false;
    }

    return true;
}




Measured memory_bytes: 3228
#pragma GCC optimize ("O3")

#include <bits/stdc++.h>

using namespace std;

#ifdef LOCAL
#include <prettyprint.hpp>
#define debug(...)  cerr << "[" << #__VA_ARGS__ << "]: ", d_err(__VA_ARGS__);
#else
#define debug(...) 83;
#endif

void d_err() {
    cerr << endl;
}

template <typename H, typename... T>
void d_err(H h, T... t) {
    cerr << h << " ";
    d_err(t...);
}

template <typename T>
void print(T x) {
    cout << x << endl;
}

#define ALL(x) (x).begin(), (x).end()
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define bcnt __builtin_popcountll

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<ll,ll> Pll;
typedef pair<int,int> Pin;

ll INF = 1e16;
int inf = 1e9;
ll MOD = 1e9+7;

int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    
    int X, Y;
    cin >> X >> Y;

    int a = (4 * X - Y) / 2;
    int b = (Y - 2 * X) / 2;

    if (a + b == X && 2 * a + 4 * b == Y && a > -1 && b > -1) {
        print("Yes");
    } else {
        print("No");
    }
    
}


Measured memory_bytes: 3640
def main():
    n,k,q=map(int,input().split(' '))
    answers = [0]*n
    for i in range(q):
        answer = int(input())
        answers[answer-1] += 1
    for i in range(n):
        if k-q+answers[i] >0:
            print('Yes')
        else:
            print('No')

if __name__ == '__main__':
    main()

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

using i32 = std::int_fast32_t;
using i64 = std::int_fast64_t;
template <typename T>
constexpr T INF = numeric_limits<T>::has_infinity ? numeric_limits<T>::infinity() : numeric_limits<T>::max() / 2;

#define REP(i, stop) FOR(i, 0, stop)
#define FOR(i, start, stop) for (int i = start, i##_len = stop; i < i##_len; ++i)
#define RREP(i, n) for (int i = n; i-- > 0;)
#define ALL(v) (v).begin(), (v).end()

template<typename T>
istream& operator>>(istream& in, vector<T>& a) { for (T& x : a) cin >> x; }

void LOG(const int& x) { cerr << x << "\n"; }
void LOG(const vector<int>& a) { for (int x : a) cerr << x << " "; cerr << "\n"; }

int ceil(int a, int b) { return (a - 1) / b + 1; }

class UnionFind {
private:
  vector<int> par;
  vector<int> rnk;
  int find(int x) { return par[x] == x ? x : par[x] = find(par[x]); }
public:
  UnionFind(int size) { par.resize(size); rnk.resize(size); REP(i, size) par[i] = i, rnk[i] = 0; }
  void unite(int x, int y) { x = find(x); y = find(y); if (x == y) return; if (rnk[x] < rnk[y]) { par[x] = y; } else { par[y] = x; if (rnk[x] == rnk[y]) rnk[x]++; } }
  bool same(int x, int y) { return find(x) == find(y); }
};

struct InitCpp { InitCpp() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
} } initCpp;

signed main() {
  int n;
  cin >> n;
  set<int> s;
  REP(i, n) {
    int a;
    cin >> a;
    if (s.count(a))
      s.erase(a);
    else
      s.insert(a);
  }
  cout << s.size() << endl;
}

Measured memory_bytes: 4992
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
typedef long long  ll;
#define rep(i,s,n)for(ll i=s;i<n;i++)
#define repe(i,s,n)for(ll i=s;i<=n;i++)

static const ll MOD = 1e9 + 7;
static const ll INF = (ll)1 << 62;

static const ll MAX_N = 100001;
static const ll MAX_M = 200001;

int main() {
	ll n; string s; cin >> n >> s;
	ll cnt = 0;
	string t = "";

	rep(i, 0, s.size()) {
		if (s[i] == '(') {
			cnt++;
			t = t + '(';
		}
		else if (s[i] == ')') {
			cnt--;
			t = t + ')';
		}
		if (cnt < 0) {
			t = '(' + t;
			cnt++;
		}
	}

	if (cnt > 0) {
		rep(i, 0, cnt) {
			t = t + ')';
		}
	}

	cout << t << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <numeric>
#define rep(i, m, n) for(int i = m;i < n;i++)
#define repr(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define INF 999999999
using namespace std;

long long normalize = 1000000007;

long long fanc(long long x){
    long long ans = 1;
    rep(i, 1, x + 1) ans = (i * ans) % normalize;
    return ans;
}

int main(){
    long long n, m; cin >> n >> m;
    //EXCEPTION
    if(abs(n-m) >= 2) goto cant_make_pire;
    //TRY
    long long ans;
    //clucrate n! and m!
    long long n_fanc, m_fanc;
    n_fanc = fanc(n);
    m_fanc = fanc(m);
    //n + m = odd
    if(abs(m - n) == 1) ans = (n_fanc * m_fanc) % normalize;
    //n + m = even_n
    else if(m == n) ans = (n_fanc * m_fanc * 2) % normalize;

    cout << ans << endl;
    return 0;

    cant_make_pire:;
    cout << 0 << endl;
}


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

using namespace std;

typedef long long ll;
typedef pair<ll, ll> pii;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef vector<pii> vpii;
const ll INF = (1ll << 60);

int main() {
  int x, y;
  cin >> x >> y;
  if (x > y)
    swap(x, y);
  if (x == 1 && y == 1)
    cout << 1000000 << endl;
  else if (x == 1 && y == 2)
    cout << 500000 << endl;
  else if (x == 1 && y == 3)
    cout << 400000 << endl;
  else if (x == 2 && y == 2)
    cout << 400000 << endl;
  else if (x == 2 && y == 3)
    cout << 300000 << endl;
  else if (x == 3 && y == 3)
    cout << 200000 << endl;
  else if (x == 1)
    cout << 300000 << endl;
  else if (x == 2)
    cout << 200000 << endl;
  else if (x == 3)
    cout << 100000 << endl;
  else
    cout << 0 << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(){
	int h,w,a[100005],b[105][105];
	scanf("%d %d",&h,&w);
	int n;
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
		scanf("%d",&a[i]);
	int p=1,l=1;
	for(int i=1;i<=n;i++){
		while(a[i]!=0){
			a[i]--;
			b[l][p++]=i;
			if(p==w+1){
				p=1;
				l++;
			}	
		}
	}
	for(int i=1;i<=h;i++)
		for(int j=1;j<=w;j++){
			if(i%2==1){
				if(j==w)printf("%d\n",b[i][j]);
				else printf("%d ",b[i][j]);
			}
			else{
				if(j==w)printf("%d\n",b[i][w-j+1]);
				else printf("%d ",b[i][w-j+1]);
			}
		}
}

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

typedef long long ll;
const ll MOD = 1000000007;

int main()
{
  int N;
  std::string S;
  std::cin >> N >> S;

  std::vector<int> cnt(26, 0);
  for (auto c : S) {
    ++cnt[c - 'a'];
  }

  ll ans = 1;
  for (auto c : cnt) {
    ans = (ans * (c + 1)) % MOD;
  }

  std::cout << ans - 1 << std::endl;
  return 0;
}


Measured memory_bytes: 512
n=int(input())
def bs(n):
    l,r=0,10**9
    while l+1!=r:
        if n>(((l+r)//2)**2+(l+r)//2)/2:
            l=(l+r)//2
        else:
            r=(l+r)//2
    return r
a=(bs(n)**2+bs(n))//2-n
for i in range(bs(n)):
    if i+1==a:
        continue
    print(i+1)

Measured memory_bytes: 3316
#include <cstdio>
#include <cstring>
#include <algorithm>

static const int maxm = 1e6 + 10;
static const int INF = 1 << 30;

int A[maxm],pre[maxm],suf[maxm];
int N,D,Q,cur,x;

int main(){
	scanf("%d%d",&N,&D);
	
	for(int i = 1;i <= N;i++) scanf("%d",&A[i]);
	
	pre[0] = D;
	for(int i = 1;i <= N;i++){
		if(cur < D && abs(D - cur) > abs(D - cur - A[i])){
			pre[i] = abs(D - cur - A[i]);
			cur += A[i];
		}
		else if(cur > D && abs(D - cur) > abs(cur - A[i] - D)){
			pre[i] = abs(cur - A[i] - D);
			cur -= A[i];
		}
		else pre[i] = pre[i - 1];
	}

	memset(suf,0x3f,sizeof suf);
	
	suf[N] = 1;
	for(int i = N - 1;i >= 1;i--){
		if(A[i + 1] / 2 >= suf[i + 1]) suf[i] = suf[i + 1];
		else suf[i] = suf[i + 1] + A[i + 1];
	}
	
//	for(int i = 1;i <= N;i++) printf("%d ",pre[i]); putchar(10);
//	for(int i = 1;i <= N;i++) printf("%d ",suf[i]); putchar(10);
	
	scanf("%d",&Q);
	for(int i = 1;i <= Q;i++){
		scanf("%d",&x);
		if(suf[x] <= pre[x - 1]) puts("YES");
		else puts("NO");
	}
	
	return 0;
}


Measured memory_bytes: 12032
#include<bits/stdc++.h>
#include <boost/math/common_factor_rt.hpp>
const int INF = 1e9;
const int MOD = 1e9+7;
using LL = long long;
const LL LINF = 1e18;
using namespace std;
#define COUT(v) cout<<(v)<<endl
#define CIN(n)  int(n);cin >> (n)
#define LCIN(n) LL(n);cin >> (n)
#define SCIN(n) string(n);cin >> (n)
#define YES(n) cout<<((n)? "YES" : "NO")<<endl
#define Yes(n) cout<<((n)? "Yes" : "No")<<endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE"  ) << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible"  ) <<endl

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)

#define FOREACH(x,a) for(auto& (x) : (a) )

#define ALL(obj) (obj).begin(),(obj).end()

#define P pair<LL,LL>
#define I vector<int>
#define S set<int>
#define pb(v) push_back(v)
#define V vector
#define rt return
#define rmsame(a) sort(ALL(a)),a.erase(unique(ALL(a)), a.end())

typedef string::const_iterator State;
class PalseError {};
class Edge{
public:
    LL from,to,value;
    Edge(LL a,LL b,LL c){
        from = a;
        to = b;
        value = c;
    }
    Edge(LL a,LL b){
        from = a;
        to = b;
    }
};
int main(){
    CIN(N);
    map<int,int> mp;
    I vec;
    REP(a,N){
        CIN(b);
        vec.pb(b);
        if(mp.find(b)==mp.end()){
            mp[b]=1;
        }else{
            mp[b]++;
        }
    }
    map<int,int> w;
    if(N%2){
        w[0]=1;
        REP(a,N-1){
            w[a+1]=2;
        }
    }else{
        REP(a,N-1){
            w[a+1]=2;
        }
    }
    bool result = true;
    FOREACH(a,mp){
        if(a.second != w[a.first]){
            result = false;
        }
    }
    if(result){
        LL ans = 1;
        REP(a,N/2){
            ans *= 2;
            ans %= MOD;
        }
        COUT(ans);
    }else{
        COUT(0);
    }
    return 0;
}


Measured memory_bytes: 8312
import java.util.*;
 
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String S = sc.next();
        String[] s = S.split("");
        int len = 0;
        StringBuilder sb = new StringBuilder();
        for(int i=0; i<s.length; i++) {
            if(s[i].equals("A") || s[i].equals("C") || s[i].equals("G") || s[i].equals("T")) {
                sb.append(s[i]);
                if(i == s.length-1) {
                    if(sb.length() > len) {
                        len = sb.length();
                    }
                }
            }else {
                if(sb.length() > len) {
                    len = sb.length();
                    sb = new StringBuilder();
                }
            }
        }
        
        System.out.println(len);
    }
}

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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcountll

#define INF 1e16
#define mod 998244353

ll dp[3003][3003][2];

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

  ll A,B,C,D;
  cin>>A>>B>>C>>D;

  dp[A][B][0]=1;
  repl(i,A,C+1){
    repl(j,B,D+1){
      rep(k,2){
        if(j+1<=D){
          if(k==0){
            (dp[i][j+1][0]+=dp[i][j][k]*i%mod)%=mod;
          }else{
            (dp[i][j+1][0]+=dp[i][j][k]%mod)%=mod;
          }
        }
        if(i+1<=C){
          (dp[i+1][j][1]+=dp[i][j][k]*j%mod)%=mod;
        }
      }
    }
  }
  cout<<(dp[C][D][0]+dp[C][D][1])%mod<<endl;

  return 0;
}


Measured memory_bytes: 144352
#!usr/bin/env python3
from collections import defaultdict, deque
from heapq import heappush, heappop
from itertools import permutations, accumulate
import sys
import math
import bisect
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    n,m,v,p = LI()
    a = LI()
    a.sort()
    l = -1
    r = n-1
    while l+1 < r:
        i = (l+r) >> 1
        A = a[i]+m
        ri = bisect.bisect_right(a,A)
        j = n-ri
        if j >= p:
            l = i
            continue
        s = m*p
        for j in range(n-p+1):
            if i == j:
                continue
            s += min(m,A-a[j])
        if s >= m*v:
            r = i
        else:
            l = i
    print(n-r)
    return

#Solve
if __name__ == "__main__":
    solve()


Measured memory_bytes: 58864
n = int(input())
h = list(map(int, input().split()))
h = h[::-1]
ans = ''
for i in range(1, n):
  if h[i - 1] >= h[i]:
    next
  elif h[i] - h[i - 1] == 1:
    h[i] = h[i] - 1
  else:
    ans = 'No'
    break
if ans == '':
  ans = 'Yes'
print(ans)

Measured memory_bytes: 20680
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int p = 1e9 + 7;
inline void add(int &x, int y) {
  x += y;
  if (x >= p) {
    x -= p;
  }
}
inline void dec(int &x, int y) {
  x -= y;
  if (x < 0) {
    x += p;
  }
}
inline int qpow(int value, int n) {
  int result = 1;
  for (; n; n >>= 1, value = (ll)value * value % p) {
    if (n & 1) {
      result = (ll)result * value % p;
    }
  }
  return result;
}
int main() {
  do {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
  } while (false);
  int a, b, c, A, B, C;
  cin >> a >> b >> c >> A >> B >> C;
  if (A % a || B % b || C % c) {
    puts("0");
  } else {
    auto calc = [&] (int n, int N, int m, int M) {
      int result = 0;
      add(result, (ll)m * qpow(n, M / m) % p);
      add(result, (ll)n * qpow(m, N / n) % p);
      dec(result, (ll)n * m % p);
      return result;
    };
    int answer = 0;
    add(answer, (ll)a * qpow(calc(b, B, c, C), A / a) % p);
    add(answer, (ll)b * qpow(calc(a, A, c, C), B / b) % p);
    add(answer, (ll)c * qpow(calc(a, A, b, B), C / c) % p);
    dec(answer, (ll)a * b % p * qpow(c, A / a * B / b) % p);
    dec(answer, (ll)a * c % p * qpow(b, A / a * C / c) % p);
    dec(answer, (ll)b * c % p * qpow(a, B / b * C / c) % p);
    add(answer, (ll)a * b * c % p);
    int limit = max(A / a, B / b);
    vector<vector<int> > binom(limit + 1, vector<int>(limit + 1));
    for (int i = 0; i <= limit; i++) {
      binom[i][0] = binom[i][i] = 1;
      for (int j = 1; j < i; j++) {
        binom[i][j] = (binom[i - 1][j] + binom[i - 1][j - 1]) % p;
      }
    }
    vector<vector<int> > dp(A / a + 1, vector<int>(B / b + 1));
    for (int i = A / a; i > 0; i--) {
      for (int j = B / b; j > 0; j--) {
        dp[i][j] = (ll)binom[A / a][i] * binom[B / b][j] % p * qpow(c, (A / a - i) * (B / b - j)) % p;
        for (int x = i; x <= A / a; x++) {
          for (int y = j; y <= B / b; y++) {
            if (x != i || y != j) {
              dec(dp[i][j], (ll)dp[x][y] * binom[x][i] % p * binom[y][j] % p);
            }
          }
        }
        if (i != A / a || j != B / b) {
          int result = 0;
          add(result, qpow(qpow(b, i) + qpow(a, j) - 1, C / c));
          dec(result, qpow(qpow(b, i), C / c));
          dec(result, qpow(qpow(a, j), C / c));
          add(result, 1);
          add(answer, (ll)result * a * b * c % p * dp[i][j] % p);
        }
      }
    }
    cout << answer << endl;
  }
  return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include<string>
#include<cstring>
#include <cstdio>
#include<utility>
#include<algorithm>
#include<vector>
#include<cmath>
#include<map>
#include<bitset>
#include<queue>
#include<stack>
#include<set>
#include <limits>
#include <climits>
#include <numeric>
#include<cassert>
#include<cctype>
#include<iterator>
using namespace std;
typedef long long ll;
typedef vector<ll>VI;
typedef vector<bool>VB;
typedef pair<ll,ll>P;
typedef pair<double,double>P_D;
#define VV(T) vector<vector<T>>
#define PI 3.1415926535897932384626433832795
#define rep(i, n) for (ll i = 0; i < (ll)n; i++)
#define reprev(i, n) for (ll i = (ll)n - 1; i >= 0; i--)
#define bitrep(bit,A) for(int bit=A; ;bit=(bit-1)&A)
#define ALL(a)  (a).begin(),(a).end()
#define SZ(a) (ll)((a).size())
#define c_max(a, b) (((ll)a)>((ll)b)?(a):(b))
#define c_min(a,b) (((ll)a)<((ll)b)?(a):(b))
#define chmax(x,a) x=c_max(x,a)
#define chmin(x,a) x=c_min(x,a)
#define vmax(v) *max_element(ALL(v))
#define vmin(v) *min_element(ALL(v))
#define SORT(c) stable_sort(ALL(c))
#define $(x) {cout<<#x<<" = " <<(x)<<endl;}
#define fi first
#define se second
#define MAX 100100//5
#define MAX2 200100
#define MAX_6 1001001//6
#define MAX_7 10010010//7
#define SENTINEL 2000000000//9
#define NIL -1
#define MOD 1000000007
#define INF 1<<30
#define INFTY 1000000000000000001LL
#define MAX_INT INT_MAX
#define Endl '\n'
#define greater greater<int>()
VI findAll(string S,string pattern){VI P;ll pos=(ll)S.find(pattern);
while(pos!=string::npos){P.push_back(pos);pos=(ll)S.find(pattern,pos+1);}return P;}
inline ll GCD(ll a,ll b){return b?GCD(b,a%b):a;}
inline ll lcm(ll a,ll b){return a*b/GCD(a,b);}
bool is_prime(ll n){if(n<2)return 0;for(int i=2;i*i<n;i++)if(n%i==0)return 0;return 1;}
inline void eratosthenes(VB& p){rep(i,SZ(p))p[i]=1;p[0]=p[1]=0;
rep(i,SZ(p)/2+1){if(p[i])for(ll j=i+i;j<SZ(p);j+=i)p[j]=0;}}
inline ll mod_add(ll a,ll b){return (a+b)%MOD;}
inline ll mod_sub(ll a,ll b){return (a+MOD-b)%MOD;}
inline ll mod_mul(ll a,ll b){return ((a%MOD)*(b%MOD))%MOD;}
inline ll mod_pow(ll x,ll n,ll mod=(ll)MOD){ll res=1;while(n>0){
if(n&1)res=res*x%mod;x=x*x%mod;n>>=1;}return res;}
inline ll mod_inv(ll x){return mod_pow(x,MOD-2);}
inline ll mod_div(ll a, ll b){return mod_mul(a,mod_inv(b));}
using Graph=vector<vector<int> >;//int と P

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

Measured memory_bytes: 512
#include "bits/stdc++.h"
using namespace std;
const auto start_time = std::chrono::high_resolution_clock::now();
void timecalculater(){
    #ifndef ONLINE_JUDGE
    auto end_time = std::chrono::high_resolution_clock::now();
    std::chrono::duration<double> diff = end_time-start_time;
    cerr<<"Time Taken : "<<diff.count()<<"\n";
    #endif
}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
void __print(int x) {cout << x;}
void __print(long x) {cout << x;}
void __print(long long x) {cout << x;}
void __print(unsigned x) {cout << x;}
void __print(unsigned long x) {cout << x;}
void __print(unsigned long long x) {cout << x;}
void __print(float x) {cout << x;}
void __print(double x) {cout << x;}
void __print(long double x) {cout << x;}
void __print(char x) {cout << '\'' << x << '\'';}
void __print(const char *x) {cout << '\"' << x << '\"';}
void __print(const string &x) {cout << '\"' << x << '\"';}
void __print(bool x) {cout << (x ? "true" : "false");}
template<typename T, typename V>
void __print(const pair<T, V> &x) {cout << '{'; __print(x.first); cout << ','; __print(x.second); cout << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cout << '{'; for (auto &i: x) cout << (f++ ? "," : ""), __print(i); cout << "}";}
void _print() {cout << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cout << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define dbg(x...) cout << "[" << #x << "] = ["; _print(x)
#else
#define dbg(x...)
#endif
#define fastio  cin.sync_with_stdio(0); cin.tie(0);cin.exceptions(cin.failbit);
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define repA(i, a, n) for(int  i = a; i <= (n); ++i)
#define all(x) x.begin(), x.end()
#define sz(x) (int) (x).size()
#define fill(a,v) memset(a, v, sizeof(a))
#define fst first
#define snd second
#define mp make_pair
#define pb push_back
#define endl '\n'
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<long long int> vll;
typedef vector<pii> vpii;
ll p=1e9+7;
const int N=2e5+5;
int main() {

    fastio;
    int T=1;
    // cin>>T;
    while(T--){
        ll n;cin>>n;
        // ll ans=0;
        ll ans[n+1]={0};
        for(ll x=1;x<=100;x++){
            for(ll y=1;y<=100;y++){
                for(ll z=1;z<=100;z++){
                    ll val=x*x+y*y+z*z+x*y+y*z+z*x;
                    if(val<=n){
                        ans[val]++;
                    }
                }
            }
        }
        for(ll i=1;i<=n;i++){
            cout<<ans[i]<<endl;
        }
    }   
    timecalculater();
    return 0;   
} 

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

int main(){
    int N,K; cin >> N >> K;
    long long sum=0;
    long long a[N];
    for(int i=0;i<N;i++){
        cin >> a[i];
        sum+=a[i];
    }
    sort(a,a+N);
    vector<long long> div;
    for(long long i=1;i*i<=sum;i++){
        if(sum%i==0){
            div.push_back(i);
            if(sum/i!=i) div.push_back(sum/i);
        }
    }
    sort(div.begin(),div.end());
    long long ans=0;
    for(int i=0;i<div.size();i++){
        //cout << div[i] << endl;
        long long tmp[N];
        for(int j=0;j<N;j++){
            tmp[j]=a[j]%div[i];
        }
        sort(tmp,tmp+N);
        for(int j=1;j<N;j++){
            tmp[j]+=tmp[j-1];
        }
        long long a,b;
        bool flag=false;
        for(int j=0;j<N;j++){
            a=tmp[j];
            b=div[i]*(N-1-j)-(tmp[N-1]-tmp[j]);
            if(max(a,b)<=K){
                flag=true;
                break;
            }
        }
        if(flag) ans=max(ans,div[i]);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
// AtCoder Beginner Contest - Problem D: Partittion (https://beta.atcoder.jp/contests/abc112/tasks/abc112_b)
#include <bits/stdc++.h>

#define LOGV(vec, sep) { cerr << #vec << " ="; for (const auto& v : (vec)) cerr << " " << v; cerr << (sep); }

using namespace std;

vector<int> divisors(int M)
{
    vector<int> ds;
    int d;

    for (d = 1; d * d < M; ++d)
    {
        if (M % d)
            continue;

        auto k = M / d;

        ds.push_back(d);
        ds.push_back(k);
    }

    if (d * d == M)
        ds.push_back(d);

    sort(ds.begin(), ds.end());

    return ds;
}

void solve(int N, int M)
{
    auto ds = divisors(M);
    auto ans = 1;

    for (const auto& d : ds)
    {
        if ((M / d) - 1 >= N - 1)
            ans = d;
        else
            break;
    }

    cout << ans << endl;
}

int main()
{
    ios::sync_with_stdio(false);

    int N, M;
    cin >> N >> M;

    solve(N, M);

    return 0;
}


Measured memory_bytes: 256
using System;
using System.Linq;

namespace Sample101
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] line = Console.ReadLine().Split(' ').Select(str => int.Parse(str)).ToArray();

            if (line[0] < line[1])
            {
                Console.WriteLine("a < b");
            } else if (line[0] > line[1])
            {
                Console.WriteLine("a > b");
            } else if (line[0] == line[1])
            {
                Console.WriteLine("a == b");
            }
        }
    }
}


Measured memory_bytes: 18332
#include <bits/stdc++.h>
typedef long long int ll;
#define FOR(i, a, b) for (ll i = (signed)(a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define EREP(i, n) for (int i = (n)-1; i >= 0; --i)
#define MOD 1000000007
#define pb push_back
#define INF 93193111451418101
#define MIN -93193111451418101
#define EPS 1e-11
#define tp(a, b, c) make_tuple(a, b, c)
#define lb(a, b) lower_bound((a).begin(), (a).end(), (b))
#define ub(a, b) upper_bound((a).begin(), (a).end(), (b))
#define bitcnt(a) (ll) __builtin_popcount((a))
using namespace std;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> T;
template <typename T> void fill_all(T &arr, const T &v) { arr = v; }
template <typename T, typename ARR> void fill_all(ARR &arr, const T &v) {
  for (auto &i : arr) {
    fill_all(i, v);
  }
}
//------------------変数-----------------------//
//-------------------関数----------------------//
bool flag[514514];
int main() {
  ll n, x;
  cin >> n >> x;
  if (x == n * 2 - 1 || x == 1) {
    cout << "No" << endl;
    return 0;
  }
  cout << "Yes" << endl;
  if (n == 2) {
    cout << "1 2 3" << endl;
    return 0;
  }
  ll aa[] = {-2, 1, 0, -1};
  if (x == n * 2 - 2) {
    flag[x] = flag[x + 1] = flag[x + -1] = flag[x + -2] = 1;
  } else {
    flag[x] = flag[x - 1] = flag[x + 2] = flag[x + 1] = 1;
    aa[0] = 2;
    aa[1] = -1;
    aa[2] = 0;
    aa[3] = 1;
  }
  ll itr = 1;
  REP(i, (n * 2 - 1) / 2 - 2) {
    while (flag[itr]) {
      itr++;
    }
    cout << itr << endl;
    itr++;
  }
  REP(i, 4) { cout << x + aa[i] << endl; }
  REP(i, (n * 2 - 1) - ((n * 2 - 1) / 2 - 2) - 4) {
    while (flag[itr]) {
      itr++;
    }
    cout << itr << endl;
    itr++;
  }
}


Measured memory_bytes: 1536
#include <bits/stdc++.h>
using namespace std;
#define md 998244353
int main() {
    int n,k;
    cin>>n>>k;
    int g=k;
    vector<pair<int,int>> vc;
    while(g--)
    {
    	int a,b;
    	cin>>a>>b;
    	vc.push_back(make_pair(a,b));
    }
    long long int dp[n+1];
    for(int i=0;i<=n;i++) dp[i]=0;
    dp[n]=0;

    for(int i=n-1;i>=1;i--)
    {
    	int yy=0;
    	for(int j=0;j<k;j++)
    	{
    		if(n-i>=vc[j].first && n-i<=vc[j].second)
    		{yy=1;break;}
    	}
    	if(yy==1) dp[i]=(dp[i]+1)%md;
    	for(int j=0;j<vc.size();j++)
    	{
    		if(i+vc[j].first<n) 
    		{
    			dp[i]=(dp[i]+dp[i+vc[j].first])%md;
    			int g=min(n-1,i+vc[j].second);
    			dp[i]=(dp[i]+md-dp[g+1])%md;
    		}
    	}
    	dp[i]=(dp[i]+dp[i+1])%md;
    }
    long long int an=(dp[1]-dp[2]+md)%md;
    cout<<an<<endl;
	return 0;
}

Measured memory_bytes: 5192
#include<iostream>
#include<string.h>
#include<queue>
#include<map>
#include<vector>
#include <cstdlib>
#include<algorithm>
#include <cstdio>
#include <cctype>
using namespace std;
const long long INF=10000000000000LL;
typedef long long ll;
typedef pair<ll,ll> P;
ll N,K=1,C[55];
ll A,B[55][55][2555]={};
ll ans=0;
bool h,o;
//bool D[100005];
int main(){
	cin>>N>>A;
	for(int i=0;i<N;++i){
		cin>>C[i];
	}
	B[0][0][0]=1;
	for(int i=0;i<N;++i){
		for(int j=0;j<2501;++j){
			for(int k=0;k<=i;++k){
				B[k+1][i+1][j+C[i]]+=B[k][i][j];
				B[k][i+1][j]+=B[k][i][j];
			}
		}
	}
//	cout<<"aaa"<<endl;

	for(ll i=1;i<=N;++i){
		for(ll j=0;j<2501;++j){
			if(j/i==A&&j%i==0)ans+=B[i][N][j];
		}
	}
	cout<<ans<<endl;
	return 0;
}


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

#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
#define abs(a) max((a),-(a))
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define repe(i,n) rep(i,(n)+1)
#define per(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define pere(i,n) rep(i,(n)+1)
#define all(x) (x).begin(),(x).end()
#define SP <<" "<<
#define RET return 0
#define MOD 1000000007
#define INF 1000000000000000000

typedef long long LL;
typedef long double LD;

int main(){
  int n;
  cin >> n;
  vector<int> a(n);
  for(int i=0;i<n;i++) cin >> a[i];
  int nokori;
  bool okflag;
  for(int ans=100;ans>0;ans--){
    nokori=0;
    okflag=true;
    for(int i=0;i<n;i++){
      nokori+=a[i];
      if(nokori<ans){
        okflag=false;
        break;
      }
      nokori-=ans;
    }
    if(okflag){
      cout << ans << endl;
      return 0;
    }
  }
  return 0;
}



Measured memory_bytes: 3104
#include<bits/stdc++.h>
using namespace std;
#define FasterIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define mem(a,x) memset(a,x,sizeof(a))
#define pb push_back
#define mk make_pair
#define ff first
#define ss second
typedef long long ll;
typedef double db;
const int MX=100000;
const ll mod=1e9+7;
vector<ll>g[MX+5];
ll dp[MX+5][2];
void dfs(int x, int p)
{
    dp[x][1]=dp[x][0]=1;
    for(int i=0;i<g[x].size();i++)
    {
        ll ad=g[x][i];
        if(ad==p)continue;
        dfs(ad,x);
        dp[x][0]=(dp[x][0]*(dp[ad][1]+dp[ad][0])%mod)%mod;
        dp[x][1]=(dp[x][1]*dp[ad][0])%mod;
    }
}
int main()
{
    FasterIO;
    ll n,x,y;
    cin>>n;
    for(int i=1;i<n;i++)
    {
        cin>>x>>y;
        g[x].pb(y);
        g[y].pb(x);
    }
    dfs(1,1);
    cout<<(dp[1][0]+dp[1][1])%mod<<endl;
    return 0;
}


Measured memory_bytes: 14208
#include<iostream>
#include<iomanip>
#include<cassert>
#include<stdexcept>
#include<utility>
#include<functional>
#include<numeric>
#include<cmath>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<array>
#include<stack>
#include<queue>
#include<deque>
#include<vector>
#include<complex>
#include<set>
#include<map>
#include<unordered_map>
#include<unordered_set>
#include<string>
#include<bitset>
#include<memory>
using namespace std;
using ll=long long;

int main(){
    int n;
    cin>>n;
    vector<string> s(n);
    vector<int> t(n);
    for(int i=0;i<n;i++) cin>>s[i]>>t[i];

    string tar;
    cin>>tar;
    int res=0;
    for(int i=0;i<n;i++){
        if(tar==s[i]){
            for(int j=i+1;j<n;j++){
                res+=t[j];
            }
            break;
        }
    }
    
    cout<<res<<endl;
    return 0;
}


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

int cnt = 0;
int G[] = {1, 4, 13, 40, 121, 364, 1093, 3280, 9841, 29524, 88573, 265720, 797161};
int A[1000000];
int shellSort(int A[], int n);
void insertionSort(int A[], int n, int g);


int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin>>n;
    for(int i=0; i<n; i++) cin>>A[i];
    int m = shellSort(A, n);
    cout<<m<<'\n';
    for(int i=m-1; i>0; i--) cout<<G[i]<<' ';
    cout<<"1\n"<<cnt<<'\n';

    for(int i=0; i<n; i++) cout<<A[i]<<'\n';
    return 0;
}

int shellSort(int A[], int n)
{
    int m = 1;
    while(G[m]<n) m++;
    for(int i=m-1; i>=0; i--) insertionSort(A, n, G[i]);
    return m;
}

void insertionSort(int A[], int n, int g)
{
    for(int i=g; i<n; i++) {
        int v=A[i];
        int j=i-g;
        while(j>=0 && A[j]>v) {
            A[j+g] = A[j];
            j-=g;
            cnt++;
        }
        A[j+g]=v;
    }
}

Measured memory_bytes: 5112
#!/usr/bin/env python3
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"
dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]
dy8, dx8 = [0, -1, 0, 1, 1, -1, -1, 1], [1, 0, -1, 0, 1, 1, -1, -1]


def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W


def ceil(a, b):
    return (a + b - 1) // b


def sum_of_arithmetic_progression(s, d, n):
    return n * (2 * s + (n - 1) * d) // 2


def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, a % b)


def lcm(a, b):
    g = gcd(a, b)
    return a / g * b


def solve():
    N = int(input())
    X = list(map(int, input().split()))

    ans = INF
    for p in range(0, 102):
        t = 0
        for x in X:
            t += (x - p) ** 2
        ans = min(ans, t)
    print(ans)

def main():
    solve()


if __name__ == '__main__':
    main()


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

// ダイクストラ法
// 参照：蟻本　p97
// O(mlogn)
struct edge{int to,cost;};
typedef pair<int,int> P; // firstは最短距離、secondは頂点の番号

int n; // 頂点の数
vector<edge> G[100010];
int d[100010];

void dijkstra(int s){
    priority_queue<P,vector<P>, greater<P>> que;
    fill(d,d+n,INF);
    d[s]=0;
    que.push(P(0,s));

    while(!que.empty()){
        P p=que.top(); que.pop();
        int v=p.second;
        if(d[v]<p.first) continue;
        rep(i,G[v].size()){
            edge e=G[v][i];
            if(d[e.to]>d[v]+e.cost){
                d[e.to]=d[v]+e.cost;
                que.push(P(d[e.to],e.to));
            }
        }
    }
}

int main(){
    int x,y;
    cin >> n>>x>>y;
    x--,y--;
    for (int i=0; i<n-1; ++i) {
        G[i].push_back({i+1,1});
        G[i+1].push_back({i,1});
    }
    G[x].push_back({y,1});
    G[y].push_back({x,1});
    
    map<int,int> m;
    rep(i,n){
        dijkstra(i);
        rep(j,n) m[d[j]]++;
    }

    for(int k=1;k<=n-1;k++){
        cout<<m[k]/2<<endl;
    }
}



Measured memory_bytes: 6140
import math
N = int(input())
f_min = int(math.log10(N)+1)
for i in range(1,int(math.sqrt(N))+2):
	if N%i == 0:
		f = max(int(math.log10(i)+1),int(math.log10(N//i)+1))
		
		if f < f_min:
			f_min = f
print(f_min)


Measured memory_bytes: 3060
from collections import Counter
n = int(input())
C = Counter(map(int,input().split()))
quad = [i for i in C if C[i] >= 4]
if quad: maxa = max(quad)**2
else: maxa = 0

twice = [i for i in C if C[i] >= 2]
twice.sort()
if len(twice) >= 2: maxa = max(maxa, twice[-1]*twice[-2])
print(maxa)

Measured memory_bytes: 24224
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int A = sc.nextInt();
    int B = sc.nextInt();
    sc.close();
    if (A>=10||B>=10) System.out.println(-1);
    else System.out.println(A*B);
    return;
  }
}


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

#define all(x)        (x).begin(),(x).end()
#define eb            emplace_back
#define mp            make_pair
#define pb            push_back
#define fi            first
#define se            second
#define sz(x)         ((int)(x).size())
#define rep(x,y,z)    for(int x=y;x<z;x++)
#define per(x,z,y)    for(int x=z-1;x>=y;x--)
#define trav(y,x)     for(auto& y:x)
#define pii           pair<int, int>
#define pll           pair<ll, ll>
#define vi            vector<int>
#define vpi           vector<pii>

int dbg = 0;
#define cri           if(0)
#define shame         cri cerr<<(++dbg)<<"\n\n";

const int MAX = 2001;

int N;
vector<pll> a;
ll dp[MAX][MAX];
ll f(int l, int r) {
  if (l + r == N) return 0;
  if (dp[l][r] != -1) return dp[l][r];
  auto x = a[l + r];
  int li = l, ri = N - 1 - r;
  ll lv = -x.fi * abs(x.se - li);
  ll rv = -x.fi * abs(x.se - ri);
  dp[l][r] = max(lv + f(l + 1, r), rv + f(l, r + 1));
  return dp[l][r];
}

// aaaaaaaaaaaaaaaa
void solve() {
  scanf("%d", &N);

  int x;
  rep(i, 0, N) {
    scanf("%d", &x);
    a.eb(-x, i);
  }
  sort(all(a));

  rep(i, 0, N)
    fill(dp[i], dp[i] + N, -1);
  printf("%lld\n", f(0, 0));
}

int main() {
  // int _; scanf("%d", &_); while (_--)
  solve();
	return 0;
}


Measured memory_bytes: 35236
#include <iostream>
#include <algorithm>
#include <math.h>
#include <vector>
#include <string>
#include <queue>
#include <map>
#include <utility>
using namespace std;
using ll = long long;
 
int main() {
	int a,b,c;
	cin >> a >> b >> c;
	int ans = b/a;
	if (ans > c) ans = c;
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
N, K = list(map(int, input().split()))
TD = [tuple(map(int, input().split())) for _ in range(N)]
TD.sort(key = lambda x: x[1], reverse=True)

max_kiso = sum([d for t,d in TD[:K]])
classes = set([t for t,d in TD[:K]])
n_classes = len(classes)

from itertools import groupby, accumulate
to_remove = []
for k,g in groupby(sorted(TD[:K]), key = lambda x:x[0]):
    #k: t
    to_remove.extend(list(g)[:-1]) #最大のもの以外
d_to_remove = sorted([d for t,d in to_remove])
d_to_remove_cumsum = list(accumulate(d_to_remove))

assert n_classes + len(to_remove) == K

to_add = []
for k,g in groupby(sorted(TD[K:]), key = lambda x:x[0]):
    if k not in classes:
        to_add.append(list(g)[-1]) #最大のもの
d_to_add = sorted([d for t,d in to_add], reverse= True)
d_to_add_cumsum = list(accumulate(d_to_add))

answer = max_kiso + n_classes **2
for i in range(0, min(len(to_remove), len(to_add))):
    a = max_kiso + d_to_add_cumsum[i] - d_to_remove_cumsum[i] + (n_classes + i+1)**2
    answer = max(a,answer)

print(answer)

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

// @@ !! LIM()

int main(int argc, char *argv[]) {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout << setprecision(20);

  string S; cin >> S;
  ll n = S.size();
  for (ll k = n-2; k >= 2; k-= 2) {
    ll m = k / 2;
    bool success = true;
    for (ll i = 0; i < m; i++) {
      if (S.at(i) != S.at(m + i)) {
	success = false;
	break;
      }
    }
    if (success) {
      cout << k << endl;
      return 0;
    }
  }

  return 0;
}



Measured memory_bytes: 256