akhauriyash/Code-Regression huggingface dataset:
unittest
{
	assert( [ "6", "3 1 2 4 2 1" ].parse.expand.solve == 2 );
	assert( [ "4", "1 2 3 4" ].parse.expand.solve == 0 );
	assert( [ "10", "3 3 3 3 4 4 4 5 5 5" ].parse.expand.solve == 20 );
}



import std.algorithm;
import std.conv;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

void main()
{
	stdin.byLineCopy.parse.expand.solve.writeln;
}

auto parse( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto n = input.front.strip.to!( long );
	input.popFront;
	auto as = input.front.split.to!( long[] );
	return tuple( as );
}

auto solve( long[] as )
{
	auto gs = as.sort!( ( a, b ) => b < a ).group;
	
	auto a = 0L;
	auto b = 0L;
	foreach( g; gs )
	{
		if( a == 0 && 4 <= g[ 1 ] )
		{
			a = g[ 0 ];
			b = g[ 0 ];
			break;
		}
		if( 2 <= g[ 1 ] )
		{
			if( a == 0 )
			{
				a = g[ 0 ];
				// まだ片方の辺しか決まってないので続行
			}
			else
			{
				b = g[ 0 ];
				break;
			}
		}
	}
	
	return a * b;
}


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

int main() {
    int D; cin >> D;
    vector<int> c(26);
    for (int i = 0; i < 26; i++) cin >> c.at(i);
    vector<vector<int>> s(D, vector<int>(26));
    for (int i = 0; i < D; i++) {
        for (int j = 0; j < 26; j++) {
            cin >> s.at(i).at(j);
        }
    }

    int ns = 0;
    vector<int> last(26, 0);
    for (int i = 0; i < D; i++) {
        int t; cin >> t;
        ns += s.at(i).at(t-1);
        last.at(t-1) = i + 1;
        
        for (int j = 0; j < 26; j++) {
            ns -= c.at(j) * (i + 1 - last.at(j));
        }
        cout << ns << endl;
    }
    
}

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

int main() {
    ll a, b, x, ans = 0;
    cin >> a >> b >> x;
    if(a<b*2){
        ans += x/1000*a;
        x %= 1000;
    }
    if(x>0)ans += min(((x-1)/1000+1)*a,((x-1)/500+1)*b);
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 3124
function Main(input) {
	input = input.trim().split(" ").map((a)=>Number(a));
  var A = input[0];
  var B = input[1];
  var list = [A+B,A-B,A*B];
  var max = Math.max.apply(null,list);
  if(max == "-0"){
     max = 0;
     }
  console.log(max);
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 7372
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define ppb pop_back
#define pii pair<int, int> 
#define all(a) a.begin(), a.end()
#define int long long
#define ll long long
#define vi vector<int>
#define vip vector<pii>
#define mod1 998244353
#define mod 1000000007
#define endl "\n"
#define loop(i,a,b) for(int i=a;i<b;i++)
#define bloop(i,a,b) for(int i=a;i>=b;i--)
#define testcase  int t; cin>>t; while(t--) 
#define FIO ios_base::sync_with_stdio(false);  cin.tie(NULL);

using namespace std;

int max(int a, int b) { return (a > b)? a : b; } 

int min(int a, int b) { return (a < b)? a : b; }


   
/*************************************************************************/



int32_t main() {
	
	FIO
	// testcase
	{
		string s;
		cin>>s;
		for(int i=0;i<3;i++)
		cout<<s[i];
		
	}
	return 0;
}

Measured memory_bytes: 3576
"use strict";
const main = arg => {
    var input = arg.split('\n');
    var line = input.shift();
    var lines = input.shift().split(' ').map(i => BigInt(i));

    var answer =  lines[0];

    if(lines.includes(0n)){
        console.log(0);
        return;
    }

    for(let i = 1; i < line;i++){

        answer = answer * lines[i];
        if(answer > 1000000000000000000n){
            console.log(-1);
            return;
        }
    }


    console.log(answer.toString());



}

main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 43956
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
typedef long long ll;
typedef unsigned long long int ull;
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define ff first
#define ss second
#define pb push_back
#define Inf  1e17
#define inf -1e18
#define mod 1000000007
using vll = vector<ll>; 
using vvll = vector<vector<ll>>;
using mll = map<ll,ll>;
using umll = unordered_map<ll,ll>;
using sll = set<ll>;
using msll = multiset<ll>;
using pll = pair<ll,ll>;
 
ll power(ll A,ll B) {
    ll RES = 1;
    A = A%mod;
    while (B > 0)
    {
        if (B & 1)
            RES = (RES*A)%mod;
        B = B>>1;
        A = (A*A)%mod;
    }
  return RES;
}


long long fact[101];
void pre(){
		fact[0] = 1;
		for(int i = 1 ;i <= 100;i ++){
			fact[i] = (fact[i - 1]*i)%mod;
		}
}
vector<vector<vector<long>>>DP(105,vector<vector<long>>(105,vector<long>(500,-1)));
int arr[101];
int N , K;
int Now;
long Rec(int Current, int  Left ,int Xor){
		
		if(Current==(N+1)){
			  return (Left == 0&&Xor==K);
		}
		if(Left==0){
			return Xor==K;
		}
		if(DP[Current][Left][Xor]!=-1)
					return DP[Current][Left][Xor];
		long ans = 0;
			ans = ans + Rec(Current+1,Left-1,Xor^arr[Current]);
		ans = ans + Rec(Current+1,Left,Xor);
		if(ans>=mod)	
				ans-=mod;
		return DP[Current][Left][Xor] = ans;
}

void testcases(int C){
		cin >> N >> K;
		long long ans = 0;
		for(int i = 1 ;i <= N ; i ++){
			cin >> arr[i];
		}
		for(int i = 1 ;i <= N; i ++){
			Now = i;
			ans = (ans%mod + (Rec(1,i,0)%mod*fact[i]%mod)%mod)%mod;
		}
		cout  << ans << "\n";
}

int main(){
	pre();
  //sieve();
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
    ll t;
    //cin >> t;
    t = 1;
    ll Case = 1;
    while(t--)
    {
      testcases(Case++);
    }
}



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

int helper(int *ar,int n,int k)
{
    int *dp = new int[n];
    dp[0] = 0;
    dp[1] = abs(ar[1] - ar[0]);
    for(int i = 2;i<n;i++)
    {
        int mini = INT_MAX;
        for(int j = i-1;j>=0 && j >= i-k;j--)
        {
            mini = min(mini,abs(ar[i] - ar[j]) + dp[j]);
        }
        dp[i] = mini;//(abs(ar[i] - ar[i-1]) + dp[i-1],abs(ar[i] - ar[i-2]) + dp[i-2]);
    }
    
    return dp[n-1];
}

int main()
{
  int n,k;
  cin>>n>>k;
  int *ar = new int[n];
  for(int i = 0;i<n;i++)
  {
      cin>>ar[i];
  }
  cout<<helper(ar,n,k)<<endl;
}

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

int main() {
    int n; cin >> n;
    int adj_mat[n][n];

    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            adj_mat[i][j] = 0;
        }
    }

    for (int i = 0; i < n; i++) {
        int m, l; cin >> m >> l;
        for (int j = 0; j < l; j++) {
            int k; cin >> k;
            adj_mat[i][k-1] = 1;
        }
    }

    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            if (j) cout << " ";
            cout << adj_mat[i][j];
        }
        cout << endl;
    }

    return 0;
}


Measured memory_bytes: 3084
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int N = 2e5 + 5, mod = 1e9 + 7;


int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int n;
    cin >> n;
    cout << (1000 - n % 1000)%1000;

    return 0;
}


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

int main(){

    int a,b;
    cin>>a>>b;
    if (a<b){
        cout<<"a < b"<<endl;
    }else if(a>b){
        cout<<"a > b"<<endl;
    }else{
        cout<<"a == b"<<endl;
    }

    return 0;
}


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

/*
int main(void)
{
	int n;
	vector<int> vecPrime;

	while (cin >> n)
	{
		// vectorの破棄
		vecPrime.clear();

		// nが2以上の時,2のみ追加
		if (n >= 2)
		{
			vecPrime.push_back(2);
		}

		// 奇数のみ探索
		for (int i = 3; i <= n; i += 2)
		{
			// 割り切れたらtrueにする
			bool flagPrime = false;

			// 奇数しかループさせないため、j = 1からでよい
			int size = vecPrime.size();
			for (int j = 1; j < size && vecPrime[j] < sqrt((double)i); j++)
			{
				// 割り切れたら素数でない
				if (i % vecPrime[j] == 0)
				{
					flagPrime = true;
					break;
				}
			}
			// すべて割り切れなかった場合
			if (flagPrime == false)
			{
				vecPrime.push_back(i);
			}
		}

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

	return 0;
}
*/


#define SIZE 100000

int main(void)
{
	int n;
	int prime[SIZE] = {0};

	while (cin >> n)
	{
		int ans = 0;

		// nが2以上の時,2のみ追加
		if (n >= 2)
		{
			prime[0] = 2;
			ans++;
		}

		// 奇数のみ探索
		for (int i = 3; i <= n; i += 2)
		{
			// 割り切れたらtrueにする
			bool flagPrime = false;

			// 奇数しかループさせないため、j = 1からでよい(sqrtの部分が < ではwrongAnswer)
			for (int j = 1; j < ans && prime[j] <= sqrt((double)i); j++)
			{
				// 割り切れたら素数でない
				if (i % prime[j] == 0)
				{
					flagPrime = true;
					break;
				}
			}
			// すべて割り切れなかった場合
			if (flagPrime == false)
			{
				prime[ans] = i;
				ans++;
			}
		}

		cout << ans << endl;
	}

	return 0;
}

Measured memory_bytes: 1556
#include<set>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<iostream>
using namespace std;
int a[100010],fa[100010],N,M,x,y,cnt,now[100010],size[100010],p;
long long ans;
int read()
{
	static int x;
	static char ch;
	x = 0;
	for(ch=getchar();ch>'9'||ch<'0';ch=getchar());
	for(;ch>='0'&&ch<='9';ch=getchar()) x = x * 10 + ch - '0';
	return x;
}
int find(int x)
{
	return x == fa[x] ? x : fa[x] = find(fa[x]);
}
bool cmp(int x,int y)
{
	return a[x] < a[y];
}
void solve()
{
	for (int i = 1;i<=N;++i) now[i] = i,size[fa[i]]++;
	sort(now+1,now+1+N,cmp); 
	p = N;
	cnt*=2;
	for (int i = N;i>=1 && p>cnt;--i) if (size[fa[now[i]]] > 1) ans-=a[now[i]],size[fa[now[i]]]--,p--;
	cout << ans << endl;
}
int main()
{
	N = read();M = read();
	for (int i = 1;i<=N;++i) a[i] = read(),fa[i]=i,ans+=a[i];
	for (int i = 1;i<=M;++i) 
	{
		x = read() + 1;y = read() + 1;
		fa[find(x)] = find(y);
	}
	for (int i = 1;i<=N;++i) if(find(i)==i) ++cnt;
	cnt--;
	if (cnt>(N>>1)) puts("Impossible");
	else if (!cnt) puts("0");
	else solve();
	return 0;
}

Measured memory_bytes: 1792
#include <stdio.h>

int main() {
  int n;
  scanf("%d",&n);
  int i;
  int a1[n],a2[n];
  for(i=0;i<n;i++) {
    scanf("%d",&a1[i]);
  }
  int sum = a1[0];
  for(i=0;i<n;i++) {
    scanf("%d",&a2[i]);
    sum += a2[i];
  }
  int summax = sum;
  for (i=1;i<n;i++) {
    sum = sum - a2[i-1] + a1[i];
    if(sum > summax) {
      summax = sum;
    }
  }
  printf("%d\n",summax);
  return 0;
}


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

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int H, W, K;
    cin >> H >> W >> K;
    K--;
    ll MOD = 1e9 + 7;
    vector<vector<ll>> dp(H + 1, vector<ll>(W));
    vector<ll> toorisuuByWide = {1, 2, 3, 5, 8, 13, 21, 34}; //各幅で可能な線の引き方の通り数。フィボナッチ数列になるらしい
    dp.at(0).at(0) = 1;
    for (int i = 0; i < H; i++)
    {
        for (int j = 0; j < W; j++)
        {
            if (j > 0)
            {
                dp.at(i + 1).at(j) += dp.at(i).at(j - 1) * toorisuuByWide.at(max(0, j - 2)) * toorisuuByWide.at(max(0, W - j - 2));
            }
            dp.at(i + 1).at(j) += dp.at(i).at(j) * toorisuuByWide.at(max(0, j - 1)) * toorisuuByWide.at(max(0, W - j - 2));
            if (j < W - 1)
            {
                dp.at(i + 1).at(j) += dp.at(i).at(j + 1) * toorisuuByWide.at(max(0, j - 1)) * toorisuuByWide.at(max(0, W - j - 3));
            }
            dp.at(i + 1).at(j) %= MOD;
        }
    }
    cout << dp.at(H).at(K) << endl;
    return 0;
}


Measured memory_bytes: 256
//	????°???????????????????
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

#define DEF_ELEM_MAX 1000
#define DEF_VMAX 10000

//  ????°?????????????
#ifndef min
#define min(a, b)            (((a) < (b)) ? (a) : (b))
#endif

int A[DEF_ELEM_MAX];
int B[DEF_ELEM_MAX];
int VD[DEF_ELEM_MAX];
int N;

/////////////////////////////////////////////////////////////////////////////////
//
/////////////////////////////////////////////////////////////////////////////////
int search(int x)
{
  int i;
  for ( i = 0 ; i < N ; i++ ) {
	  if ( A[i] == x ) {
		  break;
	  }
  }
  return i;
}

/////////////////////////////////////////////////////////////////////////////////
//
/////////////////////////////////////////////////////////////////////////////////
int int_sort( const void * a , const void * b )
{
	int p = *( int * )a;
	int q = *( int * )b;
  if( p < q ) {
    return -1;
  }  else if( p == q  ) {
    return 0;
  }
  return 1;
}

/////////////////////////////////////////////////////////////////////////////////
//
/////////////////////////////////////////////////////////////////////////////////
int sillysort( void )
{
	int s;
	int cost = 0;
	int i;
	int amin;
	int sum;
	int n;
	int x;

	// init
	s = B[0];
	// compute
	for ( i = 0 ; i < N ; i++ ) {
		x = i;
		n = sum = 0;
		amin = DEF_VMAX;
		while ( VD[x] == 0 ) {
			VD[x] = 1;
			n++;
			sum += A[x];
			amin = min(amin, A[x]);
			x = search(B[x]);
		}
		if ( n > 1 ) { 
			cost += min(sum+(n-2)*amin, sum+amin+(n+1)*s);
		}
	}
	return cost;
}
/////////////////////////////////////////////////////////////////////////////////
//
/////////////////////////////////////////////////////////////////////////////////
int main(void)
{
	int i;
	int ans;
//
	scanf("%d", &N);
	for ( i = 0 ; i < N ; i++ ) {
		scanf("%d", &A[i] );
		B[i] = A[i];
	}

	qsort(B, N , sizeof( int ), int_sort );

	ans = sillysort();

	printf("%d\n", ans);

	return 0;
}

Measured memory_bytes: 656
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <map>
#include <vector>
#include <set>
#include <utility>
#include <cstdio>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repp(i, n, m) for (int i = (int)(n); i < (int)(m); i++)
#define rrep(i, n, m) for (int i = n; i >= m; i--)
typedef long long LL;
template <class T>
bool contain(const std::string &s, const T &v)
{
    return s.find(v) != std::string::npos;
}

int main()
{
    int N,a,b,c;
    int dpA[100005]={},dpB[100005]={},dpC[100005]={};
    cin>>N;
    repp(i,1,N+1){
        cin>>a>>b>>c;
        dpA[i] = max(dpB[i-1],dpC[i-1])+a;
        dpB[i] = max(dpA[i-1],dpC[i-1])+b;
        dpC[i] = max(dpA[i-1],dpB[i-1])+c;
    }
    cout<<max(dpA[N],max(dpB[N],dpC[N]))<<endl;
}

Measured memory_bytes: 1408
#if 1
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <stack>
#include <array>
#include <deque>
#include <algorithm>
#include <utility>
#include <cstdint>
#include <functional>
#include <iomanip>
#include <numeric>
#include <assert.h>
#include <bitset>
#include <list>
#include <cmath>

auto& in = std::cin;
auto& out = std::cout;
#define all_range(C) std::begin(C), std::end(C)
const double PI = 3.141592653589793238462643383279502884197169399375105820974944;

std::string S;
int maxmax[1000000];
int main()
{
	using std::endl;
	in.sync_with_stdio(false);
	out.sync_with_stdio(false);
	in.tie(nullptr);
	out.tie(nullptr);

	in >> S;

	int now = 0;
	for (size_t i = 0; i < S.size(); i++)
	{
		if (S[i] == '<') {
			++now;
			maxmax[i + 1] = std::max(maxmax[i + 1], now);
		}
		else {
			now = 0;
		}
	}
	now = 0;
	for (int i = S.size()-1; i >= 0; --i)
	{
		if (S[i] == '>') {
			++now;
			maxmax[i] = std::max(maxmax[i], now);
		}
		else {
			now = 0;
		}
	}


	out << std::accumulate(all_range(maxmax), (int64_t)0) << endl;;


	return 0;
}
#endif


Measured memory_bytes: 2808
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;

#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")

#define    boost        ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define    nl           "\n"
#define    ll           long long
#define    pb           push_back
#define    mpr          make_pair
#define    fr(i,a,n)    for(ll i=a;i<n;++i)
#define    fr0(i,n)     for(ll i=0;i<n;++i)
#define    pii          pair<int, int>
#define    FO           find_by_order
#define    OK           order_of_key
#define    mem(a)       memset(a,0,sizeof(a))
#define    ff           first
#define    ss           second


typedef tree <
int,
null_type,
less<int>,
rb_tree_tag,
tree_order_statistics_node_update >
set_t;


void fio()
{
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
}


template<typename T> void TIME(T start, T end)
{
#ifndef ONLINE_JUDGE
	double time_taken =  chrono::duration_cast<chrono::nanoseconds>(end - start).count();
	time_taken *= 1e-9;
	cout << "\nExecuted in: " << fixed
	     << time_taken << setprecision(9);
	cout << " sec";
#endif
}

///----------------------------- | FUNCTIONS | --------------------------------------///

/*
const int N = 2e5 + 5;

vector<int> adj[N];
bool visited[N];
//int val[N];
//int depth[N];
//int parent[N];

void dfs(int v)
{
	visited[v] = true;
	for (int u : adj[v])
	{
		if (!visited[u])
		{
			//parent[u] = v;
			//depth[u] = depth[v] + 1;
			dfs(u);
		}
	}
}
*/

// left shift << multiply by 2
// right shift >> divide by 2

///----------------------------- | START FROM HERE | --------------------------------------///

//#define int long long //change int main to int32_t main


void solve()
{
	int x; cin >> x;
	if (x >= 30) cout << "Yes\n";
	else cout << "No\n";

}





int main()
{
	auto start = chrono::high_resolution_clock::now();
	boost;
	fio();
	int t;
	t = 1;
	//cin >> t;
	while (t--) solve();
	auto end = chrono::high_resolution_clock::now();
	TIME(start, end);
	return 0;
}




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

int main(){
  int coin_1,coin_500;
  int sum;
  int change;
  
  cin >> sum;
  cin >> coin_1;
  
  change = (sum % 500);
  
  if (coin_1 >= change){
    cout << "Yes" << endl;
  }
  if (coin_1 < change){
    cout << "No" << endl;
  }
}



Measured memory_bytes: 256
import bisect,collections,copy,heapq,itertools,math,string
import sys
def S(): return sys.stdin.readline().rstrip()
def M(): return map(int,sys.stdin.readline().rstrip().split())
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LS(): return list(sys.stdin.readline().rstrip().split())
n = I()
ans = 'No'
cnt = 0
for i in range(n):
    a, b = M()
    if a == b:
        cnt += 1
        if cnt == 3:
            ans = 'Yes'
            break
    else:
        cnt = 0
print(ans)

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

int main() {
  int n; cin>>n;
  
  int a[n];
  int maxa=0;
  int mina=1000000;
  rep(i, n){
    cin>>a[i];
    if(maxa<a[i])maxa=a[i];
    if(mina>a[i])mina=a[i];
  }
  
  if(maxa-mina>=2){cout<<"No"<<endl;
                   return 0;}
  if(maxa==mina){if(n<2*maxa&&n!=maxa+1)cout<<"No"<<endl;
                 else cout<<"Yes"<<endl;
                 return 0;}
  
  int numu=0;
  int numg=0;
  rep(i, n){if(a[i]==maxa)numu++;
            else numg++;}
  
  if(maxa-numg-numu/2<=0 && maxa-numg-1>=0)cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
  
}


Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
#include <bitset>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <complex>
#include <string.h>
#include <numeric>
using namespace std;

//#define int long long
#define reps(i,s,n) for(int (i)=(s);(i)<(n);++(i))
#define rep(i,n) reps(i,0,n)
#define rept(i,n) rep(i,(n)+1)
#define repst(i,s,n) reps(i,s,(n)+1)
#define reprt(i,n,t) for(int (i)=(n);(i)>=(t);--(i))
#define repr(i,n) reprt(i,n,0)
#define each(itr,v) for(auto &(itr):(v))
#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define tmax(x,y,z) max(x,max(y,z))
#define tmin(x,y,z) min(x,min(y,z))
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define ln '\n'
#define bln(i,n) (((i)==(n)-1)?'\n':' ')
#define dbg(x) cout<<#x" = "<<(x)<<ln<<flush
#define dbga(x,n) {cout<<#x" : ";for(int (i)=0;i<(n);++i){cout<<((x)[i])<<(i==((n)-1)?'\n':' ')<<flush;}}
#define zero(a) memset(a,0,sizeof(a))
#define unq(a) sort(all(a)),a.erase(unique(all(a)),a.end())

//typedef complex<double> P;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<string> vst;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<vector<int> > mat;

const ll inf = (ll)1e9+10;
const ll linf = (ll)1e18+10;
const ll mod = (ll)(1e9+7);
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};
const double eps = 1e-10;

ll mop(ll a,ll b,ll m=mod) {ll r=1;a%=m;for(;b;b>>=1){if(b&1)r=r*a%m;a=a*a%m;}return r;}
ll gcd(ll a,ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b) {return a*b/gcd(a,b);}
bool ool(int x,int y,int h,int w) {return((x<0)||(h<=x)||(y<0)||(w<=y));}
bool deq(double a,double b) {return abs(a-b)<eps;}

struct oreno_initializer {
	oreno_initializer() {
		cin.tie(0);
		ios::sync_with_stdio(0);
	}
} oreno_initializer;



int n, k, res;
vector<int> a(26);
string s;

signed main() {
	cin >> n >> k;
	rep(i,n) {
		cin >> s;
		a[s[0]-'A']++;
	}
	while (1) {
		sort(a.rbegin(), a.rend());
		int t = k;
		rep(i,26) if (t && a[i]) t--, a[i]--;
		if (t==0) res++;
		else break;
	}
	cout << res << endl;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
 
int main()
{
	int N;
	int M;
	int maxCoinsTmp = 0;
	int maxCoins;
	string tmp;

	cin >> N;
	string s[N];
	for (int i = 0; i < N; i++) { cin >> s[i]; }

	cin >> M;
	string t[M];
	for (int k = 0; k < M; k++) { cin >> t[k]; }
	

	// s[]を検索
	for (int i = 0; i < N; i++) {

		tmp = s[i];
		maxCoinsTmp = 1;

		// i以外を検索
		for (int j = 0; j < N; j++) {
			
			if (j != i) {
				if (s[j] == tmp) {
					maxCoinsTmp++;
				}
			}
		
		}
		
		// t[]を検索
		for (int k = 0; k < M; k++) {
			if (t[k] == tmp) {
				maxCoinsTmp--;
			}
		}

		if (maxCoins < maxCoinsTmp) {
			maxCoins = maxCoinsTmp;
		}

	}

	cout << max(0,maxCoins) << endl;

	return 0;
}

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

int main(){
  string s,t;
  int ans=0;
  cin >> s >> t;
  rep(i,s.size()){
    if(s.at(i)!=t.at(i)){
      ans++;
    }
  }
  cout << ans << endl;
}

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

signed main() {
  int K, S;
  cin >> K >> S;
  
  bool san = false;
  int ans = 0;
  for( int x = 0; x <= K; x++ ){
    for( int y = 0; y <= K; y++ ){
      if( S-x-y >= 0 && S-x-y <= K ){
        int z = S-x-y;
        ans++;
        if( san == false && x == y && y == z ) san = true;
        else if( san == true && x == y && y == z ) ans--;
        //cout << x << " " << y << " " << z << endl;
      }
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<queue>
#include<vector>
using namespace std;
int head[100];
int cnt;
int vist[10];
vector<int>vec[10];
int n,m;
void dfs(int x,int sum)
{
	if(sum==n)
	{
		cnt++;
		return;
	}
	vist[x]=1;
	for(int i=0;i<vec[x].size();i++)
	{
		if(!vist[vec[x].at(i)])
		{
			vist[vec[x].at(i)]=1;
			dfs(vec[x].at(i),sum+1);
			vist[vec[x].at(i)]=0;
		}
	}
}
int main(){
	while(scanf("%d %d",&n,&m)==2)
	{
		cnt=0;
		memset(vist,0,sizeof(vist));
		for(int i=1;i<=n;i++)
		vec[i].clear();
		for(int i=0;i<m;i++)
		{
			int a,b;
			scanf("%d %d",&a,&b);
			vec[a].push_back(b);
			vec[b].push_back(a);
		}
		dfs(1,1);
		printf("%d\n",cnt);
	}
	return 0;
} 

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define x first
#define y second
using namespace std;

using pii = pair<int, int>;

struct Pack {
	int x, y, cost; };

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

const int N = 805;


int dist[N][N];
char mx[N][N];
bool f[N][N];

int n, m, k, sx, sy, ant;


static bool ok(pii nod) {
	return (1 <= nod.x && nod.x <= n) && (1 <= nod.y && nod.y <= m); }

static void bfs() {
	deque<pii> dq;
	pii u, v;

	dist[sx][sy] = 1;
	dq.push_back({sx, sy});

	while (!dq.empty()) {
		u = dq.front(), dq.pop_front();

		if (dist[v.x][v.y] <= k)
		for (int dir = 0; dir < 4; ++dir) {
			v.x = u.x + dx[dir];
			v.y = u.y + dy[dir];

			if (!ok(v) || dist[v.x][v.y] || mx[v.x][v.y] == '#')
				continue;

			f[v.x][v.y] = 1;
			dist[v.x][v.y] = dist[u.x][u.y] + 1;
			dq.push_back(v); } } }


int main() {
#ifdef HOME
	freopen("agc14c.in", "r", stdin);
	freopen("agc14c.out", "w", stdout);
#endif
	ios::sync_with_stdio(false);
	cin.tie(0), cout.tie(0);

	cin >> n >> m >> k;
	for (int i = 1; i <= n; ++i) {
		cin >> (mx[i] + 1);
		for (int j = 1; j <= m; ++j) if (mx[i][j] == 'S')
			sx = i, sy = j; }

	if (sx == 1 || sx == n || sy == 1 || sy == m)
		ant = 0;
	else
		ant = 2e9;

	bfs();

	for (int i = 1; i <= n; ++i)
	for (int j = 1; j <= m; ++j) if (dist[i][j]) {
		ant = min(ant, (min(i - 1, n - i) + k - 1) / k + 1);
		ant = min(ant, (min(j - 1, m - j) + k - 1) / k + 1); }

	cout << ant << endl;

	return 0; }


Measured memory_bytes: 4096
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
using ll = long long;
ll gcd(ll a,ll b){return b==0?a:gcd(b,a%b);}
signed main(){
  
  ll n,m;
  cin>>n>>m;
  vector<ll> k(m),p(m);
  vector<vector<ll>> s(m);
  rep(i,m){
    cin>>k[i];
    s[i].resize(k[i]);
    rep(j,k[i]){
      cin>>s[i][j];
      s[i][j]--;
    }
  }
  rep(i,m)cin>>p[i];

  ll ans=0;
  for(ll bit=0;bit<(1<<n);++bit){
    vector<ll> res(m,0);
    for(ll show=0;show<n;++show){
      if(bit&(1<<show)){
        rep(i,m){
          rep(j,k[i])if(s[i][j]==show)res[i]++;
        }
      }
    }
    for(auto&elm:res)elm%=2;
    //for(auto elm:res)cout<<elm<<" ";cout<<endl;
    if(res==p)ans++;
  }
  cout<<ans<<endl;

  return 0;
}

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

int main(){
    int a[3];
    int n;
    cin >> n;
    for (int i = 0; i < n; i++){
	cin >> a[0] >> a[1] >> a[2];
	sort(a, a + 3);
	if (a[0] * a[0] + a[1] * a[1] == a[2] * a[2]) puts("YES");
	else puts("NO");
    }
    return 0;
}

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

int main()
{
    int k;
    cin>>k;

    string s;
    cin>>s;

    int len = s.length();

    if(len <= k)
        cout<<s<<endl;
    else{
        string str = "";
        for(int i=0; i<k; i++){
            str = str + s[i];
        }

        str = str + "...";
        cout<<str<<endl;

    }

    return 0;
}


Measured memory_bytes: 3632
#include<iostream>
#include<fstream>
#include<cstdio>
#include<vector>
#include<string>
#include<cstring>
#include<queue>
#include<map>
#include<set>
#include<algorithm>
#include<iomanip>
#include<bitset>
using namespace std;

const int MOD = 1000000007;

int n, ve[100][100], ver[10000], nrc, d[100][3][3];
char a[2][100];

int main() {
   // freopen("ttt", "r", stdin);

cin >> n;

if(n == 1) {
    cout << 3;
    return 0;
}
    cin >> a[0];
    cin >> a[1];
int i, j;
    for(i = 0; i < n; ++i) {
        if(!ver[a[0][i]])
            ver[a[0][i]] = ++nrc;
        if(!ver[a[1][i]])
            ver[a[1][i]] = ++nrc;
    }

    for(i = 0; i < n; ++i) {
        int s1 = ver[a[0][i]], s2 = ver[a[0][i + 1]], s3 = ver[a[1][i]], s4 = ver[a[1][i + 1]];

        if(i + 1 != n && s1 != s2) {
            ve[s1][s2] = ve[s2][s1] = 1;
        }
        if(s1 != s3)
            ve[s1][s3] = ve[s3][s1] = 1;
        if(i + 1 != n && s3 != s4)
            ve[s3][s4] = ve[s4][s3] = 1;
    }

    for(i = 0; i < 3; ++i)
        for(j = 0; j < 3; ++j)
            if(i != j) d[2][i][j] = 1;
int k, l;

    for(i = 3; i <= n; ++i) {

        for(j = 0; j < 3; ++j)
            for(k = 0; k < 3; ++k) {
                for(l = 0; l < 3; ++l) {

                    int ver = 1;
                    if(j == k && ve[i - 1][i - 2])
                        ver = 0;
                    if(k == l && ve[i][i - 1])
                        ver = 0;
                    if(j == l && ve[i - 2][i])
                        ver = 0;

                    if(ver)
                        d[i][k][l] = (d[i][k][l] + d[i - 1][j][k]) % MOD;
                }
            }
    }

    int r = 0;

    for(i = 0; i < 3; ++i)
        for(j = 0; j < 3; ++j)
            r = (r + d[n][i][j]) % MOD;

    cout << r;

    return 0;
}


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

#define MP make_pair
#define PB push_back
#define ALL(x)      (x).begin(),(x).end()
#define REP(i,n)    for(int i=0;i<(n);i++)
#define REP1(i,n)   for(int i=1;i<(n);i++)
#define REP2(i,d,n) for(int i=(d);i<(n);i++)
#define RREP(i,n)   for(int i=(n);i>=0;i--)
#define CLR(a)      memset((a),0,sizeof(a))
#define MCLR(a)     memset((a),-1,sizeof(a))
#define RANGE(x,y,maxX,maxY) (0 <= (x) && 0 <= (y) && (x) < (maxX) && (y) < (maxY))

typedef long long LL;
typedef unsigned long long ULL;
typedef vector<int> VI;
typedef vector<VI > VVI;
typedef vector<string> VS;
typedef vector<LL> VLL;
typedef pair<int,int> PII;

const int INF = 0x3f3f3f3f;
const LL INFL = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-9;

const int DX[]={1,0,-1,0},DY[]={0,-1,0,1};


void solve(long long N, long long K, std::vector<long long> x, std::vector<long long> y){
    vector<pair<LL, LL> > points;
    REP(i, N) points.PB({x[i], y[i]});

    sort(ALL(points));
    sort(ALL(x));
    sort(ALL(y));

    LL ans = INFL;
    REP(lx, N) REP2(rx, lx+1, N) REP(uy, N) REP(dy, N) {
        LL res = (x[rx]-x[lx]) * (y[dy]-y[uy]);
        if(ans <= res) continue;

        LL cnt = 0;
        REP(i, N) {
            if(x[lx] <= points[i].first && points[i].first <= x[rx] && y[uy] <= points[i].second && points[i].second <= y[dy]) {
                cnt++;
            }
        }

        if(K <= cnt) ans = min(ans, res);
    }

    cout << ans << endl;
}

int main(){
    long long N;
    scanf("%lld",&N);
    long long K;
    scanf("%lld",&K);
    std::vector<long long> x(N);
    std::vector<long long> y(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&x[i]);
        scanf("%lld",&y[i]);
    }
    solve(N, K, std::move(x), std::move(y));
    return 0;
}


Measured memory_bytes: 384
// C++ code to find number of distinct numbers 
// in a subarray 
#include<bits/stdc++.h> 
using namespace std; 

const int MAX = 5000000; 

// structure to store queries 
struct Query 
{ 
	int l, r, idx; 
}; 

// cmp function to sort queries according to r 
bool cmp(Query x, Query y) 
{ 
	return x.r < y.r; 
} 

// updating the bit array 
void update(int idx, int val, int bit[], int n) 
{ 
	for (; idx <= n; idx += idx&-idx) 
		bit[idx] += val; 
} 

// querying the bit array 
int query(int idx, int bit[], int n) 
{ 
	int sum = 0; 
	for (; idx>0; idx-=idx&-idx) 
		sum += bit[idx]; 
	return sum; 
} 

void answeringQueries(int arr[], int n, Query queries[], int q) 
{ 
	// initialising bit array 
	int bit[n+1]; 
	memset(bit, 0, sizeof(bit)); 

	// holds the rightmost index of any number 
	// as numbers of a[i] are less than or equal to 10^6 
	int last_visit[MAX]; 
	memset(last_visit, -1, sizeof(last_visit)); 

	// answer for each query 
	int ans[q]; 
	int query_counter = 0; 
	for (int i=0; i<n; i++) 
	{ 
		// If last visit is not -1 update -1 at the 
		// idx equal to last_visit[arr[i]] 
		if (last_visit[arr[i]] !=-1) 
			update (last_visit[arr[i]] + 1, -1, bit, n); 

		// Setting last_visit[arr[i]] as i and updating 
		// the bit array accordingly 
		last_visit[arr[i]] = i; 
		update(i + 1, 1, bit, n); 

		// If i is equal to r of any query store answer 
		// for that query in ans[] 
		while (query_counter < q && queries[query_counter].r == i) 
		{ 
			ans[queries[query_counter].idx] = 
					query(queries[query_counter].r + 1, bit, n)- 
					query(queries[query_counter].l, bit, n); 
			query_counter++; 
		} 
	} 

	// print answer for each query 
	for (int i=0; i<q; i++) 
		cout << ans[i] << endl; 
} 

// driver code 
int main() 
{ 
  	int n , q ;
  	cin >> n >> q ;
  	int a[n];
  	for(int i = 0 ; i < n ; i++) cin >> a[i];
	Query queries[q];
  	for(int i = 0 ; i < q ; i++) cin >> queries[i].l >> queries[i].r , queries[i].idx = i , queries[i].l--, queries[i].r--;
	sort(queries, queries+q, cmp); 
	answeringQueries(a, n, queries, q); 
	return 0; 
} 


Measured memory_bytes: 35024
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000
#define int long long

signed main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    int a[100010];
    int M = 0;
    rep(i, n) {
        cin >> a[i];
        a[i] *= 2;
    }
    sort(a, a + n, greater<int>());
    int ans1 = a[0];
    int ans2 = a[1];
    for(int i = 1; i < n; i++) {
        //cout << abs(ans1 / 2 - a[i]) << " " <<  ans2 << endl;
        if (abs(ans1 / 2 - a[i]) < abs(ans1 / 2 - ans2)) {
            ans2 = a[i];
        }
    }
    cout << ans1/2 << " " << ans2/2 << endl;

    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#include <string>
using namespace std;
int main(){
	int a,b;
	scanf("%d %d",&a,&b);
	if(a - 2 * b >= 0){
		printf("%d",a - 2*b);
	}else{
		printf("%d",0);
	}
}

Measured memory_bytes: 3828
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a, b, c, d;
  cin >> a >> b;
  c = (a + b) / 2;
  d = (a + b) % 2;
  if (d == 0){
    cout << c << endl;
  }
  else if (d == 1){
    cout << c + 1 << endl;
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include<algorithm>
#include<iomanip>
#include<queue>
#include<map>
#include<bitset>
#include<math.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define REP(i,m,n) for(int i=m;i<(int)(n);i++)
typedef pair<int,int> pint;
typedef long long ll;
const int inf   = 1e9+7;
const ll  longinf = 1LL<<60;
const ll mod=998244353;
int dx[4]={1,0,-1,0}, dy[4]={0,1,0,-1};

int main(){
  int N;
  cin >> N;
  int a[N], b[N], c[N];
  ll ans = 0;
  rep(i, N){
    cin >> a[i];
  }
   rep(i, N){
    cin >> b[i];
  }
   rep(i, N){
    cin >> c[i];
    c[i] = -c[i];
  }
  sort(a, a+N);
  sort(b, b+N);
  sort(c, c+N);
  rep(i, N){
    int x = lower_bound(a, a+N, b[i])-a;
    int y = lower_bound(c, c+N, -b[i])-c;
    ans += (ll)x*y;
}
  cout << ans << endl; 
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
bool data[4][10010];
int dp[10010][16];
int main(){
	int h, n;
	cin >> h >> n;
	for(int i = 0; i < 4; i++){
		for(int j = 0; j < 10010; j++) data[i][j] = true;
	}
	for(int i = 0; i < 10010; i++){
		for(int j = 0; j < 16; j++) dp[i][j] = -1;
	}
	for(int i = 0; i < n; i++){
		int x, y;
		cin >> x >> y;
		data[x][y] = false;
	}
	int s = 0;
	if(data[0][0]) s = s | 8;
	if(data[1][0]) s = s | 4;
	if(data[2][0]) s = s | 2;
	if(data[3][0]) s = s | 1;
	dp[0][s] = 0;
	for(int i = 0; i < h-1; i++){
		for(int j = 0; j < 16; j++){
			if(dp[i][j] == -1) continue;
			int st = j;
			// cout << data[0][i+1] <<  data[1][i+1] <<  data[2][i+1] <<  data[3][i+1] << endl;	
			if(data[0][i+1]) st = st | 128;
			if(data[1][i+1]) st = st | 64;
			if(data[2][i+1]) st = st | 32;
			if(data[3][i+1]) st = st | 16;
			// cout << i << " " << j << " " << st << endl;
			//none
			{
				int st2 = st >> 4;
				// cout << "none" << endl;
				// cout << j << " -> " << st2 << endl;
				dp[i+1][st2] = max(dp[i+1][st2], dp[i][j]);
			}
			//left
			if((st & 204) == 204){
				int st2 = st >> 4;
				st2 = st2 & 3;
				// cout << "left" << endl;
				// cout << j << " -> " << st2 << endl;
				dp[i+1][st2] = max(dp[i+1][st2], dp[i][j] + 1);
			}
			//middle
			if((st & 102) == 102){
				int st2 = st >> 4;
				st2 = st2 & 9;
				// cout << "middle" << endl;
				// cout << j << " -> " << st2 << endl;
				dp[i+1][st2] = max(dp[i+1][st2], dp[i][j] + 1);
			}
			//right
			if((st & 51) == 51){
				int st2 = st >> 4;
				st2 = st2 & 12;
				// cout << "right" << endl;
				// cout << j << " -> " << st2 << endl;
				dp[i+1][st2] = max(dp[i+1][st2], dp[i][j] + 1);
			}
			//left+right
			if((st & 255) == 255){
				// cout << "left and right" << endl;
				// cout << j << " -> " << 0<< endl;
				dp[i+1][0] = max(dp[i+1][0], dp[i][j] + 2);
			}
			// cout << "----" << endl << endl;
		}
	}
	int ans = 0;
	for(int i = 0; i < 16; i++){
		// cout << dp[h-1][i] << " ";
		ans = max(ans, dp[h-1][i]);
	}
	cout << ans << endl;
}


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

int main() {
	
	int n;
	cin >> n;
	vector<pair<int, int>> ba(n);
	rep(i, n){
		cin >> ba[i].second >> ba[i].first;
	}
	sort(ba.begin(), ba.end());
	
	int t = 0;
	for(int i=0; i<n; i++){
		t += ba[i].second;
		if(t > ba[i].first){
			puts("No");
			return 0;
		}
	}
	 
	puts("Yes");
	return 0;
}

Measured memory_bytes: 1792
import sys
n, k = map(int,input().split())
a = list(map(int,input().split()))
t = [0]*(n + 1) # 1-indexed
vis = []

mod_max = n
rep_start = n
cur = 1
flag = 0
for i in range(0,k + 1):
    if t[cur] > 0:
        mod_max = i
        rep_start = vis.index(cur)
        flag = 1
        break
    t[cur] += 1
    vis.append(cur)
    cur = a[cur - 1]
if flag == 0:
    print(vis[-1])
    sys.exit()
mod = mod_max - rep_start
vis_mod = vis[mod_max - mod:]
# print(mod_max,mod)
# print(rep_start)
# print(vis, vis_mod)
# print(mod, len(vis_mod))
print(vis_mod[(k - (mod_max - mod))%mod])

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


int main() {
    int N; cin >> N;
    vector<int> T(N);
    for (int i = 0; i < N; ++i) cin >> T[i];

    int M; cin >> M;
    vector<vector<int>> PX(M, vector<int>(2, 0));
    for (int i = 0; i < M; ++i) {
        for (int j = 0; j < 2; ++j) {
            cin >> PX[i][j];
        }
    }

    for (int i = 0; i < M; ++i) {
        vector<int> tmp(N);
        copy(T.begin(), T.end(), tmp.begin());
        tmp[PX[i][0] - 1] = PX[i][1];
        cout << accumulate(tmp.begin(), tmp.end(),0) << endl;
    }
    return 0;
}

Measured memory_bytes: 256
flag = "ok"
list_A = [i for i in range(6)]
for i in range(6):
  list_A[i] = int(input())
for j in range(5):
  for l in range(5):
    if (list_A[j]-list_A[l]) > list_A[5]:
      flag = "ng"
if flag == "ok":
  print("Yay!")
else:
  print(":(")

Measured memory_bytes: 3060
mod = 10 ** 9 + 7
n = gets.to_i

h = Array.new(60,0)

gets.split.each do |e|
    e = e.to_i
    60.times {|i| h[i] += e[i]}
end

ans = 0
h.each_with_index do |v, i|
    ans = (ans + v * (n - v) * (1 << i % mod)) % mod
end

puts ans

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

const long long INF=1LL<<60;
const int N_MAX=100000;
ll dp[101000];

int main() {
    int N,K;
    int h[N_MAX];
    cin>>N>>K;
    rep(i,N)    cin>>h[i];

    for(int i=0;i<101000;i++) {
        dp[i]=INF;
    }

    dp[0]=0;


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

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

 return 0;
}

Measured memory_bytes: 1408
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<string>
#include<math.h>
#include<vector>
#include<iomanip>
using namespace std;

int main(void)
{
    bool judge = false;
    int n;
    cin >> n;
    for(int i = 0;i <= n / 4;i++)
    {
        for(int j = 0;j <= n / 7;j++)
        {
            if(i * 4 + j * 7 == n){judge = true;}
        }
    }
    if(judge){cout << "Yes" << endl;}
    else{cout << "No" << endl;}
    return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define IOS ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define MOD 1000000007
#define MOD2 998244353
#define pb emplace_back
#define mp make_pair
#define all(v) v.begin(),v.end()
#define sz(x) (ll)x.size()
#define F first
#define S second
#define FOR(i,a,b) for(ll i=a;i<=b;++i)
#define ROF(i,a,b) for(ll i=a;i>=b;--i)
#define trace(x) cerr<<#x<<": "<<x<<'\n';
typedef long long ll;
using namespace std;
using namespace __gnu_pbds;
#define T ll
#define ordered_set tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>

ll mexp(ll a, ll b, ll m){
    ll ans=1;
    a%=m;
    while(b){
        if(b&1) ans=ans*a%m;
        b>>=1;
        a=a*a%m;
    }
    return ans;
}

map<string,ll>f;

int main(){
    IOS
    int n;
    cin>>n;
    string s;
    FOR(i,1,n){
    	cin>>s;
    	sort(all(s));
    	f[s]++;
    }
    ll ans=0;
    for(auto i:f){
    	ans += i.S*(i.S-1)/2;
    }
    cout<<ans;

    return 0;
}

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

int main()
{
	int x,y;
	cin >> x >> y;
	if(x == 2){
		if(y == 2){
			cout << "Yes\n";
		}else{
			cout << "No\n";
		}
	}else if(x == 4 || x == 6 || x == 9 || x == 11){
		if(y == 4 || y == 6 || y == 9 || y == 11){
			cout << "Yes\n";
		}else{
			cout << "No\n";
		}
	}else{
		if(y == 1 || y == 3 || y == 5 || y == 7 || y == 8 || y == 10 || y == 12){
			cout << "Yes\n";
		}else{
			cout << "No\n";
		}
	}

	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
long long n,k;
cin>>n>>k;
set<long long>s;
for(long long i=1;i<=n;i++){
  s.insert(i);
}
for(long long i=0;i<k;i++){
  long long d;
  cin>>d;
  long long l;
  for(long long j=0;j<d;j++){
    cin>>l;
    s.erase(l);
  }
}
cout<<s.size()<<endl;
return 0;

}

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

//#define int long long
typedef long long ll;

typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = mod * mod;
const int INF_N = 1e+9;
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 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++)
#define all(v) (v).begin(),(v).end()
typedef pair<ll, ll> LP;
typedef long double ld;
typedef pair<ld, ld> LDP;
const ld eps = 1e-12;
const ld pi = acos(-1.0);
//typedef vector<vector<ll>> mat;
typedef vector<int> vec;

//繰り返し二乗法
ll mod_pow(ll a, ll n, ll m) {
	ll res = 1;
	while (n) {
		if (n & 1)res = res * a%m;
		a = a * a%m; n >>= 1;
	}
	return res;
}

struct modint {
	ll n;
	modint() :n(0) { ; }
	modint(ll m) :n(m) {
		if (n >= mod)n %= mod;
		else if (n < 0)n = (n%mod + mod) % mod;
	}
	operator int() { return n; }
};
bool operator==(modint a, modint b) { return a.n == b.n; }
modint operator+=(modint &a, modint b) { a.n += b.n; if (a.n >= mod)a.n -= mod; return a; }
modint operator-=(modint &a, modint b) { a.n -= b.n; if (a.n < 0)a.n += mod; return a; }
modint operator*=(modint &a, modint b) { a.n = ((ll)a.n*b.n) % mod; return a; }
modint operator+(modint a, modint b) { return a += b; }
modint operator-(modint a, modint b) { return a -= b; }
modint operator*(modint a, modint b) { return a *= b; }
modint operator^(modint a, int n) {
	if (n == 0)return modint(1);
	modint res = (a*a) ^ (n / 2);
	if (n % 2)res = res * a;
	return res;
}

//逆元(Eucledean algorithm)
ll inv(ll a, ll p) {
	return (a == 1 ? 1 : (1 - p * inv(p%a, a)) / a + p);
}
modint operator/(modint a, modint b) { return a * modint(inv(b, mod)); }

const int max_n = 1 << 18;
modint fact[max_n], factinv[max_n];
void init_f() {
	fact[0] = modint(1);
	for (int i = 0; i < max_n - 1; i++) {
		fact[i + 1] = fact[i] * modint(i + 1);
	}
	factinv[max_n - 1] = modint(1) / fact[max_n - 1];
	for (int i = max_n - 2; i >= 0; i--) {
		factinv[i] = factinv[i + 1] * modint(i + 1);
	}
}
modint comb(int a, int b) {
	if (a < 0 || b < 0 || a < b)return 0;
	return fact[a] * factinv[b] * factinv[a - b];
}
using mP = pair<modint, modint>;

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




void solve() {
    int N, K; cin >> N >> K;
    vec a(N+1, 0), b(N+1, N);
    b[N] = 0;
    rep(i, N) cin >> a[i];
    rep(i, K){
        vec s(N+1, 0);
        rep(j, N){
            int l = max(j-a[j], 0);
            int r = min(j+a[j]+1, N);
            s[l]++;
            s[r]--;
        }
        rep(j, N) s[j+1] += s[j];
        a = s;
        if(a == b){
            break;
        }
    }
    rep(i, N){
        cout << a[i];
        if(i != N-1) cout << " ";
        else cout << endl;
    }
}

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  //cout << fixed << setprecision(10);
  //init_f();
  //init();
  //int t; cin >> t; rep(i, t)solve();
  solve();
//   stop
    return 0;
}


Measured memory_bytes: 9800
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define pii pair<int,int>
#define fi first
#define se second
#define mp make_pair
#define poly vector<ll>
#define For(i,l,r) for(int i=(int)(l);i<=(int)(r);i++)
#define Rep(i,r,l) for(int i=(int)(r);i>=(int)(l);i--)
#define pb push_back
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 ll read(){
	ll x=0;char ch=gc();bool positive=1;
	for(;!isdigit(ch);ch=gc()) if(ch=='-') positive=0;
	for(;isdigit(ch);ch=gc()) x=x*10+ch-'0';
	return positive?x:-x;
}
inline void write(ll x){
	if(x<0){
		x=-x;putchar('-');
	}
	if(x>=10) write(x/10);
	putchar('0'+x%10);
}
inline void writeln(ll x){write(x);puts("");}
inline void writep(ll x){write(x);putchar(' ');}
inline ull rnd(){
	return ((ull)rand()<<30^rand())<<4|rand()%4;
}
const int N=1e5+5;
int sz[N];
poly v[N];
bool dfs(int u,int fa){
	sz[u]=1;int cnt=0;
	for(auto k:v[u]){
		if(k==fa) continue;
		if(dfs(k,u)) return 1;
		if(sz[k]){
			cnt++;sz[u]=0;
			if(cnt==2) return 1;
		}
	}
	return 0;
}
int main(){
	int n=read();
	For(i,1,n-1){
		int x=read(),y=read();
		v[x].pb(y);v[y].pb(x);
	}
	if(dfs(1,0)||sz[1]) puts("First");
	else puts("Second");
}

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

typedef long long ll;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define each(itr,c) for(__typeof(c.begin()) itr=c.begin(); itr!=c.end(); ++itr)
#define all(x) (x).begin(),(x).end()
#define mp make_pair
#define pb push_back
#define fi first
#define se second

typedef pair<int,int> pi;

int dp[5001][5001]={0};

int main()
{
    int n,m;
    cin >>n >>m;

    vector<int> x(n),y(n);
    vector<pi> p(n);

    //the number of points
    map<pi,int> s;

    rep(i,n)
    {
        scanf(" %d %d", &x[i], &y[i]);

        p[i]=pi(x[i],y[i]);
        if(s.find(p[i])==s.end()) s[p[i]]=1;
        else ++s[p[i]];
    }

    //eliminate same value
    sort(all(x));
    sort(all(y));
    x.erase( unique(all(x)), x.end());
    y.erase( unique(all(y)), y.end());

    int X=x.size();
    int Y=y.size();

    //make DPtable
    rep(i,n)
    {
        int idx=lower_bound(all(x),p[i].fi)-x.begin()+1;
        int idy=lower_bound(all(y),p[i].se)-y.begin()+1;
        ++dp[idy][idx];
    }
    /*
    for(int i=Y; i>=0; --i)
    {
        rep(j,X+1) printf(" %d", dp[i][j]);
        printf("\n");
    }
    */

    for(int i=1; i<=Y; ++i)for(int j=1; j<=X; ++j)
    {
        dp[i][j]+=dp[i-1][j]+dp[i][j-1]-dp[i-1][j-1];
    }

    /*
    for(int i=Y; i>=0; --i)
    {
        rep(j,X+1) printf(" %d", dp[i][j]);
        printf("\n");
    }
    */

    rep(Q,m)
    {
        int x1,y1,x2,y2;
        scanf(" %d %d %d %d",&x1,&y1,&x2,&y2);

        int rx=upper_bound(all(x),x2)-x.begin();
        int ry=upper_bound(all(y),y2)-y.begin();
        int lx=lower_bound(all(x),x1)-x.begin();
        int ly=lower_bound(all(y),y1)-y.begin();

        //printf("%d,%d, %d,%d\n", lx,ly,rx,ry);
        //printf("%d - %d - %d + %d\n", dp[ry][rx],dp[ry][lx],dp[ly][rx],dp[ly][lx]);
        printf("%d\n", dp[ry][rx]-dp[ry][lx]-dp[ly][rx]+dp[ly][lx]);
    }

    return 0;
}

Measured memory_bytes: 101124