akhauriyash/Code-Regression huggingface dataset:
using namespace std;

#include <iostream>
#include <cstring>

int n, m, q;
int *a, *b, *c, *d;

int search_max_point(int depth, int* seq);
int calc_point(int* seq);

int main() {
    cin >> n >> m >> q;
    a = new int[q];
    b = new int[q];
    c = new int[q];
    d = new int[q];
    for (int i = 0; i < q; ++i) {
        cin >> a[i] >> b[i] >> c[i] >> d[i];
        a[i] -= 1;
        b[i] -= 1;
    }
    int ans = search_max_point(0, new int[n]);
    cout << ans;
    return 0;
}

int calc_point(int* seq) {
    int point = 0;
    for (int i = 0; i < q; ++i) {
        if (seq[b[i]] - seq[a[i]] == c[i]) {
            point += d[i];
        }
    }
    return point;
}

int search_max_point(int depth, int* seq) {
    if (depth == n) {
        return calc_point(seq);
    }
    int num_start;
    if (depth == 0) {
        num_start = 1;
    } else {
        num_start = seq[depth - 1];
    }
    int max_point = 0;
    int child_point;
    for(int num = num_start; num <= m; ++num) {
        int *child_seq = new int[n];
        memcpy(child_seq, seq, n * sizeof(int));
        child_seq[depth] = num;
        child_point = search_max_point((depth + 1), child_seq);
        if (child_point > max_point) {
            max_point = child_point;
        }
    }
    return max_point;
}

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

int main(){
 int N;
 cin >> N;
  
 int cmax=100/4;
 int dmax=100/7;
 for (int i=0;i<=cmax;i++){
   for (int j=0;j<=dmax;j++){
      if (i*4+j*7==N) {
       cout << "Yes" << endl;
       return 0;
      }
   }
 }
  cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <vector>

#define int long long
#define dotimes(i, n) for (int i = 0; i < (n); i++)

using namespace std;

int rint() {
  int n;
  scanf("%lld", &n);
  return n;
}

void wint(int n) {
  printf("%lld\n", n);
}

template<typename T>
inline int size(T container) {
  return static_cast<int>(container.size());
}

vector<pair<int, int>> factor(int n) {
  vector<bool> f; // true if composite
  vector<pair<int, int>> primaries;
  auto reduce =
    [&](int p) {
      int a = 0;
      while (n % p == 0) {
        n /= p;
        a++;
      }
      if (a)
        primaries.emplace_back(p, a);
    };
  auto is_prime =
    [=](int p) {
      int i = p / 2 - 1;
      return !(i < size(f) && f[i]);
    };
  auto mark_composite =
    [&](int c) {
      int i = c / 2 - 1;
      f.resize(i + 1, false);
      f[i] = true;
    };
  reduce(2);
  for (int p = 3; p * p <= n; p += 2)
    if (is_prime(p)) {
      reduce(p);
      int q = 2 * p;
      for (int c = p * p; c * c <= n; c += q)
        mark_composite(c);
    }
  if (n > 1)
    primaries.emplace_back(n, 1);
  return primaries;
}

signed main() {
  int n = rint();
  printf("%lld:", n);
  for (auto primary : factor(n))
    dotimes(i, primary.second)
      printf(" %lld", primary.first);
  puts("");
  return 0;
}



Measured memory_bytes: 2776
data = [int(input()) for _ in range(6)]
flag = True
for i in range(5):
    for j in range(i+1,5):
        length = abs(data[i] -data[j])
        if length > data[5]:
            flag = False
            break 
if flag:
  print("Yay!")
else:
  print(":(")

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

int main(){
    string a, b;
    cin >> a >> b;
    int an, bn;
    an = a[0] - '0';
    bn = b[0] - '0';
    if (an < bn){
        for(int i = 0; i < bn; i++)cout << a[0];
    }
    else {
        for(int i = 0; i < an; i++)cout << b[0];
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define rep1(i,n) for(int i=1;i<=(int)n;i++)
#define sp(n) cout << fixed << setprecision(n)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
typedef long long ll;
using namespace std;
int n;
vector<int> d(50);
int dfs(int i,vector<int>& x){
    if(i==n){
        int buf=24;
        x.push_back(0);
        x.push_back(24);
        sort(x.begin(),x.end());
        rep(j,n+1){
            chmin(buf,x[j+1]-x[j]);
        }
        return buf;
    }
    
    int res=0;
    auto nx1=x;
    nx1.push_back(d[i]);
    int buf=dfs(i+1,nx1);chmax(res,buf);
    auto nx2=x;
    nx2.push_back(24-d[i]);
    buf=dfs(i+1,nx2);chmax(res,buf);
    return res;
    
}

int main(void){
    cin>>n;
    map<int,int> mp;
    rep(i,n){
        cin>>d[i];
        mp[d[i]]++;
    }
    
    for(auto& p:mp){
        if(p.second>=3||p.first==0){
            cout<<0<<endl;
            return 0;
        }
        
    }
    if(n>=13){
        cout<<1<<endl;
        return 0;
    }
    vector<int> x;
    int res=dfs(0,x);
    cout<<res<<endl;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
const int MOD = 1e9 + 7;
typedef long long lint;
const int INF =1e7;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define trep(i, k, n) for (int i = (k); i < (int)(n); ++i)
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
int main(){
    int n,l;
    cin >> n >> l;
    vector<string> s(n);
    rep(i,n){
        cin >> s[i];
    }
    sort(s.begin(), s.end());
    string ans = "";
    rep(i,n){
        ans += s[i];
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
//Bismillahir rahmanir rahim
#include<bits/stdc++.h>
using namespace std;
int n;
int arr[100005];
int dp[100005];
int solve(int pos)
{
    if(pos==n) return 0;
    int &ret=dp[pos];
    if(ret!=-1) return ret;
    ret=1e9;
    if(pos+1<=n){
        ret=min(ret,solve(pos+1)+abs(arr[pos+1]-arr[pos]));
    }
    if(pos+2<=n){
        ret=min(ret,solve(pos+2)+abs(arr[pos+2]-arr[pos]));
    }
    return ret;
}
int main()
{
    scanf("%d",&n);
    for(int i=1;i<=n;i++) scanf("%d",&arr[i]);
    memset(dp,-1,sizeof(dp));
    int ans=solve(1);
    printf("%d\n",ans);
    return 0;
}


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

int main() {
	int N;
	cin >> N;
	int *a = new int[N];
	for (int i = 0; i < N; i++) cin >> a[i];

	int button = 1;
	int cnt = 0;
	while (cnt <= N) {
		button = a[button-1];
		cnt++;

		if (button == 2) break;
	}

	if (cnt != N + 1) {
		cout << cnt << endl;
	}
	else {
		cout << -1 << endl;
	}
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#include <iostream>
#include <string>
#include <cstdlib> 
#include <string.h>
#include <vector>
#include <cstdio>
#include <iomanip>
#include <stack>
#include <set>
#include <map>
#include <list>
#include <ctime>
#include <algorithm>
#include <cmath>
#define PI 3.1415926535897932384626433832795l
#define IOS ios :: sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define deci(n) cout<<fixed<<setprecision(n);
#define F first
#define S second
#define mk make_pair
#define pb push_back
#define ALPHA 27
#define ll long long int
#define ld long double
#define mmset(arr, n) memset(arr, n, sizeof arr)
#define debug(x) cerr << '#' << ' ' << x << '\n'
#define len(s) s.length()
#define ForA(i,a,b) for(int i = a; i < b; i++)
#define ForA1(i,a,b) for(int i = b - 1; i >= a; i--)
#define ForB1(i,a,b) for(int i = b; i > a; i--)
#define ForB(i,a,b) for(int i = a; i <= b; i++)
#define INT_SIZE 18 
#define maxn 1010
#define Maxn 100010

using namespace std;

const ll INF = (ll)(8e18);
const ll MOD = 1000000007;

char c[maxn][maxn];
int dp[maxn][maxn]; 

int main()
{
    IOS;       
    int h,w; cin >> h >> w;
    ForB(i,1,h){
        ForB(j,1,w) cin >> c[i][j];
    }
    dp[1][1] = 1;
    ForB(i,1,h){
        ForB(j,1,w){
            if(c[i][j] != '#'){
                dp[i][j] += dp[i - 1][j] + dp[i][j - 1];
                if(dp[i][j] >= MOD) dp[i][j] -= MOD;
            }
        }
    }
    cout << dp[h][w] << '\n';
    #ifdef LOCAL_DEFINE
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
    #endif
    return 0 ;
}


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

const int N=300005,mod=1000000007;
int ans;
char s[N];
int f[N][5][5];

int main(void)
{
	scanf("%s",s+1);
	register int len=strlen(s+1);
	f[0][0][0]=1;
	for(register int i=0;i<len;++i)
	{
		if(s[i+1]!='1')
		{
			for(register int j=0;j<3;++j)
				for(register int k=0;k<3;++k)
					if(k==2) f[i+1][j][k-1]=(f[i+1][j][k-1]+f[i][j][k])%mod;
					else f[i+1][j][k+1]=(f[i+1][j][k+1]+f[i][j][k])%mod;
		}
		if(s[i+1]!='0')
		{
			for(register int j=0;j<3;++j)
				for(register int k=0;k<3;++k)
					if(k==0) f[i+1][j+(j!=2)][k]=(f[i+1][j+(j!=2)][k]+f[i][j][k])%mod;
					else f[i+1][j][k-1]=(f[i+1][j][k-1]+f[i][j][k])%mod;
		}
	}
	for(register int i=0;i<3;++i)
		for(register int j=0;j<=i;++j)
			ans=(ans+f[len][i][j])%mod;
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 29824
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 $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")
    };
}

fn main() {
    input! {
        a: i32,
        b: i32
    }
    let muled = a * b;
    let moded = muled % 2;
    match moded {
        0 => println!("Even"),
        1 => println!("Odd"),
        _ => println!("Error"),
    }
}

Measured memory_bytes: 4352
#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <math.h>

using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;
using vc = vector<char>;
using vvc = vector<vc>;
template<class T> using hset = unordered_set<T>;
template<class Key, class T> using hmap = unordered_map<Key, T>;

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

int main() {
    int R0, W0, C, R;

    while (cin >> R0 >> W0 >> C >> R) {
        if (R0 == 0) break;
        int x = 0;
        while (C*W0 > R0 + x*R) x++;
        cout << x << endl;
    }

    return 0;
}

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


int main(){
  int A,B,M,i,j;
  cin >> A >> B >> M;
  vector<int> a(A),b(B);
  int mia=1000000;
  int mib=1000000;
  for(i=0;i<A;++i){
    cin >> a[i];
    mia=min(a[i],mia);
  }
  for(i=0;i<B;++i){
    cin >> b[i];
    mib=min(b[i],mib);
  }
  vector<int> x(M),y(M),c(M);
  for(i=0;i<M;++i){
    cin >> x[i] >> y[i] >> c[i];
  }
  int ans=mia+mib;
  for(i=0;i<M;++i){
    int cal=a[x[i]-1]+b[y[i]-1]-c[i];
    ans=min(ans,cal);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 2176
#include <stdio.h>
#include <math.h>
#define NMAX 300
#define EPS 1e-10
const double g = 9.8;

int n, v, x, y;
int left[NMAX], bot[NMAX], right[NMAX], top[NMAX];
int cmpi(double lb, double ub, double c);
int check(double qx, double qy);

int main(void)
{
  int i, hit;
  scanf("%d %d %d %d", &n, &v, &x, &y);
  for (i = 0; i < n; i++) {
    scanf("%d %d %d %d", &left[i], &bot[i], &right[i], &top[i]);
    if (right[i]> x) right[i] = x;
  }
  hit = check(x, y);
  for (i = 0; i < n; i++) {
    hit |= check(left[i], top[i]);
    hit |= check(right[i], top[i]);
  }
  printf("%s\n", hit ? "Yes" : "No");
}

int cmpi(double lb, double ub, double c)
{
  return c < lb + EPS ? -1 : c > ub - EPS ? 1 : 0;
}

int check(double qx, double qy)
{
  int i, d, hit = 1;
  double a = g * g / 4, b = g * qy - v * v, c = qx * qx + qy * qy;
  double D = b * b - 4 * a * c;
  if (D < 0 && D > -EPS) D = 0;
  if  (D < 0) return 0;
  for (d = -1; d <= 1; d += 2) {
    double t, vx, vy, yt, t2 = (-b + d * sqrt(D)) / (2 * a);
    if (t2 <= 0) continue;
    t = sqrt(t2);
    vx = qx / t;
    vy = qy / t + g * t / 2;
    yt = vy * x / vx - g * pow(x / vx, 2) / 2;
    if (yt < y - EPS) continue;
    for (i = 0; i < n; i++) {
      int yl, yr, xh, yh;
      if (left[i] >= x) continue;
      if (right[i] == x && y <= top[i] && bot[i] <= yt) {
        hit = 0;
        break;
      }
      yl = cmpi(bot[i], top[i], vy * left[i] / vx - g * pow(left[i] / vx, 2) / 2);
      yr = cmpi(bot[i], top[i], vy * right[i] / vx - g * pow(right[i] / vx, 2) / 2);
      xh = cmpi(left[i], right[i], vx * (vy / g));
      yh = cmpi(bot[i], top[i], vy * vy / g - g * pow(vy / g, 2) / 2);
      if ((xh ==0 && yh >= 0 && yl < 0) || (yl * yr <= 0)) {
        hit = 0;
        break;
      }
    }
    if (hit) return 1;
  }
  return 0;
}


Measured memory_bytes: 2100
#include <iostream>
#include <cstdio>

using namespace std;

typedef long long ll;
ll n, mx, sum, a[105];
int b[105][105];

void f(ll p)
{
    if(p > n)
    {
        sum = 0;
        for(ll i = 1; i <= n; i++)
        {
            sum += a[i];
        }
        mx = max(mx, sum);
        return;
    }
    f(p + 1);
    if(a[p] < 0) {
        for(int i = p; i <= n; i += p) b[p][i] = a[i];
        for(int i = p; i <= n; i += p) a[i] = 0;
        f(p + 1);
        for(int i = p; i <= n; i += p) a[i] = b[p][i];
    }
}

int main()
{
    scanf("%lld", &n);
    for(ll i = 1; i <= n; i++)
    {
        scanf("%lld", &a[i]);
    }
    for(ll i = n / 2 + 1; i <= n; i++)
    {
        if(a[i] < 0) a[i] = 0;
    }
    f(1);
    printf("%lld", mx);
    return 0;
}


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

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

  if (text == "hi") {
    cout << "Yes" << endl;
  }
   else if (text == "hihi") {
    cout << "Yes" << endl;
  }
   else if (text == "hihihi") {
    cout << "Yes" << endl;
  }
   else if (text == "hihihihi") {
    cout << "Yes" << endl;
  }
   else if (text == "hihihihihi") {
    cout << "Yes" << endl;
  }
 else {
   cout << "No" << endl;
 } 
}


Measured memory_bytes: 256
from sys import stdin
from collections import defaultdict
n = int(stdin.readline())

dp = defaultdict(int)
for i in range(0, n):
    cur = [int(i) for i in stdin.readline().split(' ')]
    dp[(i, "a")] = cur[0]+max(dp[(i-1, "b")], dp[(i-1, "c")])
    dp[(i, "b")] = cur[1]+max(dp[(i-1, "a")], dp[(i-1, "c")])
    dp[(i, "c")] = cur[2]+max(dp[(i-1, "a")], dp[(i-1, "b")])

print(max(dp[(n-1, "a")], dp[(n-1, "b")], dp[(n-1, "c")]))

Measured memory_bytes: 47444
/*痛みを受け取れ，痛みを知れ*/
#include<bits/stdc++.h>
#define f(i,a,b) for(register int i=a;i<=b;++i)
#define ff(i,a,b) for(register int i=a;i>=b;--i)
#define debug(x) cerr << #x << " : " << x << " " << endl
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<string, string> pss;
const ll mod = 1e9 + 7;
const int inf = 0x3f3f3f3f;
const double tiaohe = 0.57721566490153286060651209;
ll oula(ll x) { ll res = x;f(i, 2, x / i) { if (x % i == 0) { res = res / i * (i - 1);while (x % i == 0) x /= i; } }if (x > 1) res = res / x * (x - 1);return res; }
ll quickmod(ll a, ll n, ll m) { ll s = 1;while (n) { if (n & 1) { s = s * a % m; }a = (a*a) % m;n = n / 2; }return s; }
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
void ex_gcd(ll a, ll b, ll &x, ll &y, ll &d) { if (!b) { d = a, x = 1, y = 0; } else { ex_gcd(b, a % b, y, x, d);y -= x * (a / b); } }
ll inv(ll t, ll p) { ll d, x, y;ex_gcd(t, p, x, y, d);return d == 1 ? (x % p + p) % p : -1; }
bool isPrime(ll x) { if (x == 2)return true;if (x % 2 == 0)return false;for (ll i = 2;i*i <= x;i++) if (x % i == 0)return false; return true; }
//double a = log(n) +tiaohe + 1.0 / (2 * n);
double eqa = (1 + sqrt(5.0)) / 2.0;
const int N = 5e5 + 5;

int main()
{
	//freopen("in.txt", "r", stdin);
	ll a, b, c;
	while (cin >> a >> b >> c)
	{
		ll k = a / (b + c);
		cout << k * b + min(b, a % (b + c)) << endl;
	}
	return 0;
}

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

int main(){
	string str;
	cin >> str;
	//str = "abcde";
	long q;
	cin >> q;
	//q = 1;
	for (long i = 0; i < q; i++){
		long a = 0, b = 0;
		string p;
		string order;
		cin >> order;
		//order = "print";
		if (order == "print"){
			cin >> a >> b;
			//a = 1;
			//b = 3;
			cout << str.substr(a, b - a + 1) << endl;
		}
		else if (order == "reverse"){
			cin >> a >> b;
			//a = 1;
			//b = 3;
			string str2;
			str2 = str.substr(a, b - a + 1);
			//cout << str2 << endl;
			reverse(str2.begin(), str2.end());
			//cout << str2 << endl;
			str = str.replace(a, b - a + 1, str2);
			//cout << str << endl;
		}
		else if (order == "replace"){
			cin >> a >> b >> p;
			str = str.replace(a, b - a + 1, p);
		}
	}
	return 0;
}

Measured memory_bytes: 1220
#include <stdio.h>
#include <math.h>

int main(){
	int i,j,n;
	int count=0;
	scanf("%d",&n);
	for(i=0;i<n;i++){
		int x;
		scanf("%d",&x);
		int d;
		j=2;
		while(j<=sqrt(x)){
			d=x%j;
			if(x%j==0) break;
			j++;
		}
		if(d!=0) count++;
	}
	printf("%d\n",count);
	return 0;
}

Measured memory_bytes: 2652
#include <iostream>
#include <algorithm>
#include <string>
#define int long long
using namespace std;
signed main() {
	int n, a[114514], ans = 0;
	cin >> n; for (int i = 0; i < n; i++)cin >> a[i];
	sort(a, a + n);
	if (n % 2 == 0) {
		for (int i = n - 1; i > n / 2; i--) ans += a[i] * 2; ans += a[n / 2];
		for (int i = 0; i < n / 2 - 1; i++) ans -= a[i] * 2; ans -= a[n / 2 - 1];
		cout << ans << endl;
	}
	else {
		int ans1 = 0;
		for (int i = n - 1; i > n / 2 + 1; i--)ans += a[i] * 2; ans += a[n / 2] + a[n / 2 + 1];
		for (int i = 0; i < n / 2; i++)ans -= a[i] * 2;
		for (int i = n - 1; i > n / 2; i--)ans1 += a[i] * 2;
		for (int i = 0; i < n / 2 - 1; i++)ans1 -= a[i] * 2; ans1 -= a[n / 2] + a[n / 2 - 1];
		cout << max(ans, ans1) << endl;
	}
}

Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <string>
#include <queue>
using namespace std;
#define ll long long
#define rep(i, s, n) for(int i = s; i < n; i++)

int ans = 2510;
int h, w;
vector<string> s(50);
typedef pair<int, int> P;

void bfs(int x, int y, int cost, vector<vector<int>> flag) {
    //cout << "x: " << x << " y: " << y << " cost: " << cost << endl;
    /*
    for(int i = 0; i <= h; i++) {
        for(int j = 0; j <= w; j++) {
            cout << flag[i][j];
        }
        cout << endl;
    }
    cout << endl;
    */
    
    if(x == w && y == h) {
        ans = min(ans, cost);
        return;
    }
    if(s[y][x] == '#') {
        flag[y][x] = 1;
        return;
    }
    flag[y][x] = 1;
    if(y+1 <= h && flag[y+1][x] == 0) bfs(x, y+1, cost+1, flag);
    if(x+1 <= w && flag[y][x+1] == 0) bfs(x+1, y, cost+1, flag);
    if(y-1 >= 0 && flag[y-1][x] == 0) bfs(x, y-1, cost+1, flag);
    if(x-1 >= 0 && flag[y][x-1] == 0) bfs(x-1, y, cost+1, flag);
    return;
}

int main() {
    cin >> h >> w;
    int count = 0;
    int xp[4] = {0, 1, 0, -1};
    int yp[4] = {1, 0, -1, 0};
    vector<vector<int>> flag(h, vector<int> (w, 0));
    for(int i = 0; i < h; i++) {
        cin >> s[i];
        for(int j = 0; j < w; j++) {
            if(s[i][j] == '#') count++;
        }
    }
    queue<P> que;
    que.push({0, 0});
    vector<vector<int>> dist(h, vector<int>(w, 0));
    dist[0][0] = 0;
    while(!que.empty()) {
        P p = que.front(); que.pop();
        int x = p.second; int y = p.first;
        for(int i = 0; i < 4; i++) {
            int px = xp[i]+x;
            int py = yp[i]+y;
            if(px < w && px >= 0 && py < h && py >= 0 && s[py][px] == '.' && flag[py][px] == 0) {
                que.push({py, px});
                flag[py][px] = 1;
                dist[py][px] += dist[y][x]+1;
            }
        }
    }
    if(dist[h-1][w-1] == 0) cout << -1 << endl;
    else cout << h*w-dist[h-1][w-1]-count-1 << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream> 
 
using namespace std; 
 
int main(){ 
	int n;
	cin >> n;
	int a_1[n];
	int a_2[n];
	for(int i = 0; i < n; i++){
		cin >> a_1[i];
	}
	for(int i = 0; i < n; i++){
		cin >> a_2[i];
	}
	
	int ans[n];
	int max_ans = 0;
	for(int i = 0; i < n; i++){
		ans[i] = 0;
		for(int j = 0; j < n; j++){
			if(j == i) ans[i] += a_1[j] + a_2[j];
			else if(j > i) ans[i] += a_2[j];
			else if(j < i) ans[i] += a_1[j];
		}
		max_ans = (ans[i] > max_ans)?ans[i]:max_ans;
	}
	cout << max_ans << endl;
}


Measured memory_bytes: 3596
import java.util.*;

class Main{
    void solve(){
        Scanner sc = new Scanner(System.in);
        int N, x, y, b, p;
        N = sc.nextInt();
        for(int i = 0; i < N; ++i) {
           x = sc.nextInt();
           y = sc.nextInt();
           b = sc.nextInt();
           p = sc.nextInt();
           System.out.println(Math.min(x*b+y*p, (x*Math.max(b,5)+y*Math.max(p,2))*4/5) );
        }
    }

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






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

int main(){
  int A1,A2,A3;
  cin >>A1>>A2>>A3;
  if (A1+A2+A3 >= 22){
    cout <<"bust"<<endl;
  }
  else {
    cout <<"win"<<endl;
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <math.h>
#include <numeric>
#include <set>
#include <unordered_set>
#include <queue>
#include <cmath>
 
using namespace std;
#define ll long long
#define rep(i, n) for(int i = 0;i < n;i++)
#define FOR(i, n, m) for(int i=n; i<m; ++i)

using Graph = vector<vector<int>>;

// 深さ優先探索
vector<bool> seen;
void dfs(const Graph &G, int v) {
    seen[v] = true; // v を訪問済にする

    // v から行ける各頂点 next_v について
    for (auto next_v : G[v]) { 
        if (seen[next_v]) continue; // next_v が探索済だったらスルー
        dfs(G, next_v); // 再帰的に探索
    }
}

int main() {
  ll X, N, t;
  cin >> X >> N;
  vector<ll> p;
  rep(i,N){ 
    cin >> t;
    p.push_back(t);
  }
  
  if(find(p.begin(), p.end(), X) == p.end()){
    cout << X << endl;
    return 0;
  }
  
  ll x1,x2;
  x1 = X-1;
  x2 = X+1;
  while(1){
    if(find(p.begin(), p.end(), x1) == p.end()){
  	  cout << x1 << endl;
      return 0;
    }
    if(find(p.begin(), p.end(), x2) == p.end()){
  	  cout << x2 << endl;
      return 0;
    }
    x1--;
    x2++;
  }
  
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
#define Int int64_t

using namespace std;

int main() {
	string V = "Vacant", M = "Male", F = "Female";
	int N;
	cin >> N;

	string f0, f1;
	cout << 0 << endl;
	cin >> f0;
	if (f0 == V) { return 0; }
	cout << N - 1 << endl;
	cin >> f1;
	if (f1 == V) { return 0; }

	int l = 0, r = N - 1;
	string s;
	int cnt = 0;
	while (r - l > 1 && cnt++ < 19) {
		int m = (r + l) / 2;

		cout << m << endl;
		cin >> s;
		if (s == V) { return 0; }
		if (s == f0) {
			if (m % 2 == 0) { l = m; }
			else { r = m; }
		} else {
			if (m % 2 == 0) { r = m; }
			else { l = m; }
		}
	}

	return 0;
}


Measured memory_bytes: 852
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees#, log2
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10**9 + 7
#from decimal import *
 
R, G, B, N = MAP()
ans = 0

for r in range(N//R + 1):
	for g in range((N-r*R)//G + 1):
		if (N - R*r - G*g) % B == 0:
			ans += 1
		
print(ans)

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


int main()
{
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    if(fabs(c-a)<=d)
    {
        cout<<"Yes\n";
        return 0;
    }
    if(fabs(b-a)<=d&&fabs(c-b)<=d)
    {
        cout<<"Yes\n";
        return 0;
    }
    else
        cout<<"No\n";
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <cmath>
#include <iomanip>
#include <bitset>
#include <string>
#include <stdlib.h>
using namespace std;
//cout <<  << endl;
typedef long long int ll;
typedef long double ld;

int main(){
    ll a,b;
    cin >> a >> b;
    if (b%a==0){
        cout << a+b <<  endl;
        return 0;
    }
    cout << b-a <<  endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
   int n,k;
   cin>>k>>n;
   if(k==1)
    cout<<n<<endl;
   else
   {
       vector<int>v;
       int z=n;
       v.push_back(n);
       for(int i=1;i<k;i++)
       {
          z--;
          v.push_back(z);
       }
       int z1=n;
       for(int i=1;i<k;i++)
       {
          z1++;
          v.push_back(z1);
       }
       sort(v.begin(),v.end());
       for(auto c:v)
        cout<<c<<" ";
   }

    return 0;
}




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

int find(int x,int y,int z)
{
  	int a[3];
  	a[0] = x, a[1] = y, a[2] = z;
	sort(a,a+3);
  	return a[1];
}

int main()
{
  int n;
  cin>>n;
  int* p = new int[n];
  for(int i=0;i<n;i++)
    cin>>p[i];
  int count = 0;
  
  for(int i=0;i<n-2;i++)
  {
    int x = p[i],y=p[i+1],z=p[i+2];
    int k = find(x,y,z);
    if(k==p[i+1])
      count++;
  }
  cout <<count<<endl;
    return 0;
}

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

string s, t;
vector<int>ans;
bool change(int t_i, int s_i){
    if((s[s_i]==t[t_i]||s[s_i]=='?')) {
        ans.push_back(s_i);
        if(t_i==0) return true;
        else return change(t_i-1, s_i-1);
    }
    return false;
}
int main(void){
    cin>>s>>t;
    vector<string> kouho;
    for(int i=t.size()-1;i<=s.size()-1;i++){
        if(change(t.size()-1, i)){
            string tmp=s;
            rep(i, ans.size()) tmp[ans[i]]=t[t.size()-1-i];
            rep(i, tmp.size()){
                if(tmp[i]=='?') tmp[i]='a';
            }
            kouho.push_back(tmp);
        }
        ans=vector<int>();
    }
    if(kouho.size()==0) {
        cout<<"UNRESTORABLE"<<endl;
        return 0;
    }
    sort(kouho.begin(), kouho.end());
    cout<<kouho[0]<<endl;
    return 0;
}

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

struct parts{int power; int motor; int cable; int pass;};

int main(){
	int a, b, c;
	int N;
	int is_disorder[300];
	parts result[1000];	
	for(;;){
		cin >> a >> b >> c;
		if(a == 0 && b == 0 && c == 0) break;
		for(int i = 0; i < a + b + c; i++) is_disorder[i] = 2;
		cin >> N;
		for(int i = 0; i < N; i++){
			cin >> result[i].power >> result[i].motor >> result[i].cable >> result[i].pass;
			result[i].power--; result[i].motor--; result[i].cable--;
			if(result[i].pass == 1){
				is_disorder[result[i].power] = 1;
				is_disorder[result[i].motor] = 1;
				is_disorder[result[i].cable] = 1;
			}
		}
		for(int i = 0; i < N; i++){
			if(result[i].pass == 0){
				if(is_disorder[result[i].power] == 1 && is_disorder[result[i].motor] == 1) is_disorder[result[i].cable] = 0;
				if(is_disorder[result[i].power] == 1 && is_disorder[result[i].cable] == 1) is_disorder[result[i].motor] = 0;
				if(is_disorder[result[i].motor] == 1 && is_disorder[result[i].cable] == 1) is_disorder[result[i].power] = 0;
			}
		}
		for(int i = 0; i < a + b + c; i++){
			cout << is_disorder[i] << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 3004
use std::io::*;

fn main() {
    let mut s: String = String::new();
    std::io::stdin().read_to_string(&mut s).ok();
    let mut itr = s.trim().split_whitespace();
    let n: usize = itr.next().unwrap().parse().unwrap();
    let mut h: i64 = itr.next().unwrap().parse().unwrap();

    let mut a: Vec<i64> = vec![0; n];
    let mut b: Vec<i64> = vec![0; n];
    for i in 0..n {
        a[i] = itr.next().unwrap().parse().unwrap();
        b[i] = itr.next().unwrap().parse().unwrap();
    }
    a.sort();
    a.reverse();
    b.sort();
    b.reverse();

    let mut idx = 0u64;
    while idx < n as u64 && h > 0 && b[idx as usize] > a[0] {
        h -= b[idx as usize];
        idx += 1;
    }
    if h > 0 {
        idx += ((h + a[0] - 1) / a[0]) as u64
    }
    println!("{}", idx);
}


Measured memory_bytes: 10232
#  --*-coding:utf-8-*--

def fulkerson(graph, src, sink):
    n = len(graph)

    matrix = [[0]*n for i in range(n)]
    bothDirGraph = [[] for i in range(n)]

    for nodeId, edges in enumerate(graph):
        for nodeId2, flowLimit in edges:
            matrix[nodeId][nodeId2] = flowLimit
            bothDirGraph[nodeId].append(nodeId2)
            bothDirGraph[nodeId2].append(nodeId)

    while True:
        path = findPath(bothDirGraph, matrix, src, sink)

        if path == None:
            break

        v = min(matrix[path[i]][path[i+1]] 
                for i in range(len(path)-1))

        for i in range(len(path)-1):
            node1 = path[i]
            node2 = path[i+1]
            
            matrix[node1][node2] -= v
            matrix[node2][node1] += v

    return (sum(c for _, c in graph[src]) - 
            sum(c for c in matrix[src]))


def findPath(bothDirGraph, matrix, src, sink):
    prevs = [None]*len(matrix)
    q = set([src])
    prevs[src] = src

    while len(q) > 0:
        node = q.pop()

        for nextNode in bothDirGraph[node]:
            if prevs[nextNode] == None and matrix[node][nextNode] > 0:
                prevs[nextNode] = node
                
                if nextNode == sink:
                    path = []
                    pathNode = sink

                    while pathNode != src:
                        path.append(pathNode)
                        pathNode = prevs[pathNode]

                    path.append(src)
                    return list(reversed(path))

                q.add(nextNode)

    return None
                    

def main():
    N = int(input())
    graph = [[] for i in range(2*N+2)]
    
    for i in range(N):
        graph[0].append(((i+1)*2, 1))
        graph[(i+1)*2+1].append((1, 1))

    p1s = [tuple(map(int, input().split())) for i in range(N)]
    p2s = [tuple(map(int, input().split())) for i in range(N)]

    for i1, p1 in enumerate(p1s):
        for i2, p2 in enumerate(p2s):
            if p1[0] < p2[0] and p1[1] < p2[1]:
                graph[(i1+1)*2].append(((i2+1)*2+1, 1))

    print(fulkerson(graph, 0, 1))


if __name__ == '__main__':
    main()


Measured memory_bytes: 3700
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define erep(i,a,b) for(int i=a;i<=(int)(b);++i)
#define per(i,a,b) for(int i=(a);i>(b);--i)
#define eper(i,a,b) for(int i=(a);i>=b;--i)
#define fore(x, a) for(auto &x : a)
#define pb push_back
#define mp make_pair
#define INF 100100100100
#define inf 2001001001
#define MOD 1000000007
#define ALL(x) begin(x),end(x)
using namespace std;
using ll = long long;
using pii = pair<int,int>;
using vii = vector<int>;
using vll = vector<ll>;
template<class T>using vv = vector<T>;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
template<class T>void show(const vector<T> &a) { for (int i = 0; i < (int)a.size(); ++i) cout << a[i] << (i != (int)a.size()-1 ? " " : "\n"); }
template<class T>T gcd(T a, T b){ return b ? gcd(b, a % b) : a; }
template<class T>T lcm(T a, T b){ return a / gcd(a, b) * b; }
int dy[]={0, 1, -1, 0};
int dx[]={1, 0, 0, -1};

int n;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
    cin >> n;
    vll t(n), a(n), mi(n, 0);
    rep(i, 0, n) cin >> t[i];
    rep(i, 0, n) cin >> a[i];
    rep(i, 0, n) mi[i] = min(t[i], a[i]);
    ll ans = 1;
    if (t[n-1] != a[0]) {
      cout << 0 << endl;
      return 0;
    }
    rep(i, 1, n-1) {
      if (t[i] == t[i-1] && a[i] == a[i+1]) {
        ans = (ans * mi[i]) % MOD;
      }
      else if (t[i-1] < t[i] && a[i] == a[i+1] && a[i] < t[i]) {
        ans = 0;
      } 
      else if (t[i-1] == t[i] && a[i] > a[i+1] && a[i] > t[i]) {
        ans = 0;
      }
      else if (t[i-1] > t[i] && a[i] < a[i+1] && a[i] != t[i]) {
        ans = 0;
      }
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 2560
/*
        karmany evadhikaras te
        ma phalesu kadacana 
        ma karma-phala-hetur bhur
        ma re sango'stv akarmani (B.G.-2.47)
 
Translation:
        Lord Krsna to Arjuna.
You have a right to perform your prescribed duty, 
but you are not entitled to the fruits of action. 
Never consider yourself the cause of the results of your activities, 
and never be attached to not doing your duty.    
*/
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int N = 200005;
const ll mod = 1e9+7;
#define ld long double
#define PI 3.14159265358979323846
const int X = 10000000;

void flash()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cout.setf(ios::fixed);
    cout.setf(ios::showpoint);
    cout.precision(10);
}

//3. Structure or classes
//3. Ends here

//1. Data structures declaration here
//1. Ends here

//2. Extra Functions here
//2. Ends here


void solve();
int32_t main()
{
    flash();
    int t;
    t = 1;
    //cin>>t;
    for (int zz = 0; zz < t; zz++)
    {
        solve();
        //cout<<"\n";
    }
    return 0;
}

void solve()
{
    int n;
    cin>>n;
    vector<int>c(n+1,0);
    for(int i=1;i<=n;i++){
        for(int j=0;(j+=i)<=n;){
            c[j]++;
        }
    }
    ll ans=0;
    for(int i=1;i<=n;i++){
        ans+=1ll*i*c[i];
    }
    cout<<ans;
    return;
}



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

int main(){
    int n, a, b;
    cin >> n >> a >> b;
    
    long long int ans = (long long int)b*(n-1)+a
    - ((long long int)a*(n-1)+b) + 1;
    if(ans >= 1) cout << ans << endl;
    else cout << 0 << endl;
    return 0;
}

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

int main() {
    int A;
    int B;
    cin >> A >> B;

    int result = 0;

   for (int i = A; i <= B; i++) {
       int firstDigit = i % 10;
       int secondDigit = i /10 % 10;
       int fourthDigit = i / 1000 % 10;
       int fifthDigit = i / 10000 % 10; 

       if (firstDigit == fifthDigit && secondDigit == fourthDigit) {
           result++;
       }
   } 

    cout << result << endl; 
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <cstdio>
 
const static double PI = 4*atan(1.0);
 
using namespace std;
 
 
int count=0;
 
 
  
void Koch_curve(int n, double p1x, double p1y, double p2x, double p2y){
    double sx, sy, tx, ty, ux, uy;
     
    if(n == 0){
        //cout << p2x << ' ' << p2y << endl;
        printf("%.4lf %.4lf\n", p2x, p2y);
        count++;
    }
    else{
        n--;
        sx = p1x + (p2x-p1x)*(1.0/3.0);
        sy = p1y + (p2y-p1y)*(1.0/3.0);
        tx = p1x + (p2x-p1x)*(2.0/3.0);
        ty = p1y + (p2y-p1y)*(2.0/3.0);
 
        //求め方は http://www.infra.kochi-tech.ac.jp/takagi/Survey2/3PolarRect.pdf　
        // 極座標の回転　（二次元回転行列）
        ux= sx + (tx-sx)*cos(PI/3.0) - (ty-sy)*sin(PI/3.0);
        uy= sy + (tx-sx)*sin(PI/3.0) + (ty-sy)*cos(PI/3.0);
 
        Koch_curve(n, p1x, p1y, sx, sy);
        Koch_curve(n, sx, sy, ux, uy);
        Koch_curve(n, ux, uy,tx, ty);
        Koch_curve(n, tx, ty, p2x, p2y);
    }
     
}
  
int main() {
    int n;
     
    cin >> n;
    //cout.setf(ios::fixed, ios::floatfield); //固定小数表記 
    //cout << 0.0 << ' ' << 0.0 << endl;
    printf("%.4lf %.4lf\n", 0.0, 0.0);
    Koch_curve(n, 0.0, 0.0, 100.0, 0.0);
         
        return 0;
}


Measured memory_bytes: 3184
#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<numeric>
#include<cmath>
#include<queue>
#include<stack>
#include<list>
#include<unordered_map>
#include<unordered_set>
#include<cctype>
#include<iomanip>
#include<limits>
#include<bitset>

using namespace std;
typedef long long int ll; typedef pair<int, int> P;
const ll mod = 1000000007;
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(a) (a).begin(),(a).end()
#define allg(a) (a).begin(),(a).end(),greater<>()
#define SUM(a) accumulate((a).begin(),(a).end(),0)
#define d10 std::setprecision(10)
#define d20 std::setprecision(20)
const double PI = 3.14159265359;
ll gcd(ll a, ll b) { ll t; while (b != 0) { t = a % b; a = b; b = t; }return a; }
int gcd(int a, int b) { int t; while (b != 0) { t = a % b; a = b; b = t; }return a; }
ll recfact(ll start, ll n) {
	ll i;
	if (n <= 16) {
		ll r = start;
		for (i = start + 1; i < start + n; i++) r = r * i % mod;
		return r % mod;
	}
	i = n / 2;
	return recfact(start, i) % mod * recfact(start + i, n - i) % mod;
}
ll fct(ll n) { return recfact(1, n); }
ll ncm(ll n, ll m) {
	if (n < m)return 0;
	ll x = (fct(n) % mod / (fct(m) * fct(n - m)) % mod) % mod;
	return x;
}
bool isincluded(char x, string str) {
	bool f = 0;
	for (size_t i = 0; i < str.size(); i++) {
		if (str.at(i) == x)f = 1;
	}
	return f;
}
int ctoi(char c) {
	if ('0' <= c && c <= '9') {
		return c - '0';
	}
	return 0;
}


int main(void) {
	string str; cin >> str;
	ll n = (ll)str.size() - 1;
	ll ans = 0;
	for (ll bit = 0; bit < (1 << n); ++bit) {
		ll tmp = ctoi(str.at(0));
		//cout << "init " << tmp << endl;
		for (int i = 0; i < n; i++) {
			if (bit & (1 << i)) {
				ans += tmp;
				tmp = ctoi(str.at(i + 1));
				//cout << i << " tmp " << tmp << endl;
			}
			else {
				tmp = tmp * 10 + ctoi(str.at(i + 1));
				//cout << i << " tmp " << tmp << endl;
			}
		}
		ans += tmp;
		//cout << "ans " << ans << endl;
	}
	cout << ans << endl;


	return 0;
}

Measured memory_bytes: 256
icase=0
if icase==0:
    from itertools import permutations, combinations,combinations_with_replacement,product
    n,d=map(int,input().split())
    x=[]
    for i in range(n):
        xi=list(map(int,input().split()))
        x.append(xi)
    xc=list(combinations(x,2))
    icnt=0
    for xxc in xc:
        dist=0
        x1=xxc[0]
        x2=xxc[1]
        for i in range(d):
            dist=dist+(x1[i]-x2[i])**2
        dist=dist**0.5
        if int(dist)==dist:
            icnt+=1
    print(icnt)      

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

namespace ABC
{
    class ProgramC
    {
        static void Main(string[] args)
        {
            var inputs = Console.ReadLine().Split(" ");
            var d = int.Parse(inputs[0]);
            var g = int.Parse(inputs[1]);

            var pList = new int[d];
            var cList = new int[d];
            for (var i = 0; i < d; i++)
            {
                var inputs1 = Console.ReadLine().Split(" ");
                pList[i] = int.Parse(inputs1[0]);
                cList[i] = int.Parse(inputs1[1]);
            }

            var ans = int.MaxValue;
            for (var i = 0; i < 1 << d; i++)
            {
                var num = 0;
                var s = 0;
                var restMax = 0;
                for (var j = 0; j < d; j++)
                {
                    if (((i >> j) & 1) == 1)
                    {
                        s += 100 * (j + 1) * pList[j] + cList[j];
                        num += pList[j];
                    }
                    else
                    {
                        restMax = j;
                    }
                }

                if (s < g)
                {
                    var p = 100 * (restMax + 1);
                    var need = (g - s + (p - 1)) / p;
                    if (need >= pList[restMax])
                        continue;
                    num += need;
                }
                ans = Math.Min(ans, num);
            }

            Console.WriteLine(ans);
        }
    }
}


Measured memory_bytes: 27516
import java.util.Scanner;

class Main{
       public static void main(String[] args){
    	Scanner scan = new Scanner(System.in);
    	int r = scan.nextInt();
    	int c = scan.nextInt();
    	int[][] num = new int[r + 1][c + 1];
    	
    	for(int i = 0; i < r; i++){
    		for(int j = 0; j < c; j++){
        		num[i][j] = scan.nextInt();
        	}
    	}
    	
    	for(int i = 0; i < r; i++){
    		for(int j = 0; j < c; j++){
    			num[i][c] += num[i][j];
    		}
    	}
    	for(int j = 0; j < c + 1; j++){
    		for(int i = 0; i < r; i++){
    			num[r][j] += num[i][j];
    		}
    	}
    	
    	for(int i = 0; i < r + 1; i++){
    		for(int j = 0; j < c + 1; j++){
    			if(j != c){
    				System.out.print(num[i][j] + " ");
    			}else{
    				System.out.println(num[i][j]);
    			}
    		}
    	}
    }
}

Measured memory_bytes: 41356
#include<iostream>
#include<math.h>
#include<algorithm>
#include<stdint.h>
#include<vector>
#include<deque>
#include<stack>
#include<string>
#include<cstring>
#include<time.h>
#include<iomanip>
#include<list>
#include<set>
#include<unordered_map>
#include<unordered_set>
#include<random>
#include<bitset>
#include <queue>
#include <map>


using namespace std;
using ll = long long;
using ull = unsigned long long;
using uint = unsigned int;
using ldouble = long double;


#define repi(i,a,b) for(ll i = (a); i < (b); i++)
#define rep(i, n) for(ll i = 0; i < (n); ++i)


//正剰余
long long mod(long long a, long long b)
{
	return a - (long long)std::floor((double)a / (double)b) * b;
}
ll MOD = 1000000007;
ll inf = 1e18;
int main() {
	ull cur = 100;
	ull x;
	cin >> x;
	int c = 0;
	while (true) {
		c++;
		cur = cur + (cur / 100);
		if (cur >= x) {
			cout << c << endl;
			return 0;
		}
	}
	return 0;
}


Measured memory_bytes: 3680
n,m = map(int,input().split())
di = [[] for _ in range(n)]
ac = 0
wa = 0
for i in range(m):
    a,b = map(str,input().split())
    di[int(a)-1].append(b)
for j in range(n):
    if "AC" in di[j]:
        wa += di[j].index("AC")
        ac += 1
print(ac,wa)

Measured memory_bytes: 20364
using System;
using System.Collections.Generic;//list用
using System.Text;//StringBuilder用
using System.Collections;
using System.Linq;
class Program
{
    static List<int>[] s;
    static decimal result;
static Hashtable ht=new Hashtable();
static int N,M;
static long[,] table;
    static void Main()
    {
Read1();
      Read2();
      int tmpresult;
      int[,,] t=new int[N,N,2];
      for(int i=0;i<N;i++){
      for(int j=0;j<N;j++){
        if(i==j){continue;}
      t[i,j,0]=s[i][0]-s[j][0];
      t[i,j,1]=s[i][1]-s[j][1];        
      }
      }
      //tがp,qの可能性のある配列。これを全チェック。
      result=0;
             for(int i=0;i<N;i++){
      for(int j=i+1;j<N;j++){
        if(t[i,j,0]==0 && t[i,j,1]==0){continue;}
        tmpresult=0;
      for(int x=0;x<N;x++){
      for(int y=0;y<N;y++){
        if(x==y){continue;}
        if(s[x][0]-s[y][0]==t[i,j,0] && s[x][1]-s[y][1]==t[i,j,1])
        {tmpresult++;}
      }
      }
      if(tmpresult>result){result=tmpresult;}
      }
      }
      result=N-result;
                    Console.WriteLine(result.ToString());

    }

    static void Read1()
    {
        string tmp = Console.ReadLine();
        N = int.Parse(tmp);
    }

    static void Read2()
    {
      
        string[] tmp;
      s=new List<int>[N];
      for(int j=0;j<N;j++)
      {
        s[j]=new List<int>();
      tmp= Console.ReadLine().Split(' ');
        for (int i = 0; i <2; i++) { s[j].Add(int.Parse(tmp[i])); }
      }
    }

}

Measured memory_bytes: 11220
#include<iostream>
#include<cmath>
#include<algorithm>
//#define MODE 1
#ifdef MODE
#define DEB(X) cout<<#X<<": "<<X<<" ";
#define ARDEB(i,X) cout<<#X<<"["<<i<<"]: "<<X[i]<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define ARDEB(X) {}
#define END {}
#endif
using namespace std;
int main(){
	int n;
	int a[100001],co=0,ans=0;
	cin>>n;
	for(int i=0;i<n;i++)cin>>a[i];
	sort(a,a+n);
	for(int i=0;i<n;i++){
		if(a[i]==a[i+1])co++;
		if(a[i]!=a[i+1]){
			co++;
			if(co%2==1)ans++;
			co=0;
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 640
import math

N, A, B = [int(_) for _ in input().split()]
H = sorted([int(input()) for _ in range(N)])

sup = sum([h // A + 1 for h in H])
inf = 1

while sup - inf > 1:
    x = (sup + inf) // 2
    c = sum([math.ceil((h - x * B)/(A-B)) for h in H if h > x * B])
    if c <= x:
        sup = x
    else:
        inf = x

print(sup)







Measured memory_bytes: 10944
#include <bits/stdc++.h>
long long int mod = 1000000000 + 7;



int main() {
    int n, m;
    std::cin>>n>>m;
    std::vector<std::string> input(n);
    for(int i =0; i < n;i++) {
        std::cin>>input[i];
    }
    std::vector<std::vector<long long int>> dp(n, std::vector<long long int>(m, 0));
    dp[0][0] = 1;
    bool seen = true;
    for(int i = 1; i<m;i++) {
        if (input[0][i] == '#') seen = false;
        dp[0][i] = seen;
    }  
    seen = true;
    for(int i = 1; i < n; i++) {
        if (input[i][0] == '#') seen = false;
        dp[i][0] = seen;
    }

    for(int i = 1; i < n; i++) {
        for(int j = 1; j < m; j++) {
            if(input[i][j] == '.') {
                dp[i][j] = (dp[i-1][j] + dp[i][j-1]) %  mod;
            } else {
                dp[i][j] = 0;
            }
        }
    }
    std::cout << dp[n-1][m-1]<< std::endl;
}

Measured memory_bytes: 9216
#include <bits/stdc++.h>
#define ll long long
using namespace std;
 
ll gcd(ll a, ll b){
  if(b == 0){
    return a;
  }
  else{
    return gcd(b,(a%b));
  }
}
ll lcm(ll a,ll b){
  return a/gcd(a,b)*b;
}
ll mpower(ll a,ll b,ll c){
  int z;
  if(b==0){
    z=1;
    z%=c;
    return z;
  }
  if(b==1){
    z=a;
    z%=c;
    return z;
  }
  else{
    return (((mpower(a,b/2,c))*(mpower(a,b/2,c))%c)*mpower(a,b%2,c)%c);
  }
}

int main(){
  int h,w,a,b;
  cin>>h>>w>>a>>b;
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      if(i<b&&j<a){
        cout<<0;
      }
      else if(i>=b&&j>=a){
        cout<<0;
      }
      else{
        cout<<1;
      }
    }
    cout<<endl;
  }
}

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


int main()
{
    ll N,min=1000000000;
    cin >> N;

    int X[N];
    int tmp;

    rep(i,N) cin >> X[i];

    for(int p=1;p<=100;p++){
        tmp=0;
        rep(i,N) tmp += (X[i]-p)*(X[i]-p);
        if(tmp<min) min =tmp;
    }

    cout <<min <<endl;
 
    return 0;

}

Measured memory_bytes: 256
#ABC062C

h,w=map(int,raw_input().split())
res=[]
#case1
s1=(h/3)*w
s2=(h-h/3)*(w/2)
s3=h*w-s1-s2
s=[s1,s2,s3]
res.append(max(s)-min(s))
#case2
s1=((h/3)+1)*w
s2=(h-h/3-1)*(w/2)
s3=h*w-s1-s2
s=[s1,s2,s3]
res.append(max(s)-min(s))
#case3
s1=s2=(h/3)*w
s3=h*w-2*s1
s=[s1,s2,s3]
res.append(max(s)-min(s))
#case4
s1=(h/3)*w
s2=(h/3+1)*w
s3=h*w-s1-s2
s=[s1,s2,s3]
res.append(max(s)-min(s))

w,h=h,w
#case5
s1=(h/3)*w
s2=(h-h/3)*(w/2)
s3=h*w-s1-s2
s=[s1,s2,s3]
res.append(max(s)-min(s))
#case5
s1=((h/3)+1)*w
s2=(h-h/3-1)*(w/2)
s3=h*w-s1-s2
s=[s1,s2,s3]
res.append(max(s)-min(s))
#case7
s1=s2=(h/3)*w
s3=h*w-2*s1
s=[s1,s2,s3]
res.append(max(s)-min(s))
#case8
s1=(h/3)*w
s2=(h/3+1)*w
s3=h*w-s1-s2
s=[s1,s2,s3]
res.append(max(s)-min(s))
print min(res)


Measured memory_bytes: 2696
#include <iostream>
#include <string>
using namespace std;
int main(){
    string s;
    cin>>s;
    for(int i=0; i<s.size()-1; i++){
        if (s[i]=='A'&&s[i+1]=='C'){
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout<<"No"<<endl;
}

Measured memory_bytes: 256