akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
 
#define ll                 long long
#define ull                unsigned long long
#define pii                pair<int, int>
#define pll                pair<ll, ll>
#define mp                 make_pair
#define ff                 first
#define ss                 second
#define sz(x)              (int) x.size()
#define all(v)             v.begin(), v.end()

template <typename T> inline void smin(T &a, T b) {a = a < b ? a : b;}
template <typename T> inline void smax(T &a, T b) {a = a > b ? a : b;}
 
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string> it) {cout << endl;}
template<typename T, typename... Args> void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " = " << a << ", ";
	err(++it, args...);
}
 
template <typename T> inline void Int(T &n) {
	n = 0; int f = 1; register int ch = getchar();
	for (; !isdigit(ch); ch = getchar()) if (ch == '-') f = -1;
	for (; isdigit(ch); ch = getchar()) n = (n << 3) + (n << 1) + ch - '0';
	n = n * f;
}
 
template <typename T, typename TT> inline void Int(T &n, TT &m) { Int(n); Int(m); }
template <typename T, typename TT, typename TTT> inline void Int(T &n, TT &m, TTT &l) { Int(n, m); Int(l); }

const int mod = (int) 1e9 + 7;
 
inline int add(int a, int b) {a += b; return a >= mod ? a - mod : a;}
inline int sub(int a, int b) {a -= b; return a < 0 ? a + mod : a;}
inline int mul(int a, int b) {return (ll) a * b % mod;}
 
const int inf = (int) 2e9 + 5;
const ll  Inf = (ll) 2e18 + 5;
const int N   = (int) 2e5 + 5;



int solve() {
    int a[4][4];
    for(int i = 1; i <= 3; i++) {
    	for(int j = 1; j <= 3; j++) {
    		Int(a[i][j]);
    	}
    }
    set<int> s;
    int n; Int(n);
    for(int i = 1; i <= n; i++) {
    	int x;
    	Int(x);
    	s.insert(x);
    }
    for(int i = 1; i <= 3; i++) {
    	int cnt = 0;
    	for(int j = 1; j <= 3; j++) {
            if(s.count(a[i][j])) cnt++;
    	}
    	if(cnt == 3) return printf("Yes\n");
    	cnt = 0;
    	for(int j = 1; j <= 3; j++) {
            if(s.count(a[j][i])) cnt++;
    	}
    	if(cnt == 3) return printf("Yes\n");
    }
    int cnt = 0;
    for(int i = 1; i <= n; i++) {
       if(s.count(a[i][i])) cnt++;
    }
    if(cnt == 3) return printf("Yes\n");
    cnt = 0;
    for(int i = 1; i <= n; i++) {
       if(s.count(a[i][4 - i])) cnt++;
    }
    if(cnt == 3) return printf("Yes\n");
    printf("No\n");
	return 0;
}
 
int main() {
	//ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	int test = 1, tc = 0;
	//Int(test);
	//cin >> test;
	while (test--) {
		//printf("Case %d: ", ++tc);
		solve();
	}
	return 0;
}


Measured memory_bytes: 256
import bisect,collections,copy,itertools,math,string
import sys
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())
def main():


    n = I()
    a = LI()

    mx = max(a)
    a.remove(mx)

    r = (float("inf"), -1)
    half = mx//2
    
    if mx%2 == 0:
        for x in a:
            sa = abs(x-half)
            if sa < r[0]:
                r = (sa, x)
    else:
        for x in a:
            sa = min(abs(x-half), abs(x-(half+1)))
            if sa < r[0]:
                r = (sa, x)

    ans = (mx, r[1])
    print(*ans)
            

                    


main()


Measured memory_bytes: 21232
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayDeque;
import java.util.Arrays;
import java.util.NoSuchElementException;

public class Main {
	public static void main(String[] args) throws FileNotFoundException {
		long t = System.currentTimeMillis();
		new Main().run();
		System.err.println(System.currentTimeMillis() - t);
	}

	void run() {
		Scanner sc = new Scanner();
		int n = sc.nextInt();
		int k = sc.nextInt();
		long[] x = new long[n];
		long[] y = new long[n];
		for (int i = 0; i < n; ++i) {
			x[i] = sc.nextLong();
			y[i] = sc.nextLong();
		}
		long ans = Long.MAX_VALUE;
		for (long x1 : x) {
			for (long x2 : x) {
				for (long y1 : y) {
					for (long y2 : y) {
						if (x1 >= x2 || y1 >= y2)
							continue;
						int cnt = 0;
						for (int i = 0; i < n; ++i) {
							if (x1 <= x[i] && x[i] <= x2 && y1 <= y[i] && y[i] <= y2) {
								++cnt;
							}
						}
						if (cnt >= k) {
							ans = Math.min(ans, (x2 - x1) * (y2 - y1));
						}
					}
				}
			}
		}
		System.out.println(ans);
	}

  class Scanner {
		private final InputStream in = System.in;
		private final byte[] buffer = new byte[1024];
		private int ptr = 0;
		private int buflen = 0;

		private boolean hasNextByte() {
			if (ptr < buflen) {
				return true;
			} else {
				ptr = 0;
				try {
					buflen = in.read(buffer);
				} catch (IOException e) {
					e.printStackTrace();
				}
				if (buflen <= 0) {
					return false;
				}
			}
			return true;
		}

		private int readByte() {
			if (hasNextByte())
				return buffer[ptr++];
			else
				return -1;
		}

		private boolean isPrintableChar(int c) {
			return 33 <= c && c <= 126;
		}

		private void skipUnprintable() {
			while (hasNextByte() && !isPrintableChar(buffer[ptr]))
				ptr++;
		}

		public boolean hasNext() {
			skipUnprintable();
			return hasNextByte();
		}

		public String next() {
			if (!hasNext())
				throw new NoSuchElementException();
			StringBuilder sb = new StringBuilder();
			int b = readByte();
			while (isPrintableChar(b)) {
				sb.appendCodePoint(b);
				b = readByte();
			}
			return sb.toString();
		}

		public long nextLong() {
			if (!hasNext())
				throw new NoSuchElementException();
			long n = 0;
			boolean minus = false;
			int b = readByte();
			if (b == '-') {
				minus = true;
				b = readByte();
			}
			if (b < '0' || '9' < b) {
				throw new NumberFormatException();
			}
			while (true) {
				if ('0' <= b && b <= '9') {
					n *= 10;
					n += b - '0';
				} else if (b == -1 || !isPrintableChar(b)) {
					return minus ? -n : n;
				} else {
					throw new NumberFormatException();
				}
				b = readByte();
			}
		}

		public int nextInt() {
			return (int) nextLong();
		}
	}

	static void tr(Object... objects) {
		System.out.println(Arrays.deepToString(objects));
	}

}


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

int main() {
 int N,M;
 cin >> N >> M;
 if(N == M) cout << "Yes" <<endl;
 else cout << "No" <<endl;


}


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

int main(){
  int q,a,b;
  string str,ch,p;
  char c;

  cin>>str;
  cin>>q;
  for(int i=0;i<q;i++){
    cin >> ch;
    if(ch=="print"){
      cin >> a >>b;
      for(int j = a; j<b+1;j++){
        cout << str[j];
      }
      cout << endl;
    }
    if(ch=="reverse"){
      cin >> a >> b;
      for(int j =a,k=b;j<(a+b+1)/2;j++,k--){
        swap(str[j],str[k]);
      }
    }
    if(ch=="replace"){
      cin >> a >> b >> p;
      for(int j=a,k=0;j<=b;j++,k++){
        str[j]=p[k];
        }
    }
  }
 return 0;
}


Measured memory_bytes: 3240
from collections import defaultdict
from bisect import bisect_right
INF = float('inf')
N, Ma, Mb = map(int, input().split())
a, b, c = [None] * N, [None] * N, [None] * N
for i in range(N):
    a[i], b[i], c[i] = map(int, input().split())
hN = N // 2
dic1 = defaultdict(lambda : INF)
for i in range(1 << hN):
    _a, _b, _c = 0, 0, 0
    for j in range(hN):
        if (i >> j) & 1:
            _a += a[j]
            _b += b[j]
            _c += c[j]
    if _c < dic1[(_a, _b)]:
        dic1[(_a, _b)] = _c
dic2 = defaultdict(lambda : INF)
for i in range(1 << (N - hN)):
    _a, _b, _c = 0, 0, 0
    for j in range(N - hN):
        if (i >> j) & 1:
            _a += a[hN+j]
            _b += b[hN+j]
            _c += c[hN+j]
    if _c < dic2[(_a, _b)]:
        dic2[(_a, _b)] = _c
ans = INF
for k in dic1:
    _a, _b = k
    v = dic1[k]
    for i in range(1, N+1):
        ans = min(ans, v + dic2[(Ma*i-_a,Mb*i-_b)])
ans = ans if ans < INF else -1
print(ans)

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

using namespace std;

int main() {
  string target;
  string pattern;
  string double_target;

  cin >> target >> pattern;

  double_target = target + target.substr(0, target.size() - 1);

  if(double_target.find(pattern) != string::npos) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}



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

using namespace std;
int main() {
  int cnt = 0;
  string n, a;
  cin >> a;
  for(int i = 0; i < a.size(); i++) {
    if(a[i] >= 'a' && a[i] <= 'z') a[i] = a[i] - 'a' + 'A';
  }
  while(cin >> n && n != "END_OF_TEXT") {
    for(int i = 0; i < n.size(); i++) {
      if(n[i] >= 'a' && n[i] <= 'z') n[i] = n[i] - 'a' + 'A';
    }
    if(n == a) cnt++;
  }
  cout << cnt << endl;
  return 0;

}



Measured memory_bytes: 3176
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define pb push_back
#define vll vector<ll>
#define pll pair<ll,ll>
#define vpll vector<pll>
#define ub upper_bound
#define lb lower_bound
#define all(v) ((v).begin()),((v).end())
#define allr(v) ((v).rbegin()),((v).rend())
#define ff first
#define ss second
#define mp make_pair
#define pll pair<ll,ll> 
#define fo(i,n) for(ll i=0;i<n;i++)
#define foa(i,s,e) for(ll i=(s);i<e;i++)
#define fod(i,s,e) for(ll i= (s);i>=(e);i--)
#define max3(a,b,c) max(max(a,b),c)
#define min3(a,b,c) min(min(a,b),c)
#define deb(x) cerr<<#x<<' '<<'='<<' '<<x<<'\n'
#define sz(x) (ll)(x.size())
#define ANS cout<<ans<<'\n'
#define YES cout<<"YES\n"
#define NO cout<<"NO\n"
#define Yes cout<<"Yes\n"
#define No cout<<"No\n"
const ld pi = 3.14159265358979323846;
ll MOD = 1e9 + 7;
//ll MOD = 998244353;
const char nl = '\n';
const ll inf = 1e15;
#define fill(a,b) memset(a, b, sizeof(a))
#define setbits(x) __builtin_popcountll(x)
#define print2d(dp,n,m) fo(i, n){fo(j, m)cout<<dp[i][j]<<" ";cout<<"\n";}
ll nxt(){ll x; cin >> x; return x;}
ll mul(ll x,ll y){
    return (1ll* (x%MOD)*(y%MOD));
}
ll modpow(ll x,ll y){ll z=1;while(y>0){if(y%2)z=mul(z,x);x =mul(x,x) ;y/=2;}return z;}
ll power(ll x,ll y){ll z=1;while(y>0){if(y%2)z=z*x;x =x*x ;y/=2;}return z;}
ll gcd(ll a,ll b){if(a<b) return gcd(b,a);if(b==0) return a;return gcd(b,a%b);} 
ll min(ll a,ll b){if(a<b)return a;return b;}
ll max(ll a,ll b){if(a>b)return a;return b;}
ll sq(ll a){
    ll ans = (1ll*a*a);
    return ans;
}

void solve(){
    ll n, w;
    cin >> n >> w;
    vll wt(n), val(n);
    fo(i, n){
        cin >> wt[i] >> val[i];
    }
    ll s =  0;
    for(ll x : val)s+= x;
    vll dp(s + 1, inf);
    dp[0] = 0;
    fo(i, n){
        fod(j, s - val[i], 0){
            dp[j + val[i]] = min(dp[j + val[i]], dp[j] + wt[i]);
        }
    }
    fod(i, s, 0){
        if(dp[i] <= w){
            cout << i << nl;
            break;
        }
    }
}
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0),cout.tie(0);
    #ifndef ONLINE_JUDGE
    freopen("inputf.txt" , "r" , stdin) ;
    freopen("outputf.txt" , "w" , stdout) ;
    freopen("error.txt" , "w" , stderr) ;
    #endif
    ll TC = 1;
    //cin>>TC;
    while(TC--){
        solve();
    }
    cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
}


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


#define optimize() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define endl '\n'
// User defined sizeof macro
# define my_sizeof(type) ((char *)(&type+1)-(char*)(&type))


int main()

{
    optimize();
    int n;
    cin>>n;
    if(n==0) cout<<"1";
    else cout<<"0";













    return 0;
}





Measured memory_bytes: 3648
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cassert>
#include<vector>
#include<map>
#define ll long long
using namespace std;
inline ll read(){
	ll re=0,flag=1;char ch=getchar();
	while(!isdigit(ch)){
		if(ch=='-') flag=-1;
		ch=getchar();
	}
	while(isdigit(ch)) re=(re<<1)+(re<<3)+ch-'0',ch=getchar();
	return re*flag;
}
ll n,vis[200010],pri[100010],cntp,mark;
map<ll,ll>big;
void init(){
	ll i,j,k;vis[1]=1;
	for(i=2;i<=100000;i++){
		if(!vis[i]){pri[++cntp]=i;big[(ll)i*(ll)i]=i;}
		for(j=1;j<=cntp;j++){
			k=i*pri[j];if(k>100000) break;
			vis[k]=1;
			if(i%pri[j]==0) break;
		}
		if(i==3000) mark=cntp;
	}
}
vector<ll>f1,f2;bool cb=0;
ll cur[100010],inv[100010];
map<ll,ll>s;
void F(ll x,ll num){
	if(x==1){cur[num]=inv[num]=1e15;cb=1;return;}
	ll i,cnt,flag=0;
	f1.clear();f2.clear();
	for(i=1;i<=mark;i++){
		if(x%pri[i]) continue;
		cnt=0;
		while(x%pri[i]==0) cnt++,x/=pri[i];
		if(cnt%3==1) f1.push_back(pri[i]),flag=1;
		if(cnt%3==2) f2.push_back(pri[i]),flag=1;
	}
//	cout<<"mid "<<x<<' '<<num<<'\n';
	if(x!=1){
		flag=1;
		if(big.count(x)) f2.push_back(big[x]);
		else f1.push_back(x);
	}
//	cout<<"kkk "<<flag<<' '<<f1.size()<<' '<<f2.size()<<'\n';
	if(!flag){cur[num]=inv[num]=1e15;cb=1;return;}
	ll rer=1,rel=1;
	for(auto i:f1) rer*=(i*i),rel*=i;
	for(auto i:f2) rer*=i,rel*=(i*i);
	if(s.count(rel)) s[rel]++;
	else s[rel]=1;
	cur[num]=rel;inv[num]=rer;
//	cout<<"final "<<num<<' '<<cur[num]<<' '<<inv[num]<<'\n';
}
ll rk[100010];
inline bool cmp(ll l,ll r){
	return cur[l]<cur[r];
}
int main(){
	init();
	n=read();ll i,tmp,j,de=0,tot=0;
	for(i=1;i<=n;i++){
		tmp=read();
		F(tmp,i);rk[i]=i;
	}
	sort(rk+1,rk+n+1,cmp);
	for(j=1;j<=n;j++){
//		cout<<j<<' '<<rk[j]<<' '<<cur[rk[j]]<<' '<<inv[rk[j]]<<'\n';
		if(cur[rk[j]]==1e15) continue;
		tot++;
		if(cur[rk[j]]==cur[rk[j-1]]) continue;
		if(inv[rk[j]]>=cur[rk[j]]&&s.count(inv[rk[j]])){
//			cout<<"add de "<<'\n';
			de+=min(s[cur[rk[j]]],s[inv[rk[j]]]);
		}
	}
	cout<<tot-de+(cb!=0)<<'\n';
}
	

Measured memory_bytes: 11264
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) begin(v),end(v)
#define fi first
#define se second
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
using ll = long long;
using pii = pair<int, int>;
constexpr ll INF = 1ll<<30;
constexpr ll longINF = 1ll<<60;
constexpr ll MOD = 1000000007;
constexpr bool debug = 0;
//---------------------------------//

namespace tk {
template<typename T>
T gcd(const T & a, const T &b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}

template<typename T>
T lcm(const T & a, const T & b) {
	return a / gcd(a, b) * b;
}

template<typename T>
T extgcd(const T & a, const T & b, T &x, T &y) {
	T a0 = a, a1 = 1, a2 = 0, b0 = b, b1 = 0, b2 = 1;
	while (b0 > 0) {
		T q = a0 / b0, r = a0 % b0;
		T nb1 = a1 - q * b1, nb2 = a2 - q * b2;
		a0 = b0; b0 = r;
		a1 = b1; b1 = nb1;
		a2 = b2; b2 = nb2;
	}
	x = a1;
	y = a2;
	return a0;
}
}

using pll = pair<ll, ll>;
vector<pll> prime_factorization(ll n) {
	vector<pll> res;
	
	for (ll i = 2; i * i <= n; i++) {
		if (n % i == 0) res.emplace_back(i, 0);
		while (n % i == 0) {
			n /= i;
			res.back().second++;
		}
	}
	if (n > 1) res.emplace_back(n, 1);
	
	return res;
}

int main() {
	ll N;
	cin >> N;
	if (N <= 10000) {
		ll k = 1;
		while (true) {
			if (k * (k + 1) % N == 0) {
				cout << k << endl;
				return 0;
			}
			++k;
		}
	}
	N *= 2;
	
	// (1 + k)k = l N (l は正整数) で最小の k
	
	vector<pll> pf = prime_factorization(N);
	
	vector<ll> powpf(pf.size(), 1);
	REP(i, pf.size()) {
		REP(j, pf[i].second) powpf[i] *= pf[i].first;
	}
	
	ll ans = longINF;
	REP(s, 1 << pf.size()) {
		ll alpha = 1, beta = 1;
		REP(i, pf.size()) {
			if (s >> i & 1) alpha *= powpf[i];
			else beta *= powpf[i];
		}
		// ここで gcd(alpha, beta) = 1
		// k = m1 alpha
		// k + 1 = m2 beta
		// 1 = m2 beta - m1 alpha
		ll m1, m2;
		tk::extgcd(beta, alpha, m2, m1);
		m1 = abs(m1);
		m2 = abs(m2);
		
		// cout << m1 << ", " << m2 << endl;
		
		if (m1 > 0 && m2 > 0 && m1 * alpha == m2 * beta - 1) {
			ll k = m1 * alpha;
			chmin(ans, k);
		}
		
		// k = m1 alpha
		// k - 1 = m2 beta
		// -1 = m2 beta - m1 alpha
		// 1 = -m2 beta + m1 alpha
		tk::extgcd(beta, alpha, m2, m1);
		m1 = abs(m1);
		m2 = abs(m2);
		
		if (m1 > 0 && m2 > 0 && m1 * alpha == m2 * beta + 1) {
			ll k = m1 * alpha;
			chmin(ans, k);
		}
	}
	
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
 
int L, R;
 
int main() {
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	cin>>L>>R;
	if(R-L >= 2018)	cout<<0;
	else{
		int ans = 987654321;
		// L < R is guaranteed;
		L %= 2019;
		R %= 2019;
		for(int i = L; i<=R;i++)
			for(int j = i+1;j<=R;j++)
				ans = min(ans, i * j % 2019);
		cout<<ans;
	}
	return 0;
}

Measured memory_bytes: 256
program c171

implicit none
integer(16) :: n, m, l
integer :: i, j
character(len=12) :: a, b

read *, n

i = 0

do while (n > 26)
 i = i + 1
 m = mod(n,26)
 if (m == 0) then
   m = 26
 end if
  a(i:i) = char(96 + m)
  n = n - m
  n = n / 26
end do

a(i+1:i+1) = char(96 + n)

do j = 1, i+1
 b(j:j) = a(i+2-j:i+2-j)
end do

if (i+1 == 12) then
 print '(A12)', trim(adjustl(b))
else if (i+1 == 11) then
 print '(A11)', trim(adjustl(b))
else if (i+1 == 10) then
 print '(A10)', trim(adjustl(b))
else if (i+1 == 9) then
 print '(A9)', trim(adjustl(b))
else if (i+1 == 8) then
 print '(A8)', trim(adjustl(b))
else if (i+1 == 7) then
 print '(A7)', trim(adjustl(b))
else if (i+1 == 6) then
 print '(A6)', trim(adjustl(b))
else if (i+1 == 5) then
 print '(A5)', trim(adjustl(b))
else if (i+1 == 4) then
 print '(A4)', trim(adjustl(b))
else if (i+1 == 3) then
 print '(A3)', trim(adjustl(b))
else if (i+1 == 2) then
 print '(A2)', trim(adjustl(b))
else
 print '(A1)', trim(adjustl(b))
end if

end program c171

Measured memory_bytes: 2832
# -*- coding: utf-8 -*-
x, y, a, b, c = map(int, input().split())
p = list(map(int, input().split()))
q = list(map(int, input().split()))
r = list(map(int, input().split()))

P = sorted(p, reverse=True)[:x]
Q = sorted(q, reverse=True)[:y]

P.extend(Q)
P.extend(r)

list = sorted(P, reverse=True)[:x+y]
ans = sum(list)

print(ans)


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

using namespace std;
#define ll long long
#define ull unsigned long long
#define mp make_pair
typedef pair<int, int> pii;
typedef priority_queue<int, vector<int>, greater<int> > small_heap;
typedef priority_queue<int> big_heap;
int n, k;
ll s[200009];
map<ll, ll> mmp;

int main() {
    scanf("%d%d", &n, &k);
    for (int i = 1; i <= n; i++) {
        int x;
        scanf("%d", &x);
        s[i] = s[i - 1] + x;
    }
    mmp[0] = 1;
    ll ans = 0;
    int l = 0;
    for (int i = 1; i <= n; i++) {
        if (i >= k) {
            mmp[(s[l] - l + k) % k]--, l++;
        }
        ans += mmp[(s[i] - i + k) % k];
        mmp[(s[i] - i + k) % k]++;
    }
    printf("%lld\n", ans);
    return 0;
}

Measured memory_bytes: 14336
#include<iomanip>
#include<limits>
#include<thread>
#include<utility>
#include<iostream>
#include<string>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<stack>
#include<queue>
#include<cmath>
#include<numeric>
#include<cassert>
#include<random>
#include<chrono>
#include<unordered_set>
#include<unordered_map>
#include<fstream>
#include<list>
#include<functional>
#include<bitset>
#include<complex>
#include<tuple>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef pair<ll,ll> pll;
typedef long double D;
#define F first
#define S second
const ll E=1e18+7;
const ll MOD=1000000007;


int main(){
    ll m,k;
    cin>>m>>k;
    if(k>=(1LL<<m) || (m==1 && k==1)){cout<<-1<<endl; return 0;}
    if(k==0){
        for(ll i=0;i<(1LL<<m);i++){
            cout<<i<<" "<<i;
            if(i+1!=(1LL<<m)){cout<<" ";}
        }
        cout<<endl;
    }
    else{
        for(ll i=0;i<(1LL<<m);i++){
            if(i==k){continue;}
            cout<<i<<" ";
        }
        cout<<k<<" ";
        for(ll i=(1LL<<m)-1;i>=0;i--){
            if(i==k){continue;}
            cout<<i<<" ";
        }
        cout<<k<<endl;
    }
    
    return 0;
}


Measured memory_bytes: 1792
import java.util.Scanner;
public class Main {
    public static void main (String[] args) {
	Scanner scan = new Scanner(System.in);
	double v, y, n;
	while (scan.hasNext()) {
	    v = Double.parseDouble(scan.nextLine());
	    y = v * v / (2 * 9.8);
	    n = Math.ceil((y + 5) / 5);
	    System.out.println((int)n);
	}
    }
}

Measured memory_bytes: 26008
line1 = gets.split(' ')
line2 = gets.split(' ')
 
newline2 = line2.sort {|a, b| b.to_i <=> a.to_i } 
counter = 0
h = 0
 
while h <= line1[0].to_i - 3
  i = 1
  while i <= line1[0].to_i - 2
    j = 1
    while i + j <= line1[0].to_i - 1
      if newline2[h].to_i >= newline2[i].to_i + newline2[i+j].to_i || h > i || h > i+j
      else
        if newline2[h].to_i == newline2[i].to_i || newline2[h].to_i == newline2[i+j].to_i || newline2[i].to_i == newline2[i+j].to_i
        else
          counter += 1
        end
      end
      j += 1
    end
    i += 1
  end
  h += 1
end
 
 
p counter

Measured memory_bytes: 14284
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<utility>
#include<cmath>
#include<climits>
#include<queue>
#include<stack>
#include<numeric>
#include<set>
#include<iomanip>
#include<map>
#include<type_traits>
#include<tuple>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
#define rep(i,N) for(ll (i)=0;(i)<(N);(i)++)
const int mod = 1000000007;

int main(){
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i, n) cin >> a[i];
  int count = 0;
  int two = 0;
  rep(i, n){
    if(a[i] % 4 == 0) count++;
    else if(a[i] % 2 == 0) two++;
  }
  if(two == n)  {
    cout << "Yes" << endl;
    return 0;
  }
  two = max(0, two - 1);

  if(count >= (n - count - 1 - two) && count > 0)  cout << "Yes" << endl;
  else cout << "No" << endl;
}


Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <queue>

int main() {
  unsigned int N, M;
  std::cin >> N >> M;

  std::vector<std::vector<unsigned int>> day_jobs(100000 + 5);
  for (unsigned int i = 0; i < N; ++i) {
    unsigned int a, b;
    std::cin >> a >> b;
    day_jobs.at(a).push_back(b);
  }

  std::priority_queue<unsigned int> job_queue;
  unsigned long long sum = 0;
  for (unsigned int i = 1; i <= M; ++i) {
    for (auto x : day_jobs.at(i)) {
      job_queue.push(x);
    }
    if (!job_queue.empty()) {
      sum += job_queue.top();
      job_queue.pop();
    }
  }

  std::cout << sum << std::endl;

  return 0;
}


Measured memory_bytes: 5632
using System;
using System.Collections.Generic;
using System.Linq;

namespace test
{
    class Program
    {
        static void Main(string[] args)
        {
            var S = Read();
            var N = S.Length;
            var numB = 0;
            for (int i = 0; i < N; i++) if (S[i] == 'B') numB++;
            if (numB == N || numB == 0)
            {
                Console.WriteLine(0);
                return;
            }
            var ans = 0L;
            var posR = 1;
            for (int i = N - 1; i >= 0; i--)
            {
                if (S[i] == 'B')
                {
                    ans += N - i - posR;
                    posR++;
                }
            }

            Console.WriteLine(ans);
            Console.ReadLine();
        }

        static string Read() { return Console.ReadLine(); }
        static int ReadInt() { return int.Parse(Read()); }
        static long ReadLong() { return long.Parse(Read()); }
        static int[] ReadArrayInt() { return Read().Split(' ').Select(s => int.Parse(s)).ToArray(); }
        static long[] ReadArrayLong() { return Read().Split(' ').Select(s => long.Parse(s)).ToArray(); }
    }
}

Measured memory_bytes: 11616
#include <iostream>
#include <string>
using namespace std;
int main(){
    string s;
    cin >> s;
    if (s == "SUN") cout << 7;
    else if (s == "MON") cout << 6;
    else if (s == "TUE") cout << 5;
    else if (s == "WED") cout << 4;
    else if (s == "THU") cout << 3;
    else if (s == "FRI") cout << 2;
    else if (s == "SAT") cout << 1;
    return 0;
}

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

int main()
{
    int n,k;
    bool sunuke[101];

    cin>>n>>k;
    for (int i = 0; i < n; i++)
    {
        sunuke[i]=false;
    }


    for (int j  = 0; j < k; j++)
    {
        int d;
        cin>>d;
        for (int i = 0; i < d; i++)
        {
            int a;
            cin>>a;
            sunuke[a-1]=true;
        }
        
    }

    int ans=0;
    for (int i = 0; i < n; i++)
    {
        if(sunuke[i]==false){
            ans++;
        }
    }

    cout<<ans;

    return 0;    
}

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

int N;

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

    pair< pair<string, int>, int >  ans[100];
    for(int i=0;i<N;i++)    ans[i] = make_pair( make_pair(S[i], P[i]), i+1);

    sort(ans, ans+N);

    for(int i=0;i<N;i++){
        int j = i+1;
        while( ans[j].first.first == ans[i].first.first ){
            j++;
            if( N <= j ) break;
        }
        int end = j - 1;
        while( i <= end ){
            cout << ans[end].second << endl;
            end--;
        }
        i = j - 1;
    }
}

Measured memory_bytes: 256
a, v = map(int, input().split())
b, w = map(int, input().split())
t = int(input())

if a > b:
    a = a - v * t
    b = b - w * t
    print('YES' if a <= b else 'NO')
elif a < b:
    a = a + v * t
    b = b + w * t
    print('YES' if a >= b else 'NO')



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

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

	int result = 0;
	sort(d.begin(), d.end());
	if(d.size() % 2 == 0) {
		result = d[N/2] - d[N/2 - 1];
	}

	cout << result << endl;
}


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

#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = (n)-1; i >= 0; i--)
#define rep1(i,n) for(int i = 1; i <= (n); i++)
#define rrep1(i,n) for(int i = (n); i > 0; i--)

#define ll long long
#define pi pair<int, int>
#define pll pair<ll, ll>

#define MOD 1000000007
#define INF 1000000000000000LL

using namespace std;

int main(){
  int n;cin>>n;
  vector<ll> a(n+1);
  rep(i, n+1)cin>>a[i];

  if(n==0 && a[0]!=1) { cout<<-1<<endl; return 0; }
  if(n!=0 && a[0]!=0) { cout<<-1<<endl; return 0; }

  vector<ll> limit(n+1);
  limit[n] = a.back();
  rrep(i, n){
    limit[i]=a[i]+limit[i+1];
  }

  ll result=0;
  ll now=1;
  rep(i, n+1){
    result += now;
    now -= a[i];
    if(now<0) { cout<<-1<<endl; return 0; }
    now = min<ll>(now*2, limit[i+1]);
  }

  cout<<result<<endl;

  return 0;
}


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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
const ull mod = 1e9 + 7;
#define REP(i,n) for(int i=0;i<(int)n;++i)

int main(){
    string S;
    cin >> S;
    REP(i, S.length()){
        if(S[i] == '1'){
            S[i] = '9';
        }else if(S[i] == '9'){
            S[i] = '1';
        }
    }
    cout << S << endl;
    return 0;
}

Measured memory_bytes: 256
n, m = map(int, input().split())
AB = [[int(i) for i in input().split()] for i in range(n)]
CD = [[int(i) for i in input().split()] for i in range(m)]

for ab in AB:
    dist = [abs(ab[0] - cd[0]) + abs(ab[1] - cd[1]) for cd in CD]
    print(dist.index(min(dist)) + 1)

Measured memory_bytes: 3064
#include "bits/stdc++.h"
using namespace std;

int f(long long a,int n,int m,int b)
{
    int s[3]={7,5,3};
    for(int i=0;i<3;i++){
        if(a*10+s[i]<=n)
            m=f(a*10+s[i],n,m,(b%s[i]==0?b:b*s[i]));
    }
    if(b%3==0&&b%5==0&&b%7==0) return m+1;
    return m;
}

int main()
{
    int n,m=0;
    cin >> n;
    long long a=0;
    int b=1;
    cout << f(a,n,m,b) << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define For(i,a,b) for (int i=a;i<=b;i++)
#define fi first
#define se second
#define pb push_back
#define dscan(x) scanf("%d", &x)
#define lldscan(x) scanf("%lld", &x)
#define task "C"
#define rep(i,x) for (int i=1;i<=x;i++)
using namespace std;

/*~~~~~~~~~~~~~~~~~~~~SET YOUR MAXIMUM N VALUE HERE~~~~~~~~~~~~~~~~~~~~*/

const ll maxn = 100007;
const ll inf = 1000000007;

/*~~~~~~~~~~~~~~~~~~~~VARIABLES~~~~~~~~~~~~~~~~~~~~*/

int n;
ll a[maxn], b[maxn];
ll res=0;

/*~~~~~~~~~~~~~~~~~~~~FUNCTIONS & PROCEDURES~~~~~~~~~~~~~~~~~~~~*/

void open() {
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    //freopen(task".inp","r",stdin);
    //freopen(task".out","w",stdout);
}

void read() {
    open();
    dscan(n);
    rep(i,n+1) lldscan(a[i]);
    rep(i,n) lldscan(b[i]);
}

void solve() {
    rep(i,n) {
        ll tg=min(a[i],b[i]);
        b[i]-=tg; a[i]-=tg;
        res+=tg;
        tg=min(a[i+1],b[i]);
        a[i+1]-=tg; b[i]-=tg;
        res+=tg;
    }
    printf("%lld\n", res);
}

/*~~~~~~~~~~~~~~~~~~~~MAIN~~~~~~~~~~~~~~~~~~~~*/

int main()
{
    read();
    solve();
    return 0;
}

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

#define int long long

const int N = 3e3 + 10;

int n , m , k , Map[N][N] , dp[N][N][4][2];

int F(int x , int y){
	int Max = 0;
	for(int p = 0; p <= 3; p++) Max = max(Max , dp[x][y][p][0]);
	for(int p = 0; p <= 3; p++) Max = max(Max , dp[x][y][p][1]);
	return Max;
}

signed main(){
	scanf("%lld %lld %lld" , &n , &m , &k);
	for(int u , v , w , i = 1; i <= k; i++)
		scanf("%lld %lld %lld" , &u , &v , &w) , Map[u][v] = w;
	for(int i = 1; i <= n; i++)
		for(int j = 1; j <= m; j++){
			int Max = F(i - 1 , j);
			dp[i][j][0][0] = max(Max , dp[i][j - 1][0][0]);
			dp[i][j][1][1] = Max + Map[i][j];
			for(int p = 1; p <= 3; p++){
				dp[i][j][p][0] = max(dp[i][j - 1][p][0] , dp[i][j - 1][p][1]);
				dp[i][j][p][1] = max(max(dp[i][j - 1][p - 1][0] , dp[i][j - 1][p - 1][1]) + Map[i][j] , dp[i][j][p][1]);
			}
		}
	int ans = 0;
	for(int p = 1; p <= 3; p++) ans = max(ans , max(dp[n][m][p][0] , dp[n][m][p][1]));
	printf("%lld" , max(ans , dp[n][m][0][0]));
	return 0;
}

Measured memory_bytes: 638316
#include<bits/stdc++.h>
#define O 2000
#define M 4009
#define N 200009
using namespace std;
const int mod = 1e9+7;
int n, a[N],b[N];
int dp[M][M],C[M][M],Ans;
int main() {
    scanf("%d",&n);
    for(int i = 1; i <= n; i++) scanf("%d%d",&a[i],&b[i]),dp[a[i]+O][b[i]+O]++;
    for(int i = 2*O; i >= 0; i--) {
        for(int j = 2*O; j >= 0; j--) {
			dp[i][j] = ((dp[i][j] + dp[i+1][j]) % mod + dp[i][j+1]) % mod;
        }
    }
    C[0][0] = 1;
    for(int i = 0; i <= 2*O; i++) {
        for(int j = 0; j <= 2 * O; j++) {
            if(i > 0) C[i][j] = (C[i-1][j] + C[i][j]) % mod;
            if(j > 0) C[i][j] = (C[i][j-1] + C[i][j]) % mod;
        }
    }
    for(int i = 1; i <= n; i++) Ans = (Ans + dp[O-a[i]][O-b[i]]) % mod;
    for(int i = 1; i <= n; i++) Ans = (Ans - C[b[i]*2][a[i]*2] % mod + mod) % mod;
    Ans = (long long)(Ans) * 500000004 % mod;
    printf("%lld\n",Ans);
	return 0;
}

Measured memory_bytes: 130704
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        
        Scanner scan = new Scanner(System.in);
        int vertical = scan.nextInt();
        int side = scan.nextInt();
 
        vertical = vertical - 1;
        side = side - 1;
        
        int ans = vertical * side;
        
        System.out.println(ans);
        
    }
}

Measured memory_bytes: 22868
import java.util.*;

class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String K = sc.next();
		int N = K.length();
		int D = Integer.parseInt(sc.next());
		int mod = 1_000_000_007;

		int[][][] dp = new int[N+1][D][2];
		dp[0][0][0]=1;
		for (int i=0;i<N;i++) {
			for (int j=0;j<D;j++) {
				for (int k=0;k<10;k++) {
					if (K.charAt(i)-48<k) {
						dp[i+1][(j+k)%D][0]+=0;
						dp[i+1][(j+k)%D][1]=(dp[i+1][(j+k)%D][1]+dp[i][j][1])%mod;
					} else if (K.charAt(i)-48==k) {
						dp[i+1][(j+k)%D][0]=(dp[i+1][(j+k)%D][0]+dp[i][j][0])%mod;
						dp[i+1][(j+k)%D][1]=(dp[i+1][(j+k)%D][1]+dp[i][j][1])%mod;
					} else if (K.charAt(i)-48>k) {
						dp[i+1][(j+k)%D][0]+=0;
						dp[i+1][(j+k)%D][1]=(dp[i+1][(j+k)%D][1]+dp[i][j][1]+dp[i][j][0])%mod;
					}
				}
			}
		}
		System.out.println((dp[N][0][0]+dp[N][0][1]+mod-1) % mod);
	}
}

Measured memory_bytes: 56944
#define _USE_MATH_DEFINES
#define INF 10000000
#include <iostream>
#include <sstream>
#include <cmath>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>
#include <list>

using namespace std;

typedef long long ll;
typedef pair <int,int> P;
typedef pair <P,P> PP;
typedef pair <int,PP> PPP;

static const double eps = 1e-8;

int main(){
	int n,m;
	while(~scanf("%d %d",&n,&m)){
		if(n==m && m==0) break;
		int* bag = new int[n];
		for(int i=0;i<n;i++){
			scanf("%d",bag+i);
		}

		sort(bag,bag+n,greater<int>());

		int sum = 0;
		for(int i=1;i<=n;i++){
			if(i%m==0) continue;
			sum += bag[i-1];
		}
		printf("%d\n",sum);
		delete[] bag;
	}
}

Measured memory_bytes: 3124
#include<bits/stdc++.h>
#define REP(i,n) for(int i = 0; i < n; ++i)
#define REPR(i,n) for(int i = n; i >= 0; --i)
#define FOR(i,a,b) for(int i = (a); i < (b); ++i)
#define FORR(i, a, b) for(int i = b-1;i >= a;--i)
#define p(s) cout << (s) << endl
#define p2(s,t) cout << (s) << " " << (t) << endl 
#define ALL(v) (v).begin(), (v).end()
#define m0(x) memset(x,0,sizeof(x))
typedef long long ll;

using namespace std;

static const ll MOD  = 1e9 + 7;
static const ll INF  = 1e18;
static const ll MAX_N = 10000;
static const ll MAX_M = 10000;

static const int White = 0;
static const int Gray = 1;
static const int Black = 2;

void pvector(vector<int> A){
    cout << "[vector]";
    for(int i = 0; i < A.size(); i++){
        cout << A[i] << " ";
    }
    cout << endl;
}

int main(){
    int N, A, B, C, ans = 0, cnt = 0;
    cin >> A >> B >> C;
    int M = max(A,B);
    M = max(M, C);
    p(A + B + C - M);
}

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

int main(void)
{
    string s, t;
    cin >> s >> t;

    s += t.at(t.size()-1);
    if(s == t){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 3632
///                ..:: In The Name Of God ::..
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <set>
#include <map>
#include <queue>
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstring>
#include <cctype>
#include <cassert>
#include <limits>
#include <functional>
#include <iomanip>
#include <complex>
#include <bitset>
#include <stack>
#include <bits/stdc++.h>

#define REP(i, n) for (int i = 0; i < n; i++)
#define endl '\n'
#define int ll
#define vi vector<int>
#define vii vector<pii>

typedef long long ll;

using namespace std;

signed main(){
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    int N, K;
    cin >> N >> K;
    if(K == 1){
        cout << 0 << endl;
    }
    else{
        cout << N-K << endl;
    }
    return 0;
}

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

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

  int k = 0;
  for (int i = 0; i < n; i++) {
    if (p[i] != i + 1) k++;
  }

  if (k <= 2) {
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define re(x) cout<<(#x)<<" is "<<(x)<<"\n"; 
#define gif(a,b) ((a)/(b)+((a)%(b)?1:0))
using namespace std;

int32_t main()
{
	IOS
	int T = 1; 
	//cin >> T;  
	for (int t = 0; t < T; ++t)
	{
		string s;
		cin >> s;
		int n = 3;
		int ans = 0, Ans = 0;
		while(n--)
		{
			if(s[n] == 'R')
				ans++;
			else
				ans = 0;
			Ans = max(ans, Ans);
		}
		cout << Ans <<"\n";
	}
	return 0;
}
//if not working? go ahead.


Measured memory_bytes: 3652
#include<bits/stdc++.h>
using namespace std;
#define fr first
#define sc second
typedef long long ll ;
typedef double ld;
typedef pair<int,int> p2;
typedef pair<ll,p2> p3;
typedef vector<int> vi;
const ll  Mod = 7 + 1e9;
const ll  INF32 = 5 + 2e9;
const ll  INF64 = 5 + 1e18;
const ll  MAX = 5+ 1e4;

ll N,D,dp[MAX][105][2];
string K;

ll Try(int i,int sum,bool eq)
{
    if(i==N)
        return !sum;
    ll &r = dp[i][sum][eq];
    if( r != -1 )
        return r;
    r = 0;
    int cur = K[i] - '0';
    for(int j =(eq ? cur : 9); j>=0; j--)
        r = (r + Try(i+1,(sum + j)%D, eq && j == cur ))%Mod;
    return r;
}

int main()
{
    cin >> K >> D;
    N = K.size();
    memset(dp,-1,sizeof(dp));
    cout << (Try(0,0,1)-1 + Mod)%Mod << endl;
    return 0;
}


Measured memory_bytes: 17408
#include <iostream>
#include <cmath>
#include <string>
#include <vector>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <queue>
#include <algorithm>
using namespace std;

int inf = 1000000001;
int N, M, L;
int C[301][301];
int s[90000], t[90000];

int d[301][301];

int LC[301][301];
int Ld[301][301];

void wf(int G[301][301], int D[301][301]) {
    for (int i = 1; i <= N; ++i) {
        for (int j = 1; j <= N; ++j) {
            D[i][j] = G[i][j];
        }
    }

    for (int k = 1; k <= N; ++k) {
        for (int i = 1; i <= N; ++i) {
            for (int j = 1; j <= N; ++j) {
                if (D[i][j] > D[i][k] + D[k][j]) {
                    D[i][j] = D[i][k] + D[k][j];
                }
            }
        }
    }
}

int main() {
    cin >> N >> M >> L;

    fill((int *)C, (int *)C + 301 * 301, inf);

    for (int i = 1; i <= M; ++i) {
        int a, b, c;
        cin >> a >> b >> c;
        C[a][b] = C[b][a] = c;
    }

    int Q;
    cin >> Q;

    for (int i = 1; i <= Q; ++i) {
        cin >> s[i] >> t[i];
    }

    wf(C, d);

    fill((int *)LC, (int *)LC + 301 * 301, inf);

    for (int i = 1; i <= N - 1; ++i) {
        for (int j = i + 1; j <= N; ++j) {
            if (d[i][j] <= L) {
                LC[i][j] = LC[j][i] = 1;
            }
        }
    }

    wf(LC, Ld);

    for (int i = 1; i <= Q; ++i) {
        cout << (Ld[s[i]][t[i]] == inf ? -1 : Ld[s[i]][t[i]] - 1) << endl;
    }

    return 0;
}


Measured memory_bytes: 2688
N, Q = gets.split(" ").map(&:to_i)

tree = {} # ハッシュで木を表現
(N - 1).times do 
    a, b = gets.split(" ").map(&:to_i)
    tree[a] ||= [] #tree[a]がnilなら[]を代入して、すでに値をもっていたら何もしない
    tree[a] << b
    tree[b] ||= []
    tree[b] << a
end

score = Array.new(N + 1, 0)
Q.times do 
    p, x = gets.split(" ").map(&:to_i)
    score[p] += x #計算回数を減らすため取りあえず根の部分だけ得点を加える
end

q = [[1, score[1]]] #キュー
until q.empty? do
    n, s = q.shift #dequeue
    next if tree[n].nil?
    score[n] = s
    tree[n].each do |c|
        q << [c, s + score[c]] #enqueue この部分で親の得点を加算している
    end
    tree[n] = nil #一度訪れた節は2度数えないようにnilにしている
end

puts score[1..-1].join(" ")


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

int main(){
    long long N;
    long long counter=0;;
    cin >> N;
    vector<long long> L(N+1);


    for(int i=1;i<=N;i++){
        cin >> L[i];
    }

    for(int i=1;i<=N-2;i++){
        for(int j=i+1;j<=N-1;j++){
            if(L[i] == L[j]){
                continue;
            }
            for(int k=j+1;k<=N;k++){
                if(L[i] == L[k] || L[j] == L[k]){
                    continue;
                }
                if(L[i]+L[j]>L[k] && L[i]+L[k]>L[j] && L[j]+L[k]>L[i]){
                    counter++;
                }
            }
        }
    }
    cout << counter << endl;

    return 0;
}

Measured memory_bytes: 3640
#include <cstdio>
#include <vector>
#include <algorithm>
typedef long long ll;

const int N=200005,P=1000000007;
struct Node
{
    int a,b,c;
    inline void operator+=(const Node &o)
    {
        c=(ll(a+b+c)*o.c+ll(b+c)*o.b+(ll)c*o.a)%P;
        b=((ll)a*o.b+(ll)b*o.a)%P,a=(ll)a*o.a%P;
    }
}v;

ll Pow(ll a,ll b,ll s=1){for(;b;b>>=1,a=a*a%P)if(b&1)s=s*a%P;return s%P;}

int n,h[N],l[N],r[N],t,Ans;
std::vector<Node> q[N];

void DFS(int x)
{
    if(!h[x])return q[r[x]=++t].push_back(v),void();
    int m=0,y,z;
    for(int i=h[x];i;i=l[i])
    {
        if(DFS(i),i==h[x]){r[x]=r[i];continue;}
        y=q[r[x]].size(),z=q[r[i]].size(),m=std::max(m,std::min(y,z));
        if(y<z)std::swap(y,z),std::swap(r[x],r[i]);
        for(int j=1;j<=z;++j)q[r[x]][y-j]+=q[r[i]][z-j];
    }
    m=(int)q[r[x]].size()-m;
    for(int j=(int)q[r[x]].size()-1;j>=m;--j)q[r[x]][j].a=(q[r[x]][j].a+q[r[x]][j].c)%P,q[r[x]][j].c=0;
    q[r[x]].push_back(v);
}

int main()
{
    scanf("%d",&n),v=(Node){(P+1)>>1,(P+1)>>1,0};
    for(int i=1,x;i<=n;++i)scanf("%d",&x),l[i]=h[x],h[x]=i;
    DFS(0);
    for(int i=(int)q[r[0]].size()-1;i>=0;--i)Ans=(Ans+q[r[0]][i].b)%P;
    printf("%d\n",int(Ans*Pow(2,n+1)%P));
    return 0;
}


Measured memory_bytes: 23668
#include <algorithm>
#include <cstdio>
#include <queue>
#include <set>
#include <vector>
#include <map>

using namespace std;

struct Edge {
  int s;
  int t;
  int w;
  Edge(int s, int t, int w) {
    this->s = s;
    this->t = t;
    this->w = w;
  }
};

bool cmp(const Edge& e1, const Edge& e2) {
  return e1.w > e2.w;
}

vector<Edge> edges;
map<int, vector<Edge>> adj;

int V, E;
int res = 0;
set<int> black;

void input() {
  scanf("%d %d", &V, &E);
  for (int i = 0; i < E; i++) {
    int s, t, w;
    scanf("%d %d %d", &s, &t, &w);
    //edges.emplace_back(s, t, w);
    Edge e(s, t, w);
    adj[s].push_back(e);
    adj[t].push_back(e);
  }
}

class cmp {
public:
  bool operator() (Edge e1, Edge e2) {
    return e1.w < e2.w;
  }
};

void solve() {
  black.insert(0);
  priority_queue<Edge, vector<Edge>, std::function<bool(Edge, Edge)>> pq(cmp);
  for (const Edge& e: adj[0]) {
    pq.push(e);
    //printf("inserting edge %d %d %d to pq\n", e.s, e.t, e.w);
  }
  while (black.size() < V) {
    Edge t(-1, -1, -1);
    bool found = false;
    while (!found) {
      t = pq.top();
      //printf("took edge %d %d %d from pq\n", t.s, t.t, t.w);
      pq.pop();
      found = (black.count(t.s) != black.count(t.t));
    }
    res += t.w;
    //printf("edge %d %d %d included to MST\n", t.s, t.t, t.w);
    int newV = t.s;
    if (black.count(t.s) == 1) {
      newV = t.t;
    }
    for (const Edge& e: adj[newV]) {
      pq.push(e);
      //printf("inserting edge %d %d %d to pq\n", e.s, e.t, e.w);
    }
    black.insert(newV);
  }
}

void output() {
  printf("%d\n", res);
  // for (const auto& x : edges) {
  //   printf("s:%d t:%d w:%d\n", x.s, x.t, x.w);
  // }
}

int main() {
  input();
  solve();
  output();
}

Measured memory_bytes: 10180
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <cmath>
using namespace std;
typedef long long ll;
#define rep(i,n) for (int i=0;i < (int)(n);i++)

int main(){
   int a,b,c,d;
   string s;
   cin >> a >> b >> c >> d;
   if (a+b > c+d) cout << "Left" << endl;
   else if (a+b == c+d) cout << "Balanced" << endl;
   else cout << "Right" << endl;
   return 0;
}


Measured memory_bytes: 256
C = set([i*i+j*j for i in xrange(160) for j in xrange(160)])

N = int(raw_input())
for loop in xrange(N):
    p,q = map(abs,map(int,raw_input().split()))
    pq = p*p+q*q

    cnt = 0
    for x in xrange(0,max(p,q)):
        for y in xrange(x,max(p,q)):
            xy = x*x+y*y
            if xy < 1: continue
            if pq%xy == 0 and pq/xy in C:
                cnt += 1
    print "P" if cnt == 1 else "C"

Measured memory_bytes: 5528
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
//#include<boost/multiprecision/cpp_int.hpp>
//#include<boost/multiprecision/cpp_dec_float.hpp>
//namespace mp=boost::multiprecision;
//#define mulint mp::cpp_int
//#define mulfloat mp::cpp_dec_float_100
using namespace std;
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
constexpr int MOD=1000000007;
//constexpr int MOD=998244353;
#define INF (1<<30)
#define LINF (lint)(1LL<<56)
#define endl "\n"
#define rep(i,n) for(lint (i)=0;(i)<(n);(i)++)
#define reprev(i,n) for(lint (i)=(n-1);(i)>=0;(i)--)
#define Flag(x) (1<<(x))
#define Flagcount(x) __builtin_popcountll(x)
#define pint pair<int,int>
#define pdouble pair<double,double>
#define plint pair<lint,lint>
#define fi first
#define se second
typedef long long lint;
int dx[8]={1,1,0,-1,-1,-1,0,1};
int dy[8]={0,1,1,1,0,-1,-1,-1};
const int MAX_N=2e5+5;
//struct edge{lint to,num;};
//vector<int> bucket[MAX_N/1000];

int main(void){
    srand((unsigned)time(NULL));
    lint N;
    cin >> N;
    lint A[N],B[N];
    rep(i,N) cin >> A[i];
    rep(i,N) cin >> B[i];
    lint cnta[N+1]={};
    lint cntb[N+1]={};
    rep(i,N) cnta[A[i]]++;
    rep(i,N) cntb[B[i]]++;
    multiset<lint> nums;
    rep(i,N) nums.insert(B[i]);
    bool chk=true;
    lint half=N/2+1;
    lint maxi=0;
    lint mst=0;
    rep(i,N+1){
        if(cnta[i]+cntb[i]>N) chk=false;
        if(maxi<cnta[i]+cntb[i]) mst=i;
        maxi=max(maxi,cnta[i]+cntb[i]);
    }
    if(!chk) cout << "No" << endl;
    else{
        cout << "Yes" << endl;
        lint ans[N]={};
        rep(i,N){
            lint num=A[i];
            auto itr=nums.upper_bound(num);
            if(itr==nums.end()) itr=nums.begin();
            if(*itr==A[i]) chk=false;
            ans[i]=*itr;
            nums.erase(itr);
        }
        queue<int> same;
        rep(i,N) if(A[i]==ans[i]) same.push(i);
        while(!same.empty()){
            int now=same.front();
            same.pop();
            int to=rand()%N;
            if(A[now]!=ans[to] && A[to]!=ans[now]) swap(ans[now],ans[to]);
            else same.push(now);
        }
        rep(i,N) cout << ans[i] << " ";
        cout << endl;
    }
}


Measured memory_bytes: 20796
#include<bits/stdc++.h>
//#include<boost/multiprecision/cpp_ll.hpp>
//using boost::multiprecision::cpp_ll; // use cpp_ll as data type for large numbers 
using namespace std;

#define int ll
#define ll long long
#define pb push_back
#define fast() ios_base::sync_with_stdio(false); cin.tie(NULL); 
#define mod 1000000007
#define mp make_pair
#define ff first
#define ss second
#define vi vector<ll>
#define vll vector<long long>
#define log2(X) (63ll - __builtin_clzll(X))
#define test ll t; cin>>t; while(t--)
#define modInv(n) po(n,mod-2)%mod
#define ncr(n,r) (((fact[n]*modInv(fact[r]))%mod)*modInv(fact[n-r]))%mod

ll po(ll a, ll b)
{
    ll res=1;
    while(b)
    {
        if(b&1)
        {
            res=(res*a)%mod;
        }
        a=(a*a)%mod;
        b=b/2;
    }
    return res%mod;
}

signed main() 
{
    fast()
    //test
    {
      int n,k;
      cin>>n>>k;
      int arr[n+1]={0};
      int dp[k+1]={0};
      for(int i=1; i<=n; i++) cin>>arr[i];
      
      for(int i=0; i<=k; i++)
      {
          for(int j=1; j<=n; j++)
          {
              if(i>=arr[j] && dp[i-arr[j]]==0)
              {
                  dp[i]=1;
              }
          }
      }
      if(dp[k]) cout<<"First"<<"\n";
      else cout<<"Second"<<"\n";
    }   
}


Measured memory_bytes: 4400
from itertools import combinations

n = int(input())
s = [input() for _ in range(n)]
s.sort()
march = [0, 0, 0, 0, 0]
st = ['M', 'A', 'R', 'C', 'H']
for i in range(n):
    for j in range(5):
        if s[i][0] == st[j]:
            march[j] += 1
#print(march)
if sum(march) == 0:
    print(0)
    exit()

ans = 0

a = list(combinations(range(5), 3))
for i in range(len(a)):
    tmp = 1
    for j in a[i]:
        tmp *= march[j]
    ans += tmp

print(ans)

Measured memory_bytes: 10212
using System;
using System.Linq;
using System.IO;
using System.Text;
using System.Collections;
using System.Collections.Generic;
using System.Text.RegularExpressions;

namespace AtCoder.ABC068
{
    class Program
    {
        static void Main()
        {
            Console.WriteLine("ABC{0}", Console.ReadLine());
        }
    }
}

Measured memory_bytes: 13140