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

#define ll long long
#define sd(x) scanf("%d", &(x))
#define pii pair<int, int>
#define F first
#define S second

#define TRACE

#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
	cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
	const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif

const int N = 200005;
int a[N];
map<ll, int> curr;
int main(){
	int n; sd(n);
	curr[0] = 1;
	long long ans = 0;
	long long sm = 0;
	for(int i = 1; i  <= n; i++){
		sd(a[i]);
		sm += a[i];
		ans += curr[sm];
		curr[sm]++;
	}
	cout << ans;
}

Measured memory_bytes: 13568
#include<iostream>
#include<string>
#include<algorithm>
#include<stdio.h>
#include<queue>
#include<stack>

using namespace std;

typedef long long ll;
typedef double db;
typedef vector<int> vint;
typedef vector<ll> vll;

int main(){
    int n,k,x;
    int ans = 0;
    cin>>n>>k;

    for(int i=0; i<n; i++){
        cin>>x;
        if(x<k-x){
            ans += x;
        }else{
            ans += k-x;
        }
    }
    cout<<ans*2<<endl;


    return 0;
}

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

using namespace std;

#define debug(n) cerr << #n << ':' << n << endl;
#define dline    cerr << __LINE__ << endl;

using ll = long long;
template<class T, class U> using P = pair<T,U>;
template<class T> using Heap = priority_queue<T>;
template<class T> using heaP = priority_queue<T,vector<T>,greater<T>>;
template<class T,class U> using umap = unordered_map<T,U>;
template<class T> using uset = unordered_set<T>;

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

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

template<class T, size_t N, class U>
void Fill(T (&a)[N], const U&v){
    fill((U*)a,(U*)(a+N),v);
}

template<class T>
istream& operator >> (istream&is, vector<T>&v){
  for(auto&e:v)is >> e;
  return is;
}

int main(){
  int n,m; cin >> n >> m;
  vector<int> v(n);
  for(int i = 0; i < m; ++i){
    int a, b; cin >> a >> b;a--;b--;
    v[a]++; v[b]++;
  }
  for(int i = 0; i < n; ++i){
    cout << v[i] << endl;
  }
  return 0;
}


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

const int MOD = 1000000007;

int main() {
	//入力
	int n;
	cin >> n;
	vector<int> d1(n), d2(n);
	rep(i, n) cin >> d1[i] >> d2[i];

	//処理
	int ans = 0;
	rep(i, n) {
		if (d1[i] == d2[i]) {
			++ans;
			if (ans == 3) {
				cout << "Yes" << endl;
				return 0;
			}
		}
		else {
			ans = 0;
		}
	}

	//出力
	cout << "No" << endl;

	return 0;
}


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

int main(){
  long long a,b=0;
  cin >> a;
  for(long long i=1;i<=a;i++){
    if(i%3!=0 && i%5!=0){
      b=i+b;
    }
  }
  cout <<b;
}

Measured memory_bytes: 3636
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <utility>
#include <tuple>
#include <algorithm>
#include <numeric>
#include <cstring>
#include <cmath>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

const ll INF = 1e18;

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i, n) cin >> a[i];
  vector<vector<ll>> dp(n+1, vector<ll>(n+1, INF));
  rep(i, n+1) dp[i][i] = 0;
  rep(i, n) dp[i][i+1] = 0;
  vector<ll> sum(n+1);
  rep(i, n) sum[i+1] = sum[i]+a[i];
  for (int len = 2; len <= n; len++) {
    for (int i = 0; i+len <= n; i++) {
      int j = i+len;
      ll mn = INF, idx;
      for (int k = i+1; k < j; k++) {
        ll t1 = sum[k]-sum[i];
        ll t2 = sum[j]-sum[k];
        if (chmin(mn, dp[i][k]+dp[k][j]+t1+t2))
          idx = k;
      }
      dp[i][j] = mn;
    }
  }
  cout << dp[0][n] << endl;
  return 0;
}

Measured memory_bytes: 1536
import math
import copy
from operator import mul
from functools import reduce
from collections import defaultdict
from collections import Counter
from collections import deque
# 直積 A={a, b, c}, B={d, e}:のとき，A×B={(a,d),(a,e),(b,d),(b,e),(c,d),(c,e)}: product(A, B)
from itertools import product
# 階乗 P!: permutations(seq), 順列 {}_len(seq) P_n: permutations(seq, n)
from itertools import permutations
# 組み合わせ {}_len(seq) C_n: combinations(seq, n)
from itertools import combinations
from bisect import bisect_left, bisect_right
# import numpy as np

def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W

# 四方向: 右, 下, 左, 上
dy = [0, -1, 0, 1]
dx = [1, 0, -1, 0]

def i_inpl(): return int(input())
def l_inpl(): return list(map(int, input().split()))
INF = float("inf")

######
# URL: https://atcoder.jp/contests/sumitrust2019/tasks/sumitb2019_d
######

def main():
    N = i_inpl()
    base_S = input()
    ans = set()
    for i in range(1000):
        S = copy.deepcopy(base_S)
        find_num = str(i).zfill(3)
        k = S.find(find_num[0])
        if k == -1:
            continue

        S = S[k+1:]
        k = S.find(find_num[1])
        if k == -1:
            continue

        S = S[k+1:]
        k = S.find(find_num[2])
        if k == -1:
            continue

        ans.add(find_num)
    print(len(ans))

if __name__ == "__main__":
    main()

Measured memory_bytes: 3796
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <queue>
#include <set>

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

int main()
{
    int a, b, i;
    scanf("%d %d", &a, &b);
    if(a <= 0 && b>=0)
    {
        printf("Zero\n");

    }
    else if(a > 0)
    {
        printf("Positive\n");
    }
    else
    {
        int t;
        if(b > 0)
            t = 0 - a;
        else
            t = b - a + 1;
        if(t % 2 == 0)
            printf("Positive\n");
        else
            printf("Negative\n");
    }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod=1e9+7;
const ll INF=mod*mod;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define all(x) (x).begin(),(x).end()
ll min(ll a,ll b){
  if(a>b){
    return b;
    }
      else{
        return a;
      }
  }
  
  ll max(ll a,ll b){
    if(a>b){
      return a;
    }
    else{
      return b;
    }
  }

ll power(ll a,ll b){
 ll ans=1;
 for(ll i=1;i<=b;i++){
ans*=a;
  }
  return ans;
}

 ll gcd(ll m,ll n){
 	if(n==0){
       return m;
     }
   return gcd(n,m%n);
 }
ll lcm(ll a,ll b){
  ll g=gcd(a,b);
  return a/gcd(a,b)*b;
		

}
int main(){
  
  string S;
  cin>>S;
  ll sum=0;
 for(ll i=1;i<S.size();i++){
    if(S[i]!=S[i-1]){
      sum++;
    }
 }
cout<<sum<<endl;
}


  

Measured memory_bytes: 512
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<math.h>
using namespace std;

#define MAX 256

int main(void){
	
	int a;
	scanf("%d", &a);
	int A[a];

	for (int i = 0; i < a; i++){
		scanf("%d", &A[i]);
	}

	for (int k = 0; k < a - 1; k++){
		printf("%d ", A[k]);
	}

	printf("%d\n", A[a - 1]);

	int key, j;

	for (int i = 1; i < a; i++){
		key = A[i];
		j = i - 1;
		while (j >= 0 && A[j] > key){
			A[j + 1] = A[j];
			j--;
		}
		A[j + 1] = key;

		for (int k = 0; k < a - 1; k++){
			printf("%d ", A[k]);
		}

		printf("%d\n", A[a - 1]);
	}

	return 0;
}

Measured memory_bytes: 3156
#ifndef ONLINE_JUDGE
    #include "debug.cpp"
#endif

#include <bits/stdc++.h>
using namespace std;

#define endl '\n'
#define int long long

void solve()
{
    string s;
    cin >> s;
    int sum = 0;
    for(int i = 0; i < s.size(); i++)
    {
        sum += s[i] - '0';
    }
    if(sum % 9 == 0)
        cout << "Yes\n";
    else
        cout << "No\n";
}   

int32_t main()
{
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);

    int t = 1;
    // cin >> t;
    while (t--)
        solve();
    return 0;
}


Measured memory_bytes: 3740
#include <iostream>
#include <algorithm>
#include <string.h>
#include <stdio.h>
#include <cmath>
#include <queue>
#include <vector>
#define INF 0x3f3f3f3f
#define MAXV  10001
using namespace std;
typedef struct edge
{
    int to,distance,cost;
    edge(){}
	edge(int to, int distance, int cost) : to(to), distance(distance), cost(cost){}
};
int V,d[10001];
vector<edge> G[MAXV];
typedef pair<int,int> cddt;
void dijk(int s)
{
    priority_queue<cddt,vector<cddt>,greater<cddt> > que;
    memset(d, 0x3f, sizeof(d));
    d[s]=0;
    que.push(cddt(0,s));
    while(!que.empty())
    {
        cddt now = que.top(); que.pop();
        int v = now.second;
        if (d[v] < now.first) continue;
        for(int i=0;i<G[v].size();i++)
        {
            edge x = G[v][i];
            if(d[x.to]>d[v]+x.distance)
            {
                d[x.to]=d[v]+x.distance;
                que.push(cddt(d[x.to],x.to));
            }
        }
    }
}
int main()
{
    int i,j,k,a,b,c,dis,E;
    while(scanf("%d%d",&V,&E)&&V)
    {
        for (int i = 0; i < V; ++i)
		{
			G[i].clear();
		}
        for(i=0;i<E;i++)
        {
            int u, v, d, c;
			cin >> u >> v >> d >> c;
			--u, --v;
			G[u].push_back(edge(v, d, c));
			G[v].push_back(edge(u, d, c));
        }
        dijk(0);
        int ans =0,mini;
        for(i=1;i<V;i++)
        {
            mini=INF;
            for(j=0;j<G[i].size();j++)
            {
                if(d[G[i][j].to]+G[i][j].distance==d[i]&&G[i][j].cost<mini)
                {
                    mini=G[i][j].cost;
                }
            }
            ans+=mini;
        }
        cout<<ans<<endl;
    }
    return 0;
}

Measured memory_bytes: 5100
using System;
using System.Collections.Generic;
using System.Collections;
using System.Collections.Specialized;
using System.Linq;
using System.Text;
using System.IO;
using System.Reflection;
using static System.Math;
using System.Numerics;
static class Program{
	const int mod=(int)1e9+7;
	static void Main(){
		Sc sc=new Sc();
		var s=sc.Ia;
		var h=new int[s[0]+1];
		var b=new bool[s[0]+1];
		for(int i = 0;i<s[1];i++) {
			var e=sc.Sa;
			int p=int.Parse(e[0]);
			if(e[1]=="AC"){
				b[p]=true;
			}
			else if(!b[p]){
				h[p]++;
			}
		}
		long a1=0,a2=0;
		for(int i = 1;i<=s[0];i++) {
			if(b[i]){
				a1++;
				a2+=h[i];
			}
		}
		Console.WriteLine("{0} {1}",a1,a2);
	}
}
public class Sc{
	public int I{get{return int.Parse(Console.ReadLine());}}
	public long L{get{return long.Parse(Console.ReadLine());}}
	public double D{get{return double.Parse(Console.ReadLine());}}
	public string S{get{return Console.ReadLine();}}
	public int[] Ia{get{return Array.ConvertAll(Console.ReadLine().Split(),int.Parse);}}
	public long[] La{get{return Array.ConvertAll(Console.ReadLine().Split(),long.Parse);}}
	public double[] Da{get{return Array.ConvertAll(Console.ReadLine().Split(),double.Parse);}}
	public string[] Sa{get{return Console.ReadLine().Split();}}
	public object[] Oa{get{return Console.ReadLine().Split();}}
	public int[] Ia2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),int.Parse);}}
	public int[] Ia3(int a){return Array.ConvertAll((a.ToString()+" "+Console.ReadLine()).Split(),int.Parse);}
	public int[] Ia3(bool a,int b,bool c,int d){return Array.ConvertAll(((a?b.ToString()+" ":"")+Console.ReadLine()+(c?" "+d.ToString():"")).Split(),int.Parse);}
	public long[] La2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),long.Parse);}}
	public long[] La3(int a){return Array.ConvertAll((a.ToString()+" "+Console.ReadLine()).Split(),long.Parse);}
	public long[] La3(bool a,int b,bool c,int d){return Array.ConvertAll(((a?b.ToString()+" ":"")+Console.ReadLine()+(c?" "+d.ToString():"")).Split(),long.Parse);}
	public T[] Arr<T>(int n,Func<T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f();}return a;}
	public T[] Arr<T>(int n,Func<int,T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(i);}return a;}
	public T[] Arr<T>(int n,Func<string[],T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(Console.ReadLine().Split());}return a;}
	public T[] Arr<T>(int n,Func<int,string[],T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(i,Console.ReadLine().Split());}return a;}
}

Measured memory_bytes: 17488
#include <iostream>
#include <string>
#include <list>
#include <cstring>

#define USE_SET

int main(void) {
  int K;

  std::string str;

  std::string s_;
  std::cin >> s_;
  const char* s = s_.c_str();

  std::cin >> str;
  K = std::stoi(str);

  size_t lsize = 0;
  size_t len = s_.length();

#if defined(USE_SET)
  typedef struct s_set {
    int pos;
    int len;

    s_set(int i, int j) : pos(i), len(j) {
    }
  } set;
#endif

#if defined(USE_SET)
  std::list<set> wlist;
  wlist.push_back(set(0, 1));
#else
  std::list<std::string> wlist;
  wlist.push_back(s_.substr(0, 1));
#endif

  for (int a = 'a'; a <= 'z' && lsize < K; ++a) {        /* a to z   */
    for (int b = 'a'; b <= 'z' && lsize < K; ++b) {      /* a to z   */
      for (int i = 0; i < len; ++i) {                    /* 0 to len */
        if (s[i] == a && (i+1 >= len || s[i+1] == b)) {
          for (int j = 1; j <= len - i && j <= K; ++j) {           /* length 1 to len - i */
            for (auto itr = wlist.begin(); itr != wlist.end(); ++itr) {
#if defined(USE_SET)
              int cmp = s_.compare(i, j, s_, itr->pos, itr->len);
#else
              int cmp = s_.compare(i, j, *itr);
#endif
              if (cmp == 0) {
                break;
              }
              if (cmp < 0) {
#if defined(USE_SET)
                wlist.insert(itr, set(i, j));
#else
                wlist.insert(itr, s_.substr(i, j));
#endif
                lsize++;
                break;
              }
#if defined(USE_SET)
              if (cmp > 0 && (itr->pos == wlist.rbegin()->pos && itr->len == wlist.rbegin()->len)) {
                wlist.push_back(set(i, j));
#else
              if (cmp > 0 && itr->c_str() == wlist.rbegin()->c_str()) {
                wlist.push_back(s_.substr(i, j));
#endif
                lsize++;
                break;
              }
            }
          }
        }
      }
    }
  }

  size_t idx = 0;
  for (auto &str : wlist) {
    idx++;
    if (idx == K) {
#if defined(USE_SET)
      //std::cout << str.pos << "," << str.len << std::endl;
      std::cout << s_.substr(str.pos, str.len) << std::endl;
#else
      std::cout << str << std::endl;
#endif
    }
  }

  return 0;
}

Measured memory_bytes: 256
import math
import sys
import os
from operator import mul
import collections
import itertools
import numpy as np
import copy

sys.setrecursionlimit(10**7)

def _S(): return sys.stdin.readline().rstrip()
def I(): return int(_S())
def LS(): return list(_S().split())
def LI(): return list(map(int,LS()))

if os.getenv("LOCAL"):
    inputFile = basename_without_ext = os.path.splitext(os.path.basename(__file__))[0]+'.txt'
    sys.stdin = open(inputFile, "r")
INF = float("inf")

H,W,K = LI()
grid = [list(_S()) for i in range(H)]
ans = 0

for x in range(1<<H):
    for y in range(1<<W):
        count = 0
        for i in range(H):
            for j in range(W):
                # 塗りつぶされない
                if (x >> i) & 1 == 0 and (y >> j) &1 ==0:
                    if grid[i][j] == '#':
                        count += 1
        if count == K:
            ans += 1

print(ans)

Measured memory_bytes: 27092
def main():
    n, m = map(int, input().split())
    print(solve(n, m))

def solve(n, m):
    if n > m:
        n, m = m, n
    
    if n * m == 1:
        return 1
    
    if n == 1:
        return n * m - 2
    
    return n * m - (n - 1) * 2 - (m - 1) * 2

main()


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

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

    int frag = 0;

    for(int i =1; i <= b; i++){
        if(a * i % b == c){
            frag = 1;
            break;
        }
    }

    if(frag == 0){
        cout << "NO" << endl;
    }else{
        cout << "YES" << endl;
    }
}

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

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

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

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

    string s;
    cin >> s;

    for (int i = 0; i < (sz(s) + 1) / 4; i++) {
        if (s[i] != s[sz(s) / 2 - i - 1] ||
                s[i] != s[sz(s) / 2 + i + 1] ||
                s[i] != s[sz(s) - i - 1]) {
            return cout << "No", 0;
        }
    }
    cout << "Yes";
}


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

int main() {
  int x, h;
  double s;

  while (1) {
    cin >> x >> h;
    if (!x && !h) break;
    s = x*x + 2*x*sqrt(h*h+x*x/4.0);
    cout.setf(ios::fixed);
    cout.precision(6);
    cout << s << endl;
  }
  return 0;
}

Measured memory_bytes: 1236
# -*- coding: utf-8 -*-
import numpy as np

def main():
    n=int(input())
    h = list(map(int, input().split()))
    cnt=1
    for i in range(1,n):
        for j in range(i):
            if(h[i]<h[j]):
                break
            if((j+1)==i):
                cnt=cnt+1
    print(cnt)

if __name__ == '__main__':
    main()

Measured memory_bytes: 12496
#include <stdio.h>
   #include <stdlib.h>
   #include <time.h>
    
   int main(){
       int n, ans=0;
       scanf("%d",&n);
       if(n % 10 == 1){
       	ans += 9;
       } else if(n % 10 == 9){
       	ans += 1;
       } else {
       	ans += (n % 10);
       }
       int x = (n / 10) % 10;
       switch(x){
       	case 1: ans += 90; break;
       	case 9: ans += 10; break;
       	default: ans += (x * 10); break;
       }
       x = n / 100;
       switch (x){
       	case 1: ans += 900; break;
       	case 9: ans += 100; break;
       	default: ans += x * 100; break;
       }
       printf("%d", ans);
       return 0;
   }

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

using namespace std;
#define ll long long
const int maxn=1e3+5;
char a[maxn];
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin>>(a+1);
	int n=strlen(a+1);
	int r=(n-1)/2;
	int flag1=0,flag2=0,flag3=0;
	for(int i=1;;i++)
	{
	    if(a[i]!=a[r])
        {
            flag1=1;
            break;
        }
         r--;
        if(i>=r)
        {
            break;
        }

	}
	r=n;
	for(int i=(n+3)/2;;i++)
    {
        if(a[i]!=a[r])
        {
            flag2=1;
            break;
        }

        r--;
        if(i>=r)
        {
            break;
        }
    }
    r=n;
    for(int i=1;;i++)
    {
        if(a[i]!=a[r])
        {
            flag3=1;
            break;
        }
        r--;
        if(i>=r)
            break;
    }
    if(flag1==0&&flag2==0&&flag3==0)
    {
        cout<<"Yes"<<'\n';
    }
    else
        cout<<"No"<<'\n';










}


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


inline auto divide (const string & s)
{
  auto n = s.length ();
  
}

auto main () -> int
{
  cin.tie (nullptr);
  ios::sync_with_stdio (false);

  string s;
  cin >> s;

  vector <int> children (s.size (), 0);

  // RRRRRRRRRRRRRRRRRRRRRLLLLLLL|RRRRRRRRRRRRRRRRRRLLLLLLLLLLLLLLLL
  auto ite = s.begin ();

  while (ite != s.end ())
  {
    auto first = ite;
    auto right = find (ite, s.end (), 'L');
    auto left = prev (right);
    auto last = find (right, s.end (), 'R');

    auto first_pos = distance (s.begin (), first);
    auto left_pos = distance (s.begin (), left);
    auto right_pos = distance (s.begin (), right);
    auto last_pos = distance (s.begin (), last);
    auto sub_n = last_pos - first_pos;
    if (sub_n % 2 == 0)
    {
      children [left_pos] = sub_n / 2;
      children [right_pos] = sub_n / 2;
    }
    else if (first_pos % 2 == left_pos % 2)
    {
      children [left_pos] = sub_n / 2 + 1;
      children [right_pos] = sub_n / 2;
    }
    else if (first_pos % 2 == right_pos % 2)
    {
      children [left_pos] = sub_n / 2;
      children [right_pos] = sub_n / 2 + 1;
    }
    ite = last;
  }

  copy (children.begin (), children.end (), ostream_iterator <decay_t <decltype (* children.begin ())>> (cout, " "));
  cout << endl;
}



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

/*
given weights and values array, each i-th means it weights[i] and values[i] 

find the maximum with given W 

3 8
3 30
4 50
5 60
dp[i][w] = i-th means consider up to i, w means the weight it used 
1. add it (if w >= weights[i])
dp[i][w] = dp[i-1][w-weights[i]] + values[i]
2. ignore it 
dp[i][w] = dp[i-1][w]
*/

int main() {
    int n;
    int W;
    long long ans = 0;
    scanf("%d%d", &n, &W);
    
    vector<vector<long long>> dp(n+1, vector<long long>(W+1));
    
    for (int i = 1; i <= n; i++) {
        int weight;
        int value;
        scanf("%d%d", &weight, &value);
        for (int w = 0; w <= W; w++) {
            dp[i][w] = dp[i-1][w]; // ignore
            if (w >= weight) {
                dp[i][w] = max(dp[i][w], dp[i-1][w-weight]+value); // add
            }
            ans = max(ans, dp[i][w]);
        }
    }
    
    printf("%lld", ans);
    
	return 0;
}






Measured memory_bytes: 80256
//***No one wants to die...yet death is the destiation we all share***
 
#include<bits/stdc++.h>
using namespace std;
 
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define ll long long 
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define rep(i,n) for(i=0;i<n;i++)
#define forn(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define for1(i, n) for (ll i = 1; i <= (ll)(n); ++i)
#define ford(i, n) for (ll i = (ll)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (ll i = (ll)(a); i <= (ll)(b); ++i)
#define fora(it,x) for(auto it:x)
#define PI 3.14159265
#define sync ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define endl "\n"
 
typedef pair<ll, ll> pii;
typedef vector<ll> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long i64;
typedef vector<i64> vi64;
typedef vector<vi64> vvi64;
typedef pair<i64, i64> pi64;
typedef long double ld;
 
template<class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }

int main(){
   string s,t;
   cin>>s>>t;
   ll c=0;
   forn(i,s.length()){
       if(s[i]!=t[i]) c++;
   }
   cout<<c;
}

Measured memory_bytes: 3916
fun main(args: Array<String>) {

    val list = readLine()!!.split(" ").map { it.toInt() }

    val strArray = mutableListOf<String>()
    for (i in 0 until list[0])
    // LOOK inputが3で3つ欲しい時は0始まりでuntilになる
        strArray.add(readLine()!!)

    // mutableListの場合、sortしたら値が置き換わるのかな？
    strArray.sort()
    // LOOK joinToStringを覚える
    println(strArray.joinToString(separator = ""))
}

Measured memory_bytes: 36068
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
const double PI = 4*atan(1);
const int INF = 0x3f3f3f3f;
const int MOD = 1e9+7;
const ll LINF = 0x3f3f3f3f3f3f3f3f;
const double EPS = 1e-9;
const string YES = "Possible";
const string NO = "Impossible";
#define pb push_back
#define mp make_pair
#define eb emplace_back

const int MAX_N = 2e6+10;

ll D,T,S;

void solve()
{
	if(S*T>=D) cout<<"Yes\n";
	else cout<<"No\n";
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	cin >> D >> T >> S;
	solve();
	return 0;
}

Measured memory_bytes: 3648
#include<iostream>
#include<algorithm>
using namespace std;
int a, b, c, n;
int main(){
  cin >> a >> b >> c >> n;
  int ret = max(a, b);
  ret = max(ret, c);
  int others = a + b + c - ret;
  for(int i=0; i<n; i++) ret*= 2;
  ret += others;
  cout << ret << endl;
  return 0;
  }

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <array>
#include <set>
#include <cmath>
#include <string>
#include <sstream>
#include <queue> 
#include <list>
#include <stack>
#include <unordered_map>
#include <algorithm> 
#include <numeric>  
#include <functional>
#include <cassert>
#include <bitset>
#include <cctype>  
#include <iomanip> 
#include <limits>  
#include <regex>
// std::numeric_limits<int>::max(), min()
// std::setprecision(X)
// std::islower(), std::isupper(), std::tolower, std::toupper
// std::accumulate(m.begin(), m.end(), 0LL);
// std::sort(begin(),end()) // 0, 1, 2, 3 ,4 (default, less);
// std::priority_queue<int, vector<int>, less<int>> que; // 4, 3, 2, 1 (defualt, less) : 
// if ( std::regex_match(S, std::regex("(dream|dreamer|erase|eraser)*")) ) std::cout << "YES" << std::endl;
 
#define rep(i, n) for(int i = 0; i < (int)(n);    i++)
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()

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; }
typedef long long ll;
typedef std::vector<int> vi;
typedef std::vector<std::vector<int>> vvi;

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 * b / gcd(a, b); }


int main (void) {
  std::cin.tie(0);  std::ios::sync_with_stdio(false);
  int N, M; std::cin >> N >> M;
  if ( N == M ) std::cout << "Yes" << std::endl;
  else std::cout << "No" << std::endl;
  return 0;
}


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

using namespace std;
const long long INF = 1e18;

int main() {
    long long H, W;
    cin >> H >> W;

    long long ans;
    if (H%3 == 0 || W%3 == 0) ans = 0;
    else {
        ans = INF;

        for (long long h = 1; h < H; h++) {
            long long cut = h*W;
            if ((H - h)%2 == 0 || W%2 == 0) {
                long long rem = (H - h)*W/2;
                ans = min(ans, abs(cut - rem));
            } else {
                long long a = min(H - h, W);
                long long b = max(H - h, W);
                long long rem1 = a*(b - 1)/2;
                long long rem2 = a*(b + 1)/2;
                ans = min(ans, max({cut, rem1, rem2}) - min({cut, rem1, rem2}));
            }
        }

        for (long long w = 1; w < W; w++) {
            long long cut = H*w;
            if ((W - w)%2 == 0 || H%2 == 0) {
                long long rem = (W - w)*H/2;
                ans = min(ans, abs(cut - rem));
            } else {
                long long a = min(W - w, H);
                long long b = max(W - w, H);
                long long rem1 = a*(b - 1)/2;
                long long rem2 = a*(b + 1)/2;
                ans = min(ans, max({cut, rem1, rem2}) - min({cut, rem1, rem2}));
            }
        }
    }

    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(void)
{
  int N, K;
  cin >> N >> K;
  for(int i = 0; i < N; i++) {
    int A;
    cin >> A;
  }
  if(N != K)
  	cout << (N + K - 3)/(K - 1) << endl;
  else 
    cout << 1 << endl;
  
  return 0;
}

Measured memory_bytes: 256
// 標準入力
var fs = require('fs'),
length = fs.fstatSync(process.stdin.fd).size,
buffer = new Buffer(length),
bytesRead = fs.readSync(process.stdin.fd, buffer, 0, length, 0),
input = buffer.toString('utf8', 0, bytesRead).trim().split('\n');
main();
    
// ここから
function main(){
  var primeNumbers = calcPrimeNumbers();
  var primeCounts = new Int32Array(50001);

  for(var i = 1; i < 5133; i++){
    var pni = primeNumbers[i];
    for(var k = 1; k <= i; k++){
      var sum = pni + primeNumbers[k];
      if(sum > 50000)
        break;
        primeCounts[sum]++;
    }
  }
  var i = 0;
  while(c = +input[i++]){
    console.log(primeCounts[c]);
  }
  
}
   
function calcPrimeNumbers(){
  var max = 50021;
  var primeNumbers = new Int8Array(max + 1);
   
  // 除外
  primeNumbers[0] = primeNumbers[1] = 1;
  for(var i = 2, maxI = ~~Math.sqrt(max); i <= maxI; i++){
    if(primeNumbers[i]){
      continue;
    }
       
    for(var j = (i<<1); j <= max; j+=i){
      primeNumbers[j] = 1;
    }
  }
   
  var primeNums = new Int32Array(5134 + 1);
  var c = 0;
  for(var i = 1; i <= max; i++){
    if(!primeNumbers[i]){
      primeNums[++c] = i;
    }
  }
     
  return primeNums;
}

Measured memory_bytes: 13656
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int, int> pi;
#define debug(x) cerr << #x << ": " << x << endl;
#define debug2(x, y) debug(x) debug(y);
#define repn(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define rep(i, a) for(int i = 0; i < (int)(a); i++)
#define all(v) v.begin(), v.end() 
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define sq(x) ((x) * (x))
const int MOD = 1e9 + 7;

template<class T> T gcd(T a, T b){ return ((b == 0) ? a : gcd(b, a % b)); }

ll mypow(ll a, ll p){
	if(p == 0) return 1;
	if(p == 1) return (a % MOD);
	if(p & 1) return ((a % MOD) * (mypow(a, p - 1) % MOD)) % MOD;
	ll x = mypow(a, p / 2) % MOD;
	return (x * x) % MOD;
}

ll inv(ll base){
	return mypow(base, MOD - 2);
}

ll C(ll n, ll r){
	ll num = 1LL;
	ll r1 = r;
	ll n1 = n;
	while(r1--){
		num *= n1;
		n1--;
		num %= MOD;
	}
	ll den = 1LL;
	for(ll i = 1LL; i <= r; i++){
		den *= (1LL * i);
		den %= MOD;
	}
	return (num * inv(den)) % MOD;
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	//freopen("input.in", "r", stdin);
	//freopen("output.out", "w", stdout);
	ll n, a, b;
	cin >> n >> a >> b;
	ll ans = mypow(2, n);
	ans += MOD;
	ans -= C(n, a);
	ans += MOD;
	ans %= MOD;
	ans -= C(n, b);
	ans += MOD;
	ans %= MOD;
	cout << ans - 1 << endl;
	return 0;
}
/*
Things to look out for:
	- Integer overflows
	- Array bounds
	- Special cases
Be careful!
*/


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

#define ll long long 
#define inf 0x3f3f3f3f
#define infll 0x3f3f3f3f3f3f3f3f
#define all(x) (x).begin(),(x).end()
#define f(i, a, b) for (int i=a; i<(signed)(b); ++i)
#define pc __builtin_popcount // counts number of 1's in bin(num)
#define pb push_back
#define mp make_pair

const double pi = 2*acos(0.0);
//__gcd(n1, n2);
//cout << fixed;
//cout << setprecision(6); //fixes # of dp
//tgamma(i+1) is 1!
const int mod = 1e9 + 7;

void solve(){
    int n, k;
    cin >> n >> k;
    ll ans = 0;
    ll s[n+1];
    memset(s,0,sizeof(s));
    f(i,1,n+1){
        s[i] += i + s[i-1];
    }
    f(i,k,n+2){
        ll small = s[i-1];
        ll big = s[n];
        if(i != n + 1){
            big = s[n] - s[n-i];
        }
        ans += big-small+1;
    }
    cout << ans%mod;
}


int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	
    solve();
}








Measured memory_bytes: 5176
#include <stdio.h>
#include <set>
using namespace std;
int main(){
    int n,a,b;
    set<int> s;
    scanf("%d",&n);
    while(n--){
        scanf("%d%d",&a,&b);
        a+=b;
        while(s.find(a)!=s.end()){
            s.erase(a);
            a++;
        }
        s.insert(a);
    }
    for(int i:s){
        printf("%d %d\n",i,0);
    }
}


Measured memory_bytes: 5736
<?php
  $sum = 0;
  $amax = 0;
  for ($i=0; $i<5; $i++) {
    fscanf(STDIN, "%d", $a);
    $sum += (int)(($a+9)/10)*10;
    if ($a%10 != 0) {
	  $amax = max($amax, 10 - $a%10);
    }
  }
  echo $sum - $amax . "\n";
?>

Measured memory_bytes: 4604
import std.algorithm, std.container, std.conv, std.math, std.range, std.typecons, std.stdio, std.string;

auto rdsp(){return readln.splitter;}
void pick(R,T)(ref R r,ref T t){t=r.front.to!T;r.popFront;}
void readV(T...)(ref T t){auto r=rdsp;foreach(ref v;t)pick(r,v);}

void main()
{
  long n, m; readV(n, m);

  auto x = min(n, m/2);
  auto y = (m-x*2)/4;

  writeln(x+y);
}


Measured memory_bytes: 256
#!/usr/bin/env python3
# encoding:utf-8
import copy
import random
import bisect #bisect_left　これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
import math
import sys
import collections
from decimal import Decimal # 10進数で考慮できる
import numpy as np

mod = 10**9+7
sys.setrecursionlimit(mod) # 再帰回数上限はでdefault1000

d = collections.deque()
def LI(): return list(map(int, sys.stdin.readline().split()))
"""
H, W, K = LI()
c = [[0 for j in range(W)] for i in range(H)]

for h in range(H):
    c[h] = list(str(input()))

# print(c)
for h in range(H):
    for w in range(W):
        if c[h][w] == ".":
            c[h][w] = 0
        else:
            c[h][w] = 1 


"""
# 2 ** (H + W)通り試せば良い
"""
ans = 0
# 10進数のnを2進数のリストに変換


def n2kdigit(n,k):
    digits = [0 for i in range(H + W)]
    tmp = 0
    while n > 0:
        digits[tmp] = n % k
        n = n // k
        tmp += 1

    return digits

for i in range(2 ** (H + W)):
    cnt = 0
    c_ = copy.deepcopy(c)
    digits = n2kdigit(i, k = 2)
    for j, digit in enumerate(digits):
        if digit == 1:
            if j >= H:
                for h in range(H):
                    # print(j - H -1)
                    c_[h][j - H - 1] = 0
            else:
                "Hを示す"
                c_[j] = [0 for k in range(W)]
    # print(c_)
    for h in range(H):
        cnt += sum(c_[h])
    if cnt == K:
        ans += 1

print(ans)


"""

# 実装例
H, W, K = list(map(int, input().split()))

c = []
for h in range(H):
    l = []
    for s in input():
        if s == ".":
            l.append(0)
        else:
            l.append(1)
    c.append(l)

ans = 0
for bit_h in range(2 ** H): # bit_hが2進数で隠すか隠さないかを示す
    for bit_w in range(2 ** W):
        k = 0
        nn = np.asarray(c)
        # mask 部分
        for h in range(H):
            """
            (bit_h & 2 ** h)の部分で，マスクがかかっている部分を調べる
            >> hによって，参照したい行が0 or 1なのかを調べる．0なら色がないので，したの作業がいらない
            """
            if (bit_h & 2 ** h) >> h == 0:
                continue
            nn[h] = np.zeros((1, W))
        for w in range(W):
            if (bit_w & 2 ** w) >> w == 0:
                continue
            nn[:, w] = np.zeros((1, H))
        # cnt部分
        if K == np.sum(nn):
            ans += 1
print(ans)

        


        


Measured memory_bytes: 27128
#include <bits/stdc++.h>
#define forn(i,b) for(int i=0 ; i< b ;i++)
#define for1(i,b) for(int i=1 ; i<=b ;i++)
#define reps(i,a,b) for(int i=a ; i< b.length() ;i++)
typedef long long ll;
#define MOD 1000000007

using namespace std;




int main()
{
  ll x,hp=0 , n1 , n2 , res = 0  ;
  cin >> x  ;

  hp = 1000 * (x/500) ;
  res =(x%500)/5    ;
  hp += 5 * res;
  cout << hp ;


  return 0 ;
}


Measured memory_bytes: 256
#include<stdlib.h>

#include<iostream>
#include<vector>
using namespace std;
int vis[100001];
vector<int> arr[100001];
void dfs(int node)
{
    vis[node]=1;
    for(int child: arr[node])
        if(vis[child]==0)
        dfs(child);
}
int main()
{
    int a,b,n,m;
    cin>>n>>m;
    for(int i=1;i<=m;i++)
        cin>>a>>b,arr[a].push_back(b),arr[b].push_back(a);  
    int co=0;
    for(int i=1;i<=n;i++)
        if(!vis[i])
        dfs(i),co++;
    cout<<co-1;
}


Measured memory_bytes: 9496
import java.util.Locale;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in).useLocale(Locale.ENGLISH);
        int count = scanner.nextInt();
        double[] arr = new double[count + 1];
        for (int i = 1; i <= count; ++i) {
            arr[i] = scanner.nextDouble();
        }

        double[][] dp = new double[count + 1][count + 1];
        double res = 0.0;
        dp[0][0] = 1.0;
        for (int i = 1; i <= count; ++i) {
            for (int j = 0; j <= i; ++j) {
                dp[i][j] = dp[i - 1][j] * (1 - arr[i]);
                if (j > 0) {
                    dp[i][j] += dp[i - 1][j - 1] * arr[i];
                }
                if (i == count && j > i - j) {
                    res += dp[i][j];
                }
            }
        }

        System.out.println(res);
    }
}

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

int dp[3010][3010];
bool vis[3010][3010];
string s, t;
string ans;

int rec( int m, int n )
{
    if(m>=s.size() or n>=t.size())
        return 0;
    if(vis[m][n])
        return dp[m][n];

    int q1= 0, q2= 0, q3= 0;
    if( s[m]==t[n] )
        q1= 1+rec( m+1, n+1 );
    else
    {
        q2= rec( m+1, n );
        q3= rec( m, n+1 );
    }

    vis[m][n]= 1;

    return dp[m][n]= max( q1, max(q2,q3));
}

void gen( int i, int j )
{
    if( i>=s.size() or j>=t.size() )
        return;

    if( s[i]==t[j] )
    {
        ans.push_back( s[i] );
        gen( i+1, j+1 );
        return;
    }

    if( dp[i+1][j]>dp[i][j+1] )
    {
        gen( i+1, j );
        return;
    }

    gen( i, j+1 );
}

int main()
{
    cin>>s>>t;

    int pp= rec( 0, 0 );

    gen( 0,0 );

    cout<< ans <<"\n";
}


Measured memory_bytes: 44672
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef vector<int> VI;
typedef pair<int,int> PII;
typedef double db;
mt19937 mrand(random_device{}()); 
const int mod=1000000007;
#define ll long long
int rnd(int x) { return mrand() % x;}
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
// head
void printDivisors(int n) 
{
    for (int i=1; i<=sqrt(n); i++) 
    { 
        if (n%i == 0) 
        {
            if (n/i == i) 
                printf("%d ", i); 
  
            else 
                printf("%d %d ", i, n/i); 
        } 
    } 
} 

int _,a,b,n,k,m;
int main() {
	#ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
    int a,k;
    rep(i,0,5){
    	cin>>a;
    	if(a==0){
    		k=i+1;
    	}
    }
    cout<<k<<endl;
}

Measured memory_bytes: 3700
import java.util.*;

class Main {
	Scanner sc;
	long r1, c1, r2, c2;
	int[] m;
	static final int MOD = 1_000_000_007;
	
	private void calc() {
		sc = new Scanner(System.in);
		r1 = sc.nextInt();
		c1 = sc.nextInt();
		r2 = sc.nextInt();
		c2 = sc.nextInt();
		
		if (c2-c1 > r2-r1) {
			long t = c1; c1 = r1; r1 = t;
			t = c2; c2 = r2; r2 = t;
		}
		
		long nCr = 1;
		for (int i = 1; i <= r1; i++)
			nCr = nCr*(i+c1)%MOD * inv(i) % MOD;
		long top = nCr;
		long left = nCr;
		long s = nCr;
		long ds = nCr;
		
		for (long x = 1; x < r2-r1+c2-c1+1; x++) {
			long i = (2*ds - top - left+2*MOD)%MOD;
			ds = 0;
			left = left * ((c1 + r1 + x)%MOD )%MOD;
			if (x < c2-c1+1) {
				left = left * inv(c1 + x) %MOD;
				ds += left;
			} else {
				left = left * inv(r1 + x-c2+c1) %MOD;
			}
			top = top * ((c1 + r1 + x)%MOD )%MOD;
			if (x < r2-r1+1) {
				top = top * inv(r1 + x) %MOD;
				ds += top;
			} else {
				top = top * inv(c1 + x-r2+r1) %MOD;
			}
			ds = (ds + i)%MOD;
			s = (s + ds)%MOD;
		}
		
		System.out.println(s);
	}
	
	static final long inv(long a) {
		long b = MOD;
		long aa = a, bb = b;
		long x0 = 1, x1 = 0;
		long y0 = 0, y1 = 1;
	
		while (b != 0) {
			long q = a / b;
			long r = a % b;
			long x2 = x0 - q * x1;
			long y2 = y0 - q * y1;
	
			a = b; b = r;
			x0 = x1; x1 = x2;
			y0 = y1; y1 = y2;
		}
		if (bb > 0 && x0 < 0) {
			long n = -x0/bb;
			if (-x0%bb != 0) n++;
			x0 += n*bb; y0 -= n*aa;
		}
	    return x0;
	}
	
	public static void main(String[] args) {
		new Main().calc();
	}
}


Measured memory_bytes: 22484
import java.util.*;class Main{public static void main(String[]z){Scanner s=new Scanner(System.in);int n=s.nextInt()+1,m=s.nextInt(),i=1,j,t;int[] p=new int[n*n];Arrays.fill(p,9999999);for(;i<n;++i)p[i*n+i]=0;for(;m-->0;){z=s.next().split(",");i=new Integer(z[0]);j=new Integer(z[1]);p[i*n+j]=new Integer(z[2]);p[j*n+i]=new Integer(z[3]);}for(t=1;t<n;++t)for(i=1;i<n;++i)for(j=1;j<n;++j)if(p[i*n+j]>(m=p[i*n+t]+p[t*n+j]))p[i*n+j]=m;z=s.next().split(",");i=new Integer(z[0]);j=new Integer(z[1]);System.out.println(new Integer(z[2])-new Integer(z[3])-p[i*n+j]-p[j*n+i]);}}

Measured memory_bytes: 11000
loop do
  w, h = gets.split.map(&:to_i)
  break if h == 0

  field = h.times.map do
    gets.chomp.split(//)
  end


  i, j = -> () {
    field.each.with_index do |f, i|
      f.each.with_index do |c, j|
        return [i,j] if c == '@'
      end
    end
  }.()

  field[i][j] = '.'

  walk = -> (x, y) {
    return 0 if x < 0 || y < 0 || x >= h || y >= w
    return 0 if field[x][y] != '.'
    field[x][y] = 'x'
    return 1 + 
      walk.(x+1, y) +
      walk.(x-1, y) +
      walk.(x, y-1) +
      walk.(x, y+1)
  }

  cnt = walk.(i, j)

  puts cnt
end

Measured memory_bytes: 9168
def solve_range(h, frm, to):
    """[frm, to)"""
    # print(frm, to, h)
    if frm >= to:
        return 0
    res = 0
    start = frm
    for i in range(frm, to):
        h[i] -= 1
        if h[i] < 0:
            if start < i:
                res += solve_range(h, start, i) + 1
            start = i + 1
        elif i == to - 1:
            res += solve_range(h, start, to) + 1
    return res


def solve(h):
    return solve_range(h, 0, n)


n = int(input())
h = list(map(int, input().split()))

print(solve(h))

Measured memory_bytes: 3064
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintStream;
import java.util.Stack;

class Main {

    public static void main(String[] args) throws IOException {
        doit(args, System.in, System.out);
    }

    static void doit(String[] args, InputStream in, PrintStream out)
            throws IOException {
        BufferedReader reader = new BufferedReader(new InputStreamReader(in));
        String line = null;
        while ((line = reader.readLine()) != null) {
            if (line.isEmpty()) {
                continue;
            }
            String[] tokens = line.split(" ");
            Stack<Double> stack = new Stack<Double>();
            for (String token : tokens) {
                try {
                    double number = Double.parseDouble(token);
                    stack.push(number);
                    continue;
                } catch (NumberFormatException e) {
                    /* nothing */
                }
                double b = stack.pop();
                double a = stack.pop();
                double c = 0.0;
                if (token.equals("+")) {
                    c = a + b;
                } else if (token.equals("-")) {
                    c = a - b;
                } else if (token.equals("*")) {
                    c = a * b;
                } else if (token.equals("/")) {
                    c = a / b;
                }
                stack.push(c);
            }
            double result = stack.pop();
            out.println(String.format("%.6f", result));
        }
    }
}

Measured memory_bytes: 12000
#include<iostream>
#include<string>
#include<algorithm>
#include<utility>

using namespace std;

int main(){
  string s,s1="Sunny",s2="Cloudy",s3="Rainy";
  cin>>s;
  cout<<(equal(s.begin(),s.end(),s1.begin(),s1.end()) ?  "Cloudy" : equal(s.begin(),s.end(),s2.begin(),s2.end()) ? "Rainy" : "Sunny")<<endl;
  return 0;
}

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

using namespace std;

#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define REV(i,n) for(ll (i) = (n) - 1;(i) >= 0;--i)
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {REP(WW,n)cerr << v[WW] << ' ';cerr << endl << endl;}
#define SHOW2d(v,WW,HH) {REP(W_,WW){REP(H_,HH)cerr << v[W_][H_] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL
#define MOD 1000000007
#define fastcin() cin.tie(0);ios::sync_with_stdio(false)

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


int main(){
	
	int n;cin >> n;
	string a,b,c;cin >> a >> b >> c;
	int ans = 0;
	REP(i,n){
		set<char> s;
		s.insert(a[i]);
		s.insert(b[i]);
		s.insert(c[i]);
		if(s.size() == 1){
			
		}
		else if(s.size() == 2){
			ans++;
		}
		else {
			ans += 2;
		}
	}
	
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 256
import bisect
N = int(input())
A = [int(input())for i in range(N)]
m = [-A[0]]
ans = 1
for i in A[1:]:
    p = bisect.bisect_left(m,-i+1)
    if p == ans:
        ans += 1
        m.append(-i)
    else:
        m[p] = -i
print(ans)


Measured memory_bytes: 11756
#include <iostream>

int main(int argc, char** argv) {
	int n, balance, i, unit;
	double interest;
	balance = 100000;
	interest = 0.05;
	unit = 1000;
	std::cin >> n;
	for(i = 0; i < n; i++) {
		balance *= (1.00 + interest);
		if (balance % unit) {
		    balance += unit - (balance % unit);
		}
	}
	std::cout << balance << std::endl;
}


Measured memory_bytes: 3032
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
#define F(i,a,n) for(int i=a; i<n; i++)


int main(){
  int n,m;
  scanf("%d%d",&n,&m);
  int mm=m;
  while(mm){
    if(n%2){
      for(int i=1, r=n-1; i<r && mm; i++,r--){
        printf("%d %d\n",i,r);
        mm--;
      }
    }else{
      int flag=0;
      for(int i=1,r=n-1; i<r && mm; i++,r--){
        if(!flag && r-i<=n/2){
          flag=1;
          r--;
        }
        printf("%d %d\n",i,r);
        mm--;
      }
    }
  }
  
  return 0;
}

Measured memory_bytes: 1732
#include"bits/stdc++.h"
#define int long long
#define rep(i,n) for(int i=0,i##_len=(n);i<i##_len;++i)
#define itr(i,x) for(auto i=(x).begin();i!=(x).end();++i)
#define All(x) (x).begin(),(x).end()
using namespace std;
typedef pair<int,int> P;
const int mod=1000000007;


int mpow(int a,int x);
int m_inv(int n){return mpow(n,mod-2);}

int gcd(int x,int y){return y?gcd(y,x%y):x;}
int lcm(int x,int y){return x*y/gcd(x,y);}

signed main(){
    string s;
    cin>>s;
    int n=s.length();
    vector<int> dp(n+1);
    int a=-1,b=-1;
    rep(i,s.size()-1){
    	if(s[i]==s[i+1]){
    		a=i+1;
    		b=i+2;
    	}
    }
    rep(i,s.size()-2){
    	if(s[i]==s[i+2]){
    		a=i+1;
    		b=i+3;
    	}
    }
    cout<<a<<" "<<b<<endl;
}

int mpow(int a,int x){
	int ans=1;
	while(x>0){
		if(x%2==1) (ans*=a)%=mod;
		(a*=a)%=mod;
		x>>=1;
	}
	return ans;
}

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

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

fn read_vec2<T: std::str::FromStr>(n: u32) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}
fn main(){
    let xab = read_vec::<i64>();
    let (x,a,b) = (xab[0],xab[1],xab[2]);
    let ans = if (-a+b) <= 0{
        "delicious"
    } else if  -a+b <= x{
        "safe"
    } else {
        "dangerous"
    };
    println!("{}",ans);
}

Measured memory_bytes: 4352
import java.util.*;
 
class Main{
    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);
        int x = sc.nextInt();
        int t = sc.nextInt();
        
        if(x<=t){
            System.out.println("0");
            return;
        }else{
            System.out.println(x-t);
        }
        
    }
}

Measured memory_bytes: 21844
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int h,w;
  	cin>>h>>w;
	vector<string>grid(h);
  	for(int i=0;i<h;i++)
    {
      cin>>grid[i];
    }
  	vector<vector<int>>dp(h,vector<int>(w,INT_MAX));
  	dp[0][0]=(grid[0][0]=='#');
  	for(int row=0;row<h;row++)
    {
      for(int col=0;col<w;col++)
      {
        if(row==0&&col==0)
            continue;
        if(row!=0)
        {
            dp[row][col]=min(dp[row][col],dp[row-1][col]+(grid[row][col]=='#'&&grid[row-1][col]=='.'));
        }
        if(col!=0)
        {
            dp[row][col]=min(dp[row][col],dp[row][col-1]+(grid[row][col]=='#'&&grid[row][col-1]=='.'));
        }
          
      }
    }
    cout<<dp[h-1][w-1]<<endl;
}


Measured memory_bytes: 256