akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1e18;
#define rep(i, n) for (int i = 0; i < n; i++)
using Graph = vector<vector<int>>;
using pint = pair<int, int>;
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
int dxx[8] = {1, 1, 1, 0, 0, -1, -1, -1}, dyy[8] = {-1, 0, 1, -1, 1, -1, 0, 1};

int main() {
    int n;
    cin >> n;
    int a[n];
    rep (i, n) cin >> a[i];
    rep (i, n) {
        cout << "node " << i + 1 << ": key = " << a[i];
        if (i != 0) cout << ", parent key = " << a[(i - 1) / 2];
        if (i * 2 + 1 < n) {
            cout << ", left key = " << a[i * 2 + 1];
            if (i * 2 + 2 < n) cout << ", right key = " << a[i * 2 + 2];
        }
        cout << ", \n";
    }
}


Measured memory_bytes: 3100
//written by syzs
#include<bits/stdc++.h>
using namespace std;
const int N=5e5+25;
long long l,r,tott,tem[N],vol[N],n,L,sum;
struct dsa{
	long long v;
	double t;
} a[N];
int main(){
	cin>>n>>L;
	for(int i=1;i<=n;i++) scanf("%lld%lld",&tem[i],&vol[i]);
	for(int i=1;i<=n;i++){
		while(sum+vol[i]>L){//当水溢出时，优先把单调队列的前几份水排空 
	        int rea=min(sum+vol[i]-L,a[l].v);
	        a[l].v-=rea;
	        sum-=rea;
	        tott-=rea*a[l].t;
	        if(!a[l].v) l++;
		}
		sum+=vol[i];
		tott+=vol[i]*tem[i];
		a[++r].v=vol[i];
		a[r].t=tem[i];
		while(l<r&&a[r].t<a[r-1].t){//考虑混合 
			a[r-1].t=(a[r].t*a[r].v+a[r-1].t*a[r-1].v)/(a[r-1].v+a[r].v);
			a[r-1].v=a[r-1].v+a[r].v;
			r--;
		}
		printf("%.10lf\n",(double)tott/L);
	}
}

Measured memory_bytes: 26112
//s.empty() //emptyなら1を出力 入っていれば0を出力
/*//ABC018-B 部分的にreverseをかける解法
int main() {
  string s;
  cin >> s;
  int n;
  cin >> n;
  vector<int>a(n);
  vector<int>b(n);
  rep(i,n) cin>>a.at(i)>>b.at(i);
  rep(i,n)a.at(i)--;
  rep(i,n)b.at(i)--;
  string t;
  rep(i,n){
    t = s;
    for(int k=0;k<=b.at(i)-a.at(i);k++){
      t.at(a.at(i)+k) = s.at(b.at(i)-k);
    }
    s = t;
  }
  cout << s << endl;
}
*///ABC018-B
//  string s;
//  cin >> s;
//  cout << s.at(0) <<endl;
//  cout << s.at(0)-'0' <<endl;
//  Aが16？
//  cout << char(i+48) << endl;//なぜかaは47と得る時がある。+48で出力もaにできる。
//  cout << char(97) << endl;//アスキーコードでaを出力
// sort(b.begin(), b.end());//bという配列を小さい方からソート
// reverse(b.begin(), b.end());//bという配列をリターン
// 10桁でdouble出力するパターン１ 
// printf("%.10f\n", ma);
// 10桁でdouble出力するパターン２
//cout << fixed << setprecision(10);
//  cout << ma << endl;

/*01 02 03 12 13 23　と６回見ていくパターン 
for(int i=0;i<n-1;i++){
  for(int j=i+1;j<n;j++){
    }
  }
*///vector<vector<int>> data(3, vector<int>(4));//int型の2次元配列(3×4要素の)の宣言
//int64_t a;
//10のi乗pow(10, i);
/*string s; stringでの文字列を数字型に変える方法
  cin >> s;
  rep(i,s.size()-2) {
  int a= (s.at(i)-'0')*100 + (s.at(i+1)-'0')*10+ s.at(i+2) -'0';
    */
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main() {
  int n;
  cin >> n;
  if(n%10==3)cout<<"bon"<<endl;
  else if(n%10==0||n%10==1||n%10==6||n%10==8)cout<<"pon"<<endl;
  else cout<<"hon"<<endl;
}


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

class ACGTstrings {
  private:
  	std::string str;
  
  public:
  	ACGTstrings ( std::string _str) {
      str = _str;
    }
  
  	int Sol () {
      int max = 0, count = 0;
      for(int i=0; i<=str.size(); i++){
        if ( i == str.size() ) {
 			max = std::max(max, count);
            continue;
        }     
        if ( str[i] == 'A' || str[i] == 'C' || str[i] == 'G' || str[i] == 'T' ) {
          count++;
        }
        else {
          max = std::max(max, count);
          count = 0;
        }
      }
      return max;
    }
};


int main (void){
  std::string s; std::cin >> s;
  ACGTstrings s_ (s);
  std::cout << s_.Sol() << std::endl;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<stdlib.h>
#include<vector>
#include<algorithm>
#include<stdio.h>
#include<string>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>

#define rep(i,n) for(ll i = 0; i < (ll)n; i++)
#define swap(a,b) a^=b;b^=a;a^=b;
//#define for(i,a,b) for (ll i=(a);i<(ll)b; i++)
#define print(x) std::cout << x << std::endl;

using namespace std;

typedef long long ll;

template<class T, class U> std::string replace(std::string s, const T& target, const U& replacement, bool replace_first = 0, bool replace_empty = 0);
bool isContain(int value, int under, int top);
vector<int> range(int x);

int main(void) {
	//Program Start

	long N;
	string S;
	
	cin >> N;
	cin >> S;

	long W_Num = 0;
	long B_Num = 0;

	for (long i = 0; i < N; i++) 
		if (S[i] == '.') W_Num++;

	B_Num = N - W_Num;

	long min = W_Num;

	int BC = 0;
	int WC = 0;

	for (long i = 1; i <= N; i++) {
		//i:境界

		if (S[i - 1] == '#') {
			BC++; B_Num--;
		}
		else {
			WC++; W_Num--;
		}

		min = std::min(min, BC + W_Num);
	}
	
	cout << min << endl;

ProgramEndPointLabel:;

	//Program End
	system("pause");

	return 0;
}


vector<int> range(int y) {
	vector<int> result(y);
	for (int i = 0; i < y; i++)
		result[i] = i;
	return result;
}

bool isContain(int value, int under, int top) {
	if (under <= value && value <= top) return true;
	return false;
}

template<class T, class U> std::string replace(std::string s, const T& target, const U& replacement, bool replace_first, bool replace_empty) {
	using S = std::string;
	using C = std::string::value_type;
	using N = std::string::size_type;
	struct {
		auto len(const S& s) { return s.size(); }
		auto len(const C* p) { return std::char_traits<C>::length(p); }
		auto len(const C  c) { return 1; }
		auto sub(S* s, const S& t, N pos, N len) { s->replace(pos, len, t); }
		auto sub(S* s, const C* t, N pos, N len) { s->replace(pos, len, t); }
		auto sub(S* s, const C  t, N pos, N len) { s->replace(pos, len, 1, t); }
		auto ins(S* s, const S& t, N pos) { s->insert(pos, t); }
		auto ins(S* s, const C* t, N pos) { s->insert(pos, t); }
		auto ins(S* s, const C  t, N pos) { s->insert(pos, 1, t); }
	} util;

	N target_length = util.len(target);
	N replacement_length = util.len(replacement);
	if (target_length == 0) {
		if (!replace_empty || replacement_length == 0) return s;
		N n = s.size() + replacement_length * (1 + s.size());
		s.reserve(!replace_first ? n : s.size() + replacement_length);
		for (N i = 0; i < n; i += 1 + replacement_length) {
			util.ins(&s, replacement, i);
			if (replace_first) break;
		}
		return s;
	}

	N pos = 0;
	while ((pos = s.find(target, pos)) != std::string::npos) {
		util.sub(&s, replacement, pos, target_length);
		if (replace_first) return s;
		pos += replacement_length;
	}
	return s;
}


Measured memory_bytes: 764
#include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip> 
#include <complex> 
#include <string>
#include <vector> 
#include <list>
#include <deque> 
#include <stack> 
#include <queue> 
#include <set>
#include <map>
#include <bitset>
#include <functional>
#include <utility>
#include <algorithm> 
#include <numeric> 
#include <typeinfo> 
#include <cstdio>
#include <cstdlib> 
#include <cstring>
#include <cmath>
#include <climits> 
#include <ctime>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int main(void){
	string str;
	cin >> str;
	for(int i=0;i<str.size();i++){
		printf("%c",str[i]);
		if(i==3)printf(" ");
	}
	printf("\n");
	return 0;
}

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

int main() {
	int w, a, b, tmp;

	scanf("%d%d%d", &w, &a, &b);
	if (a > b)
		tmp = a, a = b, b = tmp;
	printf("%d\n", a + w >= b ? 0 : b - (a + w));
	return 0;
}


Measured memory_bytes: 128
#ifdef _MSC_VER
#include <__msvc_all_public_headers.hpp>
#undef min
#undef max
#else
#define NDEBUG
#include <bits/stdc++.h>
#endif

using namespace std;
using large = long long;

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

    auto b = vector<int>(m);
    auto a = vector<vector<int>>(n, vector<int>(m));
    for (auto& b_i : b)
        cin >> b_i;
    for (auto i = 0; i < n; ++i) {
        for (auto j = 0; j < m; ++j) {
            cin >> a[i][j];
        }
    }

    auto cnt = 0;
    for (auto i = 0; i < n; ++i) {
        auto sum = 0LL;
        for (auto x = 0; x < m; ++x) {
            sum += a[i][x] * b[x];
        }
        sum += c;
        if (sum > 0)
            cnt++;
    }

    cout << cnt << endl;
    return 0;
}


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

int main(void){
    int score;
    cin >> score;
    if(score < 1200){
        cout << "ABC" << endl;
    }else if(score < 2800){
        cout << "ARC" << endl;
    }else{
        cout << "AGC" << endl;
    }
    return 0;
}

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

int main() {
	int n;
	cin >> n;
	vector<tuple<string, int , int >> a;
	for (int i = 1; i <= n; i++) {
		string s;
		int p;
		cin >> s >> p;
		p = -p;
		a.emplace_back(s, p, i);
	}
	sort(a.begin(), a.end());
	for (int i = 0; i < n; i++) {
		cout << get<2>(a[i]) << endl;
	}
	return 0;
}

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

using namespace std;

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

	vector<string> a(H);

	string s = "#";
	string buf0 = "";
	for (int j = 0; j < W+2; j++)
	{
		buf0 += s;
	}
	cout << buf0 << endl;
	for (int i = 0; i < H; i++)
	{
		string buf = "";
		cin >> a.at(i);
		buf = s + a.at(i) + s;
		cout << buf << endl;
	}
	cout << buf0 << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = (int)(a); i <= (int)(n); ++i)
#define rrep(i, a, n) for (int i = (int)(a); i >= (int)(n); --i)
#define debug(x) cerr << #x << " = " << x << "\n"
#define debugv(x) \
  rep(f, 0, (x.size() - 1)) cerr << x[f] << (f == (x.size() - 1) ? "\n" : " ")
#define all(x) x.begin(), x.end()
#define int long long
using namespace std;
typedef pair<int, int> pii;
typedef vector<int> vi;
const int MX = 1e5 + 5, INF = 5 << 28, MOD = 1e9 + 7;

int x, a, b;
void input() {
  cin >> x >> a >> b;

  ;
}
void solve() {
  int ans;

  ans = abs(x - a) > abs(x - b);
  cout << (ans ? "B" : "A") << endl;
  ;
  ;
}
signed main() {
  input();
  solve();
  return 0;
}

Measured memory_bytes: 256
import sys,collections as cl,bisect as bs
sys.setrecursionlimit(100000)
input = sys.stdin.readline
mod = 10**9+7
Max = sys.maxsize
def l(): #intのlist
    return list(map(int,input().split()))
def m(): #複数文字
    return map(int,input().split())
def onem(): #Nとかの取得
    return int(input())
def s(x): #圧縮
    a = []
    aa = x[0]
    su = 1
    for i in range(len(x)-1):
        if aa != x[i+1]:
            a.append([aa,su])
            aa = x[i+1]
            su = 1
        else:
            su += 1
    a.append([aa,su])
    return a
def jo(x): #listをスペースごとに分ける
    return " ".join(map(str,x))
def max2(x): #他のときもどうように作成可能
    return max(map(max,x))
def In(x,a): #aがリスト(sorted)
    k = bs.bisect_left(a,x)
    if k != len(a) and a[k] ==  x:
        return True
    else:
        return False
"""
def nibu(x,n,r):
    ll = 0
    rr = r
    while True:
        mid = (ll+rr)//2

    if rr == mid:
        return ll
    if (ここに評価入れる):
        rr = mid
    else:
        ll = mid+1
"""
s = input().split()[0]

if s.count("hi") * 2 == len(s):
    print("Yes")
else:
    print("No")



Measured memory_bytes: 38620
#include<vector>
#include<cmath>
#include<map>
#include<cstdlib>
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<set>
#include<stack>
#include<bitset>
#include<functional>
#include<ctime>
#include<queue>
#include<deque>
#include<complex>
#include<cassert>
using namespace std;
#define pb push_back
#define pf push_front
typedef long long lint;
typedef complex<double> P;
#define mp make_pair
#define fi first
#define se second
typedef pair<int,int> pint;
#define All(s) s.begin(),s.end()
#define rAll(s) s.rbegin(),s.rend()
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
//問題文および制約はちゃんと確認しよう！
//サイズは10^5じゃなくて2×10^5とかかもしれないし、重要な制約・条件を見落としているかも
//とりあえずサンプルを読んでから解法を考えよう？
bool dp[5010][10010];
int a[10]={0,2,5,5,4,5,6,3,7,6};
int main()
{
	int n,m,x;vector<int> v;
	cin>>n>>m;
	rep(i,m){
		cin>>x;v.pb(x);
	}
	sort(All(v));reverse(All(v));
	memset(dp,false,sizeof(dp));
	dp[0][0]=1;
	rep(i,5005) rep(j,n+1){
		if(!dp[i][j]) continue;
		rep(k,m) dp[i+1][j+a[v[k]]]=true;
	}
	int d=0;
	rep(i,5005){
		if(dp[i][n]) d=max(d,i);
	}
	string out="";
	for(int i=d;i>0;i--){
		x=0;
		rep(j,m){
			if(dp[i-1][n-a[v[j]]]) x=max(x,v[j]);
		}
		out+=('0'+x);n-=a[x];
	}
	cout<<out<<endl;
}


Measured memory_bytes: 49280
#include <stdio.h>  
#include <algorithm>  
#include <assert.h>
#include <bitset>
#include <cmath>  
#include <complex>  
#include <deque>  
#include <functional>  
#include <iostream>  
#include <limits.h>  
#include <map>  
#include <math.h>  
#include <queue>  
#include <set>  
#include <stdlib.h>  
#include <string.h>  
#include <string>  
#include <time.h>  
#include <unordered_map>  
#include <unordered_set>  
#include <vector>  

#pragma warning(disable:4996)  
#pragma comment(linker, "/STACK:336777216")  
using namespace std;

#define mp make_pair  
#define Fi first  
#define Se second  
#define pb(x) push_back(x)  
#define szz(x) ((int)(x).size())  
#define rep(i, n) for(int i=0;i<n;i++)  
#define all(x) (x).begin(), (x).end()  
#define ldb ldouble  

typedef unsigned int uint;
typedef tuple<int, int, int> t3;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair <ll, int> pli;
typedef pair <db, db> pdd;

int IT_MAX = 1 << 19;
const ll MOD = 1000000007;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const db PI = acos(-1);
const db ERR = 1e-10;

const int MX = 55*55*55;

int P[MX];
ll dp[MX];
pll unit[MX];
ll cnt[MX], W[MX];
int N, X, D;

int main()
{
	scanf("%d%d%d%lld", &N, &X, &D, W+1);
	for(int i = 2; i <= N; i++) scanf("%lld%d", W+i, P+i);
	for(int i = 1; i <= N; i++) cnt[i] = 1;
	for(int i = N; i >= 2; i--) cnt[P[i]] += cnt[i], W[P[i]] += W[i];

	for(int i = 1; i <= N; i++) unit[i] = pll(W[i], cnt[i]);

	ll ans = 0;
	int tot = 0;
	for(int i = 1; i < MX; i++) dp[i] = 1e18;
	for(int i = 1; i <= N; i++){
		int u = i == 1? 50 : min(50, D);
		tot += unit[i].second * u;
		for(int j = tot; j >= 0; j--){
			for(int k = 0; k <= u; k++){
				if(j < k * unit[i].second) break;
				dp[j] = min(dp[j], dp[j - k*unit[i].second] + k*unit[i].first);
			}
		}
	}

	sort(unit+1, unit+N+1, [](pll l, pll r){ return l.first * r.second < l.second * r.first; });
	for(int i = 0; i <= tot; i++){
		ll sum = i, rm = X - dp[i];
		for(int j = 1; j <= N && rm >= 0; j++){
			ll dv = min(rm / unit[j].first, max(0ll, D - 50ll));
			if(unit[j].second == N) dv = rm / unit[j].first;
			sum += dv * unit[j].second; rm -= dv * unit[j].first;
		}
		if(rm >= 0) ans = max(ans, sum);
	}
	printf("%lld\n", ans);
}


Measured memory_bytes: 4736
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,x,n) for(int i=x;i<n;i++)
#define mod 1000000007 //10^9+7
#define INF 1000000000000 //10^12
#define F first
#define S second
#define P pair<int,int>
#define all(vec) vec.begin(),vec.end()
map<int,int>mp;
int tri(int n){
    int x=0;
    for(int i=1;;i++){
        if(x+i>n){
            return i-1;
        }
        else x+=i;
    }
    return 0;
}
vector<int>vec;
signed main(){
    int n;
    int ans=0;
    cin>>n;
    int nn=n;
    for(int i=2;i<=sqrt(nn);i++){
        if(n%i==0){
            mp[i]++;
            n/=i;
            i--;
        }
        if(n==1){
            break;
        }
    }
    if(n>1){
        mp[n]++;
    }
    for(auto x:mp){
        ans+=tri(x.second);
    }
    if(ans==0&&n>1)cout<<1<<endl;
    else cout<<ans<<endl;
    return 0;
}


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

int main(){
    string s;
    cin>>s;
    reverse(s.begin(),s.end());
    int n=s.size();
    string ans;
    rep(i,n){
        if(s.substr(i,8)=="LAVITSEF"){
            ans=s.substr(i+8);
            break;
        }
    }
    reverse(ans.begin(),ans.end());
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define For(i, a, b) for(int (i)=(int)(a); (i)<(int)(b); ++(i))
#define rFor(i, a, b) for(int (i)=(int)(a)-1; (i)>=(int)(b); --(i))
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef unsigned long long ulint;
typedef pair<int, int> pii;
typedef pair<int, lint> pil;
typedef pair<lint, lint> pll;
template<class T> bool chmax(T &a, const T &b){if(a<b){a=b; return true;} return false;}
template<class T> bool chmin(T &a, const T &b){if(a>b){a=b; return true;} return false;}
template<class T> T div_floor(const T a, const T b){return a>=0 ? a/b : (a+1)/b-1;}
template<class T> T div_ceil(const T a, const T b){return a>=0 ? (a-1)/b+1 : a/b;}

constexpr lint mod = 1e9+7;
constexpr lint INF = mod*mod;
constexpr int MAX = 100010;

typedef struct UnionFindTree{
    vector<int> par, bl, wh;

    UnionFindTree(int n){
        par.resize(n, -1);
        bl.resize(n, 0);
        wh.resize(n, 0);
    }

    bool is_root(int x){
        return par[x]<0;
    }

    int find(int x){
        if(is_root(x)) return x;
        return par[x] = find(par[x]);
    }

    int size(int x){
        return -par[find(x)];
    }

    bool unite(int x, int y){
        x = find(x);
        y = find(y);
        if(x == y) return false;
        if(size(x) < size(y)) swap(x, y);
        par[x] += par[y];
        bl[x] |= bl[y];
        wh[x] |= wh[y];
        par[y] = x;
        return true;
    }

    bool same(int x, int y){
        return find(x) == find(y);
    }

    void set_col(int x, int c){
        x = find(x);
        if(c == 0) bl[x] = 1;
        else wh[x] = 1;
    }
}UF;

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

int idx(int x, int y){
    return x*w+y;
}

int main(){
    while(scanf("%d%d", &w, &h) && h){
        char a[h][w];
        rep(i, h)rep(j, w) scanf(" %c", &a[i][j]);
        UF uf(h*w);
        rep(x, h)rep(y, w)if(a[x][y]=='.'){
            rep(i, 4){
                int nx = x+dx[i], ny = y+dy[i];
                if(0<=nx && nx<h && 0<=ny && ny<w){
                    if(a[nx][ny] == 'B') uf.set_col(idx(x, y), 0);
                    else if(a[nx][ny] == 'W') uf.set_col(idx(x, y), 1);
                    else uf.unite(idx(x, y), idx(nx, ny));
                }
            }
        }
        int ansb = 0, answ = 0;
        rep(i, h*w)if(uf.is_root(i)){
            if(uf.bl[i] && !uf.wh[i]) ansb += uf.size(i);
            if(!uf.bl[i] && uf.wh[i]) answ += uf.size(i);
        }
        printf("%d %d\n", ansb, answ);
    }
}


Measured memory_bytes: 3172
import java.util.*;
import java.util.ArrayDeque;
import java.util.Queue;
import java.math.RoundingMode;
import java.math.BigDecimal;
 
 
 
public class Main{
	 public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		int k = sc.nextInt();
		int ans = 0;
		if(a<=k) {
			ans+=a;
			k-=a;
		}
		else {
			ans+=k;
			k = 0;
		}
		if(k!=0) {
			if(b<=k) {
				k-=b;
			}
			else {
				k=0;
			}
		}
		if(k!=0) {
			if(c<=k) {
				ans-=c;
			}
			else {
				ans-=k;
			}
		}
		System.out.println(ans);
	 }
}

Measured memory_bytes: 35820
#include "bits/stdc++.h"
// Begin Header {{{
#define all(x)          (x).begin(), (x).end()
#define rep(i, n)       for (i64 i = 0, i##_limit = (n); i < i##_limit; ++i)
#define reps(i, s, t)   for (i64 i = (s), i##_limit = (t); i <= i##_limit; ++i)
#define repr(i, s, t)   for (i64 i = (s), i##_limit = (t); i >= i##_limit; --i)
#ifndef DBG
#define trace(...)
#endif
using namespace std;
using i64 = int_fast64_t;
using pii = pair<i64, i64>;
template <class T, class U> inline bool chmax(T &a, const U &b) { return b > a && (a = b, true); }
template <class T, class U> inline bool chmin(T &a, const U &b) { return b < a && (a = b, true); }
constexpr int INF  = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;

template <class T>
inline vector<T> make_v(const T &initValue, size_t sz) {
    return vector<T>(sz, initValue);
}

template <class T, class... Args>
inline auto make_v(const T &initValue, size_t sz, Args... args) {
    return vector<decltype(make_v<T>(initValue, args...))>(sz, make_v<T>(initValue, args...));
}

inline void read() {}

template <class Head, class... Tail>
inline void read(Head &head, Tail&... tail) { cin >> head; read(tail...); }

inline void print() { cout << "\n"; }

template <class Head, class... Tail>
inline void print(Head &&head, Tail&&... tail) {
    cout << head;
    if (sizeof...(tail)) cout << ' ';
    print(forward<Tail>(tail)...);
}

template <class T>
inline ostream& operator<< (ostream &out, const vector<T> &vec) {
    static constexpr const char *delim[] = { " ", "" };
    for (const auto &e : vec) out << e << delim[&e == &vec.back()];
    return out;
}
// }}} End Header

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

    int N, K, S;
    cin >> N >> K >> S;

    vector<int> a(N);
    rep(i, K) a[i] = S;
    reps(i, K, N-1) a[i] = (S - 1 >= 1 ? S - 1 : S + 1);

    print(a);

    return 0;
}


Measured memory_bytes: 1792
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<ll, int> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	cin >> n;
	vector<int> a(n);
	rep(i,n) cin >> a[i];
	if(a[0] != 0){
		cout << -1 << endl;
		return 0;
	}
	ll ans = -1;
	int b = -1;
	rep(i,n){
		if(a[i] == b+1){
			++ans;
			++b;
		}
		else if(a[i] > b+1){
			cout << -1 << endl;
			return 0;
		}
		else{
			ans += a[i];
			b = a[i];
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3992
#include<stdio.h>

int main(){
	int a,b,c;
	scanf("%d %d %d",&a,&b,&c);
	
	if((a<=b)&&(b<=c)){
		printf("%d %d %d\n",a,b,c);
	}else if((c<=b)&&(a<=c)){
		printf("%d %d %d\n",a,c,b);
	}else if((a<=b)&&(c<=a)){
		printf("%d %d %d\n",c,a,b);
	}else if((b<=a)&&(a<=c)){
		printf("%d %d %d\n",b,a,c);
	}else if((c<=a)&&(b<=c)){
		printf("%d %d %d\n",b,c,a);
	}else if((b<=a)&&(c<=b)){
		printf("%d %d %d\n",c,b,a);
	}
	
	return 0;
}

Measured memory_bytes: 596
#pragma gcc optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;

int n;
string s;

int main() {
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    cin >> n >> s;
    if (n & 1) return cout << "No\n", 0;
    cout << (s.substr(0, n >> 1) == s.substr(n >> 1, n >> 1) ? "Yes" : "No") << '\n';
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)n;i++)
int main() {
  int n,l; cin>>n>>l;
  vector<string> s(n);
  rep(i,n)cin>>s[i];
  sort(s.begin(),s.end());
  rep(i,n)cout<<s[i];
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#define ll long long int
#define F first
#define S second
const ll mod = 1e9 + 7;
const ll INF = 10000000000000;
#define pb push_back
#define deb(x) cout << '>' << #x << ':' << x << endl;
#define fastio ios_base::sync_with_stdio(0); cin.tie(0);
using namespace std;

int main()
{
    fastio;
    ll n=0;
    cin>>n;
    ll v[n];
    for(ll i=0;i<n;++i) cin>>v[i];
    sort(v,v+n);
    ll cost=INT_MAX;
    for(ll i=v[0];i<=v[n-1];++i){
        ll curr=0;
        for(ll j=0;j<n;++j){
            ll d=abs(i-v[j]);
            curr+=(d*d);
        }
        cost=min(curr,cost);
    }
    cout<<cost;
}

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

typedef long long ll;

int main(){
  ll a,b,q;
  cin >> a >> b >> q;
  ll s[a+2],t[b+2],x[q];
  for(int i=1;i<a+1;i++){
    cin >> s[i];
  }
  for(int i=1;i<b+1;i++){
    cin >> t[i];
  }
  for(int i=0;i<q;i++){
    cin >> x[i];
  }
  s[0]=-1e15;
  s[a+1]=1e15;
  t[0]=-1e15;
  t[b+1]=1e15;
  for(int i=0;i<q;i++){
    ll lb=0,ub=a+1;
    while(ub-lb>1){
      ll mid=(lb+ub)/2;
      if(s[mid]>=x[i]){
        // これが条件を満たせば、解の存在範囲は(lb,mid]
        ub=mid;
      }
      else{
        // これが条件を満たせば、解の存在範囲は(mid,ub]
        lb=mid;
      }
    }
    // この時点でlb+1=ub
    
    
    ll lb_t=0,ub_t=b+1;
    while(ub_t-lb_t>1){
      ll mid=(lb_t+ub_t)/2;
      if(t[mid]>=x[i]){
        ub_t=mid;
      }
      else{
        lb_t=mid;
      }
    }
    ll ans=min({abs(s[lb]-x[i])+abs(t[lb_t]-s[lb]),abs(s[lb]-x[i])+abs(t[ub_t]-s[lb]),abs(s[ub]-x[i])+abs(t[lb_t]-s[ub]),abs(s[ub]-x[i])+abs(t[ub_t]-s[ub]),abs(t[lb_t]-x[i])+abs(s[lb]-t[lb_t]),abs(t[lb_t]-x[i])+abs(s[ub]-t[lb_t]),abs(t[ub_t]-x[i])+abs(s[lb]-t[ub_t]),abs(t[ub_t]-x[i])+abs(s[ub]-t[ub_t])});
    cout << ans << endl;
  }
}


Measured memory_bytes: 3712
def modpow(val, n, mod):
    ret = 1
    while n:
        if n & 1:
            ret = (ret * val) % mod
        val = (val * val) % mod
        n = n >> 1
    return ret


def calc(val, my_dict, cnt):
    num_one = bin(val).count('1')
    if val in my_dict:
        return cnt + my_dict[val]
    else:
        if num_one == 0:
            return cnt
        nex = val % num_one
        ret = calc(nex, my_dict, cnt+1)
        my_dict[val] = ret - cnt
        return ret


n = int(input())
x = input()
tmp = list(x)
my_dict = dict()

num_one = tmp.count('1')
num_one_plus = num_one + 1
num_one_minus = num_one - 1

modsum_plus = 0
modsum_minus = 0
for i in range(1, n+1):
    if tmp[-i] == '1':
        modsum_plus += modpow(2, i-1, num_one_plus) % num_one_plus
        if num_one_minus != 0:
            modsum_minus += modpow(2, i-1, num_one_minus) % num_one_minus

for i in range(n):
    if num_one == 1 and tmp[i] == '1':
        print(0)
        continue
    if tmp[i] == '0':
        val = (modsum_plus + modpow(2, n-i-1, num_one_plus)) % num_one_plus
    else:
        if num_one_minus != 0:
            val = (modsum_minus - modpow(2, n-i-1, num_one_minus)) % num_one_minus
        else:
            val = 0
    if val != 0:
        print(calc(val, my_dict, 1))
    else:
        print(1)


Measured memory_bytes: 13172
// 26/01/20 // 12:19 PM //

#include <bits/stdc++.h>

using namespace std;

#define endl "\n"
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define int long long

const int MAXN = (int)(3e3) + 10;

int n, a[MAXN];
int memo[MAXN][MAXN];

int solve(int l, int r){
    if(memo[l][r]!=-1) return memo[l][r];

    if(l>r) return memo[l][r] = 0;
    if(((r-l+1)&1)==(n&1))
        return memo[l][r] = max(a[l] + solve(l+1, r), a[r] + solve(l, r-1));
    else
        return memo[l][r] = min(solve(l+1, r) -a[l], solve(l, r-1) -a[r]);
}

int32_t main(){
    fastio;

    cin >> n;
    for(int i=1; i<=n; i++) cin >> a[i];

    memset(memo, -1, sizeof(memo));
    cout << solve(1, n) << endl;

    return 0;
}


Measured memory_bytes: 71168
#include <bits/stdc++.h>
#include <vector> 
# include <cstdint>
#define FOR(i,l,r) for(int i=(l);i<(r);++i)
#define RFOR(i,l,r) for(int i=(l);i>=(int)(r);i--)
#define rep(i,n)  FOR(i,0,n)
#define rrep(i,n)  RFOR(i,n-1,0)

#define int long long
using namespace std;
const int MX = 1e6;
const int inf = 1e9;
const int mod = 1e9+7;
using ll = long long;
using P = pair<ll, ll>;
vector<int> to[100005];
int cost[100005];

int x[10];
int y[10];

double dist(ll i, ll j) {
    int xx = (x[i]-x[j])*(x[i]-x[j]);
    int yy = (y[i]-y[j])*(y[i]-y[j]);
    return sqrt(xx+yy);
}

signed main(){
    long long n;
    cin >> n;
    long double ans = 0;
    vector<int> np(n);
    rep(i, n) np[i] = i;
    long fac = 1;
    FOR(i,1, n) fac *= i; 
    //cout << fac << endl;
    rep(i, n) {
        cin >> x[i] >> y[i];
    }
    for(int i = 0; i<n; i++) {
        for(int j = i+1; j<n; j++) {
        ans += dist(i, j)*2/n;
        //cout << np[i]<< " " <<np[i+1]<<" "<<dist(np[i], np[i+1]) << endl;
        }
    }
   
    cout << setprecision(15) << ans << endl;

    return 0;
}



Measured memory_bytes: 2560
#include <iostream>
#include <cstdio>
#include <cmath>

using namespace std;

char ans[105][105];

int main(){
    int a,b;
    for (int i = 0 ; i < 100;i++){
        for (int j = 0;j < 100; j++){
            if ( j < 50) ans[i][j] = '#';
            else ans[i][j] = '.';
        }
    }
//    for (int i = 0; i < 100;i++){
//        for (int j = 0;j < 100; j++){
//            cout<< ans[i][j]<<" ";
//        }
//        cout<<endl;
//    }
//    ###...
//    ###...
//    ###...
    //左白右黑填表
    cin>>a>>b;
    int k = 0;
    for (int i = 0;i < 100; i+=2){
        for (int j = 0;j < 50;j++){
            if ((i+j)%2==0){
                if(a!=1){
                    ans[i][j] = '.';
                    a--;
                }
                else{
                    k = 1;
                    break;
                }
            }
        }
        if(k){
            break;
        }
    }
    k = 0;
    for (int i = 0; i < 100;i+=2){
        for (int j = 50;j < 100;j++){
            if ((i+j)%2==1){
                if(b!=1){
                    ans[i][j] = '#';
                    b--;
                }
                else{
                    k =1;
                    break;
                }
            }
        }
        if (k == 1){
            break;
        }
    }
    cout<<100<<" "<<100<<endl;
    for (int i = 0;i < 100;i++){
        for (int j = 0;j < 100; j++){
            if (j == 99){
                cout<<ans[i][j]<<endl;
            }
            else{
                cout<<ans[i][j];
            }
        }
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main(){
    int N, M;
    cin >> N >> M;
    
    int AC[N] = {}, WA[N] = {}, count = 0, pena = 0;
    for(int i=0;i<M;i++){
        int p;
        string S;
        cin >> p >> S;
        if(S == "WA"){
            WA[p-1]++;
        }else{
            if(AC[p-1] == 0){   // 初めてACした場合
                pena += WA[p-1];
                AC[p-1] = 1;
                count++;
            }
        }
    }
    
    cout << count << ' ' << pena << endl;

}

Measured memory_bytes: 1024
require 'prime'
require 'set'
require 'tsort'
include Math
ALP = ('a'..'z').to_a
INF = 0xffffffffffffffff
def max(a,b);              a > b ? a : b                              end
def min(a,b);              a < b ?  a : b                             end
def swap(a,b);             a, b = b, a                                end
def gif;                   gets.to_i                                  end
def gff;                   gets.to_f                                  end
def gsf;                   gets.chomp                                 end
def gi;                    gets.split.map(&:to_i)                     end
def gf;                    gets.split.map(&:to_f)                     end
def gs;                    gets.chomp.split.map(&:to_s)               end
def gc;                    gets.chomp.split('')                       end
def pr(num);               num.prime_division                         end
def pr?(num);              Prime.prime?(num)                          end
def digit(num);            num.to_s.length                            end
def array(s,ini=nil);      Array.new(s){ini}                          end
def darray(s1,s2,ini=nil); Array.new(s1){Array.new(s2){ini}}          end
def rep(num);              num.times{|i|yield(i)}                     end
def repl(st,en,n=1);       st.step(en,n){|i|yield(i)}                 end

puts gc[0]+gc[1]+gc[2]


Measured memory_bytes: 4348
from sys import stdin

N, T = [int(i) for i in stdin.readline().rstrip().split()]
c = []
t = []

for i in range(N):
    tmp1, tmp2 = [int(i) for i in stdin.readline().rstrip().split()]
    c.append(tmp1)
    t.append(tmp2)

ans = 1001
for i in range(len(t)):
    if t[i] <= T and c[i] < ans:
        ans = c[i]

if ans == 1001:
    print('TLE')
else:
    print(ans)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
int n;
long long sum,cnt,res,a[200001];
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
#ifdef LOCAL
    freopen("test.inp","r",stdin);
    freopen("test.out","w",stdout);
#endif // LOCAL
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        cin>>a[i];
        sum+=a[i];
    }
    res=1e17;
    for(int i=1;i<=n;i++)
    {
        sum-=a[i];
        cnt+=a[i];
        res=min(res,abs(sum-cnt));
    }
    cout<<res;
}



Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
int main()
{
    char inn;
    int i=1;
    int jud[100005];
    while(cin>>inn)
    {
        if(inn=='b')
            jud[i]=1;
        else if(inn=='d')
            jud[i]=4;
        else if(inn=='p')
            jud[i]=2;
        else if(inn=='q')
            jud[i]=3;
        i++;
    }
    if((i-1)%2==0)
    {
        for(int j=1;j<=(i-1)/2;j++)
        {
            if(jud[j]+jud[i-j]!=5)
            {
                cout<<"No"<<endl;
                return 0;
            }
        }
        cout<<"Yes"<<endl;
        return 0;
    }
    else
        cout<<"No"<<endl;
        return 0;
}

Measured memory_bytes: 640
#include<stdio.h>
 
int main(void){
	int a,b,c,K;

	scanf("%d",&K);
	a = K/2;
	b = K%2;
	if(b == 0)
		c = a*a;
	else c = a * (a+1);

	printf("%ld\n",c);
 
	return 0;
}

Measured memory_bytes: 128
#include<cstdio>
#include<cstring>
int f[15][15][15][15];
short num[15];
int dfs(short len,short num3,short num5,short num7,bool lead,bool limit){
	if(!len)return num3&&num5&&num7;
	if(!lead&&!limit&&f[len][num3][num5][num7]!=-1)return f[len][num3][num5][num7];
	int ans=0;
	if(lead)ans=dfs(len-1,num3,num5,num7,1,0);
	if(limit){
		if(num[len]>=3)if(num[len]>=5)if(num[len]>=7)ans+=dfs(len-1,num3+1,num5,num7,0,0)+dfs(len-1,num3,num5+1,num7,0,0)+dfs(len-1,num3,num5,num7+1,0,num[len]==7);
		else ans+=dfs(len-1,num3+1,num5,num7,0,0)+dfs(len-1,num3,num5+1,num7,0,num[len]==5);
		else ans+=dfs(len-1,num3+1,num5,num7,0,num[len]==3);
	}else ans+=dfs(len-1,num3+1,num5,num7,0,0)+dfs(len-1,num3,num5+1,num7,0,0)+dfs(len-1,num3,num5,num7+1,0,0);
	if(!lead&&!limit)f[len][num3][num5][num7]=ans;
	return ans;
}
inline int work(int n){
	short l=0;
	while(n){
		num[++l]=n%10;
		n/=10;
	}
	memset(f,-1,sizeof(f));
	return dfs(l,0,0,0,1,1);
}
int main(){
	int n;
	scanf("%d",&n);
	printf("%d\n",work(n));
	return 0;
}

Measured memory_bytes: 384
a = []
a.append(list(map(int, input().split())))
a.append(list(map(int, input().split())))
a.append(list(map(int, input().split())))
n = int(input())
b = []
bingo_cnt = 3
cnt1 = 0
cnt2 = 0
cnt3 = 0
cnt_diag = 0
cnt_diag_rev = 0
is_bingo = False

for i in range(n):
    b.append(int(input()))
    
for i in range(len(a)):
    cnt = 0
    for j in range(len(a[i])):
        if a[i][j] in b:
            cnt = cnt + 1
            if j is 0:
                cnt1 = cnt1 + 1
            if j is 1:
                cnt2 = cnt2 + 1
            if j is 2:
                cnt3 = cnt3 + 1
            if i == j:
                cnt_diag = cnt_diag + 1
                cnt_diag_rev = cnt_diag_rev + 1
            if (i is 0 and j is 2) or (j is 0 and i is 2):
                cnt_diag_rev = cnt_diag_rev + 1
        
        if (cnt is 3 or cnt1 is 3 or cnt2 is 3 or cnt3 is 3 or cnt_diag is 3 or cnt_diag_rev is 3) and not is_bingo:
            print("Yes")
            is_bingo = True
            break

if is_bingo is False:
    print("No")

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

#define LOG(variable) cerr << #variable":\t" << (variable) << endl
#define LOGCON(i, container) for(int (i) = 0; (i) < (container).size(); ++(i)) cerr << (i) << ":\t" << (container)[(i)] << endl
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPS(i, r, n) for (int i = (r); i < (n); ++i)
#define REPR(i, n) for(int i = (n); i >= 0; --i) // from n to 0
#define REPRS(i, n, r) for(int i = (n); i >= (r); --i) // from n to r
#define REPOBJ(itr, obj) for(auto itr = (obj).begin(); itr != (obj).end() ; ++itr)
#define REPROBJ(itr, obj) for(auto itr = (obj).rbegin(), e = (obj).rend(); itr != e; ++itr)
#define COUTB(x) cout << (x) << "\n"
#define COUTS(x) cout << (x) << " "
#define PB push_back
#define SORT(obj) sort((obj).begin(), (obj).end())
#define SORTR(obj) sort((obj).begin(), (obj).end(), greater<>())
#define ALL(obj) (obj).begin(), (obj).end()
#define MOD 1000000007
#define PI (acos(-1))
template<typename T = int>
T in() {T a; cin >> a; return a;}

/***** MAIN *****/
signed main() {
  int n; cin >> n;
  int current_money = 1000;
  int current_stock = 0;
  int values[n];
  REP(i,n) {
    cin >> values[i];
  }
  // string s;
  REP(i,n-1) {
    if(values[i] < values[i+1]) {
      int quantity = current_money / values[i];
      current_stock += quantity;
      current_money -= quantity * values[i];
    } else if(values[i] > values[i+1]) {
      current_money += current_stock * values[i];
      current_stock = 0;
    }
  }
  cout << current_money + current_stock * values[n-1];
  cout << "\n";
  return 0;
}
/***** MAIN *****/


Measured memory_bytes: 3648
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES

#include <bits/stdc++.h>
using namespace std;
using i32 = int32_t; using i64 = int64_t; using f64 = double_t; using str = string;
template <typename T> using vec = vector<T>;
template <typename T> using heap = priority_queue<T, vec<T>, greater<T>>;
#define times(n, i) for (i32 i = 0; i < (n); ++i)
#define range(n, m, i) for (i32 i = (n); i < (m); ++i)
#define upto(n, m, i) for (i32 i = (n); i <= (m); ++i)
#define downto(n, m, i) for (i32 i = (n); i >= (m); --i)
#define foreach(xs, x) for (auto &x : (xs))
#define all(xs) (xs).begin(), (xs).end()
#define sortall(xs) sort(all(xs))
#define reverseall(xs) reverse(all(xs))
#define uniqueall(xs) (xs).erase(unique(all(xs)), (xs).end())
#define maximum(xs) (*max_element(all(xs)))
#define minimum(xs) (*min_element(all(xs)))
#define even(x) (((x) & 1) == 0)
#define odd(x) (((x) & 1) == 1)
#define append emplace_back
const i64 MOD = 1000000007;

i32 h, w;
str m[8];
str r[8];

i32 oy[2] = { 0, 1 };
i32 ox[2] = { 1, 0 };

bool rec(i32 y, i32 x) {
    if (m[y][x] == '.')
        return false;

    r[y][x] = '#';
    if (y == h-1 && x == w-1)
        return true;

    bool b[2] = { false, false };
    times(2, i) {
        i32 ny = y + oy[i];
        i32 nx = x + ox[i];
        b[i] = ny < h && nx < w && m[ny][nx] == '#';
    }
    if (b[0] && b[1]) {
        return false;
    }
    times(2, i) {
        if (b[i]) {
            return rec(y+oy[i], x+ox[i]);
        }
    }
    return false;
}

i32 main()
{
    cin >> h >> w;
    times(h, i) {
        cin >> m[i];
        r[i] = "";
        times(w, j) {
            r[i] += '.';
        }
    }

    bool b = rec(0, 0);
    if (b) {
        times(h, i) {
            b &= m[i] == r[i];
        }
    }

    cout << (b ? "Possible" : "Impossible") << endl;
    return 0;
}

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

int main() {
  string s;
  cin >> s;
  if (s[2]==s[3] && s[4] == s[5]) {
    cout << "Yes" << endl;
  }else{
      cout << "No" << endl;
  }
  return 0;
}

Measured memory_bytes: 3616
#include<stdio.h>
#include<iostream>
#include<cmath>
#define maxn 1e7+7
using namespace std;
int main()
{
    int k;long long num=0,sum=0;
    cin>>k;
    bool flag=0;
    for(int i=0;i<maxn;i++)
    {
        num=(num*10+7)%k;
        if(num%k==0)
        {
            flag=1;
            sum=i+1;
            break;
        }
    }
    if(flag==1)
    {
        cout<<sum<<endl;
    }
    else
        cout<<"-1"<<endl;
}


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

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

        int n = sc.nextInt();
        int[][] red = new int[n][2];
        int[][] blue = new int[n][2];

        for (int i = 0; i < n; i++) {
            red[i][0] = sc.nextInt();
            red[i][1] = sc.nextInt();
        }

        for (int i = 0; i < n; i++) {
            blue[i][0] = sc.nextInt();
            blue[i][1] = sc.nextInt();
        }

        // red[i][1]の昇順
        Arrays.sort(red, (x, y) -> x[1] - y[1]);
        // blue[i][0]の昇順
        Arrays.sort(blue, (x, y) -> x[0] - y[0]);

        int cnt = 0;
        boolean[] isUse = new boolean[n];
        for (int i = 0; i < n; i++) {
            for (int j = n-1; j >= 0; j--) {
                if (blue[i][0] > red[j][0] && blue[i][1] > red[j][1] && !isUse[j]) {
                    isUse[j] = true;
                    cnt++;
                    break;
                }
            }
        }

        System.out.println(cnt);
    }
}


Measured memory_bytes: 26580
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
    int n, m;
    cin >> n >> m;
    vector<int> a(n+m, 0);
    rep(i,m) a[i] = 1;
    int ans = 0;
    rep(i,n+m)rep(j,n+m){
        if(i >= j) continue;
        if((a[i]+a[j])%2 == 0) ans++;
    }
    cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
/*#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>

#include <boost/rational.hpp>
*/
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
using ll = long long;
using ld = long double;
#define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++)
#define rep3(i, n) for (ll i = 1; i < (ll)(n+1); i++)
#define rep4(i, s, n) for (ll i = (s); i < (ll)(n+1); i++)
#define repr(i,n) for (ll i = (n-1); i>=0;i--)
#define repr3(i,n) for(ll i = (n);i>0;i--)
#define repr4(i,s,n) for(ll i = (n);i>=(s);i--)
#define stlen(s) ll s.size()-1
#define all(v) v.begin(), v.end()
#define cout(n) cout<<std::fixed<<std::setprecision(n)
using Graph = vector<vector<int>>;
using Graphw = vector<vector<pair<ll,ll>>>;
#define INF1  INT_MAX;
#define INF2  LLONG_MAX;
#define PI  3.14159265358979323846;
#define MOD 1000000007;
/*
namespace mp = boost::multiprecision;
// 任意長整数型
using Bint = mp::cpp_int;
// 仮数部長が32の浮動小数点数型
using Real32 = mp::number<mp::cpp_dec_float<32>>;
// 仮数部長が1024の浮動小数点数型
using Real1024 = mp::number<mp::cpp_dec_float<1024>>;
// 有理数型
using Rat = boost::rational<Bint>;
*/
const int mod = 1000000007;


int main() {
int N,M;
cin>>N>>M;
ll A[N+1];
A[0]=0;
map<ll,int> rem;
rem[0]++;
ll count=0;
rep3(i,N){
    cin>>A[i];
    
    A[i]+=A[i-1];
    
    count+=rem[A[i]%M];
    rem[A[i]%M]++;
    
    
    
}

cout<<count<<endl;
return 0;
}

Measured memory_bytes: 8188
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define REP(i,a,b) for(int i=int(a);i<(int)b;++i)


using namespace std;
using ll = long long;

const int m = 2019;

int main(void)
{
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);
    string s;
    cin >> s;
    int n = s.size();
    reverse(s.begin(),s.end());
    int x = 1,tot = 0;
    vector<int> cnt(m);
    ll ans = 0;
    rep(i,n)
    {
        tot += (s[i]-'0')*x;
        tot %= m;
        if(tot == 0) ans++;
        cnt[tot] ++;
        x =x*10%m;
    }
    rep(i,m)
    {
        ans += cnt[i]*(cnt[i]-1)/2;

    }
    cout << ans << endl;
    

    
   

    return 0;
}


Measured memory_bytes: 3748
#include <iostream>
#include <climits>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <deque>
#define INF_INT (INT_MAX / 2)
#define INF_LONG (LONG_MAX / 2)
//#define DEBUG true
#define DEBUG false
using namespace std;

typedef long long ll;
typedef pair< int, int > pii;
typedef pair< ll, ll > pll;
typedef pair< ll, int > pli;
typedef pair< int, ll > pil;

int ceil(int x, int y){
  return (x % y == 0) ? x / y : x / y + 1;
}

int gcd(int x, int y){
  return y ? gcd(y, x % y) : x;
}

int lcm(int x, int y){
  return x / gcd(x, y) * y;
}

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

  int n, k;
  cin >> n >> k;
  ll x[n];
  for(int i = 0; i < n; i++) cin >> x[i];

  ll ans = INF_LONG;
  for(int s = 0; s + k - 1 < n; s++){
    int t = s + k - 1;
    ll tmp;
    if(x[t] <= 0) tmp = -x[s];
    else if(x[s] >= 0) tmp = x[t];
    else tmp = 2l * min(-x[s], x[t]) + max(-x[s], x[t]);
    ans = min(ans, tmp);
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
using namespace std;
typedef long long ll;
const int N=110;
int tt,head[N],to[N*2],nxt[N*2],f[N],dep[N],v[N];
inline void dfs(int x,int fa) {
	dep[x]=0;
	for(int i=head[x],u;i;i=nxt[i])
		if((u=to[i])!=fa){
			dfs(u,x),dep[x]=max(dep[x],dep[u]+1);
		}
}
inline void solve(int x,int fa,int d);
inline void link(int x,int y){to[++tt]=y,nxt[tt]=head[x],head[x]=tt;}
int main() {
	int n,ans=1<<30,tp=0,x,y;ll sum=-1;
	cin>>n;
	for(int i=1;i<n;i++) {
		scanf("%d%d",&x,&y);
		link(x,y);link(y,x);
	}
	for(int i=1;i<=n;i++)dfs(i,0),ans=min(ans,dep[i]);
	for(int i=1;i<=n;i++){
		dfs(i,0);
		if(dep[i]==ans) v[++tp]=i;
	}
	if(tp==1) {
		++ans;
		printf("%d ",ans);
		int x=v[1],y;
		solve(x,0,0),sum=1;
		for(int j=0;j<ans-1;j++) sum*=f[j];
		for(int i=head[x];i;i=nxt[i]) {
			y=to[i];
			memset(f,0,sizeof(f));
			solve(x,y,0),solve(y,x,0);
			ll g=2;
			for(int j=0;j<ans-1;j++) g*=f[j];
			sum=min(sum,g);
		}
	}
	else {
		printf("%d ",ans);
		int x=v[1],y=v[2];
		solve(x,y,0),solve(y,x,0),sum=2;
		for(int j=0;j<ans-1;j++) sum=sum*f[j];
	}
	printf("%lld",sum);
	return 0;
}
inline void solve(int x,int fa,int d) {
	int ch=0;
	for(int i=head[x];i;i=nxt[i])
		if(to[i]!=fa) ++ch,solve(to[i],x,d+1);
	f[d]=max(ch,f[d]);
}


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

int main() {
  int n,k;
  cin >> n >> k;
  ll ans;
  ans = k*pow(k-1,n-1);
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 512