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

using namespace std;
typedef long long ll;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)


class Unionfind
{
    vector<int> p;

public:
    int find(int x);
    void unite(int x, int y);
    Unionfind(int n);
};

Unionfind::Unionfind(int n)
{
    for (int i = 0; i < n; i++)
    {
        p.push_back(i);
    }
}

int Unionfind::find(int x)
{
    while (p[x] != x)
    {
        p[x] = p[p[x]];
        x = p[x];
    }
    return x;
}

void Unionfind::unite(int x, int y)
{
    x = Unionfind::find(x);
    y = Unionfind::find(y);
    if (x != y)
    {
        p[x] = y;
    }
}

int main()
{

#ifdef DEBUG
    cout << "DEBUG MODE" << endl;
    ifstream in("input.txt"); //for debug
    cin.rdbuf(in.rdbuf());    //for debug
#endif

    int n, k, l, x, y;
    cin >> n >> k >> l;
    Unionfind road(n);
    Unionfind rail(n);
    map<pair<int, int>, int> road_rail;
    pair<int, int> parent[n];

    rep(i, k)
    {
        cin >> x >> y;
        road.unite(x - 1, y - 1);
    }

    rep(i, l)
    {
        cin >> x >> y;
        rail.unite(x - 1, y - 1);
    }

    rep(i, n)
    {
        parent[i].first = road.find(i);
        parent[i].second = rail.find(i);
    }

    for (auto x : parent)
    {
        road_rail[x] += 1;
    }

    rep(i, n)
    {
        cout << road_rail[parent[i]];
        if (i != n - 1)
            cout << " ";
    }
    cout << endl;

    return 0;
}


Measured memory_bytes: 15092
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(v) (v).begin(), (v).end()
using ll = long long;
constexpr int INF = 1e9;
constexpr long long LINF = 1e18;
constexpr long long MOD = 1e9 + 7;

signed main() {
    int n, m;
    cin >> n >> m;
    int a[n];
    rep(i, n) {
        cin >> a[i];
        a[i]--;
    }
    ll sum = 0;
    ll imos[2][2 * m + 1];
    fill(imos[0], imos[2], 0);
    rep(i, n - 1) {
        int l = a[i], r = a[i + 1];
        if (l > r) r += m;
        sum += r - l;
        imos[0][l + 2]--;
        imos[0][r + 1]++;
        imos[1][r + 1] += r - l - 1;
    }
    rep(i, 2 * m) {
        imos[0][i + 1] += imos[0][i];
    }
    rep(i, 2 * m) {
        imos[0][i + 1] += imos[0][i];
    }
    rep(i, 2 * m) {
        imos[1][i + 1] += imos[1][i];
    }
    rep(i, 2 * m) {
        imos[1][i] += imos[0][i];
    }
    ll ans = LINF;
    rep(i, m) {
        ans = min(ans, imos[1][i] + imos[1][m + i] + sum);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 7136
//abc096_c_2.cpp
//Sat May 12 20:42:57 2018

#include <iostream>
#include <string>
#include <queue>
#include <unordered_map>
#include <vector>
using namespace std;

int main(){
	int h;
	int w;
	cin >> h;
	cin >> w;

	string row;

	string s[h][w];
	for (int i=0;i<h;i++){
		cin >> row;
		for (int j=0;j<w;j++){
			s[i][j] = row[j];
		}
	}

	int ans = 1;

	for (int i=0;i<h;i++){
		for (int j=0;j<w;j++){
			if (s[i][j] == "#"){
				int flag = 1;
//				cout << "# " << endl;
				if (i>0){
					if (s[i-1][j] == "#"){
						flag = 0;
					}
				}
				if (i<h-1){
					if (s[i+1][j] == "#"){
						flag = 0;
					}
				}
				if (j>0){
					if (s[i][j-1] == "#"){
						flag = 0;
					}
				}
				if (j<w-1){
					if (s[i][j+1] == "#"){
						flag = 0;
					}
				}
				if (flag == 1){
					ans = 0;
				}
			}
		}
	}

	if (ans == 0){
		cout << "No" << endl;
	}else {
		cout << "Yes" << endl;
	}

}

Measured memory_bytes: 384
#include <iostream>
#include <map>
#include <string>

using namespace std;

int main() {
    int left, center, right;
    int count = 0;
    map<char, char> dict;
    string input;
    dict['w'] = 'w';
    dict['i'] = 'i';
    dict['('] = ')';
    dict[')'] = '(';
    cin >> input;
    center = input.length()/2;
    if (input.length()%2 != 0) {
        left = center-1;
        right = center+1;
        if (dict[input[center]] != input[center]) {
            count++;
        }
    }
    else {
        left = center-1;
        right = center;
    }
    for (; left>=0; left--, right++) {
        if (dict[input[left]] != input[right]) {
            count++;
        }
    }
    cout << count << endl;

    return 0;
}

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

int main(void)
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	int a,b;

	cin >> a >> b;

	if((a+b)%2==1)
	{
		cout << (a+b)/2 + 1 << '\n';
	}
	else
	{
		cout << (a+b)/2 << '\n';
	}
	
	return 0;	
}

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

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vpii;
typedef pair<ll,ll> pll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<pll> vpll; 

#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define test() int t;cin>>t;while(t--)
#define all(v) v.begin(),v.end()
#define prinp(p) cout<<p.first<<" "<<p.second<<endl
#define prinv(V) for(auto v:V) cout<<v<<" ";cout<<endl
#define take(V,f,n) for(int in=f;in<f+n;in++) cin>>V[in]
#define what(x) cerr<<#x<<" = "<<x<<endl
#define KStest() int t,t1;cin>>t;t1=t;while(t--)
#define KScout cout<<"Case #"<<t1-t<<": "
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int MOD = 1e9+7,MAX = 1e6+5;
const ll INF = 1e18+5;

int main()
{
	int n;
	cin>>n;
	vi A(n);
	take(A,0,n);
	ll ans=0;
	for(int i=1;i<n;i++)
	{
		if(A[i]<A[i-1])
		{
			ans += A[i-1]-A[i];
			A[i] = A[i-1];
		}
	}
	cout<<ans<<endl;
}	

Measured memory_bytes: 4016
import java.io.*;
import java.util.*;
import java.math.BigInteger;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);

//   String nyuA=sc.nextLine();
  // String nyuB=sc.nextLine();
 
    String[] s=sc.nextLine().split(" ");
//     String[] e=sc.nextLine().split(" ");

//int n=Integer.parseInt(nyuA);

int A=Integer.parseInt(s[0]);
int B=Integer.parseInt(s[1]);
int C=Integer.parseInt(s[2]);
int D=Integer.parseInt(s[3]);

int[] num=new int[105];

for(int i=0;i<num.length;i++){
if(A<=i && i<B)num[i]++;
if(C<=i && i<D)num[i]++;
}
int res=0;
for(int i=0;i<num.length;i++){
if(num[i]==2)res++;
}

System.out.println(res);

//long H=Long.parseLong(t[0]);
//long W=Long.parseLong(t[1]);
//long C=Long.parseLong(t[2]);


	}
}

Measured memory_bytes: 21844
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
using namespace std;
typedef tuple<int, int, int, int> quadruple;

const int MAX_N = 505;

int h, w;
int a[MAX_N][MAX_N];

int main()
{
	ios::sync_with_stdio(false);
	cin >> h >> w;
	for (int y = 0; y < h; y++)
		for (int x = 0; x < w; x++)
			cin >> a[y][x];

	vector<quadruple> result;
	result.reserve(h * w);
	for (int y = 0; y < h; y++)
	{
		for (int x = (y % 2 == 0 ? 0 : w - 1); (y % 2 == 0 && x < w) || (y % 2 != 0 && x >= 0); x += (y % 2 == 0 ? 1 : -1))
		{
			if (a[y][x] % 2 != 0)
			{
				int nextY, nextX;
				if ((y % 2 == 0 && x == w - 1) || (y % 2 != 0 && x == 0))
				{
					nextY = y + 1;
					nextX = x;
				}
				else
				{
					nextY = y;
					nextX = x + (y % 2 == 0 ? 1 : -1);
				}
				if (nextY < h && nextX >= 0 && nextX < w)
				{
					result.emplace_back(y + 1, x + 1, nextY + 1, nextX + 1);
					a[y][x]--;
					a[nextY][nextX]++;
				}
			}
		}
	}

	cout << result.size() << endl;
	for (const auto& q : result)
		cout << get<0>(q) << " " << get<1>(q) << " " << get<2>(q) << " " << get<3>(q) << endl;
}

Measured memory_bytes: 6912
'use strict'

function Main(input){
  let baseStr = input.toString();
  const isGood = (a,b) =>{
    return a != b ? true : false
  }

  isGood(baseStr.slice(0,1),baseStr.slice(1,2)) && isGood(baseStr.slice(1,2),baseStr.slice(2,3)) && isGood(baseStr.slice(2,3),baseStr.slice(3,4)) ? console.log("Good") : console.log("Bad");

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

Measured memory_bytes: 21064
#include <iostream>
#include <iomanip>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <array>
#include <tuple>
#include <string>
#include <algorithm>
#include <functional> // greater など
#include <cmath>      // abs など
#include <numeric>    // accumulate, gcd など
#include <cassert>    // assert
#include <stdexcept>
#include <bitset>
using namespace std;

// #include <boost/multiprecision/cpp_int.hpp>
// using namespace boost::multiprecision;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
// typedef int128_t ll;
// typedef cpp_int ll;

// GCC, 配列のアクセスなど
#define _GLIBCXX_DEBUG
// Clang, 配列のアクセスなど
#define _LIBCPP_DEBUG 0

//////////////// //////////////// //////////////// //////////////// ////////////////
//////////////// //////////////// //////////////// //////////////// ////////////////

constexpr inline ll mod = 1'000'000'007;

constexpr inline int max_n = 100'000 + 5;
vector<ll> xs(max_n + 1); // xs[d] = #{ d % gcd == 0 }
vector<ll> ys(max_n + 1); // ys[d] = #{ d == gcd }

ll modpow(ll x, int y) {
    if (y == 0) { return 1; }
    if (y % 2 == 0) {
        ll res = modpow(x, y/2);
        return res * res % mod;
    } else {
        return modpow(x, y-1) * x % mod;
    }
}

int main()
{
    // 高速な入出力
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << setprecision(15); // 浮動小数の表示の精度

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

    ll res = 0;
    for (int d = 1; d <= k; d++) {
        ll c = k / d; // 倍数の個数
        xs[d] = modpow(c, n);
    }
    for (int d = k; d >= 1; d--) {
        ys[d] = xs[d];
        for (int i = 2; d * i <= k; i++) {
            int d2 = d * i;
            ys[d] -= ys[d2] - mod;
            ys[d] %= mod;
        }
    }
    for (int d = 1; d <= k; d++) {
        res += d * ys[d];
        res %= mod;
    }
    cout << res << endl;

    return 0;
}


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

 char getGrade( int m, int f, int r ){
  int sum = m + f;
  char grade;
   if ( m == -1 || f == -1 ){
     grade = 'F';
   } else if (80 <= sum ){
     grade = 'A';
   } else if ( 65 <= sum && sum < 80 ){
     grade = 'B';
   } else if ( 50 <= sum && sum < 65 ){
     grade = 'C';
   } else if ( 30 <= sum && sum < 50 ){
     if ( 50 <= r ) grade = 'C';
       else grade = 'D';
   } else if ( sum < 30 ){
     grade = 'F';
   }
 
   return grade;
 }

int main(){
 int m,f,r;
  while(1){
   cin >> m >> f >> r;
   if ( m == -1 && f == -1 && r == -1 ) break;
   cout << getGrade( m, f, r ) << endl;
  }
  
  return 0;
}

Measured memory_bytes: 1152
#include <bits/stdc++.h>
using namespace std;
int main(){
  int d;
  cin>>d;
  for(int j=0;j<d;j++){

  int n,r0=0,r1=0,a[100];
  cin>>n;
  for(int i=0;i<n;i++) cin>>a[i];
  for(int i=0;i<n-1;i++){
    int x=a[i+1]-a[i];
    if(x>0) r0=max(r0,x);
    else r1=max(r1,-x);
  }
  cout<<r0<<" "<<r1<<endl;

  }
  return 0;
}

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

using namespace std;

int main(){
  int mn1,mn2, sum;
  int a[3];
  int b[3];
  for(int i=0;i<3;i++){
    cin >> a[i];
  }

  for(int i=0;i<2;i++){
    cin >> b[i];
  }
  mn1 =2000;

  mn2=2000;
  
  for(int i=0;i<3;i++){
    if(a[i] < mn1) mn1 = a[i];
  }

  for(int i=0;i<2;i++){
    if(b[i] < mn2) mn2 = b[i];
  }


  sum = mn1 + mn2 -50;

  cout << sum << endl;
  return 0;
}


Measured memory_bytes: 3100
#include <iostream>
#include <math.h>
#include <stack>
using namespace std;

long long conv2_753(long long n) {
  stack<long long> tmp;
  while (n > 0) {
    tmp.push(n % 4);
    n /= 4;
  }
  long long result = 0;
  bool t_0 = false;
  bool t_3 = false;
  bool t_5 = false;
  bool t_7 = false;
  while (!tmp.empty()) {
    result *= 10;
    long long t = tmp.top();
    if (t == 1) {
      result += 3;
      t_3 = true;
    } else if (t == 2) {
      result += 5;
      t_5 = true;
    } else if (t == 3) {
      result += 7;
      t_7 = true;
    } else
      t_0 = true;
    tmp.pop();
  }
  if (!t_0 && t_3 && t_5 && t_7)
    return result;
  return 0;
}

int main() {
  long N;
  cin >> N;

  long long count = 0, result = 0;
  while (true) {
    long long tmp = conv2_753(count);
    if (tmp > N)
      break;
    if (tmp != 0) {
      result++;
      // cout << tmp << endl;
    }
    count++;
  }
  cout << result << endl;
}

Measured memory_bytes: 256
#[allow(unused_imports)]
use std::cmp::{Ordering};

#[allow(unused_imports)]
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};

#[allow(unused_imports)]
use std::io::{stdin, stdout, BufWriter, Write};

#[allow(unused_imports)]
use std::iter::FromIterator;

#[allow(unused_macros)]
macro_rules! min {
    ($x: expr) => ($x);
    ($x: expr, $($z: expr),+) => {{
        std::cmp::min($x, min!($($z),*))
    }}
}

#[allow(unused_macros)]
macro_rules! max {
    ($x: expr) => ($x);
    ($x: expr, $($z: expr),+) => {{
        std::cmp::max($x, max!($($z),*))
    }}
}

#[allow(unused_macros)]
macro_rules! get { 
    ([$t: ty]) => { 
        { 
            let mut line = String::new(); 
            stdin().read_line(&mut line).unwrap(); 
            line.split_whitespace().map(|t|t.parse::<$t>().unwrap()).collect::<Vec<_>>()
        }
    };
    ([$t: ty];$n: expr) => {
        (0..$n).map(|_|get!([$t])).collect::<Vec<_>>()
    };
    ($t: ty) => {
        {
            let mut line = String::new();
            stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t: ty),*) => {
        { 
            let mut line = String::new();
            stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            ($(iter.next().unwrap().parse::<$t>().unwrap(),)*)
        }
    };
    ($t: ty; $n: expr) => {
        (0..$n).map(|_|get!($t)).collect::<Vec<_>>()
    };
    ($($t: ty),*; $n: expr) => {
        (0..$n).map(|_|get!($($t),*)).collect::<Vec<_>>()
    };
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        #[cfg(debug_assertions)]
        writeln!(&mut std::io::stderr(), concat!("[DEBUG] ", $(stringify!($a), "={:?} "),*), $($a),*).unwrap();
    }
}

const BIG_STACK_SIZE: bool = true;

#[allow(dead_code)]
fn main() {
    use std::thread;
    if BIG_STACK_SIZE {
        thread::Builder::new()
            .stack_size(32 * 1024 * 1024)
            .name("solve".into())
            .spawn(solve)
            .unwrap()
            .join()
            .unwrap();
    } else {
        solve();
    }
}

fn solve() {
    let n = get!(usize);
    if n % 2 == 0 {
        println!("{}", n/2-1);
    } else {
        println!("{}", n/2);
    }
}


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

int main(){
  ll N,K,ans=0;
  cin >> N >> K;
  if(N<=K) ans=0;
  else{
    vector<ll> H(N);
    rep(i,N) {
      cin >> H[i];
    }
    sort(H.begin(),H.end());
    rep(i,N-K) {
      ans+=H[i];
    }
  }
  
  cout << ans << endl;
  return 0; 
}

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

using namespace std;

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

#define MOD 1000000007
#define REP(i, N) for (int i = 0; i < N; ++i)
#define REP1(i, N) for (int i = 1; i <= N; ++i)
#define RREP(i, N) for (int i = N - 1; i >= 0; --i)
#define ALL(a) a.begin(), a.end()

int main() {
  ll q, h, s, d, n;
  cin >> q >> h >> s >> d >> n;
  ll one = min(min(4 * q, 2 * h), s);
  ll two = min(2 * one, d);
  cout << (n / 2) * two + (n % 2) * one << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define lsn l,mid,rt<<1
#define rsn mid+1,r,rt<<1|1
const int N = 100005;
int a[N], tree[N<<2], l[N], r[N];
int n, m;
pair<int, int>pos[N];
int ans = 0;
/*
void build(int l, int r, int rt){
    if(l == r){
        tree[rt] = a[l];
        pos[rt] = l;
        return;
    }
    int mid = (l + r) >> 1;
    build(lsn);
    build(rsn);
    if(tree[rt<<1] >= tree[rt<<1|1]){
        tree[rt] = max(tree[rt<<1], tree[rt<<1|1]);
        pos[rt] = pos[rt<<1];
    }else{
        tree[rt] = max(tree[rt<<1], tree[rt<<1|1]);
        pos[rt] = pos[rt<<1|1];
    }
}
pair<int, int> query(int l, int r, int rt, int L, int R){
    if(l > R || r < L) return make_pair(0, 0);
    if(l == r){
        return make_pair(tree[rt], pos[rt]);
    }
    pair<int, int>ans, tmp;
    int mid = (l + r) >> 1;
    if(L <= mid){
        tmp = query(lsn, L, R);
        ans = tmp;
    }
    if(R >= mid+1){
        tmp = query(rsn, L, R);
        if(tmp.first > ans.first){
            ans = tmp;
        }
    }
    return ans;
}
*/
int main(){
    scanf("%d%d", &n, &m);
    for(int i = 1; i <= m; ++i){
        scanf("%d%d", l+i, r+i);
        if(l[i] > r[i]) swap(l[i], r[i]);
        pos[i] = make_pair(r[i], l[i]);
    }
    sort(pos+1, pos+m+1);
    //for(int i = 1; i <= m; ++i) cout << pos[i].first << " " << pos[i].second << endl;
    int last;
    for(int i = 1; i <= m; ++i){
        if(i == 1){
            last = pos[i].first;
            ans++;
        }else{
            if(pos[i].second < last) continue;
            else{
                last = pos[i].first;
                ans++;
            }
        }
    }
    printf("%d\n", ans);
    return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define INF 2e9
using namespace std;
typedef long long llong;
typedef long double ldouble;
int main()
{
  cout<<fixed<<setprecision(10);
  int A, B;
  cin >> A >> B;
  if(B%A==0) cout << A+B << endl;
  else cout << B-A << endl;
}

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

int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};


typedef struct{
	char mp[10][10];
}M;
M zero,flg,ch;

vector<string>V;
void init(string s){
	if(s.size()==5){
		V.push_back(s);
		return;
	}
	for(char c='1';c<='6';c++){
		init(s+c);
	}
}

void saiki(int x,int y){
	if(flg.mp[x][y]=='0'){
		flg.mp[x][y]='1';
		for(int i=0;i<4;i++){
			if(ch.mp[x][y]==ch.mp[x+dx[i]][y+dy[i]] && flg.mp[x+dx[i]][y+dy[i]]=='0'){
				saiki(x+dx[i],y+dy[i]);
			}
		}
	}
}

void draw(char c){
	for(int i=0;i<100;i++){
		if(flg.mp[i/10][i%10]=='1'){
			ch.mp[i/10][i%10]=c;
		}
	}
}

int cnt(){
	int p=0;
	for(int i=0;i<100;i++){
		if(flg.mp[i/10][i%10]=='1'){
			p++;
		}
	}
	return p;
}


int main(){
	init("");
	
	for(int i=0;i<100;i++)zero.mp[i/10][i%10]='0';
	
	for(int h,w,c;cin>>h>>w>>c,c;){
		int ans=0;
		M in = zero;
		for(int i=1;i<=h;i++){
			for(int j=1;j<=w;j++){
				cin>>in.mp[j][i];
			}
		}
		for(int i=0;i<V.size();i++){
			M tmp=in;
			M tmp2=tmp;
			for(int j=0;j<V[i].size();j++){
				flg=zero;
				ch=tmp;
				saiki(1,1);
				draw(V[i][j]);
				tmp=ch;
			}
			
			
			
			flg=zero;
			ch=tmp;
			saiki(1,1);
			if(ch.mp[1][1]==(c+'0')){
				ans=max(ans,cnt());
			}
		}
		cout<<ans<<endl;
	}
	
	return 0;
}


Measured memory_bytes: 1536
import sys
sys.setrecursionlimit(10**7)

def input(): return sys.stdin.readline()[:-1]
mod = 10**9 + 7
def readInt():return int(input())
def readIntList():return list(map(int,input().split()))
def readStringList():return list(input())
def readStringListWithSpace():return list(input().split())
def readString():return input()

a,b,c,d = readIntList()

res = max(a*d,a*c,b*c,b*d)
print(res)

Measured memory_bytes: 9192
import numpy as np
from collections import defaultdict
from functools import reduce

# s = input()
# n = int(input())
# A = list(map(int, input().split()))
n, m = map(int, input().split())
A = sorted(list(map(int, input().split())))

C = []

for i in range(m):
    b, c = map(int, input().split())
    C.append((c,b))

C.sort(reverse=True)

# print(A)
# print(C)

res = 0

a_idx = 0
c_idx = 0

while c_idx < m:
  c, b = C[c_idx]
  while b > 0 and a_idx < n:
    a = A[a_idx]
    if a < c:
      a_idx += 1
      res += c
      b -= 1
    else:
      break
  c_idx += 1

for i in range(a_idx, n):
  res += A[i]


print(res)


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

int main() {
	int N; 
	cin >> N;
	vector<int>A(8);
	int count = 0;
	for (int i = 0;i<N;++i) {
		int num;
		cin >> num;
		if (num < 3200) {
			A[num / 400]++;
		}
		else {
			count++;
		}
	}

	int ans = 0;
	for (int i = 0;i<8;++i) {
		if (A[i]>0) {
			ans++;
		}
	}
	if (0 != ans) {
		cout << ans << " " << ans + count << endl;
	}
	else {
		cout << 1 << " " << ans + count << endl;
	}
	return 0;
}

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

using namespace std;
using ll = int64_t;
using pii = pair<int, int>;
using pli = pair<ll, int>;
using mii = map<int, int>;
using vi = vector<int>;
using vii = vector<vi>;
using vl = vector<ll>;
using vll = vector<vl>;
using tpi = tuple<int, int, int>;

using vqi = vector<queue<int>>;
using vpi = vector<pii>;
using bs = bitset<60>;
using vbi = vector<bs>;

ll gcd(ll a, ll b) {
    if (a < b) {
        swap(a, b);
    }

    /* ユークリッドの互除法 */
    ll r = a % b;
    while (r != 0) {
        a = b;
        b = r;
        r = a % b;
    }
    return b;
}

ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

constexpr int64_t __pow_mod(int64_t n, int64_t p, int64_t mod) noexcept {
    if (p == 0) {
        return 1;
    }
    if (p % 2 == 0) {
        int64_t t = __pow_mod(n, p / 2, mod);
        return (t * t) % mod;
    }
    return (n * (__pow_mod(n, p - 1, mod) % mod)) % mod;
}

constexpr int64_t pow_mod(int64_t n, int64_t p, int64_t mod) noexcept {
    int64_t res = __pow_mod(n, p, mod);
    if (res == 0) {
        res = mod;
    }
    return res;
}

constexpr int64_t nCr_mod(int64_t n, int64_t r, int64_t mod) noexcept {
    int64_t count = 1;
    auto a = r;
    for (auto i = n; i > n - r; i--) {
        count *= i;
        if (count % mod != 0) {
            count %= mod;
        }
        int64_t inv = pow_mod(a, mod - 2, mod);
        count *= inv;
        if (count % mod != 0) {
            count %= mod;
        }
        a--;
    }
    return count;
}

void solve(long long N) {
    set<ll> answers;

    if (N == 2) {
        cout << 1 << endl;
        return;
    }

    for (ll p = 2; p <= sqrt(N); p++) {
        if (N % p == 0) {
            ll nn = N;
            while (nn % p == 0) {
                nn /= p;
            }
            if (nn % p == 1) {
                answers.insert(p);
            }

            nn = N;
            ll inv_p = N / p;
            while (nn % inv_p == 0) {
                nn /= inv_p;
            }
            if (nn % inv_p == 1) {
                answers.insert(inv_p);
            }
        }
        if ((N - 1) % p == 0) {
            answers.insert(p);
            answers.insert((N - 1) / p);
        }
    }
    answers.insert(N);
    answers.insert(N - 1);
    cout << answers.size() << endl;
}

int main() {
    long long N;
    std::cin >> N;
    solve(N);
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;
typedef vector<ll> vll;
#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 pb push_back
#define eb emplace_back
#define fi first
#define se second
#define sz(x) ((int)(x).size())
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define INF 1000000000
#define MOD 1000000007

void solve() {
    int N, W;
    cin >> N >> W;
    vi w(N), v(N);
    rep(i,0,N) {
        cin >> w[i] >> v[i];
    }
    unordered_map<int, ll> dp;
    rep(i,0,N) {
        per(j,0,W+1) {
            if (j>=w[i]) {
                dp[j] = max(dp[j], dp[j-w[i]] + v[i]);
            }
        }
    }
    cout << dp[W];
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    int t = 1;
    // cin >> t;
    while (t--)
        solve();
    return 0;
}


Measured memory_bytes: 7292
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LS()
    return l
sys.setrecursionlimit(1000000)
mod = 1000000007

#A
def A():
    n = S()
    for i in n:
        if i == "1":
            print(9,end = "")
        else:
            print(1,end = "")
    print()
#B
def B():
    n = I()
    for i in range(n,1000):
        if i%111 == 0:
            print(i)
            quit()
    return

#C
def C():
    return

#D
def D():
    return

#E
def E():
    return

#F
def F():
    return

#G
def G():
    return

#H
def H():
    return

#Solve
if __name__ == "__main__":
    B()


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

#define what_is(x)    cerr<<#x<<" is "<<x<<"\n";
#define rep(i,a,n)    for(int i=a; i<=n; ++i)
#define rep1(i,a,n)   for(int i=a; i>=n; --i)
#define pb            push_back
#define mp            make_pair
#define int           long long
#define fr            first
#define sc            second
#define vc            vector
#define sz(v)         (int)v.size()
#define all(x)        (x).begin(),(x).end()
#define rall(x)       (x).rbegin(),(x).rend()
#define M             1000000007
#define MM            998244353
#define PI            3.14159265358979
#define INF           1000000000000000

typedef vector<int> vi;
typedef pair<int,int> pii;
typedef map<int,int> mii;

int n,m,ans; string str;

int m1,m2=INF;
int solve(){
    cin>>n>>m;
    rep(i,1,m){
        int a,b; cin>>a>>b;
        m1=max(m1,a);
        m2=min(m2,b);
    }
    cout<<max(m2-m1+1,0ll);
    return 0;
}

signed main() {
    ios::sync_with_stdio(0);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    int t=1;
    //cin>>t;
    while(t--) solve();
    return 0;
}

Measured memory_bytes: 256
"use strict";
var input = require("fs").readFileSync("/dev/stdin", "utf8");
var cin = input.trim().split(/ |\n/), cid = 0;

console.log(main());

function main() {
    var n = +cin.shift();
    if (cin.indexOf('0') >= 0) return 0;
    let ans = 1n;
    let max = BigInt(10) ** BigInt(18);
    for (let i = 0; i < n; i++) {
        ans = ans * BigInt(cin.shift());
        if (ans > max) return -1;
    }
    return ans.toString();
}

Measured memory_bytes: 40660
#include<iostream>
using namespace std;
int main()
{
int date,month,day;
while(cin>>month>>date&&month!=0)
{	
switch(month)
{
case 1:
switch(date%7)
{
case 1:
day=4;
break;
case 2:
day=5;
break;
case 3:
day=6;
break;
case 4:
day=7;
break;
case 5:
day=1;
break;
case 6:
day=2;
break;
case 0:
day=3;
break;
}
break;
case 2:
switch(date%7)
{
case 1:
day=7;
break;
case 2:
day=1;
break;
case 3:
day=2;
break;
case 4:
day=3;
break;
case 5:
day=4;
break;
case 6:
day=5;
break;
case 0:
day=6;
break;
}
break;
case 3:
switch(date%7)
{
case 1:
day=1;
break;
case 2:
day=2;
break;
case 3:
day=3;
break;
case 4:
day=4;
break;
case 5:
day=5;
break;
case 6:
day=6;
break;
case 0:
day=7;
break;
}
break;
case 4:
switch(date%7)
{
case 1:
day=4;
break;
case 2:
day=5;
break;
case 3:
day=6;
break;
case 4:
day=7;
break;
case 5:
day=1;
break;
case 6:
day=2;
break;
case 0:
day=3;
break;
}
break;
case 5:
switch(date%7)
{
case 1:
day=6;
break;
case 2:
day=7;
break;
case 3:
day=1;
break;
case 4:
day=2;
break;
case 5:
day=3;
break;
case 6:
day=4;
break;
case 0:
day=5;
break;
}
break;
case 6:
switch(date%7)
{
case 1:
day=2;
break;
case 2:
day=3;
break;
case 3:
day=4;
break;
case 4:
day=5;
break;
case 5:
day=6;
break;
case 6:
day=7;
break;
case 0:
day=1;
break;
}
break;
case 7:
switch(date%7)
{
case 1:
day=4;
break;
case 2:
day=5;
break;
case 3:
day=6;
break;
case 4:
day=7;
break;
case 5:
day=1;
break;
case 6:
day=2;
break;
case 0:
day=3;
break;
}
break;
case 8:
switch(date%7)
{
case 1:
day=7;
break;
case 2:
day=1;
break;
case 3:
day=2;
break;
case 4:
day=3;
break;
case 5:
day=4;
break;
case 6:
day=5;
break;
case 0:
day=6;
break;
}
break;
case 9:
switch(date%7)
{
case 1:
day=3;
break;
case 2:
day=4;
break;
case 3:
day=5;
break;
case 4:
day=6;
break;
case 5:
day=7;
break;
case 6:
day=1;
break;
case 0:
day=2;
break;
}
break;
case 10:
switch(date%7)
{
case 1:
day=5;
break;
case 2:
day=6;
break;
case 3:
day=7;
break;
case 4:
day=1;
break;
case 5:
day=2;
break;
case 6:
day=3;
break;
case 0:
day=4;
break;
}
break;
case 11:
switch(date%7)
{
case 1:
day=1;
break;
case 2:
day=2;
break;
case 3:
day=3;
break;
case 4:
day=4;
break;
case 5:
day=5;
break;
case 6:
day=6;
break;
case 0:
day=7;
break;
}
break;
case 12:
switch(date%7)
{
case 1:
day=3;
break;
case 2:
day=4;
break;
case 3:
day=5;
break;
case 4:
day=6;
break;
case 5:
day=7;
break;
case 6:
day=1;
break;
case 0:
day=2;
break;
}
break;
}
switch(day)
{
case 1:
cout<<"Monday"<<endl;
break;
case 2:
cout<<"Tuesday"<<endl;
break;
case 3:
cout<<"Wednesday"<<endl;
break;
case 4:
cout<<"Thursday"<<endl; 
break;
case 5:
cout<<"Friday"<<endl;
break;
case 6:
cout<<"Saturday"<<endl;
break;
case 7:
cout<<"Sunday"<<endl;
break;
}
}
return 0;
}

Measured memory_bytes: 3096
/*input
cabacc
abc
*/

#include <bits/stdc++.h>
using namespace std; 
#define int long long int
// #define max(x, y) ((x) > (y) ? (x) :(y))
#define pii pair< int , int> 
#define vi vector<int>
#define fore( i ,st) for ( int i= 0 ; i < (int)(st) ; i ++)
#define REP( i , st , en ) for ( int i =st; i < (int)en; i++)
#define REPD( i , en , st ) for ( int i =en; i >= (int)st; i--)
#define SZ(a) (int)a.size()
#define all(v) v.begin() , v.end()
#define pb push_back
#define F first
#define S second
#define bug(x) cout <<__LINE__ << ":"<<__FILE__ << " : " <<   #x  << " = " << x << "\n";
#define bitch_i_m_on_fiyaah_yeahhhh ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
const int mod = 1e9+7;
ostream& operator << ( ostream&  o, vector<int> s){for ( int i = 0;  i < (int)s.size() ; i++)o << s[i] << " ";o << "\n";return o;}
int  add( int a, int b){int c = a + b; if ( a> mod ) a-= mod; return c;}
void sub( int &a, int b){a = a - b;if ( a < 0) a += mod;}
int mul( int a , int b){return ((a %mod) * (b %mod) ) %mod;}
int exp( int a , int pow){ return (pow == 0 ? 1 : ( pow & 1  ? mul ( a ,exp( mul(a, a) , pow /2) ) : exp(mul(a ,a) , pow/2)));}
int gcd(int a, int b) { return b ? gcd(b, a%b) : a; }
// void in( vector<int> &v){for (int i=0;i<(int)v.size();i++)cin>>v[i];}
// void in(int &n) {cin >> n; }

const int maxn = 2e5 +5;


void solve( int test){
	
	
	string s ,t;
	cin >> s >> t;
	int ans =INT_MAX;
	fore( i , SZ(s)){
		int coo =0;
		if ( i + SZ(t)-1 >= SZ(s)) break;
		for ( int j =0 ; j < SZ(t); j++){
			if ( s[i+j] != t[j]){
				coo++;
			}
		}
		ans = min( ans , coo);
	}
	cout << ans;
	


}
signed main(){
	bitch_i_m_on_fiyaah_yeahhhh
	int t =1; 
	// cin >> t;
	for ( int i = 0 ; i < t; i++)
		solve(i+1);
}

Measured memory_bytes: 3648
import copy

# a = get_int()
def get_int():
    return int(input())

# a = get_string()
def get_string():
    return input()

# a_list = get_int_list()
def get_int_list():
    return [int(x) for x in input().split()]

# a_list = get_string_list():
def get_string_list():
    return input().split()

# a, b = get_int_multi()
def get_int_multi():  # a, b = get_int_multi()
    return map(int, input().split())

# a_list = get_string_char_list()
def get_string_char_list():
    return list(str(input()))

# print("{} {}".format(a, b))
# for num in range(0, a):
# a_list[idx]
# a_list = [0] * a
'''
while (idx < n) and ():

    idx += 1
'''

def main():
    n, k = get_int_multi()
    a_list = get_int_list()

    for i in range(0, n-k):
        if a_list[i] < a_list[k+i]:
            print("Yes")
        else:
            print("No")




if __name__ == '__main__':
    main()




Measured memory_bytes: 31892
#include <iostream>
#include <vector>
#include <cmath>
#include <iomanip>
#include <queue>
#include <algorithm>
#define shosu(x) fixed<<setprecision(x)
using namespace std;
typedef pair<int,int> P;
const int inf=1<<30;
const double pi=acos(-1);

class Dijkstra{
	private:
		struct edge{
			int to,cost;
		};
		int V;
		vector<vector<edge> > G;
	public:
		vector<int> d;
		Dijkstra(int x){
			V=x;
			G=vector<vector<edge> >(x);
		}
		void add_edge(int x,int y,int z){
			edge tmp={y,z};
			G[x].push_back(tmp);
		}
		void dijkstra(int s){
			priority_queue<P> que;
			d=vector<int>(V,inf);
			d[s]=0;
			que.push(P(0,s));
			while(!que.empty()){
				P p=que.top();
				que.pop();
				int v=p.second;
				if(d[v]<-1*p.first) continue;
				for(int i=0;i<G[v].size();i++){
					edge e=G[v][i];
					if(d[e.to]>d[v]+e.cost){
						d[e.to]=d[v]+e.cost;
						que.push(P(-1*d[e.to],e.to));
					}
				}
			}
		}
};

int v,e,r;

int main(){ 
	cin>>v>>e>>r;
	Dijkstra dij(v);
	for(int i=0;i<e;i++){
		int a,b,c;
		cin>>a>>b>>c;
		dij.add_edge(a,b,c);
	}
	dij.dijkstra(r);
	for(int i=0;i<v;i++){
		if(dij.d[i]==inf) cout<<"INF"<<endl;
		else cout<<dij.d[i]<<endl;
	}
}

Measured memory_bytes: 11844
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define sz(x) (int)(x.size())
#define fi first
#define se second
#define x se.fi
#define y se.se
#define pii pair<int, int>
const int N = 2e5 + 10;

signed main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    int n;
    cin >> n;
    vector<pair<int, pii>> a(n + 1);
    a[0] = {0ll, {0ll, 0ll}};
    for(int i = 1; i <= n; i++) {
        cin >> a[i].fi >> a[i].se.fi >> a[i].se.se;
    }
    bool ans = true;
    for(int i = 1; i <= n; i++) {
        int diff = abs(a[i].x - a[i - 1].x) + abs(a[i].y - a[i - 1].y);
        int t_diff = a[i].fi - a[i - 1].fi;
        if(diff > t_diff) {
            ans = false;
        }else if((t_diff - diff) % 2 == 1){
            ans = false;
        }
    }
    if(ans) {
        cout << "Yes\n";
    }else {
        cout << "No\n";
    }
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
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;
typedef vector<ll> vll;
typedef vector<ld> vld;
typedef vector<pll> vpl;

#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define FI first
#define SE second
#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 FOR(i,a,b) for(int i=(a);i<(b);i++)
#define PB push_back
#define EB emplace_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 yes cout<<"Yes"<<endl
#define YES cout<<"YES"<<endl
#define no cout<<"No"<<endl
#define NO cout<<"NO"<<endl
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL

const int inf = 1e9;
const ll linf = 1LL << 50;
const double eps = 1e-10;
const int MOD = 1e9 + 7;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};

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

  ll n,k;
  cin>>n>>k;
  n%=k;

  ll ans=min(n,k-n);
  cout<<ans<<endl;
}



Measured memory_bytes: 256
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

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

//constant
//--------------------------------------------
const double PI  = acos(-1.0);

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
int main(){
    int a , b, c, x, cnt=0, tmp;
    cin >> a >> b >> c>> x;
   REP(i,a+1){
       REP(j,b+1){
           REP(k,c+1){
               tmp=i*500+j*100+k*50;
               if(tmp==x) cnt++;
           }
       }
   }
    cout << cnt << endl;
}

Measured memory_bytes: 256
from collections import deque
import sys
def main():
    readline = sys.stdin.readline
    write = sys.stdout.write
    W, H = map(int, readline().split())
    MP = [readline() for i in range(H)]
    A = [[-1]*W for i in range(H)]
    B = [[-1]*W for i in range(H)]
    C = [[0]*W for i in range(H)]
    SW0 = 'ABCDEFGHIJ'
    SW1 = 'abcdefghij'
    for i, mp in enumerate(MP):
        Ai = A[i]; Bi = B[i]
        for j, c in enumerate(mp):
            if c == '#':
                continue
            if c in '^' or c in SW0:
                Ai[j] = 1
                if c != '^':
                    Bi[j] = SW0.index(c)+1
            elif c in '_%&' or c in SW1:
                Ai[j] = 0
                if c == '%':
                    sx = j; sy = i
                elif c == '&':
                    gx = j; gy = i
                elif c != '_':
                    Bi[j] = SW1.index(c)+1
            elif c == '|':
                Bi[j] = 0
                Ai[j] = 2
    S = int(readline())
    for k in range(S):
        MP = [readline() for i in range(H)]
        for i, mp in enumerate(MP):
            Ci = C[i]
            for j, c in enumerate(mp):
                if c == '*':
                    Ci[j] |= (2 << k)

    dist = [[{} for i in range(W)] for j in range(H)]
    dist[sy][sx][0] = 0
    dd = ((-1, 0), (0, -1), (1, 0), (0, 1))
    bc = [0]*(2 << S)
    for i in range(1, 2 << S):
        bc[i] = bc[i ^ (i & -i)] ^ 1
    que = deque([(0, sx, sy, 0)])
    while que:
        state, x, y, d = que.popleft()
        if B[y][x] == 0:
            if state^1 not in dist[y][x]:
                dist[y][x][state^1] = d+1
                que.append((state^1, x, y, d+1))
        elif B[y][x] != -1:
            n_state = state ^ (1 << B[y][x]) ^ (state & 1)
            n_state ^= bc[n_state & C[y][x]] ^ A[y][x]
            if n_state not in dist[y][x]:
                dist[y][x][n_state] = d+1
                que.append((n_state, x, y, d+1))
        for dx, dy in dd:
            nx = x + dx; ny = y + dy
            if not 0 <= nx < W or not 0 <= ny < H or A[ny][nx] == -1:
                continue
            if A[ny][nx] == 2:
                if state not in dist[ny][nx]:
                    dist[ny][nx][state] = d+1
                    que.append((state, nx, ny, d+1))
            else:
                np = bc[state & C[ny][nx]] ^ A[ny][nx]
                if state&1 == np and state not in dist[ny][nx]:
                    dist[ny][nx][state] = d+1
                    que.append((state, nx, ny, d+1))
    if dist[gy][gx]:
        write("%d\n" % min(dist[gy][gx].values()))
    else:
        write("-1\n")
main()


Measured memory_bytes: 100688
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<int,int> Pi;
#define rep(i,n) for(ll i=0;i<n;i++)
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define fi first
#define se second
#define endl "\n"

template<typename T> inline bool chmax(T &a, T b){if(a<b){a=b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if(a>b){a=b;return true;}return false;}
template<typename T> ostream& operator<<(ostream& s,const complex<T>& d) {return s<<"("<<d.real()<<", "<<d.imag()<< ")";}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const pair<T1,T2>& d) {return s<<"("<<d.first<<", "<<d.second<<")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& d){int len=d.size();rep(i,len){s<<d[i];if(i<len-1) s<<" ";}return s;}
template<typename T> ostream& operator<<(ostream& s,const vector<vector<T>>& d){int len=d.size();rep(i,len){s<<d[i]<<endl;}return s;}
template<typename T> ostream& operator<<(ostream& s,const set<T>& v){s<<"{ ";for(auto itr=v.begin();itr!=v.end();++itr) {if (itr!=v.begin()) {s<< ", ";}s<<(*itr);}s<<" }";return s;}
template<typename T> ostream& operator<<(ostream& s,const multiset<T>& v){s<<"{ ";for(auto itr=v.begin();itr!=v.end();++itr) {if (itr!=v.begin()) {s<< ", ";}s<<(*itr);}s<<" }";return s;}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const map<T1,T2>& m){s<<"{"<<endl;for(auto itr=m.begin();itr!=m.end();++itr){s<<" "<<(*itr).first<<" : "<<(*itr).second<<endl;}s<<"}"<<endl;return s;}

const ll mod=1'000'000'007;
const ll inf=1'000'000'000'000'000'00;
const int INF=1'000'000'000;
const double EPS=1e-10;
const double PI=acos(-1);

int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    string s;
    cin>>s;
    ll k;
    cin>>k;
    rep(i,s.size()){
        if(i+1==k){
            cout<<s[i]<<endl;
            return 0;
        }
        if(s[i]!='1'){
            cout<<s[i]<<endl;
            return 0;
        }
    }
    cout<<1<<endl;
}

Measured memory_bytes: 3644
from operator import itemgetter

N = int(input())
AB = sorted([list(map(int, input().split())) for i in range(N)], key=itemgetter(1))

time = 0

for A, B in AB:
    if time + A <= B:
        time += A
    else:
        print('No')
        break
else:
    print('Yes')

Measured memory_bytes: 55268
N, x = map(int, input().split())
a = list(map(int, input().split()))
y = x
a = sorted(a)
ans = 0

for i in a:
    if y >= i:
        ans += 1
        y -= i
    else:
        break

if x > sum(a):
    ans -= 1
print(ans)

Measured memory_bytes: 38384
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using pint = pair<int,  int>;
using pll = pair<ll, ll>;
using edge = pair<int, ll>;
using Graph = vector<vector<int>>; 
using WeightedGraph = vector<vector<edge>>;
const ll INF = 1LL << 60;
const int INF32 = 1 << 29;
const ll MOD = 1000000007;

int main(){
ll n; cin >> n;
ll ans = 0;
for(int i = 0; i < n; ++i){
    ll l,r;cin >> l >> r;
    ans += (r-l+1);
}
cout << ans << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>

using namespace std;

int main(){
    int n, k;
    string s;
    cin >> n;
    cin >> s;
    cin >> k;
    char moji = s.at(k - 1);
    for(int i = 0; i < n; i++){
        if(s.at(i) != moji){
            s.at(i) = '*';
        }
    }
    cout << s <<endl;
}

Measured memory_bytes: 256
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=[0]
sum=0

for i in range(n):
  if b[i]+c[i]-a[i]>=0:
    if c[i]-a[i]>=0:
      c.append(b[i])
      
    else:
      c.append(b[i]+c[i]-a[i])
    sum+=a[i]
  else:
    c.append(0)
    sum+=b[i]+c[i]

if c[n]>a[n]:
  print(sum+a[n])
else:
  print(sum+c[n])

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

using ll = long long;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define ddrep(i, n) for (int i = n; i > 0; --i)
#define srep(i, s, t) for (int i = s; i < t; ++i)
#define ssrep(i, s, t) for (int i = s; i <= t; ++i)

#define rng(a) a.begin(), a.end()
#define pb push_back
#define eb emplace_back
#define fi first
#define se second

#define chmax(x, y) (x = max(x, y))
#define chmin(x, y) (x = min(x, y))

using pi = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using ld = long double;

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << "(" << p.first << "," << p.second << ")";
  return os;
}

template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
  os << "{";
  rep(i, (int)v.size()) {
    if (i)
      os << ",";
    os << v[i];
  }
  os << "}";
  return os;
}

template <typename T, size_t S> void printArray(const T (&array)[S]) {
  for (auto val : array)
    std::cout << val << ", ";
  std::cout << "\n";
}

const int mod = 1e9 + 7;
const int inf = 1e9 + 5;

ll gcd(ll x, ll y) {
  if (y == 0) return x;
  return gcd(y, x % y);
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << std::setprecision(10);

  ll a, b; std::cin >> a >> b;
  ll n = gcd(a, b);
  int ans = 1;
  for (ll x = 2; x*x <= n; x++) {
    if (n % x == 0) ans++;
    while (n % x == 0) n /= x;
  }
  if (n != 1) ans++;
  std::cout << ans << "\n";
}


Measured memory_bytes: 256
# coding: utf-8

import sys
import math
import collections
import itertools
INF = 10 ** 13
MOD = 10 ** 9 + 7
def input() : return sys.stdin.readline().strip()
def lcm(x, y) : return (x * y) // math.gcd(x, y)
def I() : return int(input())
def LI() : return [int(x) for x in input().split()]
def RI(N) : return [int(input()) for _ in range(N)]
def LRI(N) : return [[int(x) for x in input().split()] for _ in range(N)]
def LS() : return input().split()
def RS(N) : return [input() for _ in range(N)]
def LRS(N) : return [input().split() for _ in range(N)]
def PL(L) : print(*L, sep="\n")
def YesNo(B) : print("Yes" if B else "No")
def YESNO(B) : print("YES" if B else "NO")

N = I()
 
ans = 0
for a in range(1, N+1):
    for b in range(1, N+1):
        for c in range(1, N+1):
            ans += math.gcd(math.gcd(a, b), c)
 
print(ans)


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

using namespace std;

vector<int>primes;

void sieve(int N){

         primes.clear();

         vector<bool>Primes(N+1);

         for(int i=2;i<=N;i++){

             if(!Primes[i]){

                primes.push_back(i);

                for(int j=i;j<=N;j+=i){

                    Primes[j]=true;
                }
             }
         }
 }

int main()
{
    sieve(100005);
    int x;
    cin>>x;
    for(int i=0;i<(int)primes.size();i++){
        if(primes[i]>=x){
            cout<<primes[i]<<endl;
            return 0;
        }
    }
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
int n,num;
int a[1010][1010];
int main()
{
	scanf("%d",&n);
	if (n==1)
	{
		printf("1\n1\n");
		return 0;
	}

	int doe=((n-1)/4 +1)*2;
	printf("%d\n",doe);
	for (int i=1;i<=doe;++i)
	{
		if (num+(doe-i+1)*2 > n)
		{
			for (int j=1;j<=doe;++j) a[(j+num-1)%doe+1][j]=num+1;
			++num;
		}
		else
		{
			++num;
			for (int j=1;j<=doe;++j) a[(j+i-2+doe)%doe+1][j]=num+j%2;
			++num;
		}
	}
	for (int i=1;i<=doe;++i)
	{
		for (int j=1;j<=doe;++j) printf("%d ",a[i][j]);
		printf("\n");
	}	
	return 0;
}

Measured memory_bytes: 3200
#include<iostream>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<math.h>
#include<set>
#include<map>
#include<time.h>
#include<list>
#include<iomanip>
#include<cstring>
#define ll unsigned long long
using namespace std;
int main() 
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  map<string,ll int>a;
  ll int t, i;
  string x;
  vector<string>b;
  b={"AC","WA","TLE","RE"};
  cin>>t;
  for(i=0;i<4;i++) 
  a.insert(make_pair(b[i],0));
  while(t--) 
  {
  	cin>>x;
  	a[x]++;
  } 
  for(i=0;i<4;i++) 
  cout<<b[i]<<" x "<<a[b[i]]<<endl;
  return 0;
} 


Measured memory_bytes: 3660