akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

// エイリアス
using  ll = long signed long;
using ull = long unsigned long;
using  ld = long double;
using   P = pair<int, int>;
using llP = pair<ll, ll>;
using DoP = pair<double, double>;

// 汎用マクロ
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define FOREACH(i,q) for (auto &i : q)
#define UNIQUE(v) do { sort((v).begin(), (v).end()); (v).erase(unique((v).begin(), (v).end()), (v).end()); } while (false)
#define SZ(x) ((int)(x).size())
template <class T>inline bool chmin(T &a, const T b) {if (a > b) { a = b; return true;} return false;}
template <class T>inline bool chmax(T &a, const T b) {if (a < b) { a = b; return true;} return false;}
template <class T>inline void line_out(const vector<T> vec) {int n = SZ(vec); rep(i, n) { cout << vec[i]; if(i < n-1) cout << " ";}cout << endl;}
const int di[] = {0, 1, 0, -1, 1, 1, -1, -1};
const int dj[] = {1, 0, -1, 0, 1, -1, 1, -1};
const int di2[] = {1, 1, -1, -1, 0, 1, 2, 2, 2, 2, 2, 1, 0, -1, -2, -2, -2, -2, -2, -1};
const int dj2[] = {1, -1, 1, -1, 2, 2, 2, 1, 0, -1, -2, -2, -2, -2, -2, -1, 0, 1, 2, 2};
const int INF = 1 << 28;
const ll INF64 = 1ll << 55;
const int mod = 1000000007;
//const int mod = 998244353;
struct mint
{
  ll x; // typedef long long ll;
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  mint &operator+=(const mint a)
  {
    if ((x += a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator-=(const mint a)
  {
    if ((x += mod - a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator*=(const mint a)
  {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const
  {
    mint res(*this);
    return res += a;
  }
  mint operator-(const mint a) const
  {
    mint res(*this);
    return res -= a;
  }
  mint &operator++()
  {
    if ((x += 1) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator--()
  {
    if ((x += mod - 1) >= mod)
      x -= mod;
    return *this;
  }
  mint operator*(const mint a) const
  {
    mint res(*this);
    return res *= a;
  }
  mint pow(ll t) const
  {
    if (!t)
      return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1)
      a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const
  {
    return pow(mod - 2);
  }
  mint &operator/=(const mint a)
  {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const
  {
    mint res(*this);
    return res /= a;
  }
};

int main(){
  int n; cin >> n;
  vector<ll> a(n);
  rep(i, n) cin >> a[i];
  ll sum = 0;
  rep(i, n) sum ^= a[i];
  rep(i, n) cout << (sum^a[i]) << " ";
  cout << endl;

}

Measured memory_bytes: 4744
#include<cstdio>
#include <string>
#include <iostream>
using namespace std;

int main(){
	string S, T;
	cin >> S >> T;
	int A[S.size()], B[T.size()];
	for (int i = 0; i < S.size(); ++i){
		A[i] = S[i] - 'a';
		B[i] = T[i] - 'a';
	}
	int first_appearance_of_alphabet_S[26], first_appearance_of_same_letter_S[S.size()];
	int first_appearance_of_alphabet_T[26], first_appearance_of_same_letter_T[T.size()];
	for (int i = 0; i < 26; ++i){
		first_appearance_of_alphabet_S[i] = first_appearance_of_alphabet_T[i] = -1;
	}
	bool flag = true;
	for (int i = 0; i < S.size(); ++i){
		if(first_appearance_of_alphabet_S[A[i]] < 0) first_appearance_of_alphabet_S[A[i]] = i;
		if(first_appearance_of_alphabet_T[B[i]] < 0) first_appearance_of_alphabet_T[B[i]] = i;
		first_appearance_of_same_letter_S[i] = first_appearance_of_alphabet_S[A[i]];
		first_appearance_of_same_letter_T[i] = first_appearance_of_alphabet_T[B[i]];
		if(first_appearance_of_same_letter_S[i] != first_appearance_of_same_letter_T[i]){
			flag = false;
			break;
		}
	}
	printf("%s\n", flag ? "Yes" : "No");
	return 0;
}

Measured memory_bytes: 3848
#pragma GCC optimize ("O3")
#pragma GCC target ("avx")
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please


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


	int N, K;
	cin >> N >> K;
	int H[200000];
	rep(i, N) cin >> H[i];
	sort(H, H + N);

	int kaisuu = max(0, N - K);
	
	ll kotae = 0;
	rep(i, kaisuu) kotae += H[i];

	co(kotae);

	Would you please return 0;
}

Measured memory_bytes: 1024
n=int(input())
a=list(map(int,input().split()))
l=[0]*n
s=0
for i in range((n-1)//2):
    s+=a[2*i+1]
l[0]=sum(a)-2*s
for i in range(n-1):
    l[i+1]=2*a[i]-l[i]
for i in l:
    print(int(i), end=" ")

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

  int division2(int n){
    
    //basecase
    if (n % 2 == 1) {
      return 0;
    }
    
    //recursive
    int s = division2(n / 2);
    return s + 1;
  }
  
int main(void){
  int N;
  cin >> N;
  
  int number = 1;
  
  for (int i = 1; i <= N ; i++) {
    if (division2(i) >= division2(number)) {
      number = i;
    }
  }

  cout << number << endl;
}

Measured memory_bytes: 384
l = []
res = 0
w = input()
while True:
    temp = input()
    if temp[-1] == '.':
        temp = temp[:-1]
    if temp =='END_OF_TEXT':
        break
    l.append(temp.split())
for i in l:
    for j in i:
        if w == j.lower():
            res += 1
print(res)


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

#define int long long

int f(int n) {
    n++;
    switch(n % 4) {
        case 0:
            return 0;
        case 1:
            return (n - 1);
        case 2:
            return 1;
        case 3:
            return 1 ^ (n - 1);
    }
}

signed main() {
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int A, B;
    cin >> A >> B;
    if (A == 0) cout << f(B) << endl;
    else cout << (f(A - 1) ^ f(B)) << endl;

    return 0;
}

Measured memory_bytes: 384
import java.util.*;
public class Main{   
    public static void main(String[] args){
      Scanner sc = new Scanner(System.in);
      long n = sc.nextLong();
      long m = sc.nextLong();
      long INF = 1000000007;
      if(Math.abs(n-m)>=2){
      	System.out.println(0);
        return;
      }
      long x = 1;
      for(long i = 1;i <= n;i++)x = (x*i)%INF;
      for(long i = 1;i <= m;i++)x = (x*i)%INF;
      if(n-m==0)
      System.out.println((x*2)%INF);
      else System.out.println(x);
    }
    public static int lcm(int x, int y){
      return x*y/gcd(x,y);
    }
    public static int gcd(int x, int y){
      if(x < y)return gcd(y,x);
      if(y==0)return x;
      return gcd(y,x%y);
    }
}

Measured memory_bytes: 23892
x, y, z, k = list(map(int, input().split()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
import heapq
q = []
A.sort(reverse=True)
B.sort(reverse=True)
C.sort(reverse=True)
def val(i, j, k):
  return -(A[i] + B[j] + C[k])
heapq.heappush(q, (val(0,0,0), 0,0,0))
visited = set((0,0,0))
for _ in range(k):
  v, aa, bb, cc = heapq.heappop(q)
  print(-v)
  if aa + 1 < len(A) and (aa+1, bb, cc) not in visited:
    visited.add((aa+1, bb, cc))
    heapq.heappush(q, (val(aa+1, bb, cc), aa+1, bb, cc))
  if bb + 1 < len(B) and (aa, bb+1, cc) not in visited:
    visited.add((aa, bb+1, cc))
    heapq.heappush(q, (val(aa, bb+1, cc), aa, bb+1, cc))
  if cc + 1 < len(C) and (aa, bb, cc+1) not in visited:
    visited.add((aa, bb, cc+1))
    heapq.heappush(q, (val(aa, bb, cc+1), aa, bb, cc+1))


Measured memory_bytes: 4956
#coding:utf-8

n = int(input())
v = list(map(int, input().split()))
c = list(map(int, input().split()))
# 宝石の価値-入手コストを格納する（利益出る分だけ）
diff = []

for i in range(n):
    # 手に入れた場合の利益を計算
    tmp = v[i] - c[i]
    # 利益が出るなら入手する
    if tmp > 0:
        diff.append(tmp)

print(sum(diff))

Measured memory_bytes: 3060
#include <stdio.h>
#define N 8

int main( void ) {
  int i, j;
  int d[ N ] = { 1, 2, 1, 2, 1, 4, 1, 4 };
  int num[ N ];
  int dt[ N ][ N ];
  int p[ N ];

  /* 配列から値へ */
  for( i = 0; i < N; i++ ) {
    num[ i ] = 0;
    for( j = 0; j < N; j++ ) {
      num[ i ] *= 10;
      num[ i ] += d[ ( i+j ) % N ];
    }
  }

  /* 値のソート */
  for( i = 0; i < N-1; i++ ) {
    int w = num[ i+1 ];
    for( j = i+1; j > 0 && num[ j-1 ] > w; j-- )
      num[ j ] = num[ j-1 ];
    num[ j ] = w;
  }

  /* 値から配列へ */
  for( i = 0; i < N; i++ ) {
    for( j = N-1; j >= 0; j-- ) {
      dt[ i ][ j ] = num[ i ] % 10;
      num[ i ] /= 10;
    }
  }

  /* 実際の処理 */
  while( scanf( "%d%d%d%d%d%d%d%d",
        &p[ 0 ], &p[ 1 ], &p[ 2 ], &p[ 3 ],
        &p[ 4 ], &p[ 5 ], &p[ 6 ], &p[ 7 ] ) == 8 ) {
    int dsum, msumind, msum; // 合計値，合計最大値インデックス

    /* 0番目を最小として始める */
    dsum = 0;
    for( j = 0; j < N; j++ )
      if( p[ j ] > dt[ 0 ][ j ] )
        dsum += p[ j ] - dt[ 0 ][ j ];
    msum = dsum;
    msumind = 0;

    /* 1番目以降を見ていく */
    for( i = 1; i < N; i++ ) {
      dsum = 0;
      for( j = 0; j < N; j++ )
        if( p[ j ] > dt[ i ][ j ] )
          dsum += p[ j ] - dt[ i ][ j ];

      if( msum > dsum ) {
        msumind = i;
        msum = dsum;
      }
    }

    /* 出力 */
    for( j = 0; j < N; j++ ) {
      printf( "%d", dt[ msumind ][ j ] );
      if( j < N-1 )
        printf( " " );
    }
    printf( "\n" );
  }

  return( 0 );
}

Measured memory_bytes: 0
//ABC-139-E
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a) for(int i = 0; i < (a); i++)
#define ALL(a) (a).begin(),(a).end()
typedef long long ll;
typedef pair<int, int> P;
const int INF = INT_MAX;
const long long LINF = LLONG_MAX;
const long long MOD = 1e9 + 7;

const int MAX_V = 1000 *  (1000 - 1) / 2;

int dp[MAX_V];
int ans = 0;

vector<int> Tsort(vector<vector<int>> & G){
    vector<int> To; //トポロジカルソート後のグラフ
    // To.size() == V であればトポロジカルソートができた、そうでなければできなかったと判定できる
    int V = G.size();
    stack<int> st; //入次数が0の頂点の集合
    int indeg[V] = {}; //頂点の入次数を管理する配列
    for(int i = 0; i < V; i++){
        for(int j = 0; j < G[i].size(); j++){
            indeg[G[i][j]]++;
        }
    }
    for(int i = 0; i < V; i++){
        if(indeg[i] == 0){
            st.push(i);
        }
    }
    while(!st.empty()){
        int u = st.top();
        st.pop();
        To.push_back(u);
        for(int i = 0; i < G[u].size(); i++){
            indeg[G[u][i]]--; //隣接する頂点の入次数を1減らす
            dp[G[u][i]] = max(dp[G[u][i]], dp[u] + 1);
            ans = max(ans, dp[G[u][i]]);
            if(indeg[G[u][i]] == 0){
                st.push(G[u][i]); //入次数が0になればstに追加
            }
        }
    }
    return To;
}

signed main(){
    int n;
    cin >> n;
    int id[n][n];
    int V = 0;
    REP(i,n){
        for(int j = i + 1; j < n; j++){
            id[i][j] = V;
            V++;
        }
    }
    int num[n][n - 1];
    int a,b;
    REP(i,n){
        REP(j,n - 1){
            cin >> a;
            a--;
            b = i;
            if(a > b){
                swap(a, b);
            }
            num[i][j] = id[a][b];
        }
    }
    vector<vector<int>> G(V);
    REP(i,n){
        REP(j,n - 2){
            G[num[i][j]].push_back(num[i][j + 1]);
        }
    }
    vector<int> To = Tsort(G);
    if(To.size() != V){
        cout << -1 << endl;
        return 0;
    }
    cout << ans + 1 << endl;
    return 0;
}

Measured memory_bytes: 41464
#include <bits/stdc++.h>
using namespace std;
using Pi = pair < int , int >;

constexpr int INF = (1 << 30) - 1;

int N, T;
Pi dat[3005];
int dp[3005][6005];
int maxv = 0;

int main()
{
	cin >> N >> T;
	for ( int i = 0; i < N; i++ ) {
		cin >> dat[i].first >> dat[i].second;
	}
	
	sort(dat, dat + N);
	for ( int i = 0; i < 3005; i++ ) {
		for ( int j = 0; j < 6005; j++ ) { 
			dp[i][j] = -INF;
		}
	}

	dp[0][0] = 0;
	
	for ( int i = 0; i < N; i++ ) {
		for ( int j = 0; j <= T + 3000; j++ ) {
			if ( dp[i][j] == -INF ) continue;
			dp[i + 1][j] = max(dp[i + 1][j], dp[i][j]);
			if ( j < T ) dp[i + 1][j + dat[i].first] = max(dp[i + 1][j + dat[i].first], dp[i][j] + dat[i].second);
			maxv = max(maxv, dp[i][j]);
		}
	}

	cout << max(maxv, *max_element(dp[N], dp[N] + 6005)) << endl;

	return ( 0 );
}

Measured memory_bytes: 70784
fun main(args: Array<String>) {
    abc085d()
}

private data class Sword(val swing: Long, val throwing: Long)

fun abc085d() {
    val (n, hp) = readLine()!!.split(" ").map { it.toLong() }
    val swords = (1..n).map { readLine()!!.split(" ").map { it.toLong() } }
        .map { Sword(it[0], it[1]) }

    // 最大振り攻撃ダメージより大きい刀は最後に確定で投げるようにする
    val maxSwingDamage = swords.maxBy { it.swing }!!.swing
    val throwingAttacks = swords.filter { it.throwing >= maxSwingDamage }
        .sortedByDescending { it.throwing }

    var hpLeft = hp
    var attackCount = 0
    for (throwingAttack in throwingAttacks) {
        if (hpLeft <= 0) break
        attackCount++
        hpLeft -= throwingAttack.throwing
    }

    // 最大振り攻撃ダメージの刀で残りを削る
    while (hpLeft > 0) {
        attackCount++
        hpLeft -= maxSwingDamage
    }

    println(attackCount)
}


Measured memory_bytes: 82360
/// Code By t_bone_289 (Tushar Singh)
/// An Immature Programmer.... I'm still developing !!
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/trie_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define pll pair<ll,ll>
#define fi first
#define se second
#define mp make_pair
#define pb emplace_back
#define endl '\n'
#define M 1000000007
#define error(x) cout << #x << " = " << x << endl;
#define pi 3.14159265358979323846
typedef long long ll;
typedef long double ld;
template <typename T>
void ContainerError(T &v){cout<<"{";for(auto &x:v){cout<<x<<',';}cout<<"}"<<endl;return;}
typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
ll powmod(ll base,ll exp,ll MOD){ll res=1;while(exp>0){if(exp%2==1) res=(res*base)%MOD;base=(base*base)%MOD;exp/=2;}return (res%MOD);}
ll mpow(ll base,ll exp){ll res=1;while(exp>0){if(exp%2==1) res=(res*base);base=(base*base);exp/=2;}return (res);}
ll gcd(ll a, ll b){return b?gcd(b,a%b):a;}
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    ll n;
    cin>>n;
    ll ans = n/2;
    if(n%2==0)
    {
        ans --;
    }
    cout<<ans;
    return 0;
}































Measured memory_bytes: 764
// C
 #ifndef _GLIBCXX_NO_ASSERT
 #include <cassert>
 #endif
 #include <cctype>
 #include <cerrno>
 #include <cfloat>
 #include <ciso646>
 #include <climits>
 #include <clocale>
 #include <cmath>
 #include <csetjmp>
 #include <csignal>
 #include <cstdarg>
 #include <cstddef>
 #include <cstdio>
 #include <cstdlib>
 #include <cstring>
 #include <ctime> 
 #ifdef __GXX_EXPERIMENTAL_CXX0X__
 #include <ccomplex>
 #include <cfenv>
 #include <cinttypes>
 #include <cstdbool>
 #include <cstdint>
 #include <ctgmath>
 #include <cwchar>
 #include <cwctype>
 #endif
 
 // C++
 #include <algorithm>
 #include <bitset>
 #include <complex>
 #include <deque>
 #include <exception>
 #include <fstream>
 #include <functional>
 #include <iomanip>
 #include <ios>
 #include <iosfwd>
 #include <iostream>
 #include <istream>
 #include <iterator>
 #include <limits>
 #include <list>
 #include <locale>
 #include <map>
 #include <memory>
 #include <new>
 #include <numeric>
 #include <ostream>
 #include <queue>
 #include <set>
 #include <sstream>
 #include <stack>
 #include <stdexcept>
 #include <streambuf>
 #include <string>
 #include <typeinfo>
 #include <utility>
 #include <valarray>
 #include <vector> 
 #ifdef __GXX_EXPERIMENTAL_CXX0X__
 #include <array>
 #include <atomic>
 #include <chrono>
 #include <condition_variable>
 #include <forward_list>
 #include <future>
 #include <initializer_list>
 #include <mutex>
 #include <random>
 #include <ratio>
 #include <regex>
 #include <system_error>
 #include <thread>
 #include <tuple>
 #include <typeindex>
 #include <type_traits>
 #include <unordered_map>
 #include <unordered_set>
 #endif
using namespace std;
const long long INF = 1LL<<60;
long long dp[22][50010];
int main(){
    int n,m; cin >> n >> m;
    vector<int> coin(m);
    for(int i=0;i<m;++i) cin >> coin[i];
    for(int i=0;i<=m;++i){
        for(int j=0;j<=n;++j){
            dp[i][j] = INF;
        }
    }
    for(int i=0;i<m;++i) dp[i][0] = 0;
    for(int i=0;i<m;++i){
        for(int j=0;j<=n;++j){
            dp[i+1][j] = dp[i][j];
            if(j-coin[i]>=0){
                dp[i+1][j] = min(dp[i][j],dp[i][j-coin[i]] + 1);
                dp[i+1][j] = min(dp[i+1][j],dp[i+1][j-coin[i]] + 1);
            }
        }
    }
    cout << dp[m][n] << endl;
    return 0;
}


Measured memory_bytes: 11272
#include <iostream>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <cstring>
using namespace std;

int main(int argc, char *argv[])
{
	char str1[16], str2[128], str3[16];
	cin >> str1 >> str2 >> str3;

	cout << 'A' << str2[0] << 'C' << endl;

	return 0;
}


Measured memory_bytes: 256
<?php
list($n, $m) = array_map("intval", explode(" ", trim(fgets(STDIN))));
$di = new Di($n);
for($i = 0; $i < $m; $i++){
  list($from, $to, $d) = array_map("intval", explode(" ", trim(fgets(STDIN))));
  $di->connect($from, $to, $d);
}
for($i = 2; $i <= $n; $i++){
  $di->connect($i, $i - 1, 0);
}
$di->solve(1);
$distance = $di->distance[$n];
if($distance == $di->inf){
  echo -1;
}else{
  echo $distance;
}

/**
 * Dijkstra
 * Attention: 1-origin
 **/
class Di{
  public $pq;
  public $distance;
  public $G;
  public $from;
  public $inf = 10**18;
  function __construct($n) {
    $this->pq = new SplPriorityQueue();
    for($i = 1; $i <= $n; $i++){
      $this->distance[$i] = $this->inf;
      $this->from[$i] = 0;
    }
  }
  function connect($from, $to, $cost){
    $this->G[$from][] = [$to, $cost];
  }
  function solve($from){
    $this->pq->insert($from, 0);
    $this->distance[$from] = 0;
    while($this->pq->count()){
      $f = $this->pq->extract();
      if(!isset($this->G[$f]))continue;
      foreach($this->G[$f] as list($t, $dist)){
        $new = $this->distance[$f] + $dist;
        if($this->distance[$t] > $new){
          $this->distance[$t] = $new;
          $this->from[$t] = $f;
          $this->pq->insert($t, -$new);
        }
      }
    }
  }
}

Measured memory_bytes: 142708
#include <iostream>
#include <queue>
#include <algorithm>

using namespace std;
typedef pair<long, int> P;
P p[100000];

long A[100000], B[100000], C[100000];
long sum1[100000], sum2[100000];

int main(){
    int X, Y, Z;
    cin >> X >> Y >> Z;
    int N = X+Y+Z;
    for(int i = 0; i < (X+Y+Z); i++){
        cin >> A[i] >> B[i] >> C[i];
        p[i] = P(A[i]-B[i], i);
    }
    sort(p, p+N, greater<P>());
   
    long ans = 0;
    long base = 0;
    long sum_diff = 0;
    priority_queue<long, vector<long>, greater<long>> pq1, pq2;
    for(int i = 0; i < X; i++){
        int idx = p[i].second;
        long diff = A[idx]-C[idx];
        base += C[idx];
        sum_diff += diff;
        pq1.push(diff);
    }
    sum1[X-1] = base+sum_diff;
    for(int i = X; i+Y < N; i++){
        int idx = p[i].second;
        long diff = A[idx]-C[idx];
        long top = pq1.top();
        base += C[idx];
        if(top < diff){
            sum_diff -= top;
            sum_diff += diff;
            pq1.pop();
            pq1.push(diff);
        }
        //cout << pq1.size() << endl;
        sum1[i] = base+sum_diff;
    }
    base = 0;
    sum_diff = 0;
    for(int i = 0; i < N; i++){
        int idx = p[i].second;
        //cout << A[idx] << ' ' << B[idx] << ' ' << C[idx] << endl;        
    }
    for(int i = N-1; i >= N-Y; i--){
        int idx = p[i].second;
        long diff = B[idx]-C[idx];
        base += C[idx];
        sum_diff += diff;
        pq2.push(diff);
        //cout << A[idx] << ' ' << B[idx] << ' ' << C[idx] << endl;
    }
    //cout << base <<  ' ' << sum_diff << endl;
    sum2[N-Y] = base+sum_diff;
    for(int i = N-Y-1; i >= X; i--){
        int idx = p[i].second;
        long diff = B[idx]-C[idx];
        long top = pq2.top();
        base += C[idx];
        if(top < diff){
            sum_diff -= top;
            sum_diff += diff;
            pq2.pop();
            pq2.push(diff);
        }
        //cout << diff << endl;
        //cout << pq2.size() << endl;
        sum2[i] = base+sum_diff;
    }
   //cout << base << ' ' << sum_diff << endl;
    for(int i = X-1; i < N-Y; i++){
        //cout << sum1[i] << ' ' << sum2[i+1] << endl;
        ans = max(ans, sum1[i]+sum2[i+1]);
    }
    cout << ans << endl;
}

Measured memory_bytes: 5628
// D = 25 なら Christmas,
// D = 24 なら Christmas Eve
// D = 23 なら Christmas Eve Eve
// D = 22 なら Christmas Eve Eve Eve
#include <iostream>
using namespace std;

int main(){
  int d;cin >> d;
  string r;
  d = -(d - 25);
  cout << "Christmas" << endl;
  for(int i;d>i;++i){
    cout << " Eve" << endl;
  }
}

Measured memory_bytes: 256
import sys
from bisect import *
from collections import *
from copy import deepcopy
from heapq import *
from itertools import *
from math import *
from operator import *
from pprint import *

sys.setrecursionlimit(10**8)

input = sys.stdin.readline

# 必ず勝率が上がる勝ち方がある
def main():
    """ main """
    N = int(input())
    a = (N-1)//2+1
    print(a/N)

if __name__ == '__main__':
    main()

Measured memory_bytes: 3952
#include<stdio.h>
#include<math.h>
#include<string.h>
#define pr(x) printf("%s %lld\n", #x , x)
int main()
{
    //freopen("in.txt", "w", stdout);
     char string[10];
     scanf("%s",string);
     if(string[2] == string[3] && string[4] == string[5]) printf("Yes\n");
     else printf("No\n");
}   

Measured memory_bytes: 128
import collections

n, *a = map(int, open(0).read().split())
c = collections.Counter(a)
length_l = list(c.keys())
length_l.sort(reverse = True)
side1 = 0
ans = 0
for l in length_l:
    cnt = c[l]
    if cnt >= 4:
        if side1 != 0:
            ans = side1*l
            break
        else:
            ans = l**2
            break
    elif cnt >= 2:
        if side1 != 0:
            ans = side1*l
            break
        else:
            side1 = l
print(ans)

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

using namespace std;

#define int ll
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<double> vd;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<pi> vp;
typedef vector<pl> vpl;

signed main()
{
    ios_base::sync_with_stdio(false); 
    cin.tie(nullptr); 
    cout.tie(nullptr); 
    cerr.tie(nullptr);    

    int n, k;
    cin >> n >> k;

    vi a(n);
    for (auto& i : a)
        cin >> i;

    int dp[k + 1];
    for (int i = 0; i <= k; ++i){
        dp[i] = 0;
    }

    dp[0] = 2;
    for (int i = 1; i <= k; ++i){
        dp[i] = 2;
        for (int j = 1; j <= n; ++j){
            if (a[j - 1] > i) break;

            if (dp[i - a[j - 1]] == 2){
                dp[i] = 1;
                break;
            }
        }
    }

    if (dp[k] == 1)
        cout << "First\n";
    else
        cout << "Second\n";
}

Measured memory_bytes: 1024
def gcd(a,b):
    while a%b!=0:
        a,b=b,a%b
    return b
def main(a,b):
    return (a*b)//gcd(a,b)
N=int(input())
A=list(map(int,input().split()))
res=A[0]
for i in range(1,N):
    res=main(res,A[i])
res-=1
ans=0
for a in A:
    ans+=res%a
print(ans)

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

using namespace std;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  string a, b, c;
  cin >> a >> b>>c;
  string out;
  out.push_back(a[0]);
  out.push_back(b[0]);
  out.push_back(c[0]);
  cout << out << "\n";
}


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

vector <int> l;

int main(){
	ios::sync_with_stdio(false);
	int n, x;
	cin >> n >> x;
	int sum = 0;
	int ans = 0;
	l.resize(n);
	for (int i = 0; i < n; i ++){
		if (sum <= x)
			ans ++;
		cin >> l[i];
		sum += l[i];
	}
	if (sum <= x)
		ans ++;
	cout << ans;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define pi 2*asin(1.0)
#define MAX 10000000
#define MOD 1000000007
 
 
vector<long> fac(MAX);
vector<long> finv(MAX);
vector<long> inv(MAX);
 
//template functions
/////////////////////////
void Cominit(){
  fac.at(0)=fac.at(1)=1;
  finv.at(0)=finv.at(1)=1;
  inv.at(1)=1;
  for(long i=2;i<MAX;i++){
      fac.at(i)=(fac.at(i-1)*i)%MOD;
      inv.at(i)=MOD-inv.at(MOD%i)*(MOD/i)%MOD;
      finv.at(i)=finv.at(i-1)*inv.at(i)%MOD;
  }
}

long facComb(long N,long M){// nCm%
if(N<M) return 0;
if(N<0||M<0) return 0;
return fac.at(N)*(finv.at(M)*finv.at(N-M)%MOD)%MOD;
}

long Comb(long N,long M){// nCm
long ans=1;
for(long i=N;i>N-M;i--){
    ans=ans*i;
}
for(long i=M;i>0;i--){
    ans=ans/i;
}
return ans;
}

long Perm(long N,long M){// nPm
long ans=1;
for(long i=N;i>N-M;i--){
    ans=ans*i;
}
return ans;
}

long GCM(long A,long B){
            long W,r;
    if(A<B){

        W=B;
        B=A;
        A=W;
    }
    while(A%B!=0){
        r=A%B;
        A=B;
        B=r;
    }
    return B;
}
long LCM(long A,long B){
    return (A*B)/GCM(A,B);
}

long upDiv(long a,long b){
  return (a+b-1)/b;
}

long strtolong(string str){
istringstream ss;
ss=istringstream(str);
long num;
ss>>num;
return num;
}

long chartolong(char ch){
long num;
num=ch-'0';
return num;
}

/////////////////////////


//Answer



int main() {

string T,S;
cin>>S>>T;
long N=T.size(),cou=0,max=0;
for(long i=0;i<S.size()-T.size()+1;i++){
    cou=0;
    for(long j=0;j<T.size();j++){
        if(S.at(i+j)==T.at(j)){
            cou++;
        }
    }
    if(max<cou){
        max=cou;
    }
}
cout<<N-max<<endl;


}



Measured memory_bytes: 237448
#include <bits/stdc++.h>
#define INF 0x3f3f3f3f
using namespace std;
const int N = 2e5 + 5;
const int dx[] = {-1, 1, 0, 0};
const int dy[] = {0, 0, -1, 1};

struct node {
    int step, r, d, x, y;
    bool operator < (const node& A) const {
        if (step == A.step) return r > A.r;
        return step > A.step;
    }
};

void run() {
    int h, w, K;
    cin >> h >> w >> K;
    int sx, sy, ex, ey;
    cin >> sx >> sy >> ex >> ey;
    --sx, --sy, --ex, --ey;
    vector<string> s(h);
    for (int i = 0; i < h; i++) {
        cin >> s[i];
    }
    priority_queue<node> que;
    vector<vector<vector<pair<int, int>>>> dis(h, vector<vector<pair<int, int>>>(w, vector<pair<int, int>>(5, make_pair(INF, INF))));
    auto ok = [&] (int x, int y) {
        return x >= 0 && x < h && y >= 0 && y < w && s[x][y] == '.';
    };
    que.push(node {0, 0, 4, sx, sy});
    dis[sx][sy][4] = make_pair(0, 0);
    while (!que.empty()) {
        node cur = que.top(); que.pop();
        int x = cur.x, y = cur.y, d = cur.d;
        if (make_pair(cur.step, cur.r) > dis[x][y][d]) continue;
        if (d != 4) {
            int nx = x + dx[d], ny = y + dy[d];
            if (ok(nx, ny)) {
                int nowd1 = dis[x][y][d].first, nowd2 = dis[x][y][d].second;
                if (++nowd2 == K) {
                    nowd2 = 0;
                    ++nowd1;
                }
//                cout <<dis[x][y][d].first << ' ' <<dis[x][y][d].second << '\n';
//                cout <<dis[nx][ny][d].first << ' ' <<dis[nx][ny][d].second << '\n';
                if (dis[nx][ny][d] > make_pair(nowd1, nowd2)) {
                    dis[nx][ny][d] = make_pair(nowd1, nowd2);
                    que.push(node{nowd1, nowd2, d, nx, ny});
                }
            }
        }
        for (int k = 0; k < 4; k++) if (k != d) {
            int nowd1 = cur.step, nowd2 = cur.r;
            if (nowd2 > 0) ++nowd1;
            nowd2 = 0;
            if (dis[x][y][k] > make_pair(nowd1, nowd2)) {
                dis[x][y][k] = make_pair(nowd1, nowd2);
                que.push(node{nowd1, nowd2, k, x, y});
            }
        }
    }
    pair<int, int> res(INF, INF);
    for (int i = 0; i < 5; i++) {
        res = min(res, dis[ex][ey][i]);
    }
    if (res == make_pair(INF, INF)) {
        cout << -1 << '\n';
    } else {
        int ans = res.first + (res.second > 0);
        cout << ans << '\n';
    }
}

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


Measured memory_bytes: 144944
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <numeric>

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

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

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int a, b;
    cin >> a >> b;
    int cnt = 0, ans = 1;
    while (ans < b) {
        ans += a - 1;
        cnt++;
    }
    cout << cnt << endl;
    return 0;
}


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

int main(){
    int a[32]={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
    int k;
    cin >> k;
    cout << a[k-1] << endl;
    
    return 0;
}







Measured memory_bytes: 256
#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

typedef long long ll;

#define sz size()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(c) (c).begin(), (c).end()
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define clr(a, b) memset((a), (b) ,sizeof(a))
#define ctos(c) string(1,c)
#define print(x) cout<<#x<<" = "<<x<<endl;

#define MOD 1000000007

vector<int> uf, usz;
int nc;

void init(int n){
  vector<int> uf_(n);
  vector<int> usz_(n, 1);
  uf = uf_;
  usz = usz_;
  nc = n;

  for(int i = 0; i < uf.size(); i++){
    uf[i] = i;
  }
}

int find(int a){
  return (uf[a] == a) ? a : uf[a] = find(uf[a]);
}

void union_(int a, int b){
  a = find(a);
  b = find(b);

  if(a != b){
    if(usz[a] >= usz[b]){
      swap(a, b);
    }
    uf[a] = b;
    usz[b] += usz[a];
    nc--;
  }
}

int check(int a, int b){
  return (find(a) == find(b)) ? 1 : 0;
}

int get_size(int a){
  return usz[find(a)];
}

ll d1[200010];
ll d2[200010];
ll d3[200010];

int main() {
	ll n,k,l;
	cin>>n>>k>>l;
	init(n);
	rep(i,0,k){
		ll a,b;
		cin>>a>>b;
		a--;b--;
		union_(a,b);
	}
	set<ll> se;
	rep(i,0,n){
		ll a = find(i);
		se.insert(a);
		d1[i] = a;
	}
	vector<ll> v1(all(se));
	map<ll,ll> ma;
	rep(i,0,v1.sz){
		ma[v1[i]] = i;
	}
	vector<vector<ll> > vv(v1.sz,vector<ll>());
	rep(i,0,n){
		vv[ma[d1[i]]].pb(i);
	}
	// rep(i,0,vv.sz){
	// 	rep(j,0,vv[i].sz){
	// 		cout << vv[i][j] << " ";
	// 	}
	// 	cout << endl;
	// }
	init(n);
	rep(i,0,l){
		ll a,b;
		cin>>a>>b;
		a--;b--;
		union_(a,b);
	}
	rep(i,0,n){
		ll a = find(i);
		d2[i] = a;
	}
	clr(d3,0);
	rep(i,0,vv.sz){
		map<ll,ll> ma2;
		rep(j,0,vv[i].sz){
	 		ma2[d2[vv[i][j]]]++;
	 	}
	 	rep(j,0,vv[i].sz){
	 		d3[vv[i][j]] = ma2[d2[vv[i][j]]];
	 	}
	}
	rep(i,0,n){
		cout << d3[i];
		if(i!=n-1)cout << " ";
	}
	cout << endl;
	return 0;
}


Measured memory_bytes: 38216
#include<stdio.h>
int main(void){
	
	int r,c,a[100][100],sum1[100],count=0,i,j,k,l;
	
	scanf("%d %d",&r,&c);
	
	for(i=0;i<r;i++){
		for(j=0;j<c;j++){
			scanf("%d",&a[i][j]);
			count+=a[i][j];
		}
		sum1[i]=count;
		count=0;
	}
	
	for(i=0;i<r+1;i++){
		
		if(i==r){
			
			for(k=0;k<c+1;k++){
				if(k==c){
					for(l=0;l<r;l++){
						count+=sum1[l];
					}
					printf("%d\n",count);
					count=0;
				}else{
					for(l=0;l<r;l++){
						count+=a[l][k];
					}
					printf("%d ",count);
					count=0;
				}
				
			}
			
		}else{
			for(j=0;j<c+1;j++){
				if(j==c){
					printf("%d\n",sum1[i]);
				}
				else{
					printf("%d ",a[i][j]);
				}
			}
		}
		
	}
	
	
	return 0;
}


Measured memory_bytes: 2044
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <tuple>


using namespace std;

typedef long long ll;

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

bool greaterSecond(const pair<int, int>& f, const pair<int, int>& s){
	return f.second > s.second;
}



int main(void){
	int a, b;

	cin >> a >> b;

	if (a >= 13){
		cout << b << endl;
	}
	else if (a >= 6){
		cout << b / 2 << endl;
	}
	else {
		cout << 0 << endl;
	}

}


Measured memory_bytes: 256
import java.io.*;
import java.util.*;
public class Main
{
	public static void main(String args[])throws IOException
	{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st = new StringTokenizer(br.readLine());
		int x = Integer.parseInt(st.nextToken());
		int n = Integer.parseInt(st.nextToken());
		if(n==0)
		{
			System.out.println(x);
			return;
		}
		st = new StringTokenizer(br.readLine());
		int arr[] = new int[n];
		for(int i=0;i<n;i++)
			arr[i] = Integer.parseInt(st.nextToken());
		Arrays.sort(arr);
		if(Arrays.binarySearch(arr,x)<0)
		{
			System.out.println(x);
			return;
		}
		for(int i=1;i<=100;i++)
		{
			
			if(Arrays.binarySearch(arr,x-i)<0)
			{
				System.out.println(x-i);
				return;
			}
			if(Arrays.binarySearch(arr,x+i)<0)
			{
				System.out.println(x+i);
				return;
			}
		}
	}
}

Measured memory_bytes: 32696
import java.util.*;
import java.io.*;

class Main {
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		int n = Integer.parseInt(br.readLine());
		int[][] adj = new int[n][n];

		for (int i=0; i<n; i++) {
			String line = br.readLine();
			String[] str = line.split(" ");
			for (int j=2; j<str.length; j++) {
				adj[Integer.parseInt(str[0])-1][Integer.parseInt(str[j])-1] = 1;
			}
		}

		for (int i=0; i<n; i++) {
			StringBuilder sb = new StringBuilder();
			for (int j=0; j<n-1; j++) {
				sb.append(adj[i][j]).append(" ");
			}
			sb.append(adj[i][n-1]);
			System.out.println(sb);
		}

		br.close();
	}
}

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

int main(){

    ll a, v, b, w, T;
    cin >> a >> v >> b >> w >> T;

    ll dif = abs(b-a);
    ll pdif = w-v;

    if (pdif>=0){
        cout << "NO" << endl;
    }
    else{
        ll cnt, mod;
        cnt = dif/abs(pdif);
        mod = dif%abs(pdif);

        if (mod != 0) cnt++;
        
        if (T<cnt) cout << "NO" << endl;
        else cout << "YES" << endl;
    }
    return 0;
}

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

using ll = long long;
using vi = vector<int>;
#define f(i,a,b) for (int i = a; i < b; i++)
#define pb push_back

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
#ifdef LOCAL
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	clock_t start = clock();
#endif

	int n;
	cin>>n;
	int a[n],b[n];
	f(i,0,n) cin>>a[i];
	f(i,0,n) cin>>b[i];
	vi r,s;
	f(i,1,51) r.pb(i);
	auto valid = [&]() {
		vi ls;
		for (int x : r) ls.pb(x);
		for (int y : s) ls.pb(y);
		sort(begin(ls),end(ls),greater<int>());

		f(i,0,n) if (a[i] != b[i]) {
			bool dp[51];
			f(j,0,51) dp[j]=0;
			dp[a[i]]=1;
			for (int x : ls)
				f(j,0,51) if (dp[j])
					dp[j%x] = 1;
			if (!dp[b[i]]) return 0;
		}		
		return 1;
	};
	if (!valid()) {
		cout << -1 << endl;
		return 0;
	}
	while (r.size()) {
		int v = r.back();
		r.pop_back();
		if (!valid())
			s.pb(v);
	}
	ll ans = 0;
	for (int y : s) ans += 1LL<<y;
	cout << ans << endl;

#ifdef LOCAL
	cout << setprecision(12) << (long double)(clock()-start) / CLOCKS_PER_SEC << endl;
#endif
	
	return 0;
}



Measured memory_bytes: 256
N = int(input())
A = list(input())
B = list(input())
C = list(input())

if A == B and B == C:
	print(0)
else:
	counter = 0
	for j, k, l in zip(A,B,C):
		if j == k and k == l:
			pass
		elif j == k or k == l or j == l:
			counter += 1
		else:
			counter += 2

	print(counter)

Measured memory_bytes: 3064
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; ++i)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = int64_t;
using ld = long double;
using P = pair<int, int>;
using vs = vector<string>;
using vi = vector<int>;
using vvi = vector<vi>;
const int INF = 100010001;
const ll LINF = (ll)INF*INF*10;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    vector<ll> a(n);
    bool x = true;
    rep(i, n) {
        cin >> a[i];
        if(a[i] >= n) x = false;
    }
    if(x) {
        cout << 0 << endl;
        return 0;
    }

    vi r(n);
    rep(i, n) {
        r[i] = a[i]%(n+1);
    }

    ll ans = INT64_MAX;
    rep(i, n+1) {
        ll cnt = 0;
        rep(j, n) {
            int now = r[j]+i;
            now %= n+1;
            if(now == n) {
                cnt = -1;
                break;
            }
            cnt += a[j]-now;
            //cout << now << ' ' << j << ' ' << i << endl;
        }
        //cout << i << ' ' << cnt << endl;
        if(cnt >= 0) {
            ans = min(ans, cnt);
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 3604
#include <iostream>

using namespace std;

int tab[100007];
int dp[100007];
const int INF=2000000007;

int main()
{
    int N,K;
    cin >> N >> K;
    for(int i=1; i<=N; i++)
    {
        cin >> tab[i];
        dp[i]=INF;
    }
    dp[1]=0;
    for(int i=2; i<=N; i++)
    {
        for(int j=i-1;j>0 && j>=i-K; j--)
            dp[i]=min(dp[i], dp[j]+abs(tab[j]-tab[i]));
    }
    cout << dp[N];
}

Measured memory_bytes: 1024
///Combination + Bit mask

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll inf = 1e9;
#define Fast    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define sz      15

int arr[sz][sz];
vector < int > cost;

int main(){
    Fast;
    int n,m,x,i,j,val;

    cin>>n>>m>>x;
    for(i=1; i<=n; i++){
        cin>>val;
        cost.push_back(val);
        for(j=1; j<=m; j++){
            cin>>arr[i][j];
        }
    }

    int ans=inf;
    int all=(1<<n);
    for(int mask=0; mask<all; mask++){
        int c=0;
        vector < int > level(m+1);
        for(i=1; i<=n; i++){
            if(mask&(1<<(i-1))){
                c+=cost[i-1];
                for(j=1; j<=m; j++){
                    level[j]+=arr[i][j];
                }
            }
        }
        bool ok=true;
        for(i=1; i<=m; i++){
            if(level[i]<x)ok=false;
        }
        if(ok)ans=min(ans,c);
    }
    if(ans==inf)cout<<-1<<endl;
    else    cout<<ans<<endl;


    return 0;
}

///1000


Measured memory_bytes: 3660
/*
Author: CNYALI_LK
LANG: C++
*/
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<cmath>
#define up(a,b,c) for (int a(b),end##a(c);a<=end##a;++a)
#define down(a,c,b) for (int a(b),end##a(c);a>=end##a;--a)
#define uup(a,c,b) for (int a(b),end##a(c);a<=end##a;++a)
#define udown(a,b,c) for (int a(b),end##a(c);a>=end##a;--a)
#define endl '\n'
using namespace std;
const double eps=1e-8;
const double PI=acos(-1.0);
int main(){
	int a,b,c,d;
	cin>>a>>b>>c>>d;
	if(a>c){
		swap(a,c);
		swap(b,d);
	}
	if(b>d)cout<<d-c<<endl;
	else if(b>c)cout<<b-c<<endl;
	else cout<<0<<endl;
	return 0;
}


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

#define pb push_back
#define S second
#define F first
#define sz size()
#define eps 0.000001
#define oo 1000000007
#define endl '\n'
#define bg begin()
#define nd end()
#define up upper_bound
#define lw lower_bound
#define debug(x) #x << " = " << x << "; "
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vii;


int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	int n, w;
	cin >> n >> w;
	int val[n], wei[n];
	for(int i = 0; i < n; i++) cin >> wei[i] >> val[i];
	int dp[n+1][100001];
	for(int i = 0; i <= 100000; i++) dp[n][i] = oo;
	dp[n][0] = 0;
	for(int i = n-1; i>=0; i--){
		for(int j = 0; j <= 100000; j++){
			dp[i][j] = oo;
			if(j - val[i] >= 0) dp[i][j] = min(dp[i][j], dp[i+1][j - val[i]] + wei[i]);
			dp[i][j] = min(dp[i][j], dp[i+1][j]);
		}	
	}
	int best = 0;
	for(int i = 0; i <= 100000; i++) if(dp[0][i] <= w) best = i;
	cout << best << endl;
}

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

using namespace std;
using ll =long long;
#define For(i, a, b)    for(int i = (a) ; i < (b) ; ++i)
#define rep(i, n)       For(i, 0, n)
#define debug(x)  cerr << #x << " = " << (x) << endl;
#define leftunique(a) {sort((a).begin(),(a).end());(a).erase(unique((a).begin(),(a).end()),(a).end());}
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; }
static const ll INF = 1LL << 60;
//Write From this Line

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

	ll ans = 0;
	// TODO:約数を全部見る。　約数-1が行けるかどうかを調べる
	// 約数を調べるのはO(√N)
	for(ll i = 1; i * i <= n; i++){
		if(n % i == 0){
			// TODO i - 1が条件を満たすか
			ll num = i - 1;
			ll num2 = n / i;
			num2 --;
			if(num != 0){
				if((n / num) == (n % num)) {
					ans += num;
				}
			}
			if(num2 != 0){
				if((n / num2) == (n % num2)){
					ans += num2;
				}
			}
		}
	}
	if(n == 2) ans = 0;
	cout << ans << endl;
}


Measured memory_bytes: 256
/**-------------------------
|--------From A.R.A--------|
-------------------------**/
#include <bits/stdc++.h>

#define ll long long int
#define ull unsigned long long int
#define FOR(i,n) for(ll i=0;i<n;i++)
#define input (a,i,n)for(ll i=0;i<n;i++){      cin>>a[i];}
#define output(a,i,n)for(ll i=0;i<n;i++){cout<<a[i]<<" ";}
#define pb push_back
#define sz(c) (c).size()
#define vi vector <int>
#define vs vector <string>
#define vc vector <char>
#define vl vector <ll>
#define sall(c) sort((c).begin(),(c).end())
#define rsall(c) sort((c).rbegin(),(c).rend())
#define max3(a,b,c) max(max(a,b),c)
#define min3(a,b,c) min(min(a,b),c)
int64_t TN=1;
using namespace std;
void  solution(){
    int n,m,c=0;
    cin>>n>>m>>c;
    cout<<((n+m-1)/m)*c<<endl;
}
int main()
{

    ios_base::sync_with_stdio(0);
    cin.tie(0);
    //cin>>TN;
    while(TN--){
        solution();
    }
    return 0;
}


Measured memory_bytes: 3648
#include<iostream>
#include<algorithm>
#include<vector> 
using namespace std;
typedef pair<int,int> P;

bool cmp(const P &p,const P &q){
  return p.second > q.second;
}

int main(){
  int n,id,s1,s2;
  vector<P> patient;
  while(cin >> n && n){
    patient.clear();
    for(int i=0;i<n;i++){
      cin >> id >> s1 >> s2;
      patient.push_back(P(id,s1+s2));
    }
    sort(patient.begin(),patient.end(),cmp);
    cout << patient[0].first << " " << patient[0].second << endl;

  }
  return 0;
}

Measured memory_bytes: 1328
#include<iostream>
#include<stdio.h>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include <queue>
#include <utility>
#include <map>
#include <set>
using namespace std;

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

    cout << ((N%K) ? 1 : 0) << endl;



    return 0;

}

Measured memory_bytes: 256
// ABC150B - Count ABC

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

typedef unsigned long long int ull;
typedef long long int ll;

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

	int ans = 0;
	for (int i = 0; i < N - 2; i++) {
		if ((S[i] == 'A')&&(S[i+1] == 'B')&&(S[i+2] == 'C')) {
			++ans;
		}
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <string.h>
#define rep(i, n) for(int i = 0; i<(n); i++)
using namespace std;
typedef long long ll;
static const int MAX = 200000; 
//pi = 3.14159265358979323846

int main() {

    int n, k;
    int count = 0;
    cin >> n >> k;
    rep(i, n){
        int h;
        cin >> h;
        if(h >= k) count++;
    }
    cout << count;

}




Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <sstream>
#include <iomanip>

using namespace std;

typedef long long ll;
typedef vector <int> vi;
typedef vector <vector <int>> vii;
typedef vector <long long> vll;
typedef vector <string> vs;
typedef vector <char> vc;
typedef set <int> si;
typedef set <string> ss;
typedef queue <int> qi;
typedef queue <long long> qll;
typedef queue <string> qs;
typedef queue <char> qc;
typedef struct board board;
typedef pair <int, int> pi;
typedef pair <long long, long long> pll;
typedef pair <int, pair<int, int>> pii;

#define eb emplace_back
#define ppb pop_back
#define clr(a) a.clear()
#define F first
#define S second
#define mkp make_pair

#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()

#define left(x) x * 2
#define right(x) x * 2 + 1

#define meme(a, b, c) fill(a + 1, a + 1 + b, c)

#define max(a, b) (a > b ? a : b)
#define min(a, b) (a > b ? b : a)
#define abs(a) (a > 0? a : -(a))

#define move(s) s += "#"

#define fr(i, a, b) for (ll i = a; i <= b; ++ i)
#define rf(i, a, b) for (ll i = a; i >= b; -- i)

#define eprintf(...) fprintf(stderr, __VA_ARGS__);

void to_pray() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cerr << "Ready\n";
}

const int N = 4e6 + 10;
const int NN = 1e3 + 10;
const int NNN = 2e3 + 9;
const int MOD = 1e9 + 7;
const int INF = 1e9 + 7;
const ll LLINF = 1e12 + 7;
const ll P = 53;
const int EPS = 1e-9 - 8;
const int vN = 2e4 + 10;
const int sz = (1 << 22) - 1;
const double PI = acos(-1);

int main () {
    to_pray();

    int a, b;
    cin >> a >> b;
    
    if ((a + b) & 1)
    	cout << "IMPOSSIBLE";
   	else
   		cout << (a + b) / 2;
    
    cout << '\n';
    return 0;
}

Measured memory_bytes: 256
def resolve():
    n = int(input())
    a = tuple(map(int, input().split()))
    b = tuple(map(int, input().split()))
    c = tuple(map(int, input().split()))
    before_dinner = a[0]
    ans = sum(b)
    for i in range(1,n):
        if a[i] - before_dinner==1:
            ans += c[before_dinner-1]
        before_dinner = a[i]
    print(ans)
resolve()

Measured memory_bytes: 9092
//g++ -std=c++14 test.cpp -o test.out
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <iomanip>
#include <vector>
#include <queue>
#include <map> 
#include <utility>
#include <limits.h>
using namespace std;

long N;

long ans = 0;
 
void solve(){
	ans = (N-1)*N/2;
}
 
int main(){
	cin>>N;

	solve();

	cout<<ans;
	return 0;
}

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


int main(){
  int a,b,c,d;
  cin >> a >> b >> c >>d;
  if(a+b>c+d){
    cout<<"Left"<<endl;
  }
  else if(a+b<c+d){
    cout <<"Right"<<endl;
  }
  else{
    cout <<"Balanced" << endl;
  }
  }


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

using namespace std;

const long long int MOD = 1000000007;
const long double EPS = 1e-8;

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

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

	cin >> N >> L >> R >> H >> W;
	L = N / L + !!(N%L);
	L *= R;
	H = N / H + !!(N%H);
	H *= W;
	cout << min(L, H) << endl;
	return 0;
}


Measured memory_bytes: 3208
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<algorithm>
using namespace std;
int main()
{
    int s=1,x,i,n,ans=1;
    scanf("%d",&n);
    for(i=0;i<n;i++)
    {
        scanf("%d",&x);
        ans=ans*3;
        if(x%2==0)
        s=s*2;
    }
    printf("%d\n",ans-s);
    return 0;
}


Measured memory_bytes: 128