akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
using namespace std;

vector<vector<pair<int, int > > > V;

bool bit(int mask, int position){
    if((1 & (mask >> position)) != 0) return true;
    return false;
}

int counter(int x) {
    if(x == 0) return 0;
    return counter(x >> 1) + (x & 1);
}

int main(void){
    // Your code here!
    int N;
    cin >> N;
    int x, y;
    int A[N];
    V.resize(N);
    
    for(int i = 0; i < N; i++){
        cin >> A[i];
        
        for(int j = 0; j < A[i]; j++){
            cin >> x >> y;
            V[i].push_back(make_pair(x, y));
        }
    }
    
    int ans = 0;
    for(int i = 0; i < (1 << N); i++){
        bool ok = true;
        for(int j = 0; j < N; j++){
            /* jが正直者 */
            if(bit(i, j)) {
                for(int k = 0; k < V[j].size(); k++){
                    int other = V[j][k].first - 1;
                    int honest = V[j][k].second;
                    if(bit(i, other) && honest == 0) {
                        ok = false;
                    } else if(!bit(i, other) && honest == 1){
                        ok = false;
                    }
                }
            }
        }
        
        if(ok) ans = max(ans, counter(i));
    }
    
    cout << ans << endl;
}


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

using namespace std;

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

#define ndl cout << '\n'
#define sz(v) int(v.size())
#define pb push_back
#define mp make_pair
#define fs first
#define sc second
#define present(a, x) (a.find(x) != a.end())
#ifdef LOCAL
#define db(...) ({cout << "> Line " << __LINE__  \
		<< ": "; _db(#__VA_ARGS__, __VA_ARGS__);})
#define RNG() rng()
#else
#define db(...) true
#define RNG() true
#endif

template<class T>
void _db(const char *dbStr, T e) {
	cout << dbStr << " = " << e << endl;
}
template<class T, class... L>
void _db(const char *dbStr, T e, L... r) {
  while(*dbStr != ',') cout << *dbStr++;
  cout << " = " << e << ','; _db(dbStr + 1, r...);
}
template<class S, class T>
ostream& operator<<(ostream& o, const map<S, T>& v) {
	o << "["; int i = 0;
	for (const pair<S, T>& pr : v) o << (!i++ ? "" : ", ") << "{"
	<< pr.fs << " : " << pr.sc << "}"; return o << "]";
}
template<template <class, class...> class S, class T, class... L>
ostream& operator<<(ostream& o, const S<T, L...>& v) {
	o << "["; int i = 0;
	for (const auto& e : v) o << (!i++ ? "" : ", ") << e;
	return o << "]";
}
template<class S, class T>
ostream& operator<<(ostream& o, const pair<S, T>& pr) {
	return o << "(" << pr.fs << ", " << pr.sc << ")";
}
ostream& operator<<(ostream& o, const string& s) {
	for (const char& c : s) o << c;
	return o;
}

template<class T> using V = vector<T>;
template<class T> using VV = V<V<T>>;
template<class T> using VVV = VV<V<T>>;
using ll = long long;
using pii = pair<int, int>;
using vi = V<int>;
using vii = V<pii>;
using vvi = VV<int>;
using mii = map<int, int>;
using umii = unordered_map<int, int>;
using si = set<int>;
using usi = unordered_set<int>;





int main() {
	#ifdef LOCAL
	auto stTime = clock();
//	freopen("in.txt", "r", stdin);
	mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
	#endif
	ios::sync_with_stdio(false);
	cout.precision(10);
	cin.tie(0);


	int N, pi;

	cin >> N;

	int mn = N + 1;

	int ans = 0;

	for (int i = 1; i <= N; ++i) {
		cin >> pi;
		if (pi <= mn)
			++ans;

		mn = min(mn, pi);
	}


	cout << ans << '\n';

	#ifdef LOCAL
	cout << "\n\n\nExecution time: " <<
		(clock() - stTime) * 1e3 / CLOCKS_PER_SEC << " ms" << endl;
	#endif
    return 0;
}


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

typedef long long int ll;
typedef long double ld;
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define MOD (ll)(1e9 + 7)
#define vi vector<int>
#define vii vector<vector<int> >
#define vl vector<ll>
#define vll vector<vector<ll> >
#define vc(T, nm) vector<T> nm
#define pb push_back
#define popb pop_back
#define si set<int>
#define sl set<ll>
#define F first
#define S second
#define pii pair<int, int>
#define mp make_pair
#define ins insert
#define ers erase
#define endl "\n"
#define mul(a, b) ((a % MOD) * (b % MOD)) % MOD
#define adr(a, b) ((a % MOD) + (b % MOD)) % MOD
#define FORA(x, s, e, inc) for(ll x = s; x != e; x += inc)
#define ROFA(x, s, e, inc) for(ll x = s; x != e; x -= inc)
#define FOR(x, s, e) FORA(x, s, e, 1)
#define ROF(x, s, e) ROFA(x, s, e, 1)
#define loop(x, n) FOR(x, 0, n)
#define rd1(t, a) 					t a; cin >> a;
#define rd2(t, a, b) 				rd1(t, a); rd1(t, b); 
#define rd3(t, a, b, c) 			rd2(t, a, b); rd1(t, c);
#define rd4(t, a, b, c, d) 			rd3(t, a, b, c); rd1(t, d);
#define rd5(t, a, b, c, d, e) 		rd4(t, a, b, c, d); rd1(t, e);
#define rd6(t, a, b, c, d, e, f) 	rd5(t, a, b, c, d, e); rd1(t, f);
#define rdA(t, nm, len)				t nm[len]; loop(i, len) {cin >> nm[i];}
#ifdef DEBUG
	#define deb(v) cout << endl << #v << ": " << v << endl
	#define db1(v) cout << endl << #v << ": " << "[ "; for(auto x: v) {cout << x << " ";}; cout << "]" << endl;
	#define db2(v) cout << endl << #v << ": " << endl; for(auto r: v) {cout << "[ "; for(auto x: r) {cout << x << " ";}; cout << "]" << endl;};
	#define dbl cout << "-------------------------------" << endl
#else
	#define deb(v)
	#define db1(v)
	#define db2(v)
	#define dbl
#endif

void solve() {
    rd3(ll, n, x, t);
    int ans = 0;
    while(n > 0) {
        ans += t;
        n -= x;
    }
    
    cout << ans;
}


int main() {
	
	fastio;
	
	ll t = 1;
// 	rd1(ll, t);
    while(t--) {
        solve();
    }


	return 0;
}

Measured memory_bytes: 3648
#include<iostream>
using namespace std;
#define int long long
int get(int n) 
 { 
     int res = 0;
    while(n){
        res+= n%10;
        n/= 10; 
        
    }
  return res;
 } 
int32_t main() {
	int k;
	cin>>k;
    int a=1,p=1;
    for(int i=0;i<k;i++){
      cout<<a<<"\n";
      int n=a+p;
      int m=a+p*10;
      if(n*get(m)<=m*get(n)) a=n; 
      else 
       {  a=m; 
          p*=10;
           
       }
   }
}


Measured memory_bytes: 3588
#include <bits/stdc++.h>
#define ll long long int
#define db double
#define pb push_back
#define mpr make_pair
#define andl "\n"
#define f first
#define s second
#define mset(x,y) memset(x,y,sizeof(x))
#define fr(i,n) for(long long int i=0;i<n;i++)
#define trace(it,x) for(auto it = (x).begin(); it != (x).end(); it++)
#define mod 1000000007
#define fastio ios::sync_with_stdio (false); cin.tie (0); cout.tie (0);
#define runtime cerr<< '\n' << "Time elapsed :" << clock() * 1000.0 / CLOCKS_PER_SEC << " ms\n" ;
using namespace std;
 
// convert number to string to_string(x);
// convert string to number stoi();
 
// ll mulmod(ll x,ll y)
// {
//     return ((x%mod)*(y%mod))%mod;
// }
 
// ll binpow(ll x, ll y)
// {
//     ll z = 1;
//     while(y > 0)
//     {
//         if(y % 2 == 1)
//             z = mulmod(z, x);
//         x = mulmod(x, x);
//         y /= 2;
//     }
//     return z;
// }
 
// ll ncr(ll n,ll r)
// {
//     return mulmod(fact[n],binpow(mulmod(fact[n-r],fact[r]),mod-2));
// }
 
// ll pwr(ll n,ll m)
// {
//   if(n==1 || m==0)
//     return 1;
 
//   ll x=pwr(n,m/2);
//   if(m%2==0)
//     return x*x;
//   else
//     return n*x*x;
// }
 
// ll pwr(ll n,ll m,ll b)
// {
//   if(n==1 || m==0)
//     return 1;
 
//   ll x=pwr(n,m/2,b);
//   if(m%2==0)
//     return ((x%b)*(x%b))%b;
//   else
//     return ((n%b)*(((x%b)*(x%b))%b))%b;
// }
 
void solve()
{
  return ;
}
 
int main()
{
  fastio
  
  ll a,b,c,d,e,f=-1e18;
  cin >> a >> b >> c >> d;
  e=max({b*d,b*c,d*a,a*c});
  if((0>=a&&0<=b) || (0>=c&&0<=d))
  	f=0;
  cout << max(f,e);
 
  runtime
}

Measured memory_bytes: 3780
# -*- coding: utf-8 -*-
n=input()
keta = len(n)
keta_num = 0
for k in range(1,keta):
    if(k%2==1):
        keta_num += (10**k)-(10**(k-1))
if(keta%2==1):
    n_int = int(n)
    keta_num += n_int - (10**(keta-1))+1
if(keta==1):    
    print(int(n))
else:
    print(keta_num)

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

#define REP(i,n) for(int i=0; i < (n); ++i)
#define REPR(i,n) for(int i=(n); i >= 0; --i)
#define FOR(i, m, n) for(int i = (m); i < (n); ++i)

using ll = long long;
#define INF 1e9


int main(){
  int x[3];
  cin >> x[0] >> x[1] >> x[2];
  int cnt5=0, cnt7=0;
  REP(i, 3){
    if(x[i] == 5){
      cnt5++;
    } 
    else if(x[i]==7){
      cnt7++;
    }
  }
  if(cnt5==2 && cnt7==1){
    cout << "YES" << endl;
  }
  else{
    cout << "NO" << endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define dup(x,y) (((x)+(y)-1)/(y))
#define ALL(x) (x).begin(), (x).end()
typedef long long ll;
typedef pair<int, int> pii;
const double EPS = 1e-10;
const int INF = 1e9;
const ll LINF = 1e18;
const int MOD = 1000000007;
const double PI = acos(-1);
int dx[4] = {0,1,0,-1};
int dy[4] = {1,0,-1,0};

int main() {
	int n;
	cin >> n;
	vector<int> a(n), b(n);
	rep(i,n) cin >> a[i] >> b[i];
	int c = 0;
	rep(i,n) {
		if (a[i] == b[i]) c++;
		else c = 0;
		if (c == 3) {
			cout << "Yes" << endl;
			return 0;
		}
	}
	cout << "No" << endl;
}

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

using namespace std;

string s;
int firsta=-1, lastz = -1, n;

int main()
{
  ios_base::sync_with_stdio(0);  cin.tie(0); cout.tie(0);
  cin>>s;
  n = s.size();
  for(int i=0; i<n; i++){
    if(s[i]=='A' && firsta == -1)
      firsta = i;
    if(s[i]=='Z')
      lastz = i;
  }
  int ans = lastz - firsta + 1;
  cout<<ans<<"\n";
  return 0;
}


Measured memory_bytes: 848
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i <= n; i++)
#define FORR(i, m, n) for(int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define VSORTR(v) sort(v.rbegin(), v.rend());
#define ALL(v) (v).begin(),(v).end()
 
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll, ll>;

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

    string s;
    cin >> s;
    ll n = s.size(), res = 0;
    REP(i, n) {
        if (i > n - 1 - i) break;
        if (s[i] != s[n - 1 - i]) res++;
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int box;
int c[203][3] = {0};

int main()
{
    int n;
    int a[201][3];
    scanf("%d",&n);
    for(int i = 0; i < n; i++){
        scanf("%d %d %d",&a[i][0],&a[i][1],&a[i][2]);
    }
    for(int i = 0; i < 3; i++)
    {
        for(int j = 0; j < n; j++)
        {
            for(int k = j + 1; k < n; k++)
            {
                if(a[j][i] == a[k][i])
                {
                     c[j][i] = 1;
                     c[k][i] = 1;
                }

            }
        }
    }
    for(int i = 0; i < n; i++)
    {
        for(int j = 0; j < 3; j++)
        {
            if(c[i][j] == 1)
            {
                a[i][j] = 0;
            }
        }
    }


    for(int j = 0; j < n; j++)printf("%d\n",a[j][0] + a[j][1] + a[j][2]);
    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
int main()
{
	using namespace std;
	string s;
	int c = 0;
	cin >> s;
	for (int i = 0; i < s.length(); ++i) {
		if (s[i] == '1') {
			c++;
		}
	}

	cout << c << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>

int main(void)
{

    char c_inputString[101];

    scanf("%s", c_inputString);

    for (int index = 0; index < strlen(c_inputString); index++)
    {
        c_inputString[index] = 'x';
    }

    printf("%s", c_inputString);

}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define modulo 1000000007
#define mod(mod_x) ((((long long)mod_x+modulo))%modulo)
#define Inf 1000000000

int main(){
	
	string S;
	cin>>S;
	
	if(S.size()>=10){
		cout<<"NO"<<endl;
		return 0;
	}
	
	for(int i=0;i<(1<<(S.size()+1));i++){
		string X = "";
		
		for(int j=0;j<S.size();j++){
			if((1<<j)&i){
				X += 'A';
			}
			X += S[j];
		}
		
		if((1<<S.size())&i)X += 'A';
		
		if(X=="AKIHABARA"){
			cout<<"YES"<<endl;
			return 0;
		}
	}
	
	cout<<"NO"<<endl;
	
	return 0;
}

Measured memory_bytes: 256
import java.io.*;
import java.util.*;
import static java.lang.System.*;
import static java.lang.Math.*;

public class Main
{	
	public static void main(String []args)throws IOException
	{
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		
		String []s=br.readLine().split(" ");
		
		int ans=0;
		
		for(int i=0;i<5;i++)
		{
			int a=Integer.parseInt(s[i]);
				if(a==0)
					ans=i+1;
		}
			
		out.println(ans);
		
	}
	
	
}




Measured memory_bytes: 32780
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    String X = sc.next();
    String Y = sc.next();
    if(X.charAt(0) < Y.charAt(0)){
      System.out.println("<");
    }else if(X.charAt(0) == Y.charAt(0)){
      System.out.println("=");
    }else{
      System.out.println(">");
    }
  }
}


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

using namespace std;

#define MOD 1000000007
#define PI 3.1415926535897932384626433832795
#define INF (int)1e9
typedef long long int int64;

void print() {
    cout << endl;
}

void print(string s, bool endline = true) {
    cout << s;
    if (endline) print();
}

void print(int s, bool endline = true) {
    cout << s;
    if (endline) print();
}

template <typename T, typename T2>
void print(pair<T, T2>& p, bool endline = true) {
    print("(", false);
    print(p.first, false);
    print(", ", false);
    print(p.second, false);
    print(")", false);

    if (endline) print();
}

template <typename T, typename T2>
void print(map<T, T2>& m, bool endline = true) {
    print("{");
    for (auto& p : m) {
        print("  ", false);
        print(p);
    }
    print("}");

    if (endline) {}
}

template<typename T>
void print(vector<T>& v, bool endline = true) {
    print("[", false);
    for (size_t i = 0; i < v.size(); ++i) {
        print(v[i], false);
        if(i != v.size() - 1) print(",", false);
    }
    print("]", false);

    if(endline) print();
}

template <typename T>
vector<T> operator+(const vector<T> &a, const vector<T> &b)
{
    vector<T> ret;
    ret.reserve( a.size() + b.size() );                // preallocate memory
    ret.insert( ret.end(), a.begin(), a.end() );        // add A;
    ret.insert( ret.end(), b.begin(), b.end() );        // add B;

    return ret;
}

template <typename T>
vector<T> &operator+=(vector<T> &a, const vector<T> &b)
{
    a.reserve( a.size() + b.size() );                // preallocate memory without erase original data
    a.insert( a.end(), b.begin(), b.end() );         // add B;
    return a;
}

int main() {
    // g++ -Wall -Wextra -O2 -std=c++17 helloworld.cpp
    string s;

    cin >> s;

    vector<string> days = {"SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"};

    auto it = find(days.begin(), days.end(), s);

    cout << 7 - distance(days.begin(), it) << endl;

    return 0;
}

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

using namespace std;

#define debug(n) cerr << #n << ':' << n << endl;
#define dline    cerr << __LINE__ << endl;

using ll = long long;
template<class T, class U> using P = pair<T,U>;
template<class T> using Heap = priority_queue<T>;
template<class T> using heaP = priority_queue<T,vector<T>,greater<T>>;
template<class T,class U> using umap = unordered_map<T,U>;
template<class T> using uset = unordered_set<T>;

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

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

template<class T, size_t N, class U>
void Fill(T (&a)[N], const U&v){
    fill((U*)a,(U*)(a+N),v);
}

template<class T>
istream& operator >> (istream&is, vector<T>&v){
  for(auto&e:v)is >> e;
  return is;
}

int main(){
  string s,t; cin >> s >> t;
  const int slen = (int)s.size(), tlen = (int)t.size();
  vector<vector<int>> dp(slen+1,vector<int>(tlen+1,0));
  for(int i = 1; i <= slen; ++i){
    for(int j = 1; j <= tlen; ++j){
      dp[i][j] = max(dp[i-1][j],dp[i][j-1]);
      if(s[i-1] == t[j-1]){
	ChangeMax(dp[i][j],dp[i-1][j-1] + 1);
      }
    }    
  }
  string ans;
  int spos = slen, tpos = tlen;
  while(spos > 0 && tpos > 0){
    if(s[spos-1] == t[tpos-1]){
      ans += s[spos-1];
      spos--;
      tpos--;
    } else {
      if(dp[spos-1][tpos] > dp[spos][tpos-1])spos--;
      else tpos--;
    }
  }
  if(ans.size() > 0)reverse(ans.begin(), ans.end());
  cout << ans << endl;
  return 0;
}

// int main(){
//   string s,t; cin >> s >> t;
//   static string mp[3001][3001] = {};
//   int slen = (int)s.size(), tlen = (int)t.size();
//   vector<vector<int>> dp(slen+1,vector<int>(tlen+1,0));
//   for(int i = 1; i <= slen; ++i){
//     for(int j = 1; j <= tlen; ++j){
//       dp[i][j] = max(dp[i-1][j],dp[i][j-1]);
//       mp[i][j] = (dp[i-1][j] < dp[i][j-1] ? mp[i][j-1] : mp[i-1][j]);
//       if(s[i-1] == t[j-1]){
// 	if(ChangeMax(dp[i][j],dp[i-1][j-1] + 1)) mp[i][j] = mp[i-1][j-1] + s[i-1];
//       }
//       mp[i-1][j-1]="";
//       mp[i-1][j-1].shrink_to_fit();
//     }    
//   }
//   cout << mp[slen][tlen] << endl;
//   return 0;
// }


Measured memory_bytes: 35712
N = int(input())
abc = [list(map(int, input().split())) for _ in range(N)]

dp = [[0] * 3 for _ in range(N+1)]

for i in range(1, N+1):
    for j in range(3):
        for k in range(3):
            if j != k:
                dp[i][j] = max(dp[i][j], dp[i-1][k] + abc[i-1][k])

print(max(dp[N]))

Measured memory_bytes: 74072
#include <cmath>

#include <algorithm>
#include <iostream>
#include <string>
#include <vector>

using namespace std;

using ll = long long;
using ld = long double;
using vi = vector<int>;

int n;
int a;
int b;

void input() {
  cin >> n >> a >> b;
}

void solve() {
  ll ans = 1 + 1ll * (n - 2) * (b - a);

  if (a > b || (n == 1 && a != b))
    ans = 0;

  if (n ==  1 && a == b)
    ans = 1;

  cout << ans << '\n';
}

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

  cout.precision(16);
  cout << fixed;

  int _times = 1;

#ifdef _DEBUG
  freopen("input.txt", "r", stdin);
  //freopen("output.txt", "w", stdout);

  _times = 4;
#endif

  // cin >> _times;

  while (_times--) {
    input();
    solve();
  }
}


Measured memory_bytes: 3652
#include <bits/stdc++.h>
#include <vector>
#include <iostream>
#include<algorithm>
#include<string>
#include <map>
#include <queue>
#include <stack>

#define DIV 1000000007
using namespace std;

void many_e(long long &ans, string &s,vector<int> &bit) {
    long long digi = 1;
    for (int i = 0; i < s.size(); i++) {
        if (bit[i]) ans += (s[i] - '0') *digi, digi = 1;
        else {
            ans += (s[i]-'0') * digi;
            digi *= 10;
        }
    }
    //cout << ans << endl;
}
int main() {
    string s;
    cin >> s;
   
    int len = s.size();
    vector<int> bit(len);
    long long ans = 0;
    reverse(s.begin(), s.end());
    for (int i = 0; i < pow(2, len-1); i++) {
        int temp = i;
        for (int j = 0; temp > 0; j++) {
            bit[j] = temp % 2;
            temp /= 2;
        }
        many_e(ans, s, bit);
    }
    cout << ans << endl;
}

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

int main(){
    int n;
    cin >> n;
    long long a[n];
    long long m = 1000000000000000000LL;

    rep(i,n){
        cin >> a[i];
        if(a[i]==0){
            cout << 0 << endl;
            return 0;
        }
    }

    long long ans=1LL;
    rep(i,n){
        if(ans > m/a[i] ){
            cout << "-1" << endl;
            return 0;
        }
        ans *= a[i];
    }

    cout << setprecision(20)<< ans << endl;

    return 0;
}

Measured memory_bytes: 4404
import java.util.*;
import java.io.*;
import java.lang.*;
public class Main{
public static void main(String[] args) throws FileNotFoundException, IOException{
       Scanner s=new Scanner(System.in);
       int n=s.nextInt(),k=s.nextInt();
       //boolean[][] dp=new boolean[n+1][k+1];
       int[] arr=new int[n+1];
       for(int i=1;i<=n;i++){
        arr[i]=s.nextInt();
       }
       boolean[] b=new boolean[k+1];
       /*for(int i=1;i<=n;i++){
        for(int j=1;j<=k;j++){
          if(arr[i]>j){
            dp[i][j]=dp[i-1][j];
          }
          else{
            dp[i][j]=dp[i-1][j]||(!dp[i][j-arr[i]]);
          }
        }
       }*/
       for(int i=0;i<=k;i++){
        if(!b[i]){
          for(int j=1;j<=n;j++){
            if(i+arr[j]<=k){b[i+arr[j]]=true;}
          }
        }
       }

       if(b[k]){
        System.out.println("First");
       }
       else{System.out.println("Second");}
        }
    }


Measured memory_bytes: 23764
#include <iostream>
#include <cstring>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <tuple>
#include <queue>
#include <set>
#include <cstdio>
#include <climits>
#include <cmath>
#include <array>
#include <functional>
#include <list>
#include <iomanip>
#include <set>
const int MOD=1000000007;
const int INF=1000000000;
using namespace std;
typedef long long ll;
typedef vector<int> vi;
const double eps=1e-9;
const int inf=1e9;
typedef pair<int,int> P;
struct Point
{
  double x,y;
  Point(){x=0;y=0;}
  Point(double d_x,double d_y){x=d_x,y=d_y;}
  double operator*(Point obj){return obj.x*x+obj.y*y;}
  double operator%(Point obj){return obj.y*x-obj.x*y;}
  Point operator*(double b){Point tmp;tmp.x=x*b;tmp.y=y*b;return tmp;}
  Point operator/(double b){Point tmp;tmp.x=x/b;tmp.y=y/b;return tmp;}
  Point operator+(Point obj){Point tmp;tmp.x=x+obj.x;tmp.y=y+obj.y;return tmp;}
  Point operator-(){Point tmp;tmp.x=-x;tmp.y=-y;return tmp;}
  Point operator-(Point obj){Point tmp;tmp.x=x-obj.x;tmp.y=y-obj.y;return tmp;}
  Point operator-=(Point obj){x-=obj.x;y-=obj.y;return *this;}
  Point operator+=(Point obj){x+=obj.x;y+=obj.y;return *this;}
  Point operator/=(double b){x=x/b;y=y/b;return *this;}
  Point operator*=(double b){x=x*b;y=y*b;return *this;}
  double size(){return hypot(x,y);}
  Point unit(){return Point(x/size(),y/size());}
  Point normal(){return Point(y,-x);}
  double atan(){return atan2(y,x);}
};

bool operator<(Point a,Point b){return a.x!=b.x?a.x<b.x:a.y<b.y;}
bool operator>(Point a,Point b){return b<a;}
bool operator<=(Point a,Point b){return !(b<a);}
bool operator>=(Point a,Point b){return !(a<b);}
bool operator==(Point a,Point b){return (a-b).size()<eps;}
bool operator!=(Point a,Point b){return !(a==b);}

bool equal(double a,double b){return abs(a-b)<eps;}
double cross(Point a,Point b){return a%b;}
double dot(Point a,Point b){return a*b;}

int ccw(Point a,Point b,Point c)
{
  b=b-a;
  c=c-a;
  if(b%c>0) return +1;
  else if(b%c<0)return -1;
  else if(b*c<0) return +2;
  else if(b.size()<c.size()) return -2;
  else return 0;
}

int n;
int main(int argc,char const* argv[])
{
  cin >> n;
  for(int i=0;i<n;i++)
    {
      unsigned int c[9];
      unsigned int ans=0;
      for(int j=0;j<9;j++)
	{
	  cin >> hex >> c[j];
	}
      for(int j=0;j<32;j++)
	{
	  unsigned int sum=0;
	  for(int k=0;k<8;k++)
	    {
	      sum+=c[k]^ans;
	    }
	  if((sum&(1<<j)) !=(c[8]&(1<<j))) ans |=1<<j;
	    
	}
      cout << hex << ans << endl;
    }
  return 0;
}



Measured memory_bytes: 3100
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <iomanip>
#include <vector>
#include <string.h>
#include <string>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <math.h>
#include <algorithm>
#include <numeric>

using namespace std;

// マクロ&定数 ============================================================
typedef unsigned int uint;
typedef long long ll;
//typedef pair<int, int> P;

typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<double> vdouble;
typedef vector<bool> vbool;
typedef vector<string> vstring;

typedef vector<pair<int, int>> vpint;
typedef vector<pair<ll, ll>> vpll;
typedef vector<pair<double, double>> vpdouble;

typedef vector<vector<int>> vvint;
typedef vector<vector<ll>> vvll;
typedef vector<vpint> vvpint;
typedef vector<vpll> vvpll;
typedef vector<vector<double>> vvdouble;
typedef vector<vector<string>> vvstring;
typedef vector<vector<bool>> vvbool;

typedef vector<vector<vector<ll>>> vvvll;

const int c_YET = -1;
const int INF = 1e9 + 1;
const ll LLINF = 1e17 + 1;
const int DX[9] = { 0,0,1,-1, 1, 1, -1, -1, 0 }; // 4;４近傍
const int DY[9] = { 1,-1,0,0, 1, -1, 1, -1, 0 }; // 8:８近傍 9:(0,0)を含む
const ll MOD = 1e9 + 7; //10^9 + 7
const ll MAX = 1e9;
const double PI = 3.14159265358979323846264338327950288;
//========================================================================





int main() {

	////==================================
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(30);
	////==================================


	ll N, K;
	cin >> N;
	string S;
	cin >> S;
	cin >> K;


	char target = S[K - 1];

	for (int i = 0; i < N; i++)
	{
		if (S[i] != target)
		{
			S[i] = '*';
		}
	}

	cout << S << endl;





}





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

/**
 * Block
 */
public class Main {

	static int[][] board;
	final static int BLOCK_WIDTH = 4;
	final static int BLOCK_HEIGHT = 2;
	final static int EMPTY = 0;

	static int w, h;

	public static void main(String[] args) throws IOException {

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line = "";

		while (!(line = br.readLine()).equals("0 0")) {

			w = Integer.parseInt(line.substring(0, line.indexOf(' ')));
			h = Integer.parseInt(line.trim().substring(line.indexOf(' ') + 1));

			board = new int[w + 1][h + 1];

			line = br.readLine();
			int xs = Integer.parseInt(line.substring(0, line.indexOf(' ')));
			int ys = Integer.parseInt(line.substring(line.indexOf(' ') + 1));

			line = br.readLine();
			int xg = Integer.parseInt(line.substring(0, line.indexOf(' ')));
			int yg = Integer.parseInt(line.substring(line.indexOf(' ') + 1));

			int n = Integer.parseInt(br.readLine());
			for (int i = 0; i < n; ++i) {
				putBlock(br.readLine());
			}

			if (solve(xs, ys, xg, yg)) {
				System.out.println("OK");
			} else {
				System.out.println("NG");
			}

		}

	}

	static void putBlock(String info) {
		StringTokenizer st = new StringTokenizer(info);

		int c, d, x, y;
		c = Integer.parseInt(st.nextToken());
		d = Integer.parseInt(st.nextToken());
		x = Integer.parseInt(st.nextToken());
		y = Integer.parseInt(st.nextToken());

		putBlock(c, d, x, y);
	}

	static void putBlock(int c, int d, int x, int y) {

		if (d == 0) {
			for (int i = x; i < x + BLOCK_WIDTH; ++i) {
				for (int j = y; j < y + BLOCK_HEIGHT; ++j) {
					// assert board[i][j] == EMPTY;
					board[i][j] = c;
				}
			}
		} else {
			for (int i = x; i < x + BLOCK_HEIGHT; ++i) {
				for (int j = y; j < y + BLOCK_WIDTH; ++j) {
					// assert board[i][j] == EMPTY;
					board[i][j] = c;
				}
			}
		}
	}

	static boolean solve(int xs, int ys, int xg, int yg) {

		final int V[] = { 1, -1, 0, 0 };
		final int H[] = { 0, 0, 1, -1 };

		if (board[xs][ys] != board[xg][yg]) {
			return false;
		}

		int[] next, prev;
		int color = board[xs][ys];

		next = new int[] { xs, ys };
		ArrayDeque<int[]> queue = new ArrayDeque<int[]>();

		queue.offer(next);
		board[xs][ys] = EMPTY;

		while (!queue.isEmpty()) {

			prev = queue.poll();

			int px, py, nx, ny;
			px = prev[0];
			py = prev[1];
			board[px][py] = EMPTY;

			if (px == xg && py == yg) {
				return true;
			}

			for (int i = 0; i < 4; ++i) {
				nx = px + V[i];
				ny = py + H[i];
				if (nx > 0 && nx < w + 1 && ny > 0 && ny < h + 1) {
					if (board[nx][ny] == color) {
						queue.offer(new int[] { nx, ny });
						board[nx][ny] = EMPTY;
					}
				}
			}
		}

		return false;
	}
}

Measured memory_bytes: 18572
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define REP(i, n) for(int i=0;i<(n);++i)
typedef long long ll;

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

	int n, a[100000], b[100000], c[100000];
	cin >> n;
	REP(i, n) cin >> a[i] >> b[i] >> c[i];

	int dp[100010][5];
	REP(i, 5) dp[0][i] = 0;
	for(int i = 1; i <= n; i++){
		for(int j = 1; j <= 3; j++){
			if(j == 1) dp[i][j] = max(dp[i-1][2]+b[i-1], dp[i-1][3]+c[i-1]);
			if(j == 2) dp[i][j] = max(dp[i-1][1]+a[i-1], dp[i-1][3]+c[i-1]);
			if(j == 3) dp[i][j] = max(dp[i-1][1]+a[i-1], dp[i-1][2]+b[i-1]);
		}
	}
	cout << max({dp[n][1], dp[n][2], dp[n][3]}) << endl;

	return 0;
}


Measured memory_bytes: 3328
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <climits>
#include <string>
#include <bitset>
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef pair<int,int> P;
typedef vector<pair<int,int> > vpii;
typedef vector<pair<string,int>> vpsi;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define fin(ans) cout<<(ans)<<endl
#define STI(s) atoi(s.c_str())
#define mp(p,q) make_pair(p,q)
#define pb(n) push_back(n)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define Sort(a) sort(a.begin(),a.end())
#define Rort(a) sort(a.rbegin(),a.rend())
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
const int MOD = 1000000007;
const int INF = INT_MAX;
const ll LLINF = 1LL<<60;



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

int h,a;
cin >> h >> a;
int i=0;
for(i=0;h>0;i++)h-=a;
fin(i);

//////////////////////////////////////////////////////
return 0;}

Measured memory_bytes: 256
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <queue>
#include <sstream>
#include <stack>
#include <time.h>
#include <vector>
#include <complex>
#include <map>
#include <set>
#include <iomanip>
#include <math.h>
#include <stdlib.h>
using namespace std;
vector<int>p[100004];
queue<int>q;
int v1[100003];
int v2[100003];
void dfs1(){
 int j,x,y;
 q.push(1);
 q.push(0);
 while(!q.empty()){
   x=q.front();
   q.pop();
   y=q.front();
   q.pop();
   for(int i=0;i<p[x].size();i++){
     j=p[x][i];
     if(v1[j]==0){
     v1[j]=y+1;
     q.push(j);
     q.push(y+1);
     }
   }
  }
}
void dfs2(int n){
  int j,x,y;
  while(!q.empty())
    q.pop();
    q.push(n);
    q.push(0);
    while(!q.empty()){
      x=q.front();
      q.pop();
      y=q.front();
      q.pop();
      for(int i=0;i<p[x].size();i++){
	    j=p[x][i];
        if(v2[j]==0){
          v2[j]=y+1;
          q.push(j);
          q.push(y+1);
        }
     }
   }
}
int main(){
  int n,x,y;
  cin>>n;
  for(int i=1;i<n;i++){
    cin>>x>>y;
    p[x].push_back(y);
    p[y].push_back(x);
  }
for(int i=0;i<100000;i++)
  if(v1[i]!=0)
  v1[i]=0;
  v1[1]=-1;
  dfs1();
  for(int i=0;i<100000;i++)
    if(v2[i]!=0)
      v2[i]=0;
  v2[n]=-1;
  dfs2(n);
  v2[n]=-1;
  y=0;
  for(int i=1;i<=n;i++)
    if(v2[i]<v1[i])y++;
  x=n-y;
  if(x>y)cout<<"Fennec";
  else cout<<"Snuke";
  return 0;
}

Measured memory_bytes: 6784
/*
  AOJ 1018
  Title:
  @kankichi573
*/
#include <stdio.h>
#include <stdlib.h>

int N,time[100];

int compare(const void *a, const void *b)
{
  return( *(int *)a - *(int *)b);
}


main()
{
  int i,ret;
  while(EOF!=scanf("%d",&N))
    {
      for(i=0;i<N;i++)
	scanf("%d",&time[i]);
      qsort(time,N,sizeof(int),compare);
      for(i=ret=0;i<N;i++)
	ret += (N-i)*time[i];
      printf("%d\n",ret);
    }
  return(0);
}

Measured memory_bytes: 604
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <tuple>
#include <numeric>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 2LL*1e18;
const double pi = acos(-1);

ll dp[2][42];  /* dp[id][i+1] : xの先頭からiビット目まで決めたときのf(x)の最大値。
                                ただし、id = 0 のときxは現時点でkと等しい。
                                id = 1 のときxは現時点でkより小さいことが確定。 */

int main() {
    ll n, k;
    cin >> n >> k;
    
    vl v0(41);  // v0[i] : 先頭からiビット目の0の個数
    vl v1(41);  // v1[i] : 先頭からiビット目の1の個数
    rep(loop, n) {
        ll a;
        cin >> a;
        exrep(i, 0, 40) {
            ll mask = 1LL<<(40 - i);
            if(mask & a) {
                v1[i]++;
            }
            else {
                v0[i]++;
            }
        }
    }

    rep(id, 2) {
        rep(i, 42) {
            dp[id][i] = -INF;
        }
    }
    
    dp[0][0] = 0;
    exrep(i, 0, 40) {
        ll mask = 1LL<<(40 - i);
        if(k & mask) {  // kの先頭からiビット目が1のとき
            chmax(dp[0][i+1], dp[0][i] + mask*v0[i]);
            chmax(dp[1][i+1], max(dp[1][i] + mask*max(v0[i], v1[i]), dp[0][i] + mask*v1[i]));
        }
        else {  // kの先頭からiビット目が0のとき
            chmax(dp[0][i+1], dp[0][i] + mask*v1[i]);
            chmax(dp[1][i+1], dp[1][i] + mask*max(v0[i], v1[i]));
        }
    }
    
    out(max(dp[0][41], dp[1][41]));
    re0;
}

Measured memory_bytes: 256
class EightPuzzle
  DX = [0, -1, 0, 1]
  DY = [-1, 0, 1, 0]
  TARGET = [1, 2, 3, 4, 5, 6, 7, 8, 0]

  class Puzzle
    attr_accessor :place, :sp, :cnt

    def initialize(place)
      @place = place
      @sp = place.index(0)
      @cnt = 0
    end

    def initialize_copy(obj)
      @place = obj.place.dup
      @sp = obj.sp
      @cnt = obj.cnt
    end
  end

  def initialize
    place = []
    3.times do
      place << gets.split.map(&:to_i)
    end
    place.flatten!
    @puz = Puzzle.new(place)
    @q = []
    @s = {}
  end

  def solve
    @q << @puz
    @s[@puz.place] = true

    while !@q.empty?
      puz = @q.shift
      return puz.cnt if puz.place == TARGET
      sx = puz.sp % 3
      sy = puz.sp / 3
      (0..3).each do |i|
        x = sx + DX[i]
        y = sy + DY[i]
        next if x < 0 || 2 < x || y < 0 || 2 < y
        v = puz.dup
        v.place[puz.sp], v.place[3 * y + x] = v.place[3 * y + x], v.place[puz.sp]
        v.sp = 3 * y + x
        unless @s[v.place]
          @s[v.place] = true
          v.cnt += 1
          @q << v
        end
      end
    end
  end
end

ep = EightPuzzle.new
puts ep.solve

Measured memory_bytes: 72920
#include<bits/stdc++.h>
#pragma GCC optimize ("Ofast")
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#ifdef __debug_leywart
#include<debug/to_string.h>
#else
#define db1(x) ;
#define db2(x,begin,end) ;
#define db3(x) ;
#define db4(x,begin,end) ;
#define dbmat1(x,begin_v,end_v,begin_h,end_h) ;
#define dbmat2(x,begin_v,end_v,begin_h,end_h) ;
#define dbin1(x) ;
#define dbin2(x,begin,end) ;
#define dbtree(x,size) ;
#endif
using namespace std;
#define F first
#define S second
#define int long long

///My functions
void sread ( string &s ){ cin >> s ; s = '_' + s ; }
void sprint ( string &s ){ cout << s.substr( 1 , s.size() ) ; } 

//Constants
const int mxn = 3005, inf = 1e9+7, mod = 998244353;
const long long infLL = 1e18+5;
const double EPS = 1e-9 , PI = acos(-1);

//Structs

//Variables
int n,m,Q,k,a,b,c,S,sum,ans,MAXans,MINans,sc,pos,acc[mxn],racc[mxn],ar[mxn],dp[mxn];
vector<int>v,g[mxn];
bitset<mxn>flag;
bool sol ;
string s;

int32_t main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    
    cin >> n >> S ;
    dp[0] = 1 ; 
    for(int i = 1 ; i <= n ; i++){
        cin >> a ;
        for( int j = S ; j >= 0 ; j-- ){

            if( j + a <= S ) {

                dp[j + a] += dp[j];
                dp[j + a] %= mod ; 
            
            }

            dp[j] += dp[j] ;
            dp[j] %= mod ; 

        }

    }

    cout << dp[S] ; 

    return 0;
}
























Measured memory_bytes: 3780
N = int(input())
B = list(map(int, input().split()))
ans = 0
ans += B[0]
ans += B[N-2]
for i in range(N-2):
  if B[i] <= B[i+1]:
    ans += B[i]
  else:
    ans += B[i+1]
print(ans)

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

// region template
#define rep(i, a, b) for (int i = (a); i < (b); ++i)
#define trav(a, x) for (auto &a : x)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;

ll gcd(ll a, ll b) { return __gcd(a, b); }

ll euclid(ll a, ll b, ll &x, ll &y) {
    if (b) { ll d = euclid(b, a % b, y, x);
        return y -= a/b * x, d; }
    return x = 1, y = 0, a;
}

typedef unsigned long long ull;
typedef long double ld;
ull mod_mul(ull a, ull b, ull M) {
    ll ret = a * b - M * ull(ld(a) * ld(b) / ld(M));
    return ret + M * (ret < 0) - M * (ret >= (ll)M);
}
ull mod_pow(ull b, ull e, ull mod) {
    ull ans = 1;
    for (; e; b = mod_mul(b, b, mod), e /= 2)
        if (e & 1) ans = mod_mul(ans, b, mod);
    return ans;
}

const ll mod = 1000000007;
struct Mod {
    ll x;
    Mod(ll xx) : x(xx) {}
    Mod operator+(Mod b) { return Mod((x + b.x) % mod); }
    Mod operator-(Mod b) { return Mod((x - b.x) % mod); }
    Mod operator*(Mod b) { return Mod((x * b.x) % mod); }
    Mod operator/(Mod b) { return *this * invert(b); }
    Mod invert(Mod a) {
        ll x, y, g = euclid(a.x, mod, x, y);
        assert(g == 1); return Mod((x + mod) % mod);
    }
    Mod operator^(ll e) {
        if (!e) return Mod(1);
        Mod r = *this ^ (e / 2); r = r * r;
        return e & 1 ? *this * r : r;
    }
};
// endregion

int main() {
    cin.sync_with_stdio(0); cin.tie(0); cin.exceptions(cin.failbit);

    int x, y, a, b, c; cin >> x >> y >> a >> b >> c;
    priority_queue<pair<ll, int>> pq;

    rep(i, 0, a) { int t; cin >> t; pq.push({t, 1}); }
    rep(i, 0, b) { int t; cin >> t; pq.push({t, 2}); }
    rep(i, 0, c) { int t; cin >> t; pq.push({t, 3}); }

    int ttl = x + y;
    ll ans = 0;
    rep(i, 0, ttl) {
        while (true) {
            pair<ll, int> e = pq.top(); pq.pop();
            if (e.second == 1) {
                if (x == 0) continue;
                x--;
            } else if (e.second == 2) {
                if (y == 0) continue;
                y--;
            }
            ans += e.first;
            break;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 10604
module.exports=function(t){var e={};function n(r){if(e[r])return e[r].exports;var i=e[r]={i:r,l:!1,exports:{}};return t[r].call(i.exports,i,i.exports,n),i.l=!0,i.exports}return n.m=t,n.c=e,n.d=function(t,e,r){n.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:r})},n.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},n.t=function(t,e){if(1&e&&(t=n(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var r=Object.create(null);if(n.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var i in t)n.d(r,i,function(e){return t[e]}.bind(null,i));return r},n.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return n.d(e,"a",e),e},n.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},n.p="",n(n.s=0)}([function(t,e,n){"use strict";var r=n(1);n(2)(r.readFileSync("/dev/stdin","utf8"))},function(t,e){t.exports=require("fs")},function(t,e,n){"use strict";var r=n(3),i=n(5);t.exports=function(t){var e=new r(t);i(e)}},function(t,e,n){"use strict";var r=n(4);t.exports=class{constructor(t){var e=t.trim().split(/\s+/g);this.inp=new r(e)}inr(){return this.inp.deq()}in(){return parseInt(this.inp.deq(),10)}fin(){this.inp.clear()}}},function(t,e,n){"use strict";t.exports=class{constructor(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[];this.size=t.length,this.items=t,this.ind=0}enq(t){this.size+=1,this.items.push(t)}deq(){var t=this.items[this.ind];return this.size-=1,this.ind+=1,t}clear(){this.items=[],this.size=0,this.ind=0}}},function(t,e,n){"use strict";t.exports=function(t){var e=t.in(),n=t.in();console.log(e/n)}}]);

Measured memory_bytes: 7372
from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,datetime
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())

dx = [1,1,1,0,0,0,-1,-1,-1]
dy = [1,0,-1,1,0,-1,1,0,-1]

def dfs(x,y):
    global MAP
    if MAP[y][x] == 0:
        return
    else:
        MAP[y][x] = 0
        for i in range(9):
            dfs(x+dx[i],y+dy[i])


while True:
    W,H = inpl()
    if W == 0:
        break
    else:
        MAP = [[0] + inpl() + [0] for i in range(H)]
        MAP = [[0]*(W+2)] + MAP + [[0]*(W+2)]
        ans = 0
        for y in range(1,H+1):
            for x in range(1,W+1):
                if MAP[y][x] == 1:
                    ans += 1
                    dfs(x,y)
        print(ans)



Measured memory_bytes: 9684
// Grid-1

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
import java.util.Arrays;

class Main {
	public static void Grid1(char[][] arr, int m, int n) {
		long[][] dp = new long[m+1][n+1];
		long mod = 1000000007l;
		for(int i = 0; i <= m; i++)
			dp[i][0] = 0;;

		for(int i = 0; i <= n; i++)
			dp[0][i] = 0l;

		for(int i = 1; i <= m; i++) {
			for(int j = 1; j <= n; j++) {
				if(i == 1 && j == 1) {
					dp[i][j] = 1l;
				}
				else if(arr[i-1][j-1] == '.') {
					dp[i][j] = (dp[i-1][j]+dp[i][j-1])%mod;
				}
				else {
					dp[i][j] = 0l;
				}
			}
		}
		System.out.println((dp[m][n]%mod));
	}

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

		int m = Integer.parseInt(s[0]);
		int n = Integer.parseInt(s[1]);

		char[][] arr = new char[m][n];
		for(int i = 0; i < m; i++) {
			String temp = br.readLine();
			for(int j = 0; j < n; j++) {
				arr[i][j] = temp.charAt(j);
			}
		}
		Grid1(arr, m, n);
	}

	public static int max(int...arr) {
		int max = Integer.MIN_VALUE;
		for(int i: arr) {
			if(i > max)
				max = i;
		}
		return max;
	}
}


Measured memory_bytes: 40500
#include <iostream>
#include <vector>
#include <array>
#include <algorithm>
#include <cstring>
#include <queue>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <cstdlib>
#include <sstream>
#include <bitset>

using namespace std;

using ll = long long;
using Vec = vector<ll>;
using P = pair<ll, ll>;
using VecP = vector<P>;
#define rep(i, n) for(ll i=0;i<(n);i++)
#define SIZE_OF_ARRAY(array) (sizeof(array)/sizeof(array[0]))

//static const ll MOD = 1000000007;
//static const ll INF = 100000000;
//#define PI 3.14159265359


int main() {
    // input
    ll N;
    cin >> N;
    vector<int> D(N, 0);
    for (int i = 0; i < N; ++i) {
        cin >> D[i];
    }

    //process
    sort(D.begin(), D.end());

    ll ans = 24;
    ll r = 0, l = 0;
    rep(i, N) {
        if (i % 2 == 0) {
            ans = min(ans, abs(l - D[i]));
            ans = min(ans, abs(r - D[i]));
            r = D[i];
        } else {
            ans = min(ans, abs(l - (24 - D[i])));
            ans = min(ans, abs(r - (24 - D[i])));
            l = 24 - D[i];
        }
    }

    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 256
import sys

def solve():
    file = sys.stdin.readline
    N = int(file())
    A = [None] * N
    mindig = [0 for i in range(30)]
    nim = 0
    for i in range(N):
        a = int(file())
        A[i] = a
        nim ^= a
        reverse = format(a ^ (a - 1), "b").zfill(30)
        for j in range(30):
            if reverse[j] == "1":
                mindig[j] += 1
                break
    if nim == 0: print(0)
    else:
        nim = format(nim, "b").zfill(30)
        flip = 0
        for i in range(30):
            if nim[i] == "1":
                if flip % 2 == 0:
                    if mindig[i] == 0:
                        print(-1)
                        break
                    else: flip += 1
            else:
                if flip % 2 == 1:
                    if mindig[i] == 0:
                        print(-1)
                        break
                    else: flip += 1
        else: print(flip)
    return 

if __name__ == "__main__":
    solve()

Measured memory_bytes: 6980
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Scanner;
import java.util.concurrent.SynchronousQueue;

public class Main {
	public static void main(String[] args) {
		new Main().solve();
	}

	void solve() {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int d = sc.nextInt();
		int x = sc.nextInt();
		double[] F = new double[200001];
		double[] G = new double[200001];
		{
			Arrays.fill(F, -1);
			Arrays.fill(G, -1);
		}
		F[1] = 0.5;
		G[1] = 1;
		for (int i = 2; i <= 200000; ++i) {
			F[i] = (1 + 2. / i) * F[i - 1] + 5. / (2 * i) * G[i - 1] + 1. / (2 * i) * i * (2 * i - 1);
			G[i] = (1 + 1. / i) * G[i - 1] + 1;
		}
		System.out.println(String.format("%.20f", F[n] * x + d * G[n]));
	}

	public static void tr(Object... objects) {
		System.out.println(Arrays.deepToString(objects));
	}
}


Measured memory_bytes: 28244