akhauriyash/Code-Regression huggingface dataset:
//https://atcoder.jp/contests/abc083/tasks/abc083_a

#include <bits/stdc++.h>
using namespace std;
int main()
{
    int A, B, C, D;
    // string op;
    cin >> A >> B >> C >> D;
    if (A + B > C + D)
    {
        cout << "Left" << endl;
    }
    else if (A + B < C + D)
    {
        cout << "Right" << endl;
    }
    else
    {
        cout << "Balanced" << endl;
    }
}

Measured memory_bytes: 3636
fact=[1]
temp=1
MOD=10**9+7
for i in range(1,7000):
    temp*=i
    temp%=MOD
    fact+=[temp]

def bino(a,b):
    if b>a:
        return 0
    else:
        up=fact[a]
        down=fact[b]*fact[a-b]
        down=pow(down,MOD-2,MOD)
        return (up*down)%MOD
def ans(N,K,i):
    return (bino(K-1,i-1)*bino(N-K+1,i))%(10**9+7)

N,K=list(map(int,input().strip().split(' ')))
for i in range(1,K+1):
    print(ans(N,K,i))
    


Measured memory_bytes: 3572
c = [list(map(int, input().split())) for i in range(3)]
a = [0, 0, 0]
b = [0, 0, 0]
a[0] = 0
for i in range(3):
    for j in range(3):
        if i == 0:
            b[j] = c[i][j]
        else:
            a[i] = c[i][j]-b[j]

ans = []
ans1 = [0, 0, 0]
for i in range(3):
    ans1 = [0, 0, 0]
    for j in range(3):
        ans1[j] = a[i]+b[j]
    ans.append(ans1)

print("Yes" if c == ans else "No")

Measured memory_bytes: 3064
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;

namespace AtCoder
{
    class Program
    {
        private static string Read() { return Console.ReadLine(); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }

        static long Solve(int N, long[] A)
        {
            var dp = new long[N - 1][];
            dp[0] = new long[] { A[0], -A[0] };
            for (int i = 1; i < N - 1; ++i)
            {
                dp[i] = new long[2];
                dp[i][0] = Math.Max(dp[i - 1][0] + A[i], dp[i - 1][1] - A[i]);
                dp[i][1] = Math.Max(dp[i - 1][0] - A[i], dp[i - 1][1] + A[i]);
            }
            return Math.Max(dp[N - 2][0] + A[N - 1], dp[N - 2][1] - A[N - 1]);
        }

        static void Main(string[] args)
        {
            int N = ReadInt();
            long[] A = ReadLongs();
            Console.WriteLine(Solve(N, A));
        }
    }
}


Measured memory_bytes: 32728
#include <iostream>
#include <cstdio>
#include <string>
#include <cassert>
#include <map>
#include <vector>
#include <algorithm>
using namespace std;

#define rep(i, n)     reps(i, 0, n)
#define reps(i, f, n) for (int i = (f); i < (int)(n); ++i)

struct Data {
    int id;
    int len;
    Data(int id, int len) : id(id), len(len) {}
    Data(){}
};

vector<Data> hdd;
vector<int> deleted;

void W(int id, int s)
{
    rep(i, hdd.size()){
        if(deleted[hdd[i].id]){
            if(hdd[i].len <= s){
                s -= hdd[i].len;
                hdd[i].id = id;
            }
            else{
                int remain = hdd[i].len - s;
                hdd[i].id = id;
                hdd[i].len = s;
                hdd.insert(hdd.begin()+i+1, Data(0, remain));
                s = 0;
            }
        }
        if(s == 0)
            return;
    }
    //assert(1==0);
}

void D(int id)
{
    deleted[id] = 1;
}

int R(int p)
{
    int pos = 0;
    rep(i, hdd.size()){
        if(pos<=p && p<pos+hdd[i].len){
            return hdd[i].id;
        }
        pos += hdd[i].len;
    }
    //assert(0);
}

void dump()
{
    puts("===");
    rep(i, hdd.size()){
        printf("%d, len=%d\n", hdd[i].id, hdd[i].len);
    }
    puts("");
}

int main()
{
    int n;
    while(scanf("%d", &n), n){
        // initialize
        hdd.assign(1, Data(0, 1000000010));
        deleted.assign(n+1, 0);
        deleted[0] = 1;
        map<int, int> dict;
        vector<int> inv(n+1, -1);
        
        rep(i, n){
            char cmd[10];
            scanf("%s", cmd);
            if(cmd[0] == 'W'){
                int id, s;
                scanf("%d%d", &id, &s);
                
                int tmp = dict.size() + 1;
                dict[id] = tmp;
                inv[tmp] = id;
                W(tmp, s);
            }
            else{
                int id;
                scanf("%d", &id);
                if(cmd[0] == 'D')
                    D(dict[id]);
                else{
                    int ret = R(id);
                    if(deleted[ret])
                        puts("-1");
                    else
                        printf("%d\n", inv[ret]);
                }
            }
        }
        puts("");
    }
    return 0;
}

Measured memory_bytes: 1432
#include <iostream>
#include <map>

using namespace std;

int addTx(int p, int x)
{
    float v = p;
    v *= (100 + x);
    v /= 100;
    return (int)v;
}

int main(void)
{
    int a, b, t;
    while(cin >> a >> b >> t){
        if(a == 0 && b == 0 && t == 0)
            return 0;

        int max = 0;

        for(int x = 1; x <= t; ++x)
            for(int y = 1; y <= (t - x); ++y){
                // cout << addTx(x, a) + addTx(y, a) << endl;
                if(addTx(x, a) + addTx(y, a) == t){
                    int s = addTx(x, b) + addTx(y, b);
                    if(max < s)
                        max = s;
                }
            }

        cout << max << endl;
    }
}

Measured memory_bytes: 1160
#import sys
#import numpy as np
import math
#from fractions import Fraction
import itertools
from collections import deque
from collections import Counter
#import heapq
from fractions  import gcd
#input=sys.stdin.readline
import bisect
s=input()
t=input()
n=len(s)
x={}
y={}
for i in range(n):
    if s[i] not in x:
        x[s[i]]=set([i])
    else:
        x[s[i]].add(i)
    if t[i] not in y:
        y[t[i]]=set([i])
    else:
        y[t[i]].add(i)
a=set()
b=set()
for i in x.values():
  if i not in y.values():
    print("No")
    break
else:
  print("Yes")

Measured memory_bytes: 113048
object Main{
  def main(args: Array[String]) {
    val sc = new java.util.Scanner(System.in)
    val a = sc.nextInt
    val b = sc.nextInt

    val oe = (a * b % 2) match {
      case 0 => "Even"
      case 1 => "Odd"
    }
    println(oe)
  }
}


Measured memory_bytes: 25536
#include <iostream>
#include <cstdio>
#include <algorithm>

using namespace std;

#define FOR(i,a,b) for(int i = (a); i < (b); i++)
#define REP(i,n) FOR(i,0,n)

typedef long long ll;

ll dp[2000][2000];
int cake[2000];
int n;

ll dfs(int a, int b, bool f) {
	if (dp[a][b]) return dp[a][b];
	if (a == b) {
		if (f) return dp[a][b] = cake[a];
		else return dp[a][b] = 0;
	}
	
	ll res = 0;
	if (f) {
		res = max(dfs((a + 1) % n, b, !f) + cake[a], dfs(a, (b + n - 1) % n, !f) + cake[b]);
	}
	else {
		if (cake[a] < cake[b])
			res = dfs(a, (b + n - 1) % n, !f);
		else
			res = dfs((a + 1) % n, b, !f);
	}
	
	return dp[a][b] = res;
}

int main() {
	cin >> n;
	REP(i, n) scanf("%d", &cake[i]);
	
	ll ans = 0;
	REP(i, n) ans = max(ans, dfs((i + 1) % n, (i + n - 1) % n, false) + cake[i]);
	cout << ans << endl;
	return 0;
}

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

const int INF = 10000000;

int main()
{
    int h, w;
    cin >> h >> w;
    string s[103];
    for(int i = 0; i < h; i++) cin >> s[i];
    int d[102][102];
    for(int i = 0; i < h; i++) for(int j = 0; j < w; j++) d[i][j] = INF;
    d[0][0] = 0;
    if(s[0][0] == '#') d[0][0] = 1;
    for(int i = 0; i < h; i++){
        for(int j = 0; j < w; j++){
            if(s[i][j] == '#'){
                if(i > 0){
                    if(s[i - 1][j] == '#') d[i][j] = min(d[i][j], d[i - 1][j]);
                    else d[i][j] = min(d[i][j], d[i - 1][j] + 1);
                }
                if(j > 0){
                    if(s[i][j - 1] == '#') d[i][j] = min(d[i][j], d[i][j - 1]);
                    else d[i][j] = min(d[i][j], d[i][j - 1] + 1);
                }
            }
            else{
                if(i > 0) d[i][j] = min(d[i][j], d[i - 1][j]);
                if(j > 0) d[i][j] = min(d[i][j], d[i][j - 1]);
            }
        }
    }
    cout << d[h - 1][w - 1] << endl;
}

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

#include <vector>
#include <stack> // s.top()
#include <queue> // s.front()
using namespace std;
typedef long long llong;

#define INFTY 10000000

typedef pair<llong, llong> P;

bool pairComp(const P& firstElof, const P& secondElof) {
	return firstElof.second > secondElof.second;
}

int main() {
	int N;
	vector<int> L;

	cin >> N;
	for (int i = 0; i < N; i++) {
		int ipt = 0;
		cin >> ipt;
		L.push_back(ipt);
	}
	sort(L.begin(), L.end());
	int mx = L[N-1];
	int sm = 0;
	for (int i = 0; i < N-1; i++) {
		sm += L[i];
	}
	if (sm > mx)cout << "Yes" << endl;
	else cout << "No" << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define forn(i, n) for(int i = 0; i < int(n); i++)
#define fore(i, l, r) for(int i = int(l); i < int(r); i++)
#define pb push_back
#define all(x) x.begin(), x.end()
#define sz(a) int((a).size())
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef pair<int, int> pii;
const int mod = 1e9 + 7;
template<class T, class U> inline void add_self(T &a, U b){a += b;if (a >= mod) a -= mod;if (a < 0) a += mod;}
template<class T, class U> inline void min_self(T &x, U y) { if (y < x) x = y; }
template<class T, class U> inline void max_self(T &x, U y) { if (y > x) x = y; }

#define _deb(x) cout<<x;
void _print() {cerr << "]\n";} template <typename T, typename... V>void _print(T t, V... v) {_deb(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#define deb(x...) cerr << "[" << #x << "] = ["; _print(x)
template <class T, class U> void print_m(const map<T,U> &m, int w=3){if(m.empty()){cout<<"Empty"<<endl; return;}for(auto x: m)cout<<"("<<x.first<<": "<<x.second<<"),"<<endl;cout<<endl;}
template<class T, class U>void debp(const pair<T, U> &pr, bool end_line=1){cout<<"{"<<pr.first<<" "<<pr.second<<"}"; cout<<(end_line ? "\n" : ", ");}
template <class T> void print_vp(const T &vp, int sep_line=0){if(vp.empty()){cout<<"Empty"<<endl; return;}if(!sep_line) cout<<"{ ";for(auto x: vp) debp(x,sep_line);if(!sep_line) cout<<"}\n";cout<<endl;}
template <typename T>void print(const T &v, bool show_index = false){int w = 2;if(show_index){for(int i=0; i<sz(v); i++)cout<<setw(w)<<i<<" ";cout<<endl;}for(auto &el: v) cout<<setw(w)<<el<<" ";cout<<endl;}
template <typename T>void print_vv(const T &vv){if(sz(vv)==0) {cout<<"Empty"<<endl; return;} int w = 3;cout<<setw(w)<<" ";for(int j=0; j<sz(*vv.begin()); j++)cout<<setw(w)<<j<<" ";cout<<endl;int i = 0;for(auto &v: vv){cout<<i++<<" {";for(auto &el: v) cout<<setw(w)<<el<<" ";cout<<"},\n";}cout<<endl;}

int main(){
    ll a; string b;
    while(cin>>a>>b){
        int c1 = b[0] - '0';
        int c2 = b[2] - '0';
        int c3 = b[3] - '0';

        ll a1 = a*c1;
        ll a2 = a*c2*10;
        ll a3 = a*c3;
        ll ans = a1 + (a2+a3)/100;
        cout<<ans<<endl;
    }
    return 0;
}

Measured memory_bytes: 3644
//【ライブラリここから】
// 1. 入力の容易化（https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8）
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

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

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

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

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

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

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

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}
//【ライブラリここまで】
fn main() {
    input! { n: String };
    let mut val_sum = 0;
    for c in n.chars() {
        val_sum += c as i32 - '0' as i32
    }
    println!("{}", if val_sum % 9 == 0 { "Yes" } else { "No" });
}


Measured memory_bytes: 2308
#define _USE_MATH_DEFINES
#include<iostream>
#include<fstream>
#include<cstdlib> 
#include<string>
#include<math.h>
#include<bitset>
#include<algorithm>
#include<vector>
#include<set>
#include<stack>
#include<queue>
using namespace std;

int main(){

	string s;
	int k;
	cin >> s >> k;

	vector<int> v;

	int sumv=0;
	for(int i=0;i<s.size();i++){
		int t=s[i]-'a';
		if(t!=0)t=26-t;
		v.push_back(t);
		sumv+=t;
	}

	bool flag=1;

	for(int i=0;i<s.size()-1;i++){
		if(true){
			if(k>=v[i]){
				cout << 'a';
				k-=v[i];
			}else{
				cout << s[i];
			}
		}else{
			cout << s[i];
		}
	}
	int t=s[s.size()-1]-'a';
	char c = 'a'+(t+k)%26;
	cout << c << endl;

	//while(1);

	return 0;
}

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

using namespace std;

using ll = long long;

template<class T>
struct Graph {
    struct Edge {
        int dst; T w;
        Edge(int _d, T _w) : dst(_d), w(_w) {}
    };

    const int n, s;
    const T INF;
    bool is_neg_cycle;
    std::vector<std::vector<Edge>> adj;
    std::vector<T> d;

    Graph(int _n, int _s)
        : n(_n), s(_s), INF(std::numeric_limits<T>::max()),
          is_neg_cycle(false), adj(n), d(n, INF) { }

    void add_edge(int u, int v, T w) { adj[u].emplace_back(Edge(v, w)); }
    T ShortestDistance(const int t) const { return d[t]; }
    bool IsNegativeCycleFromS() const { return is_neg_cycle; }

    bool CheckNegativeCycle() {
        std::fill(d.begin(), d.end(), 0);
        BellmanFord();
        return is_neg_cycle;
    }

    void BellmanFord() {
        d[s] = 0;
        for (int i = 0; ; ++i) {
            bool update = false;
            for (int v = 0; v < n; ++v)
                for (const auto &e : adj[v])
                    if (d[v] < INF && d[v] + e.w < d[e.dst]) {
                        d[e.dst] = d[v] + e.w;
                        update = true;
                        if (e.dst == n - 1 && n <= i) is_neg_cycle = true;
                    }
            if (!update) break;
            if (i == 2 * n) { break; }
        }
    }
};

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

    int n, m;
    cin >> n >> m;

    Graph<ll> g(n, 0);
    for (int i = 0; i < m; ++i) {
        ll a, b, c;
        cin >> a >> b >> c;
        g.add_edge(a - 1, b - 1, -c);
    }

    g.BellmanFord();
    if (g.is_neg_cycle) cout << "inf\n";
    else cout << -g.ShortestDistance(n - 1) << endl;

    return 0;
}


Measured memory_bytes: 384
n = int(input())
mv = 0
mi = 0
d = []
for i in range(n):
    tmp = int(input())
    if tmp > mv:
        mv = tmp
        mi = i
    else:
        d.append(tmp)

for i in range(n):
    if i == mi:
        print(max(d))
    else:
        print(mv)

Measured memory_bytes: 12532
#include<cstdio>


int main(){
    int a[100];
    int n,m,sum=0,ans1=0,ans2=0;
    scanf("%d",&n);
    for(int i=0;i<n;i++){
        scanf("%d",a+i);
        sum+=a[i];
    }
    m=sum/n;
    for(int i=0;i<n;i++){
        ans1+=(a[i]-m)*(a[i]-m);
    }
    if(m>=0)m++;
    else m--;
    for(int i=0;i<n;i++){
        ans2+=(a[i]-m)*(a[i]-m);
    }
    if(ans1<ans2)printf("%d\n",ans1);
    else printf("%d\n",ans2);
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std::literals::string_literals;
using i64 = std::int_fast64_t;
using std::cout;
using std::cerr;
using std::endl;
using std::cin;

template<typename T>
std::vector<T> make_v(size_t a){return std::vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return std::vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

int main() {
	i64 n; scanf("%lld", &n);

	long double x = (long double)n / 3.;
	printf("%.12Lf\n", x * x * x);
	return 0;
}


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

int main(){
    int n,a,b,c;
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>a>>b>>c;
        if(a*a+b*b==c*c||a*a+c*c==b*b||b*b+c*c==a*a){
            cout<<"YES"<<endl;
        }else{
            cout<<"NO"<<endl;
        }
    }
    return 0;
}

Measured memory_bytes: 3064
#include <stdio.h>
int main(void)
{
    int d,t,s;
    scanf("%d %d %d", &d,&t,&s);
    double time = (double)d / s;
    if(time > t){
        printf("No");
    }
    else{
        printf("Yes");
    }
    return 0;

}


Measured memory_bytes: 1700
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():
    X, A, B = map(int, read().split())

    print((X - A) % B)

    return


if __name__ == '__main__':
    main()


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

#define rep(i, n) for (int i = 0; i < (n); i++)
#define repr(i, n) for (int i = (n) - 1; i >= 0; i--)

using namespace std;
using ll = long long;

const int MOD = 1000000007;

class mint {
  int n;
public:
  mint(int n_ = 0) : n(n_) {}
  friend mint operator-(mint a) { return -a.n + MOD * (a.n != 0); }
  friend mint operator+(mint a, mint b) { int x = a.n + b.n; return x - (x >= MOD) * MOD; }
  friend mint operator-(mint a, mint b) { int x = a.n - b.n; return x + (x < 0) * MOD; }
  friend mint operator*(mint a, mint b) { return (long long)a.n * b.n % MOD; }
  friend mint &operator+=(mint &a, mint b) { return a = a + b; }
  friend mint &operator-=(mint &a, mint b) { return a = a - b; }
  friend mint &operator*=(mint &a, mint b) { return a = a * b; }
  friend bool operator==(mint a, mint b) { return a.n == b.n; }
  friend bool operator!=(mint a, mint b) { return a.n != b.n; }
  friend istream &operator>>(istream &i, mint &a) { return i >> a.n; }
  friend ostream &operator<<(ostream &o, mint a) { return o << a.n; }
};

const int B = 2500;

mint dp[55][55][5050];

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int N, K;
  cin >> N >> K;
  dp[0][0][B] = 1;
  for (int i = 0; i < N; i++) {
    for (int j = 0; j <= N; j++) {
      for (int k = 0; k <= 2*B; k++) {
        if (dp[i][j][k] == 0) continue;
        dp[i+1][j][k] += dp[i][j][k];
        if (j>0) dp[i+1][j][k+i-i] += j*dp[i][j][k];
        dp[i+1][j+1][k-i-i] += dp[i][j][k];
        if (j>0) dp[i+1][j][k-i+i] += j*dp[i][j][k];
        if (j>0) dp[i+1][j-1][k+i+i] += j*j*dp[i][j][k];
      }
    }
  }
  cout << dp[N][0][B+K] << endl;
}


Measured memory_bytes: 59904
#include <iostream>
#include <algorithm>
#include <string>
#define int long long
using namespace std;
signed main() {
	int n, a, b, c, d; cin >> n >> a >> b >> c >> d;
	n--;
	for (int i = 0; i <= n; i++) {
		int max, min;
		max = i * d - (n - i)*c;
		min = i * c - (n - i)*d;
		if (a + min <= b && b <= a + max) {
			cout << "YES\n";
			return 0;
		}
	}
	cout << "NO\n";
}

Measured memory_bytes: 256
using System;
using System.Linq;

namespace ConsoleApp22
{
    class Program
    {
        static void Main(string[] args)
        {
            var n = Convert.ToInt32(Console.ReadLine());
            double[] a = Console.ReadLine().Split(' ').Select(double.Parse).Take(n).ToArray();
            var answer = 0.0;

            for (int i = 0; i < a.Length; i++)
            {
                answer += (1 / a[i]);
            }

            Console.WriteLine((1 / answer).ToString());

        }

    }
}


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

int main()
{
    int n, m, d;
    
    scanf("%d %d %d", &n, &m, &d);
    
    double per;
    
    if(d!=0) per = 2*(n-d)/pow(n,2);
    else per = (n-d)/pow(n,2);
    
    printf("%.10f", per*(double)(m-1));
    
    return 0;
}

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

using namespace std;

using ll=long long;
const ll INF = 1e15+5ll;
const int mxVal=100000;

void min_self(ll &a, ll b){
    a=min(a,b);
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);

    int n,w;
    cin>>n>>w;
    vector<ll>dp(mxVal+1,INF);
    dp[0]=0;
    for(int i=0; i<n; i++){
        int wei, val;
        cin>>wei>>val;
        for(int curr=mxVal; curr-val>=0; curr--){
            min_self(dp[curr],dp[curr-val]+(ll)wei);
        }
    }
    ll ans=0;
    for(int i=mxVal; i>=0; i--){
        if(dp[i]<=w){
            ans=i;
            break;
        }
    }
    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 3968
/******************************************************************************

                              Online C++ Compiler.
               Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.

*******************************************************************************/

#include <iostream>

using namespace std;

int main()
{
    int s , w ;
    cin>>s>>w;
    
    if ( s<=w){
        
        cout<<"unsafe";
        
    }
  else 
  {
      cout<<"safe";
  }
  
  
    return 0;
}


Measured memory_bytes: 3636
import sys

k,s = map(int,sys.stdin.readline().split(' '))

result = 0

for x in range(k+1):
    for y in range(min(s-x+1,k+1)):
        z = s-x-y
        if z < 0: continue
        if z<=k:
            result+=1
        
print(result)

Measured memory_bytes: 9168
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;

char ds[] = "NESW";

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

int H, W;
string s[100];

struct state {
	int x, y;
	int d;
	state(int x_, int y_, int d_)
		: x(x_), y(y_), d(d_) {}
	bool operator<(const state& a) const {
		return x != a.x ? x < a.x : y != a.y ? y < a.y : d < a.d;
	}
};

state nex(const state& st) {
	int x = st.x, y = st.y, d = st.d;
	while (true) {
		int tx = x + dx[d], ty = y + dy[d];
		if (0 <= tx && tx < H && 0 <= ty && ty < W && s[tx][ty] != '#') break;
		d = (d + 1) & 3;
	}
	return state(x + dx[d], y + dy[d], d);
}

state nex(state st, int cnt) {
	while (cnt--) st = nex(st);
	return st;
}

int main()
{
	ios::sync_with_stdio(false), cin.tie(0);
	ll L;
	while (cin >> H >> W >> L, H | W | L) {
		int sx = 0, sy = 0, sd = 0;
		for (int i = 0; i < H; i++) {
			cin >> s[i];
			for (int j = 0; j < W; j++) {
				if (s[i][j] != '.' && s[i][j] != '#') {
					sx = i;
					sy = j;
					sd = find(ds, ds + 4, s[i][j]) - ds;
				}
			}
		}
		state st(sx, sy, sd);
		map<state, int> d;
		int it = 0;
		auto tmp = st;
		while (!d.count(tmp)) {
			d[tmp] = it++;
			tmp = nex(tmp);
		}
		int rp = it - d[tmp];
		if (L < d[tmp]) {
			tmp = nex(st, L);
		}
		else {
			tmp = nex(tmp, (L - d[tmp]) % rp);
		}
		cout << tmp.x + 1 << ' ' << tmp.y + 1 << ' ' << ds[tmp.d] << endl;
	}
	return 0;
}



Measured memory_bytes: 3548
#include <iostream>
#include <cstdio>
#include <climits>

using namespace std;

typedef unsigned long long ull;
typedef long double ld;

int n; ull m;
ull a[20];
ld p[20];

inline ull gcd(ull a, ull b) {
    if (a > b) swap(a, b);
    if (a == 0) return b;
    return gcd(b % a, a);
}

ull lcm(ull a, ull b) {
    a /= gcd(a, b);
    if ((double)a * b > 1e18) return 0; // オーバーフロー
    return a * b;
}

int main() {
    cin >> n >> m;
    for (int i = 0; i < n; i++) cin >> a[i];
    for (int i = 0; i < n; i++) {
        int _p; cin >> _p;
        p[i] = _p / 100.0;
    }

    ld expv = 0; // 期待値, expected value
    for (int s = 1; s < (1<<n); s++) {
        int bitcount = 0;
        ull div_factor = 1;
        ld pos = 1.0;
        for (int i = 0; i < n; i++) {
            if (s & (1<<i)) {
//                cout << a[i] << ' ';
                bitcount++;

                ull _lcm = lcm(div_factor, a[i]);
                // オーバーフローしたとき
                // そもそも10**18より大きい数で割り切れる数はm以下には存在しないため無視する
                if (_lcm == 0) goto loop_end;
                div_factor = _lcm;
                pos *= p[i];
            }
        }
//        cout << endl;

        if (bitcount % 2 == 1) {
            expv += pos * (m / div_factor);
        } else {
            expv -= pos * (m / div_factor);
        }
//        cout << pos << ' ' << div_factor << ' ';
//        cout << expv << endl;
loop_end:
        continue;
    }

    printf("%.10llf\n", expv);
    return 0;
}

Measured memory_bytes: 1204
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
int main(){
  ll n;cin>>n;int a[10001]={0};
  for(int i=1;i*i<=10000;i++){
	for(int j=1;j*j<=10000;j++){
	  for(int k=1;k*k<=10000;k++){
	  	ll x=i*i+j*j+k*k+i*j+j*k+k*i;
	  	if(x<=10000)a[x]++;
      }
    }
  }
  for(int i=1;i<=n;i++){
    cout<<a[i]<<endl;
  }
}


Measured memory_bytes: 3684
#include <cstdio>
#define MX (200000 + 255)

int du[MX];

int main(){
	int n; scanf("%d" ,&n);
	for(int i = 1 ,u ; i < n ; ++i){
		scanf("%d" ,&u);
		du[u]++;
	}for(int i = 1 ; i <= n ; ++i){
		printf("%d\n" ,du[i]);
	}return 0;
}

Measured memory_bytes: 4004
n = int(input())

a = list(map(int,input().split()))

l = [0]*100005 

for i in a:
    l[i] += 1
    
ans = 0
for i in range(1,99999):
    ans = max(ans,l[i] + l[i-1] + l[i+1])

print(ans)

Measured memory_bytes: 13964
N,K = map(int,input().split())
R,S,P = map(int,input().split())
T = input()
N = len(T)
ans = 0
for i in range (0,N-K):
  if str(T[i]) == str(T[i+K]):
    T = T[:i+K] + 'a' + T[i+K+1:]
for i in range (0,N):
  if str(T[i]) == "r":
    ans = ans + P
  elif str(T[i]) == "s":
    ans = ans + R
  elif str(T[i]) == "p":
    ans = ans + S
print(ans)

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

int main() {
  ll n; cin >> n;
  vector<ll>v(n);
  for(ll i = 0; i<n; i++){
    cin >> v[i];
  }
  sort(v.begin(),v.end());
  ll sum;
  for(ll i = 0; i<n-1; i++){
    sum+=v[i];
  }
  if(sum>v[n-1]) cout << "Yes" << endl;
  else cout << "No" << endl;
  
  return 0;
}

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

int main() {

  int N;
  cin >> N;

  map<int, int> map;

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

  int count = 0;

  for (auto i: map) {
    if (i.second % 2 != 0) {
      count++;
    }
  }

  cout << count << endl;

}

Measured memory_bytes: 4864
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, n) for (int i = 1; i < (int)(n); i++)
#define Sort(a) sort(a.begin(), a.end())
typedef long long int ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
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;}

int main(){
    int a[33] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
    int k;
    cin >> k;
    cout << a[k-1] << endl;
    return 0;
}

Measured memory_bytes: 3596
N = int(input())
A = [input()]
C = 0
for i in range(N-1):
    B = input()
    if A[i][-1] == B[0]:
        A.append(B)
    else:
        C +=1
        break
A = set(A)
if C == 1:
    print("No")
elif len(A) == N:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 3060
from sys import exit, setrecursionlimit, stderr
from functools import reduce
from itertools import *
from collections import *
from bisect import *

def read():
  return int(input())
 
def reads():
  return [int(x) for x in input().split()]

setrecursionlimit(1 << 30)

class union_find:
  def __init__(self, n): self.par = [-1] * n; self.rank = [0] * n
  def __repr__(self): return "union_find({0})".format([self.root(i) for i in range(n)])
  def unite(self, x, y):
    x = self.root(x); y = self.root(y)
    if x == y: return
    if self.rank[x] < self.rank[y]: self.par[x] = y
    else:
      self.par[y] = x
      if self.rank[x] == self.rank[y]: self.rank[x] += 1
  def root(self, x):
    if self.par[x] == -1: return x
    else: self.par[x] = self.root(self.par[x]); return self.par[x]
  def same(self, x, y): return self.root(x) == self.root(y)

N = read()
ps = []
for i in range(N):
  x, y = reads()
  ps.append((i, x, y))

edges = []

for q in range(1, 3):
  ps.sort(key=lambda p: p[q])
  for i in range(N-1):
    edges.append((ps[i+1][q] - ps[i][q], ps[i][0], ps[i+1][0]))

edges.sort()

uf = union_find(N)
ans = 0
for c, i, j in edges:
  if not uf.same(i, j):
    ans += c
    uf.unite(i, j)
print(ans)

Measured memory_bytes: 127904
#include "bits/stdc++.h"
using namespace std;

int main(){
    int n;
    cin>>n;
    int k;
    int h[n];
    cin>>k;
    int res=0;
    for(int i=0;i<n;i++){
           cin>>h[i];
           if(h[i]>=k) res++;
    }
    cout<<res;

}

Measured memory_bytes: 640
#include <bits//stdc++.h>
using namespace std;
#define int long long
signed main(){
	int n,m,k;
	cin>>n>>m>>k;
	for(int i=0;i<=n;i++){
		for(int j=0;j<=m;j++){
			if(i*m+j*n-i*j*2==k){
				cout<<"Yes\n"<<endl;
				return 0;
			}
		}
	}
	cout<<"No\n";
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  ll n;
  cin >> n;
  if (n%2 == 1) {
    cout << 0 << endl;
    return 0;
  }
  
  n /= 2;
  ll cnt = 0;
  for (ll i = 1; i < 30; i++) {
    ll x = pow(5, i);
    if (n/x == 0) {
      break;
    }
    cnt += n/x;
  }
  
  cout << cnt << endl;
}

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

const int N=333;
typedef long long LL;
int A[N][N],idx[N][N];

int main(){
	int n,flag=1;
	LL ans=0;
	cin>>n;
	for(int i=1;i<=n;i++)
	for(int j=1;j<=n;j++)
	cin>>A[i][j],idx[i][j]=0;
	
	for(int k=1;k<=n;k++){
		for(int i=1;i<=n;i++){
			for(int j=1;j<=n;j++){
				if(i==j||i==k||j==k) continue;
				if(A[i][k]+A[k][j]<A[i][j]) flag=0;
				if(A[i][k]+A[k][j]==A[i][j]) idx[i][j]=1;
			}
		}
	}
	
	if(!flag) {cout<<-1<<endl;return 0;}
	for(int i=1;i<=n;i++){
		for(int j=1;j<=n;j++){
			if(!idx[i][j]) ans+=A[i][j];
		}
	}
	
	cout<<ans/2<<endl;
	return 0;
}

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

int main(){
    string s, t;
    cin >> s >> t;
    sort(s.begin(), s.end());
    sort(t.begin(), t.end(), greater<char>());
    if (s < t) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
n = int(input())
max_num = -10**12
stores = {}

for i in range(n):
    stores[i] =[int('0b'+''.join(input().split()), 2)]
for i in range(n):
    stores[i].append(list(map(int, input().split())))
for i in range(1, 1024):
    total_sum = 0
    for j in range(n):
        common_open_time = bin(stores[j][0] & i).count('1')
        total_sum += stores[j][1][common_open_time]
    max_num = max(total_sum, max_num)
print(max_num)
    

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main(){
    ll a,b,Q;
    ll x[200000],y[200000],q[200000],xm[200000],ym[200000];
    cin>>a>>b>>Q;
    for(int i=1;i<a+1;i++){
        cin>>x[i];
    }
    x[0]=-99999999999;
  xm[0]=99999999999;
    x[a+1]=99999999999;
  xm[a+1]=999999999999;
    for(int i=1;i<b+1;i++){
        cin>>y[i];
    }
    y[0]=-99999999999;
  ym[0]=999999999999;
    y[b+1]=99999999999;
  ym[b+1]=999999999999;
    for(int i=0;i<Q;i++){
        cin>>q[i];
    }

    
    for(int i=1;i<a+1;i++){
        int k;
        k=lower_bound(y,y+b+2,x[i])-y;
        ll sin=min(abs(y[k]-x[i]),abs(y[k-1]-x[i]));
        xm[i]=sin;
      //cout<<xm[i]<<endl;
    }
    for(int i=1;i<b+1;i++){
        int k;
        k=lower_bound(x,x+a+2,y[i])-x;
        ll sin=min(abs(x[k]-y[i]),abs(x[k-1]-y[i]));
        ym[i]=sin;
      //cout<<ym[i]<<endl;
    }
    for(int i=0;i<Q;i++){
        ll a1,a2,a3,a4,s1,s2;
        s1=lower_bound(x,x+a+2,q[i])-x;
        s2=lower_bound(y,y+b+2,q[i])-y;
      //cout<<s1<<" "<<s2<<endl;
        a1=abs(q[i]-x[s1])+xm[s1];
        a2=abs(q[i]-x[s1-1])+xm[s1-1];
        a3=abs(q[i]-y[s2])+ym[s2];
        a4=abs(q[i]-y[s2-1])+ym[s2-1];
        printf("%10lld\n",min(min(a1,a2),min(a3,a4)));
    }

}


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

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


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

    vector<float> v(N);
    rep(i,N) cin >> v.at(i);
    sort(v.begin(),v.end());

    float x;

    rep(i,N-1){
        x = (v.at(i)+v.at(i+1))/2;
        v.at(i+1) = x;
    }

    cout << v.at(N-1) << endl;


}

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

#define _LL long long
#define rep(i, n) for(_LL i = 0; i < (_LL)(n); i++)

int modl(_LL a, _LL k)
{
    a %= k;
    if( a < 0 ) a += k * ( 1 - (a + 1) / k );
    return a;
}

int modadd(_LL a, _LL b, _LL k)
{
    return modl(a + b, k);
}

int modminus(_LL a, _LL b, _LL k)
{
    return modl(a - b, k);
}

int main()
{
    _LL n, k;
    cin >> n >> k;
    _LL* a = (_LL*) malloc(n * sizeof(_LL));
    rep(i, n) cin >> a[i];

    map<_LL, _LL> sub;
    _LL sum = 0;
    _LL ans = 0;
    _LL *dl = (_LL*) malloc(n * sizeof(_LL));
    rep(i, n)
    {
        sum = modadd(sum, a[i], k);
        if( i - k >= 0 )
        {
            int rem = i - k;
            sub[dl[rem]]--;
        }

        if(sum == i + 1) ans += 1;
        _LL d = modminus(sum, i + 1, k);
        ans += sub[d];
//        cout << i << ":" << d << " : " << ans << endl;
        sub[d]++;
        dl[i] = d;
    }
    cout << ans << endl;
}

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

using namespace std;

int main()
{  int c=0;
   double a;
   cin>>a;
   for (int i=1 ; i<=a ; i++)
   {
       if(i%2==1)
        c++;
   }
   cout<<fixed<<setprecision(10)<<c/a;
    return 0;
}


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

int main(){
    string S;
  cin >> S;
  if (S[0] != S[1] && S[1] != S[2] && S[0] != S[2]) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}


Measured memory_bytes: 256
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif

using namespace std;
typedef long long ll;
//typedef pair<int,int> Pint;
typedef pair<ll, ll> P;
//typedef pair<int, pair<int, int>> P;
//typedef tuple<int,int,int> T;
typedef vector<ll> vec;
typedef vector<vec> mat;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define revrep(i, n) for(ll i = n-1; i >= 0; i--)
ll max(ll a, ll b){return (a > b) ? a : b;}
ll min(ll a, ll b){return (a < b) ? a : b;}

ll INFL = 1000000000000000010;//10^18 = 2^60
int INF = 1000000000;//10^9
ll MOD  = 1000000007;
//vector<int> dy = {0,0,1,-1};
//vector<int> dx = {1,-1,0,0};


int main(void){
  int X, A;
  cin >> X >> A;
  if(X < A){
    cout << 0 << endl;
  }else{
    cout << 10 << endl;
  }
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void){
  int i,ans=0;
  char S[200001],T[200001];
  scanf("%s",S);
  scanf("%s",T);

  for(i=0;S[i]!='\0';i++){
    if(S[i] != T[i]) ans++;
  }
  
  printf("%d",ans);
  
  return 0;
}

Measured memory_bytes: 2088
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
int dp[10000];
int main() { 
  int n,k,A,ans;
  char c;
  bool t=true;
  string s;
  cin >>n;
  rep(i,9){rep(j,9)
  if((i+1)*(j+1)==n){cout<<"Yes"<<endl;t=false;break;}
  if(!t)break;}
  if(t)cout<<"No"<<endl;
  vector<int> a(n),val(n);
  
  //cout<<ans<<endl;
}

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

using namespace std;

int main(void){
int N,K;
int keta = 0;
int tmp = 0;
//int flag = 0;
//int N;
cin >> N;
cin >> K;
/*
vector<int> sosuu;
sosuu.push_back(2);
int result = 0;

for(int i = 0; i < N; i++){
  cin >> P.data[i];
}
for(int i = 0; i < N; i++){
  cin >> Q.data[i];
}*/
tmp = N;
tmp = tmp/K;
keta++;
while(tmp != 0){
  keta++;
  tmp = tmp/K;
}
cout << keta << endl;
return 0;
}


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

typedef long long ll;
typedef pair<ll,ll> pi;
typedef vector <ll> vi;
typedef vector <pi> vpi;
#define f first
#define s second
#define FOR(i,s,e) for(ll i=s;i<=ll(e);++i)
#define DEC(i,s,e) for(ll i=s;i>=ll(e);--i)
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define lbd(x, y) lower_bound(all(x), y)
#define ubd(x, y) upper_bound(all(x), y)
#define aFOR(i,x) for (auto i: x)
#define mem(x,i) memset(x,i,sizeof x)
#define fast ios_base::sync_with_stdio(false),cin.tie(0)

string S;
string str;

bool palin(int i,int j){
	if (i >= j) return 1;
	return (str[i] == str[j]) && palin(i + 1, j - 1);
}

int main(){
	fast;
	
	cin>>S;
	int N = S.size();
	str = 'a' + S;
	
	
	if (!palin(1,S.size())){
		cout<<"No";
		return 0;
	}
	
	if (!palin(1,(N-1)/2)){
		cout<<"No";
		return 0;
	}

	if (!palin((N+3) / 2, N)){
		cout<<"No";
		return 0;
	}
	cout<<"Yes";
	
}



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

public class Main {
	public static void main(String[] args) {
		final Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] arr = new int[n];
		int[] rev = new int[n+1];
		for(int i = 0; i < n; i++) {
			arr[i] = sc.nextInt();
			rev[arr[i]] = i;
		}
		long count = 0;

		TreeSet<Integer> sorted = new TreeSet<>();
		sorted.add(-1);
		sorted.add(n);

		for(int i = 1; i <= n; i++) {
			int l = sorted.lower(rev[i]);
			int r = sorted.higher(rev[i]);
			count += (long)i*(rev[i] - l)*(r - rev[i]);
			sorted.add(rev[i]);
		}
		System.out.println(count);
	}
}

Measured memory_bytes: 73392
N,M = map(int,input().split())

INF = 10**7
dist = [[INF for j in range(N)] for i in range(N)]
d = [[INF for j in range(N)] for i in range(N)]
prev = [[i for j in range(N)] for i in range(N)]
t = [[0 for j in range(N)] for i in range(N)]

# 初期化
for i in range(N):
    d[i][i] = 0
    dist[i][i] = 0

for _ in range(M):
    a,b,c = map(int,input().split())
    dist[a-1][b-1] = c
    dist[b-1][a-1] = c
    d[a-1][b-1] = c
    d[b-1][a-1] = c

#　d[a][b]:aとbの距離
def warshall_floyd(n):
    for k in range(n):
        for i in range(n):#始点
            for j in range(n):#終点
                d[i][j] = min(d[i][j],d[i][k]+d[k][j])

warshall_floyd(N)
ans = 0
for i in range(N):
    for j in range(N):
        if dist[i][j] != INF and d[i][j] != dist[i][j]:
            ans += 1
print(ans//2)


Measured memory_bytes: 3700
#include<bits/stdc++.h>
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main(){
    char s[5];
    for(int i=0;i < 4;i++)cin >> s[i];
    int bit=0;
    int ans;
    int tmp;
    for(bit=0;bit < (1<<4);bit++){
        tmp=s[0]-'0';
        for(int i=0;i < 3;i++){
            if(bit & 1<<i){
                tmp+=s[i+1]-'0';
            }
            else{
                tmp-=s[i+1]-'0';
            }
        }
        if(tmp==7){
            break;
        }
    }
    char op1,op2,op3;
    if(bit & 1)op1='+';
    else op1='-';
    if(bit & 2)op2='+';
    else op2='-';
    if(bit & 4)op3='+';
    else op3='-';

    cout << s[0] << op1 << s[1] << op2 << s[2] << op3 << s[3] << "=7" << endl;
}

Measured memory_bytes: 256
def isCLKWISE(ph) : return not ((ph[-1][0] - ph[-3][0])*(- ph[-3][1] + ph[-2][1]) - (ph[-2][0] - ph[-3][0])*(- ph[-3][1] + ph[-1][1] ) < 0)
      
def ConvexHullScan(P):
    P = sorted(P)
    phU = []
    phU.append(P[0])
    phU.append(P[1])
    for p in P[2:]:
        phU.append(p)
        if isCLKWISE(phU) : continue
        while(True):
            del phU[-2]
            try:
                if isCLKWISE(phU) : break
            except IndexError : break
    phL = []
    phL.append(P[-1])
    phL.append(P[-2])
    for p in P[-3::-1]:
        phL.append(p)
        if isCLKWISE(phL) : continue
        while(True):
            del phL[-2]
            try:
                if isCLKWISE(phL) : break
            except IndexError : break
      
    ph = phU + phL[1:-1]
    return ph
  
n = range(int(input()))
P = [[int(x) for x in input().split()] for _ in n]
P = ConvexHullScan(P)
P.reverse()
print(len(P))
idx = min([[x[1][1],x[1][0],x[0]] for x in enumerate(P)])[2]
P = P[idx:] + P[:idx]
for p in P : print(p[0],p[1])

Measured memory_bytes: 33144
//codeforces
//
#include "bits/stdc++.h"
using namespace std;
 
int main()
{
  int a,b,c,d;
  cin>>a>>b>>c>>d;
  while(1){
    c -= b;
    if(a<1|| c<1)
      break;
    a -= d;
    if(a<1 || c<1)
      break;
  }
  
  
  if(a>0)
    cout<<"Yes";
  else
    cout<<"No";
	
	return 0;
}

Measured memory_bytes: 3636
package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
	"strconv"
)

const mod = 998244353
const facNum = 300001
const INF = 10000007

func main() {
	sc := newScanner(os.Stdin)
	K, N := sc.i(), sc.i()
	A := sc.is(N)
	a := make([]int, N)
	m := K - A[N-1] + A[0]
	index := N - 1
	a[N-1] = m
	for i := 0; i < N-1; i++ {
		a[i] = A[i+1] - A[i]
		if m < max(m, a[i]) {
			m = max(m, a[i])
			index = i
		}
	}
	sum := 0
	for i := 0; i < N; i++ {
		if i == index {
			continue
		}
		sum += a[i]
	}
	fmt.Println(sum)

}

// fmt.Println("Yes")
// fmt.Println("No")

// I/O
type scanner struct {
	sc *bufio.Scanner
}

func newScanner(input io.Reader) *scanner {
	sc := bufio.NewScanner(input)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024), int(1e+9))
	return &scanner{sc}
}

func (s *scanner) s() string {
	s.sc.Scan()
	return s.sc.Text()
}

func (s *scanner) i() int {
	i, e := strconv.Atoi(s.s())
	if e != nil {
		panic(e)
	}
	return i
}

func (s *scanner) f() float64 {
	f, e := strconv.ParseFloat(s.s(), 64)
	if e != nil {
		panic(e)
	}
	return f
}

func (s *scanner) bs() []byte {
	return []byte(s.s())
}

func (s *scanner) is(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = s.i()
	}
	return res
}

func (s *scanner) fs(n int) []float64 {
	res := make([]float64, n)
	for i := 0; i < n; i++ {
		res[i] = s.f()
	}
	return res
}

//------------------------------

//const factorial = new
func Pow(a, n int) int {
	ans := 1
	for n > 0 {
		if (n & 1) == 1 {
			ans = ans * a % mod
		}
		a = a * a % mod
		n = n >> 1
	}
	return ans
}

func Gcd(a, b int) int {
	if a < b {
		return Gcd(b, a)
	}
	for b != 0 {
		a, b = b, a%b
	}
	return a
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func combination(n, k int, fac, ifac []int) int {
	if n < k || n < 0 {
		return 0
	}
	if k == 0 {
		return 1
	}
	//while n != 0
	ans := ifac[k] * ifac[n-k] % mod
	return ans * fac[n] % mod
}

func abs(i int) int {
	if i < 0 {
		return -i
	}
	return i
}

// 階乗: factorial
// コンビネーションを計算する際に前もって計算しておく
// fac[k] => k! (mod M)
// ifac[k] => k!^(M-2) (mod M)
// n: ex. 2 * 10^5 => 200001
// fac, ifac := factorial()
func factorial() (fac []int, ifac []int) {
	fac = make([]int, facNum)
	fac[0] = 1
	ifac = make([]int, facNum)
	ifac[0] = 1
	for i := 1; i < facNum; i++ {
		fac[i] = fac[i-1] * i % mod
		ifac[i] = ifac[i-1] * Pow(i, mod-2) % mod
	}
	return
}

// vs: sorted slice int value
func lowerBound(vs []int, v int) (index int) {
	n := len(vs) / 2
	m := len(vs)
	for m != n {
		if vs[n] < v {
			n = (m-n+1)/2 + n
			//m = m
		} else {
			m = n
			n = n / 2
		}
	}
	return n
}

func IntSlice(n, init int) []int {
	r := make([]int, n)
	for i := range r {
		r[i] = init
	}
	return r
}


Measured memory_bytes: 6640
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		Scanner io = new Scanner(System.in);
		String s1 = io.next();
		String s2 = io.next();
		String s3 = io.next();
		
		System.out.print( s1.toUpperCase().charAt(0));

		System.out.print( s2.toUpperCase().charAt(0));

		System.out.println( s3.toUpperCase().charAt(0));
	}
}

Measured memory_bytes: 22996
#include<iostream>
using namespace std;
int w,h,i,j;
int map[51][51];

void rec(int i,int j){
  if(i<1 || i>h || j<1 || j>w){
    return;
  }
  
  if(map[i][j]==0)return;
  map[i][j]=0;
  rec(i+1,j);
  rec(i-1,j);
  rec(i,j-1);
  rec(i,j+1);
  rec(i-1,j-1);
  rec(i-1,j+1);
  rec(i+1,j-1);
  rec(i+1,j+1);
}
int main(){
  
  
  while(1){
    cin >> w >> h;
    if(w==0 && h==0)break;
    
    for(i=1;i<=h;i++){
      for(j=1;j<=w;j++){
	cin >> map[i][j];
	
      }
    }
    int count=0;
    for(int k=1;k<=h;k++){
      for(int l=1;l<=w;l++){
	if(map[k][l]==1){
	  count++;
	  rec(k,l);
	}
      }
    }
    cout << count << endl;
  }
  
  return 0;
}

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

#define rep(i, n) for(int i = 0; i < (n); ++i)
#define repr(i, n) for(int i = (n-1); i >= 0; --i)

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

const int MAX = 200005;
const int INF = 1001001001;
const int MOD = 1000000007;

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

    vector<int> A(N);
    rep(i, N) cin >> A[i];

    int ans = 0, l = 0;
    while (l < N - 1) {
        ans++;
        l += K - 1;
    }

    cout << ans << endl;
}

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

int main(){
	int a,b,c;
	int count = 0;
	cin >> a >> b >> c;
	for (int i = a; i <= b; i++){
		if (c%i == 0){
			count++;
		}
	}
	cout << count << endl;
	return 0;
}

Measured memory_bytes: 1164
#include<iostream>
#include<cstdio>
#include<iomanip>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<vector>
#include<map>
using namespace std;
string s[10005];
int main() 
{
	int n;
    cin>>n;
    long long ans=0;
    for (int i=1;i<=n;i++)
    {
        if (i%3==0)
        continue;
        else if (i%5==0)
        continue;
        else
        ans+=i;
    }
    cout<<ans<<endl;
    return 0;
}



Measured memory_bytes: 3940
def sieve(n):
    p = [True for i in range(n + 1)]
    p[0] = p[1] = False
    end = int(n ** .5)
    for i in range(2, end + 1):
        if p[i]:
            for j in range(i * i, n + 1, i):
                p[j] = False
 
    return p
 
def primes_below(n):
    if n < 2: return 0
    c = 1
    for i in range(3, n + 1, 2):
        if p[i]: c += 1
 
    return c
 
p = sieve(1000000)
while 1:
    try:
        n = int(input())
    except EOFError:
        break
    else:
        print(primes_below(n))

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

int32_t main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t,n,m,i,j,k,sum=0;
    cin>>n;
    cout<<3*n*n<<'\n';



    return 0;
}


Measured memory_bytes: 256