akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

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

const int INF = 1e18;

int N, A, B, C;
vector<int> l;

// 「使用する可能性のある竹の集合」と「目標の長さ」を渡すと、目標の長さにするための最小コストを返してくれる
int calc2(vector<int> v, int val) {
  int ret = INF;
  int n = v.size();

  // 竹の集合の使い方を全列挙
  for (int mask = 0; mask < (1LL << n); mask++) {
    int cnt = 0;
    int sum = 0;
    for (int i = 0; i < n; i++) {
      if (mask & (1LL << i)) {
        sum += v[i];
        cnt++;
      }
    }
    if (cnt == 0) continue;
    chmin(ret, (cnt-1)*10 + abs(sum - val));
  }

  return ret;
}

// Aに使う竹、Bに使う竹、Cに使う竹の集合を渡すと、それぞれの目標の高さにするまでの最小コストを返してくれる
int calc(vector<int> a, vector<int> b, vector<int> c) {
  return calc2(a, A) + calc2(b, B) + calc2(c, C);
}

// 「Aに使う可能性のある竹の集合」「Bに使う可能性のある竹の集合」「Bに使う可能性のある竹の集合」を全列挙
int rec(int idx, vector<int> a, vector<int> b, vector<int> c) {
  if (idx >= N) {
    if (a.size() == 0 || b.size() == 0 || c.size() == 0) return INF;
    return calc(a, b, c);
  }

  int ret = INF;

  // idx番目の竹ををAに使う
  a.push_back(l[idx]);
  chmin(ret, rec(idx+1, a, b, c));
  a.pop_back();

  // idx番目の竹ををBに使う
  b.push_back(l[idx]);
  chmin(ret, rec(idx+1, a, b, c));
  b.pop_back();

  // idx番目の竹ををCに使う
  c.push_back(l[idx]);
  chmin(ret, rec(idx+1, a, b, c));
  c.pop_back();

  return ret;
}

signed main() {
  cin >> N >> A >> B >> C;
  l.resize(N);
  for (int i = 0; i < N; i++) {
    cin >> l[i];
  }

  vector<int> a;
  vector<int> b;
  vector<int> c;
  int ans = rec(0, a, b, c);

  cout << ans << endl;

  return 0;
}

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

int main()
{
  char S[26];

  scanf("%s", S);

  if(S[1] != '\0')
  {
    for(int i=0; S[i] != '\0'; i++)
    {
      for(int j=i+1; S[j] != '\0'; j++)
      {
        if(S[i] == S[j])
        {
          printf("no\n");
          return 0;
          }
      }
    }
    printf("yes\n");
  }

  return 0;
}


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

using namespace std;
using vi = vector<int>;

int const NMAX = 2e5 + 11;

int n, ans[NMAX];
vi  g[NMAX];

void dfs(int u, int p = -1)
{
    for (auto v : g[u])
    {
        if (v == p)
            continue;
        ans[v] += ans[u];
        dfs(v, u);
    }
}

int main(void)
{
    int q, u, v, p, x;
    cin >> n >> q;

    for (int i = 0; i < n - 1; ++i)
    {
        cin >> u >> v, u--, v--;
        g[u].push_back(v);
        g[v].push_back(u);
    }

    while (q--)
    {
        cin >> p >> x, p--;
        ans[p] += x;
    }
    dfs(0);
    for_each(ans, ans + n, [](int x) { cout << x << " "; }), cout << endl;

    return 0;
}


Measured memory_bytes: 27748
N,M=map(int,input().split())
A=list(map(int,input().split()))

import sys

limit=sum(A)/(4*M)
A.sort()
A=A[::-1]
for i in range(M):
    if A[i] < limit:
        print('No')
        sys.exit()
else:
    print('Yes')

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize ("-ffloat-store") // to restrict undesirable precision
#pragma GCC optimize ("-fno-defer-pop")// to pop argument of function as soon as it returns
#define all(a) a.begin(),a.end()
#define ll long long int
#define ld long double
ll power(ll a,ll b,ll m){ if(b==0) return 1; if(b==1) return a%m; ll t=power(a,b/2,m)%m; t=(t*t)%m; if(b&1) t=((t%m)*(a%m))%m; return t;}
ll modInverse(ll a, ll m) { return power(a, m-2, m); }
#define ps push_back
#define fs first
#define sc second
#define takeline cin.ignore();
#define iactive cout.flush();
#define N 3000005
#define endl "\n"
#define mod 1000000007
//((1.0l)*BIG MULTIPLY MAGIC?)
// string to integer stoi()
// string to long long stoll()
// string.substr(position,length);
// integer to string to_string();
//-----------------------------------------------
int main(){
	
	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	
	ll n,m;
	cin>>n>>m;
	if(n==m){
		cout<<"Yes";
	}
	else cout<<"No";
	return 0;
}

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

const string YES = "Yes";
const string NO = "No";

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long N,K,Q;cin >> N >> K >> Q;
    if(K > Q){
        for(int i=0;i < N;i++) cout << "Yes" << endl;
        return 0;
    }
    vector<long long> point(N,K - Q);
    for(long long i=0;i < Q;i++){
        long long n; cin >> n;
        point[n - 1] += 1;
    }

    for(int i=0;i < N;i++){
        if(point[i] > 0) cout << YES << endl;
        else cout << NO << endl;
    }

    return 0;
}


Measured memory_bytes: 1280
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <string>
#include <cmath>
#include <stack>
#include <queue>
#include <list>
#include <set>
using namespace std;
#define INF 1010101010
#define MOD 1000000007
#define LL long long
using Coord = pair<int, int>;

int main() {
    int n, m;
    cin >> n >> m;
    vector<int> a(n), b(n), c(m), d(m);
    for (int i = 0; i < n; i++) cin >> a[i] >> b[i];
    for (int i = 0; i < m; i++) cin >> c[i] >> d[i];
    for (int i = 0; i < n; i++) {
        int mj, md = INF;
        for (int j = 0; j < m; j++) {
            int t = abs(a[i] - c[j]) + abs(b[i] - d[j]);
            if (t < md) {
                md = t;
                mj = j;
            }
        }
        cout << mj + 1 << endl;
    }
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        
        int n = sc.nextInt();
        int min = 0, max = 0, i;
        long sum = 0;
        int [] num = new int[n];
        
        for(i = 0; i < n; i++){
            num[i] = sc.nextInt();
            sum += num[i];
        }
        min = num[0];
        max = num[0];
        for(i = 0;i<n;i++){
            if(min > num[i]) min = num[i];
            if(max < num[i]) max = num[i];
        }
        System.out.println(min+" "+max+" "+sum);
    }
}


Measured memory_bytes: 41348
#include<iostream>
using namespace std;
 
int main(){
 int S;
 cin >> S;
 int h,m,s;
 h = S / 3600;
 m = (S - h*3600) / 60;
 s = S - h*3600 -60*m;
 
 cout << h << ":" << m << ":" << s << endl;
 
}


Measured memory_bytes: 3112
n=int(input())
a=[[int(i) for i in input().split()] for i in range(2)]
koho=[]
for i in range(n):
    if i==0:
        cnt=a[0][0]+sum(a[0][0:i])+sum(a[1][i:])
    else:
        cnt=sum(a[0][0:i+1])+sum(a[1][i:])
    koho.append(cnt)
print(max(koho))

Measured memory_bytes: 3064
#include<iostream>
#include<cstdio>
#include<vector>
#include<algorithm>
using namespace std;
int main(){
	int H,W;
while(true){
cin>>H>>W;
if(H==0&&W==0)break;
	for(int i=0;i<W;i++)cout<<"#";cout<<endl;
	
	for(int i=1;i<H-1;i++){
		for(int j=0;j<W;j++){
			if(j==0||j==W-1)cout<<"#";
			else cout<<".";
		}
		cout<<endl;
	}
	for(int i=0;i<W;i++)cout<<"#";cout<<endl;
	cout<<endl;
}
return 0;
}

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

#define pb         push_back

typedef long long ll;
const ll INF = 1000000000ll;
const ll MOD = 1000000007ll;
const double EPS = 1e-8;

int main(void) {
	//ios_base::sync_with_stdio(false);
	//cin.tie(0);
	
	long long w, h;
	vector<int> p;
	vector<int> q;
	vector<pair<long long, int> > e;

	cin >> w >> h;
	for(int i=0; i<w; i++){
		int tp;
		cin >> tp;
		p.push_back(tp);
		e.push_back(make_pair(tp, 0));
	}
	for(int i=0; i<h; i++){
		int tq;
		cin >> tq;
		q.push_back(tq);
		e.push_back(make_pair(tq, 1));
	}

	sort(p.begin(), p.end());
	sort(q.begin(), q.end());
	sort(e.begin(), e.end());

	int lr = 0;
	int td = 0;
	long long ans = 0;
	for(int i=0; i<e.size(); i++){
		if(e[i].second == 0){
			ans += e[i].first * (h+1 - td);
			lr++;
		}else if(e[i].second == 1){
			ans += e[i].first * (w+1 - lr);
			td++;
		}
	}

	cout << ans << endl;
	

	return 0;
}


Measured memory_bytes: 5232
import java.util.*;
import java.io.*;
import static java.lang.Math.*;

public class Main {
    public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		
		// 入力
		int n = sc.nextInt();
		
		// 計算
		long result = n*(n+1)/2;
		
		// 出力
		System.out.println(result);
	}
	
	public static class Scanner {
		private BufferedReader br; private StringTokenizer tok;
		public Scanner(InputStream is) throws IOException { br = new BufferedReader(new InputStreamReader(is));}
		private void getLine() throws IOException { while(!hasNext()) tok = new StringTokenizer(br.readLine());}
		private boolean hasNext() { return tok != null && tok.hasMoreTokens();}
		public String next() throws IOException { getLine(); return tok.nextToken();}
		public int nextInt() throws IOException { return Integer.parseInt(next());}
		public long nextLong() throws IOException { return Long.parseLong(next());}
		public double nextDouble() throws IOException { return Double.parseDouble(next());}
	}
}



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

int main() {
  int d; cin >> d;
  int n = 26;
  vector<int> c(n), t(d);
  vector<vector<int>> s(d, vector<int>(n));
  rep(i,n) cin >> c[i];
  rep(i,d) {
    rep(j,n) {
      cin >> s[i][j];
    }
  }
  rep(i,d) {
    int d = 0;
    rep(j,n) {
      if (d < s[i][j]) {
        t[i] = j+1;
        d = s[i][j];
      }
    }
  }
  for (auto ti : t) {
    cout << ti << endl;
  }
}

Measured memory_bytes: 3680
#include <algorithm>
#include <iostream>
#include <numeric>
#include <vector>
int main(int, char **) {
  double m, n;
  std::cin >> n >> m;
  std::vector<double> a(n);
  for (int i = 0; i < n; ++i) {
    std::cin >> a.at(i);
  }
  const double total = std::accumulate(a.begin(), a.end(), 0);
  const double kagen = total * (1 / (4 * m));
  //[&] { std::cout << "kagen ==" << kagen << "\n"; }();
  std::sort(a.begin(), a.end(), std::greater<int>());
  int i = 0;  // iこめの人気商品
  for (const auto &ai : a) {
    //[&] { std::cout << "Ai == " << ai << std::endl; }();
    if (ai < kagen) {
      //[&] { std::cout << "Ai : " << ai << " < " << kagen << std::endl; }();
      break;
    } else {
      ++i;
    }
  }
  //[&] { std::cout << i << "\n"; }();
  std::cout << (i >= m ? "Yes" : "No") << std::endl;
}

Measured memory_bytes: 256
def main():
    N = int(input())
    S = list(input())
    K = int(input())
    spec_s = S[K-1]
    ans = ""
    for i in range(len(S)):
        if S[i] != spec_s:
            S[i] = '*'
    for x in S:
        ans += x
    print(ans)
main()

Measured memory_bytes: 3060
let S = readLine()!.characters.map{String($0)}
var ans = S.count
for i in 0..<2 {
    var cnt = 0
    for j in 0..<S.count {
        if j%2^i != Int(S[j]) {
            cnt += 1
        }
    }
    ans = min(ans, cnt)
}
print(ans)

Measured memory_bytes: 7808
#include <algorithm>
#include <bitset>
#include <cstdio>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#define REP(i, b, n) for (Int i = b; i < Int(n); i++)
#define rep(i, n) REP(i, 0, n)
using namespace std;
using Int = long long;
Int inf = 1000000000000000001LL;
using vi = vector<Int>;
using vvi = vector<vi>;

Int GCD(Int a, Int b){
    if(b==0) return a;
    if(a < b) return GCD(b, a);
    unsigned r;
    while ((r=a%b)) {
        a = b;
        b = r;
    }
    return b;
}

int main() {
    Int N,K;
    cin >> N>>K;
    vi H = vi(N);
    Int ans =inf;

    rep(i,N){
        cin >> H[i];
    }

    sort(H.begin(),H.end());
    Int tree_count = K-1;
    REP(i,tree_count,N){
        Int hmin = H[i-tree_count];
        Int hmax = H[i];
        ans = min(ans, hmax-hmin);
    }

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

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

int main() {
  int n,m,tmp1,tmp2;
  cin >> n >> m;
  
  vector<int> data(n);
  if(n == 1 && m == 0){
    cout << 0 << endl; 
    return 0;    
  }
  
  for(int i = 0; i < m; i++){
    cin >> tmp1 >> tmp2;
    //桁は有効か
    if(tmp1 > n){
     cout << -1 << endl; 
     return 0;
    }
    //0の場合
    if(tmp2 == 0){
      //桁が桁数と一致していない場合は不正
      if(tmp1 != n){
        cout << -1 << endl; 
        return 0;  
      }
    }
    //既に値が入っている場合で違う値の場合
    if(data.at(tmp1 - 1) != 0 && data.at(tmp1 - 1) != tmp2){
        cout << -1 << endl; 
        return 0;
    }
    data.at(tmp1 - 1) = tmp2;
  }

  for(int i = 0; i < n; i++){
    if(i == 0 && data.at(i) == 0 && n != 1){
      data.at(i) = 1;
    }
  }
  
  for(int i = 0; i < n; i++){
    cout << data.at(i);
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
    string s;
    int count_A = 0,count_Z = 0;
    cin >> s;
    for(int i = 0; i < s.size(); i++){
        if(s[i] == 'A'){
            count_A = i;
            break;
        }
    }
    for(int j = s.size(); j >=0; j--){
        if(s[j] == 'Z'){
            count_Z = j;
            break;
        }
    }

    cout << count_Z - count_A + 1 << endl;
}

Measured memory_bytes: 640
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Linq;
using static MyIO;


public class B
{
	public static void Main()
	{
		string S = GetString();

		int[] num = new int[3];
		for(int i = 0; i < S.Length; i++)
			num[(int)(S[i] - 'a')]++;

		for(int i = 0; i < 3; i++)
		{
			for(int j = i + 1; j < 3; j++)
			{
				if(Math.Abs(num[i] - num[j]) > 1)
				{
					Console.WriteLine("NO");
					return;
				}
			}
		}
		Console.WriteLine("YES");
	}
}


public static class MyIO
{
	private static string[] args = null;
	private static int num = -1;
	private static int used = -1;

	private static string getArg()
	{
		if(used == num)
		{
			args = Console.ReadLine().Split(' ');
			num = args.Length;
			used = 0;
		}
		return args[used++];
	}

	public static int GetInt(){ return int.Parse(getArg()); }
	public static long GetLong(){ return long.Parse(getArg()); }
	public static double GetDouble(){ return double.Parse(getArg()); }
	public static string GetString(){ return getArg(); }
}


Measured memory_bytes: 13140
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, a, b) for (int i = a; i < b; i++)
//'A' = 65, 'Z' = 90, 'a' = 97, 'z' = 122

int main()
{
    int n;
    cin >> n;
    int x[n];
    int ans = -1e9;
    int mn = 2e9;
    rep(i, 0, n) {
        cin >> x[i];
        if (i == 0) continue;
        mn = min(mn, x[i - 1]);
        ans = max(ans, x[i] - mn);
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 3884
#include<algorithm>
#include<bitset>
#include<cassert>
#include<cfloat>
#include<climits>
#include<cmath>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<map>
#include<queue>
#include<array>
#include<set>
#include<stack>
#include<string>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>

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


//ユークリッド互除法
template<typename T>
T gcd(T x, T y) {

	if (y == 0) {
		return x;
	}
	else {
		return gcd(y, x % y);
	}
}

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


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

int dx4[4] = { 1,0,0,-1 };
int dy4[4] = { 0,1,-1,0 };
int dx2[2] = { 1,0 };
int dy2[2] = { 0,1 };

/******************************************************************************************/
typedef tuple<int,int,int> tpl;

template <typename T> bool next_combination(const T first, const T last, int k) {
    const T subset = first + k;
    // empty container | k = 0 | k == n 
    if (first == last || first == subset || last == subset) {
        return false;
    }
    T src = subset;
    while (first != src) {
        src--;
        if (*src < *(last - 1)) {
            T dest = subset;
            while (*src >= *dest) {
                dest++;
            }
            iter_swap(src, dest);
            rotate(src + 1, dest + 1, last);
            rotate(subset, subset + (last - dest) - 1, last);
            return true;
        }
    }
    // restore
    rotate(first, subset, last);
    return false;
}

int main() {

	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(10);

	ll N;
	string S;
	cin >> N >> S;

	ll R = 0;
	ll G = 0;
	ll B = 0;

	for(int i = 0;i < S.size();i++){
		if(S[i] == 'R'){
			R++;
		}
		if(S[i] == 'G'){
			G++;
		}
		if(S[i] == 'B'){
			B++;
		}
	}

	ll ans = R*G*B;

	ll rgb = 'R'-'A'+'G'-'A'+'B'-'A';
	
	for(int i = 0;i < N;i++){
		for(int j = i+1;j < N;j++){
			int other = j+j-i;
			int num = S[i]-'A'+S[j]-'A'+S[other]-'A';
			if(other < N && num==rgb){
				ans--;
			}
		}
	}

	cout << ans << endl;

	return 0;
}






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

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


typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pi> vpi;

#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define all(x) x.begin(), x.end()

const int MOD = 1000000007;
const ll INF = 1e18;

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

int main() {
	ios_base::sync_with_stdio(0); cin.tie(0);
	ll n; cin>>n;
	if(n%2==1) cout<<0<<endl;
	else
	{
	ll s=0,k=10;
	while(k<=n) s+=n/k, k*=5;
	cout<<s<<endl;
	}
	
    return 0;
}


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

const int MOD = 1000000007;
const int INF_32 = 1LL << 30;
const int64_t INF_64 = 1LL << 60;

int main()
{
    char alpha;
    cin >> alpha;
    if (alpha >= 'a' && alpha <= 'z') {
        cout << 'a' << endl;
    } else {
        cout << 'A' << endl;
    }
    return 0;
}


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

int main(){
  int N;
  cin >> N;
  long long a;
  vector <long long> s;
  for(int i = 0;i < N;i++){
    cin >> a;
    s.push_back(a);
  }
  long long sum = 0;
  sort(s.begin(),s.end());
  for(int i = 0;i < N;i++){
    long long m = s[i];
    int j = i;
    while(s[i] == m){
      i++;
    }
    if((i-j)%2 == 1){
      sum++;
    }
    i--;
  }
  cout << sum << endl;

}


Measured memory_bytes: 1400
# include <bits/stdc++.h>
# define ll long long 
using namespace std;
const ll N = 5e5 + 10, mod = 1e9 + 7;
string s;
int n, m, q, tree[26][N];
void upd(int x, int y, int z){
    while(x <= n){
        tree[z][x] += y;
        x += x & -x;
    }
}
int query(int x, int y){
    int ans = 0;
    while(x){
        ans += tree[y][x];
        x -= x & -x; 
    }
    return ans;
}
int main(){
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    cin >> n >> s >> q;
    s = "#" + s;
    for(int i = 1; i <= n; i++){
        upd(i, 1, s[i] - 'a');
    }
    while(q --){
        int ty;
        cin >> ty;
        if(ty == 1){
            int x;
            char y;
            cin >> x >> y;
            upd(x, -1, s[x] - 'a');
            s[x] = y;
            upd(x, 1, s[x] - 'a');
        }else{
            int l, r, sum = 0;
            cin >> l >> r;
            for(int i = 0; i < 26; i++){
                sum += (query(r, i) - query(l - 1, i)) > 0;
            }
            cout << sum << endl;
        }
    }
}

Measured memory_bytes: 51760
package main

import (
	"fmt"
)

func main() {
	var n, d1, d2, cnt int
	fmt.Scan(&n)

	for i := 0; i < n; i++ {
		fmt.Scan(&d1, &d2)
		if d1 == d2 {
			cnt++
		} else {
			cnt = 0
		}
		if cnt > 2 {
			fmt.Println("Yes")
			return
		}
	}
	fmt.Println("No")
}


Measured memory_bytes: 1772
#include <iostream>

using namespace std;

#define N 110
#define K 100'010
#define MOD 1'000'000'007

int main() {
  int32_t n, k;
  cin >> n >> k;

  auto a = new uint32_t[N];
  for (int32_t i = 1; i <= n; ++i) {
    cin >> a[i];
  }

  auto dp = new uint32_t[N][K];
  dp[0][0] = 1;
  for (int32_t j = 1; j <= k; ++j) {
    dp[0][j] = 0;
  }

  for (int32_t i = 1; i <= n; ++i) {
    dp[i][0] = 1;
    auto ai = a[i];
    for (int32_t j = 1; j <= ai; ++j) {
      dp[i][j] = (dp[i][j-1] + dp[i-1][j]) % MOD;
    }
    for (int32_t j = ai + 1; j <= k; ++j) {
      dp[i][j] = (dp[i][j-1] + dp[i-1][j] - dp[i-1][j-ai-1] + MOD) % MOD;
    }
  }

  cout << dp[n][k] << endl;
}


Measured memory_bytes: 41216
import sys
from bisect import bisect_left

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    A, B, Q = map(int, readline().split())
    S = [-INF]
    S.extend(int(readline()) for _ in range(A))
    S.append(INF)
    T = [-INF]
    T.extend(int(readline()) for _ in range(B))
    T.append(INF)
    X = [int(readline()) for _ in range(Q)]

    ans = [INF] * Q
    for i, x in enumerate(X):
        idx_s = bisect_left(S, x)
        idx_t = bisect_left(T, x)

        for s in (S[idx_s - 1], S[idx_s]):
            for t in (T[idx_t - 1], T[idx_t]):
                ans[i] = min(ans[i], abs(x - s) + abs(s - t), abs(x - t) + abs(t - s))

    print('\n'.join(map(str, ans)))

    return


if __name__ == '__main__':
    main()


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

int main(){
  int a,b;
  cin >> a >> b;
  if(a==1) a=14;
  if(b==1) b=14;
  if(b<a) cout << "Alice" << endl;
  else if(a<b) cout << "Bob" << endl;
  else cout << "Draw" << endl;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10**6)
INF = 10 ** 9 + 1  # sys.maxsize # float("inf")
MOD = 10 ** 9 + 7

# dsu / UnionFind


def init_unionfind(N):
    global parent, rank
    parent = [-1] * N
    rank = [0] * N


def find_root(x):
    p = parent[x]
    if p == -1:
        return x
    p2 = find_root(p)
    parent[x] = p2
    return p2


def unite(x, y):
    x = find_root(x)
    y = find_root(y)
    if x == y:
        return  # already united
    if rank[x] < rank[y]:
        parent[x] = y
    else:
        parent[y] = x
        if rank[x] == rank[y]:
            rank[x] += 1


def is_connected(x, y):
    return (find_root(x) == find_root(y))

# acl/dsu


def init(n):
    init_unionfind(n)


def merge(a, b):
    unite(a, b)
    # FIXME: return value


def same(a, b):
    return is_connected(a, b)


def leader(a):
    return find_root(a)


def size(a):
    raise NotImplementedError


def group(a):
    raise NotImplementedError
# ---


def debug(*x):
    print(*x, file=sys.stderr)


def main():
    # parse input
    N, Q = map(int, input().split())
    init(N)
    for _q in range(Q):
        q, u, v = map(int, input().split())
        if q == 0:
            merge(u, v)
        else:
            print(int(same(u, v)))


# tests
T1 = """
4 7
1 0 1
0 0 1
0 2 3
1 0 1
1 1 2
0 0 2
1 1 3
"""
TEST_T1 = """
>>> as_input(T1)
>>> main()
0
1
0
1
"""


def _test():
    import doctest
    doctest.testmod()
    g = globals()
    for k in sorted(g):
        if k.startswith("TEST_"):
            doctest.run_docstring_examples(g[k], g, name=k)


def as_input(s):
    "use in test, use given string as input file"
    import io
    f = io.StringIO(s.strip())
    g = globals()
    g["input"] = lambda: bytes(f.readline(), "ascii")
    g["read"] = lambda: bytes(f.read(), "ascii")


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

if sys.argv[-1] == "-t":
    print("testing")
    _test()
    sys.exit()

main()


Measured memory_bytes: 81512
import java.util.*;
import java.io.*;

public class Main {
	private static void solve(){
		//Implement solution here.
		int a = ni();
		int b = ni();
		int result = 0;
		if(a >= 6 && a <= 12) {
			result = b/2;
		} else if( a > 12) {
			result = b;
		}
		System.out.println(result);
	}

	//Switch input source (stdin/file)
	private static BufferedReader br  = new BufferedReader(new InputStreamReader(System.in));
	public static void main(String[] args){
		String debugDataPath = System.getenv("DD_PATH");        
		if(debugDataPath != null){
			try{
				br = new BufferedReader(new InputStreamReader(new FileInputStream(new File(debugDataPath))));
			}catch(Exception e){
				throw new RuntimeException(e);
			}
		}
		solve();
	}

	//Input read utility
	private static StringTokenizer tokenizer = null;
	public static String next() {
		while (tokenizer == null || !tokenizer.hasMoreTokens()) {
			try {
				tokenizer = new StringTokenizer(br.readLine());
			} catch (Exception e) {
				throw new RuntimeException(e);
			}
		}
		return tokenizer.nextToken();
	}
	//Get next single int
	private static int ni() {
		return Integer.parseInt(next());
	}
	//Get next single long
	private static long nl() {
		return Long.parseLong(next());
	}
	//Get next single double
	private static double nd() {
		return Double.parseDouble(next());
	}
	//Get next int array from one line
	private static int[] na(int n) {
		int[] a = new int[n];
		for (int i = 0; i < n; i++)
			a[i] = ni();
		return a;
	}
	//Get next char array from one line
	private static char[] ns() {
		return next().toCharArray();
	}
	//Get next long array from one line
	private static long[] nal(int n) {
		long[] a = new long[n];
		for (int i = 0; i < n; i++)
			a[i] = nl();
		return a;
	}
}

Measured memory_bytes: 23252
N,X,M=map(int,input().split())
ans=[X]
flag=0
for n in range(N):
    a=ans[-1]**2%M
    if a in ans:
        num=n
        flag=1
        break
    ans.append(a)
if flag==0:
    print(sum(ans[:-1]))
else:
    first = ans.index(a)
    if num==first:
        answer=sum(ans[:-1])+a*(N-num)
        print(answer)
    else:

        nums = ans[first:]
        rest = N - num
        answer = sum(ans)
        kaisuu = rest // (num - first + 1)
        answer += sum(nums) * kaisuu
        nokori = rest - kaisuu * (num - first + 1)
        answer += sum(nums[:nokori - 1])
        print(answer)
        

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

int main(){
	long long B;
	long long A;
	long long K;
	scanf("%lld",&K);
	scanf("%lld",&A);
	scanf("%lld",&B);
	long long res = 1, nokori = K;
	if (A+2 <= B && K>A) {
		res += A-res;
		nokori -= A-1;
		res += (B-A)*(nokori/2);
		nokori %= 2;
		res += nokori;
	} else {
		res += nokori;
	}
	printf("%lld\n", res);

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <numeric>
#include <algorithm>
#include <queue>
#include <set>
#include <map>
#include <cmath>

using namespace std;
using ll = long long;

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

#define CIN(T, x) T x; cin >> x;
#define CINS(T, x, N) vector<T> x(N); for(int i = 0; i < (N); i++) { cin >> x[i]; }
#define SHOW(x) for(int i = 0; i < x.size(); i++) { cout << x[i] << " "; } cout << "\n";
#define SHOW2(x) for(int j = 0; j < x.size(); j++) { SHOW(x[j]); } cout << "\n";


int main() {

    CIN(string, s);

    ll ans = 0;
    ll countA = 0;

    for (int i = 0; i < s.size() - 1; i++) {
        if (s[i] == 'A') {
            countA++;
        } else if ( s[i] == 'B' && s[i+1] == 'C' ) {
            i++;
            ans += countA;
        } else {
            countA = 0;
        }
    }

    cout << ans << "\n";
    return 0;
}

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

using namespace std;

const int INF = 1 << 30;

int vy[] = {0, 1, 0, -1}, vx[] = {1, 0, -1, 0};


int main()
{
  int H, W, K;
  string A[800];
  int sx, sy;
  int v[800][800];
  memset(v, -1, sizeof(v));


  cin >> H >> W >> K;
  for(int i = 0; i < H; i++) {
    cin >> A[i];
    for(int j = 0; j < W; j++) {
      if(A[i][j] == 'S') {
        sx = j;
        sy = i;
      }
    }
  }

  queue< pair< int, int > > que;
  que.emplace(sy, sx);
  v[sy][sx] = 0;
  while(!que.empty()) {
    auto p = que.front();
    que.pop();
    for(int i = 0; i < 4; i++) {
      int ny = p.first + vy[i], nx = p.second + vx[i];
      if(ny < 0 || nx < 0 || ny >= H || nx >= W) continue;
      if(A[ny][nx] == '#') continue;
      if(~v[ny][nx]) continue;
      v[ny][nx] = v[p.first][p.second] + 1;
      que.emplace(ny, nx);
    }
  }

  int ret = INF;

  auto getCost = [&](int y, int x)
  {
    int res = INF;
    res = min(res, y);
    res = min(res, x);
    res = min(res, W - x - 1);
    res = min(res, H - y - 1);
    if(res < 0) throw (0);
    return (res);
  };

  for(int i = 0; i < H; i++) {
    for(int j = 0; j < W; j++) {
      if(v[i][j] == -1) continue;
      int cost = v[i][j];
      if(cost > K) continue;
      ret = min(ret, (getCost(i, j) + K - 1) / K + 1);
    }
  }

  cout << ret << endl;
}

Measured memory_bytes: 3584
#!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from itertools import permutations
import sys
import math
import bisect
import random
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    def Z_algorithm(s):
        n = len(s)
        z = [0]*n
        z[0] = n
        c = 1
        for i in range(1,n):
            if i+z[i-c] < c+z[c]:
                z[i] = z[i-c]
            else:
                j = max(0,c+z[c]-i)
                while i+j < n and s[j] == s[i+j]:
                    j += 1
                z[i] = j
                c = i
        return z
    n = I()
    a = LI()
    b = LI()
    c = [a[i]^a[(i+1)%n] for i in range(n)]
    d = [b[i]^b[(i+1)%n] for i in range(n)]
    z = Z_algorithm(d+c*2)[n:2*n]
    for k in range(n):
        if z[k] >= n:
            print(k,a[k]^b[0])
    return

#Solve
if __name__ == "__main__":
    solve()


Measured memory_bytes: 119636
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef vector<vector<int> > Graph;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }


int main(){
    ll n,k,y;
    cin >> n >> k;
    if(n>=k){
        y=n%k;
    }
    else{
        y=n;
    }
    ll ans = min(y,k-y);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,n,s) for(int i=(s);i<(n);i++)
#define rrep(i,n) for(int i=(n-1);i>=0;i--)
#define rreps(i,n,s) for(int i=s;i>=n;i--)
#define MOD 1000000007
using ll = long long;
using namespace std;
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 (a>b) { a=b; return 1; } return 0; }

int main(){
cin.tie(0);
ios::sync_with_stdio(false);
int a, b, c, d;
cin >> a >> b >> c >> d;
int cnt = 0;
while(a>0&&c>0){
    if(cnt%2==0){
        c -= b;
    }
    else{
        a -= d;
    }
    cnt++;
}
if(c<=0){
    cout <<"Yes" <<endl;
}
else{
    cout << "No" << endl;
}
//system("pause");
return 0;
}

Measured memory_bytes: 3640
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mxn= 5e5+5;
#define mod 1000000007
#define endl '\n'
void rishabh(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
}
int get(int n){
    if(n%2==0)return n/2;
    else return 3*n+1;
}
int main(){
    set<int> s;
    int x;
    cin>>x;
    for(int i=2;;i++){
        s.insert(x);
        x=get(x);
        if(s.count(x)){
            cout<<i;
            return 0;
        }
    }
}



Measured memory_bytes: 3608
#include <iostream>
#include <algorithm>
#define ll long long
using namespace std;

int main(){
  int N; cin >> N;
  ll a[N]; ll sum=0;
  
  for(int i=0; i<N; i++){
    cin >> a[i]; sum = sum + a[i];
  }
  
  ll min; ll snuke=0;
  for(int i=0; i<N-1; i++){
    snuke = snuke + a[i];
    if(i==0 || min > abs(2*snuke-sum)){
      min = abs(2*snuke-sum);
    }  
  }
  
  cout << min;
  
  return 0;
}

Measured memory_bytes: 1792
// Template {{{
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0; i<(int)(n); ++i)
using namespace std;
typedef long long LL;

#ifdef LOCAL
#include "contest.h"
#else
#define error(args...) 
#endif

const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
inline bool valid(int x, int w) { return 0 <= x && x < w; }

void iostream_init() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.setf(ios::fixed);
    cout.precision(12);
}
//}}}

map<pair<int, int>, bool> memo;
bool dfs(int X, int Y) {
    if(X <= 1 && Y <= 1) { return false; }
    if(X > Y) { return dfs(Y, X); }
    auto state = make_pair(X, Y);
    if(memo.count(state)) { return memo[state]; }
    for(int i = 1; 2*i <= X; i++) {
        if(!dfs(X-2*i, Y+i)) {
            return memo[state] = true;
        }
    }
    for(int i = 1; 2*i <= Y; i++) {
        if(!dfs(X+i, Y-2*i)) {
            return memo[state] = true;
        }
    }
    return memo[state] = false;
}
int main(){
    iostream_init();
    // for(int x = 1; x <= 10; x++) {
    //     for(int y = 1; y <= 10; y++) {
    //         cout << x << " " << y << " = " << dfs(x, y) << endl;
    //     }
    // }
    // for(int x = 1; x <= 30; x++) {
    //     for(int y = 1; y <= 30; y++) {
    //         cout << dfs(x, y) ? 1 : 0;
    //         cout << " ";
    //     }
    //     cout << endl;
    // }
    LL X, Y;
    cin >> X >> Y;
    if(X < 10 && Y < 10) {
        cout << (dfs(X, Y) ? "Alice" : "Brown") << endl;
    } else if(abs(X - Y) > 1) {
        cout << "Alice" << endl;
    } else {
        cout << "Brown" << endl;
    }
    return 0;
}



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

int main(){
    int a,b,n;
    cin >> a>> b >> n;
    int ans=0;
    for(int i=0; i<n; i++){
        int s,f;
        cin >> s >> f;
        if((a<s && s<b) || (s<=a && a<f)){
            ans=1;
        }
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 3112
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < n; ++i)
#define rrep(i, n) for(int i = n-1; i >= 0; --i)
#define fi first
#define se second
using namespace std;
using lint = long long;
using uint = unsigned int;
using ulint = unsigned long long;
using ldouble = long double;
using pii = pair<int, int>;
using pli = pair<lint, lint>;
using pdd = pair<double, double>;
using pld = pair<ldouble, ldouble>;
using v1i = vector<int>;
using v1li = vector<lint>;
using v2i = vector<vector<int>>;
using v2li = vector<vector<lint>>;
using v3i = vector<vector<vector<int>>>;
using v3li = vector<vector<vector<lint>>>;
using v1b = vector<bool>;
using v2b = vector<vector<bool>>;
using v3b = vector<vector<vector<bool>>>;
using v1c = vector<char>;
using v2c = vector<vector<char>>;
using v3c = vector<vector<vector<char>>>;
constexpr lint mod1 = 1e9+7;
constexpr lint mod2 = 998244353;

int main() {
  int n, a = 0;
  string s;
  cin >> n >> s;
  vector<string> v(1000, "");
  rep(i, 1000){
    if(i < 10){
      v[i] += "00";
      v[i] += (char)'0' + i;
    }
    else if(i < 100){
      v[i] += '0';
      v[i] += (char)'0' + i/10;
      v[i] += (char)'0' + i%10;
    }
    else{
      v[i] += (char)'0' + i/100;
      v[i] += (char)'0' + i/10%10;
      v[i] += (char)'0' + i%10;
    }
  }
  rep(i, 1000){
    int tmp = 0;
    rep(j, s.size()){
      if(s[j] == v[i][tmp]) tmp++;
      if(tmp == 3) break;
    }
    if(tmp == 3) a++;
  }
  cout << a << endl;
  return 0;
}

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

int main(){
	cin.tie(0),ios::sync_with_stdio(false);
	int n; cin>>n;
	vector<int>h(n),cnt(n,0); for(auto&i:h)cin>>i;
	int ans=0;
	for(int i=0;h!=cnt;i=0){
		int w=100;
		while(i<n&&h.at(i)==0)++i;
		if(i==n)break;
		int j=i+1;
		while(j<n&&h.at(j)!=0)++j;
		for(int k=i;k<j;++k)w=min(w,h.at(k));
		for(int k=i;k<j;++k)h.at(k)-=w;
		ans+=w;
	}
	cout<<ans<<"\n"s;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define reps(i, n) for(int i = 1; i <= (int)(n); i++)
#define rrep(i, n) for(int i = ((int)(n)-1); i >= 0; i--)
#define srep(i, from, to) for(int i = from; i < (int)(to); i++)
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;

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

  return 0;
}


Measured memory_bytes: 256
import sys
import numpy as np
import random
from decimal import Decimal
import itertools
import re
import bisect
from collections import deque, Counter
from functools import lru_cache

sys.setrecursionlimit(10**9)
INF = 10**13
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
def SERIES(n): return np.fromstring(sys.stdin.buffer.read(), dtype=np.int32, sep=' ')
def GRID(h,w): return np.fromstring(sys.stdin.buffer.read(), dtype=np.int32, sep=' ').reshape(h,-1)[:,:w]
def GRIDfromString(h,w): return np.frombuffer(sys.stdin.buffer.read(), 'S1').reshape(h,-1)[:,:w]
MOD = 1000000007

def main():
	n, k = LI()
	print(k*(k-1)**(n-1))

if __name__ == '__main__':
    main()

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

int main()
{
  uint64_t h;
  cin >> h;
  uint64_t ans = 0;
  uint64_t m = 1;
  while (h > 1) {
    h >>= 1;
    ans += m;
    m *= 2;
  }
  ans += m;
  cout << ans << endl;
}


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


using namespace std;

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

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

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

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

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  FOR(i,0,n)
#define loop(n) FOR(i,0,n)
#define rrep(i,a,b) for(int i=(a);i>=(b);--i)
//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int INF = (int)1000000007;
const LL MOD = (LL)1000000007;//10^9+7
const LL INF2 = (LL)100000000000000000;//10^18


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

	int prev; cin >> prev;


	LL ans = 0;
	for (int i = 1; i < n; i++) {
		int now; cin >> now;

		ans += min(t, now - prev);
		prev = now;
	}

	cout << ans+t << endl;

	return 0;
}

Measured memory_bytes: 256
import java.util.*;
class Main{
    static int n;
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        n = sc.nextInt();
        dfs("",'a');
    }

    public static void dfs(String s,char ch){
        if(s.length() == n)
            System.out.println(s);
        else
            for(char c = 'a';c<=ch;c++)
                dfs(s+c ,c == ch?(char)(ch+1):ch);
    }
}

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

int main(){
  int h, w;
  cin >> h >> w;
  char pix[h+2][w+2];
  for(int i = 0; i < h+2; i++){
    for(int j = 0; j < w+2; j++){
      pix[i][j] = '#';
    }
  }
  for(int i = 1; i <= h; i++){
    for(int j = 1; j <= w; j++){
      cin >> pix[i][j];
    }
  }
  for(int i = 0; i < h+2; i++){
    for(int j = 0; j < w+2; j++){
      cout << pix[i][j];
    }
    cout << endl;
  }
  return 0;
}


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

int main() {
    int x;
    cin >> x;
    ll ans = 0;
    ans += 1000 * (x / 500);
    ans += 5 * ((x % 500) / 5);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#pragma GCC optimize("Ofast")
#define rep(i,a,n) for(int i=a; i<n; i++)
typedef long long ll;
typedef pair<int,int> P;
const ll MOD = (int)1e9+7;
const ll INF = MOD*MOD;
const ll powll = 1LL<<1;
 
int main(){
	ll n,m; cin >> n >> m;
    ll sum = 0;
    rep(i,0,m){
        int a; cin >> a;
        sum += a;
    }
    cout << max(-1LL, n-sum) << "\n";
}

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

const int mod = 998244353;

string s;

map<string, int> f;

inline int ADD(int x, int y) { return x + y >= mod ? x + y - mod : x + y; }

inline int dfs(string s)
{
	if(f.count(s)) return f[s];
	if(s.size() == 0) return f[s] = 1;
	int ans = 0;
	string t; t.clear();
	for(int i = 1; i < s.size(); i++) t.push_back(s[i]);
	ans = ADD(ans, 1ll * (1 + s[0] - '0') * dfs(t) % mod);
	for(int len = 1; len < s.size(); len++)
	{
		string now; now.clear();
		for(int i = 0; i < len; i++) now.push_back(s[i]);
		for(int k = 2; k <= s.size() / len; k++)
		{
			for(int i = (k - 1) * len, j = 0; j < len; i++, j++)
				if(s[i] == '0' || now[j] == '0') now[j] = '0';
				else now[j] = '1';
			string nxt; nxt.clear();
			for(int i = k * len; i < s.size(); i++) nxt.push_back(s[i]);
			//cout << s << ' ' << now << ' ' << nxt << endl;
			ans = ADD(ans, 1ll * dfs(now) * dfs(nxt) % mod);
		}
	}
	return f[s] = ans;
}

int main()
{
	cin >> s;
	printf("%d", dfs(s));
	return 0;
}

Measured memory_bytes: 5632
#include "bits/stdc++.h"
using namespace std;
#define f first
#define s second
#define pb push_back
#define reset(a,b) memset(a,b,sizeof a);
#define ALL(x) x.begin(),x.end()
 
template <typename T>
void cetak(T t){cout << t << ')' << endl;}
template <typename T, typename... V>
void cetak(T t, V... v) {cout << t; if (sizeof...(v)) cout << ", "; cetak(v...);}
 
#define debug(x...) cout << '(' << #x << ") = ("; cetak(x) 
#define sz(x) (int)(x.size())
#define lt(x) (int)(x.length())


const int MOD = 1e9 + 7;

int add(int x, int y){
    int ret = x + y;
    if(ret >= MOD) ret -= MOD;
    return ret;
}
int sub(int x, int y){
    int ret = x - y;
    if(ret < 0) ret += MOD;
    return ret;
}
int mul(int x, int y){
    return (long long)x * y % MOD;
}


const int mx = 1e5 + 10;

void solve(){
    int n;
    cin >> n;
    vector<int> t(n);
    vector<string> s(n);
    for(int i = 0; i < n; i++) cin >> s[i] >> t[i];
    string ss;
    cin >> ss;
    int total = 0;
    for(int i = 0; i < n; i++){
        if(ss != s[i]) continue;
        for(int j = i + 1; j < n; j++) total += t[j];
        break;
    }
    cout << total << '\n';
}

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int t = 1;
    // cin >> t;
    while(t--){
        solve();
    }
}


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

int main() {
    int N, X, Y;
    cin >> N;
    X = N % 1000;

    if (X == 0) {
        cout << X << endl;
    }
    else if (X < 1000) {
        cout << (X - 1000) * -1 << endl;
    }
}

Measured memory_bytes: 3596