akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;

// definition {{{ 1

// scaning {{{ 2
#define Scd(x) scanf("%d", &x)
#define Scd2(x,y) scanf("%d%d", &x, &y)
#define Scd3(x,y,z) scanf("%d%d%d", &x, &y, &z)

#define Scll(x) scanf("%lld", &x)
#define Scll2(x,y) scanf("%llu%llu", &x, &y)
#define Scll3(x,y,z) scanf("%lld%lld%lld", &x, &y, &z)

#define Scc(c) scanf("%c", &c);
#define Scs(s) scanf("%s", s);
#define Scstr(s) scanf("%s", &s);
// }}} 2

// constants {{{ 2
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
// }}} 2

// systems {{{ 2
#define Repe(x,y,z) for(ll x = z; x < y; x++)
#define Rep(x,y) Repe(x,y,0)
// }}} 2

// output {{{ 2
#define YesNo(a) (a)?printf("Yes\n"):printf("No\n");
// }}} 2

// }}} 1

ll mod = 998244353;

// PowMod( base, index, modulo) return base ** index % modulo {{{
// PowMod = base ** index % mod ( natural numbers )
ll PowMod( ll base, ll index, ll modulo = mod ){
    if( index == 0 ) return 1;
    // O( log(index) )
    if( index % 2 ){
        return base * PowMod(base, index - 1, modulo) % modulo;
    }else{
        ll Phalf = index / 2;
        ll half = PowMod(base, Phalf, modulo);
        return half * half % modulo;
    }
}
// }}}

int main() {

    ll N,A,B;
    Scll3(N,A,B);
    ll K;
    Scll(K);

    vector<ll> f(N+1);
    f[0] = 1;
    vector<ll> rf(N+1);
    rf[0] = 1;

    Rep(i,N){
        f[i+1] = f[i]*(i+1)%mod;
        rf[i+1] = rf[i]*PowMod(i+1,mod-2)%mod;
        // printf ("%lld %lld\n", f[i], rf[i] );
    }

    ll ans = 0;
    ll n = N;
    Rep(i,N+1){
        if( A * i > K ) break;
        if( (K-A*i) % B == 0 ){
            ll b = (K-A*i)/B;
            if( b > N ) continue;
            // N_C_b * ?
            ll plus = f[n];
            plus *= rf[b];
            plus %= mod;
            plus *= rf[n-b];
            plus %= mod;

            plus *= f[n];
            plus %= mod;
            plus *= rf[i];
            plus %= mod;
            plus *= rf[n-i];
            plus %= mod;


            ans += plus;
            ans %= mod;
        }
    }

    printf ("%lld\n", ans );

    return 0;
}



Measured memory_bytes: 4992
// In the name of Allah. Ya ali!
#include<bits/stdc++.h>
#define double long double
#define debug(x)//  cerr << #x << " = " << x << endl
typedef long long ll;
const ll MAX_N = 1000+100;
const ll MOD = 1e9+7;
using namespace std;

int a[MAX_N][MAX_N];
int dis[MAX_N][MAX_N];
int n,m;

void bfs()
{
    vector<pair<int,int>> vc;
    for(int i = 1;i<=n;++i)
    {
        for(int j = 1;j<=m;++j)
        {
            if (a[i][j])
                vc.push_back({i,j});
            else
                dis[i][j] = 1e9;
        }
    }
    for(int i = 0;i<vc.size();++i)
    {
        int u = vc[i].first;
        int v = vc[i].second;
        vector<pair<int,int>> checks;
        if (u-1>0)
            checks.push_back({u-1,v});
        if (v+1<m+1)
            checks.push_back({u,v+1});
        if (v-1>0)
            checks.push_back({u,v-1});
        if (u-1<n+1)
            checks.push_back({u+1,v});
        for(auto x:checks)
        {
            int a = x.first;
            int b = x.second;
            if (dis[a][b]>dis[u][v]+1)
            {
                dis[a][b] = dis[u][v] + 1;
                vc.push_back(x);
            }
        }
    }
}

int main()
{
    cin >> n >> m;
    for(int i = 1;i<=n;++i)
    {
        string s;
        cin >> s;
        for(int j = 1;j<=m;++j)
            a[i][j] = (s[j-1]=='#');
    }
    bfs();
    int ans = 0;
    for(int i = 1;i<=n;++i)
        for(int j = 1;j<=m;++j)
            ans = max(ans,dis[i][j]);
    cout << ans;
    return 0;
}


Measured memory_bytes: 19308
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <queue>
#include <deque>
#include <list>
#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>

using namespace std;


#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repr(i,n) for(int (i)=(n); (i)>=(0); (i)--)
#define SIZE(x) ((int)(x).size())
#define GCD(a, b) int gcd(int a,int b){return b?gcd(b,a%b):a;}
#define QP(a, b) int qp(int a,ll b){int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}
#define pb(a) push_back(a)
#define mp(a,b) make_pair(a,b)
#define all(v) (v).begin(),(v).end()


template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
template<typename A, size_t N, typename T>
void FILL(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

typedef vector<int, int> vint;
typedef pair<int,int> pint;
typedef vector<pint>vpint;
typedef long long ll;

int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const ll INF = 1LL << 60;
const ll MOD = 1000000007LL;


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a, b; cin >> a >> b;
    cout << a * b;
    cout << endl;
    return 0;
}

Measured memory_bytes: 3636
#include <stdio.h>
int main() {
  int A;
  int B;
  scanf("%d\n",&A);
  scanf("%d\n",&B);
  if (A<=12) {
    if (A<6) {
      printf("%d\n",0);
    }else{
      printf("%d\n",B/2 );
    }
  }else{
    printf("%d\n",B);
  }
  return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) (x).begin(),(x).end()
#define MAX_N 10000000
struct UnionFind{
	int par[MAX_N+100];
	void init(){
		for(int i=0;i<MAX_N+5;i++){
			par[i] = i;
		}
	}
	int find(int x){
		if(par[x]==x)return x;
		else return par[x] = find(par[x]);
	}
	void unite(int x,int y){
		x = find(x);
		y = find(y);
		if(x==y)return;
		par[x] = y;
		return;
	}
	bool same(int x,int y){
		return find(x)==find(y);
	}
}uf;
const ll mod = 1000000007ll;

ll mypow(ll x, ll n) {
	if (n == 0ll) return 1ll;
	if (n == 1ll) return x % mod;
	if (n % 2ll == 0ll) {
		return mypow(x * x % mod, n / 2ll);
	} else {
		return mypow(x, n - 1ll) * x % mod;
	}
}
string O,Z;
string rO,rZ;
int N;
bool pali(string s){
	string t = s;
	reverse(all(t));
	return (s==t);
}
bool is_pre(string& s,string& t){
	return (s==t.substr(0,s.size()));
}
string suf(string s,int n){
	return s.substr(s.size()-n);
}
bool check(){
	if(Z.size()>=O.size()){
		if(!is_pre(O,Z))return false;
		if(!pali(suf(Z,Z.size()-O.size())))return false;
	}else{
		if(!is_pre(Z,O))return false;
		if(!pali(suf(O,O.size()-Z.size())))return false;
	}
	return true;
}	
struct node{
	char x;
	int id;
	node(){}
};
node str[MAX_N*2+200100];
char pos[MAX_N+100];
int main(){
	uf.init();
	cin >> Z;
	cin >> O;
	cin >> N;
	rO = O;
	reverse(all(rO));
	rZ = Z;
	reverse(all(rZ));
	if(N<=1000000){
		for(int i=0;i<N;i++){
			pos[i] = '$';
		}
		int offset = 0;
		for(int i=0;i<N;i++){
			str[offset+i].id = i;
		}
		offset += N;
		for(int i=0;i<Z.size();i++){
			str[offset+i].id = -1;
			str[offset+i].x = Z[i];
		}
		offset += Z.size();
		for(int i=0;i<N;i++){
			str[offset+i].id = i;
		}
		offset += N;
		for(int i=0;i<O.size();i++){
			str[offset+i].id = -1;
			str[offset+i].x = O[i];
		}
		offset += O.size();
		for(int i=0;i<offset/2;i++){
			int j = offset-1-i;
			if(str[i].id==-1&&str[j].id==-1){
				if(str[i].x!=str[j].x){
					cout << 0 << endl;
					return 0;
				}
			}else if(str[i].id==-1){
				int id = str[j].id;
				id = uf.find(id);
				if(pos[id]=='$'){
					pos[id] = str[i].x;
				}else{
					if(str[i].x!=pos[id]){
						cout << 0 << endl;
						return 0;
					}
				}
			}else if(str[j].id==-1){
				int id = str[i].id;
				id = uf.find(id);
				if(pos[id]=='$'){
					pos[id] = str[j].x;
				}else{
					if(str[j].x!=pos[id]){
						cout << 0 << endl;
						return 0;
					}
				}
			}else{
				int I = str[i].id;
				int J = str[j].id;
				I = uf.find(I);
				J = uf.find(J);
				if(pos[I]=='$'||pos[J]=='$'){
					if(pos[I]!='$')pos[J]=pos[I];
					if(pos[J]!='$')pos[I]=pos[J];
					uf.unite(I,J);
				}else{
					if(pos[I]!=pos[J]){
						cout << 0 << endl;
						return 0;
					}
					uf.unite(I,J);
				}
			}
		}
		ll ans = 1ll;
		for(int i=0;i<N;i++){
			if(uf.find(i)!=i)continue;
			if(pos[i]=='$'){
				ans = (ans*26ll)%mod;
			}
		}
		cout << ans << endl;
	}else{
		if(!check()){
			cout << 0 << endl;
			return 0;
		}
		if(Z.size()>=O.size()){
			cout << mypow(26ll,(N-O.size()+1)/2) << endl;
		}else{
			cout << mypow(26ll,(N-O.size()+1)/2) << endl;
		}
	}
	return 0;
}


Measured memory_bytes: 45716
#平安京
#http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=2186&lang=jp
#AOJでは、numpyは、使えなかった。
#当初、行と列の設定を間違えて大変なことになった。どっちがx、どっちがyが普通なんですかね。縦をyにすると添字はyxの順番になってしまう。
#バーチャルマタタビを置いたのが勉強になった。もっとも、行列を結合しようとして、「なぜか」うまくいかなかった。

#import numpy as np
n = int(input())
for i in range (n):
  gx,gy = map(int,input().split())
  m = int(input())
  #Vert = np.concatenate([np.full((gx+1,1),False),np.full((gx+1,gy),True)])
  #Horiz = np.concatenate([np.full((1,gy+1),False),np.full((gx,gy+1),True)],1)
  Vert = [[True]*(gx+1) for i in range(gy+1)]
  #print(Vert)
  Horiz = [[True]*(gx+1) for i in range(gy+1)]
  #print(Horiz)
  for k in range(gx+1):
    #Vert[k][0] = False
    Vert[0][k] = False
    #print(Vert)
  for l in range(gy+1):
    #Horiz[0][l] = False
    Horiz[l][0] = False
    #print(Horiz)
  for j in range(m):
    x1,y1,x2,y2 = map(int,input().split())
    if x1 == x2:
      Vert[max(y1,y2)][x1] = False
    else:
      Horiz[y1][max(x1,x2)] = False
  dp = [[0]*(gx+1) for i in range(gy+2)]
  dp[0][0] = 1
  for k in range(gx+1):
    for l in range(gy+1):
      if Vert[l][k]:
        dp[l][k] += dp[l-1][k]
      if Horiz[l][k]:
        dp[l][k] += dp[l][k-1]
  if dp[gy][gx] == 0:
    print("Miserable Hokusai!")
  else:
    print(dp[gy][gx])


Measured memory_bytes: 5624
#include <bits/stdc++.h>
typedef long long ll;
#define fr first
#define sc second
#define int ll

using namespace std;
const int MN = 55+7;
const int MOD = 1e9+7;

int k, n, a[MN][MN], dp[MN][MN][MN], ans[MN][MN];


signed main(){
    cin >> n >> k;
    for(int i = 0; i < n; i++){
        for(int j = 0; j < n; j++){
            cin >> a[i][j];
            if(a[i][j])dp[i][j][0]++;
        }
    }
    int z = 0, f = 0;
    for(int i = 0; i < n; i++){
        ans[i][0] = 1;
    }
    while(k){
        if(k & 1){
            for(int i = 0; i < n; i++){
                for(int j = 0; j < n; j++){
                    ans[i][f+1] = (ans[j][f] * dp[j][i][z] % MOD + ans[i][f+1]) % MOD;
                }
            }
            f++;
        }
        for(int i = 0; i < n; i++){
            for(int j = 0; j < n; j++){
                dp[i][j][z+1] = 0;
                for(int l = 0; l < n; l++){
                    dp[i][j][z+1] = (dp[i][j][z+1] + dp[i][l][z] * dp[l][j][z] % MOD) % MOD;
                }
            }
        }
        z++;
        k >>= 1;
    }
    ll re = 0;
    for(int i = 0; i < n; i++){
        re = (re + ans[i][f]) % MOD;
    }
    cout << re;
}


Measured memory_bytes: 1664
#pragma GCC optimize("Ofast,O3,unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma")

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <functional>
using namespace __gnu_pbds;
using namespace std;

#define endl '\n'
#define hoise cerr<<"hoise - "<<__LINE__<<"\n";
#define tham getchar();
#define FASTIO ios::sync_with_stdio(false);cin.tie(nullptr);

using ll = long long;
using ii = pair <int, int>;
using vi = vector <int>;
using vl = vector <ll>;

const int MXN = (int)2e5+6;
const double PI = acos(-1.0);
const ll mod = 1e9 + 7;

#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
    cerr << *it << " = " << a << endl;
    err(++it, args...);
}

inline int Set(int N, int pos){return N=N | (1<<pos);}
inline int Reset(int N, int pos){return N=N & ~(1<<pos);}
inline bool Check(ll N, ll pos){return (bool)(N & (1LL<<pos));}

inline void normal(ll &a) { a %= mod; (a < 0) && (a += mod); }
inline ll modMul(ll a, ll b) { a %= mod, b %= mod; normal(a), normal(b); return (a * b) % mod; }
inline ll modAdd(ll a, ll b) { a %= mod, b %= mod; normal(a), normal(b); return (a + b) % mod; }
inline ll modSub(ll a, ll b) { a %= mod, b %= mod; normal(a), normal(b); a -= b; normal(a); return a; }
inline ll modPow(ll b, ll p) { ll r = 1; while (p) { if (p & 1) r = modMul(r, b); b = modMul(b, b); p >>= 1; } return r; }
inline ll modInverse(ll a) { return modPow(a, mod - 2); }
inline ll modDiv(ll a, ll b) { return modMul(a, modInverse(b)); }


template <typename T> using orderedSet = tree<T, null_type, greater<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <typename T> using orderedSet1 = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
/*--------------------------------------------------------------------------------------------------------------------------*/




int main(){
	FASTIO
	int a, b, c, d;
	cin >> a >> b >> c >> d;
	int x = (c + b - 1) / b;
	int y = (a + d - 1) / d;
	if (x <= y) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
	
    return 0;
}

/*

*/


Measured memory_bytes: 3652
a, b, c = gets.split(" ").map(&:to_i)
k = gets.to_i
if c > b && b > a
    puts "Yes"
    exit
end
array = [a, b, c]
i = 0
while i < k  
  if c <= a
    c = c * 2
    array = [a, b, c]
  elsif c <= b
    c = c * 2
    array = [a, b, c]
  elsif c > b && b <= a
    b = b * 2
    array = [a, b, c]
  end
  if c > b && b > a
    puts "Yes"
    exit
  end
  i += 1
end

puts "No"

Measured memory_bytes: 14236
#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
	int n;
	cin >> n;
	int sum = 1;
	string* a = new string[n+1];
	for (int i = 1;i <= n;i++)
	{
		cin >> a[i];
	}
	sort(a, a + n + 1);
	string temp = a[1];
	for (int i = 1;i <= n;i++)
	{
		if (temp != a[i]) sum++;
		temp = a[i];
	}
	cout << sum << endl;
}

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

#define PI 3.14159265358979323846264338327950288419

using namespace std;

const long long NINF = -(1LL << 60);
long long dp[200005][3];
int n;
int a[200005];

int main(){
	scanf("%d", &n);
	for(int i = 1; i <= n; i++){
		scanf("%d", &a[i]);
	}
	for(int i = 0; i <= n; i++){
		for(int j = 0; j <= 2; j++){
			dp[i][j] = NINF;
		}
	}
	dp[0][1] = 0;
	dp[1][0] = a[1];
	for(int i = 2; i <= n; i++){
		for(int j = 0; j <= 2; j++){
			for(int k = 0; k <= j; k++){
				if(i - k - 2 >= 0){
					dp[i][j] = max(dp[i][j], dp[i - k - 2][j - k] + a[i]);
				}
			}
		}
	}
	
	long long ans = NINF;
	
	int margin;
	if(n & 1) margin = 2;
	else margin = 1;
	
	for(int i = 0; i <= margin; i++){
		ans = max(ans, dp[n - i][margin - i]);
	}
	printf("%lld\n", ans);
	
	return 0;
}

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

using namespace std;
using ll = long long;
#define int ll
using VI = vector<int>;
using VVI = vector<VI>;
using PII = pair<int, int>;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define PB push_back

const ll LLINF = (1LL<<60);
const int INF = (1LL<<30);
const int MOD = 1000000007;

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template <typename T> bool IN(T a, T b, T x) { return a<=x&&x<b; }
template<typename T> T ceil(T a, T b) { return a/b + !!(a%b); }
template<class S,class T>
ostream &operator <<(ostream& out,const pair<S,T>& a){
  out<<'('<<a.first<<','<<a.second<<')';
  return out;
}
template<class T>
ostream &operator <<(ostream& out,const vector<T>& a){
  out<<'[';
  REP(i, a.size()) {out<<a[i];if(i!=a.size()-1)out<<',';}
  out<<']';
  return out;
}

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

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

  int n, c;
  cin >> n >> c;
  VI x(n), v(n);
  REP(i, n) cin >> x[i] >> v[i];

  VI dp1(n);
  dp1[0] = v[0] - x[0];
  FOR(i, 1, n) dp1[i] = dp1[i-1] + v[i] - (x[i] - x[i-1]);
  FOR(i, 1, n) chmax(dp1[i], dp1[i-1]);

  VI dp2(n);
  dp2[n-1] = v[n-1] - (c - x[n-1]);
  for(int i=n-2; i>=0; --i) {
    dp2[i] = dp2[i+1] + v[i] - (x[i+1] - x[i]);
  }
  for(int i=n-2; i>=0; --i) {
    dp2[i] = max(dp2[i], dp2[i+1]);
  }

  int ans = max(0LL, dp2[0]);
  REP(i, n) {
    // i番目まで時計回りで取る
    int tmp = dp1[i];
    // [i+1, n-1] の最大
    if(i+1<n && dp2[i+1] - x[i] > 0) tmp += dp2[i+1] - x[i];
    chmax(ans, tmp);
  }
  for(int i=n-1; i>=0; --i) {
    int tmp = dp2[i];
    if(i >= 1 && dp1[i-1] - (c - x[i]) > 0 ) tmp += dp1[i-1] - (c - x[i]);
    chmax(ans, tmp);
  }
  cout << ans << endl;

  return 0;
}

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

int main() {
  int a,b,c;
  cin >> a >> b >> c;
  if(c<a){
    cout << "No" << endl;
  }else if(b<c){
    cout << "No" << endl;
  }else{
    cout << "Yes" << endl;
  }
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

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

    for (int i = 0; i < S.length(); i++) {
      char c= S.charAt(i);
      if( (i+1)%2 ==0){
        if(c != 'L' && c!='U' && c!='D'){
          System.out.println("No");
          return;
        }
      }else{
        if(c != 'R' && c!='U' && c!='D'){
          System.out.println("No");
          return;
        }
      }
    }
    System.out.println("Yes");
    }

}


Measured memory_bytes: 22100
import sys
readline = sys.stdin.readline
N, M = map(int, readline().split())
H = list(map(int, readline().split()))
Edge = [[] for _ in range(N)]
table = [1]*N
for _ in range(M):
    a, b = map(int, readline().split())
    a -= 1
    b -= 1
    if H[a] == H[b]:
        table[a] = 0
        table[b] = 0
    elif H[a] > H[b]:
        table[b] = 0
    else:
        table[a] = 0
print(sum(table))

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

using namespace std;

typedef long long int ll;
typedef pair<ll, ll> pll;

#define FOR(i, n, m) for(ll (i)=(m);(i)<(n);++(i))
#define REP(i, n) FOR(i,n,0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll) 1e15;

ll A[200005];
ll B[1000005];

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

    memset(B, 0, sizeof(B));
    REP(i, N) {
        cin >> A[i];
        B[A[i]]++;
    }

    ll ans = N;
    REP(i, N) {
        if (B[A[i]] > 1) {
            ans--;
            continue;
        }

        ll n = 1;
        while (n * n <= A[i]) {
            bool e = false;
            if (A[i] % n == 0) {
                ll x = n;
                ll y = A[i] / n;
                if (B[x] > 0 && A[i] != x)
                    e = true;
                if (B[y] > 0 && y != A[i])
                    e = true;
            }

            if (e) {
                ans--;
                break;
            }
            n++;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 13028
#include<bits/stdc++.h>
using namespace std;
#ifndef ONLINE_JUDGE
#define dbg(x...) do { cout << "\033[32;1m " << #x << " -> "; err(x); } while (0)
void err() { cout << "\033[39;0m" << endl; }
template<template<typename...> class T, typename t, typename... A>
void err(T<t> a, A... x) { for (auto v: a) cout << v << ' '; err(x...); }
template<typename T, typename... A>
void err(T a, A... x) { cout << a << ' '; err(x...); }
#else
#define dbg(...)
#endif
typedef long long ll;
typedef pair<int,int> pi;
typedef vector<int> vi;
template<class T> using vc=vector<T>;
template<class T> using vvc=vc<vc<T>>;
template<class T> void mkuni(vector<T>&v)
{
    sort(v.begin(),v.end());
    v.erase(unique(v.begin(),v.end()),v.end());
}
template<class T>
void print(T x,int suc=1)
{
    cout<<x;
    if(suc==1) cout<<'\n';
    else cout<<' ';
}
template<class T>
void print(const vector<T>&v,int suc=1)
{
    for(int i=0;i<v.size();i++)
    print(v[i],i==(int)(v.size())-1?suc:2);
}
const int maxn=1e5+7;
bool vis[maxn];
int main()
{
    string s;
    cin>>s;
    vi a((int)s.length());
    a[0]=s[0]=='1';
    for(int i=1;i<s.length();i++)
        a[i]=s[i]!=s[i-1];
    //dbg(a);
    int ans=s.length();
    for(int i=0;i<s.length();i++)
    {
        if(a[i]==0) continue;
        ans=min(ans,max(i,(int)s.length()-i));
    }
    print(ans);
}

Measured memory_bytes: 896
import java.util.Scanner;
public class Main {
    public static void main(String[] args){
    
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int m = sc.nextInt();
   
    int a = 0;
    for(int i=1; i<n; i++) {
    	a += i;
    }
    int b = 0;
    for(int i=1; i<m; i++) {
    	b += i;
    }
    	System.out.println(a+b);
   }
}


Measured memory_bytes: 35820
#include<bits/stdc++.h>
using namespace std;
int main(){
	int N,D;
	cin >> N >> D;
	int ans = N/(2*D+1);
	if(N%((2*D+1))){
		cout << ans+1 << endl;
	}else{
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
#define rep(i, s, n) for (int i = (int)(s); i < (int)(n); i++)

int main() {
  int N;
  string S;
  cin >> N >> S;
  
  long int r = 0, g = 0, b = 0;
  rep(i, 0, N) {
    if(S[i] == 'R') {
      r++;
    }
    else if(S[i] == 'G') {
      g++;
    }
    else if(S[i] == 'B') {
      b++;
    }
  }
  
  long int ans = r * g * b;
  long int sub = 0;
  
  rep(i, 0, N) {
    rep(j, i+1, N) {
      if(S[i] == S[j]) {
        continue;
      }
      int k = 2 * j - i;
      if(k >= N || S[i] == S[k] || S[j] == S[k]) {
        continue;
      }
      sub++;
    }
  }
  ans = ans - sub;
  cout << ans << endl;
}

Measured memory_bytes: 3608
n,k=map(int,input().split())
xy=[list(map(int,input().split())) for _ in range(n)]
x=[xy[i][0] for i in range(n)]
y=[xy[i][1] for i in range(n)]
res = 10**20
for i in range(n):
    xl = xy[i][0]
    for j in range(n):
        xr = xy[j][0]
        if xr<xl:continue
        for p in range(n):
            yl = xy[p][1]
            for q in range(n):
                yr = xy[q][1]
                if yr<yl:continue
                tres = 0
                for sxy in xy:
                    if sxy[0] >= xl and sxy[0] <= xr and sxy[1] >= yl and sxy[1] <= yr:
                        tres += 1
                if tres >= k:
                    res = min(res,(xr-xl)*(yr-yl))
print(res)

Measured memory_bytes: 50012
#include <iostream>

using namespace std;

int gcd(int a, int b){
  return b ? (gcd(b, a%b)): a;
}

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

  a--;
  long long int max_divisor = c * d / gcd(c, d);

  cout << b - a - (b/c + b/d - b/max_divisor - (a/c + a/d - a/max_divisor));
}

Measured memory_bytes: 256
N=int(input())
p=list(map(int,input().split()))
ans = "YES"
for i in range(N-1):
    if p[i] > p[i+1]:
        ans ="NO"
        break

if ans != "YES":
    for i in range(N-1):
        for j in range(i+1,N):
            pcopy = p.copy()
            pcopy[i],pcopy[j] = pcopy[j],pcopy[i]
            flg = True
            for k in range(N-1):
                if pcopy[k] > pcopy[k+1]:
                    flg = False
            if flg:
                ans ="YES"
                break        

print(ans)

Measured memory_bytes: 3064
N=int(input())
for n in range(N):
    gx,gy=map(int,input().split())
    T=[[0 for i in range(gy+1)] for j in range(gx+1)]
    left=[[0 for i in range(gy+1)] for j in range(gx+1)]
    upper=[[0 for i in range(gy+1)] for j in range(gx+1)]
    p=int(input())
    for i in range(p):       
        x1,y1,x2,y2=map(int,input().split())
        if x1==x2:
            upper[x1][max(y1,y2)]=1
        if y1==y2:
            left[max(x1,x2)][y1]=1

    for i in range(gx+1):
        for j in range(gy+1):
            if i==0:
                left[i][j]=1
            if j==0:
                upper[i][j]=1
    for i in range(gx+1):
        for j in range(gy+1):
            if i==0 and j==0:
                T[i][j]=1
            else:  
                if left[i][j]==1 and upper[i][j]==1:
                    T[i][j]=0
                elif left[i][j]==0 and upper[i][j]==1:
                    T[i][j]=T[i-1][j]
                elif left[i][j]==1 and upper[i][j]==0:
                    T[i][j]=T[i][j-1]
                else:
                    T[i][j]=T[i-1][j]+T[i][j-1]

    if T[gx][gy]==0:
        print("Miserable Hokusai!")
    else:
        print(T[gx][gy])


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

#define rep(i, N) for (ll i = 0; i < N; i++)
#define rep1(i, N) for (ll i = 1; i <= N; i++)
#define repr(i, N) for (ll i = N-1; i >= 0; i--)
#define repr1(i, N) for (ll i = N; i > 0; i--)

#define INF (int)1e9+7

using ll = long long;
using namespace std;

typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<P> vpi;
typedef pair<ll,ll> Pl;
typedef vector<ll> vl;
typedef vector<Pl> vpl;

ll gcd(ll a, ll b){
    if(a < b) swap(a, b);
    if(b <= 0) return -1;
    ll r = a % b;
    while(r != 0){
        a = b;
        b = r;
        r = a % b;
    }
    return b;
}

ll lcm(ll a, ll b){
    return (a/gcd(a,b)*b);
}

int main() {
    string S, T;
    cin >> S >> T;

    reverse(S.begin(), S.end());
    reverse(T.begin(), T.end());

    bool flag = true;
    if(S.size() < T.size()) {
        flag = false;
    } else {
        for(int index = 0; index < S.size() - T.size() +1; index++) {
            if(S[index] != '?' && S[index] != T[0]) continue;
            flag = true;
            rep(i, T.size()){
                if(S[index+i] != '?' && S[index+i] != T[i]) {
                    flag = false;
                    break;
                }
            }
            if(flag) {
                rep(i, T.size()){
                    S[index+i] = T[i];
                }
                break;
            }
        }

        rep(i, S.size()) {
            if(S[i] == '?') S[i] = 'a';
        }
        reverse(S.begin(), S.end());
    }
    
    string ans = ( flag ? S : "UNRESTORABLE" );
    //printf("%.8lf\n", ans);
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main()
{
  int n;
  scanf("%d",&n);
  char s[n+1];
  scanf("%s",s);
  int a=0;

  for(int i=0;i<n;i++){
    if(s[i]=='A'){
      if(s[i+1]=='B' && s[i+2]=='C') a=a+1;
    }
  }
  printf("%d\n",a);
  return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define pb push_back
typedef long long ll;
const ll N=500;
using namespace std;
int a[N][N];
vector<int> answer;
int main()
{
    int h,w;
    cin>>h>>w;
    for (int i=0; i<h; i++)
        for (int j=0; j<w; j++)
            cin>>a[i][j];
    for (int i=0; i<h; i++)
        for (int j=0; j<w; j++)
        {
            if (a[i][j]%2==1)
            {
                if (i+1<h && a[i+1][j]%2==1)
                {
                    a[i+1][j]++;
                    answer.pb(i+1);
                    answer.pb(j+1);
                    answer.pb(i+2);
                    answer.pb(j+1);
                    continue;
                }
                if (j+1<w && a[i][j+1]%2==1)
                {
                    a[i][j+1]++;
                    answer.pb(i+1);
                    answer.pb(j+1);
                    answer.pb(i+1);
                    answer.pb(j+2);
                    continue;
                }
                if (i+1<h)
                {
                    a[i+1][j]++;
                    answer.pb(i+1);
                    answer.pb(j+1);
                    answer.pb(i+2);
                    answer.pb(j+1);
                    continue;
                }
                if (j+1<w)
                {
                    a[i][j+1]++;
                    answer.pb(i+1);
                    answer.pb(j+1);
                    answer.pb(i+1);
                    answer.pb(j+2);
                    continue;
                }
            }
        }
    cout<<answer.size()/4<<endl;
    for (int i=0; i<answer.size(); i+=4)
    {
        cout<<answer[i]<<" "<<answer[i+1]<<" "<<answer[i+2]<<" "<<answer[i+3]<<endl;
    }
}

Measured memory_bytes: 5104
/******************************************
* AUTHOR : Lokesh goel*
* NICK : InsaneNerd *
* INSTITUTION : NIT Kurukshetra *
******************************************/
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define MAX 1000000000
#define N 100005
#define pii pair<int,int>
#define vp vector<pair<int,int > >
#define mod 1000000007
#define pb push_back
#define mp make_pair
#define gsz(x) ((int)(x).size())
#define F first
#define S second
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);cerr.tie(NULL);
#define endl "\n"
#define ms(x,v) memset(x,v,sizeof(x))

int main()
{
	fastio;
	int n,a[200001],i,j,k;
	cin>>n;
	for(i=0;i<n;i++){
		cin>>a[i];
	}
	sort(a,a+n);
	ll sum=0;
	priority_queue<int>pq;
	pq.push(a[n-1]);
	for(i=n-2;i>=0;i--){
		int curr = pq.top();
		pq.pop();
		sum+=curr;
		pq.push(a[i]);
		pq.push(a[i]);
	}
	cout<<sum<<endl;


	return 0;
}

Measured memory_bytes: 5060
#include <bits/stdc++.h>
using namespace std;
#define rep0(i, n) for (long long i = 0; i < (long long)(n); i++)
#define rep1(i,n) for(long long i=1;i<=(long long)(n);i++)
#define all(v) v.begin(),v.end()
typedef long long ll;

vector<ll> primevector(ll N){
    vector<ll> data(1);
    data[0]=2;
//素数を追加していく
    for(ll i=3;i<N;i++){
        ll cnt=0;
        for(ll j=0;j<data.size();j++){
            if(i%data[j]==0){cnt++;break;}
        }
        if(cnt==0){data.push_back(i);}
    }
    return data;
}

int main() {
  ll X;
  cin>>X;
  vector<ll> prime;
  prime=primevector(X);
  bool flag=true; 
  while(flag){
    if(X==2){break;}
    flag=false;
    rep0(i,prime.size()){if(X%prime[i]!=0){flag=true;} else{flag=false; break;}}
    if(flag){break;}
    if(1-flag){X++; flag=true;}
  }
  cout<<X<<endl;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define R cin>>
#define Z class
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
template<Z A>void pr(A a){cout<<a;ln;}
template<Z A,Z B>void pr(A a,B b){cout<<a<<' ';pr(b);}
template<Z A,Z B,Z C>void pr(A a,B b,C c){cout<<a<<' ';pr(b,c);}
template<Z A,Z B,Z C,Z D>void pr(A a,B b,C c,D d){cout<<a<<' ';pr(b,c,d);}
template<Z A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}
const ll MAX=1000000007,MAXL=1LL<<61,dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
typedef pair<int,int> P;
 
void Main() {
  int n,m;
  cin >> n >> m;
  pr((m*1900+(n-m)*100)*(1<<m));
}
 
int main(){ios::sync_with_stdio(0);cin.tie(0);Main();return 0;}

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

#define F first
#define S second
#define pb push_back
#define sz(x) (int)x.size()
#define all(x) (x).begin(), (x).end()

#define rep(i,n) for(int i=0;i<n;++i)
#define Rep(i,a,n) for(int i=a;i<=n;++i)
#define Speed() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define mset multiset
#define pqueue priority_queue
#define umap unordered_map
 
using namespace std;

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

const double PI=acos(-1),eps=1e-9;
const int dx[]={-1,1,0,0},dy[]={0,0,-1,1};
const int N=3e5+5,mod=1e9+7,inf=1e9;

void solve(){
	int a,b,c;
	cin>>a>>b>>c;
	cout<<min(a*b,c);
}

int main(){
	Speed();
	int T=1;
	//cin>>T;
	while(T--)solve();
}



Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
int c[100010][3];
long long dp[100010][3];
int main()
{
	int n;
	cin>>n;
	for(int i=1;i<=n;i++)
	   cin>>c[i][0]>>c[i][1]>>c[i][2];
	for(int i=0;i<n;i++){
		for(int j=0;j<3;j++)
		   for(int k=0;k<3;k++){
		   	  if(j!=k){
		   	  	dp[i+1][k]=max(dp[i+1][k],dp[i][j]+c[i+1][k]);
		   	  }
		   }
	}
	cout<<max(dp[n][0],max(dp[n][1],dp[n][2]));
	return 0;
}


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

int main(void){
	int n;
	int a[500000];
	cin>>n;
	for(int i=0;i<n;i++)cin>>a[i];
	make_heap(a,a+n);
	for(int i=0;i<n;i++){
		cout<<" "<<a[i];
	}
	cout<<endl;
	return 0;
}

Measured memory_bytes: 4968
//encoding:utf-8
//#include <iostream> //c++
//#include<stack> //スタックに関して　最新のデータから捨てる
//#include<queue> //キューに関して　最古のデータから捨てる
//#include<math.h>
//#include<vector>
//#include<algorithm> //sort とかにいる
#include<bits/stdc++.h>//vector,algorithm,que
#include<time.h> //時間にかんして

#define ll long long
#define MOD 1000000007
using namespace std;
int main(){
  int a,b,c;
  cin>>a>>b>>c;
  int ans;
  if(a==b){
    ans = c;
  }
  else if(a==c){
    ans = b;
  }
  else{
    ans = a;
  }
  cout<<ans<<endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

int main(){
    long long N, K, BK;

    cin >> N >> K;
    const long long MN = 1000000007;
    long long inv2 = modinv (2, MN);

    K = K % MN;
    if ( K > 0 ){
        BK = K - 1;
    }
    else
    {
        BK = MN - 1;
    }
    

    vector<int> A(N);
    for ( int i = 0; i < N; i++ ) cin >> A.at(i);


    long long ans = 0LL;
    long long ans1, ans2;

    // K = 1での転倒

    ans1 = 0LL;

    for ( int i = 0; i < N - 1; i++ ){
        for ( int j = i + 1; j < N; j++ ){
            if ( A.at(i) > A.at(j) ){
                ans1++;
            }
        }
    }
	

    ans1 = ( ans1 * K ) % MN;


    // K > 2での転倒

    ans2 = 0LL; 

    for ( int i = 0; i < N; i++ ){
        for ( int j = 0; j < N; j++ ){
            if ( A.at(i) > A.at(j) ){
                ans2++;
            }
        }
    }

    BK = ( ( K * BK ) % MN ) * inv2;
    BK %= MN;

    ans2 = ans2 * BK;
    ans2 = ans2 % MN;

    ans =  (ans1 + ans2) % MN;

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(void)
{
char a[11], b[11], c[11];
int i;

scanf("%s %s %s", a, b, c);

for(i=0; a[i+1] != '\0'; i++);
if(a[i] == b[0]){
for(i=0; b[i+1] != '\0'; i++);
if(b[i] == c[0]){
printf("YES\n");
}else{
printf("NO\n");
}
}else{
printf("NO\n");
}

return 0;
}

Measured memory_bytes: 128
#include <algorithm>
#include <array>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <limits>
#include <set>
#include <string>
#include <utility>

using namespace std;

int main() {
  int animal_num, foot_num;

  cin >> animal_num >> foot_num;

  int max_turtle_num = foot_num / 4;

  for (int turtle_num = max_turtle_num; turtle_num >= 0; turtle_num--) {
    int remain_foot_num = foot_num - turtle_num * 4;

    if (remain_foot_num >= 0 && remain_foot_num % 2 == 0 &&
        remain_foot_num / 2 + turtle_num == animal_num) {
      cout << "Yes" << endl;
      return 0;
    }
  }

  cout << "No" << endl;

  return 0;
}


Measured memory_bytes: 3132
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        RainFlowsintoDams solver = new RainFlowsintoDams();
        solver.solve(1, in, out);
        out.close();
    }

    static class RainFlowsintoDams {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int n = in.nextInt();
            long[] dams = new long[n];
            for (int i = 0; i < n; i++) {
                dams[i] = 2 * in.nextLong();
            }

            long[] mountains = new long[n];
            mountains[0] = 0;
            for (int j = 1; j < n; j++) {
                mountains[j] = dams[j - 1] - mountains[j - 1];
            }

            mountains[0] = (dams[n - 1] - mountains[n - 1]) / 2;
            for (int j = 1; j < n; j++) {
                mountains[j] = dams[j - 1] - mountains[j - 1];
            }
            for (int k = 0; k < n; k++) {
                out.print(mountains[k] + " ");
            }

        }

    }
}



Measured memory_bytes: 60868
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;


signed main(){
    ios::sync_with_stdio(false);
	cin.tie(0);
    cout << fixed << setprecision(20);

    ll n;
    cin>>n;
    ll ans = 0;
    while(n){
        ans++;
        n/=2;
    }
    cout << ans <<endl;
    
}


Measured memory_bytes: 3188
// greedy

#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>

bool comp(const std::pair<int, int>& a, const std::pair<int, int>& b)
{
    if(a.second == b.second) return a.first > b.first;
    return a.second < b.second;
}

int main()
{
    using namespace std;
    using Pii = pair<int, int>;

    int N;
    cin >> N;
    vector<Pii> ab(N), cd(N);
    for(int i=0; i<N; i++) scanf(" %d %d", &ab[i].first, &ab[i].second);
    for(int i=0; i<N; i++) scanf(" %d %d", &cd[i].first, &cd[i].second);

    sort(ab.begin(), ab.end(), greater<Pii>());
    sort(cd.begin(), cd.end(), comp);
    vector<bool> matched(N, false);
    int ans = 0;
    for(int i=0; i<N; i++){
        for(int j=0; j<N; j++){
            if(!matched[j] && ab[i].first < cd[j].first && ab[i].second < cd[j].second){
                matched[j] = true; ans++; break;
            }
        }
    }
    // cout << "ab" << endl;
    // for(int i=0; i<N; i++) cout << ab[i].first << " " << ab[i].second << endl;
    // cout << "cd" << endl;
    // for(int i=0; i<N; i++) cout << cd[i].first << " " << cd[i].second << endl;

    cout << ans << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
#include<vector>
#include<math.h>
#include<queue>
#include<map>
#include<algorithm>
#include<string.h>
#include<functional>
using namespace std;
int main(){
 long long a,b,v,w,t;
 scanf("%lld%lld %lld%lld %lld",&a,&v,&b,&w,&t);
 
 if(abs(b-a)<=(v-w)*t)
  puts("YES");
 else puts("NO");
  
  
return 0;}


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

#define ull unsigned long long int
#define lli long long int
#define li long int
#define ld long double
#define ft first
#define sc second

#define mp make_pair
#define pb push_back

#define si(n) scanf("%d",&n)
#define sl(n) scanf("%ld",&n)
#define sll(n) scanf("%lld",&n)
#define pi(n) printf("%d",n)
#define pl(n) printf("%ld",n)
#define pll(n) printf("%lld",n)

using namespace std;
const int MAX = 1e5+5;
const int64_t MOD = 1e9+7;

int64_t cnt[26];

int main() {
	// freopen("a.in","r",stdin);
    // freopen("a.out","w",stdout);
    int N; cin >> N;
    string S; cin >> S;

    for(int i=0; i<N; i++) {
    	cnt[S[i]-'a']++;
    }

    int64_t ans = 1;

    for(int i=0; i<26; i++) {
    		ans = (ans * (1+cnt[i])) % MOD;
    }

    if(ans == 0) {
    	ans = MOD-1;
    }
    else {
    	ans -= 1;
    }
    cout << ans << "\n";
    

	return 0;
}

Measured memory_bytes: 512
using System;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using Debug = System.Diagnostics.Debug;
using static System.Math;
using System.Runtime.CompilerServices;
using MethodImplOptions = System.Runtime.CompilerServices.MethodImplOptions;
using MethodImplAttribute = System.Runtime.CompilerServices.MethodImplAttribute;

static class P
{
    static void Main()
    {
        string s = Console.ReadLine();
        string t = Console.ReadLine();
        int[][] nextInds = Enumerable.Repeat(0, s.Length).Select(_ => Enumerable.Repeat(-1, 26).ToArray()).ToArray();
        for (int i = 0; i < 26; i++)
        {
            var targetChar = (char)('a' + i);
            int lastInd = -1;
            for (int j = s.Length - 1; j >= 0; j--)
            {
                nextInds[j][i] = lastInd;
                if (s[j] == targetChar) lastInd = j;
            }
            for (int j = s.Length - 1; j >= 0; j--)
            {
                if (nextInds[j][i] != -1) break;
                nextInds[j][i] = lastInd;
            }
        }
        long sCount = 0;
        int currentInd = s.IndexOf(t[0]);
        if (currentInd == -1)
        {
            Console.WriteLine(-1);
            return;
        }
        foreach (var c in t.Skip(1))
        {
            var nextInd = nextInds[currentInd][c - 'a'];
            if (nextInd == -1)
            {
                Console.WriteLine(-1);
                return;
            }
            if (currentInd >= nextInd) sCount++;
            currentInd = nextInd;
        }
        Console.WriteLine(sCount * s.Length + currentInd + 1);
    }
}


Measured memory_bytes: 37396
using System;
using System.Linq;

// 3.3 ??????????????????
namespace ALDS1_2_A
{
    class Program
    {
        static void Main(string[] args)
        {
            int.Parse(Console.ReadLine());
            var line = Console.ReadLine();
            var array = line.Split(' ').Select(int.Parse).Cast<int>().ToArray();

            int swapCnt = bubbleSort(array);
            // Console.WriteLine(string.Join(" ", array));
            Console.WriteLine(string.Join(" ", array.Select(e => e.ToString()).Cast<string>().ToArray()));
            Console.WriteLine(swapCnt);
        }
        static int bubbleSort(int[] array)
        {
            int swapCnt = 0;
            for (var i = 0; i < array.Length; i++)
            {
                for (var j = array.Length - 1; j > i; j--)
                {
                    if (array[j - 1] > array[j])
                    {
                        int tmp = array[j - 1];
                        array[j - 1] = array[j];
                        array[j] = tmp;
                        swapCnt++;
                    }
                }
            }
            return swapCnt;
        }
    }
}

Measured memory_bytes: 9596
n,k=map(int,input().split())
r,s,p=map(int,input().split())
t=list(input())

commands = ['']*n
score = 0

for i,c in enumerate(t):
    if c=='r':
        command = 'p'
        point = p
    elif c=='p':
        command = 's'
        point = s
    elif c=='s':
        command = 'r'
        point = r
        
    if (i-k>=0) and (commands[i-k]==command):
        command = ''
        point = 0
    
    score += point
    commands[i] = command

print(score)

Measured memory_bytes: 50512
#include <stdio.h>

int main(void){
    int i,j;
    int shu[3],mai[3];
    for(i = 0;i <4;i++){
        scanf("%d%d",&shu[i],&mai[i]);
        switch(shu[i]) {
            case 1:printf("%d\n",6000*mai[i]);break;
            case 2:printf("%d\n",4000*mai[i]);break;
            case 3:printf("%d\n",3000*mai[i]);break;
            case 4:printf("%d\n",2000*mai[i]);break;
        }
    }

    return 0;
}

Measured memory_bytes: 600
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ld long double
#define al(a) (a).begin(),(a).end()
#define mk make_pair
#define check cout<<"?"<<endl;

ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;

vector<int> v;

void init_uf(int n){
    v.assign(n,-1);
}

int find_(int x){
    if(v[x]<0) return x;
    v[x]=find_(v[x]);
    return v[x];
}

int same_(int a,int b){
    if(find_(a)==find_(b)) return 1;
    return 0;
}

void union_(int a,int b){
    if(same_(a,b)) return;
    int a_p=find_(a),b_p=find_(b);
    if(a_p>b_p) swap(a_p,b_p);
    v[a_p]+=v[b_p]; v[b_p]=a_p;
}

int main(){
    ll n; cin>>n;
    init_uf(n);
    vector<pair<ll,ll>> x(n),y(n);
    rep(i,n){
        ll X,Y; cin>>X>>Y;
        x[i]=mk(X,i); y[i]=mk(Y,i);
    }
    sort(al(x)); sort(al(y));
    set<pair<ll,ll>> xt,yt;
    rep(i,n-1){
        xt.insert(mk(x[i+1].first-x[i].first,i));
        yt.insert(mk(y[i+1].first-y[i].first,i));
    }
    ll dx,dy,sx,sy,ans=0;
    while(!(xt.empty()) || !(yt.empty())){
        dx=dy=INF; sx=sy=-1;
        if(!(xt.empty())){
            tie(dx,sx)=*begin(xt);
        }
        if(!(yt.empty())){
            tie(dy,sy)=*begin(yt);
        }
        if(dx<dy){
            if(same_(x[sx].second,x[sx+1].second)==0){
                union_(x[sx].second,x[sx+1].second);
                ans+=dx;
            }
            xt.erase(mk(dx,sx));
        }
        else{
            if(same_(y[sy].second,y[sy+1].second)==0){
                union_(y[sy].second,y[sy+1].second);
                ans+=dy;
            }
            yt.erase(mk(dy,sy));
        }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 19368
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
ll mod=1e9+7;

// function to determine the edge colors 
void colorEdges(int ptr, vector<vector<pair<int, int> > >& gra, 
                vector<int>& edgeColors, bool isVisited[]) 
{ 
    queue<int> q; 
    int c = 0; 
  
    set<int> colored; 
  
    // return if isVisited[ptr] is true 
    if (isVisited[ptr]) 
        return; 
  
    // Mark the current node visited 
    isVisited[ptr] = 1; 
  
    // Traverse all edges of current vertex 
    for (int i = 0; i < gra[ptr].size(); i++) { 
        // if already colored, insert it into the set 
        if (edgeColors[gra[ptr][i].second] != -1) 
            colored.insert(edgeColors[gra[ptr][i].second]); 
    } 
  
    for (int i = 0; i < gra[ptr].size(); i++) { 
        // if not visited, inset into the queue 
        if (!isVisited[gra[ptr][i].first]) 
            q.push(gra[ptr][i].first); 
  
        if (edgeColors[gra[ptr][i].second] == -1) { 
            // if col vector -> negative 
            while (colored.find(c) != colored.end()) 
  
                // increment the color 
                c++; 
  
            // copy it in the vector 
            edgeColors[gra[ptr][i].second] = c; 
  
            // then add it to the set 
            colored.insert(c); 
            c++; 
        } 
    } 
  
    // while queue's not empty 
    while (!q.empty()) { 
        int temp = q.front(); 
        q.pop(); 
  
        colorEdges(temp, gra, edgeColors, isVisited); 
    } 
  
    return; 
} 
  
// Driver Function 
int main() 
{ 
    set<int> empty; 
  
    // declaring vector of vector of pairs, to define Graph 
    vector<vector<pair<int, int> > > gra; 
  
    vector<int> edgeColors; 
  
    bool isVisited[100000] = { 0 }; 
  
    // Enter the Number of Vertices 
    // and the number of edges 
		int N;
 		cin>>N; 

    int ver = N; 
    int edge = N-1; 

    gra.resize(ver); 
    edgeColors.resize(edge, -1); 
  
    // Enter edge & vertices of edge 
    // x--; y--; 
    // Since graph is undirected, push both pairs 
    // (x, y) and (y, x) 
    // graph[x].push_back(make_pair(y, i)); 
    // graph[y].push_back(make_pair(x, i)); 
		for (int i(0);i<N-1;i++){
      int x,y;
      cin>>x>>y;
      x--;
      y--;
      gra[x].push_back(make_pair(y, i)); 
      gra[y].push_back(make_pair(x, i)); 
    }
    colorEdges(0, gra, edgeColors, isVisited); 
  
    // printing all the edge colors 
    int cnt[100001] = {0};
    int ans(0);
    for (int i(0);i<edge;i++){
      if (cnt[edgeColors[i]] ==0){
        ans++;
        cnt[edgeColors[i]] = 1;
      }
    }
    cout << ans << endl;
    for (int i = 0; i < edge; i++) {
        //cout << "Edge " << i + 1 << " is of color "
    //         << edgeColors[i] + 1 << "\n"; 
        cout << edgeColors[i] + 1 << endl; 
    }
    return 0; 
}


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

int main(){

int n,m;
cin >> n >> m;

vector<vector<int>> a(n,vector<int>(m));
  rep(i, n){
    rep(j, m){
      cin >> a.at(i).at(j);
    }
  }
vector<int> b(m);
rep(i, m) cin >> b.at(i);
 
  vector<int> c(n);

for(int i = 0; i < n; i++){
    for (int j = 0; j < m; j++ ){
        c.at(i) += a.at(i).at(j) * b.at(j);
    }
}
    for (int i =0; i < n ; ++i) cout << c.at(i) << endl;
}


Measured memory_bytes: 3204