akhauriyash/Code-Regression huggingface dataset:
#define lop(i, n) for (ll i = n-1; i >= 0; i--)
#define loop(i, x) for (ll i = 0; i < x; i++)
#define loopf(i, x, n) for (ll i = x; i < n; i++)
#define loopr(i, x, n) for (ll i = x - 1; i >= n; i--)
#define ain(arr, n) for (ll i = 0; i < n; i++) cin>>arr[i]
#define aout(arr, n) for (ll i = 0; i < n; i++) cout<<arr[i]<<" "
#define mm(lamb, tttt) memset(lamb, tttt, sizeof lamb)
#define bit(i) (1<<(i))

#define null NULL
#define eps 0.000000001
#define mod 1000000007
#define PI 3.14159265358979323846
#define pb push_back
#define pf push_front
#define mp make_pair
#define fe first
#define se second
#define ALL(V) V.begin(), V.end()
#define sz(V) (ll)V.size()
#define _ <<" "<<

#include <iostream>
#include <fstream>
#include <stdio.h>
#include <stack>
#include <queue>
#include <deque>
#include <vector>
#include <iterator>
#include <bitset>
#include <list>
#include <map>
#include <set>
#include <unordered_map>
#include <cstring>
#include <string>
#include <algorithm>
#include <cmath>
#include <cassert>
#include <limits.h>
#include <iomanip>
#include <cctype>
#include <numeric>
#include <complex>

using namespace std;

typedef long long ll;
typedef vector <ll> vi;
typedef vector<vi> vvi;
typedef pair <ll, ll> ii;
typedef pair<ll, pair<ll,ll> > iii;
typedef vector<ii> vii;
typedef complex<ll> ci;

int main()
{
	ios_base::sync_with_stdio(false);
	ll k;
	cin>>k;
	ll data[k];
	loop(i, k)
		cin>>data[k-i-1];
	ll low = 2 ,high = 2;
	loop(i, k)
	{
		ll x = (low + data[i] - 1)/data[i], y = (high)/data[i];
		x *= data[i], y *= data[i];
		if (y < x)
		{
			cout<<-1<<"\n";
			return 0;
		}
		low = x;high = y + data[i] - 1;
	}
	cout<<low<<" "<<high<<"\n";
	return 0;
}




Measured memory_bytes: 1024
A,B,C,X,Y = map(int,input().split())

ans1 = A*X+B*Y
ans2 = C*min(X,Y)*2
if X < Y :
    ans2 += min(C*2,B)*(Y-X)
else :
    ans2 += min(C*2,A)*(X-Y)
ans = min(ans1,ans2)
print(ans)


Measured memory_bytes: 3060
#include <stdio.h>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>
#include <functional>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef vector<vector<int>> v2int;
typedef vector<ll> vll;
typedef vector<vector<ll>> v2ll;
typedef list<int> liint;
typedef pair<int, int> pint;
const int INF = int(2e9);
const ll LINF = ll(2e9) * ll(2e9);
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T, class C> void chmax(T& a, C b) { a > b ? : a = b; }
template<class T, class C> void chmin(T& a, C b) { a < b ? : a = b; }

int exp_mod(long long a, long long b, int m) {
    long long res = 1;
    while (b > 0) {
        if (b & 1)
            res = (res * a) % m;
        a = (a * a) % m;
        b >>= 1;
    }
    return (int)res;
}

int main() {
    int N;
    cin >> N;
    vint A(N);
    rep(i, N) {
        cin >> A[i];
    }
    ll m = 1000000007;
    vll p(N);
    vll sum_(N + 1);
    sum_[1] = 1;
    REP(i, 2, N + 1) {
         sum_[i] = (sum_[i - 1] + ll(exp_mod(i, m - 2, m))) % m;
    }
    rep(i, N) {
        p[i] = (sum_[i + 1] + (sum_[N - i] - sum_[1])) % m;
    }
    ll ans = 0;
    ll N_fac = 1;
    rep(i, N) {
        ans += A[i] * p[i];
        ans %= m;
        N_fac *= (i+1);
        N_fac %= m;
    }
    cout << (ans * N_fac) % m << endl;
    return 0;
}

Measured memory_bytes: 2176
#include <iostream>

int main(){
   int H, W, N;
   std::cin >> H >> W >> N;

   int a[N];
   for(int i=0; i<N; ++i)
      std::cin >> a[i];

   int x = 0;
   int y = 0;
   int dx = 1;
   int ans[H][W];
   for(int i=0; i<N; ++i){
      for(int j=0; j<a[i]; ++j){
	 ans[y][x] =  i+1;
	 x += dx;
	 if(x<0 || x==W){
	    dx = -dx;
	    x += dx;
	    y++;
	 }
      }
   }
   for(int i=0; i<H; ++i){
      for(int j=0; j<W; ++j){
	 std::cout << ans[i][j] << ' ';
      }
      std::cout << std::endl;
   }
   return 0;
}


Measured memory_bytes: 384
// #pragma GCC optimize("Ofast")
// #pragma GCC optimize ("unroll-loops")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace std;
using namespace __gnu_pbds;

typedef long long int ll;
#define endl '\n'
#define ld long double
#define all(a) a.begin(),a.end()
#define int long long
#define pb push_back
#define pii pair <int, int>
#define ff first
#define ss second
#define sz(v) (int)v.size() 
#define UB upper_bound
#define LB lower_bound
#define BP(x) __builtin_popcountll(x)
#define PQS priority_queue <int, vector<int>, greater<int> > 
#define OST tree<pii, null_type,less<pii>, rb_tree_tag,tree_order_statistics_node_update>
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int getRand(int l, int r) {
  uniform_int_distribution<int> uid(l, r);
  return uid(rng);
}

const int INF = 1e18 + 0;
const int mod = 1e9 + 7;
//const int mod = 998244353;

void solve() {
  string s = "ACL";
  int k; cin >> k;

  while(k--) {
    cout << s;
  }
}

/*
  * overflow, array bounds
  * do smth instead of nothing and stay organized
*/
signed main() {   
  ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

  #ifndef ONLINE_JUDGE
   freopen("input.txt", "r", stdin);
   freopen("output.txt", "w", stdout);
  #endif
   int t = 1; // cin >> t;
   for(int i = 1; i <= t; i++) {
   //  cout << "Case #" << i << ": ";
     solve();
  }
}    

/*

*/

Measured memory_bytes: 3620
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

const bool is_drawable(vector<double> given)
{
  stable_sort(given.begin(), given.end());
  double sum_other;
  for (auto i = 0; i < (given.size() - 1); ++i) sum_other += given[i];
  return given.back() < sum_other;
}

int main()
{
ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);

int N;
cin >> N;
vector<double> L(N);
for (auto i = 0; i < N; ++i) cin >> L[i];
cout << (is_drawable(L) ? "Yes" : "No") << endl;
return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define up(l,r,i) for(int i=l;i<=r;i++)
#define dn(l,r,i) for(int i=l;i>=r;i--)
using namespace std;

typedef long long LL;
const int INF =2147483647;
int qread(){
	int w=1,c,ret;
	while((c=getchar())> '9'||c< '0')
	w=(c=='-'?-1:1); ret=c-'0';
	while((c=getchar())>='0'&&c<='9')
	ret=ret*10+c-'0';
	return ret*w;
}
const int MAXN =2e5+3;
int P[MAXN],Q[MAXN],A[MAXN],B[MAXN],n,ans;
int calc(int x){
	int p=0,k=1;
	while(k) if(p+k<=n&&Q[p+k]<x)
	p+=k,k<<=1; else k>>=1;
	return p;
}
int main(){
	n=qread();
	up(1,n,i) A[i]=qread();
	up(1,n,i) B[i]=qread();
	up(0,28,t){
		int tmp=1<<t,tmp_=(1<<t+1)-1,cnt=0;
		up(1,n,i) P[i]=A[i]&tmp_,Q[i]=B[i]&tmp_;
		sort(Q+1,Q+1+n);
		up(1,n,i){
			cnt+=calc(2*tmp-P[i]);
			cnt-=calc(  tmp-P[i]);
			cnt+=calc(4*tmp-P[i]);
			cnt-=calc(3*tmp-P[i]);
		}
		if(cnt&1) ans|=tmp;
	}
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 3328
#include <bits/stdc++.h>
using namespace std;
#define Rep(i,n) for(int i=0;i<(int)(n);i++)
#define For(i,n1,n2) for(int i=(int)(n1);i<(int)(n2);i++)
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define RREP(i,n) for(ll i=((ll)(n)-1);i>=0;i--)
#define FOR(i,n1,n2) for(ll i=(ll)(n1);i<(ll)(n2);i++)
#define RFOR(i,n1,n2) for(ll i=((ll)(n1)-1);i>=(ll)(n2);i--)
#define all(a)  (a).begin(),(a).end()
#define SORT(a) sort((a).begin(),(a).end())
#define oorret 0
#define oor(x) [&](){try{x;} catch(const out_of_range& oor){return oorret;} return x;}()
#define IOS cin.tie(0),ios::sync_with_stdio(false)
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
template<typename T1, typename T2> inline bool chmin(T1& a, T2 b) { if (a > b) { a = b; return 1; }return 0; }
template<typename T1, typename T2> inline bool chmax(T1& a, T2 b) { if (a < b) { a = b; return 1; }return 0; }
template<class Type>struct is_vector : std::false_type {};
template<class ValueType, class Alloc>struct is_vector<std::vector<ValueType, Alloc>> : std::true_type {};
template <typename T> inline ostream& operator << (ostream& out, const vector<T>& v) {
	if (v.empty())return out;
	constexpr bool is_vector_v = is_vector<T>::value;
	if (is_vector_v)for (auto itr = v.begin(); itr != v.end();)out << (*itr), out << ((++itr != v.end()) ? "\n" : "");
	else for (auto itr = v.begin(); itr != v.end();)out << (*itr), out << ((++itr != v.end()) ? " " : "");
	return out;
}
inline void put() {}
template<class T> inline void put(const T& first) { std::cout << first << "\n"; }
template<class T, class... N> inline void put(const T& first, const N& ... rest) { std::cout << first << " "; put(rest...); }
inline void putn() {}
template<class T, class... N> inline void putn(const T& first, const N& ... rest) { std::cout << first << "\n"; putn(rest...); }


int main() {
	IOS;
	int n;
	cin >> n;
	if (n % 2 == 1) {
		cout << setprecision(20) << (long double)(n / 2 + 1) / n << endl;
	} else {
		cout << setprecision(20) << (long double)(n / 2) / n << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = 1e9 + 7;
const int INF = 2e9;

int main()
{
    int n, x, ans = 1;
    cin >> n >> x;
    vector<int> l(n);
    for (int i = 0; i < n; i++)
    {
        cin >> l[i];
    }
    for (int i = 0; i < n; i++)
    {
        if (l[i] <= x)
        {
            ans++;
            if (i != n - 1)
            {
                l[i + 1] += l[i];
            }
        }
        else
        {
            break;
        }
    }
    cout << ans << endl;
}

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

typedef pair<int, int> P;

vector<P> v;
int N, M;
int ans = 0;

int main() {
  string s, t;
  cin >> s;
  cin >> t;
  int begin, end;
  bool flag = false;
  for (int i = 0; i < s.length(); i++) {
    int cnt = 0;
    for (int j = 0; j < t.length(); j++) {
      if (s[i+j] == t[j] || s[i+j] == '?') {
        cnt++;
        if (cnt == t.length()) {
          begin = i; end = i + j;
          flag = true;
          break;
        }
      }
    }
  }
  
  if (flag) {
    for (int i = 0; i < t.length(); i++) {
      s[begin+i] = t[i];
    }
    int pos = s.find('?');
    while (pos != string::npos) {
      s[pos] = 'a';
      pos = s.find('?', pos+1);
    }
    cout << s << endl;
  } else cout << "UNRESTORABLE" << endl;
  
  return 0;
}

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

using namespace std;

long long solve(long long a, long long b, long long c, long long d){
    long long res = abs(a-c) + abs(b-d);
    auto calc = [](long long x1, long long y1, long long x2, long long y2){
        auto sx = x1, sy = y1, gx = x2, gy = y2; 
        long long res = 0;
        long long block = 1;
        for(int i=0;i<30;i++){
            if(sx == gx && sx%3 == 1 && abs(sy - gy) >= 2){
                long long c1 = x1 % block;
                long long c2 = x2 % block;
                res = max(res, min(c1+c2+2, 2*block-c1-c2) + abs(y1 - y2));
            }
            sx /= 3;
            sy /= 3;
            gx /= 3;
            gy /= 3;
            block *= 3;
        }
        return res;
    };
    return max(res, max(calc(a, b, c, d), calc(b, a, d, c)));
}

int main(){
    int Q;
    while(cin >> Q){
        while(Q--){
            long long a, b, c, d;
            cin >> a >> b >> c >> d;
            cout << solve(a-1, b-1, c-1, d-1) << endl;
        }
    }
}

Measured memory_bytes: 384
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cassert>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
using namespace std;


typedef long long i64;
const int inf = (int)1.05e9;


int main()
{
	int n;
	char s[200005];

	scanf("%d%s", &n, s);

	int black = 0;
	for(int i = 0; i < n; i++) {
		if(s[i] == '#') {
			black += 1;
		}
	}

	int ans = n * 2;
	int left_black = 0;

	for(int i = 0; i <= n; i++) {

		int right_white = n - i - (black - left_black);
		int c = left_black + right_white;
		ans = min(ans, c);

		if(i < n && s[i] == '#') {
			left_black += 1;
		}
	}

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

	return 0;
}

/* waffle */


Measured memory_bytes: 384
import sys
sys.setrecursionlimit(10**5)
m = 100005
visited = [False]*(m*2)
cnt = [0,0]
def dfs(i):
    visited[i] = True
    cnt[i//m] = cnt[i//m]+1
    for j in to[i]:
        if not visited[j]:
            dfs(j)
 
input = sys.stdin.readline
n = int(input())
to = [[] for _ in range(m*2)]
for _ in range(n):
    x,y = map(int,input().split())
    y = y+m
    to[x].append(y)
    to[y].append(x)
 
ans = 0
for i in range(m):
    if not visited[i]:
        cnt = [0,0]
        dfs(i)
        ans = ans + cnt[0]*cnt[1]
 
print(ans-n)

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

bool comp(pair<int,int> a, pair<int,int> b){
	return a.second < b.second;
}

int main(){
  int n,tmp1,tmp2;
  cin >> n;
  pair<int,int> pp[n+100];
  for(int i=0;i<n;i++){
  	cin >> tmp1 >> tmp2;
    pp[i] = {tmp1-tmp2,tmp1+tmp2};
  }
  
  sort(pp, pp+n, comp);
  
  int ans=0;
  int aa=-1000000001;
  for(int i=0;i<n;i++){
  	if(pp[i].first >= aa){
      ans++;
      aa = pp[i].second;
    }
  }
  cout << ans;
  return 0;
}




Measured memory_bytes: 1024
#include <iostream>
#include <cstdio>

using namespace std;

int main(){
	int N; double d, x;
	while(cin >> N >> d >> x){
		double res = 0.0;
		while(N){
			res += 0.5*(2*d+(2*N-1)*x);
			double ns = ((2*N-2)*d + 4*d + 5*x)/(2*N);
			double ne = ((2*N-2)*(d+(2*N-1)*x) + 4*d + (8*N-9)*x)/(2*N);
			--N;
			d = ns;
			x = (ne-ns)/(2*N-1);
		}
		printf("%.10lf\n", res);
	}
}



Measured memory_bytes: 256
#include <string>
#include <vector>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <map>
#include <list>
#include <set>
#include <numeric>
#include <queue>
#include <stack>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <climits>
#include <cfloat>
#include <ctime>
#include <complex>
#include <cassert>
#include <array>
#include <bitset> 
#include <unordered_map>
using namespace std;
typedef long long LL;
typedef pair<LL,LL> P;


void solve(long long N, std::vector<long long> A){
	LL b=0;
	for(auto a:A){
		b^=a;
		//cerr << a << ", ";
	}
	//cerr << endl;
	//cerr << b << endl;
	LL s=0;
	for(int i=60;i>=0;i--){
		LL u=1LL<<i;
		if(b&u)continue;
		//cerr << "aaa" << endl;
		for(int j=0;j<A.size();j++){
			if(A[j]&u){
				//cerr << i << ", " << j << ": " << A[j] << endl;
				if(!(s&u)){
					s^=A[j];
				}
				for(int k=j+1;k<A.size();k++){
					if(A[k]&u){
						A[k]^=A[j];
					}
				}
				A[j]=0;
				break;
			}
		}
	}
	cout << (b^s)+s << endl;
}

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


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

int main(){
    int n,k;cin >> n >> k;
    int arr[n];
    for(int i = 0;i<n;i++)
        cin >> arr[i];
    sort(arr,arr+n);
    long long int ans = 0;
    for(int i = 0;i<k;i++){
        ans += arr[i];
    }
    cout << ans << '\n';
}

Measured memory_bytes: 3596
n=int(input())
A=list(map(int,input().split()))
a=[]
for i in range(n):
  a.append([i+1,A[i]])
b=sorted(a,key=lambda x:x[1])
lst=[]
for k in range(n):
  lst.append(b[k][0])
print(*lst)
  


Measured memory_bytes: 24408
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
#include<ctime>

using namespace std;
using ll = long long;

int f_dir[2][4] = {{-1, 0, 0, 1}, {0, -1, 1, 0}};
int e_dir[2][8] = {{-1, -1, -1, 0, 0, 1, 1, 1}, {-1, 0, 1, -1, 1, -1, 0, 1}};
bool is_in_field(int y, int x, int h, int w){
  return (y >= 0 && y < h && x >= 0 && x < w);
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int ti = clock();
  // start-----------------------------------------------
  ll n, a, b; cin >> n >> a >> b;
  cout <<  (n / (a+b)) * a + min(n % (a+b), a) << endl;

  // end-----------------------------------------------
  // cerr << 1.0 * (clock() - ti) / CLOCKS_PER_SEC << endl;
}


Measured memory_bytes: 256
n = gets.chomp.to_i
s = gets.chomp

pos = n - 1
while pos >= 0
  if s[pos] == '#'
    pos -= 1
    next
  end
  break
end

black_cnt = 0
white_cnt = 0
ans = 0
while pos >= 0
  if s[pos] == '#'
    black_cnt += 1
  else
    white_cnt += 1
  end
  if black_cnt > white_cnt
    ans += white_cnt
    black_cnt = 0
    white_cnt = 0
  end
  pos -= 1
end
puts ans + [black_cnt, white_cnt].min


Measured memory_bytes: 2172
ok = false
s = gets.chomp
ss =s+s
p = gets.chomp
for i in 0..(s.length-1)
for j in 0..(p.length-1)
if ss[i+j]  != p[j]
break
end
if j == p.length-1
ok=true
end
end
end
if ok == true
puts "Yes"
else
puts "No"
end

Measured memory_bytes: 8712
#include<cstdio>
#include<cstring>
#include<string>
#include<iostream>
#include<cmath>
#include<algorithm>
#include<queue>
#include<map>
#include<ctime>

using namespace std;

template <typename T>

inline T read()
{
	T x=0,f=1;char c=getchar();
	while(!isdigit(c))
	{if(c=='-') f=-f;c=getchar();}
	while(isdigit(c))
	{x=(x<<3)+(x<<1)+(c-48);c=getchar();}
	return x*f;
}

#define lint long long int
#define ulint unsigned lint

const int inf=1e9+1e7;

int gcd(int A,int B)
{

	return ( A==0 ? B : gcd(B%A,A) );

}

int main(void)
{

	// freopen("testdata.in","r",stdin);
	// freopen("testdata.out","w",stdout);

	int n=read<int>();
	lint ans=0;

	for(int i=1;i<=n;i++)
		for(int j=1;j<=n;j++)
			for(int k=1;k<=n;k++)
			{
				int tmp=( i>j ? gcd(j,i) : gcd(i,j) );
				int res=( tmp>k ? gcd(k,tmp) : gcd(tmp,k) );
				ans+=(lint)res;
			}

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

	return 0;

}


Measured memory_bytes: 3652
import java.util.*;
import java.io.*;

public class Main{
    public static void main(String[] args) throws IOException{
        BufferedReader f = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));
        StringTokenizer st = new StringTokenizer(f.readLine());
        int a = Integer.parseInt(st.nextToken());
        int b = Integer.parseInt(st.nextToken());
        int c = Integer.parseInt(st.nextToken());
        int d = Integer.parseInt(st.nextToken());
        int t1 = 60*a+b;
        int t2 = 60*c+d;
        int k = Integer.parseInt(st.nextToken());
        out.println(t2-t1-k);


        out.close();
    }
}


Measured memory_bytes: 32592
#include <bits/stdc++.h>
#define REP(i, N) for (int i = 0; i < (N); ++i)
#define ALL(x) (x).begin(), (x).end()
#define MOD 1000000007
#define PB push_back
#define MP make_pair
using namespace std;
typedef long long ll;
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }

//++時計回り --反時計回り
// int dx[4] = {1, 0, -1, 0};
// int dy[4] = {0, 1, 0, -1};

ll div_ceil(ll a, ll b) {
  ll quotient = a / b;
  ll remainder = a % b;
  if (remainder == 0) {
    return quotient;
  } else {
    return quotient + 1;
  }
}

int main() {
  int N, D;
  cin >> N >> D;
  cout << div_ceil(N, D * 2 + 1) << '\n';
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <stack>
#include <cstring>
#include <queue>
#include <algorithm>
#include <cmath>
//#include <unordered_map>
#define N 1000010
//#define lson x<<1
//#define rson x<<1|1
//#define mid ((lt[x].l+lt[x].r)/2)
//#define ID(x, y) ((x)*m+(y))
//#define CHECK(x, y) ((x)>=0 && (x)<n && (y)>=0 && (y)<m)
using namespace std;
typedef long long LL;
typedef pair<LL,LL> PII;
const LL INF=0x3f3f3f3f;
void Open()
{
    #ifndef ONLINE_JUDGE
        freopen("F:/in.txt","r",stdin);
        //freopen("F:/my.txt","w",stdout);
    #endif // ONLINE_JUDGE
}
LL n, ans;
LL d[N];
int w[N];
vector<LL> G[N];
vector<LL> lis[N];
queue<LL> que;
int main()
{
//    Open();
    scanf("%lld", &n);
    for(LL i = 0; i < n; i++){
        LL l;
        scanf("%lld%lld", &w[i], &l);
        if(l != -1) G[i].push_back(l), d[l]++;
    }
    for(LL i = 0; i < n; i++)
    {
        if(d[i] == 0) que.push(i);
    }
    while(!que.empty())
    {
        LL u = que.front();que.pop();
        for(LL i = 0; i < G[u].size();i++)
        {
            LL v = G[u][i];
            lis[v].push_back(w[u]);
            w[v] += w[u];
            d[v]--;
            if(d[v] == 0) que.push(v);
        }
    }
    ans = 0;
    for(LL i = 0; i < n; i++)
    {
        sort(lis[i].begin(), lis[i].end());
        LL siz = lis[i].size();
        for(LL j = siz-2, cnt = 1; j >= 0; j--, cnt++)
        {
            ans += lis[i][j] * cnt;
        }
    }
    printf("%lld\n", ans);
    return 0;
}

Measured memory_bytes: 122520
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<int(N);++i)
#define rep1(i,N) for(int i=1;i<int(N);++i)
#define all(a) (a).begin(),(a).end()
#define print(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<_<<", "; cerr<<"]"<<endl; }
#define printpair(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<"{"<<_.first<<","<<_.second<<"}"<<", "; cerr<<"]"<<endl; }
#define dump(x) cerr<<#x<<": "<<x<<endl;
#define bit(k) (1LL<<(k))
typedef long long ll;
typedef pair<int, int> i_i;
typedef pair<ll, ll> l_l;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;
template< typename T1, typename T2 >
ostream &operator<<(ostream &os, const pair< T1, T2 >& p) {
  os << "{" <<p.first << ", " << p.second << "}";
  return os;
}
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; }

const int INF = (ll)1e9;
const ll INFLL = (ll)1e18+1;
const ll MOD = (ll)1e9+7;
const double PI = acos(-1.0);
/*
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const string dir = "DRUL";
*/

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

    int l, r, d;
    cin >> l >> r >> d;
    int ans = 0;
    for(int i = l; i <= r; i++){
        ans += (i % d == 0);
    }
    cout << ans << endl;
}


Measured memory_bytes: 3576
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <string>
using namespace std;
#define REP(i, n) for(int i = 0; i < (int)(n); ++i)

int nD;
bool notOK[20];

inline bool isOK(int x) {
  while(x > 0) {
    int d = x % 10;
    if(notOK[d])
      return false;
    x /= 10;
  }
  return true;
}

int main(void) {
  int n;
  scanf("%d%d", &n, &nD);
  REP(i, nD) {
    int d;
    scanf("%d", &d);
    notOK[d] = true;
  }
  for(int i = n; ; ++i) {
    if(isOK(i)) {
      printf("%d\n", i);
      break;
    }
  }
  return 0;
}


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

int main() {
  int t,h,n,now;
  cin>>t;
  while(t--) {
    int h=0,l=0,prev=0;
    cin>>n;
    cin>>prev;
    for(int i=1; i<n; ++i) {
      cin>>now;
      if(prev > now) {
        l = max(l, prev-now);
      } else {
        h = max(h, now-prev);
      }
      prev = now;
    }
    cout<<h<<" "<<l<<endl;
  }
}

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

typedef pair<int,int> P;

int main(){
    vector<vector<int>>v(3,vector<int>(3));
    for (int i = 0; i < 3; i++){
        for (int j = 0; j < 3; j++){
            cin >> v.at(i).at(j);
        }
    }
    int n;
    cin >> n;
    vector<int>bingo(n);
    for (int i = 0; i < n; i++){
        cin >> bingo.at(i);
    }
    for (int i = 0; i < n; i++){

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

                if (v.at(j).at(k) == bingo.at(i)){
                    v.at(j).at(k) = -1;
                }

            }
        }
    }
    bool ok = false;
    if (v.at(0).at(0) == v.at(0).at(1) && v.at(0).at(1) == v.at(0).at(2)) ok = true;
    if (v.at(1).at(0) == v.at(1).at(1) && v.at(1).at(1) == v.at(1).at(2)) ok = true;
    if (v.at(2).at(0) == v.at(2).at(1) && v.at(2).at(1) == v.at(2).at(2)) ok = true;
    if (v.at(0).at(0) == v.at(1).at(1) && v.at(1).at(1) == v.at(2).at(2)) ok = true;
    if (v.at(0).at(2) == v.at(1).at(1) && v.at(1).at(1) == v.at(2).at(0)) ok = true;
    if (v.at(0).at(0) == v.at(1).at(0) && v.at(1).at(0) == v.at(2).at(0)) ok = true;
    if (v.at(0).at(1) == v.at(1).at(1) && v.at(1).at(1) == v.at(2).at(1)) ok = true;
    if (v.at(0).at(2) == v.at(1).at(2) && v.at(1).at(2) == v.at(2).at(2)) ok = true;
    if (ok){
        cout << "Yes" << "\n";
    }else{
        cout << "No" << "\n";
    }
}

Measured memory_bytes: 256
using System;


    class MainClass
    {
        public static void Main(string[] args)
        {
           

            string[] input1 = Console.ReadLine().Split(' ');
            ulong N= ulong.Parse(input1[0]);
            ulong K = ulong.Parse(input1[1]);

            while (N >= K)
            {

                N =N%K;
            }

            

            if (N <= K/2)
            {
                Console.WriteLine(N);
            }
            else
            {
                Console.WriteLine(K - N);
            }

            


        }
    }

Measured memory_bytes: 13140
#include <stdio.h>
int main()
{
    long long int i,a,x=0;
    scanf("%lld",&a);
    for (i=1; i<=a; i++)
    {
        if (i%15 == 0 || (i%3) == 0 || (i%5) == 0)
          ;
        else
          x=x+i;
    }
    printf("%lld\n",x);
    return 0;
}


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

int main() {
	string s, t;
	cin >> s >> t;
	bool y;
	int p = s.length();
	int a1 = -1;
	char b1;
	for (int i = s.length() - t.length();i >= 0;i --) {
		y = true;
		int a2 = s.length();
		char b2;
		for (int j = i;j < i + t.length();j ++) {
			if (s[j] == '?') {
				if (a2 == s.length()) {
					a2 = j;
					b2 = t[j - i];
				}
			} else if (s[j] != t[j - i]) y = false;
		}
		if (y) {
			if (a1 < a2 || (a2 == a1 && b2 < b1)) {
				p = i;
				a1 = a2;
				b1 = b2;
			}
		}
	}
	
	if (a1 == -1) {
		cout << "UNRESTORABLE";
		return 0;
	}
	for (int i = 0;i < p;i ++) cout << (s[i] == '?' ? 'a' : s[i]);
	for (int i = 0;i < t.length();i ++) cout << t[i];
	for (int i = p + t.length();i < s.length();i ++) cout << (s[i] == '?' ? 'a' : s[i]);
	return 0;
}

Measured memory_bytes: 256
def intersection(lst1, lst2): 
    lst3 = [value for value in lst1 if value in lst2] 
    return lst3 

n,k=map(int,input().split())
a=list(map(str,input().split()))
while(1):
    x=list(str(n))
    check=True
    if len(intersection(x,a))==0:
        print(n)
        break
    n+=1

Measured memory_bytes: 41564
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  double A[N];
  double ans=0;
  for(int i=0; i<N; i++)
    {
    cin >> A[i];
    ans += (double)1 / A[i];
    }
  //分解するより精度上げてみる
  
  ans = (double)1 /ans;
  printf("%.8lf",ans);
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define all(v) v.begin(),v.end()
using namespace std;
int main(){
	int n,m,a,b,c[100]={};
	cin>>n>>m;
	for(int i=0;i<m;i++){
		cin>>a>>b;
		c[a]++;
		c[b]++;
	}
	for(int i=1;i<=n;i++){
		cout<<c[i]<<endl;
	}
	return(0);
}

Measured memory_bytes: 3596
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

type Vec struct{ x, y int }

func add(a, b Vec) Vec {
	return Vec{a.x + b.x, a.y + b.y}
}

func sub(a, b Vec) Vec {
	return Vec{a.x - b.x, a.y - b.y}
}

func rot(a Vec) Vec {
	return Vec{-a.y, a.x}
}

func parse() (Vec, Vec) {
	stdin := bufio.NewScanner(os.Stdin)
	stdin.Split(bufio.ScanWords)

	var line [4]int

	for i := 0; i < len(line); i++ {
		stdin.Scan()
		n, _ := strconv.Atoi(stdin.Text())

		line[i] = n
	}

	return Vec{line[0], line[1]}, Vec{line[2], line[3]}
}

func main() {

	x1, x2 := parse()
	v := sub(x2, x1)

	v = rot(v)
	x3 := add(x2, v)

	v = rot(v)
	x4 := add(x3, v)

	fmt.Println(x3.x, x3.y, x4.x, x4.y)
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define rep(i, m, n) for(int i = m; i < (n); i++)
#define print(x) cout << (x) << endl;
#define printa(x,n) for(int i = 0; i < n; i++){ cout << (x[i]) << " ";} cout << endl;
#define printa2(x,m,n) for(int i = 0; i < m; i++){ for(int j = 0; j < n; j++){ cout << x[i][j] << " ";} cout << endl;}
#define printp(x,n) for(int i = 0; i < n; i++){ cout << "(" << x[i].first << ", " << x[i].second << ") "; } cout << endl;
#define INF (1e18)
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
typedef struct{
    int x;
    int y;
} P;
typedef struct{
    ll to;
    ll cost;
} edge;
typedef pair<ll, ll> lpair;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll X,Y;
    cin >> X >> Y;
    if(abs(X-Y) <= 1){
        print("Brown");
    }else{
        print("Alice");
    }
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <utility>
#include <vector>
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i, s, n) for(int i = s; i < (n); ++i)
#define REP(i, n) FOR(i, 0, n)
typedef long long ll;
const int MOD = 1000000007;
using namespace std;

int main(){
    string s; cin >> s;
    string ans="";
    if(s[0] == 'S') ans = "Cloudy";
    else if(s[0] == 'C') ans = "Rainy";
    else ans = "Sunny";
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
#include <iostream>
#include <string.h>
#include <stdio.h>
#include <map>
#include <vector>
#include <math.h>
#include <algorithm>
#include <queue>
#include <set>
#include <tuple>
using namespace std;

#define FOR(i,init,a) for(int i=init; i<a; i++)
#define rep(i,a) FOR(i,0,a)
#define rrep(i,a) for(int i=a; i>=0; i--)
#define rep1(i,a) for(int i=1; i<=a; i++)
#define cout1(a) cout << a << endl;
#define cout2(a,b) cout << a << " " << b << endl;
#define cout3(a,b,c) cout << a << " " << b << " " << c << endl;
#define cout4(a,b,c,d) cout << a << " " << b << " " << c << " " << d << endl;
#define mem(a,n) memset( a, n, sizeof(a))
#define all(a) a.begin(),a.end()
#define chmin(a,b) a=min(a,b);
#define chmax(a,b) a=max(a,b);

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef vector<int> V;
typedef vector<V> VV;
typedef vector<VV> VVV;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LLINF = 1e18;
static const double pi = 3.141592653589793;

int calc(string a){
    return atoi(a.c_str());
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    string s;
    cin>>s;
    
    int mn=INF;
    rep(i,s.size()-2){
        int n=calc(s.substr(i,3));
        if(mn>abs(753-n)) mn=abs(753-n);
    }
    cout1(mn)
}

Measured memory_bytes: 256
import collections
n=int(input())
v=list(map(int,input().split()))
a=[]
b=[]
for i in range(0,n,2):
    a.append(v[i])
    b.append(v[i+1])
    
a_count=collections.Counter(a)
b_count=collections.Counter(b)

if a_count.most_common()[0][0]==b_count.most_common()[0][0]:
    if a_count.most_common()[0][1]==n//2 :
        print(a_count.most_common()[0][1])
    else:
        print(min(n-a_count.most_common()[0][1]-a_count.most_common()[1][1],n-b_count.most_common()[0][1]-b_count.most_common()[1][1]))
else:
    ans=n-a_count.most_common()[0][1]-b_count.most_common()[0][1]
    print(ans)

Measured memory_bytes: 20344
#define _USE_MATH_DEFINES
#include <vector>
#include <string>
#include <iostream>
#include <fstream>
#include <list>
#include <algorithm>
#include <sstream>
#include <set>
#include <math.h>
#include <cmath>
#include <map>
#include <stack>
#include <queue>
#include <stdio.h>
#include <string.h>
#include <numeric>
 
using namespace std;

typedef long long ll;

int N,K; ll M;
 
int main(){
 
cin>>N>>K; M=1;

if(N==1) cout<<K<<endl;

else{
  for(int i=0; i<N-1;i++){
    M*=K-1;
  }

  cout<<K*M<<endl;
}

return 0;
 
}


Measured memory_bytes: 384
#define _CRT_SECURE_NO_WARNINGS
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <array>
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <deque>
#include <set>
#include <map>
#include <algorithm>
#include <bitset>
#include <utility>
#include <assert.h>
#include <regex>
#include <numeric>
using namespace std;

typedef unsigned long long ull;
typedef signed long long ll;
#define INF (1LL << 48)

struct PT { ll x; ll y; };
string to_s(ull x) { return to_string(x); }
string to_s(ll x) { return to_string(x); }
ll to_ll(const string& x) { return stoll(x); }
ull to_ull(const string& x) { return stoull(x); }




int main(int argc, char* argv[])
{
	for (;;) {
		int N, M;

		cin >> N >> M;
		if (cin.fail()) break;

		bitset<11> L[11];
		for (int i = 0; i < M; i++) {
			int sn, s;
			cin >> sn;
			while (sn--) {
				cin >> s;
				L[i].set(s - 1);
			}
		}
		int P[11];
		for (int i = 0; i < M; i++) {
			cin >> P[i];
		}

		int result = 0;
		for (int np = 0; np < (1 << N); np++) {
			bitset<11> x(np);
			bool on = true;
			for (int i = 0; i < M && on; i++) {
				int s = 0;
				for (int j = 0; j < N; j++) {
					if (L[i][j] && x[j]) s++;
				}
				on = (s % 2) == P[i];
			}
			if (on) result++;
		}
		cout << result << endl;
	}

	return 0;
}


Measured memory_bytes: 256
from operator import itemgetter

n, m = list(map(int, input().split()))
shops = []
for _ in range(n):
    a, b = list(map(int, input().split()))
    shops.append((a, b))

shops = sorted(shops, key=itemgetter(0))
rest = m
cost = 0
for a, b in shops:
    if rest > b:
        cost += a * b
        rest -= b
    else:
        cost += a * rest
        break

print(cost)

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

int main(){
   int n;cin>>n;
   vector<long int> a(n);
   vector<int> m(100010);
   for(int i=0;i<n;i++) {
       cin>>a[i];
       m[a[i]]++;if(a[i]!=0)m[a[i]-1]++;
       m[a[i]+1]++;
   }
   sort(a.begin(),a.end(),greater<int>());
   int max=0;
   for(int i=0;i<=a[0];i++){
       //if(m[i]!=0) printf("i=%d %d\n",i,m[i]);
       if(max<m[i]) max=m[i];
   }
   cout<<max<<endl;
}


Measured memory_bytes: 1408
a, b, c, d = gets.chomp.chars.map(&:to_i)

if a + b + c + d == 7
  puts "#{a}+#{b}+#{c}+#{d}=7"
elsif a + b + c - d == 7
  puts "#{a}+#{b}+#{c}-#{d}=7"
elsif a + b - c + d == 7
  puts "#{a}+#{b}-#{c}+#{d}=7"
elsif a - b + c + d == 7
  puts "#{a}-#{b}+#{c}+#{d}=7"
elsif a - b - c + d == 7
  puts "#{a}-#{b}-#{c}+#{d}=7"
elsif a + b - c - d == 7
  puts "#{a}+#{b}-#{c}-#{d}=7"
elsif a - b + c - d == 7
  puts "#{a}-#{b}+#{c}-#{d}=7"
elsif a - b - c - d == 7
  puts "#{a}-#{b}-#{c}-#{d}=7"
end


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

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

int main(){
    int ans=0,chk=0;
    char s[15];
    scanf("%s",s);
    rep (i,10) {
        if (s[i]=='A' || s[i]=='C' || s[i]=='G' || s[i]=='T') {
            chk++;
        } else {
            chk=0;
        }
        ans=max(ans,chk);
    }
    printf("%d\n",ans);
    return 0;
}


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

using namespace std;
const long long mod = 1e9 + 7;
int main()
{
    int h, w;
    cin >> h >> w;
    vector<vector<int>> grid(h, vector<int>(w));
    for (int i = 0; i < h; i++)
    {
        string str;
        cin >> str;
        for (int j = 0; j < w; j++)
        {
            if (str[j] == '.')
            {
                grid[i][j] = 0;
            }
            else
                grid[i][j] = 1;
        }
    }
    vector<vector<long long>> dp(h, vector<long long>(w, -1));
    dp[0][0] = 1;
    dp[h - 1][w - 1] = 0;
    for (int j = 1; j < w; j++)
    {
        if (grid[0][j] == 0)
        {
            dp[0][j] = (dp[0][j - 1]) % mod;
        }
        else
        {
            dp[0][j] = 0;
        }
    }
    for (int i = 1; i < h; i++)
    {
        if (grid[i][0] == 0)
        {
            dp[i][0] = (dp[i - 1][0]) % mod;
        }
        else
        {
            dp[i][0] = 0;
        }
    }
    for (int i = 1; i < h; i++)
    {
        for (int j = 1; j < w; j++)
        {
            if (grid[i][j] == 0)
                dp[i][j] = (dp[i - 1][j] + dp[i][j - 1]) % mod;
            else
                dp[i][j] = 0;
        }
    }
    cout << dp[h - 1][w - 1] << "\n";
}

Measured memory_bytes: 12032
#include <stdio.h>

int returnMax(int a,int b,int c);

int main(void){
  int datanum=1;

  int num[3];
  int i,j;
  int temp;
  while(scanf("%d %d",&num[0],&num[1])!= EOF){
    temp = num[0] + num[1];
    i=0;
    while(1){
      temp = temp / 10;
      i++;
      if(temp == 0) break;
    }
    printf("%d\n",i);
  }

  //check
  /*
  for(i=0;i<datanum;i++){
    printf("%d-%d-%d\n",num[i],num[i+1],num[i+2]);
  }
  */
  return(0);
}
int returnMax(int a,int b,int c){

  if(a>b+c){
    return(a);
  }
  else if(b>a+c){
    return(b);
  }
  else
    return(c);
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define ll long long
#define rep(i,n) for (int i = 0; i < n; i++)
#define vl vector<ll>
#define vpl vector<pair<ll,ll>>
#include<algorithm>//__gcd(a,b)


int main(){
    ll n,st;cin>>n>>st;
    vl x(n);rep(i,n){
        cin>>x[i];
        if(x[i]-st<0)x[i]=st-x[i];
        if(x[i]-st>=0)x[i]=x[i]-st;
    }

    ll G=x[n-1];


    rep(i,n)G=__gcd(G,x[i]);

    cout<<G<<endl;

    
}

Measured memory_bytes: 1024
#include <iostream>

class Trump{
public:
	char c;
	int value;
};

class Sort{
public:
	void bubble_sort(Trump *A, int N){
		for(int i = 0; i < N; ++i){
			for(int j = N-1; j > i; --j){
				if(A[j].value < A[j-1].value){
					Trump tmp = A[j];
					A[j] = A[j-1];
					A[j-1] = tmp;
				}
			}
		}
		for(int i = 0; i < N; ++i){
			if(i > 0) std::cout << " ";
			std::cout << A[i].c << A[i].value;
		}
		std::cout << std::endl;
	}

	void selection_sort(Trump *A, int N){
		for(int i = 0; i < N; ++i){
			int minj = i;
			for(int j = i; j < N; ++j){
				if(A[j].value < A[minj].value) minj = j;
			}
			Trump tmp = A[i];
			A[i] = A[minj];
			A[minj] = tmp;
		}
		for(int i = 0; i < N; ++i){
			if(i > 0) std::cout << " ";
			std::cout << A[i].c << A[i].value;
		}
		std::cout << std::endl;
	}

	void isStable(Trump *A_in, Trump *A_out, int N){
		for(int i = 0; i < N; ++i){
			for(int j = i; j < N; ++j){
				for(int a = 0; a < N; ++a){
					for(int b = a + 1; b < N; ++b){
						if((A_in[i].value == A_in[j].value) && (A_in[i].value == A_out[b].value) && (A_in[i].c == A_out[b].c) && (A_in[j].value == A_out[a].value) && (A_in[j].c == A_out[a].c)){
							std::cout << "Not stable" << std::endl;
							return;
						}
					}
				}
			}
		}
		std::cout << "Stable" << std::endl;
	}
};



int main(){
	int N;
	Trump t_in[36];
	Trump t_out[36];
	Trump t_out2[36];
	Sort s;

	std::cin >> N;
	for(int i = 0; i < N; ++i){
		std::cin >> t_in[i].c >> t_in[i].value;
		t_out[i] = t_in[i];
		t_out2[i] = t_in[i];
	}
	
	s.bubble_sort(t_out, N);
	s.isStable(t_in, t_out, N);
	s.selection_sort(t_out2, N);
	s.isStable(t_in, t_out2, N);

	return 0;
}


Measured memory_bytes: 3100
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 100010;
const ll mod = 1000000007;
int n, p1, p2;
int a[N];
ll cnt[N], inv[N];
ll power(ll x, ll t)
{
	ll ret = 1;
	for(; t; t >>= 1, x = x * x % mod) if(t & 1) ret = ret * x % mod;
	return ret;
}
ll calc(int a, int b)
{
	if(a < b) return 0;
	return inv[a] * power(inv[b], mod - 2) % mod * power(inv[a - b], mod - 2) % mod; 
}
int main()
{
	scanf("%d", &n);
	++n;
	inv[0] = 1ll;
	for(int i = 1; i <= n; ++i)
		inv[i] = inv[i - 1] * (ll)i % mod;
	for(int i = 1; i <= n; ++i)
	{
		scanf("%d", &a[i]);
		++cnt[a[i]];
		if(cnt[a[i]] == 2) p2 = i;
	}
	for(int i = 1; i < p2; ++i) if(a[i] == a[p2])
	{
		p1 = i; 
		break;
	}
	for(int i = 1; i <= n; ++i)
		printf("%lld\n", (((calc(n, i) - calc(n - p2 + p1 - 1, i - 1)) % mod) + mod) % mod);
	return 0;
}

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

const int INF = 1e9;

int main() {
  int h,w;
  cin>>h>>w;

  char s[h][w];
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      cin>>s[i][j];
    }
  }

  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      if(s[i][j]=='.'){
        continue;
      }
      if(i>0&&s[i-1][j]=='#'){
        continue;
      }
      if(i<h-1&&s[i+1][j]=='#'){
        continue;
      }
      if(j>0&&s[i][j-1]=='#'){
        continue;
      }
      if(j<w-1&&s[i][j+1]=='#'){
        continue;
      }
      cout<<"No"<<endl;
      return 0;
    }
  }
  cout<<"Yes"<<endl;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); i++)
#define divup(a,b) ( ( (a) + ( (b) - 1u) ) / (b) ) // a/b の余り切り上げ
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
int mod = 1000000007;

int main(){
    ll n,m;
    cin>>n>>m;
    vector<ll> a(n);
    vector<pair<ll,ll>> p(m);
    rep(i,n){
        cin>>a[i];
    }
    rep(i,m){
        cin>>p[i].second>>p[i].first;
    }
    sort(a.begin(),a.end());
    sort(p.begin(),p.end(),greater<pair<ll,ll>>());
    ll ct=0;
    bool f=false;
    rep(i,m){
        rep(j,p[i].second){
            if(a[ct]<p[i].first){
                a[ct]=p[i].first;
                ct++;
            }else{
                f=true;
                break;
            }
        }
        if(f==true) break;
    }
    ll ss = accumulate(a.begin(),a.end(),0LL);
    cout<<ss<<endl;
}


Measured memory_bytes: 2560
H, W, k = map(int, input().split())
"""
dp[k][i][j]
i行目、j番目まで来た時に、k個アイテムをとったときの価値の最大値
"""
fs = [[0]*(W+1) for i in range(H+1)]
dp = [[[-1]*(W+1) for i in range(H+1)] for j in range(4)]

# 価値を受け取る
for i in range(k):
    h, w, v = map(int, input().split())
    fs[h-1][w-1] += v

# initialize
dp[0][0][0] = 0
dp[1][0][0] = fs[0][0]

for h in range(H):
    for w in range(W):
        for i in range(4):
            if i == 0:
                dp[i][h][w+1] = max(dp[0][h][w], dp[0][h][w+1])
            else:
                dp[i][h][w+1] = max(dp[i][h][w], dp[i][h][w+1], dp[i-1][h][w]+fs[h][w+1])
    for w in range(W):
        dp[0][h+1][w] = max(dp[0][h][w],dp[1][h][w],dp[2][h][w],dp[3][h][w],0)
        dp[1][h+1][w] = dp[0][h+1][w] + fs[h+1][w]

mx = 0
for i in range(4):
    mx = max(dp[i][H-1][W-1],mx)
print(mx)

Measured memory_bytes: 430552
#include "bits/stdc++.h"

using namespace std;
int main() {
	int N;
	cin >> N;
	string S;
	cin >> S;
	int rB = 0;
	for (int i = 0; i < S.size(); ++i) {
		if (S[i] == '#') {
			rB++;
		}
	}
	int rW = N - rB;
	int lB = 0;
	int lW = 0;
	int ans = rW + lB;
	for (int i = 0; i < S.size(); ++i) {
		if (S[i] == '.') {
			rW--;
			lW++;
		}
		else {
			rB--;
			lB++;
		}
		ans = min(ans, lB + rW);
	}
	cout << ans <<  endl;
}


Measured memory_bytes: 3764
#include<stdio.h>

int main(){
  int n = 0;
  char str[100001] = {};
  int i = 0;
  int plana = 0;
  int planb = 0;
  scanf(" %s",str);
  
  while(1){
    if(str[n] != '\0'){
      n++;
    }else{
      break;
    }
  }
  for(i=0;i<n;i++){
    if((str[i] == '0' && i % 2==0)||(str[i] == '1' && i % 2==1)){
      plana++;
    }else{
      planb++;
    }
  }
  if(plana > planb){
    printf("%d",planb);
  }else{
    printf("%d",plana);
  }
  return 0;
}
  

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long
#define vi vector<ll>
#define vvi vector<vi>
#define BITLE(n) (1LL<<((ll)n))
#define SHIFT_LEFT(n) (1LL<<((ll)n))
#define SUBS(s,f,t) ((s).substr((f)-1,(t)-(f)+1))
#define ALL(a) (a).begin(),(a).end()
using namespace std;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n,k;cin>>n>>k;

  ll now = (n-1)*(n-2)/2;
  if(now < k){
    cout<<-1<<endl;
    return 0;
  }
  vvi E(n);
  for(int i=1;i<n;i++){
    E[0].pb(i);
  }
  for(int i=1;i<n;i++){
    for(int j=i+1;j<n;j++){
      if(now != k){
	now--;
	E[i].pb(j);
      }
    }
  }

  ll ans = 0;
  for(int i=0;i<n;i++)
    ans += E[i].size();
  cout<<ans<<endl;
  for(int i=0;i<n;i++){
    for(auto e:E[i])
      cout<<i+1<<" "<<e+1<<endl;
  }
  return 0;
}


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

#define size_of_array(array) (sizeof(array)/sizeof(array[0]))

int main()
{
		int N;
		vector<int> L;
		int triagle_count = 0;

		cin >> N;
		for (int i = 0; i < N; i++) {
			int input;
			cin >> input;
			L.push_back(input);
		}
		sort(L.begin(), L.end());

		for (int i = N-1; i >= 2; i--) {
			for (int j = i-1; j >= 1; j=j-1){
				for (int k = j - 1; k >= 0; k--) {
					if (L[k] < (L[i] + L[j])) {
						if (L[i] < (L[j] + L[k]) && L[j] < (L[k] + L[i])) {
							triagle_count++;
						}
						else
						{
							break;
						}
					}
					else
					{
						break;
					}
				}
			}
		}

		cout << triagle_count << endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

class Rest {
	
	
	public String s;
	public int p;
	public int index;
	
	public Rest left;
	public Rest right;
	
	public Rest(String s, int p, int i) {
		this.s = s;
		this.p = p;
		this.index = i;
		this.left = this.right = null;
	}
};


public class Main {
	
	public static void showAll(Rest r) {
		if(r.left != null) {
			showAll(r.left);
		}
		System.out.println(r.index);
		
	/*		
		System.out.print(" ");
		System.out.print(r.s);
		System.out.print(" ");
		System.out.println(r.p);
	*/
		if(r.right != null) {
			showAll(r.right);
		}
	}
	
	public static int compare(String a, String b) 
	{
		for(int i=0; i < a.length() && i < b.length() ; i++) {
			if(a.charAt(i)<b.charAt(i)) {
				return -1;
			}
			if(a.charAt(i)>b.charAt(i)) {
				return 1;
			}
		}
		
		if(a.length() == b.length()) {
			return 0;
		}

		if(a.length()<b.length()) {
			return -1;
		} else {
			return 1;
		}
	
	}

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String buf;
		int count     = sc.nextInt();
		buf = sc.nextLine();

		Rest top = null;
		
		for(int i = 0; i < count; i++) {
			String s=sc.next();
			int p = sc.nextInt();
			
			Rest r = new Rest( s , p , i+1 );

			if(top == null) {
				top = r;
			} else {
				Rest tmp = top;

				while(true) {
					int ans = compare( tmp.s , r.s );
					if(ans == 1) {
						if(tmp.left == null) {
							tmp.left = r;
							break;
						}
						tmp = tmp.left;
					} else {
						if(ans == -1) {
							if(tmp.right == null) {
								tmp.right = r;
								break;
							}
							tmp = tmp.right;
						} else {

							if(r.p > tmp.p ) {
								if(tmp.left == null) {
									tmp.left = r;
									break;
								}
								tmp = tmp.left;
							} else {
								if(tmp.right == null) {
									tmp.right = r;
									break;
								}
								tmp = tmp.right;
							}
						}
					}
				}
			}
		}

		showAll(top);
	}
}


Measured memory_bytes: 21844
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin>>n;
    long long int arr[100001]={0};
    long long int sum=0;
    vector<int> v;
    for(int i=0;i<n;i++){
        int x;
        cin>>x;
        sum+=x;
        v.push_back(x);
        arr[x]++;
    }
    int q;
    cin>>q;
    for(int i=0;i<q;i++){
        int a,b;
        cin>>a>>b;
        sum=sum-(long long int)a*arr[a];
        sum=sum+(long long int)b*arr[a];
        arr[b]=arr[b]+arr[a];
        arr[a]=0;
        cout<<sum<<endl;
    }
}

Measured memory_bytes: 4612
import java.util.*;
import java.lang.*;
import java.io.*;

public class Main {
    public static void main(String args[]) {
        Scanner scan = new Scanner(System.in);
        String a = scan.next();
        String b = scan.next();
        String c = scan.next();

        System.out.print(a.charAt(0));
        System.out.print(b.charAt(1));
        System.out.print(c.charAt(2));
    }
}


Measured memory_bytes: 21716
#include <bits/stdc++.h>
using namespace std;
const double EPS = 1E-9;
const long long INF = 1000LL * 1000 * 1000 * 1000 * 1000 * 1000;
#define pb push_back
#define ll long long
int n;
int a[100000];
int main()
{
	scanf("%d" , &n);
	ll ans = 0;
	for(int i = 0; i < n; i++)
	{
		scanf("%d"  , &a[i]);
	}
	for(int i = 0; i < n - 1; i++)
	{
		ans += a[i] / 2;
		a[i] %= 2;
		ans += min(a[i + 1] , a[i]);
		a[i + 1] -= min(a[i + 1] , a[i]);
	}
	ans += a[n - 1] / 2;
	cout << ans;
}


Measured memory_bytes: 640