akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define speedio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

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

#ifndef ONLINE_JUDGE
#define deb(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define deb(x...)
#endif

#define ll         long long
#define int        long long
#define pb         push_back
#define ff         first
#define sec        second
#define eb         emplace_back
#define SORT(a)      sort(a.begin(),a.end())
#define SORTR(a)     sort(a.rbegin(),a.rend())
#define all(x)       x.begin(),x.end()
#define sz(v)        ((int)(v.size()))
#define mem(a,val)   memset(&a,val,sizeof(a))
#define mid(s,e)     ((s)+((e)-(s))/2)
#define endl       '\n'


typedef vector<int>     vi;
typedef vector<bool>    vb;
typedef vector<vi>      vvi;
typedef vector<string>  vs;

typedef pair<int, int>  pii;
typedef vector< pii >   vpii;

#define fo(i,a,b)     for(ll i = (int)(a); i <= (int)(b); ++i)
#define fr(i,b)       for(ll i = (int)0; i < (int)(b); ++i)
#define rf(i,a,b)     for(ll i = (ll)(a); i >= (ll)(b); --i)
#define read(a,n)     for(int i=0;i<n;++i)cin>>a[i];
#define show(a,n)     for(int i=0;i<n;++i)cout<<a[i]<<' ';cout<<endl;

const int MOD = 1e9 + 7 ;
const int INF = 1e18    ;


void add(ll &x, ll y) { x += y; if (x >= MOD) x -= MOD; if (x < 0) x += MOD; }

// typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> oset;




void solve() {

	int n; cin >> n;
	string s; cin >> s;

	vi pos  ; for ( int i = 0 ; i < n ; ++ i) if ( s[i] == 'R') pos.pb(i);
	if (sz(pos) == 0) {
		cout << 0 << endl; return ;
	}

	int j = sz(pos) - 1; int c = 0 ;
	//deb(pos) ;
	for ( int i = 0 ; i < n ; ++i ) {
		if (i > pos[j] || j < 0 ) break;

		if (s[i] == 'W') {
			//deb(i, j);
			c++; j--;

			if (j < 0) break;
		}
	}

	cout << c << endl;
}


int32_t main() {
	speedio; cout << fixed << setprecision(12);
	/*#ifndef ONLINE_JUDGE
		freopen("input.txt", "r", stdin);
		freopen("output.txt", "w", stdout);
	#endif
	*/
	int T = 1; //cin>>T;
	while (T--) {
		solve();
	}

	return 0;
}







Measured memory_bytes: 5472
import java.util.*;
import java.io.*;
public class Main
{
    public static void main(String args[])throws Exception
    {
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        PrintWriter pw=new PrintWriter(System.out);
        int n=Integer.parseInt(br.readLine());
        HashMap<String,Integer> hmap=new HashMap<>();
        for(int i=0;i<n;i++)
        {
            String s=br.readLine();
            hmap.put(s,hmap.getOrDefault(s,0)+1);
        }
        pw.println("AC x "+hmap.getOrDefault("AC",0));
        pw.println("WA x "+hmap.getOrDefault("WA",0));
        pw.println("TLE x "+hmap.getOrDefault("TLE",0));
        pw.println("RE x "+hmap.getOrDefault("RE",0));
        pw.flush();
        pw.close();
    }
}

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


int main(){

    int a;
    cin>>a;
    int x=a/100,y=a%100;

    int ans=0;
    if(y>=1 && y<=12) ans|=1;
    if(x>=1 && x<=12) ans|=2;

    if(ans==0) printf("NA\n");
    else if(ans==3) printf("AMBIGUOUS\n");
    else if(ans==1) printf("YYMM\n");
    else printf("MMYY\n");

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define For(i,n,k) for(ll i=(n);i<(k);i++)
vector<int> iroha;
bool Main(){
    For(i,0,3){
        int l;cin>>l;
        iroha.push_back(l);
    }
    sort(iroha.begin(),iroha.end());
    if(iroha.at(0)==5&&iroha.at(1)==5&&iroha.at(2)==7){
        cout<<"YES"<<endl;
    }
    
    else{
        cout<<"NO"<<endl;
    }
}
int main(){
    Main();
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
//namespace mp = boost::multiprecision;

#include "atcoder/all"

using namespace std;

const double PI = 3.14159265358979323846;
typedef long long ll;
const double EPS = 1e-9;
#define rep(i, n) for (int i = 0; i < (n); ++i)
typedef pair<ll, ll> P;
const ll INF = 10e17;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)
#define ret() return 0;

double equal(double a, double b) {
    return fabs(a - b) < DBL_EPSILON;
}

std::istream &operator>>(std::istream &in, set<int> &o) {
    int a;
    in >> a;
    o.insert(a);
    return in;
}

std::istream &operator>>(std::istream &in, queue<int> &o) {
    ll a;
    in >> a;
    o.push(a);
    return in;
}

bool contain(set<int> &s, int a) { return s.find(a) != s.end(); }

typedef priority_queue<ll, vector<ll>, greater<ll> > PQ_ASK;


using mint = atcoder::modint998244353;

std::istream &operator>>(std::istream &in, mint &o) {
    long long a;
    in >> a;
    o = a;
    return in;
}

int main() {

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

    atcoder::scc_graph g(n);
    rep(_, m) {
        int a, b;
        cin >> a >> b;

        g.add_edge(a, b);
    }
    auto ans = g.scc();

    cout << ans.size() << endl;
    for (auto &e: ans) {
        cout << e.size() << ' ';
        for (int i : e) cout << i << ' ';
        cout << endl;
    }


}


Measured memory_bytes: 40548
#include<iostream>
#include<math.h>

using namespace std;

int main()
{
	int N, M, K[10], P[10], s[10][10];
	int i, j, k;
	int ans = 0,sw,ch;
	cin >> N >> M;
	for (i = 0; i < M; i++) {
		cin >> K[i];
		for (j = 0; j < K[i]; j++) {
			cin >> s[i][j];
		}
	}
	for (i = 0; i < M; i++)cin >> P[i];
	for (i = 0; i < pow(2,N); i++) {
		ch = 1;
		for (j = 0; j < M; j++) {
			sw = 0;
			for (k = 0; k < K[j]; k++) {
				if ((i / (int)pow(2, s[j][k] - 1)) % 2)sw++;
			}
			if (sw % 2 != P[j])ch = 0;
		}
		ans += ch;
	}
	cout << ans << endl;
}

Measured memory_bytes: 384
#include<iostream>
#include<string.h>
#include<string>
#include<cstdio>
#include<algorithm>
#include<stack>
#include<queue>
#include<vector>
#include<cmath>
#include<utility>
#include<set>
#define ll long long int
#define ld long double
#define INF 1000000000
#define EPS 0.0000000001
#define rep(i,n) for(i=0;i<n;i++)
using namespace std;
typedef pair<int, int> pii;

int main()
{
  int n,m,k;
  int i,j;
  int a;

  while(1){
    cin>>n;
    if(n==0)break;
    int p[105][105]={};
    int l[105]={};
    rep(i,n){
      cin>>m;
      rep(j,m){
	cin>>a;
	p[i][a]++;
      }
    }
    cin>>k;
    rep(i,k){
      cin>>a;
      l[a]++;
    }

    queue<int> q;

    rep(i,n){
      bool ans=true;
      rep(j,105)
	if(l[j]>p[i][j])
	  ans=false;
      if(ans)q.push(i);
    }
    if(q.size()==1)
      cout<<q.front()+1<<endl;
    else
      cout<<"-1"<<endl;
  }
}

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

const int MAX_N = 101;
int P[MAX_N]; // P[i] -- N!に素数iが何個含まれているか
bool prime[MAX_N];
int N;

void init(int N) {
    fill(prime, prime + N + 1, true);
    prime[0] = prime[1] = false;
    for(int i = 2; i <= N; ++i) {
        if(prime[i]) {
            for(int j = 2*i; j <= N; j += i) prime[j] = false;
        }
    }

    for(int i = 1; i <=N; ++i) {
        if(prime[i]) {
            for(int j = i; j <= N; j += i) {
                int k = j;
                while(k%i == 0) { k /= i; ++P[i]; }
            }
        }
    }
}

int search(int a) {
    int cnt = 0;
    for(int i = 0; i <= N; ++i){
        if(a-1 <= P[i]) ++cnt;
    }
    return cnt;
}

int main()
{
    cin >> N;
    init(N);
    /*
    for(int i = 0; i <= N; ++i) cout << P[i] << " ";
    cout << endl;
    */
    int res = 0;
    res = search(75) + 
        + search(25) * (search(3)-1)
        + search(15) * (search(5)-1)
        + search(5) * (search(5)-1) * (search(3)-2) / 2;
        //同じ集合から二つ選ぶので、重複が生じているため、2で割る
    
    cout << res << endl; 
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

long long fibodp(int n){
    long long fibodp[200] = {0};
    fibodp[0] = 1;
    fibodp[1] = 1;
    for(int i = 2; i <= n; i++){
        fibodp[i] = fibodp[i-1] + fibodp[i-2];
    }
    return fibodp[n];
}
int main(void){
    int n;
    scanf("%d", &n);
    printf("%lld\n", fibodp(n));
}


Measured memory_bytes: 2104
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define lvector vector<ll>
#define lque queue<ll>
#define lpque priority_queue<ll>
#define dlpque priority_queue<ll,lvector,greater<ll>>
#define P pair<ll,ll>
#define ALL(a) (a).begin(),(a).end()
#define rep(i,n) for(ll (i)=0; (i)<(n); ++(i))
#define print(a) cout << (a) << endl

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n,k,R,S,P_,ans=0;string t;cin>>n>>k>>R>>S>>P_>>t;
  vector<char> did(n);
  rep(i,n) {
    if(t[i]=='r') {
      if(i-k<0) {ans+=P_;did[i]='p';}
      else {
        if(did[i-k]!='p') {ans+=P_;did[i]='p';}
        else did[i]=='x';
      }
    }
    else if(t[i]=='p') {
      if(i-k<0) {ans+=S;did[i]='s';}
      else {
        if(did[i-k]!='s') {ans+=S;did[i]='s';}
        else did[i]=='x';
      }
    }
    else {
      if(i-k<0) {ans+=R;did[i]='r';}
      else {
        if(did[i-k]!='r') {ans+=R;did[i]='r';}
        else did[i]=='x';
      }
    }
  }
  print(ans);
  return 0;
}

Measured memory_bytes: 512
N = int(input())
S = input()

m = 0

for i in range(1, N):
    ans = 0
    X = S[:i]
    Xu = list(set(X))
    Y = S[i:]
    for a in Xu:
        if(Y.count(a)>0):
            ans+=1
    m = max(m, ans)

print(m)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
int main(){
    string S;
    string T;
    cin >> S;
    cin >> T;
    for (int i=0;i<S.size();i++){
        if (S==T){
            cout << "Yes" << endl;
            return 0;
        }
        S = S.back() + S;
        S.pop_back();
    }
    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define lli long long int

using namespace std;

int main()
{
  int n;
  cin>>n;
  lli a[n],x;
  for(int i=0;i<n;i++)
  {
    cin>>x;
    a[i]=x-(i+1);
  }
  sort(a,a+n);
  lli m=a[n/2];
  lli sum=0;
  for(int i=0;i<n;i++)
  {
    sum+=abs(a[i]-m);
  }
  cout<<sum<<endl;
  return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <cstdio>

std::string s[51], t[51];
int n, m;

bool search(int x, int y) {
    int cnt = 0;
    for (int i = x; i < x+m && i < n; ++i) {
        for (int j = y; j < y+m && j < n; ++j) {
            if (cnt == m*m) return true;
            if (s[i][j] != t[i-x][j-y]) return false;
            else cnt++;
        }
    }
    if (cnt != m*m) return false;
    return true;
}

int main() {

    std::cin >> n >> m;
    for (int i = 0; i < n; ++i) {
        std::cin >> s[i];
    }
    for (int i = 0; i < m; ++i) {
        std::cin >> t[i];
    }

    bool flag = false;

    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < n; ++j) { 
            if (s[i][j] == t[0][0]) {
                flag = search(i, j);
                if (flag) goto END;
            }
        }
    }
    END:
    if (flag) std::cout << "Yes\n";
    else std::cout << "No\n";

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <string>
#include <queue>
#include <fstream>
#include <string>
#include <math.h>
#include <set>
#include <string>
#include <bitset>
#include <fstream>
#include <stack>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef pair<ll, P> T;

#define rep(i, n) for (ll i = 0; i < (n); i++)
#define revrep(i, n) for (ll i = (n) - 1; i >= 0; i--)
#define f first
#define s second
#define pb push_back

ll mod = 1000000007;
const ll INF = 100000000000010000;
//const ull B = 998244353;
//ll kai[3010];

//void pres(double A, ll x = 20) { printf("%.20f\n", x); }

vector<ll> dx = { 0, 1, 0, -1, 1, -1, 1, -1, 0};
vector<ll> dy = { 1, 0, -1, 0, 1, 1, -1, -1, 0};

void chmin(ll& x, ll y) {
	x = min(x, y);
}

void chmax(ll& x, ll y) {
	x = max(x, y);
}

ll pow_long(ll x, ll y) {
	ll res = 1;
	while (y > 0) {
		if (y % 2 == 1) res *= x;
		x *= x;
		y /= 2;
	}
	return res;
}

void test() {
	cout << "888888888888888888888888" << endl;
}

ll gcd(ll x, ll y) {
	if (y == 0) return x;
	return gcd(y, x % y);
}

ll pow_mod(ll x, ll k) {
	x %= mod;
	ll res = 1;
	while (k > 0) {
		if (k % 2) {
			res *= x; res %= mod;
		}
		x *= x; x %= mod;
		k /= 2;
	}
	return res;
}

ll div_mod(ll x) {
	return pow_mod(x, mod - 2);
}

//コンビネーション
const int MAXcomb = 1000010;
ll fac[MAXcomb], finv[MAXcomb], inv[MAXcomb];
//facはn!,finvは1/n!
//invは逆元
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAXcomb; 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 comb(int n, int k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * finv[k] % mod * finv[n - k] % mod;
}

ll n;
string s;
ll R[4010], G[4010], B[4010];
ll ans;

void solve() {
	cin >> n >> s;
	rep(i, n) {
		R[i + 1] = R[i];
		G[i + 1] = G[i];
		B[i + 1] = B[i];
		if (s[i] == 'R') R[i + 1]++;
		if (s[i] == 'G') G[i + 1]++;
		if (s[i] == 'B') B[i + 1]++;
	}
	rep(i, n) for (ll j = i + 1; j < n; j++) {
		if (s[i] == s[j]) continue;
		if (s[i] != 'R' && s[j] != 'R') {
			ans += R[n] - R[j + 1];
			if (j + j - i < n && s[j + j - i] == 'R') ans--;
		}
		if (s[i] != 'G' && s[j] != 'G') {
			ans += G[n] - G[j + 1];
			if (j + j - i < n && s[j + j - i] == 'G') ans--;
		}
		if (s[i] != 'B' && s[j] != 'B') {
			ans += B[n] - B[j + 1];
			if (j + j - i < n && s[j + j - i] == 'B') ans--;
		}
	}
	cout << ans << endl;
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll T = 1;
	//cin >> T;
	rep(i, T) solve();
}


Measured memory_bytes: 3292
#include <bits/stdc++.h>
using namespace std;
using pii=pair<int,int>;
using ll=long long;

#define fi first
#define se second
#define pb push_back
#define rep(i,n) for(int i=0; i<(int)(n); i++)

int main() {
	string s,t,u;
	int a,b;
	cin >> s >> t;
	cin >> a >> b >> u;
	if(s == u) a--;
	if(t == u) b--;
	cout << a << " " << b << endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	void run() {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		if( a == b) {
			System.out.println(c);
		}
		else {
			if(a == c)System.out.println(b);
			else System.out.println(a);
		}
		sc.close();
	}

	void debug(Object... o) {
		System.out.println(Arrays.deepToString(o));
	}

	public static void main(String[] args) {
		new Main().run();
	}
}

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

#define X first
#define Y second
#define mp make_pair
#define pb pop_back
#define eb emplace_back
#define sz(v) (int) v.size()

using namespace std;

typedef long long LL;
typedef long double LD;

void solve() {
	int n;
	cin >> n;
	LL ans = 1LL * n * (n - 1) / 2;
	cout << ans << "\n";
}

signed main() {
// #define TASK ""
#if !defined(LOCAL) && defined(TASK)
	freopen(TASK".in", "r", stdin);
	freopen(TASK".out", "w", stdout);
#endif
	ios::sync_with_stdio(0); cin.tie(0);
	int tests = 1;
	// cin >> tests;
	while (tests--) {
		solve();
	}
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long n = sc.nextLong();
        long k = sc.nextLong();
        if(n < k) {
            long min = Math.min(n, k - n);
            System.out.println(min);
        } else if(k == 1) {
            System.out.println(0);
        } else if(n % k == 0){
            System.out.println(0);
        } else {
            long tmp = n % k;
            long min = Math.min(tmp, Math.abs(tmp - k));
            System.out.println(min);
        }
    }
}

Measured memory_bytes: 35684
//↓見なくていいよ！ここから--------------------------------------------------
var read = require('readline').createInterface({
  input: process.stdin,
  output: process.stdout
});
var obj;
var inLine = [];
read.on('line', function(input){inLine.push(input);});
read.on('close', function(){
  obj = init(inLine);
  myerr("-----start-----");
  var start = new Date();
  Main();
  var end = new Date() - start;
  myerr("----- end -----");
  myerr("time : " + (end) + "ms");
  myerr("memory : " + Math.round(process.memoryUsage().heapTotal / 1024) + "KB");
});
function nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}
function nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}
function next(){return obj.next();} function hasNext(){return obj.hasNext();}
function init(input){  
  var returnObj = {
    list : input, index : 0, max : input.length,
    hasNext : function(){return (this.index < this.max);},
    next : function(){if(!this.hasNext()){throw "ArrayIndexOutOfBoundsException これ以上ないよ";}else{var returnInput = this.list[this.index];this.index++;return returnInput;}}
  };
  return returnObj;
}
function myout(s){console.log(s);}
function myerr(s){console.error("debug:" + require("util").inspect(s,false,null));}
//[no]要素の扱い。数値型
//不明値、異常時:引数そのまま返す 1:数値へ変換
//2:半角SPで分割 4:半角SPで分割し、数値配列へ
//6:1文字で分割  7:1文字で分割し、数値配列へ
//8:半角SPで結合 9:改行で結合 0:文字なしで結合
function myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(" ");case 4:return i.split(" ").map(Number);case 6:return i.split("");case 7:return i.split("").map(Number);case 8:return i.join(" ");case 9:return i.join("\n");case 0:return i.join("");default:return i;}}catch(e){return i;}}

//↑見なくていいよ！ここまで--------------------------------------------------
function Main(){
	var N = nextInt();
	var list = nextIntArray();
	var map = {};
	var submap = new Set();
	var sameSet = new Set();
	for(var i = 0; i < N; i++){
		if(submap.has(list[i])){
			sameSet.add(list[i]);
			continue;
		}
		submap.add(list[i]);
		if(map[list[i]] == null){
			map[list[i]] = getDivisorList(list[i]);
		}
	}
	var output = 0;
	for(var i = 0; i < N; i++){
		if(sameSet.has(list[i])){
			continue;
		}
		var getDiv = map[list[i]];
		var isOK = true;
		for(var j = 0; j < getDiv.length; j++){
			if(getDiv[j] != list[i] && submap.has(getDiv[j])){
				isOK = false;
				break;
			}
		}
		if(isOK){
			output++;
		}
	}
	myout(output);
}
function getDivisorList(val){
  var list = [];
  for(var i = 1; i * i <= val; i++){
    if(val % i == 0){
      list.push(i);
      if(i * i != val){
        list.push(val / i);
      }
    }
  }
  list.sort(function(a,b){ return a - b; });
  return list;
}


Measured memory_bytes: 143176
#include <iostream>
#include <cmath>
#include <algorithm>
#include <string>
using namespace std;
#define ll long long ;

char c[9];


int main(){

	for (int i = 0; i < 9; i++) cin >> c[i];
	cout << c[0] << c[4] << c[8] << endl; 


	return 0;
}


Measured memory_bytes: 256
import sys

sys.setrecursionlimit(10 ** 6)
INF = float("inf")
MOD = 10 ** 9 + 7


def input():
    return sys.stdin.readline().strip()


def main():
    N, W = map(int, input().split())
    dp = [[0] * (W + 1) for _ in range(N + 1)]
    item = [(0, 0)]
    for _ in range(N):
        w, v = map(int, input().split())
        item.append((w, v))

    for i in range(1, N + 1):
        for w in range(W + 1):
            if w - item[i][0] >= 0:
                tmp = dp[i - 1][w - item[i][0]] + item[i][1]
                if tmp > dp[i][w]:
                    dp[i][w] = max(dp[i - 1][w], tmp)
            else:
                dp[i][w] = dp[i - 1][w]

    print(max(dp[-1]))


if __name__ == "__main__":
    main()


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

#define fo(i,s,t) for(int i = s; i <= t; ++ i)
#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define pii pair<int,int>
const int maxn = 100050;

int n, q, dep[maxn], fa[maxn][20];
long long dis[maxn][20];
struct edge{int next,to,w;}e[maxn<<1];
int cnt, head[maxn];

void link(int u,int v,int w)
{
	++ cnt; e[cnt].next = head[u];
	e[cnt].to = v; e[cnt].w = w;
	head[u] = cnt;
}
void dfs(int x,int f=0)
{
	for(int i = head[x]; i; i = e[i].next)
		if(e[i].to != f)
		{
			dep[e[i].to] = dep[x] + 1;
			fa[e[i].to][0] = x;
			dis[e[i].to][0] = e[i].w;
			dfs(e[i].to,x);
		}
}
int lca(int x,int y)
{
	if(dep[x] < dep[y]) swap(x,y);
	int c = dep[x] - dep[y];
	for(int j = 19; j >= 0; -- j) if(c&(1<<j)) x = fa[x][j];
	for(int j = 19; j >= 0; -- j) if(fa[x][j]!=fa[y][j]) x = fa[x][j], y = fa[y][j];
	return (x==y?x:fa[x][0]);
}
long long calc(int x,int y)
{
	int g = lca(x,y);
	long long ret = 0;
	int c = dep[x]-dep[g];
	for(int j = 19; j >= 0; -- j) if(c&(1<<j)) ret += dis[x][j], x = fa[x][j];
	c = dep[y]-dep[g];
	for(int j = 19; j >= 0; -- j) if(c&(1<<j)) ret += dis[y][j], y = fa[y][j];
	return ret;
}
int main()
{
	scanf("%d",&n);
	fo(i,2,n)
	{
		int a, b, c;
		scanf("%d%d%d",&a,&b,&c);
		link(a,b,c);
		link(b,a,c);
	}
	dfs(1);
	fo(j,1,19) fo(i,1,n)
	{
		fa[i][j] = fa[fa[i][j-1]][j-1];
		dis[i][j] = dis[i][j-1]+dis[fa[i][j-1]][j-1];
	}
	int k;
	scanf("%d%d",&q,&k);
	while(q--)
	{
		int x, y; scanf("%d%d",&x,&y);
		printf("%lld\n",calc(x,k)+calc(k,y));
	}
	return 0;
}


Measured memory_bytes: 33024
def main():
    N = int(input())
    # 4hnw = N(hn + nw + wh)
    # (4hn - N(n + h)) w = Nhn
    for h in range(1, 3501):
        for n in range(1, 3501):
            d = 4 * h * n - N * (n + h)
            if d <= 0 or (N * h * n) % d != 0 or (N * h * n) // d > 3500:
                continue
            w = (N * h * n) // d
            print(h, n, w)
            return


if __name__ == '__main__':
    main()


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

using namespace std;

int main() {
    int a, b, c;
    cin >> a >> b >> c;
    if (a == b && a != c || b == c && a != b || a == c && b != c) {
        cout << "Yes";
    } else {
        cout << "No";
    }
    return 0;
}

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

int main()
{
    string s;
    cin >> s;
    int fro=0, end=s.size()-1;
    for (int i=0;i<s.size();i++)
    {
        if (s.at(i)=='A')
        {
            fro=i;
            break;
        }
    }
    for (int i=s.size()-1;i>=0;i--)
    {
        if (s.at(i)=='Z')
        {
            end=i;
            break;
        }
    }
    cout << end-fro+1 << endl;
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
#define REP(i, n) for(int i=0; i<n; i++)
#define REPi(i, a, b) for(int i=int(a); i<int(b); i++)
#define MEMS(a,b) memset(a,b,sizeof(a))
#define mp make_pair
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; }
const ll MOD = 1e9+7;

int main(){
    ll N;
    cin >> N;
    ll A, B;
    cin >> A >> B;

    ll S = A+B;

    ll ans = 0;
    ll num = N / S;

    ans += num * A;

    N -= num * S;

    ans += min(N, A);

    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
a,b,c,x,y=map(int,input().split())
A=a*x
B=b*y
ABa=c*x*2
ABab=b*(y-x) if y>x else 0
ABb=c*y*2
ABba=a*(x-y) if x>y else 0
AB=2*c*x if x>y else 2*c*y
print(min(A+B,ABa+ABab,ABb+ABba,AB))
#ABはいらないみたい

Measured memory_bytes: 3060
import java.util.*;

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

        S = S.replaceAll("eraser",  "-");
        S = S.replaceAll("erase",   "-");
        S = S.replaceAll("dreamer", "-");
        S = S.replaceAll("dream",   "-");
        S = S.replaceAll("-", "");
        if (S.length() == 0)
            System.out.println("YES");
        else
            System.out.println("NO");
    }
}

Measured memory_bytes: 29524
#include <stdio.h>
inline char gc(){
	static char buf[100000],*p1=buf,*p2=buf;
	return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
}
#define gc getchar
inline long long read(){
	long long now=0;int f=0;register char c=gc();
	for(;c<48||c>57;c=='-'&&(f=1),c=gc());for(;c>47&&c<58;now=(now<<3)+(now<<1)+c-'0',c=gc());
	return f?-now:now;
}
#define Maxn 200005
long long n,d,a[Maxn],dpl[Maxn],dpr[Maxn],ans;
long long Min(long long x, long long y) { return (((y - x) >> (64 - 1)) & (x ^ y)) ^ x; }
signed main()
{
	n=read(),d=read();
	for (int i=0;i<n;++i) a[i]=read(),ans+=a[i];
	ans+=(n-1)*d;dpl[0]=a[0];dpr[n-1]=a[n-1];
	for (int i=1;i<n;++i) dpl[i]=Min(a[i],dpl[i-1]+d);
	for (int i=n-2;~i;--i) dpr[i]=Min(a[i],dpr[i+1]+d);
	for (int i=1;i<n-1;++i) ans+=Min(dpl[i],dpr[i]);
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 4864
import sys
X,N=map(int,input().split())

P=list(map(int,input().split()))

Sa=[]

for i in range(100):
    ma=X+i
    mi=X-i
    if mi not in P:
        print(mi)
        sys.exit()
    elif ma not in P:
        print(ma)
        sys.exit()

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

#define ll long long
#define fw(p) for(int w=0;w<(p);w++)
#define fx(p) for(int x=0;x<(p);x++)
#define fy(p) for(int y=0;y<(p);y++)
#define fz(p) for(int z=0;z<(p);z++)
#define fyg(p,g) for(int y=(g);y<(p);y++)
#define fzg(p,g) for(int z=(g);z<(p);z++)
#define ce(d) cout<<d<<endl;
#define vecp(p) int aa;cin>>aa;(p).push_back(aa);
#define vecpl(p) long long aa;cin>>aa;(p).push_back(aa);
#define vecps(p) string aa;cin>>aa;(p).push_back(aa);
#define vecp2(p) cin>>aa;(p).push_back(aa);
#define vecpl2(p) long long a	b;cin>>ab;(p).push_back(ab);
#define vecps2(p) string ab;cin>>ab;(p).push_back(ab);
#define sorts(c) sort((c).begin(),(c).end());
#define reverses(c) reverse((c).begin(),(c).end());
#define vec(b) vector<int> (b);
#define vecl(b) vector<long long> (b);
#define vecs(b) vector<string> (b);
#define pb(b,a) (b).push_back((a));
#define doublece(a,b) cout<<(a)<<' '<<(b)<<endl;
#define pairs(s) vector<pair<int,int>> (s);
#define pairsp(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define MOD 1000000007
#define cey ce("Yes")
#define cen ce("No")
#define ceY ce("YES")
#define ceN ce("NO")

int main()
{

int N, M;
	cin >> N >> M;
	int sum[110000] = { 0, };
	fx(M) {
		int a, b;
		cin >> a >> b;
		sum[a] ++ ;
		sum[b]++;
	}
	fx(N) {
		if (sum[x+1]%2==1) {
			ceN;
			return 0;
		}
	}
	ceY;
    return 0;
}



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

using namespace std;

int main() {
  int N, M;
  cin >> N >> M;
  
  vector<int> wa(N+1, 0); // それぞれの問題でAC出すまでに間違えた数を記録
  bool flag[N+1] = {false}; // それぞれの問いをACだしたか
  
  int wa_sum = 0;
  int ac_sum = 0;
  
  for (int i = 0; i < M; i++) {
    int num;
    string S;
    cin >> num >> S;

    
    if (flag[num]) {
      continue;
    } else { 
      if (S.at(0) == 'W') {
        wa[num]++;
      }
      if (S.at(0) == 'A') {
        flag[num] = true;
        ac_sum++;
        wa_sum += wa[num];
      }
    }
  }   
  cout << ac_sum << " " << wa_sum << endl;
}

Measured memory_bytes: 768
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <stack>
#include <cassert>
#include <map>
#include <numeric>
#include <cstring>
#include <set>
#include <ctime>
#include <queue>
#include <cmath>
#include <iomanip>
#include <iterator>

using namespace std;

clock_t timeStart, timeFinish;

void timeBegin() {
    timeStart = clock();
}

void timeEnd() {
    timeFinish = clock();
}

void timeDuration() {
    double time_taken = double(timeFinish - timeStart) / double(CLOCKS_PER_SEC);
    cout << "Time taken by program is : " << fixed << time_taken << setprecision(5);
    cout << " sec " << endl;
}

class InputReader {
public:
    InputReader() {
        input_file = stdin;
        cursor = 0;
        fread(buffer, SIZE, 1, input_file);
    }
    InputReader(const char *file_name) {
        input_file = fopen(file_name, "r");
        cursor = 0;
        fread(buffer, SIZE, 1, input_file);
    }
    inline InputReader &operator >>(int &n) {
        while((buffer[cursor] < '0' || buffer[cursor] > '9') && buffer[cursor] != '-') {
            advance();
        }
        int sign = 1;
        if (buffer[cursor] == '-') {
            sign = -1;
            advance();
        }
        n = 0;
        while('0' <= buffer[cursor] && buffer[cursor] <= '9') {
            n = n * 10 + buffer[cursor] - '0';
            advance();
        }
        n *= sign;
        return *this;
    }
private:
    FILE *input_file;
    static const int SIZE = 1 << 17;
    int cursor;
    char buffer[SIZE];
    inline void advance() {
        ++ cursor;
        if(cursor == SIZE) {
            cursor = 0;
            fread(buffer, SIZE, 1, input_file);
        }
    }
};

int main() {
    timeBegin();
    //ifstream cin("input.in");
    //ofstream cout("papagali.out");
    int h1, m1, h2, m2, k;
    cin >> h1 >> m1 >> h2 >> m2 >> k;
    cout << (h2 * 60 + m2 - h1 * 60 - m1) - k << "\n";
    //timeDuration();
    return 0;
}

Measured memory_bytes: 3628
/*
─────────────────────
───────────████████──
──────────███▄███████
──────────███████████
──────────███████████
──────────██████─────
──────────█████████──
█───────███████──────
██────████████████───
███──██████████──█───
███████████████──────
███████████████──────
─█████████████───────
──███████████────────
────████████─────────
─────███──██─────────
─────██────█─────────
─────█─────█─────────
─────██────██────────
─────────────────────
*/
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>

#define int long long
#define read(a) int a; cin >> a;
#define readb(a, b) int a, b; cin >> a >> b;
#define readc(a, b, c) int a, b, c; cin >> a >> b >> c;
#define reads(s) string s; cin >> s;
#define readarr(a, n) int a[(n) + 1] = {}; fori (i, 1, (n)) {cin >> a[i];}
#define readmat(a, n, m) int a[n + 1][m + 1] = {}; fori (i, 1, n) {fori (j, 1, m) cin >> a[i][j];}

#define print(a) cout << a << endl;
#define printarr(a, n) fori (i, 1, n) cout << a[i] << " "; cout << endl;
#define printv(v) for (int i: v) cout << i << " "; cout << endl;
#define printmat(a, n, m) fori (i, 1, n) {fori (j, 1, m) cout << a[i][j] << " "; cout << endl;} cout << endl;
#define all(v) v.begin(), v.end()
#define sz(s) (int)(s.size())
#define pb push_back
#define fi first
#define se second
#define rz resize
#define fori(i, a, b) for (int i = (a); i <= (b); i++)
#define ford(i, a, b) for (int i = (a); i >= (b); i--)
#define endl '\n'
#define setprec(x) cout << fixed << setprecision(x)
 
using namespace std;
using namespace __gnu_pbds; 
 
typedef tree<long long,null_type,less<long long>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef vector<pair <int, int>> vpi;
typedef vector < vector <int> > vvi;
 
const int INF = 4e18;
const int mod = 1e9+7; 

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

    //start from here

    readb(a, b); readb(c, k);

    int sum = 0;

    if(k > a) sum += a, k -= a;
    else sum += k, k = 0;

    if(k > b) k -= b;
    else k = 0;

    if(k > c) sum -= c, k -= c;
    else sum -= k, k = 0;

    cout << sum;

    return 0;
}


Measured memory_bytes: 3640
// Template from https://techracho.bpsinc.jp/jhonda/2019_08_05/78537

// input macro for competive-programming from https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };

    ($iter:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($next:expr, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, bytes) => {
        read_value!($iter, String).into_bytes()
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    use std::io::Read;
    let mut s = String::new();
    std::io::stdin().read_to_string(&mut s).unwrap();

    println!("{}", solve(&s));
}

macro_rules! test {
    ($($input:expr => $output:expr),* $(,)*) => {
        #[test]
        fn solve_test() {
            $(
                assert_eq!(solve($input), $output);
            )*
        }
    };
}

test! {
r#"4"# => r#"0.5"#,
r#"5"# => r#"0.6"#,
r#"1"# => r#"1"#,
}

fn solve(src: &str) -> String {
    input! {
        source = src,
        n: usize,
    }

    // let m = (1..n + 1).filter(|i| i % 2 != 0).count();
    // (m as f64 / n as f64).to_string()
    let m = n / 2;
    ((m as f64 + if n % 2 == 0 { 0.0 } else { 1.0 } ) / n as f64).to_string()
}

Measured memory_bytes: 4352
#include <iostream>
#include <bitset>
#include <fstream>
#include <string>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <vector>
#include <algorithm>
#include <numeric>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <functional>
#include <cctype>
#include <list>
#include <limits>
//#include <boost/multiprecision/cpp_int.hpp>

const double EPS = (1e-10);


using namespace std;
using Int = long long;
//using namespace boost::multiprecision;

const Int MOD = 1000000007;

Int mod_pow(Int x, Int n) {
    Int res = 1;
    while(n > 0) {
        if(n & 1) res = (res * x) % MOD; //ビット演算(最下位ビットが1のとき)
        x = (x * x) % MOD;
        n >>= 1; //右シフト(n = n >> 1)
    }
    return res;
}


int a[10];

void output(int a){
    if (a){
        cout << "YES" << endl;
    }else{
        cout << "NO" << endl;
    }
    exit(0);
}

int main(){
    cin.tie(0);
    
    string s; cin >> s;
    for (int i = 0; i < s.length(); i++){
        if (s[i] == '9') cout << 1;
        else cout << 9;
    }
    cout << endl;
} 


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

int main(){
    int n; cin >> n;
    string s; cin >> s;
    long long r = 0, g = 0, b = 0;
    for(int i = 0; i < n; i++){
        if(s.at(i) == 'R') r++;
        else if(s.at(i) == 'G') g++;
        else b++;
    }
    long long ans = r*g*b;
    for(int i = 0; i < n; i++){
        for(int j = i + 1; j < n && 2*j - i < n; j++){
            if(s.at(i) != s.at(j) && s.at(i) != s.at(2*j - i) && s.at(j) != s.at(2*j - i)) ans--;
        }
    }
    cout << ans << endl;
}

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

using namespace std;

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

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

const ll mod = 1e9+7;
const ll INF = 1e9;

ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

bool valid(int lx,int ux,int ly,int uy,int x,int y){
	return (lx<=x&&x<ux&&ly<=y&&y<uy);
}

int solve(int w,int h){
	vector<vector<int>> m(h,vector<int>(w,-1));

	set<P> wall;
	rep(i,2*h-1){
		if(i%2==0){
			rep(j,w-1){
				int x;
				cin>>x;
				if(x==1){
					wall.insert(P(i/2*w+j,i/2*w+j+1));
					wall.insert(P(i/2*w+j+1,i/2*w+j));
				}
			}
		}else{
			rep(j,w){
				int x;
				cin>>x;
				if(x==1){
					wall.insert(P(i/2*w+j,i/2*w+w+j));
					wall.insert(P(i/2*w+w+j,i/2*w+j));
				}
			}
		}
	}

	m[0][0]=1;
	queue<int> que;
	que.push(0);
	while(!que.empty()){
		int pos_h=que.front()/w;
		int pos_w=que.front()%w;
		que.pop();

		rep(i,4){
			if(valid(0,w,0,h,pos_w+dx[i],pos_h+dy[i])){
				if(m[pos_h+dy[i]][pos_w+dx[i]]<0 && wall.count(P(pos_h*w+pos_w,w*(pos_h+dy[i])+pos_w+dx[i]))==0){
					m[pos_h+dy[i]][pos_w+dx[i]] = m[pos_h][pos_w]+1;
					que.push(w*(pos_h+dy[i])+pos_w+dx[i]);
				}
			}
		}
	}

	if(m[h-1][w-1]<0) m[h-1][w-1]=0;

	return m[h-1][w-1];
}


int main()
{
	int h,w;
	while(cin>>w>>h,w!=0&&h!=0){
		cout<<solve(w,h)<<endl;
	}
	return 0;
}


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

bool is_palindrome(const string & Sx){
    for (int i = 0, j = Sx.size() - 1; i < j; ++i, --j){
        if (Sx[i] != Sx[j]) return false;
    }
    return true;
}

vector<int> count_x(const string & S){
    vector<int> ret;
    int count = 0;
    for (char c : S){
        if (c == 'x'){
            ++count;
        }else{
            ret.push_back(count);
            count = 0;
        }
    }
    ret.push_back(count);
    return ret;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    string S;
    cin >> S;
    string Sx;
    for (char c : S){
        if (c != 'x') Sx.push_back(c);
    }
    if (not is_palindrome(Sx)){
        cout << -1 << endl;
    }else{
        auto nxs = count_x(S);
        int ans = 0;
        for (int i = 0, j = nxs.size() - 1; i < j; ++i, --j){
            ans += abs(nxs[i] - nxs[j]);
        }
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 1228
#include <bits/stdc++.h>
#define ll long long

#define TASKNAME ""

using namespace std;

const int INF = 1e9 + 7;
const int MAXN = 1e6 + 7;
const double EPS = 1e-8;

vector <int> merge(vector <int> &a, vector <int> &b) {
    vector <int> c;
    int n = a.size(), m = b.size();
    int i = 0, j = 0;
    while (i < n && j < m) {
        if (a[i] < b[j]) {
            c.push_back(a[i]);
            i++;
        } else {
            c.push_back(b[j]);
            j++;
        }
    }
    while (i < n) {
        c.push_back(a[i]);
        i++;
    }
    while (j < m) {
        c.push_back(b[j]);
        j++;
    }
    return c;
}

int main() {
    #ifdef MY
        freopen("input.txt", "r", stdin);
        //freopen("output.txt", "w", stdout);
    #else
        //freopen(TASKNAME".in", "r", stdin);
        //freopen(TASKNAME".out", "w", stdout);
        ios_base::sync_with_stdio(false);
        cin.tie(0);
        cout.tie(0);
    #endif // MY
    int n, k, q;
    cin >> n >> k >> q;
    vector <int> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    int res = INF;
    for (int i = 0; i < n; i++) {
        vector <int> now;
        vector <int> all;
        for (int j = 0; j < n; j++) {
            if (a[i] <= a[j]) {
                now.push_back(a[j]);
            } else {
                sort(now.begin(), now.end());
                for (int l = 0; l < max((int) now.size() - k + 1, 0); l++) {
                    all.push_back(now[l]);
                }
                now.clear();
            }
        }
        sort(now.begin(), now.end());
        for (int l = 0; l < max((int) now.size() - k + 1, 0); l++) {
            all.push_back(now[l]);
        }
        now.clear();
        //cout << all.size() << "\n";
        sort(all.begin(), all.end());
        if ((int) all.size() >= q) {
            res = min(res, all[q - 1] - a[i]);
        }
    }
    cout << res;
}


Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))
ans = [1]
for i in range(n):
    if a[i] % 2 == 0:
        if a[i] % 3 == 0 or a[i] % 5 == 0:
            ans.append(1)
        else:
            ans.append(-1)
if len(set(ans)) == 1:
    print('APPROVED')
else:
    print('DENIED')

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

int main(){
  int x, y;
  cin >> x >> y;

  set<int> a = {1, 3, 5, 7, 8, 10, 12};
  set<int> b = {4, 6, 9, 11};
  set<int> c = {2};

  if ((a.find(x) != a.end() && a.find(y) != a.end()) || (b.find(x) != b.end() && b.find(y) != b.end()) || (c.find(x) != c.end() && c.find(y) != c.end())){
    cout << "Yes" << endl;
  }
  else
  {
    cout << "No" << endl;
  }
  
}

Measured memory_bytes: 3500
from math import sqrt

class  Point (object):
    def __init__(self, x, y):
        self.x = x
        self.y = y

def d (p1, p2):
    return sqrt((p1.x - p2.x) ** 2 + (p1.y - p2.y) ** 2)

data = [float(e) for e in input().split()]
p1 = Point(data[0], data[1])
p2 = Point(data[2], data[3])

print(d(p1, p2))


Measured memory_bytes: 5664
import java.util.*;
 
public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
 
        double W = sc.nextDouble();
        Double H = sc.nextDouble();
        Double x = sc.nextDouble();
        Double y = sc.nextDouble();

        if(x==W/2 && y==H/2){
            System.out.println(W * H / 2 + " " + 1);
        }
        else{
            System.out.println(W * H / 2 + " " + 0);
        }
    }
}

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

int main() {
  int n;
  int Alice,Bob=0;
  cin >> n;
  vector<int> vec(n);
  for(int i=0;i<n;i++){
    cin >> vec.at(i);
  }
  sort(vec.begin(), vec.end());
  reverse(vec.begin(), vec.end());
  for(int i=0;i<n;i++){
    if(i%2==0) Alice += vec.at(i);
    else Bob += vec.at(i);
  }
  cout << Alice - Bob << endl;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<queue>
#define pb push_back
#define pf push_front
#define Pf pop_front
#define MN 100005
using namespace std;
inline int in(){
    int x=0;bool f=0;char c;
    for (;(c=getchar())<'0'||c>'9';f=c=='-');
    for (x=c-'0';(c=getchar())>='0'&&c<='9';x=(x<<3)+(x<<1)+c-'0');
    return f?-x:x;
}
deque <int> q;
int dis[MN],k;
bool vis[MN];
int main()
{
	k=in();memset(dis,0x3f,sizeof(dis));
	dis[1]=0;q.pb(1);
	while (!q.empty()){
		int u=q.front();q.Pf();
		if (vis[u]) continue;
		if (!u) break;vis[u]=1;int v=(10*u)%k;
		if (dis[v]>dis[u]) dis[v]=dis[u],q.pf(v);
		v=(u+1==k)?0:u+1;
		if (dis[v]>dis[u]+1) dis[v]=dis[u]+1,q.pb(v);
	}printf("%d",dis[0]+1);return 0;
}

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

class DisjointSet {
public:
    vector<int> par;

    DisjointSet() {}
    DisjointSet(int size) {
        par.resize(size, 0);
        for (int i = 0; i < size; i++) {
            makeSet(i);
        }
    }

    void makeSet(int x) {
        par[x] = x;
    }

    bool same(int x, int y) {
        if (findset(x) == findset(y)) return true;
        else return false;
    }

    int findset(int x) {
        if (par[x] != x) {
            par[x] = findset(par[x]);
        }
        return par[x];
    }

    void unite(int x, int y) {
        link(findset(x), findset(y));
    }

    void link(int x, int y) {
        par[y] = x;
    }

};

int main() {
    int n, m;
    cin >> n >> m;
    vector<int> P(n + 1);
    for (int i = 1; i <= n; i++) {
        cin >> P[i];
    }
    DisjointSet ds = DisjointSet(n + 1);
    for (int i = 1; i <= m; i++) {
        int x, y;
        cin >> x >> y;
        ds.unite(x, y);
    }

    int cnt = 0;
    for (int i = 1; i <= n; i++) {
        if (ds.same(ds.par[i], ds.par[P[i]]) == true) {
            cnt++;
        }
    }

    cout << cnt << endl;

    return 0;
}


Measured memory_bytes: 1024
n, k = map(int, input().split())
a = list(map(int, input().split()))

try_count = min(50, k)

for i in range(try_count):
    imos_up = [0 for _ in range(len(a))]
    imos_down = [0 for _ in range(len(a))]
    for j in range(len(a)):
        up = max(0,j-a[j])
        imos_up[up] += 1
        down = min(len(a)-1, j+a[j])
        imos_down[down] += 1
    now = 0
    for j in range(len(a)):
        now += imos_up[j]
        a[j] = now
        now -= imos_down[j]

print(" ".join(list(str(s) for s in a)))

Measured memory_bytes: 182616
import java.util.*;
import static java.lang.System.*;
import static java.lang.Math.*;
public class Main {
    public static void main(String[] $) {
        Scanner sc = new Scanner(in);
        int n=sc.nextInt();
        int[][] f=new int[n][10];
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < 10; j++) {
                f[i][j]=sc.nextInt();
            }
        }
        int[][] p=new int[n][11];
        for (int i = 0; i < n; i++) {
            for (int j = 0; j <= 10; j++) {
                p[i][j]=sc.nextInt();
            }
        }
        long ans=Long.MIN_VALUE;
        for (int i = 1; i < (1<<10); i++) {
            long temp=0;
            int[] c=new int[n];
            for (int j = 0; j < 10; j++) {
                if((1&(i>>j))==1){
                    for (int k = 0; k < n; k++) {
                        c[k]+=f[k][j];
                    }
                }
            }
            for (int j = 0; j < n; j++) {
                temp+=p[j][c[j]];
            }
            ans=max(ans,temp);
        }
        out.println(ans);
    }
}

Measured memory_bytes: 26476
#include <iostream>
#include <utility>
#include <vector>

using namespace std;
typedef signed long long ll;

int N, M;
vector<pair<int, ll> > e[100000];
bool used[100000];
ll pos[100000];

int main() {
    cin >> N >> M;

    for (int i = 0; i < M; i++) {
        int l, r;
        ll d;
        cin >> l >> r >> d;
        l--;
        r--;

        e[l].push_back(make_pair(r, d));
        e[r].push_back(make_pair(l, -d));
    }

    for (int i = 0; i < N; i++) {
        used[i] = false;
    }

    for (int i = 0; i < N; i++) {
        if (used[i]) {
            continue;
        }

        vector<pair<int, ll> > stack;
        stack.push_back(make_pair(i, 0));

        while (!stack.empty()) {
            auto p = stack.back();
            stack.pop_back();
            int i = p.first;
            ll d = p.second;

            if (used[i]) {
                if (pos[i] != d) {
                    cout << "No" << endl;
                    return 0;
                }
            } else {
                used[i] = true;
                pos[i] = d;
                for (int j = 0; j < e[i].size(); j++) {
                    auto to = e[i][j];
                    stack.push_back(make_pair(to.first, d + to.second));
                }
            }
        }
    }

    cout << "Yes" << endl;
    return 0;
}


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

#define each(i, c) for (auto& i : c)
#define unless(cond) if (!(cond))

using namespace std;

typedef long long int lli;
typedef unsigned long long ull;
typedef complex<double> point;

template<typename P, typename Q>
ostream& operator << (ostream& os, pair<P, Q> p)
{
  os << "(" << p.first << "," << p.second << ")";
  return os;
}

int main(int argc, char *argv[])
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);

  int n;
  while (cin >> n) {
    int o = 0;
    int e = 0;
    for (int i = 0; i < n; ++i) {
      int a;
      cin >> a;
      if (a % 2 == 0) ++e;
      else ++o;
    }
    cout <<  ((o % 2 == 0) ? "YES" : "NO") << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main() {
    char arr[1000000];
    int n;
    cin >> n;
    for (int i = 0; i < n; i++) { cin >> arr[i]; }

    int i = 0;
    int ans = 0;
    while(i < n - 1) {
        if ((arr[i] == 'O' && arr[i + 1] == 'X') || (arr[i] == 'X' && arr[i + 1] == 'O')) {
            ans++;
            i += 2;
        } else {
            i++;
        }
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 3212