akhauriyash/Code-Regression huggingface dataset:
let dbg = Printf.printf "[debug]%s"

let max_num = 1_000_000_000

let id = fun x -> x
let tuple2 x y = (x,y)
let tuple3 x y z = (x,y,z)
let succ x = x + 1
let pred x = x - 1

let (++) n m =
  let rec aux i =
    if i = m then [m]
    else i :: aux (i+1) in
  if n > m then [] else aux n

let (++^) n m = n ++ (m-1)

let scan fmt f = Scanf.sscanf (read_line ()) fmt f

let scan_lines n fmt f =
  List.map (fun _ -> scan fmt f) (0++^n)

let scan_matrix n m e conv =
  let arr = Array.make_matrix n m e in
  Array.iteri (fun i line ->
      let s = Scanf.Scanning.from_string @@ read_line () in
      Array.iteri (fun j _ ->
          arr.(i).(j) <- Scanf.bscanf s " %s" conv;
        ) line) arr; arr

let between n x m = n <= x && x < m

let string_to_list s =
  List.map (String.get s) (0 ++^ String.length s)

let (v,e) = scan "%d %d" tuple2
let edges =
  let a = Array.make_matrix v v None in
  scan_lines e "%d %d %d" tuple3
  |> List.iter (fun (x,y,z)-> a.(x).(y) <- Some z);
  a


let solve start =
  let memo = Array.make_matrix (1 lsl v) v None in
  let rec aux s w = match memo.(s).(w) with
    | Some va -> va
    | None ->
      if s = (1 lsl v) - 1 then
        if start = w then 0 else max_num
      else
        let va =
          List.filter (fun i -> s land (1 lsl i) = 0) (0 ++^ v)
          |> List.map (fun x ->
              match edges.(w).(x) with
              | None -> max_num
              | Some e -> e + aux (s lor (1 lsl x)) x)
          |> List.fold_left min max_num in
        memo.(s).(w) <- Some va; va in
  aux 0 start

let () =
  List.map (fun i -> solve i) (0 ++^ v)
  |> List.fold_left min max_num
  |> (fun va -> if va >= max_num then -1 else va)
  |>  Printf.printf "%d\n"



Measured memory_bytes: 20664
#include <bits/stdc++.h>
#define int int64_t
#define REP(i, n) for (int i = 0; (i) < (int)(n); ++ (i))
#define REP3(i, m, n) for (int i = (m); (i) < (int)(n); ++ (i))
#define REP_R(i, n) for (int i = (int)(n) - 1; (i) >= 0; -- (i))
#define REP3R(i, m, n) for (int i = (int)(n) - 1; (i) >= (int)(m); -- (i))
#define REPP(i, n) for (int i = 1; (i) < (int)(n+1); ++ (i))
#define REPR(i, n) for (int i = (int)(n) - 1; (i) >= 0; -- (i))
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define FORR(i, m, n) for(int i=(m)-1; i>=(n); i--)
#define ALL(v) v.begin(), v.end()
#define SZ(a) int((a).size())
#define SORT(c) sort((c).begin(),(c).end())
#define SORTR(c) sort((c).begin(),(c).end(),greater<int>());
#define BIT(n) (1LL<<(n))
#define PCNT(x) __builtin_popcountll(x)
#define GCD(x,y) __gcd(x,y)
#define LCM(x,y) x/__gcd(x,y)*y
#define PB push_back
#define MP make_pair
#define endl "\n"
#define yes cout << "Yes" << endl
#define no cout << "No" << endl
using namespace std;
using Graph = vector<vector<int> >;
using WeightedGraph = vector<vector<pair<int, int> > >;
typedef long double LD;
typedef vector<int> VI;
typedef vector<vector<int> > VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef vector<PII> VPII;
const int INF = 2000000000;
const long double PI = acosl(-1);
const int MOD = 1000000007;
void print() {cout << endl;}
template <class Head, class... Tail> void print(Head&& head, Tail&&... tail) {cout << head; if (sizeof...(tail) != 0) cout << " ";print(forward<Tail>(tail)...);}
template <class T> void print(vector<T> &vec) {for (auto& a : vec) {cout << a; if (&a != &vec.back()) cout << " ";} cout << endl;}
template <class T> void print(vector<vector<T>> &df) { for (auto& vec : df) { print(vec);}}


signed main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    cout << fixed << setprecision(10);
    int ans = 0;
    
    string S, T;
    cin >> S >> T;
    if (S == T.substr(0,S.length()) && S.length() == T.length() - 1) yes;
    else no;
    
    
    
    return 0;
}

/*
cd ~/Desktop/Programming/AtCoder/contest/abc167/abc167_a && sh shellscripts/test_cpp.sh
cd ~/Desktop/Programming/AtCoder/contest/abc167/abc167_a && sh shellscripts/etest_cpp.sh
cd ~/Desktop/Programming/AtCoder/contest/abc167/abc167_a && sh shellscripts/submit_cpp.sh
*/


Measured memory_bytes: 3652
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,k;
  scanf("%d%d",&n,&k);
  vector<int> height(n);
  for(int i=0;i<n;i++) cin>>height[i];
  vector<int> dp(n,INT_MAX);
  dp[0]=0;
  dp[1]=abs(height[1]-height[0]);
  for(int i=2;i<n;i++){
    int x=i-1,count=0;
    while(count<k && x>=0){
      dp[i]=min(dp[i],dp[x]+abs(height[i]-height[x]));
      x--;count++;
    }
  }
  printf("%d",dp[n-1]);
  return 0;
}

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

using i64 = int64_t;

#define rep(i, x, y) for (i64 i = i64(x), i##_max_for_repmacro = i64(y); i < i##_max_for_repmacro; ++i)
#define debug(x) #x << "=" << (x)

#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define print(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define print(x)
#endif

const int inf = 1.01e9;
const i64 inf64 = 4.01e18;
const double eps = 1e-9;

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

template <typename T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
    os << "[";
    for (const auto &v : vec) {
        os << v << ",";
    }
    os << "]";
    return os;
}

template <typename T>
bool chmin(T &a, const T &b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}

template <typename T>
bool chmax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

void solve() {
    //const i64 mod = 1'000'000'007;

    i64 N,M;
    cin >> N >> M;

    vector<bool> vb(10);
    vector<i64> cost={-1,2,5,5,4,5,6,3,7,6};

    assert(cost.size()==10);

    vector<i64> A(M);
    rep(i,0,M){
        cin >> A[i];
        vb[A[i]]=true;
    }

    vector<string> dp(N+1);
    dp[0]="0";
    rep(i,1,N+1){
        rep(j,1,10) {
            if (!vb[j]) continue;
            if (i - cost[j] < 0) continue;
            if (dp[i - cost[j]].empty()) continue;
            if (dp[i - cost[j]] == "0") {
                string tmp;
                tmp += '0' + j;
                if(tmp.length()<dp[i].length()) continue;
                if(tmp.length()>dp[i].length()){
                    dp[i]=tmp;
                    continue;
                }
                chmax(dp[i], tmp);
            } else {
                if(dp[i-cost[j]].length()+1<dp[i].length()) continue;
                if(dp[i-cost[j]].length()+1>dp[i].length()){
                    dp[i]=dp[i - cost[j]] + char('0' + j);
                    continue;
                }
                chmax(dp[i], dp[i - cost[j]] + char('0' + j));
            }
        }
    }

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

int main() {
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(16);
    solve();
    return 0;
}


Measured memory_bytes: 39296
#include<stdio.h>

void main(){
  char s[16];
  scanf("%s",&s);
  
  char t[16];
  scanf("%s",&t);
  
  int tf=0;
  
  int i;
  for(i=0;i<16;i++){
    if(s[i]=='\0'){
      if(t[i]!='\0'&&t[i+1]=='\0'){
        tf=1;
        break;
      }else{
        tf=0;
        break;
      }
    }else if(s[i]!=t[i]){
      tf=0;
      break;
    }
  }
  if(tf==0)
    printf("No\n");
  else
    printf("Yes\n");
}

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

int main() {
    long int a;
    double b;
    cin >> a >> b;
    
    long int ib;
    ib = b * 100 + 0.1;
    
    a = a * ib;
    a /= 100;
    
    cout << a << endl;
    
    return 0;
}




Measured memory_bytes: 3728
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;

const long long MOD = 1000000007LL;
const long long INF = 1e18;

int GCD(int a, int b){return b == 0 ? a : GCD(b, a % b);}
long long fast_exp(long long base, long long exp, long long mod = MOD) {
    long long tot = 1;
    for(;exp > 0;exp >>= 1) {
       if((exp & 1) == 1) tot = tot * base % mod;
       base = base * base % mod;
    }
    return tot;
}
long long mult_mod(long long base, long long exp, long long mod = MOD) {
    long long tot = 0;
    for(;exp > 0;exp >>= 1){
       if((exp & 1) == 1) tot = (tot + base) % mod;
       base = base * 2 % mod;
    }
    return tot;
}

struct chash {
    static uint64_t splitmix64(uint64_t x) {x += 0x8e3779b97f4a7c15; x = (x ^ (x >> 30)) * 0xbf54876d1ce4e5b9; x = (x ^ (x >> 27)) * 0x94d049bb133111eb; return x ^ (x >> 31);}
    size_t operator()(uint64_t x) const { static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count(); return splitmix64(x + FIXED_RANDOM);}
    size_t operator()(pair<uint64_t,uint64_t> x) const { static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count(); return splitmix64(x.first + FIXED_RANDOM)^(splitmix64(x.second + FIXED_RANDOM) >> 1);}
};

int main(){

    cin.sync_with_stdio(0); cin.tie(0); cout.tie(0);

    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);

    int a, b; cin >> a >> b;

    cout << max(a + a - 1, max(b + b - 1, a + b));

    return 0;
}


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

long double dp[301][301][301];

int n;
long double foo(int c1,int c2,int c3)
{
	if(dp[c1][c2][c3] != (-1)) return dp[c1][c2][c3];
	if(c1 == 0 && c2 ==0 && c3==0) return 0;
	 
	long double ans = n*1.0;

	if(c1 > 0) ans+= (c1*foo(c1-1,c2,c3));
	if(c2 > 0) ans+= (c2*foo(c1+1,c2-1,c3));
	if(c3 > 0) ans+= (c3*foo(c1,c2+1,c3-1));

	ans = ans/(0.0+c1+c2+c3);
	dp[c1][c2][c3] = ans;
	return ans;
}
int main()
{

	for(int i=0;i<=300;i++)
	{
		for(int j=0;j<=300;j++)
			for(int k=0;k<=300;k++)
				dp[i][j][k] = (-1);
	}
	cin>>n;
	int one = 0,two=0,three = 0;
	for(ll i=0;i<n;i++)
	{
		int x ;
		cin>>x;
		if(x==1) one++;
		if(x==2) two++;
		if(x==3) three++;
	}
	cout<<setprecision(15)<<foo(one,two,three)<<endl;
	return 0;
}

Measured memory_bytes: 426496
#include <stdio.h>

int main()
{
  int i, n, t, len=1;
  fscanf(stdin, "%d", &n);
  int a[n];
  fscanf(stdin, "%d", &a[0]);
  for (i=1; i<n; i++) {
    fscanf(stdin, "%d", &t);
    if (a[len-1]!=t) a[len++]=t;
  }
  for (i=0; i<len-1; i++)
    printf("%d ", a[i]);
  printf("%d\n", a[i]);

  return 0;
}



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

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

    vector<int> a(n);
    int odd = 0, e2 = 0, e4 = 0;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        if (a[i] % 2) {
            odd++;
        }
        else if (a[i] % 4) {
            e2++;
        }
        else {
            e4++;
        }
    }

    bool f = false;
    if (odd - e4 + e2 % 2 < 2) {
        f = true;
    }

    cout << (f ? "Yes" : "No") << endl;

    return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <iomanip>
#include <vector>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <cstring>
#define rep(i, N) for (int i = 0; i < (int)N; i++)
using namespace std;
typedef long long ll;
const ll LLINF = 9223372036854775807;
const int MOD = 1000000007;

int main() {
  ll S, C; cin >> S >> C;

  ll result = 0;
  if (S>=C/2) result = C/2;
  else result = S + (C-2*S) / 4;
  cout << result << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n,a=1,b=10,ans;
int main(){
	scanf("%d",&n);
	while(a<=n){
		for(int i=a;i<=min(b-1,n);i++)ans++;
		a*=100;b*=100;
	}
	printf("%d",ans);
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
int a,b,c,g;
cin>>a>>b>>c;
g=a;
a=b;
b=g;
g=a;
a=c;
c=g;
printf("%d %d %d",a,b,c);
return 0;
}

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

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

int main() {
	cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
	int n; cin>>n;
	int x=sqrt(n);
	cout << x*x << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#ifdef ENABLE_DEBUG
#define DEBUG(a) cerr<<#a<<"="<<a<<endl
#define DEBUG_ARRAY(a,n) cerr<<#a<<"["<<n<<"]="<<a[n]<<endl
#else
#define DEBUG(a) 
#define DEBUG_ARRAY(a,n) 
#endif
#define FOR(i, a, b) for(int i = a;i < b;i++)
#define For(i, a) FOR(i, 0, a)
#define REV(i, a, b) for(int i = b-1;i >= a;i--)
#define Rev(i, a) REV(i, 0, a)
#define REP(a) For(i, a)

typedef long long int ll;
typedef unsigned long long ull;
typedef unsigned int uint;
typedef pair<ll, ll> P;
typedef pair<ll,P> PP;
typedef vector<ll> vll;

const ll INF=(1LL<<50);


void solve(long long N, std::vector<long long> A, std::vector<long long> B){
    ll ans=0;
    vector<P> ab;
    REP(N){
        ab.push_back(P(A[i],B[i]));
    } 
    sort(ab.begin(),ab.end(),[](P a,P b){return (a.first+a.second)>(b.first+b.second);});
    REP(N){
        if(i%2==0){
            ans+=ab[i].first;
        }else{
            ans-=ab[i].second;
        }
    }
    cout<<ans<<endl;
}

int main(){
    long long N;
    scanf("%lld",&N);
    std::vector<long long> A(N);
    std::vector<long long> B(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&A[i]);
        scanf("%lld",&B[i]);
    }
    solve(N, std::move(A), std::move(B));
    return 0;
}


Measured memory_bytes: 3956
#include<bits/stdc++.h>
#define N 300010
#define EPS 1e-9
#define PI acos(-1)
#define MOD 1000000007
#define INF 0x3f3f3f3f
#define fs first
#define sc second
#define db double
#define pb push_back
#define ll long long
#define VI vector<int>
#define PII pair<int,int>
#define PQ priority_queue
#define NP next_permutation
#define ull unsigned long long
#define sz(a) (int)a.size()
#define len(a) (int)strlen(a)
#define all(a) a.begin(),a.end()
#define mem(a,b) memset(a,b,sizeof(a))
#define F(i,j,k) for(register int i=j;i<=k;i++)
#define CK1(x) cout<<"["<<(x)<<"]\n";
#define CK2(x,y) cout<<"["<<(x)<<","<<(y)<<"]\n";
#define CK3(x,y,z) cout<<"["<<(x)<<","<<(y)<<","<<(z)<<"]\n";
#define IOS ios::sync_with_stdio(false)
using namespace std;
istream &operator >> (istream &in,VI &v){for(auto &i:v)in>>i;return in;}
ostream &operator << (ostream &out,VI &v){for(auto i:v)out<<i<<" ";return out;}
int main()
{
    IOS;
#if 0
    int T;cin>>T;
    while(T--)
#endif
    {
        int n;
        cin>>n;
        map<string,int> mp;
        while(n--)
        {
            string s;
            cin>>s;
            mp[s]++;
        }
        cout<<"AC x "<<mp["AC"]<<"\n";
        cout<<"WA x "<<mp["WA"]<<"\n";
        cout<<"TLE x "<<mp["TLE"]<<"\n";
        cout<<"RE x "<<mp["RE"];
    }
}


Measured memory_bytes: 3664
import java.util.Scanner;
 
public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    long[] x = new long[N+1];
    for (int i =0; i<N+1; i++) {
      x[i] = sc.nextLong();
    }
    long dist; long D = Math.abs(x[1] - x[0]);
    for (int i =1; i<N+1; i++) {
      dist = Math.abs(x[i] - x[i - 1]);
      D = gcd(dist,D);
    }
    System.out.println(D);
  }
  
  static long gcd(long a, long b) {
    if (b > 0) {
      return gcd(b, a % b);
    } else {
      return a;
    } 
  }
}

Measured memory_bytes: 60332
// I SELL YOU...! 
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
#include<chrono>
#include<iomanip>
#include<map>
#include<set>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using TP = tuple<ll,ll,ll>;
void init_io(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(18);
}
signed main(){
  init_io();
  ll d,n=26,score=0;
  cin >> d;
  vector<ll> c(n),contest(d);
  vector<vector<ll>> s(d,vector<ll>(n));
  for(int i=0;i<n;i++){
    cin >> c[i];
  }
  for(int i=0;i<d;i++){
    for(int j=0;j<n;j++){
      cin >> s[i][j];
    }
  }
  for(int i=0;i<d;i++){
    cin >> contest[i];
    contest[i]--;
  }
  for(int i=0;i<d;i++){
    score += s[i][contest[i]];
    for(int j=0;j<n;j++){
      ll day = 0;
      for(int k=i;k>=0;k--){
        if(contest[k]==j){
          day = k+1;
          break;
        }
      }
      score -= (i+1-day)*c[j];
    }
    cout << score << endl;
  }
}


Measured memory_bytes: 3744
#include <stdio.h>
#include <string.h>
#include <iostream>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <map>
#include <string>
#include <algorithm>
#include <numeric>
#include <utility>
#include <cmath>

using namespace std;

typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;

const int iinf = 1 << 29;
const int imax = ~(1 << 31);
const long long linf = 1ll << 61;
const long long lmax = ~(1ll << 63);

#define dump(x) cerr << #x << " : " << x << '\n'
#define MOD(x, y) (((y) + (x) % (y)) % (y))

int main(int argc, char* argv[])
{
	int N, M;
	scanf("%d%d", &N, &M);
	ll ans;
	if (N == 1) {
		if (M == 1) {
			ans = 1;
		} else {
			ans = M - 2;
		}
	} else {
		if (M == 1) {
			ans = N - 2;
		} else {
			ans = ll(N - 2) * ll(M - 2);
		}
	}
	printf("%lld\n", ans);

	return 0;
}


Measured memory_bytes: 256
let split str delim =
  let rec doit s acc =
    match
      try Some (String.index s delim)
      with _ -> None
    with
    | None -> s :: acc
    | Some i ->
        let s1 = String.sub s 0 i in
        let s2 = String.sub s (i + 1) (String.length s - String.length s1 - 1) in
        doit s2 (s1 :: acc)
  in
  List.rev (doit str [])

let () =
  let l = read_line () in
  match List.map int_of_string (split l ' ') with
  | [] -> exit 1
  | [_] -> exit 1
  | a :: b :: _ -> Printf.printf "%d %d\n" (a * b) (2*a + 2*b)

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

using namespace std;

int main() {
	int n;
	cin >> n;
	vector<int> dish(n), buff(n), c(n - 1);
	for (int i = 0; i < n; i++) {
		cin >> dish[i];
	}
	for (int i = 0; i < n; i++) {
		cin >> buff[i];
	}
	for (int i = 0; i < n - 1; i++) {
		cin >> c[i];
	}
	int total = buff[dish[0]-1];
	//cout << "primeiro passo: " << total << endl;
	for (int i = 1; i < n; i++) {
		total += buff[dish[i]-1];
		if (dish[i - 1] == dish[i] - 1) {
			total += c[dish[i-1]-1];
		}
	}
	cout << total << endl;
	return 0;
}

Measured memory_bytes: 256
using System;

namespace VSC
{
    class Program
    {
        static void Main(string[] args)
        {
            int N = int.Parse(System.Console.ReadLine());
            String S = System.Console.ReadLine();
            int K = int.Parse(System.Console.ReadLine());
            Char[] str = S.ToCharArray();
            Char chr = str[K - 1];

            foreach(var s in str){
                
                if( s == chr)
                {
                    System.Console.Write( chr); 
                }
                else
                {
                    System.Console.Write( '*'); 
                }
            }
          
        }
    }
}


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

typedef long long ll;
typedef unsigned long long int ull;
#define endl "\n"
#define pb push_back
#define sq(a) (a)*(a)
#define debug(x) cerr<<#x<<'='<<(x)<<endl;
#define debugv(v) cerr<<#v<<" : ";for (auto x:v) cerr<<x<<' ';cerr<<endl;
#define MOD 1000000007
#define PI 3.141592653589793238
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);

ll gcd(ll a, ll b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
}

ll exp(ll x,ll n,ll mod)
{
    ll result=1;
    while(n>0)
    {
        if(n & 1 ==1)
            result=(result * x)%mod;
        x=(x*x)%mod;
        n=n>>1;
    }
    return result;
}



int32_t main()
{
    IOS

    ll n,w;
    cin>>n>>w;

    ll v[n],wt[n];

    for(ll i=0;i<n;i++)
    {
    	cin>>wt[i]>>v[i];
    }

    ll dp[n+1][w+1];
	memset(dp,0,sizeof(dp));
    for(ll i=1;i<=n;i++)
    {
    	for(ll j=1;j<=w;j++)
    	{
    		if(wt[i-1]>j)
    			dp[i][j]=dp[i-1][j];
    		else
    			dp[i][j]=max(v[i-1]+dp[i-1][j-wt[i-1]],dp[i-1][j]);
    	}
    }

    cout<<dp[n][w]<<endl;

    
    return 0;
}


Measured memory_bytes: 82432
#include<bits/stdc++.h>
#define ll long long
#define  vi vector<int>
#define pb push_back
//#define int long long
#define boost ios_base::sync_with_stdio(false);	cin.tie(0);	cout.tie(0)
#define pi pair<int,int>
#define F first
#define S second
using namespace std;

//int mod=(int)(1e9+7);

void solve()
{
 
 int a,b,c,d;
 cin>>a>>b>>c>>d;
 if(a%d!=0)a+=d;
 if(c%b!=0)c+=b;

 if(a/d>=c/b)cout<<"Yes";
 else cout<<"No";


}

signed main()
{ boost;
 //cout<<fixed<<setprecision(14 );
 // int t;cin>>t;
  //for(int i=1;i<=t;i++)
  solve();
 // cout<<"Case #"<<i<<": "<<solve()<<endl;

return 0;
}

Measured memory_bytes: 3612
import java.util.Scanner;
import java.lang.Math;
public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        //int n = sc.nextInt();
        while(true){
            int h = sc.nextInt();
        int w = sc.nextInt();
        if(h==0&&w==0)break;
        for(int i = 0;i<h;i++){
            for(int j = 0;j<w;j++){
                if((j%2+i%2)%2==0){
                    System.out.print('#');
                }
                else {
                    System.out.print('.');
                }
            }
            System.out.println();
        }
        System.out.println();
        }
        
        sc.close();
    }
}


Measured memory_bytes: 37312
x,n = map(int,input().split())

if n == 0:
    print(x)
    quit()
p = set(map(int,input().split()))
dibba = 0
dif = float("inf")
for i in range(-100,201):
    if i not in p:
        diff = abs(x-i)
        if diff < dif:
            dif = diff
            dibba = i
print(dibba)

Measured memory_bytes: 9132
N,C = map(int,input().split())
G = {i:[0 for _ in range(10**5+1)] for i in range(1,C+1)}
for i in range(N):
    s,t,c = map(int,input().split())
    G[c][s] += 1
    G[c][t] -= 1
F = [0 for _ in range(2*(10**5)+1)]
for c in range(1,C+1):
    for i in range(10**5+1):
        if G[c][i]==1:
            F[2*i-1] += 1
        elif G[c][i]==-1:
            F[2*i] -= 1
H = [0 for _ in range(2*(10**5)+1)]
for i in range(1,2*(10**5)+1):
    H[i] = H[i-1]+F[i]
print(max(H))

Measured memory_bytes: 118088
S = input()
m = 0
l = []

for k in range(len(S)):#開始位置
    for i in range(1,len(S)+1-k):#文字数
        moji = ""
        check = True
        for j in range(i):#番目
            #print(S[j+k])
            if not check:
                break
            if S[j+k] == "A" or S[j+k] == "T" or S[j+k] == "C" or S[j+k] == "G":
                moji += S[j+k]
            else:
                check = False
        #print(moji)
        l.append(len(moji))
        #check
        #for str_ in moji:
print(max(l))
            

Measured memory_bytes: 3064
n = int(input())
a, b = [int(i) for i in input().split()]
A = [int(i) for i in input().split()]

first = []
sec = []
thi = []

for i in A:
    if i<=a:
        first.append(i)
    elif i<=b:
        sec.append(i)
    else:
        thi.append(i)

print(min(len(first), len(sec), len(thi)))


Measured memory_bytes: 3060
#include <stdio.h>
#include <stdlib.h>

int *A;

int partation(p, r){
    int i, par_small = 0, par_end = 0, temp;

    for(i = 0; i < p; i++){
        if(r < A[i]){
            par_end++;
        }
        else{
            temp = A[par_small];
            A[par_small] = A[i];
            A[i] = temp;
            par_small++;
            par_end++;
        }
    }
    return par_small;
}

int main(){

    int n, i, center;

    scanf("%d",&n);
    A = malloc(sizeof(int) * n);
    for(i = 0; i < n; i++) scanf("%d",&A[i]);

    center = partation(n, A[n-1]);
    for(i = 0; i < n; i++){
        if(i == center - 1){
            printf("[");
        }
        printf("%d",A[i]);
        if(i == center - 1){
            printf("]");
        }
        if(i < n-1) printf(" ");
    }
    printf("\n");
    return 0;
}


Measured memory_bytes: 2140
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef vector<ll> vl;
typedef pair<ll, ll> PP;
#define rep(i, n) for(ll i = 0; i < ll(n); i++)
#define CIN>>x scanf("%lld",&x);
#define all(v) v.begin(), v.end()
bool chmin(ll & a, ll  b) { if (b < a) { a = b; return 1; } return 0; }
bool chmax(ll & a, ll b) { if (b > a) { a = b; return 1; } return 0; }
const ll INF = 999999999999999;
const ll MOD = 1000000007;
const ll MAX_N=500010;
ll a, b, c, d, e, f, p, t, x, y, z, q, m, n, r, h, k, w, l, ans;
int main() {
    string s;
    cin >> s;
    if(s=="AAA"||s=="BBB")cout<<"No"<<endl;
    else cout<<"Yes"<<endl;
}

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

int main() {
    string s; cin >> s;
    vector<bool> d(26);
    for (int i=0;i<s.size();++i) d[s[i]-'a']=true;
    for (int i = 0; i<26; ++i){
        if (!(d[i])) {
            cout << (char)(i+'a') << endl;
            break;
        } 
        else if (i==25) cout << "None" << endl;
    }
}

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

public class AtCoderA
{
    static void Main()
    {
        var sc = new Scanner();

        int a = sc.NextInt();
        int b = sc.NextInt();

        int answer = a > b ? a - 1 : a;

        Console.WriteLine(answer);
    }

    class Scanner
    {
        private string[] _line;
        private int _index;
        private const char Separator = ' ';

        public Scanner()
        {
            _line = new string[0];
            _index = 0;
        }

        public string Next()
        {
            while (_index >= _line.Length)
            {
                _line = Console.ReadLine().Split(Separator);
                _index = 0;
            }

            return _line[_index++];
        }

        public int NextInt() => int.Parse(Next());
        public long NextLong() => long.Parse(Next());
        public double NextDouble() => double.Parse(Next());
        public decimal NextDecimal() => decimal.Parse(Next());
        public char NextChar() => Next()[0];
        public char[] NextCharArray() => Next().ToCharArray();

        public string[] Array()
        {
            _line = Console.ReadLine().Split(Separator);
            _index = _line.Length;
            return _line;
        }

        public int[] IntArray() => Array().Select(int.Parse).ToArray();
        public long[] LongArray() => Array().Select(long.Parse).ToArray();
        public double[] DoubleArray() => Array().Select(double.Parse).ToArray();
        public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray();
    }
}

Measured memory_bytes: 11092
Public Class Program
  Shared Sub Main()
    Dim n As Long = Long.Parse(Console.ReadLine())
    Dim s As String = Console.ReadLine()
    Dim ans As Long = 1
    For i As Long = 0 To n - 2
      If s(i) <> s(i + 1) Then ans += 1
    Next
    Console.WriteLine(ans.ToString())
  End Sub
End Class

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

struct Point{ double x,y; };
  
void koch(int n, Point a,Point b){
  if(n == 0) return;
  Point s,t,u;
  double th = M_PI * 60.0 / 180.0;
  
  s.x = (2.0*a.x + 1.0 *b.x)/3.0;
  s.y = (2.0*a.y + 1.0 *b.y)/3.0;
  t.x = (1.0*a.x + 2.0 *b.x)/3.0;
  t.y = (1.0*a.y + 2.0 *b.y)/3.0;
  u.x = (t.x - s.x) * cos(th) - (t.y - s.y) * sin(th) + s.x;
  u.y = (t.x - s.x) * sin(th) + (t.y - s.y ) * cos(th) + s.y;
  
  koch(n-1,a,s);
  printf("%.8f %.8f\n", s.x,s.y);
  koch(n-1,s,u);
  printf("%.8f %.8f\n", u.x,u.y);
  koch(n-1,u,t);
  printf("%.8f %.8f\n", t.x,t.y);
  koch(n-1,t,b);
}
  

int main(){
  Point a,b;
  int n; cin >> n;
  
  a.x = 0;
  a.y = 0;
  b.x = 100;
  b.y = 0;
  
  printf("%.8f %.8f\n", a.x,a.y);
  koch(n,a,b);
  printf("%.8f %.8f\n", b.x,b.y);
  return 0;
}
                                        
  
  
  
     





Measured memory_bytes: 3212
#include <stdio.h>
#define max(a, b) ((a) > (b) ? (a) : (b))

int
main(int argc, char *argv[])
{
  int a, b, c;
  scanf("%d %d %d", &a, &b, &c);

  if(a + b + c == 2 * max(a, max(b, c))) printf("Yes\n");
  else printf("No\n");

  return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
#include<complex>
using namespace std;

#define rep(i,x) for(ll i=0;i<x;i++)
#define repn(i,x) for(ll i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 1000000007;
const ll MAX = 4000001;
const long double eps = 1E-14;

ll max(ll a, ll b) {
	if (a > b) { return a; }
	return b;
}

ll min(ll a, ll b) {
	if (a > b) { return b; }
	return a;
}

ll gcd(ll a, ll b) {
	if (b == 0) { return a; }
	if (a < b) { return gcd(b, a); }
	return gcd(b, a % b);
}

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

struct edge {
	ll ind;
	ll fr;
	ll to;
	ll d;
};

class mint {
	long long x;
public:
	mint(long long x = 0) : x((x% MOD + MOD) % MOD) {}
	mint operator-() const {
		return mint(-x);
	}
	mint& operator+=(const mint& a) {
		if ((x += a.x) >= MOD) x -= MOD;
		return *this;
	}
	mint& operator-=(const mint& a) {
		if ((x += MOD - a.x) >= MOD) x -= MOD;
		return *this;
	}
	mint& operator*=(const  mint& a) {
		(x *= a.x) %= MOD;
		return *this;
	}
	mint operator+(const mint& a) const {
		mint res(*this);
		return res += a;
	}
	mint operator-(const mint& a) const {
		mint res(*this);
		return res -= a;
	}
	mint operator*(const mint& a) const {
		mint res(*this);
		return res *= a;
	}

	mint pow(ll t) const {
		if (!t) return 1;
		mint a = pow(t >> 1);
		a *= a;
		if (t & 1) a *= *this;
		return a;
	}

	// for prime MOD
	mint inv() const {
		return pow(MOD - 2);
	}
	mint& operator/=(const mint& a) {
		return (*this) *= a.inv();
	}
	mint operator/(const mint& a) const {
		mint res(*this);
		return res /= a;
	}

	friend ostream& operator<<(ostream& os, const mint& m) {
		os << m.x;
		return os;
	}
};

mint pw(mint a, ll b) {
	if (b == 0) { return 1; }
	mint ret = pw(a, b >> 1);
	ret *= ret;
	if (b & 1) { ret *= a; }
	return ret;
}

typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef vector<vector<vector<ll>>> vvvll;

typedef vector<mint> vmint;
typedef vector<vector<mint>> vvmint;
typedef vector<vector<vector<mint>>> vvvmint;

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


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

	vll a(N + 1);
	repn(i, N) cin >> a[i];

	vvmint dp(N + 1, vmint(K + 1, 0));
	vvmint rdp(N + 1, vmint(K + 1, 0));

	dp[0][0] = 1;
	rep(j, K + 1)rdp[0][j] = 1;

	repn(i, N)rep(j, K + 1) {
		if (j > a[i])dp[i][j] = rdp[i - 1][j] - rdp[i - 1][j - a[i]-1];
		else dp[i][j] = rdp[i - 1][j];

		if (j == 0)rdp[i][j] = dp[i][j];
		else rdp[i][j] = rdp[i][j - 1] + dp[i][j];

		//cout << i << " " << j << " " << dp[i][j] << " " << rdp[i][j] << endl;
	}

	cout << dp[N][K] << endl;
}

Measured memory_bytes: 161840
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
main(){
	int t[101],co=0;
	for(int i=0;i<=100;++i)t[i]=0;
	while(cin>>t[co]){
		if(t[co]==0){
			--co;
			cout<<t[co]<<endl;
		}else ++co;
	}
}

Measured memory_bytes: 1160
#include <stdio.h>
int main(void)
{
int a,b;
char op;

while(1){
 scanf("%d %c %d",&a,&op,&b);
  if(op == '+')
     printf("%d\n",a + b);
  else if(op == '-') 
     printf("%d\n",a - b);
  else if(op == '*')
     printf("%d\n",a * b);
  else if(op == '/')
     printf("%d\n",a / b);
  else if( op == '?') break;
}
return 0;
}

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

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
template<class T>void chmin(T&a,const T&b){if(a>b)a=b;}
template<class T>void chmax(T&a,const T&b){if(a<b)a=b;}


int nextInt() { int x; scanf("%d", &x); return x;}

int main2() {
  int N = nextInt();
  map<int,int> c;
  REP(i, N) {
    ++c[nextInt()];
  }
  int ans = 0;
  for (auto it = c.begin(); it != c.end(); ++it) {
    int a = it->first;
    int count = it->second;
    if (a > count) ans += count;
    else ans += (count - a);
  }
  cout << ans << endl;
  return 0;
}

int main() {
  for (;!cin.eof();cin>>ws) main2();
  return 0;
}



Measured memory_bytes: 4736
n,m = map(int,input().split())
matrix = [0 for i in range(n)]
vector = [0 for i in range(m)]

#matrix
for i in range(n):
    matrix[i] = list(map(int,input().split()))

#vector
for j in range(m):
    vector[j] = int(input())

#calculate
for row in range(n):
    ans = 0
    for col in range(m):
        ans += matrix[row][col] * vector[col]
    print(ans)


Measured memory_bytes: 6016
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;


public class Main {

	public static void main(String[] args) {
		
		Scanner sc = new Scanner(System.in);
		List<MyList> L  = new ArrayList<>();
		
		int n = sc.nextInt();
		
		int q = sc.nextInt();
		
		for(int i=0;i<n;i++) {
			MyList List = new MyList();
			L.add(List);
		}
		
		
		for(int i=0;i<q;i++) {
			
			int ver = sc.nextInt();
			int t=0,s=0,x=0;
			switch(ver) {
			
			case 0 :
				t = sc.nextInt();
				x = sc.nextInt();
				
				L.get(t).insert(x);
				
				break;
			case 1 :
				t = sc.nextInt();
				
				L.get(t).dump();
				break;
			case 2 :
				s = sc.nextInt();
				t = sc.nextInt();
				
				L.get(t).splice(L.get(s));
				break;
			}
		}
	}

}

class MyNode{
	int x;
	MyNode after;
	MyNode(int x_ , MyNode after_){
		x = x_;
		after = after_;
	}
}

class MyList{
	MyNode start;
	MyNode end;
	int size;
	
	MyList(){
		
		start = new MyNode(0,null);
		end = start;
		size = 0;
	}
	
	void insert(int x) {
		
		MyNode newNode = new MyNode(x,null);
		
		end.after = newNode;
		end = end.after;
		size++;
	}
	
	void dump() {
		
		MyNode cursor = start.after;
		for( int i = 0; i < size; i++ ){
			if( i == 0 )
				System.out.print( cursor.x );
			else
				System.out.print( " " + cursor.x ); 
			cursor = cursor.after;
		}
		System.out.println();
	}
	
	void splice(MyList Ls) {
		
		end.after = Ls.start.after;
		end = Ls.end;
		size += Ls.size;
		
		Ls.end = Ls.start;
		Ls.size = 0;
	}
}


Measured memory_bytes: 310388
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define zzz ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(0);
ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); }
ll lcm(ll a, ll b){return (a*b)/gcd(a, b);}
int main()
{
    zzz;
    int a,b,c; cin>>a>>b>>c;
    cout<<max(0,c-(a-b));
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define pi 3.14159265358979323
double modu(double val){
    while (val>=360)
        val-=360;
    return val;
}
int main(){
    double a,b,h,m;
    cout<<fixed<<setprecision(12);
    cin>>a>>b>>h>>m;
    h*=30;
    h+=m/2;
    h=modu(h);
    m*=6;
        double angle=abs(h-m);
        angle/=180;
        angle*=pi;
        cout<<sqrt(a*a+b*b-2*a*b*cos(angle))<<endl;
}


Measured memory_bytes: 4216
// #pragma GCC optimize("Ofast")
// #pragma GCC target("avx,avx2,fma")
// #pragma GCC optimization ("unroll-loops")

#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

#define fo(i,n)         for(int i=0;i<n;i++)
#define Fo(i,k,n)       for(int i=k;i<n;i++) 
#define nl              "\n"
#define ff              first
#define ss              second
#define int             long long
#define pb              push_back
#define mp              make_pair
#define vec(x)          vector<x>
#define matrix(x)       vector<vector<x>>
#define sz(x)           (int)x.size()
#define mem(a,b)        memset(a, b, sizeof a)
#define vii             vector<pair<int,int>>
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define gcd(a,b)        __gcd(a,b)
#define lcm(a,b)        (a*(b/gcd(a,b)))
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define MOD             998244353
#define deb(x)          cerr <<#x<<" = "<<x<<"\n"
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
#define all(v)          v.begin(),v.end()
#define rep(i,a,b)      for (int i = a; i<b; ++i)
#define len(s)          s.length()
#define watch(x)        cout << #x << " = " << x << endl
#define trace(x)        cerr << #x << " = " << x << endl
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds; //for storing unique elements
typedef tree<int , null_type , less_equal<int> , rb_tree_tag , tree_order_statistics_node_update> ordered_set; //for repeating elements
 
int power(int a,int b,int m=mod)
{int ans=1;while(b>0){if(b&1)ans=(ans*a)%m;a=(a*a)%m;b>>=1;}
return ans;}

void babuBhaiya()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
}

const int N = 1e5+1;
const double pi = acos(-1);

void solve(){
    
	string s,t; cin>>s>>t;
	int ans = inf;
	for(int i = 0;i+len(t)<=len(s);i++){
		int cnt = 0;
		for(int j = 0;j<len(t);j++){
			cnt += s[i+j] != t[j];
		}
		ans = min(ans,cnt);
	}
	cout<<ans;
}

 
int32_t main()
{
    babuBhaiya();

    int t;

    t = 1;
    //cin>>t;

    while(t--){
        solve();
    }
    
    return 0;
}

Measured memory_bytes: 3672
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        AtCoder solver = new AtCoder();
        solver.solve(1, in, out);
        out.close();
    }

    static class AtCoder {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            long x = in.nextLong();
            long y = in.nextLong();

            if (x % y == 0) {
                out.println(-1);
            } else {
                out.println(x);
            }
        }
    }
}



Measured memory_bytes: 21844
n,m,c = map(int,input().split())
b_list = list(map(int,input().split()))
a_list = []
for i in range(n):
    a_list.append(list(map(int,input().split())))
ans = 0
for i in range(n):
    num = 0
    for j in range(m):
        num += (b_list[j]*a_list[i][j])
    num += c
    if num > 0:
        ans += 1
print(ans)

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

#define TYPE(c)   remove_reference_t<decltype(c)>
#define REP(i, n) for(TYPE(n) i = 0; i < n; i++)
#define FOR(v, c) for(TYPE(c.begin()) v = c.begin(); v != c.end(); v++)
#define ALL(c)    c.begin(), c.end()
#define SORT(c)   sort(ALL(c))
#define RSORT(c)  sort(ALL(c), greater<TYPE(c)::value_type>())
#define UNIQUE(c) c.erase(unique(ALL(c)), c.end())

using namespace std;
using ll = long long;

constexpr int MOD  = (int)1e9 + 7;
constexpr int INF  = (int)1e9 + 1;
constexpr ll  LINF = (ll)1e18 + 1;
template<typename T> constexpr bool chmax(T& a, const T& b)
{ if(a < b) { a = b; return true; } else { return false; } }
template<typename T> constexpr bool chmin(T& a, const T& b)
{ if(b < a) { a = b; return true; } else { return false; } }
template<typename S, typename T> ostream& operator<<(ostream &os, const pair<S, T>& p)
{ return os << "(" << p.first << "," << p.second << ")"; }
ostream& operator<<(ostream &os, const string& s)
{ FOR(v, s) os << *v; return os; }
template<typename T> auto operator<<(ostream& os, const T& t)
    -> typename conditional<true, ostream&, decltype(*t.begin())>::type
{ os << "["; FOR(v, t) { if(v != t.begin()) os << ","; os << *v; } os << "]"; return os; }

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

    int H, W;
    cin >> H >> W;
    vector<string> s(H);
    REP(i, H) {
        cin >> s[i];
    }

    vector<vector<int>> dp(H, vector<int>(W));
    REP(i, H) {
        REP(j, W) {
            dp[i][j] = INF;
        }
    }

    dp[0][0] = (s[0][0] == '#') ? 1 : 0;
    REP(i, H) {
        REP(j, W) {
            if(i == 0 && j == 0) continue;
            if(0 < i) {
                auto cost = (s[i - 1][j] == '.' && s[i][j] == '#') ? 1 : 0;
                dp[i][j] = min(dp[i][j], dp[i - 1][j] + cost);
            }
            if(0 < j) {
                auto cost = (s[i][j - 1] == '.' && s[i][j] == '#') ? 1 : 0;
                dp[i][j] = min(dp[i][j], dp[i][j - 1] + cost);
            }
        }
    }

    cout << dp[H - 1][W - 1] << endl;

    return 0;
}


Measured memory_bytes: 384
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<string>
#include<vector>
#include<array>
#include<deque>
#include<queue>
#include<map>
#include<cmath>
#include<stdio.h>

using std::cout;
using std::cin;
using std::setw;
using std::setfill;
using std::string;
using std::pair;
using std::make_pair;
using std::vector;
using std::array;
using std::queue;
using std::deque;
using std::priority_queue;
using std::multimap;
using std::next_permutation;
//using std::iota;
using std::sort;
using std::greater;
using std::max;
using std::min;
using std::sin;
using std::cos;
using std::log;

using lli = long long int;
using ulli = unsigned long long int;

#define INF 999999999;
#define MOD 1000000007;
#define PI 3.141592653589793;

#define EVEL 1

#ifndef EVEL
#define dbug(X) std::cout << #X << ":" <<X<<" " ;
#define dbugf(s) std::cout << s << " ";
#define dbugln std::cout<<"\n";
#else
#define dbug(X) {}
#define dbugf(s) {}
#define dbugln {}
#endif

int N;
struct SP{
	int num;
	string name;
	int val;
};
vector<SP> SPs;


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

	cin >> N;
	for(int i = 0; i < N; i++){
		SP inp;
		cin >> inp.name >> inp.val;
		inp.num = i+1;
		SPs.push_back(inp);
	}
	sort(SPs.begin(), SPs.end(), [](SP a, SP b){if(a.name == b.name){return (a.val > b.val);}else{return (a.name < b.name);}});
	for(int i = 0; i < SPs.size(); i++){
		cout << SPs[i].num << "\n";
	}



	return 0;
}


Measured memory_bytes: 256
import sys
from statistics import *
from collections import *
from operator import itemgetter

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline()

a, b = na()
s = input()
print('Yes' if s.count('-') == 1 and s[a] == "-" else 'No')

Measured memory_bytes: 5148
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
 
struct BIT{
  int size;
  vector<ll> dat;
  void init(int n){
    size=n;
    dat.clear();
    dat.resize(n+1);
  }
  void Add(int i,ll x){
    while(0<i&&i<=size){
      dat[i]+=x;
      i+=(i&-i);
    }
  }
  ll Sum(int i){
    ll res=0;
    while(0<i){
      res+=dat[i];
      i-=(i&-i);
    }
    return res;
  }
};
 
 
 
int main(){
  int n,q;
  BIT A,B;
  scanf("%d %d",&n,&q);
  A.init(n);
  B.init(n);
  for(int i=1;i<=q;i++){
    int type;
    ll s,t,value;
    scanf("%d",&type);
    if(type==0){
      scanf("%lld %lld %lld",&s,&t,&value);
      A.Add(s,value);
      A.Add(t,-value);
      B.Add(s,-value*(s-1));
      B.Add(t,value*(s-1) + value*(t-s+1) );
    }
    if(type==1){
      scanf("%lld %lld",&s,&t);
      s--;
      printf("%lld\n", A.Sum(t)*t+B.Sum(t) - A.Sum(s)*s-B.Sum(s) );
    }
  }
  return 0;
}

Measured memory_bytes: 4396
#include<iostream>

using namespace std;

int main()
{
	int a,b,c,X;
	int counter = 0;
	cin >> a >> b >> c >> X;

	for(int i=0;i<=a;i++)
	{
		for(int j=0;j<=b;j++)
		{
			for(int k=0;k<=c;k++)
			{
				if( i*500+j*100+k*50 == X)
				{
					counter++;
				}
			}
		}
	}

	cout << counter << endl;

	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner

import scala.collection.mutable
import scala.collection.mutable.ArrayBuffer

object Main extends App {
  val in = new Scanner(System.in)
  val V = in.nextInt()
  val E = in.nextInt()
  val dinitz = new Dinitz(V)
  for (_ <- 0 until E) {
    val s = in.nextInt()
    val t = in.nextInt()
    val c = in.nextInt()
    dinitz.addEdge(s, t, c)
  }

  val f = dinitz.maxFlow(0, V - 1)
  println(f)
}

import java.util

class Dinitz(val V: Int) {

  class Edge(var to: Int, var cap: Long, var rev: Int)

  private val graph = (for (_ <- 0 until V) yield new ArrayBuffer[Edge]()).toArray
  private val iter = new Array[Int](V)


  def addEdge(from: Int, to: Int, cap: Long): Unit = {
    graph(from).append(new Edge(to, cap, graph(to).size))
    graph(to).append(new Edge(from, 0, graph(from).size - 1))
  }

  def maxFlow(source: Int, sink: Int): Long = {
    var flow = 0L

    while (true) {
      val queue = new mutable.Queue[Int]()
      val level = Array.fill[Int](V)(-1)
      level(source) = 0
      queue.enqueue(source)
      while (queue.nonEmpty) {
        val v = queue.dequeue()
        for (e <- graph(v)) {
          if (e.cap > 0 && level(e.to) < 0) {
            level(e.to) = level(v) + 1
            queue.enqueue(e.to)
          }
        }
      }

      if (level(sink) < 0) return flow
      util.Arrays.fill(iter, 0)

      def dfs(v: Int, t: Int, f: Long): Long = {
        if (v == t) return f

        while (iter(v) < graph(v).size) {
          val e = graph(v)(iter(v))
          if (e.cap > 0 && level(v) < level(e.to)) {
            val d = dfs(e.to, t, Math.min(f, e.cap))
            if (d > 0) {
              e.cap -= d
              graph(e.to)(e.rev).cap += d
              return d
            }
          }

          iter(v) += 1
        }
        0
      }

      var f = 1L
      while (f > 0) {
        f = dfs(source, sink, Long.MaxValue)
        flow += f
      }
    }

    throw new IllegalStateException()
  }
}

Measured memory_bytes: 52848