akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
#define rep(i,m,n) for(int i=m;i<n;i++)
ll mod=1e9+7;

ll a[500000+1],b[500000+1];

ll power(ll x,ll n){
    if(n==0) return 1;
    ll res=power(x*x%mod,n/2);
    if(n&1) res=res*x%mod;
    return res;
}

ll perm(int n,int k){
  return a[n]*b[n-k]%mod;
}

ll comb(int n,int k){
  return a[n]*b[k]%mod*b[n-k]%mod;
}

int main(){
  int n,m;
  cin>>n>>m;
  a[0]=1;
  rep(i,1,m+1) a[i]=a[i-1]*i%mod;
  b[m]=power(a[m],mod-2);
  for(int i=m-1;i>=0;i--) b[i]=b[i+1]*(i+1)%mod;
  ll ans=0;
  rep(i,0,n+1){
    ll now=comb(n,i)*perm(m,i)%mod*perm(m-i,n-i)%mod*perm(m-i,n-i)%mod;
    if(i%2==0) ans+=now;
    else ans-=now;
    if(ans<0) ans+=mod;
    else ans%=mod;
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 11392
#include <bits/stdc++.h>
using namespace std;
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    cin >> n;
    vector<int> a(n), b(n);
    for (int i = 0; i < n; i++)
        cin >> a[i];
    for (int i = 0; i < n; i++)
        cin >> b[i];
    reverse(b.begin(), b.end());
    int c = -1;
    for (int i = 0; i < n; i++) {
        if (a[i] == b[i]) {
            c = a[i];
            break;
        }
    }
    int l = n, r = -1;
    for (int i = 0; i < n; i++) {
        if (a[i] == c and b[i] == c) {
            l = min(l, i);
            r = max(r, i);
        }
    }
    for (int i = 0; i < n; i++) {
        if (a[i] != c and b[i] != c and l <= r) {
            swap(b[i], b[l]);
            ++l;
        }
    }
    if (l <= r) {
        cout << "No" << "\n";
        return 0;
    }
    cout << "Yes" << "\n";
    for (int i = 0; i < n; i++) {
        cout << b[i] << " \n"[i == n - 1];
    }
    return 0;
}


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

#define f first
#define s second
#define ll long long
#define pb push_back
#define mp make_pair
#define inp(x) cin>>x
#define print(x) cout<<x
#define pii pair<int,int>
#define pll pair<ll,ll>
#define gcd(a,b) __gcd(a,b)
#define reset(d,val) memset(d,val,sizeof(d))
#define sort(v) sort(v.begin(),v.end())
#define sort_arr(arr,i,f) sort(arr+i,arr+f)
#define pq priority_queue<int,vector<int>,greater<int> >
#define pq1 priority_queue<pll,vector<pll>,greater<pll> >

const int mod = 1e9+7;

ll x;
ll f(ll mid) {
	int i=0;
	ll ans = 1;
	while(i<5){
		ans *= mid;
		i++;
		//cout<<ans<<" ";
		if(ans>x) return 0;
	}
	return 1;
}

int main(int argc, char const *argv[])
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	cin>>x;
	ll l = 1;
	ll h = x;
	ll ans;
	while(l<=h) {
		ll mid = (l+h)>>1;
		//cout<<l<<" "<<h<<" "<<mid<<endl;
		if(f(mid)) {
			ans = mid;
			l = mid+1;
		}
		else h = mid-1;
	}
	for (ll i = -1*ans*10; i <=ans*10 ; ++i)
	{
		for(ll j = -1*ans*10 ;j<=ans*10;j++){
			if(pow(i,5)-pow(j,5)==x) {
				cout<<i<<" "<<j;
				return 0;
			}
		}
	}
	return 0;
}


Measured memory_bytes: 4080
#include<iostream>

#include<vector>

using namespace std;

template<typename input_Integer>
void is_Prime(input_Integer N,vector<int>& Prime){


    vector<bool> check(N+1,true);
    check[0]=false;
    check[1]=false;


    for(input_Integer i = 2; i * i <= N; ++i){
        if(check[i]){
            for(input_Integer k = i * 2; k < N; k += i){
                check[k] = false;
            }
        }
    }


    for(input_Integer i=2;i<N;++i){
        if(check[i]){
            Prime.emplace_back(i);
        }
    }

}


int main(){
    long long N;
    cin>>N;
    long long  ans=1;

    vector<int> vec(1000,1);
    vector<int> prime;
    is_Prime(1000,prime);

    for(int i=1;i<=N;++i){
        int tmp=i;
        for(int k=0;k<prime.size();++k){
            while(tmp%prime[k]==0){
                vec[prime[k]]++;
                tmp=tmp / prime[k];
            }
        }


    }


    for(auto &x:vec){
        ans*=x;
        
        ans%=1000000007;
    }

    cout<<ans<<endl;

}

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

public class Main {

	public static void main(String[] args) {
		//		new Main().solveA();
		//		new Main().solveB();
		new Main().solveC();
		// new Main().solveD();
	}

	private void solveA() {
		Scanner scanner = null;
		String line = "";

		try {
			scanner = new Scanner(System.in);
			line = scanner.next();

			System.out.println(line.replaceAll("2017", "2018"));

		} finally {
			if (scanner != null) {
				scanner.close();
			}
		}
	}

	private void solveB() {
		Scanner scanner = null;
		int n = 0;

		try {
			scanner = new Scanner(System.in);
			n = scanner.nextInt();
			int[] wk = new int[n];

			for (int i = 0; i < n; i++) {
				wk[i] = scanner.nextInt();
			}

			Arrays.sort(wk);

			int res = 0;
			for (int i = 0; i < wk.length; i++) {
				if (i == 0) {
					res++;
				} else if (wk[i] != wk[i - 1]) {
					res++;
				}

			}

			System.out.println(res);

		} finally {
			if (scanner != null) {
				scanner.close();
			}
		}
	}

	private void solveC() {
		Scanner scanner = null;
		int n = 0;
		int y = 0;

		try {
			scanner = new Scanner(System.in);
			n = scanner.nextInt();
			y = scanner.nextInt();

			for (int i = n; i >= 0; i--) {
				if (i * 10000 > y) {
					continue;
				}
				for (int j = 0; j <= n - i; j++) {
					for (int k = 0; k <= n - i - j; k++) {
						if (n == i + j + k && i * 10000 + j * 5000 + k * 1000 == y) {
							System.out.println(i + " " + j + " " + k);
							return;
						}
					}
				}
			}

			System.out.println(-1 + " " + -1 + " " + -1);

		} finally {
			if (scanner != null) {
				scanner.close();
			}
		}
	}

	private void solveD() {
		Scanner scanner = null;
		int lineAB = 0;
		int lineBC = 0;
		int lineCA = 0;

		try {
			scanner = new Scanner(System.in);
			lineAB = scanner.nextInt();

			System.out.println("");

		} finally {
			if (scanner != null) {
				scanner.close();
			}
		}
	}
}

Measured memory_bytes: 23124
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define countof(array) (sizeof(array) / sizeof(array[0]))
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,n,s) for(int i = s; i < (n); ++i)
#define rsrep(i,n,s) for(int i = (n)-1; i >= s; --i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define aall(a) (a), (a)+countof(a)
#define raall(a) (a), (a)+countof(a), greater<>()
#define show(x) cout<<#x<<" = "<<x<<endl;
#define vfind(v, a) find(all(v), a) != v.end()
#define yn(f) { if (f) puts("YES"); else puts("NO"); }
#define yns(f) { if (f) puts("Yes"); else puts("No"); }
#define show_ary(...) { cout<<#__VA_ARGS__<<" = "; for (const auto& x : (__VA_ARGS__)) { cout<<x<<" "; } cout<<endl; }
#define out_ary(...) { for (const auto& x : (__VA_ARGS__)) { cout<<x<<" "; } cout<<endl; }
typedef long long int ll;
typedef vector<int> vint;
const ll LINF = 9000000000000000000ll;
const int INF = 2000000000;
const ll MOD = 1e9+7;

int main() {
    int n;
    cin >> n;
    vint a(n);
    rep(i, n) cin >> a[i];
    vint ans;
    int x = 0;
    int odd = 1;
    rep(i, n) {
        x += a[i] * odd;
        odd *= -1;
    }
    ans.push_back(x);
    int tmp;
    rep(i, n-1) {
        tmp = 2 * a[i] - x;
        ans.push_back(tmp);
        x = tmp;
    }
    out_ary(ans);
    return 0;
}

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

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

	int n;
	cin >> n;

	int num;
	int zero = 0, one = 0, two = 0;
	for(int i=0; i<n; ++i) {
		cin >> num;
		if(num % 2) ++zero;
		else if(num % 4) ++one;
		else ++two;
	}

	bool res;
	if(zero == 0) res = true;
	else if(one == 0) res = (two >= zero-1) ? true : false;
	else if(two == 0) res = false;
	else res = (two >= zero) ? true : false;

	if(res) cout << "Yes";
	else cout << "No";

	return 0;
}

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


void solve(long long N){
    long long table[100];
    fill(table, table+100, 0);
    for(int i=1; i <= N; i++){
        // cout << "*" << i << "*" << endl;
        string s = to_string(i);
        char top = s[0];
        char end = s[s.size() - 1];
        int ind = s.size() - 1;
        if(end == '0'){
            continue;
        }
        int a = top - '0';
        int b = end - '0';
        table[10*a+b]++;
    }
    long long res = 0;
    for(int i=1; i <= N; i++){
        // cout << "*" << i << "*" << endl;
        string s = to_string(i);
        char top = s[0];
        char end = s[s.size() - 1];
        int ind = s.size() - 1;
        if(end == '0'){
            continue;
        }
        int b = top - '0';
        int a = end - '0';
        res += table[10*a+b];
    }
    cout << res << endl;

}

void solve2(long long N){
    long long res = 0;
    for(int i=1; i <= N; i++){
        // cout << "*" << i << "*" << endl;
        string s = to_string(i);
        char top = s[0];
        char end = s[s.size() - 1];
        int ind = s.size() - 1;
        if(end == '0'){
            continue;
        }
        // while(end == '0'){
        //     ind--;
        //     end = s[ind];
        // }
        // start from "end" and end with "top"
        int b = top - '0';
        int a = end - '0';
        // cout << "(" << a << "," << b << ")" << endl;
        // exception
        if(a == b){
            res++;
        }
        if(10*a+b <= N){
            res++;
        }
        for(int m=1; m < 5; m++){
            long long sub = min((N - b - a*pow(10, m+1))/10, pow(10, m) - 1) - pow(10, m-1) + 1;
            // cout << sub << endl;
            res += max(sub, 0LL);
        }
        // cout << i;
        // if(top == end && s[s.size() - 1] == ){
        //     cout << "*";
        //     res++;
        // }
        // cout << endl;
        // cout << "res" << res << endl;

    }
    cout << res << endl;
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long N;
    scanf("%lld",&N);
    solve(N);
    return 0;
}


Measured memory_bytes: 384
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#include<cmath>

#define REP(i,n) for (int i = 0; (i) < (n); ++ (i))
#define FOR(i,n) for (int i = 1; (i) <= (n); ++ (i))
#define dump(x)  cout << #x << " = " << (x) << endl;
#define pb push_back
#define int long long

const int INF = 1e18;
const int MOD = 1e9+7;
//const lint LINF = 1e18;
const double eps = 0.000000001;//もとの値の10^(-16)まで

using namespace std;

//typedef pair<int, int> P;
//priority_queue< P, vector<P>, greater<P> > q;//ダイクストラの時、greaterで小さい順
//cout << fixed << setprecision(10) << ans << endl;
//int gcd(int a,int b){return b?gcd(b,a%b):a;}
int p[300000];
signed main(){
    int n,k;
    cin >> n >> k;
    REP(i,n){
        cin >> p[i];
    }
    int now = 0;
    int ans = 0;
    REP(i,n){
        int now2 = now + p[i]+1;
        if(i-k>=0){
            now2 -= p[i-k]+1;
            ans = max(ans,now2);
            now = now2;
        }
        else{
            ans = max(ans,now2);
            now = now2;
        }   
    }
    double anss = 1.0 * ans / 2;
    cout << fixed << setprecision(10) << anss << endl;
    return 0;
}

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

using namespace std;

using ll = long long;

constexpr ll mod = 1e9 + 7;

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

  int n;
  cin >> n;

  // how many heads
  vector<double> probs(n + 1);
  probs[0] = 1;
  for (int i = 0; i < n; ++i) {
    double p;
    cin >> p;

    for (int j = n; j > 0; --j) {
      probs[j] = probs[j - 1] * p + (1 - p) * probs[j];
    }
    probs[0] *= 1 - p;
  }

  cout << setprecision(16) << fixed << accumulate(probs.begin() + n / 2 + 1, probs.end(), 0.) << '\n';

  return 0;
}


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

int main() {
    cin.tie(0)->sync_with_stdio(false);

    int n, c, k;
    cin >> n >> c >> k;

    vector<int> t(n);
    REP(i, n) cin >> t[i];
    sort(t.begin(), t.end());

    int ans = 0;
    REP(i, n) {
        int cnt = 0;
        for (int j = 1; j < c; j++) {
            if (abs(t[i] - t[i + j]) <= k) cnt++;
            else break ;
        }
        i += cnt;
        ans++;
    }

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


Measured memory_bytes: 640
# http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_1_A&lang=jp

def insertion_sort(array):
    putsarray(array)
    N = len(array)
    for i in range(1, N):
        j = i - 1
        num = array[i]
        while j >= 0 and array[j] > num:
            array[j + 1] = array[j]
            j -= 1
        array[j + 1] = num
        putsarray(array)

def putsarray(array):
    for i in range(len(array) - 1):
        print(array[i], end=" ")
    print(array[-1])


N = int(input())
array = input().split()
array = [int(n) for n in array]
insertion_sort(array)





Measured memory_bytes: 5980
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <tuple>
using namespace std;
typedef long long ll;

vector<ll> vd;

void calcDivisor(ll n){

    set<ll> sttemp, st;

    ll iend = sqrt(n) + 1;
    for(int i=1; i<=iend; i++){
        if(n % i == 0){
            sttemp.insert(i);
        }
    }

    for(ll x : sttemp){
        st.insert(x);
        st.insert(n/x);
    }

    for(ll x : st){
        vd.push_back(x);
    }

    sort(vd.begin(), vd.end());
    return;
}

int calcDigits(ll n){

    int cnt = 0;
    while(n > 0){
        cnt++;
        n /= 10;
    }

    return cnt;
}

int main(){

    ll n; cin >> n;

    calcDivisor(n);

    int vmin = 1e9;
    for(auto x : vd){
        if(x > sqrt(n) + 1){
            break;
        }
        
        vmin = min(vmin, max(calcDigits(x), calcDigits(n/x)));
    }

    cout << vmin;

    return 0;
}

Measured memory_bytes: 512
#include <stdio.h>
#include <math.h>

typedef struct{
  double x; 
  double y;
}Node;

void kock(int, Node, Node);

int main(){

  int n;
  Node p1, p2;

  scanf("%d", &n);

  p1.x = 0;
  p1.y = 0;
  p2.x = 100;
  p2.y = 0;      //?????????

  printf("%.8f %.8f\n", p1.x, p1.y);
  kock(n, p1, p2);
  printf("%.8f %.8f\n", p2.x, p2.y);   


  return 0;
}

void kock(int n, Node p1, Node p2){

  Node s, t, u;
  double a;

  if(n == 0){
    return;
  }

  a = M_PI * 60.0/180.0;
  
  s.x = (2.0 * p1.x + 1.0 * p2.x) / 3.0;
  s.y = (2.0 * p1.y + 1.0 * p2.y) / 3.0;
  t.x = (1.0 * p1.x + 2.0 * p2.x) / 3.0;
  t.y = (1.0 * p1.y + 2.0 * p2.y) / 3.0;
  u.x = ((t.x - s.x) * cos(a)) - ((t.y - s.y) * sin(a)) + s.x;
  u.y = ((t.x - s.x) * sin(a)) + ((t.y - s.y) * cos(a)) + s.y;

  kock(n-1, p1, s);
  printf("%.8f %.8f\n", s.x, s.y);
  kock(n-1, s, u);
  printf("%.8f %.8f\n", u.x, u.y);
  kock(n-1, u, t);
  printf("%.8f %.8f\n", t.x, t.y);
  kock(n-1, t, p2);
}

Measured memory_bytes: 640
n,m=map(int,input().split())
mi = 0
ma = 10**5+1
for i in range(m):
  s,e = map(int,input().split())
  if s > mi:
    mi = s
#    print('mi',mi)
  if e < ma:
    ma = e
#    print('ma',ma)
print(max(ma-mi+1,0))

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

int main() {
  string S, T;
  cin >> S >> T;
  int n = S.size();
  int now = 0;
  rep(i, n) {
    if (S.at(i) == T.at(i)) continue;
    now++;
  }
  cout << now << endl;
}


Measured memory_bytes: 3912
ans = []
while True:
    m,f,r = map(int, input().split())
    if m==-1 and f==-1 and r==-1:break
    if m == -1 or f == -1:
        ans.append("F")
    elif m + f < 30:
        ans.append("F")
    elif 30 <=  m + f < 50:
        if r < 50:
            ans.append("D")
        else:
            ans.append("C")
    elif 50 <= m + f < 65:
        ans.append("C")
    elif 65 <= m + f < 80:
        ans.append("B")    
    else:
        ans.append("A")

for a in ans:
    print(a)


Measured memory_bytes: 5596
import sys
import math
from pprint import pprint

def solve(n, s):

    ans = 0
    if s[0] == "W" or s[2*n-1] == "W":
        return ans

    l_c = 0
    r_c = 0
    o_c = 1
    mod = 10**9 + 7
    for s_i in s:
        if s_i == "B" and (l_c - r_c) % 2 == 0:
            l_c += 1
        elif s_i == "W" and (l_c - r_c) % 2 == 0:
            o_c *= l_c - r_c
            o_c %= mod
            r_c += 1
        elif s_i == "B" and (l_c - r_c) % 2 == 1:
            o_c *= l_c - r_c
            o_c %= mod
            r_c += 1
        elif s_i == "W" and (l_c - r_c) % 2 == 1:
            l_c += 1
        # print(s_i, l_c, r_c, o_c)
        if l_c - r_c < 0:
            return 0
    # print(l_c, r_c, o_c)
    if l_c - r_c > 0:
        return 0

    return (o_c * math.factorial(n)) % mod

if __name__ == '__main__':
    n = int(sys.stdin.readline().strip())
    s = list(sys.stdin.readline().strip())
    print(solve(n, s))

Measured memory_bytes: 55972
#pragma GCC optimize("O2")

#include <bits/stdc++.h>
#ifdef DEBUG
	#include "debug.hpp"
#endif

using namespace std;

#define all(c) (c).begin(), (c).end()
#define traverse(c, it) for(auto it = (c).begin(); it != (c).end(); it++)
#define rep(i, N) for(int i = 0; i < (N); i++)
#define rep1(i, N) for(int i = 1; i <= (N); i++)
#define rep2(i, s, e) for(int i = (s); i <= (e); i++)
#define rep3(i, s, e, d) for(int i = (s); (d) >= 0 ? i <= (e) : i >= (e); i += (d))
#define pb push_back


#ifdef DEBUG
	#define debug(x...) { dbg::depth++; string dbg_vals = dbg::to_string(x); dbg::depth--; dbg::fprint(__func__, __LINE__, #x, dbg_vals); }
	#define light_debug(x) { dbg::light = 1; dbg::dout << __func__ << ":" << __LINE__ << "  " << #x << " = " << x << endl; dbg::light = 0; }
#else
	#define debug(x...)
	#define light_debug(x) 
#endif

template<typename T>
inline T& ckmin(T& a, T b) { return a = a > b ? b : a; }

template<typename T>
inline T& ckmax(T& a, T b) { return a = a < b ? b : a; }

using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;

struct BIT {
	int n;
	vi a;

	BIT(int _n) : n(_n), a(_n + 1, _n) { }

	void upd(int i, int v) {
		for(i = n + 1 - i; i <= n; i += i & -i) ckmin(a[i], v);
	}

	int qry(int i) {
		int r = n;
		for(i = n + 1 - i; i; i -= i & -i) ckmin(r, a[i]);
		return r;
	}
};

int main() {

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

	#ifdef DEBUG
		freopen("debug", "w", stderr);
	#endif
	
	int N, Q; cin >> N >> Q;
	ll ans = (ll)(N - 2) * (N - 2);

	vector<BIT> bit(2, BIT(N));

	rep(_, Q) {
		int t, x; cin >> t >> x;
		--t;
		int k = bit[t].qry(x);
		debug(t, x, k);
		ans -= k - 2;
		bit[!t].upd(k, x);
	}	

	cout << ans << '\n';

	#ifdef DEBUG
		dbg::dout << "\nExecution time: " << clock() << "ms\n";
	#endif

	return 0;
}


Measured memory_bytes: 5520
// F - Must Be Rectangular!
#include <bits/stdc++.h>

using namespace std;

vector<int> _parent, _rank;

void set_init(int n)
{
	_parent.assign(n, -1);
	_rank.assign(n, 0);
}

int set_find(int x)
{
	return _parent[x] < 0 ? x : _parent[x] = set_find(_parent[x]);
}

bool set_join(int x, int y)
{
	x = set_find(x), y = set_find(y);
	if (x == y) return false;
	if (_rank[y] > _rank[x]) swap(x, y);
	else if (_rank[x] == _rank[y]) _rank[x]++;
	_parent[y] = x;
	return true;
}

int main(int argc, char *argv[])
{
	ios::sync_with_stdio(false); cin.tie(0);

	int n;
	cin >> n;
	set_init(n);
	vector<int> x(n), y(n);
	map<int, int> mx, my;
	for (int i = 0; i < n; i++) {
		cin >> x[i] >> y[i];
		if (mx.count(x[i])) set_join(i, mx[x[i]]);
		mx[x[i]] = i;
		if (my.count(y[i])) set_join(i, my[y[i]]);
		my[y[i]] = i;
	}

	vector<set<int> > xs(n), ys(n);

	for (int i = 0; i < n; i++) {
		xs[set_find(i)].insert(x[i]);
		ys[set_find(i)].insert(y[i]);
	}
	long long c = 0;
	for (int i = 0; i < n; i++)
		c += 1LL * xs[i].size() * ys[i].size();

	cout << (c - n) << endl;

	return 0;
}


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

#define rep(i,x,y) for(int i=(x);i<(y);++i)
#define debug(x) #x << "=" << (x)

#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define print(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define print(x)
#endif

const int inf=1e9;
const int64_t inf64=1e18;
const double eps=1e-9;

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){
    os << "[";
    for (const auto &v : vec) {
    	os << v << ",";
    }
    os << "]";
    return os;
}

using i64=int64_t;

void solve(){
    int N,M;
    cin >> N >> M;
    vector<vector<int>> graph(N);
    rep(i,0,M){
        int a,b;
        cin >> a >> b;
        --a;
        --b;
        graph[a].push_back(b);
        graph[b].push_back(a);
    }

    int Q;
    cin >> Q;
    vector<tuple<int,int,int>> qs;
    rep(i,0,Q){
        int v,d,c;
        cin >> v >> d >> c;
        --v;
        qs.push_back(make_tuple(v,d,c));
    }
    reverse(qs.begin(),qs.end());

    vector<vector<int>> dp(N,vector<int>(11,inf));
    function<void(int,int,int)> rec=[&](int u,int d,int i){
        if(dp[u][d]!=inf) return;
        dp[u][d]=i;
        if(d==0) return;
        rec(u,d-1,i);
        for(int v:graph[u]) rec(v,d-1,i);
    };
    rep(i,0,Q) rec(get<0>(qs[i]),get<1>(qs[i]),i);
    
    vector<int> idx(N,inf);
    rep(i,0,N) rep(j,0,11) idx[i]=min(idx[i],dp[i][j]);
    rep(i,0,N){
        if(idx[i]==inf) cout << 0 << endl;
        else cout << get<2>(qs[idx[i]]) << endl;
    }
}

int main(){
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(16);
    solve();
    return 0;
}


Measured memory_bytes: 16624
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
from bisect import bisect

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

S= input()
K = INT()

for i in range(K):
	if S[i] == "1":
		continue
	else:
		print(S[i])
		break
else:
	print(1)


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

template <class T, class U>
void chmin(T& t, const U& u) {
    if (t > u) t = u;
}
template <class T, class U>
void chmax(T& t, const U& u) {
    if (t < u) t = u;
}

int main() {
    ll A, B, C, X, Y;
    cin >> A >> B >> C >> X >> Y;
    ll ans = A * X + B * Y;
    if (X >= Y) {
        chmin(ans, C * 2 * X);
        chmin(ans, C * 2 * Y + A * (X - Y));
    } else {
        chmin(ans, C * 2 * Y);
        chmin(ans, C * 2 * X + B * (Y - X));
    }
    cout << ans << endl;
}

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

int main()
{
        cin.tie(NULL);
        ios_base::sync_with_stdio(false);

        int k;
        string s;

        cin >> k;
        cin >> s;

        if (s.length() <= k) cout << s;
        else {
                s[k] = '\0';
                cout << s.c_str() << "...\n";
        }

        return 0;
}

Measured memory_bytes: 3632
n,k = map(int,input().split())
array = []
for i in range(n):
    a,b = map(int,input().split())
    array.append((a,b))
array.sort()
count = 0
for i in range(n):
    count += array[i][1]
    if count >= k:
        print(array[i][0])
        break

Measured memory_bytes: 53208
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
public class MainClass
{
	public const long Giri = 1000000007;
	public const long DpInf = 99999999999999;
	
	public static void Main(string[] args)
	{
		var p = Console.ReadLine();
		Console.WriteLine(p.Contains("9")?"Yes":"No");
	}

	
	static long GCD(long a, long b)
	{
		var v = new[] { a, b };
		while (v[1] != 0) { v = new[] { v[1], v[0] % v[1] }; }
		return v[0];
	}
	public static string[] Input() { return Console.ReadLine().Split(); }
}

public static class Smarter
{
	public static int ToInt(this string str) { return int.Parse(str); }
	public static long ToLong(this string str) { return long.Parse(str); }
	public static int[] ToInt(this string[] str, int offset = 0)
	{
		var r = new int[str.Length];
		for(int i = 0; i < str.Length; i++) r[i] = str[i].ToInt() + offset;
		return r;
	}
}

Measured memory_bytes: 25804
n =int(input())
array = []
for i in range(n):
    array.append(input())
flag = True
tmp = array[0]
for j in array[1:]:
    if tmp[-1] == j[0]:
        tmp = j
    else:
        flag = False
        break
print("Yes" if flag and len(set(array)) == len(array) else "No")

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

int main(){
  int a,b;
  cin>>a>>b;
  int x=b-a;
  vector<int> t(1000);
  t[0]=0;
  t[1]=1;
  for(int i=2;i<1000;i++)t[i]=t[i-1]+i;
  cout<<t[x]-b<<endl;
}


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

using namespace std;

typedef long long ll;
typedef pair<ll, ll> pll;


const ll LongINF=1e13+7;
const int INF=1e9+7;
const int dx[]={0,1,0,-1};
const int dy[]={1,0,-1,0};

template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
template <class T, class Y>T GCD(T a, Y b){if(a<b){int c=a;a=b;b=c;}if (a % b == 0){return b;}return GCD(b, a % b);}
void clear(queue<pair<int, int>> &q){queue<pair<int, int>> empty;swap(q, empty);} //queueの中身の型は適時変更を忘れない

#define REP(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define rv reverse
#define ALL(a) (a).begin(),(a).end()


int main(){
    ll A,B,K;
    cin>>A>>B>>K;
    if(A+B<K)cout<<0<<" "<<0<<endl;
    else if(A<K){
        K-=A;
        cout<<0<<" "<<B-K<<endl;
    }else cout<<A-K<<" "<<B<<endl;

    return 0;
}

//a=97,z=122

Measured memory_bytes: 256
import java.util.Scanner;
 
public class Main { 
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int M = sc.nextInt();
    int list[][] = new int[N+1][N+1];
    for (int i =0; i<M; i++) {
      int a = sc.nextInt();
      int b = sc.nextInt();
      list[a][b] = 1;
      list[b][a] = 1;
    }
    
    boolean seen = true;
    int result =0;
    while (seen) {
      seen = false;
      for (int i =1; i<=N; i++) {
        int count =0;
        for (int j =1; j<=N; j++) {
          if (list[i][j] == 1) count++;
        }
        if (count == 1) {
          result++;
          seen = true;
          for (int j =1; j<=N; j++) {
            list[i][j] =0;
            list[j][i] =0;
          }
        }
      }
    }
    System.out.println(result);
  }
}

Measured memory_bytes: 21844
#include <iostream>
#include <vector>
#include <algorithm> // sort
#include <map> // pair

#define all(x) (x).begin(),(x).end()
#define FOR(x) for(ll i = 0;i < x;++i)

using namespace std;
typedef long long ll;

int main(){
  int N,M;
  cin>>N>>M;
  cout<<N - M + 1;
  
  
  return 0;
}

Measured memory_bytes: 256
const lines=readlines()
state=0
input()=lines[global state+=1]
int(s::String)=parse(Int32,s)
intSub(s::SubString{String})=parse(Int32,s)
floatSub(s::SubString{String})=parse(Float64,s)
intLine()=map(intSub,split(input()))
function f(n::Int32)::Int32
    if n%2<1
        return div(n,2)
    else
        return 3n+1
    end
end
function main()
    s=int(input())
    a=zeros(Bool,10^7)
    a[s]=true
    n=1
    while true
        s=f(s)
        n+=1
        if a[s]
            println(n)
            break
        else
            a[s]=true
        end
    end
end
main()

Measured memory_bytes: 125476
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
#define show(x) {for(auto i: x){cout << i << " ";} cout << endl;}
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
    int N;
    cin >> N;
    vector<int> A(N);
    rep(i, N) cin >> A[i];
    vector<int> so = A;
    sort(so.rbegin(), so.rend());
    rep(i, N) {
        int ans = so[0];
        if (A[i] == so[0]) ans = so[1];
        printf("%d\n", ans);
    }
    return 0;
}

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

bool is_prime(int x){
    for(int i=2; i*i<=x; i++){
        if(x%i == 0){
            return false;
        }
    }
    return true;
}

int main() {

    int n;
    cin >> n;

    for(int i=n; ;i++){
        if(is_prime(i)){
            cout << i << endl;
            break;
        }
    }

    return 0;
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(100000)
input=sys.stdin.readline
def intinput():return map(int,input().split())

n=int(input())
x=[tuple(intinput()) for i in range(n)]
dp=[[0,0,0] for i in range(n+1)]
for i in range(len(x)):
    for j in range(3):
        dp[i+1][j]=max(dp[i][j-1]+x[i][j-1],dp[i][j-2]+x[i][j-2])
print(max(dp[-1]))

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

using namespace std;
using ll = long long int;

int main(void) {
    constexpr ll MOD = 1e9 + 7;
    constexpr double PI = acos(-1);
    cout << fixed << setprecision(16);
    cin.tie(0); ios::sync_with_stdio(false);

    ll n;
    cin >> n;
    vector<ll> t(n+1);
    for(ll i=0; i<n+1; i++)
        t[i] = i;

    ll r = 0;
    for(ll i=0; i<n; i++) {
        ll p;
        cin >> p;
        t[p] = t[p-1];
        r = max(r, p - t[p]);
    }
    cout << n-r << endl;
}


Measured memory_bytes: 1792
N = int(input())
a = list(map(int,input().split()))
minus = 0
for i in a:
    if i < 0:
        minus += 1
    if i == 0:
        minus = 0
        break
b = []
for j in a:
    b.append(abs(j))
b.sort()
if minus % 2 == 0:
    print(sum(b))
else:
    print(sum(b)-b[0]*2)

Measured memory_bytes: 91496
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
	private StringTokenizer st;
	private BufferedReader bf;
	private int n;
	
	Main() {
		readData();
		
		System.out.println((int)Math.pow(n, 3));
	}
	
	private void readData() {
		try {
			bf = new BufferedReader(new InputStreamReader(System.in));
			st = new StringTokenizer(bf.readLine());
			n = nextInt();
			
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	private int nextInt() throws IOException {
		return Integer.parseInt(next());
	}
	
	private String next() throws IOException {
		if (st == null || !st.hasMoreTokens())
			st = new StringTokenizer(bf.readLine());
		return st.nextToken();
	}
	
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Main m = new Main();
	}

}

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

int main() {
    int N; cin >> N;
    vector<int> S;
    for(int i = 0; i < N; i++) {
        int s; cin >> s; S.push_back(s);
    }
    int Q; cin >> Q;
    vector<int> T;
    for(int i = 0; i < Q; i++) {
        int t; cin >> t; T.push_back(t);
    }
    sort(S.begin(), S.end());
    int res = 0;
    for(int i = 0; i < Q; i++) {
        res += binary_search(S.begin(), S.end(), T[i]);
    }
    cout << res << endl;
}

Measured memory_bytes: 1324
#ごり押し

from scipy.sparse import csr_matrix
from scipy.sparse.csgraph import dijkstra
import numpy as np
from collections import Counter

N, X, Y = map(int, input().split())

start = list(range(0, N-1)) + list(range(1, N)) + [X-1, Y-1] 
end = list(range(1, N)) + list(range(0, N-1)) + [Y-1, X-1]
cost = [1] * len(start)

graph = csr_matrix((cost, (start, end)))
lengths = dijkstra(graph, directed = False)

c = Counter(lengths.astype(np.int64).reshape(-1))
for k in range(1, N):
    print(c[k]//2)


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

using namespace std;

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

    int n; cin >> n;
    string s; cin >> s;
    if(n & 1) {cout << "No"; return 0;}
    int t = n >> 1;
    for(int i = 0; i < t; ++i)
    if(s[i] != s[i + t]) {cout << "No"; return 0;}
    cout << "Yes"; return 0;
}


Measured memory_bytes: 256
from collections import Counter

n = int(input())
v = list(map(int, input().split()))

"""数字が1種類の場合は半分を書き換える必要が確定"""
if len(set(v)) == 1:
    print(len(v) // 2)
    exit()

"""要素出現数を集計"""
odd_count = Counter(v[1::2])
even_count = Counter(v[::2])

"""一番多く出現する2つの数字を探す"""
max_hit = 0
odd = None
even = None
for odd_val, odd_hit in odd_count.most_common(5):
    # if max_hit > odd_hit:
    #     break  # もう最大値は更新されないので打ち止め
    for even_val, even_hit in even_count.most_common(5):
        # if max_hit > even_hit:
        #     break  # もう最大値は更新されないので打ち止め
        if odd_val == even_val:
            continue  # 数字は2種類ないとダメ
        if odd_hit + even_hit > max_hit:
            max_hit = odd_hit + even_hit
            odd = odd_val
            even = even_val

"""一致していない要素が書き換え必要回数"""
print(len(v) - max_hit)


Measured memory_bytes: 18652
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <bitset>
#include <deque>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <iterator>
#include <string>
#include <chrono>
#include <random>
#include <tuple>
#include <utility>
#include <fstream>
#include <complex>

long n;
typedef std::complex<double> Com;

//geometric library
//#include <complex>
//typedef complex<double> Com;
//内積
double dot_product(Com a, Com b){
	return (conj(a)*b).real();
}
//外積
double cross_product(Com a, Com b){
	return (conj(a)*b).imag();
}
//点と直線の距離
double dist_dot_line(Com st, Com en, Com dt){
    return std::abs(cross_product(dt-st, en-st) / std::abs(en-st));
}
//点と線分の距離
double dist_dot_seg(Com st, Com en, Com dt){
	if(dot_product(en-st, dt-st) <= 0){
		return std::abs(dt-st);
	}else if(dot_product(st-en, dt-en) <= 0){
		return std::abs(dt-en);
	}else{
		return dist_dot_line(st, en, dt);
	}
}
//線分の交差判定
bool seg_crossing(Com st1, Com en1, Com st2, Com en2){
	double cross1 = cross_product(en1-st1, st2-st1) * cross_product(en1-st1, en2-st1);
	double cross2 = cross_product(en2-st2, st1-st2) * cross_product(en2-st2, en1-st2);
	return (cross1 <= 0) && (cross2 <= 0);
}
//線分と線分の距離
double dist_seg(Com st1, Com en1, Com st2, Com en2){
	if(seg_crossing(st1, en1, st2, en2)){
		return 0;
	}
	return std::min(std::min(dist_dot_seg(st1, en1, st2), dist_dot_seg(st1, en1, en2)), std::min(dist_dot_seg(st2, en2, st1), dist_dot_seg(st2, en2, en1)));
}


void solve(){
    double ans = 10000;
    Com s, g;
    double sx, sy, gx, gy;
    scanf("%lf%lf%lf%lf", &sx, &sy, &gx, &gy);
    s = Com(sx, sy);
    g = Com(gx, gy);
    for(int i = 0; i < n; i++){
        double cod[2][2];
        double height;
        for(int j = 0; j < 2; j++){
            for(int k = 0; k < 2; k++){
                scanf("%lf", &cod[j][k]);
            }
        }
		std::vector<Com> ver;
        scanf("%lf", &height);
        for(int j = 0; j < 2; j++){
            for(int k = 0; k < 2; k++){
                ver.push_back(Com(cod[j][0], cod[k][1]));
            }
        }
		ver.push_back(ver[0]);
		for(int j = 0; j < 4; j++){
			double d = dist_seg(Com(sx, sy), Com(gx, gy), ver[j], ver[j+1]);
			if(d < height){
				ans = std::min(ans, d);
			}else{
				ans = std::min(ans, (height*height + d*d) / (2*height));
			}
		}
    }
    printf("%.9lf\n", ans);
}

int main(){
    while(1){
        scanf("%ld", &n);
        if(n == 0){
            return 0;
        }
        solve();
    }
}



Measured memory_bytes: 3156
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
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++)
#define Clear(a) a = decltype(a)()
#define all(a) a.begin(),a.end()
#define vec vector
typedef long long ll;
typedef pair<int,int> p;
//const ll big=998244353;
const ll big=1000000007;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
ll max(ll x,ll y){
if(x>y)return x;
else return y;
}
ll min(ll x,ll y){
if(x<y)return x;
else return y;
}
ll expm(ll x,ll y){
    if(y==0)return 1;//0^0=1
    if(x==1||x==0)return x;
    if(y%2==1)return (expm(x,y-1)*x)%big;
    ll t=expm(x,y/2);
    return (t*t)%big;
}
ll exp(ll x,ll y){
    if(y==0)return 1;//0^0=1
    if(x==1||y==0)return x;
    if(y%2==1)return exp(x,y-1)*x;
    ll t=exp(x,y/2);
    return t*t;
}
ll inv(ll x){
    return expm(x,big-2);
}

int f(int n,int a){//a%10!=0で良い
    if(n<=9)return (n>=a||(a%10<=n&&to_string(a)[0]==to_string(a)[(int)to_string(a).size()-1]));
    else if(n<=99){
        int ans=f(9,a);
        if(a<=9)a*=11;
        int l=to_string(a)[(int)to_string(a).size()-1]-'0';
        int k=10*l+a/10;
        if(k<=n)ans++;
        return ans;
    }
    else{
        int ans=0;
        if(n<=999)ans+=f(99,a);
        else if(n<=9999)ans+=f(999,a);
        else if(n<=99999)ans+=f(9999,a);
        else /*n<=200000*/ans+=f(99999,a);
        /*
        あとは nと同じ桁数を探索すれば良い
        */
        string s=to_string(a),t=to_string(n);
        swap(s[0],s[(int)s.size()-1]);
        if(t[0]>s[0]){
            ans+=exp(10,(int)t.size()-2);
        }
        else if(t[0]==s[0]){
            int k=1;
            string tt=t;
            reverse(all(tt));
            rep(i,tt.size()-2){
                k+=(tt[i+1]-'0')*exp(10,i);
            }

            if(t[(int)t.size()-1]<s[(int)s.size()-1])k=max(0,k-1);
            ans+=k;
        }
        return ans;
    }
}

int main(){
    ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    cout << fixed << setprecision(10);
    /*--------------------------------*/

    int n;cin >> n;
    ll res=0;
    vec<ll> ans(100,-1);
    rep2(i,1,n+1){
        if(i%10==0)continue;
        int k=i%10;
        k+=(to_string(i)[0]-'0')*10;
        if(ans[k]==-1)res+=f(n,k);
        else res+=ans[k];
    }
    cout << res << endl;
}

Measured memory_bytes: 3604
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = 1e9+7,MAX = 1e5;
const double pie = 3.14159265358979;

int main()
{
	double a,b,c,d;
	cin >> a >> b >> c;
	printf("%.7lf\n",a*b*sin(c*pie/180.0)/2);
	printf("%.7lf\n",a+b+sqrt(a*a+b*b-2*a*b*cos(pie*c/180.0)));
	printf("%.7lf\n",b*sin(c*pie/180.0));
	return 0;
}


Measured memory_bytes: 3388
#include <iostream>
#include <algorithm>
#include <math.h>
#include <vector>
#include <string>
#include <queue>
#include <map>
#include <utility>
#include <iomanip>  // std::setprecision()
using namespace std;
using ll = long long;
#define rep(i,a,b) for(int i=(a); i<(b); i++)
#define YES cout << "YES" << endl;
#define NO cout << "NO" << endl;
#define yes cout << "Yes" << endl;
#define no cout << "No" << endl;
#define pai 3.14159265358979323846
ll gcd(ll a, ll b){if (a%b == 0)  return(b);else  return(gcd(b, a%b));}
ll lcm(ll a, ll b){return a * b / gcd(a, b);}
/* map<string,int> */
/* 大文字を小文字に変換 tolower*/
/* 小文字を大文字に変換 toupper*/
/* 辞書順 next_permutation(a.begin(),a.end()) */
 
int main() {
    char a;
    cin >>a ;
    if (a >= 'A' && a <= 'Z') {
        cout << 'A' << endl;
        return 0;
    }
    if (a >= 'a' && a <= 'z') {
        cout << 'a' << endl;
        return 0;
    }
}

Measured memory_bytes: 3060
// This file is a "Hello, world!" in C++ language by GCC for wandbox.
#include <iostream>
#include <cstdlib>
#include <string>
using namespace std;

int main()
{
    int h,n;
    cin >> h >> n;
    string ans;
    
    int a[n];
    for(int i=0; i<n; i++){
        cin >> a[i] ;
    }
    
    int c=0;
    for(int i=0; i<n; i++){
        c += a[i] ;
    }
    
    if(c >= h)
        ans = "Yes";
    else
        ans = "No";
    
    cout << ans << endl;
}

// GCC reference:
//   https://gcc.gnu.org/

// C++ language references:
//   https://cppreference.com/
//   https://isocpp.org/
//   http://www.open-std.org/jtc1/sc22/wg21/

// Boost libraries references:
//   https://www.boost.org/doc/


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


int main() {
  int A,V,B,W,T;
  cin >> A >> V >> B >> W >> T;
  
  if(W >= V){
    cout << "NO" <<endl;
  }
  
  else if(A > B){
    if((A-B)/(V-W)<T){
      cout << "YES" <<endl;
    }
    else if((A-B)%(V-W)==0 && (A-B)/(V-W)==T){
      cout << "YES" <<endl;
    }
    else{
      cout << "NO" <<endl;
    }
  }
  else{
    if((B-A)/(V-W)<T){
      cout << "YES" <<endl;
    }
    else if((B-A)%(V-W)==0 && (B-A)/(V-W)==T){
      cout << "YES" <<endl;
    }
    else{
      cout << "NO" <<endl;
    }
  }
}


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

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

    int i;
    long long n;
    cin >> n;

    vector<int> a(n), b(n), c(n);
    for (i = 0; i < n; i++){
        cin >> a[i];
    }
    for (i = 0; i < n; i++){
        cin >> b[i];
    }
    for (i = 0; i < n; i++){
        cin >> c[i];
    }

    sort(begin(a), end(a));
    sort(begin(b), end(b));
    sort(begin(c), end(c));

    long long res = 0;

    for (i = 0; i < n; i++){
        int acount = lower_bound(a.begin(), a.end(), b[i]) - a.begin();
        int ccount = upper_bound(c.begin(), c.end(), b[i]) - c.begin();
        if(acount >= 1 && ccount != n){
            res += acount * (n - ccount);
        }
    }

    cout << res << endl;

    return 0;
}

Measured memory_bytes: 1408
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#include <map>
using namespace std;


int main()
{
    int A,N;
    int max_num,next_max_num;
    int flag[100000] ={};
    max_num = next_max_num = 0;
    string s;
    cin >> N;

    for (int i = 0; i < N; i++) {
        cin >> A;
        flag[i] = A;
    }
    sort(flag, flag + N,
         [](int a, int b) {return a > b;});

    for (int i = 0; i < N - 1; i++) {
        if (next_max_num) {
            break;
        }

        if (flag[i] == flag[i + 1]) {
            if (max_num) {
                next_max_num = flag[i];
            } else {
                max_num = flag[i];
            }
            i++;
        }
    }
    
    cout << (long long) max_num * next_max_num << "\n";
    return 0;
}

Measured memory_bytes: 640
import java.util.*;
/*
Main class for AOJ where there is no input.
*/
public class Main{
   public static void main(String[] args){
      Scanner sc = new Scanner(System.in);
      int[] height = new int[10];
      
      for(int i = 0; i < 10; i ++){
         height[i] = Integer.parseInt(sc.nextLine());
      }
      
      Arrays.sort(height);
      
      System.out.println(height[9]);
      System.out.println(height[8]);
      System.out.println(height[7]);
      
   }//main
}//class

Measured memory_bytes: 26052
import java.util.Scanner;

public class Main{
  public static void main(String[] args){
    Scanner scan = new Scanner(System.in);
    String S = scan.next();
    String ans = "";
    
    if(S.equals("ABC")){
      ans = "ARC";
    }else if(S.equals("ARC")){
      ans = "ABC";
    }
    
    System.out.println(ans);
  }
}

Measured memory_bytes: 35676
#include<stdio.h>

int main( void ) 
{
	int a,b;
	char  op='\0';
	
	for( ; '?' != op; ) {
		scanf( "%d %c %d", &a, &op, &b );
		
		if( '?' == op ) { break; }		
		switch( op ) {
			case '+':
				printf( "%d\n", a+b);
				break;
			case '-':
				printf( "%d\n", a-b);
				break;
			case '*':
				printf( "%d\n", a*b);
				break;
			case '/':
				printf( "%d\n", a/b);
				break;
		}
		
	}

	return 0;
}

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

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


  if(H==1 || W==1){
    cout << 1 << endl;
  }else
  {
    cout << (H*W + 1)/2 << endl;
  }
  
  

  return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <cmath>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
constexpr ll INF = 1ll << 55;
constexpr int INFi = 1ll << 28;

template <typename T> inline constexpr bool chmin(T &a, T b) {
  if (b <= a) {
    a = b;
    return true;
  }
  return false;
}
template <typename T> inline constexpr bool chmax(T &a, T b) {
  if (b >= a) {
    a = b;
    return true;
  }
  return false;
}

// multi-dimensional vector (require c++14)
template <typename T, typename U>
static inline vector<U> make_nd_vector(T &&n, U &&val) noexcept {
  static_assert(is_integral<T>::value,
                "[make_nd_vector] 1st argument must be an integer type");
  return vector<U>(forward<T>(n), forward<U>(val));
}
template <typename T, typename... Args>
static inline decltype(auto) make_nd_vector(T &&n, Args &&... args) noexcept {
  static_assert(is_integral<T>::value,
                "[make_nd_vector] 1st argument must be an integer type");
  return vector<decltype(make_nd_vector(forward<Args>(args)...))>(
      forward<T>(n), make_nd_vector(forward<Args>(args)...));
}
//
// Print from Iterator
template <typename ite>
void print_ite(ite start, ite end, char sp = ' ', char en = '\n') {
  for (auto i = start; i != end; i++)
    cout << *i << sp;
  cout << en;
}
//
inline void Yes(bool condition) { cout << (condition ? "Yes\n" : "No\n"); }

int main() {
  int x, n;
  cin >> x >> n;
  if (n == 0) {
    cout << x << endl;
    return 0;
  }
  vector<bool> nums(205, false);
  for (int i = 0; i < n; i++) {
    int p;
    cin >> p;
    nums[p] = true;
  }
  int ans = INFi;
  int diff = INFi;
  for (int i = 200; i >= 0; i--) {
    if (!nums[i]) {
      if (chmin(diff, abs(x - i))) {
        chmin(ans, i);
      }
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 3164
#include<stdio.h>
#include<iostream>
#include<math.h>
using namespace std;

int main()
{
	long long n, a;
	long long k = 0;
	cin >> n;
	long long maxx = -2147483647, minn = 2147483647;
	for (long long i = 0; i < n; i++)
	{
		cin >> a;
		if (a > maxx)maxx = a;
		if (a < minn)minn = a;
		k += a;
	}
	printf("%lld %lld %lld\n", minn, maxx, k);
	return 0;
}

Measured memory_bytes: 3184
#include<iostream>
using namespace std;
int main()
{
	int n,m;
	cin>>n>>m;
	if(n==m)
	{
		for(int i=0;i<n;i++)
		cout<<n;
	}
	else 
	{
		int a=n,b=m;
		if(a>b)
		{
			int t;
			t=a;a=b;b=t;
		}
		for(int i=0;i<b;i++)
		cout<<a;
	}
 } 

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ft first
#define sc second
#define lb lower_bound
#define ub upper_bound
#define pb push_back
#define pt(sth) cout << sth << "\n"
#define chmax(a, b) {if(a<b) a=b;}
#define chmin(a, b) {if(a>b) a=b;}
#define moC(a, s, b) (a)=((a)s(b)+MOD)%MOD
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
static const ll INF=1e18;
static const ll MAX=1e5+7;
static const ll MOD=1e9+7;
ll max(ll a, ll b) {return a>b?a:b;}
ll min(ll a, ll b) {return a<b?a:b;}



int main(void) {
  ll N;
  cin >> N;
  ll a[MAX*2];
  ll b[MAX*2];
  ll i;
  
  for(i=0; i<N; i++) {
    cin >> a[i];
    b[i]=a[i];
  }
  sort(b, b+N);
  
  ll m1=b[N-1];
  ll m2=b[N-2];
  
  for(i=0; i<N; i++) {
    if(a[i]==m1) {
      pt(m2);
    }else {
      pt(m1);
    }
  }
  
}









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

using namespace std;

int main(){
    int A[9];
    int n, b[10];
    bool card[9];
    for(int i = 0; i < 9; i++) {
        card[i] = false;
        cin >> A[i];
    }
    cin >> n;
    for(int i = 0; i < n; i++) {
        cin >> b[i];
    }

    for(int i = 0; i < n; i++) {
        for(int j = 0; j < 9; j++) {
            if(A[j] == b[i]) {
                card[j] = true;
            }
        }
    }

    bool bingo = false;
    for(int i = 0; i < 3; i++) {
        if(card[3*i] && card[3*i+1] && card[3*i+2]) {
            bingo = true;
        }
        if(card[0+i] && card[3+i] && card[6+i]) {
            bingo = true;
        }
    }
    if(card[0] && card[4] && card[8]) {
        bingo = true;
    }
    if(card[2] && card[4] && card[6]) {
        bingo = true;
    }

    if(bingo) {
        cout << "Yes"<< endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}


Measured memory_bytes: 3640