akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<string>

using namespace std;

int main()
{
	string s;
	int pA, pZ;

	cin >> s;

	for (size_t i = 0; i < s.length(); ++i)
	{
		if (s[i] == 'A')
		{
			pA = i;
			break;
		}
	}	
	for (size_t i = s.length() - 1; i >= 0; i--)
	{
		if (s[i] == 'Z')
		{
			pZ = i;
			break;
		}
		
	}
	
	cout << pZ - pA + 1 << endl;

	return 0; 
}

Measured memory_bytes: 832
#include <bits/stdc++.h>
#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--)
#define ALL(x) (x).begin(),(x).end() 
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define INF 1000000000
using namespace std;
typedef long long ll;
ll mod = 1e+9 + 7;

int main(){
    ll N, all = 1, pos = 1, res = 1, ans;
    bool flag = true;

    cin >> N;

   
    REP(i, N){
        all = (all*10)%mod;
        pos = (pos*9)%mod;
        res = (res*8)%mod;
    }
    ans = all - 2*pos + res;
    ans %= mod;
    ans = (ans+mod)%mod;

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3604
#include <iostream>
#include <algorithm>
#include <set>

using  namespace std;
set<string> se;
int main(){

  int m;
  cin>>m;
  for(int i = 0;i<m;i++){
    string s;
    cin>>s;
    se.insert(s);
    for(int j = 1;j<=s.size();j++){
      string tmp = s.substr(0,j);
      string tmp2 = s.substr(j);
      se.insert(tmp2+tmp);
      reverse(tmp.begin(),tmp.end());
      se.insert(tmp + tmp2);
      se.insert(tmp2 + tmp);
      reverse(tmp2.begin(),tmp2.end());
      se.insert(tmp + tmp2);
      se.insert(tmp2 + tmp);
      reverse(tmp.begin(),tmp.end());
      se.insert(tmp2+ tmp);
      se.insert(tmp+tmp2);
      

    }
    /*
    set<string>::iterator itr = se.begin();
    while(itr != se.end()){
      cout<<*itr<<endl;
      itr++;
    }
    */
    cout<<se.size()<<endl;
    se.clear();
  }


  return 0;
}

Measured memory_bytes: 3192
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <iostream>
#include <istream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <tuple>
#include <iomanip>
#include <climits>
#include <fstream>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
//typedef pair<ll, ll> P;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define revrep(i, n) for(int i = (n)-1; i >= 0; i--)
#define pb push_back
#define f first
#define s second
#define chmin(x, y) x = min(x, y);
#define chmax(x, y) x = max(x, y);

//const ll INFL = LLONG_MAX;//10^18 = 2^60
const ll INFL = 1LL<<60;
//const int INF = INT_MAX;
const int INF = 1 << 30;//10^9
//ll MOD = 1000000007;
ll MOD = 998244353;
double EPS = 1e-10;

vector<ll> dy = {0, 1, 0, -1, 1, 1, -1, -1, 0};
vector<ll> dx = {1, 0, -1, 0, 1, -1, 1, -1, 0};

void pres(double A){printf("%.12lf\n", A);}
void BinarySay(ll x, ll y = 60){rep(i, y) cout << (x>>(y-1-i) & 1); cout << endl;}
ll cnt_bit(ll x){return __builtin_popcountll(x);}

ll pow_long(ll x, ll k){
  ll res = 1;
  while(k > 0){
    if(k % 2) res *= x;
    x *= x; k /= 2;
  }
  return res;
}

ll pow_mod(ll x, ll k){
  x %= MOD;
  ll res = 1;
  while(k > 0){
    if(k % 2){
      res *= x; res %= MOD;
    }
    x *= x; x %= MOD;
    k /= 2;
  }
  return res;
}

ll inverse(ll x){return pow_mod(x, MOD - 2);};

ll gcd(ll a, ll b){
    if(b == 0) return a;
    return gcd(b, a % b);
}

ll lcm(ll x, ll y){
  ll res = x / gcd(x, y);
  res *= y;
  return res;
};


//コンビネーション
const int MAXcomb = 2000010;
ll fac[MAXcomb], finv[MAXcomb], inv[MAXcomb];
//facはn!,finvは1/n!
//invは逆元
void COMinit(){
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for(int i = 2; i < MAXcomb; i++){
        fac[i] = fac[i-1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD/i) % MOD;
        finv[i] = finv[i-1] * inv[i] % MOD;
    }
}
ll comb(int n, int k){
    if(n < k) return 0;
    if(n < 0 || k < 0) return 0;
    return fac[n] * finv[k] % MOD * finv[n-k] % MOD;
}

const int MAXkai = 200010;
ll kai_memo[MAXkai];
ll kai(ll N){
  if(kai_memo[N] != 0) return kai_memo[N];
  if(N <= 1) return 1;
  return kai_memo[N] = N * kai(N-1) % MOD;
}

ll disit(ll s, ll base = 10){
  if(s == 0) return 1;
  ll res = 0;
  while(s){
    res++;
    s /= base;
  }
  return res;
}

//約数の列挙O(√n)
vector<ll> divisor(ll n){
    vector<ll> res(0);
    for(ll i = 1; i * i <= n; i++){
        if(n % i == 0){
            res.push_back(i);
            if(i != n/i) res.push_back(n/i);
        }
    }
    sort(res.begin(), res.end());
    return res;
}

ll s[10], c[10];
void solve(){
  ll N, M;
  cin >> N >> M;

  rep(i, M){
    cin >> s[i] >> c[i];
    s[i]--;
  }
  for(ll i = 0; i <= 1000; i++){
    if(disit(i) != N) continue;
    bool ok = 1;
    string S;
    rep(j, N) S += '0' + (i / pow_long(10, N-j-1) % 10);
    rep(j, M){
      if(S[s[j]] != (char)'0'+c[j]) ok = 0;
    }
    if(ok){
      cout << i << endl;
      return;
    }
  }
  cout << -1 << endl;
}


int main(){
  ios_base::sync_with_stdio(0);
  cin.tie(0), cout.tie(0);
  solve();
}


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

int main(){ 
    int N;
    int M;
    
    cin >> N;
    cin >> M;
    
    vector<int> ans(N, 10);
  
    //整数入力
    for(int i = 0; i < M; i++){
        int s, c;
        cin >> s; cin >> c;
        
        if(ans.at(s-1) > 9){
            ans.at(s-1) = c;
        }else{
            if(ans.at(s-1) != c){
                cout << "-1" << endl;
                return 0;
            }
        }
    }
    
    // 最上位が0かつ桁数が1より大きい場合存在しない    
    if(ans.at(0) == 0 && N > 1){
        cout << "-1" << endl;
        return 0;
    }

    //最上位が定義されていなかった場合、1を設定
    if(ans.at(0) > 9){
        if(N > 1){
            ans.at(0) = 1;
        }else{
            ans.at(0) = 0;
        }
    }

    //最上位から値を出力。定義されていなかった場合0を出力
    for(int i = 0; i < N; i++){
        if(ans.at(i) > 9){
            cout << 0;
        }else{
            cout << ans.at(i);
        }
    }
    cout << endl;
    return 0;
}
        


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

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

	int numG = 0;
	int numP = 0;
	int n = s.size();
	for (int i = 0; i < n; ++i) {
		if (s[i] == 'g') {
			++numG;
		}
		else {
			++numP;
		}
	}

	int limP = n / 2;
	cout << limP - numP << endl;

	return 0;

}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
using namespace std;
using ll = long long;
using P = pair<int,int>;
template <class T> void chmin(T &a, const T &b) noexcept { if (b < a) a = b; }
template <class T> void chmax(T &a, const T &b) noexcept { if (a < b) a = b; }
void debug_out() { cout << "\n"; }
template <class T, class... Args>
void debug_out(const T &x, const Args &... args) { cout << x << " "; debug_out(args...);}
#ifdef _DEBUG
  #define debug(...) debug_out(__VA_ARGS__)
#else
  #define debug(...) 
#endif

int main() {
  std::cin.tie(nullptr);
  std::ios_base::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);
  int h,w,d;
  cin >> h >> w >> d;
  vector<P> a(h*w+1);
  rep(i,h)rep(j,w) {
    int x;
    cin >> x;
    a[x] = P(i+1,j+1);
  }
  vector<vector<ll> > S(d+1,vector<ll>((h*w+d-1)/d+1,0));
  for (int i = 1; i <= d; ++i) {
    P pre = a[i];
    for (int j = 1; i+d*j <= h*w; ++j) {
      P cur = a[i+d*j];
      S[i][j+1] += llabs(cur.first - pre.first)+llabs(cur.second - pre.second);
      S[i][j+1] += S[i][j];
      pre = cur;
    }
  }
  int q;
  cin >> q;
  rep(i_,q) {
    int l,r;
    cin >> l >> r;
    int i = l % d;
    if (i == 0) i = d;
    int itr1 = (l-i) / d;
    int itr2 = (r-i) / d;
    // debug(itr1, itr2, i, S[i][itr2+1], S[i][itr1]);
    ll ans = S[i][itr2+1] - S[i][itr1+1];
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 6144
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <deque>
#include <numeric>
#include <sstream>
#include <iomanip>
#define ALL(X) X.begin(), X.end()
using lint = long long;
template <typename T>
void print_container(std::vector<T> vec)
{
    for (auto iter = vec.begin(); iter != vec.end(); ++iter)
    {
        std::cout << *iter << " ";
    }
    std::cout << std::endl;
}

class Step
{
public:
    lint y;
    lint x;
    lint step;
};

int main()
{
    lint h, w, k;
    scanf("%lld", &h);
    scanf("%lld", &w);
    scanf("%lld", &k);

    lint sy, sx, gy, gx;
    scanf("%lld", &sy);
    scanf("%lld", &sx);
    scanf("%lld", &gy);
    scanf("%lld", &gx);

    std::vector<std::vector<lint>> maze(h, std::vector<lint>(w, 0));
    std::vector<std::vector<lint>> seen(h, std::vector<lint>(w, 1000000000));

    for (int i = 0; i < h; ++i)
    {
        std::string s;
        std::cin >> s;

        for (int j = 0; j < w; ++j)
        {
            if (s[j] == '@')
            {
                maze[i][j] = 1;
            }
        }
    }

    std::vector<std::pair<lint, lint>> dirs;
    dirs.emplace_back(1, 0);
    dirs.emplace_back(-1, 0);
    dirs.emplace_back(0, 1);
    dirs.emplace_back(0, -1);

    std::deque<Step> q;

    q.push_back(Step{sy - 1, sx - 1, 0});
    seen[sy - 1][sx - 1] = 0;

    lint done = 0;
    lint ans = -1;

    while (!q.empty())
    {
        auto cur = q.front();
        q.pop_front();
        lint nx_step = cur.step + 1;
        for (auto dir : dirs)
        {
            lint nx_y = cur.y;
            lint nx_x = cur.x;
            for (int i = 0; i < k; ++i)
            {
                nx_y += dir.first;
                nx_x += dir.second;
                if (0 <= nx_y && nx_y < h && 0 <= nx_x && nx_x < w && maze[nx_y][nx_x] != 1 && seen[nx_y][nx_x] >= nx_step)
                {
                    if (nx_y == (gy - 1) && nx_x == (gx - 1))
                    {
                        done = 1;
                        ans = nx_step;
                    }
                    if (seen[nx_y][nx_x] > nx_step)
                    {
                        q.push_back(Step{nx_y, nx_x, nx_step});
                    }
                    seen[nx_y][nx_x] = nx_step;
                }
                else
                {
                    break;
                }
            }
        }
        if (done == 1)
        {
            break;
        }
    }

    if (ans < 0)
    {
        std::cout << -1 << "\n";
    }
    else
    {
        std::cout << ans << "\n";
    }

    return 0;
}


Measured memory_bytes: 26348
n, m = gets.chomp.split(" ").map(&:to_i)
ks = []
ss = []
m.times do |i|
  k, *s = gets.chomp.split(" ").map(&:to_i)
  ks[i] = k
  sp = Array.new(n, 0)
  s.each do |j|
    sp[j - 1] = 1
  end
  ss[i] = sp
end
p = gets.chomp.split(" ").map(&:to_i)

def all_on?(pat, ss, p)
  ss.each_with_index do |s, j|
    cnt = 0
    s.each_with_index do |v, i|
      cnt += v * pat[i]
    end
    return false if cnt % 2 != p[j]
  end
  true
end

cnt = 0
0.upto(n) do |i|
  # n個中，i個switch on
  (0...n).to_a.combination(i).each do |c|
    pat = Array.new(n, 0)
    c.each do |j|
      pat[j] = 1
    end
    cnt += 1 if all_on?(pat, ss, p)
  end
end
puts cnt


Measured memory_bytes: 1916
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

//INSERT ABOVE HERE
signed main(){
  Int n;
  cin>>n;
  vector<vector<Int> > G(n);
  for(Int i=1;i<n;i++){
    Int x,y;
    cin>>x>>y;
    x--;y--;
    G[x].emplace_back(y);
    G[y].emplace_back(x);    
  }
  
  Int s=0;
  vector<Int> dp(n,-1);
  function<void(Int, Int)> dfs=
    [&](Int v,Int p){
      if(dp[s]<dp[v]) s=v;
      for(Int u:G[v]){
        if(u==p) continue;
        dp[u]=dp[v]+1;
        dfs(u,v);
      }
    };
  dp.assign(n,-1);
  dp[0]=1;
  dfs(0,-1);
  
  dp.assign(n,-1);
  dp[s]=1;
  dfs(s,-1);
  
  Int ans=*max_element(dp.begin(),dp.end());
  //cout<<ans<<endl;
  cout<<((ans%3!=2)?"First":"Second")<<endl;
  return 0;
}


Measured memory_bytes: 28416
#include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<vector>
#include<cmath>
#include<cstdio>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define it ::iterator
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double ESP=1e-10;
using namespace std;
int main(){
  int m;
  int co=0;
  while(cin>>m,m){
    co++;
    int n;
    cin>>n;
    int in[1001][1001]={0};
    rep(q,n){
      int i=q+1;
      int a,b;char d;
      cin>>a>>d>>b;
      rep(j,m+1){
	if(j>=b)
	  in[i][j]=max(in[i][j],in[i-1][j-b]+a);
	in[i][j]=max(in[i][j],in[i-1][j]);
      }
    }
    int max1=0;
    rep(i,m+1)max1=max(max1,in[n][i]);
    rep(i,m+1)
      if(in[n][i]==max1){
	cout<<"Case "<<co<<":"<<endl;
	cout<<max1<<endl<<i<<endl;
	break;
      }
  }
}

/*int main(){
  int m;
  int co=0;
  while(cin>>m,m){
    co++;
    int n;
    char d;
    cin>>n;
    vector<int>w(n),v(n);
    vector<vector<int> >dp(n+1);
    rep(i,m+1)dp[0].pb(0);
    rep(q,n){
      int i=q+1;
      int a,b;char d;
      cin>>a>>d>>b;
      dp[i].pb(0);
      

}
*/

Measured memory_bytes: 5084
//https://atcoder.jp/contests/abc147/tasks/abc147_a
#include <bits/stdc++.h>
#if LOCAL
#include "dump.hpp"
#else
#define dump(...)
#endif
using namespace std;
using ll=long long;
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
template<class T>bool chmax(T &a, const T &b) {if (a<b) { a=b; return 1; } return 0;}
template<class T>bool chmin(T &a, const T &b) {if (b<a) { a=b; return 1; } return 0;}
int main() {
    ll a1,a2,a3; cin>>a1>>a2>>a3;
    ll ans=a1+a2+a3;
    if(ans>=22) cout<<"bust"<<endl;
    else cout<<"win"<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<stdio.h>
#include<vector>
#include<list>
#include<stack>
#include<queue>
#include<set>
#include<map>
#include<string>
#include<algorithm>
#include<functional>
#include<math.h>
#include<unordered_set>

using namespace std;

int main() {
	int a, b, c, k;

	cin >> a >> b >> c >> k;

	if (a < b)swap(a, b);
	if (a < c)swap(a, c);

	cout << a * pow(2,k) + b + c << endl;

	return 0;
}

Measured memory_bytes: 512
main = do
  n <- readLn :: IO Int
  as <- getLine >>= return . map read . words :: IO [Int]

  let
    f (_:[]) = 0
    f (x:y:xs) = (abs (y-x)) + (f (y:xs))
    s = f (0 : as ++ [0])
    g (_:_:[]) = []
    g (x:y:z:xs) = (abs (x-z) - abs (x-y) - abs (y-z)) : (g (y:z:xs))

  mapM_ print $ map (s +) (g (0 : as ++ [0]))

Measured memory_bytes: 31100
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main(){
	ll n, r = 0, ans = 0;
	string s;
	cin >> n >> s;
	for (char c : s) if (c == 'R') r++;
	for (ll i = 0; i < r; i++){
		if (s[i] == 'W') ans++;
	}
	cout << ans;
}

Measured memory_bytes: 3748
def main():
    N = int(input())
    A = [int(input()) for _ in range(N)]
    lis = [A[0]]
    for a in A[1:]:
        if a > lis[-1]:
            lis.append(a)
        else:
            idx = binary_search(lis, a)
            lis[idx] = a
    print(len(lis))


def binary_search(A, x):
    ok = len(A)
    ng = -1
    while abs(ok - ng) > 1:
        mid = (ok + ng) // 2
        if A[mid] >= x:
            ok = mid
        else:
            ng = mid
    return ok


if __name__ == '__main__':
    main()



Measured memory_bytes: 11120
#include<iostream>
#include<set>
#include<map>
#include<cmath>
#include<algorithm>
#include<stack>
#include<deque>
#include<queue>
#include<vector>
#include<string>
#include<time.h>
#include<unordered_map>
#include<random>
#include<unordered_set>
#include<forward_list>

#pragma GCC optimize("Ofast")

#define ll long long
#define int long long
#define endl "\n"
#define ld long double
#define si pair<string,int>
#define mp make_pair
#define ii pair<int,int>
#define is pair<int,string>
#define fi first
#define se second
#define _CRT_SECURE_NO_WARNINGS
#pragma warning(disable : 4996)


using namespace std;


signed main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);

    //freopen("08.in", "r", stdin);
	//freopen("output.txt", "w", stdout);

	//mt19937 gen{ std::random_device{}() };
	//gen();
	
	int x;
	cin >> x;
	int ans = (x / 500) * 1000 + ((x % 500) / 5) * 5;
	cout << ans;



	//system("pause");
	return 0;
}

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

int main(){
    string S,T;
    cin >> S >> T;
    int A,B;
    cin >> A >> B;
    string U;
    cin >> U;
    if ( S == U ){
        cout << A - 1 << " " << B << endl;
    } else if ( T == U ){
        cout << A << " " << B - 1 << endl;
    } else {
        cout << A << " " << B << endl;
    }
    return 0;
}


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

int main(void){
    int N, M;
    int i;
    cin >> N >> M;
    vector<bool> broken(2*N, false);
    vector<ll> res(2*N);
    for(i = 0 ; i < M; i++){
        ll a;
        cin >> a;
        broken[a] = true;
    }
    res[0] = 1;
    res[1] = broken[1]? 0 : 1;
    for(i = 2; i <= N; i++){
        res[i] = (broken[i] ? 0 : res[i-1] + res[i-2]);
        res[i] %= (ll)1e9+7;
    }
    cout << res[N] << endl; 
    return 0;
}


Measured memory_bytes: 1792
#include <string>
#include <set>
#include <iostream>
#include <algorithm>

using namespace std;

int main() {
  int m;
  cin >> m;
  int sum[m];

  for(int i=0;i<m;i++){

    string A,l,r;
    set<string> a;
    cin >> A;
    for(int j=1;j<A.size();j++){
      for(int k=0;k<2;k++) {
	l=A.substr(0,j);
	r=A.substr(j);

	if(k==1)swap(l,r);

	a.insert(l+r);
	reverse(l.begin(), l.end());
	a.insert(l+r);
	reverse(r.begin(), r.end());
	a.insert(l+r);
	reverse(l.begin(), l.end());
	a.insert(l+r);
      }
    }
    sum[i] = a.size();
  }
  for(int i=0;i<m;i++)
    cout << sum[i] << endl;
  return 0;
}

Measured memory_bytes: 960
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,l,r) for(int i=l;i<=r;i++)
#define in(x) scanf("%d",&x)
#define out(x) printf("%d\n",x)
#define ll long long

int n,m,k[15],a[15][15],p[15],ans,flag,sum;
signed main(){
	in(n),in(m);
	FOR(i,1,m){
		in(k[i]);
		FOR(j,1,k[i]){
			in(a[i][j+1]);
		}
	}
	FOR(i,1,m)
	in(p[i]);
	ans=0;
	for(int i=0;i<(1<<n);i++){
		flag=0;
		for(int j=1;j<=m;j++){
			sum=0;
			for(int r=1;r<=k[j];r++){
				if((1<<(a[j][r+1]-1))&i){
					sum++;
				}
			}
			if(sum%2!=p[j]){			
				flag=1;
			}
		}
		if(!flag)ans++;
	}
	cout<<ans<<endl;
	return 0;
} 

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

typedef long long ll;
#define pii pair<int , int>
#define _FastIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define MAXX 1005

int a , b;

int main()
{
    _FastIO;
    cin >> a >> b;
    int k = a + b - 1;
    cout << a * b - k << endl;
    return 0;
}
	

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

public class Main {
    public static int[][] memo;

    public static void main(String[] args){
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int k = scanner.nextInt();
        Set<Integer> set = new HashSet<Integer>();
        for(int i = 1; i <= n; i++){
            set.add(scanner.nextInt());
        }
        memo = new int[3][k+1];
        memo[1][0] = 2;
        memo[2][0] = 1;
        int res = play(set, k, 1, 2);
        if(res==1){
            System.out.println("First");
        }else{
            System.out.println("Second");
        }
    }

    public static int play(Set<Integer> set, int k, int first, int second){
        if(memo[first][k]!=0) return memo[first][k];
        for(Integer i : set){
            if(k-i>=0) {
                int aux = play(set, k - i, second, first);
                if (aux == first) {
                    memo[first][k] = first;
                    break;
                }
            }
        }
        if(memo[first][k]!=first) memo[first][k] = second;
        return memo[first][k];
    }
}


Measured memory_bytes: 43404
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n, k, min=10000;
    int loop = 1;
    int num = 0;
    int ans = 1;
    cin >> n >> k;
    
    for(int i=0; i< n;i++){
        loop *=2;
    }
    
    for(int i=0; i< loop;i++){
        for(int j=0; j< n;j++){
            num = i >> j;
            
            if((num&0x01) == 0){
                ans *=2;
            }else{
                ans += k;
            }
        }

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

Measured memory_bytes: 256
// template version 1.6
// {{{ define basic macro
using namespace std;
#include <iostream>
#include <bits/stdc++.h>
// varibable settings
#define int long long
#define INF 1000000000000000000LL
// #define INF 2147483647
#define MOD 1000000007LL
// #define MOD 998244353LL
#define infile "../test/sample-1.in"

#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define _rrep(i,n) rrepi(i,0,n)
#define rrepi(i,a,b) for(int i=(int)(b-1);i>=(int)(a);--i)
#define rrep(...) _overload3(__VA_ARGS__,rrepi,_rrep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define pb(a) push_back(a)
#define mp(a, b) make_pair(a, b)
#define uni(x) sort(all(x));x.erase(unique(all(x)),x.end())
#define ten(n) ((int)1e##n)
template<class T, size_t N> size_t sza(const T (&array)[N]) { return N; }
template<class T> inline void chmax(T &a, const T &b) { if(a < b) a = b; }
template<class T> inline void chmin(T &a, const T &b) { if(a > b) a = b; }
template<class T=int> T in() {T x; cin>>x; return (x);}
struct Fast { Fast(){ std::cin.tie(0); ios::sync_with_stdio(false); } } fast;

// dump macro
#ifdef PCM
  #include "dump.hpp"
#else
  #define dump(...) 42
  #define dump_1d(...) 42
  #define dump_2d(...) 42
#endif

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef long double ld;
typedef pair<int,int> pii;
typedef tuple<int,int,int> iii;
template<typename T> using PQ = priority_queue<T, vector<T>, greater<T>>;
int dx[]={1, -1, 0, 0};
int dy[]={0, 0, 1, -1};
#define fi first
#define se second

// }}}

int solve(){
  int n;cin>>n;
  int a[n]; rep(i, n) {cin>>a[i];}

  int tmp=0;
  int maxidx = -1;
  rep(i, n){
    if (abs(a[i])>=tmp) {
      tmp = abs(a[i]);
      maxidx = i;
    }
  }
  dump(maxidx);

  cout << 2*n << endl;
  if (a[maxidx]>=0){
    cout << maxidx+1 << " " << "1" << endl;
    cout << maxidx+1 << " " << "1" << endl;
    rep(i, 1, n){
      cout << i << " " << i+1 << endl;
      cout << i << " " << i+1 << endl;
    }
  }
  else{
    cout << maxidx+1 << " " << n << endl;
    cout << maxidx+1 << " " << n << endl;
    rrep(i, 1, n){
      cout << i+1 << " " << i << endl;
      cout << i+1 << " " << i << endl;
    }
  }

  return 0;
}

signed main() { //{{{
#ifdef INPUT_FROM_FILE
  std::ifstream in(infile);
  std::cin.rdbuf(in.rdbuf());
#endif
  solve();
  return 0;
} //}}}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
 
const int mod = 1e+9 + 7;
 
int main(){
    int n, k;
    cin >> n >> k;
    ll sum = 0;
    for(ll i = k; i <= n + 1; i++){
        ll l = (i - 1) * i / 2;
        ll r = i * (n - i + 1 + n) / 2;
        sum += r - l + 1;
        sum %= mod;
    }
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 3632
#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif
#pragma comment(linker, "/STACK:1024000000,1024000000")
#define MOD 1000000007
#define INF 0x3f3f3f3f
#define EPS 1e-10
#define set0(x) memset((x),0,sizeof(x))
#define setINF(x) memset((x),63,sizeof(x))
/*
	Problem: Coins
	Source: AtCoder Grand Contest 018
	Author: fts2001 (the_silliest)
 */
using namespace std;
const int N=100005;
int x,y,z,n,a[N],b[N],c[N],ind[N];
long long l[N],r[N];
inline bool cmp(int x,int y){
    return (a[x]-b[x])<(a[y]-b[y]);
}
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin>>x>>y>>z;
    n=x+y+z;
    for(int i=0;i<n;i++){
        cin>>a[i]>>b[i]>>c[i];
        ind[i]=i;
    }
    sort(ind,ind+n,cmp);
    priority_queue<int> pq;
    for(int i=1;i<=n;i++){
        l[i]=l[i-1]+b[ind[i-1]];
        pq.push(c[ind[i-1]]-b[ind[i-1]]);
        if(i>y){
            l[i]+=pq.top();
            pq.pop();
        }
    }
    while(!pq.empty())pq.pop();
    for(int i=n-1;i>=0;i--){
        r[i]=r[i+1]+a[ind[i]];
        pq.push(c[ind[i]]-a[ind[i]]);
        if(n-i>x){
            r[i]+=pq.top();
            pq.pop();
        }
    }
    long long ans=0;
    for(int i=y;i<=n-x;i++){
        ans=max(ans,l[i]+r[i]);
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3832
N = int(input())
A = {}
B = {}
C = {}

for i in range(N):
    A[i+1], B[i+1], C[i+1] = map(int, input().split())

dp = {}

dp[1] = {}
dp[1][0] = A[1]
dp[1][1] = B[1]
dp[1][2] = C[1]

for i in range(2, N+1):
    dp[i] = {}
    dp[i][0] = A[i]+max(dp[i-1][1],dp[i-1][2])
    dp[i][1] = B[i]+max(dp[i-1][0],dp[i-1][2])
    dp[i][2] = C[i]+max(dp[i-1][0],dp[i-1][1])

print(max(dp[N][0],dp[N][1],dp[N][2]))


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

typedef long long int int64;

#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))
#define ABS(a,b) ((a)>(0)?(a):-(a))

#include<stdio.h>
#include<stdlib.h>
#include<math.h>

typedef long long int int64;

#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))
#define ABS(a,b) ((a)>(0)?(a):-(a))

int main(void){
int a, b ;
scanf("%d",&a);
scanf("%d",&b);
if(a < 9 && b <9 ){
printf("Yay!");
}else{
printf(":(");
}
return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  vector<int> p(N);
  for (int i = 0; i < N; i++) {
    cin >> p.at(i);
  }
  sort(p.begin(), p.end());
  bool a = true;
  for (int i = 0; i < N - 1; i++) {
    if (p.at(i) == p.at(i + 1)) {
      a = false;
      cout << "NO" <<endl;
      break;
    }
  }
  if (a) {
    cout << "YES" <<endl;
  }
}

Measured memory_bytes: 1024
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <tuple>
# include <unordered_map>
# include <numeric>
# include <complex>
# include <bitset>
# include <random>
# include <chrono>
# include <cstdlib>
# include <tuple>
# include <array>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
using D = double;
constexpr int INF = 2147483647;
constexpr int HINF = INF / 2;
constexpr double DINF = 100000000000000000.0;
constexpr double HDINF = 50000000000000000.0;
constexpr long long LINF = 9223372036854775807;
constexpr long long HLINF = 4500000000000000000;
const double PI = acos(-1);
template <typename T_char>T_char TL(T_char cX) { return tolower(cX); };
template <typename T_char>T_char TU(T_char cX) { return toupper(cX); };
typedef pair<LL, LL> pii;
const int vy[] = { -1, -1, -1, 0, 1, 1, 1, 0 }, vx[] = { -1, 0, 1, 1, 1, 0, -1, -1 };
const int dx[4] = { 0,1,0,-1 }, dy[4] = { 1,0,-1,0 };
int popcnt(unsigned long long n) { int cnt = 0; for (int i = 0; i < 64; i++)if ((n >> i) & 1)cnt++; return cnt; }
int d_sum(LL n) { int ret = 0; while (n > 0) { ret += n % 10; n /= 10; }return ret; }
int d_num(LL n) { int ret = 0; while (n > 0) { ret++; n /= 10; }return ret; }
LL gcd(LL a, LL b) { if (b == 0)return a; return gcd(b, a%b); };
LL lcm(LL a, LL b) { LL g = gcd(a, b); return a / g*b; };
# define ALL(qpqpq)           (qpqpq).begin(),(qpqpq).end()
# define RALL(qpqpq)           (qpqpq).rbegin(),(qpqpq).rend()
# define UNIQUE(wpwpw)        sort(ALL((wpwpw)));(wpwpw).erase(unique(ALL((wpwpw))),(wpwpw).end())
# define LOWER(epepe)         transform(ALL((epepe)),(epepe).begin(),TL<char>)
# define UPPER(rprpr)         transform(ALL((rprpr)),(rprpr).begin(),TU<char>)
# define FOR(i,tptpt,ypypy)   for(LL i=(tptpt);i<(ypypy);i++)
# define RFOR(i,tptpt,ypypy)  for(LL i=(tptpt);i>=(ypypy);i--)
# define REP(i,upupu)         FOR(i,0,upupu)
# define INIT                 std::ios::sync_with_stdio(false);std::cin.tie(0)

int c, n;
string s[101010];
int cnt[1010][1010];

int calc(int pos) {
	if (pos < n / 2)return pos;
	return n - pos - 1;
}

int main() {
	cin >> c >> n;
	REP(i, n) {
		cin >> s[i];
	}
	REP(i, n)REP(j, n) {
		if(s[i][j]=='1')cnt[calc(i)][calc(j)]++;
	}
	int ngcnt = 0;
	REP(i, n / 2)REP(j, n / 2) {
		if (cnt[i][j] % 4 != 0)ngcnt++;
	}
	int ans = 0;
	if (ngcnt == 0)ans++;
	REP(ccc, c - 1) {
		int d;
		cin >> d;
		REP(i, d) {
			int r, c;
			cin >> r >> c;
			r--, c--;
			if (s[r][c] == '1') {
				s[r][c] = '0';
				cnt[calc(r)][calc(c)]--;
				if (cnt[calc(r)][calc(c)] % 4 == 0)ngcnt--;
				else if (cnt[calc(r)][calc(c)] % 4 == 3)ngcnt++;
			}
			else {
				s[r][c] = '1';
				cnt[calc(r)][calc(c)]++;
				if (cnt[calc(r)][calc(c)] % 4 == 0)ngcnt--;
				else if (cnt[calc(r)][calc(c)] % 4 == 1)ngcnt++;
			}
		}
	
		if (ngcnt == 0) {
			ans++;
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 6904
h,w = map(int,input().split())
ans = []
for i in range(h):
    
    s = list(input())
    tmp = ["#"] + s + ["#"]
    ans.append(tmp)

aaa = [["#"] * (w+2)]
aaa.extend(ans)
aaa.append(["#"] * (w+2))

for i in aaa:
    print("".join(i))




Measured memory_bytes: 38384
def bisect(L,a):
    if L == []:
        return 0
    n = len(L) - 1
    if L[n/2] == a:
        return 1
    elif L[n/2] > a:
        return bisect(L[:n/2], a) + 1
    return bisect(L[n/2+1:], a) + 1

while True:
    n = input()
    if n == 0:
        break
    print bisect([input() for _ in xrange(n)], input())

Measured memory_bytes: 4220
///
// File:  c.go
// Author: ymiyamoto
//
// Created on Sat Jun 16 23:19:12 2018
//
package main

import "fmt"

var N int
var arr []int

func pow2(n int) int {
	ret := 0
	for n%2 == 0 {
		n /= 2
		ret++
	}
	return ret
}
func main() {
	fmt.Scan(&N)

	ans := 0
	for i := 0; i < N; i++ {
		var a int
		fmt.Scan(&a)
		ans += pow2(a)

	}
	fmt.Println(ans)
}


Measured memory_bytes: 1280
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
#include <ctype.h>
#include <map>
#include <vector>
#include <stdlib.h>
#define REP(i,n) for(int i=0;i<(int)n;++i)
#define REP1(j,n) for(int j=0;j<(int)n;++j)
#define REPD(i,n) for(int i=n;i>=0;--i)
#define REPD1(j,n) for(int j=n;j=>0;--j)
#define REPS(i,n) for(int i=1;i<=(int)n;++i)
#define REPS1(j,n) for(int j=1;j<=(int)n;++j)
#define rep(i,a,n) for(int i=a;i<=(int)n;++i)
#define SZ(x) ((int)(x).size())	//size() unsigned -> int
#define DescSort(a) sort(a.begin(),a.end(),std::greater<int>())

using namespace std;
typedef long long ll;

int main(void) {
	string s;
	int n, q;
	cin >> n >> q;
	cin >> s;
	vector<int> l(q), r(q);
	REP(i, q)cin >> l[i] >> r[i];
	vector<int> t(n+1,0);
	//累積和
	//ACが出る可能性は2文字目から
	for (int i = 1; i < n;i++) {
		t[i + 1] = t[i];
		if (s[i - 1] == 'A'&&s[i] == 'C') {
			t[i + 1]++;
		}
	}
	//0,1,2,3,4,5
	//A C A C A C
	//1 2 3 4 5 6
	REP(i, q) {
		cout << t[r[i]] - t[l[i]] << endl;
	}
	return 0;
}


Measured memory_bytes: 2176
from collections import Counter
s = input()
count = Counter(s).most_common()
ans = 100
for c,n in count:
    ss = s
    cnt = 0
    while any(ssi != ss[0] for ssi in ss):
        ss_new = ""
        for i in range(len(ss)-1):
            if ss[i] != c and ss[i+1] == c:
                ss_new += c
            else:
                ss_new += ss[i]
        ss = ss_new
        cnt += 1
    if cnt < ans:
        ans = cnt

print(ans)

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

public class Main {

	public static void main(String args[]) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		long n = Long.parseLong(br.readLine());
		String s = String.valueOf(n);
		String str[] = s.split("");

		int ans = 0;
		for (int i = 0; i < str.length; i++) {
			ans += Integer.parseInt(str[i]);
		}

		int down = ((Integer.parseInt(str[0]) - 1));

		for (int i = 0; i < str.length - 1; i++) {
			down += 9;
		}

		ans = Math.max(ans, down);
		System.out.println(ans);
	}
}


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

int n, m, q;
vector<int> a, b, c, d;
int ans = 0;

void dfs(vector<int> A)
{
    if (A.size() == n+1) {
        //calc score
        int score = 0;
        for (int i = 0; i < q; i++) {
            if (A[b[i]] - A[a[i]] == c[i])
                score += d[i];
        }
        ans = max(ans, score);
        return;
    }

    A.push_back(A.back());
    while (A.back() <= m) {
        dfs(A);
        A.back()++;
    }
}

int main()
{
    cin >> n >> m >> q;
    a = b = c = d = vector<int>(q);
    for (int i = 0; i < q; i++)
        cin >> a[i] >> b[i] >> c[i] >> d[i];
    
    dfs(vector<int>(1,1));

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3656
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define endl '\n'
#define rep(i, n)    for(ll i = 0; i < (n); ++i)
#define repA(i, a, n)  for(ll i = a; i <= (n); ++i)
#define repD(i, a, n)  for(ll i = a; i >= (n); --i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (ll)(x).size()
#define unique_sort(x) (sort(x.begin(), x.end()), x.resize(distance(x.begin(), unique(x.begin(), x.end()))))
#define fill(a)  memset(a, 0, sizeof (a))
#define ff first
#define ss second
#define pb push_back
typedef long double ld;
typedef vector<ll> vll;
const ll INF = 1e18;
const ld PI = 4*atan((ld)1);
const ll mod = 1e9+7;

int main()
{
    ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    ll tt=1;
        // cin >> tt;
    while((tt)--){
        ll n;cin >> n;
        ll f=0;
        while(n!=0){
           ll t= n%10;
           n/=10;
           if(t==7){
             f=1; break;
           }
        }
        if(f){
            cout << "Yes" << endl;
        }else{
            cout << "No" << endl;
        }
    }
}


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

signed main(){
	int A,B; cin>>A>>B;
	int ans=-1;
	for(int i=0;i<1000000;i++){
		if(A==floor(0.08*i) && B==floor(0.1*i)){
			ans=i; break;
		}
	}
	cout<<ans<<endl;
}

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

int w,h;
int ans;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

bool canmove(int x,int y){
  return (0 <= x && x < w && 0 <= y && y < h);
}

struct Map{
  int map[20][20];
  int s,g;
  int cnt;
  int cur;
  Map(int m[20][20]){
    for(int i=0;i<h;i++){
      for(int j=0;j<w;j++){
	map[i][j]=m[i][j];
	if(m[i][j]==2) s=i*32+j;
	if(m[i][j]==3) g=i*32+j;
      }
    }
    cnt=0;
    cur=s;
  }
  Map(int m[20][20],int curling,int _cnt){
    for(int i=0;i<h;i++){
      for(int j=0;j<w;j++){
	map[i][j]=m[i][j];
	if(m[i][j]==2) s=i*32+j;
	if(m[i][j]==3) g=i*32+j;
      }
    }
    cnt=_cnt;
    cur=curling;
  }
  Map move(int direc){
    Map m(map,cur,cnt+1);
    int y=cur/32,x=cur%32;
    if(canmove(x+dx[direc],y+dy[direc]) && map[y+dy[direc]][x+dx[direc]]==1){
      m.cnt=100;
      return m;
    }
    int k=1;
    while(true){
      bool b=canmove(x+k*dx[direc],y+k*dy[direc]);
      int num=map[y+k*dy[direc]][x+k*dx[direc]];
      if(b && num==3){
	m.cur=g;
	break;
      }
      else if(b && num!=1) k++;
      else if(b && num==1){
	m.map[y+k*dy[direc]][x+k*dx[direc]]=0;
	k--;
	m.cur=(y+k*dy[direc])*32+x+k*dx[direc];
	break;
      }else{
	m.cnt=100;
	break;
      }
    }
    // cout<<m.cnt<<endl;
    return m;
  }
};

void dfs(Map m){
  if(m.cnt > 10) return;
  if(m.cnt >= ans) return; 
  if(m.cur == m.g){
    ans = min(m.cnt,ans);
    return;
  }
  for(int i=0;i<4;i++){
    dfs(m.move(i));
  }
}

int main(){
  while(cin>>w>>h,w+h){
    int map[20][20];
    ans=1000;
    for(int i=0;i<h;i++) for(int j=0;j<w;j++) cin>>map[i][j];
    Map m(map);
    dfs(m);
    if(ans == 1000) cout<<-1<<endl;
    else cout<<ans<<endl;
  }
  return 0;
}

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

typedef long long int ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef vector<string>vst;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;
typedef map<int,int> dct;

#define fastio ios_base::sync_with_stdio(false);cin.tie(0)
#define all(ct) ct.begin() , ct.end()
#define endl "\n"
#define fr(i,a) for(auto i:a)
#define f(i,a,b) for(int i=a;i<b;++i)
#define fd(i,a,b) for(int i=a;i>=b;--i)
#define pb push_back
#define in(d,v) d.find(v)!=d.end()
#define mp make_pair
#define pi 3.14159265

bool compare(pll a, pll b){
    return a.first*b.second<a.second*b.first;
}

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

ll modexp(ll x,ll n){
    if(n==0)return 1;
    if(n%2==0)return modexp((x*x)%mod,n/2);
    return (x*modexp((x*x)%mod,n/2))%mod;
}

int main(){
    //clock_t tm = clock();
    fastio;
    ll n,k;
    cin>>n>>k;
    vl a(n),cm(n+1,0);
    f(i,0,n)cin>>a[i];
    sort(all(a));
    f(i,0,n)cm[i+1]=(cm[i]+a[i])%mod;
    ll ans=0,curr;
    if(k==1){
        cout<<0<<endl;
        return 0;
    }
    vl fac(n+1,1);
    f(i,2,n+1)fac[i]=(i*fac[i-1])%mod;
    f(i,k-1,n){
        curr=(cm[n]-cm[i]+mod)%mod;
        curr=(curr-cm[n-i]+mod)%mod;
        ll fc=(fac[i-1]*modexp(fac[k-2],mod-2))%mod;
        fc=(fc*modexp(fac[i-k+1],mod-2))%mod;
        ans=(ans+(fc*curr)%mod)%mod;
    }
    cout<<ans<<endl;
    //cout<<((clock()-tm)*1.0)/CLOCKS_PER_SEC<<endl;
}

Measured memory_bytes: 2560
local r = 1 << 29
local n = tonumber(io.read("*l"))
for _ in io.read("*l"):gmatch("%d+") do
  local r0 = 0
  local k = tonumber(_)
  while k % 2 < 1 do
    r0 = r0 + 1
    k = k // 2
  end
  if r > r0 then
    r = r0
  end
end
return print(r)


Measured memory_bytes: 256
#include<stdio.h>
int function( int a)
{
    while( a != 0)
    {
        if( a%10==7)
        {
            return 1 ;
            break ;
        }
        a = a/10 ;
    }
    return 0 ;
}
int main( )
{
    int a ;
    scanf("%d" , &a);
    if( function(a) == 1)
        printf("Yes\n");
    else
        printf("No\n");
        return 0;
}

Measured memory_bytes: 2060
#include <stdio.h>

int main () {
    char s[200001];
    long i=0,j=0,c=0;

    scanf("%s",s);
    while(s[i]!='\0') {
        if(s[i]=='B') j++;
        else c+=j;
        i++;
    }

    printf("%ld\n",c);
    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;

int N, A, B;
ll v[50];
ll comb[51][51];

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  cin >> N >> A >> B;
  for (int i = 0; i <= N; i++) {
    comb[i][0] = comb[i][i] = 1;
    for (int j = 1; j < i; j++) {
      comb[i][j] = comb[i - 1][j - 1] + comb[i - 1][j];
    }
  }
  for (int i = 0; i < N; i++) {
    cin >> v[i];
  }
  sort(v, v + N);
  reverse(v, v + N);
  double ave = 0;
  for (int i = 0; i < A; i++) {
    ave += v[i];
  }
  ave /= A;
  ll cnt = 0;
  int p = 0, q = 0;
  for (int i = 0; i < N; i++) {
    if (i < A) p += v[i] == v[A - 1];
    q += v[i] == v[A - 1];
  }
  if (v[0] == v[A - 1]) {
    for (int i = A; i <= min(B, q); i++) {
      cnt += comb[q][i];
    }
  } else {
    cnt = comb[q][p];
  }
  cout << ave << endl;
  cout << cnt << endl;

  return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
 
int main(){
 
  int n, m, e, a[100000];
  bool f[200001]={};
 
  cin>>n>>m;
  for(int i=0;i<m;i++){
    cin>>e;
    a[i]=e;
  }
 
  for(int i=m-1;i>=0;i--){
    if(f[a[i]]==false){
      cout<<a[i]<<endl;
      f[a[i]]=true;
    }
  }
  for(int i=1;i<=n;i++){
    if(f[i]==false) cout<<i<<endl;
  }
 
  return 0;
}

Measured memory_bytes: 3668
#include<bits/stdc++.h>
#define mod 1000000007
#define ll long long
#define ff first
#define pb push_back
#define ss second
#define maxn 500005
using namespace std;

vector<ll> v;
ll sum, res, mn = 1e18;
int main(){

    int n;
    cin >> n;
    for(int i=1;i<=n;i++){
        ll x;
        cin >> x;
        sum += x;
        v.pb(x);
    }
    for(auto x: v){
        res += x;
        mn = min(mn, abs( (sum-res)-res) );
    }
    cout << mn << endl;

    return 0;
}


Measured memory_bytes: 2420
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <string>
#include <cstring>
#include <ctime>


using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }

//math
//-------------------------------------------
template<class T> inline T sqr(T x) { return x*x; }

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define EXISTch(s,c) ((((s).find_first_of(c)) != std::string::npos)? 1 : 0)//cがあれば1 if(1)
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  FOR(i,0,n)
#define loop(n) FOR(i,0,n)
#define rrep(i,a,b) for(int i=(a);i>=(b);--i)
//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int INF = (int)1000000007;
const LL MOD = (LL)1000000007;//10^9+7
const LL INF2 = (LL)100000000000000000;//10^18

int main() {
	for (int i = 1; i < 10; i++) {
		for (int j = 1; j < 10; j++) {
			cout << i << "x" << j << "=" << i*j << endl;
		}
	}

	return 0;
}




Measured memory_bytes: 3104
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

public class Main {

    static PrintWriter out;
    static Scanner sc;

    static void solve() {
        String s = nextString();
        if (s.indexOf('a') != -1 && s.indexOf('b') != -1 && s.indexOf('c') != -1) {
            out.println("Yes");
        } else {
            out.println("No");
        }
    }

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

    static long nextLong() {
        return Long.parseLong(sc.next());
    }

    static String nextString() {
        return sc.next();
    }

    static int[] nextIntArray(int n) {
        int[] a = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = nextInt();
        }
        return a;
    }

    static List<Integer> nextIntList(int n) {
        List<Integer> list = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            list.add(nextInt());
        }
        return list;
    }

    static List<Long> nextLongList(int n) {
        List<Long> list = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            list.add(nextLong());
        }
        return list;
    }

    static <T extends Comparable<? super T>> void sort(List<T> list) {
        Collections.sort(list);
    }

    // greatest common divisor
    static long gcd(long a, long b) {
        if (b == 0) {
            return a;
        }
        return gcd(b, a % b);
    }

    // baseのn乗を計算を返す
    static int pow(int base, int n) {
        int ret = 1;
        for (int i = 0; i < n; i++) {
            ret *= base;
        }
        return ret;
    }

    // intをlength桁のbit文字列に変換
    static String toBinaryString(int input, int length) {
        return toBinaryString(input).substring(29 - length);
    }

    // intを29桁のbit文字列に変換
    static String toBinaryString(int input) {
        String ret = "";
        int max = 0x10000000;
        for (int i = 0; i < 29; i++) {
            int tmp = input / max;
            ret += tmp;
            input %= max;
            max /= 2;
        }
        return ret;
    }

    public static void main(String[] args) {
        out = new PrintWriter(System.out);
        sc = new Scanner(System.in);

        solve();

        out.flush();
        sc.close();
    }

}


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

using namespace std;

int main() {
	ios_base::sync_with_stdio(false);
	int n, k, x, y;
	cin >> n >> k >> x >> y;
	int result;
	if (n >= k) {
		result = k * x + (n-k) * y;
	}
	else {
		result = n * x;
	}
	cout << result << '\n';
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner

object Main extends App {
  val sc = new Scanner(System.in)

  val n = sc.nextInt
  val s = sc.next

  val w =
    0 +:
      s.foldLeft(Vector.empty[Int]){case (v,c) =>
        if(v.isEmpty) Vector( if (c == '.') 1 else 0)
        else v :+ ( v.last + (if(c == '.') 1 else 0))
  }

  val res =
    (0 to n).foldLeft(Int.MaxValue){case (min, i) =>
      val preB  = i - w(i)
      val postW = w(n) - w(i)
      Math.min(min, preB + postW)
  }

  println(res)
}


Measured memory_bytes: 54028
#include<stdio.h>

int main(void)
{
	unsigned long long int a, b, c = 1, d = 0;
	int i;

	scanf("%lld", &a);

	for (i = 0; i < a; i++) {
		scanf("%lld", &b);

		if (d != 1) {
			if (18 < log10(b) + log10(c)) {
				d = 1;
			}
			else if (1000000000000000000 < c * b) {
				d = 1;
			}
		}

		else if (b == 0) {
			d = 0;
		}
		c = c * b;
	}

	if (d == 0) {
		printf("%lld", c);
	}

	else {
		printf("-1");
	}


	return 0;
}

Measured memory_bytes: 2496