akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define INF 1000000000
#define REP(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
typedef long long LL;

#define BITTYPE int

#define BITCNT  2

#define BITSIZE 512345

namespace _BIT{

    int i=0;

    BITTYPE t[2][BITSIZE];

    inline BITTYPE* get(){

        return t[i++];

    }

}



struct BIT{

    using T=BITTYPE;

    T *t;

    int n;

    BIT(int N):t(_BIT::get()),n(N+1){

        REP(i,n+1)t[i]=0;

    }

    void add(int r,T v){//add v for [1,r]

        for(;r;r-=r&-r)t[r]+=v;

    }

    void add(int l,int r,T v){//add v for [l,r]

        add(r,v);

        add(l-1,-v);

    }

    T get(int i){//get sum[i]

        T res=0;

        for(;i<=n;i+=i&-i)res+=t[i];

        return res;

    }

};

typedef pair<int,int> P;
int l[300001];
int r[300001];
vector<P>v;
int main(){
    int N,M;
    cin>>N>>M;
    BIT bit(300001);
    REP(i,N){
        cin>>l[i]>>r[i];
        v.push_back(make_pair(r[i]-l[i],i));
    }
    sort(v.begin(),v.end());//ここで，ソート
    
    int a=0;
    REP(i,M){
        int j=i+1;
        while(a<N){
           if(v[a].first+1>=j)break;
           bit.add(l[v[a].second],r[v[a].second],1);
           a++;
        }
        LL ans=N-a;
        for(int k=j;k<=M;k=k+j){
            ans+=bit.get(k);
        }
        cout<<ans<<endl;
    }
    
    return 0;
}

Measured memory_bytes: 7664
k, a, b = map(int, input().split(' '))

ans = 1
if b - a <= 2:
    # No Exchange
    ans += k
elif k < (a - 1) + 2:
    # cannot do first exchange
    ans += k
else:
    k -= (a - 1) + 2
    ans = b
    ans += (b - a) * int(k / 2)
    if k % 2 == 1:
        ans += 1

print(ans)


Measured memory_bytes: 3060
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int[] A = new int[N];
		for (int i = 0; i < N; i++) {
			A[i] = sc.nextInt();
		}
		for (int i = 0; i < N; i++) {
			if (A[i] % 2 == 0) {
				if (!(A[i] % 3 == 0 || A[i] % 5 == 0)) {
					System.out.println("DENIED");
					return;
				}
			}
		}
		System.out.println("APPROVED");
	}
}

Measured memory_bytes: 21844
/* ＵＴＦ－８ */
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <list>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <array>
#include <queue>
#include <stack>
#include <algorithm>
#include <tuple>
#include <numeric>
#include <type_traits>
#include <limits>

#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <string.h>

#define USE_COLORED 1

#ifdef USE_COLORED
static const char stdout_pre[]  = "\033[1m"; // bold black
static const char stderr_pre[]  = "\033[31;1m"; // bold red
static const char stdxxx_post[] = "\033[m";

// 当然ながら GCC(g++)/libstdc++ 依存
#include <ext/stdio_filebuf.h>
using stdio_filebuf = __gnu_cxx::stdio_filebuf<char>;
class colored_stdio_filebuf : public stdio_filebuf {
private:
	const char* const pre_;
	const char* const post_;

public:
	colored_stdio_filebuf(FILE* fp, const char* pre, const char* post) : stdio_filebuf(fp, std::ios_base::out), pre_(pre), post_(post)
	{
	}

protected:
	std::streamsize xsputn(const char* s, std::streamsize count) override
	{
		stdio_filebuf::xsputn(pre_, strlen(pre_));
		auto ret = stdio_filebuf::xsputn(s, count);
		stdio_filebuf::xsputn(post_, strlen(post_));
		return ret;
	}
};
#endif

int main()
{
#ifdef USE_COLORED
	if (getenv("DEBUG")) {
		std::cout.rdbuf(new colored_stdio_filebuf(stdout, stdout_pre, stdxxx_post));
		std::cerr.rdbuf(new colored_stdio_filebuf(stderr, stderr_pre, stdxxx_post));
	} else
#endif
	{
		int fd = open("/dev/null", O_WRONLY);
		dup2(fd, 2);
		close(fd);
	}
	std::string s;
	std::cin >> s;
	s.insert(4, " ");
	std::cout << s << "\n";
}


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

pair<int, int> f[2500];
int e[51][51], p[50] = {}, c[50];
int j, y;

void dfs(int v) {
    c[v] = 1;
    if (v == f[j].second) y = 1;
    for (int i = 0; i < p[v]; i++) {
        int u = e[v][i];
        if (f[j].first == v && f[j].second == u) continue;
        if (f[j].first == u && f[j].second == v) continue;
        if (c[u]) continue;
        if (y) continue;
        dfs(u);
    }
}

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

    for (int i = 0; i < m; i++) {
        int a, b;
        cin >> a >> b;
        a--; b--;

        e[a][p[a]++] = b;
        e[b][p[b]++] = a;
        f[i] = { a, b };
    }

    int r = 0;
    for (int i = 0; i < m; i++) {
        for (int l = 0; l < 50; l++) c[l] = 0;
        j = i;
        y = 0;
        dfs(f[j].first);
        r += y;
    }

    cout << m - r << endl;

    return 0;
}

Measured memory_bytes: 256
import std.stdio;
import std.conv;
import std.string;
import std.typecons;
import std.algorithm;
import std.array;
import std.range;
import std.math;
import std.regex : regex;
import std.container;
import std.bigint;
import std.ascii;


void main()
{
  int m, d;
  readf("%s %s\n", &m, &d);
  
  int cnt;
  foreach (i; 1..m+1) {
    foreach (j; 1..d+1) {
      auto d1 = j % 10;
      auto d10 = j / 10;
      if (d1 >= 2 && d10 >= 2 && d1 * d10 == i) {
        cnt++;
      }
    }
  }
  cnt.writeln;
}


Measured memory_bytes: 256
#pragma GCC optimize ("O3")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse4")
#include"bits/stdc++.h"
using namespace std;
typedef long long ll;
#define int ll
#define all(x) x.begin(), x.end()
#define trav(i,a) for(auto &i:a) 
inline int in(){int x;scanf("%lld",&x);return x;}
int32_t main()
{
	
	string d;
	cin>>d;
	int ans=0;int s=0;
	for(auto i:d)
	{
		if(i=='R')s++;
		else s=0;
		ans=max(s,ans);
	}
	ans=max(s,ans);
	cout<<ans;
	
	
}

Measured memory_bytes: 3624
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
using namespace std;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)

typedef long long ll;
typedef pair<int, int> P;
typedef pair<int, double> Pid;
typedef pair<double, int> Pdi;
const double PI = 3.1415926535897932;   // acos(-1)
const double EPS = 1e-15;
const int INF = 1001001001;
const int mod = 1e+9 + 7;

#define chadd(x, y) x = (x + y) % mod

ll dp[10005][105][2];

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

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

    dp[0][0][1] = 1;
    for(int i = 0; i < n; ++i){
        int num = s[i] - '0';
        for(int m = 0; m < 10; ++m){
            for(int j = 0; j < d; ++j){
                int after = (m + j) % d;
                if(m > num){
                    chadd(dp[i+1][after][0], dp[i][j][0]);
                }
                else if(m == num){
                    chadd(dp[i+1][after][1], dp[i][j][1]);
                    chadd(dp[i+1][after][0], dp[i][j][0]);
                }
                else{   // m < num
                    chadd(dp[i+1][after][0], dp[i][j][1]);
                    chadd(dp[i+1][after][0], dp[i][j][0]);
                }
            }
        }
    }

    // for(int i = 0; i <= n; ++i){
    //     for(int j = 0; j < d; ++j){
    //         for(int k = 0; k < 2; ++k){
    //             cerr << dp[i][j][k] << " ";
    //         }
    //         cerr << "\n";
    //     }
    //     cerr << "\n";
    // }

    // -1 は 0 の分を取り除くための減算処理
    ll res = (dp[n][0][0] + dp[n][0][1] - 1) % mod;
    if(res < 0) res += mod;
    cout << res << endl;
}

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

using namespace std;

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

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

    long g = 0;
    long count = 1;
    for (int j=0;j<n;j++){
        g += a[j];
        if (g<=x){
            count++;
        }
    }

    cout << count << endl;

    return 0;
}


Measured memory_bytes: 3552
function Main(input) {
  input = input.trim()
  input = input.split("\n");
  var N = input[0];
  input.shift();
  var arr = new Array(26).fill(0);
  var mem = new Array(26).fill(0);
      var A = input[0].split("");
  for(var i=0;i<input[0].length;i++){
    arr[A[i].charCodeAt(0)-97]++;
  }
  for(i=1;i<N;i++){
    var str = input[i].split("");
    for(var j=0;j<str.length;j++){
     mem[str[j].charCodeAt(0)-97]++;
    }
    for(var k=0;k<26;k++){
    if(arr[k]>mem[k]){
    arr[k]=mem[k]
    }
    }
    mem.fill(0);
  }
  for(var p=0;p<26;p++){
    for(var e=0;e<arr[p];e++){
     process.stdout.write(String.fromCharCode(p+97));
    }
  }
  console.log();
}Main(require("fs").readFileSync("/dev/stdin", "utf8"));

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

int main(){
  int n;
  cin >> n;
  vector<int> a(n) , cnt(100010);
  ll sum = 0;
  rep(i,n){
    cin >> a[i];
    sum += a[i];
    ++cnt[a[i]];
  }
  int q;
  cin >> q;
  vector<ll> ans(q);
  rep(i,q){
    int b , c;
    cin >> b >> c;
    sum += (c - b) * cnt[b];
    cnt[c] += cnt[b];
    cnt[b] = 0;
    ans[i] = sum;
  }
  for(ll x : ans) cout << x << endl;
  return 0;
}

Measured memory_bytes: 4752
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<queue>
#include<vector>
#include<map>
#include<list>
#include<cctype>
#include<climits>
#include<bitset>
#include<stack>

using namespace std;

typedef long long ll;

const int dx[4] = { 1, 0, -1, 0 }, dy[4] = { 0, 1, 0, -1 };
const int MAX = 18;
int W, H, fld[10][10];
int P, sx, sy;
map<pair<pair<int, int>, int>, int> memo;

inline int CountBit(int s)
{
	int res = 0;
	for (int i = 0; i < P; i++) res += (s >> i) & 1;
	return res;
}

inline bool IsInside(int x, int y)
{
	return 0 <= x && x < W && 0 <= y && y < H;
}

inline bool CanDown(int x, int y, int s, int noBits)
{
	if (x == sx && y == sy && noBits == P) return true;
	if (fld[y][x] == -1) return false;
	return ((s >> fld[y][x]) & 1) == 0;
}

int DFS(int x, int y, int s)
{
	int cnt = CountBit(s);
	if (x == sx && y == sy && cnt == P) return 1;
	pair<pair<int, int>, int> state = make_pair(make_pair(x, y), s);
	if (cnt < MAX)
	{
		map<pair<pair<int, int>, int>, int>::iterator itr = memo.find(state);
		if (itr != memo.end()) return itr->second;
	}
	int sum = 0;
	for (int i = 0; i < 4; i++)
	{
		int nx = x + dx[i], ny = y + dy[i];
		while (IsInside(nx, ny) && !CanDown(nx, ny, s, cnt))
			nx += dx[i], ny += dy[i];
		if (!IsInside(nx, ny)) continue;
		sum += DFS(nx, ny, s | (1 << fld[ny][nx]));
	}
	if (cnt < MAX) memo[state] = sum;
	return sum;
}

signed main()
{
	while (cin >> W >> H, W || H)
	{
		memo.clear();
		P = 0;
		for (int i = 0; i < H; i++)
		{
			for (int j = 0; j < W; j++)
			{
				cin >> fld[i][j];
				if (fld[i][j] == 0) fld[i][j] = -1;
				else if (fld[i][j] == 1) fld[i][j] = P++;
				else sx = j, sy = i, fld[i][j] = -1;
			}
		}
		printf("%d\n", DFS(sx, sy, 0));
	}
	return 0;
}

Measured memory_bytes: 57480
package main

import (
	"fmt"
	"math"
)

func main() {
	var n int
	fmt.Scan(&n)

	n--
	e := 1
	border := 26
	preB := 0
	for true {
		if n < border {
			n -= preB
			break
		}
		e++
		preB = border
		border += int(math.Pow(26, float64(e)))
	}

	num26 := make([]int, e)
	for i := 0; i < e; i++ {
		t := n % 26
		num26[i] = t

		m := n / 26
		if m < 26 {
			if m != 0 {
				num26[i+1] = m
			}
			break
		}

		n = (n - t) / 26
	}

	abc := []string{}
	for i := 0; i < len(num26); i++ {
		s := fmt.Sprintf("%q", num26[i]+97)
		abc = append(abc, string(s[1]))
	}

	for i := len(abc) - 1; i >= 0; i-- {
		fmt.Print(abc[i])
	}
	fmt.Println()
}


Measured memory_bytes: 1836
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <queue>
#include <map>
#include <numeric>
#include <unordered_map>
#include <iomanip>
#include <functional>
#include <bitset>
#include <complex>
#include <stack>



#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define all(x) (x).begin(),(x).end()

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

typedef long long ll;

using namespace std;


int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  string s;cin>>s;
  for(auto& c:s){
    if(c==',')c=' ';
  }
  cout<<s<<endl;

  return 0;

}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Text;

namespace AtTest.D_Challenge
{
    class ABC_084
    {
        static void Main(string[] args)
        {
            Method(args);
            Console.ReadLine();
        }

        static void Method(string[] args)
        {
            int q = ReadInt();
            long[] likes = LikeNumbers(1, 100000);
            var cnts = new int[100000];
            int likeIndex = 0;
            cnts[0]= 0;
            for (int i = 1; i < cnts.Length; i++)
            {
                cnts[i] = cnts[i - 1];
                if (likeIndex < likes.Length
                    && i + 1 == likes[likeIndex])
                {
                    cnts[i]++;
                    likeIndex++;
                }
                //Console.WriteLine(cnts[i]);
            }
            var lrs = new int[q][];
            for(int i = 0; i < q; i++)
            {
                lrs[i] = ReadInts();
            }

            for(int i = 0; i < q; i++)
            {
                int val = cnts[lrs[i][1] - 1];
                if (lrs[i][0] - 2 >= 0)
                {
                    val -= cnts[lrs[i][0] - 2];
                }
                Console.WriteLine(val);
            }
        }

        static long[] LikeNumbers(long min, long max)
        {
            var likes = new List<long>();
            var primeDict = new Dictionary<long,bool>();
            primeDict.Add(2, true);
            for (long i = 3; i <= max; i += 2)
            {
                long rootI = (long)Math.Sqrt(i);
                bool isPrime = true;
                for (long j = 3; j <= rootI; j += 2)
                {
                    if (i % j == 0)
                    {
                        isPrime = false;
                        break;
                    }
                    else
                    {
                        continue;
                    }
                }
                if (isPrime)
                {
                    if (primeDict.ContainsKey((i + 1) / 2))
                    {
                        likes.Add(i);
                    }
                    primeDict.Add(i, true);
                }
            }
            return likes.ToArray();
        }

        private static string Read() { return Console.ReadLine(); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }
    }
}


Measured memory_bytes: 23752
#include <bits/stdc++.h>
#include <chrono>
using namespace std;
typedef long long ll;
#define tr(container, it) \
    for (auto it = container.begin(); it != container.end(); it++)
#define scontains(c, x) ((c).find(x) != (c).end())   //O(log n)
#define contains(c, x) (find((c).begin(),(c).end(),x) != (c).end()) //O(n)
#define ill(_x)  ll _x;scanf("%lld",&_x);
#define idb(_x)  double _x;scanf("%lf",&_x);
#define pll pair<ll,ll>
#define pii pair<int,int>
#define mll map<ll,ll>
#define vll vector<ll>
#define sll set<ll>
#define vs vector<string>
#define in0(x, a, b)((x)>=a && (x)<=b    )
#define in1(x, a, b)((x)>a && (x)<b)
#define  rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
const double PI = 3.14159265358979323846;
const double E  = 2.71828182845904523536;
const int INF = 0x3f3f3f3f;
const int MOD = (int) (1e9) + 7;

pair<ll,ll> f1(ll* A, int i,int j){
    ll sum=A[j]-A[i];
    int pos = lower_bound(A+i+1,A+j,sum/2+A[i]) - A;
    pos-=(j==pos);
    if(pos>1+i){
        if(abs(2*(A[pos]-A[i])-sum)<abs(2*(A[pos-1]-A[i])-sum))return {A[pos]-A[i],A[j]-A[pos]};
        return {A[pos-1]-A[i],A[j]-A[pos-1]};
    }
    return {A[pos]-A[i],A[j]-A[pos]};


}

ll dif(ll a, ll b, ll c, ll d){
    vector<ll> v={a,b,c,d};
    sort(v.begin(),v.end());
    return v[3]-v[0];
}

ll S[202222];
void _(){
    int n; cin >> n;
    ll sum=0;
    S[0]=0;
    for (int i = 1; i <n+1; ++i) {
        ll t; cin >> t;
        sum+=t;
        S[i] = sum;
    }
    ll mi=LLONG_MAX;
    for (int i = 2; i < n; ++i) {
        pair<ll,ll> p1=f1(S,0,i);
        pair<ll,ll> p2=f1(S,i,n);

        mi= min(mi,dif(p1.first,p1.second,p2.first,p2.second));

    }

    cout << mi << "\n";



}


int main() {
#ifdef debug
    freopen("/home/joduskame/Desktop/cp/IO/Input.txt", "r", stdin);
    freopen("/home/joduskame/Desktop/cp/IO/Output.txt", "w", stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
#endif


    _();
    return 0;

}








Measured memory_bytes: 1920
class SegmentTree():
    """一点更新、区間取得クエリをそれぞれO(logN)で答えるデータ構造を構築する
    update: i番目をvalに変更する
    get_min: 区間[begin, end)の最小値を求める
    """
    def __init__(self, n):
        self.n = n
        self.INF = 10**18
        self.size = 1
        while self.size < n:
            self.size *= 2
        self.node = [self.INF] * (2*self.size - 1)

    def update(self, i, val):
        i += (self.size - 1)
        self.node[i] = val
        while i > 0:
            i = (i - 1) // 2
            self.node[i] = min(self.node[2*i + 1], self.node[2*i + 2])

    def get_min(self, begin, end):
        begin += (self.size - 1)
        end += (self.size - 1)
        s = self.INF
        while begin < end:
            if (end - 1) & 1:
                end -= 1
                s = min(s, self.node[end])
            if (begin - 1) & 1:
                s = min(s, self.node[begin])
                begin += 1
            begin = (begin - 1) // 2
            end = (end - 1) // 2
        return s


from operator import itemgetter


n, m = map(int, input().split())
info = [list(map(int, input().split())) for i in range(m)]

info = sorted(info, key = itemgetter(1))
st = SegmentTree(n)
st.update(0, 0)

i = 0
for num in range(n+1):
    while True:
        if i >= m:
            break
        if info[i][1] != num:
            break
        else:
            l = info[i][0] - 1
            r = num
            tmp = min(st.get_min(l, r) + info[i][2], st.get_min(num - 1, num))
            st.update(num-1, tmp)
            i += 1
ans = st.get_min(n-1, n)
if ans == 10**18:
    print(-1)
else:
    print(ans)

Measured memory_bytes: 134464
#pragma region Macros
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define rep2(i, a, b) for(ll i = a; i <= b; ++i)
#define rep(i, n) for(i = 0; i < n; ++i)
#define rep3(i, a, b) for(ll i = a; i >= b; --i)
using namespace std;

// _________コーディングはここから！！___________
template <typename T = long long, const int sz = 5 * 10000000> struct IO {
    char reader[sz], writer[sz];
    char *now, *now2 = writer;
    IO() {
        reader[fread(reader, sizeof(char), sizeof(char) * sz, stdin)];
        now = reader;
    }
    inline T read() {
        while(*now && *now <= 32) now++;
        if(*now == '-') {
            now++;
            T res = 0;
            while('0' <= *now and *now <= '9') { res = res * 10 + *now++ - '0'; }
            return -res;
        } else {
            T res = 0;
            while('0' <= *now and *now <= '9') { res = res * 10 + *now++ - '0'; }
            return res;
        }
    }
    inline string read_str() {
        string res;
        while(*now and *now != '\n' and *now != ' ') res += *now++;
        now++;
        return res;
    }
    inline void write(T x, char margin = ' ') {
        if(x == 0) {
            putchar('0');
            putchar(margin);
            return;
        }
        if(x < 0) {
            putchar('-');
            x = -x;
        }
        while(x) {
            *now2 = '0' + x % 10;
            now2++;
            x /= 10;
        }
        do {
            now2--;
            putchar(*now2);
        } while(now2 != writer);
        putchar(margin);
    }
    inline void write_str(string s, char margin = ' ') {
        for(auto c : s) putchar(c);
        putchar(margin);
    }
};
IO<int> io;
int n, m, k,i;
constexpr int MAX = 1e9 + 1;
constexpr int N = 200010;
int a[N], b[N];
int nn,now,ans;
main() {
    n = io.read(), m = io.read(), k = io.read();
    nn = n;
    rep(i, n) {
        a[i + 1] = io.read() + a[i];
        if(a[i + 1] > k) {
            nn = i;
            ++i;
            for(; i < n; ++i) {
                while(*io.now && *io.now <= 32) io.now++;
                while('0' <= *io.now and *io.now <= '9') io.now++;
            }
            break;
        }
    }
    rep(i, m) {
        b[i + 1] = io.read() + b[i];
        if(b[i + 1] > k) {
            m = i;
            break;
        }
    }
    now = nn;
    ans = now;
    for(i = 1; i <= m; i++) {
        while(b[i] + a[now] > k) now--;
        ans = max(ans, i + now);
    }
    io.write(ans);
}


Measured memory_bytes: 7840
n,m = map(int,input().split())
ac = [0]*(n+1)
wa = [0]*(n+1)
for i in range(m):
    p,s = input().split()
    p = int(p)
    if s=="AC":
        ac[p]=1
    else:
        if ac[p] ==0:
            wa[p]+=1
w = 0
for i in range(n+1):
    if ac[i] ==1:
        w+=wa[i]
print(sum(ac),w)


Measured memory_bytes: 4596
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <queue>
#include <list>
#include <cmath>
#include <stack>
#include <iomanip>

using namespace std;
typedef long long ll;
using Pll = pair<ll,ll>;

const ll INF = 1LL<<60;
const ll MOD = 1000000007;

//cout << fixed << setprecision(10);

int main() {
    
    ll N,X;
    cin >> N >> X;
    vector<ll> L(N);
    for(int i=0;i<N;i++) cin >> L[i];
    ll tmp=0;
    ll ans=1;
    for(int i=0;i<N;i++){
        tmp+=L[i];
        if(tmp<=X) ans++;
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
//ios::sync_with_stdio(false);
//cin.tie(0);
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<pii,int> ppii;
typedef pair<int,pii> pipi;
typedef pair<ll,ll> pll;
typedef pair<pll,ll> ppll;
typedef pair<ll,pll> plpl;
typedef tuple<ll,ll,ll> tl;
ll mod=1000000007;
ll mod2=998244353;
ll inf=1000000000000000000;
double pi=2*acos(0);
#define rep(i,m,n) for(ll i=m;i<n;i++)
#define rrep(i,n,m) for(ll i=n;i>=m;i--)
int dh[4]={1,-1,0,0};
int dw[4]={0,0,1,-1};
int ddh[8]={-1,-1,-1,0,0,1,1,1};
int ddw[8]={-1,0,1,-1,1,-1,0,1};
ll lmax(ll a,ll b){
    if(a<b)return b;
    else return a;
}
ll lmin(ll a,ll b){
    if(a<b)return a;
    else return b;
}
ll gcd(ll a,ll b){
    if(a<b)swap(a,b);
    if(a%b==0)return b;
    return gcd(b,a%b);
}
ll Pow(ll n,ll k){
    ll ret=1;
    ll now=n;
    while(k>0){
        if(k&1)ret*=now;
        now*=now;
        k/=2;
    }
    return ret;
}
ll gya[200010];
ll kai[200010];
ll m;
ll beki(ll n,ll k){
  ll ret=1;
  ll now=n;
  while(k>0){
    if(k%2==1){
      ret*=now;
      ret%=m;
    }
    now*=now;
    now%=m;
    k/=2;
  }
  return ret;
}
ll gyaku(ll n){
  return beki(n,mod-2);
}
void nckinit(ll n){
  kai[0]=1;
  kai[1]=1;
  for(int i=2;i<=n;i++){
    kai[i]=kai[i-1]*i;
    kai[i]%=mod;
  }
  gya[n]=gyaku(kai[n]);
  for(int i=n-1;i>=1;i--){
    gya[i]=gya[i+1]*(i+1);
    gya[i]%=mod;
  }
  gya[0]=1;
}    
ll nck(ll n,ll k){
  if(k<0)return 0;
  if(k==0||n==k)return 1;
  ll ret=kai[n];
  ret*=gya[n-k];
  ret%=mod;
  ret*=gya[k];
  ret%=mod;
  return ret;
}
ll npk(ll n,ll k){
  if(k<0)return 0;
  if(k==0)return 1;
  ll ret=kai[n];
  ret*=gya[n-k];
  ret%=mod;
  return ret;
}
int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
 int a,b;cin>>a>>b;
  if(b==1){
    cout<<0<<endl;
    return 0;
  }
  int y=a-1;
  rep(i,1,100){
    if(a>=b){
      cout<<i<<endl;
      return 0;
    }
    a+=y;
  }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int,int>;
constexpr ll INF = 9e18;
constexpr int inf = 1e9;
constexpr double INFD = 1e100;
constexpr ll mod = 1000000007;
const double PI = 3.1415926535897932384626433832795028841971;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
};
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
};
 
// intやllをstringに変換
template<typename T> inline string toString(const T &a){
  ostringstream oss;
  oss << a;
  return oss.str();
};
// ---------------------------------------------------------------------------

int main(){
  string S;
  cin >> S;
  int Q;
  cin >> Q;
  string pre = "";
  string suf = "";
  int cnt = 0;
  for(int i=0; i<Q; i++){
    int id;
    cin >> id;
    if(id == 1){
      cnt++;
    }else{
      int id2;
      cin >> id2;
      string T;
      cin >> T;
      if(cnt%2){
        if(id2 == 1){
          suf += T;
        }else{
          pre += T;
        }
      }else{
        if(id2 == 1){
          pre += T;
        }else{
          suf += T;
        }
      }
    }
  }
  if(cnt%2){
    reverse(S.begin(),S.end());
    reverse(suf.begin(),suf.end());
    S = suf + S + pre;
  }else{
    reverse(pre.begin(),pre.end());
    S = pre + S + suf;
  }
  cout << S << endl;
  return 0;
}


Measured memory_bytes: 1348
#include<iostream>
#include<vector>
#include<algorithm>
#include<cctype>
#include<utility>
#include<string>
#include<cmath>
#include<cstring>
#include<queue>
#include<map>
#include<set>

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)

using namespace std;

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


template<typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }
template<typename T, typename... Ts>
auto make_v(size_t a, Ts... ts) {
	return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template<typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T& t, const V& v) { t = v; }
template<typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T& t, const V& v) {
	for (auto& e : t) fill_v(e, v);
}


#define ARRAY_MAX 100005
const int INF = 1e9;
const ll MOD = 1e9 + 7;

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




/******************************************************************************************/


int main() {

	

	string s;
	cin >> s;
	if (s == "Sunny") {
		cout << "Cloudy" << endl;
	}
	else if (s == "Cloudy") {
		cout << "Rainy" << endl;
	}
	else
	{
		cout << "Sunny" << endl;
	}






	return 0;
}


Measured memory_bytes: 256
#[allow(unused_imports)]
use proconio::{fastout, input};

#[fastout]
fn main() {
    input!(a_1: usize, a_2: usize, a_3: usize);
    println!("{}", if a_1 + a_2 + a_3 >= 22 { "bust" } else { "win" });
}


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

int main()
{
  char s[100001],t[100001];
  int i;
  int n,m;
  scanf("%s",s);
  n=strlen(s);
  m=(n+1)/2;
  for(i=0;i<m;i++){
    t[i]=s[2*i];
  }
  printf("%s",t);
  return 0;
}


Measured memory_bytes: 1876
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>

#define ll long long 
#define fr(i,n) for(int i=0;i<n;i++)
#define pb push_back
#define inf (1<<31)

using namespace std;

int main() {
	ios::sync_with_stdio(0);
	int s,k;
	cin>>k>>s;
	long int ans=0;
	fr(i,k+1){
		fr(j,k+1){
			if(s-i-j<=k && s-i-j>=0)
				ans++;
		}
	}
	cout<<ans;
	return 0;
}

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

#define _ << " _ " <<
#define TRACE(x) cout << #x << " = " << x << endl

int n, p[200010], pos[200010];

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

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


    int sol = n + 1;
    for (int i = 0; i < n; i++) {
        int j;
        for (j = i + 1; j <= n && pos[j] > pos[j - 1]; j++) {}
        sol = min(sol, n - (j - i));
        i = j - 1;                                                                                      
    }

    cout << sol;

    return 0;
}


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

using ll = long long;

void solve(long long N, long long M, long long K, std::vector<long long> A, std::vector<long long> B){
    vector<ll> ruisekiA, ruisekiB;
    ruisekiA.push_back(0);
    ruisekiB.push_back(0);
    for(int i = 0;i < N;i++){
        ruisekiA.push_back(ruisekiA.back() + A[i]);
    }
     for(int i = 0;i < M;i++){
        ruisekiB.push_back(ruisekiB.back() + B[i]);
    }
    int ans = 0;
    for(int i = 0;i <= N;i++){
        ll cost = ruisekiA[i];
        if(cost > K)break;
        int ok = 0;
        int ng = M + 1;
        while(ng - ok > 1){
            int mid = (ok + ng) / 2;
            if(ruisekiB[mid] + cost > K){
                ng = mid;
            }else{
                ok = mid;
            }
        }
        ans = max(ans, ok + i);
    }
    cout<<ans<<endl;;
}

int main(){
    long long N;
    scanf("%lld",&N);
    long long M;
    scanf("%lld",&M);
    long long K;
    scanf("%lld",&K);
    std::vector<long long> A(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&A[i]);
    }
    std::vector<long long> B(M);
    for(int i = 0 ; i < M ; i++){
        scanf("%lld",&B[i]);
    }
    solve(N, M, K, std::move(A), std::move(B));
    return 0;
}


Measured memory_bytes: 11148
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <stack>
#include <cmath>
#include <queue>
#include <numeric>



int main()
{
	long long a, b, c, d;

	std::cin >> a >> b >> c >> d;

	if (a + b == c + d) {
		std::cout << "Balanced" << std::endl;
	}
	else if (a + b < c + d) {
		std::cout << "Right" << std::endl;
	}
	else {
		std::cout << "Left" << std::endl;
	}

	return 0;
}


Measured memory_bytes: 256
from sys import stdin
import sys

N, K = [int(x) for x in stdin.readline().rstrip().split()]
ans = N
temp = 0

if N % K == 0:
    print("0")
    sys.exit()
N = N % K
while N != K:
    # print(ans, abs(N-K), abs(temp-K))
    N = abs(N-K)
    # print(ans, abs(N-K), abs(temp-K))
    if abs(N-K) == temp:
        print(ans)
        sys.exit()
    temp = N
    if N < ans:
        ans = N


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

int main() {
  string S, T, U;
  int A, B;
  cin >> S >> T;
  cin >> A >> B;
  cin >> U;
  if (S == U) A -= 1;
  if (T == U) B -= 1;
  cout << A << " " << B << "\n";
  return 0;
}

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

void solve()
{
	long long A,B,C,D;
	scanf("%lld%lld%lld%lld",&A,&B,&C,&D);
	if (A<B)
	{
		puts("No");
		return;
	}
	if (B>D)
	{
		puts("No");
		return;
	}
	if (B<=C)
	{
		puts("Yes");
		return;
	}
	if (D%B==0)
	{
		puts(A%B>C?"No":"Yes");
		return;
	}
	long long g=__gcd(B,D),a=A%B,c=C%B,tmp=((c+B+g-a)/g*g+a)%B;
	if (tmp>c)
	{
		puts("No");
		return;
	}
	puts("Yes");
}

int main()
{
	int T;
	scanf("%d",&T);
	while (T--) solve();
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define int long long
#define endl "\n"
using namespace std;



int32_t main() {

    fast
    int x;
    cin >> x;

    if(x <= 599) {
        cout << 8 << endl;
    } else if(x <= 799) {
        cout << 7 << endl;
    }    else if(x <= 999) {
        cout << 6 << endl;
    } else if(x <= 1199) {
        cout << 5 << endl;
    } else if(x <= 1399) {
        cout << 4 << endl;
    }    else if(x <= 1599) {
        cout << 3 << endl;
    } else if(x <= 1799) {
        cout << 2 << endl;
    } else {
        cout << 1 << endl;
    }




    return 0;
}



Measured memory_bytes: 3632
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
string s[100];
int main()
{
  int N, L;
  ios::sync_with_stdio(false);
  cin >> N >> L;
  for( int i=0; i<N; i++ ){
    cin >> s[i];
  }
  sort( s, s+N );
  for( int i=0; i<N; i++ ){
    cout << s[i];
  }
  cout << endl;
}

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


def main():
    n = int(input())
    a = list(map(int, input().split()))
    count = 0
    number = 1

    for ai in a:
        if ai == number:
            number += 1
        else:
            count += 1

    if count == n:
        print(-1)
    else:
        print(count)


if __name__ == '__main__':
    main()


Measured memory_bytes: 26268
N,K = map(int,input().split(" "))
h = list(map(int,input().split(" ")))

dp = [float('inf')] * N
dp[0] = 0
dp[1] = dp[0] + abs(h[1]-h[0])

for i in range(2,N):
    for j in range(1,min(K+1,i+1)):
        dp[i] = min(dp[i],dp[i-j]+abs(h[i]-h[i-j]))

print(dp[N-1])

Measured memory_bytes: 54644
def main():
    sx, sy, tx, ty = map(int, input().split())
    dx = tx - sx
    dy = ty - sy

    ans = ''
    ans += 'R' * dx + 'U' * dy
    ans += 'L' * dx + 'D' * dy
    ans += 'L' + 'U' * (dy + 1) + 'R' * (dx + 1) + 'D'
    ans += 'R' + 'D' * (dy + 1) + 'L' * (dx + 1) + 'U'

    print(ans)


if __name__ == '__main__':
    main()

# import sys
#
# sys.setrecursionlimit(10 ** 7)
#
# input = sys.stdin.readline
# rstrip()
# int(input())
# map(int, input().split())


Measured memory_bytes: 3060
#
# 　　  ⋀_⋀　 
#　　  (･ω･)  
# .／ Ｕ ∽ Ｕ＼
#  │＊　合　＊│
#  │＊　格　＊│ 
#  │＊　祈　＊│ 
#  │＊　願　＊│ 
#  │＊　　　＊│ 
#      ￣
#
import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
from math import floor,sqrt,factorial,hypot,log #log2ないｙｐ
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from fractions import gcd
from random import randint
def ceil(a,b): return (a+b-1)//b
inf=float('inf')
mod = 10**9+7
def pprint(*A): 
    for a in A:     print(*a,sep='\n')
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')

def main():
    N,M=MI()
    *S,=ST().split()
    *T,=ST().split()

    dp = [[1]*(M+1) for _ in range(N+1)]
    for i,s in enumerate(S,start=1):
        for j,t in enumerate(T,start=1):
            if s==t:
                dp[i][j] = (dp[i-1][j] + dp[i][j-1])%mod
            else:
                dp[i][j] = (dp[i-1][j] + dp[i][j-1] - dp[i-1][j-1])%mod
    print(dp[-1][-1])
if __name__ == '__main__':
    main()

Measured memory_bytes: 97368
def median(array):
    if N % 2:
        return array[N // 2]
    else:
        return sum(array[N // 2 - 1: N // 2 + 1])


N = int(input())
A, B = [], []
for _ in range(N):
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)
A.sort()
B.sort()
x = median(A)
y = median(B)
print(y - x + 1)

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

using namespace std;

int main() {
    long long n, m;
    cin >> n >> m;
    vector<long long> a{};
    for(long long i = 0; i < n; i++) {
        long long j;
        cin >> j;
        a.push_back(j - 1);
    }

    // fav=0だったときの総合数
    long long fav_0 = 0;
    for (long long i = 0; i < n - 1; i++) {
        fav_0 += min( (a[i + 1] - a[i] + m) % m, a[i + 1] + 1 );
    }

    // between[fav] = a_i と a_i+1 の間に fav がある i の数
    vector<long long> between(m, 0);
    for (long long i = 0; i < n - 1; i++) {
        if (a[i + 1] < a[i] && a[i + 1] != 0) {
            between[0]++;
        }
    }
    vector<long long> table(m, 0);
    for (long long i = 0; i < n - 1; i++) {
        table[(a[i] + 1) % m]++;
        table[a[i + 1]]--;
    }
    for (long long i = 1; i < m; i++) {
        between[i] =  between[i - 1] + table[i];
    }

    vector<long long> on(m, 0);
    for (long long i = 0; i < n - 1; i++) {
        on[a[i+1]] += (a[i + 1] - a[i] + m) % m - 1;
    }

    vector<long long> result{fav_0};
    for(long long fav = 1; fav < m; fav++) {
        result.push_back(result[fav-1] - between[fav-1] + on[fav-1]);
    }

    cout << *min_element(result.begin(), result.end()) << endl;


    return 0;
}


Measured memory_bytes: 4852
H, W = map(int, input().split())
s = [input() for i in range(H)]

dx = [-1, 0, 0, 1]
dy = [0, 1, -1, 0]
for i in range(H):
    for j in range(W):
        if s[i][j] == '#':
            flag = False
            for k in range(4):
                if s[i][j] == '#':
                    nx = j + dx[k]
                    ny = i + dy[k]
                    if nx < 0 or nx >= W or ny < 0 or ny >= H:
                        continue
                if s[ny][nx] == '#':
                    flag = True
            if flag == False:
                print('No')
                exit()        

print('Yes')

Measured memory_bytes: 39920
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
    	
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		int N = sc.nextInt();
//		String ans = "";
		StringBuilder ans = new StringBuilder();

		// Mapの宣言
        Map<String,Integer> map = new HashMap<>();
        
		for (int i = 1; i <= N;i ++ ){
			// 文字列の入力
			String str = sc.next();

        	map.put( str,i);

		}

		for (int i = 1; i <= N;i ++ ){
//        	if(ans.isEmpty()) {
//            	ans = "" + map.get(i);
//            }else {
//            	ans = ans + " " + map.get(i);
//        	}
//    		System.out.println(map.get(String.valueOf(i))+" ");
			ans.append(map.get(String.valueOf(i))+" ");
		}


		System.out.println(ans);
		
   		sc.close();
        return ;

    }
    
}



Measured memory_bytes: 71336
#include <iostream>
#include <iomanip>
#include <utility>
#include <cmath>
#include <random>
#include <vector>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <algorithm>
using namespace std;

#define rep(i,n) for(int i = 0; i<n; ++i)
#define REP(i,n) for(int i = 1; i<=n; ++i)
#define all(x) begin(x),end(x)
#define show(obj) {for(auto x:obj)cout<<x<<' ';cout<<endl;}
#define line "----------"
typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll,ll> LP;
const int inf = 1001001000;
const ll INF = 1LL<<60;
const int MOD = (int)1e9 + 7;

template<class T> inline bool chmax(T& a, T b) {if (a < b) { a = b; return true; } return false;}
string lcs(string a, string b){
	vector<vector<int>> dp(a.size()+1, vector<int>(b.size()+1, 0));
	vector<vector<P>> transition(a.size()+1, vector<P>(b.size()+1));
	REP(i,a.size()){
		REP(j,b.size()){
			if(a[i-1] == b[j-1]){
				dp[i][j] = dp[i-1][j-1]+1;
				transition[i][j] = make_pair(i-1, j-1);
			}else{
				if(chmax(dp[i][j], dp[i-1][j]))transition[i][j] = make_pair(i-1, j);
				if(chmax(dp[i][j], dp[i][j-1]))transition[i][j] = make_pair(i, j-1);
			}
		}
	}
	string res;
	int i = a.size(), j = b.size();
	while(true){
		if(i == 0 || j == 0)break;
		if(a[i-1] == b[j-1])res.push_back(a[i-1]);
		P from = transition[i][j];
		i = from.first;
		j = from.second;
	}
	reverse(all(res));
	return res;
}

int main(){
	string s, t;
	cin >> s >> t;
	cout << lcs(s, t) << endl;
	return 0;
}


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

using namespace std;

map<long long int,long long int> prime_factor(long long int n){
    map<long long int,long long int> res;
    for(long long int i=2;i*i<=n;i++){
        while(n%i==0){
            ++res[i];
            n/=i;
        }
    }

    if(n!=1){
        res[n] = 1;
    }
    return res;
}

int main(){
    long long int N,ans=0;
    vector<long long int> vec(100);

    vec[0] = 1;

    for(int i=1;i<100;i++){
        vec[i] = vec[i-1] + i+1;
    }

    cin >> N;

    map<long long int,long long int> mp;

    mp = prime_factor(N);

    for(auto itr = mp.begin();itr!=mp.end();++itr){

        for(int j=0;j<100;j++){
            if(itr->second<vec[j]){
                ans += j;
                break;
            }
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 3636
#include <cstdio>
#include <algorithm>
#include <ctype.h>
const int bufSize = 1e6;
inline char nc()
{
    #ifdef DEBUG
    return getchar();
    #endif
    static char buf[bufSize], *p1 = buf, *p2 = buf;
    return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, bufSize, stdin), p1 == p2) ? EOF : *p1++;
}
inline void read(char *s)
{
    static char c;
    for (; !isalpha(c); c = nc());
    for (; isalpha(c); c = nc()) *s++ = c;
    *s = '\0';
}
template<typename T>
inline T read(T &r)
{
    static char c;
    static int flag;
    flag = 1, r = 0;
    for (c = nc(); !isdigit(c); c = nc()) if (c == '-') flag = -1;
    for (; isdigit(c); c = nc()) r = r * 10 + c - 48;
    return r *= flag;
}
long long X,K,D;
int main()
{
    read(X),read(K),read(D);
    X = std::abs(X);
    long long steps = X / D;
    if(steps >= K)
    {
        printf("%lld\n",X - K * D);
        return 0;
    }
    K -= steps;
    long long mina = X - steps * D, minb = std::abs(mina - D);
//    printf("%lld %lld\n",mina,minb);
    if(K & 1) printf("%lld\n",minb);
    else printf("%lld\n",mina);
//    printf("%lld\n",std::min(mina,minb));
    return 0;
}

Measured memory_bytes: 3232
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
long long inf=(long long)1E17;
#define i_7 (long long)(1E9+7)
long mod(long a){
    long long c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
using namespace std;
long long gcd(long long a, long long b){
  if(a<b){
    swap(a,b);
  }
  if(a%b==0){
    return b;
  }else{
    return gcd(b,a%b);
  }
}
 
long long lcm(long long x, long long y){
  return (x/gcd(x,y))*y;
}
 
class UnionFind {
    public:
    //各頂点の親の番号を格納する。その頂点自身が親だった場合は-(その集合のサイズ)を入れる。
    vector<int> Parent;
    
    //クラスを作るときは、Parentの値を全て-1にする。
    //以下のようにすると全てバラバラの頂点として解釈できる。
    UnionFind(int N) {
        Parent = vector<int>(N, -1);
    }
    
    //Aがどのグループに属しているか調べる
    int root(int A) {
        if (Parent[A] < 0) return A;
        return Parent[A] = root(Parent[A]);
    }
    
    //自分のいるグループの頂点数を調べる
    int size(int A) {
        return -Parent[root(A)];//先祖をrootで取っておきたい。
    }
    
    //AとBをくっ付ける
    bool connect(int A, int B) {
        //AとBを直接つなぐのではなく、root(A)にroot(B)をくっつける
        A = root(A);
        B = root(B);
        if (A == B) {
            //すでにくっついてるからくっ付けない
            return false;
        }
        
        //大きい方(A)に小さいほう(B)をくっ付けたい
        //大小が逆だったらAとBをひっくり返す。
        if (size(A) < size(B)) swap(A, B);
        
        //Aのサイズを更新する
        Parent[A] += Parent[B];
        //Bの親をAに変更する
        Parent[B] = A;
        
        return true;
    }
};
 
int main(){
  long long x;
  cin>>x;
  long long time;
  int rest;
  time = x/11;
  rest = x%11;
  long long ans;
  if(rest==0){
    ans = 2*time;
  }else if(rest<=6){
    ans = 2*time+1;
  }else{
    ans = 2*time+2;
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
def popcount_int(n):
    return bin(n).count('1')

def popcount_bin(s):
    return s.count('1')

def poptimes(n,cnt=1):
    if n==0:
        return cnt
    else:
        n%=popcount_int(n)
        cnt+=1
        return poptimes(n,cnt)

N=int(input())
S=input()

S_int=int(S,2)
pc=popcount_bin(S)
pc_plus=S_int%(pc+1)
if pc!=1:
    pc_minus=S_int%(pc-1)

for i in range(N):
    if S[i]=='1':
        if pc!=1:
            tmp=pc_minus-pow(2,N-i-1,pc-1)
            print(poptimes(tmp%(pc-1)))
        else:
            print(0)
            continue
    else:
        tmp=pc_plus+pow(2,N-i-1,pc+1)
        print(poptimes(tmp%(pc+1)))

Measured memory_bytes: 9488
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, gcd
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7 
#mod = 998244353
from decimal import *
#import numpy as np
#decimal.getcontext().prec = 10

N = INT()
A = LIST()
a = [abs(x) for x in A] #Aの絶対値

n = sum([A[i] != a[i] for i in range(N)]) #Aの中で負のものは何個あるか

if n%2:
	print(sum(a) - 2*min(a))
else:
	print(sum(a))


Measured memory_bytes: 21772
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,b,t,time,sum=0;
    cin>>a>>b>>t;
    time=t+0.5;
    if(time<a)
    {
        cout<<"0"<<endl;
    }
    else
    {
        for(int i=a; i<=time; i=i+a)
        {
            sum=sum+b;
        }
        cout<<sum<<endl;
    }

    return 0;
}





Measured memory_bytes: 256
# ABC-145-D
X, Y = map(int, input().split())
ans = 0
mod = 10**9 + 7

# 組み合わせを出す関数
# https://qiita.com/derodero24/items/91b6468e66923a87f39f
def cmb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2,r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result

if (X + Y) % 3 != 0: 
    ans = 0
else:
    #(+1,+2)を行う回数nを求める。
    n = (2*Y - X)//3
    #(+2,+1)を行う回数mを求める。    
    m = Y - 2*n
    if n < 0 or m < 0:
        ans = 0
    else:
        ans = cmb(n+m, n)
    
print(ans%mod)

Measured memory_bytes: 44148
s = input()
if(s[0]=='0')|(s[-1]=='1'):
    print(-1)
    exit()

n = len(s)
size = []
for i in range(1,n//2):
    sl = s[i]
    sr = s[n-2-i]
    if(sl != sr):
        print(-1)
        exit()
    if(sl=='1'):
        size.append(i+1)

size.append(n-1)
ans = []
now = 1
for si in size:
    for j in range(now+1,si+2):
        ans.append(' '.join(map(str,[now,j])))
    now = si+1

print('\n'.join(ans))

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

int main()
{
  int n;
  cin >> n;
  vector<int> a(100000,0);
  int k;
  long s = 0;
  for(int i = 0; i<n;++i){
    cin >> k;
    a[k-1]++;
    s+= (long)k;
  }
  int q;
  cin >> q;
  int b,c;
  
  for(int i = 0; i<q;++i){
    cin >> b >> c;
    a[c-1] += a[b-1];
    s += (long)(c - b)*(long)a[b-1];
    a[b-1] = 0;
    cout << s << endl;
  }
 
}


Measured memory_bytes: 3780