akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

int main()
{
	int n, m;
	cin >> n;
	
	vector<string> s(n);
	for(int i = 0; i < n; i++)
	{
		cin >> s[i];
	}
	
	cin >> m;
	vector<string> t(m);
	for(int i = 0; i < m; i++)
	{
		cin >> t[i];
	}
	
	int ans = 0;
	for(int i = 0; i < n; i++)
	{
		int tmp = 0;
		for(int j = 0; j < n; j++)
		{
			if(s[i] == s[j])
			{
				tmp++;
			}
		}
		
		for(int j = 0; j < m; j++)
		{
			if(s[i] == t[j])
			{
				tmp--;
			}
		}
		if(ans < tmp)
		{
			ans = tmp;
		}
	}
	
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <set>
#include <map>
#include <algorithm>

#define int long long
#define MOD7 1000000007
#define MOD9 1000000009

#define rep(i, n) for (int i = 0; i < (n); i++)
#define REP(i, a, n) for (int i = (a); i <= (n); i++)
#define all(a) (a).begin(), (a).end()

using namespace std;

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

int nextInt() {int a; cin >> a; return a;}
char nextChar() {char a; cin >> a; return a;}
double nextDouble() {double a; cin >> a; return a;}
string nextString() {string a; cin >> a; return a;}

template<class T> void inputVector(vector<T>& v, int n) {
    v.resize(n);
    for (int i = 0; i < v.size(); i++) cin >> v[i];
}

signed main() {
	int H, W;
	cin >> H >> W;

	int ret = INT_MAX;
	REP(x, 1, W - 1) {
		int maxS, minS;
		int s1 = H * x;

		int s2 = (W - x) / 2 * H;
		int s3 = (W - x + 1) / 2 * H;
		
		maxS = max(s1, max(s2, s3));
		minS = min(s1, min(s2, s3));
		if (minS > 0) {
			ret = min(ret, maxS - minS);
		}

		s2 = H / 2 * (W - x);
		s3 = (H + 1) / 2 * (W - x);

		maxS = max(s1, max(s2, s3));
		minS = min(s1, min(s2, s3));

		if (minS > 0) {
			ret = min(ret, maxS - minS);
		}
	}

	REP(y, 1, H - 1) {
		int maxS, minS;
		int s1 = W * y;

		int s2 = (H - y) / 2 * W;
		int s3 = (H - y + 1) / 2 * W;
		
		maxS = max(s1, max(s2, s3));
		minS = min(s1, min(s2, s3));
		if (minS > 0) {
			ret = min(ret, maxS - minS);
		}

		s2 = W / 2 * (H - y);
		s3 = (W + 1) / 2 * (H - y);

		maxS = max(s1, max(s2, s3));
		minS = min(s1, min(s2, s3));

		if (minS > 0) {
			ret = min(ret, maxS - minS);
		}
	}

	cout << ret << endl;

    return 0;
}


Measured memory_bytes: 256
#import<cstdio>
#import<map>
#define I(M,A)for(i=0;i<M;i++)scanf("%d",&x),A[i+1]=A[i]+x;
main(){for(int n[1501],m[1501],o,a,b,i,j,x;scanf("%d%d",&a,&b),a;printf("%d\n",o)){std::map<int,int>z;*n=*m=o=0;I(a,n)I(b,m)for(i=0;i<=a;i++)for(j=0;j<=b;j++)z[n[i]+m[j]]++;for(std::map<int,int>::iterator p=z.begin();p!=z.end();p++)o+=p->second*(p->second-1)/2;}}

Measured memory_bytes: 18000
#include <bits/stdc++.h>
using namespace std;
int main() {
	int n; cin >> n;
	int a[n] = {};
	for (int i = 0; i < n; i++)
		cin >> a[i];
	int Xor = a[0];
	for (int i = 1; i < n; i++)
		Xor ^= a[i];
	for (int i = 0; i < n; i++)
		cout << (Xor ^ a[i]) << ' ';
}

Measured memory_bytes: 4268
#include<bits/stdc++.h>
using namespace std;
#define ll  long long
#define endl '\n'
#define FASTINOUT ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
const ll mod = 1000000007;
const double PI = 3.141592653589793238463;
const int N=5e5+10;
int main()
{
    FASTINOUT;
    ll y[3];
    cin>>y[0]>>y[1]>>y[2];
    sort(y,y+3);
    int k;
    cin>>k;
    while (k--)
        y[2]*=2;
    cout<<y[0]+y[1]+y[2]<<endl;
    return 0;
}


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

using namespace std;
using ll = long long;

#define REP(i, n) for (ll i = 0; i < n; i++)
#define INF 9223372036854775807
#define all(x) (x).begin(), (x).end()

ll ts = 1000000007;

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

  ll n;
  cin >> n;

  vector<int> a(n);
  REP(i, n) { cin >> a[i]; }

  sort(all(a));

  cout << a[n - 1] - a[0] << "\n";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast", "unroll-loops")
#define ll long long 
#define pii pair<int, int>
#define ull unsigned ll
#define f first
#define s second
#define FOR(i,a,b) for (int i=(a); i<(b); i++)
#define REP(i,n) for (int i=0; i<(n); i++)
#define RREP(i,n) for (int i=(n-1); i>=0; i--)
#define ALL(x) x.begin(),x.end()
#define SZ(x) x.size()
#define MNTO(a,b) a = min(a,(__typeof__(a))(b))
#define MXTO(a,b) a = max(a,(__typeof__(a))(b))
#define pb push_back
#define debug(x) cerr<<#x<<" is "<<x<<endl
using namespace std;

// #define int ll

const int maxn = 3e5+5;
const int iinf = 1<<29;
const ll inf = 1ll<<60;
const ll mod = 1e9+7;


void GG(){cout<<"-1\n"; exit(0);}

ll inv (int b){
	if (b==1) return 1;
	return inv(mod%b) * (mod - mod/b) %mod;
}

ll pow(ll a, ll n, ll mod = 1e9+7){ 
	ll re=1;
	while (n>0){
		if (n&1) re = re*a % mod;
		a = a*a %mod;
		n>>=1;
	}
	return re;
}



main(){
    ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    int n, k; cin>>n>>k;
    vector<int> v;
    REP(i,n){
        int in; cin>>in;
        v.push_back(in);
    }
    ll re = 0;
    REP(tl,min(k+1,n+1)){
        REP(tr, min(k+1, n+1)){
            if (tl+tr>k || tl + tr > n) break;
            vector<int> took;
            REP(i, tl) took.pb(v[i]);
            FOR(j, n-tr, n) took.pb(v[j]);
            int cc = k-tl-tr;
            sort(ALL(took), greater<int>());
            REP(i, cc){
                if (!took.size()) break;
                if (took.back()<0) took.pop_back();
            }
            ll ans = 0;
            for (int x : took){
                ans+=x;
            }
            MXTO(re, ans);
        }
    }
    cout<<re<<endl;
}	

Measured memory_bytes: 256
#include<cstdio>
const int MaxN=100010;
int N,A[MaxN],B[MaxN],deg[MaxN*2],X[MaxN];
struct edge{int to;bool del;edge*rev,*next;}E[MaxN*12],*ne=E,*fir[MaxN*2];
void link(int u,int v,bool d=1){
	*ne=(edge){v,0,ne+1,fir[u]};fir[u]=ne++;
	*ne=(edge){u,0,ne-1,fir[v]};fir[v]=ne++;
	if(d)deg[u]++,deg[v]++;
}
void dfs(int i){
	while(fir[i]){
		edge*e=fir[i];
		fir[i]=e->next;
		if(e->del)continue;
		e->del=e->rev->del=1;
		if(i&&i<=N&&e->to>N)X[i]++;
		if(i>N&&e->to&&e->to<=N)X[e->to]--;
		dfs(e->to);
	}
}
int main(){
	scanf("%d",&N);
	for(int i=1;i<=N;i++){
		scanf("%d",A+i);
		link(A[i]<0?0:A[i],i);
	}
	for(int i=1;i<=N;i++){
		scanf("%d",B+i);
		link(B[i]<0?0:B[i]+N,i+N);
	}
	for(int i=1;i<=N;i++){
		if(deg[i]+deg[i+N]&1)return puts("IMPOSSIBLE"),0;
		for(int j=deg[i]>deg[i+N]?deg[i]:deg[i+N];j--;)link(i,i+N,0);
	}
	dfs(0);
	puts("POSSIBLE");
	for(int i=1;i<=N;i++)printf("%d%c",X[i]," \n"[i==N]);
}

Measured memory_bytes: 45568
#include <bits/stdc++.h>
 
using namespace std;
 
#define FORE(i, a) for (auto i = a.begin(); i != a.end(); ++i)
#define REPU(i, a, b) for (int i = (a); i < (b); ++i)
#define REPD(i, a, b) for (int i = (a); i > (b); --i)
#define MEM(a, x) memset(a, x, sizeof(a))
#define ALL(a) a.begin(), a.end()
#define UNIQUE(a) a.erase(unique(ALL(a)), a.end())
 
vector<string> split(const string &s, char c) {
	vector<string> v; stringstream ss(s); string x;
	while (getline(ss, x, c)) v.push_back(x);
	return v;
}
#define DEBUG(args...) { vector<string> _v = split(#args, ','); err(_v.begin(), args); }
void err(vector<string>::iterator it) {}
template<typename T, typename... Args>
void err(vector<string>::iterator it, T a, Args... args) {
	cerr << "[DEBUG] " << it -> substr((*it)[0] == ' ', it -> length()) << " = " << a << '\n';
	err(++it, args...);
}
 
typedef long long ll;
const int MOD = 1000000007;
 
template<class T, class U> inline T tmin(T a, U b) { return (a < b) ? a : b; }
template<class T, class U> inline T tmax(T a, U b) { return (a > b) ? a : b; }
template<class T, class U> inline void amax(T &a, U b) { if (b > a) a = b; }
template<class T, class U> inline void amin(T &a, U b) { if (b < a) a = b; }
template<class T> T gcd(T a, T b) { while (b != 0) { T c = a; a = b; b = c % b; } return a; }
 
#define in(x) int x; cin >> x
#define ou(x) cout << x << endl
 
int main(int argc, char *argv[]) {
  ios_base::sync_with_stdio(false);
  int n; cin >> n;
  vector<int> a(n);
  REPU(i, 0, n) {
    cin >> a[i];
  }
  ll ans = 1;
  vector<int> mp(n, 0);
  int rem = 3;
  REPU(i, 0, n) {
    mp[a[i]]++;
    if (mp[a[i]] > 3) {
      puts("0"); return 0;
    }
    if (a[i] == 0) {
      ans = ans * (rem--) % MOD;
      continue;
    }
    if (mp[a[i] - 1] == 0) {
      puts("0"); return 0;
    }
    ans = ans * mp[a[i] - 1] % MOD;
    mp[a[i] - 1]--;
    
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 1024
const input = require('fs').readFileSync('/dev/stdin', 'utf8');
const lines = input.trim().split('\n');

const getMax = (limit, numbers) => {
	return 
}

const getHighestPriceSum = (budget, priceList) => {
	const sums= [];
	for (i=0; i<priceList.length; i++) {
		const leftAddend = priceList[i]
		for (j=0; j<priceList.length; j++) {
			if (i !== j) {
				const rightAddend = priceList[j]
				sums.push(leftAddend + rightAddend);
			}
		}
	}

	return sums.reduce((acc, next) => {
		if (next > acc) {
			if (next <= budget) {
				return next
			}
			return acc	
		}
		return acc
	}, 0);
};

let ctr = 0;

const dataSets = [];

const objHolder = {};

while (line = lines.shift()) {
	if (ctr % 2 === 0) {
		const budget = line.split(' ').map(Number)[1];
		objHolder.budget = budget;
	} else {
		const priceList = line.split(' ').map(Number);
		objHolder.priceList = priceList;
		
		const { budget } = objHolder;
		const highest = getHighestPriceSum(budget, priceList)
		if (highest === 0) {
			console.log('NONE')
		} else {
			console.log(highest)
		}
	}

	
	ctr++
}


Measured memory_bytes: 77260
#include<iostream>
#include <string>
using namespace std;
int main()
{
    // 整数の入力
    string str_s;
    string str_t;
    cin >> str_s;
    cin >> str_t;

//    cout << str_s;
//    cout << str_t;

    int ans = 0;
    for(int i = 0; i < str_s.size(); i++) {
      if(str_s[i] != str_t[i]) {
        ans++;
      }
    }

    cout << ans;

    return 0;
}


Measured memory_bytes: 3916
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using P = pair<ll, ll>;
#define rep(i, n)  for (int i = 0; i <  (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
#define all(x) (x).begin(), (x).end()

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

    ll A,B,C,D;
    cin >> A;
    cin >> B;
    cin >> C;
    cin >> D;

    ll turn = 1;

    while (A>0 && C>0){
        if (turn > 0){
            C -= B;
        }
        else{
            A -= D;
        }
        if (A <= 0){
            cout << "No";
        }
        if (C <= 0){
            cout << "Yes";
        }
        turn = turn * (-1);
    }
}

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

typedef long long int ll;
#define rep(i,n) for (int i = 0; i < (n); i++)
const ll mod = 1000000007;
const ll INF = 10010010010010010;

vector<int> E[200005];
ll ans[200005];

void dfs(int par, int to, ll score) {
    ans[to] += score;
    for (auto& nx : E[to]) {
        if (nx != par) dfs(to, nx, ans[to]);
    }
}

int main() {
    int n,m,a,b,p; cin >> n >> m;
    rep(i,n-1) {
        cin >> a >> b;
        a--; b--;
        E[a].push_back(b);
        E[b].push_back(a);
    }
    rep(i,n) ans[i] = 0;
    ll x;
    rep(i,m) {
        cin >> p >> x;
        p--;
        ans[p] += x;
    }
    dfs(-1,0,0);
    rep(i,n) {
        printf("%lld ", ans[i]);
    }
    printf("\n");

    return 0;
}


Measured memory_bytes: 28772
A, B = list(map(int,input().split(" ")))
if B == 1:
  print(0)
elif A >= B:
  print(1)
else:
  if (B-A)%(A-1) == 0:
    print((B-A)//(A-1)+1)
  else:
    print((B-A)//(A-1)+2)

Measured memory_bytes: 9116
#include"bits/stdc++.h"

using namespace std; 

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef vector<PII> VPII;
typedef long long LL;
typedef priority_queue<int> PQ_DESC;
typedef priority_queue<int, vector<int>, greater<int>> PQ_ASC;
typedef priority_queue<PII> PQ_DESC_PII;
typedef priority_queue<PII, vector<PII>, greater<PII>> PQ_ASC_PII;

#define ALL(c) (c).begin(),(c).end()
#define PB push_back
#define MP make_pair
#define SORT_ASC(c) sort(ALL(c))
#define SORT_DESC(c) sort(ALL(c), greater<typeof(*((c).begin()))>())
#define SIZE(a) int((a).size())

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define ROF(i,a,b) for(int i=(b-1);i>=(a);--i)
#define REP(i,n) FOR(i,0,n)
#define PER(i,n) ROF(i,0,n)

const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int LARGE_INT = 1e9+100;
const int INF = 2e9+100;
const LL INF_LL = (LL)INF * 300 * 300;
const int MOD = 1e9+7;

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

LL modpow(LL a, LL n) {
    LL res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % MOD;
        a = a * a % MOD;
        n >>= 1;
    }
    return res;
}


void Main()
{
    int n;cin>>n;

    VI a(n);
    REP(i,n){
        int t;cin>>t;
        a[t]++;
    }

    if(n%2 == 0){
        REP(i,n){
            if(i%2==0 && a[i]!=0){
                cout << 0 << endl;
                return;
            }
            if(i%2==1 && a[i]!=2){
                cout << 0 << endl;
                return;
            }
        }
    }
    else{
        REP(i,n){
            if(i==0 && a[i]!=1){
                cout << 0 << endl;
                return;
            }
            if(i != 0 && i%2==0 && a[i]!=2){
                cout << 0 << endl;
                return;
            }
            if(i%2==1 && a[i]!=0){
                cout << 0 << endl;
                return;
            }
        }
    }

    cout<<modpow(2,n/2)<<endl;

	return;
}

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

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

using namespace std;

const int MAXN = 2000;
int a[MAXN];
int b[MAXN];

int solve(int cutoff, int n, int k, int q)
{
    priority_queue<int, vector<int>, greater<int>> mins;
    int ptr = 0;
    while (ptr < n)
    {
        priority_queue<int, vector<int>, greater<int>> pq;
        while (ptr < n && a[ptr] > cutoff)
        {
            pq.push(a[ptr]);
            ptr++;
        }
        while (pq.size() >= k)
        {
            mins.push(pq.top());
            pq.pop();
        }
        ptr++;
    }
    if (mins.size() < q)
        return 1E9 + 5;
    int small = mins.top();
    for (int i = 0; i < q - 1; i++)
        mins.pop();
    return mins.top() - small;
}

int main()
{
    int n, k, q;
    cin >> n >> k >> q;
    for (int i = 0; i < n; i++)
    {
        cin >> a[i];
        b[i] = a[i];
    }
    int ans = solve(0, n, k, q);
    for (int i = 0; i < n; i++)
    {
        ans = min(ans, solve(a[i], n, k, q));
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
if __name__ == '__main__':
    from sys import stdin
    input = stdin.readline

    a, b, m = map(int, input().split())
    aa = list(map(int, input().split()))
    bb = list(map(int, input().split()))
    min_ab = min(aa) + min(bb)
    for _ in range(m):
        x, y, c = map(int, input().split())
        now = aa[x-1] + bb[y-1] - c
        if min_ab > now:
            min_ab = now
    print(min_ab)


Measured memory_bytes: 18616
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1e9+7;
vector<ll>div(ll n){
    vector<ll>res;
    for(ll i=1;i*i<=n;i++){
        if(n%i==0){
            res.push_back(i);
            ll j=n/i;
            if(j!=i) res.push_back(j);
        }
    }
    sort(res.begin(),res.end());
    return res;
}
int main() {
    ll n,m;
    cin >> n >> m;
    ll ans=1;
    vector<ll>num=div(m);
    for(auto x:num){
        if(x*n<=m) ans=max(ans,x);
    }
    cout << ans << endl;
}

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

const int _ = 1e5 + 7; struct Edge{int end , upEd , f , c;}Ed[_]; int head[_] , cntEd = 1 , S , T;
void addEd(int a , int b , int c , int d){Ed[++cntEd] = (Edge){b , head[a] , c , d}; head[a] = cntEd;}
void addE(int a , int b , int c , int d){addEd(a , b , c , d); addEd(b , a , 0 , -d);}

queue < int > q; int pre[_] , dis[_] , fl[_]; bool vis[_];
bool SPFA(){
	q.push(S); for(int i = 1 ; i <= T + 1 ; ++i) dis[i] = -(1ll << 31) + 1;
	dis[S] = 0; fl[S] = (1ll << 31) - 1;
	while(!q.empty()){
		int t = q.front(); q.pop(); vis[t] = 0;
		for(int i = head[t] ; i ; i = Ed[i].upEd)
			if(Ed[i].f && dis[t] + Ed[i].c > dis[Ed[i].end]){
				dis[Ed[i].end] = dis[t] + Ed[i].c; fl[Ed[i].end] = min(Ed[i].f , fl[t]); pre[Ed[i].end] = i;
				if(!vis[Ed[i].end]){vis[Ed[i].end] = 1; q.push(Ed[i].end);}
			}
	}
	return dis[T] != dis[T + 1];
}

void EK(){
	int sum1 = 0 , sum2 = 0;
	while(SPFA()){
		sum1 += fl[T]; sum2 += fl[T] * dis[T]; int cur = T;
		while(cur != S){int p = pre[cur]; Ed[p].f -= fl[T]; Ed[p ^ 1].f += fl[T]; cur = Ed[p ^ 1].end;}
	}
	cout << sum2 << endl;
}

#define id(i,j) (((i) - 1) * M + (j))
int N , M; char Map[53][53];

int main(){
	cin >> N >> M; T = N * M + 1;
	for(int i = 1 ; i <= N ; ++i)
		for(int j = 1 ; j <= M ; ++j){
			cin >> Map[i][j];
			if(Map[i][j] != '#'){
				addE(id(i , j) , T , 1 , 0); if(Map[i][j] == 'o') addE(S , id(i , j) , 1 , 0);
				if(j != M) addE(id(i , j) , id(i , j + 1) , 1e9 , 1);
				if(i != N) addE(id(i , j) , id(i + 1 , j) , 1e9 , 1);
			}
		}
	EK(); return 0;
}


Measured memory_bytes: 3936
# coding:utf-8

memo = []

def main():
    N,Q = map(int,input().split())
    S = input()
    t = [0] *(N+1)
    for i in range(N):
        if S[i:i+2] == "AC":
            t[i+1] = t[i] + 1
        else:
            t[i+1] = t[i]
    # for i in range(N-1):
    #     if S[i:i+2] == "AC":
    #         memo.append(i)
    # print(memo)

    for i in range(Q):
        li,ri = map(int,input().split())
        print(t[ri-1] - t[li-1])
        # count = len(memo)
        # 両方の範囲に入る最初と最後
        # print(li,ri)
        # for i in range(li-1,ri-1):
        #     # print("debug"+str(i))
        #     if S[i] == "A" and S[i+1] == "C":
        #         count += 1
        #         start = i
        #         break
        # if start < 0:
        #     count = 0
        # else: 
        #     for i in reversed(range(li-1,ri+1)):
        #         if S[i-1] == "A" and S[i] == "C":
        #             end = i-1
        #             break
        #     print(start,end)
        #     count = memo.index(end) - memo.index(start) + 1


        # for i in range(len(memo)):
        #     if ac_check(i,li,ri):
        #         start = i
        #         break
        # if start < 0:
        #     count = 0
        # else:
        #     for i in reversed(range(len(memo))):
        #         if ac_check(i,li,ri):
        #             end = i
        #             break
        #     # print(start,end)
        #     count = count - (start) - (len(memo)-end) + 1
        # print(count)

# def ac_check(i,li,ri):
#     if memo[i] >= li-1 and memo[i]+1 <= ri-1:
#         return True
#     return False

# def ac_check(sub_s):
#     count = 0
#     for i in range(len(sub_s)-1):
#         if sub_s[i:i+2] == "AC":
#             count += 1
#     return count


if __name__ == "__main__":
    main()

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

typedef long long ll;

#define fi first
#define se second
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcount

typedef long double D;
typedef complex<D> P;
typedef pair<int,D> edge;

#define X real()
#define Y imag()

const D eps=1e-8;
const D inf=1e12;
const D PI=acos(-1);

namespace std{
  bool operator<(const P& a,const P& b){
    return a.X==b.X?a.Y<b.Y:a.X<b.X;
  }
}
bool cmp_x(const P& a,const P& b){ return a.X==b.X?a.Y<b.Y:a.X<b.X; }
bool cmp_y(const P& a,const P& b){ return a.Y==b.Y?a.X<b.X:a.Y<b.Y; }
bool cmp_a(const P& a,const P& b){ return arg(a)==arg(b)?norm(a)<norm(b):arg(a)<arg(b); }
D cross(P a,P b){ return (conj(a)*b).Y; }
D dot(P a,P b){ return (conj(a)*b).X; }
D toRag(D deg){ return deg*PI/180.0; }
P rot(P base,P a,D theta){ return base+polar(abs(a-base),arg(a-base)+theta); }

struct L : public vector<P> { // line and segment
  L(const P& a,const P &b){
    push_back(a);
    push_back(b);
  }
};

D f(P a,P b){ return acos(dot(a,b)/abs(a)/abs(b))/PI*180; }

int n;
D r,theta;
double dp[22][22][10010];
vector<edge> es[22][22];
P ps[22];

struct state{
  int pre,v,cnt;
  D d;
};
bool operator<(const state& a, const state& b){ return a.d > b.d; }

int main(){
	cin.sync_with_stdio(false);
  cin>>n;
  cin>>r>>theta;
  rep(i,n){
    D x,y;
    cin>>x>>y;
    ps[i]=P(x,y);
  }
  rep(i,n)rep(j,n)rep(k,10010)dp[i][j][k]=inf;
  rep(i,n)rep(j,n){
    if(i==j)continue;
    rep(k,n){ // (i,j) -> k
      if(i==k||j==k)continue;
      P v1=ps[j]-ps[i];
      P v2=ps[k]-ps[j];
      if(abs(f(v1,v2))<theta){
        //dbg(i); dbg(j); dbg(k);
        es[i][j].push_back(edge(k,abs(v2)));
      }
    }
  }
  priority_queue<state> que;
  repl(i,1,n){
    que.push((state){0,i,1,abs(ps[i]-ps[0])});
  }
  int res=0;
  while(que.size()){
    int pre=que.top().pre,v=que.top().v,cnt=que.top().cnt;
    D d=que.top().d; que.pop();
    if(dp[pre][v][cnt]!=inf)continue;
    if(d<r)maxch(res,cnt);
    else continue;
    dp[pre][v][cnt]=d;
    for(edge nxt : es[pre][v]){
      que.push((state){v,nxt.fi,cnt+1,d+nxt.se});
    }
  }
  cout<<res<<endl;
	return 0;
}

Measured memory_bytes: 36684
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const LL INF = 1e18;
const int MAXN = 20;
char sl[MAXN],sr[MAXN],sm[MAXN];

int main(){
	int n;
	scanf("%d",&n);
	int L=0,R=n-1,mid;
	printf("%d\n",L);
	fflush(stdout);
	scanf("%s",sl);
	if(sl[0]=='V') return 0;
	while(L+1<R){
		mid=(L+R)/2;
		printf("%d\n",mid);
		fflush(stdout);
		scanf("%s",sm);
		if(sm[0]=='V') return 0;
		if((mid-L-1)&1){
			if(sl[0]==sm[0]) L=mid;
			else R=mid;
		}else{
			if(sl[0]==sm[0]) R=mid;
			else L=mid,sl[0]=sm[0];
		}
	}
	printf("%d\n",n-1);
	fflush(stdout);
	scanf("%s",sr);
    return 0;
}

Measured memory_bytes: 852
#include <bits/stdc++.h>
#define INF (1<<30)
#define MOD 1000000007
#define l_ength size
using ll = long long;
using namespace std;

int main(){
	int d, g;
	cin >> d >> g;
	vector<int> p(d);
	vector<int> c(d);
	for( int i = 0; i < d; ++i ){
		cin >> p[i] >> c[i];
	}
	int ans = INF;
	for( int i = 0; i < (1<<d); ++i ){
		int sum = 0;
		int sumt = 0;
		for( int j = 0; j < d; ++j ){
			if( i & (1<<j) ){
				sum += (j+1)*100*p[j] + c[j];
				sumt += p[j];
			}
		}
		if( sum >= g ){
			ans = min( ans, sumt );
			continue;
		}
		for( int j = d-1; j >= 0; --j ){
			if( !(i & (1<<j)) ){
				int at = g-sum;
				int t = (j+1)*100;
				int res = (at+t-1)/t;
				if( at > (j+1)*100*p[j] ) break;
				ans = min( ans, sumt+res ); 
				break;
			}
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
n = int(input())
a = [int(i) for i in input().split()]
a.sort()

big =  [a[-1]]
rest = a[:-1]


for i in range(n):
    not_yet = []
    count = 0
    for b in big:
        if count==2**i:
            break
        while rest:
            r = rest.pop()
            if r < b:
                big.append(r)
                count += 1
                break
            not_yet.append(r)
    big.sort(reverse=True)
    rest += not_yet[::-1]
print("Yes" if len(rest)==0 else "No")

Measured memory_bytes: 34404
#!/usr/bin/env python2
"""
This file is part of https://github.com/cheran-senthil/PyRival
Copyright 2019 Cheran Senthilkumar <hello@cheran.io>

"""
from __future__ import division, print_function

import itertools
import os
import sys
from atexit import register
from cStringIO import StringIO
from collections import Counter

range = xrange

filter = itertools.ifilter
map = itertools.imap
zip = itertools.izip

sys.stdout = StringIO()
register(lambda: os.write(1, sys.stdout.getvalue()))
input = StringIO(os.read(0, os.fstat(0).st_size)).readline

MOD = 10**9 + 7
MODF = float(MOD)

MAGIC = 6755399441055744.0
SHRT = 65536.0

MODF_INV = 1.0 / MODF
SHRT_INV = 1.0 / SHRT

fround = lambda x: (x + MAGIC) - MAGIC
fmod = lambda a: a - MODF * fround(MODF_INV * a)
fmul = lambda a, b, c=0.0: fmod(fmod(a * SHRT) * fround(SHRT_INV * b) + a * (b - SHRT * fround(b * SHRT_INV)) + c)


def main():
    n = int(input())
    c = [int(input()) for _ in range(n)]

    _c, prev = [], 0
    for i in range(n):
        if c[i] != prev:
            _c.append(c[i])
        prev = c[i]
    c = _c
    n = len(c)

    prev_occur = [0] * (2 * 10**5 + 1)
    res, counts = [1.0] * (n + 1), Counter()
    for i in range(n):
        ind = prev_occur[c[i]]
        if ind != 0:
            res[i + 1] = fmod(res[i] + res[ind])
        else:
            res[i + 1] = res[i]

        counts[c[i]] += 1
        prev_occur[c[i]] = i + 1

    print(int(res[-1]) % MOD)


if __name__ == '__main__':
    main()


Measured memory_bytes: 71536
#include <algorithm>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <tuple>
#include <vector>

using namespace std;

#define rep(i, n) for (int64_t i = 0; i < (int64_t)(n); i++)
#define irep(i, n) for (int64_t i = 0; i <= (int64_t)(n); i++)
#define rrep(i, n) for (int64_t i = (n)-1; i >= 0; i--)
#define rirep(i, n) for (int64_t i = n; i >= 0; i--)

template <typename F>
void forNeighbor8(int h, int w, int x, int y, F f) {
  for (int dx = -1; dx <= 1; dx++) {
    for (int dy = -1; dy <= 1; dy++) {
      if (dx != 0 || dy != 0) {
        int nx = x + dx, ny = y + dy;
        if (nx >= 0 && nx < h && ny >= 0 && ny < w) {
          f(nx, ny);
        }
      }
    }
  }
}

int main() {
  int H, W;
  cin >> H >> W;
  vector<string> grid(H);
  rep(i, H) { cin >> grid[i]; }

  rep(i, H) rep(j, W) {
    if (grid[i][j] == '.') {
      int cnt = 0;
      forNeighbor8(H, W, i, j, [&](int x, int y) {
        if (grid[x][y] == '#') {
          cnt++;
        }
      });
      grid[i][j] = cnt + '0';
    }
  }

  rep(i, H) { cout << grid[i] << "\n"; }

  return 0;
}

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

typedef long long ll;
const int maxn=1e6+7;
const int inf=INT_MAX;
const ll inff=1e18;
const ll mod=1e9+7;
#define pii pair<int,int>
#define mkp make_pair
#define F first
#define S second
#define pb push_back
#define sz(v) ((int)(v).size())
#define all(v) (v).begin(),(v).end()
#define int ll

#ifdef HNO2
#define IOS
#else
#define endl '\n'
#define IOS ios::sync_with_stdio(0); cin.tie(0);
#endif // HNO2

int a[307];
vector<int> v;

int check(int x)
{
    int ret=0;
    for (int i=0;i<sz(v);i++)
        if ((1ll<<i)&x) ret^=(1ll<<v[i]);
    return ret;
}

int32_t main()
{
    IOS
    int n;
    cin>>n;
    for (int i=1;i<=n;i++) cin>>a[i];
    int B=0;
    for (int i=3;i<=n;i++) B^=a[i];

    if ((a[1]+a[2]-B)<0||((a[1]+a[2]-B)&1)) return cout<<-1<<endl,0;
    int X=(a[1]+a[2]-B)/2;
    if ((X&B)!=0) return cout<<-1<<endl,0;

    if (B==0)
    {
        if ((a[1]+a[2])&(1ll)) cout<<-1<<endl;
        else if (a[1]>=a[2]) cout<<a[1]-(a[1]+a[2])/2<<endl;
        else cout<<-1<<endl;
    }
    else
    {
        for (int i=0;i<=55;i++)
        if (B&(1ll<<i)) v.pb(i);

        int L=(X==0 ? 1 : 0),R=(1ll<<sz(v))-1;
        if ((check(L)^X)>a[1]) return cout<<-1<<endl,0;
        if ((check(R)^X)<=a[1]) return cout<<a[1]-(check(R)^X)<<endl,0;
        while (R-L>1)
        {
            int M=(L+R)>>1;
            if ((check(M)^X)<=a[1]) L=M;
            else R=M;
        }
        cout<<a[1]-(check(L)^X)<<endl;
    }
}



Measured memory_bytes: 3652
#include <iostream>
#include <string>
#include <cstring>
#include <iostream>
#include <string>
#include <cstring>
#include <cmath>
#include <cstdio>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <utility>
using namespace std;
int main(){
    int n;
    int m;
    cin>>n>>m;
    vector<int> a(n+1);
    vector<bool> b(n,true);
    for(int i=0;i<m;i++){
        int k;
        cin>>k;
        b[k-1]=false;
        a[k]=0;
    }
    a[0]=1;
    if(b[0]==true)a[1]=1;
    else a[1]=0;
    for(int i=2;i<=n;i++){
        if(b[i-1]==true)a[i]=(a[i-1]+a[i-2])%1000000007;
    }
    cout<<a[n]<<endl;
    return 0;
}



Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep2(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
const ll INF = 1LL<<60;
const ll MOD = 1e9+7;


int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n; cin>>n;
    int cnt = 0;
    for(int i=0; i<n; i++){
        int a;cin>>a;
        if(a%2!=0)cnt++;

    }
    cout<<(cnt%2==0?"YES":"NO")<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
struct Edge{int to,next;}e[200003];int head[200003],len,h[100003],n,m,s;void add(int &u,int &v){e[++len]=(Edge){v,head[u]},head[u]=len;}
main(){
    scanf("%d%d",&n,&m);for(int i=1;i<=n;i++) scanf("%d",&h[i]);while(m--){int a,b;scanf("%d%d",&a,&b),add(a,b),add(b,a);}
    for(int i=1;i<=n;i++){bool ok=1;for(int j=head[i];j;j=e[j].next) if(h[i]<=h[e[j].to])ok=0;if(ok) ++s;}printf("%d\n",s);return 0;
}

Measured memory_bytes: 4036
#include <bits/stdc++.h>
using namespace std;
#define int long long



struct listnode{
 int val;
 listnode*  next;};
 vector<int> func( vector<int> a,vector<int>l,int sum){
      vector<int>k,val;
       for(int i=0;i<l.size();i++)
           if(l[i]==0){
            k.push_back(i);
            val.push_back(a[i]);}
   if(sum<0)
   return a;
  else {
      sort(val.rbegin(),val.rend());
      for(int i=0;i<k.size();i++)
         a[k[i]]=val[i];}
         return a;

 }
 


int32_t main(){
 int m=1000000007;
 
     int n;
     cin>>n;
    int dp[2001];
dp[0] = 1; 
dp[1] = 0; 
dp[2] = 0; 
dp[3] = 1; 
dp[4] = 1; 
dp[5] = 1; 
dp[6] = 2;
dp[7] = 3;
for(int i=8;i<n+1;i++)
dp[i]=(dp[i-3]+dp[i-1])%m;
cout<<dp[n]%m<<endl;
return 0;
}

Measured memory_bytes: 3632
import java.util.*;
import java.io.*;
import java.lang.reflect.Array;
import java.math.BigInteger;

import static java.lang.Math.*;
import static java.util.Arrays.*;
import static java.util.Collections.*;
 
public class Main{
    static long mod=1000000007;
    static int dx[]={-1,0,1,0};
    static int dy[]={0,-1,0,1};

    public  static void main(String[] args)   throws Exception, IOException{        
        Reader sc = new Reader(System.in);
        PrintWriter out=new PrintWriter(System.out);

        int n=sc.nextInt();
        int m=sc.nextInt();
        int d[]=new int[n+2];
        for (int i = 0; i < m; i++) {
			d[sc.nextInt()]++;
			d[sc.nextInt()+1]--;
		}
        int ans=0,c=0;
        for (int i = 1; i <= n ; i++) {
			c+=d[i];
			if(c==m)ans++;
		}
        out.println(ans);
        out.flush();
    }
    



    static boolean validpos(int x,int y,int r, int c){
        return x<r && 0<=x && y<c && 0<=y;
    }

    static void db(Object... os){
        System.err.println(Arrays.deepToString(os));
    }  
}

//class P {
//    int id, d;
//    P(int  id, int d) {
//        this.id=id;
//        this.d=d;
//    }
//}


//class P implements Comparable<P>{
//    long a,b; 
//    int id;
//    P(long a, long b,int id) {
//        this.a=a;
//        this.b=b;
//        this.id=id;
//    }
//    public int compareTo(P p){
//    	if(a*b-p.a*p.b>0) return 1;
//    	if(-a*b+p.a*p.b>0) return -1;    	
//        return 0;
//    }
//}

class Reader
{ 
    private BufferedReader x;
    private StringTokenizer st;
    
    public Reader(InputStream in)
    {
        x = new BufferedReader(new InputStreamReader(in));
        st = null;
    }
    public String nextString() throws IOException
    {
        while( st==null || !st.hasMoreTokens() )
            st = new StringTokenizer(x.readLine());
        return st.nextToken();
    }
    public int nextInt() throws IOException
    {
        return Integer.parseInt(nextString());
    }
    public int[] nextIntArray(int size) throws IOException{
    	int r[] = new int[size];
    	for (int i = 0; i < size; i++) {
			r[i] = this.nextInt(); 
		}
    	return r;
    }
    public long[] nextLongArray(int size) throws IOException{
    	long r[] = new long[size];
    	for (int i = 0; i < size; i++) {
			r[i] = this.nextLong(); 
		}
    	return r;
    }
    public long nextLong() throws IOException
    {
        return Long.parseLong(nextString());
    }
    public double nextDouble() throws IOException
    {
        return Double.parseDouble(nextString());
    }
}


Measured memory_bytes: 41344
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] p = new int[n];
        for (int i = 0; i < p.length; i++) {
            p[i] = sc.nextInt();
        }
        int ans = 0;
        for (int i = 0; i < n - 2; i++) {
            List<Integer> list = new ArrayList<>();
            int tmp = 0;
            for (int j = 0; j < 3; j++) {
                list.add(p[i + j]);
                if(j == 1) {
                    tmp = p[i + j];
                }
            }
            Collections.sort(list);
            if(list.get(1) == tmp) ans++;
        }
        System.out.println(ans);
    }
}


Measured memory_bytes: 35880
import java.util.StringTokenizer;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.io.OutputStream;
public class Main {
	public static void main(String args[]) {
		Sc sc = new Sc(System.in);
		String st = sc.n();
		boolean n = false;
		boolean e = false;
		boolean s = false;
		boolean w = false;
		for(int i = 0; i<st.length(); i++) {
			if(st.charAt(i) == 'N') n = true;
			if(st.charAt(i) == 'W') w = true;
			if(st.charAt(i) == 'E') e = true;
			if(st.charAt(i) == 'S') s = true;
		}
		boolean ok = (s == n) && (w == e);
		if(ok) System.out.println("Yes");
		else System.out.println("No");
	}
}
class Sc {
    public Sc(InputStream i) {
        r = new BufferedReader(new InputStreamReader(i));
    }

    public boolean hasM() {
        return peekToken() != null;
    }

    public int nI() {
        return Integer.parseInt(nextToken());
    }

    public double nD() { 
        return Double.parseDouble(nextToken());
    }

    public long nL() {
        return Long.parseLong(nextToken());
    }

    public String n() {
        return nextToken();
    }

    private BufferedReader r;
    private String line;
    private StringTokenizer st;
    private String token;

    private String peekToken() {
        if (token == null) 
            try {
                while (st == null || !st.hasMoreTokens()) {
                    line = r.readLine();
                    if (line == null) return null;
                    st = new StringTokenizer(line);
                }
                token = st.nextToken();
            } catch (IOException e) { }
        return token;
    }

    private String nextToken() {
        String ans = peekToken();
        token = null;
        return ans;
    }
}

Measured memory_bytes: 8020
#include<iostream>
#include<string>

using namespace std;

int main(){
 string s;
  cin >> s;
  
  bool res=true;
  if(s[0]!='A'||(s[1]<'a'||'z'<s[1])||(s[s.length()-1]<'a'||'z'<s[s.length()-1])) res=false;
  
  int cnt=0;
  for(int j=2;j<s.length()-1;j++){
   if(s[j]=='C') cnt++;
   else if(s[j]<'a'||'z'<s[j]) res=false;
  }
  if(cnt!=1) res=false;
  
 
  
  
   if(res) cout << "AC" << endl;
   else cout << "WA" << endl;
  

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> ii;
typedef pair<ll, ll> l4;
typedef pair<double, double> dd;
#define mp make_pair
#define pb push_back
#define debug(x) cerr << #x << " = " << x << " "


int main()
{
  string s; cin >> s;
  cout << string(s.length(), 'x') << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
vector< vector<char> > a;
int main(void){
    int H,W;
    cin>>H>>W;


    a = vector< vector<char> >(H, vector<char>(W, 0));

    vector<int> hcount(H);
    vector<int> wcount(W);

    for(int i=0;i<H;i++){
      hcount[i] = 0;
    }
    for(int i=0;i<W;i++){
      wcount[i] = 0;
    }

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


    for(int i=0;i<H;i++){
      for(int j=0;j<W;j++){
          if(a[i][j]=='.') hcount[i]++;
      }
    }
    for(int i=0;i<W;i++){
      for(int j=0;j<H;j++){
          if(a[j][i]=='.') wcount[i]++;
      }
    }



    // for(int i=0;i<H;i++){
    //       cout<<hcount[i]<<endl;
    // }
    // for(int i=0;i<W;i++){
    //       cout<<wcount[i]<<endl;
    // }
    //
    //
    for(int i=0;i<H;i++){
      for(int j=0;j<W;j++){
        if(!(hcount[i]==W||wcount[j]==H)){
          cout<<a[i][j];
        }
        }
        if(!(hcount[i]==W)){
        cout<<endl;
      }
    }

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
signed main(){
  ios_base::sync_with_stdio(false);cin.tie(NULL);
  long long x,k,d;
    cin>>x>>k>>d;
    x=abs(x);
    if(x/d>=k)cout<<x-k*d<<endl;
    else {
      k-=x/d;
      if(k%2)cout<<d-x%d<<endl;
      else cout<<x%d<<endl;
    }
}


Measured memory_bytes: 3652
#include<iostream>
#include<math.h>
#include<vector>
#include<algorithm>
#include<numeric>
#include<map>
using namespace std;

int N,P[110];
string S[110];

int func(string s,int p){
    for(int i=0;i<N;++i)
       if(s==S[i]&&p==P[i])return i+1;
    return 0;
}
int main(){
    map <string,vector<int>>mp;
    cin>>N;
    for(int i=0;i<N;++i){
        cin>>S[i]>>P[i];
        mp[S[i]].push_back(P[i]);}
    
    for(auto itr=mp.begin();itr!=mp.end();++itr){
        sort(itr->second.begin(),itr->second.end(),greater<int>());
        for(int i=0;i<(itr->second.size());++i)cout<<func(itr->first,itr->second[i])<<endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>

using namespace std;
typedef long long ll;
const ll M = pow(10,9)+7;
const ll im = 1;

int main(){
  ll N;
  cin >> N;
  ll A[N];
  for(ll i=0;i<N;i++){
    cin >> A[i];
  }
  ll bit[61] = {0};
  for(ll i=0;i<N;i++){
    for(int j=0;j<61;j++){
      if((im<<j)&A[i]) bit[j]++;
    }
  }
  ll ans = 0;
  for(int i=0;i<61;i++){
    ll sum = (bit[i]*(N-bit[i]))%M;
    ll val = (im<<i)%M;
    ans += (sum*val)%M;
  }
  cout << ans%M << endl;
}


Measured memory_bytes: 5484
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int INF=0x7fffffff,MAXN=2005;
int n,a[MAXN<<1],f[MAXN][MAXN],Sum[MAXN<<1][MAXN<<1];
int Get(int x,int B,int W){return (Sum[x][B]-Sum[x-1][B]+Sum[x][W])-(Sum[x][n]+Sum[x-1][W]-Sum[x-1][n]);}
int main(){
    scanf("%d",&n);
    for(int i=1;i<=(n<<1);++i){
    	char ch[10];scanf("%s%d",ch,&a[i]),a[i]+=(ch[0]=='B')*n;
        for(int j=1;j<i;++j) Sum[a[j]][a[i]]=1;
    }
    memset(f,63,sizeof(f));f[0][0]=0;
    for(int i=1;i<=(n<<1);++i) for(int j=1;j<=(n<<1);++j) Sum[i][j]+=Sum[i-1][j]+Sum[i][j-1]-Sum[i-1][j-1];
    for(int i=0;i<=n;++i) for(int j=(i==0);j<=n;++j) f[i][j]=min(i?f[i-1][j]+Get(i,i,j+n):INF,j?f[i][j-1]+Get(j+n,i,j+n):INF);
    printf("%d\n",f[n][n]);
    return 0;
}

Measured memory_bytes: 78720
import java.util.Arrays;
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;
import java.util.stream.IntStream;

public class Main {

	public static void main(String[] args) {
		try (Scanner scanner = new Scanner(System.in)) {
			int n = scanner.nextInt(), k = scanner.nextInt();
			int[] p = new int[n];
			IntStream.range(0, n).forEach(i -> p[i] = scanner.nextInt() - 1);
			long[] c = new long[n], scores = new long[n + 1];
			IntStream.range(0, n).forEach(i -> c[i] = scanner.nextLong());
			long max = Long.MIN_VALUE;
			for (int i = 0; i < n; i++) {
				Set<Integer> set = new HashSet<>();
				Arrays.fill(scores, 0L);
				long score = 0L;
				int count = 0;
				int current = i;
				while ((!set.contains(current)) && (k > count)) {
					set.add(current);
					score += c[current];
					scores[++count] = score;
					current = p[current];
				}
				if ((score > 0) && (k > count)) {
					max = Math.max(max, (k / count) * score
							+ IntStream.rangeClosed(1, k % count).mapToLong(j -> scores[j]).max().orElse(0L));
					max = Math.max(max, Math.max(0, (k / count) - 1) * score
							+ IntStream.rangeClosed(1, count).mapToLong(j -> scores[j]).max().orElse(0L));
				} else {
					max = Math.max(max, IntStream.rangeClosed(1, count).mapToLong(j -> scores[j]).max().getAsLong());
				}
			}
			System.out.println(max);
		}
	}
}


Measured memory_bytes: 60948
#include"bits/stdc++.h"
using namespace std;

#define ll long long int
#define watch(x) cout << (#x) << " is " << (x) << endl
#define f(i,x,n)  for(int i=x;i<n;i++)
#define FASTIO cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(false);
#define eb(x) emplace_back(x)
#define mp(a,b) make_pair(a,b)
#define sz(a) int((a).size())
#define mod 1000000007
#define tr(c,i) for(typeof((c)).begin() i = (c).begin(); i != (c).end(); i++)
#define inf LLONG_MAX
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }


void seethis(vector<ll>vect)
{
    for(ll x:vect)
        cout<<x<<" ";
    cout<<"\n";
}

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " = " << a << endl;
	err(++it, args...);
}
//LCM
int lcm(int a, int b) {  return a * (b / __gcd(a, b)); }

//For sort by second
bool cmp(const pair<int,int> &a)
{ return a.first<a.second; }

//Tree
/* const int MAXN = 1e5 + 5;
vector<ll> adj[MAXN];*/

//ModPower
ll modpower(ll a,ll b,ll c)
{
	ll res=1;
	while(b)
	{
		if(b&1LL)
			res=(res*a)%c;
		a=(a*a)%c;
		b>>=1;
	}
	return res;
}

int main()
{
	FASTIO;
	/*#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	#endif*/
	char ch;
	 cin>>ch;

	 if(ch>='a' and ch<='z')
	 	cout<<"a\n";
	 else
	 	cout<<"A\n";

	
	return 0;
}

Measured memory_bytes: 3608
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;

int main() {
  int N, i, sat = 0;
  cin >> N;

  vector<int> A(N+2), B(N+2), C(N+2);
  rep(i, N){
    cin >> A.at(i);
  }
  rep(i, N){
    cin >> B.at(i+1);
  }
  rep(i, N-1){
    cin >> C.at(i+1);
  }

  rep(i, N){
    sat += B.at( A.at(i) );
    if( (i>0) && (A.at(i) == (A.at(i-1)+1)) ){
      sat += C.at( A.at(i-1) );
    }
  }
  cout << sat << endl;

  return 0;
}

Measured memory_bytes: 256
def a_zero_sum_ranges(N, A):
    import collections
    import itertools
    # s[l]==s[r] のとき、A[l+1]+...+A[r] == 0 となる
    s = itertools.accumulate([0] + A)
    count = collections.Counter(s)
    ans = 0
    for k, v in count.items():
        ans += v * (v - 1) // 2
    return ans

N = int(input())
A = [int(i) for i in input().split()]
print(a_zero_sum_ranges(N, A))

Measured memory_bytes: 40468
n=int(input())
H=list(map(int,input().split()))
l=0
r=1
ans=0
c=0
while r<=n-1:
  if H[r-1]>=H[r]:
    c+=1
    ans=max(ans,c)
    r+=1
  else:
    l=r
    r+=1
    c=0
print(ans)

Measured memory_bytes: 15020
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
using namespace std;
typedef long long ll;

ll N, A, B, C;
ll ans = 1e9;
vector<int> l;

// 0: A, 1: B, 2: C 3: x の場合 
void calc(vector<int> v) {
    // 全部 0 1 2 が1種類ずつある
    map<int, int> mp; 

    // くっつけた後の長さ
    ll a = 0, b = 0, c = 0;
    for (int i = 0; i < v.size(); i++) {
        if (v[i] == 3) continue;

        mp[v[i]]++;
        if (v[i] == 0) a += l[i];
        else if (v[i] == 1) b += l[i];
        else if (v[i] == 2) c += l[i];
    }

    // 3種類ない場合
    if (mp.size() != 3) {
        return;
    }

    // cout << v.size() << endl;
    // for (auto iter = mp.begin(); iter != mp.end(); iter++) {
    //     cout << iter->first << " " << iter->second;
    // }
    // cout << endl;

    // MP 計算
    ll tmp = 0;
    // printf("%d %d %d %d %d %d %d %d\n", A, a, B, b, C, c, mp[0], mp[1], mp[2]);
    tmp = abs(A - a) + abs(B - b) + abs(C - c) + (mp[0] - 1 + mp[1] - 1 + mp[2] - 1) * 10;
    // cout << tmp << endl;
    ans = min(ans, tmp);
}

void dfs(int depth, vector<int> v) {
    if (depth == N) {
        // for (int i = 0; i < v.size(); i++) {
        //     cout << v[i] << " ";
        // }
        calc(v);
        return;
    }


    for (int i = 0; i < 4; i++) {
        v[depth] = i;
        dfs(depth + 1, v);
    }
}

int main() {
    cin >> N >> A >> B >> C;

    rep(i, N) {
        ll x; 
        cin >> x;
        l.push_back(x);
    }

    vector<int> v(N);
    dfs(0, v);

    cout << ans << endl;
}

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

#define COUNTOF(array) (sizeof(array) / sizeof(array[0]))    
#define OUT(P) cout << (P) << endl    
#define OUT2(P1, P2) cout << (P1) << " " << (P2) << endl    
#define PRINT_ARRAY(P) for(int i=0; i<P.size(); i++) cout << P[i] << endl;    
#define PRINT_ARRAY_INLINE(P) do { for(int i=0; i<P.size(); i++) cout << P[i] << " "; cout << endl; } while(0)    
#define PRINT_ARRAY_WITH_LABEL(L, P) do { cout << L << ": "; PRINT_ARRAY_INLINE(P); cout << endl; } while(0)    
typedef long long ll;    
const long DIVIDE = 1e9+7;

int sum_digits(int num);    
template <class T>    
vector<T> copy_vector(vector<T> vec);    
int gcd(int a, int b);    
// ****** print functions ****** //
template <class T, class U>
void print_pairs(const vector<pair<T, U>> pairs);
template <class K, class V>
void print_map(const map<K, V> m);


int main() {    

    int n, x;
    cin >> n >> x;
    vector<int> l(n);
    for(int i=0; i<n; i++) {
        cin >> l[i];
    }

    vector<int> pt(n+1);
    pt[0] = 0;
    for(int i=1; i<n+1; i++) {
        pt[i] = pt[i-1] + l[i-1];
    }
    int cnt=0;
    for(int i=0; i<n+1; i++) {
        if(pt[i] <= x) {
            cnt++;
        }
    }
    cout << cnt << endl;
    return 0;    
}    

/******************************/    
/***** DECRARED FUNCTIONS *****/    
/******************************/    

int sum_digits(int num) {    
    int rtn = 0;    
    while(num != 0) {    
        int tmp = num % 10;    
        rtn += tmp;    
        num /= 10;    
    }    
    return rtn;    
}    

// vectorのコピー    
template <class T>    
vector<T> copy_vector(vector<T> vec) {    
    vector<T> rtn;    
    rtn.reserve(vec.size());    
    copy(vec.begin(), vec.end(), back_inserter(rtn));    
    return rtn;    
}    

// ユークリウッドの互除法    
int gcd(int a, int b) {    
    if(b==0) return a;    
    else return gcd(b, a % b);    
}

template <class T, class U>
void print_pairs(const vector<pair<T, U>> &pairs) {
    for(int i=0; i<pairs.size(); i++) { 
        cout << "(" << pairs[i].first << ", " << pairs[i].second << ")" << " "; 
    } 
    cout << endl;
}

template <class K, class V>
void print_map(const map<K, V> &m) {
    for(auto it=m.cbegin(); it!=m.cend(); it++) {
        cout << it->first << ": " << it->second << endl;
    }
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void){
    char s[15], t[15];

    scanf("%s", s);
    scanf("%s", t);

    //printf("%lu\n", sizeof(s));
    int flag = 0;
    int i = 0;
    while(s[i] != '\0'){
        //printf("%c\n", s[i]);
        //printf("%c\n", t[i]);
        if(s[i] != t[i]) flag = 1;
        //printf("%d\n", i);
        i++;
    }

    if(flag) puts("No");
    else puts("Yes");

    return 0;
}

Measured memory_bytes: 1664