akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <string>
#include <vector>
using namespace std;
typedef pair<int,int> pii;

int main(){
  int H, W;
  cin >> H >> W;
  string F[H];
  for(int i = 0; i < H; ++i){
    cin >> F[i];
  }
  int dx[] = {1,0,-1,0}, dy[] = {0,1,0,-1};
  pair<pii,pii> e[4];
  e[0] = make_pair(pii(1,0),pii(1,1));
  e[1] = make_pair(pii(0,1),pii(1,1));
  e[2] = make_pair(pii(0,0),pii(0,1));
  e[3] = make_pair(pii(0,0),pii(1,0));
  vector< pair<double,int> > A;//"#"?????°???N??¨????????¨2*N+2????????????????´???°
  for(int i = 0; i < H; ++i){
    for(int j = 0; j < W; ++j){
      if(F[i][j] == '#'){
	for(int k = 0; k < 4; ++k){
	  if(i+dx[k] < 0 || j+dy[k] < 0 || i+dx[k] > H-1 || j+dy[k] > W-1 || F[i+dx[k]][j+dy[k]] != '#'){
	    pii s = pii(H-i-e[k].first.first, j+e[k].first.second);
	    pii t = pii(H-i-e[k].second.first, j+e[k].second.second);
	    //printf("(%d, %d), (%d, %d)\n",s.first,s.second,t.first,t.second);
	    if(s.second && s.first)
	      A.push_back(make_pair((double)s.first/s.second, -1));
	    if(t.second && s.first)
	      A.push_back(make_pair((double)t.first/t.second, +1));
	  }
	}
      }
    }
  }
  sort(A.begin(),A.end());
  int ans = 0, t = 0;

  for(int i = 0; i < (int)A.size(); ++i){

    t += A[i].second;
    t = max(t,0);
    ans = max(t,ans);
  }

  cout << (ans+1)/2 + 1 << endl;
  return 0;
}

Measured memory_bytes: 19976
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <list>
#include <utility>
#include <tuple>
#include <cstdio>
#include <set>
#include <queue>
#include <stack>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cctype>
#include <cmath>
#define _GLIBCXX_DEBUG
using namespace std;
const long long INF = 1LL << 60;
typedef long long ll;
int main() {
    int N,M,X;
    cin >> N >> M >> X;
    //
    vector<int> A(M);
    vector<int> B(N+1);   // 料金を格納
    for(int i=0;i<=N;i++){
        B[i]=0;
    }
    for(int i=0;i<M;i++){
        cin >> A[i];
        B[A[i]]=1;
    }
    //
    vector<int> cost(N+1); 
    cost[X]=0;
    // to N
    for(int i=X+1;i<=N;i++){
        cost[i] = cost[i-1] + B[i];
    }
    // to 0
    for(int i=X-1;i>=0;i--){
        cost[i] = cost[i+1] + B[i];
    }
    int min_cost;
    min_cost = min(cost[0],cost[N]); 
    cout << min_cost << endl;
}

Measured memory_bytes: 3632
#pragma GCC optimize("O3") //コンパイラ最適化用

#define _GLIBCXX_DEBUG //配列に[]でアクセス時のエラー表示
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
// forループ関係
#define REP(i, n) for (ll i = 0; i < ll(n); i++)
#define REPD(i, n) for (ll i = n - 1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = a; i < ll(b); i++)
#define FORD(i, a, b) for (ll i = a; i > ll(b); i--)
// xにはvectorなどのコンテナ
#define ALL(x) x.begin(), x.end() // sortなどの引数を省略したい
#define SIZE(x) ll(x.size())      // sizeをsize_tからllに直しておく
//定数
#define INF 1000000000000 // 10^12:極めて大きい値,∞
const int MOD = 1000000007;
#define MAXR 100000 // 10^5:配列の最大のrange(素数列挙などで使用)
//略記
#define Umap unordered_map
#define Uset unordered_set
const unsigned int BIT_FLAG_0 = (1 << 0); // 0000 0000 0000 0001
const unsigned int BIT_FLAG_1 = (1 << 1); // 0000 0000 0000 0010
const unsigned int BIT_FLAG_2 = (1 << 2); // 0000 0000 0000 0100
const unsigned int BIT_FLAG_3 = (1 << 3); // 0000 0000 0000 1000
const unsigned int BIT_FLAG_4 = (1 << 4); // 0000 0000 0001 0000
const unsigned int BIT_FLAG_5 = (1 << 5); // 0000 0000 0010 0000
const unsigned int BIT_FLAG_6 = (1 << 6); // 0000 0000 0100 0000
const unsigned int BIT_FLAG_7 = (1 << 7); // 0000 0000 1000 0000
void add(long long &a, long long b) {
    a += b;
    if (a >= MOD)
        a -= MOD;
}
template <class T> inline bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template <class T> inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

int main() {

    int n, k;
    cin >> n >> k;
    if (n > k)
        cout << 0 << endl;
    else
        cout << 1 << endl;
}



Measured memory_bytes: 3104
#include <bits/stdc++.h>
using namespace std;
int main(void) {
  string s;
  cin >> s;
  for (int i = 0; i < s.size(); i++) {
    if (s[i] == 'C') {
      for (int j = i+1; j < s.size(); j++) {
        if (s[j] == 'F') {
          cout << "Yes" << endl;
          return 0;
        }
      }
    }
  }
  cout << "No" << endl;
}


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

int main() {
  int n;
	while(cin>>n)
	{
		if(n==25) printf("Christmas\n");
		else if(n==24) printf("Christmas Eve\n");
		else if(n==23) printf("Christmas Eve Eve\n");
		else if (n==22) printf("Christmas Eve Eve Eve\n");
	}
	return 0;
}

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

signed main()
{
    ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    
    //int t=1 ; cin>>t ; while(t--)
    {
        int n;
        cin >> n;
        int ans = 0;
        for(int i=1;i<=n;i++)
        {
            int x = i, c = 0;
            while(x)
            {
                x /= 10;
                c++;
            }
            ans += c % 2;
        }

        cout << ans << '\n';
    }
    
    cerr << "Time elapsed : " << 1.0 * clock() / CLOCKS_PER_SEC << " sec \n";
    return 0;
}



Measured memory_bytes: 512
#include <iostream>

int main()
{
  	char b;
  	std::cin >> b;

  	switch ( b )
    {
      case 'A': std::cout << 'T' << std::endl; break;
      case 'C': std::cout << 'G' << std::endl; break;
      case 'G': std::cout << 'C' << std::endl; break;
      case 'T': std::cout << 'A' << std::endl; break;
    }

  return ( 0 );
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define SZ(x) ((int)x.size())
using namespace std;
typedef long long ll;
typedef long double ld;
int n,t[100010],x[100010],y[100010];
int main() {
	scanf("%d", &n);
	x[0]=y[0]=1;
	bool r = 1;
	for(int i=1; i<=n; i++) {
		scanf("%d%d%d",t+i,x+i,y+i);
		int l = abs(x[i]-x[i-1])+abs(y[i]-y[i-1]);
		int d = t[i] - t[i-1];
		if(l > d || (l - d) % 2 != 0) r = 0;
	}
	puts(r ? "Yes" : "No");
	return 0;
}

Measured memory_bytes: 1408
s = str(input())
slist = list(s)
sum = 0
if 4 == len(slist):
    for i in range(len(slist)):
        if slist[i] == '+':
            sum += 1
        elif slist[i] == '-':
            sum -= 1
        else:
            print('hoge!')
            exit()
    print(sum)
else:
    print('hoge!')

Measured memory_bytes: 3064
from math import sqrt
n = int(input())

n_cnt = [0]*n

for x in range(1, int(sqrt(2*n))+1):
    for y in range(1, int(sqrt(2*n))+1):
        for z in range(1, int(sqrt(2*n))+1):
            t = (x+y)**2 + (y+z)**2 + (z+x)**2
            if t % 2 == 0 and t // 2 - 1 < n:
                n_cnt[t // 2 - 1] += 1


for i in range(n):
    print(n_cnt[i])

Measured memory_bytes: 69820
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <numeric>
#include <string>
#include <set>

using namespace std;

typedef long long ll;
const int INF = 1001001001;

class Index{
public:
    int x, y, z;
        
    Index(int _x, int _y, int _z){
        x = _x;
        y = _y;
        z = _z;
    }
        
    bool operator<(const Index& other) const{
        return x < other.x;
    }
};

typedef pair<ll, Index> P;

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

int main(){
    int X, Y, Z, K;
    cin >> X >> Y >> Z >> K;
    vector<ll> A(X), B(Y), C(Z);
    for(int i = 0; i < X; ++i){
        cin >> A[i];
    }
    for(int i = 0; i < Y; ++i){
        cin >> B[i];
    }
    for(int i = 0; i < Z; ++i){
        cin >> C[i];
    }
    sort(A.begin(), A.end(), greater<ll>());
    sort(B.begin(), B.end(), greater<ll>());
    sort(C.begin(), C.end(), greater<ll>());
    
    priority_queue<pair<ll, Index>> que;
    // bool used[1000][1000][1000]の役割
    // 配列で用意すると、1億要素になってグローバルにおけない(?)
    // ハッシュ値で管理する
    set<int> hash;
    
    Index index(0, 0, 0);
    que.push(make_pair(A[0] + B[0] + C[0], index));
    hash.insert(0);        // (=(0 << 20) | (0 << 10) | 0)
    int cnt = 0;
    
    while(cnt < K && !que.empty()){
        P p = que.top();
        que.pop();
        cout << p.first << endl;
        cnt++;
        
        Index id(p.second.x, p.second.y, p.second.z);
        
        for(int i = 0; i < 3; ++i){
            int nx = id.x + dx[i];
            int ny = id.y + dy[i];
            int nz = id.z + dz[i];
            if(nx >= X || ny >= Y || nz >= Z)      continue;
            
            int temp = (nx << 20) | (ny << 10) | nz;
            if(hash.find(temp) != hash.end())       continue;
            
            Index subst(nx, ny, nz);
            que.push(P(A[nx] + B[ny] + C[nz], subst));
            hash.insert(temp);
        }
    }
}

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

int main() {
  int N;
  cin >> N;
  string W[100];
  for (int i = 0; i < N; i++) {
    cin >> W[i];
  }
  for (int i = 0; i < N-1; i++) {
    for (int j = i+1; j < N; j++) {
      if(W[i] == W[j]) {
        cout << "No";
        exit(0);
      }
    }
  }
  for (int i = 0; i < N; i++) {
    if(i != 0) {
      if(W[i][0] != W[i-1][W[i-1].size()-1]) {
        cout <<"No";
        exit(0);
      }
    }
  }
  cout << "Yes";
}

Measured memory_bytes: 256
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;


public class C
{
	public static void Main()
	{
		string arg = Console.ReadLine();
		int N = Int32.Parse(arg);
		int maxD = arg.Length;
		int[] conv = new int[3]{3,5,7};
		
		int ans = 0;
		for(int d = 3; d <= maxD; d++)
		{
			for(int mask = 0; mask < Math.Pow(3,d); mask++)
			{
				int[] eachNum = new int[d];
				int flag = 0;  // 0-th:3, 1-st:5, 2-nd:7
				int tmp = mask;
				for(int i = 0; i < d; i++)
				{
					flag |= (1 << (tmp % 3));
					eachNum[i] = conv[tmp % 3];
					tmp /= 3;				
				}
				int num = 0;
				for(int i = d - 1; i >= 0; i--)
					num = num * 10 + eachNum[i];
			
				if(num > N)
					break;
				
				//if(flag == 0b111)
				if(flag == 7)
					ans++;
			}			
		}
		
		Console.WriteLine(ans);
	}	
}





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

#define FASTIO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define rep(i,a,b) for(int i=a; i<b; i++)
#define vi vector<int>
#define pb push_back
#define ll long long

int main()
{
    FASTIO
    int n;
    cin >> n;
    vector<string> v(n);
    rep(i,0,n) cin >> v[i];
    set<string> s(v.begin(), v.end());
    cout << s.size() << "\n";

    return 0;
}

Measured memory_bytes: 25112
# -*- coding: utf-8 -*-

n, a, b = map(int, input().split())
s = 0
ans = 0

def findSumOfDigits(num):
    s = 0
    while num > 0:
        s += int(num % 10)
        num  = int(num / 10)
    return s


for i in range(n + 1):
    s = findSumOfDigits(i)
    if a <= s <= b:
        ans += i
print(ans)


Measured memory_bytes: 9180
#include <bits/stdc++.h>
using namespace std;
struct fastio { fastio () { std::ios::sync_with_stdio(false); std::cin.tie(nullptr); } } _io;
template<class T, class U> bool chmax(T& a, const U &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T, class U> bool chmin(T& a, const U &b) { if (a > b) { a = b; return 1; } return 0; }

int main() {
	long long n;
	std::cin >> n;
	vector<long long> a(n);
	for (long long &e : a) cin >> e;
	a.erase(std::unique(a.begin(), a.end()), a.end());
	n = a.size();
	
	long long l = 0, r = n - 1;
	for (l = 0; l + 1 < n; l++) {
		if (a[l] < a[l + 1]) break;
	}
	for (r = n - 1; r > 0; r--) {
		if (a[r - 1] < a[r]) break;
	}
	
	long long kabu = 0, ans = 1000;
	
	auto buy = [&](long long i) {
		long long buff = ans / a[i];
		kabu += buff;
		ans -= (buff * a[i]);
	};
	auto sell = [&](long long i) {
		ans += a[i] * kabu;
		kabu = 0;
	};
	
	for (long long i = l; i <= r; i++) {
		if (i == r or (a[i - 1] < a[i] and a[i] > a[i + 1])) {
			sell(i);
		} else if (i == l or (a[i - 1] > a[i] and a[i] < a[i + 1])) {
			buy(i);
		}
	}
	
	std::cout << ans << '\n';
	return 0;
}

Measured memory_bytes: 3676
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
/*int main() {
	int N;
	int S;
	cin>> N;
	S = 800 * N - 200 * (N / 15);
	cout << S;
	return 0;
}*/
/*
int main() {

	int kai=0;
	int N;
	int A;
	int B;
	int a=0, b=0;
	cin >> N;
	cin >> A;
	cin >> B;
	for (int i = 1; i <=N; i++) {
		
			a = i % 10 + (i / 10) % 10 + (i / 100) % 10 + (i / 1000) % 10 + i / 10000;
			if (a >= A && a <=B ) {

				kai +=i  ;
	}
		}
	cout << kai;
}*/

int main() {
	string T;
	string S;
	cin >> S;
	cin >> T;
	int j = 0;
	int count_t=0;
	int count_s=0;
	int k = 0;
	int count=0;
	while (T[j]) {
		count_t++;
		j++;
	}
	j = 0;
	while (S[j]) {
		count_s++;
		j++;
	}



	for (int i = count_s-1; i >= 0; i--) {
	
			for (int j = 0; j < count_t; j++) {
				if (i + count_t > count_s) {

					break;
					
				}

				if (S[i + j] != T[j] && S[i + j] != '?') {
					break;
				}

				if (j+1 ==count_t) {
					for (int k = 0; k < count_t; k++) {
						S[i + k] = T[k];

					}
					count = 1;
					break;

				}
			}
			if (count == 1) { break; }
		
	}

	if (count == 1) {
		for (int i = 0; i < count_s; i++) {
			if (S[i] == '?') {
				S[i] = 'a';

			}
		}
		cout << S;
	}
	else {
		cout << "UNRESTORABLE";
	}
	
}



Measured memory_bytes: 256
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 6)

N = int(input())
a = [int(i) for i in input().split()]

b = []
for i in range(N - 1) :
  b.append(a[i] ^ a[(i + 1) % N])

x = 0
for i in range(0, N - 1, 2) :
  x ^= b[i]

ret = [a[-1] ^ x]
for c in b[::-1] :
  ret.append(c ^ ret[-1])

ret = ret[::-1]
print(*ret)

Measured memory_bytes: 124828
#include <iostream>
#include <string>
#include <array>
#include <algorithm>
#include <vector>
#include <string>
#include <set>
#include <cctype>
#include <map>
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <ctype.h>
#include <queue>


#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

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

using namespace std;

bool is_integer( float x ){
    return floor(x)==x;
}

bool is_prime(long long N) {
    if (N == 1) return false;
    for (long long i = 2; i * i <= N; ++i) {
        if (N % i == 0) return false;
    }
    return true;
}

//yakusuu rekkyo
vector<long long> enum_divisors(long long N) {
    vector<long long> res;
    for (long long i = 1; i * i <= N; ++i) {
        if (N % i == 0) {
            res.push_back(i);
            // push its partner
            if (N/i != i) res.push_back(N/i);
        }
    }

    sort(res.begin(), res.end());
    return res;
}


vector<pair<long long, long long> > prime_factorize(long long N) {
    vector<pair<long long, long long> > res;
    for (long long a = 2; a * a <= N; ++a) {
        if (N % a != 0) continue;
        long long ex = 0; // exponential

        // divide as much as you can
        while (N % a == 0) {
            ++ex;
            N /= a;
        }

        // push the result
        res.push_back({a, ex});
    }

    // last num (if the lasting n is prime number and not 1)
    if (N != 1) res.push_back({N, 1});
    return res;
}



int main() {
    ll n; cin >> n;
    ll ans = 0;
    ll tmp;
    rep(i,n){
        cin >> tmp;
        while(tmp%2 == 0){
            tmp /= 2;
            ans ++;
        }
    }
    cout << ans;

    return 0;
}











Measured memory_bytes: 3608
#include <iostream>

using namespace std;

int main() {
    unsigned long long a, b, c, k;
    long long s = 0;
    cin >> a >> b >> c >> k;
    if (k < a) {
        s = k;
    } else {
        s = a;
        k -= a;
        if (k > b) {
            k -= b;
            s -= k;
        }
    }
    cout << s;
    return 0;
}

Measured memory_bytes: 3636
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;
template<class S,class T> ostream& operator << (ostream& out,const pair<S,T>& o){ out << "(" << o.first << "," << o.second << ")"; return out; }
template<class T> ostream& operator << (ostream& out,const vector<T> V){ for(int i = 0; i < V.size(); i++){ out << V[i]; if(i!=V.size()-1) out << " ";} return out; }
template<class T> ostream& operator << (ostream& out,const vector<vector<T> > Mat){ for(int i = 0; i < Mat.size(); i++) { if(i != 0) out << endl; out << Mat[i];} return out; }
template<class S,class T> ostream& operator << (ostream& out,const map<S,T> mp){ out << "{ "; for(auto it = mp.begin(); it != mp.end(); it++){ out << it->first << ":" << it->second; if(mp.size()-1 != distance(mp.begin(),it)) out << ", "; } out << " }"; return out; }

/*
 <url:>
 問題文============================================================
 =================================================================
 解説=============================================================
 ================================================================
 */
ll solve(){
    ll res = 0;
    ll H,W; cin >> H >> W;
    vector<vector<ll>> M(H+2,vector<ll>(W+2,LINF));
    vector<pll> Section(H*W);
    for(int i = 1; i <= H;i++){
        for(int j = 1; j <= W;j++){
            ll x; cin >> x; x--;
            M[i][j] = x;
            Section[x] = {i,j};
        }
    }
    
    vector<vector<ll>> flag(H+2,vector<ll>(W+2,-1));
    int id = 0;
    int d[4] = {1,0,-1,0};
    for(int i = 0; i < H*W;i++){
        ll x,y; tie(x,y) = Section[i];
        
        vector<ll> F;
        for(int k = 0; k < 4;k++){
            ll nx = x + d[k];
            ll ny = y + d[k^1];
            if(M[nx][ny] < M[x][y]){
                if(flag[nx][ny] == INF){
                    F.push_back(INF); F.push_back(INF+1);
                }else{
                    F.push_back(flag[nx][ny]);
                }
            }
        }
        sort(F.begin(),F.end());
        F.erase(unique(F.begin(),F.end()),F.end());
        if(F.empty()){
            flag[x][y] = id++;
        }else if(F.size() == 1){
            flag[x][y] = F[0];
        }else{
            flag[x][y] = INF;
            res++;
        }

    }
    return res;
}
int main(void) {
    cin.tie(0); ios_base::sync_with_stdio(false);
    cout << solve() << endl;
    return 0;
}



Measured memory_bytes: 34284
#include <iostream>
#include <string>
#include <vector>
#include <climits>
#include <algorithm>
#include <set>
#include <unordered_map>
#include <queue>
#include <iomanip>
#include <map>

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

using namespace std;

int N;

int main() {
  cin >> N;
  vector<int> A(N);
  long ans = 0;
  long rem = 0;

  rep(i, N) {
    cin >> A.at(i);
    ans += (long)A.at(i)/2;
    int nowrem = A.at(i)%2;
    // rem = 1, nowrem = 1;
    if (rem + nowrem == 2) {
      ans++;
      rem = 0;
      continue;
    }
    if (A.at(i) == 0) {
      rem = 0;
      continue;
    }
    if (rem == 0) {
      rem = nowrem;
    }
  }
  cout << ans << endl;
}


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

int main() {
    int N, M;
    cin >> N >> M;
    int A[N];
    int sum = 0;
    for (int i = 0; i < N; ++i) {
        cin >> A[i];
        sum += A[i];
    }
    int cnt = 0;
    for (int i = 0; i < N; ++i) {
        if (A[i] < sum / (4.0 * M)) {
            continue; 
        }
        else {
            ++cnt;
        }
    }
    if (cnt >= M) cout << "Yes" << endl;
    else cout << "No" << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define ll long long
#define ull unsigned long long
#define F first
#define S second
#define eps 1e-6
#define mp make_pair
const long long INF=2*1e9+2;
const int MX=200003;
int N, M, k;
int arr[MX];
int main()
{
    map<string, int> an;
    string last;
    cin>>N;
    bool ok=0;
    for(int i=1;i<=N;i++)
    {
        string s;
        cin>>s;
        if(i == 1)
        {
            last=s;
            an[last]++;
            continue;
        }
        if(s[0] != last[last.size()-1])
        {
           ok=1;
//            return 0;
        }
        if(an.find(s) != an.end())
        {
            ok=1;
        }
        an[s]++;
        last=s;
    }
    if(ok)cout<<"No\n";
    else cout<<"Yes\n";
    return 0;
}


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

bool prime[1000001];
void is_prime(int n){
	for(int i = 0; i <= n; ++i)
		prime[i] = true;
	prime[0] = prime[1] = false;
	
	for(int i = 2; i <= n; ++i){
		if(prime[i]){
			for(int j = i * 2; j <= n; j += i)
				prime[j] = false;
		}
	}
}

bool DP[1000001];
int N, X;

int main() {
	is_prime(1000000);
	while(cin >> N >> X && (N || X)){
		int cook[50], ans = 0;
		memset(DP, 0, sizeof(DP));
		
		for(int i = 0; i < N; ++i){
			cin >> cook[i];
			DP[cook[i]] = true;
		}
		
		for(int i = 0; i < N; ++i){
			for(int j = 0; j <= X; ++j){
				if(DP[j] && j + cook[i] <= X)
					DP[j + cook[i]] = true;
			}
		}
			
		for(int i = 0; i <= X; ++i)
			if(DP[i] && prime[i])
				ans = i;
		if(ans == 0)
			cout << "NA" << endl;
		else
			cout << ans << endl;
	}
	
	
	return 0;
}

Measured memory_bytes: 3120
#include<bits/stdc++.h>
using namespace std;
 
#define rep(i, n) for (int i = 0; i < (n); i++)
 
int main(){
    int N,M,Q;
    cin >> N >> M >> Q;
    int R[N][N] = {};
    rep(i,M){
        int l,r;
        cin >> l >> r;
        l--,r--;
        R[l][r]++;
    }

    long long C[N+1][N+1] = {};
    rep(i,N){
        rep(j,N){
            C[i+1][j+1] = C[i+1][j] +  C[i][j+1] - C[i][j] + R[i][j];
        }
    }
    
    rep(i,Q){
        int p,q;
        cin >> p >> q;
        cout << C[q][q] - C[q][p-1] - C[p-1][q]  + C[p-1][p-1] << endl;
    }

    return 0;
}

Measured memory_bytes: 3840
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#endif

#include <bits/stdc++.h>

using namespace std;

mt19937 mrand(random_device{} ()); 

int rnd(int x) {
  return mrand() % x;
}

typedef long double ld;
typedef long long ll;

#ifdef DEBUG
#define eprintf(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
#else
#define eprintf(...) ;
#endif

#define pb push_back
#define mp make_pair
#define sz(x) ((int) (x).size())
#define TASK "text"

const int inf = (int) 1.01e9;
const ld eps = 1e-9;
const ld pi = acos((ld) -1.0);

const int mod = (int) 1e9 + 7;

void add(int &x, int y) {
  if ((x += y) >= mod) {
    x -= mod;
  }
}

int mult(int x, int y) {
  return (long long) x * y % mod;
}

int myPower(int x, int pw) {
  int res = 1;
  for (; pw; pw >>= 1) {
    if (pw & 1) {
      res = mult(res, x);
    }
    x = mult(x, x);
  }
  return res;
}

void precalc() {
}

const int maxn = (int) 5e5 + 10;
char s[maxn];

int n, q;

int read() {
  if (scanf("%s%d", s, &q) < 1) {
    return 0;
  }
  n = (int) strlen(s);
  return 1;
}

const int maxl = 20;
int pr[maxl][maxn];

const int maxc = 26;
int fin[maxc + 1][maxn];

void solve() {
  for (int c = 0; c <= maxc; ++c) {
    fin[c][n + 1] = n + 1;
  }
  pr[0][n + 1] = n + 1;
  for (int i = n; i >= 0; --i) {
    for (int c = 0; c <= maxc; ++c) {
      fin[c][i] = n + 1;
    }
    if (i == n) {
      fin[maxc][i] = i;
    } else {
      fin[s[i] - 'a'][i] = i + 1;
      for (int c = (s[i] - 'a') + 1; c <= maxc; ++c) {
        fin[c][i] = fin[c - 1][fin[c - 1][i]];
      }

      int pos = fin[maxc][i];
      for (int c = 0; c < s[i] - 'a'; ++c) {
        fin[c][i] = fin[c][pos];
      }
    }

    pr[0][i] = fin[maxc][i];
  }

  for (int it = 1; it < maxl; ++it) {
    for (int i = 0; i < n + 2; ++i) {
      pr[it][i] = pr[it - 1][pr[it - 1][i]];
    }
  }

  for (int iter = 0; iter < q; ++iter) {
    int l, r;
    scanf("%d%d", &l, &r);
    --l;

    int x = l;
    for (int it = maxl - 1; it >= 0; --it) {
      if (pr[it][x] <= r) {
        x = pr[it][x];
      }
    }
    printf(x == r ? "Yes\n" : "No\n");
  }
}

int main() {
  precalc();
#ifdef LOCAL
  freopen(TASK ".out", "w", stdout);
  assert(freopen(TASK ".in", "r", stdin));
#endif

  while (1) {
    if (!read()) {
      break;
    }
    solve();
#ifdef DEBUG
    eprintf("Time %.2f\n", (double) clock() / CLOCKS_PER_SEC);
#endif
  }
  return 0;
}


Measured memory_bytes: 92928
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <algorithm>
#include <numeric>
#include <fstream>
#include <iomanip>

typedef long double ld;
typedef long long ll;
const ll INF = (ll)1e18 + 1;
const ll MOD = 1e9 + 7;

// Split
namespace util {

std::vector< std::string > split(std::string s, char delimiter)
{
  std::vector< std::string > vs;
  std::string sub;
  for (auto c : s) {
    if (c == delimiter) vs.push_back(sub), sub.clear();
    else sub += c;
  }
  vs.push_back(sub);
  return vs;
}

} // namespace util

// Minimum, Maximum
template<class T> T minimum(T head, T tail) { return std::min(head, tail); }
template<class H, class... T> H minimum(H head, T... tail) { return std::min(head, minimum(tail...)); }
template<class T> T maximum(T head, T tail) { return std::max(head, tail); }
template<class H, class... T> H maximum(H head, T... tail) { return std::max(head, maximum(tail...)); }

// Output
template<class T, class S> std::ostream& operator << (std::ostream& os, std::pair<T, S> p)
{
  return os << "(" << p.first << " " << p.second << ")";
}

template<class T> std::ostream& operator << (std::ostream& os, std::vector< T > v)
{
  for (ll i = 0; i < (ll)v.size(); i++){ os << " [" << i << "]" << v[i]; if (i % 10 == 9) os << std::endl; }
  //os << v[0]; for (ll i = 1; i < (ll)v.size(); i++){ os << " " << v[i]; }
  return os;
}

template<class T, class S> std::ostream& operator << (std::ostream& os, std::map< T, S > m)
{
  ll i = 0; for (auto p : m){ os << " [" << i << "]" << p.first << "->" << p.second; i++;}
  return os;
}

void print(){ std::cout << std::endl; }
template<typename H> void print(H head) { std::cout << head << std::endl; }
template<typename H, typename... T> void print(H head, T... tail){ std::cout << head << " ", print(tail...); }

// GCD, LCM
ll gcd(ll a, ll b) {
  while (b != 0) { a %= b; std::swap(a, b); }
  return a;
}
ll lcm(ll a, ll b) { return (a / gcd(a, b)) * b; }

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

  ll N;
  std::cin >> N;
  std::vector< ll > va(N, 0LL);
  for (ll i = 0; i < N; i++) {
    std::cin >> va[i];
  }

  ll sum = 0LL;
  for (ll i = 0; i < N; i++) {
    for (ll j = i+1; j < N; j++) {
      sum += va[i] * va[j];
    }
  }

  print(sum);

  return 0;
}


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

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

int main() {
  for(;;) {
    double a, b, c, d, e, f;
    if( !(cin >> a >> b >> c >> d >> e >> f) )break;
    double det = 1.0 / (a * e -b * d);
    double x = det * (e * c - b * f);
    double y = det * (-d * c + a * f);
    double EPS = 1e-8;
    char buf[128];
    sprintf(buf, "%.4f", x + EPS);
    buf[ strlen(buf) - 1 ] = ' ';
    printf(buf);
    sprintf(buf, "%.4f", y + EPS);
    buf[ strlen(buf) - 1 ] = '\n';
    printf(buf);
  }
  return 0;
}

Measured memory_bytes: 0
// Template {{{
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0; i<(int)(n); ++i)
using namespace std;
typedef long long LL;

#ifdef LOCAL
#include "contest.h"
#else
#define dump(x) 
#endif

const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
inline bool valid(int x, int w) { return 0 <= x && x < w; }

void iostream_init() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.setf(ios::fixed);
    cout.precision(12);
}
//}}}

int main(){
    iostream_init();
    int N;
    cin >> N;
    vector<int> A(N);
    REP(i, N) cin >> A[i];
    int ans = INT_MAX;
    for(int X = -100; X <= 100; X++) {
        int sum = 0;
        REP(i, N) {
            int diff = X - A[i];
            sum += diff * diff;
        }
        if(ans > sum) ans = sum;
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
const int N = 200000+5;
using namespace std;
int a[N];
int main() {
    int n;
    scanf("%d",&n);
 
    int num4=0,num2=0;
    for(int i=1;i<=n;i++){
        scanf("%d",&a[i]);
        if(a[i]%4==0)
            num4++;
        else if(a[i]%2==0)
            num2++;
    }
    if(n>2*num4+num2+1)
       printf("No\n");
    else if(2*num4+num2+1==n&&num2!=0)
        printf("No\n");
    else
        printf("Yes\n");
    return 0;
}

Measured memory_bytes: 640
#include<stdio.h>

int main() {
	long int D[10100] , N, i,j,result=0;
	scanf("%ld",&N);

	for (i = 0; i != N; i++) {
		scanf("%ld", &D[i]);
		for (j = 0; D[i] % 2 != 1; result++) { D[i] = D[i] / 2; }
	}
	printf("%ld",result);

}

Measured memory_bytes: 256
N, M = map(int, input().split())
X = list(map(int, input().split()))
X.sort()
gap = list()
for i in range(M-1):
  gap.append(X[i+1]-X[i])
gap.sort(reverse = True)
if(N >= M):
  print(0)
else:
  cnt = 0
  for i in range(N-1):
    cnt += gap[i]
  print(sum(gap)-cnt)

Measured memory_bytes: 13968
#include<bits/stdc++.h>
#define pb push_back
#define vl vector
#define ll long long
#define fast std::ios::sync_with_stdio(false)
using namespace std;

bool check(ll a,ll b)
{
    if(a==0 && b==0) return false;
    return true;
}

int main()
{
    fast;
    ll x;
    cin>>x;
    ll count=0;
    ll a=100;
    while(1)
    {
        if(a>=x)
        {
            cout<<count;
            return 0;
        }
        count++;
        a+=a/100;
    }
    
}


Measured memory_bytes: 3600
#include "bits/stdc++.h"
using namespace std;
#define Rep(i,n) for(int i=0;i<(int)(n);i++)
#define For(i,n1,n2) for(int i=(int)(n1);i<(int)(n2);i++)
#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,n1,n2) for(ll i=(ll)(n1);i<(ll)(n2);i++)
#define put(a) cout<<a<<"\n"
#define all(a)  (a).begin(),(a).end()
#define SORT(a) sort((a).begin(),(a).end())
#define oorret 0
#define oor(x) [&](){try{x;} catch(const out_of_range& oor){return oorret;} return x;}()
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
template<typename T1, typename T2> inline bool chmin(T1& a, T2 b) { if (a > b) { a = b; return 1; }return 0; }
template<typename T1, typename T2> inline bool chmax(T1& a, T2 b) { if (a < b) { a = b; return 1; }return 0; }


int main() {
	ll n, m;
	cin >> n >> m;
	vector<ll> a(n), c(m);
	vector<int> b(m);
	vector<pair<ll, ll>> p(m + n);
	REP(i, n) {
		cin >> p[i].first;
		p[i].second = 1;
	}
	//ll cnt = 0;
	REP(i, m) {
		cin >> p[i + n].second >> p[i + n].first;
		//cin >> b[i] >> c[i];
		//cnt += p[i + n].second;
	}
	sort(all(p),greater<>());
	ll res = 0;
	ll cnt = 0;
	int i;
	for (i = 0;cnt+p[i].second<n; ++i) {
		res += p[i].first * p[i].second;
		cnt += p[i].second;
	}
	res += p[i].first * (n - cnt);
	put(res);
	return 0;
}



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

public class Main {
    public static void main(String[] args) throws Exception {

        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));
    
        String[] s = br.readLine().split(" ");
        
        out.println(s[1] + s[0]);
        out.close();
        
    }
}

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

typedef long long ll;

int a, b, x;
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> a >> b >> x;
    if (x >= a && x <= a + b)
        cout << "YES" << endl;
    else
        cout << "NO" << endl;

    return 0;
}



Measured memory_bytes: 3616
#include <bits/stdc++.h>
using namespace std;
// #define int long long
using ll=long long;
using vi=vector<int>;
using vl=vector<long long>;
using pii=pair<int,int>;
#define ITR(v,c) for(auto v=begin(c);v!=end(c);v++)
#define FORE(x,c) for(auto &x:c)
#define FOR(v,a,n) for(int v=a;v<(int)(n);v++)
#define REP(v,n) FOR(v,0,n)
#define RREP(v,n) for(int v=((int)(n)-1);v>=0;v--)
#define ALL(c) begin(c),end(c)
#define RALL(c) rbegin(c),rend(c)
#define SZ(c) ((int)c.size())
const int DX[9]={0,1,0,-1,1,1,-1,-1,0}, DY[9]={-1,0,1,0,-1,1,1,-1,0};
const int INF=1e9; const long long INFLL=1e18;
template<class T>ostream&operator<<(ostream &os,const vector<T> &v){
    ITR(i,v)os<<*i<<(i==end(v)-1?"":" ");return os;}
//------------------------------------------------------------------------------

signed main() {
    string s;
    cin>>s;
    int ans=0;
    FOR(i,1,SZ(s)) {
        if(s[i-1]!=s[i]) ans++;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
const int maxn = 1e5+10;
int c[maxn],a[maxn],n;
inline int read(void)
{
	int x = 0,f = 1; char ch = getchar();
	while(!isdigit(ch)) {f = ch == '-' ? -1 : 1; ch = getchar();}
	while(isdigit(ch)) {x = (x << 3) + (x << 1) + ch - '0'; ch = getchar();}
	return x * f;
}

int main(int argc, char *argv[])
{
	n = read();
	for (int i = 1; i <= n; i++) a[i] = read();
	c[0] = a[0] = a[n+1] = 0;
	for (int i = 1; i <= n+1; i++) c[i] = c[i-1] + abs(a[i]-a[i-1]);
	for (int i = 1; i <= n; i++)
	{
		int ret = c[i-1] + c[n+1] - c[i+1];
		ret += abs(a[i-1]-a[i+1]);
		printf("%d\n",ret);
	}
	return 0;
}

Measured memory_bytes: 2048
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * 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;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        D solver = new D();
        solver.solve(1, in, out);
        out.close();
    }

    static class D {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            // 入力
            int n = Integer.parseInt(in.next());
            char[] c = in.next().toCharArray();
            int ans = 0;
            int cnt_r = 0;
            for (int i = 0; i < n; i++) {
                if (c[i] == 'R') cnt_r++;
            }
            for (int i = 0; i < cnt_r; i++) {
                if (c[i] == 'W') ans++;
            }

            // 出力
            out.println(ans);

        }

    }
}



Measured memory_bytes: 40548
package main

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

var sc, wr = bufio.NewScanner(os.Stdin), bufio.NewWriter(os.Stdout)

func scanString() string   { sc.Scan(); return sc.Text() }
func scanRunes() []rune    { return []rune(scanString()) }
func scanInt() int         { a, _ := strconv.Atoi(scanString()); return a }
func scanInt64() int64     { a, _ := strconv.ParseInt(scanString(), 10, 64); return a }
func scanFloat64() float64 { a, _ := strconv.ParseFloat(scanString(), 64); return a }

func scanInts(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = scanInt()
	} 
	return res
}

func debug(a ...interface{}) { fmt.Fprintln(os.Stderr, a...) }

func abs(a int) int {
	if a < 0 {
		return -a
	}
	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
}

//•*¨*•.¸¸♪main•*¨*•.¸¸♪(　-ω-)ノ　(　・ω・)
func main() {
	defer wr.Flush()
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 10000), 1001001)

	n := scanInt()
	c := map[int]int{}
	for i := 0; i < n; i++ {
		c[scanInt()] ^= 1
	}
	ans := 0
	for _, e := range c {
		ans += e
	}
	fmt.Fprintln(wr, ans)
}


Measured memory_bytes: 8652
program prob6
    implicit none
    integer :: n
    integer, allocatable :: a(:)
    integer ::  i, tmp, ans, x
    read(*,*) n
    allocate(a(n))
    do i = 1, n
        read(*,*) x
        a(x) = i
    end do


    tmp = 1
    ans = 1
    do i = 1, n-1
        if(a(i) < a(i+1)) then
            tmp = tmp + 1
        else
            ans = max(tmp, ans)
            tmp = 1
        end if
    end do
    ans = max(tmp, ans)

    write(*,*) n - ans

    deallocate(a)

    stop
contains
end program prob6

Measured memory_bytes: 3256
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <functional>
#include <algorithm>

using namespace std;

#define rep(i,j) REP((i), 0, (j))
#define REP(i,j,k) for(int i=(j);(i)<(k);++i)
#define BW(a,x,b) ((a)<=(x)&&(x)<=(b))
#define ALL(v) (v).begin(), (v).end()
#define LENGTHOF(x) (sizeof(x) / sizeof(*(x)))
#define AFILL(a, b) fill((int*)a, (int*)(a + LENGTHOF(a)), b)
#define SQ(x) ((x)*(x))
#define Mod(x, mod) (((x)+(mod)%(mod))
#define MP make_pair
#define PB push_back
#define Fi first
#define Se second
#define INF (1<<29)
#define EPS 1e-10
#define MOD 1000000007

typedef pair<int, int> pi;
typedef pair<int, pi> pii;
typedef vector<int> vi;
typedef queue<int> qi;
typedef long long ll;

int N, T;

int main()
{
  cin >> N >> T;
  vector<int>D(N);
  rep(i, N) cin >> D[i];
  sort(D.begin(), D.end());
  ll res = 1;
  for(int i=1;i<N;i++){
    int pos = lower_bound(D.begin(), D.end(), D[i]-T) - D.begin();
    res = (res * (i-pos+1))%MOD;
  }
  
  cout << res << endl;
  return 0;
}

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

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

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

#define MAX 100005
#define INF 1001001001

int main(int, char**)
{
  int n;
  cin >> n;

  rep(i,1<<n) {
    cout << i << ":";
    rep(j,n) if (i&(1<<j)) cout << " " << j;
    cout << endl;
  }

  return 0;
}



Measured memory_bytes: 3100
import java.util.*;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int K = sc.nextInt();
		int A = sc.nextInt();
		int B = sc.nextInt();
		System.out.println(B/K*K >= A ? "OK" : "NG");
		
		sc.close();
	}
}


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

int main() {
    int a, b;
    cin >> a >> b;
    if(a <= 0 && 0 <= b) cout << "Zero" << endl;
    else if(b < 0){
        if((b-a+1)%2 == 0) cout << "Positive" << endl;
        else cout << "Negative" << endl;
    }
    else cout << "Positive" << endl;
}


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

using namespace std;

typedef long long ll;

const int mod = 1e9 + 7;

int n, m;
vector<vector<int>> paths;
vector<pair<int, int>> edges;
vector<bool> used;
vector<vector<bool>> edge_used;
vector<vector<int>> g;
vector<vector<vector<bool>>> path_edge;

bool dfs(int cur, int end, int num) {
    if (cur == end) {
        paths[num].push_back(cur);
        return true;
    }
    used[cur] = true;
    for (const auto &to:g[cur]) {
        if (!used[to]) {
            if (dfs(to, end, num)) {
                paths[num].push_back(cur);
                used[cur] = false;
                return true;
            }
        }
    }
    used[cur] = false;
    return false;
}

int main() {
    cin >> n;
    g.resize(n);
    used.resize(n);
    for (int i = 0; i < n - 1; ++i) {
        int u, v;
        cin >> u >> v;
        u--, v--;
        g[u].push_back(v);
        g[v].push_back(u);
        edges.emplace_back(min(u, v), max(u, v));
    }
    cin >> m;
    paths.resize(m);
    path_edge.resize(n, vector<vector<bool>>(n, vector<bool>(m, false)));
    for (int i = 0; i < m; ++i) {
        int u, v;
        cin >> u >> v;
        u--, v--;
        dfs(u, v, i);
    }
    for (int i = 0; i < m; ++i) {
        for (int j = 0; j + 1 < paths[i].size(); ++j) {
            path_edge[min(paths[i][j], paths[i][j + 1])][max(paths[i][j], paths[i][j + 1])][i] = true;
        }
    }
    ll ans = 1ull << (n - 1);
    for (int i = 1; i < 1ull << (paths.size()); ++i) {
        ll edge_num = 0, bits = 0, cur = 1, j = 0;
        vector<int> ind;
        while (cur <= i) {
            if (cur & i) {
                bits++;
                ind.push_back(j);
            }
            cur *= 2;
            j++;
        }
        for (auto &edge:edges) {
            for (auto k:ind) {
                if (path_edge[edge.first][edge.second][k]) {
                    edge_num++;
                    break;
                }
            }
        }
        if (bits & 1) {
            ans -= 1ull << (n - 1 - edge_num);
        } else {
            ans += 1ull << (n - 1 - edge_num);
        }
    }
    cout << ans;
    return 0;
}

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

#define pb push_back
#define mp make_pair
#define taskname "A"

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int,int> ii;
const int maxn = 2e3 + 10;
const int inf = 1e6;
const ll C = 2e9;

struct edge{
    int u , v , c;
    ll cost;
    edge(){};edge(int u , int v , int c , ll cost):u(u),v(v),c(c),cost(cost){};
}e[maxn * 20];

vector<int> adj[maxn * 2];
int s , t;
int nTime = 0;

void add_edge(int u , int v , int c , ll cost){
    e[nTime * 2] = edge(u,v,c,cost);
    e[nTime * 2 + 1] = edge(v,u,0,-cost);
    adj[u].pb(nTime * 2);adj[v].pb(nTime*2+1);
    ++nTime;
}

ll d[maxn];
int trace[maxn];
int vis[maxn];
bool spfa(){
    queue<int> q;
    fill_n(d,maxn,1e18);fill_n(trace,maxn,-1);
    q.push(s);
    d[s] = 0;
    while(q.size()){
        auto u = q.front();q.pop();vis[u] = 0;
//        cout << u << " " << d[u] << endl;
        for(int c : adj[u]){
            if(e[c].c > 0 && d[e[c].v] > d[u] + e[c].cost){
                d[e[c].v] = d[u] + e[c].cost;
                trace[e[c].v] = c;
                if(vis[e[c].v] == 0){
                    vis[e[c].v] = 1;
                    q.push(e[c].v);
                }
            }
        }
    }
    return d[t] != 1e18;
}
int n;

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    if(fopen(taskname".INP" , "r"))
        freopen(taskname".INP","r",stdin),
        freopen(taskname".OUT","w",stdout);
    cin >> n;
    int sum = 0;s = 0 , t = maxn - 1;
    for(int i = 1 ; i <= n ; ++i){
        int x , y , c;cin >> x >> y >> c;
        sum += c;add_edge(s,i,c,0);
        for(int j = 0 ; j < 4 ; ++j){
            ll tmp = C + ((j & 1) ? -x : x) + ((j & 2) ? -y : y);
            add_edge(i,t-j-1,c,tmp);
        }
    }
    for(int i = 1 ; i <= n ; ++i){
        int x , y , c;cin >> x >> y >> c;
        add_edge(i+n,t,c,0);
        for(int j = 0 ; j < 4 ; ++j){
            ll tmp = C + ((j & 1) ? x : -x) + ((j & 2) ? y : -y);
            add_edge(t-j-1,i+n,c,tmp);
        }
    }
    ll res = 0;
    while(spfa()){
        int delta = 1e9;
        for(int u = t ; u != s ; u = e[trace[u]].u){
            delta = min(delta,e[trace[u]].c);
        }
        for(int u = t ; u != s ; u = e[trace[u]].u){
            e[trace[u]].c -= delta;e[trace[u]^1].c+=delta;
        }
        res += d[t] * delta;
//        cout << d[t] << " " << delta << endl;
    }
    res = 2 * sum * C - res;
//    res -= C * sum;
    cout << res;
}


Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#include <set>
#include <tuple>
#define mkp make_pair
#define mkt make_tuple
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
const ll MOD=1e9+7;

ll cnt[10][10];

int updig(int val){
  while(val/10>0){
    val/=10;
  }
  return val;
}

int main(){
  int N;
  cin>>N;
 
  for(int i=1;i<=N;i++){
      int ma=updig(i);
      cnt[ma][i%10]++;
  }

  ll ans=0;
  for(int i=1;i<=9;i++) for(int j=1;j<=9;j++) ans+=cnt[i][j]*cnt[j][i];

  cout<<ans<<endl;


  return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
class Program
{
	static void Main(string[] args)
	{
		string[] str = Console.ReadLine().Split();
		int N = int.Parse(str[0]);
		int M = int.Parse(str[1]);
		int[]A = new int[M];
		for(var i=0;i<M;i++){
			A[i] = int.Parse(Console.ReadLine());
		}
		long[,]B = new long[N+1,2];
		long mod = 1000000007;
		int t = 0;
		B[0,0]=1;
		for(var i=1;i<=N;i++){
			if(t>=M || A[t]!=i){
				B[i,0] = (B[i-1,0]+B[i-1,1]) % mod;
				B[i,1] = B[i-1,0] % mod;
			} else {
				t++;
				B[i,1] = B[i-1,0] % mod;
			}
		}
		Console.WriteLine(B[N,0]);
	}
}

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

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

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

void Main() {
  int n;
  cin >> n;
  vector<int> L(n);
  rep(i, n) cin >> L[i];
  sort(L.begin(), L.end());
  int ans = 0;
  rep(i, n-2) REP(j, i+1, n-1) {
    int a = L[i];
    int b = L[j];
    int pos = upper_bound(L.begin() + j, L.end(), a + b - 1) - L.begin() - j - 1;
    ans += pos;
  }
  cout << ans << endl;
}

int main() {
  std::cin.tie(nullptr);
  std::ios_base::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);
  Main();
  return 0;
}


Measured memory_bytes: 256
/*---Author:HenryHuang---*/
#include<bits/stdc++.h>
using namespace std;
const int maxn=3e3+5;
typedef long long ll;
int n,p;
ll ksm(ll a,ll b,ll p){
	ll ans=1;
	while(b){
		if(b&1) ans=ans*a%p;
		b>>=1,a=a*a%p;
	}
	return ans;
}
ll C[maxn][maxn],S[maxn][maxn];
void init(){
	C[0][0]=S[0][0]=1;
	for(int i=1;i<=n+1;++i){
		C[i][0]=1;
		for(int j=1;j<=i;++j){
			S[i][j]=(S[i-1][j-1]+j*S[i-1][j])%p;
			C[i][j]=(C[i-1][j-1]+C[i-1][j])%p;
		}
	}
}
ll a[32769],b[32769];
ll c[32769],d[32769];
ll p1(ll x){
	return a[x&0x00007fff]*b[x>>15]%p;
}
ll p2(ll x){
	return c[x&0x00007fff]*d[x>>15]%(p-1);
}
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0),cout.tie(0);
	cin>>n>>p;init();
	a[0]=1;
	for(int i=1;i<=32768;++i){
		a[i]=a[i-1]*2%p;
	}
	b[0]=1,b[1]=a[32768];
	for(int i=2;i<=32768;++i){
		b[i]=b[i-1]*b[1]%p;
	}
	c[0]=1;
	for(int i=1;i<=32768;++i){
		c[i]=c[i-1]*2%(p-1);
	}
	d[0]=1,d[1]=c[32768];
	for(int i=2;i<=32768;++i){
		d[i]=d[i-1]*d[1]%(p-1);
	}
	ll ans=0;
	for(int i=0;i<=n;++i){
		ll tmp=p1(p2(n-i))*C[n][i]%p,owo=0;
		if(i&1) tmp=p-tmp;
		for(int j=0;j<=i;++j){
			owo=(owo+S[i+1][j+1]*p1(1ll*(n-i)*j%(p-1)))%p;
		}
		(ans+=tmp*owo)%=p;
	}
	cout<<ans<<'\n';
	return 0;
}


Measured memory_bytes: 96864
// which is larger, a...a (b times) or b...b (a times) 

use proconio::input;

fn main() {
  input! {
    a: usize,
    b: usize,
  };
  let s: String = (0..b).map(|_| std::char::from_digit(a as u32, 10).unwrap()).collect();
  let t: String = (0..a).map(|_| std::char::from_digit(b as u32, 10).unwrap()).collect();
  if s < t {
    println!("{}", s);
  } else {
    println!("{}", t);
  }
}


Measured memory_bytes: 2160
# time complexity: O(N^3 + R!)
# space complexity: O(N^2)

import sys
fin = sys.stdin.readline
from itertools import permutations


def warshall_floyd_int(adj, w):
    num_vertices = len(adj)
    dp = [[float('inf')] * num_vertices for _ in range(num_vertices)]
    for u in range(num_vertices):
        dp[u][u] = 0
        for v in adj[u]:
            dp[u][v] = w[u][v]

    for k in range(num_vertices):
        for i in range(num_vertices):
            for j in range(num_vertices):
                dp[i][j] = min(dp[i][j], dp[i][k] + dp[k][j])
    return dp


N, M, R = [int(elem) for elem in fin().split()]
r_list = [int(elem) - 1 for elem in fin().split()]
assert len(r_list) == R

adj = [[] for _ in range(N)]
w = [[None] * N for _ in range(N)]

for _ in range(M):
    A, B, C = [int(elem) for elem in fin().split()]
    A -= 1
    B -= 1
    adj[A].append(B)
    adj[B].append(A)
    w[A][B] = C
    w[B][A] = C

# calculate the shortest distance between any pair of vertices
shortest_distances = warshall_floyd_int(adj, w)

# choose the best route by examining all possible routes
# this is possible because R <= 8
min_distance = float('inf')
for permutation in permutations(r_list):
    distance = 0
    for i, city in enumerate(permutation[:-1]):
        next_city = permutation[i + 1]
        distance += shortest_distances[city][next_city]
    min_distance = min(min_distance, distance)
print(min_distance)


Measured memory_bytes: 57564