akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <stdlib.h>

int sort(void *a, void *b) {
	return *(int *)a - *(int *)b;
}


int search(int s[], int x1, int x2, int v) {
	int c = (x2 - x1) >> 1;
	int x = x1 + c;
	if (c == 0) {
		return (s[x1] == v) || (s[x2] == v);
	} 
	if (s[x] > v) {
		return search(s, x1, x, v);
	} else if (s[x] < v) {
		return search(s, x, x2, v);
	}
	return 1;
}

int main(void) {
	int S[100000];
	int n, q;
	int v, c = 0;
	int i;
	
	scanf("%d", &n);
	
	for (i = 0; i < n; ++i) {
		scanf("%d", &v);
		S[i] = v;
	}
	
	qsort(S, n, sizeof(S[0]), sort);
	
	scanf("%d", &q);
	
	++q;
	while (--q) {
		scanf("%d", &v);
		if (search(S, 0, n - 1, v)) {
			++c;
		}
	}
	
	printf("%d\n", c);
	
	return 0;	
}

Measured memory_bytes: 1040
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {

	public static void main(String[] args) {
		FastReader s = new FastReader();
		
		int a =s.nextInt();
		int b = s.nextInt();
		
		if(4*a >= b && b >= 2*a && (4*a-b)%2==0 && (b - 2*a)%2==0)
				System.out.println("Yes");
		else System.out.println("No");
		
		
	}
	
	static class FastReader {
        BufferedReader br;
        StringTokenizer st;
 
        public FastReader()
        {
            br = new BufferedReader(new
                    InputStreamReader(System.in));
        }
 
        String next()
        {
            while (st == null || !st.hasMoreElements())
            {
                try
                {
                    st = new StringTokenizer(br.readLine());
                }
                catch (IOException  e)
                {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }
 
        int nextInt()
        {
            return Integer.parseInt(next());
        }
 
        long nextLong()
        {
            return Long.parseLong(next());
        }
 
        double nextDouble()
        {
            return Double.parseDouble(next());
        }
 
        String nextLine()
        {
            String str = "";
            try
            {
                str = br.readLine();
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
            return str;
        }
	}

}


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

int  main()
{
	int n; cin >> n;
	vector<int> a(n);
	rep(i, n)
		cin >> a[i];
	vector<int> b(n);
	map<int , int> mp;
	rep(i, n)
	{
		cin >> b[i];
		mp[i+1] = b[i];
	}
	vector<int> c(n-1);
	rep(i,n-1)
		cin >> c[i];
	// deque<int> q;
	int sum = 0;
	rep(i, n)
	{
		sum += mp[a[i]];
		if (i < n-1 && a[i+1]- a[i] == 1)
		{
			sum += c[a[i]-1];
		}
	}
	cout << sum << endl;
	return (0);
}


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

int main() {
  ll N,mini(10000000000000000);
  vector <ll> A(4);
  cin>>N>>A[0]>>A[1]>>A[2]>>A[3]>>A[4];
  for (int i(0);i<5;i++) mini=min(mini,A[i]);
  // ll mini =*min_element(A.begin(),A.end());
  ll sum=(N+mini-1)/mini+4;
  cout <<sum<<endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
//template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
 
/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
*/

int main(){
    ll q,h,s,d; cin >> q >> h >> s >> d;
    ll N; cin >> N;

    cout << min(min(8*q, 4*h), min(2*s, d))*(N/2) + min(4*q, min(2*h, s))*(N%2) << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <fstream>
#include <stdio.h>
#include <math.h>
#include <time.h>
#include <string>
#include <tuple>
#include <vector>
#include <map>
#include <unordered_map>
#include <list>
#include <set>
#include <stack>
#include <queue>
#include <cstdlib>
#include <algorithm>
#include <random>
#include <cassert>
using namespace std;
#define LL long long
#define MP(a, b) make_pair(a, b)
#define POWER9 1000000000
#define MOD POWER9+7
#undef INT_MIN
#undef INT_MAX
#define INT_MIN -2147483647
#define INT_MAX 2147483647
#define LL_MIN (LL)-9223372036854775807
#define LL_MAX (LL)9223372036854775807
#define PI 3.14159265359

int a[200000],b[200000];
int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << setprecision(9);

	int N,M;
	cin >> N >> M;
	LL ans = 1;
	if(N == M){
		ans = 2;
		for(int i=1; i<=N; i++){
			ans *= (LL)i;
			ans %= MOD;
		}
		for(int i=1; i<=M; i++){
			ans *= (LL)i;
			ans %= MOD;
		}
	}
	else if(N+1 == M){
		for(int i=1; i<=N; i++){
			ans *= (LL)i;
			ans %= MOD;
		}
		for(int i=1; i<=M; i++){
			ans *= (LL)i;
			ans %= MOD;
		}
	}
	else if(N == M+1){
		for(int i=1; i<=N; i++){
			ans *= (LL)i;
			ans %= MOD;
		}
		for(int i=1; i<=M; i++){
			ans *= (LL)i;
			ans %= MOD;
		}
	}
	else{
		ans = 0;
	}
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
from collections import Counter

n = int(input())
d = list(map(int, input().split()))
mod = 998244353

c = Counter(d)

if d[0] != 0 or c[0] != 1:
    print(0)
    exit()

ans = 1
for i in range(1, max(d)+1):
    if i not in c:
        print(0)
        exit()
    ans *= pow(c[i-1], c[i], mod)

print(ans % mod)


Measured memory_bytes: 19936
# -*- coding: utf-8 -*-
import numpy as np
N, T = map(int, input().split())
c = np.zeros(N, dtype=int)
t = np.zeros(N)
for i in range(N):
  c[i], t[i] = map(int, input().split())

cc = c[t<=T]
if(len(cc) == 0):
  print('TLE')
else:
  print(min(cc))


Measured memory_bytes: 12500
import java.util.Scanner;

class Main {

	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);

		for(;;){
			int m = scan.nextInt();
			int f = scan.nextInt();
			int r = scan.nextInt();
			int sum;
			if(m == -1)
				sum = m;
			else if(f == -1)
				sum = f;
			else if(m == -1 && f == -1)
				sum = 0;
			else
				sum = m + f;

			if(m == -1 && f == -1 && r == -1)
				break;
			else if(sum >= 80)
				System.out.println("A");
			else if(sum >= 65 && sum < 80)
				System.out.println("B");
			else if((sum >= 50 && sum < 65) || (sum >= 30 && sum < 50 && r >= 50))
				System.out.println("C");
			else if(sum >= 30 && sum < 50)
				System.out.println("D");
			else if(sum < 30)
				System.out.println("F");

			if(r == -1)
				continue;

		}
	}

}

Measured memory_bytes: 19244
#include<stdio.h>

int main(void)
{
    long int a,b;
    scanf("%ld",&a);
    scanf("%ld",&b);

    if(a%2 == 0 && b%2 != 0 || a%2 != 0 && b%2 == 0)
        printf("\nIMPOSSIBLE\n");
    else
    {
        long int ans = (a+b)/2;
        printf("\n%ld\n",ans);
    }
    
    return 0;

}


Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <algorithm>
using namespace std;
template <typename T = int>
T in() {
    T temp;
    cin >> temp;
    return temp;
}


int main() {
    int H(in()), W(in());
    int h(in()), w(in());
    cout << (H -h ) * (W - w) << endl; 
    return 0;
}




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

int main() {
    int n,x;
    cin>>n>>x;
    while (n!=0||x!=0)
    {
        int count=0;
        for (int i = 1; i <= n-2; ++i) {
            for (int j = i+1; j <=n-1 ; ++j) {
                for (int k = j+1; k <=n ; ++k) {
                    if (i==j||i==k||j==k) break;
                    if (i+j+k==x) count++;
                }
            }
        }
        cout<<count<<endl;
        cin>>n>>x;
    }
    return 0;
}


Measured memory_bytes: 3088
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <locale>
#include <iostream>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define ALL(x) (x).begin(),(x).end()

using namespace std;

using ll = long long;
using ld = long double;

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template <typename T> int len(const T &x) { return x.size(); }

template<typename T>
vector<T> table(int n, T v) { return vector<T>(n, v); }

template <class... Args>
auto table(int n, Args... args) {
  auto val = table(args...);
  return vector<decltype(val)>(n, move(val));
}

struct yes_no : numpunct<char> {
  string_type do_truename()  const { return "YES"; }
  string_type do_falsename() const { return "NO"; }
};

const string a = "AKIHABARA";

void solve(string S) {
  REP(i,16) {
    string s;
    if ((i >> 0) & 1) s += "A";
    s += "KIH";
    if ((i >> 1) & 1) s += "A";
    s += "B";
    if ((i >> 2) & 1) s += "A";
    s += "R";
    if ((i >> 3) & 1) s += "A";
    if (s == S) {
      cout << true << endl;
      return;
    }
  }
  cout << false << endl;
}

int main() {
  locale loc(locale(), new yes_no);
  cout << boolalpha << setprecision(12) << fixed;
  cout.imbue(loc);
	string S;
	cin >> S;
	solve(S);
	return 0;
}


Measured memory_bytes: 764
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> pl;
typedef vector<pl> vp;
#define fore(i,a,b) for(ll i=(ll)(a);i<=(ll)(b);++i)
#define rep(i,n) fore(i,0,(n)-1)
#define rfore(i,a,b) for(ll i=(ll)(b);i>=(ll)(a);--i)
#define rrep(i,n) rfore(i,0,(n)-1)
#define all(x) (x).begin(),(x).end()
const ll INF=1001001001;
const ll LINF=1001001001001001001;
const ll D4[]={0,1,0,-1,0};
const ll D8[]={0,1,1,0,-1,-1,1,-1,0};
template<class T>
bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>
bool chmin(T &a,const T &b){if(b<a){a=b;return 1;}return 0;}

void solve(){
    ll n;cin>>n;
    vvl a(n,vl(n));
    rep(i,n)rep(j,n)cin>>a[i][j];

    vector<vector<bool>> ok(n,vector<bool>(n));
    rep(i,n)rep(j,n)rep(k,n){
        if(i==j||i==k)continue;
        if(a[j][k]==a[j][i]+a[i][k])ok[j][k]=1;
        if(a[j][k]>a[j][i]+a[i][k]){
            cout<<-1<<endl;
            return;
        }
    }
    ll ans=0;
    rep(i,n)fore(j,i+1,n-1){
        if(!ok[i][j])ans+=a[i][j];
    }
    cout<<ans<<endl;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    solve();
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<(int)(n); i++)
#define all(v) v.begin(), v.end()
#define PRINT(v) for (auto x : (v)) cout <<x <<" " ; cout <<endl;
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using mat = vector<vector<ll>>;
const ll MOD = 1000000007;
const ll INF = 10000000000000000;
const int inf = 1001001001;
vector<int> x4 = {0, 1, 0, -1}, x8 = {0, 1, 1, 1, 0, -1, -1, -1};
vector<int> y4 = {1, 0, -1, 0}, y8 = {1, 1, 0, -1, -1, -1, 0, 1};
template<class T> inline bool chmin(T& a, T b){if (a>b){a = b; return true;}return false;}
template<class T> inline bool chmax(T& a, T b){if (a<b){a = b; return true;}return false;}
template<class T> inline T powerM(T a,T b){if (b==0) return 1;
T tmp = powerM(a,b/2); if (b%2==0) return tmp*tmp%MOD; else return tmp*tmp%MOD*a%MOD; }
template<class T> inline T power(T a,T b,T m){ if (b==0) return 1;
  T tmp = power(a,b/2,m); if (b%2==0) return tmp*tmp%m; else return tmp*tmp%m*a%m; }
template<class T> inline T gcd(T a, T b){if (b==0) return a; return gcd(b, a%b);}
template<class T> inline T lcm(T a, T b){return a / gcd(a,b) * b;}
// ax+by=gcd(a,b)を解く
template<class T> inline T extgcd(T a,T b,T &x,T &y){if (b==0){x=1; y=0; return a;} T d=extgcd(b,a%b,y,x); y -= a/b*x; return d;}
void hey(){ cout <<"hey" <<endl; }

template<class T> struct edge { int to; T cost;};


int main() {
  int N,W; cin >>N >>W;
  vector<int> w(N);
  vector<ll> v(N);
  rep(i, N) cin >>w[i] >>v[i];
  vector<vector<ll>> dp(N+1, vector<ll>(W+1, 0));
  for (int i=0; i<N; i++){
    for (int j=0; j<=W; j++){
      chmax(dp[i+1][j], dp[i][j]);
      if (j+w[i] <= W) chmax(dp[i+1][j+w[i]], dp[i][j] + v[i]);
    }
  }
  ll res = 0;
  for (int j=0; j<=W; j++) chmax(res, dp[N][j]);
  cout <<res <<endl;
}


Measured memory_bytes: 80256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i=0;i < (int)(n);i++)
const ll INF = 1LL << 55;

ll d[101][101];

bool can[101];

int main(){
    int V,E;
    cin >> V >> E;
    rep(i,V){
        rep(j,V){
            if(i == j) d[i][j] = 0;
            else d[i][j] = INF;
        }
    }

    rep(i,E){
        int a,b;
        ll cost;
        cin >> a >> b >> cost;
        d[a][b] = cost; 
    }
    for (int i= 0;i < V;i++){
        for (int j = 0; j < V;j++){
            for (int k = 0; k < V;k++){
                d[j][k] = min(d[j][k],d[j][i]+d[i][k]);
            }
        }
    }

    for (int i= 0;i < V;i++){
        for (int j = 0; j < V;j++){
            for (int k = 0; k < V;k++){
                if (d[j][k] > d[j][i]+d[i][k]){
                    can[k] = true;
                    cout << "NEGATIVE CYCLE" << endl;
                    return 0;
                }
            }   
        }
    }

    rep(i,V){
        rep(j,V){
            if (0 < j) cout << " ";
            if (d[i][j] >= INF/2) cout << "INF";
            else cout << d[i][j];
        }
        cout << endl;
    }

    return 0;
}




Measured memory_bytes: 3172
#include <stdio.h>
#include <iostream>
using namespace std;

int main()
{
	int N;
	cin >> N;
	char s[200005];
	cin >> s;
	long long a = 1;
	int nest = 0;
	int i;
	for (i = 0; i < 2 * N; i++)
	{
		int x = i%2 ? -1 : 1;
		x *= s[i] == 'B' ? 1 : -1;
		if (x == -1)
		{
			a *= nest;
			a %= 1000000007;
		}
		nest += x;
		if (nest < 0)
		{
			cout << 0 << endl;
			return 0;
		}
	}
	if (nest)
	{
		cout << 0 << endl;
		return 0;
	}
	for (i = 1; i <= N; i++)
	{
		a *= i;
		a %= 1000000007;
	}
	cout << a << endl;
	return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
typedef pair<double,double> P;
typedef pair<int,int> PP;

double D(P a,P b) {
  return sqrt((a.F-b.F)*(a.F-b.F)+(a.S-b.S)*(a.S-b.S));
}

int p[222222],r[222222];
void init(){for(int i=0; i<222222; i++) p[i]=i,r[i]=0;}
int find(int x){return (p[x]==x)?x:(p[x]=find(p[x]));}
void unite(int x,int y) {
  x=find(x),y=find(y);
  if(x==y)return;
  if(r[x]<r[y])p[x]=y;
  else{p[y]=x;if(r[x]==r[y])r[x]++;}
}

int main() {
  init();
  int n;
  double d;
  cin >> n >> d;
  P a[n];
  for(int i=0; i<n; i++) cin >> a[i].F >> a[i].S;
  map<PP,int> m;
  for(int i=0; i<n; i++) {
    int x=floor(a[i].F/d),y=floor(a[i].S/d);
    for(int dx=-1; dx<2; dx++) {
      for(int dy=-1; dy<2; dy++) {
        if(m.count(PP(x+dx,y+dy))) unite(i,m[PP(x+dx,y+dy)]);
      }
    }
    m[PP(x,y)]=i;
  }
  set<int> s;
  for(int i=0; i<n; i++) s.insert(find(i));
  cout << s.size() << endl;
  return 0;
}

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

using namespace std;

int main() {
    int n, m;
    cin>>n>>m;
    map<int, int> penatly;
    set<int> qno;
    int tp = 0, tac = 0;
    while(m--) {
        int q;
        string status;
        cin>>q>>status;
        if(status == "AC") {
            qno.insert(q);
        } else if(!qno.count(q)){
            penatly[q]++;
        }
    }
    for(auto i: penatly) {
        if(qno.count(i.first)) {
            tp += i.second;
        }
    }
    
    cout<<qno.size()<<" "<<tp;
    return 0;
}

Measured memory_bytes: 4992
// ICPC 得点集計ソフトウェア
// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=1147&lang=jp
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
)

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)

	for	{
		n := nextInt(sc)
		if n == 0 { break }

		score_list := []int{}
		for i := 0; i < n; i++ {
			score_list = append(score_list, nextInt(sc))
		}

		// 最低点と最高点を取り除く (3 ≤ n ≤ 100)
		sort.Sort(sort.IntSlice(score_list))
		score_list = score_list[1:len(score_list)-1]

		// 平均点を求める
		sum := 0
		for _, score := range score_list {
			sum += score
		}
		fmt.Println(sum / len(score_list))
	}
}

func nextInt(sc *bufio.Scanner) int {
	sc.Scan()
	i, err := strconv.Atoi(sc.Text())
	if err != nil {
		panic(err)
	}
	return i
}



Measured memory_bytes: 1128
def main():
    s = str(input())

    ans = []
    for val in s :
        if val == "B" and ans == [] :
            pass
        elif val == "B" and ans != [] :
            ans.pop(-1)
        else :
            ans.append(val)

    ans_str = ""
    for val in ans :
        ans_str = ans_str + val

    print(ans_str)



if __name__ == '__main__':
    main()


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

using namespace std;
typedef long long ll;
typedef unsigned long long ull;

ull S(ull i) {
    ull res = 0;
    while (i) {
        res += i % 10;
        i /= 10;
    }
    return res;
}

int main() {
    ull k;
    cin >> k;
    ull base = 1;
    ull begin = 1;
    for (ull i = 0; i < k; ++i) {
        cout << begin << endl;
        if (1.0 * (begin + base) / S(begin + base) > 1.0 * (begin + 2 * base) / S(begin + 2 * base)) {
            base *= 10;
        }
        begin += base;
    }
    return 0;
}

static int speedUp = []() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    return 0;
}();

Measured memory_bytes: 256
//
//  main.cpp
//  A - Ball Distribution
//
//  Created by Hashizo on 2019/06/15.
//  Copyright © 2019 Hashizo. All rights reserved.
//

#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <regex>

using namespace std;

#undef INT_MAX
#undef INT_MIN

#define INT_MAX	2147483647
#define INT_MIN	(-INT_MAX  -1)

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())
#define REPLACE(s, f, t) regex_replace(s, regex(f), t)

int main(int argc, const char * argv[]) {
	int n,k;
	cin >> n >> k;

	if (k == 1) {
		cout << 0 << endl;
	}
	else {
		cout << n - k << endl;
	}
	return 0;
}


Measured memory_bytes: 256
const input=require('fs').readFileSync('/dev/stdin', 'utf8').split(/[\s]/);const nin=()=>{const r = input[0];input.shift();return Number(r)};const nrin=(n)=>{const a:number[]=[];rep(n,()=>a.push(nin()));return a};const sin=()=>{const r = input[0];input.shift();return String(r)};const out=(...a)=>{console.log(...a)};const floor=(a)=>{return Math.floor(a)};const abs=(a)=>{return Math.abs(a)};const min=(...a)=>{return Math.min(...a)};const max=(...a)=>{return Math.max(...a)};const rep=(n, callback)=>{for(let i = 0;i < n; i++){callback()}};const strrep=(s, i, v)=>{return s.slice(0, i)+v+s.slice(i+1);};const permutation=({result=[],pre=[],post,n=post.length})=>{if(n>0){post.forEach((_,i)=>{const rest=[...post];const elem=rest.splice(i, 1);permutation({result, pre: [...pre,...elem],post:rest,n:n-1})})}else{result.push(pre)}return result}

const main = ()=>{
  let[a,b]=nrin(2);
  b%a==0?out(a+b):out(b-a);
}
main();

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



int main(){
    int a,b;
    cin >> a >> b;
    int ans[3]={1,2,3};

    rep(i,3){
        if(ans[i]!=a&&ans[i]!=b){
            cout << ans[i]<<endl;
            return 0;
        }
    }

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <map>
#include <string>
using namespace std;
int main(){
    int n,m;
    map <long long,int> ab;
    cin >> n >> m;
    vector<long long> a;
    long long q;
    int p;
    for(int i = 0;i<n;i++){
        cin >> q >> p;
        auto itr = ab.find(q);
        if(itr != ab.end()){
            ab[q] = ab[q] + p;
        }
        else{
            ab[q] = p;
            a.push_back(q);
        }
    }
    sort(a.begin(),a.end());
    long long ans = 0;
    int j = 0;
    while(m > 0){
        if(m > ab[a[j]]){
            ans = ans + a[j]*ab[a[j]];
            m = m - ab[a[j]];
        }
        else{
            ans = ans + a[j]*m;
            m = 0;
        }
        j++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 7284
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <vector>
#include <iostream>
#include <set>
#include <map>
using namespace std;
typedef long long ll;

string S;

int main(int argc, char const *argv[]) {
	cin >> S;
	int size = S.size();
	string s(size, '0');
	for (int i = 0; i < size; i++) s[i] = S[size-i-1];

	while (s.size()) {
		if (s.substr(0, 5) == "maerd" || s.substr(0, 5) == "esare") s = s.substr(5);
		else if (s.substr(0, 6) == "resare") s = s.substr(6);
		else if (s.substr(0, 7) == "remaerd") s = s.substr(7);
		else {
			cout << "NO" << endl;
			return 0;
		}
	}
	cout << "YES" << endl;

	return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
#define mod 1000000007
#define first f
#define second s
#define N 1000000
vector<ll>v(N);
ll l,m,n,sum,ans,maximum,minimum,mahakal,a,b,c,t,i,j,k;
ll cnt,cnt1,cnt2,cnt3;
string str,str1;
ll arr[N];
int main(){
    cin>>n;
  cout<<n*n<<endl;
    return 0;
}

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

#ifdef LOCAL
#define debug(var) cerr << (#var) << " = " << (var) << endl;
#else
#define debug(var)
#endif

void init() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
}

long long nCr(long long n, long long r) {
  if (n < r) return 0;
  long long ret = 1;
  for (int i = n-r+1; i <= n; ++i)
    ret *= i;
  for (int i = 2; i <= r; ++i)
    ret /= i;
  return ret;
}

void solve() {
  string n; cin >> n;
  vector<int> nz;
  for (int i = 0; i < (int)n.size(); ++i) {
    if (n[i] == '0') continue;
    nz.push_back(i);
  }
  int k; cin >> k;
  if (k > n.size()) {
    puts("0");
    return;
  }
  long long ans = nCr(n.size()-1, k)*pow(9, k);
  for (int i = 1; i <= k && i <= n.size(); ++i) {
    if (i > nz.size()) break;
    int ind = nz[i-1];
    long long cur = n[ind]-'0'-1;
    cur *= nCr(n.size()-ind-1, k-i)*pow(9, k-i);
    debug(cur);
    debug(n.size()-ind-1);
    ans += cur;
    if (k-i == 0) {
      ++ans;
      continue;
    }
    if (i+1 > nz.size()) continue;
    ans += nCr(n.size()-nz[i]-1, k-i)*pow(9, k-i);
  }
  cout << ans;
}

int main() {
  init();
  int t = 1; //scanf("%d", &t);
  while (t--) {
    solve();
  }
  return 0;
}


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

int main() {
  int d,a;

  while(cin>>d){
    a=1;
    for(;a<=d;a=a<<1) {
      if(a&d) {
	cout<<a;
	if(d/a>2) cout<<" ";
      }
    }
    cout<<endl;

    /*
    a=1;
    for(;d>0;) {
      if(d%2==1) {
	cout<<a;
	d--;
	if(d>0) cout<<" ";
      }
      d/=2;
      a*=2;
    }
    cout<<endl;
    */
  }

}

Measured memory_bytes: 0
import sys
from fractions import gcd


def eratosthenes_generator():
    yield 2
    n = 3
    h = {}
    while True:
        m = n
        if n in h:
            b = h[n]
            del h[n]
        else:
            b = n
            yield n
        m += b << 1
        while m in h:
            m += b << 1
        h[m] = b
        n += 2


def prime(n):
    ret = []
    if n % 2 == 0:
        ret.append(2)
        while n % 2 == 0:
            n >>= 1
    for i in range(3, int(n ** 0.5) + 1, 2):
        if n % i == 0:
            ret.append(i)
            while n % i == 0:
                n = n // i
        if n == 1:
            break
    if n > 1:
        ret.append(n)
    return ret


def solve(n, aaa):
    g = abs(aaa[-1])
    for a in aaa[:-1]:
        if a != 0:
            g = gcd(g, abs(a))
    ans = set(prime(g))

    for p in eratosthenes_generator():
        if p > n + 2:
            break
        if p in ans or aaa[0] % p != 0:
            continue
        q = p - 1
        tmp = [0] * q
        for i, a in enumerate(aaa):
            tmp[i % q] += a
        if all(t % p == 0 for t in tmp):
            ans.add(p)

    ans = sorted(ans)
    return ans


n = int(input())
aaa = list(map(int, sys.stdin))
aaa.reverse()
print('\n'.join(map(str, solve(n, aaa))))


Measured memory_bytes: 6156
#include <bits/stdc++.h>
typedef long long LL;
#define SORT(c) sort((c).begin(),(c).end())

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

using namespace std;
int main(void)
{
  for(;;){
    int n,l;
    cin >> n >> l;
    if(!n&&!l) return 0;
    int ant[128][2];
    // pos,(l=0,r=1);
    REP(i,128) REP(j,2) ant[i][j]=0;
    REP(i,n){
      string lr;
      int pos;
      cin >> lr >> pos;
      if(lr=="L") ant[pos][0]=i+1;
      else ant[pos][1]=i+1;
    }
    int anst,ansi;
    REP(time,128){
      if(ant[l][1]){
	anst=time;
	ansi=ant[l][1];
      }
      if(ant[0][0]){
	anst=time;
	ansi=ant[0][0];
      }
      for(int i=0;i<l;i++) ant[i][0]=ant[i+1][0];
      for(int i=l;i>0;i--) ant[i][1]=ant[i-1][1];
      ant[l][0]=0;
      ant[0][1]=0;
      REP(i,l) if(ant[i][0]&&ant[i][1]){
	int a,b;
	a=ant[i][0];
	b=ant[i][1];
	ant[i][0]=b;
	ant[i][1]=a;
      }
    }
    cout << anst << ' ' << ansi << endl;
  }
}

Measured memory_bytes: 1208
package main

import (
	"bufio"
	"fmt"
	"os"
)

const Inf = 1 << 62

func main() {
	H, W, K := ReadInt(), ReadInt(), ReadInt()
	S := make([]string, H)
	for i := 0; i < H; i++ {
		S[i] = ReadString()
	}
	id := make([]int, H)
	ans := Inf
	for i := 0; i < 1<<(H-1); i++ {
		g := 0
		for h := 0; h < H; h++ {
			id[h] = g
			if i>>h&1 == 1 {
				g++
			}
		}
		g++
		cut := g - 1
		groups := make([]int, g)
		for w := 0; w < W; w++ {
			over := false
			now := make([]int, g)
			for h := 0; h < H; h++ {
				if S[h][w] == '1' {
					groups[id[h]]++
					now[id[h]]++
					if now[id[h]] > K {
						cut = Inf
					}
					if groups[id[h]] > K {
						over = true
					}
				}
			}
			if over {
				groups = now
				cut++
			}
		}
		if ans > cut {
			ans = cut
		}
	}
	fmt.Println(ans)
}

var reader = bufio.NewReader(os.Stdin)

func Scan(a ...interface{}) {
	if _, err := fmt.Fscan(reader, a...); err != nil {
		panic(err)
	}
}
func ReadInt() (i int)       { Scan(&i); return }
func ReadString() (s string) { Scan(&s); return }


Measured memory_bytes: 6456
n=int(input())
a=[int(i) for i in input().split()]
e=0
s=0
for i in range(1,len(a)):
    if(a[i]>=a[i-1]):
        pass
    else:
        e=abs(a[i]-a[i-1])
        s=s+e
        a[i]=a[i]+e
print(s)

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

int solve(vector<int> v,int t){
int n=v.size();
int cost[n];
cost[0]=0;
cost[1]=cost[0]+abs(v[1]-v[0]);
for(int i=2;i<n;i++){
    cost[i]=INT_MAX;
    for(int k=1;k<=t;k++){
    if((i-k)>=0)
    cost[i]=min(cost[i],cost[i-k]+abs(v[i]-v[i-k]));}
}
return cost[n-1];
}
int main() {
   int n,t;
   cin>>n>>t;
   vector<int> v;
   while(n--){
       int k;
       cin>>k;
       v.push_back(k);
   }
   cout<<solve(v,t)<<endl;
   return 0;
}

Measured memory_bytes: 4580
a,b=map(int,input().split())
A=[1]
for i in range(2,int(a**0.5)+1):
    if a%i==0:
        while a%i==0:
            a//=i
        A.append(i)
if a>1:
    A.append(a)
B=[1]
for i in range(2,int(b**0.5)+1):
    if b%i==0:
        while b%i==0:
            b//=i
        B.append(i)
if b>1:
    B.append(b)
can=0
for i in A:
    if i in B:
        can+=1
print(can)

Measured memory_bytes: 9468
/* package codechef; // don't place package name! */

import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
class Main
{
    static long solve(long arr[][],int k,int n){
        
        
        long t[][]=new long[n+1][k+1];
        
        for(int i=1;i<=3;i++){
            t[1][i]=arr[0][i-1];
        }
        
        for(int i=2;i<=n;i++){
            for(int j=1;j<=k;j++){
                if(j==1){
                t[i][j]=arr[i-1][j-1]+Math.max(t[i-1][2],t[i-1][3]);
            }
            
            
            else if(j==2){
                 t[i][j]=arr[i-1][j-1]+Math.max(t[i-1][1],t[i-1][3]);
            }
            
            else{
                
                 t[i][j]=arr[i-1][j-1]+Math.max(t[i-1][2],t[i-1][1]);
            }
            }
        }
        long max=0;
        for(int i=1;i<=3;i++){
            max=Math.max(max,t[n][i]);
        }
        
          return max;     
        }
        
  
    
    
    
	public static void main (String[] args) throws java.lang.Exception
	{
	
	Scanner s=new Scanner(System.in);
	int n=s.nextInt();
	long arr[][]=new long[n][3];
	
	for(int i=0;i<n;i++){
	    for(int j=0;j<3;j++){
	        arr[i][j]=s.nextLong();
	    }
	}
	
	
System.out.println(	solve(arr,3,n));
	
	}
}


Measured memory_bytes: 103368
#include<bits/stdc++.h>
/*
g++ -std=c++11 -Wall -g -fsanitize=undefined -D_GLIBCXX_DEBUG abc/abc064/c.cpp
*/
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define SZ(x) ((int)(x).size())
#define INF (1e16)
typedef long long ll;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);//おまじないでcin, cout早くする
    int N;
    cin >> N;
    int color[10];// 1: gray, 2: b, ... 8 : red, 9: free
    for(int i = 1; i <= 9; i++){
        color[i] = 0;
    }
    rep(i, N){
        int a;
        int flag = 0;
        cin >> a;
        for(int i = 1; i <= 8; i++){
            if(a < i * 400){
                color[i]++;
                flag = 1;
                break;
            }
        }
        if(flag == 0){
            color[9]++;
        }
    }
    int ans_min = 0;
    int ans_max = 0;
    for(int i = 1; i <= 8; i++){
        if(color[i] != 0){
            ans_max++;
            ans_min++;
        }
    }
    ans_max += color[9];
    if(ans_min == 0){
        ans_min = 1;
    }
    cout << ans_min << " " << ans_max << "\n";
    return 0;
}

Measured memory_bytes: 256
/* Author rumoisen */
/* created 2018/10/18 */

#include <algorithm>
#include <vector>
#include <map>
#include <string>
#include <cmath>
#include <iomanip>
#include <numeric>
#include <iostream>

using namespace std;
 
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())
#define INF (ll)1e18
#define MOD (ll)1e9 + 7
#define pb push_back

typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> V;
typedef map<int, int> M;

void no(){cout<<"No"<<endl;exit(0);}
void yes(){cout<<"Yes"<<endl;exit(0);}
void No(){cout<<"NO"<<endl;exit(0);}
void Yes(){cout<<"YES"<<endl;exit(0);}

using namespace std;

int main(void)
{
    string s;
    cin>>s;
    s[5]=' ';
    s[13]=' ';
    cout<<s<<endl;
    return 0;
}

Measured memory_bytes: 256
package main

import (
   "bufio"
   "fmt"
   "os"
)

func solution(n, m, k int, a, b []int) int {
   cumA := make([]int, n+1)
   cumB := make([]int, m+1)

   for i := range a {
        cumA[i+1] = cumA[i] + a[i]
   }
   for i := range b {
        cumB[i+1] = cumB[i] + b[i]
   }

   out, j := 0, m

   for i := range cumA {
        if cumA[i] > k {
                break
        }
        for cumB[j] > k-cumA[i] {
                j--
        }
        out = max(out, i+j)
   }
   return out
}

func max(x, y int) int {
   if x > y {
        return x
   }
   return y
}

func main() {
   r := bufio.NewReader(os.Stdin)
   var n, m, k int
   fmt.Fscan(r, &n, &m, &k)
   a := make([]int, n)
   for i := range a {
        fmt.Fscan(r, &a[i])
   }
   b := make([]int, m)
   for i := range b {
        fmt.Fscan(r, &b[i])
   }
   fmt.Println(solution(n, m, k, a, b))
}

Measured memory_bytes: 11196
#include<bits/stdc++.h>
#define $$ long long int
#define pb push_back
#define db pop_back
#define q2(n) (n%2)==0
#define vp vector<pair <$$,$$> >
#define vctr vector<$$>
#define in(a) cin>>a;
#define out(a) cout<<a<<"\n";
#define nxt() cout<<"\n";
#define no() cout<<"No\n";
#define yes() cout<<"Yes\n";
#define bug1() cout<<"@ ";
#define bug2() cout<<"# ";
#define ff first
#define ss second
#define ip(n) $$ n; cin>>n;
#define ipar(ar,n) $$ ar[n]; loop(i,0,n) cin>>ar[i];
#define opar(ar,n) loop(i,0,n) cout<<ar[i]<<" ";
#define loop(i,m,p) for ($$ i = m; i < p; i++)
#define loopn(i,m,p) for ($$ i = p-1; i >=m; --i)

using namespace std;

int main()
{
   ip(n) ip(m)
         ipar(a,n)
         $$ sum=0;
         loop(i,0,n) sum+=a[i];
            sort(a,a+n);
            $$ rq=sum/(4*m);
            if((sum%(4*m))==0)
            {
             if(a[n-m]>=rq) yes()
             else
             no()
            }
            else
            {
             if(a[n-m]>rq) yes()
             else
             no()
            }








return 0;
}




Measured memory_bytes: 256
N = int(input())

W = list(map(int,input().split()))
W_sum = []

summon = sum(W)
mini = -1

now_sum = 0

for i in range(N):
    now_sum += W[i]

    if (mini < 0):
        mini = abs(summon - 2 * now_sum)

    elif (mini > abs(summon - 2 * now_sum)):
        mini = abs(summon - 2 * now_sum)


print (mini)

Measured memory_bytes: 3064
n = gets.to_i
l = gets.split.map(&:to_i)

sum = 0
if n < 3
  sum = 0
elsif n>= 3
  (n-2).times {|i|
    (n-i-2).times{|j|
      (n-i-j-2).times{|k|
        if l[i] == l[i+j+1] || l[i] == l[i+j+k+2] || l[i+j+1] == l[i+j+k+2]
          sum += 0
        elsif l[i] + l[i+j+1] > l[i+j+k+2] && l[i] + l[i+j+k+2] > l[i+j+1] && l[i+j+1] + l[i+j+k+2] > l[i]
          sum += 1
        else sum += 0
        end
        }
      }
    }
end
  
p sum

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

for x in range(1, 3501):
    for y in range(1, 3501):
        tmp1 = n*x*y
        tmp2 = 4*x*y - n*x - n*y
        if tmp2 > 0 and int(tmp1/tmp2) == tmp1/tmp2: 
            print(x, y, int(tmp1/tmp2))
            exit()

Measured memory_bytes: 42332
from collections import deque

n, m = map(int, input().split())
ad_list = [[] for i in range(n)]
for _ in range(m):
    i, j = map(int, input().split())
    ad_list[i - 1].append(j - 1)
    ad_list[j - 1].append(i - 1)


def bfs(node, ad_list):
    visited = [-1] * node
    queue = deque()
    count = 0
    for i in range(node):
        if visited[i] == 0: continue
        queue.append(i)
        visited[i] = 0
        while queue:
            n = queue.popleft()
            for ad in ad_list[n]:
                if visited[ad] == -1:
                    visited[ad] = 0
                    queue.append(ad)
        count += 1
    return count

ans = bfs(n, ad_list) - 1
print(ans)

Measured memory_bytes: 26536
#2020-03-19
cards = [['no' for i in range(13)] for j in range(4)]
pattern = ["S", "H", "C", "D"]

n =  int(input())
num = 0
for t in range(n):
    mark,number = input().split()
    if mark == 'S':
        num = 0
    elif mark == 'H':
        num = 1
    elif mark == 'C':
        num = 2
    elif mark == 'D':
        num = 3

    cards[num][int(number) - 1] = 'yes'

    
    
for j in range(4):    
    for i in range(13):
        if cards[j][i] == 'no':
            print(pattern[j], i+1)


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

using namespace std;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    long long n, k;
    cin >> n >> k;
    long long x = n % k;
    long long y = abs(x - k);
    if (y < x) {
        cout << y;
    } else {
        cout << x;
    }
}


Measured memory_bytes: 3640
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int n = Integer.parseInt(sc.nextLine());
		for(int i = 0; i < n; i++) {
			String s = sc.nextLine();
			String[] sp = s.split("\\s+");
			
			int sum = num(sp[0]) + num(sp[1]);
			System.out.println(str(sum));
		}
		
	}
	
	public static int num(String s) {
		int pos = 0, sum = 0;
		
		while(pos < s.length()) {
			int multi = 0;
			switch(s.charAt(pos)) {
			case 'm': sum += 1000; pos++; break;
			case 'c': sum += 100; pos++; break;
			case 'x': sum += 10; pos++; break;
			case 'i': sum += 1; pos++; break;
			default:
				multi = s.charAt(pos++) - '0';
				if(pos < s.length()) {
					switch(s.charAt(pos++)) {
					case 'm': multi *= 1000; sum += multi; break;
					case 'c': multi *= 100; sum += multi; break;
					case 'x': multi *= 10; sum += multi; break;
					case 'i': sum += multi; break;
					default: sum += multi; break;
					}
				}
				break;
			}
		}
		
		return sum;
	}

	public static String str(int num) {
		String s = "";

		int m = num / 1000;
		if(m > 0) {
			if(m == 1) {
				s += 'm';
			}else {
				s += Integer.toString(m) + 'm';
			}
		}
		int c = (num % 1000) / 100;
		if(c > 0) {
			if(c == 1) {
				s += 'c';
			} else {
				s += Integer.toString(c) + 'c';
			}
		}
		int x = (num % 1000) % 100 / 10;
		if(x > 0) {
			if(x == 1) {
				s += 'x';
			}else {
				s += Integer.toString(x) + 'x';
			}
		}
		int i = (num % 1000) % 100 % 10 / 1;
		if(i > 0) {
			if(i == 1) {
				s += 'i';
			}else {
				s += Integer.toString(i) + 'i';
			}
		}
		
		return s;
	}
	
}



Measured memory_bytes: 45200
import sys


def main():

    # Get Args
    args = _input_args()  # get arguments as an array from console/script parameters.

    # Call main Logic
    result = _main(args)

    # Output a result in a correct way.
    _output_result(result)


def _main(args):
    """Write Main Logic here for the contest.

    :param args: arguments
    :type args: list
    :return: result
    :rtype: depends on your logic.
    """
    # Extract arguments.
    N = int(args[0])
    K = int(args[1])

    # Write main logic here.
    now = 1
    for i in range(N):
        if now < K:
            now = now * 2
        else:
            now = now + K

    # Return something.
    return now


def _input_args():
    # Comment-out appropriate pattern depends on subject.

    # arguments = sys.argv[1:]  # ptn1: get args from script parameters.
    # arguments = _input().split()  # ptn2: get args from 1 line console prompt with space separated.

    # for multi-line console input, use this.
    arguments = _get_args_from_multiple_lines(end_of_lines_char=[''], limit=2)

    # Cast elements If you need.
    # arguments = list(map(int, arguments))  # cast elements to int for example.

    return arguments  # This will be array.


def _input():
    # If Subject requires interactive input, use this and patch mock in unittest.
    return input()  # Change if necessary.


def _get_args_from_multiple_lines(end_of_lines_char=[''], limit=2):
    """Get arguments from multiple lines standard input.

    :param end_of_lines_char: Strings that indicate the end of lines.
    :type end_of_lines_char: list of str
    :param limit: If a number of the input line are certain, you can use this param to close prompt immediately.
    :type limit: int
    :return: args
    :rtype list of str
    """
    args = []
    for i in range(limit):
        try:
            arg = _input()
            if arg in end_of_lines_char:
                break
            args.append(arg)
        except EOFError:  # Supports EOF Style. (Very Rare case)
            break
    return args


def _output_result(result):
    # Comment-out appropriate output pattern depends on subject.

    # sys.stdout.write(result)  # No Line Feed, and an result must be string (not useful). for single value output.
    print(result)  # The result will cast to strings. Line feed will be appended to the end. for single value output.
    # print(result, end='')  # Same as above except Line Feed won't be appended. for single value output.
    # print(','.join(map(str, result)))  # Print array elements as comma separated strings. for multi-value.
    # print('ans={}'.format(str(result)))  # Same as above, but more versatile.


if __name__ == '__main__':
    main()


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

struct info {
  int x;
  int y;
  int h;
};
bool cmp_info(const info &i1, const info &i2) { return i1.h > i2.h; }

int main() {
  int n;
  cin >> n;
  info in[n];
  for ( int i = 0; i < n; i++ ) {
    cin >> in[i].x >> in[i].y >> in[i].h;
  }
  sort(in, in+n, cmp_info);

  int X, Y, H = -1;
  bool f = false;
  for ( X = 0; X <= 100; X++ ) {
    for ( Y = 0; Y <= 100; Y++ ) {
      H = abs(X-in[0].x) + abs(Y-in[0].y) + in[0].h;
      for ( int i = 1; i < n; i++ ) {
        if ( in[i].h != max(H - abs(X-in[i].x) - abs(Y-in[i].y), 0) ) {
          H = -1;
          break;
        }
      }
      if ( H != -1 ) { f = true; break; }
    }
    if ( f ) { break; }
  }

  cout << X << ' ' << Y << ' ' << H << endl;
  return 0;
}


Measured memory_bytes: 256
use proconio::input;
use proconio::marker::Chars;
use std::cmp::{max, min};
const alpha: [char; 26] = [
    'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's',
    't', 'u', 'v', 'w', 'x', 'y', 'z',
];

const Alpha: [char; 26] = [
    'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S',
    'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
];
fn main() {
    input!(s: Chars);
    input!(t: Chars);
    let mut ans: usize = 0;
    for i in 0..s.len() {
        if s[i] != t[i] {
            ans += 1;
        }
    }

    println!("{}", ans);
}


Measured memory_bytes: 3928
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<sstream>
#include<unordered_map>
#include<unordered_set>
#include<vector>
using namespace std;
using uint = unsigned int;
using ll = long long;
const int M = 1e9 + 7;
const ll MLL = 1e18L + 9;
#pragma unused(M)
#pragma unused(MLL)
#ifdef LOCAL
#include"rprint.hpp"
#else
template <ostream& out = cout, class... T> void prints(T&&...){ }
template <ostream& out = cout, class... T> void printd(T&&...){ }
template <ostream& out = cout, class... T> void printb(T&&...){ }
template <ostream& out = cout, class... T> void printArr(T&&...){ }
#endif

int main(){
    ll n, a, b, c, d;
    cin >> n >> a >> b >> c >> d;
    for(int i = 0; i <= n - 1; i++){
        ll p = a + c * (n - 1) - 2 * c * i;
        if(p - i * (d - c) <= b && b <= p + (n - 1 - i) * (d - c)){
            printd(i, p, b);
            cout << "YES" << '\n';
            return 0;
        }
    }
    cout << "NO" << '\n';
    // bool odd = n & 1;
    // ll mini = MLL;
    // for(int i = 0; i < (n - 1) / 2; i++){
    //     if(odd){
    //         mini = min(mini, abs(b - (a + c * 2 * i)));
    //     }else{
    //         mini = min(mini, abs(b - (a + c * (2 * i + 1))));
    //     }
    // }
    return 0;
}


Measured memory_bytes: 256
#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>;
using vecveci = vector<vector<int>>;
using vecvecl = vector<vector<long long>>;

int main() {
    int N;
    cin >> N;
    vecl A(N);
    REP(i,N) cin >> A[i];
    vecl ans(N);
    REP(i,N) {
        if(i%2 == 0) ans[0] += A[i];
        else ans[0] -= A[i];
    }
    REP(i,N-1) {
        ans[i+1] = 2*(A[i] - ans[i]/2);
    }
    REP(i,N) cout << ans[i] << " ";
    cout << endl;
}


Measured memory_bytes: 2944
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;
public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		String a = sc.next();
		int count = 0;
		int flag = 0;
		ArrayList<Integer> array = new ArrayList<Integer>();
		String[] param = a.split("");
		for (int i = 0; i < a.length(); i++) {
			if (param[i].equals("A")) {
				flag = i;
				break;
			}
		}
		for (int j = flag; j < a.length(); j++) {
			count++;
			if (param[j].equals("Z")) {
				array.add(count);
			}
		}
		Collections.sort(array);
		Collections.reverse(array);
		System.out.println(array.get(0));
	}
}

Measured memory_bytes: 51988
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

use itertools::Itertools;

fn main() {
    input! {
        n: i32,
        l_vec: [i32; n]
    }

    let it = (0..n).combinations(3);
    let mut num_patterns = 0;
    for pattern in it {
        let mut l_pattern = vec![
            l_vec[pattern[0] as usize],
            l_vec[pattern[1] as usize],
            l_vec[pattern[2] as usize],
        ];
        l_pattern.sort();
        let first = l_pattern[0];
        let second = l_pattern[1];
        let third = l_pattern[2];
        let is_all_diff = first != second && first != third && second != third;
        let is_triangle = first + second > third;
        if is_all_diff && is_triangle {
            num_patterns += 1;
        }
    }
    println!("{}", num_patterns);
}


Measured memory_bytes: 2168