akhauriyash/Code-Regression huggingface dataset:
n,k = map(int,input().split())
s = input()+"2"
lst0 = [0]
lst1 = [0]
if s[0] == "0": lst1.append(0)
cnt = 0
for i in range(n):
    cnt += 1
    if s[i] != s[i+1]:
        if s[i] == "0": lst0.append(cnt)
        else: lst1.append(cnt)
        cnt = 0
l0 = len(lst0)
l1 = len(lst1)
k = min(k,l0-1)
for i in range(l0-1): lst0[i+1] += lst0[i]
for i in range(l1-1): lst1[i+1] += lst1[i]
# print(lst0)
# print(lst1)
ans = 0
for l in range(l0):
    r = min(l+k,l0-1)
    rr = r if r == l1-1 else r+1
    cnt = lst0[r]-lst0[l] + lst1[rr]-lst1[l]
    ans = max(cnt,ans)
print(ans)

Measured memory_bytes: 7148
#include <bits/stdc++.h>
#define REP(i,n,N) for(int i=n;i<N;i++)
#define p(S) cout<<S<<endl
#define ck(n,a,b) (a<=(n)&&(n)<b)
using namespace std;


int main(){
	string s;
	set<char> right{'y','u','i','o','p','h','j','k','l','n','m'};
	while(cin>>s && s!="#"){
		bool flag=true;//true:right
		int ans=0;
		if(right.find(s[0])==right.end()) flag=false;
		REP(i,1,(int)s.size()){
			if(right.find(s[i])==right.end()&&flag) {
				ans++;
				flag=false;
			}else if(right.find(s[i])!=right.end()&&!flag){
				ans++;
				flag=true;
			}
		}
		p(ans);
	}
	return 0;
}

Measured memory_bytes: 3148
#include<bits/stdc++.h>
using namespace std;
#define int long
using pi=pair<int,int>;
signed main(){
    int n, m;
    cin >> n >> m;
    vector<pi> s(m);
    string res(n, 'x');
    for (int i = 0; i < m; ++i) cin >> s[i].first >> s[i].second, --s[i].first;
    if(m){
        for (int i = 0; i < m; ++i) {
            if (res[s[i].first] != 'x' && res[s[i].first] != '0' + s[i].second) return cout << -1, 0;
            res[s[i].first] = '0' + s[i].second;
        }
    }
    for (int i = 0; i < n;++i)
        if (res[i] == 'x') res[i] = (i||n==1 ? '0' : '1');
    if (n > 1 && res[0] == '0') return cout << -1, 0;
    cout << res;
}

Measured memory_bytes: 256
#include<iostream>
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define IO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;
vector<int> v;
int n, b[200009], ans[200009];
int main()
{
    IO
    cin>>n;
    for(int i=1; i<=n; i++)
        cin>>b[i];
    for(int i=n; i>=1; i--)
    {
        int sum=0;
        for(int j=i; j<=n; j+=i)
            sum+=ans[j];
        if(sum%2!=b[i]%2){
            ans[i]=1;
            v.push_back(i);
        }
    }
    cout<<v.size()<<"\n";
    reverse(v.begin(),v.end());
    for(auto i : v)
        cout<<i<<" ";
}


Measured memory_bytes: 5236
N, K = map(int, input().split())
a = list(map(int, input().split()))

dp = [False] * (K+1)

for i in range(1, K+1):
    for j in range(N):
        if 0 <= i - a[j] and not dp[i-a[j]]:
            dp[i] = True

print("First" if dp[K] else "Second")

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

int main(){
  int N;
  cin >> N;
  vector<int> v(N);
  for(int i = 0; i < N;i++){
    cin >> v.at(i);
  }
  
  sort(v.begin(), v.end());
  
  float ans = v.at(0);
  for(int i = 1; i < N;i++){
    ans = (ans + v.at(i)) / 2;
  }
  
  cout << ans;
  
  return 0;
}


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

using namespace std;

int main() {
  int N, K;
  
  cin >> N >> K;
  
  vector<int> A(N, 0);
  
  for (int i = 0; i < K; i++) {
    int d;
    
    cin >> d;
    
    for (int j = 0; j < d; j++) {
      int A_i;
      
      cin >> A_i;
      
      A[A_i - 1]++;
    }
  }
  
  int ans = 0;
  for (int i = 0; i < N; i++) {
    if (A[i] == 0) {
      ans++;
    }
  }
  
  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 3624
#include <iostream>
#include <vector>
#include <algorithm>
#include <stack>
#include <string>
#include <cmath>
#include <cstdio>
using namespace std;

#define PI 4*atan(1);

int main(){
  bool sub[30] = {false};
  for(int i = 0; i < 28; i++){
    int tmp;
    cin >> tmp;
    sub[tmp - 1] = true;
  }
  for(int i = 0; i < 30; i++){
    if(sub[i] == false){
      cout << i + 1 << endl;
    }
  }
}

Measured memory_bytes: 1160
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<math.h>
#include<stdbool.h>
#include<set>
#define N 1000000007
using namespace std;
typedef long long ll;

int main(void) {
	int a, b, c, sum = 0;
	cin >> a >> b >> c;
	set<int>st;
	while (true) {
		sum += a;
		if (sum%b == c) {
			cout << "YES" << endl;
			return 0;
		}
		else {
			if (!st.count(sum%b)) {
				st.insert(sum%b);
			}
			else {
				cout << "NO" << endl;
				return 0;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define f(x,n) for (int i=x;i<n;i++)

int count(int a[], int n, int k)
{
  
 int ans[n+1],m;
  ans[1]=0;
  ans[2]=abs(a[2]-a[1]);
  
  for (int i=3;i<=n;i++)
  {
    int result=INT_MAX;
    for (int j=i-1;j>0 && j>=i-k;j--)
    {

      m=abs(a[i]-a[j])+ans[j];
      result=min(result,m);
      
    }
    
    ans[i]=result;
   
  }

  return ans[n];

}

int main()
{
  int n,k;
  cin>>n>>k;
  int a[n+1];
 
   for(int i=1;i<=n;i++)
    cin>>a[i];
  int ans=count(a,n,k);
  cout<<ans;

  return 0;
}

Measured memory_bytes: 4404
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef vector<ll> vl;
typedef vector<string> vs;
typedef vector<char> vc;
typedef queue<ll> ql;
typedef deque<ll> dql;
typedef priority_queue<ll/*, vl, greater<ll>*/> pql; //降順(/*昇順*/)
typedef set<ll> sl;
typedef pair<ll, ll> pl;
typedef vector<vl> vvl;
typedef vector<pl> vpl;
#define rep(i, n) for(ll i = 0; i < ll(n); i++)
#define rep2(i, n) for(ll i = 1; i <= ll(n); i++)
//#define rep(i, k, n) for(ll i = k-1; i < ll(n); i++)
//#define rep2(i, k, n) for(ll i = k; i <= ll(n); i++)
#define all(v) (v).begin(), (v).end()
bool chmin(ll &a, ll b) {if(b < a) {a = b; return 1;} return 0;}
bool chmax(ll &a, ll b) {if(b > a) {a = b; return 1;} return 0;}
const ll INF = 1LL << 60;
const ll MOD = 1e9 + 7;
//const ll MOD = 998244353;
const ll MAX = 1e9;
const char newl = '\n';

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

  //input
  ll D;
  cin >> D;
  ll c[26+1];
  rep2(i, 26) cin >> c[i];
  ll s[D+1][26+1];
  rep2(i, D) rep2(j, 26) cin >> s[i][j];
  ll t[D+1];
  rep2(i, D) cin >> t[i];
  
  ll stfc=0; //satisfaction
  
  ll Nstr[26+1]; // not holding streak
  rep2(i, 26) Nstr[i]=0;
  
  rep2(d, D) {
    // calculate
    ll con=t[d]; //contest
    stfc += s[d][con];
    rep2(i, 26) {
      if(i==con) Nstr[i]=0;
      else {Nstr[i]++; stfc -= c[i]*Nstr[i];}
    }
    
    // output
    cout << stfc << newl;
  }
  
  return 0;
}

Measured memory_bytes: 3612
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<string>
#include<vector>
#include<set>
#include<cctype>
using namespace std;

int main(void){
	ios::sync_with_stdio(false); cin.tie(0);
	
	string a[3],p="ABC";
	cin>>a[0]>>a[1]>>a[2];
	int turn=0,next;
//	cout<<endl;
	while(1){
//		cout<<turn<<endl;
//		cout<<"before:"<<endl<<a[0]<<endl<<a[1]<<endl<<a[2]<<endl;
		if(a[turn].length()==0){
			cout<<p[turn]<<endl;
			break;
		}
		else{
//			cout<<"turnchar:"<<(int)a[turn][0]-(int)'a'<<endl;
			next=(int)a[turn][0]-(int)'a';
			a[turn]=a[turn].substr(1,a[turn].length()-1);
			turn=next;
		}
//		cout<<"after:"<<endl<<a[0]<<endl<<a[1]<<endl<<a[2]<<endl;
	}
	
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <cfloat>
#include <stack>
#include <queue>
#include <vector>
#include <string>
#include <iostream>
#include <set>
#include <map>
#include <time.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef pair<int,int> P;
typedef pair<ll,pair<ll,ll> > p;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
#define bit(n,k) ((n>>k)&1) /*nのk bit目*/
static const int MAX_SIZE = 1 << 17; //segment tree のサイズ。この実装では2べきにする必要がある。 2^17 ≒ 1.3 * 10^5

ll dp[2][11000][110];

int main(){
    int n,nx;
    string K;
    int D;
    cin>>K>>D;
    n=K.size();
    dp[0][0][0]=1;
    for(int i=0;i<2;i++){
        for(int j=1;j<=n;j++){
            for(int k=0;k<D;k++){
                if(i==0){
                    nx=K[j-1]-'0';
                    for(int l=0;l<nx;l++){
                        dp[1][j][(k+l)%D]+=dp[i][j-1][k];
                        dp[1][j][(k+l)%D]%=MOD;
                    }
                    dp[0][j][(k+nx)%D]+=dp[0][j-1][k];
                }else{
                    for(int l=0;l<10;l++){
                        dp[1][j][(k+l)%D]+=dp[1][j-1][k];
                        dp[1][j][(k+l)%D]%=MOD;
                    }
                }
            }
        }
    }
    if(dp[0][n][0]+dp[1][n][0]==0) cout<<MOD-1<<endl;
    else cout<<(dp[0][n][0]+dp[1][n][0]-1)%MOD<<endl;
}



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

int main() {
  int N, x, dmin = 100;
  cin >> N;
  for (int i = 0; i < N; i++) {
    int d = 0;
    cin >> x;
    while (x % 2 == 0) {
      x /= 2;
      d++;
    }
  dmin = min(dmin, d);
  }
  cout << dmin << endl;
}


Measured memory_bytes: 256
//D - Teleporter

#include<iostream>
#include<vector>
#include<set>
#include<algorithm>

using namespace std;

typedef long long ll;

int main(){
    ll n,k;
    cin>>n>>k;

    vector<int> a(n);

    for(int i=0; i<n; i++){
        cin>>a.at(i);
        a.at(i)--;
    }

    set<int> set;
    vector<int> path;
    int p=0,cnt=0,s,r;

    while(set.count(p)==0){
        set.insert(p);
        path.push_back(p);
        p=a[p];
    }

    s = find(path.begin(), path.end(), p)- path.begin();
    r = path.size()-s;

    if(k < s){
        cout<<path[k]+1<<endl;
    }else{
        cout<<path[(k-s)%r+s]+1<<endl;
    }

    return 0;
}


Measured memory_bytes: 13972
import java.util.Scanner;

public class Main {

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

		int n=sc.nextInt();

		int a[]=new int[n];
		for(int i=0;i<n;i++){
			a[i]=sc.nextInt();
		}

		for(int i=n-1;i>0;i--){
			System.out.print(a[i]+" ");
		}
		System.out.println(a[0]);
	}
}

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

using namespace std;

int main()
{
  long long int n, m, l;

  cin >> n >> m >> l;

  long long int a[n][m], b[m][l], c[n][l];

  for (int i = 0; i < n; i++)
  {
    for (int j = 0; j < m; j++)
    {
      cin >> a[i][j];
    }
  }

  for (int i = 0; i < m; i++)
  {
    for (int j = 0; j < l; j++)
    {
      cin >> b[i][j];
    }
  }

  for (int i = 0; i < n; i++)
  {
    for (int j = 0; j < l; j++)
    {
      c[i][j] = 0;
    }
  }

  for (int i = 0; i < n; i++)
  {
    for (int j = 0; j < l; j++)
    {
      for (int k = 0; k < m; k++)
      {
        c[i][j] += a[i][k] * b[k][j];
      }
    }
  }

  for (int i = 0; i < n; i++)
  {
    for (int j = 0; j < l; j++)
    {
      if (j == l - 1)
      {
        cout << c[i][j] << endl;
        ;
      }
      else
      {
        cout << c[i][j] << " ";
      }
    }
  }
}


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

using namespace std;

#define ll  long long
#define f first
#define s second

const int N = 1e5+5;

ll mod = 1e9+7;
ll fact[N] , inv[N];

ll fp(ll base, ll exp)
{
    if (exp == 0)
        return 1;
    ll ans = fp(base, exp / 2);
    ans = (ans * ans) % mod;
    if (exp % 2 != 0)
        ans = (ans * (base % mod)) % mod;
    return ans;
}

void calcFacAndInv(ll n)
{
    fact[0] = inv[0] = 1;
    for (ll i = 1; i <= n; i++)
    {
        fact[i] = (i * fact[i - 1]) % mod;
        inv[i] = fp(fact[i], mod - 2);
    }
}

ll ncr(ll n, ll r)
{
    return ((fact[n] * inv[r]) % mod * inv[n - r]) % mod;
}

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

    calcFacAndInv(N-2);
    ll sum , ans=0;
    cin >> sum;

    for(int i=1; i<=sum; i++) //size of seq
    {
        ll rem = sum - i*3;
        if (rem < 0) break;
        ans = (ans+ncr(i+rem-1 , rem))%mod;
    }

    cout << ans << '\n';

    return 0;
}

Measured memory_bytes: 5208
#include<stdio.h>
int main()
{
int i,x,y;
scanf("%d %d",&x,&y);
while(x!=0||y!=0){
if(x<y){
printf("%d %d\n",x,y);
}else{
printf("%d %d\n",y,x);}
scanf("%d %d",&x,&y);}
return 0;
}

Measured memory_bytes: 596
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>

int llcmp(const void *a, const void *b) {
    if (*(long long *)a > *(long long *)b) return -1;
    else if (*(long long *)a < *(long long *)b) return 1;
    else return 0;
}

long long T[100000010];

long long max(int len, ...) {
    long long i, _max, num;
    va_list ap;
    va_start(ap, len);

    _max = va_arg(ap, long long);
    for (i = 1; i < len; i++) {
        num = va_arg(ap, long long);
        if (num > _max)
            _max = num;
    }
    va_end(ap);
    return _max;
}
int main(void) {
    int i, j, l, m, n, X, Y, Z, K;
    long long A[1010], B[1010], C[1010];
    scanf("%d%d%d%d", &X, &Y, &Z, &K);
    for (l=0;l<X;l++) scanf("%lld", &A[l]);
    for (m=0;m<Y;m++) scanf("%lld", &B[m]);
    for (n=0;n<Z;n++) scanf("%lld", &C[n]);
    i = 0; j = 0;
    qsort(A, X, sizeof(long long), llcmp);
    qsort(B, Y, sizeof(long long), llcmp);
    qsort(C, Z, sizeof(long long), llcmp);
    for (l=0;l<X;l++) for (m=0;m<Y;m++) for (n=0;n<Z;n++) {
        if ((l+1)*(m+1)*(n+1) <= K) T[i++] = A[l] + B[m] + C[n];
        else break;
    }
    qsort(T, i, sizeof(long long), llcmp);
    for (l=0;l<K;l++) printf("%lld\n", T[l]);

    return 0;
}

Measured memory_bytes: 1916
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<math.h>
using namespace std;
int main() {
	int n;cin >> n;
    vector<double> x(n);
    vector<string> u(n);
    for(int i=0;i<n;i++){
        cin>>x[i]>>u[i];
    }
    double ans=0;
    for(int i=0;i<n;i++){
        if(u[i]=="BTC"){
            ans+=(x[i]*380000.0);
        }else{
            ans+=x[i];
        }
    }
    cout << ans << endl;
}

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

int main(){
    using namespace std;
    size_t N, M, Q;
    cin >> N >> M >> Q;
    vector<vector<unsigned long>> train(N + 1, vector<unsigned long>(N + 1));
    for(size_t i = 0, L, R; i < M; ++i){
        cin >> L >> R;
        ++train[L][R];
    }
    for(size_t i = N; i--; ){
        partial_sum(train[i].begin(), train[i].end(), train[i].begin());
        transform(train[i].begin(), train[i].end(), train[i + 1].begin(), train[i].begin(), plus<>());
    }
    for(size_t i = 0, p, q; i < Q; ++i){
        cin >> p >> q;
        cout << train[p][q] << endl;
    }
    return 0;
}

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

#define rt0 return 0
#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
#define replet(c) for(char c='a';c<='z';c++) 
#define LL long long
#define pii pair <int,int>
#define pb push_back
#define fi first
#define se second
#define mpr make_pair
#define sqr(a) ((a)*(a))

using namespace std;

const LL MOD=1e9+7;

LL n,x[60],y[60],p,q,nx,ny,res,ans=1e9,st1,st2;
bool vis[60],has;

void go(LL pos,LL xx,LL yy)
{
	nx=x[pos];
	ny=y[pos];
	vis[pos]=true;
	while(true)
	{
		has=false;
		rep(i,n)
		{
			if(x[i]!=nx+xx||y[i]!=ny+yy||vis[i]) continue;
			vis[i]=true;
			has=true;
			nx=x[i];
			ny=y[i];
		}
		if(!has) break;
	}
}

int main()
{
	cin>>n;
	rep(i,n) cin>>x[i]>>y[i];
	rep(i,n)
	{
		rep(j,n)
		{
			st1=i;
			st2=j;
			res=0;
			p=x[i]-x[j];
			q=y[i]-y[j];
			memset(vis,0,sizeof(vis));
			rep(k,n)
			{
				if(vis[k]) continue;
				res++;
				go(k,p,q);
				go(k,-p,-q);
			}
			ans=min(ans,res);
		}
	}
	cout<<ans<<endl;
	rt0;
}

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

int main(){
  int a, b, c, x;
  cin >> a >> b >> c >> x;

  int count = 0;
  for(int i = 0; i <= a; i++){
    for(int j = 0; j <= b;j++){
      for(int k = 0; k <= c; k++){
        int judge = i * 500 + j * 100 + 50 * k;
        if(judge == x){
          count++;
        }
      }
    }
  }
  cout << count << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n)for(int i=0;i<(n);i++)
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define pb push_back
using ll = long long;
using P = pair<int, int>;

const int mod = 1000000007;
struct mint{
    ll x;
    mint(ll x=0):x((x%mod+mod)%mod){}
    mint operator-() const { return mint(-x); }
    mint& operator+=(const mint a){
        if((x+=a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint a){
        if((x += mod-a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const mint a){
        (x *= a.x) %= mod;
        return *this;
    }
    mint operator+(const mint a) const {
        mint res(*this);
        return res += a;
    }
    mint operator-(const mint a) const {
        mint res(*this);
        return res -= a;
    }
    mint operator*(const mint a) const {
        mint res(*this);
        return res *= a;
    }
    mint pow(ll t) const {
        if(!t) return 1;
        mint a = pow(t >> 1);
        a *= a;
        if(t&1) a *= *this;
        return a;
    }

    mint inv() const {
        return pow(mod - 2);
    }
    mint& operator/=(const mint a) {
        return (*this) *= a.inv();
    }
    mint operator/(const mint a) const {
        mint res(*this);
        return res /= a;
    }
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

struct combination {
    vector<mint> fact, ifact;
    combination(int n):fact(n+1),ifact(n+1){
        assert(n < mod);
        fact[0] = 1;
        for(int i = 1; i <= n; i++) fact[i] = fact[i-1]*i;
        ifact[n] = fact[n].inv();
        for(int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;  
    }
    mint operator()(int n, int k){
        if(k < 0 || n < k) return 0;
        return fact[n]*ifact[k]*ifact[n-k];
    }
};

vector<P> prime_factor(int n){
    vector<P> res;
    for(int i = 2; i * i <= n; ++i){
        if(n % i != 0) continue;
        int cnt = 0;
        while(n % i == 0){
            n /= i;
            cnt++;
        }
        res.push_back(P(i, cnt));
    }
    if(n != 1) res.push_back(P(n, 1));//nが素数の時
    return res;
}


int main(){
    int n, m; cin >> n >> m; 
    auto vec = prime_factor(m);
    combination comb(200000);
    mint ans = 1;
    for(auto elem : vec){
        int num = elem.second;
        ans *= comb(num + n - 1, n - 1);
    }
    cout << ans << endl;
}

Measured memory_bytes: 3328
#include <bits/stdc++.h>
#include <ext/hash_map>
#include <ext/numeric>

using namespace std;
using namespace __gnu_cxx;

#define REP(i,n) for( (i)=0 ; (i)<(n) ; (i)++ )
#define rep(i,x,n) for( (i)=(x) ; (i)<(n) ; (i)++ )
#define REV(i,n) for( (i)=(n) ; (i)>=0 ; (i)-- )
#define FORIT(it,x) for( (it)=(x).begin() ; (it)!=(x).end() ; (it)++ )
#define foreach(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();++it)
#define rforeach(it,c) for(__typeof((c).rbegin()) it=(c).rbegin();it!=(c).rend();++it)
#define foreach2d(i, j, v) foreach(i,v) foreach(j,*i)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define SZ(x) ((int)(x).size())
#define MMS(x,n) memset(x,n,sizeof(x))
#define mms(x,n,s) memset(x,n,sizeof(x)*s)
#define pb push_back
#define mp make_pair
#define NX next_permutation
#define UN(x) sort(all(x)),x.erase(unique(all(x)),x.end())
#define CV(x,n) count(all(x),(n))
#define FIND(x,n) find(all(x),(n))-(x).begin()
#define ACC(x) accumulate(all(x),0)
#define PPC(x) __builtin_popcountll(x)
#define LZ(x) __builtin_clz(x)
#define TZ(x) __builtin_ctz(x)
#define mxe(x) *max_element(all(x))
#define mne(x) *min_element(all(x))
#define low(x,i) lower_bound(all(x),i)
#define upp(x,i) upper_bound(all(x),i)
#define NXPOW2(x) (1ll << ((int)log2(x)+1))
#define PR(x) cout << #x << " = " << (x) << endl ;

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

const int OO = (int) 2e9;
const double eps = 1e-9;

int n, m, k;

int main() {
	std::ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
#ifndef ONLINE_JUDGE
//	freopen("in.txt", "rt", stdin);
//	freopen("out.txt", "wt", stdout);
#endif
	cin >> n >> m >> k;
	for (int i = 0; i <= n; i++) {
		for (int j = 0; j <= m; j++) {
			int res = i * m + j * n - 2 * (i * j);
//			cout << i << " " << j << " " << res << endl;
			if (res == k) {
				puts("Yes");
				return 0;
			}
		}
	}
	puts("No");
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
const int MAX_K = 1e5;

int main(){
    int n, k; cin >> n >> k;
    vector<int> a(n);
    for(auto& v:a){
        cin >> v;
    }
    sort(a.begin(), a.end());
    vector<int> dp(MAX_K+1, -1);
    for(int i=0; i<a[0]; i++){
        dp[i] = 0;
    }
    for(int i=0; i<k; i++){
        for(int j=0; j<n; j++){
            if(dp[i] == -1){continue;}
            if(i + a[j] > MAX_K){continue;}
            if(dp[i] == 0){
                dp[i+a[j]] = max(dp[i+a[j]], 1);
            }
            else{
                dp[i+a[j]] = max(dp[i+a[j]], 0);
            }
        }
    }
    if(dp[k] == 1){
        cout << "First\n";
    }
    else{
        cout << "Second\n";
    }
    return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
 
int main() {
  long long n;
  cin>>n;
  vector<int> a(n);
  rep(i,n){
    cin>>a[i];
  }
  bool b=1;
  sort(a.begin(),a.end());
  rep(i,n){
    if(a[i]==a[i+1]){
      b=0;
      break;
    }
  }
  if(b){
    cout<<"YES"<<endl;
  }
  else{
    cout<<"NO"<<endl;
  }
}


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

using namespace std;

inline void quit(){ exit(0); }

typedef long long ll;

ll mpow(ll _x, ll _y, ll _mod){
    if(_y==0) return 1;
    if(_y==1) return _x%_mod;
    if(_y&1) return (mpow(_x, _y-1, _mod)*_x)%_mod;
    ll _tmp = mpow(_x, _y>>1, _mod);
    return (_tmp*_tmp)%_mod;
}

int n, k;
int h[100002];
int ans;

int main(){
    cin>>n>>k;
    for(int i=1; i<=n; i++) cin>>h[i];
    for(int i=1; i<=n; i++) if(k<=h[i]) ans++;
    cout<<ans;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define rep(i, a, b) for(int i = a; i < b; i++)
#define Rep(i, a, b) for(int i = a; i <= b; i++)
#define cinf(n,x,y) for(int i=0;i<(n);i++) cin >> x[i]>>y[i];
#define _GLIBCXX_DEBUG
#define V vector<int>
using namespace std;
using ll = long long;

int main(){
    string w;
    cin>>w;
    vector<int> buc(25,0);
    rep(i,0,w.size()){
        buc[w[i]-'a']++;
    }
    bool f=true;
    rep(i,0,25){
        if(buc[i]%2!=0) f=false;
    }
    if(f) cout<<"Yes"<<"\n";
    else cout<<"No"<<"\n";
}

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


int main(){
    int count=0;
    char s[4];
    scanf("%s",&s);
    for(int i=0;i<4;i++){
        if(s[0]==s[i])count++;
        if(s[1]==s[i])count++;
        if(s[2]==s[i])count++;
        if(s[3]==s[i])count++;
    }
    if(count==8)cout << "Yes" <<endl;
    else cout << "No" <<endl;

}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
#define chmin(a, b) ((a)=min((a), (b)))
#define chmax(a, b) ((a)=max((a), (b)))
#define fs first
#define sc second
#define eb emplace_back
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;

const ll MOD=1e9+7;
const ll INF=1e18;
const double pi=acos(-1);
const double eps=1e-10;

int dx[]={1, 0, -1, 0};
int dy[]={0, -1, 0, 1};

int main(){
    int n; cin>>n;
    vector<int> a(n);
    for(int i=0; i<n; i++){
        int x; cin>>x;
        x--;
        a[x] = i;
    }

    set<int> st;
    st.insert(-1);
    st.insert(n);

    ll ans=0;
    for(int i=0; i<n; i++){
        st.insert(a[i]);

        auto mid = st.find(a[i]);
        auto ub = mid; ub++;
        auto lb = mid; lb--;

        ans += (ll)(*ub - *mid) * (*mid - *lb) * (i+1);
    }

    cout << ans << endl;
}

Measured memory_bytes: 10368
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<deque>
#include<cmath>
#include<map>
#include<cstring>
#include<iomanip> //cout << fixed << setprecision(15) << x << endl;

using namespace std;
typedef long long ll;
const int INF = 1e9 + 6;
const int MOD = 1e9 + 7;
const ll LLINF = 1LL<<60;
#define P pair<int, int>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()

const int MAX = 8000;

bool dpx[MAX + 1][2 * MAX + 5], dpy[MAX + 1][2 * MAX + 5];
// dpx[i][x] : sの先頭からi文字目まで見たときx座標にいることができるか？

int main() {
    string s; cin >> s;
    int x, y; cin >> x >> y;
    int N = s.size();
    int cntF = 0;
    vector<int> t;
    rep(i, N) {
        if(s[i] == 'T') {
            if(cntF != 0)t.pb(cntF);
            t.pb(0);//Tを示す
            cntF = 0;
        }else {
            ++cntF;
            if(i == N - 1) t.pb(cntF);
        }
    }
    x += MAX; y += MAX;
    //目的は，座標(8000, 8000)から出発し，(8000 + x, 8000 + y) にたどり着けるか？？
    dpx[1][8000 + t[0]] = true;
    dpy[1][8000] = true;
    int cntT;
    cntT = (t[0] == 0);
    for(int i = 1; i < t.size(); ++i) {
        if(t[i] == 0) {
            ++cntT;
        }
        if(cntT % 2 == 0) {//x方向への移動
            rep(j, 2 * MAX) {
                if(dpx[i][j]) {
                    if(j + t[i] < 2 * MAX) dpx[i + 1][j + t[i]] = true;
                    if(j - t[i] >= 0) dpx[i + 1][j - t[i]] = true;
                }
                dpy[i + 1][j] = dpy[i][j];
            }
        }else if(cntT % 2 == 1) {//y方向への移動
            rep(j, 2 * MAX) {
                if(dpy[i][j]) {
                    if(j + t[i] < 2 * MAX) dpy[i + 1][j + t[i]] = true;
                    if(j - t[i] >= 0) dpy[i + 1][j - t[i]] = true;
                }
                dpx[i + 1][j] = dpx[i][j];
            }
        }
    }
    cout << ((dpx[t.size()][x] && dpy[t.size()][y]) ? "Yes" : "No") << endl;
}


Measured memory_bytes: 249984
a,b=map(int,input().split())
c,d,e=map(int,input().split())
g=input()
l = a-b
for i in range(l):
   if g[i] == g[i+b]:
      g = g[:i+b] + 'a' + g[i+1+b:]
      
else:
  R = g.count('r')
  S = g.count('s')
  P = g.count('p')
  answer = c*S+d*P+e*R
  print(answer)

Measured memory_bytes: 3452
#include <iostream>
#include<string>
#include<stack>
#include<queue>
#include<map>
#include<list>
#include<vector>
#include <locale>
#include<algorithm>
#include<unordered_map>
#include <locale>


using namespace std;
int  main() {
	vector<long long>v;
	long long n, k , sum = 0;
	cin >> n >> k;
	for (int i = 0; i < n; i++) {
		long long c;
		cin >> c;
		sum += c;
		v.push_back(c);
	}

	if (k == 0) {
		cout << sum<<endl;
	}

	else if (k >= n) {
		cout << 0 << endl;
	}
	else {
		sum = 0;
		sort(v.begin(), v.end());
		reverse(v.begin(), v.end());
		for (int i = k ; i < v.size(); i++) {
			sum += v[i];
		}

		cout << sum << endl;

	}
	return 0;
}

Measured memory_bytes: 2420
N, Ma, Mb = map(int, input().split())
A = []
B = []
C = []
for _ in range(N):
    a, b, c = map(int, input().split())
    A.append(a)
    B.append(b)
    C.append(c)
M = 401
dp = [[[float('INF') for _ in range(M)]
       for _ in range(M)] for _ in range(N + 1)]
dp[0][0][0] = 0
for i in range(N):
    for j in range(M):
        for k in range(M):
            if dp[i][j][k] == float('INF'):
                continue
            dp[i + 1][j][k] = min(dp[i + 1][j][k], dp[i][j][k])
            dp[i + 1][j + A[i]][k + B[i]
                                ] = min(dp[i + 1][j + A[i]][k + B[i]], dp[i][j][k] + C[i])
ans = float('INF')
for j in range(1, M):
    for k in range(1, M):
        if j * Mb == k * Ma:
            ans = min(ans, dp[N][j][k])
if ans == float('INF'):
    print(-1)
else:
    print(ans)

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

typedef long long ll;

/*
const ll M = 1000000007;
vector<ll> fac(3001);
vector<ll> ifac(3001);
ll mpow(ll x, ll n){
    ll ans = 1;
    while(n != 0){
        if(n&1) ans = ans*x % M;
        x = x*x % M;
        n = n >> 1;
    }
    return ans;
}
 
ll comb(ll a, ll b){
    if(a == 0 && b == 0)return 1;
    if(a < b || a < 0 || b < 0)return 0;
    ll tmp = ifac[a-b]* ifac[b] % M;
    return tmp * fac[a] % M;
}
*/


ll lcm(ll a,ll b){
 
  ll r, x, tmp;
  x = a * b;
  if(a<b){
    tmp = a;
    a = b;
    b = tmp;
  }
 
  r = a % b;
  while(r!=0){
    a = b;
    b = r;
    r = a % b;
  }
  return x/b;
}

ll gcd(ll a ,ll b){
    if(a==0){return b;}
    else if(b==0){return a;}
    else{
    ll tmp,r;
    if(a<b){
        tmp = a;
        a = b;
        b = tmp;
    }
    
    r = a % b;
    while(r!=0){
        a = b;
        b = r;
        r = a % b;
    }
    return b;
    }
}




int main(void){
    const ll inf = 1000000007;
    ll n, k, ans = 0;
    cin >> n >> k;
    ll a[n],b[2*n];
    for(int i=0;i<n;i++)cin >> a[i];
    for(int i=0;i<n;i++){b[i]=a[i];b[i+n]=a[i];}
    ll kC2=(k*(k-1)/2) % inf;
    ll m = 0;
    ll M = 0;
    for(ll i=0;i<n;i++){
        for(ll j=i+1;j<n;j++){
            if(a[i]>a[j])m++;
        }
    }
    for(ll i=0;i<n*2;i++){
        for(ll j=i+1;j<n*2;j++){
            if(b[i]>b[j])M++;
        }
    }
    M = M - m*2;
    ans = (kC2 * M + m * k)%inf;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
M,D = [int(s) for s in input().split()]
ls=[[a,b] for a in range(2,10) for b in range(2,10)]
count=0
for x in ls:
  if(x[0]*10+x[1]<=D and x[0]*x[1]<=M):
    count+=1
print(count)
  


Measured memory_bytes: 3060
#include <bits/stdc++.h>
typedef long long lint;

#define PI acos(-1)
#define INF64 1LL << 60
#define INF32 1 << 29
#define all(a) (a).begin(), (a).end()
#define INV ((long long int)1000000007)

using namespace std;

void execute()
{
	int sx, sy, tx, ty;
	int diff_x, diff_y;
	cin >> sx >> sy >> tx >> ty;

	diff_x = tx - sx;
	diff_y = ty - sy;

	for (int i = 0; i < diff_x; i++)
	{
		cout << 'R';
	}
	for (int i = 0; i < diff_y; i++)
	{
		cout << 'U';
	}
	for (int i = 0; i < diff_x; i++)
	{
		cout << 'L';
	}
	for (int i = 0; i < diff_y; i++)
	{
		cout << 'D';
	}
	cout << 'D';
	for (int i = 0; i < diff_x + 1; i++)
	{
		cout << 'R';
	}
	for (int i = 0; i < diff_y + 1; i++)
	{
		cout << 'U';
	}
	cout << "LU";
	for (int i = 0; i < diff_x + 1; i++)
	{
		cout << 'L';
	}
	for (int i = 0; i < diff_y + 1; i++)
	{
		cout << 'D';
	}
	cout << 'R' << endl;
	return;
}

int main()
{
	cin.tie(0);
	ios_base::sync_with_stdio(false);
	std::cout << std::fixed << std::setprecision(15);
	execute();

	int stop;
	cin >> stop;

	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(void){
    int r, x1, x2, d, i;

    scanf("%d%d%d",&r ,&d ,&x1);

    for(i=0; i<10; i++){
        x2 = r*x1 - d;
        printf("%d\n",x2);
        x1 = x2;
    }

    return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#define llu unsigned long long
#define ll long long
#define INF 0x3f3f3f3f
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n"

using namespace std;

int main()
{
	fast
	ll N, ans=0;
	cin>>N;
	ans+=(N/500);
	N=N-(ans*500);
	ans*=1000;
	ans+=(N/5)*5;
	cout<<ans<<endl;
}		

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<vector>
#include<set>
#include<stack>
#include<queue>
#include<list>
#include<map>
#define ll long long
#define INF 2000000000
#define NINF -2000000000
#define MOD 1000000007
#define br '\n'
using namespace std;
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	char s[200001];
	cin>>s;
	int l=strlen(s);
	int a=0;
	while(s[a]!='A')
		a++;
	int z=l-1;
	while(s[z]!='Z')
		z--;
	cout<<z+1-a<<br;
	return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <string>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <numeric>
#include <regex>

#define FOR(i, f, n) for(int (i) = (f); (i) < (n); (i)++)
#define RFOR(i, f, n) for(int (i) = (f); (i) >= (n); (i)--)
#define REP(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define RREP(i, n) for(int (i) = (n); (i) >= 0; (i)--)
#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define rrep(i, n) for(int (i) = (n); (i) >= 0; (i)++)
#define p(...) printf(__VA_ARGS__); cout << endl;
#define in(...) __VA_ARGS__; input__(__VA_ARGS__);
#define input(...) in(__VA_ARGS__)
#define out(...) output__(__VA_ARGS__);
#define output(...) out(__VA_ARGS__)
#define list_input(x, n) x[(n)]; for(int (i) = 0; (i) < (n); (i)++) cin >> x[i];
#define lambda(a, b, c) [](const a, const b){ return c ;}
#define key(t, x, compare) [](const t& a, const t& b){ return a x compare b x ;}

using namespace std;

using pii = pair<int, int>;

template <class... T>
void input__(T &...a) {
  for(auto v: {&a...}) {
    cin >> *v;
  }
}

template <class... T>
void output__(T ...a) {
  for(auto v: {a...}) {
    cout << v << " ";
  }
  cout << endl;
}

int main(){
  string in(a, b);
  rep(i, 3) {
    if(a[i] != b[2 - i]) goto ELSE;
  }
  out("YES");
  return 0;

ELSE:
  out("NO");
}


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

using namespace std;

const int MAX_N = 2e5;

int n;
int a[MAX_N];
int wns[MAX_N];
set<pair<int, int>> s[MAX_N];
vector<int> g[MAX_N];
int lev[MAX_N];
queue<int> al;
int cnt = 0;

void dfs(int v) {
    vector<int> tmp;
    for (int u : g[v]) {
        dfs(u);
        tmp.push_back(wns[u]);
    }
    sort(tmp.begin(), tmp.end());
    int mx = -1;
    for (int i = 0; i < tmp.size(); i++) {
        mx = max(mx, tmp[i] + (int) tmp.size() - 1 - i);
    }
    wns[v] = mx + 1;
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin >> n;
    a[0]--;
    for (int i = 1; i < n; i++) {
        cin >> a[i];
        a[i]--;
        g[a[i]].push_back(i);
    }
    dfs(0);
    cout << wns[0] << "\n";
}



Measured memory_bytes: 26112
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> P;

void transposition(vector<P> &v){
    for(int i=0; i<v.size(); i++){
        v[i] = P{v[i].second, -v[i].first};
    }
    return;
}

bool check(vector<P> v, vector<P> u){
    bool same = true;
    int dx = v[0].first - u[0].first;
    int dy = v[0].second - u[0].second;
    if(v.size() != u.size()) return false;
    for(int i=0; i<v.size(); i++){
        if(v[i].first != u[i].first + dx || v[i].second != u[i].second + dy) same = false;
    }
    return same;
}

void solve(int n){
    int m;
    cin >> m;
    vector<P> origin(m);
    for(int i=0; i<m; i++) cin >> origin[i].first >> origin[i].second;
    for(int N=0; N<n; N++){
        vector<P> v;
        bool same = false;
        cin >> m;
        for(int i=0; i<m; i++){
            int x, y;
            cin >> x >> y;
            v.push_back(P{x, y});
        }

        for(int i=0; i<2; i++){
            for(int j=0; j<4; j++){
                same |= check(origin, v);
                transposition(v);
            }
            reverse(v.begin(), v.end());
        }
        if(same == true) cout << N+1 << endl;
    }
    return;
}


int main(){
    int n;
    while(true){
        cin >> n;
        if(n == 0) return 0;
        solve(n);
        cout << "+++++" << endl;
    }
}


Measured memory_bytes: 3000
import sys,math,collections,itertools
input = sys.stdin.readline

N,K=list(map(int,input().split()))
S=input().rstrip()

ori_num=0
turn_num=0
for i in range(N):
    if i>0:
        if S[i-1] =='L' and S[i] =='L':
            ori_num += 1
        if S[i-1] != S[i]:
            turn_num +=1
        
    if i<N-1:
        if S[i] =='R' and S[i+1] =='R':
            ori_num += 1

if turn_num >=2*K:
    ori_num += 2*K
else:
    num = turn_num//2
    num2 = turn_num%2
    ori_num += 2*num+num2
    
print(ori_num)


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

int sum;

int main() {
    int a, b, c, k;
    cin >> a >> b >> c >> k;
    while(k>0){
        while(a>0 && k>0){
            k--;
            a--;
            sum++;
        }
        while(b>0 && k>0){
            k--;
            b--;
        }
        while(c>0 && k>0){
            k--;
            c--;
            sum--;
        }
    }
    
    cout << sum << endl;
}


Measured memory_bytes: 3596
#include<bits/stdc++.h>
#include <algorithm>
using namespace std;
int main(){
  int a,b,c,d,e;
  cin>>a>>b>>c>>d>>e;
  int t=0;
  for(int i=0;i<14;i++){
      if(a<=i*10){
          t=t+i*10;
          a=a-i*10;
          break;
      }
  }
  for(int i=0;i<14;i++){
      if(b<=i*10){
          t=t+i*10;
          b=b-i*10;
          break;
      }
  }
  for(int i=0;i<14;i++){
      if(c<=i*10){
          t=t+i*10;
          c=c-i*10;
          break;
      }
  }
  for(int i=0;i<14;i++){
      if(d<=i*10){
          t=t+i*10;
          d=d-i*10;
          break;
      }
  }
  for(int i=0;i<14;i++){
      if(e<=i*10){
          t=t+i*10;
          e=e-i*10;
          break;
      }
  }
  t=t+min({a,b,c,d,e});
  cout<<t<<endl;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner scan = new Scanner(System.in);
    int n = scan.nextInt();
    scan.close();
    
    int count = 0;
    for(int i = 1; i <= n; i++) {
      int len = String.valueOf(i).length();
      if(len % 2 == 1) count++;
    }
    System.out.println(count);
  }
}

Measured memory_bytes: 30164
import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop, core.stdc.string;

void main() {
    auto S = readln.chomp;
    auto T = readln.chomp;

    auto N = S.length.to!int;
    auto M = T.length.to!int;

    auto next = new int[][](M, 26);
    foreach (i; 0..M) fill(next[i], 1<<29);

    foreach (i; 0..M) {
        foreach_reverse (j; i..M) {
            next[i][T[j]-'a'] = j;
        }
    }

    auto dp = new int[][](N+1, M+1);
    auto prevc = new dchar[][](N+1, M+1);
    auto previ = new Tuple!(int, int)[][](N+1, M+1);
    foreach (i; 0..N+1) fill(previ[i], tuple(-1, -1));

    foreach (i; 0..N) {
        foreach (j; 0..M) {
            {
                int nx = j;
                int nv = dp[i][j];
                if (nv > dp[i+1][nx]) {
                    dp[i+1][nx] = nv;
                    prevc[i+1][nx] = prevc[i][j];
                    previ[i+1][nx] = previ[i][j];
                }
            }
            if (next[j][S[i]-'a'] != 1<<29) {
                int nx = next[j][S[i]-'a'] + 1;
                int nv = dp[i][j] + 1;

                if (nv > dp[i+1][nx]) {
                    dp[i+1][nx] = nv;
                    prevc[i+1][nx] = S[i];
                    previ[i+1][nx] = tuple(i, j);
                }
            }
        }
    }

    int mi = 0;
    int mj = 0;
    int ms = 0;
    foreach (i; 0..N+1) {
        foreach (j; 0..M+1) {
            if (dp[i][j] > ms) {
                ms = dp[i][j];
                mi = i;
                mj = j;
            }
        }
    }

    dchar[] ans;
    while (previ[mi][mj][0] != -1) {
        ans ~= prevc[mi][mj];
        auto t = previ[mi][mj];
        mi = t[0];
        mj = t[1];
    }
    ans.reverse;

    ans.writeln;
}


Measured memory_bytes: 146684
#include <bits/stdc++.h>
using namespace std;
long long n,a,b;
int main() {
	scanf("%lld%lld%lld",&n,&a,&b);
	if (a > b)
		swap(a,b);
	if (abs(a-b)%2 == 0) {
		printf("%lld",abs(a-b)/2);
		return 0;
	}
	else {
		long long ans;
		long long sum=a-1;
		long long bb=b-a+1,aa;
		sum++;
		bb--;
		aa=1;
		sum+=abs(aa-bb)/2;
		ans=sum;
		sum=n-b;
		aa=a+n-b;
		aa++;
		sum++;
		bb=n;
		sum+=abs(aa-bb)/2;
		printf("%lld",min(ans,sum));
	}
	return 0;
}

Measured memory_bytes: 256
n,m=map(int,input().split())
list1=[]
for i in range(m):
    a=list(map(int,input().split()))
    list1.append(a)
p=list(map(int,input().split()))

num=2**n
count=0
for i in range(num):
    lump=1
    x=[]
    for j in range(n):
        x.append((i*2//(2**(j+1)))% 2)
    for k in range(m):
        sum=0
        for k1 in range(len(list1[k][1:])):
            if x[list1[k][k1+1]-1]==1:
                sum=sum+1
        if sum % 2!=p[k]:
            lump=0
    if lump==1:
        count=count+1
print(count)

Measured memory_bytes: 42608
#include <algorithm>
#include <climits>
#include <iostream>
#include <string>
#include <utility>
#include <vector>

using namespace std;
template <class T> ostream &operator<<(ostream &os, vector<T> &v) {
  for (auto i = v.begin(); i != v.end(); i++) {
    os << *i << " ";
  }
  return os;
}

using ll = long long int;

int main(void) {
  int n, l;
  cin>> n >> l;
  int ans = 0;
  for(int i=1; i<=n; i++) {
    ans += l+i-1;
  }

  if(l<1) {
    if (l+n-1<0) {
      ans -= l+n-1;
    }
  } else {
    ans -= l;
  }
    
  std::cout << ans << std::endl;
  return 0;
}



Measured memory_bytes: 256
c=[list(map(int,input().split())) for i in range(3)]
for i in range(min(c[0])+1):
  b1=c[0][0]-i
  b2=c[0][1]-i
  b3=c[0][2]-i
  if c[1][0]-b1==c[1][1]-b2==c[1][2]-b3:
    if c[2][0]-b1==c[2][1]-b2==c[2][2]-b3:
      print("Yes")
      break
    else:
      continue
  else:
    continue
else:
  print("No")

Measured memory_bytes: 3064
#include<stdio.h>
int main(void){
  
  int a,b,i;
  char op;
  
  for(i=0;;i++){
    scanf("%d %c %d",&a,&op,&b);
    if(op == '?' )break;
    
    if (op == '+' )
      printf("%d\n",a+b);
    else if(op == '-' )
      printf("%d\n",a-b);
    else if(op == '*' )
      printf("%d\n",a*b);
    else if(op == '/' )
      printf("%d\n",a/b);
  }
  
  return 0;
}

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

typedef long long ll;
typedef long long llong;
typedef long double ld;
typedef unsigned long long ull;

using namespace std;

/*
ll pw(ll a, ll b) {
	ll ans = 1; while (b) {
		while (!(b & 1)) b >>= 1, a = (a * a) % MOD;
		ans = (ans * a) % MOD, --b;
	} return ans;
}
*/

int h, w, d;
int c[1200];
char s[1200][1200];

int main() {
	cin >> h >> w >> d;
	for (int i = 0; i < h + w - 1; ++i) {
		if (i >= d)
			c[i] = c[i - d] ^ 1;
		else
			c[i] = 0;
	}
	for (int i = 0; i < h; ++i)
		for (int j = 0; j < w; ++j) {
			int a = c[i + j] * 2 + c[i + (w - 1 - j)];
			if (a == 0)
				s[i][j] = 'R';
			else if (a == 1)
				s[i][j] = 'G';
			else if (a == 2)
				s[i][j] = 'B';
			else
				s[i][j] = 'Y';
		}
	for (int i = 0; i < h; ++i) {
		printf("%s\n", s[i]);
	}
	return 0;
}




Measured memory_bytes: 1024
import java.io.*;
import java.util.*;

class Main{
    public static void main(String args[])throws IOException{
      try(BufferedReader br = new BufferedReader(new InputStreamReader(System.in))){
        // input
        int N = Integer.parseInt(br.readLine());
        String[] permutation = br.readLine().split(" ");

        // algorithm
        int min = 0;
        int result = 0;
        int tmp = 0;

        for(int i = 0; i < N; i++){
          tmp = Integer.parseInt(permutation[i]);
          
          if(i == 0){
            min = tmp;
            result++;
          }else{
            if(min >= tmp){
              result++;
              min = tmp;
            }else{
              continue;  
            }
          }

        }

        System.out.println(result);
      }
    }
}

Measured memory_bytes: 49876
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <numeric>
#include <map>
#include <iomanip>
#include <bitset>

using namespace std;    
typedef long long ll;
typedef pair<ll, ll> pll;
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
const bool DEBAG = true;


int main(){

    bool isPrime[100001];
    for(int i = 0; i <= 100000; i++){
        isPrime[i] = true;
    }

    isPrime[0] = false;
    isPrime[1] = false;

    for(int i = 2; i <= 1000; i++){
        if( isPrime[i] ){
            for(int j = (2 * i) ; j <= 100000; j+=i ){
                isPrime[j] = false;
            }
        }
    }

    ll primeTable[100001] = {0};
    for(int i = 1; i <= 100000; i++){
        primeTable[i] = primeTable[i-1];
        if(isPrime[i] && isPrime[(i+1) / 2]) primeTable[i] ++;
    }

    ll Q, left, right;
    cin >> Q;
    for(int i = 0; i < Q; i++){
        cin >> left >> right;

        cout << primeTable[right] - primeTable[left - 1] << endl;
    }


}

Measured memory_bytes: 1536
H, N = map(int, input().split())

A = []
B = []

for n in range(N):
  a, b = map(int, input().split())
  A.append(a)
  B.append(b)
  
INF = float('inf')
dp = [INF] * (H + max(A))
dp[0] = 0
# dp[i]を、HP iを減らすために必要な最小の魔力とする

for hp in range(1, H+1):
  for n in range(N):
      dp[hp] = min(dp[max(hp-A[n],0)] + B[n], dp[hp])

print(dp[H])

Measured memory_bytes: 74128
#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

int n;
vector<int> d;

void scan()
{
    cin >> n;
    int t;
    for(auto i = 0; i != n; ++i){
        cin >> t;
        d.push_back(t);
    }
}

int main()
{
    scan();
    int sum = 0;
    for(auto i = 0; i != n-1; ++i){
        for(auto j = i + 1; j != n; ++j){
            sum += d[i] * d[j];
        }
    }
    cout << sum << endl;
}



Measured memory_bytes: 256
#ifdef _DEBUG
#include "MyLib.h"
#else
#define main_C main
#include "bits/stdc++.h"
#include <regex>
#define _USE_MATH_DEFINES
#include <math.h>
#define FOR(i,s,e) for (int i = int(s); i < int(e); ++i)
#define REP(i,e) FOR(i,0,e)
#define INF (INT_MAX/2)
#define EPS (1.0e-8)
#define LINF (LONG_MAX/2)
const int MGN = 8;
const int ARY_SZ_MAX = 10000000;
using namespace std;
using ll = long long; using ull = unsigned long long;
using vi = vector<int>; using vvi = vector<vi>; using vvvi = vector<vvi>;
using vb = vector<bool>; using vvb = vector<vb>; using vvvb = vector<vvb>;
using vl = vector<ll>; using vvl = vector<vl>;
using vd = vector<double>; using vs = vector<string>;
using pii = pair<int, int>; using pll = pair<ll, ll>;
using psi = pair<string, int>;
// functions

#endif


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


    string S;  cin >> S;
    int N = S.size();

    int M = 1 << (N - 1);
    vl tm;
    REP(i,M) {
        int p = i;
        int mask = 0x01;
        int l = 0;
        REP(j,N-1) {
            if (p&mask) {
                int r = j;
                tm.push_back(stoll(S.substr(l, r - l + 1)));
                l = r + 1;
            }
            mask <<= 1;
        }
        string t = S.substr(l);
        if (t.size() > 0) tm.push_back(stoll(t));
    }
    
    ll ans = 0;
    for (ll i : tm) ans += i;

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 384