akhauriyash/Code-Regression huggingface dataset:
N = int(input())
book = dict()

for i in range(N):
    inp = input().split()
    if book.get(inp[0]):
        book[inp[0]].append( (i, int(inp[1])) )
    else:
        book[inp[0]] = [(i, int(inp[1])),]

for s in sorted(book.items(), key=lambda x:x[0]):
    rests = s[1]
    for r in sorted(rests, key=lambda x:x[1], reverse=True):
        print(r[0]+1)

Measured memory_bytes: 3064
#include <algorithm>
#include <bitset>
#include <cctype>
#include <chrono>
#include <cmath>
#include <cstdio>
#include <ctime>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <string>
#include <tuple>
#include <unordered_map>
#include <vector>
using namespace std;

#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()

const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
/*----------------------------------------*/
const int MOD = 1000000007;

int main() {
  cin.tie(0); ios::sync_with_stdio(false);
  // freopen("input.txt", "r", stdin);

  int n, k; cin >> n >> k;
  vector<int> a(n); REP(i, n) cin >> a[i];
  vector<vector<long long> > dp(n+1, vector<long long>(k+1, 0));
  REP(i, n+1) dp[i][0] = 1;
  REP(i, n) FOR(j, 1, k+1) {
    if (j-1-a[i]<0) dp[i+1][j] = (dp[i][j] + dp[i+1][j-1]) % MOD;
    else dp[i+1][j] = (dp[i][j] + dp[i+1][j-1] - dp[i][j-1-a[i]] + MOD) % MOD;
  }
  cout << dp[n][k] << '\n';
  return 0;
}


Measured memory_bytes: 80256
N, A, B, C = map(int, input().split())
l = [int(input()) for _ in range(N)]

ret = float('inf')
for k in range(4 ** N):
    cost = 0
    stick = [0, 0, 0]

    for i in range(N):
        t = k % 4
        if t != 0:
            if stick[t - 1] > 0:
                cost += 10
            stick[t - 1] += l[i]
        k //= 4

    if stick[0] == 0 or stick[1] == 0 or stick[2] == 0:
        continue
    cost += abs(A - stick[0]) + abs(B - stick[1]) + abs(C - stick[2])

    ret = min(ret, cost)

print(ret)


Measured memory_bytes: 3064
Scanf.scanf "%d" (fun n ->
    let a = Array.init n (fun i -> Scanf.scanf " %d" (fun a -> a, i)) in
    Array.sort (fun a b -> compare b a) a;

    let dp = Array.make_matrix (n + 1) n 0 in

    Array.iteri (fun i (act, pos) ->
        for j = 0 to i do
            dp.(i + 1).(j    ) <- max dp.(i + 1).(j)     (dp.(i).(j) + abs (pos - (n - 1 - i + j)) * act);
            if j + 1 < n then
            dp.(i + 1).(j + 1) <- max dp.(i + 1).(j + 1) (dp.(i).(j) + abs (pos - j) * act)
        done
    ) a;
    Array.fold_left max 0 dp.(n) |> Printf.printf "%d\n"
)

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

bool ch[2][105] = {0};
char mp[105][105];
int h, w;

int main() {
  int i, j;
  cin >> h >> w;
  for(i = 0; i < h; ++i)
    for(j = 0; j < w; ++j) {
      cin >> mp[i][j];
      if(mp[i][j] == '#') ch[0][i] = ch[1][j] = 1;
    }
  for(i = 0; i < h; ++i) {
    for(j = 0; j < w; ++j)
      if(ch[0][i] && ch[1][j]) cout << mp[i][j];
    cout << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <cstring>
#include <cstdio>
#include <math.h>
#include <algorithm>
#include <vector>
#include <string>
#include <stdlib.h>
#include <queue>
#include <stack>
#include <utility>
#include <fstream>
#include <random>
#include <map>
#include <unordered_map>
#include <cstdlib>
#include <functional>
#include <random>
#include <time.h>
#include <chrono>
#include <sstream>
#include <iomanip>
#define rep(i,n) for(int i=0;i<n;i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ll long long
#define INF 1000000001
#define mod 1000000007
#define SORT(s) sort(s.begin(), s.end());
#define reverse(s) reverse(s.begin(), s.end());
#define P pair<int,int>
#define mp make_pair
#define valid(x,y,h,w) (0<=x&&x<h&&0<=y&&y<w)
int dx[4] = { 0,1,0,-1 };
int dy[4] = { 1,0,-1,0 };
using namespace std;
int POW(int x, int y) { return int(pow(double(x), double(y))); }
double log(double a, double b) { return log(b) / log(a); }




int main() {
	int a, p;
	cin >> a >> p;
	int sum = a * 3 + p;
	cout << sum / 2 << endl;
	
}



Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
int main(void)
{
	char str[201]={0,},str1[201]={0,},str2[201]={0,};
	int n,h,size,i;
    
    while(1){
		scanf("%s", &str);
		if(str[0]=='-') break;
		size=strlen(str);
		scanf("%d", &n);
		for(i=0;i<n;i++){
			scanf("%d", &h);
			if(size>h){
				strcpy(str1,&str[h]);
				str[h]='\0';
				strcpy(str2,&str[0]);
				strcat(str1,str2);
				strcpy(str,str1);
			}

		}
		printf("%s\n",str);
	}
	return 0;   
}

Measured memory_bytes: 600
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<unordered_set>
#include<unordered_map>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
#define mod 1000000007
#define mad(a,b) a=(a+b)%mod;
vector<P> v;
ll fff(ll n,P p){
    ll res=n/p.first*p.second+n%p.first;
    return res;
}
ll solve(ll n){
    if(v.size()==0)return n;
    if(v.size()==1){
	return fff(n,v[0]);
    }
    if(v.size()==2){
	ll ma=n;
	for(ll i=0;i*v[0].first<=n;i++){
	    ll cur=fff(i*v[0].first,v[0]);
	    cur+=fff(n-i*v[0].first,v[1]);
	    ma=max(ma,cur);
	}
	return ma;
    }
    ll ma=n;
    for(ll i=0;i*v[0].first<=n;i++){
	for(ll j=0;i*v[0].first+j*v[1].first<=n;j++){
	    ll cur=fff(i*v[0].first,v[0]);
	    cur+=fff(j*v[1].first,v[1]);
	    cur+=fff(n-i*v[0].first-j*v[1].first,v[2]);
	    ma=max(ma,cur);
	}
    }
    return ma;
}
int main(){
  ll n,a,b,c,d,e,f;
  cin>>n>>a>>c>>e>>b>>d>>f;
  if(a<b)v.push_back(make_pair(a,b));
  if(c<d)v.push_back(make_pair(c,d));
  if(e<f)v.push_back(make_pair(e,f));
  n=solve(n);
  v.clear();
  if(a>b)v.push_back(make_pair(b,a));
  if(c>d)v.push_back(make_pair(d,c));
  if(e>f)v.push_back(make_pair(f,e));
  cout<<solve(n)<<endl;
  return 0;
}


Measured memory_bytes: 256
n, m = map(int, input().split())
sc = [tuple(map(int, input().split())) for _ in range(m)]
for i in range(1000):
    t = str(i)
    if len(t) != n: continue
    for s, c in sc:
        if str(c) != t[s-1]: break
    else:
        print(i)
        break
else: print(-1)


Measured memory_bytes: 3060
#include <algorithm>
#include <stdio.h>
#include <math.h>
using namespace std;

const int NMAX = 100110;

int dp[NMAX];
int h[NMAX];

int main()
{
    int n, k;
    scanf("%d%d", &n, &k);
    fill(dp, dp + n + 1, 2e9);

    for (int i = 1; i <= n; i++)
        scanf("%d", h + i);

    dp[1] = 0;

    for (int i = 1; i <= n; i++)
        for (int j = 1; j <= k; j++)
            dp[i + j] = min(dp[i + j], dp[i] + abs(h[i] - h[i + j]));

    printf("%d\n", dp[n]);

    return 0;
}


Measured memory_bytes: 896
#include <iostream>
#include <stdio.h>
#include <vector> 
#include <math.h> 
#include <algorithm> 
using namespace std;
int main(void){
    int a,b,k; cin >> a >> b >> k;
    int i = 1;
    vector<int> num;
    while (i <= 100) {
        if (a % i == 0 && b % i == 0) num.push_back(i);
        i++;
    }
    sort(num.begin(), num.end(), greater<int>());
    cout << num[k-1] << endl;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i = 0; i < (N); i++)
#define repo(i,N) for(int i = 1; i < (N); i++)
//#define int long long
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
//#define num 1000000007
#define pi acos(-1.0)
//cout << fixed << setprecision (10);   小数点以下１０桁まで
//intの最大値2147483647 ≒ 2×10^9
//long longの最大値9223372036854775807 ≒ 9×10^18
//'大文字'+=32;    で小文字に
//string s = to_string(int数);
//int n = stoi(string文字列);

int main() {
  int s;
  cin >>s;
  cout << fixed << setprecision (10); 
  
  if(s%2==0){
  cout << 0.5 << endl;
  }
  
  else {
  cout << (double)(s/2+1)/s <<endl;
  }
  
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  double res = 0;
  cin >> n;
  for(int i=1; i<=n;++i){
    double x;
    cin >> x;
    res+=1/x;
  }
  res=1/res;
  cout << res;
}

Measured memory_bytes: 256
import           Control.Monad
import           Data.Array.IO
import           Data.Bits
import qualified Data.ByteString.Char8       as BS
import           Data.Char
import           Data.Maybe
import qualified Data.Vector.Unboxed         as V
import qualified Data.Vector.Unboxed.Mutable as VM

readInt = fst . fromJust . BS.readInt
getInt = readInt <$> BS.getLine
getIntVec n = V.unfoldrN n (BS.readInt . BS.dropWhile isSpace) <$> BS.getLine

main = do
  n <- getInt
  as <- getIntVec n

  cs <- VM.new 61
  VM.set cs (0::Int)

  forM_ [0..n-1] $ \i -> do
    let a = as V.! i
    forM_ [0..60] $ \j ->
      when (testBit a j) $ do
        c <- VM.read cs j
        VM.write cs j (c+1)
  cs' <- V.freeze cs

  let calc i c a = let c1 = fromIntegral c :: Integer
                       c2 = fromIntegral (n-c) :: Integer
                   in
                     c1 * c2 * bit i + a

  print $ V.ifoldr calc 0 cs' `mod` 1000000007


Measured memory_bytes: 15996
#include <bits/stdc++.h>
#include <algorithm>
#include <numeric>
using namespace std;
 
int main() {
  int n;
  cin >> n;
  int a[100100];

  for(int i = 0; i < 100010; i++){
      a[i] = 0;
  }
 
  for(int i = 0; i < n; i++){
      cin >> a[i];
  }
  
  sort(a,a+n);
  
  for(int i = 0; i < n - 1; i++){
    if(__gcd(a[i+1],a[0]) == 1){
       cout << 1 << endl;
        return 0;
    }else{
       a[i+1] = __gcd(a[i+1],a[0]);
     }
  }
  
  sort(a,a+n);
  
  cout << a[0] << endl;
 
}

Measured memory_bytes: 640
n,k=map(int,input().split())
A=list(map(int,input().split()))
s=[]
v=1
ord=[-1]*(n+1)
c=1
l=0
while ord[v]==-1:
  ord[v]=len(s)
  s.append(v)
  v=A[v-1]
c=len(s)-ord[v]
l=ord[v]

if k<l:
  print(s[k])
else:
  k-=l
  k%=c
  print(s[l+k])


Measured memory_bytes: 94788
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <bitset>
#include <deque>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <iterator>
#include <string>
#include <chrono>
#include <random>
#include <tuple>
#include <utility>
#include <fstream>
#include <complex>

const long INF = (1l << 30);
const long LINF = (1l << 60);

long n;
long a[100005];
long max = 0;
long min = LINF;

int main(){
    scanf("%ld", &n);
    for(int i = 0; i < n; i++){
        scanf("%ld", &a[i]);
        max = std::max(max, a[i]);
        min = std::min(min, a[i]);
    }
    if(max - min >= 2){
        printf("No\n");
        return 0;
    }else if(max - min == 1){
        long cnt = 0;
        for(int i = 0; i < n; i++){
            if(a[i] == max){
                cnt++;
            }
        }
        if(n-max+1 <= cnt && cnt <= 2*(n-max)){
            printf("Yes\n");
        }else{
            printf("No\n");
        }
    }else{
        if(2*max <= n || max == n-1){
            printf("Yes\n");
        }else{
            printf("No\n");
        }
    }
}


Measured memory_bytes: 1024
(let* ((n (read))
       (d (read))
       (ans 0))
  (loop :for i :from 1 :to n
        :for x := (read)
        :for y := (read)
        :if (<= (+ (* x x) (* y y)) (* d d))
        :do (incf ans))
  (format t "~A~%" ans))


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

using namespace std;

#define PI 3.1415926535897932

int main(){
    int mod=1000000007;
    int n,m,chk,p,x;
    scanf("%d",&n);
    vector<int> t(n);
    for (auto&e:t) {
        scanf("%d",&e);
    }
    chk = accumulate(t.begin(),t.end(),0);
    scanf("%d",&m);
    for (int i=0;i<m;i++) {
        scanf("%d %d",&p,&x);
        printf("%d\n",chk-(t[p-1]-x));
    }
    return 0;
}


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

public class Main {
	private static final int MOD = (int)Math.pow(10, 9) + 7;
	public static void main(String[] args) {
		FastReader sc = new FastReader();
      	String s = sc.next();
      	// 對每個字母計數
      	int[] charCnt = new int[26];
      	// 每個字母最遠到哪裡，例如finalLoc[0] = 15,代表a最後一次出現的位置
      	int[] finalLoc = new int[26];
      	int len = s.length();
      	
      	for (int i = 1; i < len; i++) {
      		if (s.charAt(i) == s.charAt(i - 1)) {
      			System.out.println((i) + " " + (i + 1));
  				System.exit(0);
      		}
      	}
      	
      	for (int i = 2; i < len; i++) {
      		if (s.charAt(i) == s.charAt(i - 2)) {
      			System.out.println((i - 1) + " " + (i + 1));
  				System.exit(0);
      		}
      	}
      	
      	System.out.println("-1 -1");
	}
	
    static class FastReader {
	    BufferedReader br;
	    StringTokenizer st;
	
	    public FastReader() {
	      br = new BufferedReader(new InputStreamReader(System.in));
	    }
	  
	    String next() { 
	      while (st == null || !st.hasMoreElements()) {
	        try {
	          st = new StringTokenizer(br.readLine());
	        } catch (IOException  e) {
	          e.printStackTrace();
	        }
	      }
	      return st.nextToken();
	    }
	
	    int nextInt() {
	      return Integer.parseInt(next());
	    }
	
	    long nextLong() {
	      return Long.parseLong(next());
	    }
	
	    double nextDouble() { 
	      return Double.parseDouble(next());
	    }
	
	    String nextLine() {
	      String str = "";
	        try{
	            str = br.readLine();
	        } catch (IOException e) {
	            e.printStackTrace();
	        }
	        return str;
	      }
	  }
}


Measured memory_bytes: 24788
def search(t, i, reached):
    if reached[i]:
        return

    reached[i] = True
    for nt in t[i]:
        search(t, nt, reached)


def main():
    N, M = map(int, input().split())
    AB = [list(map(int, input().split())) for _ in range(M)]

    t = [[] for _ in range(N)]
    for a, b in AB:
        a -= 1
        b -= 1
        t[a].append(b)
        t[b].append(a)

    cnt = 0
    for a, b in AB:
        a -= 1
        b -= 1

        t[a].remove(b)
        t[b].remove(a)
        reached = [False for _ in range(N)]
        search(t, 0, reached)
        if not all(reached):
            cnt += 1

        t[a].append(b)
        t[b].append(a)

    print(cnt)


main()


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

#define AC "AC"
#define WA "WA"
#define TLE "TLE"
#define RE "RE"

int main()
{
    int n, ac = 0, wa = 0, tle = 0, re = 0;
    char judge_result[5];

    scanf("%d", &n);
    for (int i = 0; i<n; i++)
    {
        scanf("%s", judge_result);
        if (strcmp(judge_result, AC) == 0)
        {
            ac ++;
        } else if (strcmp(judge_result, WA) == 0)
        {
            wa ++;
        } else if (strcmp(judge_result, TLE) == 0)
        {
            tle ++;
        } else if (strcmp(judge_result, RE) == 0)
        {
            re ++;
        }
    }

    printf("AC x %d\n", ac);
    printf("WA x %d\n", wa);
    printf("TLE x %d\n", tle);
    printf("RE x %d\n", re);

    return 0;
}

Measured memory_bytes: 1736
#include <queue>
#include <cstdio>
#include <iostream>
#include <math.h>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <sstream>
#include <algorithm>
#include <iomanip>
#include <stack>
#include <time.h>
#include <functional>
using namespace std;
typedef long long int ll;

#define EPS (1e-9)
#define INF (1e9)
#define PI (acos(-1))
#define REP(i,n) for(int i=0;i<n;i++)

int gcd(int a, int b) {
    if (a < b) swap(a, b);
    if (b == 0) return a;
    return gcd(b, a % b);
}

ll beki(ll a, ll b) {
    ll tmp = 1;
    REP(i, b) tmp *= a;
    return tmp;
}

int K;
ll sum = 0;

int main() {
    cin >> K;
    for (int i = 1; i <= K; i++) {
        for (int j = 1; j <= K; j++) {
            for (int k = 1; k <= K; k++) {
                sum += gcd(i, gcd(j, k));
            }
        }
    }
    cout << sum << endl;
}


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

using namespace std;

#define endl "\n"

const int MAXN = 25;
const int MAXMASK = (1<<21)+10;
const int MOD = int(1e9) + 7;

int n;
bool comp[MAXN][MAXN];
int memo[MAXMASK];

void print_2(int num){
    bool flag = false;
    for(int i=31; i>=0; i--){
        flag = (flag || (num&(1<<i)));

        if(flag) cout << ((num&(1<<i))!=0);
    }
    cout << endl;
}

int32_t solve(int i, int mask){
    if(memo[mask]!=-1) return memo[mask];

    if(i>=n) return (mask==((1<<n)-1));

    memo[mask] = 0;
    for(int j=0; j<n; j++){
        if(comp[i][j] && (mask&(1<<j))==0){
            memo[mask] = (memo[mask]+solve(i+1, mask|(1<<j)))%MOD;
        }
    }

    return memo[mask];
}


int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    cin >> n;

    for(int i=0; i<n; i++)
        for(int j=0; j<n; j++)
            cin >> comp[i][j];

    memset(memo, -1, sizeof(memo));

    cout << solve(0, 0) << endl;

    return 0;
}

Measured memory_bytes: 8448
n = int(input())
a = list(map(int, input().split()))
new_list = []
count = 0

for i in a:
    if i % 2 == 0:
        new_list.append(i)
    else:
        continue
for i in new_list:
    if i % 3 == 0 or i % 5 == 0:
        count += 1
if count == len(new_list):
    print('APPROVED')
else:
    print('DENIED')


Measured memory_bytes: 3060
#include<iostream>
using namespace std;
int main(){
  int P, Q, R;
  cin >> P >> Q >> R;
  int m;
  if (P > Q)
    m = P;
  else
    m = Q;
  if (R > m)
    m = R;
  cout << P + Q + R - m << endl;
  return 0;
}

Measured memory_bytes: 256
let (>>=) xs f = List.map f xs |> List.concat
let rec choice s c acc = function
  | [] -> if s = 0 then [] else [(s, c-10, acc)]
  | x::xs -> choice s c (x::acc) xs @ choice (s+x) (c+10) acc xs
let () =
  Scanf.scanf "%d %d %d %d" @@ fun n a b c ->
  let l = Array.init n (fun _ -> Scanf.scanf " %d" ((+) 0)) |> Array.to_list in
  (choice 0 0 [] l >>= fun (a', wa, l) ->
   choice 0 0 [] l >>= fun (b', wb, l) ->
   choice 0 0 [] l >>= fun (c', wc, l) ->
     [wa + wb + wc + abs (a - a') + abs (b - b') + abs (c - c')])
  |> List.fold_left min 1010101010
  |> Printf.printf "%d\n"


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

using namespace std;

int main() {
    int A, B;

    cin >> A >> B;

    int sum = A+B;
    int sub = A-B;
    int mult = A*B;

    priority_queue<int> ops;
    ops.push(sum);
    ops.push(sub);
    ops.push(mult);

    cout << ops.top() << endl;

    return 0;
}

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

int main()
{
	int n;
	cin >> n;
	vector<int> a(n);
	for(int i = 0;i<n;i++)cin >> a[i];
	sort(a.begin(),a.end());
	a.back() /=2;
	int ans = 0;
	for(int i = 0;i<n;i++)ans+=a[i];

	cout << ans << endl;
}


Measured memory_bytes: 3540
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define ALL(v) (v).begin(),(v).end()
const ll MOD = 1e9 + 7;
struct UnionFind {
	vector<int> par;
	vector<int> size;
	vector<set<int>> S;
	UnionFind(int n) {
		par = vector<int>(n);
		for (int i = 0; i < n; i++) par[i] = i;
		size = vector<int>(n, 1);
		S = vector<set<int>>(n);
	}

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

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

	void unite(int x, int y) {
		x = find(x);
		y = find(y);
		if (x == y) return;
		if (S[x].size() < S[y].size()) {
			for (int e : S[x]) {
				S[y].insert(e);
			}
			par[x] = y;
		}
		else {
			for (int e : S[y]) {
				S[x].insert(e);
			}
			par[y] = x;
		}
	}
};
vector<int> vec[100001];
set<int> T[100001];
int main() {
	int N;
	cin >> N;
	UnionFind U(100001);
	for (int i = 0; i < N; i++) {
		int x, y;
		cin >> x >> y;
		vec[y].push_back(x);
		U.S[x].insert(y);
		T[x].insert(y);
	}
	for (int i = 1; i <= 100000; i++) {
		for (int j = 0; j + 1 < vec[i].size(); j++) {
			U.unite(vec[i][j], vec[i][j + 1]);
		}
	}
	ll ans = 0;
	for (int i = 1; i <= 100000; i++) {
		int x = U.find(i);
		ans += U.S[x].size() - T[i].size();
	}
	cout << ans << endl;
}


Measured memory_bytes: 36736
#include <iostream>
#include <algorithm>
#include <numeric>

using namespace std;

using Action = struct
{
    int64_t val;
    int64_t num;
};

int64_t a[100'000];
Action act[100'000];

int main()
{
    int N, M;

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

    for (int i = 0; i < M; i++)
    {
        cin >> act[i].num >> act[i].val;
    }

    sort(a, a + N, [](int64_t &l, int64_t &r) {
        return l < r;
    });

    sort(act, act + M, [](Action &l, Action &r) {
        return l.val > r.val;
    });

    int curr = 0;
    for (int i = 0; i < N; i++)
    {
        if (curr >= M)
        {
            break;
        }
        if (a[i] < act[curr].val)
        {
            a[i] = act[curr].val;
            act[curr].num--;
            if (act[curr].num == 0)
            {
                curr++;
            }
        }
    }

    int64_t result = accumulate(a, a + N, 0LL, [](int64_t l, int64_t r) {
        return l + r;
    });

    cout << result << endl;

    return 0;
}

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

int main() {
#ifdef LOCAL
    freopen("xxx.in", "r", stdin);
    freopen("xxx.out", "w", stdout);    
#endif
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int a, b;
    string s;
    cin >> a >> b;
    cin >> s;
    if ((int)s.size() != a + b + 1) {
        cout << "No";
        return 0;
    }
    for (int i = 0; i < a; ++i) {
        if (!(s[i] >= '0' && s[i] <= '9')) {
            cout << "No";
            return 0;
        }
    }
    if (s[a] != '-') {
        cout << "No";
        return 0;
    }
    for (int i = a + 1; i < a + b + 1; ++i) {
        if (!(s[i] >= '0' && s[i] <= '9')) {
            cout << "No";
            return 0;
        }
    }
    cout << "Yes";
    return 0;
}

Measured memory_bytes: 256
N = int(input())
xyh = []

for i in range(N):
    ent = input().split()
    xyh.append((int(ent[0]), int(ent[1]), int(ent[2])))

sortedxyh = sorted(xyh, key=lambda x:int(x[2]))

pointA = None
pointB = None
for x in xyh:
    if x[2] != 0:
        if pointA == None:
            pointA = x
        else:
            pointB = x
            break

endflg = False
if pointB == None:
    # 1点しか高さのある点がないケース
    print(str(pointA[0]) + ' ' + str(pointA[1]) + ' ' + str(pointA[2]))
else:
    # 2点あれば全探索で計算出来る?
    # 高さ算出
    for cx in range(0, 101):
        for cy in range(0, 101):
            AH = pointA[2] + max( ( abs(pointA[0] - cx) + abs(pointA[1] - cy) ), 0)
            BH = pointB[2] + max( ( abs(pointB[0] - cx) + abs(pointB[1] - cy) ), 0)
            if AH == BH and AH != 0 and BH != 0:
                H = AH
                continueflg = False
                for other in xyh:
                    if other[2] != max((H - abs(other[0] - cx) - abs(other[1] - cy)), 0):
                        continueflg = True
                        break
                if continueflg:
                    continue
                print(str(cx) + ' ' + str(cy) + ' ' + str(H))
                endflg = True
                break
            else:
                continue
        if endflg:
            break

Measured memory_bytes: 3064
import java.util.*;

class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        //約数か判断
        if((b % a) == 0){
            System.out.println(a + b);
        }else{
            System.out.println(-a + b);
        }
    }
}

Measured memory_bytes: 21972
n = int(input())
s = list(input())
al = list("ABCDEFGHIJKLMNOPQRSTUVWXYZ")
for i in range(len(s)):
  ind = al.index(s[i]) + n
  if ind > 25:
    ind = ind - 26
  s[i] = al[ind]
print("".join(s))

Measured memory_bytes: 39152
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
int main(){
  ll a,b,c;
  cin >> a >> b >> c;
  string ans="NO";
  ll sum=0,cp=a;
  rep(i,b){
    sum+=a;
    if(sum%b==c){
      ans="YES";
    }
  }
  cout << ans;
}

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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;

#define PB push_back
#define F first
#define S second
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define sz(x) (int)x.size()

const double PI = acos(-1);
const double eps = 1e-9;
const int inf = 2000000000;
const ll infLL = 9000000000000000000;
#define MOD 1000000007
// #define harmonic(n) 0.57721566490153286l+log(n)

#define mem(a,b) memset( a, b, sizeof(a) )
#define gcd(a,b) __gcd(a,b)
#define sqr(a) ((a) * (a))

#define optimize() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define fraction() cout.unsetf(ios::floatfield); cout.precision(10); cout.setf(ios::fixed,ios::floatfield);
#define file() freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);

inline bool checkBit(ll n, int i) { return n & (1LL << i); }
inline ll setBit(ll n, int i) { return n | (1LL << i); }
inline ll resetBit(ll n, int i) { return n & (~(1LL << i)); }

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

inline bool EQ(double a, double b) { return fabs(a-b) < 1e-9; }
inline void normal(ll &a) { a %= MOD; (a < 0) && (a += MOD); }
inline ll modMul(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a*b)%MOD; }
inline ll modAdd(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a+b)%MOD; }
inline ll modSub(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); a -= b; normal(a); return a; }
inline ll modPow(ll b, ll p) { ll r = 1; while(p) { if(p&1) r = modMul(r, b); b = modMul(b, b); p >>= 1; } return r; }
inline ll modInverse(ll a) { return modPow(a, MOD-2); }
inline ll modDiv(ll a, ll b) { return modMul(a, modInverse(b)); }

int main() {
    optimize();
    ll n;
    cin >> n;
    ll ans = 0;
    ll a = 1;
    while (n > 0) {
        ans += a;
        a *= 2;
        n /= 2;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(ll i = 0; i < n; i++)
#define repr(i, n) for(ll i = n; i >= 0; i--)
#define inf LLONG_MAX
#define all(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;


int main()
{
    ll x ; cin >> x;
    ll c = 0;
    ll i = 1;
    while (c + i < x) {
        c += i;
        i++;
    }
    cout << i << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;
typedef long long ll;
const int MAXN = 1e5+10;
ll n, k;
ll counts[MAXN];

void solve() {
  for (int i=0;i<=MAXN;i++) {
    if (counts[i] >= k) {
      cout << i << endl;
      return;
    }
    k -= counts[i];
  }
}

int main() {
  cin >> n >> k;
  ll a, b;
  for (int i=0;i<n;i++) {
    cin >> a >> b;
    counts[a] += b;
  }
  solve();
}


Measured memory_bytes: 1024
N , M = map(int,input().split())
SC = []
for i in range(M):
    SC.append(list(map(int,input().split())))

if M == 0:
    if N == 1:
        print(0)
    else:
        print(10**(N-1))
    exit()
    
if N == 1:
    for i in range(10):
        n = str(i)
        for j in range(M):
            if int(n[SC[j][0]-1]) != SC[j][1]:
                break
            if j == M-1:
                print(i)
                exit()
  
else:
    for i in range(10**(N-1),10**N):
        n = str(i)
        for j in range(M):
            if int(n[SC[j][0]-1]) != SC[j][1]:
                break
            if j == M-1:
                print(i)
                exit()
                
print(-1)

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

using namespace std;

using ll = long long;
using ld = long double;
using P = pair<string, int>;
constexpr ld EPS = 1e-12;
constexpr int INF = numeric_limits<int>::max() / 2;
constexpr int MOD = 1e9 + 7;

template <typename T>
void printv(const vector<T> &v)
{
    int sz = v.size();
    for (int i = 0; i < sz; i++)
    {
        cout << v[i] << " \n"[i == sz - 1];
    }
}

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

    string com;
    priority_queue<ll> q;
    while (cin >> com)
    {
        if (com == "end")
            break;
        if (com == "extract")
        {
            cout << q.top() << endl;
            q.pop();
        }
        else
        {
            ll x;
            cin >> x;
            q.push(x);
        }
    }
}



Measured memory_bytes: 11276
max = 1000000
candidates = [True for x in range(0, max + 1)]
candidates[0] = False
candidates[1] = False

for i in range(2, max / 2):
    if not candidates[i]:
        continue

    j = i + i
    while True:
        if max < j:
            break
        candidates[j] = False
        j += i

while True:
    try:
        n = int(raw_input())
        print len([i for i in candidates[0:n+1] if i])
    except Exception:
        break

Measured memory_bytes: 44464
#pragma GCC optimize (3)
#include<vector>
#include<stack>
#include<bitset>
#include<cstdlib>
#include<cmath>
#include<set>
#include<list>
#include<deque>
#include<map>
#include<queue>
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
/*#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#include<ext/pb_ds/hash_policy.hpp>
#include<ext/pb_ds/trie_policy.hpp>
#include<ext/pb_ds/priority_queue.hpp>*/
#define PII pair<int,int>
#define ll long long
#define ull unsigned long long
#define INFI 2147483647
#define INFL 9223372036854775807
#define INFU 18446744073709551615
using namespace std;
//using namespace __gnu_pbds;
const double PI=acos(-1.0);
const double eps=1e-6;
inline int read()
{
    int x=0,f=1;
    char ch=getchar();
    while(ch<'0' || ch>'9'){
        if(ch=='-') f=-1;
        ch=getchar();
    }
    while(ch>='0' && ch<='9'){
        x=x*10+ch-'0';
        ch=getchar();
    }
    return x*f;
}
int main()
{
	//ios_base::sync_with_stdio(false);
    //cin.tie(0);
    //cout.tie(0);
	ll x,y=100;
	cin>>x;
    for(ll i=1;i<=1000000;i++){
        y=(y+y/100);
        if(y>=x){
            printf("%lld\n",i);
            return 0;
        }
    }
	return 0;
}


Measured memory_bytes: 3760
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n, i, taro = 0, hanako = 0;
        String tc, hc;
        
        n = sc.nextInt();
        
        for(i = 0; i < n; i++) {
        	tc = sc.next();
        	hc = sc.next();
        	
        	if(tc.compareTo(hc) > 0) {
        		taro += 3;
        	} else if (tc.compareTo(hc) < 0) {
        		hanako += 3;
        	} else {
        		taro++;
        		hanako++;
        	}
        	
        }
        
        System.out.println(taro + " " + hanako);
        
    }
}


Measured memory_bytes: 30724
#include "bits/stdc++.h"
using namespace std;
#define pb push_back
#define fi first
#define se second
#define FF first
#define SS second
#define mp make_pair
#define ll long long
#define pii pair<int,int>
#define sd(x) scanf("%d",&x)
#define slld(x) scanf("%lld",&x)
#define pd(x) printf("%d\n",x)
#define plld(x) printf("%lld\n",x)
#define endl '\n'
#define fr(i, a, b) for(int i = a; i <= b; i++)
#define sz(x) (int)x.size()
typedef long double f80;
#define all(x) x.begin(), x.end()

vector<int> pos[26];

signed main()
{
    #ifdef LOCAL
        freopen("inp.txt", "r", stdin);
        freopen("out.txt", "w", stdout);
    #endif
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(NULL);
    string s, t;
    cin >> s >> t;
    fr(i, 0, sz(s) - 1) {
        pos[s[i] - 'a'].pb(i);
    }
    fr(i, 0, sz(t) - 1) {
        if(pos[t[i] - 'a'].empty()) {
            cout << -1;
            return 0;
        }
    }
    int p = -1;
    ll ans = 0;
    fr(i, 0, sz(t) - 1) {
        auto it = upper_bound(all(pos[t[i] - 'a']), p);
        if(it == pos[t[i] - 'a'].end()){
            ans += sz(s);
            p = -1;
            auto it = upper_bound(all(pos[t[i] - 'a']), p);
            p = *it;
        }
        else {
            p = *it;
        }
    }
    ans += p + 1;
    cout << ans;
    return 0;
}

Measured memory_bytes: 1228
modulo = 10**9+7

def modpow(base, n):
    ans = 1
    while n:
        if n&1:
            ans = (ans*base)%modulo
        base = (base*base)%modulo
        n >>= 1
    return ans
    

factorials = [1]
N = 10**5
for i in range(1, N+1):
    factorials.append((factorials[-1]*i)%modulo)

inv = [0]
for i in range(1, N+1):
    inv.append(modpow(factorials[i], modulo-2))


def nCr(n, r):
    if r == 0 or r == n:
        return 1
    return (factorials[n]*inv[n-r]*inv[r])%modulo


def read_int():
    return int(input().strip())


def read_ints():
    return list(map(int, input().strip().split(' ')))


def solve():
    N, K = read_ints()
    A = read_ints()
    A.sort()
    max_sum = 0
    for i in range(K-1, N):
        max_sum = (max_sum+A[i]*nCr(i, K-1))%modulo
    min_sum = 0
    for i in range(N-K+1):
        min_sum = (min_sum+A[i]*nCr(N-i-1, K-1))%modulo
    return (max_sum-min_sum)%modulo


if __name__ == '__main__':
    print(solve())


Measured memory_bytes: 87436
import java.util.Scanner;

public class Main {
	
	public static void main(String[] args) 
	{
		Scanner in = new Scanner(System.in);
		int H=in.nextInt();
        int	W=in.nextInt();
		int K=in.nextInt();
		char [][] c=new char [H][W];
		for(int i=0;i<H;i++)
		{
			String s=in.next();
			for(int j=0;j<W;j++)
			{
				c[i][j]=s.charAt(j);
			}
		}
		int ans=0;
		for(int maskR = 0;maskR<(1 << H);maskR++)
		{
			for(int maskC = 0; maskC <(1 << W);maskC++)
			{
				int black=0;
				for(int i=0;i<H;i++)
				{
					for(int j=0;j<W;j++)
					{
						if (((maskR >> i) & 1) == 0 && ((maskC >> j) & 1) == 0 && c[i][j] == '#')
							black = black + 1;
					}
				}
				if (black == K)
					ans = ans + 1;
			}
		}
		System.out.println(ans);
	}
}


Measured memory_bytes: 35728
import sys
input = sys.stdin.readline
I=lambda:int(input())
MI=lambda:map(int,input().split())
LI=lambda:list(map(int,input().split()))
from collections import deque

res=0
INF=10**9


N,u,v=MI()
G=[[] for _ in [0]*(N+1)]
for i in range(N-1):
    a,b=MI()
    G[a].append(b)
    G[b].append(a)


def bfs(a):
    q=deque()
    q.append(a)
    d=[INF]*(N+1)
    d[a]=0
    res=0
    while q:
        r=q.popleft()
        for nr in G[r]:
            if d[nr]==INF:
                q.append(nr)
                d[nr]=d[r]+1
                res+=1
    return d

aoki=bfs(v)
taka=bfs(u)

m=0
for i in range(1,N+1):
    if taka[i]<aoki[i]:
        m=max(aoki[i],m)
print(m-1)

Measured memory_bytes: 84780
#include <iostream>
#include <queue>

using namespace std;
typedef long long ll;
#define REP(i,n) for (ll i = 0; i < (n); ++i)

int main(){
    int n;
    cin >> n;
    vector<int> s(n, 0);
    REP(i, n){
        int ai;
        cin >> ai;
        s.at(--ai)++;
    }
    priority_queue<int, vector<int>, greater<int>> que;
    REP(i, n){
        if(s.at(i)){
            que.push(s.at(i));
        }
    }
    vector<int> ans(n, 0);
    for(int i = que.size(); i >= 1; --i){
        ans.at(i - 1) = que.top();
        if(que.size() > 1){
            int x1 = que.top(); que.pop();
            for(; x1 > 0; --x1){
                int x2 = que.top(); que.pop();
                que.push(x2 + 1);
            }
        }
    }
    REP(i, ans.size()){
        cout << ans.at(i) << endl;
    }
    return 0;
}


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

class D
{
	static void Main()
	{
		Func<long[]> read = () => Console.ReadLine().Split().Select(long.Parse).ToArray();
		var h = read();
		var k = (int)h[1];
		var s = new int[h[0]].Select(_ => read()).OrderByDescending(x => x[1]).ToArray();

		var g0 = s.Take(k).ToLookup(x => x[0], x => x[1]);
		var l0 = g0.SelectMany(g => g.Skip(1)).OrderBy(x => x).ToList();
		var l1 = s.Skip(k).Where(x => !g0.Contains(x[0])).GroupBy(x => x[0]).Select(g => g.First()[1]).OrderByDescending(x => x).ToList();

		var f = new long[Math.Min(l0.Count, l1.Count) + 1];
		f[0] = g0.SelectMany(x => x).Sum() + (long)g0.Count * g0.Count;
		for (int i = 0; i < f.Length - 1; i++) f[i + 1] = f[i] + l1[i] - l0[i] + 2 * (g0.Count + i) + 1;
		Console.WriteLine(f.Max());
	}
}


Measured memory_bytes: 39796
#include <bits/stdc++.h>
	
using namespace std;
 
#define len(x) int(x.size())
#define all(x) x.begin(), x.end()

typedef long long ll;
typedef pair <int, int> pii;

const int N = 2e5 + 10;

int a[N];

int main(){
	#ifdef HOME
	freopen("input.txt", "rt", stdin);
	#endif //HOME
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int a, b, c;
	cin >> a >> b >> c;
	int x = a - b;
	c = max(c - x, 0);
	cout << c;
	return 0;
}

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

int main(void){
    long int a, b ,k;
    cin >> a >> b >> k;
    if(a >= k){
        cout << a-k << ' ' << b << endl;
    }else if(a+b >= k){
        cout << "0 " << a + b - k << endl;
    }else{
        cout << "0 0" << endl;
    }
    return 0;
}

Measured memory_bytes: 3588
ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))

class tree:
    def __init__(self,n):
        self.n = n
        self.vlist = [None]*self.n
        self.start = [None]*self.n
        self.finish = [None]*self.n
        self.time = 0
    
    def add(self,n,v):
        v.sort()
        self.vlist[n] = v

    def search(self,u):
        if self.start[u] != None:
            return
        else:
            self.time += 1
            self.start[u] = self.time

            for i in self.vlist[u]:
                self.search(i-1)

            self.time += 1
            self.finish[u] = self.time
            return

n = ii()
t = tree(n)

for i in range(n):
    vk = li()
    u = vk[0]
    k = vk[1]
    v = vk[2:]
    t.add(u-1,v)

for i in range(n):
    t.search(i)

for i in range(n):
    print(i+1, t.start[i], t.finish[i])



Measured memory_bytes: 5668
import fractions

A,B = map(int, input().strip().split(' '))

# 素因数分解
def trial_division(n):
  result = []
  while n % 2 == 0:
    result.append(2)
    n //= 2
  f = 3
  while f*f <= n:
    if n % f == 0:
      result.append(f)
      n //= f
    else:
      f += 2
  if n != 1:
    result.append(n)
  return result

gcd_ = fractions.gcd(A,B)
if gcd_ == 1:
  print(1)
else:
  print(len(set(trial_division(gcd_)))+1)


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

int main(){
  string a, b, c;
  cin >> a >> b >> c;
  queue<char> sa, sb, sc;
  for(char t : a){
    sa.push(t);
  }
  for(char t : b){
    sb.push(t);
  }
  for(char t : c){
    sc.push(t);
  }
  char turn = sa.front();
  sa.pop();
  while(1){
    if(turn == 'a'){
      if(sa.empty()){
        cout << 'A';
        return 0;
      }
      turn = sa.front();
      sa.pop();
    }else if(turn == 'b'){
      if(sb.empty()){
        cout << 'B';
        return 0;
      }
      turn = sb.front();
      sb.pop();
    }else{
      if(sc.empty()){
        cout << 'C';
        return 0;
      }
      turn = sc.front();
      sc.pop();
    }
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <math.h>

using namespace std;

int main(){

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

  if ((a[a.size() - 1] == b[0]) && (b[b.size() - 1] == c[0])){
    cout << "YES" << endl;
  }
  else {
    cout << "NO" << endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i, a, b) for(ll i=(a); i<(b); i++)
#define PER(i, a, b) for(ll i=(a); i>=(b); i--)
#define rep(i, n) REP(i, 0, n)
#define per(i, n) PER(i, n, 0)
#define ALL(a)  (a).begin(),(a).end()
const ll INF = 1e18+18;
const ll MAX = 200000;
const ll MOD = 1000000007;
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl;
#define YES(n) cout << ((n) ? "YES" : "NO") << endl;


int main(){
    ll A, B, C, D;
    cin>>A>>B>>C>>D;
    ll T=C/B;
    if(C%B)T++;
    ll S=A/D;
    if(A%D)S++;
    Yes(T<=S);
}

Measured memory_bytes: 3632
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <utility>
#include <functional>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <unordered_map>

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
using namespace std;
typedef long long ll;
const int INF = (1<<30);
const int MOD = 1000000007;
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; }

int main() {
    int x;
    cin >> x;
    cout << (int)pow(x, 3) << endl;

    return 0;
}


Measured memory_bytes: 3232
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i,n) for (int i = 0; i < (n); ++i)
const int INF = 100100100;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;

bool is_kaibun(string S){
    string str = S;
    reverse(str.begin(), str.end());
    return S==str;
}

int main(){
    string s;
    cin >> s;
    int n = s.length();

    bool f = 1;
    f &= is_kaibun(s);

    string t = "";
    FOR(i,0,((n-1)/2)){
        t += s[i];
    }
    f &= is_kaibun(t);
    
    if(f == 1){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
   
using namespace std;
#define ll long long
#define ld long double
#define pll pair<long long,long long>
#define vll vector<long long>
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define deb(x) cout << #x << "=" << x << endl
#define F(i,a,b) for(ll i=a;i<=b;i++)
#define RF(i,a,b) for(ll i=a;i>=b;i--)
#define in(a,n) F(i,0,n-1)cin>>a[i]
#define vi vector<int>
#define out(a,n) F(i,0,n-1)cout<<a[i]<<" ";cout<<endl
#define mod 1000000007
#define trace1(x)                cerr<<#x<<": "<<x<<endl
#define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
#define int long long
  map<int,int>r,c,r1,c1;
   set<pll>s,s1;
   int n,m,k;
int sol()
{
     
   int ans=0;
   for(auto x:r)
   {
       ans=max(ans,x.ss);
   }
   int row=0;
   for(auto x:r)
   {
       if(x.ss==ans)
       {
           row=x.ff;
           break;
       }
   }
   int t=0;
   for(int i=1;i<=m;i++)
   {
       if(c.count(i))
       {
           if(s.count({row,i}))
           {
               int y=0;
               y=max(y,c[i]-1);
               t=max(t,y);
           }
           else
           {
               t=max(t,c[i]);
           }
       }
   }
   
   return ans+t;
   
   
}
int sol2()
{
     
   int ans=0;
   for(auto x:r1)
   {
       ans=max(ans,x.ss);
   }
   int row=0;
   for(auto x:r1)
   {
       if(x.ss==ans)
       {
           row=x.ff;
           break;
       }
   }
   int t=0;
   for(int i=1;i<=n;i++)
   {
       if(c1.count(i))
       {
           if(s1.count({row,i}))
           {
               int y=0;
               y=max(y,c1[i]-1);
               t=max(t,y);
           }
           else
           {
               t=max(t,c1[i]);
           }
       }
   }
   
   return ans+t;
   
      
}



void solve()
{
   
   cin>>n>>m>>k;
   
    r.clear();
    c.clear();
    s.clear();
    r1.clear();
    c1.clear();
    s1.clear();
    
   for(int i=0;i<k;i++)
   {
       int x,y;
       cin>>x>>y;
       r[x]++;
       c[y]++;
       r1[y]++;
       c1[x]++;
       s.insert({x,y});
       s1.insert({y,x});
   }
   
   int ans1=sol();
   int ans2=sol2();
   
   
   
   
  
   
   cout<<max(ans1,ans2)<<'\n';
   
   
   
   
}

int32_t main()
{
	ios::sync_with_stdio(false);
    cin.tie(NULL);
    
	int t=1;
//	cin>>t;
	while(t--)solve();
	    
   
}


Measured memory_bytes: 116168
#include<bits/stdc++.h>
#define all(v) (v).begin(),(v).end()
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define ri(x) scanf("%d",&(x))
#define ri2(x,y) scanf("%d %d",&(x),&(y))
#define ri3(x,y,z) scanf("%d %d %d",&(x),&(y),&(z))
#define rll(x) scanf("%lld",&(x))
#define rll2(x,y) scanf("%lld %lld",&(x),&(y))
#define rll3(x,y,z) scanf("%lld %lld %lld",&(x),&(y),&(z))
#define gc(x) ((x) = getchar())
using namespace::std;

const long double PI = acos(-1);
const long long MOD = 1000000000 +7;

typedef long long ll;
typedef pair<ll,ll> pll;
typedef pair<ll,pll> tll;
typedef pair<int,int> ii;
typedef pair<int,ii> iii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<iii> viii;
typedef vector<ll> vll;
typedef vector<pll> vpll;
typedef vector<tll> vtll;
typedef vector<string> vs;
typedef set<int> si;
typedef set<ii> sii;
typedef set<iii> siii;

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

ll add(ll a, ll b, ll m = MOD){
	if(a >= m) a %= m;
	if(b >= m) b %= m;
	if(a < 0) a += m;
	if(b < 0) b += m;
	ll res = a+b;
	if(res >= m or res <= -m) res %= m;
	if(res < 0) res += m;
	return res;
}

ll mul(ll a, ll b, ll m = MOD){
	if(a >= m) a %= m;
	if(b >= m) b %= m;
	if(a < 0) a += m;
	if(b < 0) b += m;
	ll res = a*b;
	if(res >= m or res <= -m) res %= m;
	if(res < 0) res += m;
	return res;
}

ll pow_mod(ll a, ll b, ll m = MOD){
	ll res = 1LL;
	a = a%m;
	while(b){
		if(b&1) res = mul(res,a,m);
		b >>= 1;
		a = mul(a,a,m);
	}
	return res;
}

ll fastexp(ll a, ll b){
	ll res = 1LL;
	while(b){
		if(b&1) res = res*a;
		b >>= 1;
		a *= a;
	}
	return res;
}

int gcdExtendido(int a, int b, int *x, int *y){
	if(a == 0){
		*x = 0;
		*y = 1;
		return b;
	}
	int x1, y1;
	int gcd = gcdExtendido(b%a,a,&x1,&y1);
	
	*x = y1-(b/a)*x1;
	*y = x1;
	return gcd;
}

int modInverso(int a, int m){
	int x, y;
	int g = gcdExtendido(a,m,&x,&y);
	if(g!=1) return -1;
	else return (x%m + m)%m;
}

/****************************************
*************P*L*A*N*T*I*L*L*A************
*****************************************/

const int MAX = 200000 + 5;
const int N = 100000+5;

int n;
int m;
vi G[N];
int D[N][3];
int pf[MAX];

void init(){
	for(int i=2; i<MAX; i++) pf[i] = i;
	for(int i=2; i*i <= MAX; i++){
		if(pf[i] == i){
			for(int j=i*i; j<MAX; j+=i) pf[j] = i;
		}
	}
}

void BFS(int src){
	memset(D,-1,sizeof D);
	D[src][0] = 0;
	queue<int> Q;
	Q.emplace(src);
	Q.emplace(0);
	while(!Q.empty()){
		int u = Q.front(); Q.pop();
		int c = Q.front(); Q.pop();
		for(int v : G[u]){
			int nc = c^1;
			if(D[v][nc] == -1){
				D[v][nc] = D[u][c] + 1;
				Q.emplace(v);
				Q.emplace(nc);
			}
		}
	}
}

int solve(int snk){
	if(D[snk][0] == 2) return 2;
	if(D[snk][1] == -1) return -1;
	int ans = D[snk][1];
	while(pf[ans] != ans) ans += 2;
	return ans;
}

int main(){
	ri2(n,m);
	int s, t;
	ri2(s,t);
	init();
	for(int i=0; i<m; i++){
		int u, v;
		ri2(u,v);
		G[u].emplace_back(v);
		G[v].emplace_back(u);
	}
	BFS(s);
	int ans = solve(t);
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 10712
def main():
    S = input()
    T = input()

    s1 = [ord(s) - ord('a') for s in S]
    t1 = [ord(t) - ord('a') for t in T]

    s1.sort()
    t1.sort(reverse=True)


    for i, j in zip(s1, t1):
        if i < j:
            print('Yes')
            return

    if (len(s1) < len(t1)) & (i > j):
        print('No')
        return
    elif (len(s1) < len(t1)):
        print('Yes')
        return

    print('No')

main()

Measured memory_bytes: 3064