akhauriyash/Code-Regression huggingface dataset:
//#pragma once
#include <stdio.h>
#include <string>
#include <iostream>
#include <queue>
#include <algorithm>
#include <sstream>
#include <vector>
#include <math.h>
#include <set>
#include <map>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cctype>


using namespace std;
#define modd 1000000007


typedef pair<long long, long long> pl;


typedef string::const_iterator State;
class ParseError {};




#define ll long long




class UnionFind {
public:
	vector <ll> par;
	vector <ll> siz;

	// Constructor
	UnionFind(ll sz_) : par(sz_), siz(sz_, 1LL){
		for (ll i = 0; i < sz_; ++i) par[i] = i;
	}
	void init(ll sz_) {
		par.resize(sz_);
		siz.assign(sz_, 1LL);  // resize だとなぜか初期化されなかった
		for (ll i = 0; i < sz_; ++i) par[i] = i; // 初期では親は自分自身
	}

	// Member Function
	// Find
	ll root(ll x) { // 根の検索
		while (par[x] != x) {
			x = par[x] = par[par[x]]; // x の親の親を x の親とする
		}
		return x;
	}

	// Union(Unite, Merge)
	bool merge(ll x, ll y) {
		x = root(x);
		y = root(y);
		if (x == y) return false;

		// merge technique（データ構造をマージするテク．小を大にくっつける）
		if (siz[x] < siz[y]) swap(x, y);
		siz[x] += siz[y];
		par[y] = x;
		return true;
	}



	bool issame(ll x, ll y) { // 連結判定
		return root(x) == root(y);
	}

	ll size(ll x) { // 素集合のサイズ
		return siz[root(x)];
	}


};


long long N, M, K, a, b, c, d, e, H, W, L;
ll A[2][200005] = {};
ll B[100005] = {};
ll C[300005] = {};
bool f, ff;
string S,T;
set <long long>sll;
pl bufpl;
vector <long long>vl[2][100005];
vector <long long>vll[100005];
vector <pl>vpl;
vector <string> vs;
set<ll> llset;
multiset<ll> llmset;


/*
struct ST
{
	long long Kati;
	int bangou;

	bool operator<(const ST& another) const
	{
		return Kati < another.Kati;//比較
	};

};



/*vector <ST> vst;
ST st[200005];
ST bufst;
bitset<5000> bits;*/


long long modinv(long long aa, long long mm) {
	long long bb = mm, uu = 1, vv = 0;
	while (bb) {
		long long tt = aa / bb;
		aa -= tt * bb; swap(aa, bb);
		uu -= tt * vv; swap(uu, vv);
	}
	uu %= mm;
	if (uu < 0) uu += mm;
	return uu;
}



ll minn, maxx;
double ansa;
bool fl[30] = {};



string ss, sss;


int main() {


	cin >> N;

	UnionFind uf(N);

	for (ll i = 0; i < N; i++) {
		cin >> A[0][i] >> A[1][i];
		a = A[0][i];
		b = A[1][i];

		if (!vl[0][a].empty()) {
			uf.merge(i, vl[0][a][0]);
		}

		if (!vl[1][b].empty()) {
			uf.merge(i, vl[1][b][0]);
		}

		vl[0][a].push_back(i);
		vl[1][b].push_back(i);


	}

	for (ll i = 0; i < N; i++) {
		vll[uf.root(i)].push_back(i);

	}
	e = 0;
	for (ll i = 0; i < 100001; i++) {
		if (vll[i].size() >= 3) {
			a = 0;
			b = 0;
			bool fu[2][100001] = {};
			for (int j = 0; j < vll[i].size(); j++) {
				c = A[0][vll[i][j]];
				d = A[1][vll[i][j]];
				if (fu[0][c] == false) {
					a++;
					fu[0][c] = true;
				}

				if (fu[1][d] == false) {
					b++;
					fu[1][d] = true;
				}

			}

			e += a * b - vll[i].size();

		}

	}

	cout << e << endl;
	return 0;

}


Measured memory_bytes: 19328
#include <bits/stdc++.h>
#define ALL(A) (A).begin(),(A).end()
#define ll long long
#define rep(i,n) for(int i=0;i<(n);i++)

const ll mod = 1e9+7;
const ll INF = -1*((1LL<<63)+1);
const int inf = -1*((1<<31)+1);

using namespace std;

vector<ll> dp(2e5+1);
vector<ll> r(3e5+1);
int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<fixed<<setprecision(20);
    int N;
    cin >> N ;
    vector<ll> a(3*N);
    rep(i,3*N)cin >> a[i];
    vector<ll> v;
    map<int,int> mp;
    for(int i=0;i<N;i++){
        mp[a[i]]++;
        if(i==0)dp[i] = a[i];
        else dp[i] = dp[i-1] + a[i];
    }
    for(int i=N;i<N+N;i++){
        mp[a[i]]++;
        dp[i] = dp[i-1] + a[i] - mp.begin()->first;
        mp.begin()->second--;
        if(mp.begin()->second ==0)mp.erase(mp.begin());
    }
    priority_queue <int> pq;
    for(int i=3*N-1;i>=2*N;i--){
        pq.push(a[i]);
        r[i] = r[i+1] + a[i];
    }
    for(int i=2*N-1;i>=N;i--){
        pq.push(a[i]);
        r[i] = r[i+1] + a[i] - pq.top();
        pq.pop();
    }
    ll ans = -1e18;
    for(int i=N-1;i<2*N;i++){
        ans = max(ans,dp[i] - r[i+1]);
    }
    cout << ans << endl;
}


Measured memory_bytes: 11904
#include <algorithm>
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <string>
#include <sstream>
#include <vector>
#include <set>
using namespace std;


int main()
{
	int n;
	cin>>n;
	if( n % 2 ==0 ){
		cout << ( n /2 )*(n / 2) <<endl;
	}else{
		cout << ((n - 1)/2) * ((n + 1)/2) <<endl;
	}
	
	return 0;
}




Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <string>
#include <cmath>
#include <cstdio>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <functional>
#include <numeric>
#include <iomanip>
 
using namespace std;
typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
 
#define REP(i,n) for(int i = 0; i < (int)(n); ++i)
#define FOR(i,a,b) for(int i = (a); i < (int)(b); ++i)
#define ALL(c) (c).begin(), (c).end()
#define SIZE(v) ((int)v.size())
 
#define pb push_back
#define mp make_pair
#define mt make_tuple
 
int main(void)
{
    cin.sync_with_stdio(false);
    int N, M;
    cin >> N >> M;
    vector<set<int>> edges(N);
    REP(m,M) {
        int a, b;
        cin >> a >> b;
        --a; --b;
        edges[a].insert(b);
        edges[b].insert(a);
    }
    vector<int> order(N-1);
    REP(n,N-1) order[n] = n+1;
    int ans = 0;
    do {
        int cur = 0;
        bool ok = true;
        for(auto e: order) {
            if (edges[cur].count(e)) {
                cur = e;
            }
            else {
                ok = false;
                break;
            }
        }
        ans += ok;
    } while(next_permutation(ALL(order)));
    cout << ans << endl;
    
    return 0;
}


Measured memory_bytes: 888
#include<bits/stdc++.h>
#include<unordered_set>
#include<unordered_map>
using namespace std;
#define REP(i,m,n) for(int i=(m);i<(n);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define all(a) a.begin(),a.end()
#define rall(c) (c).rbegin(),(c).rend()
#define mp make_pair
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef long double ld;
const ll inf=1e9+7;
ll mod;
//Combination
long long extGCD(long long a,long long mod,long long &x,long long &y){
    if(mod==0){
        x=1;
        y=0;
        return a;
    }
    long long d=extGCD(mod,a%mod,y,x);
    y-=(a/mod)*x;
    return d;
}
long long invmod(long long a,long long mod){
    long long x,y;
    extGCD(a,mod,x,y);
    x%=mod;
    if(x<0)x+=mod;
    return x;
}
ll fac[2000010],finv[2000010],inv[2000010];
void combinit(){
    fac[0]=fac[1]=1;
    finv[0]=finv[1]=1;
    inv[1]=1;
    REP(i,2,2000010){
        fac[i]=fac[i-1]*i%mod;
        inv[i]=invmod(i,mod);
        finv[i]=finv[i-1]*inv[i]%mod;
    }
}
ll comb(ll n,ll k){
    if(n<k)return 0;
    if(n<0||k<0)return 0;
    return fac[n]*(finv[k]*finv[n-k]%mod)%mod;
}
int main(){
    ll n,p;cin>>n>>p;
    mod=p;
    combinit();
    string s;cin>>s;
    if(p==2||p==5){
        ll ans=0;
        rep(i,n){
            ll c=s[i]-'0';
            if(c%p==0)ans+=i+1;
        }
        cout<<ans<<endl;
        return 0;
    }
    vector<ll>a(n);
    a[0]=(s[0]-'0')%p;
    vector<ll>b(p);
    b[a[0]]=1;
    ll ans=0;
    ll now=1;
    ll cnt=0;
    if(a[0]==0)cnt++;
    REP(i,1,n){
        now=now%p*invmod(10%p,p)%p;
        if(now<0)now+=p;
        ll c=(s[i]-'0')%p;
        a[i]=(a[i-1]%p*10%p+c)%p;
        if(a[i]<0)a[i]+=p;
        ll d=a[i]%p*now%p;
        if(d<0)d+=p;
        if(a[i]==0)cnt++;
        ans+=b[d];
        b[d]++;
    }
    cout<<ans+cnt<<endl;
}

Measured memory_bytes: 49028
x, y = map(int, input().split())
a = [300000, 200000, 100000]

if x > 3 and y > 3:
	print(0)
elif x == 1 and y == 1:
	print(1000000)
elif x <= 3 and y <= 3:
	print(a[x-1] + a[y-1])
elif x <= 3 and y > 3:
	print(a[x-1])
elif y <= 3 and x > 3:
	print(a[y-1])

Measured memory_bytes: 3316
x, k, d = gets.chomp.split.map(&:to_i)
cnt = [k, x.abs / d].min
k -= cnt

if x <= 0
  x += cnt * d
  if k % 2 != 0 && k > 0
    x += d
  end
else
  x -= cnt * d
  if k % 2 != 0 && k > 0
    x -= d
  end
end
puts x.abs

Measured memory_bytes: 14360
N, M = map(int, input().split())

bag = {m+1: 0 for m in range(M)}

for n in range(N):
    all_list = list(map(int, input().split()))
    K = all_list[0]
    A = all_list[1:]
    for k in range(K):
        bag[A[k]] += 1

count = 0
for key, value in bag.items():
    if value == N:
        count += 1

print(count)
        

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

typedef long long LL;
typedef pair<int, int> PII;
typedef vector<int> VI;
#define MP make_pair
#define PB push_back
#define X first
#define Y second

#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define RFOR(i, b, a) for(int i = (b) - 1; i >= (a); --i)
#define ALL(a) a.begin(), a.end()
#define SZ(a) (int)((a).size())
#define FILL(a, value) memset(a, value, sizeof(a))
#define debug(a) cout << #a << " = " << a << endl;

const double PI = acos(-1.0);
const LL INF = 1e9 + 47;
const LL LINF = INF * INF;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int main()
{
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	
	LL a, b;
	cin >> a >> b;
	LL n = __gcd(a, b);
	
	int ans = 0;
	for(int i = 2; i * (LL) i <= n; ++i)
		if (n % i == 0)
		{
			ans++;
			while(n % i == 0) n /= i;
		}
		
	if (n > 1) ans++;
	cout << ans + 1 << endl;
	
	cerr << "Time elapsed: " << clock() / (double)CLOCKS_PER_SEC << endl;
	return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <utility>
#include <tuple>
#include <algorithm>
#include <numeric>
#include <cstdio>
#include <cstring>
#include <cmath>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  string s;
  cin >> n >> s;
  if (n%2) {
    cout << "No" << endl;
    return 0;
  }
  rep(i, n/2) {
    if (s[i] != s[i+n/2]) {
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
  return 0;
}

Measured memory_bytes: 256
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <unordered_map>
#include <unordered_set>
#include <map>
#include <set>
using namespace std;

long long M=1000000007;
int main(int argc, char const *argv[]) {
  long long m,n;cin>>m>>n;
  if(abs(m-n)>=2)cout<<"Alice"<<endl;
  else cout<<"Brown"<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
int main(){

	int a,b,c,a0,b0;
	int gcd;
	double lcm;

	for(;scanf("%d %d",&a,&b)!=EOF;){

		a0=a;
		b0=b;

		if(a<b){
			c=a,a=b,b=c;
		}

		gcd=1;
		if(a==0 || b==0){
			gcd=0;
			lcm=0;
		} else {
			while(a%b!=0){
				c=b;
				b=a%b;
				a=c;
			}
			gcd=b;
			lcm=((double)a0*(double)b0)/(double) gcd;
		}
		printf("%d %.f\n",gcd,lcm);
	}

	return 0;
}

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

#define pb push_back
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,n,s) for(int i=(s);i<(n);i++)
#define rrep(i,n) for(int i=(n-1);i>=0;i--)
#define rreps(i,n,s) for(int i=s;i>=n;i--)
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; }

using ll = long long;
using namespace std;
constexpr long long MAX = 5100000;
constexpr long long INF = 1LL << 60;
constexpr int MOD = 1000000007;

int main(){
cin.tie(0);
ios::sync_with_stdio(false);
string s;
cin>>s;
int n=s.size();
ll ans=0;
ll last=n-1;
rrep(i,n){
    if(s[i]=='B'){
        ans+=last-i;
        last--;
    }
}

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

Measured memory_bytes: 720
# -*- coding: utf-8 -*-
import sys
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
input=lambda: sys.stdin.readline().rstrip()
YesNo=lambda b: bool([print('Yes')] if b else print('No'))
YESNO=lambda b: bool([print('YES')] if b else print('NO'))
int1=lambda x:int(x)-1

def main():
    c=[input() for i in range(3)]
    for i in range(3):
        print(c[i][i],end='')

if __name__ == '__main__':
    main()


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

int main() {
	int n; scanf("%d", &n);
	for (int i = 1; i <= n; i++) {
		int x = i;
		if (x % 3 == 0) {
			cout << " " << i;
		}
		else {
			while (x) {
				if (x % 10 == 3) {
					cout << " " << i;
					break;
				}
				x /= 10;
			}
		}
	}
	cout << endl;
}



Measured memory_bytes: 3220
object Main {
  def main(args: Array[String]) {
    val sc = new java.util.Scanner(System.in)
    val n = sc.nextInt()
    val pair = List.fill(n)(sc.next(), sc.next())

    val score = pair.foldLeft((0, 0)) {
      case (score, (input1, input2)) =>
        val seq = Seq(input1, input2)
        if (input1 == input2) (score._1 + 1, score._2 + 1)
        else if (seq.sorted == seq) (score._1, score._2 + 3)
        else (score._1 + 3, score._2)
    }

    println(s"${score._1} ${score._2}")
  }
}

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

using namespace std;
using ll = long long;
using VI = vector<int>;
using VL = vector<ll>;
#define FOR(i, a, n) for(int (i)=(a);(i)<(n);(i)++)
#define eFOR(i, a, n) for(int (i)=(a);(i)<=(n);(i)++)
#define rFOR(i, a, n) for(int (i)=(n)-1;(i)>=(a);(i)--)
#define erFOR(i, a, n) for(int (i)=(n);(i)>=(a);(i)--)
#define SORT(i) sort((i).begin(),(i).end())
#define rSORT(i, a) sort((i).begin(),(i).end(),(a))
#define all(i) (i).begin(),(i).end()
constexpr ll INF = 1000000000;
//constexpr ll LLINF = 1LL << 60;
constexpr ll mod = 1000000007;
constexpr ll MOD = 998244353;

//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;
}

inline void init() {
    cin.tie(nullptr);
    cout.tie(nullptr);
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
}

template<class T>
inline istream &operator>>(istream &input, vector<T> &v) {
    for (auto &elemnt : v)input >> elemnt;
    return input;
}

int main() {
    init();
    int a, b, n;
    cin >> a >> b >> n;

    VI s, f;
    int start = 0;
    FOR(i, start, n) {
        int in, in1;
        cin >> in >> in1;
        s.push_back(in);
        f.push_back(in1);
    }
    s.push_back(a);
    f.push_back(b);
    sort(s.begin(), s.end());
    sort(f.begin(), f.end());

    for(int i=0;i<n;i++){
//        if(f[i] == f.empty() || s[i] == s.empty()){
//            break;
//        }
        if (s[i + 1] < f[i]) {
            cout << 1 << endl;
            return 0;
        } else if (s[i + 1] == s[i]) {
            cout << 1 << endl;
            return 0;
        }
    }
    cout << 0 << endl;
    return 0;
}



Measured memory_bytes: 3164
n,m = map(int,input().split())
card = [0]*n
l,r = 1,n
for i in range(m):
    tmp_l,tmp_r = map(int,input().split())
    if l < tmp_l:
        l=tmp_l
    if r > tmp_r:
        r = tmp_r
ans = 0
if r-l>=0:
    ans = r-l+1
print(ans)

Measured memory_bytes: 3828
import sys
bbn=1000000007
	
#+++++

def modinv(a,m):
	b=m
	u=1
	v=0
	
	while b > 0:
		t = a //b
		a = a - (t * b)
		a,b = b,a
		u = u - (t * v)
		u,v=v,u
	
	u = u % m
	if u < 0:
		u+=m
	return u

def gcd(a,b):
	while b!= 0:
		a,b=b,a%b
		
	return a
		
def main():
	n = int(input())
	al = list(map(int, input().split()))
	
	#saisyoukoubausuu
	ss=1
	for v in al:
		ss = ss * v //gcd(ss,v)
		#ss %= bbn
	
	ss=ss%bbn
	ret=0
	for v in al:
		ret += ss *modinv(v, bbn)
		ret%=bbn
		
	
	print(ret)
	
	
#+++++
isTest=False

def pa(v):
	if isTest:
		print(v)

if __name__ == "__main__":
	if sys.platform =='ios':
		sys.stdin=open('inputFile.txt')
		isTest=True
	else:
		pass
		#input = sys.stdin.readline
			
	ret = main()
	if ret is not None:
		print(ret)

Measured memory_bytes: 42332
import java.util.*;

class Main{
    int L;
    int[] A;

    Main(){
        Scanner SC = new Scanner(System.in);

        String N = SC.next();
        L = N.length();
        A = new int[L+1];
        for(int i=1;i<=L;i++){
            A[i] = N.charAt(i-1) - 48;
        }

        int[][] DP = new int[L+1][2];
        DP[L][0] = A[L];
        DP[L][1] = 10-A[L];
        for(int i=L-1;i>=0;i--){
            DP[i][0] = Math.min(DP[i+1][0]+A[i], DP[i+1][1]+A[i]+1);
            DP[i][1] = Math.min(DP[i+1][0]+10-A[i], DP[i+1][1]+10-(A[i]+1));
        }

        System.out.println(Math.min(DP[0][0], DP[0][1]));
    }

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


Measured memory_bytes: 68584
#include <algorithm>
#include <iostream>
#include <vector>
#include <set>
using namespace std;

int main() {
    set<int> s;
    int q; cin >> q;
    while (q--) {
        int com, x; cin >> com >> x;
        if (com == 0) {
            s.emplace(x);
            cout << s.size() << endl;
        } else if (com == 1) {
            cout << s.count(x) << endl;
        } else if (com == 2) {
            s.erase(x);
        } else if (com == 3) {
            int y; cin >> y;
            auto it = s.lower_bound(x);
            while (it != s.end() && *it <= y) {
                cout << *it << endl;
                it++;
            }
        }
    }
    return 0;
}


Measured memory_bytes: 12464
#include<iostream>
#include<map>
#include<algorithm>

using namespace std;

int main(int argc, char const *argv[])
{
    int d=1000000;
    map<string,int> arl;
long long ans=0;
    cin>>d;

    for (int i = 0; i < d; i++)
    {
        string S;
        cin>>S;
      sort(S.begin(),S.end());

    arl[S]++;

    ans+=arl[S]-1;
        
        
    }
    cout<<ans<<endl;


}


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

long long min(long long a,long long b){
  return a>b? b:a;
}

int main()
{
  long long N,A,B,C,D,E;
  cin>>N>>A>>B>>C>>D>>E;
  long long ans;
  ans=min(A,min(B,min(C,min(D,E))));
  cout<<( (N%ans)? (N-(N%ans))/ans+5:N/ans+4 );
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
typedef long long int ll;
typedef char c;
int main()
{
 ios_base::sync_with_stdio(0);
  cin.tie(0);
  ll x;
  string s,t;
  cin>>s>>t;
  x=s.size();
  ll l=0;
  for(ll i=0;i<x;i++)
  {
    if(s[i]==t[i]);
    else
      l++;
  }
  cout<<l<<"\n";
  return 0;
}  

Measured memory_bytes: 3460
H, W = map(int, input().split())
S = [list(input()) for i in range(H)]

U = [[0] * W for i in range(H)]
D = [[0] * W for i in range(H)]
L = [[0] * W for i in range(H)]
R = [[0] * W for i in range(H)]

for i in range(H):
    for j in range(W):
        if S[i][j] == '.':
            if i == 0:
                U[i][j] = 1
            if i > 0:
                U[i][j] = U[i - 1][j] + 1
            if j == 0:
                L[i][j] = 1
            if j > 0:
                L[i][j] = L[i][j - 1] + 1
                
for i in range(H - 1, -1, -1):
    for j in range(W - 1, -1, -1):
        if S[i][j] == '.':
            if i == H - 1:
                D[i][j] = 1
            if i < H - 1:
                D[i][j] = D[i + 1][j] + 1
            if j == W - 1:
                R[i][j] = 1
            if j < W - 1:
                R[i][j] = R[i][j + 1] + 1                
        
ans = 0
for i in range(H):
    for j in range(W):
        if S[i][j] == '.':
            tmp = U[i][j]  + D[i][j] + L[i][j] + R[i][j] - 3
            ans = max(ans, tmp)
            
print(ans)

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

int a[3005][3005];
ll dp[3005][3005][4];
 
int main() {
  int R, C, n;
  cin >> R >> C >> n;
  rep(i,n) {
    int r, c, v;
    cin >> r >> c >> v;
    a[r-1][c-1] = v;
  }
 
  rep(i,R)rep(j,C) {
    for (int k = 2; k >= 0; k--) {
      chmax(dp[i][j][k+1], dp[i][j][k]+a[i][j]);
    }
    rep(k,4) {
      chmax(dp[i+1][j][0], dp[i][j][k]);
      chmax(dp[i][j+1][k], dp[i][j][k]);
    }
  }
 
  ll ans = 0;
  rep(k,4) chmax(ans, dp[R-1][C-1][k]);
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 320184
#include<bits/stdc++.h>
using namespace std;
#define MAXN 100000

int N, M, dp[MAXN + 3], answer;
vector<int> adj[MAXN + 3];

int longestPath(int u) {
    if (dp[u] != -1)
        return dp[u];

    int result = 0;
    for (int i = 0; i < adj[u].size(); i++) {
        int v = adj[u][i];
        result = max(result, 1 + longestPath(v));
    }

    return dp[u] = result;
}

int main() {
    cin >> N >> M;
    for (int i = 1; i <= M; i++) {
        int x, y;
        cin >> x >> y;
        adj[x].push_back(y);
    }

    memset(dp, -1, sizeof(dp));

    answer = 0;
    for (int i = 1; i <= N; i++)
        answer = max(answer, longestPath(i));

    cout << answer << endl;
}


Measured memory_bytes: 8192
#include <iostream>
#include <string>
using namespace std;
int main ()
{
  int N;
  cin >> N;
  int ac  = 0;
  int wa  = 0;
  int tle = 0;
  int re  = 0;
  for(int i = 0; i < N; i++)
  {
    string s;
    cin >> s;
    if     (s == "AC" ) { ac++;  }
    else if(s == "WA" ) { wa++;  }
    else if(s == "TLE") { tle++; }
    else if(s == "RE" ) { re++;  }
  }
  
  cout << "AC x "  << ac  << endl
       << "WA x "  << wa  << endl
       << "TLE x " << tle << endl
       << "RE x "  << re  << endl;
}


Measured memory_bytes: 3200
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
using namespace std;
typedef long long int64;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const int INF = 1<<29;
const long long  INFL = 1e18;
const int MOD = 1000000007;
const int MAX = 210000;
const int MAX_NUM = 999999999;
void solve() {
	int n, m, x; cin >> n >> m >> x;
	vector<int> c(n);
	vector<vector<int>> a(n, vector<int>(m));
	for (int i = 0; i < n; ++i) {
		cin >> c[i];
		for (int j = 0; j < m; ++j) {
			cin >> a[i][j];
		}
	}	
	int64 ans = INF;
	for (int bit = 0; bit < (1 << n); ++bit) {
		int64 cost = 0;
		vector<int> skill(m);
		for (int i = 0; i < n; ++i) {
			if (bit & (1 << i)) {
				cost += c[i];
				for (int  j = 0; j < m; ++j) {
					skill[j] += a[i][j];
				}
			}
		}
		int64 tmp = 0;
		for (int i = 0; i < m; ++i) {
			tmp += skill[i];
		}
		bool flg = true;
		for (int i = 0; i < m; ++i) {
			if (skill[i] < x) {
				flg = false;
				break;
			}
		}	
		if (flg) {
			ans = min(ans, cost);
		}
	}
	cout << (ans == INF ? -1 : ans) << endl;
	return;
}
int main() {
	solve();
	return 0;
}

Measured memory_bytes: 3608
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#define pb push_back
#define endl '\n';
#define sz(s) int(s.size())
#define Ceil(x,y)  ((x+y-1)/y)
#define all(v) ((v).begin()),((v).end())
#define allr(v) ((v).rbegin()), ((v).rend())
#define I64 int
typedef long long ll;
typedef unsigned long long ull;
typedef double dl;
const ll mod = ll(1e9 + 7);
const double PI = acos(-1.0);
const int N = (int)1e7 + 1;
using namespace std;
void Selim()
{
	std::ios_base::sync_with_stdio(0);
	cin.tie(NULL);
	cout.tie(NULL);
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
}
int dx[8] = { 1, 0, -1, 0, -1, 1, -1, 1 };
int dy[8] = { 0, 1, 0, -1, -1, 1, 1, -1 };
ll gcd(ll a, ll b) { return !b ? a : gcd(b, a % b); }
ll LCM(ll a, ll b) { return a / gcd(a, b)*b; }
//ll fact(long long  n) { return !n ? 1 : n * fact(n - 1); }
//transform(s.begin(), s.end(), s.begin(), ::tolower);
//palindrom if(s==string(s.rbegin(),s.rend()));
//memset(arr,0,sizeof arr)

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

If you want something you've never had, you must be willing to do something you've never done

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

int main()
{
	//freopen("mulan.in", "r", stdin);
	Selim();   
	int l, r, d;
	cin >> l >> r >> d;
	int ans = 0;
	for (int i = l; i <= r; i++){
		if (i%d == 0)ans++;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3648
import java.util.*;

class Main{
	public static void main(String[] $){
		//入力
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		sc.close();

		//処理
		if(a == 1) a += 13;
		if(b == 1) b += 13;
		String ans = "Draw";
		if(a > b) ans = "Alice";
		if(b > a) ans = "Bob";

		//出力
		System.out.println(ans);
	}
}


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

int main () {   
    int k, x;
    cin >> k >> x;
    if ((k * 500) >= x) {
        cout << "Yes" << endl;
    }
    else cout << "No" << endl;
}  

Measured memory_bytes: 256
/******************************************
* AUTHOR : SOMU KUMAR *
* INSTITUTION : IIT BHUBANESWAR *
******************************************/
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define N 100005
#define MOD 1000000007
#define pb push_back
#define mk make_pair
#define pii pair<int,int>
#define pll pair<ll,ll>
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
//code here...............//
int n;
cin>>n;
int ac=0,tle=0,re=0,wa=0;
for(int i=0;i<n;i++){
	string s;
	cin>>s;
	if(s=="AC")ac++;
	else if(s=="WA")wa++;
	else if(s=="TLE")tle++;
	else re++;
}
cout<<"AC "<<"x "<<ac<<endl;
cout<<"WA "<<"x "<<wa<<endl;
cout<<"TLE "<<"x "<<tle<<endl;
cout<<"RE "<<"x "<<re<<endl;

return 0;
}

Measured memory_bytes: 3620
n,m = map(int, input().split())
l = sorted(list(map(int,input().split())))
sub = [0]*(m-1)
if n >= m:
  print(0)
else:
  for i in range(m-1):
    sub[i] = l[i+1] - l[i]
  sub.sort()
  a = 0
  a = sum(sub[0:m-n])
  print(a)

Measured memory_bytes: 13968
#include<bits/stdc++.h>
#define pb push_back
using namespace std;
typedef long long ll;
int n,a[100001]; 
int ans=0;
int main(void)
{
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);
	} 
	for(int i=1;i<=n;i++)
	{
		if(a[i]==i)
		{
			if(a[i+1]==i+1)
			{ans++;
			i++;
			}
			else
			ans++;
		}
	}
	cout<<ans<<endl;
	return 0; 
}

Measured memory_bytes: 640
(function() {
    'use strict';

    var fs = require('fs');
    var contents = fs.readFileSync('/dev/stdin', 'utf-8');
    var lines = contents.trim().split("\n");
    var n = parseInt(lines[0]);

    var A = [];
    var a = lines[1].split(" ");
    var q = parseInt(lines[2]);
    var ms = lines[3].split(" ");
    var max = 0;
    for (var i = 0; i < a.length; i++) {
        A[i] = parseInt(a[i]);
        max += A[i];
    }

    var solve = function() {
        var memo = [];
        memo.length = 20;
        for (var j = 0; j < 20; j++) {
            memo[j] = [];
        }
        var func = function(i, m) {
            if (m === 0) return 1;
            if (i >= n || m < 0 || m > max) return 0;

            var result = memo[i][m];
            if (typeof result !== 'number') {
                result = func(i + 1, m) || func(i + 1, m - A[i]);
                if (result) {
                    memo[i][m] = 1;
                }
            }
            return result;
        };
        return func;
    }();

    for (var i = 0; i < ms.length; i++) {
        if (solve(0, parseInt(ms[i]))) {
            console.log("yes");
        } else {
            console.log("no");
        }
    }
})();

Measured memory_bytes: 16780
#include <iostream>
#include <string>
#include <cstdio>
#include <vector>
#include <stdio.h>
#include <algorithm>
#include <functional>
#include <queue>
#include <math.h>

#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;

int main(){
    long long n;
    int k;
    cin >>n>>k;
    if(n==1){
        cout<<1<<endl;
        return 0;
    }
    double value = (double)log(n) / (double)log(k);
    int ans=ceil(value);
    cout <<ans<<endl;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
 
/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
    sizeは(int)とキャストしよう
    ごちゃごちゃ場合分けを考える前に全探索は考えましたか？
*/

int main(){
    int H, W, D; cin >> H >> W >> D;
    vector<pair<int, int>> cor(H*W+1);
    for(int i=1; i<=H; i++) for(int j=1; j<=W; j++){
        int a; cin >> a;
        cor[a] = make_pair(i, j);
    }

    vector<int> cum(H*W+1, 0);
    for(int i=D+1; i<=H*W; i++) cum[i] = cum[i-D] + abs(cor[i].first - cor[i-D].first) + abs(cor[i].second - cor[i-D].second);

    int Q; cin >> Q;
    vector<int> ans(Q);
    for(int i=0; i<Q; i++){
        int l, r; cin >> l >> r;
        ans[i] = cum[r]-cum[l];
    }

    for(auto e:ans) cout << e << endl;
}

Measured memory_bytes: 2560
#include <stdio.h>
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <queue>
#include <cstring>

using namespace std;

#define rep(i,x) for(int i=0;i<x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define FIND(x, target) find(x.begin(),x.end(),target)
#define pb(x) push_back(x)
#define pob(x) pop_back(x)
#define output(x) cout<<x<<endl
#define ERASE(x, n) x.erase(x.begin()+n)
// #define int long long
#define P pair<int, int>
typedef long long ll;

const long long int MOD = 1e9+7;
const int INF = -1;
ll dp[100005][13];

signed main(void) {
	int A, B;
	cin >> A >> B;

	int ans = 0;
	int num = 1;
	while (num < B) {
		num += A-1;
		ans++;
	}

	cout << ans << endl;
}


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

using namespace std;

using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;

int n;
vector<ll> x, y;

ll f(ll p, ll q) {
  if (p == 0 && q == 0) return n;
  ll ret = n;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < n; j++)
      if (i != j) {
        if (x[i] - x[j] == p && y[i] - y[j] == q) ret--;
      }
  return ret;
}

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  cin >> n;
  x.resize(n);
  y.resize(n);
  for (int i = 0; i < n; i++) cin >> x[i] >> y[i];
  ll ret = 1000000000;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < n; j++) {
      ret = min(ret, f(x[i] - x[j], y[i] - y[j]));
    }
  cout << ret << endl;
  return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define maxn 100001
#define maxa 1000005
#define MOD 1000000007
#define INF 1000000000000000000

using namespace std;

#define ll long long
#define pii pair<ll, ll>
#define piii pair<pii, ll>
#define ft first
#define sd second
#define rep(i, a, n) for(ll i = a; i < n; i++)
#define repr(i, a, n) for(ll i = n-1; i >= a; i--)
#define meme(a, b) memset(a, b, sizeof(a))

void fast(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
}
ll ceil(ll a, ll b){if((a%b) != 0) return a/b+1; return a/b;}
void flaged(bool flag){
    if(flag) cout << "Yes\n";
    else cout << "No\n";
}
ll power(ll a, ll b = MOD-2){
    if(b == 0) return 1;
    ll r = power(a, b/2);
    r = (r*r)%MOD;
    if(b%2 == 1) r = (r*a)%MOD;
    return r;
}

void solve(){
    ll x, y; string a, b, c;
    cin >> a >> b >> x >> y >> c;
    if(c == a) x--;
    else y--;
    cout << x << " " << y;
 }

int main()
{
    fast();
    ll t = 1;
    //cin >> t;
    while(t--){
        solve();
    }
}


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

using namespace std;

#define _for(i,j,N) for(int i = (j); i < (N);i++)
#define ALL(x) x.begin()m,x.end()
#define INF INT_MAX

int get_int(){int x;scanf("%d",&x);return x;}

int main()
{
    int maxnum = -1;
    int n;
    vector<int> vi;
    scanf("%d",&n);
    _for(i,0,n) {vi.push_back(get_int());maxnum = max(vi[i],maxnum);}

    int small = INF;
    int goodnum = -1;

    if(!(maxnum%2)){
        int best = maxnum/2;
        //printf("%d\n",best);
        _for(i,0,n){
            if(vi[i] != maxnum && small > abs(vi[i] - best)){
                small = abs(vi[i] - best);
                goodnum = vi[i];
            }
        }

    }
    else{
        int bestl = maxnum/2;
        int bestr = maxnum/2+1;
         _for(i,0,n){
            if(vi[i] != maxnum && small > min(abs(vi[i] - bestl),abs(vi[i] - bestr))) {
                small = min(abs(vi[i] - bestl),abs(vi[i] - bestr));
                goodnum = vi[i];
            }
        }
    }

    printf("%d %d\n",maxnum,goodnum);

    return 0;
}

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

typedef long long LL;

int N;

LL now_lcm;

LL gcd(LL a, LL b) {
  if (b == 0) {
    return a;
  } 
  return gcd(b, a % b);
}

LL cal_lcm(LL a, LL b) {
  return a / gcd(a, b) * b;
}

int main() {
  cin >> N;

  LL num;
  for(int i = 0; i < N; i++) {
    cin >> num;
    if (i == 0) now_lcm = num;
    now_lcm = cal_lcm(now_lcm, num);
  }

  cout << now_lcm << endl;
  return 0;
}


Measured memory_bytes: 256
def dfs(G,v,N):
    seen[v]=True
    for nv in G[v]:
        if(seen[nv]):
            continue
        dfs(G,nv,N)

N,M=map(int,input().split())
xy=[list(map(lambda x:int(x)-1,input().split())) for i in range(M)]
res=0
for i in range(M):
    G=[[] for i in range(N)]
    seen=[False]*N
    for j in range(M):
        if(i==j):
            continue
        G[xy[j][0]].append(xy[j][1])
        G[xy[j][1]].append(xy[j][0])
    cnt=0
    for k in range(N):
        if(not seen[k]):
            dfs(G,k,N)
            cnt+=1
    if(cnt>1):
        res+=1
print(res)

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

#define rep(l, r) for (int i = (l); i < (r); i++)

typedef long long ll;
 
using namespace std;

void solve() {
    string s;
    cin >> s;

    int n, min_diff = 1e9;
    rep(0, s.size()-2) {
        n = stoi(s.substr(i, 3));
        min_diff = min(min_diff, abs(753 - n));
    }

    cout << min_diff << endl;
}

int main() {
    solve();

    return 0;
}


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

string tl(string &s)
{
  string t = s;
  rep(i,t.size())
  {
    if(isupper(t[i])) t[i] += 32;
  }
  return t;
}

int main()
{
  string s, w;
  cin >> w;
  int cnt = 0;
  while(cin>>s)
  {
    if(s=="END_OF_TEXT") break;
    if(tl(s)==w) cnt++;
  }
  cout << cnt << "\n";
}


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

int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  double a, b;
  cin >> a >> b;
  rep(i,10000) {
    int x = i*0.08, y = i*0.1;
    if (x == a && y == b) {
      cout << i << endl;
      return 0;
    }
  }
  cout << -1 << endl;
  return 0;
}

Measured memory_bytes: 256
N, K = map(int, input().split())
A = [int(a) for a in input().split()]

def make_group(list):
    list.sort()
    group = []
    g_count = 0
    prev = list[0]
    for i in range(N):
        current = list[i]
        if prev != current:
            group.append(g_count)
            g_count = 0
        g_count += 1
        prev = current
        if i == N - 1:
            group.append(g_count)
    return sorted(group)

def calc_moving_count(group):
    group_length = len(group)
    length = max(group_length - K, 0)
    should_move_group = group[:length]
    count = sum(should_move_group)
    return count

def main():
    group = make_group(A)
    count = calc_moving_count(group)
    print(count)

if __name__  == '__main__':
    main()

Measured memory_bytes: 24852
// D - String Equivalence
#include <bits/stdc++.h>
using namespace std;
#define rp(i,s,e) for(int i=(s);i<(e);++i)

int main(){
	int N; cin>>N;
	set<string> s;
	s.insert("a");
	rp(i, 1, N){
		set<string>t; swap(s,t);
		for(auto pre:t){
			set<char> types; for(auto c:pre) types.insert(c);
			rp(j, 0, types.size()+1) s.insert(pre + string(1, j+'a'));
		}
	}
	for(auto x:s) cout<< x <<endl;
}

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

int main(){
cin.tie(0);
ios::sync_with_stdio(false);
int n,x;
cin>>n>>x;
int L;
int cnt=1;
int d=0;
rep(i,n){
    cin>>L;
    d+=L;
    if(d<=x)cnt++;
    else break;
}
cout<<cnt<<endl;
//system("pause");
return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define rep(i, n) for(int i = 0; i < n; i++)
#define REP(i, a, b) for(int i = a; i <= b; i++)
#define all(x) x.begin(), x.end()
#define fi first
#define se second
#define debug(...) cerr<<__LINE__<<" ["<<#__VA_ARGS__<<"]:",debug_out(__VA_ARGS__)
template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec)
{ for (auto v : vec) os << v << ' '; os << '\n'; return os; }
template <typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &pa)
{ os << '(' << pa.first << ',' << pa.second << ')'; return os; }
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail> void debug_out(Head H, Tail... T)
{ cerr << " " << H; debug_out(T...); }
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; }
const int INF = (1<<30) - 1;
const ll LINF = (1LL<<60) - 1;

void solve() {
    int a, b;
    cin >> a >> b;
    cout << max({a + b, a - b, a * b}) << endl;
}

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


Measured memory_bytes: 3568
N = int(input())

dp = []

def dfs(x):
    if check(x):
        dp.append(x)

    if (x <= 10**9):
        dfs(10*x+3)
        dfs(10*x+5)
        dfs(10*x+7)

def check(x):
    set_x = set(list(str(x)))
    if set_x >= {'3','5','7'} and set_x <= {'3','5','7'}:
        return True


dfs(0)
print(len([item for item in dp if item <= N]))

Measured memory_bytes: 7028
import java.util.*

fun main(args : Array<String>) {
    println(inOutExec(Scanner(System.`in`)))
}

fun inOutExec(scanner: Scanner): String {
    val day = scanner.nextInt()

    return when(day) {
        25 -> "Christmas"
        24 -> "Christmas Eve"
        23 -> "Christmas Eve Eve"
        22 -> "Christmas Eve Eve Eve"
        else -> ""
    }
}


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

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int a,b,c;
  string s,t="unsafe";
  cin >>a>>b;
  if (a>b) t="safe";
  cout <<t;
}

Measured memory_bytes: 3608
require 'prime'
include Math
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 gi;																	gets.split.map(&:to_i) 										end
def gs;																	gets.chomp 																end
def gc;																	gets.chomp.split('') 											end
def pr(num); 														num.prime_division 												end
def putall(obj);												obj.each{|o| puts(o)} 										end
def array(size,init = nil);							Array.new(size){init} 										end
def darray(size1, size2, init = nil);		Array.new(size1){Array.new(size2){init}} 	end
def rep(num);														num.times do|i|yield(i) end 							end
	def repl(st,en);											st.upto en-1 do|i|yield(i) end 						end
		
		n = gif
		t = gi
		m = gif
		sum = 0
		t.each do |tt|
			sum += tt
		end

		rep m do
			d = gi
			puts sum - t[d[0]-1]+d[1]
		end




Measured memory_bytes: 2044
#include <iostream>

using namespace std;

#define MAX 2000000

int H = 0, T[MAX + 1];

void maxHeapify(int A[], int i) {
	int l = 2 * i, r = 2 * i + 1;
	int maxi = 0;
	if (l <= H && A[l] > A[i]) maxi = l;
	else maxi = i;
	if (r <= H && A[r] > A[maxi]) maxi = r;
	if (maxi != i) {
		swap(A[i], A[maxi]);
		maxHeapify(A, maxi);
	}
}

void buildMaxHeap(int A[]) {
	for (int i = H / 2; i > 0; --i) maxHeapify(A, i);
}

void insert(int S[], int k) {
	H++;
	S[H] = k;
	int i = H;
	while (i > 1 && S[i / 2] < S[i]) {
		swap(S[i], S[i / 2]);
		i /= 2;
	}
}

int extractMax(int S[]) {
	if (H < 1) return 0;
	int v = S[1];
	S[1] = S[H--];
	maxHeapify(S, 1);
	return v;
}

int main() {
	string s;
	while (cin >> s, s != "end") {
		if (s == "insert") {
			int k; cin >> k;
			insert(T, k);
		} else {
			cout << extractMax(T) << endl;
		}
	}

	return 0;
}


Measured memory_bytes: 6940
#include <bits/stdc++.h>
#define ALL(obj) begin(obj), end(obj)
#define debug(x) cerr << #x << ": " << x << '\n'
using namespace std;
template <class T>
vector<T> make_vec(size_t a) {
    return vector<T>(a);
}
template <class T, class... Ts>
auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
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;
}

using ll = long long;
using ull = unsigned long long;
const int INF = 2100100100;
// const int MOD = 1e9 + 7;

template <class T>
ostream &operator<<(ostream &s, vector<T> vec) {
    for (int i = 0; i < (int)vec.size(); ++i) {
        if (i > 0) {
            s << ' ';
        }
        s << vec[i];
    }
    return s << endl;
}

int main() {
    int N, K, C;
    string S;
    cin >> N >> K >> C >> S;
    vector<int> A;
    int d = 0;
    for (int i = 0; i < N;) {
        if (S[i] == 'o') {
            d++;
            A.push_back(i);
            i += C + 1;
        } else {
            i++;
        }
    }
    if (d > K) return 0;

    //cerr << A;

    vector<int> ans;
    A.push_back(INF);
    for (int i = d - 1; i >= 0; i--) {
        bool flag = true;
        for (int l = min(A[i + 1], N) - 1; l > A[i]; l--) {
            if (S[l] == 'o' && l + C < A[i + 1]) {
                flag = false;
                A[i] = l;
                break;
            }
        }
        if (flag) {
            ans.push_back(A[i]);
        }
    }
    // cerr << A;
    reverse(ans.begin(), ans.end());
    for (auto i : ans) {
        cout << i + 1 << "\n";
    }
}


Measured memory_bytes: 3448
import java.util.*;

public class Main {

	private void doit(){
		Scanner sc = new Scanner(System.in);
		while(true){
			int n = sc.nextInt();
			if(n == 0)break;
			int [] score = new int[2];
			for(int i = 0; i < n; i++){
				int a = sc.nextInt();
				int b = sc.nextInt();
				if(a > b){
					score[0] += a + b;
				}
				else if(b > a){
					score[1] += a + b;
				}
				else{
					score[0] += a;
					score[1] += b;
				}
			}
			System.out.println(score[0] + " " + score[1]);
		}
	}

	private void debug(Object... o) {
		System.out.println("debug = " + Arrays.deepToString(o));
	}

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

Measured memory_bytes: 51884
A, B, C, D = map(int, input().split())

if C % B == 0:
  n_t = C//B
else:
  n_t = C//B + 1
  
if A % D == 0:
  n_a = A//D
else:
  n_a = A//D + 1

if n_a >= n_t:
  print('Yes')
else:
  print('No')

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

int main()
{
	int a,b,c,d;
	cin>>a>>b>>c>>d;
    for(int i=1;i<=100;++i)
    {
        if(a<=d*i||c<=b*i)
    	{
    		if(c<=b*i)
    		    cout<<"Yes"<<endl;
    		else if(a<=d*i)
    		    cout<<"No"<<endl;
    		break;
    	}
    	else
    	    continue;
    }
    return 0;
}

Measured memory_bytes: 3624
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
// #include <iomanip>
// std::cout << std::fixed << std::setprecision(5);

int main()
{
    int a, b;
    std::cin >> a >> b;
    std::cout << std::max(a+b, std::max(a-b, a*b)) << std::endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

main() {
	int H[1000], W[1000], i, kkn = 0, j, k;
	for (i = 0;i < 10000;i++) {
		scanf("%d %d", &H[i], &W[i]);
		if (H[i] == 0 && W[i] == 0) break;
		kkn++;

	}
	for (i = 0;i < kkn;i++) {
		for (j = 0;j < H[i];j++) {
			if (j % 2 != 0) {
				for (k = 0;k < W[i];k++) {
					if (k % 2 == 0) {
						putchar('.');
					}
					else {
						putchar('#');
					}
				
				}
			}
			else {
				for (k = 0;k < W[i];k++) {
					if (k % 2 == 0) {
						putchar('#');
					}
					else {
						putchar('.');
					}
				}
			}
			putchar('\n');
		}
		printf("\n");

	}
}


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

#define x first
#define y second
#define y1 Y1
#define y2 Y2
#define mp make_pair
#define pb push_back
#define DEBUG(x) cout << #x << " = " << x << endl;

using namespace std;

typedef long long LL;
typedef pair <int, int> pii;

template <typename T> inline int Chkmax (T &a, T b) { return a < b ? a = b, 1 : 0; }
template <typename T> inline int Chkmin (T &a, T b) { return a > b ? a = b, 1 : 0; }
template <typename T> inline T read ()
{
	T sum = 0, fl = 1; char ch = getchar();
	for (; !isdigit(ch); ch = getchar()) if (ch == '-') fl = -1;
	for (; isdigit(ch); ch = getchar()) sum = (sum << 3) + (sum << 1) + ch - '0';
	return sum * fl;
}

inline void proc_status ()
{
	ifstream t ("/proc/self/status");
	cerr << string (istreambuf_iterator <char> (t), istreambuf_iterator <char> ()) << endl;
}

const int Maxn = 2e5 + 100;

int N, Sum[2][Maxn];
char S[Maxn];

inline void Solve ()
{
	LL ans = 0;
	int sum = 0, op = 0;
	for (int i = 1; i <= N; ++i)
	{
		if (S[i] == 'W') ans += Sum[0][i];
	}
	cout << ans << endl;
}

inline void Input ()
{
	scanf("%s", S + 1);
	N = strlen (S + 1);
	for (int i = 1; i <= N; ++i)
	{
		Sum[0][i] = Sum[0][i - 1] + (S[i] == 'B'); 
		Sum[1][i] = Sum[1][i - 1] + (S[i] == 'W'); 
	}
}

int main()
{

#ifdef hk_cnyali
	freopen("A.in", "r", stdin);
	freopen("A.out", "w", stdout);
#endif

	Input ();
	Solve ();

	return 0;
}


Measured memory_bytes: 2048
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<ll,ll> P;
typedef vector<P> vp;
typedef vector<string> vs;
typedef vector<bool> vb;

const ll mod=1e9+7;
const ll inf=1e16;

#define rep(i,m,n) for(ll i=m;i<n;i++)
#define repr(i,m,n) for(ll i=m-1;i>=n;i--)
#define fi first
#define se second
#define chmax(x,y) x=max(x,y)
#define chmin(x,y) x=min(x,y)
#define eb(x) emplace_back(x)
#define all(x) x.begin(),x.end()
#define gll greater<ll>()

void solve(){
 ll n,k;
  cin >> n >> k;
 vll a(n);
  rep(i,0,n) cin >> a[i];
 
 while(k--){ 
  vll b(n+1,0); 
  rep(i,0,n){
    ll l=max(0ll,i-a[i]);
    ll r=min(n-1,i+a[i]);
    b[l]++;
    b[r+1]--;
  }
   rep(i,1,n+1) b[i]+=b[i-1];
   rep(i,0,n) swap(a[i],b[i]);
   if(*min_element(all(a))==n) break;
 }
 rep(i,0,n) {
   cout << a[i];
   if(i<n-1) cout << " ";
   else cout << endl;
 }
}  
int main(){
   cin.tie(nullptr);
  ios::sync_with_stdio(false);
  solve();
}


Measured memory_bytes: 6368
//  cd Desktop/Atcoder
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#define rep(i,n) for(i=0;i<(n);i++)
#define Rep(i,n) for(i=1;i<(n);i++)
#define ll long long
#define ull unsigned long long
#define MOD 1000000007

int main(){
    int n;
    scanf("%d",&n);
    n%=1000;
    if (n==0) printf("%d",0);
    else printf("%d",1000-n);
    return 0;
}


Measured memory_bytes: 1736