akhauriyash/Code-Regression huggingface dataset:
fun main(args : Array<String>) {
    val (N ,M) = readLine()!!.split(" ").map { it.toInt() }
    val S = mutableListOf<List<Int>>()
    (1..M).forEach {
        val kAndS = readLine()!!.split(" ").map { it.toInt() }
        S.add(kAndS.subList(1, kAndS.size))
    }
    val P = readLine()!!.split(" ").map { it.toInt() }

    val allConbinations = Math.pow(2.toDouble(), N.toDouble()).toInt()

    var answer = 0
    // O(2^N)
    for (bits in 1..allConbinations) {
        // O(N)
        val switchFlags = mutableListOf<Boolean>()
        for (i in 0..(N - 1)) {
            val iThSwitchOn = isBitSet(bits, i)
            switchFlags.add(iThSwitchOn)
        }

        var allFlashed = true
        // o(M)
        S.forEachIndexed { index, s ->
            if (allFlashed) {
                val p = P[index]
                var onCount = 0
                // O(K)
                s.forEach { switchIndex ->
                    if (switchFlags[switchIndex - 1]) {
                        onCount++
                    }
                }
                if (onCount.mod(2) != p) {
                    allFlashed = false
                }
            }
        }

        if (allFlashed) {
            answer++
        }
    }

    println(answer)
}
fun isBitSet(bit: Int, index: Int) : Boolean {
    return bit.shr(index).and(1) == 1
}

Measured memory_bytes: 39024
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <typeinfo>
#include <numeric>
#include <functional>
#include <unordered_map>
#include <bitset>
#include <stack>


using namespace std;
using ll = long long;
using ull = unsigned long long;

const ll INF = 1e16;
const ll MOD = 1e9 + 7;

#define REP(i, n) for(ll i = 0; i < n; i++)
#define Yes(condition) if(condition){ cout << "Yes" << '\n'; }else{ cout << "No" << '\n'; }
#define YES(condition) if(condition){ cout << "YES" << '\n'; }else{ cout << "NO" << '\n'; }
#define yes(condition) if(condition){ cout << "yes" << '\n'; }else{ cout << "no" << '\n'; }





int main() {
    ll n;
    cin >> n;
    vector<ll> c(13);
    c[0]++;
    REP(i, n){
        ll d;
        cin >> d;
        c[d]++;
    }
    if(c[0] >= 2 || c[12] >= 2){
        cout << 0 << endl;
        return 0;
    }
    for(ll i = 1; i < 12; i++){
        if(c[i] >= 3){
            cout << 0 << endl;
            return 0;
        }
    }
    
    ll ans = 0;
    REP(i, 1 << 11){
        vector<bool> v(24);
        v[0] = true;
        if(c[12]) v[12] = true;
        REP(j, 11){
            if(!c[j + 1]) continue;
            if(c[j + 1] == 1){
                if((i >> j) & 1){
                    v[j + 1] = true;
                }
                else{
                    v[24 - (j + 1)] = true;
                }
            }
            else{
                v[j + 1] = true;
                v[24 - (j + 1)] = true;
            }
        }
        ll mn = INF;
        REP(j, 24){
            if(!v[j]) continue;
            REP(k, 24){
                if(j == k || !v[k]) continue;
                mn = min({mn, abs(j - k), (j + 24 - k) % 24, (k + 24 - j) % 24});
            }
        }
        ans = max(ans, mn);
    }
    cout << ans << endl;
}


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

int main() {
  int n=0, a=0;
  string s;
  cin >> n;
  
  using tsii = tuple<string, int, int>;
  using vtsii = vector<tsii>;
  
  vtsii restrunts(n);
  
  for (int i=0; i<n; i++) {
    cin >> s >> a;
    get<0>(restrunts.at(i)) = s;
    get<1>(restrunts.at(i)) = -a;
    get<2>(restrunts.at(i)) = i+1;
  }
  
  sort(restrunts.begin(), restrunts.end());
  
  for (int i=0; i<n; i++) {
    cout << get<2>(restrunts.at(i)) << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef pair<ll,ll> pll;	

#define fastio() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define loop(i,a,b) for(ll i=a;i<b;i++)
#define test() ll t;cin>>t;for(ll test = 1;test<=t;test++)
#define f first
#define s second
#define pb push_back
#define nl cout<<"\n"
#define MOD(x) ((x%P)+P)%P
#define vec(v) loop(i,0,v.size()) cout<<v[i]<<" "; nl
const int N = 100005;
const ll P = 1000000007;
const double eps = 1e-6;

ll dp[3005][3005];
int main()
{
	fastio();

	int n; cin>>n;

	ll arr[n];
	for(int i=0; i<n; i++) cin>>arr[i];


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

	for(int len=2; len<=n; len++)
	{
		for(int i=0; i<n-len+1; i++)
		{
			int j = i+len-1;
			dp[i][j] = max(arr[j]-dp[i][j-1], arr[i]-dp[i+1][j]);
		}
	}

	cout<<dp[0][n-1],nl;

	//cerr << "\nTime elapsed : " << 1000 * clock() / CLOCKS_PER_SEC << " ms\n";
	return 0;
}

Measured memory_bytes: 70016
def main():
    import sys
    readline = sys.stdin.readline

    inf = 10 ** 9

    n, k = map(int, readline().split())
    *h, = map(int, readline().split())
    h = [inf] + h + [inf] * (k - 1)  # 1-indexed化

    dp = [inf] * (n + k)
    dp[0] = 0
    dp[1] = 0

    for i in range(1, n):  # ジャンプ元,1-indexed
        for j in range(1, k + 1):
            dp[i + j] = min(
                dp[i + j],
                dp[i] + abs(h[i + j] - h[i]))

    print(dp[n])


if __name__ == '__main__':
    main()


Measured memory_bytes: 58460
/**
 *    author:  math2do
 *    created: 21.11.2019 16:19:13
**/

#include <bits/stdc++.h>

using namespace std;

using lli = long long int;

vector <vector <lli>> dp;


lli solve(int idx, int n, int w, vector <vector <int>> &mat) {
  if (idx == n) return 0;
  if (dp[idx][w] != -1) return dp[idx][w];

  lli ans = 0;
  if (w - mat[idx][0] >= 0) {
    ans = max(ans, mat[idx][1] + solve(idx + 1, n, w - mat[idx][0], mat));
  }
  ans = max(ans, solve(idx + 1, n, w, mat));
  return dp[idx][w] = ans;
} 

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  #ifdef LOCAL
    freopen("knapsack_1.in", "rt", stdin);
  #endif
  int n, w;
  cin >> n >> w;
  vector <vector <int>> mat(n, vector <int>(2));

  for (int i = 0; i < n; i++) {
    cin >> mat[i][0] >> mat[i][1];
  }


  dp.resize(n);
  for (int i = 0; i < n; i++) {
    dp[i].resize(w + 1);
    fill(dp[i].begin(), dp[i].end(), -1LL);
  } 

  lli ans = solve(0, n, w, mat);
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 78720
use std::cmp;

fn main() {

    let scan = std::io::stdin();

    let mut line1 = String::new();
    let mut line2 = String::new();

    scan.read_line(&mut line1);
    let n = line1.parse().unwrap_or(0);
    scan.read_line(&mut line2);

    let vec: Vec<&str> = line2.split_whitespace().collect();

    let mut min = i32::max_value();
    let mut max = i32::min_value();
    for s in vec{
        let a = s.parse().unwrap_or(0);
        min = cmp::min(min, a);
        max = cmp::max(max, a);
    }
    println!("{}",max - min);
}

Measured memory_bytes: 4352
#include<bits/stdc++.h>
#include<string>
#include<cmath>

using namespace std;

#define ll long long int
#define ld long double
#define loop(i, n) for (int i = 0; i < n; i++)
#define loops(i, s, n) for (int i = s; i < n; i++)
#define pb push_back
#define mp make_pair
#define all(v) v.begin(),v.end()
#define sz(x) ((int)(x).size())
#define fi first
#define se second
#define deb(x) cout<< #x << '=' << x <<endl
#define MOD 1000000007

int vis[10001];

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

    int x,n;
    cin>>x>>n;
    int a[n];    
    for(int i = 0; i<n; i++){
        cin>>a[i];
        vis[a[i]] = 1;
    }
    int min = INT_MAX;
    int ans = 0;
    for(int i = 0; i<=1000; i++){
        if(vis[i] == 0){
            if(abs(x - i) < min){
                min = abs(x-i);
                ans = i;
            }
        }
    }
    cout<<ans;
}

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

using std::cout;
using std::cin;
using std::endl;

int main()
{
    int64_t X;
    cin >> X;
    int64_t sum = 0;
    int64_t i;
    for (i = 1; sum < X; ++i)
        sum += i;
    cout << --i << endl;
}

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

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

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

using namespace std;

int main() {
  int n;
  cin >> n;
  if (n % 2 == 0)
    cout << n / 2 << endl;
  else
    cout << n / 2 + 1 << endl;

  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    map<int,int> s;
    for(int i=2;i*(i-1)/2<=1e5;i++)
    {
        s[i*(i-1)/2] = i;
    }
    int n;
    cin>>n;
    if(!s.count(n))
    {
        cout<<"No"<<endl;
        return 0;
    }
    cout<<"Yes"<<endl;
    int nums = s[n];
    vector<set<int>> v(nums);
    int p1=0, p2=0;
    for(int i=1;i<=n;++i)
    {
        p2++;
        v[p1].insert(i);
        v[p2].insert(i);
        if(p2 == nums-1)
        {
            p1 = p2 = p1+1;
        }
    }
    cout<<nums<<endl;
    for(auto s : v)
    {
        cout<<s.size();
        for(int x:s)
        {
            cout<<" "<<x;
        }
        cout<<endl;
    }
}

Measured memory_bytes: 10752
#include<bits/stdc++.h>
#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define rep(i,j,k) for(int i=j;i<=k;i++) 
#define dec(i,j,k) for(int i=j;i>=k;i--)
const int mod = 1e9+7;
const int N = 2e5+1;
using namespace std;
#define debug(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args);}
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " = " << a << " ";
	err(++it, args...);
}

typedef long long ll;
vector<pair<int,int>> v;
ll n,k,x,y;
ll ans;
ll arr[N];
ll binpow(ll  a , ll n)
{
	ll res = 1;
	while(n)
	{
		if(n&1)
			res=res*a%mod;
		a=a*a%mod;
		n/=2;
	}
	return res;
}
void solve()
{  cin>>n;
   ll p = binpow(10,n);
   ll q = binpow(9,n);
   ll r = binpow(8,n);
   ans = (p-2*q+r)%mod; 
   while(ans<0)ans+=mod;
   cout<<ans;
   //cerr<<"\n";
}
int main()
{ 
//#ifndef ONLINE_JUDGE
//  freopen("fi.txt","r",stdin);
//  freopen("fo.txt","w",stdout); 
//  freopen("err.txt","w",stderr);
//#endif
  int t;
  t=1;
  //cin>>t;
  while(t--)
  {
	  solve();
  }
  return 0;
}

Measured memory_bytes: 3628
#include<iostream>
#include<cstring>
using namespace std;
int main()
{
	int i,j,n,x=1,m;
	char s[200];
	scanf("%s",s); 
	n=strlen(s);
	for(i=0;i<n;i++)
	{
		if(s[i]!=s[n-i-1])
		{x=0;break;
		}
	}
	m=(n-1)/2;
		for(i=0;i<m;i++)
	{
		if(s[i]!=s[m-i-1])
		{x=0;break;
		}
	}
	m=(n+3)/2;
		for(i=m;i<n;i++)
	{
		if(s[i]!=s[n-i-1])
		{x=0;break;
		}
	}
	if(x==1)
	cout<<"Yes";
	else
	cout<<"No";
	
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int lim=2e6,N=2e6+10,mo=998244353;
ll jc[N],ny[N],n,k;
ll power(ll a,ll b=mo-2){
	ll ans=1;
	while (b){
		if (b&1)ans=ans*a%mo;
		a=a*a%mo;
		b>>=1;
	}return ans;
}
ll C(ll n,ll m){
	if (n<m||m<0)return 0;
	return (ny[m]*ny[n-m]%mo*jc[n]%mo);
}
ll calc(ll n,ll m,ll l){
//	assert(m>=l);
	if (l<=0)return 0;
	return (C(n+m,m)-C(n+m,m-l)+mo)%mo;
}
int main(){
	cin>>n>>k;
	jc[0]=1;
	for (int i=1;i<=lim;i++)jc[i]=jc[i-1]*i%mo;
	ny[lim]=power(jc[lim]);
	for (int i=lim;i;i--)ny[i-1]=ny[i]*i%mo;
	ll ans=0;
	for (int R=1;R<=k;R++){
		int B=k-R;
		if (R<B)continue;
		if (R==B)ans=(ans+calc(R,B-1,B-n+1))%mo;
		if (R>B)ans=(ans+calc(R,B,R-n+1))%mo;
//		cerr<<ans<<endl;
	}
	cout<<ans<<endl;
} 

Measured memory_bytes: 31616
#include <iostream>
#include <algorithm>

using namespace std;
typedef long long  ll;
#define rep(i,s,n)for(ll i = s;i<n;i++)

int main() {
	char s[100001]; cin >> s;

	rep(i, 0, 100001) {
		if (i % 2 == 0) {
			cout << s[i];
		}
		if (s[i + 1] == '\0')break;
	}
	cout << endl;

	return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <climits>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <deque>
#define INF_INT (INT_MAX / 2)
#define INF_LONG (LONG_MAX / 2)
//#define DEBUG true
#define DEBUG false
using namespace std;

const int MAX = 100001;
const int MOD = 1000000007;

typedef long long ll;
typedef pair< int, int > pii;
typedef pair< ll, ll > pll;
typedef pair< ll, int > pli;
typedef pair< int, ll > pil;

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

  int n, h, w;
  cin >> n >> h >> w;
  int a[n], b[n];
  for(int i = 0; i < n; i++) cin >> a[i] >> b[i];

  int count = 0;
  for(int i = 0; i < n; i++){
    if(a[i] >= h && b[i] >= w) ++count;
  }

  cout << count << endl;

  return 0;
}


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

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

using namespace std;

typedef long long ll;

int main()
{
    int N, M;
    cin >> N >> M;
    vector<int> X(M, 0);
    REP(i, M) cin >> X[i];
    sort(X.begin(), X.end());
    vector<int> diff;
    REP(i, M - 1) diff.push_back(X[i + 1] - X[i]);
    sort(diff.begin(), diff.end());
    reverse(diff.begin(), diff.end());
    int ans = 0;
    if (N < M)
    {
        ans = X[M - 1] - X[0];
        REP(i, N - 1) ans -= diff[i];
    }

    cout << ans << endl;
}


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

int main() {
	int a, b;
	cin >> a >> b;
	if (a == b) {
		cout << a * 2 << endl;
	} else {
		cout << max(a, b) * 2 - 1 << endl;
	}
	return 0;
}

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

int main() {
	int K;
	int N;
	int n = 0;
	int a = 0;
	cin >> K >> N;
	while (a==0) {
		K = K - N+(N-1);
		n = n + 1;
		if (K == (N-1)) {
			break;
		}
	}
	cout << n << endl;
}


Measured memory_bytes: 256
#include<iostream>
#define rep(p) for(int i = 0; i < p; i++)
using namespace std;
int main() {
    int w,h;
    while(1) {
        cin >> w >> h;
        if(w == 0 && h == 0)break;
        rep(w) {
            rep(h) {
                cout << "#";
            }
            cout << endl;
        }
        cout << endl;
    }
    
    return 0;
}


Measured memory_bytes: 3096
/*

                   _ooOoo_
                  o8888888o
                  88" . "88
                  (| -_- |)
                  O\  =  /O
               ____/`---'\____
             .'  \\|     |//  `.
            /  \\|||  :  |||//  \
           /  _||||| -:- |||||-  \
           |   | \\\  -  /// |   |
           | \_|  ''\---/''  |   |
           \  .-\__  `-`  ___/-. /
         ___`. .'  /--.--\  `. . __
      ."" '<  `.___\_<|>_/___.'  >'"".
     | | :  `- \`.;`\ _ /`;.`/ - ` : | |
     \  \ `-.   \_ __\ /__ _/   .-` /  /
======`-.____`-.___\_____/___.-`____.-'======
                   `=---='
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
                    prayer
*/

// g++ -std=c++11 a.cpp
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<unordered_map>
#include<utility>
#include<cmath>
#include<random>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(long long i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
#define FOR(i,a) for(auto i:a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
#define show1d(v) {rep(_,v.size())cout<<" "<<v[_];cout<<endl;}
#define show2d(v) {rep(__,v.size())show1d(v[__]);}
using namespace std;
//kaewasuretyuui
typedef long long ll;
#define int ll
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
#define mt make_tuple
typedef tuple<int,int,int,int> tp;
typedef vector<tp> vt;
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;}
const double PI=acos(-1);
const double EPS=1e-9;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9+10;
#define yes cout<<"Yes\n"
#define no cout<<"No\n"

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

	int a,b,c;
	cin>>a>>b>>c;
	cout<<a+b+c-max({a,b,c})<<endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

class Main{
  public static void main(String[] args){
    Scanner scan=new Scanner(System.in);
    int mt=scan.nextInt();
    int road=scan.nextInt();
    int[] high=new int[mt];
    boolean[] good=new boolean[mt];
    for(int a=0; a<mt; a++){
      high[a]=scan.nextInt();
      good[a]=true;
    }
    for(int a=0; a<road; a++){
      int x=scan.nextInt();
      int y=scan.nextInt();
      if(high[x-1]>high[y-1] && good[y-1]==true){
        good[y-1]=false;
        //System.out.println(y);
      }else if(high[x-1]<high[y-1] && good[x-1]==true){
        good[x-1]=false;
        //System.out.println(x);
      }else if(high[x-1]==high[y-1]){
        good[x-1]=false;
        good[y-1]=false;
      }
    }
    int ans=0;
    for(int a=0; a<good.length; a++){
      if(good[a]==true){
        ans++;
      }
    }
    System.out.println(ans);
  }
}

Measured memory_bytes: 59488
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstdlib>
#include<string>

using namespace std;
int main(){
	int n , m[4] ;
	scanf("%d",&n);
	for(int i = 0;i <= 3 ;i++){
		m[i] = n%10 ;
		n = n/10 ;
		}
	if((m[0]==m[1]&&m[1]==m[2])||(m[1]==m[2]&&m[2]==m[3]))
		printf("Yes\n");
	else printf("No\n");
    return 0;
	}

Measured memory_bytes: 256
#include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<queue>
#include<deque>
#include<regex>
#include<stack>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
#include<iomanip>

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

typedef int long long ll;
using namespace std;
typedef pair<int, int> P;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
const ll MOD = 1e9 + 7;
static const int MAX = 100;
static const int INF = (1 << 23);

ll gcd(ll a,ll b){
    if(a==0||b==0)return max(a,b);
    if(b>a)swap(a,b);
    while(1){
        if(a%b!=0){
            ll tmp=b;b=a%b;
            a=tmp;
        }else{
            return b;
        }
    }
}

int main() {
    ll n,m;
    cin>>n>>m;
    string s,t;
    cin>>s>>t;
    ll ans = n*m/gcd(n,m);
    map<ll,ll> po;


    for(int i=1;i<=n;i++){
        int p = (i-1)*(ans/n)+1;
        po[p]=i;
    }

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

        int p = (i-1)*(ans/m)+1;

        if(po[p]!=0){
            int k = po[p]-1; 
            if(s[k]!=t[i-1] ){
                cout<<-1<<endl;
                return 0;
            }
        }
    }

    cout<<ans<<endl;







    return 0;
}


Measured memory_bytes: 10880
#include<bits/stdc++.h>
#define ll long long int
#define pb push_back
#define mod 1000000007
#define pi (3.141592653589)
#define deb(n) cerr << #n << " = " << (n) << " ";
using namespace std;

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cout << fixed;
	cout.precision(10);
	
	char c;
	cin >> c;
	if(islower(c))
	{
		cout << 'a';
	}
	else
	{
		cout << 'A';
	}

	return 0;
}


Measured memory_bytes: 3608
#include <cmath>
#include <cstdio>
#include <iostream>
#include <queue>
#include <vector>

#include <algorithm>
#include <functional>
#include <iterator>
#include <map>
#include <set>
#include <string>

using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = (n)-1; i >= 0; i--)
#define INF 1 << 29
#define ALEN(ARR) (sizeof(ARR) / sizeof((ARR)[0]))
#define MP make_pair
#define mp make_pair
#define pb push_back
#define PB push_back

#if DEBUG
#define _DEBUG(x) cout << #x << ": " << x << endl
#define _DDEBUG(x, y) cout << #x << ": " << x << ", " << #y << ": " << y << endl
#else
#define _DEBUG(x) ;
#define _DDEBUG(x, y) ;
#endif

#define ll long long
#define ull unsigned long long
#define MOD 1000000007

/** FOR VECTOR DEBUG */
template <typename T> ostream &operator<<(ostream &out, const vector<T> &v) {
  if (!v.empty()) {
    out << '[';
    copy(v.begin(), v.end(), ostream_iterator<T>(out, ", "));
    out << "\b\b]";
  }
  return out;
}

/* template end */

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

  int h, w;
  cin >> h >> w;

  string table[h];
  vector<int> wv(w);
  vector<int> hv(h);
  for (int i = 0; i < h; i++) {
    cin >> table[i];
    for (int j = 0; j < w; j++) {
      wv[j] += table[i][j] == '.' ? 1 : 0;
      hv[i] += table[i][j] == '.' ? 1 : 0;
    }
  }

  for (int i = 0; i < h; i++) {
    string s = "";
    for (int j = 0; j < w; j++) {
      if (hv[i] != w && wv[j] != h) {
        s += table[i][j];
      }
    }
    if (!s.empty()) {
      cout << s << endl;
    }
  }

  return 0;
}


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

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<int, pii> piii;
typedef vector<int> vi;
typedef vector<ll> vll;

#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define sz(a) ((int)(a).size())
#define rep(i,a,b) for(int i=(a); i<(b); i++)
#define trav(it, a) for(auto& it : a)
#define allin(it, a) for(auto it : a)
#define read(v, a, b) for(int i=(a); i<(b); i++) scanf("%d", &v[i]);
#define clr(a,v) memset(a, v, sizeof(a))
#define all(a) (a).begin(),(a).end()
#define FAST cin.tie(0), cout.tie(0), ios::sync_with_stdio(0)
#define db(x) cerr << #x << " == " << x << endl

const int maxn = 110, maxv = 1e5 + 100, inf = 0x3f3f3f3f;

int n, W, w[maxn], v[maxn], dp[maxn][maxv];

int solve(int i, int value){ //we want the minimal weight using items up to i and with that value
	if(i==n && value) return inf;
	if(i==n) return 0;
	if(dp[i][value] != -1) return dp[i][value];
	
	int add = v[i] <= value? solve(i+1, value - v[i]) + w[i] : inf;
	int not_add = solve(i+1, value);
	int ans = min(add, not_add);
	if(ans > W) ans = inf;
	return dp[i][value] = ans;
}

int main(){
	scanf("%d %d", &n, &W);
	
	rep(i,0,n)
		scanf("%d %d", &w[i], &v[i]);
		
	clr(dp, -1);
	
	for(int i = maxv - 100; i >= 0; i--)
		if(solve(0, i) < inf){
			printf("%d\n", i);
			return 0;
		}
	
}


Measured memory_bytes: 43264
#include<bits/stdc++.h>
#define FastIO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

using namespace std;
int main()
{
	FastIO;
	int n,c;
	cin>>n>>c;
	if(n>12)cout<<c;
	else if(n>=6&&n<=12)cout<<c/2;
	else cout<<0;
}

Measured memory_bytes: 256
def proc(n):
    new = []
    n = str(n)
    for i in range(1, len(n)):
        new.append(int(n[:i]) * int(n[i:]))
    return max(new)

for _ in range(int(input())):
    ans = 0
    n = int(input())
    while(n > 9):
        n = proc(n)
        ans += 1
    print(ans)


Measured memory_bytes: 5604
from sys import exit, setrecursionlimit, stderr, stdin
from functools import reduce
from itertools import *
from collections import defaultdict, Counter
from bisect import bisect
import functools

setrecursionlimit(10**7)

def input():
  return stdin.readline().strip()

def read():
  return int(input())

def reads():
  return [int(x) for x in input().split()]

MOD = 10**6 + 3

fact = [1] * MOD
for i in range(1, MOD):
  fact[i] = (fact[i-1] * i) % MOD
invfact = [0] * MOD; invfact[-1] = pow(fact[-1], MOD-2, MOD)
for i in range(MOD-2, -1, -1):
  invfact[i] = invfact[i+1] * (i+1) % MOD
# print(invfact[:10])

def inv(n):
  return pow(n, MOD-2, MOD)

def solve(x, d, n):
  if x == 0:
    return 0
  if d == 0:
    return pow(x, n, MOD)
  k = x * inv(d) % MOD
  if n + k - 1 >= MOD:
    return 0
  return fact[n + k - 1] * invfact[k-1] % MOD * pow(d, n, MOD) % MOD

Q = read()
for _ in range(Q):
  x, d, n = reads()
  ans = solve(x, d, n)
  print(ans)

Measured memory_bytes: 69852
#include<bits/stdc++.h>
#define pb push_back
#define fr first
#define sc second
#define all(x) x.begin(), x.end()
#define skip continue
#define NAME "code"
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
 
void faster(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}
 
const ll INF = 1e9;
const ll MOD = 1e9 + 7;
const ll MAXN = 3e5 + 123;
const ld EPS = 1e-12;
const int dx[4] = {-1, 0, 0, 1};
const int dy[4] = {0, -1, 1, 0};

int n, x, a[MAXN], u[MAXN];

void solve(){
	cin >> n >> x;

	if(x == 1 || x == n * 2 - 1){
		cout << "No\n";
		return;
	}

	cout << "Yes\n";
	
	for(int i = 1; i < n * 2; ++i)
		a[i] = i;
	
	
	if(x < n){
		swap(a[n], a[x]);
		swap(a[n - 1], a[x - 1]);
		sort(a + 1, a + n - 1);
	}
	else{
		swap(a[n], a[x]);
		swap(a[n + 1], a[x + 1]);
		sort(a + n + 2, a + n * 2);
	}

	for(int i = 1; i <= n * 2 - 1; ++i){
		cout << a[i] << ' ';
	}
}

int main(){

	faster();
 
	int T = 1;
	// cin >> T;
	
	while(T--){
		solve();
	}
 
	return 0;
}

Measured memory_bytes: 2304
#include<bits/stdc++.h>
using namespace std;
#define f(i,n) for(int i = 0;i<n;i++)
#define ll long long
char solve(char c1,char c2){
	if(c1=='R'&&c2=='G') return 'B';
	if(c1=='G'&&c2=='R') return 'B';

	if(c1=='B'&&c2=='G') return 'R';
	if(c1=='G'&&c2=='B') return 'R';

	if(c1=='R'&&c2=='B') return 'G';
	if(c1=='B'&&c2=='R') return 'G';

	return ' ';
}
struct color{
	int r=0;
	int g=0;
	int b=0;

};
typedef struct color color;
int main(){

	ll n;
	cin>>n;

	string s;
	cin>>s;

	int size = s.length();
	vector<color>v(size);
	ll totalR=0,totalG=0,totalB=0;
	//initialize
	if(s[0]=='R') {v[0].r = 1;totalR++;}
	if(s[0]=='G') {v[0].g = 1;totalG++;}
	if(s[0]=='B') {v[0].b = 1;totalB++;}

	for(int i = 1;i<n;i++){
		v[i].r = v[i-1].r;
		v[i].g = v[i-1].g;
		v[i].b = v[i-1].b;
		if(s[i]=='R'){
			totalR++;
			v[i].r = v[i-1].r + 1;
		}
		if(s[i]=='G'){
			totalG++;
			v[i].g = v[i-1].g + 1;
		}	
		if(s[i]=='B'){
			totalB++;
			v[i].b = v[i-1].b + 1;
		}
	}
	// cout<<"HERE";
	// f(i,s.length()){
	// 	cout<<i<<" "<<v[i].r<<" "<<v[i].g<<" "<<v[i].b<<endl;	
	// }
	// cout<<"BEGIN"<<endl;
	// cout<<"totals "<<totalR<<" "<<totalB<<" "<<totalG<<endl;
	f(i,s.length()){
		v[i].r = totalR-v[i].r;
		v[i].g = totalG-v[i].g;
		v[i].b = totalB-v[i].b;
		// cout<<i<<" "<<v[i].r<<" "<<v[i].g<<" "<<v[i].b<<endl;
	}
	// cout<<"HERE1";
	ll count = 0;
	for(int i = 0;i<n;i++){
		for(int j = i+1;j<(n-1);j++){
			char ch = solve(s[i],s[j]);
			// cout<<i<<" "<<j<<" "<<ch<<" ";
			// cout<<endl;
			int key = 2*j-i;
			if(ch=='R'){
				count = count+v[j].r;
				if(key<n)
				if(s[2*(j)-(i)]=='R') count--;
			}
			if(ch=='G'){
				// cout<<"J "<<j<<v[j].g<<endl;
				count = count+v[j].g;
				if(key<n)
				if(s[2*j-i]=='G') count--;
			}
			if(ch=='B'){
				count = count+v[j].b;
				if(key<n)
				if(s[2*j-i]=='B') count--;
			}
			// cout<<count<<endl;
		}
	}

	cout<<count;
	

}

Measured memory_bytes: 3652
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
template<typename T> bool chmax(T &a,T b){if(a<b){a=b;return true;}return false;}
template<typename T> bool chmin(T &a,T b){if(a>b){a=b;return true;}return false;}
#define itn int
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define rrep1(i,n) for(int i=(int)(n);i>=1;i--)
#define all(vec) vec.begin(),vec.end()
#define sortt(vec) sort((vec).begin(),(vec).end())
#define rsort(vec) sort((vec).rbegin(), (vec).rend()-1)
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
typedef tuple<ll,ll,ll> tlll;
typedef tuple<int,int,int> tiii;
const ll mod=1e9+7;
const int inf=2e9;
const ll lnf=9e18;

int main(){
  int n; ll W; cin >> n >> W;
  vector<ll> w(n);
  vector<ll> v0={0};
  vector<ll> v1={0};
  vector<ll> v2={0};
  vector<ll> v3={0};
  vector<ll> v(n);
  rep(i,n){
    cin >> w[i] >> v[i];
    if(w[i]==w[0]) v0.push_back(v[i]);
    if(w[i]==w[0]+1) v1.push_back(v[i]);
    if(w[i]==w[0]+2) v2.push_back(v[i]);
    if(w[i]==w[0]+3) v3.push_back(v[i]);
  }
  rsort(v0);
  rsort(v1);
  rsort(v2);
  rsort(v3);
  rep(i,v0.size()-1) v0[i+1]+=v0[i];
  rep(i,v1.size()-1) v1[i+1]+=v1[i];
  rep(i,v2.size()-1) v2[i+1]+=v2[i];
  rep(i,v3.size()-1) v3[i+1]+=v3[i];
  ll ans=0;
  rep(i,v0.size())rep(j,v1.size())rep(k,v2.size())rep(l,v3.size()){
    if(w[0]*i+(w[0]+1)*j+(w[0]+2)*k+(w[0]+3)*l<=W) chmax(ans,v0[i]+v1[j]+v2[k]+v3[l]);
  }
  cout << ans << endl;
}


Measured memory_bytes: 3720
#include <iostream>
#include <stdio.h>
#include <math.h>
#include <time.h>
#include <algorithm>
#include <cmath>
#include <vector>
#include <regex> //正規表現
#include <map>
#include <set>
#include <cassert> //assart
#include <numeric>
#include <iterator>
#include <list>

using namespace std;
#define ll long long int
#define FOR(i,min,max) for(int i=(min);i<(max);i++)
#define FOReq(i,min,max) for(int i=(min);i<=(max);i++)
#define FORREV(i,max,min) for(int i=(max)-1;i>=(min);i--)
#define FORREVeq(i,max,min) for(int i=(max);i>=(min);i--)
const int  MOD=1e9+7;
const int  INF=2000000000;
const int INF2=  10000000;
const double  Micro=1e-5;

int UnUsedVariable(){
    if(INF || Micro || MOD || INF2){;}
    return 0;
}

#define pf printf
#define sf scanf
#define inarray(array,min,max) FOR(i,min,max){cin>>array[i];}
#define inarrayW(arrayA,arrayB,min,max) FOR(i,min,max){cin>>arrayA[i]>>arrayB[i];}
#define br printf("\n");
#define OutputAndReturn0(x) {cout<<(x)<<endl;return 0;}

#define issame(a,b,c,d) ((a)==(b) and (b)==(c) and (c)==(d))
#define isdiff3(a,b,c) ((a)!=(b) and (b)!=(c) and (c)!=(a))
#define isdiff4(a,b,c,d) ((a)!=(b) and (b)!=(c) and (c)!=(a) and (d)!=(a) and (d)!=(b) and (d)!=(c))
inline int isEven(int x){return x%2==0;}
inline int isOdd (int x){return x%2==1;}
inline ll  gcd(ll a,ll b){ if(b==0)return a;else return gcd(b,a%b);}//最大公約数 なお一方が0なら答えは他方になるので番兵は０で良い また、負の数もOK -4%3=-1となるため
inline ll  lcm(ll a,ll b){return a*b/gcd(a,b);}//MODやオーバーフローには注意！



//Eと名のつくのはデバッグ用！
int EintN(int array[],const int num){
    for(int i=0;i<num;i++){cerr<<array[i]<<" ";}
    br;
    return 0;
}
int EintNN(const int heighth,const int width,int array[heighth][width]){
    FOR(i, 0, heighth){
        FOR(k, 0, width){
            {cerr<<array[i][k]<<" ";}
        }
        br;
    }
    br;
    return 0;
}
int Eint(string str,const int num){
    cerr<<str<<" is "<<num<<" now."<<endl;
    return 0;
}


int AllElementChange0(int array[],const int num){
    for(int i=0;i<num;i++){array[i]=0;}
    return 0;
}


int test(){
    return 0;
}

int Ap(){
    int ans;ans=0;
    int a;
    cin>>a;
    
    OutputAndReturn0(a*a*3);
    return 0;
}

int Bp(){
    int ans;ans=0;
    int N,D;
    cin>>N>>D;
    OutputAndReturn0((N+2*D)/(2*D+1));
    return 0;
}

int Cp(){
    int ans;ans=0;
    OutputAndReturn0(ans);
    return 0;
}

int Dp(){
    int ans;ans=0;
    OutputAndReturn0(ans);
    return 0;
}

signed main(){
    //test();
    //Ap();
    Bp();
    //Cp();
    //Dp();
    return 0;
}


Measured memory_bytes: 888
N = int(input())
list = list(map(int,input().split()))
josu = 0

#脳筋
for i in range(len(list)):
    josu += 1/list[i]

ans = 1/josu


#ちょい工夫？
# all_jousu = 1
# for i in range(len(list)):
#     all_jousu *= list[i]
#
# josu = 0
# for i in range(len(list)):
#     josu += all_jousu/list[i]
#
# ans = all_jousu/josu



print(ans)

Measured memory_bytes: 2940
n, k = map(int,input().split())
s = input()

if s[k-1] == 'A':
    x = s[:k-1] + 'a' + s[k:]
elif s[k-1] == 'B':
    x = s[:k-1] + 'b' + s[k:]
else:
    x = s[:k - 1] + 'c' + s[k:]

print(x)

Measured memory_bytes: 2940
S = input()

T = ""
items = ["dream", "dreamer", "erase", "eraser"]
candidates = [""]

for i in range(int(len(S)/5) + 1):
  new_candidates = []
  for candidate in candidates:
    for item in items:
      tmp = candidate + item
      # print(tmp)
      if len(tmp) > len(S):
        continue
      elif S == tmp:
        print("YES")
        exit()
      elif S[:len(tmp)] == tmp:
        new_candidates.append(tmp)
  candidates = new_candidates
  # print(candidates)
  if candidates == []:
    print("NO")
    exit()

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

int main(){
	int n,m,q;
	cin >> n >> m >> q;
	vector<vector<int>> mp(n+1, vector<int>(n+1));
	int l,r;
	rep(i,m){
		cin >> l >> r;
		mp[l][r]++;
	}
	vector<vector<int>> cum(n+1, vector<int>(n+1));
	rep(i,n){
		rep(j,n){
			cum[i+1][j+1] = cum[i+1][j] + mp[i+1][j+1];
		}
	}
	rep(i,q){
		int ans(0);
		cin >> l >> r;
		for(int j(l);j<=r;++j){
			ans += cum[j][r] - cum[j][l-1];
		}
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 2944
#include <stdio.h>
#include <stdlib.h>


#define	ll_int	long long int
#define	SIZE	1000000


// 指定した位置へ値を入れる
void Push(ll_int *box, int pos, int x)
{
	box[pos] = x;
}


// 指定された位置の値を表示
void Random_access(ll_int *box, int pos)
{
	printf("%lld\n", box[pos]);
}


int main(void){
	ll_int *box;		// 固定長配列(十分に確保)
	char in_str[20];	// 入力文字のための文字配列
	int q;			// クエリ数
	int command, d, x;
	int rear, front;
	int i;

	box = (ll_int *)malloc(sizeof(ll_int) * SIZE);
	front = SIZE / 2;
	rear  = SIZE / 2 - 1;

	fgets(in_str, sizeof(in_str), stdin);
	sscanf(in_str, "%d", &q);

	for(i = 0; i < q; i++){
		fgets(in_str, sizeof(in_str), stdin);
		sscanf(in_str, "%d %d %d", &command, &d, &x);

		if(command == 0){
		// push
			if(d)
			// 末尾
				Push(box, ++rear, x);
			else
			// 先頭
				Push(box, --front, x);
		}else if(command == 1){
		// random_access
			Random_access(box, front + d);
		}else{
		// pop
			if(d)
			// 末尾
				rear--;
			else
			// 先頭
				front++;
		}
	}
}


Measured memory_bytes: 4836
#include <bits/stdc++.h>
#define fi first
#define se second
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define enter putchar('\n')
#define space putchar(' ')
#define MAXN 100005
#define eps 1e-8
//#define ivorysi
using namespace std;
typedef long long int64;
typedef double db;
template<class T>
void read(T &res) {
    res = 0;char c = getchar();T f = 1;
    while(c < '0' || c > '9') {
	if(c == '-') f = -1;
	c = getchar();
    }
    while(c >= '0' && c <= '9') {
	res = res * 10 + c - '0';
	c = getchar();
    }
    res *= f;
}
template<class T>
void out(T x) {
    if(x < 0) {x = -x;putchar('-');}
    if(x >= 10) {
	out(x / 10);
    }
    putchar('0' + x % 10);
}
int N,M,A,B,S,T;
char ans[1005][1005];
int main() {
#ifdef ivorysi
    freopen("f1.in","r",stdin);
#endif
    read(N);read(M);read(A);read(B);
    S = N;T = M;
    if(N * M < (A + B) * 2) {
	puts("NO");
	return 0;
    }
    for(int i = 1 ; i <= N ; ++i) {
	for(int j = 1 ; j <= M ; ++j) {
	    ans[i][j] = '.';
	}
    }
    if(M & 1) {
	int t = 1;
	while(B) {
	    if(t + 1 > N) break;
	    ans[t][M] = '^';
	    ans[t + 1][M] = 'v';
	    t += 2;
	    --B;
	}
	--M;	
    }
    if(N & 1) {
	int t = T;
	while(A) {
	    if(t - 1 < 1) break;
	    ans[N][t] = '>';
	    ans[N][t - 1] = '<';
	    t -= 2;
	    --A;
	}
	--N;
    }
    int rem = N * M;
    for(int i = 1 ; i <= N ; i += 2) {
	for(int j = M - 1 ; j >= 1 ; j -= 2) {
	    if(A >= 2) {
		A -= 2;
		rem -= 4;
		ans[i][j] = '<';
		ans[i][j + 1] = '>';
		ans[i + 1][j] = '<';
		ans[i + 1][j + 1] = '>';
	    }
	    else if(B >= 2) {
		B -= 2;
		rem -= 4;
		ans[i][j] = '^';
		ans[i + 1][j] = 'v';
		ans[i][j + 1] = '^';
		ans[i + 1][j + 1] = 'v';
	    }
	}
    }
    if(!A || !B || rem >= 8) {
	for(int i = 1 ; i <= N ; i += 2) {
	    for(int j = M - 1 ; j >= 1 ; j -= 2) {
		if(ans[i][j] != '.') continue;
		if(A) {
		    --A;
		    ans[i][j] = '<';
		    ans[i][j + 1] = '>';
		}
		else if(B) {
		    --B;
		    ans[i][j] = '^';
		    ans[i + 1][j] = 'v';
		}
	    }
	}
    }
    else if(rem >= 4){
	if(A == 1 && B == 1 && (S & 1) && (T & 1)) {
	    --A;--B;
	    ans[N - 1][1] = '<';ans[N - 1][2] = '>';
	    ans[N][1] = '^';ans[N + 1][1] = 'v';
	} 
    }
    if(A || B) {puts("NO");return 0;}
    puts("YES");
    for(int i = 1 ; i <= S ; ++i) {
	for(int j = 1 ; j <= T ; ++j) {
	    putchar(ans[i][j]);
	}
	enter;
    }
    return 0;
}


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

int main() {
  int N;
  cin >> N;

  double m[N];
  string kind_m[N];
  for(int i=0; i<N ; i++){
    cin >> m[i] >> kind_m[i];
  }
  
  double sum=0;
  for(int i=0; i<N ; i++){
    if(kind_m[i]=="JPY"){
      sum += m[i];
    }
    if(kind_m[i]=="BTC"){
      sum += m[i]*380000.0;
    }
  }
    cout << sum << endl;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll          long long
#define mp	    make_pair
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define x           first
#define y           second
#define sz(x)       (int)x.size()
#define endl        '\n'
#define MOD        1000000007
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define gcd(a,b)    __gcd((a),(b))
#define lcm(a,b)    ((a)*(b)) / gcd((a),(b))
#define rep(i,a,b)  for(int i=a;i<b;i++)
#define N	 100
void solve(){
	int n;
	cin>>n;
	cout<<n/3<<endl;
}
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t;
    t =1;
//     cin>>t;
    while(t--){
        solve();
    }
    return 0;
}



Measured memory_bytes: 256
str_list = input().split(' ')
A, B, K = [int(x) for x in str_list]
takahashi = max(A-K, 0)
if takahashi==A-K:
    aoki=B
else:
    aoki = max(B-(K-A), 0)
print('%d %d' % (takahashi, aoki))


Measured memory_bytes: 2940
#include <bits/stdc++.h>
#define ll long long
#define pp push_back
#define fr first
#define sc second
#define mp make_pair
using namespace std;


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


    int x , y;
    cin >> x >> y;
    if(y >= x * 2 && y <= x * 4
       && y % 2 == 0){
        cout << "Yes\n";
    }
    else{
        cout << "No\n";
    }

    return 0;
}


Measured memory_bytes: 3648
#include <utility>
#include <vector>
#include <iostream>
#include <algorithm>
#include <functional>
#include <map>
#include <set>
#include <list>
#include <string>
#define REP(i, n) for (int i = 0; i < n; i++)
using namespace std;

typedef long long ll;
typedef pair<ll, ll> Pll;

int main()
{
    int N, K;
    cin >> N >> K;
    ll V[N];
    REP(i, N)
    {
        ll v;
        cin >> v;
        V[i] = v;
    }

    int max = 0;
    for (int i = -1; i < N; i++)
    {
        for (int j = -1; j < N; j++)
        {
            if (i >= N - j - 1 || i + j + 2 > K)
                break;

            vector<ll> vec;
            for (int t = 0; t <= i; t++)
                vec.push_back(V[t]);
            for (int t = 0; t <= j; t++)
                vec.push_back(V[N - 1 - t]);

            sort(vec.begin(), vec.end());

            int sum = 0;
            for (int t = 0; t < vec.size(); t++)
            {
                if (K - i - j - 2 > t && vec[t] < 0)
                    continue;
                sum += vec[t];
            }
            if (sum > max)
                max = sum;
        }
    }

    cout << max << endl;
}

void cheatsheet()
{
    // loop
    // vector<int> vec(10);
    vector<int> vecloop;
    REP(i, 10)
    {
        vecloop.push_back(i);
    }

    // swap
    int a = 1;
    int b = 5;
    swap(a, b); // -> a = 5, b = 1

    // sort
    int arr[] = {1, 2, 3, 4, 5, 6, 7, 8, 9};
    sort(arr, arr + 9, greater<int>()); // 9 8 7 6 5 4 3 2 1

    // lower
    vector<int> vec(arr, end(arr));
    sort(vec.begin(), vec.end());
    cout << lower_bound(vec.begin(), vec.end(), 2)[0]; // 2

    // map
    map<Pll, ll> m;
    m[Pll(10, 100)] = 100;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<unordered_map>
#include<bitset>
#include<iomanip>
#include<list>
#include<deque>
using namespace std;
//#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define DEB2(X) cout<<X<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define DEB2(X) {}
#define END {}
#endif
typedef long long ll;
#define int ll
#define uset unordered_set
#define umap unordered_map
//typedef std::pair<int,int> P;
struct edge{int to,cost;};
const int INF=100000000000000000;
const int INF2=9223372036854775807;
const int MOD=1000000007;
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define min(X,Y) (((int)(X)<(int)(Y))?(X):(Y))
#define max(X,Y) (((int)(X)>(int)(Y))?(X):(Y))
#define NP(X,Y) next_permutation(X,Y)
#define setdouble(X,Y) cout<<fixed<<setprecision(X)<<Y
int ceil2(int a,int b){if(a%b==0){return a/b;}else{return a/b+1;}}
int pow2(int a,int b){int r=1;for(int i=1;i<=b;i++){r*=a;}return r;}
int Log2(int a){int t=0;while(1){if(a==0||a==1){break;}a/=2;t++;}return t;}

int N,M;
int H[100010];
int A[100010],B[100010];
int num[100010];
int E[100010];

signed main(){
	cin>>N>>M;
	REP(i,N){
		cin>>H[i];
	}
	REP(i,M){
		cin>>A[i]>>B[i];
		A[i]--,B[i]--;
		E[A[i]]++,E[B[i]]++;
		if(H[A[i]]>H[B[i]]){
			num[A[i]]++;
		}
		if(H[A[i]]<H[B[i]]){
			num[B[i]]++;
		}
	}
	int ans=0;
	REP(i,N){
		if(E[i]==num[i]){
			ans++;
		}
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 7540
use std::io::{self, Read};
use std::str::FromStr;

pub struct Scanner<R: Read> {
    reader: R,
}
impl<R: Read> Scanner<R> {
    pub fn new(reader: R) -> Scanner<R> {
        Scanner { reader: reader }
    }
    pub fn read<T: FromStr>(&mut self) -> T {
        let s = self
            .reader
            .by_ref()
            .bytes()
            .map(|c| c.expect("failed to read char") as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>();
        s.parse::<T>().ok().expect("failed to parse token")
    }
}

use std::collections::BinaryHeap;

/// 標準ライブラリを用いた実装の場合
fn use_lib() {
    let sin = io::stdin();
    let sin = sin.lock();
    let mut sc = Scanner::new(sin);

    let mut pq = BinaryHeap::new();

    loop {
        let cmd: String = sc.read();

        match cmd.as_str() {
            "insert" => {
                let val: i64 = sc.read();
                pq.push(val);
            },
            "extract" => {
                if let Some(m) = pq.pop() {
                    println!("{}", m);
                }
            },
            "end" => {
                break;
            },
            _ => {
                unreachable!();
            }
        }
    }
}

fn main() {
    // call_self_dev();
    use_lib();
}



Measured memory_bytes: 14060
import numpy as np

N = int(input())
T, A = map(int, input().split())
H = list(map(int, input().split()))

H = np.array(H)
H_t = abs(T - H * 0.006 - A)
H_min_ind = [n for n, v in enumerate(H_t) if v == min(H_t)]

print(H_min_ind[0]+1)

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

using namespace std;


const int six_dx[]={1,1,0,-1,-1,0};
const int six_dy[]={1,0,-1,-1,0,1};

int main()
{
    int n,k,m;
    while(cin>>n>>k>>m,n){
    
        vector<int> stone;
        for(int i=1;i<=n;i++) stone.push_back(i);
    
        int pos=m-1;
        for(int i=1;i<n;i++){
            vector<int> stone2;
            for(int j=0;j<stone.size();j++){
                if(j!=pos) stone2.push_back(stone[j]);
            }
            pos=pos+k-1;
            pos%=(n-i);
            stone=stone2;
        }
    
        cout<<stone[0]<<endl;
    }
}

Measured memory_bytes: 1356
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define mod 1000000007ll
#define vll vector<ll>
#define pll pair<ll,ll>
#define vpll vector<pll>
#define pb push_back
#define mp make_pair
#define x first
#define y second
#define db(x) cout << #x << " = " << x << '\n'
#define sep cout << "********************************************\n"
#define fast ios_base::sync_with_stdio(false), cin.tie(NULL)
ll n, k, a[200005];
void solve(vll cyc, ll left)
{
	if (left == 0)
	{
		cout << cyc[0];
		exit(0);
	}
	ll sz = cyc.size();
	left %= sz;
	cout << cyc[left];
	exit(0);
}
int main(int argc, char const *argv[])
{
	fast;
	cin >> n >> k;
	for (int i = 1; i <= n; ++i)
	{
		cin >> a[i];
	}
	if (a[1] == 1)
		return cout << 1, 0;
	vll path;
	map<ll, ll> mapp;
	mapp[1] = 0;
	path.pb(1);
	ll c = 1, mno = 1;
	while (k > 0)
	{
		ll nxt = a[c];
		if (mapp.count(nxt))
		{
			ll st = mapp[nxt];
			vll temp;
			for (int i = st; i < mno; ++i)
			{
				temp.pb(path[i]);
			}
			solve(temp, k - 1);
		} 
		else
		{
			path.pb(nxt);
			mapp[nxt] = mno;
			mno ++;
		}
		k --;
		c = nxt;
	}
	cout << c;
	return 0;
}

Measured memory_bytes: 19068
#include <bits/stdc++.h>
using namespace std;
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
#define ll long long
#define debug(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " = " << a << endl;
	err(++it, args...);
}

ll mod = 1e9+7;

int main(){
    fastio
    ll n,pv,v;
    ll res = 0;
    cin >> n;
    pv = 0;
    for(int i=0;i<n;i++) {
        cin >> v;
        if(v<pv) {
            res += pv-v;
            v = pv;
        }
        pv = v;
    }
    cout << res;
}


Measured memory_bytes: 3648
//============================================================================
// My word     : hakuna matata
// My wisdom   : وتحسب انك جرم صغير وفيك انطوى العالم الأكبر
//============================================================================
#include <bits/stdc++.h>
using namespace std;
void file()
{

    freopen("divisors.in", "r", stdin);
    //  freopen("out.txt", "w", stdout);

}
#define Star ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define endl '\n'
#define mem(x,y)    memset(x,y,sizeof(x))
typedef long long ll;
const int maxsize=2e5+5,oo=0X3f3f3f3f;
ll n,ans,tot,arr[maxsize];
char c;





int main()
{
    Star;
    cin>>c;
    c+=1;
    cout<<c<<endl;
    
    














    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
int a,b;
cin >> a >> b;
int coun = 1,ans = a;
while(ans < b){
    ans = ans + a-1;
    coun++;
}
if( b==1)
    coun = 0;
cout << coun << endl;

return 0;
}


Measured memory_bytes: 256
import java.util.*;
import java.math.BigInteger;
// warm-up
public class Main {

	static void solve() {
		Scanner sc = new Scanner(System.in);
		BigInteger N = sc.nextBigInteger(), M = sc.nextBigInteger();
		if (N.equals(BigInteger.ONE) && M.equals(BigInteger.ONE)) System.out.println(1);
		else if (N.equals(BigInteger.ONE) && !M.equals(BigInteger.ONE)) System.out.println(M.subtract(new BigInteger("2")));
		else {
			if (M.equals(BigInteger.ONE)) 
			System.out.println(BigInteger.ZERO.subtract(
				N.subtract(new BigInteger("2")).multiply(
					M.subtract(new BigInteger("2")))));			
			else System.out.println(N.subtract(new BigInteger("2")).multiply(M.subtract(new BigInteger("2"))));			
		}
		sc.close();		
	}

	public static void main(String args[]) {
		solve();
	}

}

Measured memory_bytes: 36040
#include<iostream>
#include<algorithm>
#define ll long long
using namespace std;
int main()
{
	ll a[100005],aa,bb,ca,cb;
	int n;
	while(cin>>n)
	{
		ca=-1;
		cb=-1;
		for(int i=0;i<n;i++)
		{
			cin>>a[i];
		}
		sort(a,a+n);
		for(int i=n-2;i>=0;i--)
		{
			if(a[i]==a[i+1]&&ca==-1)
			{
				ca=a[i];
				i--;
			}
			else if(a[i]==a[i+1]&&cb==-1)
			{
				cb=a[i+1];
				break;
			}
		} 
		if(cb==-1)
		{
			cout<<0<<endl;
		}
		else
		{
			cout<<ca*cb<<endl;
		}
	}
	return 0;
}

Measured memory_bytes: 1024
# 131 D - Megalomania
N = int(input())
AB = [list(map( int,input().split() )) for i in range(N)]

from operator import itemgetter
AB = sorted(AB, key=itemgetter(1))

rt = 'Yes'
val = 0
for i in range(N):
    val += AB[i][0]
    if val > AB[i][1] :
        rt = 'No'
        break
print(rt)


Measured memory_bytes: 55256