akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#include<stdlib.h>
#include<stdint.h>
#include<inttypes.h>
#include<string.h>

typedef int32_t i32;

int cmp (const void *a, const void *b) {
  i32 d = *(i32 *)a - *(i32 *)b;
  return d == 0 ? 0 : d < 0 ? -1 : 1;
}

void run (void) {
  i32 n, k;
  scanf ("%" SCNi32 "%" SCNi32, &n, &k);
  i32 *a = (i32 *) calloc (n, sizeof (i32));
  for (i32 i = 0; i < n; ++i) {
    scanf ("%" SCNi32, a + i);
  }
  qsort (a, n, sizeof (i32), cmp);
  const i32 bit_num = 8 * sizeof (uint64_t);
  i32 len = (k + bit_num - 1) / bit_num;
  uint64_t *dp = (uint64_t *) calloc (len + 1, sizeof (uint64_t));
  i32 l = -1;
  i32 r = n;
  while (r - l > 1) {
    i32 m = (l + r) / 2;
    memset (dp, 0, sizeof (uint64_t) * len);
    dp[0] = 1;
    for (i32 i = 0; i < n; ++i) {
      if (i == m) continue;
      i32 p = a[i] / bit_num;
      i32 q = a[i] % bit_num;
      if (q == 0) {
        for (i32 i = len - 1 - p; i >= 0; --i) {
          dp[i + p] |= dp[i];
        }
        continue;
      }
      for (i32 i = len - 1 - p; i >= 0; --i) {
        uint64_t x = dp[i];
        dp[i + p] |= x << q;
        dp[i + p + 1] |= x >> (bit_num - q);
      }
    }
    i32 i = k - 1;
    for (; !(1 & (dp[i / bit_num] >> (i % bit_num))); --i);
    if (i + a[m] >= k) {
      r = m;
    } else {
      l = m;
    }
  }
  printf ("%" PRIi32 "\n", r);
}

int main (void) {
  run();
  return 0;
}


Measured memory_bytes: 252
val MOD = 1000000007L

fun main(args:Array<String>){
  var (n,m) = readLine()!!.split(" ").map(String::toInt)
  val a = BooleanArray(n+10){false}
  for(i in 0..m-1){
    a[readLine()!!.toInt()] = true
  }
  var dp = LongArray(n+10){0}
  dp[0] = 1
  for(i in 1..n+1){
    if(a[i]){
      dp[i] = 0
    }else{
      if(i<2){
        dp[i] = dp[i-1]
        continue
      }
      dp[i] = dp[i-1]+dp[i-2]
      dp[i] %= MOD
    }
  }
  println(dp[n])
}

Measured memory_bytes: 41224
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cassert>
#include <functional>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
using namespace std;
using llong = long long;

llong n, m;
llong a[100005];
llong b[100005];
llong c[100005];
pair<llong, llong> q[100005];


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

    for (int i = 0; i < m; i++) {
        cin >> b[i] >> c[i];
        q[i] = make_pair(c[i], b[i]);
    }

    sort(a, a + n);
    sort(q, q + m, greater<>());

    llong sum = 0;
    llong itr = 0;
    for (int i = 0; i < n; i++) {
        if (a[i] >= q[itr].first) {
            sum += a[i];
        }
        else {
            sum += q[itr].first;
            q[itr].second--;
            if (q[itr].second == 0) itr++;
        }
    }

    cout << sum << endl;

    return 0;
}


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

int main(){
  int N;
  cin >> N;
  int h;
  cin >> h;
  int hmax = h;
  int cnt = 1;
  for (int i = 1; i < N; i++) {
    cin >> h;
    if (h >= hmax){
      hmax = h;
      cnt++;
    };
  }
  cout << cnt << endl;
}

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

int n;
int d[100005];

int main(void){
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		scanf("%d",&d[i]);
	}
	sort(d,d+n);
	printf("%d\n",d[n/2]-d[(n/2)-1]);
	return 0;
}


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

int main() { 
    long long int n, k, a, b, sum = 0;
    cin >> n >> k;
    vector<pair<int, int>> ab;
    for(int i = 0; i < n; ++i) {
        cin >> a >> b;
        ab.push_back(make_pair(a, b));
    }
    sort(ab.begin(), ab.end());
    for(int i = 0; i < n; ++i) {
        k -= ab[i].second;
        if(k <= 0) {
            cout << ab[i].first << '\n';
            return 0;
        }
    }
}

Measured memory_bytes: 1400
pub fn read1<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

pub fn readn<T: std::str::FromStr>(delimiter: &str) -> Vec<T> {
    let s = read1::<String>();
    s.split(delimiter).map(|e| e.parse().ok().unwrap()).collect::<Vec<T>>()
}

fn main() {
    let n = read1::<usize>();
    let mut pos = (0..n).map(|_| {
        let xl = readn::<isize>(" ");
        (xl[0] - xl[1], xl[0] + xl[1])
    }).collect::<Vec<(isize, isize)>>();
    pos.sort_by(|a, b| (a.1).cmp(&b.1));

    let mut right = pos[0].0;
    let mut ans = 0;
    for p in pos.iter() {
        if p.0 >= right {
            right = p.1;
            ans += 1;
        }
    }

    println!("{}", ans);
}

Measured memory_bytes: 6396
#include<stdio.h>
#include<algorithm>
using namespace std;
int b[21];
int dp[1<<20];
int dx[]={1,3,4,5};
int dy[]={1,-1,0,1};
int solve(int a){
	if(~dp[a])return dp[a];
	if(a==0)return dp[a]=0;
	int now[20];
	int sz=0;
	for(int i=0;i<20;i++){
		if(a&(1<<i))now[sz++]=i;
	}
	int ret=sz;
	for(int i=0;i<sz;i++){
		for(int j=0;j<4;j++){
			if(i+dx[j]<sz&&i%4+dy[j]<4&&0<=i%4+dy[j]&&b[now[i]]==b[now[i+dx[j]]]){
				ret=min(ret,solve(a-(1<<now[i])-(1<<now[i+dx[j]])));
			}
		}
	}
	return dp[a]=ret;
}
int main(){
	int a;
	scanf("%d",&a);
	while(a--){
		for(int i=0;i<20;i++)scanf("%d",b+i);
		for(int i=0;i<(1<<20);i++)dp[i]=-1;
		printf("%d\n",solve((1<<20)-1));
	}
}

Measured memory_bytes: 5120
def d(a, b):
    return abs(a[0] - b[0]) + abs(a[1] - b[1])


n, m = map(int, input().split())
students = {}
check = {}
for i in range(1, n+1):
    x = list(map(int, input().split()))
    students[i] = x

for i in range(1, m+1):
    x = list(map(int, input().split()))
    check[i] = x

for i in range(1, n+1):
    st = students[i]
    b = 10**10
    ans = 0
    for j in range(1, m+1):
        if b > d(st, check[j]):
            b = d(st, check[j])
            ans = j
    print(ans)



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

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

    long long int ans = 0;
    for (int i = 0; i < n; ++i) {
        const int c = min(a[i], b[i]);
        b[i] -= c;
        ans += c;
        const int d = min(a[i+1], b[i]);
        a[i+1] -= d;
        ans += d;
    }
    /*
    for (int i = n-1; i >= 0; --i) {
        const int c = max(0, b[i] - a[i+1]);
        ans += b[i] - c;
        ans += min(a[i], c);
        a[i] = max(0, a[i] - c);
    }
    */
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1024
import java.util.*;

/**
 * Copyright © 2018 Chris. All rights reserved.
 *
 * @author Chris
 * 2018/7/5 22:51
 */
public class Main {

    final static int MOD = 1000000007;
    static Scanner sc;

    private static int comb(int n, int m) {
        return 1;
    }

    static void getDiv(Map<Integer, Integer> map, int n) {
        int sqrt = (int) Math.sqrt(n);
        for (int i = sqrt; i >= 2; i--) {
            if (n % i == 0) {
                getDiv(map, i);
                getDiv(map, n / i);
                return;
            }
        }
        map.put(n, map.getOrDefault(n, 0) + 1);
    }

    @SuppressWarnings("unchecked")
    private static void solve() {
        int n = nextInt();
        if (n == 1) {
            System.out.println("Yes");
            System.out.println(2);
            System.out.println("1 1");
            System.out.print("1 1");
            return;
        }
        int sum = n * 2;
        int m = (int) Math.sqrt(sum + 0.5);
        if (m * (m + 1) != sum) {
            System.out.print("No");
            return;
        }
        boolean ok = true;
//        int cnt[] = new int[n + 1];
        List<Integer>[] ans = new List[m + 2];
        for (int i = 1; i <= m + 1; i++) {
            ans[i] = new ArrayList<>();
        }
        for (int i = 1; i <= m; i++) {
            ans[1].add(i);
            ans[i + 1].add(i);
//            cnt[i] = 2;
        }
        int next = m + 1;
        for (int i = 2; i <= m + 1; i++) {
            for (int j = ans[i].size() + 1; j <= m; j++) {
//                cnt[next] = 2;
                ans[i].add(next);
                ans[j + 1].add(next);
                if (++next > n) {
                    break;
                }
            }
            if (next > n) {
                break;
            }
        }
        for (int i = 1; i <= m + 1; i++) {
            if (ans[i].size() != m) {
                ok = false;
                break;
            }
        }
        if (!ok) {
            System.out.print("No");
        } else {
            System.out.println("Yes");
            System.out.println(m + 1);
            for (int i = 1; i <= m + 1; i++) {
                System.out.print(m);
                for (int j = 0; j < m; j++) {
                    System.out.print(" " + ans[i].get(j));
                }
                if (i < m + 1) System.out.println();
            }
        }
    }

    static long gcd(long a, long b) {
        if (a < b) {
            a ^= b;
            b ^= a;
            a ^= b;
        }
        while (b != 0) {
            long tmp = a % b;
            a = b;
            b = tmp;
        }
        return a;
    }

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

    private static int nextInt() {
        return sc.nextInt();
    }

    private static long nextLong() {
        return sc.nextLong();
    }

    private static String next() {
        return sc.next();
    }

    private static double nextDouble() {
        return sc.nextDouble();
    }
}

Measured memory_bytes: 50200
#include<cstdio>
#include<map>
#include<queue>
#include<vector>
#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;
const int Maxn=1e5;
const int INF=0x3f3f3f3f;
int dis[6*Maxn+5];
int vis[6*Maxn+5];
struct Edge 
{
    int to,cost;
    Edge(int a,int b){to=a,cost=b;}
};
vector<Edge>way[6*Maxn+5];
void AddEdge(int u,int v,int w) 
{
    way[u].push_back(Edge(v,w));
    way[v].push_back(Edge(u,w));
}

void spfa(int s) 
{
    memset(dis,0x3f,sizeof dis);
    queue<int> q;
    q.push(s);
    vis[s]=1,dis[s]=0;
    while(!q.empty()) 
	{
        int u=q.front();
        q.pop();vis[u]=0;

        for(int i=0;i<way[u].size();i++) 
		{
            int v=way[u][i].to,w=way[u][i].cost;
            if(dis[v]>dis[u]+w) 
			{
                dis[v]=dis[u]+w;
                if(!vis[v]) 
				{
                    vis[v]=1;
                    q.push(v);
                }
            }
        }
    }
}

map<pair<int,int>,int>pos;
int cnt;
int Getid(int u,int c) 
{
    if(pos.find(make_pair(u,c))!=pos.end())
        return pos[make_pair(u,c)];
    return pos[make_pair(u,c)]=++cnt;
}
int t1,t2;
int N,M;
int u,v,c;
int main() 
{
    scanf("%d%d",&N,&M);
    cnt=N;
    for(int i=1;i<=M;i++) 
	{
        scanf("%d%d%d",&u,&v,&c);
        t1=Getid(u,c);
		t2=Getid(v,c);
        AddEdge(t1,t2,0);
        AddEdge(u,t1,1);
        AddEdge(v,t2,1);
    }
    spfa(1);
    if(dis[N]==INF)puts("-1");
    else printf("%d\n",dis[N]/2);
}


Measured memory_bytes: 62464
use std::io::prelude::*;
fn main() {
    let stdin = std::io::stdin();
    let mut input = stdin.lock().lines();
    let _: usize = (&input.next().unwrap().unwrap()).trim().parse().unwrap();
    let rates: Vec<u32> = input
        .next()
        .unwrap()
        .unwrap()
        .split_whitespace()
        .map(|a| a.parse().expect("parse error"))
        .collect();
    let (the_min, the_max) = solve(&rates);
    println!("{} {}", the_min, the_max);
}

fn solve(rates: &[u32]) -> (u32, u32) {
    let mut flags = vec![false; 8];
    let mut other_ratees = 0;
    for &rate in rates {
        if rate < 3200 {
            flags[(rate / 400) as usize] = true;
        } else {
            other_ratees += 1;
        }
    }
    let minimum = flags
        .iter()
        .fold(0, |acc, &e| if e { acc + 1 } else { acc });
    if minimum == 0 && other_ratees > 0 {
        (1, other_ratees)
    } else {
        (minimum, minimum + other_ratees)
    }
}


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

int main(){
    int n,m;
    cin >> n>>m;
    priority_queue<int> pq;
    rep(i,n){
        int a;
        cin>>a;
        pq.push(a);
    }
    rep(i,m){
        int b = pq.top(); pq.pop();
        b/=2;
        pq.push(b);
    }
    ll ans=0;
    rep(i,n){
        ans+=pq.top();pq.pop();
    }
    
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 892
#include <cstdio>
#define file(x) freopen(#x".in", "r", stdin), freopen(#x".out", "w", stdout)

const int N(4010), Mod(1e9 + 7);
int max(int x, int y) { return y < x ? x : y; }
int fac[N], inv[N], n, K;
int C(int n, int m) { return 1ll * fac[n] * inv[m] % Mod * inv[n - m] % Mod; }
int fastpow(int x, int y)
{
	int ans = 1;
	for (; y; y >>= 1, x = 1ll * x * x % Mod)
		if (y & 1) ans = 1ll * ans * x % Mod;
	return ans;
}

int main()
{
	scanf("%d%d", &n, &K), fac[0] = inv[0] = 1;
	for (int i = 1; i <= n + K; i++) fac[i] = 1ll * fac[i - 1] * i % Mod;
	inv[n + K] = fastpow(fac[n + K], Mod - 2);
	for (int i = n + K - 1; i; i--) inv[i] = 1ll * inv[i + 1] * (i + 1) % Mod;
	printf("%lld\n", 1ll * ((C(n + K - 2, K - 1) - C(n + K - 2, K - 2) + Mod) % Mod)
			* fastpow(2, max(0, n - K - 1)) % Mod);
	return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string S;
  cin >> S;
  string ans;
  
  if(S=="Sunny")
    ans = "Cloudy";
  else if(S=="Cloudy")
    ans = "Rainy";
  else
    ans = "Sunny";
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <numeric>
#include <algorithm>

using namespace std;

int numberOfTreasureChests; // 1 =< numberOfTreasureChests <= 12
int numberOfKeys;
vector<int> keys;
vector<int> costs;
vector<vector<int>> chest2key;

int allOpened;
int minCost0;

inline void insert(int& s,int k){
    s |= (1<<k);
}

int isElement(int e,int s){
    return ((1<<e) & s);
}

void setup(){
    cin >> numberOfTreasureChests;
    cin >> numberOfKeys;
    allOpened = (1 << numberOfTreasureChests) - 1;
    for(int i=0;i<numberOfTreasureChests;++i){
        chest2key.push_back(vector<int>());
    }
    for (int i = 0; i < numberOfKeys; ++i){
        int c;
        cin >> c;
        costs.push_back(c);
        int n; // How many chests can this key open?
        cin >> n;
        int key = 0;
        for (int j = 0; j < n; ++j){
            int v;
            cin >> v;
            insert(key,v-1);
            chest2key[v - 1].push_back(i);
        }
        keys.push_back(key);
    }
    minCost0 = accumulate(costs.begin(), costs.end(), 0);
    for(auto k:chest2key){
        sort(k.begin(), k.end(), [](int a, int b) { return costs[a] < costs[b];});
    }
}

void findAnswer(int chestId,int openedChests,int costSoFar){
    if (costSoFar > minCost0 || chestId > numberOfTreasureChests){ // これ以上探しても無駄
        return ;
    }
    if (openedChests == allOpened){ // 全ての箱が開けることができる
        if(costSoFar < minCost0){  // 今までの最小コストより、現在のコストが小さければ変更
            minCost0 = costSoFar;
        }
    }
    else if (isElement(chestId, openedChests))
    { // 既に、この箱は開けることができる
        // 次の箱をチェックする
        findAnswer(chestId + 1, openedChests, costSoFar);
    }else{
        for (int id = chestId; id < numberOfTreasureChests; ++id){
            for(auto k : chest2key[id]){
                int opened = openedChests | keys[k];
                int cost0 = costSoFar + costs[k];
                if(opened == allOpened){
                    minCost0 = min(minCost0, cost0);
                    //break;
                }
                else
                {
                    findAnswer(id + 1, opened, cost0);
                }
            }
        }
    }

}

int main(){
    setup();
    int k = accumulate(keys.begin(), keys.end(), 0, [](int acc, int v) {
        return acc | v;
    });
    if (k != allOpened){
        // We cannot open all chests.
        cout << -1 << endl;
    }else{
        findAnswer(0, 0, 0);
        cout << minCost0 << endl;
    }

    return 0;
}

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

const int N = 1e5 + 5;
int n;
int a[N], b[N];
int p[N];
int c[2 * N + 5];

int lowbit(int k) {return k & (-k);}

void Add(int k)
{
    for (int i = k; i <= 2 * N; i += lowbit(i))
        c[i]++;
}

long long Find(int k)
{
    long long sum = 0;
    for (int i = k; i != 0; i -= lowbit(i))
        sum += c[i];
    return sum;
}

long long Calc(int num)
{
    long long ans = 0;
    int sum = 0;
    memset(c, 0, sizeof(c));
    for (int i = 1; i <= n; i++)
    {
        if (a[i] >= num)
        {
            Add(-sum + N);
            sum++;
        }
        else
        {
            Add(-sum + N);
            sum--;
        }
        ans += Find(-sum - 1 + N);
    }
    return ans;
}

int main()
{
    scanf ("%d",&n);
    for (int i = 1; i <= n; i++)
    {
        scanf ("%d",&a[i]);
        b[i] = a[i];
    }
    sort(b + 1, b + 1 + n);
    int l = 1, r = n;
    while (l < r)
    {
        int mid = (l + r + 1) / 2;
        if (Calc(b[mid]) > 1ll * n * (n + 1) / 2 / 2) r = mid - 1;
        else l = mid;
    }
    printf ("%d",b[l]);
}


Measured memory_bytes: 1792
// they tried to make me write an inspirational code but i said, no no no
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cstring>
#include <cassert>
using namespace std;
#define rep(i,a,n) for (int i=a;i<(n);i++)
#define per(i,a,n) for (int i=(n)-1;i>=(a);i--)
typedef long long ll;

const int N = 2e5 + 10;

struct Edge {
    int a, b, c;
    Edge(int _a, int _b, int _c) : a(_a), b(_b), c(_c) {}
    Edge() {}
    
    int other(int at) {
        return (at == a) ? b : a;
    }
};

Edge e[N];
map<int, vector<int>> g[N];
map<int, int> dist[N];

int main() {
    ios_base::sync_with_stdio(false);
    int n, m;
    cin >> n >> m;
    
    rep(i, 0, m) {
        int a, b, c;
        cin >> a >> b >> c;
        a--, b--;
        if (a > b) swap(a, b);
        e[i] = Edge(a, b, c);
        g[a][c].push_back(i);
        g[b][c].push_back(i);
    }
    
    set<pair<int, pair<int, int>>> q;
    q.insert({0, {0, 0}});
    dist[0][0] = 1;
    
    auto update = [&](int next, int color, int distance) {
        if (!dist[next].count(color)
                || dist[next][color] > distance) {
            if (dist[next].count(color)) {
                q.erase({dist[next][color], {next, color}});
            }
            dist[next][color] = distance;
            q.insert({dist[next][color], {next, color}});
            //cout << next << " " << color << ": " << distance << endl;
        }
    };
    
    while (!q.empty()) {
        auto state = q.begin()->second;
        q.erase(q.begin());
        int cur = state.first;
        int curColor = state.second;
        
        if (cur == n - 1) {
            cout << dist[cur][curColor] << endl;
            return 0;
        }
        
        if (curColor == 0) {
            for (auto& nextColor : g[cur]) {
                for (auto x : nextColor.second) {
                    int next = e[x].other(cur);
                    update(next, nextColor.first, dist[cur][curColor]);
                    update(next, 0, dist[cur][curColor] + 1);
                }
            }
            g[cur].clear();
        } else {
            if (!g[cur].count(curColor)) continue;
            
            for (auto x : g[cur][curColor]) {
                int next = e[x].other(cur);
                update(next, curColor, dist[cur][curColor]);
                update(next, 0, dist[cur][curColor] + 1);
            }
            g[cur].erase(curColor);
        }
    }
    cout << -1 << endl;
    
    return 0;
}


Measured memory_bytes: 81024
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;

#define FOR(i,n) for(int i=0;i<n;i++)
#define PRINT(a) cout<<a<<"\n"
 
int main(){

	char s[20];

	cin>>s;

	FOR(i,5) cout<<s[i];
	cout<<" ";
	FOR(i,7) cout<<s[i+6];
	cout<<" ";
	FOR(i,5) cout<<s[i+14];

	

	return 0;
}

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

int main(){
  int w,d;

  while(cin >> w >> d , w | d){
    int left[w],right[d];

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

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

    sort(left,left+w);
    sort(right,right+d);

    int ans = 0;
    bool useW[w],useD[d];
    fill(useW,useW+w,true);
    fill(useD,useD+d,true);

    for(int i = 0 ; i < w ; i++){
      for(int j = 0 ; j < d ; j++){
	if(left[i] == right[j] && useW[i] && useD[j]){
	  ans += left[i];
	  useW[i] = false;
	  useD[j] = false;
	}
      }
    } 

    for(int i = 0 ; i < w ; i++){
      if(useW[i]){
	ans += left[i];
      }
    }

    for(int i = 0 ; i < d ; i++){
      if(useD[i]){
	ans += right[i];
      }
    }
    cout << ans << endl;
  }

  return 0;
}

Measured memory_bytes: 1180
t="abcdefghijklmnopqrstuvwxyz"
s=input()
if s==t[::-1]:print(-1);exit()
if len(s)!=26:
  for i in t:
    if i not in s:print(s+i);exit()
i=25
while s[i-1]>s[i]:i-=1
tt=s[i-1]
ss=list(s[i-1:])
ss.sort()
print(s[:i-1]+ss[ss.index(tt)+1])

Measured memory_bytes: 3064
using System;
using System.Collections.Generic;
using System.Linq;

namespace ConsoleApp1
{
	class Program
	{
		static void Main(string[] a_asArgs)
		{
			int[] l_aiInput = Console.ReadLine().Split(' ').Select(a => int.Parse(a)).ToArray();
			int l_iN = l_aiInput[0];
			int l_iM = l_aiInput[1];

			for (int l_iD = l_iM / l_iN; l_iD >= 1; l_iD--)
			{
				if (l_iM % l_iD == 0)
				{
					Console.WriteLine(l_iD);
					break;
				}
			}
		}
	}
}


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

//--> definitions
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define RFOR(i,a,b) for(int i=b-1;i>=a;i--)

//--> typedef
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<int,ll> pil;
typedef pair<pii,int> piii;
typedef tuple<int,int,int> tiii;

#define MP make_pair
#define PB push_back
#define fi first
#define se second
#define INF 1e9

const int maxN = 2e5+11;
const int mod = 1e9+7;

ll a[maxN];
ll sum=0;

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

    int n;
    cin>>n;
    
    FOR(i,0,n){
        cin>>a[i];
        sum = (sum+ a[i])%mod;
    }
    
    ll ans=0;
    FOR(i,0,n-1){
        sum=(sum-a[i])%mod;
        if(sum<0)
            sum=(sum+mod);
        ans =(ans+ ((a[i] * sum)%mod))%mod;
    }
    
    cout<<ans<<"\n";
    
	return 0;
}

Measured memory_bytes: 5204
#include <iostream>
#include <vector>
using namespace std;
int H,W;
int main(int argc, char* argv[])
{
	cin>>H>>W;
	vector<vector<int>> c(10,vector<int>(10)); 
	vector<vector<int>> A(H,vector<int>(W));
	int i,j,k;
	for (i=0;i<10;i++){
		for (j=0;j<10;j++){
			cin>>c[i][j];
		}
	}
	bool One=true;
	for (i=0;i<H;i++){
		for (j=0;j<W;j++){
			cin>>A[i][j];
			if (A[i][j]==1 || A[i][j]==-1){
			}else{
				One=false;
			}
		}
	}
	if (One){
		cout<<0<<endl;
		return 0;
	}
	for (k=0;k<10;k++){
		for (i=0;i<10;i++){
			for (j=0;j<10;j++){
				if (c[i][j]>c[i][k]+c[k][j]){
					c[i][j]=c[i][k]+c[k][j];
				}
			}
		}
	}

	int aw=0;
	for (i=0;i<H;i++){
		for (j=0;j<W;j++){
			if (A[i][j]!=-1 && A[i][j]!=1){
				aw+=c[A[i][j]][1];
			}
		}
	}
	cout<<aw<<endl;
	return 0;
}

Measured memory_bytes: 384
#include<iostream>
#include<algorithm>
using namespace std;
int main() {
	int n, q;
	cin >> n;
	int s[100005];
	int t[100005];
	for (int i = 0; i < n; i++) {
		cin >> s[i];
	}
	cin >> q;
	for (int i = 0; i < q; i++) {
		cin >> t[i];
	}
	int count = 0;
	for (int i = 0; i < q; i++) {
		int l = 0;
		int r = n;
	  while (l < r) {
		int mid = (l + r) / 2;
			if (s[mid] == t[i]) {
				count++;
				break;
			}
			else if (s[mid] <= t[i]) {
				l = mid + 1;
			}
			else {
				r = mid;
			}
	  }
	}
	cout << count << endl;
	return 0;    
}


Measured memory_bytes: 3688
A,B = list(map(int, input().split()))
ans = 10e7
is_true = False
for i in range(1,1010):
    a = int(i*0.08)
    b = int(i*0.10)
    if a == A and b == B:
        ans = min(ans, i)
        is_true = True
if is_true:
    print(ans)
else:
    print(-1)



Measured memory_bytes: 9120
#include <iostream>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <unordered_map>
#include <random>
#include <queue>

#define BIG 998244353
#define LLMAX 9223372036854775807
#define LLMIN (-9223372036854775808)
#define long long long

using namespace std;


int main() {
    int n;
    cin >> n;
    vector<long> a(n,0);
    bool isOdd = false;
    long sum = 0;
    long min = LLMAX;
    for(int i = 0;i < n;++i){
        cin >> a[i];
        if(a[i] < 0)isOdd = !isOdd;
        long ab = abs(a[i]);
        if(ab < min)min = ab;
        sum += ab;
    }
    if(isOdd)sum -= min * 2;
    cout << sum << endl;
}



Measured memory_bytes: 1024
s = input()
n = len(s)-1
a=0
for i in range(2**n):
  f = s[0]
  for j in range(n):
    
    if ((i >> j) &1):
      f += "+"
    f += s[j+1]
  a += sum(map(int,f.split("+")))
      
print(a)

Measured memory_bytes: 9184
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace divertaPCBX
{
    class Program
    {
        static void Main(string[] args)
        {
            int ans = 0;
            int AB = 0;
            int BA = 0;
            int BX = 0;
            int XA = 0;
            int N = int.Parse(Console.ReadLine());
            string[] s = new string[N];
            for (int i = 0; i < N; i++)
            {
                s[i] = Console.ReadLine();
                for (int j = 0; j < s[i].Length - 1; j++)//ABの個数
                {
                    if (s[i][j] == 'A' && s[i][j + 1] == 'B')
                    {
                        AB++;
                    }
                }
                //Console.WriteLine(AB);
                if (s[i].Substring(0, 1) == "B")
                {
                    if (s[i].Substring(s[i].Length - 1, 1) == "A")
                    {
                        BA++;//"BA"
                    }
                    else
                    {
                        BX++;//"BX"
                    }
                }
                else if (s[i].Substring(s[i].Length - 1, 1) == "A")
                {
                    XA++;//"XA"
                }
            }
            //Console.WriteLine(AB+" "+BA+" "+BX+" "+XA);
            if (BA > 0 && BX == 0 && XA == 0)//BAだけの時
            {
                ans = AB + BA - 1;
            }
            if (BA > 0 && BX == 0 && XA > 0)//XAとBA
            {
                ans = AB + BA;
            }
            if (BA > 0 && BX > 0 && XA == 0)//BAとBX
            {
                ans = AB + BA;
            }
            if (XA > 0 && BA > 0 && BX > 0)
            {
                ans = AB + BA + 1 + Math.Min(XA - 1, BX - 1);
            }
            if (BA == 0 && BX > 0 && XA > 0)
            {
                ans = AB + Math.Min(XA, BX);
            }
            if (BA == 0 && BX == 0 && XA == 0)//ABだけのとき
            {
                ans = AB;
            }
            if (BA == 0 && BX > 0 && XA == 0)
            {
                ans = AB;
            }
            if (BA == 0 && BX == 0 && XA > 0)
            {
                ans = AB;
            }
            Console.WriteLine(ans);
        }
    }
}


Measured memory_bytes: 13216
#ifdef LOCAL
#define _GLIBCXX_DEBUG
#endif
#include<bits/stdc++.h>
#include <atcoder/all>
using namespace atcoder;
using namespace std;
#define rep(i,s,t) for(ll i = (ll)(s); i < (ll)(t); i++)
#define rrep(i,s,t) for(ll i = (ll)(s-1);(ll)(t) <= i; i--)
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> Pll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vvl> vvvl;
constexpr ll INF = numeric_limits<ll>::max()/4;
constexpr ll n_max = 2e5+10;
#define int ll

template <typename A, typename B>
string to_string(pair<A, B> p);
string to_string(const string &s) {return '"' + s + '"';}
string to_string(const char *c) {return to_string((string) c);}
string to_string(bool b) {return (b ? "true" : "false");}
template <size_t N>
string to_string(bitset<N> v){
    string res = "";
    for(size_t i = 0; i < N; i++) res += static_cast<char>('0' + v[i]);
    return res;
}
template <typename A>
string to_string(A v) {
    bool first = true;
    string res = "{";
    for(const auto &x : v) {
        if(!first) res += ", ";
        first = false;
        res += to_string(x);
    }
    res += "}";
    return res;
}
template <typename A, typename B>
string to_string(pair<A, B> p){return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";}

void debug_out() {cerr << endl;}
template<typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
    cerr << " " << to_string(H);
    debug_out(T...);
}

#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

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

signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    ll n,m; cin >> n >> m;
    vector<ll> a(n);
    for(int i = 0; i < n; i++) cin >> a[i];
    vector<ll> b(m);
    for(int i = 0; i < m; i++) cin >> b[i];
    auto c = convolution(a, b);

    for(auto &i : c){
        cout << i << " ";
    }
    cout << "\n";
}

Measured memory_bytes: 27204
#include <iostream>
#include <cstdio>
#include <cmath>
using namespace std;

int main() {
    int N;
    cin >> N;
    int a, b, c;
    while (N--) {
        cin >> a >> b >> c;
        int l=max(a,max(b,c));
        int x, y;
        if (a==l) {
            x=b; y=c;
        } else if (b==l) {
            x=a; y=c;
        } else if (c==l) {
            x=a; y=b;
        }
        if (l==sqrt(pow(x,2)+pow(y,2))) {
            printf("YES\n");
        } else {
            printf("NO\n");
        }
    }
    return 0;
}

Measured memory_bytes: 2972
N = int(input())
S = input()

words = [chr(i) for i in range(65, 65+26)]
words2 = [chr(i) for i in range(65, 65+26)] * 2
for i in range(len(S)):
    ind = words.index(S[i]) + N
    print(words2[ind],end="")

Measured memory_bytes: 42456
#include <bits/stdc++.h>
#define fst first
#define snd second
#define pb push_back
#define IO ios_base::sync_with_stdio(0); cin.tie(0);
#define endl '\n'
#define mod 1000000007
using namespace std;

long long binexp(const long long &base, long long pot){
	if(pot == 0LL)
		return 1LL;
	if(pot == 1LL)
		return base;
	
	long long r = binexp(base,pot/2);
	r = (r*r)%mod;
	if(pot%2LL == 1LL)
	 r = (r*base)%mod;
	return r;
}

long long fact[200005];

long long comb(const long long &n, const long long &k){
	return (fact[n]*binexp(((fact[n-k]*fact[k])%mod),mod-2))%mod;
}


long long h,w,a,b;


int main()
{
	IO
	cin>>h>>w>>a>>b;
	fact[0] = 1;
	for(long long i = 1; i <= 200000; ++i)
		fact[int(i)] = (fact[int(i)-1]*i)%mod;
	
	long long limitr = h-a;
	long long limitc = w-b;
	
	long long res = 0;
	
	for(long long i = b+1; i <= w; ++i){
		//cout<<"comb "<<h-limitr+(limitc-(i-b))-1<<" "<<limitc-(i-b)<<endl;
		res = (res+(comb(limitr-2LL+i,i-1LL)*comb(h-limitr+(limitc-(i-b))-1,limitc-(i-b)))%mod)%mod;
		//cout<<comb(limitr-2LL+i,i-1LL)<<" "<<comb(h-limitr+(limitc-(i-b))-1,limitc-(i-b))<<endl;
	
	}	//cout<<endl;
	
	cout<<res<<endl;
	

	return 0;
}

Measured memory_bytes: 1792
#include <algorithm>
#include <array>
#include <bitset>
#include <complex>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <queue>

using namespace std;

struct BoolName : numpunct<char> {
  string t, f;
  BoolName (string t = "Yes", string f = "No") : t(t), f(f) {}
  string do_truename() const {return t;}
  string do_falsename() const {return f;}
};

struct Initializer {
  Initializer() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout << fixed << setprecision(15) << boolalpha;
    cout.imbue(locale(cout.getloc(), new BoolName));
  }
} initializer;

template<typename T> istream& operator>>(istream &s, vector<T> &v) {
  for (T &t : v) s >> t;
  return s;
}

template<typename T> ostream& operator<<(ostream &s, const vector<T> &v) {
  for (const T &t : v) s << t << endl;
  return s;
}

void set_bool_name(string t, string f) {
  cout.imbue(locale(cout.getloc(), new BoolName(t, f)));
}

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

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

template<typename T> void sort(vector<T>& v) {sort(v.begin(), v.end());}

int main() {
  int64_t n, k, res = 0;
  cin >> n >> k;
  if (k == 0) {
    cout << n * n << endl;
    return 0;
  }
  for (int b = k + 1; b <= n; ++b) {
    res += n / b * (b - k) + max(n % b - k + 1, int64_t(0));
  }
  cout << res << endl;
}



Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;


int main(void) {
    cin.tie(0); ios::sync_with_stdio(false);
    string s; cin >> s;
    cout << count(s.begin(),s.end(),'1') << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i, n) for(int i = 0;i < (int)n;i++)
#define repb(i, n) for(int i = (int)n;i >= 0;i--)
#define reps(i, m, n) for(int i = (int)m;i < (int)n;i++)
#define repsb(i, m, n) for(int i = (int)m;i >= (int)n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define pb(a) push_back(a)
#define INF 999999999999999999
using namespace std;
int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};
using namespace std;
int main(int argc, char const *argv[]) {
    string s;
    long long int cnt=0,step=0;
    cin>>s;
    rep(i,s.size()){
        if(s[i]=='W'){
          cnt+=i-step;
          step++;
        }

    }
    cout<<cnt<<endl;
    return 0;
}


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

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

  vector<string> s(N);
  vector<int> t(N);
  rep(i, N) {
    cin >> s[i];
    cin >> t[i];
  }
  string X;
  cin >> X;

  int ans = 0;
  bool sleep = false;
  rep(i, N) {
    if (sleep) ans += t[i];
    if (s[i] == X) sleep = true;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3640
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);
    String line = null;
    
    line = scanner.nextLine();
    long oniPlace = Integer.parseInt(line.split(" ")[0]);
    long oniWalk = Integer.parseInt(line.split(" ")[1]);

    line = scanner.nextLine();
    long playerPlace = Integer.parseInt(line.split(" ")[0]);
    long playerWalk = Integer.parseInt(line.split(" ")[1]);
    
    long sec = Integer.parseInt(scanner.nextLine());


    long oniMove = (sec * oniWalk);
    long playerMove = (sec * playerWalk);

    
    if (oniPlace < playerPlace) {
	  oniPlace += oniMove;
      playerPlace += playerMove;
      if (oniPlace >= playerPlace) {
      	System.out.println("YES");
      } else {
      	System.out.println("NO");
      }
    } else {
	  oniPlace -= oniMove;
      playerPlace -= playerMove;
      if (oniPlace <= playerPlace) {
      	System.out.println("YES");
      } else {
      	System.out.println("NO");
      }
    }
    
    
  }
}


Measured memory_bytes: 35756
#include <bits/stdc++.h>
typedef long long ll;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REP2(i, a, b) for(int i = a;i <= b;i++)
#define REPR(i, a, b) for(int i = a; i >= b; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e12
#define MOD 1000000007
#define PI 3.14159265358979323846
#define vi vector<int>
#define vll vector<ll>
#define vi2 vector<vector<int>>
#define eb emplace_back
#define fi first
#define se second
#define ALL(v) v.begin(), v.end()
#define sz(x) int(x.size())
using namespace std;
using P = pair<ll,ll>;
const int dx[]{0, 1, 0, -1, -1, -1, 1, 1}, dy[]{1, 0, -1, 0, -1, 1, -1, 1};
#define INT(name) int name;cin >> name;
#define VEC(type,name,n) vector<type> name(n);REP(i,n) cin >> name[i];

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;
}
const int mod = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}
int main()
{
  ll N;
  cin >> N;
  VEC(ll,T,N);
  VEC(ll,A,N);

  vector<ll> MAX(N,INF);
  vector<ll> MIN(N,1);
  MAX[0]=T[0];
  MIN[0]=T[0];
  REP(i,N-1){
    if(T[i+1]>T[i]){
      MAX[i+1]=T[i+1];
      MIN[i+1]=T[i+1];
    }else{
      if(MAX[i+1]>T[i+1]){
        MAX[i+1]=T[i+1];
      }
    }
  }
  if(MAX[N-1]<A[N-1]||MIN[N-1]>A[N-1]){
    cout << 0 << endl;
    return 0;
  }
  MAX[N-1]=A[N-1];
  MIN[N-1]=A[N-1];
  REPR(i,N-2,0){
    if(A[i+1]<A[i]){
      if(A[i]>MAX[i]||A[i]<MIN[i]){
        cout << 0 << endl;
        return 0;
      }
      MAX[i]=A[i];
      MIN[i]=A[i];
    }else{
      if(MAX[i]>A[i]){
        MAX[i]=A[i];
      }
    }
  }

  mint ans = 1;
  REP(i,N){
    ans*=(MAX[i]-MIN[i]+1);
  }

  cout << ans << endl;
}

Measured memory_bytes: 6352
#include<bits/stdc++.h>
using namespace std;
int gcd(int x, int y)
{
    if(y == 0)
        return x;
    return gcd(y, x % y);
}
int main(){
	long long a,b,c,d;
	cin>>a>>b>>c>>d;
	long long cha=b-a+1;
	long long cc=c-((a-1)%c+1)+a;
	long long ccc=b-(b%c);
	long long dd=d-((a-1)%d+1)+a;
	long long ddd=b-(b%d);
	long long e=c*d/gcd(c,d);
	long long ee=e-((a-1)%e+1)+a;
	long long eee=b-(b%e);
	long long cccc=(ccc-cc)/c+1; 
	long long dddd=(ddd-dd)/d+1; 
	long long eeee=(eee-ee)/e+1; 
//	cout<<cccc<<endl<<dddd<<endl<<eeee<<endl;
	cout<<cha-cccc-dddd+eeee<<endl;
	return 0;
}

Measured memory_bytes: 256
import sys
from collections import deque
import copy
ns = lambda: sys.stdin.readline().rstrip()
ni = lambda: int(ns())
nm = lambda: map(int, sys.stdin.readline().split())
nl = lambda: list(nm())
nsm = lambda: map(str, sys.stdin.readline().split())

n, k = nm()
v = nl()
d = deque(v)
ans = 0
for m in range(k + 1):
    for p in range(m + 1):
        lis = copy.copy(d)
        neg = []
        summ = 0
        for i in range(p):
            if len(lis) == 0:
                break
            l = lis.popleft()
            summ += l
            if l < 0:
                neg.append(l)
        for j in range(m - p):
            if len(lis) == 0:
                break
            l = lis.pop()
            summ += l
            if l < 0:
                neg.append(l)
        neg.sort()
        for o in range(k - m):
            if o < len(neg):
                summ -= neg[o]
            else:
                break
        ans = max(ans, summ)
print(ans)


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

int main(){
    int n;
    cin >> n;
    bool ok =false;
    for(int i=1; i<10; i++){
        if(n%i==0&&n/i<10){
            ok=true;
            break;
        }
    }
    if(ok) puts("Yes");
    else puts("No");
    return 0;
}

Measured memory_bytes: 256
// C.

#include <iostream>
#include <sstream>
#include <algorithm>
#include <vector>

using namespace std;

template <class T> void update_max(T &a, const T &b) { a = max(a, b); }
template <class T> bool update_min(T &a, const T &b) { a = min(a, b); }

int main(int argc, char *argv[]) {
	int x = 1, y = 2;
	x=min(x, y);

	int n;
	cin >> n;
	string s;
	cin >> s;
	int dp[2] = {};
	for (char c : s) {
		int a = dp[0], b = dp[1];
		if (c == '.') {
			dp[0] = a;
			dp[1] = b + 1;
		} else {
			dp[0] = a + 1;
			dp[1] = min(a, b);
		}
	}
	int ans = min(dp[0], dp[1]);
	cout << ans << endl;
	return 0;
}


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

l mod = 1e9 + 7;
void add_self(int &a, int b)
{
    long long int t = a;
    t += b;
    t %= mod;
    a = t;
}

void sub_self(int &a, int b)
{
    a -= b;
    if (a < 0)
        a += mod;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    // all the code goes here
    int n, k;
    cin >> n >> k;

    int dp[k + 1];
    memset(dp, 0, sizeof(dp));
    dp[0] = 1;

    for (int child = 0; child < n; child++)
    {
        int upto;
        cin >> upto;
        vector<int> f(k + 1, 0);
        for (int used = k; used >= 0; used--)
        {
            int l = used + 1;
            int r = used + min(upto, k - used);
            if (l <= r)
                add_self(f[l], dp[used]);
            if (r + 1 <= k)
                sub_self(f[r + 1], dp[used]);
        }

        int psum = 0;
        for (int i = 0; i <= k; i++)
        {
            add_self(psum, f[i]);
            add_self(dp[i], psum);
        }
    }

    cout << dp[k] << "\n";
    return 0;
}

Measured memory_bytes: 1024
N,Q = map(int,input().split())
S = input()
ansers = [0] * (N+1)
for i in range(N):
    ansers[i+1] = ansers[i] + (1 if S[i:i+2] == 'AC' else 0)
for q in range(Q):
    l,r = map(int,input().split())
    print(ansers[r-1] - ansers[l-1])


Measured memory_bytes: 9540
import sys
read = sys.stdin.buffer.read
input = sys.stdin.readline
input = sys.stdin.buffer.readline


#sys.setrecursionlimit(10**9)
#from functools import lru_cache

def RD(): return sys.stdin.read()
def II(): return int(input())
def MI(): return map(int,input().split())
def MF(): return map(float,input().split())
def LI(): return list(map(int,input().split()))
def LF(): return list(map(float,input().split()))
def TI(): return tuple(map(int,input().split()))
# rstrip().decode('utf-8')


#import numpy as np

def main():
	s=input().decode()

	ans="Yes"

	if s[2]!=s[3] or s[4]!=s[5]:
		ans="No"

	print(ans)




if __name__ == "__main__":
	main()

Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <cstdio>
#include <cmath>
#include <algorithm>
using namespace std;

int main (){
    int n;
    cin >> n;
    int a[n],b,c;
    for(int i=0;i<n;i++){
        cin >> a[i];
    }
    b=a[0];c=-1000000000;
    for(int i=1;i<n;i++){
        c=max(c,a[i]-b);
        b=min(b,a[i]);
    }
    cout << c << endl;
    }


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

constexpr int64_t mod = 2019;

int main() {
    string s;
    cin >> s;

    int64_t len = s.length();
    
    vector<int64_t> t(len, 0);
    int64_t num = 0;
    int64_t digit = 1;
    for(int i = len - 1; i >= 0; i--) {
        int d = s[i] - '0';
        d *= digit;
        d %= mod;
        num += d;
        num %= mod;
        t[len - i - 1] = num;
        digit *= 10;
        digit %= mod;
    }

    vector<int64_t> mod_num(mod, 0);
    for(int i = 0; i < len; i++) mod_num[t[i]]++;

    int64_t ans = mod_num[0];
    for(int i = 0; i < mod; i++) {
        if(mod_num[i] > 1) ans += mod_num[i] * (mod_num[i] - 1) / 2;
    }

    // for(int i = 0; i < mod; i++) {
    //     if(mod_num[i] > 0) cout << i << ": " << mod_num[i] << endl;
    // }

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

Measured memory_bytes: 5184
n = gets.to_i
ans = Float::INFINITY
(1..n/2).each do |i|
  _ans = 0
  i.to_s.chars{|a| _ans += a.to_i}
  (n-i).to_s.chars{|a| _ans += a.to_i}
  ans = _ans if _ans < ans
end
puts ans


Measured memory_bytes: 1788
#include <algorithm>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <queue>
#include <stack>
#include <utility>
#include <vector>
using std::cin;
using std::cout;
using std::endl;

int main(void) {

    int n, m, q;
    cin >> n >> m >> q;
    int train[501][501] = {};
    int cum[501][501]   = {};

    int m1, m2;
    for (int i = 0; i < m; i++) {
        // cin >> m1 >> m2;
        scanf("%d%d", &m1, &m2);
        train[m1][m2]++;
    }
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= n; j++) {
            cum[i][j] = cum[i][j - 1] + train[i][j];
        }
    }

    int a, b;
    int answer = 0;
    for (int i = 0; i < q; i++) {
        answer = 0;
        // cin >> a >> b;
        scanf("%d%d", &a, &b);
        for (int j = a; j <= b; j++) {
            answer += cum[j][b];
        }
        // cout << answer << endl;
        printf("%d\n", answer);
    }

    return 0;
}


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

int main() {
  
  int N,n;
  cin >> N;
  for (int i = 0; i < N; i++) {
    int l,r;
    cin >> l >> r;
    for (int j = l; j <= r; j++) {
      n++;
    }
  }
  cout << n << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define fo(i,a,b) for(register int (i)=(a);(i)<=(b);++(i))
#define rd read()
#define maxn 200001
#define gc getchar()
#define mem(a,b) memset(a,b,sizeof(a))
#define mp make_pair
#define ll long long
#define ull unsigned ll
#define pb push_back
#define db double
#define pu puts(" ")
using namespace std;
const int p=998244353;
int read()
{
	int x=0,f=1;
	char ch=gc;
	while(!isdigit(ch))
	{
		if(ch=='-')f=-1;
		ch=gc;
	}
	while(isdigit(ch))x=x*10+ch-48,ch=gc;
	return x*f;
}
void print(int x)
{
	if(x<0)putchar('-'),x=-x;
	if(x>9)print(x/10);
	putchar(x%10+48);
}
int qp(int a,int b)
{
	int ans=1;
	while(b)
	{
		if(b&1)ans=(ll)ans*a%p;
		a=(ll)a*a%p;
		b>>=1;
	}
	return ans;
}

int main()
{
   
	printf("%d\n",(rd-2)*180);
	return 0;
}

Measured memory_bytes: 256