akhauriyash/Code-Regression huggingface dataset:
import java.util.*;
import java.io.*;
import static java.lang.System.*;

class FastScanner {
  private final InputStream in = System.in;
  private final byte[] buffer = new byte[1024];
  private int ptr = 0;
  private int buflen = 0;
  private boolean hasNextByte() {
      if (ptr < buflen) {
          return true;
      }else{
          ptr = 0;
          try {
              buflen = in.read(buffer);
          } catch (IOException e) {
              e.printStackTrace();
          }
          if (buflen <= 0) {
              return false;
          }
      }
      return true;
  }
  private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
  private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
  public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}
  public String next() {
      if (!hasNext()) throw new NoSuchElementException();
      StringBuilder sb = new StringBuilder();
      int b = readByte();
      while(isPrintableChar(b)) {
          sb.appendCodePoint(b);
          b = readByte();
      }
      return sb.toString();
  }
  public long nextLong() {
      if (!hasNext()) throw new NoSuchElementException();
      long n = 0;
      boolean minus = false;
      int b = readByte();
      if (b == '-') {
          minus = true;
          b = readByte();
      }
      if (b < '0' || '9' < b) {
          throw new NumberFormatException();
      }
      while(true){
          if ('0' <= b && b <= '9') {
              n *= 10;
              n += b - '0';
          }else if(b == -1 || !isPrintableChar(b)){
              return minus ? -n : n;
          }else{
              throw new NumberFormatException();
          }
          b = readByte();
      }
  }
  public int nextInt() {
      long nl = nextLong();
      if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
      return (int) nl;
  }
  public double nextDouble() { return Double.parseDouble(next());}
}

class Main {
  public static final int MOD = 1000000007;
  public static final int INF = 1000000000;
  public static void main(String[] args) {
    FastScanner sc = new FastScanner();
    int N = sc.nextInt();
    int H = sc.nextInt();
    int a[] = new int[N];
    int b[] = new int[N];
    for(int i=0; i<N; i++){
      a[i] = sc.nextInt();
      b[i] = sc.nextInt();
    }
    Arrays.sort(a);
    Arrays.sort(b);
    int sum = 0;
    int ans = 0;
    for(int i=N-1; i>=0; i--){
      if(b[i] < a[N-1]) break;
      sum += b[i];
      ans++;
      if(sum >= H) break;
    }
    if(sum < H) ans += (H - sum + a[N-1] - 1) / a[N-1];
    out.println(ans);
  }
}

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

template <class T>
inline void read(T &x) {
    x = 0;
    char c = getchar();
    bool f = 0;
    for (; !isdigit(c); c = getchar()) f ^= c == '-';
    for (; isdigit(c); c = getchar()) x = x * 10 + (c ^ 48);
    x = f ? -x : x;
}

template <class T>
inline void write(T x) {
    if (x < 0) {
        putchar('-');
        x = -x;
    }
    T y = 1;
	int len = 1;
    for (; y <= x / 10; y *= 10) ++len;
    for (; len; --len, x %= y, y /= 10) putchar(x / y + 48);
}

const int MAXN = 10;
int n, d, ans, x[MAXN + 5][MAXN + 5];

inline int dist(int a, int b) {
	int res = 0;
	for (int i = 1; i <= d; ++i)
		res += (x[a][i] - x[b][i]) * (x[a][i] - x[b][i]);
	return res;
}

int main() {
	read(n), read(d);
	for (int i = 1; i <= n; ++i)
		for (int j = 1; j <= d; ++j)
			read(x[i][j]);
	for (int i = 1; i <= n; ++i)
		for (int j = i + 1; j <= n; ++j) {
			int t = dist(i, j), p = sqrt(t);
			if (t == p * p) ++ans;
		}
	write(ans);
	putchar('\n');
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstring>
using namespace std;
static const double EPS = 1e-5;
typedef long long ll;

vector<int> kyaku;

int main(){
	int n;
	while(cin>>n){
		if(n==0)break;
		
		kyaku.clear();
		
		for(int i=0;i<n;i++){
			int t;
			cin>>t;
			kyaku.push_back(t);
		}
		sort(kyaku.begin(),kyaku.end());
		ll ans=0;
		vector<int> mati;
		mati.push_back(0);
		for(int i=0;i<n-1;i++){
			mati.push_back(mati[i]+kyaku[i]);
			ans+=mati[i+1];
		}
		
		
		cout<<ans<<endl;
	}
}

Measured memory_bytes: 0
import std.stdio, std.algorithm, std.string, std.conv, std.array, std.range, std.math;
import core.memory : GC;
int readint() { return readln.chomp.to!int; }
int[] readints() { return readln.split.to!(int[]); }
 
void main() {
    GC.disable();
    int n, m; readf("%d %d\n", &n,&m);
    int[] ps = readints();
 
    auto uf = new UnionFind(n);
    foreach (_; iota(m)) {
        int[] xy = readints();
        uf.unite(xy[0] - 1, xy[1] - 1);
    }
 
    iota(n).filter!(i => uf.same(i, ps[i] - 1)).array.length.writeln;
}
 
class UnionFind {
    import std.algorithm.mutation;
    int[] p;
    this(int n) {
        p.length = n;
        p[0..$] = -1;
    }
    bool unite(int u, int v){
        u = root(u); v = root(v);
        if (u == v) return false;
        if (p[u] > p[v]) swap(u, v);
        p[u] += p[v]; p[v] = u;
        return true;
    }
    bool same(int u, int v){ return root(u) == root(v); }
    int root(int u){ return p[u] < 0 ? u : (p[u] = root(p[u])); }
    int size(int u){ return -p[u]; }
}


Measured memory_bytes: 21820
//
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
//
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

//
// solution 
//
#[allow(unused_mut)]
#[allow(non_snake_case)]
fn main() {
    input!{
        H: usize,
        W: usize,
        a: [ [usize; W]; H],
    }
    
    let mut operations = Vec::new();
    for h in 0..H-1 {
        for w in 0..W-1 {
            if a[h][w] % 2 != 0 {
                a[h][w+1] += 1;
                operations.push((h+1, w+1, h+1, w+2));
            }
        }

        if a[h][W-1] % 2 != 0 {
            a[h+1][W-1] += 1;
            operations.push((h+1, W, h+2, W));
        }
    }

    for w in 0..W-1 {
        if a[H-1][w] % 2 != 0 {
            a[H-1][w+1] += 1;
            operations.push((H, w+1, H, w+2));
        }
    }

    println!("{}", operations.len());
    for &operation in operations.iter() {
        println!("{} {} {} {}", operation.0, operation.1, operation.2, operation.3);
    }
}


Measured memory_bytes: 15096
#include <bits/stdc++.h>
#define int long long int
using namespace std;
template<typename T,typename U> using P=pair<T,U>;
template<typename T> using V=vector<T>;
template<typename T>bool chmax(T&a,T b){if(a<b){a=b;return true;}return false;}
template<typename T>bool chmin(T&a,T b){if(a>b){a=b;return true;}return false;}

template<typename T>auto&operator<<(ostream&s,const vector<T>&v){s<<"[";bool a=1;for(auto e:v){s<<(a?"":" ")<<e;a=0;}s<<"]";return s;}
template<typename T,typename U>auto&operator<<(ostream&s,const pair<T,U>&p){s<<"("<<p.first<<","<<p.second<<")";return s;}
template<typename T>auto&operator<<(ostream&s,const set<T>&st){s<<"{";bool a=1;for(auto e:st){s<<(a?"":" ")<<e;a=0;}s<<"}";return s;}
template<typename T,typename U>auto&operator<<(ostream&s,const map<T,U>&m){s<<"{";bool a=1;for(auto e:m){s<<(a?"":" ")<<e.first<<":"<<e.second;a=0;}s<<"}";return s;}
#define DUMP(x)  cerr<<#x<<" = "<<(x)<<endl;

struct edge { int to, cost; };

const int INF = 1e18;
const int MOD = 1e9+7;

signed main()
{
   int n, K; cin >> n >> K;
   V<int> h(n);
   for (int i = 0; i < n; i++) {
      cin >> h[i];
   }

   V<int> dp(n, INF);
   dp[0] = 0;
   for (int i = 0; i < n; i++) {
      for (int k = 1; k <= K; k++) if (i+k < n) {
         chmin(dp[i+k], dp[i] + abs(h[i] - h[i+k]));
      }
   }
   cout << dp[n-1] << endl;

   return 0;
}


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

using namespace std;

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

	int best = numeric_limits<int>::max();
	int besti = 0;
	for (auto i = 1; i <= N; ++i) {
		int c, t;
		cin >> c >> t;
		if (t <= T && c < best) {
			best = c;
			besti = i;
		}
	}
	if (besti) {
		cout << best;
	} else {
		cout << "TLE";
	}
}

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

#define cn count
#define pb push_back
#define in insert
#define fs first
#define sc second
#define sz size
#define len length
#define forn(i, n) for (ll i = 0; i < (ll) (n); ++i)
#define forni(i, n) for (ll i = 1; i < (ll) (n); ++i)
#define IO ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)

using namespace std;
using ll = long long;
const ll inf = 1e9+7; 
const double PI =  3.141592653589793;

int main(){
	IO;
	string s;
	cin>>s;
	string days[] = {"SAT","FRI","THU","WED","TUE","MON","SUN"};
	forn(i,7){
		if(s==days[i]){cout<<i+1<<"\n";break;}
	}
	return 0;
}


// _   .-')                .-. .-')                 .-')                                               
//( '.( OO )_              \  ( OO )               ( OO ).                                             
// ,--.   ,--.).-'),-----. ,--. ,--.  .-'),-----. (_)---\_) ,--. ,--.     .-----.  ,-.-')  .-'),-----. 
// |   `.'   |( OO'  .-.  '|  .'   / ( OO'  .-.  '/    _ |  |  | |  |    '  .--./  |  |OO)( OO'  .-.  '
// |         |/   |  | |  ||      /, /   |  | |  |\  :` `.  |  | | .-')  |  |('-.  |  |  \/   |  | |  |
// |  |'.'|  |\_) |  |\|  ||     ' _)\_) |  |\|  | '..`''.) |  |_|( OO )/_) |OO  ) |  |(_/\_) |  |\|  |
// |  |   |  |  \ |  | |  ||  .   \    \ |  | |  |.-._)   \ |  | | `-' /||  |`-'| ,|  |_.'  \ |  | |  |
// |  |   |  |   `'  '-'  '|  |\   \    `'  '-'  '\       /('  '-'(_.-'(_'  '--'\(_|  |      `'  '-'  '
// """    """     """""""" """  """"      """""""  """""""  """"""""      """"""   """         """""""



Measured memory_bytes: 3652
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

fn main() {
    let v = read_vec::<usize>();
    let (n, k) = (v[0], v[1]);
    let mut tiles = vec![vec![0i64; 2 * k]; 2 * k];

    for _ in 0..n {
        let v = read_vec::<String>();
        let mut x: usize = v[0].parse().unwrap();
        let mut y: usize = v[1].parse().unwrap();
        if v[2] == "W" {
            y += k;
        }
        x %= k * 2;
        y %= k * 2;
        if y >= k {
            x = (x + k) % (k * 2);
            y = y - k;
        }

        tiles[x][y] += 1;
        tiles[x][y + k] -= 1;
        if x < k {
            tiles[x + k][y] -= 1;
            tiles[x + k][y + k] += 1;
        } else if x > k {
            tiles[x - k][y] -= 1;
            tiles[x - k][y + k] += 1;
            tiles[0][y] += 1;
            tiles[0][y + k] -= 1;
        }
    }

    for x in 0..2 * k {
        for y in 1..2 * k {
            tiles[x][y] += tiles[x][y - 1];
        }
    }

    for x in 1..2 * k {
        for y in 0..2 * k {
            tiles[x][y] += tiles[x - 1][y];
        }
    }
    let mut ans = 0;
    for x in 0..k * 2 {
        for y in 0..k {
            ans = std::cmp::max(
                ans,
                tiles[x][y] + tiles[(x + k) % (2 * k)][(y + k) % (2 * k)],
            );
        }
    }
    println!("{}", ans);
}


Measured memory_bytes: 45308
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return i
}

func nextFloat64() float64 {
	f, _ := strconv.ParseFloat(next(), 64)
	return f
}

func nextInts(n int) []int {
	slice := make([]int, n)
	for i := 0; i < n; i++ {
		slice[i] = nextInt()
	}
	return slice
}

func main() {
	sc.Split(bufio.ScanWords)
	a, b, c, d := nextInt(), nextInt(), nextInt(), nextInt()
	if a+b > c+d {
		fmt.Println("Left")
	} else if a+b < c+d {
		fmt.Println("Right")
	} else {
		fmt.Println("Balanced")
	}
}


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

int main(){
	ll n;
	cin>>n;
	ll h[n];
	ll d[n];
	for(ll i=0;i<n;i++){
		cin>>h[i];
		d[i]=pow(10,18);
	}
	d[0]=0;
	for(ll i=1;i<n;i++){
		if(i>1)d[i]=min(d[i],d[i-2]+abs(h[i]-h[i-2]));
		d[i]=min(d[i],d[i-1]+abs(h[i]-h[i-1]));
	}
	cout<<d[n-1]<<endl;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
#include<iostream>
#include<cmath>
#include<vector>
#include<string>
#include<queue>
#include<set>
#include<map>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef pair<ull, ull> pullull;
typedef pair<ll, int> plli;
typedef pair<int, pii> pipii;
typedef vector<vector<int> > mati;
typedef vector<vector<double> > matd;

#define rep(i,x,y) for(int i=(x); i<(y); ++i)
const int INF = (1<<30);
const ll INFLL = 1LL<<62;
const long double EPS = 1e-12;

template <typename T>
void vec_print(vector<T> VEC){
  rep(i, 0, VEC.size()){
    cout << VEC[i] << " ";
  }
  cout << "\n";
};

template <typename T>
void mat_print(vector<vector<T> > MAT){
  rep(i, 0, MAT.size()){
    rep(j, 0, MAT[i].size()){
      cout << MAT[i][j] << " ";
    }
    cout << "\n";
  }
};

class HOGE{
  public:
    ll index;
    ll value;
    HOGE(ll index, ll value){
      this->index = index;
      this->value = value;
    };
    ~HOGE(void){
      return;
    };

    void print(void){
      cout << "index : " << index << ", value : " << value << "\n";
      return;
    };
    
    bool operator==(const HOGE &obj){
      return (this->value == obj.value);
    };
    bool operator<(const HOGE &obj){
      return (this->value < obj.value);
    };
    bool operator>(const HOGE &obj){
      return (this->value > obj.value);
    };
};

int main(){
  cin.tie(0); // cut the cin and cout (default, std::flush is performed after std::cin)
  ios::sync_with_stdio(false); // cut the iostream and stdio (DON'T endl; BUT "\n";)

  ll H, W;
  cin >> H >> W;
  vector<vector<int> > a(H, vector<int>(W));
  vector<vector<int> > B(H, vector<int>(W));
  vector<vector<int> > R(H, vector<int>(W));

  rep(i, 1, H-1){
    rep(j, 1, W-1){
      if(i%2==0){
        B[i][j] = 1;
        R[i][j] = 0;
      }else{
        R[i][j] = 1;
        B[i][j] = 0;
      }
    }
  }
  rep(i, 0, H){
    B[i][0] = 1;
    R[i][W-1] = 1;
  }

  rep(i, 0, H){
    rep(j, 0, W){
      char tmp;
      cin >> tmp;
      if(tmp == '#'){
        a[i][j] = 1;
        B[i][j] = 1;
        R[i][j] = 1;
      }else{
        a[i][j] = 0;
      }

    }
  }

  rep(i, 0, H){
    rep(j, 0, W){
      if(B[i][j]==0){
        cout << ".";
      }else{
        cout << "#";
      }
    }
    cout << "\n";
  }
  cout << "\n";

  rep(i, 0, H){
    rep(j, 0, W){
      if(R[i][j]==0){
        cout << ".";
      }else{
        cout << "#";
      }
    }
    cout << "\n";
  }

  return 0;
}

Measured memory_bytes: 3712
def examA():
    S = SI()
    ans = "Good"
    for i in range(len(S)-1):
        if S[i+1]==S[i]:
            ans = "Bad"
    print(ans)
    return

def examB():
    N, L = LI()
    ans = 0
    if L>=0:
        for i in range(N - 1):
            ans += (L + i + 1)
    else:
        for i in range(N):
            ans += (L+i)
        if L+N-1<0:
            ans -=(L+N-1)
    print(ans)
    return

def gcd(x, y):
    if y == 0:
        return x
    while y != 0:
        x, y = y, x % y
    return x
def lcm(x, y):
    return x * y // gcd(x, y)
def examC():
    A, B, C, D = LI()
    CD = lcm(C,D)
    ans = B - (B//C + B//D - B//CD) - ((A-1) - ((A-1)//C + (A-1)//D - (A-1)//CD))
    print(ans)
    return

import sys,copy,bisect,itertools,heapq,math
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
mod = 10**9 + 7
inf = float('inf')

if __name__ == '__main__':
    examC()


Measured memory_bytes: 38452
#include <iostream>
#include <string>
#include <cstring>
#include <algorithm>
#include <functional>
#include <cmath>
#include <set>
#include <queue>
#include <vector>
#include <climits>
#include <sstream>
#include <iomanip>
#include <map>
using namespace std;

void getPrime(int N, set<int>& prime)
{
	vector<bool> isNotPrime(N + 1);
	for (auto i = 2; i <= N; ++i)
	{
		if (isNotPrime[i])
		{
			continue;
		}

		prime.insert(i);
		for (auto j = i; j <= N; j += i)
		{
			isNotPrime[j] = true;
		}
	}
}

int main()
{
	const int N = 100000;
	set<int> prime;
	getPrime(N, prime);

	vector<int> sum(N + 1);
	auto temp = 0;
	for (auto i = 1; i <= N; ++i)
	{
		if ((i % 2 != 0)
			&& prime.find(i) != prime.end()
			&& prime.find((i + 1) / 2) != prime.end())
		{
			++temp;
		}
		sum[i] = temp;
	}

	int Q;
	cin >> Q;
	vector<int> result(Q);
	for (auto i = 0; i < Q; ++i)
	{
		int l, r;
		cin >> l >> r;
		result[i] = sum[r] - sum[l - 1];
	}

	for (auto i = 0; i < Q; ++i)
	{
		cout << result[i] << endl;
	}

	return 0;
}


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

using namespace std;

int main(void){
    int n;
    cin >> n;
    vector<int> a(n), l(n), r(n);
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }
    for(int i = 0; i < n; i++){
        if(i == 0)l[i] = a[i];
        else l[i] = __gcd(l[i-1], a[i]);
    }
    for(int i = n - 1; 0 <= i; i--){
        if(i == n - 1)r[i] = a[i];
        else r[i] = __gcd(a[i], r[i+1]);
    }
    int ans = 1;
    for(int i = 0; i < n; i++){
        if(i == 0)ans = max(ans, r[i+1]);
        else if(i == n-1)ans = max(ans, l[i-1]);
        else ans = max(ans, __gcd(l[i-1], r[i+1]));
    }
    cout << ans << endl;
}

Measured memory_bytes: 1408
#include <algorithm>
#include <cassert>
#include <climits>
#include <cstdio>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <utility>
#include <vector>

using namespace std;
using ll = long long;

const int INF = 1e9;
const long long LINF = 1e18;
const double PI=3.14159265358979323846;

typedef priority_queue<int, vector<int>, greater<int>> priority_queue_asc;

int main() {
    int N, K, S;
    cin >> N >> K >> S;

    for (int i = 0; i < K; i++) {
        cout << S << ' ';
    }

    for (int i = 0; i < N - K; i++) {
        if (S == 1e9) {
            cout << 1 << ' ';
        } else {
            cout << S + 1 << ' ';
        }
    }

    cout << endl;
    return 0;
}


Measured memory_bytes: 3184
#include <cstdio>
using namespace std;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
int a,b,sum=0;
int y[21][21]={};
char x[21][21];
void dfs(int aa,int bb){
for(int i=0;i<4;i++){
  if(aa+dx[i]>=0 && aa+dx[i]<a && bb+dy[i]>=0 && bb+dy[i]<b && y[bb+dy[i]][aa+dx[i]]==0){
y[bb+dy[i]][aa+dx[i]]=1;
dfs(aa+dx[i],bb+dy[i]);
}
}
}
int main(){
int c,d;
while(1){
scanf("%d %d",&a,&b);
if(a==0 && b==0) break;
for(int i=0;i<b;i++){
scanf("%s",x[i]);
}
for(int i=0;i<b;i++){
for(int j=0;j<a;j++){
if(x[i][j]=='.'){
y[i][j]=0;
}else if(x[i][j]=='#'){
y[i][j]=2;
}else{
	y[i][j]=1;
c=j;
d=i;
}
}}
dfs(c,d);
for(int i=0;i<b;i++){
  for(int j=0;j<a;j++){
    if(y[i][j]==1){
      sum++;
    }
  }
}
printf("%d\n",sum);
sum=0;
}
return 0;
}

Measured memory_bytes: 1040
#include <cstdio>
#include <algorithm>
using namespace std;
int a[12],sum[12][1010];
int H,W,K,ans=2000;
char s[12][1010];
int judge(int cnt,int la,int j){
	int i,num;
	a[cnt+1]=H;
	for(i=1;i<=cnt+1;i++){
		num=sum[a[i]][j]-sum[a[i]][la]-sum[a[i-1]][j]+sum[a[i-1]][la];
		if(num>K) return 1;
	}
	return 0;
}
void solve(int cnt){
	int j,tot,la;
	tot=cnt,la=0;
	for(j=1;j<=W;j++)
		if(judge(cnt,la,j))tot++,la=j-1;
	if(!judge(cnt,W-1,W))ans=min(ans,tot);
}
void dfs(int step,int cnt){
	if(step==H){
		solve(cnt);
		return;
	}
	dfs(step+1,cnt);
	a[cnt+1]=step,dfs(step+1,cnt+1);
	
}
int main(){
	int i,j;
	scanf("%d%d%d",&H,&W,&K);
	for(i=1;i<=H;i++)scanf("%s",s[i]+1);
	for(i=1;i<=H;i++)
		for(j=1;j<=W;j++)
			sum[i][j]=sum[i-1][j]+sum[i][j-1]-sum[i-1][j-1]+s[i][j]-'0';
	dfs(1,0);
	printf("%d\n",ans);
	return 0;
}

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

using namespace std;

//#define _FILES
const int maxn = 100005;
int cnt[maxn];

int main()
{
    ios_base::sync_with_stdio(false);

    #ifdef _FILES
        freopen("","r",stdin);
        freopen("","w",stdout);
    #endif // _FILES
    int n;
    cin >> n;
    for (int i=0;i<n;i++)
    {
        int x;
        cin >> x;
        x++;
        cnt[x-1]++;
        cnt[x]++;
        cnt[x+1]++;
    }
    int ans = 0;
    for (int i=0;i<maxn;i++)
    {
        ans = max(ans, cnt[i]);
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 640
#include<bits/stdc++.h>
#define int long long
#define for1(i, n) for(int i = 1; i <= (n);i++)
#define puts(x) cout << x << "\n"
constexpr int mod = 1000000007;
using namespace std;
int d, c[30], l[30], s[400][30];
signed main() {
	cin >> d;
	for1(i, 26)cin >> c[i];
	for1(i, d)for1(j, 26)cin >> s[i][j];
	for1(i, d) {
		int p = 0, k = -mod;
		for1(j, 26) {
			int kj = s[i][j] + c[j] * (i - l[j]) * 2.40 + c[j] * 24;
			if (kj > k) { p = j; k = kj; }
			else if (kj == k && c[j] > c[p])p = j;
		}
		puts(p); l[p] = i;
	}
}

Measured memory_bytes: 3688
# ===================================
# (c) MidAndFeed aka ASilentVoice
# ===================================
import math, fractions, collections
# ===================================
a, b = [str(x) for x in input().split()]
ans = int(a+b)
t = math.sqrt(ans)
print("Yes" if t == math.floor(t) else "No")

Measured memory_bytes: 5684
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
#include <stack>
#include <queue>
#include <list>
#include <vector>
using namespace std;

int main() {
	string input;
	cin >> input;

	stack<int> r_inc;
	stack<pair<int, int>> s;
	int sum = 0;

	for(int i = 0; i < input.size(); i++) {
		if(input[i] == '\\') {
			r_inc.push(i);
		}
		else if(input[i] == '/' && r_inc.size() > 0) {
			int left = r_inc.top();
			r_inc.pop();
			sum += i - left;
			int a = i - left;
			while(s.size() > 0 && s.top().first > left) {
				a += s.top().second;
				s.pop();
			}
			s.push(make_pair(left, a));
		}
	}

	vector<int> ans;

	while(s.size() > 0) {
		ans.push_back(s.top().second);
		s.pop();
	}
	reverse(ans.begin(), ans.end());
	cout << sum << endl;
	cout << ans.size();
	for(int i = 0; i < ans.size(); i++) {
		cout << " ";
		cout << ans[i];
	}
	cout << endl;
}




Measured memory_bytes: 3252
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using ld = long double;
long double const pi = std::acos(-1.0L);
typedef pair<int,int> P;

int main() {
  int n; cin >> n;
  vector<int> x(n);
  rep(i,n)cin >> x[i];
  int minv = 1e9;
  for(int i = 1; i <=100 ;++i) {
    int sum = 0;
    rep(j,n){
      sum += (x[j]-i)*(x[j]-i);
    }
    minv = min(minv,sum);
  }
  cout << minv << endl;
  return 0;
}

Measured memory_bytes: 3588
s = input()

ans = 'Yes'
i = 1
for c in s:
    if i % 2 == 1 and c == 'L':
        ans = 'No'
        break
    elif i % 2 == 0 and c == 'R':
        ans = 'No'
        break
    i += 1
print(ans)


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

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

    int a[2][n];
    ll count = 0;
    rep(i, 2){
        rep(j, n){
            cin >> a[i][j];
        }
    }

    ll b[2][n+1];

    b[0][n-1] = a[0][n-1] + a[1][n-1];
    b[1][n-1] = a[1][n-1];

    for(int i = n-1; i > 0; i--){
        b[1][i-1] = a[1][i-1] + b[1][i];
        b[0][i-1] = max(b[0][i], b[1][i-1]) + a[0][i-1];
    }


    cout << b[0][0] << endl;
    return 0;




}


Measured memory_bytes: 256
N = int(input())
A = [int(i) for i in input().split()]
ans = [0]*N
S = sum(A)
S_2 = sum([A[i] for i in range(1, N) if i % 2])
ans[0] = str(S - 2*S_2)
for i in range(1, N):
    ans[i] = str((A[i-1] - int(ans[i-1])//2)*2)
print(' '.join(ans))

Measured memory_bytes: 17464
#include<stdio.h>
int main()
{
  int num[6];
  int top=0,front=1,right=2,left=3,back=4,bottom=5;
  int i,j,n;
  int x,y;
  int rep;
  int aftertop,afterfront;
  for(i=0;i<6;i++) scanf("%d",&num[i]);
  scanf("%d",&n);
  for(i=0;i<n;i++)
    {
      scanf("%d%d",&x,&y);
      for(j=0;j<6;j++)
	{
	  if(x==num[j])
	    {
	      aftertop=j;
	      break;
	    }
	}
      for(j=0;j<6;j++)
	{
	  if(y==num[j])
	    {
	      afterfront=j;
	      break;
	    }
	}
      top=0;
      front=1;
      right=2;
      left=3;
      back=4;
      bottom=5;
      while((top!=aftertop)&&(front!=afterfront))
	{
	  rep=top;
	  top=front;
	  front=bottom;
	  bottom=back;
	  back=rep;
	}
      while(top!=aftertop)
	{
	  rep=top;
	  top=right;
	  right=bottom;
	  bottom=left;
	  left=rep;
	}
      while(front!=afterfront)
	{
	  rep=front;
	  front=right;
	  right=back;
	  back=left;
	  left=rep;
	}
      printf("%d\n",num[right]);
    }
  return 0;
}

Measured memory_bytes: 596
#include <stdio.h>

typedef struct ver{
  int e[101];
  int se;
  int color;
} ver;
   
int n,u;
int time;
int a[101];
int b[101];
ver c[101];
 
void visit(int u){

  int v,w;

  c[u].color=1;
  a[u] = ++time;

  for(v=1;v<=c[u].se;v++){
    w=c[u].e[v];
    if(c[w].color == 0){
      visit(w);
    }

  }

  c[u].color = 2;
  b[u] = ++time;

}
 
void dfs(){

  int u;

  for(u=1;u<=n;u++){
    c[u].color = 0;
  }

  time = 0;

  for(u=1;u<=n;u++){
    if(c[u].color==0){
      visit(u);
    }

  }
}
 
 
 
 
int main(){

  int i,j,k,v;
 
  scanf("%d",&n);

  for(i=1;i<=n;i++){
    scanf("%d",&u);
    scanf("%d",&k);
    c[u].se=k;
    for(j=1;j<=k;j++){
      scanf("%d",&v);
      c[u].e[j]=v;
    }
  }
 
  dfs();
 
  for(i=1;i<=n;i++){
    printf("%d %d %d\n",i,a[i],b[i]);
  }
   
  return 0;
}

Measured memory_bytes: 640
import static java.lang.Math.*;
import static java.util.Arrays.*;

import java.util.*;
import java.io.*;

public class Main {
	int p, q, a, n, cnt;
	void run() {
		Scanner sc = new Scanner(System.in);
		for(;;) {
			p = sc.nextInt(); q = sc.nextInt(); a = sc.nextInt(); n = sc.nextInt();
			if( (p|q|a|n) == 0 ) break;
			
			cnt = 0;
			int vs[] = new int[n];
			dfs(1, 0, 1, vs);
			System.out.println(cnt);
		}
	}
	
	void dfs( int i, int x, int mul, int[] vs) {
//		debug(i, x, mul, add);
		int sum = 0;
		for(int j=0;j<x;j++) sum += mul / vs[j];
		if( p * mul == sum * q ) {
//			debug(i, x, mul, vs);
			cnt++; return;
		}
		if( p * mul < sum * q ) return;
		if( x == n ) return;
		for(int j=i;j<=a;j++) {
			if( mul * j > a )break;
			vs[x] = j;
			dfs( j, x+1, mul*j, vs );
		}
	}

	void debug(Object... os) {
		System.err.println(Arrays.deepToString(os));
	}

	public static void main(String[] args) {
		new Main().run();
	}
}

Measured memory_bytes: 23900
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
typedef long long ll;

int n, a, b;
string s;

int all, current, countB;
string sa, sb;


int main() {
    ios::sync_with_stdio(false);
  
    cin >> n >> a >> b;
    cin >> s;
    
    all = a + b;
    
    for (int i = 0; i < n; i++) {
        if (s[i] == 'a' && current < all) {
            cout << "Yes" << endl;
            current++;
        }
        else if (s[i] == 'b' && current < all && countB < b) {
            cout << "Yes" << endl;
            current++;
            countB++;
        }
        else if (s[i] == 'c')
            cout << "No" << endl;
        else
            cout << "No" << endl;
    }
    
    
    
    

    
    return 0;
}




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


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

    int n,m;
    cin>>n>>m;
    string s[n];
    for(int i=0;i<n;i++){
        cin>>s[i];
    }
    int cnt[26]={};
    for(int i=0;i<n;i++){
        for(int j=0;j<m;j++){
            cnt[s[i][j]-'a']++;
        }
    }
    bool ok=true;
    if(n%2==0 && m%2==0){
        for(int i=0;i<26;i++){
            if(cnt[i]%4!=0) ok=false;
        }
    }
    else if(n%2==0 || m%2==0){
        if(m%2==0) swap(n,m);
        int t=0;
        for(int i=0;i<26;i++){
            if(cnt[i]%2==1) ok=false;
            if(cnt[i]>=4){
                t += cnt[i]-cnt[i]%4;
            }
        }
        if(t < n*m-n) ok=false;
    }
    else {
        bool odd=0;
        int t=0;
        for(int i=0;i<26;i++){
            if(odd && cnt[i]%2==1) ok=false;
            if(!odd && cnt[i]%2==1) odd=true;
            if(cnt[i]>=4){
                t+=cnt[i]-cnt[i]%4;
            }
        }
        if(t < (n-1)*(m-1)) ok=false;
    }
    if(ok){
        cout<<"Yes"<<endl;
    }
    else cout<<"No"<<endl;
    
}

Measured memory_bytes: 256
#include <cstdio>

template<typename T>
T gcd(T a, T b)
{
	if (a < b) return gcd(b, a);
	T r;
	while (r = a % b)
	{
		a = b;
		b = r;
	}
	return b;
}

int main()
{
  long long n, k, g;
  scanf("%lld%lld%lld", &n, &k, &g);
  long long max = g;
  for (long long i = 1; i < n; ++i)
  {
    long long a;
    scanf("%lld", &a);
    g = gcd(g, a);
    if (max < a) max = a;
  }
  puts(k % g == 0 && k <= max ? "POSSIBLE" : "IMPOSSIBLE");
  return 0;
}

Measured memory_bytes: 128
N,K,A[100000],B[100000],i,j;
long long x,y;
main(){
	scanf("%d%d",&N,&K);
	for(;~scanf("%d%d",A+i,B+i);++i);
	for(j=0;j<30;++j){
		if(j?K&1<<j?K|=(1<<j)-1,K^=1<<j:0:1){
			x=0;
			for(i=0;i<N;++i){
				(A[i]|K)<=K&&(x+=B[i]);
			}
			y=x>y?x:y;
		}
	}
	printf("%lld",y);
}


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

# define    ll            long long 
# define    vi             std::vector<ll>
# define    int            long long 
# define    setbits(x)     __builtin_popcountll(x)
# define    zrobits(x)     __builtin_ctzll(x)
# define    fast           ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
# define    pb             push_back
# define    fn             for(int i=0;i<n;i++)
# define    fo(i,a,b)      for(ll i=a;i<b;i++)
# define    all(x)         x.begin(), x.end()
# define    allr(a)        a.rbegin(), a.rend()
# define    PI             3.14159265358979323846
# define    mod            1000000007
# define    endl           "\n"
# define    pii            pair<ll,ll>
# define    deb1(x)        cout<<#x<<" "<<x<<endl;
# define    deb2(x,y)      cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<endl;
# define    deb3(x,y,z)    cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<" "<<#z<<" "<<z<<endl;
 
void getio()
{
    fast
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
}


void solve()
{
	ll n;
	cin>>n;
	if(n%1000==0) cout<<0<<endl;
		else
	cout<<1000-n%1000<<endl;
}



int32_t main()
{
	// getio();
    // int t; cin>>t; while(t--)
    solve();
}

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

#define scd second
#define fst first
#define mkp make_pair
#define pb push_back
#define pf push_front

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vint;
typedef vector<ll> vlong;
typedef vector<vint> vvint;
typedef vector<vlong> vvlong;
typedef vector<bool> vbool;

int gcd(int a, int b) {
    return b==0 ? a : gcd(b,a%b);
}

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

    int k, ans=0;
    cin>>k;
    for(int a=1; a<=k; a++){
        for(int b=1; b<=k; b++){
            for(int c=1; c<=k; c++){
                ans+=gcd(gcd(a,b),c);
            }
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 3596
#include <iostream>

int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  std::cout.tie(nullptr);
  int l, r, d;
  int cnt = 0;
  std::cin >> l >> r >> d;
  for (int i = l; i <= r; ++i) cnt += i % d == 0;
  std::cout << cnt;
}

Measured memory_bytes: 3648
let NY = readLine()!.characters.split(" ").map { Int(String($0))! }
let N = NY[0]
let Y = NY[1]
var xRes: Int = -1
var yRes: Int = -1
var zRes: Int = -1

for x in 0...NY[0] {    // 10000円札の枚数 xのループ
    for y in 0...NY[0] {    // 5000円札の枚数 yのループ
        let z: Int = NY[0] - x - y  // お札の合計枚数が N枚から, 1000円札の枚数 zを求める
        if 0 <= z { // 1000円札の枚数が 0以上のときのみ
            let otoshidama: Int = 10000*x + 5000*y + 1000*z
            if otoshidama == NY[1] {
                xRes = x
                yRes = y
                zRes = z
            }
        }
    }
}
print(xRes, yRes, zRes)

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

class dice {
    int dice[6];
    string state;
public:
    void input() {
        for(int i=0; i<6; ++i) cin >> dice[i];
    }
    void output() {
        cout << dice[0];
        for(int i=1; i<6; ++i) cout << ' ' << dice[i];
        cout << endl;
    }
    void move(string state) {
        for(int i=0; i<state.length(); ++i) {
            switch(state[i]) {
                case 'N':
                    swap(dice[0], dice[1]);
                    swap(dice[1], dice[5]);
                    swap(dice[5], dice[4]);
                    break;
                case 'S':
                    swap(dice[0], dice[4]);
                    swap(dice[4], dice[5]);
                    swap(dice[5], dice[1]);
                    break;
                case 'E':
                    swap(dice[0], dice[3]);
                    swap(dice[3], dice[5]);
                    swap(dice[5], dice[2]);
                    break;
                case 'W':
                    swap(dice[0], dice[2]);
                    swap(dice[2], dice[5]);
                    swap(dice[5], dice[3]);
                    break;
                default:
                    break;
            }
        }
    }
    int getTopside(string state) {
        move(state);
        return dice[0];
    }
};

int main() {
    dice d;
    string state;

    d.input();
    cin >> state;
    cout << d.getTopside(state) << endl;

    return 0;
}

Measured memory_bytes: 3228
N, M = map(int, input().split())

AC = [False for _ in range(N)]
n_WA = [0 for _ in range(N)]
n_penalties = 0

for _ in range(M):
    p, S = input().split()
    p = int(p) - 1
    if not AC[p]:
        if S == "AC":
            AC[p] = True
            n_penalties += n_WA[p]
        elif S == "WA":
            n_WA[p] += 1
        else:
            raise ValueError

print(sum(AC), n_penalties)

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

#define vt          vector
#define sz(x)       int((x).size())
#define all(x)      (x).begin(), (x).end()
#define rall(x)     (x).rbegin(), (x).rend()
#define fi          first
#define se          second

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

void solve() {
    int x;
    cin >> x;

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

        if (ok) return void(cout << x);
    }
}

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

    int tcs = 1;
    for (int tc = 1; tc <= tcs; tc++) {
        // cout << "Case " << tc << ": ";
        solve();
    }
}


Measured memory_bytes: 3596
#pragma comment(linker, "/stack:200000000")

#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")

#include <bits/stdc++.h>
#define ll long long 
#define int long long
#define ull unsigned long long
#define ld long double
#define rep(i, l, r) for (int i = l; i < r; i++)
#define repb(i, r, l) for (int i = r; i > l; i--)
#define sz(a) (int)a.size()
#define fi first
#define se second
#define all(x) x.begin(),x.end()
#define pb push_back
#define mp(a, b) make_pair(a, b)
#define ret(a) return cout<<a,0;

using namespace std;

typedef pair < int , int > pii ;
typedef pair < long long  , long long > pll ;
int k;
ll ans[1000000];
int toint(string s){
	reverse(all(s));
	int res = 0;
	for(int i = 0 ; i < sz(s) ; i++){
		res += (s[i] - '0');
		res *= 10;
	}
	res /= 10;
	return res;
}
int get(int n){
	int res = 0;
	while(n != 0)
		res += n % 10 , n /= 10ll;
	return res;
}

main(){
//    ios::sync_with_stdio(0); cin.tie(0);cout.tie(0);
//    freopen("t.out" , "w" , stdout);
	cin >> k ;
	ans[1] = 1;
	int add = 1;
	for(int i = 2 ; i <= k ; i++){
	   if((ans[i - 1] + add) * get(ans[i - 1] + add * 10ll) <= (ans[i - 1] + add * 10ll) * get(ans[i - 1] + add)){
	   		ans[i] = ans[i - 1] + add;
	   }
	   else
	   	add *= 10ll , ans[i] = ans[i - 1] + add;
	}
	for(int i = 1 ; i <= k ; i++)
		cout << ans[i] << '\n';



}

Measured memory_bytes: 256
#include<bits/stdc++.h>
 
using namespace std;
 
typedef long long int ll;
#define pb push_back
#define mp make_pair

double dp[3002][3002];

int main(){
	int n;
	scanf("%d",&n);
	double p[3002];
	for(int i=1;i<=n;i++){
		scanf("%lf",&p[i]);
	}

	dp[1][0] = 1-p[1];
	dp[1][1] = p[1];

	for(int i=2;i<=n;i++){
		for(int j=i;j>=1;j--){
			dp[i][j] += dp[i-1][j-1]*p[i];
			dp[i][j-1] += dp[i-1][j-1]*(1-p[i]);
		}
	}
	double ans=0;
	for(int i=n/2+1;i<=n;i++){
		ans+=dp[n][i];
	}

	printf("%.10lf\n",ans );


	return 0;
}


Measured memory_bytes: 68992
def main():
	n = int(input())
	d = {}
	for _ in range(n):
		b, f, r, v = map(int, input().split())
		d[(b,f,r)] = d.get((b,f,r),0) + v
	for i in range(1, 5):
		for j in range(1, 4):
			for k in range(1, 11):
				print(' ', d.get((i,j,k), 0), sep='', end='')
			print()
		if i < 4:
			print('####################')

main()



Measured memory_bytes: 5628
//* AuThOr GaRyMr *//
#include<bits/stdc++.h>
#define rb(a,b,c) for(int a=b;a<=c;++a)
#define rl(a,b,c) for(int a=b;a>=c;--a)
#define niv vector<int>
#define LL long long
#define IT iterator
#define PB push_back
#define II(a,b) make_pair(a,b)
#define FIR first
#define SEC second
#define FREO freopen("check.out","w",stdout)
#define rep(a,b) for(int a=0;a<b;++a)
#define KEEP while(1)
#define SRAND mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#define random(a) rng()%a
#define ALL(a) a.begin(),a.end()
#define ff fflush(stdout)
using namespace std;
const int INF=0x3f3f3f3f;
typedef pair<int,int> mp;
typedef pair<mp,mp> superpair;
vector<int> each[1000+10];
int degree[1000+10];int n,m;
int AA[2000+10],BB[2000+10];
bool check(){
	
	cin>>n>>m;
	rb(i,1,m){
		int ai,bi;
		cin>>ai>>bi;
		AA[i]=ai,BB[i]=bi;
		each[ai].PB(bi);
		degree[bi]++;
	}
	int Pu[1000+10]={0};
	queue<int> Q;
	rb(i,1,n) if(!degree[i]) Q.push(i);
	while(!Q.empty()){
		int now=Q.front();Q.pop();
		Pu[now]=1;
		for(auto it :each[now]){
			degree[it]--;
			if(!degree[it]) Q.push(it);
		} 
	}
	rb(i,1,n) if(!Pu[i]) return 1;
	return 0;
}
int v[1000+10];
bool check1(vector<int> A){
	int Con[1000+10]={0};
	for(auto it :A) Con[it]=1;
	int Cnt=0;
	rb(i,1,m){
		if(Con[AA[i]]&&Con[BB[i]]){
//			cout<<AA[i]<<' '<<BB[i]<<endl;
			Cnt++;
		}
	} 
//	cout<<Cnt<<endl;
	return bool(Cnt==A.size());
}
void Find(){
	vector<int> Res;
	int Is=INF;
	rb(i,1,n)
	{
		rb(j,1,n) v[j]=0;
		queue<mp > Q;
		Q.push(II(i,0));
		int flg=0;
		while(!Q.empty()){
			mp now=Q.front();
			Q.pop();
			if(now.FIR!=i)
			v[now.FIR]=1;
			if(now.SEC){
				if(now.FIR==i){
					if(Is>=now.SEC){
						Is=now.SEC;
						Res.clear();
						Res.PB(i); 
					}break;
				}
			}
			for(auto it:each[now.FIR]){
				if(!v[it]){
					Q.push(II(it,now.SEC+1));
				}
			}
		}
	}
	cout<<Is<<endl;
	for(auto IT:Res){
	int RES=IT;
		rb(j,1,n) v[j]=0;
	queue<mp > Q;int i=RES;
	Q.push(II(i,0));
	int flg=0;
	
	int Las[1000+10]={0},shad;
	while(!Q.empty()){
		mp now=Q.front();
		Q.pop();
		if(now.FIR!=i)
		v[now.FIR]=1;
		if(now.SEC){
			if(now.FIR==i){
				break;
			}
		}
		for(auto it:each[now.FIR]){
			if(!v[it]){
				Las[it]=now.FIR;
				Q.push(II(it,now.SEC+1));
			}
		}
	}
		int now=RES;
		vector<int> ANS;
		rb(i,1,Is){
		//cout<<now<<endl;
		ANS.PB(now);
		now=Las[now];
		}//cout<<endl;
//		ANS.clear();
//		ANS.PB(2),ANS.PB(3),ANS.PB(4),ANS.PB(5);
		if(check1(ANS)){
			for(auto ITITI:ANS){
				cout<<ITITI<<endl;
//				return ;
			}
			return;
		}
	}
	
}
int main(){
	if(check()){
		Find();
	}
	else cout<<-1<<endl;
	return 0;
}


Measured memory_bytes: 384
n,m=input().split()
n=int(n)
m=int(m)
a = input().split()
for i in range(m):
  a[i]=int(a[i])
a.sort()
  
if n>=m :
  sum=0
else:
  b=[]
  sum=a[m-1]-a[0]
  for i in range(m-1):
    b+=[a[i+1]-a[i]]
  b.sort()
  b.reverse()
  for i in range(n-1):
    if b[i]>0:
      sum-=b[i]
    else:
      sum+=b[i]
print(sum)
  


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

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

const ll INF64 = 1LL << 60;
const int INF32 = 1 << 30;
const ll MOD = 1000000007;

ll dp[101010];

int main() {
#ifdef MYLOCAL
    ifstream in("input.txt");
    cin.rdbuf(in.rdbuf());
#endif

    int n, k; cin >> n >> k;
    vector<int> v(n);
    for(int i = 0; i < n; ++i){
        cin >> v[i];
    }

    ll ans = 0;
    for(int i = 0; i <= k; ++i){
        int len = min(i, n);
        for(int l_width = 0; l_width <= len; ++l_width){
            priority_queue<ll, vector<ll>, greater<ll> > temoto;
            vector<ll> left, right;
            ll total = 0;
            for(int j = 0; j < l_width; ++j){
                temoto.push(v[j]);
                total += v[j];
                left.push_back(v[j]);
            }

            for(int j = 0; j < len - l_width; ++j){
                temoto.push(v[n - 1 - j]);
                total += v[n - 1 - j];
                right.push_back(v[n - 1 - j]);
            }

            for(int j = 0; j < k - len; ++j){
                if(temoto.empty()){
                    break;
                }
                ll top = temoto.top();
                if(top < 0){
                    temoto.pop();
                    total -= top;
                }
            }
            ans = max(ans, total);
        }
    }
    cout << ans << endl;
    return 0;
}



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

long long int n,a,b,c,ans,x;
string s;

signed main()
{
    ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	
	cin>>n;ans=0;
	for (a=1;a<n+1;a++) for (b=1;b<n+1;b++) for (c=1;c<n+1;c++)
	{
		x=__gcd(a,b);x=__gcd(x,c);ans=ans+x;
	}
	cout<<ans;
}


Measured memory_bytes: 3620
from functools import lru_cache
N = int(input())
K = int(input())
@lru_cache(None)
def F(N,K):
#  assert N>=0
  if N<10:
    if K==0:
      return 1
    if K==1:
      return N
    return 0
  p, q = divmod(N,10)
  ret = 0
  if K>0:
    ret += F(p,K-1) * q
    ret += F(p-1,K-1) * (9-q)
  ret += F(p,K)
  return ret
print(F(N,K))

Measured memory_bytes: 39536
using System;
using System.Collections.Generic;
using System.Text;
using System.Linq;

namespace atcoder
{
    class Program
    {
        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());
            List<int> A = Console.ReadLine().Split().Select(f => int.Parse(f)).ToList();
            long count = 0;
            List<int> sort = Enumerable.Range(0, N).ToList();
            int[] larr = Enumerable.Range(-1, N).ToArray();
            int[] rarr = Enumerable.Range(1, N).ToArray();
            sort.Sort((a, b) => A[b] - A[a]);
            for (int i = 0; i < N; i++)
            {
                var l = larr[sort[i]];
                var r = rarr[sort[i]];
                if (r != N)
                {
                    larr[r] = l;
                    
                }
                if (l != -1)
                {
                    rarr[l] = r;
                }
                count += (long)A[sort[i]] * (long)(sort[i] - l) * (long)(r- sort[i]);
            }
            Console.WriteLine(count);
        }
    }
}


Measured memory_bytes: 27072
S = input()
#llen(S)-1までの長さのバイナリを入れる、0をそのまま、１を＋とみなす。
#再帰関数にして、引数に前のls-1を入れればいい
def sumall(ls = 0):
    bls = bin(ls)
    if len(S) <= len(bls)-2:
        return 0
    else:
        count = 0
        pi = 0
        for ib,b in enumerate(bls[::-1]):
            if b == 'b':
                count += int(S[pi:])
                break
            elif b == '1':
                count += int(S[pi:ib+1])
                pi = ib+1
        #print(count)
        return count + sumall(ls+1)
if len(S) == 1:
    print(int(S))
else:
    print(sumall(0))

Measured memory_bytes: 3572
/*------------------------------------
........Bismillahir Rahmanir Rahim....
..........created by Abdul Aziz.......
------------------------------------*/
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <cmath>
#include <vector>
#include <set>
#include <list>
#include <stack>
#include <map>
#include <cstring>
#include <unordered_map>
#include <queue>
#include <functional>
#define   mod  998244353
#define   int  long long 
#define   ld   long double
#define   pb   push_back
#define   vi   vector<int> 
#define   co(x)  cout << x << '\n' 
#define   dbg(x)  cerr << #x << " = " << x << '\n' 
#define   bitcount(x)  (int)__builtin_popcount(x) 
#define   sz(x)  (int)x.size()
#define   all(a) a.begin(),a.end() 
#define   ff   first
#define   ss   second
#define   pii  pair<int,int> 
#define   lcm(a,b) (a*b)/__gcd(a,b) 
using namespace std;

inline void solve(){
	int n ; cin >> n ; 
	vi a(n),b(n);
	for (int i=0;i<n;i++){
		int l,r; 
		cin >> l >> r ; 
		a[i] = l+r;
		b[i] = l-r;
	}
	sort(all(a));
	sort(all(b));
    co (max(a[n-1]-a[0],b[n-1]-b[0])) ; 
}

signed main()
{
    int n=1; // cin>>n;
    while (n--) solve();
    return 0;
}


Measured memory_bytes: 6412
import java.io.*;
import java.math.BigInteger;
import java.util.*;


public class  Main{
    public static void main(String[] args) throws Exception{
    	MScanner sc = new MScanner(System.in);
        //MScanner sc = new MScanner("reduce.in");
        PrintWriter pw=new PrintWriter(System.out);
        int l=sc.nextInt();int r=sc.nextInt();
        if(r-l+1>=2019) {
        	pw.println(0);
        }
        else {
        	int ans=1000000000;
        	for(int i=l;i<=r;i++) {
        		for(int j=i+1;j<=r;j++) {
        			ans=(int)Math.min(ans,(i*1l*j*1l)%2019);
        		}
        	}
        	pw.println(ans);
        }
        pw.flush();
    }
    
    
    static class MScanner {
		StringTokenizer st;
		BufferedReader br;
 
		public MScanner(InputStream system) {
			br = new BufferedReader(new InputStreamReader(system));
		}
 
		public MScanner(String file) throws Exception {
			br = new BufferedReader(new FileReader(file));
		}
 
		public String next() throws IOException {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}
 
		public String nextLine() throws IOException {
			return br.readLine();
		}
 
		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}
 
		public double nextDouble() throws IOException {
			return Double.parseDouble(next());
		}
 
		public char nextChar() throws IOException {
			return next().charAt(0);
		}
 
		public Long nextLong() throws IOException {
			return Long.parseLong(next());
		}
 
		public boolean ready() throws IOException {
			return br.ready();
		}
 
		public void waitForInput() throws InterruptedException {
			Thread.sleep(3000);
		}
	}
}

Measured memory_bytes: 23124