akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
// const bool debug=true;
const bool debug=false;
#define DEBUG if(debug==true)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll MOD = 1000000007;
const int MAX = 510000;
ll pow3[MAX],pow2[MAX];

void powinit(void){
    pow3[0]=1;
    rep(i,MAX-1){
        pow3[i+1] = pow3[i]*3;
        pow3[i+1] %= MOD;
    }
    pow2[0]=1;
    rep(i,MAX-1){
        pow2[i+1] = pow2[i]*2;
        pow2[i+1] %= MOD;
    }
}

int main(void) {
    string L;
    cin >> L;
    int n = L.size();
    int cnt=0;
    ll res=0;
    powinit();
    rep(i,n){
        if(L[i]=='1'){
            ll tmp;
            tmp = pow2[cnt];
            tmp *= pow3[n-i-1];
            tmp %=MOD;
            res += tmp;
            res %=MOD;
            cnt++;
        }
    }
    res += pow2[cnt];
    res %= MOD;
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 8448
#include <stdio.h>





void solve(int a) {
    a%=10;
    if (a==3) printf("bon");
    else if (a==0||a==1||a==6||a==8) printf("pon");
    else printf("hon");
}

int main () {
    int a;
    scanf("%d",&a);
    solve(a);
}


Measured memory_bytes: 1716
#include<bits/stdc++.h>
constexpr long long INFL = 1LL << 60;
constexpr int INF = 1e9;

using namespace std;

using ll = long long;

int main()
{
    int a,b,c;
    cin >> a >> b >> c;
    if(a == c) cout << b << endl;
    if(a == b) cout << c << endl;
    if(b == c) cout << a << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<cstring>
#include<sstream>
#include<iomanip>
#include<limits>
#include<deque>
#include<map>
#include<list>
#include<set>
#include <unordered_set>
#include<vector>
#include<cmath>
#include<cstdio>
#include<memory>
#include<bitset>
#include<stack>
#include<functional>
#include<queue>
#include<regex>
#include<time.h>
#include<type_traits>

using namespace std;
using ll = long long;

constexpr ll MOD = 1000000007;
constexpr ll INF = 1050000000;
constexpr ll LONGINF = 1050000000000000000;

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

	cout << (a + b)*h / 2 << endl;


	return 0;
}

Measured memory_bytes: 256
# B - Median Pyramid Easy
from collections import deque
N,x = map(int,input().split())
if x==1 or x==2*N-1:
    print('No')
elif N==2:
    print('Yes')
    for x in range(1,4):
        print(x)
else:
    print('Yes')
    if x==2:
        num = deque(list(range(5,2*N)))
        que = deque([3,2,1,4])
    else:
        num = deque(list(range(1,x-2))+list(range(x+2,2*N)))
        que = deque([x-1,x,x+1,x-2])
    for i in range(2*N-1):
        if N-2<=i<=N+1:
            print(que.popleft())
        else:
            print(num.popleft())

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

const long long MOD = 1e9 + 7;
long long dp[105][4][4][4];
 
int main() {
    int N; cin >> N;
    int A = 0;
    int G = 1;
    int C = 2;
    int T = 3;
 
    for (int j = 0; j < 4; j++) for (int k = 0; k < 4; k++) for (int l = 0; l < 4; l++) {
        if (j == A && k == G && l == C) continue;
        if (j == A && k == C && l == G) continue;
        if (j == G && k == A && l == C) continue;
        dp[2][j][k][l] = 1;
    }
  
    for (int i = 2; i < N - 1; i++) {
        for(int j = 0; j < 4; j++) for (int k = 0; k < 4; k++) for (int l = 0; l < 4; l++) for (int m = 0; m < 4; m++) {
            if (j == A && k == G && m == C) continue;
            if (j == A && l == G && m == C) continue;
            if (k == G && l == A && m == C) continue;
            if (k == A && l == G && m == C) continue;
            if (k == A && l == C && m == G) continue;
            dp[i + 1][k][l][m] = (dp[i + 1][k][l][m] + dp[i][j][k][l]) % MOD;
        }
    }
  
    long long ans = 0;
    for (int j = 0; j < 4; j++) for (int k = 0; k < 4; k++) for (int l = 0; l < 4; l++) {
        ans = (ans + dp[N - 1][j][k][l]) % MOD;
    }

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

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<tuple>
#include<cassert>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define Per(i,sta,n) for(int i=n-1;i>=sta;i--)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;
typedef pair<P, int> PP;
int dx[4]={1,-1,0,0};
int dy[4]={0,0,1,-1};

int h,w;
int cy,cx,gy,gx;
string S[1010];
int d[1010][1010];

void solve(){
    cin >> h >> w;
    rep(i,h){
        rep(j,w){
            d[i][j]=mod;
        }
    }
    cin >> cy >> cx >> gy >> gx;cy--;cx--;gy--;gx--;
    rep(i,h){
        cin >> S[i];
    }
    deque<PP> que;que.push_back(PP(P(cy,cx),0));
    while(!que.empty()){
        int y=que[0].first.first,x=que[0].first.second,l=que[0].second;
        que.pop_front();
        if(d[y][x]!=mod) continue;
        //cout << y << " " << x << " " << l << endl;
        d[y][x]=l;
        rep(k,4){
            int ny=y+dy[k],nx=x+dx[k];
            if(ny<0 || ny>h-1 || nx<0 || nx>w-1) continue;
            if(S[ny][nx]=='#') continue;
            que.push_front(PP(P(ny,nx),l));
        }
        Rep(i,-2,3){
            Rep(j,-2,3){
                int ny=y+i,nx=x+j;
                if(ny<0 || ny>h-1 || nx<0 || nx>w-1) continue;
                if(S[ny][nx]=='#') continue;
                que.push_back(PP(P(ny,nx),l+1));
            }
        }
    }
    if(d[gy][gx]<mod)cout << d[gy][gx] << endl;
    else cout << -1 << endl;
}

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

Measured memory_bytes: 10072
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <string>
#include <vector>
#include <math.h>
#include <queue>
#include <deque>
#include <map>
const int MOD = 1e9+7;
#define PI 3.14159265359
typedef long long ll;
using namespace std;

vector<pair<ll, ll> >primenum;

void prime(ll n){
	ll temp = n;
	for(ll i = 2; i*i <= n; i++){
		int coun = 0;
		while(n%i == 0){
			n /= i;
			coun++;
		}
		primenum.push_back(make_pair(i, coun));
	}
	primenum.push_back(make_pair(n, 1));
	return;
}


int main(){
	ll n;
	cin >> n;
	prime(n);
	ll ans = 0;
	for (auto x : primenum){
		if (x.first != 1){
		int hoge = x.second;
		for (int j = 1; ; j++){
			if (hoge >= j){
				ans++;
				hoge -= j;
			}else{
				break;
			}
		}
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 19704
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
int n,p,a[55];
ll dp[55][5];
int main(void){
    cin>>n>>p;
    cin>>a[0];
    dp[0][a[0]%2]++;
    dp[0][0]++;
    for(int i=1;i<n;i++){
		cin>>a[i];
		if(a[i]%2==0){
			dp[i][0]=2*dp[i-1][0];
			dp[i][1]=2*dp[i-1][1];
		}else{
			dp[i][0]=dp[i-1][0]+dp[i-1][1];
			dp[i][1]=dp[i-1][0]+dp[i-1][1];
		}
	}
	cout<<dp[n-1][p]<<endl;
	
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); 
#define endl '\n'
#define ll long long
#define mod 1000000007
#define inf 1000000000000000000

int main()
{
	fastio;
	#ifdef APNA_IO
		freopen("input.txt" , "rt" ,stdin);
		freopen("output.txt" , "wt" ,stdout);
	#endif
	ll n,l;
	cin>>n>>l;
	ll arr[n];
	for(ll i=0;i<n;i++)
		arr[i]=i+l;
	ll sum=0;
	for(ll i=0;i<n;i++)
	{
		sum+=arr[i];
	}
	if(arr[0]>0)
		cout<<sum-arr[0]<<endl;
	else if(arr[n-1]>=0)
		cout<<sum<<endl;
	else
		cout<<sum-arr[n-1]<<endl;
	return 0;
}





Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const long long MOD = 1e9 + 7, MAX = 1e18, larg = 1e5, INF = -1e9;
long long A, B, C, D, E, F, G, H, I, J, K, L, N, M, O, P, Q, R, S, T, U, V, W;
typedef long long ll;
typedef pair<ll, ll> Pa;

int cnt[100001];

vector<bool> IsPrime;
void sieve(size_t max) {
	if (max + 1 > IsPrime.size()) {     // resizeで要素数が減らないように
		IsPrime.resize(max + 1, true); // IsPrimeに必要な要素数を確保
	}
	IsPrime[0] = false; // 0は素数ではない
	IsPrime[1] = false; // 1は素数ではない

	for (size_t i = 2; i * i <= max; ++i) // 0からsqrt(max)まで調べる
		if (IsPrime[i]) // iが素数ならば
			for (size_t j = 2; i * j <= max; ++j) // (max以下の)iの倍数は
				IsPrime[i * j] = false;      // 素数ではない
}

int main()
{
	cin >> Q;
	sieve(100001);
	cnt[0] = 0;
	for (int i = 0; i < 50000; i++) {
		int num = i * 2 + 1;
		if (IsPrime[num] && IsPrime[(num + 1) / 2]) cnt[i + 1] = cnt[i] + 1;
		else cnt[i + 1] = cnt[i];
	}
	vector<int> ans;
	rep(i, Q) {
		cin >> A >> B;
		ans.push_back(cnt[(B - 1)/2+1] - cnt[(A - 1)/2]);
	}
	rep(i, Q) {
		cout << ans[i] << endl;
	}
}


Measured memory_bytes: 1404
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<set>
#include<map>
using namespace std ;

#define MAXN 2007
#define MOD 1000000007

int n , k ;
int a[ MAXN ] ;

int prv[ MAXN ] ;
int tot[ MAXN ] ;

void input ( ) {
    scanf ( "%d%d" , &n , &k ) ;
    for ( int i = 1 ; i <= n ; ++ i ) {
        scanf ( "%d" , &a[ i ] ) ;
    }
}

void solve ( ) {
    for ( int i = 1 ; i <= n ; ++ i ) {
        for ( int j = 1 ; j <= n ; ++ j ) {
            if ( a[ j ] > a[ i ] ) {
                if ( j < i ) { ++ prv[ i ] ; }
                ++ tot[ i ] ;
            }
        }
    }
    long long ans = 0 ;
    for ( int i = 1 ; i <= n ; ++ i ) {
        ans = ( ans + 1LL * k * prv[ i ] ) % MOD ;
        long long cur = 1LL * k * ( k - 1 ) / 2 ;
        cur %= MOD ;
        cur = ( cur * tot[ i ] ) % MOD ;
        ans = ( ans + cur ) % MOD ;
    }
    printf ( "%lld\n" , ans ) ;
}

int main ( ) {
    ios_base :: sync_with_stdio ( false ) ;
    cin.tie ( NULL ) ;
    input ( ) ;
    solve ( ) ;
    return 0 ;
}


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

using namespace std;

int main() {
	int N;
	cin >> N;
	int *a = new int[N];
	for (int i = 0; i < N; i++) cin >> a[i];
	vector<pair<int,int>> count(100010,make_pair(0,0));
	
	for (int i = 0; i < 100010; i++) count[i].second = i - 1;

	for (int i = 0; i < N; i++) {
		count[a[i] - 1+1].first++;
		count[a[i]+1].first++;
		count[a[i] + 1+1].first++;
	}

	sort(count.begin(), count.end(), greater<pair<int,int>>());
	cout << count.begin()->first << endl;

	return 0;
}

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

typedef long long ll;
#define pii pair<int , int>
#define _FastIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define MAXX 1005

int n , ans;
int p[MAXX];

int main()
{
    _FastIO;
    cin >> n;
    for(int i = 0; i < n; i++){
        cin >> p[i];
    }
    for(int i = 1; i < n - 1; i++){
        int x = min(p[i] , min(p[i - 1] , p[i + 1]));
        int y = max(p[i] , max(p[i - 1] , p[i + 1]));
        int z = (p[i - 1] + p[i] + p[i + 1]) - (x + y);
        if(z == p[i])   ans++;
    }
    cout << ans << endl;
    return 0;
}


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

#define fr first
#define sc second
#define mk make_pair
#define pb push_back
#define ll long long

using namespace std;

 long long oc[123] = {0};
int main()
{
    string s;
    long long  c = 0, n, sum = 0;
    int i;
    cin >> s;
    n = s.size();
    for (i = 0; i < n; i++)
    {
        oc[s[i]]++;
    }
    for (i = 97; i < 123; i++)
    {
        sum += max(0LL, (oc[i] * (oc[i] - 1) * 1LL) / 2);
    }
    cout << (((n * 1LL * (n - 1)) / 2) - sum) + 1;
}




Measured memory_bytes: 640
m['= r'][5],W,z,k,i,*p;f(i){k[p=m[i]]=p[4]+47?0:p[k]?:1+f(i+~(k%2*W)*~-(k&2));}main(t){for(scanf("%*d%d",&W);m[++i+W][4]=~getchar(););for(;k--?:(t=k=3,--i);z=z<-t?-t:z)t-=f(i+W);printf("%d",z);}

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

const int MAXN = 1e5 + 5;

int N, K;
int a[MAXN];

int main() {
	scanf("%d%d", &N, &K);
	for (int i = 1; i <= N; i++)
		scanf("%d", a + i);
	
	if (K == N) {
		puts("1");
		return 0;
	}
	
	int pos = 0;
	for (int i = 1; i <= N; i++)
		if (a[i] == 1)
			pos = i;
	
	int sol = 0, curr = 0;
	for (; curr + K < pos; curr += K - 1)
		sol++;
	
	curr += K;
	sol++;
	
	for (; curr < N; curr += K - 1)
		sol++;
	
	printf("%d\n", sol);
	
	return 0;
}

Measured memory_bytes: 640
using System;
class Program
{
	static void Main(string[] args)
	{
		// スペース区切りの整数の入力
		string[] input = Console.ReadLine().Split(' ');
		int a = int.Parse(input[0]);
		int b = int.Parse(input[1]);
		int k = int.Parse(input[3]);
		//出力
        int result = 0;
        if (k <= a)
        {
            result = k;
        }
        else if (k <= a + b)
        {
            result = a;
        }
        else
        {
            result = a - (k - a - b);
        }
        Console.WriteLine(result);
	}
}

Measured memory_bytes: 27544
n, k = map(int, input().split())
X = list(map(int, input().split()))

ans = 10 ** 9
for i in range(n - k + 1):
    x_min = X[i]
    x_max = X[i + k - 1]

    if x_min <= 0 <= x_max:
        dist_min = min(abs(x_min), x_max)
        dist_max = max(abs(x_min), x_max)

        ans = min(ans, 2 * dist_min + dist_max)
    else:
        ans = min(ans, max(abs(x_min), abs(x_max)))

print(ans)


Measured memory_bytes: 14568
/* 
chirag11032000
Chirag Thakur
*/

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

using ll = long long;
using db = double;
using pii = pair < int, int >;
using pll = pair < ll, ll >;

template < typename T > using OrderedSet = tree < T, null_type, less < T >, rb_tree_tag, tree_order_statistics_node_update >;
template < typename T > using MinPriorityQueue = priority_queue < T, vector < T >, greater < T > >;

#ifndef ONLINE_JUDGE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template < typename Arg1 >
void __f(const char* name, Arg1&& arg1) {
	cerr << name << " : " << arg1 << std::endl;
}
template < typename Arg1, typename... Args >
void __f(const char* names, Arg1&& arg1, Args&&... args) {
	const char* comma = strchr(names + 1, ',');
	cerr.write(names, comma - names) << " : " << arg1 << " | ";
	__f(comma + 1, args...);
}
#else
#define trace(...)
#endif

#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define unique_sort(x) sort(all(x)), x.resize(distance(x.begin(), unique(all(x))))

const db PI = acos(-1);
const ll LINF = LLONG_MAX;
const int INF = INT_MAX, MOD = 1e9 + 7, N = 1e5 + 10;

void test_case();

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	test_case();
	cerr << "Time taken: " << int((clock() * 1000.) / CLOCKS_PER_SEC) << "ms\n";
	return 0;
}

void test_case() {
	int n;
	cin >> n;
	vector < int > v(n);
	for (auto &el: v) {
		cin >> el;
	}
	int mx = -INF, cnt = 0;
	for (auto &el: v) {
		if (el >= mx) {
			++cnt;
		}
		mx = max(mx, el);
	}
	cout << cnt << "\n";
}

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

int main() {
  int lx = 0, ly = 0, rx, ry, N;
  cin >> rx >> ry >> N;
  rep(i, N) {
    int x, y, a;
    cin >> x >> y >> a;
    if(a == 1 && lx < x)
      lx = x;
    else if(a == 2 && rx > x)
      rx = x;
    else if(a == 3 && ly < y)
      ly = y;
    else if(a == 4 && ry > y)
      ry = y;
  }
  if(rx < lx || ry < ly)
    cout << 0 << endl;
  else
    cout << (rx - lx) * (ry - ly) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<int, int> pii;
#ifdef DEBUG
#define display(x) cerr << #x << " = " << x << endl;
#define displaya(a, st, n)\
	{cerr << #a << " = {";\
	for(int qwq = (st); qwq <= (n); ++qwq) {\
		if(qwq == (st)) cerr << a[qwq];\
		else cerr << ", " << a[qwq];\
	} cerr << "}" << endl;}
#define displayv(v) displaya(v, 0, (int)(v).size() - 1)
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
#define display(x) ;
#define displaya(a, st, n) ;
#define displayv(v) ;
#define eprintf(...) if(0) fprintf(stderr, "...")
#endif
template<typename T> bool chmin(T &a, const T &b) { return a > b ? a = b, true : false; }
template<typename T> bool chmax(T &a, const T &b) { return a < b ? a = b, true : false; }

const int maxN = 10000 + 5;
int n, deg[maxN];
vector<int> G[maxN];
vector<int> p;
int q[maxN];

int main() {
	ios::sync_with_stdio(false);
	cin >> n;
	memset(deg, 0, sizeof(deg));
	for(int i = 1; i < n; ++i) {
		int x, y; cin >> x >> y;
		G[x].push_back(y);
		G[y].push_back(x);
		deg[x]++; deg[y]++;
	}
	p.resize(n);
	for(int i = 0; i < n; ++i) cin >> p[i];
	if(n == 1) {
		cout << 0 << endl << p[0] << endl;
		return 0;
	}
	sort(p.begin(), p.end());
	reverse(p.begin(), p.end());
	queue<int> Q;
	for(int u = 1; u <= n; ++u) if(deg[u] == 1) Q.push(u);
	LL ans = std::accumulate(p.begin() + 1, p.end(), 0);
	while(Q.size()) {
		int u = Q.front(); Q.pop();
		q[u] = p.back(); p.pop_back();
		for(int v : G[u]) {
			if(--deg[v] == 1) Q.push(v);
		}
	}
	cout << ans << endl;
	for(int i = 1; i <= n; ++i) cout << q[i] << " ";
	cout << endl;
	return 0;
}


Measured memory_bytes: 1024
import sys
sys.setrecursionlimit(10**8)
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for i in range(N)]
def dp2(ini, i, j): return [[ini]*i for i2 in range(j)]
def dp3(ini, i, j, k): return [[[ini]*i for i2 in range(j)] for i3 in range(k)]
#import bisect #bisect.bisect_left(B, a)
#from collections import defaultdict #d = defaultdict(int) d[key] += value
#from collections import Counter # a = Counter(A).most_common()
#from itertools import accumulate #list(accumulate(A))

N, X = mi()
'''
def rec(level):
    if level == 0:
        return 'P'
    return 'B' + rec(level-1) + 'P' + rec(level-1) + 'B'

b = rec(N)
print(b)
'''
X -= 1
cnt = 0
level = N
while True:
    if level == 0:
        cnt += 1
        break
    half = 2**(level+1) - 2
    #print(level, half, cnt)
    if X == 0:
        break
    elif X == half * 2:
        cnt += 2**(level+1) - 1
        break
    elif X > half:
        cnt += 2**(level)
        X -= half + 1
    elif X == half:
        cnt += 2**(level)
        break 
    else:
        X -= 1
    level -= 1
print(cnt)

Measured memory_bytes: 3064
fun main(args: Array<String>) {
    val (a, b) = readLine()!!.split(" ").map(String::toInt)
    if (a == b) {
        println(0)
        return
    }
    if ((a - b) % 2 == 0) {
        val k = a+b
        if (k>=0){
            print(k/2)
        }else{
            print(-k/2)
        }
        return
    }
    print("IMPOSSIBLE")
}

Measured memory_bytes: 37740
import java.util.*;

class Main {
    static int N ;
    static int M ;
    static int Q ;
    static int[] a;
    static int[] b;
    static int[] c;
    static int[] d;
    static int[] A;

    static int max = 0 ;
    
  
	
	public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        N = sc.nextInt();
        M = sc.nextInt();
        Q = sc.nextInt();
        a = new int[Q];
        b = new int[Q];
        c = new int[Q];
        d = new int[Q];
        A = new int[N];
  
        
        for(int i = 0; i < Q; i++) {
             a[i] = sc.nextInt();
             b[i] = sc.nextInt();
             c[i] = sc.nextInt();
             d[i] = sc.nextInt();
        }
        
        
        array(0);
        System.out.println(max);
        
        
        }
	
	public static void array(int i) {		
		for(int j = 1; j <= M; j++) {
				if(i == 0 || A[i-1] <= j) {
					A[i] = j;		
				
					if(i == N-1) {
						//System.out.print("A = ");
						//for(int n : A) {
							//System.out.print(n + ",");
						//}
						//System.out.println();
						calcSum();
					}else {
						array(i+1);
				}
			}
		}			
	}
	
	public static void calcSum() {
		
		int sum = 0;
		for(int i = 0; i < Q; i++) {
				if(A[b[i]-1]- A[a[i]-1] == c[i]){
					sum += d[i];
				}				
		}
		//System.out.println("sum = " + sum);
		max = Math.max(max, sum);
	}
}
		
	


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

#define FAST ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

#define MAXX 100005

#define PI 3.14159265358979323846264338327950

#define ll signed long long int

ll a[MAXX];
multiset<ll> ms;
multiset<ll>::iterator it;
signed main()
{
    FAST;
    char b;
    cin >> b;
    if(b == 'A'){
    	cout << "T";
	}
	else if(b == 'T'){
		cout << "A";
	}
	else if(b == 'C'){
		cout << "G";
	}
	else{
		cout << "C";
	}
}

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

int main() {
        
    int W,H,x,y,r;
    cin>>W>>H>>x>>y>>r;
    if(r<=x&&x<=W-r&&r<=y&&y<=H-r) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}



Measured memory_bytes: 3108
#include <stdio.h>

int main(void){
	int n,k;;
	char s[11];
	scanf("%d",&n);
	scanf("%s",s);
	scanf("%d",&k);
	char x[2];
	x[0] = s[k-1];
	for(int i=0;i<n;i++){
		if(s[i]!=x[0])printf("*");
		else printf("%c",x[0]);
	}
	return 0;
}

Measured memory_bytes: 128
n, m, k = [int(i) for i in input().split()]
p = 10 ** 9 + 7

S = 0

for d in range(n):
    S += m ** 2 * d * (n - d)
    S %= p

for d in range(m):
    S += n ** 2 * d * (m - d)
    S %= p

def fact(n, p=10**9 + 7):
    f = [1]
    for i in range(1, n+1):
        f.append(f[-1]*i%p)
    return f

def invfact(n, f, p=10**9 + 7):
    inv = [pow(f[n], p-2, p)]
    for i in range(n, 0, -1):
        inv.append(inv[-1]*i%p)
    return inv[::-1]

f = fact(n * m - 2)
invf = invfact(n * m - 2, f)

def comb(a, b):
    if a < b:
        return 0
    if a < 0 or b < 0:
        return 0
    return f[a] * invf[b] * invf[a-b] % p

S *= comb(n * m - 2, k - 2)

print(S % p)

Measured memory_bytes: 56052
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define inf 10e17
#define rep(i,n) for(long long i=0; i<n; i++)
#define repr(i,n,m) for(long long i=m; i<n; i++)
#define mod 1000000007
#define sorti(x) sort(x.begin(), x.end())
#define sortd(x) sort(x.begin(), x.end(), std::greater<long long>())
#define debug(x) std::cerr << (x) << std::endl;
#define roll(x) for (auto&& itr : x) { cerr << (itr) << " "; }

template <class T> inline void chmax(T &ans, T t) { if (t > ans) ans = t;}
template <class T> inline void chmin(T &ans, T t) { if (t < ans) ans = t;}

int main() {
  int n,r;
  cin >> n >> r;
  if (n >= 10) {
    cout << r << endl;
  } else {
    cout << r + 100 * (10 - n) << endl;
  }
}

Measured memory_bytes: 256
from collections import Counter


def main():
    N = int(input())
    D = input().split()
    M = int(input())
    T = input().split()

    d = Counter(D)
    t = Counter(T)
    for key, value in t.items():
        if d.get(key, 0) < value:
            print('NO')
            exit()
    else:
        print('YES')


if __name__ == '__main__':
    main()

Measured memory_bytes: 69344
#include<stdio.h>
int main(void)
{
    int n,r,p,c,N[50],i,j,C[51];
    for(i=0;i<50;i++){
        N[i]=0;
        C[i]=0;
    }
    while(1){
        scanf("%d%d",&n,&r);
        if(n==0&&r==0) break;
        for(i=0;i<n;i++) N[i]=n-i;
        for(i=0;i<r;i++){
            scanf("%d%d",&p,&c);
            for(j=0;j<c;j++) C[j]=N[p-1+j];
            for(j=0;j<p-1;j++) N[p+c-2-j]=N[p-2-j];
            for(j=0;j<c;j++) N[j]=C[j];
        }
    printf("%d\n",N[0]);
    }
    return 0;
}    

Measured memory_bytes: 600
#include <iostream>

using namespace std;

int main(int argc, char* argv[])
{
    int N; cin >> N;
    if (N == 1) {
        cout << "Hello World" << endl;
    } else {
        int A, B; cin >> A >> B;
        cout << A+B << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
void solve();
typedef long long ll;
#define endl "\n"
const unsigned int M = 1000000007;

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

#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("error.txt", "w", stderr);
	freopen("output.txt", "w", stdout);
#endif

	int t = 1;
	///*is Single Test case?*/cin>>t;
	while (t--) {
		solve();
		cout << "\n";
	}
	cerr << "time taken : " << (float)clock() / CLOCKS_PER_SEC << " secs" << endl;
	return 0;
}

void solve() {
	int n, sum = 0;
	cin >> n;
	int t = 3;
	for (int i = 1; i <= 3; ++i) {
		sum += pow(n, i);
	}
	cout << sum;
}

Measured memory_bytes: 4136
import Control.Monad
import Data.Char

countCh str ch = length $ filter (== ch) str
countChs str = [countCh str1 ch | ch <- ['a'..'z']]
  where
    str1 = map (\ch -> if isUpper ch then toLower ch else ch) str
    
main = do
  str <- getContents
  mapM_ putStrLn $ zipWith (++) (map (\x -> x : " : ") ['a'..'z']) $ map show $ countChs str

Measured memory_bytes: 3736
import java.util.*;
class Main
{
	public static void main(String[] args)
	{
		Scanner sc = new Scanner(System.in);
		int K = sc.nextInt();
		String Sa = sc.nextLine();
		String S = sc.nextLine();
		
		if(K >= S.length())
		{
			System.out.println(S);
		}
		else
		{
			String T = S.substring(0, K);
			String U = T + "...";
			System.out.println(U);
		}
	}
}


Measured memory_bytes: 38684
#include<iostream>
#include<string>
using namespace std;
int main(){
    int x = 0;
    string s , t;
    cin >> s >> t;
    for(int i = 0 ; i < 3 ; i++){
        if(s[i] == t[i])
            x++;
    }
    cout << x << endl;
    return 0;
}


Measured memory_bytes: 256
N = int(input())
S = [input() for _ in range(N)]
counter1 = 0
counter2 = 0
counter3 = 0
for s in S:
    if s[-1] == "A":
        if s[0] == "B":
            counter1 += 1
        else:
            counter2 += 1
    elif s[0] == "B":
        counter3 += 1
ans = 0
if counter1 == 0:
    ans += min(counter2, counter3)
else:
    if counter2 + counter3 > 0:
        ans += (counter1 + min(counter2, counter3))
    else:
        ans += (counter1 - 1)

for s in S:
    ans += s.count("AB")
print(ans)


Measured memory_bytes: 3700
#include <stdio.h>
#define min(a,b) a>b?b:a
int main()
{
	int n,k,ans=1,i;
	scanf("%d %d",&n,&k);
	for(i=0;i<n;i++)
		ans=min(ans*2,ans+k);
	printf("%d",ans);
}

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

using namespace std;

const double PI = acos(-1);

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  double A, B, H, M;
  cin >> A >> B >> H >> M;
  complex<double> a = polar(A, (H + M / 60) / 12 * 2 * PI);
  complex<double> b = polar(B, M / 60 * 2 * PI);
  cout << fixed << setprecision(10) << abs(a - b) << '\n';
  return 0;
}


Measured memory_bytes: 4108
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

N, M = map(int, readline().split())
outdeg = {i: [] for i in range(N)}
for _ in range(M):
    a, b = map(int, readline().split())
    a -= 1
    b -= 1
    outdeg[a].append(b)

dp = [-1] * (N)


def rec(s):
    if dp[s] != -1:
        return dp[s]

    res = 0
    for t in outdeg[s]:
        res = max(res, rec(t)+1)
    dp[s] = res
    return res


ans = 0
for s in range(N):
    ans = max(ans, rec(s))
print(ans)


Measured memory_bytes: 67516
s = str(input())
s0 = s[0]
if s0 == s[1]:
    if s[2] == s[3] and s[2] != s0:
        print('Yes')
    else:
        print('No')
else:
    s1 = s[1]
    if s1 in s[2:4] and s0 in s[2:4]:
        print('Yes')
    else:
        print('No')


Measured memory_bytes: 38384
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll h, w, sx, sy, gx, gy;
constexpr ll INF = (ll)(1e9 + 7);
vector<string> maze(50);
typedef pair<ll, ll> P;
vector<vector<ll>> a(50, vector<ll>(50));

ll dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
ll bfs()
{
    queue<P> que;
    for (int i = 0; i < h; i++)
    {
        for (int j = 0; j < w; j++)
        {
            a[i][j] = INF;
        }
    }
    que.push(P(sy, sx));
    a[sy][sx] = 0;
    while (que.size())
    {
        P p = que.front();
        que.pop();
        if (p.first == gy && p.second == gx)
            break;
        for (int i = 0; i < 4; i++)
        {
            ll ny = dy[i] + p.first, nx = dx[i] + p.second;
            if (0 <= nx && nx < w && 0 <= ny && ny < h && maze[ny][nx] == '.' && a[ny][nx] == INF)
            {
                que.push(P(ny, nx));
                a[ny][nx] = a[p.first][p.second] + 1;
            }
        }
    }
    return a[gy][gx];
}
int main()
{
    ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    cin >> h >> w;
    for (ll i = 0; i < h; i++)
    {
        cin >> maze[i];
    }
    vector<pair<ll, ll>> dot;
    for (ll i = 0; i < h; i++)
    {
        for (ll j = 0; j < w; j++)
        {
            if (maze[i][j] == '.')
                dot.emplace_back(make_pair(j, i));
        }
    }
    ll ans = 0;
    for (ll i = 0; i < dot.size(); i++)
    {
        for (ll j = dot.size() - 1; 0 <= j; j--)
        {
            sx = dot[i].first;
            sy = dot[i].second;
            gx = dot[j].first;
            gy = dot[j].second;
            ans = max(bfs(), ans);
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
// vim: foldmethod=marker
#include <iostream> // cout, endl, cin{{{
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
using namespace std;
typedef long long ll;/*}}}*/

int main(int argc, char *argv[])
{
  string s;
  cin >> s;
  int ans;

  if (s == "SUN") {
    ans = 7;
  } else if (s == "MON") {
    ans = 6;
  } else if (s == "TUE") {
    ans = 5;
  } else if (s == "WED") {
    ans = 4;
  } else if (s == "THU") {
    ans = 3;
  } else if (s == "FRI") {
    ans = 2;
  } else if (s == "SAT") {
    ans = 1;
  }
  cout << ans << endl;
}


Measured memory_bytes: 760
N, M = map(int, input().split())
XYZ = [list(map(int, input().split())) for _ in range(N)]

ans = -float('inf')
patterns = [[a, b, c] for a in [-1, +1] for b in [-1, 1] for c in [-1, 1]]
for a, b, c in patterns:
    values = [a*x+b*y+c*z for x, y, z in XYZ]
    ans = max(ans, sum(sorted(values, reverse=True)[:M]))
print(ans)


Measured memory_bytes: 3316
import std.algorithm, std.conv, std.range, std.stdio, std.string;
import std.bitmanip;  // BitArray

alias graph = Graph!(int, size_t);

void main()
{
  auto rd1 = readln.split.to!(size_t[]), n = rd1[0], m = rd1[1];

  struct Edge { size_t a, b; int c; }

  auto e = new Edge[](m);
  auto g = new int[][](n, n);
  foreach (i; 0..n) {
    g[i][] = graph.inf;
    g[i][i] = 0;
  }

  foreach (i; 0..m) {
    auto rd2 = readln.splitter;
    auto a = rd2.front.to!size_t-1; rd2.popFront();
    auto b = rd2.front.to!size_t-1; rd2.popFront();
    auto c = rd2.front.to!int;
    e[i] = Edge(a, b, c);
    g[a][b] = g[b][a] = c;
  }

  auto d = graph.floydWarshal(g);

  auto ans = BitArray();
  ans.length = m;

  foreach (i; 0..n)
    foreach (j; 0..m) {
      auto a = e[j].a, b = e[j].b, c = e[j].c;
      if (d[i][a] + c == d[i][b] || d[i][b] + c == d[i][a])
        ans[j] = true;
    }

  writeln(m - ans.bitsSet.walkLength);
}

template Graph(Wt, Node, Wt _inf = 10 ^^ 9, Node _sent = Node.max)
{
  import std.algorithm, std.array, std.conv;

  const inf = _inf, sent = _sent;

  Wt[][] floydWarshal(Wt[][] g)
  {
    Wt[][] dist;
    Node[][] inter;
    floydWarshal(g, dist, inter);
    return dist;
  }

  void floydWarshal(Wt[][] g, out Wt[][] dist, out Node[][] inter)
  {
    auto n = g.length;
    dist = g.map!(i => i.dup).array;

    inter = new Node[][](n, n);
    foreach (i; 0..n) inter[i][] = sent;

    foreach (k; 0..n)
      foreach (i; 0..n)
        foreach (j; 0..n)
          if (dist[i][j] > dist[i][k] + dist[k][j]) {
            dist[i][j] = dist[i][k] + dist[k][j];
            inter[i][j] = k.to!Node;
          }
  }
}


Measured memory_bytes: 508
#include<stdio.h>
int main()
{
	int a,b;
	scanf("%d%d",&a,&b);
	if(a!=1&&b!=1)
	{
		printf("1\n");
	}
	else if(a!=2&&b!=2)
	{
		printf("2\n");
	}
	else{ printf("3\n");}
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define fi first
#define se second
typedef pair<ll, ll> P;
using VP = vector<P>;
using VVP = vector<VP>;
using VI = vector<ll>;
using VVI = vector<VI>;
using VVVI = vector<VVI>;
const int inf = 1e9 + 7;
const ll INF = 1LL << 61;
const ll mod = 1e9 + 7;

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

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

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int i, j;
    ll n, a, b;
    cin >> n >> a >> b;
    VI x(n);
    for (i = 0; i < n; i++) cin >> x[i];
    VI v;
    for (i = 1; i < n; i++) {
        v.pb(a * (x[i] - x[i - 1]));
    }
    // sort(v.begin(),v.end());
    ll m = n - 1;
    ll ans = 0;
    for (i = 0; i < n - 1; i++) {
        if (v[i] < b) {
            ans += v[i];
            m--;
        }
    }
    ans += m * b;
    cout << ans << endl;
}

Measured memory_bytes: 5044
from collections import Counter
N = int(input())
A = list(map(int,input().split()))
d=Counter(A)
dic={}
total=0
for item in d.items():
    counter=item[1]
    s1=(counter - 1)*(counter - 2)/2 #1個少ない
    s2=(counter)*(counter - 1)/2
    dic[item[0]]=int(s1 - s2)
    total+=int(s2)

for a in A:
    print(total + dic[a])


Measured memory_bytes: 30892
n = int(input())
s = input()+"?"
i = 0
ref = []
mod = 10**9+7
while i<n:
	if s[i]==s[i+1]:
		ref += [1]
		i += 2
	else:
		ref += [0]
		i += 1
ans = 6 if ref[0] else 3
for i,j in zip(ref,ref[1:]):
	if (1-i)&(1-j):
		ans *= 2
	elif i&(1-j):
		ans *= 1
	elif (1-i)&j:
		ans *= 2
	else:
		ans *= 3
	ans %= mod
print(ans)

Measured memory_bytes: 3064
<?php

fscanf(STDIN, "%d %d", $n, $x);

$num_arr = array_map("intval", explode(" ", trim(fgets(STDIN))));
$count = 1;
$dist = 0;
for ($i = 0; $i < $n; $i++) {
    $dist += $num_arr[$i];
    if ($x < $dist) {
        break;
    }
    $count++;
}

echo $count, "\n";

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

int main(){
  int n,k;
  cin >> n >> k;
  vector<pair<long long,long long>> xys;
  vector<long long>xs(n),ys(n);

  for (int i = 0; i < n; i++)
  {
    long long x,y;
    cin >> x >> y;
    xys.emplace_back(x,y);
    xs[i]=x;
    ys[i]=y;
  }
  sort(xs.begin(),xs.end());
  sort(ys.begin(),ys.end());

  long long minarea = 4000000000000000010;
  for (int i = 0; i < n-1; i++)
  {
    for (int j = n-1; j > i; j--)
    {
      for (int l = 0; l < n-1; l++)
      {
        for (int m = n-1; m > l; m--)
        {
          long long minx = xs[i];
          long long maxx = xs[j];
          long long miny = ys[l];
          long long maxy = ys[m];
          long long area = (maxx-minx)*(maxy-miny);

          int cnt = 0;
          for(auto xy:xys){
            long long x = xy.first;
            long long y = xy.second;
            if(x>=minx && x<=maxx && y>=miny && y<=maxy) cnt++;
          }
          if(cnt>=k) minarea = min(minarea,area);
        }
      }
    }
  }
  
  cout << minarea << endl;
}

Measured memory_bytes: 256
#include <vector> 
#include <list> 
 #include <map>
 #include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <queue>
using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

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


set<int64_t> st;
int N;
int64_t k;
int main(){
    cin>>N;
    REP(i,N){
        cin>>k;
        if(EXIST(st,k)){
            st.erase(k);
        }
        else{
            st.insert(k);
        }
    }

    cout<<st.size()<<endl;
}

Measured memory_bytes: 4864
#include <iostream>
#include <cmath>
using namespace std;

#define rep(i, n) for(int i = 0; i < n; i++)
const double EPS = 1e-10;

int main(){
  int n;
  int id, w, h;
  int best;
  double dif;
  while(cin >> n && n){
    best = 0;
    dif = 1e10;
    rep(i, n){
      cin >> id >> h >> w;
      double d = abs(22.0 - (double)w / ((double)h * h) * 10000);
      if(d < dif || abs(d - dif) < EPS && id < best){
	dif = d;
	best = id;
      }

    }
    cout << best << endl;
  }
  return 0;
}

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

int main() {
    int N; cin >> N;
    vector<double> A(N);
    rep(i, N){
        cin >> A[i];
    }

    long double ans = 0;
    rep(i, N){
        double a = 1.0 / A[i];
        ans += a;
    }

    ans = 1.0 / ans;

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3812
#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>
using namespace std;
using namespace __gnu_pbds;
#define ll long long
#define int long long
#define endl "\n"
#define fi first
#define se second
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define fr(a,b,c) for(int a=b; a<c; a++)
#define frr(a,b,c) for(int a=b;a>=c;a--)
#define pb push_back
#define pii pair<int,int>
#define R(a) ll a; cin >> a;
#define RS(a) string  a; cin >> a;
typedef tree<long long,null_type,greater<long long>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
typedef tree<long long,null_type,less<long long>,rb_tree_tag,tree_order_statistics_node_update> ordered_set1;

#define RA(a, n) ll a[(n) + 1] = {}; fr(i, 1, (n)+1) {cin >> a[i];}
#define RM(a, n, m) int a[n + 1][m + 1] = {}; fr(i, 1, n+1) {fr(j, 1, m+1) cin >> a[i][j];}
#define reset(X) memset(X, 0, sizeof(X))
using vi=vector<int>;
const int inf = 1e18;
const int mod=1e9+7;
unsigned int power(int x, unsigned int y, int p)
{
    int res = 1;
    x = x % p;
    while (y > 0)
    {
        if (y & 1)
            res = (res*x) % p;
        y = y>>1;
        x = (x*x) % p;
    }
    return res;
}
bool isPrime(int n)
{   if (n <= 1)  return false;
    if (n <= 3)  return true;
    if (n%2 == 0 || n%3 == 0) return false;
    for (int i=5; i*i<=n; i=i+6)
        if (n%i == 0 || n%(i+2) == 0)
           return false;
    return true;
}
int modInverse(int n, int p)
{
    return power(n, p-2, p);
}
signed main()
{
    fastio;
    string s;
    cin>>s;
    int cnt=0,mx=0;
    fr(i,0,s.size())
    {
        if(s[i]=='R')
        {
            cnt+=1;
        }
        else
        {
            mx=max(mx,cnt);
            cnt=0;
        }
    }
  mx=max(mx,cnt);
    cout<<mx<<endl;
}


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

#ifdef LOCAL
#define DEBUG(...) cerr << #__VA_ARGS__ << ": ", debug(__VA_ARGS__);
#else
#define DEBUG(...)
#endif

template<typename T, typename S> ostream& operator << (ostream &os, const pair<T, S> &p) {return os << "(" << p.first << ", " << p.second << ")";}
template<typename T> ostream& operator << (ostream &os, const vector<T> &v) {os << "["; for (int i=0; i<(int)v.size(); i++) {if (i) os << ", "; os << v[i];} return os << "]";}
void debug() {cerr << "\n";} template<typename T, typename... Args> void debug(T x, Args... args) {cerr << x << "; "; debug(args...);}

int a[100];

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);

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

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

    int select = 0;
    for (int i=0; i<n; i++)
        if (a[i] * 4 * m >= sum)
            select++;

    cout << (select < m ? "No" : "Yes") << "\n";

    return 0;
}


Measured memory_bytes: 256
import math,itertools,fractions,heapq,collections,bisect,sys,queue,copy

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

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

class ComMod():
  def __init__(self,n_max,mod):
    self.mod=mod
    self.fact=[0]*(n_max+1)
    self.ifact=[0]*(n_max+1)
    self.fact[0]=1  
    for i in range(1,n_max+1):
      self.fact[i]=self.fact[i-1]*i
      self.fact[i]%=mod
    self.ifact[n_max]=pow(self.fact[n_max],mod-2,mod)
    for i in range(n_max,0,-1):
      self.ifact[i-1]=self.ifact[i]*i
      self.ifact[i-1]%=mod
  def com(self,n,k):
    if n<0 or k<0 or n<k:
      return 0
    return self.fact[n]*(self.ifact[k]*self.ifact[n-k]%self.mod)%self.mod

def main():
  n,m,k=LI()
  res=0
  mod=998244353
  tmp=m*pow(m-1,n-k-1,mod)

  c=ComMod(200005,mod)

  for r in range(n-k-1,n):
    res=(res+tmp*c.com(n-1,r)%mod)%mod
    tmp=tmp*(m-1)%mod
  return res

# main()
print(main())


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

signed main () {
    int n, s;
    int64_t mod = 998244353;
    cin >> n >> s;
    vector < int > a(n + 1, 0);
    for (int i = 1; i <= n; ++i)
        cin >> a[i];
    vector < vector < int64_t > > dp(n + 1, vector < int64_t > (s + 1, 0));
    dp[0][0] = 1;
    for (int i = 1; i <= n; ++i) {
        for (int j = 0; j <= s; ++j) {
            (dp[i][j] += 2 * dp[i - 1][j]) %= mod;
            if (j + a[i] <= s)
                (dp[i][j + a[i]] += dp[i - 1][j]) %= mod;
        }
    }
    cout << dp[n][s] << '\n';
}


Measured memory_bytes: 73756
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define ok() puts(ok?"Yes":"No");
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<vi> vvi;
typedef vector<ii> vii;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef set<int> si;
typedef map<string, int> msi;
typedef greater<int> gt;
typedef priority_queue<int, vector<int>, gt> minq;
typedef long long ll;
typedef pair<ll,ll> pll;
const ll LINF = 1e18L + 1;
const int INF = 1e9 + 1;
//clang++ -std=c++11 -stdlib=libc++ 

int main() {
  int n; cin >> n;
  vector<pair<string, int>> rest(n);
  map<int, int> mp;
  rep(i,n) {
    string s; int p;
    cin >> s >> p;
    rest[i] = make_pair(s,p);
    mp[p] = i;
  }
  sort(rest.begin(), rest.end(), [] (pair<string, int> a, pair<string, int> b) {
    if (a.first == b.first) return a.second > b.second;
    return a.first < b.first;
  });
  rep(i,n) {
    cout << mp[rest[i].second] + 1 << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstdio>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <cstring>
#include <cstdlib>
using namespace std;

#define REP(i,n) for(int i = 0; i < (int)(n); i++)
typedef long long ll;
typedef pair<int, int> pint;
template <class T> inline void chmax(T &a, const T b) { a = max(a, b); }
template <class T> inline void chmin(T &a, const T b) { a = min(a, b); }
template <class T> void pp(T v, int n) { REP(i,n) cout<<v[i]<< ' '; cout << endl; }

void inline TorF(bool tf, const string &trueMessage, const string &falseMessage) { 
  cout << (tf ? trueMessage : falseMessage) << endl;
}
void inline YESNO(bool tf) { TorF(tf, "YES", "NO"); }
void inline YesNo(bool tf) { TorF(tf, "Yes", "No"); }

typedef int Edge;
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;
Graph g;
vector<int> pre;

int main() {
  int N, M; cin>>N>>M;
  g = Graph(N);
  pre = vector<int>(N,-1);
  REP(i,M) {
    int from, to; cin>>from>>to; from--; to--;
    g[from].push_back(to);
    g[to].push_back(from);
  }
  deque<int> q[2];
  q[0].push_back(0);
  for(int step = 0; ; step++) {
    const int from = step % 2, to = 1 - from;
    if(q[from].empty()) break;
    q[to].clear();
    REP(i, q[from].size()) {
      const int cur = q[from][i];
      REP(j, g[cur].size()) {
	const int nxt = g[cur][j];
	if(pre[nxt] < 0) {
	  //	  cout << cur+1 << "->" << nxt+1 << endl;
	  pre[nxt] = cur;
	  //	  pp(pre, pre.size());
	  q[to].push_back(nxt);
	}
      }
    }
  }
  cout << "Yes" << endl;
  for(int i = 1; i < N; i++) {
    cout << pre[i]+1 << endl;
  }
  return 0;
}


Measured memory_bytes: 9916
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner scan = new Scanner(System.in);
    int n = scan.nextInt();
    int[] a = new int[n];
    for (int i=0;i<n;i++){
      a[i] = scan.nextInt();
    }

    int[] b = new int[n];
    ArrayList<Integer> c = new ArrayList<Integer>();
    for (int i=n-1;i>=0;i--){
      if ((b[i] % 2) != a[i]){
        c.add(i+1);
        b = add1(b,i+1);
      }
    }

    Collections.sort(c);
    System.out.println(c.size());
    if (c.size() == 0){
      return;
    }
    for (int j=0;j<c.size()-1;j++){
      System.out.print(c.get(j) +" ");
    }
    System.out.println(c.get(c.size()-1));
  }

  static int[] add1(int[] a, int b){
    int g = (int) Math.sqrt(b);
    if (g*g == b){
      a[g-1] -= 1;
    }

    for (int i=g;i>=1;i--){
      if ((b%i) == 0){
        a[i-1] += 1;
        int t = (int) b/i;
        a[t-1] += 1;
      }
    }
    return a;
  }
}


Measured memory_bytes: 63468
n,m = gets.chomp.split.map(&:to_i)
ds = n.times.map{gets.chomp.split.map(&:to_i)}.sort_by(&:first)

sum = 0
ds.each do |a,b|
  break if m == 0
  sum += a * [b, m].min
  m = [m - b,0].max
end

puts sum

Measured memory_bytes: 12664