akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef vector<int> VI;
 
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
const int mod=1e9+7;

template< int mod >
struct ModInt {
  int x;
 
  ModInt() : x(0) {}
 
  ModInt(int64_t y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {}
 
  ModInt &operator+=(const ModInt &p) {
    if((x += p.x) >= mod) x -= mod;
    return *this;
  }
 
  ModInt &operator-=(const ModInt &p) {
    if((x += mod - p.x) >= mod) x -= mod;
    return *this;
  }
 
  ModInt &operator*=(const ModInt &p) {
    x = (int) (1LL * x * p.x % mod);
    return *this;
  }
 
  ModInt &operator/=(const ModInt &p) {
    *this *= p.inverse();
    return *this;
  }
 
  ModInt operator-() const { return ModInt(-x); }
 
  ModInt operator+(const ModInt &p) const { return ModInt(*this) += p; }
 
  ModInt operator-(const ModInt &p) const { return ModInt(*this) -= p; }
 
  ModInt operator*(const ModInt &p) const { return ModInt(*this) *= p; }
 
  ModInt operator/(const ModInt &p) const { return ModInt(*this) /= p; }
 
  bool operator==(const ModInt &p) const { return x == p.x; }
 
  bool operator!=(const ModInt &p) const { return x != p.x; }
 
  ModInt inverse() const {
    int a = x, b = mod, u = 1, v = 0, t;
    while(b > 0) {
      t = a / b;
      swap(a -= t * b, b);
      swap(u -= t * v, v);
    }
    return ModInt(u);
  }
 
  ModInt pow(int64_t n) const {
    ModInt ret(1), mul(x);
    while(n > 0) {
      if(n & 1) ret *= mul;
      mul *= mul;
      n >>= 1;
    }
    return ret;
  }
 
  friend ostream &operator<<(ostream &os, const ModInt &p) {
    return os << p.x;
  }
 
  friend istream &operator>>(istream &is, ModInt &a) {
    int64_t t;
    is >> t;
    a = ModInt< mod >(t);
    return (is);
  }
 
  static int get_mod() { return mod; }
};
 
using modint = ModInt< mod >;



int main(){
  int n;cin>>n;
  string s;cin>>s;
  if(s[0]=='W'||s[2*n-1]=='W'){
    cout<<0<<endl;exit(0);
  }
  int p[2*n];
  p[0]=1;
  rep(i,2*n-1){
    if(s[i]!=s[i+1])p[i+1]=p[i];
    else p[i+1]=1-p[i];
  }
  int sum[2*n+1];
  sum[0]=0;
  rep(i,2*n){
    sum[i+1]=sum[i]+p[i];
  }
  if(sum[2*n-1]!=n){
    cout<<0<<endl;exit(0);
  }
  modint ans=1;
  int ctr=0;
  rep(i,2*n){
    if(p[i])continue;
    ans*=modint(sum[i+1]-ctr);
    ctr++;
  }
  rep(i,1,n+1)ans*=modint(i);
  cout<<ans<<endl;
}





Measured memory_bytes: 2180
#include<iostream>

using namespace std;
long long int max(long long int a,long long int b)
{
    if(a>=b)
    return a;
    return b;
}
int main()
{

  long long int n,w;
	    cin>>n;
	    cin>>w;
	    long long int value[n];
	    long long int weight[n];
	    for(long long int i=0;i<n;i++)
        { cin>>weight[i];
	    cin>>value[i];
        }
  

  
long long int dp[n+1][w+1];
  
  for(long long int i=0;i<=n;i++)
  {
    for(long long int j=0;j<=w;j++)
    {
	if(i==0||j==0)
      dp[i][j]=0;
      else if(weight[i-1]>j)
        dp[i][j]=dp[i-1][j];
      else
        dp[i][j]=max(value[i-1]+dp[i-1][j-weight[i-1]],dp[i-1][j]);
    }
  }
  
 cout<<dp[n][w]<<endl;
 
  
  return 0;
}
  


Measured memory_bytes: 79232
#include <stdio.h>

int main(){
	int i,j,n;
	int ans = 0;
	scanf("%d",&n);
	
	char table[n][n+1];
	for(i=0;i<n;i++){
		scanf("%s",table[i]);
	}
	
	int w[n],k[n];
	for(i=0;i<n;i++){
		w[i] = 0;
		k[i] = 0;
	}
	
	for(i=0;i<n;i++){
		for(j=0;j<n;j++){
			if(table[i][j]=='#'){
				w[i]++;
			}else{
				k[i]++;
			}
		}
		int found = 1;
		for(j=0;j<n;j++){
			if(table[j][i]=='#') found = 0;
		}
		k[i]+=found;
		if(w[i]==n) k[i] = 0;
	}
	
	int maxw = w[0];
	for(i=0;i<n;i++){		
		if(maxw < w[i])	maxw = w[i];
	}
	if(maxw == 0){
		printf("%d\n",-1);
		return 0;
	}
	
	int mink = k[0];
	for(i=0;i<n;i++){		
		if(mink > k[i])	mink = k[i];
	}
	
	ans += mink;
	
	int h[n];
	for(i=0;i<n;i++) h[i] = 0;
	for(j=0;j<n;j++){
		for(i=0;i<n;i++){
			if(table[i][j]=='.') h[j] = 1;
		}
	}
	
	int t = 0;
	for(i=0;i<n;i++) t += h[i];
	
	ans += t;
	
	printf("%d\n",ans);
	
	
	return 0;
}

Measured memory_bytes: 384
#include<stdio.h>
#include<stdlib.h>
#include<string.h>


int main(){
	char ss[105];
	int i,c;
	c=0;
	while(0<=scanf("%s",ss)){
		for(i=0;i<=strlen(ss)-1;i++){
			if(ss[i]!=ss[strlen(ss)-i-1])break;
		}
		
		if(i==strlen(ss))++c;
	}
	printf("%d\n",c);
	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);
#define all(x) x.begin(),x.end()
#define pb push_back
#define pf push_front
#define ff first
#define ss second
#define vll vector<ll>
#define sll set<ll>
#define pll pair<ll, ll>
#define vpll vector<pll>
#define endl "\n"
const ll maxn = 2e5+2;

int main()
{
    fastio; //remove for interactive
    ll i, j, k, n, m, t;    

    string s,s2;

    cin>>s>>s2;

    n=s.size();m=s2.size();
    
    ll mini=1000;
    for ( i = 0; i <= n-m; i++)
    {
        ll c=0;
        string s3=s.substr(i,m);
        for ( j = 0; j < m; j++)
        {
           if(s3[j]!=s2[j]) 
            c++;
        }
        mini=min(mini,c);
    }
    cout<<mini<<endl;    
        
    return 0;
}

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

typedef long long ll;
#define int ll

using namespace std;

const int N=1010;

vector<int> g[N],r[N];
bool used[N];
vector<int> ans;

void dfs(int v)
{
    if(used[v])
        return;
    used[v]=true;
    int mn=int(ans.size())-1;
    for(int from:r[v])
        for(int i=0;i<ans.size();i++)
            if(ans[i]==from)
                mn=min(mn,i);
    vector<int> del(ans.begin()+mn+1,ans.end());
    ans.erase(ans.begin()+mn+1,ans.end());
    ans.push_back(v);
    int mx=-1;
    for(int to:g[v])
        for(int i=0;i<ans.size();i++)
            if(ans[i]==to)
                mx=max(mx,i);
    if(mx>=0)
    {
        cout<<ans.size()-mx<<"\n";
        for(int i=mx;i<ans.size();i++)
            cout<<ans[i]<<"\n";
        exit(0);
    }
    for(int to:g[v])
        dfs(to);
    ans.pop_back();
    ans.insert(ans.end(),del.begin(),del.end());
}

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

    int n,m;
    cin>>n>>m;
    while(m--)
    {
        int a,b;
        cin>>a>>b;
        g[a].push_back(b);
        r[b].push_back(a);
    }
    for(int i=1;i<=n;i++)
        dfs(i);
    cout<<-1;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define F first
#define S second

const int mx=100010;
const ll mod=1e9+7;

struct UnionFind {  
  vector<int> par,sizes;                     // par[i]:iの親の番号(ex)par[3]=2 : 3の親が2
  UnionFind(int n) : par(n),sizes(n,1)  {    //最初は全てが根であるとして初期化
    for(int i=0; i<n; i++){ par[i]=i; }  
  }
  int root(int x) {                       //xが属する木の根を再帰で得る:root(x)={xの木の根}
    if(par[x]==x){ return x; }
    return par[x] = root(par[x]);
  }
  void unite(int x, int y) {                 // xとyの木を併合
    int rx = root(x);                        //xの根をrx
    int ry = root(y);                        //yの根をry
    if(rx == ry){ return; }                  //xとyの根が同じ(=同じ木にある)時はそのまま
    if(sizes[rx]<sizes[ry]){ swap(rx, ry); } //xの木をおおきくする
    par[ry] = rx; 
    sizes[rx] += sizes[ry];                  //sizes[ry]はもう使わない
  }

  bool check(int x, int y) {                 // x,yが属する木が同じならtrueを返す
    return root(x) == root(y);
  }
  
  int size(int x){                           //xが含まれる木の大きさを返す
    return sizes[root(x)];
  }
};

int main() {
  int n,m,k; 
  cin >> n >> m >> k;
  UnionFind fr(n),bl(n);
  set<int> st[n];

  rep(i,m){
    int x,y;
    cin >> x >> y; x--; y--;
    fr.unite(x,y);
    st[x].insert(y);
    st[y].insert(x);
  }
  
  vector<int> ans(n,0);
  rep(i,n){
    ans[i] = fr.size(i) - st[i].size() - 1;
  }
  rep(i,k){
    int x,y;
    cin >> x >> y; x--; y--;
    if(fr.check(x,y)){
      ans[x]--; ans[y]--;
    }
  }
  
  rep(i,n){
    if(i!=n-1){ cout << ans[i] << " "; } else { cout << ans[i] << endl; }
  }
  return 0;
}


Measured memory_bytes: 16896
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
using namespace std;

typedef long long ll;

typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 1000000007;
typedef double ld;
typedef complex<ld> Point;
const ll INF = mod * mod;
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++)
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
typedef vector<int> vec;
typedef vector<string> svec;

void solve() {
	int t; cin >> t;
	int h = t / 30;
	int m = (t % 30) * 2;
	cout << h << " " << m << endl;
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(5);
	//while (cin >> n>>h>>m>>s,n)solve();
	solve();
	//stop
	return 0;
}



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

signed main(){
	int N; cin >> N;
	int l = 1, r = N, ans = -1;
	while(l<=r){
		int mid = (l+r)>>1;
		double total = 1.0*mid*1.08;

		if(floor(total) <= N){
			if(floor(total) == N) ans = mid;
			l=mid+1;
		}
		else r = mid-1;
	}
	if(ans < 0) cout << ":(";
	else cout << ans;
}

Measured memory_bytes: 256
class Bit:
    def __init__(self, n):
        self.size = n
        self.tree = [0] * (n + 1)

    def sum(self, i):
        s = 0
        while i > 0:
            s += self.tree[i]
            i -= i & -i
        return s

    def add(self, i, x):
        while i <= self.size:
            self.tree[i] += x
            i += i & -i

    # i+1番目からR番目まで足すとt以上となるような最小のRを返す
    def bisect_plus(self, i, t):
        L = i
        R = self.size
        R_prev = R
        sum_i = self.sum(i)
        while True:
            range_sum = self.sum(R) - sum_i
            if range_sum < t:
                if R == self.size:
                    return self.size + 1
                L, R = R, R_prev
            else:
                R_prev = R
                R = (L + R + 1) // 2
                if R == R_prev:
                    return R

    # L番目からi-1番目まで足すとt以上となるような最小のRを返す
    def bisect_minus(self, i, t):
        L = 1
        R = i
        L_prev = L
        sum_i = self.sum(i - 1)
        while True:
            range_sum = sum_i - self.sum(L - 1)
            if range_sum < t:
                if L == 1:
                    return 0
                L, R = L_prev, L
            else:
                L_prev = L
                L = (L + R) // 2
                if L == L_prev:
                    return L


N = int(input())
a = list(map(int, input().split()))

idx = [0] * (N+1)
for i in range(N):
    idx[a[i]] = i+1

bit = Bit(N)
ans = 0
for i in range(1, N+1):
    p = idx[i]
    bit.add(p, 1)
    L = bit.bisect_minus(p, 1)
    R = bit.bisect_plus(p, 1)
    ans += (((R-L) * (R-L-1)) // 2 - ((p-L) * (p-L-1)) // 2 - ((R-p) * (R-p-1)) // 2) * i

print(ans)


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

using namespace std;
typedef long long ll;

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

    int n, cnt = 0;
    cin >> n;
    vector<int> a(n);
    for(int i = 0; i < n; ++i) cin >> a[i];

    for(int i = 0; i < n; ++i) {
        for(int j = n - 1; j > i; --j) {
            if(a[j] < a[j - 1]) {
                swap(a[j], a[j - 1]);
                cnt++;
            }
        }
    }

    for(int i = 0; i < n; ++i) {
        printf("%d", a[i]);
        printf(i == n - 1 ? "\n" : " ");
    }
    printf("%d\n", cnt);

    return 0;
}


Measured memory_bytes: 3240
#include <iostream>
#include <cmath>

using namespace std;

int main(void){
  int i;
  int N, K;
  cin >> N >> K;
  long long x[N];
  for(i=0; i<N; i++)
    cin >> x[i];
  //入力終わり

  long long tmp;
  long long ans = 1000000000000000000; //10^18ぐらいで適当に初期化
  int l, r;
  //左端を固定して全探索
  for(l = 0; l<=N-K; l++ ){
    r = l + K - 1;
    //min(左行ってから右，右行ってから左)
    tmp = min(abs(x[l] )+abs(x[r]-x[l] ),
	      abs(x[r] )+abs(x[r]-x[l] ) );
    //最初値の更新
    if(tmp < ans)
      ans = tmp;
  }

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


Measured memory_bytes: 1024
#include <iostream>

using namespace std;

typedef long long ll;

int main(int argc, char *argv[])
{
	ll N, A, B;

	cin >> N >> A >> B;

	ll x = N / (A + B);
	ll y = N % (A + B);

	ll ans = (A + B) * x - x * B;
	if (y >= A) {
		ans += A;
	} else {
		ans += y;
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int N=100005;
int a[N],n;
int main() {
    scanf("%d",&n);
    for(int i=0;i<n;i++)
        scanf("%d",&a[i]);
    a[0]--;
    for(int i=1;i<n;i++)
        if(a[i]!=a[i-1]) a[i]--;
    bool f=true;
    for(int i=1;i<n;i++)
        if(a[i]<a[i-1]) f=false;
    printf("%s\n",f?"Yes":"No");
    return 0;
}

Measured memory_bytes: 640
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<deque>
#include<stack>
#include<set>
#include<map>
#include<bitset>
#include<string>
#define rep(i,n,m) for(int i=(n);i<(int)(m);i++)
#define reps(i,n,m) for(int i=(n);i<=(int)(m);i++)
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair
#define fs first
#define sc second
#define lb lower_bound
#define ub upper_bound
#define LB(a,x) lb(all(a), x) - a.begin()
#define UB(a,x) ub(all(a), x) - a.begin()
#define printfdouble(x) printf("%.12f\n",(x))
#define chartoint(c) (int)((c) - '0')
#define chartoll(c) (long long)((c) - '0')
#define MOD 1000000007
#define itn int
#define enld endl
#define ednl endl
#define icn cin
#define stirng string
using namespace std;
typedef long long ll;
const double pi = 3.141592653589793;
using Graph = vector<vector<int>>;
template<class T> bool chmax(T &a, const T &b){if(a<b){a=b; return 1;} return 0;}
template<class T> bool chmin(T &a, const T &b){if(b<a){a=b; return 1;} return 0;}
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    int H,N; cin >> H >> N;
    int A[1005],B[1005];
    rep(i,0,N) cin >> A[i] >> B[i];
    int dp[10005]; // dp[i] = 体力をi以上減らすのに必要な魔力の最小値
    Fill(dp,1001001001);
    dp[0] = 0;
    rep(i,0,N){
        reps(j,0,H){
            if(A[i] > j) chmin(dp[j], B[i]);
            else chmin(dp[j], dp[j-A[i]] + B[i]);
        }
    }
    cout << dp[H] << endl;
    return 0;
}


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

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

#define DEBUG(x) cout<<#x<<": "<<x<<'\n'
#define DEBUG_VEC(v) cout<<#v<<":";REP(i, v.size())cout<<' '<<v[i];cout<<'\n'
#define ALL(a) (a).begin(), (a).end()

#define CHMIN(a, b) a=min((a), (b))
#define CHMAX(a, b) a=max((a), (b))

const ll MOD=1000000007ll;
// const ll MOD=998244353ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

const double EPS=1e-11;
#define EQ0(x) (abs((x))<EPS)
#define EQ(a, b) (abs((a)-(b))<EPS)q

int dp[114514];

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n, k, h[114514];
	cin>>n>>k;
	REP(i, n){
		cin>>h[i];
	}
	FOR(i, 1, n){
		dp[i]=MOD;
	}
	REP(i, n-1){
		FOR(j, 1, k+1){
			if(i+j>=n){
				break;
			}
			CHMIN(dp[i+j], dp[i]+abs(h[i]-h[i+j]));
		}
	}
	cout<<dp[n-1]<<'\n';
	return 0;
}


Measured memory_bytes: 1024
/*
 *  Author : H_Tatsuhiro ( Tatsuhiro Hashimoto )
 *  Created : 2020/08/29 21:14:55
 */

#include <bits/stdc++.h>
#include <boost/multiprecision//cpp_int.hpp>
using namespace std;

namespace mp = boost::multiprecision;
using Booint = mp::cpp_int;

#define endl "\n"
#define FSP(n) cout << fixed << setprecision(n);
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
#define ilMAX 2147483647;
#define llMAX 9223372036854775807;
#define ullMAX 18446744073709551615;
#define SORT(v) sort((v).begin(), (v).end());
#define REV(v) reverse((v).begin(), (v).end());
#define prepare cin.tie(0); cout.tie(0); ios::sync_with_stdio(false);

void solve() {
    Booint a, b, c, d;
    cin >> a >> b >> c >> d;
    if (a >= 0 && b >= 0) {
        if (c >= 0 && d >= 0) cout << b * d << endl;
        else if (c <= 0 && d >= 0) cout << b * d << endl;
        else cout << a * d << endl;
    }
    else if (a <= 0 && b >= 0) {
        if (c >= 0 && d >= 0) cout << b * d << endl;
        else if (c <= 0 && d >= 0) cout << max(b * d, a * c) << endl;
        else cout << a * c << endl;
    }
    else {
        if (c >= 0 && d >= 0) cout << b * c << endl;
        else if (c <= 0 && d >= 0) cout << a * c << endl;
        else cout << a * c << endl;
    }
}

signed main() {
    prepare
    solve();
}

Measured memory_bytes: 3692
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int main() {
	string s, t;
	cin >> s >> t;
	string h = s + s;
	bool ans = false;
	for (int i = 0; i < s.length(); ++i) {
		if (h.substr(i, s.length()) == t) {
			ans = true;
			break;
		}
	}
	
  if(ans) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <functional>
using namespace std;
#define int long long
#define All(v) (v).begin(),(v).end()
int dy[8] = {-1,0,1,0,-1,1,1,-1};
int dx[8] = {0,1,0,-1,1,1,-1,-1};
const int mod = 1000000007;
const int inf = mod*mod;
const int d5 = 100100;
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int a,b,c;
    cin>>a>>b>>c;
    int x=min({a,b,c});
    int z=max({a,b,c});
    int y=a+b+c-x-z;
    int cnt=z-y;
    x+=cnt;
    cnt+=(z-x+1)/2;
    x+=(z-x+1)/2*2;
    if(x!=z)cnt++;
    cout<<cnt<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <tuple>
using namespace std;
    #define fio ios_base::sync_with_stdio(false), cin.tie(NULL)
    #define ll long long
    #define int long long 
    #define ull unsigned long long 
    #define ld long double
    #define sb __builtin_popcount
    #define vi vector<int>
    #define vc vector<char>
    #define ii pair<int, int>
    #define pq priority_queue<ii, vector<ii>, greater<ii>>
    #define vii vector<ii>
    #define sz(a) int((a).size())
    #define f(a, b) for (int i = a; i < b; i++)
    #define fr(a, b) for (int i = a - 1; i >= b; i--)
    #define tr(x, m) for (auto x : m)
    #define in(a, b) (b.find(a) != string::npos)
    #define minin(a) *min_element(all(a))
    #define maxin(a) *max_element(all(a))
    #define X first
    #define Y second
    #define fill(a, x) memset(a, x, sizeof(a))
    #define pb push_back
    #define pf push_front
    #define mp make_pair
    #define all(v) v.begin(), v.end()
    #define rall(v) reverse(v.begin(), v.end())
    #define unq(v) v.erase(unique(all(v)), v.end())
    #define el "\n"
    #define mx3(a, b, c) max(max(a, b), c)
    #define mn3(a, b, c) min(min(a, b), c)
    #define S(v) accumulate(all(v), (ll)0)
    #define SP(n) cout.precision(n)
    const ld PI = atan(1.0) * 4.0;
    const ll MOD = 1e9 + 7;
    const ll INF = 1e18;
    const ld EPS = 0.0000001;
    const ll MD = 998244353;
   
    int32_t main() {
        fio;
        int n;
        cin>>n;
        int a[n]={0} , b[n]={0} , c[n]={0};
        unordered_map<int,int> mp1,mp2;
        for(int i=0;i<n;i++){
            cin>>a[i];
        }
        for(int i=0;i<n;i++){
            b[i]=a[i]+i;
            c[i]=i-a[i];
            mp1[b[i]]++;
            mp2[c[i]]++;
        }
        int ans=0;
        for(auto x:mp1){
            ans+=((x.Y)*(mp2[x.X]));
        }
        cout<<ans<<el;
        return 0;
    }


Measured memory_bytes: 30920
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        int t = Integer.parseInt(sc.next());
        int[] cost = new int[n];
        int[] time = new int[n];
        for (int i = 0; i < n; i++) {
            cost[i] = Integer.parseInt(sc.next());
            time[i] = Integer.parseInt(sc.next());
        }
        int ans = Integer.MAX_VALUE;
        for (int i = 0; i < n; i++) {
            if (time[i] <= t) {
                if (cost[i] < ans) {
                    ans = cost[i];
                }
            }
        }
        if (ans == Integer.MAX_VALUE) {
            System.out.println("TLE");
        } else {
            System.out.println(ans);
        }
    }
}


Measured memory_bytes: 23124
#!/usr/bin/env python3
import sys
import collections

sys.setrecursionlimit(10 ** 7)

# 1 ✕ 1 (int)
N = int(input().rstrip())

# N ✕ M
A = list(tuple(map(int, input().rstrip().split())) for _ in range(N))

array = []
for s, t in A:
    array.append((s + t, s - t))

array.sort()
# print(array)

ans = 0
t = -1e9
for e, s in array:
    if t <= s:
        t = e
        ans += 1

print(ans)


Measured memory_bytes: 30808
#include<bits/stdc++.h>
#define vi vector<int>
#define pp pair<int,int>
#define all(x) x.begin(),x.end()
#define pb push_back
#define forx(i,x) for(int i=0;i<x;i++)
using namespace std;
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	int x,y;
	cin>>x>>y;
	cout<<x+y/2<<endl;


}


Measured memory_bytes: 256
# Aizu Problem 0186: Aizu Chicken
#
import sys, math, os, bisect

# read input:
PYDEV = os.environ.get('PYDEV')
if PYDEV=="True":
    sys.stdin = open("sample-input.txt", "rt")


def aizu_chicken(q1, b, c1, c2, q2):
    for i in range(q2, 0, -1):
        cj = i * c1
        normal = int((b - cj) // c2)
        if i + normal < q1:
            continue
        elif normal >= 0:
            print(i, normal)
            break
    else:
        print("NA")


while True:
    inp = [int(_) for _ in input().split()]
    if len(inp) == 1:
        break
    q1, b, c1, c2, q2 = inp[:]
    aizu_chicken(q1, b, c1, c2, q2)

Measured memory_bytes: 7700
#include<bits/stdc++.h>
#include<math.h>
using namespace std;
#define ll long long
// GCD of 'a' and 'b' 
int main()
{
	int n; cin>>n;
	int a[n];
	int mn=INT_MAX;
	int mx=INT_MIN;
	for(int i=0;i<n;i++)    
	{
		cin>>a[i];
		mn=min(mn,a[i]);
		mx=max(mx,a[i]);
	}
	
	int cur=INT_MAX;
	int ans;
	for(int i=1;i<=mx;i++)
	{
		int cor=i;
		int score=0;
		for(int j=0;j<n;j++)
		{
			int u=abs(cor-a[j]);
			u*=u;
			score+=u;
		}
		if(score<cur)
		{
			cur=score;
			ans=i;
		}
	}
	cout<<cur;

			
	
		
	
	
}
	

Measured memory_bytes: 256
import sys
from collections import deque


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


def main():
    N = int(input())
    edge = [[] for _ in range(N + 1)]
    for i in range(N - 1):
        u, v, w = map(int, input().split())
        edge[u].append((v, w))
        edge[v].append((u, w))

    color = [False] * (N + 1)
    color[1] = 0
    q = deque([1])
    pass
    while q:
        u= q.popleft()
        c1 = color[u]
        for c,w in edge[u]:
            if color[c] is False:
                q.append(c)
                color[c] = (c1+w)%2

    color.pop(0)
    print(*color)

if __name__ == "__main__":
    main()


Measured memory_bytes: 96112
#include <iostream>

using namespace std;

typedef struct {
	int x;
	int y;
} Point;

int main()
{
	Point p1, p2, p3, p4;
	cin >> p1.x >> p1.y >> p2.x >> p2.y;

	Point d = { p2.x - p1.x, p2.y - p1.y };
	bool dx[4] = { true, true, false, false }, dy[4] = { false, true, true, false };
	
	int i;
	if (d.x > 0) {
		if (d.y > 0) {
			i = 0;
		}
		else {
			i = 1;
		}
	}
	else {
		if (d.y > 0) {
			i = 2;
		}
		else {
			i = 3;
		}
	}

	if (d.x < 0) {
		d.x = -d.x;
	}
	if (d.y < 0) {
		d.y = -d.y;
	}

	switch (i % 4) {
	case 0:
		p3.x = p2.x - d.y;
		p3.y = p2.y + d.x;
		p4.x = p3.x - d.x;
		p4.y = p3.y - d.y;
		break;
	case 1:
		p3.x = p2.x + d.y;
		p3.y = p2.y + d.x;
		p4.x = p3.x - d.x;
		p4.y = p3.y + d.y;
		break;
	case 2:
		p3.x = p2.x - d.y;
		p3.y = p2.y - d.x;
		p4.x = p3.x + d.x;
		p4.y = p3.y - d.y;
		break;
	case 3:
		p3.x = p2.x + d.y;
		p3.y = p2.y - d.x;
		p4.x = p3.x + d.x;
		p4.y = p3.y + d.y;
		break;
	}
	printf("%d %d %d %d\n", p3.x, p3.y, p4.x, p4.y);

	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
 
int main()
{
  //int A, B, C, X, Y;
//  int m[101]={};
  long long min=0;
  int   A, B, C, K;
  long long a[10001]={};
  long long sub[10001]={};
  int i,j,k;
  int flag=0;
  int tmp=0;
  int cnt =0;
  int next_cnt = 0;
  int tmp_cnt =0;
  int tmp_next_cnt = 0;

//    int k=0;

  scanf("%d", &A);
  //printf("%d\n", A);

 for(i=0;i<A;i++){
  scanf("%lld", &a[i]);
  }

i=0;
//  printf("cnt = %d  ", cnt);
   flag = 0;
   while (1){
   if( (a[i] % 2 == 0)){
     a[i] = a[i]/2;
     cnt++;
     } else {
     i++;
     }
     if(i==A) break;
   }
//  printf("%d  \n", a[i]);
//  printf("%d\n", cnt);

  printf("%d\n", cnt);
return 0;
}


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

using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, t) for (int i = (s); i < (int)(t); i++)
typedef long long ll;
const ll mod = 1e9 + 7;

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

    vector<string> ans(H, "");
    vector<int> DH{-1, 0, 1};
    vector<int> DW{-1, 0, 1};
    rep(i, H) {
        rep(j, W) {
            if (m[i][j] == '#') {
                ans[i] += '#';
                continue;
            }
            int cnt = 0;
            for (int &dh: DH) {
                for (int &dw: DW) {
                    if (dh == 0 && dw == 0) {
                        continue;
                    }
                    if (i + dh < 0 || i + dh >= H || j + dw < 0 || j + dw >= W) {
                        continue;
                    }
                    if (m[i + dh][j + dw] == '#') {
                        cnt++;
                    }
                }
            }
            ans[i] += to_string(cnt);
        }
    }
    rep(i, H) {
        cout << ans[i] << endl;
    }

}

Measured memory_bytes: 256
import sys
inp = sys.stdin.readline

N, M = map(int,inp().split())
AB = sorted([list(map(int,inp().split())) for _ in range(N)], key = lambda x: x[0])

money = 0
for a, b in AB:
  if(M < 0):
    break
  if(b <= M):
    money += b*a
    M -= b
  else:
    money += M*a
    M -= b
print(money)

Measured memory_bytes: 29836
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <array>
#include <vector>
#include <functional>
using namespace std;

int main(void) {
	long long a, b, c, d;
	cin >> a >> b >> c >> d;
	cout << max(a*b, c*d) << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <algorithm>
#include <bitset>
#include <tuple>
#include <set>
#define range(i, r) for(int i=0;i<r;i++)
#define ranges(i, l, r) for(int i=l;i<r;i++)
#define vv(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define vvi std::vector<std::vector<int> >
#define vvl std::vector<std::vector<ll> >
#define MODs 1000000007;
#define MODn 1000000009;
typedef long long int ll;
using namespace std;

int main(int argc, char const *argv[]) {
  ll N;
  std::cin >> N;
  std::vector<ll> s(N);
  range(i, N) std::cin >> s[i];
  vvl dp = vv(N, 0, 0, ll);
  for(int i=1;i<N;i++){
    dp[i].push_back(0);
  }
  for(int i=1;i<N;i++){
    for(int j=1;j*i<N-1;j++){
      dp[i].push_back(dp[i][j-1]+s[N-1-j*i] + s[j*i]);
    }
  }
  ll ans = 0;
  for(int i=1;i<N;i++){
    for(int j=1;j<dp[i].size();j++) {
      if((N-1 - i*j)%i==0 && i*j>=(N-1 - i*j)) continue;
      if(i >= (N-1-i*j)) continue;
      //std::cout << dp[i][j];
      ans = max(ans, dp[i][j]);
    }
    //std::cout << '\n';
  }
  std::cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 17268
# AOJ ITP2_7_A: Set: Search
# Python3 2018.6.24 bal4u

tbl = set()
q = int(input())
for i in range(q):
	a = input().split()
	x = int(a[1])
	if a[0] == '0':
		tbl.add(x)
		print(len(tbl))
	else: print(1 if x in tbl else 0)


Measured memory_bytes: 23356
#include <iostream>
#include <vector>
#include <limits.h>
#include <algorithm>
#include <string>
#include <math.h>
#include <limits.h>
#include <queue>
#include <map>
#include <set>
#include <iomanip>
#include <bitset>
#include <cassert>
#include <random>
#include <functional>
#include <stack>
#include <iomanip>
#include <cassert>
using namespace std;
long long MOD = 1e9 + 7;

vector<long long> A;
vector<long long> S;
int N;
typedef pair<long long, long long> pll;

pll judge(int l, int r) {
	int s = l, e = r;
	while (e - s > 1) {
		int m = (e + s) / 2;
		if (S[m] >= (long double)(S[r] + S[l - 1]) / 2)e = m;
		else s = m;
	}
	long long p1 = 2 * S[e] - S[r] - S[l - 1];
	long long p2 = S[r] + S[l - 1] - 2 * S[s];
	if (p1 < p2) return pll(S[e] - S[l - 1], S[r] - S[e]);
	else return pll(S[e - 1] - S[l - 1], S[r] - S[e - 1]);
}

int main() {
	cin >> N;
	A.resize(N + 1,0);
	S.resize(N + 1,0);
	for (int n = 1; n <= N; n++)cin >> A[n];
	for (int n = 1; n <= N; n++)S[n] = S[n - 1] + A[n];
	long long ans = LLONG_MAX;
	for (int k = 2; k <= N - 2; k++) {
		pll L = judge(1, k);
		long long B = L.first, C = L.second;
		pll R = judge(k + 1, N);
		long long D = R.first, E = R.second;
		ans = min(ans, max(B, max(C, max(D, E))) - min(B, min(C, min(D, E))));
	}
	cout << ans << endl;
	return 0;
}

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

using namespace std;

int main(){
  int n;
  std::cin >> n;

  vector<int> L(n);
  for(int i=0; i<n; i++){
    std::cin >> L[i];
  }

  sort(L.begin(), L.end(), greater<int>());

  int sum = 0;
  for(int i=1; i<n; i++){
    sum += L[i];
  }

  if( sum > L[0] ) std::cout << "Yes" << '\n';
  else std::cout << "No" << '\n';
  return 0;
}


Measured memory_bytes: 504
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back

using namespace std;
const long long MOD = (long long)1e9 + 7;

long long gcd(long long x, long long y)
{
	if (y) return gcd(y, x%y);
	else return x;
}

long long a, b, c, d, t1, t2, t3, s1;

int main()
{
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin >> a >> b >> c >> d;
	a--;
	t1 = a / c; t2 = a / d;
	t3 = a / (c*d / gcd(c, d));
	s1 = a - t1 - t2 + t3;
	a = b;
	t1 = a / c; t2 = a / d;
	t3 = a / (c*d / gcd(c, d));
	s1 = a - t1 - t2 + t3 - s1;
	cout << s1;
	//system("pause");
	return 0;
}

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

int main() {
    long N;
    cin>>N;
    int rootN = pow(N, 0.5);
    long ans = __LONG_MAX__;
    REP(i, 1, rootN+1){
        if(N%i == 0){
            if(ans > i + N/i) ans = i + N/i;
        }
    }
    ans -= 2;
    cout << ans << endl;
}

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

vector<int> check_string_contains_AC(string str)
{
	string AC = "AC";
	vector<int> string_contains_AC(str.size(), 0);

	for (int i = 0; i < str.size() - AC.size() + 1; i++) {
		if (str.substr(i, AC.size()) == AC) {
			string_contains_AC[i+1] = string_contains_AC[i] + 1;
		}
		else {
			string_contains_AC[i + 1] = string_contains_AC[i];
		}
	}

	return string_contains_AC;
}

int main(void)
{
	int N, Q;
	string S;
	vector<int> l, r;

	cin >> N >> Q;
	cin >> S;
	for (int i = 0; i < Q; i++) {
		int l_tmp, r_tmp;
		cin >> l_tmp >> r_tmp;
		l.push_back(l_tmp);
		r.push_back(r_tmp);
	}

	vector<int> string_contains_AC = check_string_contains_AC(S);
	/*
	for (int i = 0; i < string_contains_AC.size(); i++) {
		cout << string_contains_AC[i];
	}
	cout << endl;
	*/

	for (int i = 0; i < Q; i++) {
		cout << string_contains_AC[r[i] - 1] - string_contains_AC[l[i] - 1] << endl;
	}

	return 0;
}

Measured memory_bytes: 2420
import java.io.*;
import java.util.Scanner;
public class Main{
    public static void main(String[] args){
        Scanner sc= new Scanner(System.in);
        int w=sc.nextInt();
        int n=sc.nextInt();
        int amida[]=new int[w];
        for (int i=0;i<w;i++){
            amida[i]=i+1;
        }
        sc.nextLine();
        for (int i=0;i<n;i++){
            String s=sc.nextLine();
            Scanner kb=new Scanner(s);
            int count=0;
            String snum[]={"", ""};
            int num[]={0, 0};
            for (int j=0;j<s.length();j++){
                if (s.charAt(j)==','){
                    count++;
                }
                else{
                    snum[count]+=s.charAt(j);
                }
            }
            for (int j=0;j<2;j++){
                for (int k=0;k<snum[j].length();k++){
                    num[j]+=(snum[j].charAt(k)-'0')*Math.pow(10, snum[j].length()-k-1);
                }
            }
            int hoge=amida[num[0]-1];
            amida[num[0]-1]=amida[num[1]-1];
            amida[num[1]-1]=hoge;
        }

        for (int i=0;i<w;i++){
            System.out.println(amida[i]);
        }
    }
}

Measured memory_bytes: 26032
#include<stdio.h>
#include<string.h>
int main(void)
{
  double n;
  int u,i;
  char d[15];
  for(;;){
    scanf("%lf", &n); if(n<0)break; 
    u=(int)n;
    n-=u;
    strcpy(d,"00000000.0000");
    if(u>255)strcpy(d,"NA");
    else{
      for(i=7;i>=0;i--){
        d[i]+=u%2;
        u/=2;
      }
      for(i=9;n!=0;i++){
        d[i]+=(int)(n*2);
        n*=2;
        if(n>=1){
          n-=1;
        }
        if(i>12){
          strcpy(d,"NA");
          break;
        }
      }
    } 
    puts(d);
  }
  return 0;
}

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

int cmpnum(const void * n1, const void * n2)
{
	if (*(long *)n1 > *(long *)n2)
	{
		return 1;
	}
	else if (*(long *)n1 < *(long *)n2)
	{
		return -1;
	}
	else
	{
		return 0;
	}
}

int main(void){

  long n;
  scanf("%ld", &n);
  long a[n], b[n], c[n];
  for (long i = 0; i < n; i++) {
    scanf("%ld", &a[i]);
  }
  for (long i = 0; i < n; i++) {
    scanf("%ld", &b[i]);
  }
  for (long i = 0; i < n; i++) {
    scanf("%ld", &c[i]);
  }
  qsort(a, n, sizeof(long), cmpnum);
  qsort(b, n, sizeof(long), cmpnum);
  qsort(c, n, sizeof(long), cmpnum);

  long a_b[n];
  long mark_a = 0;
  for (long i = 0; i < n; i++) {
    while (mark_a < n) {
      if (a[mark_a] >= b[i]) {
        a_b[i] = mark_a;
        break;
      } else {
        mark_a++;
      }
    }
    if (mark_a == n) {
      a_b[i] = n;
    }
  }

  long a_b_c[n];
  long mark_b = 0;
  long sum = 0;
  for (long i = 0; i < n; i++) {
    a_b_c[i] = sum;
    while (mark_b < n) {
      if (b[mark_b] >= c[i]) {
        break;
      } else {
        a_b_c[i] += a_b[mark_b];
        sum = a_b_c[i];
        mark_b++;
      }
    }
    if (mark_b == n) {
      a_b_c[i] = sum;
    }
  }
  sum = 0;
  for (long i = 0; i < n; i++) {
    sum += a_b_c[i];
  }
  printf("%ld\n", sum);

  return 0;
}

Measured memory_bytes: 4848
#include<iostream>
#include<string>
#include<vector>
using namespace std;

int main() {
    string s;
    cin >> s;
    vector<bool> pos(s.length() + 1, false);
    pos.front() = true;
    for (int i=1; i<=s.length(); i++) {
        pos[i] = (i >= 5 and pos[i - 5] and s.substr(i - 5, 5) == "erase")
              or (i >= 5 and pos[i - 5] and s.substr(i - 5, 5) == "dream")
              or (i >= 6 and pos[i - 6] and s.substr(i - 6, 6) == "eraser")
              or (i >= 7 and pos[i - 7] and s.substr(i - 7, 7) == "dreamer");
    }
    cout << (pos[s.length()] ? "YES" : "NO") << endl;
    return 0;
}

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

#define each(i, c) for (auto& i : c)
#define mkp(a, b) make_pair(a, b)

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> Pll;
const ll MOD = 1e9+7;

template<typename P, typename Q> ostream& operator << (ostream& os, pair<P, Q> p) { os << "(" << p.first << ": " << p.second << ")"; return os; }
template<typename T> ostream& operator << (ostream& os, vector<T> v) { os << "("; each (i, v) os << i << ", "; os << ")"; return os; }
template<typename K, typename V> ostream& operator << (ostream& os, map<K, V> m) { os << "{"; each (i, m) os << i << ", "; os << "}"; return os; }

int main() {
  ll r, g, b, n;
  cin >> r >> g >> b >> n;

  ll ans = 0;
  for (ll i = 0; i <= n/r; ++i) {
    for (ll j = 0; j <= n/g; ++j) {
      ll k = n - (i*r + j*g);
      if (k >= 0 && k%b == 0) ++ans;
    }
  }

  cout << ans << endl;

  return 0;
}


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

using ll = long long;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  int d;
  cin >> d;
  
  vector<int> c(26);
  for (int i = 0; i < 26; i++) cin >> c.at(i);
  
  vector<vector<ll>> s(d, vector<ll>(26));
  for (int i = 0; i < d; i++) {
    for (int j = 0; j < 26; j++) {
      cin >> s.at(i).at(j);
    }
  }
  
  vector<int> t(d);
  for (int i = 0; i < d; i++) {
    cin >> t.at(i);
    t.at(i)--;
  }
  
  vector<int> last(26, 0);
  ll suff = 0;
  for (int i = 1; i <= d; i++) {
    suff += s.at(i - 1).at(t.at(i - 1));
    last.at(t.at(i - 1)) = i;
    for (int j = 0; j < 26; j++) {
      suff -= c.at(j) * (i - last.at(j));
    }
    cout << suff << '\n';
  }
}

Measured memory_bytes: 3676
#include <bits/stdc++.h>
using namespace std;  
typedef long long ll;
typedef vector<ll> vint;
int main() {
  ll x,y,z,k;
  cin >> x>>y>>z>>k;
  vint A(x),B(y),C(z);
  for (ll i=0;i<x;i++) cin >> A.at(i);
  for (ll i=0;i<y;i++) cin >> B.at(i);
  for (ll i=0;i<z;i++) cin >> C.at(i);
  
  sort(A.begin(),A.end());
  sort(B.begin(),B.end());
  sort(C.begin(),C.end());
  reverse(A.begin(),A.end());
  reverse(B.begin(),B.end());
  reverse(C.begin(),C.end());
  
  vint f(x*y);
  for (ll i=0;i<y;i++) {
    for (ll j=0;j<x;j++) {
      f.at(x*i+j)= A.at(j)+B.at(i);
    }
  }
  
  sort(f.begin(),f.end());
  reverse(f.begin(),f.end());
  
  ll r = min(k,x*y);
  
  vint g(r*z);
  for (ll i=0;i<r;i++) {
    for (ll j=0;j<z;j++) {
      g.at(z*i+j)= f.at(i)+C.at(j);
    }
  }     
  sort(g.begin(),g.end());
  reverse(g.begin(),g.end());
  
  for (ll i=0;i<k;i++) {
    cout << g.at(i) << endl;
  }
}

Measured memory_bytes: 31616
import java.util.*;

class Main {
    public static void main(String[] args) {
	Scanner s = new Scanner(System.in);
	double ep = 0.0;
	while(s.hasNext()) {
	    double[] d = new double[8];
	    for(int i=0 ; i<8 ; i++)
		d[i] = s.nextDouble();
	    double a = (d[3]-d[1])*(d[7]-d[5]) + (d[2]-d[0])*(d[6]-d[4]);
	    String ans;
	    if(a == 0)
		ans = "YES";
	    else
		ans = "NO";
	    System.out.println(ans);
	}
    }
}

Measured memory_bytes: 12000
import java.io._
import java.util.StringTokenizer
import scala.util.control.Breaks.{breakable,break}
import scala.collection.mutable.{Map, Stack, Queue, PriorityQueue, Set}

object Main extends App {
  val in = new InputReader(System.in)
  val pw = new PrintWriter(System.out)

  val N, P = in.next().toInt
  val S = in.next()

  //
  if (P == 2 || P == 5) {
    var ans = 0L
    for (i <- (0 until N).reverse) {
      val c = S(i)
      val n = c.toString.toInt

      if (n % P == 0)
        ans += i + 1
    }

    println(ans)
  }
  else {
    val dp = new Array[Long](N+1)
    var base = 1L
    var acc = 0L
    for (i <- (0 until N).reverse) {
      val c = S(i)
      val n = c.toString.toInt

      acc += n * base
      acc %= P

      dp(i) = acc

      base *= 10
      base %= P
    }

    val hash = Map[Long, Long]()
    for (i <- 0 until N) {
      val now = dp(i)
      if (!hash.contains(now))
        hash += (now -> 1)
      else
        hash(now) += 1
    }

    var ans = 0L
    for ((k, v) <- hash) {
      ans += (v * (v - 1)) / 2
      if (k == 0)
        ans += v
    }

    println(ans)
  }
}

object Sub {
  def print2DimArray[A](mat: Array[Array[A]]): Unit = {
    mat.foreach(lin => println(lin.toList))
  }
}

class InputReader(stream: InputStream) {
  private[this] val reader = new BufferedReader(new InputStreamReader(stream))
  private[this] var tokenizer: StringTokenizer = new StringTokenizer(reader.readLine())
  def next(): String = {
    while (!tokenizer.hasMoreTokens()) {
      tokenizer = new StringTokenizer(reader.readLine())
    }
    tokenizer.nextToken()
  }
}


Measured memory_bytes: 59328
#include <bits/stdc++.h>
#include <cassert>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define ok() puts(ok?"Yes":"No");
#define chmax(x,y) x = max(x,y)
#define chmin(x,y) x = min(x,y)
using namespace std;
using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using ii = pair<int, int>;
using vvi = vector<vi>;
using vii = vector<ii>;
using gt = greater<int>;
using minq = priority_queue<int, vector<int>, gt>;
using P = pair<ll,ll>;
const ll LINF = 1e18L + 1;
const int INF = 1e9 + 1;
//clang++ -std=c++11 -stdlib=libc++ 

int main() {
  ll n; cin >> n;
  vector<ll> a(n);
  rep(i,n) cin>>a[i];
  ll ans = LINF;
  
  // even is positive
  // odd is nevgative
  ll sum=0;
  ll num=0;
  rep(i,n) {
    sum+=a[i];
    if (i&1) {
      if (sum>=0) {
        num += (sum + 1);
        sum = -1;
      }
    } else {
      if (sum <= 0) {
        num += (-sum + 1);
        sum = 1;
      }
    }
  }
  chmin(ans, num);
  // even is negative
  // odd is positive
  num = 0;
  sum = 0;
  rep(i,n) {
    sum+=a[i];
    if (i&1) {
      if (sum <= 0) {
        num += (-sum + 1);
        sum = 1;
      }
    } else {
      if (sum>=0) {
        num += (sum + 1);
        sum = -1;
      }
    }
  }
  chmin(ans, num);
  printf("%lld\n", ans);
  return 0;
}

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

int main(void)
{
    int n;
    scanf("%d", &n);

    long* arr = calloc(n, sizeof(long));

    for (int i = 0; i < n; i++) {
        scanf("%ld", &arr[i]);
    }

    for (int i = n - 1; i > 0; i--) {
        if (arr[i] == arr[i - 1] - 1) {
            arr[i - 1]--;
        }

        if (arr[i] < arr[i - 1]) {
            printf("No");
            free(arr);
            return 0;
        }
    }

    printf("Yes");

    free(arr);
    return 0;
}


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

int main() {
  int N, M;
  cin >> N >> M;
  vector<string> A(N), B(M);
  for (int i = 0; i < N; i++) cin >> A[i];
  for (int i = 0; i < M; i++) cin >> B[i];

  for (int i = 0; i < N - M + 1; i++) {
    for (int j = 0; j < N - M + 1; j++) {
      bool f = true;
      for (int k = 0; k < M; k++) {
        if (A[i + k].substr(j, M) != B[k]) f = false;
      }
      if (f) {
        cout << "Yes" << endl;
        return 0;
      }
    }
  }
  cout << "No" << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define NL            "\n"
#define _SAD()        ios::sync_with_stdio(0),cin.tie(0), cout.tie(0);
#define SZ(s)         s.size()
#define SRT(x,y)      sort(x,x+y)
#define REV(a,b)      reverse(a,a+b)
#define VSRT(x)       sort(x.begin(),x.end())
#define VREV(x)       reverse(x.begin(),x.end())
int main()
{
    _SAD()
    int m1,d1,m2,d2;
    cin>>m1>>d1>>m2>>d2;
    if(((m1==4||m1==6||m1==9||m1==11)&&d1==30)||(m1==2&&d1==28)||((m1==1||m1==3||m1==5||m1==7||m1==8||m1==10||m1==12)&&d1==31))
    {
        cout<<"1"<<NL;
    }
    else
    {
        cout<<"0"<<NL;
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include<algorithm>
#include<string>
#include <cmath>
#include <vector>
#include <map>
#include <cstdio>
#include <iomanip>
#include<set>
#include <numeric>
#pragma region Macros
#define int long long
#define double long double
constexpr int MOD = 1000000007;
constexpr double PI = 3.14159265358979323846;
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<=n;i++)
#define LAST(x) x[x.size()-1]
#define ALL(x) (x).begin(),(x).end()
#define swap(a,b) (a += b,b = a - b,a -= b)
#define DIVCEIL(a,b) ((a+b-1)/b)
//int CHMAX

int FACT(int a) {
	if (a == 0)
		return 1;
	else
		return a * FACT(a - 1);
}
int MODFACT(int a, int mod) {
	if (a == 0)
		return 1;
	else
		return (a * FACT(a - 1))%mod;
}
int nPr(int n, int r) {
	int s = n - r + 1;
	int sum = 1;
	for (int i = s; i <= n; i++)
		sum *= i;
	return sum;
}
int MODnPr(int n, int r, int mod) {
	int s = n - r + 1;
	int sum = 1;
	for (int i = s; i <= n; i++) {
		sum *= i;
		sum = sum % MOD;
	}
	return sum;
}
//int nCr(int n, int r)
int nCr2(int n, int r) {
	return FACT(n) / (FACT(r) * FACT(n - r));
}
int GCD(int a, int b)
{
	if (a < b)
		swap(a, b);
	if (b == 0)
		return a;
	if (a % b == 0)
		return b;
	return GCD(b, a % b);
}
int LCM(int a, int b)
{
	return  a * b / GCD(a, b);
}
int NUMOFDIV(int n) {
	int ans = 0;
	REP(i, n) {
		if (n % i == 0)
			ans++;
	}
	return ans;
}
int CEIL1(int n) {
	return (n + 9) / 10 * 10;
}
int DIGITSUM(int n) {
	int sum = 0, dig;
	while (n) {
		dig = n % 10;
		sum += dig;
		n /= 10;
	}
	return sum;
}
int DIVTIME(int n, int k) {
	int div = 0;
	while (n % k == 0) {
		div++;
		n /= k;
	}
	return div;
}
int MODPOW(int a, int n, int mod) {
	// a^n mod
	int ans = 1;
	while (n > 0) {
		if (n & 1)
			ans = ans * a % mod;
		a = a * a % mod;
		n >>= 1;
	}
	return ans;
}
double LOG(int a, int b) {
	return log(b) / log(a);
}
inline bool BETWEEN(int x, int min, int max) {
	if (min <= x && x <= max)
		return true;
	else
		return false;
}
inline bool PRIMEOR(int x) {
	if (x == 1)
		return false;
	if (x == 2)
		return true;
	if (x % 2 == 0)
		return false;
	double sqrtx = sqrt(x);
	for (int i = 3; i <= sqrtx; i += 2) {
		if (x % i == 0)
			return false;
	}
	return true;
}
bool SQRTOR(int n) {
	if (sqrt(n) == (int)sqrt(n))
		return true;
	else
		return false;
}
// 順位付け
using namespace std;
#pragma endregion
signed main() {
	int a, b;
	cin >> a >> b;
	a--;
	b--;
	cout << DIVCEIL(b, a);
}

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

using namespace std;

typedef uint64_t u64;
typedef int64_t s64;
typedef uint32_t u32;
typedef int32_t s32;
typedef vector<s32> vs32;
typedef vector<u32> vu32;
typedef vector<s64> vs64;
typedef vector<u64> vu64;

const double PI=3.14159265358979323846;

#define MAX(x, y) ((x) < (y) ? (y) : (x))
#define MIN(x, y) ((x) > (y) ? (y) : (x))

#define rep(i, N) for(int i = 0; i < N; ++i)

#define CEIL(x, y) (((x) + (y) - 1) / (y))
#define MOD 1000000007ULL


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

    s64 n, m;
    cin >> n >> m;

    vs64 s(n + 1);
    s[0] = 0;
    s64 a;
    rep (i, n)
    {
        cin >> a;
        s[i + 1] = s[i] + a;
    }

    map<s64, s64> cnt;
    rep (i, n + 1)
    {
        ++cnt[s[i] % m];
    }

    s64 ans = 0;
    for (auto a : cnt)
    {
        ans += a.second * (a.second - 1) / 2;
    }

    cout << ans << "\n";
    return 0;
}



Measured memory_bytes: 4992
#include <iostream>

using namespace std;

int main()
{
  	int X, Y, Z;
  	cin >> X >> Y >> Z;
  	X -= Z;
  	int ans = 0;
  	while(X - (Y+Z) >= 0){
      	X -= Y+Z;
      	ans++;
    }
  	cout << ans;
  	return 0;
}

Measured memory_bytes: 256