akhauriyash/Code-Regression huggingface dataset:
def readInts():
  return list(map(int, input().split()))

n, m = readInts()
a = readInts()
s = sum(a)
cnt = 0
for i in range(n):
  if a[i]*4*m >=s:
    cnt +=1
    
if cnt >= m:
  print("Yes")
else:
  print("No")
  


Measured memory_bytes: 3060
using System;
//using System.Collections.Generic;
//using System.Globalization;
//using System.IO.Compression;
//using System.IO.Pipes;
//using System.Linq;
//using System.Numerics;
//using System.Security.Cryptography.X509Certificates;
//using System.Text;
using static System.Console;
using static System.Math;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var HR = ReadInts();
            var H = HR[0];
            var R = HR[1];

            var a = H + R;

            if (a > 0)
            {
                WriteLine(1);
            }
            else if (a == 0)
            {
                WriteLine(0);
            }
            else
            {
                WriteLine(-1);
            }
        }

        private static string Read() { return ReadLine(); }
        private static string[] Reads() { return (Read().Split()); }
        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); }
    }
}



Measured memory_bytes: 17928
s = input()

def a(r,l):
    print("0 "*(r-1), end="")
    if (r+l)%2 == 0:
        print(int((r+l)/2), int((r+l)/2), end="")
    elif r%2 == 0:
        print(int((r+l-1)/2), int((r+l-1)/2+1), end="")
    else:
        print(int((r+l-1)/2+1), int((r+l-1)/2), end="")
    print(" 0"*(l-1), end="")

nr=0
nl=0
for i in s:
    if nl > 0 and i =='R':
        a(nr, nl)
        print(" ", end="")
        nr=0
        nl=0

    if i == 'R':
        nr+=1
    elif i == 'L':
        nl+=1

a(nr, nl)
print()

Measured memory_bytes: 5132
def main():
    x, n = map(int, input().split())
    p = set(map(int, input().split()))
    if not x in p:
        print(x)
    else:
        a = [abs(x-i) if not i in p else 1000 for i in range(-1, 102)]
        print(a.index(min(a))-1)

if __name__ == "__main__":
    main()

Measured memory_bytes: 9132
#include <iostream>
#include <algorithm>
#include <queue>
#include <vector>
#include <set>
#include <cmath>
#include <string>
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ROF(i,a,b) for(int i=b-1;i>=a;i--)
#define FI first
#define SE second
#define SI size()
#define MA(i,j) make_pair(i,j)
#define PA pair<int,int>
#define PF push_front
#define PB push_back
#define VE vector<int>
#define VP vector<PA>
#define LL long long
#define YES(i) cout<<(i?"YES":"NO")<<endl
#define Yes(i) cout<<(i?"Yes":"No")<<endl
using namespace std;
//
const int INF=1e9+7;
const int MOD=1e9+7;
//
int N,M;
int A[100000],B[100000];
int C[100001];
int main(){
  cin>>N>>M;
  FOR(i,0,M){
    cin>>A[i]>>B[i];
    C[A[i]]++;
    C[B[i]]++;
  }
  FOR(i,1,N+1){
    if(C[i]%2){
      YES(0);
      return 0;
    }
  }
  YES(1);
  return 0;
}


Measured memory_bytes: 1408
import java.util.Scanner;

class Main{
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		String s=sc.nextLine();
		String ans="";
		for(int i=0; i<s.length(); i++) {
			if(s.charAt(i)>='a' && s.charAt(i)<='z') {
				ans+=((char)(s.charAt(i)-32));
			}
			else if(s.charAt(i)>='A' && s.charAt(i)<='Z') {
				ans+=((char)(s.charAt(i)+32));
			}
			else {
				ans+=s.charAt(i);
			}
		}
		System.out.println(ans);
	}
}


Measured memory_bytes: 31288
#include <algorithm>
#include <climits>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <vector>

// #define int long long int
constexpr int INF = std::numeric_limits<int>::max();
constexpr int NINF = std::numeric_limits<int>::min();
using namespace std;

const vector<pair<int, int>> PPP = {{-1, 0}, {1, 0}, {0, -1}, {0, 1}};

int depth[60][60];

void solve() {
  int H, W;
  cin >> H >> W;

  int num_sharpe = 0;

  vector<string> S;
  S.emplace_back('#', W + 2);
  for (int i = 0; i < H; i++) {
    string s;
    cin >> s;
    num_sharpe += count(s.begin(), s.end(), '#');
    S.push_back("#" + s + "#");
  }
  S.emplace_back('#', W + 2);

  queue<pair<int, int>> q;
  q.emplace(1, 1);
  depth[1][1] = 1;

  bool fin = false;

  while (!q.empty() && !fin) {
    auto p = q.front();
    q.pop();
    int x = p.first;
    int y = p.second;

    for (pair<int, int> d : PPP) {
      int nx = d.first + x;
      int ny = d.second + y;
      if (S[nx][ny] == '.' && depth[nx][ny] == 0) {
        depth[nx][ny] = depth[x][y] + 1;
        q.emplace(nx, ny);
      }
      if (nx == H && ny == W) {
        fin = true;
        break;
      }
    }
  }

  if (depth[H][W] == 0) {
    cout << -1 << endl;
    return;
  }

  // for (int h = 1; h <= H; h++) {
  //   for (int w = 1; w <= W; w++) {
  //     cout << depth[h][w] << " ";
  //   }
  //   cout << endl;
  // }

  // cout << depth[H][W] << endl;
  // cout << num_sharpe << endl;

  cout << H * W - depth[H][W] - num_sharpe << endl;
}

signed main() {
  // cin.tie(0);
  // ios::sync_with_stdio(false);
  solve();
  return 0;
}


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

template<typename T, typename E> struct LazySegmentTree {
  using F = function<T(T, T)>;
  using G = function<T(T, E)>;
  using H = function<E(E, E)>;
  using P = function<E(E, int)>;

  int n;
  T ti;
  E ei;
  F f;
  G g;
  H h;
  P p;
  vector<T> data;
  vector<E> lazy;

  LazySegmentTree(int n_, F f, G g, H h, T ti = INT_MAX, E ei = INT_MAX,
                  vector<T> v = vector<T>(), P p = [](E a, int b) { return a; })
      : f(f), g(g), h(h), ti(ti), ei(ei), p(p) {
    init(n_);
    if (n_ == (int)v.size()) build(v);
  }
  void init(int n_) {
    n = 1;
    while (n < n_) n *= 2;
    data.assign(n * 2 - 1, ti);
    lazy.assign(n * 2 - 1, ei);
  }
  void build(vector<T> v) {
    for (int i = 0; i < v.size(); ++i) data[i + n - 1] = v[i];
    for (int i = n - 2; i >= 0; --i) {
      data[i] = f(data[i * 2 + 1], data[i * 2 + 2]);
    }
  }
  inline void eval(int len, int k) {
    if (lazy[k] == ei) return;
    if (k * 2 + 1 < n * 2 - 1) {
      lazy[k * 2 + 1] = h(lazy[k * 2 + 1], lazy[k]);
      lazy[k * 2 + 2] = h(lazy[k * 2 + 2], lazy[k]);
    }
    data[k] = g(data[k], p(lazy[k], len));
    lazy[k] = ei;
  }
  T update(int a, int b, E x, int k = 0, int l = 0, int r = -1) {
    if (r < 0) r = n;
    eval(r - l, k);
    if (b <= l || r <= a) return data[k];
    if (a <= l && r <= b) {
      lazy[k] = h(lazy[k], x);
      return g(data[k], p(lazy[k], r - l));
    }
    T vl = update(a, b, x, k * 2 + 1, l, (l + r) / 2);
    T vr = update(a, b, x, k * 2 + 2, (l + r) / 2, r);
    return data[k] = f(vl, vr);
  }
  T query(int a, int b, int k = 0, int l = 0, int r = -1) {
    if (r < 0) r = n;
    eval(r - l, k);
    if (b <= l || r <= a) return ti;
    if (a <= l && r <= b) return data[k];
    T vl = query(a, b, k * 2 + 1, l, (l + r) / 2);
    T vr = query(a, b, k * 2 + 2, (l + r) / 2, r);
    return f(vl, vr);
  }
};

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

  LazySegmentTree<ll, ll>::F f = [](ll a, ll b) { return min(a, b); };
  LazySegmentTree<ll, ll>::G g = plus<ll>();
  LazySegmentTree<ll, ll>::H h = plus<ll>();

  int n, q; cin >> n >> q;
  LazySegmentTree<ll, ll> seg(n, f, g, h, INT_MAX, 0, vector<ll>(n, 0));

  while (q--) {
    int com; cin >> com;
    if (com) {
      int s, t; cin >> s >> t;
      cout << seg.query(s, t + 1) << endl;
    } else {
      int s, t, x; cin >> s >> t >> x;
      seg.update(s, t + 1, x);
    }
  }
  return 0;
}



Measured memory_bytes: 8652
#include <bits/stdc++.h>
using namespace std;
signed main(){
    long long a , b , n , x;
    cin >> a >> b >> n;
    
    x = min(n , a/b * 7 + b-1);
    if(x%b == 0){
        x--;
    }
    
    cout << (a*x)/b - a*(x/b) << endl; 
    return(0);
}

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

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

    string ans;

    if (a == b) ans = "Draw";
    else {
        if (a == 1) ans = "Alice";
        else if (b == 1) ans = "Bob";
        else if (a < b) ans = "Bob";
        else ans = "Alice";
    }

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

Measured memory_bytes: 256
# coding: UTF-8

#import scipy.optimize
from math import ceil,floor
from heapq import heappush, heappop, heapify
    
##################################################################

if __name__ == "__main__":

    Input = [input() for i in range(2)]
    N,M = list(map(int,Input[0].split()))
    A = list(map(int,Input[1].split()))
    A = [-a for a in A]
    heapify(A)
    Use = 0
    while Use < M:
        temp = -1*heappop(A)
        temp = floor(temp/2)
        heappush(A, -temp)
        Use += 1
    print(sum(A)*-1)                            


Measured memory_bytes: 15228
#pragma warning(disable:4996)
#include <bits/stdc++.h>

using namespace std;

//macro
#define FOR(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) (a).begin(),(a).end()
#define EPS (1e-8)
#define equals(a,b)(fabs((a)-(b))<EPS)

using ll = long long;
using ull = unsigned long long;
using vb = vector<bool>;
using vi = vector<int>;
using vll = vector<ll>;
using vs = vector<string>;
using vvb = vector<vb>;
using vvi = vector<vi>;
using vvll = vector<vll>;
//func
template<typename A, typename T>void assign2d(A&arr, ll H, ll W, T t) { arr.resize(H); REP(i, H) arr[i].assign(W, t); }
template<class T> ostream &operator<<(ostream &os, const vector<T> &v) { int n = v.size(); REP(i, n)os << v[i] << (i == n - 1 ? "" : " "); return os; }
template <class T = int> inline T IN() { T x; cin >> x; return x; }
template<class T> inline void OUT(const T &x) { cout << x << "\n"; }
void YESNO(bool c) { OUT(c ? "YES" : "NO"); };
void YesNo(bool c) { OUT(c ? "Yes" : "No"); };
struct pre_ { pre_() { cin.tie(nullptr); ios::sync_with_stdio(false); /*cout << fixed << setprecision(6);*/ } } pre__;

int main() {
	int x[12] = { 1,3,1,2,1,2,1,1,2,1,2,1 };
	int X, Y;
	cin >> X >> Y;
	X--; Y--;
	YesNo(x[X] == x[Y]);
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string.h>
#include<string>
#include<cmath>
#include<cstdlib>
#include<vector>
#include<functional>

using namespace std;

int main() {
	int n;
	cin >> n;
	if (n < 1000)cout << "ABC" << endl;
	if (n >= 1000)cout << "ABD" << endl;
	return 0;
}

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

int main() {
  int n;
  cin >> n;
  
  using tsii = tuple<string, int, int>;
  vector<tsii> p(n);
  for (int i=0; i<n; i++) {
    string city;
    int point;
    cin >> city >> point;
    p[i] = make_tuple(city, -point, i+1);
  }
  
  sort(p.begin(), p.end());
  
  for (int i=0; i<n; i++) cout << get<2>(p[i]) << endl;
  
}


Measured memory_bytes: 3624
/*#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;*/
#include<algorithm>
#include <bits/stdc++.h>
#include<stdio.h>
#include<math.h>
#include<string.h>
#include<stdlib.h>
#include<stdbool.h>
#include<ctype.h>
using namespace std;
#define pb push_back
#define S second
#define F first
#define f(i,n) for(ll i=0;i<n;i++)
#define f1(i,n) for(ll i=1;i<=n;i++)
#define fb(i,n) for(ll i=n-1;i>=0;i--)
#define fb1(i,n) for(ll i=n;i>0;i--)
#define end cout<<'\n';
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define vi vector<ll>
#define pii pair<ll,ll>
#define CASES  ll t;cin>>t;while(t--)
typedef long long ll;
typedef unsigned long long ull;
//typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
//typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
//*X.find_by_order()
//X.order_of_key()
int main()
{
fast;
    ll x;
    ll ans;
    long double y;
    cin>>x>>y;
    ans=x*y;
    cout<<ans;
    
    return 0;
}

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

signed main() {
  int N, K, Q;
  cin >> N >> K >> Q;
  vector<int> p(N, K - Q);
  for (int i = 0; i < Q; i++) {
    int A;
    cin >> A;
    A--;
    p[A]++;
  }

  for (int i = 0; i < N; i++) {
    if (p[i] > 0) {
      cout << "Yes" << endl;
    } else {
      cout << "No" << endl;
    }
  }

  return 0;
}

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

using namespace std;
 
int main(void) {
  int n; cin>>n;
  int a;
  bool can = true;
  for(int i = 0; i < n; i++) {
    cin >> a;
    if(a%2==0 && a%3!=0 && a%5!=0) can = false;
  }
  cout << (can ? "APPROVED" : "DENIED") << endl;
  return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main {


    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int x = sc.nextInt();

        for (int i = 1; i <= x; i++) {
            if (i % 3 == 0) {
                System.out.print(" "+i);
            } else {
                int j = i;
                while (j!=0) {
                    if (j% 10 == 3) {
                        System.out.print(" "+i);
                        break;
                    } else {
                        j /= 10;
                    }
                }
            }
        }
        System.out.println("");
    }
}



Measured memory_bytes: 28736
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor
from operator import mul
from functools import reduce


sys.setrecursionlimit(2147483647)
INF = 10 ** 13
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().rstrip().split()
def S(): return sys.stdin.readline().rstrip()
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 998244353

n, k = LI()
A = LI()
ok = max(A)
ng = 0
while ok - ng > 1:
    cnt = 0
    mid = (ok + ng) // 2
    for a in A:
        if a % mid == 0:
            cnt += a // mid - 1
        else:
            cnt += a // mid
        if cnt > k:
            ng = mid
            break
    else:
        ok = mid

print(ok)




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

using namespace std;

typedef long long ll;

ll a[200005];
ll dp[200005][16];
ll dp2[200005][16];

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

  for(int i = 0; i <= 15; i++) {
    dp[n-1][i] = i;
    dp2[0][i] = i;
  }

  for(ll i = n - 2; i >= 0; i--) {
    for(ll j = 0; j <= 15; j++) {
      ll x = 1ll << (2 * j);
      ll k = 0;
      ll tmp = 1;
      while(a[i] * x > a[i+1] * tmp) {
	tmp *= 4;
	k++;
      }
      if(k <= 15) {
	dp[i][j] = dp[i+1][k] + j;
      }
      else {
	dp[i][j] = dp[i+1][15] + (n-i-1) * (k-15) + j;
      }
    }
  }


  for(ll i = 1; i < n; i++) {
    for(ll j = 0; j <= 15; j++) {
      ll x = 1ll << (2 * j);
      ll k = 0;
      ll tmp = 1;
      while(a[i-1] * tmp < a[i] * x) {
	tmp *= 4;
	k++;
      }
      if(k <= 15) {
	dp2[i][j] = dp2[i-1][k] + j;
      }
      else {
	dp2[i][j] = dp2[i-1][15] + i * (k-15) + j;
      }
    }
  }
  ll ans = dp[0][0] * 2;
  for(int i = 1; i < n; i++) {
    ans = min(ans,dp2[i-1][0] * 2 + i + dp[i][0] * 2);
  }
  cout << min(ans,dp2[n-1][0] * 2 + n) << endl;
}
  
  


Measured memory_bytes: 51840
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] sa = br.readLine().split(" ");
		int n = Integer.parseInt(sa[0]);
		int m = Integer.parseInt(sa[1]);
		int p = Integer.parseInt(sa[2]);
		Hen[] arr = new Hen[m];
		Map<Integer, List<Hen>> map = new HashMap<Integer, List<Hen>>();
		Map<Integer, List<Hen>> map2 = new HashMap<Integer, List<Hen>>();
		for (int i = 0; i < m; i++) {
			sa = br.readLine().split(" ");
			Hen h = new Hen();
			h.a = Integer.parseInt(sa[0]) - 1;
			h.b = Integer.parseInt(sa[1]) - 1;
			h.c = (Integer.parseInt(sa[2]) - p) * -1;
			arr[i] = h;

			List<Hen> list = map.get(h.a);
			if (list == null) {
				list = new ArrayList<Hen>();
				map.put(h.a, list);
			}
			list.add(h);
			list = map2.get(h.b);
			if (list == null) {
				list = new ArrayList<Hen>();
				map2.put(h.b, list);
			}
			list.add(h);
		}
		br.close();

		boolean[] flg1 = new boolean[n];
		ArrayDeque<Integer> que = new ArrayDeque<Integer>();
		que.add(0);
		flg1[0] = true;
		while (!que.isEmpty()) {
			Integer cur = que.poll();
			List<Hen> list = map.get(cur);
			if (list != null) {
				for (Hen h : list) {
					if (!flg1[h.b]) {
						que.add(h.b);
						flg1[h.b] = true;
					}
				}
			}
		}

		boolean[] flgN = new boolean[n];
		que = new ArrayDeque<Integer>();
		que.add(n - 1);
		flgN[n - 1] = true;
		while (!que.isEmpty()) {
			Integer cur = que.poll();
			List<Hen> list = map2.get(cur);
			if (list != null) {
				for (Hen h : list) {
					if (!flgN[h.a]) {
						que.add(h.a);
						flgN[h.a] = true;
					}
				}
			}
		}

		int[] d = new int[n];
		for (int i = 1; i < n; i++) {
			d[i] = 1000000000;
		}
		boolean upd = true;
		for (int i = 0; i <= n && upd; i++) {
			upd = false;
			for (int j = 0; j < m; j++) {
				Hen h = arr[j];
				if (!flg1[h.a] || !flgN[h.b]) {
					continue;
				}
				int alt = d[h.a] + h.c;
				if (d[h.b] > alt) {
					d[h.b] = alt;
					upd = true;
				}
			}
			if (i == n) {
				System.out.println(-1);
				return;
			}
		}
		System.out.println(Math.max(-d[n - 1], 0));
	}

	static class Hen {
		int a, b, c;
	}
}


Measured memory_bytes: 30016
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N, A[200];
  int even_count = 0;
  bool is_even = true;
  
  cin >> N;
  for ( int i = 0; i < N ; i++ ) {
    cin >> A[i];
  }
  
  for ( ; is_even; ) {
    for ( int j = 0; j < N ; j++ ) {
      if ( A[j] % 2 != 0 ) {
        is_even = false;
        break;
      }
      A[j] /= 2;
    }
    if( is_even == true ) {
      even_count++;
    }
  }
  cout << even_count << endl;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Globalization;
using static System.Console;
using Pair = System.Collections.Generic.KeyValuePair<int, int>;

class Program
{
    static void Main()
    {
        var sw = new StreamWriter(OpenStandardOutput()) { AutoFlush = false };
        SetOut(sw);
        new Program().solve();
        Out.Flush();
    }
    Scanner cin = new Scanner();
    readonly int[] dd = { 0, 1, 0, -1, 0 };
    readonly int mod = 1000000007;

    int ans = int.MaxValue;
    string S;
    void solve()
    {
        S = cin.next;

        int cnt = 0;
        for (int i = 1; i < S.Length; i++)
        {
            if (S[i] != S[i - 1])
            {
                cnt++;
            }
        }

        WriteLine(cnt);
    }
}
class Scanner
{
    string[] s; int i;
    char[] cs = new char[] { ' ' };
    public Scanner() { s = new string[0]; i = 0; }
    public string[] scan { get { return ReadLine().Split(); } }
    public int[] scanint { get { return Array.ConvertAll(scan, int.Parse); } }
    public long[] scanlong { get { return Array.ConvertAll(scan, long.Parse); } }
    public double[] scandouble { get { return Array.ConvertAll(scan, double.Parse); } }
    public string next
    {
        get
        {
            if (i < s.Length) return s[i++];
            string st = ReadLine();
            while (st == "") st = ReadLine();
            s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
            i = 0;
            return next;
        }
    }
    public int nextint { get { return int.Parse(next); } }
    public long nextlong { get { return long.Parse(next); } }
    public double nextdouble { get { return double.Parse(next); } }
}

Measured memory_bytes: 3416
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <array>
#include <vector>
#include <functional>
#include <unordered_map> 
#include <map> 
#include <numeric>
#include <limits>
#include <utility>
#include <queue>
#include <random>
#include <bitset>
using namespace std;
typedef long long LL;

int main(void) {
	unsigned long long n, m, ans;

	cin >> n >> m;

	if (n == 1 || m == 1) {
		ans = max(n, m) - 2;
	} else {

		ans = (n - 2)*(m - 2);
		//if (ans <= 0)ans = 0;
	}

	if (n == 1 && m == 1) {
		ans = 1;
	}

	cout << ans << endl;


	return 0;
}

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

// 各桁の値は10で割ったあまり

int add_digits(int n) {
  int sum = 0;
    
  while (n > 0) {
    sum += n % 10;
    n /= 10;
  }
  
  return sum;
}

int main() {
  int n, a, b;
  cin >> n >> a >> b;
  int total = 0, sum = 0;
  
  for (int i = 1; i <= n; i++) {
    sum = add_digits(i);
    if (sum >= a && sum <= b) total += i;
  }
  
  cout << total << endl;
}


Measured memory_bytes: 3596
#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 FORR(i, m, n) for (int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define ll long long
#define ull unsigned long long
#define pb(a) push_back(a)
#define INF 999999999
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

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

int main()
{
    int n;
    cin >> n;
    pair<pair<string, int>, int> p[n];
    REP(i, n){
        cin >> p[i].first.first >> p[i].first.second;
        p[i].first.second *= -1;
        p[i].second = i + 1;
    }
    sort(p, p+n);
    REP(i, n) cout << p[i].second << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int maxn=2e5+10;
int n;
int val[maxn],sor[maxn],tag[maxn];
bool check(int v)
{
    for(int i=1;i<=2*n-1;i++)tag[i]=val[i]>=v;
    int dis1=1<<30,col1=0;
    int dis2=1<<30,col2=0;
    for(int i=n;i>=2;i--)
    if(tag[i]==tag[i-1])
    {
        dis1=n-i,col1=tag[i];
        break;
    }
    for(int i=n;i<=2*n-2;i++)
    if(tag[i]==tag[i+1])
    {
        dis2=i-n,col2=tag[i];
        break;
    }
    if(dis1==dis2&&dis1==(1<<30))return ((n-1)&1)^tag[n];
    return dis1<dis2?col1:col2;
}
int main()
{
    scanf("%d",&n);
    for(int i=1;i<=2*n-1;i++)scanf("%d",&val[i]),sor[i]=val[i];
    sort(sor+1,sor+2*n);
    int l=1,r=2*n-1,ans=1;
    while(l<=r)
    {
        int mid=l+r>>1;
        if(check(sor[mid]))l=mid+1,ans=mid;
        else r=mid-1;
    }
    printf("%d\n",sor[ans]);
}

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

namespace { using std::cin, std::cout, std::endl, std::string, std::vector; }

int main()
{
	int N, M;
	cin >> N >> M;
	int count = N;
	vector<int> H(N);
	vector<bool> isHigher(N, true);
	for (auto& i : H)
		cin >> i;
	for (int i = 0; i < M; ++i)
	{
		int A, B;
		cin >> A >> B;
		if (H[A - 1] >= H[B - 1] && isHigher[B - 1])
		{
			isHigher[B - 1] = false;
			count--;
		}
		if (H[B - 1] >= H[A - 1] && isHigher[A - 1])
		{
			isHigher[A - 1] = false;
			count--;
		}		
	}

	cout << count << endl;
}

Measured memory_bytes: 3720
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <limits>
#include <map>
#include <regex>
#define REP(i,n) for(long (i)=0;(i)<(n);(i)++)
#define REPI(i,a,b) for(long (i)=(a);(i)<(b);(i)++)
#define INF numeric_limits<double>::infinity()
constexpr long MOD = 1e9 + 7;
using namespace std;
using P = pair<long, long>;
using VI = vector<long>;

int main() {
    int n;
    cin >> n;
    VI v(n);
    REP(i,n) {
        cin >> v[i];
        v[i]--;
    }
    
    int cnt = 0;
    REP(i,n) {
        if (v[v[i]] == i) cnt++;
    }
    
    cout << cnt / 2 << endl;
}


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

using namespace std;
typedef long long ll;

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

int keta(int n) {
  int ans = 0;
  while(n) {
    ans++;
    n /= 10;
  }
  return ans;
}

int main() {
  int N;
  cin >> N;
  int ans = 0;
  for (int i = 1; i <= N; i++) {
    if (keta(i) % 2 == 1) {
      ans++;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
n = gets.to_i
ary = []
n.times do 
  ary << gets.to_i
end
#こうしておけば最大値が複数あっても大丈夫
first = ary.max
second = ary.sort.reverse[1]
(0..n-1).each do |i|
  if ary[i] == first
    puts second
  else
    puts first
  end
end

Measured memory_bytes: 18920
#include <functional>
#include <algorithm>
#include <iostream>
#include <numeric>
#include <iomanip>
#include <utility>
#include <cstdlib>
#include <sstream>
#include <bitset>
#include <vector>
#include <cstdio>
#include <ctime>
#include <queue>
#include <deque>
#include <cmath>
#include <stack>
#include <list>
#include <map>
#include <set>

using namespace std;

typedef vector<int> vi;
typedef pair<int,int> pii;
typedef long long ll;

#define dump(x)  cerr << #x << " = " << (x) << endl
#define rep(i,n) for(int i=0;i<(n);i++)
#define ALL(a)  (a).begin(),(a).end()
#define pb push_back
#define sz size()

const double EPS = 1e-10;
const int INF = 100000000;


int main(){
    int n,m;
    while(cin>>n>>m){
        if(n==0 && m==0)break;
        
        int data[600][600]={};
        rep(i,600){
            rep(j,600){
                if(i==j){
                    data[i][j]=0;
                }
                else{
                    data[i][j]=INF;
                }
            }
        }
        
        rep(i,m){
            int a,b;
            cin>>a>>b;
            a--;b--;
            data[a][b]=1;
            data[b][a]=1;
        }
        
        rep(k,n){
            rep(i,n){
                rep(j,n){
                    data[i][j]=min(data[i][j],data[i][k]+data[k][j]);
                }
            }
        }
        int c=0;
        for(int i=1;i<n;i++){
            if(data[0][i]<=2)
                c++;
        }
        cout<<c<<endl;
    }
    return 0;
    
}

Measured memory_bytes: 2572
#include <bits/stdc++.h>
using namespace std;
 
int main()
{
  int H, W, bomb=0;
  cin >> H >> W;
  vector<vector<char>> find(H, vector<char>(W));
  for(int i=0;i<H;i++)
  {
    for(int j=0;j<W;j++)
    {
      cin >> find.at(i).at(j);
    }
  }

  for(int i=0;i<H;i++)
  {
     for(int j=0;j<W;j++)
     {
        if(find[i][j]!='#')
        {
           bomb=0;
           if(i>0&&j>0&&find[i-1][j-1]=='#')//左上
             bomb++;
           if(i>0&&find[i-1][j]=='#')//真上
             bomb++;
           if(i>0&&j+1<W&&find[i-1][j+1]=='#')//右上
             bomb++;
           if(j>0&&find[i][j-1]=='#')//真左
             bomb++;
           if(j+1<W&&find[i][j+1]=='#')//真右
             bomb++;
           if(i+1<H&&j>0&&find[i+1][j-1]=='#')//左下
             bomb++;
           if(i+1<H&&find[i+1][j]=='#')//真下
             bomb++;
           if(i+1<H&&j+1<W&&find[i+1][j+1]=='#')//右下
             bomb++;
           find[i][j]='0' + bomb;
        }
     }
  }

  for(int i=0;i<H;i++)
  {
    for(int j=0;j<W;j++)
    {
       cout << find.at(i).at(j);
      if(j==W-1)
        cout << endl;
    }
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
typedef double dd;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> ii;
typedef pair<ll, int> li;
typedef pair<int, ll> il;
typedef pair<ll , ll> lli;
typedef vector<ii> vii;
typedef vector<il> vil;
typedef vector<li> vli;
typedef vector<lli> vlli;
 
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define in insert
#define f0(b) for(int i=0;i<(b);i++)
#define f00(b) for(int j=0;j<(b);j++)
#define f1(b) for(int i=1;i<=(b);i++)
#define f11(b) for(int j=1;j<=(b);j++)
#define f2(a,b) for(int i=(a);i<=(b);i++)
#define f22(a,b) for(int j=(a);j<=(b);j++)
#define sf(a) scanf("%lld",&a)
#define sff(a,b) scanf("%lld %lld", &a , &b)
#define pf(a) printf("%lld\n",a)
#define pff(a,b) printf("%lld %lld\n", a , b)
#define PI 3.14159265359
#define bug printf("**!\n")
#define mem(a , b) memset(a, b ,sizeof(a))
#define front_zero(n) __builtin_clzll(n)
#define back_zero(n) __builtin_ctzll(n)
#define total_one(n) __builtin_popcountll(n)

const ll mod = (ll)1e9+7;
const ll maxn = (ll)2e5+5;
const int nnn = 1048590;
const int inf = numeric_limits<int>::max()-1;
//const ll INF = numeric_limits<ll>::max()-1;
const ll INF = 1e18;

ll dx[]={0,1,0,-1};
ll dy[]={1,0,-1,0};
ll dxx[]={0,1,0,-1,1,1,-1,-1};
ll dyy[]={1,0,-1,0,1,-1,1,-1};


void solve(){
	ll n , k;
	cin >> n >> k;
	cout << min(n%k, abs(k-(n%k))) ;
	return;
}


int main() {
   
    ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
    ll T;
    T=1;
   // cin >> T;
    //scanf("%lld",&T);
    ll CT = 0;
    //work();
    while(T--){
    	//cout << "Case " << ++CT <<": " ;
    	//printf("Case %lld: ",++CT);
		solve();
	}
    
    return 0;
}


Measured memory_bytes: 3548
#include<iostream>
#include<cstdio>
using namespace std;
int cnt[111111],n,mx,x;
int main()
{
	scanf("%d",&n);
	for (int i=1;i<=n;i++)
	{
		scanf("%d",&x);
		cnt[x]++;
	}
	for (int i=1;i<=100000;i++)
	{
		mx=max(mx,cnt[i-1]+cnt[i]+cnt[i+1]);
	}
	printf("%d\n",mx);
	return 0;
}

Measured memory_bytes: 640
using System;

namespace abc125_a
{
    class Program
    {
        static void Main(string[] args)
        {
            double q;
            int p;
            string[] array = Console.ReadLine().Split(' ');
            int a = int.Parse(array[0]);
            int b = int.Parse(array[1]);
            int t = int.Parse(array[2]);

            q = (t + 0.5) / a;
            p = (int)q;

            Console.WriteLine(p * b);
        }
    }
}


Measured memory_bytes: 11092
import bisect
import sys
import math
import itertools
sys.setrecursionlimit(10000)

INF = float('inf')

# input macro
def i():
    return int(raw_input())
def ii():
    return map(int,raw_input().split(" "))
def s():
    return raw_input()
def ss():
    return raw_input().split(" ")
def slist():
    return list(raw_input())
def join(s):
    return ''.join(s)

#memoize macro
def memoize(f):
    cache = {}
    def helper(*args):
        if args not in cache:
            cache[(args)] = f(*args)
        return cache[args]
    return helper

nh=zip([1,0,-1,0],[0,1,0,-1])
mod=1000000007

###########
k,t=ii()
a=ii()
cur=a.index(max(a))
a[cur]-=1
cnt=0
for j in range(k-1):
    tmp=[a[j] for j in range(t) if j!=cur and a[j]!=0]
    if len(tmp)!=0:
        cur=a.index(max(tmp))
        a[cur]-=1
    else:
        a[cur]-=1
        cnt+=1
print cnt


Measured memory_bytes: 3072
#include <stdio.h>
 
int main(){
    int j,s_length = 0;
    char s[101],p[101];
    scanf("%s",s);
    scanf("%s",p);
 
    for(int i = 0; s[i] != '\0';i++) s_length++;
 
    for(int left = 0;s[left] != '\0';left++){
        for(j = 0;p[j] != '\0' && p[j] == s[(left+j)%s_length];j++);
        if(p[j] == '\0'){
            printf("Yes\n");
            return 0;
        }
    }
    printf("No\n");
    return 0;
}


Measured memory_bytes: 2628
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
#include <stdlib.h>
#include <map>
#include <cmath>
#define MOD_P 1000000007
#define MOD_Q 998244353
#define PI 3.14159265358979
#define ll long long
using namespace std;

void func(int i, int& left, int& right)
{
	right = i % 10;
	while (i >= 10) {
		i /= 10;
	}
	left = i % 10;
}

int main()
{
	int n;
	cin >> n;
	int a = n % 10;

	string test[] = { "pon","pon","hon","bon","hon","hon","pon","hon","pon","hon" };

	cout << test[a];

	return 0;
}



Measured memory_bytes: 3632
/*
时间:2020-7-29
书籍：算法和数据结构
内容：散列法
页数：P94
*/
#include<iostream>
#include<string>
using namespace std;
const int M = 1046527;       //大于1000000的质数，用于散列函数
//int T[1000];
string H[M];                   //string型默认值为空字符串
//将字符串转化为数值并生成key
//long long getKey(string str)
//{
//	long long sum = 0, p = 1, i;
//	for (i = 0; i < str.size(); ++i)
//	{
//		sum += p * (T[str[i]]);
//		p *= 5;
//	}
//	return sum;
//}
int main()
{
	hash<string> h;
//	T['A'] = 1; T['C'] = 2; T['G'] = 3; T['T'] = 4;
	int n;
	string command, info;
	long long key;
	cin >> n;
	for (int i = 0; i < n; ++i)
	{
		cin >> command >> info;
		key = (h(info)) % M;                     //注意要取模M
		if (command[0] == 'i')
		{
			while (true)
			{
				if (H[key] == "")
				{
					H[key] = info;
					break;
				}
				else
				{
					key = (key + 1) % M;
				}
			}
		}
		else
		{
			while (true)
			{
				if (H[key] == info)
				{
					cout << "yes" << endl;
					break;
				}
				else if (H[key] == "")
				{
					cout << "no" << endl;
					break;
				}
				else
					key = (key + 1) % M;
			}
		}
	}
	return 0;
}


Measured memory_bytes: 42880
N,A,B,C,D=map(int,input().split())

if N%A==0:
    X=B*(N//A)
else:
    X=B*((N//A)+1)

if N%C==0:
    Y=D*(N//C)
else:
    Y=D*((N//C)+1)
    
if X>=Y:
    print(Y)
else:
    print(X)


Measured memory_bytes: 5596
N,Ma,Mb = map(int,input().split())

INF = float('inf')

dp = [[INF for b in range(401)] for a in range(401)]

dp[0][0] = 0

sa = 0
sb = 0

for i in range(1,N+1):
    ai,bi,ci = map(int,input().split())
    sa += ai
    sb += bi
    for a in range(sa+1,-1,-1):
        for b in range(sb+1,-1,-1):
            if a-ai >= 0 and b-bi >= 0:
                dp[a][b] = min(dp[a][b],dp[a-ai][b-bi]+ci)


ans = INF
for j in range(1,401):
    if Ma*j > 400 or Mb*j > 400:
        break
    ans = min(ans,dp[Ma*j][Mb*j])
print(ans if ans != INF else -1)



Measured memory_bytes: 4872
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] min = new int[128];
		Arrays.fill(min, 99999);
		for(int i=0;i<n;i++) {
			int[] count = new int[128];
			String s = sc.next();
			for(int j=0;j<s.length();j++) {
				count[s.charAt(j)]++;
			}
//			System.out.println(Arrays.toString(count));
			for(int j=0;j<128;j++) {
				min[j] = Math.min(min[j], count[j]);
			}
		}
		StringBuilder sb = new StringBuilder();
		for(int i=0;i<128;i++) {
			for(int j=0;j<min[i];j++) {
				sb.append((char) i);
			}
		}
		System.out.println(sb);
	}

}


Measured memory_bytes: 22228
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<math.h>
using namespace std;
typedef long long ll;
#define int long long
typedef vector<int> VI;
typedef pair<int, int> pii;
typedef priority_queue<int> PQ;
#define fore(i,a) for(auto &i:a)
#define REP(i,n) for(int i=0;i<n;i++)
#define eREP(i,n) for(int i=0;i<=n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define eFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define rSORT(c) sort((c).rbegin(),(c).rend())
#define LB(x,a) lower_bound((x).begin(),(x).end(),(a))
#define UB(x,a) upper_bound((x).begin(),(x).end(),(a))
#define INF 1000000000
#define LLINF 9223372036854775807
#define mod 1000000007
//vector<vector<int> > dp;
//vector<vector<vector<int> > > vvvi;
//dp=vector<vector<int> >(N, vector<int>(M,0));
//vector<pair<int,int> > v;
//v.push_back(make_pair(x,y));
//priority_queue<int,vector<int>, greater<int> > q2;



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

	int N;
	cin >> N;
	
	int cnt[4] = { 0 };
	REP(i, N) {
		int a;
		cin >> a;
		cnt[a]++;
	}
	double dp[310][310][310] = { 0 };

	eREP(k, N) {
		eREP(j, N - k) {
			eREP(i, N - k - j) {
				if ((i == 0 && j == 0 && k == 0) || i + j + k > N)continue;

				double tmp = N * 1.0 / (i + j + k), pi = i * 1.0 / (i + j + k);
				double pj = j * 1.0 / (i + j + k), pk = k * 1.0 / (i + j + k);

				if (i)dp[i][j][k] += pi * dp[i - 1][j][k];
				if (j)dp[i][j][k] += pj * dp[i + 1][j - 1][k];
				if (k)dp[i][j][k] += pk * dp[i][j + 1][k - 1];

				dp[i][j][k] += tmp;
			}
		}
	}



	printf("%.10f\n", dp[cnt[1]][cnt[2]][cnt[3]]);
	//cout << dp[cnt[1]][cnt[2]][cnt[3]] << endl;
	
	return 0;
}



Measured memory_bytes: 232960
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")

#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define pii pair<int, int>
#define pll pair<ll, ll>
#define st first
#define sc second
#define arr array
#define yes cout << "Yes" <<"\n"
#define no cout << "No" <<"\n"
#define lb lower_bound
#define ub upper_bound
#define fast ios_base::sync_with_stdio(false)
#define out cin.tie(nullptr)
#define task "A"
#define open(task)  if(fopen(task".inp", "r")){freopen(task".inp", "r", stdin); freopen(task".out", "w", stdout);}
#define open_to_check(task)  if(fopen(task".inp", "r")){freopen(task".inp", "r", stdin);}
#define int64 long long

const int maxn = 3e5 + 2;
const int maxN = 1e5 + 5;
const ll mod = 1e9 + 7;

using namespace std;

/// Count : 1

ll a[maxn];

vector<int>adj[maxn];
int dem = 0;
bool vs[maxn];

void dfs(int u)
{
    vs[u] = false;
    dem ++;
    for(auto j : adj[u]){
        if(vs[j]){
            dfs(j);
        }
    }
}

int main()
{
    //if(fopen(task".inp", "r")){
        //freopen(task".inp", "r", stdin);
        //freopen(task".out", "w", stdout);
    //}
    int n, m;
    cin >> n >> m;
    for(int i=1; i<=m; i++){
        int u, v;
        cin >> u >> v;
        adj[u].pb(v);
        adj[v].pb(u);
    }
    for(int i=1; i<=n; i++) vs[i] = true;


    int ans = 0;
    for(int i=1; i<=n; i++){
        if(vs[i]){
            dem = 0;
            dfs(i);
            ans = max(ans, dem);
        }
    }
    cout << ans;
}


Measured memory_bytes: 23244
#include <cstdio>
#include<string>
#include<stack>
#include<queue>
#include<stdio.h>
#include <iostream>
#include <algorithm>
#include <cmath>
#include<set>
#include<vector>

#define _CRT_SECURE_NO_WARNINGS

using namespace std;
struct Human
{
	int age;
	double weight;
	char name[256];
};

int findSumOfDigits(int n) {
	int sum = 0;
	while (n > 0) { // n が 0 になるまで
		sum += n % 10;
		n /= 10;
	}
	return sum;
}

int main()
{
	int l[10000];
	int n = 6;
	int v[3];

	string s; // s.size() to_string char string %s
	int a,b,c,d;
	int sum = 0;
	vector<string> lang;
	vector<int> data;


	//cin>>N;
	// for (int i = 0; i < N; ++i) cin >> A[i];
	//while(true){break; ++res;}
	//cout << res << endl;
	//sort(a, a+N, greater<int>()) 大きい順ソート
	//set<int>values; values.insert() values.size()
	//map<string,int>salary; salary["John"] = 1400;
	// string num = to_string(counter);

	int count=0;
	int kari = 0;
	int N, K;

	cin >>v[0]>>v[1]>>v[2];

	sort(v, v+3);

	cout << v[0] <<" "<< v[1] <<" "<< v[2] << endl;




	return 0;
}


Measured memory_bytes: 3092
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int64_t i=0; i<(int64_t)(n); i++)
#define all(v) v.begin(), v.end()
//b
int main(){

    int64_t a, v, b, w, t;
    cin >> a >> v >> b >> w >> t;

    int64_t sa=abs(a-b);
    sa-=(v-w)*t;
    if(sa<=0) cout << "YES" << endl;
    else cout << "NO" << endl;

}

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

typedef long long int ll;
typedef long double ld;
typedef pair<int, int> pi;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
#define all(x) (x).begin(), (x).end()
#define endl "\n"
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define ar array
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
const ll mod = 1e9 + 7;
const ll inf = 2e9 + 5;
double PI = 3.14159265358979323846;


void solve() {

    int n, W;
    cin >> n >> W;
    ll wt[n], val[n];
    for (int i = 0; i < n; i++) {
        cin >> wt[i] >> val[i];
    }

    vl dp(W + 1, 0);
    for (int i = 0; i < n; i++) {
        for (int j = W; j >= 0; j--) {
            if (j - wt[i] >= 0) {
                dp[j] = max(dp[j], dp[j - wt[i]] + val[i]);
            }
        }
    }

    ll ans = 0;
    for (int j = 0; j <= W; j++) {
        ans = max(dp[j], ans);
    }

    cout << ans << endl;

}

int32_t main()
{
    IOS
    // int T; cin >> T; while (T--)
    solve();
    return 0;
}


Measured memory_bytes: 3968
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
 
int main()
{
    int n;
    cin >> n;
 
    vector<int> vec(n);
    for (int i = 0; i < n; i++)
    {
        cin >> vec.at(i);
    }
 
    int a = vec.size();
    sort(vec.begin(), vec.end());
    vec.erase(unique(vec.begin(), vec.end()), vec.end());
    int b = vec.size();
 
    if (a == b)
    {
        cout << "YES" << endl;
    }
    else
    {
        cout << "NO" << endl;
    }
}

Measured memory_bytes: 1024
import java.util.*;

public class Main {
    public void main(Scanner sc) {
        int i = sc.nextInt();
        int o = sc.nextInt();
        int t = sc.nextInt();
        int j = sc.nextInt();
        int l = sc.nextInt();
        int s = sc.nextInt();
        int z = sc.nextInt();

        long ans1 = o;
        ans1 += (i / 2) * 2;
        ans1 += (j / 2) * 2;
        ans1 += (l / 2) * 2;
        ans1 += 3 * ((i % 2) * (j % 2) * (l % 2));

        long ans2 = o;
        if (i >= 1 && j >= 1 && l >= 1) {
            ans2 += 3;
            i--;
            j--;
            l--;
        }
        ans2 += (i / 2) * 2;
        ans2 += (j / 2) * 2;
        ans2 += (l / 2) * 2;

        System.out.println(Math.max(ans1, ans2));
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        new Main().main(sc);
        sc.close();
    }
}


Measured memory_bytes: 23380
#include <iostream>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <vector>
#include <stack>
#include <string>

using namespace std;

typedef long long LL;

LL a[300010], ss[300010];

int main() {
    int n;
    cin >> n;
    LL s= 0;
    for (int i = 1; i <= n; ++i) {
        cin >> a[i];
        s+=a[i];
        ss[i]=ss[i-1]+a[i];
    }
    LL ans = 0x3f3f3f3f3f3f3f3fll;
     for (int i = 1; i <= n; ++i) {
        ans = min(ans, abs(s-ss[i]-ss[i]));
    }
    cout<<ans<< endl;
}

Measured memory_bytes: 3840
#include<stdio.h>
#include<math.h>
int main (void)
{
    int i=0 ;
    double n=0 ,cmp=0 ;
    double s[1001] = {0} ;
    double a2=0 ;
    double m=0 ;
    while(1)
    {
        a2=0 ;
        cmp=0 ;
        m=0 ;
        scanf("%lf" ,&n) ;
        if (n == 0) 
        break ;
        for (i=0 ;i < n ;i++)
        {
            scanf("%lf" ,&s[i]) ;
            cmp = cmp + s[i] ;
        }
        m = cmp / n ;
        for (i=0 ;i < n ;i++)
        {
            a2 = a2 + pow((s[i] - m) ,2) / n ;
        }
        printf("%f\n" ,sqrt(a2)) ;
    }
    return 0 ;
}


Measured memory_bytes: 2112
#include <stdio.h>

#define MAXN    504

int h, w, a[MAXN][MAXN];
int route[MAXN * MAXN][2];
int ans[MAXN * MAXN];

int main()
{
    int i, j;
    scanf("%d%d", &h, &w);

    for (i = 0; i < h; ++i)
        for (j = 0; j < w; ++j)
            scanf("%d", &a[i][j]);

    int route_len = 0;
    for (i = 0; i < h; ++i) {
        int start, end, inc;
        if (i % 2 == 0) {
            start = 0; end = w; inc = +1;
        } else {
            start = w - 1; end = -1; inc = -1;
        }
        for (j = start; j != end; j += inc) {
            route[route_len][0] = i;
            route[route_len++][1] = j;
        }
    }

    int last_odd = -1, ans_len = 0;
    for (i = 0; i < route_len; ++i)
        if (a[route[i][0]][route[i][1]] % 2 == 1) {
            if (last_odd == -1) {
                last_odd = i;
            } else {
                for (j = last_odd; j < i; ++j)
                    ans[ans_len++] = j;
                last_odd = -1;
            }
        }

    printf("%d\n", ans_len);
    for (i = 0; i < ans_len; ++i)
        printf("%d %d %d %d\n",
            route[ans[i]][0] + 1, route[ans[i]][1] + 1,
            route[ans[i] + 1][0] + 1, route[ans[i] + 1][1] + 1);

    return 0;
}


Measured memory_bytes: 5504
#include <iostream>
#include <fstream>
#include <vector>
#include <cstring>
#include <string>
#include <cmath>
#include <algorithm> // sort
#include <iomanip>
#include <queue>
#include <map>
#include <bits/stdc++.h>

using namespace std;

#define DEBUG 0
#define REP(i, n) for (long long i = 0; i < (n); i++) 
typedef long long ll;
static const ll INF = 1000000000000000000LL;
typedef pair<int,int> pint;

const int MAX = 1000000007;
const int MOD = 1000000007;

int main(){

#if DEBUG
    std::ifstream in("input.txt");
    std::cin.rdbuf(in.rdbuf());
#endif
    string s;
    cin >> s;
    int iMax = 0;

    vector <int> xcnt;
    vector <char> moji;

    int cnt = 0;

    REP(i,s.size())
    {
        if(s[i] == 'x')++cnt;
        else
        {
            moji.push_back(s[i]);
            xcnt.push_back(cnt);
            cnt = 0;
        }
    }
    xcnt.push_back(cnt);

    //回分判定
    for(int i = 0; i < (moji.size()+1)/2; ++i)
    {
        if(moji[i] != moji[moji.size()-1 - i])
        {
            cout << -1 << endl;
            return 0;
        }
    }

    int res = 0;
    for(int i = 0; i < (xcnt.size()+1)/2; ++i)
    {
        res += abs(xcnt[i] - xcnt[xcnt.size()-1-i]);
    }

    cout << res <<  endl;
    return 0;
}

Measured memory_bytes: 1148
#include<map>
#include<set>
#include<queue>
#include<cmath>
#include<cstdio>
#include<vector>
#include<string>
#include<cstring>
#include<iostream>
#include<algorithm>
#define lc (x<<1)
#define rc (x<<1|1)
#define gc getchar()//(p1==p2&&(p2=(p1=buf)+fread(buf,1,size,stdin),p1==p2)?EOF:*p1++)
#define mk make_pair
#define pi pair<int,int>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int N=2e5+10,size=1<<20;

//char buf[size],*p1=buf,*p2=buf;
template<class o> void qr(o &x) {
	char c=gc; x=0; int f=1;
	while(!isdigit(c)){if(c=='-')f=-1; c=gc;}
	while(isdigit(c)) x=x*10+c-'0',c=gc;
	x*=f;
}
template<class o> void qw(o x) {
	if(x/10) qw(x/10);
	putchar(x%10+'0');
}
template<class o> void pr1(o x) {
	if(x<0)x=-x,putchar('-');
	qw(x); putchar(' ');
}
template<class o> void pr2(o x) {
	if(x<0)x=-x,putchar('-');
	qw(x); puts("");
}

char s[N];
int n,now;
int f[2022],g[2022];
ll ans;

int main() {
	scanf("%s",s+1); n=strlen(s+1); f[0]++;
	for(register int i=1;i<=n;i++) {
		now=(now*10+s[i]-'0')%2019;
		ans+=f[now]++;
		memset(g,0,sizeof g);
		for(register int j=0;j<2019;j++)
			g[j*10%2019]+=f[j];
		for(register int j=0;j<2019;j++) f[j]=g[j];
	} 
	pr2(ans);
	return 0;
}



Measured memory_bytes: 3840
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#ifdef tabr
#include "library/debug.cpp"
#else
#define debug(...) 0
#endif

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

    int h, w, n;
    cin >> h >> w >> n;
    vector<vector<int>> z(w + 2);
    rep(i, 0, n) {
        int x, y;
        cin >> x >> y;
        if (x >= y)
            z[y].emplace_back(x);
    }
    rep(i, 1, w + 1) sort(z[i].begin(), z[i].end());
    int ans = h;
    int x = 1, y = 1;
    for (; x <= h; x++) {
        //debug(x, y);
        int p = h + 1;
        if (z[y].size() != 0) {
            auto it = lower_bound(z[y].begin(), z[y].end(), x + 1);
            if (it != z[y].end()) p = *it;
        }
        if (p == x + 1) {
            ans = min(ans, x);
        } else if (z[y + 1].size() == 0 || upper_bound(z[y + 1].begin(), z[y + 1].end(), x + 1) - lower_bound(z[y + 1].begin(), z[y + 1].end(), x + 1) == 0) {
            if (y != w) y++;
        }
        ans = min(p - 1, ans);
        if (y == w || x >= ans) break;
    }

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

Measured memory_bytes: 7424