akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <algorithm>
using namespace std;
const int mod = 1000000007;
int a[110];
int pow(int x, int p) {
	if (p == 0) return 1;
	if (p == 1) return x;
	long long res = pow(x, p / 2);
	res = res * res % mod;
	if (p & 1) {
		res = res * x % mod;
	}
	return res;
}
int dp[110][110][2][2][2];
void add(int &x, long long v) {
	x += v;
	if (x >= mod) x -= mod;
}
void go(int l, int r, int b) {
	int h = *min_element(a + l, a + r);
	for (int i = l; i < r; i++) {
		if (a[i] == h) {
			if (i == l) {
				dp[l][i+1][0][0][0] = 1;
				dp[l][i+1][1][1][0] = 1;
			} else {
				for (int x = 0; x < 2; x++) {
					for (int y = 0; y < 2; y++) {
						for (int z = 0; z < 2; z++) {
							for (int u = 0; u < 2; u++) {
								add(dp[l][i+1][x][u][z|(y==u)], dp[l][i][x][y][z]);
							}
						}
					}
				}
			}
			continue;
		}
		int j = i;
		while (a[j] > h) ++j;
		go(i, j, h);
		if (i > l) {
			for (int x = 0; x < 2; x++) {
				for (int y = 0; y < 2; y++) {
					for (int z = 0; z < 2; z++) {
						long long d = dp[i][j][x][y][z];
						for (int u = 0; u < 2; u++) {
							for (int v = 0; v < 2; v++) {
								for (int w = 0; w < 2; w++) {
									add(dp[l][j][u][y][z|w|(v==x)], ((long long)dp[l][i][u][v][w] * d) % mod);
									if (!z) {
										add(dp[l][j][u][y^1][z|w|(v==(x^1))], ((long long)dp[l][i][u][v][w] * d) % mod);
									}

								}
							}
						}
					}
				}
			}
		} else {
			for (int x = 0; x < 2; x++) {
				int s = dp[l][j][x][0][0];
				add(s, dp[l][j][x^1][1][0]);
				dp[l][j][x][0][0] = dp[l][j][x^1][1][0] = s % mod;
				swap(dp[l][j][x][0][1], dp[l][j][x^1][1][1]);
			}
		}
		i = j - 1;
	}
	if (h - b == 1) return;
	int pa = (h - b - 1) & 1;
	long long m = pow(2, h - b - 2);
	for (int i = 0; i < 2; i++) {
		int s = dp[l][r][i][0][0];
		add(s, dp[l][r][i^1][1][0]);
		dp[l][r][i][0][0] = dp[l][r][i^1][1][0] = m * s % mod;
		swap(dp[l][r][i][0][1], dp[l][r][i^1][1][1]);
	}
}
int main() {
	int n;
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		scanf("%d", &a[i]);
	}
	go(0, n, 0);
	int ans = 0;
	for (int x = 0; x < 2; x++) {
		for (int y = 0; y < 2; y++) {
			for (int z = 0; z < 2; z++) {
				add(ans, dp[0][n][x][y][z]);
			}
		}
	}
	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 512
'''
研究室PCでの解答
'''
import math
#import numpy as np
import queue
import bisect
from collections import deque,defaultdict
import heapq as hpq
from sys import stdin,setrecursionlimit
#from scipy.sparse.csgraph import dijkstra
#from scipy.sparse import csr_matrix
ipt = stdin.readline
setrecursionlimit(10**7)
mod = 10**9+7

def main():
    n,k = map(int,ipt().split())
    d = set(map(int,ipt().split()))
    for i in range(n,10**5+1):
        ls = len(str(i))
        for j in range(ls):
            if int(str(i)[j]) in d:
                break
            if j == ls-1:
                print(i)
                exit()

    return None

if __name__ == '__main__':
    main()


Measured memory_bytes: 75112
#include <stdio.h>
#include <iostream>
#include <cstdlib>
#include <iomanip>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <limits>
#include <numeric>
#include <queue>
#include <set>
#include <bitset>
#include <map>

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<char> vc;
typedef queue<int, int> qii;
typedef pair<int, int> pii;

#define PI 3.14159265359
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repz(i,n) rep(i,0,n)

//int型を受け取ってその桁数を返す
int check_digits(int n) {
	int digits = 0;
	while (n != 0) {
		n /= 10;
		digits++;
	}
	return digits;
}


//最大公約数を返す関数
int gcd(int n, int m) {
	while (n != 0) {
		if (n < m) swap(n, m);
		n = n % m;
	}
	return m;
}


//2点間の距離を返す
float dis(int x1, int y1, int x2, int y2) {
	return sqrt(pow(abs(x1 - x2), 2) + pow(abs(y1 - y2), 2));
}


int main() {
	int n, x,ans=0;
	cin >> n >> x;
	vi m(n);
	repz(i, n)cin >> m[i];
	sort(m.begin(), m.end());
	
	//とりあえず全部作る
	repz(i, n) {
		x -= m[i];
		ans++;
	}

	ans += x / m[0];
	cout << ans << endl;


	system("pause");
	return 0;
}

Measured memory_bytes: 504
#include <stdio.h>
#include <math.h>
#include <stdbool.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>

int main(){
	long long int n, m, i, j;
	scanf("%lld", &n);
	scanf("%lld", &m);
	if(n==1 && m==1){
		printf("%lld\n", n*m);
	}
	else if(n==1 || m==1){
		printf("%lld\n", n*m-2);
	}
	else {
		printf("%lld\n", (n-2)*(m-2));
	}
	return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = 1e9+7,MAX = 1e5;

class dice
{
	int ue,mae,migi,hidari,sita,usiro;
	public:
	dice(int a,int b,int c,int d,int e,int f)
	{
		ue = a;
		mae = b;
		migi = c;
		hidari = d;
		sita = f;
		usiro = e;
	}
	void N()
	{
		swap(ue,mae);
		swap(mae,sita);
		swap(sita,usiro);
	}
	void S()
	{
		swap(ue,usiro);
		swap(usiro,sita);
		swap(sita,mae);
	}
	void E()
	{
		swap(ue,hidari);
		swap(hidari,sita);
		swap(sita,migi);
	}
	void W()
	{
		swap(ue,migi);
		swap(migi,sita);
		swap(sita,hidari);
	}
	int top()
	{
		return ue;
	}
	int right()
	{
		return migi;
	}
	int front()
	{
		return mae;
	}
	void turn_right()
	{
		swap(mae,migi);
		swap(migi,usiro);
		swap(usiro,hidari);
	}
	int serch_turn(int i)
	{
		while(1)
		{
			turn_right();
			if(i==front())
			{
				return right();
			}
		}
	}
};



int main()
{
	int a,b,c,d,e,f;
	cin >> a >> b >> c >> d >> e >>f;
	dice D(a,b,c,d,e,f);
	int n;
	cin >> n;
	for(int i = 0;i<n;i++)
	{
		int x,y;
		cin >> x >> y;
		
		//cout<<' '<<D.top()<<' '<<D.front()<<endl;
		if(D.top()==x)
		{
			cout<<D.serch_turn(y)<<endl;
			continue;
		}
		D.N();
		if(D.top()==x)
		{
			cout<<D.serch_turn(y)<<endl;
			continue;
		}
		D.N();
		if(D.top()==x)
		{
			cout<<D.serch_turn(y)<<endl;
			continue;
		}
		D.N();
		if(D.top()==x)
		{
			cout<<D.serch_turn(y)<<endl;
			continue;
		}
		D.N();
		D.E();
		if(D.top()==x)
		{
			cout<<D.serch_turn(y)<<endl;
			continue;
		}
		D.W();
		D.W();
		if(D.top()==x)
		{
			cout<<D.serch_turn(y)<<endl;
			continue;
		}
		
		
	}
	return 0;
}


Measured memory_bytes: 3108
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <cmath>
#include <climits>
#include <iomanip>
#include <set>
#include <map>
using namespace std;
typedef long long ll;
int main(){
  ll n = 0;
  cin >> n;
  for(int i = n;i < 1000;i++){
    if(i % 111 == 0){
      cout << i << endl;
      return 0;
    }
  }
}


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

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();

		String S = "";

		boolean ans = false;

		for(int i=0;i<N;i++) {

			S = sc.next();

			if(S.equals("Y")) {

				ans = true;

				break;
			}
		}

		if(ans) System.out.println("Four");

		else System.out.println("Three");
	}

}


Measured memory_bytes: 21844
import Control.Applicative
import Control.Monad
import Data.List

-- Top, Front, Right. Back, Left, Bottom
-- X: Right-Left, Y: Front-Back, Z: Top-Bottom
type Dice a = (a,a,a,a,a,a)

rollPX :: Dice a -> Dice a
rollPX (tp,fr,rg,bk,lf,bt) = (fr,bt,rg,tp,lf,bk)

rollNX :: Dice a -> Dice a
rollNX (tp,fr,rg,bk,lf,bt) = (bk,tp,rg,bt,lf,fr)

rollPY :: Dice a -> Dice a
rollPY (tp,fr,rg,bk,lf,bt) = (lf,fr,tp,bk,bt,rg)

rollNY :: Dice a -> Dice a
rollNY (tp,fr,rg,bk,lf,bt) = (rg,fr,bt,bk,tp,lf)

rollPZ :: Dice a -> Dice a
rollPZ (tp,fr,rg,bk,lf,bt) = (tp,rg,bk,lf,fr,bt)

rollNZ :: Dice a -> Dice a
rollNZ (tp,fr,rg,bk,lf,bt) = (tp,lf,fr,rg,bk,bt)

rollX :: Int -> Dice a -> Dice a
rollX n = if n >= 0 then (foldl (.) id (replicate (n `mod` 4) rollPX)) else (foldl (.) id (replicate ((-n) `mod` 4) rollNX))

rollY :: Int -> Dice a -> Dice a
rollY n = if n >= 0 then (foldl (.) id (replicate (n `mod` 4) rollPY)) else (foldl (.) id (replicate ((-n) `mod` 4) rollNY))

rollZ :: Int -> Dice a -> Dice a
rollZ n = if n >= 0 then (foldl (.) id (replicate (n `mod` 4) rollPZ)) else (foldl (.) id (replicate ((-n) `mod` 4) rollNZ))

allRolls :: Dice a -> [Dice a]
allRolls dice = tail $ scanl (\d f -> f d) dice  (concatMap (\f -> (rollPZ . f) : replicate 3 rollPZ) (take 6 (cycle [rollPX, rollPY])))


dTop (tp,_,_,_,_,_) = tp
dBottom (_,_,_,_,_,bt) = bt
dRight (_,_,rg,_,_,_) = rg
dLeft (_,_,_,_,lf,_) =lf
dFront (_,fr,_,_,_,_) = fr
dBack (_,_,_,bk,_,_) = bk


main = do
  [d1,d2,d3,d4,d5,d6] <- map read . words <$> getLine :: IO [Int]
  q <- readLn :: IO Int
  
  let
    dice = (d1,d5,d3,d2,d4,d6)
    allrolls = allRolls dice

  replicateM_ q $ do
    [a,b] <- map read . words <$> getLine :: IO [Int]

    let Just (_,_,rg,_,_,_) = find (\d -> dTop d == a && dBack d == b) allrolls
    print rg
  



Measured memory_bytes: 4052
#include <math.h>
#include <algorithm>
#include <iostream>
#include <map>
#include <ostream>
#include <set>
#include <tuple>
#include <vector>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;

typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

typedef int _lcint;
#define REP(i, n) for (_lcint i = 0; i < n; i++)
#define FOR(i, a, b) for (_lcint i = (_lcint)(a); i < (_lcint)(b); i++)
#define FORREV(i, a, b) for (_lcint i = (_lcint)(b)-1; i >= (_lcint)(a); i--)
#define DEBUG(x) cout << #x << ": " << x << endl;
#define DEBUG_VEC(v)  \
  cout << #v << ": "; \
  REP(i, v.size()) cout << " " << v[i] << endl;

#define ALL(a) (a).begin(), (a).end()
#define CHMIN(a, b) a = min((a), (b))
#define CHMAX(a, b) a = max((a), (b))

// permutation
ll mPn(ll m, ll n) {
  ll a = 1;
  REP(i, n) { a *= m - i; }
  return a;
}

// excrametion
ll exc(ll m) {
  ll a = 1;
  FOR(i, 1, m) { a *= i + 1; }
  return a;
}

// combination
ll mCn(ll m, ll n) {
  ll a = 1, b = 1;
  REP(i, n) {
    a *= m - i;
    b *= n - i;
  }
  return a / b;
}

// 最大公約数を求める 条件
ll eculidean(ll a, ll b) {
  ll tmp;
  if (a < b) {
    tmp = a;
    a = b;
    b = tmp;
  }

  ll r = a % b;
  while (r != 0) {
    a = b;
    b = r;
    r = a % b;
  }

  return b;
}

int main() {
  int A, P;
  cin >> A >> P;
  cout << floor((A * 3 + P) / 2) << endl;

  return 0;
}


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

int main(){
    long N;
    cin >> N;
    vector<long> A(N);
    for(auto& i : A)cin >> i;
    nth_element(A.begin(), A.end() - 1, A.end());
    long m = A[N - 1];
    nth_element(A.begin(), A.begin(), A.end() - 1, [&m](auto a, auto b){return abs(2 * a - m) < abs(2 * b - m);});
    cout << A[N - 1] << " " << A[0] << endl;
}

Measured memory_bytes: 1024
#include <iostream>
#include <fstream>
#include <string.h>
#include <math.h>

using namespace std;

int main(){
    int N;
    string S,T,U;
    cin >> N;
    cin >> S;
    cin >> T;
    for(int i = 0; i < N; i++){
        U.push_back(S[i]);
        U.push_back(T[i]);
    }
    cout << U << endl;
}


Measured memory_bytes: 256
//abc064_b.cpp
//Tue Oct 30 22:15:03 2018

#include <iostream>
#include <string>
#include <queue>
#include <unordered_map>
#include <vector>
#include <algorithm>
#include <math.h>
#define INTINF 2147483647
#define LLINF 9223372036854775807
using namespace std;
using ll=long long;
typedef pair<int,int> P;

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

	sort(a,a+n);

	cout << a[n-1] - a[0]<< endl;
//	printf("%.4f\n",ans);
}

Measured memory_bytes: 256
//#include<bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<set>

/*
#include<boost/multiprecision/cpp_int.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/rational.hpp>
namespace mp = boost::multiprecision;
using Real = mp::number<mp::cpp_dec_float<1024>>;
using Bint = mp::cpp_int;
*/

using namespace std;

#define int long long
#define REP(i,s,e) for((i)=(s);(i)<(e);(i)++)
#define RREP(i,s,e) for((i)=((s)-1);(i)>=(e);(i)--)
#define FOR(i,n) for((i)=(0);(i)<(n);(i)++)
#define RFOR(i,n) for((i)=((n)-1);(i)>=(0);(i)--)
#define MOD 1000000007

signed main(){

    int N;
    cin>>N;
    while(N!=0){
        if(N%10==7){
            cout<<"Yes"<<endl;
            return 0;
        }
        N/=10;
    }
    cout<<"No"<<endl;
}



Measured memory_bytes: 3096
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10**6)
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI_(): return list(map(lambda x: int(x)-1, input().split()))
def LF(): return list(map(float, input().split()))
def LC(): return [c for c in input().split()]
def LLI(n): return [LI() for _ in range(n)]
def NSTR(n): return [input() for _ in range(n)]

def array2d(N, M, initial=0):
    return [[initial]*M for _ in range(N)]

def copy2d(orig, N, M):
    ret = array2d(N, M)
    for i in range(N):
        for j in range(M):
            ret[i][j] = orig[i][j]
    return ret


INF = float("inf")
MOD = 10**9 + 7

class BIT:
    # 1-index
    def __init__(self, n):
        self.size = n
        self.tree = [0] * (n + 1)

    def sum(self, i):
        s = 0
        while i > 0:
            s += self.tree[i]
            i -= i & -i
        return s

    def add(self, i, x):
        while i <= self.size:
            self.tree[i] += x
            i += i & -i


def main():
    N, Q = MAP()
    c = [None]+LI()
    lri = [(l, r, i) for i, (l, r) in enumerate(LLI(Q))]
    ans = [0]*Q

    # クエリは右端でソート
    lri.sort(key=lambda x: x[1])
    good_ball = [-1]*(N+1)
    acc = BIT(N)

    # 1-indexで統一したい
    curr = 1
    # 始めの一つの更新
    acc.add(curr, 1)
    good_ball[c[1]] = 1
    for l, r, i in lri:
        # currがrに到達するまで、良い玉の集合を更新する。
        while r > curr:
            curr += 1
            cc = c[curr]
            # 良い玉が既にあれば、bitから除く
            if good_ball[cc] != -1:
                acc.add(good_ball[cc], -1)
            acc.add(curr, 1)
            # 良い玉の位置を更新する
            good_ball[cc] = curr
        # print(l, r, curr, dict(good_ball))
        # print([acc.sum(i+1) for i in range(N)])

        # クエリに答える
        # [l, r]に対する答えはsum(r)-sum(l-1)
        ans[i] = acc.sum(r)-acc.sum(l-1)

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

    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 259012
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <climits>
using namespace std;

using Graph = vector<vector<int>>;

int dfs(const Graph& g, int p, int s, int dis){
  if(dis == 0) return 1;

  int cnt = 0;
  for(int i=0; i<g[s].size(); i++){
    int nxt = g[s][i];
    if(nxt == p) continue;
    cnt += dfs(g, s, nxt, dis-1);
  }

  return cnt + 1;
}

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

  Graph g(n);
  vector<pair<int, int>> e(n-1);

  for(int i=0; i<n-1; i++){
    int a, b; cin >> a >> b;
    a--, b--;

    g[a].push_back(b);
    g[b].push_back(a);

    e[i] = {a, b};
  }

  int cnt = 0;
  if(k % 2 == 0){
    for(int i=0; i<n; i++){
      cnt = max(cnt, dfs(g, -1, i, k/2));
    }
  }
  else{
    for(int i=0; i<n-1; i++){
      int l = (k-1) / 2;
      int a = e[i].first, b = e[i].second;
      cnt = max(cnt, dfs(g, a, b, l) + dfs(g, b, a, l));
    }
  }

  cout << n - cnt << endl;

  return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = n - 1; i >= 0; i--)
using namespace std;
using Graph = vector<vector<int>>;
#define MOD 1000000007
#define MOD2 998244353
#define INF ((1<<30)-1)
#define LINF (1LL<<60)
#define EPS (1e-10)
typedef long long ll;
typedef pair<ll, ll> P;
long double PI = acos(-1);



int main(){
    double r;
    cin >> r;
    cout << fixed << setprecision(10) << 2 * r * PI << endl;
    return 0;
}

Measured memory_bytes: 3776
/**
 *      ABC 72 C
 *      author  : kyomukyomupurin
 *      created : 2018-09-06 10:01:11
**/

#include <bits/stdc++.h>
using namespace std;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int N; cin >> N;
    int a[N];
    for (int i = 0; i < N; ++i) {
        cin >> a[i];
    }
    int count[100000 + 10] = {};
    for (int i = 0; i < N; ++i) {
        count[a[i]]++;
    }

    int max = 1;
    for (int i = 0; i < N; ++i) {
        if (count[i] + count[i + 1] + count[i + 2] > max){
            max = count[i] + count[i + 1] + count[i + 2];
        }        
    }
    cout << max << endl;

    return 0;
}

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

using namespace std;

int main()
{
    long long x, k, d;
    cin >> x >> k >> d;
    if(x < 0)
        x *= -1;
    long long factor = x/d;
        
    if(k >= factor){
        k-=factor;
        x -= factor*d;
        if(k % 2)
            x -= d;
    }
    else{
        x -= k*d;
    }
    cout << abs(x) << '\n';
    return 0;
}


Measured memory_bytes: 3680
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long LL;
typedef long double LD;

LL inf = 1000000000000;
LL mod = 1000000007;

vector<string> vs;

void stringy (string s, const LL n, LL k, LL d, LL m) {
	if (k == n) {
		vs.push_back(s);
	}
	else {
		for (LL i = 0; i <= d; ++i) {
			s[k] = (char)('a'+i);
			m = max(m, i);
			stringy(s, n, k+1, m+1, m);
		}
	}
}

int main()
{
	LL n;
	cin >> n;


	string s(n, ' ');
	
	stringy(s, n, 0, 0, 0);
	for (auto e : vs) {
		cout << e << "\n";
	}

}

Measured memory_bytes: 7796
#include<iostream>
using namespace std;
int main(){
  int D;
  cin >>D;
  if(D == 22) cout <<"Christmas" <<" " <<"Eve" <<" " <<"Eve" <<" " <<"Eve" <<endl;
  if(D == 23) cout <<"Christmas" <<" " <<"Eve" <<" " <<"Eve" <<endl;
  if(D == 24) cout <<"Christmas" <<" " <<"Eve" <<"" <<endl;  
  if(D == 25) cout <<"Christmas" <<endl;
  
   return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <chrono>
#include <climits>
#include <cmath>
#include <complex>
#include <cstring>
#include <deque>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <cstdint>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
#define MP make_pair
#define PB push_back
#define inf 1000000007
#define mod 1000000007
#define rep(i,n) for(int i = 0; i < (int)(n); ++i)
#define all(x) (x).begin(),(x).end()

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}
 
template<class T> inline bool chmax(T &a, T b){
    if(a<b){
        a = b;
        return true;
    }
    return false;
}

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

int main(){
    int n,q;
    cin >> n >> q;
    vector<int>a(n);
    vector<int>s(n+1);
    vector<int>p(n+1);
    rep(i,n){
        cin >> a[i];
        s[a[i]]++;
    }
    rep(i,n+1){
        for(int j=i;j>=max(0,i-s[i]+1);j--){
            p[j]++;
        }
    }
    int sm = 0;
    for(int i=1;i<=n;i++){
        if(p[i]==0)sm++;
    }
    rep(zz,q){
        int x,y;
        cin >> x >> y;
        x--;
        int pre = a[x];
        a[x] = y;
        int id = pre-s[pre]+1;
        if(id>0){
            if(p[id]==1){
                sm++;
            }
            p[id]--;
        }
        s[pre]--;
        s[y]++;
        int nid = y-s[y]+1;
        if(nid>0){
            if(p[nid]==0){
                sm--;
            }
            p[nid]++;
        } 
        cout << sm << "\n";
    }
    return 0;
}

Measured memory_bytes: 4472
#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() {
  ll n;
  cin >> n;
  ll ans = n * (n - 1) / 2;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
int main(){
    vector<string> card(3);
    for(int i=0; i<3; i++)
        cin>>card[i];
    int n=0;
    while(1){
        if(card[n].empty()){
            printf("%c",'A'+n);
            return 0;
        }
        int t=card[n][0]-'a';
        card[n].erase(begin(card[n]));
        n=t;
    }
}

Measured memory_bytes: 256
/* ex7_1
   tamayama */

#include<stdio.h>
#include<stdlib.h>

typedef struct{    //point型の定義
    int x_elem;
    int y_elem;
}point;

point shift_point(point a,point b){    //２点間の距離から次の点を求める関数
    point c;
    int x_dist,y_dist;

    x_dist = b.x_elem - a.x_elem;
    y_dist = b.y_elem - a.y_elem;

    c.x_elem = b.x_elem - y_dist;
    c.y_elem = b.y_elem + x_dist;
    return c;
}

int main(void){
    point P1,P2,P3,P4;

    scanf("%d %d %d %d",&P1.x_elem,&P1.y_elem,&P2.x_elem,&P2.y_elem);
    P3 = shift_point(P1,P2);
    P4 = shift_point(P2,P3);
    printf("%d %d %d %d",P3.x_elem,P3.y_elem,P4.x_elem,P4.y_elem);
    return 0;
}

Measured memory_bytes: 1732
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;
#define pb push_back
#define all(v) (v).begin(), (v).end()
#define debug(x) cout<<#x<<" = "<<(x)<<endl
#define debugv(v) do{for(auto x:(v)) cout<<x<<","; cout<<endl;}while(0)

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

  vi dp; //i番目の色で塗っている数字の最大値

  int a;
  for(int i=0; i<N; i++){
    cin>>a;
    auto itr = upper_bound(all(dp), a, [](int a, int b){
      return a > b;
    });
    if(itr!=dp.end()){
      *itr = a;
    }else{
      dp.pb(a);
    }
    //debug(dp.size());
    //debugv(dp);
  }

  cout<<dp.size()<<endl;
}

Measured memory_bytes: 892
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a, b, c, d;
	scanf("%d%d%d%d", &a, &b, &c, &d);
	while (true)
	{
		c -= b;
		if (c <= 0)
			break;
		a -= d;
		if (a <= 0)
			break;
	}
	if (c <= 0)
		puts("Yes");
	else
		puts("No");
	return 0;
}

Measured memory_bytes: 3760
//#define local
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define rep(i,n); for(long long i = 0;i < (n);i++)
using ll = long long;
using P = pair<long long,long long>;
template <class T> using vec = vector<T>;
#ifdef local
#include "debug.cpp"
#else
#define debug(...)
#endif

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    //cout << fixed << setprecision(10);
    bool x; cin >> x;
    cout << !x << endl;
}


Measured memory_bytes: 3608
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<list>
#include<set>
#include<string>
using namespace std;
int gcd(int a, int b) {
	int c = a % b;
	while (c != 0) {
		a = b;
		b = c;
		c = a % b;
	}
	return b;
}
struct UnionFind {
	vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

	UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
		for (int i = 0; i < N; i++) par[i] = i;
	}

	int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
		if (par[x] == x) return x;
		return par[x] = root(par[x]);
	}

	void unite(int x, int y) { // xとyの木を併合
		int rx = root(x); //xの根をrx
		int ry = root(y); //yの根をry
		if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
		par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
	}

	bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
		int rx = root(x);
		int ry = root(y);
		return rx == ry;
	}
};
typedef long long ll;

const ll M = 998244353;

vector<ll> fac(300001); //n!(mod M)
vector<ll> ifac(300001); //k!^{M-2} (mod M)

ll mpow(ll x, ll n) {
	ll ans = 1;
	while (n != 0) {
		if (n & 1) ans = ans * x % M;
		x = x * x % M;
		n = n >> 1;
	}
	return ans;
}
ll comb(ll a, ll b) {
	if (a == 0 && b == 0)return 1;
	if (a < b || a < 0)return 0;
	ll tmp = ifac[a - b] * ifac[b] % M;
	return tmp * fac[a] % M;
}
// mod. m での a の逆元 a^{-1} を計算する
long long modinv(long long a) {
	long long b = M, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= M;
	if (u < 0) u += M;
	return u;
}
int main() {
	int a, b, c;
	cin >> a >> b >> c;
	cout << min(min(a + b, b + c), c + a) << endl;
}

Measured memory_bytes: 4992
def binarySearch(key):
    left = 0
    right = n
    while left < right:
        mid = (left + right) // 2
        if key == A[mid]: return 1
        if key > A[mid]: left = mid + 1
        elif key < A[mid]: right = mid
    return 0

n = int(input())
A = list(map(int,input().split()))
input()
print(sum(binarySearch(e) for e in map(int,input().split())))


Measured memory_bytes: 16716
n = int(input())
a = []
for _ in range(n):
  a_ = int(input())
  a.append(a_)

ans = 0
c = 1
for i in range(n):
  c = a[c-1]
  ans += 1
  if c == 2:
    print(ans)
    exit()
print(-1)

Measured memory_bytes: 12816
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    char c;
    std::cin >> c;
    if ( c == 'a' ){
        std::cout << "vowel" << std::endl;
    }
    else if ( c == 'i' ){
        std::cout << "vowel" << std::endl;
    }
    else if ( c == 'u' ){
        std::cout << "vowel" << std::endl;
    }
    else if ( c == 'e' ){
        std::cout << "vowel" << std::endl;
    }
    else if ( c == 'o' ){
        std::cout << "vowel" << std::endl;
    }
    else {
        std::cout << "consonant" << std::endl;
    }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define fr(i,a,b) for(ll i=a;i<=b;i++)
#define ll long long
#define pb push_back
#define endl "\n"
#define mod 1000000007
using namespace std;

int main()
{
    ll n;
    cin>>n;
    unordered_set<string>st;
    for(int i=1;i<=n;i++)
    {
    	string s;
    	s.clear();
		cin>>s;
    	st.insert(s);
	}
	cout<<(st.size())<<endl;
}

Measured memory_bytes: 17680
#include "bits/stdc++.h"
 
typedef long long ll;
#define int ll
#define fi first
#define se second
#define SORT(a) sort(a.begin(),a.end())
#define rep(i,n) for(int i = 0;i < (n) ; i++) 
#define REP(i,n) for(int i = 0;i < (n) ; i++) 
#define MP(a,b) make_pair(a,b)
#define pb(a) push_back(a)
//#define INF LLONG_MAX/2

using namespace std;

int MOD = 1000000007;
ll kaijo(int x){
    if(x == 0) return 1;
    return x*kaijo(x-1);
}

#define MAX_V 210 //100を適宜変える
int INF = 12345678910LL;//INFの入力忘れない
int cost[MAX_V][MAX_V];//cost[u][v] は　u -> v のコスト
int d[MAX_V];//頂点sからの最短距離 
bool used[MAX_V];//すでに使われたかのフラグ
int V;//頂点数

void dijkstra(int s){
    fill(d+1,d+V+1,INF);
    fill(used+1,used+V+1,false);
    d[s] = 0;

    while(true){
        int v = -1;
        for(int u = 1;u <= V;u++){
            if(!used[u] && (v == -1 || d[u] < d[v])) v = u;
        }
        if(v == -1) break;
        used[v]  = true;
        for(int u=1;u <= V;u++){
            d[u] = min(d[u],d[v] + cost[v][u]);
        }
    }
}

signed main(){
    int N,M,R;
    cin >> N >> M >> R;
    V = N;
    vector<int> r(10);
    rep(i,R) cin >> r[i];
    int m[10][10];
  	rep(i,N) rep(j,N)cost[i+1][j+1] = INF;

    rep(i,M){
        int a,b,c;
        cin >> a >> b >> c;
        cost[a][b] = c;
        cost[b][a] = c;
    }
    rep(i,N) cost[i+1][i+1] = 0;

    rep(i,R){
        dijkstra(r[i]);
        rep(j,R) m[i][j] = d[r[j]];
    }

    rep(i,R){
         rep(j,R) cerr << m[i][j];
         cerr << endl;
    }
    
    int ans = 100000000000;
    int num = kaijo(R);
    vector<int> a(R);
    rep(i,R) a[i] = i;
    rep(i,num){
        int c = 0;
        for(int j = 0;j < R-1;j++){
            c += m[a[j]][a[j+1]];
        }
        ans = min(ans,c);
        next_permutation(a.begin(),a.end());
    }
    cout << ans << endl;
  
  return 0;
}
// g++ -std=c++14 code1.cpp
// rm -r -f test;oj dl 

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define rrep(i,n) for(int i=1;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int inf = 1001001001;
const int mod = 1000000007;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int a, b, c, d;
	cin >> a >> b >> c >> d;
	while (1) {
		c -= b;
		if (c <= 0) {
			cout << "Yes" << endl;
			break;
		}
		a -= d;
		if (a <= 0) {
			cout << "No" << endl;
			break;
		}
	}
	return 0;
}


Measured memory_bytes: 3652
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Queue;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int k = sc.nextInt();
		List<Double> list = new ArrayList<>();
		for (int i = 0; i < n; i++) {
			list.add(p(sc.nextDouble()));
		}
		sc.close();

		List<Double> list2 = new ArrayList<>();
		Queue<Double> q = new ArrayDeque<>();
		Double sum = 0d;
		for (int i = 0; i < k; i++) {
			q.add(list.get(i));
			sum += list.get(i);
		}
		list2.add(sum);
		for (int i = k; i < n; i++) {
			Double temp = list.get(i);
			sum = sum - q.poll() + temp;
			q.add(temp);
			list2.add(sum);
		}

		System.out.println(Collections.max(list2));
	}

	public static Double p(Double num) {
		return ((1d + num) * (num / 2d)) / num;
	}
}


Measured memory_bytes: 162696
//** aman**/
#include<bits/stdc++.h>
#define int          long long
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define dl          double
#define hell        1000000007
#define endl        '\n'
#define rep(i,a,b) for(int i=a;i<b;i++)
#define lb lower_bound
#define ub upper_bound
#define bs          binary_search
#define ios         ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
using namespace std;
int a[405],p[405];
int dp[405][405];
int fun(int l,int r){
	if(l==r)return 0;
	if(dp[l][r]!=-1)return dp[l][r];
	int ans=1e17;
	for(int i=l;i<r;i++){
		ans=min(ans,fun(l,i)+fun(i+1,r)+p[r]-p[l-1]);
	}
	dp[l][r]=ans;
	return ans;
}
signed main(){
	int n;cin>>n;
	for(int i=1;i<=n;i++)cin>>a[i];
	a[0]=0;p[0]=0;
	for(int i=1;i<=n;i++)p[i]=p[i-1]+a[i];
	//for(int i=1;i<=n;i++)cout<<p[i]<<" ";cout<<endl;
	memset(dp,-1,sizeof(dp));
	cout<<fun(1,n)<<endl;
}

Measured memory_bytes: 1536
#include <iostream>
#include <queue>
#define MAX 100
#define INF 2000000
#define WHITE 0
#define GRAY 1
#define BLACK 2

using namespace std;

int n;
int color[MAX+1];
int m[MAX+1][MAX+1];
int d[MAX+1];

void bfs(int s){
    queue<int> q;
    int u, v;
    for(u = 1; u <= n; u++){
        color[u] = WHITE;
        d[u] = INF;
    }
    color[s] = GRAY;
    d[s] = 0;
    q.push(s);
    while(!q.empty()){
        u = q.front();
        q.pop();
        for(v = 1; v <= n; v++){
            if(m[u][v] == 0 || d[v] != INF) continue;
            if(color[v] == WHITE){
                color[v] = GRAY;
                d[v] = d[u] + 1;
                q.push(v);
            }
        }
        color[u] = BLACK;
    }
}

int main(){
    int k, u, v, i, j;
    
    cin >> n;

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

    for(i = 1; i <= n; i++){
        cin >> u >> k;
        for(j = 1; j <= k; j++){
            cin >> v;
            m[u][v] = 1;
        }
    }

    bfs(1);
    
    for(i = 1; i <= n; i++){
        cout << i << " ";
        if(d[i] == INF) cout << -1 << endl;
        else cout << d[i] << endl;
    }
    
    return 0;
}


Measured memory_bytes: 3124
#include <bits/stdc++.h>
using namespace std;
int N,M,L,K;

int main() {
	cin >> N;
	vector<int>p(N);
	int maxp = 0;
	int ans = 0;
	for (int i = 0; i < N; i++)
	{
		cin >> p[i];
		ans += p[i];
		maxp = max(p[i], maxp);
	}
	cout << ans - maxp / 2 << endl;
}


Measured memory_bytes: 256
package main
import (
    "fmt"
)
    
func main(){
    var N, ans int
    fmt.Scan(&N)
    for i, div, mod:=3, N/3, N%3;div>1;i+=2{
        div, mod = N/i, N%i
        if mod == 0 && div > mod{
            continue
        }else if (mod-div)%div==0{
            ans += i+(mod-div)/div
        }
        i+=mod/div-1
    }
    fmt.Println(ans)
}


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

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

int linearSearch(vector<int> S, int key) {
  S.push_back(key);
  int i = 0;
  while (S[i] != key) i++;
  if (i == S.size() - 1)
    return -1;
  else
    return i;
}

int main() {
  int n;
  cin >> n;
  vector<int> S(n, 0);
  rep(i, n) cin >> S[i];

  int q;
  cin >> q;
  vector<int> T(q, 0);
  rep(i, q) cin >> T[i];

  int cnt = 0;
  rep(i, T.size()) {
    if (linearSearch(S, T[i]) >= 0) cnt++;
  }
  cout << cnt << endl;
  return 0;
}



Measured memory_bytes: 3224
#include<stdio.h>
int main()
{
	int n;
	scanf("%d", &n);
	int i, j, k;
	long long int a[302][302];
	for (i = 0; i < n; i++)
		for (j = 0; j < n; j++)
			scanf("%lld", &a[i][j]);
	for (k = 0; k < n; k++)
	{
		for (i = 0; i < n; i++)
		{
			for (j = 0; j < n; j++)
			{
				if (a[i][j] > a[i][k] + a[k][j])
				{
					printf("-1\n");
					return 0;
				}
			}
		}
	}
	long long int ans = 0;
	for (i = 0; i < n; i++)
		for (j = 0; j < n; j++)
			ans += a[i][j];
	for (k = 0; k < n; k++)
	{
		for (i = 0; i < n; i++)
		{
			for (j = 0; j < n; j++)
			{
				if (a[i][j] == a[i][k] + a[k][j] && i != j && i != k && j != k)
				{
					ans -= a[i][j];
					a[i][j] = 1000000009;
				}
			}
		}
	}
	printf("%lld\n", ans / 2);
	return 0;
}

Measured memory_bytes: 896
// #include <bits/stdc++.h>
#include<climits>
#include<cmath>
#include<cstdio>
#include<deque>
#include<map>
#include<set>
#include<vector>
#include<iostream>
#include<sstream>
#include<algorithm>
#include<numeric>
#include<string>
#include<tuple>
using namespace std;
// #include <boost/multiprecision/cpp_int.hpp>
// using namespace boost::multiprecision;
#define BEGIN ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define END return EXIT_SUCCESS
#define rep(I,N) for(auto I=0;I<(N);++I)
#define up(I,A,B) for(auto I=(A);I<=(B);++I)
#define dw(I,A,B) for(auto I=(A);I>=(B);--I)
#define all(C) (C).begin(),(C).end()
#define rall(C) (C).rbegin(),(C).rend()
#define ft first
#define sd second
#define mp make_pair
#define mt make_tuple
#define pf push_front
#define pb push_back
#define pt pop_front
#define pk pop_back
#define lb lower_bound
#define ub upper_bound
#define rs resize
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;}
template<class T>inline void                             in(T &p){cin>>p;}
template<class T1,class T2>inline void                   in(T1 &p1,T2 &p2){cin>>p1>>p2;}
template<class T1,class T2,class T3>inline void          in(T1 &p1,T2 &p2,T3 &p3){cin>>p1>>p2>>p3;}
template<class T1,class T2,class T3,class T4>inline void in(T1 &p1,T2 &p2,T3 &p3,T4 &p4){cin>>p1>>p2>>p3>>p4;}
template<class T>inline void                             ins(T &p){for_each(all(p),in<decltype(p[0])>);}
template<class T>inline void                             out(T p){cout<<p<<endl;}
template<class T1,class T2>inline void                   out(T1 p1,T2 p2){cout<<p1<<" "<<p2<<endl;}
template<class T1,class T2,class T3>inline void          out(T1 p1,T2 p2,T3 p3){cout<<p1<<" "<<p2<<" "<<p3<<endl;}
template<class T1,class T2,class T3,class T4>inline void out(T1 p1,T2 p2,T3 p3,T4 p4){cout<<p1<<" "<<p2<<" "<<p3<<" "<<p4<<endl;}
template<class T>inline void                             outs(T p){for_each(all(p),out<decltype(p[0])>);}
string s;
inline void solve(void){
  in(s);
  s.insert(4," ");
  cout<<s<<endl;
}
int main(int argc,char**argv){
  BEGIN;
  solve();
  END;
}


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

using namespace std;
using ll = long long;

#pragma region Macros
#define FOR(i, m, n) for (ll i = (ll)(m); i < (ll)(n); i++)
#define rep(i, n) FOR(i, 0, n)

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

template <class T> string join(const T &v, const string delim = ",")
{
    if (v.empty())
        return "";

    ostringstream res;
    res << v[0];
    for (int i = 1; i < v.size(); i++)
    {
        res << delim << v[i];
    }
    return res.str();
}

#pragma endregion Macros

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

    set<int> p;
    rep(i,N){
        int n;
        cin >> n;
        p.insert(n);
    }

    int ans;
    int d = 1000;
    for (int i = 0; i <= 101; i++) {
        if(p.find(i) == p.end()){
            if(d > abs(X-i)){
                d = abs(X - i);
                ans = i;
            }
        }
    }

    cout << ans << endl;
}


Measured memory_bytes: 3612
n,q=map(int,input().split())
s=input()
p=[input().split() for i in range(q)]
def judge_l(x):
    for(k,v)in p:
        if k==s[x]:
            if v=="L":
                x-=1
            else:
                x+=1
        if x==-1:
            return True
        elif x==n:
            return False
    return False

def judge_r(x):
    for(k,v)in p:
        if k==s[x]:
            if v=="L":
                x-=1
            else:
                x+=1
        if x==-1:
            return False
        elif x==n:
            return True
    return False

ok=-1
ng=n

while abs(ok-ng)>1:
    mid=(ok+ng)//2
    if judge_l(mid):
        ok=mid
    else:
        ng=mid
l=ok+1

ok=n
ng=-1

while abs(ok-ng)>1:
    mid=(ok+ng)//2
    if judge_r(mid):
        ok=mid
    else:
        ng=mid
r=n-ok
#print(l,r)
print(max(n-l-r,0))

Measured memory_bytes: 41392
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <string>
#define MAX 20
#define INF 100000
#define ll long long
#define forall(i,a,b) for(int i = a; i < b; ++i)
#define sd(s) scanf("%d", &s);
#define ss(s) scanf("%s", )
using namespace std;

int N, M;
int D[1 << MAX];
int Cnt[1 << MAX];
int W[MAX][MAX];
int P;
int answer = INF;

string INIT;
int main() {
	sd(N);
	cout << ((N / 100) == (N % 10) ? "Yes" : "No");
}

Measured memory_bytes: 256
#include <stdio.h>
#define N 1000
int main(){
  int i, n, a[N], j, v, t;
  scanf("%d",&n);
  for(i=0 ; i<n ; i++){
    scanf("%d",&a[i]);
  }
  for(i=0 ; i<n ; i++){
    v=a[i];
    j=i-1;
    while(j>=0 && a[j]>v){
      a[j+1]=a[j];
      j--;
      a[j+1]=v;
    }

    for(t=0 ; t<n ; t++){
      if(t==n-1) printf("%d",a[t]);
      else printf("%d ",a[t]);   
    }
    printf("\n");
  }
return 0;
}

Measured memory_bytes: 604
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a, b, A, B;
  cin >> a>>b;
  A = a % 2;
  B = b % 2;
  if (A * B == 1) {
    cout << "Odd" << endl;
  }
  else {
    cout << " Even " << endl;
  }
}

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

#define REP(i, n) for(int i = 0;i < n;i++)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define ALL(a) (a).begin(), (a).end()

using namespace std;

int main()
{
    string str; cin >> str;

    cout << (str[0] == str[2] ? "Yes" : "No") << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
	int N; cin >> N; 
	pair<long long, int> A[2010] = {}; 
	for(int i = 0; i < N; i++){
		cin >> A[i].first; A[i].second = i;
	}
	sort(A, A+N, greater<pair<long long, int>>()); 
	long long dp[2010][2010] = {}; 
	for(int i = 0; i <= N; i++){
		for(int j = 0; j <= N; j++){
			if(i + j > N) break; 
			if(i == 0 && j == 0) dp[i][j] = 0; 
			else if(i == 0) dp[i][j] = dp[i][j-1] + A[i+j-1].first * abs(N - j - A[i+j-1].second); 
			else if(j == 0) dp[i][j] = dp[i-1][j] + A[i+j-1].first * abs(i - 1 - A[i+j-1].second); 
			else{
				long long tmp1 = dp[i][j-1] + A[i+j-1].first * abs(N - j - A[i+j-1].second); 
				long long tmp2 = dp[i-1][j] + A[i+j-1].first * abs(i - 1 - A[i+j-1].second); 
				dp[i][j] = max(tmp1, tmp2); 
			}
		}
	}
	long long ans = 0; 
	for(int i = 0; i <= N; i++) ans = max(dp[i][N-i], ans);
	cout << ans << endl; 
}

Measured memory_bytes: 35204
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main {

	static Scanner scanner;

	public static void main(String[] args) {
	    scanner = new Scanner(System.in);

        int a=gi();
        int b=gi();
        
        int c = b-a;
        int d=0;
        for(int i=1; i<c;i++) {
        	d+=i;
        }
        


	    System.out.println(d-a);

//	    if (isNumber(s1) && isNumber(s2) && s.charAt(a) == '-') {
//	    	System.out.print("Yes");
//	    }else {
//	    	System.out.print("No");
//	    }



	}

	public static long d(long n) {
		String a=String.valueOf(n);
		return (long)a.length();
	}

	// 文字列として入力を取得
	public static String gs() {
		return scanner.next();
	}

	// intとして入力を取得
	public static int gi() {
		return Integer.parseInt(scanner.next());
	}

	// longとして入力を取得
	public static long gl() {
		return Long.parseLong(scanner.next());
	}

	// doubleとして入力を取得
	public static double gd() {
		return Double.parseDouble(scanner.next());
	}
}

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

#define pb         push_back

typedef long long ll;
const ll INF = 1000000000ll;
const ll MOD = 1000000007ll;
const double EPS = 1e-8;

vector<int> a;
vector<int> b;
vector<int> c;

int dp[50][500][500];

int gcd( int m, int n )
{
	if ( ( 0 == m ) || ( 0 == n ) )
		return 0;
	
	while( m != n )
	{
		if ( m > n ) m = m - n;
		else         n = n - m;
	}
	return m;
}

int main(void) {
	//ios_base::sync_with_stdio(false);
	//cin.tie(0);
	
	int n, ma, mb;
	cin >> n >> ma >> mb;

	a.push_back(0);
	b.push_back(0);
	c.push_back(0);
	for(int i=0; i<n; i++){
		int t1, t2, t3;
		cin >> t1 >> t2 >> t3;
		a.push_back(t1);
		b.push_back(t2);
		c.push_back(t3);
	}

	for(int i=0; i<=n; i++){
		for(int j=0; j<=400; j++){
			for(int k=0; k<=400; k++){
				dp[i][j][k] = INF;
			}
		}
	}

	dp[0][0][0] = 0;
	for(int i=1; i<=n; i++){
		for(int j=0; j<=400; j++){
			for(int k=0; k<=400; k++){
				dp[i][j][k] = dp[i-1][j][k];
				if(j - a[i] >= 0 && k - b[i] >= 0){
					dp[i][j][k] = min(dp[i-1][j][k], dp[i-1][j - a[i]][k - b[i]] + c[i]);
				}
			}
		}
	}

	/*
	for(int i=0; i<=20; i++){
		for(int j=0; j<=20; j++){
			if(dp[3][i][j] != INF){
				printf("%d ", dp[3][i][j]);
			}else{
				printf("# ");
			}
		}
		puts("");
	}
	*/


	int ans = INF;
	for(int i=1; i<=400; i++){
		for(int j=1; j<=400; j++){
			int k = i/gcd(i,j);
			int l = j/gcd(i,j);


			if(k == ma && l == mb){
				ans = min(ans, dp[n][i][j]);
			}
		}
	}
	if(ans != INF){
		cout << ans << endl;
	}else{
		puts("-1");
	}
	
	return 0;
}


Measured memory_bytes: 40832
#include <iostream>
#include <algorithm>
#include <string>
#include <string.h>
#include <vector>
#include <cstdio>
#include <cmath>

using namespace std;

int main(){
  string s;
  cin>>s;
  int size=s.length();
  for(int i=0;i<=size-1;i=i+2){
    cout<<s[i];
  }
    return 0;
}


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

using namespace std;
const int INF = 1e9 + 5; 

int main()
{
    int N;
    int K; 
    cin >>N>>K;
    vector<int> h(N);
    for(int i=0;i<N;i++)
        cin >>h[i]; 
    vector<int> dp(N,INF);

    dp[0]=0;

    for(int i=0;i<N;i++)
    {
        for(int j=i+1;j<=i+K;j++)
        {
            if(j<N) 
            {
                dp[j] = min(dp[j],dp[i] + abs(h[j]-h[i])); 
            }
        }
    }
    cout <<dp[N-1]<<endl ; 
    

    return 0; 
}


Measured memory_bytes: 1024
import java.util.*;

public class Main{
    public static void main(String[]args){
        Scanner sc = new Scanner(System.in);
        int S = sc.nextInt();
        int W = sc.nextInt();
        if(W>=S){
            System.out.println("unsafe");
        }else{
            System.out.println("safe");
        }
    }
}

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

int main () {
    int a1, a2, a3;
    cin >> a1 >> a2 >> a3;
    int x1, x2, x3;

    x1 = max (a3-a2, a2-a3);
    x2 = max (a3-a1, a1-a3);
    x3 = max (a1-a2, a2-a1);

    cout << x1 + x2 + x3 - max(x1, max(x2, x3)) << endl;

    return 0;
}

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

#define repi(itr, ds) for(auto itr = ds.begin(); itr != ds.end(); itr++)
// vector
template <typename T>
istream &operator>>(istream &is, vector<T> &vec) {
  for(T &x : vec) is >> x;
  return is;
}
// pair
template <typename T, typename U>
ostream &operator<<(ostream &os, pair<T, U> &pair_var) {
  os << "(" << pair_var.first << ", " << pair_var.second << ")";
  return os;
}
// vector
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
  os << "{";
  for(int i = 0; i < vec.size(); i++) {
    os << vec[i] << (i + 1 == vec.size() ? "" : ", ");
  }
  os << "}\n   ";
  return os;
}
// map
template <typename T, typename U>
ostream &operator<<(ostream &os, map<T, U> &map_var) {
  os << "{";
  repi(itr, map_var) {
    os << *itr;
    itr++;
    if(itr != map_var.end()) os << ", ";
    itr--;
  }
  os << "}";
  return os;
}
// set
template <typename T>
ostream &operator<<(ostream &os, set<T> &set_var) {
  os << "{";
  repi(itr, set_var) {
    os << *itr;
    itr++;
    if(itr != set_var.end()) os << ", ";
    itr--;
  }
  os << "}";
  return os;
}

#define DUMPOUT cerr

void dump_func() { DUMPOUT << endl; }
template <class Head, class... Tail>
void dump_func(Head &&head, Tail &&... tail) {
  DUMPOUT << head;
  if(sizeof...(Tail) > 0) {
    DUMPOUT << ", ";
  }
  dump_func(std::move(tail)...);
}
#ifdef DEBUG_
#define DEB
#define dump(...)                                                             \
  DUMPOUT << "  " << string(#__VA_ARGS__) << ": "                             \
          << "[" << to_string(__LINE__) << ":" << __FUNCTION__ << "]" << endl \
          << "    ",                                                          \
      dump_func(__VA_ARGS__)
#else
#define DEB if(false)
#define dump(...)
#endif

typedef long long int ll;
const int MOD = 1e9 + 7;
const int INF = 1e9;

int main() {
  int A, B;
  cin >> A >> B;
  int n = A - 1;
  int tap = 1;
  int cnt = 0;
  while(tap < B) {
    tap += n;
    cnt++;
  }
  cout << cnt << endl;
}


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

#define int long long
#define rep(i,l,r) for(int i=(int)(l);i<(int)(r);i++)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)x.size())
template<class T>bool chmax(T &a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a,T b){if(a>b){a=b;return 1;}return 0;}

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;

const int inf = 1LL<<60;
const int mod = 1e9 + 7;
const double eps = 1e-9;

/*{
  }*/

signed main(){
  int n;
  cin >> n;

  vvi ans(n, vi(n));
  rep(i, 0, n) rep(j, 0, n) if(ans[i][j] == 0){
    rep(k, 0, 10) if((i & 1<<k) != (j & 1<<k)){
      ans[i][j] = k;
      break;
    }
  }

  rep(i, 0, n){
    rep(j, i+1, n){
      cout << ans[i][j]+1 << " \n"[j==n-1];
    }
  }

  return 0;
}



Measured memory_bytes: 2432
ABCD = input()
ans = ''
def dfs(i, s):
    global ans
    s += ABCD[i]
    if i == 3:
        if eval(s) == 7:
            ans = s
        return
    i += 1
    dfs(i, s+'+')
    dfs(i, s+'-')
dfs(0, '')
print(ans+'=7')

Measured memory_bytes: 3060
H,W=map(int,input().split())
N=int(input())
S=list(map(int,input().split()))

T = [[0 for j in range(W)] for i in range(H)]
posx=1
posy=1
for i in range(N):
    tmp=S[i]
    cnt=0
    while tmp>cnt:
        T[posy-1][posx-1]=i+1
        if posy%2!=0:
            posx+=1
            if posx>W:
                posy+=1
                posx-=1
        else:
            posx-=1
            if posx<1:
                posy+=1
                posx+=1
        cnt+=1  

for i in T:
    print(*i)



Measured memory_bytes: 9516
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cassert>
#include <complex>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <sstream>
#include <ctime>
#include <cctype>
#include <set>
#include <map>
#include <queue>
#include <bitset>
#include <deque>
#include <stack>
#include <memory.h>
using namespace std;
typedef long long ll;
#define mp make_pair
int a;
int main()
{
	cin>>a;
	if(a<1000){
		cout<<"ABC";
		return 0;
	}
	cout<<"ABD";
    return 0;
}


Measured memory_bytes: 256