akhauriyash/Code-Regression huggingface dataset:
#pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
using namespace std;
inline void rd(int &x){
  int k;
  int m=0;
  x=0;
  for(;;){
    k = getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
inline void wt_L(char a){
  putchar_unlocked(a);
}
inline void wt_L(int x){
  int s=0;
  int m=0;
  char f[10];
  if(x<0){
    m=1;
    x=-x;
  }
  while(x){
    f[s++]=x%10;
    x/=10;
  }
  if(!s){
    f[s++]=0;
  }
  if(m){
    putchar_unlocked('-');
  }
  while(s--){
    putchar_unlocked(f[s]+'0');
  }
}
inline int BIT_ctz_L(const int x){
  return __builtin_ctz(x);
}
inline int BIT_ctz_L(const long long x){
  return __builtin_ctzll(x);
}
int N;
int res[500];
int main(){
  int i;
  rd(N);
  for(i=(0);i<(N-1);i++){
    res[i] = 1 +BIT_ctz_L(i+1);
  }
  for(i=(0);i<(N-1);i++){
    {
      int Lj4PdHRW;
      if(N-1-i==0){
        putchar_unlocked('\n');
      }
      else{
        for(Lj4PdHRW=(0);Lj4PdHRW<(N-1-i-1);Lj4PdHRW++){
          wt_L(res[Lj4PdHRW]);
          wt_L(' ');
        }
        wt_L(res[Lj4PdHRW]);
        wt_L('\n');
      }
    }
  }
  return 0;
}
// cLay varsion 20190921-1

// --- original code ---
// int N;
// int res[500];
// {
//   rd(N);
//   rep(i,N-1) res[i] = 1 + BIT_ctz(i+1);
//   rep(i,N-1) wt(res(N-1-i));
// }


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define pb push_back
#define f(i,x,n) for(int i=x;i<n;i++)
#define all(c) c.begin(),c.end()
#define int ll
using ll = long long;
using pii = pair<int,int>;
const int MOD = 1e9+7, N = 1e5 + 10; 

int32_t main(){
   ios::sync_with_stdio(false);
   cin.tie(NULL);
   int n;
   cin >> n;
   string s;
   cin >> s;
   int ans = 0;
   f(i,0,n-2){
      if(s.substr(i,3) == "ABC"){
         ans++;
      }
   }
   cout << ans << '\n';
   return 0;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <cstdio>
#include <vector>
#include <string>
#include <iostream>
#include <algorithm>
#include <map>
#include <iterator>
#include <functional>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <fstream>
#include <iomanip>
#include <unordered_map>
#include <unordered_set>
#include <numeric>
#include <cmath>
#include <list>
#include <sstream>
#include <tuple>
#include <complex>
#include <stdio.h>
using namespace std;
#pragma GCC optimize("O3")
#pragma GCC target("sse4")

typedef double LD;
typedef long long LL;
typedef pair<int, int> PII;
typedef pair<LD, LD> PDD;
typedef pair<LL, LL> PLL;
typedef vector<int> VI;
typedef vector<LL> VLL;
typedef vector<char> VCH;
typedef vector<LD> VLD;
typedef vector<string> VS;
typedef vector<VS> VSS;
typedef vector<VI> VVI;
typedef vector<VLL> VVLL;
typedef vector<VCH> VVCH;
typedef vector<PII> VPII;
typedef vector<PLL> VPLL;
typedef vector<PDD> VPDD;
#define MP make_pair
#define PB push_back
#define X first
#define Y second
#define next fake_next
#define prev fake_prev
#define left fake_left
#define right fake_right

#define FOR(i,a,b) for(int i = (a); i < (b); ++i)
#define RFOR(i,b,a) for(int i = (b) - 1; i >= (a); --i)
#define REP(i, t) FOR(i,0,t)
#define ALL(a) a.begin(), a.end()
#define SZ(a) (int)((a).size())

const LD PI = acos(-1.0);
const LL mod = 1000000007;
const LL INF = 1e9;
const LL LINF = 1e18;
const LL MAXQ = 1007;
const int MAXN = 10007;

int main()
{
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	//freopen("In.txt", "r", stdin);

	LL n;
	cin >> n;
	VLL p(n);
	FOR(i, 0, n)
		cin >> p[i], p[i]--;

	VLL a(n), b(n);
	a[0] = 1;
	b[0] = INF;

	VLL k(n);
	k[0] = 0;

	map<int, int> m;
	FOR(i, 0, n)
		m[p[i]] = i;

	VLL s(n);

	FOR(i, 0, n)
		s[p[i]] = i - m[0];

	VLL x(n), y(n);

	VLL ss = s;
	FOR(i, 1, n)
		s[i] = ss[i] - ss[i - 1];

	FOR(i, 1, n)
	{
		if (s[i] > 0)
			x[i] = s[i] + 1, y[i] = 1;
		else
			x[i] = 1, y[i] = -s[i] + 1;
	}

	FOR(i, 1, n)
	{
		a[i] = a[i - 1] + x[i];
		b[i] = b[i - 1] - y[i];
	}

	FOR(i, 0, n)
		cout << a[i] << " ";
	cout << endl;
	FOR(i, 0, n)
		cout << b[i] << " ";
	//cin >> n;	
	return 0;
}

Measured memory_bytes: 2816
import Control.Applicative ((<$>))
import Control.Monad (replicateM, unless)
import Data.List (foldl', nub)
import Data.IntMap (IntMap, (!))
import qualified Data.IntMap as IM

main :: IO ()
main = do
  [n, m] <- map read <$> words <$> getLine
  unless (n == 0 && m == 0) $ do
    r <- readLn
    rs <- replicateM r ((\[t, _, m, s] -> Record t m s) <$> map read <$> words <$> getLine)
    q <- readLn
    qs <- replicateM q ((\[x,y,z] -> (x, y, z)) <$> map read <$> words <$> getLine)
    mapM_ print $ solve rs qs
    main

solve :: [Record] -> [(Int, Int, Int)] -> [Int]
solve rs qs = map (\(st, et, m) -> calct (st, et) (db ! m)) qs
  where db = IM.fromList $ map f (nub (map (\(_,_,m) -> m) qs))
        f x = (x, utm (filter (\(Record _ m _) -> m == x) rs))

data Record = Record Int Int Int deriving Show

utm :: [Record] -> [(Int, Int)]
utm = snd . foldl' f ([],[])
  where f (st, as) (Record t m s) | s == 1 = (t:st, as)
                                  | (null . tail) st = ([], (head st, t):as)
                                  | otherwise = (tail st, as)

calct :: (Int,Int) -> [(Int,Int)] -> Int
calct (st, et) = foldl' f 0
  where f tt (t1, t2) = tt + max 0 (min et t2 - max st t1)



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

using namespace std;

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

typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define CHMIN(a,b) a=min((a),(b))
#define CHMAX(a,b) a=max((a),(b))

// mod
const ll MOD = 1000000007ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

// floating
typedef double Real;
const Real EPS = 1e-11;
#define EQ0(x) (abs(x)<EPS)
#define EQ(a,b) (abs(a-b)<EPS)
typedef complex<Real> P;

int data[125252];
int init(){
  REP(i,125252)data[i]=-1;
}
int root(int x){
  return data[x]<0?x:data[x]=root(data[x]);
}
void unite(int a,int b){
  a=root(a);b=root(b);
  if(a!=b){
    if(data[a]>data[b])swap(a,b);
    data[a] += data[b];
    data[b] = a;
  }
}
int size(int x){
  return -data[root(x)];
}

int n,m;
vi langs[125252];

int main(){
  init();
  scanf("%d%d",&n,&m);
  REP(i,n){
    int k;
    scanf("%d",&k);
    REP(j,k){
      int l;
      scanf("%d",&l);
      --l;
      langs[l].push_back(i);
    }
  }
  REP(i,m){
    REP(j,langs[i].size()-1){
      unite(langs[i][j],langs[i][j+1]);
    }
  }
  puts(size(0)==n?"YES":"NO");
  return 0;
}


Measured memory_bytes: 5632
#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
template<class T>
using Table = vector<vector<T>>;
const ld eps=1e-9;

//// < "D:\D_Download\Visual Studio 2015\Projects\programing_contest_c++\Debug\a.txt"
int main() {
	int a, b, c; cin >> a >> b >> c;
	int sum = 0;
	sum = a * 4 + b * 2 + c;
	if (sum == 6 || sum == 1)cout << "Open" << endl;
	else cout << "Close" << endl;
	
	return 0;
}

Measured memory_bytes: 3060
#![allow(non_snake_case, unused)]
use std::cmp::*;
use std::collections::*;
use std::f64::consts::*;

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

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

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

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

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

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

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

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

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

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

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

fn dfs(v: usize, p: usize, mut nex: usize, g: &mut Vec<HashSet<usize>>, pre: &mut Vec<usize>) {
    let n = g.len();
    for &w in g[v].clone().iter() {
        if w == p {
            continue;
        }
        if pre[w] < n && pre[v] < pre[w] {
            continue;
        }
        if pre[w] == n {
            pre[w] = nex;
            nex += 1;
            dfs(w, v, nex, g, pre);
            if g[w].len() % 2 == 1 {
                g[w].remove(&v);
            } else {
                g[v].remove(&w);
            }
        } else {
            g[w].remove(&v);
        }
    }
}


fn main() {
    input!{
        n: usize,
        m: usize,
        link: [(usize1, usize1); m],
    }
    if m % 2 == 1 {
        return println!("-1");
    }
    let mut g = vec![HashSet::new(); n];

    for &(a, b) in &link {
        g[a].insert(b);
        g[b].insert(a);
    }
    let mut pre = vec![n; n];
    pre[0] = 0;
    dfs(0, 0, 1, &mut g, &mut pre);
    for u in 0..n {
        for &v in &g[u] {
            println!("{} {}", u + 1, v + 1)
        }
    }
}


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

// {U}{INT,LONG,LLONG}_{MAX,MIN}
#define INF         INT_MAX/3
#define MOD         (1000000007LL)
#define inc(i, l, r)   for(long long i=(l);i<(r);i++)
#define dec(i, l, r)   for(long long i=(r)-1;i>=(r);i--)
#define se          second
#define fi          first

using LL  = long long;

int di[] = {0, -1, 0, 1};
int dj[] = {1, 0, -1, 0};
// }}}

int main() {
    std::ios::sync_with_stdio(false);
    int n, y;cin >> n >> y;
    y /= 1000;
    inc(i, 0, 2001){
        inc(j, 0, 4001){
            int k = n-i-j;
            if(k < 0) continue;
            if(i*10+j*5+k == y){
                cout << i << " " << j << " " << k << endl;
                return 0;
            }
        }
    }
    cout << "-1 -1 -1" << endl;
    return 0;
}


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

using ll = long long;
using Vi = vector<int>;
using Vl = vector<ll>;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

constexpr int I_INF = numeric_limits<int>::max();
constexpr ll L_INF = numeric_limits<ll>::max();

//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

void solve() {
    ll N, K;
    cin >> N >> K;
    Vl A(N);
    for (ll i = 0; i < N; i++) {
        cin >> A[i];
        --A[i];
    }

    ll ans = -1;

    ll cnt = 0;
    Vi visited(N, -1);

    ll cur = 0;
    ll nxt;
    visited[0] = 0;
    while (true) {
        nxt = A[cur];
        ++cnt;
        --K;

        if (K == 0) {
            ans = nxt;
            break;
        }

        if (visited[nxt] >= 0) {
            ll d = cnt - visited[nxt];
            K = K % d;
            break;
        }

        visited[nxt] = cnt;
        cur = nxt;
    }

    if (ans >= 0) {
        cout << ans + 1 << endl;
    }
    else {
        cur = nxt;
        while (K > 0) {
            cur = A[cur];
            --K;
        }

        ans = cur;

        cout << ans + 1 << endl;
    }
}

//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

int main() {
#ifdef FASTIO
    cin.tie(0), cout.tie(0);
    ios::sync_with_stdio(false);
#endif
#ifdef FILEINPUT
    ifstream ifs("./in_out/input.txt");
    cin.rdbuf(ifs.rdbuf());
#endif
#ifdef FILEOUTPUT
    ofstream ofs("./in_out/output.txt");
    cout.rdbuf(ofs.rdbuf());
#endif
    solve();
    cout << flush;
    return 0;
}

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

int main(){
  int N, M;
  cin >> N >> M;
  int a[M];
  int b[M];
  for(int i=0; i<M; i++){
    cin >> a[i] >> b[i];
  }
  int road[N+1]={0};
  for(int i=0; i<M; i++){
    road[a[i]]+=1;
    road[b[i]]+=1;
  }
  for(int i=1; i<=N; i++){
    cout << road[i] << endl;
  }
}

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

int main() {
	int l, r, d;
	scanf("%d %d %d", &l, &r, &d);
	int ans = r / d;
	ans -= (l / d);
	if(l % d == 0) ans++;
	printf("%d\n", ans);
	return 0;
}
//ios_base::sync_with_stdio(false);


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

#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
typedef long long ll;

const long long INF = 1LL << 60;

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

    vector<int> p(N), co(N);
    rep(i, N) {
        cin >> p[i];
        co[i] = p[i];
    }

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

    int cnt = 0;
    rep(i, N) {
        if (p[i] != co[i]) {
            cnt++;
        }
    }

    if (cnt <= 2) {
        cout << "YES" << endl;
    }
    else {
        cout << "NO" << endl;
    }
    
    return 0;
}

Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
#define PI 3.14159265359
using namespace std;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
const long long INF= 1e+18+1;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll> >vvl;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> T;
const ll MOD=1000000007LL;
string abc="abcdefghijklmnopqrstuvwxyz";
string ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
int main(){
  ll n,W;cin>>n>>W;
  vl w(n),v(n);
  rep(i,n)cin>>w[i]>>v[i];
  ll dp[100010];
  rep(i,W+1)dp[i]=0;
  rep(i,n){
    for(ll j=W;j>=0;j--){
      if(j>=w[i])dp[j]=max(dp[j],dp[j-w[i]]+v[i]);
    }
  }
  ll ans=0;
  cout<<dp[W]<<endl;
}
  

Measured memory_bytes: 1024
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
int INF = 1LL << 30;
int MOD = 1e9+7;
main(){
    int N;
    cin >> N;
    string st;
    map<string,int> mp;
    for(int i = 0;i < N;i++){
        string st;
        cin >> st;
        mp[st]++;        
    }
    cin >> N;
    for(int i = 0;i < N;i++){
        cin >> st;
        mp[st]--;
    }
    int ma = 0;
    for(auto p:mp){
        ma = max(ma, p.second);
    }
    cout << ma << endl;
}

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

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

	int A, B;
	cin >> A >> B;
	if ((A - B) % 2 == 0) cout << abs(A - B) / 2 + min(A, B);
	else cout << "IMPOSSIBLE";
}

Measured memory_bytes: 256
import sys
N = int(input())
L = [int(i) for i in input().split()]
L.sort()
if N <= 2:
    print(0)
    sys.exit()
ans = 0
for i in range(N):
    for j in range(N):
        for k in range(N):
            if i < j and j < k and L[i] != L[j] and L[j] != L[k] and L[i] != L[k]:
                m = max(L[i], L[j], L[k])
                if m < L[i]+L[j]+L[k] - m:
                    ans += 1
print(ans)

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

namespace AtCoder.Beginner067
{
    public class ABC067B_SnakeToy
    {
        public static void Main(string[] args)
        {

            // 入力
            int[] nums1 = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
            int[] nums2 = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
            int n = nums1[0];
            int k = nums1[1];
            
            Array.Sort(nums2);

            int sum = 0;
            for( int i = 0; i < k; i++ )
            {
                sum += nums2[nums2.Length - i - 1];
            }

            // 結果出力
            Console.WriteLine(sum);

        }
    }
}

Measured memory_bytes: 11348
#include<iostream>
#include<algorithm>
using namespace std;
int n,m;
long long k,dp[20010],a[20010],x,y;
int main(){
	cin>>n>>m>>k;
	for(int i=0;i<n;i++){
		cin>>a[i];
		dp[i+1]=114514114514114514;
	}dp[0]=0;
	for(int i=0;i<n;i++){
		x=a[i],y=a[i];
		for(int j=1;j<=m;j++){
			dp[i+j]=min(dp[i+j],dp[i]+k+j*(x-y));
			x=max(x,a[i+j]),y=min(y,a[i+j]);
			if(i+j==n)break;
		}
	}
	cout<<dp[n]<<endl;
	return 0;
}

Measured memory_bytes: 3436
# 入力
D = int(input())
C = list(map(int, input().split()))
S_2d = []
for i in range(D):
    s_1d = list(map(int, input().split()))
    S_2d.append(s_1d)
T = []
for i in range(D):
    t = int(input())
    T.append(t)

last_days = [0] * 26
tot_score = 0

for i in range(D):
    today_contest = T[i]
    last_days[today_contest - 1] = i + 1
    today_plus = S_2d[i][today_contest - 1]
    today_minus = 0
    for j, c in enumerate(C):
        today_minus += c * (i + 1 - last_days[j])
    tot_score += today_plus - today_minus
    print(tot_score)



Measured memory_bytes: 9084
import java.util.Scanner;
import java.util.ArrayList;
import java.util.HashMap;
import java.lang.Integer;
import java.lang.StringBuilder;
import java.lang.Math;

public class Main {
  public static void main(String[] args) {
    Scanner in = new Scanner(System.in);
    String ATCODER = in.next();
    String s = in.next();
    String CONTEXT = in.next();

    String S = String.valueOf(s.charAt(0));
    System.out.println("A" + S.toUpperCase() + "C");
  }
}

Measured memory_bytes: 10192
#include<bits/stdc++.h>
#define int long long
#define rep(i,a,b) for(int i=a;i<b;i+=1)
#define reps(i,a,b) for(int i=a;i>=b;i-=1)
#define vi vector<int>
#define pb push_back
#define pi pair<int, int>
#define mp make_pair
#define ff first
#define ss second
#define in(x) int x; cin>>x;
#define inn(x, y) int x, y; cin>>x>>y;
#define mi unordered_map<int,int>
#define mem(x) memset(x, 0, sizeof(x))
#define IOS ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
using namespace std;

//bool primes[1000001];vi prime;
//void seive(){memset(primes, true, sizeof(primes));primes[0] = primes[1] = false;for(int i = 2; i*i<=1000000;i += 1){
//if(primes[i]){for(int j = i*i; j <= 1000000;j += i) primes[j] = false;}}rep(i, 2, 1000001){if(primes[i]) prime.pb(i);}}

//int gcd(int a, int b){return b==0 ? a : gcd(b, a%b);}

int32_t main(void){
	IOS;
	
	string s;
	cin>>s;
	if(s == "ABC") cout<<"ARC";
	else cout<<"ABC";
}

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

vector<int> A;
vector<int> B;
int main(void){
    // Your code here!
    
    int N;
    cin >> N;
    A.resize(N);
    B.resize(N);
    int a = 0;
    for(int i = 0; i < N; i++) {
        cin >> a;
        A[i] = B[i] = a;
    }
    
    
    sort(A.begin(), A.end(), greater<int>());
    for(int i = 0; i < N; i++){
        if(B[i] == A[0] && A[0] == A[1]) cout << A[0] << endl;
        else if(B[i] == A[0] && A[0] != A[1]) cout << A[1] << endl;
        else cout << A[0] << endl;
    }
}


Measured memory_bytes: 3200
#include <bits/stdc++.h>
#ifdef HIRO
#define d(f_, ...) printf((f_), ##__VA_ARGS__)
#else
#define d(f_, ...)
#endif

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef queue<int> qi;
typedef queue< pair<int, int> > qp;
#define mp make_pair
#define pi 3.14159265358979323846
#define MAX max_element
#define MIN min_element
#define all(v) v.begin(), v.end()
#define gt(T) greater<T>()
#define sum(v) accumulate(v.begin(), v.end(), 0)
#define uni(v) do{ \
  sort(v.begin(), v.end()); \
  decltype(v)::iterator result = unique(v.begin(), v.end()); \
  v.erase(result, v.end()); \
}while(0)
#define fi(init, n) for(int i = init; i < n; ++i)
#define fj(init, n) for(int j = init; j < n; ++j)
#define fk(init, n) for(int k = init; k < n; ++k)
#define zero(x) memset(x, 0, sizeof(x))
#define negative(x) memset(x, ~0, sizeof(x))
const ll MOD = 1e9 + 7;
const int INF = 1e9;
const int di[] = { 0, 1, 0, -1 };
const int dj[] = { 1, 0, -1, 0 };

template<typename T>
T gcd(T a, T b) {
	return b ? gcd(b, a % b) : a;
}
template<typename T>
T lcm(T a, T b) {
	return a * b / gcd(a, b);
}
template<typename T>
int finder(vector<T> vec, T number) {
	auto itr = find(vec.begin(), vec.end(), number);
	size_t index = distance(vec.begin(), itr);
	if (index != vec.size()) return 1;
	else return 0;
}
ll frac(ll n){
	if (n == 0) return 1;
	return (n * frac(n - 1)) % MOD;
}
template<class T> inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template<class T> inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

int main(int argc, char** argv) {
#ifdef HIRO
  string quiz(argv[1]);
  string id(argv[2]);
  string filename("input/" + quiz + "/" + id + ".txt");
  ifstream fin(filename);
  if (fin.peek() == ifstream::traits_type::eof()) {
    cout << "No input.";
    return 0;
  }
  ifstream cin(filename);
  std::cin.rdbuf(cin.rdbuf());
#endif
  ll ans = 0;
  ll n;
  cin >> n;
  // ll n, m;
  // cin >> n >> m;
  // ll n, m, k;
  // cin >> n >> m >> k;
  set<ll> s;
  ll x;
  while(n--){
    cin >> x;
    auto it = s.find(x);
    if(it != s.end()) {
      s.erase(it);
    }
    else {
      s.insert(x);
    }
  }
  ans = s.size();
  cout << ans << endl;
  return 0;
}



Measured memory_bytes: 4864
package main

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

func parseToArray2d(lines []string) [][]int64 {
	var result [][]int64
	for _, line := range lines {
		var parsedLine []int64
		for _, element := range strings.Split(line, " ") {
			n, err := strconv.ParseInt(element, 10, 64)
			if err != nil {
				fmt.Printf("Error: element = %v\n", element)
			}
			parsedLine = append(parsedLine, n)
		}
		result = append(result, parsedLine)
	}
	return result
}

func pop(stack []int64) ([]int64, int64) {
	lenStack := len(stack)
	return stack[0:(lenStack - 1)], stack[lenStack-1]
}

func contains(s []int64, e int64) bool {
	for _, a := range s {
		if a == e {
			return true
		}
	}
	return false
}

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	content := []string{}
	for scanner.Scan() {
		line := scanner.Text()
		content = append(content, line)
	}
	arr := parseToArray2d(content)
	x := arr[0][0]
	y := arr[0][1]

	if x == 0 && y == 0 {
		fmt.Println(1)
		return
	}

	filledRange := []int64{1, 0, 0, 0}
	direction := 0
	var prev int64 = 1
	var curr int64 = 1
	xSatisfied := false
	ySatisfied := false
	i := 1
	for ; i < 100; i++ {
		filledRange[direction%4] += curr
		direction++
		// fmt.Println(filledRange)

		if (x >= 0 && x <= filledRange[0]) || (x <= 0 && -x <= filledRange[2]) {
			xSatisfied = true
		}
		if (y >= 0 && y <= filledRange[1]) || (y <= 0 && -y <= filledRange[3]) {
			ySatisfied = true
		}

		if xSatisfied && ySatisfied {
			break
		}

		prev, curr = curr, prev+curr
	}

	fmt.Println(i%3 + 1)
}



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

int dp[100];

//最大公約数
int gcd(int x, int y){
  if(x % y == 0) return y;
  return gcd(y, x % y);
}
//最小公倍数
int lcm(int x, int y){
  return x * y / gcd(x, y);
}
//フィボナッチ数列
//配列dpを-1で初期化する
int fib(int n){
  if(n == 0 || n == 1) return dp[n] = 1;
  if(dp[n] != -1) return dp[n];
  return dp[n] = fib(n - 1) + fib(n - 2);
}
//階乗計算(factorial)
int fact(int n){
  if(n = 1) return 1;
  return n * fact(n - 1);
}
//累乗計算(Exponentiation)
//x**y
ll expo(int x, int y){
  ll ans = 1;
  rep(i, y){
    ans *= x;
  }
  return ans;
}
//桁数
int keta(ll x){
  if(x == 0) return 1;
  int res = 0;
  while(x){
    x /= 10;
    res++;
  }
  return res;
}


int main(){
  int n;
  cin >> n;
  vector<int> h(n);
  rep(i,n) cin >> h[i];
  vector<int> dp(n);
  dp[0] = 0; dp[1] = abs(h[1] - h[0]);

  for(int i = 2; i < n; i++){
    dp[i] = min(dp[i-1] + abs(h[i]-h[i-1]), dp[i-2] + abs(h[i]-h[i-2]));
  }
  cout << dp[n-1] << endl;
}




Measured memory_bytes: 1024
import java.util.Scanner;

public class Main {

	static Scanner sc = new Scanner(System.in);
	static int N;
	static int[] DR = { 1, 0, -1, 0 };
	static int[] DC = { 0, 1, 0, -1 };

	static boolean solve() {
		int[][] map = new int[21][21];
		int all = 0;
		for (int i = 0; i < N; ++i) {
			int x = sc.nextInt();
			int y = sc.nextInt();
			map[y][x] = 1;
			all++;
		}
		int r = 10;
		int c = 10;
		int collect = 0;
		int M = sc.nextInt();
		for (int i = 0; i < M; ++i) {
			int d = "NESW".indexOf(sc.next());
			int l = sc.nextInt();
			for (int j = 0; j < l; ++j) {
				r += DR[d];
				c += DC[d];
				collect += map[r][c];
				map[r][c] = 0;
			}
		}
		return collect == all;
	}

	public static void main(String[] args) {
		while (true) {
			N = sc.nextInt();
			if (N == 0) break;
			System.out.println(solve() ? "Yes" : "No");
		}
	}
}

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

string s;
vector<string>v={"SUN","MON","TUE","WED","THU","FRI","SAT"};

int main(){
	cin>>s;
	
	for(int i=0;i<7;i++){
		if(v[i]==s){
			cout<<7-i<<'\n';
			return 0;
		}
	}
}

Measured memory_bytes: 256
#include <bits//stdc++.h>
using namespace std;
int main() {
	int n,l;
	cin>>n>>l;
	int nsum=0;
	for(int i=1;i<n+1;i++){
		nsum+=l+i-1;
	}
	int min=1000000000;
	int k;
	for(int i=1;i<n+1;i++){
      k=l+i-1;
		if(abs(min)>abs(k))min=k;
	}
	cout<<nsum-min;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,s,n) for(int i=(int)s;i<(int)n;i++)
int main() {
  int n,w[110],a=110; cin>>n;
  rep(i,0,n) cin>>w[i];
  rep(i,0,n){
    int s1=0,s2=0;
    rep(j,0,i+1) s1+=w[j];
    rep(j,i+1,n) s2+=w[j];
    a=min(a,abs(s1-s2));
  }
  cout<<a;
}

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

int main()
{
  long long n;
  cin >> n;
  long long loc = 2;
  for (int r = (int)sqrt(n); r > 0; r--){
    if (n % r == 0){
      loc = r + n / r;
      break;
    }
  }
  cout << loc - 2 << endl;
 
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
/* typedef */
typedef long long ll;
typedef pair<int, int> pii;
/* constant */
const ll LINF = 1LL << 50;
const int VMAX = 1e+5;
/* global variables */
/* function */
/* main */
int main(){
    string s, t;
    cin >> s >> t;
    vector<vector<int>> dp(s.size()+1, vector<int>(t.size()+1));

    for (int i = 0; i < s.size(); i++) {
        for (int j = 0; j < t.size(); j++) {
            dp[i+1][j+1] = max(dp[i][j+1], dp[i+1][j]);
            if (s[i] == t[j]) {
                dp[i+1][j+1] = dp[i][j] + 1;
            }
        }
    }
    string ret = "";
    int slen = s.size()-1;
    int tlen = t.size()-1;
    int len = dp[s.size()][t.size()];
    while (len > 0) {
        // 同じなら使った事になる
        if (s[slen] == t[tlen]) {
            ret += s[slen];
            slen--;
            tlen--;
            len--;
        }
        // 違うならどっちからきたか
        else if (dp[slen+1][tlen+1] == dp[slen+1][tlen]) tlen--;
        else slen--;
    }
    reverse(ret.begin(), ret.end());
    cout << ret << '\n';
}


Measured memory_bytes: 38636
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
  	int a=sc.nextInt();
  	String[] s= new String[a];
  	
  	for(int i=0;i<a;i++){
  		s[i]=sc.next();
  	}
  	Arrays.sort(s);
  	int f=1;
  	
  	for(int i=1;i<a;i++){
  		if(s[0].equals(s[i])){
  		}else{
  			s[0]=s[i];
  			f++;
  		}
  	}
  	System.out.print(f);
  }
}

Measured memory_bytes: 70404
#include <bits/stdc++.h>
using namespace std;
int main()
{
        int x,y;cin>>x>>y;
        char a[x][y];
        for(int i=0;i<x;i++)
            for(int j=0;j<y;j++)
                cin>>a[i][j];
        for(int i=0;i<x;i++){
            for(int j=0;j<y;j++){
                int c=0;
            if(a[i][j]=='.')
            {
                if(a[i-1][j]=='#' &&i!=0)
                    c++;
                if(a[i+1][j]=='#'&&i!=x-1)
                    c++;
                if(a[i][j-1]=='#'&&j!=0)
                    c++;
                if(a[i][j+1]=='#' && j!=y-1)
                    c++;
                if(a[i+1][j+1]=='#' && j!=y-1)
                    c++;
                if(a[i-1][j-1]=='#'&&j!=0&&i!=0)
                    c++;
                if(a[i+1][j-1]=='#'&&j!=0&&i!=x-1)
                    c++;
                if(a[i-1][j+1]=='#'&&i!=0&&j!=y-1)
                    c++;
            char d='0'+c;
         a[i][j]=d;
            }
        }
        }
                for(int i=0;i<x;i++){
            for(int j=0;j<y;j++)
                cout<<a[i][j];
                cout<<endl;
                }
    return 0;
   }

Measured memory_bytes: 3608
import sys
sys.setrecursionlimit(10 ** 9)
MOD = 10 ** 9 + 7

H, W = map(int, input().split())

G = [['#'] * (W + 2)]
for _ in range(H):
    G.append(['#'] + list(input()) + ['#'])

G.append(['#'] * (W + 2))

for tmp in G:
    print (*tmp, sep = '')


Measured memory_bytes: 4468
import java.util.Scanner;
 
public class Main{
public static void main(String[] args){
Scanner scan=new Scanner(System.in);
int na=scan.nextInt();
String[] nb=new String[na+1];
int[] nc=new int[na];
 
int i=0;
for(i=0;i<na;i++){
  nb[i]=scan.next();
  nc[i]=scan.nextInt();
}
  nb[na]=scan.next();
 
int sum=0;
for(i=0;i<na;i++){
  if(nb[i].equals(nb[na])){
    break;
  }else{
    sum=sum+1;
  }
}
 
int summ=0;
for(i=sum+1;i<na;i++){
  summ=summ+nc[i];
}
     
System.out.println(summ);
     
}
}
  

Measured memory_bytes: 22484
#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>;

void solve() {
    ll n;
    cin >> n;

    ll ans = 0;

    for (int j = 1; j <= n; j++) {
        // 1 ~ n までの j の倍数の和を取る
        // for (int i = 1; i <= n; i++) {
        //     if (i % j == 0)
        //         ans += i;
        // }
        ll k = n / j;
        ans += j * k * (k + 1l) / 2l;
    }

    cout << ans << endl;

}

int main() {
    solve();
    return 0;
}


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

using namespace std;

typedef long long ll;
typedef vector <ll> v_ll;
typedef vector <vector <ll> > vv_ll;
typedef vector < pair <ll,ll> > vp_ll;
typedef pair <ll,ll> p_ll;
typedef vector <string> v_str;
ll N;
vector <string> S;
v_ll P;
v_ll A;
int main(){
  cin >> N;
  S.assign(1000,"");
  P.assign(1000,0);
  A.assign(1000,0);
  for (ll i=1;i<=N;i++){
    cin >> S[i] >> P[i];
  }
  ll ans;
  for (ll i=1;i<=N;i++){
    ans=1;
    for (ll j=1;j<=N;j++){
      if (i==j)continue;
      if ( (S[j]<S[i]) || (S[j]==S[i] && P[j]>P[i]) ) ans++;
    }
    A[ans]=i;

  }
  for (ll i=1;i<=N;i++)
    cout << A[i] << endl;

}


Measured memory_bytes: 256
#include <iostream>
#include <string>

using namespace std;

int main(){
    // int ans = 0;
    
    string S, T;
    cin >> S;
    cin >> T;
    // cout << S << endl << T << endl;
    string SS, TT;

    SS = S;
    // TT = SS;
    for (int j=0; j < S.size(); j++)
    {
        SS[0] = S[S.size()-1];
        // cout << SS << endl;
        for (int i=1; i < S.size(); i++)
        {
            SS[i] = S[i-1];
        }
        S = SS;
        if ( S == T)
        {
            cout << "Yes" << endl;
            return 0;
        }
    
    }

    cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, a, b) for (int i = a; i < b; i++)
#define all(v) v.begin(), v.end()
const int MOD = 1e9 + 7;
const int INF = 2e9;
//'A' = 65, 'Z' = 90, 'a' = 97, 'z' = 122

int main() {
    int h, w, n;
    cin >> h >> w >> n;
    int a[n];
    int color[h * w] = {};
    int cnt = 0;
    rep(i, 0, n) {
        cin >> a[i];
        rep(j, 0, a[i]) {
            color[cnt] = i + 1;
            cnt++;
        }
    }

    int ans[h][w] = {};
    cnt = 0;
    for (int i = 0; i< h; i++) {
        if (i % 2 == 0) {
            for (int j = 0; j < w; j++) {
                ans[i][j] = color[cnt];
                cnt++;
            }
        } else {
            for (int j = w - 1; j >= 0; j--) {
                ans[i][j] = color[cnt];
                cnt++;
            }
        }
    }

    rep(i, 0, h) {
        rep(j, 0, w) {
            cout << ans[i][j];
            if (j != w - 1) cout << " ";
        }
        cout << endl;
    }
    return 0;
}


Measured memory_bytes: 384
import math
import collections
import fractions
import itertools
import functools
import operator

def solve():
    n = int(input())
    a = list(map(int, input().split()))
    a.sort()
    ans = 0
    mid = n // 2
    if n % 2 == 1:
        for i in range(mid, n-1):
            ans += a[i+1]
        for i in range(mid):
            ans += a[i+mid]
    else:
        for i in range(mid, n-1):
            ans += a[i+1]
        ans += a[mid]
        for i in range(1, mid):
            ans += a[i+mid-1]
    print(ans)
    return 0

if __name__ == "__main__":
    solve()


Measured memory_bytes: 33016
#include <bits/stdc++.h>
#define int long long
using namespace std;
 
inline int read()
{
	int sum=0,ff=1; char ch=getchar();
	while(!isdigit(ch))
	{
		if(ch=='-') ff=-1;
		ch=getchar();
	}
	while(isdigit(ch))
		sum=sum*10+(ch^48),ch=getchar();
	return sum*ff;
}
 
signed main()
{
	int n,m;
	n=read();
	m=read();
	if(n<10) m+=(10-n)*100;
	printf("%lld\n",m);
}

Measured memory_bytes: 256
"use strict";
    
const main = arg => {
    arg = arg.trim().split("\n");
    const N = parseInt(arg[0].split(" ")[0]);
    const C = arg[1].split("");
    
    let Rcnt = 0;
    let Wcnt = 0;
    
    let Rplace = [];
    let done = [];
    
    for(let i=0; i<N; i++) {
        if(C[i] === "R") {
            Rplace.push(i);
        }
    }
    
    let answer = 0;
    let tempR = [...Array(Rplace.length)].fill("R");
    let tempW = [...Array(N - Rplace.length)].fill("W");
    
    const splitted = tempR.concat(tempW);
    let temp = 0;
    
    for(let i=0; i<Rplace.length; i++) {
        if(C[i] !== splitted[i]) temp++;
    }
    
    //console.log(temp)
    
    answer = Math.min(temp, Math.min(Rplace.length, N - Rplace.length));
    
    //  for(let i=0; i<N; i++) {
    //     if(C[i] === "R" && done.indexOf(i) !== -1) {
    //         continue;
    //     } else if(C[i] === "W") {
    //         Wcnt++;
    //     }
        
    //     if(Wcnt > 0 && C[i] === "R") {
    //         for(let j=0; j<Wcnt; j++) {
    //             let temp = Rplace.pop();
                
    //             if(temp === i) {
    //                 answer++;
    //                 break;
    //             }
                
    //             done.push(temp);
                
    //             answer++;
    //         }
    //     }
    //  }

    console.log(answer);
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

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

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

int main(){
    ll A,B;
    cin >>A >> B;
    if((A+B)%2 ==0){
        cout << (A+B)/2;
    }else{
        cout << "IMPOSSIBLE";
    }
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
// #pragma GCC optimize("Ofast")
// #pragma GCC optimize ("unroll-loops")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
using ll = long long int;

ll mpow(ll a, ll n, ll mod)
{
	ll r = 1;
	while (n) {
		if (n&1) r = r*a%mod;
		a = a*a%mod;
		n >>= 1;
	}
	return r;
}

const int N = 1e6+5;
int Div[N];

int main()
{
	ios::sync_with_stdio(0); cin.tie(0);
	mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
	
	for (int i = 1; i < N; ++i)
		for (int j = i; j < N; j += i)
			++Div[j];
	int n; cin >> n;
	ll ans = 0;
	for (int c = 1; c < n; ++c)
		ans += Div[n-c];
	cout << ans << '\n';
}

Measured memory_bytes: 7556
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) FOR(i, 0, (n))
#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define LAR(a, b) ((a)=max((a),(b)))
#define SML(a, b) ((a)=min((a),(b)))
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vl = vector<ll>;
using pii = pair<int, int>;
using vpii = vector<pair<int, int>>;
template<typename T>
using pque = priority_queue<T, vector<T>, greater<T>>;
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define ALL(a) (a).begin(), (a).end()
#ifdef LOCAL_DEBUG
#define DEBUG(...) printf(__VA_ARGS__)
#else
#define DEBUG(...)
#endif

char s[212345];

int main(){
	scanf("%s", s);
	int n = strlen(s);
	REP(i, n) if(s[i] == '?') s[i] = 'D';
	printf("%s\n", s);
}


Measured memory_bytes: 3852
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define de cout<<"debuglandınız\n";
#define md 1000000007
ll int n,m,a,ar[105],i,ans,su=1;
int main(){
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	cin >> n;
	for(i=0;i<n;i++)cin >> ar[i];
	ar[n]=n+5;
	for(i=0;i<n;i++){
		if(ar[i]==ar[i+1])su++;
		else{
			ans+=su/2;
			su=1;
		}
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
using ll     = long long;
using pii    = pair<int, int>;
using pll    = pair<ll, ll>;
using vi     = vector<int>;
using vl     = vector<ll>;
using vvi    = vector<vi>;
using vvl    = vector<vl>;
const ll INF = 1LL << 60;
const ll MOD = 1000000007;
template <class T>
bool chmax(T &a, const T &b) {
    return (a < b) ? (a = b, 1) : 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    return (b < a) ? (a = b, 1) : 0;
}
template <class C>
void print(const C &c, std::ostream &os = std::cout) {
    std::copy(std::begin(c), std::end(c), std::ostream_iterator<typename C::value_type>(os, " "));
    os << std::endl;
}

int main() {
    ll h, n;
    cin >> h >> n;
    vl a(n);
    ll sum = 0;
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
        sum += a[i];
    }
    if (sum >= h)
        cout << "Yes"
             << "\n";
    else
        cout << "No"
             << "\n";
    return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
 
 
int s,n,m;
int x[2000];
int t,p;
map<int,int> mp;
vector<int> A,B;
int dp[2005][2005];
 
int main(){
  cin>>s>>n>>m;
  for(int i=0;i<s;i++)cin>>x[i];
  for(int i=0;i<n;i++){
    cin>>t>>p;
    mp[t-x[p-1]]++;
  }
 
  A.push_back(0);
  B.push_back(0);
  map<int,int> :: iterator it;
  for(it=mp.begin();it!=mp.end();it++){
    A.push_back(it->first);
    B.push_back(it->second);
  }
  int size=A.size()-1,base=A[1];
  for(int i=1;i<=size;i++)A[i]-=base;
  /*
  for(int i=1;i<=size;i++)cout<<A[i]<<' '<<B[i]<<endl;
  cout<<endl;
  */
 
  fill(dp[0],dp[1],0);  
  fill(dp[1],dp[2005],1e9);
 
 
  for(int j=1;j<=m;j++){
    for(int i=1;i<=size;i++){
 
      int sum=0;
      for(int k=i-1;k>=0;k--){
        dp[i][j]=min(dp[i][j],dp[k][j-1]+sum);
        sum+=(A[i]-A[k])*B[k];
        if(sum>dp[i][j])break;
      }
    }
  }
  
  /*
  for(int j=1;j<9;j++){
    for(int i=1;i<9;i++){  
      if(dp[i][j]==1e9)printf(" INF ");
      else printf("%4d ",dp[i][j]);
    }
    printf("\n");
  }
  */
  cout<<dp[size][m]<<endl;
 
 
  return 0;
}

Measured memory_bytes: 17036
#include <bits/stdc++.h>
using namespace std; 
int main() 
{
	long long n,t;
	cin>>n>>t;
	long long a[n];
	for(int i=0;i<n;i++)cin>>a[i];
	for(int i=1;i<n;i++)a[i]=a[i]+a[0];
	long long res=0LL;
	for(int i=1;i<n;i++)
	{
		if(a[i]-a[i-1]<t)
		{
			res+=a[i]-a[i-1];
		}
		else
		{
			res+=t;
		}
	}
	res+=t;
	cout<<res;
}

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

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

  vector<int> vec(M);
  for (int i = 0; i < M; i++) {
  cin >> vec.at(i);
  }
  
  int left = 0;
  for (int i = 0; i < M; i++) {
    if (vec.at(i) < X) {
      left++;
    }
  }
  
  int right = 0;
  for (int i = 0; i < M; i++) {
    if (vec.at(i) > X) {
      right++;
    }
  }
  
  if (left > right) {
    cout << right << endl;
  }
  
  else {
    cout << left << endl;
  }
}

Measured memory_bytes: 256
from collections import deque
from itertools import product
from sys import stdin
import sys
sys.setrecursionlimit(10 ** 7)
H,W = [int(x) for x in stdin.readline().rstrip().split()]
grid = [input() for _ in range(H)]

# 移動用（上下左右）
mv = [(1, 0),
      (0, 1)]

# スタート位置の設定
for i, j in product(range(H), range(W)):
    if grid[i][j] == 's':
        start = (i, j)

# 訪問したかどうか
is_visited = [[False for _ in range(W)] for _ in range(H)]



def dfs(i, j):
    if not (0 <= i < H) or not (0 <= j < W):
        # 範囲外
        return False
    
    if is_visited[i][j]:
        # 壁または訪問済み
        return False
    
    if grid[i][j] == '#':
        p2.append((i,j))
        return False
 
    is_visited[i][j] = True
    if i == H-1 and j == W-1:
        return True

    for di, dj in mv:
        flg = dfs(i+di, j+dj)
        if flg:
            return True

        
        
def dfs2(i, j):
    if not (0 <= i < H) or not (0 <= j < W):
        # 範囲外
        return False
    
    if is_visited[i][j]:
        # 壁または訪問済み
        return False
    
    if grid[i][j] == '.':
        p1.append((i,j))
        return False
 
    is_visited[i][j] = True
    if i == H-1 and j == W-1:
        return True

    for di, dj in mv:
        flg = dfs2(i+di, j+dj)
        if flg:
            return True
        
ans = 0

p1 = deque([(0,0)])
p2 = deque([])
f = False

while True:
    while p1:
        s1,s2 = p1.popleft()
        if dfs(s1,s2):
            f = True
    if f:
        break
    ans += 1
    while p2:
        s1,s2 = p2.popleft()
        if dfs2(s1,s2):
            f = True
    if f:
        break
print(ans)

Measured memory_bytes: 50776
# -*- coding: utf-8 -*-
s = list(str(input()))

n = len(s)
ans = []
for i in range(n):
    if s[i] == 'B' and len(ans) != 0:
        ans.pop(len(ans) - 1)
    elif s[i] == '0' or s[i] == '1':
        ans.append(s[i])
print(''.join(ans))


Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
template<class T> using vc = vector<T>;
template<class T> using vvc = vector<vector<T>>;

#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define repr(i, n) for (ll i = (n)-1; i >= 0; i--)
#define repe(i, l, r) for (ll i = (l); i < (r); i++)
#define reper(i, l, r) for (ll i = (r)-1; i >= (l); i--)
#define repa(i,n) for (auto& i: n)

template<class T> inline bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> inline bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
void init() {cin.tie(0);ios::sync_with_stdio(false);cout << fixed << setprecision(15);}

#ifdef DEBUG
template <class T, class N> void verr(const T& a, const N& n) { rep(i, n) cerr << a[i] << " "; cerr << "\n" << flush; }
ll dbgt = 1; void err() { cerr << "passed " << dbgt++ << "\n" << flush; }
template<class H, class... T> void err(H&& h,T&&... t){ cerr<< h << (sizeof...(t)?" ":"\n") << flush; if(sizeof...(t)>0) err(forward<T>(t)...); }
#endif

const ll INF = 4e18;
const ld EPS = 1e-11;
const ld PI = acos(-1.0L);
const ll MOD = 1e9 + 7;
// const ll MOD = 998244353;
//--------------------------------------------------------------------------------//

int main() {
    init();
    ll A, B, K;
    cin >> A >> B >> K;
    rep(i,K){
        if(i%2==0){
            if(A&1){
                A--;
            }
            A /= 2;
            B += A;
        }
        else{
            if(B&1){
                B--;
            }
            B /= 2;
            A += B;
        }
    }

    cout << A << " " << B << endl;
}

Measured memory_bytes: 3628
string1 = gets.chop
string2 = gets.chop

ok = 0
i = 0
while ok == 0 and i <= string1.length - 1 do
	if string1.chars.to_a.rotate(i) == string2.chars.to_a
		ok = 1
	end
	i += 1
end

puts ok == 1 ? 'Yes' : 'No'

Measured memory_bytes: 2172
#include <stdio.h>
#include <iostream>
#include <string>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <queue>
#include <vector>
#include <iomanip>
using namespace std;


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

    
}

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

using namespace std;

typedef long long ll;

int main() {
    ll x; cin >> x;
    vector<ll> s;
    s.push_back(0);
    for (ll i = 1;;i++) {
        ll p = pow(i, 5);
        s.push_back(p);
        int lb = 0;
        int ub = (int)s.size();
        while (ub - lb > 1) {
            int mid = (lb + ub) / 2;
            if (s[mid] <= p - x) {
                lb = mid;
            } else {
                ub = mid;
            }
        }
        if (s[lb] == p - x) {
            cout << i << ' ' << lb;
            return 0;
        }
        lb = 0;
        ub = (int)s.size();
        while (ub - lb > 1) {
            int mid = (lb + ub) / 2;
            if (s[mid] <= x - p) {
                lb = mid;
            } else {
                ub = mid;
            }
        }
        if (s[lb] == x - p) {
            cout << i << ' ' << -lb;
            return 0;
        }
    }
    return 0;
}


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

using namespace std;

int main(){
    int n,w,h;
    cin>>n>>w>>h;
    vector<int> x(w+1,0),y(h+1,0);
    for (int i = 0; i < n; ++i) {
        int a,b,c;
        cin>>a>>b>>c;
        int l=max(a-c,0),r=min(a+c,w+1),d=max(b-c,0),u=min(b+c,h+1);
        ++x[l];--x[r];++y[d];--y[u];
    }
    for (int i = 1; i <= w+1; ++i) {
        x[i]+=x[i-1];
    }
    for (int j = 1; j <= h+1; ++j) {
        y[j]+=y[j-1];
    }
    int zx=0,zy=0;
    for (int i = 0; i < w; ++i) {
        if(x[i]==0)++zx;
    }
    for (int i = 0; i < h; ++i) {
        if(y[i]==0)++zy;
    }
    if(zx==0||zy==0)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}


Measured memory_bytes: 3640
#include<cstdio>
#include<cmath>
#include<string>
#include<vector>
#include<algorithm>
#include<set>
#include<stack>
#include<queue>
#include<map>
#include<cstring>
#include<functional>

using namespace std;

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

	int n;

	scanf("%d", &n);
	long long lmin = 999999999;

	vector<long long> arr;

	for (int i = 0; i < n; i++)
	{
		long long input;

		scanf("%lld", &input);

		arr.push_back(input);
	}

	sort(arr.begin(), arr.end(), greater<long long>());

	long long sol = 0;

	for (int i = 0; i < n - 1; i++)
	{
		sol += arr[(i + 1) / 2];
	}

	printf("%lld\n", sol);

	return 0;
}

Measured memory_bytes: 4836
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<stdlib.h>
using namespace std;
vector<int>pat[100000];
vector<int>ko[100000];
bool flag[100000];
typedef long long ll;
ll dat[100000];
void dfs(int node)
{
	flag[node] = true;
	for (int i = 0; i < pat[node].size(); i++)
	{
		if (!flag[pat[node][i]])
		{
			ko[node].push_back(pat[node][i]);
			dfs(pat[node][i]);
		}
	}
}
void no()
{
	printf("NO\n");
	exit(0);
}
ll calc(int node)
{
	if (ko[node].size() == 0)return dat[node];
	vector<ll>v;
	for (int i = 0; i < ko[node].size(); i++)v.push_back(calc(ko[node][i]));
	sort(v.begin(), v.end());
	ll s = 0;
	for (int i = 0; i < v.size(); i++)s += v[i];
	if (s < dat[node])no();
	ll k = s - dat[node];
	if (s - k - k < 0)no();
	if (s - v[v.size() - 1] < k)no();
	//printf("%d %d\n", node + 1, s - k - k);
	return s - k - k;
}
int main()
{
	int num;
	scanf("%d", &num);
	for (int i = 0; i < num; i++)scanf("%lld", &dat[i]);
	for (int i = 0; i < num - 1; i++)
	{
		int za, zb;
		scanf("%d%d", &za, &zb);
		za--, zb--;
		pat[za].push_back(zb);
		pat[zb].push_back(za);
	}
	dfs(0);
	int t = calc(0);
	if (t != 0 && ko[0].size()>1)no();
	if (t != dat[0] && ko[0].size() == 0)no();
	printf("YES\n");
}

Measured memory_bytes: 20096