akhauriyash/Code-Regression huggingface dataset:
a, b = map(int, input().split())
ans = []
def paintW():
  a_count = 1
  for i in range(50, 100):
    if a_count == a:
      return
    for j in range(1, 101):
      if not ans[i+1][j] == '.' and not ans[i-1][j] == '.' and not ans[i][j+1] == '.' and not ans[i][j-1] == '.' and not ans[i-1][j-1] == '.' and not ans[i-1][j+1] == '.' and not ans[i+1][j-1] == '.' and not ans[i+1][j+1] == '.':
        ans[i][j] = '.'
        a_count += 1
      if a_count == a:
        return
def paintB():
  b_count = 1
  if b_count == b:
    return
  for i in range(1, 50):
    for j in range(1, 101):
      if not ans[i+1][j] == '#' and not ans[i-1][j] == '#' and not ans[i][j+1] == '#' and not ans[i][j-1] == '#' and not ans[i-1][j-1] == '#' and not ans[i-1][j+1] == '#' and not ans[i+1][j-1] == '#' and not ans[i+1][j+1] == '#':
        ans[i][j] = '#'
        b_count += 1
      if b_count == b:
        return
ans.append(['*']*102)
for i in range(50):
  ans.append(['*'] + ['.']*100 + ['*'])

for i in range(50):
  ans.append(['*'] + ['#']*100 + ['*'])
ans.append(['*']*102)

paintB()
paintW()

print(100, 100)
for i in range(1, len(ans)-1):
  print(''.join(ans[i][1:101]))

Measured memory_bytes: 3188
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Net;
using System.Numerics;
using System.Reflection.Metadata;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Intrinsics.X86;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;

namespace AtCoder
{
	public class Program
	{
		static void Main()
		{
			var nm = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
			int n = nm[0];
			int m = nm[1];

			var ab = new(int a, int b)[n];
			for (int i = 0; i < n; i++) {
				var temp = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
				ab[i] = (temp[0], temp[1]);
			}

			var cd = new (int c, int d)[m];
			for (int i = 0; i < m; i++) {
				var temp = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
				cd[i] = (temp[0], temp[1]);
			}

			var ans = new int[n];
			for (int i = 0; i < n; i++) {
				int min = int.MaxValue;
				int index = 0;
				for (int j = 0; j < m; j++) {
					int d = Math.Abs(ab[i].a - cd[j].c) + Math.Abs(ab[i].b - cd[j].d);
					if (d < min) {
						index = j + 1;
						min = d;
					}
				}

				ans[i] = index;
			}

			Console.WriteLine(string.Join(Environment.NewLine, ans));
		}
	}
}


Measured memory_bytes: 28412
#include <iostream>
#include <stdio.h>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <math.h>

using namespace std;

int main(){
    double r, ans;
    cin >> r;
    ans = 2.0*r*M_PI;
    cout << fixed << ans;
    return 0;
}


Measured memory_bytes: 3788
#include<bits/stdc++.h>
using namespace std;
int main() {
	int N,K;
	cin>>N>>K;
	int x[100000];
	int nCounter=0,pCounter=0,zero=0;
	for(int i=0;i<N;i++){
		cin>>x[i];
		if(x[i]<0){nCounter++;}
		else if(x[i]==0){zero++;}
		else{pCounter++;}
	}
	//int pos1,pos2;
	//if(nCounter>=K)pos1=nCounter+zero-K;
	//if(pCounter>=K)pos2=nCounter+zero+K-1;
	
	int left;
	int ans=1000000000;
	if(nCounter+zero>=K){
		left=nCounter+zero-K;
		ans= -x[left];
		left++;
	}
	else{left=0;}
	while(left+K-1<N&&left<nCounter+1){
		
      if(-x[left]>x[left+K-1]&&left!=nCounter+zero){
			if(ans>-x[left]+x[left+K-1]*2)ans= -x[left]+x[left+K-1]*2;
		}else if(left!=nCounter+zero){
			if(ans>-x[left]*2+x[left+K-1])ans= -x[left]*2+x[left+K-1];
		}else{
			if(ans>x[left+K-1])ans = x[left+K-1];
		}
		
		left++;
		
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 640
from collections import Counter
import heapq

n,k=map(int,input().split())
a=list(map(int,input().split()))
kind = len(set(a))
if kind<=k:
    print(0)
else:
    temp = list(Counter(a).values())
    heapq.heapify(temp)
    ans=0
    for _ in range(kind-k):
        ans+=heapq.heappop(temp)
    print(ans)
    

Measured memory_bytes: 37160
#include<stdio.h>
#include<stdlib.h>
#include<math.h>

typedef long long int int64;

#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))
#define ABS(a) ((a)>(0)?(a):-(a))

void run(void){
  int n;
  scanf("%d",&n);
  int cnt=0;
  while(n--){
    int a;
    scanf("%d",&a);
    cnt+=a%2;
  }
  printf("%s\n",cnt%2==0?"YES":"NO");
}

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

Measured memory_bytes: 128
#include <bits/stdc++.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++)
#define all(v) v.begin(), v.end()
 
int main() {
  int N;
  cin>>N;
  int A[N];
  rep(i,N-1){
    cin>>A[i];
  }
  A[N-1]=A[N-2];
  int sum=A[0];    
  rep2(i,0,N-1){
    sum+=min(A[i],A[i+1]);
  }
  cout << sum<<endl;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
using namespace std;
int main()
{
	int n;
	int a;
	long long sum=0;
	scanf("%d",&n);
	for(int i=0;i<n;i++)
	{
		scanf("%d",&a);
		sum+=a-1;
	}
	printf("%lld",sum);
	return 0;
}

Measured memory_bytes: 256
let () =
  let rec charlist_of_string str n i =
    if i = n then [] else str.[i] :: charlist_of_string str n (i+1) in
  Scanf.scanf "%s\n%s\n" @@ fun s t ->
  let slst = charlist_of_string s (String.length s) 0 in
  let tlst = charlist_of_string t (String.length t) 0 in
  let ans = ref max_int in
  let rec check lst1 lst2 ans = match lst1, lst2 with
    | [], [] -> ans
    | _,  [] -> raise Not_found
    | [], _  -> raise Not_found
    | h1 :: t1, h2 :: t2 -> if h1 = h2 then check t1 t2 ans else check t1 t2 (ans + 1) in
  for start = 0 to (String.length s) - (String.length t) do
    let buf = check (Array.to_list (Array.sub (Array.of_list slst) start (String.length t))) tlst 0 in
    if buf < !ans then ans := buf
  done;
  Printf.printf "%d\n" !ans

Measured memory_bytes: 10988
N, M = map(int, input().split())
mod = 10**9 + 7

def factorial(n):
    ans = 1
    i = 0
    while i < n:
        ans *= (n-i)
        ans %= mod
        i += 1
    return ans

if abs(N-M) >= 2:
    print(0)
elif N == M:
    ans = (factorial(N) * factorial(M) * 2) % mod
    print(ans)
else:
    ans = (factorial(N) * factorial(M)) % mod
    print(ans)


Measured memory_bytes: 9132
#include <iostream>
#include <iomanip>
#include <vector>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <cstring>
#define rep(i, N) for (int i = 0; i < (int)N; i++)
using namespace std;
typedef long long ll;
const ll LLINF = 9223372036854775807;
const int MOD = 1000000007;

int main() {
  int N; cin >> N;
  int A[N]; rep(i, N) cin >> A[i];
  sort(A, A+N);
  int result = A[N-1]-A[0];
  cout << result << endl;
  return 0;
}

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

using namespace std;

int main()
{
    int n,m;
    cin >> n >> m;
    vector<bool> vb(n+1, false);
    bool ans = false;
    for(int i=0;i<m;i++)
    {
        int a,b;
        cin >> a >> b;
        assert(1 <= a && a < b && b <= n);
        if(a==1)
        {
            if(vb[b]==true)
                ans=true;
            vb[b]=true;
        }
        else if(b==n)
        {
            if(vb[a]==true)
                ans=true;
            vb[a]=true;
        }
    }
    if(ans)
        cout << "POSSIBLE\n";
    else
        cout << "IMPOSSIBLE\n";


    return 0;
}



Measured memory_bytes: 3648
#!/usr/bin/env ruby

require 'set'

class Hash
  def push(key, value)
    self[key] = [] if self[key] == nil
    self[key].push(value)
  end
end

class Array
  def lower_bound(value)
    left = -1;
    right = self.length;
    while left + 1 < right
      mid = left + (right - left) / 2;
      if self[mid] >= value
        right = mid
      else
        left = mid
      end
    end
    right
  end

  def unique
    res = [self.first]
    each_cons(2) do |a, b|
      if a != b
        res.push(b)
      end
    end
    res
  end
end

def get_ints
  gets.chomp.split.map(&:to_i)
end

def get_ints_minus_one
  get_ints.map { |x| x - 1 }
end

def get_int
  gets.chomp.to_i
end

def bit_search(bit_num)
  for x in [*0...2**bit_num]
    # true, falseの配列がyieldされる
    yield x.to_s(2).rjust(bit_num, '0').split('').map { |s| s == '1' }
  end
end

N, M = get_ints

def check_value(v, bool)
  if bool
    # plusが正と思う
    v
  else
    -v
  end
end

if M == 0
  puts 0
else
  sums = Array.new(8) { [] }

  N.times do |i|
    x, y, z = get_ints
    i = 0
    bit_search(3) do |x_bool, y_bool, z_bool|
      stock = check_value(x, x_bool) + check_value(y, y_bool) + check_value(z, z_bool)
      sums[i] << stock
      i += 1
    end
  end

  test = sums.map { |x| x.sort.reverse[0..(M-1)].sum }

  puts test.max
end


Measured memory_bytes: 14544
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<vector>
#include<stack> 
#include<queue>
#include<cmath>
#include<map>
#include<bitset>
#include<set>
#define LL long long
#define ULL unsigned long long
#define N 100100
#define M 5010
#define MOD 1000000007
#define FOR(i,l,r) for (int i = (l); i <= (r); i ++)
#define CLR(a,x) memset(a,x,sizeof(a))
#define INF 0x3f3f3f3f
#define ALL(x) x.begin(),x.end()
#define pb push_back
#define X first
#define Y second
using namespace std;
int a[N];
int main(){
	int n;
	scanf("%d",&n);
	int ans = 1,cnt = 1;
	FOR(i,1,n){
		scanf("%d",&a[i]);
		ans *= 3;
		if (!(a[i] & 1)) cnt *= 2;
	}
	printf("%d\n",ans - cnt);
}

Measured memory_bytes: 256
import numpy as np

N = int(input())
a = sorted([int(input()) for _ in range(N)])

s = sum(a)
m = (s + 1) // 2
m1 = m + 1


def func():
    ab = np.zeros(m1, dtype='uint32')
    ab[m] = 1
    for i in range(N):
        c = a[i]
        ab[:-c] = (2 * ab[:-c] + ab[c:]) % 998244353
        ab[-c:] = (2 * ab[-c:] + ab[m]) % 998244353
    return ab[0]


def func1():
    ab = np.zeros(m1, dtype='uint32')
    ab[m] = 1
    for i in range(N):
        c = a[i]
        ab[:-c] = (ab[:-c] + ab[c:]) % 998244353
        ab[-c:] = ab[-c:]
    return ab[0]


ans = 3 ** N % 998244353 - 3 * func()
if s % 2 == 0:
     ans += 3 * func1()
print(ans % 998244353)

Measured memory_bytes: 12988
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
using namespace std;
using namespace __gnu_pbds;
typedef long long int ll;
 
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
 
 
 
const ll N = 3001;
const ll mod = 1000000007;
const long long int inf = 2*(1e16);
#define pp pair<ll,ll>

typedef long double ld;
typedef vector<pp> vpl;
#define MP make_pair
#define endl "\n"
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep1(i,n) for(ll i=1;i<n;i++)
#define rrep(i,n) for(ll i=n-1;i>=0;i--)
#define repb(i,n) for(ll i=1;i<n-1;i++) 
#define trace(i,a) for(auto i=a.begin();i!=a.end();i++) 
#define mtrace(i,a) for(auto i=a.begin();i!=a.end();i++)  cout<<i->first<<" "<<i->second<<endl;   
 
 
 
 
void fastIO(void);
void decimal(int);
ll modmulti(ll, ll);
ll modadd(ll, ll);
ll modpower(ll, ll);
ll gcd(ll, ll );
ll modinv(ll);


ll dp[N][N];

int main()
{
    string s,t,a;
    cin>>s>>t;
    ll n = s.length(),m= t.length();
    dp[0][0] = 0;
    rep(i,n+1) dp[i][0] = 0;
    rep(i,m+1) dp[0][i] = 0;
    rep1(i,n+1){
        rep1(j,m+1){
            if(s[i-1]==t[j-1]){
                dp[i][j] = dp[i-1][j-1]+1;
            }
            else{
                dp[i][j] = max(dp[i-1][j],dp[i][j-1]);
            }
        }
    }
    ll i =n,j=m;
    while(i>0 && j>0){
        if(s[i-1]==t[j-1]){
            a.push_back(s[i-1]);
            i--;
            j--;
        }
        else if(dp[i-1][j]>dp[i][j-1]) i--;
        else j--;
    }
    rrep(tt,a.length()) cout<<a[tt];
    cout<<endl;
}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
void fastIO(void)
{  ios_base::sync_with_stdio(false);
   cin.tie(0);
   cout.tie(0);
}
 
void decimal(int n){
   cout<<fixed;
   cout<<setprecision(n);
}
ll modmulti(ll a, ll b){
   return ((a%mod)*1ll*(b%mod))%mod;
}
ll modadd(ll a, ll b){
   ll asdfgh =  ((a%mod)+(b%mod)+mod+mod)%mod;
   asdfgh = (asdfgh+mod)%mod;
   return asdfgh;
}
ll modpower(ll a, ll n){
   if(n==0) return 1;
   if(n==1) return a%mod;
   ll b = modpower(a,n/2);
   b = modmulti(b,b);
   if(n%2==0) return b;
   return modmulti(a,b);
}
ll gcd(ll a, ll b){
   if(b==0)
      return a;
   return gcd(b,a%b);
}
ll modinv(ll a){
   return modpower(a,mod-2);
}

Measured memory_bytes: 70656
#include <iostream>

using namespace std;
long long s1 = 0,s2 = 0,a[10010],b[10010];
int main(){
	int i,n;
	cin >> n;
	for(i=0;i<n;i++){
		cin >> a[i]; s1 += a[i];
	}
	for(i=0;i<n;i++){
		cin >> b[i]; s2 += b[i];
	}
	if(s1>s2){
		cout << "No" << endl;
		return 0;
	}
	long long cnt1 = 0,cnt2 = 0;
	for(i=0;i<n;i++){
		cnt1 += max(a[i] - b[i],0LL);
		cnt2 += max((b[i] - a[i] + 1)/2,0LL);
	}
	if(s2 - s1>=cnt1 && s2 - s1>=cnt2){
		cout << "Yes" << endl;
	}else{
		cout << "No" << endl;
	}
}

Measured memory_bytes: 384
from sys import exit, stdin
N, M = [int(_) for _ in stdin.readline().rstrip().split()]
A = [int(_) for _ in stdin.readline().rstrip().split()]
BC = [list(map(int, stdin.readline().rstrip().split())) for _ in range(M)]
BC.sort(reverse=True, key=lambda x: x[1])
ans = []
for b, c in BC:
    if len(ans) >= N:
        break
    ans+=[c]*b
ans+=A
ans.sort(reverse=True)
print(sum(ans[:N]))

Measured memory_bytes: 81536
#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <utility>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <functional>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>
 
using namespace std;
 
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define rep(i,n) REP(i, 0, n)
#define pb push_back
#define mp make_pair
#define all(r) (r).begin(),(r).end()
#define rall(r) (r).rbegin(),(r).rend()
#define fi first
#define se second
 
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<ll> vl;
typedef vector<vl> vll;
typedef pair<int, int> pii;
typedef pair<double, int> pdi;
typedef pair<ll, ll> pll;
 

 
const int INF = 1000000;
const double EPS = 1e-8;
const int mod = 1e9 + 7;
const ll LINF = 1e18;
const double PI = acos(-1);

struct Input
{
	int n;
	char c;
	char str[1024];
	string s;
	int nextInt(){
		scanf("%d", &n);
		return n;
	}
	char nextChar(){
		scanf("%c", &c);
		return c;
	}
	string next(){
		scanf("%s", str);
		return string(str);
	}
	string nextLine(){
		getline(cin, s);
		return s;
	}
};
Input in;

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

string getBinary(char c){
	string ret;
	int p = 0;
	if(c >= '0' && c <= '9') p = c-'0';
	else p = 10 + c-'a';

	while(p > 0) ret += (char)('0'+p%2), p/=2;
	while(ret.size()<4) ret += '0';
	reverse(all(ret));
	return ret;
}

string calcs(string s){
	string ret;
	for(int i = 0; i < s.size(); i++) ret += getBinary(s[i]);
	return ret;
}

int calcr(string r){
	int ret = 0;
	reverse(all(r));
	int p = 1;

	rep(i, r.size()){
		ret += p * (r[i]-'0');
		p *= 2;
	}

	return ret;
}

string calcm(string m){
	double d = 0, p = 1.0;

	for(int i = 0; i < m.size(); i++){
		p /= 2.0;
		d += p * (m[i]-'0');
	}

	stringstream ss;
	string s;

	ss<<fixed << setprecision(7) << d;
	ss>>s;
	//cout<<" "<<s;

	if(s.size() < 2) return "0";
	int t = 0;
	for(int i = s.size()-1; i >= 0; i--){
		if(s[i]!='0') break;
		t++;
	}
	s = s.substr(2, ((int)s.size())-t-2);
	if(s.size()==0) return "0";
	return s;
}

int main(){
	int n = in.nextInt();
	while(n--){
		string s = in.next();
		s = calcs(s);
		string sign = s.substr(0, 1);
		string real = s.substr(1, 24);
		string imag = s.substr(25);

		int r = calcr(real);
		string m = calcm(imag);

		if(sign[0]=='1') cout<<'-';
		cout<<r<<"."<<m<<endl;
	}
}

Measured memory_bytes: 1328
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <sstream>
#include <string>
#define _repargs(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _repargs(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
#define inf 2000000007
#define mp make_pair
#define pb push_back
typedef long long ll;
using namespace std;
template <typename T>
inline void output(T a, int p = 0) {
    if(p) cout << fixed << setprecision(p)  << a << "\n";
    else cout << a << "\n";
}
// end of template

int main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    // source code
    int N;
    cin >> N;
    ll ans = 0;
    rep(i, N){
        ll l, r;
        cin >> l >> r;
        ans += r - l + 1;
    }
    output(ans);
    return 0;
}

Measured memory_bytes: 256
from bisect import bisect_left

n,q=map(int,input().split())
ans=["kogakubu10gokan"]
for i in range(n):
    y,s=input().split()
    ans.append(s)
    y=int(y)
    if y==q:
        print(s)
        exit()
    elif y>q:
        print(ans[i])
        exit()
print(ans[-1])


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

string repeat(int x, int c) {
    string s = "";
    for (int i = 0; i < x;i++) {
        s = s + to_string(c);
    }
    return s;
}

int main(void) {
    int a, b;
    cin >> a >> b;

    string aa = repeat(a, b);
    string bb = repeat(b, a);

    cout << min(aa, bb);
}

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

int main(){

  string S;

  cin >> S;

  if(S.at(2) == S.at(3) && S.at(4) == S.at(5)){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
}

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


int HP[100], M;
long long dp1[100001], dp2[100001];

int solve(int N)
{
  memset(dp1, 0, sizeof(dp1));
  memset(dp2, 0, sizeof(dp2));
    
  for(int i = 0; i < N; i++) {
    cin >> HP[i];
  }
  cin >> M;

  bool end = false;
  while(M--) {
    string Name, Target;
    int MP, Damage;
    cin >> Name >> MP >> Target >> Damage;
    if(MP == 0) {
      if(Damage > 0) end = true;
      continue;
    }
    for(int i = MP; i <= 100000; i++) {
      dp2[i] = max(dp2[i], dp2[i - MP] + Damage);
    }
    if(Target.size() == 6) continue;
    for(int i = MP; i <= 100000; i++) {
      dp1[i] = max(dp1[i], dp1[i - MP] + Damage);
    }
  }
  if(end) return(0);
  
  int best = 1 << 30;
  for(int i = 0; i <= 100000; i++) {
    int ret = 0;
    for(int j = 0; j < N; j++) {
      ret += lower_bound(dp2, dp2 + 100001, HP[j] - dp1[i]) - dp2;
    }
    best = min(best, i + ret);
  }
  return(best);
}

int main()
{
  int N;
  while(cin >> N, N) {
    cout << solve(N) << endl;
  }
}

Measured memory_bytes: 2780
import math
import random
import heapq
from collections import Counter, defaultdict
from decimal import Decimal, ROUND_HALF_UP, ROUND_CEILING
from functools import lru_cache, reduce
from itertools import combinations_with_replacement, product, combinations


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


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input()


def read_str_n():
    return list(map(str, input().split()))


def mt(f):
    import time
    import sys

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        print(e - s, 'sec', file=sys.stderr)
        return ret

    return wrap


@mt
def slv(A, B, C, K):

    ans = sum([A, B, C])
    m = max([A, B, C])
    ans -= m
    for i in range(K):
        m *= 2
    return ans + m


def main():
    A, B, C = read_int_n()
    K = read_int()
    print(slv(A, B, C, K))


if __name__ == '__main__':
    main()

Measured memory_bytes: 7400
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;

namespace AtCoder
{
	public class Program
	{
		static void Main()
		{
			string s = Console.ReadLine();
			int ans = 0;
			for (int i = 0; i < 3; i++) {
				if (s[i] == '1') {
					++ans;
				}
			}

			Console.WriteLine(ans);
		}
	}
}

Measured memory_bytes: 11092
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i < (n); ++i)
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
using namespace std;
using ll = long long;
using P = pair<int,int>;
using Pl = pair<long long,long long>;
using veci = vector<int>;
using vecl = vector<long long>;
using vecveci = vector<vector<int>>;
using vecvecl = vector<vector<long long>>;

int main() {
    int N; cin >> N;
    if(N%1000 != 0) cout << (N/1000+1)*1000-N << endl;
    else cout << 0 << endl;
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1e5+5;
struct node
{
    ll x,y;
    node(ll x=0,ll y=0):x(x),y(y){}
    bool operator<(const node&o)const
    {
       return y>o.y;
    }
}a[N];
ll n,m;
set<int>s;
set<int>::iterator it;
int main()
{
    scanf("%lld%lld",&n,&m);
    for(int i=1;i<=m;i++)
        s.insert(i);
    for(int i=1;i<=n;i++)
        scanf("%lld%lld",&a[i].x,&a[i].y);
    sort(a+1,a+1+n);
    ll ans=0;
    for(int i=1;i<=n;i++)
    {
        if(s.size()==0) break;
        ll t=a[i].x;
        it=s.lower_bound(t);
        if(it!=s.end())
        {
            s.erase(*it);
            ans+=a[i].y;
        }
    }
    printf("%lld\n",ans);
}


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

#define FOR(i,a,b) for(int i = (a); i < (b); ++i)
#define REP(i,n) FOR(i,0,n)
typedef long long ll;
using ll = long long;
using vi = vector<int>;
using mii = map<int, int>;
using msi = map<string, int>;
using pii = pair<int, int>;

int main()
{
    string s;
    cin >> s;
    int a = s[0]-'0', b = s[1]-'0', c = s[2]-'0', d = s[3]-'0';
    if(a-b-c-d==7) printf("%d-%d-%d-%d=7\n", a, b, c, d);
    else if(a-b-c+d==7) printf("%d-%d-%d+%d=7\n", a, b, c, d);
    else if(a-b+c-d==7) printf("%d-%d+%d-%d=7\n", a, b, c, d);
    else if(a-b+c+d==7) printf("%d-%d+%d+%d=7\n", a, b, c, d);
    else if(a+b-c-d==7) printf("%d+%d-%d-%d=7\n", a, b, c, d);
    else if(a+b-c+d==7) printf("%d+%d-%d+%d=7\n", a, b, c, d);
    else if(a+b+c-d==7) printf("%d+%d+%d-%d=7\n", a, b, c, d);
    else if(a+b+c+d==7) printf("%d+%d+%d+%d=7\n", a, b, c, d);

    return 0;
}

Measured memory_bytes: 256
package main

import "fmt"

func reverseString(s string)string{
	rs := []rune(s)
	for i, j := 0, len(s)-1; i < j; i, j = i+1, j-1{
		rs[i], rs[j] = rs[j], rs[i]
	}
	return string(rs)
}

func checkPalindrome(s string)bool{
	if s == reverseString(s){
		return true
	}
	return false
}

func main() {
	var s string
	fmt.Scan(&s)
	slen := len(s)
	if slen % 2 == 0 {
		return
	}

	ans := "No"
	if checkPalindrome(s[:]) && checkPalindrome(s[0:(slen-1)/2]) && checkPalindrome(s[(slen+1)/2:]){
		ans = "Yes"
	}

	fmt.Println(ans)


}

Measured memory_bytes: 512
#include<bits/stdc++.h>
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 sz(x) int(x.size())
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define YesorNo(a) printf(a ? "Yes\n" : "No\n")
#define endl '\n'
#define fi first
#define se second
using ll = long long;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
template<class T> using V = vector<T>;
const int dx[] = {0,1,0,-1,1,1,-1,-1};
const int dy[] = {1,0,-1,0,1,-1,-1,1};
const int inf = (1<<30)-1;
const ll infll = (1LL<<62)-1;
ll ceil(const ll &a, const ll &b){return ((a)+(b)-1)/b;}
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; }


struct UnionFind { // UnionFindTree
  vector<int> d;
  UnionFind(int n): d(n,-1) {}
  int find(int x) {
    if(d[x] < 0) return x;
    return d[x] = find(d[x]);
  }
  bool unite(int x, int y) {
    x = find(x);
    y = find(y);
    if(x == y) return false;
    if(-d[x] < -d[y]) swap(x,y);
    d[x] += d[y];
    d[y] = x;
    return true;
  }
  bool same(int x, int y) { return find(x) == find(y); }
  int size(int x) { return -d[find(x)]; }
};


int main(){
    int n, k;
    cin >> n >> k;
    V<int> p(n), c(n);
    rep(i,n) cin >> p[i];
    rep(i,n) cin >> c[i];
    map<int, ll> mp;
    UnionFind uf(n);
    rep(i,n) {
        uf.unite(i,p[i]-1);
    }
    rep(i,n) {
        mp[uf.find(i)] += c[i];
    }
    ll ans = -infll;
    rep(i,n) { // スタート位置
        int roop = uf.size(i);
        int times = (mp[uf.find(i)] > 0 ? (k-1)/roop : 0);
        int over = max(min(roop, k - roop*times), 1);
        ll tmp = 0;
        ll s = -infll;
        int idx = i;
        rep(j,over) {
            tmp += c[idx];
            chmax(s, tmp);
            idx = p[idx]-1;
        }
        s += times * mp[uf.find(i)];
        chmax(ans, s);
    }
    cout << ans << endl;
}

Measured memory_bytes: 3708
#include <bits/stdc++.h>
using namespace std;
template <typename T> void read(T &t) {
	t=0; char ch=getchar(); int f=1;
	while ('0'>ch||ch>'9') { if (ch=='-') f=-1; ch=getchar(); }
	do {(t*=10)+=ch-'0';ch=getchar();} while ('0'<=ch&&ch<='9'); t*=f;
}
const int maxn=100;
int n,a[maxn],b[maxn],c[maxn],tot;
int lg,d[maxn];
void add(int x,int y,int z) {
	a[++tot]=x; b[tot]=y; c[tot]=z;
}
int main() {
	//freopen("1.txt","r",stdin);
	read(n);
	for (int i=0;i<20;i++)
		if (n&(1<<i)) d[++lg]=i;
	for (int i=1;i<=d[lg];i++)
		add(i,i+1,0),add(i,i+1,(1<<(i-1)));
	n=(1<<d[lg]);
	for (int i=lg-1;i>=1;i--)
		add(d[i]+1,d[lg]+1,n),n+=(1<<d[i]);
	printf("%d %d\n",d[lg]+1,tot);
	for (int i=1;i<=tot;i++)
		printf("%d %d %d\n",a[i],b[i],c[i]);
	return 0;
}

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

int main() {
    string S; cin >> S;
    int Q; cin >> Q;

    int rev = 0;
    rep(i, Q){
        int T;
        cin >> T;
        if (T == 1)rev++;
        else {
            int F; cin >> F;
            if ((F+rev)%2 == 1){
                string C; cin >> C;
                S.insert(0,C);
            } else {
                char C; cin >> C;
                S.push_back(C);
            }
        }
    }

    if(rev % 2 == 1)reverse(S.begin(),S.end());

    cout << S << endl;

}

Measured memory_bytes: 1028
n = int(input())
s = [input() for _ in range(n)]

cnt = 0
cnta = 0
cntb = 0
cntab = 0
for i in range(n):
    if 'AB' in s[i]:
        cnt += s[i].count('AB')
    if s[i][0] == 'B' and s[i][-1] == 'A':
        cntab += 1
    elif s[i][0] == 'B':
        cntb += 1
    elif s[i][-1] == 'A':
        cnta += 1
    
if cntab == 0:
    cnt += min(cnta, cntb)
else:
    if cnta + cntb > 0:
        cnt += cntab + min(cnta, cntb)
    else:
        cnt += cntab - 1
print(cnt)

Measured memory_bytes: 9560
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const int MOD = 1e9+7;
const int INF = 1e9;
const ll INFll = 1e18;
#define put(n) cout<<(n)<<endl
#define Cout(n) cout<<(n)
#define rep(i,num,N) for(int(i)=(num);(i)<(N);++(i))
#define rrep(i,num,N) for(int (i)=(num);(i)>(N);--(i))
#define all(v) (v).begin() , (v).end()
#define rall(v) (v).rbegin() , (v).rend()
#define MP make_pair
#define pb(q) push_back(q)
int dx[4] = {0,0,1,-1};
int dy[4] = {1,-1,0,0};


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int N,K;
    
    while(cin>>N>>K,N!=0&&K!=0){
        set<string> num;
        vector<string> card(N);
        rep(i,0,N) cin>>card[i];
        sort(all(card));

        do{
            string s = "";
            rep(i,0,K) s += card[i]; 
            num.insert(s);
        }while(next_permutation(all(card)));
        put(num.size());
    }
}


Measured memory_bytes: 3312
import java.util.Scanner;
public class Main {
	public static void main(String[] args)throws Exception{
		Scanner stdIn=new Scanner(System.in);
		int N=stdIn.nextInt();
		long A[]=new long[N];
		for(int i=0;i<N;i++){
			A[i]=stdIn.nextLong();
			if(A[i]==0){
				System.out.println(0);
				System.exit(0);
			}
		}
		try{
			long sum=1,key=1;
			key*=Math.pow(10,9);
			key*=Math.pow(10,9);
			for(int i=0;i<N;i++){
				sum=Math.multiplyExact(sum,A[i]);
			}
			if(sum>key)
				System.out.println(-1);
			else
				System.out.println(sum);
		}
		catch(Exception e){
			System.out.println(-1);
		}
	}
}


Measured memory_bytes: 61376
#include<stdio.h>

#define INFTY 2097152
#define WHITE 0
#define GRAY 1
#define BLACK 2

int n,A[100][100];

int prim(){
  int mincost,u,i,v,s=0,iro[100],d[100],p[100];
  for(i=0;i<n;i++){
    d[i]=INFTY;
    p[i]=-1;
    iro[i]=WHITE;
  }
  d[0]=0;

  while(1){
    mincost=INFTY;
    for(i=0;i<n;i++){
      if(iro[i]!=BLACK&&d[i]<mincost){
	mincost=d[i];
	u=i;
      }
    }
    if(mincost==INFTY)break;
    iro[u]=BLACK;
    for(v=0;v<n;v++){
      if(iro[v]!=BLACK&&A[u][v]!=INFTY){
	if(A[u][v]<d[v]){
	  d[v]=A[u][v];
	  p[v]=u;
	  iro[v]=GRAY;
	}
      }
    }
  }
  for(i=0;i<n;i++){
    if(p[i]!=-1)s=s+A[i][p[i]];
  }
  return s;
}

int main(){
  int i,j,a,ans;

  scanf("%d",&n);
  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      scanf("%d",&a);
      A[i][j]=(a==-1)?INFTY:a;
    }
  }
  ans=prim();
  printf("%d\n",ans);

  return 0;
}



Measured memory_bytes: 2112
#include <bits/stdc++.h>
using namespace std;
/*てんぷれぞーん！*/
static const int INF = 2147483647;
static const long long llINF = 9223372036854775807;
static const int NIL = -1;
static const int MOD = 1000000007;
typedef long long ll;
typedef pair<int,int> P;
struct edge {int to,cost;};
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define np next_permutation
#define pq priority_queue
/*t y p o っ て 知 っ て る ！ ？ */
#define itn int
#define scnaf scanf
#define reutnr return
#define int ll
#define INF llINF
int dx[4] = {0,1,0,-1}, dy[4] = {1,0,-1,0};
/*てんぷれぞーんしゅーりょー！*/

static const int MAX_V = 114514;
vector<edge> G[MAX_V];
int d[MAX_V],V; //dはKを始点とした最短距離を記録

void print(){
    /*for(int i=0;i<V;i++) printf("%lld ",d[i]);
    printf("\n");*/
    //debug用の関数でしたが、今は無が入っています
}

void dijkstra(int s){
    pq<P,vector<P>,greater<P> > que;
    fill(d,d+V,INF);
    d[s] = 0;
    que.push(P(0,s));
    print();

    while(!que.empty()){
        P p=que.top(); que.pop();
        int v = p.se;
        if(d[v]<p.fi) continue;
        for(int i=0;i<G[v].size();i++){
            edge e = G[v][i];
            if(d[e.to]>d[v]+e.cost){
                d[e.to] = d[v] + e.cost;
                que.push(P(d[e.to],e.to));
            }
        }
        print();
    }
}

signed main(){
    scanf("%lld",&V);
    for(int i=0;i<V-1;i++){
        int a,b,c;
        scanf("%lld %lld %lld",&a,&b,&c);
        a--; b--;   //0-indexに
        edge tmp;
        tmp.to = a; tmp.cost = c;
        G[b].pb(tmp);
        tmp.to = b;
        G[a].pb(tmp);
    }

    int q,k;
    scanf("%lld %lld",&q,&k);
    dijkstra(k-1);  //0-indexをわするるな
    for(int i=0;i<q;i++){
        int start,goal;
        scanf("%lld %lld",&start,&goal);
        start--; goal--;    //0-index!!!!!!!!!!!!!
        int ans = d[start] + d[goal];
        printf("%lld\n",ans);
    }
}

Measured memory_bytes: 9204
#include <iostream>

using namespace std;

int main(){
    int seconds,sec,min,hour;
    cin>>seconds;
    
    hour = (seconds/60)/60;
    min = (seconds/60)%60;
    sec = seconds%60;
    
    cout<<hour<<":"<<min<<":"<<sec<<endl;
    
    return 0;
    
}


Measured memory_bytes: 3104
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int N = 100005;

int n, m, k;
vector<int> fconn[N];
vector<int> bconn[N];

int curGroup = 0;
int group[N], groupSize[N + 5];

bitset<N> valid;

void color(int v) {
    group[v] = curGroup;
    groupSize[curGroup]++;
    for (auto u : fconn[v]) {
        if (!group[u]) color(u);
    }
}

int main() {
    cin.sync_with_stdio(0); cin.tie(0);
    cin >> n >> m >> k;
    for (int i = 0; i < m; i++) {
        int a, b; cin >> a >> b;
        a--; b--;
        fconn[a].push_back(b);
        fconn[b].push_back(a);
    }

    for (int i = 0; i < k; i++) {
        int a, b; cin >> a >> b;
        a--; b--;
        bconn[a].push_back(b);
        bconn[b].push_back(a);
    }

    for (int i = 0; i < n; i++) {
        curGroup++;
        if (!group[i]) color(i);
    }

    for (int i = 0; i < n; i++) {
        int ans = groupSize[group[i]] - 1;
        valid.set();
        for (auto u : fconn[i]) {
            valid[u] = false;
            ans--;
        }

        for (auto u : bconn[i]) {
            if (group[u] == group[i] && valid[u]) {
                ans--;
            }
        }
        cout << ans << ' ';
    }
}


Measured memory_bytes: 12672
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define mst(a,b) memset((a),(b),sizeof(a))
#define pi acos(-1)
#define pii pair<int,int>
const int INF = 0x3f3f3f3f;
const double eps = 1e-12;
const int MAXN = 1e5 + 10;
const int MAXM = 1e6 + 10;
const ll mod = 1e9 + 7;

int a[MAXN];


int main()
{
#ifdef local
    freopen("data.txt","r",stdin);
//    freopen("data.txt","w",stdout);
#endif
    int n;
    scanf("%d",&n);
    int ans = 0;
    for(int i=0; i<n; i++) {
        scanf("%d",&a[i]);
        if(i == 0) ans += abs(a[i]);
        else ans += abs(a[i] - a[i-1]);
        if(i == n-1) ans += abs(a[i]);
    }
    for(int i=0; i<n; i++) {
        int sum = ans;
        if(i == 0)
            sum = sum - abs(a[i]) - abs(a[i]-a[i+1]) + abs(a[i+1]);
        else if(i == n-1)
            sum = sum - abs(a[i]) - abs(a[i]-a[i-1]) + abs(a[i-1]);
        else
            sum = sum - abs(a[i]-a[i+1]) - abs(a[i]-a[i-1]) + abs(a[i-1]-a[i+1]);
        printf("%d\n",sum);
    }
    return 0;
}


Measured memory_bytes: 1664
import java.util.Scanner;
public class Main{
    public static void main(String[] args) {
        // TODO Auto-generated method stub
        Scanner sc=new Scanner(System.in);
        int N= sc.nextInt();
        int game=N*(N-1)/2;
        int point[] =new int[N];
        for(int i=0;i<game;i++){
            int a=sc.nextInt();
            int b=sc.nextInt();
            int c=sc.nextInt();
            int d=sc.nextInt();
            if(c<d){
                point[b-1]=point[b-1]+3;
            }else if(c>d){
                point[a-1]=point[a-1]+3;
            }else if(c==d){
                point[a-1]=point[a-1]+1;
                point[b-1]=point[b-1]+1;
            }
        }//???????????§???????¨????
        int rnk[]=new int[N];
        for(int i=0;i<N;i++){
        rnk[i]=1;
        for(int j=0;j<N;j++){
        if(point[i]<point[j]){
        rnk[i]=rnk[i]+1;
        }
    }
}
        for(int i=0; i<N;i++){
        System.out.println(rnk[i]);
        }
    }
}

Measured memory_bytes: 42036
#include <iostream>
#include <vector>
using namespace std;
typedef long long  ll;

ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}

int main()
{
    int a,b;
    cin >> a >> b;

    cout << lcm(a, b) << endl;
    return 0;
}

Measured memory_bytes: 3592
/*********************
*  Author: xuziyuan  * 
*********************/

#include <bits/stdc++.h>

#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
#define LL long long
#define pii pair <int,int>
#define fi first
#define se second
#define pb push_back
#define mpr make_pair

using namespace std;

int n,a[200010],ans=0;

int main()
{
  cin>>n;
  rep(i,n) cin>>a[i];
  int mn=1e9;
  rep(i,n)
  {
    mn=min(mn,a[i]);
    if(a[i]==mn) ans++;
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <cmath>
using namespace std;
int main()
{
    // スペース区切りの整数の入力
    int n,d;
    cin >> n >> d;
    
    int vec[n][d];
  
    for (int i = 0; i < n; ++i) {
      for (int j = 0; j < d; ++j) {
        cin >> vec[i][j];
      }
    }
  
    int seisuu = 0;
    for (int i = 0; i < n - 1; ++i) {
      for (int j = i + 1; j < n; ++j) {
        int sum = 0;
        for (int k = 0 ; k < d; k++) {
          sum += pow(vec[i][k] - vec[j][k],2);
        }
        double sqr = 0.0;
        sqr = sqrt(sum);
        int isq = sqr;
        double sub = sqr - isq;
        if (sub < 0.000001) {
          seisuu +=1;
        }
      }
    }
    cout << seisuu << endl;
    return 0;
}

Measured memory_bytes: 256
#include<cstdio>

using namespace std;

int h,w,n,a[10005],g[105][105];

int main() {
	scanf("%d%d%d", &h, &w, &n);
	for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
	int i = 1, j = 1, c = 0, x = 1, y = 1;
	while (c < h * w) {
		if (a[y] == 0) y++;
		else {
			c++;
			g[i][j] = y;
			a[y]--;
			if ((i % 2 == 1) && (j == w)) {
				i++;	
			}
			else if ((i % 2 == 0) && (j == 1)) {
				i++;	
			}
			else if (i % 2 == 1) j++;
			else j--;
		}
	}
	for (int i = 1; i <= h; i++) {
		for (int j = 1; j <= w; j++) {
			if (j != w) printf("%d ", g[i][j]);
			else printf("%d\n", g[i][j]); 
		}	
	}
}

Measured memory_bytes: 256
import bisect
import itertools
import sys

input=sys.stdin.readline

def main(args):
    n, d, a = map(int,input().split())
    
    monster = [0]*n
    pos = [0]*n
    for i in range(n):
        x, h = map(int,input().split())
        monster[i] = (x, -(-h//a))
        pos[i] = x
    
    pos.sort()
    monster.sort()
    
    limit = [0]*n
    #そのモンスターを攻撃したとき巻き添えにできるやつらの中で一番右のヤツのindex
    for i in range(n):
        limit[i] = bisect.bisect_right(pos, pos[i]+2*d)-1
    
    #print(limit)
    
    damage = [0]*(n+1)
    ans = 0
    for i in range(n):
        if damage[i] >= monster[i][1]:
            pass
        else:
            plus = monster[i][1] - damage[i]
            ans += plus
            damage[i] += plus
            damage[limit[i]+1] -= plus
        #print(damage)
        
        damage[i+1] += damage[i]
    
    print(ans)

if __name__ == '__main__':
    main(sys.argv[1:])

Measured memory_bytes: 90384
import sys
sys.setrecursionlimit(10**7)
n , m , k = map(int, input().split())
r = [[] for i in range(n)]
bk = [[] for i in range(n)]
for i in range(m):
    a , b = map(int, input().split())
    r[a-1].append(b-1)
    r[b-1].append(a-1)
for i in range(k):
    c , d = map(int, input().split())
    bk[c-1].append(d-1)
    bk[d-1].append(c-1)


v=[0]*n
l=[0]*n
w=[0]*n

def dfs(now,c):
    global ln
    if v[now]==1:
        return
    v[now]=1
    ln+=1
    w[now]=c
    l[c]=ln
    for i in r[now]:
        dfs(i,c)
    return

for i in range(n):
    ln=0
    dfs(i,i)

ans =[]
for i in range(n):
    d=0
    for j in bk[i]:
        if w[j]==w[i]:
            d+=1
    ans.append(str(l[w[i]]-1-d-len(r[i])))
print(' '.join(ans))


Measured memory_bytes: 64164
#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <vector>
//#include <random>
//#include <unordered_set>
#include <complex>
using namespace std;
int main()
{
    int x,a,b;
    cin>>x>>a>>b;
    x-=a;
    cout<<x%b;
    system ("pause"); 
    return 0;
}

Measured memory_bytes: 504
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> pi;
int n;
int fenwick[26][500005];

long long sum(int alpha, int i) {
    long long ans = 0;
    while (i > 0) {
        ans += fenwick[alpha][i];
        i -= (i & -i);
    }
    return ans;
}
void update(int alpha, int i, long long diff) {
    while (i <=n) {
        fenwick[alpha][i] += diff;
        i += (i & -i);
    }
}

int main(){
	cin>>n;
	string s;
	cin>>s;
	for(int i=0; s[i]; i++){
		update((int)(s[i]-'a'),i+1,1);
	}
	int q;
	cin>>q;
	while(q--){
		int type;
		cin>>type;
		if(type==1){
			int index;
			char ch;
			cin>>index>>ch;
			if(s[index-1]==ch) continue;
			else{
				int change = (int)(s[index-1]-'a');
				update(change,index,-1);
				s[index-1] = ch;
				update((int)(ch-'a'),index,1);
			}
		}
		else{
			int a,b;
			cin>>a>>b;
			int counter = 0;
			for(int i=0; i<26; i++){
				counter+=((sum(i,b)-sum(i,a-1))?1:0);
			}
			cout<<counter<<'\n';
		}
	}
}

Measured memory_bytes: 54624
#include <iostream>
#include <string>
#include <array>

int main(){
    std::string s;
    std::cin >> s;
    int size = s.size();
    for(int i = 0; i < size; i++){
        if(s[i] == s[i+1]){
            std::cout << i+1 << " " << i+2;
            return 0;
        }
        else if(s[i] == s[i+2]){
            std::cout << i+1 << " " << i+3;
            return 0;
        }
    }
    std::cout << -1 << " " << -1;
    return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <string>

using namespace std;

int main()
{
	int n, t[100], m, p[100],x[100],ans=0,vol;
	cin >> n;
	for (int i = 0; i < n; i++)
	{
		cin >> t[i];
	}

	cin >> m;

	for (int i = 0; i < m; i++)
	{
		cin >> p[i] >> x[i];
	}

	for (int i = 0; i < m; i++)
	{
		for (int j = 0; j < n; j++)
		{
			if (p[i] == j+1)
			{
				vol = x[i];
				ans += vol;
			}
			else
			{
				ans += t[j];
			}
		}
		cout << ans << endl;
		ans = 0;
	}
	
	return 0;
}

Measured memory_bytes: 256
using System;
using System.IO;

namespace CExceptionHandling
{
    class Program
    {
        static void Main(string[] args)
        {
            // 入力の取得
            var n = int.Parse(Console.ReadLine());
            int[] numbers = new int[n], sortedNumbers = new int[n];
            for (var i = 0; i < n; i++)
            {
                var num = int.Parse(Console.ReadLine());
                numbers[i] = num;
                sortedNumbers[i] = num;
            }

            Array.Sort(sortedNumbers);
            Array.Reverse(sortedNumbers);

            // 解答の出力
            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);
            foreach (var num in numbers)
            {
                var answer = num != sortedNumbers[0] ? sortedNumbers[0] : sortedNumbers[1];
                Console.WriteLine(answer);
            }
            Console.Out.Flush();
        }
    }
}


Measured memory_bytes: 18584
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;


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

  int l_max = 1;
  int r_min = 1e5;
  for (int i = 0; i < m; i++) {
	int l, r;
	cin >> l >> r;
	l_max = max(l_max, l);
	r_min = min(r_min, r);
  }

  int res = (r_min - l_max) + 1;
  if (res >= 0)
	cout << res << endl;
  else
	cout << 0 << endl;

  return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize(3, "Ofast", "inline")
#include <bits/stdc++.h>
#if __cplusplus >= 201103L
#include <chrono>
using namespace std::chrono;
#endif
using namespace std;
#define ll long long
#define ull unsigned long long
#define pii pair<int, int>
#define pb push_back
#define fi first
#define se second
#ifdef LOCAL
#define prl puts("\n------------------\n")
#define prln(x) (cout << #x << ' ' << x << endl)
#define pr(x) (cout << #x << ' ' << x << ' ' )
#define prv(x) (cout << x << ' ')
#else
#define prl 
#define prln(x) 
#define pr(x)
#define prv(x)
#endif
#define clr(x) memset((x), 0, sizeof((x)))
#define clr1(x) memset((x), -1, sizeof((x)))
#define endl "\n"
#define pi acos(-1)
#define rep(i, st, ed) for (int i = (st); i <= (ed); ++i)
#define rep0(i, st, ed) for (int i = (st); i < (ed); ++i)
#define per(i, st, ed) for (int i = (st); i >= ed; --i)
template<class T> void _sf(T &x) {cin >> x;}
void _sf(int &x) {scanf("%d", &x);}
void _sf(ll &x) {scanf("%lld", &x);}
void _sf(double &x) {scanf("%lf", &x);}
void _sf(char &x) {scanf(" %c", &x);}
void _sf(char *x) {scanf("%s", x);}
void sf() {}
template <class T, class...U> void sf(T & head, U&... tail) { _sf(head); sf(tail...);}
const int mod = 1e9 + 7;
const int INF = 0x3f3f3f3f;

int read() {
    int x = 0, f = 1;
    char ch = getchar();
    while (ch < '0' || ch > '9') {
        if (ch == '-') f = -1;
        ch = getchar();
    }
    while (ch >= '0' && ch <= '9') {
        x = x * 10 + ch - '0';
        ch = getchar();
    }
    return x * f;
}
const int maxn = 1e5 + 5;
int dp[maxn];
int a[maxn];
int main(){
    #ifdef LOCAL
        freopen("in.txt", "r", stdin);
        freopen("out.txt", "w", stdout);
        #if __cplusplus >= 201103L
        auto start = steady_clock::now();
        #endif
    #endif
    memset(dp, INF, sizeof(dp));
    int n = read(), k = read();
    rep(i, 1, n) a[i] = read();
    dp[1] = 0;
    for (int i = 2; i <= n; ++i) {
        for (int j = 1; j <= k; ++j) {
            if (i - j >= 1) {
                dp[i] = min(dp[i], dp[i - j] + abs(a[i] - a[i - j]));
            }
        }
    }
    // rep(i, 1, n)
    cout << dp[n] << endl;
    #ifdef LOCAL
        #if __cplusplus >= 201103L
        auto end = steady_clock::now();
        duration<double> time_span = duration_cast<duration<double>>(end - start);;
        printf("Total time: %.6fs\n", time_span.count());
        #endif
    #endif
    return 0;
}

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

using namespace std;
typedef long long ll;
#define rep(i,j,n) for (ll i = j; i < (n); i++)
#define CLR(mat,f) memset(mat, f, sizeof(mat))
#define IN(a, b, x) (a<=x&&x<b)
#define out(ans) cout << ans << endl
typedef pair<ll,ll>P;
const ll mod=1e9+7;
const int INF = 1000000;
const double PI=3.14159265359;


int main(){

  double n;cin>>n;

  if(n<1||50000<n){
    out(":(");
    return 0;
  }


  for(int i=1;i<=50000;i++){
    if((int)(i*1.08)==n){
      out(i);
      return 0;
    }
  }
  out(":(");



  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>   
#define rep(i, n) for(long long int i = 0; i < n; i++)
#define _rep(i, m, n) for(long long int i = m; i < n; i++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const ll mod = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
     
ll gcd(ll A, ll B){
    if(B == 0)return A;
    return gcd(B, A % B);
}
ll lcm(ll A, ll B){
    return A * B / gcd(A, B);
}
using Graph = vector<vector<int>>;
Graph G;

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

    vector<ll> sum_a(n + 1);
    vector<ll> sum_b(m + 1);
    sum_a[0] = 0;
    sum_b[0] = 0;
    _rep(i, 1, n + 1) sum_a[i] = sum_a[i - 1] + a[i - 1];
    _rep(i, 1, m + 1) sum_b[i] = sum_b[i - 1] + b[i - 1];

    int ans_max = 0;
    rep(i, n + 1){
        if(sum_a[i] > k) continue;
        auto it = upper_bound(sum_b.begin(), sum_b.end(), k - sum_a[i]);
        int index = distance(sum_b.begin(), it);
        ans_max = max((int)i + index - 1, ans_max);
    }
    cout << ans_max << endl;
}

Measured memory_bytes: 9532
import java.util.*;
class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        int[] a = new int[3*n];
        for(int i =0;i<3*n;i++){
            a[i]=Integer.parseInt(sc.next());
        }
        long ans = 0;
        Arrays.sort(a);
        for(int i =n;i<3*n;i+=2){
            ans += a[i];
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 63396
#include <stdio.h>
#include <stdlib.h>

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

	scanf("%d %d %d %d", &a, &b, &c, &d);

	printf(abs(a - c) <= d || abs(a - b) <= d && abs(b - c) <= d ? "Yes\n" : "No\n");

	return 0;
}

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


int main()
{
    ll n,temp;
    cin>>n;
    deque<ll> dq;
    deque<ll>::iterator it;
    for(int i=0;i<n;i++)
    {
        cin>>temp;
        if(i%2==0)
        {
            dq.push_back(temp);
        }
        else
        {
            dq.push_front(temp);
        }
    }
    if(n%2!=0)
    {
        reverse(dq.begin(),dq.end());
    }
    for(it=dq.begin();it!=dq.end();it++)
    {
        cout<<*it<<" ";
    }
    printf("\n");


    return 0;
}

Measured memory_bytes: 3840