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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,n,m) for(int i=(int)(n); i<=(int)(m); i++)
#define RFOR(i,n,m) for(int i=(int)(n); i>=(int)(m); i--)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)

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; }

#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>

#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ins insert

using namespace std;

/* Some Libraries */

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

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; cin>>n;
    vll a(n);
    vll cnt(200050);
    rep(i,n) cin>>a[i];
    rep(i,n) cnt[a[i]]++;
    ll sum=0;
    rep(i,200050){
        sum+=cnt[i]*(cnt[i]-1)/2;
    }
    rep(i,n){
        ll x = a[i];
        ll A = cnt[x]*(cnt[x]-1)/2;
        ll B = (cnt[x]-1)*(cnt[x]-2)/2;
        cout<<sum-A+B<<"\n";
    }
    return 0;
}


Measured memory_bytes: 5760
#include <stdio.h>
int n;
struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node  Node;
void maxHeapify(Node A[],int i){
    int l = i*2;
    int r = i*2+1;
    int largest;
    Node x;
    if(l<=n && A[l].key>A[i].key){
        largest=l;
    }
    else{
        largest=i;
    }
    if(r<=n && A[r].key>A[largest].key){
        largest=r;
    }
    if(largest!=i){
        x=A[i];
        A[i]=A[largest];
        A[largest]=x;
        maxHeapify(A,largest);
    }
}
void buildMaxHeap(Node A[]){
    int i;
    for(i=n/2;i>=1;i--){
        maxHeapify(A,i);
    }
}
int main(){
    Node x[1000000];
    int i;
    scanf("%d",&n);
    for(i=1;i<=n;i++){
        scanf("%d",&x[i].key);
    }
    buildMaxHeap(x);
    for(i=1;i<=n;i++){
        printf(" %d",x[i].key);
    }
    printf("\n");
    
return 0;
}


Measured memory_bytes: 17364
import java.util.Scanner;

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

    if(a < b && b < c) {
      System.out.println("Yes");
    } else {
      System.out.println("No");
    }
  }
}

Measured memory_bytes: 26112
// ABC.cpp : Defines the entry point for the console application.
//

#include <iostream>
#include <algorithm>
#include <string>

using namespace std;

int main()
{
	int n, m = 1;
	cin >> n;
	while (m <= n) {
		m *= 2;
	}
	cout << m / 2 << endl;
	return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <vector>
using namespace std;
int lim = 1e5;

int main(){
	vector<bool> prime(lim, true);
	prime[0] = prime[1] = false;
	for(int i=2; i*i<lim; i++){
		if(prime[i]){
			for(int j=i*2; j<lim; j+=i){
				prime[j] = false;
			}
		}
	}

	int n;
	while(cin >> n){
		for(int i=n-1; ; i--){
			if(prime[i]){
				cout << i << " ";
				break;
			}
		}
		for(int i=n+1; ; i++){
			if(prime[i]){
				cout << i << endl;
				break;
			}
		}
	}
	return 0;
}


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

#define REP(i,s,n) for(int i=s;i<n;++i)
#define rep(i,n) REP(i,0,n)
#define ALL(x) x.begin(),x.end()
#define EPS (1e-8)
#define equals(a,b) (fabs((a)-(b))<EPS)

using namespace std;

typedef long long ll;
bool LTE(double a,double b) { return equals(a,b) || a < b; }
bool LT(double a,double b) { return !equals(a,b) && a < b; }

void compute() {

}

const string ans = "keyence";

int main() {
  string s;
  cin >> s;
  int n = s.size();
  if( s == ans ) {
    puts("YES");
    return 0;
  }
  rep(i,n) {
    REP(j,i,n) {
      string t = "";
      rep(k,n) {
	if( !( i <= k && k <= j ) ) t += s[k];
      }
      if( t == ans ) {
	puts("YES");
	return 0;
      }
    }
  }
  puts("NO");
  compute();
  return 0;
}


Measured memory_bytes: 256
// inputに入力データ全体が入る
function Main(input) {
  // 1行目がinput[0], 2行目がinput[1], …に入る
  var ans = "No";
  input = input.trim().split("\n");
  // const [X] = input[0].split(" ").map((n) => parseInt(n));
	var S = input[0];
	if (kaibun(S) && 
	kaibun(S.slice(0, Math.floor(S.length / 2))) &&
	kaibun(S.slice(Math.ceil(S.length / 2)))) {
		ans = 'Yes'
	}
	

  function kaibun(str) {
		flg = true
    for (var i = 0; i < str.length /2; i++) {
      if (str[i] != str[str.length - i - 1]) {
				flg = false
        break;
      }
		}
		return flg
  }

  //出力
  console.log(ans);
}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));
// Main(require("fs").readFileSync("./input.txt", "utf-8"));


Measured memory_bytes: 29496
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
#include <stack>
#include <functional>

#ifdef LOCAL
    #define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
    #define eprintf(...) 42
#endif

#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define repp(i, m, n) for(int i = m, i##_len = (n); i < i##_len; ++i)
#define reprev(i, n) for(int i = (n-1LL); i >= 0; --i)
#define all(x) (x).begin(), (x).end()
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> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair <int,int> P;
typedef long double ld;

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a, b;
    cin >> a >> b;
    if (a >= 13) cout << b;
    else if (a <= 5) cout << 0;
    else cout << b/ 2;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A, B, C, a, b, c, d, e;
  cin >> A >> B >> C;
  a = A+B;
  b = A-B;
  c = A*B;
  if(a >= b)
    d = a;
  if(a < b)
    d = b;
  if(d >= c)
    cout << d << endl;
  if(d < c)
    cout << c << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPS(i, x) for (int i = 1; i <= (int)(x); i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORS(i, m, n) for (int i = m; i <= n; i++)
#define INF 2e9
#define MOD (1000000007)
#define EPS 1e-9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef long long int lli;
int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N, Q;
  cin >> N >> Q;
  //vector<pair<int, pair<double, double>>> pp;
  vector<pair<double, pair<int, double>>> ev;
  vector<int> d(Q);
  REP(i, N)
  {
    int s, t, x;
    cin >> s >> t >> x;
    //   pp.emplace_back(x, make_pair(s - 0.5 - x, t - 0.5 - x));
    ev.emplace_back(s - 0.5 - x, make_pair(1, x));
    ev.emplace_back(t - 0.5 - x, make_pair(-1, x));
  }
  //sort(ALL(pp));
  REP(i, Q)
  {
    cin >> d[i];
    ev.emplace_back(d[i], make_pair(100, 100));
  }
  sort(ALL(ev));
  //クエリを用意して反映させる。.second.first,.second.second内にあるものについてxの値を挿入する。
  //扉の開け閉めをシミュレートする。N log N
  //Di Q * log N
  /*REP(i, 2 * N + Q)
  {
    cout << ev[i].first << "\n";
  }*/
  set<int>
      st;
  REP(i, 2 * N + Q)
  {
    if (ev[i].second.first == 1)
    {
      st.insert(ev[i].second.second);
    }
    else if (ev[i].second.first == -1)
    {
      st.erase(ev[i].second.second);
    }
    else
    {
      cout << (st.empty() ? -1 : *(st.begin())) << "\n";
    }
  }
}

Measured memory_bytes: 27496
#include<stdio.h>
long long div[2000];
int inde;

void getDiv(long long n){
  inde = 0;
  long long i;
  for(i=1;i*i<=n;i++)
    if(n%i == 0)
	{
	  div[inde++] = i;
	  if(i!= n/i)
	    div[inde++] = n/i;
	}
}

long long gcd(long long x,long long y)
{
  long long r;
  if(x < y)
    {
      long long tmp = x;
      x = y;
      y = tmp;
    }
  while(y > 0)
    {
      r = x%y;
      x = y;
      y = r;
    }
  return x;
}

int main()
{
  long long n;
  
  while(1)
    {
      scanf("%lld",&n);
      if(n == 0)
	break;
      long long cnt = 0;
      long long i,j;
      getDiv(n);
      for(i=0;i<inde;i++)
	{
	  for(j=i;j<inde;j++)
	    {
	      long long a,b;
	      a = div[i];
	      b = div[j];
	      if(a/gcd(a,b)*b == n)
		cnt++;
	    }
	}
      printf("%lld\n",cnt);
    }
  
  return 0;
}

Measured memory_bytes: 616
#include <iostream>
#include <algorithm>
#include <map>
#include <cmath>

#define MOD 1000000007

using namespace std;

long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

map<long, long> factorize(long N){
    map<long, long> m;
    long lim = sqrt(N);
    long div = 2;
    while(N != 1 && div <= lim){
        long cnt = 0;
        while(N % div == 0){
            cnt ++;
            N /= div;
        }
        if(cnt != 0) m.insert({div, cnt});
        div ++;
    }
    if(N != 1) m.insert({N, 1});
    return m;
}

long comb(int n, int k){
    if(k == 1) return n;
    else {
        long ans = comb(n, k-1) * (n-k+1);  ans %= MOD;
        ans *= modinv(k, MOD);  ans %= MOD;
        return ans;
    }
}

int main(){
    int N, M;
    cin >> N >> M;
    long ans = 1;
    auto f = factorize(M);
    for(auto c : f){
        ans *= comb(c.second + N - 1, c.second);
        ans %= MOD;
    }    
    cout << ans << endl;
    return 0;
}

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

int n;
vector<int> a;

int main() {
  cin >> n;
  a.resize(n);
  for (auto& p : a) {
    cin >> p;
    --p;
  }
  int res = 0;
  for (int i = 0; i < n; ++i) res += a[a[i]] == i;
  cout << res / 2 << endl;
  return 0;
}


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

const int MAXN = 2e5 + 5;
const ll INF = 1e18;
const ll MOD = 1e9 + 7;
ll maxlis[MAXN], wt[MAXN];
int pos[MAXN];

struct node {
    int l, r;
    ll mx;
    node *left, *right;

    node(int l, int r) : l(l), r(r) {
        mx = -INF;
        if(l != r) {
            int m = (l + r)/2;
            left = new node(l, m);
            right = new node(m + 1, r);
        }
    }

    void upd(int pos, ll val) {
        if(pos < l || r < pos)
            return;
        if(l == r) {
            mx = val;
            return;
        }
        left->upd(pos, val);
        right->upd(pos, val);
        mx = max(left->mx, right->mx);
    }

    ll qrymx(int rl, int rr) {
        if(rr < l || r < rl)
            return -INF;
        if(rl <= l && r <= rr)
            return mx;
        return max(left->qrymx(rl, rr), right->qrymx(rl, rr));
    }
};

int main() {
    int n;
    cin >> n;
    node st = node(1, n);
    for(int i = 1; i <= n; i++)
        cin >> pos[i];
    for(int i = 1; i <= n; i++)
        cin >> wt[i];
    for(int i = 1; i <= n; i++) {
        int p = pos[i];
        ll mx = st.qrymx(1, p);
        maxlis[p] = wt[i] + max(mx, 0ll);
        st.upd(p, maxlis[p]);
    }
    ll mx = 0;
    for(int i = 1; i <= n; i++)
        mx = max(mx, maxlis[i]);
    cout << mx << endl;
}

Measured memory_bytes: 24448
arr = input().split()

n = {
    0 : [(3, 1), (4, 3), (2, 4), (1, 2)],
    1 : [(0, 3), (3, 5), (5, 2), (2, 0)],
    2 : [(0, 1), (4, 0), (5, 4), (1, 5)],
    3 : [(0, 4), (4, 5), (5, 1), (1, 0)],
    4 : [(0, 2), (2, 5), (5, 3), (3, 0)],
    5 : [(1, 3), (3, 4), (4, 2), (2, 1)],
}

q = int(input())
for _ in range(q):
    a, b = input().split()
    
    for i in range(6):
        if (arr.index(a), arr.index(b)) in n[i]:
            print(arr[i])


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

int main()
{
  int R;
  cin >> R;
  if (R<1200) cout << "ABC" << endl;
  else if(1200<=R && R<2800) cout << "ARC" << endl;
  else cout << "AGC" << endl;
} 

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


int main(void){
  int A, B;
  cin >> A >> B;
  int max =  A + B;
  if(max < A - B) max =  A - B; 
  if(max < A * B) max =  A * B; 
  cout << max << endl;
 return 0;
  
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.Random;
import java.util.StringTokenizer;

public final class Main {

    public static void main(String[] args) {
        final FastScanner fs = new FastScanner();
        final int a = fs.nextInt();
        final int b = fs.nextInt();
        System.out.println((a % 2 != 0 && b % 2 != 0) ? "Yes" : "No");
    }

    static final class Util {
        public static void shuffleSort(int[] x) {
            shuffle(x);
            Arrays.sort(x);
        }

        public static void shuffleSort(long[] x) {
            shuffle(x);
            Arrays.sort(x);
        }

        public static void shuffle(int[] x) {
            final Random r = new Random();

            for (int i = 0; i <= x.length - 2; i++) {
                final int j = i + r.nextInt(x.length - i);
                swap(x, i, j);
            }
        }

        public static void shuffle(long[] x) {
            final Random r = new Random();

            for (int i = 0; i <= x.length - 2; i++) {
                final int j = i + r.nextInt(x.length - i);
                swap(x, i, j);
            }
        }

        public static void swap(int[] x, int i, int j) {
            final int t = x[i];
            x[i] = x[j];
            x[j] = t;
        }

        public static void swap(long[] x, int i, int j) {
            final long t = x[i];
            x[i] = x[j];
            x[j] = t;
        }

        private Util() {}
    }

    static class FastScanner {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st = new StringTokenizer("");

        private String next() {
            while (!st.hasMoreTokens()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    //noinspection CallToPrintStackTrace
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        int[] nextIntArray(int n) {
            final int[] a = new int[n];
            for (int i = 0; i < n; i++) { a[i] = nextInt(); }
            return a;
        }

        long[] nextLongArray(int n) {
            final long[] a = new long[n];
            for (int i = 0; i < n; i++) { a[i] = nextLong(); }
            return a;
        }
    }
}


Measured memory_bytes: 32740
#include <iostream>

using namespace std;

int main(void) {
	int sind,tind,diff;
	string s,t,ss,st;
	while (cin >> s, s != ".") {
		cin >> t;
		diff = sind = tind = 0;
		while (diff < 2 && sind < s.length() && tind < t.length()) {
			if (s[sind] != t[tind]) {
				diff = 2;
			}
			else {
				if (s[sind] == '\"') {
					++sind;
					ss = "";
					while (s[sind] != '\"') {
						ss += s[sind];
						++sind;
					}
					st = "";
					++tind; 
					while (t[tind] != '\"') {
						st += t[tind];
						++tind;
					}
					if (ss != st) {
						++diff;
					}
				}
			}
			++sind;
			++tind;
		}
		if (sind < s.length() || tind < t.length()) {
			diff = 2;
		}
		if (diff == 0) {
			cout << "IDENTICAL" << endl;
		}
		else if (diff == 1) {
			cout << "CLOSE" << endl;
		}
		else {
			cout << "DIFFERENT" << endl;
		}
	}
	return 0;
}



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

using namespace std;

int main() {
  int n, m, t, p;
  while (cin >> n >> m >> t >> p, n) {
    vector<vector<int>> g(n * n, vector<int>(m * m, 0));
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        g[i][j] = 1;
      }
    }
    int px = 0, py = 0;

    for (int i = 0; i < t; i++) {
      int d, c;
      cin >> d >> c, d--;
      if (d) {
        py += c;
        for (int j = 0; j < c; j++) {
          for (int i = 0; i < n * n; i++) {
            g[i][py + j] += g[i][py - j - 1];
          }
        }
      } else {
        px += c;
        for (int i = 0; i < c; i++) {
          for (int j = 0; j < m * m; j++) {
            g[px + i][j] += g[px - i - 1][j];
          }
        }
      }  
    }

    for (int i = 0; i < p; i++) {
      int x, y;
      cin >> x >> y;
      cout << g[px + x][py + y] << endl;
    }

  }
  return 0;
}



Measured memory_bytes: 7084
#include <iostream>
#include <string>
#include <vector>
#include <functional>
#include <algorithm>
#include <array>

using namespace std;

template<typename T>
class Heap
{
public:
	Heap(const vector<T>& v) :nodes_(v) {}
	void printAllNodeInfo() {
		const int n = nodes_.size();
		const function<bool(int)> isInRange = [&](const int index) {
			return 1 <= index && index <= n;
		};
		const function<void(int,string)> printValueIfInRange = [&](const int index, const string& name) {
			if (isInRange(index)) cout << name << " = " << nodes_.at(index - 1) << ", ";
		};
		
		for (int id = 1; id <= n; ++id) {
			const int parentIndex = static_cast<int>(floor(id / 2));
			const int leftIndex = 2 * id;
			const int rightIndex = leftIndex + 1;

			cout << "node " << id << ": ";
			printValueIfInRange(id, "key");
			printValueIfInRange(parentIndex, "parent key");
			printValueIfInRange(leftIndex, "left key");
			printValueIfInRange(rightIndex, "right key");
			cout << endl;
		}
	}
	vector<T> nodes_;
};

template<typename T>
void execute(T& cin) {
	int n;
	cin >> n;
	vector<int> v(n);
	for (auto& i : v)cin >> i;
	Heap<int> heap(v);
	heap.printAllNodeInfo();
}


int main()
{
execute(cin);


	return 0;
}


Measured memory_bytes: 3160
// Package main provides
//
// File:  c.go
// Author: ymiyamoto
//
// Created on Fri Jan  4 15:54:17 2019
//
package main

import (
	"fmt"
	"sort"
)

func min(slice ...int) int {
	sort.Ints(slice)
	return slice[0]
}

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

func main() {
	var N int
	fmt.Scan(&N)

	m := map[int]int{}
	for i := 0; i < N; i++ {
		var a int
		fmt.Scan(&a)
		m[a]++
	}

	ans := 0
	for k, v := range m {
		if v >= k {
			ans += v - k
		} else {
			ans += v
		}
	}

	fmt.Println(ans)
}


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

int main() {
    string s;
    cin >> s;
    string ans="AC";
    if(s.at(0)!='A'){
        ans="WA";
    }
    int count=0;
    for(int i=1;i<s.size();i++){
        if(isupper(s.at(i))){
            if(i==1||i==s.size()-1||s.at(i)!='C'){
                ans="WA";
            }
            count++;
        }
    }
    if(count!=1){
        ans="WA";
    }
    cout << ans << endl;
}

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

#define DEBUG 1

#if (DEBUG == 1)
#endif

int main()
{
  int S;
  int W;

  cin >> S >> W;

  if (S <= W) {
    cout << "unsafe" << endl;
  } else {
    cout << "safe" << endl;
  }

  return 0;
}


Measured memory_bytes: 3568
#include <bits/stdc++.h>
#include <vector> 
# include <cstdint>
#define FOR(i,l,r) for(int i=(l);i<(r);++i)
#define RFOR(i,l,r) for(int i=(l);i>=(int)(r);i--)
#define rep(i,n)  FOR(i,0,n)
#define rrep(i,n)  RFOR(i,n-1,0)

#define int long long
using namespace std;
const int MX = 1e6;
const int inf = 1e9;
const int mod = 1e9+7;
#define ll long long

signed main() {
  int d;
  cin >> d;
  vector<int> c(26);
  rep(i,26) cin >> c[i];
  vector<vector<int>> s(d);
  int ans = 0;
  rep(i,d) {
    int ma = 0;
    rep(j,26) {
      int num;
      cin >> num;
      ma = max(ma,num);
      if(ma==num) ans = j+1;
      s[i].push_back(num);
    }
    cout << ans << endl;
  }
  // vector<int> t(d);


  // rep(i,d) {
  //   cout << 9 << endl;
  // }
  
  
  return 0;
}


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

typedef long long ll;

int N,N_,A,B,Q;
int X[200010];
ll INF = 1001001001001001001;
ll seg[2][800010];

void init()
{
    N_ = 1;
    while(N_ <= N)N_ *= 2;
    for(int i = 0; i < N_ * 2 - 1; i++)seg[0][i] = seg[1][i] = INF;
    return;
}

void update(int t,int p,ll x)
{
    p += N_ - 1;
    seg[t][p] = min(seg[t][p],x);
    while(p)
    {
        p = (p - 1) / 2;
        seg[t][p] = min(seg[t][p * 2 + 1],seg[t][p * 2 + 2]);
    }
    return;
}

ll get_min(int t,int a,int b,int k = 0,int l = 0,int r = N_)
{
    if(b <= l || r <= a)return INF;
    if(a <= l && r <= b)return seg[t][k];
    ll L = get_min(t,a,b,k * 2 + 1,l,(l + r) / 2);
    ll R = get_min(t,a,b,k * 2 + 2,(l + r) / 2,r);
    return min(L,R);
}

ll unit()
{
    ll ans = INF,mem = 0;
    for(int i = 1; i <= Q; i++)
    {
        ll L = get_min(0,0,X[i]) + X[i],R = get_min(1,X[i],N) - X[i];
        ll res = min(L,R) - abs(X[i] - X[i - 1]);
        update(0,X[i - 1],res - X[i - 1]);
        update(1,X[i - 1],res + X[i - 1]);
        mem += abs(X[i] - X[i - 1]);
    }
    for(int i = 0; i < N; i++)ans = min(ans,get_min(0,i,i + 1) + i);
    return ans + mem;
}

int main()
{
    scanf("%d%d%d%d",&N,&Q,&A,&B);
    A--;B--;
    for(int i = 1; i <= Q; i++)scanf("%d",X + i),X[i]--;
    ll ans = INF;

    init();
    X[0] = B;
    update(0,A,-A);
    update(1,A,A);
    ans = unit();

    init();
    X[0] = A;
    update(0,B,-B);
    update(1,B,B);
    ans = min(ans,unit());

    printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 13312
use proconio::{fastout, input};
use std::collections::HashMap;

#[fastout]
fn main() {
    input! {
        n: u32,
        m: u32,
        h: [u32;n],
        com: [[u32;2];m]
    }

    let mut bad_peaks = HashMap::new();

    for i in 0..com.len() {
        // println!("{}", h[com[i][0] as usize - 1]);
        // println!("{}", h[com[i][1] as usize - 1]);
        if h[com[i][0] as usize - 1] > h[com[i][1] as usize - 1] {
            bad_peaks.entry(com[i][1]).or_insert(1);
        } else if h[com[i][0] as usize - 1] == h[com[i][1] as usize - 1] {
            bad_peaks.entry(com[i][1]).or_insert(1);
            bad_peaks.entry(com[i][0]).or_insert(1);
        } else {
            bad_peaks.entry(com[i][0]).or_insert(1);
        }
    }

    // println!("{:?}", bad_peaks);

    println!("{}", n - bad_peaks.len() as u32);
}


Measured memory_bytes: 10996
while True:
  n=int(input())
  if n==-1:
    break
  a=4280
  b=1150
  if n<=10:
    print(a-b)
  elif 10<n<=20:
    print(a-(b+(n-10)*125))
  elif 20<n<=30:
    print(a-(b+1250+(n-20)*140))
  else:
    print(a-(b+1250+1400+(n-30)*160))


Measured memory_bytes: 5596
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>

using namespace std;

using vi = vector<int>;

// Implementation provided by github.com/danielf !!
struct UF 
{
    vi p, rank;
    UF(int n) 
    {
        p = vi(n);
        rank = vi(n, 0);

		for (int i = 0; i < n; i++) p[i] = i;
    }
    
    int find(int v) 
    {
        if( p[v] != v) p[v] = find(p[v]);
        return p[v];
    }

    bool unio(int a, int b) {
        a = find(a); b = find(b);
        if(a == b) return false;
        if(rank[a] < rank[b]) p[a] = b;
        else p[b] = a;
        if(rank[a] == rank[b]) rank[a]++;
        return true;
    }
};

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

	UF uf(N);

	for (int i = 0; i < M; i++) {
		int a, b;

		cin >> a >> b;
		a--;
		b--;
		
		uf.unio(a, b);
	}

	vector<int> count(N, 0);
	for (int i = 0; i < N; i++) count[uf.find(i)]++;

	sort(count.rbegin(), count.rend());

	cout << count[0] << endl;

	return 0;
}


Measured memory_bytes: 5640
#include<bits/stdc++.h> 
//#define <- プログラムの文字列を置換する
//typedef <- 新しい型に名前を付けるためのキーワード

using namespace std;

#define MAX_N 1

typedef long long ll;

const double PI = 3.141592653589793;
const long long MOD = 1e9 + 7;
const long long INF = 1e15;
const int INF_INT = 1e9;

int main(){
    int a,b,c;
    cin >> a >> b >> c;
    cout << max(c - (a - b),0) << endl;
}


Measured memory_bytes: 3596
#include <stdio.h>

int main(int argc, const char * argv[]) {
    int a;
    scanf("%d",&a);
    int t=0,i;
    long int b[a],k=0;
    //int b[1500000],k=0;
    for(i=0;i<a;i++){
        scanf("%ld",&b[i]);
        if(t<b[i]) t=b[i];
        else k+=t-b[i];
    }
    printf("%ld",k);
    return 0;
}


Measured memory_bytes: 3288
N = int(input())
S_list = []
for n in range(N):
    S_list.append(input())

dic = dict()
for s in S_list:
    if s in dic:
        dic[s] += 1
    else:
        dic[s] = 1

dict_sorted = sorted(dic.items(), key=lambda x: x[1], reverse=True)

outs = []
max = None
for (out, num) in dict_sorted:
    if max is None:
        outs.append(out)
        max = num
    elif max == num:
        outs.append(out)
    else:
        break

for out in sorted(outs):
    print(out)


Measured memory_bytes: 119936
#include <bits/stdc++.h>
#include <typeinfo>
#include <cxxabi.h>
#ifdef LOCAL
#include "dbgtoki.hpp"
#define DUMP(i) dump((string)TOSTRING(i), demangle(typeid(i).name()), __LINE__ , i) 
#else
#define DUMP(i)
#endif

using namespace std;
#define TOSTRING(x) #x
#define SZ(x) (int)(x).size()
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define ALL(s) (s).begin(), (s).end()
#define dis distance
#define so(V) sort(ALL(V))
#define rev(V) reverse(ALL(V))
#define uni(v) v.erase( unique(ALL(v)) , v.end());
#define pub push_back
#define sec second
#define fir first

typedef long long unsigned int llu;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vector <int> > vvi;
const int EPS = 1e-9;
const int MOD = 1e9+7;
const int INF = (1 << 30);
const double PI = acos(-1);

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	cin >> n;
	vector<int> V(n,-1);
	int ans = 0;
	REP(i,n){
		int a;
		cin >> a;
		a--;
		V[i] = a;
		DUMP(i);
		DUMP(V[a]);
		if(V[a]==i)ans++;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 640
/*input
2
ip cc
*/
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
#define IOS ios_base::sync_with_stdio(0); cin.tie(0)
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define F first
#define S second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define eb emplace_back
#define pb push_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define EL cout<<'\n'
#define BS(a,x) binary_search(ALL(a),x)
template<typename T1,typename T2>
ostream& operator<<(ostream& out,pair<T1,T2> P){
	out<<'('<<P.F<<','<<P.S<<')';
	return out;
}
template<typename T>
ostream& operator<<(ostream& out,vector<T> V){
	REP(i,SZ(V)) out<<V[i]<<((i!=SZ(V)-1)?" ":"");
	return out;
}
//}}}
const ll maxn=300005;
const ll maxlg=20;
const ll INF64=1e18;
const int INF=0x3f3f3f3f;
const ll MOD=ll(1e9+7);
const ld PI=acos(-1);
const ld eps=1e-9;
//const ll p=880301;
//const ll P=31;

ll mypow(ll a,ll b){
	ll res=1LL;
	while(b){
		if(b&1) res=res*a%MOD;
		a=a*a%MOD;
		b>>=1;
	}
	return res;
}


int main(){
	IOS;
	int n;
  cin>>n;
  cout<<3*n*n;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <stack>
#include <climits>
#include <map>
#include <set>

using namespace std;

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

const ll mod = 1000000007;
const int inf = 1e9;
const long long INF = 1LL << 60;

struct UnionFind{
    vector<int> rank,p,size;
    UnionFind(int n){
        rank.resize(n,0);
        p.resize(n,0);
        size.resize(n,0);
        for(int i = 0; i < n; i++){
            p[i] = i;
            rank[i] = 0;
            size[i] = 1;
        }
    }
    bool same(int x,int y){
        return root(x) == root(y);
    }
    int root(int x){
        if(x != p[x]){
            p[x] = root(p[x]);
        }
        return p[x];
    }
    bool unite(int x,int y){
        int rx = root(x);
        int ry = root(y);
        if(rx == ry) return false;
        if(rank[rx] > rank[ry]){
            p[ry] = rx;
            size[rx] += size[ry];
        }else{
            p[rx] = ry;
            size[ry] += size[rx];
            if(rank[rx] == rank[ry]){
                rank[ry]++;
            }
        }
        return true;
    }
    int tree_size(int x){
        return (size[root(x)]);
    }
};

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

    int ans = 0;

    for(int i = 0; i < m; i++){
        UnionFind uf(n);
        for(int j = 0; j < m; j++){
            if(i == j){
                continue;
            }else{
                uf.unite(a[j],b[j]);
            }
        }
        if(!uf.same(a[i],b[i])){
            ans++;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <cstring>
#include <queue>
#include <cmath>
#include <stack>
#include <map>
#include <set>
using namespace std;
#define REP(i, a, b) for(int i = a; i <= b; i++)
#define PER(i, a, b) for(int i = a; i >= b; i--)
#define LL long long
#define int long long
#define lowbit(x) x &(-x)

inline int read() {
    int x = 0, flag = 1;char ch = getchar();
    while(!isdigit(ch)) {
        if(ch == '-') flag = - 1;
        ch = getchar();
    }
    while(isdigit(ch)) x = x * 10 + ch - '0', ch = getchar();
    return x * flag;
}

const LL INF = 1e17;
const int N = 2e5 + 5;
LL s[N << 2];
inline void pushup(int p) {
    s[p] = min(s[p << 1], s[p << 1 | 1]);
}

inline void build(int p, int l, int r) {
    if(l == r) {
        s[p] = INF;
        return;
    }
    int mid = (l + r) >> 1;
    build(p << 1, l, mid); build(p << 1 | 1, mid + 1, r);
    pushup(p);
}

inline LL query(int p, int l, int r, int x, int y) {
    if(x <= l && r <= y) return s[p];
    int mid = (l + r) >> 1;
    LL ans = INF;
    if(x <= mid) ans = min(ans, query(p << 1, l, mid, x, y));
    if(y > mid) ans = min(ans, query(p << 1 | 1, mid + 1, r, x, y));
    return ans;
}

inline void update(int p, int l, int r, int x, int v) {
    if(l == r) {
        if(v < s[p]) s[p] = v;
        return;
    }
    int mid = (l + r) >> 1;
    if(x <= mid) update(p << 1, l, mid, x, v);
    else update(p << 1 | 1, mid + 1, r, x, v);
    pushup(p);
}
int n, m;

struct node {
    int l, w;
};
vector<node> G[N];

signed main() {   
    n = read(); m = read();
    REP(i, 1, m) {
        int x = read(), y = read(), z = read();
        G[y].push_back((node){x, z});
    }   build(1, 1, n);
    for(int i = 1; i <= n; ++i) {
        for(int j = 0; j < G[i].size(); ++j) {
            int l = G[i][j].l, w = G[i][j].w;
            if(l == 1) update(1, 1, n, i, w);
            else {
                LL res = query(1, 1, n, l, i);
                if(res < INF) update(1, 1, n, i, w + res);
            }
        }
    }
    LL ans = query(1, 1, n, n, n);
    if(ans >= INF) cout << -1 << endl;
    else printf("%lld\n", ans);
	return 0;
}


Measured memory_bytes: 11520
H,W=map(int,input().split())
A=[[None]*(W+2)]
A.extend([[i=="." for i in "#"+input()+"#"] for _ in range(H)])
A.append([None]*(W+2))

#q=[[(i,j) for i in range(1,H+1) for j in range(1,W+1) if not A[i][j]]]
q=[(i,j) for i in range(1,H+1) for j in range(1,W+1) if not A[i][j]]

for k in range(2000):
#k=0
#while(q):
    r=[]
    #q.append([])
    #for i,j in q[k]:
    for i,j in q:
        if A[i-1][j]:
            A[i-1][j]=None
            #q[k+1].append((i-1,j))
            r.append((i-1,j))
        if A[i+1][j]:
            A[i+1][j]=None
            #q[k+1].append((i+1,j))
            r.append((i+1,j))
        if A[i][j-1]:
            A[i][j-1]=None
            #q[k+1].append((i,j-1))
            r.append((i,j-1))
        if A[i][j+1]:
            A[i][j+1]=None
            #q[k+1].append((i,j+1))
            r.append((i,j+1))
    if not len(r):
        break
    q=r
print(k)

Measured memory_bytes: 106876
#include <bits/stdc++.h>
#define fin ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define ii pair<int,int>
#define F first
#define S second
#define pb push_back
#define pf push_front
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define fore(i,a,b) for(int i = a;i < b; i+= 1)
#define forr(i,a) for(int i = a; i >= 0; i--)
#define fori(i,m) for(auto i = m.begin(); i != m.end(); i++) 
#define sz(s) int(s.size())
#define cls(a,car) memset(a,car,sizeof (a))
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ii> vii;
const int N = 1 * 1e5 + 5;
const ll mod = 1e9 + 7;
const int INF = INT_MAX;
const ll INFCAD  = ll(INT_MAX) * 2 + 1;
const double E = 1e-9;

int main(){
    //freopen("in","r",stdin);
    //freopen("out","w",stdout);
    fin;
    int n;
    cin >> n;
    int v[n + 5];
    fore(i, 1, n + 1)
        cin >> v[i];
    int cnt = 0;
    int i = 1;
    set<int> s;
    bool flag = 1;
    while(i != 2){
        cnt++;
        i = v[i];
        if(!s.count(i))
            s.insert(i);
        else{
            flag = 0;
            break;
        }
    }
    cout << (flag?cnt:-1) << '\n';
    return 0;
}   

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

using namespace std;
int main(){
  long q,h,s,d,n;
  cin >> q >> h >> s >> d >> n;
 
  long ans;
  
  ans=(n/2)*min(min(d,2*s),min(4*h,8*q))+(n%2)*min(s,min(2*h,4*q));
   
  
 cout << ans << endl;
  
  
}

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

int main(int argc, char const *argv[])
{
    int H,W;
    while(1) {
        cin >> H >> W;
        if(H==0 && W ==0) break;
        for (int i = 0; i < H; ++i)
        {
            for (int j = 0; j < W; ++j)
            {
                if(i==0 || i==H-1) cout << "#";
                else if(j==0 || j==W-1) cout << "#";
                else cout << ".";
            }
            cout << endl;
        }
        cout << endl;
    }
    return 0;
}

Measured memory_bytes: 1152
#include <cassert>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
#include <iostream>
using namespace std;
#define REP(i, n) for(int i = 0; i < (int)(n); ++i)

typedef long long ll;

ll dp[100000+10];

int main(void) {
  int n, W;
  scanf("%d%d", &n, &W);
  REP(i, n) {
    ll w, v;
    scanf("%lld%lld", &w, &v);
    for(int j = W-w; j >= 0; --j) {
      dp[j+w] = max(dp[j+w], dp[j] + v);
    }
  }
  ll maxi = 0;
  REP(i, W+1) {
    maxi = max(maxi, dp[i]);
  }
  cout << maxi << endl;
  return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i = a; i < b; ++i)
#define all(c) c.begin(), c.end()
#define gmax(x,y) x=max(x,y)
#define gmin(x,y) x=min(x,y)
#define gadd(x,y) x=add(x,y)
#define gmul(x,y) x=mul(x,y)
using namespace std;

typedef pair<int,int> pii;
typedef long long ll;
typedef vector<int> vi;

int main(){
	cin.tie(0);
	cout.tie(0);
	ios_base::sync_with_stdio(0);
	int a;
	cin >> a;
	cout << a + a*a + a*a*a << '\n';
}


Measured memory_bytes: 3668
import sys
input = sys.stdin.readline


n,k,c = map(int,input().split())
s = list(input())

if c == 0:
    res = []
    for i in range(n):
        if s[i] == "o":
            res.append(i+1)
    if len(res) <= k:
        for e in res:
            print(e)
    exit()


back = [0]*(n+1)
fro = [0]*(n+1)

for i in range(n-1,-1,-1):
    if i >= n-c:
        if back[i+1] == 1:
            back[i] = 1
        elif s[i] == "o":
            back[i] = 1
        else:
            back[i] = 0
    else:
        if s[i] == "o":
            back[i] = max(back[i+c+1]+1,back[i+1])
        else:
            back[i] = back[i+1]

for i in range(n):
    if i <= c:
        if fro[i-1] == 1 or s[i] == "o":
            fro[i] = 1
        else:
            fro[i] = 0

    else:
        if s[i] == "o":
            fro[i] = max(fro[i-c-1]+1,fro[i-1])
        else:
            fro[i] = fro[i-1]


for i in range(n):
    if i == 0:
        if n == 1:
            print(1)
        else:
            if back[1] < k:
                print(1)
        continue

    if back[i+1] + fro[i-1] < k:
        print(i+1)

Measured memory_bytes: 64368
#include<iostream>
#include<algorithm>
#include<vector>
#include<cstdio>
#include<cmath>
#include<string>
#include<cstdlib>
#include<utility>

typedef long long ll;
#define INF 10e9

using namespace std;

int main() {
	int d;
	cin >> d;

	if (d == 25) cout << "Christmas" << endl;
	if (d == 24) cout << "Christmas Eve" << endl;
	if (d == 23) cout << "Christmas Eve Eve" << endl;
	if (d == 22) cout << "Christmas Eve Eve Eve" << endl;
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>
using namespace std;
using ll = long long;
#define fst first
#define snd second

/* clang-format off */
template <class T, size_t D> struct _vec { using type = vector<typename _vec<T, D - 1>::type>; };
template <class T> struct _vec<T, 0> { using type = T; };
template <class T, size_t D> using vec = typename _vec<T, D>::type;
template <class T> vector<T> make_v(size_t size, const T& init) { return vector<T>(size, init); }
template <class... Ts> auto make_v(size_t size, Ts... rest) { return vector<decltype(make_v(rest...))>(size, make_v(rest...)); }
template <class T> inline void chmin(T &a, const T& b) { if (b < a) a = b; }
template <class T> inline void chmax(T &a, const T& b) { if (b > a) a = b; }
/* clang-format on */

int main() {
#ifdef DEBUG
  ifstream ifs("in.txt");
  cin.rdbuf(ifs.rdbuf());
#endif
  int N, M;
  while (cin >> N >> M) {
    int l = 0, r = N + 1;
    for (int i = 0; i < M; i++) {
      int L, R;
      cin >> L >> R;
      l = max(l, L);
      r = min(r, R);
    }
    int res = max(0, r - l + 1);
    cout << res << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<utility>
#include<iomanip>
#include<map>
#include<cmath>
#include<cstdio>

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

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

int main(int argc, const char * argv[]) {
    int X, Y;
    cin >> X >> Y;
    
    bool ans=false;
    for(int i=0; i<=X; i++){
        if(i*2 + (X-i)*4 == Y) ans=true;
    }
    
    if(ans) cout << "Yes" << endl;
    else cout << "No" << endl;
    
    return 0;
}


Measured memory_bytes: 3624
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;

int main(){
    
    ll color[10] = {};
    ll N;
    cin >> N;
    for(ll i = 0; i < N; i++){
        ll a;
        cin >> a;
        if(0 <= a && a < 400)color[1]=1;
        else if(400 <= a && a < 800)color[2]=1;
        else if(800 <= a && a < 1200)color[3]=1;
        else if(1200 <= a && a < 1600)color[4]=1;
        else if(1600 <= a && a < 2000)color[5]=1;
        else if(2000 <= a && a < 2400)color[6]=1;
        else if(2400 <= a && a < 2800)color[7]=1;
        else if(2800 <= a && a < 3200)color[8]=1;
        else color[0]++;
    }
    ll mn = 0;
    for(int i = 1; i <= 8; i++)mn += color[i];
    cout << max(mn, 1LL) << " " << mn + color[0] << endl;

    return 0;
}

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

using namespace std;

const int vy[] = {0, 1, 0, -1}, vx[] = {1, 0, -1, 0};

int H, W, R, C;
bool graph[505][505][4];
bool iswin[505][505];

int main()
{
  while(scanf("%d %d %d %d", &H, &W, &R, &C), H) {
    for(int i = 0, x; i <= H * 2; i++) {
      if(i & 1) {
        for(int j = 0; j <= W; ++j) {
          scanf("%d", &x);
          graph[j][i / 2 + 1][0] = graph[j + 1][i / 2 + 1][2] = x == 0;
        }
      } else {
        for(int j = 0; j < W; ++j) {
          scanf("%d", &x);
          graph[j + 1][i / 2][1] = graph[j + 1][i / 2 + 1][3] = x == 0;
        }
      }
    }

    queue< tuple< int, int > > que;
    memset(iswin, false, sizeof(iswin));
    for(int i = 1; i <= H; i++) {
      que.emplace(1, i);
      que.emplace(W, i);
    }
    for(int i = 1; i <= W; i++) {
      que.emplace(i, 1);
      que.emplace(i, H);
    }
    while(!que.empty()) {
      int x, y;
      tie(x, y) = que.front();
      que.pop();
      if(iswin[x][y]) continue;
      bool ok = false, ng = false;
      for(int i = 0; i < 4; i++) {
        int nx = x + vx[i], ny = y + vy[i];
        if(nx <= 0 || ny <= 0 || nx > W || ny > H || iswin[nx][ny]) {
          if(graph[x][y][i]) ok = true;
          else ng = true;
        }
      }
      if(ok && ng) {
        iswin[x][y] = true;
        for(int i = 0; i < 4; i++) {
          int nx = x + vx[i], ny = y + vy[i];
          if(1 <= nx && nx <= W && 1 <= ny && ny <= H && !iswin[nx][ny]) {
            que.emplace(nx, ny);
          }
        }
      }
    }
    bool win = false;
    for(int i = 0; i < 4; i++) {
      int nx = C + vx[i], ny = R + vy[i];
      if(graph[C][R][i] && (nx <= 0 || ny <= 0 || nx > W || ny > H || iswin[nx][ny])) {
        win = true;
      }
    }
    if(win) puts("Yes");
    else puts("No");
  }
}

Measured memory_bytes: 4396
#include <iostream>
#include <algorithm>
#include <cstring>
#include <vector>
#include <cstring>
#include <set>
#include <map>
using namespace std;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define sz(x) (int)x.size()
#define rep(i, a, b) for (int i=(a);i<=(b);i++)
#define dd(x) cout << #x << " = " << x << endl;
typedef pair<int, int> pii;
typedef long long LL;

const LL MOD = 1000000007;
const int N = 500000+10;

LL n, y;
int main() {
    cin >> n >> y;
    rep(i, 0, n) {
        rep(j, 0, n-i) {
            LL now = 10000L * (LL)i + 5000L * (LL)j;
            if (now <= y && (y - now) / 1000 + i + j == n) {
                printf("%d %d %d\n", i, j, (y - now) / 1000);return 0;
            }
        }
    }
    printf("-1 -1 -1\n");
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
string A(int a)
{
   for(int j=1;j<=9;j++)
   {
     if((a/j)>=1 && (a/j)<=9)
     {if(a%j==0)
       return "Yes";}
   }
  return "No";
}
int main()
{
  int a;
  cin>>a;
  cout<<A(a)<<endl;
}

Measured memory_bytes: 256
def prepare(n, MOD):
    f = 1
    factorials = [1]
    for m in range(1, n + 1):
        f = f * m % MOD
        factorials.append(f)
    inv = pow(f, MOD - 2, MOD)
    invs = [1] * (n + 1)
    invs[n] = inv
    for m in range(n, 1, -1):
        inv = inv * m % MOD
        invs[m - 1] = inv

    return factorials, invs


def solve(n, a, b, c, d, MOD):
    facts, invs = prepare(n, MOD)

    pre = {}
    for i in range(a, b + 1):
        iv = invs[i]
        for k in range(c, d + 1):
            if i * k > n:
                break
            pre[i, k] = pow(iv, k, MOD) * invs[k] % MOD

    dp = [0] * (n + 1)
    dp[n] = 1
    for i in range(a, b + 1):
        iv = invs[i]
        for j in range(i * c, n + 1):
            base = dp[j]
            for k in range(c, d + 1):
                ik = i * k
                if ik > j:
                    break
                dp[j - ik] = (dp[j - ik] + base * pre[i, k]) % MOD
    return dp[0] * facts[n] % MOD


n, a, b, c, d = map(int, input().split())
MOD = 10 ** 9 + 7
print(solve(n, a, b, c, d, MOD))


Measured memory_bytes: 4336
{-# OPTIONS_GHC -funbox-strict-fields #-}
module Main where

import Data.Int
import Control.Monad
import Control.Applicative
import Data.Array.IO

main :: IO ()
main = do
  [n, m] <- map read . words <$> getLine :: IO [Int]
  es <- replicateM m ((\[a, b] -> (a, b)) . map read . words <$> getLine) :: IO [(Int, Int)]
  let len = fromIntegral n :: Int64
  let numOfEdges = len * (len - 1) `div` 2
  uf <- initUf n
  ans <- solve numOfEdges uf 0 [] $ reverse es
  mapM_ print ans

solve :: Int64 -> UnionFind -> Int64 -> [Int64] -> [(Int, Int)] -> IO [Int64]
solve noe uf cnt acc [] = return $ map (noe -) acc
solve noe uf cnt acc ((a, b):edges) = do
  -- update uf
  (uf', isSame) <- sameUf uf a b
  if isSame
  then solve noe uf' cnt (cnt:acc) edges
  else do
    sizeA <- sizeUf uf' a
    sizeB <- sizeUf uf' b
    uf'' <- uniteUf uf' a b
    let cnt' = cnt + fromIntegral (sizeA * sizeB)
    solve noe uf'' cnt' (cnt:acc) edges

-- unionfind

data UnionFind = UnionFind
  { parent :: IOUArray Int Int
  , size :: IOUArray Int Int
  }

initUf :: Int -> IO UnionFind
initUf n = UnionFind
  <$> newListArray (1, n) [1..n]
  <*> newArray (1, n) 1

rootUf :: UnionFind -> Int -> IO (UnionFind, Int)
rootUf uf x = do
  px <- readArray (parent uf) x
  if px == x 
  then return (uf, x)
  else do
    (UnionFind parent' size', rx) <- rootUf uf px
    writeArray parent' x rx
    return (UnionFind parent' size', rx)

sameUf :: UnionFind -> Int -> Int -> IO (UnionFind, Bool)
sameUf uf x y = do
  (uf', rx) <- rootUf uf x
  (uf'', ry) <- rootUf uf' y
  return (uf'', rx == ry)

uniteUf :: UnionFind -> Int -> Int -> IO UnionFind
uniteUf uf x y = do
  (uf', x') <- rootUf uf x
  (uf''@(UnionFind parent' size'), y') <- rootUf uf' y
  if x' == y'
  then return uf''
  else do
    sizeX <- readArray size' x'
    sizeY <- readArray size' y'
    if sizeX < sizeY
    then do
      writeArray parent' x' y'
      writeArray size' y' (sizeX + sizeY)
      return $ UnionFind parent' size'
    else do
      writeArray parent' y' x'
      writeArray size' x' (sizeX + sizeY)
      return $ UnionFind parent' size'
    
sizeUf :: UnionFind -> Int -> IO Int
sizeUf uf x = do
  (UnionFind _ size', x') <- rootUf uf x
  readArray size' x'


Measured memory_bytes: 78204
N,P = map(int,input().split())
ans=1
i=2
if N==1:
  print(P)
  exit()
if N>=40 or P==1:
  print(1)
  exit()
  
while i**N<=P:
  while P%(i**N) == 0:
    ans *= i
    P = P//(i**N)
  if i==2:
    i+=1
  else:
    i+=2
print(ans)

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

public class Main{

	static class FastReader{
		BufferedReader br;
		StringTokenizer st;
		public FastReader(){
			br = new BufferedReader(new InputStreamReader(System.in));
		}
		public String next(){
			try{
				while(st==null||!st.hasMoreElements()){
					st = new StringTokenizer(br.readLine());
				}
			}catch(Exception e){
				e.printStackTrace();
			}
			return st.nextToken();
	
		}
		public int nextInt(){
			return Integer.parseInt(next());
		}
		public long nextLong(){
			return Long.parseLong(next());
		}
		public double nextDouble(){
			return Double.parseDouble(next());
		}
		public String nextLine(){
			String s = "";
			try{
				s = br.readLine();
			}catch(Exception e){
				e.printStackTrace();
			}	
			return s;		
		}
	} 
	
	public static void main(String[] args){
		FastReader in = new FastReader();
		PrintWriter out = new PrintWriter(System.out);
		int sx = in.nextInt();
		int sy = in.nextInt();
		int tx = in.nextInt();
		int ty = in.nextInt();
		for(int i = 0 ; i < ty - sy ; i++){
			out.print("U");
		}
		for(int i = 0 ; i < tx - sx;i++){
			out.print("R");
		}
		for(int i = 0; i < ty-sy;i++){
			out.print("D");
		}
		for(int i = 0; i < tx-sx;i++){
			out.print("L");
		}
		out.print("L");
		for(int i = 0;i<=ty-sy;i++){
			out.print("U");
		}
		for(int i = 0; i <= tx - sx ; i++){
			out.print("R");
		}
		out.print("D");	
		out.print("R");
		for(int i = 0; i <=ty-sy;i++){
			out.print("D");
		}
		for(int i = 0; i<=tx-sx;i++){
			out.print("L");
		}
		out.print("U");
		out.flush();
		out.close();  
	}

}





Measured memory_bytes: 23124