akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> pii;
typedef pair<long long,int> pli;
const long long mod=1000000007;
const long long inf=0x3f3f3f3f3f3f3f3f;
const int maxn=112345;
const int maxm=212345;
int n,m,s,t,u[maxm],v[maxm],w[maxm];
long long d[2][maxn],dp[2][maxn];
vector<pii> G[maxn];
inline void dijkstra(int s,long long *d,long long *dp) {
    for (int i=1;i<=n;++i) d[i]=inf;
    priority_queue<pli,vector<pli>,greater<pli> > que;
    d[s]=0;
    dp[s]=1;
    que.push(pli(0,s));
    while (!que.empty()) {
        int u=que.top().second;
        long long o=que.top().first;
        que.pop();
        if (o>d[u]) continue;
        for (int i=0;i<(int)G[u].size();++i) {
            int v=G[u][i].first;;
            int w=G[u][i].second;
            if (d[v]>d[u]+w) {
                d[v]=d[u]+w;
                dp[v]=dp[u];
                que.push(pli(d[v],v));
            } else if (d[v]==d[u]+w) dp[v]=(dp[v]+dp[u])%mod;

        }
    }
}
inline long long sqr(long long x) {
    return x*x%mod;
}
int main()
{
    scanf("%d%d%d%d",&n,&m,&s,&t);
    for (int i=1;i<=m;++i) {
        scanf("%d%d%d",&u[i],&v[i],&w[i]);
        G[u[i]].push_back(pii(v[i],w[i]));
        G[v[i]].push_back(pii(u[i],w[i]));
    }
    dijkstra(s,d[0],dp[0]);
    dijkstra(t,d[1],dp[1]);
    long long res=sqr(dp[0][t]);
    for (int i=1;i<=n;++i) if (d[0][i]+d[1][i]==d[0][t]&&d[0][i]==d[1][i])
        res=((res-sqr(dp[0][i])*sqr(dp[1][i])%mod)%mod+mod)%mod;
    for (int i=1;i<=m;++i) for (int j=0;j<2;++j) {
        if (d[0][u[i]]+d[1][v[i]]+w[i]==d[0][t]
            &&d[0][v[i]]>d[1][v[i]]
            &&d[1][u[i]]>d[0][u[i]])
            res=((res-sqr(dp[0][u[i]])*sqr(dp[1][v[i]])%mod)%mod+mod)%mod;
        swap(u[i],v[i]);
    }
    cout<<res<<endl;
    return 0;
}


Measured memory_bytes: 20628
import bisect
N, Q = map(int, input().split())
S = list(input())
lr = [list(map(int, input().split())) for i in range(Q)]

alst,clst=[],[]
for i in range(N-1):
    if S[i]=="A" and S[i+1]=="C":
        alst.append(i)
        clst.append(i+1)

ans=[]
for j in range(Q):
    l,r = lr[j][0]-1, lr[j][1]-1
    ans.append(bisect.bisect_right(clst,r) - bisect.bisect_left(alst,l))

for a in ans:
    print(a)


Measured memory_bytes: 36816
#include <bits/stdc++.h>
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define pb push_back
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) FOR(i, 0, n)
#define ll long long
using namespace std;

const ll P = 1000000007;
int gcd(int a, int b) { return b != 0 ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }

int main()
{
  cout << fixed << setprecision(10);
  ll N;
  cin >> N;
  ll M = pow(N,0.5);
  ll ans = 100000000000000;
  for(ll i=M;i>0;i--)
  {
    if(N%i==0)
    {
      cout << i+(N/i)-2 << endl;
      return 0;
    }
  }
  return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <algorithm>
#include <iterator>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <string>
#include <cmath>
using namespace std;
#define MOD 1000000007
#define INF 1<<30
#define LINF (ll)1<<62
#define MAX 510000
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(ll i=(a); i<(b); i++)
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll, ll> P;
typedef vector<pair<ll, ll>> vpl;
const int mod = 1e9 + 7;



int main(){
    ll n; cin >> n;
    vector<vector<P>> G(n);
    vector<pair<P,ll>> a(n),b(n);
    rep(i,n){
        ll p,q; cin >> p >> q;
        a[i] = make_pair(P(p,q),i);
        b[i] = make_pair(P(q,p),i);
    }
    sort(all(a));
    sort(all(b));
    rep(i,n){
        ll y,x;
        if(i>0){
            x = abs(a[i].first.first - a[i-1].first.first);
            y = abs(b[i].first.first - b[i-1].first.first);
            G[a[i].second].emplace_back(a[i-1].second,x);
            G[a[i-1].second].emplace_back(a[i].second,x);
            G[b[i].second].emplace_back(b[i-1].second,y);
            G[b[i-1].second].emplace_back(b[i].second,y);
        }
        if(i<n-1){
            x = abs(a[i].first.first - a[i+1].first.first);
            y = abs(b[i].first.first - b[i+1].first.first);
            G[a[i].second].emplace_back(a[i+1].second,x);
            G[a[i+1].second].emplace_back(a[i].second,x);
            G[b[i].second].emplace_back(b[i+1].second,y);
            G[b[i+1].second].emplace_back(b[i].second,y);
        }
    }
    priority_queue<P,vector<P>,greater<P>> pq;
    pq.emplace(0,0);
    vector<bool> visit(n,false);
    ll res = 0;
    while(!pq.empty()){
        P p = pq.top(); pq.pop();
        ll u = p.second;
        if(visit[u]) continue;
        visit[u] = true;
        res += p.first;
        for(auto v : G[u]){
            pq.emplace(v.second, v.first);
        }
    }
    cout << res << endl;
}

Measured memory_bytes: 32748
n , m = gets.split(" ").map(&:to_i)

matrix_a = Array.new(n).map{Array.new(m,0)}

for i in 0..n-1 do
	matrix_a[i] = gets.split(" ").map(&:to_i)
end

matrix_b = []

for i in 0..m-1 do	
	matrix_b[i] = gets.to_i
end

for i in 0..n-1 do
    sum = 0
	for j in 0..m-1 do
		sum += matrix_a[i][j] * matrix_b[j] 
	end
	puts sum
end

Measured memory_bytes: 8940
n, m = map(int, input().split())
a = []
b = []
c = []
d = []
for _ in range(n):
  _a, _b = map(int, input().split())
  a.append(_a)
  b.append(_b)

for _ in range(m):
  _c, _d = map(int, input().split())
  c.append(_c)
  d.append(_d)

for i in range(n):
  point = 1
  ans = abs(a[i]-c[0])+abs(b[i]-d[0])
  for j in range(m):
    man = abs(a[i] - c[j]) + abs(b[i] - d[j])
    if ans > man:
      point = j + 1
      ans = man
  print(point)


Measured memory_bytes: 3064
#include <iostream>

using namespace std;

int main()
{
    int w, h, x, y, r;
    cin >> w >> h >> x >> y >> r;
    if(x-r>=0 && y-r>=0 && x+r<=w && y+r<=h)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
}


Measured memory_bytes: 3088
import java.util.*;
public class Main {
    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);
        int N,A=0,B=0;
        N=sc.nextInt();
        if(N==1) System.out.println("Hello World");
        else if(N==2){
            A=sc.nextInt();
            B=sc.nextInt();
            int sum=A+B;
            System.out.println(sum);
        }

    }
}

Measured memory_bytes: 21204
N=int(input())
xyh=[list(map(int,input().split())) for _ in range(N)]

def calcH(x,y,h,Cx,Cy):
    if h>0:
        return(h+abs(x-Cx)+abs(y-Cy))
    return -1

for Cx in range(100+1):
    for Cy in range(100+1):
        H=-1
        check=[]
        for x,y,h in xyh:
            Hi=calcH(x,y,h,Cx,Cy)
            if Hi==-1:
                check.append(abs(x-Cx)+abs(y-Cy))
                continue
            if H==-1:
                H=Hi
            elif Hi!=H:
                break
        else:
            for c in check:
                if H>c:
                    break
            else:
                print(Cx,Cy,H)
                exit()

Measured memory_bytes: 3064
#include <cstdio>
#include <iostream>
#include <string>
#include <sstream>
#include <stack>
#include <algorithm>
#include <cmath>
#include <queue>
#include <map>
#include <set>
#include <cstdlib>
#include <bitset>
#include <tuple>
#include <assert.h>
#include <deque>
#include <bitset>
#include <iomanip>
#include <limits>
#include <chrono>
#include <random>
#include <array>
#include <unordered_map>
#include <functional>
#include <complex>

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

constexpr long long MAX = 5100000;
constexpr long long INF = 1LL << 60;
constexpr int inf = 1 << 28;
//constexpr long long mod = 1000000007LL;
//constexpr long long mod = 998244353LL;

using namespace std;
typedef unsigned long long ull;
typedef long long ll;

int dh[4] = { 1,0,-1,0 };
int dw[4] = { 0,1,0,-1 };
int main()
{
	/*
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	*/
	int kkt = 89;
	while (kkt) {
		int W, H; cin >> W >> H;
		if (W == 0) break;
		vector<string> vs(H); for (int i = 0; i < H; i++) cin >> vs[i];
		vector<vector<bool>> bl(H, vector<bool>(W, false)), wh(H, vector<bool>(W, false));
		{
			queue<pair<int, int>> q;
			for (int i = 0; i < H; i++) for (int j = 0; j < W; j++) if (vs[i][j] == 'B') q.emplace(i, j);
			while (!q.empty()) {
				int h, w; tie(h, w) = q.front();
				q.pop();
				for (int i = 0; i < 4; i++) {
					int nh = h + dh[i];
					int nw = w + dw[i];
					if (nh < 0 || nh >= H || nw < 0 || nw >= W) continue;
					if (vs[nh][nw] != '.') continue;
					if (bl[nh][nw]) continue;
					bl[nh][nw] = true;
					q.emplace(nh, nw);
				}
			}
		}
		{
			queue<pair<int, int>> q;
			for (int i = 0; i < H; i++) for (int j = 0; j < W; j++) if (vs[i][j] == 'W') q.emplace(i, j);
			while (!q.empty()) {
				int h, w; tie(h, w) = q.front();
				q.pop();
				for (int i = 0; i < 4; i++) {
					int nh = h + dh[i];
					int nw = w + dw[i];
					if (nh < 0 || nh >= H || nw < 0 || nw >= W) continue;
					if (vs[nh][nw] != '.') continue;
					if (wh[nh][nw]) continue;
					wh[nh][nw] = true;
					q.emplace(nh, nw);
				}
			}
		}
		int rb = 0, rw = 0;
		for (int i = 0; i < H; i++) for (int j = 0; j < W; j++) {
			if (bl[i][j] && !wh[i][j]) rb++;
			if (!bl[i][j] && wh[i][j]) rw++;
		}
		cout << rb << " " << rw << "\n";
	}
	return 0;

}


Measured memory_bytes: 3180
import java.util.Scanner;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int a=sc.nextInt();
    int b=sc.nextInt();
    while(true){
    if(a%b==0){
      System.out.println(b);
      break;
    }
      a%=b;
      if(b%a==0){
        System.out.println(a);
        break;
      }
      b%=a;
    }
     sc.close();
  }
}


Measured memory_bytes: 26300
from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from itertools import combinations # (string,3) 3回
from collections import deque
from collections import defaultdict
import bisect
#
#    d = m - k[i] - k[j]
#    if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#

import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7

def readInts():
  return list(map(int,input().split()))
def main():
    a,b = readInts()
    from fractions import gcd
    g = gcd(a,b)
    #print(g)
    i = 2
    A = defaultdict(int)
    while i * i <= g:
        if g % i == 0:
            A[i] += 1
            g //= i
        else:
            i += 1
    A[g] += 1
    ans = 1
    for k,v in A.items():
        if k != 1:
            ans += 1
    print(ans)
if __name__ == '__main__':
  main()


Measured memory_bytes: 5276
#include<cstdio>
#include<vector>
#include<algorithm>


using namespace std;
using vi=vector<int>;


int main(void)
{
	int n, x;

	while(scanf("%d%d", &n, &x)==2)
	{
		vi a(n);

		for(int i=0;i<n;i++)
		{
			scanf("%d", &a[i]);
		}
		sort(a.begin(), a.end());

		int ans=0;
		for(int i=0;i+1<n;i++)
		{
			if(x<a[i]) break;
			x-=a[i];
			ans++;
		}
		if(x==a[n-1]) ans++;
		printf("%d\n", ans);
	}

	return 0;
}


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

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

    int n, k;
    cin >> n >> k;
    vector<int> A(n);
    REP(i, n) cin >> A[i];

    int mini = 1e9;
    REP(i, n - k + 1){
        int tmp;
        tmp = A[i + k - 1] - A[i] + min(abs(A[i]), abs(A[i + k - 1]));
        mini = min(mini, tmp);
    } 

    cout << mini << endl;

    return 0;
}

Measured memory_bytes: 640
#include <cstdio>
#include <cctype>
#include <utility>
#include <vector>
#include <algorithm>
using namespace std;

const auto gcu = getchar_unlocked;
const auto pcu = putchar_unlocked;
#define _T template <typename T>
#define _HT template <typename H, typename... T>
#define _il inline
#define _sc _il bool scan
_T T in(int c){T n=0;int m=1;while(isspace(c)){c=gcu();}if(c=='-')m=-1,c=gcu();
	do{n=10*n+(c-'0'),c=gcu();}while(c>='0'&&c<='9');return m*n;}
_il int in() {return in<int>(gcu());}
_T T scan(T &n){int c=gcu();return c==EOF?false:(n=in<T>(c),true);}
_sc(char &c){c=gcu();gcu();return c!=EOF;}
#ifdef _GLIBCXX_STRING
_sc(string &s){int c;s="";
	for(;;){c=gcu();if(c=='\n'||c==' ')return true;else if(c==EOF)return false;s+=c;}}
#endif
_HT _sc(H &h, T&&... t){return scan(h)&&scan(t...);}
#define _ot _il void out
#define _ol _il void outl
_ot(bool b) {pcu('0'+b);}
_ot(const char *s){while(*s)pcu(*s++);}
_ot(char c){pcu(c);}
#ifdef _GLIBCXX_STRING
_ot(string s){for(char c:s)pcu(c);}
#endif
_T _ot(T n){static char b[20];char *p=b,m=n<0?pcu('-'),-1:1;
	if(!n)*p++='0';else while(n)*p++=n%10*m+'0',n/=10;while(p!=b)pcu(*--p);}
_ol(){out('\n');}
#ifdef _GLIBCXX_VECTOR
_T _ot(vector<T> &v){for(T &x:v)out(&x == &v[0]?"":" "),out(x);outl();}
#endif
_HT _ot(H&& h, T&&... t){out(h);out(move(t)...);}
template <typename... T> _ol(T&&... t){out(move(t)...);outl();}

int main() {
	for (int N, M; N = in(), M = in();) {
		vector<int> t(N), u;
		for (int &p: t)
			p = in();
		t.push_back(0);
		sort(t.begin(), t.end());
		for (auto i = t.begin(); i != t.end(); i++)
			for (auto j = i; j != t.end(); j++)
				if (*i + *j <= M)
					u.push_back(*i + *j);
		sort(u.begin(), u.end());
//		u.erase(unique(u.begin(), u.end()), u.end());
		int r = 0;
		for (auto i = u.begin(), e = u.end() - 1; i <= e; i++) {
			for (; *i + *e >= M; e--)
				;
			if (*i + *e > r)
				r = *i + *e;
		}
		outl(r);
	}
}


Measured memory_bytes: 6228
using System;
using System.Collections.Generic;
using System.Linq;
class Scanner
{
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner() {
        s = new string[0];
        i = 0;
    }

    public string next() {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return next();
        i = 0;
        return s[i++];
    }

    public int Int() {
        return int.Parse(next());
    }
    public int[] ArrayInt(int N, int add = 0) {
        int[] Array = new int[N];
        for (int i = 0; i < N; i++) {
            Array[i] = Int() + add;
        }
        return Array;
    }

    public long Long() {
        return long.Parse(next());
    }

    public long[] ArrayLong(int N, long add = 0) {
        long[] Array = new long[N];
        for (int i = 0; i < N; i++) {
            Array[i] = Long() + add;
        }
        return Array;
    }
}
class Program {
    struct X {
        public int index;
        public long value;
        public X(int INDEX, long VALUE) {
            index = INDEX;
            value = VALUE;
        }
    }

    static Scanner cin = new Scanner();
    static void Main() {
        int N = cin.Int();
        var A = new long[N];
        var B = new long[N];
        for (int i = 0; i < N; i++) {
            A[i] = cin.Long();
            B[i] = cin.Long();
        }

        var list = new List<X>();
        for (int i = 0; i < N; i++) {
            list.Add(new X(i, A[i] + B[i]));
        }
        list = list.OrderByDescending(x => x.value).ToList();
        //var takahashi = new List<int>();
        //var aoki = new List<int>();
        //for (int i = 0; i < N; i += 2) {
        //    takahashi.Add(dic.Keys.ElementAt(i));
        //}
        //for (int i = 1; i < N; i += 2) {
        //    aoki.Add(dic.Keys.ElementAt(i));
        //}

        long TAKAHASHI = 0, AOKI = 0;
        for (int i = 0; i < N; i += 2) {
            TAKAHASHI += A[list[i].index];
        }
        for (int i = 1; i < N; i += 2) {
            AOKI += B[list[i].index];
        }
        //foreach (var x in takahashi) {
        //    TAKAHASHI += A[x];
        //}
        //foreach (var x in aoki) {
        //    AOKI += B[x];
        //}
        //var C = new long[N];
        //for (int i = 0; i < N; i++) {
        //    C[i] = A[i] + B[i];
        //}

        //C = C.OrderByDescending(x => x).ToArray();
        //long takahashi = 0, aoki = 0;
        //for (int i = 0; i < N; i += 2) {
        //    takahashi += C[i];
        //}
        //for (int i = 1; i < N; i += 2) {
        //    aoki += C[i];
        //}
        Console.WriteLine(TAKAHASHI - AOKI);
        Console.ReadLine();
    }
}

Measured memory_bytes: 28996
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 1e9
#define ALL(v) v.begin(), v.end()

using namespace std;
typedef long long ll;

int main(){
    // read in integers
    ll n;
    cin >> n;

    vector<ll> coords(n);
    for (int i = 0; i < n; i++){
        cin >> coords.at(i);
    }
    
    int min_dist = INF;
    int min_p = 0;
    
    FOR(p, 0, 100){
        ll sum = 0.0;
        FOR(k, 0, n){
            sum += pow(coords[k] - p, 2.0);    
        } 
        if (sum < min_dist){
            min_dist = sum;
            min_p = p;
        }
    }
    cout << (int)(min_dist) << endl;
}

Measured memory_bytes: 256
package main

import (
	"fmt"
)

type Point struct{ X, Y int }
type Key struct{ Dx, Dy int }

func main() {
	var n int
	fmt.Scan(&n)

	if n == 1 {
		fmt.Println(1)
		return
	}

	ps := make([]Point, n)
	for i := range ps {
		fmt.Scan(&ps[i].X, &ps[i].Y)
	}

	xm := make(map[Key]int)
	for _, v1 := range ps {
		for _, v2 := range ps {
			if v1 == v2 {
				continue
			}
			xm[Key{v1.X - v2.X, v1.Y - v2.Y}]++
		}
	}

	max := 0
	for _, v := range xm {
		if v > max {
			max = v
		}
	}
	fmt.Println(n - max)
}


Measured memory_bytes: 896
#float型を許すな
#numpyはpythonで
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil,pi,factorial
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def SI(): return input().rstrip()
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7


n,m=MI()
data=[]
for i in range(m):
    a,b=MI()
    c=LI()
    u=0
    for x in c:
        u+=2**(x-1)
    data.append([a,u])
data.sort()
#print(data)
dp=[[inf]*(2**n) for i in range(m+1)]
dp[0]=[inf]*(2**n)
dp[0][0]=0
#print(dp)
for i in range(m):
    for j in range(2**n):
        dp[i+1][j|data[i][1]]=min(dp[i+1][j|data[i][1]],dp[i][j|data[i][1]],dp[i][j]+data[i][0])
        dp[i+1][j]=min(dp[i][j],dp[i+1][j])
        #print(i+1,j|data[i][1],dp[i][j|data[i][1]],dp[i][j]+data[i][0])
    #print()
#print(dp)
if dp[-1][-1]>=inf:
    print(-1)
else:
    print(dp[-1][-1])

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

int main() {
    int n;
    string s;
    cin >> n >> s;
    int sume[n+1]; sume[0] = 0;
    for (int i = 0; i < n; i++) {
        sume[i+1] = sume[i] + (s[i] == 'E');
    }
    int ans = (1 << 30);
    for (int i = 0; i < n; i++) {
        int tmp = (i - sume[i]) + (sume[n] - sume[i+1]);
        ans = min(ans, tmp);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1796
#include <stdio.h>
using namespace std;
#define MAX(a,b) (a>b?a:b)
#define MOD(a) (a>0?a:-(a))
#define custoate(i)
int main(){
  int npedras, maxpulo;
  scanf("%d %d",&npedras,&maxpulo);
  int hpedra[npedras],custoate[npedras];
  for (size_t i = 0; i < npedras; i++)
    scanf("%d", &hpedra[i]);
  custoate[0] = 0;
  int tempcost = 2147483647,k,tempcost2;
  for (size_t i = 1; i < npedras; i++,tempcost = 2147483647) {
    // printf("i = %d, tempcost = %d\n", i,tempcost);
    for (k= (maxpulo>i ? i : maxpulo); k > 0; k--) {
      // printf("k = %d ",k);
      tempcost2 = custoate[i-k] + MOD(hpedra[i-k]-hpedra[i]);
      if (tempcost > tempcost2)
        tempcost = tempcost2;
    }
    // printf("custo[%d] = %d",i,tempcost);
    custoate[i] = tempcost;
    // printf("\n\n");
  }
  printf("%d\n", custoate[npedras-1]);

}

Measured memory_bytes: 896
#include<bits/stdc++.h>
using namespace std;
char s[2100][2100];
int vis1[2100][2100],vis2[2100][2100];
int h,w,ans=0;
int main()
{
    cin>>h>>w;
    for(int i=0;i<h;i++) scanf("%s",s[i]);
    for(int i=0;i<w;i++) if(s[0][i]=='.') vis1[0][i]=1;
    for(int i=1;i<h;i++)
        for(int j=0;j<w;j++)
        {
            if(s[i][j]=='.')
            {
                if(s[i-1][j]=='.') vis1[i][j]=vis1[i-1][j]+1;
                else vis1[i][j]=1;
            }
        }
    for(int i=h-2;i>=0;i--)
        for(int j=0;j<w;j++)
        {
            if(vis1[i+1][j]&&vis1[i][j]) vis1[i][j]=vis1[i+1][j];
        }
    for(int i=0;i<h;i++) if(s[i][0]=='.') vis2[i][0]=1;
    for(int i=1;i<w;i++)
        for(int j=0;j<h;j++)
        {
            if(s[j][i]=='.')
            {
                if(s[j][i-1]=='.') vis2[j][i]=vis2[j][i-1]+1;
                else vis2[j][i]=1;
            }
        }
    for(int j=w-2;j>=0;j--)
        for(int i=0;i<w;i++)
        {
            if(vis2[i][j+1]&&vis2[i][j]) vis2[i][j]=vis2[i][j+1];
        }
    for(int i=0;i<h;i++)
        for(int j=0;j<w;j++)
            ans=max(ans,vis1[i][j]+vis2[i][j]);
    cout<<ans-1<<endl;
    return 0;
}

Measured memory_bytes: 38784
//#include <tourist>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> p;
const int INF = 1e9;
const ll LINF = ll(1e18);
const int MOD = 1000000007;
const int dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0};
const int Dx[8] = {0, 1, 1, 1, 0, -1, -1, -1}, Dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
#define rep(i, n) for (int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()
#define debug(v)          \
    cout << #v << ":";    \
    for (auto x : v)      \
    {                     \
        cout << x << ' '; \
    }                     \
    cout << endl;
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;
}
//cout<<fixed<<setprecision(15);有効数字15桁
//-std=c++14
//-std=gnu++17
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
  	int a, b, c;
    cin >> a>>b>>c;
    if(a+b>=c)yes;
  else no;
}


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

int main() {
	set<int> l;
	int p[3];
	for (int i = 0; i < 3; i++) {
		cin >> p[i];
		l.insert(p[i]);
	}
	int ans = l.size();
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
#define lli long long int
#define REP(i,s,l) for(lli i=s;i<l;i++)
#define DEBUG 0
#define INF (1LL<<50)

signed main(){

	lli n;
	cin>>n;
	vector<lli> a(n);
	vector<lli> plus,minus;

	REP(i,0,n){
		cin>>a[i];
		if(a[i]>=0)plus.push_back(a[i]);
		else minus.push_back(a[i]);
	}

	sort(plus.begin(),plus.end(),greater<lli>());
	sort(minus.begin(),minus.end());
	if(minus.empty())minus.push_back(plus.back()),plus.pop_back();
	if(plus.empty())plus.push_back(minus.back()),minus.pop_back();

	vector<pair<lli,lli>> res;
	lli cur = minus[0];
	REP(i,0,plus.size()-1){
		res.push_back({cur,plus[i]});
		cur -= plus[i];
	}
	res.push_back({plus.back(),cur});
	cur = plus.back()-cur;

	for(lli i=1;i<minus.size();i++){
		res.push_back({cur,minus[i]});
		cur-=minus[i];
	}
	cout<<cur<<endl;
	for(auto p:res)cout<<p.first<<" "<<p.second<<endl;

	return 0;
}


Measured memory_bytes: 5872
{-# LANGUAGE BangPatterns #-}

import Data.Bits
import Data.List
import Data.IntMap.Strict (IntMap)
import qualified Data.IntMap.Strict as IntMap
import qualified Data.ByteString.Char8 as B
import Control.Monad
import Control.Applicative
import Data.Maybe
import Data.Function
import qualified Data.IntMap.Strict as M
import qualified Data.ByteString.Char8 as B
import qualified Data.Vector.Unboxed as V
import qualified Data.Vector.Unboxed.Mutable as VM
import qualified Data.Vector as VB
import qualified Data.Vector.Mutable as VBM
-- import Data.Vector.Unboxed ((!))
import Data.Tuple
import Data.Ord (Down(..))
import Data.Coerce

code :: Int -> Int -> Int
code p k = 10^12 + 10^6 * p + k

query :: Int -> Int -> V.Vector (Int,Int) -> V.Vector Int
query n m vec
  = V.replicate m 0 V.// codes
  where
    dict :: VB.Vector (IntMap Int)
    dict = VB.create $ do
      dictmut <- VBM.replicate n $ IntMap.empty
      V.imapM_ (\i (p,y) -> do entry <- VBM.read dictmut (p-1)
                               VBM.write dictmut (p-1)
                                 $! IntMap.insert y i entry) vec
      return dictmut
    codes :: [(Int,Int)]
    codes = concat $ VB.toList $
      VB.imap (\pm1 -> zipWith (\k i -> (i,code (pm1+1) k)) [1..]
                                 . IntMap.elems) dict 

main :: IO ()
main = do
  [n,m] <- map read . words <$> getLine :: IO [Int]
  rest <- B.getContents
  let vec = V.unfoldrN m (\b -> let (l,r) = B.span (/= '\n') b in
                             Just (decode l, B.tail r)) rest
      decode l = (p,y)
        where Just (p, l1) = B.readInt l
              Just (y, _ ) = B.readInt $ B.dropWhile (== ' ') l1
  V.mapM_ (putStrLn . tail . show) $ query n m vec


Measured memory_bytes: 34300
import sys, math, itertools, bisect, copy, re
from collections import Counter, deque, defaultdict

# from itertools import accumulate, permutations, combinations, takewhile, compress, cycle
# from functools import reduce
# from math import ceil, floor, log10, log2, factorial
# from pprint import pprint

INF = float('inf')
MOD = 10 ** 9 + 7
EPS = 10 ** -7
sys.setrecursionlimit(1000000)

# N = int(input())
# N,M = [int(x) for x in input().split()]
# V = [[0] * 100 for _ in range(100)]
# A = [int(input()) for _ in range(N)]
# DP = [[0] * 100 for _ in range(100)]
# DP = defaultdict(lambda: float('inf'))


N = int(input())
A = []
m1 = 0
m2 = 0

for _ in range(N):
    a = int(input())
    if a >= m1:
        m2 = m1
        m1 = a
    elif a > m2:
        m2 = a
    A.append(a)

for a in A:
    if a == m1:
        print(m2)
    else:
        print(m1)

pass


Measured memory_bytes: 69080
#include <iostream>
#include <string>
#include <vector>
#include <climits>
#include <set>
#include <algorithm>
#include <unordered_map>
#include <queue>
#include <iomanip>
#include <map>
#include <utility>
#include <numeric>
#include <chrono>
#include <ctime>
#include <bitset>
#include <iterator>

#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define P pair<long long, long long>
#define debug(x) cerr << #x << ": " << x << ", "
#define debugln(x) cerr << #x << ": " << x << '\n'

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

using namespace std;
using ll = long long;
const ll mod = 1e9 + 7;

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

  int w, a, b; cin >> w >> a >> b;
  cout << max(0, abs(a-b)-w);
}

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

int main() {
    
       string a[]={"AC","WA","TLE","RE"};
       int b[4]={0};
       string s;
       long int n;
       cin>>n;
       for(long int i=0;i<n;i++)
       {
           cin>>s;
           for(long int j=0;j<4;j++)
           {
               if(s==a[j])
               b[j]++;
           }
       }
       for(long int i=0;i<4;i++)
       {
           cout<<a[i]<<" x "<<b[i]<<endl;
       }
	// your code goes here
	return 0;
}


Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
#define rep(i,m,n) for(int i=(int)(m);i<(int)(n);++i)
#define rREP(i,m,n) for(int (i)=(n)-1; (i)>=(m);--(i))
#define all(x) (x).begin(),(x).end()
#define out(y,x,h,w) (y)<0||(x)<0||(y)>=(h)||(x)>=(w)
constexpr int INF = 1000000001;
constexpr ll mod = 1000000007;
constexpr double PI = 3.1415926535897932;

template<class T>inline bool chmin(T& a, T b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}
template<class T>inline bool chmax(T& a, T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}
inline void init() {
	cin.tie(nullptr); cout.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}

int main() {
	init();

	int N; cin >> N;
	vector<ll>A(N), B(N);
	rep(i, 0, N) {
		cin >> A[i] >> B[i];
	}
	ll ans = 0;
	rREP(i, 0, N) {
		ans += (ans + A[i] + B[i] - 1) / B[i] * B[i] - A[i] - ans;
	}
	cout << ans << "\n";

	return 0;
}

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

// main
int main(){
    int K, X;
    cin >> K >> X;

    if(500 * K >= X){
        cout << "Yes" << endl;
    }else
    {
        cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
forgotten :: Int -> Int -> Int -> Int -> [Int]
forgotten x1 y1 x2 y2 = [x2 - diffy, y2 + diffx, x1 - diffy, y1 + diffx]
 where diffx = x2 - x1
       diffy = y2 - y1

main = do
  points <- fmap (map read.words) getLine
  let x1:y1:x2:y2:_ = points
  mapM_ print $ forgotten x1 y1 x2 y2
  

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

const int64 INF = 1LL << 60;

struct Edge {
    int to, id;
    Edge(int _to, int _id) : to(_to), id(_id) {}
};

int main() {
    int N; cin >> N;
    vector<vector<Edge>> G(N);
    for(int i = 0; i < N - 1; ++i) {
        int a, b;
        cin >> a >> b;
        a--, b--;
        G[a].emplace_back(b, i);
        G[b].emplace_back(a, i);
    }
    int M; cin >> M;
    auto dfs = [&](auto &&dfs, int u, int v, int pre) -> int64 {
        if(u == v) return INF;
        int64 res = 0LL;
        for(auto &e : G[u]) {
            if(e.to == pre) continue;
            int64 tmp = dfs(dfs, e.to, v, u);
            if(tmp) {
                res |= tmp;
                res |= 1LL << e.id;
            }
        }
        return res;
    };
    vector<int64> masks(M);
    for(int i = 0; i < M; ++i) {
        int u, v;
        cin >> u >> v;
        --u, --v;
        masks[i] = dfs(dfs, u, v, -1) - INF;
    }
    int64 ans = 0LL;
    for(int bit = 0; bit < (1 << M); ++bit) {
        int64 mask = 0;
        for(int i = 0; i < M; ++i) {
            if(bit & (1 << i)) mask |= masks[i];
        }
        int n = __builtin_popcount(bit);
        int m = __builtin_popcountll(mask);
        if(n % 2 == 0) ans += 1LL << (N - m - 1);
        else ans -= 1LL << (N - m - 1);
    }
    cout << ans << '\n';
    return 0;
}


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

using namespace std;

struct point {
	double x, y;
	point() {}
	point(double _x, double _y) : x(_x), y(_y) {}
};

void read(point &P) {
	cin >> P.x >> P.y;
}

point operator + (const point &P, const point &Q) {
	return point(P.x + Q.x, P.y + Q.y);
}

point operator - (const point &P, const point &Q) {
	return point(P.x - Q.x, P.y - Q.y);
}

point operator * (const point &P, const double k) {
	return point(P.x * k, P.y * k);
}

inline double dot(const point &P, const point &Q) {
	return P.x * Q.x + P.y * Q.y;
}

inline double cross(const point &P, const point &Q) {
	return P.x * Q.y - P.y * Q.x;
}

inline double norm2(const point &P) {
	return dot(P, P);
}

inline double norm(const point &P) {
	return sqrt(dot(P, P));
}

inline point project(const point &P, const point &P1, const point &P2) {
	return P1 + (P2 - P1) * (dot(P2 - P1, P - P1) / norm2(P2 - P1));
}

inline point reflect(const point &P, const point &P1, const point &P2) {
	return project(P, P1, P2) * 2.0 - P;
}

inline point intersect(const point &A, const point &B, const point &C, const point &D) {
	return A + (B - A) * (cross(C - A, C - D) / cross(B - A, C - D));
}

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

	int q;
	cin >> q;
	while (q--) {
		point A, B, C, D;
		cin >> A.x >> A.y >> B.x >> B.y >> C.x >> C.y >> D.x >> D.y;
		point answer = intersect(A, B, C, D);
		cout << fixed << answer.x << " " << fixed << answer.y << "\n";
	}
}

Measured memory_bytes: 3232
#include<iostream>
#include<algorithm>
#include<cstring>
#include<string>
#include<cmath>
using namespace std;
int main(){
//int n,a[100001]={0};
//cin>>n;
//cout<< <<endl;
int n,a;
cin>>n>>a;
cout<<n*n-a; 
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
#define pb push_back
int dy[]={0, 0, 1, -1, 1, 1, -1, -1};
int dx[]={1, -1, 0, 0, 1, -1, -1, 1};

#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define mp make_pair
#define fi first
#define sc second

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

	a += 13 - 2;
	b += 13 - 2;
	a %= 13;
	b %= 13;

	if(a < b) {
		cout << "Bob" << endl;
	}else if(a > b) {
		cout << "Alice" << endl;
	}else {
		cout << "Draw" << endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define chmin(a, b) ((a)=min((a), (b)))
#define chmax(a, b) ((a)=max((a), (b)))
#define fs first
#define sc second
#define eb emplace_back
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;

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

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

int main(){
    int h, w; cin>>h>>w;
    vector<string> a(h);
    for(int i=0; i<h; i++) cin>>a[i];

    vector<vector<ll>> dp(h+10, vector<ll>(w+10, 0));
    dp[0][0]=1;
    for(int i=0; i<h; i++){
        for(int j=0; j<w; j++){
            if(a[i][j]=='#') continue;

            if(0<=i-1 && 0<=j-1){
                dp[i][j]=max(dp[i][j], dp[i-1][j]+dp[i][j-1]);
            }
            else if(0<=j-1){
                dp[i][j]=max(dp[i][j], dp[i][j-1]);
            }
            else if(0<=i-1){
                dp[i][j]=max(dp[i][j], dp[i-1][j]);
            }
            dp[i][j]%=MOD;
        }
    }
    cout << dp[h-1][w-1] << endl;
}

Measured memory_bytes: 9344
from collections import deque

x,y,a,b,c = map(int,input().split())
p = sorted(list(map(int,input().split())), reverse=True)
q = sorted(list(map(int,input().split())), reverse=True)
r = sorted(list(map(int,input().split())), reverse=True)

p = deque(p[0:x])
q = deque(q[0:y])
r = deque(r)


while len(r) != 0 and min(p[-1],q[-1]) < r[0]:
  if p[-1] < q[-1]:
    p.appendleft(r.popleft())
    p.pop()
  else:
    q.appendleft(r.popleft())
    q.pop()
    
print(sum(p)+sum(q))

Measured memory_bytes: 106980
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

template <unsigned T>
bool nextBitset(bitset<T> &bs, int digit)
{
    bitset<T> x, y, z;
    x = bs.to_ulong() & (~(bs.to_ulong()) + 1ULL);
    y = bs.to_ulong() + x.to_ulong() + 0ULL;
    z = bs & ~y;
    if(bs[digit-1] && bs == z)
        return false;
    bs = ((z.to_ulong() / x.to_ulong()) >> 1) + 0ULL;
    bs |= y;
    return true;
}

int main()
{
    for(;;){
        int n, s;
        cin >> n >> s;
        if(n == 0)
            return 0;

        bitset<10> bs((1<<n)-1);
        int ret = 0;
        do{
            int tmp = 0;
            for(int i=0; i<10; ++i){
                if(bs[i])
                    tmp += i;
            }
            if(tmp == s)
                ++ ret;
        }while(nextBitset(bs, 10));
        cout << ret << endl;
    }
}

Measured memory_bytes: 0
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <string>
#include <cmath>

using namespace std;

#define ll long long

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

    if(n == m){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }

    return 0;
}

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

public class Main {

	Scanner sc = new Scanner(System.in);
	public void run() {
		while(sc.hasNext()){
			int n = sc.nextInt();
			int m = sc.nextInt();
			int l = sc.nextInt();
			int k = sc.nextInt();
			int a = sc.nextInt();
			int h = sc.nextInt();
			if(n == 0 && m == 0 && l == 0 && k == 0 && a == 0 && h == 0)break;
			else calc(n, m, l, k, a, h);
			
		}
	}
	public void calc(int n, int m, int l, int k, int a, int h){
		int[] freezeTown = new int[n];
		int[][] roads = new int[n][n];
		for(int i = 0; i < n; i++){
			for(int j = 0; j < n; j++){
				roads[i][j] = Integer.MAX_VALUE;
			}
		}
		for(int i = 0; i < l; i++){
			int town = sc.nextInt();
			freezeTown[town] = 1;
		}
		freezeTown[a] = 1;
		freezeTown[h] = 1;
		for(int i = 0; i < k; i++){
			int x = sc.nextInt();
			int y = sc.nextInt();
			int t = sc.nextInt();
			roads[x][y] = t;
			roads[y][x] = t;
		}
		
		//ワーシャるフロイド
		for(int t = 0; t < n; t++){
			for(int i = 0; i < n; i++){
				for(int j = 0; j < n; j++){
					int pk;
					if(roads[i][t] == Integer.MAX_VALUE || roads[t][j] == Integer.MAX_VALUE) 
						pk = Integer.MAX_VALUE;
					else pk = roads[i][t] + roads[t][j];
					
					if(pk < roads[i][j]) roads[i][j] = pk;
				}
			}
		}
		
		int[][] p = new int[n][n];
		
		//初期化
		for(int i = 0; i < n; i++){
			for(int j = 0; j < n; j++){
				if(freezeTown[i] == 1 && freezeTown[j] == 1 && roads[i][j] <= m){
					p[i][j] = roads[i][j];
				}
				else p[i][j] = Integer.MAX_VALUE;
			}
		}
		
		//ワーシャルフロイドもういっちょ
		for(int t = 0; t < n; t++){
			for(int i = 0; i < n; i++){
				for(int j = 0; j < n; j++){
					int pk;
					if(p[i][t] == Integer.MAX_VALUE || p[t][j] == Integer.MAX_VALUE)
						pk = Integer.MAX_VALUE;
					else pk = p[i][t] + p[t][j];
					
					if(pk < p[i][j]) p[i][j] = pk;	
				}
			}
		}
		if(p[a][h] == Integer.MAX_VALUE) System.out.println("Help!");
		else {
			int pk = p[a][h];
			if(pk > m) pk = pk + p[a][h] - m;
			System.out.println(pk);
		}
	}

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

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

typedef long long int ll;
ll h, w, dp[1007][1007];
char grid[1007][1007];

int main() {
    cin >> h >> w;
    for(ll i = 1; i <= h; ++i) {
        for(ll j = 1; j <= w; ++j) cin >> grid[i][j];
    }

    dp[1][1] = 0;

    bool ok = 1;
    for(ll i = 1; i <= h; ++i) {
        if(grid[i][1] == '#') ok = 0;

        if(ok) dp[i][1] = 1;
    }

    ok = 1;
    for(ll i = 1; i <= w; ++i) {
        if(grid[1][i] == '#') ok = 0;

        if(ok) dp[1][i] = 1;
    }

    for(ll i = 2; i <= h; ++i) {
        for(ll j = 2; j <= w; ++j) {
            if(grid[i][j] == '#') dp[i][j] = 0;
            else {
                dp[i][j] = dp[i - 1][j] + dp[i][j - 1];
                dp[i][j] %= 1000000007;
            }
        }
    }

    /*for(ll i = 1; i <= h; ++i) {
        for(ll j = 1; j <= w; ++j) {
            cout << dp[i][j] << ' ';
        }

        cout << endl;
    }*/

    cout << dp[h][w] << endl;
    return 0;
}

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

#define pb push_back
#define S second
#define F first
#define sz size()
#define eps 0.000001
#define oo 2000000007
#define endl '\n'
#define bg begin()
#define nd end()
#define up upper_bound
#define lw lower_bound
#define debug(x) #x << " = " << x << "; "
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vii;
string abc = "abcdefghijklmnopqrstuvwxyz";


int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	int n, w;
	cin >> n >> w;
	int val[n], weight[n];
	ll dp[n+1][w + 1];
	for(int i = 0; i < n; i++){
		cin  >> weight[i] >> val[i];
	}
	for(int i = 0; i <= w; i++) dp[n][i] = 0;
	for(int i = n - 1; i >= 0; i--){
		for(int j = 0; j <= w; j++){
			dp[i][j] = 0;
			if(j - weight[i] >= 0) dp[i][j] = max(dp[i][j], dp[i + 1][j - weight[i]] + val[i]);
			dp[i][j] = max(dp[i][j], dp[i + 1][j]);
		}
	}
	cout << dp[0][w] << endl;
}

Measured memory_bytes: 79232
W, H, N = map(int, input().split())

l = [0, W, 0, H]

for _ in range(N):
  x, y, a = map(int, input().split())
  if a == 1:
    if l[0] < x:
      l[0] = x
  elif a == 2:
    if l[1] > x:
      l[1] = x
  elif a == 3:
    if l[2] < y:
      l[2] = y
  else:
    if l[3] > y:
      l[3] = y

if l[0] < l[1] and l[2] < l[3]:
  print((l[1]-l[0])*(l[3]-l[2]))
else:
  print(0)

Measured memory_bytes: 38384
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main() {
	vector<int> a(4);
	for (int i = 0; i < 4; i++) {
		cin >> a[i];
	}
	sort(a.begin(), a.end());
	if (a[0] == a[1] && a[2] == a[3]) {
		cout << "yes" << endl;
	}
	else {
		cout << "no" << endl;
	}
	return 0;
}

Measured memory_bytes: 3140
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<string> vs;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define all(x) (x).begin(),(x).end()

constexpr auto INF = INT_MAX/2;
constexpr auto MOD = 1000000007;

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

	ll ans = 0;


	if (k > 0) {
		for (int b = k + 1;b <= n;b++) {
			ans += ((ll)b - k) * (n / b) + max((n % b) - k + 1, 0);
		}
	}
	else ans = (ll)n * n;

	cout << ans << endl;

}

Measured memory_bytes: 256
unittest
{
	assert( [ "10 30 20" ].parse.expand.solve == "Yes" );
	assert( [ "30 30 100" ].parse.expand.solve == "No" );
	assert( [ "56 25 31" ].parse.expand.solve == "Yes" );
}



import std.conv;
import std.range;
import std.stdio;
import std.typecons;

void main()
{
	stdin.byLineCopy.parse.expand.solve.writeln;
}

auto parse( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto abc = input.front.split.to!( long[] );
	return tuple( abc[ 0 ], abc[ 1 ], abc[ 2 ] );
}

auto solve( long a, long b, long c )
{
	return ( a + b == c || a + c == b || b + c == a ) ? "Yes" : "No";
}


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

struct node{
	node*l,*r;
	int cnt,val,Min;
};
node pool[400000];
int p;

int cnt(node*t){return t?t->cnt:0;}
int Min(node*t){return t?t->Min:INF;}

node*update(node*t){
	if(!t)abort();
	t->cnt=cnt(t->l)+cnt(t->r)+1;
	t->Min=min({t->val,Min(t->l),Min(t->r)});
	return t;
}
node*merge(node*l,node*r){
	if(!l)return r;
	if(!r)return l;
	if(rand()%(cnt(l)+cnt(r))<cnt(l)){
		l->r=merge(l->r,r);
		return update(l);
	}
	else{
		r->l=merge(l,r->l);
		return update(r);
	}
}
pair<node*,node*>split(node*t,int k){
	if(!t)return make_pair((node*)NULL,(node*)NULL);
	if(k<=cnt(t->l)){
		auto p=split(t->l,k);
		t->l=p.second;
		return make_pair(p.first,update(t));
	}
	else{
		auto p=split(t->r,k-cnt(t->l)-1);
		t->r=p.first;
		return make_pair(update(t),p.second);
	}
}

int main(){
	int n,q;scanf("%d%d",&n,&q);
	node*root=NULL;
	rep(i,n){
		int a;scanf("%d",&a);
		node*t=&pool[p++];
		*t={NULL,NULL,1,a,a};
		root=merge(root,t);
	}
	rep(i,q){
		int x,y,z;scanf("%d%d%d",&x,&y,&z);
		if(x==0){
			z++;
			auto a=split(root,y);
			auto b=split(a.second,z-y-1);
			auto c=split(b.second,1);
			root=merge(merge(merge(a.first,c.first),b.first),c.second);
		}
		else if(x==1){
			z++;
			auto a=split(root,y);
			auto b=split(a.second,z-y);
			printf("%d\n",Min(b.first));
			root=merge(merge(a.first,b.first),b.second);
		}
		else{
			auto a=split(root,y);
			auto b=split(a.second,1);
			b.first->val=z;
			update(b.first);
			root=merge(merge(a.first,b.first),b.second);
		}
	}
}


Measured memory_bytes: 9456
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
using namespace std;
 
#define mod 1000000007
#define FOR(x,to) for(int x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
#define long long long
inline int rei(){int x;cin>>x;return x;}
inline long rel(){long x;cin>>x;return x;}
inline string res(){string x;cin>>x;return x;}
//------------------------------------------------------- 
bool S[200000];
long DP[4][200000];
long C[100000];
void Calc(){
	int N = rei();
	int M = rei();
	string s = res();
	for(int i=0;i<M;i++){
		S[i] = s[i] == s[0];
	}
	long ans;
	{
		bool AllSame = true;
		for(int i=0;i<M;i++){
			AllSame &= S[i];
		}
		if(AllSame){
			DP[0][0] = 1;
			DP[3][0] = 1;
			for(int i=1;i<N;i++){
				DP[0][i] = DP[1][i-1];
				DP[1][i] = (DP[1][i-1]+DP[0][i-1]) % mod;
				DP[2][i] = DP[3][i-1];
				DP[3][i] = (DP[3][i-1]+DP[2][i-1]) % mod;
			}
			ans = DP[1][N-1] + DP[2][N-1] + DP[3][N-1];
			ans %= mod;
			cout << ans << endl;
			return;
		}
	}
	if(N % 2 != 0){
		cout << 0 << endl;
		return;
	}
	int K = -1;
	{
		int before = 0;
		for(int i=0;i<M;i++){
			if(S[i]){
				before++;
			}
			else{
				if(K == -1){
					K = (before+2)/2;
				}
				else{
					if(before % 2 != 0){
						K = min(K,(before+2)/2);
					}
				}
				before = 0;
			}
		}
	}
	C[0] = 1;
	long sum = 1;
	for(int i=1;i<N/2;i++){
		C[i] = sum;
		sum += C[i];
		if(i-K >= 0){
			sum += mod - C[i-K];
		}
		sum %= mod;
	}
	ans = 0;
	for(int i=1;i<=min(N/2,K);i++){
		ans += i*C[N/2-i]%mod;
	}
	ans *= 2;
	ans %= mod;
	cout << ans << endl;
}
int main(int argc,char** argv){
	ios::sync_with_stdio(false), cin.tie(0);
	cout.tie(0); Calc(); return 0;
}

Measured memory_bytes: 7060
import java.util.Scanner;

public class Main {
    public static void main(String args[] ) throws Exception {
    	new Main().exec(args);
    }

    public Main() {
    }

    public void exec(String args[]) throws Exception {
    	Scanner sc = new Scanner(System.in);
    	long a = sc.nextLong();
    	long b = sc.nextLong();
    	long x = sc.nextLong();
    	long ax = a/x;
    	long amx = a%x;
    	long bx = b/x;
    	long bmx = b%x;
    	if(amx==0){
        	System.out.println(bx-ax+1);
    	}else{
        	System.out.println(bx-ax);
    	}
    }
}

Measured memory_bytes: 9684
#include <bits/stdc++.h>
using namespace std;
int main () {
  long N, sum = 0;
  cin >> N;
  vector<pair<long, long>> data(N);
  for(int i = 0; i < N; i++){
    cin >> data.at(i).first >> data.at(i).second;
  }
  for(int i = N - 1; i >= 0; i--){
    if((sum + data.at(i).first) % data.at(i).second == 0)continue;
    else {
      sum += data.at(i).second - (sum + data.at(i).first) % data.at(i).second;
    }
  }
  cout << sum << endl;
  return 0;
}


Measured memory_bytes: 1792
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    N = int(readline())

    vec = [[0] * 10 for _ in range(10)]
    for n in range(1, N + 1):
        s = str(n)
        vec[int(s[0])][int(s[-1])] += 1

    ans = 0
    for i in range(10):
        for j in range(10):
            ans += vec[i][j] * vec[j][i]

    print(ans)
    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 73464