akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <iomanip>//setprecision
#include<math.h>
#include <functional>
#include<climits>
using namespace std;
#define ll  long long 
#define rep(i, n)        for(ll i=0; i<(ll)(n); ++i)
#define mod 1000000007
  vector<ll>to[1000005];
int main(){
  ll a,b,c,d,e,f;
  cin>>a>>b>>c>>d;
  e=a+b;
  f=c+d;
  if(e>f)cout<<"Left";
  else if(e==f)cout<<"Balanced";
  else cout<<"Right";
  }


Measured memory_bytes: 23680
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using static System.Math;

namespace AtCorder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            var l = Console.ReadLine()
               .Split(' ')
               .Select(int.Parse)
               .ToArray();
            var n = l[0];
            var k = l[1];
            var s = Console.ReadLine();
            var s2 = new string(s
                .Select((c, i) => (i + 1 == k) ? (char)(c - 'A' + 'a') : c)
                .ToArray());
            Console.WriteLine(s2);
        }
    }
}


Measured memory_bytes: 13396
#include <iostream>
#include <string>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
using namespace std;

typedef long long ll;
#define rep(i, n) for(int i = 0; i < n; i++)

int main(){
    int N;
    cin >> N;
    string S;
    cin >> S;
    int Rcnt = 0;
    rep(i, N){
        if(S[i] == 'R') Rcnt++;
    }
    int ans = 0;
    for(int i = Rcnt; i < N; i++){
        if(S[i] == 'R') ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3752
#include<iostream>
#include<algorithm>
int n,d[30000];

bool bh(int i,int j,int k){
    if (d[i]<d[j]+d[k]){
        return true;
    }
    return false;
}

int main(){
    std::cin>>n;
    for (int i=1;i<=n;i++){
        std::cin>>d[i];
    }
    int sl=0;
    std::sort(d+1,d+n+1);
    for (int i=1;i<=n-2;i++){
        for (int j=i+1;j<=n-1;j++){
            for (int k=j+1;k<=n;k++){
                if ((bh(i,j,k)) && (bh(j,k,i)) && (bh(k,i,j))){
                sl++;}
                else break;
            }
        }
    }
    std::cout<<sl;
    return 0;
}

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

int main() {
  string s1,s2,s3;
  cin >> s1 >> s2 >> s3;
  cout << s1[0] << s2[0] << s3[0] << endl;
  return 0;
}


Measured memory_bytes: 256
const main = stdin => {
    const input = stdin.trim().split('\n')
    //ここにかく
    //文字列S
    const S = input[0].split(" ")[0];
    let result0 = [];
    let result1 = [];
    // const N = S.length;
    for (let i=0; i<S.length; i++){
        if (S[i] == 0){
        result0.push(0);
        }
        else{
        result1.push(1);
        }
    }
  
    let vanishN;
    if (result0.length<result1.length){
        vanishN = result0.length*2;
    }else{
        vanishN = result1.length*2
    }
console.log(vanishN);
}
    
    
    // 標準入力
    main(require("fs").readFileSync("/dev/stdin", "utf8"))

Measured memory_bytes: 35144
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n,x,t;
	cin >> n >> x >> t;
	cout << ((n+x-1)/x) * t << "\n";
}


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

using namespace std;

typedef long long ll;

const int INF = 1e9;
const ll LLINF = 1e18;
const ll MOD = (ll)1e9 + 7;

int main()
{
  int N, LIM; scanf("%d %d", &N, &LIM);
  vector<int> W(N), V(N);
  for (int i = 0; i < N; ++i) {
    scanf("%d %d", &W[i], &V[i]);
  }

  vector<vector<ll>> dp(N + 5, vector<ll>(305, 0));
  int sum = 0;
  for (int i = 0; i < N; ++i) {
    int diff = W[i] - W[0];
    sum += diff;
    for (int p = i + 1; p >= 1; --p) {
      for (int j = 0; j <= sum; ++j) {
        if (j - diff >= 0) {
          dp[p][j] = max(dp[p][j], dp[p - 1][j - diff] + V[i]);
        }
      }
    }
  }

  ll ans = 0;
  for (int i = 1; i <= N; ++i) {
    for (int j = 0; j <= sum; ++j) {
      if (1LL* i * W[0] + j <= LIM and dp[i][j] != LLINF) {
        ans = max(ans, dp[i][j]);
      }
    }
  }
  printf("%lld\n", ans);
  return 0;
}


Measured memory_bytes: 512
#include <algorithm>
#include <bitset>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#define repd(i, a, b) for (ll i = (a); i < (b); i++)
#define rep(i, n) repd(i, 0, n)
typedef long long ll;

using namespace std;

template <typename T> void output(T, int);
int gcd(int a, int b);

int main() {
    // source
    ll x, y;
    cin >> x >> y;
    if (abs(x - y) <= 1) {
        cout << "Brown" << endl;
    } else {
        cout << "Alice" << endl;
    }
    return 0;
}

template <typename T> void output(T a, int precision) {
    if (precision > 0) {
        cout << setprecision(precision) << a << "\n";
    } else {
        cout << a << "\n";
    }
}

template <typename T> T min(T a, T b) {

    if (a < b) {
        return a;
    } else {
        return b;
    }
}

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


Measured memory_bytes: 256
const fs = require('fs')
const stdin = fs.readFileSync('/dev/stdin', 'utf8')

const input = stdin.split('\n')

const [N, K] = input[0].split(' ').map(Number)
const S = input[1].split('')

const is0Start = S[0] === '0'
const is0End = S[S.length - 1] === '0'

let tmp = []

if (is0Start) {
  tmp = [0]
}

let count = 0
for (let i = 0; i < S.length; i++) {
  if (S[i] === S[i - 1] || i === 0) {
    count++
  } else {
    tmp[tmp.length] = count
    count = 1
  }
}

tmp[tmp.length] = count

if (is0End) {
  tmp[tmp.length] = 0
}

let cSumTmp = [0]

for (let i = 0; i < tmp.length; i++) {
  cSumTmp[i+1] = cSumTmp[i] + tmp[i]
}

let max = 0

for (let i = 0; i < cSumTmp.length; i += 2) {
  const right = Math.min(i + 2 * K + 1, cSumTmp.length - 1)
  const left = i

  const sum = cSumTmp[right] - cSumTmp[left]

  max = max > sum ? max : sum
}

console.log(max)


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

int main(){
  int n, c, a[30], b[31];
  while(cin >> n >> c, n){
    for(int i = 0; i < n; i++){
      a[i] = 0;
      for(int j = 0; j < 16; j++){
        int aa;
        cin >> aa;
        if(aa) a[i] |= 1 << j;
      }
    }
    for(int i = 0; i < c; i++){
      b[i] = 0;
      for(int j = 0; j < 16; j++){
        int bb;
        cin >> bb;
        if(bb) b[i] |= 1 << j;
      }
    }
    b[c] = 0;
    c++;
    

    int dp[31][1 << 16];
    fill_n( *dp, 31 * (1 << 16), -1);
    dp[0][0] = 0;
    int ret = 0;
    for(int i = 0; i < n; i++){ //今押している所
      for(int j = 0; j < 1 << 16; j++){ //前のbitの状態
        if(dp[i][j] == -1) continue;
        for(int k = 0; k < c; k++){
          int bits = (a[i]|j)&~b[k];
          dp[i + 1][bits] = max( dp[i + 1][bits], dp[i][j] + __builtin_popcount((a[i]|j) & b[k]));
          ret = max( dp[i + 1][bits], ret);
        }
      }
    }
    cout << ret << endl;
  }
}

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

using namespace std;


#define PI 3.14159265
#define int long long



main(){


	int n, k; cin >> n >> k;

	int r, s, p; cin >> r >> s >> p;

	string t; cin >> t;

	int ans = 0;

	for(int i = 0; i < k; i++){
		if(t[i] == 'r'){
			ans += p;
		}
		if(t[i] == 'p'){
			ans += s;
		}
		if(t[i] == 's'){
			ans += r;
		}
	}

	for(int i = k; i < n; i++){
		if(t[i] != t[i - k]){
			if(t[i] == 'r'){
				ans += p;
			}
			if(t[i] == 'p'){
				ans += s;
			}
			if(t[i] == 's'){
				ans += r;
			}
		}else{
			t[i] = '*';
		}
	}


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

Measured memory_bytes: 512
#include <iostream>
#include <algorithm>
#include <bits/stdc++.h>

using namespace std;

int main()
{
    double b,c,d;
    int a;
    b=3.14159265358979323846;

    cin>>a;
    cout.precision(20);
    c=a*b;
    c*=2;
    printf("%.20lf\n",c);

    return 0;

}



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

using namespace std;

int main()
{
    int n,i,coun=0;
    string a,b,c;
    cin>>n>>a>>b>>c;
    for(i=0;i<n;i++)
    {
        if(a[i]==b[i] && a[i]==c[i])
            coun=coun+0;
        else
            if(a[i]==b[i] && a[i]!=c[i])
            coun++;
        else
            if(a[i]==c[i] && a[i]!=b[i])
            coun++;
        else
            if(c[i]==b[i] && a[i]!=c[i])
            coun++;
        else
            coun=coun+2;
    }
    cout<<coun;

    return(0);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(ll i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(ll i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(ll i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) ((ll)(x).size())
#define len(x) ((ll)(x).length())
#define endl "\n"

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    // ifstream in("input.txt");
    // cin.rdbuf(in.rdbuf());
    ll h, w;
    cin >> h >> w;
    vector<string> s(h);
    rep(i, h) cin >> s[i];
    vector<vector<ll>> xdp(h, vector<ll>(w, 0));
    rep(i, h) {
        ll idx = -1, cnt = 0;
        rep(j, w) {
            if (s[i][j] == '#') {
                if (idx != -1) {
                    xdp[i][idx] += cnt;
                    xdp[i][j] -= cnt;
                    idx = -1;
                    cnt = 0;
                }
            }
            else {
                cnt++;
                if (idx == -1) {
                    idx = j;
                }
            }
        }
        if (idx != -1) xdp[i][idx] += cnt;
    }
    rep(i, h) {
        reps(j, 1, w) {
            xdp[i][j] += xdp[i][j - 1];
        }
    }
    vector<vector<ll>> ydp(h, vector<ll>(w, 0));
    rep(i, w) {
        ll idx = -1, cnt = 0;
        rep(j, h) {
            if (s[j][i] == '#') {
                if (idx != -1) {
                    ydp[idx][i] += cnt;
                    ydp[j][i] -= cnt;
                    idx = -1;
                    cnt = 0;
                }
            }
            else {
                cnt++;
                if (idx == -1) {
                    idx = j;
                }
            }
        }
        if (idx != -1) ydp[idx][i] += cnt;
    }
    rep(i, w) {
        reps(j, 1, h) {
            ydp[j][i] += ydp[j - 1][i];
        }
    }
    ll ans = 0;
    rep(i, h) {
        rep(j, w) {
            if (s[i][j] == '#') continue;
            ans = max(ans, xdp[i][j] + ydp[i][j] - 1);
        }
    }
    cout << ans << endl;
    // rep(i, h) rep(j, w) printf("%lld%s", xdp[i][j], (j == (w - 1)) ? "\n" : " ");
    return 0;
}


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

#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
const int INF = 1e9;

int main() {
  ll n, ans = 0, a, even = 0;
  map<ll, ll> mp;
  cin >> n;
  rep(i, n) cin >> a, mp[a]++;

  for (auto m : mp) {
    if (m.second > 1 && m.second % 2 == 0) even++;
    ans++;
  }

  cout << (even % 2 == 0 ? ans : ans - 1) << endl;
  return 0;
}


Measured memory_bytes: 6528
inp=list(map(int,input().split()))
m=inp[1]
inp=list(map(int,input().split()))
ans=0
inp=[-1*item for item in inp]
import heapq
heapq.heapify(inp)
while m>0:
    a=heapq.heappop(inp)
    a*=-1
    x=a//2
    heapq.heappush(inp,-1*x)
    m-=1
print (-1*sum(inp))

Measured memory_bytes: 19988
import java.util.Scanner;


public class Main {

	public static void main(String[] args) {
		
		Scanner scanner =new Scanner(System.in);
		while(true) {
		int n = scanner.nextInt();
		int m = scanner.nextInt();
		
			if((n+m)==0) break;
		
			int[] t =new int[1000];
			int[] h =new int[1000];
		
			int sum_t =0;
			int sum_h =0;
		
			for(int i=0; i<n; i++){
				t[i]=scanner.nextInt();
				sum_t += t[i];
			}
			for(int j=0; j<m; j++){
				h[j]=scanner.nextInt();
				sum_h +=h[j];
			}
		
			int ct=10000000;
			int ch=10000000;
		
			for(int i=0; i<n; i++){ 
				for(int j=0; j<m; j++){
					if(sum_t-t[i]+h[j] == sum_h-h[j]+t[i]){
						if(t[i]+h[j]<ct+ch){
						ct=t[i];
						ch=h[j];
						}
					}
				}
			}
			if(ct==10000000 && ch==10000000)
				System.out.println("-1");
			else
			System.out.println(ct+" "+ch);
		}
	}
}

Measured memory_bytes: 23244
sx,sy,tx,ty = map(int,input().split())

ue = ty - sy
migi = tx - sx

print('U'*ue+'R'*migi+'D'*ue+'L'*(migi+1)+'U'*(ue+1)+'R'*(migi+1)+'D'+'R'+'D'*(ue+1)+'L'*(migi+1)+'U')

Measured memory_bytes: 3060
#[allow(unused_imports)]
use itertools::Itertools;
#[allow(unused_imports)]
use num::*;
use proconio::input;
#[allow(unused_imports)]
use proconio::marker::*;
#[allow(unused_imports)]
use std::collections::*;

fn solve() {
    input! {
        n: usize
    };

    let res = (n + 1) / 2;
    println!("{}", res);
}

fn main() {
    std::thread::Builder::new()
        .name("big stack size".into())
        .stack_size(256 * 1024 * 1024)
        .spawn(|| {
            solve();
        })
        .unwrap()
        .join()
        .unwrap();
}


Measured memory_bytes: 2228
import java.util.*;
public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner (System.in);
    String s1=  sc.next();
    String s2 = sc.next();
    int v1 = sc.nextInt();
    int v2 = sc.nextInt();
    String result = sc.next();
    if (s1.equals(result)) {
      v1--;
      System.out.println(v1 + " " + v2);
    }
    else {
      v2--;
      System.out.println(v1 + " " + v2);
    }
  }
}

Measured memory_bytes: 21844
while True:
    h, w = map(int, input().split())
    if h == 0:
        break

    t_list = []
    for i in range(h):
        t_list.append(input())

    p = [0,0]
    p_passed = []
    while True:
        t = t_list[p[1]][p[0]]
        if t == ">":
            p[0] += 1
        elif t == "<":
            p[0] -= 1
        elif t == "^":
            p[1] -= 1
        elif t == "v":
            p[1] += 1
        else:
            print(p[0], p[1])
            break
        if p in p_passed:
            print("LOOP")
            break
        p_passed.append(p[:])



Measured memory_bytes: 5616
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> P;
int main() {
  ll n,m;
  cin>>n>>m;
  ll x=m/n;
  for(int i=x;i>0;i--){
    if(m%i==0){
      cout<<i<<endl;
      return 0;
    }
  }
	return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <valarray>
#include <vector>
using namespace std;
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
int main() {
    //freopen("C.01.in","r",stdin);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n, m,ans=0,c=0,a,b;
    cin >> n >> m;
    multimap<ll, ll> mm;
    rep(i, 0, n){
        cin >> a >> b;
        mm.insert({a,b});
    }
    trav(it, mm){
        if(c==m){
            break;
        }
        else if(m<c+it.second){
            ans += it.first*(m-c);
            break;
        }
        c += it.second;
        ans += it.first*it.second;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 9852
#include <iostream>
#include <cmath>
#include <string>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <math.h>
#include <iomanip>
#include <bitset>
#include <cstring>
#include <stdlib.h>
#include <utility>
#include <set>
#include <map>
#include <string.h>
#include <cstring>

using namespace std;

int main(){
   
    int n;
    cin >> n;
    
    vector<long long> a(n);
    for(int i=0;i<n;i++){
        cin >> a[i];
    }
    
    sort(a.begin(),a.end());
    
    for(int i=0;i<n-1;i++){
            if(a[i]==a[i+1]){
                cout << "NO" << endl;
                return 0;
            }
            
    }
    cout << "YES" << endl;
    return 0;
}

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

int main() {

    /*
     *  Knapsack problem 2
     *  For this variation, the weights can be massive. We need to somehow use the *value* as our
     *  iterator, not the weights.
     *
     *  Previous algorithm was O(N * W), can we do O(N*max_value)?
     *  Old definition was:
     *  dp[w, i] = maximum value for capacity w after inserting item i
     *
     *  What about:
     *  dp[v] = *minimum* weight with total value exactly v
     *
     *  Consider item with weight 3, value 30
     *  After this it should be:
     *  [0, inf, inf, ...,  3, inf, inf, ...]
     *   0    1    2       30  31
     *
     *  So if we're considering item `i`, and it has weight/value (wi, vi)
     *  Then there are two cases, we either take or don't take.
     *      - If we take, then we'd add the minimum weight for the value before this one.
     *        So the new weight would be dp[v-vi] + wi
     *      - If we don't take, we'd use the minimum weight for the value we're already at
     *        dp[v].
     *  Whichever of those two is the minimum, use that.
     *
     *  This should run in O(N * max_v) time, where max_v is the sum of all the input item weights.
     *
     */

    int n;
    long long maxw;
    long long maxv = 0;

    const long long INF = 1e11 + 1ll;
    
    std::cin >> n;
    std::cin >> maxw;

    std::vector<std::pair<long long, int>> items;

    for (int i = 0; i < n; i++) {
        int w, v;
        std::cin >> w;
        std::cin >> v;

        items.push_back(std::make_pair(w, v));
        maxv += v;
    }

    std::vector<long long> dp(maxv+1, INF);

    // Minimum weight with value 0 is always zero.
    dp[0] = 0ll;

    for (int i = 0; i < n; i++) {
        const auto weight = items[i].first;
        const auto val    = items[i].second;
        for (int j = maxv; j >= 0; j--) {
            dp[j] = std::min(dp[j], (j-val >= 0) ? dp[j-val]+weight : INF);
        }
    }

    for (int i = maxv; i >= 0; i--) {
        if (dp[i] <= maxw) {
            std::cout << i;
            break;
        }
    }


    return 0;
}

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

int main() {
	
	int n;
	cin >> n;
	
	const int INF = 1001001001;
	vector<int> dp(n+1, INF);
	dp[0] = 0;
	for(int i = 1; i <= n; i++){
		int power = 1;
		while(power <= i){
			dp[i] = min(dp[i], dp[i - power] + 1);
			power *= 6;
		}
		power = 9;
		while(power <= i){
			dp[i] = min(dp[i], dp[i - power] + 1);
			power *= 9;
		}
	}
	cout << dp[n] << endl;
	return 0;
}

Measured memory_bytes: 640
#include<stdio.h>
#include<string.h>
#include<iostream>
#include<set>
#include<algorithm>
#include<vector>
#include<math.h>
#include<queue>
#include<set>
#include<map>
using namespace std;
const int maxn = 100 + 5;
const int inf = 1e9;

set<int>s;

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

	int now;
	for(int i = 1 ; i <= n ; i++){
		cin >> now;
		s.insert(now);
	}
	cout << s.size();
}	


Measured memory_bytes: 256
#include <iostream>

using namespace std;

typedef long long ll;

int main(){
    ll N;
    cin >> N;
    for (ll i = 1; i<=3500;++i) {
        for (ll j = i; j<=3500 ; ++j) {
            ll a = N * i * j;
            ll b = 4ll * i * j - i * N - j * N;
            if (b != 0 && a % b == 0) {
                ll k = a / b;
                if (k > 0) {
                    cout << i << " " << j << " " << k << endl;
                    return 0;
                }
            }
        }
    }
    return 0;
}

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

int main()
{
    int x, y,xi,yi;
    bool ka = false;
    cin >> x >> y;
    for (int i = 0; i <= x;i++)
    {
        xi = i * 2;
        yi = (x - i) * 4;
        if(xi+yi==y)
        {
            cout << "Yes" << endl;
            ka = true;
            break;
        }
    }
    if(ka==false)
    {
        cout << "No" << endl;
    }
}


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

using namespace std;

char s[1234567];

int main() {
  scanf("%s", s);
  int k;
  scanf("%d", &k);
  for (int i = 0; s[i]; i++) {
    if (s[i] != 'a') {
      int ops = 'z' - s[i] + 1;
      if (ops <= k) {
        k -= ops;
        s[i] = 'a';
      }
    }
  }
  int len = strlen(s);
  while (k--) {
    s[len - 1]++;
    if (s[len - 1] > 'z') {
      s[len - 1] = 'a';
    }
  }
  puts(s);
  return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <iomanip>
#include <stdio.h>
#include <cstring>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <functional>
#include <math.h>
using namespace std;

typedef long long ll;

int main() {
  string S; cin >> S;
  int N = S.length(), g = 0, p = 0;
  for (int i = 0; i < N; i++) {
    if (S[i] == 'g') g++;
    else p++;
  }
  int x, y = N / 2;
  x = N - y;
  cout << y - p << endl;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#include <iostream>
#include <iomanip>
#include <numeric>
#include <math.h>
#include <stdio.h>
#include <climits>
#include <cfloat>
#include <string>
#include <unordered_map>
using namespace std;

int main(){
	int n, m;
	cin >> n >> m;
	vector<long long int> h(n);
	vector<bool> x(n);
	int ans = 0;
	for(int i=0;i<n;i++){
		x.at(i) = true;
	}
	for(int i=0;i<n;i++){
		cin >> h.at(i);
	}
	long long int a, b;
	for(int i=0;i<m;i++){
		cin >> a >> b;
		if(h.at(a-1) >= h.at(b-1)){
			x.at(b-1) = false;
		}
		if(h.at(a-1) <= h.at(b-1)){
			x.at(a-1) = false;
		}
	}
	for(int i=0;i<n;i++){
		if(x.at(i)){
			ans++;
		}
	}
	cout << ans << endl;
	return 0;
	}

Measured memory_bytes: 4048
#include <vector>
#include <list>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
#include <functional>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <cassert>
using namespace std;
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define EACH(t,i,c) for(t::iterator i=(c).begin(); i!=(c).end(); ++i)
const double EPS = 1e-10;
const double PI  = acos(-1.0);

int main(){
	int n,m;
	while(cin>>n,n){
		cin>>m;
		string s;
		cin>>s;

		int cnt=0;
		int ans=0;
		REP(i,s.size()){
			if(cnt%2==0){
				if(s[i]=='I'){
					cnt++;
				}else{
					cnt=0;
				}
			}else if(cnt>0){
				if(s[i]=='O'){
					cnt++;
				}else{
					cnt=1;
				}
			}
			if(cnt==2*n+1){
				ans++;
				cnt-=2;
			}
		}
		cout<<ans<<endl;
	}
}

Measured memory_bytes: 2108
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
//#define CHKR
#define ll int
#define pb push_back
//#define mp make_pair
#define fr first
#define sc second
#define ARRS int(2e5+500)
#define BARRS int(6e4+600)
#define MAX ((long long)(1e9+1))
#define EP ((long double)(1e-9))
#define MMAX ((long long)(1e9+10))
#define HS1 ((long long)(1000001329))
#define HS2 ((long long)(1000001531))
#define MOD ((long long)1000000009ll)
#define SQ 31622780
#define PI 3.14159265358979323846264338327950288419716939937510
#define BG 4294967232ll
#define MH 200008
ll n,m;
ll a[ARRS];
#ifndef CHKR
int main(){
#else
int doit(fstream &in,fstream &out){
    cin.rdbuf(in.rdbuf());
    cout.rdbuf(out.rdbuf());
#endif
    #ifdef KHOKHO
        #ifndef CHKR
        freopen("in.in","r",stdin);
        freopen("out.out","w+",stdout);
        #endif //CHKR
    #endif //KHOKHO
    ll k,p,q,l,r;
    cin>>l>>r;
    if(l<=0&&0<=r){
		cout<<"Zero";
    }
    else if(0<l){
		cout<<"Positive";
    }
	else if((r-l)&1){
		cout<<"Positive";
	}
	else  cout<<"Negative";

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define mod107 1000000007
#define rep(i, n) for (int i = 0; i < n; ++i)
using Graph = vector<vector<int>>;
#define grepq priority_queue<double, std::vector<double>, std::greater<double>>
#define all(v) v.begin(), v.end()
#define PI acos(-1)

const ll INF = 10010001010;
const int inf = 1000034000;
typedef vector<ll> vecl;
typedef vector<int> veci;
typedef tuple<string, int, int> TUP;

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


int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    //cout << fixed << setprecision(15);
    int A, B;
    cin >> A >> B;
    int ans = 0;
    for (int i = A; i <= B;i++)
    {
        string S = to_string(i);
        string T = S;
        reverse(all(T));
        if(T == S){
            ans++;
        }
    }
    cout << ans << endl;
}


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

typedef long long ll;

int main() {
  ll A, B;
  cin >> A >> B;

  ll com = min(A, B);

  while (com % A != 0 || com % B != 0) {
    com += min(A, B);
  }
  cout << com << endl;
}

Measured memory_bytes: 768
#include <iostream>
#include <iomanip>
#include <cmath>
#include <vector>
#include <queue>
#include <limits>
#include <algorithm>
#include <string>
#include <cstring>
#include <map>

#include <inttypes.h>
using namespace std;

static int32_t N, Ma, Mb;
static int32_t a[40], b[40], c[40];
static int32_t memo[41][401][401];

static int32_t dfs(int32_t _index, int32_t sum_a, int32_t sum_b)
{
	if (memo[_index][sum_a][sum_b] > -1)
		return memo[_index][sum_a][sum_b];

	int32_t res = dfs(_index + 1, sum_a + a[_index], sum_b + b[_index]) + c[_index];
	res = min(res, dfs(_index + 1, sum_a, sum_b));
	memo[_index][sum_a][sum_b] = res;
	return res;
}

int main()
{
	scanf("%d%d%d", &N, &Ma, &Mb);
	int32_t max_cost = 0;
	for (int32_t i = 0; i < N; i++) {
		scanf("%d%d%d", &a[i], &b[i], &c[i]);
		max_cost += c[i];
	}

	for (int32_t _index = 0; _index <= N; _index++)
		for (int32_t sum_a = 0; sum_a < 401; sum_a++)
			fill(memo[_index][sum_a], memo[_index][sum_a] + 401, -1);

	for (int32_t sum_a = 0; sum_a < 401; sum_a++) {
		for (int32_t sum_b = 0; sum_b < 401; sum_b++) {
			memo[N][sum_a][sum_b] =
				(sum_a > 0 && sum_b > 0 && sum_a * Mb == sum_b * Ma) ? 0 : numeric_limits<int32_t>::max() / 2;
		}
	}

	int32_t res = dfs(0, 0, 0);
	printf("%d\n", res > max_cost ? -1 : res);

	return 0;
}

Measured memory_bytes: 25984
#include <stdio.h>
#include <vector>
#include <iostream>
#include <string>
using namespace std;

int main() {
  int A,B,K,k,ans;
  cin>>A>>B>>K;
  k = 0;
  for (int i = min(A,B); i >= 1; i--) {
    if (A%i == 0 && B%i == 0) k++;
    if (k == K) {
      ans = i;
      break;
    }
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<algorithm>
using namespace std;
int d[110];
int e[110];
int L[110];
int R[110];
int main(){
	int a;
	scanf("%d",&a);
	for(int i=0;i<a;i++){
		int h,m;
		scanf("%d:%d-",&h,&m);
		L[i]=h*60+m;
		scanf("%d:%d",&h,&m);
		R[i]=h*60+m;
	}
	int b;scanf("%d",&b);
	for(int i=0;i<b;i++){	
		int p;scanf("%d",&p);
		while(p--){
			int h,m;
			scanf("%d:%d-",&h,&m);
			int left=h*60+m;
			scanf("%d:%d",&h,&m);
			int right=h*60+m;
			for(int j=0;j<a;j++){
				if(left<=L[j]&&R[j]<=right)d[j]++;
			}
		}
	}
	scanf("%d",&b);
	for(int i=0;i<b;i++){	
		int p;scanf("%d",&p);
		while(p--){
			int h,m;
			scanf("%d:%d-",&h,&m);
			int left=h*60+m;
			scanf("%d:%d",&h,&m);
			int right=h*60+m;
			for(int j=0;j<a;j++){
				if(left<=L[j]&&R[j]<=right)e[j]++;
			}
		}
	}
	int ret=0;
	for(int i=0;i<a;i++)ret+=min(d[i],e[i]);
	printf("%d\n",ret);
}

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

#define int long long
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define all(v) (v).begin(),(v).end()
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
#define pb push_back
#define fi first
#define se second
template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

int N;
int x[50],y[50];
signed main(){
    cin>>N;
    rep(i,N)cin>>x[i]>>y[i];

    if(N&1){
        puts("NA");
        return 0;
    }

    bool ok=true;
    rep(i,N/2){
        if(x[i+1]-x[i]!=-(x[(i+1+N/2)%N]-x[i+N/2]))ok=false;
        if(y[i+1]-y[i]!=-(y[(i+1+N/2)%N]-y[i+N/2]))ok=false;
    }

    if(ok)printf("%.20f %.20f\n",(x[N/2]+x[0])/2.0,(y[N/2]+y[0])/2.0);
    else puts("NA");
    return 0;

}

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

int main() {
    int n;
    ll x;
    cin >> n >> x;
    vector<ll> a(n);
    rep(i, n) cin >> a[i];

    vector<ll> pre(n);
    if(a[0]>x)
        pre[0] = x;
    else
        pre[0] = a[0];

    for (int i = 1; i < n;++i){
        ll now = pre[i - 1] + a[i];
        
        if(now<=x)
            pre[i] = a[i];
        else
            pre[i] = a[i] - (now - x);
    }

    ll ans = 0;
    rep(i, n)
        ans += a[i] - pre[i];

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1792
import java.util.*;
import java.util.stream.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        sc.next();
        List<Integer> numList = new ArrayList<>();
         while(sc.hasNext()){
         numList.add(Integer.parseInt(sc.next()));
        }
        int X = numList.stream().reduce(0,(s1,s2) -> s1 + s2);
        double x1 = Math.ceil(((double)X / numList.size()));
        double x2 = Math.floor(((double)X / numList.size()));
        int res1 = 0;
        int res2 = 0;
        for(int i = 0; i < numList.size();i++){
            res1 += Math.pow(numList.get(i) - x1 , 2);
            res2 += Math.pow(numList.get(i) - x2 , 2);
        }
        System.out.println(Math.min(res1,res2));
    }
}


Measured memory_bytes: 27092
#include <iomanip>
#include <iostream>
#include <math.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;

int main(void) {
  ios::sync_with_stdio(false);
  int64_t N, M;
  cin >> N >> M;
  int64_t SUM = 0;
  rep(i, M) {
     int64_t a;
     cin >> a;
     SUM += a;
  }
  if(N < SUM) cout << -1 << endl;
  else cout << N - SUM << endl;
  return 0;
}


Measured memory_bytes: 3616
#include <bits/stdc++.h>
using namespace std;
using vi=vector<int>;
using vvi=vector<vi>;
using vs=vector<string>;
using msi=map<string,int>;
using mii=map<int,int>;
using pii=pair<int,int>;
using vlai=valarray<int>;
using ll=long long;
#define rep(i,n) for(int i=0;i<n;i++)
#define range(i,s,n) for(int i=s;i<n;i++)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define fs first
#define sc second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define INF 1e9
#define EPS 1e-9

int main(){
	set<int> s;
	int n;
	cin>>n;
	rep(i,n){int p;
	    cin>>p;
	    s.insert(p);
	}
	cout<<s.size()<<endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define rep(i,l,r) for(int (i)=(l);(i)<(r);i++)
#define erep(i,l,r) for(int (i)=(l);(i)<=(r);i++)
#define MOD 1000000007
using namespace std;
ll K;

int N;
ll f(string S) {
    N = S.length();
    ll dp[N+1][K+3][2];
    rep(dgt, 0, N + 1) rep(nz, 0, K+2) rep(isless, 0, 2) dp[dgt][nz][isless] = 0;
    dp[0][0][0] = 1;
    rep(dgt, 0, N)rep(nz, 0, K+1)rep(isless, 0, 2) {
        int c = S[dgt] - '0';

        rep(x, 0, 10) {
            int dgt2 = dgt + 1;
            int nz2 = nz;
            if (x != 0) nz2++;
            
            if (isless == 1) {
                dp[dgt2][nz2][isless] += dp[dgt][nz][isless];
            } else {
                if (x < c) dp[dgt2][nz2][1] += dp[dgt][nz][isless];
                else if (x == c) dp[dgt2][nz2][0] += dp[dgt][nz][isless];
            }
        }
    }

    ll res = 0;
    rep(i,K,K+1)rep(isless, 0, 2){
        res += dp[N][i][isless];
       // cout<<dp[N][i][isless]<<endl;
    }
    return res;
}

int main() {
    string S;
    cin >> S;
    cin >> K;
    ll ans = f(S);

    printf("%lld\n", ans);
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
int dp[1001][1001];
int lcs(string x,string y) {
    int m = x.size(), n = y.size(),la = 0;
    x = " " + x;
    y = " " + y;
    for (int i = 0; i <= m;i++) dp[i][0] = 0;
    for (int i = 1; i <= n;i++) dp[0][i] = 0;
    for (int i = 1;i <= m;i++) {
        for (int j = 1;j <= n;j++) {
            if (x[i] == y[j]) {
                dp[i][j] = dp[i - 1][j - 1] + 1;
            }
            else
                dp[i][j] = max(dp[i-1][j],dp[i][j -1]);
            la = max(la, dp[i][j]);
        }
    }
    return la;
}
int main() {
    int q;string x, y;
    cin >> q;
    for (int i = 0; i < q;i++) {
        cin >> x >> y;
        cout << lcs(x, y) << endl;
    }

}


Measured memory_bytes: 7092
#!/usr/bin/env python3
#ABC112 B

n,T = map(int,input().split())

mi = float('inf')
for i in range(n):
    c,t = map(int,input().split())
    if t <= T:
        mi = min(mi,c)
if mi == float('inf'):
    print('TLE')
else:
    print(mi)


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

def main():
    a = 0
    for i in range(1,n+1):
        c = 0
        if i %2 != 0:
            for j in range(1,i+1):
                if i % j == 0:
                    c += 1
            if c == 8:
                a += 1
                
    return a

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



Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define lp(i,n) for(int i=0; i<n ; ++i)
#define lpx(i,x,n) for(int i=x; i<n ; ++i)
#define all(v) v.begin() , v.end()
#define sz(v) (int(v.size()))
typedef unsigned long long ul;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<vector<int> > vii;
typedef pair<int, int> pii;
typedef pair<char, int> pci;
typedef vector<pii> vp;
typedef vector<pci> vpc;
typedef pair<int,pii> piii;

int OO = 2e9;
const double eps = 1e-9 ;
const int N = 500000;
int mx = -1e9 , mn = 1e9 ;
ll arr[N],arr2[N] ;

int dcmp(double x, double y)
{
    return fabs(x - y) <= eps ? 0 : x > y ? -1 : 1;
}



int main()
{
    int a, b, c; cin>> a>> b>> c;
    cout << (b+c > a ? (b+c)-a : 0) << endl;



    return 0;
}
























Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <set> 
#include <vector>
#include <algorithm>
#include <bitset>
#define ll long long
using namespace std;

int main(){
    int n;
    cin>>n;
    if(n%2==0) cout<<n;
    else cout<<2*n;
    cout<<endl;
    return 0;
  
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
using ll = long long;
const int MOD = 1e9+7;
int n, a;
ll in, out, k, ans;
struct BIT{
	vector<int> dat;
	int sz;
	BIT(int n){
		for(sz = 1; sz < n; sz *= 2);
		sz++;
		dat.resize(sz);
	}
	void set(int x, int n){
		for(int i = n; i < sz; i += i&-i) dat[i] += x;
	}
	int get(int n){
		int ret = 0;
		for(int i = n; i > 0; i -= i&-i) ret += dat[i];
		return ret;
	}
};

int main(){
	scanf("%d%lld", &n, &k);
	BIT bt(2005);
	rep(i,n){
		scanf("%d", &a);
		bt.set(1, a);
		in += i+1 - bt.get(a);
	}
	rep(i,2000) out -= bt.get(i+1) * (bt.get(i+1) - bt.get(i));
	out += n * n;
	ans = (in * k % MOD + out % MOD * (k * (k-1) / 2 % MOD)) % MOD;
	printf("%lld\n", ans);
}

Measured memory_bytes: 256
#![allow(unused_imports)]pub mod pcl{pub mod stdin{use std::io::prelude::*;use std::io::stdin;use std::str::FromStr;pub fn read_line()->String{let mut s=String::new();stdin().read_line(&mut s).unwrap();s.trim().to_string()}pub fn read<T:FromStr>()->T{read_from(stdin())}pub fn read_token()->String{read_token_from(stdin())}pub fn read_ascii()->char{read_ascii_from(stdin())}pub fn read_from<R:Read,T:FromStr>(read:R)->T{read_token_from(read).parse().unwrap_or_else(|_|panic!("failed to parse a value"))}pub fn read_token_from<R:Read>(read:R)->String{read.bytes().flat_map(|x|x.map(|x|x as char)).skip_while(|x|x.is_whitespace()).take_while(|x|!x.is_whitespace()).collect()}pub fn read_ascii_from<R:Read>(read:R)->char{read.bytes().flat_map(|x|x.map(|x|x as char)).skip_while(|x|x.is_whitespace()).next().expect("failed to get a next character")}}}
use pcl::stdin::*;
fn main() {
    let mut v = vec![vec![0; 3]; 3];
    for r in &mut v {
        for x in r {
            *x = read();
        }
    }
    let n: usize = read();
    for _ in 0..n {
        let b: i32 = read();
        'check: for r in &mut v {
            for x in r {
                if *x == b {
                    *x = 0;
                    break 'check;
                }
            }
        }
    }
    let bingo = match (
        (v[0][0], v[0][1], v[0][2]),
        (v[1][0], v[1][1], v[1][2]),
        (v[2][0], v[2][1], v[2][2]),
    ) {
        ((0, 0, 0), _, _) | (_, (0, 0, 0), _) | (_, _, (0, 0, 0)) => true,
        _ => false,
    };
    let bingo = bingo
        || match (
            (v[0][0], v[1][0], v[2][0]),
            (v[0][1], v[1][1], v[2][1]),
            (v[0][2], v[1][2], v[2][2]),
        ) {
            ((0, 0, 0), _, _) | (_, (0, 0, 0), _) | (_, _, (0, 0, 0)) => true,
            _ => false,
        };
    let bingo = bingo
        || match ((v[0][0], v[1][1], v[2][2]), (v[2][0], v[1][1], v[0][2])) {
            ((0, 0, 0), _) | (_, (0, 0, 0)) => true,
            _ => false,
        };
    if bingo {
        println!("Yes");
    } else {
        println!("No");
    }
}



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

namespace _0018
{
    class Program
    {
        static void Main(string[] args)
        {
            int []a = Console.ReadLine().Split().Select(int.Parse).ToArray();
            Array.Sort(a);
            Console.WriteLine(a[4] + " " + a[3] + " " + a[2] + " " + a[1] + " " + a[0]);
        }
    }
}

Measured memory_bytes: 9640
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))
def getArray(intn):
    return [int(input()) for i in range(intn)]
def input():
    return sys.stdin.readline().rstrip()
def rand_N(ran1, ran2):
    return random.randint(ran1, ran2)
def rand_List(ran1, ran2, rantime):
    return [random.randint(ran1, ran2) for i in range(rantime)]
def rand_ints_nodup(ran1, ran2, rantime):
  ns = []
  while len(ns) < rantime:
    n = random.randint(ran1, ran2)
    if not n in ns:
      ns.append(n)
  return sorted(ns)

def rand_query(ran1, ran2, rantime):
  r_query = []
  while len(r_query) < rantime:
    n_q = rand_ints_nodup(ran1, ran2, 2)
    if not n_q in r_query:
      r_query.append(n_q)
  return sorted(r_query)

from collections import defaultdict, deque, Counter
from sys import exit
from decimal import *
import heapq
import math
from fractions import gcd
import random
import string
import copy
from itertools import combinations, permutations, product
from operator import mul, itemgetter
from functools import reduce
from bisect import bisect_left, bisect_right

import sys
sys.setrecursionlimit(1000000000)
mod = 10 ** 9 + 7

#############
# Main Code #
#############

N, D = getNM()
que = [getList() for i in range(N)]
ans = 0
for x, y in que:
    opt = math.sqrt(x ** 2 + y ** 2)
    if opt <= D:
        ans += 1
print(ans)

Measured memory_bytes: 110800
#include <bits/stdc++.h>
#define rep(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;
    vector<ll> A(N + 1), B(N);
    rep(i,N+1) cin >> A.at(i);
    rep(i,N) cin >> B.at(i);
    ll ans = 0;

    rep(i,N+1) {
        if (i == 0) {
            ll beat = min(A.at(0), B.at(0));
            ans += beat;
            B.at(i) -= beat;
        } else if (i == N) {
            ll beat = min(A.at(N), B.at(N - 1));
            ans += beat;
        } else {
            ll beatlow = min(A.at(i), B.at(i - 1));
            ll beathigh = min(A.at(i) - beatlow, B.at(i));
            ans += beatlow + beathigh;
            B.at(i) -= beathigh;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 4836
#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(register int i=(a);i<=(b);++i)
#define All(x) (x).begin(),(x).end()
#define pb emplace_back
#define mp make_pair
typedef long long ll;
typedef vector<int> VI;
typedef pair<int,int> PII;
const double PI=acos(-1.0);
const double eps=1e-6;
const long long mod=1e9+7;
const int inf=0x7fffffff;
const int maxn=100005;
ll qpow(ll x,ll y,ll Mod) {ll ans=1,base=x%Mod; while(y){if(y&1)ans=(ans*base)%Mod;base=(base*base)%Mod;y>>=1;} return ans;}
ll gcd(ll a,ll b) {return b?gcd(b,a%b):a;}
// fast read
template<class T> void read(T &x) {
	x=0;int f=0;char ch=getchar();
	while(ch<'0'||ch>'9'){f|=(ch=='-');ch=getchar();}
	while(ch>='0'&&ch<='9'){x=(x<<1)+(x<<3)+(ch^48);ch=getchar();}
	x=f?-x:x;
	return;
}

int a,b;

int main(){
	//freopen("test.in","r",stdin);
	read(a),read(b);
	printf("%d\n",a*b);
	return 0;
}

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

int main(){
    string s;
    cin>>s;
    int n=s.size();
    rep(i,n){
        cout<<'x';
    }
    cout<<endl;
}

Measured memory_bytes: 256
import numpy as np

N,K = map(int,input().split())
Point = list(map(int,input().split()))
T = input()
T = "0" + T

dp = np.zeros(N+1,dtype='int')

win = {
    'r':2, # グーなのでパーで勝
    's':0, # チョキなのでグーで勝
    'p':1 # パーなのでチョキで勝
    }

for i in range(1,N+1):
    if i < K + 1:
        dp[i] = win[T[i]]
    else:
        if win[T[i]] != dp[ i - K ]:
            dp[i] = win[T[i]]
        else:
            # if (i + K) <= N:
            #     dp[i] = 3 - win[T[i + K]] - dp[ i - K ]
            # else:
            #     dp[i] = -1
            dp[i] = -1

# print(dp)
ans = 0

for j in range(1,N+1):
    if dp[j] >= 0:
        ans += Point[dp[j]]

print(ans)

Measured memory_bytes: 13508
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <map>
#include <queue>
#include <stack>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cctype>
#include <numeric>
#include <complex>
#define rep(i,n) for(int (i) = 0; (i) < (n); ++(i))
using namespace std;
typedef long long ll;

int main(){
    string s;
    cin >> s;
    for(int i = 1; i < 4; ++i){
        if(s[i] == s[i-1]){
            cout << "Bad" << endl;
            return 0;
        }
    }
    cout << "Good" << endl;
    return 0;
}


Measured memory_bytes: 256
def main():
	N, M = map(int,input().split())
	if M == 0:
		print("Yes")
		return
	x = [[] for _ in range(N)]
	ans = [0 for _ in range(N)]
	for i in range(M):
		l, r, d = map(int, input().split())
		l, r = l-1, r-1
		x[l].append([r, d])
		x[r].append([l, -d])

	visited = [False for _ in range(N)]

	def dfs(i):
		vs = [i]
		while vs:
			v = vs.pop()
			for nex in x[v]:
				if not visited[nex[0]]:
					visited[nex[0]] = True
					ans[nex[0]] = ans[v]+nex[1]
					vs.append(nex[0])
				else:
					if ans[nex[0]] != ans[v]+nex[1]:
						return False
		return True

	ans_exist = True
	for i in range(N):
		if not visited[i]:
			visited[i] = True
			ans_exist = dfs(i)
		if not ans_exist:
			break

	if ans_exist:
		print("Yes")
	else:
		print("No")


if __name__ == '__main__':
    main()

Measured memory_bytes: 77724
// Author : Mohamed Sameh
#include <bits/stdc++.h>
#define pb push_back
#define f first
#define s second
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define SZ(a) (int)a.size()
#define Flush fflush(stdout);
typedef long long ll ;
using namespace std ;
int n, m;
const int M = 1e5 ;
vector<int> adj[M];
int Max[M];
int dfs (int u = 0)
{
    if (Max[u] != 0 )return Max[u];
    for (int i : adj[u])
    {
        Max[u] = max (Max[u] , 1 + dfs(i));
    }
    return Max[u]; 
} 
int main ()
{
    scanf("%d%d" , &n ,&m);
    for (int i =0 ;i  < m ;i++)
    {
        int u , v;
        scanf("%d%d" , &u ,&v ); 
        u--;
        v--; 
        adj[u].pb(v); 
    }
    /*
    for each vertix find long path come to it 
    */
   int ans = 0;
   for (int i =0  ; i < n ;i++)
   ans = max (ans , dfs(i));
   printf ("%d\n" ,ans );
}


Measured memory_bytes: 7424
/**
 *    author:  otera    
**/
#include<iostream>
#include<string>
#include<cstdio>
#include<cstring>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<deque>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
using namespace std;

#define int long long
typedef long long ll;
typedef unsigned long long ul;
typedef unsigned int ui;
typedef long double ld;
const int inf=1e9+7;
const ll INF=1LL<<60 ;
const ll mod=1e9+7 ;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<int, int> P;
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
#define fr first
#define sc second
#define all(c) c.begin(),c.end()
#define pb push_back
#define debug(x)  cerr << #x << " = " << (x) << endl;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

void solve() {
	int n; cin >> n;
    vector<int> a(n);
    vector<P> b(n);
    rep(i, n) {
        cin >> a[i];
        b[i] = {a[i], i};
    }
    sort(all(b));
    reverse(all(b));
    static int dp[2020][2020];
    rep(i, 2020) {
        rep(j, 2020) {
            dp[i][j] = 0;
        }
    }
    rep(i, n) {
        int x = b[i].fr, k = b[i].sc;
        for(int j = 0; j <= i; ++ j) {
            chmax(dp[i + 1][j + 1], dp[i][j] + x * abs(k - j));
            chmax(dp[i + 1][j], dp[i][j] + x * abs(n - 1 - i + j - k));
        }
    }
    int ans = 0;
    rep(i, n + 1) {
        chmax(ans, dp[n][i]);
    }
    cout << ans << endl;
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(10);
	//int t; cin >> t; rep(i, t)solve();
	solve();
    return 0;
}

Measured memory_bytes: 35588
import sys

def debug(x, table):
    for name, val in table.items():
        if x is val:
            print('DEBUG:{} -> {}'.format(name, val), file=sys.stderr)
            return None

def solve():
    N = int(input())
    s, b = 0, 0

    for loop in range(N):
        t, a = map(int, sys.stdin.readline().split())

        if loop == 0:
            s, b = t, a
        else:
            k = max((s + t - 1)//t, (b + a - 1)//a)
            s, b = k*t, k*a

    ans = s + b
    print(ans)



if __name__ == '__main__':
    solve()

Measured memory_bytes: 3064