akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define drep(i,cc,n) for(int i=(cc);i<=(n);++i)
#define rep(i,n) drep(i,0,n-1)
#define drrep(i,cc,n) for(int i=(cc);i>=(n);--i)
#define rrep(i,n) drrep(i,0,n-1)
#define sz(s) (int)(s.size())
#define vecprint(v) rep(i,v.size())if(i==0)cout << v[i];else cout << " " << v[i]; cout << endl;
#define arrprint(v,n) rep(i,n)if(i==0)cout << v[i];else cout << " " << v[i]; cout << endl;
#define matprint(v,n,m) rep(i,n){rep(j,m){cout << v[i][j] << " ";}cout << endl;}
#define SORT(v) sort(v.begin(), v.end())
#define REV(v) reverse(v.begin(), v.end())
using namespace std;
const int mod=1000000007;
const int INF=1001001001;
using ll = long long;
using P = pair<int,int>;
template<typename T>
using priority_queue_rev = priority_queue<T, vector<T>, greater<T>>; //小さいものから取り出す

int d;
vector<int> c(26);
vector<vector<int>> s;
vector<int> t, now;
vector<int> last(26, -1);
ll best = 0;

ll score(){
    ll res = 0;
    rep(i,26)last[i] = -1;
    rep(i,d){
        res += s[i][now[i]];
        last[now[i]] = i;
        rep(j,26) res -= c[j] * (i - last[j]);
    }
    return res;
}

int main(){
    random_device seed;
    mt19937 mt(seed());
    uniform_int_distribution<int> rnd1(0,25);

    cin >> d;
    uniform_int_distribution<int> rnd2(0,d-1);

    rep(i,26) cin >> c[i];
    s.resize(d);
    rep(i,d)s[i].resize(26);
    rep(i,d)rep(j,26) cin >> s[i][j];
    t.resize(d);now.resize(d);
    rep(i,d){now[i] = i%26;t[i] = now[i];}
    best = score();
    ll now_s;
    rep(dd,25){
        rep(i,d)now[i] = (dd+i)%26;
        now_s = score();
        if(best < now_s){
            best = now_s;
            rep(j,d)t[j] = now[j];
        }        
        rep(_,400){
            // cout << best << endl;
            // rep(i,d)now[i] = rnd1(mt);
            int choice = rnd2(mt);
            rep(i,26){
                now[choice] = i;
                now_s = score();
                if(best < now_s){
                    best = now_s;
                    rep(j,d)t[j] = now[j];
                }
            }
        }
    }

    // cout << score() << endl;
    rep(i,d)cout << t[i]+1 << endl;

    return 0;
}

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

#define debug(x) cout <<"DEBUG"<<" "<< #x << ":" << x << '\n'

//↓0-originか1-originでn回繰り返し
#define rep(i,n) for(int i = 0; i < ((int)(n)); i++)   //0-indexed昇順
#define rep1(i,n) for(int i = 1; i <= ((int)(n)); i++) //1-indexed昇順
#define rrep(i,n) for(int i = ((int)(n)-1); i >= 0; i--)  //0-indexed降順
#define rrep1(i,n) for(int i = ((int)(n)); i >= 1; i--)   //1-indexed降順
#define all(x) (x).begin(),(x).end()

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vi> vii; //2次元配列
typedef vector<ll> vll;
typedef pair<int, int> PII;

template<typename T>
using vec = vector<T>;
template<class T>
using maxheap = std::priority_queue<T>;
template<class T>
using minheap = std::priority_queue<T, std::vector<T>, std::greater<T>>;

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

const ld PI = acos(-1.0L);
const ll infll = (1LL<<62)-1;
const int inf = (1<<30)-1;
const int mod = 1000000007;
//const int mod = 998244353;

/*FUNCs=================================================*/


/*MAIN==================================================*/
signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);   //cin cout 高速化
    //cout << fixed << setprecision(10);

    ll n, k; cin >> n >> k;
    vll h(n); rep(i,n) cin >> h[i];
    sort(all(h));
    ll times = n-k;
    ll ans = 0;
    for(ll i = 0; i < times; i++) {
        ans += h[i];
    }
    cout << ans << '\n';

}

Measured memory_bytes: 1792
def main():
    n, k = map(int, input().split())
    r, s, p = map(int, input().split())
    t = list(input())

    score = 0
    for i in range(n):
        if i - k >= 0:
            if t[i] == t[i-k]:
                t[i] = "x"
                continue

        if t[i] == "r":
            score += p
        elif t[i] == "s":
            score += r
        elif t[i] == "p":
            score += s

    print(score)


if __name__ == '__main__':
    main()

Measured memory_bytes: 4084
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<vector>
#define SF scanf
#define PF printf
#define MAXN 200010
using namespace std;
typedef long long ll;
int n,m;
int cnt[MAXN][2];
char s[MAXN];
bool del[MAXN];
vector<int> a[MAXN];
void dfs(int x){
	del[x]=1;
	for(int i=0;i<a[x].size();i++){
		int u=a[x][i];
		if(del[u]==0){
			cnt[u][s[x]-'A']--;
			if(cnt[u][s[x]-'A']==0)
				dfs(u);
		}
	}
}
int main(){
	SF("%d%d",&n,&m);
	SF("%s",s+1);
	int u,v;
	for(int i=1;i<=m;i++){
		SF("%d%d",&u,&v);
		a[u].push_back(v);
		a[v].push_back(u);
		cnt[v][s[u]-'A']++;
		cnt[u][s[v]-'A']++;	
	}
	for(int i=1;i<=n;i++)
		if(del[i]==0&&(cnt[i][0]==0||cnt[i][1]==0))
			dfs(i);
	for(int i=1;i<=n;i++)
		if(del[i]==0){
			PF("Yes");
			return 0;
		}
	PF("No");
}

Measured memory_bytes: 15488
#include <bits/stdc++.h>
#define F(i,a,b) for(int i=(a);i<=(b);++i)
#define F_(i,a,b) for(int i=(a);i>=(b);--i)
#define G(i,u) for(int i=Head[a];i;i=Next[i])

typedef long long ll;
typedef double db;
typedef long double ld;

template<typename T> inline T max(T& a, T b) { return a>b?a:a=b; }
template<typename T> inline T min(T& a, T b) { return a<b?a:a=b; }

const int N = 200005;

int a[N];

int main() {
	int n;
	scanf("%d", &n); 
	F(i,1,n) scanf("%d", &a[i]), a[i] = a[i-1]^a[i];
	
	int l = 1; ll ans = 1;
	
	F(i,2,n) {
		while((a[i-1]^a[l-1]) & (a[i]^a[i-1])) l ++;
		ans += i-l+1;
	}
	printf("%lld\n", ans);
	
	return 0;
}


Measured memory_bytes: 1024
#include<cstdio>
using namespace std;

int main(){
  bool g[1000][1000];
  int p[2][1000],i,j,h,w,n,t;
  while(scanf("%d%d%d",&h,&w,&n) && (h||w||n)){
    for(i=0;i<h;i++)
      for(j=0;j<w;j++){
	scanf("%d",&t);
	g[i][j]=t?1:0;
       
      }
    for(i=0;i<w;i++)p[0][i]=p[1][i]=0;
    p[0][0]=n-1;
    for(i=0;i<h;i++)
      for(j=0;j<w;j++){
	t=i&1;
	n=p[t][j];
	if(g[i][j]){
	  p[1-t][j]+=n/2;
	  p[t][j+1]+=n-n/2;
	}else{
	  p[1-t][j]+=n-n/2;
	  p[t][j+1]+=n/2;
	}
	if(n&1)g[i][j]=!g[i][j];
	p[t][j]=0;
      }

    i=j=0;
    while(i<h && j<w)g[i][j]?j++:i++;
    printf("%d %d\n",i+1,j+1);
  }
}

Measured memory_bytes: 1748
#include <iostream>
#include <string>
int main(){

std::string N ;

std::cin >> N ;

if(N[0]==N[1] && N[1]==N[2])
{std::cout << "Yes" << std::endl;
}
else if(N[1]==N[2] && N[2]==N[3])
{std::cout << "Yes" << std::endl;}
else
{std::cout << "No" << std:: endl;
}
	}

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

int main(){
  string S;
  cin >> S;
  rep(i, S.size()){
    int count = 0;
    rep(j, S.size()){
      if (i == j) continue;
      if (S.at(i) == S.at(j)) count += 1;
    }
    if (count != 1){
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
}

Measured memory_bytes: 3588
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

using vl = vector<ll>;

vl b(const vl &v)
{
    int n = v.size();

    vl r(v);
    r[0]+=n;
    for(int i=1; i<n; ++i) --r[i];

    sort(all(r));
    return r;
}

int main()
{
    ll k;
    cin >>k;

    int n = 50;
    ll num = k/n;
    vl a(n,num+49);
    k -= num*n;

    while(k--) a = b(a);

    printf("%d\n", n);
    rep(i,n) printf("%lld%c", a[i], " \n"[i==n-1]);
    return 0;
}


Measured memory_bytes: 256
l = [int(i) for i in input().split()] 
ans = 0

for j in range(len(l) - 1):
	for i in range(len(l) - 1):
		if l[i+1] < l[i]:
			tmp = l[i+1]
			l[i+1] = l[i]
			l[i] = tmp
        
for i in range(len(l) - 1):
	ans += l[i+1] - l[i]
    
print(ans)

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

int main() {
	int x,a,b;
  	cin>>x>>a>>b;
  int al = a-x;
  int bl = b-x;
  
  if(al<0){
    al = -al;
  }
  
  if(bl<0){
    bl = -bl;
  }
  
  
  if(al<bl){
    cout<<"A"<<endl;
  }
  
  else{
    cout<<"B"<<endl;
  }
      
          
}
  

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
constexpr int P = 1'000'000'007;
int main() {
  int n;
  cin >> n;
  vector<int> a(n + 1, 0);
  for (int &i : a) cin >> i;
  vector<int> fac(n+2,1), ifac(n+2,1),rev(n+2,0);
  rev[1]=1;
  for (int i = 2; i <= n+1; ++i) {
    rev[i] = (P - (int64_t) (P / i) * rev[P % i] % P) % P;
    fac[i] = (int64_t) i * fac[i - 1] % P;
    ifac[i] = (int64_t) rev[i] * ifac[i - 1] % P;
  }
  auto choose = [&](int n, int k) {
    return k < 0 || k > n ? (int64_t) 0 : (int64_t) fac[n] * ifac[k] % P * ifac[n - k] % P;
  };
  int len = -1;
  vector<int> pos(n+1,-1);
  for (int i = 0; i <= n; ++i) {
    if (pos[a[i]] == -1) pos[a[i]] = i;
    else len = i - pos[a[i]] + 1;
  }
  for (int i = 1; i <= n + 1; ++i) {
    cout << (choose(n + 1, i) + P - choose(n+1-len,i-1))%P << '\n';
  }
  return 0;
}

Measured memory_bytes: 5004
#include <bits/stdc++.h>
#define ll long long
#define MOD 1000000007
using namespace std;


int main(){

    ll n,m;
    cin>>n>>m;
    vector<ll>v[n+1];

    bool A[n+1]= {false};
    ll indeg[100004] = {0};
    for(ll i = 0; i < n+m-1; i++){
        ll a,b;
        cin>>a>>b;
        v[a].push_back(b);
        indeg[b]++;
        A[b] = true;
    }
    ll root=0;
    for(ll i = 1; i <= n; i++){
        if(!A[i])
            root = i;
    }
    ll dis[100004] = {0};
    dis[root] = 0;
    queue<ll>qu;
    qu.push(root);
    while(!qu.empty()){
        ll s = qu.front();
        qu.pop();
        for (ll i = 0; i < v[s].size(); ++i)
        {
            indeg[v[s][i]]--;
            if(indeg[v[s][i]] == 0){
                qu.push(v[s][i]);
                dis[v[s][i]] = s;
            }
        }
    }
    for(ll i = 1; i <= n; i++){
        cout<<dis[i]<<"\n";
    }
    return 0;
}




//freopen("input.in","r",stdin);
//freopen("output.out","w",stdout);
//ios::sync_with_stdio(0);cin.tie(0);


Measured memory_bytes: 7936
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i < (n+1); ++i)
using namespace std;
using ll = long long;
const ll INF = +10010010000;
typedef pair<ll,ll> P;
const int mod = 1e9+7;

struct mint{
    ll x;
    mint(ll x=0):x((x%mod+mod)%mod){}
    mint& operator+=(const mint a){
        (x+=a.x)%=mod;
        return *this;
    }
    mint& operator-=(const mint a){
        (x-=mod-a.x)%=mod;
        return *this;
    }
    mint& operator*=(const mint a){
        (x *= a.x)%= mod;
        return *this;
    }
    mint operator+(const mint a)const{
        mint res(*this);
        return res+=a;
    }
    mint operator-(const mint a)const{
        mint res(*this);
        return res-=a;
    }
    mint operator*(const mint a)const{
        mint res(*this);
        return res*=a;
    }
    mint pow(ll t) const {
      if(!t)return 1;
      mint a = pow(t>>1);
      a*=a;
      if(t%1)a*=*this;
      return a;
    }

    // for prime mod
    mint inv() const {
      return pow(mod-2);
    }
    mint& operator/=(const mint a){
      return (*this) *= a.inv();
    }
    mint operator/(const mint a)const{
      mint res(*this);
      return res/=a;
    }
};

struct combination{
  vector<mint> fact, ifact;
  combination(int n):fact(n+1),ifact(n+1){
    fact[0] = 1;
    for(int i = 1; i<n;++i)fact[i] = fact[i-1] * i;
    ifact[n] = fact[n].inv();
    for(int i = n; i>=1;--i) ifact[i-1] = ifact[i] * i;
  }
  mint operator()(int n, int k){
    if(k<0 || k>n)return 0;
    return fact[n] * ifact[k] + ifact[n-k]; 
  }
};

ll calc(ll x){
    ll ans = 0;
    rep(i,50){
        ll loop = 1LL<<(i+1);
        ll cnt = (x/loop) * (loop/2);
        cnt += max((x%loop)-(loop/2)+1,0LL);
        if(cnt%2==1){
            ans += (1LL<<i);
        }
    }
    return ans;
}

int main(){
    ll a,b;
    cin >> a >> b;
    b = calc(b);a = calc(a-1);
    ll ans = a^b;
    cout << ans << endl;
    return 0;

}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.UncheckedIOException;
import java.util.HashMap;
import java.util.StringTokenizer;

class Main{
	public static void main(String[] args) {
		SC sc=new SC(System.in);
		while(true) {
			int N=sc.nextInt();
			if(N==0) {
				System.exit(0);
			}
			HashMap<String,String> unko=new HashMap<String,String>();
			for(int i=0; i<N; i++) {
				String moto=sc.next();
				String ato=sc.next();
				unko.put(moto, ato);
			}
			StringBuilder sb=new StringBuilder();
			int K=sc.nextInt();
			for(int i=0; i<K; i++) {
				String tmp=sc.next();
				if(unko.containsKey(tmp)) {
					sb.append(unko.get(tmp));
				}
				else {
					sb.append(tmp);
				}
			}
			pl(sb.toString());
		}
	}
	public static void pl(Object o) {
		System.out.println(o);
	}
	public static void pl() {
		System.out.println();
	}
	public static void p(Object o) {
		System.out.print(o);
	}
	static class SC {
		private BufferedReader reader = null;
		private StringTokenizer tokenizer = null;
		public SC(InputStream in) {
			reader = new BufferedReader(new InputStreamReader(in));
		}
		public String next() {
			if (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					tokenizer = new StringTokenizer(reader.readLine());
				} catch (IOException e) {
					throw new UncheckedIOException(e);
				}
			}
			return tokenizer.nextToken();
		}
		public int nextInt() {
			return Integer.parseInt(next());
		}
		public long nextLong() {
			return Long.parseLong(next());
		}
		public double nextDouble() {
			return Double.parseDouble(next());
		}
		public String nextLine() {
			try {
				return reader.readLine();
			} catch (IOException e) {
				throw new UncheckedIOException(e);
			}
		}
	}
}


Measured memory_bytes: 44036
import java.util.*;
import java.util.stream.Collectors;

public class Main {

    static public void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int H = sc.nextInt();
        int W = sc.nextInt();
        int M = sc.nextInt();

        Map<Integer, Integer> hNum = new HashMap<>();
        Map<Integer, Integer> wNum = new HashMap<>();
        HashSet<Point> points = new HashSet<Point>();


        for (int i = 0; i < M; i++) {
            int h = sc.nextInt();
            int w = sc.nextInt();

            points.add(new Point(h,w));

            if (hNum.containsKey(h)) {
                hNum.put(h, hNum.get(h) + 1);
            } else {
                hNum.put(h, 1);
            }

            if (wNum.containsKey(w)) {
                wNum.put(w, wNum.get(w) + 1);
            } else {
                wNum.put(w, 1);
            }
        }

        List<Map.Entry<Integer, Integer>> hs = hNum.entrySet().stream()
                .sorted((e1, e2) -> Integer.compare(e2.getValue(), e1.getValue()))
                .collect(Collectors.toList());
        List<Map.Entry<Integer, Integer>> ws = wNum.entrySet().stream()
                .sorted((e1, e2) -> Integer.compare(e2.getValue(), e1.getValue()))
                .collect(Collectors.toList());


        int hMax = hs.get(0).getValue();
        int wMax = ws.get(0).getValue();

        List<Map.Entry<Integer, Integer>> hsMax = hs.stream().filter(e -> e.getValue() == hMax).collect(Collectors.toList());
        List<Map.Entry<Integer, Integer>> wsMax = ws.stream().filter(e -> e.getValue() == wMax).collect(Collectors.toList());

        boolean on = true;
        for(Map.Entry<Integer, Integer> he : hsMax){
            for(Map.Entry<Integer, Integer> we : wsMax){
                Point p = new Point(he.getKey(), we.getKey());
                if(!points.contains(p)){
                    on = false;
                    break;
                }
            }
            if(!on){
                break;
            }
        }

        System.out.println(hMax + wMax - 1 + (on ? 0 : 1));
    }

    static class Point implements Comparable<Point> {
        int h;
        int w;

        Point(int h, int w) {
            this.h = h;
            this.w = w;
        }

        @Override
        public int compareTo(Point o) {
            if (this.h > o.h) {
                return 1;
            } else if (this.h < o.h) {
                return -1;
            }
            return this.w - o.w;
        }

        @Override
        public boolean equals(Object o){
            if(!(o instanceof Point)){
                return false;
            }
            Point op = (Point)o;
            return (this.h == op.h) && (this.w == op.w);
        }

        @Override
        public int hashCode(){
            return h*31+w;
        }
    }
}


Measured memory_bytes: 126872
N, M = map(int, input().split())
X = sorted(list(map(int, input().split())))

if N>=M:
    print(0)
else: 
    dist = [b-a for a, b  in zip(X, X[1:])]
    dist.sort()
    if (N-1)==0:
        print(sum(dist[:M-N]))
    else:
        print(sum(dist[:-(N-1)]))

Measured memory_bytes: 13960
n = int(input())
a = [list(map(int, input().split())) for _ in range(2)]

line_one = [sum(a[0][0:i+1]) for i in range(n)]
line_two = [sum(a[1][n-1-i:n]) for i in range(n)][::-1]

print(max([line_one[i] + line_two[i] for i in range(n)]))


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

int main(){
	int N;
	string S, T;
	cin >> N >> S>> T;
	string c="";
	for(int x = 0; x<N; x++){
		c = c + S[x];
		c = c + T[x];
	}
	cout << c;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <chrono>
#include <random>
#include <cassert>

std::mt19937 rng((int) std::chrono::steady_clock::now().time_since_epoch().count());

int main() {
	std::ios_base::sync_with_stdio(false); std::cin.tie(NULL);
	int n, m;
	std::cin >> n >> m;
	std::vector<int> mask(n, 0);
	while(m--) {
		int u, v;
		std::cin >> u >> v;
		u--;v--;
		if(u == 0) {
			mask[v] |= 1;
		}
		if(v == n-1) {
			mask[u] |= 2;
		}
	}
	bool valid = false;
	for(auto x : mask) valid = valid || x == 3;
	std::cout << (valid ? "POSSIBLE\n" : "IMPOSSIBLE\n");
}

Measured memory_bytes: 4012
a = input()
b = input()
c = input()
d = input()
e = input()
k = input()


list = [a,b,c,d,e]
flag = 0


for first_num in list:
    for second_num in list:
        if (int(first_num) - int(second_num)) > abs(int(k)):
          flag = 1

if flag == 0:
  print('Yay!')
else:
  print(':(')


Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <algorithm>
#include <stdio.h>
#include <math.h>
#include <string>
#include <cctype>
#include <map>
#include <limits>
#include <iomanip>

using namespace std;

const int mod = 1000000007;
#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))
#define ll long long

int main()
{
    char C;
	cin >> C;

	cout << (isupper(C) ? "A" : "a") << endl;

	return 0;
}

Measured memory_bytes: 3056
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <iterator>
#include <numeric>
#include <cstdint>
#include <cmath>
#include <bitset>
#include <string>
#include <list>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>

#define N_TIMES(i, n)     for ( uint64_t i = 0;     i <  n; ++i )
#define N_TIMES_REV(i, n) for (  int64_t i = n - 1; i >= 0; --i )

using namespace std;

uint64_t diff_abs(uint64_t x, uint64_t y)
{
  return x > y ? x - y : y - x;
}

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

  vector<uint64_t> A(N);
  N_TIMES(n, N) { cin >> A[n]; }

  vector<uint64_t> S(N + 1, 0);
  N_TIMES(n, N) {
    S[n + 1] = A[n] + S[n];
  }

  uint64_t L = S[N], m = 1e+18;
  N_TIMES(n, N - 1) {
    uint64_t x = S[n + 1], y = L - S[n + 1];
    m = min(m, diff_abs(x, y));
  }
  cout << m << endl;

  return 0;
}

Measured memory_bytes: 3328
#!/usr/bin/env python
import numpy as np


def solve():
    N = int(input())
    A = np.array(list(map(int, input().split())))
    B = np.array(list(map(int, input().split())))

    # 自明
    if sum(A) < sum(B):
        print(-1)
        return

    # できるとき
    few = A < B
    few_cnt = few.sum()
    few_sum = (B - A)[few].sum()
    if few_cnt == 0:
        print(0)
        return

    over = (A >= B)
    overs = (A - B)[over]
    overs.sort()
    overs_cumsum = overs[::-1].cumsum()
    for i, v in enumerate(overs_cumsum):
        if v >= few_sum:
            print(few_cnt + i + 1)
            return


if __name__ == "__main__":
    solve()


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

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

using namespace std;

int main() {
  int n;
  std::cin >> n;
  std::vector<uint64_t> a(n);
  rep(i, n) std::cin >> a[i];

  std::map<int, int> map;
  rep(i, n) { map[a[i]]++; }

  int num = 0;
  for (auto i : map) {
    if (i.second % 2) {
      num++;
    }
  }

  std::cout << num << std::endl;
  return 0;
}


Measured memory_bytes: 8628
n,k=map(int,input().split())
A=list(map(int,input().split()))
A=[i-1 for i in A]
seen=[-1]*n;seen[0]=0

cnt=0
now=0
roop=[0]
while 1:
    if seen[A[now]]!=-1:
        roopnum=cnt-seen[A[now]]+1
        mae=seen[A[now]]
        trueroop=roop[seen[A[now]]: cnt+1]
        #print(trueroop,roopnum,mae)
        break
    now=A[now]
    cnt+=1
    roop.append(now)
    seen[now]=cnt

if k<=mae:
    print(roop[k]+1)
else:
    print(trueroop[(k-mae)%roopnum]+1)


Measured memory_bytes: 32364
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <math.h> // sqrt
using namespace std;

int main() {
    vector<int> data(5);
    for (int i = 0; i < 5; i++) {
        cin >> data.at(i);
    } 
    for (int i = 0; i < 5; i++) {
        if (data.at(i) == 0) {
            cout << i + 1 << endl;
        }
    } 
}

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

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

    if (N == 1) {
        cout << 1 << endl;
        return 0;
    }

    vector<int> P(N);
    for (int i = 0; i < N; i++)
    {
        cin >> P[i];
    }

    int counter = N;
    int minValue = P[0];
    for (int i = 0; i < N; i++)
    {
        if (P[i] > minValue) {
            counter--;
        }
        minValue = min(minValue, P[i]);
    }

    cout << counter << endl;
}

Measured memory_bytes: 1024
#include <iostream>

using namespace std;

typedef long long ll;

int main(void)
{
  int S;
  cin >> S;
  int pre = S / 100;
  int suf = S % 100;
  if (1 <= pre && pre <= 12) {
    if (1 <= suf && suf <= 12) {
      cout << "AMBIGUOUS" << endl;
    } else {
      cout << "MMYY" << endl;
    }
  } else {
    if (1 <= suf && suf <= 12) {
      cout << "YYMM" << endl;
    } else {
      cout << "NA" << endl;
    }
  }
}


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

int main(void)
{
	const int N = 100;
	char str[N+1];
	int count = 0;
	int i, j;
	while(scanf("%s", str) == 1)
	{
		int size = strlen(str);
		for(i = 0, j = size-1; i<j; i++,j--)
		{
			if(str[i] != str[j])
				break;
		}
		if(i >= j)
			count++;
	}
	printf("%d\n", count);
	return 0;
}

Measured memory_bytes: 0
import sys
def input(): return sys.stdin.readline().rstrip()
from collections import Counter
def main():
    h,w=map(int,input().split())
    s=""
    for _ in range(h):
        s+=input()
    sc=list(Counter(s).values())
    cunt_1=(h%2)*(w%2)
    cunt_2=(h%2)*(w//2)+(w%2)*(h//2)
    cunt_4=(h//2)*(w//2)
    #print(sc)
    for i,scc in enumerate(sc):
        if scc>=4:
            x=min(scc//4,cunt_4)
            sc[i]-=x*4
            cunt_4-=x
        if cunt_4==0:break
    else:
        print("No")
        sys.exit()
    for i,scc in enumerate(sc):
        if scc>=2:
            x=min(scc//2,cunt_2)
            sc[i]-=x*2
            cunt_2-=x
        if cunt_2==0:break
    else:
        print("No") 
        sys.exit()
    for i,scc in enumerate(sc):
        if scc>=1:
            x=min(scc,cunt_1)
            sc[i]-=x
            cunt_1-=x
        if cunt_1==0:break
    else:
        print("No")   
        sys.exit()  
    print("Yes")

        

if __name__=='__main__':
    main()


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

#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define F0R(i,a) FOR(i,0,a)
#define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define R0F(i,a) ROF(i,0,a)

using ll = long long;
using ld = long double;
ll INF = LLONG_MAX;

using vi = vector<int>;
using vll = vector<ll>;
using pii = pair<int, int>;

namespace output {
	void pr(int x) { cout << x; }
	void pr(long x) { cout << x; }
	void pr(ll x) { cout << x; }
	void pr(unsigned x) { cout << x; }
	void pr(unsigned long x) { cout << x; }
	void pr(unsigned long long x) { cout << x; }
	void pr(float x) { cout << x; }
	void pr(double x) { cout << x; }
	void pr(ld x) { cout << x; }
	void pr(char x) { cout << x; }
	void pr(const char* x) { cout << x; }
	void pr(const string& x) { cout << x; }
	void pr(bool x) { pr(x ? "true" : "false"); }
	template<class T> void pr(const complex<T>& x) { cout << x; }
	
	template<class T1, class T2> void pr(const pair<T1,T2>& x);
	template<class T> void pr(const T& x);
	
	template<class T, class... Ts> void pr(const T& t, const Ts&... ts) { 
		pr(t); pr(ts...); 
	}
	template<class T1, class T2> void pr(const pair<T1,T2>& x) { 
		pr("{",x.f,", ",x.s,"}"); 
	}
	template<class T> void pr(const T& x) { 
		pr("{"); // const iterator needed for vector<bool>
		bool fst = 1; for (const auto& a: x) pr(!fst?", ":"",a), fst = 0; 
		pr("}");
	}
	
	void print() { pr("\n"); } // print w/ spaces
	template<class T, class... Ts> void print(const T& t, const Ts&... ts) { 
		pr(t); if (sizeof...(ts)) pr(" "); print(ts...); 
	}
}

using namespace output;
int N, K, C; 
vi dpl;
vi dpr;
int dprq(int i) {
	if (i < N) return dpr[i];
	return 0;
}
int dplq(int i) {
	if (i < 0) return 0;
	return dpl[i];
}

int main() {
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	cin >> N >> K >> C;
	string S; cin >> S;
	dpr.resize(N);
	dpl.resize(N);
	R0F(i, N) {
		if (S[i] == 'o') {
			dpr[i] = 1 + dprq(i + C + 1);
		}
		dpr[i] = max(dpr[i], dprq(i+1));
	}
	F0R(i, N) {
		if (S[i] == 'o') {
			dpl[i] = 1 + dplq(i - C - 1);
		}
		dpl[i] = max(dpl[i], dplq(i-1));
	}
	int LC = 0;
	int LM = 0;
	F0R(i, N) if (S[i] == 'o') {
		if (LC + dprq(max(i+1, LM)) < K && dplq(i - C - 1) + dprq(i + C + 1) + 1 == K) {
			print(i+1);
		}
		if (LM <= i) {
			LC++;
			LM = i + C + 1;
		}
	}
}

Measured memory_bytes: 3348
#include "bits/stdc++.h"
using namespace std;
template <typename T> void read(T& t){ cin >> t; }
template <typename T, typename ... U> void read(T& t, U& ... u){ read(t); read(u ...); }
template <typename T> void write(T t){ cout << t; }
template <typename T, typename ... U> void write(T t, U ... u){ write(t); write(u ...); }
//#define int long long
#define FAST ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define size(x) (int)x.size()
#define all(x) x.begin(),x.end()
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define ROF(i,b,a) for(int i=b; i>=a; --i)
#define LL long long
using pii = pair<int,int>;
const int INF = 2e9;
const int NN = 1e5 + 3;

int n;
set<LL> s;
map<LL,int> id;
map<int,LL> dist, dist2;
int sz[NN];
vector<pii> e;
vector<int> adj[NN];

void checkConn(int u, set<int> &visited){
	visited.insert(u);
	for(int v: adj[u]) if(!visited.count(v)) checkConn(v, visited);
}

LL getDistSum(int u, int prv, int d){
	LL sum = 0;
	sum += d;
	for(int v: adj[u]) if(v != prv) sum += getDistSum(v, u, d+1);
	return sum;
}

void distributeDistSum(int u, int prv, LL sum){
	dist2[u] = sum;
	for(int v: adj[u]) if(v != prv) distributeDistSum(v, u, sum - sz[v] + (n-sz[v]));
}

int32_t main(){ FAST;
	read(n);
	FOR(i,1,n){ LL d; read(d); s.insert(d); id[d] = i; dist[i] = d; }

	if(n == 2 || n == 3 || n == 4){
		write(-1, "\n");
		return 0;
	}

	FOR(i,1,n) sz[i] = 1;
	ROF(cnt,n,2){
		LL d = *rbegin(s);
		s.erase(d);
		int i = id[d];

		LL nxtD = d + sz[i] - (n-sz[i]);
		if(!s.count(nxtD)){
			write(-1, "\n");
			return 0;
		}

		int j = id[nxtD];
		e.emplace_back(i,j);
		sz[j] += sz[i];
	}

	for(pii edg: e){
		int u,v; tie(u,v) = edg;
		adj[u].emplace_back(v);
		adj[v].emplace_back(u);
	}

	int root = -1;
	FOR(i,1,n) if(sz[i] == n) root = i;
	if(root == -1){
		write(-1, "\n");
		return 0;
	}
	
	set<int> visited;
	checkConn(root, visited);
	if(!(size(visited) == n)){
		write(-1, "\n");
		return 0;
	}

	LL sum = getDistSum(root,root,0);

	distributeDistSum(root,root,sum);

	bool different = false;
	for(auto el: dist) if(dist[el.first] != dist2[el.first]) different = true;
	for(auto el: dist2) if(dist[el.first] != dist2[el.first]) different = true;
	if(different){
		write(-1, "\n");
		return 0;
	}

	for(pii edg: e) write(edg.first, " ", edg.second, "\n");
}

Measured memory_bytes: 39032
import sys

sx, sy, tx, ty = map(int, sys.stdin.readline().split())

def main():
    dx = tx - sx + 1
    dy = ty - sy + 1
    u, r, d, l = list('URDL')
    
    res = ''
    res += u * (dy - 1)
    res += r * dx
    res += d * dy
    res += l * dx
    res += u + l
    res += u * dy
    res += r * dx
    res += d * dy
    res += l * (dx - 1)
    return res

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

Measured memory_bytes: 3064
#include <bits/stdc++.h>
typedef long long int ll;

using namespace std;

typedef std::pair<ll, ll> P;

ll INF = 9223372036854775806;

ll prim(vector<bool> &visit, vector<vector<P>> E)
{
    ll total_cost = 0;

    priority_queue<P, vector<P>, greater<P>> S;
    visit[0] = 1;
    for (P u_pair : E[0])
    {

        S.push(u_pair);
    }

    while (!S.empty())
    {

        ll cost = S.top().first;
        ll u = S.top().second;
        S.pop();

        if (visit[u] == 0)
        {
             //cout << cost <<endl;
            visit[u] = 1;
            total_cost += cost;

            for (P v_pair : E[u])
            {
                if (visit[v_pair.second] == 0)
                {
                    S.push(v_pair);
                }
            }
        }
    }

    return total_cost;
}

int main()
{

    ll N;

    cin >> N;

    vector<P> xs(0);
    vector<P> ys(0);

    vector<ll> xi(N);
    vector<ll> yi(N);

    for (ll i = 0; i < N; i++)
    {

        ll x, y;

        cin >> x >> y;

        xs.push_back(make_pair(x, i));
        ys.push_back(make_pair(y, i));

        xi[i] = x;
        yi[i] = y;
    }

    sort(xs.begin(), xs.end());
    sort(ys.begin(), ys.end());

    vector<vector<P>> E(N, vector<P>(0));
    for (int i = 0; i < N - 1; i++)
    {
        P e1 = make_pair(abs(xi[xs[i + 1].second] - xi[xs[i].second]),xs[i + 1].second);
        P e2 = make_pair(abs(xi[xs[i + 1].second] - xi[xs[i].second]),xs[i].second);

        E[xs[i + 1].second].push_back(e2);
        E[xs[i].second].push_back(e1);
    }

    for (int i = 0; i < N - 1; i++)
    {

        P e1 = make_pair( abs(yi[ys[i + 1].second] - yi[ys[i].second]), ys[i + 1].second);
        P e2 = make_pair( abs(yi[ys[i + 1].second] - yi[ys[i].second]),ys[i].second);
        E[ys[i + 1].second].push_back(e2);
        E[ys[i].second].push_back(e1);
    }

    vector<bool> visit(N, 0);

    ll ans = prim(visit, E);

    cout << ans << endl;
}

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

#define rep(i, n) for ( ll i = 0; i < (n); ++i )
#define reps(i, n) for ( ll i = 1; i <= (n); ++i )
#define _rep(i, n) for ( ll i = (n) - 1; i >= 0; --i )
#define _reps(i, n) for ( ll i = n; i > 0; --i )
#define all(x) (x).begin(), (x).end()
#define _all(x) (x).rbegin(), (x).rend()

using namespace std;
using ll =  long long;
using P = pair<ll, ll>;

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

	set<ll> x[n + 1];
	rep( i, m ) {
		ll a, b;
		cin >> a >> b;
		x[a].insert(b);
		x[b].insert(a);
	}

	ll mark[n + 1] = {};
	mark[1] = -1;
	vector<ll> q;
	q.emplace_back(1);
	ll cnt = 0;
	while( cnt < (ll)q.size() ) {
		for ( const ll& tmp : x[q[cnt]] ) {
			if ( mark[tmp] == 0 ) {
				mark[tmp] = q[cnt];
				q.emplace_back(tmp);
			}
		}
		cnt++;
	}

	reps( i, n ) {
		if ( mark[i] == 0 ) {
			cout << "No" << endl;
			return 0;
		}
	}

	cout << "Yes" << endl;
	for ( ll i = 2; i <= n; i++ ) {
		cout << mark[i] << endl;
	}


	return 0;
}


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

int main() {

    int N, X, T;
    cin >> N >> X >> T;

    int c = N - ((N / X) * X);

    if (c == 0) cout << (N / X) * T << endl;
    else cout << (N / X + 1) * T << endl;

    return 0;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
using namespace std;
using str = string;
using ll = long long;
using vi = vector<int>;
using vii = vector<vi>;

int main() {
    str S;
    cin >> S;
    int n = S.size();
    str ans;
    for(int i = 1; i <=5; i++) {
        ans += "hi";
        if(ans == S) {
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007
int main() {
	ll n;
	cin>>n;
	vector<ll>q1,q2,q3,q4;
	ll x[200010];
	ll y[200010];
	for(ll i=0;i<n;i++){
		cin>>x[i]>>y[i];
	}
	ll ans=0;
	for(ll i=0;i<n;i++){
		ll nowx=x[i];
		ll nowy=y[i];
		q1.push_back(nowx+nowy);
	}
	sort(q1.begin(),q1.end());
	ans=max(ans,q1[n-1]-q1[0]);
	for(ll i=0;i<n;i++){
		ll nowx=1000000000-x[i];
		ll nowy=y[i];
		q2.push_back(nowx+nowy);
	}
	sort(q2.begin(),q2.end());
	ans=max(ans,q2[n-1]-q2[0]);	
	for(ll i=0;i<n;i++){
		ll nowx=1000000000-x[i];
		ll nowy=1000000000-y[i];
		q3.push_back(nowx+nowy);
	}
	sort(q3.begin(),q3.end());
	ans=max(ans,q3[n-1]-q3[0]);	
	for(ll i=0;i<n;i++){
		ll nowx=x[i];
		ll nowy=1000000000-y[i];
		q4.push_back(nowx+nowy);
	}
	sort(q4.begin(),q4.end());
	ans=max(ans,q4[n-1]-q4[0]);			
	cout <<ans;
	// your code goes here
	return 0;
}

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

public class Hello
{
    public static void Main()
    {
        var d = new Dictionary<char, long>();
        var s = Console.ReadLine().Trim();
        var sL =(long) s.Length;
        for (int i = 0; i < sL; i++)
            if (d.ContainsKey(s[i])) d[s[i]]++;
            else d[s[i]] = 1;
        var count = 0L;
        foreach (var x in d.Where(y => y.Value >= 2))
            count += x.Value* (x.Value - 1) / 2;
        var res = sL * (sL - 1) / 2 - count + 1;
        Console.WriteLine(res);
    }
}



Measured memory_bytes: 14048
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define per(i,a,b) for(int i=(a);i>=(b);--i)
#define ll long long
#define mp make_pair
#define pb push_back
#define debug(...) fprintf(stderr, __VA_ARGS__)
using namespace std;
template<typename T> void ckmax(T&a, T b) { if (b > a) a = b; }
template<typename T> void ckmin(T&a, T b) { if (b < a) a = b; }

const int N = 100000 + 5, mod = 1000000007;
int plu (int u, int v) { return u + v >= mod ? u + v - mod : u + v; }
int mul (int u, int v) { return 1LL * u * v % mod; }
int n, a[N], dp[N][7];//123 132 213 231 312 321
int s[3][6] = {{0, 0, 1, 1, 2, 2}, {1, 2, 0, 2, 0, 1}, {2, 1, 2, 0, 1, 0}}, f[N][6], avi[N][6];
vector<int> he[N];
map<vector<int>, int> tmpp;
int main ()
{
	scanf ("%d", &n);
	for (int i = 1; i <= n; ++i) scanf ("%d", &a[i]), he[a[i] + 1].pb (i);
	for (int i = 1; i <= n; ++i) if (he[i].size() > 3) { printf ("0\n"); return 0; }
	for (int i = 1; i < n; ++i) if (he[i].size() < he[i + 1].size()) { printf ("0\n"); return 0; }
	rep (i, 1, n) rep (j, 1, 3 - he[i].size()) he[i].pb (0);
	rep (p, 1, n) {
		tmpp.clear();
		rep (i, 0, 5) {
			vector<int>tmp;
			rep (j, 0, 2) tmp.pb (he[p][s[j][i]]);
			if (tmpp[tmp]) continue;
			if (p == 1) f[1][i] = 1;
			tmpp[tmp] = 1;
			avi[p][i] = 1;
		}
	}
	rep (i, 2, n) {
		if (!he[i].size()) break;
		bool flag;
		rep (x, 0, 5) rep (y, 0, 5) {
			if (!avi[i][y]) continue;
			if (!f[i - 1][x]) continue;
			flag = true;
			rep (k, 0, 2) if (he[i - 1][s[k][x]] > he[i][s[k][y]] && he[i][s[k][y]]) flag = false;
			rep (k, 0, 2) if (!he[i - 1][s[k][x]] && he[i][s[k][y]]) flag = false;
			if (!flag) continue;
			f[i][y] = plu (f[i][y], f[i - 1][x]);
		}
	}
	int ans = 0;
	rep (i, 0, 5) ans = plu (ans, f[n][i]);
	printf ("%d\n", ans);
	return 0;
}

Measured memory_bytes: 11904
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
ll GetDigit(ll num){ return log10(num)+1; } //numの桁数を求める

int main()
{
    int n;
    cin >> n;
    vector<int> a(n);
    vector<int> b(n);
    vector<int> c(n-1);
    rep(i,n) cin >> a[i];
    rep(i,n) cin >> b[i];
    rep(i,n-1) cin >> c[i];
    int ans = 0;
    rep(i,n){
        ans += b[i];
    }
    rep(i,n-1){
        if(a[i]+1 == a[i+1]){
            ans += c[a[i]-1];
        }
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3728
#include<iostream>
#include<set>
#include<algorithm>
#include<cmath>
#include<map>
#include<vector>

#define REP(i,s,n) for(int i=s;i<n;i++)
#define rep(i,n) REP(i,0,n)
#define inf (1<<28)
#define MAX (1<<13)

using namespace std;
int n,S;
short M[21];
short memo[21][MAX];

bool dfs(int phase,int nS)
{
  if(memo[phase%(2*n)][nS] != -1)return memo[phase%(2*n)][nS];
  if(nS <= 1)
    {
      if(phase%2)return 1;//enemy
      else       return 0;//friend
    }

  bool res,update;
  update = false;
  REP(i,1,M[phase%(2*n)]+1)
    {
      bool bres = dfs(phase+1,nS-i);
      if(phase%2)
	{
	  if(!update)
	    {
	      update = true;
	      res = bres;
	    } 
	  else res &= bres; 
	}
      else
	{
	  if(!update)
	    {
	      update = true;
	      res = bres;
	    }
	  else res |= bres;
	}
    }
  return memo[phase%(2*n)][nS] = res;
}

int main()
{
  while(cin >> n,n)
    {
      cin >> S;
      rep(i,2*n)cin >> M[i];
      rep(i,21)rep(j,MAX)memo[i][j] = -1;
      //cout << "---------" <<endl;
      cout << (dfs(0,S)?1:0) << endl;
    }
  return 0;
}

Measured memory_bytes: 1920
#include <iostream>
#include <cstdio>
#include <cmath>
#include <string>
#include <algorithm>
using namespace std;
#define mp  std::make_pair
#define ll long long int
#define abs(n) ((n>0)?(n):((n)*(-1)))
#define CEIL(a,b) (((a) + ((b)-1)) / (b))
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n) FOR(i,0,(n)-1)
#define VREP_ll(v) for(std::vector<ll>::iterator itr = (v).begin(); itr != (v).end();itr++)
#define VREP_int(v) for(std::vector<int>::iterator itr = (v).begin(); itr != (v).end();itr++)
#define VALL(v) ((v).begin(),(v).end())
#define errln(v) cerr << (v) << endl;
#define println(v) cout << (v) << endl;

int main(int argc, const char * argv[]) {
	char c;
	cin >> c;
	c+=1;
	cout << c << endl;;

	return 0;
}


Measured memory_bytes: 256
class BIT:
    def __init__(self, n):
        self.n = n
        self.data = [0] * (n + 1)

    def total(self, i):
        res = 0
        while i:
            res += self.data[i]
            i -= i & -i
        return res

    def add(self, i, val):
        while i <= self.n:
            self.data[i] += val
            i += i & -i


N = int(input())
bit = BIT(N)
for i, c in enumerate(input()):
    ind = ord(c) - ord("a")
    bit.add(i + 1, 1 << (ind * 20))
Q = int(input())
for _ in range(Q):
    parts = input().split()
    if parts[0] == "1":
        ind = int(parts[1])
        nval = 1 << ((ord(parts[2]) - ord("a")) * 20)
        val = bit.total(ind) - bit.total(ind - 1)
        bit.add(ind, nval - val)
    else:
        l, r = map(int, parts[1:])
        val = bit.total(r) - bit.total(l - 1)
        mask = (1 << 20) - 1
        ans = 0
        while val:
            if val & mask:
                ans += 1
            val >>= 20
        print(ans)


Measured memory_bytes: 127816
#include<iostream>
#include<string>
using namespace std;
string S; int a[3];
int main() {
	cin >> S; if (S == "mewmew") { goto E; }
	for (int i = 0; i < S.size() - 1; i++) {
		if (S.substr(i, 2) == "mw") { goto E; }
	}
	for (int i = 0; i < S.size(); i++) {
		if (S[i] == 'm') { a[0]++; }
		else if (S[i] == 'e') { a[1]++; }
		else { a[2]++; }
		if (!(a[0] >= a[1] && a[1] >= a[2])) { goto E; }
	}
	cout << "Cat" << endl; goto F;
E:;
	cout << "Rabbit" << endl;
F:;
}

Measured memory_bytes: 1192
#define DEBUG 0
#include <bits/stdc++.h>
#define loop(n) for (lint ngtkana_is_a_genius = 0; ngtkana_is_a_genius < lint(n); ngtkana_is_a_genius++)
#define rep(i, begin, end) for (lint i = lint(begin); (i) < lint(end); i++)
#define all(v) v.begin(), v.end()
#define rand(l, r) std::uniform_int_distribution<>(l, r)(mt)
using lint = long long;
auto mt = std::mt19937_64(std::random_device{}());
auto cmn = [](auto&& a, auto b){ if (a > b) {a = b; return true;} return false; };
auto cmx = [](auto&& a, auto b){ if (a < b) {a = b; return true;} return false; };
void debug_impl() { std::cerr << std::endl; }
template <typename Head, typename... Tail>
void debug_impl(Head head, Tail... tail) { std::cerr << " " << head; debug_impl(tail...); }
#if DEBUG
#define debug(...)\
  do {\
    std::cerr << std::boolalpha << "[" << #__VA_ARGS__ << "]:";\
    debug_impl(__VA_ARGS__);\
    std::cerr << std::noboolalpha;\
  } while (false)
#else
#define debug(...) {}
#endif

template < typename Container, typename Value = typename Container::value_type, std::enable_if_t<!std::is_same< Container, std::string >::value, std::nullptr_t> = nullptr>
std::istream& operator>> (std::istream& is, Container& v)
  { for (auto & x : v) { is >> x; } return is; }

template < typename Container, typename Value = typename Container::value_type, std::enable_if_t<!std::is_same< Container, std::string >::value, std::nullptr_t> = nullptr >
std::ostream& operator<< (std::ostream& os, Container const& v) {
 os << "{";
  for (auto it = v.begin(); it != v.end(); it++)
    {os << (it != v.begin() ? "," : "") << *it;}
  return os << "}";
}

int main() {
  std::cin.tie(0); std::cin.sync_with_stdio(false);
  int n; std::cin >> n;
  std::vector<int> a(n), b(n); std::cin>>a>>b;
  for (int & x : a) x--;
  for (int & x : b) x--;
  debug(a,b);

  int i = 0;
  int x = -1, y = -1;
  std::vector<int> p(n);
  std::iota(all(p), 0);
  do {
    if (a==p) x = i;
    if (b==p) y = i;
    i++;
  } while (std::next_permutation(all(p)));
  assert(x != -1 && y != -1);
  debug(x,y);

  int ans = x - y;
  if (ans < 0 ) ans = -ans;
  std::cout << ans << std::endl;
  return 0;
}

Measured memory_bytes: 256
def main():
    S = input()
    n = len(S)
    i = 0
    prev = None
    count = 0
    while i < n:
        t = S[i]
        while t == prev and i+1 < len(S) :
            i += 1
            t += S[i]
        if prev != t:
            prev = t
            count += 1
        i += 1
        # print(prev)
    return count

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

Measured memory_bytes: 3500
#include <bits/stdc++.h>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <climits>
#include <utility>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <iomanip>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp> 
//setbase - cout << setbase (16); cout << 100 << endl; Prints 64
//setfill -   cout << setfill ('x') << setw (5); cout << 77 << endl; prints xxx77
//setprecision - cout << setprecision (14) << f << endl; Prints x.xxxx
//cout.precision(x)  cout<<fixed<<val;  // prints x digits after decimal in val
using namespace std;
using namespace __gnu_pbds;

#define sp << " " <<
#define mod 1000000007
#define PI 3.14159265358979323
#define y second
#define x first
#define pb push_back
#define mp make_pair
#define sz(a) a.size()
#define pqueue priority_queue< ll >
//#define pdqueue priority_queue< ll,vector<ll> ,greater< ll > >
#define codejamDebug(x) cout<<"Case #"<<x<<": ";
#define debug(x) cout<<#x<<" :"<<x<<endl;
#define rep(i,n) for(long long i=0;i<n;i++)
#define f(i,a,b) for(long long i = a; i < b; i++)
#define fd(i,a,b) for(long long i = a; i >=b; i--)
#define sync ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
typedef long long int           ll;
typedef long double             ld;
typedef unsigned long long int ull;
typedef vector <int>            vi;
typedef vector <ll>            vll;
typedef pair <int, int>        pii;
typedef pair <ll, ll>          pll;
typedef vector < pii >        vpii;
typedef vector < pll >        vpll;
typedef vector <string>         vs;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const ll INF=1e18L+5;
const int nax = 405;
ll dp[nax][nax]; 
//dp[i][j] - minimum cost of combining interval [i,j] into a vertix

ll a[nax];
//Handle:cyber_rajat

//Start Construction from small side
ll fun(ll L,ll R)
{
	ll s=0;
	f(i,L,R+1)s+=a[i];
	return s;
}

int main(int argc, char const *argv[])
{
	sync;
	/*#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	#endif*/
	ll n;
	cin>>n;
	rep(i,n)cin>>a[i];
	fd(L,n-1,0)
	{
		f(R,L,n)
		{
			if(L==R)dp[L][R]=0;
			else
			{
				dp[L][R]=INF;
				ll sum=fun(L,R);
				f(i,L,R)
				{
					dp[L][R]=min(dp[L][R],dp[L][i]+dp[i+1][R]+sum);
				}
			}
		}
	}
	cout<<dp[0][n-1]<<endl;
	return 0;
}


Measured memory_bytes: 1536
package main

import (
	"fmt"
	"math"
)

func main() {
	// Code for C - Colorful Leaderboard
	var N int
	fmt.Scanf("%d", &N)

	color := make(map[int]int, 9)
	var a int
	var flag int = 0
	for i := 0; i < N; i++ {
		fmt.Scanf("%d", &a)

		flag = 0
		for j := 0; j < 8; j++ {
			if 400*j <= a && a < 400*(j+1) {
				color[j]++
				flag = 1
			}
		}

		if flag == 0 {
			color[8]++
		}
		/*
			if 1 <= a && a <= 399 {
				color[0]++
			} else if 400 <= a && a <= 799 {
				color[1]++
			} else if 800 <= a && a <= 1199 {
				color[2]++
			} else if 1200 <= a && a <= 1599 {
				color[3]++
			} else if 1600 <= a && a <= 1999 {
				color[4]++
			} else if 2000 <= a && a <= 2399 {
				color[5]++
			} else if 2400 <= a && a <= 2799 {
				color[6]++
			} else if 2800 <= a && a <= 3199 {
				color[7]++
			} else {
				color[8]++
			}
		*/
	}

	var count int
	for i := 0; i < 8; i++ {
		if color[i] > 0 {
			count++
		}
	}

	var min, max int
	min = int(math.Max(float64(count), 1))
	max = count + color[8]

	fmt.Println(min, max)
}


Measured memory_bytes: 1844
-- diverta 2019 A problem
import Control.Monad
import qualified Data.Text as T

-- conversion from String to Int
toInt :: String -> Int
toInt x = read x :: Int

-- obtain [Int] from I/O
getInts :: IO [Int]
getInts = do
  x <- getLine
  let y = (map $ toInt) $ words x
  return y

-- main function
main :: IO ()
main = do
  nk <- getInts
  let n = head nk
  let k = last nk
  print (n-k+1)

Measured memory_bytes: 508