akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

using db = double;
using ll = long long;
using vi = vector <int>;
#define op operator
#define pb push_back

using pii = pair <int, int>;

const int N = 511;
vector <pii> e[N], r[N];
int f[N], g[N], h[N];

void dij(int n, int s, vector <pii> *e, int *f) {
	for(int i = 1; i <= n; i ++)
		f[i] = 1e8L;
	f[s] = 0; set <pii> st;
	for(int i = 1; i <= n; i ++)
		st.insert({f[i], i});
	while(!st.empty()) {
		pii p = *st.begin(); st.erase(st.begin());
		int u = p.second;
		for(pii i : e[u]) {
			int v = i.first, w = i.second;
			if(f[u] + w < f[v]) {
				st.erase({f[v], v});
				f[v] = f[u] + w;
				st.insert({f[v], v});
			}
		}
	}
}

int main() {
	cout << fixed << setprecision(9);
	ios :: sync_with_stdio(0);

	int n, m, s, g1, g2;
	while(cin >> n >> m >> s >> g1 >> g2 && n) {
		for(int i = 1; i <= n; i ++) {
			e[i].clear();
			r[i].clear();
		}
		for(int i = 0; i < m; i ++) {
			int u, v, w; cin >> u >> v >> w;
			e[u].pb({v, w});
			r[v].pb({u, w});
		}
		dij(n, s, e, f);
		dij(n, g1, r, g);
		dij(n, g2, r, h);

		int ans = 1e8L;
		for(int i = 1; i <= n; i ++)
			ans = min(ans, f[i] + g[i] + h[i]);
		cout << ans << '\n';
	}

	return 0;
}

Measured memory_bytes: 3220
N = int(input())
ans = 1
prev = 0
for i in range(1,N+1):
  counter = 0
  while i % 2 == 0:
    i /= 2
    counter += 1
  if prev < counter:
    ans = int(i * (2**counter))
    prev = counter
    
print(ans)

Measured memory_bytes: 3060
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
using namespace std;
int main(){
	char a,b;
	cin>>a>>b;
	if(a==b)cout<<'H';
	else cout<<'D';
    return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<functional>
using namespace std;
int main(void)
{
	int n,k,p,x,i,j;
	scanf("%d",&n);
	for(i=0;i<n;i++)	{
		scanf("%d %d",&k,&p);
		x=k%p;
		if(x==0)	x=p;
		printf("%d\n",x);
	}
	return 0;
}


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

int main() {
	int64_t x, y;
	cin >> x >> y;
	int cnt = 0;
	while (x <= y) {
		cnt++;
		x *= 2;
	}
	cout << cnt << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(long long int i = 0; i < n; i++)
#define print(n) std::cout << n << std::endl
#define _print(n) std::cout << n
using namespace std;
typedef long long ll;
const int N = 1000000;

int main(){
    int a,b; cin >> a;
    string s; cin >> s;
    cin >> b;
    if(s == "+")print(a + b);
    else print(a - b);
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int n;ll k;
int a[200010],head[200010],nxt[200010],ne[200010],cz[200010],t[200010];
int sta[200010],top;bool b[200010];
int calc(int pl){
	for(int i=pl;i<=n;i++){
		if(!b[a[i]])sta[++top]=a[i],b[a[i]]=1;
		else {
			b[a[i]]=0;
			while(sta[top]!=a[i])b[sta[top]]=0,top--;
			top--;
		}
	}
	for(int i=1;i<=top;i++)cout<<sta[i]<<' ';exit(0);
}
int main(){
	cin>>n>>k;
	if(n==1&((k+1)&1))return 0;
	for(int i=1;i<=n;i++)cin>>a[i];
	if(k==1)calc(1);
	for(int i=n;i>=1;i--){
		nxt[i]=head[a[i]];
		head[a[i]]=i;
	}
	for(int i=1;i<=n;i++)if(!nxt[i])nxt[i]=head[a[i]];
	for(int i=n;i>=1;i--)if(nxt[i]<=i)ne[i]=nxt[i];
	else ne[i]=ne[nxt[i]+1];
	for(int i=1;i<=n;i++)ne[i]=ne[i]+1;ne[n+1]=1;
	cz[1]=1;t[1]=1;
	for(int i=2;i<=k;i++){
		cz[i]=ne[cz[i-1]];
		if(i==k)calc(cz[i]);
		if(t[cz[i]]){
			//xunhuanjie:
			int L=t[cz[i]],R=i-1;
			k=(k-L+1)%(R-L+1);
			if(k==0)k=R-L+1;
			calc(cz[k]);
		}
		t[cz[i]]=i;
	}
}


Measured memory_bytes: 6656
#include <bits/stdc++.h>
using namespace std;
int main()
{
  string te;
  cin>>te;
  int t1 = 0 , t2 = 0;
  for(int i = 0 ; i < 2 ; i++)
  {
    t1 = t1 * 10 + (te[i] - '0');
  }
  for(int i = 2 ; i < 4 ; i++)
  {
    t2 = t2 * 10 + (te[i] - '0');
  }
  //cout<<t1 <<" " << t2<<endl;
  if(t1 <= 12 && t1 > 0 && (t2 >= 13 || t2 == 0)) puts("MMYY");
  else if((t1 >= 13 || t1 == 0) && t2 <= 12 && t2 > 0) puts("YYMM");
  else if(t1 <= 31 && t2 <= 31 && t1 != 0 && t2 != 0) puts("AMBIGUOUS");
  else puts("NA");


}

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define DUMP(x)  cout << #x << " = " << (x) << endl;
#define FOR(i, m, n) for(ll i = m; i < n; i++)
#define IFOR(i, m, n) for(ll i = n - 1; i >= m; i-- )
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
#define FOREACH(x,a) for(auto& (x) : (a) )
#define ALL(v) (v).begin(), (v).end()

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


Measured memory_bytes: 256
import sys
input = sys.stdin.readline
n,m=map(int,input().split())
g=[[] for _ in range(n)]
for _ in range(m):
    a,b=map(int,input().split())
    g[a-1].append(b-1)
    g[b-1].append(a-1)
from itertools import permutations
P=list(permutations(range(n)))
#print(P)
cnt=0
for p in P:
    if p[0]!=0:
        continue
    flg=True
    for i in range(len(p)-1):
        #print(p)
        if p[i] not in g[p[i+1]]:
            flg=False
    if flg:
        cnt+=1
print(cnt)


Measured memory_bytes: 45424
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <queue>
#include <map>
#include <numeric>
#include <unordered_map>
#include <iomanip>
#include <functional>
#include <bitset>
#include <complex>
#include <stack>
#include <cstdint>



#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define rrep(i, n) for(ll i = (ll)(n-1); i >= 0; i--)
#define repi(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rrepi(i,a,b) for(ll i=(ll)(b-1);i>=(ll)(a);i--)

#define all(x) (x).begin(),(x).end()

template<class T>inline bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>inline bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

typedef long long ll;

using namespace std;

ll n,k;
vector<ll>a;
ll lo(ll num,ll d){
  ll mo=num%d;
  if(mo<0)mo+=d;
  return (num-mo)/d;
}
ll hi(ll num,ll d){

  ll mo=num%d;
  if(mo<0)mo+=d;
  if(mo!=0)mo-=d;
  return (num-mo)/d;
}
bool check(ll num){//numがkばんめ以降か
  ll cnt=0;//numより小さいもの
  rep(i,n){
    if(a[i]==0){
      if(0ll<num)cnt+=n-1-i;
      continue;
    }
    if(a[i]>0){
      ll tn=hi(num,a[i]);
      ll id=lower_bound(all(a),tn)-a.begin();
      cnt+=max(0ll,id-i-1);
    }
    else {
      ll tn=lo(num,a[i]);
      ll id=upper_bound(all(a),tn)-a.begin();
      cnt+=max(0ll,n-max(i+1,id));
    }
  }
  //cout<<cnt<<" "<<num<<endl;
  return cnt>=k;
}
bool check2(ll num){
  ll cnt=0;
  rep(i,n){
    if(a[i]<0){
      ll lo=-1,hi=n;
      while(hi-lo>1){
        ll mid=(hi+lo)/2;
        if(a[i]*a[mid]<num)hi=mid;
        else lo=mid;
      }
      cnt+=n-hi;
      if(a[i]*a[i]<num)cnt--;
    }
    else {
      ll lo=-1,hi=n;
      while(hi-lo>1){
        ll mid=(hi+lo)/2;
        if(a[i]*a[mid]<num)lo=mid;
        else hi=mid;
      }
      cnt+=hi;
      if(a[i]*a[i]<num)cnt--;
    }
  }
  return cnt/2>=k;
}
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin>>n>>k;
  a.resize(n);
  rep(i,n)cin>>a[i];
  sort(all(a));
  ll ng=-(ll)1e18-7,ok=(ll)1e18+7;

  while(abs(ok-ng)>1){
    ll mid=(ok+ng)/2;
    if(check2(mid))ok=mid;
    else ng=mid;
  }
  cout<<ng<<endl;

  return 0;

}


Measured memory_bytes: 1920
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.BufferedReader;
public class Main {
    public static void main(String[] args) throws NumberFormatException, IOException {

       BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringBuilder sb = new StringBuilder();

        int i = 1;
        while (true) {
            int n = Integer.parseInt(br.readLine());
            if (n == 0) {
                break;
            }
            sb.append("Case ").append(i).append(": ").append(n).append("\n");
            i++;
        }
        System.out.print(sb);
    }

}

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

long long int r,D,x;
int main (){
    cin >> r >> D >>x;
    long long int p = x;
    for(int i=1; i<=10; i++) {
        p = r * p - D;
        cout << p << endl;
    }
    return 0;
}


Measured memory_bytes: 256
a,b,x = [int(x) for x in input().split()]
sq = x/a
sq2 = a*b - sq
if sq2 <= a*b/2:
  line = sq2*2/a+0.00000001
  import math 
  #print(sq,sq2,line)
  t = 90-math.degrees(math.atan(a/line))
  print(t)
else:
  line = sq*2/b+0.00000001
  import math 
  #print("a",sq,sq2,line)
  t = 90-math.degrees(math.atan(line/b))
  print(t)

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

#define int         long long
#define endl        "\n"
#define P           pair<int, int>

const int mod = 998244353;

inline int add(int x, int y) { int res = x + y; if(res >= mod) res -= mod; return res; }
inline int sub(int x, int y) { int res = x - y; if(res < 0) res += mod; return res; }
inline int mul(int x, int y) { int res = (x % mod * y % mod) % mod; return res; }

int modpow(int a, int b) {
    if(a == 0 || a == 1 || b == 1) return a;
    int res = 1;
    while(b) {
        if(b % 2) res = mul(res, a);
        b /= 2;
        a = mul(a, a);
    }
    return res;
}

const int N = 3003;
int pw[N];
const int MI2 = modpow(2, mod - 2);
int dp[N][N];
int n, s;
int a[N];

void solve() {
    cin >> n >> s;
    for(int i=1; i<=n; i++) cin >> a[i];
    memset(dp, 0, sizeof dp);
    dp[0][0] = pw[n];
    for(int i=1; i<=n; i++) {
        for(int j=0; j<=s; j++) {
            dp[i][j] = add(dp[i][j], dp[i - 1][j]);
            if(j - a[i] >= 0) dp[i][j] = add(dp[i][j], mul(MI2, dp[i-1][j - a[i]]));
        }   
    }
    cout << dp[n][s] << endl;
}

signed main() {

    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    cout << fixed << setprecision(12);

    int T = 1;
    // cin >> T;
    pw[0] = 1;
    for(int i=1; i<N; i++) pw[i] = mul(2, pw[i-1]);
    for(int i=1; i<=T; i++) {
        solve();
    }
    return 0;
}

Measured memory_bytes: 74136
/* Nurgazy Zhandos */

#include <bits/stdc++.h>
#include <functional>
#include <algorithm>
#include <stdexcept>
#include <streambuf>	
#include <exception>
#include <typeinfo>
#include <valarray>
#include <iostream>
#include <iterator>
#include <cstdlib>
#include <istream>
#include <iomanip>
#include <fstream>
#include <complex>
#include <utility>
#include <ostream>
#include <numeric>	
#include <sstream>
#include <utility>
#include <bitset>
#include <iosfwd>
#include <string>
#include <limits>
#include <vector>
#include <cstdio>
#include <locale>
#include <memory>	
#include <string>	
#include <vector>
#include <queue>
#include <deque>
#include <cmath>
#include <stack>
#include <queue>
#include <stack>
#include <list>	
#include <map>
#include <set>
#include <ios>
#include <new>
//#include <unordered_set>
//#include <unordered_map> 

#define F first
#define S second

#define pf push_front
#define pb push_back
#define mp make_pair
#define pp pop_back
#define in insert

#define resize(v) v.resize(unique(all(v)) - v.begin()); 
#define all(a) a.begin(), a.end()
#define sz(a) a.size()
#define STOP return 0

#define nl '\n'

//#define int long long

using namespace std;

typedef pair <int, pair <int, int > > pIii;
typedef pair < pair <int, int >, int> piiI;
typedef pair <long long, long long> pll;
typedef pair <int, long double> pid;
typedef pair <long double, int> pdi;
typedef pair <int, long long> pil;
typedef pair <long long, int> pli;
typedef unsigned long long ull;
typedef pair <int, int> pii;
typedef long double ld;
typedef long long ll;

const int MAX_N = 1e5 + 123;
const int inf = 1e9 + 123;
const ll INF = 1e18 + 123;
const int NN = 2e6 + 123;
const double eps = 1e-9;
const int mod = 1e9 + 7;

inline void fre() {
	freopen(".in", "r", stdin);                                                                                                                       
	freopen(".out", "w", stdout);
}

inline void boost() {
	ios_base :: sync_with_stdio(0);
	cin.tie(0), cout.tie(0);
}

vector <int > v;

int main () {
	//fre();
	boost();

	ll n;
	cin >> n;

	int mx = 0;

	ll m = n;
	int cnt = 0;

	int f = 0;

	while(m > 0) {
		mx += m % 10;
		v.pb(m % 10);
		f = m % 10;
		m /= 10;
		cnt++;
	}

	mx = max(mx, (cnt - 1) * 9);
	
	int g;

	if(f > 1) {
	 	g = 0;
	 	g += f - 1;
	 	g += (cnt - 1) * 9;
		mx = max(mx, g);
	}

	int cur = 0;

	reverse(all(v));

	for(int i = 0; i < sz(v); i++) {
		if(v[i] >= 1) {
	 		mx = max(mx, cur + (v[i] - 1) + ((cnt - 1) * 9));
		 }
		 	cur += v[i];
		 	cnt--;
	}

	cout << mx;
return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int A, B;
    scanf("%d %d", &A, &B);
    
    int result;
    if(A <= 5){
        result = 0;
    }else if(A <= 12){
        result = B/2;
    }else{
        result = B;
    }
    
    cout << result;
}


Measured memory_bytes: 256
# coding: utf-8
# Your code here!
import sys
readline = sys.stdin.readline
read = sys.stdin.read

n, = map(int,readline().split())
*a, = map(int,readline().split())
*b, = map(int,readline().split())
b = b[::-1]

same = [i for i in range(n) if a[i] == b[i]]
if same:
    # 以下すべて半開区間
    v = a[same[0]] # 重なる値は一種類しかない。これを v とおく。
    r = same[0]
    s = same[-1]+1
    vidx = [i for i in range(n) if a[i]==v or b[i]==v]
    p = vidx[0]
    q = vidx[-1]+1
    # [p,q) でかぶる。[r,s)でどちらかが値 v をとる
    if q > n-s+r+p: # かぶりを吹っ飛ばせない
        print("No")
        exit()
    # かぶった部分を左、右によける
    if p >= s-r:
        b[r:s],b[:s-r] = b[:s-r],b[r:s]
    else:
        b[r:r+p],b[:p] = b[:p],b[r:r+p]
        b[r+p:s],b[n-s+r+p:] = b[n-s+r+p:], b[r+p:s]

print("Yes")
print(*b)



Measured memory_bytes: 41720
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <vector>
#include <utility>
#include <cstring>
#include <queue>
#include <stack>
#define rep(i, s, g) for (i = s; i <= g; i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const ll MOD = 1e9 + 7;

int main(void)
{
    int N, K;
    vector<double> p;
    int i, j;
    double sum = 0;
    double maxs;

    cin >> N >> K;

    p.resize(N + 1);

    rep(i, 0, N - 1)
    {
        cin >> p[i];

        if (i < K)
        {
            sum += (double)(p[i] + 1) / 2;
            maxs = sum;
        }
        else
        {
            maxs = max(maxs, sum + (double)(p[i] + 1) / 2 - (double)(p[i - K] + 1) / 2);
            sum = sum + (double)(p[i] + 1) / 2 - (double)(p[i - K] + 1) / 2;
        }
    }

    printf("%.7f\n", maxs);
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
long long int mod = 1000000007;
long long int modPow(long long int a, long long int n){//繰り返し自乗法(a^n mod p)。計算量 O(logN)
    long long int p = pow(10, 9) + 7;//任意のp(素数) modのやつで使える 
    if(n == 0){
        return 1;
    }
    if(n == 1){
        return a % p;
    }
    if (n % 2 == 1){ 
        return (a * modPow(a, n - 1)) % p;
    }      
    long long t = modPow(a, n / 2);
    return (t * t) % p;
}

int main(){
    long long int n;
    cin >> n;
    vector<long long int> a(n);
    vector<long long int> b(n - 1);
    long long int res = 0;
    long long int sum = 0;
    for(int i = 0; i < n; i++){
        cin >> a.at(i);
        sum = (sum + a.at(i)) % mod;
    }
    for(int i = 0; i < n - 1; i++){
        b.at(i) = (sum - a.at(i)) % mod;
        sum -= a.at(i);
        // cout << b.at(i) << endl;
        if(b.at(i) < 0){
            b.at(i) += mod;
        }
    }

    long long int tmp = 0;
    for(int i = 0; i < n - 1; i++){
        tmp = (a.at(i) * b.at(i)) % mod;
        res = (res + tmp) % mod;
        /*
        for(int j = i + 1; j < n; j++){
            tmp = a.at(i) * a.at(j) % mod;
            res = (res + tmp) % mod;
        }
        */
    }
    cout << res << endl;

}

Measured memory_bytes: 6360
#include <bits/stdc++.h>
#pragma GCC target("avx2")
#pragma GCC optimization("O3")
#pragma GCC optimization("unroll-loops")
#define all(vec) vec.begin(), vec.end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
constexpr ll INF = (1LL << 30) - 1LL;
constexpr ll LINF = (1LL << 60) - 1LL;
constexpr ll MOD = 1e9 + 7;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }
int a[2000], c[1001];
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    int ma = 0;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        c[a[i]]++;
        chmax(ma, a[i]);
    }
    int ans = 0;
    int i, j, k;
    for (i = 1; i <= ma; i++) {
        if (c[i] >= 3) {
            ans += c[i] * (c[i] - 1LL) * (c[i] - 2LL) / 6LL;
        }
        for (j = i + 1; j <= ma; j++) {
            if (c[i] >= 2 && j < i + i) {
                ans += c[i] * (c[i] - 1LL) / 2LL * c[j];
            }
            if (c[j] >= 2) {
                ans += c[j] * (c[j] - 1LL) / 2LL * c[i];
            }
            int su = i + j;
            for (k = j + 1; k <= ma; k++) {
                if (k < su) {
                    ans += c[i] * c[j] * c[k];
                }
            }
        }
    }
    cout << ans << "\n";
}

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

  int N ;
  cin >> N ;
  vector<int> A(N) ;
  rep(i,N) cin >> A.at(i) ;
  rep(i,N){
    if( A.at(i)%2 == 0 ){
      if(A.at(i)%3 == 0 || A.at(i)%5 == 0 ) continue ;
      else{
        cout << "DENIED" << endl;
        return 0 ;
      }
    }
  }
  cout << "APPROVED" << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
using namespace std;
int main(void){
  double N,M;
  cin >> N >> M;
  
  vector<int>a(N);
  for(int i=0;i<N;i++){
    cin >> a[i];
  }
  
  double total = 0;
  
  for(int i=0;i<N;i++){
    total += a[i];
  }
  
  double c = total / (4 * M);
  
  int ans = 0;
  for(int i=0;i<N;i++){
    if(a[i] >= c) ans++;
  }
  
  if(ans >= M) cout << "Yes" << endl;
  else cout << "No" << endl;
  
  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args) throws Exception {

//    	File file = new File("test.txt");
//    	Scanner sc = new Scanner(file);
    	Scanner sc = new Scanner(System.in);
    	double a = sc.nextDouble();
    	double b = sc.nextDouble();
    	int H = sc.nextInt();
    	int M = sc.nextInt();
    	sc.close();
    	double ans = 0;
    	double X = Math.abs((M * 6) - ((H * 30) + (M * 0.5)));
    	if(X > 180){
    		X = 360 - X;
    	}
    	double cos = Math.cos(Math.toRadians(X));
    	ans = a*a + b*b - 2 * a * b * cos;
    	System.out.println(Math.sqrt(ans));
    }
}

Measured memory_bytes: 37292
N= int(input())
A = [int(x) for x in input().split()]
for i in A:
  if i%2==0 and (i%3==0 or i%5==0):
    continue
  elif i%2==0 and (i%3!=0 or i%5!=0):
    print("DENIED")
    exit()
print("APPROVED")

Measured memory_bytes: 38384
#include <iostream>
#include <vector>
#include <deque>
#include <algorithm>
#include <numeric>
#include <string>
#include <cstring>
#include <list>
#include <unordered_set>
#include <tuple>
#include <cmath>
#include <limits>
#include <type_traits>
#include <iomanip>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <set>
#include <bitset>
#include <regex>
#include <random>
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
#define rep(i,n)for(ll i=0;i<n;++i)
#define exout(x) printf("%.10f\n", x)
const double pi = acos(-1.0);
const ll MOD = 1000000007;
const ll INF = 1e18;
const ll MAX_N = 201010;

//最大公約数
ll gcd(ll x, ll y) {
	return y ? gcd(y, x % y) : x;
}

ll lcm(ll x, ll y) {
	if (x == 0 || y == 0)return 0;
	return (x / gcd(x, y) * y);
}

ll dx[4] = { 0,0,-1,1 };
ll dy[4] = { -1,1,0,0 };
ll ans[110][110];

//long longしか使わない
//素数は1より大きい
//lower_boundは指定したkey以上の要素の一番左のイテレータをかえす
//upper_boundは指定したkeyより大きい要素の一番左のイテレータをかえす
int main() {
	ll n;
	cin >> n;
	vector<ll>a(n);
	ll minus = 0;
	ll ans = 0;
	rep(i, n) {
		cin >> a[i];
		if (a[i] < 0)minus++;
		a[i] = abs(a[i]);
		ans += a[i];
	}
	sort(a.begin(), a.end());
	if (minus % 2 == 0) {
		cout << ans << endl;
	}
	else {
		ans -= a[0] * 2;
		cout << ans << endl;
	}
	return 0;
}


Measured memory_bytes: 4024
H,W,D = list(map(int,input().split()))

A = [list(map(int,input().split())) for i in range(H)]

Num = [0]*H*W

for i in range(H):
    for j in range(W):
        Num[A[i][j]-1] = (i,j)


Q = int(input())

B = [list(map(int,input().split())) for i in range(Q)]

S = []
for i in range(D):
    s = [0]
    score = 0
    num = i+D
    while num<H*W:
        score += abs(Num[num][0]-Num[num-D][0])+abs(Num[num][1]-Num[num-D][1])
        num += D
        s.append(score)
    S.append(s)

for b in B:
    d = (b[0]-1)%D
    n1 = (b[1]-1)//D
    n0 = (b[0]-1)//D
    print(S[d][n1]-S[d][n0])

Measured memory_bytes: 82268
import sys
import itertools
sys.setrecursionlimit(10000)
def resolve():
    N = int(input())
    d = {
        "M": 0,
        "A": 0,
        "R": 0,
        "C": 0,
        "H": 0
    }
    for i in range(N):
        name = input()
        if name[0] in d:
            d[name[0]] += 1
    
    import itertools
    combs = list(itertools.combinations(d.keys(), 3))

    cnt = 0
    for comb in combs:
        cnt += d[comb[0]] * d[comb[1]] * d[comb[2]]
    
    print(cnt)

if '__main__' == __name__:
    resolve()

Measured memory_bytes: 43624
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define all(v) v.begin(),v.end()
#define P pair<int,int>
#define siz(s) (int)s.size()
#define pb push_back

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;
}
void cmps(vector<int>&v,int &i){
	i=lower_bound(all(v),i)-v.begin();
}
constexpr int mod = 1e9+7;
constexpr int inf = 3e18;


signed main(){
	int K,A,B;
	cin>>K>>A>>B;
	for(int i=A;i<=B;i++){
		if(i%K==0){
			cout<<"OK\n";return 0;
		}
	}
	cout<<"NG\n";
}


Measured memory_bytes: 3648
#include<bits/stdc++.h>
using namespace std;
const int maxn=300009;
const int inf=1000000000;


struct Set{
	priority_queue<int>q1,q2;
	void push(int x){
		q1.push(x);
	}
	void pop(int x){
		q2.push(x);
	}
	int top(){
		while(!q2.empty()&&q1.top()==q2.top()){
			q1.pop();q2.pop();
		}
		if(q1.empty())return 0;
		return q1.top();
	}
}S;

int H,W;
int m;

int cnt[maxn];

vector<int>G[maxn];

int main(){
	scanf("%d%d%d",&H,&W,&m);
	while(m--){
		int x,y;scanf("%d%d",&x,&y);
		G[x].push_back(y);
		cnt[y]++;
	}
	for(int i=1;i<=W;++i)S.push(cnt[i]);
	
	int ans=0;
	for(int i=1;i<=H;++i){
		for(int j=0;j<G[i].size();++j){
			int y=G[i][j];
			S.pop(cnt[y]);--cnt[y];S.push(cnt[y]);
		}
		ans=max(ans,(int)G[i].size()+S.top());
		for(int j=0;j<G[i].size();++j){
			int y=G[i][j];
			S.pop(cnt[y]);++cnt[y];S.push(cnt[y]);
		}
	}
	
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 30244
import java.io.File;
import java.io.FileNotFoundException;
import java.util.Arrays;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) throws FileNotFoundException {
        Scanner s = new Scanner(System.in);

        int n = s.nextInt();

        int result = 0;

        int p1 = s.nextInt();
        int p2 = s.nextInt();
        int p3;

        for (int i = 0; i < n - 2; i++) {
            p3 = s.nextInt();

            if (p1 > p2 && p2 > p3) {
                result += 1;
            } else if (p1 < p2 && p2 < p3) {
                result += 1;
            }

            p1 = p2;
            p2 = p3;
        }

        System.out.println(result);

    }
}


Measured memory_bytes: 21844
# encoding:utf-8
import copy
import random
import bisect #bisect_left　これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
import math
import sys
import collections

mod = 10**9+7
sys.setrecursionlimit(mod) # 再帰回数上限はでdefault1000

d = collections.deque()
def LI(): return list(map(int, sys.stdin.readline().split()))

X, Y = LI()

ans = True
if Y % 2 == 1:
    ans = False

if X * 2 <= Y <= X * 4:
    pass
else:
    ans = False



if ans:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 10924
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "debug.h"
#else
#define dump(...)
#endif
#define endl "\n"
#define ll long long
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define REP(i, x) for (int i = 0; i < (int)(x); i++)
#define REPS(i, x) for (int i = 1; i <= (int)(x); i++)
#define RREP(i, x) for (int i = ((int)(x)-1); i >= 0; i--)
#define RREPS(i, x) for (int i = ((int)(x)); i > 0; i--)
#define INF 2147483647
#define LLINF 9223372036854775807LL
#define vi vector<int>
#define vvi vector<vector<int>>
#define pi pair<int, int>
#define ALL(a) (a).begin(), (a).end()
#define BIT(n) (1LL << (n))
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end()) //sortしてからつかうこと
constexpr ll MOD = 1e9 + 7;
int dx[8] = {1, 0, -1, 0, 1, 1, -1, -1};
int dy[8] = {0, 1, 0, -1, 1, -1, 1, -1};
ll A, B, C, D, E, F, G, H, N, M, L, K, P, Q, R, W, X, Y, Z;
string S, T;
ll ans = 0;

template <typename T>
istream &operator>>(istream &is, vector<T> &vec) {
    for (T &x : vec)
        is >> x;
    return is;
}

signed main() {
    cin >> A;
    cout << A + A * A + A * A * A << endl;
}

Measured memory_bytes: 3628
N,K=map(int,input().split())
P=[1]
for k in range(17):
    P.append(P[-1]/2)

Q=0
for i in range(1,N+1):
    u=0
    x=i
    while x<K:
        u+=1
        x*=2
    Q+=P[u]

print(Q/N)


Measured memory_bytes: 79976
#include<iostream>
using namespace std;
int main(){
  int K, S;
  int count = 0;
  cin >> K >> S;
  for(int x = 0;x < K+1 ;x++){
    for(int y = 0; y < K +1; y++){
        int z = S - x - y;
        if(0 <= z && z <= K) count++;
    }
  }
  cout << count <<endl;
}

Measured memory_bytes: 256
N = int(input())
line = input().split(" ")
A = [int(c) for c in line]

answer = "YES"
memo = {}
for a in A:
    if memo.get(a) is None:
        memo[a] = 1
    else:
        memo[a] += 1
        answer = "NO"
        break

print(answer)


Measured memory_bytes: 46668
#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++)
using ll = long long;
using VL = vector<ll>;
using VVL = vector<vector<ll>>;
using P = pair<ll, ll>;

// chmin, chmax関数
template<typename T, typename U, typename Comp=less<>>
bool chmax(T& xmax, const U& x, Comp comp={}) {
    if(comp(xmax, x)) {
        xmax = x;
        return true;
    }
    return false;
}
template<typename T, typename U, typename Comp=less<>>
bool chmin(T& xmin, const U& x, Comp comp={}) {
    if(comp(x, xmin)) {
        xmin = x;
        return true;
    }
    return false;
}

// Yes-Noを出力する問題で楽をする
void Ans(bool f){
    if(f) cout << "Yes" << endl;
    else cout << "No" << endl;
}

//---------------------------

int main(){
    ll n, k; cin >> n >> k;
    cout << min(n%k, k-n%k) << endl;
    return 0;
}

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

typedef long long int ll;

int main(){
    int N, point;
    cin >> N;

    vector<ll> A(N);
    for(int i=0; i<N; i++){
        cin >> A[i];
        }
    sort(A.begin(), A.end());
    int Size = N;
    int k = 0;
    while(Size > 1){
        if(A[k] == 0){ k++;if(k>N)k=0;continue;}
        for(int i=0; i<N; i++){
            if(i != k && A[i] != 0){
                A[i] = A[i] % A[k];
                if(A[i]==0){
                    Size--;
                    if(Size==1) cout << A[k];
                    }
                }



            }
            k++;
            if(k>N)k=0;
        }
}

Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
#include <vector>
#include <numeric>
#include <map>
#include <cmath>
#include <iomanip>
using ll =long long;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;

int main(){
    int N, M;
    cin >> N >> M;
    vi A(N);

    double a, b;
    int sum = 0;
    for (int i = 0; i < N; ++i) {
        cin >> A.at(i);
        sum += A.at(i);
    }

    a = (double)sum * 1/(4 * (double)M);

    int c = 0;
    for (int i = 0; i < N; ++i) {
        if(A.at(i) >= a){
            c++;
        }
    }

    if(c >= M){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }


}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
#define lli long long int
#define REP(i,s,n) for(int i=s;i<n;i++)
#define MOD 1000000007
#define NUM 2520
#define INF (1LL<<50)
#define DEBUG 0
#define mp(a,b) make_pair(a,b)
#define SORT(V) sort(V.begin(),V.end())
#define PI 3.14159265358979

struct LazySegmentTree{
private:
	lli n;
	vector<lli> node;
	vector<lli> lazy;

public:
	LazySegmentTree(vector<lli> &v){
		lli size = v.size();
		n = 1;while(n<size)n*=2;

		node.resize(2*n-1);
		lazy.resize(2*n-1,0);

		REP(i,0,size)node[i+n-1]=v[i];
		for(lli i=n-2;i>=0;i--)node[i] = node[2*i+1]+node[2*i+2];
	}

	void eval(lli k,lli l,lli r){
		if(lazy[k] != 0){
			node[k]+=lazy[k];

			if(r-l>1){
				lazy[2*k+1] += lazy[k]/2;
				lazy[2*k+2] += lazy[k]/2;
			}
			lazy[k]=0;
		}
	}

	void add(lli a,lli b,lli x,lli k=0,lli l=0,lli r=-1){
		if(r<0)r = n;
		eval(k,l,r);

		if(b<=l || r<=a)return;

		if(a<=l && r<=b){
			lazy[k] += (r-l)*x;
			eval(k,l,r);
		}
		else{
			add(a,b,x,2*k+1,l,(l+r)/2);
			add(a,b,x,2*k+2,(l+r)/2,r);
			node[k] = node[2*k+1]+node[2*k+2];
		}
	}
	lli getSum(lli a,lli b,lli k=0,lli l=0,lli r=-1){
		if(r<0)r=n;
		if(b<=l || r<=a)return 0;

		eval(k,l,r);
		if(a<=l && r<=b)return node[k];
		lli vl = getSum(a,b,2*k+1,l,(l+r)/2);
		lli vr = getSum(a,b,2*k+2,(l+r)/2,r);
		return vl+vr;
	}
};

signed main(){

	lli n,q;
	cin>>n>>q;

	vector<lli> v(n,0);
	LazySegmentTree lazyTree(v);

	REP(i,0,q){

		lli k;
		cin>>k;
		if(k==0){
			lli s,t,x;
			cin>>s>>t>>x;
			lazyTree.add(s-1,t,x);
		}
		else{
			lli s,t;
			cin>>s>>t;
			cout<<lazyTree.getSum(s-1,t)<<endl;
		}

	}

	return 0;
}


Measured memory_bytes: 7868
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <cstdio>
#include <string>
#include <cmath>
#include <queue>
#include <tuple>
#include <bitset>
#include <cassert>
#include <chrono>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <random>
#include <set>
#include <stack>
#include <time.h>

//#include <bits/stdc++.h>
#define maxs(x,y) x = max(x,y)
#define mins(x,y) x = min(x,y)
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define repr(i, n) for (int i = (n) - 1; i >= 0; i--)
#define FOR(i,i0,n) for(int (i)=(i0);(i)<(n);(i)++)
#define FORR(i,i0,n) for(int (i)=(n)-1; (i)>=(i0);(i)--)
#define SORT(x) sort(x.begin(),x.end())
#define SORTR(x) sort(x.begin(),x.end(),greater<int>())
#define rn return
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple

using namespace std;
using ll = long long;
typedef std::pair<int,int> pii;
typedef std::vector<int> vi;
typedef std::vector<pii> vii;

#define PI 3.14159265358979323846264338327950L
const int mod = 1000000007;


void solve(){
    int d,l,r;
    cin >> l >> r >> d;
    
    cout << (r/d)-((l-1)/d);
}

int main(){
    int T;
    T = 1;
    //cin >> T;
    while(T--){
        solve();
        cout << endl;
    }
}






Measured memory_bytes: 3592
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<utility>
#include<map>
#include<set>
#include <sstream>
#include<queue>
#include<stack>
#include<functional>
#include<math.h>
#include <iomanip>
using namespace std;


int main(void){
  long N,K;
  cin >> N >> K;
  N = N % K;
  if(N == 0){
    cout << 0 << endl;
  }else if(abs(N-K) > N){
    cout << N << endl;
  }else{
    cout << abs(N-K) << endl;
  }
  return 0;
}

Measured memory_bytes: 3604
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <deque>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
#include <cctype>
#include <cstring>
#include <ctime>
#include <iterator>
#include <bitset>
#include <numeric>
#include <list>
#include <iomanip>
#include <stack>
using namespace std;
#define ll int64_t
const long mod = 1e9 + 7;


const long LINF = 1e13;
const long LLINF = 1e18;
const long ALPHABET = 26;

template <class T>
void Swap(T& r, T& l) {
  T tmp = r;
  r = l;
  l = tmp;
}

template<typename T>
istream& operator >> (istream& is, vector<T>& vec) {
  for (T& x : vec) is >> x; //for(int i=0; i<vec.size(); i++) is >> x[i]; とかでもいい
  return is;
}


int main() {
  long n,m,l;
  char s;
  cin >> n >>m >>l;

  // vector<long> a(n);
  // vector<long> b(n);
  // cin >> b;




  bool an = true;
  // long ans = 0;

  if (n==m && m==l){
    an = true;
  }else{
    an = false;
  }


  // cout << ans <<endl;
  cout << (an?"Yes":"No");






}




















Measured memory_bytes: 256
n = int(input())
b = {}

for i in range(n):
    a = int(input())
    b[i+1] = b.get(i+1, 0) + a

key, t = b.get(1, 0), 1
key_set = {1}
while key != 0:
    if key in key_set:
        print(-1)
        break

    if key == 2:
        print(t)
        break

    key_set.add(key)
    key = b.get(key, 0)
    t += 1

else:
    print(-1)


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

signed main(void)
{
	int a, b, c, sum;
	int ans[3][3];
	bool ok;

	cin >> a >> b >> c;
	ans[0][0] = a;
	ans[0][1] = b;
	ans[1][1] = c;
	ans[2][0] = ans[0][0] + ans[0][1] - ans[1][1];
	ans[1][2] = ans[0][0] + ans[2][0] - ans[1][1];
	ans[0][2] = ans[0][0] + ans[1][1] - ans[1][2];
	ans[1][0] = ans[0][1] + ans[0][2] - ans[2][0];
	ans[2][1] = ans[0][0] + ans[1][1] - ans[2][0];
	ans[2][2] = ans[0][1] + ans[1][1] - ans[2][0];
	rep(i, 3) 
	{
		rep(j, 3)
			cout << ans[i][j] << " ";
		cout << endl;
	}
	return 0;
}


Measured memory_bytes: 256
loop {
    m, f, r, = gets.split(" ").map(&:to_i)
    point = m + f
    if m & f & r == -1
        break
    end

    if m == -1 || f == -1
        puts "F"
    elsif point >= 80
        puts "A"
    elsif point >= 65 && point < 80
        puts "B"
    elsif point >= 50 && point < 65
        puts "C"
    elsif r >= 50 
        puts "C"
    elsif point >= 30 && point < 50
        puts "D"
    elsif point < 30
        puts "F"
    end
}

Measured memory_bytes: 8620
#include <cmath>
#include <iostream>
#include <string>
#include <time.h>
#include <stdio.h>
#include <iomanip>
#include <vector>
#include <map>
#include <algorithm>
using namespace std;

int main()
{
    long long n;
    cin >> n;
    vector<long long> a(n);
    for (int i = 0; i < n; i++)
        cin >> a[i];
    /* code */
    long long max;
    long long min = a[0];
    for (int j = 1; j < n; j++)
    {
        if (j == 1)
            max = a[j] - min;
        if (max < a[j] - min)
            max = a[j] - min;
        if (min > a[j])
            min = a[j];
    }
    cout << max << endl;
    return 0;
}



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

int main() {
  int N,X,T;
  cin >> N >> X >> T;
  if(N % X == 0){
    cout << (N/X)*T << endl;
  }
  else{
    cout << (N/X+1)*T << endl;
  }
}


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

int main() {
  string S;
  cin >> S;
  if (S == "Sunny")
    cout << "Cloudy" << endl;
  if (S == "Cloudy")
    cout << "Rainy" << endl;
  if (S == "Rainy")
    cout << "Sunny" << endl;
}

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

typedef long long ll;

int N;
int A[10010], B[10010];

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

    for(int i = 0; i < N; i++) {
        scanf("%d", &A[i]);
    }
    for(int i = 0; i < N; i++) {
        scanf("%d", &B[i]);
    }
    for(int i = 0; i < N; i++) {
        A[i] -= B[i];
    }

    ll asum = 0;
    ll bsum = 0;
    for(int i = 0; i < N; i++) {
        if(A[i] > 0) asum += A[i];
        if(A[i] < 0) bsum -= A[i];
    }
    ll cnt = bsum - asum;
    if(cnt < 0) {
        printf("No");
        return 0;
    }
    for(int i = 0; i < N; i++) {
        if(A[i] < 0) {
            if(cnt < (-A[i] + 1) / 2) {
                printf("No");
                return 0;
            }
            cnt -= (-A[i] + 1) / 2;
            A[i] += (-A[i] + 1) / 2 * 2;
        }
    }

    printf("Yes");
}


Measured memory_bytes: 384
// Package main provides
//
// File:  a.go
// Author: ymiyamoto
//
// Created on Wed Jan  9 22:39:27 2019
//
package main

import "fmt"

func main() {
	var n, m int
	fmt.Scan(&n, &m)
	fmt.Println((n - 1) * (m - 1))
}


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

bool check(string &s,string obj){
  int length=obj.length();
  if(s.length()<length){
    return false;
  }
  for(int i=0;i<length;i++){
    if(s[s.length()-1-i]!=obj[obj.length()-1-i]){
      return false;
    }
  
  }
  for(int i=0;i<length;i++){
    s.pop_back();
  }
  return true;
}

int main(){
  string s;
  cin>>s;
  while(s.length()){
    int temp=s.length();
    check(s,"erase");
    check(s,"eraser");
    check(s,"dream");
    check(s,"dreamer");
    if(temp==s.length())break;
  }
  if(s.length()==0){
    cout<<"YES";
  }else{
    cout<<"NO";
  }
  return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
const int inf=0x3f3f3f3f;
typedef long long ll;
char s[1000005];
int main()
{
    scanf("%s",s+1);
    if(s[3]==s[4]&&s[5]==s[6]) printf("Yes\n");
    else printf("No\n");
}


Measured memory_bytes: 256
#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 rep2(i,n) for(int i = 1; i <= (n); ++i)
#define rrep2(i,n) for(int i = (n); i > 0; --i)
#define srep(i,s,n) for(int i = s; i < (n); ++i)
#define rsrep(i,s,n) 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)//for array sorting
#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 show_pair(...) cout<<#__VA_ARGS__<<" = "<<endl; for (const auto& x : (__VA_ARGS__)) { cout<<"  "<<x.fi<<" : "<<x.se<<endl; }
#define out_ary(...) { int n = (__VA_ARGS__).size(); rep(i, n) printf("%d%s", (__VA_ARGS__)[i], i != n-1 ? " " : "\n"); }
#define argmax(v) distance((v).begin(), max_element(all(v)))
#define argmin(v) distance((v).begin(), min_element(all(v)))
#define vmax(v) *max_element(all(v))
#define vmin(v) *min_element(all(v))
typedef long long int ll;
typedef pair<int, int> P;
typedef vector<P> vpair;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<double> vdouble;
typedef vector<string> vstr;
typedef vector<bool> vbool;
typedef vector<vint> vvint;
typedef vector<vll> vvll;
typedef vector<vstr> vvstr;
typedef vector<vbool> vvbool;
const ll LINF = 2000000000000000000ll;
const int INF = 1000000100;
const ll MOD = 1e9+7;

int main() {
    int a, v, b, w, t;
    cin >> a >> v >> b >> w >> t;

    int dv = v-w;
    if (dv <= 0) {
        puts("NO");
        return 0;
    }
    int d = abs(a-b);
    if ((d + (dv - 1)) / dv <= t) puts("YES");
    else puts("NO");
    return 0;
}

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

int main(){
    int N;
    std::cin >> N;
    std::vector<int> x(N),y(N),x_rev(N),dis(N),dis_rev(N);
    for (int i=0;i<N;i++){
        std::cin >> x[i] >> y[i];
        x_rev[i] = 1000000000 - x[i];
        dis[i] = x[i] + y[i];
        dis_rev[i] = x_rev[i] + y[i];
    }
    int max,max_rev,ans;
    
    max = *std::max_element(dis.begin(),dis.end()) - *std::min_element(dis.begin(),dis.end());
    max_rev = *std::max_element(dis_rev.begin(),dis_rev.end()) - *std::min_element(dis_rev.begin(),dis_rev.end());
    std::cout << std::max(max,max_rev) << std::endl;
    return 0;

}


Measured memory_bytes: 7216
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include <cmath>
#include <limits>
#include <utility>
#include <map>
#include <iomanip>


#define rep(p,q) for(int i = p;i < q;i++)
#define ll long long

using namespace std;

const ll CONS = 1e9 + 7;
const ll INF = 1e16 + 7;



//65C
int main(void) {
	ll n = 2, m = 2;
	cin >> n >> m;
	ll factN = 1, factM = 1;
	for (int i = n; i > 1; i--) {
		factN = (factN * i) % CONS;
	}

	for (int i = m; i > 1; i--) {
		factM = (factM * i) % CONS;
	}
	if (n == m) cout << (2 * factN * factN) % CONS << endl;
	else if (abs(n - m) == 1)cout << (factN * factM) % CONS << endl;
	else cout << 0 << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <cstdlib>
#include <list>
#include <numeric>
#include <map>
#define rep(i,n) for(int i=0;i<n;i++)
#define all(x) (x).begin(),(x).end()
using namespace std;
//================================================

int a = 0, b = 0, c, d, n, k=0;
string s, t;


int main()
{
	string s, t;
	cin >> s >> t;
	t += t;
	
	rep(i, s.size())
	{
		a = 0;
		rep(j, s.size())
		{
			if (s[j] == t[i + j])
				a++;
		}
		if (a == s.size())
		{
			cout << "Yes" << endl; return 0;
		}

	}
	cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fast ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
void input()
{
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
#endif
}
using namespace std;
typedef long long ll ;
const long long N = 1e5,OO=0x3f3f3f3f;
ll n,weight,w[105],v[105];
ll dp[105][N+5];

int main()
{
    cin>>n>>weight;
    for(int i=0; i<n; i++)
        cin>>w[i]>>v[i];

    for(int i=0; i<105; i++)
        for(int j=0; j<=N; j++)
            dp[i][j]=1e18;

    dp[0][v[0]]=w[0];
    for(int i=0;i<=100;i++)dp[i][0]=0;
    for(int i=1; i<n; i++)
    {

        for(int j=0; j<=N; j++)
        {
            ll &ret=dp[i][j];
            ret=min(ret,dp[i-1][j]);
            if(v[i]<=j)
                ret=min(ret,w[i]+dp[i-1][j-v[i]]);
            }
    }
    for(int i=N; i>=0; i--)
        if(dp[n-1][i]<=weight)
        {
            cout<<i<<endl;
            break;
        }
}


Measured memory_bytes: 85652
/**
 *    author:  tourist
 *    created: 16.12.2019 13:30:15       
**/
#include <bits/stdc++.h>

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<vector<int>> g(n);
  for (int i = 0; i < n - 1; i++) {
    int x, y;
    cin >> x >> y;
    --x; --y;
    g[x].push_back(y);
    g[y].push_back(x);
  }
  int ans = 0;
  vector<pair<int, int>> down(n);
  function<pair<int, int>(int, int)> Dfs = [&](int v, int pr) {
    int one = 1;
    int two = 0;
    int profit = 0;
    for (int u : g[v]) {
      if (u == pr) {
        continue;
      }
      auto res = Dfs(u, v);
      one = max(one, 1 + res.first);
      two += res.second;
      profit = max(profit, res.first - res.second);
    }
    one = max(one, two + profit);
    two = max(two, 1);
    ans = max(ans, one);
    return down[v] = make_pair(one, two);
  };
  Dfs(0, -1);
  function<void(int, int, pair<int, int>)> Solve = [&](int v, int pr, pair<int, int> up) {
    vector<pair<int, int>> children;
    for (int u : g[v]) {
      if (u == pr) {
        continue;
      }
      children.push_back(down[u]);
    }
    int sz = (int) children.size();
    vector<int> pref_one(sz + 1);
    vector<int> pref_two(sz + 1);
    vector<int> pref_profit(sz + 1);
    vector<int> suf_one(sz + 1);
    vector<int> suf_two(sz + 1);
    vector<int> suf_profit(sz + 1);
    pref_one[0] = 1;
    for (int i = 0; i < sz; i++) {
      pref_one[i + 1] = max(pref_one[i], 1 + children[i].first);
      pref_two[i + 1] = pref_two[i] + children[i].second;
      pref_profit[i + 1] = max(pref_profit[i], children[i].first - children[i].second);
    }
    suf_one[sz] = 1;
    for (int i = sz - 1; i >= 0; i--) {
      suf_one[i] = max(suf_one[i + 1], 1 + children[i].first);
      suf_two[i] = suf_two[i + 1] + children[i].second;
      suf_profit[i] = max(suf_profit[i + 1], children[i].first - children[i].second);
    }
    ans = max(ans, max(max(pref_one.back(), 1 + up.first), pref_two.back() + up.second + max(pref_profit.back(), up.first - up.second)));
    int ptr = 0;
    for (int u : g[v]) {
      if (u == pr) {
        continue;
      }
      int one = 1 + up.first;
      int two = up.second;
      int profit = up.first - up.second;
      one = max(one, max(pref_one[ptr], suf_one[ptr + 1]));
      two += pref_two[ptr] + suf_two[ptr + 1];
      profit = max(profit, max(pref_profit[ptr], suf_profit[ptr + 1]));
      one = max(one, two + profit);
      two = max(two, 1);
      Solve(u, v, make_pair(one, two));
      ptr += 1;
    }
  };
  Solve(0, -1, make_pair(0, 0));
  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 6784
#include<iostream>
#include<vector>
#include<queue>
#include<algorithm>
#include<string>
#include<cmath>

using namespace std;
using ll  = long long;
template <typename T> T In() {
    T t;
    cin >> t;
    return t;
}
template <typename T> vector<vector<T>> Vec2(int i, int j, T ini = 0) {
    vector<vector<T>> vec(i, vector<T>(i, ini));
    return move(vec);
}
template <typename T> vector<vector<vector<T>>> Vec3(int i, int j, int k, T ini = 0) {
    vector<vector<vector<T>>> vec(i, vector<vector<T>>(j, vector<T>(k, ini)));
    return move(vec);
}

int getKeta(int n){
    int ans = 1;
    while(n >= 10) {
        n /= 10;
        ans++;
    }
    return ans;
}
int main() { 
    int N = In<int>();
    int now = In<int>() - 1;
    for(int n = 1; n < N; n++) {
        int h = In<int>();
        if(now < h )
            now = h - 1;
        else if( now==h)
            now = h;
        else{
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<algorithm>
#define ll long long
using namespace std;
const int N=200100,P=1e9+7;
inline int read(){
	int x=0,f=0,c=getchar();
	for(;c>'9'||c<'0';f=c=='-',c=getchar());
	for(;c>='0'&&c<='9';c=getchar())
	x=(x<<1)+(x<<3)+c-'0';return f?-x:x;
}
inline void write(ll x){
	if(x<0)putchar('-'),x=-x;
	if(x>9)write(x/10);putchar(x%10+'0');
}
int n,h[N],L,X[N],Y[N],ne[N],to[N],ans;ll res;
void addl(int x,int y){
	ne[++L]=h[x];h[x]=L;to[L]=y;
	ne[++L]=h[y];h[y]=L;to[L]=x;
}
int lv,sm[N];
void dfs(int x,int fa,int c){
	int d=0,k;if(c>lv)lv=c;
	for(k=h[x];k;k=ne[k])if(to[k]!=fa)
	d++,dfs(to[k],x,c+1);sm[c]=max(sm[c],d);
}
void solve(int x,int y){
	dfs(x,y,1);dfs(y,x,1);
	int i;ll s=x==y?1:2;
	for(i=1;i<lv;i++)s=s*sm[i],sm[i]=0;
	if(lv<ans||(lv==ans&&s<res))
		ans=lv,res=s;lv=0;
}
int main(){
	n=read();int i;
	for(i=1;i<n;i++){
		X[i]=read();Y[i]=read();
		addl(X[i],Y[i]);
	}ans=n;
	for(i=1;i<n;i++)solve(X[i],Y[i]);
	for(i=1;i<=n;i++)solve(i,i);
	printf("%d %lld\n",ans,res);
	return 0;
}

Measured memory_bytes: 2176
n,m = map(int,input().split())
x = sorted(map(int,input().split()))
diff = sorted([x[i+1] - x[i] for i in range(m-1)], reverse=True)

sm = x[-1] - x[0]
acc = 0
if n >= m:
    print(0)
    exit()
print(sm - sum(diff[:n-1]))


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

typedef long long ll;
const int INF = 1e9;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	
	// int t;
	// cin>>t;
	// while(t--){
		int n;
		cin>>n;
		n %= 1000;
		if (n == 0){
			cout<<0<<'\n';
		}else{
			cout<<1000-n<<'\n';
		}
	// }
	return 0;
}

Measured memory_bytes: 3636
//ABC104A
#include <bits/stdc++.h>
#include <iostream>
#include <iomanip>
#include <numeric>
#include <math.h>
#include <stdio.h>
#include <climits>
#include <cfloat>
#include <string>
using namespace std;

int main(){
	int r;
	cin >> r;
	if(r<1200){
		cout << "ABC" << endl;
	}else if(r<2800){
		cout << "ARC" << endl;
	}else{
		cout << "AGC" << endl;
	}
	return 0;
}

Measured memory_bytes: 256