akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#include<string.h>
  
int LCS(char *X, char *Y){
  int i,j,m,n,c[1001][1001];
  m = strlen(X);
  n = strlen(Y);
    
  for(i=0; i<m; i++){
    c[i][0] = 0;
  }
  for(j=0; j<n; j++){
    c[0][j] = 0;
  }
  
  for(i=1;i<m+1;i++){
    for(j=1;j<n+1;j++){
      if (X[i-1]==Y[j-1]) c[i][j]=c[i-1][j-1]+1;
      else if (c[i-1][j]>=c[i][j-1]) c[i][j]=c[i-1][j];
      else c[i][j]=c[i][j-1];
    }
  }
  return c[i-1][j-1];
}
  
int main(){
  int i, q;
  char X[1001], Y[1001];
    
  scanf("%d", &q);
  for(i=0; i<q; i++){
    scanf("%s", X);
    scanf("%s", Y);
    printf("%d\n", LCS(X, Y));
  
  }
  return 0;
}

Measured memory_bytes: 4524
A = int(input())
B = int(input())
C = int(input())
X = int(input())
count = 0

for x in range(0, A+1):
  for y in range(0, B+1):
    for z in range(0, C+1):
      if x*500 + y*100 + z*50 == X:
        count +=1
      
print(count)

Measured memory_bytes: 3060
#include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<queue>
#include<stack>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
#include<iomanip>
#define rep(i,n) for(int long long i=0;i<n;i++)
typedef int long long ll;
using namespace std;
int main(){
    ll n;
    cin>>n;
    vector<ll> a(n),b(n),c(n);
    rep(i,n){
        cin>>a[i];
    }
    rep(i,n){
        cin>>b[i];
    }
    rep(i,n){
        cin>>c[i];
    }
    
    sort(a.begin(),a.end());
    sort(b.begin(),b.end());
    sort(c.begin(),c.end());
    vector<ll> bb(n+1),cc(n+1);
    bb[0]=0;
    
    rep(i,b.size()){
        ll cb=upper_bound(c.begin(),c.end(),b[i])-c.begin();
        cb=n-cb;
        bb[i+1]=bb[i]+cb;
        //bb[i]+=1;
    }
   
    ll ans=0;
  
rep(i,b.size()){
    auto bj=upper_bound(b.begin(),b.end(),a[i])-b.begin();
    //cout<<bb<<endl;
    ans+=bb[n]-bb[bj];
   // cout<<bb[i+1]<<endl;
}
    cout<<ans<<endl;
    return 0;
}

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

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

  int N;
  cin >> N;
  vector<int> T(N);
  int sum_time = 0;
  for (int i = 0; i < N; ++i) {
    cin >> T.at(i);
    sum_time += T.at(i);
  }
  int M;
  cin >> M;
  vector<int> P(M), X(M);
  for (int i = 0; i < M; ++i) cin >> P.at(i) >> X.at(i);

  for (int i = 0; i < M; ++i) {
    cout << sum_time - T.at(P.at(i) - 1) + X.at(i) <<endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
//#pragma comment(linker, "/stack:200000000")
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#define int long long
#define y1 zzz
#define fi first
#define se second
#define PII pair<int,int>
#define PII2 pair<int,PII >
#define PII3 pair<PII,int >
#define PII4 pair<PII,PII >
#define all(x) (x).begin(),(x).end()
#define pb push_back
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int n,m,k,a[200010],b[200010],ans,x1=1e9,x2=1e9;
void solve()
{
    cin>>n>>m>>k;
    for(int i=1;i<=n;i++)
    {
        cin>>a[i];
        x1=min(x1,a[i]);
    }
    for(int i=1;i<=m;i++)
    {
        cin>>b[i];
        x2=min(x2,b[i]);
    }
    ans=x1+x2;
    for(int i=1;i<=k;i++)
    {
        int x,y,c;
        cin>>x>>y>>c;
        ans=min(ans,a[x]+b[y]-c);
    }
    cout<<ans;
}
int32_t main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    //freopen("STRWC.inp","r",stdin);
    //freopen("STRWC.out","w",stdout);
    //int t;cin>>t;while(t--)
    solve();
    return 0;
}


Measured memory_bytes: 1024
import os
import sys

import numpy as np

if os.getenv('LOCAL'):
    sys.stdin = open('_in.txt', 'r')

sys.setrecursionlimit(2147483647)
INF = float('inf')


def bisect_right_callable(fn, x, lo, hi):
    """
    lo から hi-1 のうち、fn の結果が x 以下となる、最も右の値 + 1
    bisect.bisect_right と同じ
    https://docs.python.org/ja/3/library/bisect.html
    :param callable fn:
    :param x:
    :param int lo: 最小値
    :param int hi: 最大値 + 1
    :return: lo <= ret <= hi
    """
    while lo < hi:
        mid = (lo + hi) // 2
        if x < fn(mid):
            hi = mid
        else:
            lo = mid + 1
    return lo


N, X = list(map(int, sys.stdin.readline().split()))
B, L, U = list(zip(*[map(int, sys.stdin.readline().split()) for _ in range(N)]))

B = np.array(B, dtype=int)
L = np.array(L, dtype=int)
U = np.array(U, dtype=int)

# 全部 L で B 点とると仮定する
target = (B * L).sum()

# こうすれば target と比較できる
scores = B * L + (X - B) * U
scores_i = scores.argsort()

scores = scores[scores_i]
scores_cumsum = np.concatenate((scores[::-1].cumsum()[::-1], [0]))
B = B[scores_i]
L = L[scores_i]
U = U[scores_i]


def get_max_score(x):
    # x 点とったときの最大のスコア

    # 満点の数
    perfects = x // X
    # 途中まで頑張るやつは何点取ればいいか
    half_x = x % X

    border = N - perfects
    ret = []
    if len(B[:border]) > 0:
        # 途中まで頑張るやつを 0 点エリアから選択
        ret.append(max(
            scores_cumsum[border] +
            np.minimum(half_x, B[:border]) * L[:border] + np.maximum(0, half_x - B[:border]) * U[:border]
        ))
    if len(B[border:]) > 0:
        # 途中まで頑張るやつを満点エリアから選択
        ret.append(max(
            scores_cumsum[border - 1] - scores[border:] +
            np.minimum(half_x, B[border:]) * L[border:] + np.maximum(0, half_x - B[border:]) * U[border:]
        ))
    return max(0, *ret)


ans = bisect_right_callable(get_max_score, target - 1, 0, B.sum())
print(ans)


Measured memory_bytes: 76832
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<math.h>
#include<queue>
#include<deque>
#include<stack>
#include<cstdio>
#include<utility>
#include<set>
#include<list>
#include<cmath>
#include<stdio.h>
#include<string.h>
#include<iomanip>
#include<cstdio>
#include<cstdlib>
#include<cstring>
using namespace std;
#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)
#define REP(i, n) FOR(i, 0, n - 1)
#define NREP(i, n) FOR(i, 1, n)
using ll = long long;
using pii = pair<int, int>;
using piii = pair<pii, pii>;
const ll dx[4] = { 0, -1, 1, 0 };
const ll dy[4] = { -1, 0, 0, 1 };
const int INF = 1e9 + 7;
int gcd(int x, int y) {
	if (x < y)swap(x, y);
	if (y == 0)return x;
	return gcd(y, x%y);
}
void mul(ll a, ll b) {
	a = a * b % INF;
}
///////////////////////////////////////

int main() {
	ll N;
	cin >> N;
	ll a[N * 3 + 1];
	for (int i = 1; i <= N*3; ++i)cin >> a[i];
	ll red[2*N+1];
	red[0] = 0;
	//red[i]=前半i個からN個選んだ総和の最大値
	priority_queue<ll,vector<ll>,greater<ll>>rque;
	//大きいほうからN個を保持
	for (int i = 1; i <= N; ++i) {
		red[i] = red[i - 1] + a[i];
		rque.push(a[i]);
	}
	//ここから小さいのが切り捨てられる
	for (int i = N + 1; i <= N * 2; ++i) {
		red[i] = red[i - 1] + a[i];
		rque.push(a[i]);
		red[i] -= rque.top();
		rque.pop();
	}
	reverse(a+1,a+N*3+1);
	ll blue[N * 2 + 1];
	blue[0] = 0;
	//blue[i]=後半i個からN個選んだ総和の最小値
	priority_queue<ll>bque;
	for (int i = 1; i <= N; ++i) {
		blue[i] = blue[i - 1] + a[i];
		bque.push(a[i]);
	}
	for (int i = N+1; i <= N * 2; ++i) {
		blue[i] = blue[i - 1] + a[i];
		bque.push(a[i]);
		blue[i] -= bque.top();
		bque.pop();
	}
	ll ans = -1e20;
	for (int i = N; i <= N * 2; ++i) {
		ans = max(ans, red[i] - blue[N * 3 - i]);
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 7412
#include <bits/stdc++.h>
#define rep(i,n)for(int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const long long INF = 1LL<<60;
const int MOD = 1000000000+7;
#define rev(s) (string((s).rbegin(), (s).rend()))
// cout << fixed << setprecision(10) << ans << endl; 有効桁数指定
// *min_element(c + l, c + r) *max_element(c + l, c + r) 配列の中のmin-max
// int dx[8]={1,1,0,-1,-1,-1,0,1};
// int dy[8]={0,1,1,1,0,-1,-1,-1};
// int dx[4]={1,0,-1,0};
// int dy[4]={0,1,0,-1};
// ~ は、-1の時だけfalse

const int MAX = 1000010;
// const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

// int main() {
//     // 前処理
//     COMinit();

//     // 計算例
//     cout << COM(100000, 50000) << endl;
// }

int main () {

    int x,y;cin>>x>>y;

    int c=max(x,y),d=min(x,y);

    int a=c-d;

    COMinit();

    if ((c-2*a)%3==0) {
        int n=(c-2*a)/3;
        if (3*n+a==d) {
            cout<<COM(2*n+a,n)<<endl;
        } else {
            cout<<0<<endl;
        }
    } else {
        cout<<0<<endl;
    }


}

Measured memory_bytes: 23680
//AUTHOR: RAVAN_2070
//PUNE INSTITUTE OF COMPUTER TECHNOLOGY
/*
    I LOVE CLARICE STARLING

     ♥LOVE♥        ♥LOVE♥
  ♥LOVE♥♥LOVE♥  ♥LOVE♥♥LOVE♥
♥LOVE♥♥LOVE♥♥LOVE♥♥LOVE♥♥LOVE♥
   ♥LOVE♥♥LOVE♥♥LOVE♥♥LOVE♥
      ♥LOVE♥♥LOVE♥♥LOVE♥
         ♥LOVE♥♥LOVE♥
            ♥LOVE♥
               ♥


    EXPLAINATION BELOW->
    Dp on trees+pnc
   
*/
//
#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef long double ld;
typedef vector<ll> vi;
typedef vector<pair<ll,ll>> vii;
typedef pair<ll,ll> pii;
typedef map<ll,ll> mii;
#define MOD7 1000000007
#define MOD9 1000000009
#define pi 3.1415926535
#define Test_cases ll TC;cin>>TC;while(TC--)
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(), x.rend()
#define sp(x) fixed<<setprecision(x)
#define sz(x) (ll)(x.size())
#define fo(i,a,b) for(i=a;i<b;i++)
#define foe(i,a,b) for(i=a;i<=b;i++)
int n;
vector<vector<int>>adj;
vector<vector<ll>>dp;
void dfs(int v,int p=-1)
{
    ll ans_w,ans_b;ans_b=ans_w=1ll;
    for(auto it:adj[v])
    {
        if(it!=p)
        {
            dfs(it,v);
            ans_w=((ans_w)*((dp[it][1]+dp[it][0])%MOD7))%MOD7;
            ans_b=(ans_b*dp[it][1])%MOD7;
        }
    }
    dp[v][0]=ans_b;dp[v][1]=ans_w;
}
void solve()
{
  cin>>n;
  adj=vector<vector<int>>(n);
  dp=vector<vector<ll>>(n+1,vector<ll>(2,0));
  int i,u,v;
  fo(i,0,n-1)
  {
      cin>>u>>v;u--;v--;
      adj[u].pb(v);adj[v].pb(u);
  }
  dfs(0);
  ll ans=(dp[0][0]+dp[0][1])%MOD7;
  cout<<ans<<"\n";
}
int main()
{
   fastio
   solve();
  return 0;
}
//map<ll,ll,greater<int>> to sort in descending order ,in iterator declaration no greater<int>
//if you want to apply lowerbound on set use s.lower_bound(key),not the one used for vector
/* TIPS FOR DEBUGGING
 * Check if values are not overflowing (use long long where required)
 * Check if ranges are inclusive or not.
 * Check properly if greedy will work or not before using it.
 * Check EDGE CASES!! Seriously, even in 2B, saving 8 points by being
 * 2 minutes faster will bite you in the ass if you don't make sure
 * it works on edge cases.
 * Keep adding to this list.
*/


Measured memory_bytes: 18176
#include<iostream>
#include<algorithm>
#include<climits>
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define scan(arg) cin>>arg
#define prin(arg) cout<<arg<<"\n"
#define prin2(arg1,arg2) cout<<arg1<<" "<<arg2<<"\n"
using namespace std;
typedef long long ll;
const int NMAX=1<<17;
char x,y;
int main(){
  scan(x);scan(y);
  if(x<y) prin("<");
  else if(x>y) prin(">");
  else prin("=");
  
  return 0;
}


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

// int/long:		-2,147,483,648 - 2,147,483,648 (-2^31 <= int < 2^31)
// long/long long:	-9,223,372,036,854,775,808 - 9,223,372,036,854,775,807 (-2^63 <= long < 2^63)

#define	INF (1<<29)
//536,870,912

// lower_bound(A.begin(), A.end(), N)
// upper_bound(...

// A.erase(unique(A.begin(), A.end()), A.end())

// bit: &/and, |/or, ^/xor, ~/not

// getline(cin, String)

// Graph
// Warshall-Floyd: Distance between each node, N^3
// Dijkstra: Distance from the start node, N^2
// DFS(Depth-First Search)

/*
int	gcd(int A, int B) {
	while (0!=B) {
		A %=B;
		swap(A, B);
	}
	return A;
}
*/

#define	MOD 1000000007

int	main() {
	int N, A, B;
	cin >>N >>A >>B;
	vector<int> P(N, 0);
	for (int i=0; i<N; i++)
		cin >>P.at(i);
	sort(P.begin(), P.end());
	int AN=upper_bound(P.begin(), P.end(), A)-P.begin();
	int BN=upper_bound(P.begin(), P.end(), B)-P.begin()-AN;
	cout <<min(AN, min(BN, N-BN-AN)) <<endl;
	return 0;
}



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


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

  string S = "";

  while(N > 0) {
    N--;
    S.push_back('a'+N%26);
    N /= 26;
  } 

  reverse(S.begin(),S.end());
  cout << S << endl;
  

  

}


Measured memory_bytes: 3576
#include<bits/stdc++.h>
#define rep(i,N) for(int i=0;i<(N);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e12;
const int inf = 1e9;
typedef long long ll;
typedef pair<ll,int> P;
typedef set<int> S;
ll n;
int main(){
    string s,t;
    cin>>s>>t;
    cout<<t<<s<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main()
{
	int n;
	scanf("%d", &n);
	int ans = 0;
	int i;
	int a[102];
	for (i = 0; i < n; i++)
		scanf("%d", &a[i]);
	for (i = 0; i < n; i += 2)
		if (a[i] % 2 > 0)
			ans++;
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 1724
s, t = map(int, raw_input().split())
ans = 0
for a in range(s, t + 1):
    a = str(a)
    flag = 0
    for i in range(len(a)):
        if a[i] != a[len(a) - 1 - i]:
            flag = 1
            break
    if flag == 0:
        ans += 1
print ans

Measured memory_bytes: 7428
// Author:: MOHAMMAD FAISAL
// BEGINNING WITH THE NAME OF ALMIGHTY GOD ALLAH
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int a,b,c,d;
  cin >> a >> b >> c >> d;
  int left = a+b;
  int right = c+d;
  if(left > right) cout<<"Left";
  if(left < right) cout<<"Right";
  if(left==right) cout<<"Balanced";
  return 0;
}

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

using namespace std;
typedef long double ld;
typedef vector<ld> vd;
#define REP(i,n) for (int i = 0; i < n; ++i)
#define FOR(i,m,n) for (int i = m; i < n; ++i)

const int MAX = 3e3+10;
int N;
ld P[MAX], dp[MAX][MAX];

int main () {
  cin >> N;
  REP (i, N) cin >> P[i];
  dp[0][0] = 1;
  REP (i, N) {
    dp[i+1][0] = dp[i][0] * (1.0 - P[i]);
    REP (j, i+1) dp[i+1][j+1] = dp[i][j]*P[i] + dp[i][j+1]*(1.0-P[i]);
  }
  ld ans = 0;
  FOR (i, N/2+1, N+1) ans += dp[N][i];
  cout << setprecision(10) << ans << endl;
}

Measured memory_bytes: 139776
#include<bits/stdc++.h>
#define int long long
#define mod 1000000007
#define vi vector<int> 
#define pb push_back
#define mmst(a,b) memset(a,b,sizeof(a))
#define mx 1000005
#define mx2 100005
#define pii pair<int,int>
#define fastIO ios_base::sync_with_stdio(false)

using namespace std; 

vi graph[mx2];
// int par[mx2];
bool vis[mx2];
int disc[mx2];
int low[mx2];
vi art_pt;
int t=0;
vector<pii > bridge;
int prime[mx];

int power(int a,int b){
    if(b==0) return 1;
    int x = power(a,b/2);
    x = (x*x)%mod;
    if(b%2) return (x*(a%mod))%mod;
    return x;
}

void sieve(){
    prime[0]=prime[1]=1;
    for(int i=2;i*i<mx;i++){
        if(prime[i]==0){
            for(int j=i*i;j<mx;j+=i)
                prime[j]=1;
        }
    }
}

void dfs(int node,int par){
    vis[node]=true;
    int child =0;
    t++;
    disc[node]=low[node]=t;
    for(auto i:graph[node]){
        if(!vis[i]){
            // par[i.first]=node;
            child++;
            dfs(i,node);
            low[node]=min(low[node],low[i]);
            if(par==-1 and child>1 ){
                art_pt.pb(node);
            }
            if(par!=-1 and low[i]>=disc[node]){
                art_pt.pb(node);
            }
            if(low[i]>disc[node]){
                bridge.push_back({node,i});
            }
        }else{
            if(par!=i){
                low[node] = min(low[node],disc[i]);
            }
        }
    }
}

signed main(){
    fastIO;
    cin.tie(NULL);
    cout.tie(NULL);
    int n;
    string s;
    cin>>n>>s;
    int l=0,r=n-1,cnt=0;
    while(l<r){
        while(l<n and s[l]=='R'){
            l++;
        }
        while(r>=0 and s[r]=='W'){
            r--;
        }
        if(l<r){
            swap(s[l],s[r]);
            cnt++;
        }else{
            break;
        }
    }
    cout<<cnt<<endl;
}



Measured memory_bytes: 6076
#include<iostream>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<queue>
#define LL long long
using namespace std;
int n,tot,r,ans; 
int a[1000001],b[1000001];
int read()
{
	int _=0,__=1;char ch=getchar();
	while(ch<'0'||ch>'9') {if(ch=='-')__=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){_=_*10+ch-'0';ch=getchar();}
	return _*__;
}
//该题主要思路在于想到去求连续(数字连续而不是位置连续)的上升子序列，然后用总数减就可以了，这题的结论得出的比较玄学，未能严格证明 
int main()
{
	n=read();
	for(int i=1;i<=n;i++)
	a[i]=read();
	for(int i=1;i<=n;i++)
	b[a[i]]=i; 
	r=-1;ans=-1;
	for(int i=1;i<=n;i++)
	{
		if(b[i]>r)
		{
			++tot;
			r=b[i];
		}
		else
		{
			ans=max(ans,tot);
			tot=1;
			r=b[i];
		}
	}
	ans=max(ans,tot);
	printf("%d\n",n-ans);
	return 0;
	
 }



Measured memory_bytes: 5120
#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;
int main(){
    int n,x[100],y[100];
    cin >> n;
    for(int i=0;i<n;i++)cin >>x[i];
    for(int i=0;i<n;i++)cin >>y[i];
    double d[4];
    for(int i=0;i<4;i++)d[i]=0.0;
    for(int p=1;p<=3;p++){
        for(int i=0;i<n;i++){
            d[p]+=pow(fabs(x[i]-y[i]),p);
    }
    d[p]=pow(d[p],1.0/p);
    }
    for(int i=0;i<n;i++){
        d[0]=(d[0]<fabs(x[i]-y[i])?fabs(x[i]-y[i]):d[0]);
    }
    
    printf("%lf\n",d[1]);
    printf("%lf\n",d[2]);
    printf("%lf\n",d[3]);
    printf("%lf\n",d[0]);
}


Measured memory_bytes: 3340
///====================== khela STARTS HERE =====================///
#include "bits/stdc++.h"
const int inf = 1000000005;
const long long INF = 3e18;
const double pi = 2 * acos ( 0.0 );
typedef long long ll;
#define pii pair<int, int>
#define pb push_back
#define pf push_front
#define all(v) v.begin(), v.end()
#define maximum *max_element
#define minimum *min_element
#define MEMSET(v, x) memset(v, x, sizeof(v))
#define ABS(x) ((x)<0?-(x):(x))
#define white 1
#define grey 2
#define black 3
#define bug cout << "ei porjonto thikase" << endl;
#define fastread ios_base::sync_with_stdio(false);cin.tie(0);
using namespace std;
int gcd (int a, int b ) {
    a =  abs( a ); b = abs( b );
    while ( b ) { a = a % b; swap ( a, b ); } return a;}
int modInverse(int a, int m)
{int m0 = m;int y = 0, x = 1;if (m == 1)return 0;
while (a > 1){int q = a / m;int t = m;m = a % m, a = t;t = y;y = x - q * y;x = t;}if (x < 0)x += m0;return x;}
int lcm(int a, int b)
{int temp = gcd(a, b);return temp ? (a / temp * b) : 0;}
///====================== khela end1s HERE =====================///
const int maxn = 55;
int arr[maxn];
ll dp[maxn][101*101], p, n;
ll call(int i, int ammount){
	if(i>=n){
		if(ammount%2 == p)return 1;
		else{
			return 0;
		}
	}
	if(dp[i][ammount] == -1){
		ll ret1 = 0, ret2 = 0;
		ret1 = call(i+1, arr[i]+ammount);
		ret2 = call(i+1, ammount);
		dp[i][ammount] = ret1 + ret2;
	}
	return dp[i][ammount];
}

int main(int argc, char const *argv[])
{
	cin >> n >> p;
	for(int i=0; i<n; i++)cin >> arr[i];
	MEMSET(dp, -1);
	cout << call(0, 0) << endl;
}

Measured memory_bytes: 4608
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (int i = a; i < b; i++)
#define REP(i,b) FOR(i,0,b)
#define RFOR(i,a,b) for (int i = a-1; i >= b; i--)
#define RREP(i,a) RFOR(i,a,0)
#define REPALL(i,v) for (int i = 0; i < v.size(); i++)
#define RREPALL(i,v) for (int i = v.size()-1; i >= 0; i--)
#define SORT(v) sort(v.begin(), v.end())
#define MIN_ELEMENT(v) min_element(v.begin(), v.end())
#define MAX_ELEMENT(v) max_element(v.begin(), v.end())
#define COUNT(v,n) count(v.begin(), v.end(), n);
void YES(bool flag) {cout<<(flag ? "YES" : "NO")<<endl;}
void Yes(bool flag) {cout<<(flag ? "Yes" : "No")<<endl;}
void yes(bool flag) {cout<<(flag ? "yes" : "no")<<endl;}
typedef long long ll;
typedef unsigned long long ull;
const int INF = 1e7;
const ll MOD = 1e9 + 7;

int num[10] = {0, 2, 5, 5, 4, 5, 6, 3, 7, 6};
bool use[10];
string dp[11111];

string mymax(string s, string t)
{
    if (s.size() > t.size()) {
        return s;
    } else if (s.size() < t.size()) {
        return t;
    }else {
        return max(s, t);
    }
}

int main()
{
    int n, m;
    cin>>n>>m;
    REP(i,m) {
        int a;
        cin>>a;
        use[a] = true;
    }
    dp[0] = "";
    FOR(i,1,10) {
        if (use[i]) {
            dp[num[i]] = mymax(to_string(i), dp[num[i]]);
        }
    }
    FOR(i,1,n+1) {
        FOR(j,1,10) {
            if (use[j] && i - num[j] >= 0
            && (dp[i - num[j]] != "" || i - num[j] == 0)) {
                dp[i] = mymax(to_string(j) + dp[i - num[j]], dp[i]);
            }
        }
    }
    cout<<dp[n]<<endl;

    return 0;
}


Measured memory_bytes: 32384
#
# 　　  ⋀_⋀　 
#　　  (･ω･)  
# .／ Ｕ ∽ Ｕ＼
#  │＊　合　＊│
#  │＊　格　＊│ 
#  │＊　祈　＊│ 
#  │＊　願　＊│ 
#  │＊　　　＊│ 
#      ￣
#
import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
from math import floor,sqrt,factorial,hypot,log #log2ないｙｐ
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from fractions import gcd
from random import randint
def ceil(a,b): return (a+b-1)//b
inf=float('inf')
mod = 10**9+7
def pprint(*A): 
    for a in A:     print(*a,sep='\n')
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
    N=I()
    D={
        "A":0, "G":1, "C":2, "T":3
    }

    DP=[[[[0]*4 for _ in range(4)] for _ in range(4)] for _ in range(N)] #DP[i][a][b][c] := i文字目までで、最後の文字ががabcな場合の数
    DP[1][3] = [[1]*4 for _ in range(4)] 
    for i in range(2,N):
        for a in range(4):
            for b in range(4):
                for c in range(4):
                    for s in range(4):
                        if s==0: #なんでもOK
                            pass
                        elif s==1: #ACGだとout
                            if (b,c)==(D["A"],D["C"]):
                                continue
                        elif s==2: #AGC,GAC,A?GC,AG?Cがout
                            if (b,c) in ((D["A"],D["G"]), (D["G"],D["A"])) or (a,c) == (D["A"], D["G"]) or (a,b) == (D["A"], D["G"]) :
                                continue
                        else: #なんでもOK
                            pass
                        DP[i][b][c][s] += DP[i-1][a][b][c]
                        DP[i][b][c][s] %= mod

    ans = 0
    for a in DP[-1]:
        ans += sum([sum(i) for i in a])
    print(ans%mod)
    """
    AGC
    ACG
    GAC
    A?GC
    AG?C

    """
if __name__ == '__main__':
    main()


Measured memory_bytes: 69356
N, M = list(map(int, input().split()))
H = list(map(int, input().split()))
graphs = [[] for i in range(N)]
for i in range(M):
    a, b = list(map(int, input().split()))
    graphs[a-1].append(b-1)
    graphs[b-1].append(a-1)

ans = 0
for i in range(N):
    h = H[i]
    flag = True
    for b in graphs[i]:
        if H[b] >= h:
            flag = False
            break
    if flag:
        ans += 1
print(ans)
        


Measured memory_bytes: 29456
#include<cstdio>
#include<algorithm>

using namespace std;

int main(){
	int n, m; scanf("%d %d", &n, &m);
	int e[8][8] = {};
	for(int i = 0; i < m; i++){
		int a, b; scanf("%d %d", &a, &b); a--; b--;
		e[a][b] = e[b][a] = 1;
	}
	int v[8] = {0, 1, 2, 3, 4, 5, 6, 7};
	int res = 0;
	do{
		int f = 1;
		for(int i = 0; i < n - 1; i++) if(e[v[i]][v[i + 1]] == 0) f = 0;
		res += f;
	}while(next_permutation(v + 1, v + n));
	printf("%d\n", res);
	return 0;
}

Measured memory_bytes: 128
pub fn read1<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

pub fn readn<T: std::str::FromStr>(delimiter: &str) -> Vec<T> {
    let s = read1::<String>();
    s.split(delimiter).map(|e| e.parse().ok().unwrap()).collect::<Vec<T>>()
}

const INF: usize = 1000000000;

fn main() {
    let hn = readn::<usize>(" ");
    let h = hn[0];
    let n = hn[1];

    let mut dp = vec![vec![INF; h+1]; n+1];
    for i in 0..n+1 {
        dp[i][0] = 0;
    }

    for i in 1..n+1 {
        let ab = readn::<usize>(" ");
        for j in 1..h+1 {
            if j >= ab[0] {
                dp[i][j] = std::cmp::min(dp[i-1][j], dp[i][j-ab[0]] + ab[1]);
            } else {
                dp[i][j] = std::cmp::min(dp[i-1][j], dp[i][0] + ab[1]);
            }
        }
    }
    println!("{}", dp[n][h]);
}

Measured memory_bytes: 92412
N=gets.to_i
A,B,C=3.times.map{gets.split.map(&:to_i).sort}
x=0
t=B.map{|b|while x<N&&b>A[x]do x+=1 end;x}
s=[0];N.times{|i|s<<s[-1]+t[i]}
r=0;y=0
C.map{|c|while y<N&&c>B[y]do y+=1 end;r+=s[y]}
p r

Measured memory_bytes: 26224
#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL)
typedef long long ll;
typedef double dd;
#define pb push_back
#define mp make_pair
#define endl "\n"
#define M 1000000007
#define pi acos(-1)
/*ll power(ll a,ll b)
{
    ll res = 1;
    while(b > 0)
    {
        if(b & 1)
            res = (res*a)%M;
        a = (a*a)%M;
        b = b >> 1;
    }
    return res;
}*/
/*ll modinv(ll a)
{
   return power(a,M - 2); 
}*/
/*vector<ll> primes(ll n)
{
    bool *sieve = new bool[n + 1];
    ll i,j;
    vector<ll> v;
    for(i = 3; i <= n; i+=2)
        sieve[i] = true;
    sieve[2] = true;
    for(i = 3; i*i <= n; i+=2)
    {
        if(sieve[i])
            for(j = i*i; j <= n; j+=i)
                sieve[j] = false;
    }
    if(n >= 2)
    {
        v.pb(2);
        for(i = 3; i <= n; i+=2)
        {
            if(sieve[i])
                v.pb(i);
        }
    }
    return v;
}*/

/*class graph{
public:
    vector<ll> *g;
    ll n;
    graph(ll v)
    {
        n = v + 1;
        g = new vector<ll> [n];
    }
    void addegde(ll f,ll s)
    {
        g[f].pb(s);
        g[s].pb(f);
    }
    void dfs(bool *visited,ll sv)
    {
        visited[sv] = true;
        for(auto x: g[sv])
        {
            if(!visited[x])
            {
                dfs(visited,x);
            }
        }
    }
    void bfs(ll sv){
       queue<ll> q;
       bool visited[n] = {};
       q.push(sv);
       visited[sv] = true;
       while(!q.empty())
       {
           ll node = q.front();
           q.pop();
           for(auto x : g[node])
           {
               if(!visited[x])
               {
                   visited[x] = true;
                   q.push(x);
               }
           }
       }
    }
};*/
int main()
{
    fast;
    ll a[3];
    cin >> a[0]>>a[1]>>a[2];
    sort(a,a + 3);
    if(a[0] == a[1] && (a[1] != a[2]))
        cout<<"Yes"<<endl;
    else if(a[1] == a[2] && a[0] != a[1])
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h> 
#define int long long
#define quickie ios_base::sync_with_stdio(false); cin.tie(NULL);
#define rep(i, a, b) for(int i=a; i<b; i++)
#define rep1(i, a, b) for(int i=a; i<=b; i++)
#define repp(i, a, b) for(int i=b-1; i>=a; i--)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
#define db double
#define mi map<int, int>
#define mc map<char, int>
#define ms map<string, int>
#define vi vector<int>
#define qi queue<int>
#define MI(x) power(x, mod-2)
#define test int t; cin >> t;
#define mod 1000000007LL
//#define mod 998244353 
using namespace std;
int power(int x, int y) ;
int gcd(int a, int b) ;
#define pi 3.141592653589

signed main() {
    quickie
    db a, b, n ;
    cin >> a >> b >> n ;
    if(n >= b) {
        db xx = (a*(b-1))/b ;
        db yy = ((b-1))/b ;
        cout << floor(xx)-(a*floor(yy)) << "\n" ;
    }
    else {
        db xx = (a*n)/b ;
        db yy = (n)/b ;
        cout << floor(xx)-(a*floor(yy)) << "\n" ;
    }
}

int power(int x, int y) {
    int res = 1; x %= mod;
    while (y > 0) {
        if (y & 1)
            res = (res*x) % mod;
        y = y>>1;
        x = (x*x) % mod;
    }
    return res%mod;
}

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

Measured memory_bytes: 3884
#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++)
typedef int64_t llong;
char moji[26]={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
char moji2[26]={'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
char moji3[10]={'0','1','2','3','4','5','6','7','8','9'};
#define Sort(a) sort(a.begin(),a.end());
#define Reverse(a) reverse(a.begin(),a.end());


int main(){
    int x,y,z;
    cin >> x >> y >>z;
    int ans;
    x-= y + 2*z;
    ans= 1 + x/(y+z);
    cout << ans << endl;
}

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

// Begin {{{
using namespace std;

#define all(x) x.begin(), x.end()
#define rep(i, n) for (i64 i = 0; i < (n); ++i)
#define reps(i, s, n) for (i64 i = (s); i <= (n); ++i)
#define VAR(Type, ...) Type __VA_ARGS__; IN(__VA_ARGS__)
#define Float(x) OUTN(fixed, setprecision(x));

using i64 = int_fast64_t;
using pii = pair<i64, i64>;

template<class A, class B>
inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }

template<class A, class B>
inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }

constexpr int INF = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int MOD = int(1e9) + 7;

//IN
void IN() {}
template<class Head, class... Tail>
void IN(Head&& head, Tail&&... tail) {
  cin >> head;
  IN(forward<Tail>(tail)...);
}

//OUTS
template<size_t> struct int_{};
template<class Tuple, size_t Pos>
ostream& print_tuple(ostream& out, const Tuple& t, int_<Pos>) {
  out << get<tuple_size<Tuple>::value-Pos>(t) << " ";
  return print_tuple(out, t, int_<Pos-1>());
}

template <class Tuple>
ostream& print_tuple(ostream& out, const Tuple& t, int_<1>) {
  return out << get<tuple_size<Tuple>::value-1>(t);
}

template<class... Args>
ostream& operator<<(ostream& out, const tuple<Args...>& t) {
  return print_tuple(out, t, int_<sizeof...(Args)>());
}

#define OUTS(...) cout << make_tuple(__VA_ARGS__) << "\n";

//OUTL
void OUTL() {}
template<class Head, class... Tail>
void OUTL(Head&& head, Tail&&... tail) {
  cout << head << "\n";
  OUTL(forward<Tail>(tail)...);
}

//OUTN
void OUTN() {}
template<class Head, class... Tail>
void OUTN(Head&& head, Tail&&... tail) {
  cout << head;
  OUTN(forward<Tail>(tail)...);
}
// }}} End

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

  vector<int> cnt(5);
  rep(i, 3) {
    VAR(int, a, b);
    cnt[a]++;
    cnt[b]++;
  }

  reps(i, 1, 4) {
    if (cnt[i] >= 3) {
      OUTL("NO");
      return 0;
    }
  }

  OUTL("YES");
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
	int n,num,digit,rev=0;
	cin>>num;
	n = num;
	do
	{
	  digit = num%10;
	  rev = (rev * 10) + digit;
	  num = num/10;
	}
	while(num != 0);
	if ( n== rev)
	  cout<<"Yes";
   else
      cout<<"No";
      return 0;
}

Measured memory_bytes: 256
import java.util.*;

class Main{
  public static void main(String[] args){
    Scanner sc=new Scanner(System.in);
    int n=sc.nextInt();
    int st=sc.nextInt();
    int[] ten={0,sc.nextInt(),sc.nextInt(),sc.nextInt()};
    String t=sc.next();
    int flag;
    int ans=0;
    for(int i=0;i<st;i++){
      flag=0;
      for(int j=i;j<n;j+=st){
        if(flag==tete(t.charAt(j))){
          flag=0;
        }else{
          flag=tete(t.charAt(j));
        }
        ans+=ten[flag];
      }
    }
    System.out.println(ans);
  }
  static int tete(char c){
    if(c=='r'){
      return 3;
    }else if(c=='s'){
      return 1;
    }else if(c=='p'){
      return 2;
    }else{
      return -1;
    }
  }
}

Measured memory_bytes: 25044
// g++ -std=c++14

#include<bits/stdc++.h>

typedef long long ll;
typedef long double lld;
using namespace std;

#define sd(x) scanf("%d",&x)
#define sd2(x,y) scanf("%d%d",&x,&y)
#define sd3(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define endl "\n"
#define fi first
#define se second
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define all(c) (c.begin(),c.end())
#define LET(x, a)  __typeof(a) x(a)
#define foreach(it, v) for(LET(it, v.begin()); it != v.end(); it++)
#define MEMS(a,b) memset(a,b,sizeof(a))
#define _ ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define __ freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define inf 1000000000000000001

#define tr(...) cout<<__FUNCTION__<<' '<<__LINE__<<" = ";trace(#__VA_ARGS__, __VA_ARGS__)

template<typename S, typename T>
ostream& operator<<(ostream& out,pair<S,T> const& p){out<<'('<<p.fi<<", "<<p.se<<')';return out;}

template<typename T>
ostream& operator<<(ostream& out,vector<T> const& v){
ll l=v.size();for(ll i=0;i<l-1;i++)out<<v[i]<<' ';if(l>0)out<<v[l-1];return out;}

template<typename T>
void trace(const char* name, T&& arg1){cout<<name<<" : "<<arg1<<endl;}

template<typename T, typename... Args>
void trace(const char* names, T&& arg1, Args&&... args){
const char* comma = strchr(names + 1, ',');cout.write(names, comma-names)<<" : "<<arg1<<" | ";trace(comma+1,args...);}

#define int ll
int32_t main(){ _
  int n, w;
  cin >> n >> w;
  vector<int> weight(n), value(n);
  for(int i = 0; i < n; i++){
    cin >> weight[i] >> value[i];
  }
  vector<vector<int> > dp(n, vector<int>(w + 1, INT_MIN));
  if(weight[0] <= w)
    dp[0][weight[0]] = value[0];
  dp[0][0] = 0;
  for(int i = 1; i < n; i++){
      for(int j = 0; j <= w; j++){
        dp[i][j] = max(dp[i][j], dp[i - 1][j]);
        if(j - weight[i] >= 0)
          dp[i][j] = max(dp[i][j], dp[i - 1][j - weight[i]] + value[i]);
      }
  }
  int ans = 0;
  for(int j = 0; j <= w; j++)
    ans = max(ans, dp[n - 1][j]);
  cout << ans << endl;
}


Measured memory_bytes: 82372
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,f,n) for(int i=f; i<(n); i++)
int main()
{
  double ans = 0;
  int n, cnt=0;
  cin >> n;
  vector<int> c;
  vector<pair<int, int>> a;
  REP(i,0,n){
    int x, y;
    c.push_back(i);
    cin >> x >> y;
    a.push_back({x, y});
  }
  do{
    cnt++;
    double cost = 0;
    int x = a[c[0]].first, y = a[c[0]].second;
    REP(i,1,n){
      //cout << "[" << x << "," << y << "]->";
      cost += sqrt((x-a[c[i]].first)*(x-a[c[i]].first)+(y-a[c[i]].second)*(y-a[c[i]].second));
      x = a[c[i]].first;
      y = a[c[i]].second;
    }
    //cout << "[" << x << "," << y << "]->";
    //cout << cost << endl;
    ans += cost;
  }while(next_permutation(c.begin(), c.end()));
  //cout << ans << ", " << cnt << endl;
  printf("%.10lf\n",ans/cnt);

  //--debug : end_stoper
  //string end_stoper; cin >> end_stoper;

  return 0;
}

Measured memory_bytes: 3824
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
using namespace std;


int main(){
    int n,k,d,b,ans=0;
    cin>>n>>k;
    vector<int>a(1000);
    for(int i=0;i<k;i++){
        cin>>d;
        for(int j=0;j<d;j++){
            cin>>b;
            a[b]++;
        }
    }
    for(int i=1;i<=n;i++){
        if(a[i]==0){
            ans++;
        }
    }
    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 3624
#include<iostream>
#include<iomanip>
#include<string>
#include<set>
#include<vector>
#include<utility>
#include<queue>
#include<algorithm>
#include<functional>
using namespace std;
#define LL long long
#define MOD 100000
#define inf 1999999999
#define ALL(x) (x).begin(), (x).end()
#define LBi(x, n) lower_bound(ALL(x), n) - (x).begin()
#define ZIP(x) (x).erase(unique(ALL(x)), (x).end())
#define Pi pair<int, int>
#define Vi vector<int>

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

string s = "";
char ch[10];
int n, a, b, c, d, x, m[5];

int main() {
	cin >> x >> a >> b;
	cout << (x - a) % b << endl;
	return 0;
}


Measured memory_bytes: 256
import math
import heapq
from collections import Counter

#N,K=map(int, input[].split())  #複数数値入力　「A B」みたいなスペース空いた入力のとき
#x=list(map(int, input[].split()))  #リスト入力 「a1 a2 a3 ...」みたいな配列のような入力のとき

N,K=map(int, input().split())  #複数数値入力　「A B」みたいなスペース空いた入力のとき
A=list(map(int, input().split()))  #リスト入力 「a1 a2 a3 ...」みたいな配列のような入力のとき

S=Counter(A)
s= S.most_common(K)

print(N-[sum(x) for x in zip(*s)][1])


Measured memory_bytes: 32540
#ライブラリインポート
from collections import defaultdict

con = 10 ** 9 + 7
#入力受け取り
def getlist():
	return list(map(int, input().split()))

#処理内容
def main():
	N = int(input())
	S = input()
	ans = 0
	for i in range(N - 2):
		if S[i:i + 3] == "ABC":
			ans += 1

	print(ans)

if __name__ == '__main__':
	main()

Measured memory_bytes: 38384
/* ex7_3
  kt125 */

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

int main(void){
    int height, width, *row, *col;
    char **board;
    scanf("%d %d", &height, &width);

    //高さ分の配列を動的確保
    row = (int*)calloc(height, sizeof(int));
    if(row == NULL) { //エラー処理
        fprintf(stderr, "memory allocation error.\n");
        exit(1);
    }
    
    //幅分の配列を動的確保
    col = (int*)calloc(width, sizeof(int));
    if(col == NULL) { //エラー処理
        fprintf(stderr, "memory allocation error.\n");
        exit(1);
    }

    //マス目を格納する配列の動的確保
    board = (char**)calloc(height, sizeof(char*));
    if(board == NULL){ //エラー処理
        fprintf(stderr, "memory allocation error.\n");
        exit(1);
    }
    for(int i=0; i<height;i++){
        board[i] = (char*)calloc(width+1, sizeof(char));
        if(board[i] == NULL){ //エラー処理
            fprintf(stderr, "memory allocation erroe.\n");
            exit(1);
        }
    }

    //マス目を得る
    for(int i=0; i<height; i++){
        scanf("%s", board[i]);
    }

    //'#'を含む行と列をマーク
    for(int i=0; i<height; i++){
        for(int j=0; j<width; j++){
            if(board[i][j] == '#'){
                row[i]++;
                col[j]++;
            }
        }
    }

    //マークした列と行のみ出力
    for(int i=0; i<height; i++){
        if(row[i]){
            for(int j=0; j<width; j++){
                if(col[j]){
                    printf("%c", board[i][j]);
                }
            }
            printf("\n");
        }
    }

    //メモリ解放
    free(row);
    free(col);
    for (int i=0; i<height; i++){
        free(board[i]);
    }
    free(board);

    return 0;
}

Measured memory_bytes: 1660
#include<bits/stdc++.h>
using namespace std;
#define INF (1<<28)
#define DEKAI 1000000007
#define lp(i,n) for(int i=0;i<n;i++)
#define int long long
int a;
int c[1050000];


signed main(){
  int n,k;
  cin>>n>>k;
  string s;
  cin>>s;
  s[k-1]-='A';
  s[k-1]+='a';
  cout<<s<<endl;
  return 0;
}

Measured memory_bytes: 256
N = int(input())
A = list(map(int,input().split()))
count = 0
for i in range(N-1,0,-1):
    for j in range(i):
        if A[j] > A[j+1]:
            A[j],A[j+1] = A[j+1],A[j]
            count += 1

print(*A)
print(count)



Measured memory_bytes: 5608
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pll;
#define rep(i,n) for(int i=0;i<n;i++)
#define all(x) x.begin(),x.end()
#define chmin(a,b) a=min(a,b)
#define chmax(a,b) a=max(a,b)
#define mod 998244353
#define pl(a,b) a=(a+b)%mod;
ll po(ll x,ll y){
	ll res=1;
	for(;y;y>>=1){
		if(y&1)res=res*x%mod;
		x=x*x%mod;
	}
	return res;
}
#define N 3010
ll dp[N][N];
int main(){
	ll a,b,c,d;
	cin>>a>>b>>c>>d;
	rep(i,N)rep(j,N)dp[i][j]=0;
	dp[a][b]=1;
	for(ll h=a;h<=c;h++){
		ll cs=0;
		for(ll w=b;w<=d;w++){
			pl(dp[h+1][w],dp[h][w]*w);
			/*for(ll k=1;w+k<=d;k++){
				pl(dp[h+1][w+k],dp[h][w]*po(h,k));
			}*/
			pl(cs,dp[h][w]);
			cs=cs*h%mod;
			pl(dp[h+1][w+1],cs);
		}
	}
	ll ans=0;
	for(ll w=b;w<=d;w++){
		pl(ans,dp[c][w]*po(c,d-w));
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 74412
// IO library
#include <cstdio>
#include <iomanip>
#include <ios>
#include <iostream>

// algorithm library
#include <algorithm>
#include <cmath>
#include <numeric>

// container library
#include <deque>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>

// namespace
using namespace std;

// typedef
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef vector<string> VS;
typedef vector<bool> VB;
typedef vector<VB> VVB;

// conversion
#define INT(c) static_cast<int>(c)
#define CHAR(n) static_cast<char>(n)
#define LL(n) static_cast<ll>(n)

// container
#define EACH(i, c) for (auto i = (c).begin(); i != (c).end(); i++)
#define SORT(c) sort((c).begin(), (c).end())
#define GSORT(c) sort((c).begin(), (c).end(), greater<decltype((c).front())>())
#define SZ(x) (INT((x).size()))
#define MEMSET(c, v) memset((c), v, sizeof(c))

// repetition
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define NREP(i, n) FOR(i, 1, n + 1)
#define RFOR(i, a, b) for (int i = (a); i >= (b); i--)
#define RREP(i, n) RFOR(i, n, 0)
#define RNREP(i, n) RFOR(i, n, 1)

// constant
// const ll MOD = 1e9 + 7;
// const int INF = 1<<25;
// const ll INF = 1LL<<50;
// const int dx[4] = {0, -1, 1, 0};
// const int dy[4] = {-1, 0, 0, 1};
// const int dx[8] = {-1, 0, 1, -1, 1, -1, 0, 1};
// const int dy[8] = {-1, -1, -1, 0, 0, 1, 1, 1};

// debug
#define test(x) cout << #x << " = " << x << endl

// answer output
#define Yes(c) cout << ((c) ? "Yes" : "No") << endl;
#define YES(c) cout << ((c) ? "YES" : "NO") << endl;
#define yes(c) cout << ((c) ? "yes" : "no") << endl;

#define possible(c) cout << ((c) ? "possible" : "impossible") << endl;
#define POSSIBLE(c) cout << ((c) ? "POSSIBLE" : "INPOSSIBLE") << endl;


// --------------------------------------------------------


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

  string w;
  VI num(26, 0);
  cin >> w;
  REP(i, w.size()) {
    num[w[i] - 'a']++;
  }
  REP(i, 26) {
    if (num[i] % 2 > 0) {
      cout << "No" << endl;
      return 0;
    }
  }

  cout << "Yes" << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define N 300
#define A 300
#define mod 998244353
int a[N+1],dp1[2][N*A+1],dp2[2][N*A+1],Sum[N+1];
int main(){
	int n,imp=0,power=1,i,j;scanf("%d",&n);
	for(i=1;i<=n;i++)scanf("%d",a+i),Sum[i]=Sum[i-1]+a[i],power=3ll*power%mod;
	dp1[0][0]=1;
	for(i=1;i<=n;i++)for(j=0;j<=Sum[i];j++)
		dp1[i&1][j]=(2*dp1[i-1&1][j]%mod+(j>=a[i]?dp1[i-1&1][j-a[i]]:0))%mod
//		,printf("dp[%d][%d]=%d\n",i,j,dp1[i&1][j])
		;
	for(i=Sum[n]+1>>1;i<=Sum[n];i++)imp+=3ll*dp1[n&1][i]%mod,imp%=mod;
	if(!(Sum[n]&1)){
		dp2[0][0]=1;
		for(i=1;i<=n;i++)for(j=0;j<=Sum[i];j++)
			dp2[i&1][j]=(dp2[i-1&1][j]+(j>=a[i]?dp2[i-1&1][j-a[i]]:0))%mod;
		imp-=3ll*dp2[n&1][Sum[n]>>1]%mod;while(imp<0)imp+=mod;imp%=mod;
	}
	power-=imp;if(power<0)power+=mod;
	printf("%d\n",power);
	return 0;
}
/*1
4
1
1
1
2
*/
/*2
6
1
3
2
3
5
2
*/
/*3
20
3
1
4
1
5
9
2
6
5
3
5
8
9
7
9
3
2
3
8
4
*/

Measured memory_bytes: 1664
use proconio::{fastout, input};

#[fastout]
fn main() {
  input! {
      k: u32,
      a: u32,
      b: u32
  }

  let mut acc = k;
  while acc <= b {
    if a <= acc && acc <= b {
      println!("OK");
      return;
    }
    acc += k;
  }
  println!("NG");
}


Measured memory_bytes: 2144
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.stream.Stream;

public class Main{
	public static void main(String[] args){
		InputStreamReader inputStreamReader = new InputStreamReader(System.in);
		BufferedReader bufferedReader = new BufferedReader(inputStreamReader);
		StringBuilder stringBuilder = new StringBuilder();
		
		try{
			String dataSet;
			int[][] intArray = new int[2][4];
			int index = 0;
			while((dataSet=bufferedReader.readLine())!=null){
				if(dataSet.length()==0) break;
				String[] stringArray = dataSet.split(" ");
				intArray[index] = Stream.of(stringArray).mapToInt(Integer::parseInt).toArray();
				if(index==1){
					int[] result = hitBlow(intArray[0], intArray[1]);
					stringBuilder.append(result[0] + " " + result[1] + "\n");
					index = 0;
				}else
					++index;
			}
			System.out.print(stringBuilder);
		}catch(IOException e){
			e.printStackTrace();
		}
	}
	
	static int[] hitBlow(int[] a, int[] n){
		int hit = 0;
		int blow = 0;
		for(int i=0; i<4; i++){
			int key = a[i];
			for(int j=0; j<4; j++){
				if(key==n[j]){
					if(i==j){
						++hit;
					}else{
						++blow;
					}
				}
			}
		}
		int[] result = {hit, blow};
		return result;
	}
}

Measured memory_bytes: 30700
#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
#define FOR(i,s,n) for(int i=s;i<n;i++)
#define ROF(i,n,e) for(int i=n;i>e;i--)
#define mod 1e9+7
#define MAX 1000005    //10^5+5
#define MAXQ 200005    //2*10^5+5
#define pi pair<int,int>
#define pb push_back
#define all(c) c.begin(),c.end()
#define tr(it,container) for(typeof(container.begin()) it = container.begin(); it != container.end(); it++)
#define ll long long
#define f first
#define s second
#define sz(container) container.size()
typedef pair<int,int> pii;
typedef pair<int,pii> node;

inline ll modExp(ll a,ll b,ll m=mod){
	ll res=1;
	a%=m;
	while(b>=1){
		if(b%2!=0){
			res=(res%m*a%m)%m;
		}
		a=(a%m*a%m)%m;
		b=b/2;
	}
	return res;
}
bool isPrime(int x){
	if(x<=1){
		return false;
	}
	if(x==2||x==3){
		return true;
	}
	if(x%2==0){
		return false;
	}
	for(int i=3;i<=sqrt(x);i+=2){
		if(x%i==0){
			return false;
		}
	}
	return true;
}
int main(int argc, char const *argv[])
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    int n,k;
    cin>>n>>k;
    int r,s,p;
    cin>>r>>s>>p;
    string str;
    cin>>str;
    ll ans=0;
    map<char,int>m={{'r',p},{'s',r},{'p',s}};
    vector<char>arr(n);
    FOR(i,0,n){
		ll val=0;
    	if(i<k){
    		ans+=m[str[i]];
    	}else{
    		if(str[i]==str[i-k]){
    			str[i]='?';
    		}else{
    			ans+=m[str[i]];
    		}
    	}
    }
    cout<<ans<<"\n";
    // cout<<str<<"\n";
    return 0;    
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
using namespace std;
#define rep(i,x) for(ll i = 0; i < (ll)(x); i++)
#define rrep(i,x) for(ll i = (ll)(x)-1;i <= 0; i--)
#define reps(i,x) for(ll i = 1; i < (ll)(x); i++)
#define rreps(i,x) for(ll i = (ll)(x)-1; i <= 1; i--)
#define debug(x) cerr << #x << ": " << (x) << "\n";
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<vector<vector<ll>>> vvvl;
const ll INF = numeric_limits<ll>::max()/4;
const int n_max = 1e5+10;

template<class T>
bool chmax(T &a, T b){if(a < b){a = b; return true;} return false;}
template<class T>
bool chmin(T &a, T b){if(a > b){a = b; return true;} return false;}
void print() {
    cout << endl;
}

int main(){
    string s;cin >> s;
    ll n = s.size();
    vector<vector<ll>> dp(2, vector<ll>(n+1,INF));
    dp[0][0] = 0;
    rep(i,n){
        ll t = s[i] - '0';
        chmin(dp[0][i+1], dp[0][i] + t);
        chmin(dp[1][i+1], dp[0][i] + 10 - t);
        chmin(dp[1][i+1], dp[1][i] + 9 - t);
        chmin(dp[0][i+1], dp[1][i] + t + 1);
    }

    cout << min(dp[0][n], dp[1][n]+1) << endl;
}

Measured memory_bytes: 24836