akhauriyash/Code-Regression huggingface dataset:
import std.algorithm;
import std.array;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

T read(T)() { return readln.chomp.to!T; }
T[] reads(T)() { return readln.split.to!(T[]); }
alias readint = read!int;
alias readints = reads!int;

void main() {
    auto nmq = readints;
    int n = nmq[0], m = nmq[1], Q = nmq[2];

    auto g = new int[][](n + 1, n + 1);
    for (int i = 0; i < m; i++) {
        auto lr = readints;
        g[lr[0]][lr[1]]++;
    }

    for (int r = n; r > 0; r--) {
        for (int c = 1; c <= n; c++) {
            g[r][c] += g[r][c - 1];
        }
        if (r < n) {
            for (int c = 1; c <= n; c++) {
                g[r][c] += g[r + 1][c];
            }
        }
    }

    for (int i = 0; i < Q; i++) {
        auto pq = readints;
        int p = pq[0], q = pq[1];

        writeln(g[p][q]);
    }
}


Measured memory_bytes: 9340
X, N = map(int, input().split())
P = list(map(int, input().split()))
 
ans = X
for i in range(N+1):
    a = X + i
    b = X - i
    if a not in P:
        ans = a
        if b not in P:
            ans = b
        break
    if b not in P:
        ans = b
        break
print(ans)

Measured memory_bytes: 9136
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define ll long long
#define endl '\n'
using namespace std;
int dy[4] = {1, 0, -1, 0}, dx[4] = {0, 1, 0, -1};
typedef pair<ll, ll> P;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a, b, t;
    cin >> a >> b >> t;
    cout << t / a * b << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const static ll INF = 1e9;
const static ll MOD = 1e9+7;
 
int main(){
    int N, K; cin >> N >> K;
    vector<int> A(N); for(int i = 0; i < N; i++) cin >> A[i];
    ll ans = 0;
    ll cnt = 0;
    for(int i = 0; i < N; i++){
        ans++;
        if(i == 0) cnt+=K;
        else cnt+= K-1;
        if(cnt >= N) break;
    }
    cout << ans << endl;
}

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

using namespace std;

int main(void) {
	int num, i, len, ans = 0;
	cin >> num;
	vector<int> d(num);
	for (i = 0; i < num; i++)
		scanf("%d", &d[i]);
	for (i = 0; i < num - 1; i++) {
		len = 1;
		while (i < num - 1 && d[i] == d[i + 1]) {
			len++;
			i++;
		}
		ans += len >> 1;
	}
	cout << ans << "\n";
	return 0;
}

Measured memory_bytes: 256
R,G,B=map(int,input().split())
K=int(input())
for _ in range (K) :
    if R < G :
        pass
    else:
        G*=2
        continue

    if G < B :
        pass
    else:
        B*=2
        continue
    
if R < G < B :
    print('Yes')
else :
    print('No')


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

int main() {
  long a,b,q,sm,sp,tm,tp;
  cin >> a >> b >> q;
  vector<long> s(a);
  vector<long> t(b);
  vector<long> x(q);
  vector<long> ans(q);
  set<long> ss,ts;
  for(long i=0;i<a;i++) cin >> s[i];
  for(long i=0;i<b;i++) cin >> t[i];
  for(long i=0;i<q;i++) cin >> x[i];

  for(long i=0;i<a;i++) ss.insert(s[i]);
  for(long i=0;i<b;i++) ts.insert(t[i]);
  for(long i=0;i<q;i++) {
    sm=99999999999999,sp=99999999999999,tm=99999999999999,tp=99999999999999;
    auto itr1=ss.lower_bound(x[i]);
    auto itr2=ts.lower_bound(x[i]);
    if(itr1!=ss.end()) sp=*itr1;
    if(itr1!=ss.begin()) {
      itr1--;
      sm=*itr1;
    }
    if(itr2!=ts.end()) tp=*itr2;
    if(itr2!=ts.begin()) {
      itr2--;
      tm=*itr2;
    }
    sm-=x[i],sp-=x[i],tm-=x[i],tp-=x[i];
    sm=labs(sm),sp=labs(sp),tm=labs(tm),tp=labs(tp);
    ans[i]=max(sm,tm);
    ans[i]=min(ans[i],max(sp,tp));
    ans[i]=min(ans[i],sm*2+tp);
    ans[i]=min(ans[i],sp*2+tm);
    ans[i]=min(ans[i],sm+tp*2);
    ans[i]=min(ans[i],sp+tm*2);
    cout << ans[i] << endl;
  }
}

Measured memory_bytes: 13824
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define PI 3.14159265358979323846
#define MOD 1000000007
#define INF (int)1e9

using namespace std;
using namespace __gnu_pbds;
//typedef tree<TYPE, null_type, less<TYPE>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
//typedef tree<TYPE, null_type, less_equal<TYPE>, rb_tree_tag, tree_order_statistics_node_update> indexed_multiset;

int N, K, A[100000];

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cin >> N >> K;
	for(int i = 0; i < N; i++) cin >> A[i];
	int dp[100000];
	for(int i = N - 1; i >= 0; i--){
		if(i == N - 1) dp[i] = 0;
		else{
			int mn = INT_MAX;
			for(int j = i + 1; j < i + K + 1 && j < N; j++) mn = min(mn, abs(A[i] - A[j]) + dp[j]);
			dp[i] = mn;
		}
	}
	cout << dp[0] << "\n";
	return 0;
}


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

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

    vector<vector< long long > > va(l, vector<long long>(m));
    vector<vector< long long > > vb(m, vector<long long>(n));

    for(int i = 0; i < l; i++){
        for(int j = 0; j < m; j++){
            cin >> va[i][j];
        }
    }
    for(int i = 0; i < m; i++){
        for(int j = 0; j < n; j++){
            cin >> vb[i][j];
        }
    }

    
    for(int i = 0; i < l; i++){
        for(int j = 0; j < n; j++){
            long long sum = 0;
            for(int k = 0; k < m; k++){
                sum += va[i][k] * vb[k][j];
            }
            if(j != n - 1){
                cout << sum << " ";
            }
            else{
                cout << sum << endl;
            }
        }
    }
}


Measured memory_bytes: 3192
fn main(){
  loop {
    let s1: String = read();
    let v1: Vec<char> = s1.chars().collect();
    let v1l = v1.len();

    if v1l == 0 { break; }
    
    let s2: String = read();
    let v2: Vec<char> = s2.chars().collect();
    let v2l = v2.len();

    let mut dp: Vec<Vec<u32>> = vec![vec![0;v2.len()]; v1.len()];

    
    for i in 0 .. v1l {
      if v1[i] == v2[0] {
        dp[i][0] = 1;
      }
    }
    
    for i in 0 .. v2l {
      if v1[0] == v2[i] {
        dp[0][i] = 1;
      }
    }

    for i in 1 .. v1l {
      for j in 1 .. v2l {
        if v1[i] == v2[j] {
          dp[i][j] = dp[i-1][j-1] + 1;
        }
      }
    }

    let ans: &u32 = dp.iter().map(|v| v.iter().max().unwrap()).max().unwrap();
    
    println!("{}", *ans);
  }
}

fn read<T>() -> T
  where T: std::str::FromStr,
        T::Err: std::fmt::Debug
{
  let mut buf = String::new();
  std::io::stdin().read_line(&mut buf).expect("failed to read");
  buf.trim().parse().unwrap()
}



Measured memory_bytes: 86948
import sys
readline = sys.stdin.readline
 
N, K = map(int, readline().split())
A = list(map(int, readline().split()))
 
l = 0
r = 10**10
 
def test(m):
  return sum((a + m - 1) // m for a in A) - N <= K

while l + 1 < r:
  m = (l + r) // 2
  if test(m):
  	r = m
  else:
    l = m
print(r)

Measured memory_bytes: 103892
import java.lang.Math

val MOD: Int = 1000000000 + 7
val MODL: Long = MOD.toLong()

fun main(args: Array<String>)
{
    val n = read().toInt()
    val s = read().toCharArray()

    var ans = 0
    for (i in 0 until n-2) {
        ans += if (s[i] == 'A' && s[i+1] == 'B' && s[i+2] == 'C') 1 else 0
    }

    println(ans)
}

fun read(): String = readLine()!!


Measured memory_bytes: 33616
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<vector>
#include<functional>
#include<algorithm>
#include<stdlib.h>
#include<string>
#include<string.h>
#define _USE_MATH_DEFINES
#include<math.h>
#include<deque>
#include<set>
#include<map>
#include<queue>
#include<list>
#include<iostream>
#include <bitset>
using namespace std;
typedef long long ll;
#define rep(i,a,b) for(auto i=a;i<b;i++)
#define rep2(i, a)for(auto i : a)
#define all(_x) _x.begin(), _x.end()
#define r_sort(_x) sort(_x, std::greater<int>())
#define vec_cnt(_a, _n) (upper_bound(all(_a), _n) - lower_bound(all(_a), _n))
#define vec_unique(_a) _a.erase(std::unique(all(_a)), _a.end());
#define vvec vector<vector<ll>>
ll gcd(ll a, ll b) { return a % b == 0 ? b : gcd(b, a % b); }
ll lcm(ll a, ll b) { return (a / gcd(a, b)) * b; }
#define INF 1 << 30
const int mod = 1000000007;
ll power(ll x, ll p) { ll a = 1; while (p > 0) { if (p % 2 == 0) { x *= x; p /= 2; } else { a *= x; p--; } }return a; }
ll mpower(ll x, ll p) { ll a = 1; while (p > 0) { if (p % 2 == 0) { x = x * x % mod; p /= 2; } else { a = a * x % mod; p--; } }return a; }
ll co(ll n, ll k) { ll a = 1; rep(i, 1ll, k) { a *= n - i + 1; a /= i; }return a; }
ll mc(ll n, ll m) { ll k = 1, l = 1; rep(i, n - m + 1, n + 1) k = k * i % mod; rep(i, 1, m + 1) l = l * i % mod; l = mpower(l, mod - 2); return k * l % mod; }

int main(void) {
	int n, c = 0;
	cin >> n;
	vector<int> x(n), y(n);
	rep(i, 0, n)cin >> x[i] >> y[i];
	vector<int> a(n);
	rep(i, 0, n)a[i] = i;
	double ans = 0;
	do {
		double sum = 0;
		rep(i, 0, n - 1)sum += pow(pow(x[a[i]] - x[a[i + 1]], 2) + pow(y[a[i]] - y[a[i + 1]], 2), 0.5);
		ans += sum;
		c++;

	} while (next_permutation(all(a)));
	printf("%.10f\n", ans / c);
	return 0;
}

Measured memory_bytes: 4060
#include<iostream>
#include<string>
#include<algorithm>
#include<cstdlib>
using namespace std;


int main() {
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    if (a*b > c*d)cout << a * b << endl;
    else cout << c * d << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
using namespace std;
char s[100005];
int ch[200005][2],cnt=1,n;
ll ans=0,len;
inline ll get(ll p)
{if (p==0) return 0;
ll g=1;
while (p%(g*2)==0) g*=2;
return g;
}
void dfs(int pos,int dep)
{if (!ch[pos][0]) {ans^=get(len-dep);}
else {dfs(ch[pos][0],dep+1);}
if (!ch[pos][1]) {ans^=get(len-dep);}
else {dfs(ch[pos][1],dep+1);}
}
int main (){
	int i;
	scanf ("%d%lld",&n,&len);
	for (i=1;i<=n;i++)
	{scanf ("%s",s+1);
	int len=strlen(s+1),j,pos=1;
	for (j=1;j<=len;j++)
	{int nxt=s[j]-'0';
	if (!ch[pos][nxt]) ch[pos][nxt]=++cnt;
	pos=ch[pos][nxt];
	}
	}
	dfs(1,0);
	puts(ans==0?"Bob":"Alice");
	return 0;
}
	

Measured memory_bytes: 3456
n = int(input())
a = [int(input()) for i in range(n)]
sum_len = sum(a)
max_len = -((-sum_len)//2)
MOD = 998244353

#dp[i番目まで選ぶ][Aの長さ]= 通り数(B,Cの選び方も考慮する)
dp = [[0]*(sum_len+1) for i in range(n+1)]
dp[0][0]= 1
for i in range(n):
    for len in range(sum_len+1):
        #a[i]を選ばないとき → a[i]はBかCに振り分けられるので*2をする
        dp[i+1][len] = dp[i][len]*2
        #a[i]を選ぶとき
        if 0 <= len-a[i]:
            dp[i+1][len] += dp[i][len-a[i]]
        dp[i+1][len] %= MOD

            
#dp[i番目まで選ぶ][Aの長さ]= 通り数(B,Cの選び方を考慮しない)
dp2 = [[0]*(sum_len+1) for i in range(n+1)]
dp2[0][0]= 1
for i in range(n):
    for len in range(sum_len+1):
        #a[i]を選ばないとき
        dp2[i+1][len] = dp2[i][len]
        #a[i]を選ぶとき
        if 0 <= len-a[i]:
            dp2[i+1][len] += dp2[i][len-a[i]]
        dp2[i+1][len] %= MOD

if sum_len % 2 == 0:
    ans = pow(3,n,MOD) - 3*sum(dp[n][max_len:]) + 3*dp2[n][max_len]
else:
    ans = pow(3,n,MOD) - 3*sum(dp[n][max_len:])
ans %= MOD
print(ans)

Measured memory_bytes: 457224
import sys

sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    n, k = map(int, input().split())
    A = list(map(int, input().split()))
    M, P = [], []
    for a in A:
        M.append(a) if a < 0 else P.append(a)

    m, p = len(M), len(P)
    ok = False
    if p > 0:
        ok = m % 2 == 0 if n == k else True
    else:
        ok = k % 2 == 0

    res = 1
    if not ok:
        A.sort(key=lambda x: abs(x))
        for i in range(k):
            res = (res * A[i]) % mod
    else:
        P.sort()
        M.sort(reverse=True)
        if k % 2:
            a = P.pop()
            res = (res * a) % mod
        M_2 = []
        while len(P) >= 2:
            a = P.pop()
            a *= P.pop()
            M_2.append(a)
        while len(M) >= 2:
            a = M.pop()
            a *= M.pop()
            M_2.append(a)
        M_2.sort(reverse=True)
        for i in range(k // 2):
            res = (res * M_2[i]) % mod
    print(res)


if __name__ == '__main__':
    resolve()


Measured memory_bytes: 31608
n,m=gets.split.map(&:to_i)
hash=Hash.new(0)

(2..(Math.sqrt(m).ceil)).each do |i|
    while m % i == 0
        m /= i
        hash[i] += 1
    end
    break if m == 1
end

if m != 1
    hash[m] += 1
end

ans = 1
hash.each do |k,v|
    ans = ans * k ** (v/n) if v >= n
end

p ans


Measured memory_bytes: 1916
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;

public class Main {
  public static void main(String[] args) throws IOException {
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    int n = Integer.parseInt(in.readLine());
    String[] str = in.readLine().split(" ");
    int[] a = new int[n];
    int odd = 0;
    int even = 0;
    for(int i=0; i<n; i++) {
      a[i] = Integer.parseInt(str[i]);
      if(a[i]%2==0)
        even++;
      if(a[i]%2!=0)
        odd++;
    }
    
    System.out.println(odd%2!=0?"NO":"YES");
  }
}

Measured memory_bytes: 46436
N = int(input())
ml = list(map(int,input().split()))
hl = list(map(int,input().split()))
ans = 0

for i,h in enumerate(hl):
    if(ml[i]<h):
        ans += ml[i]
        h -= ml[i]
        ml[i] = 0
        if(ml[i+1]<h):
            ans += ml[i+1]
            h -= ml[i+1]
            ml[i+1] = 0
        else:
            ans += h
            ml[i+1] -= h
            h = 0
    else:
        ans += h
        ml[i] -= h
        h = 0

print(ans)


Measured memory_bytes: 18380
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
int main()
{
    ll n,coun=0;
    cin>>n;
    ll sum=n+100;
    for(ll i=2;i*i<=n;i++)
    {
        if(n%i==0)
        {
            coun++;
            ll x= n/i;
            if(i+x<sum)sum=(i+x);

        }
    }
    if(coun==0)
        cout<<n-1<<endl;
    else{
       cout<<sum-2<<endl;
    }
}


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

using namespace std;

int main() {
	int n;
	cin>>n;
	vector<int> arr(n, 0);
	for(int& x: arr)
		cin>>x;
	int m = arr[0], cnt = 1;
	for(int i = 1; i < n; i++ ) {
		if(arr[i] < m) {
			cnt++;
			m = arr[i];
		}
	}
	if(n == 0) 
		cout<<0<<endl;
	else
		cout<<cnt<<endl;
	return 0;
}


Measured memory_bytes: 1024
#include <stdio.h>
#include <string.h>

int main(void) {
	char buffer[2][256], *src, *dest, *tmp;
	int m, i, h, l;
	while (scanf("%255s", buffer[0]) == 1 && strcmp(buffer[0], "-") != 0) {
		src = buffer[0];
		dest = buffer[1];
		l = strlen(src);
		dest[l] = '\0';
		if (scanf("%d", &m) != 1) return 1;
		for (i = 0; i < m; i++) {
			if (scanf("%d", &h) != 1) return 1;
			memcpy(dest + l - h, src, h);
			memcpy(dest, src + h, l - h);
			tmp = src;
			src = dest;
			dest = tmp;
		}
		puts(src);
	}
	return 0;
}




Measured memory_bytes: 2100
program main
    use,intrinsic :: iso_fortran_env
    implicit none
    integer(int64):: n,k,i,j,l,r,jj
    integer(int64), allocatable:: a(:), na(:),ims(:)
    logical:: same

    read*, n,k
    allocate(a(n), na(0:n),ims(n))
    read*, a(:)
    ! a(:) = 0
    ! a(1) = 1

    if (k >= 50) then
        a(:) = n
        print'(*(i0,1x))', a(:)
        stop
    end if

    do i=1,k
        na(:) = 0
        ims(:) = 0
        same = .true.
        do j=1,n

            l = max(j-a(j),1_8)
            r = (j+a(j)+1)
            ! print'(*(i0,1x))', j,l,r
            ims(l)=ims(l)+1
            if (r <= n) ims(r)=ims(r)-1
        end do
        ! print'(*(i0,1x))', ims(:)
        do j=1,n
            na(j) = na(j-1)+ims(j)
        end do

        do j=1,n
            if (na(j) /= a(j)) same = .false.
        end do
        if (same) exit
        a(:) = na(1:)
    end do
    ! print'(i0)', i
    print'(*(i0,1x))', na(1:)
end program main

Measured memory_bytes: 9204
using System;
class latte
{
    static void Main()
    {
        string[] s = Console.ReadLine().Split();
        int[] V = new int[5];
        for (int i = 0; i < 5; i++)
            V[i] = int.Parse(s[i]);

        Array.Sort(V);
        Array.Reverse(V);
        string ans = "";
        for (int i = 0; i < 5; i++)
        {
            if (i != 0) ans += " ";
            ans += V[i];
        }
        Console.WriteLine(ans);
    }
}

Measured memory_bytes: 5756
#coding:utf-8                                                                   

inp = list(raw_input())

a = int(inp[0])
b = int(inp[1])
c = int(inp[2])
d = int(inp[3])

if a + b + c + d == 7:
    print str(a) + "+" + str(b) + "+" + str(c) + "+" + str(d) + "=7"
elif a - b + c + d == 7:
    print str(a) + "-" + str(b) + "+" + str(c) + "+" + str(d) + "=7"
elif a + b - c + d == 7:
    print str(a) + "+" + str(b) + "-" + str(c) + "+" + str(d) + "=7"
elif a + b + c - d == 7:
    print str(a) + "+" + str(b) + "+" + str(c) + "-" + str(d) + "=7"
elif a - b - c + d == 7:
    print str(a) + "-" + str(b) + "-" + str(c) + "+" + str(d) + "=7"
elif a - b + c - d == 7:
    print str(a) + "-" + str(b) + "+" + str(c) + "-" + str(d) + "=7"
elif a + b - c - d == 7:
    print str(a) + "+" + str(b) + "-" + str(c) + "-" + str(d) + "=7"
elif a - b - c - d == 7:
    print str(a) + "-" + str(b) + "-" + str(c) + "-" + str(d) + "=7"

Measured memory_bytes: 2696
from sys import setrecursionlimit
setrecursionlimit(10 ** 9)

n, m = [int(i) for i in input().split()]
A = [[int(i) for i in input().split()] for j in range(n+m-1)]

T = [[] for i in range(n+1)]
RT = [[] for i in range(n+1)]

for a, b in A:
    T[a].append(b)
    RT[b].append(a)

P = [0] * (n+1)
D = [0] * (n+1)

def dfs(i):
    if D[i] > 0:
        return D[i] + 1
    for t in RT[i]:
        d = dfs(t)
        if d > D[i]:
            D[i] = d
            P[i] = t

    return D[i] + 1

def root(i):
    if not RT[i]:
        return i
    return root(RT[i][0])

D[root(1)] = 1

for i, t in enumerate(T):
    if not t:
        dfs(i)

for p in P[1:]:
    print(p)

Measured memory_bytes: 134764
#include<bits/stdc++.h>
#define INF 0x3f3f3f3f
#define MOD 1000000007
typedef long long ll;
typedef std::pair<int,int> ii;
using namespace std;
ll l[90];

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

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

using vi = vector<int>;
using vvi = vector<vector<int>>;
using vvvi = vector<vector<vector<int>>>;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using vvvll = vector<vector<vector<ll>>>;
using vd = vector<double>;
using vvd = vector<vector<double>>;
using vvvd = vector<vector<vector<double>>>;
using vb = vector<bool>;
using vvb = vector<vector<bool>>;
using vs = vector<string>;
using pint = pair<int, int>;
using Graph = vvi;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()

string s = "MARCH";
ll c[5];

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

    rep(i, n) {
        string t;
        cin >> t;
        rep(j, 5) {
            if(t[0] == s[j]) c[j]++;
        }
    }

    ll ans = 0;
    for(int i = 0; i < 5; i++) {
        for(int j = i + 1; j < 5; j++) {
            for(int k = j + 1; k < 5; k++) {
                ans += (c[i] * c[j] * c[k]);
            }
        }
    }
    
    cout << ans << endl;

    return 0;
}


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

int main(){
    int A,B,i;
    int a,b,c,d;
    int count=0;

    cin >> A >> B;

    for(i=A;i<=B;i++){
        d=i%10;
        c=(i/10)%10;
        b=(i/1000)%10;
        a=(i/10000)%10;

        if(a==d){
            if(b==c){
                count++;
            }
        }
    }

    cout << count << endl;
}


Measured memory_bytes: 256
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <fstream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <limits>

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }

//math
//-------------------------------------------
template<class T> inline T sqr(T x) { return x * x; }

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define EXISTch(s,c) ((((s).find_first_of(c)) != std::string::npos)? 1 : 0)//cがあれば1 if(1)
#define SORT(c) sort((c).begin(),(c).end())

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int INF = (int)1000000007;
const LL MOD = (LL)1000000007;//10^9+7
const LL INF2 = (LL)100000000000000000;//10^18

struct P {
	LL f, s;
};

bool comp(P p1, P p2) {
	return p1.f > p2.f;
}

void dump(const vector<P> a) {
	int n = a.size();
	for (int i = 0; i < n; i++) {
		cout << a[i].f << " " << a[i].s << endl;
	}
}

/*
vector<P> a(n);
for (int i = 0; i < n; i++) {
		cin >> a[i].f>>a[i].s;
	}

	sort(a.begin(), a.end(),comp);

*/

int main() {
	LL n, m; cin >> n >> m;
	vector<LL> a(n);

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

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

	vector<LL> imos(n+10);

	for (int i = n-1; i >=0; i--) {
		imos[i] = imos[i + 1] + a[i];
	}



	vector<P> b(m+10);
	for (int i = 0; i < m; i++) {
		cin >> b[i].s >> b[i].f;
	}

	sort(b.begin(), b.end(), comp);


	LL ans = imos[0];
	LL sum = 0;
	LL p = 0;
	LL sumafter =0;
	for (int i = 1; i < n+1; i++) {

		sum += a[i - 1];

		if (b[p].s == 0) {
			p++;
		}

		if (p >= m+1)break;

		if (b[p].s > 0) {
			sumafter += b[p].f;
			b[p].s--;
		}

		LL d = max(sumafter, sum);
		LL tmp = d + imos[i];

		ans = max(ans, tmp);

	}

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

Measured memory_bytes: 3328
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};
using pii = pair<int, int>;
const ll mod = 1e9 + 7;
int main() {
  int n;
  cin >> n;
  vector<ll> a(n);
  ll sum = 0;

  for (int i = 0; i < n; i++) {
    cin >> a[i];
    sum += a[i];
    sum %= mod;
  }

  ll ans = 0;

  for (int i = 0; i < n; i++) {
    sum -= a[i];
    sum = (sum + mod) % mod;
    ans += (a[i] * sum) % mod;
    ans %= mod;
  }

  cout << ans << endl;
}

Measured memory_bytes: 4840
#include "iostream"
#include "fstream"
#include "algorithm"
#include "iomanip"
#include "stack"
#include "queue"
#include "string"
#include "vector"
#include "map"
#include "set"
#include "unordered_set"
#include "unordered_map"
#include "iterator"
#include <ctime>
#include "bitset"
#include "cmath"
#include "list"
#include "complex"
#include <cassert>
#include "deque"
#include "numeric"
#include <cstdio>
 
using namespace std;
 
//#define f(i,n) for(int i=0; i<n;i++) 
//#define rf(i, n) for(int i=n-1;i>=0;i--)
//#define forn(i, j, n) for(int i=j; i<n; i++)
//#define ff(i, j, n) f(i, n)f(j, n)
#define pb push_back
//#define mp make_pair
#define maxi(a,b) a = max(a, b);
#define mini(a,b) a = min(a, b);
#define endl '\n'
#define all(a) a.begin(), a.end()
#define sqr(x) ((x) * (x))
#define SZ(a) ((int)(a.size()))
#define watch(x) cout << (#x) << " = " << x << endl;
//typedef long long ll;
typedef long double ld;
#define int long long
#define double ld
typedef map<int, int> mii;
typedef pair<int, int> pii;
typedef pair<string, int> psi;
typedef pair<int, string> pis;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<pii> vpii;
typedef vector<char> vc;
 
template<class T>
void show(const vector<T> &a)
{
	for (T x : a)
		cout << x << " ";
	cout << endl;
}
 
const int sze = 3e5 + 50, oo = 1e18 + 500, mod = 1e9 + 7;
const double eps = 1e-9, PI = 2 * acos(0.0);
vi vertices[sze];
vc visit(sze, false);
vc used(sze, false);
vi arr(sze, 0);
int n, m, k;
int A, B;
int cnt = 0;
 
int dp[3050][3050];
 
signed main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
 
	string s, t;
	cin >> s >> t;
 
	for (int i = 0; i < s.size(); i++)
	{
		for (int j = 0; j < t.size(); j++)
		{
			if (s[i] == t[j])
			{
				maxi(dp[i + 1][j + 1], dp[i][j] + 1);
			}
          else
          {
            
			maxi(dp[i + 1][j + 1], dp[i][j + 1]);
			maxi(dp[i + 1][j + 1], dp[i + 1][j]);
          }
		}
	}
 
	cnt = dp[s.size()][t.size()];
	n = s.size();
	m = t.size();
 
	string ans = "";
	while (n > 0 && m > 0)
	{
		if (dp[n][m] == dp[n - 1][m - 1] + 1 && s[n-1] == t[m-1])
		{
			ans += s[n - 1];
			n--;
			m--;
			cnt--;
		}
		else
		{
			if (dp[n][m] == dp[n - 1][m])
			{
				n--;
			}
			else
			{
				m--;
			}
		}
	}
 
	reverse(all(ans));
	cout << ans;
	return 0;
}

Measured memory_bytes: 81792
package main

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

var INF int32 = math.MaxInt32
var INF64 int64 = math.MaxInt64

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func max(a, b int) int {
	if a < b {
		return b
	}
	return a
}

func min64(a, b int64) int64 {
	if a < b {
		return a
	}
	return b
}

func max64(a, b int64) int64 {
	if a < b {
		return b
	}
	return a
}

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

func readLineNums(bf *bufio.Reader) []int {
	line, _ := bf.ReadString('\n')
	line = strings.Trim(line, "\n")
	fields := strings.Split(line, " ")
	nums := []int{}
	for _, field := range fields {
		num, _ := strconv.Atoi(field)
		nums = append(nums, num)
	}
	return nums
}

func readLineNum64s(bf *bufio.Reader) []int64 {
	line, _ := bf.ReadString('\n')
	line = strings.Trim(line, "\n")
	fields := strings.Split(line, " ")
	nums := []int64{}
	for _, field := range fields {
		num, _ := strconv.ParseInt(field, 10, 64)
		nums = append(nums, num)
	}
	return nums
}

func readLineFloats(bf *bufio.Reader) []float64 {
	line, _ := bf.ReadString('\n')
	line = strings.Trim(line, "\n")
	fields := strings.Split(line, " ")
	nums := []float64{}
	for _, field := range fields {
		num, _ := strconv.ParseFloat(field, 64)
		nums = append(nums, num)
	}
	return nums
}

func readLineStrs(bf *bufio.Reader) []string {
	line, _ := bf.ReadString('\n')
	line = strings.Trim(line, "\n")
	return strings.Split(line, " ")
}

func main() {
	bf := bufio.NewReader(os.Stdin)
	nk := readLineNums(bf)
	N, K := nk[0], nk[1]
	ans := 0
	for N > 0 {
		ans++
		N /= K
	}
	fmt.Println(ans)
}


Measured memory_bytes: 640
#!/usr/bin/env python
# -*- coding: utf-8 -*-

S = input()

i = 1
good = True
for s in S:
    if i % 2 == 0:
        if s == 'R':
            good = False
            break
    elif i % 2 ==1:
        if s == 'L':
            good = False
            break
    i += 1
if good:
    print('Yes')
else:
    print('No')


Measured memory_bytes: 38384
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define ALL(x) (x).begin(),(x).end()
#define LL long long

using namespace std;

int main(){
    int N,T;
    cin>>N>>T;
    int A[N];
    REP(i,N)cin>>A[i];

    int min_=A[0];
    int max_ben=1;
    int cnt=0;
    REP(i,N-1){
        if(A[i+1]-min_>max_ben){
            max_ben=A[i+1]-min_;
            cnt=1;
        }else if(A[i+1]-min_==max_ben){cnt++;}
        min_=min(min_,A[i+1]);
    }

    cout<< cnt <<endl;

    return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
int a,b;
int main()
{
//    freopen("garden.in","r",stdin);
//    freopen("garden.out","w",stdout);
    
    scanf("%d%d",&a,&b);
    printf("%d\n",(a-1)*(b-1));
    return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
const ld eps = 1e-9;

//// < "d:\d_download\visual studio 2015\projects\programing_contest_c++\debug\a.txt" > "d:\d_download\visual studio 2015\projects\programing_contest_c++\debug\b.txt"


int main() {
	while (1) {
		int N, T; cin >> N >> T;
		if (!N)break;
		int num = 0;
		vector<int>v;
		vector<vector<int>>guards(N);
		while (num < N) {
			int a; cin >> a;
			if (a != 0) {
				guards[num].push_back(a);
			}
			else {
				num++;
			}
		}
		vector<pair<int, int>>status(N,make_pair(0,0));
		deque<int>que;
		int ans = 0;
		for (int t = 0; t < T; ++t) {
			int nbat = -1;
			if (!que.empty()) {
				ans += que.size() - 1;
				nbat = que.front();
			}
			for (int i = 0; i < N; ++i) {
				
				bool nowbat = status[i].first % 2;
				if (nowbat) {
					if (i ==nbat) {
						status[i].second++;
						if (status[i].second == guards[i][status[i].first]) {
							status[i].second = 0;
							status[i].first = (status[i].first + 1) % guards[i].size();
							que.pop_front();
						}
					}
				}
				else {
					status[i].second++;
					if (status[i].second == guards[i][status[i].first]) {
						status[i].second = 0;
						status[i].first = (status[i].first+1) % guards[i].size();
						que.push_back(i);
					}
				}
			}
		}
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 3184
#include<iostream>

using namespace std;
int Weeks;
int Debt = 100000;
int Interest;

int Rounded (int x)
{
    int Remain,y;
    if(x%1000!=0)
    {
        Remain = x%1000;
        y = x-Remain;
        y = y+1000;
        return y;
    }
    else
    {
        return x;
    }

}
int main()
{
    cin >> Weeks;
    for(int z = 0; z < Weeks; z++)
    {
        Interest = Debt * 1.05;
        Interest = Rounded(Interest);
        Debt = Interest;


    }


    cout << Interest << endl;
}

Measured memory_bytes: 1160
#include <cstdio>
main(){while(1){int h[5]={0},t[4]={0},w=0;for(;w<5;w++){scanf("%d",h+w);t[h[w]]++;if(!*h)return 0;}w=t[1]&&t[2]&&t[3]?-1:t[1]&&t[2]?1:t[2]&&t[3]?2:t[1]&&t[3]?3:-1;while((*t)++<5)puts(w<0?"3":h[*t-1]-w?"2":"1");}}

Measured memory_bytes: 0
import math 
N, D = map(int, input().split())

xy_list = [map(int, input().split()) for i in range(N)]

count = 0

for x, y in xy_list:
  dist = x ** 2 + y ** 2
  
  if dist <= D ** 2:
    count += 1
    
print(count)

Measured memory_bytes: 129316
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>

using namespace std;

int main(){
	int N[4];
	char abcd[5];
	scanf("%s",abcd);
	for(int i=0;i<4;i++){
		N[i] = abcd[i] - '0';
	}

	if(N[0]+N[1]+N[2]+N[3]==7) printf("%d+%d+%d+%d=7\n",N[0],N[1],N[2],N[3]);
	else if(N[0]+N[1]+N[2]-N[3]==7) printf("%d+%d+%d-%d=7\n",N[0],N[1],N[2],N[3]);
	else if(N[0]+N[1]-N[2]+N[3]==7) printf("%d+%d-%d+%d=7\n",N[0],N[1],N[2],N[3]);
	else if(N[0]+N[1]-N[2]-N[3]==7) printf("%d+%d-%d-%d=7\n",N[0],N[1],N[2],N[3]);
	else if(N[0]-N[1]+N[2]+N[3]==7) printf("%d-%d+%d+%d=7\n",N[0],N[1],N[2],N[3]);
	else if(N[0]-N[1]+N[2]-N[3]==7) printf("%d-%d+%d-%d=7\n",N[0],N[1],N[2],N[3]);
	else if(N[0]-N[1]-N[2]+N[3]==7) printf("%d-%d-%d+%d=7\n",N[0],N[1],N[2],N[3]);
	else if(N[0]-N[1]-N[2]-N[3]==7) printf("%d-%d-%d-%d=7\n",N[0],N[1],N[2],N[3]);


	return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <numeric>//accumulate(v.begin(), v.end(), 0);
#include <algorithm>//sort(v.begin(),v.end());
#include <string>//
using namespace std;
#define ll long long
#define rep(i, n) for(int i = 0; i < (int)(n); i++)

ll C[51][51];

void comb_table(int N){
        for(int i=0; i<=N; ++i) {
                for(int j=0; j<=i; ++j) {
                        if(j==0 or j==i) {
                                C[i][j]=1LL;
                        }else{
                                C[i][j]=(C[i-1][j-1]+C[i-1][j]);
                        }
                }
        }
}

int main(){
        int A,B,N;
        cin >> N >> A >> B;
        vector <ll> v(N,0);
        rep(i,N){
                cin >> v[i];
        }

        sort(v.begin(),v.end());
        reverse(v.begin(),v.end());

        comb_table(N);
        double max=0.0;
        rep(i,A){
                max+=v[i];
        }
        max/=A;
        int res=0,num=0;
        rep(i,N){
                if(v[i]==v[A-1]) {
                        res++;
                        if(i<A) {
                                num++;
                        }
                }
        }
        ll ans=0LL;
        if(num==A) {
                for(num=A; num<=B; num++) {
                        ans+=C[res][num];
                }
        }else{
                ans+=C[res][num];
        }
        cout.precision(10);
        cout << fixed << max << endl;
        cout << ans << endl;

        return 0;
}


Measured memory_bytes: 256
s = list(input())
n = len(s)

s = [int(n) for n in s]
s1 = [0, 1] * int(n/2)
s2 = [1, 0] * int(n/2)

if(n%2 == 1):
    s1.append(0)
    s2.append(1)

c1, c2 = 0, 0

for i in range(n):
    if(s[i] != s1[i]):
        c1 += 1
    if(s[i] != s2[i]):
        c2 += 1

if(c1 <= c2):
    print(c1)
else:
    print(c2)


Measured memory_bytes: 6940
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
#define mx2 102
#define mx3 1003
#define mx4 10004
#define mx5 100005
#define mx6 1000006
#define mod 1000000007
#define PI 3.14159265
#define fo(i,n) for(int i=0 ; i<n ; i++)
#define Fo(i,k,n) for(int i=k ; i<n ; i++)
 
typedef long long int ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<pair<int,int>,int> piii;

int n , arr[mx5] , dp[mx5] , ans; 

int main() {
	ios::sync_with_stdio(false);
	//cin>>t;while(t--)
	{
		cin>>n;
		fo(i,n) cin>>arr[i];
		for(int i=n-1 ; i>0 ; i--)
		{
			if( arr[i-1]>=arr[i] )
			{
				dp[i-1]=1+dp[i];
			}
		}
		fo(i,n)ans=max(ans,dp[i]);
		cout<<ans;
	}
	return 0;
}


Measured memory_bytes: 1024
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        int x = sc.nextInt();
        List<Integer> l = new ArrayList<Integer>();

        for(int i = 0; i < n; i++){
            l.add(sc.nextInt());
        }

        int distance = 0;
        int cnt = 1;
        for(int i = 0; i < n; i++){
            distance += l.get(i);
            if(distance <= x) cnt++;
        }
        System.out.println(cnt);
        return;
    }
}


Measured memory_bytes: 23124
def main():
    import sys
    input = sys.stdin.readline

    N, M = map(int, input().split())
    cond = []
    for _ in range(M):
        cond.append(list(map(int, input().split())))

    if N == 1:
        if M == 0:
            print(0)
            exit()
        ans = set()
        for s, c in cond:
             ans.add(c)
        if len(ans) != 1:
            print(-1)
            exit()
        print(cond[0][1])
        exit()

    for i in range(10**(N-1), 10**N):
        i_ = str(i)
        ok = 1
        for s, c in cond:
            if int(i_[s-1]) != c:
                ok = 0
                break
        if ok:
            print(i)
            exit()
    print(-1)


if __name__ == '__main__':
    main()


Measured memory_bytes: 38384
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define Would
#define you
#define please

long long N, K, A[59], dp[59][5009][2], mod = 1000000007;

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

	int N, M, X, Y;
	cin >> N >> M >> X >> Y;
	int x[100], y[100];
	rep(i, N) cin >> x[i];
	rep(i, M) cin >> y[i];
	sort(x, x + N);
	sort(y, y + M);

	int kotae = 0;
	for (int i = -101; i < 102; i++) {
		if (x[N - 1] < i && i <= y[0] && i <= Y && X < i) kotae = 1;
	}

	if (kotae) co("No War");
	else co("War");

	Would you please return 0;

}

Measured memory_bytes: 256
fun main(args: Array<String>) {
    var (p,q,r) = readLine()!!.split(" ").map { it.toInt() }
    if (p > q){
        if (p > r)println(q + r)
        else println(p + q)
    }else{
        if (q > r) println(p + r)
        else println(p + q)
    }
}


Measured memory_bytes: 37984
N = int(input())

def dfs(n,i,s,ans):
    if n == N:
        ans.append(s)
        return
    
    for j in range(i+1):
        tmp = s + chr(j + 97)
        max_j = ord(max(tmp)) - 96
        dfs(n+1,max_j,tmp,ans) 
    

def main():
    ans = []
    dfs(1,1,'a',ans)
    ans.sort()
    for a in ans:
        print(a)


    


if __name__ == "__main__":
    main()

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

#define repu(i,a,b) for(int i=a;i<=b;i++)
#define rep(i,a)    for(int i=0;i<a;i++)

using namespace std;

int main() {
    long long y, z, x, k, d;
    cin>>x>>k>>d;
    x=abs(x);
    y=x/d;
    z=k-y;
    if(k<=y)
    {
        cout<<x-k*d<<endl;
        return 0;
    }
    assert(z>=0);
    if(z%2==0)
    {
        cout<<x-y*d<<endl;
    }
    else
    {
        cout<<abs(x-y*d-d)<<endl;
    }
}

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

int main(){

    int K, N;
    size_t i;
    cin >> N >> K;
    vector<int>h(N);
    int ANS = 1000000000;
    for (i = 0; i < N; i++)cin >> h.at(i);
    sort(h.begin(), h.end());
  
    for (i = 0; i < N - K + 1; i++){
      ANS = min(ANS, h.at(i+K-1)-h.at(i));
    }
    cout << ANS << endl;

}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
#define all(x) x.begin(),x.end()
#define rep(i,j,n) for (int i = j; i < (int)(n); i++)
#define _GLIBCXX_DEBUG
#define MOD 1000000007
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; }
//name[i][j]-> vvl name(i,vl(j))
//map<int,int>mp
//余りを切り上げる =>  (a + b - 1) / b 

signed main(){
	ll n; cin>>n;
	ll a=n/500;
	ll b=n%500;
	ll c=b/5;
	cout<<(a*1000)+(c*5);
	
	return 0;
}

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

int main() {
  int a,b,c;
  cin >> a>>b>>c;
  if(a<=c&&b<=c){
    cout<<a+b<<endl;
  }
  else if(a<=b&&c<=b){
    cout<<a+c<<endl;
  }
  else{
    cout<<b+c<<endl;
  }
}


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

#define M 1000000007
#define MM 998244353 
#define ll long long 
#define pb push_back
#define mem0(a) memset(a,0,sizeof(a))
#define mem1(a) memset(a,-1,sizeof(a))
#define memf(a) memset(a,false,sizeof(a))
#define all(v) v.begin(),v.end()
#define sz(a) (ll)a.size()
#define F first
#define S second
#define PI 3.1415926536
#define INF 2e18
#define endl "\n"
#define llevel 20
ll power(ll b,ll e,ll m)
{
	if(e==0) return 1;
	if(e&1) return b*power(b*b%m,e/2,m)%m;
	return power(b*b%m,e/2,m);
}
ll power( ll b, ll e)
{
	if(e==0) return 1;
	if(e&1) return b*power(b*b,e/2);
	return power(b*b,e/2);
}

int _runtimeTerror_()
{
	string s;
	cin>>s;
	int n=s.length();
	if(s.length()%2!=1)
	{
		cout<<"No";return 0;
	}
	for(int i=0;i<n/2;++i)
	{
		if(s[i]!=s[n-1-i])
		{
			cout<<"No";return 0;
		}
	}
	s=s.substr(0,(n-1)/2);
	n=s.length();
	for(int i=0;i<n/2;++i)
	{
		if(s[i]!=s[n-1-i])
		{
			cout<<"No";return 0;
		}
	}
	cout<<"Yes";
	return 0;
}

int main()
{
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	#ifdef runSieve
		sieve();
	#endif
	#ifdef NCR
		initialize();
	#endif
	int TESTS=1;
	//cin>>TESTS;
	while(TESTS--)
		_runtimeTerror_();
	return 0;
}


Measured memory_bytes: 256
/*
　　こんにちは。あたしはｶｳｶﾞｰﾙ。
　　RedcoderになるためAtCoderを巡る旅をしてます。

　　　 　＿_
　　　 ヽ|＿_|ノ　　　　ﾓｫ
　　　　||‘‐‘||ﾚ　　_)_, ―‐ 、
　　　　/(Ｙ (ヽ＿ /・ ヽ　　   ￣ヽ
　　　　∠ ＿ ゝ　 ｀^ヽ ﾉ.::::_(ノヽ
　　　　 _/ヽ　 　　  /ヽ￣￣￣/ヽ
*/

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define dump(x) cout << #x << " = " << (x) << endl
#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 rep(i, n) REP(i, 0, n)                  // 0, 1, ..., n-1
#define REP(i, x, n) for(int i = x; i < n; i++) // x, x + 1, ..., n-1
#define FOREACH(x, a) for(auto &(x) : (a))

#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()

#define COUT(x) cout << (x) << endl

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

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

    char c; cin >> c;
    c++;
    COUT((char)c);
}


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

#define int long long

signed main()
{
  ll n;
  cin >> n;
  
  ll res = 0;
  res += (n/11)*2;
  n %= 11;
  
  if(n == 0){}
  else if(n <= 6) res += 1;
  else res += 2;
  
  cout << res << endl;
  
  //return 0;
}


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

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        while (sc.hasNextInt()) {
            int[] a = {sc.nextInt(), sc.nextInt(), sc.nextInt()};
            Arrays.sort(a);
            System.out.println(a[0] + a[1]);
        }
    }
}


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

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
#define CLR(t,v) memset(t,(v),sizeof(t))
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
template<class T>void chmin(T&a,const T&b){if(a>b)a=b;}
template<class T>void chmax(T&a,const T&b){if(a<b)a=b;}

const ll MOD = (ll)(1e9 + 7);

const int SZ = 1123456;
ll inv[SZ];
ll fact[SZ];
ll fact_inv[SZ];
ll choose(int n, int r) {
  if (n < 0 || r < 0 || n < r) return 0;
  return fact[n] * fact_inv[n-r] % MOD * fact_inv[r] % MOD;
}

ll f(ll N, ll k) {
  ll a = 2 * k - N;
  ll b = N - k - 1;
  return fact[N-k-1] * fact[k] % MOD * choose(a+b, b) % MOD;
}

int main2() {
  ll N; cin >> N;
  ll ans = 0;
  for (ll k = N/2; k <= N - 1; k++) {
    ll c1 = f(N, k-1);
    ll c2 = f(N, k);
    ll c = (c2 - c1) % MOD;
    ans += c * k;
    ans = (ans % MOD + MOD) % MOD;
  }
  cout << ans << endl;
  return 0;
}

int main() {

  inv[1] = 1;
  for (int i = 2; i < SZ; i++) inv[i] = inv[(int) (MOD % i)] * (MOD - MOD / i) % MOD;
  fact[0] = 1;
  for (int i = 1; i < SZ; i++) fact[i] = fact[i-1] * i % MOD;
  fact_inv[0] = 1;
  for (int i = 1; i < SZ; i++) fact_inv[i] = fact_inv[i-1] * inv[i] % MOD;

  for (;!cin.eof();cin>>ws)
    main2();

  return 0;
}


Measured memory_bytes: 26624
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define RI(a) scanf("%d",&a)
#define RII(a,b) scanf("%d%d",&a,&b)
#define RIII(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define IOS ios_base::sync_with_stdio(0); cin.tie(0)
#define ALL(a) a.begin(),a.end()
#define F first
#define S second
#define REP(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#ifdef leowang
#define debug(...) do{\
	fprintf(stderr,"%s - %d : (%s) = ",__PRETTY_FUNCTION__,__LINE__,#__VA_ARGS__);\
	_DO(__VA_ARGS__);\
}while(0)
template<typename I> void _DO(I&&x){cerr<<x<<endl;}
template<typename I,typename...T> void _DO(I&&x,T&&...tail){cerr<<x<<", ";_DO(tail...);}
#else
#define debug(...)
#endif
//}}}
const ll maxn=100005;
const ll maxlg=__lg(maxn)+2;
const ll INF64=8000000000000000000LL;
const int INF=2000000000;
const ll mod=998244353;

map<int,int> mp;

int main()
{
	int n;
	cin>>n;
	REP(i,n){
		int x;
		cin>>x;
		mp[x]++;
	}
	cin>>n;
	REP(i,n){
		int x;
		cin>>x;
		if(mp[x]==0){
			puts("NO");
			return 0;
		}
		mp[x]--;
	}
	puts("YES");
	return 0;
}












Measured memory_bytes: 9600
import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline

in_n = lambda: int(readline())
in_nn = lambda: map(int, readline().split())
in_nl = lambda: list(map(int, readline().split()))
in_na = lambda: map(int, read().split())
in_s = lambda: readline().rstrip().decode('utf-8')


def t(S):

    N = len(S)

    a = [0] * (N + 1)
    d = [0] * (N + 1)
    for i in range(N):
        if S[i] == 'A':
            a[i + 1] = 1
        else:
            d[i + 1] = 1

    for i in range(N):
        a[i + 1] += a[i]
        d[i + 1] += d[i]

    ans = 0
    for i in range(1, N):
        if S[i] == 'D':
            ans += a[i]

    return ans


def main():

    S = in_s()
    S = S.replace('BC', 'D')
    S = S.replace('B', ' ')
    S = S.replace('C', ' ')

    ans = 0
    for ts in S.split():
        ans += t(ts)

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 18244
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  FOR(i,0,n)
#define pai 3.14159265358979323846
const int INF = 1001001001;
typedef long long ll;
int A[3][3], N;
bool punched[3][3];
bool ok[3][3];
int a[3][3],n;
using Graph = vector<vector<int>>;
vector<vector<int>> field;
vector<bool> seen;



int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  vector<int> B(N);
  for (int i = 0; i < N; i++) {
    cin >> A[i];
    B[i] = A[i];
  }
  sort(B.begin(), B.end());
  for (int i = 0; i < N; i++) {
    if (A[i] < B[N - 1]) {
      cout << B[N - 1] << "\n";
    } else {
      cout << B[N - 2] << "\n";
    }
  }
  return 0;
  
    
   
  

}



Measured memory_bytes: 3200
def comb(n,k):
	if n<k or n==0: return 0
	elif k==0: return 1
	else: return f[n]*p[k]*p[n-k]%(10**9+7)
from collections import Counter
n = int(input())
print(n)
a = [int(i) for i in input().split()]
twice = Counter(a).most_common(1)[0][0]
x,y = (i for i,j in enumerate(a) if j == twice)
num,y,f,p = 1,n-y,[1],[1]
for i in range(1,n+2):
	f.append(f[-1]*i%(10**9+7))
	p.append(pow(f[-1],10**9+5,10**9+7))
for i in range(2,x+y+2): print((comb(n+1,i)-comb(x+y,i-1))%(10**9+7))
for i in range(x+y+2,n+2): print(comb(n+1,i))

Measured memory_bytes: 19928
#include<iostream>
#include<cmath>
using namespace std;
long long k, _min, _max, x_y, x, y, fibx, fiby, a; long double mid;

#define MOD 1000000007

int dp[3];

int main() {
	cin >> k;
	a = sqrt(k) / 16;
	x_y = (long long)((2 * sqrtl(k - a - 0.01)) - 1);
	_max = (long long)((x_y + 2)*(x_y + 2) / 4);
	_min = (long long)((x_y + 1)*(x_y + 1) / 4) + 1;
	mid = 1.0*(_max + _min) / 2;
	if (k <= mid) { y = (k - _min) * 2; }
	else { y = (_max - k) * 2 + 1; }
	x = x_y - y;
	
	//fibx.
	if (x < 3)
	{
		fibx = x + 1;
	}

	else {
		dp[0] = 1;
		dp[1] = 2;
		dp[2] = 3;

		for (long long i = 3; i <= x; i += 3)
		{
			dp[0] = (dp[1] + dp[2]) % MOD;
			dp[1] = (dp[2] + dp[0]) % MOD;
			dp[2] = (dp[0] + dp[1]) % MOD;
		}

		fibx = dp[x % 3];
	}

	//fiby.
	if (y < 3)
	{
		fiby = y + 1;
	}

	else {
		dp[0] = 1;
		dp[1] = 2;
		dp[2] = 3;

		for (long long i = 3; i <= y; i += 3)
		{
			dp[0] = (dp[1] + dp[2]) % MOD;
			dp[1] = (dp[2] + dp[0]) % MOD;
			dp[2] = (dp[0] + dp[1]) % MOD;
		}

		fiby = dp[y % 3];
	}

	cout << ((long long)(fibx * fiby) % MOD) << endl;
	return 0;
}

Measured memory_bytes: 3096
n = int(input())

def sieve(n):
    n += 10
    res = list(range(n))
    res[0] = -1
    res[1] = -1
    i = 2
    while i*i<n:
        if res[i]<i:
            i += 1
            continue
        j = i*i
        while j<n:
            if res[j]==j:
                res[j] = i
            j += i
        i += 1
    return res

l = sieve(n)
res = 0
for k in range(1,n+1):
    m = k
    r = 1
    while m!=1:
        p = l[m]
        c = 0
        while l[m]==p:
            m //= l[m]
            c += 1
        r *= c+1
    res += k*r
print(res)


Measured memory_bytes: 146292