akhauriyash/Code-Regression huggingface dataset:
class Card():
    def __init__(self, num, mark):
        self.num = num
        self.mark = mark

    def __eq__(self, other):
        if other is None or not isinstance(other, Card):
            return False
        return self.__dict__ == other.__dict__

    def __ne__(self, other):
        return not self.__eq__(other)


def partition(array, start, end):
    end_val = array[end].num
    left_end = start - 1
    for search_idx in range(start, end):
        if array[search_idx].num <= end_val:
            left_end += 1
            array[left_end], array[search_idx] = array[search_idx], array[left_end]
    array[left_end + 1], array[end] = array[end], array[left_end + 1]
    return left_end + 1


def quicksort(array, start, end):
    if start < end:
        pivot_index = partition(array, start, end)
        quicksort(array, start, pivot_index - 1)
        quicksort(array, pivot_index + 1, end)


def mergesort(array, n):
    if n <= 1:
        return array
    left_end = n // 2
    left_sorted = mergesort(array[:left_end], left_end) + [Card(10**9, None)]
    right_sorted = mergesort(array[left_end:], n - left_end) + [Card(10**9, None)]
    left_idx, right_idx = 0, 0
    idx = 0
    sorted_list = [None] * n
    while idx < n:
        if left_sorted[left_idx].num <= right_sorted[right_idx].num:
            sorted_list[idx] = left_sorted[left_idx]
            left_idx += 1
        else:
            sorted_list[idx] = right_sorted[right_idx]
            right_idx += 1
        idx += 1
    return sorted_list


def main():
    n = int(input())
    cards = []
    for _ in range(n):
        mark, number = input().split(" ")
        cards.append(Card(int(number), mark))
    mergesorted_cards = mergesort(cards, n)
    quicksort(cards, 0, n - 1)
    message = "Stable"
    for i in range(n):
        if mergesorted_cards[i] != cards[i]:
            message = "Not stable"
    print(message)
    for i in range(n):
        print("{} {}".format(cards[i].mark, cards[i].num))


if __name__ == "__main__":
    main()



Measured memory_bytes: 27624
#include <iostream>
#include <string>
#include <vector>
#include <climits>
#include <set>
#include <algorithm>
#include <unordered_map>
#include <queue>
#include <iomanip>
#include <map>
#include <utility>
#include <numeric>
#include <chrono>
#include <ctime>
#include <bitset>

#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define P pair<int, int>
#define debug(x) cerr << #x << ": " << x << ", "
#define debugln(x) cerr << #x << ": " << x << '\n'

using namespace std;
using ll = long long;
const ll mod = 1e9+7;

vector<vector<int>> dp = vector<vector<int>>(2, vector<int>(21));

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

  int n; cin >> n;
  vector<ll> a(n);
  rep(i, n) {
    cin >> a.at(i);
  }

  ll before = a.at(n-1);
  ll ans = 0;
  vector<ll> ans1(n);
  ans1.at(n-1) = 0;
  dp[0][0] = 1;
  for(int i=n-2; i>=0; i--) {
    ll tmp = a.at(i);
    int cnt = 0;
    if (tmp <= before) {
      while (tmp <= before) {
        tmp *= 4;
        cnt++;
      }
      cnt--;
      for(int j=0; j+cnt<=20; j++) {
        dp[1][j+cnt] = dp[0][j];
      }
    } else {
      while(before < tmp) {
        before *= 4;
        cnt++;
      }
      for(int j=0; j<=cnt; j++) {
        dp[1][0] += dp[0][j];
        ans += dp[0][j]*(cnt-j);
      }
      for(int j=cnt+1; j<=20; j++) {
        dp[1][j-cnt] = dp[0][j];
      }
    }
    before = a.at(i);
    ans1.at(i) = ans;
    dp[1][0]++;
    rep(j, 20) {
      dp[0][j] = dp[1][j];
      //debug(dp[0][j]);
      dp[1][j] = 0;
    }
    //cout << endl;
  }

  reverse(a.begin(), a.end());
  vector<ll> ans2(n);
  ans2.at(n-1) = 0;
  rep(i, 2) {
    rep(j, 20) {
      dp[i][j] = 0;
    }
  }
  dp[0][0] = 1;
  ans = 0;
  before = a.at(n-1);
  for(int i=n-2; i>=0; i--) {
    ll tmp = a.at(i);
    int cnt = 0;
    if (tmp <= before) {
      while (tmp <= before) {
        tmp *= 4;
        cnt++;
      }
      cnt--;
      for(int j=0; j+cnt<=20; j++) {
        dp[1][j+cnt] = dp[0][j];
      }
    } else {
      while(before < tmp) {
        before *= 4;
        cnt++;
      }
      for(int j=0; j<=cnt; j++) {
        dp[1][0] += dp[0][j];
        ans += dp[0][j]*(cnt-j);
      }
      for(int j=cnt+1; j<=20; j++) {
        dp[1][j-cnt] = dp[0][j];
      }
    }
    before = a.at(i);
    ans2.at(i) = ans;
    dp[1][0]++;
    rep(j, 20) {
      dp[0][j] = dp[1][j];
      //debug(dp[0][j]);
      dp[1][j] = 0;
    }
    //cout << endl;
  }

  rep(i, n) {
    ans1.at(i) *= 2;
    //debugln(ans1.at(i));
  }
  rep(i, n) {
    ans2.at(i) *= 2;
    ans2.at(i) += n-i;
    //debugln(ans2.at(i));
  }

  ll answer = LONG_MAX;
  answer = min(answer, ans1.at(0));
  answer = min(answer, ans2.at(0));

  for(int i=1; i<=n-1; i++) {
    answer = min(answer, ans1.at(i) + ans2.at(n-i));
  }

  cout << answer << endl;

  /*
  rep(i, n) {
    debugln(ans1.at(i));
  }*/

}

Measured memory_bytes: 4992
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef pair<ll,ll> pll;
const ll mod=1e9+7;
//const ll mod=998244353;
const ll inf=1LL<<61;

int main() {
  ll n;
  cin >> n;
  ll ans=0;
  map<pll,ll> cnt;
  for(ll i=1;i<=n;i++) {
    ll tmp=i;
    ll t=tmp%10;
    while(tmp>=10) {
      tmp/=10;
    }
    cnt[pll(tmp,t)]++;
  }
  for(auto p:cnt) {
    ans+=p.second*cnt[pll(p.first.second,p.first.first)];
  }
  cout << ans << endl;
}

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

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

struct Team {
    int num=0, ac=0, pen=0;
    int wa[15] = {0};
};

void solve(int M,int T,int P,int R) {
    vector<Team> teams(T+2);
    rep(i,T) teams[i].num=i+1;
    rep(i,R) {
        int time,tm, prg, msg;
        cin>>time>>tm>>prg>>msg;
        tm--; prg--;
        if(msg != 0) {
            teams[tm].wa[prg]++;
        } else {
            teams[tm].ac++;
            teams[tm].pen += teams[tm].wa[prg] * 20 + time;
        }
    }
    rep(i,T) rep(j,T-1) {
        if(teams[j].ac < teams[j+1].ac) swap(teams[j], teams[j+1]);
        if(teams[j].ac == teams[j+1].ac
                and teams[j].pen > teams[j+1].pen) swap(teams[j], teams[j+1]);
        if(teams[j].ac == teams[j+1].ac
                and teams[j].pen == teams[j+1].pen
                and teams[j].num < teams[j+1].num) swap(teams[j], teams[j+1]);
    }

    rep(i,T) {
        cout << teams[i].num;
        if(i+1 == T)
            puts("");
        else if(teams[i].ac == teams[i+1].ac and teams[i].pen == teams[i+1].pen)
            cout << '=';
        else
            cout << ',';
    }
}

int main() {
    int M,T,P,R;
    while(cin>>M>>T>>P>>R, T) solve(M,T,P,R);
    return 0;
}

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

#define jaldi ios_base::sync_with_stdio(false)
#define fr(i,j,n) for(i=j;i<n;i++)
#define si(x) scanf("%d",&x)
#define sl(x) scanf("%ld",&x)
#define sll(x) scanf("%lld",&x)
#define sc(x) scanf("%c",&x)
#define ss(x) scanf("%s",x)
#define pi(x) printf("%d",x)
#define pl(x) printf("%ld",x)
#define pll(x) printf("%lld",x)
#define pc(x) printf("%c",x)
#define ps(x) printf("%s",x)
#define vi vector<int> 
#define vl vector<long> 
#define vll vector<long long>
#define vc vector<char>  
#define vs vector<string>
#define vvi vector<vector<int>> 
#define vvll vector<vector<long long>> 
#define F first
#define S second
#define ll long long
#define pb push_back
#define ppii pair<int,int> 
#define ppll pair<long long,long long>
#define ppcc pair<char,char>
#define ppss pair<string,string> 
#define vpll vector<pair<long long,long long>>
#define PI 3.1415926535897932384626
#define precision(x) cout<<fixed<<setprecision(x) 
#define mod 1000000007

int x_d[8] = {-1,1,0,0,-1,-1,1,1};
int y_d[8] = {0,0,-1,1,-1,1,-1,1};

ll power(ll b,ll e)
{
    if(b==0)
        return 0;
    
    ll r=1;
    while(e>0)
    {
        if(e%2)
            r=(r*b)%mod;
        b=(b*b)%mod;
        e/=2;
    }
    return r;
}

int main()
{
    jaldi;
    precision(20);
    ll i,j;

    string s;
    cin>>s;
    if(s=="ABC")
        cout<<"ARC";
    else
        cout<<"ABC";

    return 0;
}

Measured memory_bytes: 3604
// template version 1.14
using namespace std;
#include <bits/stdc++.h>

// varibable settings
#define int long long
const int INF=1e18;
const int MOD=1e9+7;

// define basic macro {{{
#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 each(i,a) for (auto&& i : a)
#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 mt(a, b, c) make_tuple(a, b, c)
#define ceil(a,b) ((a)+(b)-1)/(b)
#define is_in(x, a, b) ((a)<=(x) && (x)<(b))
#define uni(x) sort(all(x));x.erase(unique(all(x)),x.end())
#define ub upper_bound
#define lb lower_bound
#define posl(A, x) (lower_bound(all(A), x)-A.begin())
#define posu(A, x) (upper_bound(all(A),x)-A.begin())
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); }

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>>;
struct Fast { Fast(){ std::cin.tie(0); ios::sync_with_stdio(false); } } fast;

#if defined(PCM) || defined(LOCAL)
  #include "lib/dump.hpp"
#else
  #define dump(...) 42
  #define dump_1d(...) 42
  #define dump_2d(...) 42
#endif
//}}}

signed main() {
  string s,t;cin>>s>>t;
  cout << t+s << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

int d[4];
string in;
int data[10000];

void solve(){
  bool f = true;
  for(int i=1;i<4;i++) if(in[0] != in[i]) f = false;
  if(f) cout << "NA" << endl;
  else{
    int ans = 0;
    for(int i=0;i<4;i++) d[i] = in[i] - '0';
    while(1){
      if(d[0] == 6 && d[1] == 1 && d[2] == 7 && d[3] == 4) break;
      int l = 0, s = 0;
      sort(d, d+4);
      for(int i=0;i<4;i++){
        s *= 10;
        s += d[i];
        l *= 10;
        l += d[3-i];
      }
      ans++;
      int tmp  = l - s;
      if(data[tmp] != -1){
        ans += data[tmp];
        break;
      }
      for(int i=0;i<4;i++){
        d[3-i] = tmp % 10;
        tmp /= 10;
      }
    }
    int tmp = 0;
    for(int i=0;i<4;i++){
      tmp *= 10;
      tmp += d[3-i];
    }
    data[tmp] = ans;
    cout << ans << endl;
  }
}

main(){
  fill(data, data+10000, -1);
  while(cin >> in){
    if(in == "0000") break;
    solve();
  }
}

Measured memory_bytes: 1248
#include <bits/stdc++.h>
#include <iostream>
using namespace std;
#define ll long long 
int main()
{
	ll n,a,b;
    cin>>n>>a>>b;
    ll x=a+b;
    cout<<a*(n/x)+min(a,n%x)<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cmath>
using namespace std;
typedef long long ll;
ll N, K, ans;
int main() {
  scanf("%ld %ld", &N, &K);
  if(K%2 == 0) ans += pow((N+K/2)/K, 3);
  ans += pow(N/K, 3);
  printf("%ld\n", ans);
}

Measured memory_bytes: 128
n = gets.chomp.to_i
s = gets.chomp

a = []
(0...n).each do |i|
  a << i if s[i] == '#'
end

if a.empty?
  puts 0

else
  w = []
  w[0] = a[0] == 0 ? 0 : s[0, a[0] - 1].count('#')
  (1...a.length).each do |i|
    w[i] = w[i - 1] + s[a[i - 1], a[i] - a[i - 1]].count('#')
  end

  b = []
  b[a.length - 1] = s[a[-1], n - a[-1]].count('.')
  (a.length - 2).downto(0).each do |i|
    b[i] = b[i + 1] + s[a[i], a[i + 1] - a[i]].count('.')
  end

  counts = []
  (0...a.length).each do |i|
    counts[i] = w[i] + b[i]
  end
  counts << s.count('#')

  puts counts.min
end


Measured memory_bytes: 8568
#include<cstdio>
#include<algorithm>
#include<cmath>
using namespace std;
typedef long long ll;
int a,b,c,d;
ll ans;
int main(){
	scanf("%d %d %d %d",&a,&b,&c,&d);
	ans=max(max(1ll*a*d,1ll*a*c),max(1ll*b*c,1ll*b*d));
	printf("%lld\n",ans);
	return 0;
}


Measured memory_bytes: 1720
import java.util.*;

//update 2020/1/1 23:01

public class Main{

  static Scanner sc = new Scanner(System.in);
  static StringBuilder sb = new StringBuilder();

  public static void main(String[] args) {

    int n = nextInt();
    int k = nextInt();
    double[] p = new double[n];
    for(int i=0;i<n;i++){
      p[i] = nextDouble();
    }

    double[] eachK = new double[n-k+1];

    double firstSum = 0;

    double max = 0;

    for(int i=0;i<k;i++){
      firstSum += (1+p[i])/2;
    }

    max = firstSum;

    for(int i=1;i<n-k+1;i++){
      firstSum -= (1+p[i-1])/2;
      firstSum += (1+p[i+k-1])/2;
      max = Math.max(max,firstSum);
    }


    System.out.println(max);

  }
  /*
    static String toSmall(String s){
      char c = s.charAt(0);
      //if(Character.isUpperCase(c)){
      if(c<=90){
        c += 32;
      }
      return String.valueOf(c);
    }
    static String toBig(String s){
      char c = s.charAt(0);
      //if(Character.isLowerCase(c)){
      if(c>=97){
        c -= 32;
      }
      return String.valueOf(c);
    }
  */

  static String toSmall(String s){
    return s.toLowerCase();
  }

  static String toBig(String s){
    return s.toUpperCase();
  }

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

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

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

  static double nextDouble(){
    return Double.parseDouble(sc.next());
  }

  static String[] splitString(String s){
    return s.split("");
  }

  static char[] splitChar(String s){
    return s.toCharArray();
  }

  static int charToInt(char a){
    return a - 48;
  }

////////////////////////////////////////////
  public static int max(int[] a){
    int lng = a.length;
    int max = a[0];
    for(int i=1;i<lng;i++){
      max = Math.max(max,a[i]);
    }
    return max;
  }
  public static long max(long[] a){
    int lng = a.length;
    long max = a[0];
    for(int i=1;i<lng;i++){
      max = Math.max(max,a[i]);
    }
    return max;
  }
////////////////////////////////////////////

////////////////////////////////////////////
  public static int min(int[] a){
    int lng = a.length;
    int min = a[0];
    for(int i=1;i<lng;i++){
      min = Math.min(min,a[i]);
    }
    return min;
  }
  public static long min(long[] a){
    int lng = a.length;
    long min = a[0];
    for(int i=1;i<lng;i++){
      min = Math.min(min,a[i]);
    }
    return min;
  }
////////////////////////////////////////////

}


Measured memory_bytes: 60468
#include<iostream>
#include<vector>
#include<map>
#include<algorithm>
#include<cmath>
#include<string>
#include<cstdlib>
#include<iomanip>

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

using namespace std;

typedef long long int ll;

const ll INF=(ll)1e18;

vector<vector<pair<int,ll> > > d(100001);

int color[100001];
bool visited[100001];

void dfs(int n, int col){
//  printf("%d %d\n",n,col);
  if(visited[n])return;
  visited[n] = true;
  color[n]=col;
  int col2 = col == 0 ? 1 : 0;

  REP(i,d[n].size()){
    if(d[n][i].second % 2 == 0){
      dfs(d[n][i].first, col);
    }else{
      dfs(d[n][i].first, col2);
    }
  }
}

int main(){

  int N;
  cin >> N;


  REP(i,N-1){
    int u,v;
    ll w;
    cin >> u >> v >> w;
    d[u].push_back(make_pair(v,w));
    d[v].push_back(make_pair(u,w));
  }

  // FOR(i,1,N+1){
  //   cout << i << endl;
  //   REP(j,d[i].size()){
  //     printf("%d %lld\n", d[i][j].first,d[i][j].second);
  //   }
  // }

  FOR(i,1,N+1)visited[i]=false;

  dfs(1,0);

  FOR(i,1,N+1){
    cout << color[i] << endl;
  }

}


Measured memory_bytes: 9984
#include <iostream>
#include <cstdio>
#include <vector>
#include <set>
#include <unordered_set>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <cassert>
#include <utility>

using namespace std;
using lli = long long int;
// #define DEBUG
#ifdef DEBUG
#define debug(var) cout << (#var) << ": " << (var) << endl;
template<class T> void dump_array_impl(const T& a) {
  bool first = true;
  for (auto&& x : a) {
    if (!first) { cout << ", "; first = false; }
    cout << x;
  }
}
#define debug_array(a) cout<<(#a)<<": ";dump_array_impl(a);cout<<endl
#else
#define debug(var) {}
#define debug_array(a) {}
#endif
template<class T> void read_n(vector<T>& v, size_t n) {
  v = vector<T>(n);
  for (lli i=0; i<n; ++i) cin >> v[i];
}

int main() {
  string s, t;
  cin >> s >> t;
  vector<char> tabs(256, 0), tabt(256, 0);
  vector<bool> used(256, false);
  for (int i=0; i<s.size(); ++i) {
    if ((tabs[s[i]] != 0 && tabs[s[i]] != t[i])
	|| (tabt[t[i]] != 0 && tabt[t[i]] != s[i])) {
      cout << "No" << endl;
      return 0;
    }
    tabs[s[i]] = t[i];
    tabt[t[i]] = s[i];
  }
  cout << "Yes" << endl;
  return 0;
}


Measured memory_bytes: 776
#include<cstdio>
#include<cstdlib>
#include<iostream>
#include<vector>
#include<queue>
#include<bitset>
#include<string>
#include<stack>
#include<set>
#include<map>
#include<cstring>
#include<complex>
#include<cmath>
#include<iomanip>
#include<numeric>
#include<algorithm>
#include<list>
#include<functional>
#include<cassert>
#define mp make_pair
#define pb push_back
#define X first
#define Y second
#define INF 987654321987654321
#define PI 3.14159265358979323846264
#define fup(i,a,b,c) for(int (i)=(a);(i)<=(b);(i)+=(c))
#define fdn(i,a,b,c) for(int (i)=(a);(i)>=(b);(i)-=(c))
#define MEM0(a) memset(a,0,sizeof(a));
#define MEM_1(a) memset(a,-1,sizeof(a));
#define ALL(a) a.begin(),a.end()
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int, int> Pi;
typedef pair<ll, ll> Pll;
typedef pair<double, double> Pd;
typedef vector<int> Vi;
typedef vector<ll> Vll;
typedef vector<double> Vd;
typedef vector<Pi> VPi;
typedef vector<Pll> VPll;
typedef vector<Pd> VPd;
typedef tuple<int, int, int> iii;
typedef tuple<ll, ll, ll> LLL;
typedef vector<iii> Viii;
typedef vector<LLL> VLLL;
typedef complex<double> base;
ll MOD = 1000000007;
ll POW(ll a, ll b, ll MMM = MOD) { ll ret = 1; for (; b; b >>= 1, a = (a*a) % MMM)if (b & 1)ret = (ret*a) % MMM; return ret; }
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll lcm(ll a, ll b) { if (a == 0 || b == 0)return a + b; return a*(b / gcd(a, b)); }
int dx[] = { 0,-1,1,0 }, dy[] = { 1,0,0,-1 };
int ddx[] = { 0,0,1,1,1,-1,-1,-1 }, ddy[] = { 1,-1,1,0,-1,1,0,-1 };

set<string> S;
int main() {
	string s;
	cin >> s;
	int k;
	scanf("%d", &k);
	k--;
	int n = s.length();
	fup(i, 0, n - 1, 1)
	{
		string t;
		fup(j, 0, 4, 1)
		{
			if (i + j >= n)break;
			t += s[i + j];
			S.insert(t);
		}
	}
	auto it = S.begin();
	for (; k; it++, k--);
	cout << *it;
}

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

int main () {
  int c[3][3];
  bool check = true;
  string ans = "No";
  for (int i = 0; i < 3; ++i) {
    for (int j = 0; j < 3; ++j) {
      cin >> c[i][j];
    }
  }
  int a[3] = {0};
  int b[3] = {0};
  for (a[0] = 0; a[0] <= c[0][0]; ++a[0]){
    b[0] = c[0][0] - a[0];
    for (a[1] = 0; a[1] <= c[1][1]; ++a[1]) {
      b[1] = c[1][1] - a[1];
      for (a[2] = 0; a[2] <= c[2][2]; ++a[2]) {
        b[2] = c[2][2] - a[2];
        for (int i = 0; i < 3; ++i) {
          for (int j = 0; j < 3; ++j) {
            if (c[i][j] != a[i] + b[j]) check = false;
          }
        }
        if (check == true) ans = "Yes";
        check = true;
      }
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>

using namespace std;

void solve()
{
	int n;
	cin >> n;
	vector<int> S(n);
	for (int i = 0; i < n; ++i)
	{
		cin >> S[i];
	}
	int q;
	cin >> q;
	vector<int> T(q);
	for (int i = 0; i < q; ++i)
	{
		cin >> T[i];
	}
	int ans = 0;
	for (int i = 0; i < q; ++i)
	{
		for (int j = 0; j < n; ++j)
		{
			if (T[i] == S[j])
			{
				++ans;
				break;
			}
		}
	}
	cout << ans << endl;
}

int main()
{
	solve();
	return(0);
}

Measured memory_bytes: 1232
from operator import mul
from functools import reduce

def cmb(n,r):
    r = min(n-r,r)
    if r == 0: return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1,r + 1))
    return over // under

N = 10**9 +7

S = int(input())
if S==1 or S==2:
    print(0)
    exit(0)

n = S // 3
ans =0
for i in range(1, n+1):
    m = S - 2 * i
    ans += cmb(m-1,i-1)

print(ans%N)

Measured memory_bytes: 73588
import sys
import os

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    N = iss()
    print('Yes' if N == N[::-1] else 'No')


if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (int)n; i++)
  
int main(){
int n;
cin >> n;
vector<int> p(n);
rep(i, n) cin >> p[i];
int count = 0;
rep(i, n) if(p[i] != i + 1) count++;
  
if(count <= 2){
cout << "YES" << endl;
}
  
else{
  cout << "NO" << endl;
}
}

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

typedef long long ll;
typedef pair<int,int> P;
int dx[] = {-1, 1, 0,  0};
int dy[] = { 0, 0, 1, -1};
 
int main(){
  int a, b;
  cin >> a >> b;
  int ans = max(a*b, a-b);
  ans = max(ans, a+b);
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
// clang-format off
#include <bits/stdc++.h>
#define int long long
#define main signed main()
// #define main int main()
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define prec(n) fixed << setprecision(n)
#define stlice(from, to) substr(from, (to) - (from) + 1)
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
using namespace std;
using pii = pair<int, int>;
using vi = vector<int>;
using vd = vector<double>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vpii = vector<pii>;
using vvi = vector<vi>;
using vvb = vector<vb>;
using vvpii = vector<vpii>;
template<typename A> using fn = function<A>;
constexpr int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
constexpr int MOD = 1000000007;
constexpr double PI = acos(-1);
template<typename A, typename B> bool cmin(A &a, const B &b) { return a > b ? (a = b, true) : false; }
template<typename A, typename B> bool cmax(A &a, const B &b) { return a < b ? (a = b, true) : false; }
constexpr bool odd(const int &n) { return n & 1; }
constexpr bool even(const int &n) { return !odd(n); }
void solve();
main { solve(); return 0; }
// clang-format on

vector<string> split(const string &s, const char &delim) {
  istringstream ss(s);
  string got;
  vector<string> v;
  while (getline(ss, got, delim)) v.pb(got);
  return v;
}

void solve() {
  string s;
  while (getline(cin, s), s != "END OF INPUT") {
    vs v = split(s, ' ');
    for (auto &x : v) cout << x.size();
    cout << endl;
  }
}

Measured memory_bytes: 3028
use std::io::{self, BufRead, Read};

fn main() {
	let stdin = io::stdin();
    let mut stdin = stdin.lock();
    stdin.by_ref().split(b'\n').next().unwrap();

    let mut v = [0; 100000]; // cardinality

    for a in stdin.split(b' ') {
    	let a: usize = String::from_utf8(a.unwrap()).unwrap()
            .trim_right()
            .parse().unwrap();
    	v[a] += 1;
    }

    let res = v.windows(3)
    	.map(|w| w.iter().sum::<u32>())
        .max().unwrap();

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


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

int main(){
    int r, D;
    cin >> r >> D;
    vector<int> x(2020);
    cin >> x[2000];

    x[2001] = r * x[2000] - D;
    cout << x[2001] << endl;
    x[2002] = r * x[2001] - D;
    cout << x[2002] << endl;
    x[2003] = r * x[2002] - D;
    cout << x[2003] << endl;
    x[2004] = r * x[2003] - D;
    cout << x[2004] << endl;
    x[2005] = r * x[2004] - D;
    cout << x[2005] << endl;
    x[2006] = r * x[2005] - D;
    cout << x[2006] << endl;
    x[2007] = r * x[2006] - D;
    cout << x[2007] << endl;
    x[2008] = r * x[2007] - D;
    cout << x[2008] << endl;
    x[2009] = r * x[2008] - D;
    cout << x[2009] << endl;
    x[2010] = r * x[2009] - D;
    cout << x[2010] << endl;


    
    return 0;
}

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

int main(int argc, char *argv[])
{
	int n, i;
	cin >> n;
	int result[n];
	int input[n - 1];

	memset(result, 0, sizeof(result));

	for (i = 0; i < n - 1; i++)
		cin >> input[i];

	for (i = 0; i < n - 1; i++)
		result[input[i] - 1]++;

	for (i = 0; i < n; i++)
		cout << result[i] << endl;

	return 0;
}

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

int main(){
    int x, n;
    cin >> x;
    cin >> n;
    
    int kaisuu=0;
    while(x>=n){
        x = x/n;
        kaisuu += 1;
    }
    kaisuu+=1;
 
    cout << kaisuu << endl;
}

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

typedef long long ll;

const int maxn =  1e5 + 5;

int n, E, T, pos;
int a[maxn];
ll f[maxn], mn = 1e18;

int main()
{
    scanf("%d%d%d", &n, &E, &T);
    for(int i = 1; i <= n; i++)
        scanf("%d", &a[i]);
    for(int i = 1; i <= n; i++)
    {
        while(T < 2 * (a[i] - a[pos + 1]))
        {
            mn = min(mn, f[pos] - 2 * a[pos + 1]);
            pos++;
        }
        f[i] = min(f[i - 1] + T, mn + 2 * a[i]);
        f[i] = min(f[pos] + T, f[i]);
    }
    printf("%lld\n", f[n] + E);
    return 0;
}

Measured memory_bytes: 1280
using System;
using System.Numerics;
using System.Linq;
using System.Collections.Generic;
using System.Text;

namespace debug
{
    class ProgramC
    {
        static void Main(string[] args)
        {

            //入力
            int n = int.Parse(Console.ReadLine());
            string[] s = Console.ReadLine().Split(' ');
            int[] odd = new int[100000];
            int[] even = new int[100000];


            //それぞれの位置を記録
            for (int i = 0; i < n; i++)
            {
                if (i % 2 == 0)
                {
                    odd[int.Parse(s[i]) - 1]++;
                    continue;
                }

                even[int.Parse(s[i]) - 1]++;

            }

            int em = 0;
            int ec = 0;
            int om = 0;
            int oc = 0;

            //最頻値の場所と数を求める
            for (int i = 0; i < 100000; i++)
            {
                int temp1 = even[i];
                int temp2 = odd[i];

                if (ec < temp1)
                {
                    em = i;
                    ec = temp1;
                }
                if (oc < temp2)
                {
                    om = i;
                    oc = temp2;
                }

            }

            int em2 = 0;
            int ec2 = 0;
            int om2 = 0;
            int oc2 = 0;

            //第二の最頻値の場所と数を求める
            for (int i = 0; i < 100000; i++)
            {
                int temp1 = even[i];
                int temp2 = odd[i];

                if (ec2 < temp1 && em != i)
                {
                    em2 = i;
                    ec2 = temp1;
                }
                if (oc2 < temp2 && om != i)
                {
                    om2 = i;
                    oc2 = temp2;
                }

            }

            //両方同じ数の場合、どっちか少ない方を選択する
            if (em == om)
            {
                Console.WriteLine(Math.Min(n - ec - oc2, n - ec2 - oc));
                return;
            }

            //それ以外は普通に両方の最頻値を出す
            Console.WriteLine(n - ec - oc);


        }


    }



}


Measured memory_bytes: 19168
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
typedef long long ll;
using namespace std;
 
int main(){
  string s;
  cin >> s;
  
  bool ans = false; 
  
  rep(i,4) if(s[i] == s[i+1]) ans = true;
  if(ans) puts("Bad");
  else puts("Good");
  
  return 0;
  
}

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

typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;
#define y0 y3487465
#define y1 y8687969
#define j0 j1347829
#define j1 j234892
#define next asdnext
#define prev asdprev
#define dump(x)  cout << #x << " = " << (x) << endl;	//debug
#define SZ(x) ((int)(x).size())
#define REP(i, n) for(ll i = 0; i < (n); i++)
#define REPR(i, n) for (ll i = (n); i >= 0; i--)
#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)
#define ps(s) cout << #s << endl;
#define pv(v) cout << (v) << endl;
#define ALL(a)  (a).begin(),(a).end()

int main() {
	ll x;
	cin >> x;
	ll num500 = x / 500;
	x = x % 500;
	ll num5 = x / 5;
	ll res = num500 * 1000 + num5 * 5;
	pv(res)
	return(0);
}

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

int main()
{
    string s, p;

    cin >> s >> p;

    s = s + s;

    if (s.find(p) != string::npos) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 1192
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <inttypes.h>
#include <string.h>
#include <math.h>

int main (int argc, char const *argv[])
{
    char S[(int)1e5 + 1];
    int64_t len, bw = 0, wb = 0;

    gets(S);
    len = strlen(S);
    
    for (int i = 0; i < len; i++) {
        if (i % 2) {
            if (S[i] == '0') {
                bw++;
            }
        } else {
            if (S[i] == '1') {
                bw++;
            }
        }
    }

    for (int i = 0; i < len; i++) {
        if (i % 2) {
            if (S[i] == '1') {
                wb++;
            }
        } else {
            if (S[i] == '0') {
                wb++;
            }
        }
    }

    printf("%"PRId64"\n", bw > wb ? wb : bw);
}


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

using namespace std;

using ll = long long;
using ld = long double;
using P = pair<int, int>;
constexpr ld EPS = 1e-12;
constexpr int INF = numeric_limits<int>::max() / 2;
constexpr int MOD = 1e9 + 7;

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

    int l, k;
    cin >> l >> k;
    vector<vector<ll>> dp(l+1, vector<ll>(2,0));
    dp[0][0] = 1;
    for(int i=0;i<l;i++){
        dp[i+1][0] += dp[i][1];
        dp[i+1][1] += dp[i][0];
        if(i+k<=l) dp[i+k][1] += dp[i][0];
    }
    ll res=0;
    for(int i=1;i<=l;i++) res += dp[i][1];
    cout<<res<<endl;
}



Measured memory_bytes: 3216
import std.stdio,
  std.array,
  std.string,
  std.algorithm,
  std.range,
  std.conv;

void main()
{
  int n, k;

  readf("%d %d\n", &n, &k); 
  string ds = readln.chomp.replace(" ", "");

  while (any!(a => ds.canFind(a))(n.to!string)) {
    n++;
  }

  writeln(n);

}


Measured memory_bytes: 1276
#include<cstdio>
#include<vector>
#include<algorithm>

using namespace std;

int n,m;
class data{
public:
	int x,p;
	data(int ix,int ip){
		x=ix;
		p=ip;
	}
	bool operator<(const data& d1)const{
		return d1.p<p;
	}
};


vector<data> dat;
int main(void){
	while(1){
		scanf("%d %d",&n,&m);
		if(n+m==0)break;
		dat.clear();
		for(int i=0;i<n;i++){
			int x,p;
			scanf("%d%d",&x,&p);
			dat.push_back(data(x,p));
		}
		sort(dat.begin(),dat.end());
		int res=0;
		for(int i=0;i<n;i++){
			if(m>0){
				if(m<dat[i].x){
					res+=(dat[i].x-m)*dat[i].p;
					m=0;
				}
				if(m>=dat[i].x){
					m-=dat[i].x;
				}
			}else res+=dat[i].x*dat[i].p;
		}
		printf("%d\n",res);
	}
	return 0;
}

Measured memory_bytes: 1160
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    for (int i = 0; i <= n; i++){
      if ((int)(i*1.08) == n){
        System.out.println(i);
        return;
      }
    }
    System.out.println(":(");
  }
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

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

#define DEBUG(x) cout<<#x<<": "<<x<<'\n'
#define DEBUG_VEC(v) cout<<#v<<":";REP(i, v.size())cout<<' '<<v[i];cout<<'\n'
#define ALL(a) (a).begin(), (a).end()

#define CHMIN(a, b) a=min((a), (b))
#define CHMAX(a, b) a=max((a), (b))

const ll MOD=1000000007ll;
// const ll MOD=998244353ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

const double EPS=1e-11;
#define EQ0(x) (abs((x))<EPS)
#define EQ(a, b) (abs((a)-(b))<EPS)

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n, m, a, b;
	pii ab[114514];
	cin>>n>>m;
	REP(i, m){
		cin>>a>>b;
		ab[i]=make_pair(a-1, b-2);
	}
	sort(ab, ab+m);
	int l=0, r=m;
	int ans=1;
	REP(i, m){
		if(r>=ab[i].first){
			l=max(l, ab[i].first);
			r=min(r, ab[i].second);
		}
		else{
			l=ab[i].first;
			r=ab[i].second;
			++ans;
		}
	}
	cout<<ans<<'\n';
	return 0;
}


Measured memory_bytes: 1280
n = int(input())
w = list(map(int, input().split()))
ans = 1000
for i in range(1, n):
    sa = sum(w[:i])
    sb = sum(w[i:])
    if sa < sb:
        if abs(sb-sa) < ans:
            ans = abs(sb-sa)
    elif sb <= sa:
        if abs(sa-sb) < ans:
            ans = abs(sa-sb)
print(ans)


Measured memory_bytes: 38512
#include <bits/stdc++.h>
#define REP(i,k,n) for(int(i)=(k);(i)<(n);++(i))
#define ALL(x) (x).begin(),(x).end()
#define chmin(x,v) x = min(x, v)
#define chmax(x,v) x = max(x, v)
using namespace std;
typedef long long ll;

int A[5];
int k;

int main()
{
  REP(i,0,5) cin >> A[i];
  cin >> k;

  bool res = true;  // すべて通信できる
  REP(i,0,5) REP(j,i+1,5) {
    if (abs(A[i] - A[j]) > k) {
      res = false; break;
    }
  }

  cout << (res ? "Yay!" : ":(") << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
const ll INF = 1e9;
const ll MOD = 10007; // 1e9+7
const ll LINF = 1e18;
using namespace std;

#define dump(x)  cout << #x << " = " << (x) << endl;
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE"  ) << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible"  ) << endl
#define possible(n) cout << ((n) ? "possible" : "impossible"  ) << endl

#define SANKOU(n,a,b) cout << ((n) ? (#a) : (#b) ) << endl

#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define REP(i,n) for(ll i=0;i<(n);++i)
#define REPR(i,n) for(ll i=n;i>=0;i--)

#define FOREACH(x,a) for(auto&& (x) : (a) )

#define WFA(d,v) REP(k,v)REP(i,v)REP(j,v)d[i][j]=min(d[i][j],d[i][k]+d[k][j])

#define SCOUT(x) cout<<(x)<<" "
#define ENDL cout<<endl

#define VECCIN(x) for(auto&youso_: (x) )cin>>youso_
#define VECIN2(x,y) REP(i,x.size())cin>>x[i]>>y[i]
#define VECCOUT(x) if(1){for(auto tt=x.begin();tt!=x.end();tt++){if(tt!=x.begin())cout<<" ";cout<<(*tt);}cout<<endl;}

#define ALL(obj) (obj).begin(),(obj).end()

#define EXIST(n,x) (find(ALL(n),x)!=n.end())
#define UNIQUE(obj) sort(ALL( obj )); obj.erase(unique(ALL(obj)),obj.end())
#define EN(x) if(1){cout<<#x<<endl;return 0;}
#define COUT(x) cout<<(x)<<endl
void CINT(){}
template <class Head,class... Tail>
void CINT(Head&& head,Tail&&... tail){
    cin>>head;
    CINT(move(tail)...);
}
#define CIN(...) ll __VA_ARGS__;CINT(__VA_ARGS__)
#define LCIN(...) ll __VA_ARGS__;CINT(__VA_ARGS__)
#define SCIN(...) string __VA_ARGS__;CINT(__VA_ARGS__)

template <class T = ll>
T IN(){T x;cin>>x;return (x);}

template <class Head>
void VT(Head head){}
template <class Head,class Seco,class... Tail>
void VT(Head&& head,Seco&& seco,Tail&&... tail){
    seco.resize(head);
    VT(head,move(tail)...);
}
void VT2(){}
template <class Head,class... Tail>
void VT2(Head&& head,Tail&&... tail){
  VECCIN(head);
  VT2(move(tail)...);
}

template <class Head>
void VT3(Head&& head){}
template <class Head,class Seco,class... Tail>
void VT3(Head&& head,Seco&& seco,Tail&&... tail){
  seco[head]=IN();
  VT3(head,move(tail)...);
}

#define VC1(n,...) V __VA_ARGS__;VT(n,__VA_ARGS__);VT2(__VA_ARGS__); //aaabbbccc
#define VC2(n,...) V __VA_ARGS__;VT(n,__VA_ARGS__);REP(i,n)VT3(i,__VA_ARGS__); //abcabcabc

// #include <boost/multiprecision/cpp_ll.hpp>
// using namespace boost::multiprecision; // cpp_ll

#define P pair<ll,ll>
#define V vector<ll>
#define M map<ll,ll>
#define S set<ll>

#define pb(a) push_back(a)
#define mp make_pair

signed main(){
    SCIN(s);
    ll n = s.size();
    ll ans = 0;
    ll c = 0;
    REP(i,n){
        if(s[i] == 'W'){
            ans += i - c;
            ++c;
        }
    }
    COUT(ans);

}


Measured memory_bytes: 644
//   _/                _/                 _/_/_/   _/
//_/_/_/_/   _/_/   _/_/_/_/   _/_/    _/       _/_/
// _/     _/    _/   _/     _/    _/  _/_/_/     _/
//_/     _/    _/   _/     _/    _/  _/    _/   _/
// _/_/   _/_/       _/_/   _/_/      _/_/     _/
#include<iostream>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<set>
#include<map>
#include<queue>
#include<vector>
using namespace std;
typedef long long ll;
const int MOD=1e9+7;
const double pi=acos(-1);
int main() {
  cin.tie(0),cout.tie(0);
  ios::sync_with_stdio(false);
  ll n,a[200005]={},ans=0,cnt=0,r=0;
  cin >> n;
  for(int i=0; i<n; i++) {
    cin >> a[i];
  }
  for(int l=0; l<n; l++) {
    while(r<n&&(cnt^a[r])==cnt+a[r]) {
      cnt+=a[r];
      r++;
    }
    ans+=r-l;
    if(r==l) {
      r++;
    }
    else {
      cnt-=a[l];
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

using namespace std;

#define rep(i, a, b) for (int i = a; i < b; i++)
#define rrep(i, a, b) for (int i = a; i <= b; i++)
#define all(a)  begin((a)),end((a))
#define uniq(c) (c).erase(unique(all((c))), end((c)))

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

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

typedef long long ll;
const ll MOD = 1e9 + 7;
const long long INF = 1LL<<60;
const double PI=3.14159265358979323846;
const int NMAX=100005;
using namespace std;


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

Measured memory_bytes: 3584
{-# LANGUAGE TupleSections #-}

import qualified Data.ByteString.Char8 as B
import           Data.Maybe (fromJust)
import qualified Data.Map.Strict as M
import           Control.Monad (replicateM)

modT :: Integer
modT = 1000000007

main :: IO ()
main = do
  n <- getInt
  m <- M.fromListWith (+) . fmap ((, 1) . convert) <$> replicateM n getIntegers
  print . solve $ m

convert [a, b]
  | a == 0 && b == 0 = (0, 0)
  | a == 0 = (0, 1)
  | b == 0 = (1, 0)
  | otherwise = let gcd' = gcd a b
                in if b < 0
                   then (-div a gcd', -div b gcd')
                   else (div a gcd', div b gcd')

solve :: M.Map (Integer, Integer) Integer -> Integer
solve map = let zero = M.findWithDefault 0 (0, 0) map
                ans = solve' . M.delete (0, 0) $ map
            in (ans + fromIntegral zero - 1) `mod` modT

solve' :: M.Map (Integer, Integer) Integer -> Integer
solve' map =
  if M.null map
  then 1
  else let ((a, b), count) = M.elemAt 0 map
           inv = if a > 0
                 then (-b, a)
                 else (b, -a)
           count' = M.findWithDefault 0 inv map
           ncount = solve' . M.delete (a, b) . M.delete inv $ map
           ccount = (2 ^ count - 1) + (2 ^ count' - 1) + 1
       in (ncount * ccount) `mod` modT

getInt = fst . fromJust . B.readInt <$> B.getLine

getIntegers = fmap (fst . fromJust . B.readInteger) . B.words <$> B.getLine


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

typedef long long LL;
const int M=2e5+5;
const LL INF=0x3f3f3f3f3f3f3f3f;
int a[M];
map<int,LL> dp[M];
// dp[i][j] consider 1-i select j

LL getdp(int n,int k)
{
	//cout<<n<<" "<<k<<endl;
	if(k>(n+1)/2) return -INF;
	if(k==0||n<0) return 0;
	if(dp[n].count(k)) return dp[n][k];
	LL &ans=dp[n][k];
	ans=-INF;
	ans=max(getdp(n-1,k),getdp(n-2,k-1)+a[n]);
	return ans;
}

int main()
{
	int n; scanf("%d",&n);
	for(int i=1;i<=n;i++)
		scanf("%d",&a[i]);
	printf("%lld\n",getdp(n,n/2));
	return 0;
}

Measured memory_bytes: 40420
can = [0]
l = gets.to_i
a = gets.split.map(&:to_i)
n = gets.to_i
m = gets.split.map(&:to_i)
l.times{|i|
  if i == 0
    can << a[i]
  else
    can = Marshal.load(Marshal.dump(can + can.map {|ele| ele + a[i]}))
  end
  can.uniq!
}
n.times{|i|
  if can.include?m[i]
    puts 'yes'
  else
    puts 'no'
  end
}

Measured memory_bytes: 6424
n = int(input())
s = input()
ans = 0

for i in range(1000):
    t = str(i).zfill(3)
    isExists = [False]*3
    pos = 0
    for (p,j) in enumerate(t):
        while pos<n:
            if s[pos]==j:
                pos += 1
                isExists[p] = True
                break
            pos += 1
    if all(isExists):
        ans += 1

print(ans)

Measured memory_bytes: 42716
using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Text;

namespace LogicSummoner
{
    class Program
    {
        static void Main(string[] args)
        {
            var nums = GetNumbers();

            var flag = true;
            for (int i = 0; i < nums.Count - 1; i++)
            {
                flag &= nums[i] < nums[i + 1];
            }

            if (flag)
            {
                Console.WriteLine("Yes");
            }
            else
            {
                Console.WriteLine("No");
            }
        }

        static int GetNumber()
        {
            return int.Parse(Console.ReadLine().Trim());
        }

        static List<int> GetNumbers()
        {
            return Console.ReadLine().Trim().Split(new[] { " " }, StringSplitOptions.RemoveEmptyEntries).Select(x => int.Parse(x)).ToList();
        }

        static List<string> GetStrings()
        {
            return Console.ReadLine().Trim().Split(new[] { " " }, StringSplitOptions.RemoveEmptyEntries).ToList();
        }
    }
}

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

int main(void){
  int n; cin >> n;
  vector<int> a(n);
  for(int i = 0; i < n; i++) cin >> a[i];
  int maxv = *max_element(a.begin(), a.end());
  double med = maxv/2.0;
  int ans = -1;
  int minv = 1e9;
  for(int i = 0; i < n; i++){
    if(maxv == a[i]) continue;
    if(abs(med - a[i]) < minv){
      ans = a[i];
      minv = abs(med - a[i]);
    }
  }
  cout << maxv << " " << ans << endl;
  return 0;

}


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

int main(){
	int N , T , i , j ;
	int c , t ;
	scanf("%d%d",&N,&T);
	int min = 100000; 
	for( i = 0 ; i < N ; i++ ){
		scanf("%d%d",&c,&t);
		if( t <= T){
			if( c < min ) min = c ;
		}
	}
	if( min > 1000){
		puts("TLE");
	}
	else{
		printf("%d\n",min);
	}

	return 0 ;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
    int n,a;
    cin>>n;
    while(n!=0)
    {
        a=n%10;
        n=n/10;
        if(a==7)
        {
            cout<<"Yes";
            return 0;
        }
    }
    cout<<"No";
}

Measured memory_bytes: 3624
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <queue>
#include <stack>
#include <tuple>
#include <cmath>
#include <iomanip>
#include <map>
#include <cstring> //memset(dp,0,sizeof(dp))
#include <functional>
#define ll long long
#define rep(i,n) for(int i=0;i<(n);i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define fi first
#define se second
#define pb push_back
#define ppb pop_back()
#define ALL(a) (a).begin(),(a).end()
#define int long long
using namespace std;
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;}
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;


signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n; cin >> n;
    vector<pair<ll,int>> v;
    rep(i,n){
        ll a; cin >> a;
        v.pb({a,i});
    }
    sort(ALL(v),greater<pair<ll,int>>());
    ll dp[n+1][n+1];
    memset(dp,0,sizeof(dp));
    rep(i,n+1){
        rep(j,n+1){
            if(i>0&&i+j-1<n) chmax(dp[i][j],dp[i-1][j]+abs(v[i+j-1].se-(i-1))*v[i+j-1].fi);
            if(j>0&&i+j-1<n) chmax(dp[i][j],dp[i][j-1]+abs(v[i+j-1].se-(n-j))*v[i+j-1].fi);
        }
    }
    ll ans=0;
    rep(i,n+1){
        chmax(ans,dp[i][n-i]);
    }
    cout << ans << endl;
}


Measured memory_bytes: 34896
_, _, _, k = gets.split.map(&:to_i)
a = gets.split.map(&:to_i)
b = gets.split.map(&:to_i)
c = gets.split.map(&:to_i)

ab = a.product(b).map { |a, b| a + b }
ab.sort!.reverse!

abc = ab.take(k).product(c).map { |ab, c| ab + c }
abc.sort!.reverse!

p(*abc.take(k))


Measured memory_bytes: 263808
n,m = map(int,input().split())
Inf = sorted([list(map(int,input().split())) for i in range(n)])
ans = 0
for i in range(n):
    cost = Inf[i][0]
    num = Inf[i][1]
    if m >= num:
        get = num
    else:
        get = m
    sumcost = cost*get
    ans += sumcost
    m -= get
    if m == 0:
        break
print(ans)

    

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

using namespace std;

const int N = 105;

int a[N], b[N];

int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n - 1; i++) {
    cin >> b[i];
  }
  for (int i = 0; i < n - 1; i++) {
    if (i == 0) {
      a[i] = a[i + 1] = b[i];
    } else if (a[i] > b[i]) {
      a[i] = a[i + 1] = b[i];
    } else {
      a[i + 1] = b[i];
    }
  }
  int sum = 0;
  for (int i = 0; i < n; i++) {
    sum += a[i];
  }
  cout << sum << '\n';
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
int INF = 1LL << 30;
int MOD = 1e9+7;
main(){
    int N;
    cin >> N;
    vector<int> A(N),B(N);
    for(int i = 0;i < N;i++){
        cin >> A[i];
    }
    for(int i = 0;i < N;i++){
        cin >> B[i];
    }
    ll sum = 0;
    for(int i = 0;i < N;i++){
        sum += B[i] - A[i];
        if(A[i] >= B[i])continue;
        sum -= (B[i] - A[i] + 1)/2;
    }
    if(sum < 0)cout << "No" << endl;
    else cout << "Yes" << endl;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define int long long
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e18;

struct UF{
    vector<int> par, sz;
    UF(){}
    UF(int n):par(n), sz(n, 1){
        iota(par.begin(), par.end(), 0);
    }
    int find(int x){
        if(x == par[x]) return x;
        return par[x] = find(par[x]);
    }
    void unite(int x, int y){
        x = find(x); y = find(y);
        if(x == y) return;
        if(sz[x] < sz[y]) swap(x, y);
        sz[x] += sz[y];
        par[y] = x;
    }
    bool same(int x, int y){
        return find(x) == find(y);
    }
};

signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n, m;
    cin >> n >> m;
    UF uf(m);
    vector<int> cnt(m);
    rep(i, 0, n){
        int k;
        cin >> k;
        vector<int> l(k);
        rep(j, 0, k){
            cin >> l[j];
            l[j]--;
            cnt[l[j]]++;
        }
        rep(j, 0, k - 1){
            uf.unite(l[j], l[j + 1]);
        }
    }
    bool f = true;
    int id = -1;
    rep(i, 0, m){
        if(cnt[i]){
            if(id == -1) id = uf.find(i);
            else{
                if(uf.find(i) != id) f = false;
            }
        }
    }
    if(f) cout << "YES" << endl;
    else cout << "NO" << endl;
}

Measured memory_bytes: 2560