akhauriyash/Code-Regression huggingface dataset:
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.Map;

public class Main {
    public static void main(String[] args) {
        try (BufferedReader in = new BufferedReader(new InputStreamReader(System.in))){
            Map<Character, Integer> ret = new HashMap<>();
            for (int i = 0; i < 26; i++) {
                char c = (char) (i + 97);
                ret.put(c, 0);
            }

            while (true) {
                String s = in.readLine();
                if (s == null || s.equals("")) break;

                for (int i = 0; i < s.length(); i++) {
                    char c = s.charAt(i);
                    if (Character.isAlphabetic(c)) {
                        c = Character.toLowerCase(c);
                        ret.put(c, ret.get(c) + 1);
                    }
                }
            }

            StringBuilder sb = new StringBuilder();
            for (int i = 0; i < 26; i++) {
                char c = (char) (i + 97);
                sb.append(c);
                sb.append(" : ");
                sb.append(ret.get(c));
                sb.append("\n");
            }
            System.out.print(sb);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}



Measured memory_bytes: 24360
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>


using namespace std;
using namespace __gnu_pbds;

#define int long long int
#define pb push_back
#define M 998244353
#define ff first
#define ss second
#define deb(x) cout< #x< " "< x< endl;
#define fo(i,n) for(int i=0;i<n;i++)
#define ffo(i,k,n) for(int i=k;i<=n;i++)
#define ffORR(a,b,c) for(int a= b;a>=c;a--)
#define fa(defr) for(auto x:defr)
#define sz size()
// #define mp make_pair
#define mxm3(a,b,c) max(a, max(b,c))
#define mi3(a,b,c) min(a, min(b,c))
#define MarX 100005
#define PII pair<int,int>
#define aint(v) v.begin(), v.end()
#define endl "\n"
#define fast ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);


// typedef tree<pair<int, int>,
//         nuint_type,
//         less<pair<int, int>>,
//         rb_tree_tag,
//         tree_order_statistics_node_update> oset;

//126271
// 107897


int lcm(int a, int b) {
	int x = (a * b) % M;
	return x / __gcd(a, b);
}

int ceil(int a, int b) {
	if (a % b != 0) return a / b + 1;
	return a / b;
}


int power(int x, int y, int p)
{
	int res = 1LL;
	x = x % p;
	while (y > 0)
	{
		if (y & 1)
			res = (res * x) % p;
		y = y >> 1;
		x = (x * x) % p;
	}
	return res;
}

int pow1(int n) {
	int ans = power(2, n, M);
	ans = (ans - 1 + M) % M;
	return ans % M;
}


int32_t main() {

	fast;
	int t;
	// cin >> t;
	t = 1;
	// int tc = 1;
	while (t--) {
		// solve();
		int n; cin >> n;
		vector<int>arr(n);
		vector<int>dp(n);
		for (auto &x : arr) cin >> x;
		dp[0] = 0;
		dp[1] = abs(arr[1] - arr[0]);
		for (int i = 2; i < n; i++)
			dp[i] = min(dp[i-2] + abs(arr[i] - arr[i-2]), dp[i-1] + abs(arr[i-1] - arr[i]));
		// cout << min(dp[n - 1] , arr[n - 2]) << endl;
		cout << dp[n-1] << endl;
	}

}


Measured memory_bytes: 1792
#include <algorithm>
#include <climits>
#include <complex>
#include <cstring>
#include <iostream>
#include <map>
#include <set>
#include <vector>

// using
using namespace std;

// typedef
typedef long long ll;

// define
#define ALL(c) (c).begin(), (c).end()
#define SORT(c) sort(ALL(c))
#define REVERSE(c) reverse(ALL(c))
#define UNIQ(c) unique(ALL(c))
#define FOR(i, a, b, c) for (int i = (int)(a); i < (int)(b); i += (int)(c))
#define REP(i, n) FOR(i, 0, n, 1)
#define RFOR(i, a, b, c) for (int i = (int)(a); i >= (int)(b); i -= (int)(c))
#define RREP(i, n) RFOR(i, n, 0, 1)

// functions
int ceil(int a, int b) {
    return (a + b - 1) / b;
}
int round(int a, int b) {
    return (a + b / 2) / b;
}
int gcd(int a, int b) {
    return b ? gcd(b, a % b) : a;
}
int lcm(int a, int b) {
    return a * b / gcd(a, b);
}
template <class T> bool amax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template <class T> bool amin(T &a, const T &b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}

// main
int main() {
    int a, b, c;
    cin >> a >> b >> c;
    int res = (a != b) + (b != c) + (c != a);
    cout << max(res, 1) << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
int main()
{
	string a,b;
	cin>>a>>b;
	int ans=0;
	for(int i=0;i<a.length();i++)
	{
		string anss;
		anss=a.substr(i,a.length()-i)+a.substr(0,i);
		if(anss==b)
		{
			ans=1;
			break;
		}
	}
	if(ans)
		cout<<"Yes\n";
	else
		cout<<"No\n";
}

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

int main(){
    int N, K;
    cin >> N >> K;
    vector<int> x(N);
    for (int i = 0;  i < N;  i++){
        cin >> x.at(i);
    }
    int d = 0, min_d;
    for (int i = 0;  i <= N - K;  i++){
        d = x.at(K - 1 + i) - x.at(i);
        d += min(abs(x.at(K - 1 + i)), abs(x.at(i)));
        if (i == 0) min_d = d + 1;
        min_d = min(min_d, d);
    }
    cout << min_d << endl;
}

Measured memory_bytes: 640
import sys
# input = sys.stdin.readline
sys.setrecursionlimit(10 ** 9)
MOD = 10 ** 9 + 7

S = list(input())
i = len(S) - 1

T = ['dream', 'dreamer', 'erase', 'eraser']

while i > 0:
    if S[i] == 'm':
        for j in range(5):
            if S[i - j] == T[0][4 - j]:
                continue
            else:
                print ('NO')
                exit()
        i -= 5
    elif S[i] == 'r':
        if S[i - 2] == 'm':
            for j in range(7):
                if S[i - j] == T[1][6 - j]:
                    continue
                else:
                    print ('NO')
                    exit()
            i -= 7
        else:
            for j in range(6):
                if S[i - j] == T[3][5 - j]:
                    continue
                else:
                    print ('NO')
                    exit()
            i -= 6
    else:
        for j in range(5):
            if S[i - j] == T[2][4 - j]:
                continue
            else:
                print ('NO')
                exit()
        i -= 5

if i == -1:
    print ('YES')
else:
    print ('NO')

Measured memory_bytes: 4084
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007

ll cnt[26];
int main() {
	string s;
	cin>>s;
	ll i=0;ll j=s.size()-1;
	ll ans=0;
	while(i<j){
		if(s[i]==s[j]){
			i++;j--;
			continue;
		}
		else if(s[i]=='x'){
			i++;ans++;
			continue;
		}
		else if(s[j]=='x'){
			j--;ans++;
			continue;
		}
		cout << -1;
		return 0;
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 512
#include <stdio.h>
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#include <functional>
#include <map>
#include <iomanip>

using namespace std;

int main() {
	long long i, j, a, b, x, cnt=0;
	long long num, num1, num2;
	cin >> a >> b >> x;
	/*
	for (i = a; i <= b; i++) {
		if (i%x == 0) {
			cnt++;
		}
	}*/

	num1 = b / x;
	num2 = a / x;

	if (a%x == 0) {
		num2--;
	}

	num = num1 - num2;





	cout << num << endl;



	return 0;
}

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

#define rep(i,n) for(int i=0;i<(n);i++)
#define fi first
#define se second
#define pb push_back
#define mp make_pair

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

template<typename T> ostream& operator<< (ostream& os,const vector<T>& vec){ os << "{"; for(T v:vec) os << v << ","; os << "}"; }
template<typename T> ostream& operator<< (ostream& os,const set<T>& st){ os << "{"; for(T v:st) os << v << ","; os << "}"; }
template<typename T,typename U> ostream& operator<< (ostream& os,const pair<T,U>& p){ os << "{" << p.first << "," << p.second << "}"; return os; }


int m,nmin,nmax;

void solve(){
    vector<int> P(m);
    rep(i,m) cin>>P[i];

    int ans = -1;
    int diff = 0;

    for(int i=nmin;i<=nmax;i++){
        int idx = i-1;
        if(P[idx]==P[idx+1]) continue;

        int d = P[idx]-P[idx+1];
        //cout << i <<  " " << d << endl;
        if(diff <= d){
            diff = d;
            ans = i;
        }
    }
    cout << ans << endl;
}

int main(){
    while(1){
        cin >> m >> nmin >> nmax;
        if(m==0 and nmin==0 and nmax==0) break;
        solve();
    }
}

Measured memory_bytes: 3052
#include <bits/stdc++.h>     
 
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define ll long long
#define int ll
#define forn(i, a, b) for(int i = (a); i <= (b); ++i)
#define forev(i, b, a) for(int i = (b); i >= (a); --i)
#define VAR(v, i) __typeof( i) v=(i)
#define forit(i, c) for(VAR(i, (c).begin()); i != (c).end(); ++i)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define file(s) freopen(s".in","r",stdin); freopen(s".out","w",stdout);
 
using namespace std;
 
const int maxn = (int)3e3 + 100;
const int N = (int)1e5 + 100;
const int mod = (int)1e9 + 7;
 
#define inf mod
 
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;   
typedef vector<ll> Vll;               
typedef vector<pair<int, int> > vpii;
typedef vector<pair<ll, ll> > vpll;
 
int n, m, dp[maxn][maxn];
char a[maxn][maxn];
main () {
	cin >> n >> m;
	forn(i, 1, n)
		forn(j, 1, m)
			cin >> a[i][j];
	forn(i, 1, n)
		forn(j, 1, m){
			if(a[i][j] == '#') continue;
			if(i == 1 && j == 1) dp[i][j] = 1;
			else if(i == 1) dp[i][j] = dp[i][j - 1];
			else if(j == 1) dp[i][j] = dp[i - 1][j];
			else
				dp[i][j] = (dp[i - 1][j] + dp[i][j - 1]) % mod;
		}
	cout << dp[n][m];
}

Measured memory_bytes: 30976
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cfloat>
#include <ctime>
#include <cassert>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <numeric>
#include <list>


using namespace std;

#ifdef _MSC_VER
#define __typeof__ decltype
template <class T> int __builtin_popcount(T n) { return n ? 1 + __builtin_popcount(n & (n - 1)) : 0; }
#endif

#define foreach(it, c) for (__typeof__((c).begin()) it=(c).begin(); it != (c).end(); ++it)
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define CLEAR(arr, val) memset(arr, val, sizeof(arr))

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

template <class T> void max_swap(T& a, const T& b) { a = max(a, b); }
template <class T> void min_swap(T& a, const T& b) { a = min(a, b); }

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

const double EPS = 1e-8;
const double PI = acos(-1.0);
const int dx[] = { 0, 1, 0, -1 };
const int dy[] = { 1, 0, -1, 0 };


struct Digit
{
	char c;
	int weight;
	bool forbid_zero, right_statement;
	Digit(char c, int w, bool r)
		: c(c), weight(w), right_statement(r) { }

	int comp_value() const
	{
		int res = weight;
		if (right_statement)
			++res;
		return res;
	}
};
bool operator<(const Digit& a, const Digit& b)
{
	return a.comp_value() < b.comp_value();
}
vector<Digit> create_digits(string s, bool right)
{
	reverse(all(s));
	vector<Digit> res;
	for (int i = 0, w = 1; i < s.size(); ++i, w *= 10)
		res.push_back(Digit(s[i], w, right));
	return res;
}
vector<Digit> digits;
int res;
bool forbid_zero[256];
int map_to_num[256];
bool used[10];

void dfs(int k, int left_sum, int right_sum, bool check)
{
	if (k == digits.size())
	{
		if (left_sum == right_sum)
			++res;
		return;
	}
	else if (check)
	{
		int mod = digits[k].weight;
		int fix_l = left_sum % mod;
		int fix_r = right_sum % mod;
		if (fix_l != fix_r)
			return;
	}

	Digit& d = digits[k];
	if (map_to_num[d.c] == -1)
	{
		for (int i = forbid_zero[d.c] ? 1 : 0; i < 10; ++i)
		{
			if (!used[i])
			{
				used[i] = true;
				map_to_num[d.c] = i;

				if (d.right_statement)
					dfs(k + 1, left_sum, right_sum + i * d.weight, true);
				else
					dfs(k + 1, left_sum + i * d.weight, right_sum, false);

				used[i] = false;
				map_to_num[d.c] = -1;
			}
		}
	}
	else
	{
		int num = map_to_num[d.c];

		if (d.right_statement)
			dfs(k + 1, left_sum, right_sum + num * d.weight, true);
		else
			dfs(k + 1, left_sum + num * d.weight, right_sum, false);
	}
}
int main()
{
	ios::sync_with_stdio(false);

	int n;
	while (cin >> n, n)
	{
		digits.clear();
		CLEAR(forbid_zero, 0);
		for (int i = 0; i < n; ++i)
		{
			string s;
			cin >> s;
			vector<Digit> d = create_digits(s, i + 1 == n);
			for (int j = 0; j < d.size(); ++j)
				digits.push_back(d[j]);
			if (s.size() > 1)
				forbid_zero[s[0]] = true;
		}
		sort(all(digits));

		CLEAR(map_to_num, -1);
		CLEAR(used, 0);
		res = 0;
		dfs(0, 0, 0, false);
		cout << res << endl;
	}
}

Measured memory_bytes: 920
#include <numeric>
#include<iostream>
#include<set>
#include<queue>
#include<vector>
#include<map>
#include<stack>
#include<algorithm>
#include <sstream>
#include<string.h>
#include <cmath>
#include <iomanip>
using namespace std;
#define inf 1000000007
#define int long long
#define rep(i,j,n) for(int i=j;i<n;++i)
typedef pair<int,int>  P;
string alph("abcdefghijklmnopqrstuvwxyz");
struct edge{int from,to,cost;};
vector<edge> G;
double pi = 3.141592653589793;
P sg[10];
int a[55],b[55];
int n,m;
int dp[55][55]={};//i番目までの数でj個選んだ状態のsum
int fi[305][305];
int h,w,d;

signed main(){
    cin>>h>>w>>d;
    P num[114514];
    rep(i,0,h)rep(j,0,w){
        cin>>fi[i][j];
        num[fi[i][j]].first=i,num[fi[i][j]].second=j;
    }
    int sum[114514];
    rep(i,0,d)sum[i]=0;
    rep(i,1,h*w+1-d){
        sum[i+d]=sum[i]+abs(num[i+d].first-num[i].first)+abs(num[i+d].second-num[i].second);
    }
    int q;cin>>q;
    rep(i,0,q){
        int l,r;cin>>l>>r;
        cout<<sum[r]-sum[l]<<endl;
    }
    return 0;
}


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

int main() {
    int N;
    int count = 0;

    cin >> N;
    for (int i = 0; i < N; i++) {
        int l, r;
        cin >> l >> r;

        for (int j = l; j <= r; j++) {
            count++;
        }
    }
    cout << count << endl;
}

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

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

#define BE(x) x.begin(), x.end()

const llong inf = llong(1e18)+7;
const llong mod = 1e9+7;

int main(){
	string a,b;
	cin >> a >> b;
	if(a.size() > b.size())
		cout << "GREATER" << endl;
	else if(a.size() < b.size())
		cout << "LESS" << endl;
	else{
		bool same = true;
		for(int i = 0; i < (int)a.size(); i++){
			if(a[i] < b[i]){
				same = false;
				cout << "LESS" << endl;
				break;
			}else if(a[i] > b[i]){
				same = false;
				cout << "GREATER" << endl;
				break;
			}
		}
		if(same)
			cout << "EQUAL" << endl;
	}

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define lint long long
#define inf 100000000000000000
#define mod 1000000007
#define MAX 100005
#define pb push_back
#define vit vector<int>::iterator
typedef pair<int,int> pii;
map<int,int>M;
vector<int> V[MAX];
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin>>n;
    if(n>=400 && n<600) cout<<8;
    else if(n>=600 && n<800) cout<<7;
    else if(n>=800 && n<1000) cout<<6;
    else if(n>=1000 && n<1200) cout<<5;
    else if(n>=1200 && n<1400) cout<<4;
    else if(n>=1400 && n<1600) cout<<3;
    else if(n>=1600 && n<1800) cout<<2;
    else if(n>=1800 && n<2000) cout<<1;

    return 0;
}


Measured memory_bytes: 5932
#define _GLIBCXX_DEBUG

#include <algorithm>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map> //pair is also included in this library
#include <stack>
#include <string>
#include <vector>

#define INF (INT_MAX/3)

#define REP(i,s,n) for(int i = (int)(s); i < (int)(n); i++)

using namespace std;

typedef long long int ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef pair<int, int> PII;

ll solve(int N, int A, VI v){
  ll ans = 0;

  vector<vector<VL>> dp(N+1, vector<VL>(N+1, VL(N * A + 1)));

  REP(i, 0, N+1){
    REP(j, 0, N+1){
      REP(k, 0, N * A + 1){
        if(j == 0 && k == 0){
          dp[i][0][0] = 1;
        } else if(v[i] > k && j > 0){
          dp[i][j][k] = dp[i-1][j][k];
        } else if(v[i] <= k && i > 0 && j > 0){
          dp[i][j][k] = dp[i-1][j][k] + dp[i-1][j-1][k-v[i]];
        } else {
          dp[i][j][k] = 0;
        }
      }
    }
  }
  
  REP(i, 1, N+1){
    ans += dp[N][i][i*A];
  }

  return ans;
}

int main(){
  int N, A;

  cin >> N >> A;

  VI v(N+1);
  v[0] = 0;

  // int i = 1;
  // while(cin >> v[i]){
  //   i++;
  // }
  REP(i, 1, N+1){
    cin >> v[i];
  }

  ll ans = solve(N, A, v);

  cout << ans << endl;

  return 0;
}


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

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            //[summary]A - Buying Sweets
            var lines = ReadLines(3);
            int x = lines[0];
            int a = lines[1];
            int b = lines[2];

            Console.WriteLine((x - a) % b);
        }

        static List<int> ReadLines(int count = 0)
        {
            //[summary]コンソールの値を読み込む
            var numbers = new List<int>();

            //読み込む行数が未指定のときは、1行目の値を"count"とみなす
            if (count == 0)
            {
                string s = Console.ReadLine().TrimEnd();
                count = int.Parse(s);
            }

            for (int i = 0; i < count; i++)
            {
                string s = Console.ReadLine().TrimEnd();
                numbers.Add(int.Parse(s));
            }

            return numbers;
        }
    }
}

Measured memory_bytes: 13140
#include <iostream>

using namespace std;

int main()
{
	char masu[4];
	int i;
	int ball = 0;
	
	cin >> masu;
	
	
	for (i = 0; i < 3; i++){
		if (masu[i] == '1'){
			ball++;
		}
	}
	
	cout << ball << "\n";
	
	return (0);
}


Measured memory_bytes: 256
#include <iostream>
#include <queue>
#include <algorithm>
#include <string>
#include <utility>
#include <vector>
#include <map>
#include <stack>
#include <iomanip>
#include <set>
#include <sstream>
#include <cmath>
#include <deque>
#include <list>
#include <bitset>
using namespace  std;
typedef pair<string, int> Psi;
typedef pair<long long , long long> P;
typedef long long int64;
typedef long long lint;
#define REP(i, n) for(int (i)=0; (i)<(n); ++i)
#define FOR(i, a, b) for(int (i)=(a); (i)<(b); ++i)
#define ALL(a) (a).begin(),(a).end()
#define PB push_back
#define FST first
#define SND second

signed main(){
    int N, M, C; cin >> N >> M >> C;
    vector<int> B(M);
    REP(i, M) cin >> B[i];
    int cnt = 0;
    REP(i, N){
        int tmpTotal = 0; 
        REP(j, M){
            int a; cin >> a;
            tmpTotal += a*B[j];
        }
        if(tmpTotal+C>0) cnt++;
    } 
    cout << cnt << endl;
    return 0;

}

Measured memory_bytes: 256
#!/usr/bin/env python3


def read_h(typ=int):
    return list(map(typ, input().split()))


def read_v(n, m=1, typ=int):
    return [read_h() if m > 1 else typ(input()) for _ in range(n)]


def main():
    L, R = read_h()

    ans = 3000
    for di in range(R - L + 1 if R - L < 2019 else 2019):
        i = L + di
        for dj in range(1, R - i + 1 if R - i < 2019 else 2019):
            j = i + dj
            ans = min(ans, ((i % 2019) * (j % 2019)) % 2019)

    print(ans)


if __name__ == '__main__':
    main()


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

// @author: pashka

int main() {
    ios::sync_with_stdio(false);

    string s;
    cin >> s;
    s = "0" + s;
    int n = s.size();
    vector<int> d = {0, INT_MAX};
    for (int i = n - 1; i >= 0; i--) {
        vector<int> dd = {INT_MAX, INT_MAX};
        int z = s[i] - '0';
        for (int j = 0; j < 2; j++) {
            if (d[j] == INT_MAX) continue;
            for (int x = 0; x < 10; x++) {
                // x - y - j (+10?) = z
                int y = (x - j - z + 10) % 10;
                int jj = (x - j - y) < 0;
                dd[jj] = min(dd[jj], d[j] + x + y);                
            }
        }
        d = dd;
    }
    cout << d[0];   

    return 0;
}

Measured memory_bytes: 2332
import itertools
n = int(input())
l = [i for i in range(1,n+1)]
p = tuple(map(int,input().split()))
q = tuple(map(int,input().split()))
d = list(itertools.permutations(l, n))
p_ind = 0
q_ind = 0
for i in range(len(d)):
  if p == d[i]:
    p_ind = i
  if q == d[i]:
    q_ind = i
print(abs(p_ind-q_ind))

Measured memory_bytes: 13948
#include<stdio.h>
#include<stdbool.h>
#include<math.h>
bool IsPrime(int num){
  int i;
  double sqrtNum;
  sqrtNum= sqrt(num);
  if (num < 2) return false;
  else if (num == 2) return true;
  else if (num % 2 == 0) return false;

  for (i = 3; i <= sqrtNum; i += 2){
    if (num % i == 0)
      return false;
  }
  return true;
}
int main(){
  int n,k,i,count=0;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&k);
    if(IsPrime(k))count++;
    
  }
  printf("%d\n",count);
  return 0;
  
}

Measured memory_bytes: 596
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
using namespace std;

int S[1000],top;

void push(int x){
	top++;
	S[top]=x;
}

int pop(){
	top--;
	return S[top+1];
}

int main(){
	int a,b;
	top=0;
	char s[100];
	
	while(scanf("%s",s)!=EOF){
		if(s[0]=='+'){
			a=pop();
			b=pop();
			push(a+b);
		}else if(s[0]=='-'){
			a=pop();
			b=pop();
			push(b-a);
		}else if(s[0]=='*'){
			a=pop();
			b=pop();
			push(a*b);
		}else{
			push(atoi(s));
		}
	}
	
	printf("%d\n",pop());
	
	return 0;
}



Measured memory_bytes: 2752
#include <stdio.h>
#include <iostream>
#include <math.h>
#include <algorithm>
using namespace std;

int main()
{
	
	// 係数行列
	double A[2][2];
	
	// 定数ベクトル
	double  B[2];
	
	// 解ベクトル
	double x[2];
	
	
	double a, b, c, d, e, f;
	// 入力の最後まで処理する
	while(cin >> a >> b >> c >> d >> e >> f){
	A[0][0] = a;
	A[0][1] = b;
	A[1][0] = d;
	A[1][1] = e;
	
	B[0] = c;
	B[1] = f;
	
	
	
	int i,j,k;
	double tmp;
	
	// 前進消去
	for(i=0;i<1;i++){
		for(j=i+1;j<2;j++){
			for(k=i+1;k<2;k++){
				A[j][k] = A[j][k] - (A[j][i]/A[i][i])*A[i][k];
			}
			B[j] = B[j] - (A[j][i]/A[i][i])*B[i];
		}
	}
	
	// 後退代入
	for(i=1;i>=0;i--){
		tmp = B[i];
		for(j=i+1;j<2;j++){
			tmp = tmp - A[i][j]*x[j];
		}
		x[i] = tmp/A[i][i];
	}
	
	printf("%.3f %.3f\n", x[0], x[1]);
	
	}
	
	return 0;
}

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

string a;
long long l, c[30], ans;

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cin >> a;
	l = a.size();
	for(int i=0; i<l; ++i)
		++c[a[i]-'a'];
	ans = l * (l - 1) / 2;
	for(int i=0; i<26; ++i)
		ans -= c[i] * (c[i] - 1) / 2;
	cout << 1 + ans << "\n";
}

Measured memory_bytes: 720
#include <bits/stdc++.h>
#define FOR(i, m, n) for (ll i = m; i < (n); i++)
#define RFOR(i, m, n) for (ll i = (m - 1); i >= 0; i--)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) RFOR(i, n, 0)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
#define print(ele) cout << (ele) << "\n"
#define print10(ele) cout << fixed << setprecision(10) << (ele) << "\n"

using namespace std;
typedef long long ll;
typedef vector<int> ivec;
typedef vector<string> svec;
typedef vector<ll> lvec;

const int mod = 1e9 + 7;
const ll INF = 1000000000000000000LL;

int main() {
  ll n, k;
  cin >> n >> k;
  if (n == k) {
    print(0);
  } else {
    ll ans = n % k;
    ans = min(ans, abs(ans - k));
    print(ans);
  }
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define ALL(v) (v).begin(), (v).end()
using ll = long long;
using P = pair<int, int>;
constexpr int INF = 1e9;
constexpr long long LINF = 1e18;
constexpr long long MOD = 1e9 + 7;

signed main() {
    int n;
    cin >> n;
    int m = n % 10;
    if (m == 2 || m == 4 || m == 5 || m == 7 || m == 9){
        cout << "hon" << endl;
    }else if(m == 3){
        cout << "bon" << endl;
    }else{
        cout << "pon" << endl;
    }
    return 0;
}

Measured memory_bytes: 3580
#include <bits/stdc++.h>
#include <string>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <numeric>
using namespace std;


int main(){
  vector<int> task(3);
  cin >> task.at(0) >> task.at(1) >> task.at(2);
  sort(task.begin(),task.end());
  cout << 0 + task.at(1)-task.at(0) + task.at(2) - task.at(1) << endl;

}

Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<vector>
#include<cmath>
#include<queue>
#include<string.h>
#include<map>
#include<set>
#include<algorithm>
#define pi pair < long long,long long >
#define mp(a,b) make_pair(a,b)
#define rep(i,a,b) for(int i = a;i < b;i++)

using namespace std;

long long t1,t2,a1,a2,b1,b2;

int main()
{
    ios_base::sync_with_stdio(false);

    cin >> t1 >> t2;
    cin >> a1 >> a2;
    cin >> b1 >> b2;

    if(a1 < b1 && a2 < b2)
        cout << 0;
    else if(a1 > b1 && a2 > b2)
        cout << 0;
    else
    {
        if(a1 < b1)
        {
            long long tmp = a1;
            a1 = b1;
            b1 = tmp;

            tmp = a2;
            a2=b2;
            b2=tmp;
        }

        long long d = (b1-a1)*t1+(b2-a2)*t2;

        if(d < 0)
        {
            cout << 0;
        }
        else if(d==0)
        {
            cout<<"infinity";
        }
        else
        {
            long long k = ((a1-b1)*t1)/d;

            while(k*d+b1*t1 < a1*t1)
                k++;
            while((k-1)*d+b1*t1>=a1*t1)
                k--;

            long long ans = 2*k-1;

            if(k*d+b1*t1==a1*t1)
                ans++;

            cout << ans;
        }
    }

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<cmath>
#include<algorithm>
using namespace std;
using ll = long long;

ll gcd(ll a, ll b)
{
    if (a < b) {
        a ^= b;
        b ^= a;
        a ^= b;
    }
    
    return b ? gcd(b, a % b) : a;
}

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

int main(){
    ll a,b,c,d,xc,xd,yc,yd,za,zb;
    cin >> a >> b >> c >> d;
    xc = (a-1)/c;
    xd = (a-1)/d;
    yc = b/c;
    yd = b/d;
    za = (a-1)/lcm(c,d);
    zb = b/lcm(c,d);
    cout << (b-a+1)-((yc+yd)-(xc+xd)-(zb-za)) << endl;
    return 0;
}


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

int main() {
    int N;
    while (cin >> N, N) {
        bool ok = false;
        int k, cnt = 0;
        for (int i=0; i<N; ++i) {
            cin >> k;
            if (0 < k) cnt ++;
            if (2 <= k) ok = true;
        }
        if ( ! ok) {
            cout << "NA" << endl;
        } else {
            cout << cnt + 1 << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h> 
#define FOR(i,a,b) for(int i=(a);i<=(b);++i) 
#define RFOR(i,a,b) for(int i=(a);i>=(b);--i) 
#define REP(i,n) for(int i=0;i<(n);++i)
#define RREP(i,n) for(int i=(n);i>0;--i)
#define CI cin>> 
#define CO cout<<
#define EN <<endl 
#define all(x) (x).begin(),(x).end() 
#define asn ans
using namespace std;
template <typename T> istream& operator >> (istream& is, vector<T>& vec) { for (T& x : vec) is >> x; 	return is; }
using ll = long long;

int main() {
	int a; CI a;
	int ans = 0;
	int tmp = a;

	while (tmp) {
		ans += tmp % 10;
		tmp /= 10;
	}
	if (a%ans) {
		CO "No" EN;
	}
	else {
		CO "Yes" EN;
	}

	return 0;
}

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

const string YES = "Yes";
const string NO = "No";
int main(){
  int N, M; cin >> N >> M;
  int sum = 0;
  vector<int> A(N);
  rep(i, N) {
    cin >> A[i];
    sum += A[i];
  }

  int cnt = 0;

  rep(i, N) {
    if (A[i] * 4 * M >= sum) cnt++;
  }

  if (cnt >= M) cout << YES << endl;
  else cout << NO << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iostream>
#include <iomanip>
#include <numeric>
#include <math.h>
#include <stdio.h>
#include <climits>
#include <cfloat>
#include <string>
#include <unordered_map>
using namespace std;

int main(){
	string s;
	cin >> s;
	if(s.at(2) == s.at(3) && s.at(4) == s.at(5)){
		cout << "Yes" << endl;
	}else{
		cout << "No" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
package main

import "fmt"

func main() {
	var N, M, Q int
	fmt.Scan(&N, &M, &Q)

	sum := [501][501]int{}
	var l, r int
	for i := 0; i < M; i++ {
		fmt.Scan(&l, &r)
		sum[l][r]++
	}

	for i := 0; i < N; i++ {
		for j := 0; j < N; j++ {
			sum[i+1][j+1] += sum[i+1][j] + sum[i][j+1] - sum[i][j]
		}
	}

	var p, q int
	for i := 0; i < Q; i++ {
		fmt.Scan(&p, &q)
		p--
		ans := sum[q][q] - sum[q][p] - sum[p][q] + sum[p][p]
		fmt.Println(ans)
	}
}


Measured memory_bytes: 8192
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#include <unordered_map>
//#include"testlib.h"
#define endl "\n"
#define all(v) v.begin(),v.end()
#define allr(s) s.rbegin(),s.rend()
#define RT(s) return cout<<s,0
#define watch(x) cout << (#x)<<" = "<<x<<endl
#define sz(s)    (int)(s.size())
#define PI acos(-1)
#define EPS 1e-8
using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
int dy[] = { 1, -1, 0, 0, -1, 1, 1, -1 };
int dx[] = { 0, 0, 1, -1, 1, -1, 1, -1 };
void file() {
#ifndef ONLINE_JUDGE
	freopen("in.txt", "r", stdin);
	//freopen("out.txt", "w", stdout);
#else
	//freopen("street.in", "r", stdin);
	//freopen("out.txt", "w", stdout);
#endif
}
void fast() {
	std::ios_base::sync_with_stdio(0);
	cin.tie(NULL);
}

int main() {
	//file();
	fast();
	int x, n; cin >> x >> n;
	vi v1(n);
	for (auto& it : v1)
		cin >> it;
	sort(all(v1));
	int mn = INT_MAX;
	int h1 = INT_MAX;
	for (int i = -109; i <= 109; i++) {
		if (binary_search(all(v1), i)) continue;
		if (abs(i - x) < mn)
			h1 = i, mn = abs(i - x);
		else if (i < h1)
			h1 = i;
	}
	cout << h1 << endl;
	return 0;
}

Measured memory_bytes: 3656
#include<stdio.h>
int main(void)
{
	char a,b;
	scanf("%c %c",&a,&b);
	if(a=='H') {
		printf("%c\n",b);
	}
	if(a=='D') {
		if(b=='H') {
			printf("D\n");
		}
		if(b=='D') {
			printf("H\n");
		}
	}
	return 0;
}

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

using namespace std;

int main()
{
    int i,j,n,m,t;
    string x,y;

    cin>>x>>y;
    n = x.length();
    m = y.length();

    int dp[n+1][m+1];
    for(i=0;i <= n;i++)
    {
        for(j=0;j <= m;j++)
        {
            if(i==0 || j == 0)
            {
                dp[i][j] = 0;
                continue;
            }

            if(x[i-1] == y[j-1])
            {
                dp[i][j] = dp[i-1][j-1]+1;
            }
            else
            {
                dp[i][j] = max(dp[i-1][j],dp[i][j-1]);
            }
        }
    }

    int co = dp[n][m];
    char k[co];
    i = n,j = m;
    int ind = 0;

    while(i > 0 && j > 0)
    {
        if(dp[i][j] == dp[i-1][j-1]+1 && (x[i-1] == y[j-1]))
        {
            k[ind] = x[i-1];
            ind++;
            i--;
            j--;
        }
        else if(dp[i-1][j] > dp[i][j-1])
        {
            i--;
        }
        else
            j--;
    }

    for(i=co-1;i >= 0;i--)
    {
        cout<<k[i];
    }

    return 0;
}


Measured memory_bytes: 35456
#pragma warning disable

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.Serialization.Formatters.Binary;
using System.Text;
using System.Text.RegularExpressions;
using System.Diagnostics;
using System.Numerics;
using System.Collections;

static class MainClass
{
    public static void Main(string[] args)
    {


        var N = Console.ReadLine().ToInt32();
        var H = Console.ReadLine().ToInt32();
        var W = Console.ReadLine().ToInt32();
        Console.WriteLine((N - H + 1)*(N - W + 1));

        Console.ReadLine();
    }
   

    #region ライブラリ
    public static long ToInt64(this string str) => long.Parse(str);
    public static int ToInt32(this string str) => int.Parse(str);
    public static BigInteger ToBigInteger(this string str) => BigInteger.Parse(str);
    public static List<string> SplittedStringToList(this string str) => str.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).ToList();
    public static List<int> SplittedStringToInt32List(this string str) => str.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).Select(x => int.Parse(x)).ToList();
    public static List<long> SplittedStringToInt64List(this string str) => str.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).Select(x => long.Parse(x)).ToList();
    public static List<BigInteger> SplittedStringToBigInteger(this string str) => str.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).Select(x => BigInteger.Parse(x)).ToList();
    public const int INF = int.MaxValue / 2;
    public const long LONGINF = long.MaxValue / 2;

    public static int Max(params int[] values)
    {
        var maxes = -1;
        for (int i = 0; i < values.Length; i++)
        {
            maxes = Math.Max(values[i], maxes);
        }
        return maxes;
    }

    #endregion
}



Measured memory_bytes: 13140
#include <bits/stdc++.h>
using namespace std;
int main () {
    int c[9];
    for (int i = 0; i < 9; i++) {
        cin >> c[i];
    }
    set<vector<int>> s;
    for (int i = 0; i < 3; i++) {
        vector<int> v;
        for (int j = 3+i; j < 9; j += 3) {
            v.push_back(c[j]-c[j-3]);
        }
        s.insert(v);
    }
    if (s.size() == 1) {
        puts("Yes");
    }
    else {
        puts("No");
    }
}

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

int main()
{
    ll N,K;
    cin >> N >> K;

    map<ll,ll> mp;
    for(int i = 0; i < N; i++)
    {
        ll lltmp;
        cin >> lltmp;
        mp[lltmp]++;
    }
    
    vector<ll> B;

    for(auto e:mp)
    {
        B.push_back(e.second);
    }

    sort(B.begin(),B.end());
    int count = 0;
    ll dif = B.size() - K;
    int i = 0;

    while(dif > 0)
    {
        dif--;
        count += B.at(i);
        i++;
        
    }

    cout << count << endl;

    return 0;

}

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

#define rep(i,x,y) for(int i=(x);i<(y);++i)
#define debug(x) #x << "=" << (x)

#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define dump(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define dump(x)
#endif

typedef long long int ll;
typedef pair<int,int> pii;
//template<typename T> using vec=std::vector<T>;

const int inf=1<<30;
const long long int infll=1LL<<58;
const double eps=1e-9;
const int dx[]={1,0,-1,0},dy[]={0,1,0,-1};

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){
    os << "[";
    for (const auto &v : vec) {
    	os << v << ",";
    }
    os << "]";
    return os;
}

void solve(){
    const int idx1[]={0,4,5,1,3,7,6,2};
    const int idx2[]={0,3,7,4,1,2,6,5};
    auto equal=[&](const vector<int>& x,const vector<int>& y){
        auto equal_=[](const vector<int> &a,vector<int> b){
            auto equal__=[&]{
                rep(i,0,4){
                    bool ok=true;
                    rep(j,0,4) if(a[j]!=b[(i+j)%4] or a[4+j]!=b[(4+i+j>=8?i+j:4+i+j)]){
                        ok=false;
                        break;
                    }
                    if(ok) return true;
                }
                return false;
            };
            if(equal__()) return true;
            reverse(b.begin(),b.end());
            return equal__();
        };
        if(equal_(x,y)) return true;
        vector<int> tmp(8);
        rep(i,0,8) tmp[i]=y[idx1[i]];
        if(equal_(x,tmp)) return true;
        rep(i,0,8) tmp[i]=y[idx2[i]];
        return equal_(x,tmp);
    };
    string tmp;
    while(cin >> tmp){
        vector<string> color(8);
        color[0]=tmp;
        rep(i,1,8) cin >> color[i];

        map<string,int> mp;
        int cnt=0;
        rep(i,0,8) if(mp.find(color[i])==mp.end()){
            mp[color[i]]=cnt;
            ++cnt;
        }
        vector<int> v(8);
        rep(i,0,8) v[i]=mp[color[i]];
        sort(v.begin(),v.end());

        vector<vector<int>> all;
        do{
            bool ok=true;
            for(const auto& a:all) if(equal(v,a)){
                ok=false;
                break;
            }
            if(ok) all.emplace_back(v);
        }while(next_permutation(v.begin(),v.end()));

        cout << all.size() << endl;
    }
}

int main(){
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);
    cout << fixed << setprecision(8);
    solve();
    return 0;
}

Measured memory_bytes: 3276
#include<iostream>
#include<vector>
#include<algorithm>
#include<map>

using namespace std;

int main(){
  for(int c=1,N;cin>>N,N;c++){
    if(c!=1){
      cout<<endl;
    }
    typedef map<int,map<int,map<int,int> > > G;
    G g[101];
    for(int i=0;i<5;i++){
      for(int j=0;j<5;j++){
	for(int k=0;k<5;k++){
	  char cl;
	  cin>>cl;
	  g[0][i][j][k]=cl-'0';
	}
      }
    }
    vector<int> ab[2];
    for(int i=0;i<2;i++){
      int M;
      cin>>M;
      ab[i].resize(M);
      for(int j=0;j<M;j++){
	cin>>ab[i][j];
      }
      sort(begin(ab[i]),end(ab[i]));
    }
    for(int i=0;i<N;i++){
      for(int j=0;j<5;j++){
	for(int k=0;k<5;k++){
	  for(int l=0;l<5;l++){
	    int s=-g[i][j][k][l];
	    for(int m=-1;m<=1;m++){
	      for(int n=-1;n<=1;n++){
		for(int o=-1;o<=1;o++){
		  s+=g[i][j+m][k+n][l+o];
		}
	      }
	    }
	    g[i+1][j][k][l]=binary_search(begin(ab[g[i][j][k][l]]),end(ab[g[i][j][k][l]]),s);
	  }
	}
      }
    }
    cout<<"Case "<<c<<':'<<endl;
    for(int i=0;i<5;i++){
      for(int j=0;j<5;j++){
	for(int k=0;k<5;k++){
	  cout<<g[N][i][j][k];
	}
	cout<<endl;
      }
      if(i!=4){
	cout<<endl;
      }
    }
  }
}

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

using namespace std;

#define pb push_back
#define mp make_pair
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
typedef long long LL;
typedef pair<int, int> PII;

int n, q;
int a[100001];
LL ans[100000];

int main() {
    ios_base::sync_with_stdio(false);
    cin >> n;
    LL sum = 0;
    forn(i, n) {
        int x;
        cin >> x;
        ++a[x];
        sum += x;
    }
    cin >> q;
    forn(i, q) {
        int b, c;
        cin >> b >> c;
        sum += LL(c - b) * a[b];
        a[c] += a[b];
        a[b] = 0;
        ans[i] = sum;
    }
    forn(i, q) {
        cout << ans[i] << '\n';
    }
    return 0;
}


Measured memory_bytes: 4748
from collections import deque

n = int(input())
A = list(map(int, input().split()))

if n == 2:
    print(max(A))
    exit()

A.sort()
B = A[::-1]
point = deque()
point.append(B[0])
ans = 0
for i in range(1, n):
    ans += point.popleft()
    point.append(B[i])
    point.append(B[i])
print(ans)


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

int main(){
    int h,w;
    cin >> h >> w;
    while(h!=0&&w!=0){
        int i,j;
        for(i=0;i<h;i++){
            for (j=0;j<w;j++){
                cout << "#";
            }
        cout << endl;
        }
    cout << endl;
    cin >> h >> w;
    }
    return 0;
}






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

int main() {
  string s;
  cin >> s;
  for(int i=0; i<s.size(); i++) {
    if(i%2 == 0) {
      if(s[i]=='L') {
        cout << "No" << endl;
        return 0;
      }
    }
     else {
      if(s[i]=='R') {
        cout << "No" << endl;
        return 0;
      }
    }
  }
  cout << "Yes" << endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class Main {

    /*
     * https://atcoder.jp/contests/abc164/tasks/abc164_c
     */

    public static void main(String[] args) {

        Scanner stdIn = new Scanner(System.in);
        int jogen = Integer.parseInt(stdIn.nextLine());

        Set<String> gacha = new HashSet<>(jogen);
        for (int i = 0; i < jogen; i++) {
            gacha.add(stdIn.nextLine());
        }
        stdIn.close();

        System.out.println(gacha.size());

    }
}

Measured memory_bytes: 70960
#include<bits/stdc++.h>
using namespace std;
#define mkp make_pair
typedef long long ll;
typedef pair<ll,ll> P;
int main()
{
	ll n,m,q;
	cin>>n>>m>>q;
	vector<int> A,B,C,D;
	for(int i=0;i<q;i++)
	{
		int a,b,c,d;
		cin>>a>>b>>c>>d;
		a--;
		b--; 
		A.push_back(a);
		B.push_back(b);
		C.push_back(c);
		D.push_back(d);
	}
	int ma = -1234;
	for(int a=1;a<=m;a++)
		for(int b=a;b<=m;b++)
			for(int c=b;c<=m;c++)
			for(int d=c;d<=m;d++)
			for(int e=d;e<=m;e++)
			for(int f=e;f<=m;f++)
			for(int g=f;g<=m;g++)
			for(int h=g;h<=m;h++)
			for(int i=h;i<=m;i++)
			for(int j=i;j<=m;j++)
			{
				vector<int> now;
				int by = n;
				int all[10] = {a,b,c,d,e,f,g,h,i,j};
				while(by>0)
					now.push_back(all[10-by]) , by--;
				int sum = 0;
				for(int pos = 0;pos<q;pos++)
				{
					ll tmp = now[pos];
					ll p1,p2;
					p1 = now[A[pos]];
					p2 = now[B[pos]];
					if(p2-p1 == C[pos])
						sum+=D[pos]; 
				}
				ma = max(ma,sum);
			}
	cout<<ma<<endl;
	return 0; 
}

Measured memory_bytes: 3640
import java.util.*;
public class Main
{
    static int dp[][];
    static String longest;
    public static int lcs(String s,String t,int index1,int index2)
    {
        if(index1>=s.length())return 0;
        if(index2>=t.length())return 0;
        if(dp[index1][index2]!=-1)return dp[index1][index2];
        int temp1=0,temp2=0;
        if(s.charAt(index1)==t.charAt(index2)) temp1=1+lcs(s,t,index1+1,index2+1);
        else
        {
          temp1=lcs(s,t,index1+1,index2);
          temp2=lcs(s,t,index1,index2+1);
        }
        return dp[index1][index2]=Math.max(temp1,temp2);
    }
	public static void main(String[] args) {
		Scanner kb=new Scanner(System.in);
		String s=kb.next();
		String t=kb.next();
		dp=new int[s.length()][t.length()];
		longest="";
		for(int i=0;i<dp.length;i++)
		for(int j=0;j<dp[i].length;j++)
		dp[i][j]=-1;
		lcs(s,t,0,0);
// 		for(int i=0;i<dp.length;i++)
// 		{
// 		for(int j=0;j<dp[i].length;j++)
// 		System.out.print(dp[i][j]+" ");
// 		System.out.println();
// 		}
		
		int i=0,j=0;
		StringBuilder ans=new StringBuilder();
		while(i<s.length() && j<t.length())
		{
		    if(s.charAt(i)==t.charAt(j))
		    {
		        ans.append(Character.toString(s.charAt(i)));
		        i++;j++;
		    }
		    else 
		    {
		        if((i+1)<s.length() && (j+1)<t.length())
		        {
		           if(dp[i+1][j]>dp[i][j+1]){i++;}
		           else j++;
		        }
		        else if((i+1)<s.length())i++;
		        else if((j+1)<t.length())j++;
		        else break;
		    }
		}
		System.out.println(ans);
	}
}


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

class Main{
    public static void main(String[] args){
	BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
	String line;
	int energy,x,y,z,conse;
	int barrier,maxb=1000000;
	try{
	    while(0!=(energy=Integer.valueOf(br.readLine()))){
		conse = energy;
		if(Math.pow(z=(int)Math.cbrt(energy),3.0)<=energy&&z>1.0){
		    energy-=(z*z*z);
		    barrier = z;

		}else {
		    z = 0;
		    barrier = 0;
		}
		do{
		    if(Math.pow(y=(int)Math.sqrt(energy),2.0)<=energy&&y>1.0){
			energy-=(y*y);
		    }else y = 0;
		    x = energy;
		    barrier = x+y+z;
		    if(barrier<maxb){
			maxb = barrier;
		    }
		    z--;
		    energy = conse-(z*z*z);
		}while(z>=0);
		System.out.println(Integer.toString(maxb));
		maxb = 1000000;
	    }
	}
	catch(Exception e){
	    System.exit(0);
	}
    }
}

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

#define REP(i,n) for(ll i=0;i<ll(n);++i)
#define RREP(i,n) for(ll i=ll(n)-1;i>=0;--i)
#define FOR(i,m,n) for(ll i=m;i<ll(n);++i)
#define RFOR(i,m,n) for(ll i=ll(n)-1;i>=ll(m);--i)
#define ALL(v) (v).begin(),(v).end()
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());
#define INF 1000000001ll
#define MOD 1000000007ll
#define EPS 1e-9

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


using namespace std;

using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vvl = vector<vl>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

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

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	while (cin >> n, n) {
		vvi color(4);
		vi x(n), y(n), r(n), c(n);
		REP(i, n) {
			cin >> x[i] >> y[i] >> r[i] >> c[i];
			c[i]--;
			color[c[i]].push_back(i);
		}
		vi b(1 << n, 0);
		b[(1 << n) - 1] = 1;
		vvi g(n);
		vi d(n, 0);
		REP(i, n)FOR(j, i + 1, n) {
			if ((x[i] - x[j])*(x[i] - x[j]) + (y[i] - y[j])*(y[i] - y[j]) < (r[i] + r[j])*(r[i] + r[j])) {
				g[i].push_back(j);
				d[j]++;
			}
		}
		queue<int> q;
		q.push((1 << n) - 1);
		while (!q.empty()) {
			int bit = q.front(); q.pop();
		
			vi c = d;
			REP(i, n) {
				if ((bit&(1 << i)) == 0) {
					REP(j, g[i].size()) {
						c[g[i][j]]--;
					}
				}
			}
			REP(k, 4)REP(i, color[k].size())FOR(j, i + 1, color[k].size()) {
				if ((bit&(1 << color[k][i])) && (bit&(1 << color[k][j]))&&c[color[k][i]]==0&&c[color[k][j]]==0) {
					if (b[bit ^ (1 << color[k][i]) ^ (1 << color[k][j])] == 0)q.push(bit ^ (1 << color[k][i]) ^ (1 << color[k][j]));
					b[bit ^ (1 << color[k][i]) ^ (1 << color[k][j])] = 1;

				}
			}
		}
		int ans = 0;
		REP(i, 1 << n) {
			if (b[i] == 0)continue;
			int cnt = n;
			REP(j, n)if (i&(1 << j))cnt--;
			chmax(ans, cnt);
		}
		cout << ans << endl;
	}
}


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

using namespace std;
using ll = long long;
using PII = std::pair<int, int>;
using PLL = std::pair<ll, ll>;

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


const int amax = 18;

struct node
{
    int custom;
    int depth;
    vector<int> ansestors;
    vector<int> childrens;
};

vector<node> nodes;

void dfs(int s, int d)
{
    nodes[s].depth = d;
    for (auto z : nodes[s].childrens)
        dfs(z, d + 1);
}

int back_to_ansestors(int s, int n)
{
    int m, c;
    c = 0;
    if (n == 0)
        return s;
    else
    {
        m = n;
        while (m > 0 && m % 2 == 0)
        {
            c++;
            m /= 2;
        }
        return back_to_ansestors(nodes[s].ansestors[c], n - pow(2, c));
    }
}

int lca(int a, int b)
{
    int dd, ok, ng, mid;

    dd = nodes[a].depth - nodes[b].depth;
    if (dd > 0)
        a = back_to_ansestors(a, dd);
    if (dd < 0)
        b = back_to_ansestors(b, abs(dd));
    if (a == b)
        return a;
    if (a == 0 || b == 0)
        return 0;

    while (nodes[a].ansestors[0] != nodes[b].ansestors[0])
    {
        for (int i = amax - 1; i > -1; i--)
        {
            if (nodes[a].ansestors[i] != nodes[b].ansestors[i])
            {
                a = nodes[a].ansestors[i];
                b = nodes[b].ansestors[i];
                break;
            }
        }
    }

    return nodes[a].ansestors[0];
}

int main()
{

#ifdef DEBUG
    cout << "DEBUG MODE" << endl;
    ifstream in("input.txt"); //for debug
    cin.rdbuf(in.rdbuf());    //for debug
#endif

    int n, k, c, q, a, b, da, db, dd, ca;
    cin >> n;
    vector<int> ainit, cinit;

    rep(i, n)
    {
        nodes.push_back((node){0, 0, ainit, cinit});
        rep(j, amax)
        {
            nodes[i].ansestors.push_back(-1);
        }
    }

    rep(i, n)
    {
        cin >> k;
        rep(j, k)
        {
            cin >> c;
            nodes[c].ansestors[0] = i;
            nodes[i].childrens.push_back(c);
        }
    }
    rep(j, amax - 1)
    {
        rep(i, n)
        {
            if (nodes[i].ansestors[j] != -1 && nodes[nodes[i].ansestors[j]].ansestors[j] != -1)
                nodes[i].ansestors[j + 1] = nodes[nodes[i].ansestors[j]].ansestors[j];
        }
    }

    dfs(0, 0);

    cin >> q;
    rep(i, q)
    {
        cin >> a >> b;
        cout << lca(a, b) << endl;
    }

    // rep(i, n)
    // {
    //     cout << nodes[i].depth << "\t";
    //     rep(j, amax)
    //     {

    //         cout << nodes[i].ansestors[j] << " ";
    //     }
    //     cout << endl;
    // }

    return 0;
}


Measured memory_bytes: 28544