akhauriyash/Code-Regression huggingface dataset:
N,W = map(int,input().split())
val = []
wei = []
for i in range(N):
    a,b = map(int,input().split())
    val.append(a)
    wei.append(b)

dp = [[0 for j in range(W+1)] for i in range(N+1)]

#DP計算
for i in range(N):
    for w in range(W+1):
        if(w >= wei[i]):
            dp[i+1][w] = max(dp[i][w - wei[i]] + val[i],dp[i][w])
        else:
            dp[i+1][w] = dp[i][w]

print(int(dp[N][W]))


Measured memory_bytes: 42268
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x, n) for(int i = x; i <= n; i++)
#define rep3(i, x, n) for(int i = x; i >= n; i--)
#define elif else if
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pdd;
const ll MOD = 1e9+7;
const ll MOD2 = 998244353;
const ll INF = LLONG_MAX;
const string alpha = "abcdefghijklmnopqrstuvwxyz";

int main(){
    bool a[10];
    fill_n(a, 10, false);
    int N[4];
    rep(i, 4){
        cin >> N[i];
        a[N[i]] = true;
    }
    if(a[1] && a[9] && a[7] && a[4]) cout << "YES" << endl;
    else cout << "NO" << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n ; i++)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define whole(f, x, ...) ([&](decltype((x)) whole) { return (f)(begin(whole), end(whole), ## __VA_ARGS__); })(x) // decltypeで型取得、引数があればva_argsのところに入れる
using namespace std;
typedef long long ll; // long longをllでかけるようにした
const long long INF = 1LL<<60;

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

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

const int MAX_N = 110;
const int MAX_V = 100100;

// 入力
int N;
long long W, weight[MAX_N], value[MAX_N]; // 品物の個数は 100 個なので少し余裕持たせてサイズ 110 に

// DPテーブル
long long dp[MAX_N][MAX_V];


int main(void){
    cin >> N >> W;
    REP(i, N) cin >> weight[i] >> value[i];

    REP(i, MAX_N) REP(j, MAX_V) dp[i][j] = INF;

    dp[0][0] = 0;

    REP(i, N){
        REP(sum_v, MAX_V){
            // この時のdpの中身は重さを表してる
            if(sum_v - value[i] >= 0) chmin(dp[i + 1][sum_v], dp[i][sum_v - value[i]] + weight[i]);

            chmin(dp[i + 1][sum_v], dp[i][sum_v]);

        } 
    }

    ll res = 0;
    REP(sum_v, MAX_V){
        if(dp[N][sum_v] <= W) res = sum_v;
    }
    cout << res << endl;
}

Measured memory_bytes: 86272
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<math.h>
#include<vector>
using namespace std;
#include <string>

int main()
{
	int n;

	cin >> n;

	int ac = 0,wa = 0,tle = 0,re = 0;

	//��������
	vector<string> list(n);
	for (int i = 0; i < n; i++) cin >> list[i];
	
	for (int i = 0; i < n; i++)
	{
		if ("AC" == list[i])
			ac++;
		if ("WA" == list[i])
			wa++;
		if ("TLE" == list[i])
			tle++;
		if ("RE" == list[i])
			re++;
	}

	cout << "AC x " << ac << endl;
	cout << "WA x " << wa << endl;
	cout << "TLE x " << tle << endl;
	cout << "RE x " << re << endl;


	return 0;
}

Measured memory_bytes: 6360
import collections
n, k = map(int, input().split())
list_a = list(map(int, input().split()))

count = collections.Counter(list_a)
sort_c = sorted(count.items(), key=lambda x:x[1])
num_kind = len(sort_c)

result = 0
for i in range(num_kind - k):
  result += sort_c[i][1]
print(result)


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

int main(){
  int a,b,d,r;
  double f;
  cin >> a >> b;
    
  d = a / b;
  r = a % b;
  f = 1.00000 * a / b;
  
  std::cout << std::fixed;
  std::cout << d << " " << r << " " << std::setprecision(5) << f << endl;
  
  return 0;
}


Measured memory_bytes: 3260
#include <iostream>
#include <vector>
#include <algorithm>
#include <iterator>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <string>
#include <cmath>
#include<cstdio>

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define ALL(obj) (obj).begin(), (obj).end()
// #define ALLR(obj) (obj).rbegin(), (obj).rend()
#define BIT(n) (1LL << (n))

using namespace std;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  int a;
  int b;
  
  cin >> a;
  cin >> b;
    
  REP(i, 30) {
    int c = a*i - (i-1);
    if (c >= b) {
      cout << i;
      break;
    }
  }
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAX 150
#define L 1000

int LCSLength(char *X, char *Y){
  int m = strlen(X), n = strlen(Y);
  int i,j;
  int c[m+1][n+1];

  for(i=1; i<=m; i++) c[i][0] = 0;
  for(j=0; j<=n; j++) c[0][j] = 0;

  for(i=1; i<m+1; i++){
    for(j=1; j<n+1; j++){
      if(X[i-1] == Y[j-1]){
	c[i][j] = c[i-1][j-1] + 1;
      }
      else if(c[i-1][j] >= c[i][j-1]){
	c[i][j] = c[i-1][j];
      }
      else {
	c[i][j] = c[i][j-1];
      }
    }
  }

  return c[i-1][j-1];
}

int main(void){
  int q,i,j;
  int LCS[MAX];
  char X[MAX][L], Y[MAX][L];

  // input & calculate
  scanf("%d",&q);
  for(i=0; i<q; i++){
    scanf("%s", &X[i]);
    scanf("%s", &Y[i]);
    LCS[i] = LCSLength(X[i],Y[i]);
  }

  // output
  for(i=0; i<q; i++) printf("%d\n", LCS[i]);

  return 0;
}

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

using namespace std;

#define mp make_pair
#define pb push_back
#define st first
#define nd second

typedef long long ll;
typedef vector<ll> vl;
typedef pair<int, int> ii;
typedef pair<ll,ll> pll;

int main() {
  int a, b, t;
  cin >> a >> b >> t;
  cout << (t / a) * b << endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
	public static void main(String args[]){
		run();
	}
	static void run(){
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		int ans = isDivisor(a, b, c);
		System.out.println(ans);
	}
	static int isDivisor(int a, int b, int c){
		int ans = 0;
		for(int i = a; i <= b; i++){
			if(c % i == 0){
				ans++;
			}
		}
		return ans;
	}
}

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

int main() {
  string N;
  cin >> N;
  int flag = 0;
  rep(i,3){
    if(N.at(i)=='7') flag = 1; 
  }
  if(flag) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}

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

#define all(a) a.begin(), a.end()
#define allr(a) a.rbegin(), a.rend()
#define rev(v) reverse(v.begin(), v.end());
#define io() ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); srand(time(NULL));
 
using namespace std;

using ll = long long;
using ld = long double;
using ull = unsigned long long;

signed main(){
    io();
    int n; cin >> n;
    int aux = 1;
    bool ok = 0;
    for(int i = 0; i < n; ++i){
        int x; cin >> x;
        if(x == aux){
            ++aux;
            ok = 1;
        }
    }
    cout << (ok ? n - aux + 1 : -1) << '\n';
    return 0;
}

Measured memory_bytes: 3644
import java.math.BigInteger;
import java.util.*;
public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		long a=sc.nextLong();
		long b=sc.nextLong();
		long k=sc.nextLong();
		long ca=0;
		long cb=0;
		if(k<a) {
			ca=a-k;
			cb=b;
		}
		else {
			k=k-a;
			if(k<b) {
				cb=b-k;
				
			}
			else {
				ca=0;
				cb=0;
			}
		}
		System.out.println(ca+" "+cb);
	}
}

Measured memory_bytes: 23892
import java.io.IOException;
import java.io.InputStream;
import java.util.Arrays;
import java.util.NoSuchElementException;

class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;

    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        } else {
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }

    private int readByte() {
        if (hasNextByte())
            return buffer[ptr++];
        else
            return -1;
    }

    private static boolean isPrintableChar(int c) {
        return 33 <= c && c <= 126;
    }

    public boolean hasNext() {
        while (hasNextByte() && !isPrintableChar(buffer[ptr]))
            ptr++;
        return hasNextByte();
    }

    public String next() {
        if (!hasNext())
            throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while (isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }

    public long nextLong() {
        if (!hasNext())
            throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while (true) {
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            } else if (b == -1 || !isPrintableChar(b)) {
                return minus ? -n : n;
            } else {
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }

    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)
            throw new NumberFormatException();
        return (int) nl;
    }

    public double nextDouble() {
        return Double.parseDouble(next());
    }
}

public class Main {
    static int[] w = new int[100010];
    static int[] v = new int[100010];
    static int[][] dp = new int[110][100010];
    static int k;

    static int chmin(int a, int b) {
        if (a > b) {
            a = b;
            return a;
        }
        return a;
    }

    static int chmax(int a, int b) {
        if (a < b) {
            a = b;
            return a;
        }
        return a;
    }

    public static void main(String[] args) {
        FastScanner fs = new FastScanner();
        int n = fs.nextInt();
        double m = Math.sqrt(n);
        int ans = 0;
        for (int i = 1; i <= m; i++) {
            ans++;
        }

        System.out.println(ans * ans);
    }

}


Measured memory_bytes: 81364
"""
# 標準入力取得
## 文字列
     = sys.stdin.readline().rstrip()
     = list(sys.stdin.readline().rstrip())

## 数値
     = int(sys.stdin.readline())
     = map(int, sys.stdin.readline().split())
     = list(map(int, sys.stdin.readline().split()))
     = [list(map(int,list(sys.stdin.readline().split()))) for i in range(h)]  # 二次元配列入力　二次元マップみたいな入力のとき

# 0埋め, 小数点出力桁指定時のときの出力
a = 100
b = 0.987654321
print("{0:06d}-{1:6f}".format(a,b))
000100-0.987654

# 文字列をリストに格納
char_list = list("abcd") # ["a","b","c","d"]
"""

import math
import sys
import itertools
import queue
from fractions import gcd

def lcm(a, b):
    return a * b // gcd(a, b)

mod = 1000000007

if __name__ == "__main__":
     N, A, B = map(int, sys.stdin.readline().split())
     print(min(N * A, B))


Measured memory_bytes: 5328
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <class T, class U> using Pa = pair<T, U>;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    double R;
    cin >> R;
    cout << fixed << setprecision(10) << R*6.2831853071795 << "\n";
}

Measured memory_bytes: 3800
import Data.List

solve :: [[Int]] -> Bool
solve dat
  | length dat == 1 = let [xs] = dat in length xs >= 2 * head xs || length xs == head xs + 1
  | length dat == 2 =
      let
        [xs,ys] = dat
        k = head ys
      in
        head xs + 1 == head ys && k - length xs > 0 && 2 * (k - length xs) <= length ys
  | otherwise = False

main :: IO ()
main = do
  n <- readLn :: IO Int
  as <- group . sort . map read . words <$> getLine :: IO [[Int]]
  
  putStrLn $ if solve as then "Yes" else "No"
  


Measured memory_bytes: 31100
fn main() {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();

    let mut ans = 0;
//    for c in s.into_bytes(){
//        if c=='+' as u8{ ans+=1 }
//        else if c=='-' as u8{
//            ans-=1
//        }
//    }
//

    for c in s.trim().chars(){
        if c== '+'{ ans +=1}
        else { ans -=1 }
    }
    println!("{}", ans);
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repe(i, n) for (int i = 0; i <= (n); ++i)
#define all(x) (x).begin(),(x).end()
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
typedef long long ll;
const int INF = 1e9;
const ll mod = 1000000007;
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a*b / gcd(a,b);}

int main() {
    int a,b;
    cin >> a >> b;
    vector<int> vc = {2,3,4,5,6,7,8,9,10,11,12,13,1};
    vector<int>::iterator itr_a = find(vc.begin(), vc.end(), a);
    vector<int>::iterator itr_b = find(vc.begin(), vc.end(), b);
    int index_a = distance(vc.begin(), itr_a);
    int index_b = distance(vc.begin(), itr_b);
    if (index_a > index_b) {
        cout << "Alice" << "\n";
    }
    if (index_b > index_a) {
        cout << "Bob" << "\n";
    }
    if (index_a == index_b) {
        cout << "Draw" << "\n";
    }
}


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

#define int long long
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define rep1(i,n) for(int i=1;i<=(int)(n);++i)
#define rep11(i,n) for(int i=1;i<(int)(n);++i)
#define repo(i,o,n) for(int i=o;i<(int)(n);++i)
#define repm(i,n) for(int i=(int)(n)-1;i>=0;--i)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define pb(n) push_back(n)
#define mp make_pair
#define MOD 1000000007
#define INF LONG_LONG_MAX

const int MAX = 110000;

int fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
int COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int n,k,a,ans;
vector<int> v;

signed main() {
    COMinit();
    cin >> n >> k;
    rep(i,n) cin >> a, v.pb(a);
    sort(all(v));
    rep(i,n-k+1) {
        int tmp = (COM(n-i-1,k-1)*v[i])%MOD;
        ans = (ans-tmp+MOD)%MOD;
    }
    reverse(all(v));
    rep(i,n-k+1) {
        int tmp = (COM(n-i-1,k-1)*v[i])%MOD;
        ans = (ans+tmp)%MOD;
    }
    cout << (ans+MOD)%MOD << endl;
}



Measured memory_bytes: 4088
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define REP(i, start, end) for (ll i = start, i##Len = (end); i < i##Len; ++i)
#define REPR(i, start, end) for (ll i = start, i##Len = (end); i > i##Len; --i)
using ll = long long;
using namespace std;

int main()
{
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);

    ll n;
    cin >> n;
    const ll mod = 1e9 + 7;
    ll x = 1, y = 1, z = 1;
    REP(i, 0, n)
    {
        x = x * 10 % mod;
        y = y * 9 % mod;
        z = z * 8 % mod;
    }
    cout << ((x - y * 2 + z) % mod + mod) % mod << endl;
}

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

using namespace std;
using ll = long long;
using vec = vector<ll>;
using mat = vector<vec>;
using pll = pair<ll,ll>;

#define INF (1LL << 60)
#define MOD 1000000007
#define PI 3.14159265358979323846

#define REP(i,m,n) for(ll (i)=(m),(i_len)=(n);(i)<(i_len);++(i))
#define FORR(i,v) for(auto (i):v)
#define ALL(x) (x).begin(), (x).end()
#define PR(x) cout << (x) << endl
#define PS(x) cout << (x) << " "
#define SZ(x) ((ll)(x).size())
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))
#define REV(x) reverse(ALL((x)))
#define ASC(x) sort(ALL((x)))
#define DESC(x) ASC((x)); REV((x))
#define pb push_back
#define eb emplace_back

int main()
{
    ll N;
    string S;
    cin >> N >> S;

    ll cnt = 0;
    REP(i,0,10) {
        REP(j,0,10) {
            REP(k,0,10) {
                ll p = 0;
                while(p < N && S[p] - '0' != i) ++p;
                ++p;
                while(p < N && S[p] - '0' != j) ++p;
                ++p;
                while(p < N && S[p] - '0' != k) ++p;
                if(p < N) ++cnt;
            }
        }
    }


    PR(cnt);


    return 0;
}

/*



*/

Measured memory_bytes: 3664
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <numeric>
#include <utility>
#include <tuple>

#define REP(i, a, b) for (int i = int(a); i < int(b); i++)
using namespace std;
using ll = long long int;
using P = pair<int, int>;

// clang-format off
#ifdef _DEBUG_
#define dump(...) do{ cerr << __LINE__ << ":\t" << #__VA_ARGS__ << " = "; PPPPP(__VA_ARGS__); cerr << endl; } while(false)
template<typename T> void PPPPP(T t) { cerr << t; }
template<typename T, typename... S> void PPPPP(T t, S... s) { cerr << t << ", "; PPPPP(s...); }
#else
#define dump(...) do{ } while(false)
#endif
template<typename T> vector<T> make_v(size_t a, T b) { return vector<T>(a, b); }
template<typename... Ts> auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v(ts...))>(a, make_v(ts...)); }
template<typename T> bool chmin(T &a, T b) { if (a > b) {a = b; return true; } return false; }
template<typename T> bool chmax(T &a, T b) { if (a < b) {a = b; return true; } return false; }
template<typename T> void print(T a) { cout << a << endl; }
template<typename T, typename... Ts> void print(T a, Ts... ts) { cout << a << ' '; print(ts...); }
template<typename T> istream &operator,(istream &in, T &t) { return in >> t; }
// clang-format on

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n;
    cin, n;
    vector<ll> a(n);
    REP(i, 0, n) {
        cin >> a[i];
    }
    ll ans = 1LL << 60;
    REP(i, 0, 102) {
        ll temp = 0;
        REP(j, 0, n) {
            temp += (a[j] - i) * (a[j] - i);
        }
        chmin(ans, temp);
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
// #include "pch.h"
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <bitset>
#include <climits>
#include <string>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>
#include <ctime>
#include <cassert>
#include <fstream>
#include <stack>
#include <random>
#include <atcoder/segtree>

typedef long long ll;
typedef std::pair<int, int> Pii;
typedef std::pair<long long, long long> Pll;
typedef std::pair<double, double> Pdd;

#define rip(i, n, s) for (int i = (s);i < (int)( n ); i++)
#define all(a) a.begin(), a.end()
#define MM << " " <<

template<typename T>
using MaxHeap = std::priority_queue<T>;
template<typename T>
using MinHeap = std::priority_queue<T, std::vector<T>, std::greater<T>>;

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

template<typename T>
void vdeb(std::vector<T> &da) {
    for (int i = 0;i < da.size();i++) {
        if (i == da.size() - 1) std::cout << da[i];
        else std::cout << da[i] << ' ';
    }
    std::cout << '\n';
}
template<typename T>
void vdeb(std::vector<std::vector<T>> &da) {
    for (int i = 0;i < da.size();i++) {
        std::cout << i << ' ';
        vdeb(da[i]);
    }
    std::cout << '\n';
}

using namespace std;
namespace ac = atcoder;

int vv = 0;

int op (int a, int b){return max(a, b);};
int e() {return -1;};
bool f(int x) {return x < vv;}

int main() {
    int n, q; cin >> n >> q;
    vector<int> da(n);
    rip(i,n,0) cin >> da[i];
    ac::segtree<int, op, e> st(da);
    vector<int> ans(0);
    rip(i,q,0) {
        int t,x,v; cin >>t >> x >> v;
        if(t == 1) {
            --x;
            st.set(x, v);
        }
        else if (t == 2) {
            --x;
            ans.push_back(st.prod(x, v));
        }
        else {
            --x;
            vv = v;
            ans.push_back(st.max_right<f>(x)+1);
        }
    }
    for(auto i:ans) printf("%d\n", i);
}

Measured memory_bytes: 7040
h,w=map(int,input().split())
ans=h*w
for i in range(1,w):
  s1=i*h
  s2=(w-i)//2*h
  s3=w*h-s1-s2
  m1=max(s1,s2,s3)-min(s1,s2,s3)
  s2=h//2*(w-i)
  s3=w*h-s1-s2
  m2=max(s1,s2,s3)-min(s1,s2,s3)
  ans=min(ans,m1,m2)
for i in range(1,h):
  s1=i*w
  s2=(h-i)//2*w
  s3=w*h-s1-s2
  m1=max(s1,s2,s3)-min(s1,s2,s3)
  s2=w//2*(h-i)
  s3=w*h-s1-s2
  m2=max(s1,s2,s3)-min(s1,s2,s3)
  ans=min(ans,m1,m2)
print(ans)

Measured memory_bytes: 73604
//Æ­·Ö²»¹æ·¶£¬±¬ÁãÁ½ÐÐÀá
#include<bits/stdc++.h>
#define ll long long
#define mp make_pair
#define endl '\n'
#define rep(i,n) for(register int i=0;i<(n);++i)
#define For(i,x,y) for(register int i=(x);i<=(y);++i)
#define pii pair<int,int>
using namespace std;
#define mod_int quick_num
long long md=19260817;
struct quick_num{
	long long num;
	inline void read(){cin>>num;}
	inline void write(){cout<<num;}
	inline void _write(){cout<<num<<' ';}
	inline void print(){cout<<num<<endl;}
};
inline void read(quick_num&x){cin>>x.num;}
inline void write(quick_num x){cout<<x.num;}
inline void _write(quick_num x){cout<<x.num<<' ';}
inline void print(quick_num x){cout<<x.num<<endl;}
inline long long qp(long long x,long long y){
	long long rt=1;
	for(;y;y>>=1,(x*=x)%=md)if(y&1)(rt*=x)%=md;
	return rt;
}
inline long long inv(long long x){return qp(x,md-2);}
inline quick_num operator +(quick_num a,quick_num b){
	quick_num c;c.num=a.num+b.num;
	if(c.num>=md)c.num-=md;
	return c;
}
inline quick_num operator -(quick_num a,quick_num b){
	quick_num c;c.num=a.num-b.num;
	if(c.num<0)c.num+=md;
	return c;
}
inline quick_num operator *(quick_num a,quick_num b){
	quick_num c;c.num=a.num*b.num;
	c.num%=md;
	return c;
}
inline quick_num operator /(quick_num a,quick_num b){
	quick_num c;c.num=a.num*inv(b.num)%md;
	return c;
}
inline quick_num operator %(quick_num a,quick_num b){
	quick_num c;c.num=a.num%b.num;
	return c;
}
const int maxn=1000;
char buffer[maxn],*S,*T;
inline char Get_Char(){
    if(S==T){
        T=(S=buffer)+fread(buffer,1,maxn,stdin);
        if(S==T)return EOF;
    }
    return *S++;
}

inline int read(){
    char c;
    int re=0,f=0;
    for(c=Get_Char();c<'0' or c>'9';c=Get_Char())if(c=='-')f=1;
    for(;c>='0' and c<='9';)re=(re<<1)+(re<<3)+(c-'0'),c=Get_Char();
    if(f)return -re;
    return re;
}

inline void read(int&x){
    char c;
    int re=0,f=0;
    for(c=Get_Char();c<'0' or c>'9';c=Get_Char())if(c=='-')f=1;
    for(;c>='0' and c<='9';)re=(re<<1)+(re<<3)+(c-'0'),c=Get_Char();
    if(f)x=-re;
    else x=re;
}

signed main(){
	ios_base::sync_with_stdio(false);
	ll n,a,b,c,d;
	cin>>n>>a>>b;
	if((a-b)%2==0){
		cout<<abs(a-b)/2<<endl;
		return 0;
	}
	if(a>b)swap(a,b);
	ll x=1,y=b-a+1;
	if(abs(x-y)%2==0){
		c=a-1+abs(y-x)/2;
	}else{
		c=a+abs(y-x-1)/2;
	}
	ll ta=a,tb=b;
	a+=(n-b),b=n;
	if(abs(b-a)%2==0){
		d=n-tb+(abs(b-a)/2);
	}else{
		d=n-tb+1+(abs(b-a-1))/2;
	}
	cout<<min(c,d)<<endl;
}

Measured memory_bytes: 256
#include <cstdio>

long long pi[233];

int main()
{
	int n; scanf("%d",&n);
	for(int i=1; i<=n; i++)
	{
		int a=i,b=i%10;
		while(a>9) a=a/10;
		pi[a*10+b]++;
	}
	long long sum=0;
	for(int i=1; i<=9; i++) for(int j=1; j<=9; j++)
		sum+=pi[i*10+j]*pi[j*10+i];
	printf("%lld",sum);
	return 0;
}

Measured memory_bytes: 128
// #include <bits/stdc++.h>
#include <stdio.h>
#include <iostream>
#include <vector>
#include <string>
#include <tuple>
#include <map>
#include <math.h>
#include <algorithm> // std::sort, std::min, std::next_permutation, std::lower_bound
#include <iomanip> // std::setprecision
#include <cmath> // std::ceil
#include <numeric> // std::gcd, std::lcm
#include <limits> // std::numeric_limits<long int>::max()
#include <unordered_map>
#include <map>
#include <cmath> // std::atan2
#include <deque>
#include <queue>

using namespace std;
typedef long long ll;
#define INF 1999999999
#define MODA 1000000007 
#define rep(i,n) for (long long i = 0; i < (n); ++i)

int main() {
  ll N;
  cin >> N;
  vector<ll> h(N);
  rep (i, N) cin >> h[i];

  ll ans = 0;
  ll prev = 0;
  rep (i, N) {
    if(h[i] > prev) ans += h[i] - prev;
    prev = h[i];
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3172
def myAnswer(N:int,L:int,S:list)->str:
   S.sort()
   ans = ""
   for s in S:
      ans+=s
   return ans

def modelAnswer():
   tmp=1
def main():
   N,L=map(int,input().split())
   S =[]
   for _ in range(N):
      S.append(str(input()))
   print(myAnswer(N,L,S[:]))


if __name__ == '__main__':
   main()

Measured memory_bytes: 3064
while 1:
	n = int(raw_input())
	if n == 0:
		break;
	
	li = []
	t = 0
	for i in range(n):
		li.append(int(raw_input()))
	
	li.sort()
	for i in range(n - 1, 0, -1):
		t += i * li[n - i - 1]
		
	print t

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

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

    static class Triangles {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int n = in.nextInt();
            int[] array = new int[n];

            for (int i = 0; i < n; i++) {
                array[i] = in.nextInt();
            }
            Arrays.sort(array);

            long result = 0;
            for (int i = 0; i < array.length - 2; i++) {
                int a = array[i];
                for (int j = i + 1; j < array.length - 1; j++) {
                    int b = array[j];
                    int k = j;
                    while (k < array.length && array[k] < a + b) {
                        k++;
                    }
                    result += k - (j + 1);
                }
            }
            out.println(result);
        }

    }
}



Measured memory_bytes: 40128
A, B, C, X, Y = map(int, input().split())
ans0 = A * X + B * Y
# A
ans1 = A * X + 2 * C * Y
# B
ans2 = 2 * C * X + B * Y
# C
ans3 = 2 * C * max(X, Y)
# D
#
t = abs(X - Y)

ans4 = 2 * C * min(X, Y)
ans5 = 10 ** 18
ans6 = 10 ** 18
if X > Y:
    temp1 = A * t
    temp2 = 2 * C * t
    ans5 = ans4 + min(temp1, temp2)
else:
    temp1 = B * t
    temp2 = 2 * C * t
    ans6 = ans4 + min(temp1, temp2)

print(min(ans0,ans1, ans2, ans3, ans5, ans6))


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

#define IOS                                                                    \
    ios::sync_with_stdio(0);                                                   \
    cin.tie(0);                                                                \
    cout.tie(0);
#define endl "\n"
typedef long long ll;
const ll N = 2e6 + 5;
const ll MOD = 1e9 + 7;

ll powmod(ll a, ll b, ll m) {
    ll ans = 1;
    while(b) {
        if(b & 1)
            ans = (ans * a) % m;
        b /= 2;
        a = (a * a) % m;
    }
    return ans;
}

ll fact[N], invfact[N];

ll modinv(ll k) { return powmod(k, MOD - 2, MOD); }

void precompute() {
    fact[0] = fact[1] = 1;
    for(ll i = 2; i < N; i++) {
        fact[i] = fact[i - 1] * i;
        fact[i] %= MOD;
    }
    invfact[N - 1] = modinv(fact[N - 1]);
    for(ll i = N - 2; i >= 0; i--) {
        invfact[i] = invfact[i + 1] * (i + 1);
        invfact[i] %= MOD;
    }
}

ll nCr(ll x, ll y) {
    if(y > x)
        return 0;
    ll num = fact[x];
    num *= invfact[y];
    num %= MOD;
    num *= invfact[x - y];
    num %= MOD;
    return num;
}

int main(void) {
    IOS;
    precompute();

    ll k;
    string s;
    cin >> k >> s;

    ll sum = 0;
    ll n = s.size();
    for(ll i = 0; i <= k; i++) {
        sum += nCr(n + i - 1, i) % MOD * powmod(25, i, MOD) % MOD *
               powmod(26, k - i, MOD) % MOD;
        // cout << "i:" << i << " n:" << n << " nCr:" << nCr(n + i - 1, i)
        //     << " ---- ";
        sum %= MOD;
        // cout << sum << endl;
    }
    cout << sum % MOD;
}


Measured memory_bytes: 35492
#include <iostream>
#include <iomanip>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <math.h>
#include <sstream>
#include <numeric>
#include <string>
#include <cassert>

using namespace std;
typedef long long ll;

int main() {
  int N;
  cin >> N;
  vector<int> P(N);
  for (int i = 0; i < N; ++i) {
    cin >> P[i];
  }

  vector<int> idx(N + 1);
  for (int i = 0; i < N; ++i) {
    idx[P[i]] = i;  // P[i] in {1..N}
  }

  ll ans = 0;
  set<int> s;
  for (int val = N; val >= 1; --val) {
    int x = idx[val];
    s.insert(x);

    vector<int> l(2, -1);
    vector<int> r(2, N);
    {  // left
      auto it = s.find(x);
      for (int i = 0; i < 2; ++i) {
	if (it == s.begin()) break;
	--it;
	l[i] = *it;
      }
    }
    {  // right
      auto it = s.find(x);
      for (int i = 0; i < 2; ++i) {
	++it;
	if (it == s.end()) break;
	r[i] = *it;
      }
    }
    
    if (l[0] != -1) {
      ans += (ll)(l[0] - l[1]) * (r[0] - x) * val;
    }
    if (r[0] != N) {
      ans += (ll)(x - l[0]) * (r[1] - r[0]) * val;
    }
  }

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


Measured memory_bytes: 5760
#include<bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define pb push_back
#define powerof2 ()
#define mp make_pair
#define pi acos(-1)
using ll = long long;
const ll M = 1000000007;
const ll M1= 998244353;
using vl = vector<ll>;
using pll =  pair<ll,ll>;
ll power(ll x,ll y){
	if(y==0)
		return 1;
	ll res=power(x,y/2);
	res=(res*res);
	if(y&1)
		res=(res*x);
	return res;
}
 
ll powermod(ll x,ll y,ll mod){
	if(y==0)
		return 1;
	ll res=powermod(x,y/2,mod);
	res=(res*res)%mod;
	if(y&1)
		res=(res*x)%mod;
	return res;
}
/*ll binarysearch(ll va)
{
	ll n=1;
	ll l=va+1,u=n;
	ll st=num.order_of_key(va);
	while(l+1<u)
	{
		m=(l+u)/2;
		ll in=num.order_of_key(m);
		if(in-st==m-va)
		{
			l=m;
		}
		else
		{
            u=m;
		}
	}
	if(num1.find(l)==num1.end())
		return l;
	return u;
}*/
void solve(){
	string s;
	cin>>s;
	int f=0;
	for(int i=0;i<(int)s.length();i++){
        if(i%2==0){
			if(s[i]=='R' || s[i]=='U' || s[i]=='D') f++;
		}
		else{
   if(s[i]=='L' || s[i]=='U' || s[i]=='D') f++;
		}
	}
	if(f==(int)s.length()) cout<<"Yes";
	else cout<<"No";
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t=1;
    // cin>>t;
 
    for(int i=1;i<=t;i++)
    {//cout<<"Case #"<<i<<": ";
    solve();}
    return 0;
}

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

int main() {
  int a;
  cin >> a;
  int b;
  cin >> b;
  bool d = false;
  for (int i = 1; i <= b; i = i + 1) {
    if (b%i == 0) {
      if (i == a) {
        d = true;
      }
    }
  }
  if (d) {
    cout << a + b << endl;
  } else {
    cout << b - a << endl;
  }
}
  

Measured memory_bytes: 384
h,w = map(int,input().split())
a = [input() for _ in range(h)]
x = [1,-1,0,0]
y = [0,0,1,-1]
for i in range(h):
    for j in range(w):
        cnt = 0
        if a[i][j] == '#':
            for k in range(4):
                if 0 <= i+x[k] < h and 0 <= j+y[k] < w:
                    if a[i+x[k]][j+y[k]] == '#':
                        cnt += 1
        else:
            continue

        if cnt == 0:
            print('No')
            exit()
else:
    print('Yes')

Measured memory_bytes: 3188
n,m,*t=map(int,open(0).read().split());r=[n+1]*(n+1)
for a,b in zip(*[iter(t)]*2):
	r[a]=min(r[a],b)
a=0;cur=n+1
for i in range(n+1):
	cur=min(cur, r[i])
	if i==cur:
		cur=r[i]
		a+=1
print(a)

Measured memory_bytes: 25132
#include <iostream>

using namespace std;

const int MAXN = 1e5+10;

int n, m;
int a[MAXN], b[MAXN];
int cnt[MAXN];

void solve() {
  for (int i=0;i<m;i++) {
    cnt[a[i]-1]++;
    cnt[b[i]-1]++;
  }
  for (int i=0;i<n;i++) {
    if (cnt[i] % 2 == 1) {
      cout << "NO" << endl;
      return;
    }
  }
  cout << "YES" << endl;
}

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


Measured memory_bytes: 1408
#include <bits/stdc++.h>
#define rep(i,l,n) for(int i=l;i<n;i++)
#define rer(i,l,n) for(int i=l;i<=n;i++)
#define all(a) a.begin(),a.end()
#define o(a) cout<<a<<endl
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef vector<int> vint;
typedef pair<int,int> pii;

int main(){
	vint w(10),k(10);
	int sw=0,sk=0;
	rep(i,0,10) cin>>w[i];
	rep(i,0,10) cin>>k[i];
	sort(all(w));
	sort(all(k));
	rep(i,7,10) sw+=w[i];
	rep(i,7,10) sk+=k[i];
	o(sw<<" "<<sk);
}

Measured memory_bytes: 1216
#!/usr/bin/env python3

import sys
sys.setrecursionlimit(300000)

MOD = 1000000007  # type: int

def get_fraction_mod(numerator, denominator):
    '''
        returns numerator / denominator (mod 1000000007)
    '''
    inv = pow(denominator, MOD - 2, MOD)
    return numerator * inv % MOD

def make_facts(n):
    '''
        0!(=1), 1!, 2!, 3! .... n!
    '''
    fact = [1]
    for i in range(n):
        fact.append((fact[i] * (i + 1)) % MOD)
    return fact

def solve(N: int, x: "List[int]"):
    facts = make_facts(N)
    f = facts[N - 1]
    ret = 0
    cur = 0
    for i in range(N - 1):
            d = x[i + 1] - x[i]
            cur += get_fraction_mod(f, i + 1)
            tmp  = d * cur
            ret += tmp
            ret %= MOD
    print(ret)
    return

def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    x = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, x)

if __name__ == '__main__':
    main()


Measured memory_bytes: 19492
#include <iostream>
#include <vector>
#include <set>
#include <string>
#include <algorithm>
#include <math.h>
typedef long long ll;
using namespace std;

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

	if (x < a) cout << "NO";
	else {
		if (a + b >= x) cout << "YES";
		else cout << "NO";
	}
}

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

#define ff first
#define ss second

#define pb push_back
#define mp make_pair
#define ins insert

#define f(i,n) for(int i = 0 ;  i < n ; i ++)
#define f1(i,n) for(int i = 1 ; i<= n ; i++)

#define int long long int

#define fast() ios_base::sync_with_stdio(false);cin.tie(NULL);
#define test() int t;cin>>t;while(t--)





int32_t main()
{
	fast();

	int k;
	cin >> k;
	int l , r;
	cin >> l >> r;

	int div = l/k;
	bool ok ;

	if(l%k==0)
		ok = true;
	else if(div*k + k <= r)
		ok  = true;
	else
		ok = false;

	if(ok)
		cout<<"OK";
	else
		cout<<"NG";
		
	return  0 ;
	
}




Measured memory_bytes: 3644
#include <cstdio>
#include <cstring>
#include <string>
#include <cmath>
#include <cassert>
#include <iostream>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <bitset>
#include <functional>
#include <numeric>
using namespace std;

#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define mp(a,b) make_pair((a),(b))
#define pb(a) push_back((a))
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<((x))<<endl
#define fi first
#define se second

#define INF 2147483600
#define long long long

int main(){
  string a,b,c;
  cin>>a>>b>>c;
  cout<<"A"<<b[0]<<"C"<<endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define mp make_pair
#define sz(x) (int)(x).size()
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define ii pair<int,int>
#define INF 1000000000
#define INFLL 1000000000000000010ll
#define UQ(x) (x).resize(distance((x).begin(),unique(all((x)))))
#define mid(x,y) (((x)+(y))>>1)
int n,a[300005];
int main() {
	scanf("%d",&n);
	for (int i=0;i<3*n;i++) scanf("%d",&a[i]);
	ll ans=0ll;
	sort(a,a+3*n);
	for (int i=0;i<n;i++) {
		ans+=(ll)a[3*n-(i+1)*2];
	}
	printf("%lld\n", ans);
}

Measured memory_bytes: 1408
#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; i >= 0; i--) 
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
#define downque(que) priority_queue<ll> que;
#define upque(que) priority_queue<ll, vector<int>, greater<int>> que;
typedef long long ll;
typedef vector<vector<int>> Matrix;
const int MOD = 1e9 + 7;
const int MAX = 1e7;
const int INF = numeric_limits<int>::max();

int main(){
 int n,m,x,t=0,res=0; cin>>n>>m>>x;
 int a[n+1]; REP(i,n+1)a[i]=0;
 REP(i,m){
     int t; cin>>t;
     a[t]=1;
 }
 int sum1=0,sum2=0,step=x;
 while(step!=0){
     if(a[step])sum1++;
     step--;
 }
step=x;
 while(step!=n){
     if(a[step])sum2++;
     step++;
 }
cout<<min(sum1,sum2)<<endl;
}

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

#define MAX 100000

int compare_int(const void *a,const void *b){
    return *(int*)a - *(int*)b;
}

int main(void){

    int N,d[MAX],i,j,tmp,result;

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

    qsort(d,N,sizeof(int),compare_int);

    result = d[N/2] - d[(N/2) - 1];

    printf("%d",result);
    return 0;
}

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

struct ca
{
  int idx,st,et,aidx;
};

int prime[1000001]={};

int power(int x, unsigned int y, int p)  
{  
    int res = 1;     
  
    x = x % p; 
   
    if (x == 0) return 0; 
  
    while (y > 0)  
    {  
         
        if (y & 1)  
            res = (res*x) % p;  
  
        
        y = y>>1; 
        x = (x*x) % p;  
    }  
    return res;  
}  

void pr()
{
  prime[1]=0;

 for(int i=2;i*i<1000001;i++)
  if(prime[i]==0)
  for(int j=i*i;j<1000001;j+=i)
  prime[j]=1;

}

int countSetBits( int n) 
{ 
     int count = 0; 
    while (n) { 
        count += n & 1; 
        n >>= 1; 
    } 
    return count; 
} 
  
bool cmp1(ca c1,ca c2)
{
  if(c1.st<c2.st)
   return true;

  if(c1.st==c2.st && c1.idx<c2.idx)
   return true;

  return false;
}

bool cmp2(ca c1,ca c2)
{
  
  if(c1.idx<c2.idx)
  return true;
  return false;
}








int main()
{

    ios_base::sync_with_stdio(false); 
    cin.tie(NULL);  
   //pr();
  int t;
   //cin>>t;
   t=1;
  int id=1;

  while(t--)
{
   int n;
    cin>>n;
   
    long sum=0;
   int count=0;

  for(int i=1;i<=n;i++)
   if(i%3!=0 && i%5!=0)
   {
     sum+= i;
     count++;
   }

  cout<<sum;
}



return 0;
}


Measured memory_bytes: 3640
#include<bits/stdc++.h>
#define pii pair<int,int>
#define mp make_pair
#define F first
#define S second
#define vi vector<pii>
#define pb push_back
using namespace std;
const int N=505;
vi v,e;vector<int>ans;
int n,m,a[N][N];
void init()
{
	for(int i=0;i<n;i++)
		for(int j=0;j<m-1;j++)
			v.pb(mp(i,j));
	for(int i=0;i<n;i++)
		e.pb(mp(i,m-1));
}
void solve()
{
	for(int i=0;i<v.size();i++)
	{
		int x=v[i].F;
		int y=v[i].S;
		if(a[x][y]%2==1)
		{
			a[x][y]--,a[x][y+1]++;
			ans.pb(x);
			ans.pb(y);
			ans.pb(x);
			ans.pb(y+1);
		}
	}
	for(int i=0;i<e.size();i++)
	{
		int x=e[i].F;
		int y=e[i].S;
		if(a[x][y]%2==1&&i!=e.size()-1)
		{
			a[x][y]--,a[x+1][y]++;
			ans.pb(x);
			ans.pb(y);
			ans.pb(x+1);
			ans.pb(y);
		}
	}
	cout<<ans.size()/4<<endl;
	for(int i=0;i<ans.size();i+=4)cout<<ans[i]+1<<' '<<ans[i+1]+1<<' '<<ans[i+2]+1<<' '<<ans[i+3]+1<<endl;
}
int main()
{
	cin>>n>>m;
	for(int i=0;i<n;i++)
		for(int j=0;j<m;j++)
			cin>>a[i][j];
	init();
	solve();
	return 0;
}

Measured memory_bytes: 7156
#include <bits/stdc++.h>
using namespace std;
//Define many functions and words!!
//The functions I have defined start with a capital letter.

//C++ words.
#define MOD 1'000'000'007 //998'244'353
#define PI 3.14159265358979323846
typedef long long ll;
typedef vector<ll> vl;
typedef vector<double> vd;
typedef vector<vl> matrix;//A(n, vl(m));
typedef vector<string> vs;
typedef pair<ll,ll> pl;
typedef vector<pl> vp;
typedef pair<double,double> pd;
typedef vector<pd> vpd;
typedef vector<bool> vb;
typedef map<ll,ll> mapl;
#define nl "\n"s
#define rep(i,n) for(ll i=0LL; i<(n); i++)
#define INF ((1LL<<62)-(1LL<<31))
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define All(V) V.begin(),V.end()
#define Sortup(V) sort(All(V))
#define Sortdown(V) sort(V.rbegin(), V.rend())
#define Atleast(key, V) lower_bound(All(V), key)
#define Largerthan(key, V) upper_bound(All(V), key)

#define endYes do{cout << "Yes" << nl; return 0;}while(0)
#define endYES do{cout << "YES" << nl; return 0;}while(0)
#define endNo  do{cout << "No" << nl; return 0;}while(0)
#define endNO  do{cout << "NO" << nl; return 0;}while(0)


//Mathmatical functions.
template<class T>bool Chmax(T &a, const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool Chmin(T &a, const T &b){if(b<a){a=b;return 1;}return 0;}
ll Lpow(ll e,ll x){ll res=1LL;while(x){if(x&1)res*=e;e*=e;x/=2;}return res;}
ll LpowMOD(ll e,ll x){ll res=1LL;while(x){if(x&1)res*=e;e*=e;x/=2;res%=MOD;e%=MOD;}return res;}
void CumuSum(vl &A){rep(i,A.size())if(i)A[i]+=A[i-1];}
bool Bit(ll subset, ll Rsift){ return ((subset)>>(Rsift))&1; }
ll Gcd(ll a,ll b){ return b?Gcd(b,a%b):abs(a); }
ll Lcm(ll A,ll B){ return A/Gcd(A,B)*B; }
template<class T>double Dist(T x,T y,T X,T Y){return sqrt(pow(x-X,2.0)+pow(y-Y,2.0));}

//////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////
// solution comes here

//解説AC

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

    ll N;
    cin >> N;
    vl a(N);
    rep(i, N) cin >> a[i];

    mapl m;
    rep(i, N) m[a[i]]++;

    if(m.count(0)  and  m.size() == 1) endYes;

    else if(m.count(0)  and  m[0]*3 == N  and  m.size()==2  and  N%3==0) endYes;

    else if(m.size() == 3){
        ll t=0;
        for(auto x:m){
            if( x.S*3 != N ) endNo;
            t ^= x.F;
        }

        if( t == 0) endYes;
    }

    endNo;
}

Measured memory_bytes: 5760
import java.io.PrintStream;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception{
		new Main(new Scanner(System.in), System.out, System.err).exec();
	}
	public final Scanner sc;
	public final PrintStream out, err;
	public Main(final Scanner sc, final PrintStream out, final PrintStream err) {
		this.sc = sc;this.out = out;this.err = err;
	}
	static public final long pair(int a, int b) {return (((long)a) << 32) + b;}
	static public final int getPair1(long v) {return (int)(v >> 32);}
	static public final int getPari2(long v) {return (int)(v & 0xFFFFFFFF);}

	static public final long quad(long a, long b, long c, long d) {
		return ((a&0xFFFF)<< 48) + ((b&0xFFFF)<< 32) + ((c&0xFFFF)<< 16) +(d&0xFFFF);}
	static public final int getQuad1(long v) {return (int)( v >> 48          );}
	static public final int getQuad2(long v) {return (int)((v >> 32) & 0xFFFF);}
	static public final int getQuad3(long v) {return (int)((v >> 16) & 0xFFFF);}
	static public final int getQuad4(long v) {return (int)( v        & 0xFFFF);}

	static public final long record(int e, int m, int i) {
		return quad(-1, e, m, i);
	}
	static public final int re(long record) {
		return getQuad2(record);
	}
	static public final int rm(long record) {
		return getQuad3(record);
	}
	static public final int ri(long record) {
		return getQuad4(record);
	}

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

	private int p;
	private int[] inv;
	private int[] fact;
	private int[] finv;
	public final int mod(long v) {
		v %= p;
		return (int)(v < 0 ? v+p : v);
	}
	public final int mul(long a, long b) {
		return mod(a*b);
	}
	public final void initFact(double limit, double p) {
		initFact((int)limit, (int)p);
	}
	public final void initFact(int limit, int p) {
		this.p = p;
		this.inv = new int[limit+1];
		this.fact = new int[limit+1];
		this.finv = new int[limit+1];
		fact[1] = finv[1] = inv[0] = inv[1] = 1;
		for(int i=2;i<=limit;i++) {
			int a = p / i;
			int b = p % i;
			inv[i]  = mul(-a, inv[b]);
			fact[i] = mul(fact[i-1], i);
			finv[i] = mul(finv[i-1], inv[i]);
		}
	}
	public final int comb(int m, int n) {
		return mul(mul(fact[m], finv[n]), finv[m-n]);
	}
	//------------------------------------------
	static long lcm (long a, long b) {
		long temp;
		long c = a;
		c *= b;
		while((temp = a%b)!=0) {
			a = b;
			b = temp;
		}
		return (long)(c/b);
	}

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



	public void exec() throws Exception{
		final int N = sc.nextInt();
		final String[] S = new String[N+1];
		for(int i=0;i<N;i++) {
			S[i] = sc.next();
		}
		S[N] = "";
		Arrays.sort(S, 0, N);
		int max = 0;
		int cnt = 1;
		List<String> list = new LinkedList<String>();
		for(int i=1;i<N+1;i++) {
			if(!S[i-1].equals(S[i])) {
				// 切れ目
				if(max < cnt) {
					// 更新
					list.clear();
					max = cnt;
					list.add(S[i-1]);
				}else if (max == cnt){
					// 追加
					list.add(S[i-1]);
				}
				cnt = 1;
			}else {
				// 継続
				cnt++;
			}
		}
		for(String s : list) {
			out.println(s);
		}
	}
}


Measured memory_bytes: 79892
#include <iostream>
#include <set>
#include <map>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>
#include <iomanip>
#include <queue>
#include <deque>
#include <stack>
#include <climits>
#include <math.h>
#include <cassert>
#include <unordered_map>
#include <chrono>
#include <random>
#include <ctime>
using namespace std;
#pragma warning(disable : 4996)
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

const ld PI = 3.14159265358979323846;
const ll MOD = 1e9 + 7;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const ll MAXN = 5e5 + 1;

ll fact[MAXN];

ll mul(ll a, ll b) {
	return (a * b) % MOD;
}


ll pw(ll a, ll p) {
	ll res = 1;
	while (p > 0) {
		if (p & 1) {
			res = mul(res, a);
		}
		a = mul(a, a);
		p /= 2;
	}
	return res;
}

ll inv(ll a) {
	return pw(a, MOD - 2);
}


ll bin(ll k, ll n) {
	return mul(mul(fact[n], inv(fact[k])), inv(fact[n - k]));
}

ll a(ll k, ll n) {
	return mul(fact[n], inv(fact[n - k]));
}

int main() {
#ifdef _DEBUG
	freopen("input1.txt", "r", stdin);
	freopen("output2.txt", "w", stdout);
#endif
	srand(time(0));
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	fact[0] = 1;
	for (int i = 1; i < MAXN; i++) {
		fact[i] = mul(fact[i - 1], i);
	}
	ll n, m;
	cin >> n >> m;
	ll ans = 0;
	for (int i = 0; i <= n; i++) {
		ll opa = a(n - i, m - i);
		opa = mul(opa, opa);
		ll c = a(i, m);
		ll kek = bin(i, n);
		ll add = mul(mul(c, opa), kek);
		if (i & 1)add = -add;
		ans = (ans + add + MOD) % MOD;
	}
	cout << ans;
}

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

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

using namespace std;

void knapsack(int yosan,const vector< pair<int,int> > &a){
	int n=a.size();
	int dp[301]={};
	rep(i,n){
		int value=a[i].first,price=a[i].second;
		for(int j=yosan;j>=price;j--) dp[j]=max(dp[j],dp[j-price]+value);
	}
	int ans=max_element(dp,dp+yosan+1)-dp;
	printf("%d %d\n",dp[ans],ans);
}

int main(){
	for(int n,days,yosan;~scanf("%d%d%d",&n,&days,&yosan);){
		vector< pair<int,int> > kanmi[100];
		rep(i,n){
			int m; scanf("%d",&m);
			kanmi[i].resize(m);
			rep(j,m) scanf("%d%d",&kanmi[i][j].first,&kanmi[i][j].second);
		}

		vector< pair<int,int> > item;
		rep(t,days){
			int id; scanf("%d",&id);
			item.insert(item.end(),kanmi[id].begin(),kanmi[id].end());
		}

		knapsack(yosan,item);
	}

	return 0;
}

Measured memory_bytes: 1144