akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main() {
    int n,m,s[10],c[10],keta= 1,ans=0,piyo;
    bool ok = true;
    map<int,int> mp;
    cin >> n >> m;
    for(int i=0;i<m;i++) cin >> s[i] >> c[i];
    for(int i=0;i<m;i++){
        if(s[i] == 1 && c[i] == 0 && n != 1){
            ok = false;
            break;
        }
        if(mp.find(s[i]) == mp.end()){
            mp[s[i]] = c[i];
        }else{
            if(mp[s[i]] != c[i]){
                ok = false;
                break;
            }
        }
    }
    for(int i=0;i<n;i++){
        keta*= 10;
    }
    keta /=10;
    piyo = keta;
    if(ok){
        for(int i=1;i<=n;i++){
            if(mp.find(i) != mp.end()){
                ans += mp[i] * keta;
            }
            keta /= 10;
        }
        if(ans >= piyo)cout << ans << endl;
        else if(n == 1)cout << ans << endl;
        else{
            if(ans == 0)cout << piyo << endl;
            else{
                ans += piyo*1;
                cout << ans << endl;
            }
        }
    }else{
        cout <<"-1" << endl;
    }

}

Measured memory_bytes: 256
import itertools
import copy
N = int(input())
p = list(map(int,input().split()))
p_new = copy.copy(p)
t = 0
arg_combination = list(itertools.combinations(range(N),2))

for k in range(N-1):
	if p[k] > p[k+1]:
		t = 1
if t == 0:
	print("YES")
	exit()

for a in arg_combination:
	p_new = copy.copy(p)
	p_new[a[0]] = p[a[1]]
	p_new[a[1]] = p[a[0]]
	t = 0
	for k in range(N-1):
		if p_new[k] > p_new[k+1]:
			t = 1
	if t == 0:
		print("YES")
		exit()
print("NO")


Measured memory_bytes: 3572
#include<bits/stdc++.h>
using namespace std;
#define V vector
#define L long
#define W V<L>
L E=70,M=2e17,i,a,b;W S(V<W>p){if(!E)return{1,0};V<V<W>>T(2);for(W x:p){T[x[1]&1].push_back({x[0]/2,x[1]/2});if(x[0]&1)T[x[1]&1].push_back({x[0]/2,++x[1]/2});}for(L i;i<2;i++){L c=0;for(W x:T[!i])c^=(2*x[0]+x[1])%3+1;if(!c){E--;W A=S(T[i]);A[0]*=2;A[1]*=2;A[1]+=i;return A;}}for(W&v:p)v[0]++;W A=S(p);A[0]--;return A;}int main(){cin>>i;V<W>p(i);while(i--,cin>>a>>b)p[i]={a+M,b+M};W x=S(p);cout<<x[0]-M<<" "<<x[1]-M;}

Measured memory_bytes: 62908
#include <iostream>
#include <iomanip>
#include <vector>
#include <cmath>
#include <algorithm>
#include <climits>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <string>
#include <list>
#include <ctime>
#include <complex>
#include <bitset>
#include <tuple>

#define IOS ios::sync_with_stdio(false);cin.tie(0)
#define all(x) x.begin(), x.end()
#define ff first
#define ss second
#define MOD 1000000007LL
#define rep(i,a,n) for (int i=a ; i<n ; i++)
#define per(i,a,n) for (int i=n-1 ; i>=a ; i--)
#define LLINF (llong)1e18+5
#define INF 1e9+5

using namespace std;
using llong = long long;
using VI = vector<int>;
using VLL = vector<long long>;
using PII = pair<int, int>;

int main()
{
	IOS;
	int r, c;
	cin >> r >> c;
	vector<vector<bool>> grid(r, vector<bool>(c));
	vector<vector<llong>> ans(r, vector<llong>(c));

	rep(i, 0, r)
	{
		rep(j, 0, c)
		{
			char c;
			cin >> c;
			if (c == '.') grid[i][j] = false;
			else grid[i][j] = true;
		}
	}
	rep(i, 0, c)
	{
		if (grid[0][i] == true) break;
		ans[0][i] = 1;
	}
	rep(i, 0, r)
	{
		if (grid[i][0] == true) break;
		ans[i][0] = 1;
	}
	rep(i, 1, r)
	{
		rep(j, 1, c)
		{
			if (grid[i][j] == true) ans[i][j] = 0;
			else ans[i][j] = (ans[i - 1][j] + ans[i][j - 1]) % MOD;
		}
	}
	cout << ans[r - 1][c - 1];
	return 0;
}


Measured memory_bytes: 11308
#include<iostream>
#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#include<algorithm>
#define ll long long
#define rep(i, a, b) for(int i = a; i <= b; i++)
void read(int &x) {
    x = 0; int flag = 1; char ch = ' ';
    while(ch < '0' || ch > '9') { if(ch == '-') flag = -1; ch = getchar(); }
    while(ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar();
    x *= flag;
}
void read(ll &x) {
    x = 0; int flag = 1; char ch = ' ';
    while(ch < '0' || ch > '9') { if(ch == '-') flag = -1; ch = getchar(); }
    while(ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar();
    x *= flag;
}
using namespace std;
char s[5];
int main()
{
    bool flag = 1;
    scanf("%s", s + 1);
    rep(i, 1, 3)
        if(s[i] == s[i + 1]) flag = 0;
    if(flag) puts("Good"); else puts("Bad");
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		String str = sc.nextLine();
		sc.close();
		String[] array = str.split(" ");
		int x=0,y=0;

		if(array[0].equals("A")) {
			x = 10;
		}
		if(array[0].equals("B")) {
			x = 11;
		}
		if(array[0].equals("C")) {
			x = 12;
		}
		if(array[0].equals("D")) {
			x = 13;
		}
		if(array[0].equals("E")) {
			x = 14;
		}
		if(array[0].equals("F")) {
			x = 15;
		}


		if(array[1].equals("A")) {
			y = 10;
		}
		if(array[1].equals("B")) {
			 y = 11;
		}
		if(array[1].equals("C")) {
			y = 12;
		}
		if(array[1].equals("D")) {
			 y = 13;
		}
		if(array[1].equals("E")) {
			 y = 14;
		}
		if(array[1].equals("F")) {
			 y = 15;
		}

		if(x<y) {
			System.out.print("<");
		}
		if(x>y) {
			System.out.print(">");
		}
		if(x==y) {
			System.out.print("=");
		}


	}
}


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

using ll = long long;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  int n;
  cin >> n;
  
  ll ans = 0;
  for (ll i = 1; i <= n; i++) {
    if (i % 3 != 0 && i % 5 != 0) ans += i;
  }
  
  cout << ans << '\n';
}

Measured memory_bytes: 3612
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> l_l;
typedef pair<int , int> i_i;
typedef vector<ll> vl;
typedef vector<int> vi;
typedef vector<char> vec;
typedef vector<bool> veb;
typedef vector<string> ves;
typedef vector<vector<ll>> vvl;
typedef vector<vector<int>> vvi;
typedef vector<vector<char>> vvec;
typedef vector<vector<bool>> vveb;
typedef vector<vector<string>> vves;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<(int)(n);i++)
#define rep2(i,n) for(int i=2;i<(int)(n);i++)
#define repk(i,k,n) for(int i=k;i<(int)(n);i++)
#define fs first
#define sc second
#define pb push_back
#define pp pop_back
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define maxel(a) *max_element(all(a))
#define minel(a) *min_element(all(a))
#define acc accumulate
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define mod (1000000007)
typedef long long int64;
//const int64 INF = 1LL << 58;
#define dame { puts("-1"); return 0;}
#define YES { cout << "YES" << endl; return 0; }
#define NO { cout << "NO" << endl; return 0; }
#define Yes { cout << "Yes" << endl; return 0; }
#define No { cout << "No" << endl; return 0; }
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
int dx[] = {0, 0, -1, 1};
int dy[] = {1, -1, 0, 0};


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

    int n,t;
    cin >> n >> t;
    vi c;
    rep(i,n){
        int a,b;
        cin >> a >> b;
        if(b<=t){c.pb(a);}
    }
    if(c.empty()) cout << "TLE" << endl;
    else cout << minel(c) <<endl;
    
    return 0;
}
    

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdbool.h>
#include <math.h>

int main(void){

    char N[3];

    scanf("%s", N);

    if(N[0] == '9' || N[1] == '9'){
        printf("Yes\n");
    }else{
        printf("No\n");
    }

    return 0;
}

Measured memory_bytes: 1624
import java.util.*;

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

        double a = sc.nextDouble();
        double b = sc.nextDouble();
        double c = sc.nextDouble();

        double side = Math.sqrt(((a * a) + (b * b)) - (2 * a * b * Math.cos(Math.toRadians(c))));
        double area = a * b * Math.sin(Math.toRadians(c)) / (double)2;

        System.out.printf("%.8f\n",area);
        System.out.printf("%.8f\n",a + b + side);
        System.out.printf("%.8f\n",area * 2 / a);

    }
}


Measured memory_bytes: 28200
#include<bits/stdc++.h>
using namespace std;
int main()
{
 long long int n;
 scanf("%lld",&n);
 long long int x1,y1,x2,y2;
 bool p=1 ;
 long long int j=0;
 long long int i =sqrt(n); 
  x1 = sqrt(n)+0.9;
  y1=1;
  y2=sqrt(n)+0.9;
  x2=x1*y2-n;
  printf("0 0 %lld %lld %lld %lld",x1,y1,x2,y2);
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (n); ++i)
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;
}
using namespace std;
using ll = long long;
using P = pair<int, int>;
using Pl = pair<long long, long long>;
using veci = vector<int>;
using vecl = vector<long>;
using vecveci = vector<vector<int>>;
using vecvecl = vector<vector<long long>>;
#define INF 1e+9

vecveci dp(30,veci(500010,0));

int main() {
    int N,M; cin >> N >> M;
    veci C(M);
    REP(i,M) cin >> C[i];
    for(int i = 1; i < 500010; i++) dp[0][i] = INF;
    REP(i,M) for(int j = 0; j <= N; j++) {
        if(j < C[i]) dp[i+1][j] = dp[i][j];
        else dp[i+1][j] = min(dp[i][j],dp[i+1][j-C[i]]+1);
    }
    cout << dp[M][N] << endl;
}



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

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            //[summary]
            var line = ReadLine();
            int n = line[0];
            int m = line[1];

            //その市が誕生した年,属する県のIDを取得
            var cityInfos = GetCityInfos(m);

            var query = cityInfos.OrderBy(x => x.Key).GroupBy(x => x.Value).ToList();

            //誕生した順番を記憶するためのオブジェクト
            var birthOrder = new Dictionary<long, int>();

            foreach (var group in query)
            {
                int i = 1;

                foreach(var g in group)
                {
                    birthOrder.Add(g.Key, i);
                    i++;
                }
            }

            ////その市の番号(出てきた順)を記憶するためのオブジェクト
            //var appearOrder = new Dictionary<long, int>();
            //int count = 0;

            //foreach(var year in cityInfos.Keys)
            //{
            //    appearOrder.Add(year, count);
            //    count++;
            //}

            ////市が誕生した年の昇順にソート
            //var query = cityInfos.OrderBy(x => x.Key);

            ////誕生した順番を記憶するためのオブジェクト
            //var birthOrder = new Dictionary<long, int>();
            //count = 0;

            //foreach(var q in query)
            //{
            //    birthOrder.Add(q.Key, count);
            //    count++;
            //}

            //var prefectures = new Dictionary<int, int>();

            //foreach (var id in cityInfos.Values)
            //{
            //    if (!dic.ContainsKey(id))
            //    {
            //        dic.Add(id, 0);
            //    }
            //}

            foreach (var city in cityInfos)
            {
                long year = city.Key;
                int id = city.Value;
                
                string left = id.ToString().PadLeft(6, '0');
                string right = birthOrder[year].ToString().PadLeft(6, '0');

                Console.WriteLine(left + right);
            }
        }

        static Dictionary<long, int> GetCityInfos(int m)
        {
            var dic = new Dictionary<long, int>();

            for (int i = 0; i < m; i++)
            {
                var line = ReadLine();
                int prefectureId = line[0];
                long year = line[1];

                dic.Add(year, prefectureId);
            }

            return dic;
        }

        static List<int> ReadLine()
        {
            var line = Console.ReadLine().TrimEnd();
            var array = line.Split(' ');
            var numbers = new List<int>();

            foreach (var s in array)
            {
                int num = int.Parse(s);
                numbers.Add(num);
            }

            return numbers;
        }
    }
}

Measured memory_bytes: 45512
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
//INSERT ABOVE HERE
signed main(){
  Int n;
  cin>>n;
  Int ans=0;
  for(Int i=1;i<=n;i+=2){
    Int c=0;
    for(Int j=1;j<=i;j++) if(i%j==0) c++;
    if(c==8) ans++;
  }
  cout<<ans<<endl;
  return 0;
}


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

using namespace std;

#define EPS 1e-8

struct Point{
  double x,y;
  Point(double x = 0.0, double y = 0.0) : x(x),y(y) {}
  Point operator + (Point p){ return Point(x+p.x,y+p.y); }
  Point operator - (Point p){ return Point(x-p.x,y-p.y); }
  Point operator * (double a){ return Point(x*a,y*a); }
  Point operator / (double a){ return Point(x/a,y/a); }
  double abs(){ return sqrt(norm()); }
  double norm(){ return x*x + y*y; }
};

typedef Point Vector;
double dot(Vector a,Vector b){ return a.x*b.x+a.y*b.y; }
double cross(Vector a,Vector b){ return a.x*b.y-a.y*b.x; }

int ccw(Point p0,Point p1,Point p2){
  Vector a = p1-p0;
  Vector b = p2-p0;
  if(cross(a,b) > EPS) return 1;
  if(cross(a,b) < -EPS) return -1;
  if(dot(a,b) < -EPS) return 2;
  if(a.norm() < b.norm()) return -2;
  return 0;
}

struct Segment{
  Vector p1,p2;
  Segment(){}
  Segment(Vector p1,Vector p2) : p1(p1),p2(p2) {}
};

bool intersectSS(const Segment &s,const Segment &t){
  return (ccw(s.p1,s.p2,t.p1)*ccw(s.p1,s.p2,t.p2) <= 0) && 
         (ccw(t.p1,t.p2,s.p1)*ccw(t.p1,t.p2,s.p2) <= 0);
}

Point getCrossPoint(Segment s,Segment t){
  Vector b = t.p2 - t.p1;
  double d1 = abs(cross(b,s.p1-t.p1));
  double d2 = abs(cross(b,s.p2-t.p1));
  double d = d1 / (d1 + d2);
  return s.p1+(s.p2-s.p1)*d;
}

double getArea(Point a,Point b,Point c){
  return fabs(a.x*(b.y-c.y)+b.x*(c.y-a.y)+c.x*(a.y-b.y))/2;
}

Segment s[3];
void solve(){
  Point p1 = getCrossPoint(s[0],s[1]);
  Point p2 = getCrossPoint(s[1],s[2]);
  Point p3 = getCrossPoint(s[2],s[0]);
  double S = getArea(p1,p2,p3);
  if(S >= 1900000){
    cout << "dai-kichi" << endl;
  }else if(S >= 1000000){
    cout << "chu-kichi" << endl;
  }else if(S >= 100000){
    cout << "kichi" << endl;
  }else if(S > 0){
    cout << "syo-kichi" << endl;
  }else{
    cout << "kyo" << endl;
  }
}

int main(){
  while(true){
    cin >> s[0].p1.x >> s[0].p1.y >> s[0].p2.x >> s[0].p2.y;
    if(!s[0].p1.x && !s[0].p1.y && !s[0].p2.x && !s[0].p2.y) break;

    for(int i = 0 ; i < 2 ; i++){
      cin >> s[i+1].p1.x >> s[i+1].p1.y >> s[i+1].p2.x >> s[i+1].p2.y;
    }
    if(intersectSS(s[0],s[1]) && intersectSS(s[1],s[2]) && intersectSS(s[2],s[0])){
      solve();
    }else{
      cout << "kyo" << endl;
    }
  }

  return 0;
}

Measured memory_bytes: 1216
n = int(input())
a = [list(map(int, input().split())) for i in range(n)]

dp = [[0]*3 for i in range(n+1)]

for i in range(n):
  for j in range(3):
    for k in range(3):
      if j==k:
        continue
      dp[i+1][k] = max(dp[i+1][k], dp[i][j]+a[i][k])
print(max(dp[-1]))

Measured memory_bytes: 50216
#include <stdio.h>
int main(void)
{
    unsigned int n,i;
    long long int temp=1;
    long long int pp=1;
    long long int kk=1;
    long long int jj;
    scanf("%d",&n);
    for(i=n;i>0;i--){
        temp=temp*10;
        if (temp>1000000007)
            temp=(temp%1000000007);
    }
    for(i=n;i>0;i--){
        pp=pp*9;
        if (pp>1000000007)
            pp=pp%1000000007;
    }
    for(i=n;i>0;i--){
        kk=kk*8;
        if (kk>1000000007)
            kk=kk%1000000007;
    }
    jj=temp-pp-pp+kk;
    if (jj<0)
        jj=jj+1000000007;
    if (jj<0)
        jj=jj+1000000007;
    printf("%11d",jj);
    return 0;
}

Measured memory_bytes: 1732
#include <iostream>
#include <cmath>
using namespace std;
typedef long long ll;

int main()
{
    ll n;
    cin >> n;

    // n=m*q+q (m>q)
    ll ans = 0;
    ll lim = floor(sqrt(n));
    for (ll q = 1; q <= lim; q++)
    {
        if (n % q == 0)
        {
            ll m = n / q - 1;
            if (m > q)
            {
                ans += m;
            }
            else
            {
                break;
            }
        }
    }

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


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <vector>

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, int> pdi;

ll l[100005];
void solve() {
  int n;
  cin >> n;
  for(int i = 0; i < n; i++) cin >> l[i];
  ll ret = l[0] - 1;
  l[0] = 1;
  for(int i = 1; i < n; i++) {
    if(l[i] == l[i-1]) continue;
    if(l[i] == l[i-1] + 1) continue;
    ret += (l[i] - 1) / (l[i-1] + 1);
    l[i] = l[i-1];
  }
  cout << ret << "\n";
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL); cout.tie(NULL);
  solve();
  /*
  int t;
  cin >> t;
  for(int i = 1; i <= t; i++) {
    cout << "Case #" << i << ": ";
    solve();
  }
  */
}


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

void updateTree(ll *arr, ll *tree, int start, int end, int treeNode,
                int idx, ll value){
    if(start == end){
        arr[idx] = value;
        tree[treeNode] = value;
        return;
    }
    int mid = (start + end)/2;
    if(idx > mid) // Move to right
        updateTree(arr, tree, mid+1, end, 2*treeNode+1, idx, value);
    else    // Move to left
        updateTree(arr, tree, start, mid, 2*treeNode, idx, value);

    tree[treeNode] = max(tree[2*treeNode], tree[2*treeNode+1]);
}

ll query(ll *tree, int start, int end, int treeNode, int left, int right){

    if(start>right or end<left)
        return 0;
    if(start>=left and end<=right)
        return tree[treeNode];
    int mid = (start + end)/2;
    ll leftAns = query(tree, start, mid, 2*treeNode, left, right),
       rightAns = query(tree, mid+1, end, 2*treeNode+1, left, right);
    ll ans = max(leftAns, rightAns);
    return ans;
}

ll flowers(int beauty[], int height[], int n){

    // Notice the heights are less than or equal to 2*10^5

    ll *dp = new ll[MAX]();

    // dp[i] stores the maximum sum of beauty when
    // the last height in that subsequence is 'i'

    // Suppose input is
    // n = 9
    // height[] = 4 2 5 8 3 6 1 7 9
    // beauty[] = 6 8 8 4 6 3 5 7 5

    // dp[4] = 6
    // dp[2] = 8
    // Now the next height value is '5'
    // this flower can be appended to any of the smaller heights (either 2 or 4)
    // We append it to that subsequence of flowers which gives maximum sum of beauties
    // So we append it to the subsequence of flower having last height as '2'
    // dp[5] = 16
    // Similarly we proceed for all the flowers

    // So here when we are at a flower having height[i]
    // we need to pick that height among 1, 2, .... , height[i]-1
    // which has maximum sum of beauties
    // like in the above example, if we are at height[i] = 5
    // we want to pick that height among 1, 2, ... , 4
    // which has maximum sum of beauties
    // To quickly find maximum from a range, we can use Segment Tree

    ll maxBeauty = 0;

    ll *tree = new ll[4*MAX]();

    for(int i=0; i<n; i++){
        int h = height[i];
        // Find the maximum from 1, 2, 3, ..., h-1
        ll maximum = query(tree, 0, MAX-1, 1, 1, h-1);

        // We have 2 options for this height:
        // 1) Append it to one of the smaller height subsequence
        // 2) Ignore the current height,
        //    i.e. take the previous value which was present at this height
        ll newBeauty = maximum + beauty[i];
        if(newBeauty > dp[h]){
            updateTree(dp, tree, 0, MAX-1, 1, h, newBeauty);
            if(newBeauty > maxBeauty)
                maxBeauty = newBeauty;
        }
    }

    delete[] dp;
    delete[] tree;

    return maxBeauty;
}

int main()
{
 int n;
 cin>>n;
 int h[n];
 for(int i=0; i<n; i++)
    cin>>h[i];
 int a[n];
 for(int i=0; i<n; i++)
    cin>>a[i];
 ll ans = flowers(a, h, n);
 cout<<ans;
 return 0;
}



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

using ll = long long;
using P = pair<int, int>;

class union_find {
public:
    union_find(int n)
        : par_(n, -1)
    {}
    void init(int n) {
        par_.assign(n, -1);
    }

    int root(int x) {
        return par_[x] < 0 ? x : par_[x] = root(par_[x]);
    }

    bool unite(int x, int y) {
        x = root(x); y = root(y);
        if(x == y) {
            return false;
        } else {
            if(par_[x] < par_[y]) {
                par_[x] += par_[y];
                par_[y] = x;
            } else {
                par_[y] += par_[x];
                par_[x] = y;
            }
            return true;
        }
    }

    bool same(int x, int y) {
        return root(x) == root(y);
    }

    int size(int x) {
        return -par_[root(x)];
    }

private:
    std::vector<int> par_;
};

int main() {
    int N;
    cin >> N;
    vector<int> c(N);
    for(int i=0; i<N; ++i) {
        cin >> c[i];
    }
    int M;
    cin >> M;
    union_find uf(N);
    vector<vector<int>> g(N);
    vector<vector<P>> neib(N);
    for(int i=0; i<M; ++i) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        if(c[a] > c[b]) {
            g[b].push_back(a);
        } else if(c[a] < c[b]) {
            g[a].push_back(b);
        } else {
            uf.unite(a, b);
        }
        neib[a].push_back(make_pair(c[b], b));
        neib[b].push_back(make_pair(c[a], a));
    }

    for(int i=0; i<N; ++i) {
        if(neib[i].size() == 0) {
            continue;
        }
        sort(neib[i].begin(), neib[i].end());
        for(int j=0; j<neib[i].size()-1; ++j) {
            P u = neib[i][j], v = neib[i][j+1];
            if(u.first == v.first) {
                uf.unite(u.second, v.second);
            } else {
                g[u.second].push_back(v.second);
            }
        }
    }

    vector<int> order;
    vector<ll> dp(N);
    for(int i=0; i<N; ++i) {
        if(uf.root(i) == i) {
            order.push_back(i);
            dp[i] = 1;
        } else {
            for(auto& v : g[i]) {
                g[uf.root(i)].push_back(v);
                g[i].clear();
            }
        }
    }
    sort(order.begin(), order.end(), [&](int const v1, int const v2) {
        return c[v1] < c[v2];
    });

    ll res = 0;
    for(auto i : order) {
        for(auto to : g[i]) {
            dp[uf.root(to)] = max(dp[uf.root(to)], dp[i]+1);
        }
        res += dp[i] * uf.size(i);
    }
    cout << res << endl;
}

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

#define REP(i,init, n) for(lli i=init;i<n;i++)
#define REPE(i,init, n) for(lli i=init;i<=n;i++)
#define REPIT(it,container) for(auto it = container.begin(); it != container.end(); it++)
#define REPIT_R(it,container) for(auto it = container.rbegin(); it != container.rend(); it++)

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

typedef long long int lli;
typedef pair<lli, lli> P;


int main() {
    lli n;
    cin >> n;
    lli a[n], b[n];
    priority_queue<lli> que;
    REP(i, 1, n) {
        cin >> a[i] >> b[i];
    }
    REP(i, 0, n) {
        lli c;
        cin >> c;
        que.push(c);
    }
    lli points[n+1] = {0};
    points[a[1]] = que.top();
    que.pop();
    points[b[1]] = que.top();
    que.pop();
    REP(i, 2, n) {
        REP(j, 2, n) {
            if (points[a[j]] == 0 && points[b[j]] != 0) {
                points[a[j]] = que.top();
                que.pop();
            }
            else if (points[a[j]] != 0 && points[b[j]] == 0) {
                points[b[j]] = que.top();
                que.pop();
            }
        }
    }
    lli ans = 0;
    REP(i, 1, n) {
        ans += min(points[a[i]], points[b[i]]);
    }
    cout << ans << endl;
    REPE(i, 1, n) {
        cout << points[i] << " ";
    }
    cout << endl;

    //map<lli, lli> m;
    //REP(i, 1, n) {
    //    auto it = m.find(a[i]);
    //    if (it != m.end()) {
    //        it->second += 1;
    //    }
    //    else {
    //        m.insert(make_pair(a[i], 1));
    //    }
    //    it = m.find(b[i]);
    //    if (it != m.end()) {
    //        it->second += 1;
    //    }
    //    else {
    //        m.insert(make_pair(b[i], 1));
    //    }
    //}
    //vector<P> v;
    //REPIT(it, m) {
    //    //printf("key: %d, value: %d\n", it->first, it->second);
    //    v.push_back(make_pair(it->second, it->first));
    //}
    //sort(v.begin(), v.end());
    ////REP(i, 0, v.size()) {
    ////    cout << v[i].first << ", " << v[i].second << endl;
    ////}

    //lli points[n+1];
    //REP(i, 0, v.size()) {
    //    // v[i].first は小さい順になっている。
    //    // v[i].second の位置に、小さい順に値を入れていく
    //    if (v[i].first == 0)
    //        continue;
    //    points[v[i].second] = que.top();
    //    que.pop();
    //}
    //// つながりをもたないところにはでかいものをいれたいので
    //REP(i, 0, v.size()) {
    //    if (v[i].first != 0)
    //        continue;
    //    points[v[i].second] = que.top();
    //    que.pop();
    //}
    //lli ans = 0;
    //REP(i, 1, n) {
    //    ans += min(points[a[i]], points[b[i]]);
    //}
    //cout << ans << endl;
    //REPE(i, 1, n) {
    //    cout << points[i] << endl;
    //}

}


Measured memory_bytes: 768
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<cmath>
#include<vector>
#include<string>
#include<bitset>
#include<queue>
using namespace std;

#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define ROF(i,b,a) for (int i=(b);i>(a);--i)
#define REP(i,n) FOR(i,0,n)
#define PER(i,n) ROF(i,n-1,-1)

typedef int i32;
typedef long long int i64;
typedef unsigned long long int ui64;
typedef float f32;
typedef double f64;
typedef long double f128;
typedef pair<int,int> P;

constexpr int INF = 1e9 + 7;


int main(){
    i64 n,m,d;cin>>n>>m>>d;
    double ans;
    ans = (n-d)*(m-1)*pow(n,-2);
    if(d!=0) ans *= 2;
    cout << fixed << setprecision(20) << ans;
}

Measured memory_bytes: 384
#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 power(ll x){
  ll ans=1;
  rep(i,0,5){
    ans*=x;
  }
  return ans;
}

int main(){
  ll x;
  cin>>x;
  bool p=false;
  rep(i,-1000,1000){
    rep(j,i+1,1000){
      if(power(j)-power(i)==x){
        cout<<j<<' '<<i<<endl;
        p=true;
        break;
      }
    }
    if(p) break;
  }
}

Measured memory_bytes: 3552
isPrime :: Int -> Bool
isPrime num = null(filter (\x -> num `mod` x == 0) [2..floor(sqrt(fromIntegral num))])
 
main = do
    [x] <- map read . words <$> getLine
    let allList = [2..2*x]
    let primeList = [a | a <- allList, isPrime a ]
    let ans = head [a | a <- primeList, a >= x]
    putStrLn $ show ans

Measured memory_bytes: 1020
#include<stdio.h>
int main(){
  int ans=0,n,d[110],i,a;
  scanf("%d\n",&n);
  for(i=0;i<=100;i++){
    d[i]=0;
  }
  for(i=0;i<n;i++){
    scanf("%d\n",&a);
    if(d[a]==0){
      d[a]=1;
      ans++;
    }
  }
  printf("%d\n",ans);
  return 0;
}

Measured memory_bytes: 128
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.*;
 
public class Main {
 
    void solve() throws IOException {
        int N = ni();
        int K = ni();
        ArrayList<Integer> p = new ArrayList<>();
        for (int i = 0; i < N; i++) {
            p.add(ni());
        }
        Collections.sort(p);

        int ans = 0;
        for (int i = 0; i < K; i++) {
            ans += p.get(i);
            
        }
        out.println(ans);
    }

 
    String ns() throws IOException {
        while (!tok.hasMoreTokens()) {
            tok = new StringTokenizer(in.readLine(), " ");
        }
        return tok.nextToken();
    }
 
    int ni() throws IOException {
        return Integer.parseInt(ns());
    }
 
    long nl() throws IOException {
        return Long.parseLong(ns());
    }
 
    double nd() throws IOException {
        return Double.parseDouble(ns());
    }
 
    String[] nsa(int n) throws IOException {
        String[] res = new String[n];
        for (int i = 0; i < n; i++) {
            res[i] = ns();
        }
        return res;
    }
 
    int[] nia(int n) throws IOException {
        int[] res = new int[n];
        for (int i = 0; i < n; i++) {
            res[i] = ni();
        }
        return res;
    }
 
    long[] nla(int n) throws IOException {
        long[] res = new long[n];
        for (int i = 0; i < n; i++) {
            res[i] = nl();
        }
        return res;
    }
 
    static BufferedReader in;
    static PrintWriter out;
    static StringTokenizer tok;
 
    public static void main(String[] args) throws IOException {
        in = new BufferedReader(new InputStreamReader(System.in));
        out = new PrintWriter(System.out);
        tok = new StringTokenizer("");
        Main main = new Main();
        main.solve();
        out.close();
    }
}

Measured memory_bytes: 33348
import sys
def input():
    return sys.stdin.readline()[:-1]

N,K = map(int,input().split(' '))
l = list(map(int, input().split()))

ttl = 0
for i in range(K):
    d = l[i]
    ttl += (d+1)/2
M = ttl

for i in range(K,N):
    st = i-K
    d = l[st]
    ttl -= (d+1)/2
    dd = l[i]
    ttl += (dd+1)/2
    M = max(ttl,M)
print(M)

Measured memory_bytes: 24804
#A: Colorful Transceivers
a, b, c, d = map(int, input().split())
a_to_c = abs(a - c)
a_to_b = abs(a - b)
b_to_c = abs(b - c)
flag = a_to_b <= d and b_to_c <= d
if a_to_c <= d or flag:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3060
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>

int main()
{
    int A,B;
    scanf("%d%d",&A,&B);
    if( A != 2 && B != 2 ){
        printf("Yes\n");
        return 0;
    }
    printf("No\n");

    return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<map>
#include<vector>
#include<queue>
#define lson (rt << 1)
#define rson (rt << 1 | 1)
#define gmid ((l+r) >> 1)
#define ll long long
using namespace std;

int main()
{
     int n;
	 cin>>n;
	 cout<<n%2+n/2<<endl; 
}


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

using point = pair<Int, Int>;
using vect = point;
using indexed_point = pair<point, Int>;
using polygon = vector<indexed_point>;

vect operator-(point p, point q){
	return vect(p.first - q.first, p.second - q.second);
}

vect operator-(indexed_point p, indexed_point q){
	return vect(p.first.first - q.first.first, p.first.second - q.first.second);
}

Int cross(vect v, vect w){
	return v.first * w.second - v.second * w.first;
}

Int dot(vect v, vect w){
	return v.first * w.first + v.second * w.second;
}

double norm(vect v){
	return sqrt(v.first * v.first + v.second * v.second);
}

double deg(vect v, vect w){
	double theta = dot(v, w) / norm(v) / norm(w);
	if(theta > 1.0 - 1e-10) return 0.0;
	return acos(theta);
}

polygon convex_hull(vector<indexed_point> v, int n){
	sort(v.begin(), v.end());
	polygon res;
	for(int i=0; i<n; ++i){
		while(res.size() >= 2 && cross(res.back() - res[res.size()-2], v[i] - res[res.size()-2]) < 0) res.pop_back();
		res.push_back(v[i]);
	}
	for(int i=n-2; i>=0; --i){
		while(res.size() >= 2 && cross(res.back() - res[res.size()-2], v[i] - res[res.size()-2]) < 0) res.pop_back();
		res.push_back(v[i]);
	}
	return res;
}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	Int n; cin >> n;
	vector<Int> x(n), y(n);
	for(Int i=0; i<n; ++i) cin >> x[i] >> y[i];
	vector<indexed_point> v;
	for(Int i=0; i<n; ++i)
		v.push_back(indexed_point(point(x[i], y[i]), i));
	polygon ch = convex_hull(v, n);
//	for(size_t i=0; i<ch.size(); ++i)
//		cout << i << " " << ch[i].first.first << " " << ch[i].first.second << "\n";
	vector<double> ans(n);
	for(size_t i=0; i+1<ch.size(); ++i){
		int idx = ch[i].second;
		point pr = (i == 0 ? ch[ch.size()-2].first : ch[i-1].first);
		point p = ch[i].first;
		point ne = ch[i+1].first;
		ans[idx] = (acos(-1) - deg(pr-p, ne-p)) / (2 * acos(-1));
	}
	for(int i=0; i<n; ++i)
		cout << fixed << setprecision(10) << ans[i] << "\n";
}

Measured memory_bytes: 384
#include <stdio.h>
int main(void){
  int a,b;
  char op;
  
  while(1){
      scanf("%d %c %d",&a,&op,&b);
  if(op=='?') break;
  else if(op=='+'){
  printf("%d\n",a + b);
} else if(op=='-'){
  printf("%d\n",a - b);
} else if(op=='*'){
  printf("%d\n",a * b);
} else if(op=='/'){
  printf("%d\n",a / b);
} 
}
return 0;
}
 


Measured memory_bytes: 2144
/**
 *    author:  FromDihPout
 *    created: 2020-08-15
**/

#include <bits/stdc++.h>
using namespace std;

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


int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	int n;
	cin >> n;
	vector<int> a(n);
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	sort(all(a));

	int ans = 0;
	for (int i = 0; i < n; i++) {
		for (int j = i + 1; j < n; j++) {
			if (a[i] == a[j]) continue;
			for (int k = j + 1; k < n; k++) {
				if (a[i] == a[k] || a[j] == a[k]) continue;
				if (a[i] + a[j] > a[k]) {
					ans++;
				}
			}
		}
	}
	cout << ans << '\n';

	return 0;
}


Measured memory_bytes: 3660
#include <bits/stdc++.h>
#define RANGE(i,n) for(int i=0;i<n;i++)
typedef long long ll;
struct P{
    ll var1;
    ll var2;
};
bool operator< ( const P &one, const P &two){
    return one.var2 < two.var2;
};
bool operator> ( const P &one, const P &two){
    return one.var2 > two.var2;
};

using namespace std;

signed main() {
    int N;
    cin >> N;
    vector<P> tasks(N);
    RANGE(i, N){
        ll a,b;
        cin >> a >> b;
        tasks[i] = {a,b};
    }
    sort(tasks.begin(), tasks.end());
    ll current=0;
    bool able = true;
    RANGE(i, N){
        current += tasks[i].var1;
        if(current > tasks[i].var2) able = false;
    }
    if(able) cout << "Yes" << endl;
    else cout << "No" << endl;
}


Measured memory_bytes: 3328
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<string>
#include<iostream>
#include<cctype>
#include<cstdio>
#include<vector>
#include<stack>
#include<queue>
#include <algorithm>
#include<math.h>
#include<set>
#include<map>
#include<iomanip>

//#include<bits/stdc++.h>

using namespace std;


int main() {
	string a = "CODEFESTIVAL2016";
	string h;
	cin >> h;
	int t = 0;
	for (int i = 0; i < h.size(); i++) {
		if (a[i] != h[i])t++;
	}
	cout << t << endl;
	return 0;
	
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cstring>
#include <complex>
#include <stack>
#include <queue>
#include <unordered_map>
#include <set>
#include <deque>
#include <map>
#include <bitset>
#include <functional>

#define INF 10000000000
#define rep(i, a) for (int i = 0; i < (a); i++)
using namespace std;
using P = pair<long, long>;

template <typename X>
struct SegTree {
    using FX = function<X(X, X)>;
    int n;
    FX fx;
    const X ex;
    vector<X> dat;
    SegTree(int n_, FX fx_, X ex_) : n(), fx(fx_), ex(ex_), dat(n_ * 4, ex_) {
        int x = 1;
        while (n_ > x) {
            x *= 2;
        }
        n = x;
    }
 
    void set(int i, X x) { dat[i + n - 1] = x; }
    void build() {
        for (int k = n - 2; k >= 0; k--) dat[k] = fx(dat[2 * k + 1], dat[2 * k + 2]);
    }
 
    void update(int i, X x) {
        i += n - 1;
        dat[i] = x;
        while (i > 0) {
            i = (i - 1) / 2;  // parent
            dat[i] = fx(dat[i * 2 + 1], dat[i * 2 + 2]);
        }
    }
 
    // the minimum element of [a,b)
    X query(int a, int b) { return query_sub(a, b, 0, 0, n); }
    X query_sub(int a, int b, int k, int l, int r) {
        if (r <= a || b <= l) {
            return ex;
        } else if (a <= l && r <= b) {
            return dat[k];
        } else {
            X vl = query_sub(a, b, k * 2 + 1, l, (l + r) / 2);
            X vr = query_sub(a, b, k * 2 + 2, (l + r) / 2, r);
            return fx(vl, vr);
        }
    }
    /* debug */
    inline X operator[](int a) { return query(a, a + 1); }
    void print() {
        for (int i = 0; i < n; ++i) {
            cout << (*this)[i];
            if (i != n) cout << ",";
        }
        cout << endl;
    }
};
 
int main() {
    int N, Q;
    string S;
    cin >> N >> S >> Q;
    using X = int;
    auto fx = [](X x1, X x2) -> X { return x1 | x2; };
    X ex = 0;
    SegTree<X> seg(N, fx, ex);
 
    for(int i = 0; i < N; i++) {
        X x = 1 << (int)(S[i] - 'a');
        seg.set(i, x);
    }
    seg.build();
 
    vector<int> ans;
 
    for (int i = 0; i < Q; i++) {
        int q;
        cin >> q;
        if (q == 1) {
            int i;
            char c;
            cin >> i >> c;
            i--;
            X x = 1 << (int)(c - 'a');
            seg.update(i, x);
        } else if (q == 2) {
            int l, r;
            cin >> l >> r;
            X ans = seg.query(l - 1, r);
            cout << __builtin_popcount(ans) << "\n";
        }
    }
 
    return 0;
}

Measured memory_bytes: 8836
#include <bits/stdc++.h>
    using namespace std;
     
    int n,ans,a[220];
     
    int main(){
    	cin >> n;n<<=1;
    	for(int i=1;i<=n;++i)cin >> a[i];
    	sort(a+1,a+n+1);
    	for(int i=1;i<=n;i+=2)
    		ans+=min(a[i],a[i+1]);
    	cout << ans << endl;
    	return 0;
    }

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<cctype>
#include<climits>
#include<string>
#include<bitset>
#include<cfloat>
#include<iomanip>
#include<numeric>

//#define int long long
#define repi(i,start,end) for(int (i)=(start),TemPNuM=(int)(end);(i)<TemPNuM;++(i))
#define rep(i,end) repi((i),0,(end))
#define rfor(x,v) for(auto& (x) : (v))
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define fsort(v,lambda) sort(all((v)),(lambda))
#define vin(v) rep(i,(v).size())cin >> (v)[i];
#define vpin(v) rep(i,(v).size())cin>>v[i].first>>v[i].second

using namespace std;
using ll =  long long;
using pint =  pair<int,int>;
using vint = vector<int>;
using vvint = vector<vint>;
using vpint = vector<pint>;

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
template<class T>void put_double(T a){if(cout.precision()!=12)cout<<setprecision(12);cout<<a<<endl;}
template<class T>void print(T a){cout << a << endl;}
//lambda: [](int x, int y){return x<y;}

signed main(void) {
    int n; cin >> n;
    vint l(n); vin(l);
    sort(rall(l));
    if(l[0] < accumulate(l.begin() + 1, l.end(), 0)) {
        print("Yes");
    } else {
        print("No");
    }

    return 0;
}


Measured memory_bytes: 256
import sys
from operator import itemgetter
input = sys.stdin.readline
a=[None]*5
b=[None]*5
ab=[]
for i in range(5):
    a[i] = int(input())

for i in range(5):
    for h in range(14):
        h*=10
        abss=h-a[i]
        if (h>=a[i])and(0<=abss<=9):
            b[i]=h-a[i]
for i,j in zip(a,b):
    ab.append([i,j])
ab.sort(key=itemgetter(1))
s=0
for i in range(4):
    s+=sum(ab[i])
print(s+ab[-1][0])

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

  const int MOD = 1000000007;
  const int INF = 1e9;

  //long long
  using ll = long long;

  //出力系
  #define print(x) cout << x << endl
  #define yes cout << "Yes" << endl
  #define YES cout << "YES" << endl
  #define no cout << "No" << endl
  #define NO cout << "NO" << endl
  
  // begin() end()
  #define all(x) (x).begin(),(x).end()

  //for
  #define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
  #define REPR(i,n) for(int i=n, i##_len=(n); i>=0; i--)
  #define FOR(i,a,b) for(int i=(a), i##_len=(b); i<i##_len; ++i)

  //最大公約数 
  ll gcd(ll a,ll b){
  if(b == 0) return a;
  return gcd(b,a%b);
  }

  //最小公倍数
  ll lcm(ll a,ll b){
  ll g = gcd(a,b);
  return a / g * b; // Be careful not to overflow  if(a < b) return gcd(b, a);
    unsigned r;
    while ((r=a%b)) {
      a = b;
      b = r;
    }
    return b;
  } 


  //  int X[8]={-1, 0, 1, -1, 1, -1, 0, 1};
  //  int Y[8]={1, 1, 1, 0, 0, -1, -1, -1};




int main() {
int N;
cin >> N;
string S;
cin >> S;

int need_left = 0;
int need_right = 0;

REP(i, N){
  if(S.at(i) == '(') need_right++;
  else {
    if(need_right == 0) need_left++;
    else need_right--;
  } 
}

string ans;
REP(i, need_left) ans += '(';
ans += S;
REP(i, need_right) ans += ')';

print(ans);


}


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

using namespace std;

#define countof(a) (sizeof(a)/sizeof(*a))

#define vi vector<int>
#define vvi vector<vector<int> >
#define vpi vector<pi >
#define pi pair<int,int>
#define mp make_pair
#define fi first
#define se second
#define all(n) n.begin(), n.end()

#define FROMTO(var, from, to) for (register int var = (from), var##down = ((int)(to)) < ((int)(from));var##down ? (var >= (int)(to)) : (var <= (int)(to));var##down ? var-- : var++)
#define UPTO(var, from, to)   for (register int var = (from); var <= ((int)to); var++)
#define DOWNTO(var, from, to) for (register int var = (from); var >= ((int)to); var--)
#define FOR(var, to)          UPTO(var, 0, (to)-1)
#define DOWN(var, from)       DOWNTO(var, (from)-1, 0) 

#define INIT(var, val) FOR(i,countof(var)) var[i] = val
#define INPUT(var) FOR(i,countof(var)) cin >> var[i]
#define INPUT1(var) FOR(i,countof(var)) cin >> var[i], var[i]--

#define SORT(v) qsort(v,countof(v),sizeof(*v),int_less)
#define SORTT(v) qsort(v,countof(v),sizeof(*v),int_greater)
#define QSORT(v,b) qsort(v,countof(v),sizeof(*v),b)

#define MOD 1000000007
#define INF ((1 << 30)-1)
#define LINF ((1LL << 62)-1)

typedef uint8_t u8;
typedef uint16_t u16;
typedef uint32_t u32;
typedef uint64_t u64;
typedef int8_t s8;
typedef int16_t s16;
typedef int32_t s32;
typedef int64_t s64;

struct Comb {
    vector<vector<s64> > data;
    Comb(int n) { // O(n^2)
        data = vector<vector<s64> >(n+1,vector<s64>(n+1,1));
        UPTO(i,1,n) {
            FOR(j,i+1) {
                if (!j || j == i) data[i][j] = 1;
                else data[i][j] = data[i-1][j-1] + data[i-1][j];
            }
        }
    }
    
    s64 ncr(int n, int r) {
        return data[n][r];
    }
};

static inline int ri() {
  int a;
  scanf("%d", &a);
  return a;
}

int int_less(const void *a, const void *b) {
  return (*((const int*)a) - *((const int*)b));
}
int int_greater(const void *a, const void *b) {
  return (*((const int*)b) - *((const int*)a));
}

int main() {
	int n = ri();
	int a = ri();
	int b = ri();
	int c = ri();
	int d = ri();
	
	bool res = false;
	FOR(i,n) { // plus
		int minus = n-1-i;
		s64 minn = a + ((s64)c)*i - ((s64)d)*minus;
		s64 maxx = a + ((s64)d)*i - ((s64)c)*minus;
		if (b >= minn && b <= maxx) res = true;
	}
	
	cout << (res?"YES":"NO") << endl;
	
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	
	public static final int X = 0;
	public static final int Y = 1;
	public static double[][] pos = new double[20][2];
	public static int len = 0;

	public static void main(String[] args) {
		doIt();
	}
	
	public static void doIt(){
		Scanner sc = new Scanner(System.in);
		while(sc.hasNext()){
			String s = sc.next();
			String[] ss = s.split(",");
			pos[len][X] = Double.parseDouble(ss[X]);
			pos[len][Y] = Double.parseDouble(ss[Y]);
			len++;
//			if(len == 5){
//				break;
//			}
			//System.out.println(len);
		}
		int[] array = new int[len];
		for(int i = 0; i < len; i++){
			array[i] = i;
		}
		System.out.println(getArea(array,len));
	}
	//点startからendで構成される図形の面積を返す
	public static double getArea(int[] array, int level){
		//System.out.println("level = " + level);
		//print(array);
		double ans = 0;
		if(level == 3){
			//startから連続した3点から面積を計算
			double[] edge = new double[3];
			double z = 0;
			for(int i = 0; i < 3; i++){
				int a = i;
				int b;
				if(i == 2){
					b = 0;
				}
				else{
					b = i + 1;
				}
				edge[i] = Math.sqrt(Math.pow(pos[array[a]][X] - pos[array[b]][X], 2) + Math.pow(pos[array[a]][Y] - pos[array[b]][Y], 2));
				z += edge[i];
			}
			//ヘロンの公式
			z /= 2;
			ans = z * (z - edge[0])* (z - edge[1])* (z - edge[2]);
			ans = Math.sqrt(ans);
		}
		else{
			if(level % 2 == 0){
				int t = level / 2;
				int[] front = new int[t + 1];
				System.arraycopy(array, 0, front, 0, t + 1);
				ans += getArea(front, t + 1);
				int[] back = new int[t + 1];
				System.arraycopy(array, t, back, 0, t);
				back[t] = array[0];
				ans += getArea(back, t + 1);
			}
			else{
				int t = level / 2;
				int[] front = new int[t + 1];
				System.arraycopy(array, 0, front, 0, t + 1);
				ans += getArea(front, t + 1);
				int[] back = new int[t + 2];
				System.arraycopy(array, t, back, 0, t + 1);
				back[t + 1] = array[0];
				ans += getArea(back, t + 2);
			}
		}
		return ans;
	}
	public static void print(int[] a){
		for(int n : a){
			System.out.print(n + " ");
		}
		System.out.println();
		
	}
}

Measured memory_bytes: 10000
fun main(args: Array<String>) {

    var (N,W) = readLine()!!.split(" ").map{it.toInt()}

    var maxVal = 100000;

    var dp = Array(maxVal+1){ Long.MAX_VALUE /2}
    
    dp[0] = 0;

    for(i in 1..N){
        val (ws,vs) = readLine()!!.split(" ")
        val w = ws.toInt()
        val v = vs.toLong()
        for(sumv in maxVal downTo 0){
            if(sumv - v >= 0){
                dp[sumv] = Math.min(dp[sumv],dp[sumv- v.toInt()] + w)
            }
        }

    }
    var ans = 0;

    for(sum_v in 0 until maxVal+1){
        if(dp[sum_v]<= W){
            ans = sum_v
            //println(ans)
        }
    }

    println(ans)

}


Measured memory_bytes: 123416
n,T = map(int,input().split())
lists = [list(map(lambda x:int(x),input().split())) for i in range(n)]
min = 9999
for i in range(n):
    if lists[i][1] <= T:
        if lists[i][0] <= min:
            min = lists[i][0]
if min == 9999:
    print("TLE")
else :
    print(min)

Measured memory_bytes: 3064
/*@author hussein zayed ;
    ___  ___
   |\  \|\  \
   \ \  \_\  \
    \ \   ___ \USSEIN
     \ \  \\ \ \
      \ \__\\ \_\
       \|__| \|__|
****************************************
*/

#include <bits/stdc++.h>
using namespace std;
#define fr for(int i=0;i<n;++i)
#define fr1 for(int i=1;i<=n;++i)
#define cinA for(int i=0;i<n;++i){cin>>arr[i];}
#define cinA1 for(int i=1;i<=n;++i){cin>>arr[i];}
#define coutA for(int i=0;i<n;++i){cout<<arr[i]<<" ";}
#define ll long long
#define lnarray sizeof(arr)/sizeof(*arr)
#define vi vector<int>
#define vs vector<string>
void Fast()
{
    ios_base :: sync_with_stdio( 0 ) ;
    cin.tie( 0 ) ;
    cout.tie( 0 ) ;
}
inline int RD()
{
    int i ;
    cin>>i;
    return i;
}

inline float RF()
{
    float i ;
    cin>>i;
    return i;
}

inline double RDO()
{
    double i ;
    cin>>i;
    return i;
}

inline string RS()
{
    string i ;
    cin>>i;
    return i;
}

inline ll RLL()
{
    ll i ;
    cin>>i;
    return i;
}

ll sumSet(ll n)
{
    return (1ll*n*(n+1))/2;
}


bool isPrime(int n)
{
    if(n==1)
        return false;
    for(int i=2; i*i<=n; ++i)
    {
        if(n%i==0)
            return false;
    }
    return true;
}
int sumDigit(int n){
int sum =0;
  while (n != 0)
    {
        sum+= + n % 10;
        n = n / 10;
    }
    return sum;
}

ll power2(int n){
  ll ans=(1<<n);
  return ans;
}

ll sumpow2(ll n){
 ll sum=(n*(n+1)*(2*n-1))/6;
 return sum;
}
const int MX=3e5+100;
int n,arr[MX],cm[MX];
int Left,Right,add;
bool can(int x){
 for(int i=1,j=x;j<=n;++i,++j){
  if(cm[j]-cm[i-1]+add>=x){
  Left=i,Right=j;
   return true;}
 }
 return false;
}
bool checkP(int n){
 vector<int>vr;
 while(n!=0){
 int a=n%10;
  n/=10;
 vr.push_back(a);}
 if(vr[0]==vr[4]&&vr[1]==vr[3])
 return true;
 return false;
}
int main(){
    Fast();
//freopen("output.txt" , "w" , stdout);
//freopen("wall.in" , "r" , stdin);

int A=RD(),n=RD();
 int ans=A%500;
 if(n>=ans)
 cout<<"Yes";
 else
 cout<<"No";
 }


Measured memory_bytes: 256