akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <stdio.h>
#include <tuple>
#include <bitset>
#include <cfloat>
#include <fstream>
#include <limits.h>
#include <list>
#include <math.h>
#include <random>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <numeric>
#include <utility>
#include <sstream>
#define int long long
#define rep(i, n) for (int i = 0; i < (n); i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define FORR(i,a,b)for(int i=(a);i<=(b);i++)
#define repR(i,n) for(int i=n;i>=0;i--)
#define P pair<int, int>
#define sz(x) x.size()
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
#define VE vector<int>
#define COUT(x) cout<<(x)<<endl
#define MA map<int,int>
#define SE set<int>
#define PQ priority_queue<int>
#define PQR priority_queue<int,VE,greater<int>>
#define COUT(x) cout<<(x)<<endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl

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

using namespace std;
typedef long long ll;
ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	if (b == 0) return a;
	return gcd(b, a % b);
}
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}
bool prime(int n) {
	for (int i = 2; i <= sqrt(n); i++) {
		if (n%i == 0)return false;
	}
	return n != 1;
}
bool compare_by_b(pair<int, int> a, pair<int, int> b) {
	if (a.second != b.second) {
		return a.second < b.second;
	}
	else {
		return a.first < b.first;
	}
}

const long long MOD = 1000000007;
const long long INF = 1LL << 50;
// pair -> vector<pair<int,int>> 
//		   AandB.push_back(make_pair(a[i],b[i]))



signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n, m; cin >> n >> m;
	vector<P> p;
	rep(i, m) {
		int a, b; cin >> a >> b;
		p.push_back(make_pair(a, b));
	}
	sort(ALL(p), compare_by_b);
	int now = -1;
	int ans = 0;
	rep(i, m) {
		if (p[i].first > now) {
			ans++; now = p[i].second - 1;
		}
	}
	COUT(ans);
	return 0;
}

Measured memory_bytes: 2420
//Program.cpp
//Author : Aaryan Srivastava 
#include <bits/stdc++.h>
#include <random>
#include <chrono>
#define pb push_back
#define popb pop_back
#define ull unsigned long long  
#define beg begin
#define mp make_pair
#define pii pair<int, int>
#define piii pair<pii,int>
#define rep(i,n) for(int (i) = 0 ; i < (n) ; i++)
#define repA(i,x,y) for(int i = (x) ; i <= (y) ; i++)
#define repD(i,x,y) for(int i = (x) ; i >= (y) ; i--)
#define all(c) (c).begin(),(c).end()
#define ff first
#define ss second 
#define fill(a,val) memset(a,val,sizeof(a))
#define Randomize mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
using ll = long long;
#define int ll
const int N = 1e5 + 5 ;
const int mod = 1e9 + 5 ;
const int inf = 1e18 ;
const int SZ = 101 ;
const double eps = 1e-9 ;
using namespace std;
#ifdef AaryanS
#define mycout cout
#define mycerr cerr 
#endif

#ifndef AaryanS
#define mycout if(false) cout
#define mycerr if(false) cerr
#define AaryanS 0 
#endif

#define debug(x) mycerr << #x << " "  << x << endl ;

//17:54 stop
// 19:08 start
//19:16 stop
pii arr[105] ;
int dp[105][N+5] , n, W;

// int knap(int curr, int val){
// 	if(curr == n)
// 		return 0 ;
// 	int res = 
// 	//dp[curr][val] = min(dp[curr-1][val], arr[curr].ss + dp[curr-1][val - arr[curr].ff])
//}

void solve()
{
	cin >> n  >> W ;
	repA(i,0,n-1){
		cin >> arr[i].ff >> arr[i].ss ;
	}
	repA(i,0,n+2){
		repA(j,1,N)
			dp[i][j] = inf;
		dp[i][0] = 0 ;
	}
	sort(arr,arr+n) ;
	repA(i,1,n){
		repA(val,0,N){
			dp[i][val] = min(dp[i-1][val],dp[i][val]) ;
			if(val - arr[i-1].ss < 0){
				//mycerr << dp[i][val] << " " ;
				continue ;
			}
			dp[i][val] = min(dp[i][val],arr[i-1].ff + dp[i-1][val - arr[i-1].ss]) ;
			//mycerr << dp[i][val] << " " ;
		}
		//mycerr << endl << endl ; 
	}

	//knap(0,0) ;

	repD(i,N,0){
		if(dp[n][i] <= W){
			cout << i ;//<< " " << dp[n][i] << endl  ;
			break ;
		}
	}
}   

     
int32_t main(int32_t argc, char *argv[])
{
    double t1 = clock() ;
    ios::sync_with_stdio(0);    
    cin.tie(0); cout.tie(0);
    int TC = 1, t = 0;
   // cin >> TC ;
    while(t++ < TC)
    {
        //cout << "Case " << t << ":\n" ;
        solve();
    }
    mycerr << "Time : " << 1000 *(clock() - t1)/CLOCKS_PER_SEC << " ms\n" ;
    return 0;
}

Measured memory_bytes: 82176
n = int(input())
p = list(map(int, input().split()))
q = list(map(int, input().split()))

def permutations(nums, t, path):
    if len(nums) == 0:
        path.append(t)
        return
    for i in range(len(nums)):
        permutations(nums[:i] + nums[i + 1:], t + [nums[i]], path)

path = []
permutations([i for i in range(1, n + 1)], [], path)
path.sort()

r = abs(path.index(p) - path.index(q))
print(r)

Measured memory_bytes: 60760
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 7, mod = 1e9 + 7;
int n, ans, f[N][2];
char s[N];
int main()
{
  scanf("%s", s + 1);
  n = strlen(s + 1);
  f[0][1] = 1;
  for (int i = 1; i <= n; i++)
    if (s[i] == '1')
      f[i][0] = (3ll * f[i - 1][0] + f[i - 1][1]) % mod, f[i][1] = 2ll * f[i - 1][1] % mod;
    else
      f[i][0] = 3ll * f[i - 1][0] % mod, f[i][1] = f[i - 1][1];
  ans = (f[n][0] + f[n][1]) % mod;
  printf("%d", ans);
}

Measured memory_bytes: 1152
C=[list(map(int,input().split())) for i in range(3)]
a1=0
b=C[0]
a=[C[i][0]-b[0] for i in range(3)]
for i in range(3):
    for j in range(3):
        if C[i][j]!=a[i]+b[j]:
            print("No")
            exit()
print("Yes")

Measured memory_bytes: 3060
a = list(input())
b = list(input())
c = list(input())
# print('a',a)
# print('b',b)
# print('c',c)
# exit()
ptr = 'a'
while (True):
	if ptr == 'a':
		if a == []:
			print('A')
			break
		ptr = a.pop(0)
	if ptr == 'b':
		if b == []:
			print('B')
			break
		ptr = b.pop(0)
	if ptr == 'c':
		if c == []:
			print('C')
			break
		ptr = c.pop(0)


Measured memory_bytes: 9128
#include<iostream>
#include<string>
using namespace std;
string week[8]= {"SUN" , "MON" , "TUE", "WED", "THU", "FRI", "SAT"};
int main(){
    string s;
    cin >>s;
    for(int i=0; i<7; i++){
        if(s==week[i]){
            cout << 7-i << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

/**
 * 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;
        MyScan in = new MyScan(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskA solver = new TaskA();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskA {
        public void solve(int testNumber, MyScan in, PrintWriter out) {
            int a = in.nextInt();
            int sum = a;
            for (int r = 1; r < a; r++) {
                sum = Math.min(d(r) + d(a - r), sum);
            }
            out.println(sum);
        }

        private int d(int i) {
            if (i < 10) return i;
            return (i % 10) + d(i / 10);


        }

    }

    static class MyScan {
        private final InputStream in;
        private byte[] inbuf = new byte[1024];
        public int lenbuf = 0;
        public int ptrbuf = 0;

        public MyScan(InputStream in) {
            this.in = in;
        }

        private int readByte() {
            if (lenbuf == -1) throw new InputMismatchException();
            if (ptrbuf >= lenbuf) {
                ptrbuf = 0;
                try {
                    lenbuf = in.read(inbuf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (lenbuf <= 0) return -1;
            }
            return inbuf[ptrbuf++];
        }

        public int nextInt() {
            int num = 0, b;
            boolean minus = false;
            while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')) ;
            if (b == '-') {
                minus = true;
                b = readByte();
            }

            while (true) {
                if (b >= '0' && b <= '9') {
                    num = num * 10 + (b - '0');
                } else {
                    return minus ? -num : num;
                }
                b = readByte();
            }
        }

    }
}



Measured memory_bytes: 21332
//BUGSBUNNY
//IIT ROORKEE
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define double long double
#define ld long double
#define endl '\n'
#define vi vector<int>
#define vvi vector<vi>
#define vs vector<string>
#define vl vector<long long>
#define vpii vector<pii>
#define vpipii vector<pipii>
#define vb vector<bool>
#define pb push_back
#define pob pop_back
#define mp make_pair
#define pii pair<int,int>
#define pipii pair<int,pii>
#define piipi pair<pii,int>
#define pld pair<long double,long double>
#define mod 1000000007
// #define mod 163577857 
// #define mod 998244353
#define rep(i,n) for (ll i = 0; i < n; i++)
#define repp(i,a,b) for(ll i = a ; i<b ; i++)
#define reppr(i,a,b) for(ll i = a-1 ; i>=b ; i--)
#define repr(i,n) for (ll i = n - 1; i >= 0; i--)
#define ff first
#define ss second
#define pc putchar_unlocked
#define gc getchar_unlocked
#define inf 9223372036854775807
#define infn -9223372036854775807
#define pi 3.14159265358979323846
#define eps 0.0000000001
#define sp << " " <<
#define setprec(x) cout << fixed << setprecision(x);
#define REVERSE(a) reverse(all(a));
#define SORT(a) sort(all(a));
#define all(n) n.begin(),n.end()
 
//GCD and LCM
    int gcd (int a, int b) { return b ? gcd (b, a % b) : a; }
    int lcm (int a, int b) { return a / gcd(a, b) * b; }
 
//Modular Exponentiation
    int powmod(int x,int y) 
    { 
        if (y == 0) return 1; 
        int p = powmod(x, y/2) % mod; 
        p = (p * p) % mod;   
        return (y%2 == 0)? p : (x * p) % mod; 
    }
 
//Modular Inverse
    int inverse(int a) 
    { 
       return powmod(a,mod-2); 
    }


void solve();
signed main()
{
    //-------------------------------------------------------------------------------   
        ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
        clock_t clk = clock();
    //-------------------------------------------------------------------------------   
    //-------------------------------------------------------------------------------
        int t = 1;
        // cin >> t;       
        rep(i,t)
        {
            // cout << "Case #" << i+1 << ": ";
            solve();
        }
    //-------------------------------------------------------------------------------
        clk = clock() - clk;
        cerr << fixed << setprecision(12) << "Time: " << ((double)clk)/CLOCKS_PER_SEC;
    //-------------------------------------------------------------------------------
}

void solve()
{
    int a , b , n;
    cin >> a >> b >> n;
    if(n >= b) n = b-1 ;
    cout << (a*n)/b - a*(n/b);
}   

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

using namespace std;

int main() {
  int i, j;
  while (1) {
    int n, r;
    scanf("%d %d", &n, &r);
    if (n == 0) break;
    vector<int> a(n); // int a[n]
    for (i = 0; i < n; i++) {
      a[i] = n-i;
    }
    for (i = 0; i < r; i++) {
      int p, c;
      scanf("%d %d", &p, &c);
      auto x = vector<int>(a.begin(), a.begin() + p - 1);
      auto y = vector<int>(a.begin() + p - 1, a.begin() + p - 1 + c);
      auto z = vector<int>(a.begin() + p - 1 + c, a.end());
      a = y;
      copy(x.begin(), x.end(), back_inserter(a));
      copy(z.begin(), z.end(), back_inserter(a));
    }
    cout << a.front() << endl;
  }
}



Measured memory_bytes: 3220
/*input
3
a
aa
b
*/
#include <bits/stdc++.h>
#define fastIo ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define fi first
#define se second
#define sz size
#define pb push_back
#define mp make_pair
using namespace std;

//#define LOCAL
#ifdef LOCAL
	#define DEBUG(x) do { cout << #x << ": " << x << '\n'; } while (0)
#else
	#define DEBUG(x) 
#endif

const double EPS = 1e-9;
const double PI = 3.141592653589793238462;

const int dr[] = {1, 1, 0, -1, -1, -1, 0, 1};
const int dc[] = {0, 1, 1, 1, 0, -1, -1, -1};

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

map<char, int> m, seen;
map<char, int> tot[55];

int main(){
	fastIo;

	int n;
	cin >> n;

	for(int i = 0; i < n; i++){
		string s;
		cin >> s;
		seen.clear();
		for(int j = 0; j < s.sz(); j++){
			if(!seen[s[j]]){
				seen[s[j]] = 1;
				m[s[j]]++;
			}
			tot[i][s[j]]++;
		}
	}

	string ans;
	for(char c = 'a'; c <= 'z'; c++){
		if(m[c] == n){
			int times = 55;
			for(int i = 0; i < n; i++){
				times = min(times, tot[i][c]);
			}
			for(int i = 0; i < times; i++){
				ans.pb(c);
			}
		}
	}

	if(ans.sz() == 0){
		cout << '\n';
	}
	else{
		cout << ans << '\n';
	}

	return 0;
}

Measured memory_bytes: 384
alphala=[chr(i) for i in range(65, 65+26)]
n=int(input())
s=input()
for i in range(len(s)):
    alpha=s[i:i+1]
    for i in range(len(alphala)):
        if alphala[i]==alpha:
            print(alphala[(i+n)%26], end="")

Measured memory_bytes: 46428
// #define _GLIBCXX_DEBUG // for STL debug (optional)
#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>
using namespace std;
using ll = long long int;
using int64 = long long int;
 
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;}
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const int INF = 1LL << 29;
const ll LONGINF = 1LL << 60;
const ll MOD = 1000000007LL;

const int MAXN = 10010;
ll N, M, dp[6010][12010];

int main() {
    scanf("%lld%lld", &N, &M);

    int ofs = 6000;
    dp[0][0 + ofs] = 1;
    for(int i=0; i<3*N; i++) {
        for(int j=0; j<=2*ofs; j++) {
            if(dp[i][j] == 0) continue;
            // 最も大きい要素を使う
            // 1 個だけのグループにする場合
            (dp[i+1][j+1] += dp[i][j]) %= M;
            // 2 個のグループにする場合 (もう一個は自由)
            if(j>=1) (dp[i+2][j-1] += dp[i][j] * (3*N-i-1)) %= M;
            // 3 個のグループにする場合 (もう二個は自由)
            (dp[i+3][j] += dp[i][j] * (3*N-i-1) * (3*N-i-2)) %= M;
        }
    }

    ll ans = 0;
    for(int i=ofs; i<=2*ofs; i++) (ans += dp[3*N][i]) %= M;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 561536
#include <iostream>
#include <vector>

using namespace std;

#define M 1000000007

int main() {

	int a[9] = { 0 };//左端に線がない | |-|
	int b[9] = { 0 };//左端に線がある |-| |
	a[0] = 1;
	a[1] = 1;
	b[1] = 0;

	for (int i = 2; i < 9; i++) {
		b[i] = a[i-1];
		a[i] = a[i - 1] + b[i - 1];
		//cout << a[i] + b[i] << endl;
	}

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

	vector< vector<long long int> > dp(h, vector<long long int>(w, 0));
	dp[0][0] = (long long int)a[w];
	if (w > 1) {
		dp[0][1] = (long long int)a[w - 1];
	}
	for (int i = 1; i < h; i++) {
		for (int j = 0; j < w; j++) {
			if (dp[i - 1][j] > 0) {
				if (j == 0) {
					dp[i][j] += dp[i - 1][j] * (long long int)(a[w - 1] + b[w - 1]);
					dp[i][j] %= M;
					if (j + 1 < w) {
						dp[i][j + 1] += dp[i - 1][j] * (long long int)b[w];
						dp[i][j + 1] %= M;
					}
				}
				else if (j == w - 1) {
					dp[i][j] += dp[i - 1][j] * (long long int)(a[w - 1] + b[w - 1]);
					dp[i][j] %= M;
					if (0 <= j - 1) {
						dp[i][j - 1] += dp[i - 1][j] * (long long int)b[w];
						dp[i][j - 1] %= M;
					}
				}
				else {
					dp[i][j] += dp[i - 1][j] * (long long int)((a[j] + b[j]) * (a[w - j - 1] + b[w - j - 1]));
					dp[i][j] %= M;

					dp[i][j - 1] += dp[i - 1][j] * (long long int)((a[j - 1] + b[j - 1]) * (a[w - j - 1] + b[w - j - 1]));
					dp[i][j - 1] %= M;

					dp[i][j + 1] += dp[i - 1][j] * (long long int)((a[j] + b[j]) * (a[w - j - 2] + b[w - j - 2]));
					dp[i][j + 1] %= M;
				}
			}
		}
	}

	cout << dp[h - 1][k - 1] << endl;

	return 0;
}

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

int main() {
  int n;
  cin >> n;
  tuple<string, int, int> t[n];
  vector<tuple<string, int, int>> vt(n);
  for(int i = 1; i <= n; i++){
    string s;
    int p;
    cin >> s >> p;
    p *= -1;
    t[i - 1] = make_tuple(s, p, i);
  }
  for(int i = 0; i < n; i++)
    vt.at(i) = t[i];
  sort(vt.begin(), vt.end());
  for(int i = 0; i < n; i++){
    cout << get<2>(vt.at(i)) << endl;
  }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define asll unsigned long long
#define pii pair<int,int>
#define st first
#define nd second

asll M=1e9+7;//20190518

vector<int> v;

int a[15][15];
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);cout.tie(NULL);
	srand(time(0));//20190709
	
	int n,d;
	cin>>n>>d;
	for(int i=0;i<n;i++){
		for(int j=0;j<d;j++){
			cin>>a[i][j];
		}
	}
	
	int hasil=0,temp=0,idx;
	for(int i=0;i<130;i++){
		v.push_back(i*i);
	}
	for(int i=0;i<n-1;i++){
		for(int j=i+1;j<n;j++){
			temp=0;
			for(int k=0;k<d;k++){
				temp+=(a[i][k]-a[j][k])*(a[i][k]-a[j][k]);
			}
			idx=lower_bound(v.begin(),v.end(),temp)-v.begin();
			if(v[idx]==temp){
				hasil++;
			}
		}
	}
	cout<<hasil<<endl;
}



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

using namespace std;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define all(obj) (obj).begin(), (obj).end()
#define bit(n) (1LL << (n))

typedef long long ll;

template<class T> inline bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> inline bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

const long long INF = 1LL << 60;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  string dr = "dream";
  string drr = "dreamer";
  string er = "erase";
  string err = "eraser";
  
  reverse(all(dr));
  reverse(all(drr));
  reverse(all(er));
  reverse(all(err));
  
  string s; cin>>s;
  reverse(all(s));
  
  bool isCont = true;
  int ind = 0;
  string res = "NO";
  
  while(isCont) {
    
    if(s.substr(ind, 5) == dr) {
      ind = ind + 5;
      continue;
    }
    
    if(s.substr(ind, 7) == drr) {
      ind = ind + 7;
      continue;
    }
    
    if(s.substr(ind, 5) == er) {
      ind = ind + 5;
      continue;
    }
    
    if(s.substr(ind, 6) == err) {
      ind = ind + 6;
      continue;
    }
    
    isCont = false;
    res = "NO";
    
  }
  
  if(ind == s.length()) res="YES";
  cout<<res;

  return 0;
}

Measured memory_bytes: 3784
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"
using namespace std;
#define FOR(i,j,k) for(int (i)=(j);(i)<(int)(k);++(i))
#define rep(i,j) FOR(i,0,j)
#define each(x,y) for(auto &(x):(y))
#define mp make_pair
#define MT make_tuple
#define all(x) (x).begin(),(x).end()
#define debug(x) cout<<#x<<": "<<(x)<<endl
#define smax(x,y) (x)=max((x),(y))
#define smin(x,y) (x)=min((x),(y))
#define MEM(x,y) memset((x),(y),sizeof (x))
#define sz(x) (int)(x).size()
#define RT return
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vll = vector<ll>;

template<int MOD>
class ModInt {
public:
    ModInt() :value(0) {}
    ModInt(long long val) :value((int)(val<0 ? MOD + val % MOD : val % MOD)) { }

    ModInt& operator+=(ModInt that) {
        value = value + that.value;
        if (value >= MOD)value -= MOD;
        return *this;
    }
    ModInt& operator-=(ModInt that) {
        value -= that.value;
        if (value<0)value += MOD;
        return *this;
    }
    ModInt& operator*=(ModInt that) {
        value = (int)((long long)value * that.value % MOD);
        return *this;
    }
    ModInt &operator/=(ModInt that) {
        return *this *= that.inverse();
    }
    ModInt operator+(ModInt that) const {
        return ModInt(*this) += that;
    }
    ModInt operator-(ModInt that) const {
        return ModInt(*this) -= that;
    }
    ModInt operator*(ModInt that) const {
        return ModInt(*this) *= that;
    }
    ModInt operator/(ModInt that) const {
        return ModInt(*this) /= that;
    }
    ModInt pow(long long k) const {
        ModInt n = *this, res = 1;
        while (k) {
            if (k & 1)res *= n;
            n *= n;
            k >>= 1;
        }
        return res;
    }
    ModInt inverse() const {
        long long a = value, b = MOD, u = 1, v = 0;
        while (b) {
            long long t = a / b;
            a -= t * b;
            swap(a, b);
            u -= t * v;
            swap(u, v);
        }
        return ModInt(u);
    }
    int toi() const { return value; }

private:
    int value;
};
typedef ModInt<1000000007> mint;
ostream& operator<<(ostream& os, const mint& x) {
    os << x.toi();
    return os;
}

mint dp[100005][100][2];

void solve() {
    dp[0][0][0] = 1;

    string K;
    int D;
    cin >> K >> D;
    const int M = sz(K);
    each(c, K)c -= '0';
    rep(i, M) rep(j, D) rep(k, 2) {
        rep(d, 10) {
            if (d > K[i] && !k)continue;
            int nk = !!(d < K[i] || k);
            int nj = (j + d) % D;
            dp[i + 1][nj][nk] += dp[i][j][k];
        }
    }
    cout << (dp[M][0][0] + dp[M][0][1] - 1) << endl;
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout << fixed << setprecision(15);
	solve();
	return 0;
}

Measured memory_bytes: 78464
from collections import deque
import bisect
s = str(input())
t = str(input())

sc = [0] * 26
tc = [0] * 26

for i in range(len(s)):
    sc[ord(s[i]) - ord("a")] += 1
for i in range(len(t)):
    tc[ord(t[i]) - ord("a")] += 1

# 不可能な場合
for i in range(26):
    if tc[i] > 0 and sc[i] == 0:
        print(-1)
        exit()


alph = [[] for _ in range(26)]
for i in range(len(s)):
    alph[ord(s[i]) - ord("a")].append(i)

ans = [0] * len(t)
pre_num = -1
for i in range(len(t)):
    num = ord(t[i]) - ord("a")
    if i > 0:
        idx = bisect.bisect_right(alph[num], pre_num)
        if idx >= len(alph[num]):
            num_idx = alph[num][0]
        else:
            num_idx = alph[num][idx]
    else:
        num_idx = alph[num][0]
    ans[i] = num_idx
    pre_num = num_idx

count = 0
pre = -1
for v in ans:
    if pre >= v:
        count += 1
    pre = v

print(count * len(s) + ans[-1] + 1)


Measured memory_bytes: 8820
N=int(input())
c=input()
white=[]
red=[]
ans=0
for i in range(N):
    if c[i]=="W":
        white.append(i)
    else:
        red.append(i)
if len(white)==0 or len(red)==0:
    print(ans)
else:
    while len(white)!=0 and len(red)!=0:
        a=white.pop(0)
        b=red.pop()
        if a<b:
            ans+=1
        else:
            break
    print(ans)

Measured memory_bytes: 17300
#include <stdio.h>

int main(void) {
  int X[5], k;
  for(int i = 0; i < 5; i++) {
    scanf("%d", &X[i]);
  }
  scanf("%d", &k);

  for(int i = 0; i < 5-1; i++) {
    for(int j = i; j < 5; j++) {
      if((X[j] - X[i]) > k) {
	printf(":(\n");
	return 0;
      }
    }
  }
  printf("Yay!\n");
  return 0;
}


Measured memory_bytes: 128
A, B, C, D = map(int, input().split())
alice = []
bob = []
for i in range(0, 100):
	alice.append(0)
	bob.append(0)
for i in range(A, B):
	alice[i] = 1
for i in range(C, D):
	bob[i] = 1
cnt = 0
for i in range(0, 100):
	cnt += alice[i]*bob[i]
print(cnt)

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

int main(){
	int N, K;
	string S;
	cin >> N >> K >> S;
	int Happy = 0;
	for(int i = 1; i < N; i++){
		if(S[i - 1] == S[i])Happy++;
	}
	
	for(int i = 0; i < K; i++){
		if(Happy + 2 <= N - 1){
			Happy += 2;
		}else if(Happy + 1 <= N - 1){
			Happy++;
		}else{
			break;
		}
	}
	
	cout << Happy << endl;
}


Measured memory_bytes: 512
FAST_IO = 1
if FAST_IO:
    import io, sys, atexit
    rr = iter(sys.stdin.read().splitlines()).next
    sys.stdout = _OUTPUT_BUFFER = io.BytesIO()

    @atexit.register
    def write():
        sys.__stdout__.write(_OUTPUT_BUFFER.getvalue())
else:
    rr = raw_input
rri = lambda: int(rr())
rrm = lambda: map(int, rr().split())
rrmm = lambda n: [rrm() for _ in xrange(n)]
N = rri()

num = list(rr())
count = num.count('1')
pwrTwo_plus = [0] * N 
pwrTwo_plus[0] = 1 % (count+1)
if count>1:
    pwrTwo_minus = [0] * N 
    pwrTwo_minus[0] = 1 % (count-1)  
for i in range(1, N):  
    pwrTwo_plus[i] = pwrTwo_plus[i - 1] * (2 % count)  
    pwrTwo_plus[i] %= count+1
    if count>1:
        pwrTwo_minus[i] = pwrTwo_minus[i - 1] * (2 % count)  
        pwrTwo_minus[i] %= count-1

def getMod(_str, n, k, plus) :  
    
    # To store the result  
    res = 0
    i = 0
    j = n - 1
    while (i < n) :  
  
        # If current bit is 1  
        if (_str[j] == '1') :  
  
            # Add the current power of 2  
            if plus:
                res += (pwrTwo_plus[i] )  
                res %= k  
            else:
                res += (pwrTwo_minus[i] )  
                res %= k  
              
        i += 1
        j -= 1
  
    return res  
dic = {}
def f(x):
    if x in dic:
        return dic[x]
    if x== 0:
        return 0
    tmp = x% bin(x).count('1')
    dic[x] = f(tmp)+1
    return dic[x]
    

ans_1 = getMod(num, N, count+1, True)
if count>1:
    ans_2 = getMod(num, N, count-1, False)
for i in range(N):
    if num[i] =='0':
        cur_count = count+1
    else:
        cur_count =count-1
    if cur_count ==0:
        print(0)
    else:
        if num[i] =='0':
            cur_num = ans_1
            cur_num += pwrTwo_plus[N-1-i]
            cur_num %= cur_count
            print(f(cur_num)+1)
        else:
            cur_num = ans_2
            cur_num -=pwrTwo_minus[N-1-i] 
            cur_num %= cur_count
            print(f(cur_num)+1)
            
            


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

using int64 = long long;

int64 Solve(const int64 A, const int64 B, const vector<int64>& x) {
  const int64 n = x.size();
  int64 ret = 0;
  for (int64 i = 0; i < n - 1; ++i) {
    int64 dist = x[i + 1] - x[i];
    ret += min(dist * A, B);
  }
  return ret;
}

int main() {
  int64 N, A, B;
  cin >> N >> A >> B;
  vector<int64> x(N);
  for (int i = 0; i < N; ++i)
    cin >> x[i];

  cout << Solve(A, B, x) << "\n";

  return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <complex>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <numeric>
#include <cstring>
#include <ctime>
#include <cstdlib>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <cmath>
#include <bitset>
#include <cassert>
#include <queue>
#include <stack>
#include <deque>
#include <random>
#include <iomanip>
typedef long long int ll;
typedef long double ld;
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
const ll MOD=1000000007;
const ll MAX_N=500010;
const ll INF=999999999999;

int main(){
    ll n,k;
    cin>>n>>k;
    ll ans=0;
    if(k%2){
        n/=k;
        ans=n*n*n;
    }else{
        ll l=n/k;
        ll m;
        if(n%k>=k/2){
            m=l+1;
        }else{
            m=l;
        }
        ans=l*l*l+m*m*m;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include  <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <string>
#include<math.h>
#include<iomanip>
#include<stdio.h>
#include <stdlib.h>
#include<stdio.h>
#include <queue>
#include<map>
#include <sstream>
#include<set>
#include<stack>
#include<time.h>
typedef long long int ll;
//#include<bits/stdc++.h>


using namespace std;
 


int main()
{
   
    
    int a = 0;
    for (int i = 0; i < 5; i++)
    {
        int t;
        cin >> t;
        if (!t)a = i + 1;

    }
    cout << a << endl;


    return 0;

}

Measured memory_bytes: 3592
#include <iostream> 
#include<vector>
#include<algorithm>
#include<map>
#include<iomanip>
#include<set>
#include<queue>
#include<deque>
#include<iomanip>
#include<sstream>
#include<cmath>
#include<bitset>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define req(i,n) for(int i = 1;i <=  n; i++)
#define rrep(i,n) for(int i = n -1;i >= 0;i--)
#define ALL(obj) begin(obj), end(obj)
typedef long long int ll;
typedef long double ld;
const ll INF = (1 << 29);
ll k, m, n,h,w,v;
const ll MOD= 1000000007;
const ld PI = acos(-1);
template<typename A, size_t N, typename T>
void Fill(A(&array)[N], const T & val) {
    std::fill((T*)array, (T*)(array + N), val);
}
int main() {
    cin >> n; set<int> st;
    rep(i, n) {
        cin >> m;
        st.insert(m);
    }
    if (st.size() % 2 == 1) cout << st.size() << endl;
    else cout << st.size() - 1 << endl;
}

Measured memory_bytes: 4992
#include<cstdio>
#include<cmath>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<iostream>
#include<fstream>
using namespace std;

int main()
{
	char a[5][5],c[5][5];
	for(int i=1;i<=2;i++)
	{
		for(int j=1;j<=4;j++)
		{
			scanf("%c",&c[i][j]);
		}
	}
	if (c[1][1]==c[2][3]&&c[1][2]==c[2][2]&&c[1][3]==c[2][1]){
		printf("YES");
	}
	else{
		printf("NO");
	}
	return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Convert;
using static System.Math;

class Program
{
    static void Main(string[] args)
    {
        var num = ToInt32(ReadLine());
        var abc = new int[num][];
        for (var i = 0; i < num; i++)
            abc[i] = Array.ConvertAll(ReadLine().Split(' '), int.Parse);
        var dp = new int[num,3,3];
        for(var j = 0; j < 3; j++)
        {
            for (var h = 0; h < 3; h++)
                dp[0, j, h] = abc[0][j];
        }
        for (var i = 1; i < num; i++)
        {
            for(var j = 0; j < 3; j++)
            {
                for(var h = 0; h < 3; h++)
                {
                    if (j == h) { dp[i, j, h] = 0; continue; }
                    var m = 0;
                    for(var w = 0; w < 3; w++)
                    {
                        if (w == j) continue;
                        for (var q = 0; q < 3; q++)
                            m = Max(m, dp[i - 1, w, q]);
                    }
                    dp[i, j, h] = abc[i][j] + m;
                }
            }
        }
        var max = 0;
        for (var i = 0; i < 3; i++)
            for (var j = 0; j < 3; j++)
                max = Max(max, dp[num - 1, i, j]);
        WriteLine(max);
    }
    private const string ALFA = "abcdefghijklmnopqrstuvwxyz";
    private const int MOD = 1000000007;
}


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

int main() {
  long long l, r;
  cin >> l >> r;
  if (r - l + 1 >= 673) {
    cout << 0 << endl;
    return 0;
  }
  long long m = 2019;
  for (long long i = l; i < r; i++)
    for (long long j = i + 1; j <= r; j++)
      m = min(m, i * j % 2019);
  cout << m << endl;
}

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

using namespace std;
//#define int long long
const int INF = 200000000007;


  
signed main(){
    int n,ans=0;
    cin>>n;
    string s;
    int a=0,b=0,w=0;
    for(int i=0;i<n;i++){
        cin>>s;
        for(int j=1;j<s.size();j++){
            if(s[j-1]=='A'&&s[j]=='B')ans++;
            
        }
        if(s[0]=='B')b++;
            if(s[s.size()-1]=='A')a++;
            if(s[0]=='B'&&s[s.size()-1]=='A')w++;

    }
    if(a-w==0&&b-w==0)cout<<ans+max(w-1,0);
    else cout<<ans+w+min(a-w,b-w);

    return 0;
}

Measured memory_bytes: 256
//Name: Lupin The 4th
//Level: 3
//Category: 動的計画法,DP,メモ化再帰,ビットDP
//Note:

/*
 * 状態になるのは破った蔵の組み合わせと現在位置．
 * 持っている千両箱の重さは破った蔵の組から求められる．
 * これらの各状態について，最短でたどり着くときの時間を求め，最後に経路復元すればよい．
 * 状態[state][pos]における最短時間は直前にいた蔵として可能なものを全て列挙し，
 * それらにたどり着く最短時間に移動時間を加えたものの最小値である．
 *
 * オーダーは状態数が2^N*N，各状態から最大でN個の遷移を考えるので O(2^N * N^2)．
 */
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

double memo[1<<15][15];
int prev[1<<15][15];
double speed[1<<15];
int dist[15];
int weight[15];
int id[15];
int N;

double solve(int state, int pos) {
    double &res = memo[state][pos];
    if(res >= 0) return res;

    res = 1e30;
    const int prev_state = state & ~(1<<pos);
    for(int i = 0; i < N; ++i) {
        const int mask = 1<<i;
        if(prev_state & mask) {
            const double t = solve(prev_state, i) + abs(dist[pos]-dist[i]) / speed[prev_state];
            //cout << state << ' ' << pos << ' ' << i << ' ' << t << endl;
            if(t < res) {
                res = t;
                prev[state][pos] = i;
            }
        }
    }
    //cout << state << ' ' << pos << ' ' << res << endl;
    return res;
}

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

    cin >> N;
    for(int i = 0; i < N; ++i) {
        cin >> id[i] >> dist[i] >> weight[i];
    }

    // DP表の初期化
    const int TERMINAL = (1<<N)-1;
    for(int i = 0; i <= TERMINAL; ++i) {
        for(int j = 0; j < N; ++j) {
            memo[i][j] = (i == (1<<j)) ? 0 : -1;
            prev[i][j] = -1;
        }
    }

    // 蔵の組み合わせに対する速度の事前計算
    for(int i = 0; i <= TERMINAL; ++i) {
        int sum = 0;
        for(int j = 0; j < N; ++j) {
            if(i & (1<<j)) sum += weight[j];
        }
        speed[i] = 2000.0 / (70+sum*20);
        //cout << speed[i] << endl;
    }

    for(int i = 0; i < N; ++i) {
        solve(TERMINAL, i);
    }

    // 最短時間のとき，最後の蔵を求める．
    int cur = 0;
    for(int i = 1; i < N; ++i) {
        if(memo[TERMINAL][i] < memo[TERMINAL][cur]) {
            cur = i;
        }
    }

    // 経路復元
    int state = TERMINAL;
    vector<int> ans;
    while(cur != -1) {
        ans.push_back(id[cur]);
        int next = prev[state][cur];
        state &= ~(1<<cur);
        cur = next;
    }

    reverse(ans.begin(), ans.end());
    for(int i = 0; i < N; ++i) {
        if(i > 0) cout << ' ';
        cout << ans[i];
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 7236
#include <stdio.h>

using namespace std;

int main(){
	int a,b;
	char op;
	while(true){
		scanf("%d %c %d",&a,&op,&b);
		if(op == '?') break;
		switch(op){
		case '+':
			printf("%d\n",a+b);
			break;
		case '-':
			printf("%d\n",a-b);
			break;
		case '/':
			printf("%d\n",a/b);
			break;
		case '*':
			printf("%d\n",a*b);
			break;
		}
	}
}


Measured memory_bytes: 2620
#include <stdio.h>
int main(void){
	int A, B;
	scanf("%d", &A);
	scanf("%d", &B);
	if(A % 3 != 0 && B % 3 != 0 && (A+B) % 3 != 0){
		printf("Impossible\n");
	}else{
		printf("Possible\n");
	}
}

Measured memory_bytes: 128
#include <stdio.h>

int main(void){
	
	int n,i,j,k,A[101],M,C=0;
	scanf("%d",&n);
	for (i=0;i<n;i++){
		scanf("%d",&A[i]);
	}
	for(k=0;k<n;k++){
		for(i=n-1;i!=0;i--){
			j=i-1;
			if(A[i]<A[j]){
				M=A[i];
				A[i]=A[j];
				A[j]=M;
				C++;
			}
		}
	}
	for(i=0;i<n-1;i++){
		printf("%d ",A[i]);
	}
	printf("%d\n%d\n",A[i],C);
	return 0;
}

Measured memory_bytes: 1028
#include <bits/stdc++.h>
#include <cstdlib>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main() {
    int a, b, c, d;
    string ans;
    cin >> a >> b >> c >> d;
    while (true) {
        c = c - b;
        if (c <= 0) {
            ans = "Yes";
            break;
        }
        a = a - d; 
        if (a <= 0) {
            ans = "No";
            break;
        }
    }
    cout << ans << endl;
    return 0;
}


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

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<string, string> pss;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vii;
typedef vector<ll> vl;
typedef vector<vl> vvl;

double EPS=1e-9;
int INF=1000000005;
long long INFF=1000000000000000005ll;
double PI=acos(-1);
int dirx[8]={ -1, 0, 0, 1, -1, -1, 1, 1 };
int diry[8]={ 0, 1, -1, 0, -1, 1, -1, 1 };
const ll MOD = 1000000007;

ll sum() { return 0; }
template<typename T, typename... Args>
T sum(T a, Args... args) { return a + sum(args...); }

#define DEBUG fprintf(stderr, "====TESTING====\n")
#define VALUE(x) cerr << "The value of " << #x << " is " << x << endl
#define OUT(x) cout << x << endl
#define OUTH(x) cout << x << " "
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define READ(x) for(auto &(z):x) cin >> z;
#define FOR(a, b, c) for (int(a)=(b); (a) < (c); ++(a))
#define FORN(a, b, c) for (int(a)=(b); (a) <= (c); ++(a))
#define FORD(a, b, c) for (int(a)=(b); (a) >= (c); --(a))
#define FORSQ(a, b, c) for (int(a)=(b); (a) * (a) <= (c); ++(a))
#define FORC(a, b, c) for (char(a)=(b); (a) <= (c); ++(a))
#define EACH(a, b) for (auto&(a) : (b))
#define REP(i, n) FOR(i, 0, n)
#define REPN(i, n) FORN(i, 1, n)
#define MAX(a, b) a=max(a, b)
#define MIN(a, b) a=min(a, b)
#define SQR(x) ((ll)(x) * (x))
#define RESET(a, b) memset(a, b, sizeof(a))
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define ALL(v) v.begin(), v.end()
#define ALLA(arr, sz) arr, arr + sz
#define SIZE(v) (int)v.size()
#define SORT(v) sort(ALL(v))
#define REVERSE(v) reverse(ALL(v))
#define SORTA(arr, sz) sort(ALLA(arr, sz))
#define REVERSEA(arr, sz) reverse(ALLA(arr, sz))
#define PERMUTE next_permutation
#define TC(t) while (t--)
#define FAST_INP  ios_base::sync_with_stdio(false);cin.tie(NULL)
#define what_is(x) cerr << #x << " is " << x << endl;

void solve() {

}

int main()
{
    FAST_INP;
//    #ifndef ONLINE_JUDGE
//    freopen("input.txt","r", stdin);
//    freopen("output.txt","w", stdout);
//    #endif

//    int tc; cin >> tc;
//    TC(tc) solve();
	int n;
	cin >> n;
	vi p(n);
	READ(p);
	int ans=0;
	REP(i,n){
		if(i-1<0||i+1>n-1) continue;
		if(
			( p[i]>p[i-1]&&p[i]<p[i+1] ) ||
			( p[i]<p[i-1]&&p[i]>p[i+1] )
		) ans++;
	}
	OUT(ans);
    return 0;
}

Measured memory_bytes: 3648
#include<stdio.h>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
 
using namespace std;
 
//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
 
//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}
 
//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
 
//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
 
//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
 
//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
 
//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))
 
//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
 
int main(void){
    int n;
    int f[100][10];
    LL p[100][10];
    cin >> n;
    REP(i, n)
    {
        REP(j,10){
            int v;
            cin >> v;
            f[i][j] = v;
        }
    }
    REP(i,n){
        REP(j,11){
            LL v;
            cin >> v;
            p[i][j] = v;
        }
    }
    int ans = -(1 << 30);
    for (int b = 1; b < (1 << 10); b++)
    {
        LL x=0;
        REP(i, n)
        {
            int c = 0;
            REP(j, 10)
            {
                if ((b>>j&1) && f[i][j] == 1)
                    c++;
            }
            x += p[i][c];
        }

        if(x > ans){
            ans = x;
        }
        // ans = max(ans, x);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
string str;
int main()
{
    int n,a,b,c,d;
    cin>>n>>a>>b>>c>>d;
    cin>>str;
    int v=0;
    for(int i=a; i<c-1; i++)//第一步判断
    {
        if(str[i]==str[i+1]&&str[i]=='#')
        {
            v=1;
            break;
        }
    }
    for(int i=b; i<d-1; i++)//第一步判断
    {
        if(str[i]==str[i+1]&&str[i]=='#')
        {
            v=1;
            break;
        }
    }
    if(v==1) printf("No\n");
    else
    {
        if(c>d)//第二步判断
        {
            int u=0;
            for(int i=b-1;i<=d-1;i++)
            {
                if(str[i]==str[i-1]&&str[i]==str[i+1]&&str[i]=='.')
                {
                    u=1;
                    break;
                }
            }
            if(u==0)
            {
                printf("No\n");
            }
            else printf("Yes\n");
        }
        else printf("Yes\n");
    }
    return 0;
}

Measured memory_bytes: 640
#include <stdio.h>

#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <string>
#include <vector>
#include <numeric>

using namespace std;

void __print(int x) { cerr << x; }
void __print(long x) { cerr << x; }
void __print(long long x) { cerr << x; }
void __print(unsigned x) { cerr << x; }
void __print(unsigned long x) { cerr << x; }
void __print(unsigned long long x) { cerr << x; }
void __print(float x) { cerr << x; }
void __print(double x) { cerr << x; }
void __print(long double x) { cerr << x; }
void __print(char x) { cerr << '\'' << x << '\''; }
void __print(const char *x) { cerr << '\"' << x << '\"'; }
void __print(const string &x) { cerr << '\"' << x << '\"'; }
void __print(bool x) { cerr << (x ? "true" : "false"); }

template <typename T, typename V>
void __print(const pair<T, V> &x) {
    cerr << '{';
    __print(x.first);
    cerr << ',';
    __print(x.second);
    cerr << '}';
}
template <typename T>
void __print(const T &x) {
    int f = 0;
    cerr << '{';
    for (auto &i : x) cerr << (f++ ? "," : ""), __print(i);
    cerr << "}";
}
void _print() { cerr << "]\n"; }
template <typename T, typename... V>
void _print(T t, V... v) {
    __print(t);
    if (sizeof...(v)) cerr << ", ";
    _print(v...);
}
#ifdef LOCAL
#define debug(x...)               \
    cerr << "[" << #x << "] = ["; \
    _print(x)
#else
#define debug(x...)
#endif

#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)

typedef long long ll;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    long double a, b, x;
    cin >> a >> b >> x;

    long double ax = a/x;
    long double bx = b/x;

    cout << (long long)(floor(bx) - ceil(ax) +1) << endl;

    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(){
    
    int a,b;
    
    while(1){
        scanf("%d %d",&a,&b);
        if(a==0 && b==0){
            break;
        }
        for(int i=0 ; i<a ; i++){
            for(int j=0 ; j<b ; j++){
            	if(i%2==0){
            		if(j%2==0){
            			printf("#");	
					}
					else{
						printf(".");
					}
				}
				else{
					if(j%2==0){
            			printf(".");	
					}
					else{
						printf("#");
					}
				}
                
	        }
	        printf("\n");
	    }
	     printf("\n");
	}

	
	
	return 0;
}


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

int h, w;
string c[110];
vector<int> wr, wc;
bool f;

int main(){
	cin >> h >> w;
	for (int i = 0; i < h; ++i){
		cin >> c[i];
	}
	for (int i = 0; i < h; ++i){
		f = true;
		for (int j = 0; j < w; ++j){
			if (c[i][j] == '#'){
				f = false;
				break;
			}
		}
		if (!f) wr.push_back(i);
	}
	for (int j = 0; j < w; ++j){
		f = true;
		for (int i = 0; i < h; ++i){
			if (c[i][j] == '#'){
				f = false;
				break;
			}
		}
		if (!f) wc.push_back(j);
	}
	for (auto &i: wr){
		for (auto &j: wc){
			cout << c[i][j];
		}
		cout << endl;
	}
}

Measured memory_bytes: 256
import java.util.*;
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int K = sc.nextInt();
		int[] A = new int[N];
		int sum = 0, ans = 0;
		for(int i = 0; i < N; i++) {
			A[i] = sc.nextInt();
			sum += A[i];
		}
		Set<Integer> cd = new HashSet<>();
		for(int i = 1; i <= Math.sqrt(sum); i++)
			if(sum % i == 0) {
				cd.add(i);
				cd.add(sum/i);
			}
		for(int i : cd) {
			int[] B = new int[N];
			for(int j = 0; j < N; j++)
				B[j] = A[j] % i;
			Arrays.sort(B);
			int[] S = new int[N+1];
			for(int j = 0; j < N; j++)
				S[j+1] = S[j] + B[j];
			if(S[N-S[N]/i] <= K)
				ans = Math.max(ans, i);
		}
		System.out.println(ans);
	}

}


Measured memory_bytes: 30024
#include <iostream>
#include <stdio.h>
#include <algorithm>
using namespace std;
int input[300000];
int sorted[300000];
int getMeidan(int x, int number){
 int midian_lower = sorted[number /2 - 1 ];
 int midian_upper = sorted[number /2 ];
 if (x <= midian_lower){
 	return midian_upper;
 }else {
 	return midian_lower;
 }
}

int main() {
	// your code goes here
	int number;
	scanf("%d", &number);
	for(int i = 0; i <number; i++){
		int temp = 0;
		scanf("%d", &temp);
		input[i] = temp;
		sorted[i] = temp;
	}
	sort(sorted, sorted+number);
	
	for (int i =0; i< number; i++){
		if (i == number - 1){
			printf("%d", getMeidan(input[i], number));
	
		}else{
			printf("%d\n", getMeidan(input[i], number));
			
		}
		
	}

}
 

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

using namespace std;

int main() {
  int N;
  cin >> N;
  vector<int> vec;
  for (int i = 0; i < N; i++) {
    int z;
    cin >> z;
    vec.push_back(z);
  }

  sort(vec.begin(), vec.end());
  cout << vec[vec.size() - 1] - vec[0] << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
int main() {
  string s;
  cin >> s;
  for (int i = 0; 19 > i; i++){
    if(s.at(i) == ','){
      cout << " ";
    }else{
      cout << s.at(i);
    }
  }
  cout << endl;
}

Measured memory_bytes: 256
#include<cstdio>
#include<queue>
#include<utility>
#include<cstring>
#include<stack>
#include<algorithm>
#include<cmath>
#include<iostream>
#define INF 2147483647
#define REP(i,n) for(int i=0;i<(int)(n);i++)
int dx[4] = {1,0,0,-1};
int dy[4] = {0,1,-1,0};
using namespace std;
int main()
{
  int tmp,X,i=0,MAX=1;
  cin >> X;
  for(i=2;i<=X;i++){
    int j = 2;
    while(1){
      tmp = pow(i,j);
      j++;
      if(tmp <= X && MAX != X)
        MAX = max(MAX,tmp);
      else
        break;   
    }
  }
  cout << MAX << endl;
  return 0;
}


Measured memory_bytes: 512
#include <iostream>

using namespace std;

int main() {
    int a,b,k,x=0,d;
    cin >> a >> b;
    cin >> k;
    for(d=a;d>=1;d--)
    {
        if(b%d==0 && a%d==0)
        {
            x++;
            if(x==k)
            {
                cout<<d;
                return 0;
            }
        }
    }
    return 0;
}
    

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

#define rep(i,n) for(ll (i)=0;(i)<(ll)(n);(i)++)
#define all(x) (x).begin(),(x).end()
#define MOD 1000000007LL
#define INF (1LL<<60LL)
#define int long long
typedef long long ll;

using namespace std;



signed main() {
	ll n;
	while (cin >> n) {
		ll ans = 0;
		for(ll i = 0 ;i<10;i++)
			for (ll j = 0; j < 10; j++)
				for (ll k = 0; k < 10; k++) {
					ll d = n - i - j - k;
					if (0 <= d && d < 10) ans++;
				}
		cout << ans << endl;
	}
}


Measured memory_bytes: 3008