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

#define fast                     ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll                       long long 
#define mk                       make_pair
#define pb                       push_back
#define pob                      pop_back
#define pii                      pair<int,int>
#define vi                       vector<int>
#define vii                      vector<pii>
#define mi                       map<int,int>
#define mii                      map<pii,int>
#define all(a)                   (a).begin(),(a).end()
#define x                        first
#define y                        second
#define sz(x)                    (int)x.size()
#define endl                     '\n'
#define MOD                      1000000007
#define loop(i,a,b)              for(int (i)=(a);(i)<(b);(i)++)
#define rloop(i,a,b)             for(int (i)=(a);(i)>=(b);(i)--)
#define Unique(A)                (A).resize(distance((A).begin(),unique(all((A)))));
#define mxe(A)                   *max_element(all(A))
#define mne(A)                   *min_element(all(A))
#define debv(x)                  for(auto i : (x)) cout << i << ' ';cout << endl;
#define SP(x,y)                  cout << fixed << setprecision((y)) << (x) << endl;
#define setBits(x)               __builtin_popcountll(x)
#define zroBits(x)               __builtin_ctzll(x)
#define trace1(x)                cerr<<#x<<": "<<x<<endl
#define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
#define Max(x,y,z)               max(x,max(y,z))
#define Min(x,y,z)               min(x,min(y,z))
#define clr(x)                   memset(x,0,sizeof(x)) // not sure work for 2D arrya or not

using namespace std;
const int N = 1e7+77;
int A[N],n,dp[N];

int main(){
    cin >> n ; loop(i,0,n) cin >> A[i];
    if(n==1) {cout << 0 << endl;return 0;}
    if(n==2) {cout << abs(A[0]-A[1]) << endl;return 0;}
    
    dp[1]=abs(A[1]-A[0]);
    loop(i,2,n){
        int a = dp[i-1] + abs(A[i-1]-A[i]);
        int b = dp[i-2] + abs(A[i-2]-A[i]);
        dp[i] = min(a,b);
    }
    
    cout << dp[n-1] << endl;
    return 0;
}

Measured memory_bytes: 2688
n,m,x=map(int,input().split())
c=[]
a=[]
for i in range(n):
    A=list(map(int,input().split()))
    C=A.pop(0)
    c.append(C)
    a.append(A)

num=[]
for i in range(2 **n):
  chars = list(f"{i:0{n}b}")
  chars=list(map(int,chars))
  num.append(chars)

ans=100000000000000
for cart in num:
    t=[0]*m
    money=0
    for i in range(len(cart)):
        if cart[i]==1:
            money+=c[i]
            for k in range(m):
                t[k]+=a[i][k]
    if min(t)>=x and money<ans:
        ans=money
if ans==100000000000000:
    print(-1)
else:
    print(ans)

Measured memory_bytes: 9660
#include <algorithm>
#include <climits>
#include <iostream>
#include <string>
#include <utility>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <iomanip>
#include <cmath>

using namespace std;
using ll = long long int;

template <class T> ostream &operator<<(ostream &os, vector<T> &v) {
  for (auto i = v.begin(); i != v.end(); i++) {
    os << *i << " ";
  }
  return os;
}

ll gcd(ll a, ll b) {
  ll tmp;
  if ( b > a) {
    tmp = a;
    a = b;
    b = tmp;
  }
  while (a % b !=0) {
    tmp = b;
    b = a % b;
    a = tmp;
  }
  return b;
}

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



void solve(long long A, long long B){
  std::cout << lcm(A, B) << std::endl;
}

int main(){
  long long A;
  scanf("%lld",&A);
  long long B;
  scanf("%lld",&B);
  solve(A, B);
  return 0;
}



Measured memory_bytes: 256
// abc087_d
#include <bits/stdc++.h>
#ifdef LOCAL
#include "../cxx-prettyprint/prettyprint.hpp"
#endif
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;

#define REP(i, n) for (int (i) = 0 ; (i) < (int)(n) ; ++(i))
#define REPN(i, m, n) for (int (i) = m ; (i) < (int)(n) ; ++(i))
#define REP_REV(i, n) for (int (i) = (int)(n) - 1 ; (i) >= 0 ; --(i))
#define REPN_REV(i, m, n) for (int (i) = (int)(n) - 1 ; (i) >= m ; --(i))
#define ALL(x) x.begin(), x.end()

#define INF (ll)(1e9)
#define MOD (1000000007)

#define print2D(h, w, arr) REP(i, h) { REP(j, w) cout << arr[i][j] << " "; cout << endl; }
#define print_line(vec, n) {for(int i=0;i<(n-1);i++) cout << (vec)[i] << " "; cout << (vec)[(n)-1] << endl;}
template<class T> void print(const T& x){cout << x << endl;}
template<class T, class... A> void print(const T& first, const A&... rest) { cout << first << " "; print(rest...); }
struct PreMain {PreMain(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(20);}} premain;


template< typename T >
struct WeightedUnionFind {
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2
    vector<int> rank;
    vector<int> size; // size[i]: iが親なら連結成分の数
    vector<T> weight; // weight[i]: i -> iの根までの重み

    WeightedUnionFind(int N) : par(N), rank(N, 0), size(N, 1), weight(N) { //最初は全てが根であるとして初期化
        for (int i = 0; i < N; i++) {par[i] = i;}
    }

    int find(int x) { // データxが属する木の根を再帰で得る：find(x) = {xの木の根}
        if (par[x] == x) return x;

        // 親への重みを追加しながら根まで走査
        int rx = find(par[x]);
        weight[x] += weight[par[x]];
        return par[x] = rx;
    }

    bool unite(int x, int y, T w) { // x -> y の重みが w
        int rx = find(x); //xの根をrx
        int ry = find(y); //yの根をry
        if (rx == ry) return false; //xとyの根が同じ(=同じ木にある)時はそのまま

        w = -weight[x] + w + weight[y];

        // rank[rx] <= rank[ry] となるように rx と ry を swap
        if(rank[rx] > rank[ry]) { swap(rx, ry); w *= -1;  }

        // 同じ高さだったならばまとめたことによって高さ +1
        if(rank[rx] == rank[ry]) ++rank[rx];

        // rx -> ryの重みをセット
        weight[rx] = w;

        par[rx] = ry; // root ry に rx の木をつなぐ
        size[ry] += size[rx];
        size[rx] = 0;

        return true;
    }

    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = find(x);
        int ry = find(y);
        return rx == ry;
    }

    int get_size(int x){
        int rx = find(x);
        return size[rx];
    }

    T diff(int x, int y) { // x -> yの重みを返す
        find(x);
        find(y);
        return weight[x] - weight[y];
    }
};

int main() {
#ifdef LOCAL
    ifstream in("../arg.txt"); cin.rdbuf(in.rdbuf());
#endif

    int N, M;
    cin >> N >> M;
    WeightedUnionFind<ll> uf(N);

    REP(i, M){
        int l, r, d;
        cin >> l >> r >> d;
        l--, r--;

        if (uf.same(l, r)){

            if (uf.diff(l, r) != d){
                print("No");
                return 0;
            }

        } else {
            uf.unite(l, r, d);
        }
    }
    print("Yes");

    return 0;
}


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

typedef long long ll;

multiset<ll> hv;
ll l[300005], r[300005], v[300005], s, ans(-(1ll<<60));
int n;

int main()
{
	scanf("%d", &n);
	for (int i = 0;i < 3*n;i++) scanf("%lld", v+i);
	for (int i = 0;i < 3*n;i++)
	{
		hv.insert(v[i]); s += v[i];
		if (hv.size() > n) { s -= *hv.begin(); hv.erase(hv.begin()); }
		if (hv.size() == n)
			l[i] = s;
		else
			l[i] = -(1ll<<60);
	}
	s = 0; hv.clear();
	for (int i = 3*n-1;i >= 0;i--)
	{
		hv.insert(v[i]); s += v[i];
		if (hv.size() > n) { s -= *hv.rbegin(); hv.erase(--hv.end()); }
		if (hv.size() == n)
			r[i] = s;
		else
			r[i] = 1ll<<60;
	}
	for (int i = 1;i < 3*n;i++)
		ans = max(ans, l[i-1]-r[i]);
	printf("%lld\n", ans);
	return 0;
}


Measured memory_bytes: 13952
#include <iostream>
#include <string>
#include <climits>

using namespace std;

int main() {
  string str;
  cin >> str;
  int ans = INT_MAX;
  for (int i = 0; i + 2 < static_cast<int>(str.size()); ++i) {
    int tmp = stoi(str.substr(i, 3));
    ans = min(ans, abs(753 - tmp));
  }
  cout << ans << endl;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
#include <iostream>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <complex>
#include <vector>
#include <list>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <string>
#include <algorithm>
#if __cplusplus >= 201103
#include <numeric>
#endif
using namespace std;

int main(){
    int n;
    string s;
    cin >> n;
    cin >> s;
    int count = 0, max = 0;
    for(int i=0;i<n;i++){
        if(s.at(i)=='I'){
            count ++;
            if (count >= max) max = count; 
        }
        else if(s.at(i)=='D') count--;
    }
    cout << max << endl;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
   int a,b,c,cnt=0;
   cin>>a>>b>>c;
   for(int i=a;i<=b;i++){
    if(c%i==0)
        cnt++;
   }
   cout<<cnt;
   cout<<"\n";
    return 0;
}



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

int main(){

 long N, K;
 int ans = 0;
 scanf("%ld", &N);

if((N/1000)%10 == 2) ans += 1;
if((N/100)%10 == 2) ans += 1;
if((N/10)%10 == 2) ans += 1;
if((N/1)%10 == 2) ans += 1;
 printf("%d\n", ans);
  return 0;
}

Measured memory_bytes: 128
#include <iostream>

using namespace std;

int main(int argc, char **argv)
{
	long int min=0, max=0, sum=0;
    int temp;
    int n;
    cin>>n;
    for(int i =0;i<n;i++){
        cin>>temp;
        if(i==0){
            min = temp;
            max = temp;
        }
        sum+=temp;
        if(temp<min){
            min = temp;
        }
        if(temp>max){
            max = temp;
        }
    }
    
    cout<<min<<' '<<max<<' '<<sum<<endl;
    
	return 0;
}

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

int main(){
  int n, m, x; cin >> n >> m >> x;
  int A[n+1];
  for (int i=0; i<n+1; i++){
    A[i] = 0;
  }
  for (int i=0; i<m; i++){
    int j;
    cin >> j;
    A[j] = 1;
  }
  int cnta=0, cntb=0;
  for (int i=x+1; i<n+1; i++){
    if (A[i] == 1) cnta++;
  }
  for (int i=x-1; i>=0; i--){
    if (A[i] == 1) cntb++;
  }
  cout << min(cnta, cntb) << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define erep(i, n) for (ll i = 0; i <= (ll)(n); ++i)
#define FOR(i,a,b) for (ll i = (a); i < (ll)(b); ++i)
#define EFOR(i,a,b) for (ll i = (a); i <= (ll)(b); ++i)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } }

using Graph = vector<vector<int>>;
using P = pair<ll, ll>;
using Tuple = tuple<int, int, int>;

const double PI=3.1415926535897932;

int main() {
    double r; cin >> r;
    cout << fixed << setprecision(9) << 2 * r * PI << endl;
    return 0;
}


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

int main() {
	cin.tie(0);
   	ios::sync_with_stdio(false);
   	string a[3];cin>>a[0]>>a[1]>>a[2];
    int p[3] = {0,0,0};
    int l[3] = {a[0].length(),a[1].length(),a[2].length()};
    int t = 0;
    while(1){
        if(a[t][p[t]] >= 'a'&&a[t][p[t]] <= 'c'){
            p[t]++;
            t = a[t][p[t]-1]-'a';
        }else{
            cout << (char)('A' + t) << endl;
            return 0;
        }
    }
	
	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		try(Scanner sc = new Scanner(System.in)) {

			long n = sc.nextLong();
			//もっとも数字の近い2つの数の積に分割する

			long result = calcFactor(n);
			
			System.out.println(result);
		}
	}
	
	public static long calcFactor(long n) {
		
		long currentStep = Long.MAX_VALUE;
		
		for(long i = 1 ; i < Math.pow(n, 0.5) + 2 ; i++ ) {
			
			if ( n % i == 0 ) {
				//this is factor
				long j = n / i;
				if ( i + j - 2 < currentStep ) {
					currentStep = i + j - 2;
				}
			}
		}
		
		return currentStep;
	}
}


Measured memory_bytes: 23764
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    long n = sc.nextLong();
    long k = sc.nextLong();
    long x = sc.nextLong();
    long y = sc.nextLong();
    long ans = 0;
    if(n <= k) {
      ans = (x * n);
    } else {
      ans = (x * k) + (y * (n - k));
    }
    System.out.println(ans);
  }
}

Measured memory_bytes: 21844
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<bitset>
#include<vector>
#include<deque>
#include<queue>
#include<map>
#include<set>
#include<stack>
#include<cmath>
#include<iomanip>
#include <functional>
using namespace std;
typedef long long ll;
const int mod = 1000000007;
const int INF = 1 << 30;
const double EPS = 1e-10;
//cout << fixed << std::setprecision(9)
//memset(a, 0, sizeof(a));
//--------------------------

string s;
int a, b, c, d, x;

int main()
{
	cin >> a;

	if (a < 1200) {
		cout << "ABC" << endl;
	}
	else if (a < 2800) {
		cout << "ARC" << endl;
	}
	else {
		cout << "AGC" << endl;
	}

	return 0;
}


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

#define REP(i,n) for(int i = 0;i < n;i++)
#define REPR(i,n) for(int i = n-1;i >= 0;i--)
#define FOR(i,m,n) for(int i = m;i < n;i++)
#define PRINT(s) cout<<s
#define PRINTS(s) cout<<s<<' '
#define PRINTL(s) cout<<s<<endl
#define INF 2e9
#define ALL(v) v.begin(),v.end()
#define ll long long

using namespace std;



int gcd(int max,int min){
    
    if(max<min){
        int tmp=max;
        max=min;
        min=tmp;
    }

    if(max%min==0)return min;
    else return gcd(min,max%min);

}

int main(void){

    string s;
    cin>>s;

    int n[26]={0};

    for(int i=0;i<s.size();i++){
        int a = s[i]-'a';
        n[a]++;
        if(n[a]>1){
            cout<<"no"<<endl;
            return 0;
        }
    }
    cout<<"yes"<<endl;

    return 0;
}




Measured memory_bytes: 384
N = int(input())
testimo_ls = [ [] for i in range(N) ]
rst = 0
for i in range(N):
    A = int(input())
    for j in range(A):
        x, y = map(int, input().split(' '))
        testimo_ls[i].append([x - 1, y])
for i in range(1 << N):
    honest_ls = []
    for j in range(N):
        if i >> j & 1:
            honest_ls.append(j)
    is_ok = True
    for s in honest_ls:
        for t in testimo_ls[s]:
            if t[1] == 0 and t[0] in honest_ls:
                is_ok = False
                break
            if t[1] == 1 and t[0] not in honest_ls:
                is_ok = False
                break
    if is_ok:
        rst = max(rst, len(honest_ls))
print(rst)

Measured memory_bytes: 9128
using System;

namespace ConsoleApp2
{
    class Program
    {
        static void Main(string[] args)
        {
            int s = Console.Read();

            if (('A' <= s)&& (s <= 'Z'))
            {
                Console.Write('A');
            }
            else if(('a' <= s) && (s <= 'z'))
            {
                Console.Write('a');
            }
        }
    }
}


Measured memory_bytes: 25752
#include<map>
#include<set>
#include<cmath>
#include<stack>
#include<deque>
#include<queue>
#include<cstdio>
#include<string>
#include<vector>
#include<cstring>
#include<cstdlib>
#include<iostream>
#include<algorithm>
const int mod=1e9+7;
const double eps=1e-6;
const double pi=acos(-1);
const int inf=0x7fffffff;
typedef long long int ll;
typedef unsigned long long ull;
using namespace std;

char a[205];

int main()
{
    scanf("%s",a+1);
    int len=strlen(a+1);
    if(len&1)
    {
        len--;
        while(1)
        {
            bool flag=true;
            for(int i=1,j=len/2+1; i<=len/2; i++,j++)
            {
                if(a[i]!=a[j])
                {
                    flag=false;
                    break;
                }
            }
            if(flag)
            {
                printf("%d\n",len);
                break;
            }
            len-=2;
        }
    }
    else
    {
        len-=2;
        while(1)
        {
            bool flag=true;
            for(int i=1,j=len/2+1; i<=len/2; i++,j++)
            {
                if(a[i]!=a[j])
                {
                    flag=false;
                    break;
                }
            }
            if(flag)
            {
                printf("%d\n",len);
                break;
            }
            len-=2;
        }
    }
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
long long a[210000]={0};
int main()
{
	int n;
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		scanf("%lld",&a[i]);
	}
	int l=1,r=1;
	int sum=a[1],num=a[1];
	long long ans=0;
	//cout<<endl;
	while(r<=n)
	{
		//cout<<sum<<" "<<num<<endl;
		//cout<<"a";
		if(sum==num)
		{
			ans+=r-l+1;
			r++;
			num=num^a[r];
			sum+=a[r];
		}
		else
		{
			num=num^a[l];
			sum=sum-a[l];
			l++;
		}
		
	}
	cout<<ans;
	return 0;
}

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

int N,A[100010];

int main()
{
    scanf("%d",&N);
    for(int i = 0; i < N; i++)scanf("%d",A + i);
    int MAX = -1,id;
    for(int i = 0; i < N; i++)
    {
        if(MAX < abs(A[i]))
        {
            MAX = abs(A[i]);
            id = i;
        }
    }
    printf("%d\n",N + N - 1);
    for(int i = 0; i < N; i++)
        printf("%d %d\n",id + 1,i + 1);
    if(A[id] < 0)
    {
        for(int i = 0; i < N - 1; i++)printf("%d %d\n",N - i,N - i - 1);
    }
    else
    {
        for(int i = 0; i < N - 1; i++)printf("%d %d\n",i + 1,i + 2);
    }
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
int main(void)
{
	int n,c,i=0,p,su=0,cake;
	scanf("%d %d",&n,&c);
	for(i=0;i<c;i++){
		scanf("%d",&p);
		su+=p;
	}
	cake=su/(n+1);
	if(su%(n+1)!=0){
		cake++;
	}
	printf("%d\n",cake);
	return 0;
}


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

int main() {
  int x;
  cin >> x;
  if (x >= 30) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}

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

using namespace std;

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

typedef long long ll;

const int Inf = 1e9;
const double EPS = 1e-9;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    int cnt = 0;
    ll sum = 0;
    int mini = Inf;
    cin >> n;
    vector<ll> v(n);
    rep (i, n) {
        cin >> v[i];
        mini = (ll)min((ll)mini, abs(v[i]));
        sum += abs(v[i]);
        if (v[i] < 0) cnt++;
    }
    if (cnt % 2) {
        sum = sum - mini - mini;
    }
    cout << sum << endl;
    
    return 0;
}



Measured memory_bytes: 1024
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Convert;
using static System.Math;

class Program
{
    class P
    {
        public int index;
        public List<int> ad;
        public int d;
        public int f;
        public P(int index)
        {
            this.index = index;
            ad = new List<int>();
        }
        public override string ToString()
        {
            return $"{index+1} {d} {f}";
        }
    }
    private static int time = 0;
    static void Main(string[] args)
    {
        var num = ToInt32(ReadLine());
        var gr = new P[num];
        for(var i = 0; i < num; i++)
        {
            var input = Array.ConvertAll(ReadLine().Split(' '), int.Parse);
            gr[i] = new P(i);
            for (var j = 0; j < input[1]; j++)
                gr[i].ad.Add(input[j + 2]-1);
        }
        var set = new HashSet<int>();
        for (var i = 0; i < num; i++)
            if (!set.Contains(i))
                dfs(gr, i, set);
        WriteLine(string.Join("\n", gr.Select(g => g.ToString()).ToArray()));
    }
    private static void dfs(P[] gr,int index,HashSet<int> set)
    {
        time++;
        set.Add(index);
        gr[index].d = time;
        foreach (var ad in gr[index].ad)
        {
            if (!set.Contains(ad))
                dfs(gr, ad, set);
        }
        time++;
        gr[index].f = time;
    }
    private const string ALFA = "abcdefghijklmnopqrstuvwxyz";
    private const int MOD = 1000000007;
}



Measured memory_bytes: 16868
#include <iostream>
//#include <ios>
#include <vector>
#include <algorithm>

using namespace std;

int main(){
  ios::sync_with_stdio(false);
  int M, N;
  vector<int> u, v;

  //input
  cin >> M;
  for(int i = 0; i < M; ++i){
    int m;
    cin >> m;
    u.push_back(m);
  }

  cin >> N;
  for(int i = 0; i < N; ++i){
    int n;
    cin >> n;
    v.push_back(n);
  }

  //calc
  int res = 0;

  vector<int>& l = (M >= N ? u : v);
  vector<int>& s = (M >= N ? v : u);  

  for(auto x : s){
    if(find(l.begin(), l.end(), x) != l.end()){
      ++res;
    }
  }
  
  cout << res << endl;
}

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

int main(){
  int N,K;
  cin>>N>>K;
  vector<int64_t> H(N);
  for(int i=0;i<N;i++){
    cin>>H.at(i);
  }
  sort(H.begin(),H.end());
  reverse(H.begin(),H.end());
  int64_t s=0;
  for(int i=K;i<N;i++){
    s=s+H.at(i);
  }
  cout<<s<<endl;
}

Measured memory_bytes: 1792
import sys
import heapq
import math
import fractions
import bisect
import itertools
from collections import Counter
from collections import deque
from operator import itemgetter
def input(): return sys.stdin.readline().strip()
def mp(): return map(int,input().split())
def lmp(): return list(map(int,input().split()))

s=input()
t=input()
ans=0
for i in range(len(s)):
    if s[i]!=t[i]:
        ans+=1
print(ans)

Measured memory_bytes: 78368
#include <bits/stdc++.h>
#define REP(i,s,e) for(int i=(s); i<(e);i++)
#define rep(i,n) REP(i,0,n)
#define rep1(i,n) REP(i,1,n)
#define repe(i,n) for(auto &&i:n)
#define all(v) (v).begin(),(v).end()
#define decimal fixed<<setprecision(20)
#define fastcin() cin.tie(0);ios::sync_with_stdio(false)
using namespace std;
using LL = long long;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int INF = 1e9;
const LL LLINF = 1e16;

int main(){
  string s;
  cin>>s;
  repe(i,s) cout<<(i=='1'?'9':'1');
  cout<<endl;
}


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

int main() {
	int n, l;
	cin >> n >> l;
	vector<string> s(n);
	for (int i = 0; i < n; i++)
		cin >> s.at(i);

	sort(s.begin(), s.end());
	for (int i = 0; i < n; i++)
		cout << s.at(i);
	cout << endl;
}

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

int main() {
	int N,M,C;
    cin >> N >> M >> C;
    vector<int> B(M);
    for(int i=0;i<M;i++){
      cin >> B.at(i);
    }
    int count=0;
    for(int i=0;i<N;i++){
      vector<int> A(M);
      int sum=0;
      for(int j=0;j<M;j++){
        cin >> A.at(j);
        sum += A.at(j)*B.at(j);
      }
      sum +=C;
      if(sum>0){
        count++;
      }
    }
  cout << count << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
  int x,y,z;
  vector<int> a(3);
  cin>>x>>y>>z;
  a[0]=x+y;
  a[1]=y+z;
  a[2]=z+x;
  sort(a.begin(),a.end());
  cout<<a[0]<<endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<set>
#include<string>
#include<map>
#include<string.h>
#include<complex>
#include<math.h>
#include<queue>
#include<time.h>
using namespace std;
typedef long long int llint;
typedef pair<int, int> pint;
typedef pair<llint, llint> pllint;
typedef vector<int> vint;
typedef vector<llint> vllint;
typedef vector<pint> vpint;
typedef vector<string> vstring;
typedef vector<pair<llint, llint>> vpllint;
typedef vector<vector<int>> vvint;
typedef vector<vector<llint>> vvllint;
typedef vector<vector<pint>> vvpint;
typedef vector<bool> vbool;
#define rep(i,n) for(int i=0;i<n;i++)
#define drep(i,n) for(int i=n-1;0<=i;i--)
#define yes(ans) if(ans)cout<<"yes"<<endl;else cout<<"no"<<endl;
#define Yes(ans) if(ans)cout<<"Yes"<<endl;else cout<<"No"<<endl;
#define YES(ans) if(ans)cout<<"YES"<<endl;else cout<<"NO"<<endl;
#define POSSIBLE(ans) if(ans)cout<<"POSSIBLE"<<endl;else cout<<"IMPOSSIBLE"<<endl;
#define Pi 3.1415926535897932384626
#define mod llint(1e9+7)

class UnionFind {
public:
	//親の番号を格納する。親だった場合は-(その集合のサイズ)
	vector<int> Parent;

	//作るときはParentの値を全て-1にする
	//こうすると全てバラバラになる
	UnionFind(int N) {
		Parent = vector<int>(N, -1);
	}

	//Aがどのグループに属しているか調べる
	int root(int A) {
		if (Parent[A] < 0) return A;
		return Parent[A] = root(Parent[A]);
	}

	//自分のいるグループの頂点数を調べる
	int size(int A) {
		return -Parent[root(A)];//親をとってきたい
	}

	//AとBをくっ付ける
	bool connect(int A, int B) {
		//AとBを直接つなぐのではなく、root(A)にroot(B)をくっつける
		A = root(A);
		B = root(B);
		if (A == B) {
			//すでにくっついてるからくっ付けない
			return false;
		}

		//大きい方(A)に小さいほう(B)をくっ付けたい
		//大小が逆だったらひっくり返しちゃう。
		if (size(A) < size(B)) swap(A, B);

		//Aのサイズを更新する
		Parent[A] += Parent[B];
		//Bの親をAに変更する
		Parent[B] = A;

		return true;
	}
};

//aとbの最大公約数を求めるよ
long long GCD(long long a, long long b) {
	if (b == 0) return a;
	else return GCD(b, a % b);
}

// 返り値: a と b の最大公約数
// ax + by = gcd(a, b) を満たす (x, y) が格納される
long long extGCD(long long a, long long b, long long& x, long long& y) {
	if (b == 0) {
		x = 1;
		y = 0;
		return a;
	}
	long long d = extGCD(b, a % b, y, x);
	y -= a / b * x;
	return d;
}

bool check(llint a, llint b) {
	return a > b;
}

// mod. m での a の逆元 a^{-1} を計算する
long long modinv(long long a, long long m) {
	long long b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}

//aCbを1000000007で割った余りを求める
llint convination(llint a, llint b) {
	llint ans = 1;
	for (llint i = 0; i < b; i++) {
		ans *= a - i;
		ans %= 1000000007;
	}
	for (llint i = 1; i <= b; i++) {
		ans *= modinv(i, 1000000007);
		ans %= 1000000007;
	}
	return ans;
}

//aのb乗をmodで割った余りを求める
llint power(llint a, llint b) {
	if (b == 1)return a;
	if (b == 0)return 1;
	llint tmp = power(a, (llint)b / 2);
	tmp *= tmp;
	tmp %= mod;
	if (b % 2 == 1) {
		tmp *= a;
		tmp %= mod;
	}
	return tmp;
}

int main() {
	llint n, k;
	cin >> n >> k;
	vllint h(n);
	rep(i, n)cin >> h[i];
	sort(h.begin(), h.end(), check);
	llint ans = 0;
	for (int i = k; i < n; i++) {
		ans += h[i];
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1792
n, p = map(int, input().split())
s = input()
r = set()
last = 0
d = {0: 0}
total = 0
rem = 0
if p == 2:
    for i in range(0, len(s)):
        if int(s[i]) % 2 == 0:
            total += i + 1
    print(total)
elif p == 5:
    for i in range(0, len(s)):
        if int(s[i]) % 5 == 0:
            total += i + 1
    print(total)



else:
    power = 1
    for i in range(len(s) - 1, -1, -1):  # handling of 0's as n and rem
        n = int(s[i]) * power + rem
        power *= 10
        power = power % p
        rem = n % p
        if rem in d.keys():
            d[rem] += 1
        else:
            d[rem] = 1
        total += d[rem] - 1
    print(total + d[0])


Measured memory_bytes: 4072
// Original: https://github.com/tanakh/competitive-rs
#[allow(unused_macros)]
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)*}
    };
}

#[allow(unused_macros)]
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)*}
    };

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

#[allow(unused_macros)]
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, bytes) => {
        read_value!($next, String).into_bytes()
    };

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

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

#[allow(unused_imports)]
use std::cmp::{max, min};
#[allow(unused_imports)]
use std::collections::HashMap;

fn main() {
    input!(n: usize);
    let ans = (n - 2) * 180;
    println!("{}", ans);
}


Measured memory_bytes: 4352
N=int(input());d={};p=1
for i in range(1,1+N):
 f=2
 while f*f<=i:
  if i%f:f+=1
  else:d[f]=d.get(f,0)+1;i//=f
 if i>1:d[i]=d.get(i,0)+1
for v in d.values():p*=v+1
print(p%(10**9+7))

Measured memory_bytes: 3060
package main

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

const mod = 998244353
const facNum = 300001
const INF = 1001001001

func main() {
	sc := newScanner(os.Stdin)
	a, b, c, d := sc.i(), sc.i(), sc.i(), sc.i()
	for a > 0 && c > 0 {
		c = c - b
		if c <= 0 {
			fmt.Println("Yes")
			return
		}
		a = a - d
		if a <= 0 {
			fmt.Println("No")
			return
		}
	}
}

// fmt.Println("Yes")
// fmt.Println("No")

// I/O
type scanner struct {
	sc *bufio.Scanner
}

func newScanner(input io.Reader) *scanner {
	sc := bufio.NewScanner(input)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024), int(1e+9))
	return &scanner{sc}
}

func (s *scanner) s() string {
	s.sc.Scan()
	return s.sc.Text()
}

func (s *scanner) i() int {
	i, e := strconv.Atoi(s.s())
	if e != nil {
		panic(e)
	}
	return i
}

func (s *scanner) f() float64 {
	f, e := strconv.ParseFloat(s.s(), 64)
	if e != nil {
		panic(e)
	}
	return f
}

func (s *scanner) bs() []byte {
	return []byte(s.s())
}

func (s *scanner) is(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = s.i()
	}
	return res
}

func (s *scanner) fs(n int) []float64 {
	res := make([]float64, n)
	for i := 0; i < n; i++ {
		res[i] = s.f()
	}
	return res
}

//const factorial = new
func Pow(a, n int) int {
	ans := 1
	for n > 0 {
		if (n & 1) == 1 {
			ans = ans * a % mod
		}
		a = a * a % mod
		n = n >> 1
	}
	return ans
}

func Gcd(a, b int) int {
	if a < b {
		return Gcd(b, a)
	}
	for b != 0 {
		a, b = b, a%b
	}
	return a
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func combination(n, k int, fac, ifac []int) int {
	if n < k || n < 0 {
		return 0
	}
	if k == 0 {
		return 1
	}
	//while n != 0
	ans := ifac[k] * ifac[n-k] % mod
	return ans * fac[n] % mod
}

// 階乗: factorial
// コンビネーションを計算する際に前もって計算しておく
// fac[k] => k! (mod M)
// ifac[k] => k!^(M-2) (mod M)
// n: ex. 2 * 10^5 => 200001
// fac, ifac := factorial()
func factorial() (fac []int, ifac []int) {
	fac = make([]int, facNum)
	fac[0] = 1
	ifac = make([]int, facNum)
	ifac[0] = 1
	for i := 1; i < facNum; i++ {
		fac[i] = fac[i-1] * i % mod
		ifac[i] = ifac[i-1] * Pow(i, mod-2) % mod
	}
	return
}

// vs: sorted slice int value
func lowerBound(vs []int, v int) (index int) {
	n := len(vs) / 2
	m := len(vs)
	for m != n {
		if vs[n] < v {
			n = (m-n+1)/2 + n
			//m = m
		} else {
			m = n
			n = n / 2
		}
	}
	return n
}


Measured memory_bytes: 1756
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
using namespace std;
typedef long long int lli;
const int inf = 1e9;
const lli mod = 1e9 +7;
typedef pair<lli, lli> pll;
typedef pair<int, int> pii;

struct BinaryGridGraph{
    int h,w;
    vector<bool> g;
    vector<vector<int>> adj;
    BinaryGridGraph(vector<vector<bool>> &grid){
        h = grid.size();
        w = grid[0].size();
        g.resize(h*w);
        adj.resize(h*w);
        const int di[4] = {1, 0, -1, 0};
        const int dj[4] = {0, 1, 0, -1};
        for(int i=0; i<h; i++){
            for(int j=0; j<w; j++){
                int idx = i*w +j;
                g[idx] = grid[i][j];
                if(!grid[i][j]) continue;
                for(int d=0; d<4; d++){
                    int ni=i+di[d], nj=j+dj[d];
                    if(ni<0 or h<=ni or nj<0 or w<=nj) continue;
                    if(!grid[ni][nj]) continue;
                    int nidx = ni*w +nj;
                    adj[idx].push_back(nidx);
                    adj[nidx].push_back(idx);
                }
            }
        }
    }
    vector<vector<int>> getAdjMatrix(){
        vector<vector<int>> res(h*w, vector<int>(h*w, inf));
        for(int i=0; i<h*w; i++){
            for(int j: adj[i]){
                res[i][j] = res[j][i] = 1;
            }
            res[i][i] = 0;
        }
        return res;
    }
};

int main(){
    int h,w;
    cin >> h >> w;
    vector<vector<bool>> s(h, vector<bool>(w));
    for(int i=0; i<h; i++){
        for(int j=0; j<w; j++){
            char c;
            cin >> c;
            s[i][j] = (c == '.');
        }
    }
    BinaryGridGraph graph(s);
    auto adj = graph.getAdjMatrix();
    int n = adj.size();
    for(int k=0; k<n; k++){
        for(int i=0; i<n; i++){
            for(int j=0; j<n; j++){
                adj[i][j] = min(adj[i][j], adj[i][k]+adj[k][j]);
            }
        }
    }

    int ans = 0;
    for(int i=0; i<n; i++){
        for(int j=0; j<n; j++){
            if(adj[i][j] != inf){
                ans = max(ans, adj[i][j]);
            }
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 896
#include <bits/stdc++.h>
using namespace std;typedef long long ll;typedef string str;
typedef vector<str> vst;typedef vector<ll> vll;
ll mod = 1000000007, INF = 10000000000000000;
ll gcd(ll a, ll b){if(b==0){return a;}return gcd(b, a%b);}
// for (ll i = 0; i < n; i++) {
// sort(.begin(),.end());

int main(){
  string s;
  cin>>s;
  
  if((s[0]==s[3]&&s[1]==s[2]&&s[0]!=s[1])||(s[0]==s[1]&&s[2]==s[3]&&s[0]!=s[2])||(s[0]==s[2]&&s[1]==s[3])&&s[0]!=s[1]){
    cout<<"Yes"<<endl;
  }else{
	cout<<"No"<<endl;
  }
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main{

	public static void main(String[] args) throws IOException {
		int num1 = 0;
		int num2 = 0;
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String strArray[] = (br.readLine()).split(" ");
		Stack stack = new Stack(strArray.length);
		for(int i = 0;i < strArray.length; i++){
			if(strArray[i].equals("+")){
				num1 = stack.pop();
				num2 = stack.pop();
				stack.push(num1 + num2);
			}
			else if(strArray[i].equals("*")){
				num1 = stack.pop();
				num2 = stack.pop();
				stack.push(num1 * num2);
			}
			else if(strArray[i].equals("-")){
				num1 = stack.pop();
				num2 = stack.pop();
				stack.push(num2 - num1);
			}
			else{
				stack.push(Integer.parseInt(strArray[i]));
			}
		}
		System.out.println(stack.pop());
	}

}

class Stack{
	private int top;
	private int stack[];

	Stack(int size){
		stack = new int [size];
		top = 0;
	}

	public int pop(){
		return stack[--top];
	}

	public void push(int num){
		stack[top++] = num;
	}
}

Measured memory_bytes: 24424
#include<bits/stdc++.h>
// #define int long long
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define repa(i, s, n) for(int i = s; i < (int)n; i++)
#define MOD 1000000007
using namespace std;
using ll = long long;
typedef vector<int> vi;


signed main() {
    string s;
    cin >> s;

    vi a(4);
    a[0] = s[0] - '0';
    a[1] = s[1] - '0';
    a[2] = s[2] - '0';
    a[3] = s[3] - '0';
    
    for(int bits = 0; bits < (1 << 3); bits++){
        int sum = 7 - a[0];
        for(int i = 0; i < 3; i++){
            if(bits&(1<<i)){
                sum += a[i+1];
            }else{
                sum -= a[i+1];
            }
        }
        if(sum == 0){
            cout << a[0] << ((bits&(1<<0)? '-' : '+'))<< a[1] << ((bits&(1<<1)? '-' : '+'))
            << a[2] << ((bits&(1<<2)? '-' : '+')) << a[3] << "=7\n";
            return 0;
        }
    }
}

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

int a[10000];
int s;
int main(){
  while(cin >> s && s != 0){
    a[0] = 1;
    a[1] = 1;
    a[2] = 2;
    for(int i = 3; i < s + 1; ++i){
      a[i] = a[i-1] + a[i-2] + a[i-3];
    }
    cout << ((a[s]/10)/365) + 1 <<endl;
  }
}


Measured memory_bytes: 3060
class BinarySearchTree:
    def __init__(self):
        self.root = None
        self.order_list = []
    def insert(self, z):
        y = None
        x = self.root
        while x != None:
            y = x
            if z.key < x.key:
                x = x.left
            else:
                x = x.right
        z.parent = y
        if y == None:
            self.root = z
        elif z.key < y.key:
            y.left = z
        else:
            y.right = z
            
    def walk_preorder(self, node):
        if node == None:
            return None
        self.order_list.append(node.key)
        self.walk_preorder(node.left)
        self.walk_preorder(node.right)
    def walk_inorder(self, node):
        if node == None:
            return None
        self.walk_inorder(node.left)
        self.order_list.append(node.key)
        self.walk_inorder(node.right)
    def print_nodes(self):
        self.order_list = []
        self.walk_inorder(self.root)
        inorder_str = ' '.join(map(str, self.order_list))
        print(' {}'.format(inorder_str))
        self.order_list = []
        self.walk_preorder(self.root)
        preorder_str = ' '.join(map(str, self.order_list))
        print(' {}'.format(preorder_str))
        
class Node:
    def __init__(self, key):
        self.key = key
        self.parent = None
        self.left = None
        self.right = None

n = int(input())
tree = BinarySearchTree()
for _ in range(n):
    command = input().split(' ')
    if len(command) == 1:
        tree.print_nodes()
    else:
        opecode, operand = command[0], int(command[1])
        node = Node(operand)
        tree.insert(node)


Measured memory_bytes: 147304
package main

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

var sc = bufio.NewScanner(os.Stdin)

func main() {
	n := nextInt()
	var m = make(map[string]int, n)
	for _, str := range nextStrings(n) {
		m[str] = 1
	}

	count := 0
	for _, val := range m {
		count = count + val
	}

	fmt.Printf("%d\n", count)
}

func nextStrings(n int) []string {
	ret := make([]string, n)
	for i := 0; i < n; i++ {
		ret[i] = next()
	}
	return ret
}

func nextInt() int {
	a, _ := strconv.Atoi(next())
	return a
}

func next() string {
	sc.Scan()
	return sc.Text()
}


Measured memory_bytes: 16344
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
template < typename T > string tost( const T& n ) { ostringstream stm; stm << n; return stm.str();}
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1;} return 0;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1;} return 0;}
int const INF = 1001001001;


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

int N;
cin >> N;
vl a(3*N);
rep(i,3*N) cin >> a[i];
sort(all(a), greater<int>());
ll ans = 0;
rrep(i,N) ans += a[2*i-1];
cout << ans << endl;
return 0;
}

Measured memory_bytes: 2560
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
  ll n;
  cin>>n;
  ll sol[n][3];
  ll i;
  ll a,b,c;
  for(i=0;i<n;i++)
  {
    cin>>a>>b>>c;
    if(i==0)
    {
      sol[0][0]=a;
      sol[0][1]=b;
      sol[0][2]=c;
    }
    else
    {
      sol[i][0]=max(a+sol[i-1][1],a+sol[i-1][2]);
      sol[i][1]=max(b+sol[i-1][0],b+sol[i-1][2]);
      sol[i][2]=max(c+sol[i-1][0],c+sol[i-1][1]);
    }
  }
  cout<<max(sol[n-1][0],max(sol[n-1][1],sol[n-1][2]));
    
}


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

string S;
set<string> ans;

void dfs(int x, vector<int>& exists) {
    if (x == S.size()) {
        ans.insert(S);
        return;
    }

    if (S[x] == 'a' || exists[S[x]-'a']) {
        exists[S[x]-'a']++;
        dfs(x+1, exists);
        exists[S[x]-'a']--;
    }
    if (S[x] != 'z' && !exists[S[x]-'a'+1]) {
        char saved = S[x];
        exists[S[x]-'a'+1]++;
        S[x] = S[x]+1;
        dfs(x+1, exists);
        exists[saved-'a'+1]--;
        S[x] = saved;
    }
}

void solve() {
    vector<int> exists(26, 0);
    dfs(0, exists);
    if (ans.size() <= 10) {
        cout << ans.size() << endl;
        for (string s : ans) {
            cout << s << endl;
        }
    } else {
        cout << ans.size() << endl;
        set <string> temp;
        int count = 0;
        for (auto it = ans.begin(); count < 5; ++count, ++it) {
            cout <<* it << endl;
        }
        count = 0;
        for (auto it = ans.rbegin(); count < 5; ++count, ++it) {
            temp.insert(*it);
        }
        for (auto it : temp) {
            cout << it << endl;
        }
    }
}

int main(){
    while (true) {
        cin >> S;
        if (S == "#") break;
        ans.clear();
        solve();
    }
    return 0;
}

Measured memory_bytes: 5020
#include <iostream>
#include <sstream>
#include <stack>
#include <iomanip>
#include <numeric>
#include <string>
#include <cstring>
#include <algorithm>
#include <functional>
#include <cstdlib>
#include <map>
#include <set>
#include <vector>
#include <utility>
#include <queue>
#include <cmath>

#define BEGIN(x) x.begin()
#define END(x) x.end()
#define ALL(x) BEGIN(x), END(x)
#define PAIR make_pair
#define VEC(type) vector<type >

#define FOR(i, A, B) for(auto i = (A);i != (B); i++)
#define FORD(i, A, B) for(auto i = (A);i != (B); i--)

#define READRANGE(begin, end) FOR(it, begin, end) cin >> *it
#define READVEC(V) READRANGE(BEGIN(V), END(V))

using namespace std;

typedef long long lint;
typedef pair<int, int> Pii;
typedef pair<int, lint> Pil;
typedef pair<lint, lint> Pll;
typedef pair<lint, int> Pli;

// ---- BEGIN LIBRARY CODE ----
// ---- END LIBRARY CODE ----
void io_init()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
};

int main(int argc, char **argv)
{
    io_init();

    // Actual program code starts here.
    int H, W;
    cin >> H >> W;

    VEC(string) _Grid(H);
    FOR(i, 0, H) {
        cin >> _Grid[i];
    }

    VEC(VEC(int)) Up(H, VEC(int)(W, 0));
    VEC(VEC(int)) Left(H, VEC(int)(W, 0));
    VEC(VEC(int)) Down(H, VEC(int)(W, 0));
    VEC(VEC(int)) Right(H, VEC(int)(W, 0));

    FOR(i, 0, H) {
        int tail = 0;
        FOR(j, 0, W) {
            if (_Grid[i][j] == '#') {
                tail = 0;
            } else {
                tail++;
                Left[i][j] = tail;
                Up[i][j] = 1 + (i == 0 ? 0 : Up[i - 1][j]);
            }
        }
    }

    int ret = 0;
    FORD(i, H - 1, -1) {
        int tail = 0;
        FORD(j, W - 1, -1) {
            if (_Grid[i][j] == '#') {
                tail = 0;
            } else {
                tail++;
                Right[i][j] = tail;
                Down[i][j] = 1 + (i == H - 1 ? 0 : Down[i + 1][j]);
                ret = max(ret, Up[i][j] + Left[i][j] + Down[i][j] +
                                Right[i][j] - 4);
            }
        }
    }

    cout << (1 + ret) << endl;
    return 0;
};


Measured memory_bytes: 67328
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,n) for(int i=0;i<(n);i++)
#define all(t) (t).begin(),(t).end()
#define MOD 1000000007
typedef long long ll;
template <class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}else{return 0;}}
template <class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}else{return 0;}}
template <class T> inline T GCD(T a,T b){T c;while(b!=0){c=a%b;a=b;b=c;}return a;}
template <class T> inline T LCM(T a,T b){return a*b/GCD(a,b);}

int main(){
	int n;
	cin >> n;
	cout << fixed << setprecision(10);
	cout << ((double)((n+1)/2))/(double)n <<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
static const int MAX = 200000;
int main(){
	int R[MAX], n;
	cin >> n;
	for (int i = 0; i < n; i++)
		cin >> R[i];
	int maxv = -2000000000;
	int minv = R[0];
	for (int i = 1; i < n; i++){
		maxv = max(maxv, R[i] - minv);
		minv = min(minv, R[i]);
	}
	cout << maxv << endl;
	return 0;
}

Measured memory_bytes: 3804
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskA solver = new TaskA();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskA {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int a = in.nextInt(), b = in.nextInt();
            out.println(a + b >= 10 ? "error" : a + b);
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }
}



Measured memory_bytes: 23380
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt(), k = sc.nextInt(), ans = 0;
		int[] l = new int[n];
		for (int i = 0; i < n; i++) {
			l[i] = sc.nextInt();
		}
		Arrays.sort(l);
		for (int i = n-1; i >= n-k; i--) {
			ans += l[i];
		}
		System.out.println(ans);
	}

}

Measured memory_bytes: 21844