akhauriyash/Code-Regression huggingface dataset:
#include <string>
#include <vector>
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<stack>
#include<queue>
#include<cmath>
#include<algorithm>
#include<functional>
#include<list>
#include<deque>
#include<bitset>
#include<set>
#include<map>
#include<cstring>
#include<sstream>
#include<complex>
#include<iomanip>
#include<numeric>
#define X first
#define Y second
#define pb push_back
#define rep(X,Y) for (int (X) = 0;(X) < (Y);++(X))
#define rrep(X,Y) for (int (X) = (Y-1);(X) >=0;--(X))
#define repe(X,Y) for ((X) = 0;(X) < (Y);++(X))
#define peat(X,Y) for (;(X) < (Y);++(X))
#define all(X) (X).begin(),(X).end()
#define rall(X) (X).rbegin(),(X).rend()

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
template<class T> ostream& operator<<(ostream &os, const vector<T> &t) {
os<<"{"; rep(i,t.size()) {os<<t[i]<<",";} os<<"}"<<endl; return os;}
template<class S, class T> ostream& operator<<(ostream &os, const pair<S,T> &t) { return os<<"("<<t.first<<","<<t.second<<")";}
#define re real()
#define im imag()

typedef complex<double> P;
typedef pair<P,P> L; //sX+tY
const double EPS=1e-10;
double dot(P a,P b){return (conj(a)*b).real();}
double cros(P a,P b){return (conj(a)*b).imag();}
double area(P a,P b,P c){
  b-=a; c-=a;
  return cros(b,c)/2;
}

double area(vector<P> ps){
  double ret=0;
  rep(i,ps.size()-2)
    ret+=area(ps[0],ps[i+1],ps[i+2]);
  return ret;
}

int main(){
  ios_base::sync_with_stdio(false);
  cout<<fixed<<setprecision(0);
  int i,j,k,n,t=1;
  double x,y;
  while(1){
    scanf("%d",&n);
    if(!n)break;
    vector<P> ps;
    rep(i,n){
      scanf("%lf %lf",&x,&y);
      ps.pb(P(x,y));
    }
    printf("%d %.1f\n",t++,abs(area(ps)));
  }
  return 0;
}

Measured memory_bytes: 1272
fun main() {
    val N = readLine()!!.toInt()
    val A = readLine()!!.split(" ").map { it.toInt() }.sorted().reversed()

    var n = N
    n--
    var i = 1
    var ans = 0L
    while (n != 0){
        ans += A[i/2]
        n--
        i++
    }
    println(ans)
}

Measured memory_bytes: 65684
N = int(input())

le = len(str(N))
al = ['3','5','7']
al2 = []
for i in range(le-1):
    al1 = []
    for n in al:
        a = int(str(n)+'3')
        b = int(str(n)+'5')
        c = int(str(n)+'7')
        al1.append(a)
        al1.append(b)
        al1.append(c)
        al2.append(a)
        al2.append(b)
        al2.append(c)
    al = al1

cnt = 0
for n in al2:
    if n <= N:
        if all(str(n).count(c) > 0 for c in '753'):
            cnt += 1

print(cnt)

Measured memory_bytes: 43612
// Template from https://techracho.bpsinc.jp/jhonda/2019_08_05/78537

// input macro for competive-programming from https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        input_inner!{$s, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

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

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

#[allow(unused_macros)]
macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

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

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

    ($iter:expr, bytes) => {
        read_value!($iter, String).into_bytes()
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    use std::io::Read;
    let mut s = String::new();
    std::io::stdin().read_to_string(&mut s).unwrap();

    println!("{}", solve(&s));
}

macro_rules! test {
    ($($exp_input:expr => $output:expr),* $(,)*) => {
        #[test]
        fn solve_test() {
            $(
                let start = std::time::Instant::now();
                let input = solve($exp_input);
                let end = start.elapsed();
                assert_eq!(input, $output, "{}.{:03}", end.as_secs(), end.subsec_millis());
                assert!(end.as_secs() <= 2, "expected_sec: {}sec, actual_sec: {}sec", 2, end.as_secs());
                assert!(end.as_secs() <= 1, "expected_sec: {}sec, actual_sec: {}sec", 1, end.as_secs());
                assert!(end.subsec_millis() <= 10, "expected_ms: {}ms, actual_ms: {}ms", 10, end.subsec_millis());
                assert!(end.subsec_millis() <= 2, "expected_ms: {}ms, actual_ms: {}ms", 2, end.subsec_millis());
            )*
        }
    };
}

test! {
r#"ba"# => r#"xx"#,
}

fn solve(src: &str) -> String {
    let mut src_iter = src.split_whitespace();
    input! {
        source = src_iter,
        s: String,
    }

    (0..s.len()).map(|_| "x").collect()
}

Measured memory_bytes: 4352
import sys

sys.setrecursionlimit(10**5)

def solve():
    n, q = map(int, sys.stdin.readline().split())
    uf = UnionFind(n)
    ans = []

    for lp in range(q):
        c, x, y = map(int, sys.stdin.readline().split())

        if c == 0:
            uf.unite(x, y)
        else:
            ans.append(1 if uf.is_same(x, y) else 0)

    print(*ans, sep='\n')


class UnionFind:

    def __init__(self, n):
        self.ds = [i for i in range(n)]
        self.root = [i for i in range(n)]
        # self.rank = [0] * n

    def find_root(self, x):
        if x != self.root[x]:
            self.root[x] = self.find_root(self.root[x])

        return self.root[x]

    def is_same(self, x, y):
        return self.find_root(x) == self.find_root(y)

    def unite(self, x, y):
        p = self.find_root(x)
        q = self.find_root(y)
        self.root[p] = q

def debug(x, table):
    for name, val in table.items():
        if x is val:
            print('DEBUG:{} -> {}'.format(name, val), file=sys.stderr)
            return None

if __name__ == '__main__':
    solve()

Measured memory_bytes: 14132
S = input()
s_len = len(S)
mod_hash = {0: 1}
mod_temp = 1
mod = 0

for i in range(1, s_len + 1):
	mod = (mod + mod_temp * int(S[-i])) % 2019
	if mod in mod_hash:
		mod_hash[mod] += 1
	else:
		mod_hash[mod] = 1
	mod_temp = (mod_temp * 10) % 2019

ans = 0
for v in mod_hash.values():
	ans += v * (v - 1) // 2

print(ans)


Measured memory_bytes: 9328
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <numeric>
#include <string>
using namespace std;
const double PI = acos(-1.0);
const string alp = "abcdefghijklmnopqrstuvwxyz";
const string ALP = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
const string HEX = "0123456789ABCDEF";
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define SUM(c) accumulate((c).begin(),(c).end(),0)
#define Yn(b) puts(b?"Yes":"No")
#define YN(b) puts(b?"YES":"NO")

int main(void) {
    string s;
    cin >> s;
    cout << ((s[0]=='1')?1:0)+((s[1]=='1')?1:0)+((s[2]=='1')?1:0);
    return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize("O3")
#pragma GCC target("avx2")
 
#include <vector>
#include <set>
#include <cstdio>
using namespace std;
  
int main(){
    int N;
    long long W,tV=0,tW=0,x=0;
    scanf("%d%lld",&N,&W);
    vector<pair<long long,long long> >v(N);
    for(int i=0;i<N;i++)scanf("%lld%lld",&v[i].first,&v[i].second),tV+=v[i].first,tW+=v[i].second;
 
        int n=N/2;
        set<pair<long long,long long> >se1,se2;
        for(int i=0;i<1<<n;i++){
            long long V=0,w=0;
            for(int j=0;j<n;j++)if(i&(1<<j))V+=v[j].first,w+=v[j].second;
            se1.emplace(w,V);
        }
        for(int i=0;i<1<<(N-n);i++){
            long long V=0,w=0;
            for(int j=0;j<(N-n);j++)if(i&(1<<j))V+=v[j+n].first,w+=v[j+n].second;
            se2.emplace(w,V);
        }
        for(auto it=se1.begin();it!=se1.end();){
            auto it2=it;
            for(++it2;it2!=se1.end()&&it->second>=it2->second;)it2=se1.erase(it2);
            ++it;
        }
        for(auto it=se2.begin();it!=se2.end();){
            auto it2=it;
            for(++it2;it2!=se2.end()&&it->second>=it2->second;)it2=se2.erase(it2);
            ++it;
        }
        long long r=0;
        for(auto &e1:se1){
            auto it=se2.lower_bound({W-e1.first+1,0});
            if(it!=se2.begin()){
                --it;
                r=max(r,e1.second+it->second);
            }
        }
        printf("%lld\n",r);
}

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

int main() {
    int N, M;
    cin >> N >> M;
    vector<int> P(M);
    vector<string> S(M);
    for(int i=0; i<M; i++)
        cin >> P[i] >> S[i];
    vector<long long> nWA(N+1,0);
    long long ans = 0, pen = 0;
    for(int i=0; i<M; i++) {
        if(S[i] == "AC" && nWA[P[i]] != -1) {
            ans++;
            pen += nWA[P[i]];
            nWA[P[i]] = -1;
        } else if(S[i] == "WA" && nWA[P[i]] != -1) nWA[P[i]]++; 
    }
    cout << ans << " " << pen << "\n";
}

Measured memory_bytes: 6912
#include<bits/stdc++.h> 
#define REP(i, b) for(int i = 0; i < (b); i++)
#define REPS(i, b) for(int i = 1; i <= (b); i++)
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define ALL(v) (v).begin(), (v).end()
using namespace std;
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;

signed main()
{
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);

    int H, W; cin >> H >> W;
    vector<string> G(H); REP(i, H) cin >> G[i];
    vector<vector<int>> t(H, vector<int>(W));

    REP(i, H)
    {
        ll m = 0;
        for(int j = 0; j < W; j++)
        {
            if(G[i][j] == '#') m = 0;
            else
            {
                t[i][j] += m;
                m++;
            }
        }
        m = 0;
        for(int j = W-1; j >= 0; j--)
        {
            if(G[i][j] == '#') m = 0;
            else
            {
                t[i][j] += m;
                m++;
            }
        }
    }

    REP(i, W)
    {
        ll m = 0;
        for(int j = 0; j < H; j++)
        {
            if(G[j][i] == '#') m = 0;
            else
            {
                t[j][i] += m;
                m++;
            }
        }
        m = 0;
        for(int j = H-1; j >= 0; j--)
        {
            if(G[j][i] == '#') m = 0;
            else
            {
                t[j][i] += m;
                m++;
            }
        }
    }

    int ans = 0;
    REP(i, H) REP(j, W) ans = max(ans, t[i][j]);
    cout << ans + 1 << endl;
}

Measured memory_bytes: 20224
#include <iostream>
using namespace std;
  
int main()
{
    int array[10];
    int i,j;
    for(i=0; i<10; i++)
        cin>>array[i];
    
    for(i=0; i<9; i++){
        for(j=i+1; j<10; j++){
            if(array[i]<array[j]){
                int tmp=array[i];
                array[i]=array[j];
                array[j]=tmp;
            }
        }
    }
    
    for(i=0; i<3; i++)
        cout<<array[i]<<"\n";
    
    return 0;
}

Measured memory_bytes: 1164
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"

using namespace std;

const long long int MOD = 1000000007;

long long int N, M, K, H, W, L, R;

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

	cin >> N;
	M = N;
	while (M) {
		K += M % 10;
		M /= 10;
	}
	if (N%K)cout << "No\n";
	else cout << "Yes\n";
	return 0;
}

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

public class Solution
{
    public static void Main()
    {
        var n = int.Parse(Console.ReadLine());
        var v = Console.ReadLine().Split(' ').Select(int.Parse).OrderBy(x => x).ToArray();

        double cur = v[0];
        foreach (var x in v.Skip(1))
        {

            cur = (cur + x) / 2;
        }

        Console.WriteLine(cur);
    }
}

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

#define ll long long
#define all(x) (x).begin(), (x).end()
const long long INF = 1LL << 60;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)  //(i, 10) i=0～i=9まで
#define repr(i, n) for (int i = n; i >= 0; i--)   // (i, 10) i=10～i=0まで
#define FOR(i, m, n) for (int i = m; i < n; i++)  // (i, 3, 10) i=3～i=9まで

// 総数を1000000007で割った余り
const long long mod = 1e9 + 7;

int main() {
    // cin.tie(0);
    // ios::sync_with_stdio(false);
    // cout << fixed << setprecision(5);

    // 入力

    string s;
    cin >> s;

    // 処理
    int cnt = 0;
    rep(i, 3) {
        if (s[i] == '1') {
            cnt++;
        }
    }

    // 出力
    cout << cnt << endl;

    return 0;
}


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef double db;

#define endl "\n"

const int MOD = 1000000007;


int main()
{
    ios::sync_with_stdio(0);cin.tie(0);
    int x;
  cin >> x;
  int ans = pow(x,3);
  cout << ans << endl;
		
	
}

Measured memory_bytes: 3984
#include<bits/stdc++.h>
#define fo(i,a,b) for(register int (i)=(a);(i)<=(b);++(i))
#define rd read()
#define maxn 200001
#define gc getchar()
#define mem(a,b) memset(a,b,sizeof(a))
#define mp make_pair
#define ll long long
#define ull unsigned ll
#define pb push_back
#define db double
#define pu puts(" ")
using namespace std;
const int p=998244353;
int read()
{
	int x=0,f=1;
	char ch=gc;
	while(!isdigit(ch))
	{
		if(ch=='-')f=-1;
		ch=gc;
	}
	while(isdigit(ch))x=x*10+ch-48,ch=gc;
	return x*f;
}
void print(int x)
{
	if(x<0)putchar('-'),x=-x;
	if(x>9)print(x/10);
	putchar(x%10+48);
}
int qp(int a,int b)
{
	int ans=1;
	while(b)
	{
		if(b&1)ans=(ll)ans*a%p;
		a=(ll)a*a%p;

		b>>=1;
	}
	return ans%p;
}

int main()
{
	int a=rd,b=rd,k=rd;
	fo(i,1,k)
	{
		if(i%2==1)
		{
		if(a%2==1)a--;a/=2,b+=a;}
		else{if(b%2==1)b--;b/=2,a+=b;}
	}
	printf("%d %d\n",a,b);
	return 0;
}

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

int main(void){
	int N, M, P;
	int sum, ans;
	int X[1001];
	while((scanf("%d %d %d", &N, &M, &P) != EOF) && (N != 0 || M != 0 || P != 0)){
		sum = 0;
		for(int i = 0; i < N; i++){
			scanf("%d", X+i);
			sum += X[i];
		}

		P = 100 - P;

		if(X[M-1] == 0)	ans = 0;
		else ans = sum * P / X[M-1];

		printf("%d\n", ans);
	}
  return 0;
}

Measured memory_bytes: 1032
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<queue>
#include<stack>
using namespace std;
#define MOD 924844033
#define INF (1<<29)
#define LINF (1LL<<60)
#define EPS (1e-10)
typedef long long Int;
typedef pair<Int, Int> P;

Int fact[1080000];
Int revfact[1080000];
Int rev[1080000];

void init(){
  Int m = MOD;
  fact[0] = 1;
  revfact[0] = 1;
  rev[0] = 0;
  rev[1] = 1;
  for(int i = 1;i < 1080000;i++){
    fact[i] = fact[i-1] * i % m;
    if(i>1)rev[i] = MOD / i * (MOD-rev[MOD % i]) % MOD;
    revfact[i] = revfact[i-1] * rev[i] % MOD;
  }
}

Int nCk(Int n, Int k){
  if(n < k)return 0;
  return fact[n] * revfact[n-k] % MOD * revfact[k] % MOD;
}


Int dp[2160][2];
Int n, k, K;
int main(){
  init();
  dp[0][0] = 1;
  cin >> n >> K;
  for(int i = 0;i < K*2;i++){
    for(int j = i;j < n;j += 2*K){
      for(int k = n;k >= 1;k--){
	dp[k][0] = (dp[k][0] + dp[k][1]) % MOD;
	if(j >= K)dp[k][0] = (dp[k][0] + dp[k-1][0]) % MOD;
	if(K <= j && j < 2*K)dp[k][0] = (dp[k][0] + dp[k-1][1]) %MOD;
	if(j + K < n)dp[k][1] = (dp[k-1][0] + dp[k-1][1])%MOD;
	else dp[k][1] = 0;
      }
    }
  }

  Int cnt = fact[n];
  for(int i = 1;i <= n;i++){
    if(i % 2 == 1)cnt -= (dp[i][0] + dp[i][1]) * fact[n-i]%MOD;
    else cnt += (dp[i][0] + dp[i][1]) * fact[n-i] %MOD;
    cnt %= MOD;
  }
  if(cnt < 0)cnt += MOD;
  cout << cnt << endl;
  return 0;
}

Measured memory_bytes: 25600
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using static System.Console;
using static System.Math;
using static AtCoderTemplate.MyLibrary;

namespace AtCoderTemplate
{
    class Program
    {
        static void Main (string[] args)
        {
            string[] str = Console.ReadLine ().Split (' ');

            int A = int.Parse (str[0]);
            int B = int.Parse (str[1]);
            int C = int.Parse (str[2]);
            int D = int.Parse (str[3]);

            while (A > 0 || C > 0)
            {
                //高橋君の攻撃
                C -= B;
                if (C <= 0)
                {
                    Console.WriteLine ("Yes");
                    return;
                }

                //青木君の攻撃
                A -= D;
                if (A <= 0)
                {
                    Console.WriteLine ("No");
                    return;
                }
            }
        }

    }

    class MyLibrary
    {

        // 自作の関数
        public static int MyFunction (int n)
        {
            return 0;
        }
    }
}

Measured memory_bytes: 27448
#include <iostream>
#include <stack>
#include <stdio.h>

#define BUF_SIZE 120000

using namespace std;

int main(){

	int n;
	scanf("%d",&n);

	int S[n];

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

	int q;
	scanf("%d",&q);

	int count = 0;
	int tmp;

	for(int i = 0; i < q; i++){
		scanf("%d",&tmp);
		for(int k = 0; k < n; k++){
			if(tmp == S[k]){
				count++;
				break;
			}
		}
	}

	printf("%d\n",count);

}



Measured memory_bytes: 3244
/*
	Failure is not the reason for you to stop trying 
	   it is actually a remainder that you should 
			KEEP GOING 
*/
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back 
#define eb emplace_back
#define fn for(int i =0 ;i <n;i++)
#define fn1 for( int i =1;i<=n;i++)
#define fm for(int j =0 ;j <m;j++)
#define fm1 for(int j =1;j<=m;j++)
#define fi first
#define se second
#define E endl
#define MOD 1000000007
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
const int N = 1e6+5;
const int INF = 1e18L;
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}
int ar[N];
int dp[N];
signed main(){
	// #ifndef ONLINE_JUDGE
	// freopen("input.txt","r",stdin);
	// freopen("output.txt","w",stdout);
	// #endif
	IOS;
	int T=1;
	// cin >> T;
	while(T--){
		int n ,m;
		cin >> n >> m;
		cout<<(n==m ? "Yes" : "No");

	
	}
	
	cerr << "Time elapsed : " << 1.0 * clock() / CLOCKS_PER_SEC << " sec \n";
	return 0;
}

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


#define off ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define lmax1 9223372036854775807
#define max1 2147483647
#define lmin1 -9223372036854775808
#define pi 3.141592653589793116
#define mod 1e9+7

int pa[100001],size[100001];
vector <int > v[100001];

void make_set(int i)
{
    pa[i]=i;
    size[i]=1;
}

int find_set(int a)
{
    if(pa[a]==a)
        return a;
    return(pa[a]=find_set(pa[a]));
}
long long uni(int a,int b)
{
    a=find_set(a);
    b=find_set(b);
    if(a!=b)
        {
            pa[b]=a;
            long long x=(size[a])*1ll*(size[b]);
            size[a]+=size[b];
            return (x);
        }
     else
        return 0;   
      
}
int main() {
    off;
    int n,m;
    cin>>n>>m;
    for(int i=1;i<=n;i++)
        make_set(i);
    stack <long long > ans;
    vector <pair <int ,int > > v;
    ans.push((n*1ll*(n-1))/2);
    for(int i=0;i<m;i++)
    {   int x,y;
        cin>>x>>y;
        v.push_back({x,y});
    }
    for(int i=m-1;i>0;i--)
    {
        int s=v[i].first;
        int t=v[i].second;
        long long temp;
        temp=ans.top();
        //cout<<temp<<" "<<uni(s,t)<<"\n";
        ans.push(temp-uni(s,t));
    }
    while(ans.size()>0)
    {
        cout<<ans.top()<<'\n';
        ans.pop();
    }
      return 0;
    }

Measured memory_bytes: 6132
#include<bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define ll long long
#define pb push_back
#define pf push_front
#define Mid ((l+r)/2)
#define pi pair<int,int>
#define pii pair<int,pi>
#define deb(x) cout<<#x<<"="<<x<<endl;
#define go ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
int f[10];
int main()
{
    go;
    int x,y;
    cin>>x>>y;
    if(y>=2*x&&y<=4*x&&y%2==0)
        cout<<"Yes";
    else
        cout<<"No";
    return 0;
}


Measured memory_bytes: 3648
import heapq

if __name__ == "__main__":
    v, e, r = map(int, input().split())
    graph = [[] for _ in range(v)]
    for _ in range(e):
        s, t, d = map(int, input().split())
        graph[s].append((t, d))
    
    d = [float('inf')] * v
    d[r] = 0

    hq = [(0, r)]
    heapq.heapify(hq)

    while hq:
        cost, now = heapq.heappop(hq)
        if d[now] < cost:
            continue

        for nei in graph[now]:
            to = nei[0]
            c = nei[1]
            if d[to] > d[now] + c:
                d[to] = d[now] + c
                heapq.heappush(hq, (d[to], to))
    for i in range(v):
        if d[i] == float('inf'):
            print("INF")
        else:
            print(d[i])


Measured memory_bytes: 89288
import sys
import itertools
# import numpy as np
import time
import math
import heapq
 
sys.setrecursionlimit(10 ** 7)
 
from collections import defaultdict
 
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
INF = 10 ** 9 + 7

# map(int, input().split())
# list(map(int, input().split()))

N = int(input())
M = [0] * N
for i in range(N):
    M[i] = tuple(map(int, input().split()))

dp = [[INF] * (N) for _ in range(N)]
for i in range(N):
    dp[i][i] = 0

def rec(l, r):
    if dp[l][r] != INF:
        return dp[l][r]
    res = INF
    for mid in range(l, r):
        res = min(res, rec(l, mid) + rec(mid + 1, r) + M[l][0] * M[mid][1] * M[r][1])
    dp[l][r] = res
    return res
print(rec(0, N - 1))



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

int main() {
   int sx,sy,tx,ty;
   cin >> sx >> sy >> tx >> ty;
   for (int i=0; i<tx-sx; i++) {
       cout << "R" ;
   }
   for (int i=0; i<ty-sy; i++) {
       cout << "U";
   }
   for (int i=0; i<tx-sx; i++) {
       cout << "L";
   }
   for (int i=0; i<ty-sy+1; i++) {
       cout << "D";
   }
   for (int i=0; i<tx-sx+1; i++) {
       cout << "R" ;
       }
   for (int i=0; i<ty-sy+1; i++) {
       cout << "U";
   }
   cout << "LU";
   for (int i=0; i<tx-sx+1; i++) {
       cout << "L";
   }
   for (int i=0; i<ty-sy+1; i++) {
       cout << "D";
   }
   cout << "R" << endl;
}


Measured memory_bytes: 3588
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
using namespace std;
#define sum(n) (n)*((n) + 1) / 2

long ineq_pair(char a, char b) {
    if ( (a == '>') && (b == '<')) {
        return 0;
    }
    else if ((a == '<') && (b == '>')) {
        return 1;
    }
    else if ((a == '<') && (b == '<')) {
        return 2;
    }
    else if ((a == '>') && (b == '>')) {
        return 3;
    }
    return -1; //異常終了
}

int main()
{
    string S;
    cin >> S;
    long N = S.size() + 1;
    S = '<' + S + '>';
    vector<long> type(N);
    queue<long> q0, q1;

    //>< 0   <> 1   << 2   >> 3
    for (long i = 0; i < N; i++) {
        type.at(i) = ineq_pair(S.at(i), S.at(i + 1));

        if (type.at(i) == 1) {
            q1.push(i);
            if (i == 0) {
                q0.push(-1);
            }
            else if (i == N - 1) {
                q0.push(N);
            }
        }
        
        if (type.at(i) == 0) {
            q0.push(i);
        }

        if ((i == 0) && type.at(i) != 1) {
            q0.push(i);
        }

        if ((i == N - 1) && type.at(i) != 1) {
            q0.push(i);
        }

    }

    vector<pair<long, long>> border(q0.size() + 1, pair<long, long>(0, 0));
    long i = 0, ans = 0;
    while(!q1.empty()) {
        border.at(i).first = q1.front() - q0.front();
        q0.pop();
        border.at(i).second = q0.front() - q1.front();
        q1.pop();

        long temp_max, temp_min;
        temp_max = max(border.at(i).first, border.at(i).second);
        temp_min = min(border.at(i).first, border.at(i).second);

        ans += sum(temp_max) + sum(temp_min - 1);
        i++;
    }
    
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 8600
import math
def prime(n):
    for i in range(3, int(math.sqrt(n)), 2):
        if n % i == 0:
            return False
    return True
x = int(input())
if x <= 2:
    print(2)
else:
    if x % 2 != 0:
        y = x
    else:
        y = x + 1
    f = prime(y)
    while f == False:
        y += 2
        f = prime(y)
    print(y)


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

int main(void){
    int N;
    cin >> N;
    int i = 1;
    int ans = 1;

    while(N >= i*i){
        ans = max(ans, i*i);
        i++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
/*#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 mp make_pair
#define S second
#define F first
#define vi vector<ll>
#define pii pair<ll,ll>
#define bc __builtin_popcountll
#define vvi vector<vi> 
#define vpii vector<pair<ll,ll>>
#define mll unordered_map<ll,ll>
#define INF LONG_LONG_MAX
#define NINF LONG_LONG_MIN
#define fo(i,a,b) for(i=a;i<=b;i++)
#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 endd cout<<'\n';
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define fr(it, a) for(auto it = a.begin(); it != a.end(); it++)
#define PI 3.1415926535897932384626
#define clr(x) memset(x, -1.00, sizeof(x))
#define sortall(x) sort(all(x))
#define all(x) x.begin(), x.end()
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#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()-->returns an iterator to the k-th largest element (counting from zero)
//X.order_of_key()-->the number of items in a set that are strictly smaller than our item.
struct cmp
{
	bool operator() (ll a,ll b){
		return (a>b);
	}
};
ll ceil(const ll &a, const ll &b)
{
    if(a%b == 0)
        return a/b;
    return a/b +1;
}
ll mod=1000000007;
const ll N=3005;
ll dp[N][N][2];
ll a[N];
ll go(ll i,ll j,ll k)
{
    if(i>j)
        return 0;
    if(dp[i][j][k]!=-1)
        return dp[i][j][k];
    ll res;
    if(k==0)
    {
        res=max(a[i]+go(i+1,j,1),a[j]+go(i,j-1,1));
    }
    else
    {
        res=min(-a[i]+go(i+1,j,0),-a[j]+go(i,j-1,0));
    }
    return dp[i][j][k]=res;
}
int main()
{
fast;
    ll n;
    cin>>n;
    f(i,n)
        cin>>a[i];
    clr(dp);
    cout<<go(0,n-1,0);   
    return 0;
}

Measured memory_bytes: 144824
import sys
stdin = sys.stdin
sys.setrecursionlimit(10**6)
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

s,w = na()

if w >= s:
    print('unsafe')
else:
    print('safe')

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

using namespace std;

int main()
{
    string s;
    cin >> s;
    int k;
    cin >> k;

    vector<string> substrings;

    for(int i = 1; i <= k; i++){
        for(int j = 0; j < s.length() - i + 1; j++){
            substrings.push_back(s.substr(j,i));
        }
    }

    sort(substrings.begin(),substrings.end());

    int inx = 1;
    for(int i = 0; i < substrings.size(); i++){
        if(inx == k){
            cout << substrings[i] << endl;
            return 0;
        }
        else if(substrings[i] != substrings[i + 1]){
            inx++;
        }
    }

    return 0;
}

Measured memory_bytes: 1660
from math import sqrt 
Q = int(input())
table=[]
for i in range(Q):
    A,B=map(int,input().split())
    if A>B:
        table.append([B,A])
    else:
        table.append([A,B])
def f(a,b):
    if a==b:
        return 2*a-2
    if a+1==b:
        return 2*a-2
    m = int(sqrt(a*b))
    if m**2 ==a*b:
        return 2*m-3
    if m*(m+1) >= a*b:
        return 2*m -2
    return 2*m-1

ans = []
for a,b in table:
    ans.append(f(a,b))
print('\n'.join(map(str,ans)))

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0;i<((int)(n));i++)
#define reg(i,a,b) for(int i = ((int)(a));i<=((int)(b));i++)
#define irep(i,n) for(int i = ((int)(n)-1);i>=0;i--)
#define ireg(i,a,b) for(int i = ((int)(b));i>=((int)(a));i--)
typedef long long ll;

/*
*/

ll n,a[110],ans=0;

void init(){
	cin>>n;
	rep(i,n)cin>>a[i];
}

int main(void){
	init();
	reg(i,1,n-2){
		if(a[i-1]<=a[i] && a[i]<=a[i+1]){
			ans++;
		}else if(a[i+1]<=a[i] && a[i]<=a[i-1]){
			ans++;
		}
	}
	cout<<ans<<endl;
	return 0;
}

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

int ans[365],c[26],s[365][26],last[26],csum,nowscore,newscore,temperature=3;
const int INF=1e9,d=365;

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

void FIN(bool a){
  if(a){
    ofstream fout("output.txt");
    REP(i,d)fout<<ans[i]+1<<"\n";
    fout.close();
    return;
  }
  REP(i,d)cout<<ans[i]+1<<"\n";
  return;
}
/*
int score(){
  int res=0;
  memset(last,-1,sizeof(last));
  REP(day,d){
    res+=s[day][ans[day]];
    last[ans[day]]=day;
    REP(i,26)res-=c[i]*(day-last[i]);
  }
  return res;
}
*/
int score(){//上のがO(26*365)、こっちがO(365)のスコア計算
  int res=0,minus=csum;
  memset(last,-1,sizeof(last));
  REP(day,d){
    res+=s[day][ans[day]];
    minus-=c[ans[day]]*(day-last[ans[day]]);
    last[ans[day]]=day;
    res-=minus;
    minus+=csum;
  }
  return res;
}
void swap(){
  int RAND=rand();
  int day=RAND%(d-8),diff=((RAND^newscore)&7)+1,p=(RAND|newscore)%temperature;
  swap(ans[day],ans[day+diff]);
  newscore=score();
  if(newscore<nowscore&&p)swap(ans[day],ans[day+diff]);
  else nowscore=newscore;
}
void onechange(){
  int RAND=rand();
  int day=RAND%365,p=(RAND^newscore)%temperature;
  REP(i,26){
    int tmp=ans[day];
    ans[day]=i;
    newscore=score();
    if(newscore<nowscore&&p)ans[day]=tmp;
    else nowscore=newscore;
  }
}

int main(){
  memset(last,-1,sizeof(last));
  cin>>c[0];
  REP(i,26){cin>>c[i];csum+=c[i];}
  REP(i,d)REP(j,26)cin>>s[i][j];
  REP(day,d){
    int idx,mx=-INF;
    REP(i,26){
      int A=c[i]*(day-last[i])+s[day][i];
      if(mx<A)mx=A,idx=i;
    }
    ans[day]=idx,last[idx]=day;
  }
  nowscore=score();
  REP(_,800){
    REP(__,100)swap();
    REP(__,100)onechange();
    if(_%100)temperature++;
  }
  FIN(0);
}


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

using namespace std;

int main() {
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);

	string s, t;
	cin >> s;
	cin >> t;

	bool flag = true;
	if (t.size() != (s.size() + 1)) {
		flag = false;
	} else {
		for (int i = 0; i < s.size(); i++) {
			if (s[i] != t[i]) {
				flag = false;
			}
		}
	}

	if (flag) {
		cout << "Yes" << endl;
	} else {
		cout << "No" << endl;
	}
	return 0;
}

Measured memory_bytes: 3588
x, y = map(int, input().split())
group1 = [4, 6, 9, 11]
group2 = [1, 3, 5, 7, 8, 10, 12]
if x in group1 and y in group1:
    print("Yes")
elif x in group2 and y in group2:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 2940
n=int(input())
a=list(map(int,input().split()))
dp=[[0]*n for _ in range(n)]
# dp[i][j]:i<=j,i番目からj番目までの数列(j-i+1個)を前にした時、ゲーム終了までに自分が取れる最大得点。i,j=0,..,n-1
sa=[0]
s=0
for ai in a:
      s+=ai
      sa.append(s)
for len in range(1,n+1):
      for l in range(n-len+1):
            r=l+len-1
            s=sa[r+1]-sa[l]
            dp[l][r]=max(s-dp[l][r-1],s-dp[l+1][r] if l+1<n else 0)
print(2*dp[0][-1]-sa[-1])


Measured memory_bytes: 112476
/*   _/                _/                 _/_/_/   _/
  _/_/_/_/   _/_/   _/_/_/_/   _/_/    _/       _/_/
   _/     _/    _/   _/     _/    _/  _/_/_/     _/
  _/     _/    _/   _/     _/    _/  _/    _/   _/
   _/_/   _/_/       _/_/   _/_/      _/_/     _/ */
#include<iostream>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<set>
#include<map>
#include<queue>
#include<vector>
using namespace std;
using ll=long long;
const int MOD=1e9+7;
const double pi=3.14159265358979323846;
const int inf=2e9;
const ll INF=1e18;
using P=pair<int,int>;
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
int main() {
  cin.tie(0),cout.tie(0);
  ios::sync_with_stdio(false);
  int n,m;
  cin >>n >> m;
  cout << (n-1)*(m-1) << endl;
}

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

using namespace std;
using ll = long long;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define all(x) (x).begin(),(x).end()
#define debug(x) cerr << #x << " = " << x << endl

const long long MOD = 1000000007;


int main(){
    ll a, b;
    cin >> a >> b;
    cout << max(a+b, max(a-b, a*b)) << endl;
    
    return 0;
}


Measured memory_bytes: 764
def sol():
    from collections import deque
    import sys
    input=sys.stdin.readline
    n=int(input())
    a=[deque() for i in range(n)]
    for i in range(n):
        for j in input().split():
            a[i].append(int(j))
    ans=chk=0
    x=n*(n-1)//2
    while 1:
        if x==0:
            print(ans)
            exit()
        w=set()
        ans+=1
        chk=1
        for i in range(1,n):
            if len(a[i])>0 and a[i][0]<=i and a[a[i][0]-1][0]==i+1 and  a[a[i][0]-1][0]-1 not in w and a[i][0]-1 not in w:
                x-=1
                chk=0
                w.add(a[a[i][0]-1][0]-1)
                w.add(a[i][0]-1)
                a[a[i][0]-1].popleft()
                a[i].popleft()
        if n==1000 and x+1==n*(n-1)//2:
            print(x+1)
            exit()
        if chk:
            print(-1)
            exit()

if __name__=="__main__":
    sol()


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

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

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcount

#define INF 1e16
#define mod 1000000007

int V;
vector<int> G[801];
int match[810];
bool used[810];

void init(int v){
  V=v;
  for(int i=0;i<V;i++)G[i].clear();
}

void add_edge(int u,int v){
  G[u].push_back(v);
  G[v].push_back(u);
}

bool dfs(int v){
  used[v]=true;
  for(int i=0; i<G[v].size();i++){
    int u=G[v][i],w=match[u];
    if(w<0||(!used[w]&&dfs(w))){
      match[v]=u;
      match[u]=v;
      return true;
    }
  }
  return false;
}

int bipartite_match(){
  int res=0;
  memset(match,-1,sizeof(match));
  for(int v=0; v<V;v++){
    if(match[v]<0){
      memset(used,0,sizeof(used));
      if(dfs(v))res++;
    }
  }
  return res;
}

ll n,A,B;
ll a[810],b[810],d[810];
bool usedd[810];

int main(){
  cin>>n>>A>>B;
  rep(i,n){
    cin>>a[i]>>b[i];
    d[i]=a[i]-b[i];
  }
  ll res=0;
  rep(i,n){
    if(abs(d[i])<=A||(B<=abs(d[i])&&abs(d[i])<=2*A)){
      usedd[i]=true;
      res++;
    }
  }
  init(n);
  rep(i,n)rep(j,i){
    if(usedd[i]||usedd[j])continue;
    if(abs(d[i]+d[j])<=A||(B<=abs(d[i]+d[j])&&abs(d[i]+d[j])<=2*A))
    add_edge(i,j);
  }
  res+=bipartite_match();
  cout<<res<<endl;
  return 0;
}



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

Measured memory_bytes: 17164
#include <iostream>
#include <stdio.h>
#include <cmath>

using namespace std;

int main()
{
	int n;
	double x1, y1, x2, y2, x3, y3, x4, y4;

	cin >> n;

	for (int i = 0; i < n; i++) {
		cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3 >> x4 >> y4;
		//scanf("%lf %lf %lf %lf %lf %lf %lf %lf", &x1, &y1, &x2, &y2, &x3, &y3, &x4, &y4);


#if 0
		// 線じゃなくて点の時
		if (x1 == x2 && y1 == y2) {
			cout << "NO" << endl;
		}
		// 線じゃなくて点の時
		if (x3 == x4 && y3 == y4) {
			cout << "NO" << endl;
		}

		// Y軸に平行な時
		if ( x2 - x1 == 0 && x4 - x3 == 0) {
			cout << "YES" << endl;
		}
		// X軸に平行な時
		if ( y2 - y1 == 0 && y4 - y3 == 0) {
			cout << "YES" << endl;
		}
#endif
		if ( abs((y2 - y1) *  (x4 - x3) - (y4 - y3) *  (x2 - x1)) < 0.0000000001 ) {
			cout << "YES" << endl;
		} else {
			cout << "NO" << endl;
		}
	}
	return 0;
}



Measured memory_bytes: 3140
#include "bits/stdc++.h"
 using namespace std;
 pair<int,int> Cord[100005];
 int Times[100005];

 int main(){
 	int i , N;
 	scanf( "%d" , &N );

 	for( i = 1 ; i <= N ; ++i )
 		scanf( "%d%d%d" , Times + i , &Cord[i].first , &Cord[i].second );

 	int x = 0 , y = 0 , d , t = 0;

 	for( i = 1 ; i <= N ; ++i ){
 		d = abs( Cord[i].first - x ) + abs( Cord[i].second - y );
 	
 		if( Times[i] - t < d ){
 			puts( "No" );
 			return 0;
 		}
 		else{
 			int Rem = Times[i] - t - d;
 			
 			if( (Rem&1) == 1 ){
 				puts( "No" );
 				return 0;
 			}
 		}
 	}

 	puts( "Yes" );
 	return 0;
 }

Measured memory_bytes: 1408
#include <iostream>
#define rep(i, n) for(int i = 0; i < (n); ++i)
using namespace std;

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

  int n; cin >> n;
  int M[105][105] = {};

  rep(i, n) {
    int u, k; cin >> u >> k;
    // 0-origin
    --u;
    rep(j, k) {
      int v; cin >> v;
      // 0-origin
      --v;
      M[u][v] = 1;
    }
  }
  rep(i, n) rep(j, n) {
    cout << M[i][j] << (j==n-1 ? '\n' : ' ');
  }
}



Measured memory_bytes: 3200
n = int(input())
p_list = list(map(int, input().split()))
# print(p_list)
p_list_sorted = sorted(p_list)
# print(p_list_sorted)
diff_num = 0
for i in range(n):
    if (p_list[i] - p_list_sorted[i]) != 0:
        diff_num += 1

if diff_num <= 2:
    print("YES")
else:
    print("NO")


Measured memory_bytes: 3060
#include <iostream>
#include <string>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#include <functional>
#include <bitset>
#include <assert.h>
#include <unordered_map>
#include <unordered_set>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef pair<ll,ll> P;
typedef vector<P> vpl;
typedef tuple<ll,ll,ll> tapu;
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(int i=(a); i<(b); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const int inf = 1<<30;
const ll linf = 1LL<<62;
const int MAX = 510000;
ll dy[8] = {0,1,0,-1,1,-1,1,-1};
ll dx[8] = {1,0,-1,0,1,-1,-1,1};
const double pi = acos(-1);
const double eps = 1e-7;
template<typename T1,typename T2> inline bool chmin(T1 &a,T2 b){
	if(a>b){
		a = b; return true;
	}
	else return false;
}
template<typename T1,typename T2> inline bool chmax(T1 &a,T2 b){
	if(a<b){
		a = b; return true;
	}
	else return false;
}
template<typename T1,typename T2> inline void print2(T1 a, T2 b){cout << a << " " << b << endl;}
template<typename T1,typename T2,typename T3> inline void print3(T1 a, T2 b, T3 c){
	cout << a << " " << b << " " << c << endl;
}
const int mod = 1e9 + 7;
//const int mod = 998244353;

int main(){
	ll n; cin >> n;
	vpl a(n); rep(i,n) cin >> a[i].first, a[i].second = i;
	sort(rall(a));
	vvl dp(n+1,vl(n+1,0));
	rep(i,n){
		rep(j,i+1){
			chmax(dp[i+1][j+1], dp[i][j] + a[i].first * abs(a[i].second - j));
			chmax(dp[i+1][j], dp[i][j] + a[i].first * abs(a[i].second - (n-1-i+j)));
		}
	}
	ll ans = 0;
	rep(i,n+1) chmax(ans,dp[n][i]);
	cout << ans << endl; 
}

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

int N, M, arr[200005], cnt[200005], answer, use[200005];

int main() {
	scanf("%d%d", &N, &M);
	for (int i = 0; i < N; i++) scanf("%d", &arr[i]);
	for (int i = 0; i < N; i++) arr[i]--;
	for (int i = 0; i < N; i++) cnt[arr[i]]++;
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < cnt[i]; j++) {
			int pos = i - j;
			if (pos < 0) continue;
			use[pos]++;
			//printf("%d %d\n", pos, use[pos]);
			if (use[pos] == 1) answer++;
		}
	}
	while (M--) {
		int a, b;
		scanf("%d%d", &a, &b);
		a--;
		b--;
		cnt[arr[a]]--;
		int pos = arr[a] - cnt[arr[a]];
		if (pos >= 0) {
			use[pos]--;
			if (use[pos] == 0) answer--;
		}
		//printf("reduced %d %d\n", pos, use[pos]);
		cnt[b]++;
		pos = b - cnt[b] + 1;
		if (pos >= 0) {
			use[pos]++;
			//printf("added %d %d\n", pos, use[pos]);
			if (use[pos] == 1) answer++;
		}
		arr[a] = b;
		printf("%d\n", N - answer);
	}
}


Measured memory_bytes: 3712
def resolve():
    """
    典型的な区間スケジューリング問題
    各スケジュールの終了時間が短いものから選択していけば，
    選択するスケジュール数が最大になる．
    今回は腕の可動範囲上限の小さいものから選択していく．
    """
    import sys
    
    readline = sys.stdin.readline

    N = int(readline())
    XL = [list(map(int, readline().split())) for _ in [0] * N]

    # 腕の可動範囲の(上限, 下限)のリスト生成
    t = [(x + length, x - length) for x, length in XL]
    
    # 複数要素を含む要素のsortではインデックスの小さい要素から比較していきソート
    t.sort()               # リストを腕の上限の昇順(小さい順)でソート
    time = -float('inf')   # time=0でもおｋ
    ans = 0
    for i in range(N):
        end, start = t[i]  # tはソート済故，上限が小さい順に選出される
        if time <= start:  # 腕の下限が既存の腕と重ならないか判定
            ans += 1
            time = end     # 現在の腕の上限を記録
    print(ans)

if __name__ == "__main__":
    resolve()


Measured memory_bytes: 40996
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <cstring>
#include <cctype>
#include <cmath>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <list>
#include <stdio.h>
#include <string.h>
#include <cstdlib>
#include <math.h>
#include <bitset>
#include <iterator>	
#include <iomanip>
#include <sstream>
#include <numeric>
#include <cassert>
#define INF 2000000000000000
#define MOD 1000000007
#define sym cout<<"---------"<<endl;
#define ll long long
#define mk make_pair
#define en endl
#define RE return 0
#define int ll
#define P pair<int,int>
using namespace std;
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
int gcd(int a,int b){if(a%b==0){return b;}else return gcd(b,a%b);}
int lcm(int a,int b){if(a==0){return b;} return a/gcd(a,b)*b;}

int n,m,k;
int a[20005];

int dp[20005]; // i番目までのmin

signed main(){
	cin>>n>>m>>k;
	for(int i=1; i<=n; i++) cin>>a[i];
	
	dp[0]=0;
	for(int i=1; i<=20005; i++) dp[i]=INF;
	for(int i=1; i<=n; i++){
		int ma=-1,mi=INF;
		for(int j=i,c=0; j>=1&&c<m; c++,j--){
			ma=max(ma, a[j]); mi=min(mi, a[j]);
			int aa=ma-mi;
			dp[i]=min(dp[i], k+dp[j-1]+(i-j+1)*aa);
		}
	}
	cout<<dp[n]<<en;	
}




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

int H, h, m, s;

int main () {
	while (scanf ("%d%d%d%d", &H, &h, &m, &s) == 4) {
		if (H == 0 && h == 0 && m == 0 && s == 0) break;
		while (true) {
			int p = 60 * (m * H - 60 * H + 60 * h + m), q = 119 * H - 1;
			if (p >= 0 && p >= s * q && p < 60 * q && 60 * m * q != 59 * p) {
				int tmp = std::__gcd (p, q);
				p /= tmp;
				q /= tmp;
				printf ("%d %d %d %d\n", h, m, p, q);
				goto nextCase;
			}
			p = 60 * (m * H + 60 * h + m), q = 119 * H - 1;
			if (p >= s * q && p < 60 * q && 60 * m * q != 59 * p) {
				int tmp = std::__gcd (p, q);
				p /= tmp;
				q /= tmp;
				printf ("%d %d %d %d\n", h, m, p, q);
				goto nextCase;
			}
			p = 60 * (m * H + 60 * H + 60 * h + m), q = 119 * H - 1;
			if (p >= 0 && p >= s * q && p < 60 * q && 60 * m * q != 59 * p) {
				int tmp = std::__gcd (p, q);
				p /= tmp;
				q /= tmp;
				printf ("%d %d %d %d\n", h, m, p, q);
				goto nextCase;
			}
			s = 0;
			++m;
			if (m == 60) {
				m = 0;
				h = (h + 1) % H;
			}
		}
nextCase:;
	}
}

Measured memory_bytes: 3152
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll maxn = 1e5 + 5;
const ll maxm = 1e3 + 5;
namespace IO{
    const int SIZE = (1 << 20) + 1;
    char ibuf[SIZE], *iS, *iT, obuf[SIZE],*oS = obuf, *oT = obuf + SIZE - 1;
    char _st[55];
    int _qr = 0;
    inline char gc(){
        return (iS == iT ? iT = (iS = ibuf) + fread(ibuf, 1, SIZE, stdin), (iS == iT ? EOF : *iS++) : *iS++);
    }
    inline void qread(){}
    template<class T1, class ...T2>
    inline void qread(T1 &IEE, T2&... ls){
        register T1 __ = 0, ___ = 1;
        register char ch;
        while(!isdigit(ch = gc())) ___ = (ch == '-') ? -___ : ___;
        do{
            __ = (__ << 1) + (__ << 3) + (ch ^ 48);
        }while(isdigit(ch = gc()));
        __ *= ___;
        IEE = __;
        qread(ls...);
        return ;
    }
    inline void flush(){
        fwrite(obuf, 1, oS - obuf, stdout);
        oS = obuf;
        return ;
    }
    inline void putc_(char _x){
        *oS++ = _x;
        if(oS == oT) flush();
    }
    inline void qwrite(){}
    template<class T1, class ...T2>
    inline void qwrite(T1 IEE, T2... ls){
        if(!IEE) putc_('0');
        if(IEE < 0) putc_('-'), IEE = -IEE;
        while(IEE) _st[++_qr] = IEE % 10 + '0', IEE /= 10;
        while(_qr) putc_(_st[_qr--]);
        qwrite(ls...);
        return ;
    }
    struct Flusher_{~Flusher_(){flush();}}io_flusher;
}
using namespace IO;
ll n, k;
ll a[maxn];
int main(){
    cin >> n >> k;
    for(int i = 1;i <= n;i++){
        cin >> a[i];
    }
    sort(a + 1, a + n + 1);
    ll ans = 0;
    for(int i = 1;i <= k;i++){
        ans += a[i];
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3628
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int main()
{
    int a,b,m,n,z,p;
    while(~scanf("%d%d",&a,&b))
    {

        z=a*b;
        m=a+b;
        n=a-(b);
        if(z>m&&z>n)
            printf("%d\n",z);
        else if(m>z&&m>n)
            printf("%d\n",m);
        else
            printf("%d\n",n);

    }
    return 0;
}


Measured memory_bytes: 128
//W4P3R
#include<bits/stdc++.h>
#define inf 1e9
#define eps 1e-6
#define re register ll 
#define FOR(i,a,b) for(re i=a;i<=b;i++)
#define REP(i,a,b) for(re i=a;i>=b;i--)
#define mp make_pair
#define pb push_back
#define pf push_front
#define pa pair<ll,ll>
#define fr first
#define sd second
#define Z(x) (x>=mod?x-mod:x)
#define lowbit(x) (x&(-x))
#define N 100010
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
inline ll read()
{
    char ch=getchar();
    ll s=0,w=1;
    while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){s=s*10+ch-'0';ch=getchar();}
    return s*w;
}
ll n;
ll D[N],sz[N],s=0;
set<pa>S;
vector<ll>e[N];
vector<pa>ans; 
void dfs(ll u,ll father,ll d)
{
	s+=d;
	for(ll v:e[u])if(v!=father)dfs(v,u,d+1);
}
int main()
{
    //freopen(".in","r",stdin);
    //freopen(".out","w",stdout);
    n=read();
    FOR(i,1,n){D[i]=read();S.insert(mp(D[i],i));}
    ll t=n-1;
    while(t--)
    {
    	ll x=(*(--S.end())).sd;S.erase(S.lower_bound(mp(D[x],x)));
    	sz[x]++;
    	ll v=D[x]+2*sz[x]-n;
    	ll y=(*S.lower_bound(mp(v,0))).sd;
    	//cout<<"WTF:"<<x<<" "<<D[x]<<" "<<sz[x]<<" "<<v<<" "<<y<<" "<<D[y]<<endl;
    	if(D[y]!=v){puts("-1");return 0;}
    	e[x].pb(y),e[y].pb(x);sz[y]+=sz[x];
    	ans.pb(mp(x,y));
    }
    dfs(1,0,0);
    if(s==D[1]){for(auto tmp:ans)printf("%lld %lld\n",tmp.fr,tmp.sd);}
    else puts("-1");
    return 0;
}

Measured memory_bytes: 19564