akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define mod 1000000007
using ll=long long;
ll factorial[2000000];

ll power(ll n,ll m)
{
    ll ans=1;
    for (int r=0;m>>r>0;r++)
    {
        if ((m>>r)&1) ans=ans*n%mod;
        n=n*n%mod;
    }
    return ans;
}

ll inv(ll n)
{
    return power(n,mod-2);
}

void fact()
{
    factorial[0]=1;
    for (int i=1;i<2000000;i++) factorial[i]=i*factorial[i-1]%mod;
    return;
}

ll cmb(ll n,ll r)
{
    if (r>n) return 0;
    else return factorial[n]*inv(factorial[n-r])%mod*inv(factorial[r])%mod;
}

int main()
{
    fact();
    ll X,Y;cin >> X >>Y;
    ll x=(2*X-Y)/3,y=(2*Y-X)/3;
    if ((2*X-Y)%3!=0 || (2*Y-X)%3!=0 || x<0 || y<0)
    {
        cout << 0 <<endl;
        return 0;
    }
    else
    {
        cout << cmb(x+y,x) <<endl;
        return 0;
    }
}


Measured memory_bytes: 15872
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
typedef pair<ll,ll> P;
typedef pair<P,long double> Pi;
typedef pair <long double,int> Pd;
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
const ll inf=(1e18);
const ll mod=1000000007;
//ios_base::sync_with_stdio(false);
//cin.tie(NULL);
ll gcd(ll a,ll b) {return b ? gcd(b,a%b):a;}
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
bool ok=false;
int n;
cin>>n;
for(int i=1;i<10;i++){
   if(n%i==0&&n/i<10)ok=true;
}
if(ok)cout<<"Yes"<<endl;
else cout<<"No"<<endl;
}

Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		int[] a = new int[n];
		for (int i = 0; i < n; i++) {
			a[i] = in.nextInt();
		}
		Arrays.sort(a);
		int max = a[a.length - 1];
		double k = max / 2;
		double min = max;
		int index = 0;
		for (int i = a.length - 2; i >= 0; i--) {
			if (Math.abs(k - a[i]) < min) {
				index = i;
				min = Math.abs(k - a[i]);
			}
		}
		System.out.println(max + " " + a[index]);
		in.close();
	}
}

Measured memory_bytes: 50380
#include <bits/stdc++.h>
#define INF 2e9
#define MOD 1000000007
using namespace std;
typedef long long llong;
typedef long double ldouble;

using Graph = vector<vector<int>>;

int ctoi(const char c){
  if('0' <= c && c <= '9') return (c-'0');
  return -1;
}

// int gcd(int a, int b){
//   int ma = max(a,b);
//   int mi = min(a,b);
//   if(mi == 0) return ma;

//   return gcd(mi, ma%mi);
// }

int main(){
  string S;
  cin >> S;
  vector<llong> r(2019);
  int rem = 0;
  int previous = 0;
  for(int i=0; i<S.length(); ++i){
    if(previous == 0){
      rem = rem + ctoi(S[S.length()-1-i]);
      previous = 1;
    }else{
      rem = rem + previous * 10 * ctoi(S[S.length()-1-i]);
      previous = previous * 10 % 2019;
      if(previous<0) previous += 2019;
    }
    rem %= 2019;
    if(rem<0) rem += 2019;
    ++r[rem];
  }
  llong ans = r[0];
  for(int i=0; i<2019; ++i){
    ans += r[i] * (r[i]-1) / 2;
  }
  cout << ans << endl;
}

Measured memory_bytes: 3752
#include <bits/stdc++.h>
template<typename T>
class fixed_point : T {
  public:
    explicit constexpr fixed_point (T&& t) noexcept
      : T(std::forward<T>(t)) {}
    template<typename... Args>
    constexpr decltype(auto) operator()(Args&&... args) const
      {return T::operator()(*this, std::forward<Args>(args)...);}
};
template<typename T>
static inline constexpr decltype(auto) fix (T&& t) noexcept {
  return fixed_point<T>{std::forward<T>(t)};
}
int main() {
  std::cin.tie(0); std::cin.sync_with_stdio(false);
  size_t n, m; std::cin >> n >> m;
  std::vector<std::vector<size_t>> graph(n);
  for (size_t _ = 0; _ < m; _++) {
    size_t a, b; std::cin >> a >> b;
    a--, b--;
    graph.at(a).push_back(b);
    graph.at(b).push_back(a);
  }
  auto yes = [&] {
    std::cout << "Yes" << std::endl;
    exit(0);
  };
  auto no = [&] {
    std::cout << "No" << std::endl;
    exit(0);
  };
  std::for_each(graph.begin(), graph.end(), [&](auto& v){
    if (v.size() % 2 != 0) no();
  });
  std::for_each(graph.begin(), graph.end(), [&](auto& v){
    if (v.size() >= 6) yes();
  });
  std::vector<size_t> fours;
  for (size_t i = 0; i < n; i++) {
    if (graph.at(i).size() == 4) fours.push_back(i);
  }
  if (fours.size() >= 3) yes();
  if (fours.size() <= 1) no();
  auto check = [&] (size_t x) {
    std::vector<int> ckd(n, false);
    ckd.at(x) = true;
    auto dfs = fix ([&](auto  dfs, size_t crr, size_t p) -> void {
      ckd.at(crr) = true;
      for (auto const& nxt : graph.at(crr)) {
        if (nxt == x || nxt == p) continue;
        if (ckd.at(nxt)) yes();
        dfs(nxt, crr);
      }
    });
    for (size_t i = 0; i < n; i++) {
      if (i != x && !ckd.at(i)) dfs(i, i);
    }
  };
  std::for_each(fours.begin(), fours.end(), check);
  std::cout << "No" << std::endl;
  return 0;
}

Measured memory_bytes: 8448
H, W = [int(i) for i in input().split()]
sy, sx = [0,0]
gy, gx = [H-1, W-1]
c_ls = list()
yet_ls = [(sy,sx)]
dist_dict = {(sy, sx): 0}
road_len = 0
for i in range(H):
    c_ls.append([i for i in list(input())])
    road_len += len([i for i in c_ls[-1] if i == "."])


def dfs():
    ind = 0
    while len(yet_ls) > ind:
        y, x = yet_ls[ind]
        for move_y, move_x in [(1,0),(-1,0),(0,1),(0,-1)]:
            next_y = y + move_y
            next_x = x + move_x
            if 0 <= next_y < H and 0 <= next_x < W:
                pass
            else:
                continue
            if c_ls[next_y][next_x] == "#":
                continue
            c_ls[next_y][next_x] = "#"
            if (next_y, next_x) not in dist_dict:
                dist_dict[(next_y, next_x)] = dist_dict[(y,x)] + 1
                yet_ls.append((next_y,next_x))
            if (next_y, next_x) == (gy, gx):
                return dist_dict[(next_y, next_x)]
        ind += 1
    return road_len


print(road_len - dfs() - 1)

Measured memory_bytes: 3444
#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <string>
#include <vector>

using namespace std;

string let = "RYGB";

int main() {
  int h, w, d;
  cin >> h >> w >> d;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      int x = (i + j) % (2 * d) / d;
      int y = ((i - j) % (2 * d) + (2 * d)) % (2 * d) / d;
      putchar(let[2 * x + y]);
    }
    putchar('\n');
  }
  return 0;
}


Measured memory_bytes: 512
#include<stdio.h>
#include<string.h>

int main()
{
	long long int a = 0;
	double b = 0;
	long long int c, d;

	scanf("%lld %lf", &a, &b);

    d = (long long int)((b + 0.005)*100);

	c = a*d/100;

	printf("%lld", c);

	return 0;
}

Measured memory_bytes: 1696
#include<iostream>
#include<stdio.h>
#include<cmath>
using namespace std;
int main(){
    while(1){
        int n, s;
        double a;
        double B = 0;
        double m = 0;
        
        cin >> n;
        
        if(n == 0)break;
        int As[n];
 
        for(int i = 0; i < n; i++){
            cin >> s;
            m = m + s;
            As[i] = s;
        }
     
        m = m / n;
     
        for(int i = 0; i < n; i++){
            B = B + (As[i] - m) * (As[i] - m);
        }
     
        a = sqrt(B / n);
     
        printf("%.5lf\n", a);
    } 
}


Measured memory_bytes: 3216
#include<iostream>
using namespace std;
#define ll long long

void solve()
{
	int a,b;cin>>a>>b;
	if(a<b)
	{
		while(b--)
		cout<<a;
	}
	else
	while(a--)cout<<b;
}
int main()
{
	//int t;cin>>t;
	//while(t--)
	solve();
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class Main {
	static List<Integer> path;

	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] sa = br.readLine().split(" ");
		int n = Integer.parseInt(sa[0]);
		int a = Integer.parseInt(sa[1]);
		int b = Integer.parseInt(sa[2]);
		sa = br.readLine().split(" ");
		List<Long> list = new ArrayList<Long>(n);
		for (int i = 0; i < n; i++) {
			list.add(Long.parseLong(sa[i]));
		}
		br.close();

		Collections.sort(list);
		Collections.reverse(list);

		long sum = 0;
		double m = 0;
		for (int i = 0; i < b; i++) {
			sum += list.get(i);
			if (i >= a - 1) {
				double d = (double) sum / (i + 1);
				m = Math.max(m, d);
			}
		}
		System.out.println(new BigDecimal(m).toString());

		long cnt1 = 0;
		long cnt2 = 0;
		long va = list.get(a - 1);
		for (int i = 0; i < list.size(); i++) {
			if (list.get(i) > va) {
				cnt1++;
			} else if (list.get(i) == va) {
				cnt2++;
			}
		}

		long ans = 0;
		long f = (long) Math.floor(m);
		long c = (long) Math.floor(m);
		if (f == c && f == va) {
			for (int i = a; i <= b; i++) {
				ans += nCr(cnt2, i - cnt1);
			}
		} else {
			ans += nCr(cnt2, a - cnt1);
		}
		System.out.println(ans);
	}

	static long nCr(long n, long r) {
		long val = 1;
		for (long i = 1; i <= r; i++) {
			val = val * (n - i + 1) / i;
		}
		return val;
	}
}


Measured memory_bytes: 22740
#include "bits/stdc++.h"
using namespace std;
using ll = long long; using pii = pair<int, int>;
const int MOD = (int)1e9 + 7, INF = (1 << 27); const ll INFLL = (1LL << 55);
#define FOR(i,a,b) for(int (i)=(a);i<(int)(b);i++)
#define rep(i,n) FOR(i,0,n)
template<typename T> void dbg(T x) { cout << x << "\n"; }
template<typename T, typename U> static void chmin(T &x, U y) { if (y < x) x = y; }
template<typename T, typename U> static void chmax(T &x, U y) { if (x < y) x = y; }

int n, y;

int main() {
    cin >> n >> y;
    static int f[20000010];
    rep(a, 20000001) {
        ll x = y - n - 9999 * a;
        if (x < 0) break;
        f[x] = 1;
    }

    rep(b, y / 5000 + 1) rep(c, y / 1000 + 1) {
        ll x = 4999 * b + 999 * c;
        int a = n - b - c;
        if (a < 0 || x < 0) continue;
        bool t = 10000 * a + 5000 * b + 1000 * c == y;
        if (a + b + c == n && f[x] && t) {
            printf("%d %d %d\n", a, b, c);
            return 0;
        }
    }
    puts("-1 -1 -1");
    return 0;
}


Measured memory_bytes: 76288
s = list(str(input()))

for i in range(10**18):
    s.pop()
    if len(s)%2:
        continue
    else:
        for j in range(len(s)//2):
            if s[j] != s[j+len(s)//2]:
                break
        else:
            print(len(s))
            exit(0)
            continue


Measured memory_bytes: 2940
#include <iostream>

#include <map>
#include <cmath>
#include <vector>
#include <cstring>
#include <algorithm>

using namespace std;

using ll = long long;
using ii = pair<ll, ll>;

const int MAX { 400010 };

int west[MAX], east[MAX];

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

    int N;
    string S;
    cin >> N >> S;

    west[0] = (S[0] == 'W' ? 1 : 0);
    east[0] = (S[0] == 'E' ? 1 : 0);

    for (int k = 1; k < N; ++k)
    {
        west[k] = west[k - 1] + (S[k] == 'W' ? 1 : 0);
        east[k] = east[k - 1] + (S[k] == 'E' ? 1 : 0);
    }

/*
cout << "west = ";
    for (int k = 0; k < N; ++k)
        cout << west[k] << " ";
cout << endl;

cout << "east = ";
    for (int k = 0; k < N; ++k)
        cout << east[k] << " ";
cout << endl;
*/
    int min_changes = east[N - 1] - east[0];
//cout << "k = " << 0 << ", min_changes = " << min_changes << endl;

    for (int k = 1; k < N; ++k)
    {
        min_changes = min(min_changes, west[k - 1] + east[N - 1] - east[k]);
//cout << "dir = " << S[k] << ", k = " << k << ", min_changes = " << min_changes << endl;
    }

    cout << min_changes << endl;
 
    return 0;
}


Measured memory_bytes: 3092
n, y = map(int, input().split())

if y % 1000 != 0:
    print('-1 -1 -1')
else:
    y //= 1000
    for man in range((y - n)//9 + 1):
        if (y - n - 9 * man) % 4 == 0:
            go = (y - n - 9 * man) // 4
            if (n - man - go) >= 0:
                print(man, go, n - man - go)
                break
    else:
        print('-1 -1 -1')            

Measured memory_bytes: 9080
#include <iostream>

using namespace std;

int main(int argc, char *argv[])
{
	int N;

	cin >> N;

	int ans = 0, pp = 1000000;
	for (int i = 0; i < N; i++) {
		int p;
		cin >> p;
		if (p <= pp) {
			ans++;
			pp = p;
		}
	}
	cout << ans << endl;

	return 0;
}

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

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

/**
 * For DEBUG
 * https://github.com/ta7uw/cpp-pyprint
 */
#include "cpp-pyprint/pyprint.h"

#endif

void Main() {
    ll X, Y, A, B, C;
    cin >> X >> Y >> A >> B >> C;
    vector<ll> P(A), Q(B), R(C);
    rep(i, A) cin >> P[i];
    rep(i, B) cin >> Q[i];
    rep(i, C) cin >> R[i];
    sort(P.rbegin(), P.rend());
    sort(Q.rbegin(), Q.rend());
    sort(R.rbegin(), R.rend());
    ll ans = 0;
    ll s = 0;
    priority_queue<ll, vector<ll>, greater<ll>> que;
    rep(i, X) {
        s += P[i];
    }
    rep(i, Y) {
        s += Q[i];
    }
    rep(i, X) {
        que.push(P[i]);
    }
    rep(i, Y) {
        que.push(Q[i]);
    }
    vector<ll> Z(C, 0);
    ll z = 0;
    while (!que.empty() && z <= C - 1) {
        ll q = que.top();
        que.pop();
        Z[z] = q;
        z++;
    }
    // print(Z);
    vector<ll> accr(C + 1, 0);
    vector<ll> accz(C + 1, 0);
    rep(i, C) {
        accr[i + 1] += accr[i] + R[i];
    }
    rep(i, C) {
        accz[i + 1] += accz[i] + Z[i];
    }
    rep(c, min(C + 1, X + Y + 1)) {
        ll ac = accr[c];
        ll az = accz[c];
        ans = max(ans, s + ac - az);
//        print(s + ac - az);
//        print(ac);
//        print(az);
        //print(ac, az, ans);
    }
    cout << ans << '\n';
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
    return 0;
}


Measured memory_bytes: 6384
// reference: https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

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

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

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

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

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

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

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

fn main() {
    input! {
        n: usize,
        m: usize,
        c: i64,
        b: [i64; m],
        a: [[i64; m]; n]
    }

    let mut ans = 0;
    for i in 0..n {
        let mut v = c;
        for j in 0..m {
            v += a[i][j] * b[j];
        }
        if v > 0 {
            ans += 1;
        }
    }

    println!("{}", ans);
}


Measured memory_bytes: 4352
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
using namespace std;
const int INF = 1000000000;
long h[200005] = {0};
long b = 0;
long d = 0;
int main(){
	int n;
	int co = 0;
	cin >>  n;
	for (int i = 1; i <= n; i++) {
		cin >> h[i];
		if (b <= h[i]) {
			d = b;
			b = h[i];
		}
		else if (d <= h[i])d = h[i];

	}
	for (int i = 1; i <= n; i++) {
		
		if (h[i] == b)cout << d << endl;
		else cout << b << endl;
	}

}

Measured memory_bytes: 3200
import java.util.Scanner;
public class Main{ 
  public static void main(String[] args) { 
    Scanner sc = new Scanner(System.in);
    while(true){
      int H = sc.nextInt(); 
      int W = sc.nextInt();
      for(int i=0;i<H;i++){
        for(int j=0;j<W;j++){
          System.out.print("#");
        }
        System.out.println("");
      }
      if (H == 0 && W == 0) { 
        break; 
      }
    System.out.println("");
    }
  }
}

 

Measured memory_bytes: 34756
#include <bits/stdc++.h>
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
//#define int long long
typedef long long ll;
using namespace std;
const int MOD = 1000000007;
const int INF = 1010000000;
const double EPS = 1e-10;
const pair<int,int> fd[] = {make_pair(1,0),make_pair(-1,0),make_pair(0,1),make_pair(0,-1)}; 

signed main(){
  int n;string a,b,c;cin>>n>>a>>b>>c;
  int ans =0;
  rep(i,n){
    ans += 2;
    if(a[i] == b[i]){
      if(a[i] == c[i]){
        ans -= 2;
      }else{
        ans -= 1;
      }
    }else if(a[i] == c[i]){
      ans--;
    }else if(b[i] == c[i]){
      ans--;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <climits>
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <string>
#include <sstream>
#include <vector>
#include <map>
#include <set>
#include <complex>
#include <functional>
#include <utility>
#include <iterator>

#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
#define FOR(i, m, n) for(int i = (m); i < (int)(n); ++i)
#define ALL(x) (x).begin(), (x).end()
#define INF 2000000000

#ifdef LOCAL
  #define dprintf(...) fprintf(stdout, __VA_ARGS__)
#else
  #define dprintf(...) 0
#endif

using namespace std;

typedef long long LL;
typedef unsigned long long ULL;
typedef unsigned int uint;

bool compare_pair(pair<int, int> a, pair<int, int> b) {
  return a.second < b.second;
}

int main() {
  int n;
  vector<pair<int, int>> v;
  cin >> n;

  REP(i, n) {
    int id = i + 1;
    int left;
    cin >> left;
    v.push_back({id, left});
  }

  sort(ALL(v), compare_pair);

  REP(i, n) {
    cout << v[i].first;
    if(i != n - 1) {
      cout << ' ';
    }
  }
  cout << '\n';

  return 0;
}


Measured memory_bytes: 1780
#include <algorithm>
#include <array>
#include <cstddef>
#include <cstdint>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <vector>

using namespace std;

int main()
{
    int64_t K;
    cin >> K;

    int64_t sum = 0;
    for (int64_t i = 1; i <= K; i++)
    {
        for (int64_t j = 1; j <= K; j++)
        {
            for (int64_t k = 1; k <= K; k++)
            {
                sum += std::gcd(std::gcd(i, j), k);
            }
        }
    }
    cout << sum << endl;
}


Measured memory_bytes: 3624
#include<iostream>
#include <stdio.h>
using namespace std;
 
int main(){
	int a,b,c,d,e,f,g;
	cin>>a>>b>>c>>d>>e;
	if(b/d*d==b){f=b/d;}else{f=b/d+1;}
	if(c/e*e==c){g=c/e;}else{g=c/e+1;}
	if(a-f<a-g){
		cout<<a-f<<endl;}else{
		cout<<a-g<<endl;}
	return 0;}


Measured memory_bytes: 1160
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <string>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>

using namespace std;
typedef long long ll;

int main()
{
    int x,y,z;
    int ans;

    while(scanf("%d%d%d",&x,&y,&z) != EOF)
    {
        x -= 2*z;
        ans = x/(y+z);
        if(x%(y+z) >= y) ans++;
        printf("%d\n",ans);
    }

    return 0;
}




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

int main() {

 int H, N;
 cin >> H >> N;

 vector<int> A(N);
 vector<int> B(N);
 for (int i = 0; i < N; i++) {
   cin >> A[i] >> B[i];
 }

 // i 番目までの魔法からダメージの総和が j になるように選んだときの魔法消費量の総和の最小値
 vector<vector<int>> dp(N + 1, vector<int>(H + 1, 100000000));

 dp[0][0] = 0;

 for (int i = 0; i < N; i++) {
   for (int j = 0; j <= H; j++) {
     if (j <= A[i]) {
       dp[i+1][j] = min(dp[i][j], B[i]);
     } else {
       dp[i+1][j] = min(dp[i][j], dp[i+1][j - A[i]] + B[i]);
     }
   }
 }

 cout << dp[N][H] << endl;

}

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

int main()
{
    int n, k;
    cin>>n>>k;
    vector<int> a(n);
    for(int& x : a) {
        cin>>x;
    }
    vector<bool> dp(k + 1);
    for(int stones = 0; stones <= k; ++stones) {
        for(int x : a) {
            if(stones >= x && !dp[stones-x]) {
                dp[stones] = true;
            }
        }
    }
    if(dp[k])
        cout<<"First";
    else cout<<"Second";
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <stdlib.h>        /* abs */
using namespace std;
#define ll long long 
ll A[51];
ll B[51];
ll C[51];
ll D[51];
ll R[51];
int index[51];

int main(){
	int i,j;
	cin >> i >> j;
	for(int x = 1; x <= i; x++){
		cin >> A[x] >> B[x];
	}
	for(int y = 1; y <= j; y++){
		cin >> C[y] >> D[y];
	}
	for(int x = 1; x <= i; x++){
		ll min_r = 1000000000;
		int ind = 51;
		for(int y = 1; y <=j; y++){
			ll dis = abs(A[x]-C[y]) + abs(B[x]-D[y]);
			if(dis < min_r){
				min_r = dis;
				ind = y;
			}
		}
		R[x] = min_r;
		index[x] = ind;
	}

	for( int x = 1; x <= i; x++){
		cout << index[x] << endl;
	}

}

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

int main(){
  int i;
  char str[10001];
  fgets(str,10000,stdin);
  for(i=0;str[i];i++)
    printf("%c",'a'<=str[i]&&str[i]<='z'?str[i]-32:str[i]);
  return 0;
}

Measured memory_bytes: 0
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Linq;
using static MyIO;


public class A
{
	public static void Main() => (new Solver()).Solve();
}


public class Solver
{
	public void Solve()
	{
		int A = GetInt();
		int B = GetInt();
		Console.WriteLine((A <= 9) && (B <= 9) ? A * B : -1);

	}
}


public static class MyIO
{
	private static string[] args = null;
	private static int num = -1;
	private static int used = -1;

	private static string getArg()
	{
		if(used == num)
		{
			args = Console.ReadLine().Split(' ');
			num = args.Length;
			used = 0;
		}
		return args[used++];
	}

	public static int GetInt() => int.Parse(getArg());
	public static long GetLong() => long.Parse(getArg());
	public static double GetDouble() => double.Parse(getArg());
	public static string GetString() => getArg();
	public static char GetChar() => getArg()[0];
	public static int[] GetInts(int N) => Enumerable.Range(0, N).Select(_ => GetInt()).ToArray();
	public static long[] GetLongs(int N) => Enumerable.Range(0, N).Select(_ => GetLong()).ToArray();
	public static double[] GetDoubles(int N) => Enumerable.Range(0, N).Select(_ => GetDouble()).ToArray();
	public static string[] GetStrings(int N) => Enumerable.Range(0, N).Select(_ => GetString()).ToArray();
}


Measured memory_bytes: 13140
#include <iostream>
#include <iomanip>
#include <ios> 
#include <vector>
#include <string>
#include <algorithm>
#include <functional>
#include <queue>
#include <stack>
#include <set>
#include <cmath>
#include <bitset>
#include <map>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define sz(c) ((int)(c).size())

using namespace std;
typedef long long int ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> P;
typedef pair<ll, pair<int, int> > PP;
const int MAX=1e5+10;
//const ll INF=9e18;

int main(){
	int N;
	cin>>N;
	ll a[MAX], b[MAX];
	rep(i,N)cin>>a[i]>>b[i];
/*
	if(N==2){
		ll z=min(a[0], b[1])+min(a[1], b[0]);
		cout<<z<<endl;
		return 0;
	}
*/	
	vector<PP> v(2*N);
	rep(i,N){
		v[2*i]=make_pair(a[i], make_pair(0, i));
		v[2*i+1]=make_pair(b[i], make_pair(1, i));
	}
	sort(v.begin(), v.end());
	
	ll ans=0;
	bool small[MAX][2];
	rep(i,N)rep(j,2)small[i][j]=false;
	rep(i,N){
		ans+=v[i].first;
		P p=v[i].second;
		small[p.second][p.first]=true;
	}
	int oo=0, ox=0, xo=0, xx=0;
	rep(i,N){
		if(small[i][0] && small[i][1])oo++;
		if(small[i][0] && !small[i][1])ox++;
		if(!small[i][0] && small[i][1])xo++;
		if(!small[i][0] && !small[i][1])ox++;
	}
	if(oo>0)cout<<ans<<endl;
	else if(ox==0 || xo==0) cout<<ans<<endl;
	else{
		int indo=(v[N-1].second).second;
		int indx=(v[N].second).second;
		if(indo!=indx){
			cout<<ans-v[N-1].first+v[N].first<<endl;
		}
		else{
			ll adj=min(v[N+1].first-v[N-1].first, v[N].first-v[N-2].first);
			cout<<ans+adj<<endl;
		}
	}
}

Measured memory_bytes: 5120
import java.util.*;
import java.io.*;
import java.math.*;


import static java.lang.Math.*;
import static java.util.Arrays.*;
import static java.util.Collections.*;


public class Main{ 


    static long mod=1000000007;
    //  static int dx[]={1,-1,0,0};
    //  static int dy[]={0,0,1,-1};
    // static int dx[]={1,-1,0,0,1,1,-1,-1};
    // static int dy[]={0,0,1,-1,1,-1,1,-1}; 

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

    
    Reader sc = new Reader(System.in);
    PrintWriter out=new PrintWriter(System.out);

  int n=sc.nextInt();  
  int c[] = new int[n*2];
     for( int i=0; i < 2*n; i++ ){
        c[i] = sc.nextInt();
     }
     sort(c);
int r=0;
     for( int i=2*n-1; -1 < i; i-=2 ){
        r+=min(c[i],c[i-1]);
    }

    out.println(r);
    out.flush();
}



static void db(Object... os){

    System.err.println(Arrays.deepToString(os));

}

static boolean validpos(int x,int y,int r, int c){
    
    return x<r && 0<=x && y<c && 0<=y;
    
}
 
static boolean bit(long x,int k){
    // weather k-th bit (from right) be one or zero
    return  ( 0 < ( (x>>k) & 1 )  )  ? true:false;
}

}







class Reader
{ 
    private BufferedReader x;
    private StringTokenizer st;
    
    public Reader(InputStream in)
    {
        x = new BufferedReader(new InputStreamReader(in));
        st = null;
    }
    public String nextString() throws IOException
    {
        while( st==null || !st.hasMoreTokens() )
            st = new StringTokenizer(x.readLine());
        return st.nextToken();
    }
    public int nextInt() throws IOException
    {
        return Integer.parseInt(nextString());
    }
    public long nextLong() throws IOException
    {
        return Long.parseLong(nextString());
    }
    public double nextDouble() throws IOException
    {
        return Double.parseDouble(nextString());
    }
}



Measured memory_bytes: 7764
#include <iostream>
#include <cstdio>
using namespace std;
int n, m, a, d[100005]={1,1}, v[100005], M = 1e9+7;
int main() {
	int i;
	cin>>n>>m;
	while(m--) {
		scanf("%d", &a);
		v[a] = 1;
		d[a] = 0;
	}
	for(i=2; i<=n; i++) {
		if(!v[i]) d[i] = (d[i-1] + d[i-2]) % M;
	}
	cout<<d[n];
	return 0;
}

Measured memory_bytes: 1024
package main

import (
	"bufio"
	. "fmt"
	"os"
)

// github.com/EndlessCheng/codeforces-go
func main() {
	in := bufio.NewReader(os.Stdin)
	var n, d, s, x, y int
	for Fscan(in, &n, &d); n > 0; n-- {
		if Fscan(in, &x, &y); x*x+y*y <= d*d {
			s++
		}
	}
	Print(s)
}


Measured memory_bytes: 5044
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		String a = sc.next();
		
		int result =0;
		// スペース区切りの整数の入力

		String[] fruits = a.split("");
        for (String fruit : fruits) {
                  if(fruit.equals("+")){result++;
}else{
result--;
}
        }




System.out.println(result);


	}
}

Measured memory_bytes: 21844
#include <iostream>
#include <vector>
#include <stack>
#include <queue>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <numeric>

using namespace std;

#define rep(i, n) for(int i = 0; i < n; i++)
#define repi(i, start, end) for(int i = start; i < end; i++)
#define all(x) (x).begin(), (x).end()
typedef long long ll;
const int MAX = 999999999;

int main(){
    int a, b, x;
    cin >> a >> b >> x;

    vector<int> nums;
    for(int i = a; i < a+x && i <= b; i++) nums.push_back(i);
    for(int i = b; i > b-x && i >= a; i--) nums.push_back(i);

    sort(all(nums));
    nums.erase(unique(all(nums)), nums.end());
    rep(i, nums.size()) cout << nums[i] << endl;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int X = sc.nextInt();
        sc.nextLine();
        int[] L = new int[N];
        int D = 0;
        int count = 0;
        for(int i=0; i<N;i++){
            L[i]=sc.nextInt();
        }
        while(D <= X ){
            if(count == N){
                count++;
                D += X;
            }else{
                D += L[count];
                count++;
            }

        }
        System.out.println(count);
    }
}

Measured memory_bytes: 22996
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define Would
#define you
#define please


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


	int N;
	char C;
	while (!isdigit(C = getchar_unlocked()));
	N = C - '0';
	while (isdigit(C = getchar_unlocked())) N = N * 10 + C - '0';

	char S[300000];
	fread_unlocked(S, 1, N, stdin);

	int A[300010];
	A[0] = 0;
	rep(i, N) {
		A[i + 1] = A[i];
		if (S[i] == 'W') A[i + 1]++;
	}

	int kotae = 1e9;
	rep(i, N) {
		kotae = min(kotae, A[i] + N - i - 1 - A[N] + A[i + 1]);
	}
	co(kotae);

	Would you please return 0;
}

Measured memory_bytes: 1792
N, Q=map(int, input().split())
S=input()
counter=[0]*N
for i in range(N-1):
  if S[i:i+2]=='AC':
    counter[i]+=1
    
  counter[i+1]=counter[i]

counter=[0]+counter
for i in range(Q):
  l, r=map(int, input().split())
  print(counter[r-1]-counter[l-1])


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


int main() {
  int64_t N, K;
  cin >> N >> K;
  
  
  int64_t q = N % K;
  int64_t p = (N - q) / K;  
  
  if (q <= K / 2){
  cout << q << endl;
  }
  else{
    cout << K * (p+1) - N << endl;
  }
}
  

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

// Define
using ll = int64_t;
using ul = uint64_t;
using ld = long double;
const ll MOD = 1e9 + 7;
const ll INF = LONG_MAX;
const ul MAX = ULONG_MAX;
const char nl = '\n';

#define elif else if
#define def inline auto
#define run __attribute__((constructor)) def _

// Debug
#define debug(x) cerr << (x) << " (L:" << __LINE__ << ")" << '\n'

// Loop
#define inc(i, a, n) for (ll i = (a), _##i = (n); i < _##i; ++i)
#define dec(i, a, n) for (ll i = (a), _##i = (n); i > _##i; --i)
#define rep(i, n) inc(i, 0, n)
#define be(c) begin(c), end(c)

// Stream
#define fout(n) cout << fixed << setprecision(n)
#define fasten cin.tie(0), ios::sync_with_stdio(0)

// Speed
run() { fasten, fout(10); }
#pragma GCC optimize("-O3")
#pragma GCC target("avx")

// Math
inline ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }

signed main(){
    ll X, Y;
    cin >> X >> Y;

    ll ans = 0;
    ll a = X;
    while(true){
        ++ans;
        a = a*2;
        if(Y < a) break;
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define debug(x) cout<<#x<<": "<<x<<endl
#define rep(i,n) for(int i=0;i<n;++i)
#define EPS 1e-9
typedef complex<double> Point;
typedef vector<Point> VP;
typedef pair<Point, Point> Line;
#define X real()
#define Y imag()

#define EQ(n,m) (abs((n)-(m)) < EPS)

namespace std {
  bool operator<(const Point a, const Point b) {
    return a.X != b.X ? a.X < b.X : a.Y < b.Y;
  }
  bool operator==(const Point a, const Point b) {
    return abs(a-b)<EPS;
  }
}

double dot(Point a, Point b) {
  return a.X*b.X + a.Y*b.Y;
}

// ?????????cross(a,b) = |a||b|sin??
double cross(Point a, Point b) {
  return a.X*b.Y - a.Y*b.X;
}

int ccw(Point a, Point b, Point c) {
  b -= a;  c -= a;
  if (cross(b,c) >  EPS) return +1;  // counter clockwise
  if (cross(b,c) < -EPS) return -1;  // clockwise
  if (dot(b,c)   < -EPS) return +2;  // c--a--b on line
  if (norm(b) < norm(c)) return -2;  // a--b--c on line or a==b
  return 0;                          // a--c--b on line or a==c or b==c
}

bool isecSS(Point a1, Point a2, Point b1, Point b2) {
  return ccw(a1, a2, b1)*ccw(a1, a2, b2) <= 0 &&
  ccw(b1, b2, a1)*ccw(b1, b2, a2) <= 0;
}

Point crosspointLL(Point a1, Point a2, Point b1, Point b2) {
  double d1 = cross(b2-b1, b1-a1);
  double d2 = cross(b2-b1, a2-a1);
  if (EQ(d1, 0) && EQ(d2, 0)) return a1;  // same line
  assert(!EQ(d2, 0)); // ???????????????
  return a1 + d1/d2 * (a2-a1);
}


int main(void){
    int n;
    while(cin>>n,n){
        vector<Line> ls(n);
        int crosscnt=0;
        rep(i,n){
            double p1x,p1y,p2x,p2y;
            cin>>p1x>>p1y>>p2x>>p2y;
            ls[i] = {{p1x,p1y},{p2x,p2y}};
            set<Point> cp;
            rep(j,i){
                if(isecSS(ls[i].first,ls[i].second,ls[j].first,ls[j].second)){
                    Point p = crosspointLL(ls[i].first,ls[i].second,ls[j].first,ls[j].second);
                    if(p.X>-100 && p.X<100 && p.Y>-100 && p.Y<100) cp.insert(p);
                }
            }
            crosscnt += (int)cp.size();
        }
        cout<<n+crosscnt+1<<endl;
    }

    return 0;
}

Measured memory_bytes: 3216
import java.util.Scanner;

public class Main {

	public static void main(String[] args)  {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		String op = sc.next();
		int b = sc.nextInt();

		System.out.println(op.equals("+") ? a + b : a - b);
	}
}

Measured memory_bytes: 21588
import string
s = {i : "{:05b}".format(c) for i, c in zip(string.ascii_uppercase+" .,-'?", range(32))}
code = {'101': ' ', '000000': "'", '000011': ',', '10010001': '-',
        '010001': '.', '000001': '?', '100101': 'A', '10011010': 'B',
        '0101': 'C', '0001': 'D', '110': 'E', '01001': 'F', '10011011': 'G',
        '010000': 'H', '0111': 'I', '10011000': 'J', '0110': 'K', '00100': 'L',
        '10011001': 'M', '10011110': 'N', '00101': 'O', '111': 'P', '10011111': 'Q',
        '1000': 'R', '00110': 'S', '00111': 'T', '10011100': 'U', '10011101': 'V',
        '000010': 'W', '10010010': 'X', '10010011': 'Y', '10010000': 'Z'}

while True:
    try:
        data = input()
    except:
        break
    d = ''.join(s[c] for c in data)
    ans=tmp=""
    for c in d:
        tmp += c
        if tmp in code:
            ans += code[tmp]
            tmp = ""
    print(ans)

Measured memory_bytes: 8016
#include <vector>
#include <iostream>


class Replace {
public:
	Replace() :vector(4), vertex(4, true){
		int n = 0;
		for (auto &i : vector) {
			i = n++;
		}
	}
	Replace top() const {
		Replace result(*this);
		result.topp();
		return result;
	}
	Replace right() const {
		Replace result(*this);
		result.rightp();
		return result;
	}
	Replace bottom() const {
		Replace result(*this);
		result.bottomp();
		return result;
	}
	Replace left() const {
		Replace result(*this);
		result.leftp();
		return result;
	}
	int to_i() const {
		int result = 0;
		for (const auto &i : vector) {
			result <<= 2;
			result += i;
		}
		result >>= 2;
		for (const auto &i : vertex) {
			result <<= 1;
			result += i;
		}
		return result;
	}
private:
	std::vector<int> vector;
	std::vector<bool> vertex;
	void swap(const int &a, const int &b) {
		auto temp = vector.at(a);
		vector.at(a) = vector.at(b); vector.at(b) = temp;
	}
	void swap(const int &i) {
		vertex.at(i) = !vertex.at(i);
	}
	void topp() {
		swap(0, 1); swap(0);
	}
	void rightp() {
		swap(1, 2); swap(1);
	}
	void bottomp() {
		swap(2, 3); swap(2);
	}
	void leftp() {
		swap(3, 0); swap(3);
	}
};
int detect(const int &top, const int &right, const int &sus1, const int &sus2) {
	if (sus1 == top || sus2 == top) {
		if (sus1 == right || sus2 == right) {
			return 1;
		}
		else {
			return 0;
		}
	}
	else {
		if (sus1 == right || sus2 == right) {
			return 2;
		}
		else {
			return 3;
		}
	}
}
int pazzle_to_i(const std::vector<int> &vector) {
	auto lambda = [&](const int &i, const int &j) -> int {
		return detect(vector.at(19), vector.at(13), vector.at(i), vector.at(j));
	};
	int result = 16 * lambda(15, 20) + 4 * lambda(18, 14) + lambda(12, 11);
	for (auto i : { 1,5,7,3 }) {
		result <<= 1;
		result += (vector.at(4) == vector.at(i));
	}
	return result;
}
void search(std::vector<int> &vector, const Replace &map = Replace(), const int &count = 0) {
	if (vector.at(map.to_i()) > count) {
		vector.at(map.to_i()) = count;
		search(vector, map.top(), count + 1); search(vector, map.right(), count + 1); search(vector, map.bottom(), count + 1); search(vector, map.left(), count + 1);
	}
}
int main() {
	int n;
	std::cin >> n;
	std::vector<int> vector(1 << 10, 1 << 30);
	search(vector);
	for (auto i = 0; i < n; ++i) {
		std::vector<int> arg(30);
		for (auto &i:arg){
			std::cin >> i;
		}
		std::cout << vector.at(pazzle_to_i(arg)) << std::endl;
	}
	return 0;
}

Measured memory_bytes: 1316
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define repp(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define repm(i,n) for(int (i)=(n-1);(i)>=0;(i)--)
#define INF (1ll<<60)
#define all(x) (x).begin(),(x).end()
typedef long long lint;
const lint MOD =1000000007;
const lint MAX = 10000000;
using Graph =vector<vector<lint>>;
typedef pair<lint,lint> P;

 
lint fac[MAX], finv[MAX], inv[MAX];

void COMinit() // 二項係数を求める時は前処理としてCOMinit()をする
{
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (lint i = 2; i < MAX; i++)
    {
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
 
// 二項係数計算
long long COM(lint n, lint k)
{
    if (n < k)
        return 0;
    if (n < 0 || k < 0)
        return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

lint primary(lint num)
{
    if (num < 2) return 0;
    else if (num == 2) return 1;
    else if (num % 2 == 0) return 0; // 偶数はあらかじめ除く

    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            // 素数ではない
            return 0;
        }
    }

    // 素数である
    return 1;
}
lint lcm(lint a,lint b){
      return a/__gcd(a,b)*b;
  }
 
  int main(){
      lint N,D;
      cin>>N>>D;
      lint x[N][D];
      rep(i,N){
          rep(j,D){
              cin>>x[i][j];
          }
      }
      lint ans=0;
      rep(i,N){
          repp(j,i+1,N){
              lint accum=0;
              rep(k,D){
                    accum+=(x[i][k]-x[j][k])*(x[i][k]-x[j][k]);
              }
              rep(i,1000){
                  if(accum==i*i)ans++;
              }
          }
      }
      cout<<ans;
  }
  

Measured memory_bytes: 256
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    int n, k;
    cin >> n >> k;
    int ar[n+5] = {};
    for(int i = 1; i <= n; i++)
    {
        cin >> ar[i];
    }
    int m[n+4] = {};
    for(int i = 1; i <= n; i++)
    {
        m[i] = m[i-1]+ar[i];
    }
    int lo = 0;
    ll Max = 0;
    for(int i = k; i <= n; i++)
    {
        ll p = m[i]-m[i-k];
        if(p > Max)
        {
            Max = p;
            lo = i-k+1;
        }
    }
    //cout << lo << endl;
    double res = 0.0;
    for(int i = lo; i <lo+k; i++)
    {
        ll sum = (ar[i]*(ar[i]+1))/2;
        //cout << sum << endl;
        double pp = (double)sum/(double)ar[i];
        res += pp;
    }
    //cout << res << endl;
    printf("%0.6f\n", res);
    return 0;
}


Measured memory_bytes: 1792
#include <iostream>
using namespace std;
int main(void){
    // Here your code !
    string w;
    cin >> w;
    string d;
    int k=0;
    while(cin >> d) {
        for(int i=0;i<d.size();i++) {
            d[i] = tolower(d[i]);
        }
        if(d == w) {
            k++;
        }
    }
    cout << k << endl;
}

Measured memory_bytes: 3224
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9+7;
//const long long MOD = ;
const long long INF_LL = 1e18+3; const int INF_int = 1e9+3;
#define ll long long
#define rep(i,n) for(int i = 0;i<n;i++)
#define lrep(i,n) for(long long i = 0;i<n;i++)
#define All(a) a.begin(),a.end()
#define Debug_Output_ALL(a) for(auto itr = a.begin();itr!=a.end();itr++) cout << *itr << " ";cout << endl;
int main(){
    ll n,m,l;
    cin >> n >> m >> l;
    ll dist[n][n];
    rep(i,n) rep(j,n) dist[i][j]=INF_LL/2;
    rep(i,n) dist[i][i]=0LL;
    rep(i,m){
        ll a,b,c;
        cin >> a >> b >> c;
        dist[a-1][b-1]=c;
        dist[b-1][a-1]=c;
    }
    rep(k,n) rep(i,n) rep(j,n) dist[i][j] = min(dist[i][j],dist[i][k]+dist[k][j]);
    int ans[n][n];
    rep(i,n) rep(j,n) ans[i][j]=INF_int/2;
    rep(i,n) rep(j,n) if(dist[i][j]<=l) ans[i][j]=1;
    rep(i,n) ans[i][i]=0;
    rep(k,n) rep(i,n) rep(j,n) ans[i][j] = min(ans[i][j],ans[i][k]+ans[k][j]);
    int q;
    cin >> q;
    vector<int> ansvec;
    rep(i,q){
        int s,t;
        cin >> s >> t;
        if(ans[s-1][t-1]==INF_int/2) ansvec.push_back(-1); 
        else ansvec.push_back(ans[s-1][t-1]-1);
    }
    rep(i,ansvec.size()) cout << ansvec[i] << endl;
}

Measured memory_bytes: 2040
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
using namespace std;
typedef long long unsigned int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

int main(){
  int x, y, z;
  cin >> x >> y >> z;

  cout << (x - z) / (y + z) << endl;

  return 0;
}

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

int main() {
    string S;
    cin >> S;
    string s1 = S.substr(0,2);
    string s2 = S.substr(2,2);
    int num1 = atoi((s1).c_str());
    int num2 = atoi((s2).c_str());
    bool isMM1 = 0 < num1 && num1 <= 12;
    bool isMM2 = 0 < num2 && num2 <= 12;
    if(isMM1 && isMM2){
        cout << "AMBIGUOUS" << endl;
    }else if(isMM1 && !isMM2){
        cout << "MMYY" << endl;
    }else if(!isMM1 && isMM2){
        cout << "YYMM" << endl;
    }else{
        cout << "NA" << endl;
    }


}

Measured memory_bytes: 256
import java.util.*;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int a = N/100;
        int b = a*100+a*10+a;
        if(N <= b)    System.out.println(b);
        else System.out.println(b+111);
    }
}

Measured memory_bytes: 23124
S,Q,*C = open(0).read().split()
s = list(S)

i = 0
while i < len(C):
    cmd = C[i]
    i += 1
    if cmd == "replace":
        a = int(C[i])
        b = int(C[i+1])
        p = C[i+2]
        i += 3
        for j in range(a, b+1):
            s[j] = p[j - a]
    elif cmd == "reverse":
        a = int(C[i])
        b = int(C[i+1])
        i += 2
        r = list(reversed(s[a:b+1]))
        for j, c in enumerate(r):
            s[j + a] = c
    elif cmd == "print":
        a = int(C[i])
        b = int(C[i+1])
        i += 2
        print("".join(s[a:b+1]))
    else:
        print(cmd)
        break



Measured memory_bytes: 5648
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define INF 100000000
#define rep(i,s,n) for (int i = (int)(s); i < (int)(n); i++)
#define mp make_pair
ll mod = 1000000007;
ll mod2 = 998244353;

int main(){
	cin.tie(0);
    ios::sync_with_stdio(false);
    int n;cin>>n;
    vector<ll> a(n);
    int ord = 0;
    int zero = 0;
    rep(i,0,n){
        cin>>a[i];
        if (a[i]<0) ord++;
        else if(a[i]==0) zero++;
        a[i] = abs(a[i]);
    }
    ll ans = 0;
    if (zero>0 || ord%2==0){
        rep(i,0,n){
            ans+=abs(a[i]);
        }
        cout<<ans<<endl;
    }else{
        rep(i,0,n){
            ans+=abs(a[i]);
        }
        ans-=*min_element(a.begin(),a.end())*2;
        cout<<ans<<endl;
    }
}

Measured memory_bytes: 3996
n = int(input())
ls = list(map(int, input().split()))

ls_s = sorted(ls)
md = (ls_s[int(n/2) - 1] + ls_s[int(n/2)]) / 2

for i in range(n):
    if ls[i] <= md:
        print(ls_s[int(n/2)])
    elif ls[i] > md:
        print(ls_s[int(n/2) - 1])

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

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()

int main() {
  int n,d;
  int ans=0;
  cin >> n>>d;
  vector<vector<int> > x(n);
  REP(i,n) {
    vector<int> xi(d);
    REP(j,d) {
      cin >> xi[j];
    }
    x[i] = xi;
  }
  REP(i,n-1) {
    FOR(j,i+1,n) {
      int dist=0;
      REP(k,d) {
	    int diff=x[i][k]-x[j][k];
	    diff*=diff;
        dist+=diff;
      }
      double dst = sqrt((double)dist);
      if (dst-(int)dst==0.0) {
        ans++;
      }
    }
  }
  cout << ans << endl;
}


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

int main() {
	vector<int> v;
	int x;
	int count = 1;
	while(1) {
		cin >> x;
		if (x == 0) break;
		else v.push_back(x);
	}
	for (auto n: v) {
		cout << "Case " << count << ": " << n << endl;
		count++;
	}
	return 0;
}

Measured memory_bytes: 3264
<?php
$haveCardNum = trim(fgets(STDIN));
$cardCheckList = createCardCheckList();
 
for ($i = 0; $i < $haveCardNum; $i++) {
    list($mark, $num) = getSpacesByExplodeTrimInput();
    $cardCheckList[$mark][$num] = 'check';
}
 
foreach ($cardCheckList as $mark => $value) {
    for ($cardNum = 1; $cardNum <= 13; $cardNum++) {
        if (! isset($cardCheckList[$mark][$cardNum])) {
            echo $mark.' '.$cardNum, PHP_EOL;
        }
    }
}
 
function getSpacesByExplodeTrimInput()
{
    return explode(' ', trim(fgets(STDIN)));
}
 
function createCardCheckList()
{
    return array(
        "S" => array_fill(1, 13, null),
        "H" => array_fill(1, 13, null),
        "C" => array_fill(1, 13, null),
        "D" => array_fill(1, 13, null)
    );
}

Measured memory_bytes: 15432
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int M = sc.nextInt();
		Main main = new Main();
		Store store[] = new Store[N];
		for (int i=0;i<N;i++) {
			Store temp = main.new Store();
			temp.A = sc.nextLong();
			temp.B = sc.nextInt();
			store[i] = temp;
		}
		Arrays.sort(store);
		long sum =0;
		int count=0;
		for (int i=0;i<N;i++) {
			if (count +store[i].B>=M) {
				sum += (M-count)*store[i].A;
				break;
			} else {
				sum +=store[i].B*store[i].A;
				count +=store[i].B;
			}
		}
		System.out.println(sum);
	}

	public class Store implements Comparable<Store> {
		long A;
		int B;
		@Override
		public int compareTo(Store o) {
			if (this.A>o.A)
				return 1;
			if (this.A==o.A)
				return 0;
			return -1;
		}

	}
}

Measured memory_bytes: 92824
#include <iostream>
#include <stdio.h>
#include <ctype.h>
#include <algorithm>
#define FOR1toN(a) for(int i=1;i<=a;i++)
#define FOR0ton(a) for(int i=0;i<a;i--) 
using namespace std;

int main()
{
	//freopen("in.txt","r",stdin);
	int n,k,arr[1100];
	scanf("%d%d",&n,&k);
	FOR1toN(n) scanf("%d",&arr[i]);

	sort(arr+1,arr+1+n);

    int ans=0;
	FOR1toN(k) ans+=arr[i];
	cout<<ans<<endl;



   return 0;
}

Measured memory_bytes: 3700
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main(){
  int n,m;
  cin >> n >> m;
  int k[m][n];
  rep(i,m){
    rep(j,n){
      k[i][j]=0;
    }
  }
  rep(i,m){
    int y;
    cin >> y;
    rep(j,y){
      int r;
      cin >> r;
      k[i][r-1]=1;
    }
  }
  int p[m];
  rep(i,m)cin >> p[i];
  int cnt=0;
  rep(i,(1<<n)){
    int c=0;
    rep(j,m){
      int q=0;
      rep(w,n){
        if(k[j][w]==1&&(i&(1<<w))){
          q++;
        }
      }
      if(q%2!=p[j])c=1;
    }
    if(c==0)cnt++;
  }
  cout << cnt << endl;
}  


Measured memory_bytes: 256