akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <queue>
#include <set>
#include <vector>
#include <string>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <complex>

long long int MOD = 1e9+7;

int main(){

  // read problem
  long long int N, K, tmp;
  scanf("%lld%lld", &N, &K);
  std::vector<long long int> A;
  for(long long int i = 0; i < N; i++){
    scanf("%lld", &tmp);
    A.push_back(tmp-1);
  }

  // solve problem
  long long int internal_flip = 0;
  std::vector<long long int> count(2000);
  for(long long int i = 0; i < N; i++){
    count[A[i]]++;
    for(long long int j = A[i]+1; j < 2000; j++){
      internal_flip += count[j];
      internal_flip = (internal_flip+MOD)%MOD;
    }
  }

  long long int external_flip = 0;
  for(long long int i = 1998; i >= 0; i--){
    external_flip += count[i]*count[i+1];
    external_flip = (external_flip+MOD)%MOD;
    count[i] = count[i]+count[i+1];
  }

  long long int KC2 = (K*(K-1))/2;
  KC2 = (KC2+MOD)%MOD;

  long long int ans;
  ans = (K*internal_flip+MOD)%MOD;
  ans = (ans + ((KC2*external_flip+MOD)%MOD) + MOD)%MOD;

  std::cerr << "Answer: " << std::endl;
  std::cout << ans << std::endl;
  

  return 0;
}

Measured memory_bytes: 256
#define  _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream>
#include <random>
#include<map>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include<fstream>
#include <unordered_map>
#include <cstdlib>
#include <complex>
using namespace std;
using ll = long long;
#define Ma_PI 3.141592653589793
#define eps 0.00000001
#define LONG_INF 3000000000000000000
#define INF 1e9+7
#define rep(i,n) for(long long i = 0;i < n;++i)    
#define seg_size 524288
ll dp[101][100000];
int main(){
    int n,W;
    cin>>n>>W;
    vector<int>w(n+1),v(n+1);
    for(int i=1;i<n+1;i++)cin>>w[i]>>v[i];
    rep(i,W+1)dp[0][i]=0;
    for(int i=1;i<n+1;i++){
        for(int j=0;j<W+1;j++){
            if(j-w[i]>=0)dp[i][j]=max(dp[i-1][j],dp[i-1][j-w[i]]+v[i]);
            else dp[i][j]=dp[i-1][j];
        }
    }
    cout<<dp[n][W]<<endl;
    return 0;
}

Measured memory_bytes: 79104
num = int(input())

alice = 0
bob = 0
cards = list(map(int,input().split()))
for i in range(1,num+1):
    
    if i % 2 == 1:
        alice += max(cards)
        cards.remove(max(cards))
    else:
        bob += max(cards)
        cards.remove(max(cards))

ans = alice - bob
print(ans)
        

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

using namespace std;

int n,s[50],dp[55][2005],book[55][2005];

int solve(int i,int m)
{
    if(book[i][m]){
        return dp[i][m];
    }
	if(m==0){
        book[i][m]=1;
		dp[i][m]=1;
		return dp[i][m];
	}else if(i>=n){
	    book[i][m]=1;
		dp[i][m]=0;
		return dp[i][m];
	}
	if(solve(i+1,m)){
        book[i][m]=1;
        dp[i][m]=1;
	}else if(solve(i+1,m-s[i])){
	    book[i][m]=1;
        dp[i][m]=1;
    }else{
        book[i][m]=1;
        dp[i][m]=0;
    }
	return dp[i][m];
}

int main()
{
	int q,m;
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		scanf("%d",&s[i]);
	}
	scanf("%d",&q);
	for(int i=0;i<q;i++){
		scanf("%d",&m);
		if(solve(0,m)){
			printf("yes\n");
		}else{
			printf("no\n");
		}
	}
	return 0;
}


Measured memory_bytes: 3464
#include <bits/stdc++.h>
typedef long long ll;
#define MX 100000
#define PB push_back
ll MOD = 1e9 + 7;
using namespace std;
bool dp[MX + 5];
int main() {
	int n, k;
	cin >> n >> k;
	vector <int> vec(n);
	for (int &x : vec)
		cin >> x;
    for (int i = 0; i <= k; ++i) {
    	for (int x : vec) {
    		if(i >= x and !dp[i - x])
    			dp[i] = true;
    	}
    }
	if (dp[k])
		cout << "First" << endl;
	else
		cout << "Second" << endl;

}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#include <iomanip>
#include <math.h>
#include <unistd.h>
#include <stdio.h>
#define rep(i,x) for(ll i = 0;i<x;i++)
#define all(a) (a).begin(),(a).end()
#define vecin(a) rep(i,a.size())cin >> a[i]
#define vecout(a) rep(i,a.size()){cout << a[i];cout << (i == a.size() - 1 ? "\n":" ");}
#define mp make_pair
using ll = long long;
using ld = long double;
using namespace std;
using dou = double;
const ll inf = 2147483647;
const ll INF = 1LL << 60;
const dou pi = 3.14159265358;
const ll mod = 1000000007LL;
typedef pair<ll,ll> P;
using graph = vector<vector<ll>>;
template<class T> inline bool chmax(T& a, T b){if(a < b){a = b; return true;}return false;}
template<class T> inline bool chmin(T& a, T b){if(a > b){a = b; return true;}return false;}
template<class T> inline bool change(T a,T b){if(a > b){swap(a,b);return true;}return false;}
ll gcd(ll a,ll b){
    if(a < b)swap(a,b);
    if(a % b == 0)return b;
    else return gcd(b,a%b);
}
ll lcm(ll a,ll b){
    return a / gcd(a,b) * b;
}

//素数判定O(sqrt(N))
bool isp(ll n){
    bool res = true;
    if(n == 1)return false;
    else{
        for(ll i = 2;i * i <= n;i++){
            if(n % i == 0){
                res = false;
                break;
            }
        }
        return res;
    }
}
const ll cmax = 1000000;
ll fac[cmax], finv[cmax], inv[cmax];

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

// 二項係数計算
ll nCk(ll n, ll k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % mod) % mod;
}
//nのm乗をMODで割ったあまりO(logN)
ll modpow(ll n,ll m,ll MOD){
    ll res = 1;
    while(m){
        if(m & 1)res = (res * n) % MOD;
        m >>= 1;
        n *= n;
        n %= MOD;
    }
    return res;
}

//printf("%.10f\n", N);
/*  vector<ll> vec = {1,2,5,6,8,9,10};
    cout << binary_search(all(vec),5) << endl; -> true*/
/*
    vector<ll> vec = {1,2,5,6,8,9,10};
    auto n = upper_bound(all(vec),4);
    cout << *n << endl; -> 5*/

//    cout << fixed << setprecision(15);

ll N;
const ll NMAX = 100005;
struct edge{ll to,cost;};
vector<vector<edge>> G(NMAX);
vector<ll> dist(NMAX,INF);
void dfs(ll from,ll par){
    for(auto e : G[from]){
        if(e.to != par){
            dist[e.to] = dist[from] + e.cost;
            dfs(e.to,from);
        }
    }
}
vector<ll> ans(NMAX);
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin >> N;
    ll a,b,c;
    rep(i,N - 1){
        cin >> a >> b >> c;
        a--;b--;
        G[a].push_back({b,c});
        G[b].push_back({a,c});
    }
    dist[0] = 0;
    dfs(0,-1);
    rep(i,N){
        if(dist[i] % 2 == 1)ans[i] = 1;
    }
    rep(i,N){
        cout << ans[i] << "\n";
    }
}

Measured memory_bytes: 13680
#include <bits/stdc++.h>
#define l_ength size
const int inf = (1<<30);
const int mod = 1000000007;
using ll = long long;
using namespace std;

int main(){
	int a, b, c; cin >> a >> b >> c;
    bool flag = false;
  	for( int k = 0; k < b; ++k ){
		if( a*k % b == c ) flag = true;
	}
	cout << ( flag ? "YES" : "NO" ) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < int(n); ++i)
#define all(c) (c).begin(), (c).end()

template <class T, class U>
inline bool chmin(T& t, const U& f) { return t > f ? t = f, true : false; }

const int DMAX = 110, INF = 1 << 12;

int solve(int T, const vector<int>& t, const vector<int>& interview) {
    vector<int> dp(T, INF); dp[0] = 0;
    for (const int& M : interview) {
        vector<int> nxt(T, INF);
        rep(i, T) {
            if (M >= t[i]) chmin(nxt[(i + 1) % T], dp[i]);
            chmin(nxt[1], dp[i] + 1);
        }
        dp.swap(nxt);
    }
    return *min_element(all(dp));
}

int main() {
    for (int T; cin >> T, T;) {
        vector<int> t(T);
        for (int& e : t) cin >> e;
        int N; cin >> N;
        vector<int> interview(DMAX, INF);
        while (N--) {
            int D, M; cin >> D >> M;
            chmin(interview[D - 1], M);
        }
        cout << solve(T, t, interview) << endl;
    }
}

Measured memory_bytes: 3000
#include <iostream>
#include <sstream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>

using namespace std;

#define FOR(i,k,n) for(int i=(k); i<(int)(n); ++i)
#define REP(i,n) FOR(i,0,n)
#define FORIT(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

template<class T> void debug(T begin, T end){ for(T i = begin; i != end; ++i) cerr<<*i<<" "; cerr<<endl; }
inline bool valid(int x, int y, int W, int H){ return (x >= 0 && y >= 0 && x < W && y < H); }

typedef long long ll;
const int INF = 1000000000;
const double EPS = 1e-8;
const int MOD = 1000000007;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};

int main(){
  int N;
  while(cin>>N && N){
    int hp[100];
    REP(i, N) cin>>hp[i];
    int M; cin>>M;
    int mp[100], pow[100], type[100];
    REP(i, M){
      string s; cin>>s;
      cin>>mp[i];
      cin>>s;
      if(s == "Single") type[i] = 0;
      else type[i] = 1;
      cin>>pow[i];
    }
    ll dp[2][100001];
    REP(i, 2) fill(dp[i], dp[i] + 100001, 1e16);
    dp[0][0] = 0, dp[1][0] = 0;
    REP(from, 100000){
      REP(i, M){
        int to = from + pow[i];
        if(to > 100000) to = 100000;
        dp[type[i]][to] = min(dp[type[i]][to], dp[type[i]][from] + mp[i]);
      }
    }
    for(int j = 100000; j > 0; j--) dp[0][j - 1] = min(dp[0][j - 1], dp[0][j]);
    ll ans = 1e16;
    REP(all, 100001){
      ll sub_ans = dp[1][all];
      if(sub_ans == 1e16) continue;
      REP(i, N){
        if(hp[i] - all > 0){
          sub_ans += dp[0][hp[i] - all];
        }
      }
      ans = min(ans, sub_ans);
    }
    cout<<ans<<endl;
  }

  return 0;
}

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


using namespace std;

const int INF = 2e9 + 3;
const int N = 1e2 + 3;
const int MOD = 1e9 + 7;
const double EPS = 1e-9;

const double PI = acos(-1);


void solve() {
    int x;
    cin >> x;
    cout << (x >= 30 ? "Yes" : "No");
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    int t;
    t = 1;
    while (t--) {
        solve();
    }
}

Measured memory_bytes: 3624
#include <iostream>

using namespace std;

int P[114514];

int main() {
    int N;
    int ans = 0;
    cin >> N;
    for (int i = 0; i < N; i++) {
        cin >> P[i];
    }

    for (int i = 0; i < N; i++) {
        if (P[i] == i + 1) {
            int l = i;
            while (P[i] == i + 1) {
                i++;
            }
            int len = i - l;
            ans += (len + 1) / 2;
        }
    }

    cout << ans << endl;
}


Measured memory_bytes: 640
//RRLRRLLRL
//focus only on rl intersections
//everything will end up there
//for every r - l intersection I have the count
#include<bits/stdc++.h>
using namespace std;
string s;
int n;
int main(){
	 cin>>s;
  	 n = s.size();
  vector<int >nosr;
  vector<int >nosl;
  vector<int >fin(n,0);
  int curr=0;
  //cout<<s<<'\n';
  	for(int i=0;i<s.size();i++){
      	if(s[i]=='L')continue;
    	if(s[i]=='R' && s[i+1]!='L')curr++;
      else {curr++;nosr.push_back(curr);curr=0;}
    }

  curr=0;
    	for(int i=s.size()-1;i>=0;i--){
      	if(s[i]=='R')continue;
    	if(s[i]=='L' && s[i-1]!='R')curr++;
      else {curr++;nosl.push_back(curr);curr=0;}
    }

  reverse(nosl.begin(),nosl.end());
 // cout<<nosr.size()<<' '<<nosl.size()<<'\n';
  int j=0;
  
  for(int i=0;i<n ;i++){
  	if((s[i]=='R' && s[i+1]=='L')){
      fin[i]=ceil(nosr[j]/2.0)+floor(nosl[j]/2.0);
      fin[i+1]=ceil(nosl[j]/2.0)+floor(nosr[j]/2.0);
      j+=1;
      i+=1;
    }
  }
  for(int i=0;i<n;i++)cout<<fin[i]<<' ';
  //rrrlll
  
}

Measured memory_bytes: 4416
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#define print(x) printf("%d",x)
#define scan(x) scanf("%d",&x)
#define printn(x) printf("%d\n",x)
#define rep(i,n,m) for(int i = n; i < m; i++)

int main(void){
	int i,n,x;
	int max = -pow(10,9);
	int min;
	
	
	scan(n);
	rep(i,0,n){
		scan(x);
		
		if(max < x - min && i != 0){
			max = x - min;
		}
		if(i == 0){
			min = x;
		}else if(min > x){
			min = x;
		}
	}
	printn(max);
	return 0;
}


Measured memory_bytes: 2100
N = input()
li = list(map(int, input().split()))

ans_count = 0
while(True):
    flag = True
    for x in li:
        if x % 2 != 0:
            flag = False

    if flag:
        li = list(map(lambda x: int(x/2), li))
        ans_count += 1
    else:
        break

print(ans_count)

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

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = (n) - 1; i >= 0; i--)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (a); i > (b); i--)
#define ALL(a) (a).begin(), (a).end()

vector<int> get_lens(string s, int size) {
    vector<int> ret;
    int c = 1;
    char ch = s[0];
    FOR(i, 1, size) {
        if (s[i] != ch) {
            ret.push_back(c);
            ch = s[i];
            c = 1;
        }
        else {
            c++;
        }
    }
    if (c != 0) ret.push_back(c);
    return ret;
}

int main() {
    int N, K;
    string s;
    cin >> N >> K >> s;
    vector<int> lens = get_lens(s, N);
    if ((s[0] == '1' && lens.size() <= 2 * K + 1) || (s[0] == '0' && lens.size() <= 2 * K)) {
        cout << N << endl;
        return 0;
    }

    int sum = 0, sm = 0;
    if (s[0] == '1') {
        REP(i, 2 * K + 1) {
            sum += lens[i];
        }
        sm = sum;
        int l = 0, r = 2 * K + 1;
        while (r < lens.size()) {
            sum -= lens[l] + lens[l + 1];
            sum += lens[r] + ((r + 1 < lens.size()) ? lens[r + 1] : 0);
            l += 2;
            r += 2;
            sm = max(sm, sum);
        }
    }
    else {
        REP(i, 2 * K) {
            sum += lens[i];
        }
        sm = sum;
        bool first = true;
        int l = 0, r = 2 * K;
        while (r < lens.size()) {
            if (first) {
                sum -= lens[l];
                sum += lens[r] + ((r + 1 < lens.size()) ? lens[r + 1] : 0);
                l += 1;
                r += 2;
                first = false;
            }
            else {
                sum -= lens[l] + lens[l + 1];
                sum += lens[r] + ((r + 1 < lens.size()) ? lens[r + 1] : 0);
                l += 2;
                r += 2;
            }
            sm = max(sm, sum);
        }
    }
    cout << sm << endl;
    return 0;
}

Measured memory_bytes: 1148
#include<bits/stdc++.h>
#define int long long
#define mod 1000000007
#define trace(x) cerr<<#x<<": "<<x<<" "<<endl
#define tarce(x) cerr<<#x<<": "<<x<<" "<<endl
#define trace2(x, y) cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z) cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define sa(a,n) for(int i =0 ; i<n ; i++) cin>>a[i]
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define pb push_back
#define inf 2e18
#define scan() int n; cin>>n ; int a[n]; for(int i = 0 ; i<n ; i++) cin>>a[i]
#define print(a,n) for(int i = 0 ; i < n ; i++) cout<<a[i]<<' '
#define mem(a,v) memset(a,v,sizeof(a))
#define pii pair<int,int>
#define mkp make_pair
using namespace std;
#define N 200005


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

        int n;
        cin >> n;
        int i,a[n+2],b[n+1];
        int ans=0;
        for(i=1; i<=(n+1); i++) cin >> a[i];
        for(i=1; i<=n; i++) cin >> b[i];
        for(i=1; i<=n; i++){
            if(a[i]>b[i]){
                ans+=b[i];
                a[i]=a[i]-b[i];
                b[i]=0;
            }
            else{
                ans+=a[i];
                b[i]=b[i]-a[i];
                a[i]=0;
                if(a[i+1]>b[i]){
                    ans+=b[i];
                    a[i+1]=a[i+1]-b[i];
                }
                else{
                    ans+=a[i+1];
                    a[i+1]=0;
                }
            }
        //    tarce(ans);
        }
        cout << ans << '\n';

        
        

}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#include <stdio.h>
 
using namespace std;
 
#define int long long
 
void solve();

signed main () {
	cout.precision(10);
	ios_base::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	#ifdef LOCAL
		freopen("input.txt", "r", stdin);
	#endif
	int t = 1; 
	// cin >> t;
	int tt = t;
	while (t--) { 
		solve();
	}
	return 0;
}

void solve() {
	int a, b;
	cin >> a >> b;
	cout << max(0ll, a - 2 * b);
}		


Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
using namespace std;
int main()
{
	int a, b;
	scanf("%2d%2d", &a, &b);
	if (a == 0) {
		if (1 <= b && b <= 12) {
			cout << "YYMM" << endl;
		}
		else {
			cout << "NA" << endl;
		}
	}
	else if (1 <= a && a <= 12) {
		if (1 <= b && b <= 12) {
			cout << "AMBIGUOUS" << endl;
		}
		else {
			cout << "MMYY" << endl;
		}
	}
	else {
		if (1 <= b && b <= 12) {
			cout << "YYMM" << endl;
		}
		else {
			cout << "NA" << endl;
		}
	}
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstdio>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cmath>
#include <functional>
#include <numeric>
#include <iomanip>
#define fi first
#define se second
#define fcout(n) cout<<fixed<<setprecision((n))
#define cinl(str) getline(cin,(str))
using namespace std;
bool value(int y,int x,int R,int C){return 0<=y&&y<R&&0<=x&&x<C;}
typedef pair<int,int> pii;
typedef long long ll;
typedef vector<int> vi;
typedef vector<long long > vll;
typedef vector< vi > vvi;
double pie=acos(-1);
int INF=1000000007;
int dx[4] = { 0,-1,0,1 };
int dy[4] = { -1,0,1,0 };


int main() {
	int a,b;
	cin>>a>>b;
	if(a==1) a=14;
	if(b==1) b=14;
	if(a>b){
		cout<<"Alice"<<endl;
	}
	else if(a<b){
		cout<<"Bob"<<endl;
	}
	else{
		cout<<"Draw"<<endl;
	}
}

Measured memory_bytes: 256
#include <string>
#include <vector>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <map>
#include <list>
#include <set>
#include <numeric>
#include <queue>
#include <stack>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <climits>
#include <cfloat>
#include <ctime>
#include <complex>
#include <cassert>
#include <iomanip>
using namespace std;
typedef long long LL;
typedef pair<int,int> P;

int N,K;
int pos[50][2][3];
vector<int> v[3];
int table[100][100][100];
int main() {
	cin >> N >> K;
	for(int i=0;i<N;i++){
		for(int j=0;j<2;j++){
			for(int k=0;k<3;k++){
				cin >> pos[i][j][k];
				v[k].push_back(pos[i][j][k]);
			}
		}
	}
	for(int i=0;i<3;i++){
		sort(v[i].begin(),v[i].end());
		v[i].resize(unique(v[i].begin(),v[i].end())-v[i].begin());
	}
	for(int i=0;i<N;i++){
		int p2[2][3];
		for(int j=0;j<2;j++){
			for(int k=0;k<3;k++){
				p2[j][k]=lower_bound(v[k].begin(),v[k].end(),pos[i][j][k])-v[k].begin();
			}
		}
		for(int a=0;a<2;a++){
			for(int b=0;b<2;b++){
				for(int c=0;c<2;c++){
					int d=(a+b+c)%2==0?1:-1;
					table[p2[a][0]][p2[b][1]][p2[c][2]]+=d;
				}
			}
		}
	}
	for(int i=0;i<v[0].size();i++){
		for(int j=0;j<v[1].size();j++){
			for(int k=1;k<v[2].size();k++){
				table[i][j][k]+=table[i][j][k-1];
			}
		}
	}
	for(int i=0;i<v[0].size();i++){
		for(int j=1;j<v[1].size();j++){
			for(int k=0;k<v[2].size();k++){
				table[i][j][k]+=table[i][j-1][k];
			}
		}
	}
	for(int i=1;i<v[0].size();i++){
		for(int j=0;j<v[1].size();j++){
			for(int k=0;k<v[2].size();k++){
				table[i][j][k]+=table[i-1][j][k];
			}
		}
	}
	LL ret=0;
	for(int i=0;i+1<v[0].size();i++){
		LL x=v[0][i+1]-v[0][i];
		for(int j=0;j+1<v[1].size();j++){
			LL y=v[1][j+1]-v[1][j];
			for(int k=0;k+1<v[2].size();k++){
				if(table[i][j][k]>=K){
					LL z=v[2][k+1]-v[2][k];
					ret+=x*y*z;
				}
			}
		}
	}
	cout << ret << endl;
}

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

using namespace std;
typedef long long ll;

int main() {
    int h, n, a;
    cin >> h >> n;

    ll sum = 0;
    for (int i = 0; i < n; i++) {
        cin >> a;
        sum += a;
    }

    if (h <= sum) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>

int main(){
	int Tc, Ca=0, Cw=0, Ct=0, Cr=0;
	scanf ("%d", &Tc);
	char code[4];
	
	for(int i=0; i<Tc; i++){
		code[4];
		scanf("%s\n", &code);
			
			if (code[0]=='A'){
				Ca++;
			}
			else if (code[0]=='W'){
				Cw++;
			}
			else if (code[0]=='T'){
				Ct++;
			}
			else if (code[0]=='R'){
				Cr++;
			}
			else {
				continue;
			}
	}
	printf ("\n");
	printf ("AC x %d\n", Ca);
	printf ("WA x %d\n", Cw);
	printf ("TLE x %d\n", Ct);
	printf ("RE x %d\n", Cr);

return 0;
}

Measured memory_bytes: 1700
from collections import deque


def main():
    n, m = map(int, input().split())
    es = [[] for _ in range(n+1)]
    ans = [0 for _ in range(n+1)]

    for _ in range(m):
        a, b = map(int, input().split())
        es[a].append(b)
        es[b].append(a)

    q = deque([1])
    while len(q) > 0:
        p = q.popleft()

        for t in es[p]:
            if ans[t] > 0:
                continue
            ans[t] = p
            q.append(t)

    if 0 in ans[2:]:
        print("No")
    else:
        print("Yes")
        for a in ans[2:]:
            print(a)


if __name__ == '__main__':
    main()


Measured memory_bytes: 99476
#include<stdio.h>
int main()
{
    int a,b,k,i,count=0,d;
    int s[100];
    scanf("%d %d %d",&a,&b,&k);
    for(i=1;i<=a || i<=b;i++)
    {
        if(a%i==0 && b%i==0)
        {
            s[count]=i;
            count++;
        }
    }
    printf("%d\n",s[count-k]);
    return 0;
}


Measured memory_bytes: 1700
#include <bits/stdc++.h>
//#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
#define pb push_back
#define IOS                                                                    \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(0);                                                                  \
  cout.tie(0);cout<<fixed<<setprecision(16);
#define ll long long int
#define ld long double
#define el '\n'
#define El '\n'
#define PI (ld)3.141592653589793238462643383279502884197169399375105820974944
#define inf (ll)1000000000
#define mod (ll)1000000007
#define mod1 (ll)998244353
#define fo(i, n) for (long long i = 0; i < n; i++)
#define pll pair<ll, ll>
#define ml map<ll,ll>
#define vpl vector<pll>
#define vvl vector<vector<ll> >
#define vvpl vector< vector<pll> >
#define ff first
#define ss second
#define pqueue priority_queue< ll >
#define pdqueue priority_queue< ll,vl ,greater< ll > >
#define mem(a,b) memset(a,b,sizeof(a));
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define sz(a) (ll)a.size()
#define f(i,a,b) for(ll i=a;i<b;i++)
#define fd(i,a,b) for(ll i=a;i>=b;i--)
#define all(a) a.begin(),a.end()
#define vl vector<ll>
//#define x ff
//#define y ss
#define pt(a) for(auto it:a)cout<<it<<" ";cout<<endl;
unsigned seed = std::chrono::system_clock::now().time_since_epoch().count();
using namespace std;

// vector
template<class T> istream& operator >> (istream &is , vector<T> &v) { for(T &a : v) is >> a; return is; }
template<class T> ostream& operator << (ostream &os , const vector<T> &v) { for(const T &t : v) os << t<<" "; return os << endl; }
// pair
template<class T, class U> ostream& operator << (ostream &os , const pair<T, U> &v) { return os << v.first << " " << v.second ; }

double gcd(double a, double b) { return a < 0.01 ? b : gcd(fmod(b, a), a); }

long long bpow(long long a, long long b, long long m) {
  a %= m;
  long long res = 1;
  while (b > 0) {
    if (b & 1)

      res = res * a % m;
      a = a * a % m;
      b >>= 1;
  }
  return res;
}


ll kv;
ll t,n,x,y,h,k,z,p,q,w,r;
string s[2000],s1,s2;
vvl v;
vl vis,d;

void dfs(int s){
    vis[s]=1;
    //cout<<s<<endl;
    for(int u:v[s])if(vis[u]==0)dfs(u);
    d.pb(s);
}

int main() {
    IOS;
    cin>>n>>k;
    fo(i,n){
        cin>>s[i];
    }
    vvl dp(n,vl(k,0));
    dp[0][0]=1;
    fo(i,n)fo(j,k){
        if(i>0&&s[i-1][j]=='.')dp[i][j]+=dp[i-1][j];
        if(j>0&&s[i][j-1]=='.')dp[i][j]+=dp[i][j-1];
        dp[i][j]%=mod;
    }
    cout<<dp[n-1][k-1];
    return 0;
}


Measured memory_bytes: 9216
#include <iostream>
#include <queue>
#include <map>
#include <iostream>
using namespace std;

struct p{
	int x, y;
};
typedef struct p P;
const int INF = 1e+7;
int dx[4] = {0,0,1,-1};
int dy[4] = {1,-1,0,0};

int w,h,n;
string m[1001];
P cheese[11];
int ans = 0;
int d[1001][1001];

void bfs(){
	for(int i=1 ; i <= n ; i++ ){
		P sp = cheese[i-1];
		int sx = cheese[i-1].x;
		int sy = cheese[i-1].y;
		int gx = cheese[i].x;
		int gy = cheese[i].y;
		for(int y=0 ; y < h ; y++ ){
			for(int x=0 ; x < w ; x++ ){
				d[y][x] = INF;
			}
		}
		
		queue<P> q;
		q.push( sp );
		d[sy][sx] = 0;
		while( !q.empty() ){
			P now = q.front();
			q.pop();
			int x = now.x;
			int y = now.y;
			if( x == gx && y == gy ){
				ans += d[gy][gx];
				break;
			}
			for(int i=0 ; i < 4 ; i++ ){
				int mx = x + dx[i];
				int my = y + dy[i];
				if( mx < 0 || my < 0 || mx >= w || my >= h ) continue;
				if( m[my][mx] != 'X' ){
					P next;
					
					next.x = mx;
					next.y = my;
					if( d[my][mx] == INF ){
						d[my][mx] = d[y][x] + 1;
						q.push( next );
					}
				}
			}
		}
	}
}

int main(){
	cin >> h >> w >> n;
	for(int y=0 ; y < h ; y++ ){
		cin >> m[y];
	}
	
	
	for(int y=0 ; y < h ; y++ ){
		for(int x=0 ; x < w ; x++ ){
			char c = m[y][x];
			if( c == 'S' ){
				cheese[0].x = x;
				cheese[0].y = y;
			}
			if( c >= '1' && c <= '9' ){
				cheese[ c - '0' ].x = x;
				cheese[ c - '0' ].y = y;
			}
		}
	}
	bfs();
	cout << ans << endl;
}

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

using ll = int64_t;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define ddrep(i, n) for (int i = n; i > 0; --i)
#define srep(i, s, t) for (int i = s; i < t; ++i)
#define ssrep(i, s, t) for (int i = s; i <= t; ++i)

#define rng(a) a.begin(), a.end()
#define pb push_back
#define eb emplace_back
#define fi first
#define se second

#define chmax(x, y) (x = max(x, y))
#define chmin(x, y) (x = min(x, y))

using pi = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using ld = long double;

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << "(" << p.first << "," << p.second << ")";
  return os;
}

template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
  os << "{";
  rep(i, (int)v.size()) {
    if (i)
      os << ",";
    os << v[i];
  }
  os << "}";
  return os;
}

template <typename T, size_t S> void printArray(const T (&array)[S]) {
  for (auto val : array)
    std::cout << val << ", ";
  std::cout << "\n";
}

const int mod = 1e9 + 7;
const int inf = 1e9 + 5;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << std::setprecision(10);

  int card[3][3];
  rep(i, 3) rep(j, 3) std::cin >> card[i][j];
  int n; std::cin >> n;
  vi b(n); rep(i, n) std::cin >> b[i];
  rep(i, 3) rep(j, 3) {
    int x = card[i][j];
    rep(k, n)
      if (card[i][j] == b[k]) card[i][j]= -1;
  }
  bool ok = false;
  rep(i, 3) {
    bool vok = true, hok = true;
    rep(j, 3) {
      if (card[i][j] != -1)
        hok = false;
      if (card[j][i] != -1)
        vok = false;
    }
    if (hok || vok) ok = true;
  }
  bool diag = true;
  rep(i, 3) if (card[i][i] != -1) diag = false;
  if (diag) ok = true;
  if (card[0][2] == card[1][1] && card[1][1] == card[2][0] && card[0][2] == -1)
    ok = true;
  std::cout << (ok ? "Yes" : "No") << "\n";
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
int main(void){
	int i,n,x,y,sq[15][15];
	while(scanf("%d",&n)){
		if(n==0)break;
		for(i=0,x=n/2,y=n/2-1;i<n*n;i++){
			if(i%n==0)y+=2;
			else{y++;x++;}
			y=y%n;x=x%n;
			sq[y][x]=i+1;
		}
		for(y=0;y<n;y++){
			for(x=0;x<n;x++){
				printf("%4d",sq[y][x]);
			}
			printf("\n");
		}
	}
	return 0;
}

Measured memory_bytes: 616
#include<bits/stdc++.h>
using namespace std;
int main()
{
    double a,b,c,d,e,f;
    double x,y;
    while(cin>>a>>b>>c>>d>>e>>f){
        x=(e*c-b*f)/(a*e-d*b);
        y=(a*f-c*d)/(a*e-d*b);
        if(x==-0)x=0;
        if(y==-0)y=0;
        printf("%.3lf %.3lf\n",x,y);
    }
}

Measured memory_bytes: 3168
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <stack>
using namespace std;
using ll = long long;
using ull = unsigned long long;
int main(int argc, char *argv[]) {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);//incompatible with `while (cin >> ...)'
    int N;
    cin >> N;
    bool flag = true;
    map<string, int> W;
    string L[N];
    string w;
    cin >> w;
    W.insert(pair<string, int>(w, 0));
    L[0] = w;
    for (int i = 1; i < N; i++) {
        cin >> w;
        if (!flag) {
            continue;
        }
        if (w[0] != L[i-1][L[i-1].length() - 1] || W.find(w) != W.end()) {
            flag = false;
        }
        else {
            W.insert(pair<string, int>(w, 0));
            L[i] = w;
        }
    }
    if (flag) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <time.h>
#include <iostream>
#include <algorithm>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <bitset>
#include <vector>
using namespace std;

#define bll long long
#define dou double
#define For(i,a,b) for (int i=(a),_##i=(b); i<=_##i; ++i)
#define Rof(i,a,b) for (int i=(a),_##i=(b); i>=_##i; --i)
#define Mem(a,b) memset(a,b,sizeof(a))
#define Cpy(a,b) memcpy(a,b,sizeof(b))

int main()
{
    int n;
    for (; scanf("%d",&n)!=EOF; )
    {
        int lx,ly,lt;
        lx=ly=lt=0;
        bool flag=1;
        For(i,1,n)
        {
            int x,y,t;
            scanf("%d%d%d",&t,&x,&y);
            if (!flag) continue;
            int need=abs(x-lx)+abs(y-ly);
            int tim=t-lt;
            if ((need>tim) || ((tim-need)&1)) flag=0;
            lx=x,ly=y,lt=t;
        }
        if (flag)
            printf("Yes\n");
        else
            printf("No\n");
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {
  string s;
  
  cin >> s;
  
  if (s == "Sunny") {
    cout << "Cloudy" << endl;
  } else if (s == "Cloudy") {
  	cout << "Rainy" << endl;
  } else {
  	cout << "Sunny" << endl;
  }
  
  return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
//using System.Text;
//using System.Text.RegularExpressions;
//using System.Globalization;
//using System.Diagnostics;
using static System.Console;
//using System.Numerics;
//using static System.Math;
//using pair = Pair<int, int>;

class Program
{
    static void Main()
    {
        //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
        new Program().solve();
        Out.Flush();
    }
    Scanner cin = new Scanner();
    readonly int[] dd = { 0, 1, 0, -1, 0 }; //→↓←↑
    readonly int mod = 1000000007;
    void chmax<T>(ref T a, T b) where T : IComparable<T> { a = a.CompareTo(b) < 0 ? b : a; }
    void chmin<T>(ref T a, T b) where T : IComparable<T> { a = a.CompareTo(b) < 0 ? a : b; }

    void solve()
    {
        var A = cin.scanint;
        WriteLine(A.Max() - A.Min());
    }

}

class Scanner
{
    string[] s; int i;
    char[] cs = new char[] { ' ' };
    public Scanner() { s = new string[0]; i = 0; }
    public string[] scan { get { return ReadLine().Split(); } }
    public int[] scanint { get { return Array.ConvertAll(scan, int.Parse); } }
    public long[] scanlong { get { return Array.ConvertAll(scan, long.Parse); } }
    public double[] scandouble { get { return Array.ConvertAll(scan, double.Parse); } }
    public string next
    {
        get
        {
            if (i < s.Length) return s[i++];
            string st = ReadLine();
            while (st == "") st = ReadLine();
            s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
            i = 0;
            return next;
        }
    }
    public int nextint { get { return int.Parse(next); } }
    public long nextlong { get { return long.Parse(next); } }
    public double nextdouble { get { return double.Parse(next); } }
}

Measured memory_bytes: 13268
#include <bits/stdc++.h>
#define ri register
#define int long long
#define E (n+1)
using namespace std; const int N=1000010;
inline int read()
{
    int s=0, w=1; ri char ch=getchar();
    while(ch<'0'||ch>'9') { if(ch=='-') w=-1; ch=getchar(); }
    while(ch>='0'&&ch<='9') s=(s<<3)+(s<<1)+(ch^48), ch=getchar();
    return s*w;
}
signed main()
{
    int a,b;
    a=read(), b=read();
    if((a*b)&1ll) puts("Odd");
    else puts("Even");
    return 0;
}

Measured memory_bytes: 3640
import itertools

n = int(input())
s = [input() for _ in range(n)]


def add(dict, str):
    if not str[0] in dict:
        dict[str[0]] = []
    dict[str[0]].append(str)


march = {}
for s_i in s:
    if 'M' == s_i[0] or 'A' == s_i[0] or 'R' == s_i[0] or 'C' == s_i[0] or 'H' == s_i[0]:
        add(march, s_i)

key_combination = list(itertools.combinations(list(march), 3))
count = 0
for case in key_combination:
    indiv_count = 1
    for key in case:
        if not key in march:
            indiv_count = 0
            break
        indiv_count *= len(march[key])
    count += indiv_count
print(count)


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

using namespace std;

#define MAXN 3005
#define INF 1000000000000000LL
#define MOD 10007
#define pb push_back

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

string s1, s2;
int dp[MAXN][MAXN];

//inline string maxV(string a, string b){ return a.size() > b.size() ? a : b; }

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

	cin >> s1 >> s2;

	int tamA = s1.size(), tamB = s2.size();

	for(int i = 1; i <= tamA; i++){
		for(int j = 1; j <= tamB; j++){
			if(s1[i - 1] == s2[j - 1]) dp[i][j] = dp[i - 1][j - 1] + 1;
			else dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
		}
	}

	string res = "";

	while(tamA > 0 && tamB > 0){
		if(s1[tamA - 1] == s2[tamB - 1]){
			res += s1[tamA - 1];
			tamA--, tamB--;
		} else if(dp[tamA - 1][tamB] > dp[tamA][tamB - 1]) tamA--;
		else tamB--;
	}

	res = string(res.rbegin(), res.rend());

	cout << res << endl;

	return 0;
}

Measured memory_bytes: 35456
//#include <bits/stdc++.h>
#include <iostream>
#include <complex>
#include <sstream>
#include <string>
#include <algorithm>
#include <deque>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <vector>
#include <set>
#include <limits>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <ctime>
#include <climits>
#include <iomanip>
#include <stack>
#include <bitset>

#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i, j, k) for(int i = (int)(j); i < (int)(k); ++i)
#define ROF(i, j, k) for(int i = (int)(j); i >= (int)(k); --i)
#define FORLL(i, n, m) for(long long i = n; i < (long long)(m); i++)
#define SORT(v, n) sort(v, v+n)
#define REVERSE(v) reverse((v).begin(), (v).end())

using namespace std;
using ll = long long;
const ll MOD=1000000007LL;
typedef pair<int, int> P;

ll ADD(ll x, ll y) { return (x+y) % MOD; }
ll SUB(ll x, ll y) { return (x-y+MOD) % MOD; }
ll MUL(ll x, ll y) { return x*y % MOD; }
ll POW(ll x, ll e) { ll v=1; for(; e; x=MUL(x,x), e>>=1) if (e&1) v = MUL(v,x); return v; }
ll DIV(ll x, ll y) { /*assert(y%MOD!=0);*/ return MUL(x, POW(y, MOD-2)); }

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

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

  int n;
  string s;
  cin >> n;
  vector<int> p(n);
  REP(i,n) cin >> p[i];
  int ans = 0;
  FOR(i,2,n) {
    vector<int> tmp;
    tmp.push_back(p[i-2]);
    tmp.push_back(p[i-1]);
    tmp.push_back(p[i]);
    sort(tmp.begin(), tmp.end());
    if(tmp[1] == p[i-1]) ans++;
    //if(p[i-2] < p[i-1] && p[i-1] < p)
  }    
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int N = 55;
struct data {
  int x, y;
} d[N * 2];
int a[N];

int main() {
  int n, be = 0, mx = 0;
  scanf("%d", &n);
  int res = 0;
  for(int i = 1; i <= n; ++i) {
    scanf("%d", &a[i]);
    if(abs(a[i]) > mx) {
      be = i;
      mx = abs(a[i]);
    }
  }
  if(!be) {
    puts("0");
    exit(0);
  }
  for(int i = 1; i <= n; ++i) {
    if(i != be) {
      d[++res] = (data) {be, i};
      a[i] += a[be];
    }
  }
  if(a[be] < 0) {
    for(int i = n; i >= 2; --i) {
      d[++res] = (data) {i, i - 1};
      a[i - 1] += a[i];
    }  
  } else {
    for(int i = 2; i <= n; ++i) {
      d[++res] = (data) {i - 1, i};
      a[i] += a[i - 1];
    }
  }
  printf("%d\n", res);
  for(int i = 1; i <= res; ++i) {
    printf("%d %d\n", d[i].x, d[i].y);
  }
  return 0;
}

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

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

    long long int counter = 1;
    set<long long int> already;
    already.insert(s);
    while(true){
        counter += 1;
        if(s % 2 == 0){
            s /= 2;
        }else{
            s = 3 * s + 1;
        }
        
        if(already.find(s) == already.end()){
            already.insert(s);
        }else{
            break;
        }
    }
    cout << counter << endl;
    return 0;
}

Measured memory_bytes: 256
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


def main():
    n,m = LI()
    a = ['#'*(m+2)] + ['#' + S() + '#' for _ in range(n)] + ['#'*(m+2)]
    st = (-1,-1,-1)
    for i in range(1,n+1):
        for j in range(m+1):
            c = a[i][j]
            if c == '^':
                st = (i,j,0,1)
            elif c == 'v':
                st = (i,j,2,1)
            elif c == '>':
                st = (i,j,1,1)
            elif c == '<':
                st = (i,j,3,1)
    v = collections.defaultdict(bool)
    vs = set()
    r = -1
    kb = [[(-1,1), (0,1), (1,1)], [(1,1),(1,0),(1,-1)], [(1,-1),(0,-1),(-1,-1)], [(-1,-1),(-1,0),(-1,1)]]
    while True:
        if v[st]:
            return -1
        v[st] = True
        i,j,di,ki = st
        vs.add((i,j))
        if a[i][j] == 'G':
            return len(vs)
        if ki < 2:
            if a[i+dd[di][0]][j+dd[di][1]] != '#':
                r += 1
                st = (i+dd[di][0], j+dd[di][1], di, ki+1)
            else:
                st = (i, j, (di-1)%4, 1)
        else:
            dk = (di+1) % 4
            if a[i+dd[dk][0]][j+dd[dk][1]] == '#':
                st = (i, j, di, 1)
            else:
                st = (i, j, dk, 0)

    return -1




print(main())



Measured memory_bytes: 9604
import java.lang.reflect.Array;
import java.util.Arrays;
import java.util.OptionalInt;
import java.util.Scanner;
import java.util.ArrayList;
import java.util.Collections;
import java.util.stream.Collectors;

public class Main {

    static Scanner sc = new Scanner(System.in);

    static class El implements Comparable<El> {
        int i;
        int A;
        public El(int i, int A) {
            this.i = i;
            this.A = A;
        }

        @Override
        public int compareTo(El o) {

            if(this.A < o.A) {
                return -1;
            } else if(this.A == o.A) {
                return 0;
            } else {
                return 1;
            }
        }
    }

    public static void main(String[] args) {
        int N = sc.nextInt();

        ArrayList<El> arr = new ArrayList<>();

        for(int i = 1; i <= N; i++) {
            arr.add(new El(i, sc.nextInt()));
        }

        arr = arr.stream().sorted().collect(Collectors.toCollection(ArrayList::new));

        for(El e : arr) {
            System.out.printf("%d ", e.i);
        }
    }
}
//[B@25618e91
//[B@326de728
//

Measured memory_bytes: 69520
#include <bits/stdc++.h>
using namespace std;
using Int = long long unsigned int;
typedef pair<int,int> P;
typedef priority_queue<int> Pr;
int const MOD = 1000000007;

int dp[2001][2001]; float dpf[2001][2001]={};

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

    int n; cin>>n; double a[n]; for (int i = 0; i < n; i++)cin>>a[i];
    double ans=0;
    for (int i = 0; i < n; i++){
        ans+=1/a[i];
    }
    cout<<setprecision(14)<<1/ans<<'\n';
}

Measured memory_bytes: 256
N = int(input())
P_locat = [int(i) for i in input().split()]
M = int(input())
P = [int(i) for i in input().split()]

for i in range(M):
    tmp_locat = P_locat[P[i]-1] + 1
    if tmp_locat <= 2019 :
        P_locat[P[i]-1] += 1
    if P[i] != N:
        if P_locat[P[i]-1] == P_locat[P[i]]:
            P_locat[P[i]-1] -= 1
for i in range(N):
    print(P_locat[i])


Measured memory_bytes: 5616
#include<bits/stdc++.h>
using namespace std;
const int maxn = 55;
typedef long long LL;
#define int LL
int readint(){
	int x=0,f=1;char s=getchar();
	#define sc (s=getchar())
	while(s<'0'||s>'9'){
		if(s=='-')
			f=-1;
		sc;
	}
	while(s>='0'&&s<='9'){
		x=(x<<3)+(x<<1)+(s^48);
		sc;
	}
	#undef sc
	return x*f;
}
int n,m,q;
int a[maxn],b[maxn],c[maxn],d[maxn];
int ans[maxn];
int maxx=0;
void compare(){
	int sum=0;
	for(int i=1;i<=q;i++){
		if(ans[b[i]]-ans[a[i]]==c[i])
			sum+=d[i];	
	}
	maxx=max(maxx,sum);
}
void dfs(int ind,int last){
	if(ind==n+1){
		compare();
		return;
	}
	for(int i=last;i<=m;i++){
		ans[ind]=i;
		dfs(ind+1,i);
		ans[ind]=0;
	}
}
signed main(){
	n=readint(),m=readint(),q=readint();
	for(int i=1;i<=q;i++){
		a[i]=readint(),b[i]=readint(),c[i]=readint(),d[i]=readint();
	}
	dfs(1,1);
	cout<<maxx;
	return 0;
}

Measured memory_bytes: 3592
#include<bits/stdc++.h>
using namespace std;
 
int a[10001];
int main()
{
	ios::sync_with_stdio(false);
	int n;
	cin>>n;
	long long s=0,s2=0;
	for(int i=1;i<=n;i++) cin>>a[i],s-=a[i];
	for(int i=1;i<=n;i++){
		int x;
		cin>>x;
		s+=x;
		if(a[i]<x) s2+=ceil((x-a[i])/2.0);
	}
	if(s2<=s) cout<<"Yes";
	else cout<<"No";
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <unordered_set>
#include <cstring>

using namespace std;

const int INF = 1e9 + 5;

int main() {

    int n;
    scanf("%d", &n);
    int k;
    scanf("%d", &k);
    vector<int> h(n);
    for(int& x : h) {
        scanf("%d", &x);
    }
    vector<int> dp(n, INF);

    dp[0] = 0;
    for(int i = 0; i < n; i++) {
        for(int j =  i + 1; j <= i + k; j++ ) {
            if (j < n) {
                dp[j] = min(dp[j], dp[i] + abs(h[i] - h[j]));
            }
        }
    }

    cout << dp[n-1] << endl;


    return 0;
}

Measured memory_bytes: 1152
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
#include <stack>
#include <functional>

#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; ++i)
#define repp(i, m, n) for(ll i = m, i##_len = (n); i < i##_len; ++i)
#define reprev(i, n) for(ll i = (n-1LL); i >= 0; --i)
#define all(x) (x).begin(), (x).end()
template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template <class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }
template <class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair <int,int> P;
typedef long double ld;


int main(void)
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	int h, w, k;
	cin >> h >> w >> k;
	string s[h];
	rep (i, h) cin >> s[i];
	vector<P> str;
	rep (i, h) rep (j, w) if (s[i][j] == '#') str.emplace_back(i, j);
	int board[h][w];
	rep (i, h) rep (j, w) board[i][j] = -1;
	// vector<int> kara;
	// int now = -1;
	// rep (i, k) {
	// 	if (str[i].first > now) {
	// 		if (str[i].first - now > 1) {
	// 			repp (j, now + 1, str[i].first) {
	// 				kara.push_back(j);
	// 			}
	// 		}
	// 		now = str[i].first;
	// 	}
	// }
	// if (str.back().first < h - 1) {
	// 	repp (i, str.back().first, h) {
	// 		kara.push_back(i);
	// 	}
	// }
	// int count = 0;
	// // うえからみていけばよさそう。
	// rep (i, h) {
	// 	// 空行は一旦保留
	// 	if (!any_of(kara.begin(), kara.end(), [&](int x){return x == i;})) {
	// 	}
	// }
	rep (i, k) {
		board[str[i].first][str[i].second] = i + 1;
	}
	// ue kara
	repp (i, 1, h) {
		rep (j, w) {
			if (board[i][j] == -1) board[i][j] = board[i - 1][j];
		}
	}
	// shita kara
	for (int i = h - 2; i >= 0; i--) {
		rep (j, w) {
			if (board[i][j] == -1) board[i][j] = board[i + 1][j];
		}
	}
	// hidari kara
	rep (i, h) {
		repp (j, 1, w) {
			if (board[i][j] == -1) board[i][j] = board[i][j - 1];
		}
	}
	// migi kara
	rep (i, h) {
		for (int j = w - 2; j >= 0; j--) {
		// repp (j, 1, w) {
			if (board[i][j] == -1) board[i][j] = board[i][j + 1];
		}
	}
	rep (i, h) {
		rep (j, w) {
			cout << board[i][j] << (j != w - 1 ? ' ' : '\n');
		}
	}
	return 0;
}

Measured memory_bytes: 2036
// INCLUDES
#include <bits/stdc++.h>
//DEFINES
#define pii pair<int, int>
#define c1 __builtin_popcount
#define F first
#define S second
#define all(s) begin(s),end(s)
#define MIN3POS(a, b, c) (a) =< (b) ? ((a) =< (c) ? 1 : 3) : ((b) =< (c) ? 2 : 3)
#define MAX3POS(a,b,c) (a) >= (b) ? ((a) >= (c) ? 1 : 3) : ((b) >= (c) ? 2:3)
#define endl '\n'
#define ll long long
#define ui unsigned int
#define FOR(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define IOS   ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
//NAMESPACES
using namespace std;
vector<string> vec_splitter(string s) {
    s += ',';
    vector<string> res;
    while(!s.empty()) {
        res.push_back(s.substr(0, s.find(',')));
        s = s.substr(s.find(',') + 1);
    }
    return res;
}
void debug_out(
vector<string> __attribute__ ((unused)) args,
__attribute__ ((unused)) int idx, 
__attribute__ ((unused)) int LINE_NUM) { cerr << endl; } 
template <typename Head, typename... Tail>
void debug_out(vector<string> args, int idx, int LINE_NUM, Head H, Tail... T) {
    if(idx > 0) cerr << ", "; else cerr << "Line(" << LINE_NUM << ") ";
    stringstream ss; ss << H;
    cerr << args[idx] << " = " << ss.str();
    debug_out(args, idx + 1, LINE_NUM, T...);
}
#ifdef XOX
#define debug(...) debug_out(vec_splitter(#__VA_ARGS__), 0, __LINE__, __VA_ARGS__)
#else
#define debug(...) 42
#endif

void solve(){
int n;
cin>>n;
if(n>=400 && n <=599 ) cout<<8;
else if(n >=600 && n<=799) cout<<7;
else if(n>=800 && n<=999) cout<<6;
else if(n>=1000 && n<=1199) cout<<5;
else if(n>=1200 && n<=1399) cout<<4;
else if(n>=1400 && n<=1599) cout<<3;
else if(n>=1600 && n<=1799) cout<<2;
else cout<<1;
}
int32_t main()
{
IOS
int t=1;
// cin>>t;
while(t--) {
    solve();
}

return 0;
}
// Use emplace back in place of pushback
// Use tie function , for object destructuring

Measured memory_bytes: 3604